axnet_cs.c 55 KB

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