ni52.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  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) ((char __iomem *)(ptr32)) - p->base
  130. #define make16(ptr32) ((unsigned short) ((char __iomem *)(ptr32)\
  131. - 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, 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. char __iomem *base;
  173. char __iomem *mapped;
  174. char __iomem *memtop;
  175. spinlock_t spinlock;
  176. int reset;
  177. struct rfd_struct __iomem *rfd_last, *rfd_top, *rfd_first;
  178. struct scp_struct __iomem *scp;
  179. struct iscp_struct __iomem *iscp;
  180. struct scb_struct __iomem *scb;
  181. struct tbd_struct __iomem *xmit_buffs[NUM_XMIT_BUFFS];
  182. #if (NUM_XMIT_BUFFS == 1)
  183. struct transmit_cmd_struct __iomem *xmit_cmds[2];
  184. struct nop_cmd_struct __iomem *nop_cmds[2];
  185. #else
  186. struct transmit_cmd_struct __iomem *xmit_cmds[NUM_XMIT_BUFFS];
  187. struct nop_cmd_struct __iomem *nop_cmds[NUM_XMIT_BUFFS];
  188. #endif
  189. int nop_point, num_recv_buffs;
  190. char __iomem *xmit_cbuffs[NUM_XMIT_BUFFS];
  191. int xmit_count, xmit_last;
  192. };
  193. /* wait for command with timeout: */
  194. static void wait_for_scb_cmd(struct net_device *dev)
  195. {
  196. struct priv *p = dev->priv;
  197. int i;
  198. for (i = 0; i < 16384; i++) {
  199. if (readb(&p->scb->cmd_cuc) == 0)
  200. break;
  201. udelay(4);
  202. if (i == 16383) {
  203. printk(KERN_ERR "%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n",
  204. dev->name, readb(&p->scb->cmd_cuc), readb(&p->scb->cus));
  205. if (!p->reset) {
  206. p->reset = 1;
  207. ni_reset586();
  208. }
  209. }
  210. }
  211. }
  212. static void wait_for_scb_cmd_ruc(struct net_device *dev)
  213. {
  214. struct priv *p = dev->priv;
  215. int i;
  216. for (i = 0; i < 16384; i++) {
  217. if (readb(&p->scb->cmd_ruc) == 0)
  218. break;
  219. udelay(4);
  220. if (i == 16383) {
  221. printk(KERN_ERR "%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n",
  222. dev->name, p->scb->cmd_ruc, p->scb->rus);
  223. if (!p->reset) {
  224. p->reset = 1;
  225. ni_reset586();
  226. }
  227. }
  228. }
  229. }
  230. static void wait_for_stat_compl(void __iomem *p)
  231. {
  232. struct nop_cmd_struct __iomem *addr = p;
  233. int i;
  234. for (i = 0; i < 32767; i++) {
  235. if (readw(&((addr)->cmd_status)) & STAT_COMPL)
  236. break;
  237. udelay(32);
  238. }
  239. }
  240. /**********************************************
  241. * close device
  242. */
  243. static int ni52_close(struct net_device *dev)
  244. {
  245. free_irq(dev->irq, dev);
  246. ni_reset586(); /* the hard way to stop the receiver */
  247. netif_stop_queue(dev);
  248. return 0;
  249. }
  250. /**********************************************
  251. * open device
  252. */
  253. static int ni52_open(struct net_device *dev)
  254. {
  255. int ret;
  256. ni_disint();
  257. alloc586(dev);
  258. init586(dev);
  259. startrecv586(dev);
  260. ni_enaint();
  261. ret = request_irq(dev->irq, &ni52_interrupt, 0, dev->name, dev);
  262. if (ret) {
  263. ni_reset586();
  264. return ret;
  265. }
  266. netif_start_queue(dev);
  267. return 0; /* most done by init */
  268. }
  269. static int check_iscp(struct net_device *dev, void __iomem *addr)
  270. {
  271. struct iscp_struct __iomem *iscp = addr;
  272. struct priv *p = dev->priv;
  273. memset_io(iscp, 0, sizeof(struct iscp_struct));
  274. writel(make24(iscp), &p->scp->iscp);
  275. writeb(1, &iscp->busy);
  276. ni_reset586();
  277. ni_attn586();
  278. mdelay(32); /* wait a while... */
  279. /* i82586 clears 'busy' after successful init */
  280. if (readb(&iscp->busy))
  281. return 0;
  282. return 1;
  283. }
  284. /**********************************************
  285. * Check to see if there's an 82586 out there.
  286. */
  287. static int check586(struct net_device *dev, unsigned size)
  288. {
  289. struct priv *p = dev->priv;
  290. int i;
  291. p->mapped = (char __iomem *)isa_bus_to_virt(dev->mem_start);
  292. p->base = p->mapped + size - 0x01000000;
  293. p->memtop = p->mapped + size;
  294. p->scp = (struct scp_struct __iomem *)(p->base + SCP_DEFAULT_ADDRESS);
  295. p->scb = (struct scb_struct __iomem *) p->mapped;
  296. p->iscp = (struct iscp_struct __iomem *)p->scp - 1;
  297. memset_io(p->scp, 0, sizeof(struct scp_struct));
  298. for (i = 0; i < sizeof(struct scp_struct); i++)
  299. /* memory was writeable? */
  300. if (readb((char __iomem *)p->scp + i))
  301. return 0;
  302. writeb(SYSBUSVAL, &p->scp->sysbus); /* 1 = 8Bit-Bus, 0 = 16 Bit */
  303. if (readb(&p->scp->sysbus) != SYSBUSVAL)
  304. return 0;
  305. if (!check_iscp(dev, p->mapped))
  306. return 0;
  307. if (!check_iscp(dev, p->iscp))
  308. return 0;
  309. return 1;
  310. }
  311. /******************************************************************
  312. * set iscp at the right place, called by ni52_probe1 and open586.
  313. */
  314. static void alloc586(struct net_device *dev)
  315. {
  316. struct priv *p = (struct priv *) dev->priv;
  317. ni_reset586();
  318. mdelay(32);
  319. memset_io(p->iscp, 0, sizeof(struct iscp_struct));
  320. memset_io(p->scp , 0, sizeof(struct scp_struct));
  321. writel(make24(p->iscp), &p->scp->iscp);
  322. writeb(SYSBUSVAL, &p->scp->sysbus);
  323. writew(make16(p->scb), &p->iscp->scb_offset);
  324. writeb(1, &p->iscp->busy);
  325. ni_reset586();
  326. ni_attn586();
  327. mdelay(32);
  328. if (readb(&p->iscp->busy))
  329. printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name);
  330. p->reset = 0;
  331. memset_io(p->scb, 0, sizeof(struct scb_struct));
  332. }
  333. /* set: io,irq,memstart,memend or set it when calling insmod */
  334. static int irq = 9;
  335. static int io = 0x300;
  336. static long memstart; /* e.g 0xd0000 */
  337. static long memend; /* e.g 0xd4000 */
  338. /**********************************************
  339. * probe the ni5210-card
  340. */
  341. struct net_device * __init ni52_probe(int unit)
  342. {
  343. struct net_device *dev = alloc_etherdev(sizeof(struct priv));
  344. static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0};
  345. int *port;
  346. int err = 0;
  347. if (!dev)
  348. return ERR_PTR(-ENOMEM);
  349. if (unit >= 0) {
  350. sprintf(dev->name, "eth%d", unit);
  351. netdev_boot_setup_check(dev);
  352. io = dev->base_addr;
  353. irq = dev->irq;
  354. memstart = dev->mem_start;
  355. memend = dev->mem_end;
  356. }
  357. if (io > 0x1ff) { /* Check a single specified location. */
  358. err = ni52_probe1(dev, io);
  359. } else if (io > 0) { /* Don't probe at all. */
  360. err = -ENXIO;
  361. } else {
  362. for (port = ports; *port && ni52_probe1(dev, *port) ; port++)
  363. ;
  364. if (*port)
  365. goto got_it;
  366. #ifdef FULL_IO_PROBE
  367. for (io = 0x200; io < 0x400 && ni52_probe1(dev, io); io += 8)
  368. ;
  369. if (io < 0x400)
  370. goto got_it;
  371. #endif
  372. err = -ENODEV;
  373. }
  374. if (err)
  375. goto out;
  376. got_it:
  377. err = register_netdev(dev);
  378. if (err)
  379. goto out1;
  380. return dev;
  381. out1:
  382. release_region(dev->base_addr, NI52_TOTAL_SIZE);
  383. out:
  384. free_netdev(dev);
  385. return ERR_PTR(err);
  386. }
  387. static int __init ni52_probe1(struct net_device *dev, int ioaddr)
  388. {
  389. int i, size, retval;
  390. struct priv *priv = dev->priv;
  391. dev->base_addr = ioaddr;
  392. dev->irq = irq;
  393. dev->mem_start = memstart;
  394. dev->mem_end = memend;
  395. spin_lock_init(&priv->spinlock);
  396. if (!request_region(ioaddr, NI52_TOTAL_SIZE, DRV_NAME))
  397. return -EBUSY;
  398. if (!(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||
  399. !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) {
  400. retval = -ENODEV;
  401. goto out;
  402. }
  403. for (i = 0; i < ETH_ALEN; i++)
  404. dev->dev_addr[i] = inb(dev->base_addr+i);
  405. if (dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1
  406. || dev->dev_addr[2] != NI52_ADDR2) {
  407. retval = -ENODEV;
  408. goto out;
  409. }
  410. printk(KERN_INFO "%s: NI5210 found at %#3lx, ",
  411. dev->name, dev->base_addr);
  412. /*
  413. * check (or search) IO-Memory, 8K and 16K
  414. */
  415. #ifdef MODULE
  416. size = dev->mem_end - dev->mem_start;
  417. if (size != 0x2000 && size != 0x4000) {
  418. printk("\n");
  419. printk(KERN_ERR "%s: Invalid memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n", dev->name, size);
  420. retval = -ENODEV;
  421. goto out;
  422. }
  423. if (!check586(dev, size)) {
  424. printk(KERN_ERR "?memcheck, Can't find memory at 0x%lx with size %d!\n", dev->mem_start, size);
  425. retval = -ENODEV;
  426. goto out;
  427. }
  428. #else
  429. if (dev->mem_start != 0) {
  430. /* no auto-mem-probe */
  431. size = 0x4000; /* check for 16K mem */
  432. if (!check586(dev, size)) {
  433. size = 0x2000; /* check for 8K mem */
  434. if (!check586(dev, size)) {
  435. printk(KERN_ERR "?memprobe, Can't find memory at 0x%lx!\n", dev->mem_start);
  436. retval = -ENODEV;
  437. goto out;
  438. }
  439. }
  440. } else {
  441. static const unsigned long memaddrs[] = {
  442. 0xc8000, 0xca000, 0xcc000, 0xce000, 0xd0000, 0xd2000,
  443. 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0
  444. };
  445. for (i = 0;; i++) {
  446. if (!memaddrs[i]) {
  447. printk(KERN_ERR "?memprobe, Can't find io-memory!\n");
  448. retval = -ENODEV;
  449. goto out;
  450. }
  451. dev->mem_start = memaddrs[i];
  452. size = 0x2000; /* check for 8K mem */
  453. if (check586(dev, size))
  454. /* 8K-check */
  455. break;
  456. size = 0x4000; /* check for 16K mem */
  457. if (check586(dev, size))
  458. /* 16K-check */
  459. break;
  460. }
  461. }
  462. /* set mem_end showed by 'ifconfig' */
  463. dev->mem_end = dev->mem_start + size;
  464. #endif
  465. alloc586(dev);
  466. /* set number of receive-buffs according to memsize */
  467. if (size == 0x2000)
  468. priv->num_recv_buffs = NUM_RECV_BUFFS_8;
  469. else
  470. priv->num_recv_buffs = NUM_RECV_BUFFS_16;
  471. printk(KERN_DEBUG "Memaddr: 0x%lx, Memsize: %d, ",
  472. dev->mem_start, size);
  473. if (dev->irq < 2) {
  474. unsigned long irq_mask;
  475. irq_mask = probe_irq_on();
  476. ni_reset586();
  477. ni_attn586();
  478. mdelay(20);
  479. dev->irq = probe_irq_off(irq_mask);
  480. if (!dev->irq) {
  481. printk("?autoirq, Failed to detect IRQ line!\n");
  482. retval = -EAGAIN;
  483. goto out;
  484. }
  485. printk("IRQ %d (autodetected).\n", dev->irq);
  486. } else {
  487. if (dev->irq == 2)
  488. dev->irq = 9;
  489. printk("IRQ %d (assigned and not checked!).\n", dev->irq);
  490. }
  491. dev->open = ni52_open;
  492. dev->stop = ni52_close;
  493. dev->get_stats = ni52_get_stats;
  494. dev->tx_timeout = ni52_timeout;
  495. dev->watchdog_timeo = HZ/20;
  496. dev->hard_start_xmit = ni52_send_packet;
  497. dev->set_multicast_list = set_multicast_list;
  498. dev->if_port = 0;
  499. return 0;
  500. out:
  501. release_region(ioaddr, NI52_TOTAL_SIZE);
  502. return retval;
  503. }
  504. /**********************************************
  505. * init the chip (ni52-interrupt should be disabled?!)
  506. * needs a correct 'allocated' memory
  507. */
  508. static int init586(struct net_device *dev)
  509. {
  510. void __iomem *ptr;
  511. int i, result = 0;
  512. struct priv *p = (struct priv *)dev->priv;
  513. struct configure_cmd_struct __iomem *cfg_cmd;
  514. struct iasetup_cmd_struct __iomem *ias_cmd;
  515. struct tdr_cmd_struct __iomem *tdr_cmd;
  516. struct mcsetup_cmd_struct __iomem *mc_cmd;
  517. struct dev_mc_list *dmi = dev->mc_list;
  518. int num_addrs = dev->mc_count;
  519. ptr = p->scb + 1;
  520. cfg_cmd = ptr; /* configure-command */
  521. writew(0, &cfg_cmd->cmd_status);
  522. writew(CMD_CONFIGURE | CMD_LAST, &cfg_cmd->cmd_cmd);
  523. writew(0xFFFF, &cfg_cmd->cmd_link);
  524. /* number of cfg bytes */
  525. writeb(0x0a, &cfg_cmd->byte_cnt);
  526. /* fifo-limit (8=tx:32/rx:64) */
  527. writeb(fifo, &cfg_cmd->fifo);
  528. /* hold or discard bad recv frames (bit 7) */
  529. writeb(0x40, &cfg_cmd->sav_bf);
  530. /* addr_len |!src_insert |pre-len |loopback */
  531. writeb(0x2e, &cfg_cmd->adr_len);
  532. writeb(0x00, &cfg_cmd->priority);
  533. writeb(0x60, &cfg_cmd->ifs);;
  534. writeb(0x00, &cfg_cmd->time_low);
  535. writeb(0xf2, &cfg_cmd->time_high);
  536. writeb(0x00, &cfg_cmd->promisc);;
  537. if (dev->flags & IFF_ALLMULTI) {
  538. int len = ((char __iomem *)p->iscp - (char __iomem *)ptr - 8) / 6;
  539. if (num_addrs > len) {
  540. printk(KERN_ERR "%s: switching to promisc. mode\n",
  541. dev->name);
  542. dev->flags |= IFF_PROMISC;
  543. }
  544. }
  545. if (dev->flags & IFF_PROMISC)
  546. writeb(0x01, &cfg_cmd->promisc);
  547. writeb(0x00, &cfg_cmd->carr_coll);
  548. writew(make16(cfg_cmd), &p->scb->cbl_offset);
  549. writew(0, &p->scb->cmd_ruc);
  550. writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
  551. ni_attn586();
  552. wait_for_stat_compl(cfg_cmd);
  553. if ((readw(&cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) !=
  554. (STAT_COMPL|STAT_OK)) {
  555. printk(KERN_ERR "%s: configure command failed: %x\n",
  556. dev->name, readw(&cfg_cmd->cmd_status));
  557. return 1;
  558. }
  559. /*
  560. * individual address setup
  561. */
  562. ias_cmd = ptr;
  563. writew(0, &ias_cmd->cmd_status);
  564. writew(CMD_IASETUP | CMD_LAST, &ias_cmd->cmd_cmd);
  565. writew(0xffff, &ias_cmd->cmd_link);
  566. memcpy_toio(&ias_cmd->iaddr, (char *)dev->dev_addr, ETH_ALEN);
  567. writew(make16(ias_cmd), &p->scb->cbl_offset);
  568. writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
  569. ni_attn586();
  570. wait_for_stat_compl(ias_cmd);
  571. if ((readw(&ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) !=
  572. (STAT_OK|STAT_COMPL)) {
  573. printk(KERN_ERR "%s (ni52): individual address setup command failed: %04x\n", dev->name, readw(&ias_cmd->cmd_status));
  574. return 1;
  575. }
  576. /*
  577. * TDR, wire check .. e.g. no resistor e.t.c
  578. */
  579. tdr_cmd = ptr;
  580. writew(0, &tdr_cmd->cmd_status);
  581. writew(CMD_TDR | CMD_LAST, &tdr_cmd->cmd_cmd);
  582. writew(0xffff, &tdr_cmd->cmd_link);
  583. writew(0, &tdr_cmd->status);
  584. writew(make16(tdr_cmd), &p->scb->cbl_offset);
  585. writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
  586. ni_attn586();
  587. wait_for_stat_compl(tdr_cmd);
  588. if (!(readw(&tdr_cmd->cmd_status) & STAT_COMPL))
  589. printk(KERN_ERR "%s: Problems while running the TDR.\n",
  590. dev->name);
  591. else {
  592. udelay(16);
  593. result = readw(&tdr_cmd->status);
  594. writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc);
  595. ni_attn586(); /* ack the interrupts */
  596. if (result & TDR_LNK_OK)
  597. ;
  598. else if (result & TDR_XCVR_PRB)
  599. printk(KERN_ERR "%s: TDR: Transceiver problem. Check the cable(s)!\n",
  600. dev->name);
  601. else if (result & TDR_ET_OPN)
  602. printk(KERN_ERR "%s: TDR: No correct termination %d clocks away.\n",
  603. dev->name, result & TDR_TIMEMASK);
  604. else if (result & TDR_ET_SRT) {
  605. /* time == 0 -> strange :-) */
  606. if (result & TDR_TIMEMASK)
  607. printk(KERN_ERR "%s: TDR: Detected a short circuit %d clocks away.\n",
  608. dev->name, result & TDR_TIMEMASK);
  609. } else
  610. printk(KERN_ERR "%s: TDR: Unknown status %04x\n",
  611. dev->name, result);
  612. }
  613. /*
  614. * Multicast setup
  615. */
  616. if (num_addrs && !(dev->flags & IFF_PROMISC)) {
  617. mc_cmd = ptr;
  618. writew(0, &mc_cmd->cmd_status);
  619. writew(CMD_MCSETUP | CMD_LAST, &mc_cmd->cmd_cmd);
  620. writew(0xffff, &mc_cmd->cmd_link);
  621. writew(num_addrs * 6, &mc_cmd->mc_cnt);
  622. for (i = 0; i < num_addrs; i++, dmi = dmi->next)
  623. memcpy_toio(mc_cmd->mc_list[i],
  624. dmi->dmi_addr, 6);
  625. writew(make16(mc_cmd), &p->scb->cbl_offset);
  626. writeb(CUC_START, &p->scb->cmd_cuc);
  627. ni_attn586();
  628. wait_for_stat_compl(mc_cmd);
  629. if ((readw(&mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK))
  630. != (STAT_COMPL|STAT_OK))
  631. printk(KERN_ERR "%s: Can't apply multicast-address-list.\n", dev->name);
  632. }
  633. /*
  634. * alloc nop/xmit-cmds
  635. */
  636. #if (NUM_XMIT_BUFFS == 1)
  637. for (i = 0; i < 2; i++) {
  638. p->nop_cmds[i] = ptr;
  639. writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd);
  640. writew(0, &p->nop_cmds[i]->cmd_status);
  641. writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link);
  642. ptr = ptr + sizeof(struct nop_cmd_struct);
  643. }
  644. #else
  645. for (i = 0; i < NUM_XMIT_BUFFS; i++) {
  646. p->nop_cmds[i] = ptr;
  647. writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd);
  648. writew(0, &p->nop_cmds[i]->cmd_status);
  649. writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link);
  650. ptr = ptr + sizeof(struct nop_cmd_struct);
  651. }
  652. #endif
  653. ptr = alloc_rfa(dev, ptr); /* init receive-frame-area */
  654. /*
  655. * alloc xmit-buffs / init xmit_cmds
  656. */
  657. for (i = 0; i < NUM_XMIT_BUFFS; i++) {
  658. /* Transmit cmd/buff 0 */
  659. p->xmit_cmds[i] = ptr;
  660. ptr = ptr + sizeof(struct transmit_cmd_struct);
  661. p->xmit_cbuffs[i] = ptr; /* char-buffs */
  662. ptr = ptr + XMIT_BUFF_SIZE;
  663. p->xmit_buffs[i] = ptr; /* TBD */
  664. ptr = ptr + sizeof(struct tbd_struct);
  665. if ((void __iomem *)ptr > (void __iomem *)p->iscp) {
  666. printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n",
  667. dev->name);
  668. return 1;
  669. }
  670. memset_io(p->xmit_cmds[i], 0,
  671. sizeof(struct transmit_cmd_struct));
  672. memset_io(p->xmit_buffs[i], 0,
  673. sizeof(struct tbd_struct));
  674. writew(make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]),
  675. &p->xmit_cmds[i]->cmd_link);
  676. writew(STAT_COMPL, &p->xmit_cmds[i]->cmd_status);
  677. writew(CMD_XMIT|CMD_INT, &p->xmit_cmds[i]->cmd_cmd);
  678. writew(make16(p->xmit_buffs[i]), &p->xmit_cmds[i]->tbd_offset);
  679. writew(0xffff, &p->xmit_buffs[i]->next);
  680. writel(make24(p->xmit_cbuffs[i]), &p->xmit_buffs[i]->buffer);
  681. }
  682. p->xmit_count = 0;
  683. p->xmit_last = 0;
  684. #ifndef NO_NOPCOMMANDS
  685. p->nop_point = 0;
  686. #endif
  687. /*
  688. * 'start transmitter'
  689. */
  690. #ifndef NO_NOPCOMMANDS
  691. writew(make16(p->nop_cmds[0]), &p->scb->cbl_offset);
  692. writeb(CUC_START, &p->scb->cmd_cuc);
  693. ni_attn586();
  694. wait_for_scb_cmd(dev);
  695. #else
  696. writew(make16(p->xmit_cmds[0]), &p->xmit_cmds[0]->cmd_link);
  697. writew(CMD_XMIT | CMD_SUSPEND | CMD_INT, &p->xmit_cmds[0]->cmd_cmd);
  698. #endif
  699. /*
  700. * ack. interrupts
  701. */
  702. writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc);
  703. ni_attn586();
  704. udelay(16);
  705. ni_enaint();
  706. return 0;
  707. }
  708. /******************************************************
  709. * This is a helper routine for ni52_rnr_int() and init586().
  710. * It sets up the Receive Frame Area (RFA).
  711. */
  712. static void __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr)
  713. {
  714. struct rfd_struct __iomem *rfd = ptr;
  715. struct rbd_struct __iomem *rbd;
  716. int i;
  717. struct priv *p = (struct priv *) dev->priv;
  718. memset_io(rfd, 0,
  719. sizeof(struct rfd_struct) * (p->num_recv_buffs + rfdadd));
  720. p->rfd_first = rfd;
  721. for (i = 0; i < (p->num_recv_buffs + rfdadd); i++) {
  722. writew(make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd)),
  723. &rfd[i].next);
  724. writew(0xffff, &rfd[i].rbd_offset);
  725. }
  726. /* RU suspend */
  727. writeb(RFD_SUSP, &rfd[p->num_recv_buffs-1+rfdadd].last);
  728. ptr = rfd + (p->num_recv_buffs + rfdadd);
  729. rbd = ptr;
  730. ptr = rbd + p->num_recv_buffs;
  731. /* clr descriptors */
  732. memset_io(rbd, 0, sizeof(struct rbd_struct) * (p->num_recv_buffs));
  733. for (i = 0; i < p->num_recv_buffs; i++) {
  734. writew(make16(rbd + (i+1) % p->num_recv_buffs), &rbd[i].next);
  735. writew(RECV_BUFF_SIZE, &rbd[i].size);
  736. writel(make24(ptr), &rbd[i].buffer);
  737. ptr = ptr + RECV_BUFF_SIZE;
  738. }
  739. p->rfd_top = p->rfd_first;
  740. p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd);
  741. writew(make16(p->rfd_first), &p->scb->rfa_offset);
  742. writew(make16(rbd), &p->rfd_first->rbd_offset);
  743. return ptr;
  744. }
  745. /**************************************************
  746. * Interrupt Handler ...
  747. */
  748. static irqreturn_t ni52_interrupt(int irq, void *dev_id)
  749. {
  750. struct net_device *dev = dev_id;
  751. unsigned int stat;
  752. int cnt = 0;
  753. struct priv *p;
  754. p = (struct priv *) dev->priv;
  755. if (debuglevel > 1)
  756. printk("I");
  757. spin_lock(&p->spinlock);
  758. wait_for_scb_cmd(dev); /* wait for last command */
  759. while ((stat = readb(&p->scb->cus) & STAT_MASK)) {
  760. writeb(stat, &p->scb->cmd_cuc);
  761. ni_attn586();
  762. if (stat & STAT_FR) /* received a frame */
  763. ni52_rcv_int(dev);
  764. if (stat & STAT_RNR) { /* RU went 'not ready' */
  765. printk("(R)");
  766. if (readb(&p->scb->rus) & RU_SUSPEND) {
  767. /* special case: RU_SUSPEND */
  768. wait_for_scb_cmd(dev);
  769. p->scb->cmd_ruc = RUC_RESUME;
  770. ni_attn586();
  771. wait_for_scb_cmd_ruc(dev);
  772. } else {
  773. printk(KERN_ERR "%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",
  774. dev->name, stat, readb(&p->scb->rus));
  775. ni52_rnr_int(dev);
  776. }
  777. }
  778. /* Command with I-bit set complete */
  779. if (stat & STAT_CX)
  780. ni52_xmt_int(dev);
  781. #ifndef NO_NOPCOMMANDS
  782. if (stat & STAT_CNA) { /* CU went 'not ready' */
  783. if (netif_running(dev))
  784. printk(KERN_ERR "%s: oops! CU has left active state. stat: %04x/%02x.\n",
  785. dev->name, stat, readb(&p->scb->cus));
  786. }
  787. #endif
  788. if (debuglevel > 1)
  789. printk("%d", cnt++);
  790. /* Wait for ack. (ni52_xmt_int can be faster than ack!!) */
  791. wait_for_scb_cmd(dev);
  792. if (p->scb->cmd_cuc) { /* timed out? */
  793. printk(KERN_ERR "%s: Acknowledge timed out.\n",
  794. dev->name);
  795. ni_disint();
  796. break;
  797. }
  798. }
  799. spin_unlock(&p->spinlock);
  800. if (debuglevel > 1)
  801. printk("i");
  802. return IRQ_HANDLED;
  803. }
  804. /*******************************************************
  805. * receive-interrupt
  806. */
  807. static void ni52_rcv_int(struct net_device *dev)
  808. {
  809. int status, cnt = 0;
  810. unsigned short totlen;
  811. struct sk_buff *skb;
  812. struct rbd_struct __iomem *rbd;
  813. struct priv *p = (struct priv *)dev->priv;
  814. if (debuglevel > 0)
  815. printk("R");
  816. for (; (status = readb(&p->rfd_top->stat_high)) & RFD_COMPL;) {
  817. rbd = (struct rbd_struct __iomem *) make32(p->rfd_top->rbd_offset);
  818. if (status & RFD_OK) { /* frame received without error? */
  819. totlen = readw(&rbd->status);
  820. if (totlen & RBD_LAST) {
  821. /* the first and the last buffer? */
  822. totlen &= RBD_MASK; /* length of this frame */
  823. writew(0x00, &rbd->status);
  824. skb = (struct sk_buff *)dev_alloc_skb(totlen+2);
  825. if (skb != NULL) {
  826. skb_reserve(skb, 2);
  827. skb_put(skb, totlen);
  828. skb_copy_to_linear_data(skb, p->base + (unsigned long) rbd->buffer, totlen);
  829. skb->protocol = eth_type_trans(skb, dev);
  830. netif_rx(skb);
  831. dev->last_rx = jiffies;
  832. p->stats.rx_packets++;
  833. p->stats.rx_bytes += totlen;
  834. } else
  835. p->stats.rx_dropped++;
  836. } else {
  837. int rstat;
  838. /* free all RBD's until RBD_LAST is set */
  839. totlen = 0;
  840. while (!((rstat = readw(&rbd->status)) & RBD_LAST)) {
  841. totlen += rstat & RBD_MASK;
  842. if (!rstat) {
  843. printk(KERN_ERR "%s: Whoops .. no end mark in RBD list\n", dev->name);
  844. break;
  845. }
  846. writew(0, &rbd->status);
  847. rbd = (struct rbd_struct __iomem *) make32(readl(&rbd->next));
  848. }
  849. totlen += rstat & RBD_MASK;
  850. writew(0, &rbd->status);
  851. printk(KERN_ERR "%s: received oversized frame! length: %d\n",
  852. dev->name, totlen);
  853. p->stats.rx_dropped++;
  854. }
  855. } else {/* frame !(ok), only with 'save-bad-frames' */
  856. printk(KERN_ERR "%s: oops! rfd-error-status: %04x\n",
  857. dev->name, status);
  858. p->stats.rx_errors++;
  859. }
  860. writeb(0, &p->rfd_top->stat_high);
  861. writeb(RFD_SUSP, &p->rfd_top->last); /* maybe exchange by RFD_LAST */
  862. writew(0xffff, &p->rfd_top->rbd_offset);
  863. writeb(0, &p->rfd_last->last); /* delete RFD_SUSP */
  864. p->rfd_last = p->rfd_top;
  865. p->rfd_top = (struct rfd_struct __iomem *) make32(p->rfd_top->next); /* step to next RFD */
  866. writew(make16(p->rfd_top), &p->scb->rfa_offset);
  867. if (debuglevel > 0)
  868. printk("%d", cnt++);
  869. }
  870. if (automatic_resume) {
  871. wait_for_scb_cmd(dev);
  872. writeb(RUC_RESUME, &p->scb->cmd_ruc);
  873. ni_attn586();
  874. wait_for_scb_cmd_ruc(dev);
  875. }
  876. #ifdef WAIT_4_BUSY
  877. {
  878. int i;
  879. for (i = 0; i < 1024; i++) {
  880. if (p->rfd_top->status)
  881. break;
  882. udelay(16);
  883. if (i == 1023)
  884. printk(KERN_ERR "%s: RU hasn't fetched next RFD (not busy/complete)\n", dev->name);
  885. }
  886. }
  887. #endif
  888. if (debuglevel > 0)
  889. printk("r");
  890. }
  891. /**********************************************************
  892. * handle 'Receiver went not ready'.
  893. */
  894. static void ni52_rnr_int(struct net_device *dev)
  895. {
  896. struct priv *p = (struct priv *) dev->priv;
  897. p->stats.rx_errors++;
  898. wait_for_scb_cmd(dev); /* wait for the last cmd, WAIT_4_FULLSTAT?? */
  899. writeb(RUC_ABORT, &p->scb->cmd_ruc); /* usually the RU is in the 'no resource'-state .. abort it now. */
  900. ni_attn586();
  901. wait_for_scb_cmd_ruc(dev); /* wait for accept cmd. */
  902. alloc_rfa(dev, p->rfd_first);
  903. /* maybe add a check here, before restarting the RU */
  904. startrecv586(dev); /* restart RU */
  905. printk(KERN_ERR "%s: Receive-Unit restarted. Status: %04x\n", dev->name, p->scb->rus);
  906. }
  907. /**********************************************************
  908. * handle xmit - interrupt
  909. */
  910. static void ni52_xmt_int(struct net_device *dev)
  911. {
  912. int status;
  913. struct priv *p = (struct priv *) dev->priv;
  914. if (debuglevel > 0)
  915. printk("X");
  916. status = readw(&p->xmit_cmds[p->xmit_last]->cmd_status);
  917. if (!(status & STAT_COMPL))
  918. printk(KERN_ERR "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name);
  919. if (status & STAT_OK) {
  920. p->stats.tx_packets++;
  921. p->stats.collisions += (status & TCMD_MAXCOLLMASK);
  922. } else {
  923. p->stats.tx_errors++;
  924. if (status & TCMD_LATECOLL) {
  925. printk(KERN_ERR "%s: late collision detected.\n",
  926. dev->name);
  927. p->stats.collisions++;
  928. } else if (status & TCMD_NOCARRIER) {
  929. p->stats.tx_carrier_errors++;
  930. printk(KERN_ERR "%s: no carrier detected.\n",
  931. dev->name);
  932. } else if (status & TCMD_LOSTCTS)
  933. printk(KERN_ERR "%s: loss of CTS detected.\n",
  934. dev->name);
  935. else if (status & TCMD_UNDERRUN) {
  936. p->stats.tx_fifo_errors++;
  937. printk(KERN_ERR "%s: DMA underrun detected.\n",
  938. dev->name);
  939. } else if (status & TCMD_MAXCOLL) {
  940. printk(KERN_ERR "%s: Max. collisions exceeded.\n",
  941. dev->name);
  942. p->stats.collisions += 16;
  943. }
  944. }
  945. #if (NUM_XMIT_BUFFS > 1)
  946. if ((++p->xmit_last) == NUM_XMIT_BUFFS)
  947. p->xmit_last = 0;
  948. #endif
  949. netif_wake_queue(dev);
  950. }
  951. /***********************************************************
  952. * (re)start the receiver
  953. */
  954. static void startrecv586(struct net_device *dev)
  955. {
  956. struct priv *p = (struct priv *) dev->priv;
  957. wait_for_scb_cmd(dev);
  958. wait_for_scb_cmd_ruc(dev);
  959. writew(make16(p->rfd_first), &p->scb->rfa_offset);
  960. writeb(RUC_START, &p->scb->cmd_ruc);
  961. ni_attn586(); /* start cmd. */
  962. wait_for_scb_cmd_ruc(dev);
  963. /* wait for accept cmd. (no timeout!!) */
  964. }
  965. static void ni52_timeout(struct net_device *dev)
  966. {
  967. struct priv *p = (struct priv *) dev->priv;
  968. #ifndef NO_NOPCOMMANDS
  969. if (readb(&p->scb->cus) & CU_ACTIVE) { /* COMMAND-UNIT active? */
  970. netif_wake_queue(dev);
  971. #ifdef DEBUG
  972. printk(KERN_ERR "%s: strange ... timeout with CU active?!?\n",
  973. dev->name);
  974. printk(KERN_ERR "%s: X0: %04x N0: %04x N1: %04x %d\n",
  975. dev->name, (int)p->xmit_cmds[0]->cmd_status,
  976. readw(&p->nop_cmds[0]->cmd_status),
  977. readw(&p->nop_cmds[1]->cmd_status),
  978. p->nop_point);
  979. #endif
  980. writeb(CUC_ABORT, &p->scb->cmd_cuc);
  981. ni_attn586();
  982. wait_for_scb_cmd(dev);
  983. writew(make16(p->nop_cmds[p->nop_point]), &p->scb->cbl_offset);
  984. writeb(CUC_START, &p->scb->cmd_cuc);
  985. ni_attn586();
  986. wait_for_scb_cmd(dev);
  987. dev->trans_start = jiffies;
  988. return 0;
  989. }
  990. #endif
  991. {
  992. #ifdef DEBUG
  993. printk(KERN_ERR "%s: xmitter timed out, try to restart! stat: %02x\n",
  994. dev->name, readb(&p->scb->cus));
  995. printk(KERN_ERR "%s: command-stats: %04x %04x\n",
  996. dev->name,
  997. readw(&p->xmit_cmds[0]->cmd_status),
  998. readw(&p->xmit_cmds[1]->cmd_status));
  999. printk(KERN_ERR "%s: check, whether you set the right interrupt number!\n",
  1000. dev->name);
  1001. #endif
  1002. ni52_close(dev);
  1003. ni52_open(dev);
  1004. }
  1005. dev->trans_start = jiffies;
  1006. }
  1007. /******************************************************
  1008. * send frame
  1009. */
  1010. static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev)
  1011. {
  1012. int len, i;
  1013. #ifndef NO_NOPCOMMANDS
  1014. int next_nop;
  1015. #endif
  1016. struct priv *p = (struct priv *) dev->priv;
  1017. if (skb->len > XMIT_BUFF_SIZE) {
  1018. 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);
  1019. return 0;
  1020. }
  1021. netif_stop_queue(dev);
  1022. skb_copy_from_linear_data(skb, (char *)p->xmit_cbuffs[p->xmit_count],
  1023. skb->len);
  1024. len = skb->len;
  1025. if (len < ETH_ZLEN) {
  1026. len = ETH_ZLEN;
  1027. memset((char *)p->xmit_cbuffs[p->xmit_count]+skb->len, 0,
  1028. len - skb->len);
  1029. }
  1030. #if (NUM_XMIT_BUFFS == 1)
  1031. # ifdef NO_NOPCOMMANDS
  1032. #ifdef DEBUG
  1033. if (p->scb->cus & CU_ACTIVE) {
  1034. printk(KERN_ERR "%s: Hmmm .. CU is still running and we wanna send a new packet.\n", dev->name);
  1035. printk(KERN_ERR "%s: stat: %04x %04x\n",
  1036. dev->name, readb(&p->scb->cus),
  1037. readw(&p->xmit_cmds[0]->cmd_status));
  1038. }
  1039. #endif
  1040. writew(TBD_LAST | len, &p->xmit_buffs[0]->size);;
  1041. for (i = 0; i < 16; i++) {
  1042. writew(0, &p->xmit_cmds[0]->cmd_status);
  1043. wait_for_scb_cmd(dev);
  1044. if ((readb(&p->scb->cus) & CU_STATUS) == CU_SUSPEND)
  1045. writeb(CUC_RESUME, &p->scb->cmd_cuc);
  1046. else {
  1047. writew(make16(p->xmit_cmds[0]), &p->scb->cbl_offset);
  1048. writeb(CUC_START, &p->scb->cmd_cuc);
  1049. }
  1050. ni_attn586();
  1051. dev->trans_start = jiffies;
  1052. if (!i)
  1053. dev_kfree_skb(skb);
  1054. wait_for_scb_cmd(dev);
  1055. /* test it, because CU sometimes doesn't start immediately */
  1056. if (readb(&p->scb->cus) & CU_ACTIVE)
  1057. break;
  1058. if (readw(&p->xmit_cmds[0]->cmd_status))
  1059. break;
  1060. if (i == 15)
  1061. printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name);
  1062. }
  1063. # else
  1064. next_nop = (p->nop_point + 1) & 0x1;
  1065. writew(TBD_LAST | len, &p->xmit_buffs[0]->size);
  1066. writew(make16(p->nop_cmds[next_nop]), &p->xmit_cmds[0]->cmd_link);
  1067. writew(make16(p->nop_cmds[next_nop]),
  1068. &p->nop_cmds[next_nop]->cmd_link);
  1069. writew(0, &p->xmit_cmds[0]->cmd_status);
  1070. writew(0, &p->nop_cmds[next_nop]->cmd_status);
  1071. writew(make16(p->xmit_cmds[0]), &p->nop_cmds[p->nop_point]->cmd_link);
  1072. dev->trans_start = jiffies;
  1073. p->nop_point = next_nop;
  1074. dev_kfree_skb(skb);
  1075. # endif
  1076. #else
  1077. writew(TBD_LAST | len, &p->xmit_buffs[p->xmit_count]->size);
  1078. next_nop = p->xmit_count + 1
  1079. if (next_nop == NUM_XMIT_BUFFS)
  1080. next_nop = 0;
  1081. writew(0, &p->xmit_cmds[p->xmit_count]->cmd_status);
  1082. /* linkpointer of xmit-command already points to next nop cmd */
  1083. writew(make16(p->nop_cmds[next_nop]),
  1084. &p->nop_cmds[next_nop]->cmd_link);
  1085. writew(0, &p->nop_cmds[next_nop]->cmd_status);
  1086. writew(make16(p->xmit_cmds[p->xmit_count]),
  1087. &p->nop_cmds[p->xmit_count]->cmd_link);
  1088. dev->trans_start = jiffies;
  1089. p->xmit_count = next_nop;
  1090. {
  1091. unsigned long flags;
  1092. spin_lock_irqsave(&p->spinlock);
  1093. if (p->xmit_count != p->xmit_last)
  1094. netif_wake_queue(dev);
  1095. spin_unlock_irqrestore(&p->spinlock);
  1096. }
  1097. dev_kfree_skb(skb);
  1098. #endif
  1099. return 0;
  1100. }
  1101. /*******************************************
  1102. * Someone wanna have the statistics
  1103. */
  1104. static struct net_device_stats *ni52_get_stats(struct net_device *dev)
  1105. {
  1106. struct priv *p = (struct priv *) dev->priv;
  1107. unsigned short crc, aln, rsc, ovrn;
  1108. /* Get error-statistics from the ni82586 */
  1109. crc = readw(&p->scb->crc_errs);
  1110. writew(0, &p->scb->crc_errs);
  1111. aln = readw(&p->scb->aln_errs);
  1112. writew(0, &p->scb->aln_errs);
  1113. rsc = readw(&p->scb->rsc_errs);
  1114. writew(0, &p->scb->rsc_errs);
  1115. ovrn = readw(&p->scb->ovrn_errs);
  1116. writew(0, &p->scb->ovrn_errs);
  1117. p->stats.rx_crc_errors += crc;
  1118. p->stats.rx_fifo_errors += ovrn;
  1119. p->stats.rx_frame_errors += aln;
  1120. p->stats.rx_dropped += rsc;
  1121. return &p->stats;
  1122. }
  1123. /********************************************************
  1124. * Set MC list ..
  1125. */
  1126. static void set_multicast_list(struct net_device *dev)
  1127. {
  1128. netif_stop_queue(dev);
  1129. ni_disint();
  1130. alloc586(dev);
  1131. init586(dev);
  1132. startrecv586(dev);
  1133. ni_enaint();
  1134. netif_wake_queue(dev);
  1135. }
  1136. #ifdef MODULE
  1137. static struct net_device *dev_ni52;
  1138. module_param(io, int, 0);
  1139. module_param(irq, int, 0);
  1140. module_param(memstart, long, 0);
  1141. module_param(memend, long, 0);
  1142. MODULE_PARM_DESC(io, "NI5210 I/O base address,required");
  1143. MODULE_PARM_DESC(irq, "NI5210 IRQ number,required");
  1144. MODULE_PARM_DESC(memstart, "NI5210 memory base address,required");
  1145. MODULE_PARM_DESC(memend, "NI5210 memory end address,required");
  1146. int __init init_module(void)
  1147. {
  1148. if (io <= 0x0 || !memend || !memstart || irq < 2) {
  1149. printk(KERN_ERR "ni52: Autoprobing not allowed for modules.\n");
  1150. printk(KERN_ERR "ni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
  1151. return -ENODEV;
  1152. }
  1153. dev_ni52 = ni52_probe(-1);
  1154. if (IS_ERR(dev_ni52))
  1155. return PTR_ERR(dev_ni52);
  1156. return 0;
  1157. }
  1158. void __exit cleanup_module(void)
  1159. {
  1160. unregister_netdev(dev_ni52);
  1161. release_region(dev_ni52->base_addr, NI52_TOTAL_SIZE);
  1162. free_netdev(dev_ni52);
  1163. }
  1164. #endif /* MODULE */
  1165. MODULE_LICENSE("GPL");
  1166. /*
  1167. * END: linux/drivers/net/ni52.c
  1168. */