etherh.c 20 KB

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