smc-mca.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. /* smc-mca.c: A SMC Ultra ethernet driver for linux. */
  2. /*
  3. Most of this driver, except for ultramca_probe is nearly
  4. verbatim from smc-ultra.c by Donald Becker. The rest is
  5. written and copyright 1996 by David Weis, weisd3458@uni.edu
  6. This is a driver for the SMC Ultra and SMC EtherEZ ethercards.
  7. This driver uses the cards in the 8390-compatible, shared memory mode.
  8. Most of the run-time complexity is handled by the generic code in
  9. 8390.c.
  10. This driver enables the shared memory only when doing the actual data
  11. transfers to avoid a bug in early version of the card that corrupted
  12. data transferred by a AHA1542.
  13. This driver does not support the programmed-I/O data transfer mode of
  14. the EtherEZ. That support (if available) is smc-ez.c. Nor does it
  15. use the non-8390-compatible "Altego" mode. (No support currently planned.)
  16. Changelog:
  17. Paul Gortmaker : multiple card support for module users.
  18. David Weis : Micro Channel-ized it.
  19. Tom Sightler : Added support for IBM PS/2 Ethernet Adapter/A
  20. Christopher Turcksin : Changed MCA-probe so that multiple adapters are
  21. found correctly (Jul 16, 1997)
  22. Chris Beauregard : Tried to merge the two changes above (Dec 15, 1997)
  23. Tom Sightler : Fixed minor detection bug caused by above merge
  24. Tom Sightler : Added support for three more Western Digital
  25. MCA-adapters
  26. Tom Sightler : Added support for 2.2.x mca_find_unused_adapter
  27. Hartmut Schmidt : - Modified parameter detection to handle each
  28. card differently depending on a switch-list
  29. - 'card_ver' removed from the adapter list
  30. - Some minor bug fixes
  31. */
  32. #include <linux/mca.h>
  33. #include <linux/module.h>
  34. #include <linux/kernel.h>
  35. #include <linux/errno.h>
  36. #include <linux/string.h>
  37. #include <linux/init.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/netdevice.h>
  40. #include <linux/etherdevice.h>
  41. #include <asm/io.h>
  42. #include "8390.h"
  43. #define DRV_NAME "smc-mca"
  44. static int ultramca_open(struct net_device *dev);
  45. static void ultramca_reset_8390(struct net_device *dev);
  46. static void ultramca_get_8390_hdr(struct net_device *dev,
  47. struct e8390_pkt_hdr *hdr,
  48. int ring_page);
  49. static void ultramca_block_input(struct net_device *dev, int count,
  50. struct sk_buff *skb,
  51. int ring_offset);
  52. static void ultramca_block_output(struct net_device *dev, int count,
  53. const unsigned char *buf,
  54. const int start_page);
  55. static int ultramca_close_card(struct net_device *dev);
  56. #define START_PG 0x00 /* First page of TX buffer */
  57. #define ULTRA_CMDREG 0 /* Offset to ASIC command register. */
  58. #define ULTRA_RESET 0x80 /* Board reset, in ULTRA_CMDREG. */
  59. #define ULTRA_MEMENB 0x40 /* Enable the shared memory. */
  60. #define ULTRA_NIC_OFFSET 16 /* NIC register offset from the base_addr. */
  61. #define ULTRA_IO_EXTENT 32
  62. #define EN0_ERWCNT 0x08 /* Early receive warning count. */
  63. #define _61c8_SMC_Ethercard_PLUS_Elite_A_BNC_AUI_WD8013EP_A 0
  64. #define _61c9_SMC_Ethercard_PLUS_Elite_A_UTP_AUI_WD8013EP_A 1
  65. #define _6fc0_WD_Ethercard_PLUS_A_WD8003E_A_OR_WD8003ET_A 2
  66. #define _6fc1_WD_Starcard_PLUS_A_WD8003ST_A 3
  67. #define _6fc2_WD_Ethercard_PLUS_10T_A_WD8003W_A 4
  68. #define _efd4_IBM_PS2_Adapter_A_for_Ethernet_UTP_AUI_WD8013WP_A 5
  69. #define _efd5_IBM_PS2_Adapter_A_for_Ethernet_BNC_AUI_WD8013WP_A 6
  70. #define _efe5_IBM_PS2_Adapter_A_for_Ethernet 7
  71. struct smc_mca_adapters_t {
  72. unsigned int id;
  73. char *name;
  74. };
  75. #define MAX_ULTRAMCA_CARDS 4 /* Max number of Ultra cards per module */
  76. static int ultra_io[MAX_ULTRAMCA_CARDS];
  77. static int ultra_irq[MAX_ULTRAMCA_CARDS];
  78. MODULE_LICENSE("GPL");
  79. module_param_array(ultra_io, int, NULL, 0);
  80. module_param_array(ultra_irq, int, NULL, 0);
  81. MODULE_PARM_DESC(ultra_io, "SMC Ultra/EtherEZ MCA I/O base address(es)");
  82. MODULE_PARM_DESC(ultra_irq, "SMC Ultra/EtherEZ MCA IRQ number(s)");
  83. static const struct {
  84. unsigned int base_addr;
  85. } addr_table[] = {
  86. { 0x0800 },
  87. { 0x1800 },
  88. { 0x2800 },
  89. { 0x3800 },
  90. { 0x4800 },
  91. { 0x5800 },
  92. { 0x6800 },
  93. { 0x7800 },
  94. { 0x8800 },
  95. { 0x9800 },
  96. { 0xa800 },
  97. { 0xb800 },
  98. { 0xc800 },
  99. { 0xd800 },
  100. { 0xe800 },
  101. { 0xf800 }
  102. };
  103. #define MEM_MASK 64
  104. static const struct {
  105. unsigned char mem_index;
  106. unsigned long mem_start;
  107. unsigned char num_pages;
  108. } mem_table[] = {
  109. { 16, 0x0c0000, 40 },
  110. { 18, 0x0c4000, 40 },
  111. { 20, 0x0c8000, 40 },
  112. { 22, 0x0cc000, 40 },
  113. { 24, 0x0d0000, 40 },
  114. { 26, 0x0d4000, 40 },
  115. { 28, 0x0d8000, 40 },
  116. { 30, 0x0dc000, 40 },
  117. {144, 0xfc0000, 40 },
  118. {148, 0xfc8000, 40 },
  119. {154, 0xfd0000, 40 },
  120. {156, 0xfd8000, 40 },
  121. { 0, 0x0c0000, 20 },
  122. { 1, 0x0c2000, 20 },
  123. { 2, 0x0c4000, 20 },
  124. { 3, 0x0c6000, 20 }
  125. };
  126. #define IRQ_MASK 243
  127. static const struct {
  128. unsigned char new_irq;
  129. unsigned char old_irq;
  130. } irq_table[] = {
  131. { 3, 3 },
  132. { 4, 4 },
  133. { 10, 10 },
  134. { 14, 15 }
  135. };
  136. static short smc_mca_adapter_ids[] __initdata = {
  137. 0x61c8,
  138. 0x61c9,
  139. 0x6fc0,
  140. 0x6fc1,
  141. 0x6fc2,
  142. 0xefd4,
  143. 0xefd5,
  144. 0xefe5,
  145. 0x0000
  146. };
  147. static char *smc_mca_adapter_names[] __initdata = {
  148. "SMC Ethercard PLUS Elite/A BNC/AUI (WD8013EP/A)",
  149. "SMC Ethercard PLUS Elite/A UTP/AUI (WD8013WP/A)",
  150. "WD Ethercard PLUS/A (WD8003E/A or WD8003ET/A)",
  151. "WD Starcard PLUS/A (WD8003ST/A)",
  152. "WD Ethercard PLUS 10T/A (WD8003W/A)",
  153. "IBM PS/2 Adapter/A for Ethernet UTP/AUI (WD8013WP/A)",
  154. "IBM PS/2 Adapter/A for Ethernet BNC/AUI (WD8013EP/A)",
  155. "IBM PS/2 Adapter/A for Ethernet",
  156. NULL
  157. };
  158. static int ultra_found = 0;
  159. static const struct net_device_ops ultramca_netdev_ops = {
  160. .ndo_open = ultramca_open,
  161. .ndo_stop = ultramca_close_card,
  162. .ndo_start_xmit = ei_start_xmit,
  163. .ndo_tx_timeout = ei_tx_timeout,
  164. .ndo_get_stats = ei_get_stats,
  165. .ndo_set_rx_mode = ei_set_multicast_list,
  166. .ndo_validate_addr = eth_validate_addr,
  167. .ndo_set_mac_address = eth_mac_addr,
  168. .ndo_change_mtu = eth_change_mtu,
  169. #ifdef CONFIG_NET_POLL_CONTROLLER
  170. .ndo_poll_controller = ei_poll,
  171. #endif
  172. };
  173. static int __init ultramca_probe(struct device *gen_dev)
  174. {
  175. unsigned short ioaddr;
  176. struct net_device *dev;
  177. unsigned char reg4, num_pages;
  178. struct mca_device *mca_dev = to_mca_device(gen_dev);
  179. char slot = mca_dev->slot;
  180. unsigned char pos2 = 0xff, pos3 = 0xff, pos4 = 0xff, pos5 = 0xff;
  181. int i, rc;
  182. int adapter = mca_dev->index;
  183. int tbase = 0;
  184. int tirq = 0;
  185. int base_addr = ultra_io[ultra_found];
  186. int irq = ultra_irq[ultra_found];
  187. if (base_addr || irq) {
  188. printk(KERN_INFO "Probing for SMC MCA adapter");
  189. if (base_addr) {
  190. printk(KERN_INFO " at I/O address 0x%04x%c",
  191. base_addr, irq ? ' ' : '\n');
  192. }
  193. if (irq) {
  194. printk(KERN_INFO "using irq %d\n", irq);
  195. }
  196. }
  197. tirq = 0;
  198. tbase = 0;
  199. /* If we're trying to match a specificied irq or io address,
  200. * we'll reject the adapter found unless it's the one we're
  201. * looking for */
  202. pos2 = mca_device_read_stored_pos(mca_dev, 2); /* io_addr */
  203. pos3 = mca_device_read_stored_pos(mca_dev, 3); /* shared mem */
  204. pos4 = mca_device_read_stored_pos(mca_dev, 4); /* ROM bios addr range */
  205. pos5 = mca_device_read_stored_pos(mca_dev, 5); /* irq, media and RIPL */
  206. /* Test the following conditions:
  207. * - If an irq parameter is supplied, compare it
  208. * with the irq of the adapter we found
  209. * - If a base_addr paramater is given, compare it
  210. * with the base_addr of the adapter we found
  211. * - Check that the irq and the base_addr of the
  212. * adapter we found is not already in use by
  213. * this driver
  214. */
  215. switch (mca_dev->index) {
  216. case _61c8_SMC_Ethercard_PLUS_Elite_A_BNC_AUI_WD8013EP_A:
  217. case _61c9_SMC_Ethercard_PLUS_Elite_A_UTP_AUI_WD8013EP_A:
  218. case _efd4_IBM_PS2_Adapter_A_for_Ethernet_UTP_AUI_WD8013WP_A:
  219. case _efd5_IBM_PS2_Adapter_A_for_Ethernet_BNC_AUI_WD8013WP_A:
  220. {
  221. tbase = addr_table[(pos2 & 0xf0) >> 4].base_addr;
  222. tirq = irq_table[(pos5 & 0xc) >> 2].new_irq;
  223. break;
  224. }
  225. case _6fc0_WD_Ethercard_PLUS_A_WD8003E_A_OR_WD8003ET_A:
  226. case _6fc1_WD_Starcard_PLUS_A_WD8003ST_A:
  227. case _6fc2_WD_Ethercard_PLUS_10T_A_WD8003W_A:
  228. case _efe5_IBM_PS2_Adapter_A_for_Ethernet:
  229. {
  230. tbase = ((pos2 & 0x0fe) * 0x10);
  231. tirq = irq_table[(pos5 & 3)].old_irq;
  232. break;
  233. }
  234. }
  235. if(!tirq || !tbase ||
  236. (irq && irq != tirq) ||
  237. (base_addr && tbase != base_addr))
  238. /* FIXME: we're trying to force the ordering of the
  239. * devices here, there should be a way of getting this
  240. * to happen */
  241. return -ENXIO;
  242. /* Adapter found. */
  243. dev = alloc_ei_netdev();
  244. if(!dev)
  245. return -ENODEV;
  246. SET_NETDEV_DEV(dev, gen_dev);
  247. mca_device_set_name(mca_dev, smc_mca_adapter_names[adapter]);
  248. mca_device_set_claim(mca_dev, 1);
  249. printk(KERN_INFO "smc_mca: %s found in slot %d\n",
  250. smc_mca_adapter_names[adapter], slot + 1);
  251. ultra_found++;
  252. dev->base_addr = ioaddr = mca_device_transform_ioport(mca_dev, tbase);
  253. dev->irq = mca_device_transform_irq(mca_dev, tirq);
  254. dev->mem_start = 0;
  255. num_pages = 40;
  256. switch (adapter) { /* card-# in const array above [hs] */
  257. case _61c8_SMC_Ethercard_PLUS_Elite_A_BNC_AUI_WD8013EP_A:
  258. case _61c9_SMC_Ethercard_PLUS_Elite_A_UTP_AUI_WD8013EP_A:
  259. {
  260. for (i = 0; i < 16; i++) { /* taking 16 counts
  261. * up to 15 [hs] */
  262. if (mem_table[i].mem_index == (pos3 & ~MEM_MASK)) {
  263. dev->mem_start = (unsigned long)
  264. mca_device_transform_memory(mca_dev, (void *)mem_table[i].mem_start);
  265. num_pages = mem_table[i].num_pages;
  266. }
  267. }
  268. break;
  269. }
  270. case _6fc0_WD_Ethercard_PLUS_A_WD8003E_A_OR_WD8003ET_A:
  271. case _6fc1_WD_Starcard_PLUS_A_WD8003ST_A:
  272. case _6fc2_WD_Ethercard_PLUS_10T_A_WD8003W_A:
  273. case _efe5_IBM_PS2_Adapter_A_for_Ethernet:
  274. {
  275. dev->mem_start = (unsigned long)
  276. mca_device_transform_memory(mca_dev, (void *)((pos3 & 0xfc) * 0x1000));
  277. num_pages = 0x40;
  278. break;
  279. }
  280. case _efd4_IBM_PS2_Adapter_A_for_Ethernet_UTP_AUI_WD8013WP_A:
  281. case _efd5_IBM_PS2_Adapter_A_for_Ethernet_BNC_AUI_WD8013WP_A:
  282. {
  283. /* courtesy of gamera@quartz.ocn.ne.jp, pos3 indicates
  284. * the index of the 0x2000 step.
  285. * beware different number of pages [hs]
  286. */
  287. dev->mem_start = (unsigned long)
  288. mca_device_transform_memory(mca_dev, (void *)(0xc0000 + (0x2000 * (pos3 & 0xf))));
  289. num_pages = 0x20 + (2 * (pos3 & 0x10));
  290. break;
  291. }
  292. }
  293. /* sanity check, shouldn't happen */
  294. if (dev->mem_start == 0) {
  295. rc = -ENODEV;
  296. goto err_unclaim;
  297. }
  298. if (!request_region(ioaddr, ULTRA_IO_EXTENT, DRV_NAME)) {
  299. rc = -ENODEV;
  300. goto err_unclaim;
  301. }
  302. reg4 = inb(ioaddr + 4) & 0x7f;
  303. outb(reg4, ioaddr + 4);
  304. for (i = 0; i < 6; i++)
  305. dev->dev_addr[i] = inb(ioaddr + 8 + i);
  306. printk(KERN_INFO "smc_mca[%d]: Parameters: %#3x, %pM",
  307. slot + 1, ioaddr, dev->dev_addr);
  308. /* Switch from the station address to the alternate register set
  309. * and read the useful registers there.
  310. */
  311. outb(0x80 | reg4, ioaddr + 4);
  312. /* Enable FINE16 mode to avoid BIOS ROM width mismatches @ reboot.
  313. */
  314. outb(0x80 | inb(ioaddr + 0x0c), ioaddr + 0x0c);
  315. /* Switch back to the station address register set so that
  316. * the MS-DOS driver can find the card after a warm boot.
  317. */
  318. outb(reg4, ioaddr + 4);
  319. dev_set_drvdata(gen_dev, dev);
  320. /* The 8390 isn't at the base address, so fake the offset
  321. */
  322. dev->base_addr = ioaddr + ULTRA_NIC_OFFSET;
  323. ei_status.name = "SMC Ultra MCA";
  324. ei_status.word16 = 1;
  325. ei_status.tx_start_page = START_PG;
  326. ei_status.rx_start_page = START_PG + TX_PAGES;
  327. ei_status.stop_page = num_pages;
  328. ei_status.mem = ioremap(dev->mem_start, (ei_status.stop_page - START_PG) * 256);
  329. if (!ei_status.mem) {
  330. rc = -ENOMEM;
  331. goto err_release_region;
  332. }
  333. dev->mem_end = dev->mem_start + (ei_status.stop_page - START_PG) * 256;
  334. printk(", IRQ %d memory %#lx-%#lx.\n",
  335. dev->irq, dev->mem_start, dev->mem_end - 1);
  336. ei_status.reset_8390 = &ultramca_reset_8390;
  337. ei_status.block_input = &ultramca_block_input;
  338. ei_status.block_output = &ultramca_block_output;
  339. ei_status.get_8390_hdr = &ultramca_get_8390_hdr;
  340. ei_status.priv = slot;
  341. dev->netdev_ops = &ultramca_netdev_ops;
  342. NS8390_init(dev, 0);
  343. rc = register_netdev(dev);
  344. if (rc)
  345. goto err_unmap;
  346. return 0;
  347. err_unmap:
  348. iounmap(ei_status.mem);
  349. err_release_region:
  350. release_region(ioaddr, ULTRA_IO_EXTENT);
  351. err_unclaim:
  352. mca_device_set_claim(mca_dev, 0);
  353. free_netdev(dev);
  354. return rc;
  355. }
  356. static int ultramca_open(struct net_device *dev)
  357. {
  358. int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC addr */
  359. int retval;
  360. if ((retval = request_irq(dev->irq, ei_interrupt, 0, dev->name, dev)))
  361. return retval;
  362. outb(ULTRA_MEMENB, ioaddr); /* Enable memory */
  363. outb(0x80, ioaddr + 5); /* ??? */
  364. outb(0x01, ioaddr + 6); /* Enable interrupts and memory. */
  365. outb(0x04, ioaddr + 5); /* ??? */
  366. /* Set the early receive warning level in window 0 high enough not
  367. * to receive ERW interrupts.
  368. */
  369. /* outb_p(E8390_NODMA + E8390_PAGE0, dev->base_addr);
  370. * outb(0xff, dev->base_addr + EN0_ERWCNT);
  371. */
  372. ei_open(dev);
  373. return 0;
  374. }
  375. static void ultramca_reset_8390(struct net_device *dev)
  376. {
  377. int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC addr */
  378. outb(ULTRA_RESET, ioaddr);
  379. if (ei_debug > 1)
  380. printk("resetting Ultra, t=%ld...", jiffies);
  381. ei_status.txing = 0;
  382. outb(0x80, ioaddr + 5); /* ??? */
  383. outb(0x01, ioaddr + 6); /* Enable interrupts and memory. */
  384. if (ei_debug > 1)
  385. printk("reset done\n");
  386. }
  387. /* Grab the 8390 specific header. Similar to the block_input routine, but
  388. * we don't need to be concerned with ring wrap as the header will be at
  389. * the start of a page, so we optimize accordingly.
  390. */
  391. static void ultramca_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  392. {
  393. void __iomem *hdr_start = ei_status.mem + ((ring_page - START_PG) << 8);
  394. #ifdef notdef
  395. /* Officially this is what we are doing, but the readl() is faster */
  396. memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
  397. #else
  398. ((unsigned int*)hdr)[0] = readl(hdr_start);
  399. #endif
  400. }
  401. /* Block input and output are easy on shared memory ethercards, the only
  402. * complication is when the ring buffer wraps.
  403. */
  404. static void ultramca_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
  405. {
  406. void __iomem *xfer_start = ei_status.mem + ring_offset - START_PG * 256;
  407. if (ring_offset + count > ei_status.stop_page * 256) {
  408. /* We must wrap the input move. */
  409. int semi_count = ei_status.stop_page * 256 - ring_offset;
  410. memcpy_fromio(skb->data, xfer_start, semi_count);
  411. count -= semi_count;
  412. memcpy_fromio(skb->data + semi_count, ei_status.mem + TX_PAGES * 256, count);
  413. } else {
  414. memcpy_fromio(skb->data, xfer_start, count);
  415. }
  416. }
  417. static void ultramca_block_output(struct net_device *dev, int count, const unsigned char *buf,
  418. int start_page)
  419. {
  420. void __iomem *shmem = ei_status.mem + ((start_page - START_PG) << 8);
  421. memcpy_toio(shmem, buf, count);
  422. }
  423. static int ultramca_close_card(struct net_device *dev)
  424. {
  425. int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC addr */
  426. netif_stop_queue(dev);
  427. if (ei_debug > 1)
  428. printk("%s: Shutting down ethercard.\n", dev->name);
  429. outb(0x00, ioaddr + 6); /* Disable interrupts. */
  430. free_irq(dev->irq, dev);
  431. NS8390_init(dev, 0);
  432. /* We should someday disable shared memory and change to 8-bit mode
  433. * "just in case"...
  434. */
  435. return 0;
  436. }
  437. static int ultramca_remove(struct device *gen_dev)
  438. {
  439. struct mca_device *mca_dev = to_mca_device(gen_dev);
  440. struct net_device *dev = dev_get_drvdata(gen_dev);
  441. if (dev) {
  442. /* NB: ultra_close_card() does free_irq */
  443. int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET;
  444. unregister_netdev(dev);
  445. mca_device_set_claim(mca_dev, 0);
  446. release_region(ioaddr, ULTRA_IO_EXTENT);
  447. iounmap(ei_status.mem);
  448. free_netdev(dev);
  449. }
  450. return 0;
  451. }
  452. static struct mca_driver ultra_driver = {
  453. .id_table = smc_mca_adapter_ids,
  454. .driver = {
  455. .name = "smc-mca",
  456. .bus = &mca_bus_type,
  457. .probe = ultramca_probe,
  458. .remove = ultramca_remove,
  459. }
  460. };
  461. static int __init ultramca_init_module(void)
  462. {
  463. if(!MCA_bus)
  464. return -ENXIO;
  465. mca_register_driver(&ultra_driver);
  466. return ultra_found ? 0 : -ENXIO;
  467. }
  468. static void __exit ultramca_cleanup_module(void)
  469. {
  470. mca_unregister_driver(&ultra_driver);
  471. }
  472. module_init(ultramca_init_module);
  473. module_exit(ultramca_cleanup_module);