declance.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  1. /*
  2. * Lance ethernet driver for the MIPS processor based
  3. * DECstation family
  4. *
  5. *
  6. * adopted from sunlance.c by Richard van den Berg
  7. *
  8. * Copyright (C) 2002, 2003 Maciej W. Rozycki
  9. *
  10. * additional sources:
  11. * - PMAD-AA TURBOchannel Ethernet Module Functional Specification,
  12. * Revision 1.2
  13. *
  14. * History:
  15. *
  16. * v0.001: The kernel accepts the code and it shows the hardware address.
  17. *
  18. * v0.002: Removed most sparc stuff, left only some module and dma stuff.
  19. *
  20. * v0.003: Enhanced base address calculation from proposals by
  21. * Harald Koerfgen and Thomas Riemer.
  22. *
  23. * v0.004: lance-regs is pointing at the right addresses, added prom
  24. * check. First start of address mapping and DMA.
  25. *
  26. * v0.005: started to play around with LANCE-DMA. This driver will not
  27. * work for non IOASIC lances. HK
  28. *
  29. * v0.006: added pointer arrays to lance_private and setup routine for
  30. * them in dec_lance_init. HK
  31. *
  32. * v0.007: Big shit. The LANCE seems to use a different DMA mechanism to
  33. * access the init block. This looks like one (short) word at a
  34. * time, but the smallest amount the IOASIC can transfer is a
  35. * (long) word. So we have a 2-2 padding here. Changed
  36. * lance_init_block accordingly. The 16-16 padding for the buffers
  37. * seems to be correct. HK
  38. *
  39. * v0.008: mods to make PMAX_LANCE work. 01/09/1999 triemer
  40. *
  41. * v0.009: Module support fixes, multiple interfaces support, various
  42. * bits. macro
  43. */
  44. #include <linux/config.h>
  45. #include <linux/crc32.h>
  46. #include <linux/delay.h>
  47. #include <linux/errno.h>
  48. #include <linux/if_ether.h>
  49. #include <linux/init.h>
  50. #include <linux/kernel.h>
  51. #include <linux/module.h>
  52. #include <linux/netdevice.h>
  53. #include <linux/etherdevice.h>
  54. #include <linux/spinlock.h>
  55. #include <linux/stddef.h>
  56. #include <linux/string.h>
  57. #include <asm/addrspace.h>
  58. #include <asm/dec/interrupts.h>
  59. #include <asm/dec/ioasic.h>
  60. #include <asm/dec/ioasic_addrs.h>
  61. #include <asm/dec/kn01.h>
  62. #include <asm/dec/machtype.h>
  63. #include <asm/dec/tc.h>
  64. #include <asm/system.h>
  65. static char version[] __devinitdata =
  66. "declance.c: v0.009 by Linux MIPS DECstation task force\n";
  67. MODULE_AUTHOR("Linux MIPS DECstation task force");
  68. MODULE_DESCRIPTION("DEC LANCE (DECstation onboard, PMAD-xx) driver");
  69. MODULE_LICENSE("GPL");
  70. /*
  71. * card types
  72. */
  73. #define ASIC_LANCE 1
  74. #define PMAD_LANCE 2
  75. #define PMAX_LANCE 3
  76. #ifndef CONFIG_TC
  77. unsigned long system_base;
  78. unsigned long dmaptr;
  79. #endif
  80. #define LE_CSR0 0
  81. #define LE_CSR1 1
  82. #define LE_CSR2 2
  83. #define LE_CSR3 3
  84. #define LE_MO_PROM 0x8000 /* Enable promiscuous mode */
  85. #define LE_C0_ERR 0x8000 /* Error: set if BAB, SQE, MISS or ME is set */
  86. #define LE_C0_BABL 0x4000 /* BAB: Babble: tx timeout. */
  87. #define LE_C0_CERR 0x2000 /* SQE: Signal quality error */
  88. #define LE_C0_MISS 0x1000 /* MISS: Missed a packet */
  89. #define LE_C0_MERR 0x0800 /* ME: Memory error */
  90. #define LE_C0_RINT 0x0400 /* Received interrupt */
  91. #define LE_C0_TINT 0x0200 /* Transmitter Interrupt */
  92. #define LE_C0_IDON 0x0100 /* IFIN: Init finished. */
  93. #define LE_C0_INTR 0x0080 /* Interrupt or error */
  94. #define LE_C0_INEA 0x0040 /* Interrupt enable */
  95. #define LE_C0_RXON 0x0020 /* Receiver on */
  96. #define LE_C0_TXON 0x0010 /* Transmitter on */
  97. #define LE_C0_TDMD 0x0008 /* Transmitter demand */
  98. #define LE_C0_STOP 0x0004 /* Stop the card */
  99. #define LE_C0_STRT 0x0002 /* Start the card */
  100. #define LE_C0_INIT 0x0001 /* Init the card */
  101. #define LE_C3_BSWP 0x4 /* SWAP */
  102. #define LE_C3_ACON 0x2 /* ALE Control */
  103. #define LE_C3_BCON 0x1 /* Byte control */
  104. /* Receive message descriptor 1 */
  105. #define LE_R1_OWN 0x80 /* Who owns the entry */
  106. #define LE_R1_ERR 0x40 /* Error: if FRA, OFL, CRC or BUF is set */
  107. #define LE_R1_FRA 0x20 /* FRA: Frame error */
  108. #define LE_R1_OFL 0x10 /* OFL: Frame overflow */
  109. #define LE_R1_CRC 0x08 /* CRC error */
  110. #define LE_R1_BUF 0x04 /* BUF: Buffer error */
  111. #define LE_R1_SOP 0x02 /* Start of packet */
  112. #define LE_R1_EOP 0x01 /* End of packet */
  113. #define LE_R1_POK 0x03 /* Packet is complete: SOP + EOP */
  114. #define LE_T1_OWN 0x80 /* Lance owns the packet */
  115. #define LE_T1_ERR 0x40 /* Error summary */
  116. #define LE_T1_EMORE 0x10 /* Error: more than one retry needed */
  117. #define LE_T1_EONE 0x08 /* Error: one retry needed */
  118. #define LE_T1_EDEF 0x04 /* Error: deferred */
  119. #define LE_T1_SOP 0x02 /* Start of packet */
  120. #define LE_T1_EOP 0x01 /* End of packet */
  121. #define LE_T1_POK 0x03 /* Packet is complete: SOP + EOP */
  122. #define LE_T3_BUF 0x8000 /* Buffer error */
  123. #define LE_T3_UFL 0x4000 /* Error underflow */
  124. #define LE_T3_LCOL 0x1000 /* Error late collision */
  125. #define LE_T3_CLOS 0x0800 /* Error carrier loss */
  126. #define LE_T3_RTY 0x0400 /* Error retry */
  127. #define LE_T3_TDR 0x03ff /* Time Domain Reflectometry counter */
  128. /* Define: 2^4 Tx buffers and 2^4 Rx buffers */
  129. #ifndef LANCE_LOG_TX_BUFFERS
  130. #define LANCE_LOG_TX_BUFFERS 4
  131. #define LANCE_LOG_RX_BUFFERS 4
  132. #endif
  133. #define TX_RING_SIZE (1 << (LANCE_LOG_TX_BUFFERS))
  134. #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
  135. #define RX_RING_SIZE (1 << (LANCE_LOG_RX_BUFFERS))
  136. #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
  137. #define PKT_BUF_SZ 1536
  138. #define RX_BUFF_SIZE PKT_BUF_SZ
  139. #define TX_BUFF_SIZE PKT_BUF_SZ
  140. #undef TEST_HITS
  141. #define ZERO 0
  142. /* The DS2000/3000 have a linear 64 KB buffer.
  143. * The PMAD-AA has 128 kb buffer on-board.
  144. *
  145. * The IOASIC LANCE devices use a shared memory region. This region as seen
  146. * from the CPU is (max) 128 KB long and has to be on an 128 KB boundary.
  147. * The LANCE sees this as a 64 KB long continuous memory region.
  148. *
  149. * The LANCE's DMA address is used as an index in this buffer and DMA takes
  150. * place in bursts of eight 16-Bit words which are packed into four 32-Bit words
  151. * by the IOASIC. This leads to a strange padding: 16 bytes of valid data followed
  152. * by a 16 byte gap :-(.
  153. */
  154. struct lance_rx_desc {
  155. unsigned short rmd0; /* low address of packet */
  156. short gap0;
  157. unsigned char rmd1_hadr; /* high address of packet */
  158. unsigned char rmd1_bits; /* descriptor bits */
  159. short gap1;
  160. short length; /* 2s complement (negative!)
  161. of buffer length */
  162. short gap2;
  163. unsigned short mblength; /* actual number of bytes received */
  164. short gap3;
  165. };
  166. struct lance_tx_desc {
  167. unsigned short tmd0; /* low address of packet */
  168. short gap0;
  169. unsigned char tmd1_hadr; /* high address of packet */
  170. unsigned char tmd1_bits; /* descriptor bits */
  171. short gap1;
  172. short length; /* 2s complement (negative!)
  173. of buffer length */
  174. short gap2;
  175. unsigned short misc;
  176. short gap3;
  177. };
  178. /* First part of the LANCE initialization block, described in databook. */
  179. struct lance_init_block {
  180. unsigned short mode; /* pre-set mode (reg. 15) */
  181. short gap0;
  182. unsigned char phys_addr[12]; /* physical ethernet address
  183. only 0, 1, 4, 5, 8, 9 are valid
  184. 2, 3, 6, 7, 10, 11 are gaps */
  185. unsigned short filter[8]; /* multicast filter
  186. only 0, 2, 4, 6 are valid
  187. 1, 3, 5, 7 are gaps */
  188. /* Receive and transmit ring base, along with extra bits. */
  189. unsigned short rx_ptr; /* receive descriptor addr */
  190. short gap1;
  191. unsigned short rx_len; /* receive len and high addr */
  192. short gap2;
  193. unsigned short tx_ptr; /* transmit descriptor addr */
  194. short gap3;
  195. unsigned short tx_len; /* transmit len and high addr */
  196. short gap4;
  197. short gap5[8];
  198. /* The buffer descriptors */
  199. struct lance_rx_desc brx_ring[RX_RING_SIZE];
  200. struct lance_tx_desc btx_ring[TX_RING_SIZE];
  201. };
  202. #define BUF_OFFSET_CPU sizeof(struct lance_init_block)
  203. #define BUF_OFFSET_LNC (sizeof(struct lance_init_block)>>1)
  204. #define libdesc_offset(rt, elem) \
  205. ((__u32)(((unsigned long)(&(((struct lance_init_block *)0)->rt[elem])))))
  206. /*
  207. * This works *only* for the ring descriptors
  208. */
  209. #define LANCE_ADDR(x) (PHYSADDR(x) >> 1)
  210. struct lance_private {
  211. struct net_device *next;
  212. int type;
  213. int slot;
  214. int dma_irq;
  215. volatile struct lance_regs *ll;
  216. volatile struct lance_init_block *init_block;
  217. spinlock_t lock;
  218. int rx_new, tx_new;
  219. int rx_old, tx_old;
  220. struct net_device_stats stats;
  221. unsigned short busmaster_regval;
  222. struct timer_list multicast_timer;
  223. /* Pointers to the ring buffers as seen from the CPU */
  224. char *rx_buf_ptr_cpu[RX_RING_SIZE];
  225. char *tx_buf_ptr_cpu[TX_RING_SIZE];
  226. /* Pointers to the ring buffers as seen from the LANCE */
  227. char *rx_buf_ptr_lnc[RX_RING_SIZE];
  228. char *tx_buf_ptr_lnc[TX_RING_SIZE];
  229. };
  230. #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
  231. lp->tx_old+TX_RING_MOD_MASK-lp->tx_new:\
  232. lp->tx_old - lp->tx_new-1)
  233. /* The lance control ports are at an absolute address, machine and tc-slot
  234. * dependent.
  235. * DECstations do only 32-bit access and the LANCE uses 16 bit addresses,
  236. * so we have to give the structure an extra member making rap pointing
  237. * at the right address
  238. */
  239. struct lance_regs {
  240. volatile unsigned short rdp; /* register data port */
  241. unsigned short pad;
  242. volatile unsigned short rap; /* register address port */
  243. };
  244. int dec_lance_debug = 2;
  245. static struct net_device *root_lance_dev;
  246. static inline void writereg(volatile unsigned short *regptr, short value)
  247. {
  248. *regptr = value;
  249. iob();
  250. }
  251. /* Load the CSR registers */
  252. static void load_csrs(struct lance_private *lp)
  253. {
  254. volatile struct lance_regs *ll = lp->ll;
  255. int leptr;
  256. /* The address space as seen from the LANCE
  257. * begins at address 0. HK
  258. */
  259. leptr = 0;
  260. writereg(&ll->rap, LE_CSR1);
  261. writereg(&ll->rdp, (leptr & 0xFFFF));
  262. writereg(&ll->rap, LE_CSR2);
  263. writereg(&ll->rdp, leptr >> 16);
  264. writereg(&ll->rap, LE_CSR3);
  265. writereg(&ll->rdp, lp->busmaster_regval);
  266. /* Point back to csr0 */
  267. writereg(&ll->rap, LE_CSR0);
  268. }
  269. /*
  270. * Our specialized copy routines
  271. *
  272. */
  273. void cp_to_buf(const int type, void *to, const void *from, int len)
  274. {
  275. unsigned short *tp, *fp, clen;
  276. unsigned char *rtp, *rfp;
  277. if (type == PMAX_LANCE) {
  278. clen = len >> 1;
  279. tp = (unsigned short *) to;
  280. fp = (unsigned short *) from;
  281. while (clen--) {
  282. *tp++ = *fp++;
  283. tp++;
  284. }
  285. clen = len & 1;
  286. rtp = (unsigned char *) tp;
  287. rfp = (unsigned char *) fp;
  288. while (clen--) {
  289. *rtp++ = *rfp++;
  290. }
  291. } else {
  292. /*
  293. * copy 16 Byte chunks
  294. */
  295. clen = len >> 4;
  296. tp = (unsigned short *) to;
  297. fp = (unsigned short *) from;
  298. while (clen--) {
  299. *tp++ = *fp++;
  300. *tp++ = *fp++;
  301. *tp++ = *fp++;
  302. *tp++ = *fp++;
  303. *tp++ = *fp++;
  304. *tp++ = *fp++;
  305. *tp++ = *fp++;
  306. *tp++ = *fp++;
  307. tp += 8;
  308. }
  309. /*
  310. * do the rest, if any.
  311. */
  312. clen = len & 15;
  313. rtp = (unsigned char *) tp;
  314. rfp = (unsigned char *) fp;
  315. while (clen--) {
  316. *rtp++ = *rfp++;
  317. }
  318. }
  319. iob();
  320. }
  321. void cp_from_buf(const int type, void *to, const void *from, int len)
  322. {
  323. unsigned short *tp, *fp, clen;
  324. unsigned char *rtp, *rfp;
  325. if (type == PMAX_LANCE) {
  326. clen = len >> 1;
  327. tp = (unsigned short *) to;
  328. fp = (unsigned short *) from;
  329. while (clen--) {
  330. *tp++ = *fp++;
  331. fp++;
  332. }
  333. clen = len & 1;
  334. rtp = (unsigned char *) tp;
  335. rfp = (unsigned char *) fp;
  336. while (clen--) {
  337. *rtp++ = *rfp++;
  338. }
  339. } else {
  340. /*
  341. * copy 16 Byte chunks
  342. */
  343. clen = len >> 4;
  344. tp = (unsigned short *) to;
  345. fp = (unsigned short *) from;
  346. while (clen--) {
  347. *tp++ = *fp++;
  348. *tp++ = *fp++;
  349. *tp++ = *fp++;
  350. *tp++ = *fp++;
  351. *tp++ = *fp++;
  352. *tp++ = *fp++;
  353. *tp++ = *fp++;
  354. *tp++ = *fp++;
  355. fp += 8;
  356. }
  357. /*
  358. * do the rest, if any.
  359. */
  360. clen = len & 15;
  361. rtp = (unsigned char *) tp;
  362. rfp = (unsigned char *) fp;
  363. while (clen--) {
  364. *rtp++ = *rfp++;
  365. }
  366. }
  367. }
  368. /* Setup the Lance Rx and Tx rings */
  369. static void lance_init_ring(struct net_device *dev)
  370. {
  371. struct lance_private *lp = netdev_priv(dev);
  372. volatile struct lance_init_block *ib;
  373. int leptr;
  374. int i;
  375. ib = (struct lance_init_block *) (dev->mem_start);
  376. /* Lock out other processes while setting up hardware */
  377. netif_stop_queue(dev);
  378. lp->rx_new = lp->tx_new = 0;
  379. lp->rx_old = lp->tx_old = 0;
  380. /* Copy the ethernet address to the lance init block.
  381. * XXX bit 0 of the physical address registers has to be zero
  382. */
  383. ib->phys_addr[0] = dev->dev_addr[0];
  384. ib->phys_addr[1] = dev->dev_addr[1];
  385. ib->phys_addr[4] = dev->dev_addr[2];
  386. ib->phys_addr[5] = dev->dev_addr[3];
  387. ib->phys_addr[8] = dev->dev_addr[4];
  388. ib->phys_addr[9] = dev->dev_addr[5];
  389. /* Setup the initialization block */
  390. /* Setup rx descriptor pointer */
  391. leptr = LANCE_ADDR(libdesc_offset(brx_ring, 0));
  392. ib->rx_len = (LANCE_LOG_RX_BUFFERS << 13) | (leptr >> 16);
  393. ib->rx_ptr = leptr;
  394. if (ZERO)
  395. printk("RX ptr: %8.8x(%8.8x)\n", leptr, libdesc_offset(brx_ring, 0));
  396. /* Setup tx descriptor pointer */
  397. leptr = LANCE_ADDR(libdesc_offset(btx_ring, 0));
  398. ib->tx_len = (LANCE_LOG_TX_BUFFERS << 13) | (leptr >> 16);
  399. ib->tx_ptr = leptr;
  400. if (ZERO)
  401. printk("TX ptr: %8.8x(%8.8x)\n", leptr, libdesc_offset(btx_ring, 0));
  402. if (ZERO)
  403. printk("TX rings:\n");
  404. /* Setup the Tx ring entries */
  405. for (i = 0; i < TX_RING_SIZE; i++) {
  406. leptr = (int) lp->tx_buf_ptr_lnc[i];
  407. ib->btx_ring[i].tmd0 = leptr;
  408. ib->btx_ring[i].tmd1_hadr = leptr >> 16;
  409. ib->btx_ring[i].tmd1_bits = 0;
  410. ib->btx_ring[i].length = 0xf000; /* The ones required by tmd2 */
  411. ib->btx_ring[i].misc = 0;
  412. if (i < 3 && ZERO)
  413. printk("%d: 0x%8.8x(0x%8.8x)\n", i, leptr, (int) lp->tx_buf_ptr_cpu[i]);
  414. }
  415. /* Setup the Rx ring entries */
  416. if (ZERO)
  417. printk("RX rings:\n");
  418. for (i = 0; i < RX_RING_SIZE; i++) {
  419. leptr = (int) lp->rx_buf_ptr_lnc[i];
  420. ib->brx_ring[i].rmd0 = leptr;
  421. ib->brx_ring[i].rmd1_hadr = leptr >> 16;
  422. ib->brx_ring[i].rmd1_bits = LE_R1_OWN;
  423. ib->brx_ring[i].length = -RX_BUFF_SIZE | 0xf000;
  424. ib->brx_ring[i].mblength = 0;
  425. if (i < 3 && ZERO)
  426. printk("%d: 0x%8.8x(0x%8.8x)\n", i, leptr, (int) lp->rx_buf_ptr_cpu[i]);
  427. }
  428. iob();
  429. }
  430. static int init_restart_lance(struct lance_private *lp)
  431. {
  432. volatile struct lance_regs *ll = lp->ll;
  433. int i;
  434. writereg(&ll->rap, LE_CSR0);
  435. writereg(&ll->rdp, LE_C0_INIT);
  436. /* Wait for the lance to complete initialization */
  437. for (i = 0; (i < 100) && !(ll->rdp & LE_C0_IDON); i++) {
  438. udelay(10);
  439. }
  440. if ((i == 100) || (ll->rdp & LE_C0_ERR)) {
  441. printk("LANCE unopened after %d ticks, csr0=%4.4x.\n", i, ll->rdp);
  442. return -1;
  443. }
  444. if ((ll->rdp & LE_C0_ERR)) {
  445. printk("LANCE unopened after %d ticks, csr0=%4.4x.\n", i, ll->rdp);
  446. return -1;
  447. }
  448. writereg(&ll->rdp, LE_C0_IDON);
  449. writereg(&ll->rdp, LE_C0_STRT);
  450. writereg(&ll->rdp, LE_C0_INEA);
  451. return 0;
  452. }
  453. static int lance_rx(struct net_device *dev)
  454. {
  455. struct lance_private *lp = netdev_priv(dev);
  456. volatile struct lance_init_block *ib;
  457. volatile struct lance_rx_desc *rd = 0;
  458. unsigned char bits;
  459. int len = 0;
  460. struct sk_buff *skb = 0;
  461. ib = (struct lance_init_block *) (dev->mem_start);
  462. #ifdef TEST_HITS
  463. {
  464. int i;
  465. printk("[");
  466. for (i = 0; i < RX_RING_SIZE; i++) {
  467. if (i == lp->rx_new)
  468. printk("%s", ib->brx_ring[i].rmd1_bits &
  469. LE_R1_OWN ? "_" : "X");
  470. else
  471. printk("%s", ib->brx_ring[i].rmd1_bits &
  472. LE_R1_OWN ? "." : "1");
  473. }
  474. printk("]");
  475. }
  476. #endif
  477. for (rd = &ib->brx_ring[lp->rx_new];
  478. !((bits = rd->rmd1_bits) & LE_R1_OWN);
  479. rd = &ib->brx_ring[lp->rx_new]) {
  480. /* We got an incomplete frame? */
  481. if ((bits & LE_R1_POK) != LE_R1_POK) {
  482. lp->stats.rx_over_errors++;
  483. lp->stats.rx_errors++;
  484. } else if (bits & LE_R1_ERR) {
  485. /* Count only the end frame as a rx error,
  486. * not the beginning
  487. */
  488. if (bits & LE_R1_BUF)
  489. lp->stats.rx_fifo_errors++;
  490. if (bits & LE_R1_CRC)
  491. lp->stats.rx_crc_errors++;
  492. if (bits & LE_R1_OFL)
  493. lp->stats.rx_over_errors++;
  494. if (bits & LE_R1_FRA)
  495. lp->stats.rx_frame_errors++;
  496. if (bits & LE_R1_EOP)
  497. lp->stats.rx_errors++;
  498. } else {
  499. len = (rd->mblength & 0xfff) - 4;
  500. skb = dev_alloc_skb(len + 2);
  501. if (skb == 0) {
  502. printk("%s: Memory squeeze, deferring packet.\n",
  503. dev->name);
  504. lp->stats.rx_dropped++;
  505. rd->mblength = 0;
  506. rd->rmd1_bits = LE_R1_OWN;
  507. lp->rx_new = (lp->rx_new + 1) & RX_RING_MOD_MASK;
  508. return 0;
  509. }
  510. lp->stats.rx_bytes += len;
  511. skb->dev = dev;
  512. skb_reserve(skb, 2); /* 16 byte align */
  513. skb_put(skb, len); /* make room */
  514. cp_from_buf(lp->type, skb->data,
  515. (char *)lp->rx_buf_ptr_cpu[lp->rx_new],
  516. len);
  517. skb->protocol = eth_type_trans(skb, dev);
  518. netif_rx(skb);
  519. dev->last_rx = jiffies;
  520. lp->stats.rx_packets++;
  521. }
  522. /* Return the packet to the pool */
  523. rd->mblength = 0;
  524. rd->length = -RX_BUFF_SIZE | 0xf000;
  525. rd->rmd1_bits = LE_R1_OWN;
  526. lp->rx_new = (lp->rx_new + 1) & RX_RING_MOD_MASK;
  527. }
  528. return 0;
  529. }
  530. static void lance_tx(struct net_device *dev)
  531. {
  532. struct lance_private *lp = netdev_priv(dev);
  533. volatile struct lance_init_block *ib;
  534. volatile struct lance_regs *ll = lp->ll;
  535. volatile struct lance_tx_desc *td;
  536. int i, j;
  537. int status;
  538. ib = (struct lance_init_block *) (dev->mem_start);
  539. j = lp->tx_old;
  540. spin_lock(&lp->lock);
  541. for (i = j; i != lp->tx_new; i = j) {
  542. td = &ib->btx_ring[i];
  543. /* If we hit a packet not owned by us, stop */
  544. if (td->tmd1_bits & LE_T1_OWN)
  545. break;
  546. if (td->tmd1_bits & LE_T1_ERR) {
  547. status = td->misc;
  548. lp->stats.tx_errors++;
  549. if (status & LE_T3_RTY)
  550. lp->stats.tx_aborted_errors++;
  551. if (status & LE_T3_LCOL)
  552. lp->stats.tx_window_errors++;
  553. if (status & LE_T3_CLOS) {
  554. lp->stats.tx_carrier_errors++;
  555. printk("%s: Carrier Lost\n", dev->name);
  556. /* Stop the lance */
  557. writereg(&ll->rap, LE_CSR0);
  558. writereg(&ll->rdp, LE_C0_STOP);
  559. lance_init_ring(dev);
  560. load_csrs(lp);
  561. init_restart_lance(lp);
  562. goto out;
  563. }
  564. /* Buffer errors and underflows turn off the
  565. * transmitter, restart the adapter.
  566. */
  567. if (status & (LE_T3_BUF | LE_T3_UFL)) {
  568. lp->stats.tx_fifo_errors++;
  569. printk("%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
  570. dev->name);
  571. /* Stop the lance */
  572. writereg(&ll->rap, LE_CSR0);
  573. writereg(&ll->rdp, LE_C0_STOP);
  574. lance_init_ring(dev);
  575. load_csrs(lp);
  576. init_restart_lance(lp);
  577. goto out;
  578. }
  579. } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
  580. /*
  581. * So we don't count the packet more than once.
  582. */
  583. td->tmd1_bits &= ~(LE_T1_POK);
  584. /* One collision before packet was sent. */
  585. if (td->tmd1_bits & LE_T1_EONE)
  586. lp->stats.collisions++;
  587. /* More than one collision, be optimistic. */
  588. if (td->tmd1_bits & LE_T1_EMORE)
  589. lp->stats.collisions += 2;
  590. lp->stats.tx_packets++;
  591. }
  592. j = (j + 1) & TX_RING_MOD_MASK;
  593. }
  594. lp->tx_old = j;
  595. out:
  596. if (netif_queue_stopped(dev) &&
  597. TX_BUFFS_AVAIL > 0)
  598. netif_wake_queue(dev);
  599. spin_unlock(&lp->lock);
  600. }
  601. static void lance_dma_merr_int(const int irq, void *dev_id,
  602. struct pt_regs *regs)
  603. {
  604. struct net_device *dev = (struct net_device *) dev_id;
  605. printk("%s: DMA error\n", dev->name);
  606. }
  607. static irqreturn_t
  608. lance_interrupt(const int irq, void *dev_id, struct pt_regs *regs)
  609. {
  610. struct net_device *dev = (struct net_device *) dev_id;
  611. struct lance_private *lp = netdev_priv(dev);
  612. volatile struct lance_regs *ll = lp->ll;
  613. int csr0;
  614. writereg(&ll->rap, LE_CSR0);
  615. csr0 = ll->rdp;
  616. /* Acknowledge all the interrupt sources ASAP */
  617. writereg(&ll->rdp, csr0 & (LE_C0_INTR | LE_C0_TINT | LE_C0_RINT));
  618. if ((csr0 & LE_C0_ERR)) {
  619. /* Clear the error condition */
  620. writereg(&ll->rdp, LE_C0_BABL | LE_C0_ERR | LE_C0_MISS |
  621. LE_C0_CERR | LE_C0_MERR);
  622. }
  623. if (csr0 & LE_C0_RINT)
  624. lance_rx(dev);
  625. if (csr0 & LE_C0_TINT)
  626. lance_tx(dev);
  627. if (csr0 & LE_C0_BABL)
  628. lp->stats.tx_errors++;
  629. if (csr0 & LE_C0_MISS)
  630. lp->stats.rx_errors++;
  631. if (csr0 & LE_C0_MERR) {
  632. printk("%s: Memory error, status %04x\n", dev->name, csr0);
  633. writereg(&ll->rdp, LE_C0_STOP);
  634. lance_init_ring(dev);
  635. load_csrs(lp);
  636. init_restart_lance(lp);
  637. netif_wake_queue(dev);
  638. }
  639. writereg(&ll->rdp, LE_C0_INEA);
  640. writereg(&ll->rdp, LE_C0_INEA);
  641. return IRQ_HANDLED;
  642. }
  643. struct net_device *last_dev = 0;
  644. static int lance_open(struct net_device *dev)
  645. {
  646. volatile struct lance_init_block *ib = (struct lance_init_block *) (dev->mem_start);
  647. struct lance_private *lp = netdev_priv(dev);
  648. volatile struct lance_regs *ll = lp->ll;
  649. int status = 0;
  650. last_dev = dev;
  651. /* Stop the Lance */
  652. writereg(&ll->rap, LE_CSR0);
  653. writereg(&ll->rdp, LE_C0_STOP);
  654. /* Set mode and clear multicast filter only at device open,
  655. * so that lance_init_ring() called at any error will not
  656. * forget multicast filters.
  657. *
  658. * BTW it is common bug in all lance drivers! --ANK
  659. */
  660. ib->mode = 0;
  661. ib->filter [0] = 0;
  662. ib->filter [2] = 0;
  663. ib->filter [4] = 0;
  664. ib->filter [6] = 0;
  665. lance_init_ring(dev);
  666. load_csrs(lp);
  667. netif_start_queue(dev);
  668. /* Associate IRQ with lance_interrupt */
  669. if (request_irq(dev->irq, &lance_interrupt, 0, "lance", dev)) {
  670. printk("%s: Can't get IRQ %d\n", dev->name, dev->irq);
  671. return -EAGAIN;
  672. }
  673. if (lp->dma_irq >= 0) {
  674. unsigned long flags;
  675. if (request_irq(lp->dma_irq, &lance_dma_merr_int, 0,
  676. "lance error", dev)) {
  677. free_irq(dev->irq, dev);
  678. printk("%s: Can't get DMA IRQ %d\n", dev->name,
  679. lp->dma_irq);
  680. return -EAGAIN;
  681. }
  682. spin_lock_irqsave(&ioasic_ssr_lock, flags);
  683. fast_mb();
  684. /* Enable I/O ASIC LANCE DMA. */
  685. ioasic_write(IO_REG_SSR,
  686. ioasic_read(IO_REG_SSR) | IO_SSR_LANCE_DMA_EN);
  687. fast_mb();
  688. spin_unlock_irqrestore(&ioasic_ssr_lock, flags);
  689. }
  690. status = init_restart_lance(lp);
  691. return status;
  692. }
  693. static int lance_close(struct net_device *dev)
  694. {
  695. struct lance_private *lp = netdev_priv(dev);
  696. volatile struct lance_regs *ll = lp->ll;
  697. netif_stop_queue(dev);
  698. del_timer_sync(&lp->multicast_timer);
  699. /* Stop the card */
  700. writereg(&ll->rap, LE_CSR0);
  701. writereg(&ll->rdp, LE_C0_STOP);
  702. if (lp->dma_irq >= 0) {
  703. unsigned long flags;
  704. spin_lock_irqsave(&ioasic_ssr_lock, flags);
  705. fast_mb();
  706. /* Disable I/O ASIC LANCE DMA. */
  707. ioasic_write(IO_REG_SSR,
  708. ioasic_read(IO_REG_SSR) & ~IO_SSR_LANCE_DMA_EN);
  709. fast_iob();
  710. spin_unlock_irqrestore(&ioasic_ssr_lock, flags);
  711. free_irq(lp->dma_irq, dev);
  712. }
  713. free_irq(dev->irq, dev);
  714. return 0;
  715. }
  716. static inline int lance_reset(struct net_device *dev)
  717. {
  718. struct lance_private *lp = netdev_priv(dev);
  719. volatile struct lance_regs *ll = lp->ll;
  720. int status;
  721. /* Stop the lance */
  722. writereg(&ll->rap, LE_CSR0);
  723. writereg(&ll->rdp, LE_C0_STOP);
  724. lance_init_ring(dev);
  725. load_csrs(lp);
  726. dev->trans_start = jiffies;
  727. status = init_restart_lance(lp);
  728. return status;
  729. }
  730. static void lance_tx_timeout(struct net_device *dev)
  731. {
  732. struct lance_private *lp = netdev_priv(dev);
  733. volatile struct lance_regs *ll = lp->ll;
  734. printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n",
  735. dev->name, ll->rdp);
  736. lance_reset(dev);
  737. netif_wake_queue(dev);
  738. }
  739. static int lance_start_xmit(struct sk_buff *skb, struct net_device *dev)
  740. {
  741. struct lance_private *lp = netdev_priv(dev);
  742. volatile struct lance_regs *ll = lp->ll;
  743. volatile struct lance_init_block *ib = (struct lance_init_block *) (dev->mem_start);
  744. int entry, skblen, len;
  745. skblen = skb->len;
  746. len = skblen;
  747. if (len < ETH_ZLEN) {
  748. skb = skb_padto(skb, ETH_ZLEN);
  749. if (skb == NULL)
  750. return 0;
  751. len = ETH_ZLEN;
  752. }
  753. lp->stats.tx_bytes += len;
  754. entry = lp->tx_new & TX_RING_MOD_MASK;
  755. ib->btx_ring[entry].length = (-len);
  756. ib->btx_ring[entry].misc = 0;
  757. cp_to_buf(lp->type, (char *)lp->tx_buf_ptr_cpu[entry], skb->data,
  758. skblen);
  759. /* Clear the slack of the packet, do I need this? */
  760. /* For a firewall it's a good idea - AC */
  761. /*
  762. if (len != skblen)
  763. memset ((char *) &ib->tx_buf [entry][skblen], 0, (len - skblen) << 1);
  764. */
  765. /* Now, give the packet to the lance */
  766. ib->btx_ring[entry].tmd1_bits = (LE_T1_POK | LE_T1_OWN);
  767. lp->tx_new = (lp->tx_new + 1) & TX_RING_MOD_MASK;
  768. if (TX_BUFFS_AVAIL <= 0)
  769. netif_stop_queue(dev);
  770. /* Kick the lance: transmit now */
  771. writereg(&ll->rdp, LE_C0_INEA | LE_C0_TDMD);
  772. spin_unlock_irq(&lp->lock);
  773. dev->trans_start = jiffies;
  774. dev_kfree_skb(skb);
  775. return 0;
  776. }
  777. static struct net_device_stats *lance_get_stats(struct net_device *dev)
  778. {
  779. struct lance_private *lp = netdev_priv(dev);
  780. return &lp->stats;
  781. }
  782. static void lance_load_multicast(struct net_device *dev)
  783. {
  784. volatile struct lance_init_block *ib = (struct lance_init_block *) (dev->mem_start);
  785. volatile u16 *mcast_table = (u16 *) & ib->filter;
  786. struct dev_mc_list *dmi = dev->mc_list;
  787. char *addrs;
  788. int i;
  789. u32 crc;
  790. /* set all multicast bits */
  791. if (dev->flags & IFF_ALLMULTI) {
  792. ib->filter[0] = 0xffff;
  793. ib->filter[2] = 0xffff;
  794. ib->filter[4] = 0xffff;
  795. ib->filter[6] = 0xffff;
  796. return;
  797. }
  798. /* clear the multicast filter */
  799. ib->filter[0] = 0;
  800. ib->filter[2] = 0;
  801. ib->filter[4] = 0;
  802. ib->filter[6] = 0;
  803. /* Add addresses */
  804. for (i = 0; i < dev->mc_count; i++) {
  805. addrs = dmi->dmi_addr;
  806. dmi = dmi->next;
  807. /* multicast address? */
  808. if (!(*addrs & 1))
  809. continue;
  810. crc = ether_crc_le(ETH_ALEN, addrs);
  811. crc = crc >> 26;
  812. mcast_table[2 * (crc >> 4)] |= 1 << (crc & 0xf);
  813. }
  814. return;
  815. }
  816. static void lance_set_multicast(struct net_device *dev)
  817. {
  818. struct lance_private *lp = netdev_priv(dev);
  819. volatile struct lance_init_block *ib;
  820. volatile struct lance_regs *ll = lp->ll;
  821. ib = (struct lance_init_block *) (dev->mem_start);
  822. if (!netif_running(dev))
  823. return;
  824. if (lp->tx_old != lp->tx_new) {
  825. mod_timer(&lp->multicast_timer, jiffies + 4 * HZ/100);
  826. netif_wake_queue(dev);
  827. return;
  828. }
  829. netif_stop_queue(dev);
  830. writereg(&ll->rap, LE_CSR0);
  831. writereg(&ll->rdp, LE_C0_STOP);
  832. lance_init_ring(dev);
  833. if (dev->flags & IFF_PROMISC) {
  834. ib->mode |= LE_MO_PROM;
  835. } else {
  836. ib->mode &= ~LE_MO_PROM;
  837. lance_load_multicast(dev);
  838. }
  839. load_csrs(lp);
  840. init_restart_lance(lp);
  841. netif_wake_queue(dev);
  842. }
  843. static void lance_set_multicast_retry(unsigned long _opaque)
  844. {
  845. struct net_device *dev = (struct net_device *) _opaque;
  846. lance_set_multicast(dev);
  847. }
  848. static int __init dec_lance_init(const int type, const int slot)
  849. {
  850. static unsigned version_printed;
  851. static const char fmt[] = "declance%d";
  852. char name[10];
  853. struct net_device *dev;
  854. struct lance_private *lp;
  855. volatile struct lance_regs *ll;
  856. int i, ret;
  857. unsigned long esar_base;
  858. unsigned char *esar;
  859. #ifndef CONFIG_TC
  860. system_base = KN01_LANCE_BASE;
  861. #endif
  862. if (dec_lance_debug && version_printed++ == 0)
  863. printk(version);
  864. i = 0;
  865. dev = root_lance_dev;
  866. while (dev) {
  867. i++;
  868. lp = (struct lance_private *)dev->priv;
  869. dev = lp->next;
  870. }
  871. snprintf(name, sizeof(name), fmt, i);
  872. dev = alloc_etherdev(sizeof(struct lance_private));
  873. if (!dev) {
  874. printk(KERN_ERR "%s: Unable to allocate etherdev, aborting.\n",
  875. name);
  876. ret = -ENOMEM;
  877. goto err_out;
  878. }
  879. /*
  880. * alloc_etherdev ensures the data structures used by the LANCE
  881. * are aligned.
  882. */
  883. lp = netdev_priv(dev);
  884. spin_lock_init(&lp->lock);
  885. lp->type = type;
  886. lp->slot = slot;
  887. switch (type) {
  888. #ifdef CONFIG_TC
  889. case ASIC_LANCE:
  890. dev->base_addr = system_base + IOASIC_LANCE;
  891. /* buffer space for the on-board LANCE shared memory */
  892. /*
  893. * FIXME: ugly hack!
  894. */
  895. dev->mem_start = KSEG1ADDR(0x00020000);
  896. dev->mem_end = dev->mem_start + 0x00020000;
  897. dev->irq = dec_interrupt[DEC_IRQ_LANCE];
  898. esar_base = system_base + IOASIC_ESAR;
  899. /* Workaround crash with booting KN04 2.1k from Disk */
  900. memset((void *)dev->mem_start, 0,
  901. dev->mem_end - dev->mem_start);
  902. /*
  903. * setup the pointer arrays, this sucks [tm] :-(
  904. */
  905. for (i = 0; i < RX_RING_SIZE; i++) {
  906. lp->rx_buf_ptr_cpu[i] =
  907. (char *)(dev->mem_start + BUF_OFFSET_CPU +
  908. 2 * i * RX_BUFF_SIZE);
  909. lp->rx_buf_ptr_lnc[i] =
  910. (char *)(BUF_OFFSET_LNC + i * RX_BUFF_SIZE);
  911. }
  912. for (i = 0; i < TX_RING_SIZE; i++) {
  913. lp->tx_buf_ptr_cpu[i] =
  914. (char *)(dev->mem_start + BUF_OFFSET_CPU +
  915. 2 * RX_RING_SIZE * RX_BUFF_SIZE +
  916. 2 * i * TX_BUFF_SIZE);
  917. lp->tx_buf_ptr_lnc[i] =
  918. (char *)(BUF_OFFSET_LNC +
  919. RX_RING_SIZE * RX_BUFF_SIZE +
  920. i * TX_BUFF_SIZE);
  921. }
  922. /* Setup I/O ASIC LANCE DMA. */
  923. lp->dma_irq = dec_interrupt[DEC_IRQ_LANCE_MERR];
  924. ioasic_write(IO_REG_LANCE_DMA_P,
  925. PHYSADDR(dev->mem_start) << 3);
  926. break;
  927. case PMAD_LANCE:
  928. claim_tc_card(slot);
  929. dev->mem_start = get_tc_base_addr(slot);
  930. dev->base_addr = dev->mem_start + 0x100000;
  931. dev->irq = get_tc_irq_nr(slot);
  932. esar_base = dev->mem_start + 0x1c0002;
  933. lp->dma_irq = -1;
  934. for (i = 0; i < RX_RING_SIZE; i++) {
  935. lp->rx_buf_ptr_cpu[i] =
  936. (char *)(dev->mem_start + BUF_OFFSET_CPU +
  937. i * RX_BUFF_SIZE);
  938. lp->rx_buf_ptr_lnc[i] =
  939. (char *)(BUF_OFFSET_LNC + i * RX_BUFF_SIZE);
  940. }
  941. for (i = 0; i < TX_RING_SIZE; i++) {
  942. lp->tx_buf_ptr_cpu[i] =
  943. (char *)(dev->mem_start + BUF_OFFSET_CPU +
  944. RX_RING_SIZE * RX_BUFF_SIZE +
  945. i * TX_BUFF_SIZE);
  946. lp->tx_buf_ptr_lnc[i] =
  947. (char *)(BUF_OFFSET_LNC +
  948. RX_RING_SIZE * RX_BUFF_SIZE +
  949. i * TX_BUFF_SIZE);
  950. }
  951. break;
  952. #endif
  953. case PMAX_LANCE:
  954. dev->irq = dec_interrupt[DEC_IRQ_LANCE];
  955. dev->base_addr = KN01_LANCE_BASE;
  956. dev->mem_start = KN01_LANCE_BASE + 0x01000000;
  957. esar_base = KN01_RTC_BASE + 1;
  958. lp->dma_irq = -1;
  959. /*
  960. * setup the pointer arrays, this sucks [tm] :-(
  961. */
  962. for (i = 0; i < RX_RING_SIZE; i++) {
  963. lp->rx_buf_ptr_cpu[i] =
  964. (char *)(dev->mem_start + BUF_OFFSET_CPU +
  965. 2 * i * RX_BUFF_SIZE);
  966. lp->rx_buf_ptr_lnc[i] =
  967. (char *)(BUF_OFFSET_LNC + i * RX_BUFF_SIZE);
  968. }
  969. for (i = 0; i < TX_RING_SIZE; i++) {
  970. lp->tx_buf_ptr_cpu[i] =
  971. (char *)(dev->mem_start + BUF_OFFSET_CPU +
  972. 2 * RX_RING_SIZE * RX_BUFF_SIZE +
  973. 2 * i * TX_BUFF_SIZE);
  974. lp->tx_buf_ptr_lnc[i] =
  975. (char *)(BUF_OFFSET_LNC +
  976. RX_RING_SIZE * RX_BUFF_SIZE +
  977. i * TX_BUFF_SIZE);
  978. }
  979. break;
  980. default:
  981. printk(KERN_ERR "%s: declance_init called with unknown type\n",
  982. name);
  983. ret = -ENODEV;
  984. goto err_out_free_dev;
  985. }
  986. ll = (struct lance_regs *) dev->base_addr;
  987. esar = (unsigned char *) esar_base;
  988. /* prom checks */
  989. /* First, check for test pattern */
  990. if (esar[0x60] != 0xff && esar[0x64] != 0x00 &&
  991. esar[0x68] != 0x55 && esar[0x6c] != 0xaa) {
  992. printk(KERN_ERR
  993. "%s: Ethernet station address prom not found!\n",
  994. name);
  995. ret = -ENODEV;
  996. goto err_out_free_dev;
  997. }
  998. /* Check the prom contents */
  999. for (i = 0; i < 8; i++) {
  1000. if (esar[i * 4] != esar[0x3c - i * 4] &&
  1001. esar[i * 4] != esar[0x40 + i * 4] &&
  1002. esar[0x3c - i * 4] != esar[0x40 + i * 4]) {
  1003. printk(KERN_ERR "%s: Something is wrong with the "
  1004. "ethernet station address prom!\n", name);
  1005. ret = -ENODEV;
  1006. goto err_out_free_dev;
  1007. }
  1008. }
  1009. /* Copy the ethernet address to the device structure, later to the
  1010. * lance initialization block so the lance gets it every time it's
  1011. * (re)initialized.
  1012. */
  1013. switch (type) {
  1014. case ASIC_LANCE:
  1015. printk("%s: IOASIC onboard LANCE, addr = ", name);
  1016. break;
  1017. case PMAD_LANCE:
  1018. printk("%s: PMAD-AA, addr = ", name);
  1019. break;
  1020. case PMAX_LANCE:
  1021. printk("%s: PMAX onboard LANCE, addr = ", name);
  1022. break;
  1023. }
  1024. for (i = 0; i < 6; i++) {
  1025. dev->dev_addr[i] = esar[i * 4];
  1026. printk("%2.2x%c", dev->dev_addr[i], i == 5 ? ',' : ':');
  1027. }
  1028. printk(" irq = %d\n", dev->irq);
  1029. dev->open = &lance_open;
  1030. dev->stop = &lance_close;
  1031. dev->hard_start_xmit = &lance_start_xmit;
  1032. dev->tx_timeout = &lance_tx_timeout;
  1033. dev->watchdog_timeo = 5*HZ;
  1034. dev->get_stats = &lance_get_stats;
  1035. dev->set_multicast_list = &lance_set_multicast;
  1036. /* lp->ll is the location of the registers for lance card */
  1037. lp->ll = ll;
  1038. /* busmaster_regval (CSR3) should be zero according to the PMAD-AA
  1039. * specification.
  1040. */
  1041. lp->busmaster_regval = 0;
  1042. dev->dma = 0;
  1043. /* We cannot sleep if the chip is busy during a
  1044. * multicast list update event, because such events
  1045. * can occur from interrupts (ex. IPv6). So we
  1046. * use a timer to try again later when necessary. -DaveM
  1047. */
  1048. init_timer(&lp->multicast_timer);
  1049. lp->multicast_timer.data = (unsigned long) dev;
  1050. lp->multicast_timer.function = &lance_set_multicast_retry;
  1051. ret = register_netdev(dev);
  1052. if (ret) {
  1053. printk(KERN_ERR
  1054. "%s: Unable to register netdev, aborting.\n", name);
  1055. goto err_out_free_dev;
  1056. }
  1057. lp->next = root_lance_dev;
  1058. root_lance_dev = dev;
  1059. printk("%s: registered as %s.\n", name, dev->name);
  1060. return 0;
  1061. err_out_free_dev:
  1062. kfree(dev);
  1063. err_out:
  1064. return ret;
  1065. }
  1066. /* Find all the lance cards on the system and initialize them */
  1067. static int __init dec_lance_probe(void)
  1068. {
  1069. int count = 0;
  1070. /* Scan slots for PMAD-AA cards first. */
  1071. #ifdef CONFIG_TC
  1072. if (TURBOCHANNEL) {
  1073. int slot;
  1074. while ((slot = search_tc_card("PMAD-AA")) >= 0) {
  1075. if (dec_lance_init(PMAD_LANCE, slot) < 0)
  1076. break;
  1077. count++;
  1078. }
  1079. }
  1080. #endif
  1081. /* Then handle onboard devices. */
  1082. if (dec_interrupt[DEC_IRQ_LANCE] >= 0) {
  1083. if (dec_interrupt[DEC_IRQ_LANCE_MERR] >= 0) {
  1084. #ifdef CONFIG_TC
  1085. if (dec_lance_init(ASIC_LANCE, -1) >= 0)
  1086. count++;
  1087. #endif
  1088. } else if (!TURBOCHANNEL) {
  1089. if (dec_lance_init(PMAX_LANCE, -1) >= 0)
  1090. count++;
  1091. }
  1092. }
  1093. return (count > 0) ? 0 : -ENODEV;
  1094. }
  1095. static void __exit dec_lance_cleanup(void)
  1096. {
  1097. while (root_lance_dev) {
  1098. struct net_device *dev = root_lance_dev;
  1099. struct lance_private *lp = netdev_priv(dev);
  1100. unregister_netdev(dev);
  1101. #ifdef CONFIG_TC
  1102. if (lp->slot >= 0)
  1103. release_tc_card(lp->slot);
  1104. #endif
  1105. root_lance_dev = lp->next;
  1106. free_netdev(dev);
  1107. }
  1108. }
  1109. module_init(dec_lance_probe);
  1110. module_exit(dec_lance_cleanup);