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);
308 /*======================================================================
310 smc91c92_attach() creates an "instance" of the driver, allocating
311 local data structures for one device. The device is registered
314 ======================================================================*/
316 static dev_link_t *smc91c92_attach(void)
318 client_reg_t client_reg;
319 struct smc_private *smc;
321 struct net_device *dev;
324 DEBUG(0, "smc91c92_attach()\n");
326 /* Create new ethernet device */
327 dev = alloc_etherdev(sizeof(struct smc_private));
330 smc = netdev_priv(dev);
334 spin_lock_init(&smc->lock);
335 link->io.NumPorts1 = 16;
336 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
337 link->io.IOAddrLines = 4;
338 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
339 link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
340 if (irq_list[0] == -1)
341 link->irq.IRQInfo2 = irq_mask;
343 for (i = 0; i < 4; i++)
344 link->irq.IRQInfo2 |= 1 << irq_list[i];
345 link->irq.Handler = &smc_interrupt;
346 link->irq.Instance = dev;
347 link->conf.Attributes = CONF_ENABLE_IRQ;
349 link->conf.IntType = INT_MEMORY_AND_IO;
351 /* The SMC91c92-specific entries in the device structure. */
352 SET_MODULE_OWNER(dev);
353 dev->hard_start_xmit = &smc_start_xmit;
354 dev->get_stats = &smc_get_stats;
355 dev->set_config = &s9k_config;
356 dev->set_multicast_list = &set_rx_mode;
357 dev->open = &smc_open;
358 dev->stop = &smc_close;
359 dev->do_ioctl = &smc_ioctl;
360 #ifdef HAVE_TX_TIMEOUT
361 dev->tx_timeout = smc_tx_timeout;
362 dev->watchdog_timeo = TX_TIMEOUT;
365 smc->mii_if.dev = dev;
366 smc->mii_if.mdio_read = mdio_read;
367 smc->mii_if.mdio_write = mdio_write;
368 smc->mii_if.phy_id_mask = 0x1f;
369 smc->mii_if.reg_num_mask = 0x1f;
371 /* Register with Card Services */
372 link->next = dev_list;
374 client_reg.dev_info = &dev_info;
375 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
376 client_reg.EventMask = CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
377 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
378 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
379 client_reg.event_handler = &smc91c92_event;
380 client_reg.Version = 0x0210;
381 client_reg.event_callback_args.client_data = link;
382 ret = pcmcia_register_client(&link->handle, &client_reg);
384 cs_error(link->handle, RegisterClient, ret);
385 smc91c92_detach(link);
390 } /* smc91c92_attach */
392 /*======================================================================
394 This deletes a driver "instance". The device is de-registered
395 with Card Services. If it has been released, all local data
396 structures are freed. Otherwise, the structures will be freed
397 when the device is released.
399 ======================================================================*/
401 static void smc91c92_detach(dev_link_t *link)
403 struct net_device *dev = link->priv;
406 DEBUG(0, "smc91c92_detach(0x%p)\n", link);
408 /* Locate device structure */
409 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
410 if (*linkp == link) break;
415 unregister_netdev(dev);
417 if (link->state & DEV_CONFIG)
418 smc91c92_release(link);
421 pcmcia_deregister_client(link->handle);
423 /* Unlink device structure, free bits */
426 } /* smc91c92_detach */
428 /*====================================================================*/
430 static int cvt_ascii_address(struct net_device *dev, char *s)
436 for (i = 0; i < 6; i++) {
438 for (j = 0; j < 2; j++) {
441 da += ((c >= '0') && (c <= '9')) ?
442 (c - '0') : ((c & 0x0f) + 9);
444 dev->dev_addr[i] = da;
449 /*====================================================================*/
451 static int first_tuple(client_handle_t handle, tuple_t *tuple,
456 if ((i = pcmcia_get_first_tuple(handle, tuple)) != CS_SUCCESS ||
457 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
459 return pcmcia_parse_tuple(handle, tuple, parse);
462 static int next_tuple(client_handle_t handle, tuple_t *tuple,
467 if ((i = pcmcia_get_next_tuple(handle, tuple)) != CS_SUCCESS ||
468 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
470 return pcmcia_parse_tuple(handle, tuple, parse);
473 /*======================================================================
475 Configuration stuff for Megahertz cards
477 mhz_3288_power() is used to power up a 3288's ethernet chip.
478 mhz_mfc_config() handles socket setup for multifunction (1144
479 and 3288) cards. mhz_setup() gets a card's hardware ethernet
482 ======================================================================*/
484 static int mhz_3288_power(dev_link_t *link)
486 struct net_device *dev = link->priv;
487 struct smc_private *smc = netdev_priv(dev);
490 /* Read the ISR twice... */
491 readb(smc->base+MEGAHERTZ_ISR);
493 readb(smc->base+MEGAHERTZ_ISR);
498 /* Now read and write the COR... */
499 tmp = readb(smc->base + link->conf.ConfigBase + CISREG_COR);
501 writeb(tmp, smc->base + link->conf.ConfigBase + CISREG_COR);
506 static int mhz_mfc_config(dev_link_t *link)
508 struct net_device *dev = link->priv;
509 struct smc_private *smc = netdev_priv(dev);
513 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
518 link->conf.Attributes |= CONF_ENABLE_SPKR;
519 link->conf.Status = CCSR_AUDIO_ENA;
520 link->irq.Attributes =
521 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
522 link->io.IOAddrLines = 16;
523 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
524 link->io.NumPorts2 = 8;
526 tuple.Attributes = tuple.TupleOffset = 0;
527 tuple.TupleData = (cisdata_t *)buf;
528 tuple.TupleDataMax = sizeof(buf);
529 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
531 i = first_tuple(link->handle, &tuple, &parse);
532 /* The Megahertz combo cards have modem-like CIS entries, so
533 we have to explicitly try a bunch of port combinations. */
534 while (i == CS_SUCCESS) {
535 link->conf.ConfigIndex = cf->index;
536 link->io.BasePort2 = cf->io.win[0].base;
537 for (k = 0; k < 0x400; k += 0x10) {
538 if (k & 0x80) continue;
539 link->io.BasePort1 = k ^ 0x300;
540 i = pcmcia_request_io(link->handle, &link->io);
541 if (i == CS_SUCCESS) break;
543 if (i == CS_SUCCESS) break;
544 i = next_tuple(link->handle, &tuple, &parse);
548 dev->base_addr = link->io.BasePort1;
550 /* Allocate a memory window, for accessing the ISR */
551 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
552 req.Base = req.Size = 0;
554 i = pcmcia_request_window(&link->handle, &req, &link->win);
557 smc->base = ioremap(req.Base, req.Size);
558 mem.CardOffset = mem.Page = 0;
559 if (smc->manfid == MANFID_MOTOROLA)
560 mem.CardOffset = link->conf.ConfigBase;
561 i = pcmcia_map_mem_page(link->win, &mem);
563 if ((i == CS_SUCCESS)
564 && (smc->manfid == MANFID_MEGAHERTZ)
565 && (smc->cardid == PRODID_MEGAHERTZ_EM3288))
566 mhz_3288_power(link);
571 static int mhz_setup(dev_link_t *link)
573 client_handle_t handle = link->handle;
574 struct net_device *dev = link->priv;
577 u_char buf[255], *station_addr;
579 tuple.Attributes = tuple.TupleOffset = 0;
580 tuple.TupleData = buf;
581 tuple.TupleDataMax = sizeof(buf);
583 /* Read the station address from the CIS. It is stored as the last
584 (fourth) string in the Version 1 Version/ID tuple. */
585 tuple.DesiredTuple = CISTPL_VERS_1;
586 if (first_tuple(handle, &tuple, &parse) != CS_SUCCESS)
588 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
589 if (next_tuple(handle, &tuple, &parse) != CS_SUCCESS)
590 first_tuple(handle, &tuple, &parse);
591 if (parse.version_1.ns > 3) {
592 station_addr = parse.version_1.str + parse.version_1.ofs[3];
593 if (cvt_ascii_address(dev, station_addr) == 0)
597 /* Another possibility: for the EM3288, in a special tuple */
598 tuple.DesiredTuple = 0x81;
599 if (pcmcia_get_first_tuple(handle, &tuple) != CS_SUCCESS)
601 if (pcmcia_get_tuple_data(handle, &tuple) != CS_SUCCESS)
604 if (cvt_ascii_address(dev, buf) == 0)
610 /*======================================================================
612 Configuration stuff for the Motorola Mariner
614 mot_config() writes directly to the Mariner configuration
615 registers because the CIS is just bogus.
617 ======================================================================*/
619 static void mot_config(dev_link_t *link)
621 struct net_device *dev = link->priv;
622 struct smc_private *smc = netdev_priv(dev);
623 ioaddr_t ioaddr = dev->base_addr;
624 ioaddr_t iouart = link->io.BasePort2;
626 /* Set UART base address and force map with COR bit 1 */
627 writeb(iouart & 0xff, smc->base + MOT_UART + CISREG_IOBASE_0);
628 writeb((iouart >> 8) & 0xff, smc->base + MOT_UART + CISREG_IOBASE_1);
629 writeb(MOT_NORMAL, smc->base + MOT_UART + CISREG_COR);
631 /* Set SMC base address and force map with COR bit 1 */
632 writeb(ioaddr & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_0);
633 writeb((ioaddr >> 8) & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_1);
634 writeb(MOT_NORMAL, smc->base + MOT_LAN + CISREG_COR);
636 /* Wait for things to settle down */
640 static int mot_setup(dev_link_t *link)
642 struct net_device *dev = link->priv;
643 ioaddr_t ioaddr = dev->base_addr;
647 /* Read Ethernet address from Serial EEPROM */
649 for (i = 0; i < 3; i++) {
651 outw(MOT_EEPROM + i, ioaddr + POINTER);
653 outw((CTL_RELOAD | CTL_EE_SELECT), ioaddr + CONTROL);
655 for (loop = wait = 0; loop < 200; loop++) {
657 wait = ((CTL_RELOAD | CTL_STORE) & inw(ioaddr + CONTROL));
658 if (wait == 0) break;
664 addr = inw(ioaddr + GENERAL);
665 dev->dev_addr[2*i] = addr & 0xff;
666 dev->dev_addr[2*i+1] = (addr >> 8) & 0xff;
672 /*====================================================================*/
674 static int smc_config(dev_link_t *link)
676 struct net_device *dev = link->priv;
680 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
683 tuple.Attributes = tuple.TupleOffset = 0;
684 tuple.TupleData = (cisdata_t *)buf;
685 tuple.TupleDataMax = sizeof(buf);
686 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
688 link->io.NumPorts1 = 16;
689 i = first_tuple(link->handle, &tuple, &parse);
690 while (i != CS_NO_MORE_ITEMS) {
691 if (i == CS_SUCCESS) {
692 link->conf.ConfigIndex = cf->index;
693 link->io.BasePort1 = cf->io.win[0].base;
694 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
695 i = pcmcia_request_io(link->handle, &link->io);
696 if (i == CS_SUCCESS) break;
698 i = next_tuple(link->handle, &tuple, &parse);
701 dev->base_addr = link->io.BasePort1;
705 static int smc_setup(dev_link_t *link)
707 client_handle_t handle = link->handle;
708 struct net_device *dev = link->priv;
711 cistpl_lan_node_id_t *node_id;
712 u_char buf[255], *station_addr;
715 tuple.Attributes = tuple.TupleOffset = 0;
716 tuple.TupleData = buf;
717 tuple.TupleDataMax = sizeof(buf);
719 /* Check for a LAN function extension tuple */
720 tuple.DesiredTuple = CISTPL_FUNCE;
721 i = first_tuple(handle, &tuple, &parse);
722 while (i == CS_SUCCESS) {
723 if (parse.funce.type == CISTPL_FUNCE_LAN_NODE_ID)
725 i = next_tuple(handle, &tuple, &parse);
727 if (i == CS_SUCCESS) {
728 node_id = (cistpl_lan_node_id_t *)parse.funce.data;
729 if (node_id->nb == 6) {
730 for (i = 0; i < 6; i++)
731 dev->dev_addr[i] = node_id->id[i];
735 /* Try the third string in the Version 1 Version/ID tuple. */
736 tuple.DesiredTuple = CISTPL_VERS_1;
737 if (first_tuple(handle, &tuple, &parse) != CS_SUCCESS)
739 station_addr = parse.version_1.str + parse.version_1.ofs[2];
740 if (cvt_ascii_address(dev, station_addr) == 0)
746 /*====================================================================*/
748 static int osi_config(dev_link_t *link)
750 struct net_device *dev = link->priv;
751 static ioaddr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
754 link->conf.Attributes |= CONF_ENABLE_SPKR;
755 link->conf.Status = CCSR_AUDIO_ENA;
756 link->irq.Attributes =
757 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
758 link->io.NumPorts1 = 64;
759 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
760 link->io.NumPorts2 = 8;
761 link->io.IOAddrLines = 16;
763 /* Enable Hard Decode, LAN, Modem */
764 link->conf.ConfigIndex = 0x23;
766 for (i = j = 0; j < 4; j++) {
767 link->io.BasePort2 = com[j];
768 i = pcmcia_request_io(link->handle, &link->io);
769 if (i == CS_SUCCESS) break;
771 if (i != CS_SUCCESS) {
772 /* Fallback: turn off hard decode */
773 link->conf.ConfigIndex = 0x03;
774 link->io.NumPorts2 = 0;
775 i = pcmcia_request_io(link->handle, &link->io);
777 dev->base_addr = link->io.BasePort1 + 0x10;
781 static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid)
783 client_handle_t handle = link->handle;
784 struct net_device *dev = link->priv;
789 tuple.Attributes = TUPLE_RETURN_COMMON;
790 tuple.TupleData = buf;
791 tuple.TupleDataMax = sizeof(buf);
792 tuple.TupleOffset = 0;
794 /* Read the station address from tuple 0x90, subtuple 0x04 */
795 tuple.DesiredTuple = 0x90;
796 i = pcmcia_get_first_tuple(handle, &tuple);
797 while (i == CS_SUCCESS) {
798 i = pcmcia_get_tuple_data(handle, &tuple);
799 if ((i != CS_SUCCESS) || (buf[0] == 0x04))
801 i = pcmcia_get_next_tuple(handle, &tuple);
805 for (i = 0; i < 6; i++)
806 dev->dev_addr[i] = buf[i+2];
808 if (((manfid == MANFID_OSITECH) &&
809 (cardid == PRODID_OSITECH_SEVEN)) ||
810 ((manfid == MANFID_PSION) &&
811 (cardid == PRODID_PSION_NET100))) {
812 /* Download the Seven of Diamonds firmware */
813 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
814 outb(__Xilinx7OD[i], link->io.BasePort1+2);
817 } else if (manfid == MANFID_OSITECH) {
818 /* Make sure both functions are powered up */
819 set_bits(0x300, link->io.BasePort1 + OSITECH_AUI_PWR);
820 /* Now, turn on the interrupt for both card functions */
821 set_bits(0x300, link->io.BasePort1 + OSITECH_RESET_ISR);
822 DEBUG(2, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n",
823 inw(link->io.BasePort1 + OSITECH_AUI_PWR),
824 inw(link->io.BasePort1 + OSITECH_RESET_ISR));
830 /*======================================================================
832 This verifies that the chip is some SMC91cXX variant, and returns
833 the revision code if successful. Otherwise, it returns -ENODEV.
835 ======================================================================*/
837 static int check_sig(dev_link_t *link)
839 struct net_device *dev = link->priv;
840 ioaddr_t ioaddr = dev->base_addr;
845 if (inw(ioaddr + BANK_SELECT) >> 8 != 0x33) {
846 /* Try powering up the chip */
847 outw(0, ioaddr + CONTROL);
851 /* Try setting bus width */
852 width = (link->io.Attributes1 == IO_DATA_PATH_WIDTH_AUTO);
853 s = inb(ioaddr + CONFIG);
858 outb(s, ioaddr + CONFIG);
860 /* Check Base Address Register to make sure bus width is OK */
861 s = inw(ioaddr + BASE_ADDR);
862 if ((inw(ioaddr + BANK_SELECT) >> 8 == 0x33) &&
863 ((s >> 8) != (s & 0xff))) {
865 s = inw(ioaddr + REVISION);
870 event_callback_args_t args;
871 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n");
872 args.client_data = link;
873 smc91c92_event(CS_EVENT_RESET_PHYSICAL, 0, &args);
874 pcmcia_release_io(link->handle, &link->io);
875 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
876 pcmcia_request_io(link->handle, &link->io);
877 smc91c92_event(CS_EVENT_CARD_RESET, 0, &args);
878 return check_sig(link);
883 /*======================================================================
885 smc91c92_config() is scheduled to run after a CARD_INSERTION event
886 is received, to configure the PCMCIA socket, and to make the
887 ethernet device available to the system.
889 ======================================================================*/
891 #define CS_EXIT_TEST(ret, svc, label) \
892 if (ret != CS_SUCCESS) { cs_error(link->handle, svc, ret); goto label; }
894 static void smc91c92_config(dev_link_t *link)
896 client_handle_t handle = link->handle;
897 struct net_device *dev = link->priv;
898 struct smc_private *smc = netdev_priv(dev);
907 DEBUG(0, "smc91c92_config(0x%p)\n", link);
909 tuple.Attributes = tuple.TupleOffset = 0;
910 tuple.TupleData = (cisdata_t *)buf;
911 tuple.TupleDataMax = sizeof(buf);
913 tuple.DesiredTuple = CISTPL_CONFIG;
914 i = first_tuple(handle, &tuple, &parse);
915 CS_EXIT_TEST(i, ParseTuple, config_failed);
916 link->conf.ConfigBase = parse.config.base;
917 link->conf.Present = parse.config.rmask[0];
919 tuple.DesiredTuple = CISTPL_MANFID;
920 tuple.Attributes = TUPLE_RETURN_COMMON;
921 if (first_tuple(handle, &tuple, &parse) == CS_SUCCESS) {
922 smc->manfid = parse.manfid.manf;
923 smc->cardid = parse.manfid.card;
927 link->state |= DEV_CONFIG;
929 if ((smc->manfid == MANFID_OSITECH) &&
930 (smc->cardid != PRODID_OSITECH_SEVEN)) {
931 i = osi_config(link);
932 } else if ((smc->manfid == MANFID_MOTOROLA) ||
933 ((smc->manfid == MANFID_MEGAHERTZ) &&
934 ((smc->cardid == PRODID_MEGAHERTZ_VARIOUS) ||
935 (smc->cardid == PRODID_MEGAHERTZ_EM3288)))) {
936 i = mhz_mfc_config(link);
938 i = smc_config(link);
940 CS_EXIT_TEST(i, RequestIO, config_failed);
942 i = pcmcia_request_irq(link->handle, &link->irq);
943 CS_EXIT_TEST(i, RequestIRQ, config_failed);
944 i = pcmcia_request_configuration(link->handle, &link->conf);
945 CS_EXIT_TEST(i, RequestConfiguration, config_failed);
947 if (smc->manfid == MANFID_MOTOROLA)
950 dev->irq = link->irq.AssignedIRQ;
952 if ((if_port >= 0) && (if_port <= 2))
953 dev->if_port = if_port;
955 printk(KERN_NOTICE "smc91c92_cs: invalid if_port requested\n");
957 switch (smc->manfid) {
960 i = osi_setup(link, smc->manfid, smc->cardid); break;
962 case MANFID_NEW_MEDIA:
963 i = smc_setup(link); break;
964 case 0x128: /* For broken Megahertz cards */
965 case MANFID_MEGAHERTZ:
966 i = mhz_setup(link); break;
967 case MANFID_MOTOROLA:
968 default: /* get the hw address from EEPROM */
969 i = mot_setup(link); break;
973 printk(KERN_NOTICE "smc91c92_cs: Unable to find hardware address.\n");
980 rev = check_sig(link);
984 case 3: name = "92"; break;
985 case 4: name = ((rev & 15) >= 6) ? "96" : "94"; break;
986 case 5: name = "95"; break;
987 case 7: name = "100"; break;
988 case 8: name = "100-FD"; break;
989 case 9: name = "110"; break;
992 ioaddr = dev->base_addr;
996 mir = inw(ioaddr + MEMINFO) & 0xff;
997 if (mir == 0xff) mir++;
998 /* Get scale factor for memory size */
999 mcr = ((rev >> 4) > 3) ? inw(ioaddr + MEMCFG) : 0x0200;
1000 mir *= 128 * (1<<((mcr >> 9) & 7));
1002 smc->cfg = inw(ioaddr + CONFIG) & ~CFG_AUI_SELECT;
1003 smc->cfg |= CFG_NO_WAIT | CFG_16BIT | CFG_STATIC;
1004 if (smc->manfid == MANFID_OSITECH)
1005 smc->cfg |= CFG_IRQ_SEL_1 | CFG_IRQ_SEL_0;
1006 if ((rev >> 4) >= 7)
1007 smc->cfg |= CFG_MII_SELECT;
1011 if (smc->cfg & CFG_MII_SELECT) {
1014 for (i = 0; i < 32; i++) {
1015 j = mdio_read(dev, i, 1);
1016 if ((j != 0) && (j != 0xffff)) break;
1018 smc->mii_if.phy_id = (i < 32) ? i : -1;
1023 link->dev = &smc->node;
1024 link->state &= ~DEV_CONFIG_PENDING;
1026 if (register_netdev(dev) != 0) {
1027 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n");
1032 strcpy(smc->node.dev_name, dev->name);
1034 printk(KERN_INFO "%s: smc91c%s rev %d: io %#3lx, irq %d, "
1035 "hw_addr ", dev->name, name, (rev & 0x0f), dev->base_addr,
1037 for (i = 0; i < 6; i++)
1038 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
1042 printk(KERN_INFO " %lu byte", mir);
1044 printk(KERN_INFO " %lu kb", mir>>10);
1045 printk(" buffer, %s xcvr\n", (smc->cfg & CFG_MII_SELECT) ?
1046 "MII" : if_names[dev->if_port]);
1049 if (smc->cfg & CFG_MII_SELECT) {
1050 if (smc->mii_if.phy_id != -1) {
1051 DEBUG(0, " MII transceiver at index %d, status %x.\n",
1052 smc->mii_if.phy_id, j);
1054 printk(KERN_NOTICE " No MII transceivers found!\n");
1061 unregister_netdev(dev);
1062 config_failed: /* CS_EXIT_TEST() calls jump to here... */
1063 smc91c92_release(link);
1064 link->state &= ~DEV_CONFIG_PENDING;
1066 } /* smc91c92_config */
1068 /*======================================================================
1070 After a card is removed, smc91c92_release() will unregister the net
1071 device, and release the PCMCIA configuration. If the device is
1072 still open, this will be postponed until it is closed.
1074 ======================================================================*/
1076 static void smc91c92_release(dev_link_t *link)
1079 DEBUG(0, "smc91c92_release(0x%p)\n", link);
1081 pcmcia_release_configuration(link->handle);
1082 pcmcia_release_io(link->handle, &link->io);
1083 pcmcia_release_irq(link->handle, &link->irq);
1085 struct net_device *dev = link->priv;
1086 struct smc_private *smc = netdev_priv(dev);
1088 pcmcia_release_window(link->win);
1091 link->state &= ~DEV_CONFIG;
1094 /*======================================================================
1096 The card status event handler. Mostly, this schedules other
1097 stuff to run after an event is received. A CARD_REMOVAL event
1098 also sets some flags to discourage the net drivers from trying
1099 to talk to the card any more.
1101 ======================================================================*/
1103 static int smc91c92_event(event_t event, int priority,
1104 event_callback_args_t *args)
1106 dev_link_t *link = args->client_data;
1107 struct net_device *dev = link->priv;
1108 struct smc_private *smc = netdev_priv(dev);
1111 DEBUG(1, "smc91c92_event(0x%06x)\n", event);
1114 case CS_EVENT_CARD_REMOVAL:
1115 link->state &= ~DEV_PRESENT;
1116 if (link->state & DEV_CONFIG)
1117 netif_device_detach(dev);
1119 case CS_EVENT_CARD_INSERTION:
1120 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1121 smc91c92_config(link);
1123 case CS_EVENT_PM_SUSPEND:
1124 link->state |= DEV_SUSPEND;
1125 /* Fall through... */
1126 case CS_EVENT_RESET_PHYSICAL:
1127 if (link->state & DEV_CONFIG) {
1129 netif_device_detach(dev);
1130 pcmcia_release_configuration(link->handle);
1133 case CS_EVENT_PM_RESUME:
1134 link->state &= ~DEV_SUSPEND;
1135 /* Fall through... */
1136 case CS_EVENT_CARD_RESET:
1137 if (link->state & DEV_CONFIG) {
1138 if ((smc->manfid == MANFID_MEGAHERTZ) &&
1139 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
1140 mhz_3288_power(link);
1141 pcmcia_request_configuration(link->handle, &link->conf);
1142 if (smc->manfid == MANFID_MOTOROLA)
1144 if ((smc->manfid == MANFID_OSITECH) &&
1145 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1146 /* Power up the card and enable interrupts */
1147 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR);
1148 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR);
1150 if (((smc->manfid == MANFID_OSITECH) &&
1151 (smc->cardid == PRODID_OSITECH_SEVEN)) ||
1152 ((smc->manfid == MANFID_PSION) &&
1153 (smc->cardid == PRODID_PSION_NET100))) {
1154 /* Download the Seven of Diamonds firmware */
1155 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
1156 outb(__Xilinx7OD[i], link->io.BasePort1+2);
1162 netif_device_attach(dev);
1168 } /* smc91c92_event */
1170 /*======================================================================
1172 MII interface support for SMC91cXX based cards
1173 ======================================================================*/
1175 #define MDIO_SHIFT_CLK 0x04
1176 #define MDIO_DATA_OUT 0x01
1177 #define MDIO_DIR_WRITE 0x08
1178 #define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
1179 #define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
1180 #define MDIO_DATA_READ 0x02
1182 static void mdio_sync(ioaddr_t addr)
1185 for (bits = 0; bits < 32; bits++) {
1186 outb(MDIO_DATA_WRITE1, addr);
1187 outb(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
1191 static int mdio_read(struct net_device *dev, int phy_id, int loc)
1193 ioaddr_t addr = dev->base_addr + MGMT;
1194 u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
1198 for (i = 13; i >= 0; i--) {
1199 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1201 outb(dat | MDIO_SHIFT_CLK, addr);
1203 for (i = 19; i > 0; i--) {
1205 retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
1206 outb(MDIO_SHIFT_CLK, addr);
1208 return (retval>>1) & 0xffff;
1211 static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
1213 ioaddr_t addr = dev->base_addr + MGMT;
1214 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
1218 for (i = 31; i >= 0; i--) {
1219 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1221 outb(dat | MDIO_SHIFT_CLK, addr);
1223 for (i = 1; i >= 0; i--) {
1225 outb(MDIO_SHIFT_CLK, addr);
1229 /*======================================================================
1231 The driver core code, most of which should be common with a
1232 non-PCMCIA implementation.
1234 ======================================================================*/
1237 static void smc_dump(struct net_device *dev)
1239 ioaddr_t ioaddr = dev->base_addr;
1241 save = inw(ioaddr + BANK_SELECT);
1242 for (w = 0; w < 4; w++) {
1244 printk(KERN_DEBUG "bank %d: ", w);
1245 for (i = 0; i < 14; i += 2)
1246 printk(" %04x", inw(ioaddr + i));
1249 outw(save, ioaddr + BANK_SELECT);
1253 static int smc_open(struct net_device *dev)
1255 struct smc_private *smc = netdev_priv(dev);
1256 dev_link_t *link = &smc->link;
1259 DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n",
1260 dev->name, dev, inw(dev->base_addr + BANK_SELECT));
1261 if (pc_debug > 1) smc_dump(dev);
1264 /* Check that the PCMCIA card is still here. */
1267 /* Physical device present signature. */
1268 if (check_sig(link) < 0) {
1269 printk("smc91c92_cs: Yikes! Bad chip signature!\n");
1274 netif_start_queue(dev);
1275 smc->saved_skb = NULL;
1276 smc->packets_waiting = 0;
1279 init_timer(&smc->media);
1280 smc->media.function = &media_check;
1281 smc->media.data = (u_long) dev;
1282 smc->media.expires = jiffies + HZ;
1283 add_timer(&smc->media);
1288 /*====================================================================*/
1290 static int smc_close(struct net_device *dev)
1292 struct smc_private *smc = netdev_priv(dev);
1293 dev_link_t *link = &smc->link;
1294 ioaddr_t ioaddr = dev->base_addr;
1296 DEBUG(0, "%s: smc_close(), status %4.4x.\n",
1297 dev->name, inw(ioaddr + BANK_SELECT));
1299 netif_stop_queue(dev);
1301 /* Shut off all interrupts, and turn off the Tx and Rx sections.
1302 Don't bother to check for chip present. */
1303 SMC_SELECT_BANK(2); /* Nominally paranoia, but do no assume... */
1304 outw(0, ioaddr + INTERRUPT);
1306 mask_bits(0xff00, ioaddr + RCR);
1307 mask_bits(0xff00, ioaddr + TCR);
1309 /* Put the chip into power-down mode. */
1311 outw(CTL_POWERDOWN, ioaddr + CONTROL );
1314 del_timer_sync(&smc->media);
1319 /*======================================================================
1321 Transfer a packet to the hardware and trigger the packet send.
1322 This may be called at either from either the Tx queue code
1323 or the interrupt handler.
1325 ======================================================================*/
1327 static void smc_hardware_send_packet(struct net_device * dev)
1329 struct smc_private *smc = netdev_priv(dev);
1330 struct sk_buff *skb = smc->saved_skb;
1331 ioaddr_t ioaddr = dev->base_addr;
1335 printk(KERN_ERR "%s: In XMIT with no packet to send.\n", dev->name);
1339 /* There should be a packet slot waiting. */
1340 packet_no = inw(ioaddr + PNR_ARR) >> 8;
1341 if (packet_no & 0x80) {
1342 /* If not, there is a hardware problem! Likely an ejected card. */
1343 printk(KERN_WARNING "%s: 91c92 hardware Tx buffer allocation"
1344 " failed, status %#2.2x.\n", dev->name, packet_no);
1345 dev_kfree_skb_irq(skb);
1346 smc->saved_skb = NULL;
1347 netif_start_queue(dev);
1351 smc->stats.tx_bytes += skb->len;
1352 /* The card should use the just-allocated buffer. */
1353 outw(packet_no, ioaddr + PNR_ARR);
1354 /* point to the beginning of the packet */
1355 outw(PTR_AUTOINC , ioaddr + POINTER);
1357 /* Send the packet length (+6 for status, length and ctl byte)
1358 and the status word (set to zeros). */
1360 u_char *buf = skb->data;
1361 u_int length = skb->len; /* The chip will pad to ethernet min. */
1363 DEBUG(2, "%s: Trying to xmit packet of length %d.\n",
1366 /* send the packet length: +6 for status word, length, and ctl */
1367 outw(0, ioaddr + DATA_1);
1368 outw(length + 6, ioaddr + DATA_1);
1369 outsw(ioaddr + DATA_1, buf, length >> 1);
1371 /* The odd last byte, if there is one, goes in the control word. */
1372 outw((length & 1) ? 0x2000 | buf[length-1] : 0, ioaddr + DATA_1);
1375 /* Enable the Tx interrupts, both Tx (TxErr) and TxEmpty. */
1376 outw(((IM_TX_INT|IM_TX_EMPTY_INT)<<8) |
1377 (inw(ioaddr + INTERRUPT) & 0xff00),
1378 ioaddr + INTERRUPT);
1380 /* The chip does the rest of the work. */
1381 outw(MC_ENQUEUE , ioaddr + MMU_CMD);
1383 smc->saved_skb = NULL;
1384 dev_kfree_skb_irq(skb);
1385 dev->trans_start = jiffies;
1386 netif_start_queue(dev);
1390 /*====================================================================*/
1392 static void smc_tx_timeout(struct net_device *dev)
1394 struct smc_private *smc = netdev_priv(dev);
1395 ioaddr_t ioaddr = dev->base_addr;
1397 printk(KERN_NOTICE "%s: SMC91c92 transmit timed out, "
1398 "Tx_status %2.2x status %4.4x.\n",
1399 dev->name, inw(ioaddr)&0xff, inw(ioaddr + 2));
1400 smc->stats.tx_errors++;
1402 dev->trans_start = jiffies;
1403 smc->saved_skb = NULL;
1404 netif_wake_queue(dev);
1407 static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev)
1409 struct smc_private *smc = netdev_priv(dev);
1410 ioaddr_t ioaddr = dev->base_addr;
1414 netif_stop_queue(dev);
1416 DEBUG(2, "%s: smc_start_xmit(length = %d) called,"
1417 " status %4.4x.\n", dev->name, skb->len, inw(ioaddr + 2));
1419 if (smc->saved_skb) {
1420 /* THIS SHOULD NEVER HAPPEN. */
1421 smc->stats.tx_aborted_errors++;
1422 printk(KERN_DEBUG "%s: Internal error -- sent packet while busy.\n",
1426 smc->saved_skb = skb;
1428 num_pages = skb->len >> 8;
1430 if (num_pages > 7) {
1431 printk(KERN_ERR "%s: Far too big packet error.\n", dev->name);
1432 dev_kfree_skb (skb);
1433 smc->saved_skb = NULL;
1434 smc->stats.tx_dropped++;
1435 return 0; /* Do not re-queue this packet. */
1437 /* A packet is now waiting. */
1438 smc->packets_waiting++;
1440 SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */
1442 /* need MC_RESET to keep the memory consistent. errata? */
1444 outw(MC_RESET, ioaddr + MMU_CMD);
1448 /* Allocate the memory; send the packet now if we win. */
1449 outw(MC_ALLOC | num_pages, ioaddr + MMU_CMD);
1450 for (time_out = MEMORY_WAIT_TIME; time_out >= 0; time_out--) {
1451 ir = inw(ioaddr+INTERRUPT);
1452 if (ir & IM_ALLOC_INT) {
1453 /* Acknowledge the interrupt, send the packet. */
1454 outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT);
1455 smc_hardware_send_packet(dev); /* Send the packet now.. */
1460 /* Otherwise defer until the Tx-space-allocated interrupt. */
1461 DEBUG(2, "%s: memory allocation deferred.\n", dev->name);
1462 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT);
1467 /*======================================================================
1469 Handle a Tx anomolous event. Entered while in Window 2.
1471 ======================================================================*/
1473 static void smc_tx_err(struct net_device * dev)
1475 struct smc_private *smc = netdev_priv(dev);
1476 ioaddr_t ioaddr = dev->base_addr;
1477 int saved_packet = inw(ioaddr + PNR_ARR) & 0xff;
1478 int packet_no = inw(ioaddr + FIFO_PORTS) & 0x7f;
1481 /* select this as the packet to read from */
1482 outw(packet_no, ioaddr + PNR_ARR);
1484 /* read the first word from this packet */
1485 outw(PTR_AUTOINC | PTR_READ | 0, ioaddr + POINTER);
1487 tx_status = inw(ioaddr + DATA_1);
1489 smc->stats.tx_errors++;
1490 if (tx_status & TS_LOSTCAR) smc->stats.tx_carrier_errors++;
1491 if (tx_status & TS_LATCOL) smc->stats.tx_window_errors++;
1492 if (tx_status & TS_16COL) {
1493 smc->stats.tx_aborted_errors++;
1497 if (tx_status & TS_SUCCESS) {
1498 printk(KERN_NOTICE "%s: Successful packet caused error "
1499 "interrupt?\n", dev->name);
1501 /* re-enable transmit */
1503 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1506 outw(MC_FREEPKT, ioaddr + MMU_CMD); /* Free the packet memory. */
1508 /* one less packet waiting for me */
1509 smc->packets_waiting--;
1511 outw(saved_packet, ioaddr + PNR_ARR);
1515 /*====================================================================*/
1517 static void smc_eph_irq(struct net_device *dev)
1519 struct smc_private *smc = netdev_priv(dev);
1520 ioaddr_t ioaddr = dev->base_addr;
1521 u_short card_stats, ephs;
1524 ephs = inw(ioaddr + EPH);
1525 DEBUG(2, "%s: Ethernet protocol handler interrupt, status"
1526 " %4.4x.\n", dev->name, ephs);
1527 /* Could be a counter roll-over warning: update stats. */
1528 card_stats = inw(ioaddr + COUNTER);
1529 /* single collisions */
1530 smc->stats.collisions += card_stats & 0xF;
1532 /* multiple collisions */
1533 smc->stats.collisions += card_stats & 0xF;
1534 #if 0 /* These are for when linux supports these statistics */
1535 card_stats >>= 4; /* deferred */
1536 card_stats >>= 4; /* excess deferred */
1538 /* If we had a transmit error we must re-enable the transmitter. */
1539 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1541 /* Clear a link error interrupt. */
1543 outw(CTL_AUTO_RELEASE | 0x0000, ioaddr + CONTROL);
1544 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1549 /*====================================================================*/
1551 static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1553 struct net_device *dev = dev_id;
1554 struct smc_private *smc = netdev_priv(dev);
1556 u_short saved_bank, saved_pointer, mask, status;
1557 unsigned int handled = 1;
1558 char bogus_cnt = INTR_WORK; /* Work we are willing to do. */
1560 if (!netif_device_present(dev))
1563 ioaddr = dev->base_addr;
1565 DEBUG(3, "%s: SMC91c92 interrupt %d at %#x.\n", dev->name,
1569 saved_bank = inw(ioaddr + BANK_SELECT);
1570 if ((saved_bank & 0xff00) != 0x3300) {
1571 /* The device does not exist -- the card could be off-line, or
1572 maybe it has been ejected. */
1573 DEBUG(1, "%s: SMC91c92 interrupt %d for non-existent"
1574 "/ejected device.\n", dev->name, irq);
1580 saved_pointer = inw(ioaddr + POINTER);
1581 mask = inw(ioaddr + INTERRUPT) >> 8;
1582 /* clear all interrupts */
1583 outw(0, ioaddr + INTERRUPT);
1585 do { /* read the status flag, and mask it */
1586 status = inw(ioaddr + INTERRUPT) & 0xff;
1587 DEBUG(3, "%s: Status is %#2.2x (mask %#2.2x).\n", dev->name,
1589 if ((status & mask) == 0) {
1590 if (bogus_cnt == INTR_WORK)
1594 if (status & IM_RCV_INT) {
1595 /* Got a packet(s). */
1598 if (status & IM_TX_INT) {
1600 outw(IM_TX_INT, ioaddr + INTERRUPT);
1603 if (status & IM_TX_EMPTY_INT) {
1604 outw(IM_TX_EMPTY_INT, ioaddr + INTERRUPT);
1605 mask &= ~IM_TX_EMPTY_INT;
1606 smc->stats.tx_packets += smc->packets_waiting;
1607 smc->packets_waiting = 0;
1609 if (status & IM_ALLOC_INT) {
1610 /* Clear this interrupt so it doesn't happen again */
1611 mask &= ~IM_ALLOC_INT;
1613 smc_hardware_send_packet(dev);
1615 /* enable xmit interrupts based on this */
1616 mask |= (IM_TX_EMPTY_INT | IM_TX_INT);
1618 /* and let the card send more packets to me */
1619 netif_wake_queue(dev);
1621 if (status & IM_RX_OVRN_INT) {
1622 smc->stats.rx_errors++;
1623 smc->stats.rx_fifo_errors++;
1625 smc->rx_ovrn = 1; /* need MC_RESET outside smc_interrupt */
1626 outw(IM_RX_OVRN_INT, ioaddr + INTERRUPT);
1628 if (status & IM_EPH_INT)
1630 } while (--bogus_cnt);
1632 DEBUG(3, " Restoring saved registers mask %2.2x bank %4.4x"
1633 " pointer %4.4x.\n", mask, saved_bank, saved_pointer);
1635 /* restore state register */
1636 outw((mask<<8), ioaddr + INTERRUPT);
1637 outw(saved_pointer, ioaddr + POINTER);
1638 SMC_SELECT_BANK(saved_bank);
1640 DEBUG(3, "%s: Exiting interrupt IRQ%d.\n", dev->name, irq);
1644 if ((smc->manfid == MANFID_OSITECH) &&
1645 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1646 /* Retrigger interrupt if needed */
1647 mask_bits(0x00ff, ioaddr-0x10+OSITECH_RESET_ISR);
1648 set_bits(0x0300, ioaddr-0x10+OSITECH_RESET_ISR);
1650 if (smc->manfid == MANFID_MOTOROLA) {
1652 cor = readb(smc->base + MOT_UART + CISREG_COR);
1653 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_UART + CISREG_COR);
1654 writeb(cor, smc->base + MOT_UART + CISREG_COR);
1655 cor = readb(smc->base + MOT_LAN + CISREG_COR);
1656 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_LAN + CISREG_COR);
1657 writeb(cor, smc->base + MOT_LAN + CISREG_COR);
1659 #ifdef DOES_NOT_WORK
1660 if (smc->base != NULL) { /* Megahertz MFC's */
1661 readb(smc->base+MEGAHERTZ_ISR);
1662 readb(smc->base+MEGAHERTZ_ISR);
1665 return IRQ_RETVAL(handled);
1668 /*====================================================================*/
1670 static void smc_rx(struct net_device *dev)
1672 struct smc_private *smc = netdev_priv(dev);
1673 ioaddr_t ioaddr = dev->base_addr;
1675 int packet_length; /* Caution: not frame length, rather words
1676 to transfer from the chip. */
1678 /* Assertion: we are in Window 2. */
1680 if (inw(ioaddr + FIFO_PORTS) & FP_RXEMPTY) {
1681 printk(KERN_ERR "%s: smc_rx() with nothing on Rx FIFO.\n",
1686 /* Reset the read pointer, and read the status and packet length. */
1687 outw(PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER);
1688 rx_status = inw(ioaddr + DATA_1);
1689 packet_length = inw(ioaddr + DATA_1) & 0x07ff;
1691 DEBUG(2, "%s: Receive status %4.4x length %d.\n",
1692 dev->name, rx_status, packet_length);
1694 if (!(rx_status & RS_ERRORS)) {
1695 /* do stuff to make a new packet */
1696 struct sk_buff *skb;
1698 /* Note: packet_length adds 5 or 6 extra bytes here! */
1699 skb = dev_alloc_skb(packet_length+2);
1702 DEBUG(1, "%s: Low memory, packet dropped.\n", dev->name);
1703 smc->stats.rx_dropped++;
1704 outw(MC_RELEASE, ioaddr + MMU_CMD);
1708 packet_length -= (rx_status & RS_ODDFRAME ? 5 : 6);
1709 skb_reserve(skb, 2);
1710 insw(ioaddr+DATA_1, skb_put(skb, packet_length),
1711 (packet_length+1)>>1);
1712 skb->protocol = eth_type_trans(skb, dev);
1716 dev->last_rx = jiffies;
1717 smc->stats.rx_packets++;
1718 smc->stats.rx_bytes += packet_length;
1719 if (rx_status & RS_MULTICAST)
1720 smc->stats.multicast++;
1723 smc->stats.rx_errors++;
1725 if (rx_status & RS_ALGNERR) smc->stats.rx_frame_errors++;
1726 if (rx_status & (RS_TOOSHORT | RS_TOOLONG))
1727 smc->stats.rx_length_errors++;
1728 if (rx_status & RS_BADCRC) smc->stats.rx_crc_errors++;
1730 /* Let the MMU free the memory of this packet. */
1731 outw(MC_RELEASE, ioaddr + MMU_CMD);
1736 /*====================================================================*/
1738 static struct net_device_stats *smc_get_stats(struct net_device *dev)
1740 struct smc_private *smc = netdev_priv(dev);
1741 /* Nothing to update - the 91c92 is a pretty primative chip. */
1745 /*======================================================================
1747 Calculate values for the hardware multicast filter hash table.
1749 ======================================================================*/
1751 static void fill_multicast_tbl(int count, struct dev_mc_list *addrs,
1752 u_char *multicast_table)
1754 struct dev_mc_list *mc_addr;
1756 for (mc_addr = addrs; mc_addr && --count > 0; mc_addr = mc_addr->next) {
1757 u_int position = ether_crc(6, mc_addr->dmi_addr);
1758 #ifndef final_version /* Verify multicast address. */
1759 if ((mc_addr->dmi_addr[0] & 1) == 0)
1762 multicast_table[position >> 29] |= 1 << ((position >> 26) & 7);
1766 /*======================================================================
1768 Set the receive mode.
1770 This routine is used by both the protocol level to notify us of
1771 promiscuous/multicast mode changes, and by the open/reset code to
1772 initialize the Rx registers. We always set the multicast list and
1773 leave the receiver running.
1775 ======================================================================*/
1777 static void set_rx_mode(struct net_device *dev)
1779 ioaddr_t ioaddr = dev->base_addr;
1780 struct smc_private *smc = netdev_priv(dev);
1781 u_int multicast_table[ 2 ] = { 0, };
1782 unsigned long flags;
1783 u_short rx_cfg_setting;
1785 if (dev->flags & IFF_PROMISC) {
1786 printk(KERN_NOTICE "%s: setting Rx mode to promiscuous.\n", dev->name);
1787 rx_cfg_setting = RxStripCRC | RxEnable | RxPromisc | RxAllMulti;
1788 } else if (dev->flags & IFF_ALLMULTI)
1789 rx_cfg_setting = RxStripCRC | RxEnable | RxAllMulti;
1791 if (dev->mc_count) {
1792 fill_multicast_tbl(dev->mc_count, dev->mc_list,
1793 (u_char *)multicast_table);
1795 rx_cfg_setting = RxStripCRC | RxEnable;
1798 /* Load MC table and Rx setting into the chip without interrupts. */
1799 spin_lock_irqsave(&smc->lock, flags);
1801 outl(multicast_table[0], ioaddr + MULTICAST0);
1802 outl(multicast_table[1], ioaddr + MULTICAST4);
1804 outw(rx_cfg_setting, ioaddr + RCR);
1806 spin_unlock_irqrestore(&smc->lock, flags);
1811 /*======================================================================
1813 Senses when a card's config changes. Here, it's coax or TP.
1815 ======================================================================*/
1817 static int s9k_config(struct net_device *dev, struct ifmap *map)
1819 struct smc_private *smc = netdev_priv(dev);
1820 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
1821 if (smc->cfg & CFG_MII_SELECT)
1823 else if (map->port > 2)
1825 dev->if_port = map->port;
1826 printk(KERN_INFO "%s: switched to %s port\n",
1827 dev->name, if_names[dev->if_port]);
1833 /*======================================================================
1835 Reset the chip, reloading every register that might be corrupted.
1837 ======================================================================*/
1840 Set transceiver type, perhaps to something other than what the user
1841 specified in dev->if_port.
1843 static void smc_set_xcvr(struct net_device *dev, int if_port)
1845 struct smc_private *smc = netdev_priv(dev);
1846 ioaddr_t ioaddr = dev->base_addr;
1849 saved_bank = inw(ioaddr + BANK_SELECT);
1852 outw(smc->cfg | CFG_AUI_SELECT, ioaddr + CONFIG);
1853 if ((smc->manfid == MANFID_OSITECH) &&
1854 (smc->cardid != PRODID_OSITECH_SEVEN))
1855 set_bits(OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1856 smc->media_status = ((dev->if_port == 0) ? 0x0001 : 0x0002);
1858 outw(smc->cfg, ioaddr + CONFIG);
1859 if ((smc->manfid == MANFID_OSITECH) &&
1860 (smc->cardid != PRODID_OSITECH_SEVEN))
1861 mask_bits(~OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1862 smc->media_status = ((dev->if_port == 0) ? 0x0012 : 0x4001);
1864 SMC_SELECT_BANK(saved_bank);
1867 static void smc_reset(struct net_device *dev)
1869 ioaddr_t ioaddr = dev->base_addr;
1870 struct smc_private *smc = netdev_priv(dev);
1873 DEBUG(0, "%s: smc91c92 reset called.\n", dev->name);
1875 /* The first interaction must be a write to bring the chip out
1878 /* Reset the chip. */
1879 outw(RCR_SOFTRESET, ioaddr + RCR);
1882 /* Clear the transmit and receive configuration registers. */
1883 outw(RCR_CLEAR, ioaddr + RCR);
1884 outw(TCR_CLEAR, ioaddr + TCR);
1886 /* Set the Window 1 control, configuration and station addr registers.
1887 No point in writing the I/O base register ;-> */
1889 /* Automatically release succesfully transmitted packets,
1890 Accept link errors, counter and Tx error interrupts. */
1891 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1893 smc_set_xcvr(dev, dev->if_port);
1894 if ((smc->manfid == MANFID_OSITECH) &&
1895 (smc->cardid != PRODID_OSITECH_SEVEN))
1896 outw((dev->if_port == 2 ? OSI_AUI_PWR : 0) |
1897 (inw(ioaddr-0x10+OSITECH_AUI_PWR) & 0xff00),
1898 ioaddr - 0x10 + OSITECH_AUI_PWR);
1900 /* Fill in the physical address. The databook is wrong about the order! */
1901 for (i = 0; i < 6; i += 2)
1902 outw((dev->dev_addr[i+1]<<8)+dev->dev_addr[i],
1903 ioaddr + ADDR0 + i);
1907 outw(MC_RESET, ioaddr + MMU_CMD);
1908 outw(0, ioaddr + INTERRUPT);
1910 /* Re-enable the chip. */
1912 outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) |
1913 TCR_ENABLE | TCR_PAD_EN | smc->duplex, ioaddr + TCR);
1916 if (smc->cfg & CFG_MII_SELECT) {
1920 mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000);
1922 /* Advertise 100F, 100H, 10F, 10H */
1923 mdio_write(dev, smc->mii_if.phy_id, 4, 0x01e1);
1925 /* Restart MII autonegotiation */
1926 mdio_write(dev, smc->mii_if.phy_id, 0, 0x0000);
1927 mdio_write(dev, smc->mii_if.phy_id, 0, 0x1200);
1930 /* Enable interrupts. */
1932 outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,
1933 ioaddr + INTERRUPT);
1936 /*======================================================================
1938 Media selection timer routine
1940 ======================================================================*/
1942 static void media_check(u_long arg)
1944 struct net_device *dev = (struct net_device *) arg;
1945 struct smc_private *smc = netdev_priv(dev);
1946 ioaddr_t ioaddr = dev->base_addr;
1947 u_short i, media, saved_bank;
1950 saved_bank = inw(ioaddr + BANK_SELECT);
1952 if (!netif_device_present(dev))
1957 /* need MC_RESET to keep the memory consistent. errata? */
1959 outw(MC_RESET, ioaddr + MMU_CMD);
1962 i = inw(ioaddr + INTERRUPT);
1964 media = inw(ioaddr + EPH) & EPH_LINK_OK;
1966 media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1;
1968 /* Check for pending interrupt with watchdog flag set: with
1969 this, we can limp along even if the interrupt is blocked */
1970 if (smc->watchdog++ && ((i>>8) & i)) {
1971 if (!smc->fast_poll)
1972 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
1973 smc_interrupt(dev->irq, smc, NULL);
1974 smc->fast_poll = HZ;
1976 if (smc->fast_poll) {
1978 smc->media.expires = jiffies + HZ/100;
1979 add_timer(&smc->media);
1980 SMC_SELECT_BANK(saved_bank);
1984 if (smc->cfg & CFG_MII_SELECT) {
1985 if (smc->mii_if.phy_id < 0)
1989 link = mdio_read(dev, smc->mii_if.phy_id, 1);
1990 if (!link || (link == 0xffff)) {
1991 printk(KERN_INFO "%s: MII is missing!\n", dev->name);
1992 smc->mii_if.phy_id = -1;
1997 if (link != smc->link_status) {
1998 u_short p = mdio_read(dev, smc->mii_if.phy_id, 5);
1999 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2000 (link) ? "found" : "lost");
2001 smc->duplex = (((p & 0x0100) || ((p & 0x1c0) == 0x40))
2004 printk(KERN_INFO "%s: autonegotiation complete: "
2005 "%sbaseT-%cD selected\n", dev->name,
2006 ((p & 0x0180) ? "100" : "10"),
2007 (smc->duplex ? 'F' : 'H'));
2010 outw(inw(ioaddr + TCR) | smc->duplex, ioaddr + TCR);
2011 smc->link_status = link;
2016 /* Ignore collisions unless we've had no rx's recently */
2017 if (jiffies - dev->last_rx > HZ) {
2018 if (smc->tx_err || (smc->media_status & EPH_16COL))
2023 if (media != smc->media_status) {
2024 if ((media & smc->media_status & 1) &&
2025 ((smc->media_status ^ media) & EPH_LINK_OK))
2026 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2027 (smc->media_status & EPH_LINK_OK ? "lost" : "found"));
2028 else if ((media & smc->media_status & 2) &&
2029 ((smc->media_status ^ media) & EPH_16COL))
2030 printk(KERN_INFO "%s: coax cable %s\n", dev->name,
2031 (media & EPH_16COL ? "problem" : "ok"));
2032 if (dev->if_port == 0) {
2034 if (media & EPH_LINK_OK)
2035 printk(KERN_INFO "%s: flipped to 10baseT\n",
2038 smc_set_xcvr(dev, 2);
2040 if (media & EPH_16COL)
2041 smc_set_xcvr(dev, 1);
2043 printk(KERN_INFO "%s: flipped to 10base2\n",
2047 smc->media_status = media;
2051 smc->media.expires = jiffies + HZ;
2052 add_timer(&smc->media);
2053 SMC_SELECT_BANK(saved_bank);
2056 static int smc_link_ok(struct net_device *dev)
2058 ioaddr_t ioaddr = dev->base_addr;
2059 struct smc_private *smc = netdev_priv(dev);
2061 if (smc->cfg & CFG_MII_SELECT) {
2062 return mii_link_ok(&smc->mii_if);
2065 return inw(ioaddr + EPH) & EPH_LINK_OK;
2069 static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2072 ioaddr_t ioaddr = dev->base_addr;
2074 ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |
2075 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);
2078 tmp = inw(ioaddr + CONFIG);
2079 ecmd->port = (tmp & CFG_AUI_SELECT) ? PORT_AUI : PORT_TP;
2080 ecmd->transceiver = XCVR_INTERNAL;
2081 ecmd->speed = SPEED_10;
2082 ecmd->phy_address = ioaddr + MGMT;
2085 tmp = inw(ioaddr + TCR);
2086 ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF;
2091 static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2094 ioaddr_t ioaddr = dev->base_addr;
2096 if (ecmd->speed != SPEED_10)
2098 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
2100 if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI)
2102 if (ecmd->transceiver != XCVR_INTERNAL)
2105 if (ecmd->port == PORT_AUI)
2106 smc_set_xcvr(dev, 1);
2108 smc_set_xcvr(dev, 0);
2111 tmp = inw(ioaddr + TCR);
2112 if (ecmd->duplex == DUPLEX_FULL)
2116 outw(ioaddr + TCR, tmp);
2121 static int smc_ethtool_ioctl (struct net_device *dev, void __user *useraddr)
2124 struct smc_private *smc = netdev_priv(dev);
2126 if (get_user(ethcmd, (u32 __user *)useraddr))
2131 case ETHTOOL_GDRVINFO: {
2132 struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO };
2133 strcpy(info.driver, DRV_NAME);
2134 strcpy(info.version, DRV_VERSION);
2135 if (copy_to_user(useraddr, &info, sizeof(info)))
2141 case ETHTOOL_GSET: {
2143 struct ethtool_cmd ecmd = { ETHTOOL_GSET };
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 if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
2156 case ETHTOOL_SSET: {
2158 struct ethtool_cmd ecmd;
2159 if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
2161 spin_lock_irq(&smc->lock);
2162 if (smc->cfg & CFG_MII_SELECT)
2163 ret = mii_ethtool_sset(&smc->mii_if, &ecmd);
2165 ret = smc_netdev_set_ecmd(dev, &ecmd);
2166 spin_unlock_irq(&smc->lock);
2170 /* get link status */
2171 case ETHTOOL_GLINK: {
2172 struct ethtool_value edata = { ETHTOOL_GLINK };
2173 spin_lock_irq(&smc->lock);
2174 edata.data = smc_link_ok(dev);
2175 spin_unlock_irq(&smc->lock);
2176 if (copy_to_user(useraddr, &edata, sizeof(edata)))
2182 /* get message-level */
2183 case ETHTOOL_GMSGLVL: {
2184 struct ethtool_value edata = { ETHTOOL_GMSGLVL };
2185 edata.data = pc_debug;
2186 if (copy_to_user(useraddr, &edata, sizeof(edata)))
2191 /* set message-level */
2192 case ETHTOOL_SMSGLVL: {
2193 struct ethtool_value edata;
2194 if (copy_from_user(&edata, useraddr, sizeof(edata)))
2196 pc_debug = edata.data;
2200 /* restart autonegotiation */
2201 case ETHTOOL_NWAY_RST: {
2202 if (smc->cfg & CFG_MII_SELECT)
2203 return mii_nway_restart(&smc->mii_if);
2215 static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
2217 struct smc_private *smc = netdev_priv(dev);
2218 struct mii_ioctl_data *mii;
2221 ioaddr_t ioaddr = dev->base_addr;
2224 if (!netif_running(dev))
2229 saved_bank = inw(ioaddr + BANK_SELECT);
2231 rc = smc_ethtool_ioctl(dev, rq->ifr_data);
2232 SMC_SELECT_BANK(saved_bank);
2236 spin_lock_irq(&smc->lock);
2237 saved_bank = inw(ioaddr + BANK_SELECT);
2239 rc = generic_mii_ioctl(&smc->mii_if, mii, cmd, NULL);
2240 SMC_SELECT_BANK(saved_bank);
2241 spin_unlock_irq(&smc->lock);
2248 static struct pcmcia_driver smc91c92_cs_driver = {
2249 .owner = THIS_MODULE,
2251 .name = "smc91c92_cs",
2253 .attach = smc91c92_attach,
2254 .detach = smc91c92_detach,
2257 static int __init init_smc91c92_cs(void)
2259 return pcmcia_register_driver(&smc91c92_cs_driver);
2262 static void __exit exit_smc91c92_cs(void)
2264 pcmcia_unregister_driver(&smc91c92_cs_driver);
2265 while (dev_list != NULL)
2266 smc91c92_detach(dev_list);
2269 module_init(init_smc91c92_cs);
2270 module_exit(exit_smc91c92_cs);