etherh.c 20 KB

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