smc-ultra32.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. /* smc-ultra32.c: An SMC Ultra32 EISA ethernet driver for linux.
  2. Sources:
  3. This driver is based on (cloned from) the ISA SMC Ultra driver
  4. written by Donald Becker. Modifications to support the EISA
  5. version of the card by Paul Gortmaker and Leonard N. Zubkoff.
  6. This software may be used and distributed according to the terms
  7. of the GNU General Public License, incorporated herein by reference.
  8. Theory of Operation:
  9. The SMC Ultra32C card uses the SMC 83c790 chip which is also
  10. found on the ISA SMC Ultra cards. It has a shared memory mode of
  11. operation that makes it similar to the ISA version of the card.
  12. The main difference is that the EISA card has 32KB of RAM, but
  13. only an 8KB window into that memory. The EISA card also can be
  14. set for a bus-mastering mode of operation via the ECU, but that
  15. is not (and probably will never be) supported by this driver.
  16. The ECU should be run to enable shared memory and to disable the
  17. bus-mastering feature for use with linux.
  18. By programming the 8390 to use only 8KB RAM, the modifications
  19. to the ISA driver can be limited to the probe and initialization
  20. code. This allows easy integration of EISA support into the ISA
  21. driver. However, the driver development kit from SMC provided the
  22. register information for sliding the 8KB window, and hence the 8390
  23. is programmed to use the full 32KB RAM.
  24. Unfortunately this required code changes outside the probe/init
  25. routines, and thus we decided to separate the EISA driver from
  26. the ISA one. In this way, ISA users don't end up with a larger
  27. driver due to the EISA code, and EISA users don't end up with a
  28. larger driver due to the ISA EtherEZ PIO code. The driver is
  29. similar to the 3c503/16 driver, in that the window must be set
  30. back to the 1st 8KB of space for access to the two 8390 Tx slots.
  31. In testing, using only 8KB RAM (3 Tx / 5 Rx) didn't appear to
  32. be a limiting factor, since the EISA bus could get packets off
  33. the card fast enough, but having the use of lots of RAM as Rx
  34. space is extra insurance if interrupt latencies become excessive.
  35. */
  36. static const char *version = "smc-ultra32.c: 06/97 v1.00\n";
  37. #include <linux/module.h>
  38. #include <linux/eisa.h>
  39. #include <linux/kernel.h>
  40. #include <linux/errno.h>
  41. #include <linux/string.h>
  42. #include <linux/init.h>
  43. #include <linux/interrupt.h>
  44. #include <linux/netdevice.h>
  45. #include <linux/etherdevice.h>
  46. #include <asm/io.h>
  47. #include <asm/system.h>
  48. #include "8390.h"
  49. #define DRV_NAME "smc-ultra32"
  50. static int ultra32_probe1(struct net_device *dev, int ioaddr);
  51. static int ultra32_open(struct net_device *dev);
  52. static void ultra32_reset_8390(struct net_device *dev);
  53. static void ultra32_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
  54. int ring_page);
  55. static void ultra32_block_input(struct net_device *dev, int count,
  56. struct sk_buff *skb, int ring_offset);
  57. static void ultra32_block_output(struct net_device *dev, int count,
  58. const unsigned char *buf,
  59. const int start_page);
  60. static int ultra32_close(struct net_device *dev);
  61. #define ULTRA32_CMDREG 0 /* Offset to ASIC command register. */
  62. #define ULTRA32_RESET 0x80 /* Board reset, in ULTRA32_CMDREG. */
  63. #define ULTRA32_MEMENB 0x40 /* Enable the shared memory. */
  64. #define ULTRA32_NIC_OFFSET 16 /* NIC register offset from the base_addr. */
  65. #define ULTRA32_IO_EXTENT 32
  66. #define EN0_ERWCNT 0x08 /* Early receive warning count. */
  67. /*
  68. * Defines that apply only to the Ultra32 EISA card. Note that
  69. * "smc" = 10011 01101 00011 = 0x4da3, and hence !smc8010.cfg translates
  70. * into an EISA ID of 0x1080A34D
  71. */
  72. #define ULTRA32_BASE 0xca0
  73. #define ULTRA32_ID 0x1080a34d
  74. #define ULTRA32_IDPORT (-0x20) /* 0xc80 */
  75. /* Config regs 1->7 from the EISA !SMC8010.CFG file. */
  76. #define ULTRA32_CFG1 0x04 /* 0xca4 */
  77. #define ULTRA32_CFG2 0x05 /* 0xca5 */
  78. #define ULTRA32_CFG3 (-0x18) /* 0xc88 */
  79. #define ULTRA32_CFG4 (-0x17) /* 0xc89 */
  80. #define ULTRA32_CFG5 (-0x16) /* 0xc8a */
  81. #define ULTRA32_CFG6 (-0x15) /* 0xc8b */
  82. #define ULTRA32_CFG7 0x0d /* 0xcad */
  83. static void cleanup_card(struct net_device *dev)
  84. {
  85. int ioaddr = dev->base_addr - ULTRA32_NIC_OFFSET;
  86. /* NB: ultra32_close_card() does free_irq */
  87. release_region(ioaddr, ULTRA32_IO_EXTENT);
  88. iounmap(ei_status.mem);
  89. }
  90. /* Probe for the Ultra32. This looks like a 8013 with the station
  91. address PROM at I/O ports <base>+8 to <base>+13, with a checksum
  92. following.
  93. */
  94. struct net_device * __init ultra32_probe(int unit)
  95. {
  96. struct net_device *dev;
  97. int base;
  98. int irq;
  99. int err = -ENODEV;
  100. if (!EISA_bus)
  101. return ERR_PTR(-ENODEV);
  102. dev = alloc_ei_netdev();
  103. if (!dev)
  104. return ERR_PTR(-ENOMEM);
  105. if (unit >= 0) {
  106. sprintf(dev->name, "eth%d", unit);
  107. netdev_boot_setup_check(dev);
  108. }
  109. SET_MODULE_OWNER(dev);
  110. irq = dev->irq;
  111. /* EISA spec allows for up to 16 slots, but 8 is typical. */
  112. for (base = 0x1000 + ULTRA32_BASE; base < 0x9000; base += 0x1000) {
  113. if (ultra32_probe1(dev, base) == 0)
  114. break;
  115. dev->irq = irq;
  116. }
  117. if (base >= 0x9000)
  118. goto out;
  119. err = register_netdev(dev);
  120. if (err)
  121. goto out1;
  122. return dev;
  123. out1:
  124. cleanup_card(dev);
  125. out:
  126. free_netdev(dev);
  127. return ERR_PTR(err);
  128. }
  129. static int __init ultra32_probe1(struct net_device *dev, int ioaddr)
  130. {
  131. int i, edge, media, retval;
  132. int checksum = 0;
  133. const char *model_name;
  134. static unsigned version_printed;
  135. /* Values from various config regs. */
  136. unsigned char idreg;
  137. unsigned char reg4;
  138. const char *ifmap[] = {"UTP No Link", "", "UTP/AUI", "UTP/BNC"};
  139. if (!request_region(ioaddr, ULTRA32_IO_EXTENT, DRV_NAME))
  140. return -EBUSY;
  141. if (inb(ioaddr + ULTRA32_IDPORT) == 0xff ||
  142. inl(ioaddr + ULTRA32_IDPORT) != ULTRA32_ID) {
  143. retval = -ENODEV;
  144. goto out;
  145. }
  146. media = inb(ioaddr + ULTRA32_CFG7) & 0x03;
  147. edge = inb(ioaddr + ULTRA32_CFG5) & 0x08;
  148. printk("SMC Ultra32 in EISA Slot %d, Media: %s, %s IRQs.\n",
  149. ioaddr >> 12, ifmap[media],
  150. (edge ? "Edge Triggered" : "Level Sensitive"));
  151. idreg = inb(ioaddr + 7);
  152. reg4 = inb(ioaddr + 4) & 0x7f;
  153. /* Check the ID nibble. */
  154. if ((idreg & 0xf0) != 0x20) { /* SMC Ultra */
  155. retval = -ENODEV;
  156. goto out;
  157. }
  158. /* Select the station address register set. */
  159. outb(reg4, ioaddr + 4);
  160. for (i = 0; i < 8; i++)
  161. checksum += inb(ioaddr + 8 + i);
  162. if ((checksum & 0xff) != 0xff) {
  163. retval = -ENODEV;
  164. goto out;
  165. }
  166. if (ei_debug && version_printed++ == 0)
  167. printk(version);
  168. model_name = "SMC Ultra32";
  169. printk("%s: %s at 0x%X,", dev->name, model_name, ioaddr);
  170. for (i = 0; i < 6; i++)
  171. printk(" %2.2X", dev->dev_addr[i] = inb(ioaddr + 8 + i));
  172. /* Switch from the station address to the alternate register set and
  173. read the useful registers there. */
  174. outb(0x80 | reg4, ioaddr + 4);
  175. /* Enable FINE16 mode to avoid BIOS ROM width mismatches @ reboot. */
  176. outb(0x80 | inb(ioaddr + 0x0c), ioaddr + 0x0c);
  177. /* Reset RAM addr. */
  178. outb(0x00, ioaddr + 0x0b);
  179. /* Switch back to the station address register set so that the
  180. MS-DOS driver can find the card after a warm boot. */
  181. outb(reg4, ioaddr + 4);
  182. if ((inb(ioaddr + ULTRA32_CFG5) & 0x40) == 0) {
  183. printk("\nsmc-ultra32: Card RAM is disabled! "
  184. "Run EISA config utility.\n");
  185. retval = -ENODEV;
  186. goto out;
  187. }
  188. if ((inb(ioaddr + ULTRA32_CFG2) & 0x04) == 0)
  189. printk("\nsmc-ultra32: Ignoring Bus-Master enable bit. "
  190. "Run EISA config utility.\n");
  191. if (dev->irq < 2) {
  192. unsigned char irqmap[] = {0, 9, 3, 5, 7, 10, 11, 15};
  193. int irq = irqmap[inb(ioaddr + ULTRA32_CFG5) & 0x07];
  194. if (irq == 0) {
  195. printk(", failed to detect IRQ line.\n");
  196. retval = -EAGAIN;
  197. goto out;
  198. }
  199. dev->irq = irq;
  200. }
  201. /* The 8390 isn't at the base address, so fake the offset */
  202. dev->base_addr = ioaddr + ULTRA32_NIC_OFFSET;
  203. /* Save RAM address in the unused reg0 to avoid excess inb's. */
  204. ei_status.reg0 = inb(ioaddr + ULTRA32_CFG3) & 0xfc;
  205. dev->mem_start = 0xc0000 + ((ei_status.reg0 & 0x7c) << 11);
  206. ei_status.name = model_name;
  207. ei_status.word16 = 1;
  208. ei_status.tx_start_page = 0;
  209. ei_status.rx_start_page = TX_PAGES;
  210. /* All Ultra32 cards have 32KB memory with an 8KB window. */
  211. ei_status.stop_page = 128;
  212. ei_status.mem = ioremap(dev->mem_start, 0x2000);
  213. if (!ei_status.mem) {
  214. printk(", failed to ioremap.\n");
  215. retval = -ENOMEM;
  216. goto out;
  217. }
  218. dev->mem_end = dev->mem_start + 0x1fff;
  219. printk(", IRQ %d, 32KB memory, 8KB window at 0x%lx-0x%lx.\n",
  220. dev->irq, dev->mem_start, dev->mem_end);
  221. ei_status.block_input = &ultra32_block_input;
  222. ei_status.block_output = &ultra32_block_output;
  223. ei_status.get_8390_hdr = &ultra32_get_8390_hdr;
  224. ei_status.reset_8390 = &ultra32_reset_8390;
  225. dev->open = &ultra32_open;
  226. dev->stop = &ultra32_close;
  227. #ifdef CONFIG_NET_POLL_CONTROLLER
  228. dev->poll_controller = ei_poll;
  229. #endif
  230. NS8390_init(dev, 0);
  231. return 0;
  232. out:
  233. release_region(ioaddr, ULTRA32_IO_EXTENT);
  234. return retval;
  235. }
  236. static int ultra32_open(struct net_device *dev)
  237. {
  238. int ioaddr = dev->base_addr - ULTRA32_NIC_OFFSET; /* ASIC addr */
  239. int irq_flags = (inb(ioaddr + ULTRA32_CFG5) & 0x08) ? 0 : IRQF_SHARED;
  240. int retval;
  241. retval = request_irq(dev->irq, ei_interrupt, irq_flags, dev->name, dev);
  242. if (retval)
  243. return retval;
  244. outb(ULTRA32_MEMENB, ioaddr); /* Enable Shared Memory. */
  245. outb(0x80, ioaddr + ULTRA32_CFG6); /* Enable Interrupts. */
  246. outb(0x84, ioaddr + 5); /* Enable MEM16 & Disable Bus Master. */
  247. outb(0x01, ioaddr + 6); /* Enable Interrupts. */
  248. /* Set the early receive warning level in window 0 high enough not
  249. to receive ERW interrupts. */
  250. outb_p(E8390_NODMA+E8390_PAGE0, dev->base_addr);
  251. outb(0xff, dev->base_addr + EN0_ERWCNT);
  252. ei_open(dev);
  253. return 0;
  254. }
  255. static int ultra32_close(struct net_device *dev)
  256. {
  257. int ioaddr = dev->base_addr - ULTRA32_NIC_OFFSET; /* CMDREG */
  258. netif_stop_queue(dev);
  259. if (ei_debug > 1)
  260. printk("%s: Shutting down ethercard.\n", dev->name);
  261. outb(0x00, ioaddr + ULTRA32_CFG6); /* Disable Interrupts. */
  262. outb(0x00, ioaddr + 6); /* Disable interrupts. */
  263. free_irq(dev->irq, dev);
  264. NS8390_init(dev, 0);
  265. return 0;
  266. }
  267. static void ultra32_reset_8390(struct net_device *dev)
  268. {
  269. int ioaddr = dev->base_addr - ULTRA32_NIC_OFFSET; /* ASIC base addr */
  270. outb(ULTRA32_RESET, ioaddr);
  271. if (ei_debug > 1) printk("resetting Ultra32, t=%ld...", jiffies);
  272. ei_status.txing = 0;
  273. outb(ULTRA32_MEMENB, ioaddr); /* Enable Shared Memory. */
  274. outb(0x80, ioaddr + ULTRA32_CFG6); /* Enable Interrupts. */
  275. outb(0x84, ioaddr + 5); /* Enable MEM16 & Disable Bus Master. */
  276. outb(0x01, ioaddr + 6); /* Enable Interrupts. */
  277. if (ei_debug > 1) printk("reset done\n");
  278. return;
  279. }
  280. /* Grab the 8390 specific header. Similar to the block_input routine, but
  281. we don't need to be concerned with ring wrap as the header will be at
  282. the start of a page, so we optimize accordingly. */
  283. static void ultra32_get_8390_hdr(struct net_device *dev,
  284. struct e8390_pkt_hdr *hdr,
  285. int ring_page)
  286. {
  287. void __iomem *hdr_start = ei_status.mem + ((ring_page & 0x1f) << 8);
  288. unsigned int RamReg = dev->base_addr - ULTRA32_NIC_OFFSET + ULTRA32_CFG3;
  289. /* Select correct 8KB Window. */
  290. outb(ei_status.reg0 | ((ring_page & 0x60) >> 5), RamReg);
  291. #ifdef __BIG_ENDIAN
  292. /* Officially this is what we are doing, but the readl() is faster */
  293. /* unfortunately it isn't endian aware of the struct */
  294. memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
  295. hdr->count = le16_to_cpu(hdr->count);
  296. #else
  297. ((unsigned int*)hdr)[0] = readl(hdr_start);
  298. #endif
  299. }
  300. /* Block input and output are easy on shared memory ethercards, the only
  301. complication is when the ring buffer wraps, or in this case, when a
  302. packet spans an 8KB boundary. Note that the current 8KB segment is
  303. already set by the get_8390_hdr routine. */
  304. static void ultra32_block_input(struct net_device *dev,
  305. int count,
  306. struct sk_buff *skb,
  307. int ring_offset)
  308. {
  309. void __iomem *xfer_start = ei_status.mem + (ring_offset & 0x1fff);
  310. unsigned int RamReg = dev->base_addr - ULTRA32_NIC_OFFSET + ULTRA32_CFG3;
  311. if ((ring_offset & ~0x1fff) != ((ring_offset + count - 1) & ~0x1fff)) {
  312. int semi_count = 8192 - (ring_offset & 0x1FFF);
  313. memcpy_fromio(skb->data, xfer_start, semi_count);
  314. count -= semi_count;
  315. if (ring_offset < 96*256) {
  316. /* Select next 8KB Window. */
  317. ring_offset += semi_count;
  318. outb(ei_status.reg0 | ((ring_offset & 0x6000) >> 13), RamReg);
  319. memcpy_fromio(skb->data + semi_count, ei_status.mem, count);
  320. } else {
  321. /* Select first 8KB Window. */
  322. outb(ei_status.reg0, RamReg);
  323. memcpy_fromio(skb->data + semi_count, ei_status.mem + TX_PAGES * 256, count);
  324. }
  325. } else {
  326. memcpy_fromio(skb->data, xfer_start, count);
  327. }
  328. }
  329. static void ultra32_block_output(struct net_device *dev,
  330. int count,
  331. const unsigned char *buf,
  332. int start_page)
  333. {
  334. void __iomem *xfer_start = ei_status.mem + (start_page<<8);
  335. unsigned int RamReg = dev->base_addr - ULTRA32_NIC_OFFSET + ULTRA32_CFG3;
  336. /* Select first 8KB Window. */
  337. outb(ei_status.reg0, RamReg);
  338. memcpy_toio(xfer_start, buf, count);
  339. }
  340. #ifdef MODULE
  341. #define MAX_ULTRA32_CARDS 4 /* Max number of Ultra cards per module */
  342. static struct net_device *dev_ultra[MAX_ULTRA32_CARDS];
  343. MODULE_DESCRIPTION("SMC Ultra32 EISA ethernet driver");
  344. MODULE_LICENSE("GPL");
  345. int __init init_module(void)
  346. {
  347. int this_dev, found = 0;
  348. for (this_dev = 0; this_dev < MAX_ULTRA32_CARDS; this_dev++) {
  349. struct net_device *dev = ultra32_probe(-1);
  350. if (IS_ERR(dev))
  351. break;
  352. dev_ultra[found++] = dev;
  353. }
  354. if (found)
  355. return 0;
  356. printk(KERN_WARNING "smc-ultra32.c: No SMC Ultra32 found.\n");
  357. return -ENXIO;
  358. }
  359. void __exit cleanup_module(void)
  360. {
  361. int this_dev;
  362. for (this_dev = 0; this_dev < MAX_ULTRA32_CARDS; this_dev++) {
  363. struct net_device *dev = dev_ultra[this_dev];
  364. if (dev) {
  365. unregister_netdev(dev);
  366. cleanup_card(dev);
  367. free_netdev(dev);
  368. }
  369. }
  370. }
  371. #endif /* MODULE */