1 /*======================================================================
3 A PCMCIA ethernet driver for SMC91c92-based cards.
5 This driver supports Megahertz PCMCIA ethernet cards; and
6 Megahertz, Motorola, Ositech, and Psion Dacom ethernet/modem
9 Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net
11 smc91c92_cs.c 1.122 2002/10/25 06:26:39
13 This driver contains code written by Donald Becker
14 (becker@scyld.com), Rowan Hughes (x-csrdh@jcu.edu.au),
15 David Hinds (dahinds@users.sourceforge.net), and Erik Stahlman
16 (erik@vt.edu). Donald wrote the SMC 91c92 code using parts of
17 Erik's SMC 91c94 driver. Rowan wrote a similar driver, and I've
18 incorporated some parts of his driver here. I (Dave) wrote most
19 of the PCMCIA glue code, and the Ositech support code. Kelly
20 Stephens (kstephen@holli.com) added support for the Motorola
21 Mariner, with help from Allen Brost.
23 This software may be used and distributed according to the terms of
24 the GNU General Public License, incorporated herein by reference.
26 ======================================================================*/
28 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/init.h>
33 #include <linux/slab.h>
34 #include <linux/string.h>
35 #include <linux/timer.h>
36 #include <linux/interrupt.h>
37 #include <linux/delay.h>
38 #include <linux/crc32.h>
39 #include <linux/netdevice.h>
40 #include <linux/etherdevice.h>
41 #include <linux/skbuff.h>
42 #include <linux/if_arp.h>
43 #include <linux/ioport.h>
44 #include <linux/ethtool.h>
45 #include <linux/mii.h>
46 #include <linux/jiffies.h>
47 #include <linux/firmware.h>
49 #include <pcmcia/cistpl.h>
50 #include <pcmcia/cisreg.h>
51 #include <pcmcia/ciscode.h>
52 #include <pcmcia/ds.h>
53 #include <pcmcia/ss.h>
56 #include <asm/uaccess.h>
58 /*====================================================================*/
60 static const char *if_names[] = { "auto", "10baseT", "10base2"};
63 #define FIRMWARE_NAME "ositech/Xilinx7OD.bin"
65 /* Module parameters */
67 MODULE_DESCRIPTION("SMC 91c92 series PCMCIA ethernet driver");
68 MODULE_LICENSE("GPL");
69 MODULE_FIRMWARE(FIRMWARE_NAME);
71 #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
74 Transceiver/media type.
76 1 = 10baseT (and autoselect if #define AUTOSELECT),
79 INT_MODULE_PARM(if_port, 0);
82 #define DRV_NAME "smc91c92_cs"
83 #define DRV_VERSION "1.123"
85 /*====================================================================*/
87 /* Operational parameter that usually are not changed. */
89 /* Time in jiffies before concluding Tx hung */
90 #define TX_TIMEOUT ((400*HZ)/1000)
92 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
95 /* Times to check the check the chip before concluding that it doesn't
96 currently have room for another Tx packet. */
97 #define MEMORY_WAIT_TIME 8
100 struct pcmcia_device *p_dev;
105 struct sk_buff *saved_skb;
109 struct timer_list media;
110 int watchdog, tx_err;
111 u_short media_status;
114 struct mii_if_info mii_if;
119 /* Special definitions for Megahertz multifunction cards */
120 #define MEGAHERTZ_ISR 0x0380
122 /* Special function registers for Motorola Mariner */
123 #define MOT_LAN 0x0000
124 #define MOT_UART 0x0020
125 #define MOT_EEPROM 0x20
128 (COR_LEVEL_REQ | COR_FUNC_ENA | COR_ADDR_DECODE | COR_IREQ_ENA)
130 /* Special function registers for Ositech cards */
131 #define OSITECH_AUI_CTL 0x0c
132 #define OSITECH_PWRDOWN 0x0d
133 #define OSITECH_RESET 0x0e
134 #define OSITECH_ISR 0x0f
135 #define OSITECH_AUI_PWR 0x0c
136 #define OSITECH_RESET_ISR 0x0e
138 #define OSI_AUI_PWR 0x40
139 #define OSI_LAN_PWRDOWN 0x02
140 #define OSI_MODEM_PWRDOWN 0x01
141 #define OSI_LAN_RESET 0x02
142 #define OSI_MODEM_RESET 0x01
144 /* Symbolic constants for the SMC91c9* series chips, from Erik Stahlman. */
145 #define BANK_SELECT 14 /* Window select register. */
146 #define SMC_SELECT_BANK(x) { outw(x, ioaddr + BANK_SELECT); }
148 /* Bank 0 registers. */
149 #define TCR 0 /* transmit control register */
150 #define TCR_CLEAR 0 /* do NOTHING */
151 #define TCR_ENABLE 0x0001 /* if this is 1, we can transmit */
152 #define TCR_PAD_EN 0x0080 /* pads short packets to 64 bytes */
153 #define TCR_MONCSN 0x0400 /* Monitor Carrier. */
154 #define TCR_FDUPLX 0x0800 /* Full duplex mode. */
155 #define TCR_NORMAL TCR_ENABLE | TCR_PAD_EN
157 #define EPH 2 /* Ethernet Protocol Handler report. */
158 #define EPH_TX_SUC 0x0001
159 #define EPH_SNGLCOL 0x0002
160 #define EPH_MULCOL 0x0004
161 #define EPH_LTX_MULT 0x0008
162 #define EPH_16COL 0x0010
163 #define EPH_SQET 0x0020
164 #define EPH_LTX_BRD 0x0040
165 #define EPH_TX_DEFR 0x0080
166 #define EPH_LAT_COL 0x0200
167 #define EPH_LOST_CAR 0x0400
168 #define EPH_EXC_DEF 0x0800
169 #define EPH_CTR_ROL 0x1000
170 #define EPH_RX_OVRN 0x2000
171 #define EPH_LINK_OK 0x4000
172 #define EPH_TX_UNRN 0x8000
173 #define MEMINFO 8 /* Memory Information Register */
174 #define MEMCFG 10 /* Memory Configuration Register */
176 /* Bank 1 registers. */
178 #define CFG_MII_SELECT 0x8000 /* 91C100 only */
179 #define CFG_NO_WAIT 0x1000
180 #define CFG_FULL_STEP 0x0400
181 #define CFG_SET_SQLCH 0x0200
182 #define CFG_AUI_SELECT 0x0100
183 #define CFG_16BIT 0x0080
184 #define CFG_DIS_LINK 0x0040
185 #define CFG_STATIC 0x0030
186 #define CFG_IRQ_SEL_1 0x0004
187 #define CFG_IRQ_SEL_0 0x0002
192 #define CTL_STORE 0x0001
193 #define CTL_RELOAD 0x0002
194 #define CTL_EE_SELECT 0x0004
195 #define CTL_TE_ENABLE 0x0020
196 #define CTL_CR_ENABLE 0x0040
197 #define CTL_LE_ENABLE 0x0080
198 #define CTL_AUTO_RELEASE 0x0800
199 #define CTL_POWERDOWN 0x2000
201 /* Bank 2 registers. */
203 #define MC_ALLOC 0x20 /* or with number of 256 byte packets */
204 #define MC_RESET 0x40
205 #define MC_RELEASE 0x80 /* remove and release the current rx packet */
206 #define MC_FREEPKT 0xA0 /* Release packet in PNR register */
207 #define MC_ENQUEUE 0xC0 /* Enqueue the packet for transmit */
210 #define FP_RXEMPTY 0x8000
212 #define PTR_AUTO_INC 0x0040
213 #define PTR_READ 0x2000
214 #define PTR_AUTOINC 0x4000
215 #define PTR_RCV 0x8000
218 #define IM_RCV_INT 0x1
219 #define IM_TX_INT 0x2
220 #define IM_TX_EMPTY_INT 0x4
221 #define IM_ALLOC_INT 0x8
222 #define IM_RX_OVRN_INT 0x10
223 #define IM_EPH_INT 0x20
226 enum RxCfg { RxAllMulti = 0x0004, RxPromisc = 0x0002,
227 RxEnable = 0x0100, RxStripCRC = 0x0200};
228 #define RCR_SOFTRESET 0x8000 /* resets the chip */
229 #define RCR_STRIP_CRC 0x200 /* strips CRC */
230 #define RCR_ENABLE 0x100 /* IFF this is set, we can receive packets */
231 #define RCR_ALMUL 0x4 /* receive all multicast packets */
232 #define RCR_PROMISC 0x2 /* enable promiscuous mode */
234 /* the normal settings for the RCR register : */
235 #define RCR_NORMAL (RCR_STRIP_CRC | RCR_ENABLE)
236 #define RCR_CLEAR 0x0 /* set it to a base state */
239 /* BANK 3 -- not the same values as in smc9194! */
245 #define REVISION 0x0a
247 /* Transmit status bits. */
248 #define TS_SUCCESS 0x0001
249 #define TS_16COL 0x0010
250 #define TS_LATCOL 0x0200
251 #define TS_LOSTCAR 0x0400
253 /* Receive status bits. */
254 #define RS_ALGNERR 0x8000
255 #define RS_BADCRC 0x2000
256 #define RS_ODDFRAME 0x1000
257 #define RS_TOOLONG 0x0800
258 #define RS_TOOSHORT 0x0400
259 #define RS_MULTICAST 0x0001
260 #define RS_ERRORS (RS_ALGNERR | RS_BADCRC | RS_TOOLONG | RS_TOOSHORT)
262 #define set_bits(v, p) outw(inw(p)|(v), (p))
263 #define mask_bits(v, p) outw(inw(p)&(v), (p))
265 /*====================================================================*/
267 static void smc91c92_detach(struct pcmcia_device *p_dev);
268 static int smc91c92_config(struct pcmcia_device *link);
269 static void smc91c92_release(struct pcmcia_device *link);
271 static int smc_open(struct net_device *dev);
272 static int smc_close(struct net_device *dev);
273 static int smc_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
274 static void smc_tx_timeout(struct net_device *dev);
275 static netdev_tx_t smc_start_xmit(struct sk_buff *skb,
276 struct net_device *dev);
277 static irqreturn_t smc_interrupt(int irq, void *dev_id);
278 static void smc_rx(struct net_device *dev);
279 static void set_rx_mode(struct net_device *dev);
280 static int s9k_config(struct net_device *dev, struct ifmap *map);
281 static void smc_set_xcvr(struct net_device *dev, int if_port);
282 static void smc_reset(struct net_device *dev);
283 static void media_check(u_long arg);
284 static void mdio_sync(unsigned int addr);
285 static int mdio_read(struct net_device *dev, int phy_id, int loc);
286 static void mdio_write(struct net_device *dev, int phy_id, int loc, int value);
287 static int smc_link_ok(struct net_device *dev);
288 static const struct ethtool_ops ethtool_ops;
290 static const struct net_device_ops smc_netdev_ops = {
291 .ndo_open = smc_open,
292 .ndo_stop = smc_close,
293 .ndo_start_xmit = smc_start_xmit,
294 .ndo_tx_timeout = smc_tx_timeout,
295 .ndo_set_config = s9k_config,
296 .ndo_set_rx_mode = set_rx_mode,
297 .ndo_do_ioctl = smc_ioctl,
298 .ndo_change_mtu = eth_change_mtu,
299 .ndo_set_mac_address = eth_mac_addr,
300 .ndo_validate_addr = eth_validate_addr,
303 static int smc91c92_probe(struct pcmcia_device *link)
305 struct smc_private *smc;
306 struct net_device *dev;
308 dev_dbg(&link->dev, "smc91c92_attach()\n");
310 /* Create new ethernet device */
311 dev = alloc_etherdev(sizeof(struct smc_private));
314 smc = netdev_priv(dev);
318 spin_lock_init(&smc->lock);
320 /* The SMC91c92-specific entries in the device structure. */
321 dev->netdev_ops = &smc_netdev_ops;
322 SET_ETHTOOL_OPS(dev, ðtool_ops);
323 dev->watchdog_timeo = TX_TIMEOUT;
325 smc->mii_if.dev = dev;
326 smc->mii_if.mdio_read = mdio_read;
327 smc->mii_if.mdio_write = mdio_write;
328 smc->mii_if.phy_id_mask = 0x1f;
329 smc->mii_if.reg_num_mask = 0x1f;
331 return smc91c92_config(link);
332 } /* smc91c92_attach */
334 static void smc91c92_detach(struct pcmcia_device *link)
336 struct net_device *dev = link->priv;
338 dev_dbg(&link->dev, "smc91c92_detach\n");
340 unregister_netdev(dev);
342 smc91c92_release(link);
345 } /* smc91c92_detach */
347 /*====================================================================*/
349 static int cvt_ascii_address(struct net_device *dev, char *s)
355 for (i = 0; i < 6; i++) {
357 for (j = 0; j < 2; j++) {
360 da += ((c >= '0') && (c <= '9')) ?
361 (c - '0') : ((c & 0x0f) + 9);
363 dev->dev_addr[i] = da;
368 /*====================================================================
370 Configuration stuff for Megahertz cards
372 mhz_3288_power() is used to power up a 3288's ethernet chip.
373 mhz_mfc_config() handles socket setup for multifunction (1144
374 and 3288) cards. mhz_setup() gets a card's hardware ethernet
377 ======================================================================*/
379 static int mhz_3288_power(struct pcmcia_device *link)
381 struct net_device *dev = link->priv;
382 struct smc_private *smc = netdev_priv(dev);
385 /* Read the ISR twice... */
386 readb(smc->base+MEGAHERTZ_ISR);
388 readb(smc->base+MEGAHERTZ_ISR);
393 /* Now read and write the COR... */
394 tmp = readb(smc->base + link->config_base + CISREG_COR);
396 writeb(tmp, smc->base + link->config_base + CISREG_COR);
401 static int mhz_mfc_config_check(struct pcmcia_device *p_dev, void *priv_data)
404 p_dev->io_lines = 16;
405 p_dev->resource[1]->start = p_dev->resource[0]->start;
406 p_dev->resource[1]->end = 8;
407 p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
408 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
409 p_dev->resource[0]->end = 16;
410 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
411 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
412 for (k = 0; k < 0x400; k += 0x10) {
415 p_dev->resource[0]->start = k ^ 0x300;
416 if (!pcmcia_request_io(p_dev))
422 static int mhz_mfc_config(struct pcmcia_device *link)
424 struct net_device *dev = link->priv;
425 struct smc_private *smc = netdev_priv(dev);
429 link->config_flags |= CONF_ENABLE_SPKR | CONF_ENABLE_IRQ |
432 /* The Megahertz combo cards have modem-like CIS entries, so
433 we have to explicitly try a bunch of port combinations. */
434 if (pcmcia_loop_config(link, mhz_mfc_config_check, NULL))
437 dev->base_addr = link->resource[0]->start;
439 /* Allocate a memory window, for accessing the ISR */
440 link->resource[2]->flags = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
441 link->resource[2]->start = link->resource[2]->end = 0;
442 i = pcmcia_request_window(link, link->resource[2], 0);
446 smc->base = ioremap(link->resource[2]->start,
447 resource_size(link->resource[2]));
448 offset = (smc->manfid == MANFID_MOTOROLA) ? link->config_base : 0;
449 i = pcmcia_map_mem_page(link, link->resource[2], offset);
451 (smc->manfid == MANFID_MEGAHERTZ) &&
452 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
453 mhz_3288_power(link);
458 static int pcmcia_get_versmac(struct pcmcia_device *p_dev,
462 struct net_device *dev = priv;
466 if (pcmcia_parse_tuple(tuple, &parse))
469 buf = parse.version_1.str + parse.version_1.ofs[3];
471 if ((parse.version_1.ns > 3) && (cvt_ascii_address(dev, buf) == 0))
477 static int mhz_setup(struct pcmcia_device *link)
479 struct net_device *dev = link->priv;
484 /* Read the station address from the CIS. It is stored as the last
485 (fourth) string in the Version 1 Version/ID tuple. */
486 if ((link->prod_id[3]) &&
487 (cvt_ascii_address(dev, link->prod_id[3]) == 0))
490 /* Workarounds for broken cards start here. */
491 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
492 if (!pcmcia_loop_tuple(link, CISTPL_VERS_1, pcmcia_get_versmac, dev))
495 /* Another possibility: for the EM3288, in a special tuple */
497 len = pcmcia_get_tuple(link, 0x81, &buf);
498 if (buf && len >= 13) {
500 if (cvt_ascii_address(dev, buf) == 0)
508 /*======================================================================
510 Configuration stuff for the Motorola Mariner
512 mot_config() writes directly to the Mariner configuration
513 registers because the CIS is just bogus.
515 ======================================================================*/
517 static void mot_config(struct pcmcia_device *link)
519 struct net_device *dev = link->priv;
520 struct smc_private *smc = netdev_priv(dev);
521 unsigned int ioaddr = dev->base_addr;
522 unsigned int iouart = link->resource[1]->start;
524 /* Set UART base address and force map with COR bit 1 */
525 writeb(iouart & 0xff, smc->base + MOT_UART + CISREG_IOBASE_0);
526 writeb((iouart >> 8) & 0xff, smc->base + MOT_UART + CISREG_IOBASE_1);
527 writeb(MOT_NORMAL, smc->base + MOT_UART + CISREG_COR);
529 /* Set SMC base address and force map with COR bit 1 */
530 writeb(ioaddr & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_0);
531 writeb((ioaddr >> 8) & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_1);
532 writeb(MOT_NORMAL, smc->base + MOT_LAN + CISREG_COR);
534 /* Wait for things to settle down */
538 static int mot_setup(struct pcmcia_device *link)
540 struct net_device *dev = link->priv;
541 unsigned int ioaddr = dev->base_addr;
545 /* Read Ethernet address from Serial EEPROM */
547 for (i = 0; i < 3; i++) {
549 outw(MOT_EEPROM + i, ioaddr + POINTER);
551 outw((CTL_RELOAD | CTL_EE_SELECT), ioaddr + CONTROL);
553 for (loop = wait = 0; loop < 200; loop++) {
555 wait = ((CTL_RELOAD | CTL_STORE) & inw(ioaddr + CONTROL));
556 if (wait == 0) break;
562 addr = inw(ioaddr + GENERAL);
563 dev->dev_addr[2*i] = addr & 0xff;
564 dev->dev_addr[2*i+1] = (addr >> 8) & 0xff;
570 /*====================================================================*/
572 static int smc_configcheck(struct pcmcia_device *p_dev, void *priv_data)
574 p_dev->resource[0]->end = 16;
575 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
576 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
578 return pcmcia_request_io(p_dev);
581 static int smc_config(struct pcmcia_device *link)
583 struct net_device *dev = link->priv;
586 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
588 i = pcmcia_loop_config(link, smc_configcheck, NULL);
590 dev->base_addr = link->resource[0]->start;
596 static int smc_setup(struct pcmcia_device *link)
598 struct net_device *dev = link->priv;
600 /* Check for a LAN function extension tuple */
601 if (!pcmcia_get_mac_from_cis(link, dev))
604 /* Try the third string in the Version 1 Version/ID tuple. */
605 if (link->prod_id[2]) {
606 if (cvt_ascii_address(dev, link->prod_id[2]) == 0)
612 /*====================================================================*/
614 static int osi_config(struct pcmcia_device *link)
616 struct net_device *dev = link->priv;
617 static const unsigned int com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
620 link->config_flags |= CONF_ENABLE_SPKR | CONF_ENABLE_IRQ;
621 link->resource[0]->end = 64;
622 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
623 link->resource[1]->end = 8;
625 /* Enable Hard Decode, LAN, Modem */
627 link->config_index = 0x23;
629 for (i = j = 0; j < 4; j++) {
630 link->resource[1]->start = com[j];
631 i = pcmcia_request_io(link);
636 /* Fallback: turn off hard decode */
637 link->config_index = 0x03;
638 link->resource[1]->end = 0;
639 i = pcmcia_request_io(link);
641 dev->base_addr = link->resource[0]->start + 0x10;
645 static int osi_load_firmware(struct pcmcia_device *link)
647 const struct firmware *fw;
650 err = request_firmware(&fw, FIRMWARE_NAME, &link->dev);
652 pr_err("Failed to load firmware \"%s\"\n", FIRMWARE_NAME);
656 /* Download the Seven of Diamonds firmware */
657 for (i = 0; i < fw->size; i++) {
658 outb(fw->data[i], link->resource[0]->start + 2);
661 release_firmware(fw);
665 static int pcmcia_osi_mac(struct pcmcia_device *p_dev,
669 struct net_device *dev = priv;
672 if (tuple->TupleDataLen < 8)
674 if (tuple->TupleData[0] != 0x04)
676 for (i = 0; i < 6; i++)
677 dev->dev_addr[i] = tuple->TupleData[i+2];
682 static int osi_setup(struct pcmcia_device *link, u_short manfid, u_short cardid)
684 struct net_device *dev = link->priv;
687 /* Read the station address from tuple 0x90, subtuple 0x04 */
688 if (pcmcia_loop_tuple(link, 0x90, pcmcia_osi_mac, dev))
691 if (((manfid == MANFID_OSITECH) &&
692 (cardid == PRODID_OSITECH_SEVEN)) ||
693 ((manfid == MANFID_PSION) &&
694 (cardid == PRODID_PSION_NET100))) {
695 rc = osi_load_firmware(link);
698 } else if (manfid == MANFID_OSITECH) {
699 /* Make sure both functions are powered up */
700 set_bits(0x300, link->resource[0]->start + OSITECH_AUI_PWR);
701 /* Now, turn on the interrupt for both card functions */
702 set_bits(0x300, link->resource[0]->start + OSITECH_RESET_ISR);
703 dev_dbg(&link->dev, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n",
704 inw(link->resource[0]->start + OSITECH_AUI_PWR),
705 inw(link->resource[0]->start + OSITECH_RESET_ISR));
710 static int smc91c92_suspend(struct pcmcia_device *link)
712 struct net_device *dev = link->priv;
715 netif_device_detach(dev);
720 static int smc91c92_resume(struct pcmcia_device *link)
722 struct net_device *dev = link->priv;
723 struct smc_private *smc = netdev_priv(dev);
726 if ((smc->manfid == MANFID_MEGAHERTZ) &&
727 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
728 mhz_3288_power(link);
729 if (smc->manfid == MANFID_MOTOROLA)
731 if ((smc->manfid == MANFID_OSITECH) &&
732 (smc->cardid != PRODID_OSITECH_SEVEN)) {
733 /* Power up the card and enable interrupts */
734 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR);
735 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR);
737 if (((smc->manfid == MANFID_OSITECH) &&
738 (smc->cardid == PRODID_OSITECH_SEVEN)) ||
739 ((smc->manfid == MANFID_PSION) &&
740 (smc->cardid == PRODID_PSION_NET100))) {
741 i = osi_load_firmware(link);
743 netdev_err(dev, "Failed to load firmware\n");
749 netif_device_attach(dev);
756 /*======================================================================
758 This verifies that the chip is some SMC91cXX variant, and returns
759 the revision code if successful. Otherwise, it returns -ENODEV.
761 ======================================================================*/
763 static int check_sig(struct pcmcia_device *link)
765 struct net_device *dev = link->priv;
766 unsigned int ioaddr = dev->base_addr;
771 if (inw(ioaddr + BANK_SELECT) >> 8 != 0x33) {
772 /* Try powering up the chip */
773 outw(0, ioaddr + CONTROL);
777 /* Try setting bus width */
778 width = (link->resource[0]->flags == IO_DATA_PATH_WIDTH_AUTO);
779 s = inb(ioaddr + CONFIG);
784 outb(s, ioaddr + CONFIG);
786 /* Check Base Address Register to make sure bus width is OK */
787 s = inw(ioaddr + BASE_ADDR);
788 if ((inw(ioaddr + BANK_SELECT) >> 8 == 0x33) &&
789 ((s >> 8) != (s & 0xff))) {
791 s = inw(ioaddr + REVISION);
796 netdev_info(dev, "using 8-bit IO window\n");
798 smc91c92_suspend(link);
799 pcmcia_fixup_iowidth(link);
800 smc91c92_resume(link);
801 return check_sig(link);
806 static int smc91c92_config(struct pcmcia_device *link)
808 struct net_device *dev = link->priv;
809 struct smc_private *smc = netdev_priv(dev);
815 dev_dbg(&link->dev, "smc91c92_config\n");
817 smc->manfid = link->manf_id;
818 smc->cardid = link->card_id;
820 if ((smc->manfid == MANFID_OSITECH) &&
821 (smc->cardid != PRODID_OSITECH_SEVEN)) {
822 i = osi_config(link);
823 } else if ((smc->manfid == MANFID_MOTOROLA) ||
824 ((smc->manfid == MANFID_MEGAHERTZ) &&
825 ((smc->cardid == PRODID_MEGAHERTZ_VARIOUS) ||
826 (smc->cardid == PRODID_MEGAHERTZ_EM3288)))) {
827 i = mhz_mfc_config(link);
829 i = smc_config(link);
834 i = pcmcia_request_irq(link, smc_interrupt);
837 i = pcmcia_enable_device(link);
841 if (smc->manfid == MANFID_MOTOROLA)
844 dev->irq = link->irq;
846 if ((if_port >= 0) && (if_port <= 2))
847 dev->if_port = if_port;
849 dev_notice(&link->dev, "invalid if_port requested\n");
851 switch (smc->manfid) {
854 i = osi_setup(link, smc->manfid, smc->cardid); break;
856 case MANFID_NEW_MEDIA:
857 i = smc_setup(link); break;
858 case 0x128: /* For broken Megahertz cards */
859 case MANFID_MEGAHERTZ:
860 i = mhz_setup(link); break;
861 case MANFID_MOTOROLA:
862 default: /* get the hw address from EEPROM */
863 i = mot_setup(link); break;
867 dev_notice(&link->dev, "Unable to find hardware address.\n");
874 rev = check_sig(link);
878 case 3: name = "92"; break;
879 case 4: name = ((rev & 15) >= 6) ? "96" : "94"; break;
880 case 5: name = "95"; break;
881 case 7: name = "100"; break;
882 case 8: name = "100-FD"; break;
883 case 9: name = "110"; break;
886 ioaddr = dev->base_addr;
890 mir = inw(ioaddr + MEMINFO) & 0xff;
891 if (mir == 0xff) mir++;
892 /* Get scale factor for memory size */
893 mcr = ((rev >> 4) > 3) ? inw(ioaddr + MEMCFG) : 0x0200;
894 mir *= 128 * (1<<((mcr >> 9) & 7));
896 smc->cfg = inw(ioaddr + CONFIG) & ~CFG_AUI_SELECT;
897 smc->cfg |= CFG_NO_WAIT | CFG_16BIT | CFG_STATIC;
898 if (smc->manfid == MANFID_OSITECH)
899 smc->cfg |= CFG_IRQ_SEL_1 | CFG_IRQ_SEL_0;
901 smc->cfg |= CFG_MII_SELECT;
905 if (smc->cfg & CFG_MII_SELECT) {
908 for (i = 0; i < 32; i++) {
909 j = mdio_read(dev, i, 1);
910 if ((j != 0) && (j != 0xffff)) break;
912 smc->mii_if.phy_id = (i < 32) ? i : -1;
917 SET_NETDEV_DEV(dev, &link->dev);
919 if (register_netdev(dev) != 0) {
920 dev_err(&link->dev, "register_netdev() failed\n");
924 netdev_info(dev, "smc91c%s rev %d: io %#3lx, irq %d, hw_addr %pM\n",
925 name, (rev & 0x0f), dev->base_addr, dev->irq, dev->dev_addr);
929 netdev_info(dev, " %lu byte", mir);
931 netdev_info(dev, " %lu kb", mir>>10);
932 pr_cont(" buffer, %s xcvr\n",
933 (smc->cfg & CFG_MII_SELECT) ? "MII" : if_names[dev->if_port]);
936 if (smc->cfg & CFG_MII_SELECT) {
937 if (smc->mii_if.phy_id != -1) {
938 netdev_dbg(dev, " MII transceiver at index %d, status %x\n",
939 smc->mii_if.phy_id, j);
941 netdev_notice(dev, " No MII transceivers found!\n");
947 unregister_netdev(dev);
949 smc91c92_release(link);
952 } /* smc91c92_config */
954 static void smc91c92_release(struct pcmcia_device *link)
956 dev_dbg(&link->dev, "smc91c92_release\n");
957 if (link->resource[2]->end) {
958 struct net_device *dev = link->priv;
959 struct smc_private *smc = netdev_priv(dev);
962 pcmcia_disable_device(link);
965 /*======================================================================
967 MII interface support for SMC91cXX based cards
968 ======================================================================*/
970 #define MDIO_SHIFT_CLK 0x04
971 #define MDIO_DATA_OUT 0x01
972 #define MDIO_DIR_WRITE 0x08
973 #define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
974 #define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
975 #define MDIO_DATA_READ 0x02
977 static void mdio_sync(unsigned int addr)
980 for (bits = 0; bits < 32; bits++) {
981 outb(MDIO_DATA_WRITE1, addr);
982 outb(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
986 static int mdio_read(struct net_device *dev, int phy_id, int loc)
988 unsigned int addr = dev->base_addr + MGMT;
989 u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
993 for (i = 13; i >= 0; i--) {
994 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
996 outb(dat | MDIO_SHIFT_CLK, addr);
998 for (i = 19; i > 0; i--) {
1000 retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
1001 outb(MDIO_SHIFT_CLK, addr);
1003 return (retval>>1) & 0xffff;
1006 static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
1008 unsigned int addr = dev->base_addr + MGMT;
1009 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
1013 for (i = 31; i >= 0; i--) {
1014 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1016 outb(dat | MDIO_SHIFT_CLK, addr);
1018 for (i = 1; i >= 0; i--) {
1020 outb(MDIO_SHIFT_CLK, addr);
1024 /*======================================================================
1026 The driver core code, most of which should be common with a
1027 non-PCMCIA implementation.
1029 ======================================================================*/
1032 static void smc_dump(struct net_device *dev)
1034 unsigned int ioaddr = dev->base_addr;
1036 save = inw(ioaddr + BANK_SELECT);
1037 for (w = 0; w < 4; w++) {
1039 netdev_dbg(dev, "bank %d: ", w);
1040 for (i = 0; i < 14; i += 2)
1041 pr_cont(" %04x", inw(ioaddr + i));
1044 outw(save, ioaddr + BANK_SELECT);
1048 static int smc_open(struct net_device *dev)
1050 struct smc_private *smc = netdev_priv(dev);
1051 struct pcmcia_device *link = smc->p_dev;
1053 dev_dbg(&link->dev, "%s: smc_open(%p), ID/Window %4.4x.\n",
1054 dev->name, dev, inw(dev->base_addr + BANK_SELECT));
1059 /* Check that the PCMCIA card is still here. */
1060 if (!pcmcia_dev_present(link))
1062 /* Physical device present signature. */
1063 if (check_sig(link) < 0) {
1064 netdev_info(dev, "Yikes! Bad chip signature!\n");
1069 netif_start_queue(dev);
1070 smc->saved_skb = NULL;
1071 smc->packets_waiting = 0;
1074 init_timer(&smc->media);
1075 smc->media.function = media_check;
1076 smc->media.data = (u_long) dev;
1077 smc->media.expires = jiffies + HZ;
1078 add_timer(&smc->media);
1083 /*====================================================================*/
1085 static int smc_close(struct net_device *dev)
1087 struct smc_private *smc = netdev_priv(dev);
1088 struct pcmcia_device *link = smc->p_dev;
1089 unsigned int ioaddr = dev->base_addr;
1091 dev_dbg(&link->dev, "%s: smc_close(), status %4.4x.\n",
1092 dev->name, inw(ioaddr + BANK_SELECT));
1094 netif_stop_queue(dev);
1096 /* Shut off all interrupts, and turn off the Tx and Rx sections.
1097 Don't bother to check for chip present. */
1098 SMC_SELECT_BANK(2); /* Nominally paranoia, but do no assume... */
1099 outw(0, ioaddr + INTERRUPT);
1101 mask_bits(0xff00, ioaddr + RCR);
1102 mask_bits(0xff00, ioaddr + TCR);
1104 /* Put the chip into power-down mode. */
1106 outw(CTL_POWERDOWN, ioaddr + CONTROL );
1109 del_timer_sync(&smc->media);
1114 /*======================================================================
1116 Transfer a packet to the hardware and trigger the packet send.
1117 This may be called at either from either the Tx queue code
1118 or the interrupt handler.
1120 ======================================================================*/
1122 static void smc_hardware_send_packet(struct net_device * dev)
1124 struct smc_private *smc = netdev_priv(dev);
1125 struct sk_buff *skb = smc->saved_skb;
1126 unsigned int ioaddr = dev->base_addr;
1130 netdev_err(dev, "In XMIT with no packet to send\n");
1134 /* There should be a packet slot waiting. */
1135 packet_no = inw(ioaddr + PNR_ARR) >> 8;
1136 if (packet_no & 0x80) {
1137 /* If not, there is a hardware problem! Likely an ejected card. */
1138 netdev_warn(dev, "hardware Tx buffer allocation failed, status %#2.2x\n",
1140 dev_kfree_skb_irq(skb);
1141 smc->saved_skb = NULL;
1142 netif_start_queue(dev);
1146 dev->stats.tx_bytes += skb->len;
1147 /* The card should use the just-allocated buffer. */
1148 outw(packet_no, ioaddr + PNR_ARR);
1149 /* point to the beginning of the packet */
1150 outw(PTR_AUTOINC , ioaddr + POINTER);
1152 /* Send the packet length (+6 for status, length and ctl byte)
1153 and the status word (set to zeros). */
1155 u_char *buf = skb->data;
1156 u_int length = skb->len; /* The chip will pad to ethernet min. */
1158 netdev_dbg(dev, "Trying to xmit packet of length %d\n", length);
1160 /* send the packet length: +6 for status word, length, and ctl */
1161 outw(0, ioaddr + DATA_1);
1162 outw(length + 6, ioaddr + DATA_1);
1163 outsw(ioaddr + DATA_1, buf, length >> 1);
1165 /* The odd last byte, if there is one, goes in the control word. */
1166 outw((length & 1) ? 0x2000 | buf[length-1] : 0, ioaddr + DATA_1);
1169 /* Enable the Tx interrupts, both Tx (TxErr) and TxEmpty. */
1170 outw(((IM_TX_INT|IM_TX_EMPTY_INT)<<8) |
1171 (inw(ioaddr + INTERRUPT) & 0xff00),
1172 ioaddr + INTERRUPT);
1174 /* The chip does the rest of the work. */
1175 outw(MC_ENQUEUE , ioaddr + MMU_CMD);
1177 smc->saved_skb = NULL;
1178 dev_kfree_skb_irq(skb);
1179 dev->trans_start = jiffies;
1180 netif_start_queue(dev);
1183 /*====================================================================*/
1185 static void smc_tx_timeout(struct net_device *dev)
1187 struct smc_private *smc = netdev_priv(dev);
1188 unsigned int ioaddr = dev->base_addr;
1190 netdev_notice(dev, "transmit timed out, Tx_status %2.2x status %4.4x.\n",
1191 inw(ioaddr)&0xff, inw(ioaddr + 2));
1192 dev->stats.tx_errors++;
1194 dev->trans_start = jiffies; /* prevent tx timeout */
1195 smc->saved_skb = NULL;
1196 netif_wake_queue(dev);
1199 static netdev_tx_t smc_start_xmit(struct sk_buff *skb,
1200 struct net_device *dev)
1202 struct smc_private *smc = netdev_priv(dev);
1203 unsigned int ioaddr = dev->base_addr;
1206 unsigned long flags;
1208 netif_stop_queue(dev);
1210 netdev_dbg(dev, "smc_start_xmit(length = %d) called, status %04x\n",
1211 skb->len, inw(ioaddr + 2));
1213 if (smc->saved_skb) {
1214 /* THIS SHOULD NEVER HAPPEN. */
1215 dev->stats.tx_aborted_errors++;
1216 netdev_dbg(dev, "Internal error -- sent packet while busy\n");
1217 return NETDEV_TX_BUSY;
1219 smc->saved_skb = skb;
1221 num_pages = skb->len >> 8;
1223 if (num_pages > 7) {
1224 netdev_err(dev, "Far too big packet error: %d pages\n", num_pages);
1225 dev_kfree_skb (skb);
1226 smc->saved_skb = NULL;
1227 dev->stats.tx_dropped++;
1228 return NETDEV_TX_OK; /* Do not re-queue this packet. */
1230 /* A packet is now waiting. */
1231 smc->packets_waiting++;
1233 spin_lock_irqsave(&smc->lock, flags);
1234 SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */
1236 /* need MC_RESET to keep the memory consistent. errata? */
1238 outw(MC_RESET, ioaddr + MMU_CMD);
1242 /* Allocate the memory; send the packet now if we win. */
1243 outw(MC_ALLOC | num_pages, ioaddr + MMU_CMD);
1244 for (time_out = MEMORY_WAIT_TIME; time_out >= 0; time_out--) {
1245 ir = inw(ioaddr+INTERRUPT);
1246 if (ir & IM_ALLOC_INT) {
1247 /* Acknowledge the interrupt, send the packet. */
1248 outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT);
1249 smc_hardware_send_packet(dev); /* Send the packet now.. */
1250 spin_unlock_irqrestore(&smc->lock, flags);
1251 return NETDEV_TX_OK;
1255 /* Otherwise defer until the Tx-space-allocated interrupt. */
1256 netdev_dbg(dev, "memory allocation deferred.\n");
1257 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT);
1258 spin_unlock_irqrestore(&smc->lock, flags);
1260 return NETDEV_TX_OK;
1263 /*======================================================================
1265 Handle a Tx anomalous event. Entered while in Window 2.
1267 ======================================================================*/
1269 static void smc_tx_err(struct net_device * dev)
1271 struct smc_private *smc = netdev_priv(dev);
1272 unsigned int ioaddr = dev->base_addr;
1273 int saved_packet = inw(ioaddr + PNR_ARR) & 0xff;
1274 int packet_no = inw(ioaddr + FIFO_PORTS) & 0x7f;
1277 /* select this as the packet to read from */
1278 outw(packet_no, ioaddr + PNR_ARR);
1280 /* read the first word from this packet */
1281 outw(PTR_AUTOINC | PTR_READ | 0, ioaddr + POINTER);
1283 tx_status = inw(ioaddr + DATA_1);
1285 dev->stats.tx_errors++;
1286 if (tx_status & TS_LOSTCAR) dev->stats.tx_carrier_errors++;
1287 if (tx_status & TS_LATCOL) dev->stats.tx_window_errors++;
1288 if (tx_status & TS_16COL) {
1289 dev->stats.tx_aborted_errors++;
1293 if (tx_status & TS_SUCCESS) {
1294 netdev_notice(dev, "Successful packet caused error interrupt?\n");
1296 /* re-enable transmit */
1298 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1301 outw(MC_FREEPKT, ioaddr + MMU_CMD); /* Free the packet memory. */
1303 /* one less packet waiting for me */
1304 smc->packets_waiting--;
1306 outw(saved_packet, ioaddr + PNR_ARR);
1309 /*====================================================================*/
1311 static void smc_eph_irq(struct net_device *dev)
1313 struct smc_private *smc = netdev_priv(dev);
1314 unsigned int ioaddr = dev->base_addr;
1315 u_short card_stats, ephs;
1318 ephs = inw(ioaddr + EPH);
1319 netdev_dbg(dev, "Ethernet protocol handler interrupt, status %4.4x.\n",
1321 /* Could be a counter roll-over warning: update stats. */
1322 card_stats = inw(ioaddr + COUNTER);
1323 /* single collisions */
1324 dev->stats.collisions += card_stats & 0xF;
1326 /* multiple collisions */
1327 dev->stats.collisions += card_stats & 0xF;
1328 #if 0 /* These are for when linux supports these statistics */
1329 card_stats >>= 4; /* deferred */
1330 card_stats >>= 4; /* excess deferred */
1332 /* If we had a transmit error we must re-enable the transmitter. */
1333 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1335 /* Clear a link error interrupt. */
1337 outw(CTL_AUTO_RELEASE | 0x0000, ioaddr + CONTROL);
1338 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1343 /*====================================================================*/
1345 static irqreturn_t smc_interrupt(int irq, void *dev_id)
1347 struct net_device *dev = dev_id;
1348 struct smc_private *smc = netdev_priv(dev);
1349 unsigned int ioaddr;
1350 u_short saved_bank, saved_pointer, mask, status;
1351 unsigned int handled = 1;
1352 char bogus_cnt = INTR_WORK; /* Work we are willing to do. */
1354 if (!netif_device_present(dev))
1357 ioaddr = dev->base_addr;
1359 netdev_dbg(dev, "SMC91c92 interrupt %d at %#x.\n",
1362 spin_lock(&smc->lock);
1364 saved_bank = inw(ioaddr + BANK_SELECT);
1365 if ((saved_bank & 0xff00) != 0x3300) {
1366 /* The device does not exist -- the card could be off-line, or
1367 maybe it has been ejected. */
1368 netdev_dbg(dev, "SMC91c92 interrupt %d for non-existent/ejected device.\n",
1375 saved_pointer = inw(ioaddr + POINTER);
1376 mask = inw(ioaddr + INTERRUPT) >> 8;
1377 /* clear all interrupts */
1378 outw(0, ioaddr + INTERRUPT);
1380 do { /* read the status flag, and mask it */
1381 status = inw(ioaddr + INTERRUPT) & 0xff;
1382 netdev_dbg(dev, "Status is %#2.2x (mask %#2.2x).\n",
1384 if ((status & mask) == 0) {
1385 if (bogus_cnt == INTR_WORK)
1389 if (status & IM_RCV_INT) {
1390 /* Got a packet(s). */
1393 if (status & IM_TX_INT) {
1395 outw(IM_TX_INT, ioaddr + INTERRUPT);
1398 if (status & IM_TX_EMPTY_INT) {
1399 outw(IM_TX_EMPTY_INT, ioaddr + INTERRUPT);
1400 mask &= ~IM_TX_EMPTY_INT;
1401 dev->stats.tx_packets += smc->packets_waiting;
1402 smc->packets_waiting = 0;
1404 if (status & IM_ALLOC_INT) {
1405 /* Clear this interrupt so it doesn't happen again */
1406 mask &= ~IM_ALLOC_INT;
1408 smc_hardware_send_packet(dev);
1410 /* enable xmit interrupts based on this */
1411 mask |= (IM_TX_EMPTY_INT | IM_TX_INT);
1413 /* and let the card send more packets to me */
1414 netif_wake_queue(dev);
1416 if (status & IM_RX_OVRN_INT) {
1417 dev->stats.rx_errors++;
1418 dev->stats.rx_fifo_errors++;
1420 smc->rx_ovrn = 1; /* need MC_RESET outside smc_interrupt */
1421 outw(IM_RX_OVRN_INT, ioaddr + INTERRUPT);
1423 if (status & IM_EPH_INT)
1425 } while (--bogus_cnt);
1427 netdev_dbg(dev, " Restoring saved registers mask %2.2x bank %4.4x pointer %4.4x.\n",
1428 mask, saved_bank, saved_pointer);
1430 /* restore state register */
1431 outw((mask<<8), ioaddr + INTERRUPT);
1432 outw(saved_pointer, ioaddr + POINTER);
1433 SMC_SELECT_BANK(saved_bank);
1435 netdev_dbg(dev, "Exiting interrupt IRQ%d.\n", irq);
1439 if ((smc->manfid == MANFID_OSITECH) &&
1440 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1441 /* Retrigger interrupt if needed */
1442 mask_bits(0x00ff, ioaddr-0x10+OSITECH_RESET_ISR);
1443 set_bits(0x0300, ioaddr-0x10+OSITECH_RESET_ISR);
1445 if (smc->manfid == MANFID_MOTOROLA) {
1447 cor = readb(smc->base + MOT_UART + CISREG_COR);
1448 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_UART + CISREG_COR);
1449 writeb(cor, smc->base + MOT_UART + CISREG_COR);
1450 cor = readb(smc->base + MOT_LAN + CISREG_COR);
1451 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_LAN + CISREG_COR);
1452 writeb(cor, smc->base + MOT_LAN + CISREG_COR);
1455 if ((smc->base != NULL) && /* Megahertz MFC's */
1456 (smc->manfid == MANFID_MEGAHERTZ) &&
1457 (smc->cardid == PRODID_MEGAHERTZ_EM3288)) {
1460 tmp = readb(smc->base+MEGAHERTZ_ISR);
1461 tmp = readb(smc->base+MEGAHERTZ_ISR);
1463 /* Retrigger interrupt if needed */
1464 writeb(tmp, smc->base + MEGAHERTZ_ISR);
1465 writeb(tmp, smc->base + MEGAHERTZ_ISR);
1468 spin_unlock(&smc->lock);
1469 return IRQ_RETVAL(handled);
1472 /*====================================================================*/
1474 static void smc_rx(struct net_device *dev)
1476 unsigned int ioaddr = dev->base_addr;
1478 int packet_length; /* Caution: not frame length, rather words
1479 to transfer from the chip. */
1481 /* Assertion: we are in Window 2. */
1483 if (inw(ioaddr + FIFO_PORTS) & FP_RXEMPTY) {
1484 netdev_err(dev, "smc_rx() with nothing on Rx FIFO\n");
1488 /* Reset the read pointer, and read the status and packet length. */
1489 outw(PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER);
1490 rx_status = inw(ioaddr + DATA_1);
1491 packet_length = inw(ioaddr + DATA_1) & 0x07ff;
1493 netdev_dbg(dev, "Receive status %4.4x length %d.\n",
1494 rx_status, packet_length);
1496 if (!(rx_status & RS_ERRORS)) {
1497 /* do stuff to make a new packet */
1498 struct sk_buff *skb;
1500 /* Note: packet_length adds 5 or 6 extra bytes here! */
1501 skb = netdev_alloc_skb(dev, packet_length+2);
1504 netdev_dbg(dev, "Low memory, packet dropped.\n");
1505 dev->stats.rx_dropped++;
1506 outw(MC_RELEASE, ioaddr + MMU_CMD);
1510 packet_length -= (rx_status & RS_ODDFRAME ? 5 : 6);
1511 skb_reserve(skb, 2);
1512 insw(ioaddr+DATA_1, skb_put(skb, packet_length),
1513 (packet_length+1)>>1);
1514 skb->protocol = eth_type_trans(skb, dev);
1517 dev->last_rx = jiffies;
1518 dev->stats.rx_packets++;
1519 dev->stats.rx_bytes += packet_length;
1520 if (rx_status & RS_MULTICAST)
1521 dev->stats.multicast++;
1524 dev->stats.rx_errors++;
1526 if (rx_status & RS_ALGNERR) dev->stats.rx_frame_errors++;
1527 if (rx_status & (RS_TOOSHORT | RS_TOOLONG))
1528 dev->stats.rx_length_errors++;
1529 if (rx_status & RS_BADCRC) dev->stats.rx_crc_errors++;
1531 /* Let the MMU free the memory of this packet. */
1532 outw(MC_RELEASE, ioaddr + MMU_CMD);
1535 /*======================================================================
1537 Set the receive mode.
1539 This routine is used by both the protocol level to notify us of
1540 promiscuous/multicast mode changes, and by the open/reset code to
1541 initialize the Rx registers. We always set the multicast list and
1542 leave the receiver running.
1544 ======================================================================*/
1546 static void set_rx_mode(struct net_device *dev)
1548 unsigned int ioaddr = dev->base_addr;
1549 struct smc_private *smc = netdev_priv(dev);
1550 unsigned char multicast_table[8];
1551 unsigned long flags;
1552 u_short rx_cfg_setting;
1555 memset(multicast_table, 0, sizeof(multicast_table));
1557 if (dev->flags & IFF_PROMISC) {
1558 rx_cfg_setting = RxStripCRC | RxEnable | RxPromisc | RxAllMulti;
1559 } else if (dev->flags & IFF_ALLMULTI)
1560 rx_cfg_setting = RxStripCRC | RxEnable | RxAllMulti;
1562 if (!netdev_mc_empty(dev)) {
1563 struct netdev_hw_addr *ha;
1565 netdev_for_each_mc_addr(ha, dev) {
1566 u_int position = ether_crc(6, ha->addr);
1567 multicast_table[position >> 29] |= 1 << ((position >> 26) & 7);
1570 rx_cfg_setting = RxStripCRC | RxEnable;
1573 /* Load MC table and Rx setting into the chip without interrupts. */
1574 spin_lock_irqsave(&smc->lock, flags);
1576 for (i = 0; i < 8; i++)
1577 outb(multicast_table[i], ioaddr + MULTICAST0 + i);
1579 outw(rx_cfg_setting, ioaddr + RCR);
1581 spin_unlock_irqrestore(&smc->lock, flags);
1584 /*======================================================================
1586 Senses when a card's config changes. Here, it's coax or TP.
1588 ======================================================================*/
1590 static int s9k_config(struct net_device *dev, struct ifmap *map)
1592 struct smc_private *smc = netdev_priv(dev);
1593 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
1594 if (smc->cfg & CFG_MII_SELECT)
1596 else if (map->port > 2)
1598 dev->if_port = map->port;
1599 netdev_info(dev, "switched to %s port\n", if_names[dev->if_port]);
1605 /*======================================================================
1607 Reset the chip, reloading every register that might be corrupted.
1609 ======================================================================*/
1612 Set transceiver type, perhaps to something other than what the user
1613 specified in dev->if_port.
1615 static void smc_set_xcvr(struct net_device *dev, int if_port)
1617 struct smc_private *smc = netdev_priv(dev);
1618 unsigned int ioaddr = dev->base_addr;
1621 saved_bank = inw(ioaddr + BANK_SELECT);
1624 outw(smc->cfg | CFG_AUI_SELECT, ioaddr + CONFIG);
1625 if ((smc->manfid == MANFID_OSITECH) &&
1626 (smc->cardid != PRODID_OSITECH_SEVEN))
1627 set_bits(OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1628 smc->media_status = ((dev->if_port == 0) ? 0x0001 : 0x0002);
1630 outw(smc->cfg, ioaddr + CONFIG);
1631 if ((smc->manfid == MANFID_OSITECH) &&
1632 (smc->cardid != PRODID_OSITECH_SEVEN))
1633 mask_bits(~OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1634 smc->media_status = ((dev->if_port == 0) ? 0x0012 : 0x4001);
1636 SMC_SELECT_BANK(saved_bank);
1639 static void smc_reset(struct net_device *dev)
1641 unsigned int ioaddr = dev->base_addr;
1642 struct smc_private *smc = netdev_priv(dev);
1645 netdev_dbg(dev, "smc91c92 reset called.\n");
1647 /* The first interaction must be a write to bring the chip out
1650 /* Reset the chip. */
1651 outw(RCR_SOFTRESET, ioaddr + RCR);
1654 /* Clear the transmit and receive configuration registers. */
1655 outw(RCR_CLEAR, ioaddr + RCR);
1656 outw(TCR_CLEAR, ioaddr + TCR);
1658 /* Set the Window 1 control, configuration and station addr registers.
1659 No point in writing the I/O base register ;-> */
1661 /* Automatically release successfully transmitted packets,
1662 Accept link errors, counter and Tx error interrupts. */
1663 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1665 smc_set_xcvr(dev, dev->if_port);
1666 if ((smc->manfid == MANFID_OSITECH) &&
1667 (smc->cardid != PRODID_OSITECH_SEVEN))
1668 outw((dev->if_port == 2 ? OSI_AUI_PWR : 0) |
1669 (inw(ioaddr-0x10+OSITECH_AUI_PWR) & 0xff00),
1670 ioaddr - 0x10 + OSITECH_AUI_PWR);
1672 /* Fill in the physical address. The databook is wrong about the order! */
1673 for (i = 0; i < 6; i += 2)
1674 outw((dev->dev_addr[i+1]<<8)+dev->dev_addr[i],
1675 ioaddr + ADDR0 + i);
1679 outw(MC_RESET, ioaddr + MMU_CMD);
1680 outw(0, ioaddr + INTERRUPT);
1682 /* Re-enable the chip. */
1684 outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) |
1685 TCR_ENABLE | TCR_PAD_EN | smc->duplex, ioaddr + TCR);
1688 if (smc->cfg & CFG_MII_SELECT) {
1692 mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000);
1694 /* Advertise 100F, 100H, 10F, 10H */
1695 mdio_write(dev, smc->mii_if.phy_id, 4, 0x01e1);
1697 /* Restart MII autonegotiation */
1698 mdio_write(dev, smc->mii_if.phy_id, 0, 0x0000);
1699 mdio_write(dev, smc->mii_if.phy_id, 0, 0x1200);
1702 /* Enable interrupts. */
1704 outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,
1705 ioaddr + INTERRUPT);
1708 /*======================================================================
1710 Media selection timer routine
1712 ======================================================================*/
1714 static void media_check(u_long arg)
1716 struct net_device *dev = (struct net_device *) arg;
1717 struct smc_private *smc = netdev_priv(dev);
1718 unsigned int ioaddr = dev->base_addr;
1719 u_short i, media, saved_bank;
1721 unsigned long flags;
1723 spin_lock_irqsave(&smc->lock, flags);
1725 saved_bank = inw(ioaddr + BANK_SELECT);
1727 if (!netif_device_present(dev))
1732 /* need MC_RESET to keep the memory consistent. errata? */
1734 outw(MC_RESET, ioaddr + MMU_CMD);
1737 i = inw(ioaddr + INTERRUPT);
1739 media = inw(ioaddr + EPH) & EPH_LINK_OK;
1741 media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1;
1743 SMC_SELECT_BANK(saved_bank);
1744 spin_unlock_irqrestore(&smc->lock, flags);
1746 /* Check for pending interrupt with watchdog flag set: with
1747 this, we can limp along even if the interrupt is blocked */
1748 if (smc->watchdog++ && ((i>>8) & i)) {
1749 if (!smc->fast_poll)
1750 netdev_info(dev, "interrupt(s) dropped!\n");
1751 local_irq_save(flags);
1752 smc_interrupt(dev->irq, dev);
1753 local_irq_restore(flags);
1754 smc->fast_poll = HZ;
1756 if (smc->fast_poll) {
1758 smc->media.expires = jiffies + HZ/100;
1759 add_timer(&smc->media);
1763 spin_lock_irqsave(&smc->lock, flags);
1765 saved_bank = inw(ioaddr + BANK_SELECT);
1767 if (smc->cfg & CFG_MII_SELECT) {
1768 if (smc->mii_if.phy_id < 0)
1772 link = mdio_read(dev, smc->mii_if.phy_id, 1);
1773 if (!link || (link == 0xffff)) {
1774 netdev_info(dev, "MII is missing!\n");
1775 smc->mii_if.phy_id = -1;
1780 if (link != smc->link_status) {
1781 u_short p = mdio_read(dev, smc->mii_if.phy_id, 5);
1782 netdev_info(dev, "%s link beat\n", link ? "found" : "lost");
1783 smc->duplex = (((p & 0x0100) || ((p & 0x1c0) == 0x40))
1786 netdev_info(dev, "autonegotiation complete: "
1787 "%dbaseT-%cD selected\n",
1788 (p & 0x0180) ? 100 : 10, smc->duplex ? 'F' : 'H');
1791 outw(inw(ioaddr + TCR) | smc->duplex, ioaddr + TCR);
1792 smc->link_status = link;
1797 /* Ignore collisions unless we've had no rx's recently */
1798 if (time_after(jiffies, dev->last_rx + HZ)) {
1799 if (smc->tx_err || (smc->media_status & EPH_16COL))
1804 if (media != smc->media_status) {
1805 if ((media & smc->media_status & 1) &&
1806 ((smc->media_status ^ media) & EPH_LINK_OK))
1807 netdev_info(dev, "%s link beat\n",
1808 smc->media_status & EPH_LINK_OK ? "lost" : "found");
1809 else if ((media & smc->media_status & 2) &&
1810 ((smc->media_status ^ media) & EPH_16COL))
1811 netdev_info(dev, "coax cable %s\n",
1812 media & EPH_16COL ? "problem" : "ok");
1813 if (dev->if_port == 0) {
1815 if (media & EPH_LINK_OK)
1816 netdev_info(dev, "flipped to 10baseT\n");
1818 smc_set_xcvr(dev, 2);
1820 if (media & EPH_16COL)
1821 smc_set_xcvr(dev, 1);
1823 netdev_info(dev, "flipped to 10base2\n");
1826 smc->media_status = media;
1830 smc->media.expires = jiffies + HZ;
1831 add_timer(&smc->media);
1832 SMC_SELECT_BANK(saved_bank);
1833 spin_unlock_irqrestore(&smc->lock, flags);
1836 static int smc_link_ok(struct net_device *dev)
1838 unsigned int ioaddr = dev->base_addr;
1839 struct smc_private *smc = netdev_priv(dev);
1841 if (smc->cfg & CFG_MII_SELECT) {
1842 return mii_link_ok(&smc->mii_if);
1845 return inw(ioaddr + EPH) & EPH_LINK_OK;
1849 static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
1852 unsigned int ioaddr = dev->base_addr;
1854 ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |
1855 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);
1858 tmp = inw(ioaddr + CONFIG);
1859 ecmd->port = (tmp & CFG_AUI_SELECT) ? PORT_AUI : PORT_TP;
1860 ecmd->transceiver = XCVR_INTERNAL;
1861 ethtool_cmd_speed_set(ecmd, SPEED_10);
1862 ecmd->phy_address = ioaddr + MGMT;
1865 tmp = inw(ioaddr + TCR);
1866 ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF;
1871 static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
1874 unsigned int ioaddr = dev->base_addr;
1876 if (ethtool_cmd_speed(ecmd) != SPEED_10)
1878 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
1880 if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI)
1882 if (ecmd->transceiver != XCVR_INTERNAL)
1885 if (ecmd->port == PORT_AUI)
1886 smc_set_xcvr(dev, 1);
1888 smc_set_xcvr(dev, 0);
1891 tmp = inw(ioaddr + TCR);
1892 if (ecmd->duplex == DUPLEX_FULL)
1896 outw(tmp, ioaddr + TCR);
1901 static int check_if_running(struct net_device *dev)
1903 if (!netif_running(dev))
1908 static void smc_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1910 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
1911 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
1914 static int smc_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
1916 struct smc_private *smc = netdev_priv(dev);
1917 unsigned int ioaddr = dev->base_addr;
1918 u16 saved_bank = inw(ioaddr + BANK_SELECT);
1920 unsigned long flags;
1922 spin_lock_irqsave(&smc->lock, flags);
1924 if (smc->cfg & CFG_MII_SELECT)
1925 ret = mii_ethtool_gset(&smc->mii_if, ecmd);
1927 ret = smc_netdev_get_ecmd(dev, ecmd);
1928 SMC_SELECT_BANK(saved_bank);
1929 spin_unlock_irqrestore(&smc->lock, flags);
1933 static int smc_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
1935 struct smc_private *smc = netdev_priv(dev);
1936 unsigned int ioaddr = dev->base_addr;
1937 u16 saved_bank = inw(ioaddr + BANK_SELECT);
1939 unsigned long flags;
1941 spin_lock_irqsave(&smc->lock, flags);
1943 if (smc->cfg & CFG_MII_SELECT)
1944 ret = mii_ethtool_sset(&smc->mii_if, ecmd);
1946 ret = smc_netdev_set_ecmd(dev, ecmd);
1947 SMC_SELECT_BANK(saved_bank);
1948 spin_unlock_irqrestore(&smc->lock, flags);
1952 static u32 smc_get_link(struct net_device *dev)
1954 struct smc_private *smc = netdev_priv(dev);
1955 unsigned int ioaddr = dev->base_addr;
1956 u16 saved_bank = inw(ioaddr + BANK_SELECT);
1958 unsigned long flags;
1960 spin_lock_irqsave(&smc->lock, flags);
1962 ret = smc_link_ok(dev);
1963 SMC_SELECT_BANK(saved_bank);
1964 spin_unlock_irqrestore(&smc->lock, flags);
1968 static int smc_nway_reset(struct net_device *dev)
1970 struct smc_private *smc = netdev_priv(dev);
1971 if (smc->cfg & CFG_MII_SELECT) {
1972 unsigned int ioaddr = dev->base_addr;
1973 u16 saved_bank = inw(ioaddr + BANK_SELECT);
1977 res = mii_nway_restart(&smc->mii_if);
1978 SMC_SELECT_BANK(saved_bank);
1985 static const struct ethtool_ops ethtool_ops = {
1986 .begin = check_if_running,
1987 .get_drvinfo = smc_get_drvinfo,
1988 .get_settings = smc_get_settings,
1989 .set_settings = smc_set_settings,
1990 .get_link = smc_get_link,
1991 .nway_reset = smc_nway_reset,
1994 static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
1996 struct smc_private *smc = netdev_priv(dev);
1997 struct mii_ioctl_data *mii = if_mii(rq);
2000 unsigned int ioaddr = dev->base_addr;
2001 unsigned long flags;
2003 if (!netif_running(dev))
2006 spin_lock_irqsave(&smc->lock, flags);
2007 saved_bank = inw(ioaddr + BANK_SELECT);
2009 rc = generic_mii_ioctl(&smc->mii_if, mii, cmd, NULL);
2010 SMC_SELECT_BANK(saved_bank);
2011 spin_unlock_irqrestore(&smc->lock, flags);
2015 static const struct pcmcia_device_id smc91c92_ids[] = {
2016 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0109, 0x0501),
2017 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0140, 0x000a),
2018 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63),
2019 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63),
2020 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef),
2021 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
2022 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
2023 PCMCIA_PFC_DEVICE_PROD_ID12(0, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
2024 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Diamonds Modem+Ethernet", 0xc2f80cd, 0x656947b9),
2025 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Hearts Modem+Ethernet", 0xc2f80cd, 0xdc9ba5ed),
2026 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x016c, 0x0020),
2027 PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0023),
2028 PCMCIA_DEVICE_PROD_ID123("BASICS by New Media Corporation", "Ethernet", "SMC91C94", 0x23c78a9d, 0x00b2e941, 0xcef397fb),
2029 PCMCIA_DEVICE_PROD_ID12("ARGOSY", "Fast Ethernet PCCard", 0x78f308dc, 0xdcea68bc),
2030 PCMCIA_DEVICE_PROD_ID12("dit Co., Ltd.", "PC Card-10/100BTX", 0xe59365c8, 0x6a2161d1),
2031 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L100C", 0x6a26d1cf, 0xc16ce9c5),
2032 PCMCIA_DEVICE_PROD_ID12("Farallon", "Farallon Enet", 0x58d93fc4, 0x244734e9),
2033 PCMCIA_DEVICE_PROD_ID12("Megahertz", "CC10BT/2", 0x33234748, 0x3c95b953),
2034 PCMCIA_DEVICE_PROD_ID12("MELCO/SMC", "LPC-TX", 0xa2cd8e6d, 0x42da662a),
2035 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Four of Diamonds Ethernet", 0xc2f80cd, 0xb3466314),
2036 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Seven of Diamonds Ethernet", 0xc2f80cd, 0x194b650a),
2037 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast Ethernet PCCard", 0x281f1c5d, 0xdcea68bc),
2038 PCMCIA_DEVICE_PROD_ID12("Psion", "10Mb Ethernet", 0x4ef00b21, 0x844be9e9),
2039 PCMCIA_DEVICE_PROD_ID12("SMC", "EtherEZ Ethernet 8020", 0xc4f8b18b, 0x4a0eeb2d),
2040 /* These conflict with other cards! */
2041 /* PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0100), */
2042 /* PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab), */
2045 MODULE_DEVICE_TABLE(pcmcia, smc91c92_ids);
2047 static struct pcmcia_driver smc91c92_cs_driver = {
2048 .owner = THIS_MODULE,
2049 .name = "smc91c92_cs",
2050 .probe = smc91c92_probe,
2051 .remove = smc91c92_detach,
2052 .id_table = smc91c92_ids,
2053 .suspend = smc91c92_suspend,
2054 .resume = smc91c92_resume,
2056 module_pcmcia_driver(smc91c92_cs_driver);