hplance.c 7.1 KB

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