etherh.c 20 KB

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