eexpress.c 46 KB

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