etherh.c 20 KB

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