axnet_cs.c 50 KB

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