ni52.c 37 KB

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