etherh.c 20 KB

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