ni52.c 37 KB

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