3c509.c 42 KB

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