1 /*======================================================================
3 A PCMCIA ethernet driver for SMC91c92-based cards.
5 This driver supports Megahertz PCMCIA ethernet cards; and
6 Megahertz, Motorola, Ositech, and Psion Dacom ethernet/modem
9 Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net
11 smc91c92_cs.c 1.122 2002/10/25 06:26:39
13 This driver contains code written by Donald Becker
14 (becker@scyld.com), Rowan Hughes (x-csrdh@jcu.edu.au),
15 David Hinds (dahinds@users.sourceforge.net), and Erik Stahlman
16 (erik@vt.edu). Donald wrote the SMC 91c92 code using parts of
17 Erik's SMC 91c94 driver. Rowan wrote a similar driver, and I've
18 incorporated some parts of his driver here. I (Dave) wrote most
19 of the PCMCIA glue code, and the Ositech support code. Kelly
20 Stephens (kstephen@holli.com) added support for the Motorola
21 Mariner, with help from Allen Brost.
23 This software may be used and distributed according to the terms of
24 the GNU General Public License, incorporated herein by reference.
26 ======================================================================*/
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/string.h>
33 #include <linux/timer.h>
34 #include <linux/interrupt.h>
35 #include <linux/delay.h>
36 #include <linux/crc32.h>
37 #include <linux/netdevice.h>
38 #include <linux/etherdevice.h>
39 #include <linux/skbuff.h>
40 #include <linux/if_arp.h>
41 #include <linux/ioport.h>
42 #include <linux/ethtool.h>
43 #include <linux/mii.h>
44 #include <linux/jiffies.h>
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_param(n, int, 0)
72 Transceiver/media type.
74 1 = 10baseT (and autoselect if #define AUTOSELECT),
77 INT_MODULE_PARM(if_port, 0);
80 INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
81 static const char *version =
82 "smc91c92_cs.c 0.09 1996/8/4 Donald Becker, becker@scyld.com.\n";
83 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
85 #define DEBUG(n, args...)
88 #define DRV_NAME "smc91c92_cs"
89 #define DRV_VERSION "1.122"
91 /*====================================================================*/
93 /* Operational parameter that usually are not changed. */
95 /* Time in jiffies before concluding Tx hung */
96 #define TX_TIMEOUT ((400*HZ)/1000)
98 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
101 /* Times to check the check the chip before concluding that it doesn't
102 currently have room for another Tx packet. */
103 #define MEMORY_WAIT_TIME 8
105 static dev_info_t dev_info = "smc91c92_cs";
107 static dev_link_t *dev_list;
114 struct net_device_stats stats;
116 struct sk_buff *saved_skb;
120 struct timer_list media;
121 int watchdog, tx_err;
122 u_short media_status;
125 struct mii_if_info mii_if;
136 /* Special definitions for Megahertz multifunction cards */
137 #define MEGAHERTZ_ISR 0x0380
139 /* Special function registers for Motorola Mariner */
140 #define MOT_LAN 0x0000
141 #define MOT_UART 0x0020
142 #define MOT_EEPROM 0x20
145 (COR_LEVEL_REQ | COR_FUNC_ENA | COR_ADDR_DECODE | COR_IREQ_ENA)
147 /* Special function registers for Ositech cards */
148 #define OSITECH_AUI_CTL 0x0c
149 #define OSITECH_PWRDOWN 0x0d
150 #define OSITECH_RESET 0x0e
151 #define OSITECH_ISR 0x0f
152 #define OSITECH_AUI_PWR 0x0c
153 #define OSITECH_RESET_ISR 0x0e
155 #define OSI_AUI_PWR 0x40
156 #define OSI_LAN_PWRDOWN 0x02
157 #define OSI_MODEM_PWRDOWN 0x01
158 #define OSI_LAN_RESET 0x02
159 #define OSI_MODEM_RESET 0x01
161 /* Symbolic constants for the SMC91c9* series chips, from Erik Stahlman. */
162 #define BANK_SELECT 14 /* Window select register. */
163 #define SMC_SELECT_BANK(x) { outw(x, ioaddr + BANK_SELECT); }
165 /* Bank 0 registers. */
166 #define TCR 0 /* transmit control register */
167 #define TCR_CLEAR 0 /* do NOTHING */
168 #define TCR_ENABLE 0x0001 /* if this is 1, we can transmit */
169 #define TCR_PAD_EN 0x0080 /* pads short packets to 64 bytes */
170 #define TCR_MONCSN 0x0400 /* Monitor Carrier. */
171 #define TCR_FDUPLX 0x0800 /* Full duplex mode. */
172 #define TCR_NORMAL TCR_ENABLE | TCR_PAD_EN
174 #define EPH 2 /* Ethernet Protocol Handler report. */
175 #define EPH_TX_SUC 0x0001
176 #define EPH_SNGLCOL 0x0002
177 #define EPH_MULCOL 0x0004
178 #define EPH_LTX_MULT 0x0008
179 #define EPH_16COL 0x0010
180 #define EPH_SQET 0x0020
181 #define EPH_LTX_BRD 0x0040
182 #define EPH_TX_DEFR 0x0080
183 #define EPH_LAT_COL 0x0200
184 #define EPH_LOST_CAR 0x0400
185 #define EPH_EXC_DEF 0x0800
186 #define EPH_CTR_ROL 0x1000
187 #define EPH_RX_OVRN 0x2000
188 #define EPH_LINK_OK 0x4000
189 #define EPH_TX_UNRN 0x8000
190 #define MEMINFO 8 /* Memory Information Register */
191 #define MEMCFG 10 /* Memory Configuration Register */
193 /* Bank 1 registers. */
195 #define CFG_MII_SELECT 0x8000 /* 91C100 only */
196 #define CFG_NO_WAIT 0x1000
197 #define CFG_FULL_STEP 0x0400
198 #define CFG_SET_SQLCH 0x0200
199 #define CFG_AUI_SELECT 0x0100
200 #define CFG_16BIT 0x0080
201 #define CFG_DIS_LINK 0x0040
202 #define CFG_STATIC 0x0030
203 #define CFG_IRQ_SEL_1 0x0004
204 #define CFG_IRQ_SEL_0 0x0002
209 #define CTL_STORE 0x0001
210 #define CTL_RELOAD 0x0002
211 #define CTL_EE_SELECT 0x0004
212 #define CTL_TE_ENABLE 0x0020
213 #define CTL_CR_ENABLE 0x0040
214 #define CTL_LE_ENABLE 0x0080
215 #define CTL_AUTO_RELEASE 0x0800
216 #define CTL_POWERDOWN 0x2000
218 /* Bank 2 registers. */
220 #define MC_ALLOC 0x20 /* or with number of 256 byte packets */
221 #define MC_RESET 0x40
222 #define MC_RELEASE 0x80 /* remove and release the current rx packet */
223 #define MC_FREEPKT 0xA0 /* Release packet in PNR register */
224 #define MC_ENQUEUE 0xC0 /* Enqueue the packet for transmit */
227 #define FP_RXEMPTY 0x8000
229 #define PTR_AUTO_INC 0x0040
230 #define PTR_READ 0x2000
231 #define PTR_AUTOINC 0x4000
232 #define PTR_RCV 0x8000
235 #define IM_RCV_INT 0x1
236 #define IM_TX_INT 0x2
237 #define IM_TX_EMPTY_INT 0x4
238 #define IM_ALLOC_INT 0x8
239 #define IM_RX_OVRN_INT 0x10
240 #define IM_EPH_INT 0x20
243 enum RxCfg { RxAllMulti = 0x0004, RxPromisc = 0x0002,
244 RxEnable = 0x0100, RxStripCRC = 0x0200};
245 #define RCR_SOFTRESET 0x8000 /* resets the chip */
246 #define RCR_STRIP_CRC 0x200 /* strips CRC */
247 #define RCR_ENABLE 0x100 /* IFF this is set, we can receive packets */
248 #define RCR_ALMUL 0x4 /* receive all multicast packets */
249 #define RCR_PROMISC 0x2 /* enable promiscuous mode */
251 /* the normal settings for the RCR register : */
252 #define RCR_NORMAL (RCR_STRIP_CRC | RCR_ENABLE)
253 #define RCR_CLEAR 0x0 /* set it to a base state */
256 /* BANK 3 -- not the same values as in smc9194! */
262 #define REVISION 0x0a
264 /* Transmit status bits. */
265 #define TS_SUCCESS 0x0001
266 #define TS_16COL 0x0010
267 #define TS_LATCOL 0x0200
268 #define TS_LOSTCAR 0x0400
270 /* Receive status bits. */
271 #define RS_ALGNERR 0x8000
272 #define RS_BADCRC 0x2000
273 #define RS_ODDFRAME 0x1000
274 #define RS_TOOLONG 0x0800
275 #define RS_TOOSHORT 0x0400
276 #define RS_MULTICAST 0x0001
277 #define RS_ERRORS (RS_ALGNERR | RS_BADCRC | RS_TOOLONG | RS_TOOSHORT)
279 #define set_bits(v, p) outw(inw(p)|(v), (p))
280 #define mask_bits(v, p) outw(inw(p)&(v), (p))
282 /*====================================================================*/
284 static dev_link_t *smc91c92_attach(void);
285 static void smc91c92_detach(dev_link_t *);
286 static void smc91c92_config(dev_link_t *link);
287 static void smc91c92_release(dev_link_t *link);
288 static int smc91c92_event(event_t event, int priority,
289 event_callback_args_t *args);
291 static int smc_open(struct net_device *dev);
292 static int smc_close(struct net_device *dev);
293 static int smc_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
294 static void smc_tx_timeout(struct net_device *dev);
295 static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev);
296 static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
297 static void smc_rx(struct net_device *dev);
298 static struct net_device_stats *smc_get_stats(struct net_device *dev);
299 static void set_rx_mode(struct net_device *dev);
300 static int s9k_config(struct net_device *dev, struct ifmap *map);
301 static void smc_set_xcvr(struct net_device *dev, int if_port);
302 static void smc_reset(struct net_device *dev);
303 static void media_check(u_long arg);
304 static void mdio_sync(kio_addr_t addr);
305 static int mdio_read(struct net_device *dev, int phy_id, int loc);
306 static void mdio_write(struct net_device *dev, int phy_id, int loc, int value);
307 static int smc_link_ok(struct net_device *dev);
308 static struct ethtool_ops ethtool_ops;
310 /*======================================================================
312 smc91c92_attach() creates an "instance" of the driver, allocating
313 local data structures for one device. The device is registered
316 ======================================================================*/
318 static dev_link_t *smc91c92_attach(void)
320 client_reg_t client_reg;
321 struct smc_private *smc;
323 struct net_device *dev;
326 DEBUG(0, "smc91c92_attach()\n");
328 /* Create new ethernet device */
329 dev = alloc_etherdev(sizeof(struct smc_private));
332 smc = netdev_priv(dev);
336 spin_lock_init(&smc->lock);
337 link->io.NumPorts1 = 16;
338 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
339 link->io.IOAddrLines = 4;
340 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
341 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
342 link->irq.Handler = &smc_interrupt;
343 link->irq.Instance = dev;
344 link->conf.Attributes = CONF_ENABLE_IRQ;
346 link->conf.IntType = INT_MEMORY_AND_IO;
348 /* The SMC91c92-specific entries in the device structure. */
349 SET_MODULE_OWNER(dev);
350 dev->hard_start_xmit = &smc_start_xmit;
351 dev->get_stats = &smc_get_stats;
352 dev->set_config = &s9k_config;
353 dev->set_multicast_list = &set_rx_mode;
354 dev->open = &smc_open;
355 dev->stop = &smc_close;
356 dev->do_ioctl = &smc_ioctl;
357 SET_ETHTOOL_OPS(dev, ðtool_ops);
358 #ifdef HAVE_TX_TIMEOUT
359 dev->tx_timeout = smc_tx_timeout;
360 dev->watchdog_timeo = TX_TIMEOUT;
363 smc->mii_if.dev = dev;
364 smc->mii_if.mdio_read = mdio_read;
365 smc->mii_if.mdio_write = mdio_write;
366 smc->mii_if.phy_id_mask = 0x1f;
367 smc->mii_if.reg_num_mask = 0x1f;
369 /* Register with Card Services */
370 link->next = dev_list;
372 client_reg.dev_info = &dev_info;
373 client_reg.Version = 0x0210;
374 client_reg.event_callback_args.client_data = link;
375 ret = pcmcia_register_client(&link->handle, &client_reg);
377 cs_error(link->handle, RegisterClient, ret);
378 smc91c92_detach(link);
383 } /* smc91c92_attach */
385 /*======================================================================
387 This deletes a driver "instance". The device is de-registered
388 with Card Services. If it has been released, all local data
389 structures are freed. Otherwise, the structures will be freed
390 when the device is released.
392 ======================================================================*/
394 static void smc91c92_detach(dev_link_t *link)
396 struct net_device *dev = link->priv;
399 DEBUG(0, "smc91c92_detach(0x%p)\n", link);
401 /* Locate device structure */
402 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
403 if (*linkp == link) break;
408 unregister_netdev(dev);
410 if (link->state & DEV_CONFIG)
411 smc91c92_release(link);
414 pcmcia_deregister_client(link->handle);
416 /* Unlink device structure, free bits */
419 } /* smc91c92_detach */
421 /*====================================================================*/
423 static int cvt_ascii_address(struct net_device *dev, char *s)
429 for (i = 0; i < 6; i++) {
431 for (j = 0; j < 2; j++) {
434 da += ((c >= '0') && (c <= '9')) ?
435 (c - '0') : ((c & 0x0f) + 9);
437 dev->dev_addr[i] = da;
442 /*====================================================================*/
444 static int first_tuple(client_handle_t handle, tuple_t *tuple,
449 if ((i = pcmcia_get_first_tuple(handle, tuple)) != CS_SUCCESS ||
450 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
452 return pcmcia_parse_tuple(handle, tuple, parse);
455 static int next_tuple(client_handle_t handle, tuple_t *tuple,
460 if ((i = pcmcia_get_next_tuple(handle, tuple)) != CS_SUCCESS ||
461 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
463 return pcmcia_parse_tuple(handle, tuple, parse);
466 /*======================================================================
468 Configuration stuff for Megahertz cards
470 mhz_3288_power() is used to power up a 3288's ethernet chip.
471 mhz_mfc_config() handles socket setup for multifunction (1144
472 and 3288) cards. mhz_setup() gets a card's hardware ethernet
475 ======================================================================*/
477 static int mhz_3288_power(dev_link_t *link)
479 struct net_device *dev = link->priv;
480 struct smc_private *smc = netdev_priv(dev);
483 /* Read the ISR twice... */
484 readb(smc->base+MEGAHERTZ_ISR);
486 readb(smc->base+MEGAHERTZ_ISR);
491 /* Now read and write the COR... */
492 tmp = readb(smc->base + link->conf.ConfigBase + CISREG_COR);
494 writeb(tmp, smc->base + link->conf.ConfigBase + CISREG_COR);
499 static int mhz_mfc_config(dev_link_t *link)
501 struct net_device *dev = link->priv;
502 struct smc_private *smc = netdev_priv(dev);
503 struct smc_cfg_mem *cfg_mem;
506 cistpl_cftable_entry_t *cf;
512 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
514 return CS_OUT_OF_RESOURCE;
516 tuple = &cfg_mem->tuple;
517 parse = &cfg_mem->parse;
518 cf = &parse->cftable_entry;
521 link->conf.Attributes |= CONF_ENABLE_SPKR;
522 link->conf.Status = CCSR_AUDIO_ENA;
523 link->irq.Attributes =
524 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
525 link->io.IOAddrLines = 16;
526 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
527 link->io.NumPorts2 = 8;
529 tuple->Attributes = tuple->TupleOffset = 0;
530 tuple->TupleData = (cisdata_t *)buf;
531 tuple->TupleDataMax = 255;
532 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
534 i = first_tuple(link->handle, tuple, parse);
535 /* The Megahertz combo cards have modem-like CIS entries, so
536 we have to explicitly try a bunch of port combinations. */
537 while (i == CS_SUCCESS) {
538 link->conf.ConfigIndex = cf->index;
539 link->io.BasePort2 = cf->io.win[0].base;
540 for (k = 0; k < 0x400; k += 0x10) {
541 if (k & 0x80) continue;
542 link->io.BasePort1 = k ^ 0x300;
543 i = pcmcia_request_io(link->handle, &link->io);
544 if (i == CS_SUCCESS) break;
546 if (i == CS_SUCCESS) break;
547 i = next_tuple(link->handle, tuple, parse);
551 dev->base_addr = link->io.BasePort1;
553 /* Allocate a memory window, for accessing the ISR */
554 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
555 req.Base = req.Size = 0;
557 i = pcmcia_request_window(&link->handle, &req, &link->win);
560 smc->base = ioremap(req.Base, req.Size);
561 mem.CardOffset = mem.Page = 0;
562 if (smc->manfid == MANFID_MOTOROLA)
563 mem.CardOffset = link->conf.ConfigBase;
564 i = pcmcia_map_mem_page(link->win, &mem);
566 if ((i == CS_SUCCESS)
567 && (smc->manfid == MANFID_MEGAHERTZ)
568 && (smc->cardid == PRODID_MEGAHERTZ_EM3288))
569 mhz_3288_power(link);
576 static int mhz_setup(dev_link_t *link)
578 client_handle_t handle = link->handle;
579 struct net_device *dev = link->priv;
580 struct smc_cfg_mem *cfg_mem;
583 u_char *buf, *station_addr;
586 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
590 tuple = &cfg_mem->tuple;
591 parse = &cfg_mem->parse;
594 tuple->Attributes = tuple->TupleOffset = 0;
595 tuple->TupleData = (cisdata_t *)buf;
596 tuple->TupleDataMax = 255;
598 /* Read the station address from the CIS. It is stored as the last
599 (fourth) string in the Version 1 Version/ID tuple. */
600 tuple->DesiredTuple = CISTPL_VERS_1;
601 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {
605 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
606 if (next_tuple(handle, tuple, parse) != CS_SUCCESS)
607 first_tuple(handle, tuple, parse);
608 if (parse->version_1.ns > 3) {
609 station_addr = parse->version_1.str + parse->version_1.ofs[3];
610 if (cvt_ascii_address(dev, station_addr) == 0) {
616 /* Another possibility: for the EM3288, in a special tuple */
617 tuple->DesiredTuple = 0x81;
618 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) {
622 if (pcmcia_get_tuple_data(handle, tuple) != CS_SUCCESS) {
627 if (cvt_ascii_address(dev, buf) == 0) {
637 /*======================================================================
639 Configuration stuff for the Motorola Mariner
641 mot_config() writes directly to the Mariner configuration
642 registers because the CIS is just bogus.
644 ======================================================================*/
646 static void mot_config(dev_link_t *link)
648 struct net_device *dev = link->priv;
649 struct smc_private *smc = netdev_priv(dev);
650 kio_addr_t ioaddr = dev->base_addr;
651 kio_addr_t iouart = link->io.BasePort2;
653 /* Set UART base address and force map with COR bit 1 */
654 writeb(iouart & 0xff, smc->base + MOT_UART + CISREG_IOBASE_0);
655 writeb((iouart >> 8) & 0xff, smc->base + MOT_UART + CISREG_IOBASE_1);
656 writeb(MOT_NORMAL, smc->base + MOT_UART + CISREG_COR);
658 /* Set SMC base address and force map with COR bit 1 */
659 writeb(ioaddr & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_0);
660 writeb((ioaddr >> 8) & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_1);
661 writeb(MOT_NORMAL, smc->base + MOT_LAN + CISREG_COR);
663 /* Wait for things to settle down */
667 static int mot_setup(dev_link_t *link)
669 struct net_device *dev = link->priv;
670 kio_addr_t ioaddr = dev->base_addr;
674 /* Read Ethernet address from Serial EEPROM */
676 for (i = 0; i < 3; i++) {
678 outw(MOT_EEPROM + i, ioaddr + POINTER);
680 outw((CTL_RELOAD | CTL_EE_SELECT), ioaddr + CONTROL);
682 for (loop = wait = 0; loop < 200; loop++) {
684 wait = ((CTL_RELOAD | CTL_STORE) & inw(ioaddr + CONTROL));
685 if (wait == 0) break;
691 addr = inw(ioaddr + GENERAL);
692 dev->dev_addr[2*i] = addr & 0xff;
693 dev->dev_addr[2*i+1] = (addr >> 8) & 0xff;
699 /*====================================================================*/
701 static int smc_config(dev_link_t *link)
703 struct net_device *dev = link->priv;
704 struct smc_cfg_mem *cfg_mem;
707 cistpl_cftable_entry_t *cf;
711 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
713 return CS_OUT_OF_RESOURCE;
715 tuple = &cfg_mem->tuple;
716 parse = &cfg_mem->parse;
717 cf = &parse->cftable_entry;
720 tuple->Attributes = tuple->TupleOffset = 0;
721 tuple->TupleData = (cisdata_t *)buf;
722 tuple->TupleDataMax = 255;
723 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
725 link->io.NumPorts1 = 16;
726 i = first_tuple(link->handle, tuple, parse);
727 while (i != CS_NO_MORE_ITEMS) {
728 if (i == CS_SUCCESS) {
729 link->conf.ConfigIndex = cf->index;
730 link->io.BasePort1 = cf->io.win[0].base;
731 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
732 i = pcmcia_request_io(link->handle, &link->io);
733 if (i == CS_SUCCESS) break;
735 i = next_tuple(link->handle, tuple, parse);
738 dev->base_addr = link->io.BasePort1;
744 static int smc_setup(dev_link_t *link)
746 client_handle_t handle = link->handle;
747 struct net_device *dev = link->priv;
748 struct smc_cfg_mem *cfg_mem;
751 cistpl_lan_node_id_t *node_id;
752 u_char *buf, *station_addr;
755 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
757 return CS_OUT_OF_RESOURCE;
759 tuple = &cfg_mem->tuple;
760 parse = &cfg_mem->parse;
763 tuple->Attributes = tuple->TupleOffset = 0;
764 tuple->TupleData = (cisdata_t *)buf;
765 tuple->TupleDataMax = 255;
767 /* Check for a LAN function extension tuple */
768 tuple->DesiredTuple = CISTPL_FUNCE;
769 i = first_tuple(handle, tuple, parse);
770 while (i == CS_SUCCESS) {
771 if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID)
773 i = next_tuple(handle, tuple, parse);
775 if (i == CS_SUCCESS) {
776 node_id = (cistpl_lan_node_id_t *)parse->funce.data;
777 if (node_id->nb == 6) {
778 for (i = 0; i < 6; i++)
779 dev->dev_addr[i] = node_id->id[i];
784 /* Try the third string in the Version 1 Version/ID tuple. */
785 tuple->DesiredTuple = CISTPL_VERS_1;
786 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {
790 station_addr = parse->version_1.str + parse->version_1.ofs[2];
791 if (cvt_ascii_address(dev, station_addr) == 0) {
802 /*====================================================================*/
804 static int osi_config(dev_link_t *link)
806 struct net_device *dev = link->priv;
807 static kio_addr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
810 link->conf.Attributes |= CONF_ENABLE_SPKR;
811 link->conf.Status = CCSR_AUDIO_ENA;
812 link->irq.Attributes =
813 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
814 link->io.NumPorts1 = 64;
815 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
816 link->io.NumPorts2 = 8;
817 link->io.IOAddrLines = 16;
819 /* Enable Hard Decode, LAN, Modem */
820 link->conf.ConfigIndex = 0x23;
822 for (i = j = 0; j < 4; j++) {
823 link->io.BasePort2 = com[j];
824 i = pcmcia_request_io(link->handle, &link->io);
825 if (i == CS_SUCCESS) break;
827 if (i != CS_SUCCESS) {
828 /* Fallback: turn off hard decode */
829 link->conf.ConfigIndex = 0x03;
830 link->io.NumPorts2 = 0;
831 i = pcmcia_request_io(link->handle, &link->io);
833 dev->base_addr = link->io.BasePort1 + 0x10;
837 static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid)
839 client_handle_t handle = link->handle;
840 struct net_device *dev = link->priv;
841 struct smc_cfg_mem *cfg_mem;
846 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
850 tuple = &cfg_mem->tuple;
853 tuple->Attributes = TUPLE_RETURN_COMMON;
854 tuple->TupleData = (cisdata_t *)buf;
855 tuple->TupleDataMax = 255;
856 tuple->TupleOffset = 0;
858 /* Read the station address from tuple 0x90, subtuple 0x04 */
859 tuple->DesiredTuple = 0x90;
860 i = pcmcia_get_first_tuple(handle, tuple);
861 while (i == CS_SUCCESS) {
862 i = pcmcia_get_tuple_data(handle, tuple);
863 if ((i != CS_SUCCESS) || (buf[0] == 0x04))
865 i = pcmcia_get_next_tuple(handle, tuple);
867 if (i != CS_SUCCESS) {
871 for (i = 0; i < 6; i++)
872 dev->dev_addr[i] = buf[i+2];
874 if (((manfid == MANFID_OSITECH) &&
875 (cardid == PRODID_OSITECH_SEVEN)) ||
876 ((manfid == MANFID_PSION) &&
877 (cardid == PRODID_PSION_NET100))) {
878 /* Download the Seven of Diamonds firmware */
879 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
880 outb(__Xilinx7OD[i], link->io.BasePort1+2);
883 } else if (manfid == MANFID_OSITECH) {
884 /* Make sure both functions are powered up */
885 set_bits(0x300, link->io.BasePort1 + OSITECH_AUI_PWR);
886 /* Now, turn on the interrupt for both card functions */
887 set_bits(0x300, link->io.BasePort1 + OSITECH_RESET_ISR);
888 DEBUG(2, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n",
889 inw(link->io.BasePort1 + OSITECH_AUI_PWR),
890 inw(link->io.BasePort1 + OSITECH_RESET_ISR));
898 static int smc91c92_suspend(struct pcmcia_device *p_dev)
900 dev_link_t *link = dev_to_instance(p_dev);
901 struct net_device *dev = link->priv;
903 link->state |= DEV_SUSPEND;
904 if (link->state & DEV_CONFIG) {
906 netif_device_detach(dev);
907 pcmcia_release_configuration(link->handle);
913 static int smc91c92_resume(struct pcmcia_device *p_dev)
915 dev_link_t *link = dev_to_instance(p_dev);
916 struct net_device *dev = link->priv;
917 struct smc_private *smc = netdev_priv(dev);
920 link->state &= ~DEV_SUSPEND;
921 if (link->state & DEV_CONFIG) {
922 if ((smc->manfid == MANFID_MEGAHERTZ) &&
923 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
924 mhz_3288_power(link);
925 pcmcia_request_configuration(link->handle, &link->conf);
926 if (smc->manfid == MANFID_MOTOROLA)
928 if ((smc->manfid == MANFID_OSITECH) &&
929 (smc->cardid != PRODID_OSITECH_SEVEN)) {
930 /* Power up the card and enable interrupts */
931 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR);
932 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR);
934 if (((smc->manfid == MANFID_OSITECH) &&
935 (smc->cardid == PRODID_OSITECH_SEVEN)) ||
936 ((smc->manfid == MANFID_PSION) &&
937 (smc->cardid == PRODID_PSION_NET100))) {
938 /* Download the Seven of Diamonds firmware */
939 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
940 outb(__Xilinx7OD[i], link->io.BasePort1+2);
946 netif_device_attach(dev);
954 /*======================================================================
956 This verifies that the chip is some SMC91cXX variant, and returns
957 the revision code if successful. Otherwise, it returns -ENODEV.
959 ======================================================================*/
961 static int check_sig(dev_link_t *link)
963 struct net_device *dev = link->priv;
964 kio_addr_t ioaddr = dev->base_addr;
969 if (inw(ioaddr + BANK_SELECT) >> 8 != 0x33) {
970 /* Try powering up the chip */
971 outw(0, ioaddr + CONTROL);
975 /* Try setting bus width */
976 width = (link->io.Attributes1 == IO_DATA_PATH_WIDTH_AUTO);
977 s = inb(ioaddr + CONFIG);
982 outb(s, ioaddr + CONFIG);
984 /* Check Base Address Register to make sure bus width is OK */
985 s = inw(ioaddr + BASE_ADDR);
986 if ((inw(ioaddr + BANK_SELECT) >> 8 == 0x33) &&
987 ((s >> 8) != (s & 0xff))) {
989 s = inw(ioaddr + REVISION);
994 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n");
995 smc91c92_suspend(link->handle);
996 pcmcia_release_io(link->handle, &link->io);
997 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
998 pcmcia_request_io(link->handle, &link->io);
999 smc91c92_resume(link->handle);
1000 return check_sig(link);
1005 /*======================================================================
1007 smc91c92_config() is scheduled to run after a CARD_INSERTION event
1008 is received, to configure the PCMCIA socket, and to make the
1009 ethernet device available to the system.
1011 ======================================================================*/
1013 #define CS_EXIT_TEST(ret, svc, label) \
1014 if (ret != CS_SUCCESS) { cs_error(link->handle, svc, ret); goto label; }
1016 static void smc91c92_config(dev_link_t *link)
1018 client_handle_t handle = link->handle;
1019 struct net_device *dev = link->priv;
1020 struct smc_private *smc = netdev_priv(dev);
1021 struct smc_cfg_mem *cfg_mem;
1030 DEBUG(0, "smc91c92_config(0x%p)\n", link);
1032 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
1036 tuple = &cfg_mem->tuple;
1037 parse = &cfg_mem->parse;
1040 tuple->Attributes = tuple->TupleOffset = 0;
1041 tuple->TupleData = (cisdata_t *)buf;
1042 tuple->TupleDataMax = 64;
1044 tuple->DesiredTuple = CISTPL_CONFIG;
1045 i = first_tuple(handle, tuple, parse);
1046 CS_EXIT_TEST(i, ParseTuple, config_failed);
1047 link->conf.ConfigBase = parse->config.base;
1048 link->conf.Present = parse->config.rmask[0];
1050 tuple->DesiredTuple = CISTPL_MANFID;
1051 tuple->Attributes = TUPLE_RETURN_COMMON;
1052 if (first_tuple(handle, tuple, parse) == CS_SUCCESS) {
1053 smc->manfid = parse->manfid.manf;
1054 smc->cardid = parse->manfid.card;
1057 /* Configure card */
1058 link->state |= DEV_CONFIG;
1060 if ((smc->manfid == MANFID_OSITECH) &&
1061 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1062 i = osi_config(link);
1063 } else if ((smc->manfid == MANFID_MOTOROLA) ||
1064 ((smc->manfid == MANFID_MEGAHERTZ) &&
1065 ((smc->cardid == PRODID_MEGAHERTZ_VARIOUS) ||
1066 (smc->cardid == PRODID_MEGAHERTZ_EM3288)))) {
1067 i = mhz_mfc_config(link);
1069 i = smc_config(link);
1071 CS_EXIT_TEST(i, RequestIO, config_failed);
1073 i = pcmcia_request_irq(link->handle, &link->irq);
1074 CS_EXIT_TEST(i, RequestIRQ, config_failed);
1075 i = pcmcia_request_configuration(link->handle, &link->conf);
1076 CS_EXIT_TEST(i, RequestConfiguration, config_failed);
1078 if (smc->manfid == MANFID_MOTOROLA)
1081 dev->irq = link->irq.AssignedIRQ;
1083 if ((if_port >= 0) && (if_port <= 2))
1084 dev->if_port = if_port;
1086 printk(KERN_NOTICE "smc91c92_cs: invalid if_port requested\n");
1088 switch (smc->manfid) {
1089 case MANFID_OSITECH:
1091 i = osi_setup(link, smc->manfid, smc->cardid); break;
1093 case MANFID_NEW_MEDIA:
1094 i = smc_setup(link); break;
1095 case 0x128: /* For broken Megahertz cards */
1096 case MANFID_MEGAHERTZ:
1097 i = mhz_setup(link); break;
1098 case MANFID_MOTOROLA:
1099 default: /* get the hw address from EEPROM */
1100 i = mot_setup(link); break;
1104 printk(KERN_NOTICE "smc91c92_cs: Unable to find hardware address.\n");
1111 rev = check_sig(link);
1115 case 3: name = "92"; break;
1116 case 4: name = ((rev & 15) >= 6) ? "96" : "94"; break;
1117 case 5: name = "95"; break;
1118 case 7: name = "100"; break;
1119 case 8: name = "100-FD"; break;
1120 case 9: name = "110"; break;
1123 ioaddr = dev->base_addr;
1127 mir = inw(ioaddr + MEMINFO) & 0xff;
1128 if (mir == 0xff) mir++;
1129 /* Get scale factor for memory size */
1130 mcr = ((rev >> 4) > 3) ? inw(ioaddr + MEMCFG) : 0x0200;
1131 mir *= 128 * (1<<((mcr >> 9) & 7));
1133 smc->cfg = inw(ioaddr + CONFIG) & ~CFG_AUI_SELECT;
1134 smc->cfg |= CFG_NO_WAIT | CFG_16BIT | CFG_STATIC;
1135 if (smc->manfid == MANFID_OSITECH)
1136 smc->cfg |= CFG_IRQ_SEL_1 | CFG_IRQ_SEL_0;
1137 if ((rev >> 4) >= 7)
1138 smc->cfg |= CFG_MII_SELECT;
1142 if (smc->cfg & CFG_MII_SELECT) {
1145 for (i = 0; i < 32; i++) {
1146 j = mdio_read(dev, i, 1);
1147 if ((j != 0) && (j != 0xffff)) break;
1149 smc->mii_if.phy_id = (i < 32) ? i : -1;
1154 link->dev = &smc->node;
1155 link->state &= ~DEV_CONFIG_PENDING;
1156 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
1158 if (register_netdev(dev) != 0) {
1159 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n");
1164 strcpy(smc->node.dev_name, dev->name);
1166 printk(KERN_INFO "%s: smc91c%s rev %d: io %#3lx, irq %d, "
1167 "hw_addr ", dev->name, name, (rev & 0x0f), dev->base_addr,
1169 for (i = 0; i < 6; i++)
1170 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
1174 printk(KERN_INFO " %lu byte", mir);
1176 printk(KERN_INFO " %lu kb", mir>>10);
1177 printk(" buffer, %s xcvr\n", (smc->cfg & CFG_MII_SELECT) ?
1178 "MII" : if_names[dev->if_port]);
1181 if (smc->cfg & CFG_MII_SELECT) {
1182 if (smc->mii_if.phy_id != -1) {
1183 DEBUG(0, " MII transceiver at index %d, status %x.\n",
1184 smc->mii_if.phy_id, j);
1186 printk(KERN_NOTICE " No MII transceivers found!\n");
1193 unregister_netdev(dev);
1194 config_failed: /* CS_EXIT_TEST() calls jump to here... */
1195 smc91c92_release(link);
1196 link->state &= ~DEV_CONFIG_PENDING;
1199 } /* smc91c92_config */
1201 /*======================================================================
1203 After a card is removed, smc91c92_release() will unregister the net
1204 device, and release the PCMCIA configuration. If the device is
1205 still open, this will be postponed until it is closed.
1207 ======================================================================*/
1209 static void smc91c92_release(dev_link_t *link)
1212 DEBUG(0, "smc91c92_release(0x%p)\n", link);
1214 pcmcia_release_configuration(link->handle);
1215 pcmcia_release_io(link->handle, &link->io);
1216 pcmcia_release_irq(link->handle, &link->irq);
1218 struct net_device *dev = link->priv;
1219 struct smc_private *smc = netdev_priv(dev);
1221 pcmcia_release_window(link->win);
1224 link->state &= ~DEV_CONFIG;
1227 /*======================================================================
1229 The card status event handler. Mostly, this schedules other
1230 stuff to run after an event is received. A CARD_REMOVAL event
1231 also sets some flags to discourage the net drivers from trying
1232 to talk to the card any more.
1234 ======================================================================*/
1236 static int smc91c92_event(event_t event, int priority,
1237 event_callback_args_t *args)
1239 dev_link_t *link = args->client_data;
1240 struct net_device *dev = link->priv;
1242 DEBUG(1, "smc91c92_event(0x%06x)\n", event);
1245 case CS_EVENT_CARD_REMOVAL:
1246 link->state &= ~DEV_PRESENT;
1247 if (link->state & DEV_CONFIG)
1248 netif_device_detach(dev);
1250 case CS_EVENT_CARD_INSERTION:
1251 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1252 smc91c92_config(link);
1256 } /* smc91c92_event */
1258 /*======================================================================
1260 MII interface support for SMC91cXX based cards
1261 ======================================================================*/
1263 #define MDIO_SHIFT_CLK 0x04
1264 #define MDIO_DATA_OUT 0x01
1265 #define MDIO_DIR_WRITE 0x08
1266 #define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
1267 #define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
1268 #define MDIO_DATA_READ 0x02
1270 static void mdio_sync(kio_addr_t addr)
1273 for (bits = 0; bits < 32; bits++) {
1274 outb(MDIO_DATA_WRITE1, addr);
1275 outb(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
1279 static int mdio_read(struct net_device *dev, int phy_id, int loc)
1281 kio_addr_t addr = dev->base_addr + MGMT;
1282 u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
1286 for (i = 13; i >= 0; i--) {
1287 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1289 outb(dat | MDIO_SHIFT_CLK, addr);
1291 for (i = 19; i > 0; i--) {
1293 retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
1294 outb(MDIO_SHIFT_CLK, addr);
1296 return (retval>>1) & 0xffff;
1299 static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
1301 kio_addr_t addr = dev->base_addr + MGMT;
1302 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
1306 for (i = 31; i >= 0; i--) {
1307 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1309 outb(dat | MDIO_SHIFT_CLK, addr);
1311 for (i = 1; i >= 0; i--) {
1313 outb(MDIO_SHIFT_CLK, addr);
1317 /*======================================================================
1319 The driver core code, most of which should be common with a
1320 non-PCMCIA implementation.
1322 ======================================================================*/
1325 static void smc_dump(struct net_device *dev)
1327 kio_addr_t ioaddr = dev->base_addr;
1329 save = inw(ioaddr + BANK_SELECT);
1330 for (w = 0; w < 4; w++) {
1332 printk(KERN_DEBUG "bank %d: ", w);
1333 for (i = 0; i < 14; i += 2)
1334 printk(" %04x", inw(ioaddr + i));
1337 outw(save, ioaddr + BANK_SELECT);
1341 static int smc_open(struct net_device *dev)
1343 struct smc_private *smc = netdev_priv(dev);
1344 dev_link_t *link = &smc->link;
1347 DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n",
1348 dev->name, dev, inw(dev->base_addr + BANK_SELECT));
1349 if (pc_debug > 1) smc_dump(dev);
1352 /* Check that the PCMCIA card is still here. */
1355 /* Physical device present signature. */
1356 if (check_sig(link) < 0) {
1357 printk("smc91c92_cs: Yikes! Bad chip signature!\n");
1362 netif_start_queue(dev);
1363 smc->saved_skb = NULL;
1364 smc->packets_waiting = 0;
1367 init_timer(&smc->media);
1368 smc->media.function = &media_check;
1369 smc->media.data = (u_long) dev;
1370 smc->media.expires = jiffies + HZ;
1371 add_timer(&smc->media);
1376 /*====================================================================*/
1378 static int smc_close(struct net_device *dev)
1380 struct smc_private *smc = netdev_priv(dev);
1381 dev_link_t *link = &smc->link;
1382 kio_addr_t ioaddr = dev->base_addr;
1384 DEBUG(0, "%s: smc_close(), status %4.4x.\n",
1385 dev->name, inw(ioaddr + BANK_SELECT));
1387 netif_stop_queue(dev);
1389 /* Shut off all interrupts, and turn off the Tx and Rx sections.
1390 Don't bother to check for chip present. */
1391 SMC_SELECT_BANK(2); /* Nominally paranoia, but do no assume... */
1392 outw(0, ioaddr + INTERRUPT);
1394 mask_bits(0xff00, ioaddr + RCR);
1395 mask_bits(0xff00, ioaddr + TCR);
1397 /* Put the chip into power-down mode. */
1399 outw(CTL_POWERDOWN, ioaddr + CONTROL );
1402 del_timer_sync(&smc->media);
1407 /*======================================================================
1409 Transfer a packet to the hardware and trigger the packet send.
1410 This may be called at either from either the Tx queue code
1411 or the interrupt handler.
1413 ======================================================================*/
1415 static void smc_hardware_send_packet(struct net_device * dev)
1417 struct smc_private *smc = netdev_priv(dev);
1418 struct sk_buff *skb = smc->saved_skb;
1419 kio_addr_t ioaddr = dev->base_addr;
1423 printk(KERN_ERR "%s: In XMIT with no packet to send.\n", dev->name);
1427 /* There should be a packet slot waiting. */
1428 packet_no = inw(ioaddr + PNR_ARR) >> 8;
1429 if (packet_no & 0x80) {
1430 /* If not, there is a hardware problem! Likely an ejected card. */
1431 printk(KERN_WARNING "%s: 91c92 hardware Tx buffer allocation"
1432 " failed, status %#2.2x.\n", dev->name, packet_no);
1433 dev_kfree_skb_irq(skb);
1434 smc->saved_skb = NULL;
1435 netif_start_queue(dev);
1439 smc->stats.tx_bytes += skb->len;
1440 /* The card should use the just-allocated buffer. */
1441 outw(packet_no, ioaddr + PNR_ARR);
1442 /* point to the beginning of the packet */
1443 outw(PTR_AUTOINC , ioaddr + POINTER);
1445 /* Send the packet length (+6 for status, length and ctl byte)
1446 and the status word (set to zeros). */
1448 u_char *buf = skb->data;
1449 u_int length = skb->len; /* The chip will pad to ethernet min. */
1451 DEBUG(2, "%s: Trying to xmit packet of length %d.\n",
1454 /* send the packet length: +6 for status word, length, and ctl */
1455 outw(0, ioaddr + DATA_1);
1456 outw(length + 6, ioaddr + DATA_1);
1457 outsw(ioaddr + DATA_1, buf, length >> 1);
1459 /* The odd last byte, if there is one, goes in the control word. */
1460 outw((length & 1) ? 0x2000 | buf[length-1] : 0, ioaddr + DATA_1);
1463 /* Enable the Tx interrupts, both Tx (TxErr) and TxEmpty. */
1464 outw(((IM_TX_INT|IM_TX_EMPTY_INT)<<8) |
1465 (inw(ioaddr + INTERRUPT) & 0xff00),
1466 ioaddr + INTERRUPT);
1468 /* The chip does the rest of the work. */
1469 outw(MC_ENQUEUE , ioaddr + MMU_CMD);
1471 smc->saved_skb = NULL;
1472 dev_kfree_skb_irq(skb);
1473 dev->trans_start = jiffies;
1474 netif_start_queue(dev);
1478 /*====================================================================*/
1480 static void smc_tx_timeout(struct net_device *dev)
1482 struct smc_private *smc = netdev_priv(dev);
1483 kio_addr_t ioaddr = dev->base_addr;
1485 printk(KERN_NOTICE "%s: SMC91c92 transmit timed out, "
1486 "Tx_status %2.2x status %4.4x.\n",
1487 dev->name, inw(ioaddr)&0xff, inw(ioaddr + 2));
1488 smc->stats.tx_errors++;
1490 dev->trans_start = jiffies;
1491 smc->saved_skb = NULL;
1492 netif_wake_queue(dev);
1495 static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev)
1497 struct smc_private *smc = netdev_priv(dev);
1498 kio_addr_t ioaddr = dev->base_addr;
1502 netif_stop_queue(dev);
1504 DEBUG(2, "%s: smc_start_xmit(length = %d) called,"
1505 " status %4.4x.\n", dev->name, skb->len, inw(ioaddr + 2));
1507 if (smc->saved_skb) {
1508 /* THIS SHOULD NEVER HAPPEN. */
1509 smc->stats.tx_aborted_errors++;
1510 printk(KERN_DEBUG "%s: Internal error -- sent packet while busy.\n",
1514 smc->saved_skb = skb;
1516 num_pages = skb->len >> 8;
1518 if (num_pages > 7) {
1519 printk(KERN_ERR "%s: Far too big packet error.\n", dev->name);
1520 dev_kfree_skb (skb);
1521 smc->saved_skb = NULL;
1522 smc->stats.tx_dropped++;
1523 return 0; /* Do not re-queue this packet. */
1525 /* A packet is now waiting. */
1526 smc->packets_waiting++;
1528 SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */
1530 /* need MC_RESET to keep the memory consistent. errata? */
1532 outw(MC_RESET, ioaddr + MMU_CMD);
1536 /* Allocate the memory; send the packet now if we win. */
1537 outw(MC_ALLOC | num_pages, ioaddr + MMU_CMD);
1538 for (time_out = MEMORY_WAIT_TIME; time_out >= 0; time_out--) {
1539 ir = inw(ioaddr+INTERRUPT);
1540 if (ir & IM_ALLOC_INT) {
1541 /* Acknowledge the interrupt, send the packet. */
1542 outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT);
1543 smc_hardware_send_packet(dev); /* Send the packet now.. */
1548 /* Otherwise defer until the Tx-space-allocated interrupt. */
1549 DEBUG(2, "%s: memory allocation deferred.\n", dev->name);
1550 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT);
1555 /*======================================================================
1557 Handle a Tx anomolous event. Entered while in Window 2.
1559 ======================================================================*/
1561 static void smc_tx_err(struct net_device * dev)
1563 struct smc_private *smc = netdev_priv(dev);
1564 kio_addr_t ioaddr = dev->base_addr;
1565 int saved_packet = inw(ioaddr + PNR_ARR) & 0xff;
1566 int packet_no = inw(ioaddr + FIFO_PORTS) & 0x7f;
1569 /* select this as the packet to read from */
1570 outw(packet_no, ioaddr + PNR_ARR);
1572 /* read the first word from this packet */
1573 outw(PTR_AUTOINC | PTR_READ | 0, ioaddr + POINTER);
1575 tx_status = inw(ioaddr + DATA_1);
1577 smc->stats.tx_errors++;
1578 if (tx_status & TS_LOSTCAR) smc->stats.tx_carrier_errors++;
1579 if (tx_status & TS_LATCOL) smc->stats.tx_window_errors++;
1580 if (tx_status & TS_16COL) {
1581 smc->stats.tx_aborted_errors++;
1585 if (tx_status & TS_SUCCESS) {
1586 printk(KERN_NOTICE "%s: Successful packet caused error "
1587 "interrupt?\n", dev->name);
1589 /* re-enable transmit */
1591 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1594 outw(MC_FREEPKT, ioaddr + MMU_CMD); /* Free the packet memory. */
1596 /* one less packet waiting for me */
1597 smc->packets_waiting--;
1599 outw(saved_packet, ioaddr + PNR_ARR);
1603 /*====================================================================*/
1605 static void smc_eph_irq(struct net_device *dev)
1607 struct smc_private *smc = netdev_priv(dev);
1608 kio_addr_t ioaddr = dev->base_addr;
1609 u_short card_stats, ephs;
1612 ephs = inw(ioaddr + EPH);
1613 DEBUG(2, "%s: Ethernet protocol handler interrupt, status"
1614 " %4.4x.\n", dev->name, ephs);
1615 /* Could be a counter roll-over warning: update stats. */
1616 card_stats = inw(ioaddr + COUNTER);
1617 /* single collisions */
1618 smc->stats.collisions += card_stats & 0xF;
1620 /* multiple collisions */
1621 smc->stats.collisions += card_stats & 0xF;
1622 #if 0 /* These are for when linux supports these statistics */
1623 card_stats >>= 4; /* deferred */
1624 card_stats >>= 4; /* excess deferred */
1626 /* If we had a transmit error we must re-enable the transmitter. */
1627 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1629 /* Clear a link error interrupt. */
1631 outw(CTL_AUTO_RELEASE | 0x0000, ioaddr + CONTROL);
1632 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1637 /*====================================================================*/
1639 static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1641 struct net_device *dev = dev_id;
1642 struct smc_private *smc = netdev_priv(dev);
1644 u_short saved_bank, saved_pointer, mask, status;
1645 unsigned int handled = 1;
1646 char bogus_cnt = INTR_WORK; /* Work we are willing to do. */
1648 if (!netif_device_present(dev))
1651 ioaddr = dev->base_addr;
1653 DEBUG(3, "%s: SMC91c92 interrupt %d at %#x.\n", dev->name,
1657 saved_bank = inw(ioaddr + BANK_SELECT);
1658 if ((saved_bank & 0xff00) != 0x3300) {
1659 /* The device does not exist -- the card could be off-line, or
1660 maybe it has been ejected. */
1661 DEBUG(1, "%s: SMC91c92 interrupt %d for non-existent"
1662 "/ejected device.\n", dev->name, irq);
1668 saved_pointer = inw(ioaddr + POINTER);
1669 mask = inw(ioaddr + INTERRUPT) >> 8;
1670 /* clear all interrupts */
1671 outw(0, ioaddr + INTERRUPT);
1673 do { /* read the status flag, and mask it */
1674 status = inw(ioaddr + INTERRUPT) & 0xff;
1675 DEBUG(3, "%s: Status is %#2.2x (mask %#2.2x).\n", dev->name,
1677 if ((status & mask) == 0) {
1678 if (bogus_cnt == INTR_WORK)
1682 if (status & IM_RCV_INT) {
1683 /* Got a packet(s). */
1686 if (status & IM_TX_INT) {
1688 outw(IM_TX_INT, ioaddr + INTERRUPT);
1691 if (status & IM_TX_EMPTY_INT) {
1692 outw(IM_TX_EMPTY_INT, ioaddr + INTERRUPT);
1693 mask &= ~IM_TX_EMPTY_INT;
1694 smc->stats.tx_packets += smc->packets_waiting;
1695 smc->packets_waiting = 0;
1697 if (status & IM_ALLOC_INT) {
1698 /* Clear this interrupt so it doesn't happen again */
1699 mask &= ~IM_ALLOC_INT;
1701 smc_hardware_send_packet(dev);
1703 /* enable xmit interrupts based on this */
1704 mask |= (IM_TX_EMPTY_INT | IM_TX_INT);
1706 /* and let the card send more packets to me */
1707 netif_wake_queue(dev);
1709 if (status & IM_RX_OVRN_INT) {
1710 smc->stats.rx_errors++;
1711 smc->stats.rx_fifo_errors++;
1713 smc->rx_ovrn = 1; /* need MC_RESET outside smc_interrupt */
1714 outw(IM_RX_OVRN_INT, ioaddr + INTERRUPT);
1716 if (status & IM_EPH_INT)
1718 } while (--bogus_cnt);
1720 DEBUG(3, " Restoring saved registers mask %2.2x bank %4.4x"
1721 " pointer %4.4x.\n", mask, saved_bank, saved_pointer);
1723 /* restore state register */
1724 outw((mask<<8), ioaddr + INTERRUPT);
1725 outw(saved_pointer, ioaddr + POINTER);
1726 SMC_SELECT_BANK(saved_bank);
1728 DEBUG(3, "%s: Exiting interrupt IRQ%d.\n", dev->name, irq);
1732 if ((smc->manfid == MANFID_OSITECH) &&
1733 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1734 /* Retrigger interrupt if needed */
1735 mask_bits(0x00ff, ioaddr-0x10+OSITECH_RESET_ISR);
1736 set_bits(0x0300, ioaddr-0x10+OSITECH_RESET_ISR);
1738 if (smc->manfid == MANFID_MOTOROLA) {
1740 cor = readb(smc->base + MOT_UART + CISREG_COR);
1741 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_UART + CISREG_COR);
1742 writeb(cor, smc->base + MOT_UART + CISREG_COR);
1743 cor = readb(smc->base + MOT_LAN + CISREG_COR);
1744 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_LAN + CISREG_COR);
1745 writeb(cor, smc->base + MOT_LAN + CISREG_COR);
1747 #ifdef DOES_NOT_WORK
1748 if (smc->base != NULL) { /* Megahertz MFC's */
1749 readb(smc->base+MEGAHERTZ_ISR);
1750 readb(smc->base+MEGAHERTZ_ISR);
1753 return IRQ_RETVAL(handled);
1756 /*====================================================================*/
1758 static void smc_rx(struct net_device *dev)
1760 struct smc_private *smc = netdev_priv(dev);
1761 kio_addr_t ioaddr = dev->base_addr;
1763 int packet_length; /* Caution: not frame length, rather words
1764 to transfer from the chip. */
1766 /* Assertion: we are in Window 2. */
1768 if (inw(ioaddr + FIFO_PORTS) & FP_RXEMPTY) {
1769 printk(KERN_ERR "%s: smc_rx() with nothing on Rx FIFO.\n",
1774 /* Reset the read pointer, and read the status and packet length. */
1775 outw(PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER);
1776 rx_status = inw(ioaddr + DATA_1);
1777 packet_length = inw(ioaddr + DATA_1) & 0x07ff;
1779 DEBUG(2, "%s: Receive status %4.4x length %d.\n",
1780 dev->name, rx_status, packet_length);
1782 if (!(rx_status & RS_ERRORS)) {
1783 /* do stuff to make a new packet */
1784 struct sk_buff *skb;
1786 /* Note: packet_length adds 5 or 6 extra bytes here! */
1787 skb = dev_alloc_skb(packet_length+2);
1790 DEBUG(1, "%s: Low memory, packet dropped.\n", dev->name);
1791 smc->stats.rx_dropped++;
1792 outw(MC_RELEASE, ioaddr + MMU_CMD);
1796 packet_length -= (rx_status & RS_ODDFRAME ? 5 : 6);
1797 skb_reserve(skb, 2);
1798 insw(ioaddr+DATA_1, skb_put(skb, packet_length),
1799 (packet_length+1)>>1);
1800 skb->protocol = eth_type_trans(skb, dev);
1804 dev->last_rx = jiffies;
1805 smc->stats.rx_packets++;
1806 smc->stats.rx_bytes += packet_length;
1807 if (rx_status & RS_MULTICAST)
1808 smc->stats.multicast++;
1811 smc->stats.rx_errors++;
1813 if (rx_status & RS_ALGNERR) smc->stats.rx_frame_errors++;
1814 if (rx_status & (RS_TOOSHORT | RS_TOOLONG))
1815 smc->stats.rx_length_errors++;
1816 if (rx_status & RS_BADCRC) smc->stats.rx_crc_errors++;
1818 /* Let the MMU free the memory of this packet. */
1819 outw(MC_RELEASE, ioaddr + MMU_CMD);
1824 /*====================================================================*/
1826 static struct net_device_stats *smc_get_stats(struct net_device *dev)
1828 struct smc_private *smc = netdev_priv(dev);
1829 /* Nothing to update - the 91c92 is a pretty primative chip. */
1833 /*======================================================================
1835 Calculate values for the hardware multicast filter hash table.
1837 ======================================================================*/
1839 static void fill_multicast_tbl(int count, struct dev_mc_list *addrs,
1840 u_char *multicast_table)
1842 struct dev_mc_list *mc_addr;
1844 for (mc_addr = addrs; mc_addr && count-- > 0; mc_addr = mc_addr->next) {
1845 u_int position = ether_crc(6, mc_addr->dmi_addr);
1846 #ifndef final_version /* Verify multicast address. */
1847 if ((mc_addr->dmi_addr[0] & 1) == 0)
1850 multicast_table[position >> 29] |= 1 << ((position >> 26) & 7);
1854 /*======================================================================
1856 Set the receive mode.
1858 This routine is used by both the protocol level to notify us of
1859 promiscuous/multicast mode changes, and by the open/reset code to
1860 initialize the Rx registers. We always set the multicast list and
1861 leave the receiver running.
1863 ======================================================================*/
1865 static void set_rx_mode(struct net_device *dev)
1867 kio_addr_t ioaddr = dev->base_addr;
1868 struct smc_private *smc = netdev_priv(dev);
1869 u_int multicast_table[ 2 ] = { 0, };
1870 unsigned long flags;
1871 u_short rx_cfg_setting;
1873 if (dev->flags & IFF_PROMISC) {
1874 printk(KERN_NOTICE "%s: setting Rx mode to promiscuous.\n", dev->name);
1875 rx_cfg_setting = RxStripCRC | RxEnable | RxPromisc | RxAllMulti;
1876 } else if (dev->flags & IFF_ALLMULTI)
1877 rx_cfg_setting = RxStripCRC | RxEnable | RxAllMulti;
1879 if (dev->mc_count) {
1880 fill_multicast_tbl(dev->mc_count, dev->mc_list,
1881 (u_char *)multicast_table);
1883 rx_cfg_setting = RxStripCRC | RxEnable;
1886 /* Load MC table and Rx setting into the chip without interrupts. */
1887 spin_lock_irqsave(&smc->lock, flags);
1889 outl(multicast_table[0], ioaddr + MULTICAST0);
1890 outl(multicast_table[1], ioaddr + MULTICAST4);
1892 outw(rx_cfg_setting, ioaddr + RCR);
1894 spin_unlock_irqrestore(&smc->lock, flags);
1899 /*======================================================================
1901 Senses when a card's config changes. Here, it's coax or TP.
1903 ======================================================================*/
1905 static int s9k_config(struct net_device *dev, struct ifmap *map)
1907 struct smc_private *smc = netdev_priv(dev);
1908 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
1909 if (smc->cfg & CFG_MII_SELECT)
1911 else if (map->port > 2)
1913 dev->if_port = map->port;
1914 printk(KERN_INFO "%s: switched to %s port\n",
1915 dev->name, if_names[dev->if_port]);
1921 /*======================================================================
1923 Reset the chip, reloading every register that might be corrupted.
1925 ======================================================================*/
1928 Set transceiver type, perhaps to something other than what the user
1929 specified in dev->if_port.
1931 static void smc_set_xcvr(struct net_device *dev, int if_port)
1933 struct smc_private *smc = netdev_priv(dev);
1934 kio_addr_t ioaddr = dev->base_addr;
1937 saved_bank = inw(ioaddr + BANK_SELECT);
1940 outw(smc->cfg | CFG_AUI_SELECT, ioaddr + CONFIG);
1941 if ((smc->manfid == MANFID_OSITECH) &&
1942 (smc->cardid != PRODID_OSITECH_SEVEN))
1943 set_bits(OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1944 smc->media_status = ((dev->if_port == 0) ? 0x0001 : 0x0002);
1946 outw(smc->cfg, ioaddr + CONFIG);
1947 if ((smc->manfid == MANFID_OSITECH) &&
1948 (smc->cardid != PRODID_OSITECH_SEVEN))
1949 mask_bits(~OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1950 smc->media_status = ((dev->if_port == 0) ? 0x0012 : 0x4001);
1952 SMC_SELECT_BANK(saved_bank);
1955 static void smc_reset(struct net_device *dev)
1957 kio_addr_t ioaddr = dev->base_addr;
1958 struct smc_private *smc = netdev_priv(dev);
1961 DEBUG(0, "%s: smc91c92 reset called.\n", dev->name);
1963 /* The first interaction must be a write to bring the chip out
1966 /* Reset the chip. */
1967 outw(RCR_SOFTRESET, ioaddr + RCR);
1970 /* Clear the transmit and receive configuration registers. */
1971 outw(RCR_CLEAR, ioaddr + RCR);
1972 outw(TCR_CLEAR, ioaddr + TCR);
1974 /* Set the Window 1 control, configuration and station addr registers.
1975 No point in writing the I/O base register ;-> */
1977 /* Automatically release succesfully transmitted packets,
1978 Accept link errors, counter and Tx error interrupts. */
1979 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1981 smc_set_xcvr(dev, dev->if_port);
1982 if ((smc->manfid == MANFID_OSITECH) &&
1983 (smc->cardid != PRODID_OSITECH_SEVEN))
1984 outw((dev->if_port == 2 ? OSI_AUI_PWR : 0) |
1985 (inw(ioaddr-0x10+OSITECH_AUI_PWR) & 0xff00),
1986 ioaddr - 0x10 + OSITECH_AUI_PWR);
1988 /* Fill in the physical address. The databook is wrong about the order! */
1989 for (i = 0; i < 6; i += 2)
1990 outw((dev->dev_addr[i+1]<<8)+dev->dev_addr[i],
1991 ioaddr + ADDR0 + i);
1995 outw(MC_RESET, ioaddr + MMU_CMD);
1996 outw(0, ioaddr + INTERRUPT);
1998 /* Re-enable the chip. */
2000 outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) |
2001 TCR_ENABLE | TCR_PAD_EN | smc->duplex, ioaddr + TCR);
2004 if (smc->cfg & CFG_MII_SELECT) {
2008 mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000);
2010 /* Advertise 100F, 100H, 10F, 10H */
2011 mdio_write(dev, smc->mii_if.phy_id, 4, 0x01e1);
2013 /* Restart MII autonegotiation */
2014 mdio_write(dev, smc->mii_if.phy_id, 0, 0x0000);
2015 mdio_write(dev, smc->mii_if.phy_id, 0, 0x1200);
2018 /* Enable interrupts. */
2020 outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,
2021 ioaddr + INTERRUPT);
2024 /*======================================================================
2026 Media selection timer routine
2028 ======================================================================*/
2030 static void media_check(u_long arg)
2032 struct net_device *dev = (struct net_device *) arg;
2033 struct smc_private *smc = netdev_priv(dev);
2034 kio_addr_t ioaddr = dev->base_addr;
2035 u_short i, media, saved_bank;
2038 saved_bank = inw(ioaddr + BANK_SELECT);
2040 if (!netif_device_present(dev))
2045 /* need MC_RESET to keep the memory consistent. errata? */
2047 outw(MC_RESET, ioaddr + MMU_CMD);
2050 i = inw(ioaddr + INTERRUPT);
2052 media = inw(ioaddr + EPH) & EPH_LINK_OK;
2054 media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1;
2056 /* Check for pending interrupt with watchdog flag set: with
2057 this, we can limp along even if the interrupt is blocked */
2058 if (smc->watchdog++ && ((i>>8) & i)) {
2059 if (!smc->fast_poll)
2060 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
2061 smc_interrupt(dev->irq, smc, NULL);
2062 smc->fast_poll = HZ;
2064 if (smc->fast_poll) {
2066 smc->media.expires = jiffies + HZ/100;
2067 add_timer(&smc->media);
2068 SMC_SELECT_BANK(saved_bank);
2072 if (smc->cfg & CFG_MII_SELECT) {
2073 if (smc->mii_if.phy_id < 0)
2077 link = mdio_read(dev, smc->mii_if.phy_id, 1);
2078 if (!link || (link == 0xffff)) {
2079 printk(KERN_INFO "%s: MII is missing!\n", dev->name);
2080 smc->mii_if.phy_id = -1;
2085 if (link != smc->link_status) {
2086 u_short p = mdio_read(dev, smc->mii_if.phy_id, 5);
2087 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2088 (link) ? "found" : "lost");
2089 smc->duplex = (((p & 0x0100) || ((p & 0x1c0) == 0x40))
2092 printk(KERN_INFO "%s: autonegotiation complete: "
2093 "%sbaseT-%cD selected\n", dev->name,
2094 ((p & 0x0180) ? "100" : "10"),
2095 (smc->duplex ? 'F' : 'H'));
2098 outw(inw(ioaddr + TCR) | smc->duplex, ioaddr + TCR);
2099 smc->link_status = link;
2104 /* Ignore collisions unless we've had no rx's recently */
2105 if (time_after(jiffies, dev->last_rx + HZ)) {
2106 if (smc->tx_err || (smc->media_status & EPH_16COL))
2111 if (media != smc->media_status) {
2112 if ((media & smc->media_status & 1) &&
2113 ((smc->media_status ^ media) & EPH_LINK_OK))
2114 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2115 (smc->media_status & EPH_LINK_OK ? "lost" : "found"));
2116 else if ((media & smc->media_status & 2) &&
2117 ((smc->media_status ^ media) & EPH_16COL))
2118 printk(KERN_INFO "%s: coax cable %s\n", dev->name,
2119 (media & EPH_16COL ? "problem" : "ok"));
2120 if (dev->if_port == 0) {
2122 if (media & EPH_LINK_OK)
2123 printk(KERN_INFO "%s: flipped to 10baseT\n",
2126 smc_set_xcvr(dev, 2);
2128 if (media & EPH_16COL)
2129 smc_set_xcvr(dev, 1);
2131 printk(KERN_INFO "%s: flipped to 10base2\n",
2135 smc->media_status = media;
2139 smc->media.expires = jiffies + HZ;
2140 add_timer(&smc->media);
2141 SMC_SELECT_BANK(saved_bank);
2144 static int smc_link_ok(struct net_device *dev)
2146 kio_addr_t ioaddr = dev->base_addr;
2147 struct smc_private *smc = netdev_priv(dev);
2149 if (smc->cfg & CFG_MII_SELECT) {
2150 return mii_link_ok(&smc->mii_if);
2153 return inw(ioaddr + EPH) & EPH_LINK_OK;
2157 static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2160 kio_addr_t ioaddr = dev->base_addr;
2162 ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |
2163 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);
2166 tmp = inw(ioaddr + CONFIG);
2167 ecmd->port = (tmp & CFG_AUI_SELECT) ? PORT_AUI : PORT_TP;
2168 ecmd->transceiver = XCVR_INTERNAL;
2169 ecmd->speed = SPEED_10;
2170 ecmd->phy_address = ioaddr + MGMT;
2173 tmp = inw(ioaddr + TCR);
2174 ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF;
2179 static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2182 kio_addr_t ioaddr = dev->base_addr;
2184 if (ecmd->speed != SPEED_10)
2186 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
2188 if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI)
2190 if (ecmd->transceiver != XCVR_INTERNAL)
2193 if (ecmd->port == PORT_AUI)
2194 smc_set_xcvr(dev, 1);
2196 smc_set_xcvr(dev, 0);
2199 tmp = inw(ioaddr + TCR);
2200 if (ecmd->duplex == DUPLEX_FULL)
2204 outw(tmp, ioaddr + TCR);
2209 static int check_if_running(struct net_device *dev)
2211 if (!netif_running(dev))
2216 static void smc_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2218 strcpy(info->driver, DRV_NAME);
2219 strcpy(info->version, DRV_VERSION);
2222 static int smc_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2224 struct smc_private *smc = netdev_priv(dev);
2225 kio_addr_t ioaddr = dev->base_addr;
2226 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2230 spin_lock_irq(&smc->lock);
2231 if (smc->cfg & CFG_MII_SELECT)
2232 ret = mii_ethtool_gset(&smc->mii_if, ecmd);
2234 ret = smc_netdev_get_ecmd(dev, ecmd);
2235 spin_unlock_irq(&smc->lock);
2236 SMC_SELECT_BANK(saved_bank);
2240 static int smc_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2242 struct smc_private *smc = netdev_priv(dev);
2243 kio_addr_t ioaddr = dev->base_addr;
2244 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2248 spin_lock_irq(&smc->lock);
2249 if (smc->cfg & CFG_MII_SELECT)
2250 ret = mii_ethtool_sset(&smc->mii_if, ecmd);
2252 ret = smc_netdev_set_ecmd(dev, ecmd);
2253 spin_unlock_irq(&smc->lock);
2254 SMC_SELECT_BANK(saved_bank);
2258 static u32 smc_get_link(struct net_device *dev)
2260 struct smc_private *smc = netdev_priv(dev);
2261 kio_addr_t ioaddr = dev->base_addr;
2262 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2266 spin_lock_irq(&smc->lock);
2267 ret = smc_link_ok(dev);
2268 spin_unlock_irq(&smc->lock);
2269 SMC_SELECT_BANK(saved_bank);
2274 static u32 smc_get_msglevel(struct net_device *dev)
2279 static void smc_set_msglevel(struct net_device *dev, u32 val)
2285 static int smc_nway_reset(struct net_device *dev)
2287 struct smc_private *smc = netdev_priv(dev);
2288 if (smc->cfg & CFG_MII_SELECT) {
2289 kio_addr_t ioaddr = dev->base_addr;
2290 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2294 res = mii_nway_restart(&smc->mii_if);
2295 SMC_SELECT_BANK(saved_bank);
2302 static struct ethtool_ops ethtool_ops = {
2303 .begin = check_if_running,
2304 .get_drvinfo = smc_get_drvinfo,
2305 .get_settings = smc_get_settings,
2306 .set_settings = smc_set_settings,
2307 .get_link = smc_get_link,
2309 .get_msglevel = smc_get_msglevel,
2310 .set_msglevel = smc_set_msglevel,
2312 .nway_reset = smc_nway_reset,
2315 static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
2317 struct smc_private *smc = netdev_priv(dev);
2318 struct mii_ioctl_data *mii = if_mii(rq);
2321 kio_addr_t ioaddr = dev->base_addr;
2323 if (!netif_running(dev))
2326 spin_lock_irq(&smc->lock);
2327 saved_bank = inw(ioaddr + BANK_SELECT);
2329 rc = generic_mii_ioctl(&smc->mii_if, mii, cmd, NULL);
2330 SMC_SELECT_BANK(saved_bank);
2331 spin_unlock_irq(&smc->lock);
2335 static struct pcmcia_device_id smc91c92_ids[] = {
2336 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0109, 0x0501),
2337 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0140, 0x000a),
2338 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63),
2339 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63),
2340 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef),
2341 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
2342 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
2343 PCMCIA_PFC_DEVICE_PROD_ID12(0, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
2344 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Diamonds Modem+Ethernet", 0xc2f80cd, 0x656947b9),
2345 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Hearts Modem+Ethernet", 0xc2f80cd, 0xdc9ba5ed),
2346 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x016c, 0x0020),
2347 PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0023),
2348 PCMCIA_DEVICE_PROD_ID123("BASICS by New Media Corporation", "Ethernet", "SMC91C94", 0x23c78a9d, 0x00b2e941, 0xcef397fb),
2349 PCMCIA_DEVICE_PROD_ID12("ARGOSY", "Fast Ethernet PCCard", 0x78f308dc, 0xdcea68bc),
2350 PCMCIA_DEVICE_PROD_ID12("dit Co., Ltd.", "PC Card-10/100BTX", 0xe59365c8, 0x6a2161d1),
2351 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L100C", 0x6a26d1cf, 0xc16ce9c5),
2352 PCMCIA_DEVICE_PROD_ID12("Farallon", "Farallon Enet", 0x58d93fc4, 0x244734e9),
2353 PCMCIA_DEVICE_PROD_ID12("Megahertz", "CC10BT/2", 0x33234748, 0x3c95b953),
2354 PCMCIA_DEVICE_PROD_ID12("MELCO/SMC", "LPC-TX", 0xa2cd8e6d, 0x42da662a),
2355 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Four of Diamonds Ethernet", 0xc2f80cd, 0xb3466314),
2356 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Seven of Diamonds Ethernet", 0xc2f80cd, 0x194b650a),
2357 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast Ethernet PCCard", 0x281f1c5d, 0xdcea68bc),
2358 PCMCIA_DEVICE_PROD_ID12("Psion", "10Mb Ethernet", 0x4ef00b21, 0x844be9e9),
2359 PCMCIA_DEVICE_PROD_ID12("SMC", "EtherEZ Ethernet 8020", 0xc4f8b18b, 0x4a0eeb2d),
2360 /* These conflict with other cards! */
2361 /* PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0100), */
2362 /* PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab), */
2365 MODULE_DEVICE_TABLE(pcmcia, smc91c92_ids);
2367 static struct pcmcia_driver smc91c92_cs_driver = {
2368 .owner = THIS_MODULE,
2370 .name = "smc91c92_cs",
2372 .attach = smc91c92_attach,
2373 .event = smc91c92_event,
2374 .detach = smc91c92_detach,
2375 .id_table = smc91c92_ids,
2376 .suspend = smc91c92_suspend,
2377 .resume = smc91c92_resume,
2380 static int __init init_smc91c92_cs(void)
2382 return pcmcia_register_driver(&smc91c92_cs_driver);
2385 static void __exit exit_smc91c92_cs(void)
2387 pcmcia_unregister_driver(&smc91c92_cs_driver);
2388 BUG_ON(dev_list != NULL);
2391 module_init(init_smc91c92_cs);
2392 module_exit(exit_smc91c92_cs);