lasi_82596.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* lasi_82596.c -- driver for the intel 82596 ethernet controller, as
  2. munged into HPPA boxen .
  3. This driver is based upon 82596.c, original credits are below...
  4. but there were too many hoops which HP wants jumped through to
  5. keep this code in there in a sane manner.
  6. 3 primary sources of the mess --
  7. 1) hppa needs *lots* of cacheline flushing to keep this kind of
  8. MMIO running.
  9. 2) The 82596 needs to see all of its pointers as their physical
  10. address. Thus virt_to_bus/bus_to_virt are *everywhere*.
  11. 3) The implementation HP is using seems to be significantly pickier
  12. about when and how the command and RX units are started. some
  13. command ordering was changed.
  14. Examination of the mach driver leads one to believe that there
  15. might be a saner way to pull this off... anyone who feels like a
  16. full rewrite can be my guest.
  17. Split 02/13/2000 Sam Creasey (sammy@oh.verio.com)
  18. 02/01/2000 Initial modifications for parisc by Helge Deller (deller@gmx.de)
  19. 03/02/2000 changes for better/correct(?) cache-flushing (deller)
  20. */
  21. /* 82596.c: A generic 82596 ethernet driver for linux. */
  22. /*
  23. Based on Apricot.c
  24. Written 1994 by Mark Evans.
  25. This driver is for the Apricot 82596 bus-master interface
  26. Modularised 12/94 Mark Evans
  27. Modified to support the 82596 ethernet chips on 680x0 VME boards.
  28. by Richard Hirst <richard@sleepie.demon.co.uk>
  29. Renamed to be 82596.c
  30. 980825: Changed to receive directly in to sk_buffs which are
  31. allocated at open() time. Eliminates copy on incoming frames
  32. (small ones are still copied). Shared data now held in a
  33. non-cached page, so we can run on 68060 in copyback mode.
  34. TBD:
  35. * look at deferring rx frames rather than discarding (as per tulip)
  36. * handle tx ring full as per tulip
  37. * performance test to tune rx_copybreak
  38. Most of my modifications relate to the braindead big-endian
  39. implementation by Intel. When the i596 is operating in
  40. 'big-endian' mode, it thinks a 32 bit value of 0x12345678
  41. should be stored as 0x56781234. This is a real pain, when
  42. you have linked lists which are shared by the 680x0 and the
  43. i596.
  44. Driver skeleton
  45. Written 1993 by Donald Becker.
  46. Copyright 1993 United States Government as represented by the Director,
  47. National Security Agency. This software may only be used and distributed
  48. according to the terms of the GNU General Public License as modified by SRC,
  49. incorporated herein by reference.
  50. The author may be reached as becker@scyld.com, or C/O
  51. Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403
  52. */
  53. #include <linux/module.h>
  54. #include <linux/kernel.h>
  55. #include <linux/string.h>
  56. #include <linux/ptrace.h>
  57. #include <linux/errno.h>
  58. #include <linux/ioport.h>
  59. #include <linux/interrupt.h>
  60. #include <linux/delay.h>
  61. #include <linux/netdevice.h>
  62. #include <linux/etherdevice.h>
  63. #include <linux/skbuff.h>
  64. #include <linux/types.h>
  65. #include <linux/bitops.h>
  66. #include <linux/dma-mapping.h>
  67. #include <asm/io.h>
  68. #include <asm/irq.h>
  69. #include <asm/pdc.h>
  70. #include <asm/parisc-device.h>
  71. #define LASI_82596_DRIVER_VERSION "LASI 82596 driver - Revision: 1.30"
  72. #define PA_I82596_RESET 0 /* Offsets relative to LASI-LAN-Addr.*/
  73. #define PA_CPU_PORT_L_ACCESS 4
  74. #define PA_CHANNEL_ATTENTION 8
  75. #define OPT_SWAP_PORT 0x0001 /* Need to wordswp on the MPU port */
  76. #define LIB82596_DMA_ATTR DMA_ATTR_NON_CONSISTENT
  77. #define DMA_WBACK(ndev, addr, len) \
  78. do { dma_cache_sync((ndev)->dev.parent, (void *)addr, len, DMA_TO_DEVICE); } while (0)
  79. #define DMA_INV(ndev, addr, len) \
  80. do { dma_cache_sync((ndev)->dev.parent, (void *)addr, len, DMA_FROM_DEVICE); } while (0)
  81. #define DMA_WBACK_INV(ndev, addr, len) \
  82. do { dma_cache_sync((ndev)->dev.parent, (void *)addr, len, DMA_BIDIRECTIONAL); } while (0)
  83. #define SYSBUS 0x0000006c;
  84. /* big endian CPU, 82596 "big" endian mode */
  85. #define SWAP32(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
  86. #define SWAP16(x) (x)
  87. #include "lib82596.c"
  88. MODULE_AUTHOR("Richard Hirst");
  89. MODULE_DESCRIPTION("i82596 driver");
  90. MODULE_LICENSE("GPL");
  91. module_param(i596_debug, int, 0);
  92. MODULE_PARM_DESC(i596_debug, "lasi_82596 debug mask");
  93. static inline void ca(struct net_device *dev)
  94. {
  95. gsc_writel(0, dev->base_addr + PA_CHANNEL_ATTENTION);
  96. }
  97. static void mpu_port(struct net_device *dev, int c, dma_addr_t x)
  98. {
  99. struct i596_private *lp = netdev_priv(dev);
  100. u32 v = (u32) (c) | (u32) (x);
  101. u16 a, b;
  102. if (lp->options & OPT_SWAP_PORT) {
  103. a = v >> 16;
  104. b = v & 0xffff;
  105. } else {
  106. a = v & 0xffff;
  107. b = v >> 16;
  108. }
  109. gsc_writel(a, dev->base_addr + PA_CPU_PORT_L_ACCESS);
  110. udelay(1);
  111. gsc_writel(b, dev->base_addr + PA_CPU_PORT_L_ACCESS);
  112. }
  113. #define LAN_PROM_ADDR 0xF0810000
  114. static int __init
  115. lan_init_chip(struct parisc_device *dev)
  116. {
  117. struct net_device *netdevice;
  118. struct i596_private *lp;
  119. int retval;
  120. int i;
  121. if (!dev->irq) {
  122. printk(KERN_ERR "%s: IRQ not found for i82596 at 0x%lx\n",
  123. __FILE__, (unsigned long)dev->hpa.start);
  124. return -ENODEV;
  125. }
  126. printk(KERN_INFO "Found i82596 at 0x%lx, IRQ %d\n",
  127. (unsigned long)dev->hpa.start, dev->irq);
  128. netdevice = alloc_etherdev(sizeof(struct i596_private));
  129. if (!netdevice)
  130. return -ENOMEM;
  131. SET_NETDEV_DEV(netdevice, &dev->dev);
  132. parisc_set_drvdata (dev, netdevice);
  133. netdevice->base_addr = dev->hpa.start;
  134. netdevice->irq = dev->irq;
  135. if (pdc_lan_station_id(netdevice->dev_addr, netdevice->base_addr)) {
  136. for (i = 0; i < 6; i++) {
  137. netdevice->dev_addr[i] = gsc_readb(LAN_PROM_ADDR + i);
  138. }
  139. printk(KERN_INFO
  140. "%s: MAC of HP700 LAN read from EEPROM\n", __FILE__);
  141. }
  142. lp = netdev_priv(netdevice);
  143. lp->options = dev->id.sversion == 0x72 ? OPT_SWAP_PORT : 0;
  144. retval = i82596_probe(netdevice);
  145. if (retval) {
  146. free_netdev(netdevice);
  147. return -ENODEV;
  148. }
  149. return retval;
  150. }
  151. static int __exit lan_remove_chip(struct parisc_device *pdev)
  152. {
  153. struct net_device *dev = parisc_get_drvdata(pdev);
  154. struct i596_private *lp = netdev_priv(dev);
  155. unregister_netdev (dev);
  156. dma_free_attrs(&pdev->dev, sizeof(struct i596_private), lp->dma,
  157. lp->dma_addr, LIB82596_DMA_ATTR);
  158. free_netdev (dev);
  159. return 0;
  160. }
  161. static const struct parisc_device_id lan_tbl[] __initconst = {
  162. { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008a },
  163. { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00072 },
  164. { 0, }
  165. };
  166. MODULE_DEVICE_TABLE(parisc, lan_tbl);
  167. static struct parisc_driver lan_driver __refdata = {
  168. .name = "lasi_82596",
  169. .id_table = lan_tbl,
  170. .probe = lan_init_chip,
  171. .remove = __exit_p(lan_remove_chip),
  172. };
  173. static int lasi_82596_init(void)
  174. {
  175. printk(KERN_INFO LASI_82596_DRIVER_VERSION "\n");
  176. return register_parisc_driver(&lan_driver);
  177. }
  178. module_init(lasi_82596_init);
  179. static void __exit lasi_82596_exit(void)
  180. {
  181. unregister_parisc_driver(&lan_driver);
  182. }
  183. module_exit(lasi_82596_exit);