3c509.c 38 KB

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