eexpress.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752
  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. err = register_netdev(dev);
  379. if (!err)
  380. return dev;
  381. }
  382. free_netdev(dev);
  383. return ERR_PTR(err);
  384. }
  385. #endif
  386. /*
  387. * open and initialize the adapter, ready for use
  388. */
  389. static int eexp_open(struct net_device *dev)
  390. {
  391. int ret;
  392. unsigned short ioaddr = dev->base_addr;
  393. struct net_local *lp = netdev_priv(dev);
  394. #if NET_DEBUG > 6
  395. printk(KERN_DEBUG "%s: eexp_open()\n", dev->name);
  396. #endif
  397. if (!dev->irq || !irqrmap[dev->irq])
  398. return -ENXIO;
  399. ret = request_irq(dev->irq,&eexp_irq,0,dev->name,dev);
  400. if (ret) return ret;
  401. if (!request_region(ioaddr, EEXP_IO_EXTENT, "EtherExpress")) {
  402. printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
  403. , ioaddr);
  404. goto err_out1;
  405. }
  406. if (!request_region(ioaddr+0x4000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
  407. printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
  408. , ioaddr+0x4000);
  409. goto err_out2;
  410. }
  411. if (!request_region(ioaddr+0x8000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
  412. printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
  413. , ioaddr+0x8000);
  414. goto err_out3;
  415. }
  416. if (!request_region(ioaddr+0xc000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
  417. printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
  418. , ioaddr+0xc000);
  419. goto err_out4;
  420. }
  421. if (lp->width) {
  422. printk("%s: forcing ASIC to 8-bit mode\n", dev->name);
  423. outb(inb(dev->base_addr+Config)&~4, dev->base_addr+Config);
  424. }
  425. eexp_hw_init586(dev);
  426. netif_start_queue(dev);
  427. #if NET_DEBUG > 6
  428. printk(KERN_DEBUG "%s: leaving eexp_open()\n", dev->name);
  429. #endif
  430. return 0;
  431. err_out4:
  432. release_region(ioaddr+0x8000, EEXP_IO_EXTENT);
  433. err_out3:
  434. release_region(ioaddr+0x4000, EEXP_IO_EXTENT);
  435. err_out2:
  436. release_region(ioaddr, EEXP_IO_EXTENT);
  437. err_out1:
  438. free_irq(dev->irq, dev);
  439. return -EBUSY;
  440. }
  441. /*
  442. * close and disable the interface, leaving the 586 in reset.
  443. */
  444. static int eexp_close(struct net_device *dev)
  445. {
  446. unsigned short ioaddr = dev->base_addr;
  447. struct net_local *lp = netdev_priv(dev);
  448. int irq = dev->irq;
  449. netif_stop_queue(dev);
  450. outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
  451. lp->started = 0;
  452. scb_command(dev, SCB_CUsuspend|SCB_RUsuspend);
  453. outb(0,ioaddr+SIGNAL_CA);
  454. free_irq(irq,dev);
  455. outb(i586_RST,ioaddr+EEPROM_Ctrl);
  456. release_region(ioaddr, EEXP_IO_EXTENT);
  457. release_region(ioaddr+0x4000, 16);
  458. release_region(ioaddr+0x8000, 16);
  459. release_region(ioaddr+0xc000, 16);
  460. return 0;
  461. }
  462. /*
  463. * Return interface stats
  464. */
  465. static struct net_device_stats *eexp_stats(struct net_device *dev)
  466. {
  467. struct net_local *lp = netdev_priv(dev);
  468. return &lp->stats;
  469. }
  470. /*
  471. * This gets called when a higher level thinks we are broken. Check that
  472. * nothing has become jammed in the CU.
  473. */
  474. static void unstick_cu(struct net_device *dev)
  475. {
  476. struct net_local *lp = netdev_priv(dev);
  477. unsigned short ioaddr = dev->base_addr;
  478. if (lp->started)
  479. {
  480. if ((jiffies - dev->trans_start)>50)
  481. {
  482. if (lp->tx_link==lp->last_tx_restart)
  483. {
  484. unsigned short boguscount=200,rsst;
  485. printk(KERN_WARNING "%s: Retransmit timed out, status %04x, resetting...\n",
  486. dev->name, scb_status(dev));
  487. eexp_hw_txinit(dev);
  488. lp->last_tx_restart = 0;
  489. scb_wrcbl(dev, lp->tx_link);
  490. scb_command(dev, SCB_CUstart);
  491. outb(0,ioaddr+SIGNAL_CA);
  492. while (!SCB_complete(rsst=scb_status(dev)))
  493. {
  494. if (!--boguscount)
  495. {
  496. boguscount=200;
  497. printk(KERN_WARNING "%s: Reset timed out status %04x, retrying...\n",
  498. dev->name,rsst);
  499. scb_wrcbl(dev, lp->tx_link);
  500. scb_command(dev, SCB_CUstart);
  501. outb(0,ioaddr+SIGNAL_CA);
  502. }
  503. }
  504. netif_wake_queue(dev);
  505. }
  506. else
  507. {
  508. unsigned short status = scb_status(dev);
  509. if (SCB_CUdead(status))
  510. {
  511. unsigned short txstatus = eexp_hw_lasttxstat(dev);
  512. printk(KERN_WARNING "%s: Transmit timed out, CU not active status %04x %04x, restarting...\n",
  513. dev->name, status, txstatus);
  514. eexp_hw_txrestart(dev);
  515. }
  516. else
  517. {
  518. unsigned short txstatus = eexp_hw_lasttxstat(dev);
  519. if (netif_queue_stopped(dev) && !txstatus)
  520. {
  521. printk(KERN_WARNING "%s: CU wedged, status %04x %04x, resetting...\n",
  522. dev->name,status,txstatus);
  523. eexp_hw_init586(dev);
  524. netif_wake_queue(dev);
  525. }
  526. else
  527. {
  528. printk(KERN_WARNING "%s: transmit timed out\n", dev->name);
  529. }
  530. }
  531. }
  532. }
  533. }
  534. else
  535. {
  536. if ((jiffies-lp->init_time)>10)
  537. {
  538. unsigned short status = scb_status(dev);
  539. printk(KERN_WARNING "%s: i82586 startup timed out, status %04x, resetting...\n",
  540. dev->name, status);
  541. eexp_hw_init586(dev);
  542. netif_wake_queue(dev);
  543. }
  544. }
  545. }
  546. static void eexp_timeout(struct net_device *dev)
  547. {
  548. struct net_local *lp = netdev_priv(dev);
  549. #ifdef CONFIG_SMP
  550. unsigned long flags;
  551. #endif
  552. int status;
  553. disable_irq(dev->irq);
  554. /*
  555. * Best would be to use synchronize_irq(); spin_lock() here
  556. * lets make it work first..
  557. */
  558. #ifdef CONFIG_SMP
  559. spin_lock_irqsave(&lp->lock, flags);
  560. #endif
  561. status = scb_status(dev);
  562. unstick_cu(dev);
  563. printk(KERN_INFO "%s: transmit timed out, %s?\n", dev->name,
  564. (SCB_complete(status)?"lost interrupt":
  565. "board on fire"));
  566. lp->stats.tx_errors++;
  567. lp->last_tx = jiffies;
  568. if (!SCB_complete(status)) {
  569. scb_command(dev, SCB_CUabort);
  570. outb(0,dev->base_addr+SIGNAL_CA);
  571. }
  572. netif_wake_queue(dev);
  573. #ifdef CONFIG_SMP
  574. spin_unlock_irqrestore(&lp->lock, flags);
  575. #endif
  576. }
  577. /*
  578. * Called to transmit a packet, or to allow us to right ourselves
  579. * if the kernel thinks we've died.
  580. */
  581. static int eexp_xmit(struct sk_buff *buf, struct net_device *dev)
  582. {
  583. struct net_local *lp = netdev_priv(dev);
  584. short length = buf->len;
  585. #ifdef CONFIG_SMP
  586. unsigned long flags;
  587. #endif
  588. #if NET_DEBUG > 6
  589. printk(KERN_DEBUG "%s: eexp_xmit()\n", dev->name);
  590. #endif
  591. if (buf->len < ETH_ZLEN) {
  592. buf = skb_padto(buf, ETH_ZLEN);
  593. if (buf == NULL)
  594. return 0;
  595. length = ETH_ZLEN;
  596. }
  597. disable_irq(dev->irq);
  598. /*
  599. * Best would be to use synchronize_irq(); spin_lock() here
  600. * lets make it work first..
  601. */
  602. #ifdef CONFIG_SMP
  603. spin_lock_irqsave(&lp->lock, flags);
  604. #endif
  605. {
  606. unsigned short *data = (unsigned short *)buf->data;
  607. lp->stats.tx_bytes += length;
  608. eexp_hw_tx_pio(dev,data,length);
  609. }
  610. dev_kfree_skb(buf);
  611. #ifdef CONFIG_SMP
  612. spin_unlock_irqrestore(&lp->lock, flags);
  613. #endif
  614. enable_irq(dev->irq);
  615. return 0;
  616. }
  617. /*
  618. * Handle an EtherExpress interrupt
  619. * If we've finished initializing, start the RU and CU up.
  620. * If we've already started, reap tx buffers, handle any received packets,
  621. * check to make sure we've not become wedged.
  622. */
  623. /*
  624. * Handle an EtherExpress interrupt
  625. * If we've finished initializing, start the RU and CU up.
  626. * If we've already started, reap tx buffers, handle any received packets,
  627. * check to make sure we've not become wedged.
  628. */
  629. static unsigned short eexp_start_irq(struct net_device *dev,
  630. unsigned short status)
  631. {
  632. unsigned short ack_cmd = SCB_ack(status);
  633. struct net_local *lp = netdev_priv(dev);
  634. unsigned short ioaddr = dev->base_addr;
  635. if ((dev->flags & IFF_UP) && !(lp->started & STARTED_CU)) {
  636. short diag_status, tdr_status;
  637. while (SCB_CUstat(status)==2)
  638. status = scb_status(dev);
  639. #if NET_DEBUG > 4
  640. printk("%s: CU went non-active (status %04x)\n",
  641. dev->name, status);
  642. #endif
  643. outw(CONF_DIAG_RESULT & ~31, ioaddr + SM_PTR);
  644. diag_status = inw(ioaddr + SHADOW(CONF_DIAG_RESULT));
  645. if (diag_status & 1<<11) {
  646. printk(KERN_WARNING "%s: 82586 failed self-test\n",
  647. dev->name);
  648. } else if (!(diag_status & 1<<13)) {
  649. printk(KERN_WARNING "%s: 82586 self-test failed to complete\n", dev->name);
  650. }
  651. outw(CONF_TDR_RESULT & ~31, ioaddr + SM_PTR);
  652. tdr_status = inw(ioaddr + SHADOW(CONF_TDR_RESULT));
  653. if (tdr_status & (TDR_SHORT|TDR_OPEN)) {
  654. 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" : "");
  655. }
  656. else if (tdr_status & TDR_XCVRPROBLEM) {
  657. printk(KERN_WARNING "%s: TDR reports transceiver problem\n", dev->name);
  658. }
  659. else if (tdr_status & TDR_LINKOK) {
  660. #if NET_DEBUG > 4
  661. printk(KERN_DEBUG "%s: TDR reports link OK\n", dev->name);
  662. #endif
  663. } else {
  664. printk("%s: TDR is ga-ga (status %04x)\n", dev->name,
  665. tdr_status);
  666. }
  667. lp->started |= STARTED_CU;
  668. scb_wrcbl(dev, lp->tx_link);
  669. /* if the RU isn't running, start it now */
  670. if (!(lp->started & STARTED_RU)) {
  671. ack_cmd |= SCB_RUstart;
  672. scb_wrrfa(dev, lp->rx_buf_start);
  673. lp->rx_ptr = lp->rx_buf_start;
  674. lp->started |= STARTED_RU;
  675. }
  676. ack_cmd |= SCB_CUstart | 0x2000;
  677. }
  678. if ((dev->flags & IFF_UP) && !(lp->started & STARTED_RU) && SCB_RUstat(status)==4)
  679. lp->started|=STARTED_RU;
  680. return ack_cmd;
  681. }
  682. static void eexp_cmd_clear(struct net_device *dev)
  683. {
  684. unsigned long int oldtime = jiffies;
  685. while (scb_rdcmd(dev) && ((jiffies-oldtime)<10));
  686. if (scb_rdcmd(dev)) {
  687. printk("%s: command didn't clear\n", dev->name);
  688. }
  689. }
  690. static irqreturn_t eexp_irq(int irq, void *dev_info, struct pt_regs *regs)
  691. {
  692. struct net_device *dev = dev_info;
  693. struct net_local *lp;
  694. unsigned short ioaddr,status,ack_cmd;
  695. unsigned short old_read_ptr, old_write_ptr;
  696. if (dev==NULL)
  697. {
  698. printk(KERN_WARNING "eexpress: irq %d for unknown device\n",
  699. irq);
  700. return IRQ_NONE;
  701. }
  702. lp = netdev_priv(dev);
  703. ioaddr = dev->base_addr;
  704. spin_lock(&lp->lock);
  705. old_read_ptr = inw(ioaddr+READ_PTR);
  706. old_write_ptr = inw(ioaddr+WRITE_PTR);
  707. outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
  708. status = scb_status(dev);
  709. #if NET_DEBUG > 4
  710. printk(KERN_DEBUG "%s: interrupt (status %x)\n", dev->name, status);
  711. #endif
  712. if (lp->started == (STARTED_CU | STARTED_RU)) {
  713. do {
  714. eexp_cmd_clear(dev);
  715. ack_cmd = SCB_ack(status);
  716. scb_command(dev, ack_cmd);
  717. outb(0,ioaddr+SIGNAL_CA);
  718. eexp_cmd_clear(dev);
  719. if (SCB_complete(status)) {
  720. if (!eexp_hw_lasttxstat(dev)) {
  721. printk("%s: tx interrupt but no status\n", dev->name);
  722. }
  723. }
  724. if (SCB_rxdframe(status))
  725. eexp_hw_rx_pio(dev);
  726. status = scb_status(dev);
  727. } while (status & 0xc000);
  728. if (SCB_RUdead(status))
  729. {
  730. printk(KERN_WARNING "%s: RU stopped: status %04x\n",
  731. dev->name,status);
  732. #if 0
  733. printk(KERN_WARNING "%s: cur_rfd=%04x, cur_rbd=%04x\n", dev->name, lp->cur_rfd, lp->cur_rbd);
  734. outw(lp->cur_rfd, ioaddr+READ_PTR);
  735. printk(KERN_WARNING "%s: [%04x]\n", dev->name, inw(ioaddr+DATAPORT));
  736. outw(lp->cur_rfd+6, ioaddr+READ_PTR);
  737. printk(KERN_WARNING "%s: rbd is %04x\n", dev->name, rbd= inw(ioaddr+DATAPORT));
  738. outw(rbd, ioaddr+READ_PTR);
  739. printk(KERN_WARNING "%s: [%04x %04x] ", dev->name, inw(ioaddr+DATAPORT), inw(ioaddr+DATAPORT));
  740. outw(rbd+8, ioaddr+READ_PTR);
  741. printk("[%04x]\n", inw(ioaddr+DATAPORT));
  742. #endif
  743. lp->stats.rx_errors++;
  744. #if 1
  745. eexp_hw_rxinit(dev);
  746. #else
  747. lp->cur_rfd = lp->first_rfd;
  748. #endif
  749. scb_wrrfa(dev, lp->rx_buf_start);
  750. scb_command(dev, SCB_RUstart);
  751. outb(0,ioaddr+SIGNAL_CA);
  752. }
  753. } else {
  754. if (status & 0x8000)
  755. ack_cmd = eexp_start_irq(dev, status);
  756. else
  757. ack_cmd = SCB_ack(status);
  758. scb_command(dev, ack_cmd);
  759. outb(0,ioaddr+SIGNAL_CA);
  760. }
  761. eexp_cmd_clear(dev);
  762. outb(SIRQ_en|irqrmap[irq],ioaddr+SET_IRQ);
  763. #if NET_DEBUG > 6
  764. printk("%s: leaving eexp_irq()\n", dev->name);
  765. #endif
  766. outw(old_read_ptr, ioaddr+READ_PTR);
  767. outw(old_write_ptr, ioaddr+WRITE_PTR);
  768. spin_unlock(&lp->lock);
  769. return IRQ_HANDLED;
  770. }
  771. /*
  772. * Hardware access functions
  773. */
  774. /*
  775. * Set the cable type to use.
  776. */
  777. static void eexp_hw_set_interface(struct net_device *dev)
  778. {
  779. unsigned char oldval = inb(dev->base_addr + 0x300e);
  780. oldval &= ~0x82;
  781. switch (dev->if_port) {
  782. case TPE:
  783. oldval |= 0x2;
  784. case BNC:
  785. oldval |= 0x80;
  786. break;
  787. }
  788. outb(oldval, dev->base_addr+0x300e);
  789. mdelay(20);
  790. }
  791. /*
  792. * Check all the receive buffers, and hand any received packets
  793. * to the upper levels. Basic sanity check on each frame
  794. * descriptor, though we don't bother trying to fix broken ones.
  795. */
  796. static void eexp_hw_rx_pio(struct net_device *dev)
  797. {
  798. struct net_local *lp = netdev_priv(dev);
  799. unsigned short rx_block = lp->rx_ptr;
  800. unsigned short boguscount = lp->num_rx_bufs;
  801. unsigned short ioaddr = dev->base_addr;
  802. unsigned short status;
  803. #if NET_DEBUG > 6
  804. printk(KERN_DEBUG "%s: eexp_hw_rx()\n", dev->name);
  805. #endif
  806. do {
  807. unsigned short rfd_cmd, rx_next, pbuf, pkt_len;
  808. outw(rx_block, ioaddr + READ_PTR);
  809. status = inw(ioaddr + DATAPORT);
  810. if (FD_Done(status))
  811. {
  812. rfd_cmd = inw(ioaddr + DATAPORT);
  813. rx_next = inw(ioaddr + DATAPORT);
  814. pbuf = inw(ioaddr + DATAPORT);
  815. outw(pbuf, ioaddr + READ_PTR);
  816. pkt_len = inw(ioaddr + DATAPORT);
  817. if (rfd_cmd!=0x0000)
  818. {
  819. printk(KERN_WARNING "%s: rfd_cmd not zero:0x%04x\n",
  820. dev->name, rfd_cmd);
  821. continue;
  822. }
  823. else if (pbuf!=rx_block+0x16)
  824. {
  825. printk(KERN_WARNING "%s: rfd and rbd out of sync 0x%04x 0x%04x\n",
  826. dev->name, rx_block+0x16, pbuf);
  827. continue;
  828. }
  829. else if ((pkt_len & 0xc000)!=0xc000)
  830. {
  831. printk(KERN_WARNING "%s: EOF or F not set on received buffer (%04x)\n",
  832. dev->name, pkt_len & 0xc000);
  833. continue;
  834. }
  835. else if (!FD_OK(status))
  836. {
  837. lp->stats.rx_errors++;
  838. if (FD_CRC(status))
  839. lp->stats.rx_crc_errors++;
  840. if (FD_Align(status))
  841. lp->stats.rx_frame_errors++;
  842. if (FD_Resrc(status))
  843. lp->stats.rx_fifo_errors++;
  844. if (FD_DMA(status))
  845. lp->stats.rx_over_errors++;
  846. if (FD_Short(status))
  847. lp->stats.rx_length_errors++;
  848. }
  849. else
  850. {
  851. struct sk_buff *skb;
  852. pkt_len &= 0x3fff;
  853. skb = dev_alloc_skb(pkt_len+16);
  854. if (skb == NULL)
  855. {
  856. printk(KERN_WARNING "%s: Memory squeeze, dropping packet\n",dev->name);
  857. lp->stats.rx_dropped++;
  858. break;
  859. }
  860. skb->dev = dev;
  861. skb_reserve(skb, 2);
  862. outw(pbuf+10, ioaddr+READ_PTR);
  863. insw(ioaddr+DATAPORT, skb_put(skb,pkt_len),(pkt_len+1)>>1);
  864. skb->protocol = eth_type_trans(skb,dev);
  865. netif_rx(skb);
  866. dev->last_rx = jiffies;
  867. lp->stats.rx_packets++;
  868. lp->stats.rx_bytes += pkt_len;
  869. }
  870. outw(rx_block, ioaddr+WRITE_PTR);
  871. outw(0, ioaddr+DATAPORT);
  872. outw(0, ioaddr+DATAPORT);
  873. rx_block = rx_next;
  874. }
  875. } while (FD_Done(status) && boguscount--);
  876. lp->rx_ptr = rx_block;
  877. }
  878. /*
  879. * Hand a packet to the card for transmission
  880. * If we get here, we MUST have already checked
  881. * to make sure there is room in the transmit
  882. * buffer region.
  883. */
  884. static void eexp_hw_tx_pio(struct net_device *dev, unsigned short *buf,
  885. unsigned short len)
  886. {
  887. struct net_local *lp = netdev_priv(dev);
  888. unsigned short ioaddr = dev->base_addr;
  889. if (LOCKUP16 || lp->width) {
  890. /* Stop the CU so that there is no chance that it
  891. jumps off to a bogus address while we are writing the
  892. pointer to the next transmit packet in 8-bit mode --
  893. this eliminates the "CU wedged" errors in 8-bit mode.
  894. (Zoltan Szilagyi 10-12-96) */
  895. scb_command(dev, SCB_CUsuspend);
  896. outw(0xFFFF, ioaddr+SIGNAL_CA);
  897. }
  898. outw(lp->tx_head, ioaddr + WRITE_PTR);
  899. outw(0x0000, ioaddr + DATAPORT);
  900. outw(Cmd_INT|Cmd_Xmit, ioaddr + DATAPORT);
  901. outw(lp->tx_head+0x08, ioaddr + DATAPORT);
  902. outw(lp->tx_head+0x0e, ioaddr + DATAPORT);
  903. outw(0x0000, ioaddr + DATAPORT);
  904. outw(0x0000, ioaddr + DATAPORT);
  905. outw(lp->tx_head+0x08, ioaddr + DATAPORT);
  906. outw(0x8000|len, ioaddr + DATAPORT);
  907. outw(-1, ioaddr + DATAPORT);
  908. outw(lp->tx_head+0x16, ioaddr + DATAPORT);
  909. outw(0, ioaddr + DATAPORT);
  910. outsw(ioaddr + DATAPORT, buf, (len+1)>>1);
  911. outw(lp->tx_tail+0xc, ioaddr + WRITE_PTR);
  912. outw(lp->tx_head, ioaddr + DATAPORT);
  913. dev->trans_start = jiffies;
  914. lp->tx_tail = lp->tx_head;
  915. if (lp->tx_head==TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
  916. lp->tx_head = TX_BUF_START;
  917. else
  918. lp->tx_head += TX_BUF_SIZE;
  919. if (lp->tx_head != lp->tx_reap)
  920. netif_wake_queue(dev);
  921. if (LOCKUP16 || lp->width) {
  922. /* Restart the CU so that the packet can actually
  923. be transmitted. (Zoltan Szilagyi 10-12-96) */
  924. scb_command(dev, SCB_CUresume);
  925. outw(0xFFFF, ioaddr+SIGNAL_CA);
  926. }
  927. lp->stats.tx_packets++;
  928. lp->last_tx = jiffies;
  929. }
  930. /*
  931. * Sanity check the suspected EtherExpress card
  932. * Read hardware address, reset card, size memory and initialize buffer
  933. * memory pointers. These are held in dev->priv, in case someone has more
  934. * than one card in a machine.
  935. */
  936. static int __init eexp_hw_probe(struct net_device *dev, unsigned short ioaddr)
  937. {
  938. unsigned short hw_addr[3];
  939. unsigned char buswidth;
  940. unsigned int memory_size;
  941. int i;
  942. unsigned short xsum = 0;
  943. struct net_local *lp = netdev_priv(dev);
  944. printk("%s: EtherExpress 16 at %#x ",dev->name,ioaddr);
  945. outb(ASIC_RST, ioaddr+EEPROM_Ctrl);
  946. outb(0, ioaddr+EEPROM_Ctrl);
  947. udelay(500);
  948. outb(i586_RST, ioaddr+EEPROM_Ctrl);
  949. hw_addr[0] = eexp_hw_readeeprom(ioaddr,2);
  950. hw_addr[1] = eexp_hw_readeeprom(ioaddr,3);
  951. hw_addr[2] = eexp_hw_readeeprom(ioaddr,4);
  952. /* Standard Address or Compaq LTE Address */
  953. if (!((hw_addr[2]==0x00aa && ((hw_addr[1] & 0xff00)==0x0000)) ||
  954. (hw_addr[2]==0x0080 && ((hw_addr[1] & 0xff00)==0x5F00))))
  955. {
  956. printk(" rejected: invalid address %04x%04x%04x\n",
  957. hw_addr[2],hw_addr[1],hw_addr[0]);
  958. return -ENODEV;
  959. }
  960. /* Calculate the EEPROM checksum. Carry on anyway if it's bad,
  961. * though.
  962. */
  963. for (i = 0; i < 64; i++)
  964. xsum += eexp_hw_readeeprom(ioaddr, i);
  965. if (xsum != 0xbaba)
  966. printk(" (bad EEPROM xsum 0x%02x)", xsum);
  967. dev->base_addr = ioaddr;
  968. for ( i=0 ; i<6 ; i++ )
  969. dev->dev_addr[i] = ((unsigned char *)hw_addr)[5-i];
  970. {
  971. static char irqmap[]={0, 9, 3, 4, 5, 10, 11, 0};
  972. unsigned short setupval = eexp_hw_readeeprom(ioaddr,0);
  973. /* Use the IRQ from EEPROM if none was given */
  974. if (!dev->irq)
  975. dev->irq = irqmap[setupval>>13];
  976. if (dev->if_port == 0xff) {
  977. dev->if_port = !(setupval & 0x1000) ? AUI :
  978. eexp_hw_readeeprom(ioaddr,5) & 0x1 ? TPE : BNC;
  979. }
  980. buswidth = !((setupval & 0x400) >> 10);
  981. }
  982. memset(lp, 0, sizeof(struct net_local));
  983. spin_lock_init(&lp->lock);
  984. printk("(IRQ %d, %s connector, %d-bit bus", dev->irq,
  985. eexp_ifmap[dev->if_port], buswidth?8:16);
  986. if (!request_region(dev->base_addr + 0x300e, 1, "EtherExpress"))
  987. return -EBUSY;
  988. eexp_hw_set_interface(dev);
  989. release_region(dev->base_addr + 0x300e, 1);
  990. /* Find out how much RAM we have on the card */
  991. outw(0, dev->base_addr + WRITE_PTR);
  992. for (i = 0; i < 32768; i++)
  993. outw(0, dev->base_addr + DATAPORT);
  994. for (memory_size = 0; memory_size < 64; memory_size++)
  995. {
  996. outw(memory_size<<10, dev->base_addr + READ_PTR);
  997. if (inw(dev->base_addr+DATAPORT))
  998. break;
  999. outw(memory_size<<10, dev->base_addr + WRITE_PTR);
  1000. outw(memory_size | 0x5000, dev->base_addr+DATAPORT);
  1001. outw(memory_size<<10, dev->base_addr + READ_PTR);
  1002. if (inw(dev->base_addr+DATAPORT) != (memory_size | 0x5000))
  1003. break;
  1004. }
  1005. /* Sort out the number of buffers. We may have 16, 32, 48 or 64k
  1006. * of RAM to play with.
  1007. */
  1008. lp->num_tx_bufs = 4;
  1009. lp->rx_buf_end = 0x3ff6;
  1010. switch (memory_size)
  1011. {
  1012. case 64:
  1013. lp->rx_buf_end += 0x4000;
  1014. case 48:
  1015. lp->num_tx_bufs += 4;
  1016. lp->rx_buf_end += 0x4000;
  1017. case 32:
  1018. lp->rx_buf_end += 0x4000;
  1019. case 16:
  1020. printk(", %dk RAM)\n", memory_size);
  1021. break;
  1022. default:
  1023. printk(") bad memory size (%dk).\n", memory_size);
  1024. return -ENODEV;
  1025. break;
  1026. }
  1027. lp->rx_buf_start = TX_BUF_START + (lp->num_tx_bufs*TX_BUF_SIZE);
  1028. lp->width = buswidth;
  1029. dev->open = eexp_open;
  1030. dev->stop = eexp_close;
  1031. dev->hard_start_xmit = eexp_xmit;
  1032. dev->get_stats = eexp_stats;
  1033. dev->set_multicast_list = &eexp_set_multicast;
  1034. dev->tx_timeout = eexp_timeout;
  1035. dev->watchdog_timeo = 2*HZ;
  1036. return 0;
  1037. }
  1038. /*
  1039. * Read a word from the EtherExpress on-board serial EEPROM.
  1040. * The EEPROM contains 64 words of 16 bits.
  1041. */
  1042. static unsigned short __init eexp_hw_readeeprom(unsigned short ioaddr,
  1043. unsigned char location)
  1044. {
  1045. unsigned short cmd = 0x180|(location&0x7f);
  1046. unsigned short rval = 0,wval = EC_CS|i586_RST;
  1047. int i;
  1048. outb(EC_CS|i586_RST,ioaddr+EEPROM_Ctrl);
  1049. for (i=0x100 ; i ; i>>=1 )
  1050. {
  1051. if (cmd&i)
  1052. wval |= EC_Wr;
  1053. else
  1054. wval &= ~EC_Wr;
  1055. outb(wval,ioaddr+EEPROM_Ctrl);
  1056. outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
  1057. eeprom_delay();
  1058. outb(wval,ioaddr+EEPROM_Ctrl);
  1059. eeprom_delay();
  1060. }
  1061. wval &= ~EC_Wr;
  1062. outb(wval,ioaddr+EEPROM_Ctrl);
  1063. for (i=0x8000 ; i ; i>>=1 )
  1064. {
  1065. outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
  1066. eeprom_delay();
  1067. if (inb(ioaddr+EEPROM_Ctrl)&EC_Rd)
  1068. rval |= i;
  1069. outb(wval,ioaddr+EEPROM_Ctrl);
  1070. eeprom_delay();
  1071. }
  1072. wval &= ~EC_CS;
  1073. outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
  1074. eeprom_delay();
  1075. outb(wval,ioaddr+EEPROM_Ctrl);
  1076. eeprom_delay();
  1077. return rval;
  1078. }
  1079. /*
  1080. * Reap tx buffers and return last transmit status.
  1081. * if ==0 then either:
  1082. * a) we're not transmitting anything, so why are we here?
  1083. * b) we've died.
  1084. * otherwise, Stat_Busy(return) means we've still got some packets
  1085. * to transmit, Stat_Done(return) means our buffers should be empty
  1086. * again
  1087. */
  1088. static unsigned short eexp_hw_lasttxstat(struct net_device *dev)
  1089. {
  1090. struct net_local *lp = netdev_priv(dev);
  1091. unsigned short tx_block = lp->tx_reap;
  1092. unsigned short status;
  1093. if (!netif_queue_stopped(dev) && lp->tx_head==lp->tx_reap)
  1094. return 0x0000;
  1095. do
  1096. {
  1097. outw(tx_block & ~31, dev->base_addr + SM_PTR);
  1098. status = inw(dev->base_addr + SHADOW(tx_block));
  1099. if (!Stat_Done(status))
  1100. {
  1101. lp->tx_link = tx_block;
  1102. return status;
  1103. }
  1104. else
  1105. {
  1106. lp->last_tx_restart = 0;
  1107. lp->stats.collisions += Stat_NoColl(status);
  1108. if (!Stat_OK(status))
  1109. {
  1110. char *whatsup = NULL;
  1111. lp->stats.tx_errors++;
  1112. if (Stat_Abort(status))
  1113. lp->stats.tx_aborted_errors++;
  1114. if (Stat_TNoCar(status)) {
  1115. whatsup = "aborted, no carrier";
  1116. lp->stats.tx_carrier_errors++;
  1117. }
  1118. if (Stat_TNoCTS(status)) {
  1119. whatsup = "aborted, lost CTS";
  1120. lp->stats.tx_carrier_errors++;
  1121. }
  1122. if (Stat_TNoDMA(status)) {
  1123. whatsup = "FIFO underran";
  1124. lp->stats.tx_fifo_errors++;
  1125. }
  1126. if (Stat_TXColl(status)) {
  1127. whatsup = "aborted, too many collisions";
  1128. lp->stats.tx_aborted_errors++;
  1129. }
  1130. if (whatsup)
  1131. printk(KERN_INFO "%s: transmit %s\n",
  1132. dev->name, whatsup);
  1133. }
  1134. else
  1135. lp->stats.tx_packets++;
  1136. }
  1137. if (tx_block == TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
  1138. lp->tx_reap = tx_block = TX_BUF_START;
  1139. else
  1140. lp->tx_reap = tx_block += TX_BUF_SIZE;
  1141. netif_wake_queue(dev);
  1142. }
  1143. while (lp->tx_reap != lp->tx_head);
  1144. lp->tx_link = lp->tx_tail + 0x08;
  1145. return status;
  1146. }
  1147. /*
  1148. * This should never happen. It is called when some higher routine detects
  1149. * that the CU has stopped, to try to restart it from the last packet we knew
  1150. * we were working on, or the idle loop if we had finished for the time.
  1151. */
  1152. static void eexp_hw_txrestart(struct net_device *dev)
  1153. {
  1154. struct net_local *lp = netdev_priv(dev);
  1155. unsigned short ioaddr = dev->base_addr;
  1156. lp->last_tx_restart = lp->tx_link;
  1157. scb_wrcbl(dev, lp->tx_link);
  1158. scb_command(dev, SCB_CUstart);
  1159. outb(0,ioaddr+SIGNAL_CA);
  1160. {
  1161. unsigned short boguscount=50,failcount=5;
  1162. while (!scb_status(dev))
  1163. {
  1164. if (!--boguscount)
  1165. {
  1166. if (--failcount)
  1167. {
  1168. printk(KERN_WARNING "%s: CU start timed out, status %04x, cmd %04x\n", dev->name, scb_status(dev), scb_rdcmd(dev));
  1169. scb_wrcbl(dev, lp->tx_link);
  1170. scb_command(dev, SCB_CUstart);
  1171. outb(0,ioaddr+SIGNAL_CA);
  1172. boguscount = 100;
  1173. }
  1174. else
  1175. {
  1176. printk(KERN_WARNING "%s: Failed to restart CU, resetting board...\n",dev->name);
  1177. eexp_hw_init586(dev);
  1178. netif_wake_queue(dev);
  1179. return;
  1180. }
  1181. }
  1182. }
  1183. }
  1184. }
  1185. /*
  1186. * Writes down the list of transmit buffers into card memory. Each
  1187. * entry consists of an 82586 transmit command, followed by a jump
  1188. * pointing to itself. When we want to transmit a packet, we write
  1189. * the data into the appropriate transmit buffer and then modify the
  1190. * preceding jump to point at the new transmit command. This means that
  1191. * the 586 command unit is continuously active.
  1192. */
  1193. static void eexp_hw_txinit(struct net_device *dev)
  1194. {
  1195. struct net_local *lp = netdev_priv(dev);
  1196. unsigned short tx_block = TX_BUF_START;
  1197. unsigned short curtbuf;
  1198. unsigned short ioaddr = dev->base_addr;
  1199. for ( curtbuf=0 ; curtbuf<lp->num_tx_bufs ; curtbuf++ )
  1200. {
  1201. outw(tx_block, ioaddr + WRITE_PTR);
  1202. outw(0x0000, ioaddr + DATAPORT);
  1203. outw(Cmd_INT|Cmd_Xmit, ioaddr + DATAPORT);
  1204. outw(tx_block+0x08, ioaddr + DATAPORT);
  1205. outw(tx_block+0x0e, ioaddr + DATAPORT);
  1206. outw(0x0000, ioaddr + DATAPORT);
  1207. outw(0x0000, ioaddr + DATAPORT);
  1208. outw(tx_block+0x08, ioaddr + DATAPORT);
  1209. outw(0x8000, ioaddr + DATAPORT);
  1210. outw(-1, ioaddr + DATAPORT);
  1211. outw(tx_block+0x16, ioaddr + DATAPORT);
  1212. outw(0x0000, ioaddr + DATAPORT);
  1213. tx_block += TX_BUF_SIZE;
  1214. }
  1215. lp->tx_head = TX_BUF_START;
  1216. lp->tx_reap = TX_BUF_START;
  1217. lp->tx_tail = tx_block - TX_BUF_SIZE;
  1218. lp->tx_link = lp->tx_tail + 0x08;
  1219. lp->rx_buf_start = tx_block;
  1220. }
  1221. /*
  1222. * Write the circular list of receive buffer descriptors to card memory.
  1223. * The end of the list isn't marked, which means that the 82586 receive
  1224. * unit will loop until buffers become available (this avoids it giving us
  1225. * "out of resources" messages).
  1226. */
  1227. static void eexp_hw_rxinit(struct net_device *dev)
  1228. {
  1229. struct net_local *lp = netdev_priv(dev);
  1230. unsigned short rx_block = lp->rx_buf_start;
  1231. unsigned short ioaddr = dev->base_addr;
  1232. lp->num_rx_bufs = 0;
  1233. lp->rx_first = lp->rx_ptr = rx_block;
  1234. do
  1235. {
  1236. lp->num_rx_bufs++;
  1237. outw(rx_block, ioaddr + WRITE_PTR);
  1238. outw(0, ioaddr + DATAPORT); outw(0, ioaddr+DATAPORT);
  1239. outw(rx_block + RX_BUF_SIZE, ioaddr+DATAPORT);
  1240. outw(0xffff, ioaddr+DATAPORT);
  1241. outw(0x0000, ioaddr+DATAPORT);
  1242. outw(0xdead, ioaddr+DATAPORT);
  1243. outw(0xdead, ioaddr+DATAPORT);
  1244. outw(0xdead, ioaddr+DATAPORT);
  1245. outw(0xdead, ioaddr+DATAPORT);
  1246. outw(0xdead, ioaddr+DATAPORT);
  1247. outw(0xdead, ioaddr+DATAPORT);
  1248. outw(0x0000, ioaddr+DATAPORT);
  1249. outw(rx_block + RX_BUF_SIZE + 0x16, ioaddr+DATAPORT);
  1250. outw(rx_block + 0x20, ioaddr+DATAPORT);
  1251. outw(0, ioaddr+DATAPORT);
  1252. outw(RX_BUF_SIZE-0x20, ioaddr+DATAPORT);
  1253. lp->rx_last = rx_block;
  1254. rx_block += RX_BUF_SIZE;
  1255. } while (rx_block <= lp->rx_buf_end-RX_BUF_SIZE);
  1256. /* Make first Rx frame descriptor point to first Rx buffer
  1257. descriptor */
  1258. outw(lp->rx_first + 6, ioaddr+WRITE_PTR);
  1259. outw(lp->rx_first + 0x16, ioaddr+DATAPORT);
  1260. /* Close Rx frame descriptor ring */
  1261. outw(lp->rx_last + 4, ioaddr+WRITE_PTR);
  1262. outw(lp->rx_first, ioaddr+DATAPORT);
  1263. /* Close Rx buffer descriptor ring */
  1264. outw(lp->rx_last + 0x16 + 2, ioaddr+WRITE_PTR);
  1265. outw(lp->rx_first + 0x16, ioaddr+DATAPORT);
  1266. }
  1267. /*
  1268. * Un-reset the 586, and start the configuration sequence. We don't wait for
  1269. * this to finish, but allow the interrupt handler to start the CU and RU for
  1270. * us. We can't start the receive/transmission system up before we know that
  1271. * the hardware is configured correctly.
  1272. */
  1273. static void eexp_hw_init586(struct net_device *dev)
  1274. {
  1275. struct net_local *lp = netdev_priv(dev);
  1276. unsigned short ioaddr = dev->base_addr;
  1277. int i;
  1278. #if NET_DEBUG > 6
  1279. printk("%s: eexp_hw_init586()\n", dev->name);
  1280. #endif
  1281. lp->started = 0;
  1282. set_loopback(dev);
  1283. outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
  1284. /* Download the startup code */
  1285. outw(lp->rx_buf_end & ~31, ioaddr + SM_PTR);
  1286. outw(lp->width?0x0001:0x0000, ioaddr + 0x8006);
  1287. outw(0x0000, ioaddr + 0x8008);
  1288. outw(0x0000, ioaddr + 0x800a);
  1289. outw(0x0000, ioaddr + 0x800c);
  1290. outw(0x0000, ioaddr + 0x800e);
  1291. for (i = 0; i < (sizeof(start_code)); i+=32) {
  1292. int j;
  1293. outw(i, ioaddr + SM_PTR);
  1294. for (j = 0; j < 16; j+=2)
  1295. outw(start_code[(i+j)/2],
  1296. ioaddr+0x4000+j);
  1297. for (j = 0; j < 16; j+=2)
  1298. outw(start_code[(i+j+16)/2],
  1299. ioaddr+0x8000+j);
  1300. }
  1301. /* Do we want promiscuous mode or multicast? */
  1302. outw(CONF_PROMISC & ~31, ioaddr+SM_PTR);
  1303. i = inw(ioaddr+SHADOW(CONF_PROMISC));
  1304. outw((dev->flags & IFF_PROMISC)?(i|1):(i & ~1),
  1305. ioaddr+SHADOW(CONF_PROMISC));
  1306. lp->was_promisc = dev->flags & IFF_PROMISC;
  1307. #if 0
  1308. eexp_setup_filter(dev);
  1309. #endif
  1310. /* Write our hardware address */
  1311. outw(CONF_HWADDR & ~31, ioaddr+SM_PTR);
  1312. outw(((unsigned short *)dev->dev_addr)[0], ioaddr+SHADOW(CONF_HWADDR));
  1313. outw(((unsigned short *)dev->dev_addr)[1],
  1314. ioaddr+SHADOW(CONF_HWADDR+2));
  1315. outw(((unsigned short *)dev->dev_addr)[2],
  1316. ioaddr+SHADOW(CONF_HWADDR+4));
  1317. eexp_hw_txinit(dev);
  1318. eexp_hw_rxinit(dev);
  1319. outb(0,ioaddr+EEPROM_Ctrl);
  1320. mdelay(5);
  1321. scb_command(dev, 0xf000);
  1322. outb(0,ioaddr+SIGNAL_CA);
  1323. outw(0, ioaddr+SM_PTR);
  1324. {
  1325. unsigned short rboguscount=50,rfailcount=5;
  1326. while (inw(ioaddr+0x4000))
  1327. {
  1328. if (!--rboguscount)
  1329. {
  1330. printk(KERN_WARNING "%s: i82586 reset timed out, kicking...\n",
  1331. dev->name);
  1332. scb_command(dev, 0);
  1333. outb(0,ioaddr+SIGNAL_CA);
  1334. rboguscount = 100;
  1335. if (!--rfailcount)
  1336. {
  1337. printk(KERN_WARNING "%s: i82586 not responding, giving up.\n",
  1338. dev->name);
  1339. return;
  1340. }
  1341. }
  1342. }
  1343. }
  1344. scb_wrcbl(dev, CONF_LINK);
  1345. scb_command(dev, 0xf000|SCB_CUstart);
  1346. outb(0,ioaddr+SIGNAL_CA);
  1347. {
  1348. unsigned short iboguscount=50,ifailcount=5;
  1349. while (!scb_status(dev))
  1350. {
  1351. if (!--iboguscount)
  1352. {
  1353. if (--ifailcount)
  1354. {
  1355. printk(KERN_WARNING "%s: i82586 initialization timed out, status %04x, cmd %04x\n",
  1356. dev->name, scb_status(dev), scb_rdcmd(dev));
  1357. scb_wrcbl(dev, CONF_LINK);
  1358. scb_command(dev, 0xf000|SCB_CUstart);
  1359. outb(0,ioaddr+SIGNAL_CA);
  1360. iboguscount = 100;
  1361. }
  1362. else
  1363. {
  1364. printk(KERN_WARNING "%s: Failed to initialize i82586, giving up.\n",dev->name);
  1365. return;
  1366. }
  1367. }
  1368. }
  1369. }
  1370. clear_loopback(dev);
  1371. outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
  1372. lp->init_time = jiffies;
  1373. #if NET_DEBUG > 6
  1374. printk("%s: leaving eexp_hw_init586()\n", dev->name);
  1375. #endif
  1376. return;
  1377. }
  1378. static void eexp_setup_filter(struct net_device *dev)
  1379. {
  1380. struct dev_mc_list *dmi = dev->mc_list;
  1381. unsigned short ioaddr = dev->base_addr;
  1382. int count = dev->mc_count;
  1383. int i;
  1384. if (count > 8) {
  1385. printk(KERN_INFO "%s: too many multicast addresses (%d)\n",
  1386. dev->name, count);
  1387. count = 8;
  1388. }
  1389. outw(CONF_NR_MULTICAST & ~31, ioaddr+SM_PTR);
  1390. outw(count, ioaddr+SHADOW(CONF_NR_MULTICAST));
  1391. for (i = 0; i < count; i++) {
  1392. unsigned short *data = (unsigned short *)dmi->dmi_addr;
  1393. if (!dmi) {
  1394. printk(KERN_INFO "%s: too few multicast addresses\n", dev->name);
  1395. break;
  1396. }
  1397. if (dmi->dmi_addrlen != ETH_ALEN) {
  1398. printk(KERN_INFO "%s: invalid multicast address length given.\n", dev->name);
  1399. continue;
  1400. }
  1401. outw((CONF_MULTICAST+(6*i)) & ~31, ioaddr+SM_PTR);
  1402. outw(data[0], ioaddr+SHADOW(CONF_MULTICAST+(6*i)));
  1403. outw((CONF_MULTICAST+(6*i)+2) & ~31, ioaddr+SM_PTR);
  1404. outw(data[1], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+2));
  1405. outw((CONF_MULTICAST+(6*i)+4) & ~31, ioaddr+SM_PTR);
  1406. outw(data[2], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+4));
  1407. }
  1408. }
  1409. /*
  1410. * Set or clear the multicast filter for this adaptor.
  1411. */
  1412. static void
  1413. eexp_set_multicast(struct net_device *dev)
  1414. {
  1415. unsigned short ioaddr = dev->base_addr;
  1416. struct net_local *lp = netdev_priv(dev);
  1417. int kick = 0, i;
  1418. if ((dev->flags & IFF_PROMISC) != lp->was_promisc) {
  1419. outw(CONF_PROMISC & ~31, ioaddr+SM_PTR);
  1420. i = inw(ioaddr+SHADOW(CONF_PROMISC));
  1421. outw((dev->flags & IFF_PROMISC)?(i|1):(i & ~1),
  1422. ioaddr+SHADOW(CONF_PROMISC));
  1423. lp->was_promisc = dev->flags & IFF_PROMISC;
  1424. kick = 1;
  1425. }
  1426. if (!(dev->flags & IFF_PROMISC)) {
  1427. eexp_setup_filter(dev);
  1428. if (lp->old_mc_count != dev->mc_count) {
  1429. kick = 1;
  1430. lp->old_mc_count = dev->mc_count;
  1431. }
  1432. }
  1433. if (kick) {
  1434. unsigned long oj;
  1435. scb_command(dev, SCB_CUsuspend);
  1436. outb(0, ioaddr+SIGNAL_CA);
  1437. outb(0, ioaddr+SIGNAL_CA);
  1438. #if 0
  1439. printk("%s: waiting for CU to go suspended\n", dev->name);
  1440. #endif
  1441. oj = jiffies;
  1442. while ((SCB_CUstat(scb_status(dev)) == 2) &&
  1443. ((jiffies-oj) < 2000));
  1444. if (SCB_CUstat(scb_status(dev)) == 2)
  1445. printk("%s: warning, CU didn't stop\n", dev->name);
  1446. lp->started &= ~(STARTED_CU);
  1447. scb_wrcbl(dev, CONF_LINK);
  1448. scb_command(dev, SCB_CUstart);
  1449. outb(0, ioaddr+SIGNAL_CA);
  1450. }
  1451. }
  1452. /*
  1453. * MODULE stuff
  1454. */
  1455. #ifdef MODULE
  1456. #define EEXP_MAX_CARDS 4 /* max number of cards to support */
  1457. static struct net_device *dev_eexp[EEXP_MAX_CARDS];
  1458. static int irq[EEXP_MAX_CARDS];
  1459. static int io[EEXP_MAX_CARDS];
  1460. module_param_array(io, int, NULL, 0);
  1461. module_param_array(irq, int, NULL, 0);
  1462. MODULE_PARM_DESC(io, "EtherExpress 16 I/O base address(es)");
  1463. MODULE_PARM_DESC(irq, "EtherExpress 16 IRQ number(s)");
  1464. MODULE_LICENSE("GPL");
  1465. /* Ideally the user would give us io=, irq= for every card. If any parameters
  1466. * are specified, we verify and then use them. If no parameters are given, we
  1467. * autoprobe for one card only.
  1468. */
  1469. int init_module(void)
  1470. {
  1471. struct net_device *dev;
  1472. int this_dev, found = 0;
  1473. for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
  1474. dev = alloc_etherdev(sizeof(struct net_local));
  1475. dev->irq = irq[this_dev];
  1476. dev->base_addr = io[this_dev];
  1477. if (io[this_dev] == 0) {
  1478. if (this_dev)
  1479. break;
  1480. printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n");
  1481. }
  1482. if (do_express_probe(dev) == 0 && register_netdev(dev) == 0) {
  1483. dev_eexp[this_dev] = dev;
  1484. found++;
  1485. continue;
  1486. }
  1487. printk(KERN_WARNING "eexpress.c: Failed to register card at 0x%x.\n", io[this_dev]);
  1488. free_netdev(dev);
  1489. break;
  1490. }
  1491. if (found)
  1492. return 0;
  1493. return -ENXIO;
  1494. }
  1495. void cleanup_module(void)
  1496. {
  1497. int this_dev;
  1498. for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
  1499. struct net_device *dev = dev_eexp[this_dev];
  1500. if (dev) {
  1501. unregister_netdev(dev);
  1502. free_netdev(dev);
  1503. }
  1504. }
  1505. }
  1506. #endif
  1507. /*
  1508. * Local Variables:
  1509. * c-file-style: "linux"
  1510. * tab-width: 8
  1511. * End:
  1512. */