hplance.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* hplance.c : the Linux/hp300/lance ethernet driver
  3. *
  4. * Copyright (C) 05/1998 Peter Maydell <[email protected]>
  5. * Based on the Sun Lance driver and the NetBSD HP Lance driver
  6. * Uses the generic 7990.c LANCE code.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/types.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/ioport.h>
  13. #include <linux/string.h>
  14. #include <linux/delay.h>
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. #include <linux/pgtable.h>
  18. /* Used for the temporal inet entries and routing */
  19. #include <linux/socket.h>
  20. #include <linux/route.h>
  21. #include <linux/dio.h>
  22. #include <linux/netdevice.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/skbuff.h>
  25. #include <asm/io.h>
  26. #include "hplance.h"
  27. /* We have 16392 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, it takes (8 + 2) * 1544 bytes.
  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 hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent);
  44. static void hplance_init(struct net_device *dev, struct dio_dev *d);
  45. static void hplance_remove_one(struct dio_dev *d);
  46. static void hplance_writerap(void *priv, unsigned short value);
  47. static void hplance_writerdp(void *priv, unsigned short value);
  48. static unsigned short hplance_readrdp(void *priv);
  49. static int hplance_open(struct net_device *dev);
  50. static int hplance_close(struct net_device *dev);
  51. static struct dio_device_id hplance_dio_tbl[] = {
  52. { DIO_ID_LAN },
  53. { 0 }
  54. };
  55. static struct dio_driver hplance_driver = {
  56. .name = "hplance",
  57. .id_table = hplance_dio_tbl,
  58. .probe = hplance_init_one,
  59. .remove = hplance_remove_one,
  60. };
  61. static const struct net_device_ops hplance_netdev_ops = {
  62. .ndo_open = hplance_open,
  63. .ndo_stop = hplance_close,
  64. .ndo_start_xmit = lance_start_xmit,
  65. .ndo_set_rx_mode = lance_set_multicast,
  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. u8 addr[ETH_ALEN];
  112. int i;
  113. /* reset the board */
  114. out_8(va + DIO_IDOFF, 0xff);
  115. udelay(100); /* ariba! ariba! udelay! udelay! */
  116. /* Fill the dev fields */
  117. dev->base_addr = va;
  118. dev->netdev_ops = &hplance_netdev_ops;
  119. dev->dma = 0;
  120. for (i = 0; i < 6; i++) {
  121. /* The NVRAM holds our ethernet address, one nibble per byte,
  122. * at bytes NVRAMOFF+1,3,5,7,9...
  123. */
  124. addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4)
  125. | (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF);
  126. }
  127. eth_hw_addr_set(dev, addr);
  128. lp = netdev_priv(dev);
  129. lp->lance.name = d->name;
  130. lp->lance.base = va;
  131. lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */
  132. lp->lance.lance_init_block = NULL; /* LANCE addr of same RAM */
  133. lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */
  134. lp->lance.irq = d->ipl;
  135. lp->lance.writerap = hplance_writerap;
  136. lp->lance.writerdp = hplance_writerdp;
  137. lp->lance.readrdp = hplance_readrdp;
  138. lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
  139. lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
  140. lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
  141. lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
  142. }
  143. /* This is disgusting. We have to check the DIO status register for ack every
  144. * time we read or write the LANCE registers.
  145. */
  146. static void hplance_writerap(void *priv, unsigned short value)
  147. {
  148. struct lance_private *lp = (struct lance_private *)priv;
  149. do {
  150. out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value);
  151. } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
  152. }
  153. static void hplance_writerdp(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_RDP, value);
  158. } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
  159. }
  160. static unsigned short hplance_readrdp(void *priv)
  161. {
  162. struct lance_private *lp = (struct lance_private *)priv;
  163. __u16 value;
  164. do {
  165. value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP);
  166. } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
  167. return value;
  168. }
  169. static int hplance_open(struct net_device *dev)
  170. {
  171. int status;
  172. struct lance_private *lp = netdev_priv(dev);
  173. status = lance_open(dev); /* call generic lance open code */
  174. if (status)
  175. return status;
  176. /* enable interrupts at board level. */
  177. out_8(lp->base + HPLANCE_STATUS, LE_IE);
  178. return 0;
  179. }
  180. static int hplance_close(struct net_device *dev)
  181. {
  182. struct lance_private *lp = netdev_priv(dev);
  183. out_8(lp->base + HPLANCE_STATUS, 0); /* disable interrupts at boardlevel */
  184. lance_close(dev);
  185. return 0;
  186. }
  187. static int __init hplance_init_module(void)
  188. {
  189. return dio_register_driver(&hplance_driver);
  190. }
  191. static void __exit hplance_cleanup_module(void)
  192. {
  193. dio_unregister_driver(&hplance_driver);
  194. }
  195. module_init(hplance_init_module);
  196. module_exit(hplance_cleanup_module);
  197. MODULE_LICENSE("GPL");