axnet_cs.c 56 KB

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