eexpress.c 44 KB

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