axnet_cs.c 56 KB

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