mvme147.c 5.7 KB

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