eexpress.c 45 KB

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