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;
414 if (link->state & DEV_CONFIG)
415 smc91c92_release(link);
418 pcmcia_deregister_client(link->handle);
420 /* Unlink device structure, free bits */
423 unregister_netdev(dev);
425 } /* smc91c92_detach */
427 /*====================================================================*/
429 static int cvt_ascii_address(struct net_device *dev, char *s)
435 for (i = 0; i < 6; i++) {
437 for (j = 0; j < 2; j++) {
440 da += ((c >= '0') && (c <= '9')) ?
441 (c - '0') : ((c & 0x0f) + 9);
443 dev->dev_addr[i] = da;
448 /*====================================================================*/
450 static int first_tuple(client_handle_t handle, tuple_t *tuple,
455 if ((i = pcmcia_get_first_tuple(handle, tuple)) != CS_SUCCESS ||
456 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
458 return pcmcia_parse_tuple(handle, tuple, parse);
461 static int next_tuple(client_handle_t handle, tuple_t *tuple,
466 if ((i = pcmcia_get_next_tuple(handle, tuple)) != CS_SUCCESS ||
467 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
469 return pcmcia_parse_tuple(handle, tuple, parse);
472 /*======================================================================
474 Configuration stuff for Megahertz cards
476 mhz_3288_power() is used to power up a 3288's ethernet chip.
477 mhz_mfc_config() handles socket setup for multifunction (1144
478 and 3288) cards. mhz_setup() gets a card's hardware ethernet
481 ======================================================================*/
483 static int mhz_3288_power(dev_link_t *link)
485 struct net_device *dev = link->priv;
486 struct smc_private *smc = netdev_priv(dev);
489 /* Read the ISR twice... */
490 readb(smc->base+MEGAHERTZ_ISR);
492 readb(smc->base+MEGAHERTZ_ISR);
497 /* Now read and write the COR... */
498 tmp = readb(smc->base + link->conf.ConfigBase + CISREG_COR);
500 writeb(tmp, smc->base + link->conf.ConfigBase + CISREG_COR);
505 static int mhz_mfc_config(dev_link_t *link)
507 struct net_device *dev = link->priv;
508 struct smc_private *smc = netdev_priv(dev);
512 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
517 link->conf.Attributes |= CONF_ENABLE_SPKR;
518 link->conf.Status = CCSR_AUDIO_ENA;
519 link->irq.Attributes =
520 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
521 link->io.IOAddrLines = 16;
522 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
523 link->io.NumPorts2 = 8;
525 tuple.Attributes = tuple.TupleOffset = 0;
526 tuple.TupleData = (cisdata_t *)buf;
527 tuple.TupleDataMax = sizeof(buf);
528 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
530 i = first_tuple(link->handle, &tuple, &parse);
531 /* The Megahertz combo cards have modem-like CIS entries, so
532 we have to explicitly try a bunch of port combinations. */
533 while (i == CS_SUCCESS) {
534 link->conf.ConfigIndex = cf->index;
535 link->io.BasePort2 = cf->io.win[0].base;
536 for (k = 0; k < 0x400; k += 0x10) {
537 if (k & 0x80) continue;
538 link->io.BasePort1 = k ^ 0x300;
539 i = pcmcia_request_io(link->handle, &link->io);
540 if (i == CS_SUCCESS) break;
542 if (i == CS_SUCCESS) break;
543 i = next_tuple(link->handle, &tuple, &parse);
547 dev->base_addr = link->io.BasePort1;
549 /* Allocate a memory window, for accessing the ISR */
550 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
551 req.Base = req.Size = 0;
553 i = pcmcia_request_window(&link->handle, &req, &link->win);
556 smc->base = ioremap(req.Base, req.Size);
557 mem.CardOffset = mem.Page = 0;
558 if (smc->manfid == MANFID_MOTOROLA)
559 mem.CardOffset = link->conf.ConfigBase;
560 i = pcmcia_map_mem_page(link->win, &mem);
562 if ((i == CS_SUCCESS)
563 && (smc->manfid == MANFID_MEGAHERTZ)
564 && (smc->cardid == PRODID_MEGAHERTZ_EM3288))
565 mhz_3288_power(link);
570 static int mhz_setup(dev_link_t *link)
572 client_handle_t handle = link->handle;
573 struct net_device *dev = link->priv;
576 u_char buf[255], *station_addr;
578 tuple.Attributes = tuple.TupleOffset = 0;
579 tuple.TupleData = buf;
580 tuple.TupleDataMax = sizeof(buf);
582 /* Read the station address from the CIS. It is stored as the last
583 (fourth) string in the Version 1 Version/ID tuple. */
584 tuple.DesiredTuple = CISTPL_VERS_1;
585 if (first_tuple(handle, &tuple, &parse) != CS_SUCCESS)
587 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
588 if (next_tuple(handle, &tuple, &parse) != CS_SUCCESS)
589 first_tuple(handle, &tuple, &parse);
590 if (parse.version_1.ns > 3) {
591 station_addr = parse.version_1.str + parse.version_1.ofs[3];
592 if (cvt_ascii_address(dev, station_addr) == 0)
596 /* Another possibility: for the EM3288, in a special tuple */
597 tuple.DesiredTuple = 0x81;
598 if (pcmcia_get_first_tuple(handle, &tuple) != CS_SUCCESS)
600 if (pcmcia_get_tuple_data(handle, &tuple) != CS_SUCCESS)
603 if (cvt_ascii_address(dev, buf) == 0)
609 /*======================================================================
611 Configuration stuff for the Motorola Mariner
613 mot_config() writes directly to the Mariner configuration
614 registers because the CIS is just bogus.
616 ======================================================================*/
618 static void mot_config(dev_link_t *link)
620 struct net_device *dev = link->priv;
621 struct smc_private *smc = netdev_priv(dev);
622 ioaddr_t ioaddr = dev->base_addr;
623 ioaddr_t iouart = link->io.BasePort2;
625 /* Set UART base address and force map with COR bit 1 */
626 writeb(iouart & 0xff, smc->base + MOT_UART + CISREG_IOBASE_0);
627 writeb((iouart >> 8) & 0xff, smc->base + MOT_UART + CISREG_IOBASE_1);
628 writeb(MOT_NORMAL, smc->base + MOT_UART + CISREG_COR);
630 /* Set SMC base address and force map with COR bit 1 */
631 writeb(ioaddr & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_0);
632 writeb((ioaddr >> 8) & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_1);
633 writeb(MOT_NORMAL, smc->base + MOT_LAN + CISREG_COR);
635 /* Wait for things to settle down */
639 static int mot_setup(dev_link_t *link)
641 struct net_device *dev = link->priv;
642 ioaddr_t ioaddr = dev->base_addr;
646 /* Read Ethernet address from Serial EEPROM */
648 for (i = 0; i < 3; i++) {
650 outw(MOT_EEPROM + i, ioaddr + POINTER);
652 outw((CTL_RELOAD | CTL_EE_SELECT), ioaddr + CONTROL);
654 for (loop = wait = 0; loop < 200; loop++) {
656 wait = ((CTL_RELOAD | CTL_STORE) & inw(ioaddr + CONTROL));
657 if (wait == 0) break;
663 addr = inw(ioaddr + GENERAL);
664 dev->dev_addr[2*i] = addr & 0xff;
665 dev->dev_addr[2*i+1] = (addr >> 8) & 0xff;
671 /*====================================================================*/
673 static int smc_config(dev_link_t *link)
675 struct net_device *dev = link->priv;
679 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
682 tuple.Attributes = tuple.TupleOffset = 0;
683 tuple.TupleData = (cisdata_t *)buf;
684 tuple.TupleDataMax = sizeof(buf);
685 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
687 link->io.NumPorts1 = 16;
688 i = first_tuple(link->handle, &tuple, &parse);
689 while (i != CS_NO_MORE_ITEMS) {
690 if (i == CS_SUCCESS) {
691 link->conf.ConfigIndex = cf->index;
692 link->io.BasePort1 = cf->io.win[0].base;
693 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
694 i = pcmcia_request_io(link->handle, &link->io);
695 if (i == CS_SUCCESS) break;
697 i = next_tuple(link->handle, &tuple, &parse);
700 dev->base_addr = link->io.BasePort1;
704 static int smc_setup(dev_link_t *link)
706 client_handle_t handle = link->handle;
707 struct net_device *dev = link->priv;
710 cistpl_lan_node_id_t *node_id;
711 u_char buf[255], *station_addr;
714 tuple.Attributes = tuple.TupleOffset = 0;
715 tuple.TupleData = buf;
716 tuple.TupleDataMax = sizeof(buf);
718 /* Check for a LAN function extension tuple */
719 tuple.DesiredTuple = CISTPL_FUNCE;
720 i = first_tuple(handle, &tuple, &parse);
721 while (i == CS_SUCCESS) {
722 if (parse.funce.type == CISTPL_FUNCE_LAN_NODE_ID)
724 i = next_tuple(handle, &tuple, &parse);
726 if (i == CS_SUCCESS) {
727 node_id = (cistpl_lan_node_id_t *)parse.funce.data;
728 if (node_id->nb == 6) {
729 for (i = 0; i < 6; i++)
730 dev->dev_addr[i] = node_id->id[i];
734 /* Try the third string in the Version 1 Version/ID tuple. */
735 tuple.DesiredTuple = CISTPL_VERS_1;
736 if (first_tuple(handle, &tuple, &parse) != CS_SUCCESS)
738 station_addr = parse.version_1.str + parse.version_1.ofs[2];
739 if (cvt_ascii_address(dev, station_addr) == 0)
745 /*====================================================================*/
747 static int osi_config(dev_link_t *link)
749 struct net_device *dev = link->priv;
750 static ioaddr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
753 link->conf.Attributes |= CONF_ENABLE_SPKR;
754 link->conf.Status = CCSR_AUDIO_ENA;
755 link->irq.Attributes =
756 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
757 link->io.NumPorts1 = 64;
758 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
759 link->io.NumPorts2 = 8;
760 link->io.IOAddrLines = 16;
762 /* Enable Hard Decode, LAN, Modem */
763 link->conf.ConfigIndex = 0x23;
765 for (i = j = 0; j < 4; j++) {
766 link->io.BasePort2 = com[j];
767 i = pcmcia_request_io(link->handle, &link->io);
768 if (i == CS_SUCCESS) break;
770 if (i != CS_SUCCESS) {
771 /* Fallback: turn off hard decode */
772 link->conf.ConfigIndex = 0x03;
773 link->io.NumPorts2 = 0;
774 i = pcmcia_request_io(link->handle, &link->io);
776 dev->base_addr = link->io.BasePort1 + 0x10;
780 static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid)
782 client_handle_t handle = link->handle;
783 struct net_device *dev = link->priv;
788 tuple.Attributes = TUPLE_RETURN_COMMON;
789 tuple.TupleData = buf;
790 tuple.TupleDataMax = sizeof(buf);
791 tuple.TupleOffset = 0;
793 /* Read the station address from tuple 0x90, subtuple 0x04 */
794 tuple.DesiredTuple = 0x90;
795 i = pcmcia_get_first_tuple(handle, &tuple);
796 while (i == CS_SUCCESS) {
797 i = pcmcia_get_tuple_data(handle, &tuple);
798 if ((i != CS_SUCCESS) || (buf[0] == 0x04))
800 i = pcmcia_get_next_tuple(handle, &tuple);
804 for (i = 0; i < 6; i++)
805 dev->dev_addr[i] = buf[i+2];
807 if (((manfid == MANFID_OSITECH) &&
808 (cardid == PRODID_OSITECH_SEVEN)) ||
809 ((manfid == MANFID_PSION) &&
810 (cardid == PRODID_PSION_NET100))) {
811 /* Download the Seven of Diamonds firmware */
812 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
813 outb(__Xilinx7OD[i], link->io.BasePort1+2);
816 } else if (manfid == MANFID_OSITECH) {
817 /* Make sure both functions are powered up */
818 set_bits(0x300, link->io.BasePort1 + OSITECH_AUI_PWR);
819 /* Now, turn on the interrupt for both card functions */
820 set_bits(0x300, link->io.BasePort1 + OSITECH_RESET_ISR);
821 DEBUG(2, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n",
822 inw(link->io.BasePort1 + OSITECH_AUI_PWR),
823 inw(link->io.BasePort1 + OSITECH_RESET_ISR));
829 /*======================================================================
831 This verifies that the chip is some SMC91cXX variant, and returns
832 the revision code if successful. Otherwise, it returns -ENODEV.
834 ======================================================================*/
836 static int check_sig(dev_link_t *link)
838 struct net_device *dev = link->priv;
839 ioaddr_t ioaddr = dev->base_addr;
844 if (inw(ioaddr + BANK_SELECT) >> 8 != 0x33) {
845 /* Try powering up the chip */
846 outw(0, ioaddr + CONTROL);
850 /* Try setting bus width */
851 width = (link->io.Attributes1 == IO_DATA_PATH_WIDTH_AUTO);
852 s = inb(ioaddr + CONFIG);
857 outb(s, ioaddr + CONFIG);
859 /* Check Base Address Register to make sure bus width is OK */
860 s = inw(ioaddr + BASE_ADDR);
861 if ((inw(ioaddr + BANK_SELECT) >> 8 == 0x33) &&
862 ((s >> 8) != (s & 0xff))) {
864 s = inw(ioaddr + REVISION);
869 event_callback_args_t args;
870 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n");
871 args.client_data = link;
872 smc91c92_event(CS_EVENT_RESET_PHYSICAL, 0, &args);
873 pcmcia_release_io(link->handle, &link->io);
874 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
875 pcmcia_request_io(link->handle, &link->io);
876 smc91c92_event(CS_EVENT_CARD_RESET, 0, &args);
877 return check_sig(link);
882 /*======================================================================
884 smc91c92_config() is scheduled to run after a CARD_INSERTION event
885 is received, to configure the PCMCIA socket, and to make the
886 ethernet device available to the system.
888 ======================================================================*/
890 #define CS_EXIT_TEST(ret, svc, label) \
891 if (ret != CS_SUCCESS) { cs_error(link->handle, svc, ret); goto label; }
893 static void smc91c92_config(dev_link_t *link)
895 client_handle_t handle = link->handle;
896 struct net_device *dev = link->priv;
897 struct smc_private *smc = netdev_priv(dev);
906 DEBUG(0, "smc91c92_config(0x%p)\n", link);
908 tuple.Attributes = tuple.TupleOffset = 0;
909 tuple.TupleData = (cisdata_t *)buf;
910 tuple.TupleDataMax = sizeof(buf);
912 tuple.DesiredTuple = CISTPL_CONFIG;
913 i = first_tuple(handle, &tuple, &parse);
914 CS_EXIT_TEST(i, ParseTuple, config_failed);
915 link->conf.ConfigBase = parse.config.base;
916 link->conf.Present = parse.config.rmask[0];
918 tuple.DesiredTuple = CISTPL_MANFID;
919 tuple.Attributes = TUPLE_RETURN_COMMON;
920 if (first_tuple(handle, &tuple, &parse) == CS_SUCCESS) {
921 smc->manfid = parse.manfid.manf;
922 smc->cardid = parse.manfid.card;
926 link->state |= DEV_CONFIG;
928 if ((smc->manfid == MANFID_OSITECH) &&
929 (smc->cardid != PRODID_OSITECH_SEVEN)) {
930 i = osi_config(link);
931 } else if ((smc->manfid == MANFID_MOTOROLA) ||
932 ((smc->manfid == MANFID_MEGAHERTZ) &&
933 ((smc->cardid == PRODID_MEGAHERTZ_VARIOUS) ||
934 (smc->cardid == PRODID_MEGAHERTZ_EM3288)))) {
935 i = mhz_mfc_config(link);
937 i = smc_config(link);
939 CS_EXIT_TEST(i, RequestIO, config_failed);
941 i = pcmcia_request_irq(link->handle, &link->irq);
942 CS_EXIT_TEST(i, RequestIRQ, config_failed);
943 i = pcmcia_request_configuration(link->handle, &link->conf);
944 CS_EXIT_TEST(i, RequestConfiguration, config_failed);
946 if (smc->manfid == MANFID_MOTOROLA)
949 dev->irq = link->irq.AssignedIRQ;
951 if ((if_port >= 0) && (if_port <= 2))
952 dev->if_port = if_port;
954 printk(KERN_NOTICE "smc91c92_cs: invalid if_port requested\n");
956 switch (smc->manfid) {
959 i = osi_setup(link, smc->manfid, smc->cardid); break;
961 case MANFID_NEW_MEDIA:
962 i = smc_setup(link); break;
963 case 0x128: /* For broken Megahertz cards */
964 case MANFID_MEGAHERTZ:
965 i = mhz_setup(link); break;
966 case MANFID_MOTOROLA:
967 default: /* get the hw address from EEPROM */
968 i = mot_setup(link); break;
972 printk(KERN_NOTICE "smc91c92_cs: Unable to find hardware address.\n");
979 rev = check_sig(link);
983 case 3: name = "92"; break;
984 case 4: name = ((rev & 15) >= 6) ? "96" : "94"; break;
985 case 5: name = "95"; break;
986 case 7: name = "100"; break;
987 case 8: name = "100-FD"; break;
988 case 9: name = "110"; break;
991 ioaddr = dev->base_addr;
995 mir = inw(ioaddr + MEMINFO) & 0xff;
996 if (mir == 0xff) mir++;
997 /* Get scale factor for memory size */
998 mcr = ((rev >> 4) > 3) ? inw(ioaddr + MEMCFG) : 0x0200;
999 mir *= 128 * (1<<((mcr >> 9) & 7));
1001 smc->cfg = inw(ioaddr + CONFIG) & ~CFG_AUI_SELECT;
1002 smc->cfg |= CFG_NO_WAIT | CFG_16BIT | CFG_STATIC;
1003 if (smc->manfid == MANFID_OSITECH)
1004 smc->cfg |= CFG_IRQ_SEL_1 | CFG_IRQ_SEL_0;
1005 if ((rev >> 4) >= 7)
1006 smc->cfg |= CFG_MII_SELECT;
1010 if (smc->cfg & CFG_MII_SELECT) {
1013 for (i = 0; i < 32; i++) {
1014 j = mdio_read(dev, i, 1);
1015 if ((j != 0) && (j != 0xffff)) break;
1017 smc->mii_if.phy_id = (i < 32) ? i : -1;
1022 link->dev = &smc->node;
1023 link->state &= ~DEV_CONFIG_PENDING;
1025 if (register_netdev(dev) != 0) {
1026 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n");
1031 strcpy(smc->node.dev_name, dev->name);
1033 printk(KERN_INFO "%s: smc91c%s rev %d: io %#3lx, irq %d, "
1034 "hw_addr ", dev->name, name, (rev & 0x0f), dev->base_addr,
1036 for (i = 0; i < 6; i++)
1037 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
1041 printk(KERN_INFO " %lu byte", mir);
1043 printk(KERN_INFO " %lu kb", mir>>10);
1044 printk(" buffer, %s xcvr\n", (smc->cfg & CFG_MII_SELECT) ?
1045 "MII" : if_names[dev->if_port]);
1048 if (smc->cfg & CFG_MII_SELECT) {
1049 if (smc->mii_if.phy_id != -1) {
1050 DEBUG(0, " MII transceiver at index %d, status %x.\n",
1051 smc->mii_if.phy_id, j);
1053 printk(KERN_NOTICE " No MII transceivers found!\n");
1060 unregister_netdev(dev);
1061 config_failed: /* CS_EXIT_TEST() calls jump to here... */
1062 smc91c92_release(link);
1063 link->state &= ~DEV_CONFIG_PENDING;
1065 } /* smc91c92_config */
1067 /*======================================================================
1069 After a card is removed, smc91c92_release() will unregister the net
1070 device, and release the PCMCIA configuration. If the device is
1071 still open, this will be postponed until it is closed.
1073 ======================================================================*/
1075 static void smc91c92_release(dev_link_t *link)
1078 DEBUG(0, "smc91c92_release(0x%p)\n", link);
1080 pcmcia_release_configuration(link->handle);
1081 pcmcia_release_io(link->handle, &link->io);
1082 pcmcia_release_irq(link->handle, &link->irq);
1084 struct net_device *dev = link->priv;
1085 struct smc_private *smc = netdev_priv(dev);
1087 pcmcia_release_window(link->win);
1090 link->state &= ~DEV_CONFIG;
1093 /*======================================================================
1095 The card status event handler. Mostly, this schedules other
1096 stuff to run after an event is received. A CARD_REMOVAL event
1097 also sets some flags to discourage the net drivers from trying
1098 to talk to the card any more.
1100 ======================================================================*/
1102 static int smc91c92_event(event_t event, int priority,
1103 event_callback_args_t *args)
1105 dev_link_t *link = args->client_data;
1106 struct net_device *dev = link->priv;
1107 struct smc_private *smc = netdev_priv(dev);
1110 DEBUG(1, "smc91c92_event(0x%06x)\n", event);
1113 case CS_EVENT_CARD_REMOVAL:
1114 link->state &= ~DEV_PRESENT;
1115 if (link->state & DEV_CONFIG) {
1116 netif_device_detach(dev);
1117 smc91c92_release(link);
1120 case CS_EVENT_CARD_INSERTION:
1121 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1122 smc91c92_config(link);
1124 case CS_EVENT_PM_SUSPEND:
1125 link->state |= DEV_SUSPEND;
1126 /* Fall through... */
1127 case CS_EVENT_RESET_PHYSICAL:
1128 if (link->state & DEV_CONFIG) {
1130 netif_device_detach(dev);
1131 pcmcia_release_configuration(link->handle);
1134 case CS_EVENT_PM_RESUME:
1135 link->state &= ~DEV_SUSPEND;
1136 /* Fall through... */
1137 case CS_EVENT_CARD_RESET:
1138 if (link->state & DEV_CONFIG) {
1139 if ((smc->manfid == MANFID_MEGAHERTZ) &&
1140 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
1141 mhz_3288_power(link);
1142 pcmcia_request_configuration(link->handle, &link->conf);
1143 if (smc->manfid == MANFID_MOTOROLA)
1145 if ((smc->manfid == MANFID_OSITECH) &&
1146 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1147 /* Power up the card and enable interrupts */
1148 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR);
1149 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR);
1151 if (((smc->manfid == MANFID_OSITECH) &&
1152 (smc->cardid == PRODID_OSITECH_SEVEN)) ||
1153 ((smc->manfid == MANFID_PSION) &&
1154 (smc->cardid == PRODID_PSION_NET100))) {
1155 /* Download the Seven of Diamonds firmware */
1156 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
1157 outb(__Xilinx7OD[i], link->io.BasePort1+2);
1163 netif_device_attach(dev);
1169 } /* smc91c92_event */
1171 /*======================================================================
1173 MII interface support for SMC91cXX based cards
1174 ======================================================================*/
1176 #define MDIO_SHIFT_CLK 0x04
1177 #define MDIO_DATA_OUT 0x01
1178 #define MDIO_DIR_WRITE 0x08
1179 #define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
1180 #define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
1181 #define MDIO_DATA_READ 0x02
1183 static void mdio_sync(ioaddr_t addr)
1186 for (bits = 0; bits < 32; bits++) {
1187 outb(MDIO_DATA_WRITE1, addr);
1188 outb(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
1192 static int mdio_read(struct net_device *dev, int phy_id, int loc)
1194 ioaddr_t addr = dev->base_addr + MGMT;
1195 u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
1199 for (i = 13; i >= 0; i--) {
1200 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1202 outb(dat | MDIO_SHIFT_CLK, addr);
1204 for (i = 19; i > 0; i--) {
1206 retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
1207 outb(MDIO_SHIFT_CLK, addr);
1209 return (retval>>1) & 0xffff;
1212 static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
1214 ioaddr_t addr = dev->base_addr + MGMT;
1215 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
1219 for (i = 31; i >= 0; i--) {
1220 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1222 outb(dat | MDIO_SHIFT_CLK, addr);
1224 for (i = 1; i >= 0; i--) {
1226 outb(MDIO_SHIFT_CLK, addr);
1230 /*======================================================================
1232 The driver core code, most of which should be common with a
1233 non-PCMCIA implementation.
1235 ======================================================================*/
1238 static void smc_dump(struct net_device *dev)
1240 ioaddr_t ioaddr = dev->base_addr;
1242 save = inw(ioaddr + BANK_SELECT);
1243 for (w = 0; w < 4; w++) {
1245 printk(KERN_DEBUG "bank %d: ", w);
1246 for (i = 0; i < 14; i += 2)
1247 printk(" %04x", inw(ioaddr + i));
1250 outw(save, ioaddr + BANK_SELECT);
1254 static int smc_open(struct net_device *dev)
1256 struct smc_private *smc = netdev_priv(dev);
1257 dev_link_t *link = &smc->link;
1260 DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n",
1261 dev->name, dev, inw(dev->base_addr + BANK_SELECT));
1262 if (pc_debug > 1) smc_dump(dev);
1265 /* Check that the PCMCIA card is still here. */
1268 /* Physical device present signature. */
1269 if (check_sig(link) < 0) {
1270 printk("smc91c92_cs: Yikes! Bad chip signature!\n");
1275 netif_start_queue(dev);
1277 smc->packets_waiting = 0;
1280 init_timer(&smc->media);
1281 smc->media.function = &media_check;
1282 smc->media.data = (u_long) dev;
1283 smc->media.expires = jiffies + HZ;
1284 add_timer(&smc->media);
1289 /*====================================================================*/
1291 static int smc_close(struct net_device *dev)
1293 struct smc_private *smc = netdev_priv(dev);
1294 dev_link_t *link = &smc->link;
1295 ioaddr_t ioaddr = dev->base_addr;
1297 DEBUG(0, "%s: smc_close(), status %4.4x.\n",
1298 dev->name, inw(ioaddr + BANK_SELECT));
1300 netif_stop_queue(dev);
1302 /* Shut off all interrupts, and turn off the Tx and Rx sections.
1303 Don't bother to check for chip present. */
1304 SMC_SELECT_BANK(2); /* Nominally paranoia, but do no assume... */
1305 outw(0, ioaddr + INTERRUPT);
1307 mask_bits(0xff00, ioaddr + RCR);
1308 mask_bits(0xff00, ioaddr + TCR);
1310 /* Put the chip into power-down mode. */
1312 outw(CTL_POWERDOWN, ioaddr + CONTROL );
1315 del_timer_sync(&smc->media);
1320 /*======================================================================
1322 Transfer a packet to the hardware and trigger the packet send.
1323 This may be called at either from either the Tx queue code
1324 or the interrupt handler.
1326 ======================================================================*/
1328 static void smc_hardware_send_packet(struct net_device * dev)
1330 struct smc_private *smc = netdev_priv(dev);
1331 struct sk_buff *skb = smc->saved_skb;
1332 ioaddr_t ioaddr = dev->base_addr;
1336 printk(KERN_ERR "%s: In XMIT with no packet to send.\n", dev->name);
1340 /* There should be a packet slot waiting. */
1341 packet_no = inw(ioaddr + PNR_ARR) >> 8;
1342 if (packet_no & 0x80) {
1343 /* If not, there is a hardware problem! Likely an ejected card. */
1344 printk(KERN_WARNING "%s: 91c92 hardware Tx buffer allocation"
1345 " failed, status %#2.2x.\n", dev->name, packet_no);
1346 dev_kfree_skb_irq(skb);
1347 smc->saved_skb = NULL;
1348 netif_start_queue(dev);
1352 smc->stats.tx_bytes += skb->len;
1353 /* The card should use the just-allocated buffer. */
1354 outw(packet_no, ioaddr + PNR_ARR);
1355 /* point to the beginning of the packet */
1356 outw(PTR_AUTOINC , ioaddr + POINTER);
1358 /* Send the packet length (+6 for status, length and ctl byte)
1359 and the status word (set to zeros). */
1361 u_char *buf = skb->data;
1362 u_int length = skb->len; /* The chip will pad to ethernet min. */
1364 DEBUG(2, "%s: Trying to xmit packet of length %d.\n",
1367 /* send the packet length: +6 for status word, length, and ctl */
1368 outw(0, ioaddr + DATA_1);
1369 outw(length + 6, ioaddr + DATA_1);
1370 outsw(ioaddr + DATA_1, buf, length >> 1);
1372 /* The odd last byte, if there is one, goes in the control word. */
1373 outw((length & 1) ? 0x2000 | buf[length-1] : 0, ioaddr + DATA_1);
1376 /* Enable the Tx interrupts, both Tx (TxErr) and TxEmpty. */
1377 outw(((IM_TX_INT|IM_TX_EMPTY_INT)<<8) |
1378 (inw(ioaddr + INTERRUPT) & 0xff00),
1379 ioaddr + INTERRUPT);
1381 /* The chip does the rest of the work. */
1382 outw(MC_ENQUEUE , ioaddr + MMU_CMD);
1384 smc->saved_skb = NULL;
1385 dev_kfree_skb_irq(skb);
1386 dev->trans_start = jiffies;
1387 netif_start_queue(dev);
1391 /*====================================================================*/
1393 static void smc_tx_timeout(struct net_device *dev)
1395 struct smc_private *smc = netdev_priv(dev);
1396 ioaddr_t ioaddr = dev->base_addr;
1398 printk(KERN_NOTICE "%s: SMC91c92 transmit timed out, "
1399 "Tx_status %2.2x status %4.4x.\n",
1400 dev->name, inw(ioaddr)&0xff, inw(ioaddr + 2));
1401 smc->stats.tx_errors++;
1403 dev->trans_start = jiffies;
1404 smc->saved_skb = NULL;
1405 netif_wake_queue(dev);
1408 static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev)
1410 struct smc_private *smc = netdev_priv(dev);
1411 ioaddr_t ioaddr = dev->base_addr;
1415 netif_stop_queue(dev);
1417 DEBUG(2, "%s: smc_start_xmit(length = %d) called,"
1418 " status %4.4x.\n", dev->name, skb->len, inw(ioaddr + 2));
1420 if (smc->saved_skb) {
1421 /* THIS SHOULD NEVER HAPPEN. */
1422 smc->stats.tx_aborted_errors++;
1423 printk(KERN_DEBUG "%s: Internal error -- sent packet while busy.\n",
1427 smc->saved_skb = skb;
1429 num_pages = skb->len >> 8;
1431 if (num_pages > 7) {
1432 printk(KERN_ERR "%s: Far too big packet error.\n", dev->name);
1433 dev_kfree_skb (skb);
1434 smc->saved_skb = NULL;
1435 smc->stats.tx_dropped++;
1436 return 0; /* Do not re-queue this packet. */
1438 /* A packet is now waiting. */
1439 smc->packets_waiting++;
1441 SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */
1443 /* need MC_RESET to keep the memory consistent. errata? */
1445 outw(MC_RESET, ioaddr + MMU_CMD);
1449 /* Allocate the memory; send the packet now if we win. */
1450 outw(MC_ALLOC | num_pages, ioaddr + MMU_CMD);
1451 for (time_out = MEMORY_WAIT_TIME; time_out >= 0; time_out--) {
1452 ir = inw(ioaddr+INTERRUPT);
1453 if (ir & IM_ALLOC_INT) {
1454 /* Acknowledge the interrupt, send the packet. */
1455 outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT);
1456 smc_hardware_send_packet(dev); /* Send the packet now.. */
1461 /* Otherwise defer until the Tx-space-allocated interrupt. */
1462 DEBUG(2, "%s: memory allocation deferred.\n", dev->name);
1463 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT);
1468 /*======================================================================
1470 Handle a Tx anomolous event. Entered while in Window 2.
1472 ======================================================================*/
1474 static void smc_tx_err(struct net_device * dev)
1476 struct smc_private *smc = netdev_priv(dev);
1477 ioaddr_t ioaddr = dev->base_addr;
1478 int saved_packet = inw(ioaddr + PNR_ARR) & 0xff;
1479 int packet_no = inw(ioaddr + FIFO_PORTS) & 0x7f;
1482 /* select this as the packet to read from */
1483 outw(packet_no, ioaddr + PNR_ARR);
1485 /* read the first word from this packet */
1486 outw(PTR_AUTOINC | PTR_READ | 0, ioaddr + POINTER);
1488 tx_status = inw(ioaddr + DATA_1);
1490 smc->stats.tx_errors++;
1491 if (tx_status & TS_LOSTCAR) smc->stats.tx_carrier_errors++;
1492 if (tx_status & TS_LATCOL) smc->stats.tx_window_errors++;
1493 if (tx_status & TS_16COL) {
1494 smc->stats.tx_aborted_errors++;
1498 if (tx_status & TS_SUCCESS) {
1499 printk(KERN_NOTICE "%s: Successful packet caused error "
1500 "interrupt?\n", dev->name);
1502 /* re-enable transmit */
1504 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1507 outw(MC_FREEPKT, ioaddr + MMU_CMD); /* Free the packet memory. */
1509 /* one less packet waiting for me */
1510 smc->packets_waiting--;
1512 outw(saved_packet, ioaddr + PNR_ARR);
1516 /*====================================================================*/
1518 static void smc_eph_irq(struct net_device *dev)
1520 struct smc_private *smc = netdev_priv(dev);
1521 ioaddr_t ioaddr = dev->base_addr;
1522 u_short card_stats, ephs;
1525 ephs = inw(ioaddr + EPH);
1526 DEBUG(2, "%s: Ethernet protocol handler interrupt, status"
1527 " %4.4x.\n", dev->name, ephs);
1528 /* Could be a counter roll-over warning: update stats. */
1529 card_stats = inw(ioaddr + COUNTER);
1530 /* single collisions */
1531 smc->stats.collisions += card_stats & 0xF;
1533 /* multiple collisions */
1534 smc->stats.collisions += card_stats & 0xF;
1535 #if 0 /* These are for when linux supports these statistics */
1536 card_stats >>= 4; /* deferred */
1537 card_stats >>= 4; /* excess deferred */
1539 /* If we had a transmit error we must re-enable the transmitter. */
1540 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1542 /* Clear a link error interrupt. */
1544 outw(CTL_AUTO_RELEASE | 0x0000, ioaddr + CONTROL);
1545 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1550 /*====================================================================*/
1552 static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1554 struct net_device *dev = dev_id;
1555 struct smc_private *smc = netdev_priv(dev);
1557 u_short saved_bank, saved_pointer, mask, status;
1558 unsigned int handled = 1;
1559 char bogus_cnt = INTR_WORK; /* Work we are willing to do. */
1561 if (!netif_device_present(dev))
1564 ioaddr = dev->base_addr;
1566 DEBUG(3, "%s: SMC91c92 interrupt %d at %#x.\n", dev->name,
1570 saved_bank = inw(ioaddr + BANK_SELECT);
1571 if ((saved_bank & 0xff00) != 0x3300) {
1572 /* The device does not exist -- the card could be off-line, or
1573 maybe it has been ejected. */
1574 DEBUG(1, "%s: SMC91c92 interrupt %d for non-existent"
1575 "/ejected device.\n", dev->name, irq);
1581 saved_pointer = inw(ioaddr + POINTER);
1582 mask = inw(ioaddr + INTERRUPT) >> 8;
1583 /* clear all interrupts */
1584 outw(0, ioaddr + INTERRUPT);
1586 do { /* read the status flag, and mask it */
1587 status = inw(ioaddr + INTERRUPT) & 0xff;
1588 DEBUG(3, "%s: Status is %#2.2x (mask %#2.2x).\n", dev->name,
1590 if ((status & mask) == 0) {
1591 if (bogus_cnt == INTR_WORK)
1595 if (status & IM_RCV_INT) {
1596 /* Got a packet(s). */
1599 if (status & IM_TX_INT) {
1601 outw(IM_TX_INT, ioaddr + INTERRUPT);
1604 if (status & IM_TX_EMPTY_INT) {
1605 outw(IM_TX_EMPTY_INT, ioaddr + INTERRUPT);
1606 mask &= ~IM_TX_EMPTY_INT;
1607 smc->stats.tx_packets += smc->packets_waiting;
1608 smc->packets_waiting = 0;
1610 if (status & IM_ALLOC_INT) {
1611 /* Clear this interrupt so it doesn't happen again */
1612 mask &= ~IM_ALLOC_INT;
1614 smc_hardware_send_packet(dev);
1616 /* enable xmit interrupts based on this */
1617 mask |= (IM_TX_EMPTY_INT | IM_TX_INT);
1619 /* and let the card send more packets to me */
1620 netif_wake_queue(dev);
1622 if (status & IM_RX_OVRN_INT) {
1623 smc->stats.rx_errors++;
1624 smc->stats.rx_fifo_errors++;
1626 smc->rx_ovrn = 1; /* need MC_RESET outside smc_interrupt */
1627 outw(IM_RX_OVRN_INT, ioaddr + INTERRUPT);
1629 if (status & IM_EPH_INT)
1631 } while (--bogus_cnt);
1633 DEBUG(3, " Restoring saved registers mask %2.2x bank %4.4x"
1634 " pointer %4.4x.\n", mask, saved_bank, saved_pointer);
1636 /* restore state register */
1637 outw((mask<<8), ioaddr + INTERRUPT);
1638 outw(saved_pointer, ioaddr + POINTER);
1639 SMC_SELECT_BANK(saved_bank);
1641 DEBUG(3, "%s: Exiting interrupt IRQ%d.\n", dev->name, irq);
1645 if ((smc->manfid == MANFID_OSITECH) &&
1646 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1647 /* Retrigger interrupt if needed */
1648 mask_bits(0x00ff, ioaddr-0x10+OSITECH_RESET_ISR);
1649 set_bits(0x0300, ioaddr-0x10+OSITECH_RESET_ISR);
1651 if (smc->manfid == MANFID_MOTOROLA) {
1653 cor = readb(smc->base + MOT_UART + CISREG_COR);
1654 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_UART + CISREG_COR);
1655 writeb(cor, smc->base + MOT_UART + CISREG_COR);
1656 cor = readb(smc->base + MOT_LAN + CISREG_COR);
1657 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_LAN + CISREG_COR);
1658 writeb(cor, smc->base + MOT_LAN + CISREG_COR);
1660 #ifdef DOES_NOT_WORK
1661 if (smc->base != NULL) { /* Megahertz MFC's */
1662 readb(smc->base+MEGAHERTZ_ISR);
1663 readb(smc->base+MEGAHERTZ_ISR);
1666 return IRQ_RETVAL(handled);
1669 /*====================================================================*/
1671 static void smc_rx(struct net_device *dev)
1673 struct smc_private *smc = netdev_priv(dev);
1674 ioaddr_t ioaddr = dev->base_addr;
1676 int packet_length; /* Caution: not frame length, rather words
1677 to transfer from the chip. */
1679 /* Assertion: we are in Window 2. */
1681 if (inw(ioaddr + FIFO_PORTS) & FP_RXEMPTY) {
1682 printk(KERN_ERR "%s: smc_rx() with nothing on Rx FIFO.\n",
1687 /* Reset the read pointer, and read the status and packet length. */
1688 outw(PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER);
1689 rx_status = inw(ioaddr + DATA_1);
1690 packet_length = inw(ioaddr + DATA_1) & 0x07ff;
1692 DEBUG(2, "%s: Receive status %4.4x length %d.\n",
1693 dev->name, rx_status, packet_length);
1695 if (!(rx_status & RS_ERRORS)) {
1696 /* do stuff to make a new packet */
1697 struct sk_buff *skb;
1699 /* Note: packet_length adds 5 or 6 extra bytes here! */
1700 skb = dev_alloc_skb(packet_length+2);
1703 DEBUG(1, "%s: Low memory, packet dropped.\n", dev->name);
1704 smc->stats.rx_dropped++;
1705 outw(MC_RELEASE, ioaddr + MMU_CMD);
1709 packet_length -= (rx_status & RS_ODDFRAME ? 5 : 6);
1710 skb_reserve(skb, 2);
1711 insw(ioaddr+DATA_1, skb_put(skb, packet_length),
1712 (packet_length+1)>>1);
1713 skb->protocol = eth_type_trans(skb, dev);
1717 dev->last_rx = jiffies;
1718 smc->stats.rx_packets++;
1719 smc->stats.rx_bytes += packet_length;
1720 if (rx_status & RS_MULTICAST)
1721 smc->stats.multicast++;
1724 smc->stats.rx_errors++;
1726 if (rx_status & RS_ALGNERR) smc->stats.rx_frame_errors++;
1727 if (rx_status & (RS_TOOSHORT | RS_TOOLONG))
1728 smc->stats.rx_length_errors++;
1729 if (rx_status & RS_BADCRC) smc->stats.rx_crc_errors++;
1731 /* Let the MMU free the memory of this packet. */
1732 outw(MC_RELEASE, ioaddr + MMU_CMD);
1737 /*====================================================================*/
1739 static struct net_device_stats *smc_get_stats(struct net_device *dev)
1741 struct smc_private *smc = netdev_priv(dev);
1742 /* Nothing to update - the 91c92 is a pretty primative chip. */
1746 /*======================================================================
1748 Calculate values for the hardware multicast filter hash table.
1750 ======================================================================*/
1752 static void fill_multicast_tbl(int count, struct dev_mc_list *addrs,
1753 u_char *multicast_table)
1755 struct dev_mc_list *mc_addr;
1757 for (mc_addr = addrs; mc_addr && --count > 0; mc_addr = mc_addr->next) {
1758 u_int position = ether_crc(6, mc_addr->dmi_addr);
1759 #ifndef final_version /* Verify multicast address. */
1760 if ((mc_addr->dmi_addr[0] & 1) == 0)
1763 multicast_table[position >> 29] |= 1 << ((position >> 26) & 7);
1767 /*======================================================================
1769 Set the receive mode.
1771 This routine is used by both the protocol level to notify us of
1772 promiscuous/multicast mode changes, and by the open/reset code to
1773 initialize the Rx registers. We always set the multicast list and
1774 leave the receiver running.
1776 ======================================================================*/
1778 static void set_rx_mode(struct net_device *dev)
1780 ioaddr_t ioaddr = dev->base_addr;
1781 struct smc_private *smc = netdev_priv(dev);
1782 u_int multicast_table[ 2 ] = { 0, };
1783 unsigned long flags;
1784 u_short rx_cfg_setting;
1786 if (dev->flags & IFF_PROMISC) {
1787 printk(KERN_NOTICE "%s: setting Rx mode to promiscuous.\n", dev->name);
1788 rx_cfg_setting = RxStripCRC | RxEnable | RxPromisc | RxAllMulti;
1789 } else if (dev->flags & IFF_ALLMULTI)
1790 rx_cfg_setting = RxStripCRC | RxEnable | RxAllMulti;
1792 if (dev->mc_count) {
1793 fill_multicast_tbl(dev->mc_count, dev->mc_list,
1794 (u_char *)multicast_table);
1796 rx_cfg_setting = RxStripCRC | RxEnable;
1799 /* Load MC table and Rx setting into the chip without interrupts. */
1800 spin_lock_irqsave(&smc->lock, flags);
1802 outl(multicast_table[0], ioaddr + MULTICAST0);
1803 outl(multicast_table[1], ioaddr + MULTICAST4);
1805 outw(rx_cfg_setting, ioaddr + RCR);
1807 spin_unlock_irqrestore(&smc->lock, flags);
1812 /*======================================================================
1814 Senses when a card's config changes. Here, it's coax or TP.
1816 ======================================================================*/
1818 static int s9k_config(struct net_device *dev, struct ifmap *map)
1820 struct smc_private *smc = netdev_priv(dev);
1821 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
1822 if (smc->cfg & CFG_MII_SELECT)
1824 else if (map->port > 2)
1826 dev->if_port = map->port;
1827 printk(KERN_INFO "%s: switched to %s port\n",
1828 dev->name, if_names[dev->if_port]);
1834 /*======================================================================
1836 Reset the chip, reloading every register that might be corrupted.
1838 ======================================================================*/
1841 Set transceiver type, perhaps to something other than what the user
1842 specified in dev->if_port.
1844 static void smc_set_xcvr(struct net_device *dev, int if_port)
1846 struct smc_private *smc = netdev_priv(dev);
1847 ioaddr_t ioaddr = dev->base_addr;
1850 saved_bank = inw(ioaddr + BANK_SELECT);
1853 outw(smc->cfg | CFG_AUI_SELECT, ioaddr + CONFIG);
1854 if ((smc->manfid == MANFID_OSITECH) &&
1855 (smc->cardid != PRODID_OSITECH_SEVEN))
1856 set_bits(OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1857 smc->media_status = ((dev->if_port == 0) ? 0x0001 : 0x0002);
1859 outw(smc->cfg, ioaddr + CONFIG);
1860 if ((smc->manfid == MANFID_OSITECH) &&
1861 (smc->cardid != PRODID_OSITECH_SEVEN))
1862 mask_bits(~OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1863 smc->media_status = ((dev->if_port == 0) ? 0x0012 : 0x4001);
1865 SMC_SELECT_BANK(saved_bank);
1868 static void smc_reset(struct net_device *dev)
1870 ioaddr_t ioaddr = dev->base_addr;
1871 struct smc_private *smc = netdev_priv(dev);
1874 DEBUG(0, "%s: smc91c92 reset called.\n", dev->name);
1876 /* The first interaction must be a write to bring the chip out
1879 /* Reset the chip. */
1880 outw(RCR_SOFTRESET, ioaddr + RCR);
1883 /* Clear the transmit and receive configuration registers. */
1884 outw(RCR_CLEAR, ioaddr + RCR);
1885 outw(TCR_CLEAR, ioaddr + TCR);
1887 /* Set the Window 1 control, configuration and station addr registers.
1888 No point in writing the I/O base register ;-> */
1890 /* Automatically release succesfully transmitted packets,
1891 Accept link errors, counter and Tx error interrupts. */
1892 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1894 smc_set_xcvr(dev, dev->if_port);
1895 if ((smc->manfid == MANFID_OSITECH) &&
1896 (smc->cardid != PRODID_OSITECH_SEVEN))
1897 outw((dev->if_port == 2 ? OSI_AUI_PWR : 0) |
1898 (inw(ioaddr-0x10+OSITECH_AUI_PWR) & 0xff00),
1899 ioaddr - 0x10 + OSITECH_AUI_PWR);
1901 /* Fill in the physical address. The databook is wrong about the order! */
1902 for (i = 0; i < 6; i += 2)
1903 outw((dev->dev_addr[i+1]<<8)+dev->dev_addr[i],
1904 ioaddr + ADDR0 + i);
1908 outw(MC_RESET, ioaddr + MMU_CMD);
1909 outw(0, ioaddr + INTERRUPT);
1911 /* Re-enable the chip. */
1913 outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) |
1914 TCR_ENABLE | TCR_PAD_EN | smc->duplex, ioaddr + TCR);
1917 if (smc->cfg & CFG_MII_SELECT) {
1921 mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000);
1923 /* Advertise 100F, 100H, 10F, 10H */
1924 mdio_write(dev, smc->mii_if.phy_id, 4, 0x01e1);
1926 /* Restart MII autonegotiation */
1927 mdio_write(dev, smc->mii_if.phy_id, 0, 0x0000);
1928 mdio_write(dev, smc->mii_if.phy_id, 0, 0x1200);
1931 /* Enable interrupts. */
1933 outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,
1934 ioaddr + INTERRUPT);
1937 /*======================================================================
1939 Media selection timer routine
1941 ======================================================================*/
1943 static void media_check(u_long arg)
1945 struct net_device *dev = (struct net_device *) arg;
1946 struct smc_private *smc = netdev_priv(dev);
1947 ioaddr_t ioaddr = dev->base_addr;
1948 u_short i, media, saved_bank;
1951 saved_bank = inw(ioaddr + BANK_SELECT);
1953 if (!netif_device_present(dev))
1958 /* need MC_RESET to keep the memory consistent. errata? */
1960 outw(MC_RESET, ioaddr + MMU_CMD);
1963 i = inw(ioaddr + INTERRUPT);
1965 media = inw(ioaddr + EPH) & EPH_LINK_OK;
1967 media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1;
1969 /* Check for pending interrupt with watchdog flag set: with
1970 this, we can limp along even if the interrupt is blocked */
1971 if (smc->watchdog++ && ((i>>8) & i)) {
1972 if (!smc->fast_poll)
1973 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
1974 smc_interrupt(dev->irq, smc, NULL);
1975 smc->fast_poll = HZ;
1977 if (smc->fast_poll) {
1979 smc->media.expires = jiffies + HZ/100;
1980 add_timer(&smc->media);
1981 SMC_SELECT_BANK(saved_bank);
1985 if (smc->cfg & CFG_MII_SELECT) {
1986 if (smc->mii_if.phy_id < 0)
1990 link = mdio_read(dev, smc->mii_if.phy_id, 1);
1991 if (!link || (link == 0xffff)) {
1992 printk(KERN_INFO "%s: MII is missing!\n", dev->name);
1993 smc->mii_if.phy_id = -1;
1998 if (link != smc->link_status) {
1999 u_short p = mdio_read(dev, smc->mii_if.phy_id, 5);
2000 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2001 (link) ? "found" : "lost");
2002 smc->duplex = (((p & 0x0100) || ((p & 0x1c0) == 0x40))
2005 printk(KERN_INFO "%s: autonegotiation complete: "
2006 "%sbaseT-%cD selected\n", dev->name,
2007 ((p & 0x0180) ? "100" : "10"),
2008 (smc->duplex ? 'F' : 'H'));
2011 outw(inw(ioaddr + TCR) | smc->duplex, ioaddr + TCR);
2012 smc->link_status = link;
2017 /* Ignore collisions unless we've had no rx's recently */
2018 if (jiffies - dev->last_rx > HZ) {
2019 if (smc->tx_err || (smc->media_status & EPH_16COL))
2024 if (media != smc->media_status) {
2025 if ((media & smc->media_status & 1) &&
2026 ((smc->media_status ^ media) & EPH_LINK_OK))
2027 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2028 (smc->media_status & EPH_LINK_OK ? "lost" : "found"));
2029 else if ((media & smc->media_status & 2) &&
2030 ((smc->media_status ^ media) & EPH_16COL))
2031 printk(KERN_INFO "%s: coax cable %s\n", dev->name,
2032 (media & EPH_16COL ? "problem" : "ok"));
2033 if (dev->if_port == 0) {
2035 if (media & EPH_LINK_OK)
2036 printk(KERN_INFO "%s: flipped to 10baseT\n",
2039 smc_set_xcvr(dev, 2);
2041 if (media & EPH_16COL)
2042 smc_set_xcvr(dev, 1);
2044 printk(KERN_INFO "%s: flipped to 10base2\n",
2048 smc->media_status = media;
2052 smc->media.expires = jiffies + HZ;
2053 add_timer(&smc->media);
2054 SMC_SELECT_BANK(saved_bank);
2057 static int smc_link_ok(struct net_device *dev)
2059 ioaddr_t ioaddr = dev->base_addr;
2060 struct smc_private *smc = netdev_priv(dev);
2062 if (smc->cfg & CFG_MII_SELECT) {
2063 return mii_link_ok(&smc->mii_if);
2066 return inw(ioaddr + EPH) & EPH_LINK_OK;
2070 static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2073 ioaddr_t ioaddr = dev->base_addr;
2075 ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |
2076 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);
2079 tmp = inw(ioaddr + CONFIG);
2080 ecmd->port = (tmp & CFG_AUI_SELECT) ? PORT_AUI : PORT_TP;
2081 ecmd->transceiver = XCVR_INTERNAL;
2082 ecmd->speed = SPEED_10;
2083 ecmd->phy_address = ioaddr + MGMT;
2086 tmp = inw(ioaddr + TCR);
2087 ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF;
2092 static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2095 ioaddr_t ioaddr = dev->base_addr;
2097 if (ecmd->speed != SPEED_10)
2099 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
2101 if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI)
2103 if (ecmd->transceiver != XCVR_INTERNAL)
2106 if (ecmd->port == PORT_AUI)
2107 smc_set_xcvr(dev, 1);
2109 smc_set_xcvr(dev, 0);
2112 tmp = inw(ioaddr + TCR);
2113 if (ecmd->duplex == DUPLEX_FULL)
2117 outw(ioaddr + TCR, tmp);
2122 static int smc_ethtool_ioctl (struct net_device *dev, void __user *useraddr)
2125 struct smc_private *smc = netdev_priv(dev);
2127 if (get_user(ethcmd, (u32 __user *)useraddr))
2132 case ETHTOOL_GDRVINFO: {
2133 struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO };
2134 strcpy(info.driver, DRV_NAME);
2135 strcpy(info.version, DRV_VERSION);
2136 if (copy_to_user(useraddr, &info, sizeof(info)))
2142 case ETHTOOL_GSET: {
2144 struct ethtool_cmd ecmd = { ETHTOOL_GSET };
2145 spin_lock_irq(&smc->lock);
2146 if (smc->cfg & CFG_MII_SELECT)
2147 ret = mii_ethtool_gset(&smc->mii_if, &ecmd);
2149 ret = smc_netdev_get_ecmd(dev, &ecmd);
2150 spin_unlock_irq(&smc->lock);
2151 if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
2157 case ETHTOOL_SSET: {
2159 struct ethtool_cmd ecmd;
2160 if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
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);
2171 /* get link status */
2172 case ETHTOOL_GLINK: {
2173 struct ethtool_value edata = { ETHTOOL_GLINK };
2174 spin_lock_irq(&smc->lock);
2175 edata.data = smc_link_ok(dev);
2176 spin_unlock_irq(&smc->lock);
2177 if (copy_to_user(useraddr, &edata, sizeof(edata)))
2183 /* get message-level */
2184 case ETHTOOL_GMSGLVL: {
2185 struct ethtool_value edata = { ETHTOOL_GMSGLVL };
2186 edata.data = pc_debug;
2187 if (copy_to_user(useraddr, &edata, sizeof(edata)))
2192 /* set message-level */
2193 case ETHTOOL_SMSGLVL: {
2194 struct ethtool_value edata;
2195 if (copy_from_user(&edata, useraddr, sizeof(edata)))
2197 pc_debug = edata.data;
2201 /* restart autonegotiation */
2202 case ETHTOOL_NWAY_RST: {
2203 if (smc->cfg & CFG_MII_SELECT)
2204 return mii_nway_restart(&smc->mii_if);
2216 static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
2218 struct smc_private *smc = netdev_priv(dev);
2219 struct mii_ioctl_data *mii;
2222 ioaddr_t ioaddr = dev->base_addr;
2225 if (!netif_running(dev))
2230 saved_bank = inw(ioaddr + BANK_SELECT);
2232 rc = smc_ethtool_ioctl(dev, rq->ifr_data);
2233 SMC_SELECT_BANK(saved_bank);
2237 spin_lock_irq(&smc->lock);
2238 saved_bank = inw(ioaddr + BANK_SELECT);
2240 rc = generic_mii_ioctl(&smc->mii_if, mii, cmd, NULL);
2241 SMC_SELECT_BANK(saved_bank);
2242 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);