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