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 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/string.h>
33 #include <linux/timer.h>
34 #include <linux/interrupt.h>
35 #include <linux/delay.h>
36 #include <linux/crc32.h>
37 #include <linux/netdevice.h>
38 #include <linux/etherdevice.h>
39 #include <linux/skbuff.h>
40 #include <linux/if_arp.h>
41 #include <linux/ioport.h>
42 #include <linux/ethtool.h>
43 #include <linux/mii.h>
44 #include <linux/jiffies.h>
45 #include <linux/firmware.h>
47 #include <pcmcia/cs.h>
48 #include <pcmcia/cistpl.h>
49 #include <pcmcia/cisreg.h>
50 #include <pcmcia/ciscode.h>
51 #include <pcmcia/ds.h>
52 #include <pcmcia/ss.h>
55 #include <asm/system.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_multicast_list = 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 /*======================================================================
305 smc91c92_attach() creates an "instance" of the driver, allocating
306 local data structures for one device. The device is registered
309 ======================================================================*/
311 static int smc91c92_probe(struct pcmcia_device *link)
313 struct smc_private *smc;
314 struct net_device *dev;
316 dev_dbg(&link->dev, "smc91c92_attach()\n");
318 /* Create new ethernet device */
319 dev = alloc_etherdev(sizeof(struct smc_private));
322 smc = netdev_priv(dev);
326 spin_lock_init(&smc->lock);
327 link->resource[0]->end = 16;
328 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
329 link->conf.Attributes = CONF_ENABLE_IRQ;
330 link->conf.IntType = INT_MEMORY_AND_IO;
332 /* The SMC91c92-specific entries in the device structure. */
333 dev->netdev_ops = &smc_netdev_ops;
334 SET_ETHTOOL_OPS(dev, ðtool_ops);
335 dev->watchdog_timeo = TX_TIMEOUT;
337 smc->mii_if.dev = dev;
338 smc->mii_if.mdio_read = mdio_read;
339 smc->mii_if.mdio_write = mdio_write;
340 smc->mii_if.phy_id_mask = 0x1f;
341 smc->mii_if.reg_num_mask = 0x1f;
343 return smc91c92_config(link);
344 } /* smc91c92_attach */
346 /*======================================================================
348 This deletes a driver "instance". The device is de-registered
349 with Card Services. If it has been released, all local data
350 structures are freed. Otherwise, the structures will be freed
351 when the device is released.
353 ======================================================================*/
355 static void smc91c92_detach(struct pcmcia_device *link)
357 struct net_device *dev = link->priv;
359 dev_dbg(&link->dev, "smc91c92_detach\n");
361 unregister_netdev(dev);
363 smc91c92_release(link);
366 } /* smc91c92_detach */
368 /*====================================================================*/
370 static int cvt_ascii_address(struct net_device *dev, char *s)
376 for (i = 0; i < 6; i++) {
378 for (j = 0; j < 2; j++) {
381 da += ((c >= '0') && (c <= '9')) ?
382 (c - '0') : ((c & 0x0f) + 9);
384 dev->dev_addr[i] = da;
389 /*====================================================================
391 Configuration stuff for Megahertz cards
393 mhz_3288_power() is used to power up a 3288's ethernet chip.
394 mhz_mfc_config() handles socket setup for multifunction (1144
395 and 3288) cards. mhz_setup() gets a card's hardware ethernet
398 ======================================================================*/
400 static int mhz_3288_power(struct pcmcia_device *link)
402 struct net_device *dev = link->priv;
403 struct smc_private *smc = netdev_priv(dev);
406 /* Read the ISR twice... */
407 readb(smc->base+MEGAHERTZ_ISR);
409 readb(smc->base+MEGAHERTZ_ISR);
414 /* Now read and write the COR... */
415 tmp = readb(smc->base + link->conf.ConfigBase + CISREG_COR);
417 writeb(tmp, smc->base + link->conf.ConfigBase + CISREG_COR);
422 static int mhz_mfc_config_check(struct pcmcia_device *p_dev,
423 cistpl_cftable_entry_t *cf,
424 cistpl_cftable_entry_t *dflt,
429 p_dev->resource[1]->start = cf->io.win[0].base;
430 for (k = 0; k < 0x400; k += 0x10) {
433 p_dev->resource[0]->start = k ^ 0x300;
434 p_dev->io_lines = 16;
435 if (!pcmcia_request_io(p_dev))
441 static int mhz_mfc_config(struct pcmcia_device *link)
443 struct net_device *dev = link->priv;
444 struct smc_private *smc = netdev_priv(dev);
448 link->conf.Attributes |= CONF_ENABLE_SPKR;
449 link->conf.Status = CCSR_AUDIO_ENA;
450 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
451 link->resource[1]->end = 8;
453 /* The Megahertz combo cards have modem-like CIS entries, so
454 we have to explicitly try a bunch of port combinations. */
455 if (pcmcia_loop_config(link, mhz_mfc_config_check, NULL))
458 dev->base_addr = link->resource[0]->start;
460 /* Allocate a memory window, for accessing the ISR */
461 link->resource[2]->flags = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
462 link->resource[2]->start = link->resource[2]->end = 0;
463 i = pcmcia_request_window(link, link->resource[2], 0);
467 smc->base = ioremap(link->resource[2]->start,
468 resource_size(link->resource[2]));
469 offset = (smc->manfid == MANFID_MOTOROLA) ? link->conf.ConfigBase : 0;
470 i = pcmcia_map_mem_page(link, link->resource[2], offset);
472 (smc->manfid == MANFID_MEGAHERTZ) &&
473 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
474 mhz_3288_power(link);
479 static int pcmcia_get_versmac(struct pcmcia_device *p_dev,
483 struct net_device *dev = priv;
487 if (pcmcia_parse_tuple(tuple, &parse))
490 buf = parse.version_1.str + parse.version_1.ofs[3];
492 if ((parse.version_1.ns > 3) && (cvt_ascii_address(dev, buf) == 0))
498 static int mhz_setup(struct pcmcia_device *link)
500 struct net_device *dev = link->priv;
505 /* Read the station address from the CIS. It is stored as the last
506 (fourth) string in the Version 1 Version/ID tuple. */
507 if ((link->prod_id[3]) &&
508 (cvt_ascii_address(dev, link->prod_id[3]) == 0))
511 /* Workarounds for broken cards start here. */
512 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
513 if (!pcmcia_loop_tuple(link, CISTPL_VERS_1, pcmcia_get_versmac, dev))
516 /* Another possibility: for the EM3288, in a special tuple */
518 len = pcmcia_get_tuple(link, 0x81, &buf);
519 if (buf && len >= 13) {
521 if (cvt_ascii_address(dev, buf) == 0)
529 /*======================================================================
531 Configuration stuff for the Motorola Mariner
533 mot_config() writes directly to the Mariner configuration
534 registers because the CIS is just bogus.
536 ======================================================================*/
538 static void mot_config(struct pcmcia_device *link)
540 struct net_device *dev = link->priv;
541 struct smc_private *smc = netdev_priv(dev);
542 unsigned int ioaddr = dev->base_addr;
543 unsigned int iouart = link->resource[1]->start;
545 /* Set UART base address and force map with COR bit 1 */
546 writeb(iouart & 0xff, smc->base + MOT_UART + CISREG_IOBASE_0);
547 writeb((iouart >> 8) & 0xff, smc->base + MOT_UART + CISREG_IOBASE_1);
548 writeb(MOT_NORMAL, smc->base + MOT_UART + CISREG_COR);
550 /* Set SMC base address and force map with COR bit 1 */
551 writeb(ioaddr & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_0);
552 writeb((ioaddr >> 8) & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_1);
553 writeb(MOT_NORMAL, smc->base + MOT_LAN + CISREG_COR);
555 /* Wait for things to settle down */
559 static int mot_setup(struct pcmcia_device *link)
561 struct net_device *dev = link->priv;
562 unsigned int ioaddr = dev->base_addr;
566 /* Read Ethernet address from Serial EEPROM */
568 for (i = 0; i < 3; i++) {
570 outw(MOT_EEPROM + i, ioaddr + POINTER);
572 outw((CTL_RELOAD | CTL_EE_SELECT), ioaddr + CONTROL);
574 for (loop = wait = 0; loop < 200; loop++) {
576 wait = ((CTL_RELOAD | CTL_STORE) & inw(ioaddr + CONTROL));
577 if (wait == 0) break;
583 addr = inw(ioaddr + GENERAL);
584 dev->dev_addr[2*i] = addr & 0xff;
585 dev->dev_addr[2*i+1] = (addr >> 8) & 0xff;
591 /*====================================================================*/
593 static int smc_configcheck(struct pcmcia_device *p_dev,
594 cistpl_cftable_entry_t *cf,
595 cistpl_cftable_entry_t *dflt,
599 p_dev->resource[0]->start = cf->io.win[0].base;
600 p_dev->io_lines = cf->io.flags & CISTPL_IO_LINES_MASK;
601 return pcmcia_request_io(p_dev);
604 static int smc_config(struct pcmcia_device *link)
606 struct net_device *dev = link->priv;
609 link->resource[0]->end = 16;
610 i = pcmcia_loop_config(link, smc_configcheck, NULL);
612 dev->base_addr = link->resource[0]->start;
618 static int smc_setup(struct pcmcia_device *link)
620 struct net_device *dev = link->priv;
622 /* Check for a LAN function extension tuple */
623 if (!pcmcia_get_mac_from_cis(link, dev))
626 /* Try the third string in the Version 1 Version/ID tuple. */
627 if (link->prod_id[2]) {
628 if (cvt_ascii_address(dev, link->prod_id[2]) == 0)
634 /*====================================================================*/
636 static int osi_config(struct pcmcia_device *link)
638 struct net_device *dev = link->priv;
639 static const unsigned int com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
642 link->conf.Attributes |= CONF_ENABLE_SPKR;
643 link->conf.Status = CCSR_AUDIO_ENA;
644 link->resource[0]->end = 64;
645 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
646 link->resource[1]->end = 8;
648 /* Enable Hard Decode, LAN, Modem */
649 link->conf.ConfigIndex = 0x23;
652 for (i = j = 0; j < 4; j++) {
653 link->resource[1]->start = com[j];
654 i = pcmcia_request_io(link);
659 /* Fallback: turn off hard decode */
660 link->conf.ConfigIndex = 0x03;
661 link->resource[1]->end = 0;
662 i = pcmcia_request_io(link);
664 dev->base_addr = link->resource[0]->start + 0x10;
668 static int osi_load_firmware(struct pcmcia_device *link)
670 const struct firmware *fw;
673 err = request_firmware(&fw, FIRMWARE_NAME, &link->dev);
675 pr_err("Failed to load firmware \"%s\"\n", FIRMWARE_NAME);
679 /* Download the Seven of Diamonds firmware */
680 for (i = 0; i < fw->size; i++) {
681 outb(fw->data[i], link->resource[0]->start + 2);
684 release_firmware(fw);
688 static int pcmcia_osi_mac(struct pcmcia_device *p_dev,
692 struct net_device *dev = priv;
695 if (tuple->TupleDataLen < 8)
697 if (tuple->TupleData[0] != 0x04)
699 for (i = 0; i < 6; i++)
700 dev->dev_addr[i] = tuple->TupleData[i+2];
705 static int osi_setup(struct pcmcia_device *link, u_short manfid, u_short cardid)
707 struct net_device *dev = link->priv;
710 /* Read the station address from tuple 0x90, subtuple 0x04 */
711 if (pcmcia_loop_tuple(link, 0x90, pcmcia_osi_mac, dev))
714 if (((manfid == MANFID_OSITECH) &&
715 (cardid == PRODID_OSITECH_SEVEN)) ||
716 ((manfid == MANFID_PSION) &&
717 (cardid == PRODID_PSION_NET100))) {
718 rc = osi_load_firmware(link);
721 } else if (manfid == MANFID_OSITECH) {
722 /* Make sure both functions are powered up */
723 set_bits(0x300, link->resource[0]->start + OSITECH_AUI_PWR);
724 /* Now, turn on the interrupt for both card functions */
725 set_bits(0x300, link->resource[0]->start + OSITECH_RESET_ISR);
726 dev_dbg(&link->dev, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n",
727 inw(link->resource[0]->start + OSITECH_AUI_PWR),
728 inw(link->resource[0]->start + OSITECH_RESET_ISR));
733 static int smc91c92_suspend(struct pcmcia_device *link)
735 struct net_device *dev = link->priv;
738 netif_device_detach(dev);
743 static int smc91c92_resume(struct pcmcia_device *link)
745 struct net_device *dev = link->priv;
746 struct smc_private *smc = netdev_priv(dev);
749 if ((smc->manfid == MANFID_MEGAHERTZ) &&
750 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
751 mhz_3288_power(link);
752 if (smc->manfid == MANFID_MOTOROLA)
754 if ((smc->manfid == MANFID_OSITECH) &&
755 (smc->cardid != PRODID_OSITECH_SEVEN)) {
756 /* Power up the card and enable interrupts */
757 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR);
758 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR);
760 if (((smc->manfid == MANFID_OSITECH) &&
761 (smc->cardid == PRODID_OSITECH_SEVEN)) ||
762 ((smc->manfid == MANFID_PSION) &&
763 (smc->cardid == PRODID_PSION_NET100))) {
764 i = osi_load_firmware(link);
766 pr_err("smc91c92_cs: Failed to load firmware\n");
772 netif_device_attach(dev);
779 /*======================================================================
781 This verifies that the chip is some SMC91cXX variant, and returns
782 the revision code if successful. Otherwise, it returns -ENODEV.
784 ======================================================================*/
786 static int check_sig(struct pcmcia_device *link)
788 struct net_device *dev = link->priv;
789 unsigned int ioaddr = dev->base_addr;
794 if (inw(ioaddr + BANK_SELECT) >> 8 != 0x33) {
795 /* Try powering up the chip */
796 outw(0, ioaddr + CONTROL);
800 /* Try setting bus width */
801 width = (link->resource[0]->flags == IO_DATA_PATH_WIDTH_AUTO);
802 s = inb(ioaddr + CONFIG);
807 outb(s, ioaddr + CONFIG);
809 /* Check Base Address Register to make sure bus width is OK */
810 s = inw(ioaddr + BASE_ADDR);
811 if ((inw(ioaddr + BANK_SELECT) >> 8 == 0x33) &&
812 ((s >> 8) != (s & 0xff))) {
814 s = inw(ioaddr + REVISION);
820 .Attributes = CONF_IO_CHANGE_WIDTH,
822 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n");
824 smc91c92_suspend(link);
825 pcmcia_modify_configuration(link, &mod);
826 smc91c92_resume(link);
827 return check_sig(link);
832 /*======================================================================
834 smc91c92_config() is scheduled to run after a CARD_INSERTION event
835 is received, to configure the PCMCIA socket, and to make the
836 ethernet device available to the system.
838 ======================================================================*/
840 static int smc91c92_config(struct pcmcia_device *link)
842 struct net_device *dev = link->priv;
843 struct smc_private *smc = netdev_priv(dev);
849 dev_dbg(&link->dev, "smc91c92_config\n");
851 smc->manfid = link->manf_id;
852 smc->cardid = link->card_id;
854 if ((smc->manfid == MANFID_OSITECH) &&
855 (smc->cardid != PRODID_OSITECH_SEVEN)) {
856 i = osi_config(link);
857 } else if ((smc->manfid == MANFID_MOTOROLA) ||
858 ((smc->manfid == MANFID_MEGAHERTZ) &&
859 ((smc->cardid == PRODID_MEGAHERTZ_VARIOUS) ||
860 (smc->cardid == PRODID_MEGAHERTZ_EM3288)))) {
861 i = mhz_mfc_config(link);
863 i = smc_config(link);
868 i = pcmcia_request_irq(link, smc_interrupt);
871 i = pcmcia_request_configuration(link, &link->conf);
875 if (smc->manfid == MANFID_MOTOROLA)
878 dev->irq = link->irq;
880 if ((if_port >= 0) && (if_port <= 2))
881 dev->if_port = if_port;
883 printk(KERN_NOTICE "smc91c92_cs: invalid if_port requested\n");
885 switch (smc->manfid) {
888 i = osi_setup(link, smc->manfid, smc->cardid); break;
890 case MANFID_NEW_MEDIA:
891 i = smc_setup(link); break;
892 case 0x128: /* For broken Megahertz cards */
893 case MANFID_MEGAHERTZ:
894 i = mhz_setup(link); break;
895 case MANFID_MOTOROLA:
896 default: /* get the hw address from EEPROM */
897 i = mot_setup(link); break;
901 printk(KERN_NOTICE "smc91c92_cs: Unable to find hardware address.\n");
908 rev = check_sig(link);
912 case 3: name = "92"; break;
913 case 4: name = ((rev & 15) >= 6) ? "96" : "94"; break;
914 case 5: name = "95"; break;
915 case 7: name = "100"; break;
916 case 8: name = "100-FD"; break;
917 case 9: name = "110"; break;
920 ioaddr = dev->base_addr;
924 mir = inw(ioaddr + MEMINFO) & 0xff;
925 if (mir == 0xff) mir++;
926 /* Get scale factor for memory size */
927 mcr = ((rev >> 4) > 3) ? inw(ioaddr + MEMCFG) : 0x0200;
928 mir *= 128 * (1<<((mcr >> 9) & 7));
930 smc->cfg = inw(ioaddr + CONFIG) & ~CFG_AUI_SELECT;
931 smc->cfg |= CFG_NO_WAIT | CFG_16BIT | CFG_STATIC;
932 if (smc->manfid == MANFID_OSITECH)
933 smc->cfg |= CFG_IRQ_SEL_1 | CFG_IRQ_SEL_0;
935 smc->cfg |= CFG_MII_SELECT;
939 if (smc->cfg & CFG_MII_SELECT) {
942 for (i = 0; i < 32; i++) {
943 j = mdio_read(dev, i, 1);
944 if ((j != 0) && (j != 0xffff)) break;
946 smc->mii_if.phy_id = (i < 32) ? i : -1;
951 SET_NETDEV_DEV(dev, &link->dev);
953 if (register_netdev(dev) != 0) {
954 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n");
958 printk(KERN_INFO "%s: smc91c%s rev %d: io %#3lx, irq %d, "
960 dev->name, name, (rev & 0x0f), dev->base_addr, dev->irq,
965 printk(KERN_INFO " %lu byte", mir);
967 printk(KERN_INFO " %lu kb", mir>>10);
968 printk(" buffer, %s xcvr\n", (smc->cfg & CFG_MII_SELECT) ?
969 "MII" : if_names[dev->if_port]);
972 if (smc->cfg & CFG_MII_SELECT) {
973 if (smc->mii_if.phy_id != -1) {
974 dev_dbg(&link->dev, " MII transceiver at index %d, status %x.\n",
975 smc->mii_if.phy_id, j);
977 printk(KERN_NOTICE " No MII transceivers found!\n");
983 unregister_netdev(dev);
985 smc91c92_release(link);
988 } /* smc91c92_config */
990 /*======================================================================
992 After a card is removed, smc91c92_release() will unregister the net
993 device, and release the PCMCIA configuration. If the device is
994 still open, this will be postponed until it is closed.
996 ======================================================================*/
998 static void smc91c92_release(struct pcmcia_device *link)
1000 dev_dbg(&link->dev, "smc91c92_release\n");
1001 if (link->resource[2]->end) {
1002 struct net_device *dev = link->priv;
1003 struct smc_private *smc = netdev_priv(dev);
1006 pcmcia_disable_device(link);
1009 /*======================================================================
1011 MII interface support for SMC91cXX based cards
1012 ======================================================================*/
1014 #define MDIO_SHIFT_CLK 0x04
1015 #define MDIO_DATA_OUT 0x01
1016 #define MDIO_DIR_WRITE 0x08
1017 #define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
1018 #define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
1019 #define MDIO_DATA_READ 0x02
1021 static void mdio_sync(unsigned int addr)
1024 for (bits = 0; bits < 32; bits++) {
1025 outb(MDIO_DATA_WRITE1, addr);
1026 outb(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
1030 static int mdio_read(struct net_device *dev, int phy_id, int loc)
1032 unsigned int addr = dev->base_addr + MGMT;
1033 u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
1037 for (i = 13; i >= 0; i--) {
1038 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1040 outb(dat | MDIO_SHIFT_CLK, addr);
1042 for (i = 19; i > 0; i--) {
1044 retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
1045 outb(MDIO_SHIFT_CLK, addr);
1047 return (retval>>1) & 0xffff;
1050 static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
1052 unsigned int addr = dev->base_addr + MGMT;
1053 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
1057 for (i = 31; i >= 0; i--) {
1058 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1060 outb(dat | MDIO_SHIFT_CLK, addr);
1062 for (i = 1; i >= 0; i--) {
1064 outb(MDIO_SHIFT_CLK, addr);
1068 /*======================================================================
1070 The driver core code, most of which should be common with a
1071 non-PCMCIA implementation.
1073 ======================================================================*/
1076 static void smc_dump(struct net_device *dev)
1078 unsigned int ioaddr = dev->base_addr;
1080 save = inw(ioaddr + BANK_SELECT);
1081 for (w = 0; w < 4; w++) {
1083 printk(KERN_DEBUG "bank %d: ", w);
1084 for (i = 0; i < 14; i += 2)
1085 printk(" %04x", inw(ioaddr + i));
1088 outw(save, ioaddr + BANK_SELECT);
1092 static int smc_open(struct net_device *dev)
1094 struct smc_private *smc = netdev_priv(dev);
1095 struct pcmcia_device *link = smc->p_dev;
1097 dev_dbg(&link->dev, "%s: smc_open(%p), ID/Window %4.4x.\n",
1098 dev->name, dev, inw(dev->base_addr + BANK_SELECT));
1103 /* Check that the PCMCIA card is still here. */
1104 if (!pcmcia_dev_present(link))
1106 /* Physical device present signature. */
1107 if (check_sig(link) < 0) {
1108 printk("smc91c92_cs: Yikes! Bad chip signature!\n");
1113 netif_start_queue(dev);
1114 smc->saved_skb = NULL;
1115 smc->packets_waiting = 0;
1118 init_timer(&smc->media);
1119 smc->media.function = &media_check;
1120 smc->media.data = (u_long) dev;
1121 smc->media.expires = jiffies + HZ;
1122 add_timer(&smc->media);
1127 /*====================================================================*/
1129 static int smc_close(struct net_device *dev)
1131 struct smc_private *smc = netdev_priv(dev);
1132 struct pcmcia_device *link = smc->p_dev;
1133 unsigned int ioaddr = dev->base_addr;
1135 dev_dbg(&link->dev, "%s: smc_close(), status %4.4x.\n",
1136 dev->name, inw(ioaddr + BANK_SELECT));
1138 netif_stop_queue(dev);
1140 /* Shut off all interrupts, and turn off the Tx and Rx sections.
1141 Don't bother to check for chip present. */
1142 SMC_SELECT_BANK(2); /* Nominally paranoia, but do no assume... */
1143 outw(0, ioaddr + INTERRUPT);
1145 mask_bits(0xff00, ioaddr + RCR);
1146 mask_bits(0xff00, ioaddr + TCR);
1148 /* Put the chip into power-down mode. */
1150 outw(CTL_POWERDOWN, ioaddr + CONTROL );
1153 del_timer_sync(&smc->media);
1158 /*======================================================================
1160 Transfer a packet to the hardware and trigger the packet send.
1161 This may be called at either from either the Tx queue code
1162 or the interrupt handler.
1164 ======================================================================*/
1166 static void smc_hardware_send_packet(struct net_device * dev)
1168 struct smc_private *smc = netdev_priv(dev);
1169 struct sk_buff *skb = smc->saved_skb;
1170 unsigned int ioaddr = dev->base_addr;
1174 printk(KERN_ERR "%s: In XMIT with no packet to send.\n", dev->name);
1178 /* There should be a packet slot waiting. */
1179 packet_no = inw(ioaddr + PNR_ARR) >> 8;
1180 if (packet_no & 0x80) {
1181 /* If not, there is a hardware problem! Likely an ejected card. */
1182 printk(KERN_WARNING "%s: 91c92 hardware Tx buffer allocation"
1183 " failed, status %#2.2x.\n", dev->name, packet_no);
1184 dev_kfree_skb_irq(skb);
1185 smc->saved_skb = NULL;
1186 netif_start_queue(dev);
1190 dev->stats.tx_bytes += skb->len;
1191 /* The card should use the just-allocated buffer. */
1192 outw(packet_no, ioaddr + PNR_ARR);
1193 /* point to the beginning of the packet */
1194 outw(PTR_AUTOINC , ioaddr + POINTER);
1196 /* Send the packet length (+6 for status, length and ctl byte)
1197 and the status word (set to zeros). */
1199 u_char *buf = skb->data;
1200 u_int length = skb->len; /* The chip will pad to ethernet min. */
1202 pr_debug("%s: Trying to xmit packet of length %d.\n",
1205 /* send the packet length: +6 for status word, length, and ctl */
1206 outw(0, ioaddr + DATA_1);
1207 outw(length + 6, ioaddr + DATA_1);
1208 outsw(ioaddr + DATA_1, buf, length >> 1);
1210 /* The odd last byte, if there is one, goes in the control word. */
1211 outw((length & 1) ? 0x2000 | buf[length-1] : 0, ioaddr + DATA_1);
1214 /* Enable the Tx interrupts, both Tx (TxErr) and TxEmpty. */
1215 outw(((IM_TX_INT|IM_TX_EMPTY_INT)<<8) |
1216 (inw(ioaddr + INTERRUPT) & 0xff00),
1217 ioaddr + INTERRUPT);
1219 /* The chip does the rest of the work. */
1220 outw(MC_ENQUEUE , ioaddr + MMU_CMD);
1222 smc->saved_skb = NULL;
1223 dev_kfree_skb_irq(skb);
1224 dev->trans_start = jiffies;
1225 netif_start_queue(dev);
1228 /*====================================================================*/
1230 static void smc_tx_timeout(struct net_device *dev)
1232 struct smc_private *smc = netdev_priv(dev);
1233 unsigned int ioaddr = dev->base_addr;
1235 printk(KERN_NOTICE "%s: SMC91c92 transmit timed out, "
1236 "Tx_status %2.2x status %4.4x.\n",
1237 dev->name, inw(ioaddr)&0xff, inw(ioaddr + 2));
1238 dev->stats.tx_errors++;
1240 dev->trans_start = jiffies; /* prevent tx timeout */
1241 smc->saved_skb = NULL;
1242 netif_wake_queue(dev);
1245 static netdev_tx_t smc_start_xmit(struct sk_buff *skb,
1246 struct net_device *dev)
1248 struct smc_private *smc = netdev_priv(dev);
1249 unsigned int ioaddr = dev->base_addr;
1252 unsigned long flags;
1254 netif_stop_queue(dev);
1256 pr_debug("%s: smc_start_xmit(length = %d) called,"
1257 " status %4.4x.\n", dev->name, skb->len, inw(ioaddr + 2));
1259 if (smc->saved_skb) {
1260 /* THIS SHOULD NEVER HAPPEN. */
1261 dev->stats.tx_aborted_errors++;
1262 printk(KERN_DEBUG "%s: Internal error -- sent packet while busy.\n",
1264 return NETDEV_TX_BUSY;
1266 smc->saved_skb = skb;
1268 num_pages = skb->len >> 8;
1270 if (num_pages > 7) {
1271 printk(KERN_ERR "%s: Far too big packet error.\n", dev->name);
1272 dev_kfree_skb (skb);
1273 smc->saved_skb = NULL;
1274 dev->stats.tx_dropped++;
1275 return NETDEV_TX_OK; /* Do not re-queue this packet. */
1277 /* A packet is now waiting. */
1278 smc->packets_waiting++;
1280 spin_lock_irqsave(&smc->lock, flags);
1281 SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */
1283 /* need MC_RESET to keep the memory consistent. errata? */
1285 outw(MC_RESET, ioaddr + MMU_CMD);
1289 /* Allocate the memory; send the packet now if we win. */
1290 outw(MC_ALLOC | num_pages, ioaddr + MMU_CMD);
1291 for (time_out = MEMORY_WAIT_TIME; time_out >= 0; time_out--) {
1292 ir = inw(ioaddr+INTERRUPT);
1293 if (ir & IM_ALLOC_INT) {
1294 /* Acknowledge the interrupt, send the packet. */
1295 outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT);
1296 smc_hardware_send_packet(dev); /* Send the packet now.. */
1297 spin_unlock_irqrestore(&smc->lock, flags);
1298 return NETDEV_TX_OK;
1302 /* Otherwise defer until the Tx-space-allocated interrupt. */
1303 pr_debug("%s: memory allocation deferred.\n", dev->name);
1304 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT);
1305 spin_unlock_irqrestore(&smc->lock, flags);
1307 return NETDEV_TX_OK;
1310 /*======================================================================
1312 Handle a Tx anomolous event. Entered while in Window 2.
1314 ======================================================================*/
1316 static void smc_tx_err(struct net_device * dev)
1318 struct smc_private *smc = netdev_priv(dev);
1319 unsigned int ioaddr = dev->base_addr;
1320 int saved_packet = inw(ioaddr + PNR_ARR) & 0xff;
1321 int packet_no = inw(ioaddr + FIFO_PORTS) & 0x7f;
1324 /* select this as the packet to read from */
1325 outw(packet_no, ioaddr + PNR_ARR);
1327 /* read the first word from this packet */
1328 outw(PTR_AUTOINC | PTR_READ | 0, ioaddr + POINTER);
1330 tx_status = inw(ioaddr + DATA_1);
1332 dev->stats.tx_errors++;
1333 if (tx_status & TS_LOSTCAR) dev->stats.tx_carrier_errors++;
1334 if (tx_status & TS_LATCOL) dev->stats.tx_window_errors++;
1335 if (tx_status & TS_16COL) {
1336 dev->stats.tx_aborted_errors++;
1340 if (tx_status & TS_SUCCESS) {
1341 printk(KERN_NOTICE "%s: Successful packet caused error "
1342 "interrupt?\n", dev->name);
1344 /* re-enable transmit */
1346 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1349 outw(MC_FREEPKT, ioaddr + MMU_CMD); /* Free the packet memory. */
1351 /* one less packet waiting for me */
1352 smc->packets_waiting--;
1354 outw(saved_packet, ioaddr + PNR_ARR);
1357 /*====================================================================*/
1359 static void smc_eph_irq(struct net_device *dev)
1361 struct smc_private *smc = netdev_priv(dev);
1362 unsigned int ioaddr = dev->base_addr;
1363 u_short card_stats, ephs;
1366 ephs = inw(ioaddr + EPH);
1367 pr_debug("%s: Ethernet protocol handler interrupt, status"
1368 " %4.4x.\n", dev->name, ephs);
1369 /* Could be a counter roll-over warning: update stats. */
1370 card_stats = inw(ioaddr + COUNTER);
1371 /* single collisions */
1372 dev->stats.collisions += card_stats & 0xF;
1374 /* multiple collisions */
1375 dev->stats.collisions += card_stats & 0xF;
1376 #if 0 /* These are for when linux supports these statistics */
1377 card_stats >>= 4; /* deferred */
1378 card_stats >>= 4; /* excess deferred */
1380 /* If we had a transmit error we must re-enable the transmitter. */
1381 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1383 /* Clear a link error interrupt. */
1385 outw(CTL_AUTO_RELEASE | 0x0000, ioaddr + CONTROL);
1386 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1391 /*====================================================================*/
1393 static irqreturn_t smc_interrupt(int irq, void *dev_id)
1395 struct net_device *dev = dev_id;
1396 struct smc_private *smc = netdev_priv(dev);
1397 unsigned int ioaddr;
1398 u_short saved_bank, saved_pointer, mask, status;
1399 unsigned int handled = 1;
1400 char bogus_cnt = INTR_WORK; /* Work we are willing to do. */
1402 if (!netif_device_present(dev))
1405 ioaddr = dev->base_addr;
1407 pr_debug("%s: SMC91c92 interrupt %d at %#x.\n", dev->name,
1410 spin_lock(&smc->lock);
1412 saved_bank = inw(ioaddr + BANK_SELECT);
1413 if ((saved_bank & 0xff00) != 0x3300) {
1414 /* The device does not exist -- the card could be off-line, or
1415 maybe it has been ejected. */
1416 pr_debug("%s: SMC91c92 interrupt %d for non-existent"
1417 "/ejected device.\n", dev->name, irq);
1423 saved_pointer = inw(ioaddr + POINTER);
1424 mask = inw(ioaddr + INTERRUPT) >> 8;
1425 /* clear all interrupts */
1426 outw(0, ioaddr + INTERRUPT);
1428 do { /* read the status flag, and mask it */
1429 status = inw(ioaddr + INTERRUPT) & 0xff;
1430 pr_debug("%s: Status is %#2.2x (mask %#2.2x).\n", dev->name,
1432 if ((status & mask) == 0) {
1433 if (bogus_cnt == INTR_WORK)
1437 if (status & IM_RCV_INT) {
1438 /* Got a packet(s). */
1441 if (status & IM_TX_INT) {
1443 outw(IM_TX_INT, ioaddr + INTERRUPT);
1446 if (status & IM_TX_EMPTY_INT) {
1447 outw(IM_TX_EMPTY_INT, ioaddr + INTERRUPT);
1448 mask &= ~IM_TX_EMPTY_INT;
1449 dev->stats.tx_packets += smc->packets_waiting;
1450 smc->packets_waiting = 0;
1452 if (status & IM_ALLOC_INT) {
1453 /* Clear this interrupt so it doesn't happen again */
1454 mask &= ~IM_ALLOC_INT;
1456 smc_hardware_send_packet(dev);
1458 /* enable xmit interrupts based on this */
1459 mask |= (IM_TX_EMPTY_INT | IM_TX_INT);
1461 /* and let the card send more packets to me */
1462 netif_wake_queue(dev);
1464 if (status & IM_RX_OVRN_INT) {
1465 dev->stats.rx_errors++;
1466 dev->stats.rx_fifo_errors++;
1468 smc->rx_ovrn = 1; /* need MC_RESET outside smc_interrupt */
1469 outw(IM_RX_OVRN_INT, ioaddr + INTERRUPT);
1471 if (status & IM_EPH_INT)
1473 } while (--bogus_cnt);
1475 pr_debug(" Restoring saved registers mask %2.2x bank %4.4x"
1476 " pointer %4.4x.\n", mask, saved_bank, saved_pointer);
1478 /* restore state register */
1479 outw((mask<<8), ioaddr + INTERRUPT);
1480 outw(saved_pointer, ioaddr + POINTER);
1481 SMC_SELECT_BANK(saved_bank);
1483 pr_debug("%s: Exiting interrupt IRQ%d.\n", dev->name, irq);
1487 if ((smc->manfid == MANFID_OSITECH) &&
1488 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1489 /* Retrigger interrupt if needed */
1490 mask_bits(0x00ff, ioaddr-0x10+OSITECH_RESET_ISR);
1491 set_bits(0x0300, ioaddr-0x10+OSITECH_RESET_ISR);
1493 if (smc->manfid == MANFID_MOTOROLA) {
1495 cor = readb(smc->base + MOT_UART + CISREG_COR);
1496 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_UART + CISREG_COR);
1497 writeb(cor, smc->base + MOT_UART + CISREG_COR);
1498 cor = readb(smc->base + MOT_LAN + CISREG_COR);
1499 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_LAN + CISREG_COR);
1500 writeb(cor, smc->base + MOT_LAN + CISREG_COR);
1503 if ((smc->base != NULL) && /* Megahertz MFC's */
1504 (smc->manfid == MANFID_MEGAHERTZ) &&
1505 (smc->cardid == PRODID_MEGAHERTZ_EM3288)) {
1508 tmp = readb(smc->base+MEGAHERTZ_ISR);
1509 tmp = readb(smc->base+MEGAHERTZ_ISR);
1511 /* Retrigger interrupt if needed */
1512 writeb(tmp, smc->base + MEGAHERTZ_ISR);
1513 writeb(tmp, smc->base + MEGAHERTZ_ISR);
1516 spin_unlock(&smc->lock);
1517 return IRQ_RETVAL(handled);
1520 /*====================================================================*/
1522 static void smc_rx(struct net_device *dev)
1524 unsigned int ioaddr = dev->base_addr;
1526 int packet_length; /* Caution: not frame length, rather words
1527 to transfer from the chip. */
1529 /* Assertion: we are in Window 2. */
1531 if (inw(ioaddr + FIFO_PORTS) & FP_RXEMPTY) {
1532 printk(KERN_ERR "%s: smc_rx() with nothing on Rx FIFO.\n",
1537 /* Reset the read pointer, and read the status and packet length. */
1538 outw(PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER);
1539 rx_status = inw(ioaddr + DATA_1);
1540 packet_length = inw(ioaddr + DATA_1) & 0x07ff;
1542 pr_debug("%s: Receive status %4.4x length %d.\n",
1543 dev->name, rx_status, packet_length);
1545 if (!(rx_status & RS_ERRORS)) {
1546 /* do stuff to make a new packet */
1547 struct sk_buff *skb;
1549 /* Note: packet_length adds 5 or 6 extra bytes here! */
1550 skb = dev_alloc_skb(packet_length+2);
1553 pr_debug("%s: Low memory, packet dropped.\n", dev->name);
1554 dev->stats.rx_dropped++;
1555 outw(MC_RELEASE, ioaddr + MMU_CMD);
1559 packet_length -= (rx_status & RS_ODDFRAME ? 5 : 6);
1560 skb_reserve(skb, 2);
1561 insw(ioaddr+DATA_1, skb_put(skb, packet_length),
1562 (packet_length+1)>>1);
1563 skb->protocol = eth_type_trans(skb, dev);
1566 dev->last_rx = jiffies;
1567 dev->stats.rx_packets++;
1568 dev->stats.rx_bytes += packet_length;
1569 if (rx_status & RS_MULTICAST)
1570 dev->stats.multicast++;
1573 dev->stats.rx_errors++;
1575 if (rx_status & RS_ALGNERR) dev->stats.rx_frame_errors++;
1576 if (rx_status & (RS_TOOSHORT | RS_TOOLONG))
1577 dev->stats.rx_length_errors++;
1578 if (rx_status & RS_BADCRC) dev->stats.rx_crc_errors++;
1580 /* Let the MMU free the memory of this packet. */
1581 outw(MC_RELEASE, ioaddr + MMU_CMD);
1584 /*======================================================================
1586 Set the receive mode.
1588 This routine is used by both the protocol level to notify us of
1589 promiscuous/multicast mode changes, and by the open/reset code to
1590 initialize the Rx registers. We always set the multicast list and
1591 leave the receiver running.
1593 ======================================================================*/
1595 static void set_rx_mode(struct net_device *dev)
1597 unsigned int ioaddr = dev->base_addr;
1598 struct smc_private *smc = netdev_priv(dev);
1599 unsigned char multicast_table[8];
1600 unsigned long flags;
1601 u_short rx_cfg_setting;
1604 memset(multicast_table, 0, sizeof(multicast_table));
1606 if (dev->flags & IFF_PROMISC) {
1607 rx_cfg_setting = RxStripCRC | RxEnable | RxPromisc | RxAllMulti;
1608 } else if (dev->flags & IFF_ALLMULTI)
1609 rx_cfg_setting = RxStripCRC | RxEnable | RxAllMulti;
1611 if (!netdev_mc_empty(dev)) {
1612 struct netdev_hw_addr *ha;
1614 netdev_for_each_mc_addr(ha, dev) {
1615 u_int position = ether_crc(6, ha->addr);
1616 multicast_table[position >> 29] |= 1 << ((position >> 26) & 7);
1619 rx_cfg_setting = RxStripCRC | RxEnable;
1622 /* Load MC table and Rx setting into the chip without interrupts. */
1623 spin_lock_irqsave(&smc->lock, flags);
1625 for (i = 0; i < 8; i++)
1626 outb(multicast_table[i], ioaddr + MULTICAST0 + i);
1628 outw(rx_cfg_setting, ioaddr + RCR);
1630 spin_unlock_irqrestore(&smc->lock, flags);
1633 /*======================================================================
1635 Senses when a card's config changes. Here, it's coax or TP.
1637 ======================================================================*/
1639 static int s9k_config(struct net_device *dev, struct ifmap *map)
1641 struct smc_private *smc = netdev_priv(dev);
1642 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
1643 if (smc->cfg & CFG_MII_SELECT)
1645 else if (map->port > 2)
1647 dev->if_port = map->port;
1648 printk(KERN_INFO "%s: switched to %s port\n",
1649 dev->name, if_names[dev->if_port]);
1655 /*======================================================================
1657 Reset the chip, reloading every register that might be corrupted.
1659 ======================================================================*/
1662 Set transceiver type, perhaps to something other than what the user
1663 specified in dev->if_port.
1665 static void smc_set_xcvr(struct net_device *dev, int if_port)
1667 struct smc_private *smc = netdev_priv(dev);
1668 unsigned int ioaddr = dev->base_addr;
1671 saved_bank = inw(ioaddr + BANK_SELECT);
1674 outw(smc->cfg | CFG_AUI_SELECT, ioaddr + CONFIG);
1675 if ((smc->manfid == MANFID_OSITECH) &&
1676 (smc->cardid != PRODID_OSITECH_SEVEN))
1677 set_bits(OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1678 smc->media_status = ((dev->if_port == 0) ? 0x0001 : 0x0002);
1680 outw(smc->cfg, ioaddr + CONFIG);
1681 if ((smc->manfid == MANFID_OSITECH) &&
1682 (smc->cardid != PRODID_OSITECH_SEVEN))
1683 mask_bits(~OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1684 smc->media_status = ((dev->if_port == 0) ? 0x0012 : 0x4001);
1686 SMC_SELECT_BANK(saved_bank);
1689 static void smc_reset(struct net_device *dev)
1691 unsigned int ioaddr = dev->base_addr;
1692 struct smc_private *smc = netdev_priv(dev);
1695 pr_debug("%s: smc91c92 reset called.\n", dev->name);
1697 /* The first interaction must be a write to bring the chip out
1700 /* Reset the chip. */
1701 outw(RCR_SOFTRESET, ioaddr + RCR);
1704 /* Clear the transmit and receive configuration registers. */
1705 outw(RCR_CLEAR, ioaddr + RCR);
1706 outw(TCR_CLEAR, ioaddr + TCR);
1708 /* Set the Window 1 control, configuration and station addr registers.
1709 No point in writing the I/O base register ;-> */
1711 /* Automatically release successfully transmitted packets,
1712 Accept link errors, counter and Tx error interrupts. */
1713 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1715 smc_set_xcvr(dev, dev->if_port);
1716 if ((smc->manfid == MANFID_OSITECH) &&
1717 (smc->cardid != PRODID_OSITECH_SEVEN))
1718 outw((dev->if_port == 2 ? OSI_AUI_PWR : 0) |
1719 (inw(ioaddr-0x10+OSITECH_AUI_PWR) & 0xff00),
1720 ioaddr - 0x10 + OSITECH_AUI_PWR);
1722 /* Fill in the physical address. The databook is wrong about the order! */
1723 for (i = 0; i < 6; i += 2)
1724 outw((dev->dev_addr[i+1]<<8)+dev->dev_addr[i],
1725 ioaddr + ADDR0 + i);
1729 outw(MC_RESET, ioaddr + MMU_CMD);
1730 outw(0, ioaddr + INTERRUPT);
1732 /* Re-enable the chip. */
1734 outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) |
1735 TCR_ENABLE | TCR_PAD_EN | smc->duplex, ioaddr + TCR);
1738 if (smc->cfg & CFG_MII_SELECT) {
1742 mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000);
1744 /* Advertise 100F, 100H, 10F, 10H */
1745 mdio_write(dev, smc->mii_if.phy_id, 4, 0x01e1);
1747 /* Restart MII autonegotiation */
1748 mdio_write(dev, smc->mii_if.phy_id, 0, 0x0000);
1749 mdio_write(dev, smc->mii_if.phy_id, 0, 0x1200);
1752 /* Enable interrupts. */
1754 outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,
1755 ioaddr + INTERRUPT);
1758 /*======================================================================
1760 Media selection timer routine
1762 ======================================================================*/
1764 static void media_check(u_long arg)
1766 struct net_device *dev = (struct net_device *) arg;
1767 struct smc_private *smc = netdev_priv(dev);
1768 unsigned int ioaddr = dev->base_addr;
1769 u_short i, media, saved_bank;
1771 unsigned long flags;
1773 spin_lock_irqsave(&smc->lock, flags);
1775 saved_bank = inw(ioaddr + BANK_SELECT);
1777 if (!netif_device_present(dev))
1782 /* need MC_RESET to keep the memory consistent. errata? */
1784 outw(MC_RESET, ioaddr + MMU_CMD);
1787 i = inw(ioaddr + INTERRUPT);
1789 media = inw(ioaddr + EPH) & EPH_LINK_OK;
1791 media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1;
1793 SMC_SELECT_BANK(saved_bank);
1794 spin_unlock_irqrestore(&smc->lock, flags);
1796 /* Check for pending interrupt with watchdog flag set: with
1797 this, we can limp along even if the interrupt is blocked */
1798 if (smc->watchdog++ && ((i>>8) & i)) {
1799 if (!smc->fast_poll)
1800 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
1801 local_irq_save(flags);
1802 smc_interrupt(dev->irq, dev);
1803 local_irq_restore(flags);
1804 smc->fast_poll = HZ;
1806 if (smc->fast_poll) {
1808 smc->media.expires = jiffies + HZ/100;
1809 add_timer(&smc->media);
1813 spin_lock_irqsave(&smc->lock, flags);
1815 saved_bank = inw(ioaddr + BANK_SELECT);
1817 if (smc->cfg & CFG_MII_SELECT) {
1818 if (smc->mii_if.phy_id < 0)
1822 link = mdio_read(dev, smc->mii_if.phy_id, 1);
1823 if (!link || (link == 0xffff)) {
1824 printk(KERN_INFO "%s: MII is missing!\n", dev->name);
1825 smc->mii_if.phy_id = -1;
1830 if (link != smc->link_status) {
1831 u_short p = mdio_read(dev, smc->mii_if.phy_id, 5);
1832 printk(KERN_INFO "%s: %s link beat\n", dev->name,
1833 (link) ? "found" : "lost");
1834 smc->duplex = (((p & 0x0100) || ((p & 0x1c0) == 0x40))
1837 printk(KERN_INFO "%s: autonegotiation complete: "
1838 "%sbaseT-%cD selected\n", dev->name,
1839 ((p & 0x0180) ? "100" : "10"),
1840 (smc->duplex ? 'F' : 'H'));
1843 outw(inw(ioaddr + TCR) | smc->duplex, ioaddr + TCR);
1844 smc->link_status = link;
1849 /* Ignore collisions unless we've had no rx's recently */
1850 if (time_after(jiffies, dev->last_rx + HZ)) {
1851 if (smc->tx_err || (smc->media_status & EPH_16COL))
1856 if (media != smc->media_status) {
1857 if ((media & smc->media_status & 1) &&
1858 ((smc->media_status ^ media) & EPH_LINK_OK))
1859 printk(KERN_INFO "%s: %s link beat\n", dev->name,
1860 (smc->media_status & EPH_LINK_OK ? "lost" : "found"));
1861 else if ((media & smc->media_status & 2) &&
1862 ((smc->media_status ^ media) & EPH_16COL))
1863 printk(KERN_INFO "%s: coax cable %s\n", dev->name,
1864 (media & EPH_16COL ? "problem" : "ok"));
1865 if (dev->if_port == 0) {
1867 if (media & EPH_LINK_OK)
1868 printk(KERN_INFO "%s: flipped to 10baseT\n",
1871 smc_set_xcvr(dev, 2);
1873 if (media & EPH_16COL)
1874 smc_set_xcvr(dev, 1);
1876 printk(KERN_INFO "%s: flipped to 10base2\n",
1880 smc->media_status = media;
1884 smc->media.expires = jiffies + HZ;
1885 add_timer(&smc->media);
1886 SMC_SELECT_BANK(saved_bank);
1887 spin_unlock_irqrestore(&smc->lock, flags);
1890 static int smc_link_ok(struct net_device *dev)
1892 unsigned int ioaddr = dev->base_addr;
1893 struct smc_private *smc = netdev_priv(dev);
1895 if (smc->cfg & CFG_MII_SELECT) {
1896 return mii_link_ok(&smc->mii_if);
1899 return inw(ioaddr + EPH) & EPH_LINK_OK;
1903 static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
1906 unsigned int ioaddr = dev->base_addr;
1908 ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |
1909 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);
1912 tmp = inw(ioaddr + CONFIG);
1913 ecmd->port = (tmp & CFG_AUI_SELECT) ? PORT_AUI : PORT_TP;
1914 ecmd->transceiver = XCVR_INTERNAL;
1915 ecmd->speed = SPEED_10;
1916 ecmd->phy_address = ioaddr + MGMT;
1919 tmp = inw(ioaddr + TCR);
1920 ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF;
1925 static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
1928 unsigned int ioaddr = dev->base_addr;
1930 if (ecmd->speed != SPEED_10)
1932 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
1934 if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI)
1936 if (ecmd->transceiver != XCVR_INTERNAL)
1939 if (ecmd->port == PORT_AUI)
1940 smc_set_xcvr(dev, 1);
1942 smc_set_xcvr(dev, 0);
1945 tmp = inw(ioaddr + TCR);
1946 if (ecmd->duplex == DUPLEX_FULL)
1950 outw(tmp, ioaddr + TCR);
1955 static int check_if_running(struct net_device *dev)
1957 if (!netif_running(dev))
1962 static void smc_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1964 strcpy(info->driver, DRV_NAME);
1965 strcpy(info->version, DRV_VERSION);
1968 static int smc_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
1970 struct smc_private *smc = netdev_priv(dev);
1971 unsigned int ioaddr = dev->base_addr;
1972 u16 saved_bank = inw(ioaddr + BANK_SELECT);
1974 unsigned long flags;
1976 spin_lock_irqsave(&smc->lock, flags);
1978 if (smc->cfg & CFG_MII_SELECT)
1979 ret = mii_ethtool_gset(&smc->mii_if, ecmd);
1981 ret = smc_netdev_get_ecmd(dev, ecmd);
1982 SMC_SELECT_BANK(saved_bank);
1983 spin_unlock_irqrestore(&smc->lock, flags);
1987 static int smc_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
1989 struct smc_private *smc = netdev_priv(dev);
1990 unsigned int ioaddr = dev->base_addr;
1991 u16 saved_bank = inw(ioaddr + BANK_SELECT);
1993 unsigned long flags;
1995 spin_lock_irqsave(&smc->lock, flags);
1997 if (smc->cfg & CFG_MII_SELECT)
1998 ret = mii_ethtool_sset(&smc->mii_if, ecmd);
2000 ret = smc_netdev_set_ecmd(dev, ecmd);
2001 SMC_SELECT_BANK(saved_bank);
2002 spin_unlock_irqrestore(&smc->lock, flags);
2006 static u32 smc_get_link(struct net_device *dev)
2008 struct smc_private *smc = netdev_priv(dev);
2009 unsigned int ioaddr = dev->base_addr;
2010 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2012 unsigned long flags;
2014 spin_lock_irqsave(&smc->lock, flags);
2016 ret = smc_link_ok(dev);
2017 SMC_SELECT_BANK(saved_bank);
2018 spin_unlock_irqrestore(&smc->lock, flags);
2022 static int smc_nway_reset(struct net_device *dev)
2024 struct smc_private *smc = netdev_priv(dev);
2025 if (smc->cfg & CFG_MII_SELECT) {
2026 unsigned int ioaddr = dev->base_addr;
2027 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2031 res = mii_nway_restart(&smc->mii_if);
2032 SMC_SELECT_BANK(saved_bank);
2039 static const struct ethtool_ops ethtool_ops = {
2040 .begin = check_if_running,
2041 .get_drvinfo = smc_get_drvinfo,
2042 .get_settings = smc_get_settings,
2043 .set_settings = smc_set_settings,
2044 .get_link = smc_get_link,
2045 .nway_reset = smc_nway_reset,
2048 static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
2050 struct smc_private *smc = netdev_priv(dev);
2051 struct mii_ioctl_data *mii = if_mii(rq);
2054 unsigned int ioaddr = dev->base_addr;
2055 unsigned long flags;
2057 if (!netif_running(dev))
2060 spin_lock_irqsave(&smc->lock, flags);
2061 saved_bank = inw(ioaddr + BANK_SELECT);
2063 rc = generic_mii_ioctl(&smc->mii_if, mii, cmd, NULL);
2064 SMC_SELECT_BANK(saved_bank);
2065 spin_unlock_irqrestore(&smc->lock, flags);
2069 static struct pcmcia_device_id smc91c92_ids[] = {
2070 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0109, 0x0501),
2071 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0140, 0x000a),
2072 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63),
2073 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63),
2074 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef),
2075 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
2076 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
2077 PCMCIA_PFC_DEVICE_PROD_ID12(0, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
2078 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Diamonds Modem+Ethernet", 0xc2f80cd, 0x656947b9),
2079 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Hearts Modem+Ethernet", 0xc2f80cd, 0xdc9ba5ed),
2080 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x016c, 0x0020),
2081 PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0023),
2082 PCMCIA_DEVICE_PROD_ID123("BASICS by New Media Corporation", "Ethernet", "SMC91C94", 0x23c78a9d, 0x00b2e941, 0xcef397fb),
2083 PCMCIA_DEVICE_PROD_ID12("ARGOSY", "Fast Ethernet PCCard", 0x78f308dc, 0xdcea68bc),
2084 PCMCIA_DEVICE_PROD_ID12("dit Co., Ltd.", "PC Card-10/100BTX", 0xe59365c8, 0x6a2161d1),
2085 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L100C", 0x6a26d1cf, 0xc16ce9c5),
2086 PCMCIA_DEVICE_PROD_ID12("Farallon", "Farallon Enet", 0x58d93fc4, 0x244734e9),
2087 PCMCIA_DEVICE_PROD_ID12("Megahertz", "CC10BT/2", 0x33234748, 0x3c95b953),
2088 PCMCIA_DEVICE_PROD_ID12("MELCO/SMC", "LPC-TX", 0xa2cd8e6d, 0x42da662a),
2089 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Four of Diamonds Ethernet", 0xc2f80cd, 0xb3466314),
2090 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Seven of Diamonds Ethernet", 0xc2f80cd, 0x194b650a),
2091 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast Ethernet PCCard", 0x281f1c5d, 0xdcea68bc),
2092 PCMCIA_DEVICE_PROD_ID12("Psion", "10Mb Ethernet", 0x4ef00b21, 0x844be9e9),
2093 PCMCIA_DEVICE_PROD_ID12("SMC", "EtherEZ Ethernet 8020", 0xc4f8b18b, 0x4a0eeb2d),
2094 /* These conflict with other cards! */
2095 /* PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0100), */
2096 /* PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab), */
2099 MODULE_DEVICE_TABLE(pcmcia, smc91c92_ids);
2101 static struct pcmcia_driver smc91c92_cs_driver = {
2102 .owner = THIS_MODULE,
2104 .name = "smc91c92_cs",
2106 .probe = smc91c92_probe,
2107 .remove = smc91c92_detach,
2108 .id_table = smc91c92_ids,
2109 .suspend = smc91c92_suspend,
2110 .resume = smc91c92_resume,
2113 static int __init init_smc91c92_cs(void)
2115 return pcmcia_register_driver(&smc91c92_cs_driver);
2118 static void __exit exit_smc91c92_cs(void)
2120 pcmcia_unregister_driver(&smc91c92_cs_driver);
2123 module_init(init_smc91c92_cs);
2124 module_exit(exit_smc91c92_cs);