eexpress.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750
  1. /* Intel EtherExpress 16 device driver for Linux
  2. *
  3. * Written by John Sullivan, 1995
  4. * based on original code by Donald Becker, with changes by
  5. * Alan Cox and Pauline Middelink.
  6. *
  7. * Support for 8-bit mode by Zoltan Szilagyi <zoltans@cs.arizona.edu>
  8. *
  9. * Many modifications, and currently maintained, by
  10. * Philip Blundell <philb@gnu.org>
  11. * Added the Compaq LTE Alan Cox <alan@redhat.com>
  12. * Added MCA support Adam Fritzler <mid@auk.cx>
  13. *
  14. * Note - this driver is experimental still - it has problems on faster
  15. * machines. Someone needs to sit down and go through it line by line with
  16. * a databook...
  17. */
  18. /* The EtherExpress 16 is a fairly simple card, based on a shared-memory
  19. * design using the i82586 Ethernet coprocessor. It bears no relationship,
  20. * as far as I know, to the similarly-named "EtherExpress Pro" range.
  21. *
  22. * Historically, Linux support for these cards has been very bad. However,
  23. * things seem to be getting better slowly.
  24. */
  25. /* If your card is confused about what sort of interface it has (eg it
  26. * persistently reports "10baseT" when none is fitted), running 'SOFTSET /BART'
  27. * or 'SOFTSET /LISA' from DOS seems to help.
  28. */
  29. /* Here's the scoop on memory mapping.
  30. *
  31. * There are three ways to access EtherExpress card memory: either using the
  32. * shared-memory mapping, or using PIO through the dataport, or using PIO
  33. * through the "shadow memory" ports.
  34. *
  35. * The shadow memory system works by having the card map some of its memory
  36. * as follows:
  37. *
  38. * (the low five bits of the SMPTR are ignored)
  39. *
  40. * base+0x4000..400f memory at SMPTR+0..15
  41. * base+0x8000..800f memory at SMPTR+16..31
  42. * base+0xc000..c007 dubious stuff (memory at SMPTR+16..23 apparently)
  43. * base+0xc008..c00f memory at 0x0008..0x000f
  44. *
  45. * This last set (the one at c008) is particularly handy because the SCB
  46. * lives at 0x0008. So that set of ports gives us easy random access to data
  47. * in the SCB without having to mess around setting up pointers and the like.
  48. * We always use this method to access the SCB (via the scb_xx() functions).
  49. *
  50. * Dataport access works by aiming the appropriate (read or write) pointer
  51. * at the first address you're interested in, and then reading or writing from
  52. * the dataport. The pointers auto-increment after each transfer. We use
  53. * this for data transfer.
  54. *
  55. * We don't use the shared-memory system because it allegedly doesn't work on
  56. * all cards, and because it's a bit more prone to go wrong (it's one more
  57. * thing to configure...).
  58. */
  59. /* Known bugs:
  60. *
  61. * - The card seems to want to give us two interrupts every time something
  62. * happens, where just one would be better.
  63. */
  64. /*
  65. *
  66. * Note by Zoltan Szilagyi 10-12-96:
  67. *
  68. * I've succeeded in eliminating the "CU wedged" messages, and hence the
  69. * lockups, which were only occurring with cards running in 8-bit mode ("force
  70. * 8-bit operation" in Intel's SoftSet utility). This version of the driver
  71. * sets the 82586 and the ASIC to 8-bit mode at startup; it also stops the
  72. * CU before submitting a packet for transmission, and then restarts it as soon
  73. * as the process of handing the packet is complete. This is definitely an
  74. * unnecessary slowdown if the card is running in 16-bit mode; therefore one
  75. * should detect 16-bit vs 8-bit mode from the EEPROM settings and act
  76. * accordingly. In 8-bit mode with this bugfix I'm getting about 150 K/s for
  77. * ftp's, which is significantly better than I get in DOS, so the overhead of
  78. * stopping and restarting the CU with each transmit is not prohibitive in
  79. * practice.
  80. *
  81. * Update by David Woodhouse 11/5/99:
  82. *
  83. * I've seen "CU wedged" messages in 16-bit mode, on the Alpha architecture.
  84. * I assume that this is because 16-bit accesses are actually handled as two
  85. * 8-bit accesses.
  86. */
  87. #ifdef __alpha__
  88. #define LOCKUP16 1
  89. #endif
  90. #ifndef LOCKUP16
  91. #define LOCKUP16 0
  92. #endif
  93. #include <linux/config.h>
  94. #include <linux/module.h>
  95. #include <linux/kernel.h>
  96. #include <linux/types.h>
  97. #include <linux/fcntl.h>
  98. #include <linux/interrupt.h>
  99. #include <linux/ioport.h>
  100. #include <linux/string.h>
  101. #include <linux/in.h>
  102. #include <linux/delay.h>
  103. #include <linux/errno.h>
  104. #include <linux/init.h>
  105. #include <linux/netdevice.h>
  106. #include <linux/etherdevice.h>
  107. #include <linux/skbuff.h>
  108. #include <linux/slab.h>
  109. #include <linux/mca-legacy.h>
  110. #include <linux/spinlock.h>
  111. #include <linux/bitops.h>
  112. #include <asm/system.h>
  113. #include <asm/io.h>
  114. #include <asm/irq.h>
  115. #ifndef NET_DEBUG
  116. #define NET_DEBUG 4
  117. #endif
  118. #include "eexpress.h"
  119. #define EEXP_IO_EXTENT 16
  120. /*
  121. * Private data declarations
  122. */
  123. struct net_local
  124. {
  125. struct net_device_stats stats;
  126. unsigned long last_tx; /* jiffies when last transmit started */
  127. unsigned long init_time; /* jiffies when eexp_hw_init586 called */
  128. unsigned short rx_first; /* first rx buf, same as RX_BUF_START */
  129. unsigned short rx_last; /* last rx buf */
  130. unsigned short rx_ptr; /* first rx buf to look at */
  131. unsigned short tx_head; /* next free tx buf */
  132. unsigned short tx_reap; /* first in-use tx buf */
  133. unsigned short tx_tail; /* previous tx buf to tx_head */
  134. unsigned short tx_link; /* last known-executing tx buf */
  135. unsigned short last_tx_restart; /* set to tx_link when we
  136. restart the CU */
  137. unsigned char started;
  138. unsigned short rx_buf_start;
  139. unsigned short rx_buf_end;
  140. unsigned short num_tx_bufs;
  141. unsigned short num_rx_bufs;
  142. unsigned char width; /* 0 for 16bit, 1 for 8bit */
  143. unsigned char was_promisc;
  144. unsigned char old_mc_count;
  145. spinlock_t lock;
  146. };
  147. /* This is the code and data that is downloaded to the EtherExpress card's
  148. * memory at boot time.
  149. */
  150. static unsigned short start_code[] = {
  151. /* 0x0000 */
  152. 0x0001, /* ISCP: busy - cleared after reset */
  153. 0x0008,0x0000,0x0000, /* offset,address (lo,hi) of SCB */
  154. 0x0000,0x0000, /* SCB: status, commands */
  155. 0x0000,0x0000, /* links to first command block,
  156. first receive descriptor */
  157. 0x0000,0x0000, /* CRC error, alignment error counts */
  158. 0x0000,0x0000, /* out of resources, overrun error counts */
  159. 0x0000,0x0000, /* pad */
  160. 0x0000,0x0000,
  161. /* 0x20 -- start of 82586 CU program */
  162. #define CONF_LINK 0x20
  163. 0x0000,Cmd_Config,
  164. 0x0032, /* link to next command */
  165. 0x080c, /* 12 bytes follow : fifo threshold=8 */
  166. 0x2e40, /* don't rx bad frames
  167. * SRDY/ARDY => ext. sync. : preamble len=8
  168. * take addresses from data buffers
  169. * 6 bytes/address
  170. */
  171. 0x6000, /* default backoff method & priority
  172. * interframe spacing = 0x60 */
  173. 0xf200, /* slot time=0x200
  174. * max collision retry = 0xf */
  175. #define CONF_PROMISC 0x2e
  176. 0x0000, /* no HDLC : normal CRC : enable broadcast
  177. * disable promiscuous/multicast modes */
  178. 0x003c, /* minimum frame length = 60 octets) */
  179. 0x0000,Cmd_SetAddr,
  180. 0x003e, /* link to next command */
  181. #define CONF_HWADDR 0x38
  182. 0x0000,0x0000,0x0000, /* hardware address placed here */
  183. 0x0000,Cmd_MCast,
  184. 0x0076, /* link to next command */
  185. #define CONF_NR_MULTICAST 0x44
  186. 0x0000, /* number of multicast addresses */
  187. #define CONF_MULTICAST 0x46
  188. 0x0000, 0x0000, 0x0000, /* some addresses */
  189. 0x0000, 0x0000, 0x0000,
  190. 0x0000, 0x0000, 0x0000,
  191. 0x0000, 0x0000, 0x0000,
  192. 0x0000, 0x0000, 0x0000,
  193. 0x0000, 0x0000, 0x0000,
  194. 0x0000, 0x0000, 0x0000,
  195. 0x0000, 0x0000, 0x0000,
  196. #define CONF_DIAG_RESULT 0x76
  197. 0x0000, Cmd_Diag,
  198. 0x007c, /* link to next command */
  199. 0x0000,Cmd_TDR|Cmd_INT,
  200. 0x0084,
  201. #define CONF_TDR_RESULT 0x82
  202. 0x0000,
  203. 0x0000,Cmd_END|Cmd_Nop, /* end of configure sequence */
  204. 0x0084 /* dummy link */
  205. };
  206. /* maps irq number to EtherExpress magic value */
  207. static char irqrmap[] = { 0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0 };
  208. #ifdef CONFIG_MCA_LEGACY
  209. /* mapping of the first four bits of the second POS register */
  210. static unsigned short mca_iomap[] = {
  211. 0x270, 0x260, 0x250, 0x240, 0x230, 0x220, 0x210, 0x200,
  212. 0x370, 0x360, 0x350, 0x340, 0x330, 0x320, 0x310, 0x300
  213. };
  214. /* bits 5-7 of the second POS register */
  215. static char mca_irqmap[] = { 12, 9, 3, 4, 5, 10, 11, 15 };
  216. #endif
  217. /*
  218. * Prototypes for Linux interface
  219. */
  220. static int eexp_open(struct net_device *dev);
  221. static int eexp_close(struct net_device *dev);
  222. static void eexp_timeout(struct net_device *dev);
  223. static struct net_device_stats *eexp_stats(struct net_device *dev);
  224. static int eexp_xmit(struct sk_buff *buf, struct net_device *dev);
  225. static irqreturn_t eexp_irq(int irq, void *dev_addr, struct pt_regs *regs);
  226. static void eexp_set_multicast(struct net_device *dev);
  227. /*
  228. * Prototypes for hardware access functions
  229. */
  230. static void eexp_hw_rx_pio(struct net_device *dev);
  231. static void eexp_hw_tx_pio(struct net_device *dev, unsigned short *buf,
  232. unsigned short len);
  233. static int eexp_hw_probe(struct net_device *dev,unsigned short ioaddr);
  234. static unsigned short eexp_hw_readeeprom(unsigned short ioaddr,
  235. unsigned char location);
  236. static unsigned short eexp_hw_lasttxstat(struct net_device *dev);
  237. static void eexp_hw_txrestart(struct net_device *dev);
  238. static void eexp_hw_txinit (struct net_device *dev);
  239. static void eexp_hw_rxinit (struct net_device *dev);
  240. static void eexp_hw_init586 (struct net_device *dev);
  241. static void eexp_setup_filter (struct net_device *dev);
  242. static char *eexp_ifmap[]={"AUI", "BNC", "RJ45"};
  243. enum eexp_iftype {AUI=0, BNC=1, TPE=2};
  244. #define STARTED_RU 2
  245. #define STARTED_CU 1
  246. /*
  247. * Primitive hardware access functions.
  248. */
  249. static inline unsigned short scb_status(struct net_device *dev)
  250. {
  251. return inw(dev->base_addr + 0xc008);
  252. }
  253. static inline unsigned short scb_rdcmd(struct net_device *dev)
  254. {
  255. return inw(dev->base_addr + 0xc00a);
  256. }
  257. static inline void scb_command(struct net_device *dev, unsigned short cmd)
  258. {
  259. outw(cmd, dev->base_addr + 0xc00a);
  260. }
  261. static inline void scb_wrcbl(struct net_device *dev, unsigned short val)
  262. {
  263. outw(val, dev->base_addr + 0xc00c);
  264. }
  265. static inline void scb_wrrfa(struct net_device *dev, unsigned short val)
  266. {
  267. outw(val, dev->base_addr + 0xc00e);
  268. }
  269. static inline void set_loopback(struct net_device *dev)
  270. {
  271. outb(inb(dev->base_addr + Config) | 2, dev->base_addr + Config);
  272. }
  273. static inline void clear_loopback(struct net_device *dev)
  274. {
  275. outb(inb(dev->base_addr + Config) & ~2, dev->base_addr + Config);
  276. }
  277. static inline unsigned short int SHADOW(short int addr)
  278. {
  279. addr &= 0x1f;
  280. if (addr > 0xf) addr += 0x3ff0;
  281. return addr + 0x4000;
  282. }
  283. /*
  284. * Linux interface
  285. */
  286. /*
  287. * checks for presence of EtherExpress card
  288. */
  289. static int __init do_express_probe(struct net_device *dev)
  290. {
  291. unsigned short *port;
  292. static unsigned short ports[] = { 0x240,0x300,0x310,0x270,0x320,0x340,0 };
  293. unsigned short ioaddr = dev->base_addr;
  294. int dev_irq = dev->irq;
  295. int err;
  296. SET_MODULE_OWNER(dev);
  297. dev->if_port = 0xff; /* not set */
  298. #ifdef CONFIG_MCA_LEGACY
  299. if (MCA_bus) {
  300. int slot = 0;
  301. /*
  302. * Only find one card at a time. Subsequent calls
  303. * will find others, however, proper multicard MCA
  304. * probing and setup can't be done with the
  305. * old-style Space.c init routines. -- ASF
  306. */
  307. while (slot != MCA_NOTFOUND) {
  308. int pos0, pos1;
  309. slot = mca_find_unused_adapter(0x628B, slot);
  310. if (slot == MCA_NOTFOUND)
  311. break;
  312. pos0 = mca_read_stored_pos(slot, 2);
  313. pos1 = mca_read_stored_pos(slot, 3);
  314. ioaddr = mca_iomap[pos1&0xf];
  315. dev->irq = mca_irqmap[(pos1>>4)&0x7];
  316. /*
  317. * XXX: Transciever selection is done
  318. * differently on the MCA version.
  319. * How to get it to select something
  320. * other than external/AUI is currently
  321. * unknown. This code is just for looks. -- ASF
  322. */
  323. if ((pos0 & 0x7) == 0x1)
  324. dev->if_port = AUI;
  325. else if ((pos0 & 0x7) == 0x5) {
  326. if (pos1 & 0x80)
  327. dev->if_port = BNC;
  328. else
  329. dev->if_port = TPE;
  330. }
  331. mca_set_adapter_name(slot, "Intel EtherExpress 16 MCA");
  332. mca_set_adapter_procfn(slot, NULL, dev);
  333. mca_mark_as_used(slot);
  334. break;
  335. }
  336. }
  337. #endif
  338. if (ioaddr&0xfe00) {
  339. if (!request_region(ioaddr, EEXP_IO_EXTENT, "EtherExpress"))
  340. return -EBUSY;
  341. err = eexp_hw_probe(dev,ioaddr);
  342. release_region(ioaddr, EEXP_IO_EXTENT);
  343. return err;
  344. } else if (ioaddr)
  345. return -ENXIO;
  346. for (port=&ports[0] ; *port ; port++ )
  347. {
  348. unsigned short sum = 0;
  349. int i;
  350. if (!request_region(*port, EEXP_IO_EXTENT, "EtherExpress"))
  351. continue;
  352. for ( i=0 ; i<4 ; i++ )
  353. {
  354. unsigned short t;
  355. t = inb(*port + ID_PORT);
  356. sum |= (t>>4) << ((t & 0x03)<<2);
  357. }
  358. if (sum==0xbaba && !eexp_hw_probe(dev,*port)) {
  359. release_region(*port, EEXP_IO_EXTENT);
  360. return 0;
  361. }
  362. release_region(*port, EEXP_IO_EXTENT);
  363. dev->irq = dev_irq;
  364. }
  365. return -ENODEV;
  366. }
  367. #ifndef MODULE
  368. struct net_device * __init express_probe(int unit)
  369. {
  370. struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
  371. int err;
  372. if (!dev)
  373. return ERR_PTR(-ENOMEM);
  374. sprintf(dev->name, "eth%d", unit);
  375. netdev_boot_setup_check(dev);
  376. err = do_express_probe(dev);
  377. if (!err)
  378. return dev;
  379. free_netdev(dev);
  380. return ERR_PTR(err);
  381. }
  382. #endif
  383. /*
  384. * open and initialize the adapter, ready for use
  385. */
  386. static int eexp_open(struct net_device *dev)
  387. {
  388. int ret;
  389. unsigned short ioaddr = dev->base_addr;
  390. struct net_local *lp = netdev_priv(dev);
  391. #if NET_DEBUG > 6
  392. printk(KERN_DEBUG "%s: eexp_open()\n", dev->name);
  393. #endif
  394. if (!dev->irq || !irqrmap[dev->irq])
  395. return -ENXIO;
  396. ret = request_irq(dev->irq,&eexp_irq,0,dev->name,dev);
  397. if (ret) return ret;
  398. if (!request_region(ioaddr, EEXP_IO_EXTENT, "EtherExpress")) {
  399. printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
  400. , ioaddr);
  401. goto err_out1;
  402. }
  403. if (!request_region(ioaddr+0x4000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
  404. printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
  405. , ioaddr+0x4000);
  406. goto err_out2;
  407. }
  408. if (!request_region(ioaddr+0x8000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
  409. printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
  410. , ioaddr+0x8000);
  411. goto err_out3;
  412. }
  413. if (!request_region(ioaddr+0xc000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
  414. printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
  415. , ioaddr+0xc000);
  416. goto err_out4;
  417. }
  418. if (lp->width) {
  419. printk("%s: forcing ASIC to 8-bit mode\n", dev->name);
  420. outb(inb(dev->base_addr+Config)&~4, dev->base_addr+Config);
  421. }
  422. eexp_hw_init586(dev);
  423. netif_start_queue(dev);
  424. #if NET_DEBUG > 6
  425. printk(KERN_DEBUG "%s: leaving eexp_open()\n", dev->name);
  426. #endif
  427. return 0;
  428. err_out4:
  429. release_region(ioaddr+0x8000, EEXP_IO_EXTENT);
  430. err_out3:
  431. release_region(ioaddr+0x4000, EEXP_IO_EXTENT);
  432. err_out2:
  433. release_region(ioaddr, EEXP_IO_EXTENT);
  434. err_out1:
  435. free_irq(dev->irq, dev);
  436. return -EBUSY;
  437. }
  438. /*
  439. * close and disable the interface, leaving the 586 in reset.
  440. */
  441. static int eexp_close(struct net_device *dev)
  442. {
  443. unsigned short ioaddr = dev->base_addr;
  444. struct net_local *lp = netdev_priv(dev);
  445. int irq = dev->irq;
  446. netif_stop_queue(dev);
  447. outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
  448. lp->started = 0;
  449. scb_command(dev, SCB_CUsuspend|SCB_RUsuspend);
  450. outb(0,ioaddr+SIGNAL_CA);
  451. free_irq(irq,dev);
  452. outb(i586_RST,ioaddr+EEPROM_Ctrl);
  453. release_region(ioaddr, EEXP_IO_EXTENT);
  454. release_region(ioaddr+0x4000, 16);
  455. release_region(ioaddr+0x8000, 16);
  456. release_region(ioaddr+0xc000, 16);
  457. return 0;
  458. }
  459. /*
  460. * Return interface stats
  461. */
  462. static struct net_device_stats *eexp_stats(struct net_device *dev)
  463. {
  464. struct net_local *lp = netdev_priv(dev);
  465. return &lp->stats;
  466. }
  467. /*
  468. * This gets called when a higher level thinks we are broken. Check that
  469. * nothing has become jammed in the CU.
  470. */
  471. static void unstick_cu(struct net_device *dev)
  472. {
  473. struct net_local *lp = netdev_priv(dev);
  474. unsigned short ioaddr = dev->base_addr;
  475. if (lp->started)
  476. {
  477. if ((jiffies - dev->trans_start)>50)
  478. {
  479. if (lp->tx_link==lp->last_tx_restart)
  480. {
  481. unsigned short boguscount=200,rsst;
  482. printk(KERN_WARNING "%s: Retransmit timed out, status %04x, resetting...\n",
  483. dev->name, scb_status(dev));
  484. eexp_hw_txinit(dev);
  485. lp->last_tx_restart = 0;
  486. scb_wrcbl(dev, lp->tx_link);
  487. scb_command(dev, SCB_CUstart);
  488. outb(0,ioaddr+SIGNAL_CA);
  489. while (!SCB_complete(rsst=scb_status(dev)))
  490. {
  491. if (!--boguscount)
  492. {
  493. boguscount=200;
  494. printk(KERN_WARNING "%s: Reset timed out status %04x, retrying...\n",
  495. dev->name,rsst);
  496. scb_wrcbl(dev, lp->tx_link);
  497. scb_command(dev, SCB_CUstart);
  498. outb(0,ioaddr+SIGNAL_CA);
  499. }
  500. }
  501. netif_wake_queue(dev);
  502. }
  503. else
  504. {
  505. unsigned short status = scb_status(dev);
  506. if (SCB_CUdead(status))
  507. {
  508. unsigned short txstatus = eexp_hw_lasttxstat(dev);
  509. printk(KERN_WARNING "%s: Transmit timed out, CU not active status %04x %04x, restarting...\n",
  510. dev->name, status, txstatus);
  511. eexp_hw_txrestart(dev);
  512. }
  513. else
  514. {
  515. unsigned short txstatus = eexp_hw_lasttxstat(dev);
  516. if (netif_queue_stopped(dev) && !txstatus)
  517. {
  518. printk(KERN_WARNING "%s: CU wedged, status %04x %04x, resetting...\n",
  519. dev->name,status,txstatus);
  520. eexp_hw_init586(dev);
  521. netif_wake_queue(dev);
  522. }
  523. else
  524. {
  525. printk(KERN_WARNING "%s: transmit timed out\n", dev->name);
  526. }
  527. }
  528. }
  529. }
  530. }
  531. else
  532. {
  533. if ((jiffies-lp->init_time)>10)
  534. {
  535. unsigned short status = scb_status(dev);
  536. printk(KERN_WARNING "%s: i82586 startup timed out, status %04x, resetting...\n",
  537. dev->name, status);
  538. eexp_hw_init586(dev);
  539. netif_wake_queue(dev);
  540. }
  541. }
  542. }
  543. static void eexp_timeout(struct net_device *dev)
  544. {
  545. struct net_local *lp = netdev_priv(dev);
  546. #ifdef CONFIG_SMP
  547. unsigned long flags;
  548. #endif
  549. int status;
  550. disable_irq(dev->irq);
  551. /*
  552. * Best would be to use synchronize_irq(); spin_lock() here
  553. * lets make it work first..
  554. */
  555. #ifdef CONFIG_SMP
  556. spin_lock_irqsave(&lp->lock, flags);
  557. #endif
  558. status = scb_status(dev);
  559. unstick_cu(dev);
  560. printk(KERN_INFO "%s: transmit timed out, %s?\n", dev->name,
  561. (SCB_complete(status)?"lost interrupt":
  562. "board on fire"));
  563. lp->stats.tx_errors++;
  564. lp->last_tx = jiffies;
  565. if (!SCB_complete(status)) {
  566. scb_command(dev, SCB_CUabort);
  567. outb(0,dev->base_addr+SIGNAL_CA);
  568. }
  569. netif_wake_queue(dev);
  570. #ifdef CONFIG_SMP
  571. spin_unlock_irqrestore(&lp->lock, flags);
  572. #endif
  573. }
  574. /*
  575. * Called to transmit a packet, or to allow us to right ourselves
  576. * if the kernel thinks we've died.
  577. */
  578. static int eexp_xmit(struct sk_buff *buf, struct net_device *dev)
  579. {
  580. struct net_local *lp = netdev_priv(dev);
  581. short length = buf->len;
  582. #ifdef CONFIG_SMP
  583. unsigned long flags;
  584. #endif
  585. #if NET_DEBUG > 6
  586. printk(KERN_DEBUG "%s: eexp_xmit()\n", dev->name);
  587. #endif
  588. if (buf->len < ETH_ZLEN) {
  589. buf = skb_padto(buf, ETH_ZLEN);
  590. if (buf == NULL)
  591. return 0;
  592. length = ETH_ZLEN;
  593. }
  594. disable_irq(dev->irq);
  595. /*
  596. * Best would be to use synchronize_irq(); spin_lock() here
  597. * lets make it work first..
  598. */
  599. #ifdef CONFIG_SMP
  600. spin_lock_irqsave(&lp->lock, flags);
  601. #endif
  602. {
  603. unsigned short *data = (unsigned short *)buf->data;
  604. lp->stats.tx_bytes += length;
  605. eexp_hw_tx_pio(dev,data,length);
  606. }
  607. dev_kfree_skb(buf);
  608. #ifdef CONFIG_SMP
  609. spin_unlock_irqrestore(&lp->lock, flags);
  610. #endif
  611. enable_irq(dev->irq);
  612. return 0;
  613. }
  614. /*
  615. * Handle an EtherExpress interrupt
  616. * If we've finished initializing, start the RU and CU up.
  617. * If we've already started, reap tx buffers, handle any received packets,
  618. * check to make sure we've not become wedged.
  619. */
  620. /*
  621. * Handle an EtherExpress interrupt
  622. * If we've finished initializing, start the RU and CU up.
  623. * If we've already started, reap tx buffers, handle any received packets,
  624. * check to make sure we've not become wedged.
  625. */
  626. static unsigned short eexp_start_irq(struct net_device *dev,
  627. unsigned short status)
  628. {
  629. unsigned short ack_cmd = SCB_ack(status);
  630. struct net_local *lp = netdev_priv(dev);
  631. unsigned short ioaddr = dev->base_addr;
  632. if ((dev->flags & IFF_UP) && !(lp->started & STARTED_CU)) {
  633. short diag_status, tdr_status;
  634. while (SCB_CUstat(status)==2)
  635. status = scb_status(dev);
  636. #if NET_DEBUG > 4
  637. printk("%s: CU went non-active (status %04x)\n",
  638. dev->name, status);
  639. #endif
  640. outw(CONF_DIAG_RESULT & ~31, ioaddr + SM_PTR);
  641. diag_status = inw(ioaddr + SHADOW(CONF_DIAG_RESULT));
  642. if (diag_status & 1<<11) {
  643. printk(KERN_WARNING "%s: 82586 failed self-test\n",
  644. dev->name);
  645. } else if (!(diag_status & 1<<13)) {
  646. printk(KERN_WARNING "%s: 82586 self-test failed to complete\n", dev->name);
  647. }
  648. outw(CONF_TDR_RESULT & ~31, ioaddr + SM_PTR);
  649. tdr_status = inw(ioaddr + SHADOW(CONF_TDR_RESULT));
  650. if (tdr_status & (TDR_SHORT|TDR_OPEN)) {
  651. printk(KERN_WARNING "%s: TDR reports cable %s at %d tick%s\n", dev->name, (tdr_status & TDR_SHORT)?"short":"broken", tdr_status & TDR_TIME, ((tdr_status & TDR_TIME) != 1) ? "s" : "");
  652. }
  653. else if (tdr_status & TDR_XCVRPROBLEM) {
  654. printk(KERN_WARNING "%s: TDR reports transceiver problem\n", dev->name);
  655. }
  656. else if (tdr_status & TDR_LINKOK) {
  657. #if NET_DEBUG > 4
  658. printk(KERN_DEBUG "%s: TDR reports link OK\n", dev->name);
  659. #endif
  660. } else {
  661. printk("%s: TDR is ga-ga (status %04x)\n", dev->name,
  662. tdr_status);
  663. }
  664. lp->started |= STARTED_CU;
  665. scb_wrcbl(dev, lp->tx_link);
  666. /* if the RU isn't running, start it now */
  667. if (!(lp->started & STARTED_RU)) {
  668. ack_cmd |= SCB_RUstart;
  669. scb_wrrfa(dev, lp->rx_buf_start);
  670. lp->rx_ptr = lp->rx_buf_start;
  671. lp->started |= STARTED_RU;
  672. }
  673. ack_cmd |= SCB_CUstart | 0x2000;
  674. }
  675. if ((dev->flags & IFF_UP) && !(lp->started & STARTED_RU) && SCB_RUstat(status)==4)
  676. lp->started|=STARTED_RU;
  677. return ack_cmd;
  678. }
  679. static void eexp_cmd_clear(struct net_device *dev)
  680. {
  681. unsigned long int oldtime = jiffies;
  682. while (scb_rdcmd(dev) && ((jiffies-oldtime)<10));
  683. if (scb_rdcmd(dev)) {
  684. printk("%s: command didn't clear\n", dev->name);
  685. }
  686. }
  687. static irqreturn_t eexp_irq(int irq, void *dev_info, struct pt_regs *regs)
  688. {
  689. struct net_device *dev = dev_info;
  690. struct net_local *lp;
  691. unsigned short ioaddr,status,ack_cmd;
  692. unsigned short old_read_ptr, old_write_ptr;
  693. if (dev==NULL)
  694. {
  695. printk(KERN_WARNING "eexpress: irq %d for unknown device\n",
  696. irq);
  697. return IRQ_NONE;
  698. }
  699. lp = netdev_priv(dev);
  700. ioaddr = dev->base_addr;
  701. spin_lock(&lp->lock);
  702. old_read_ptr = inw(ioaddr+READ_PTR);
  703. old_write_ptr = inw(ioaddr+WRITE_PTR);
  704. outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
  705. status = scb_status(dev);
  706. #if NET_DEBUG > 4
  707. printk(KERN_DEBUG "%s: interrupt (status %x)\n", dev->name, status);
  708. #endif
  709. if (lp->started == (STARTED_CU | STARTED_RU)) {
  710. do {
  711. eexp_cmd_clear(dev);
  712. ack_cmd = SCB_ack(status);
  713. scb_command(dev, ack_cmd);
  714. outb(0,ioaddr+SIGNAL_CA);
  715. eexp_cmd_clear(dev);
  716. if (SCB_complete(status)) {
  717. if (!eexp_hw_lasttxstat(dev)) {
  718. printk("%s: tx interrupt but no status\n", dev->name);
  719. }
  720. }
  721. if (SCB_rxdframe(status))
  722. eexp_hw_rx_pio(dev);
  723. status = scb_status(dev);
  724. } while (status & 0xc000);
  725. if (SCB_RUdead(status))
  726. {
  727. printk(KERN_WARNING "%s: RU stopped: status %04x\n",
  728. dev->name,status);
  729. #if 0
  730. printk(KERN_WARNING "%s: cur_rfd=%04x, cur_rbd=%04x\n", dev->name, lp->cur_rfd, lp->cur_rbd);
  731. outw(lp->cur_rfd, ioaddr+READ_PTR);
  732. printk(KERN_WARNING "%s: [%04x]\n", dev->name, inw(ioaddr+DATAPORT));
  733. outw(lp->cur_rfd+6, ioaddr+READ_PTR);
  734. printk(KERN_WARNING "%s: rbd is %04x\n", dev->name, rbd= inw(ioaddr+DATAPORT));
  735. outw(rbd, ioaddr+READ_PTR);
  736. printk(KERN_WARNING "%s: [%04x %04x] ", dev->name, inw(ioaddr+DATAPORT), inw(ioaddr+DATAPORT));
  737. outw(rbd+8, ioaddr+READ_PTR);
  738. printk("[%04x]\n", inw(ioaddr+DATAPORT));
  739. #endif
  740. lp->stats.rx_errors++;
  741. #if 1
  742. eexp_hw_rxinit(dev);
  743. #else
  744. lp->cur_rfd = lp->first_rfd;
  745. #endif
  746. scb_wrrfa(dev, lp->rx_buf_start);
  747. scb_command(dev, SCB_RUstart);
  748. outb(0,ioaddr+SIGNAL_CA);
  749. }
  750. } else {
  751. if (status & 0x8000)
  752. ack_cmd = eexp_start_irq(dev, status);
  753. else
  754. ack_cmd = SCB_ack(status);
  755. scb_command(dev, ack_cmd);
  756. outb(0,ioaddr+SIGNAL_CA);
  757. }
  758. eexp_cmd_clear(dev);
  759. outb(SIRQ_en|irqrmap[irq],ioaddr+SET_IRQ);
  760. #if NET_DEBUG > 6
  761. printk("%s: leaving eexp_irq()\n", dev->name);
  762. #endif
  763. outw(old_read_ptr, ioaddr+READ_PTR);
  764. outw(old_write_ptr, ioaddr+WRITE_PTR);
  765. spin_unlock(&lp->lock);
  766. return IRQ_HANDLED;
  767. }
  768. /*
  769. * Hardware access functions
  770. */
  771. /*
  772. * Set the cable type to use.
  773. */
  774. static void eexp_hw_set_interface(struct net_device *dev)
  775. {
  776. unsigned char oldval = inb(dev->base_addr + 0x300e);
  777. oldval &= ~0x82;
  778. switch (dev->if_port) {
  779. case TPE:
  780. oldval |= 0x2;
  781. case BNC:
  782. oldval |= 0x80;
  783. break;
  784. }
  785. outb(oldval, dev->base_addr+0x300e);
  786. mdelay(20);
  787. }
  788. /*
  789. * Check all the receive buffers, and hand any received packets
  790. * to the upper levels. Basic sanity check on each frame
  791. * descriptor, though we don't bother trying to fix broken ones.
  792. */
  793. static void eexp_hw_rx_pio(struct net_device *dev)
  794. {
  795. struct net_local *lp = netdev_priv(dev);
  796. unsigned short rx_block = lp->rx_ptr;
  797. unsigned short boguscount = lp->num_rx_bufs;
  798. unsigned short ioaddr = dev->base_addr;
  799. unsigned short status;
  800. #if NET_DEBUG > 6
  801. printk(KERN_DEBUG "%s: eexp_hw_rx()\n", dev->name);
  802. #endif
  803. do {
  804. unsigned short rfd_cmd, rx_next, pbuf, pkt_len;
  805. outw(rx_block, ioaddr + READ_PTR);
  806. status = inw(ioaddr + DATAPORT);
  807. if (FD_Done(status))
  808. {
  809. rfd_cmd = inw(ioaddr + DATAPORT);
  810. rx_next = inw(ioaddr + DATAPORT);
  811. pbuf = inw(ioaddr + DATAPORT);
  812. outw(pbuf, ioaddr + READ_PTR);
  813. pkt_len = inw(ioaddr + DATAPORT);
  814. if (rfd_cmd!=0x0000)
  815. {
  816. printk(KERN_WARNING "%s: rfd_cmd not zero:0x%04x\n",
  817. dev->name, rfd_cmd);
  818. continue;
  819. }
  820. else if (pbuf!=rx_block+0x16)
  821. {
  822. printk(KERN_WARNING "%s: rfd and rbd out of sync 0x%04x 0x%04x\n",
  823. dev->name, rx_block+0x16, pbuf);
  824. continue;
  825. }
  826. else if ((pkt_len & 0xc000)!=0xc000)
  827. {
  828. printk(KERN_WARNING "%s: EOF or F not set on received buffer (%04x)\n",
  829. dev->name, pkt_len & 0xc000);
  830. continue;
  831. }
  832. else if (!FD_OK(status))
  833. {
  834. lp->stats.rx_errors++;
  835. if (FD_CRC(status))
  836. lp->stats.rx_crc_errors++;
  837. if (FD_Align(status))
  838. lp->stats.rx_frame_errors++;
  839. if (FD_Resrc(status))
  840. lp->stats.rx_fifo_errors++;
  841. if (FD_DMA(status))
  842. lp->stats.rx_over_errors++;
  843. if (FD_Short(status))
  844. lp->stats.rx_length_errors++;
  845. }
  846. else
  847. {
  848. struct sk_buff *skb;
  849. pkt_len &= 0x3fff;
  850. skb = dev_alloc_skb(pkt_len+16);
  851. if (skb == NULL)
  852. {
  853. printk(KERN_WARNING "%s: Memory squeeze, dropping packet\n",dev->name);
  854. lp->stats.rx_dropped++;
  855. break;
  856. }
  857. skb->dev = dev;
  858. skb_reserve(skb, 2);
  859. outw(pbuf+10, ioaddr+READ_PTR);
  860. insw(ioaddr+DATAPORT, skb_put(skb,pkt_len),(pkt_len+1)>>1);
  861. skb->protocol = eth_type_trans(skb,dev);
  862. netif_rx(skb);
  863. dev->last_rx = jiffies;
  864. lp->stats.rx_packets++;
  865. lp->stats.rx_bytes += pkt_len;
  866. }
  867. outw(rx_block, ioaddr+WRITE_PTR);
  868. outw(0, ioaddr+DATAPORT);
  869. outw(0, ioaddr+DATAPORT);
  870. rx_block = rx_next;
  871. }
  872. } while (FD_Done(status) && boguscount--);
  873. lp->rx_ptr = rx_block;
  874. }
  875. /*
  876. * Hand a packet to the card for transmission
  877. * If we get here, we MUST have already checked
  878. * to make sure there is room in the transmit
  879. * buffer region.
  880. */
  881. static void eexp_hw_tx_pio(struct net_device *dev, unsigned short *buf,
  882. unsigned short len)
  883. {
  884. struct net_local *lp = netdev_priv(dev);
  885. unsigned short ioaddr = dev->base_addr;
  886. if (LOCKUP16 || lp->width) {
  887. /* Stop the CU so that there is no chance that it
  888. jumps off to a bogus address while we are writing the
  889. pointer to the next transmit packet in 8-bit mode --
  890. this eliminates the "CU wedged" errors in 8-bit mode.
  891. (Zoltan Szilagyi 10-12-96) */
  892. scb_command(dev, SCB_CUsuspend);
  893. outw(0xFFFF, ioaddr+SIGNAL_CA);
  894. }
  895. outw(lp->tx_head, ioaddr + WRITE_PTR);
  896. outw(0x0000, ioaddr + DATAPORT);
  897. outw(Cmd_INT|Cmd_Xmit, ioaddr + DATAPORT);
  898. outw(lp->tx_head+0x08, ioaddr + DATAPORT);
  899. outw(lp->tx_head+0x0e, ioaddr + DATAPORT);
  900. outw(0x0000, ioaddr + DATAPORT);
  901. outw(0x0000, ioaddr + DATAPORT);
  902. outw(lp->tx_head+0x08, ioaddr + DATAPORT);
  903. outw(0x8000|len, ioaddr + DATAPORT);
  904. outw(-1, ioaddr + DATAPORT);
  905. outw(lp->tx_head+0x16, ioaddr + DATAPORT);
  906. outw(0, ioaddr + DATAPORT);
  907. outsw(ioaddr + DATAPORT, buf, (len+1)>>1);
  908. outw(lp->tx_tail+0xc, ioaddr + WRITE_PTR);
  909. outw(lp->tx_head, ioaddr + DATAPORT);
  910. dev->trans_start = jiffies;
  911. lp->tx_tail = lp->tx_head;
  912. if (lp->tx_head==TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
  913. lp->tx_head = TX_BUF_START;
  914. else
  915. lp->tx_head += TX_BUF_SIZE;
  916. if (lp->tx_head != lp->tx_reap)
  917. netif_wake_queue(dev);
  918. if (LOCKUP16 || lp->width) {
  919. /* Restart the CU so that the packet can actually
  920. be transmitted. (Zoltan Szilagyi 10-12-96) */
  921. scb_command(dev, SCB_CUresume);
  922. outw(0xFFFF, ioaddr+SIGNAL_CA);
  923. }
  924. lp->stats.tx_packets++;
  925. lp->last_tx = jiffies;
  926. }
  927. /*
  928. * Sanity check the suspected EtherExpress card
  929. * Read hardware address, reset card, size memory and initialize buffer
  930. * memory pointers. These are held in dev->priv, in case someone has more
  931. * than one card in a machine.
  932. */
  933. static int __init eexp_hw_probe(struct net_device *dev, unsigned short ioaddr)
  934. {
  935. unsigned short hw_addr[3];
  936. unsigned char buswidth;
  937. unsigned int memory_size;
  938. int i;
  939. unsigned short xsum = 0;
  940. struct net_local *lp = netdev_priv(dev);
  941. printk("%s: EtherExpress 16 at %#x ",dev->name,ioaddr);
  942. outb(ASIC_RST, ioaddr+EEPROM_Ctrl);
  943. outb(0, ioaddr+EEPROM_Ctrl);
  944. udelay(500);
  945. outb(i586_RST, ioaddr+EEPROM_Ctrl);
  946. hw_addr[0] = eexp_hw_readeeprom(ioaddr,2);
  947. hw_addr[1] = eexp_hw_readeeprom(ioaddr,3);
  948. hw_addr[2] = eexp_hw_readeeprom(ioaddr,4);
  949. /* Standard Address or Compaq LTE Address */
  950. if (!((hw_addr[2]==0x00aa && ((hw_addr[1] & 0xff00)==0x0000)) ||
  951. (hw_addr[2]==0x0080 && ((hw_addr[1] & 0xff00)==0x5F00))))
  952. {
  953. printk(" rejected: invalid address %04x%04x%04x\n",
  954. hw_addr[2],hw_addr[1],hw_addr[0]);
  955. return -ENODEV;
  956. }
  957. /* Calculate the EEPROM checksum. Carry on anyway if it's bad,
  958. * though.
  959. */
  960. for (i = 0; i < 64; i++)
  961. xsum += eexp_hw_readeeprom(ioaddr, i);
  962. if (xsum != 0xbaba)
  963. printk(" (bad EEPROM xsum 0x%02x)", xsum);
  964. dev->base_addr = ioaddr;
  965. for ( i=0 ; i<6 ; i++ )
  966. dev->dev_addr[i] = ((unsigned char *)hw_addr)[5-i];
  967. {
  968. static char irqmap[]={0, 9, 3, 4, 5, 10, 11, 0};
  969. unsigned short setupval = eexp_hw_readeeprom(ioaddr,0);
  970. /* Use the IRQ from EEPROM if none was given */
  971. if (!dev->irq)
  972. dev->irq = irqmap[setupval>>13];
  973. if (dev->if_port == 0xff) {
  974. dev->if_port = !(setupval & 0x1000) ? AUI :
  975. eexp_hw_readeeprom(ioaddr,5) & 0x1 ? TPE : BNC;
  976. }
  977. buswidth = !((setupval & 0x400) >> 10);
  978. }
  979. memset(lp, 0, sizeof(struct net_local));
  980. spin_lock_init(&lp->lock);
  981. printk("(IRQ %d, %s connector, %d-bit bus", dev->irq,
  982. eexp_ifmap[dev->if_port], buswidth?8:16);
  983. if (!request_region(dev->base_addr + 0x300e, 1, "EtherExpress"))
  984. return -EBUSY;
  985. eexp_hw_set_interface(dev);
  986. release_region(dev->base_addr + 0x300e, 1);
  987. /* Find out how much RAM we have on the card */
  988. outw(0, dev->base_addr + WRITE_PTR);
  989. for (i = 0; i < 32768; i++)
  990. outw(0, dev->base_addr + DATAPORT);
  991. for (memory_size = 0; memory_size < 64; memory_size++)
  992. {
  993. outw(memory_size<<10, dev->base_addr + READ_PTR);
  994. if (inw(dev->base_addr+DATAPORT))
  995. break;
  996. outw(memory_size<<10, dev->base_addr + WRITE_PTR);
  997. outw(memory_size | 0x5000, dev->base_addr+DATAPORT);
  998. outw(memory_size<<10, dev->base_addr + READ_PTR);
  999. if (inw(dev->base_addr+DATAPORT) != (memory_size | 0x5000))
  1000. break;
  1001. }
  1002. /* Sort out the number of buffers. We may have 16, 32, 48 or 64k
  1003. * of RAM to play with.
  1004. */
  1005. lp->num_tx_bufs = 4;
  1006. lp->rx_buf_end = 0x3ff6;
  1007. switch (memory_size)
  1008. {
  1009. case 64:
  1010. lp->rx_buf_end += 0x4000;
  1011. case 48:
  1012. lp->num_tx_bufs += 4;
  1013. lp->rx_buf_end += 0x4000;
  1014. case 32:
  1015. lp->rx_buf_end += 0x4000;
  1016. case 16:
  1017. printk(", %dk RAM)\n", memory_size);
  1018. break;
  1019. default:
  1020. printk(") bad memory size (%dk).\n", memory_size);
  1021. return -ENODEV;
  1022. break;
  1023. }
  1024. lp->rx_buf_start = TX_BUF_START + (lp->num_tx_bufs*TX_BUF_SIZE);
  1025. lp->width = buswidth;
  1026. dev->open = eexp_open;
  1027. dev->stop = eexp_close;
  1028. dev->hard_start_xmit = eexp_xmit;
  1029. dev->get_stats = eexp_stats;
  1030. dev->set_multicast_list = &eexp_set_multicast;
  1031. dev->tx_timeout = eexp_timeout;
  1032. dev->watchdog_timeo = 2*HZ;
  1033. return register_netdev(dev);
  1034. }
  1035. /*
  1036. * Read a word from the EtherExpress on-board serial EEPROM.
  1037. * The EEPROM contains 64 words of 16 bits.
  1038. */
  1039. static unsigned short __init eexp_hw_readeeprom(unsigned short ioaddr,
  1040. unsigned char location)
  1041. {
  1042. unsigned short cmd = 0x180|(location&0x7f);
  1043. unsigned short rval = 0,wval = EC_CS|i586_RST;
  1044. int i;
  1045. outb(EC_CS|i586_RST,ioaddr+EEPROM_Ctrl);
  1046. for (i=0x100 ; i ; i>>=1 )
  1047. {
  1048. if (cmd&i)
  1049. wval |= EC_Wr;
  1050. else
  1051. wval &= ~EC_Wr;
  1052. outb(wval,ioaddr+EEPROM_Ctrl);
  1053. outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
  1054. eeprom_delay();
  1055. outb(wval,ioaddr+EEPROM_Ctrl);
  1056. eeprom_delay();
  1057. }
  1058. wval &= ~EC_Wr;
  1059. outb(wval,ioaddr+EEPROM_Ctrl);
  1060. for (i=0x8000 ; i ; i>>=1 )
  1061. {
  1062. outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
  1063. eeprom_delay();
  1064. if (inb(ioaddr+EEPROM_Ctrl)&EC_Rd)
  1065. rval |= i;
  1066. outb(wval,ioaddr+EEPROM_Ctrl);
  1067. eeprom_delay();
  1068. }
  1069. wval &= ~EC_CS;
  1070. outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
  1071. eeprom_delay();
  1072. outb(wval,ioaddr+EEPROM_Ctrl);
  1073. eeprom_delay();
  1074. return rval;
  1075. }
  1076. /*
  1077. * Reap tx buffers and return last transmit status.
  1078. * if ==0 then either:
  1079. * a) we're not transmitting anything, so why are we here?
  1080. * b) we've died.
  1081. * otherwise, Stat_Busy(return) means we've still got some packets
  1082. * to transmit, Stat_Done(return) means our buffers should be empty
  1083. * again
  1084. */
  1085. static unsigned short eexp_hw_lasttxstat(struct net_device *dev)
  1086. {
  1087. struct net_local *lp = netdev_priv(dev);
  1088. unsigned short tx_block = lp->tx_reap;
  1089. unsigned short status;
  1090. if (!netif_queue_stopped(dev) && lp->tx_head==lp->tx_reap)
  1091. return 0x0000;
  1092. do
  1093. {
  1094. outw(tx_block & ~31, dev->base_addr + SM_PTR);
  1095. status = inw(dev->base_addr + SHADOW(tx_block));
  1096. if (!Stat_Done(status))
  1097. {
  1098. lp->tx_link = tx_block;
  1099. return status;
  1100. }
  1101. else
  1102. {
  1103. lp->last_tx_restart = 0;
  1104. lp->stats.collisions += Stat_NoColl(status);
  1105. if (!Stat_OK(status))
  1106. {
  1107. char *whatsup = NULL;
  1108. lp->stats.tx_errors++;
  1109. if (Stat_Abort(status))
  1110. lp->stats.tx_aborted_errors++;
  1111. if (Stat_TNoCar(status)) {
  1112. whatsup = "aborted, no carrier";
  1113. lp->stats.tx_carrier_errors++;
  1114. }
  1115. if (Stat_TNoCTS(status)) {
  1116. whatsup = "aborted, lost CTS";
  1117. lp->stats.tx_carrier_errors++;
  1118. }
  1119. if (Stat_TNoDMA(status)) {
  1120. whatsup = "FIFO underran";
  1121. lp->stats.tx_fifo_errors++;
  1122. }
  1123. if (Stat_TXColl(status)) {
  1124. whatsup = "aborted, too many collisions";
  1125. lp->stats.tx_aborted_errors++;
  1126. }
  1127. if (whatsup)
  1128. printk(KERN_INFO "%s: transmit %s\n",
  1129. dev->name, whatsup);
  1130. }
  1131. else
  1132. lp->stats.tx_packets++;
  1133. }
  1134. if (tx_block == TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
  1135. lp->tx_reap = tx_block = TX_BUF_START;
  1136. else
  1137. lp->tx_reap = tx_block += TX_BUF_SIZE;
  1138. netif_wake_queue(dev);
  1139. }
  1140. while (lp->tx_reap != lp->tx_head);
  1141. lp->tx_link = lp->tx_tail + 0x08;
  1142. return status;
  1143. }
  1144. /*
  1145. * This should never happen. It is called when some higher routine detects
  1146. * that the CU has stopped, to try to restart it from the last packet we knew
  1147. * we were working on, or the idle loop if we had finished for the time.
  1148. */
  1149. static void eexp_hw_txrestart(struct net_device *dev)
  1150. {
  1151. struct net_local *lp = netdev_priv(dev);
  1152. unsigned short ioaddr = dev->base_addr;
  1153. lp->last_tx_restart = lp->tx_link;
  1154. scb_wrcbl(dev, lp->tx_link);
  1155. scb_command(dev, SCB_CUstart);
  1156. outb(0,ioaddr+SIGNAL_CA);
  1157. {
  1158. unsigned short boguscount=50,failcount=5;
  1159. while (!scb_status(dev))
  1160. {
  1161. if (!--boguscount)
  1162. {
  1163. if (--failcount)
  1164. {
  1165. printk(KERN_WARNING "%s: CU start timed out, status %04x, cmd %04x\n", dev->name, scb_status(dev), scb_rdcmd(dev));
  1166. scb_wrcbl(dev, lp->tx_link);
  1167. scb_command(dev, SCB_CUstart);
  1168. outb(0,ioaddr+SIGNAL_CA);
  1169. boguscount = 100;
  1170. }
  1171. else
  1172. {
  1173. printk(KERN_WARNING "%s: Failed to restart CU, resetting board...\n",dev->name);
  1174. eexp_hw_init586(dev);
  1175. netif_wake_queue(dev);
  1176. return;
  1177. }
  1178. }
  1179. }
  1180. }
  1181. }
  1182. /*
  1183. * Writes down the list of transmit buffers into card memory. Each
  1184. * entry consists of an 82586 transmit command, followed by a jump
  1185. * pointing to itself. When we want to transmit a packet, we write
  1186. * the data into the appropriate transmit buffer and then modify the
  1187. * preceding jump to point at the new transmit command. This means that
  1188. * the 586 command unit is continuously active.
  1189. */
  1190. static void eexp_hw_txinit(struct net_device *dev)
  1191. {
  1192. struct net_local *lp = netdev_priv(dev);
  1193. unsigned short tx_block = TX_BUF_START;
  1194. unsigned short curtbuf;
  1195. unsigned short ioaddr = dev->base_addr;
  1196. for ( curtbuf=0 ; curtbuf<lp->num_tx_bufs ; curtbuf++ )
  1197. {
  1198. outw(tx_block, ioaddr + WRITE_PTR);
  1199. outw(0x0000, ioaddr + DATAPORT);
  1200. outw(Cmd_INT|Cmd_Xmit, ioaddr + DATAPORT);
  1201. outw(tx_block+0x08, ioaddr + DATAPORT);
  1202. outw(tx_block+0x0e, ioaddr + DATAPORT);
  1203. outw(0x0000, ioaddr + DATAPORT);
  1204. outw(0x0000, ioaddr + DATAPORT);
  1205. outw(tx_block+0x08, ioaddr + DATAPORT);
  1206. outw(0x8000, ioaddr + DATAPORT);
  1207. outw(-1, ioaddr + DATAPORT);
  1208. outw(tx_block+0x16, ioaddr + DATAPORT);
  1209. outw(0x0000, ioaddr + DATAPORT);
  1210. tx_block += TX_BUF_SIZE;
  1211. }
  1212. lp->tx_head = TX_BUF_START;
  1213. lp->tx_reap = TX_BUF_START;
  1214. lp->tx_tail = tx_block - TX_BUF_SIZE;
  1215. lp->tx_link = lp->tx_tail + 0x08;
  1216. lp->rx_buf_start = tx_block;
  1217. }
  1218. /*
  1219. * Write the circular list of receive buffer descriptors to card memory.
  1220. * The end of the list isn't marked, which means that the 82586 receive
  1221. * unit will loop until buffers become available (this avoids it giving us
  1222. * "out of resources" messages).
  1223. */
  1224. static void eexp_hw_rxinit(struct net_device *dev)
  1225. {
  1226. struct net_local *lp = netdev_priv(dev);
  1227. unsigned short rx_block = lp->rx_buf_start;
  1228. unsigned short ioaddr = dev->base_addr;
  1229. lp->num_rx_bufs = 0;
  1230. lp->rx_first = lp->rx_ptr = rx_block;
  1231. do
  1232. {
  1233. lp->num_rx_bufs++;
  1234. outw(rx_block, ioaddr + WRITE_PTR);
  1235. outw(0, ioaddr + DATAPORT); outw(0, ioaddr+DATAPORT);
  1236. outw(rx_block + RX_BUF_SIZE, ioaddr+DATAPORT);
  1237. outw(0xffff, ioaddr+DATAPORT);
  1238. outw(0x0000, ioaddr+DATAPORT);
  1239. outw(0xdead, ioaddr+DATAPORT);
  1240. outw(0xdead, ioaddr+DATAPORT);
  1241. outw(0xdead, ioaddr+DATAPORT);
  1242. outw(0xdead, ioaddr+DATAPORT);
  1243. outw(0xdead, ioaddr+DATAPORT);
  1244. outw(0xdead, ioaddr+DATAPORT);
  1245. outw(0x0000, ioaddr+DATAPORT);
  1246. outw(rx_block + RX_BUF_SIZE + 0x16, ioaddr+DATAPORT);
  1247. outw(rx_block + 0x20, ioaddr+DATAPORT);
  1248. outw(0, ioaddr+DATAPORT);
  1249. outw(RX_BUF_SIZE-0x20, ioaddr+DATAPORT);
  1250. lp->rx_last = rx_block;
  1251. rx_block += RX_BUF_SIZE;
  1252. } while (rx_block <= lp->rx_buf_end-RX_BUF_SIZE);
  1253. /* Make first Rx frame descriptor point to first Rx buffer
  1254. descriptor */
  1255. outw(lp->rx_first + 6, ioaddr+WRITE_PTR);
  1256. outw(lp->rx_first + 0x16, ioaddr+DATAPORT);
  1257. /* Close Rx frame descriptor ring */
  1258. outw(lp->rx_last + 4, ioaddr+WRITE_PTR);
  1259. outw(lp->rx_first, ioaddr+DATAPORT);
  1260. /* Close Rx buffer descriptor ring */
  1261. outw(lp->rx_last + 0x16 + 2, ioaddr+WRITE_PTR);
  1262. outw(lp->rx_first + 0x16, ioaddr+DATAPORT);
  1263. }
  1264. /*
  1265. * Un-reset the 586, and start the configuration sequence. We don't wait for
  1266. * this to finish, but allow the interrupt handler to start the CU and RU for
  1267. * us. We can't start the receive/transmission system up before we know that
  1268. * the hardware is configured correctly.
  1269. */
  1270. static void eexp_hw_init586(struct net_device *dev)
  1271. {
  1272. struct net_local *lp = netdev_priv(dev);
  1273. unsigned short ioaddr = dev->base_addr;
  1274. int i;
  1275. #if NET_DEBUG > 6
  1276. printk("%s: eexp_hw_init586()\n", dev->name);
  1277. #endif
  1278. lp->started = 0;
  1279. set_loopback(dev);
  1280. outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
  1281. /* Download the startup code */
  1282. outw(lp->rx_buf_end & ~31, ioaddr + SM_PTR);
  1283. outw(lp->width?0x0001:0x0000, ioaddr + 0x8006);
  1284. outw(0x0000, ioaddr + 0x8008);
  1285. outw(0x0000, ioaddr + 0x800a);
  1286. outw(0x0000, ioaddr + 0x800c);
  1287. outw(0x0000, ioaddr + 0x800e);
  1288. for (i = 0; i < (sizeof(start_code)); i+=32) {
  1289. int j;
  1290. outw(i, ioaddr + SM_PTR);
  1291. for (j = 0; j < 16; j+=2)
  1292. outw(start_code[(i+j)/2],
  1293. ioaddr+0x4000+j);
  1294. for (j = 0; j < 16; j+=2)
  1295. outw(start_code[(i+j+16)/2],
  1296. ioaddr+0x8000+j);
  1297. }
  1298. /* Do we want promiscuous mode or multicast? */
  1299. outw(CONF_PROMISC & ~31, ioaddr+SM_PTR);
  1300. i = inw(ioaddr+SHADOW(CONF_PROMISC));
  1301. outw((dev->flags & IFF_PROMISC)?(i|1):(i & ~1),
  1302. ioaddr+SHADOW(CONF_PROMISC));
  1303. lp->was_promisc = dev->flags & IFF_PROMISC;
  1304. #if 0
  1305. eexp_setup_filter(dev);
  1306. #endif
  1307. /* Write our hardware address */
  1308. outw(CONF_HWADDR & ~31, ioaddr+SM_PTR);
  1309. outw(((unsigned short *)dev->dev_addr)[0], ioaddr+SHADOW(CONF_HWADDR));
  1310. outw(((unsigned short *)dev->dev_addr)[1],
  1311. ioaddr+SHADOW(CONF_HWADDR+2));
  1312. outw(((unsigned short *)dev->dev_addr)[2],
  1313. ioaddr+SHADOW(CONF_HWADDR+4));
  1314. eexp_hw_txinit(dev);
  1315. eexp_hw_rxinit(dev);
  1316. outb(0,ioaddr+EEPROM_Ctrl);
  1317. mdelay(5);
  1318. scb_command(dev, 0xf000);
  1319. outb(0,ioaddr+SIGNAL_CA);
  1320. outw(0, ioaddr+SM_PTR);
  1321. {
  1322. unsigned short rboguscount=50,rfailcount=5;
  1323. while (inw(ioaddr+0x4000))
  1324. {
  1325. if (!--rboguscount)
  1326. {
  1327. printk(KERN_WARNING "%s: i82586 reset timed out, kicking...\n",
  1328. dev->name);
  1329. scb_command(dev, 0);
  1330. outb(0,ioaddr+SIGNAL_CA);
  1331. rboguscount = 100;
  1332. if (!--rfailcount)
  1333. {
  1334. printk(KERN_WARNING "%s: i82586 not responding, giving up.\n",
  1335. dev->name);
  1336. return;
  1337. }
  1338. }
  1339. }
  1340. }
  1341. scb_wrcbl(dev, CONF_LINK);
  1342. scb_command(dev, 0xf000|SCB_CUstart);
  1343. outb(0,ioaddr+SIGNAL_CA);
  1344. {
  1345. unsigned short iboguscount=50,ifailcount=5;
  1346. while (!scb_status(dev))
  1347. {
  1348. if (!--iboguscount)
  1349. {
  1350. if (--ifailcount)
  1351. {
  1352. printk(KERN_WARNING "%s: i82586 initialization timed out, status %04x, cmd %04x\n",
  1353. dev->name, scb_status(dev), scb_rdcmd(dev));
  1354. scb_wrcbl(dev, CONF_LINK);
  1355. scb_command(dev, 0xf000|SCB_CUstart);
  1356. outb(0,ioaddr+SIGNAL_CA);
  1357. iboguscount = 100;
  1358. }
  1359. else
  1360. {
  1361. printk(KERN_WARNING "%s: Failed to initialize i82586, giving up.\n",dev->name);
  1362. return;
  1363. }
  1364. }
  1365. }
  1366. }
  1367. clear_loopback(dev);
  1368. outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
  1369. lp->init_time = jiffies;
  1370. #if NET_DEBUG > 6
  1371. printk("%s: leaving eexp_hw_init586()\n", dev->name);
  1372. #endif
  1373. return;
  1374. }
  1375. static void eexp_setup_filter(struct net_device *dev)
  1376. {
  1377. struct dev_mc_list *dmi = dev->mc_list;
  1378. unsigned short ioaddr = dev->base_addr;
  1379. int count = dev->mc_count;
  1380. int i;
  1381. if (count > 8) {
  1382. printk(KERN_INFO "%s: too many multicast addresses (%d)\n",
  1383. dev->name, count);
  1384. count = 8;
  1385. }
  1386. outw(CONF_NR_MULTICAST & ~31, ioaddr+SM_PTR);
  1387. outw(count, ioaddr+SHADOW(CONF_NR_MULTICAST));
  1388. for (i = 0; i < count; i++) {
  1389. unsigned short *data = (unsigned short *)dmi->dmi_addr;
  1390. if (!dmi) {
  1391. printk(KERN_INFO "%s: too few multicast addresses\n", dev->name);
  1392. break;
  1393. }
  1394. if (dmi->dmi_addrlen != ETH_ALEN) {
  1395. printk(KERN_INFO "%s: invalid multicast address length given.\n", dev->name);
  1396. continue;
  1397. }
  1398. outw((CONF_MULTICAST+(6*i)) & ~31, ioaddr+SM_PTR);
  1399. outw(data[0], ioaddr+SHADOW(CONF_MULTICAST+(6*i)));
  1400. outw((CONF_MULTICAST+(6*i)+2) & ~31, ioaddr+SM_PTR);
  1401. outw(data[1], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+2));
  1402. outw((CONF_MULTICAST+(6*i)+4) & ~31, ioaddr+SM_PTR);
  1403. outw(data[2], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+4));
  1404. }
  1405. }
  1406. /*
  1407. * Set or clear the multicast filter for this adaptor.
  1408. */
  1409. static void
  1410. eexp_set_multicast(struct net_device *dev)
  1411. {
  1412. unsigned short ioaddr = dev->base_addr;
  1413. struct net_local *lp = netdev_priv(dev);
  1414. int kick = 0, i;
  1415. if ((dev->flags & IFF_PROMISC) != lp->was_promisc) {
  1416. outw(CONF_PROMISC & ~31, ioaddr+SM_PTR);
  1417. i = inw(ioaddr+SHADOW(CONF_PROMISC));
  1418. outw((dev->flags & IFF_PROMISC)?(i|1):(i & ~1),
  1419. ioaddr+SHADOW(CONF_PROMISC));
  1420. lp->was_promisc = dev->flags & IFF_PROMISC;
  1421. kick = 1;
  1422. }
  1423. if (!(dev->flags & IFF_PROMISC)) {
  1424. eexp_setup_filter(dev);
  1425. if (lp->old_mc_count != dev->mc_count) {
  1426. kick = 1;
  1427. lp->old_mc_count = dev->mc_count;
  1428. }
  1429. }
  1430. if (kick) {
  1431. unsigned long oj;
  1432. scb_command(dev, SCB_CUsuspend);
  1433. outb(0, ioaddr+SIGNAL_CA);
  1434. outb(0, ioaddr+SIGNAL_CA);
  1435. #if 0
  1436. printk("%s: waiting for CU to go suspended\n", dev->name);
  1437. #endif
  1438. oj = jiffies;
  1439. while ((SCB_CUstat(scb_status(dev)) == 2) &&
  1440. ((jiffies-oj) < 2000));
  1441. if (SCB_CUstat(scb_status(dev)) == 2)
  1442. printk("%s: warning, CU didn't stop\n", dev->name);
  1443. lp->started &= ~(STARTED_CU);
  1444. scb_wrcbl(dev, CONF_LINK);
  1445. scb_command(dev, SCB_CUstart);
  1446. outb(0, ioaddr+SIGNAL_CA);
  1447. }
  1448. }
  1449. /*
  1450. * MODULE stuff
  1451. */
  1452. #ifdef MODULE
  1453. #define EEXP_MAX_CARDS 4 /* max number of cards to support */
  1454. static struct net_device *dev_eexp[EEXP_MAX_CARDS];
  1455. static int irq[EEXP_MAX_CARDS];
  1456. static int io[EEXP_MAX_CARDS];
  1457. module_param_array(io, int, NULL, 0);
  1458. module_param_array(irq, int, NULL, 0);
  1459. MODULE_PARM_DESC(io, "EtherExpress 16 I/O base address(es)");
  1460. MODULE_PARM_DESC(irq, "EtherExpress 16 IRQ number(s)");
  1461. MODULE_LICENSE("GPL");
  1462. /* Ideally the user would give us io=, irq= for every card. If any parameters
  1463. * are specified, we verify and then use them. If no parameters are given, we
  1464. * autoprobe for one card only.
  1465. */
  1466. int init_module(void)
  1467. {
  1468. struct net_device *dev;
  1469. int this_dev, found = 0;
  1470. for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
  1471. dev = alloc_etherdev(sizeof(struct net_local));
  1472. dev->irq = irq[this_dev];
  1473. dev->base_addr = io[this_dev];
  1474. if (io[this_dev] == 0) {
  1475. if (this_dev)
  1476. break;
  1477. printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n");
  1478. }
  1479. if (do_express_probe(dev) == 0) {
  1480. dev_eexp[this_dev] = dev;
  1481. found++;
  1482. continue;
  1483. }
  1484. printk(KERN_WARNING "eexpress.c: Failed to register card at 0x%x.\n", io[this_dev]);
  1485. free_netdev(dev);
  1486. break;
  1487. }
  1488. if (found)
  1489. return 0;
  1490. return -ENXIO;
  1491. }
  1492. void cleanup_module(void)
  1493. {
  1494. int this_dev;
  1495. for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
  1496. struct net_device *dev = dev_eexp[this_dev];
  1497. if (dev) {
  1498. unregister_netdev(dev);
  1499. free_netdev(dev);
  1500. }
  1501. }
  1502. }
  1503. #endif
  1504. /*
  1505. * Local Variables:
  1506. * c-file-style: "linux"
  1507. * tab-width: 8
  1508. * End:
  1509. */