etherh.c 20 KB

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