ni52.c 37 KB

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