3c509.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595
  1. /* 3c509.c: A 3c509 EtherLink3 ethernet driver for linux. */
  2. /*
  3. Written 1993-2000 by Donald Becker.
  4. Copyright 1994-2000 by Donald Becker.
  5. Copyright 1993 United States Government as represented by the
  6. Director, National Security Agency. This software may be used and
  7. distributed according to the terms of the GNU General Public License,
  8. incorporated herein by reference.
  9. This driver is for the 3Com EtherLinkIII series.
  10. The author may be reached as becker@scyld.com, or C/O
  11. Scyld Computing Corporation
  12. 410 Severn Ave., Suite 210
  13. Annapolis MD 21403
  14. Known limitations:
  15. Because of the way 3c509 ISA detection works it's difficult to predict
  16. a priori which of several ISA-mode cards will be detected first.
  17. This driver does not use predictive interrupt mode, resulting in higher
  18. packet latency but lower overhead. If interrupts are disabled for an
  19. unusually long time it could also result in missed packets, but in
  20. practice this rarely happens.
  21. FIXES:
  22. Alan Cox: Removed the 'Unexpected interrupt' bug.
  23. Michael Meskes: Upgraded to Donald Becker's version 1.07.
  24. Alan Cox: Increased the eeprom delay. Regardless of
  25. what the docs say some people definitely
  26. get problems with lower (but in card spec)
  27. delays
  28. v1.10 4/21/97 Fixed module code so that multiple cards may be detected,
  29. other cleanups. -djb
  30. Andrea Arcangeli: Upgraded to Donald Becker's version 1.12.
  31. Rick Payne: Fixed SMP race condition
  32. v1.13 9/8/97 Made 'max_interrupt_work' an insmod-settable variable -djb
  33. v1.14 10/15/97 Avoided waiting..discard message for fast machines -djb
  34. v1.15 1/31/98 Faster recovery for Tx errors. -djb
  35. v1.16 2/3/98 Different ID port handling to avoid sound cards. -djb
  36. v1.18 12Mar2001 Andrew Morton
  37. - Avoid bogus detect of 3c590's (Andrzej Krzysztofowicz)
  38. - Reviewed against 1.18 from scyld.com
  39. v1.18a 17Nov2001 Jeff Garzik <jgarzik@pobox.com>
  40. - ethtool support
  41. v1.18b 1Mar2002 Zwane Mwaikambo <zwane@commfireservices.com>
  42. - Power Management support
  43. v1.18c 1Mar2002 David Ruggiero <jdr@farfalle.com>
  44. - Full duplex support
  45. v1.19 16Oct2002 Zwane Mwaikambo <zwane@linuxpower.ca>
  46. - Additional ethtool features
  47. v1.19a 28Oct2002 Davud Ruggiero <jdr@farfalle.com>
  48. - Increase *read_eeprom udelay to workaround oops with 2 cards.
  49. v1.19b 08Nov2002 Marc Zyngier <maz@wild-wind.fr.eu.org>
  50. - Introduce driver model for EISA cards.
  51. v1.20 04Feb2008 Ondrej Zary <linux@rainbow-software.org>
  52. - convert to isa_driver and pnp_driver and some cleanups
  53. */
  54. #define DRV_NAME "3c509"
  55. #define DRV_VERSION "1.20"
  56. #define DRV_RELDATE "04Feb2008"
  57. /* A few values that may be tweaked. */
  58. /* Time in jiffies before concluding the transmitter is hung. */
  59. #define TX_TIMEOUT (400*HZ/1000)
  60. #include <linux/module.h>
  61. #include <linux/mca.h>
  62. #include <linux/isa.h>
  63. #include <linux/pnp.h>
  64. #include <linux/string.h>
  65. #include <linux/interrupt.h>
  66. #include <linux/errno.h>
  67. #include <linux/in.h>
  68. #include <linux/ioport.h>
  69. #include <linux/init.h>
  70. #include <linux/netdevice.h>
  71. #include <linux/etherdevice.h>
  72. #include <linux/pm.h>
  73. #include <linux/skbuff.h>
  74. #include <linux/delay.h> /* for udelay() */
  75. #include <linux/spinlock.h>
  76. #include <linux/ethtool.h>
  77. #include <linux/device.h>
  78. #include <linux/eisa.h>
  79. #include <linux/bitops.h>
  80. #include <asm/uaccess.h>
  81. #include <asm/io.h>
  82. #include <asm/irq.h>
  83. static char version[] __devinitdata = DRV_NAME ".c:" DRV_VERSION " " DRV_RELDATE " becker@scyld.com\n";
  84. #ifdef EL3_DEBUG
  85. static int el3_debug = EL3_DEBUG;
  86. #else
  87. static int el3_debug = 2;
  88. #endif
  89. /* Used to do a global count of all the cards in the system. Must be
  90. * a global variable so that the mca/eisa probe routines can increment
  91. * it */
  92. static int el3_cards = 0;
  93. #define EL3_MAX_CARDS 8
  94. /* To minimize the size of the driver source I only define operating
  95. constants if they are used several times. You'll need the manual
  96. anyway if you want to understand driver details. */
  97. /* Offsets from base I/O address. */
  98. #define EL3_DATA 0x00
  99. #define EL3_CMD 0x0e
  100. #define EL3_STATUS 0x0e
  101. #define EEPROM_READ 0x80
  102. #define EL3_IO_EXTENT 16
  103. #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
  104. /* The top five bits written to EL3_CMD are a command, the lower
  105. 11 bits are the parameter, if applicable. */
  106. enum c509cmd {
  107. TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
  108. RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11, RxDiscard = 8<<11,
  109. TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
  110. FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
  111. SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
  112. SetTxThreshold = 18<<11, SetTxStart = 19<<11, StatsEnable = 21<<11,
  113. StatsDisable = 22<<11, StopCoax = 23<<11, PowerUp = 27<<11,
  114. PowerDown = 28<<11, PowerAuto = 29<<11};
  115. enum c509status {
  116. IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004,
  117. TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
  118. IntReq = 0x0040, StatsFull = 0x0080, CmdBusy = 0x1000, };
  119. /* The SetRxFilter command accepts the following classes: */
  120. enum RxFilter {
  121. RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
  122. /* Register window 1 offsets, the window used in normal operation. */
  123. #define TX_FIFO 0x00
  124. #define RX_FIFO 0x00
  125. #define RX_STATUS 0x08
  126. #define TX_STATUS 0x0B
  127. #define TX_FREE 0x0C /* Remaining free bytes in Tx buffer. */
  128. #define WN0_CONF_CTRL 0x04 /* Window 0: Configuration control register */
  129. #define WN0_ADDR_CONF 0x06 /* Window 0: Address configuration register */
  130. #define WN0_IRQ 0x08 /* Window 0: Set IRQ line in bits 12-15. */
  131. #define WN4_MEDIA 0x0A /* Window 4: Various transcvr/media bits. */
  132. #define MEDIA_TP 0x00C0 /* Enable link beat and jabber for 10baseT. */
  133. #define WN4_NETDIAG 0x06 /* Window 4: Net diagnostic */
  134. #define FD_ENABLE 0x8000 /* Enable full-duplex ("external loopback") */
  135. /*
  136. * Must be a power of two (we use a binary and in the
  137. * circular queue)
  138. */
  139. #define SKB_QUEUE_SIZE 64
  140. enum el3_cardtype { EL3_ISA, EL3_PNP, EL3_MCA, EL3_EISA };
  141. struct el3_private {
  142. spinlock_t lock;
  143. /* skb send-queue */
  144. int head, size;
  145. struct sk_buff *queue[SKB_QUEUE_SIZE];
  146. enum el3_cardtype type;
  147. };
  148. static int id_port;
  149. static int current_tag;
  150. static struct net_device *el3_devs[EL3_MAX_CARDS];
  151. /* Parameters that may be passed into the module. */
  152. static int debug = -1;
  153. static int irq[] = {-1, -1, -1, -1, -1, -1, -1, -1};
  154. /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
  155. static int max_interrupt_work = 10;
  156. #ifdef CONFIG_PNP
  157. static int nopnp;
  158. #endif
  159. static int __devinit el3_common_init(struct net_device *dev);
  160. static void el3_common_remove(struct net_device *dev);
  161. static ushort id_read_eeprom(int index);
  162. static ushort read_eeprom(int ioaddr, int index);
  163. static int el3_open(struct net_device *dev);
  164. static netdev_tx_t el3_start_xmit(struct sk_buff *skb, struct net_device *dev);
  165. static irqreturn_t el3_interrupt(int irq, void *dev_id);
  166. static void update_stats(struct net_device *dev);
  167. static struct net_device_stats *el3_get_stats(struct net_device *dev);
  168. static int el3_rx(struct net_device *dev);
  169. static int el3_close(struct net_device *dev);
  170. static void set_multicast_list(struct net_device *dev);
  171. static void el3_tx_timeout (struct net_device *dev);
  172. static void el3_down(struct net_device *dev);
  173. static void el3_up(struct net_device *dev);
  174. static const struct ethtool_ops ethtool_ops;
  175. #ifdef CONFIG_PM
  176. static int el3_suspend(struct device *, pm_message_t);
  177. static int el3_resume(struct device *);
  178. #else
  179. #define el3_suspend NULL
  180. #define el3_resume NULL
  181. #endif
  182. /* generic device remove for all device types */
  183. static int el3_device_remove (struct device *device);
  184. #ifdef CONFIG_NET_POLL_CONTROLLER
  185. static void el3_poll_controller(struct net_device *dev);
  186. #endif
  187. /* Return 0 on success, 1 on error, 2 when found already detected PnP card */
  188. static int el3_isa_id_sequence(__be16 *phys_addr)
  189. {
  190. short lrs_state = 0xff;
  191. int i;
  192. /* ISA boards are detected by sending the ID sequence to the
  193. ID_PORT. We find cards past the first by setting the 'current_tag'
  194. on cards as they are found. Cards with their tag set will not
  195. respond to subsequent ID sequences. */
  196. outb(0x00, id_port);
  197. outb(0x00, id_port);
  198. for (i = 0; i < 255; i++) {
  199. outb(lrs_state, id_port);
  200. lrs_state <<= 1;
  201. lrs_state = lrs_state & 0x100 ? lrs_state ^ 0xcf : lrs_state;
  202. }
  203. /* For the first probe, clear all board's tag registers. */
  204. if (current_tag == 0)
  205. outb(0xd0, id_port);
  206. else /* Otherwise kill off already-found boards. */
  207. outb(0xd8, id_port);
  208. if (id_read_eeprom(7) != 0x6d50)
  209. return 1;
  210. /* Read in EEPROM data, which does contention-select.
  211. Only the lowest address board will stay "on-line".
  212. 3Com got the byte order backwards. */
  213. for (i = 0; i < 3; i++)
  214. phys_addr[i] = htons(id_read_eeprom(i));
  215. #ifdef CONFIG_PNP
  216. if (!nopnp) {
  217. /* The ISA PnP 3c509 cards respond to the ID sequence too.
  218. This check is needed in order not to register them twice. */
  219. for (i = 0; i < el3_cards; i++) {
  220. struct el3_private *lp = netdev_priv(el3_devs[i]);
  221. if (lp->type == EL3_PNP &&
  222. !memcmp(phys_addr, el3_devs[i]->dev_addr,
  223. ETH_ALEN)) {
  224. if (el3_debug > 3)
  225. pr_debug("3c509 with address %02x %02x %02x %02x %02x %02x was found by ISAPnP\n",
  226. phys_addr[0] & 0xff, phys_addr[0] >> 8,
  227. phys_addr[1] & 0xff, phys_addr[1] >> 8,
  228. phys_addr[2] & 0xff, phys_addr[2] >> 8);
  229. /* Set the adaptor tag so that the next card can be found. */
  230. outb(0xd0 + ++current_tag, id_port);
  231. return 2;
  232. }
  233. }
  234. }
  235. #endif /* CONFIG_PNP */
  236. return 0;
  237. }
  238. static void __devinit el3_dev_fill(struct net_device *dev, __be16 *phys_addr,
  239. int ioaddr, int irq, int if_port,
  240. enum el3_cardtype type)
  241. {
  242. struct el3_private *lp = netdev_priv(dev);
  243. memcpy(dev->dev_addr, phys_addr, ETH_ALEN);
  244. dev->base_addr = ioaddr;
  245. dev->irq = irq;
  246. dev->if_port = if_port;
  247. lp->type = type;
  248. }
  249. static int __devinit el3_isa_match(struct device *pdev,
  250. unsigned int ndev)
  251. {
  252. struct net_device *dev;
  253. int ioaddr, isa_irq, if_port, err;
  254. unsigned int iobase;
  255. __be16 phys_addr[3];
  256. while ((err = el3_isa_id_sequence(phys_addr)) == 2)
  257. ; /* Skip to next card when PnP card found */
  258. if (err == 1)
  259. return 0;
  260. iobase = id_read_eeprom(8);
  261. if_port = iobase >> 14;
  262. ioaddr = 0x200 + ((iobase & 0x1f) << 4);
  263. if (irq[el3_cards] > 1 && irq[el3_cards] < 16)
  264. isa_irq = irq[el3_cards];
  265. else
  266. isa_irq = id_read_eeprom(9) >> 12;
  267. dev = alloc_etherdev(sizeof(struct el3_private));
  268. if (!dev)
  269. return -ENOMEM;
  270. netdev_boot_setup_check(dev);
  271. if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509-isa")) {
  272. free_netdev(dev);
  273. return 0;
  274. }
  275. /* Set the adaptor tag so that the next card can be found. */
  276. outb(0xd0 + ++current_tag, id_port);
  277. /* Activate the adaptor at the EEPROM location. */
  278. outb((ioaddr >> 4) | 0xe0, id_port);
  279. EL3WINDOW(0);
  280. if (inw(ioaddr) != 0x6d50) {
  281. free_netdev(dev);
  282. return 0;
  283. }
  284. /* Free the interrupt so that some other card can use it. */
  285. outw(0x0f00, ioaddr + WN0_IRQ);
  286. el3_dev_fill(dev, phys_addr, ioaddr, isa_irq, if_port, EL3_ISA);
  287. dev_set_drvdata(pdev, dev);
  288. if (el3_common_init(dev)) {
  289. free_netdev(dev);
  290. return 0;
  291. }
  292. el3_devs[el3_cards++] = dev;
  293. return 1;
  294. }
  295. static int __devexit el3_isa_remove(struct device *pdev,
  296. unsigned int ndev)
  297. {
  298. el3_device_remove(pdev);
  299. dev_set_drvdata(pdev, NULL);
  300. return 0;
  301. }
  302. #ifdef CONFIG_PM
  303. static int el3_isa_suspend(struct device *dev, unsigned int n,
  304. pm_message_t state)
  305. {
  306. current_tag = 0;
  307. return el3_suspend(dev, state);
  308. }
  309. static int el3_isa_resume(struct device *dev, unsigned int n)
  310. {
  311. struct net_device *ndev = dev_get_drvdata(dev);
  312. int ioaddr = ndev->base_addr, err;
  313. __be16 phys_addr[3];
  314. while ((err = el3_isa_id_sequence(phys_addr)) == 2)
  315. ; /* Skip to next card when PnP card found */
  316. if (err == 1)
  317. return 0;
  318. /* Set the adaptor tag so that the next card can be found. */
  319. outb(0xd0 + ++current_tag, id_port);
  320. /* Enable the card */
  321. outb((ioaddr >> 4) | 0xe0, id_port);
  322. EL3WINDOW(0);
  323. if (inw(ioaddr) != 0x6d50)
  324. return 1;
  325. /* Free the interrupt so that some other card can use it. */
  326. outw(0x0f00, ioaddr + WN0_IRQ);
  327. return el3_resume(dev);
  328. }
  329. #endif
  330. static struct isa_driver el3_isa_driver = {
  331. .match = el3_isa_match,
  332. .remove = __devexit_p(el3_isa_remove),
  333. #ifdef CONFIG_PM
  334. .suspend = el3_isa_suspend,
  335. .resume = el3_isa_resume,
  336. #endif
  337. .driver = {
  338. .name = "3c509"
  339. },
  340. };
  341. static int isa_registered;
  342. #ifdef CONFIG_PNP
  343. static struct pnp_device_id el3_pnp_ids[] = {
  344. { .id = "TCM5090" }, /* 3Com Etherlink III (TP) */
  345. { .id = "TCM5091" }, /* 3Com Etherlink III */
  346. { .id = "TCM5094" }, /* 3Com Etherlink III (combo) */
  347. { .id = "TCM5095" }, /* 3Com Etherlink III (TPO) */
  348. { .id = "TCM5098" }, /* 3Com Etherlink III (TPC) */
  349. { .id = "PNP80f7" }, /* 3Com Etherlink III compatible */
  350. { .id = "PNP80f8" }, /* 3Com Etherlink III compatible */
  351. { .id = "" }
  352. };
  353. MODULE_DEVICE_TABLE(pnp, el3_pnp_ids);
  354. static int __devinit el3_pnp_probe(struct pnp_dev *pdev,
  355. const struct pnp_device_id *id)
  356. {
  357. short i;
  358. int ioaddr, irq, if_port;
  359. __be16 phys_addr[3];
  360. struct net_device *dev = NULL;
  361. int err;
  362. ioaddr = pnp_port_start(pdev, 0);
  363. if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509-pnp"))
  364. return -EBUSY;
  365. irq = pnp_irq(pdev, 0);
  366. EL3WINDOW(0);
  367. for (i = 0; i < 3; i++)
  368. phys_addr[i] = htons(read_eeprom(ioaddr, i));
  369. if_port = read_eeprom(ioaddr, 8) >> 14;
  370. dev = alloc_etherdev(sizeof(struct el3_private));
  371. if (!dev) {
  372. release_region(ioaddr, EL3_IO_EXTENT);
  373. return -ENOMEM;
  374. }
  375. SET_NETDEV_DEV(dev, &pdev->dev);
  376. netdev_boot_setup_check(dev);
  377. el3_dev_fill(dev, phys_addr, ioaddr, irq, if_port, EL3_PNP);
  378. pnp_set_drvdata(pdev, dev);
  379. err = el3_common_init(dev);
  380. if (err) {
  381. pnp_set_drvdata(pdev, NULL);
  382. free_netdev(dev);
  383. return err;
  384. }
  385. el3_devs[el3_cards++] = dev;
  386. return 0;
  387. }
  388. static void __devexit el3_pnp_remove(struct pnp_dev *pdev)
  389. {
  390. el3_common_remove(pnp_get_drvdata(pdev));
  391. pnp_set_drvdata(pdev, NULL);
  392. }
  393. #ifdef CONFIG_PM
  394. static int el3_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
  395. {
  396. return el3_suspend(&pdev->dev, state);
  397. }
  398. static int el3_pnp_resume(struct pnp_dev *pdev)
  399. {
  400. return el3_resume(&pdev->dev);
  401. }
  402. #endif
  403. static struct pnp_driver el3_pnp_driver = {
  404. .name = "3c509",
  405. .id_table = el3_pnp_ids,
  406. .probe = el3_pnp_probe,
  407. .remove = __devexit_p(el3_pnp_remove),
  408. #ifdef CONFIG_PM
  409. .suspend = el3_pnp_suspend,
  410. .resume = el3_pnp_resume,
  411. #endif
  412. };
  413. static int pnp_registered;
  414. #endif /* CONFIG_PNP */
  415. #ifdef CONFIG_EISA
  416. static struct eisa_device_id el3_eisa_ids[] = {
  417. { "TCM5090" },
  418. { "TCM5091" },
  419. { "TCM5092" },
  420. { "TCM5093" },
  421. { "TCM5094" },
  422. { "TCM5095" },
  423. { "TCM5098" },
  424. { "" }
  425. };
  426. MODULE_DEVICE_TABLE(eisa, el3_eisa_ids);
  427. static int el3_eisa_probe (struct device *device);
  428. static struct eisa_driver el3_eisa_driver = {
  429. .id_table = el3_eisa_ids,
  430. .driver = {
  431. .name = "3c579",
  432. .probe = el3_eisa_probe,
  433. .remove = __devexit_p (el3_device_remove),
  434. .suspend = el3_suspend,
  435. .resume = el3_resume,
  436. }
  437. };
  438. static int eisa_registered;
  439. #endif
  440. #ifdef CONFIG_MCA
  441. static int el3_mca_probe(struct device *dev);
  442. static short el3_mca_adapter_ids[] __initdata = {
  443. 0x627c,
  444. 0x627d,
  445. 0x62db,
  446. 0x62f6,
  447. 0x62f7,
  448. 0x0000
  449. };
  450. static char *el3_mca_adapter_names[] __initdata = {
  451. "3Com 3c529 EtherLink III (10base2)",
  452. "3Com 3c529 EtherLink III (10baseT)",
  453. "3Com 3c529 EtherLink III (test mode)",
  454. "3Com 3c529 EtherLink III (TP or coax)",
  455. "3Com 3c529 EtherLink III (TP)",
  456. NULL
  457. };
  458. static struct mca_driver el3_mca_driver = {
  459. .id_table = el3_mca_adapter_ids,
  460. .driver = {
  461. .name = "3c529",
  462. .bus = &mca_bus_type,
  463. .probe = el3_mca_probe,
  464. .remove = __devexit_p(el3_device_remove),
  465. .suspend = el3_suspend,
  466. .resume = el3_resume,
  467. },
  468. };
  469. static int mca_registered;
  470. #endif /* CONFIG_MCA */
  471. static const struct net_device_ops netdev_ops = {
  472. .ndo_open = el3_open,
  473. .ndo_stop = el3_close,
  474. .ndo_start_xmit = el3_start_xmit,
  475. .ndo_get_stats = el3_get_stats,
  476. .ndo_set_multicast_list = set_multicast_list,
  477. .ndo_tx_timeout = el3_tx_timeout,
  478. .ndo_change_mtu = eth_change_mtu,
  479. .ndo_set_mac_address = eth_mac_addr,
  480. .ndo_validate_addr = eth_validate_addr,
  481. #ifdef CONFIG_NET_POLL_CONTROLLER
  482. .ndo_poll_controller = el3_poll_controller,
  483. #endif
  484. };
  485. static int __devinit el3_common_init(struct net_device *dev)
  486. {
  487. struct el3_private *lp = netdev_priv(dev);
  488. int err;
  489. const char *if_names[] = {"10baseT", "AUI", "undefined", "BNC"};
  490. spin_lock_init(&lp->lock);
  491. if (dev->mem_start & 0x05) { /* xcvr codes 1/3/4/12 */
  492. dev->if_port = (dev->mem_start & 0x0f);
  493. } else { /* xcvr codes 0/8 */
  494. /* use eeprom value, but save user's full-duplex selection */
  495. dev->if_port |= (dev->mem_start & 0x08);
  496. }
  497. /* The EL3-specific entries in the device structure. */
  498. dev->netdev_ops = &netdev_ops;
  499. dev->watchdog_timeo = TX_TIMEOUT;
  500. SET_ETHTOOL_OPS(dev, &ethtool_ops);
  501. err = register_netdev(dev);
  502. if (err) {
  503. pr_err("Failed to register 3c5x9 at %#3.3lx, IRQ %d.\n",
  504. dev->base_addr, dev->irq);
  505. release_region(dev->base_addr, EL3_IO_EXTENT);
  506. return err;
  507. }
  508. pr_info("%s: 3c5x9 found at %#3.3lx, %s port, address %pM, IRQ %d.\n",
  509. dev->name, dev->base_addr, if_names[(dev->if_port & 0x03)],
  510. dev->dev_addr, dev->irq);
  511. if (el3_debug > 0)
  512. pr_info("%s", version);
  513. return 0;
  514. }
  515. static void el3_common_remove (struct net_device *dev)
  516. {
  517. unregister_netdev (dev);
  518. release_region(dev->base_addr, EL3_IO_EXTENT);
  519. free_netdev (dev);
  520. }
  521. #ifdef CONFIG_MCA
  522. static int __init el3_mca_probe(struct device *device)
  523. {
  524. /* Based on Erik Nygren's (nygren@mit.edu) 3c529 patch,
  525. * heavily modified by Chris Beauregard
  526. * (cpbeaure@csclub.uwaterloo.ca) to support standard MCA
  527. * probing.
  528. *
  529. * redone for multi-card detection by ZP Gu (zpg@castle.net)
  530. * now works as a module */
  531. short i;
  532. int ioaddr, irq, if_port;
  533. __be16 phys_addr[3];
  534. struct net_device *dev = NULL;
  535. u_char pos4, pos5;
  536. struct mca_device *mdev = to_mca_device(device);
  537. int slot = mdev->slot;
  538. int err;
  539. pos4 = mca_device_read_stored_pos(mdev, 4);
  540. pos5 = mca_device_read_stored_pos(mdev, 5);
  541. ioaddr = ((short)((pos4&0xfc)|0x02)) << 8;
  542. irq = pos5 & 0x0f;
  543. pr_info("3c529: found %s at slot %d\n",
  544. el3_mca_adapter_names[mdev->index], slot + 1);
  545. /* claim the slot */
  546. strncpy(mdev->name, el3_mca_adapter_names[mdev->index],
  547. sizeof(mdev->name));
  548. mca_device_set_claim(mdev, 1);
  549. if_port = pos4 & 0x03;
  550. irq = mca_device_transform_irq(mdev, irq);
  551. ioaddr = mca_device_transform_ioport(mdev, ioaddr);
  552. if (el3_debug > 2) {
  553. pr_debug("3c529: irq %d ioaddr 0x%x ifport %d\n", irq, ioaddr, if_port);
  554. }
  555. EL3WINDOW(0);
  556. for (i = 0; i < 3; i++)
  557. phys_addr[i] = htons(read_eeprom(ioaddr, i));
  558. dev = alloc_etherdev(sizeof (struct el3_private));
  559. if (dev == NULL) {
  560. release_region(ioaddr, EL3_IO_EXTENT);
  561. return -ENOMEM;
  562. }
  563. netdev_boot_setup_check(dev);
  564. el3_dev_fill(dev, phys_addr, ioaddr, irq, if_port, EL3_MCA);
  565. dev_set_drvdata(device, dev);
  566. err = el3_common_init(dev);
  567. if (err) {
  568. dev_set_drvdata(device, NULL);
  569. free_netdev(dev);
  570. return -ENOMEM;
  571. }
  572. el3_devs[el3_cards++] = dev;
  573. return 0;
  574. }
  575. #endif /* CONFIG_MCA */
  576. #ifdef CONFIG_EISA
  577. static int __init el3_eisa_probe (struct device *device)
  578. {
  579. short i;
  580. int ioaddr, irq, if_port;
  581. __be16 phys_addr[3];
  582. struct net_device *dev = NULL;
  583. struct eisa_device *edev;
  584. int err;
  585. /* Yeepee, The driver framework is calling us ! */
  586. edev = to_eisa_device (device);
  587. ioaddr = edev->base_addr;
  588. if (!request_region(ioaddr, EL3_IO_EXTENT, "3c579-eisa"))
  589. return -EBUSY;
  590. /* Change the register set to the configuration window 0. */
  591. outw(SelectWindow | 0, ioaddr + 0xC80 + EL3_CMD);
  592. irq = inw(ioaddr + WN0_IRQ) >> 12;
  593. if_port = inw(ioaddr + 6)>>14;
  594. for (i = 0; i < 3; i++)
  595. phys_addr[i] = htons(read_eeprom(ioaddr, i));
  596. /* Restore the "Product ID" to the EEPROM read register. */
  597. read_eeprom(ioaddr, 3);
  598. dev = alloc_etherdev(sizeof (struct el3_private));
  599. if (dev == NULL) {
  600. release_region(ioaddr, EL3_IO_EXTENT);
  601. return -ENOMEM;
  602. }
  603. netdev_boot_setup_check(dev);
  604. el3_dev_fill(dev, phys_addr, ioaddr, irq, if_port, EL3_EISA);
  605. eisa_set_drvdata (edev, dev);
  606. err = el3_common_init(dev);
  607. if (err) {
  608. eisa_set_drvdata (edev, NULL);
  609. free_netdev(dev);
  610. return err;
  611. }
  612. el3_devs[el3_cards++] = dev;
  613. return 0;
  614. }
  615. #endif
  616. /* This remove works for all device types.
  617. *
  618. * The net dev must be stored in the driver data field */
  619. static int __devexit el3_device_remove (struct device *device)
  620. {
  621. struct net_device *dev;
  622. dev = dev_get_drvdata(device);
  623. el3_common_remove (dev);
  624. return 0;
  625. }
  626. /* Read a word from the EEPROM using the regular EEPROM access register.
  627. Assume that we are in register window zero.
  628. */
  629. static ushort read_eeprom(int ioaddr, int index)
  630. {
  631. outw(EEPROM_READ + index, ioaddr + 10);
  632. /* Pause for at least 162 us. for the read to take place.
  633. Some chips seem to require much longer */
  634. mdelay(2);
  635. return inw(ioaddr + 12);
  636. }
  637. /* Read a word from the EEPROM when in the ISA ID probe state. */
  638. static ushort id_read_eeprom(int index)
  639. {
  640. int bit, word = 0;
  641. /* Issue read command, and pause for at least 162 us. for it to complete.
  642. Assume extra-fast 16Mhz bus. */
  643. outb(EEPROM_READ + index, id_port);
  644. /* Pause for at least 162 us. for the read to take place. */
  645. /* Some chips seem to require much longer */
  646. mdelay(4);
  647. for (bit = 15; bit >= 0; bit--)
  648. word = (word << 1) + (inb(id_port) & 0x01);
  649. if (el3_debug > 3)
  650. pr_debug(" 3c509 EEPROM word %d %#4.4x.\n", index, word);
  651. return word;
  652. }
  653. static int
  654. el3_open(struct net_device *dev)
  655. {
  656. int ioaddr = dev->base_addr;
  657. int i;
  658. outw(TxReset, ioaddr + EL3_CMD);
  659. outw(RxReset, ioaddr + EL3_CMD);
  660. outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
  661. i = request_irq(dev->irq, el3_interrupt, 0, dev->name, dev);
  662. if (i)
  663. return i;
  664. EL3WINDOW(0);
  665. if (el3_debug > 3)
  666. pr_debug("%s: Opening, IRQ %d status@%x %4.4x.\n", dev->name,
  667. dev->irq, ioaddr + EL3_STATUS, inw(ioaddr + EL3_STATUS));
  668. el3_up(dev);
  669. if (el3_debug > 3)
  670. pr_debug("%s: Opened 3c509 IRQ %d status %4.4x.\n",
  671. dev->name, dev->irq, inw(ioaddr + EL3_STATUS));
  672. return 0;
  673. }
  674. static void
  675. el3_tx_timeout (struct net_device *dev)
  676. {
  677. int ioaddr = dev->base_addr;
  678. /* Transmitter timeout, serious problems. */
  679. pr_warning("%s: transmit timed out, Tx_status %2.2x status %4.4x Tx FIFO room %d.\n",
  680. dev->name, inb(ioaddr + TX_STATUS), inw(ioaddr + EL3_STATUS),
  681. inw(ioaddr + TX_FREE));
  682. dev->stats.tx_errors++;
  683. dev->trans_start = jiffies; /* prevent tx timeout */
  684. /* Issue TX_RESET and TX_START commands. */
  685. outw(TxReset, ioaddr + EL3_CMD);
  686. outw(TxEnable, ioaddr + EL3_CMD);
  687. netif_wake_queue(dev);
  688. }
  689. static netdev_tx_t
  690. el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
  691. {
  692. struct el3_private *lp = netdev_priv(dev);
  693. int ioaddr = dev->base_addr;
  694. unsigned long flags;
  695. netif_stop_queue (dev);
  696. dev->stats.tx_bytes += skb->len;
  697. if (el3_debug > 4) {
  698. pr_debug("%s: el3_start_xmit(length = %u) called, status %4.4x.\n",
  699. dev->name, skb->len, inw(ioaddr + EL3_STATUS));
  700. }
  701. #if 0
  702. #ifndef final_version
  703. { /* Error-checking code, delete someday. */
  704. ushort status = inw(ioaddr + EL3_STATUS);
  705. if (status & 0x0001 && /* IRQ line active, missed one. */
  706. inw(ioaddr + EL3_STATUS) & 1) { /* Make sure. */
  707. pr_debug("%s: Missed interrupt, status then %04x now %04x"
  708. " Tx %2.2x Rx %4.4x.\n", dev->name, status,
  709. inw(ioaddr + EL3_STATUS), inb(ioaddr + TX_STATUS),
  710. inw(ioaddr + RX_STATUS));
  711. /* Fake interrupt trigger by masking, acknowledge interrupts. */
  712. outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
  713. outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
  714. ioaddr + EL3_CMD);
  715. outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
  716. }
  717. }
  718. #endif
  719. #endif
  720. /*
  721. * We lock the driver against other processors. Note
  722. * we don't need to lock versus the IRQ as we suspended
  723. * that. This means that we lose the ability to take
  724. * an RX during a TX upload. That sucks a bit with SMP
  725. * on an original 3c509 (2K buffer)
  726. *
  727. * Using disable_irq stops us crapping on other
  728. * time sensitive devices.
  729. */
  730. spin_lock_irqsave(&lp->lock, flags);
  731. /* Put out the doubleword header... */
  732. outw(skb->len, ioaddr + TX_FIFO);
  733. outw(0x00, ioaddr + TX_FIFO);
  734. /* ... and the packet rounded to a doubleword. */
  735. outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
  736. if (inw(ioaddr + TX_FREE) > 1536)
  737. netif_start_queue(dev);
  738. else
  739. /* Interrupt us when the FIFO has room for max-sized packet. */
  740. outw(SetTxThreshold + 1536, ioaddr + EL3_CMD);
  741. spin_unlock_irqrestore(&lp->lock, flags);
  742. dev_kfree_skb (skb);
  743. /* Clear the Tx status stack. */
  744. {
  745. short tx_status;
  746. int i = 4;
  747. while (--i > 0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
  748. if (tx_status & 0x38) dev->stats.tx_aborted_errors++;
  749. if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
  750. if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
  751. outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
  752. }
  753. }
  754. return NETDEV_TX_OK;
  755. }
  756. /* The EL3 interrupt handler. */
  757. static irqreturn_t
  758. el3_interrupt(int irq, void *dev_id)
  759. {
  760. struct net_device *dev = dev_id;
  761. struct el3_private *lp;
  762. int ioaddr, status;
  763. int i = max_interrupt_work;
  764. lp = netdev_priv(dev);
  765. spin_lock(&lp->lock);
  766. ioaddr = dev->base_addr;
  767. if (el3_debug > 4) {
  768. status = inw(ioaddr + EL3_STATUS);
  769. pr_debug("%s: interrupt, status %4.4x.\n", dev->name, status);
  770. }
  771. while ((status = inw(ioaddr + EL3_STATUS)) &
  772. (IntLatch | RxComplete | StatsFull)) {
  773. if (status & RxComplete)
  774. el3_rx(dev);
  775. if (status & TxAvailable) {
  776. if (el3_debug > 5)
  777. pr_debug(" TX room bit was handled.\n");
  778. /* There's room in the FIFO for a full-sized packet. */
  779. outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
  780. netif_wake_queue (dev);
  781. }
  782. if (status & (AdapterFailure | RxEarly | StatsFull | TxComplete)) {
  783. /* Handle all uncommon interrupts. */
  784. if (status & StatsFull) /* Empty statistics. */
  785. update_stats(dev);
  786. if (status & RxEarly) { /* Rx early is unused. */
  787. el3_rx(dev);
  788. outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
  789. }
  790. if (status & TxComplete) { /* Really Tx error. */
  791. short tx_status;
  792. int i = 4;
  793. while (--i>0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
  794. if (tx_status & 0x38) dev->stats.tx_aborted_errors++;
  795. if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
  796. if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
  797. outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
  798. }
  799. }
  800. if (status & AdapterFailure) {
  801. /* Adapter failure requires Rx reset and reinit. */
  802. outw(RxReset, ioaddr + EL3_CMD);
  803. /* Set the Rx filter to the current state. */
  804. outw(SetRxFilter | RxStation | RxBroadcast
  805. | (dev->flags & IFF_ALLMULTI ? RxMulticast : 0)
  806. | (dev->flags & IFF_PROMISC ? RxProm : 0),
  807. ioaddr + EL3_CMD);
  808. outw(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */
  809. outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
  810. }
  811. }
  812. if (--i < 0) {
  813. pr_err("%s: Infinite loop in interrupt, status %4.4x.\n",
  814. dev->name, status);
  815. /* Clear all interrupts. */
  816. outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
  817. break;
  818. }
  819. /* Acknowledge the IRQ. */
  820. outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD); /* Ack IRQ */
  821. }
  822. if (el3_debug > 4) {
  823. pr_debug("%s: exiting interrupt, status %4.4x.\n", dev->name,
  824. inw(ioaddr + EL3_STATUS));
  825. }
  826. spin_unlock(&lp->lock);
  827. return IRQ_HANDLED;
  828. }
  829. #ifdef CONFIG_NET_POLL_CONTROLLER
  830. /*
  831. * Polling receive - used by netconsole and other diagnostic tools
  832. * to allow network i/o with interrupts disabled.
  833. */
  834. static void el3_poll_controller(struct net_device *dev)
  835. {
  836. disable_irq(dev->irq);
  837. el3_interrupt(dev->irq, dev);
  838. enable_irq(dev->irq);
  839. }
  840. #endif
  841. static struct net_device_stats *
  842. el3_get_stats(struct net_device *dev)
  843. {
  844. struct el3_private *lp = netdev_priv(dev);
  845. unsigned long flags;
  846. /*
  847. * This is fast enough not to bother with disable IRQ
  848. * stuff.
  849. */
  850. spin_lock_irqsave(&lp->lock, flags);
  851. update_stats(dev);
  852. spin_unlock_irqrestore(&lp->lock, flags);
  853. return &dev->stats;
  854. }
  855. /* Update statistics. We change to register window 6, so this should be run
  856. single-threaded if the device is active. This is expected to be a rare
  857. operation, and it's simpler for the rest of the driver to assume that
  858. window 1 is always valid rather than use a special window-state variable.
  859. */
  860. static void update_stats(struct net_device *dev)
  861. {
  862. int ioaddr = dev->base_addr;
  863. if (el3_debug > 5)
  864. pr_debug(" Updating the statistics.\n");
  865. /* Turn off statistics updates while reading. */
  866. outw(StatsDisable, ioaddr + EL3_CMD);
  867. /* Switch to the stats window, and read everything. */
  868. EL3WINDOW(6);
  869. dev->stats.tx_carrier_errors += inb(ioaddr + 0);
  870. dev->stats.tx_heartbeat_errors += inb(ioaddr + 1);
  871. /* Multiple collisions. */ inb(ioaddr + 2);
  872. dev->stats.collisions += inb(ioaddr + 3);
  873. dev->stats.tx_window_errors += inb(ioaddr + 4);
  874. dev->stats.rx_fifo_errors += inb(ioaddr + 5);
  875. dev->stats.tx_packets += inb(ioaddr + 6);
  876. /* Rx packets */ inb(ioaddr + 7);
  877. /* Tx deferrals */ inb(ioaddr + 8);
  878. inw(ioaddr + 10); /* Total Rx and Tx octets. */
  879. inw(ioaddr + 12);
  880. /* Back to window 1, and turn statistics back on. */
  881. EL3WINDOW(1);
  882. outw(StatsEnable, ioaddr + EL3_CMD);
  883. }
  884. static int
  885. el3_rx(struct net_device *dev)
  886. {
  887. int ioaddr = dev->base_addr;
  888. short rx_status;
  889. if (el3_debug > 5)
  890. pr_debug(" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
  891. inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
  892. while ((rx_status = inw(ioaddr + RX_STATUS)) > 0) {
  893. if (rx_status & 0x4000) { /* Error, update stats. */
  894. short error = rx_status & 0x3800;
  895. outw(RxDiscard, ioaddr + EL3_CMD);
  896. dev->stats.rx_errors++;
  897. switch (error) {
  898. case 0x0000: dev->stats.rx_over_errors++; break;
  899. case 0x0800: dev->stats.rx_length_errors++; break;
  900. case 0x1000: dev->stats.rx_frame_errors++; break;
  901. case 0x1800: dev->stats.rx_length_errors++; break;
  902. case 0x2000: dev->stats.rx_frame_errors++; break;
  903. case 0x2800: dev->stats.rx_crc_errors++; break;
  904. }
  905. } else {
  906. short pkt_len = rx_status & 0x7ff;
  907. struct sk_buff *skb;
  908. skb = dev_alloc_skb(pkt_len+5);
  909. if (el3_debug > 4)
  910. pr_debug("Receiving packet size %d status %4.4x.\n",
  911. pkt_len, rx_status);
  912. if (skb != NULL) {
  913. skb_reserve(skb, 2); /* Align IP on 16 byte */
  914. /* 'skb->data' points to the start of sk_buff data area. */
  915. insl(ioaddr + RX_FIFO, skb_put(skb,pkt_len),
  916. (pkt_len + 3) >> 2);
  917. outw(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
  918. skb->protocol = eth_type_trans(skb,dev);
  919. netif_rx(skb);
  920. dev->stats.rx_bytes += pkt_len;
  921. dev->stats.rx_packets++;
  922. continue;
  923. }
  924. outw(RxDiscard, ioaddr + EL3_CMD);
  925. dev->stats.rx_dropped++;
  926. if (el3_debug)
  927. pr_debug("%s: Couldn't allocate a sk_buff of size %d.\n",
  928. dev->name, pkt_len);
  929. }
  930. inw(ioaddr + EL3_STATUS); /* Delay. */
  931. while (inw(ioaddr + EL3_STATUS) & 0x1000)
  932. pr_debug(" Waiting for 3c509 to discard packet, status %x.\n",
  933. inw(ioaddr + EL3_STATUS) );
  934. }
  935. return 0;
  936. }
  937. /*
  938. * Set or clear the multicast filter for this adaptor.
  939. */
  940. static void
  941. set_multicast_list(struct net_device *dev)
  942. {
  943. unsigned long flags;
  944. struct el3_private *lp = netdev_priv(dev);
  945. int ioaddr = dev->base_addr;
  946. int mc_count = netdev_mc_count(dev);
  947. if (el3_debug > 1) {
  948. static int old;
  949. if (old != mc_count) {
  950. old = mc_count;
  951. pr_debug("%s: Setting Rx mode to %d addresses.\n",
  952. dev->name, mc_count);
  953. }
  954. }
  955. spin_lock_irqsave(&lp->lock, flags);
  956. if (dev->flags&IFF_PROMISC) {
  957. outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm,
  958. ioaddr + EL3_CMD);
  959. }
  960. else if (mc_count || (dev->flags&IFF_ALLMULTI)) {
  961. outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast, ioaddr + EL3_CMD);
  962. }
  963. else
  964. outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
  965. spin_unlock_irqrestore(&lp->lock, flags);
  966. }
  967. static int
  968. el3_close(struct net_device *dev)
  969. {
  970. int ioaddr = dev->base_addr;
  971. struct el3_private *lp = netdev_priv(dev);
  972. if (el3_debug > 2)
  973. pr_debug("%s: Shutting down ethercard.\n", dev->name);
  974. el3_down(dev);
  975. free_irq(dev->irq, dev);
  976. /* Switching back to window 0 disables the IRQ. */
  977. EL3WINDOW(0);
  978. if (lp->type != EL3_EISA) {
  979. /* But we explicitly zero the IRQ line select anyway. Don't do
  980. * it on EISA cards, it prevents the module from getting an
  981. * IRQ after unload+reload... */
  982. outw(0x0f00, ioaddr + WN0_IRQ);
  983. }
  984. return 0;
  985. }
  986. static int
  987. el3_link_ok(struct net_device *dev)
  988. {
  989. int ioaddr = dev->base_addr;
  990. u16 tmp;
  991. EL3WINDOW(4);
  992. tmp = inw(ioaddr + WN4_MEDIA);
  993. EL3WINDOW(1);
  994. return tmp & (1<<11);
  995. }
  996. static int
  997. el3_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
  998. {
  999. u16 tmp;
  1000. int ioaddr = dev->base_addr;
  1001. EL3WINDOW(0);
  1002. /* obtain current transceiver via WN4_MEDIA? */
  1003. tmp = inw(ioaddr + WN0_ADDR_CONF);
  1004. ecmd->transceiver = XCVR_INTERNAL;
  1005. switch (tmp >> 14) {
  1006. case 0:
  1007. ecmd->port = PORT_TP;
  1008. break;
  1009. case 1:
  1010. ecmd->port = PORT_AUI;
  1011. ecmd->transceiver = XCVR_EXTERNAL;
  1012. break;
  1013. case 3:
  1014. ecmd->port = PORT_BNC;
  1015. default:
  1016. break;
  1017. }
  1018. ecmd->duplex = DUPLEX_HALF;
  1019. ecmd->supported = 0;
  1020. tmp = inw(ioaddr + WN0_CONF_CTRL);
  1021. if (tmp & (1<<13))
  1022. ecmd->supported |= SUPPORTED_AUI;
  1023. if (tmp & (1<<12))
  1024. ecmd->supported |= SUPPORTED_BNC;
  1025. if (tmp & (1<<9)) {
  1026. ecmd->supported |= SUPPORTED_TP | SUPPORTED_10baseT_Half |
  1027. SUPPORTED_10baseT_Full; /* hmm... */
  1028. EL3WINDOW(4);
  1029. tmp = inw(ioaddr + WN4_NETDIAG);
  1030. if (tmp & FD_ENABLE)
  1031. ecmd->duplex = DUPLEX_FULL;
  1032. }
  1033. ethtool_cmd_speed_set(ecmd, SPEED_10);
  1034. EL3WINDOW(1);
  1035. return 0;
  1036. }
  1037. static int
  1038. el3_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
  1039. {
  1040. u16 tmp;
  1041. int ioaddr = dev->base_addr;
  1042. if (ecmd->speed != SPEED_10)
  1043. return -EINVAL;
  1044. if ((ecmd->duplex != DUPLEX_HALF) && (ecmd->duplex != DUPLEX_FULL))
  1045. return -EINVAL;
  1046. if ((ecmd->transceiver != XCVR_INTERNAL) && (ecmd->transceiver != XCVR_EXTERNAL))
  1047. return -EINVAL;
  1048. /* change XCVR type */
  1049. EL3WINDOW(0);
  1050. tmp = inw(ioaddr + WN0_ADDR_CONF);
  1051. switch (ecmd->port) {
  1052. case PORT_TP:
  1053. tmp &= ~(3<<14);
  1054. dev->if_port = 0;
  1055. break;
  1056. case PORT_AUI:
  1057. tmp |= (1<<14);
  1058. dev->if_port = 1;
  1059. break;
  1060. case PORT_BNC:
  1061. tmp |= (3<<14);
  1062. dev->if_port = 3;
  1063. break;
  1064. default:
  1065. return -EINVAL;
  1066. }
  1067. outw(tmp, ioaddr + WN0_ADDR_CONF);
  1068. if (dev->if_port == 3) {
  1069. /* fire up the DC-DC convertor if BNC gets enabled */
  1070. tmp = inw(ioaddr + WN0_ADDR_CONF);
  1071. if (tmp & (3 << 14)) {
  1072. outw(StartCoax, ioaddr + EL3_CMD);
  1073. udelay(800);
  1074. } else
  1075. return -EIO;
  1076. }
  1077. EL3WINDOW(4);
  1078. tmp = inw(ioaddr + WN4_NETDIAG);
  1079. if (ecmd->duplex == DUPLEX_FULL)
  1080. tmp |= FD_ENABLE;
  1081. else
  1082. tmp &= ~FD_ENABLE;
  1083. outw(tmp, ioaddr + WN4_NETDIAG);
  1084. EL3WINDOW(1);
  1085. return 0;
  1086. }
  1087. static void el3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1088. {
  1089. strcpy(info->driver, DRV_NAME);
  1090. strcpy(info->version, DRV_VERSION);
  1091. }
  1092. static int el3_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  1093. {
  1094. struct el3_private *lp = netdev_priv(dev);
  1095. int ret;
  1096. spin_lock_irq(&lp->lock);
  1097. ret = el3_netdev_get_ecmd(dev, ecmd);
  1098. spin_unlock_irq(&lp->lock);
  1099. return ret;
  1100. }
  1101. static int el3_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  1102. {
  1103. struct el3_private *lp = netdev_priv(dev);
  1104. int ret;
  1105. spin_lock_irq(&lp->lock);
  1106. ret = el3_netdev_set_ecmd(dev, ecmd);
  1107. spin_unlock_irq(&lp->lock);
  1108. return ret;
  1109. }
  1110. static u32 el3_get_link(struct net_device *dev)
  1111. {
  1112. struct el3_private *lp = netdev_priv(dev);
  1113. u32 ret;
  1114. spin_lock_irq(&lp->lock);
  1115. ret = el3_link_ok(dev);
  1116. spin_unlock_irq(&lp->lock);
  1117. return ret;
  1118. }
  1119. static u32 el3_get_msglevel(struct net_device *dev)
  1120. {
  1121. return el3_debug;
  1122. }
  1123. static void el3_set_msglevel(struct net_device *dev, u32 v)
  1124. {
  1125. el3_debug = v;
  1126. }
  1127. static const struct ethtool_ops ethtool_ops = {
  1128. .get_drvinfo = el3_get_drvinfo,
  1129. .get_settings = el3_get_settings,
  1130. .set_settings = el3_set_settings,
  1131. .get_link = el3_get_link,
  1132. .get_msglevel = el3_get_msglevel,
  1133. .set_msglevel = el3_set_msglevel,
  1134. };
  1135. static void
  1136. el3_down(struct net_device *dev)
  1137. {
  1138. int ioaddr = dev->base_addr;
  1139. netif_stop_queue(dev);
  1140. /* Turn off statistics ASAP. We update lp->stats below. */
  1141. outw(StatsDisable, ioaddr + EL3_CMD);
  1142. /* Disable the receiver and transmitter. */
  1143. outw(RxDisable, ioaddr + EL3_CMD);
  1144. outw(TxDisable, ioaddr + EL3_CMD);
  1145. if (dev->if_port == 3)
  1146. /* Turn off thinnet power. Green! */
  1147. outw(StopCoax, ioaddr + EL3_CMD);
  1148. else if (dev->if_port == 0) {
  1149. /* Disable link beat and jabber, if_port may change here next open(). */
  1150. EL3WINDOW(4);
  1151. outw(inw(ioaddr + WN4_MEDIA) & ~MEDIA_TP, ioaddr + WN4_MEDIA);
  1152. }
  1153. outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
  1154. update_stats(dev);
  1155. }
  1156. static void
  1157. el3_up(struct net_device *dev)
  1158. {
  1159. int i, sw_info, net_diag;
  1160. int ioaddr = dev->base_addr;
  1161. /* Activating the board required and does no harm otherwise */
  1162. outw(0x0001, ioaddr + 4);
  1163. /* Set the IRQ line. */
  1164. outw((dev->irq << 12) | 0x0f00, ioaddr + WN0_IRQ);
  1165. /* Set the station address in window 2 each time opened. */
  1166. EL3WINDOW(2);
  1167. for (i = 0; i < 6; i++)
  1168. outb(dev->dev_addr[i], ioaddr + i);
  1169. if ((dev->if_port & 0x03) == 3) /* BNC interface */
  1170. /* Start the thinnet transceiver. We should really wait 50ms...*/
  1171. outw(StartCoax, ioaddr + EL3_CMD);
  1172. else if ((dev->if_port & 0x03) == 0) { /* 10baseT interface */
  1173. /* Combine secondary sw_info word (the adapter level) and primary
  1174. sw_info word (duplex setting plus other useless bits) */
  1175. EL3WINDOW(0);
  1176. sw_info = (read_eeprom(ioaddr, 0x14) & 0x400f) |
  1177. (read_eeprom(ioaddr, 0x0d) & 0xBff0);
  1178. EL3WINDOW(4);
  1179. net_diag = inw(ioaddr + WN4_NETDIAG);
  1180. net_diag = (net_diag | FD_ENABLE); /* temporarily assume full-duplex will be set */
  1181. pr_info("%s: ", dev->name);
  1182. switch (dev->if_port & 0x0c) {
  1183. case 12:
  1184. /* force full-duplex mode if 3c5x9b */
  1185. if (sw_info & 0x000f) {
  1186. pr_cont("Forcing 3c5x9b full-duplex mode");
  1187. break;
  1188. }
  1189. case 8:
  1190. /* set full-duplex mode based on eeprom config setting */
  1191. if ((sw_info & 0x000f) && (sw_info & 0x8000)) {
  1192. pr_cont("Setting 3c5x9b full-duplex mode (from EEPROM configuration bit)");
  1193. break;
  1194. }
  1195. default:
  1196. /* xcvr=(0 || 4) OR user has an old 3c5x9 non "B" model */
  1197. pr_cont("Setting 3c5x9/3c5x9B half-duplex mode");
  1198. net_diag = (net_diag & ~FD_ENABLE); /* disable full duplex */
  1199. }
  1200. outw(net_diag, ioaddr + WN4_NETDIAG);
  1201. pr_cont(" if_port: %d, sw_info: %4.4x\n", dev->if_port, sw_info);
  1202. if (el3_debug > 3)
  1203. pr_debug("%s: 3c5x9 net diag word is now: %4.4x.\n", dev->name, net_diag);
  1204. /* Enable link beat and jabber check. */
  1205. outw(inw(ioaddr + WN4_MEDIA) | MEDIA_TP, ioaddr + WN4_MEDIA);
  1206. }
  1207. /* Switch to the stats window, and clear all stats by reading. */
  1208. outw(StatsDisable, ioaddr + EL3_CMD);
  1209. EL3WINDOW(6);
  1210. for (i = 0; i < 9; i++)
  1211. inb(ioaddr + i);
  1212. inw(ioaddr + 10);
  1213. inw(ioaddr + 12);
  1214. /* Switch to register set 1 for normal use. */
  1215. EL3WINDOW(1);
  1216. /* Accept b-case and phys addr only. */
  1217. outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
  1218. outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
  1219. outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
  1220. outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
  1221. /* Allow status bits to be seen. */
  1222. outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
  1223. /* Ack all pending events, and set active indicator mask. */
  1224. outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
  1225. ioaddr + EL3_CMD);
  1226. outw(SetIntrEnb | IntLatch|TxAvailable|TxComplete|RxComplete|StatsFull,
  1227. ioaddr + EL3_CMD);
  1228. netif_start_queue(dev);
  1229. }
  1230. /* Power Management support functions */
  1231. #ifdef CONFIG_PM
  1232. static int
  1233. el3_suspend(struct device *pdev, pm_message_t state)
  1234. {
  1235. unsigned long flags;
  1236. struct net_device *dev;
  1237. struct el3_private *lp;
  1238. int ioaddr;
  1239. dev = dev_get_drvdata(pdev);
  1240. lp = netdev_priv(dev);
  1241. ioaddr = dev->base_addr;
  1242. spin_lock_irqsave(&lp->lock, flags);
  1243. if (netif_running(dev))
  1244. netif_device_detach(dev);
  1245. el3_down(dev);
  1246. outw(PowerDown, ioaddr + EL3_CMD);
  1247. spin_unlock_irqrestore(&lp->lock, flags);
  1248. return 0;
  1249. }
  1250. static int
  1251. el3_resume(struct device *pdev)
  1252. {
  1253. unsigned long flags;
  1254. struct net_device *dev;
  1255. struct el3_private *lp;
  1256. int ioaddr;
  1257. dev = dev_get_drvdata(pdev);
  1258. lp = netdev_priv(dev);
  1259. ioaddr = dev->base_addr;
  1260. spin_lock_irqsave(&lp->lock, flags);
  1261. outw(PowerUp, ioaddr + EL3_CMD);
  1262. EL3WINDOW(0);
  1263. el3_up(dev);
  1264. if (netif_running(dev))
  1265. netif_device_attach(dev);
  1266. spin_unlock_irqrestore(&lp->lock, flags);
  1267. return 0;
  1268. }
  1269. #endif /* CONFIG_PM */
  1270. module_param(debug,int, 0);
  1271. module_param_array(irq, int, NULL, 0);
  1272. module_param(max_interrupt_work, int, 0);
  1273. MODULE_PARM_DESC(debug, "debug level (0-6)");
  1274. MODULE_PARM_DESC(irq, "IRQ number(s) (assigned)");
  1275. MODULE_PARM_DESC(max_interrupt_work, "maximum events handled per interrupt");
  1276. #ifdef CONFIG_PNP
  1277. module_param(nopnp, int, 0);
  1278. MODULE_PARM_DESC(nopnp, "disable ISA PnP support (0-1)");
  1279. #endif /* CONFIG_PNP */
  1280. MODULE_DESCRIPTION("3Com Etherlink III (3c509, 3c509B, 3c529, 3c579) ethernet driver");
  1281. MODULE_LICENSE("GPL");
  1282. static int __init el3_init_module(void)
  1283. {
  1284. int ret = 0;
  1285. if (debug >= 0)
  1286. el3_debug = debug;
  1287. #ifdef CONFIG_PNP
  1288. if (!nopnp) {
  1289. ret = pnp_register_driver(&el3_pnp_driver);
  1290. if (!ret)
  1291. pnp_registered = 1;
  1292. }
  1293. #endif
  1294. /* Select an open I/O location at 0x1*0 to do ISA contention select. */
  1295. /* Start with 0x110 to avoid some sound cards.*/
  1296. for (id_port = 0x110 ; id_port < 0x200; id_port += 0x10) {
  1297. if (!request_region(id_port, 1, "3c509-control"))
  1298. continue;
  1299. outb(0x00, id_port);
  1300. outb(0xff, id_port);
  1301. if (inb(id_port) & 0x01)
  1302. break;
  1303. else
  1304. release_region(id_port, 1);
  1305. }
  1306. if (id_port >= 0x200) {
  1307. id_port = 0;
  1308. pr_err("No I/O port available for 3c509 activation.\n");
  1309. } else {
  1310. ret = isa_register_driver(&el3_isa_driver, EL3_MAX_CARDS);
  1311. if (!ret)
  1312. isa_registered = 1;
  1313. }
  1314. #ifdef CONFIG_EISA
  1315. ret = eisa_driver_register(&el3_eisa_driver);
  1316. if (!ret)
  1317. eisa_registered = 1;
  1318. #endif
  1319. #ifdef CONFIG_MCA
  1320. ret = mca_register_driver(&el3_mca_driver);
  1321. if (!ret)
  1322. mca_registered = 1;
  1323. #endif
  1324. #ifdef CONFIG_PNP
  1325. if (pnp_registered)
  1326. ret = 0;
  1327. #endif
  1328. if (isa_registered)
  1329. ret = 0;
  1330. #ifdef CONFIG_EISA
  1331. if (eisa_registered)
  1332. ret = 0;
  1333. #endif
  1334. #ifdef CONFIG_MCA
  1335. if (mca_registered)
  1336. ret = 0;
  1337. #endif
  1338. return ret;
  1339. }
  1340. static void __exit el3_cleanup_module(void)
  1341. {
  1342. #ifdef CONFIG_PNP
  1343. if (pnp_registered)
  1344. pnp_unregister_driver(&el3_pnp_driver);
  1345. #endif
  1346. if (isa_registered)
  1347. isa_unregister_driver(&el3_isa_driver);
  1348. if (id_port)
  1349. release_region(id_port, 1);
  1350. #ifdef CONFIG_EISA
  1351. if (eisa_registered)
  1352. eisa_driver_unregister(&el3_eisa_driver);
  1353. #endif
  1354. #ifdef CONFIG_MCA
  1355. if (mca_registered)
  1356. mca_unregister_driver(&el3_mca_driver);
  1357. #endif
  1358. }
  1359. module_init (el3_init_module);
  1360. module_exit (el3_cleanup_module);