mvme147.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* mvme147.c : the Linux/mvme147/lance ethernet driver
  2. *
  3. * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk>
  4. * Based on the Sun Lance driver and the NetBSD HP Lance driver
  5. * Uses the generic 7990.c LANCE code.
  6. */
  7. #include <linux/module.h>
  8. #include <linux/kernel.h>
  9. #include <linux/types.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/ioport.h>
  12. #include <linux/slab.h>
  13. #include <linux/string.h>
  14. #include <linux/delay.h>
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. /* Used for the temporal inet entries and routing */
  18. #include <linux/socket.h>
  19. #include <linux/route.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/etherdevice.h>
  22. #include <linux/skbuff.h>
  23. #include <asm/system.h>
  24. #include <asm/io.h>
  25. #include <asm/pgtable.h>
  26. #include <asm/mvme147hw.h>
  27. /* We have 16834 bytes of RAM for the init block and buffers. This places
  28. * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
  29. * buffers and 2 Tx buffers.
  30. */
  31. #define LANCE_LOG_TX_BUFFERS 1
  32. #define LANCE_LOG_RX_BUFFERS 3
  33. #include "7990.h" /* use generic LANCE code */
  34. /* Our private data structure */
  35. struct m147lance_private {
  36. struct lance_private lance;
  37. unsigned long ram;
  38. };
  39. /* function prototypes... This is easy because all the grot is in the
  40. * generic LANCE support. All we have to support is probing for boards,
  41. * plus board-specific init, open and close actions.
  42. * Oh, and we need to tell the generic code how to read and write LANCE registers...
  43. */
  44. static int m147lance_open(struct net_device *dev);
  45. static int m147lance_close(struct net_device *dev);
  46. static void m147lance_writerap(struct lance_private *lp, unsigned short value);
  47. static void m147lance_writerdp(struct lance_private *lp, unsigned short value);
  48. static unsigned short m147lance_readrdp(struct lance_private *lp);
  49. typedef void (*writerap_t)(void *, unsigned short);
  50. typedef void (*writerdp_t)(void *, unsigned short);
  51. typedef unsigned short (*readrdp_t)(void *);
  52. /* Initialise the one and only on-board 7990 */
  53. struct net_device * __init mvme147lance_probe(int unit)
  54. {
  55. struct net_device *dev;
  56. static int called;
  57. static const char name[] = "MVME147 LANCE";
  58. struct m147lance_private *lp;
  59. u_long *addr;
  60. u_long address;
  61. int err;
  62. if (!MACH_IS_MVME147 || called)
  63. return ERR_PTR(-ENODEV);
  64. called++;
  65. dev = alloc_etherdev(sizeof(struct m147lance_private));
  66. if (!dev)
  67. return ERR_PTR(-ENOMEM);
  68. if (unit >= 0)
  69. sprintf(dev->name, "eth%d", unit);
  70. SET_MODULE_OWNER(dev);
  71. /* Fill the dev fields */
  72. dev->base_addr = (unsigned long)MVME147_LANCE_BASE;
  73. dev->open = &m147lance_open;
  74. dev->stop = &m147lance_close;
  75. dev->hard_start_xmit = &lance_start_xmit;
  76. dev->get_stats = &lance_get_stats;
  77. dev->set_multicast_list = &lance_set_multicast;
  78. dev->tx_timeout = &lance_tx_timeout;
  79. dev->dma = 0;
  80. addr=(u_long *)ETHERNET_ADDRESS;
  81. address = *addr;
  82. dev->dev_addr[0]=0x08;
  83. dev->dev_addr[1]=0x00;
  84. dev->dev_addr[2]=0x3e;
  85. address=address>>8;
  86. dev->dev_addr[5]=address&0xff;
  87. address=address>>8;
  88. dev->dev_addr[4]=address&0xff;
  89. address=address>>8;
  90. dev->dev_addr[3]=address&0xff;
  91. printk("%s: MVME147 at 0x%08lx, irq %d, Hardware Address %02x:%02x:%02x:%02x:%02x:%02x\n",
  92. dev->name, dev->base_addr, MVME147_LANCE_IRQ,
  93. dev->dev_addr[0],
  94. dev->dev_addr[1], dev->dev_addr[2],
  95. dev->dev_addr[3], dev->dev_addr[4],
  96. dev->dev_addr[5]);
  97. lp = (struct m147lance_private *)dev->priv;
  98. lp->ram = __get_dma_pages(GFP_ATOMIC, 3); /* 16K */
  99. if (!lp->ram)
  100. {
  101. printk("%s: No memory for LANCE buffers\n", dev->name);
  102. free_netdev(dev);
  103. return ERR_PTR(-ENOMEM);
  104. }
  105. lp->lance.name = (char*)name; /* discards const, shut up gcc */
  106. lp->lance.base = dev->base_addr;
  107. lp->lance.init_block = (struct lance_init_block *)(lp->ram); /* CPU addr */
  108. lp->lance.lance_init_block = (struct lance_init_block *)(lp->ram); /* LANCE addr of same RAM */
  109. lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
  110. lp->lance.irq = MVME147_LANCE_IRQ;
  111. lp->lance.writerap = (writerap_t)m147lance_writerap;
  112. lp->lance.writerdp = (writerdp_t)m147lance_writerdp;
  113. lp->lance.readrdp = (readrdp_t)m147lance_readrdp;
  114. lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
  115. lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
  116. lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
  117. lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
  118. err = register_netdev(dev);
  119. if (err) {
  120. free_pages(lp->ram, 3);
  121. free_netdev(dev);
  122. return ERR_PTR(err);
  123. }
  124. return dev;
  125. }
  126. static void m147lance_writerap(struct lance_private *lp, unsigned short value)
  127. {
  128. out_be16(lp->base + LANCE_RAP, value);
  129. }
  130. static void m147lance_writerdp(struct lance_private *lp, unsigned short value)
  131. {
  132. out_be16(lp->base + LANCE_RDP, value);
  133. }
  134. static unsigned short m147lance_readrdp(struct lance_private *lp)
  135. {
  136. return in_be16(lp->base + LANCE_RDP);
  137. }
  138. static int m147lance_open(struct net_device *dev)
  139. {
  140. int status;
  141. status = lance_open(dev); /* call generic lance open code */
  142. if (status)
  143. return status;
  144. /* enable interrupts at board level. */
  145. m147_pcc->lan_cntrl=0; /* clear the interrupts (if any) */
  146. m147_pcc->lan_cntrl=0x08 | 0x04; /* Enable irq 4 */
  147. return 0;
  148. }
  149. static int m147lance_close(struct net_device *dev)
  150. {
  151. /* disable interrupts at boardlevel */
  152. m147_pcc->lan_cntrl=0x0; /* disable interrupts */
  153. lance_close(dev);
  154. return 0;
  155. }
  156. #ifdef MODULE
  157. MODULE_LICENSE("GPL");
  158. static struct net_device *dev_mvme147_lance;
  159. int __init init_module(void)
  160. {
  161. dev_mvme147_lance = mvme147lance_probe(-1);
  162. if (IS_ERR(dev_mvme147_lance))
  163. return PTR_ERR(dev_mvme147_lance);
  164. return 0;
  165. }
  166. void __exit cleanup_module(void)
  167. {
  168. struct m147lance_private *lp = dev_mvme147_lance->priv;
  169. unregister_netdev(dev_mvme147_lance);
  170. free_pages(lp->ram, 3);
  171. free_netdev(dev_mvme147_lance);
  172. }
  173. #endif /* MODULE */