declance.c 35 KB

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