declance.c 33 KB

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