axnet_cs.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836
  1. /*======================================================================
  2. A PCMCIA ethernet driver for Asix AX88190-based cards
  3. The Asix AX88190 is a NS8390-derived chipset with a few nasty
  4. idiosyncracies that make it very inconvenient to support with a
  5. standard 8390 driver. This driver is based on pcnet_cs, with the
  6. tweaked 8390 code grafted on the end. Much of what I did was to
  7. clean up and update a similar driver supplied by Asix, which was
  8. adapted by William Lee, william@asix.com.tw.
  9. Copyright (C) 2001 David A. Hinds -- dahinds@users.sourceforge.net
  10. axnet_cs.c 1.28 2002/06/29 06:27:37
  11. The network driver code is based on Donald Becker's NE2000 code:
  12. Written 1992,1993 by Donald Becker.
  13. Copyright 1993 United States Government as represented by the
  14. Director, National Security Agency. This software may be used and
  15. distributed according to the terms of the GNU General Public License,
  16. incorporated herein by reference.
  17. Donald Becker may be reached at becker@scyld.com
  18. ======================================================================*/
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/slab.h>
  24. #include <linux/string.h>
  25. #include <linux/timer.h>
  26. #include <linux/delay.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/ethtool.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/crc32.h>
  31. #include "../8390.h"
  32. #include <pcmcia/cs_types.h>
  33. #include <pcmcia/cs.h>
  34. #include <pcmcia/cistpl.h>
  35. #include <pcmcia/ciscode.h>
  36. #include <pcmcia/ds.h>
  37. #include <pcmcia/cisreg.h>
  38. #include <asm/io.h>
  39. #include <asm/system.h>
  40. #include <asm/byteorder.h>
  41. #include <asm/uaccess.h>
  42. #define AXNET_CMD 0x00
  43. #define AXNET_DATAPORT 0x10 /* NatSemi-defined port window offset. */
  44. #define AXNET_RESET 0x1f /* Issue a read to reset, a write to clear. */
  45. #define AXNET_MII_EEP 0x14 /* Offset of MII access port */
  46. #define AXNET_TEST 0x15 /* Offset of TEST Register port */
  47. #define AXNET_GPIO 0x17 /* Offset of General Purpose Register Port */
  48. #define AXNET_START_PG 0x40 /* First page of TX buffer */
  49. #define AXNET_STOP_PG 0x80 /* Last page +1 of RX ring */
  50. #define AXNET_RDC_TIMEOUT 0x02 /* Max wait in jiffies for Tx RDC */
  51. #define IS_AX88190 0x0001
  52. #define IS_AX88790 0x0002
  53. /*====================================================================*/
  54. /* Module parameters */
  55. MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
  56. MODULE_DESCRIPTION("Asix AX88190 PCMCIA ethernet driver");
  57. MODULE_LICENSE("GPL");
  58. #ifdef PCMCIA_DEBUG
  59. #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
  60. INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
  61. #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
  62. static char *version =
  63. "axnet_cs.c 1.28 2002/06/29 06:27:37 (David Hinds)";
  64. #else
  65. #define DEBUG(n, args...)
  66. #endif
  67. /*====================================================================*/
  68. static int axnet_config(struct pcmcia_device *link);
  69. static void axnet_release(struct pcmcia_device *link);
  70. static int axnet_open(struct net_device *dev);
  71. static int axnet_close(struct net_device *dev);
  72. static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  73. static const struct ethtool_ops netdev_ethtool_ops;
  74. static irqreturn_t ei_irq_wrapper(int irq, void *dev_id);
  75. static void ei_watchdog(u_long arg);
  76. static void axnet_reset_8390(struct net_device *dev);
  77. static int mdio_read(kio_addr_t addr, int phy_id, int loc);
  78. static void mdio_write(kio_addr_t addr, int phy_id, int loc, int value);
  79. static void get_8390_hdr(struct net_device *,
  80. struct e8390_pkt_hdr *, int);
  81. static void block_input(struct net_device *dev, int count,
  82. struct sk_buff *skb, int ring_offset);
  83. static void block_output(struct net_device *dev, int count,
  84. const u_char *buf, const int start_page);
  85. static void axnet_detach(struct pcmcia_device *p_dev);
  86. static void axdev_setup(struct net_device *dev);
  87. static void AX88190_init(struct net_device *dev, int startp);
  88. static int ax_open(struct net_device *dev);
  89. static int ax_close(struct net_device *dev);
  90. static irqreturn_t ax_interrupt(int irq, void *dev_id);
  91. /*====================================================================*/
  92. typedef struct axnet_dev_t {
  93. struct pcmcia_device *p_dev;
  94. dev_node_t node;
  95. caddr_t base;
  96. struct timer_list watchdog;
  97. int stale, fast_poll;
  98. u_short link_status;
  99. u_char duplex_flag;
  100. int phy_id;
  101. int flags;
  102. } axnet_dev_t;
  103. static inline axnet_dev_t *PRIV(struct net_device *dev)
  104. {
  105. void *p = (char *)netdev_priv(dev) + sizeof(struct ei_device);
  106. return p;
  107. }
  108. /*======================================================================
  109. axnet_attach() creates an "instance" of the driver, allocating
  110. local data structures for one device. The device is registered
  111. with Card Services.
  112. ======================================================================*/
  113. static int axnet_probe(struct pcmcia_device *link)
  114. {
  115. axnet_dev_t *info;
  116. struct net_device *dev;
  117. DEBUG(0, "axnet_attach()\n");
  118. dev = alloc_netdev(sizeof(struct ei_device) + sizeof(axnet_dev_t),
  119. "eth%d", axdev_setup);
  120. if (!dev)
  121. return -ENOMEM;
  122. info = PRIV(dev);
  123. info->p_dev = link;
  124. link->priv = dev;
  125. link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
  126. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  127. link->conf.Attributes = CONF_ENABLE_IRQ;
  128. link->conf.IntType = INT_MEMORY_AND_IO;
  129. dev->open = &axnet_open;
  130. dev->stop = &axnet_close;
  131. dev->do_ioctl = &axnet_ioctl;
  132. SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
  133. return axnet_config(link);
  134. } /* axnet_attach */
  135. /*======================================================================
  136. This deletes a driver "instance". The device is de-registered
  137. with Card Services. If it has been released, all local data
  138. structures are freed. Otherwise, the structures will be freed
  139. when the device is released.
  140. ======================================================================*/
  141. static void axnet_detach(struct pcmcia_device *link)
  142. {
  143. struct net_device *dev = link->priv;
  144. DEBUG(0, "axnet_detach(0x%p)\n", link);
  145. if (link->dev_node)
  146. unregister_netdev(dev);
  147. axnet_release(link);
  148. free_netdev(dev);
  149. } /* axnet_detach */
  150. /*======================================================================
  151. This probes for a card's hardware address by reading the PROM.
  152. ======================================================================*/
  153. static int get_prom(struct pcmcia_device *link)
  154. {
  155. struct net_device *dev = link->priv;
  156. kio_addr_t ioaddr = dev->base_addr;
  157. int i, j;
  158. /* This is based on drivers/net/ne.c */
  159. struct {
  160. u_char value, offset;
  161. } program_seq[] = {
  162. {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
  163. {0x01, EN0_DCFG}, /* Set word-wide access. */
  164. {0x00, EN0_RCNTLO}, /* Clear the count regs. */
  165. {0x00, EN0_RCNTHI},
  166. {0x00, EN0_IMR}, /* Mask completion irq. */
  167. {0xFF, EN0_ISR},
  168. {E8390_RXOFF|0x40, EN0_RXCR}, /* 0x60 Set to monitor */
  169. {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
  170. {0x10, EN0_RCNTLO},
  171. {0x00, EN0_RCNTHI},
  172. {0x00, EN0_RSARLO}, /* DMA starting at 0x0400. */
  173. {0x04, EN0_RSARHI},
  174. {E8390_RREAD+E8390_START, E8390_CMD},
  175. };
  176. /* Not much of a test, but the alternatives are messy */
  177. if (link->conf.ConfigBase != 0x03c0)
  178. return 0;
  179. axnet_reset_8390(dev);
  180. mdelay(10);
  181. for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
  182. outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
  183. for (i = 0; i < 6; i += 2) {
  184. j = inw(ioaddr + AXNET_DATAPORT);
  185. dev->dev_addr[i] = j & 0xff;
  186. dev->dev_addr[i+1] = j >> 8;
  187. }
  188. return 1;
  189. } /* get_prom */
  190. /*======================================================================
  191. axnet_config() is scheduled to run after a CARD_INSERTION event
  192. is received, to configure the PCMCIA socket, and to make the
  193. ethernet device available to the system.
  194. ======================================================================*/
  195. #define CS_CHECK(fn, ret) \
  196. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  197. static int try_io_port(struct pcmcia_device *link)
  198. {
  199. int j, ret;
  200. if (link->io.NumPorts1 == 32) {
  201. link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  202. if (link->io.NumPorts2 > 0) {
  203. /* for master/slave multifunction cards */
  204. link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
  205. link->irq.Attributes =
  206. IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
  207. }
  208. } else {
  209. /* This should be two 16-port windows */
  210. link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  211. link->io.Attributes2 = IO_DATA_PATH_WIDTH_16;
  212. }
  213. if (link->io.BasePort1 == 0) {
  214. link->io.IOAddrLines = 16;
  215. for (j = 0; j < 0x400; j += 0x20) {
  216. link->io.BasePort1 = j ^ 0x300;
  217. link->io.BasePort2 = (j ^ 0x300) + 0x10;
  218. ret = pcmcia_request_io(link, &link->io);
  219. if (ret == CS_SUCCESS) return ret;
  220. }
  221. return ret;
  222. } else {
  223. return pcmcia_request_io(link, &link->io);
  224. }
  225. }
  226. static int axnet_config(struct pcmcia_device *link)
  227. {
  228. struct net_device *dev = link->priv;
  229. axnet_dev_t *info = PRIV(dev);
  230. tuple_t tuple;
  231. cisparse_t parse;
  232. int i, j, last_ret, last_fn;
  233. u_short buf[64];
  234. DEBUG(0, "axnet_config(0x%p)\n", link);
  235. tuple.Attributes = 0;
  236. tuple.TupleData = (cisdata_t *)buf;
  237. tuple.TupleDataMax = sizeof(buf);
  238. tuple.TupleOffset = 0;
  239. tuple.DesiredTuple = CISTPL_CONFIG;
  240. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
  241. CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
  242. CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
  243. link->conf.ConfigBase = parse.config.base;
  244. /* don't trust the CIS on this; Linksys got it wrong */
  245. link->conf.Present = 0x63;
  246. tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  247. tuple.Attributes = 0;
  248. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
  249. while (last_ret == CS_SUCCESS) {
  250. cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
  251. cistpl_io_t *io = &(parse.cftable_entry.io);
  252. if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
  253. pcmcia_parse_tuple(link, &tuple, &parse) != 0 ||
  254. cfg->index == 0 || cfg->io.nwin == 0)
  255. goto next_entry;
  256. link->conf.ConfigIndex = 0x05;
  257. /* For multifunction cards, by convention, we configure the
  258. network function with window 0, and serial with window 1 */
  259. if (io->nwin > 1) {
  260. i = (io->win[1].len > io->win[0].len);
  261. link->io.BasePort2 = io->win[1-i].base;
  262. link->io.NumPorts2 = io->win[1-i].len;
  263. } else {
  264. i = link->io.NumPorts2 = 0;
  265. }
  266. link->io.BasePort1 = io->win[i].base;
  267. link->io.NumPorts1 = io->win[i].len;
  268. link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
  269. if (link->io.NumPorts1 + link->io.NumPorts2 >= 32) {
  270. last_ret = try_io_port(link);
  271. if (last_ret == CS_SUCCESS) break;
  272. }
  273. next_entry:
  274. last_ret = pcmcia_get_next_tuple(link, &tuple);
  275. }
  276. if (last_ret != CS_SUCCESS) {
  277. cs_error(link, RequestIO, last_ret);
  278. goto failed;
  279. }
  280. CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
  281. if (link->io.NumPorts2 == 8) {
  282. link->conf.Attributes |= CONF_ENABLE_SPKR;
  283. link->conf.Status = CCSR_AUDIO_ENA;
  284. }
  285. CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
  286. dev->irq = link->irq.AssignedIRQ;
  287. dev->base_addr = link->io.BasePort1;
  288. if (!get_prom(link)) {
  289. printk(KERN_NOTICE "axnet_cs: this is not an AX88190 card!\n");
  290. printk(KERN_NOTICE "axnet_cs: use pcnet_cs instead.\n");
  291. goto failed;
  292. }
  293. ei_status.name = "AX88190";
  294. ei_status.word16 = 1;
  295. ei_status.tx_start_page = AXNET_START_PG;
  296. ei_status.rx_start_page = AXNET_START_PG + TX_PAGES;
  297. ei_status.stop_page = AXNET_STOP_PG;
  298. ei_status.reset_8390 = &axnet_reset_8390;
  299. ei_status.get_8390_hdr = &get_8390_hdr;
  300. ei_status.block_input = &block_input;
  301. ei_status.block_output = &block_output;
  302. if (inb(dev->base_addr + AXNET_TEST) != 0)
  303. info->flags |= IS_AX88790;
  304. else
  305. info->flags |= IS_AX88190;
  306. if (info->flags & IS_AX88790)
  307. outb(0x10, dev->base_addr + AXNET_GPIO); /* select Internal PHY */
  308. for (i = 0; i < 32; i++) {
  309. j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1);
  310. if ((j != 0) && (j != 0xffff)) break;
  311. }
  312. /* Maybe PHY is in power down mode. (PPD_SET = 1)
  313. Bit 2 of CCSR is active low. */
  314. if (i == 32) {
  315. conf_reg_t reg = { 0, CS_WRITE, CISREG_CCSR, 0x04 };
  316. pcmcia_access_configuration_register(link, &reg);
  317. for (i = 0; i < 32; i++) {
  318. j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1);
  319. if ((j != 0) && (j != 0xffff)) break;
  320. }
  321. }
  322. info->phy_id = (i < 32) ? i : -1;
  323. link->dev_node = &info->node;
  324. SET_NETDEV_DEV(dev, &handle_to_dev(link));
  325. if (register_netdev(dev) != 0) {
  326. printk(KERN_NOTICE "axnet_cs: register_netdev() failed\n");
  327. link->dev_node = NULL;
  328. goto failed;
  329. }
  330. strcpy(info->node.dev_name, dev->name);
  331. printk(KERN_INFO "%s: Asix AX88%d90: io %#3lx, irq %d, hw_addr ",
  332. dev->name, ((info->flags & IS_AX88790) ? 7 : 1),
  333. dev->base_addr, dev->irq);
  334. for (i = 0; i < 6; i++)
  335. printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
  336. if (info->phy_id != -1) {
  337. DEBUG(0, " MII transceiver at index %d, status %x.\n", info->phy_id, j);
  338. } else {
  339. printk(KERN_NOTICE " No MII transceivers found!\n");
  340. }
  341. return 0;
  342. cs_failed:
  343. cs_error(link, last_fn, last_ret);
  344. failed:
  345. axnet_release(link);
  346. return -ENODEV;
  347. } /* axnet_config */
  348. /*======================================================================
  349. After a card is removed, axnet_release() will unregister the net
  350. device, and release the PCMCIA configuration. If the device is
  351. still open, this will be postponed until it is closed.
  352. ======================================================================*/
  353. static void axnet_release(struct pcmcia_device *link)
  354. {
  355. pcmcia_disable_device(link);
  356. }
  357. static int axnet_suspend(struct pcmcia_device *link)
  358. {
  359. struct net_device *dev = link->priv;
  360. if (link->open)
  361. netif_device_detach(dev);
  362. return 0;
  363. }
  364. static int axnet_resume(struct pcmcia_device *link)
  365. {
  366. struct net_device *dev = link->priv;
  367. if (link->open) {
  368. axnet_reset_8390(dev);
  369. AX88190_init(dev, 1);
  370. netif_device_attach(dev);
  371. }
  372. return 0;
  373. }
  374. /*======================================================================
  375. MII interface support
  376. ======================================================================*/
  377. #define MDIO_SHIFT_CLK 0x01
  378. #define MDIO_DATA_WRITE0 0x00
  379. #define MDIO_DATA_WRITE1 0x08
  380. #define MDIO_DATA_READ 0x04
  381. #define MDIO_MASK 0x0f
  382. #define MDIO_ENB_IN 0x02
  383. static void mdio_sync(kio_addr_t addr)
  384. {
  385. int bits;
  386. for (bits = 0; bits < 32; bits++) {
  387. outb_p(MDIO_DATA_WRITE1, addr);
  388. outb_p(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
  389. }
  390. }
  391. static int mdio_read(kio_addr_t addr, int phy_id, int loc)
  392. {
  393. u_int cmd = (0xf6<<10)|(phy_id<<5)|loc;
  394. int i, retval = 0;
  395. mdio_sync(addr);
  396. for (i = 14; i >= 0; i--) {
  397. int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
  398. outb_p(dat, addr);
  399. outb_p(dat | MDIO_SHIFT_CLK, addr);
  400. }
  401. for (i = 19; i > 0; i--) {
  402. outb_p(MDIO_ENB_IN, addr);
  403. retval = (retval << 1) | ((inb_p(addr) & MDIO_DATA_READ) != 0);
  404. outb_p(MDIO_ENB_IN | MDIO_SHIFT_CLK, addr);
  405. }
  406. return (retval>>1) & 0xffff;
  407. }
  408. static void mdio_write(kio_addr_t addr, int phy_id, int loc, int value)
  409. {
  410. u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
  411. int i;
  412. mdio_sync(addr);
  413. for (i = 31; i >= 0; i--) {
  414. int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
  415. outb_p(dat, addr);
  416. outb_p(dat | MDIO_SHIFT_CLK, addr);
  417. }
  418. for (i = 1; i >= 0; i--) {
  419. outb_p(MDIO_ENB_IN, addr);
  420. outb_p(MDIO_ENB_IN | MDIO_SHIFT_CLK, addr);
  421. }
  422. }
  423. /*====================================================================*/
  424. static int axnet_open(struct net_device *dev)
  425. {
  426. axnet_dev_t *info = PRIV(dev);
  427. struct pcmcia_device *link = info->p_dev;
  428. DEBUG(2, "axnet_open('%s')\n", dev->name);
  429. if (!pcmcia_dev_present(link))
  430. return -ENODEV;
  431. link->open++;
  432. request_irq(dev->irq, ei_irq_wrapper, IRQF_SHARED, "axnet_cs", dev);
  433. info->link_status = 0x00;
  434. init_timer(&info->watchdog);
  435. info->watchdog.function = &ei_watchdog;
  436. info->watchdog.data = (u_long)dev;
  437. info->watchdog.expires = jiffies + HZ;
  438. add_timer(&info->watchdog);
  439. return ax_open(dev);
  440. } /* axnet_open */
  441. /*====================================================================*/
  442. static int axnet_close(struct net_device *dev)
  443. {
  444. axnet_dev_t *info = PRIV(dev);
  445. struct pcmcia_device *link = info->p_dev;
  446. DEBUG(2, "axnet_close('%s')\n", dev->name);
  447. ax_close(dev);
  448. free_irq(dev->irq, dev);
  449. link->open--;
  450. netif_stop_queue(dev);
  451. del_timer_sync(&info->watchdog);
  452. return 0;
  453. } /* axnet_close */
  454. /*======================================================================
  455. Hard reset the card. This used to pause for the same period that
  456. a 8390 reset command required, but that shouldn't be necessary.
  457. ======================================================================*/
  458. static void axnet_reset_8390(struct net_device *dev)
  459. {
  460. kio_addr_t nic_base = dev->base_addr;
  461. int i;
  462. ei_status.txing = ei_status.dmaing = 0;
  463. outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, nic_base + E8390_CMD);
  464. outb(inb(nic_base + AXNET_RESET), nic_base + AXNET_RESET);
  465. for (i = 0; i < 100; i++) {
  466. if ((inb_p(nic_base+EN0_ISR) & ENISR_RESET) != 0)
  467. break;
  468. udelay(100);
  469. }
  470. outb_p(ENISR_RESET, nic_base + EN0_ISR); /* Ack intr. */
  471. if (i == 100)
  472. printk(KERN_ERR "%s: axnet_reset_8390() did not complete.\n",
  473. dev->name);
  474. } /* axnet_reset_8390 */
  475. /*====================================================================*/
  476. static irqreturn_t ei_irq_wrapper(int irq, void *dev_id)
  477. {
  478. struct net_device *dev = dev_id;
  479. PRIV(dev)->stale = 0;
  480. return ax_interrupt(irq, dev_id);
  481. }
  482. static void ei_watchdog(u_long arg)
  483. {
  484. struct net_device *dev = (struct net_device *)(arg);
  485. axnet_dev_t *info = PRIV(dev);
  486. kio_addr_t nic_base = dev->base_addr;
  487. kio_addr_t mii_addr = nic_base + AXNET_MII_EEP;
  488. u_short link;
  489. if (!netif_device_present(dev)) goto reschedule;
  490. /* Check for pending interrupt with expired latency timer: with
  491. this, we can limp along even if the interrupt is blocked */
  492. if (info->stale++ && (inb_p(nic_base + EN0_ISR) & ENISR_ALL)) {
  493. if (!info->fast_poll)
  494. printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
  495. ei_irq_wrapper(dev->irq, dev);
  496. info->fast_poll = HZ;
  497. }
  498. if (info->fast_poll) {
  499. info->fast_poll--;
  500. info->watchdog.expires = jiffies + 1;
  501. add_timer(&info->watchdog);
  502. return;
  503. }
  504. if (info->phy_id < 0)
  505. goto reschedule;
  506. link = mdio_read(mii_addr, info->phy_id, 1);
  507. if (!link || (link == 0xffff)) {
  508. printk(KERN_INFO "%s: MII is missing!\n", dev->name);
  509. info->phy_id = -1;
  510. goto reschedule;
  511. }
  512. link &= 0x0004;
  513. if (link != info->link_status) {
  514. u_short p = mdio_read(mii_addr, info->phy_id, 5);
  515. printk(KERN_INFO "%s: %s link beat\n", dev->name,
  516. (link) ? "found" : "lost");
  517. if (link) {
  518. info->duplex_flag = (p & 0x0140) ? 0x80 : 0x00;
  519. if (p)
  520. printk(KERN_INFO "%s: autonegotiation complete: "
  521. "%sbaseT-%cD selected\n", dev->name,
  522. ((p & 0x0180) ? "100" : "10"),
  523. ((p & 0x0140) ? 'F' : 'H'));
  524. else
  525. printk(KERN_INFO "%s: link partner did not autonegotiate\n",
  526. dev->name);
  527. AX88190_init(dev, 1);
  528. }
  529. info->link_status = link;
  530. }
  531. reschedule:
  532. info->watchdog.expires = jiffies + HZ;
  533. add_timer(&info->watchdog);
  534. }
  535. static void netdev_get_drvinfo(struct net_device *dev,
  536. struct ethtool_drvinfo *info)
  537. {
  538. strcpy(info->driver, "axnet_cs");
  539. }
  540. static const struct ethtool_ops netdev_ethtool_ops = {
  541. .get_drvinfo = netdev_get_drvinfo,
  542. };
  543. /*====================================================================*/
  544. static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  545. {
  546. axnet_dev_t *info = PRIV(dev);
  547. u16 *data = (u16 *)&rq->ifr_ifru;
  548. kio_addr_t mii_addr = dev->base_addr + AXNET_MII_EEP;
  549. switch (cmd) {
  550. case SIOCGMIIPHY:
  551. data[0] = info->phy_id;
  552. case SIOCGMIIREG: /* Read MII PHY register. */
  553. data[3] = mdio_read(mii_addr, data[0], data[1] & 0x1f);
  554. return 0;
  555. case SIOCSMIIREG: /* Write MII PHY register. */
  556. if (!capable(CAP_NET_ADMIN))
  557. return -EPERM;
  558. mdio_write(mii_addr, data[0], data[1] & 0x1f, data[2]);
  559. return 0;
  560. }
  561. return -EOPNOTSUPP;
  562. }
  563. /*====================================================================*/
  564. static void get_8390_hdr(struct net_device *dev,
  565. struct e8390_pkt_hdr *hdr,
  566. int ring_page)
  567. {
  568. kio_addr_t nic_base = dev->base_addr;
  569. outb_p(0, nic_base + EN0_RSARLO); /* On page boundary */
  570. outb_p(ring_page, nic_base + EN0_RSARHI);
  571. outb_p(E8390_RREAD+E8390_START, nic_base + AXNET_CMD);
  572. insw(nic_base + AXNET_DATAPORT, hdr,
  573. sizeof(struct e8390_pkt_hdr)>>1);
  574. /* Fix for big endian systems */
  575. hdr->count = le16_to_cpu(hdr->count);
  576. }
  577. /*====================================================================*/
  578. static void block_input(struct net_device *dev, int count,
  579. struct sk_buff *skb, int ring_offset)
  580. {
  581. kio_addr_t nic_base = dev->base_addr;
  582. int xfer_count = count;
  583. char *buf = skb->data;
  584. #ifdef PCMCIA_DEBUG
  585. if ((ei_debug > 4) && (count != 4))
  586. printk(KERN_DEBUG "%s: [bi=%d]\n", dev->name, count+4);
  587. #endif
  588. outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
  589. outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
  590. outb_p(E8390_RREAD+E8390_START, nic_base + AXNET_CMD);
  591. insw(nic_base + AXNET_DATAPORT,buf,count>>1);
  592. if (count & 0x01)
  593. buf[count-1] = inb(nic_base + AXNET_DATAPORT), xfer_count++;
  594. }
  595. /*====================================================================*/
  596. static void block_output(struct net_device *dev, int count,
  597. const u_char *buf, const int start_page)
  598. {
  599. kio_addr_t nic_base = dev->base_addr;
  600. #ifdef PCMCIA_DEBUG
  601. if (ei_debug > 4)
  602. printk(KERN_DEBUG "%s: [bo=%d]\n", dev->name, count);
  603. #endif
  604. /* Round the count up for word writes. Do we need to do this?
  605. What effect will an odd byte count have on the 8390?
  606. I should check someday. */
  607. if (count & 0x01)
  608. count++;
  609. outb_p(0x00, nic_base + EN0_RSARLO);
  610. outb_p(start_page, nic_base + EN0_RSARHI);
  611. outb_p(E8390_RWRITE+E8390_START, nic_base + AXNET_CMD);
  612. outsw(nic_base + AXNET_DATAPORT, buf, count>>1);
  613. }
  614. static struct pcmcia_device_id axnet_ids[] = {
  615. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x016c, 0x0081),
  616. PCMCIA_DEVICE_MANF_CARD(0x018a, 0x0301),
  617. PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0301),
  618. PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0303),
  619. PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0309),
  620. PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1106),
  621. PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab),
  622. PCMCIA_DEVICE_MANF_CARD(0x021b, 0x0202),
  623. PCMCIA_DEVICE_PROD_ID12("AmbiCom,Inc.", "Fast Ethernet PC Card(AMB8110)", 0x49b020a7, 0x119cc9fc),
  624. PCMCIA_DEVICE_PROD_ID124("Fast Ethernet", "16-bit PC Card", "AX88190", 0xb4be14e3, 0x9a12eb6a, 0xab9be5ef),
  625. PCMCIA_DEVICE_PROD_ID12("ASIX", "AX88190", 0x0959823b, 0xab9be5ef),
  626. PCMCIA_DEVICE_PROD_ID12("Billionton", "LNA-100B", 0x552ab682, 0xbc3b87e1),
  627. PCMCIA_DEVICE_PROD_ID12("CHEETAH ETHERCARD", "EN2228", 0x00fa7bc8, 0x00e990cc),
  628. PCMCIA_DEVICE_PROD_ID12("CNet", "CNF301", 0xbc477dde, 0x78c5f40b),
  629. PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FEther PCC-TXD", 0x5261440f, 0x436768c5),
  630. PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FEtherII PCC-TXD", 0x5261440f, 0x730df72e),
  631. PCMCIA_DEVICE_PROD_ID12("Dynalink", "L100C16", 0x55632fd5, 0x66bc2a90),
  632. PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100 V3)", 0x0733cc81, 0x232019a8),
  633. PCMCIA_DEVICE_PROD_ID12("MELCO", "LPC3-TX", 0x481e0094, 0xf91af609),
  634. PCMCIA_DEVICE_PROD_ID12("PCMCIA", "100BASE", 0x281f1c5d, 0x7c2add04),
  635. PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FastEtherCard", 0x281f1c5d, 0x7ef26116),
  636. PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FEP501", 0x281f1c5d, 0x2e272058),
  637. PCMCIA_DEVICE_PROD_ID14("Network Everywhere", "AX88190", 0x820a67b6, 0xab9be5ef),
  638. PCMCIA_DEVICE_NULL,
  639. };
  640. MODULE_DEVICE_TABLE(pcmcia, axnet_ids);
  641. static struct pcmcia_driver axnet_cs_driver = {
  642. .owner = THIS_MODULE,
  643. .drv = {
  644. .name = "axnet_cs",
  645. },
  646. .probe = axnet_probe,
  647. .remove = axnet_detach,
  648. .id_table = axnet_ids,
  649. .suspend = axnet_suspend,
  650. .resume = axnet_resume,
  651. };
  652. static int __init init_axnet_cs(void)
  653. {
  654. return pcmcia_register_driver(&axnet_cs_driver);
  655. }
  656. static void __exit exit_axnet_cs(void)
  657. {
  658. pcmcia_unregister_driver(&axnet_cs_driver);
  659. }
  660. module_init(init_axnet_cs);
  661. module_exit(exit_axnet_cs);
  662. /*====================================================================*/
  663. /* 8390.c: A general NS8390 ethernet driver core for linux. */
  664. /*
  665. Written 1992-94 by Donald Becker.
  666. Copyright 1993 United States Government as represented by the
  667. Director, National Security Agency.
  668. This software may be used and distributed according to the terms
  669. of the GNU General Public License, incorporated herein by reference.
  670. The author may be reached as becker@scyld.com, or C/O
  671. Scyld Computing Corporation
  672. 410 Severn Ave., Suite 210
  673. Annapolis MD 21403
  674. This is the chip-specific code for many 8390-based ethernet adaptors.
  675. This is not a complete driver, it must be combined with board-specific
  676. code such as ne.c, wd.c, 3c503.c, etc.
  677. Seeing how at least eight drivers use this code, (not counting the
  678. PCMCIA ones either) it is easy to break some card by what seems like
  679. a simple innocent change. Please contact me or Donald if you think
  680. you have found something that needs changing. -- PG
  681. Changelog:
  682. Paul Gortmaker : remove set_bit lock, other cleanups.
  683. Paul Gortmaker : add ei_get_8390_hdr() so we can pass skb's to
  684. ei_block_input() for eth_io_copy_and_sum().
  685. Paul Gortmaker : exchange static int ei_pingpong for a #define,
  686. also add better Tx error handling.
  687. Paul Gortmaker : rewrite Rx overrun handling as per NS specs.
  688. Alexey Kuznetsov : use the 8390's six bit hash multicast filter.
  689. Paul Gortmaker : tweak ANK's above multicast changes a bit.
  690. Paul Gortmaker : update packet statistics for v2.1.x
  691. Alan Cox : support arbitary stupid port mappings on the
  692. 68K Macintosh. Support >16bit I/O spaces
  693. Paul Gortmaker : add kmod support for auto-loading of the 8390
  694. module by all drivers that require it.
  695. Alan Cox : Spinlocking work, added 'BUG_83C690'
  696. Paul Gortmaker : Separate out Tx timeout code from Tx path.
  697. Sources:
  698. The National Semiconductor LAN Databook, and the 3Com 3c503 databook.
  699. */
  700. static const char *version_8390 =
  701. "8390.c:v1.10cvs 9/23/94 Donald Becker (becker@scyld.com)\n";
  702. #include <linux/bitops.h>
  703. #include <asm/irq.h>
  704. #include <linux/fcntl.h>
  705. #include <linux/in.h>
  706. #include <linux/interrupt.h>
  707. #include <linux/etherdevice.h>
  708. #define BUG_83C690
  709. /* These are the operational function interfaces to board-specific
  710. routines.
  711. void reset_8390(struct net_device *dev)
  712. Resets the board associated with DEV, including a hardware reset of
  713. the 8390. This is only called when there is a transmit timeout, and
  714. it is always followed by 8390_init().
  715. void block_output(struct net_device *dev, int count, const unsigned char *buf,
  716. int start_page)
  717. Write the COUNT bytes of BUF to the packet buffer at START_PAGE. The
  718. "page" value uses the 8390's 256-byte pages.
  719. void get_8390_hdr(struct net_device *dev, struct e8390_hdr *hdr, int ring_page)
  720. Read the 4 byte, page aligned 8390 header. *If* there is a
  721. subsequent read, it will be of the rest of the packet.
  722. void block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
  723. Read COUNT bytes from the packet buffer into the skb data area. Start
  724. reading from RING_OFFSET, the address as the 8390 sees it. This will always
  725. follow the read of the 8390 header.
  726. */
  727. #define ei_reset_8390 (ei_local->reset_8390)
  728. #define ei_block_output (ei_local->block_output)
  729. #define ei_block_input (ei_local->block_input)
  730. #define ei_get_8390_hdr (ei_local->get_8390_hdr)
  731. /* use 0 for production, 1 for verification, >2 for debug */
  732. #ifndef ei_debug
  733. int ei_debug = 1;
  734. #endif
  735. /* Index to functions. */
  736. static void ei_tx_intr(struct net_device *dev);
  737. static void ei_tx_err(struct net_device *dev);
  738. static void ei_tx_timeout(struct net_device *dev);
  739. static void ei_receive(struct net_device *dev);
  740. static void ei_rx_overrun(struct net_device *dev);
  741. /* Routines generic to NS8390-based boards. */
  742. static void NS8390_trigger_send(struct net_device *dev, unsigned int length,
  743. int start_page);
  744. static void set_multicast_list(struct net_device *dev);
  745. static void do_set_multicast_list(struct net_device *dev);
  746. /*
  747. * SMP and the 8390 setup.
  748. *
  749. * The 8390 isnt exactly designed to be multithreaded on RX/TX. There is
  750. * a page register that controls bank and packet buffer access. We guard
  751. * this with ei_local->page_lock. Nobody should assume or set the page other
  752. * than zero when the lock is not held. Lock holders must restore page 0
  753. * before unlocking. Even pure readers must take the lock to protect in
  754. * page 0.
  755. *
  756. * To make life difficult the chip can also be very slow. We therefore can't
  757. * just use spinlocks. For the longer lockups we disable the irq the device
  758. * sits on and hold the lock. We must hold the lock because there is a dual
  759. * processor case other than interrupts (get stats/set multicast list in
  760. * parallel with each other and transmit).
  761. *
  762. * Note: in theory we can just disable the irq on the card _but_ there is
  763. * a latency on SMP irq delivery. So we can easily go "disable irq" "sync irqs"
  764. * enter lock, take the queued irq. So we waddle instead of flying.
  765. *
  766. * Finally by special arrangement for the purpose of being generally
  767. * annoying the transmit function is called bh atomic. That places
  768. * restrictions on the user context callers as disable_irq won't save
  769. * them.
  770. */
  771. /**
  772. * ax_open - Open/initialize the board.
  773. * @dev: network device to initialize
  774. *
  775. * This routine goes all-out, setting everything
  776. * up anew at each open, even though many of these registers should only
  777. * need to be set once at boot.
  778. */
  779. static int ax_open(struct net_device *dev)
  780. {
  781. unsigned long flags;
  782. struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
  783. #ifdef HAVE_TX_TIMEOUT
  784. /* The card I/O part of the driver (e.g. 3c503) can hook a Tx timeout
  785. wrapper that does e.g. media check & then calls ei_tx_timeout. */
  786. if (dev->tx_timeout == NULL)
  787. dev->tx_timeout = ei_tx_timeout;
  788. if (dev->watchdog_timeo <= 0)
  789. dev->watchdog_timeo = TX_TIMEOUT;
  790. #endif
  791. /*
  792. * Grab the page lock so we own the register set, then call
  793. * the init function.
  794. */
  795. spin_lock_irqsave(&ei_local->page_lock, flags);
  796. AX88190_init(dev, 1);
  797. /* Set the flag before we drop the lock, That way the IRQ arrives
  798. after its set and we get no silly warnings */
  799. netif_start_queue(dev);
  800. spin_unlock_irqrestore(&ei_local->page_lock, flags);
  801. ei_local->irqlock = 0;
  802. return 0;
  803. }
  804. #define dev_lock(dev) (((struct ei_device *)netdev_priv(dev))->page_lock)
  805. /**
  806. * ax_close - shut down network device
  807. * @dev: network device to close
  808. *
  809. * Opposite of ax_open(). Only used when "ifconfig <devname> down" is done.
  810. */
  811. int ax_close(struct net_device *dev)
  812. {
  813. unsigned long flags;
  814. /*
  815. * Hold the page lock during close
  816. */
  817. spin_lock_irqsave(&dev_lock(dev), flags);
  818. AX88190_init(dev, 0);
  819. spin_unlock_irqrestore(&dev_lock(dev), flags);
  820. netif_stop_queue(dev);
  821. return 0;
  822. }
  823. /**
  824. * ei_tx_timeout - handle transmit time out condition
  825. * @dev: network device which has apparently fallen asleep
  826. *
  827. * Called by kernel when device never acknowledges a transmit has
  828. * completed (or failed) - i.e. never posted a Tx related interrupt.
  829. */
  830. void ei_tx_timeout(struct net_device *dev)
  831. {
  832. long e8390_base = dev->base_addr;
  833. struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
  834. int txsr, isr, tickssofar = jiffies - dev->trans_start;
  835. unsigned long flags;
  836. ei_local->stat.tx_errors++;
  837. spin_lock_irqsave(&ei_local->page_lock, flags);
  838. txsr = inb(e8390_base+EN0_TSR);
  839. isr = inb(e8390_base+EN0_ISR);
  840. spin_unlock_irqrestore(&ei_local->page_lock, flags);
  841. printk(KERN_DEBUG "%s: Tx timed out, %s TSR=%#2x, ISR=%#2x, t=%d.\n",
  842. dev->name, (txsr & ENTSR_ABT) ? "excess collisions." :
  843. (isr) ? "lost interrupt?" : "cable problem?", txsr, isr, tickssofar);
  844. if (!isr && !ei_local->stat.tx_packets)
  845. {
  846. /* The 8390 probably hasn't gotten on the cable yet. */
  847. ei_local->interface_num ^= 1; /* Try a different xcvr. */
  848. }
  849. /* Ugly but a reset can be slow, yet must be protected */
  850. disable_irq_nosync(dev->irq);
  851. spin_lock(&ei_local->page_lock);
  852. /* Try to restart the card. Perhaps the user has fixed something. */
  853. ei_reset_8390(dev);
  854. AX88190_init(dev, 1);
  855. spin_unlock(&ei_local->page_lock);
  856. enable_irq(dev->irq);
  857. netif_wake_queue(dev);
  858. }
  859. /**
  860. * ei_start_xmit - begin packet transmission
  861. * @skb: packet to be sent
  862. * @dev: network device to which packet is sent
  863. *
  864. * Sends a packet to an 8390 network device.
  865. */
  866. static int ei_start_xmit(struct sk_buff *skb, struct net_device *dev)
  867. {
  868. long e8390_base = dev->base_addr;
  869. struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
  870. int length, send_length, output_page;
  871. unsigned long flags;
  872. u8 packet[ETH_ZLEN];
  873. netif_stop_queue(dev);
  874. length = skb->len;
  875. /* Mask interrupts from the ethercard.
  876. SMP: We have to grab the lock here otherwise the IRQ handler
  877. on another CPU can flip window and race the IRQ mask set. We end
  878. up trashing the mcast filter not disabling irqs if we don't lock */
  879. spin_lock_irqsave(&ei_local->page_lock, flags);
  880. outb_p(0x00, e8390_base + EN0_IMR);
  881. spin_unlock_irqrestore(&ei_local->page_lock, flags);
  882. /*
  883. * Slow phase with lock held.
  884. */
  885. disable_irq_nosync(dev->irq);
  886. spin_lock(&ei_local->page_lock);
  887. ei_local->irqlock = 1;
  888. send_length = ETH_ZLEN < length ? length : ETH_ZLEN;
  889. /*
  890. * We have two Tx slots available for use. Find the first free
  891. * slot, and then perform some sanity checks. With two Tx bufs,
  892. * you get very close to transmitting back-to-back packets. With
  893. * only one Tx buf, the transmitter sits idle while you reload the
  894. * card, leaving a substantial gap between each transmitted packet.
  895. */
  896. if (ei_local->tx1 == 0)
  897. {
  898. output_page = ei_local->tx_start_page;
  899. ei_local->tx1 = send_length;
  900. if (ei_debug && ei_local->tx2 > 0)
  901. printk(KERN_DEBUG "%s: idle transmitter tx2=%d, lasttx=%d, txing=%d.\n",
  902. dev->name, ei_local->tx2, ei_local->lasttx, ei_local->txing);
  903. }
  904. else if (ei_local->tx2 == 0)
  905. {
  906. output_page = ei_local->tx_start_page + TX_PAGES/2;
  907. ei_local->tx2 = send_length;
  908. if (ei_debug && ei_local->tx1 > 0)
  909. printk(KERN_DEBUG "%s: idle transmitter, tx1=%d, lasttx=%d, txing=%d.\n",
  910. dev->name, ei_local->tx1, ei_local->lasttx, ei_local->txing);
  911. }
  912. else
  913. { /* We should never get here. */
  914. if (ei_debug)
  915. printk(KERN_DEBUG "%s: No Tx buffers free! tx1=%d tx2=%d last=%d\n",
  916. dev->name, ei_local->tx1, ei_local->tx2, ei_local->lasttx);
  917. ei_local->irqlock = 0;
  918. netif_stop_queue(dev);
  919. outb_p(ENISR_ALL, e8390_base + EN0_IMR);
  920. spin_unlock(&ei_local->page_lock);
  921. enable_irq(dev->irq);
  922. ei_local->stat.tx_errors++;
  923. return 1;
  924. }
  925. /*
  926. * Okay, now upload the packet and trigger a send if the transmitter
  927. * isn't already sending. If it is busy, the interrupt handler will
  928. * trigger the send later, upon receiving a Tx done interrupt.
  929. */
  930. if (length == skb->len)
  931. ei_block_output(dev, length, skb->data, output_page);
  932. else {
  933. memset(packet, 0, ETH_ZLEN);
  934. memcpy(packet, skb->data, skb->len);
  935. ei_block_output(dev, length, packet, output_page);
  936. }
  937. if (! ei_local->txing)
  938. {
  939. ei_local->txing = 1;
  940. NS8390_trigger_send(dev, send_length, output_page);
  941. dev->trans_start = jiffies;
  942. if (output_page == ei_local->tx_start_page)
  943. {
  944. ei_local->tx1 = -1;
  945. ei_local->lasttx = -1;
  946. }
  947. else
  948. {
  949. ei_local->tx2 = -1;
  950. ei_local->lasttx = -2;
  951. }
  952. }
  953. else ei_local->txqueue++;
  954. if (ei_local->tx1 && ei_local->tx2)
  955. netif_stop_queue(dev);
  956. else
  957. netif_start_queue(dev);
  958. /* Turn 8390 interrupts back on. */
  959. ei_local->irqlock = 0;
  960. outb_p(ENISR_ALL, e8390_base + EN0_IMR);
  961. spin_unlock(&ei_local->page_lock);
  962. enable_irq(dev->irq);
  963. dev_kfree_skb (skb);
  964. ei_local->stat.tx_bytes += send_length;
  965. return 0;
  966. }
  967. /**
  968. * ax_interrupt - handle the interrupts from an 8390
  969. * @irq: interrupt number
  970. * @dev_id: a pointer to the net_device
  971. * @regs: unused
  972. *
  973. * Handle the ether interface interrupts. We pull packets from
  974. * the 8390 via the card specific functions and fire them at the networking
  975. * stack. We also handle transmit completions and wake the transmit path if
  976. * necessary. We also update the counters and do other housekeeping as
  977. * needed.
  978. */
  979. static irqreturn_t ax_interrupt(int irq, void *dev_id)
  980. {
  981. struct net_device *dev = dev_id;
  982. long e8390_base;
  983. int interrupts, nr_serviced = 0, i;
  984. struct ei_device *ei_local;
  985. int handled = 0;
  986. e8390_base = dev->base_addr;
  987. ei_local = netdev_priv(dev);
  988. /*
  989. * Protect the irq test too.
  990. */
  991. spin_lock(&ei_local->page_lock);
  992. if (ei_local->irqlock)
  993. {
  994. #if 1 /* This might just be an interrupt for a PCI device sharing this line */
  995. /* The "irqlock" check is only for testing. */
  996. printk(ei_local->irqlock
  997. ? "%s: Interrupted while interrupts are masked! isr=%#2x imr=%#2x.\n"
  998. : "%s: Reentering the interrupt handler! isr=%#2x imr=%#2x.\n",
  999. dev->name, inb_p(e8390_base + EN0_ISR),
  1000. inb_p(e8390_base + EN0_IMR));
  1001. #endif
  1002. spin_unlock(&ei_local->page_lock);
  1003. return IRQ_NONE;
  1004. }
  1005. if (ei_debug > 3)
  1006. printk(KERN_DEBUG "%s: interrupt(isr=%#2.2x).\n", dev->name,
  1007. inb_p(e8390_base + EN0_ISR));
  1008. outb_p(0x00, e8390_base + EN0_ISR);
  1009. ei_local->irqlock = 1;
  1010. /* !!Assumption!! -- we stay in page 0. Don't break this. */
  1011. while ((interrupts = inb_p(e8390_base + EN0_ISR)) != 0
  1012. && ++nr_serviced < MAX_SERVICE)
  1013. {
  1014. if (!netif_running(dev) || (interrupts == 0xff)) {
  1015. if (ei_debug > 1)
  1016. printk(KERN_WARNING "%s: interrupt from stopped card\n", dev->name);
  1017. outb_p(interrupts, e8390_base + EN0_ISR);
  1018. interrupts = 0;
  1019. break;
  1020. }
  1021. handled = 1;
  1022. /* AX88190 bug fix. */
  1023. outb_p(interrupts, e8390_base + EN0_ISR);
  1024. for (i = 0; i < 10; i++) {
  1025. if (!(inb(e8390_base + EN0_ISR) & interrupts))
  1026. break;
  1027. outb_p(0, e8390_base + EN0_ISR);
  1028. outb_p(interrupts, e8390_base + EN0_ISR);
  1029. }
  1030. if (interrupts & ENISR_OVER)
  1031. ei_rx_overrun(dev);
  1032. else if (interrupts & (ENISR_RX+ENISR_RX_ERR))
  1033. {
  1034. /* Got a good (?) packet. */
  1035. ei_receive(dev);
  1036. }
  1037. /* Push the next to-transmit packet through. */
  1038. if (interrupts & ENISR_TX)
  1039. ei_tx_intr(dev);
  1040. else if (interrupts & ENISR_TX_ERR)
  1041. ei_tx_err(dev);
  1042. if (interrupts & ENISR_COUNTERS)
  1043. {
  1044. ei_local->stat.rx_frame_errors += inb_p(e8390_base + EN0_COUNTER0);
  1045. ei_local->stat.rx_crc_errors += inb_p(e8390_base + EN0_COUNTER1);
  1046. ei_local->stat.rx_missed_errors+= inb_p(e8390_base + EN0_COUNTER2);
  1047. }
  1048. }
  1049. if (interrupts && ei_debug)
  1050. {
  1051. handled = 1;
  1052. if (nr_serviced >= MAX_SERVICE)
  1053. {
  1054. /* 0xFF is valid for a card removal */
  1055. if(interrupts!=0xFF)
  1056. printk(KERN_WARNING "%s: Too much work at interrupt, status %#2.2x\n",
  1057. dev->name, interrupts);
  1058. outb_p(ENISR_ALL, e8390_base + EN0_ISR); /* Ack. most intrs. */
  1059. } else {
  1060. printk(KERN_WARNING "%s: unknown interrupt %#2x\n", dev->name, interrupts);
  1061. outb_p(0xff, e8390_base + EN0_ISR); /* Ack. all intrs. */
  1062. }
  1063. }
  1064. /* Turn 8390 interrupts back on. */
  1065. ei_local->irqlock = 0;
  1066. outb_p(ENISR_ALL, e8390_base + EN0_IMR);
  1067. spin_unlock(&ei_local->page_lock);
  1068. return IRQ_RETVAL(handled);
  1069. }
  1070. /**
  1071. * ei_tx_err - handle transmitter error
  1072. * @dev: network device which threw the exception
  1073. *
  1074. * A transmitter error has happened. Most likely excess collisions (which
  1075. * is a fairly normal condition). If the error is one where the Tx will
  1076. * have been aborted, we try and send another one right away, instead of
  1077. * letting the failed packet sit and collect dust in the Tx buffer. This
  1078. * is a much better solution as it avoids kernel based Tx timeouts, and
  1079. * an unnecessary card reset.
  1080. *
  1081. * Called with lock held.
  1082. */
  1083. static void ei_tx_err(struct net_device *dev)
  1084. {
  1085. long e8390_base = dev->base_addr;
  1086. struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
  1087. unsigned char txsr = inb_p(e8390_base+EN0_TSR);
  1088. unsigned char tx_was_aborted = txsr & (ENTSR_ABT+ENTSR_FU);
  1089. #ifdef VERBOSE_ERROR_DUMP
  1090. printk(KERN_DEBUG "%s: transmitter error (%#2x): ", dev->name, txsr);
  1091. if (txsr & ENTSR_ABT)
  1092. printk("excess-collisions ");
  1093. if (txsr & ENTSR_ND)
  1094. printk("non-deferral ");
  1095. if (txsr & ENTSR_CRS)
  1096. printk("lost-carrier ");
  1097. if (txsr & ENTSR_FU)
  1098. printk("FIFO-underrun ");
  1099. if (txsr & ENTSR_CDH)
  1100. printk("lost-heartbeat ");
  1101. printk("\n");
  1102. #endif
  1103. if (tx_was_aborted)
  1104. ei_tx_intr(dev);
  1105. else
  1106. {
  1107. ei_local->stat.tx_errors++;
  1108. if (txsr & ENTSR_CRS) ei_local->stat.tx_carrier_errors++;
  1109. if (txsr & ENTSR_CDH) ei_local->stat.tx_heartbeat_errors++;
  1110. if (txsr & ENTSR_OWC) ei_local->stat.tx_window_errors++;
  1111. }
  1112. }
  1113. /**
  1114. * ei_tx_intr - transmit interrupt handler
  1115. * @dev: network device for which tx intr is handled
  1116. *
  1117. * We have finished a transmit: check for errors and then trigger the next
  1118. * packet to be sent. Called with lock held.
  1119. */
  1120. static void ei_tx_intr(struct net_device *dev)
  1121. {
  1122. long e8390_base = dev->base_addr;
  1123. struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
  1124. int status = inb(e8390_base + EN0_TSR);
  1125. /*
  1126. * There are two Tx buffers, see which one finished, and trigger
  1127. * the send of another one if it exists.
  1128. */
  1129. ei_local->txqueue--;
  1130. if (ei_local->tx1 < 0)
  1131. {
  1132. if (ei_local->lasttx != 1 && ei_local->lasttx != -1)
  1133. printk(KERN_ERR "%s: bogus last_tx_buffer %d, tx1=%d.\n",
  1134. ei_local->name, ei_local->lasttx, ei_local->tx1);
  1135. ei_local->tx1 = 0;
  1136. if (ei_local->tx2 > 0)
  1137. {
  1138. ei_local->txing = 1;
  1139. NS8390_trigger_send(dev, ei_local->tx2, ei_local->tx_start_page + 6);
  1140. dev->trans_start = jiffies;
  1141. ei_local->tx2 = -1,
  1142. ei_local->lasttx = 2;
  1143. }
  1144. else ei_local->lasttx = 20, ei_local->txing = 0;
  1145. }
  1146. else if (ei_local->tx2 < 0)
  1147. {
  1148. if (ei_local->lasttx != 2 && ei_local->lasttx != -2)
  1149. printk("%s: bogus last_tx_buffer %d, tx2=%d.\n",
  1150. ei_local->name, ei_local->lasttx, ei_local->tx2);
  1151. ei_local->tx2 = 0;
  1152. if (ei_local->tx1 > 0)
  1153. {
  1154. ei_local->txing = 1;
  1155. NS8390_trigger_send(dev, ei_local->tx1, ei_local->tx_start_page);
  1156. dev->trans_start = jiffies;
  1157. ei_local->tx1 = -1;
  1158. ei_local->lasttx = 1;
  1159. }
  1160. else
  1161. ei_local->lasttx = 10, ei_local->txing = 0;
  1162. }
  1163. // else printk(KERN_WARNING "%s: unexpected TX-done interrupt, lasttx=%d.\n",
  1164. // dev->name, ei_local->lasttx);
  1165. /* Minimize Tx latency: update the statistics after we restart TXing. */
  1166. if (status & ENTSR_COL)
  1167. ei_local->stat.collisions++;
  1168. if (status & ENTSR_PTX)
  1169. ei_local->stat.tx_packets++;
  1170. else
  1171. {
  1172. ei_local->stat.tx_errors++;
  1173. if (status & ENTSR_ABT)
  1174. {
  1175. ei_local->stat.tx_aborted_errors++;
  1176. ei_local->stat.collisions += 16;
  1177. }
  1178. if (status & ENTSR_CRS)
  1179. ei_local->stat.tx_carrier_errors++;
  1180. if (status & ENTSR_FU)
  1181. ei_local->stat.tx_fifo_errors++;
  1182. if (status & ENTSR_CDH)
  1183. ei_local->stat.tx_heartbeat_errors++;
  1184. if (status & ENTSR_OWC)
  1185. ei_local->stat.tx_window_errors++;
  1186. }
  1187. netif_wake_queue(dev);
  1188. }
  1189. /**
  1190. * ei_receive - receive some packets
  1191. * @dev: network device with which receive will be run
  1192. *
  1193. * We have a good packet(s), get it/them out of the buffers.
  1194. * Called with lock held.
  1195. */
  1196. static void ei_receive(struct net_device *dev)
  1197. {
  1198. long e8390_base = dev->base_addr;
  1199. struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
  1200. unsigned char rxing_page, this_frame, next_frame;
  1201. unsigned short current_offset;
  1202. int rx_pkt_count = 0;
  1203. struct e8390_pkt_hdr rx_frame;
  1204. while (++rx_pkt_count < 10)
  1205. {
  1206. int pkt_len, pkt_stat;
  1207. /* Get the rx page (incoming packet pointer). */
  1208. rxing_page = inb_p(e8390_base + EN1_CURPAG -1);
  1209. /* Remove one frame from the ring. Boundary is always a page behind. */
  1210. this_frame = inb_p(e8390_base + EN0_BOUNDARY) + 1;
  1211. if (this_frame >= ei_local->stop_page)
  1212. this_frame = ei_local->rx_start_page;
  1213. /* Someday we'll omit the previous, iff we never get this message.
  1214. (There is at least one clone claimed to have a problem.)
  1215. Keep quiet if it looks like a card removal. One problem here
  1216. is that some clones crash in roughly the same way.
  1217. */
  1218. if (ei_debug > 0 && this_frame != ei_local->current_page && (this_frame!=0x0 || rxing_page!=0xFF))
  1219. printk(KERN_ERR "%s: mismatched read page pointers %2x vs %2x.\n",
  1220. dev->name, this_frame, ei_local->current_page);
  1221. if (this_frame == rxing_page) /* Read all the frames? */
  1222. break; /* Done for now */
  1223. current_offset = this_frame << 8;
  1224. ei_get_8390_hdr(dev, &rx_frame, this_frame);
  1225. pkt_len = rx_frame.count - sizeof(struct e8390_pkt_hdr);
  1226. pkt_stat = rx_frame.status;
  1227. next_frame = this_frame + 1 + ((pkt_len+4)>>8);
  1228. if (pkt_len < 60 || pkt_len > 1518)
  1229. {
  1230. if (ei_debug)
  1231. printk(KERN_DEBUG "%s: bogus packet size: %d, status=%#2x nxpg=%#2x.\n",
  1232. dev->name, rx_frame.count, rx_frame.status,
  1233. rx_frame.next);
  1234. ei_local->stat.rx_errors++;
  1235. ei_local->stat.rx_length_errors++;
  1236. }
  1237. else if ((pkt_stat & 0x0F) == ENRSR_RXOK)
  1238. {
  1239. struct sk_buff *skb;
  1240. skb = dev_alloc_skb(pkt_len+2);
  1241. if (skb == NULL)
  1242. {
  1243. if (ei_debug > 1)
  1244. printk(KERN_DEBUG "%s: Couldn't allocate a sk_buff of size %d.\n",
  1245. dev->name, pkt_len);
  1246. ei_local->stat.rx_dropped++;
  1247. break;
  1248. }
  1249. else
  1250. {
  1251. skb_reserve(skb,2); /* IP headers on 16 byte boundaries */
  1252. skb->dev = dev;
  1253. skb_put(skb, pkt_len); /* Make room */
  1254. ei_block_input(dev, pkt_len, skb, current_offset + sizeof(rx_frame));
  1255. skb->protocol=eth_type_trans(skb,dev);
  1256. netif_rx(skb);
  1257. dev->last_rx = jiffies;
  1258. ei_local->stat.rx_packets++;
  1259. ei_local->stat.rx_bytes += pkt_len;
  1260. if (pkt_stat & ENRSR_PHY)
  1261. ei_local->stat.multicast++;
  1262. }
  1263. }
  1264. else
  1265. {
  1266. if (ei_debug)
  1267. printk(KERN_DEBUG "%s: bogus packet: status=%#2x nxpg=%#2x size=%d\n",
  1268. dev->name, rx_frame.status, rx_frame.next,
  1269. rx_frame.count);
  1270. ei_local->stat.rx_errors++;
  1271. /* NB: The NIC counts CRC, frame and missed errors. */
  1272. if (pkt_stat & ENRSR_FO)
  1273. ei_local->stat.rx_fifo_errors++;
  1274. }
  1275. next_frame = rx_frame.next;
  1276. /* This _should_ never happen: it's here for avoiding bad clones. */
  1277. if (next_frame >= ei_local->stop_page) {
  1278. printk("%s: next frame inconsistency, %#2x\n", dev->name,
  1279. next_frame);
  1280. next_frame = ei_local->rx_start_page;
  1281. }
  1282. ei_local->current_page = next_frame;
  1283. outb_p(next_frame-1, e8390_base+EN0_BOUNDARY);
  1284. }
  1285. return;
  1286. }
  1287. /**
  1288. * ei_rx_overrun - handle receiver overrun
  1289. * @dev: network device which threw exception
  1290. *
  1291. * We have a receiver overrun: we have to kick the 8390 to get it started
  1292. * again. Problem is that you have to kick it exactly as NS prescribes in
  1293. * the updated datasheets, or "the NIC may act in an unpredictable manner."
  1294. * This includes causing "the NIC to defer indefinitely when it is stopped
  1295. * on a busy network." Ugh.
  1296. * Called with lock held. Don't call this with the interrupts off or your
  1297. * computer will hate you - it takes 10ms or so.
  1298. */
  1299. static void ei_rx_overrun(struct net_device *dev)
  1300. {
  1301. axnet_dev_t *info = PRIV(dev);
  1302. long e8390_base = dev->base_addr;
  1303. unsigned char was_txing, must_resend = 0;
  1304. struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
  1305. /*
  1306. * Record whether a Tx was in progress and then issue the
  1307. * stop command.
  1308. */
  1309. was_txing = inb_p(e8390_base+E8390_CMD) & E8390_TRANS;
  1310. outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
  1311. if (ei_debug > 1)
  1312. printk(KERN_DEBUG "%s: Receiver overrun.\n", dev->name);
  1313. ei_local->stat.rx_over_errors++;
  1314. /*
  1315. * Wait a full Tx time (1.2ms) + some guard time, NS says 1.6ms total.
  1316. * Early datasheets said to poll the reset bit, but now they say that
  1317. * it "is not a reliable indicator and subsequently should be ignored."
  1318. * We wait at least 10ms.
  1319. */
  1320. mdelay(10);
  1321. /*
  1322. * Reset RBCR[01] back to zero as per magic incantation.
  1323. */
  1324. outb_p(0x00, e8390_base+EN0_RCNTLO);
  1325. outb_p(0x00, e8390_base+EN0_RCNTHI);
  1326. /*
  1327. * See if any Tx was interrupted or not. According to NS, this
  1328. * step is vital, and skipping it will cause no end of havoc.
  1329. */
  1330. if (was_txing)
  1331. {
  1332. unsigned char tx_completed = inb_p(e8390_base+EN0_ISR) & (ENISR_TX+ENISR_TX_ERR);
  1333. if (!tx_completed)
  1334. must_resend = 1;
  1335. }
  1336. /*
  1337. * Have to enter loopback mode and then restart the NIC before
  1338. * you are allowed to slurp packets up off the ring.
  1339. */
  1340. outb_p(E8390_TXOFF, e8390_base + EN0_TXCR);
  1341. outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START, e8390_base + E8390_CMD);
  1342. /*
  1343. * Clear the Rx ring of all the debris, and ack the interrupt.
  1344. */
  1345. ei_receive(dev);
  1346. /*
  1347. * Leave loopback mode, and resend any packet that got stopped.
  1348. */
  1349. outb_p(E8390_TXCONFIG | info->duplex_flag, e8390_base + EN0_TXCR);
  1350. if (must_resend)
  1351. outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START + E8390_TRANS, e8390_base + E8390_CMD);
  1352. }
  1353. /*
  1354. * Collect the stats. This is called unlocked and from several contexts.
  1355. */
  1356. static struct net_device_stats *get_stats(struct net_device *dev)
  1357. {
  1358. long ioaddr = dev->base_addr;
  1359. struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
  1360. unsigned long flags;
  1361. /* If the card is stopped, just return the present stats. */
  1362. if (!netif_running(dev))
  1363. return &ei_local->stat;
  1364. spin_lock_irqsave(&ei_local->page_lock,flags);
  1365. /* Read the counter registers, assuming we are in page 0. */
  1366. ei_local->stat.rx_frame_errors += inb_p(ioaddr + EN0_COUNTER0);
  1367. ei_local->stat.rx_crc_errors += inb_p(ioaddr + EN0_COUNTER1);
  1368. ei_local->stat.rx_missed_errors+= inb_p(ioaddr + EN0_COUNTER2);
  1369. spin_unlock_irqrestore(&ei_local->page_lock, flags);
  1370. return &ei_local->stat;
  1371. }
  1372. /*
  1373. * Form the 64 bit 8390 multicast table from the linked list of addresses
  1374. * associated with this dev structure.
  1375. */
  1376. static inline void make_mc_bits(u8 *bits, struct net_device *dev)
  1377. {
  1378. struct dev_mc_list *dmi;
  1379. u32 crc;
  1380. for (dmi=dev->mc_list; dmi; dmi=dmi->next) {
  1381. crc = ether_crc(ETH_ALEN, dmi->dmi_addr);
  1382. /*
  1383. * The 8390 uses the 6 most significant bits of the
  1384. * CRC to index the multicast table.
  1385. */
  1386. bits[crc>>29] |= (1<<((crc>>26)&7));
  1387. }
  1388. }
  1389. /**
  1390. * do_set_multicast_list - set/clear multicast filter
  1391. * @dev: net device for which multicast filter is adjusted
  1392. *
  1393. * Set or clear the multicast filter for this adaptor.
  1394. * Must be called with lock held.
  1395. */
  1396. static void do_set_multicast_list(struct net_device *dev)
  1397. {
  1398. long e8390_base = dev->base_addr;
  1399. int i;
  1400. struct ei_device *ei_local = (struct ei_device*)netdev_priv(dev);
  1401. if (!(dev->flags&(IFF_PROMISC|IFF_ALLMULTI))) {
  1402. memset(ei_local->mcfilter, 0, 8);
  1403. if (dev->mc_list)
  1404. make_mc_bits(ei_local->mcfilter, dev);
  1405. } else {
  1406. /* set to accept-all */
  1407. memset(ei_local->mcfilter, 0xFF, 8);
  1408. }
  1409. outb_p(E8390_NODMA + E8390_PAGE1, e8390_base + E8390_CMD);
  1410. for(i = 0; i < 8; i++)
  1411. {
  1412. outb_p(ei_local->mcfilter[i], e8390_base + EN1_MULT_SHIFT(i));
  1413. }
  1414. outb_p(E8390_NODMA + E8390_PAGE0, e8390_base + E8390_CMD);
  1415. if(dev->flags&IFF_PROMISC)
  1416. outb_p(E8390_RXCONFIG | 0x58, e8390_base + EN0_RXCR);
  1417. else if(dev->flags&IFF_ALLMULTI || dev->mc_list)
  1418. outb_p(E8390_RXCONFIG | 0x48, e8390_base + EN0_RXCR);
  1419. else
  1420. outb_p(E8390_RXCONFIG | 0x40, e8390_base + EN0_RXCR);
  1421. outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base+E8390_CMD);
  1422. }
  1423. /*
  1424. * Called without lock held. This is invoked from user context and may
  1425. * be parallel to just about everything else. Its also fairly quick and
  1426. * not called too often. Must protect against both bh and irq users
  1427. */
  1428. static void set_multicast_list(struct net_device *dev)
  1429. {
  1430. unsigned long flags;
  1431. spin_lock_irqsave(&dev_lock(dev), flags);
  1432. do_set_multicast_list(dev);
  1433. spin_unlock_irqrestore(&dev_lock(dev), flags);
  1434. }
  1435. /**
  1436. * axdev_setup - init rest of 8390 device struct
  1437. * @dev: network device structure to init
  1438. *
  1439. * Initialize the rest of the 8390 device structure. Do NOT __init
  1440. * this, as it is used by 8390 based modular drivers too.
  1441. */
  1442. static void axdev_setup(struct net_device *dev)
  1443. {
  1444. struct ei_device *ei_local;
  1445. if (ei_debug > 1)
  1446. printk(version_8390);
  1447. SET_MODULE_OWNER(dev);
  1448. ei_local = (struct ei_device *)netdev_priv(dev);
  1449. spin_lock_init(&ei_local->page_lock);
  1450. dev->hard_start_xmit = &ei_start_xmit;
  1451. dev->get_stats = get_stats;
  1452. dev->set_multicast_list = &set_multicast_list;
  1453. ether_setup(dev);
  1454. }
  1455. /* This page of functions should be 8390 generic */
  1456. /* Follow National Semi's recommendations for initializing the "NIC". */
  1457. /**
  1458. * AX88190_init - initialize 8390 hardware
  1459. * @dev: network device to initialize
  1460. * @startp: boolean. non-zero value to initiate chip processing
  1461. *
  1462. * Must be called with lock held.
  1463. */
  1464. static void AX88190_init(struct net_device *dev, int startp)
  1465. {
  1466. axnet_dev_t *info = PRIV(dev);
  1467. long e8390_base = dev->base_addr;
  1468. struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
  1469. int i;
  1470. int endcfg = ei_local->word16 ? (0x48 | ENDCFG_WTS) : 0x48;
  1471. if(sizeof(struct e8390_pkt_hdr)!=4)
  1472. panic("8390.c: header struct mispacked\n");
  1473. /* Follow National Semi's recommendations for initing the DP83902. */
  1474. outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD); /* 0x21 */
  1475. outb_p(endcfg, e8390_base + EN0_DCFG); /* 0x48 or 0x49 */
  1476. /* Clear the remote byte count registers. */
  1477. outb_p(0x00, e8390_base + EN0_RCNTLO);
  1478. outb_p(0x00, e8390_base + EN0_RCNTHI);
  1479. /* Set to monitor and loopback mode -- this is vital!. */
  1480. outb_p(E8390_RXOFF|0x40, e8390_base + EN0_RXCR); /* 0x60 */
  1481. outb_p(E8390_TXOFF, e8390_base + EN0_TXCR); /* 0x02 */
  1482. /* Set the transmit page and receive ring. */
  1483. outb_p(ei_local->tx_start_page, e8390_base + EN0_TPSR);
  1484. ei_local->tx1 = ei_local->tx2 = 0;
  1485. outb_p(ei_local->rx_start_page, e8390_base + EN0_STARTPG);
  1486. outb_p(ei_local->stop_page-1, e8390_base + EN0_BOUNDARY); /* 3c503 says 0x3f,NS0x26*/
  1487. ei_local->current_page = ei_local->rx_start_page; /* assert boundary+1 */
  1488. outb_p(ei_local->stop_page, e8390_base + EN0_STOPPG);
  1489. /* Clear the pending interrupts and mask. */
  1490. outb_p(0xFF, e8390_base + EN0_ISR);
  1491. outb_p(0x00, e8390_base + EN0_IMR);
  1492. /* Copy the station address into the DS8390 registers. */
  1493. outb_p(E8390_NODMA + E8390_PAGE1 + E8390_STOP, e8390_base+E8390_CMD); /* 0x61 */
  1494. for(i = 0; i < 6; i++)
  1495. {
  1496. outb_p(dev->dev_addr[i], e8390_base + EN1_PHYS_SHIFT(i));
  1497. if(inb_p(e8390_base + EN1_PHYS_SHIFT(i))!=dev->dev_addr[i])
  1498. printk(KERN_ERR "Hw. address read/write mismap %d\n",i);
  1499. }
  1500. outb_p(ei_local->rx_start_page, e8390_base + EN1_CURPAG);
  1501. outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
  1502. netif_start_queue(dev);
  1503. ei_local->tx1 = ei_local->tx2 = 0;
  1504. ei_local->txing = 0;
  1505. if (startp)
  1506. {
  1507. outb_p(0xff, e8390_base + EN0_ISR);
  1508. outb_p(ENISR_ALL, e8390_base + EN0_IMR);
  1509. outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base+E8390_CMD);
  1510. outb_p(E8390_TXCONFIG | info->duplex_flag,
  1511. e8390_base + EN0_TXCR); /* xmit on. */
  1512. /* 3c503 TechMan says rxconfig only after the NIC is started. */
  1513. outb_p(E8390_RXCONFIG | 0x40, e8390_base + EN0_RXCR); /* rx on, */
  1514. do_set_multicast_list(dev); /* (re)load the mcast table */
  1515. }
  1516. }
  1517. /* Trigger a transmit start, assuming the length is valid.
  1518. Always called with the page lock held */
  1519. static void NS8390_trigger_send(struct net_device *dev, unsigned int length,
  1520. int start_page)
  1521. {
  1522. long e8390_base = dev->base_addr;
  1523. struct ei_device *ei_local __attribute((unused)) = (struct ei_device *) netdev_priv(dev);
  1524. if (inb_p(e8390_base) & E8390_TRANS)
  1525. {
  1526. printk(KERN_WARNING "%s: trigger_send() called with the transmitter busy.\n",
  1527. dev->name);
  1528. return;
  1529. }
  1530. outb_p(length & 0xff, e8390_base + EN0_TCNTLO);
  1531. outb_p(length >> 8, e8390_base + EN0_TCNTHI);
  1532. outb_p(start_page, e8390_base + EN0_TPSR);
  1533. outb_p(E8390_NODMA+E8390_TRANS+E8390_START, e8390_base+E8390_CMD);
  1534. }