ni52.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342
  1. /*
  2. * net-3-driver for the NI5210 card (i82586 Ethernet chip)
  3. *
  4. * This is an extension to the Linux operating system, and is covered by the
  5. * same GNU General Public License that covers that work.
  6. *
  7. * Alphacode 0.82 (96/09/29) for Linux 2.0.0 (or later)
  8. * Copyrights (c) 1994,1995,1996 by M.Hipp (hippm@informatik.uni-tuebingen.de)
  9. * [feel free to mail ....]
  10. *
  11. * when using as module: (no autoprobing!)
  12. * compile with:
  13. * gcc -O2 -fomit-frame-pointer -m486 -D__KERNEL__ -DMODULE -c ni52.c
  14. * run with e.g:
  15. * insmod ni52.o io=0x360 irq=9 memstart=0xd0000 memend=0xd4000
  16. *
  17. * CAN YOU PLEASE REPORT ME YOUR PERFORMANCE EXPERIENCES !!.
  18. *
  19. * If you find a bug, please report me:
  20. * The kernel panic output and any kmsg from the ni52 driver
  21. * the ni5210-driver-version and the linux-kernel version
  22. * how many shared memory (memsize) on the netcard,
  23. * bootprom: yes/no, base_addr, mem_start
  24. * maybe the ni5210-card revision and the i82586 version
  25. *
  26. * autoprobe for: base_addr: 0x300,0x280,0x360,0x320,0x340
  27. * mem_start: 0xd0000,0xd2000,0xc8000,0xca000,0xd4000,0xd6000,
  28. * 0xd8000,0xcc000,0xce000,0xda000,0xdc000
  29. *
  30. * sources:
  31. * skeleton.c from Donald Becker
  32. *
  33. * I have also done a look in the following sources: (mail me if you need them)
  34. * crynwr-packet-driver by Russ Nelson
  35. * Garret A. Wollman's (fourth) i82586-driver for BSD
  36. * (before getting an i82596 (yes 596 not 586) manual, the existing drivers
  37. * helped me a lot to understand this tricky chip.)
  38. *
  39. * Known Problems:
  40. * The internal sysbus seems to be slow. So we often lose packets because of
  41. * overruns while receiving from a fast remote host.
  42. * This can slow down TCP connections. Maybe the newer ni5210 cards are
  43. * better. My experience is, that if a machine sends with more than about
  44. * 500-600K/s the fifo/sysbus overflows.
  45. *
  46. * IMPORTANT NOTE:
  47. * On fast networks, it's a (very) good idea to have 16K shared memory. With
  48. * 8K, we can store only 4 receive frames, so it can (easily) happen that a
  49. * remote machine 'overruns' our system.
  50. *
  51. * Known i82586/card problems (I'm sure, there are many more!):
  52. * Running the NOP-mode, the i82586 sometimes seems to forget to report
  53. * every xmit-interrupt until we restart the CU.
  54. * Another MAJOR bug is, that the RU sometimes seems to ignore the EL-Bit
  55. * in the RBD-Struct which indicates an end of the RBD queue.
  56. * Instead, the RU fetches another (randomly selected and
  57. * usually used) RBD and begins to fill it. (Maybe, this happens only if
  58. * the last buffer from the previous RFD fits exact into the queue and
  59. * the next RFD can't fetch an initial RBD. Anyone knows more? )
  60. *
  61. * results from ftp performance tests with Linux 1.2.5
  62. * send and receive about 350-400 KByte/s (peak up to 460 kbytes/s)
  63. * sending in NOP-mode: peak performance up to 530K/s (but better don't
  64. * run this mode)
  65. */
  66. /*
  67. * 29.Sept.96: virt_to_bus changes for new memory scheme
  68. * 19.Feb.96: more Mcast changes, module support (MH)
  69. *
  70. * 18.Nov.95: Mcast changes (AC).
  71. *
  72. * 23.April.95: fixed(?) receiving problems by configuring a RFD more
  73. * than the number of RBD's. Can maybe cause other problems.
  74. * 18.April.95: Added MODULE support (MH)
  75. * 17.April.95: MC related changes in init586() and set_multicast_list().
  76. * removed use of 'jiffies' in init586() (MH)
  77. *
  78. * 19.Sep.94: Added Multicast support (not tested yet) (MH)
  79. *
  80. * 18.Sep.94: Workaround for 'EL-Bug'. Removed flexible RBD-handling.
  81. * Now, every RFD has exact one RBD. (MH)
  82. *
  83. * 14.Sep.94: added promiscuous mode, a few cleanups (MH)
  84. *
  85. * 19.Aug.94: changed request_irq() parameter (MH)
  86. *
  87. * 20.July.94: removed cleanup bugs, removed a 16K-mem-probe-bug (MH)
  88. *
  89. * 19.July.94: lotsa cleanups .. (MH)
  90. *
  91. * 17.July.94: some patches ... verified to run with 1.1.29 (MH)
  92. *
  93. * 4.July.94: patches for Linux 1.1.24 (MH)
  94. *
  95. * 26.March.94: patches for Linux 1.0 and iomem-auto-probe (MH)
  96. *
  97. * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff,
  98. * too (MH)
  99. *
  100. * < 30.Sep.93: first versions
  101. */
  102. static int debuglevel; /* debug-printk 0: off 1: a few 2: more */
  103. static int automatic_resume; /* experimental .. better should be zero */
  104. static int rfdadd; /* rfdadd=1 may be better for 8K MEM cards */
  105. static int fifo = 0x8; /* don't change */
  106. #include <linux/module.h>
  107. #include <linux/kernel.h>
  108. #include <linux/string.h>
  109. #include <linux/errno.h>
  110. #include <linux/ioport.h>
  111. #include <linux/slab.h>
  112. #include <linux/interrupt.h>
  113. #include <linux/delay.h>
  114. #include <linux/init.h>
  115. #include <linux/bitops.h>
  116. #include <asm/io.h>
  117. #include <linux/netdevice.h>
  118. #include <linux/etherdevice.h>
  119. #include <linux/skbuff.h>
  120. #include "ni52.h"
  121. #define DRV_NAME "ni52"
  122. #define DEBUG /* debug on */
  123. #define SYSBUSVAL 1 /* 8 Bit */
  124. #define ni_attn586() { outb(0, dev->base_addr + NI52_ATTENTION); }
  125. #define ni_reset586() { outb(0, dev->base_addr + NI52_RESET); }
  126. #define ni_disint() { outb(0, dev->base_addr + NI52_INTDIS); }
  127. #define ni_enaint() { outb(0, dev->base_addr + NI52_INTENA); }
  128. #define make32(ptr16) (p->memtop + (short) (ptr16))
  129. #define make24(ptr32) ((unsigned long)(ptr32)) - p->base
  130. #define make16(ptr32) ((unsigned short) ((unsigned long)(ptr32)\
  131. - (unsigned long) p->memtop))
  132. /******************* how to calculate the buffers *****************************
  133. * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
  134. * --------------- in a different (more stable?) mode. Only in this mode it's
  135. * possible to configure the driver with 'NO_NOPCOMMANDS'
  136. sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
  137. sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
  138. sizeof(rfd) = 24; sizeof(rbd) = 12;
  139. sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
  140. sizeof(nop_cmd) = 8;
  141. * if you don't know the driver, better do not change these values: */
  142. #define RECV_BUFF_SIZE 1524 /* slightly oversized */
  143. #define XMIT_BUFF_SIZE 1524 /* slightly oversized */
  144. #define NUM_XMIT_BUFFS 1 /* config for both, 8K and 16K shmem */
  145. #define NUM_RECV_BUFFS_8 4 /* config for 8K shared mem */
  146. #define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */
  147. #define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 */
  148. /**************************************************************************/
  149. #define NI52_TOTAL_SIZE 16
  150. #define NI52_ADDR0 0x02
  151. #define NI52_ADDR1 0x07
  152. #define NI52_ADDR2 0x01
  153. static int ni52_probe1(struct net_device *dev, int ioaddr);
  154. static irqreturn_t ni52_interrupt(int irq, void *dev_id);
  155. static int ni52_open(struct net_device *dev);
  156. static int ni52_close(struct net_device *dev);
  157. static int ni52_send_packet(struct sk_buff *, struct net_device *);
  158. static struct net_device_stats *ni52_get_stats(struct net_device *dev);
  159. static void set_multicast_list(struct net_device *dev);
  160. static void ni52_timeout(struct net_device *dev);
  161. /* helper-functions */
  162. static int init586(struct net_device *dev);
  163. static int check586(struct net_device *dev, char *where, unsigned size);
  164. static void alloc586(struct net_device *dev);
  165. static void startrecv586(struct net_device *dev);
  166. static void __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr);
  167. static void ni52_rcv_int(struct net_device *dev);
  168. static void ni52_xmt_int(struct net_device *dev);
  169. static void ni52_rnr_int(struct net_device *dev);
  170. struct priv {
  171. struct net_device_stats stats;
  172. unsigned long base;
  173. char __iomem *memtop;
  174. spinlock_t spinlock;
  175. int reset;
  176. struct rfd_struct __iomem *rfd_last, *rfd_top, *rfd_first;
  177. struct scp_struct __iomem *scp;
  178. struct iscp_struct __iomem *iscp;
  179. struct scb_struct __iomem *scb;
  180. struct tbd_struct __iomem *xmit_buffs[NUM_XMIT_BUFFS];
  181. #if (NUM_XMIT_BUFFS == 1)
  182. struct transmit_cmd_struct __iomem *xmit_cmds[2];
  183. struct nop_cmd_struct __iomem *nop_cmds[2];
  184. #else
  185. struct transmit_cmd_struct __iomem *xmit_cmds[NUM_XMIT_BUFFS];
  186. struct nop_cmd_struct __iomem *nop_cmds[NUM_XMIT_BUFFS];
  187. #endif
  188. int nop_point, num_recv_buffs;
  189. char __iomem *xmit_cbuffs[NUM_XMIT_BUFFS];
  190. int xmit_count, xmit_last;
  191. };
  192. /* wait for command with timeout: */
  193. static void wait_for_scb_cmd(struct net_device *dev)
  194. {
  195. struct priv *p = dev->priv;
  196. int i;
  197. for (i = 0; i < 16384; i++) {
  198. if (readb(&p->scb->cmd_cuc) == 0)
  199. break;
  200. udelay(4);
  201. if (i == 16383) {
  202. printk(KERN_ERR "%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n",
  203. dev->name, readb(&p->scb->cmd_cuc), readb(&p->scb->cus));
  204. if (!p->reset) {
  205. p->reset = 1;
  206. ni_reset586();
  207. }
  208. }
  209. }
  210. }
  211. static void wait_for_scb_cmd_ruc(struct net_device *dev)
  212. {
  213. struct priv *p = dev->priv;
  214. int i;
  215. for (i = 0; i < 16384; i++) {
  216. if (readb(&p->scb->cmd_ruc) == 0)
  217. break;
  218. udelay(4);
  219. if (i == 16383) {
  220. printk(KERN_ERR "%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n",
  221. dev->name, p->scb->cmd_ruc, p->scb->rus);
  222. if (!p->reset) {
  223. p->reset = 1;
  224. ni_reset586();
  225. }
  226. }
  227. }
  228. }
  229. static void wait_for_stat_compl(void __iomem *p)
  230. {
  231. struct nop_cmd_struct __iomem *addr = p;
  232. int i;
  233. for (i = 0; i < 32767; i++) {
  234. if (readw(&((addr)->cmd_status)) & STAT_COMPL)
  235. break;
  236. udelay(32);
  237. }
  238. }
  239. /**********************************************
  240. * close device
  241. */
  242. static int ni52_close(struct net_device *dev)
  243. {
  244. free_irq(dev->irq, dev);
  245. ni_reset586(); /* the hard way to stop the receiver */
  246. netif_stop_queue(dev);
  247. return 0;
  248. }
  249. /**********************************************
  250. * open device
  251. */
  252. static int ni52_open(struct net_device *dev)
  253. {
  254. int ret;
  255. ni_disint();
  256. alloc586(dev);
  257. init586(dev);
  258. startrecv586(dev);
  259. ni_enaint();
  260. ret = request_irq(dev->irq, &ni52_interrupt, 0, dev->name, dev);
  261. if (ret) {
  262. ni_reset586();
  263. return ret;
  264. }
  265. netif_start_queue(dev);
  266. return 0; /* most done by init */
  267. }
  268. /**********************************************
  269. * Check to see if there's an 82586 out there.
  270. */
  271. static int check586(struct net_device *dev, char *where, unsigned size)
  272. {
  273. struct priv pb;
  274. struct priv *p = /* (struct priv *) dev->priv*/ &pb;
  275. char __iomem *iscp_addrs[2];
  276. int i;
  277. p->base = (unsigned long) isa_bus_to_virt((unsigned long)where)
  278. + size - 0x01000000;
  279. p->memtop = (char __iomem *)isa_bus_to_virt((unsigned long)where) + size;
  280. p->scp = (struct scp_struct __iomem *)(p->base + SCP_DEFAULT_ADDRESS);
  281. memset_io(p->scp, 0, sizeof(struct scp_struct));
  282. for (i = 0; i < sizeof(struct scp_struct); i++)
  283. /* memory was writeable? */
  284. if (readb((char __iomem *)p->scp + i))
  285. return 0;
  286. writeb(SYSBUSVAL, &p->scp->sysbus); /* 1 = 8Bit-Bus, 0 = 16 Bit */
  287. if (readb(&p->scp->sysbus) != SYSBUSVAL)
  288. return 0;
  289. iscp_addrs[0] = (char __iomem *)isa_bus_to_virt((unsigned long)where);
  290. iscp_addrs[1] = (char __iomem *)p->scp - sizeof(struct iscp_struct);
  291. for (i = 0; i < 2; i++) {
  292. p->iscp = (struct iscp_struct __iomem *) iscp_addrs[i];
  293. memset_io(p->iscp, 0, sizeof(struct iscp_struct));
  294. writel(make24(p->iscp), &p->scp->iscp);
  295. writeb(1, &p->iscp->busy);
  296. ni_reset586();
  297. ni_attn586();
  298. mdelay(32); /* wait a while... */
  299. /* i82586 clears 'busy' after successful init */
  300. if (readb(&p->iscp->busy))
  301. return 0;
  302. }
  303. return 1;
  304. }
  305. /******************************************************************
  306. * set iscp at the right place, called by ni52_probe1 and open586.
  307. */
  308. static void alloc586(struct net_device *dev)
  309. {
  310. struct priv *p = (struct priv *) dev->priv;
  311. ni_reset586();
  312. mdelay(32);
  313. spin_lock_init(&p->spinlock);
  314. p->scp = (struct scp_struct __iomem *) (p->base + SCP_DEFAULT_ADDRESS);
  315. p->scb = (struct scb_struct __iomem *) isa_bus_to_virt(dev->mem_start);
  316. p->iscp = (struct iscp_struct __iomem *)
  317. ((char __iomem *)p->scp - sizeof(struct iscp_struct));
  318. memset_io(p->iscp, 0, sizeof(struct iscp_struct));
  319. memset_io(p->scp , 0, sizeof(struct scp_struct));
  320. writel(make24(p->iscp), &p->scp->iscp);
  321. writeb(SYSBUSVAL, &p->scp->sysbus);
  322. writew(make16(p->scb), &p->iscp->scb_offset);
  323. writeb(1, &p->iscp->busy);
  324. ni_reset586();
  325. ni_attn586();
  326. mdelay(32);
  327. if (readb(&p->iscp->busy))
  328. printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name);
  329. p->reset = 0;
  330. memset_io(p->scb, 0, sizeof(struct scb_struct));
  331. }
  332. /* set: io,irq,memstart,memend or set it when calling insmod */
  333. static int irq = 9;
  334. static int io = 0x300;
  335. static long memstart; /* e.g 0xd0000 */
  336. static long memend; /* e.g 0xd4000 */
  337. /**********************************************
  338. * probe the ni5210-card
  339. */
  340. struct net_device * __init ni52_probe(int unit)
  341. {
  342. struct net_device *dev = alloc_etherdev(sizeof(struct priv));
  343. static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0};
  344. int *port;
  345. int err = 0;
  346. if (!dev)
  347. return ERR_PTR(-ENOMEM);
  348. if (unit >= 0) {
  349. sprintf(dev->name, "eth%d", unit);
  350. netdev_boot_setup_check(dev);
  351. io = dev->base_addr;
  352. irq = dev->irq;
  353. memstart = dev->mem_start;
  354. memend = dev->mem_end;
  355. }
  356. if (io > 0x1ff) { /* Check a single specified location. */
  357. err = ni52_probe1(dev, io);
  358. } else if (io > 0) { /* Don't probe at all. */
  359. err = -ENXIO;
  360. } else {
  361. for (port = ports; *port && ni52_probe1(dev, *port) ; port++)
  362. ;
  363. if (*port)
  364. goto got_it;
  365. #ifdef FULL_IO_PROBE
  366. for (io = 0x200; io < 0x400 && ni52_probe1(dev, io); io += 8)
  367. ;
  368. if (io < 0x400)
  369. goto got_it;
  370. #endif
  371. err = -ENODEV;
  372. }
  373. if (err)
  374. goto out;
  375. got_it:
  376. err = register_netdev(dev);
  377. if (err)
  378. goto out1;
  379. return dev;
  380. out1:
  381. release_region(dev->base_addr, NI52_TOTAL_SIZE);
  382. out:
  383. free_netdev(dev);
  384. return ERR_PTR(err);
  385. }
  386. static int __init ni52_probe1(struct net_device *dev, int ioaddr)
  387. {
  388. int i, size, retval;
  389. dev->base_addr = ioaddr;
  390. dev->irq = irq;
  391. dev->mem_start = memstart;
  392. dev->mem_end = memend;
  393. if (!request_region(ioaddr, NI52_TOTAL_SIZE, DRV_NAME))
  394. return -EBUSY;
  395. if (!(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||
  396. !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) {
  397. retval = -ENODEV;
  398. goto out;
  399. }
  400. for (i = 0; i < ETH_ALEN; i++)
  401. dev->dev_addr[i] = inb(dev->base_addr+i);
  402. if (dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1
  403. || dev->dev_addr[2] != NI52_ADDR2) {
  404. retval = -ENODEV;
  405. goto out;
  406. }
  407. printk(KERN_INFO "%s: NI5210 found at %#3lx, ",
  408. dev->name, dev->base_addr);
  409. /*
  410. * check (or search) IO-Memory, 8K and 16K
  411. */
  412. #ifdef MODULE
  413. size = dev->mem_end - dev->mem_start;
  414. if (size != 0x2000 && size != 0x4000) {
  415. printk("\n");
  416. printk(KERN_ERR "%s: Invalid memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n", dev->name, size);
  417. retval = -ENODEV;
  418. goto out;
  419. }
  420. if (!check586(dev, (char *)dev->mem_start, size)) {
  421. printk(KERN_ERR "?memcheck, Can't find memory at 0x%lx with size %d!\n", dev->mem_start, size);
  422. retval = -ENODEV;
  423. goto out;
  424. }
  425. #else
  426. if (dev->mem_start != 0) {
  427. /* no auto-mem-probe */
  428. size = 0x4000; /* check for 16K mem */
  429. if (!check586(dev, (char *) dev->mem_start, size)) {
  430. size = 0x2000; /* check for 8K mem */
  431. if (!check586(dev, (char *)dev->mem_start, size)) {
  432. printk(KERN_ERR "?memprobe, Can't find memory at 0x%lx!\n", dev->mem_start);
  433. retval = -ENODEV;
  434. goto out;
  435. }
  436. }
  437. } else {
  438. static const unsigned long memaddrs[] = {
  439. 0xc8000, 0xca000, 0xcc000, 0xce000, 0xd0000, 0xd2000,
  440. 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0
  441. };
  442. for (i = 0;; i++) {
  443. if (!memaddrs[i]) {
  444. printk(KERN_ERR "?memprobe, Can't find io-memory!\n");
  445. retval = -ENODEV;
  446. goto out;
  447. }
  448. dev->mem_start = memaddrs[i];
  449. size = 0x2000; /* check for 8K mem */
  450. if (check586(dev, (char *)dev->mem_start, size))
  451. /* 8K-check */
  452. break;
  453. size = 0x4000; /* check for 16K mem */
  454. if (check586(dev, (char *)dev->mem_start, size))
  455. /* 16K-check */
  456. break;
  457. }
  458. }
  459. /* set mem_end showed by 'ifconfig' */
  460. dev->mem_end = dev->mem_start + size;
  461. #endif
  462. memset((char *)dev->priv, 0, sizeof(struct priv));
  463. ((struct priv *)(dev->priv))->memtop =
  464. (char __iomem *)isa_bus_to_virt(dev->mem_start) + size;
  465. ((struct priv *)(dev->priv))->base = (unsigned long)
  466. isa_bus_to_virt(dev->mem_start) + size - 0x01000000;
  467. alloc586(dev);
  468. /* set number of receive-buffs according to memsize */
  469. if (size == 0x2000)
  470. ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_8;
  471. else
  472. ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_16;
  473. printk(KERN_DEBUG "Memaddr: 0x%lx, Memsize: %d, ",
  474. dev->mem_start, size);
  475. if (dev->irq < 2) {
  476. unsigned long irq_mask;
  477. irq_mask = probe_irq_on();
  478. ni_reset586();
  479. ni_attn586();
  480. mdelay(20);
  481. dev->irq = probe_irq_off(irq_mask);
  482. if (!dev->irq) {
  483. printk("?autoirq, Failed to detect IRQ line!\n");
  484. retval = -EAGAIN;
  485. goto out;
  486. }
  487. printk("IRQ %d (autodetected).\n", dev->irq);
  488. } else {
  489. if (dev->irq == 2)
  490. dev->irq = 9;
  491. printk("IRQ %d (assigned and not checked!).\n", dev->irq);
  492. }
  493. dev->open = ni52_open;
  494. dev->stop = ni52_close;
  495. dev->get_stats = ni52_get_stats;
  496. dev->tx_timeout = ni52_timeout;
  497. dev->watchdog_timeo = HZ/20;
  498. dev->hard_start_xmit = ni52_send_packet;
  499. dev->set_multicast_list = set_multicast_list;
  500. dev->if_port = 0;
  501. return 0;
  502. out:
  503. release_region(ioaddr, NI52_TOTAL_SIZE);
  504. return retval;
  505. }
  506. /**********************************************
  507. * init the chip (ni52-interrupt should be disabled?!)
  508. * needs a correct 'allocated' memory
  509. */
  510. static int init586(struct net_device *dev)
  511. {
  512. void __iomem *ptr;
  513. int i, result = 0;
  514. struct priv *p = (struct priv *)dev->priv;
  515. struct configure_cmd_struct __iomem *cfg_cmd;
  516. struct iasetup_cmd_struct __iomem *ias_cmd;
  517. struct tdr_cmd_struct __iomem *tdr_cmd;
  518. struct mcsetup_cmd_struct __iomem *mc_cmd;
  519. struct dev_mc_list *dmi = dev->mc_list;
  520. int num_addrs = dev->mc_count;
  521. ptr = p->scb + 1;
  522. cfg_cmd = ptr; /* configure-command */
  523. writew(0, &cfg_cmd->cmd_status);
  524. writew(CMD_CONFIGURE | CMD_LAST, &cfg_cmd->cmd_cmd);
  525. writew(0xFFFF, &cfg_cmd->cmd_link);
  526. /* number of cfg bytes */
  527. writeb(0x0a, &cfg_cmd->byte_cnt);
  528. /* fifo-limit (8=tx:32/rx:64) */
  529. writeb(fifo, &cfg_cmd->fifo);
  530. /* hold or discard bad recv frames (bit 7) */
  531. writeb(0x40, &cfg_cmd->sav_bf);
  532. /* addr_len |!src_insert |pre-len |loopback */
  533. writeb(0x2e, &cfg_cmd->adr_len);
  534. writeb(0x00, &cfg_cmd->priority);
  535. writeb(0x60, &cfg_cmd->ifs);;
  536. writeb(0x00, &cfg_cmd->time_low);
  537. writeb(0xf2, &cfg_cmd->time_high);
  538. writeb(0x00, &cfg_cmd->promisc);;
  539. if (dev->flags & IFF_ALLMULTI) {
  540. int len = ((char __iomem *)p->iscp - (char __iomem *)ptr - 8) / 6;
  541. if (num_addrs > len) {
  542. printk(KERN_ERR "%s: switching to promisc. mode\n",
  543. dev->name);
  544. dev->flags |= IFF_PROMISC;
  545. }
  546. }
  547. if (dev->flags & IFF_PROMISC)
  548. writeb(0x01, &cfg_cmd->promisc);
  549. writeb(0x00, &cfg_cmd->carr_coll);
  550. writew(make16(cfg_cmd), &p->scb->cbl_offset);
  551. writew(0, &p->scb->cmd_ruc);
  552. writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
  553. ni_attn586();
  554. wait_for_stat_compl(cfg_cmd);
  555. if ((readw(&cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) !=
  556. (STAT_COMPL|STAT_OK)) {
  557. printk(KERN_ERR "%s: configure command failed: %x\n",
  558. dev->name, readw(&cfg_cmd->cmd_status));
  559. return 1;
  560. }
  561. /*
  562. * individual address setup
  563. */
  564. ias_cmd = ptr;
  565. writew(0, &ias_cmd->cmd_status);
  566. writew(CMD_IASETUP | CMD_LAST, &ias_cmd->cmd_cmd);
  567. writew(0xffff, &ias_cmd->cmd_link);
  568. memcpy_toio(&ias_cmd->iaddr, (char *)dev->dev_addr, ETH_ALEN);
  569. writew(make16(ias_cmd), &p->scb->cbl_offset);
  570. writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
  571. ni_attn586();
  572. wait_for_stat_compl(ias_cmd);
  573. if ((readw(&ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) !=
  574. (STAT_OK|STAT_COMPL)) {
  575. printk(KERN_ERR "%s (ni52): individual address setup command failed: %04x\n", dev->name, readw(&ias_cmd->cmd_status));
  576. return 1;
  577. }
  578. /*
  579. * TDR, wire check .. e.g. no resistor e.t.c
  580. */
  581. tdr_cmd = ptr;
  582. writew(0, &tdr_cmd->cmd_status);
  583. writew(CMD_TDR | CMD_LAST, &tdr_cmd->cmd_cmd);
  584. writew(0xffff, &tdr_cmd->cmd_link);
  585. writew(0, &tdr_cmd->status);
  586. writew(make16(tdr_cmd), &p->scb->cbl_offset);
  587. writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
  588. ni_attn586();
  589. wait_for_stat_compl(tdr_cmd);
  590. if (!(readw(&tdr_cmd->cmd_status) & STAT_COMPL))
  591. printk(KERN_ERR "%s: Problems while running the TDR.\n",
  592. dev->name);
  593. else {
  594. udelay(16);
  595. result = readw(&tdr_cmd->status);
  596. writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc);
  597. ni_attn586(); /* ack the interrupts */
  598. if (result & TDR_LNK_OK)
  599. ;
  600. else if (result & TDR_XCVR_PRB)
  601. printk(KERN_ERR "%s: TDR: Transceiver problem. Check the cable(s)!\n",
  602. dev->name);
  603. else if (result & TDR_ET_OPN)
  604. printk(KERN_ERR "%s: TDR: No correct termination %d clocks away.\n",
  605. dev->name, result & TDR_TIMEMASK);
  606. else if (result & TDR_ET_SRT) {
  607. /* time == 0 -> strange :-) */
  608. if (result & TDR_TIMEMASK)
  609. printk(KERN_ERR "%s: TDR: Detected a short circuit %d clocks away.\n",
  610. dev->name, result & TDR_TIMEMASK);
  611. } else
  612. printk(KERN_ERR "%s: TDR: Unknown status %04x\n",
  613. dev->name, result);
  614. }
  615. /*
  616. * Multicast setup
  617. */
  618. if (num_addrs && !(dev->flags & IFF_PROMISC)) {
  619. mc_cmd = ptr;
  620. writew(0, &mc_cmd->cmd_status);
  621. writew(CMD_MCSETUP | CMD_LAST, &mc_cmd->cmd_cmd);
  622. writew(0xffff, &mc_cmd->cmd_link);
  623. writew(num_addrs * 6, &mc_cmd->mc_cnt);
  624. for (i = 0; i < num_addrs; i++, dmi = dmi->next)
  625. memcpy_toio(mc_cmd->mc_list[i],
  626. dmi->dmi_addr, 6);
  627. writew(make16(mc_cmd), &p->scb->cbl_offset);
  628. writeb(CUC_START, &p->scb->cmd_cuc);
  629. ni_attn586();
  630. wait_for_stat_compl(mc_cmd);
  631. if ((readw(&mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK))
  632. != (STAT_COMPL|STAT_OK))
  633. printk(KERN_ERR "%s: Can't apply multicast-address-list.\n", dev->name);
  634. }
  635. /*
  636. * alloc nop/xmit-cmds
  637. */
  638. #if (NUM_XMIT_BUFFS == 1)
  639. for (i = 0; i < 2; i++) {
  640. p->nop_cmds[i] = ptr;
  641. writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd);
  642. writew(0, &p->nop_cmds[i]->cmd_status);
  643. writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link);
  644. ptr = ptr + sizeof(struct nop_cmd_struct);
  645. }
  646. #else
  647. for (i = 0; i < NUM_XMIT_BUFFS; i++) {
  648. p->nop_cmds[i] = ptr;
  649. writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd);
  650. writew(0, &p->nop_cmds[i]->cmd_status);
  651. writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link);
  652. ptr = ptr + sizeof(struct nop_cmd_struct);
  653. }
  654. #endif
  655. ptr = alloc_rfa(dev, ptr); /* init receive-frame-area */
  656. /*
  657. * alloc xmit-buffs / init xmit_cmds
  658. */
  659. for (i = 0; i < NUM_XMIT_BUFFS; i++) {
  660. /* Transmit cmd/buff 0 */
  661. p->xmit_cmds[i] = ptr;
  662. ptr = ptr + sizeof(struct transmit_cmd_struct);
  663. p->xmit_cbuffs[i] = ptr; /* char-buffs */
  664. ptr = ptr + XMIT_BUFF_SIZE;
  665. p->xmit_buffs[i] = ptr; /* TBD */
  666. ptr = ptr + sizeof(struct tbd_struct);
  667. if ((void __iomem *)ptr > (void __iomem *)p->iscp) {
  668. printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n",
  669. dev->name);
  670. return 1;
  671. }
  672. memset_io(p->xmit_cmds[i], 0,
  673. sizeof(struct transmit_cmd_struct));
  674. memset_io(p->xmit_buffs[i], 0,
  675. sizeof(struct tbd_struct));
  676. writew(make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]),
  677. &p->xmit_cmds[i]->cmd_link);
  678. writew(STAT_COMPL, &p->xmit_cmds[i]->cmd_status);
  679. writew(CMD_XMIT|CMD_INT, &p->xmit_cmds[i]->cmd_cmd);
  680. writew(make16(p->xmit_buffs[i]), &p->xmit_cmds[i]->tbd_offset);
  681. writew(0xffff, &p->xmit_buffs[i]->next);
  682. writel(make24(p->xmit_cbuffs[i]), &p->xmit_buffs[i]->buffer);
  683. }
  684. p->xmit_count = 0;
  685. p->xmit_last = 0;
  686. #ifndef NO_NOPCOMMANDS
  687. p->nop_point = 0;
  688. #endif
  689. /*
  690. * 'start transmitter'
  691. */
  692. #ifndef NO_NOPCOMMANDS
  693. writew(make16(p->nop_cmds[0]), &p->scb->cbl_offset);
  694. writeb(CUC_START, &p->scb->cmd_cuc);
  695. ni_attn586();
  696. wait_for_scb_cmd(dev);
  697. #else
  698. writew(make16(p->xmit_cmds[0]), &p->xmit_cmds[0]->cmd_link);
  699. writew(CMD_XMIT | CMD_SUSPEND | CMD_INT, &p->xmit_cmds[0]->cmd_cmd);
  700. #endif
  701. /*
  702. * ack. interrupts
  703. */
  704. writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc);
  705. ni_attn586();
  706. udelay(16);
  707. ni_enaint();
  708. return 0;
  709. }
  710. /******************************************************
  711. * This is a helper routine for ni52_rnr_int() and init586().
  712. * It sets up the Receive Frame Area (RFA).
  713. */
  714. static void __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr)
  715. {
  716. struct rfd_struct __iomem *rfd = ptr;
  717. struct rbd_struct __iomem *rbd;
  718. int i;
  719. struct priv *p = (struct priv *) dev->priv;
  720. memset_io(rfd, 0,
  721. sizeof(struct rfd_struct) * (p->num_recv_buffs + rfdadd));
  722. p->rfd_first = rfd;
  723. for (i = 0; i < (p->num_recv_buffs + rfdadd); i++) {
  724. writew(make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd)),
  725. &rfd[i].next);
  726. writew(0xffff, &rfd[i].rbd_offset);
  727. }
  728. /* RU suspend */
  729. writeb(RFD_SUSP, &rfd[p->num_recv_buffs-1+rfdadd].last);
  730. ptr = rfd + (p->num_recv_buffs + rfdadd);
  731. rbd = ptr;
  732. ptr = rbd + p->num_recv_buffs;
  733. /* clr descriptors */
  734. memset_io(rbd, 0, sizeof(struct rbd_struct) * (p->num_recv_buffs));
  735. for (i = 0; i < p->num_recv_buffs; i++) {
  736. writew(make16(rbd + (i+1) % p->num_recv_buffs), &rbd[i].next);
  737. writew(RECV_BUFF_SIZE, &rbd[i].size);
  738. writel(make24(ptr), &rbd[i].buffer);
  739. ptr = ptr + RECV_BUFF_SIZE;
  740. }
  741. p->rfd_top = p->rfd_first;
  742. p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd);
  743. writew(make16(p->rfd_first), &p->scb->rfa_offset);
  744. writew(make16(rbd), &p->rfd_first->rbd_offset);
  745. return ptr;
  746. }
  747. /**************************************************
  748. * Interrupt Handler ...
  749. */
  750. static irqreturn_t ni52_interrupt(int irq, void *dev_id)
  751. {
  752. struct net_device *dev = dev_id;
  753. unsigned int stat;
  754. int cnt = 0;
  755. struct priv *p;
  756. p = (struct priv *) dev->priv;
  757. if (debuglevel > 1)
  758. printk("I");
  759. spin_lock(&p->spinlock);
  760. wait_for_scb_cmd(dev); /* wait for last command */
  761. while ((stat = readb(&p->scb->cus) & STAT_MASK)) {
  762. writeb(stat, &p->scb->cmd_cuc);
  763. ni_attn586();
  764. if (stat & STAT_FR) /* received a frame */
  765. ni52_rcv_int(dev);
  766. if (stat & STAT_RNR) { /* RU went 'not ready' */
  767. printk("(R)");
  768. if (readb(&p->scb->rus) & RU_SUSPEND) {
  769. /* special case: RU_SUSPEND */
  770. wait_for_scb_cmd(dev);
  771. p->scb->cmd_ruc = RUC_RESUME;
  772. ni_attn586();
  773. wait_for_scb_cmd_ruc(dev);
  774. } else {
  775. printk(KERN_ERR "%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",
  776. dev->name, stat, readb(&p->scb->rus));
  777. ni52_rnr_int(dev);
  778. }
  779. }
  780. /* Command with I-bit set complete */
  781. if (stat & STAT_CX)
  782. ni52_xmt_int(dev);
  783. #ifndef NO_NOPCOMMANDS
  784. if (stat & STAT_CNA) { /* CU went 'not ready' */
  785. if (netif_running(dev))
  786. printk(KERN_ERR "%s: oops! CU has left active state. stat: %04x/%02x.\n",
  787. dev->name, stat, readb(&p->scb->cus));
  788. }
  789. #endif
  790. if (debuglevel > 1)
  791. printk("%d", cnt++);
  792. /* Wait for ack. (ni52_xmt_int can be faster than ack!!) */
  793. wait_for_scb_cmd(dev);
  794. if (p->scb->cmd_cuc) { /* timed out? */
  795. printk(KERN_ERR "%s: Acknowledge timed out.\n",
  796. dev->name);
  797. ni_disint();
  798. break;
  799. }
  800. }
  801. spin_unlock(&p->spinlock);
  802. if (debuglevel > 1)
  803. printk("i");
  804. return IRQ_HANDLED;
  805. }
  806. /*******************************************************
  807. * receive-interrupt
  808. */
  809. static void ni52_rcv_int(struct net_device *dev)
  810. {
  811. int status, cnt = 0;
  812. unsigned short totlen;
  813. struct sk_buff *skb;
  814. struct rbd_struct __iomem *rbd;
  815. struct priv *p = (struct priv *)dev->priv;
  816. if (debuglevel > 0)
  817. printk("R");
  818. for (; (status = readb(&p->rfd_top->stat_high)) & RFD_COMPL;) {
  819. rbd = (struct rbd_struct __iomem *) make32(p->rfd_top->rbd_offset);
  820. if (status & RFD_OK) { /* frame received without error? */
  821. totlen = readw(&rbd->status);
  822. if (totlen & RBD_LAST) {
  823. /* the first and the last buffer? */
  824. totlen &= RBD_MASK; /* length of this frame */
  825. writew(0x00, &rbd->status);
  826. skb = (struct sk_buff *)dev_alloc_skb(totlen+2);
  827. if (skb != NULL) {
  828. skb_reserve(skb, 2);
  829. skb_put(skb, totlen);
  830. skb_copy_to_linear_data(skb, (char *)p->base + (unsigned long) rbd->buffer, totlen);
  831. skb->protocol = eth_type_trans(skb, dev);
  832. netif_rx(skb);
  833. dev->last_rx = jiffies;
  834. p->stats.rx_packets++;
  835. p->stats.rx_bytes += totlen;
  836. } else
  837. p->stats.rx_dropped++;
  838. } else {
  839. int rstat;
  840. /* free all RBD's until RBD_LAST is set */
  841. totlen = 0;
  842. while (!((rstat = readw(&rbd->status)) & RBD_LAST)) {
  843. totlen += rstat & RBD_MASK;
  844. if (!rstat) {
  845. printk(KERN_ERR "%s: Whoops .. no end mark in RBD list\n", dev->name);
  846. break;
  847. }
  848. writew(0, &rbd->status);
  849. rbd = (struct rbd_struct __iomem *) make32(readl(&rbd->next));
  850. }
  851. totlen += rstat & RBD_MASK;
  852. writew(0, &rbd->status);
  853. printk(KERN_ERR "%s: received oversized frame! length: %d\n",
  854. dev->name, totlen);
  855. p->stats.rx_dropped++;
  856. }
  857. } else {/* frame !(ok), only with 'save-bad-frames' */
  858. printk(KERN_ERR "%s: oops! rfd-error-status: %04x\n",
  859. dev->name, status);
  860. p->stats.rx_errors++;
  861. }
  862. writeb(0, &p->rfd_top->stat_high);
  863. writeb(RFD_SUSP, &p->rfd_top->last); /* maybe exchange by RFD_LAST */
  864. writew(0xffff, &p->rfd_top->rbd_offset);
  865. writeb(0, &p->rfd_last->last); /* delete RFD_SUSP */
  866. p->rfd_last = p->rfd_top;
  867. p->rfd_top = (struct rfd_struct __iomem *) make32(p->rfd_top->next); /* step to next RFD */
  868. writew(make16(p->rfd_top), &p->scb->rfa_offset);
  869. if (debuglevel > 0)
  870. printk("%d", cnt++);
  871. }
  872. if (automatic_resume) {
  873. wait_for_scb_cmd(dev);
  874. writeb(RUC_RESUME, &p->scb->cmd_ruc);
  875. ni_attn586();
  876. wait_for_scb_cmd_ruc(dev);
  877. }
  878. #ifdef WAIT_4_BUSY
  879. {
  880. int i;
  881. for (i = 0; i < 1024; i++) {
  882. if (p->rfd_top->status)
  883. break;
  884. udelay(16);
  885. if (i == 1023)
  886. printk(KERN_ERR "%s: RU hasn't fetched next RFD (not busy/complete)\n", dev->name);
  887. }
  888. }
  889. #endif
  890. if (debuglevel > 0)
  891. printk("r");
  892. }
  893. /**********************************************************
  894. * handle 'Receiver went not ready'.
  895. */
  896. static void ni52_rnr_int(struct net_device *dev)
  897. {
  898. struct priv *p = (struct priv *) dev->priv;
  899. p->stats.rx_errors++;
  900. wait_for_scb_cmd(dev); /* wait for the last cmd, WAIT_4_FULLSTAT?? */
  901. writeb(RUC_ABORT, &p->scb->cmd_ruc); /* usually the RU is in the 'no resource'-state .. abort it now. */
  902. ni_attn586();
  903. wait_for_scb_cmd_ruc(dev); /* wait for accept cmd. */
  904. alloc_rfa(dev, p->rfd_first);
  905. /* maybe add a check here, before restarting the RU */
  906. startrecv586(dev); /* restart RU */
  907. printk(KERN_ERR "%s: Receive-Unit restarted. Status: %04x\n", dev->name, p->scb->rus);
  908. }
  909. /**********************************************************
  910. * handle xmit - interrupt
  911. */
  912. static void ni52_xmt_int(struct net_device *dev)
  913. {
  914. int status;
  915. struct priv *p = (struct priv *) dev->priv;
  916. if (debuglevel > 0)
  917. printk("X");
  918. status = readw(&p->xmit_cmds[p->xmit_last]->cmd_status);
  919. if (!(status & STAT_COMPL))
  920. printk(KERN_ERR "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name);
  921. if (status & STAT_OK) {
  922. p->stats.tx_packets++;
  923. p->stats.collisions += (status & TCMD_MAXCOLLMASK);
  924. } else {
  925. p->stats.tx_errors++;
  926. if (status & TCMD_LATECOLL) {
  927. printk(KERN_ERR "%s: late collision detected.\n",
  928. dev->name);
  929. p->stats.collisions++;
  930. } else if (status & TCMD_NOCARRIER) {
  931. p->stats.tx_carrier_errors++;
  932. printk(KERN_ERR "%s: no carrier detected.\n",
  933. dev->name);
  934. } else if (status & TCMD_LOSTCTS)
  935. printk(KERN_ERR "%s: loss of CTS detected.\n",
  936. dev->name);
  937. else if (status & TCMD_UNDERRUN) {
  938. p->stats.tx_fifo_errors++;
  939. printk(KERN_ERR "%s: DMA underrun detected.\n",
  940. dev->name);
  941. } else if (status & TCMD_MAXCOLL) {
  942. printk(KERN_ERR "%s: Max. collisions exceeded.\n",
  943. dev->name);
  944. p->stats.collisions += 16;
  945. }
  946. }
  947. #if (NUM_XMIT_BUFFS > 1)
  948. if ((++p->xmit_last) == NUM_XMIT_BUFFS)
  949. p->xmit_last = 0;
  950. #endif
  951. netif_wake_queue(dev);
  952. }
  953. /***********************************************************
  954. * (re)start the receiver
  955. */
  956. static void startrecv586(struct net_device *dev)
  957. {
  958. struct priv *p = (struct priv *) dev->priv;
  959. wait_for_scb_cmd(dev);
  960. wait_for_scb_cmd_ruc(dev);
  961. writew(make16(p->rfd_first), &p->scb->rfa_offset);
  962. writeb(RUC_START, &p->scb->cmd_ruc);
  963. ni_attn586(); /* start cmd. */
  964. wait_for_scb_cmd_ruc(dev);
  965. /* wait for accept cmd. (no timeout!!) */
  966. }
  967. static void ni52_timeout(struct net_device *dev)
  968. {
  969. struct priv *p = (struct priv *) dev->priv;
  970. #ifndef NO_NOPCOMMANDS
  971. if (readb(&p->scb->cus) & CU_ACTIVE) { /* COMMAND-UNIT active? */
  972. netif_wake_queue(dev);
  973. #ifdef DEBUG
  974. printk(KERN_ERR "%s: strange ... timeout with CU active?!?\n",
  975. dev->name);
  976. printk(KERN_ERR "%s: X0: %04x N0: %04x N1: %04x %d\n",
  977. dev->name, (int)p->xmit_cmds[0]->cmd_status,
  978. readw(&p->nop_cmds[0]->cmd_status),
  979. readw(&p->nop_cmds[1]->cmd_status),
  980. p->nop_point);
  981. #endif
  982. writeb(CUC_ABORT, &p->scb->cmd_cuc);
  983. ni_attn586();
  984. wait_for_scb_cmd(dev);
  985. writew(make16(p->nop_cmds[p->nop_point]), &p->scb->cbl_offset);
  986. writeb(CUC_START, &p->scb->cmd_cuc);
  987. ni_attn586();
  988. wait_for_scb_cmd(dev);
  989. dev->trans_start = jiffies;
  990. return 0;
  991. }
  992. #endif
  993. {
  994. #ifdef DEBUG
  995. printk(KERN_ERR "%s: xmitter timed out, try to restart! stat: %02x\n",
  996. dev->name, readb(&p->scb->cus));
  997. printk(KERN_ERR "%s: command-stats: %04x %04x\n",
  998. dev->name,
  999. readw(&p->xmit_cmds[0]->cmd_status),
  1000. readw(&p->xmit_cmds[1]->cmd_status));
  1001. printk(KERN_ERR "%s: check, whether you set the right interrupt number!\n",
  1002. dev->name);
  1003. #endif
  1004. ni52_close(dev);
  1005. ni52_open(dev);
  1006. }
  1007. dev->trans_start = jiffies;
  1008. }
  1009. /******************************************************
  1010. * send frame
  1011. */
  1012. static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev)
  1013. {
  1014. int len, i;
  1015. #ifndef NO_NOPCOMMANDS
  1016. int next_nop;
  1017. #endif
  1018. struct priv *p = (struct priv *) dev->priv;
  1019. if (skb->len > XMIT_BUFF_SIZE) {
  1020. printk(KERN_ERR "%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n", dev->name, XMIT_BUFF_SIZE, skb->len);
  1021. return 0;
  1022. }
  1023. netif_stop_queue(dev);
  1024. skb_copy_from_linear_data(skb, (char *)p->xmit_cbuffs[p->xmit_count],
  1025. skb->len);
  1026. len = skb->len;
  1027. if (len < ETH_ZLEN) {
  1028. len = ETH_ZLEN;
  1029. memset((char *)p->xmit_cbuffs[p->xmit_count]+skb->len, 0,
  1030. len - skb->len);
  1031. }
  1032. #if (NUM_XMIT_BUFFS == 1)
  1033. # ifdef NO_NOPCOMMANDS
  1034. #ifdef DEBUG
  1035. if (p->scb->cus & CU_ACTIVE) {
  1036. printk(KERN_ERR "%s: Hmmm .. CU is still running and we wanna send a new packet.\n", dev->name);
  1037. printk(KERN_ERR "%s: stat: %04x %04x\n",
  1038. dev->name, readb(&p->scb->cus),
  1039. readw(&p->xmit_cmds[0]->cmd_status));
  1040. }
  1041. #endif
  1042. writew(TBD_LAST | len, &p->xmit_buffs[0]->size);;
  1043. for (i = 0; i < 16; i++) {
  1044. writew(0, &p->xmit_cmds[0]->cmd_status);
  1045. wait_for_scb_cmd(dev);
  1046. if ((readb(&p->scb->cus) & CU_STATUS) == CU_SUSPEND)
  1047. writeb(CUC_RESUME, &p->scb->cmd_cuc);
  1048. else {
  1049. writew(make16(p->xmit_cmds[0]), &p->scb->cbl_offset);
  1050. writeb(CUC_START, &p->scb->cmd_cuc);
  1051. }
  1052. ni_attn586();
  1053. dev->trans_start = jiffies;
  1054. if (!i)
  1055. dev_kfree_skb(skb);
  1056. wait_for_scb_cmd(dev);
  1057. /* test it, because CU sometimes doesn't start immediately */
  1058. if (readb(&p->scb->cus) & CU_ACTIVE)
  1059. break;
  1060. if (readw(&p->xmit_cmds[0]->cmd_status))
  1061. break;
  1062. if (i == 15)
  1063. printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name);
  1064. }
  1065. # else
  1066. next_nop = (p->nop_point + 1) & 0x1;
  1067. writew(TBD_LAST | len, &p->xmit_buffs[0]->size);
  1068. writew(make16(p->nop_cmds[next_nop]), &p->xmit_cmds[0]->cmd_link);
  1069. writew(make16(p->nop_cmds[next_nop]),
  1070. &p->nop_cmds[next_nop]->cmd_link);
  1071. writew(0, &p->xmit_cmds[0]->cmd_status);
  1072. writew(0, &p->nop_cmds[next_nop]->cmd_status);
  1073. writew(make16(p->xmit_cmds[0]), &p->nop_cmds[p->nop_point]->cmd_link);
  1074. dev->trans_start = jiffies;
  1075. p->nop_point = next_nop;
  1076. dev_kfree_skb(skb);
  1077. # endif
  1078. #else
  1079. writew(TBD_LAST | len, &p->xmit_buffs[p->xmit_count]->size);
  1080. next_nop = p->xmit_count + 1
  1081. if (next_nop == NUM_XMIT_BUFFS)
  1082. next_nop = 0;
  1083. writew(0, &p->xmit_cmds[p->xmit_count]->cmd_status);
  1084. /* linkpointer of xmit-command already points to next nop cmd */
  1085. writew(make16(p->nop_cmds[next_nop]),
  1086. &p->nop_cmds[next_nop]->cmd_link);
  1087. writew(0, &p->nop_cmds[next_nop]->cmd_status);
  1088. writew(make16(p->xmit_cmds[p->xmit_count]),
  1089. &p->nop_cmds[p->xmit_count]->cmd_link);
  1090. dev->trans_start = jiffies;
  1091. p->xmit_count = next_nop;
  1092. {
  1093. unsigned long flags;
  1094. spin_lock_irqsave(&p->spinlock);
  1095. if (p->xmit_count != p->xmit_last)
  1096. netif_wake_queue(dev);
  1097. spin_unlock_irqrestore(&p->spinlock);
  1098. }
  1099. dev_kfree_skb(skb);
  1100. #endif
  1101. return 0;
  1102. }
  1103. /*******************************************
  1104. * Someone wanna have the statistics
  1105. */
  1106. static struct net_device_stats *ni52_get_stats(struct net_device *dev)
  1107. {
  1108. struct priv *p = (struct priv *) dev->priv;
  1109. unsigned short crc, aln, rsc, ovrn;
  1110. /* Get error-statistics from the ni82586 */
  1111. crc = readw(&p->scb->crc_errs);
  1112. writew(0, &p->scb->crc_errs);
  1113. aln = readw(&p->scb->aln_errs);
  1114. writew(0, &p->scb->aln_errs);
  1115. rsc = readw(&p->scb->rsc_errs);
  1116. writew(0, &p->scb->rsc_errs);
  1117. ovrn = readw(&p->scb->ovrn_errs);
  1118. writew(0, &p->scb->ovrn_errs);
  1119. p->stats.rx_crc_errors += crc;
  1120. p->stats.rx_fifo_errors += ovrn;
  1121. p->stats.rx_frame_errors += aln;
  1122. p->stats.rx_dropped += rsc;
  1123. return &p->stats;
  1124. }
  1125. /********************************************************
  1126. * Set MC list ..
  1127. */
  1128. static void set_multicast_list(struct net_device *dev)
  1129. {
  1130. netif_stop_queue(dev);
  1131. ni_disint();
  1132. alloc586(dev);
  1133. init586(dev);
  1134. startrecv586(dev);
  1135. ni_enaint();
  1136. netif_wake_queue(dev);
  1137. }
  1138. #ifdef MODULE
  1139. static struct net_device *dev_ni52;
  1140. module_param(io, int, 0);
  1141. module_param(irq, int, 0);
  1142. module_param(memstart, long, 0);
  1143. module_param(memend, long, 0);
  1144. MODULE_PARM_DESC(io, "NI5210 I/O base address,required");
  1145. MODULE_PARM_DESC(irq, "NI5210 IRQ number,required");
  1146. MODULE_PARM_DESC(memstart, "NI5210 memory base address,required");
  1147. MODULE_PARM_DESC(memend, "NI5210 memory end address,required");
  1148. int __init init_module(void)
  1149. {
  1150. if (io <= 0x0 || !memend || !memstart || irq < 2) {
  1151. printk(KERN_ERR "ni52: Autoprobing not allowed for modules.\n");
  1152. printk(KERN_ERR "ni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
  1153. return -ENODEV;
  1154. }
  1155. dev_ni52 = ni52_probe(-1);
  1156. if (IS_ERR(dev_ni52))
  1157. return PTR_ERR(dev_ni52);
  1158. return 0;
  1159. }
  1160. void __exit cleanup_module(void)
  1161. {
  1162. unregister_netdev(dev_ni52);
  1163. release_region(dev_ni52->base_addr, NI52_TOTAL_SIZE);
  1164. free_netdev(dev_ni52);
  1165. }
  1166. #endif /* MODULE */
  1167. MODULE_LICENSE("GPL");
  1168. /*
  1169. * END: linux/drivers/net/ni52.c
  1170. */