/kern_2.6.32/drivers/net/pcmcia/pcnet_cs.c

http://omnia2droid.googlecode.com/ · C · 1796 lines · 1365 code · 241 blank · 190 comment · 236 complexity · 5e1329eeac297689536d7b3d37d5fbb4 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*======================================================================
  2. A PCMCIA ethernet driver for NS8390-based cards
  3. This driver supports the D-Link DE-650 and Linksys EthernetCard
  4. cards, the newer D-Link and Linksys combo cards, Accton EN2212
  5. cards, the RPTI EP400, and the PreMax PE-200 in non-shared-memory
  6. mode, and the IBM Credit Card Adapter, the NE4100, the Thomas
  7. Conrad ethernet card, and the Kingston KNE-PCM/x in shared-memory
  8. mode. It will also handle the Socket EA card in either mode.
  9. Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net
  10. pcnet_cs.c 1.153 2003/11/09 18:53:09
  11. The network driver code is based on Donald Becker's NE2000 code:
  12. Written 1992,1993 by Donald Becker.
  13. Copyright 1993 United States Government as represented by the
  14. Director, National Security Agency. This software may be used and
  15. distributed according to the terms of the GNU General Public License,
  16. incorporated herein by reference.
  17. Donald Becker may be reached at becker@scyld.com
  18. Based also on Keith Moore's changes to Don Becker's code, for IBM
  19. CCAE support. Drivers merged back together, and shared-memory
  20. Socket EA support added, by Ken Raeburn, September 1995.
  21. ======================================================================*/
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/init.h>
  25. #include <linux/ptrace.h>
  26. #include <linux/slab.h>
  27. #include <linux/string.h>
  28. #include <linux/timer.h>
  29. #include <linux/delay.h>
  30. #include <linux/ethtool.h>
  31. #include <linux/netdevice.h>
  32. #include <linux/log2.h>
  33. #include <linux/etherdevice.h>
  34. #include <linux/mii.h>
  35. #include "../8390.h"
  36. #include <pcmcia/cs_types.h>
  37. #include <pcmcia/cs.h>
  38. #include <pcmcia/cistpl.h>
  39. #include <pcmcia/ciscode.h>
  40. #include <pcmcia/ds.h>
  41. #include <pcmcia/cisreg.h>
  42. #include <asm/io.h>
  43. #include <asm/system.h>
  44. #include <asm/byteorder.h>
  45. #include <asm/uaccess.h>
  46. #define PCNET_CMD 0x00
  47. #define PCNET_DATAPORT 0x10 /* NatSemi-defined port window offset. */
  48. #define PCNET_RESET 0x1f /* Issue a read to reset, a write to clear. */
  49. #define PCNET_MISC 0x18 /* For IBM CCAE and Socket EA cards */
  50. #define PCNET_START_PG 0x40 /* First page of TX buffer */
  51. #define PCNET_STOP_PG 0x80 /* Last page +1 of RX ring */
  52. /* Socket EA cards have a larger packet buffer */
  53. #define SOCKET_START_PG 0x01
  54. #define SOCKET_STOP_PG 0xff
  55. #define PCNET_RDC_TIMEOUT (2*HZ/100) /* Max wait in jiffies for Tx RDC */
  56. static const char *if_names[] = { "auto", "10baseT", "10base2"};
  57. #ifdef PCMCIA_DEBUG
  58. static int pc_debug = PCMCIA_DEBUG;
  59. module_param(pc_debug, int, 0);
  60. #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
  61. static char *version =
  62. "pcnet_cs.c 1.153 2003/11/09 18:53:09 (David Hinds)";
  63. #else
  64. #define DEBUG(n, args...)
  65. #endif
  66. /*====================================================================*/
  67. /* Module parameters */
  68. MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
  69. MODULE_DESCRIPTION("NE2000 compatible PCMCIA ethernet driver");
  70. MODULE_LICENSE("GPL");
  71. #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
  72. INT_MODULE_PARM(if_port, 1); /* Transceiver type */
  73. INT_MODULE_PARM(use_big_buf, 1); /* use 64K packet buffer? */
  74. INT_MODULE_PARM(mem_speed, 0); /* shared mem speed, in ns */
  75. INT_MODULE_PARM(delay_output, 0); /* pause after xmit? */
  76. INT_MODULE_PARM(delay_time, 4); /* in usec */
  77. INT_MODULE_PARM(use_shmem, -1); /* use shared memory? */
  78. INT_MODULE_PARM(full_duplex, 0); /* full duplex? */
  79. /* Ugh! Let the user hardwire the hardware address for queer cards */
  80. static int hw_addr[6] = { 0, /* ... */ };
  81. module_param_array(hw_addr, int, NULL, 0);
  82. /*====================================================================*/
  83. static void mii_phy_probe(struct net_device *dev);
  84. static int pcnet_config(struct pcmcia_device *link);
  85. static void pcnet_release(struct pcmcia_device *link);
  86. static int pcnet_open(struct net_device *dev);
  87. static int pcnet_close(struct net_device *dev);
  88. static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  89. static const struct ethtool_ops netdev_ethtool_ops;
  90. static irqreturn_t ei_irq_wrapper(int irq, void *dev_id);
  91. static void ei_watchdog(u_long arg);
  92. static void pcnet_reset_8390(struct net_device *dev);
  93. static int set_config(struct net_device *dev, struct ifmap *map);
  94. static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
  95. int stop_pg, int cm_offset);
  96. static int setup_dma_config(struct pcmcia_device *link, int start_pg,
  97. int stop_pg);
  98. static void pcnet_detach(struct pcmcia_device *p_dev);
  99. static dev_info_t dev_info = "pcnet_cs";
  100. /*====================================================================*/
  101. typedef struct hw_info_t {
  102. u_int offset;
  103. u_char a0, a1, a2;
  104. u_int flags;
  105. } hw_info_t;
  106. #define DELAY_OUTPUT 0x01
  107. #define HAS_MISC_REG 0x02
  108. #define USE_BIG_BUF 0x04
  109. #define HAS_IBM_MISC 0x08
  110. #define IS_DL10019 0x10
  111. #define IS_DL10022 0x20
  112. #define HAS_MII 0x40
  113. #define USE_SHMEM 0x80 /* autodetected */
  114. #define AM79C9XX_HOME_PHY 0x00006B90 /* HomePNA PHY */
  115. #define AM79C9XX_ETH_PHY 0x00006B70 /* 10baseT PHY */
  116. #define MII_PHYID_REV_MASK 0xfffffff0
  117. #define MII_PHYID_REG1 0x02
  118. #define MII_PHYID_REG2 0x03
  119. static hw_info_t hw_info[] = {
  120. { /* Accton EN2212 */ 0x0ff0, 0x00, 0x00, 0xe8, DELAY_OUTPUT },
  121. { /* Allied Telesis LA-PCM */ 0x0ff0, 0x00, 0x00, 0xf4, 0 },
  122. { /* APEX MultiCard */ 0x03f4, 0x00, 0x20, 0xe5, 0 },
  123. { /* ASANTE FriendlyNet */ 0x4910, 0x00, 0x00, 0x94,
  124. DELAY_OUTPUT | HAS_IBM_MISC },
  125. { /* Danpex EN-6200P2 */ 0x0110, 0x00, 0x40, 0xc7, 0 },
  126. { /* DataTrek NetCard */ 0x0ff0, 0x00, 0x20, 0xe8, 0 },
  127. { /* Dayna CommuniCard E */ 0x0110, 0x00, 0x80, 0x19, 0 },
  128. { /* D-Link DE-650 */ 0x0040, 0x00, 0x80, 0xc8, 0 },
  129. { /* EP-210 Ethernet */ 0x0110, 0x00, 0x40, 0x33, 0 },
  130. { /* EP4000 Ethernet */ 0x01c0, 0x00, 0x00, 0xb4, 0 },
  131. { /* Epson EEN10B */ 0x0ff0, 0x00, 0x00, 0x48,
  132. HAS_MISC_REG | HAS_IBM_MISC },
  133. { /* ELECOM Laneed LD-CDWA */ 0xb8, 0x08, 0x00, 0x42, 0 },
  134. { /* Hypertec Ethernet */ 0x01c0, 0x00, 0x40, 0x4c, 0 },
  135. { /* IBM CCAE */ 0x0ff0, 0x08, 0x00, 0x5a,
  136. HAS_MISC_REG | HAS_IBM_MISC },
  137. { /* IBM CCAE */ 0x0ff0, 0x00, 0x04, 0xac,
  138. HAS_MISC_REG | HAS_IBM_MISC },
  139. { /* IBM CCAE */ 0x0ff0, 0x00, 0x06, 0x29,
  140. HAS_MISC_REG | HAS_IBM_MISC },
  141. { /* IBM FME */ 0x0374, 0x08, 0x00, 0x5a,
  142. HAS_MISC_REG | HAS_IBM_MISC },
  143. { /* IBM FME */ 0x0374, 0x00, 0x04, 0xac,
  144. HAS_MISC_REG | HAS_IBM_MISC },
  145. { /* Kansai KLA-PCM/T */ 0x0ff0, 0x00, 0x60, 0x87,
  146. HAS_MISC_REG | HAS_IBM_MISC },
  147. { /* NSC DP83903 */ 0x0374, 0x08, 0x00, 0x17,
  148. HAS_MISC_REG | HAS_IBM_MISC },
  149. { /* NSC DP83903 */ 0x0374, 0x00, 0xc0, 0xa8,
  150. HAS_MISC_REG | HAS_IBM_MISC },
  151. { /* NSC DP83903 */ 0x0374, 0x00, 0xa0, 0xb0,
  152. HAS_MISC_REG | HAS_IBM_MISC },
  153. { /* NSC DP83903 */ 0x0198, 0x00, 0x20, 0xe0,
  154. HAS_MISC_REG | HAS_IBM_MISC },
  155. { /* I-O DATA PCLA/T */ 0x0ff0, 0x00, 0xa0, 0xb0, 0 },
  156. { /* Katron PE-520 */ 0x0110, 0x00, 0x40, 0xf6, 0 },
  157. { /* Kingston KNE-PCM/x */ 0x0ff0, 0x00, 0xc0, 0xf0,
  158. HAS_MISC_REG | HAS_IBM_MISC },
  159. { /* Kingston KNE-PCM/x */ 0x0ff0, 0xe2, 0x0c, 0x0f,
  160. HAS_MISC_REG | HAS_IBM_MISC },
  161. { /* Kingston KNE-PC2 */ 0x0180, 0x00, 0xc0, 0xf0, 0 },
  162. { /* Maxtech PCN2000 */ 0x5000, 0x00, 0x00, 0xe8, 0 },
  163. { /* NDC Instant-Link */ 0x003a, 0x00, 0x80, 0xc6, 0 },
  164. { /* NE2000 Compatible */ 0x0ff0, 0x00, 0xa0, 0x0c, 0 },
  165. { /* Network General Sniffer */ 0x0ff0, 0x00, 0x00, 0x65,
  166. HAS_MISC_REG | HAS_IBM_MISC },
  167. { /* Panasonic VEL211 */ 0x0ff0, 0x00, 0x80, 0x45,
  168. HAS_MISC_REG | HAS_IBM_MISC },
  169. { /* PreMax PE-200 */ 0x07f0, 0x00, 0x20, 0xe0, 0 },
  170. { /* RPTI EP400 */ 0x0110, 0x00, 0x40, 0x95, 0 },
  171. { /* SCM Ethernet */ 0x0ff0, 0x00, 0x20, 0xcb, 0 },
  172. { /* Socket EA */ 0x4000, 0x00, 0xc0, 0x1b,
  173. DELAY_OUTPUT | HAS_MISC_REG | USE_BIG_BUF },
  174. { /* Socket LP-E CF+ */ 0x01c0, 0x00, 0xc0, 0x1b, 0 },
  175. { /* SuperSocket RE450T */ 0x0110, 0x00, 0xe0, 0x98, 0 },
  176. { /* Volktek NPL-402CT */ 0x0060, 0x00, 0x40, 0x05, 0 },
  177. { /* NEC PC-9801N-J12 */ 0x0ff0, 0x00, 0x00, 0x4c, 0 },
  178. { /* PCMCIA Technology OEM */ 0x01c8, 0x00, 0xa0, 0x0c, 0 }
  179. };
  180. #define NR_INFO ARRAY_SIZE(hw_info)
  181. static hw_info_t default_info = { 0, 0, 0, 0, 0 };
  182. static hw_info_t dl10019_info = { 0, 0, 0, 0, IS_DL10019|HAS_MII };
  183. static hw_info_t dl10022_info = { 0, 0, 0, 0, IS_DL10022|HAS_MII };
  184. typedef struct pcnet_dev_t {
  185. struct pcmcia_device *p_dev;
  186. dev_node_t node;
  187. u_int flags;
  188. void __iomem *base;
  189. struct timer_list watchdog;
  190. int stale, fast_poll;
  191. u_char phy_id;
  192. u_char eth_phy, pna_phy;
  193. u_short link_status;
  194. u_long mii_reset;
  195. } pcnet_dev_t;
  196. static inline pcnet_dev_t *PRIV(struct net_device *dev)
  197. {
  198. char *p = netdev_priv(dev);
  199. return (pcnet_dev_t *)(p + sizeof(struct ei_device));
  200. }
  201. static const struct net_device_ops pcnet_netdev_ops = {
  202. .ndo_open = pcnet_open,
  203. .ndo_stop = pcnet_close,
  204. .ndo_set_config = set_config,
  205. .ndo_start_xmit = ei_start_xmit,
  206. .ndo_get_stats = ei_get_stats,
  207. .ndo_do_ioctl = ei_ioctl,
  208. .ndo_set_multicast_list = ei_set_multicast_list,
  209. .ndo_tx_timeout = ei_tx_timeout,
  210. .ndo_change_mtu = eth_change_mtu,
  211. .ndo_set_mac_address = eth_mac_addr,
  212. .ndo_validate_addr = eth_validate_addr,
  213. #ifdef CONFIG_NET_POLL_CONTROLLER
  214. .ndo_poll_controller = ei_poll,
  215. #endif
  216. };
  217. /*======================================================================
  218. pcnet_attach() creates an "instance" of the driver, allocating
  219. local data structures for one device. The device is registered
  220. with Card Services.
  221. ======================================================================*/
  222. static int pcnet_probe(struct pcmcia_device *link)
  223. {
  224. pcnet_dev_t *info;
  225. struct net_device *dev;
  226. DEBUG(0, "pcnet_attach()\n");
  227. /* Create new ethernet device */
  228. dev = __alloc_ei_netdev(sizeof(pcnet_dev_t));
  229. if (!dev) return -ENOMEM;
  230. info = PRIV(dev);
  231. info->p_dev = link;
  232. link->priv = dev;
  233. link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
  234. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  235. link->conf.Attributes = CONF_ENABLE_IRQ;
  236. link->conf.IntType = INT_MEMORY_AND_IO;
  237. dev->netdev_ops = &pcnet_netdev_ops;
  238. return pcnet_config(link);
  239. } /* pcnet_attach */
  240. /*======================================================================
  241. This deletes a driver "instance". The device is de-registered
  242. with Card Services. If it has been released, all local data
  243. structures are freed. Otherwise, the structures will be freed
  244. when the device is released.
  245. ======================================================================*/
  246. static void pcnet_detach(struct pcmcia_device *link)
  247. {
  248. struct net_device *dev = link->priv;
  249. DEBUG(0, "pcnet_detach(0x%p)\n", link);
  250. if (link->dev_node)
  251. unregister_netdev(dev);
  252. pcnet_release(link);
  253. free_netdev(dev);
  254. } /* pcnet_detach */
  255. /*======================================================================
  256. This probes for a card's hardware address, for card types that
  257. encode this information in their CIS.
  258. ======================================================================*/
  259. static hw_info_t *get_hwinfo(struct pcmcia_device *link)
  260. {
  261. struct net_device *dev = link->priv;
  262. win_req_t req;
  263. memreq_t mem;
  264. u_char __iomem *base, *virt;
  265. int i, j;
  266. /* Allocate a small memory window */
  267. req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
  268. req.Base = 0; req.Size = 0;
  269. req.AccessSpeed = 0;
  270. i = pcmcia_request_window(&link, &req, &link->win);
  271. if (i != 0) {
  272. cs_error(link, RequestWindow, i);
  273. return NULL;
  274. }
  275. virt = ioremap(req.Base, req.Size);
  276. mem.Page = 0;
  277. for (i = 0; i < NR_INFO; i++) {
  278. mem.CardOffset = hw_info[i].offset & ~(req.Size-1);
  279. pcmcia_map_mem_page(link->win, &mem);
  280. base = &virt[hw_info[i].offset & (req.Size-1)];
  281. if ((readb(base+0) == hw_info[i].a0) &&
  282. (readb(base+2) == hw_info[i].a1) &&
  283. (readb(base+4) == hw_info[i].a2)) {
  284. for (j = 0; j < 6; j++)
  285. dev->dev_addr[j] = readb(base + (j<<1));
  286. break;
  287. }
  288. }
  289. iounmap(virt);
  290. j = pcmcia_release_window(link->win);
  291. if (j != 0)
  292. cs_error(link, ReleaseWindow, j);
  293. return (i < NR_INFO) ? hw_info+i : NULL;
  294. } /* get_hwinfo */
  295. /*======================================================================
  296. This probes for a card's hardware address by reading the PROM.
  297. It checks the address against a list of known types, then falls
  298. back to a simple NE2000 clone signature check.
  299. ======================================================================*/
  300. static hw_info_t *get_prom(struct pcmcia_device *link)
  301. {
  302. struct net_device *dev = link->priv;
  303. unsigned int ioaddr = dev->base_addr;
  304. u_char prom[32];
  305. int i, j;
  306. /* This is lifted straight from drivers/net/ne.c */
  307. struct {
  308. u_char value, offset;
  309. } program_seq[] = {
  310. {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
  311. {0x48, EN0_DCFG}, /* Set byte-wide (0x48) access. */
  312. {0x00, EN0_RCNTLO}, /* Clear the count regs. */
  313. {0x00, EN0_RCNTHI},
  314. {0x00, EN0_IMR}, /* Mask completion irq. */
  315. {0xFF, EN0_ISR},
  316. {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */
  317. {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
  318. {32, EN0_RCNTLO},
  319. {0x00, EN0_RCNTHI},
  320. {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */
  321. {0x00, EN0_RSARHI},
  322. {E8390_RREAD+E8390_START, E8390_CMD},
  323. };
  324. pcnet_reset_8390(dev);
  325. mdelay(10);
  326. for (i = 0; i < ARRAY_SIZE(program_seq); i++)
  327. outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
  328. for (i = 0; i < 32; i++)
  329. prom[i] = inb(ioaddr + PCNET_DATAPORT);
  330. for (i = 0; i < NR_INFO; i++) {
  331. if ((prom[0] == hw_info[i].a0) &&
  332. (prom[2] == hw_info[i].a1) &&
  333. (prom[4] == hw_info[i].a2))
  334. break;
  335. }
  336. if ((i < NR_INFO) || ((prom[28] == 0x57) && (prom[30] == 0x57))) {
  337. for (j = 0; j < 6; j++)
  338. dev->dev_addr[j] = prom[j<<1];
  339. return (i < NR_INFO) ? hw_info+i : &default_info;
  340. }
  341. return NULL;
  342. } /* get_prom */
  343. /*======================================================================
  344. For DL10019 based cards, like the Linksys EtherFast
  345. ======================================================================*/
  346. static hw_info_t *get_dl10019(struct pcmcia_device *link)
  347. {
  348. struct net_device *dev = link->priv;
  349. int i;
  350. u_char sum;
  351. for (sum = 0, i = 0x14; i < 0x1c; i++)
  352. sum += inb_p(dev->base_addr + i);
  353. if (sum != 0xff)
  354. return NULL;
  355. for (i = 0; i < 6; i++)
  356. dev->dev_addr[i] = inb_p(dev->base_addr + 0x14 + i);
  357. i = inb(dev->base_addr + 0x1f);
  358. return ((i == 0x91)||(i == 0x99)) ? &dl10022_info : &dl10019_info;
  359. }
  360. /*======================================================================
  361. For Asix AX88190 based cards
  362. ======================================================================*/
  363. static hw_info_t *get_ax88190(struct pcmcia_device *link)
  364. {
  365. struct net_device *dev = link->priv;
  366. unsigned int ioaddr = dev->base_addr;
  367. int i, j;
  368. /* Not much of a test, but the alternatives are messy */
  369. if (link->conf.ConfigBase != 0x03c0)
  370. return NULL;
  371. outb_p(0x01, ioaddr + EN0_DCFG); /* Set word-wide access. */
  372. outb_p(0x00, ioaddr + EN0_RSARLO); /* DMA starting at 0x0400. */
  373. outb_p(0x04, ioaddr + EN0_RSARHI);
  374. outb_p(E8390_RREAD+E8390_START, ioaddr + E8390_CMD);
  375. for (i = 0; i < 6; i += 2) {
  376. j = inw(ioaddr + PCNET_DATAPORT);
  377. dev->dev_addr[i] = j & 0xff;
  378. dev->dev_addr[i+1] = j >> 8;
  379. }
  380. printk(KERN_NOTICE "pcnet_cs: this is an AX88190 card!\n");
  381. printk(KERN_NOTICE "pcnet_cs: use axnet_cs instead.\n");
  382. return NULL;
  383. }
  384. /*======================================================================
  385. This should be totally unnecessary... but when we can't figure
  386. out the hardware address any other way, we'll let the user hard
  387. wire it when the module is initialized.
  388. ======================================================================*/
  389. static hw_info_t *get_hwired(struct pcmcia_device *link)
  390. {
  391. struct net_device *dev = link->priv;
  392. int i;
  393. for (i = 0; i < 6; i++)
  394. if (hw_addr[i] != 0) break;
  395. if (i == 6)
  396. return NULL;
  397. for (i = 0; i < 6; i++)
  398. dev->dev_addr[i] = hw_addr[i];
  399. return &default_info;
  400. } /* get_hwired */
  401. /*======================================================================
  402. pcnet_config() is scheduled to run after a CARD_INSERTION event
  403. is received, to configure the PCMCIA socket, and to make the
  404. ethernet device available to the system.
  405. ======================================================================*/
  406. #define CS_CHECK(fn, ret) \
  407. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  408. static int try_io_port(struct pcmcia_device *link)
  409. {
  410. int j, ret;
  411. if (link->io.NumPorts1 == 32) {
  412. link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  413. if (link->io.NumPorts2 > 0) {
  414. /* for master/slave multifunction cards */
  415. link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
  416. link->irq.Attributes =
  417. IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
  418. }
  419. } else {
  420. /* This should be two 16-port windows */
  421. link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  422. link->io.Attributes2 = IO_DATA_PATH_WIDTH_16;
  423. }
  424. if (link->io.BasePort1 == 0) {
  425. link->io.IOAddrLines = 16;
  426. for (j = 0; j < 0x400; j += 0x20) {
  427. link->io.BasePort1 = j ^ 0x300;
  428. link->io.BasePort2 = (j ^ 0x300) + 0x10;
  429. ret = pcmcia_request_io(link, &link->io);
  430. if (ret == 0)
  431. return ret;
  432. }
  433. return ret;
  434. } else {
  435. return pcmcia_request_io(link, &link->io);
  436. }
  437. }
  438. static int pcnet_confcheck(struct pcmcia_device *p_dev,
  439. cistpl_cftable_entry_t *cfg,
  440. cistpl_cftable_entry_t *dflt,
  441. unsigned int vcc,
  442. void *priv_data)
  443. {
  444. int *has_shmem = priv_data;
  445. int i;
  446. cistpl_io_t *io = &cfg->io;
  447. if (cfg->index == 0 || cfg->io.nwin == 0)
  448. return -EINVAL;
  449. /* For multifunction cards, by convention, we configure the
  450. network function with window 0, and serial with window 1 */
  451. if (io->nwin > 1) {
  452. i = (io->win[1].len > io->win[0].len);
  453. p_dev->io.BasePort2 = io->win[1-i].base;
  454. p_dev->io.NumPorts2 = io->win[1-i].len;
  455. } else {
  456. i = p_dev->io.NumPorts2 = 0;
  457. }
  458. *has_shmem = ((cfg->mem.nwin == 1) &&
  459. (cfg->mem.win[0].len >= 0x4000));
  460. p_dev->io.BasePort1 = io->win[i].base;
  461. p_dev->io.NumPorts1 = io->win[i].len;
  462. p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
  463. if (p_dev->io.NumPorts1 + p_dev->io.NumPorts2 >= 32)
  464. return try_io_port(p_dev);
  465. return 0;
  466. }
  467. static int pcnet_config(struct pcmcia_device *link)
  468. {
  469. struct net_device *dev = link->priv;
  470. pcnet_dev_t *info = PRIV(dev);
  471. int last_ret, last_fn, start_pg, stop_pg, cm_offset;
  472. int has_shmem = 0;
  473. hw_info_t *local_hw_info;
  474. DEBUG(0, "pcnet_config(0x%p)\n", link);
  475. last_ret = pcmcia_loop_config(link, pcnet_confcheck, &has_shmem);
  476. if (last_ret) {
  477. cs_error(link, RequestIO, last_ret);
  478. goto failed;
  479. }
  480. CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
  481. if (link->io.NumPorts2 == 8) {
  482. link->conf.Attributes |= CONF_ENABLE_SPKR;
  483. link->conf.Status = CCSR_AUDIO_ENA;
  484. }
  485. if ((link->manf_id == MANFID_IBM) &&
  486. (link->card_id == PRODID_IBM_HOME_AND_AWAY))
  487. link->conf.ConfigIndex |= 0x10;
  488. CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
  489. dev->irq = link->irq.AssignedIRQ;
  490. dev->base_addr = link->io.BasePort1;
  491. if (info->flags & HAS_MISC_REG) {
  492. if ((if_port == 1) || (if_port == 2))
  493. dev->if_port = if_port;
  494. else
  495. printk(KERN_NOTICE "pcnet_cs: invalid if_port requested\n");
  496. } else {
  497. dev->if_port = 0;
  498. }
  499. if ((link->conf.ConfigBase == 0x03c0)
  500. && (link->manf_id == 0x149) && (link->card_id == 0xc1ab)) {
  501. printk(KERN_INFO "pcnet_cs: this is an AX88190 card!\n");
  502. printk(KERN_INFO "pcnet_cs: use axnet_cs instead.\n");
  503. goto failed;
  504. }
  505. local_hw_info = get_hwinfo(link);
  506. if (local_hw_info == NULL)
  507. local_hw_info = get_prom(link);
  508. if (local_hw_info == NULL)
  509. local_hw_info = get_dl10019(link);
  510. if (local_hw_info == NULL)
  511. local_hw_info = get_ax88190(link);
  512. if (local_hw_info == NULL)
  513. local_hw_info = get_hwired(link);
  514. if (local_hw_info == NULL) {
  515. printk(KERN_NOTICE "pcnet_cs: unable to read hardware net"
  516. " address for io base %#3lx\n", dev->base_addr);
  517. goto failed;
  518. }
  519. info->flags = local_hw_info->flags;
  520. /* Check for user overrides */
  521. info->flags |= (delay_output) ? DELAY_OUTPUT : 0;
  522. if ((link->manf_id == MANFID_SOCKET) &&
  523. ((link->card_id == PRODID_SOCKET_LPE) ||
  524. (link->card_id == PRODID_SOCKET_LPE_CF) ||
  525. (link->card_id == PRODID_SOCKET_EIO)))
  526. info->flags &= ~USE_BIG_BUF;
  527. if (!use_big_buf)
  528. info->flags &= ~USE_BIG_BUF;
  529. if (info->flags & USE_BIG_BUF) {
  530. start_pg = SOCKET_START_PG;
  531. stop_pg = SOCKET_STOP_PG;
  532. cm_offset = 0x10000;
  533. } else {
  534. start_pg = PCNET_START_PG;
  535. stop_pg = PCNET_STOP_PG;
  536. cm_offset = 0;
  537. }
  538. /* has_shmem is ignored if use_shmem != -1 */
  539. if ((use_shmem == 0) || (!has_shmem && (use_shmem == -1)) ||
  540. (setup_shmem_window(link, start_pg, stop_pg, cm_offset) != 0))
  541. setup_dma_config(link, start_pg, stop_pg);
  542. ei_status.name = "NE2000";
  543. ei_status.word16 = 1;
  544. ei_status.reset_8390 = &pcnet_reset_8390;
  545. SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
  546. if (info->flags & (IS_DL10019|IS_DL10022))
  547. mii_phy_probe(dev);
  548. link->dev_node = &info->node;
  549. SET_NETDEV_DEV(dev, &handle_to_dev(link));
  550. if (register_netdev(dev) != 0) {
  551. printk(KERN_NOTICE "pcnet_cs: register_netdev() failed\n");
  552. link->dev_node = NULL;
  553. goto failed;
  554. }
  555. strcpy(info->node.dev_name, dev->name);
  556. if (info->flags & (IS_DL10019|IS_DL10022)) {
  557. u_char id = inb(dev->base_addr + 0x1a);
  558. printk(KERN_INFO "%s: NE2000 (DL100%d rev %02x): ",
  559. dev->name, ((info->flags & IS_DL10022) ? 22 : 19), id);
  560. if (info->pna_phy)
  561. printk("PNA, ");
  562. } else {
  563. printk(KERN_INFO "%s: NE2000 Compatible: ", dev->name);
  564. }
  565. printk("io %#3lx, irq %d,", dev->base_addr, dev->irq);
  566. if (info->flags & USE_SHMEM)
  567. printk (" mem %#5lx,", dev->mem_start);
  568. if (info->flags & HAS_MISC_REG)
  569. printk(" %s xcvr,", if_names[dev->if_port]);
  570. printk(" hw_addr %pM\n", dev->dev_addr);
  571. return 0;
  572. cs_failed:
  573. cs_error(link, last_fn, last_ret);
  574. failed:
  575. pcnet_release(link);
  576. return -ENODEV;
  577. } /* pcnet_config */
  578. /*======================================================================
  579. After a card is removed, pcnet_release() will unregister the net
  580. device, and release the PCMCIA configuration. If the device is
  581. still open, this will be postponed until it is closed.
  582. ======================================================================*/
  583. static void pcnet_release(struct pcmcia_device *link)
  584. {
  585. pcnet_dev_t *info = PRIV(link->priv);
  586. DEBUG(0, "pcnet_release(0x%p)\n", link);
  587. if (info->flags & USE_SHMEM)
  588. iounmap(info->base);
  589. pcmcia_disable_device(link);
  590. }
  591. /*======================================================================
  592. The card status event handler. Mostly, this schedules other
  593. stuff to run after an event is received. A CARD_REMOVAL event
  594. also sets some flags to discourage the net drivers from trying
  595. to talk to the card any more.
  596. ======================================================================*/
  597. static int pcnet_suspend(struct pcmcia_device *link)
  598. {
  599. struct net_device *dev = link->priv;
  600. if (link->open)
  601. netif_device_detach(dev);
  602. return 0;
  603. }
  604. static int pcnet_resume(struct pcmcia_device *link)
  605. {
  606. struct net_device *dev = link->priv;
  607. if (link->open) {
  608. pcnet_reset_8390(dev);
  609. NS8390_init(dev, 1);
  610. netif_device_attach(dev);
  611. }
  612. return 0;
  613. }
  614. /*======================================================================
  615. MII interface support for DL10019 and DL10022 based cards
  616. On the DL10019, the MII IO direction bit is 0x10; on the DL10022
  617. it is 0x20. Setting both bits seems to work on both card types.
  618. ======================================================================*/
  619. #define DLINK_GPIO 0x1c
  620. #define DLINK_DIAG 0x1d
  621. #define DLINK_EEPROM 0x1e
  622. #define MDIO_SHIFT_CLK 0x80
  623. #define MDIO_DATA_OUT 0x40
  624. #define MDIO_DIR_WRITE 0x30
  625. #define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
  626. #define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
  627. #define MDIO_DATA_READ 0x10
  628. #define MDIO_MASK 0x0f
  629. static void mdio_sync(unsigned int addr)
  630. {
  631. int bits, mask = inb(addr) & MDIO_MASK;
  632. for (bits = 0; bits < 32; bits++) {
  633. outb(mask | MDIO_DATA_WRITE1, addr);
  634. outb(mask | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
  635. }
  636. }
  637. static int mdio_read(unsigned int addr, int phy_id, int loc)
  638. {
  639. u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
  640. int i, retval = 0, mask = inb(addr) & MDIO_MASK;
  641. mdio_sync(addr);
  642. for (i = 13; i >= 0; i--) {
  643. int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
  644. outb(mask | dat, addr);
  645. outb(mask | dat | MDIO_SHIFT_CLK, addr);
  646. }
  647. for (i = 19; i > 0; i--) {
  648. outb(mask, addr);
  649. retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
  650. outb(mask | MDIO_SHIFT_CLK, addr);
  651. }
  652. return (retval>>1) & 0xffff;
  653. }
  654. static void mdio_write(unsigned int addr, int phy_id, int loc, int value)
  655. {
  656. u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
  657. int i, mask = inb(addr) & MDIO_MASK;
  658. mdio_sync(addr);
  659. for (i = 31; i >= 0; i--) {
  660. int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
  661. outb(mask | dat, addr);
  662. outb(mask | dat | MDIO_SHIFT_CLK, addr);
  663. }
  664. for (i = 1; i >= 0; i--) {
  665. outb(mask, addr);
  666. outb(mask | MDIO_SHIFT_CLK, addr);
  667. }
  668. }
  669. /*======================================================================
  670. EEPROM access routines for DL10019 and DL10022 based cards
  671. ======================================================================*/
  672. #define EE_EEP 0x40
  673. #define EE_ASIC 0x10
  674. #define EE_CS 0x08
  675. #define EE_CK 0x04
  676. #define EE_DO 0x02
  677. #define EE_DI 0x01
  678. #define EE_ADOT 0x01 /* DataOut for ASIC */
  679. #define EE_READ_CMD 0x06
  680. #define DL19FDUPLX 0x0400 /* DL10019 Full duplex mode */
  681. static int read_eeprom(unsigned int ioaddr, int location)
  682. {
  683. int i, retval = 0;
  684. unsigned int ee_addr = ioaddr + DLINK_EEPROM;
  685. int read_cmd = location | (EE_READ_CMD << 8);
  686. outb(0, ee_addr);
  687. outb(EE_EEP|EE_CS, ee_addr);
  688. /* Shift the read command bits out. */
  689. for (i = 10; i >= 0; i--) {
  690. short dataval = (read_cmd & (1 << i)) ? EE_DO : 0;
  691. outb_p(EE_EEP|EE_CS|dataval, ee_addr);
  692. outb_p(EE_EEP|EE_CS|dataval|EE_CK, ee_addr);
  693. }
  694. outb(EE_EEP|EE_CS, ee_addr);
  695. for (i = 16; i > 0; i--) {
  696. outb_p(EE_EEP|EE_CS | EE_CK, ee_addr);
  697. retval = (retval << 1) | ((inb(ee_addr) & EE_DI) ? 1 : 0);
  698. outb_p(EE_EEP|EE_CS, ee_addr);
  699. }
  700. /* Terminate the EEPROM access. */
  701. outb(0, ee_addr);
  702. return retval;
  703. }
  704. /*
  705. The internal ASIC registers can be changed by EEPROM READ access
  706. with EE_ASIC bit set.
  707. In ASIC mode, EE_ADOT is used to output the data to the ASIC.
  708. */
  709. static void write_asic(unsigned int ioaddr, int location, short asic_data)
  710. {
  711. int i;
  712. unsigned int ee_addr = ioaddr + DLINK_EEPROM;
  713. short dataval;
  714. int read_cmd = location | (EE_READ_CMD << 8);
  715. asic_data |= read_eeprom(ioaddr, location);
  716. outb(0, ee_addr);
  717. outb(EE_ASIC|EE_CS|EE_DI, ee_addr);
  718. read_cmd = read_cmd >> 1;
  719. /* Shift the read command bits out. */
  720. for (i = 9; i >= 0; i--) {
  721. dataval = (read_cmd & (1 << i)) ? EE_DO : 0;
  722. outb_p(EE_ASIC|EE_CS|EE_DI|dataval, ee_addr);
  723. outb_p(EE_ASIC|EE_CS|EE_DI|dataval|EE_CK, ee_addr);
  724. outb_p(EE_ASIC|EE_CS|EE_DI|dataval, ee_addr);
  725. }
  726. // sync
  727. outb(EE_ASIC|EE_CS, ee_addr);
  728. outb(EE_ASIC|EE_CS|EE_CK, ee_addr);
  729. outb(EE_ASIC|EE_CS, ee_addr);
  730. for (i = 15; i >= 0; i--) {
  731. dataval = (asic_data & (1 << i)) ? EE_ADOT : 0;
  732. outb_p(EE_ASIC|EE_CS|dataval, ee_addr);
  733. outb_p(EE_ASIC|EE_CS|dataval|EE_CK, ee_addr);
  734. outb_p(EE_ASIC|EE_CS|dataval, ee_addr);
  735. }
  736. /* Terminate the ASIC access. */
  737. outb(EE_ASIC|EE_DI, ee_addr);
  738. outb(EE_ASIC|EE_DI| EE_CK, ee_addr);
  739. outb(EE_ASIC|EE_DI, ee_addr);
  740. outb(0, ee_addr);
  741. }
  742. /*====================================================================*/
  743. static void set_misc_reg(struct net_device *dev)
  744. {
  745. unsigned int nic_base = dev->base_addr;
  746. pcnet_dev_t *info = PRIV(dev);
  747. u_char tmp;
  748. if (info->flags & HAS_MISC_REG) {
  749. tmp = inb_p(nic_base + PCNET_MISC) & ~3;
  750. if (dev->if_port == 2)
  751. tmp |= 1;
  752. if (info->flags & USE_BIG_BUF)
  753. tmp |= 2;
  754. if (info->flags & HAS_IBM_MISC)
  755. tmp |= 8;
  756. outb_p(tmp, nic_base + PCNET_MISC);
  757. }
  758. if (info->flags & IS_DL10022) {
  759. if (info->flags & HAS_MII) {
  760. /* Advertise 100F, 100H, 10F, 10H */
  761. mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 4, 0x01e1);
  762. /* Restart MII autonegotiation */
  763. mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 0, 0x0000);
  764. mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 0, 0x1200);
  765. info->mii_reset = jiffies;
  766. } else {
  767. outb(full_duplex ? 4 : 0, nic_base + DLINK_DIAG);
  768. }
  769. } else if (info->flags & IS_DL10019) {
  770. /* Advertise 100F, 100H, 10F, 10H */
  771. mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 4, 0x01e1);
  772. /* Restart MII autonegotiation */
  773. mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 0, 0x0000);
  774. mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 0, 0x1200);
  775. }
  776. }
  777. /*====================================================================*/
  778. static void mii_phy_probe(struct net_device *dev)
  779. {
  780. pcnet_dev_t *info = PRIV(dev);
  781. unsigned int mii_addr = dev->base_addr + DLINK_GPIO;
  782. int i;
  783. u_int tmp, phyid;
  784. for (i = 31; i >= 0; i--) {
  785. tmp = mdio_read(mii_addr, i, 1);
  786. if ((tmp == 0) || (tmp == 0xffff))
  787. continue;
  788. tmp = mdio_read(mii_addr, i, MII_PHYID_REG1);
  789. phyid = tmp << 16;
  790. phyid |= mdio_read(mii_addr, i, MII_PHYID_REG2);
  791. phyid &= MII_PHYID_REV_MASK;
  792. DEBUG(0, "%s: MII at %d is 0x%08x\n", dev->name, i, phyid);
  793. if (phyid == AM79C9XX_HOME_PHY) {
  794. info->pna_phy = i;
  795. } else if (phyid != AM79C9XX_ETH_PHY) {
  796. info->eth_phy = i;
  797. }
  798. }
  799. }
  800. static int pcnet_open(struct net_device *dev)
  801. {
  802. int ret;
  803. pcnet_dev_t *info = PRIV(dev);
  804. struct pcmcia_device *link = info->p_dev;
  805. unsigned int nic_base = dev->base_addr;
  806. DEBUG(2, "pcnet_open('%s')\n", dev->name);
  807. if (!pcmcia_dev_present(link))
  808. return -ENODEV;
  809. set_misc_reg(dev);
  810. outb_p(0xFF, nic_base + EN0_ISR); /* Clear bogus intr. */
  811. ret = request_irq(dev->irq, ei_irq_wrapper, IRQF_SHARED, dev_info, dev);
  812. if (ret)
  813. return ret;
  814. link->open++;
  815. info->phy_id = info->eth_phy;
  816. info->link_status = 0x00;
  817. init_timer(&info->watchdog);
  818. info->watchdog.function = &ei_watchdog;
  819. info->watchdog.data = (u_long)dev;
  820. info->watchdog.expires = jiffies + HZ;
  821. add_timer(&info->watchdog);
  822. return ei_open(dev);
  823. } /* pcnet_open */
  824. /*====================================================================*/
  825. static int pcnet_close(struct net_device *dev)
  826. {
  827. pcnet_dev_t *info = PRIV(dev);
  828. struct pcmcia_device *link = info->p_dev;
  829. DEBUG(2, "pcnet_close('%s')\n", dev->name);
  830. ei_close(dev);
  831. free_irq(dev->irq, dev);
  832. link->open--;
  833. netif_stop_queue(dev);
  834. del_timer_sync(&info->watchdog);
  835. return 0;
  836. } /* pcnet_close */
  837. /*======================================================================
  838. Hard reset the card. This used to pause for the same period that
  839. a 8390 reset command required, but that shouldn't be necessary.
  840. ======================================================================*/
  841. static void pcnet_reset_8390(struct net_device *dev)
  842. {
  843. unsigned int nic_base = dev->base_addr;
  844. int i;
  845. ei_status.txing = ei_status.dmaing = 0;
  846. outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, nic_base + E8390_CMD);
  847. outb(inb(nic_base + PCNET_RESET), nic_base + PCNET_RESET);
  848. for (i = 0; i < 100; i++) {
  849. if ((inb_p(nic_base+EN0_ISR) & ENISR_RESET) != 0)
  850. break;
  851. udelay(100);
  852. }
  853. outb_p(ENISR_RESET, nic_base + EN0_ISR); /* Ack intr. */
  854. if (i == 100)
  855. printk(KERN_ERR "%s: pcnet_reset_8390() did not complete.\n",
  856. dev->name);
  857. set_misc_reg(dev);
  858. } /* pcnet_reset_8390 */
  859. /*====================================================================*/
  860. static int set_config(struct net_device *dev, struct ifmap *map)
  861. {
  862. pcnet_dev_t *info = PRIV(dev);
  863. if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
  864. if (!(info->flags & HAS_MISC_REG))
  865. return -EOPNOTSUPP;
  866. else if ((map->port < 1) || (map->port > 2))
  867. return -EINVAL;
  868. dev->if_port = map->port;
  869. printk(KERN_INFO "%s: switched to %s port\n",
  870. dev->name, if_names[dev->if_port]);
  871. NS8390_init(dev, 1);
  872. }
  873. return 0;
  874. }
  875. /*====================================================================*/
  876. static irqreturn_t ei_irq_wrapper(int irq, void *dev_id)
  877. {
  878. struct net_device *dev = dev_id;
  879. pcnet_dev_t *info;
  880. irqreturn_t ret = ei_interrupt(irq, dev_id);
  881. if (ret == IRQ_HANDLED) {
  882. info = PRIV(dev);
  883. info->stale = 0;
  884. }
  885. return ret;
  886. }
  887. static void ei_watchdog(u_long arg)
  888. {
  889. struct net_device *dev = (struct net_device *)arg;
  890. pcnet_dev_t *info = PRIV(dev);
  891. unsigned int nic_base = dev->base_addr;
  892. unsigned int mii_addr = nic_base + DLINK_GPIO;
  893. u_short link;
  894. if (!netif_device_present(dev)) goto reschedule;
  895. /* Check for pending interrupt with expired latency timer: with
  896. this, we can limp along even if the interrupt is blocked */
  897. if (info->stale++ && (inb_p(nic_base + EN0_ISR) & ENISR_ALL)) {
  898. if (!info->fast_poll)
  899. printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
  900. ei_irq_wrapper(dev->irq, dev);
  901. info->fast_poll = HZ;
  902. }
  903. if (info->fast_poll) {
  904. info->fast_poll--;
  905. info->watchdog.expires = jiffies + 1;
  906. add_timer(&info->watchdog);
  907. return;
  908. }
  909. if (!(info->flags & HAS_MII))
  910. goto reschedule;
  911. mdio_read(mii_addr, info->phy_id, 1);
  912. link = mdio_read(mii_addr, info->phy_id, 1);
  913. if (!link || (link == 0xffff)) {
  914. if (info->eth_phy) {
  915. info->phy_id = info->eth_phy = 0;
  916. } else {
  917. printk(KERN_INFO "%s: MII is missing!\n", dev->name);
  918. info->flags &= ~HAS_MII;
  919. }
  920. goto reschedule;
  921. }
  922. link &= 0x0004;
  923. if (link != info->link_status) {
  924. u_short p = mdio_read(mii_addr, info->phy_id, 5);
  925. printk(KERN_INFO "%s: %s link beat\n", dev->name,
  926. (link) ? "found" : "lost");
  927. if (link && (info->flags & IS_DL10022)) {
  928. /* Disable collision detection on full duplex links */
  929. outb((p & 0x0140) ? 4 : 0, nic_base + DLINK_DIAG);
  930. } else if (link && (info->flags & IS_DL10019)) {
  931. /* Disable collision detection on full duplex links */
  932. write_asic(dev->base_addr, 4, (p & 0x140) ? DL19FDUPLX : 0);
  933. }
  934. if (link) {
  935. if (info->phy_id == info->eth_phy) {
  936. if (p)
  937. printk(KERN_INFO "%s: autonegotiation complete: "
  938. "%sbaseT-%cD selected\n", dev->name,
  939. ((p & 0x0180) ? "100" : "10"),
  940. ((p & 0x0140) ? 'F' : 'H'));
  941. else
  942. printk(KERN_INFO "%s: link partner did not "
  943. "autonegotiate\n", dev->name);
  944. }
  945. NS8390_init(dev, 1);
  946. }
  947. info->link_status = link;
  948. }
  949. if (info->pna_phy && time_after(jiffies, info->mii_reset + 6*HZ)) {
  950. link = mdio_read(mii_addr, info->eth_phy, 1) & 0x0004;
  951. if (((info->phy_id == info->pna_phy) && link) ||
  952. ((info->phy_id != info->pna_phy) && !link)) {
  953. /* isolate this MII and try flipping to the other one */
  954. mdio_write(mii_addr, info->phy_id, 0, 0x0400);
  955. info->phy_id ^= info->pna_phy ^ info->eth_phy;
  956. printk(KERN_INFO "%s: switched to %s transceiver\n", dev->name,
  957. (info->phy_id == info->eth_phy) ? "ethernet" : "PNA");
  958. mdio_write(mii_addr, info->phy_id, 0,
  959. (info->phy_id == info->eth_phy) ? 0x1000 : 0);
  960. info->link_status = 0;
  961. info->mii_reset = jiffies;
  962. }
  963. }
  964. reschedule:
  965. info->watchdog.expires = jiffies + HZ;
  966. add_timer(&info->watchdog);
  967. }
  968. /*====================================================================*/
  969. static void netdev_get_drvinfo(struct net_device *dev,
  970. struct ethtool_drvinfo *info)
  971. {
  972. strcpy(info->driver, "pcnet_cs");
  973. }
  974. static const struct ethtool_ops netdev_ethtool_ops = {
  975. .get_drvinfo = netdev_get_drvinfo,
  976. };
  977. /*====================================================================*/
  978. static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  979. {
  980. pcnet_dev_t *info = PRIV(dev);
  981. struct mii_ioctl_data *data = if_mii(rq);
  982. unsigned int mii_addr = dev->base_addr + DLINK_GPIO;
  983. if (!(info->flags & (IS_DL10019|IS_DL10022)))
  984. return -EINVAL;
  985. switch (cmd) {
  986. case SIOCGMIIPHY:
  987. data->phy_id = info->phy_id;
  988. case SIOCGMIIREG: /* Read MII PHY register. */
  989. data->val_out = mdio_read(mii_addr, data->phy_id, data->reg_num & 0x1f);
  990. return 0;
  991. case SIOCSMIIREG: /* Write MII PHY register. */
  992. mdio_write(mii_addr, data->phy_id, data->reg_num & 0x1f, data->val_in);
  993. return 0;
  994. }
  995. return -EOPNOTSUPP;
  996. }
  997. /*====================================================================*/
  998. static void dma_get_8390_hdr(struct net_device *dev,
  999. struct e8390_pkt_hdr *hdr,
  1000. int ring_page)
  1001. {
  1002. unsigned int nic_base = dev->base_addr;
  1003. if (ei_status.dmaing) {
  1004. printk(KERN_NOTICE "%s: DMAing conflict in dma_block_input."
  1005. "[DMAstat:%1x][irqlock:%1x]\n",
  1006. dev->name, ei_status.dmaing, ei_status.irqlock);
  1007. return;
  1008. }
  1009. ei_status.dmaing |= 0x01;
  1010. outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base + PCNET_CMD);
  1011. outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
  1012. outb_p(0, nic_base + EN0_RCNTHI);
  1013. outb_p(0, nic_base + EN0_RSARLO); /* On page boundary */
  1014. outb_p(ring_page, nic_base + EN0_RSARHI);
  1015. outb_p(E8390_RREAD+E8390_START, nic_base + PCNET_CMD);
  1016. insw(nic_base + PCNET_DATAPORT, hdr,
  1017. sizeof(struct e8390_pkt_hdr)>>1);
  1018. /* Fix for big endian systems */
  1019. hdr->count = le16_to_cpu(hdr->count);
  1020. outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
  1021. ei_status.dmaing &= ~0x01;
  1022. }
  1023. /*====================================================================*/
  1024. static void dma_block_input(struct net_device *dev, int count,
  1025. struct sk_buff *skb, int ring_offset)
  1026. {
  1027. unsigned int nic_base = dev->base_addr;
  1028. int xfer_count = count;
  1029. char *buf = skb->data;
  1030. #ifdef PCMCIA_DEBUG
  1031. if ((ei_debug > 4) && (count != 4))
  1032. printk(KERN_DEBUG "%s: [bi=%d]\n", dev->name, count+4);
  1033. #endif
  1034. if (ei_status.dmaing) {
  1035. printk(KERN_NOTICE "%s: DMAing conflict in dma_block_input."
  1036. "[DMAstat:%1x][irqlock:%1x]\n",
  1037. dev->name, ei_status.dmaing, ei_status.irqlock);
  1038. return;
  1039. }
  1040. ei_status.dmaing |= 0x01;
  1041. outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base + PCNET_CMD);
  1042. outb_p(count & 0xff, nic_base + EN0_RCNTLO);
  1043. outb_p(count >> 8, nic_base + EN0_RCNTHI);
  1044. outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
  1045. outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
  1046. outb_p(E8390_RREAD+E8390_START, nic_base + PCNET_CMD);
  1047. insw(nic_base + PCNET_DATAPORT,buf,count>>1);
  1048. if (count & 0x01)
  1049. buf[count-1] = inb(nic_base + PCNET_DATAPORT), xfer_count++;
  1050. /* This was for the ALPHA version only, but enough people have been
  1051. encountering problems that it is still here. */
  1052. #ifdef PCMCIA_DEBUG
  1053. if (ei_debug > 4) { /* DMA termination address check... */
  1054. int addr, tries = 20;
  1055. do {
  1056. /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here
  1057. -- it's broken for Rx on some cards! */
  1058. int high = inb_p(nic_base + EN0_RSARHI);
  1059. int low = inb_p(nic_base + EN0_RSARLO);
  1060. addr = (high << 8) + low;
  1061. if (((ring_offset + xfer_count) & 0xff) == (addr & 0xff))
  1062. break;
  1063. } while (--tries > 0);
  1064. if (tries <= 0)
  1065. printk(KERN_NOTICE "%s: RX transfer address mismatch,"
  1066. "%#4.4x (expected) vs. %#4.4x (actual).\n",
  1067. dev->name, ring_offset + xfer_count, addr);
  1068. }
  1069. #endif
  1070. outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
  1071. ei_status.dmaing &= ~0x01;
  1072. } /* dma_block_input */
  1073. /*====================================================================*/
  1074. static void dma_block_output(struct net_device *dev, int count,
  1075. const u_char *buf, const int start_page)
  1076. {
  1077. unsigned int nic_base = dev->base_addr;
  1078. pcnet_dev_t *info = PRIV(dev);
  1079. #ifdef PCMCIA_DEBUG
  1080. int retries = 0;
  1081. #endif
  1082. u_long dma_start;
  1083. #ifdef PCMCIA_DEBUG
  1084. if (ei_debug > 4)
  1085. printk(KERN_DEBUG "%s: [bo=%d]\n", dev->name, count);
  1086. #endif
  1087. /* Round the count up for word writes. Do we need to do this?
  1088. What effect will an odd byte count have on the 8390?
  1089. I should check someday. */
  1090. if (count & 0x01)
  1091. count++;
  1092. if (ei_status.dmaing) {
  1093. printk(KERN_NOTICE "%s: DMAing conflict in dma_block_output."
  1094. "[DMAstat:%1x][irqlock:%1x]\n",
  1095. dev->name, ei_status.dmaing, ei_status.irqlock);
  1096. return;
  1097. }
  1098. ei_status.dmaing |= 0x01;
  1099. /* We should already be in page 0, but to be safe... */
  1100. outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base+PCNET_CMD);
  1101. #ifdef PCMCIA_DEBUG
  1102. retry:
  1103. #endif
  1104. outb_p(ENISR_RDC, nic_base + EN0_ISR);
  1105. /* Now the normal output. */
  1106. outb_p(count & 0xff, nic_base + EN0_RCNTLO);
  1107. outb_p(count >> 8, nic_base + EN0_RCNTHI);
  1108. outb_p(0x00, nic_base + EN0_RSARLO);
  1109. outb_p(start_page, nic_base + EN0_RSARHI);
  1110. outb_p(E8390_RWRITE+E8390_START, nic_base + PCNET_CMD);
  1111. outsw(nic_base + PCNET_DATAPORT, buf, count>>1);
  1112. dma_start = jiffies;
  1113. #ifdef PCMCIA_DEBUG
  1114. /* This was for the ALPHA version only, but enough people have been
  1115. encountering problems that it is still here. */
  1116. if (ei_debug > 4) { /* DMA termination address check... */
  1117. int addr, tries = 20;
  1118. do {
  1119. int high = inb_p(nic_base + EN0_RSARHI);
  1120. int low = inb_p(nic_base + EN0_RSARLO);
  1121. addr = (high << 8) + low;
  1122. if ((start_page << 8) + count == addr)
  1123. break;
  1124. } while (--tries > 0);
  1125. if (tries <= 0) {
  1126. printk(KERN_NOTICE "%s: Tx packet transfer address mismatch,"
  1127. "%#4.4x (expected) vs. %#4.4x (actual).\n",
  1128. dev->name, (start_page << 8) + count, addr);
  1129. if (retries++ == 0)
  1130. goto retry;
  1131. }
  1132. }
  1133. #endif
  1134. while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0)
  1135. if (time_after(jiffies, dma_start + PCNET_RDC_TIMEOUT)) {
  1136. printk(KERN_NOTICE "%s: timeout waiting for Tx RDC.\n",
  1137. dev->name);
  1138. pcnet_reset_8390(dev);
  1139. NS8390_init(dev, 1);
  1140. break;
  1141. }
  1142. outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
  1143. if (info->flags & DELAY_OUTPUT)
  1144. udelay((long)delay_time);
  1145. ei_status.dmaing &= ~0x01;
  1146. }
  1147. /*====================================================================*/
  1148. static int setup_dma_config(struct pcmcia_device *link, int start_pg,
  1149. int stop_pg)
  1150. {
  1151. struct net_device *dev = link->priv;
  1152. ei_status.tx_start_page = start_pg;
  1153. ei_status.rx_start_page = start_pg + TX_PAGES;
  1154. ei_status.stop_page = stop_pg;
  1155. /* set up block i/o functions */
  1156. ei_status.get_8390_hdr = &dma_get_8390_hdr;
  1157. ei_status.block_input = &dma_block_input;
  1158. ei_status.block_output = &dma_block_output;
  1159. return 0;
  1160. }
  1161. /*====================================================================*/
  1162. static void copyin(void *dest, void __iomem *src, int c)
  1163. {
  1164. u_short *d = dest;
  1165. u_short __iomem *s = src;
  1166. int odd;
  1167. if (c <= 0)
  1168. return;
  1169. odd = (c & 1); c >>= 1;
  1170. if (c) {
  1171. do { *d++ = __raw_readw(s++); } while (--c);
  1172. }
  1173. /* get last byte by fetching a word and masking */
  1174. if (odd)
  1175. *((u_char *)d) = readw(s) & 0xff;
  1176. }
  1177. static void copyout(void __iomem *dest, const void *src, int c)
  1178. {
  1179. u_short __iomem *d = dest;
  1180. const u_short *s = src;
  1181. int odd;
  1182. if (c <= 0)
  1183. return;
  1184. odd = (c & 1); c >>= 1;
  1185. if (c) {
  1186. do { __raw_writew(*s++, d++); } while (--c);
  1187. }
  1188. /* copy last byte doing a read-modify-write */
  1189. if (odd)
  1190. writew((readw(d) & 0xff00) | *(u_char *)s, d);
  1191. }
  1192. /*====================================================================*/
  1193. static void shmem_get_8390_hdr(struct net_device *dev,
  1194. struct e8390_pkt_hdr *hdr,
  1195. int ring_page)
  1196. {
  1197. void __iomem *xfer_start = ei_status.mem + (TX_PAGES<<8)
  1198. + (ring_page << 8)
  1199. - (ei_status.rx_start_page << 8);
  1200. copyin(hdr, xfer_start, sizeof(struct e8390_pkt_hdr));
  1201. /* Fix for big endian systems */
  1202. hdr->count = le16_to_cpu(hdr->count);
  1203. }
  1204. /*====================================================================*/
  1205. static void shmem_block_input(struct net_device *dev, int count,
  1206. struct sk_buff *skb, int ring_offset)
  1207. {
  1208. void __iomem *base = ei_status.mem;
  1209. unsigned long offset = (TX_PAGES<<8) + ring_offset
  1210. - (ei_status.rx_start_page << 8);
  1211. char *buf = skb->data;
  1212. if (offset + count > ei_status.priv) {
  1213. /* We must wrap the input move. */
  1214. int semi_count = ei_status.priv - offset;
  1215. copyin(buf, base + offset, semi_count);
  1216. buf += semi_count;
  1217. offset = TX_PAGES<<8;
  1218. count -= semi_count;
  1219. }
  1220. copyin(buf, base + offset, count);
  1221. }
  1222. /*====================================================================*/
  1223. static void shmem_block_output(struct net_device *dev, int count,
  1224. const u_char *buf, const int start_page)
  1225. {
  1226. void __iomem *shmem = ei_status.mem + (start_page << 8);
  1227. shmem -= ei_status.tx_start_page << 8;
  1228. copyout(shmem, buf, count);
  1229. }
  1230. /*====================================================================*/
  1231. static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
  1232. int stop_pg, int cm_offset)
  1233. {
  1234. struct net_device *dev = link->priv;
  1235. pcnet_dev_t *info = PRIV(dev);
  1236. win_req_t req;
  1237. memreq_t mem;
  1238. int i, window_size, offset, last_ret, last_fn;
  1239. window_size = (stop_pg - start_pg) << 8;
  1240. if (window_size > 32 * 1024)
  1241. window_size = 32 * 1024;
  1242. /* Make sure it's a power of two. */
  1243. window_size = roundup_pow_of_two(window_size);
  1244. /* Allocate a memory window */
  1245. req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
  1246. req.Attributes |= WIN_USE_WAIT;
  1247. req.Base = 0; req.Size = window_size;
  1248. req.AccessSpeed = mem_speed;
  1249. CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win));
  1250. mem.CardOffset = (start_pg << 8) + cm_offset;
  1251. offset = mem.CardOffset % window_size;
  1252. mem.CardOffset -= offset;
  1253. mem.Page = 0;
  1254. CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
  1255. /* Try scribbling on the buffer */
  1256. info->base = ioremap(req.Base, window_size);
  1257. for (i = 0; i < (TX_PAGES<<8); i += 2)
  1258. __raw_writew((i>>1), info->base+offset+i);
  1259. udelay(100);
  1260. for (i = 0; i < (TX_PAGES<<8); i += 2)
  1261. if (__raw_readw(info->base+offset+i) != (i>>1)) break;
  1262. pcnet_reset_8390(dev);
  1263. if (i != (TX_PAGES<<8)) {
  1264. iounmap(info->base);
  1265. pcmcia_release_window(link->win);
  1266. info->base = NULL; link->win = NULL;
  1267. goto failed;
  1268. }
  1269. ei_status.mem = info->base + offset;
  1270. ei_status.priv = req.Size;
  1271. dev->mem_start = (u_long)ei_status.mem;
  1272. dev->mem_end = dev->mem_start + req.Size;
  1273. ei_status.tx_start_page = start_pg;
  1274. ei_status.rx_start_page = start_pg + TX_PAGES;
  1275. ei_status.stop_page = start_pg + ((req.Size - offset) >> 8);
  1276. /* set up block i/o functions */
  1277. ei_status.get_8390_hdr = &shmem_get_8390_hdr;
  1278. ei_status.block_input = &shmem_block_input;
  1279. ei_status.block_output = &shmem_block_output;
  1280. info->flags |= USE_SHMEM;
  1281. return 0;
  1282. cs_failed:
  1283. cs_error(link, last_fn, last_ret);
  1284. failed:
  1285. return 1;
  1286. }
  1287. /*====================================================================*/
  1288. static struct pcmcia_device_id pcnet_ids[] = {
  1289. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0057, 0x0021),
  1290. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0104, 0x000a),
  1291. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0xea15),
  1292. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0143, 0x3341),
  1293. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0143, 0xc0ab),
  1294. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x021b, 0x0101),
  1295. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x08a1, 0xc0ab),
  1296. PCMCIA_PFC_DEVICE_PROD_ID12(0, "AnyCom", "Fast Ethernet + 56K COMBO", 0x578ba6e7, 0xb0ac62c4),
  1297. PCMCIA_PFC_DEVICE_PROD_ID12(0, "D-Link", "DME336T", 0x1a424a1c, 0xb23897ff),
  1298. PCMCIA_PFC_DEVICE_PROD_ID12(0, "Grey Cell", "GCS3000", 0x2a151fac, 0x48b932ae),
  1299. PCMCIA_PFC_DEVICE_PROD_ID12(0, "Linksys", "EtherFast 10&100 + 56K PC Card (PCMLM56)", 0x0733cc81, 0xb3765033),
  1300. PCMCIA_PFC_DEVICE_PROD_ID12(0, "LINKSYS", "PCMLM336", 0xf7cb0b07, 0x7a821b58),
  1301. PCMCIA_PFC_DEVICE_PROD_ID12(0, "MICRO RESEARCH", "COMBO-L/M-336", 0xb2ced065, 0x3ced0555),
  1302. PCMCIA_PFC_DEVICE_PROD_ID12(0, "PCMCIAs", "ComboCard", 0xdcfe12d3, 0xcd8906cc),
  1303. PCMCIA_PFC_DEVICE_PROD_ID12(0, "PCMCIAs", "LanModem", 0xdcfe12d3, 0xc67c648f),
  1304. PCMCIA_MFC_DEVICE_PROD_ID12(0, "IBM", "Home and Away 28.8 PC Card ", 0xb569a6e5, 0x5bd4ff2c),
  1305. PCMCIA_MFC_DEVICE_PROD_ID12(0, "IBM", "Home and Away Credit Card Adapter", 0xb569a6e5, 0x4bdf15c3),
  1306. PCMCIA_MFC_DEVICE_PROD_ID12(0, "IBM", "w95 Home and Away Credit Card ", 0xb569a6e5, 0xae911c15),
  1307. PCMCIA_MFC_DEVICE_PROD_ID123(0, "APEX DATA", "MULTICARD", "ETHERNET-MODEM", 0x11c2da09, 0x7289dc5d, 0xaad95e1f),
  1308. PCMCIA_MFC_DEVICE_PROD_ID2(0, "FAX/Modem/Ethernet Combo Card ", 0x1ed59302),
  1309. PCMCIA_DEVICE_MANF_CARD(0x0057, 0x1004),
  1310. PCMCIA_DEVICE_MANF_CARD(0x0104, 0x000d),
  1311. PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0075),
  1312. PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0145),
  1313. PCMCIA_DEVICE_MANF_CARD(0x0149, 0x0230),
  1314. PCMCIA_DEVICE_MANF_CARD(0x0149, 0x4530),
  1315. PCMCIA_DEVICE_MANF_CARD(0x0149, 0xc1ab),
  1316. PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0110),
  1317. PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x2328),
  1318. PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x8041),
  1319. PCMCIA_DEVICE_MANF_CARD(0x0213, 0x2452),
  1320. PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0300),
  1321. PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0307),
  1322. PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030a),
  1323. PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1103),
  1324. PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1121),
  1325. PCMCIA_DEVICE_PROD_ID12("2408LAN", "Ethernet", 0x352fff7f, 0x00b2e941),
  1326. PCMCIA_DEVICE_PROD_ID1234("Socket", "CF 10/100 Ethernet Card", "Revision B", "05/11/06", 0xb38bcc2e, 0x4de88