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