lasi_82596.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. if (!running_on_qemu)
  111. udelay(1);
  112. gsc_writel(b, dev->base_addr + PA_CPU_PORT_L_ACCESS);
  113. }
  114. #define LAN_PROM_ADDR 0xF0810000
  115. static int __init
  116. lan_init_chip(struct parisc_device *dev)
  117. {
  118. struct net_device *netdevice;
  119. struct i596_private *lp;
  120. int retval;
  121. int i;
  122. if (!dev->irq) {
  123. printk(KERN_ERR "%s: IRQ not found for i82596 at 0x%lx\n",
  124. __FILE__, (unsigned long)dev->hpa.start);
  125. return -ENODEV;
  126. }
  127. printk(KERN_INFO "Found i82596 at 0x%lx, IRQ %d\n",
  128. (unsigned long)dev->hpa.start, dev->irq);
  129. netdevice = alloc_etherdev(sizeof(struct i596_private));
  130. if (!netdevice)
  131. return -ENOMEM;
  132. SET_NETDEV_DEV(netdevice, &dev->dev);
  133. parisc_set_drvdata (dev, netdevice);
  134. netdevice->base_addr = dev->hpa.start;
  135. netdevice->irq = dev->irq;
  136. if (pdc_lan_station_id(netdevice->dev_addr, netdevice->base_addr)) {
  137. for (i = 0; i < 6; i++) {
  138. netdevice->dev_addr[i] = gsc_readb(LAN_PROM_ADDR + i);
  139. }
  140. printk(KERN_INFO
  141. "%s: MAC of HP700 LAN read from EEPROM\n", __FILE__);
  142. }
  143. lp = netdev_priv(netdevice);
  144. lp->options = dev->id.sversion == 0x72 ? OPT_SWAP_PORT : 0;
  145. retval = i82596_probe(netdevice);
  146. if (retval) {
  147. free_netdev(netdevice);
  148. return -ENODEV;
  149. }
  150. return retval;
  151. }
  152. static int __exit lan_remove_chip(struct parisc_device *pdev)
  153. {
  154. struct net_device *dev = parisc_get_drvdata(pdev);
  155. struct i596_private *lp = netdev_priv(dev);
  156. unregister_netdev (dev);
  157. dma_free_attrs(&pdev->dev, sizeof(struct i596_private), lp->dma,
  158. lp->dma_addr, LIB82596_DMA_ATTR);
  159. free_netdev (dev);
  160. return 0;
  161. }
  162. static const struct parisc_device_id lan_tbl[] __initconst = {
  163. { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008a },
  164. { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00072 },
  165. { 0, }
  166. };
  167. MODULE_DEVICE_TABLE(parisc, lan_tbl);
  168. static struct parisc_driver lan_driver __refdata = {
  169. .name = "lasi_82596",
  170. .id_table = lan_tbl,
  171. .probe = lan_init_chip,
  172. .remove = __exit_p(lan_remove_chip),
  173. };
  174. static int lasi_82596_init(void)
  175. {
  176. printk(KERN_INFO LASI_82596_DRIVER_VERSION "\n");
  177. return register_parisc_driver(&lan_driver);
  178. }
  179. module_init(lasi_82596_init);
  180. static void __exit lasi_82596_exit(void)
  181. {
  182. unregister_parisc_driver(&lan_driver);
  183. }
  184. module_exit(lasi_82596_exit);