eexpress.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:45k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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