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>
45 #include <pcmcia/version.h>
46 #include <pcmcia/cs_types.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>
54 #include <asm/system.h>
55 #include <asm/uaccess.h>
57 /* Ositech Seven of Diamonds firmware */
60 /*====================================================================*/
62 static char *if_names[] = { "auto", "10baseT", "10base2"};
64 /* Module parameters */
66 MODULE_DESCRIPTION("SMC 91c92 series PCMCIA ethernet driver");
67 MODULE_LICENSE("GPL");
69 #define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")
72 Transceiver/media type.
74 1 = 10baseT (and autoselect if #define AUTOSELECT),
77 INT_MODULE_PARM(if_port, 0);
79 /* Bit map of interrupts to choose from. */
80 INT_MODULE_PARM(irq_mask, 0xdeb8);
81 static int irq_list[4] = { -1 };
82 MODULE_PARM(irq_list, "1-4i");
85 INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
86 static const char *version =
87 "smc91c92_cs.c 0.09 1996/8/4 Donald Becker, becker@scyld.com.\n";
88 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
90 #define DEBUG(n, args...)
93 #define DRV_NAME "smc91c92_cs"
94 #define DRV_VERSION "1.122"
96 /*====================================================================*/
98 /* Operational parameter that usually are not changed. */
100 /* Time in jiffies before concluding Tx hung */
101 #define TX_TIMEOUT ((400*HZ)/1000)
103 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
106 /* Times to check the check the chip before concluding that it doesn't
107 currently have room for another Tx packet. */
108 #define MEMORY_WAIT_TIME 8
110 static dev_info_t dev_info = "smc91c92_cs";
112 static dev_link_t *dev_list;
119 struct net_device_stats stats;
121 struct sk_buff *saved_skb;
125 struct timer_list media;
126 int watchdog, tx_err;
127 u_short media_status;
130 struct mii_if_info mii_if;
135 /* Special definitions for Megahertz multifunction cards */
136 #define MEGAHERTZ_ISR 0x0380
138 /* Special function registers for Motorola Mariner */
139 #define MOT_LAN 0x0000
140 #define MOT_UART 0x0020
141 #define MOT_EEPROM 0x20
144 (COR_LEVEL_REQ | COR_FUNC_ENA | COR_ADDR_DECODE | COR_IREQ_ENA)
146 /* Special function registers for Ositech cards */
147 #define OSITECH_AUI_CTL 0x0c
148 #define OSITECH_PWRDOWN 0x0d
149 #define OSITECH_RESET 0x0e
150 #define OSITECH_ISR 0x0f
151 #define OSITECH_AUI_PWR 0x0c
152 #define OSITECH_RESET_ISR 0x0e
154 #define OSI_AUI_PWR 0x40
155 #define OSI_LAN_PWRDOWN 0x02
156 #define OSI_MODEM_PWRDOWN 0x01
157 #define OSI_LAN_RESET 0x02
158 #define OSI_MODEM_RESET 0x01
160 /* Symbolic constants for the SMC91c9* series chips, from Erik Stahlman. */
161 #define BANK_SELECT 14 /* Window select register. */
162 #define SMC_SELECT_BANK(x) { outw(x, ioaddr + BANK_SELECT); }
164 /* Bank 0 registers. */
165 #define TCR 0 /* transmit control register */
166 #define TCR_CLEAR 0 /* do NOTHING */
167 #define TCR_ENABLE 0x0001 /* if this is 1, we can transmit */
168 #define TCR_PAD_EN 0x0080 /* pads short packets to 64 bytes */
169 #define TCR_MONCSN 0x0400 /* Monitor Carrier. */
170 #define TCR_FDUPLX 0x0800 /* Full duplex mode. */
171 #define TCR_NORMAL TCR_ENABLE | TCR_PAD_EN
173 #define EPH 2 /* Ethernet Protocol Handler report. */
174 #define EPH_TX_SUC 0x0001
175 #define EPH_SNGLCOL 0x0002
176 #define EPH_MULCOL 0x0004
177 #define EPH_LTX_MULT 0x0008
178 #define EPH_16COL 0x0010
179 #define EPH_SQET 0x0020
180 #define EPH_LTX_BRD 0x0040
181 #define EPH_TX_DEFR 0x0080
182 #define EPH_LAT_COL 0x0200
183 #define EPH_LOST_CAR 0x0400
184 #define EPH_EXC_DEF 0x0800
185 #define EPH_CTR_ROL 0x1000
186 #define EPH_RX_OVRN 0x2000
187 #define EPH_LINK_OK 0x4000
188 #define EPH_TX_UNRN 0x8000
189 #define MEMINFO 8 /* Memory Information Register */
190 #define MEMCFG 10 /* Memory Configuration Register */
192 /* Bank 1 registers. */
194 #define CFG_MII_SELECT 0x8000 /* 91C100 only */
195 #define CFG_NO_WAIT 0x1000
196 #define CFG_FULL_STEP 0x0400
197 #define CFG_SET_SQLCH 0x0200
198 #define CFG_AUI_SELECT 0x0100
199 #define CFG_16BIT 0x0080
200 #define CFG_DIS_LINK 0x0040
201 #define CFG_STATIC 0x0030
202 #define CFG_IRQ_SEL_1 0x0004
203 #define CFG_IRQ_SEL_0 0x0002
208 #define CTL_STORE 0x0001
209 #define CTL_RELOAD 0x0002
210 #define CTL_EE_SELECT 0x0004
211 #define CTL_TE_ENABLE 0x0020
212 #define CTL_CR_ENABLE 0x0040
213 #define CTL_LE_ENABLE 0x0080
214 #define CTL_AUTO_RELEASE 0x0800
215 #define CTL_POWERDOWN 0x2000
217 /* Bank 2 registers. */
219 #define MC_ALLOC 0x20 /* or with number of 256 byte packets */
220 #define MC_RESET 0x40
221 #define MC_RELEASE 0x80 /* remove and release the current rx packet */
222 #define MC_FREEPKT 0xA0 /* Release packet in PNR register */
223 #define MC_ENQUEUE 0xC0 /* Enqueue the packet for transmit */
226 #define FP_RXEMPTY 0x8000
228 #define PTR_AUTO_INC 0x0040
229 #define PTR_READ 0x2000
230 #define PTR_AUTOINC 0x4000
231 #define PTR_RCV 0x8000
234 #define IM_RCV_INT 0x1
235 #define IM_TX_INT 0x2
236 #define IM_TX_EMPTY_INT 0x4
237 #define IM_ALLOC_INT 0x8
238 #define IM_RX_OVRN_INT 0x10
239 #define IM_EPH_INT 0x20
242 enum RxCfg { RxAllMulti = 0x0004, RxPromisc = 0x0002,
243 RxEnable = 0x0100, RxStripCRC = 0x0200};
244 #define RCR_SOFTRESET 0x8000 /* resets the chip */
245 #define RCR_STRIP_CRC 0x200 /* strips CRC */
246 #define RCR_ENABLE 0x100 /* IFF this is set, we can receive packets */
247 #define RCR_ALMUL 0x4 /* receive all multicast packets */
248 #define RCR_PROMISC 0x2 /* enable promiscuous mode */
250 /* the normal settings for the RCR register : */
251 #define RCR_NORMAL (RCR_STRIP_CRC | RCR_ENABLE)
252 #define RCR_CLEAR 0x0 /* set it to a base state */
255 /* BANK 3 -- not the same values as in smc9194! */
261 #define REVISION 0x0a
263 /* Transmit status bits. */
264 #define TS_SUCCESS 0x0001
265 #define TS_16COL 0x0010
266 #define TS_LATCOL 0x0200
267 #define TS_LOSTCAR 0x0400
269 /* Receive status bits. */
270 #define RS_ALGNERR 0x8000
271 #define RS_BADCRC 0x2000
272 #define RS_ODDFRAME 0x1000
273 #define RS_TOOLONG 0x0800
274 #define RS_TOOSHORT 0x0400
275 #define RS_MULTICAST 0x0001
276 #define RS_ERRORS (RS_ALGNERR | RS_BADCRC | RS_TOOLONG | RS_TOOSHORT)
278 #define set_bits(v, p) outw(inw(p)|(v), (p))
279 #define mask_bits(v, p) outw(inw(p)&(v), (p))
281 /*====================================================================*/
283 static dev_link_t *smc91c92_attach(void);
284 static void smc91c92_detach(dev_link_t *);
285 static void smc91c92_config(dev_link_t *link);
286 static void smc91c92_release(dev_link_t *link);
287 static int smc91c92_event(event_t event, int priority,
288 event_callback_args_t *args);
290 static int smc_open(struct net_device *dev);
291 static int smc_close(struct net_device *dev);
292 static int smc_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
293 static void smc_tx_timeout(struct net_device *dev);
294 static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev);
295 static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
296 static void smc_rx(struct net_device *dev);
297 static struct net_device_stats *smc_get_stats(struct net_device *dev);
298 static void set_rx_mode(struct net_device *dev);
299 static int s9k_config(struct net_device *dev, struct ifmap *map);
300 static void smc_set_xcvr(struct net_device *dev, int if_port);
301 static void smc_reset(struct net_device *dev);
302 static void media_check(u_long arg);
303 static void mdio_sync(ioaddr_t addr);
304 static int mdio_read(struct net_device *dev, int phy_id, int loc);
305 static void mdio_write(struct net_device *dev, int phy_id, int loc, int value);
306 static int smc_link_ok(struct net_device *dev);
307 static struct ethtool_ops ethtool_ops;
309 /*======================================================================
311 smc91c92_attach() creates an "instance" of the driver, allocating
312 local data structures for one device. The device is registered
315 ======================================================================*/
317 static dev_link_t *smc91c92_attach(void)
319 client_reg_t client_reg;
320 struct smc_private *smc;
322 struct net_device *dev;
325 DEBUG(0, "smc91c92_attach()\n");
327 /* Create new ethernet device */
328 dev = alloc_etherdev(sizeof(struct smc_private));
331 smc = netdev_priv(dev);
335 spin_lock_init(&smc->lock);
336 link->io.NumPorts1 = 16;
337 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
338 link->io.IOAddrLines = 4;
339 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
340 link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
341 if (irq_list[0] == -1)
342 link->irq.IRQInfo2 = irq_mask;
344 for (i = 0; i < 4; i++)
345 link->irq.IRQInfo2 |= 1 << irq_list[i];
346 link->irq.Handler = &smc_interrupt;
347 link->irq.Instance = dev;
348 link->conf.Attributes = CONF_ENABLE_IRQ;
350 link->conf.IntType = INT_MEMORY_AND_IO;
352 /* The SMC91c92-specific entries in the device structure. */
353 SET_MODULE_OWNER(dev);
354 dev->hard_start_xmit = &smc_start_xmit;
355 dev->get_stats = &smc_get_stats;
356 dev->set_config = &s9k_config;
357 dev->set_multicast_list = &set_rx_mode;
358 dev->open = &smc_open;
359 dev->stop = &smc_close;
360 dev->do_ioctl = &smc_ioctl;
361 SET_ETHTOOL_OPS(dev, ðtool_ops);
362 #ifdef HAVE_TX_TIMEOUT
363 dev->tx_timeout = smc_tx_timeout;
364 dev->watchdog_timeo = TX_TIMEOUT;
367 smc->mii_if.dev = dev;
368 smc->mii_if.mdio_read = mdio_read;
369 smc->mii_if.mdio_write = mdio_write;
370 smc->mii_if.phy_id_mask = 0x1f;
371 smc->mii_if.reg_num_mask = 0x1f;
373 /* Register with Card Services */
374 link->next = dev_list;
376 client_reg.dev_info = &dev_info;
377 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
378 client_reg.EventMask = CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
379 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
380 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
381 client_reg.event_handler = &smc91c92_event;
382 client_reg.Version = 0x0210;
383 client_reg.event_callback_args.client_data = link;
384 ret = pcmcia_register_client(&link->handle, &client_reg);
386 cs_error(link->handle, RegisterClient, ret);
387 smc91c92_detach(link);
392 } /* smc91c92_attach */
394 /*======================================================================
396 This deletes a driver "instance". The device is de-registered
397 with Card Services. If it has been released, all local data
398 structures are freed. Otherwise, the structures will be freed
399 when the device is released.
401 ======================================================================*/
403 static void smc91c92_detach(dev_link_t *link)
405 struct net_device *dev = link->priv;
408 DEBUG(0, "smc91c92_detach(0x%p)\n", link);
410 /* Locate device structure */
411 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
412 if (*linkp == link) break;
417 unregister_netdev(dev);
419 if (link->state & DEV_CONFIG)
420 smc91c92_release(link);
423 pcmcia_deregister_client(link->handle);
425 /* Unlink device structure, free bits */
428 } /* smc91c92_detach */
430 /*====================================================================*/
432 static int cvt_ascii_address(struct net_device *dev, char *s)
438 for (i = 0; i < 6; i++) {
440 for (j = 0; j < 2; j++) {
443 da += ((c >= '0') && (c <= '9')) ?
444 (c - '0') : ((c & 0x0f) + 9);
446 dev->dev_addr[i] = da;
451 /*====================================================================*/
453 static int first_tuple(client_handle_t handle, tuple_t *tuple,
458 if ((i = pcmcia_get_first_tuple(handle, tuple)) != CS_SUCCESS ||
459 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
461 return pcmcia_parse_tuple(handle, tuple, parse);
464 static int next_tuple(client_handle_t handle, tuple_t *tuple,
469 if ((i = pcmcia_get_next_tuple(handle, tuple)) != CS_SUCCESS ||
470 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
472 return pcmcia_parse_tuple(handle, tuple, parse);
475 /*======================================================================
477 Configuration stuff for Megahertz cards
479 mhz_3288_power() is used to power up a 3288's ethernet chip.
480 mhz_mfc_config() handles socket setup for multifunction (1144
481 and 3288) cards. mhz_setup() gets a card's hardware ethernet
484 ======================================================================*/
486 static int mhz_3288_power(dev_link_t *link)
488 struct net_device *dev = link->priv;
489 struct smc_private *smc = netdev_priv(dev);
492 /* Read the ISR twice... */
493 readb(smc->base+MEGAHERTZ_ISR);
495 readb(smc->base+MEGAHERTZ_ISR);
500 /* Now read and write the COR... */
501 tmp = readb(smc->base + link->conf.ConfigBase + CISREG_COR);
503 writeb(tmp, smc->base + link->conf.ConfigBase + CISREG_COR);
508 static int mhz_mfc_config(dev_link_t *link)
510 struct net_device *dev = link->priv;
511 struct smc_private *smc = netdev_priv(dev);
515 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
520 link->conf.Attributes |= CONF_ENABLE_SPKR;
521 link->conf.Status = CCSR_AUDIO_ENA;
522 link->irq.Attributes =
523 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
524 link->io.IOAddrLines = 16;
525 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
526 link->io.NumPorts2 = 8;
528 tuple.Attributes = tuple.TupleOffset = 0;
529 tuple.TupleData = (cisdata_t *)buf;
530 tuple.TupleDataMax = sizeof(buf);
531 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
533 i = first_tuple(link->handle, &tuple, &parse);
534 /* The Megahertz combo cards have modem-like CIS entries, so
535 we have to explicitly try a bunch of port combinations. */
536 while (i == CS_SUCCESS) {
537 link->conf.ConfigIndex = cf->index;
538 link->io.BasePort2 = cf->io.win[0].base;
539 for (k = 0; k < 0x400; k += 0x10) {
540 if (k & 0x80) continue;
541 link->io.BasePort1 = k ^ 0x300;
542 i = pcmcia_request_io(link->handle, &link->io);
543 if (i == CS_SUCCESS) break;
545 if (i == CS_SUCCESS) break;
546 i = next_tuple(link->handle, &tuple, &parse);
550 dev->base_addr = link->io.BasePort1;
552 /* Allocate a memory window, for accessing the ISR */
553 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
554 req.Base = req.Size = 0;
556 i = pcmcia_request_window(&link->handle, &req, &link->win);
559 smc->base = ioremap(req.Base, req.Size);
560 mem.CardOffset = mem.Page = 0;
561 if (smc->manfid == MANFID_MOTOROLA)
562 mem.CardOffset = link->conf.ConfigBase;
563 i = pcmcia_map_mem_page(link->win, &mem);
565 if ((i == CS_SUCCESS)
566 && (smc->manfid == MANFID_MEGAHERTZ)
567 && (smc->cardid == PRODID_MEGAHERTZ_EM3288))
568 mhz_3288_power(link);
573 static int mhz_setup(dev_link_t *link)
575 client_handle_t handle = link->handle;
576 struct net_device *dev = link->priv;
579 u_char buf[255], *station_addr;
581 tuple.Attributes = tuple.TupleOffset = 0;
582 tuple.TupleData = buf;
583 tuple.TupleDataMax = sizeof(buf);
585 /* Read the station address from the CIS. It is stored as the last
586 (fourth) string in the Version 1 Version/ID tuple. */
587 tuple.DesiredTuple = CISTPL_VERS_1;
588 if (first_tuple(handle, &tuple, &parse) != CS_SUCCESS)
590 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
591 if (next_tuple(handle, &tuple, &parse) != CS_SUCCESS)
592 first_tuple(handle, &tuple, &parse);
593 if (parse.version_1.ns > 3) {
594 station_addr = parse.version_1.str + parse.version_1.ofs[3];
595 if (cvt_ascii_address(dev, station_addr) == 0)
599 /* Another possibility: for the EM3288, in a special tuple */
600 tuple.DesiredTuple = 0x81;
601 if (pcmcia_get_first_tuple(handle, &tuple) != CS_SUCCESS)
603 if (pcmcia_get_tuple_data(handle, &tuple) != CS_SUCCESS)
606 if (cvt_ascii_address(dev, buf) == 0)
612 /*======================================================================
614 Configuration stuff for the Motorola Mariner
616 mot_config() writes directly to the Mariner configuration
617 registers because the CIS is just bogus.
619 ======================================================================*/
621 static void mot_config(dev_link_t *link)
623 struct net_device *dev = link->priv;
624 struct smc_private *smc = netdev_priv(dev);
625 ioaddr_t ioaddr = dev->base_addr;
626 ioaddr_t iouart = link->io.BasePort2;
628 /* Set UART base address and force map with COR bit 1 */
629 writeb(iouart & 0xff, smc->base + MOT_UART + CISREG_IOBASE_0);
630 writeb((iouart >> 8) & 0xff, smc->base + MOT_UART + CISREG_IOBASE_1);
631 writeb(MOT_NORMAL, smc->base + MOT_UART + CISREG_COR);
633 /* Set SMC base address and force map with COR bit 1 */
634 writeb(ioaddr & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_0);
635 writeb((ioaddr >> 8) & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_1);
636 writeb(MOT_NORMAL, smc->base + MOT_LAN + CISREG_COR);
638 /* Wait for things to settle down */
642 static int mot_setup(dev_link_t *link)
644 struct net_device *dev = link->priv;
645 ioaddr_t ioaddr = dev->base_addr;
649 /* Read Ethernet address from Serial EEPROM */
651 for (i = 0; i < 3; i++) {
653 outw(MOT_EEPROM + i, ioaddr + POINTER);
655 outw((CTL_RELOAD | CTL_EE_SELECT), ioaddr + CONTROL);
657 for (loop = wait = 0; loop < 200; loop++) {
659 wait = ((CTL_RELOAD | CTL_STORE) & inw(ioaddr + CONTROL));
660 if (wait == 0) break;
666 addr = inw(ioaddr + GENERAL);
667 dev->dev_addr[2*i] = addr & 0xff;
668 dev->dev_addr[2*i+1] = (addr >> 8) & 0xff;
674 /*====================================================================*/
676 static int smc_config(dev_link_t *link)
678 struct net_device *dev = link->priv;
682 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
685 tuple.Attributes = tuple.TupleOffset = 0;
686 tuple.TupleData = (cisdata_t *)buf;
687 tuple.TupleDataMax = sizeof(buf);
688 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
690 link->io.NumPorts1 = 16;
691 i = first_tuple(link->handle, &tuple, &parse);
692 while (i != CS_NO_MORE_ITEMS) {
693 if (i == CS_SUCCESS) {
694 link->conf.ConfigIndex = cf->index;
695 link->io.BasePort1 = cf->io.win[0].base;
696 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
697 i = pcmcia_request_io(link->handle, &link->io);
698 if (i == CS_SUCCESS) break;
700 i = next_tuple(link->handle, &tuple, &parse);
703 dev->base_addr = link->io.BasePort1;
707 static int smc_setup(dev_link_t *link)
709 client_handle_t handle = link->handle;
710 struct net_device *dev = link->priv;
713 cistpl_lan_node_id_t *node_id;
714 u_char buf[255], *station_addr;
717 tuple.Attributes = tuple.TupleOffset = 0;
718 tuple.TupleData = buf;
719 tuple.TupleDataMax = sizeof(buf);
721 /* Check for a LAN function extension tuple */
722 tuple.DesiredTuple = CISTPL_FUNCE;
723 i = first_tuple(handle, &tuple, &parse);
724 while (i == CS_SUCCESS) {
725 if (parse.funce.type == CISTPL_FUNCE_LAN_NODE_ID)
727 i = next_tuple(handle, &tuple, &parse);
729 if (i == CS_SUCCESS) {
730 node_id = (cistpl_lan_node_id_t *)parse.funce.data;
731 if (node_id->nb == 6) {
732 for (i = 0; i < 6; i++)
733 dev->dev_addr[i] = node_id->id[i];
737 /* Try the third string in the Version 1 Version/ID tuple. */
738 tuple.DesiredTuple = CISTPL_VERS_1;
739 if (first_tuple(handle, &tuple, &parse) != CS_SUCCESS)
741 station_addr = parse.version_1.str + parse.version_1.ofs[2];
742 if (cvt_ascii_address(dev, station_addr) == 0)
748 /*====================================================================*/
750 static int osi_config(dev_link_t *link)
752 struct net_device *dev = link->priv;
753 static ioaddr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
756 link->conf.Attributes |= CONF_ENABLE_SPKR;
757 link->conf.Status = CCSR_AUDIO_ENA;
758 link->irq.Attributes =
759 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
760 link->io.NumPorts1 = 64;
761 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
762 link->io.NumPorts2 = 8;
763 link->io.IOAddrLines = 16;
765 /* Enable Hard Decode, LAN, Modem */
766 link->conf.ConfigIndex = 0x23;
768 for (i = j = 0; j < 4; j++) {
769 link->io.BasePort2 = com[j];
770 i = pcmcia_request_io(link->handle, &link->io);
771 if (i == CS_SUCCESS) break;
773 if (i != CS_SUCCESS) {
774 /* Fallback: turn off hard decode */
775 link->conf.ConfigIndex = 0x03;
776 link->io.NumPorts2 = 0;
777 i = pcmcia_request_io(link->handle, &link->io);
779 dev->base_addr = link->io.BasePort1 + 0x10;
783 static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid)
785 client_handle_t handle = link->handle;
786 struct net_device *dev = link->priv;
791 tuple.Attributes = TUPLE_RETURN_COMMON;
792 tuple.TupleData = buf;
793 tuple.TupleDataMax = sizeof(buf);
794 tuple.TupleOffset = 0;
796 /* Read the station address from tuple 0x90, subtuple 0x04 */
797 tuple.DesiredTuple = 0x90;
798 i = pcmcia_get_first_tuple(handle, &tuple);
799 while (i == CS_SUCCESS) {
800 i = pcmcia_get_tuple_data(handle, &tuple);
801 if ((i != CS_SUCCESS) || (buf[0] == 0x04))
803 i = pcmcia_get_next_tuple(handle, &tuple);
807 for (i = 0; i < 6; i++)
808 dev->dev_addr[i] = buf[i+2];
810 if (((manfid == MANFID_OSITECH) &&
811 (cardid == PRODID_OSITECH_SEVEN)) ||
812 ((manfid == MANFID_PSION) &&
813 (cardid == PRODID_PSION_NET100))) {
814 /* Download the Seven of Diamonds firmware */
815 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
816 outb(__Xilinx7OD[i], link->io.BasePort1+2);
819 } else if (manfid == MANFID_OSITECH) {
820 /* Make sure both functions are powered up */
821 set_bits(0x300, link->io.BasePort1 + OSITECH_AUI_PWR);
822 /* Now, turn on the interrupt for both card functions */
823 set_bits(0x300, link->io.BasePort1 + OSITECH_RESET_ISR);
824 DEBUG(2, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n",
825 inw(link->io.BasePort1 + OSITECH_AUI_PWR),
826 inw(link->io.BasePort1 + OSITECH_RESET_ISR));
832 /*======================================================================
834 This verifies that the chip is some SMC91cXX variant, and returns
835 the revision code if successful. Otherwise, it returns -ENODEV.
837 ======================================================================*/
839 static int check_sig(dev_link_t *link)
841 struct net_device *dev = link->priv;
842 ioaddr_t ioaddr = dev->base_addr;
847 if (inw(ioaddr + BANK_SELECT) >> 8 != 0x33) {
848 /* Try powering up the chip */
849 outw(0, ioaddr + CONTROL);
853 /* Try setting bus width */
854 width = (link->io.Attributes1 == IO_DATA_PATH_WIDTH_AUTO);
855 s = inb(ioaddr + CONFIG);
860 outb(s, ioaddr + CONFIG);
862 /* Check Base Address Register to make sure bus width is OK */
863 s = inw(ioaddr + BASE_ADDR);
864 if ((inw(ioaddr + BANK_SELECT) >> 8 == 0x33) &&
865 ((s >> 8) != (s & 0xff))) {
867 s = inw(ioaddr + REVISION);
872 event_callback_args_t args;
873 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n");
874 args.client_data = link;
875 smc91c92_event(CS_EVENT_RESET_PHYSICAL, 0, &args);
876 pcmcia_release_io(link->handle, &link->io);
877 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
878 pcmcia_request_io(link->handle, &link->io);
879 smc91c92_event(CS_EVENT_CARD_RESET, 0, &args);
880 return check_sig(link);
885 /*======================================================================
887 smc91c92_config() is scheduled to run after a CARD_INSERTION event
888 is received, to configure the PCMCIA socket, and to make the
889 ethernet device available to the system.
891 ======================================================================*/
893 #define CS_EXIT_TEST(ret, svc, label) \
894 if (ret != CS_SUCCESS) { cs_error(link->handle, svc, ret); goto label; }
896 static void smc91c92_config(dev_link_t *link)
898 client_handle_t handle = link->handle;
899 struct net_device *dev = link->priv;
900 struct smc_private *smc = netdev_priv(dev);
909 DEBUG(0, "smc91c92_config(0x%p)\n", link);
911 tuple.Attributes = tuple.TupleOffset = 0;
912 tuple.TupleData = (cisdata_t *)buf;
913 tuple.TupleDataMax = sizeof(buf);
915 tuple.DesiredTuple = CISTPL_CONFIG;
916 i = first_tuple(handle, &tuple, &parse);
917 CS_EXIT_TEST(i, ParseTuple, config_failed);
918 link->conf.ConfigBase = parse.config.base;
919 link->conf.Present = parse.config.rmask[0];
921 tuple.DesiredTuple = CISTPL_MANFID;
922 tuple.Attributes = TUPLE_RETURN_COMMON;
923 if (first_tuple(handle, &tuple, &parse) == CS_SUCCESS) {
924 smc->manfid = parse.manfid.manf;
925 smc->cardid = parse.manfid.card;
929 link->state |= DEV_CONFIG;
931 if ((smc->manfid == MANFID_OSITECH) &&
932 (smc->cardid != PRODID_OSITECH_SEVEN)) {
933 i = osi_config(link);
934 } else if ((smc->manfid == MANFID_MOTOROLA) ||
935 ((smc->manfid == MANFID_MEGAHERTZ) &&
936 ((smc->cardid == PRODID_MEGAHERTZ_VARIOUS) ||
937 (smc->cardid == PRODID_MEGAHERTZ_EM3288)))) {
938 i = mhz_mfc_config(link);
940 i = smc_config(link);
942 CS_EXIT_TEST(i, RequestIO, config_failed);
944 i = pcmcia_request_irq(link->handle, &link->irq);
945 CS_EXIT_TEST(i, RequestIRQ, config_failed);
946 i = pcmcia_request_configuration(link->handle, &link->conf);
947 CS_EXIT_TEST(i, RequestConfiguration, config_failed);
949 if (smc->manfid == MANFID_MOTOROLA)
952 dev->irq = link->irq.AssignedIRQ;
954 if ((if_port >= 0) && (if_port <= 2))
955 dev->if_port = if_port;
957 printk(KERN_NOTICE "smc91c92_cs: invalid if_port requested\n");
959 switch (smc->manfid) {
962 i = osi_setup(link, smc->manfid, smc->cardid); break;
964 case MANFID_NEW_MEDIA:
965 i = smc_setup(link); break;
966 case 0x128: /* For broken Megahertz cards */
967 case MANFID_MEGAHERTZ:
968 i = mhz_setup(link); break;
969 case MANFID_MOTOROLA:
970 default: /* get the hw address from EEPROM */
971 i = mot_setup(link); break;
975 printk(KERN_NOTICE "smc91c92_cs: Unable to find hardware address.\n");
982 rev = check_sig(link);
986 case 3: name = "92"; break;
987 case 4: name = ((rev & 15) >= 6) ? "96" : "94"; break;
988 case 5: name = "95"; break;
989 case 7: name = "100"; break;
990 case 8: name = "100-FD"; break;
991 case 9: name = "110"; break;
994 ioaddr = dev->base_addr;
998 mir = inw(ioaddr + MEMINFO) & 0xff;
999 if (mir == 0xff) mir++;
1000 /* Get scale factor for memory size */
1001 mcr = ((rev >> 4) > 3) ? inw(ioaddr + MEMCFG) : 0x0200;
1002 mir *= 128 * (1<<((mcr >> 9) & 7));
1004 smc->cfg = inw(ioaddr + CONFIG) & ~CFG_AUI_SELECT;
1005 smc->cfg |= CFG_NO_WAIT | CFG_16BIT | CFG_STATIC;
1006 if (smc->manfid == MANFID_OSITECH)
1007 smc->cfg |= CFG_IRQ_SEL_1 | CFG_IRQ_SEL_0;
1008 if ((rev >> 4) >= 7)
1009 smc->cfg |= CFG_MII_SELECT;
1013 if (smc->cfg & CFG_MII_SELECT) {
1016 for (i = 0; i < 32; i++) {
1017 j = mdio_read(dev, i, 1);
1018 if ((j != 0) && (j != 0xffff)) break;
1020 smc->mii_if.phy_id = (i < 32) ? i : -1;
1025 link->dev = &smc->node;
1026 link->state &= ~DEV_CONFIG_PENDING;
1028 if (register_netdev(dev) != 0) {
1029 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n");
1034 strcpy(smc->node.dev_name, dev->name);
1036 printk(KERN_INFO "%s: smc91c%s rev %d: io %#3lx, irq %d, "
1037 "hw_addr ", dev->name, name, (rev & 0x0f), dev->base_addr,
1039 for (i = 0; i < 6; i++)
1040 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
1044 printk(KERN_INFO " %lu byte", mir);
1046 printk(KERN_INFO " %lu kb", mir>>10);
1047 printk(" buffer, %s xcvr\n", (smc->cfg & CFG_MII_SELECT) ?
1048 "MII" : if_names[dev->if_port]);
1051 if (smc->cfg & CFG_MII_SELECT) {
1052 if (smc->mii_if.phy_id != -1) {
1053 DEBUG(0, " MII transceiver at index %d, status %x.\n",
1054 smc->mii_if.phy_id, j);
1056 printk(KERN_NOTICE " No MII transceivers found!\n");
1063 unregister_netdev(dev);
1064 config_failed: /* CS_EXIT_TEST() calls jump to here... */
1065 smc91c92_release(link);
1066 link->state &= ~DEV_CONFIG_PENDING;
1068 } /* smc91c92_config */
1070 /*======================================================================
1072 After a card is removed, smc91c92_release() will unregister the net
1073 device, and release the PCMCIA configuration. If the device is
1074 still open, this will be postponed until it is closed.
1076 ======================================================================*/
1078 static void smc91c92_release(dev_link_t *link)
1081 DEBUG(0, "smc91c92_release(0x%p)\n", link);
1083 pcmcia_release_configuration(link->handle);
1084 pcmcia_release_io(link->handle, &link->io);
1085 pcmcia_release_irq(link->handle, &link->irq);
1087 struct net_device *dev = link->priv;
1088 struct smc_private *smc = netdev_priv(dev);
1090 pcmcia_release_window(link->win);
1093 link->state &= ~DEV_CONFIG;
1096 /*======================================================================
1098 The card status event handler. Mostly, this schedules other
1099 stuff to run after an event is received. A CARD_REMOVAL event
1100 also sets some flags to discourage the net drivers from trying
1101 to talk to the card any more.
1103 ======================================================================*/
1105 static int smc91c92_event(event_t event, int priority,
1106 event_callback_args_t *args)
1108 dev_link_t *link = args->client_data;
1109 struct net_device *dev = link->priv;
1110 struct smc_private *smc = netdev_priv(dev);
1113 DEBUG(1, "smc91c92_event(0x%06x)\n", event);
1116 case CS_EVENT_CARD_REMOVAL:
1117 link->state &= ~DEV_PRESENT;
1118 if (link->state & DEV_CONFIG)
1119 netif_device_detach(dev);
1121 case CS_EVENT_CARD_INSERTION:
1122 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1123 smc91c92_config(link);
1125 case CS_EVENT_PM_SUSPEND:
1126 link->state |= DEV_SUSPEND;
1127 /* Fall through... */
1128 case CS_EVENT_RESET_PHYSICAL:
1129 if (link->state & DEV_CONFIG) {
1131 netif_device_detach(dev);
1132 pcmcia_release_configuration(link->handle);
1135 case CS_EVENT_PM_RESUME:
1136 link->state &= ~DEV_SUSPEND;
1137 /* Fall through... */
1138 case CS_EVENT_CARD_RESET:
1139 if (link->state & DEV_CONFIG) {
1140 if ((smc->manfid == MANFID_MEGAHERTZ) &&
1141 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
1142 mhz_3288_power(link);
1143 pcmcia_request_configuration(link->handle, &link->conf);
1144 if (smc->manfid == MANFID_MOTOROLA)
1146 if ((smc->manfid == MANFID_OSITECH) &&
1147 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1148 /* Power up the card and enable interrupts */
1149 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR);
1150 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR);
1152 if (((smc->manfid == MANFID_OSITECH) &&
1153 (smc->cardid == PRODID_OSITECH_SEVEN)) ||
1154 ((smc->manfid == MANFID_PSION) &&
1155 (smc->cardid == PRODID_PSION_NET100))) {
1156 /* Download the Seven of Diamonds firmware */
1157 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
1158 outb(__Xilinx7OD[i], link->io.BasePort1+2);
1164 netif_device_attach(dev);
1170 } /* smc91c92_event */
1172 /*======================================================================
1174 MII interface support for SMC91cXX based cards
1175 ======================================================================*/
1177 #define MDIO_SHIFT_CLK 0x04
1178 #define MDIO_DATA_OUT 0x01
1179 #define MDIO_DIR_WRITE 0x08
1180 #define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
1181 #define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
1182 #define MDIO_DATA_READ 0x02
1184 static void mdio_sync(ioaddr_t addr)
1187 for (bits = 0; bits < 32; bits++) {
1188 outb(MDIO_DATA_WRITE1, addr);
1189 outb(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
1193 static int mdio_read(struct net_device *dev, int phy_id, int loc)
1195 ioaddr_t addr = dev->base_addr + MGMT;
1196 u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
1200 for (i = 13; i >= 0; i--) {
1201 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1203 outb(dat | MDIO_SHIFT_CLK, addr);
1205 for (i = 19; i > 0; i--) {
1207 retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
1208 outb(MDIO_SHIFT_CLK, addr);
1210 return (retval>>1) & 0xffff;
1213 static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
1215 ioaddr_t addr = dev->base_addr + MGMT;
1216 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
1220 for (i = 31; i >= 0; i--) {
1221 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1223 outb(dat | MDIO_SHIFT_CLK, addr);
1225 for (i = 1; i >= 0; i--) {
1227 outb(MDIO_SHIFT_CLK, addr);
1231 /*======================================================================
1233 The driver core code, most of which should be common with a
1234 non-PCMCIA implementation.
1236 ======================================================================*/
1239 static void smc_dump(struct net_device *dev)
1241 ioaddr_t ioaddr = dev->base_addr;
1243 save = inw(ioaddr + BANK_SELECT);
1244 for (w = 0; w < 4; w++) {
1246 printk(KERN_DEBUG "bank %d: ", w);
1247 for (i = 0; i < 14; i += 2)
1248 printk(" %04x", inw(ioaddr + i));
1251 outw(save, ioaddr + BANK_SELECT);
1255 static int smc_open(struct net_device *dev)
1257 struct smc_private *smc = netdev_priv(dev);
1258 dev_link_t *link = &smc->link;
1261 DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n",
1262 dev->name, dev, inw(dev->base_addr + BANK_SELECT));
1263 if (pc_debug > 1) smc_dump(dev);
1266 /* Check that the PCMCIA card is still here. */
1269 /* Physical device present signature. */
1270 if (check_sig(link) < 0) {
1271 printk("smc91c92_cs: Yikes! Bad chip signature!\n");
1276 netif_start_queue(dev);
1277 smc->saved_skb = NULL;
1278 smc->packets_waiting = 0;
1281 init_timer(&smc->media);
1282 smc->media.function = &media_check;
1283 smc->media.data = (u_long) dev;
1284 smc->media.expires = jiffies + HZ;
1285 add_timer(&smc->media);
1290 /*====================================================================*/
1292 static int smc_close(struct net_device *dev)
1294 struct smc_private *smc = netdev_priv(dev);
1295 dev_link_t *link = &smc->link;
1296 ioaddr_t ioaddr = dev->base_addr;
1298 DEBUG(0, "%s: smc_close(), status %4.4x.\n",
1299 dev->name, inw(ioaddr + BANK_SELECT));
1301 netif_stop_queue(dev);
1303 /* Shut off all interrupts, and turn off the Tx and Rx sections.
1304 Don't bother to check for chip present. */
1305 SMC_SELECT_BANK(2); /* Nominally paranoia, but do no assume... */
1306 outw(0, ioaddr + INTERRUPT);
1308 mask_bits(0xff00, ioaddr + RCR);
1309 mask_bits(0xff00, ioaddr + TCR);
1311 /* Put the chip into power-down mode. */
1313 outw(CTL_POWERDOWN, ioaddr + CONTROL );
1316 del_timer_sync(&smc->media);
1321 /*======================================================================
1323 Transfer a packet to the hardware and trigger the packet send.
1324 This may be called at either from either the Tx queue code
1325 or the interrupt handler.
1327 ======================================================================*/
1329 static void smc_hardware_send_packet(struct net_device * dev)
1331 struct smc_private *smc = netdev_priv(dev);
1332 struct sk_buff *skb = smc->saved_skb;
1333 ioaddr_t ioaddr = dev->base_addr;
1337 printk(KERN_ERR "%s: In XMIT with no packet to send.\n", dev->name);
1341 /* There should be a packet slot waiting. */
1342 packet_no = inw(ioaddr + PNR_ARR) >> 8;
1343 if (packet_no & 0x80) {
1344 /* If not, there is a hardware problem! Likely an ejected card. */
1345 printk(KERN_WARNING "%s: 91c92 hardware Tx buffer allocation"
1346 " failed, status %#2.2x.\n", dev->name, packet_no);
1347 dev_kfree_skb_irq(skb);
1348 smc->saved_skb = NULL;
1349 netif_start_queue(dev);
1353 smc->stats.tx_bytes += skb->len;
1354 /* The card should use the just-allocated buffer. */
1355 outw(packet_no, ioaddr + PNR_ARR);
1356 /* point to the beginning of the packet */
1357 outw(PTR_AUTOINC , ioaddr + POINTER);
1359 /* Send the packet length (+6 for status, length and ctl byte)
1360 and the status word (set to zeros). */
1362 u_char *buf = skb->data;
1363 u_int length = skb->len; /* The chip will pad to ethernet min. */
1365 DEBUG(2, "%s: Trying to xmit packet of length %d.\n",
1368 /* send the packet length: +6 for status word, length, and ctl */
1369 outw(0, ioaddr + DATA_1);
1370 outw(length + 6, ioaddr + DATA_1);
1371 outsw(ioaddr + DATA_1, buf, length >> 1);
1373 /* The odd last byte, if there is one, goes in the control word. */
1374 outw((length & 1) ? 0x2000 | buf[length-1] : 0, ioaddr + DATA_1);
1377 /* Enable the Tx interrupts, both Tx (TxErr) and TxEmpty. */
1378 outw(((IM_TX_INT|IM_TX_EMPTY_INT)<<8) |
1379 (inw(ioaddr + INTERRUPT) & 0xff00),
1380 ioaddr + INTERRUPT);
1382 /* The chip does the rest of the work. */
1383 outw(MC_ENQUEUE , ioaddr + MMU_CMD);
1385 smc->saved_skb = NULL;
1386 dev_kfree_skb_irq(skb);
1387 dev->trans_start = jiffies;
1388 netif_start_queue(dev);
1392 /*====================================================================*/
1394 static void smc_tx_timeout(struct net_device *dev)
1396 struct smc_private *smc = netdev_priv(dev);
1397 ioaddr_t ioaddr = dev->base_addr;
1399 printk(KERN_NOTICE "%s: SMC91c92 transmit timed out, "
1400 "Tx_status %2.2x status %4.4x.\n",
1401 dev->name, inw(ioaddr)&0xff, inw(ioaddr + 2));
1402 smc->stats.tx_errors++;
1404 dev->trans_start = jiffies;
1405 smc->saved_skb = NULL;
1406 netif_wake_queue(dev);
1409 static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev)
1411 struct smc_private *smc = netdev_priv(dev);
1412 ioaddr_t ioaddr = dev->base_addr;
1416 netif_stop_queue(dev);
1418 DEBUG(2, "%s: smc_start_xmit(length = %d) called,"
1419 " status %4.4x.\n", dev->name, skb->len, inw(ioaddr + 2));
1421 if (smc->saved_skb) {
1422 /* THIS SHOULD NEVER HAPPEN. */
1423 smc->stats.tx_aborted_errors++;
1424 printk(KERN_DEBUG "%s: Internal error -- sent packet while busy.\n",
1428 smc->saved_skb = skb;
1430 num_pages = skb->len >> 8;
1432 if (num_pages > 7) {
1433 printk(KERN_ERR "%s: Far too big packet error.\n", dev->name);
1434 dev_kfree_skb (skb);
1435 smc->saved_skb = NULL;
1436 smc->stats.tx_dropped++;
1437 return 0; /* Do not re-queue this packet. */
1439 /* A packet is now waiting. */
1440 smc->packets_waiting++;
1442 SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */
1444 /* need MC_RESET to keep the memory consistent. errata? */
1446 outw(MC_RESET, ioaddr + MMU_CMD);
1450 /* Allocate the memory; send the packet now if we win. */
1451 outw(MC_ALLOC | num_pages, ioaddr + MMU_CMD);
1452 for (time_out = MEMORY_WAIT_TIME; time_out >= 0; time_out--) {
1453 ir = inw(ioaddr+INTERRUPT);
1454 if (ir & IM_ALLOC_INT) {
1455 /* Acknowledge the interrupt, send the packet. */
1456 outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT);
1457 smc_hardware_send_packet(dev); /* Send the packet now.. */
1462 /* Otherwise defer until the Tx-space-allocated interrupt. */
1463 DEBUG(2, "%s: memory allocation deferred.\n", dev->name);
1464 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT);
1469 /*======================================================================
1471 Handle a Tx anomolous event. Entered while in Window 2.
1473 ======================================================================*/
1475 static void smc_tx_err(struct net_device * dev)
1477 struct smc_private *smc = netdev_priv(dev);
1478 ioaddr_t ioaddr = dev->base_addr;
1479 int saved_packet = inw(ioaddr + PNR_ARR) & 0xff;
1480 int packet_no = inw(ioaddr + FIFO_PORTS) & 0x7f;
1483 /* select this as the packet to read from */
1484 outw(packet_no, ioaddr + PNR_ARR);
1486 /* read the first word from this packet */
1487 outw(PTR_AUTOINC | PTR_READ | 0, ioaddr + POINTER);
1489 tx_status = inw(ioaddr + DATA_1);
1491 smc->stats.tx_errors++;
1492 if (tx_status & TS_LOSTCAR) smc->stats.tx_carrier_errors++;
1493 if (tx_status & TS_LATCOL) smc->stats.tx_window_errors++;
1494 if (tx_status & TS_16COL) {
1495 smc->stats.tx_aborted_errors++;
1499 if (tx_status & TS_SUCCESS) {
1500 printk(KERN_NOTICE "%s: Successful packet caused error "
1501 "interrupt?\n", dev->name);
1503 /* re-enable transmit */
1505 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1508 outw(MC_FREEPKT, ioaddr + MMU_CMD); /* Free the packet memory. */
1510 /* one less packet waiting for me */
1511 smc->packets_waiting--;
1513 outw(saved_packet, ioaddr + PNR_ARR);
1517 /*====================================================================*/
1519 static void smc_eph_irq(struct net_device *dev)
1521 struct smc_private *smc = netdev_priv(dev);
1522 ioaddr_t ioaddr = dev->base_addr;
1523 u_short card_stats, ephs;
1526 ephs = inw(ioaddr + EPH);
1527 DEBUG(2, "%s: Ethernet protocol handler interrupt, status"
1528 " %4.4x.\n", dev->name, ephs);
1529 /* Could be a counter roll-over warning: update stats. */
1530 card_stats = inw(ioaddr + COUNTER);
1531 /* single collisions */
1532 smc->stats.collisions += card_stats & 0xF;
1534 /* multiple collisions */
1535 smc->stats.collisions += card_stats & 0xF;
1536 #if 0 /* These are for when linux supports these statistics */
1537 card_stats >>= 4; /* deferred */
1538 card_stats >>= 4; /* excess deferred */
1540 /* If we had a transmit error we must re-enable the transmitter. */
1541 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1543 /* Clear a link error interrupt. */
1545 outw(CTL_AUTO_RELEASE | 0x0000, ioaddr + CONTROL);
1546 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1551 /*====================================================================*/
1553 static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1555 struct net_device *dev = dev_id;
1556 struct smc_private *smc = netdev_priv(dev);
1558 u_short saved_bank, saved_pointer, mask, status;
1559 unsigned int handled = 1;
1560 char bogus_cnt = INTR_WORK; /* Work we are willing to do. */
1562 if (!netif_device_present(dev))
1565 ioaddr = dev->base_addr;
1567 DEBUG(3, "%s: SMC91c92 interrupt %d at %#x.\n", dev->name,
1571 saved_bank = inw(ioaddr + BANK_SELECT);
1572 if ((saved_bank & 0xff00) != 0x3300) {
1573 /* The device does not exist -- the card could be off-line, or
1574 maybe it has been ejected. */
1575 DEBUG(1, "%s: SMC91c92 interrupt %d for non-existent"
1576 "/ejected device.\n", dev->name, irq);
1582 saved_pointer = inw(ioaddr + POINTER);
1583 mask = inw(ioaddr + INTERRUPT) >> 8;
1584 /* clear all interrupts */
1585 outw(0, ioaddr + INTERRUPT);
1587 do { /* read the status flag, and mask it */
1588 status = inw(ioaddr + INTERRUPT) & 0xff;
1589 DEBUG(3, "%s: Status is %#2.2x (mask %#2.2x).\n", dev->name,
1591 if ((status & mask) == 0) {
1592 if (bogus_cnt == INTR_WORK)
1596 if (status & IM_RCV_INT) {
1597 /* Got a packet(s). */
1600 if (status & IM_TX_INT) {
1602 outw(IM_TX_INT, ioaddr + INTERRUPT);
1605 if (status & IM_TX_EMPTY_INT) {
1606 outw(IM_TX_EMPTY_INT, ioaddr + INTERRUPT);
1607 mask &= ~IM_TX_EMPTY_INT;
1608 smc->stats.tx_packets += smc->packets_waiting;
1609 smc->packets_waiting = 0;
1611 if (status & IM_ALLOC_INT) {
1612 /* Clear this interrupt so it doesn't happen again */
1613 mask &= ~IM_ALLOC_INT;
1615 smc_hardware_send_packet(dev);
1617 /* enable xmit interrupts based on this */
1618 mask |= (IM_TX_EMPTY_INT | IM_TX_INT);
1620 /* and let the card send more packets to me */
1621 netif_wake_queue(dev);
1623 if (status & IM_RX_OVRN_INT) {
1624 smc->stats.rx_errors++;
1625 smc->stats.rx_fifo_errors++;
1627 smc->rx_ovrn = 1; /* need MC_RESET outside smc_interrupt */
1628 outw(IM_RX_OVRN_INT, ioaddr + INTERRUPT);
1630 if (status & IM_EPH_INT)
1632 } while (--bogus_cnt);
1634 DEBUG(3, " Restoring saved registers mask %2.2x bank %4.4x"
1635 " pointer %4.4x.\n", mask, saved_bank, saved_pointer);
1637 /* restore state register */
1638 outw((mask<<8), ioaddr + INTERRUPT);
1639 outw(saved_pointer, ioaddr + POINTER);
1640 SMC_SELECT_BANK(saved_bank);
1642 DEBUG(3, "%s: Exiting interrupt IRQ%d.\n", dev->name, irq);
1646 if ((smc->manfid == MANFID_OSITECH) &&
1647 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1648 /* Retrigger interrupt if needed */
1649 mask_bits(0x00ff, ioaddr-0x10+OSITECH_RESET_ISR);
1650 set_bits(0x0300, ioaddr-0x10+OSITECH_RESET_ISR);
1652 if (smc->manfid == MANFID_MOTOROLA) {
1654 cor = readb(smc->base + MOT_UART + CISREG_COR);
1655 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_UART + CISREG_COR);
1656 writeb(cor, smc->base + MOT_UART + CISREG_COR);
1657 cor = readb(smc->base + MOT_LAN + CISREG_COR);
1658 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_LAN + CISREG_COR);
1659 writeb(cor, smc->base + MOT_LAN + CISREG_COR);
1661 #ifdef DOES_NOT_WORK
1662 if (smc->base != NULL) { /* Megahertz MFC's */
1663 readb(smc->base+MEGAHERTZ_ISR);
1664 readb(smc->base+MEGAHERTZ_ISR);
1667 return IRQ_RETVAL(handled);
1670 /*====================================================================*/
1672 static void smc_rx(struct net_device *dev)
1674 struct smc_private *smc = netdev_priv(dev);
1675 ioaddr_t ioaddr = dev->base_addr;
1677 int packet_length; /* Caution: not frame length, rather words
1678 to transfer from the chip. */
1680 /* Assertion: we are in Window 2. */
1682 if (inw(ioaddr + FIFO_PORTS) & FP_RXEMPTY) {
1683 printk(KERN_ERR "%s: smc_rx() with nothing on Rx FIFO.\n",
1688 /* Reset the read pointer, and read the status and packet length. */
1689 outw(PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER);
1690 rx_status = inw(ioaddr + DATA_1);
1691 packet_length = inw(ioaddr + DATA_1) & 0x07ff;
1693 DEBUG(2, "%s: Receive status %4.4x length %d.\n",
1694 dev->name, rx_status, packet_length);
1696 if (!(rx_status & RS_ERRORS)) {
1697 /* do stuff to make a new packet */
1698 struct sk_buff *skb;
1700 /* Note: packet_length adds 5 or 6 extra bytes here! */
1701 skb = dev_alloc_skb(packet_length+2);
1704 DEBUG(1, "%s: Low memory, packet dropped.\n", dev->name);
1705 smc->stats.rx_dropped++;
1706 outw(MC_RELEASE, ioaddr + MMU_CMD);
1710 packet_length -= (rx_status & RS_ODDFRAME ? 5 : 6);
1711 skb_reserve(skb, 2);
1712 insw(ioaddr+DATA_1, skb_put(skb, packet_length),
1713 (packet_length+1)>>1);
1714 skb->protocol = eth_type_trans(skb, dev);
1718 dev->last_rx = jiffies;
1719 smc->stats.rx_packets++;
1720 smc->stats.rx_bytes += packet_length;
1721 if (rx_status & RS_MULTICAST)
1722 smc->stats.multicast++;
1725 smc->stats.rx_errors++;
1727 if (rx_status & RS_ALGNERR) smc->stats.rx_frame_errors++;
1728 if (rx_status & (RS_TOOSHORT | RS_TOOLONG))
1729 smc->stats.rx_length_errors++;
1730 if (rx_status & RS_BADCRC) smc->stats.rx_crc_errors++;
1732 /* Let the MMU free the memory of this packet. */
1733 outw(MC_RELEASE, ioaddr + MMU_CMD);
1738 /*====================================================================*/
1740 static struct net_device_stats *smc_get_stats(struct net_device *dev)
1742 struct smc_private *smc = netdev_priv(dev);
1743 /* Nothing to update - the 91c92 is a pretty primative chip. */
1747 /*======================================================================
1749 Calculate values for the hardware multicast filter hash table.
1751 ======================================================================*/
1753 static void fill_multicast_tbl(int count, struct dev_mc_list *addrs,
1754 u_char *multicast_table)
1756 struct dev_mc_list *mc_addr;
1758 for (mc_addr = addrs; mc_addr && --count > 0; mc_addr = mc_addr->next) {
1759 u_int position = ether_crc(6, mc_addr->dmi_addr);
1760 #ifndef final_version /* Verify multicast address. */
1761 if ((mc_addr->dmi_addr[0] & 1) == 0)
1764 multicast_table[position >> 29] |= 1 << ((position >> 26) & 7);
1768 /*======================================================================
1770 Set the receive mode.
1772 This routine is used by both the protocol level to notify us of
1773 promiscuous/multicast mode changes, and by the open/reset code to
1774 initialize the Rx registers. We always set the multicast list and
1775 leave the receiver running.
1777 ======================================================================*/
1779 static void set_rx_mode(struct net_device *dev)
1781 ioaddr_t ioaddr = dev->base_addr;
1782 struct smc_private *smc = netdev_priv(dev);
1783 u_int multicast_table[ 2 ] = { 0, };
1784 unsigned long flags;
1785 u_short rx_cfg_setting;
1787 if (dev->flags & IFF_PROMISC) {
1788 printk(KERN_NOTICE "%s: setting Rx mode to promiscuous.\n", dev->name);
1789 rx_cfg_setting = RxStripCRC | RxEnable | RxPromisc | RxAllMulti;
1790 } else if (dev->flags & IFF_ALLMULTI)
1791 rx_cfg_setting = RxStripCRC | RxEnable | RxAllMulti;
1793 if (dev->mc_count) {
1794 fill_multicast_tbl(dev->mc_count, dev->mc_list,
1795 (u_char *)multicast_table);
1797 rx_cfg_setting = RxStripCRC | RxEnable;
1800 /* Load MC table and Rx setting into the chip without interrupts. */
1801 spin_lock_irqsave(&smc->lock, flags);
1803 outl(multicast_table[0], ioaddr + MULTICAST0);
1804 outl(multicast_table[1], ioaddr + MULTICAST4);
1806 outw(rx_cfg_setting, ioaddr + RCR);
1808 spin_unlock_irqrestore(&smc->lock, flags);
1813 /*======================================================================
1815 Senses when a card's config changes. Here, it's coax or TP.
1817 ======================================================================*/
1819 static int s9k_config(struct net_device *dev, struct ifmap *map)
1821 struct smc_private *smc = netdev_priv(dev);
1822 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
1823 if (smc->cfg & CFG_MII_SELECT)
1825 else if (map->port > 2)
1827 dev->if_port = map->port;
1828 printk(KERN_INFO "%s: switched to %s port\n",
1829 dev->name, if_names[dev->if_port]);
1835 /*======================================================================
1837 Reset the chip, reloading every register that might be corrupted.
1839 ======================================================================*/
1842 Set transceiver type, perhaps to something other than what the user
1843 specified in dev->if_port.
1845 static void smc_set_xcvr(struct net_device *dev, int if_port)
1847 struct smc_private *smc = netdev_priv(dev);
1848 ioaddr_t ioaddr = dev->base_addr;
1851 saved_bank = inw(ioaddr + BANK_SELECT);
1854 outw(smc->cfg | CFG_AUI_SELECT, ioaddr + CONFIG);
1855 if ((smc->manfid == MANFID_OSITECH) &&
1856 (smc->cardid != PRODID_OSITECH_SEVEN))
1857 set_bits(OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1858 smc->media_status = ((dev->if_port == 0) ? 0x0001 : 0x0002);
1860 outw(smc->cfg, ioaddr + CONFIG);
1861 if ((smc->manfid == MANFID_OSITECH) &&
1862 (smc->cardid != PRODID_OSITECH_SEVEN))
1863 mask_bits(~OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1864 smc->media_status = ((dev->if_port == 0) ? 0x0012 : 0x4001);
1866 SMC_SELECT_BANK(saved_bank);
1869 static void smc_reset(struct net_device *dev)
1871 ioaddr_t ioaddr = dev->base_addr;
1872 struct smc_private *smc = netdev_priv(dev);
1875 DEBUG(0, "%s: smc91c92 reset called.\n", dev->name);
1877 /* The first interaction must be a write to bring the chip out
1880 /* Reset the chip. */
1881 outw(RCR_SOFTRESET, ioaddr + RCR);
1884 /* Clear the transmit and receive configuration registers. */
1885 outw(RCR_CLEAR, ioaddr + RCR);
1886 outw(TCR_CLEAR, ioaddr + TCR);
1888 /* Set the Window 1 control, configuration and station addr registers.
1889 No point in writing the I/O base register ;-> */
1891 /* Automatically release succesfully transmitted packets,
1892 Accept link errors, counter and Tx error interrupts. */
1893 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1895 smc_set_xcvr(dev, dev->if_port);
1896 if ((smc->manfid == MANFID_OSITECH) &&
1897 (smc->cardid != PRODID_OSITECH_SEVEN))
1898 outw((dev->if_port == 2 ? OSI_AUI_PWR : 0) |
1899 (inw(ioaddr-0x10+OSITECH_AUI_PWR) & 0xff00),
1900 ioaddr - 0x10 + OSITECH_AUI_PWR);
1902 /* Fill in the physical address. The databook is wrong about the order! */
1903 for (i = 0; i < 6; i += 2)
1904 outw((dev->dev_addr[i+1]<<8)+dev->dev_addr[i],
1905 ioaddr + ADDR0 + i);
1909 outw(MC_RESET, ioaddr + MMU_CMD);
1910 outw(0, ioaddr + INTERRUPT);
1912 /* Re-enable the chip. */
1914 outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) |
1915 TCR_ENABLE | TCR_PAD_EN | smc->duplex, ioaddr + TCR);
1918 if (smc->cfg & CFG_MII_SELECT) {
1922 mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000);
1924 /* Advertise 100F, 100H, 10F, 10H */
1925 mdio_write(dev, smc->mii_if.phy_id, 4, 0x01e1);
1927 /* Restart MII autonegotiation */
1928 mdio_write(dev, smc->mii_if.phy_id, 0, 0x0000);
1929 mdio_write(dev, smc->mii_if.phy_id, 0, 0x1200);
1932 /* Enable interrupts. */
1934 outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,
1935 ioaddr + INTERRUPT);
1938 /*======================================================================
1940 Media selection timer routine
1942 ======================================================================*/
1944 static void media_check(u_long arg)
1946 struct net_device *dev = (struct net_device *) arg;
1947 struct smc_private *smc = netdev_priv(dev);
1948 ioaddr_t ioaddr = dev->base_addr;
1949 u_short i, media, saved_bank;
1952 saved_bank = inw(ioaddr + BANK_SELECT);
1954 if (!netif_device_present(dev))
1959 /* need MC_RESET to keep the memory consistent. errata? */
1961 outw(MC_RESET, ioaddr + MMU_CMD);
1964 i = inw(ioaddr + INTERRUPT);
1966 media = inw(ioaddr + EPH) & EPH_LINK_OK;
1968 media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1;
1970 /* Check for pending interrupt with watchdog flag set: with
1971 this, we can limp along even if the interrupt is blocked */
1972 if (smc->watchdog++ && ((i>>8) & i)) {
1973 if (!smc->fast_poll)
1974 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
1975 smc_interrupt(dev->irq, smc, NULL);
1976 smc->fast_poll = HZ;
1978 if (smc->fast_poll) {
1980 smc->media.expires = jiffies + HZ/100;
1981 add_timer(&smc->media);
1982 SMC_SELECT_BANK(saved_bank);
1986 if (smc->cfg & CFG_MII_SELECT) {
1987 if (smc->mii_if.phy_id < 0)
1991 link = mdio_read(dev, smc->mii_if.phy_id, 1);
1992 if (!link || (link == 0xffff)) {
1993 printk(KERN_INFO "%s: MII is missing!\n", dev->name);
1994 smc->mii_if.phy_id = -1;
1999 if (link != smc->link_status) {
2000 u_short p = mdio_read(dev, smc->mii_if.phy_id, 5);
2001 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2002 (link) ? "found" : "lost");
2003 smc->duplex = (((p & 0x0100) || ((p & 0x1c0) == 0x40))
2006 printk(KERN_INFO "%s: autonegotiation complete: "
2007 "%sbaseT-%cD selected\n", dev->name,
2008 ((p & 0x0180) ? "100" : "10"),
2009 (smc->duplex ? 'F' : 'H'));
2012 outw(inw(ioaddr + TCR) | smc->duplex, ioaddr + TCR);
2013 smc->link_status = link;
2018 /* Ignore collisions unless we've had no rx's recently */
2019 if (jiffies - dev->last_rx > HZ) {
2020 if (smc->tx_err || (smc->media_status & EPH_16COL))
2025 if (media != smc->media_status) {
2026 if ((media & smc->media_status & 1) &&
2027 ((smc->media_status ^ media) & EPH_LINK_OK))
2028 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2029 (smc->media_status & EPH_LINK_OK ? "lost" : "found"));
2030 else if ((media & smc->media_status & 2) &&
2031 ((smc->media_status ^ media) & EPH_16COL))
2032 printk(KERN_INFO "%s: coax cable %s\n", dev->name,
2033 (media & EPH_16COL ? "problem" : "ok"));
2034 if (dev->if_port == 0) {
2036 if (media & EPH_LINK_OK)
2037 printk(KERN_INFO "%s: flipped to 10baseT\n",
2040 smc_set_xcvr(dev, 2);
2042 if (media & EPH_16COL)
2043 smc_set_xcvr(dev, 1);
2045 printk(KERN_INFO "%s: flipped to 10base2\n",
2049 smc->media_status = media;
2053 smc->media.expires = jiffies + HZ;
2054 add_timer(&smc->media);
2055 SMC_SELECT_BANK(saved_bank);
2058 static int smc_link_ok(struct net_device *dev)
2060 ioaddr_t ioaddr = dev->base_addr;
2061 struct smc_private *smc = netdev_priv(dev);
2063 if (smc->cfg & CFG_MII_SELECT) {
2064 return mii_link_ok(&smc->mii_if);
2067 return inw(ioaddr + EPH) & EPH_LINK_OK;
2071 static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2074 ioaddr_t ioaddr = dev->base_addr;
2076 ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |
2077 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);
2080 tmp = inw(ioaddr + CONFIG);
2081 ecmd->port = (tmp & CFG_AUI_SELECT) ? PORT_AUI : PORT_TP;
2082 ecmd->transceiver = XCVR_INTERNAL;
2083 ecmd->speed = SPEED_10;
2084 ecmd->phy_address = ioaddr + MGMT;
2087 tmp = inw(ioaddr + TCR);
2088 ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF;
2093 static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2096 ioaddr_t ioaddr = dev->base_addr;
2098 if (ecmd->speed != SPEED_10)
2100 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
2102 if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI)
2104 if (ecmd->transceiver != XCVR_INTERNAL)
2107 if (ecmd->port == PORT_AUI)
2108 smc_set_xcvr(dev, 1);
2110 smc_set_xcvr(dev, 0);
2113 tmp = inw(ioaddr + TCR);
2114 if (ecmd->duplex == DUPLEX_FULL)
2118 outw(tmp, ioaddr + TCR);
2123 static int check_if_running(struct net_device *dev)
2125 if (!netif_running(dev))
2130 static void smc_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2132 strcpy(info->driver, DRV_NAME);
2133 strcpy(info->version, DRV_VERSION);
2136 static int smc_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2138 struct smc_private *smc = netdev_priv(dev);
2139 ioaddr_t ioaddr = dev->base_addr;
2140 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2144 spin_lock_irq(&smc->lock);
2145 if (smc->cfg & CFG_MII_SELECT)
2146 ret = mii_ethtool_gset(&smc->mii_if, ecmd);
2148 ret = smc_netdev_get_ecmd(dev, ecmd);
2149 spin_unlock_irq(&smc->lock);
2150 SMC_SELECT_BANK(saved_bank);
2154 static int smc_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2156 struct smc_private *smc = netdev_priv(dev);
2157 ioaddr_t ioaddr = dev->base_addr;
2158 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2162 spin_lock_irq(&smc->lock);
2163 if (smc->cfg & CFG_MII_SELECT)
2164 ret = mii_ethtool_sset(&smc->mii_if, ecmd);
2166 ret = smc_netdev_set_ecmd(dev, ecmd);
2167 spin_unlock_irq(&smc->lock);
2168 SMC_SELECT_BANK(saved_bank);
2172 static u32 smc_get_link(struct net_device *dev)
2174 struct smc_private *smc = netdev_priv(dev);
2175 ioaddr_t ioaddr = dev->base_addr;
2176 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2180 spin_lock_irq(&smc->lock);
2181 ret = smc_link_ok(dev);
2182 spin_unlock_irq(&smc->lock);
2183 SMC_SELECT_BANK(saved_bank);
2188 static u32 smc_get_msglevel(struct net_device *dev)
2193 static void smc_set_msglevel(struct net_device *dev, u32 val)
2199 static int smc_nway_reset(struct net_device *dev)
2201 struct smc_private *smc = netdev_priv(dev);
2202 if (smc->cfg & CFG_MII_SELECT) {
2203 ioaddr_t ioaddr = dev->base_addr;
2204 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2208 res = mii_nway_restart(&smc->mii_if);
2209 SMC_SELECT_BANK(saved_bank);
2216 static struct ethtool_ops ethtool_ops = {
2217 .begin = check_if_running,
2218 .get_drvinfo = smc_get_drvinfo,
2219 .get_settings = smc_get_settings,
2220 .set_settings = smc_set_settings,
2221 .get_link = smc_get_link,
2223 .get_msglevel = smc_get_msglevel,
2224 .set_msglevel = smc_set_msglevel,
2226 .nway_reset = smc_nway_reset,
2229 static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
2231 struct smc_private *smc = netdev_priv(dev);
2232 struct mii_ioctl_data *mii = if_mii(rq);
2235 ioaddr_t ioaddr = dev->base_addr;
2237 if (!netif_running(dev))
2240 spin_lock_irq(&smc->lock);
2241 saved_bank = inw(ioaddr + BANK_SELECT);
2243 rc = generic_mii_ioctl(&smc->mii_if, mii, cmd, NULL);
2244 SMC_SELECT_BANK(saved_bank);
2245 spin_unlock_irq(&smc->lock);
2249 static struct pcmcia_driver smc91c92_cs_driver = {
2250 .owner = THIS_MODULE,
2252 .name = "smc91c92_cs",
2254 .attach = smc91c92_attach,
2255 .detach = smc91c92_detach,
2258 static int __init init_smc91c92_cs(void)
2260 return pcmcia_register_driver(&smc91c92_cs_driver);
2263 static void __exit exit_smc91c92_cs(void)
2265 pcmcia_unregister_driver(&smc91c92_cs_driver);
2266 while (dev_list != NULL)
2267 smc91c92_detach(dev_list);
2270 module_init(init_smc91c92_cs);
2271 module_exit(exit_smc91c92_cs);