smc-mca.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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/netdevice.h>
  39. #include <linux/etherdevice.h>
  40. #include <asm/io.h>
  41. #include <asm/system.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_multicast_list = ei_set_multicast_list,
  166. .ndo_validate_addr = eth_validate_addr,
  167. .ndo_change_mtu = eth_change_mtu,
  168. #ifdef CONFIG_NET_POLL_CONTROLLER
  169. .ndo_poll_controller = ei_poll,
  170. #endif
  171. };
  172. static int __init ultramca_probe(struct device *gen_dev)
  173. {
  174. unsigned short ioaddr;
  175. struct net_device *dev;
  176. unsigned char reg4, num_pages;
  177. struct mca_device *mca_dev = to_mca_device(gen_dev);
  178. char slot = mca_dev->slot;
  179. unsigned char pos2 = 0xff, pos3 = 0xff, pos4 = 0xff, pos5 = 0xff;
  180. int i, rc;
  181. int adapter = mca_dev->index;
  182. int tbase = 0;
  183. int tirq = 0;
  184. int base_addr = ultra_io[ultra_found];
  185. int irq = ultra_irq[ultra_found];
  186. if (base_addr || irq) {
  187. printk(KERN_INFO "Probing for SMC MCA adapter");
  188. if (base_addr) {
  189. printk(KERN_INFO " at I/O address 0x%04x%c",
  190. base_addr, irq ? ' ' : '\n');
  191. }
  192. if (irq) {
  193. printk(KERN_INFO "using irq %d\n", irq);
  194. }
  195. }
  196. tirq = 0;
  197. tbase = 0;
  198. /* If we're trying to match a specificied irq or io address,
  199. * we'll reject the adapter found unless it's the one we're
  200. * looking for */
  201. pos2 = mca_device_read_stored_pos(mca_dev, 2); /* io_addr */
  202. pos3 = mca_device_read_stored_pos(mca_dev, 3); /* shared mem */
  203. pos4 = mca_device_read_stored_pos(mca_dev, 4); /* ROM bios addr range */
  204. pos5 = mca_device_read_stored_pos(mca_dev, 5); /* irq, media and RIPL */
  205. /* Test the following conditions:
  206. * - If an irq parameter is supplied, compare it
  207. * with the irq of the adapter we found
  208. * - If a base_addr paramater is given, compare it
  209. * with the base_addr of the adapter we found
  210. * - Check that the irq and the base_addr of the
  211. * adapter we found is not already in use by
  212. * this driver
  213. */
  214. switch (mca_dev->index) {
  215. case _61c8_SMC_Ethercard_PLUS_Elite_A_BNC_AUI_WD8013EP_A:
  216. case _61c9_SMC_Ethercard_PLUS_Elite_A_UTP_AUI_WD8013EP_A:
  217. case _efd4_IBM_PS2_Adapter_A_for_Ethernet_UTP_AUI_WD8013WP_A:
  218. case _efd5_IBM_PS2_Adapter_A_for_Ethernet_BNC_AUI_WD8013WP_A:
  219. {
  220. tbase = addr_table[(pos2 & 0xf0) >> 4].base_addr;
  221. tirq = irq_table[(pos5 & 0xc) >> 2].new_irq;
  222. break;
  223. }
  224. case _6fc0_WD_Ethercard_PLUS_A_WD8003E_A_OR_WD8003ET_A:
  225. case _6fc1_WD_Starcard_PLUS_A_WD8003ST_A:
  226. case _6fc2_WD_Ethercard_PLUS_10T_A_WD8003W_A:
  227. case _efe5_IBM_PS2_Adapter_A_for_Ethernet:
  228. {
  229. tbase = ((pos2 & 0x0fe) * 0x10);
  230. tirq = irq_table[(pos5 & 3)].old_irq;
  231. break;
  232. }
  233. }
  234. if(!tirq || !tbase
  235. || (irq && irq != tirq)
  236. || (base_addr && tbase != base_addr))
  237. /* FIXME: we're trying to force the ordering of the
  238. * devices here, there should be a way of getting this
  239. * to happen */
  240. return -ENXIO;
  241. /* Adapter found. */
  242. dev = alloc_ei_netdev();
  243. if(!dev)
  244. return -ENODEV;
  245. SET_NETDEV_DEV(dev, gen_dev);
  246. mca_device_set_name(mca_dev, smc_mca_adapter_names[adapter]);
  247. mca_device_set_claim(mca_dev, 1);
  248. printk(KERN_INFO "smc_mca: %s found in slot %d\n",
  249. smc_mca_adapter_names[adapter], slot + 1);
  250. ultra_found++;
  251. dev->base_addr = ioaddr = mca_device_transform_ioport(mca_dev, tbase);
  252. dev->irq = mca_device_transform_irq(mca_dev, tirq);
  253. dev->mem_start = 0;
  254. num_pages = 40;
  255. switch (adapter) { /* card-# in const array above [hs] */
  256. case _61c8_SMC_Ethercard_PLUS_Elite_A_BNC_AUI_WD8013EP_A:
  257. case _61c9_SMC_Ethercard_PLUS_Elite_A_UTP_AUI_WD8013EP_A:
  258. {
  259. for (i = 0; i < 16; i++) { /* taking 16 counts
  260. * up to 15 [hs] */
  261. if (mem_table[i].mem_index == (pos3 & ~MEM_MASK)) {
  262. dev->mem_start = (unsigned long)
  263. mca_device_transform_memory(mca_dev, (void *)mem_table[i].mem_start);
  264. num_pages = mem_table[i].num_pages;
  265. }
  266. }
  267. break;
  268. }
  269. case _6fc0_WD_Ethercard_PLUS_A_WD8003E_A_OR_WD8003ET_A:
  270. case _6fc1_WD_Starcard_PLUS_A_WD8003ST_A:
  271. case _6fc2_WD_Ethercard_PLUS_10T_A_WD8003W_A:
  272. case _efe5_IBM_PS2_Adapter_A_for_Ethernet:
  273. {
  274. dev->mem_start = (unsigned long)
  275. mca_device_transform_memory(mca_dev, (void *)((pos3 & 0xfc) * 0x1000));
  276. num_pages = 0x40;
  277. break;
  278. }
  279. case _efd4_IBM_PS2_Adapter_A_for_Ethernet_UTP_AUI_WD8013WP_A:
  280. case _efd5_IBM_PS2_Adapter_A_for_Ethernet_BNC_AUI_WD8013WP_A:
  281. {
  282. /* courtesy of gamera@quartz.ocn.ne.jp, pos3 indicates
  283. * the index of the 0x2000 step.
  284. * beware different number of pages [hs]
  285. */
  286. dev->mem_start = (unsigned long)
  287. mca_device_transform_memory(mca_dev, (void *)(0xc0000 + (0x2000 * (pos3 & 0xf))));
  288. num_pages = 0x20 + (2 * (pos3 & 0x10));
  289. break;
  290. }
  291. }
  292. /* sanity check, shouldn't happen */
  293. if (dev->mem_start == 0) {
  294. rc = -ENODEV;
  295. goto err_unclaim;
  296. }
  297. if (!request_region(ioaddr, ULTRA_IO_EXTENT, DRV_NAME)) {
  298. rc = -ENODEV;
  299. goto err_unclaim;
  300. }
  301. reg4 = inb(ioaddr + 4) & 0x7f;
  302. outb(reg4, ioaddr + 4);
  303. for (i = 0; i < 6; i++)
  304. dev->dev_addr[i] = inb(ioaddr + 8 + i);
  305. printk(KERN_INFO "smc_mca[%d]: Parameters: %#3x, %pM",
  306. slot + 1, ioaddr, dev->dev_addr);
  307. /* Switch from the station address to the alternate register set
  308. * and read the useful registers there.
  309. */
  310. outb(0x80 | reg4, ioaddr + 4);
  311. /* Enable FINE16 mode to avoid BIOS ROM width mismatches @ reboot.
  312. */
  313. outb(0x80 | inb(ioaddr + 0x0c), ioaddr + 0x0c);
  314. /* Switch back to the station address register set so that
  315. * the MS-DOS driver can find the card after a warm boot.
  316. */
  317. outb(reg4, ioaddr + 4);
  318. gen_dev->driver_data = dev;
  319. /* The 8390 isn't at the base address, so fake the offset
  320. */
  321. dev->base_addr = ioaddr + ULTRA_NIC_OFFSET;
  322. ei_status.name = "SMC Ultra MCA";
  323. ei_status.word16 = 1;
  324. ei_status.tx_start_page = START_PG;
  325. ei_status.rx_start_page = START_PG + TX_PAGES;
  326. ei_status.stop_page = num_pages;
  327. ei_status.mem = ioremap(dev->mem_start, (ei_status.stop_page - START_PG) * 256);
  328. if (!ei_status.mem) {
  329. rc = -ENOMEM;
  330. goto err_release_region;
  331. }
  332. dev->mem_end = dev->mem_start + (ei_status.stop_page - START_PG) * 256;
  333. printk(", IRQ %d memory %#lx-%#lx.\n",
  334. dev->irq, dev->mem_start, dev->mem_end - 1);
  335. ei_status.reset_8390 = &ultramca_reset_8390;
  336. ei_status.block_input = &ultramca_block_input;
  337. ei_status.block_output = &ultramca_block_output;
  338. ei_status.get_8390_hdr = &ultramca_get_8390_hdr;
  339. ei_status.priv = slot;
  340. dev->netdev_ops = &ultramca_netdev_ops;
  341. NS8390_init(dev, 0);
  342. rc = register_netdev(dev);
  343. if (rc)
  344. goto err_unmap;
  345. return 0;
  346. err_unmap:
  347. iounmap(ei_status.mem);
  348. err_release_region:
  349. release_region(ioaddr, ULTRA_IO_EXTENT);
  350. err_unclaim:
  351. mca_device_set_claim(mca_dev, 0);
  352. free_netdev(dev);
  353. return rc;
  354. }
  355. static int ultramca_open(struct net_device *dev)
  356. {
  357. int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC addr */
  358. int retval;
  359. if ((retval = request_irq(dev->irq, ei_interrupt, 0, dev->name, dev)))
  360. return retval;
  361. outb(ULTRA_MEMENB, ioaddr); /* Enable memory */
  362. outb(0x80, ioaddr + 5); /* ??? */
  363. outb(0x01, ioaddr + 6); /* Enable interrupts and memory. */
  364. outb(0x04, ioaddr + 5); /* ??? */
  365. /* Set the early receive warning level in window 0 high enough not
  366. * to receive ERW interrupts.
  367. */
  368. /* outb_p(E8390_NODMA + E8390_PAGE0, dev->base_addr);
  369. * outb(0xff, dev->base_addr + EN0_ERWCNT);
  370. */
  371. ei_open(dev);
  372. return 0;
  373. }
  374. static void ultramca_reset_8390(struct net_device *dev)
  375. {
  376. int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC addr */
  377. outb(ULTRA_RESET, ioaddr);
  378. if (ei_debug > 1)
  379. printk("resetting Ultra, t=%ld...", jiffies);
  380. ei_status.txing = 0;
  381. outb(0x80, ioaddr + 5); /* ??? */
  382. outb(0x01, ioaddr + 6); /* Enable interrupts and memory. */
  383. if (ei_debug > 1)
  384. printk("reset done\n");
  385. return;
  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 = (struct net_device *)gen_dev->driver_data;
  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);