etherh.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. /*
  2. * linux/drivers/acorn/net/etherh.c
  3. *
  4. * Copyright (C) 2000-2002 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * NS8390 I-cubed EtherH and ANT EtherM specific driver
  11. * Thanks to I-Cubed for information on their cards.
  12. * EtherM conversion (C) 1999 Chris Kemp and Tim Watterton
  13. * EtherM integration (C) 2000 Aleph One Ltd (Tak-Shing Chan)
  14. * EtherM integration re-engineered by Russell King.
  15. *
  16. * Changelog:
  17. * 08-12-1996 RMK 1.00 Created
  18. * RMK 1.03 Added support for EtherLan500 cards
  19. * 23-11-1997 RMK 1.04 Added media autodetection
  20. * 16-04-1998 RMK 1.05 Improved media autodetection
  21. * 10-02-2000 RMK 1.06 Updated for 2.3.43
  22. * 13-05-2000 RMK 1.07 Updated for 2.3.99-pre8
  23. * 12-10-1999 CK/TEW EtherM driver first release
  24. * 21-12-2000 TTC EtherH/EtherM integration
  25. * 25-12-2000 RMK 1.08 Clean integration of EtherM into this driver.
  26. * 03-01-2002 RMK 1.09 Always enable IRQs if we're in the nic slot.
  27. */
  28. #include <linux/module.h>
  29. #include <linux/kernel.h>
  30. #include <linux/types.h>
  31. #include <linux/fcntl.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/ioport.h>
  34. #include <linux/in.h>
  35. #include <linux/string.h>
  36. #include <linux/errno.h>
  37. #include <linux/netdevice.h>
  38. #include <linux/etherdevice.h>
  39. #include <linux/ethtool.h>
  40. #include <linux/skbuff.h>
  41. #include <linux/delay.h>
  42. #include <linux/device.h>
  43. #include <linux/init.h>
  44. #include <linux/bitops.h>
  45. #include <linux/jiffies.h>
  46. #include <asm/ecard.h>
  47. #include <asm/io.h>
  48. #include <asm/system_info.h>
  49. #define EI_SHIFT(x) (ei_local->reg_offset[x])
  50. #define ei_inb(_p) readb((void __iomem *)_p)
  51. #define ei_outb(_v,_p) writeb(_v,(void __iomem *)_p)
  52. #define ei_inb_p(_p) readb((void __iomem *)_p)
  53. #define ei_outb_p(_v,_p) writeb(_v,(void __iomem *)_p)
  54. #define DRV_NAME "etherh"
  55. #define DRV_VERSION "1.11"
  56. static char version[] =
  57. "EtherH/EtherM Driver (c) 2002-2004 Russell King " DRV_VERSION "\n";
  58. #include "lib8390.c"
  59. static u32 etherh_msg_enable;
  60. struct etherh_priv {
  61. void __iomem *ioc_fast;
  62. void __iomem *memc;
  63. void __iomem *dma_base;
  64. unsigned int id;
  65. void __iomem *ctrl_port;
  66. unsigned char ctrl;
  67. u32 supported;
  68. };
  69. struct etherh_data {
  70. unsigned long ns8390_offset;
  71. unsigned long dataport_offset;
  72. unsigned long ctrlport_offset;
  73. int ctrl_ioc;
  74. const char name[16];
  75. u32 supported;
  76. unsigned char tx_start_page;
  77. unsigned char stop_page;
  78. };
  79. MODULE_AUTHOR("Russell King");
  80. MODULE_DESCRIPTION("EtherH/EtherM driver");
  81. MODULE_LICENSE("GPL");
  82. #define ETHERH500_DATAPORT 0x800 /* MEMC */
  83. #define ETHERH500_NS8390 0x000 /* MEMC */
  84. #define ETHERH500_CTRLPORT 0x800 /* IOC */
  85. #define ETHERH600_DATAPORT 0x040 /* MEMC */
  86. #define ETHERH600_NS8390 0x800 /* MEMC */
  87. #define ETHERH600_CTRLPORT 0x200 /* MEMC */
  88. #define ETHERH_CP_IE 1
  89. #define ETHERH_CP_IF 2
  90. #define ETHERH_CP_HEARTBEAT 2
  91. #define ETHERH_TX_START_PAGE 1
  92. #define ETHERH_STOP_PAGE 127
  93. /*
  94. * These came from CK/TEW
  95. */
  96. #define ETHERM_DATAPORT 0x200 /* MEMC */
  97. #define ETHERM_NS8390 0x800 /* MEMC */
  98. #define ETHERM_CTRLPORT 0x23c /* MEMC */
  99. #define ETHERM_TX_START_PAGE 64
  100. #define ETHERM_STOP_PAGE 127
  101. /* ------------------------------------------------------------------------ */
  102. #define etherh_priv(dev) \
  103. ((struct etherh_priv *)(((char *)netdev_priv(dev)) + sizeof(struct ei_device)))
  104. static inline void etherh_set_ctrl(struct etherh_priv *eh, unsigned char mask)
  105. {
  106. unsigned char ctrl = eh->ctrl | mask;
  107. eh->ctrl = ctrl;
  108. writeb(ctrl, eh->ctrl_port);
  109. }
  110. static inline void etherh_clr_ctrl(struct etherh_priv *eh, unsigned char mask)
  111. {
  112. unsigned char ctrl = eh->ctrl & ~mask;
  113. eh->ctrl = ctrl;
  114. writeb(ctrl, eh->ctrl_port);
  115. }
  116. static inline unsigned int etherh_get_stat(struct etherh_priv *eh)
  117. {
  118. return readb(eh->ctrl_port);
  119. }
  120. static void etherh_irq_enable(ecard_t *ec, int irqnr)
  121. {
  122. struct etherh_priv *eh = ec->irq_data;
  123. etherh_set_ctrl(eh, ETHERH_CP_IE);
  124. }
  125. static void etherh_irq_disable(ecard_t *ec, int irqnr)
  126. {
  127. struct etherh_priv *eh = ec->irq_data;
  128. etherh_clr_ctrl(eh, ETHERH_CP_IE);
  129. }
  130. static expansioncard_ops_t etherh_ops = {
  131. .irqenable = etherh_irq_enable,
  132. .irqdisable = etherh_irq_disable,
  133. };
  134. static void
  135. etherh_setif(struct net_device *dev)
  136. {
  137. struct ei_device *ei_local = netdev_priv(dev);
  138. unsigned long flags;
  139. void __iomem *addr;
  140. local_irq_save(flags);
  141. /* set the interface type */
  142. switch (etherh_priv(dev)->id) {
  143. case PROD_I3_ETHERLAN600:
  144. case PROD_I3_ETHERLAN600A:
  145. addr = (void __iomem *)dev->base_addr + EN0_RCNTHI;
  146. switch (dev->if_port) {
  147. case IF_PORT_10BASE2:
  148. writeb((readb(addr) & 0xf8) | 1, addr);
  149. break;
  150. case IF_PORT_10BASET:
  151. writeb((readb(addr) & 0xf8), addr);
  152. break;
  153. }
  154. break;
  155. case PROD_I3_ETHERLAN500:
  156. switch (dev->if_port) {
  157. case IF_PORT_10BASE2:
  158. etherh_clr_ctrl(etherh_priv(dev), ETHERH_CP_IF);
  159. break;
  160. case IF_PORT_10BASET:
  161. etherh_set_ctrl(etherh_priv(dev), ETHERH_CP_IF);
  162. break;
  163. }
  164. break;
  165. default:
  166. break;
  167. }
  168. local_irq_restore(flags);
  169. }
  170. static int
  171. etherh_getifstat(struct net_device *dev)
  172. {
  173. struct ei_device *ei_local = netdev_priv(dev);
  174. void __iomem *addr;
  175. int stat = 0;
  176. switch (etherh_priv(dev)->id) {
  177. case PROD_I3_ETHERLAN600:
  178. case PROD_I3_ETHERLAN600A:
  179. addr = (void __iomem *)dev->base_addr + EN0_RCNTHI;
  180. switch (dev->if_port) {
  181. case IF_PORT_10BASE2:
  182. stat = 1;
  183. break;
  184. case IF_PORT_10BASET:
  185. stat = readb(addr) & 4;
  186. break;
  187. }
  188. break;
  189. case PROD_I3_ETHERLAN500:
  190. switch (dev->if_port) {
  191. case IF_PORT_10BASE2:
  192. stat = 1;
  193. break;
  194. case IF_PORT_10BASET:
  195. stat = etherh_get_stat(etherh_priv(dev)) & ETHERH_CP_HEARTBEAT;
  196. break;
  197. }
  198. break;
  199. default:
  200. stat = 0;
  201. break;
  202. }
  203. return stat != 0;
  204. }
  205. /*
  206. * Configure the interface. Note that we ignore the other
  207. * parts of ifmap, since its mostly meaningless for this driver.
  208. */
  209. static int etherh_set_config(struct net_device *dev, struct ifmap *map)
  210. {
  211. switch (map->port) {
  212. case IF_PORT_10BASE2:
  213. case IF_PORT_10BASET:
  214. /*
  215. * If the user explicitly sets the interface
  216. * media type, turn off automedia detection.
  217. */
  218. dev->flags &= ~IFF_AUTOMEDIA;
  219. dev->if_port = map->port;
  220. break;
  221. default:
  222. return -EINVAL;
  223. }
  224. etherh_setif(dev);
  225. return 0;
  226. }
  227. /*
  228. * Reset the 8390 (hard reset). Note that we can't actually do this.
  229. */
  230. static void
  231. etherh_reset(struct net_device *dev)
  232. {
  233. struct ei_device *ei_local = netdev_priv(dev);
  234. void __iomem *addr = (void __iomem *)dev->base_addr;
  235. writeb(E8390_NODMA+E8390_PAGE0+E8390_STOP, addr);
  236. /*
  237. * See if we need to change the interface type.
  238. * Note that we use 'interface_num' as a flag
  239. * to indicate that we need to change the media.
  240. */
  241. if (dev->flags & IFF_AUTOMEDIA && ei_local->interface_num) {
  242. ei_local->interface_num = 0;
  243. if (dev->if_port == IF_PORT_10BASET)
  244. dev->if_port = IF_PORT_10BASE2;
  245. else
  246. dev->if_port = IF_PORT_10BASET;
  247. etherh_setif(dev);
  248. }
  249. }
  250. /*
  251. * Write a block of data out to the 8390
  252. */
  253. static void
  254. etherh_block_output (struct net_device *dev, int count, const unsigned char *buf, int start_page)
  255. {
  256. struct ei_device *ei_local = netdev_priv(dev);
  257. unsigned long dma_start;
  258. void __iomem *dma_base, *addr;
  259. if (ei_local->dmaing) {
  260. netdev_err(dev, "DMAing conflict in etherh_block_input: "
  261. " DMAstat %d irqlock %d\n",
  262. ei_local->dmaing, ei_local->irqlock);
  263. return;
  264. }
  265. /*
  266. * Make sure we have a round number of bytes if we're in word mode.
  267. */
  268. if (count & 1 && ei_local->word16)
  269. count++;
  270. ei_local->dmaing = 1;
  271. addr = (void __iomem *)dev->base_addr;
  272. dma_base = etherh_priv(dev)->dma_base;
  273. count = (count + 1) & ~1;
  274. writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
  275. writeb (0x42, addr + EN0_RCNTLO);
  276. writeb (0x00, addr + EN0_RCNTHI);
  277. writeb (0x42, addr + EN0_RSARLO);
  278. writeb (0x00, addr + EN0_RSARHI);
  279. writeb (E8390_RREAD | E8390_START, addr + E8390_CMD);
  280. udelay (1);
  281. writeb (ENISR_RDC, addr + EN0_ISR);
  282. writeb (count, addr + EN0_RCNTLO);
  283. writeb (count >> 8, addr + EN0_RCNTHI);
  284. writeb (0, addr + EN0_RSARLO);
  285. writeb (start_page, addr + EN0_RSARHI);
  286. writeb (E8390_RWRITE | E8390_START, addr + E8390_CMD);
  287. if (ei_local->word16)
  288. writesw (dma_base, buf, count >> 1);
  289. else
  290. writesb (dma_base, buf, count);
  291. dma_start = jiffies;
  292. while ((readb (addr + EN0_ISR) & ENISR_RDC) == 0)
  293. if (time_after(jiffies, dma_start + 2*HZ/100)) { /* 20ms */
  294. netdev_warn(dev, "timeout waiting for TX RDC\n");
  295. etherh_reset (dev);
  296. __NS8390_init (dev, 1);
  297. break;
  298. }
  299. writeb (ENISR_RDC, addr + EN0_ISR);
  300. ei_local->dmaing = 0;
  301. }
  302. /*
  303. * Read a block of data from the 8390
  304. */
  305. static void
  306. etherh_block_input (struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
  307. {
  308. struct ei_device *ei_local = netdev_priv(dev);
  309. unsigned char *buf;
  310. void __iomem *dma_base, *addr;
  311. if (ei_local->dmaing) {
  312. netdev_err(dev, "DMAing conflict in etherh_block_input: "
  313. " DMAstat %d irqlock %d\n",
  314. ei_local->dmaing, ei_local->irqlock);
  315. return;
  316. }
  317. ei_local->dmaing = 1;
  318. addr = (void __iomem *)dev->base_addr;
  319. dma_base = etherh_priv(dev)->dma_base;
  320. buf = skb->data;
  321. writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
  322. writeb (count, addr + EN0_RCNTLO);
  323. writeb (count >> 8, addr + EN0_RCNTHI);
  324. writeb (ring_offset, addr + EN0_RSARLO);
  325. writeb (ring_offset >> 8, addr + EN0_RSARHI);
  326. writeb (E8390_RREAD | E8390_START, addr + E8390_CMD);
  327. if (ei_local->word16) {
  328. readsw (dma_base, buf, count >> 1);
  329. if (count & 1)
  330. buf[count - 1] = readb (dma_base);
  331. } else
  332. readsb (dma_base, buf, count);
  333. writeb (ENISR_RDC, addr + EN0_ISR);
  334. ei_local->dmaing = 0;
  335. }
  336. /*
  337. * Read a header from the 8390
  338. */
  339. static void
  340. etherh_get_header (struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  341. {
  342. struct ei_device *ei_local = netdev_priv(dev);
  343. void __iomem *dma_base, *addr;
  344. if (ei_local->dmaing) {
  345. netdev_err(dev, "DMAing conflict in etherh_get_header: "
  346. " DMAstat %d irqlock %d\n",
  347. ei_local->dmaing, ei_local->irqlock);
  348. return;
  349. }
  350. ei_local->dmaing = 1;
  351. addr = (void __iomem *)dev->base_addr;
  352. dma_base = etherh_priv(dev)->dma_base;
  353. writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
  354. writeb (sizeof (*hdr), addr + EN0_RCNTLO);
  355. writeb (0, addr + EN0_RCNTHI);
  356. writeb (0, addr + EN0_RSARLO);
  357. writeb (ring_page, addr + EN0_RSARHI);
  358. writeb (E8390_RREAD | E8390_START, addr + E8390_CMD);
  359. if (ei_local->word16)
  360. readsw (dma_base, hdr, sizeof (*hdr) >> 1);
  361. else
  362. readsb (dma_base, hdr, sizeof (*hdr));
  363. writeb (ENISR_RDC, addr + EN0_ISR);
  364. ei_local->dmaing = 0;
  365. }
  366. /*
  367. * Open/initialize the board. This is called (in the current kernel)
  368. * sometime after booting when the 'ifconfig' program is run.
  369. *
  370. * This routine should set everything up anew at each open, even
  371. * registers that "should" only need to be set once at boot, so that
  372. * there is non-reboot way to recover if something goes wrong.
  373. */
  374. static int
  375. etherh_open(struct net_device *dev)
  376. {
  377. struct ei_device *ei_local = netdev_priv(dev);
  378. if (request_irq(dev->irq, __ei_interrupt, 0, dev->name, dev))
  379. return -EAGAIN;
  380. /*
  381. * Make sure that we aren't going to change the
  382. * media type on the next reset - we are about to
  383. * do automedia manually now.
  384. */
  385. ei_local->interface_num = 0;
  386. /*
  387. * If we are doing automedia detection, do it now.
  388. * This is more reliable than the 8390's detection.
  389. */
  390. if (dev->flags & IFF_AUTOMEDIA) {
  391. dev->if_port = IF_PORT_10BASET;
  392. etherh_setif(dev);
  393. mdelay(1);
  394. if (!etherh_getifstat(dev)) {
  395. dev->if_port = IF_PORT_10BASE2;
  396. etherh_setif(dev);
  397. }
  398. } else
  399. etherh_setif(dev);
  400. etherh_reset(dev);
  401. __ei_open(dev);
  402. return 0;
  403. }
  404. /*
  405. * The inverse routine to etherh_open().
  406. */
  407. static int
  408. etherh_close(struct net_device *dev)
  409. {
  410. __ei_close (dev);
  411. free_irq (dev->irq, dev);
  412. return 0;
  413. }
  414. /*
  415. * Initialisation
  416. */
  417. static void __init etherh_banner(void)
  418. {
  419. static int version_printed;
  420. if ((etherh_msg_enable & NETIF_MSG_DRV) && (version_printed++ == 0))
  421. pr_info("%s", version);
  422. }
  423. /*
  424. * Read the ethernet address string from the on board rom.
  425. * This is an ascii string...
  426. */
  427. static int etherh_addr(char *addr, struct expansion_card *ec)
  428. {
  429. struct in_chunk_dir cd;
  430. char *s;
  431. if (!ecard_readchunk(&cd, ec, 0xf5, 0)) {
  432. printk(KERN_ERR "%s: unable to read module description string\n",
  433. dev_name(&ec->dev));
  434. goto no_addr;
  435. }
  436. s = strchr(cd.d.string, '(');
  437. if (s) {
  438. int i;
  439. for (i = 0; i < 6; i++) {
  440. addr[i] = simple_strtoul(s + 1, &s, 0x10);
  441. if (*s != (i == 5? ')' : ':'))
  442. break;
  443. }
  444. if (i == 6)
  445. return 0;
  446. }
  447. printk(KERN_ERR "%s: unable to parse MAC address: %s\n",
  448. dev_name(&ec->dev), cd.d.string);
  449. no_addr:
  450. return -ENODEV;
  451. }
  452. /*
  453. * Create an ethernet address from the system serial number.
  454. */
  455. static int __init etherm_addr(char *addr)
  456. {
  457. unsigned int serial;
  458. if (system_serial_low == 0 && system_serial_high == 0)
  459. return -ENODEV;
  460. serial = system_serial_low | system_serial_high;
  461. addr[0] = 0;
  462. addr[1] = 0;
  463. addr[2] = 0xa4;
  464. addr[3] = 0x10 + (serial >> 24);
  465. addr[4] = serial >> 16;
  466. addr[5] = serial >> 8;
  467. return 0;
  468. }
  469. static void etherh_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  470. {
  471. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  472. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  473. strlcpy(info->bus_info, dev_name(dev->dev.parent),
  474. sizeof(info->bus_info));
  475. }
  476. static int etherh_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  477. {
  478. cmd->supported = etherh_priv(dev)->supported;
  479. ethtool_cmd_speed_set(cmd, SPEED_10);
  480. cmd->duplex = DUPLEX_HALF;
  481. cmd->port = dev->if_port == IF_PORT_10BASET ? PORT_TP : PORT_BNC;
  482. cmd->autoneg = (dev->flags & IFF_AUTOMEDIA ?
  483. AUTONEG_ENABLE : AUTONEG_DISABLE);
  484. return 0;
  485. }
  486. static int etherh_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  487. {
  488. switch (cmd->autoneg) {
  489. case AUTONEG_ENABLE:
  490. dev->flags |= IFF_AUTOMEDIA;
  491. break;
  492. case AUTONEG_DISABLE:
  493. switch (cmd->port) {
  494. case PORT_TP:
  495. dev->if_port = IF_PORT_10BASET;
  496. break;
  497. case PORT_BNC:
  498. dev->if_port = IF_PORT_10BASE2;
  499. break;
  500. default:
  501. return -EINVAL;
  502. }
  503. dev->flags &= ~IFF_AUTOMEDIA;
  504. break;
  505. default:
  506. return -EINVAL;
  507. }
  508. etherh_setif(dev);
  509. return 0;
  510. }
  511. static u32 etherh_get_msglevel(struct net_device *dev)
  512. {
  513. struct ei_device *ei_local = netdev_priv(dev);
  514. return ei_local->msg_enable;
  515. }
  516. static void etherh_set_msglevel(struct net_device *dev, u32 v)
  517. {
  518. struct ei_device *ei_local = netdev_priv(dev);
  519. ei_local->msg_enable = v;
  520. }
  521. static const struct ethtool_ops etherh_ethtool_ops = {
  522. .get_settings = etherh_get_settings,
  523. .set_settings = etherh_set_settings,
  524. .get_drvinfo = etherh_get_drvinfo,
  525. .get_ts_info = ethtool_op_get_ts_info,
  526. .get_msglevel = etherh_get_msglevel,
  527. .set_msglevel = etherh_set_msglevel,
  528. };
  529. static const struct net_device_ops etherh_netdev_ops = {
  530. .ndo_open = etherh_open,
  531. .ndo_stop = etherh_close,
  532. .ndo_set_config = etherh_set_config,
  533. .ndo_start_xmit = __ei_start_xmit,
  534. .ndo_tx_timeout = __ei_tx_timeout,
  535. .ndo_get_stats = __ei_get_stats,
  536. .ndo_set_rx_mode = __ei_set_multicast_list,
  537. .ndo_validate_addr = eth_validate_addr,
  538. .ndo_set_mac_address = eth_mac_addr,
  539. .ndo_change_mtu = eth_change_mtu,
  540. #ifdef CONFIG_NET_POLL_CONTROLLER
  541. .ndo_poll_controller = __ei_poll,
  542. #endif
  543. };
  544. static u32 etherh_regoffsets[16];
  545. static u32 etherm_regoffsets[16];
  546. static int
  547. etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
  548. {
  549. const struct etherh_data *data = id->data;
  550. struct ei_device *ei_local;
  551. struct net_device *dev;
  552. struct etherh_priv *eh;
  553. int ret;
  554. etherh_banner();
  555. ret = ecard_request_resources(ec);
  556. if (ret)
  557. goto out;
  558. dev = ____alloc_ei_netdev(sizeof(struct etherh_priv));
  559. if (!dev) {
  560. ret = -ENOMEM;
  561. goto release;
  562. }
  563. SET_NETDEV_DEV(dev, &ec->dev);
  564. dev->netdev_ops = &etherh_netdev_ops;
  565. dev->irq = ec->irq;
  566. dev->ethtool_ops = &etherh_ethtool_ops;
  567. if (data->supported & SUPPORTED_Autoneg)
  568. dev->flags |= IFF_AUTOMEDIA;
  569. if (data->supported & SUPPORTED_TP) {
  570. dev->flags |= IFF_PORTSEL;
  571. dev->if_port = IF_PORT_10BASET;
  572. } else if (data->supported & SUPPORTED_BNC) {
  573. dev->flags |= IFF_PORTSEL;
  574. dev->if_port = IF_PORT_10BASE2;
  575. } else
  576. dev->if_port = IF_PORT_UNKNOWN;
  577. eh = etherh_priv(dev);
  578. eh->supported = data->supported;
  579. eh->ctrl = 0;
  580. eh->id = ec->cid.product;
  581. eh->memc = ecardm_iomap(ec, ECARD_RES_MEMC, 0, PAGE_SIZE);
  582. if (!eh->memc) {
  583. ret = -ENOMEM;
  584. goto free;
  585. }
  586. eh->ctrl_port = eh->memc;
  587. if (data->ctrl_ioc) {
  588. eh->ioc_fast = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, PAGE_SIZE);
  589. if (!eh->ioc_fast) {
  590. ret = -ENOMEM;
  591. goto free;
  592. }
  593. eh->ctrl_port = eh->ioc_fast;
  594. }
  595. dev->base_addr = (unsigned long)eh->memc + data->ns8390_offset;
  596. eh->dma_base = eh->memc + data->dataport_offset;
  597. eh->ctrl_port += data->ctrlport_offset;
  598. /*
  599. * IRQ and control port handling - only for non-NIC slot cards.
  600. */
  601. if (ec->slot_no != 8) {
  602. ecard_setirq(ec, &etherh_ops, eh);
  603. } else {
  604. /*
  605. * If we're in the NIC slot, make sure the IRQ is enabled
  606. */
  607. etherh_set_ctrl(eh, ETHERH_CP_IE);
  608. }
  609. ei_local = netdev_priv(dev);
  610. spin_lock_init(&ei_local->page_lock);
  611. if (ec->cid.product == PROD_ANT_ETHERM) {
  612. etherm_addr(dev->dev_addr);
  613. ei_local->reg_offset = etherm_regoffsets;
  614. } else {
  615. etherh_addr(dev->dev_addr, ec);
  616. ei_local->reg_offset = etherh_regoffsets;
  617. }
  618. ei_local->name = dev->name;
  619. ei_local->word16 = 1;
  620. ei_local->tx_start_page = data->tx_start_page;
  621. ei_local->rx_start_page = ei_local->tx_start_page + TX_PAGES;
  622. ei_local->stop_page = data->stop_page;
  623. ei_local->reset_8390 = etherh_reset;
  624. ei_local->block_input = etherh_block_input;
  625. ei_local->block_output = etherh_block_output;
  626. ei_local->get_8390_hdr = etherh_get_header;
  627. ei_local->interface_num = 0;
  628. ei_local->msg_enable = etherh_msg_enable;
  629. etherh_reset(dev);
  630. __NS8390_init(dev, 0);
  631. ret = register_netdev(dev);
  632. if (ret)
  633. goto free;
  634. netdev_info(dev, "%s in slot %d, %pM\n",
  635. data->name, ec->slot_no, dev->dev_addr);
  636. ecard_set_drvdata(ec, dev);
  637. return 0;
  638. free:
  639. free_netdev(dev);
  640. release:
  641. ecard_release_resources(ec);
  642. out:
  643. return ret;
  644. }
  645. static void etherh_remove(struct expansion_card *ec)
  646. {
  647. struct net_device *dev = ecard_get_drvdata(ec);
  648. ecard_set_drvdata(ec, NULL);
  649. unregister_netdev(dev);
  650. free_netdev(dev);
  651. ecard_release_resources(ec);
  652. }
  653. static struct etherh_data etherm_data = {
  654. .ns8390_offset = ETHERM_NS8390,
  655. .dataport_offset = ETHERM_NS8390 + ETHERM_DATAPORT,
  656. .ctrlport_offset = ETHERM_NS8390 + ETHERM_CTRLPORT,
  657. .name = "ANT EtherM",
  658. .supported = SUPPORTED_10baseT_Half,
  659. .tx_start_page = ETHERM_TX_START_PAGE,
  660. .stop_page = ETHERM_STOP_PAGE,
  661. };
  662. static struct etherh_data etherlan500_data = {
  663. .ns8390_offset = ETHERH500_NS8390,
  664. .dataport_offset = ETHERH500_NS8390 + ETHERH500_DATAPORT,
  665. .ctrlport_offset = ETHERH500_CTRLPORT,
  666. .ctrl_ioc = 1,
  667. .name = "i3 EtherH 500",
  668. .supported = SUPPORTED_10baseT_Half,
  669. .tx_start_page = ETHERH_TX_START_PAGE,
  670. .stop_page = ETHERH_STOP_PAGE,
  671. };
  672. static struct etherh_data etherlan600_data = {
  673. .ns8390_offset = ETHERH600_NS8390,
  674. .dataport_offset = ETHERH600_NS8390 + ETHERH600_DATAPORT,
  675. .ctrlport_offset = ETHERH600_NS8390 + ETHERH600_CTRLPORT,
  676. .name = "i3 EtherH 600",
  677. .supported = SUPPORTED_10baseT_Half | SUPPORTED_TP | SUPPORTED_BNC | SUPPORTED_Autoneg,
  678. .tx_start_page = ETHERH_TX_START_PAGE,
  679. .stop_page = ETHERH_STOP_PAGE,
  680. };
  681. static struct etherh_data etherlan600a_data = {
  682. .ns8390_offset = ETHERH600_NS8390,
  683. .dataport_offset = ETHERH600_NS8390 + ETHERH600_DATAPORT,
  684. .ctrlport_offset = ETHERH600_NS8390 + ETHERH600_CTRLPORT,
  685. .name = "i3 EtherH 600A",
  686. .supported = SUPPORTED_10baseT_Half | SUPPORTED_TP | SUPPORTED_BNC | SUPPORTED_Autoneg,
  687. .tx_start_page = ETHERH_TX_START_PAGE,
  688. .stop_page = ETHERH_STOP_PAGE,
  689. };
  690. static const struct ecard_id etherh_ids[] = {
  691. { MANU_ANT, PROD_ANT_ETHERM, &etherm_data },
  692. { MANU_I3, PROD_I3_ETHERLAN500, &etherlan500_data },
  693. { MANU_I3, PROD_I3_ETHERLAN600, &etherlan600_data },
  694. { MANU_I3, PROD_I3_ETHERLAN600A, &etherlan600a_data },
  695. { 0xffff, 0xffff }
  696. };
  697. static struct ecard_driver etherh_driver = {
  698. .probe = etherh_probe,
  699. .remove = etherh_remove,
  700. .id_table = etherh_ids,
  701. .drv = {
  702. .name = DRV_NAME,
  703. },
  704. };
  705. static int __init etherh_init(void)
  706. {
  707. int i;
  708. for (i = 0; i < 16; i++) {
  709. etherh_regoffsets[i] = i << 2;
  710. etherm_regoffsets[i] = i << 5;
  711. }
  712. return ecard_register_driver(&etherh_driver);
  713. }
  714. static void __exit etherh_exit(void)
  715. {
  716. ecard_remove_driver(&etherh_driver);
  717. }
  718. module_init(etherh_init);
  719. module_exit(etherh_exit);