ne2k-pci.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. // SPDX-License-Identifier: GPL-1.0+
  2. /* A Linux device driver for PCI NE2000 clones.
  3. *
  4. * Authors and other copyright holders:
  5. * 1992-2000 by Donald Becker, NE2000 core and various modifications.
  6. * 1995-1998 by Paul Gortmaker, core modifications and PCI support.
  7. * Copyright 1993 assigned to the United States Government as represented
  8. * by the Director, National Security Agency.
  9. *
  10. * This software may be used and distributed according to the terms of
  11. * the GNU General Public License (GPL), incorporated herein by reference.
  12. * Drivers based on or derived from this code fall under the GPL and must
  13. * retain the authorship, copyright and license notice. This file is not
  14. * a complete program and may only be used when the entire operating
  15. * system is licensed under the GPL.
  16. *
  17. * The author may be reached as becker@scyld.com, or C/O
  18. * Scyld Computing Corporation
  19. * 410 Severn Ave., Suite 210
  20. * Annapolis MD 21403
  21. *
  22. * Issues remaining:
  23. * People are making PCI NE2000 clones! Oh the horror, the horror...
  24. * Limited full-duplex support.
  25. */
  26. #define DRV_NAME "ne2k-pci"
  27. #define DRV_DESCRIPTION "PCI NE2000 clone driver"
  28. #define DRV_AUTHOR "Donald Becker / Paul Gortmaker"
  29. #define DRV_VERSION "1.03"
  30. #define DRV_RELDATE "9/22/2003"
  31. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  32. /* The user-configurable values.
  33. * These may be modified when a driver module is loaded.
  34. */
  35. /* More are supported, limit only on options */
  36. #define MAX_UNITS 8
  37. /* Used to pass the full-duplex flag, etc. */
  38. static int full_duplex[MAX_UNITS];
  39. static int options[MAX_UNITS];
  40. /* Force a non std. amount of memory. Units are 256 byte pages. */
  41. /* #define PACKETBUF_MEMSIZE 0x40 */
  42. #include <linux/module.h>
  43. #include <linux/kernel.h>
  44. #include <linux/errno.h>
  45. #include <linux/pci.h>
  46. #include <linux/init.h>
  47. #include <linux/interrupt.h>
  48. #include <linux/ethtool.h>
  49. #include <linux/netdevice.h>
  50. #include <linux/etherdevice.h>
  51. #include <linux/io.h>
  52. #include <asm/irq.h>
  53. #include <linux/uaccess.h>
  54. #include "8390.h"
  55. static int ne2k_msg_enable;
  56. static const int default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
  57. NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR);
  58. #if defined(__powerpc__)
  59. #define inl_le(addr) le32_to_cpu(inl(addr))
  60. #define inw_le(addr) le16_to_cpu(inw(addr))
  61. #endif
  62. MODULE_AUTHOR(DRV_AUTHOR);
  63. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  64. MODULE_VERSION(DRV_VERSION);
  65. MODULE_LICENSE("GPL");
  66. module_param_named(msg_enable, ne2k_msg_enable, int, 0444);
  67. module_param_array(options, int, NULL, 0);
  68. module_param_array(full_duplex, int, NULL, 0);
  69. MODULE_PARM_DESC(msg_enable, "Debug message level (see linux/netdevice.h for bitmap)");
  70. MODULE_PARM_DESC(options, "Bit 5: full duplex");
  71. MODULE_PARM_DESC(full_duplex, "full duplex setting(s) (1)");
  72. /* Some defines that people can play with if so inclined.
  73. */
  74. /* Use 32 bit data-movement operations instead of 16 bit. */
  75. #define USE_LONGIO
  76. /* Do we implement the read before write bugfix ? */
  77. /* #define NE_RW_BUGFIX */
  78. /* Flags. We rename an existing ei_status field to store flags!
  79. * Thus only the low 8 bits are usable for non-init-time flags.
  80. */
  81. #define ne2k_flags reg0
  82. enum {
  83. /* Chip can do only 16/32-bit xfers. */
  84. ONLY_16BIT_IO = 8, ONLY_32BIT_IO = 4,
  85. /* User override. */
  86. FORCE_FDX = 0x20,
  87. REALTEK_FDX = 0x40, HOLTEK_FDX = 0x80,
  88. STOP_PG_0x60 = 0x100,
  89. };
  90. enum ne2k_pci_chipsets {
  91. CH_RealTek_RTL_8029 = 0,
  92. CH_Winbond_89C940,
  93. CH_Compex_RL2000,
  94. CH_KTI_ET32P2,
  95. CH_NetVin_NV5000SC,
  96. CH_Via_86C926,
  97. CH_SureCom_NE34,
  98. CH_Winbond_W89C940F,
  99. CH_Holtek_HT80232,
  100. CH_Holtek_HT80229,
  101. CH_Winbond_89C940_8c4a,
  102. };
  103. static struct {
  104. char *name;
  105. int flags;
  106. } pci_clone_list[] = {
  107. {"RealTek RTL-8029(AS)", REALTEK_FDX},
  108. {"Winbond 89C940", 0},
  109. {"Compex RL2000", 0},
  110. {"KTI ET32P2", 0},
  111. {"NetVin NV5000SC", 0},
  112. {"Via 86C926", ONLY_16BIT_IO},
  113. {"SureCom NE34", 0},
  114. {"Winbond W89C940F", 0},
  115. {"Holtek HT80232", ONLY_16BIT_IO | HOLTEK_FDX},
  116. {"Holtek HT80229", ONLY_32BIT_IO | HOLTEK_FDX | STOP_PG_0x60 },
  117. {"Winbond W89C940(misprogrammed)", 0},
  118. {NULL,}
  119. };
  120. static const struct pci_device_id ne2k_pci_tbl[] = {
  121. { 0x10ec, 0x8029, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_RealTek_RTL_8029 },
  122. { 0x1050, 0x0940, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Winbond_89C940 },
  123. { 0x11f6, 0x1401, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Compex_RL2000 },
  124. { 0x8e2e, 0x3000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_KTI_ET32P2 },
  125. { 0x4a14, 0x5000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_NetVin_NV5000SC },
  126. { 0x1106, 0x0926, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Via_86C926 },
  127. { 0x10bd, 0x0e34, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_SureCom_NE34 },
  128. { 0x1050, 0x5a5a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Winbond_W89C940F },
  129. { 0x12c3, 0x0058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Holtek_HT80232 },
  130. { 0x12c3, 0x5598, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Holtek_HT80229 },
  131. { 0x8c4a, 0x1980, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Winbond_89C940_8c4a },
  132. { 0, }
  133. };
  134. MODULE_DEVICE_TABLE(pci, ne2k_pci_tbl);
  135. /* ---- No user-serviceable parts below ---- */
  136. #define NE_BASE (dev->base_addr)
  137. #define NE_CMD 0x00
  138. #define NE_DATAPORT 0x10 /* NatSemi-defined port window offset. */
  139. #define NE_RESET 0x1f /* Issue a read to reset, a write to clear. */
  140. #define NE_IO_EXTENT 0x20
  141. #define NESM_START_PG 0x40 /* First page of TX buffer */
  142. #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
  143. static int ne2k_pci_open(struct net_device *dev);
  144. static int ne2k_pci_close(struct net_device *dev);
  145. static void ne2k_pci_reset_8390(struct net_device *dev);
  146. static void ne2k_pci_get_8390_hdr(struct net_device *dev,
  147. struct e8390_pkt_hdr *hdr, int ring_page);
  148. static void ne2k_pci_block_input(struct net_device *dev, int count,
  149. struct sk_buff *skb, int ring_offset);
  150. static void ne2k_pci_block_output(struct net_device *dev, const int count,
  151. const unsigned char *buf,
  152. const int start_page);
  153. static const struct ethtool_ops ne2k_pci_ethtool_ops;
  154. /* NEx000-clone boards have a Station Address (SA) PROM (SAPROM) in the packet
  155. * buffer memory space. By-the-spec NE2000 clones have 0x57,0x57 in bytes
  156. * 0x0e,0x0f of the SAPROM, while other supposed NE2000 clones must be
  157. * detected by their SA prefix.
  158. *
  159. * Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
  160. * mode results in doubled values, which can be detected and compensated for.
  161. *
  162. * The probe is also responsible for initializing the card and filling
  163. * in the 'dev' and 'ei_status' structures.
  164. */
  165. static const struct net_device_ops ne2k_netdev_ops = {
  166. .ndo_open = ne2k_pci_open,
  167. .ndo_stop = ne2k_pci_close,
  168. .ndo_start_xmit = ei_start_xmit,
  169. .ndo_tx_timeout = ei_tx_timeout,
  170. .ndo_get_stats = ei_get_stats,
  171. .ndo_set_rx_mode = ei_set_multicast_list,
  172. .ndo_validate_addr = eth_validate_addr,
  173. .ndo_set_mac_address = eth_mac_addr,
  174. #ifdef CONFIG_NET_POLL_CONTROLLER
  175. .ndo_poll_controller = ei_poll,
  176. #endif
  177. };
  178. static int ne2k_pci_init_one(struct pci_dev *pdev,
  179. const struct pci_device_id *ent)
  180. {
  181. struct net_device *dev;
  182. int i;
  183. unsigned char SA_prom[32];
  184. int start_page, stop_page;
  185. int irq, reg0, chip_idx = ent->driver_data;
  186. static unsigned int fnd_cnt;
  187. long ioaddr;
  188. int flags = pci_clone_list[chip_idx].flags;
  189. struct ei_device *ei_local;
  190. fnd_cnt++;
  191. i = pci_enable_device(pdev);
  192. if (i)
  193. return i;
  194. ioaddr = pci_resource_start(pdev, 0);
  195. irq = pdev->irq;
  196. if (!ioaddr || ((pci_resource_flags(pdev, 0) & IORESOURCE_IO) == 0)) {
  197. dev_err(&pdev->dev, "no I/O resource at PCI BAR #0\n");
  198. goto err_out;
  199. }
  200. if (!request_region(ioaddr, NE_IO_EXTENT, DRV_NAME)) {
  201. dev_err(&pdev->dev, "I/O resource 0x%x @ 0x%lx busy\n",
  202. NE_IO_EXTENT, ioaddr);
  203. goto err_out;
  204. }
  205. reg0 = inb(ioaddr);
  206. if (reg0 == 0xFF)
  207. goto err_out_free_res;
  208. /* Do a preliminary verification that we have a 8390. */
  209. {
  210. int regd;
  211. outb(E8390_NODMA + E8390_PAGE1 + E8390_STOP, ioaddr + E8390_CMD);
  212. regd = inb(ioaddr + 0x0d);
  213. outb(0xff, ioaddr + 0x0d);
  214. outb(E8390_NODMA + E8390_PAGE0, ioaddr + E8390_CMD);
  215. /* Clear the counter by reading. */
  216. inb(ioaddr + EN0_COUNTER0);
  217. if (inb(ioaddr + EN0_COUNTER0) != 0) {
  218. outb(reg0, ioaddr);
  219. /* Restore the old values. */
  220. outb(regd, ioaddr + 0x0d);
  221. goto err_out_free_res;
  222. }
  223. }
  224. /* Allocate net_device, dev->priv; fill in 8390 specific dev fields. */
  225. dev = alloc_ei_netdev();
  226. if (!dev) {
  227. dev_err(&pdev->dev, "cannot allocate ethernet device\n");
  228. goto err_out_free_res;
  229. }
  230. dev->netdev_ops = &ne2k_netdev_ops;
  231. ei_local = netdev_priv(dev);
  232. ei_local->msg_enable = netif_msg_init(ne2k_msg_enable, default_msg_level);
  233. SET_NETDEV_DEV(dev, &pdev->dev);
  234. /* Reset card. Who knows what dain-bramaged state it was left in. */
  235. {
  236. unsigned long reset_start_time = jiffies;
  237. outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
  238. /* This looks like a horrible timing loop, but it should never
  239. * take more than a few cycles.
  240. */
  241. while ((inb(ioaddr + EN0_ISR) & ENISR_RESET) == 0)
  242. /* Limit wait: '2' avoids jiffy roll-over. */
  243. if (jiffies - reset_start_time > 2) {
  244. dev_err(&pdev->dev,
  245. "Card failure (no reset ack).\n");
  246. goto err_out_free_netdev;
  247. }
  248. /* Ack all intr. */
  249. outb(0xff, ioaddr + EN0_ISR);
  250. }
  251. /* Read the 16 bytes of station address PROM.
  252. * We must first initialize registers, similar
  253. * to NS8390_init(eifdev, 0).
  254. * We can't reliably read the SAPROM address without this.
  255. * (I learned the hard way!).
  256. */
  257. {
  258. struct {unsigned char value, offset; } program_seq[] = {
  259. /* Select page 0 */
  260. {E8390_NODMA + E8390_PAGE0 + E8390_STOP, E8390_CMD},
  261. /* Set word-wide access */
  262. {0x49, EN0_DCFG},
  263. /* Clear the count regs. */
  264. {0x00, EN0_RCNTLO},
  265. /* Mask completion IRQ */
  266. {0x00, EN0_RCNTHI},
  267. {0x00, EN0_IMR},
  268. {0xFF, EN0_ISR},
  269. /* 0x20 Set to monitor */
  270. {E8390_RXOFF, EN0_RXCR},
  271. /* 0x02 and loopback mode */
  272. {E8390_TXOFF, EN0_TXCR},
  273. {32, EN0_RCNTLO},
  274. {0x00, EN0_RCNTHI},
  275. /* DMA starting at 0x0000 */
  276. {0x00, EN0_RSARLO},
  277. {0x00, EN0_RSARHI},
  278. {E8390_RREAD+E8390_START, E8390_CMD},
  279. };
  280. for (i = 0; i < ARRAY_SIZE(program_seq); i++)
  281. outb(program_seq[i].value,
  282. ioaddr + program_seq[i].offset);
  283. }
  284. /* Note: all PCI cards have at least 16 bit access, so we don't have
  285. * to check for 8 bit cards. Most cards permit 32 bit access.
  286. */
  287. if (flags & ONLY_32BIT_IO) {
  288. for (i = 0; i < 4 ; i++)
  289. ((u32 *)SA_prom)[i] = le32_to_cpu(inl(ioaddr + NE_DATAPORT));
  290. } else
  291. for (i = 0; i < 32 /* sizeof(SA_prom )*/; i++)
  292. SA_prom[i] = inb(ioaddr + NE_DATAPORT);
  293. /* We always set the 8390 registers for word mode. */
  294. outb(0x49, ioaddr + EN0_DCFG);
  295. start_page = NESM_START_PG;
  296. stop_page = flags & STOP_PG_0x60 ? 0x60 : NESM_STOP_PG;
  297. /* Set up the rest of the parameters. */
  298. dev->irq = irq;
  299. dev->base_addr = ioaddr;
  300. pci_set_drvdata(pdev, dev);
  301. ei_status.name = pci_clone_list[chip_idx].name;
  302. ei_status.tx_start_page = start_page;
  303. ei_status.stop_page = stop_page;
  304. ei_status.word16 = 1;
  305. ei_status.ne2k_flags = flags;
  306. if (fnd_cnt < MAX_UNITS) {
  307. if (full_duplex[fnd_cnt] > 0 || (options[fnd_cnt] & FORCE_FDX))
  308. ei_status.ne2k_flags |= FORCE_FDX;
  309. }
  310. ei_status.rx_start_page = start_page + TX_PAGES;
  311. #ifdef PACKETBUF_MEMSIZE
  312. /* Allow the packet buffer size to be overridden by know-it-alls. */
  313. ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
  314. #endif
  315. ei_status.reset_8390 = &ne2k_pci_reset_8390;
  316. ei_status.block_input = &ne2k_pci_block_input;
  317. ei_status.block_output = &ne2k_pci_block_output;
  318. ei_status.get_8390_hdr = &ne2k_pci_get_8390_hdr;
  319. ei_status.priv = (unsigned long) pdev;
  320. dev->ethtool_ops = &ne2k_pci_ethtool_ops;
  321. NS8390_init(dev, 0);
  322. eth_hw_addr_set(dev, SA_prom);
  323. i = register_netdev(dev);
  324. if (i)
  325. goto err_out_free_netdev;
  326. netdev_info(dev, "%s found at %#lx, IRQ %d, %pM.\n",
  327. pci_clone_list[chip_idx].name, ioaddr, dev->irq,
  328. dev->dev_addr);
  329. return 0;
  330. err_out_free_netdev:
  331. free_netdev(dev);
  332. err_out_free_res:
  333. release_region(ioaddr, NE_IO_EXTENT);
  334. err_out:
  335. pci_disable_device(pdev);
  336. return -ENODEV;
  337. }
  338. /* Magic incantation sequence for full duplex on the supported cards.
  339. */
  340. static inline int set_realtek_fdx(struct net_device *dev)
  341. {
  342. long ioaddr = dev->base_addr;
  343. outb(0xC0 + E8390_NODMA, ioaddr + NE_CMD); /* Page 3 */
  344. outb(0xC0, ioaddr + 0x01); /* Enable writes to CONFIG3 */
  345. outb(0x40, ioaddr + 0x06); /* Enable full duplex */
  346. outb(0x00, ioaddr + 0x01); /* Disable writes to CONFIG3 */
  347. outb(E8390_PAGE0 + E8390_NODMA, ioaddr + NE_CMD); /* Page 0 */
  348. return 0;
  349. }
  350. static inline int set_holtek_fdx(struct net_device *dev)
  351. {
  352. long ioaddr = dev->base_addr;
  353. outb(inb(ioaddr + 0x20) | 0x80, ioaddr + 0x20);
  354. return 0;
  355. }
  356. static int ne2k_pci_set_fdx(struct net_device *dev)
  357. {
  358. if (ei_status.ne2k_flags & REALTEK_FDX)
  359. return set_realtek_fdx(dev);
  360. else if (ei_status.ne2k_flags & HOLTEK_FDX)
  361. return set_holtek_fdx(dev);
  362. return -EOPNOTSUPP;
  363. }
  364. static int ne2k_pci_open(struct net_device *dev)
  365. {
  366. int ret = request_irq(dev->irq, ei_interrupt, IRQF_SHARED,
  367. dev->name, dev);
  368. if (ret)
  369. return ret;
  370. if (ei_status.ne2k_flags & FORCE_FDX)
  371. ne2k_pci_set_fdx(dev);
  372. ei_open(dev);
  373. return 0;
  374. }
  375. static int ne2k_pci_close(struct net_device *dev)
  376. {
  377. ei_close(dev);
  378. free_irq(dev->irq, dev);
  379. return 0;
  380. }
  381. /* Hard reset the card. This used to pause for the same period that a
  382. * 8390 reset command required, but that shouldn't be necessary.
  383. */
  384. static void ne2k_pci_reset_8390(struct net_device *dev)
  385. {
  386. unsigned long reset_start_time = jiffies;
  387. struct ei_device *ei_local = netdev_priv(dev);
  388. netif_dbg(ei_local, hw, dev, "resetting the 8390 t=%ld...\n",
  389. jiffies);
  390. outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
  391. ei_status.txing = 0;
  392. ei_status.dmaing = 0;
  393. /* This check _should_not_ be necessary, omit eventually. */
  394. while ((inb(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
  395. if (jiffies - reset_start_time > 2) {
  396. netdev_err(dev, "%s did not complete.\n", __func__);
  397. break;
  398. }
  399. /* Ack intr. */
  400. outb(ENISR_RESET, NE_BASE + EN0_ISR);
  401. }
  402. /* Grab the 8390 specific header. Similar to the block_input routine, but
  403. * we don't need to be concerned with ring wrap as the header will be at
  404. * the start of a page, so we optimize accordingly.
  405. */
  406. static void ne2k_pci_get_8390_hdr(struct net_device *dev,
  407. struct e8390_pkt_hdr *hdr, int ring_page)
  408. {
  409. long nic_base = dev->base_addr;
  410. /* This *shouldn't* happen. If it does, it's the last thing you'll see
  411. */
  412. if (ei_status.dmaing) {
  413. netdev_err(dev, "DMAing conflict in %s [DMAstat:%d][irqlock:%d].\n",
  414. __func__, ei_status.dmaing, ei_status.irqlock);
  415. return;
  416. }
  417. ei_status.dmaing |= 0x01;
  418. outb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD);
  419. outb(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
  420. outb(0, nic_base + EN0_RCNTHI);
  421. outb(0, nic_base + EN0_RSARLO); /* On page boundary */
  422. outb(ring_page, nic_base + EN0_RSARHI);
  423. outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
  424. if (ei_status.ne2k_flags & ONLY_16BIT_IO) {
  425. insw(NE_BASE + NE_DATAPORT, hdr,
  426. sizeof(struct e8390_pkt_hdr) >> 1);
  427. } else {
  428. *(u32 *)hdr = le32_to_cpu(inl(NE_BASE + NE_DATAPORT));
  429. le16_to_cpus(&hdr->count);
  430. }
  431. /* Ack intr. */
  432. outb(ENISR_RDC, nic_base + EN0_ISR);
  433. ei_status.dmaing &= ~0x01;
  434. }
  435. /* Block input and output, similar to the Crynwr packet driver. If you
  436. *are porting to a new ethercard, look at the packet driver source for hints.
  437. *The NEx000 doesn't share the on-board packet memory -- you have to put
  438. *the packet out through the "remote DMA" dataport using outb.
  439. */
  440. static void ne2k_pci_block_input(struct net_device *dev, int count,
  441. struct sk_buff *skb, int ring_offset)
  442. {
  443. long nic_base = dev->base_addr;
  444. char *buf = skb->data;
  445. /* This *shouldn't* happen.
  446. * If it does, it's the last thing you'll see.
  447. */
  448. if (ei_status.dmaing) {
  449. netdev_err(dev, "DMAing conflict in %s [DMAstat:%d][irqlock:%d]\n",
  450. __func__, ei_status.dmaing, ei_status.irqlock);
  451. return;
  452. }
  453. ei_status.dmaing |= 0x01;
  454. if (ei_status.ne2k_flags & ONLY_32BIT_IO)
  455. count = (count + 3) & 0xFFFC;
  456. outb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD);
  457. outb(count & 0xff, nic_base + EN0_RCNTLO);
  458. outb(count >> 8, nic_base + EN0_RCNTHI);
  459. outb(ring_offset & 0xff, nic_base + EN0_RSARLO);
  460. outb(ring_offset >> 8, nic_base + EN0_RSARHI);
  461. outb(E8390_RREAD + E8390_START, nic_base + NE_CMD);
  462. if (ei_status.ne2k_flags & ONLY_16BIT_IO) {
  463. insw(NE_BASE + NE_DATAPORT, buf, count >> 1);
  464. if (count & 0x01)
  465. buf[count-1] = inb(NE_BASE + NE_DATAPORT);
  466. } else {
  467. insl(NE_BASE + NE_DATAPORT, buf, count >> 2);
  468. if (count & 3) {
  469. buf += count & ~3;
  470. if (count & 2) {
  471. __le16 *b = (__le16 *)buf;
  472. *b++ = cpu_to_le16(inw(NE_BASE + NE_DATAPORT));
  473. buf = (char *)b;
  474. }
  475. if (count & 1)
  476. *buf = inb(NE_BASE + NE_DATAPORT);
  477. }
  478. }
  479. /* Ack intr. */
  480. outb(ENISR_RDC, nic_base + EN0_ISR);
  481. ei_status.dmaing &= ~0x01;
  482. }
  483. static void ne2k_pci_block_output(struct net_device *dev, int count,
  484. const unsigned char *buf, const int start_page)
  485. {
  486. long nic_base = NE_BASE;
  487. unsigned long dma_start;
  488. /* On little-endian it's always safe to round the count up for
  489. * word writes.
  490. */
  491. if (ei_status.ne2k_flags & ONLY_32BIT_IO)
  492. count = (count + 3) & 0xFFFC;
  493. else
  494. if (count & 0x01)
  495. count++;
  496. /* This *shouldn't* happen.
  497. * If it does, it's the last thing you'll see.
  498. */
  499. if (ei_status.dmaing) {
  500. netdev_err(dev, "DMAing conflict in %s [DMAstat:%d][irqlock:%d]\n",
  501. __func__, ei_status.dmaing, ei_status.irqlock);
  502. return;
  503. }
  504. ei_status.dmaing |= 0x01;
  505. /* We should already be in page 0, but to be safe... */
  506. outb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
  507. #ifdef NE_RW_BUGFIX
  508. /* Handle the read-before-write bug the same way as the
  509. * Crynwr packet driver -- the NatSemi method doesn't work.
  510. * Actually this doesn't always work either, but if you have
  511. * problems with your NEx000 this is better than nothing!
  512. */
  513. outb(0x42, nic_base + EN0_RCNTLO);
  514. outb(0x00, nic_base + EN0_RCNTHI);
  515. outb(0x42, nic_base + EN0_RSARLO);
  516. outb(0x00, nic_base + EN0_RSARHI);
  517. outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
  518. #endif
  519. outb(ENISR_RDC, nic_base + EN0_ISR);
  520. /* Now the normal output. */
  521. outb(count & 0xff, nic_base + EN0_RCNTLO);
  522. outb(count >> 8, nic_base + EN0_RCNTHI);
  523. outb(0x00, nic_base + EN0_RSARLO);
  524. outb(start_page, nic_base + EN0_RSARHI);
  525. outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
  526. if (ei_status.ne2k_flags & ONLY_16BIT_IO) {
  527. outsw(NE_BASE + NE_DATAPORT, buf, count >> 1);
  528. } else {
  529. outsl(NE_BASE + NE_DATAPORT, buf, count >> 2);
  530. if (count & 3) {
  531. buf += count & ~3;
  532. if (count & 2) {
  533. __le16 *b = (__le16 *)buf;
  534. outw(le16_to_cpu(*b++), NE_BASE + NE_DATAPORT);
  535. buf = (char *)b;
  536. }
  537. }
  538. }
  539. dma_start = jiffies;
  540. while ((inb(nic_base + EN0_ISR) & ENISR_RDC) == 0)
  541. /* Avoid clock roll-over. */
  542. if (jiffies - dma_start > 2) {
  543. netdev_warn(dev, "timeout waiting for Tx RDC.\n");
  544. ne2k_pci_reset_8390(dev);
  545. NS8390_init(dev, 1);
  546. break;
  547. }
  548. /* Ack intr. */
  549. outb(ENISR_RDC, nic_base + EN0_ISR);
  550. ei_status.dmaing &= ~0x01;
  551. }
  552. static void ne2k_pci_get_drvinfo(struct net_device *dev,
  553. struct ethtool_drvinfo *info)
  554. {
  555. struct ei_device *ei = netdev_priv(dev);
  556. struct pci_dev *pci_dev = (struct pci_dev *) ei->priv;
  557. strscpy(info->driver, DRV_NAME, sizeof(info->driver));
  558. strscpy(info->version, DRV_VERSION, sizeof(info->version));
  559. strscpy(info->bus_info, pci_name(pci_dev), sizeof(info->bus_info));
  560. }
  561. static u32 ne2k_pci_get_msglevel(struct net_device *dev)
  562. {
  563. struct ei_device *ei_local = netdev_priv(dev);
  564. return ei_local->msg_enable;
  565. }
  566. static void ne2k_pci_set_msglevel(struct net_device *dev, u32 v)
  567. {
  568. struct ei_device *ei_local = netdev_priv(dev);
  569. ei_local->msg_enable = v;
  570. }
  571. static const struct ethtool_ops ne2k_pci_ethtool_ops = {
  572. .get_drvinfo = ne2k_pci_get_drvinfo,
  573. .get_msglevel = ne2k_pci_get_msglevel,
  574. .set_msglevel = ne2k_pci_set_msglevel,
  575. };
  576. static void ne2k_pci_remove_one(struct pci_dev *pdev)
  577. {
  578. struct net_device *dev = pci_get_drvdata(pdev);
  579. BUG_ON(!dev);
  580. unregister_netdev(dev);
  581. release_region(dev->base_addr, NE_IO_EXTENT);
  582. free_netdev(dev);
  583. pci_disable_device(pdev);
  584. }
  585. static int __maybe_unused ne2k_pci_suspend(struct device *dev_d)
  586. {
  587. struct net_device *dev = dev_get_drvdata(dev_d);
  588. netif_device_detach(dev);
  589. return 0;
  590. }
  591. static int __maybe_unused ne2k_pci_resume(struct device *dev_d)
  592. {
  593. struct net_device *dev = dev_get_drvdata(dev_d);
  594. NS8390_init(dev, 1);
  595. netif_device_attach(dev);
  596. return 0;
  597. }
  598. static SIMPLE_DEV_PM_OPS(ne2k_pci_pm_ops, ne2k_pci_suspend, ne2k_pci_resume);
  599. static struct pci_driver ne2k_driver = {
  600. .name = DRV_NAME,
  601. .probe = ne2k_pci_init_one,
  602. .remove = ne2k_pci_remove_one,
  603. .id_table = ne2k_pci_tbl,
  604. .driver.pm = &ne2k_pci_pm_ops,
  605. };
  606. module_pci_driver(ne2k_driver);