eexpress.c 46 KB

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