3c523.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. /*
  2. net-3-driver for the 3c523 Etherlink/MC card (i82586 Ethernet chip)
  3. This is an extension to the Linux operating system, and is covered by the
  4. same GNU General Public License that covers that work.
  5. Copyright 1995, 1996 by Chris Beauregard (cpbeaure@undergrad.math.uwaterloo.ca)
  6. This is basically Michael Hipp's ni52 driver, with a new probing
  7. algorithm and some minor changes to the 82586 CA and reset routines.
  8. Thanks a lot Michael for a really clean i82586 implementation! Unless
  9. otherwise documented in ni52.c, any bugs are mine.
  10. Contrary to the Ethernet-HOWTO, this isn't based on the 3c507 driver in
  11. any way. The ni52 is a lot easier to modify.
  12. sources:
  13. ni52.c
  14. Crynwr packet driver collection was a great reference for my first
  15. attempt at this sucker. The 3c507 driver also helped, until I noticed
  16. that ni52.c was a lot nicer.
  17. EtherLink/MC: Micro Channel Ethernet Adapter Technical Reference
  18. Manual, courtesy of 3Com CardFacts, documents the 3c523-specific
  19. stuff. Information on CardFacts is found in the Ethernet HOWTO.
  20. Also see <a href="http://www.3com.com/">
  21. Microprocessor Communications Support Chips, T.J. Byers, ISBN
  22. 0-444-01224-9, has a section on the i82586. It tells you just enough
  23. to know that you really don't want to learn how to program the chip.
  24. The original device probe code was stolen from ps2esdi.c
  25. Known Problems:
  26. Since most of the code was stolen from ni52.c, you'll run across the
  27. same bugs in the 0.62 version of ni52.c, plus maybe a few because of
  28. the 3c523 idiosynchacies. The 3c523 has 16K of RAM though, so there
  29. shouldn't be the overrun problem that the 8K ni52 has.
  30. This driver is for a 16K adapter. It should work fine on the 64K
  31. adapters, but it will only use one of the 4 banks of RAM. Modifying
  32. this for the 64K version would require a lot of heinous bank
  33. switching, which I'm sure not interested in doing. If you try to
  34. implement a bank switching version, you'll basically have to remember
  35. what bank is enabled and do a switch everytime you access a memory
  36. location that's not current. You'll also have to remap pointers on
  37. the driver side, because it only knows about 16K of the memory.
  38. Anyone desperate or masochistic enough to try?
  39. It seems to be stable now when multiple transmit buffers are used. I
  40. can't see any performance difference, but then I'm working on a 386SX.
  41. Multicast doesn't work. It doesn't even pretend to work. Don't use
  42. it. Don't compile your kernel with multicast support. I don't know
  43. why.
  44. Features:
  45. This driver is useable as a loadable module. If you try to specify an
  46. IRQ or a IO address (via insmod 3c523.o irq=xx io=0xyyy), it will
  47. search the MCA slots until it finds a 3c523 with the specified
  48. parameters.
  49. This driver does support multiple ethernet cards when used as a module
  50. (up to MAX_3C523_CARDS, the default being 4)
  51. This has been tested with both BNC and TP versions, internal and
  52. external transceivers. Haven't tested with the 64K version (that I
  53. know of).
  54. History:
  55. Jan 1st, 1996
  56. first public release
  57. Feb 4th, 1996
  58. update to 1.3.59, incorporated multicast diffs from ni52.c
  59. Feb 15th, 1996
  60. added shared irq support
  61. Apr 1999
  62. added support for multiple cards when used as a module
  63. added option to disable multicast as is causes problems
  64. Ganesh Sittampalam <ganesh.sittampalam@magdalen.oxford.ac.uk>
  65. Stuart Adamson <stuart.adamson@compsoc.net>
  66. Nov 2001
  67. added support for ethtool (jgarzik)
  68. $Header: /home/cvs/s3c-linux-2.6.21/drivers/net/3c523.c,v 1.1.1.1 2007/06/12 07:27:10 eyryu Exp $
  69. */
  70. #define DRV_NAME "3c523"
  71. #define DRV_VERSION "17-Nov-2001"
  72. #include <linux/init.h>
  73. #include <linux/netdevice.h>
  74. #include <linux/etherdevice.h>
  75. #include <linux/module.h>
  76. #include <linux/kernel.h>
  77. #include <linux/string.h>
  78. #include <linux/errno.h>
  79. #include <linux/ioport.h>
  80. #include <linux/skbuff.h>
  81. #include <linux/slab.h>
  82. #include <linux/interrupt.h>
  83. #include <linux/delay.h>
  84. #include <linux/mca-legacy.h>
  85. #include <linux/ethtool.h>
  86. #include <linux/bitops.h>
  87. #include <linux/jiffies.h>
  88. #include <asm/uaccess.h>
  89. #include <asm/processor.h>
  90. #include <asm/io.h>
  91. #include "3c523.h"
  92. /*************************************************************************/
  93. #define DEBUG /* debug on */
  94. #define SYSBUSVAL 0 /* 1 = 8 Bit, 0 = 16 bit - 3c523 only does 16 bit */
  95. #undef ELMC_MULTICAST /* Disable multicast support as it is somewhat seriously broken at the moment */
  96. #define make32(ptr16) (p->memtop + (short) (ptr16) )
  97. #define make24(ptr32) ((char *) (ptr32) - p->base)
  98. #define make16(ptr32) ((unsigned short) ((unsigned long) (ptr32) - (unsigned long) p->memtop ))
  99. /*************************************************************************/
  100. /*
  101. Tables to which we can map values in the configuration registers.
  102. */
  103. static int irq_table[] __initdata = {
  104. 12, 7, 3, 9
  105. };
  106. static int csr_table[] __initdata = {
  107. 0x300, 0x1300, 0x2300, 0x3300
  108. };
  109. static int shm_table[] __initdata = {
  110. 0x0c0000, 0x0c8000, 0x0d0000, 0x0d8000
  111. };
  112. /******************* how to calculate the buffers *****************************
  113. * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
  114. * --------------- in a different (more stable?) mode. Only in this mode it's
  115. * possible to configure the driver with 'NO_NOPCOMMANDS'
  116. sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
  117. sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
  118. sizeof(rfd) = 24; sizeof(rbd) = 12;
  119. sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
  120. sizeof(nop_cmd) = 8;
  121. * if you don't know the driver, better do not change this values: */
  122. #define RECV_BUFF_SIZE 1524 /* slightly oversized */
  123. #define XMIT_BUFF_SIZE 1524 /* slightly oversized */
  124. #define NUM_XMIT_BUFFS 1 /* config for both, 8K and 16K shmem */
  125. #define NUM_RECV_BUFFS_8 4 /* config for 8K shared mem */
  126. #define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */
  127. #if (NUM_XMIT_BUFFS == 1)
  128. #define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 */
  129. #endif
  130. /**************************************************************************/
  131. #define DELAY(x) { mdelay(32 * x); }
  132. /* a much shorter delay: */
  133. #define DELAY_16(); { udelay(16) ; }
  134. /* wait for command with timeout: */
  135. #define WAIT_4_SCB_CMD() { int i; \
  136. for(i=0;i<1024;i++) { \
  137. if(!p->scb->cmd) break; \
  138. DELAY_16(); \
  139. if(i == 1023) { \
  140. printk(KERN_WARNING "%s:%d: scb_cmd timed out .. resetting i82586\n",\
  141. dev->name,__LINE__); \
  142. elmc_id_reset586(); } } }
  143. static irqreturn_t elmc_interrupt(int irq, void *dev_id);
  144. static int elmc_open(struct net_device *dev);
  145. static int elmc_close(struct net_device *dev);
  146. static int elmc_send_packet(struct sk_buff *, struct net_device *);
  147. static struct net_device_stats *elmc_get_stats(struct net_device *dev);
  148. static void elmc_timeout(struct net_device *dev);
  149. #ifdef ELMC_MULTICAST
  150. static void set_multicast_list(struct net_device *dev);
  151. #endif
  152. static const struct ethtool_ops netdev_ethtool_ops;
  153. /* helper-functions */
  154. static int init586(struct net_device *dev);
  155. static int check586(struct net_device *dev, unsigned long where, unsigned size);
  156. static void alloc586(struct net_device *dev);
  157. static void startrecv586(struct net_device *dev);
  158. static void *alloc_rfa(struct net_device *dev, void *ptr);
  159. static void elmc_rcv_int(struct net_device *dev);
  160. static void elmc_xmt_int(struct net_device *dev);
  161. static void elmc_rnr_int(struct net_device *dev);
  162. struct priv {
  163. struct net_device_stats stats;
  164. unsigned long base;
  165. char *memtop;
  166. unsigned long mapped_start; /* Start of ioremap */
  167. volatile struct rfd_struct *rfd_last, *rfd_top, *rfd_first;
  168. volatile struct scp_struct *scp; /* volatile is important */
  169. volatile struct iscp_struct *iscp; /* volatile is important */
  170. volatile struct scb_struct *scb; /* volatile is important */
  171. volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS];
  172. #if (NUM_XMIT_BUFFS == 1)
  173. volatile struct transmit_cmd_struct *xmit_cmds[2];
  174. volatile struct nop_cmd_struct *nop_cmds[2];
  175. #else
  176. volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];
  177. volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];
  178. #endif
  179. volatile int nop_point, num_recv_buffs;
  180. volatile char *xmit_cbuffs[NUM_XMIT_BUFFS];
  181. volatile int xmit_count, xmit_last;
  182. volatile int slot;
  183. };
  184. #define elmc_attn586() {elmc_do_attn586(dev->base_addr,ELMC_CTRL_INTE);}
  185. #define elmc_reset586() {elmc_do_reset586(dev->base_addr,ELMC_CTRL_INTE);}
  186. /* with interrupts disabled - this will clear the interrupt bit in the
  187. 3c523 control register, and won't put it back. This effectively
  188. disables interrupts on the card. */
  189. #define elmc_id_attn586() {elmc_do_attn586(dev->base_addr,0);}
  190. #define elmc_id_reset586() {elmc_do_reset586(dev->base_addr,0);}
  191. /*************************************************************************/
  192. /*
  193. Do a Channel Attention on the 3c523. This is extremely board dependent.
  194. */
  195. static void elmc_do_attn586(int ioaddr, int ints)
  196. {
  197. /* the 3c523 requires a minimum of 500 ns. The delays here might be
  198. a little too large, and hence they may cut the performance of the
  199. card slightly. If someone who knows a little more about Linux
  200. timing would care to play with these, I'd appreciate it. */
  201. /* this bit masking stuff is crap. I'd rather have separate
  202. registers with strobe triggers for each of these functions. <sigh>
  203. Ya take what ya got. */
  204. outb(ELMC_CTRL_RST | 0x3 | ELMC_CTRL_CA | ints, ioaddr + ELMC_CTRL);
  205. DELAY_16(); /* > 500 ns */
  206. outb(ELMC_CTRL_RST | 0x3 | ints, ioaddr + ELMC_CTRL);
  207. }
  208. /*************************************************************************/
  209. /*
  210. Reset the 82586 on the 3c523. Also very board dependent.
  211. */
  212. static void elmc_do_reset586(int ioaddr, int ints)
  213. {
  214. /* toggle the RST bit low then high */
  215. outb(0x3 | ELMC_CTRL_LBK, ioaddr + ELMC_CTRL);
  216. DELAY_16(); /* > 500 ns */
  217. outb(ELMC_CTRL_RST | ELMC_CTRL_LBK | 0x3, ioaddr + ELMC_CTRL);
  218. elmc_do_attn586(ioaddr, ints);
  219. }
  220. /**********************************************
  221. * close device
  222. */
  223. static int elmc_close(struct net_device *dev)
  224. {
  225. netif_stop_queue(dev);
  226. elmc_id_reset586(); /* the hard way to stop the receiver */
  227. free_irq(dev->irq, dev);
  228. return 0;
  229. }
  230. /**********************************************
  231. * open device
  232. */
  233. static int elmc_open(struct net_device *dev)
  234. {
  235. int ret;
  236. elmc_id_attn586(); /* disable interrupts */
  237. ret = request_irq(dev->irq, &elmc_interrupt, IRQF_SHARED | IRQF_SAMPLE_RANDOM,
  238. dev->name, dev);
  239. if (ret) {
  240. printk(KERN_ERR "%s: couldn't get irq %d\n", dev->name, dev->irq);
  241. elmc_id_reset586();
  242. return ret;
  243. }
  244. alloc586(dev);
  245. init586(dev);
  246. startrecv586(dev);
  247. netif_start_queue(dev);
  248. return 0; /* most done by init */
  249. }
  250. /**********************************************
  251. * Check to see if there's an 82586 out there.
  252. */
  253. static int __init check586(struct net_device *dev, unsigned long where, unsigned size)
  254. {
  255. struct priv *p = (struct priv *) dev->priv;
  256. char *iscp_addrs[2];
  257. int i = 0;
  258. p->base = (unsigned long) isa_bus_to_virt((unsigned long)where) + size - 0x01000000;
  259. p->memtop = isa_bus_to_virt((unsigned long)where) + size;
  260. p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
  261. memset((char *) p->scp, 0, sizeof(struct scp_struct));
  262. p->scp->sysbus = SYSBUSVAL; /* 1 = 8Bit-Bus, 0 = 16 Bit */
  263. iscp_addrs[0] = isa_bus_to_virt((unsigned long)where);
  264. iscp_addrs[1] = (char *) p->scp - sizeof(struct iscp_struct);
  265. for (i = 0; i < 2; i++) {
  266. p->iscp = (struct iscp_struct *) iscp_addrs[i];
  267. memset((char *) p->iscp, 0, sizeof(struct iscp_struct));
  268. p->scp->iscp = make24(p->iscp);
  269. p->iscp->busy = 1;
  270. elmc_id_reset586();
  271. /* reset586 does an implicit CA */
  272. /* apparently, you sometimes have to kick the 82586 twice... */
  273. elmc_id_attn586();
  274. DELAY(1);
  275. if (p->iscp->busy) { /* i82586 clears 'busy' after successful init */
  276. return 0;
  277. }
  278. }
  279. return 1;
  280. }
  281. /******************************************************************
  282. * set iscp at the right place, called by elmc_probe and open586.
  283. */
  284. void alloc586(struct net_device *dev)
  285. {
  286. struct priv *p = (struct priv *) dev->priv;
  287. elmc_id_reset586();
  288. DELAY(2);
  289. p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS);
  290. p->scb = (struct scb_struct *) isa_bus_to_virt(dev->mem_start);
  291. p->iscp = (struct iscp_struct *) ((char *) p->scp - sizeof(struct iscp_struct));
  292. memset((char *) p->iscp, 0, sizeof(struct iscp_struct));
  293. memset((char *) p->scp, 0, sizeof(struct scp_struct));
  294. p->scp->iscp = make24(p->iscp);
  295. p->scp->sysbus = SYSBUSVAL;
  296. p->iscp->scb_offset = make16(p->scb);
  297. p->iscp->busy = 1;
  298. elmc_id_reset586();
  299. elmc_id_attn586();
  300. DELAY(2);
  301. if (p->iscp->busy) {
  302. printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name);
  303. }
  304. memset((char *) p->scb, 0, sizeof(struct scb_struct));
  305. }
  306. /*****************************************************************/
  307. static int elmc_getinfo(char *buf, int slot, void *d)
  308. {
  309. int len = 0;
  310. struct net_device *dev = (struct net_device *) d;
  311. int i;
  312. if (dev == NULL)
  313. return len;
  314. len += sprintf(buf + len, "Revision: 0x%x\n",
  315. inb(dev->base_addr + ELMC_REVISION) & 0xf);
  316. len += sprintf(buf + len, "IRQ: %d\n", dev->irq);
  317. len += sprintf(buf + len, "IO Address: %#lx-%#lx\n", dev->base_addr,
  318. dev->base_addr + ELMC_IO_EXTENT);
  319. len += sprintf(buf + len, "Memory: %#lx-%#lx\n", dev->mem_start,
  320. dev->mem_end - 1);
  321. len += sprintf(buf + len, "Transceiver: %s\n", dev->if_port ?
  322. "External" : "Internal");
  323. len += sprintf(buf + len, "Device: %s\n", dev->name);
  324. len += sprintf(buf + len, "Hardware Address:");
  325. for (i = 0; i < 6; i++) {
  326. len += sprintf(buf + len, " %02x", dev->dev_addr[i]);
  327. }
  328. buf[len++] = '\n';
  329. buf[len] = 0;
  330. return len;
  331. } /* elmc_getinfo() */
  332. /*****************************************************************/
  333. static int __init do_elmc_probe(struct net_device *dev)
  334. {
  335. static int slot;
  336. int base_addr = dev->base_addr;
  337. int irq = dev->irq;
  338. u_char status = 0;
  339. u_char revision = 0;
  340. int i = 0;
  341. unsigned int size = 0;
  342. int retval;
  343. struct priv *pr = dev->priv;
  344. SET_MODULE_OWNER(dev);
  345. if (MCA_bus == 0) {
  346. return -ENODEV;
  347. }
  348. /* search through the slots for the 3c523. */
  349. slot = mca_find_adapter(ELMC_MCA_ID, 0);
  350. while (slot != -1) {
  351. status = mca_read_stored_pos(slot, 2);
  352. dev->irq=irq_table[(status & ELMC_STATUS_IRQ_SELECT) >> 6];
  353. dev->base_addr=csr_table[(status & ELMC_STATUS_CSR_SELECT) >> 1];
  354. /*
  355. If we're trying to match a specified irq or IO address,
  356. we'll reject a match unless it's what we're looking for.
  357. Also reject it if the card is already in use.
  358. */
  359. if ((irq && irq != dev->irq) ||
  360. (base_addr && base_addr != dev->base_addr)) {
  361. slot = mca_find_adapter(ELMC_MCA_ID, slot + 1);
  362. continue;
  363. }
  364. if (!request_region(dev->base_addr, ELMC_IO_EXTENT, DRV_NAME)) {
  365. slot = mca_find_adapter(ELMC_MCA_ID, slot + 1);
  366. continue;
  367. }
  368. /* found what we're looking for... */
  369. break;
  370. }
  371. /* we didn't find any 3c523 in the slots we checked for */
  372. if (slot == MCA_NOTFOUND)
  373. return ((base_addr || irq) ? -ENXIO : -ENODEV);
  374. mca_set_adapter_name(slot, "3Com 3c523 Etherlink/MC");
  375. mca_set_adapter_procfn(slot, (MCA_ProcFn) elmc_getinfo, dev);
  376. /* if we get this far, adapter has been found - carry on */
  377. printk(KERN_INFO "%s: 3c523 adapter found in slot %d\n", dev->name, slot + 1);
  378. /* Now we extract configuration info from the card.
  379. The 3c523 provides information in two of the POS registers, but
  380. the second one is only needed if we want to tell the card what IRQ
  381. to use. I suspect that whoever sets the thing up initially would
  382. prefer we don't screw with those things.
  383. Note that we read the status info when we found the card...
  384. See 3c523.h for more details.
  385. */
  386. /* revision is stored in the first 4 bits of the revision register */
  387. revision = inb(dev->base_addr + ELMC_REVISION) & 0xf;
  388. /* according to docs, we read the interrupt and write it back to
  389. the IRQ select register, since the POST might not configure the IRQ
  390. properly. */
  391. switch (dev->irq) {
  392. case 3:
  393. mca_write_pos(slot, 3, 0x04);
  394. break;
  395. case 7:
  396. mca_write_pos(slot, 3, 0x02);
  397. break;
  398. case 9:
  399. mca_write_pos(slot, 3, 0x08);
  400. break;
  401. case 12:
  402. mca_write_pos(slot, 3, 0x01);
  403. break;
  404. }
  405. memset(pr, 0, sizeof(struct priv));
  406. pr->slot = slot;
  407. printk(KERN_INFO "%s: 3Com 3c523 Rev 0x%x at %#lx\n", dev->name, (int) revision,
  408. dev->base_addr);
  409. /* Determine if we're using the on-board transceiver (i.e. coax) or
  410. an external one. The information is pretty much useless, but I
  411. guess it's worth brownie points. */
  412. dev->if_port = (status & ELMC_STATUS_DISABLE_THIN);
  413. /* The 3c523 has a 24K chunk of memory. The first 16K is the
  414. shared memory, while the last 8K is for the EtherStart BIOS ROM.
  415. Which we don't care much about here. We'll just tell Linux that
  416. we're using 16K. MCA won't permit address space conflicts caused
  417. by not mapping the other 8K. */
  418. dev->mem_start = shm_table[(status & ELMC_STATUS_MEMORY_SELECT) >> 3];
  419. /* We're using MCA, so it's a given that the information about memory
  420. size is correct. The Crynwr drivers do something like this. */
  421. elmc_id_reset586(); /* seems like a good idea before checking it... */
  422. size = 0x4000; /* check for 16K mem */
  423. if (!check586(dev, dev->mem_start, size)) {
  424. printk(KERN_ERR "%s: memprobe, Can't find memory at 0x%lx!\n", dev->name,
  425. dev->mem_start);
  426. retval = -ENODEV;
  427. goto err_out;
  428. }
  429. dev->mem_end = dev->mem_start + size; /* set mem_end showed by 'ifconfig' */
  430. pr->memtop = isa_bus_to_virt(dev->mem_start) + size;
  431. pr->base = (unsigned long) isa_bus_to_virt(dev->mem_start) + size - 0x01000000;
  432. alloc586(dev);
  433. elmc_id_reset586(); /* make sure it doesn't generate spurious ints */
  434. /* set number of receive-buffs according to memsize */
  435. pr->num_recv_buffs = NUM_RECV_BUFFS_16;
  436. /* dump all the assorted information */
  437. printk(KERN_INFO "%s: IRQ %d, %sternal xcvr, memory %#lx-%#lx.\n", dev->name,
  438. dev->irq, dev->if_port ? "ex" : "in",
  439. dev->mem_start, dev->mem_end - 1);
  440. /* The hardware address for the 3c523 is stored in the first six
  441. bytes of the IO address. */
  442. printk(KERN_INFO "%s: hardware address ", dev->name);
  443. for (i = 0; i < 6; i++) {
  444. dev->dev_addr[i] = inb(dev->base_addr + i);
  445. printk(" %02x", dev->dev_addr[i]);
  446. }
  447. printk("\n");
  448. dev->open = &elmc_open;
  449. dev->stop = &elmc_close;
  450. dev->get_stats = &elmc_get_stats;
  451. dev->hard_start_xmit = &elmc_send_packet;
  452. dev->tx_timeout = &elmc_timeout;
  453. dev->watchdog_timeo = HZ;
  454. #ifdef ELMC_MULTICAST
  455. dev->set_multicast_list = &set_multicast_list;
  456. #else
  457. dev->set_multicast_list = NULL;
  458. #endif
  459. dev->ethtool_ops = &netdev_ethtool_ops;
  460. /* note that we haven't actually requested the IRQ from the kernel.
  461. That gets done in elmc_open(). I'm not sure that's such a good idea,
  462. but it works, so I'll go with it. */
  463. #ifndef ELMC_MULTICAST
  464. dev->flags&=~IFF_MULTICAST; /* Multicast doesn't work */
  465. #endif
  466. retval = register_netdev(dev);
  467. if (retval)
  468. goto err_out;
  469. return 0;
  470. err_out:
  471. mca_set_adapter_procfn(slot, NULL, NULL);
  472. release_region(dev->base_addr, ELMC_IO_EXTENT);
  473. return retval;
  474. }
  475. static void cleanup_card(struct net_device *dev)
  476. {
  477. mca_set_adapter_procfn(((struct priv *) (dev->priv))->slot, NULL, NULL);
  478. release_region(dev->base_addr, ELMC_IO_EXTENT);
  479. }
  480. #ifndef MODULE
  481. struct net_device * __init elmc_probe(int unit)
  482. {
  483. struct net_device *dev = alloc_etherdev(sizeof(struct priv));
  484. int err;
  485. if (!dev)
  486. return ERR_PTR(-ENOMEM);
  487. sprintf(dev->name, "eth%d", unit);
  488. netdev_boot_setup_check(dev);
  489. err = do_elmc_probe(dev);
  490. if (err)
  491. goto out;
  492. return dev;
  493. out:
  494. free_netdev(dev);
  495. return ERR_PTR(err);
  496. }
  497. #endif
  498. /**********************************************
  499. * init the chip (elmc-interrupt should be disabled?!)
  500. * needs a correct 'allocated' memory
  501. */
  502. static int init586(struct net_device *dev)
  503. {
  504. void *ptr;
  505. unsigned long s;
  506. int i, result = 0;
  507. struct priv *p = (struct priv *) dev->priv;
  508. volatile struct configure_cmd_struct *cfg_cmd;
  509. volatile struct iasetup_cmd_struct *ias_cmd;
  510. volatile struct tdr_cmd_struct *tdr_cmd;
  511. volatile struct mcsetup_cmd_struct *mc_cmd;
  512. struct dev_mc_list *dmi = dev->mc_list;
  513. int num_addrs = dev->mc_count;
  514. ptr = (void *) ((char *) p->scb + sizeof(struct scb_struct));
  515. cfg_cmd = (struct configure_cmd_struct *) ptr; /* configure-command */
  516. cfg_cmd->cmd_status = 0;
  517. cfg_cmd->cmd_cmd = CMD_CONFIGURE | CMD_LAST;
  518. cfg_cmd->cmd_link = 0xffff;
  519. cfg_cmd->byte_cnt = 0x0a; /* number of cfg bytes */
  520. cfg_cmd->fifo = 0x08; /* fifo-limit (8=tx:32/rx:64) */
  521. cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */
  522. cfg_cmd->adr_len = 0x2e; /* addr_len |!src_insert |pre-len |loopback */
  523. cfg_cmd->priority = 0x00;
  524. cfg_cmd->ifs = 0x60;
  525. cfg_cmd->time_low = 0x00;
  526. cfg_cmd->time_high = 0xf2;
  527. cfg_cmd->promisc = 0;
  528. if (dev->flags & (IFF_ALLMULTI | IFF_PROMISC)) {
  529. cfg_cmd->promisc = 1;
  530. dev->flags |= IFF_PROMISC;
  531. }
  532. cfg_cmd->carr_coll = 0x00;
  533. p->scb->cbl_offset = make16(cfg_cmd);
  534. p->scb->cmd = CUC_START; /* cmd.-unit start */
  535. elmc_id_attn586();
  536. s = jiffies; /* warning: only active with interrupts on !! */
  537. while (!(cfg_cmd->cmd_status & STAT_COMPL)) {
  538. if (time_after(jiffies, s + 30*HZ/100))
  539. break;
  540. }
  541. if ((cfg_cmd->cmd_status & (STAT_OK | STAT_COMPL)) != (STAT_COMPL | STAT_OK)) {
  542. printk(KERN_WARNING "%s (elmc): configure command failed: %x\n", dev->name, cfg_cmd->cmd_status);
  543. return 1;
  544. }
  545. /*
  546. * individual address setup
  547. */
  548. ias_cmd = (struct iasetup_cmd_struct *) ptr;
  549. ias_cmd->cmd_status = 0;
  550. ias_cmd->cmd_cmd = CMD_IASETUP | CMD_LAST;
  551. ias_cmd->cmd_link = 0xffff;
  552. memcpy((char *) &ias_cmd->iaddr, (char *) dev->dev_addr, ETH_ALEN);
  553. p->scb->cbl_offset = make16(ias_cmd);
  554. p->scb->cmd = CUC_START; /* cmd.-unit start */
  555. elmc_id_attn586();
  556. s = jiffies;
  557. while (!(ias_cmd->cmd_status & STAT_COMPL)) {
  558. if (time_after(jiffies, s + 30*HZ/100))
  559. break;
  560. }
  561. if ((ias_cmd->cmd_status & (STAT_OK | STAT_COMPL)) != (STAT_OK | STAT_COMPL)) {
  562. printk(KERN_WARNING "%s (elmc): individual address setup command failed: %04x\n", dev->name, ias_cmd->cmd_status);
  563. return 1;
  564. }
  565. /*
  566. * TDR, wire check .. e.g. no resistor e.t.c
  567. */
  568. tdr_cmd = (struct tdr_cmd_struct *) ptr;
  569. tdr_cmd->cmd_status = 0;
  570. tdr_cmd->cmd_cmd = CMD_TDR | CMD_LAST;
  571. tdr_cmd->cmd_link = 0xffff;
  572. tdr_cmd->status = 0;
  573. p->scb->cbl_offset = make16(tdr_cmd);
  574. p->scb->cmd = CUC_START; /* cmd.-unit start */
  575. elmc_attn586();
  576. s = jiffies;
  577. while (!(tdr_cmd->cmd_status & STAT_COMPL)) {
  578. if (time_after(jiffies, s + 30*HZ/100)) {
  579. printk(KERN_WARNING "%s: %d Problems while running the TDR.\n", dev->name, __LINE__);
  580. result = 1;
  581. break;
  582. }
  583. }
  584. if (!result) {
  585. DELAY(2); /* wait for result */
  586. result = tdr_cmd->status;
  587. p->scb->cmd = p->scb->status & STAT_MASK;
  588. elmc_id_attn586(); /* ack the interrupts */
  589. if (result & TDR_LNK_OK) {
  590. /* empty */
  591. } else if (result & TDR_XCVR_PRB) {
  592. printk(KERN_WARNING "%s: TDR: Transceiver problem!\n", dev->name);
  593. } else if (result & TDR_ET_OPN) {
  594. printk(KERN_WARNING "%s: TDR: No correct termination %d clocks away.\n", dev->name, result & TDR_TIMEMASK);
  595. } else if (result & TDR_ET_SRT) {
  596. if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */
  597. printk(KERN_WARNING "%s: TDR: Detected a short circuit %d clocks away.\n", dev->name, result & TDR_TIMEMASK);
  598. } else {
  599. printk(KERN_WARNING "%s: TDR: Unknown status %04x\n", dev->name, result);
  600. }
  601. }
  602. /*
  603. * ack interrupts
  604. */
  605. p->scb->cmd = p->scb->status & STAT_MASK;
  606. elmc_id_attn586();
  607. /*
  608. * alloc nop/xmit-cmds
  609. */
  610. #if (NUM_XMIT_BUFFS == 1)
  611. for (i = 0; i < 2; i++) {
  612. p->nop_cmds[i] = (struct nop_cmd_struct *) ptr;
  613. p->nop_cmds[i]->cmd_cmd = CMD_NOP;
  614. p->nop_cmds[i]->cmd_status = 0;
  615. p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
  616. ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
  617. }
  618. p->xmit_cmds[0] = (struct transmit_cmd_struct *) ptr; /* transmit cmd/buff 0 */
  619. ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
  620. #else
  621. for (i = 0; i < NUM_XMIT_BUFFS; i++) {
  622. p->nop_cmds[i] = (struct nop_cmd_struct *) ptr;
  623. p->nop_cmds[i]->cmd_cmd = CMD_NOP;
  624. p->nop_cmds[i]->cmd_status = 0;
  625. p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
  626. ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
  627. p->xmit_cmds[i] = (struct transmit_cmd_struct *) ptr; /*transmit cmd/buff 0 */
  628. ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
  629. }
  630. #endif
  631. ptr = alloc_rfa(dev, (void *) ptr); /* init receive-frame-area */
  632. /*
  633. * Multicast setup
  634. */
  635. if (dev->mc_count) {
  636. /* I don't understand this: do we really need memory after the init? */
  637. int len = ((char *) p->iscp - (char *) ptr - 8) / 6;
  638. if (len <= 0) {
  639. printk(KERN_ERR "%s: Ooooops, no memory for MC-Setup!\n", dev->name);
  640. } else {
  641. if (len < num_addrs) {
  642. num_addrs = len;
  643. printk(KERN_WARNING "%s: Sorry, can only apply %d MC-Address(es).\n",
  644. dev->name, num_addrs);
  645. }
  646. mc_cmd = (struct mcsetup_cmd_struct *) ptr;
  647. mc_cmd->cmd_status = 0;
  648. mc_cmd->cmd_cmd = CMD_MCSETUP | CMD_LAST;
  649. mc_cmd->cmd_link = 0xffff;
  650. mc_cmd->mc_cnt = num_addrs * 6;
  651. for (i = 0; i < num_addrs; i++) {
  652. memcpy((char *) mc_cmd->mc_list[i], dmi->dmi_addr, 6);
  653. dmi = dmi->next;
  654. }
  655. p->scb->cbl_offset = make16(mc_cmd);
  656. p->scb->cmd = CUC_START;
  657. elmc_id_attn586();
  658. s = jiffies;
  659. while (!(mc_cmd->cmd_status & STAT_COMPL)) {
  660. if (time_after(jiffies, s + 30*HZ/100))
  661. break;
  662. }
  663. if (!(mc_cmd->cmd_status & STAT_COMPL)) {
  664. printk(KERN_WARNING "%s: Can't apply multicast-address-list.\n", dev->name);
  665. }
  666. }
  667. }
  668. /*
  669. * alloc xmit-buffs / init xmit_cmds
  670. */
  671. for (i = 0; i < NUM_XMIT_BUFFS; i++) {
  672. p->xmit_cbuffs[i] = (char *) ptr; /* char-buffs */
  673. ptr = (char *) ptr + XMIT_BUFF_SIZE;
  674. p->xmit_buffs[i] = (struct tbd_struct *) ptr; /* TBD */
  675. ptr = (char *) ptr + sizeof(struct tbd_struct);
  676. if ((void *) ptr > (void *) p->iscp) {
  677. printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n", dev->name);
  678. return 1;
  679. }
  680. memset((char *) (p->xmit_cmds[i]), 0, sizeof(struct transmit_cmd_struct));
  681. memset((char *) (p->xmit_buffs[i]), 0, sizeof(struct tbd_struct));
  682. p->xmit_cmds[i]->cmd_status = STAT_COMPL;
  683. p->xmit_cmds[i]->cmd_cmd = CMD_XMIT | CMD_INT;
  684. p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i]));
  685. p->xmit_buffs[i]->next = 0xffff;
  686. p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i]));
  687. }
  688. p->xmit_count = 0;
  689. p->xmit_last = 0;
  690. #ifndef NO_NOPCOMMANDS
  691. p->nop_point = 0;
  692. #endif
  693. /*
  694. * 'start transmitter' (nop-loop)
  695. */
  696. #ifndef NO_NOPCOMMANDS
  697. p->scb->cbl_offset = make16(p->nop_cmds[0]);
  698. p->scb->cmd = CUC_START;
  699. elmc_id_attn586();
  700. WAIT_4_SCB_CMD();
  701. #else
  702. p->xmit_cmds[0]->cmd_link = 0xffff;
  703. p->xmit_cmds[0]->cmd_cmd = CMD_XMIT | CMD_LAST | CMD_INT;
  704. #endif
  705. return 0;
  706. }
  707. /******************************************************
  708. * This is a helper routine for elmc_rnr_int() and init586().
  709. * It sets up the Receive Frame Area (RFA).
  710. */
  711. static void *alloc_rfa(struct net_device *dev, void *ptr)
  712. {
  713. volatile struct rfd_struct *rfd = (struct rfd_struct *) ptr;
  714. volatile struct rbd_struct *rbd;
  715. int i;
  716. struct priv *p = (struct priv *) dev->priv;
  717. memset((char *) rfd, 0, sizeof(struct rfd_struct) * p->num_recv_buffs);
  718. p->rfd_first = rfd;
  719. for (i = 0; i < p->num_recv_buffs; i++) {
  720. rfd[i].next = make16(rfd + (i + 1) % p->num_recv_buffs);
  721. }
  722. rfd[p->num_recv_buffs - 1].last = RFD_SUSP; /* RU suspend */
  723. ptr = (void *) (rfd + p->num_recv_buffs);
  724. rbd = (struct rbd_struct *) ptr;
  725. ptr = (void *) (rbd + p->num_recv_buffs);
  726. /* clr descriptors */
  727. memset((char *) rbd, 0, sizeof(struct rbd_struct) * p->num_recv_buffs);
  728. for (i = 0; i < p->num_recv_buffs; i++) {
  729. rbd[i].next = make16((rbd + (i + 1) % p->num_recv_buffs));
  730. rbd[i].size = RECV_BUFF_SIZE;
  731. rbd[i].buffer = make24(ptr);
  732. ptr = (char *) ptr + RECV_BUFF_SIZE;
  733. }
  734. p->rfd_top = p->rfd_first;
  735. p->rfd_last = p->rfd_first + p->num_recv_buffs - 1;
  736. p->scb->rfa_offset = make16(p->rfd_first);
  737. p->rfd_first->rbd_offset = make16(rbd);
  738. return ptr;
  739. }
  740. /**************************************************
  741. * Interrupt Handler ...
  742. */
  743. static irqreturn_t
  744. elmc_interrupt(int irq, void *dev_id)
  745. {
  746. struct net_device *dev = dev_id;
  747. unsigned short stat;
  748. struct priv *p;
  749. if (!netif_running(dev)) {
  750. /* The 3c523 has this habit of generating interrupts during the
  751. reset. I'm not sure if the ni52 has this same problem, but it's
  752. really annoying if we haven't finished initializing it. I was
  753. hoping all the elmc_id_* commands would disable this, but I
  754. might have missed a few. */
  755. elmc_id_attn586(); /* ack inter. and disable any more */
  756. return IRQ_HANDLED;
  757. } else if (!(ELMC_CTRL_INT & inb(dev->base_addr + ELMC_CTRL))) {
  758. /* wasn't this device */
  759. return IRQ_NONE;
  760. }
  761. /* reading ELMC_CTRL also clears the INT bit. */
  762. p = (struct priv *) dev->priv;
  763. while ((stat = p->scb->status & STAT_MASK))
  764. {
  765. p->scb->cmd = stat;
  766. elmc_attn586(); /* ack inter. */
  767. if (stat & STAT_CX) {
  768. /* command with I-bit set complete */
  769. elmc_xmt_int(dev);
  770. }
  771. if (stat & STAT_FR) {
  772. /* received a frame */
  773. elmc_rcv_int(dev);
  774. }
  775. #ifndef NO_NOPCOMMANDS
  776. if (stat & STAT_CNA) {
  777. /* CU went 'not ready' */
  778. if (netif_running(dev)) {
  779. printk(KERN_WARNING "%s: oops! CU has left active state. stat: %04x/%04x.\n", dev->name, (int) stat, (int) p->scb->status);
  780. }
  781. }
  782. #endif
  783. if (stat & STAT_RNR) {
  784. /* RU went 'not ready' */
  785. if (p->scb->status & RU_SUSPEND) {
  786. /* special case: RU_SUSPEND */
  787. WAIT_4_SCB_CMD();
  788. p->scb->cmd = RUC_RESUME;
  789. elmc_attn586();
  790. } else {
  791. printk(KERN_WARNING "%s: Receiver-Unit went 'NOT READY': %04x/%04x.\n", dev->name, (int) stat, (int) p->scb->status);
  792. elmc_rnr_int(dev);
  793. }
  794. }
  795. WAIT_4_SCB_CMD(); /* wait for ack. (elmc_xmt_int can be faster than ack!!) */
  796. if (p->scb->cmd) { /* timed out? */
  797. break;
  798. }
  799. }
  800. return IRQ_HANDLED;
  801. }
  802. /*******************************************************
  803. * receive-interrupt
  804. */
  805. static void elmc_rcv_int(struct net_device *dev)
  806. {
  807. int status;
  808. unsigned short totlen;
  809. struct sk_buff *skb;
  810. struct rbd_struct *rbd;
  811. struct priv *p = (struct priv *) dev->priv;
  812. for (; (status = p->rfd_top->status) & STAT_COMPL;) {
  813. rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset);
  814. if (status & STAT_OK) { /* frame received without error? */
  815. if ((totlen = rbd->status) & RBD_LAST) { /* the first and the last buffer? */
  816. totlen &= RBD_MASK; /* length of this frame */
  817. rbd->status = 0;
  818. skb = (struct sk_buff *) dev_alloc_skb(totlen + 2);
  819. if (skb != NULL) {
  820. skb->dev = dev;
  821. skb_reserve(skb, 2); /* 16 byte alignment */
  822. skb_put(skb,totlen);
  823. eth_copy_and_sum(skb, (char *) p->base+(unsigned long) rbd->buffer,totlen,0);
  824. skb->protocol = eth_type_trans(skb, dev);
  825. netif_rx(skb);
  826. dev->last_rx = jiffies;
  827. p->stats.rx_packets++;
  828. p->stats.rx_bytes += totlen;
  829. } else {
  830. p->stats.rx_dropped++;
  831. }
  832. } else {
  833. printk(KERN_WARNING "%s: received oversized frame.\n", dev->name);
  834. p->stats.rx_dropped++;
  835. }
  836. } else { /* frame !(ok), only with 'save-bad-frames' */
  837. printk(KERN_WARNING "%s: oops! rfd-error-status: %04x\n", dev->name, status);
  838. p->stats.rx_errors++;
  839. }
  840. p->rfd_top->status = 0;
  841. p->rfd_top->last = RFD_SUSP;
  842. p->rfd_last->last = 0; /* delete RU_SUSP */
  843. p->rfd_last = p->rfd_top;
  844. p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */
  845. }
  846. }
  847. /**********************************************************
  848. * handle 'Receiver went not ready'.
  849. */
  850. static void elmc_rnr_int(struct net_device *dev)
  851. {
  852. struct priv *p = (struct priv *) dev->priv;
  853. p->stats.rx_errors++;
  854. WAIT_4_SCB_CMD(); /* wait for the last cmd */
  855. p->scb->cmd = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */
  856. elmc_attn586();
  857. WAIT_4_SCB_CMD(); /* wait for accept cmd. */
  858. alloc_rfa(dev, (char *) p->rfd_first);
  859. startrecv586(dev); /* restart RU */
  860. printk(KERN_WARNING "%s: Receive-Unit restarted. Status: %04x\n", dev->name, p->scb->status);
  861. }
  862. /**********************************************************
  863. * handle xmit - interrupt
  864. */
  865. static void elmc_xmt_int(struct net_device *dev)
  866. {
  867. int status;
  868. struct priv *p = (struct priv *) dev->priv;
  869. status = p->xmit_cmds[p->xmit_last]->cmd_status;
  870. if (!(status & STAT_COMPL)) {
  871. printk(KERN_WARNING "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name);
  872. }
  873. if (status & STAT_OK) {
  874. p->stats.tx_packets++;
  875. p->stats.collisions += (status & TCMD_MAXCOLLMASK);
  876. } else {
  877. p->stats.tx_errors++;
  878. if (status & TCMD_LATECOLL) {
  879. printk(KERN_WARNING "%s: late collision detected.\n", dev->name);
  880. p->stats.collisions++;
  881. } else if (status & TCMD_NOCARRIER) {
  882. p->stats.tx_carrier_errors++;
  883. printk(KERN_WARNING "%s: no carrier detected.\n", dev->name);
  884. } else if (status & TCMD_LOSTCTS) {
  885. printk(KERN_WARNING "%s: loss of CTS detected.\n", dev->name);
  886. } else if (status & TCMD_UNDERRUN) {
  887. p->stats.tx_fifo_errors++;
  888. printk(KERN_WARNING "%s: DMA underrun detected.\n", dev->name);
  889. } else if (status & TCMD_MAXCOLL) {
  890. printk(KERN_WARNING "%s: Max. collisions exceeded.\n", dev->name);
  891. p->stats.collisions += 16;
  892. }
  893. }
  894. #if (NUM_XMIT_BUFFS != 1)
  895. if ((++p->xmit_last) == NUM_XMIT_BUFFS) {
  896. p->xmit_last = 0;
  897. }
  898. #endif
  899. netif_wake_queue(dev);
  900. }
  901. /***********************************************************
  902. * (re)start the receiver
  903. */
  904. static void startrecv586(struct net_device *dev)
  905. {
  906. struct priv *p = (struct priv *) dev->priv;
  907. p->scb->rfa_offset = make16(p->rfd_first);
  908. p->scb->cmd = RUC_START;
  909. elmc_attn586(); /* start cmd. */
  910. WAIT_4_SCB_CMD(); /* wait for accept cmd. (no timeout!!) */
  911. }
  912. /******************************************************
  913. * timeout
  914. */
  915. static void elmc_timeout(struct net_device *dev)
  916. {
  917. struct priv *p = (struct priv *) dev->priv;
  918. /* COMMAND-UNIT active? */
  919. if (p->scb->status & CU_ACTIVE) {
  920. #ifdef DEBUG
  921. printk("%s: strange ... timeout with CU active?!?\n", dev->name);
  922. printk("%s: X0: %04x N0: %04x N1: %04x %d\n", dev->name, (int) p->xmit_cmds[0]->cmd_status, (int) p->nop_cmds[0]->cmd_status, (int) p->nop_cmds[1]->cmd_status, (int) p->nop_point);
  923. #endif
  924. p->scb->cmd = CUC_ABORT;
  925. elmc_attn586();
  926. WAIT_4_SCB_CMD();
  927. p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]);
  928. p->scb->cmd = CUC_START;
  929. elmc_attn586();
  930. WAIT_4_SCB_CMD();
  931. netif_wake_queue(dev);
  932. } else {
  933. #ifdef DEBUG
  934. printk("%s: xmitter timed out, try to restart! stat: %04x\n", dev->name, p->scb->status);
  935. printk("%s: command-stats: %04x %04x\n", dev->name, p->xmit_cmds[0]->cmd_status, p->xmit_cmds[1]->cmd_status);
  936. #endif
  937. elmc_close(dev);
  938. elmc_open(dev);
  939. }
  940. }
  941. /******************************************************
  942. * send frame
  943. */
  944. static int elmc_send_packet(struct sk_buff *skb, struct net_device *dev)
  945. {
  946. int len;
  947. int i;
  948. #ifndef NO_NOPCOMMANDS
  949. int next_nop;
  950. #endif
  951. struct priv *p = (struct priv *) dev->priv;
  952. netif_stop_queue(dev);
  953. len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
  954. if (len != skb->len)
  955. memset((char *) p->xmit_cbuffs[p->xmit_count], 0, ETH_ZLEN);
  956. memcpy((char *) p->xmit_cbuffs[p->xmit_count], (char *) (skb->data), skb->len);
  957. #if (NUM_XMIT_BUFFS == 1)
  958. #ifdef NO_NOPCOMMANDS
  959. p->xmit_buffs[0]->size = TBD_LAST | len;
  960. for (i = 0; i < 16; i++) {
  961. p->scb->cbl_offset = make16(p->xmit_cmds[0]);
  962. p->scb->cmd = CUC_START;
  963. p->xmit_cmds[0]->cmd_status = 0;
  964. elmc_attn586();
  965. dev->trans_start = jiffies;
  966. if (!i) {
  967. dev_kfree_skb(skb);
  968. }
  969. WAIT_4_SCB_CMD();
  970. if ((p->scb->status & CU_ACTIVE)) { /* test it, because CU sometimes doesn't start immediately */
  971. break;
  972. }
  973. if (p->xmit_cmds[0]->cmd_status) {
  974. break;
  975. }
  976. if (i == 15) {
  977. printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name);
  978. }
  979. }
  980. #else
  981. next_nop = (p->nop_point + 1) & 0x1;
  982. p->xmit_buffs[0]->size = TBD_LAST | len;
  983. p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link
  984. = make16((p->nop_cmds[next_nop]));
  985. p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0;
  986. p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0]));
  987. dev->trans_start = jiffies;
  988. p->nop_point = next_nop;
  989. dev_kfree_skb(skb);
  990. #endif
  991. #else
  992. p->xmit_buffs[p->xmit_count]->size = TBD_LAST | len;
  993. if ((next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS) {
  994. next_nop = 0;
  995. }
  996. p->xmit_cmds[p->xmit_count]->cmd_status = 0;
  997. p->xmit_cmds[p->xmit_count]->cmd_link = p->nop_cmds[next_nop]->cmd_link
  998. = make16((p->nop_cmds[next_nop]));
  999. p->nop_cmds[next_nop]->cmd_status = 0;
  1000. p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count]));
  1001. dev->trans_start = jiffies;
  1002. p->xmit_count = next_nop;
  1003. if (p->xmit_count != p->xmit_last)
  1004. netif_wake_queue(dev);
  1005. dev_kfree_skb(skb);
  1006. #endif
  1007. return 0;
  1008. }
  1009. /*******************************************
  1010. * Someone wanna have the statistics
  1011. */
  1012. static struct net_device_stats *elmc_get_stats(struct net_device *dev)
  1013. {
  1014. struct priv *p = (struct priv *) dev->priv;
  1015. unsigned short crc, aln, rsc, ovrn;
  1016. crc = p->scb->crc_errs; /* get error-statistic from the ni82586 */
  1017. p->scb->crc_errs -= crc;
  1018. aln = p->scb->aln_errs;
  1019. p->scb->aln_errs -= aln;
  1020. rsc = p->scb->rsc_errs;
  1021. p->scb->rsc_errs -= rsc;
  1022. ovrn = p->scb->ovrn_errs;
  1023. p->scb->ovrn_errs -= ovrn;
  1024. p->stats.rx_crc_errors += crc;
  1025. p->stats.rx_fifo_errors += ovrn;
  1026. p->stats.rx_frame_errors += aln;
  1027. p->stats.rx_dropped += rsc;
  1028. return &p->stats;
  1029. }
  1030. /********************************************************
  1031. * Set MC list ..
  1032. */
  1033. #ifdef ELMC_MULTICAST
  1034. static void set_multicast_list(struct net_device *dev)
  1035. {
  1036. if (!dev->start) {
  1037. /* without a running interface, promiscuous doesn't work */
  1038. return;
  1039. }
  1040. dev->start = 0;
  1041. alloc586(dev);
  1042. init586(dev);
  1043. startrecv586(dev);
  1044. dev->start = 1;
  1045. }
  1046. #endif
  1047. static void netdev_get_drvinfo(struct net_device *dev,
  1048. struct ethtool_drvinfo *info)
  1049. {
  1050. strcpy(info->driver, DRV_NAME);
  1051. strcpy(info->version, DRV_VERSION);
  1052. sprintf(info->bus_info, "MCA 0x%lx", dev->base_addr);
  1053. }
  1054. static const struct ethtool_ops netdev_ethtool_ops = {
  1055. .get_drvinfo = netdev_get_drvinfo,
  1056. };
  1057. #ifdef MODULE
  1058. /* Increase if needed ;) */
  1059. #define MAX_3C523_CARDS 4
  1060. static struct net_device *dev_elmc[MAX_3C523_CARDS];
  1061. static int irq[MAX_3C523_CARDS];
  1062. static int io[MAX_3C523_CARDS];
  1063. module_param_array(irq, int, NULL, 0);
  1064. module_param_array(io, int, NULL, 0);
  1065. MODULE_PARM_DESC(io, "EtherLink/MC I/O base address(es)");
  1066. MODULE_PARM_DESC(irq, "EtherLink/MC IRQ number(s)");
  1067. MODULE_LICENSE("GPL");
  1068. int __init init_module(void)
  1069. {
  1070. int this_dev,found = 0;
  1071. /* Loop until we either can't find any more cards, or we have MAX_3C523_CARDS */
  1072. for(this_dev=0; this_dev<MAX_3C523_CARDS; this_dev++) {
  1073. struct net_device *dev = alloc_etherdev(sizeof(struct priv));
  1074. if (!dev)
  1075. break;
  1076. dev->irq=irq[this_dev];
  1077. dev->base_addr=io[this_dev];
  1078. if (do_elmc_probe(dev) == 0) {
  1079. dev_elmc[this_dev] = dev;
  1080. found++;
  1081. continue;
  1082. }
  1083. free_netdev(dev);
  1084. if (io[this_dev]==0)
  1085. break;
  1086. printk(KERN_WARNING "3c523.c: No 3c523 card found at io=%#x\n",io[this_dev]);
  1087. }
  1088. if(found==0) {
  1089. if(io[0]==0) printk(KERN_NOTICE "3c523.c: No 3c523 cards found\n");
  1090. return -ENXIO;
  1091. } else return 0;
  1092. }
  1093. void __exit cleanup_module(void)
  1094. {
  1095. int this_dev;
  1096. for (this_dev=0; this_dev<MAX_3C523_CARDS; this_dev++) {
  1097. struct net_device *dev = dev_elmc[this_dev];
  1098. if (dev) {
  1099. unregister_netdev(dev);
  1100. cleanup_card(dev);
  1101. free_netdev(dev);
  1102. }
  1103. }
  1104. }
  1105. #endif /* MODULE */