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 <linux/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 const 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 const 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_set_mac_address = eth_mac_addr,
  444. .ndo_validate_addr = eth_validate_addr,
  445. #ifdef CONFIG_NET_POLL_CONTROLLER
  446. .ndo_poll_controller = el3_poll_controller,
  447. #endif
  448. };
  449. static int el3_common_init(struct net_device *dev)
  450. {
  451. struct el3_private *lp = netdev_priv(dev);
  452. int err;
  453. const char *if_names[] = {"10baseT", "AUI", "undefined", "BNC"};
  454. spin_lock_init(&lp->lock);
  455. if (dev->mem_start & 0x05) { /* xcvr codes 1/3/4/12 */
  456. dev->if_port = (dev->mem_start & 0x0f);
  457. } else { /* xcvr codes 0/8 */
  458. /* use eeprom value, but save user's full-duplex selection */
  459. dev->if_port |= (dev->mem_start & 0x08);
  460. }
  461. /* The EL3-specific entries in the device structure. */
  462. dev->netdev_ops = &netdev_ops;
  463. dev->watchdog_timeo = TX_TIMEOUT;
  464. dev->ethtool_ops = &ethtool_ops;
  465. err = register_netdev(dev);
  466. if (err) {
  467. pr_err("Failed to register 3c5x9 at %#3.3lx, IRQ %d.\n",
  468. dev->base_addr, dev->irq);
  469. release_region(dev->base_addr, EL3_IO_EXTENT);
  470. return err;
  471. }
  472. pr_info("%s: 3c5x9 found at %#3.3lx, %s port, address %pM, IRQ %d.\n",
  473. dev->name, dev->base_addr, if_names[(dev->if_port & 0x03)],
  474. dev->dev_addr, dev->irq);
  475. if (el3_debug > 0)
  476. pr_info("%s", version);
  477. return 0;
  478. }
  479. static void el3_common_remove (struct net_device *dev)
  480. {
  481. unregister_netdev (dev);
  482. release_region(dev->base_addr, EL3_IO_EXTENT);
  483. free_netdev (dev);
  484. }
  485. #ifdef CONFIG_EISA
  486. static int el3_eisa_probe(struct device *device)
  487. {
  488. short i;
  489. int ioaddr, irq, if_port;
  490. __be16 phys_addr[3];
  491. struct net_device *dev = NULL;
  492. struct eisa_device *edev;
  493. int err;
  494. /* Yeepee, The driver framework is calling us ! */
  495. edev = to_eisa_device (device);
  496. ioaddr = edev->base_addr;
  497. if (!request_region(ioaddr, EL3_IO_EXTENT, "3c579-eisa"))
  498. return -EBUSY;
  499. /* Change the register set to the configuration window 0. */
  500. outw(SelectWindow | 0, ioaddr + 0xC80 + EL3_CMD);
  501. irq = inw(ioaddr + WN0_IRQ) >> 12;
  502. if_port = inw(ioaddr + 6)>>14;
  503. for (i = 0; i < 3; i++)
  504. phys_addr[i] = htons(read_eeprom(ioaddr, i));
  505. /* Restore the "Product ID" to the EEPROM read register. */
  506. read_eeprom(ioaddr, 3);
  507. dev = alloc_etherdev(sizeof (struct el3_private));
  508. if (dev == NULL) {
  509. release_region(ioaddr, EL3_IO_EXTENT);
  510. return -ENOMEM;
  511. }
  512. SET_NETDEV_DEV(dev, device);
  513. netdev_boot_setup_check(dev);
  514. el3_dev_fill(dev, phys_addr, ioaddr, irq, if_port, EL3_EISA);
  515. eisa_set_drvdata (edev, dev);
  516. err = el3_common_init(dev);
  517. if (err) {
  518. eisa_set_drvdata (edev, NULL);
  519. free_netdev(dev);
  520. return err;
  521. }
  522. el3_devs[el3_cards++] = dev;
  523. return 0;
  524. }
  525. #endif
  526. /* This remove works for all device types.
  527. *
  528. * The net dev must be stored in the driver data field */
  529. static int el3_device_remove(struct device *device)
  530. {
  531. struct net_device *dev;
  532. dev = dev_get_drvdata(device);
  533. el3_common_remove (dev);
  534. return 0;
  535. }
  536. /* Read a word from the EEPROM using the regular EEPROM access register.
  537. Assume that we are in register window zero.
  538. */
  539. static ushort read_eeprom(int ioaddr, int index)
  540. {
  541. outw(EEPROM_READ + index, ioaddr + 10);
  542. /* Pause for at least 162 us. for the read to take place.
  543. Some chips seem to require much longer */
  544. mdelay(2);
  545. return inw(ioaddr + 12);
  546. }
  547. /* Read a word from the EEPROM when in the ISA ID probe state. */
  548. static ushort id_read_eeprom(int index)
  549. {
  550. int bit, word = 0;
  551. /* Issue read command, and pause for at least 162 us. for it to complete.
  552. Assume extra-fast 16Mhz bus. */
  553. outb(EEPROM_READ + index, id_port);
  554. /* Pause for at least 162 us. for the read to take place. */
  555. /* Some chips seem to require much longer */
  556. mdelay(4);
  557. for (bit = 15; bit >= 0; bit--)
  558. word = (word << 1) + (inb(id_port) & 0x01);
  559. if (el3_debug > 3)
  560. pr_debug(" 3c509 EEPROM word %d %#4.4x.\n", index, word);
  561. return word;
  562. }
  563. static int
  564. el3_open(struct net_device *dev)
  565. {
  566. int ioaddr = dev->base_addr;
  567. int i;
  568. outw(TxReset, ioaddr + EL3_CMD);
  569. outw(RxReset, ioaddr + EL3_CMD);
  570. outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
  571. i = request_irq(dev->irq, el3_interrupt, 0, dev->name, dev);
  572. if (i)
  573. return i;
  574. EL3WINDOW(0);
  575. if (el3_debug > 3)
  576. pr_debug("%s: Opening, IRQ %d status@%x %4.4x.\n", dev->name,
  577. dev->irq, ioaddr + EL3_STATUS, inw(ioaddr + EL3_STATUS));
  578. el3_up(dev);
  579. if (el3_debug > 3)
  580. pr_debug("%s: Opened 3c509 IRQ %d status %4.4x.\n",
  581. dev->name, dev->irq, inw(ioaddr + EL3_STATUS));
  582. return 0;
  583. }
  584. static void
  585. el3_tx_timeout (struct net_device *dev)
  586. {
  587. int ioaddr = dev->base_addr;
  588. /* Transmitter timeout, serious problems. */
  589. pr_warn("%s: transmit timed out, Tx_status %2.2x status %4.4x Tx FIFO room %d\n",
  590. dev->name, inb(ioaddr + TX_STATUS), inw(ioaddr + EL3_STATUS),
  591. inw(ioaddr + TX_FREE));
  592. dev->stats.tx_errors++;
  593. netif_trans_update(dev); /* prevent tx timeout */
  594. /* Issue TX_RESET and TX_START commands. */
  595. outw(TxReset, ioaddr + EL3_CMD);
  596. outw(TxEnable, ioaddr + EL3_CMD);
  597. netif_wake_queue(dev);
  598. }
  599. static netdev_tx_t
  600. el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
  601. {
  602. struct el3_private *lp = netdev_priv(dev);
  603. int ioaddr = dev->base_addr;
  604. unsigned long flags;
  605. netif_stop_queue (dev);
  606. dev->stats.tx_bytes += skb->len;
  607. if (el3_debug > 4) {
  608. pr_debug("%s: el3_start_xmit(length = %u) called, status %4.4x.\n",
  609. dev->name, skb->len, inw(ioaddr + EL3_STATUS));
  610. }
  611. /*
  612. * We lock the driver against other processors. Note
  613. * we don't need to lock versus the IRQ as we suspended
  614. * that. This means that we lose the ability to take
  615. * an RX during a TX upload. That sucks a bit with SMP
  616. * on an original 3c509 (2K buffer)
  617. *
  618. * Using disable_irq stops us crapping on other
  619. * time sensitive devices.
  620. */
  621. spin_lock_irqsave(&lp->lock, flags);
  622. /* Put out the doubleword header... */
  623. outw(skb->len, ioaddr + TX_FIFO);
  624. outw(0x00, ioaddr + TX_FIFO);
  625. /* ... and the packet rounded to a doubleword. */
  626. outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
  627. if (inw(ioaddr + TX_FREE) > 1536)
  628. netif_start_queue(dev);
  629. else
  630. /* Interrupt us when the FIFO has room for max-sized packet. */
  631. outw(SetTxThreshold + 1536, ioaddr + EL3_CMD);
  632. spin_unlock_irqrestore(&lp->lock, flags);
  633. dev_consume_skb_any (skb);
  634. /* Clear the Tx status stack. */
  635. {
  636. short tx_status;
  637. int i = 4;
  638. while (--i > 0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
  639. if (tx_status & 0x38) dev->stats.tx_aborted_errors++;
  640. if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
  641. if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
  642. outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
  643. }
  644. }
  645. return NETDEV_TX_OK;
  646. }
  647. /* The EL3 interrupt handler. */
  648. static irqreturn_t
  649. el3_interrupt(int irq, void *dev_id)
  650. {
  651. struct net_device *dev = dev_id;
  652. struct el3_private *lp;
  653. int ioaddr, status;
  654. int i = max_interrupt_work;
  655. lp = netdev_priv(dev);
  656. spin_lock(&lp->lock);
  657. ioaddr = dev->base_addr;
  658. if (el3_debug > 4) {
  659. status = inw(ioaddr + EL3_STATUS);
  660. pr_debug("%s: interrupt, status %4.4x.\n", dev->name, status);
  661. }
  662. while ((status = inw(ioaddr + EL3_STATUS)) &
  663. (IntLatch | RxComplete | StatsFull)) {
  664. if (status & RxComplete)
  665. el3_rx(dev);
  666. if (status & TxAvailable) {
  667. if (el3_debug > 5)
  668. pr_debug(" TX room bit was handled.\n");
  669. /* There's room in the FIFO for a full-sized packet. */
  670. outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
  671. netif_wake_queue (dev);
  672. }
  673. if (status & (AdapterFailure | RxEarly | StatsFull | TxComplete)) {
  674. /* Handle all uncommon interrupts. */
  675. if (status & StatsFull) /* Empty statistics. */
  676. update_stats(dev);
  677. if (status & RxEarly) { /* Rx early is unused. */
  678. el3_rx(dev);
  679. outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
  680. }
  681. if (status & TxComplete) { /* Really Tx error. */
  682. short tx_status;
  683. int i = 4;
  684. while (--i>0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
  685. if (tx_status & 0x38) dev->stats.tx_aborted_errors++;
  686. if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
  687. if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
  688. outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
  689. }
  690. }
  691. if (status & AdapterFailure) {
  692. /* Adapter failure requires Rx reset and reinit. */
  693. outw(RxReset, ioaddr + EL3_CMD);
  694. /* Set the Rx filter to the current state. */
  695. outw(SetRxFilter | RxStation | RxBroadcast
  696. | (dev->flags & IFF_ALLMULTI ? RxMulticast : 0)
  697. | (dev->flags & IFF_PROMISC ? RxProm : 0),
  698. ioaddr + EL3_CMD);
  699. outw(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */
  700. outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
  701. }
  702. }
  703. if (--i < 0) {
  704. pr_err("%s: Infinite loop in interrupt, status %4.4x.\n",
  705. dev->name, status);
  706. /* Clear all interrupts. */
  707. outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
  708. break;
  709. }
  710. /* Acknowledge the IRQ. */
  711. outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD); /* Ack IRQ */
  712. }
  713. if (el3_debug > 4) {
  714. pr_debug("%s: exiting interrupt, status %4.4x.\n", dev->name,
  715. inw(ioaddr + EL3_STATUS));
  716. }
  717. spin_unlock(&lp->lock);
  718. return IRQ_HANDLED;
  719. }
  720. #ifdef CONFIG_NET_POLL_CONTROLLER
  721. /*
  722. * Polling receive - used by netconsole and other diagnostic tools
  723. * to allow network i/o with interrupts disabled.
  724. */
  725. static void el3_poll_controller(struct net_device *dev)
  726. {
  727. disable_irq(dev->irq);
  728. el3_interrupt(dev->irq, dev);
  729. enable_irq(dev->irq);
  730. }
  731. #endif
  732. static struct net_device_stats *
  733. el3_get_stats(struct net_device *dev)
  734. {
  735. struct el3_private *lp = netdev_priv(dev);
  736. unsigned long flags;
  737. /*
  738. * This is fast enough not to bother with disable IRQ
  739. * stuff.
  740. */
  741. spin_lock_irqsave(&lp->lock, flags);
  742. update_stats(dev);
  743. spin_unlock_irqrestore(&lp->lock, flags);
  744. return &dev->stats;
  745. }
  746. /* Update statistics. We change to register window 6, so this should be run
  747. single-threaded if the device is active. This is expected to be a rare
  748. operation, and it's simpler for the rest of the driver to assume that
  749. window 1 is always valid rather than use a special window-state variable.
  750. */
  751. static void update_stats(struct net_device *dev)
  752. {
  753. int ioaddr = dev->base_addr;
  754. if (el3_debug > 5)
  755. pr_debug(" Updating the statistics.\n");
  756. /* Turn off statistics updates while reading. */
  757. outw(StatsDisable, ioaddr + EL3_CMD);
  758. /* Switch to the stats window, and read everything. */
  759. EL3WINDOW(6);
  760. dev->stats.tx_carrier_errors += inb(ioaddr + 0);
  761. dev->stats.tx_heartbeat_errors += inb(ioaddr + 1);
  762. /* Multiple collisions. */ inb(ioaddr + 2);
  763. dev->stats.collisions += inb(ioaddr + 3);
  764. dev->stats.tx_window_errors += inb(ioaddr + 4);
  765. dev->stats.rx_fifo_errors += inb(ioaddr + 5);
  766. dev->stats.tx_packets += inb(ioaddr + 6);
  767. /* Rx packets */ inb(ioaddr + 7);
  768. /* Tx deferrals */ inb(ioaddr + 8);
  769. inw(ioaddr + 10); /* Total Rx and Tx octets. */
  770. inw(ioaddr + 12);
  771. /* Back to window 1, and turn statistics back on. */
  772. EL3WINDOW(1);
  773. outw(StatsEnable, ioaddr + EL3_CMD);
  774. }
  775. static int
  776. el3_rx(struct net_device *dev)
  777. {
  778. int ioaddr = dev->base_addr;
  779. short rx_status;
  780. if (el3_debug > 5)
  781. pr_debug(" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
  782. inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
  783. while ((rx_status = inw(ioaddr + RX_STATUS)) > 0) {
  784. if (rx_status & 0x4000) { /* Error, update stats. */
  785. short error = rx_status & 0x3800;
  786. outw(RxDiscard, ioaddr + EL3_CMD);
  787. dev->stats.rx_errors++;
  788. switch (error) {
  789. case 0x0000: dev->stats.rx_over_errors++; break;
  790. case 0x0800: dev->stats.rx_length_errors++; break;
  791. case 0x1000: dev->stats.rx_frame_errors++; break;
  792. case 0x1800: dev->stats.rx_length_errors++; break;
  793. case 0x2000: dev->stats.rx_frame_errors++; break;
  794. case 0x2800: dev->stats.rx_crc_errors++; break;
  795. }
  796. } else {
  797. short pkt_len = rx_status & 0x7ff;
  798. struct sk_buff *skb;
  799. skb = netdev_alloc_skb(dev, pkt_len + 5);
  800. if (el3_debug > 4)
  801. pr_debug("Receiving packet size %d status %4.4x.\n",
  802. pkt_len, rx_status);
  803. if (skb != NULL) {
  804. skb_reserve(skb, 2); /* Align IP on 16 byte */
  805. /* 'skb->data' points to the start of sk_buff data area. */
  806. insl(ioaddr + RX_FIFO, skb_put(skb,pkt_len),
  807. (pkt_len + 3) >> 2);
  808. outw(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
  809. skb->protocol = eth_type_trans(skb,dev);
  810. netif_rx(skb);
  811. dev->stats.rx_bytes += pkt_len;
  812. dev->stats.rx_packets++;
  813. continue;
  814. }
  815. outw(RxDiscard, ioaddr + EL3_CMD);
  816. dev->stats.rx_dropped++;
  817. if (el3_debug)
  818. pr_debug("%s: Couldn't allocate a sk_buff of size %d.\n",
  819. dev->name, pkt_len);
  820. }
  821. inw(ioaddr + EL3_STATUS); /* Delay. */
  822. while (inw(ioaddr + EL3_STATUS) & 0x1000)
  823. pr_debug(" Waiting for 3c509 to discard packet, status %x.\n",
  824. inw(ioaddr + EL3_STATUS) );
  825. }
  826. return 0;
  827. }
  828. /*
  829. * Set or clear the multicast filter for this adaptor.
  830. */
  831. static void
  832. set_multicast_list(struct net_device *dev)
  833. {
  834. unsigned long flags;
  835. struct el3_private *lp = netdev_priv(dev);
  836. int ioaddr = dev->base_addr;
  837. int mc_count = netdev_mc_count(dev);
  838. if (el3_debug > 1) {
  839. static int old;
  840. if (old != mc_count) {
  841. old = mc_count;
  842. pr_debug("%s: Setting Rx mode to %d addresses.\n",
  843. dev->name, mc_count);
  844. }
  845. }
  846. spin_lock_irqsave(&lp->lock, flags);
  847. if (dev->flags&IFF_PROMISC) {
  848. outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm,
  849. ioaddr + EL3_CMD);
  850. }
  851. else if (mc_count || (dev->flags&IFF_ALLMULTI)) {
  852. outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast, ioaddr + EL3_CMD);
  853. }
  854. else
  855. outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
  856. spin_unlock_irqrestore(&lp->lock, flags);
  857. }
  858. static int
  859. el3_close(struct net_device *dev)
  860. {
  861. int ioaddr = dev->base_addr;
  862. struct el3_private *lp = netdev_priv(dev);
  863. if (el3_debug > 2)
  864. pr_debug("%s: Shutting down ethercard.\n", dev->name);
  865. el3_down(dev);
  866. free_irq(dev->irq, dev);
  867. /* Switching back to window 0 disables the IRQ. */
  868. EL3WINDOW(0);
  869. if (lp->type != EL3_EISA) {
  870. /* But we explicitly zero the IRQ line select anyway. Don't do
  871. * it on EISA cards, it prevents the module from getting an
  872. * IRQ after unload+reload... */
  873. outw(0x0f00, ioaddr + WN0_IRQ);
  874. }
  875. return 0;
  876. }
  877. static int
  878. el3_link_ok(struct net_device *dev)
  879. {
  880. int ioaddr = dev->base_addr;
  881. u16 tmp;
  882. EL3WINDOW(4);
  883. tmp = inw(ioaddr + WN4_MEDIA);
  884. EL3WINDOW(1);
  885. return tmp & (1<<11);
  886. }
  887. static void
  888. el3_netdev_get_ecmd(struct net_device *dev, struct ethtool_link_ksettings *cmd)
  889. {
  890. u16 tmp;
  891. int ioaddr = dev->base_addr;
  892. u32 supported;
  893. EL3WINDOW(0);
  894. /* obtain current transceiver via WN4_MEDIA? */
  895. tmp = inw(ioaddr + WN0_ADDR_CONF);
  896. switch (tmp >> 14) {
  897. case 0:
  898. cmd->base.port = PORT_TP;
  899. break;
  900. case 1:
  901. cmd->base.port = PORT_AUI;
  902. break;
  903. case 3:
  904. cmd->base.port = PORT_BNC;
  905. default:
  906. break;
  907. }
  908. cmd->base.duplex = DUPLEX_HALF;
  909. supported = 0;
  910. tmp = inw(ioaddr + WN0_CONF_CTRL);
  911. if (tmp & (1<<13))
  912. supported |= SUPPORTED_AUI;
  913. if (tmp & (1<<12))
  914. supported |= SUPPORTED_BNC;
  915. if (tmp & (1<<9)) {
  916. supported |= SUPPORTED_TP | SUPPORTED_10baseT_Half |
  917. SUPPORTED_10baseT_Full; /* hmm... */
  918. EL3WINDOW(4);
  919. tmp = inw(ioaddr + WN4_NETDIAG);
  920. if (tmp & FD_ENABLE)
  921. cmd->base.duplex = DUPLEX_FULL;
  922. }
  923. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
  924. supported);
  925. cmd->base.speed = SPEED_10;
  926. EL3WINDOW(1);
  927. }
  928. static int
  929. el3_netdev_set_ecmd(struct net_device *dev,
  930. const struct ethtool_link_ksettings *cmd)
  931. {
  932. u16 tmp;
  933. int ioaddr = dev->base_addr;
  934. if (cmd->base.speed != SPEED_10)
  935. return -EINVAL;
  936. if ((cmd->base.duplex != DUPLEX_HALF) &&
  937. (cmd->base.duplex != DUPLEX_FULL))
  938. return -EINVAL;
  939. /* change XCVR type */
  940. EL3WINDOW(0);
  941. tmp = inw(ioaddr + WN0_ADDR_CONF);
  942. switch (cmd->base.port) {
  943. case PORT_TP:
  944. tmp &= ~(3<<14);
  945. dev->if_port = 0;
  946. break;
  947. case PORT_AUI:
  948. tmp |= (1<<14);
  949. dev->if_port = 1;
  950. break;
  951. case PORT_BNC:
  952. tmp |= (3<<14);
  953. dev->if_port = 3;
  954. break;
  955. default:
  956. return -EINVAL;
  957. }
  958. outw(tmp, ioaddr + WN0_ADDR_CONF);
  959. if (dev->if_port == 3) {
  960. /* fire up the DC-DC convertor if BNC gets enabled */
  961. tmp = inw(ioaddr + WN0_ADDR_CONF);
  962. if (tmp & (3 << 14)) {
  963. outw(StartCoax, ioaddr + EL3_CMD);
  964. udelay(800);
  965. } else
  966. return -EIO;
  967. }
  968. EL3WINDOW(4);
  969. tmp = inw(ioaddr + WN4_NETDIAG);
  970. if (cmd->base.duplex == DUPLEX_FULL)
  971. tmp |= FD_ENABLE;
  972. else
  973. tmp &= ~FD_ENABLE;
  974. outw(tmp, ioaddr + WN4_NETDIAG);
  975. EL3WINDOW(1);
  976. return 0;
  977. }
  978. static void el3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  979. {
  980. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  981. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  982. }
  983. static int el3_get_link_ksettings(struct net_device *dev,
  984. struct ethtool_link_ksettings *cmd)
  985. {
  986. struct el3_private *lp = netdev_priv(dev);
  987. spin_lock_irq(&lp->lock);
  988. el3_netdev_get_ecmd(dev, cmd);
  989. spin_unlock_irq(&lp->lock);
  990. return 0;
  991. }
  992. static int el3_set_link_ksettings(struct net_device *dev,
  993. const struct ethtool_link_ksettings *cmd)
  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, cmd);
  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_link = el3_get_link,
  1022. .get_msglevel = el3_get_msglevel,
  1023. .set_msglevel = el3_set_msglevel,
  1024. .get_link_ksettings = el3_get_link_ksettings,
  1025. .set_link_ksettings = el3_set_link_ksettings,
  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_hw_array(irq, int, irq, 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);