mvme147.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. static const struct net_device_ops lance_netdev_ops = {
  53. .ndo_open = m147lance_open,
  54. .ndo_stop = m147lance_close,
  55. .ndo_start_xmit = lance_start_xmit,
  56. .ndo_set_multicast_list = lance_set_multicast,
  57. .ndo_tx_timeout = lance_tx_timeout,
  58. .ndo_change_mtu = eth_change_mtu,
  59. .ndo_validate_addr = eth_validate_addr,
  60. .ndo_set_mac_address = eth_mac_addr,
  61. };
  62. /* Initialise the one and only on-board 7990 */
  63. struct net_device * __init mvme147lance_probe(int unit)
  64. {
  65. struct net_device *dev;
  66. static int called;
  67. static const char name[] = "MVME147 LANCE";
  68. struct m147lance_private *lp;
  69. u_long *addr;
  70. u_long address;
  71. int err;
  72. if (!MACH_IS_MVME147 || called)
  73. return ERR_PTR(-ENODEV);
  74. called++;
  75. dev = alloc_etherdev(sizeof(struct m147lance_private));
  76. if (!dev)
  77. return ERR_PTR(-ENOMEM);
  78. if (unit >= 0)
  79. sprintf(dev->name, "eth%d", unit);
  80. /* Fill the dev fields */
  81. dev->base_addr = (unsigned long)MVME147_LANCE_BASE;
  82. dev->netdev_ops = &lance_netdev_ops;
  83. dev->dma = 0;
  84. addr=(u_long *)ETHERNET_ADDRESS;
  85. address = *addr;
  86. dev->dev_addr[0]=0x08;
  87. dev->dev_addr[1]=0x00;
  88. dev->dev_addr[2]=0x3e;
  89. address=address>>8;
  90. dev->dev_addr[5]=address&0xff;
  91. address=address>>8;
  92. dev->dev_addr[4]=address&0xff;
  93. address=address>>8;
  94. dev->dev_addr[3]=address&0xff;
  95. printk("%s: MVME147 at 0x%08lx, irq %d, "
  96. "Hardware Address %pM\n",
  97. dev->name, dev->base_addr, MVME147_LANCE_IRQ,
  98. dev->dev_addr);
  99. lp = netdev_priv(dev);
  100. lp->ram = __get_dma_pages(GFP_ATOMIC, 3); /* 16K */
  101. if (!lp->ram)
  102. {
  103. printk("%s: No memory for LANCE buffers\n", dev->name);
  104. free_netdev(dev);
  105. return ERR_PTR(-ENOMEM);
  106. }
  107. lp->lance.name = (char*)name; /* discards const, shut up gcc */
  108. lp->lance.base = dev->base_addr;
  109. lp->lance.init_block = (struct lance_init_block *)(lp->ram); /* CPU addr */
  110. lp->lance.lance_init_block = (struct lance_init_block *)(lp->ram); /* LANCE addr of same RAM */
  111. lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
  112. lp->lance.irq = MVME147_LANCE_IRQ;
  113. lp->lance.writerap = (writerap_t)m147lance_writerap;
  114. lp->lance.writerdp = (writerdp_t)m147lance_writerdp;
  115. lp->lance.readrdp = (readrdp_t)m147lance_readrdp;
  116. lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
  117. lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
  118. lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
  119. lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
  120. err = register_netdev(dev);
  121. if (err) {
  122. free_pages(lp->ram, 3);
  123. free_netdev(dev);
  124. return ERR_PTR(err);
  125. }
  126. return dev;
  127. }
  128. static void m147lance_writerap(struct lance_private *lp, unsigned short value)
  129. {
  130. out_be16(lp->base + LANCE_RAP, value);
  131. }
  132. static void m147lance_writerdp(struct lance_private *lp, unsigned short value)
  133. {
  134. out_be16(lp->base + LANCE_RDP, value);
  135. }
  136. static unsigned short m147lance_readrdp(struct lance_private *lp)
  137. {
  138. return in_be16(lp->base + LANCE_RDP);
  139. }
  140. static int m147lance_open(struct net_device *dev)
  141. {
  142. int status;
  143. status = lance_open(dev); /* call generic lance open code */
  144. if (status)
  145. return status;
  146. /* enable interrupts at board level. */
  147. m147_pcc->lan_cntrl=0; /* clear the interrupts (if any) */
  148. m147_pcc->lan_cntrl=0x08 | 0x04; /* Enable irq 4 */
  149. return 0;
  150. }
  151. static int m147lance_close(struct net_device *dev)
  152. {
  153. /* disable interrupts at boardlevel */
  154. m147_pcc->lan_cntrl=0x0; /* disable interrupts */
  155. lance_close(dev);
  156. return 0;
  157. }
  158. #ifdef MODULE
  159. MODULE_LICENSE("GPL");
  160. static struct net_device *dev_mvme147_lance;
  161. int __init init_module(void)
  162. {
  163. dev_mvme147_lance = mvme147lance_probe(-1);
  164. if (IS_ERR(dev_mvme147_lance))
  165. return PTR_ERR(dev_mvme147_lance);
  166. return 0;
  167. }
  168. void __exit cleanup_module(void)
  169. {
  170. struct m147lance_private *lp = netdev_priv(dev_mvme147_lance);
  171. unregister_netdev(dev_mvme147_lance);
  172. free_pages(lp->ram, 3);
  173. free_netdev(dev_mvme147_lance);
  174. }
  175. #endif /* MODULE */