hplance.c 6.9 KB

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