smc-mca.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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 int __init ultramca_probe(struct device *gen_dev)
  160. {
  161. unsigned short ioaddr;
  162. struct net_device *dev;
  163. unsigned char reg4, num_pages;
  164. struct mca_device *mca_dev = to_mca_device(gen_dev);
  165. char slot = mca_dev->slot;
  166. unsigned char pos2 = 0xff, pos3 = 0xff, pos4 = 0xff, pos5 = 0xff;
  167. int i, rc;
  168. int adapter = mca_dev->index;
  169. int tbase = 0;
  170. int tirq = 0;
  171. int base_addr = ultra_io[ultra_found];
  172. int irq = ultra_irq[ultra_found];
  173. if (base_addr || irq) {
  174. printk(KERN_INFO "Probing for SMC MCA adapter");
  175. if (base_addr) {
  176. printk(KERN_INFO " at I/O address 0x%04x%c",
  177. base_addr, irq ? ' ' : '\n');
  178. }
  179. if (irq) {
  180. printk(KERN_INFO "using irq %d\n", irq);
  181. }
  182. }
  183. tirq = 0;
  184. tbase = 0;
  185. /* If we're trying to match a specificied irq or io address,
  186. * we'll reject the adapter found unless it's the one we're
  187. * looking for */
  188. pos2 = mca_device_read_stored_pos(mca_dev, 2); /* io_addr */
  189. pos3 = mca_device_read_stored_pos(mca_dev, 3); /* shared mem */
  190. pos4 = mca_device_read_stored_pos(mca_dev, 4); /* ROM bios addr range */
  191. pos5 = mca_device_read_stored_pos(mca_dev, 5); /* irq, media and RIPL */
  192. /* Test the following conditions:
  193. * - If an irq parameter is supplied, compare it
  194. * with the irq of the adapter we found
  195. * - If a base_addr paramater is given, compare it
  196. * with the base_addr of the adapter we found
  197. * - Check that the irq and the base_addr of the
  198. * adapter we found is not already in use by
  199. * this driver
  200. */
  201. switch (mca_dev->index) {
  202. case _61c8_SMC_Ethercard_PLUS_Elite_A_BNC_AUI_WD8013EP_A:
  203. case _61c9_SMC_Ethercard_PLUS_Elite_A_UTP_AUI_WD8013EP_A:
  204. case _efd4_IBM_PS2_Adapter_A_for_Ethernet_UTP_AUI_WD8013WP_A:
  205. case _efd5_IBM_PS2_Adapter_A_for_Ethernet_BNC_AUI_WD8013WP_A:
  206. {
  207. tbase = addr_table[(pos2 & 0xf0) >> 4].base_addr;
  208. tirq = irq_table[(pos5 & 0xc) >> 2].new_irq;
  209. break;
  210. }
  211. case _6fc0_WD_Ethercard_PLUS_A_WD8003E_A_OR_WD8003ET_A:
  212. case _6fc1_WD_Starcard_PLUS_A_WD8003ST_A:
  213. case _6fc2_WD_Ethercard_PLUS_10T_A_WD8003W_A:
  214. case _efe5_IBM_PS2_Adapter_A_for_Ethernet:
  215. {
  216. tbase = ((pos2 & 0x0fe) * 0x10);
  217. tirq = irq_table[(pos5 & 3)].old_irq;
  218. break;
  219. }
  220. }
  221. if(!tirq || !tbase
  222. || (irq && irq != tirq)
  223. || (base_addr && tbase != base_addr))
  224. /* FIXME: we're trying to force the ordering of the
  225. * devices here, there should be a way of getting this
  226. * to happen */
  227. return -ENXIO;
  228. /* Adapter found. */
  229. dev = alloc_ei_netdev();
  230. if(!dev)
  231. return -ENODEV;
  232. SET_MODULE_OWNER(dev);
  233. SET_NETDEV_DEV(dev, gen_dev);
  234. mca_device_set_name(mca_dev, smc_mca_adapter_names[adapter]);
  235. mca_device_set_claim(mca_dev, 1);
  236. printk(KERN_INFO "smc_mca: %s found in slot %d\n",
  237. smc_mca_adapter_names[adapter], slot + 1);
  238. ultra_found++;
  239. dev->base_addr = ioaddr = mca_device_transform_ioport(mca_dev, tbase);
  240. dev->irq = mca_device_transform_irq(mca_dev, tirq);
  241. dev->mem_start = 0;
  242. num_pages = 40;
  243. switch (adapter) { /* card-# in const array above [hs] */
  244. case _61c8_SMC_Ethercard_PLUS_Elite_A_BNC_AUI_WD8013EP_A:
  245. case _61c9_SMC_Ethercard_PLUS_Elite_A_UTP_AUI_WD8013EP_A:
  246. {
  247. for (i = 0; i < 16; i++) { /* taking 16 counts
  248. * up to 15 [hs] */
  249. if (mem_table[i].mem_index == (pos3 & ~MEM_MASK)) {
  250. dev->mem_start = (unsigned long)
  251. mca_device_transform_memory(mca_dev, (void *)mem_table[i].mem_start);
  252. num_pages = mem_table[i].num_pages;
  253. }
  254. }
  255. break;
  256. }
  257. case _6fc0_WD_Ethercard_PLUS_A_WD8003E_A_OR_WD8003ET_A:
  258. case _6fc1_WD_Starcard_PLUS_A_WD8003ST_A:
  259. case _6fc2_WD_Ethercard_PLUS_10T_A_WD8003W_A:
  260. case _efe5_IBM_PS2_Adapter_A_for_Ethernet:
  261. {
  262. dev->mem_start = (unsigned long)
  263. mca_device_transform_memory(mca_dev, (void *)((pos3 & 0xfc) * 0x1000));
  264. num_pages = 0x40;
  265. break;
  266. }
  267. case _efd4_IBM_PS2_Adapter_A_for_Ethernet_UTP_AUI_WD8013WP_A:
  268. case _efd5_IBM_PS2_Adapter_A_for_Ethernet_BNC_AUI_WD8013WP_A:
  269. {
  270. /* courtesy of gamera@quartz.ocn.ne.jp, pos3 indicates
  271. * the index of the 0x2000 step.
  272. * beware different number of pages [hs]
  273. */
  274. dev->mem_start = (unsigned long)
  275. mca_device_transform_memory(mca_dev, (void *)(0xc0000 + (0x2000 * (pos3 & 0xf))));
  276. num_pages = 0x20 + (2 * (pos3 & 0x10));
  277. break;
  278. }
  279. }
  280. /* sanity check, shouldn't happen */
  281. if (dev->mem_start == 0) {
  282. rc = -ENODEV;
  283. goto err_unclaim;
  284. }
  285. if (!request_region(ioaddr, ULTRA_IO_EXTENT, DRV_NAME)) {
  286. rc = -ENODEV;
  287. goto err_unclaim;
  288. }
  289. reg4 = inb(ioaddr + 4) & 0x7f;
  290. outb(reg4, ioaddr + 4);
  291. printk(KERN_INFO "smc_mca[%d]: Parameters: %#3x,", slot + 1, ioaddr);
  292. for (i = 0; i < 6; i++)
  293. printk(" %2.2X", dev->dev_addr[i] = inb(ioaddr + 8 + i));
  294. /* Switch from the station address to the alternate register set
  295. * and read the useful registers there.
  296. */
  297. outb(0x80 | reg4, ioaddr + 4);
  298. /* Enable FINE16 mode to avoid BIOS ROM width mismatches @ reboot.
  299. */
  300. outb(0x80 | inb(ioaddr + 0x0c), ioaddr + 0x0c);
  301. /* Switch back to the station address register set so that
  302. * the MS-DOS driver can find the card after a warm boot.
  303. */
  304. outb(reg4, ioaddr + 4);
  305. gen_dev->driver_data = dev;
  306. /* The 8390 isn't at the base address, so fake the offset
  307. */
  308. dev->base_addr = ioaddr + ULTRA_NIC_OFFSET;
  309. ei_status.name = "SMC Ultra MCA";
  310. ei_status.word16 = 1;
  311. ei_status.tx_start_page = START_PG;
  312. ei_status.rx_start_page = START_PG + TX_PAGES;
  313. ei_status.stop_page = num_pages;
  314. ei_status.mem = ioremap(dev->mem_start, (ei_status.stop_page - START_PG) * 256);
  315. if (!ei_status.mem) {
  316. rc = -ENOMEM;
  317. goto err_release_region;
  318. }
  319. dev->mem_end = dev->mem_start + (ei_status.stop_page - START_PG) * 256;
  320. printk(", IRQ %d memory %#lx-%#lx.\n",
  321. dev->irq, dev->mem_start, dev->mem_end - 1);
  322. ei_status.reset_8390 = &ultramca_reset_8390;
  323. ei_status.block_input = &ultramca_block_input;
  324. ei_status.block_output = &ultramca_block_output;
  325. ei_status.get_8390_hdr = &ultramca_get_8390_hdr;
  326. ei_status.priv = slot;
  327. dev->open = &ultramca_open;
  328. dev->stop = &ultramca_close_card;
  329. #ifdef CONFIG_NET_POLL_CONTROLLER
  330. dev->poll_controller = ei_poll;
  331. #endif
  332. NS8390_init(dev, 0);
  333. rc = register_netdev(dev);
  334. if (rc)
  335. goto err_unmap;
  336. return 0;
  337. err_unmap:
  338. iounmap(ei_status.mem);
  339. err_release_region:
  340. release_region(ioaddr, ULTRA_IO_EXTENT);
  341. err_unclaim:
  342. mca_device_set_claim(mca_dev, 0);
  343. free_netdev(dev);
  344. return rc;
  345. }
  346. static int ultramca_open(struct net_device *dev)
  347. {
  348. int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC addr */
  349. int retval;
  350. if ((retval = request_irq(dev->irq, ei_interrupt, 0, dev->name, dev)))
  351. return retval;
  352. outb(ULTRA_MEMENB, ioaddr); /* Enable memory */
  353. outb(0x80, ioaddr + 5); /* ??? */
  354. outb(0x01, ioaddr + 6); /* Enable interrupts and memory. */
  355. outb(0x04, ioaddr + 5); /* ??? */
  356. /* Set the early receive warning level in window 0 high enough not
  357. * to receive ERW interrupts.
  358. */
  359. /* outb_p(E8390_NODMA + E8390_PAGE0, dev->base_addr);
  360. * outb(0xff, dev->base_addr + EN0_ERWCNT);
  361. */
  362. ei_open(dev);
  363. return 0;
  364. }
  365. static void ultramca_reset_8390(struct net_device *dev)
  366. {
  367. int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC addr */
  368. outb(ULTRA_RESET, ioaddr);
  369. if (ei_debug > 1)
  370. printk("resetting Ultra, t=%ld...", jiffies);
  371. ei_status.txing = 0;
  372. outb(0x80, ioaddr + 5); /* ??? */
  373. outb(0x01, ioaddr + 6); /* Enable interrupts and memory. */
  374. if (ei_debug > 1)
  375. printk("reset done\n");
  376. return;
  377. }
  378. /* Grab the 8390 specific header. Similar to the block_input routine, but
  379. * we don't need to be concerned with ring wrap as the header will be at
  380. * the start of a page, so we optimize accordingly.
  381. */
  382. static void ultramca_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  383. {
  384. void __iomem *hdr_start = ei_status.mem + ((ring_page - START_PG) << 8);
  385. #ifdef notdef
  386. /* Officially this is what we are doing, but the readl() is faster */
  387. memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
  388. #else
  389. ((unsigned int*)hdr)[0] = readl(hdr_start);
  390. #endif
  391. }
  392. /* Block input and output are easy on shared memory ethercards, the only
  393. * complication is when the ring buffer wraps.
  394. */
  395. static void ultramca_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
  396. {
  397. void __iomem *xfer_start = ei_status.mem + ring_offset - START_PG * 256;
  398. if (ring_offset + count > ei_status.stop_page * 256) {
  399. /* We must wrap the input move. */
  400. int semi_count = ei_status.stop_page * 256 - ring_offset;
  401. memcpy_fromio(skb->data, xfer_start, semi_count);
  402. count -= semi_count;
  403. memcpy_fromio(skb->data + semi_count, ei_status.mem + TX_PAGES * 256, count);
  404. } else {
  405. memcpy_fromio(skb->data, xfer_start, count);
  406. }
  407. }
  408. static void ultramca_block_output(struct net_device *dev, int count, const unsigned char *buf,
  409. int start_page)
  410. {
  411. void __iomem *shmem = ei_status.mem + ((start_page - START_PG) << 8);
  412. memcpy_toio(shmem, buf, count);
  413. }
  414. static int ultramca_close_card(struct net_device *dev)
  415. {
  416. int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC addr */
  417. netif_stop_queue(dev);
  418. if (ei_debug > 1)
  419. printk("%s: Shutting down ethercard.\n", dev->name);
  420. outb(0x00, ioaddr + 6); /* Disable interrupts. */
  421. free_irq(dev->irq, dev);
  422. NS8390_init(dev, 0);
  423. /* We should someday disable shared memory and change to 8-bit mode
  424. * "just in case"...
  425. */
  426. return 0;
  427. }
  428. static int ultramca_remove(struct device *gen_dev)
  429. {
  430. struct mca_device *mca_dev = to_mca_device(gen_dev);
  431. struct net_device *dev = (struct net_device *)gen_dev->driver_data;
  432. if (dev) {
  433. /* NB: ultra_close_card() does free_irq */
  434. int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET;
  435. unregister_netdev(dev);
  436. mca_device_set_claim(mca_dev, 0);
  437. release_region(ioaddr, ULTRA_IO_EXTENT);
  438. iounmap(ei_status.mem);
  439. free_netdev(dev);
  440. }
  441. return 0;
  442. }
  443. static struct mca_driver ultra_driver = {
  444. .id_table = smc_mca_adapter_ids,
  445. .driver = {
  446. .name = "smc-mca",
  447. .bus = &mca_bus_type,
  448. .probe = ultramca_probe,
  449. .remove = ultramca_remove,
  450. }
  451. };
  452. static int __init ultramca_init_module(void)
  453. {
  454. if(!MCA_bus)
  455. return -ENXIO;
  456. mca_register_driver(&ultra_driver);
  457. return ultra_found ? 0 : -ENXIO;
  458. }
  459. static void __exit ultramca_cleanup_module(void)
  460. {
  461. mca_unregister_driver(&ultra_driver);
  462. }
  463. module_init(ultramca_init_module);
  464. module_exit(ultramca_cleanup_module);