hplance.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* hplance.c : the Linux/hp300/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. /* Used for the temporal inet entries and routing */
  17. #include <linux/socket.h>
  18. #include <linux/route.h>
  19. #include <linux/dio.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 "hplance.h"
  26. /* We have 16392 bytes 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 hplance_private {
  35. struct lance_private lance;
  36. };
  37. /* function prototypes... This is easy because all the grot is in the
  38. * generic LANCE support. All we have to support is probing for boards,
  39. * plus board-specific init, open and close actions.
  40. * Oh, and we need to tell the generic code how to read and write LANCE registers...
  41. */
  42. static int hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent);
  43. static void hplance_init(struct net_device *dev, struct dio_dev *d);
  44. static void hplance_remove_one(struct dio_dev *d);
  45. static void hplance_writerap(void *priv, unsigned short value);
  46. static void hplance_writerdp(void *priv, unsigned short value);
  47. static unsigned short hplance_readrdp(void *priv);
  48. static int hplance_open(struct net_device *dev);
  49. static int hplance_close(struct net_device *dev);
  50. static struct dio_device_id hplance_dio_tbl[] = {
  51. { DIO_ID_LAN },
  52. { 0 }
  53. };
  54. static struct dio_driver hplance_driver = {
  55. .name = "hplance",
  56. .id_table = hplance_dio_tbl,
  57. .probe = hplance_init_one,
  58. .remove = hplance_remove_one,
  59. };
  60. static const struct net_device_ops hplance_netdev_ops = {
  61. .ndo_open = hplance_open,
  62. .ndo_stop = hplance_close,
  63. .ndo_start_xmit = lance_start_xmit,
  64. .ndo_set_rx_mode = lance_set_multicast,
  65. .ndo_change_mtu = eth_change_mtu,
  66. .ndo_validate_addr = eth_validate_addr,
  67. .ndo_set_mac_address = eth_mac_addr,
  68. #ifdef CONFIG_NET_POLL_CONTROLLER
  69. .ndo_poll_controller = lance_poll,
  70. #endif
  71. };
  72. /* Find all the HP Lance boards and initialise them... */
  73. static int hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent)
  74. {
  75. struct net_device *dev;
  76. int err = -ENOMEM;
  77. dev = alloc_etherdev(sizeof(struct hplance_private));
  78. if (!dev)
  79. goto out;
  80. err = -EBUSY;
  81. if (!request_mem_region(dio_resource_start(d),
  82. dio_resource_len(d), d->name))
  83. goto out_free_netdev;
  84. hplance_init(dev, d);
  85. err = register_netdev(dev);
  86. if (err)
  87. goto out_release_mem_region;
  88. dio_set_drvdata(d, dev);
  89. printk(KERN_INFO "%s: %s; select code %d, addr %pM, irq %d\n",
  90. dev->name, d->name, d->scode, dev->dev_addr, d->ipl);
  91. return 0;
  92. out_release_mem_region:
  93. release_mem_region(dio_resource_start(d), dio_resource_len(d));
  94. out_free_netdev:
  95. free_netdev(dev);
  96. out:
  97. return err;
  98. }
  99. static void hplance_remove_one(struct dio_dev *d)
  100. {
  101. struct net_device *dev = dio_get_drvdata(d);
  102. unregister_netdev(dev);
  103. release_mem_region(dio_resource_start(d), dio_resource_len(d));
  104. free_netdev(dev);
  105. }
  106. /* Initialise a single lance board at the given DIO device */
  107. static void hplance_init(struct net_device *dev, struct dio_dev *d)
  108. {
  109. unsigned long va = (d->resource.start + DIO_VIRADDRBASE);
  110. struct hplance_private *lp;
  111. int i;
  112. /* reset the board */
  113. out_8(va + DIO_IDOFF, 0xff);
  114. udelay(100); /* ariba! ariba! udelay! udelay! */
  115. /* Fill the dev fields */
  116. dev->base_addr = va;
  117. dev->netdev_ops = &hplance_netdev_ops;
  118. dev->dma = 0;
  119. for (i = 0; i < 6; i++) {
  120. /* The NVRAM holds our ethernet address, one nibble per byte,
  121. * at bytes NVRAMOFF+1,3,5,7,9...
  122. */
  123. dev->dev_addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4)
  124. | (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF);
  125. }
  126. lp = netdev_priv(dev);
  127. lp->lance.name = d->name;
  128. lp->lance.base = va;
  129. lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */
  130. lp->lance.lance_init_block = NULL; /* LANCE addr of same RAM */
  131. lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
  132. lp->lance.irq = d->ipl;
  133. lp->lance.writerap = hplance_writerap;
  134. lp->lance.writerdp = hplance_writerdp;
  135. lp->lance.readrdp = hplance_readrdp;
  136. lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
  137. lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
  138. lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
  139. lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
  140. }
  141. /* This is disgusting. We have to check the DIO status register for ack every
  142. * time we read or write the LANCE registers.
  143. */
  144. static void hplance_writerap(void *priv, unsigned short value)
  145. {
  146. struct lance_private *lp = (struct lance_private *)priv;
  147. do {
  148. out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value);
  149. } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
  150. }
  151. static void hplance_writerdp(void *priv, unsigned short value)
  152. {
  153. struct lance_private *lp = (struct lance_private *)priv;
  154. do {
  155. out_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP, value);
  156. } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
  157. }
  158. static unsigned short hplance_readrdp(void *priv)
  159. {
  160. struct lance_private *lp = (struct lance_private *)priv;
  161. __u16 value;
  162. do {
  163. value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP);
  164. } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
  165. return value;
  166. }
  167. static int hplance_open(struct net_device *dev)
  168. {
  169. int status;
  170. struct lance_private *lp = netdev_priv(dev);
  171. status = lance_open(dev); /* call generic lance open code */
  172. if (status)
  173. return status;
  174. /* enable interrupts at board level. */
  175. out_8(lp->base + HPLANCE_STATUS, LE_IE);
  176. return 0;
  177. }
  178. static int hplance_close(struct net_device *dev)
  179. {
  180. struct lance_private *lp = netdev_priv(dev);
  181. out_8(lp->base + HPLANCE_STATUS, 0); /* disable interrupts at boardlevel */
  182. lance_close(dev);
  183. return 0;
  184. }
  185. static int __init hplance_init_module(void)
  186. {
  187. return dio_register_driver(&hplance_driver);
  188. }
  189. static void __exit hplance_cleanup_module(void)
  190. {
  191. dio_unregister_driver(&hplance_driver);
  192. }
  193. module_init(hplance_init_module);
  194. module_exit(hplance_cleanup_module);
  195. MODULE_LICENSE("GPL");