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 /*======================================================================
900 This verifies that the chip is some SMC91cXX variant, and returns
901 the revision code if successful. Otherwise, it returns -ENODEV.
903 ======================================================================*/
905 static int check_sig(dev_link_t *link)
907 struct net_device *dev = link->priv;
908 kio_addr_t ioaddr = dev->base_addr;
913 if (inw(ioaddr + BANK_SELECT) >> 8 != 0x33) {
914 /* Try powering up the chip */
915 outw(0, ioaddr + CONTROL);
919 /* Try setting bus width */
920 width = (link->io.Attributes1 == IO_DATA_PATH_WIDTH_AUTO);
921 s = inb(ioaddr + CONFIG);
926 outb(s, ioaddr + CONFIG);
928 /* Check Base Address Register to make sure bus width is OK */
929 s = inw(ioaddr + BASE_ADDR);
930 if ((inw(ioaddr + BANK_SELECT) >> 8 == 0x33) &&
931 ((s >> 8) != (s & 0xff))) {
933 s = inw(ioaddr + REVISION);
938 event_callback_args_t args;
939 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n");
940 args.client_data = link;
941 smc91c92_event(CS_EVENT_RESET_PHYSICAL, 0, &args);
942 pcmcia_release_io(link->handle, &link->io);
943 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
944 pcmcia_request_io(link->handle, &link->io);
945 smc91c92_event(CS_EVENT_CARD_RESET, 0, &args);
946 return check_sig(link);
951 /*======================================================================
953 smc91c92_config() is scheduled to run after a CARD_INSERTION event
954 is received, to configure the PCMCIA socket, and to make the
955 ethernet device available to the system.
957 ======================================================================*/
959 #define CS_EXIT_TEST(ret, svc, label) \
960 if (ret != CS_SUCCESS) { cs_error(link->handle, svc, ret); goto label; }
962 static void smc91c92_config(dev_link_t *link)
964 client_handle_t handle = link->handle;
965 struct net_device *dev = link->priv;
966 struct smc_private *smc = netdev_priv(dev);
967 struct smc_cfg_mem *cfg_mem;
976 DEBUG(0, "smc91c92_config(0x%p)\n", link);
978 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
982 tuple = &cfg_mem->tuple;
983 parse = &cfg_mem->parse;
986 tuple->Attributes = tuple->TupleOffset = 0;
987 tuple->TupleData = (cisdata_t *)buf;
988 tuple->TupleDataMax = 64;
990 tuple->DesiredTuple = CISTPL_CONFIG;
991 i = first_tuple(handle, tuple, parse);
992 CS_EXIT_TEST(i, ParseTuple, config_failed);
993 link->conf.ConfigBase = parse->config.base;
994 link->conf.Present = parse->config.rmask[0];
996 tuple->DesiredTuple = CISTPL_MANFID;
997 tuple->Attributes = TUPLE_RETURN_COMMON;
998 if (first_tuple(handle, tuple, parse) == CS_SUCCESS) {
999 smc->manfid = parse->manfid.manf;
1000 smc->cardid = parse->manfid.card;
1003 /* Configure card */
1004 link->state |= DEV_CONFIG;
1006 if ((smc->manfid == MANFID_OSITECH) &&
1007 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1008 i = osi_config(link);
1009 } else if ((smc->manfid == MANFID_MOTOROLA) ||
1010 ((smc->manfid == MANFID_MEGAHERTZ) &&
1011 ((smc->cardid == PRODID_MEGAHERTZ_VARIOUS) ||
1012 (smc->cardid == PRODID_MEGAHERTZ_EM3288)))) {
1013 i = mhz_mfc_config(link);
1015 i = smc_config(link);
1017 CS_EXIT_TEST(i, RequestIO, config_failed);
1019 i = pcmcia_request_irq(link->handle, &link->irq);
1020 CS_EXIT_TEST(i, RequestIRQ, config_failed);
1021 i = pcmcia_request_configuration(link->handle, &link->conf);
1022 CS_EXIT_TEST(i, RequestConfiguration, config_failed);
1024 if (smc->manfid == MANFID_MOTOROLA)
1027 dev->irq = link->irq.AssignedIRQ;
1029 if ((if_port >= 0) && (if_port <= 2))
1030 dev->if_port = if_port;
1032 printk(KERN_NOTICE "smc91c92_cs: invalid if_port requested\n");
1034 switch (smc->manfid) {
1035 case MANFID_OSITECH:
1037 i = osi_setup(link, smc->manfid, smc->cardid); break;
1039 case MANFID_NEW_MEDIA:
1040 i = smc_setup(link); break;
1041 case 0x128: /* For broken Megahertz cards */
1042 case MANFID_MEGAHERTZ:
1043 i = mhz_setup(link); break;
1044 case MANFID_MOTOROLA:
1045 default: /* get the hw address from EEPROM */
1046 i = mot_setup(link); break;
1050 printk(KERN_NOTICE "smc91c92_cs: Unable to find hardware address.\n");
1057 rev = check_sig(link);
1061 case 3: name = "92"; break;
1062 case 4: name = ((rev & 15) >= 6) ? "96" : "94"; break;
1063 case 5: name = "95"; break;
1064 case 7: name = "100"; break;
1065 case 8: name = "100-FD"; break;
1066 case 9: name = "110"; break;
1069 ioaddr = dev->base_addr;
1073 mir = inw(ioaddr + MEMINFO) & 0xff;
1074 if (mir == 0xff) mir++;
1075 /* Get scale factor for memory size */
1076 mcr = ((rev >> 4) > 3) ? inw(ioaddr + MEMCFG) : 0x0200;
1077 mir *= 128 * (1<<((mcr >> 9) & 7));
1079 smc->cfg = inw(ioaddr + CONFIG) & ~CFG_AUI_SELECT;
1080 smc->cfg |= CFG_NO_WAIT | CFG_16BIT | CFG_STATIC;
1081 if (smc->manfid == MANFID_OSITECH)
1082 smc->cfg |= CFG_IRQ_SEL_1 | CFG_IRQ_SEL_0;
1083 if ((rev >> 4) >= 7)
1084 smc->cfg |= CFG_MII_SELECT;
1088 if (smc->cfg & CFG_MII_SELECT) {
1091 for (i = 0; i < 32; i++) {
1092 j = mdio_read(dev, i, 1);
1093 if ((j != 0) && (j != 0xffff)) break;
1095 smc->mii_if.phy_id = (i < 32) ? i : -1;
1100 link->dev = &smc->node;
1101 link->state &= ~DEV_CONFIG_PENDING;
1102 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
1104 if (register_netdev(dev) != 0) {
1105 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n");
1110 strcpy(smc->node.dev_name, dev->name);
1112 printk(KERN_INFO "%s: smc91c%s rev %d: io %#3lx, irq %d, "
1113 "hw_addr ", dev->name, name, (rev & 0x0f), dev->base_addr,
1115 for (i = 0; i < 6; i++)
1116 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
1120 printk(KERN_INFO " %lu byte", mir);
1122 printk(KERN_INFO " %lu kb", mir>>10);
1123 printk(" buffer, %s xcvr\n", (smc->cfg & CFG_MII_SELECT) ?
1124 "MII" : if_names[dev->if_port]);
1127 if (smc->cfg & CFG_MII_SELECT) {
1128 if (smc->mii_if.phy_id != -1) {
1129 DEBUG(0, " MII transceiver at index %d, status %x.\n",
1130 smc->mii_if.phy_id, j);
1132 printk(KERN_NOTICE " No MII transceivers found!\n");
1139 unregister_netdev(dev);
1140 config_failed: /* CS_EXIT_TEST() calls jump to here... */
1141 smc91c92_release(link);
1142 link->state &= ~DEV_CONFIG_PENDING;
1145 } /* smc91c92_config */
1147 /*======================================================================
1149 After a card is removed, smc91c92_release() will unregister the net
1150 device, and release the PCMCIA configuration. If the device is
1151 still open, this will be postponed until it is closed.
1153 ======================================================================*/
1155 static void smc91c92_release(dev_link_t *link)
1158 DEBUG(0, "smc91c92_release(0x%p)\n", link);
1160 pcmcia_release_configuration(link->handle);
1161 pcmcia_release_io(link->handle, &link->io);
1162 pcmcia_release_irq(link->handle, &link->irq);
1164 struct net_device *dev = link->priv;
1165 struct smc_private *smc = netdev_priv(dev);
1167 pcmcia_release_window(link->win);
1170 link->state &= ~DEV_CONFIG;
1173 /*======================================================================
1175 The card status event handler. Mostly, this schedules other
1176 stuff to run after an event is received. A CARD_REMOVAL event
1177 also sets some flags to discourage the net drivers from trying
1178 to talk to the card any more.
1180 ======================================================================*/
1182 static int smc91c92_event(event_t event, int priority,
1183 event_callback_args_t *args)
1185 dev_link_t *link = args->client_data;
1186 struct net_device *dev = link->priv;
1187 struct smc_private *smc = netdev_priv(dev);
1190 DEBUG(1, "smc91c92_event(0x%06x)\n", event);
1193 case CS_EVENT_CARD_REMOVAL:
1194 link->state &= ~DEV_PRESENT;
1195 if (link->state & DEV_CONFIG)
1196 netif_device_detach(dev);
1198 case CS_EVENT_CARD_INSERTION:
1199 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1200 smc91c92_config(link);
1202 case CS_EVENT_PM_SUSPEND:
1203 link->state |= DEV_SUSPEND;
1204 /* Fall through... */
1205 case CS_EVENT_RESET_PHYSICAL:
1206 if (link->state & DEV_CONFIG) {
1208 netif_device_detach(dev);
1209 pcmcia_release_configuration(link->handle);
1212 case CS_EVENT_PM_RESUME:
1213 link->state &= ~DEV_SUSPEND;
1214 /* Fall through... */
1215 case CS_EVENT_CARD_RESET:
1216 if (link->state & DEV_CONFIG) {
1217 if ((smc->manfid == MANFID_MEGAHERTZ) &&
1218 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
1219 mhz_3288_power(link);
1220 pcmcia_request_configuration(link->handle, &link->conf);
1221 if (smc->manfid == MANFID_MOTOROLA)
1223 if ((smc->manfid == MANFID_OSITECH) &&
1224 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1225 /* Power up the card and enable interrupts */
1226 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR);
1227 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR);
1229 if (((smc->manfid == MANFID_OSITECH) &&
1230 (smc->cardid == PRODID_OSITECH_SEVEN)) ||
1231 ((smc->manfid == MANFID_PSION) &&
1232 (smc->cardid == PRODID_PSION_NET100))) {
1233 /* Download the Seven of Diamonds firmware */
1234 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
1235 outb(__Xilinx7OD[i], link->io.BasePort1+2);
1241 netif_device_attach(dev);
1247 } /* smc91c92_event */
1249 /*======================================================================
1251 MII interface support for SMC91cXX based cards
1252 ======================================================================*/
1254 #define MDIO_SHIFT_CLK 0x04
1255 #define MDIO_DATA_OUT 0x01
1256 #define MDIO_DIR_WRITE 0x08
1257 #define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
1258 #define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
1259 #define MDIO_DATA_READ 0x02
1261 static void mdio_sync(kio_addr_t addr)
1264 for (bits = 0; bits < 32; bits++) {
1265 outb(MDIO_DATA_WRITE1, addr);
1266 outb(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
1270 static int mdio_read(struct net_device *dev, int phy_id, int loc)
1272 kio_addr_t addr = dev->base_addr + MGMT;
1273 u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
1277 for (i = 13; i >= 0; i--) {
1278 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1280 outb(dat | MDIO_SHIFT_CLK, addr);
1282 for (i = 19; i > 0; i--) {
1284 retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
1285 outb(MDIO_SHIFT_CLK, addr);
1287 return (retval>>1) & 0xffff;
1290 static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
1292 kio_addr_t addr = dev->base_addr + MGMT;
1293 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
1297 for (i = 31; i >= 0; i--) {
1298 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1300 outb(dat | MDIO_SHIFT_CLK, addr);
1302 for (i = 1; i >= 0; i--) {
1304 outb(MDIO_SHIFT_CLK, addr);
1308 /*======================================================================
1310 The driver core code, most of which should be common with a
1311 non-PCMCIA implementation.
1313 ======================================================================*/
1316 static void smc_dump(struct net_device *dev)
1318 kio_addr_t ioaddr = dev->base_addr;
1320 save = inw(ioaddr + BANK_SELECT);
1321 for (w = 0; w < 4; w++) {
1323 printk(KERN_DEBUG "bank %d: ", w);
1324 for (i = 0; i < 14; i += 2)
1325 printk(" %04x", inw(ioaddr + i));
1328 outw(save, ioaddr + BANK_SELECT);
1332 static int smc_open(struct net_device *dev)
1334 struct smc_private *smc = netdev_priv(dev);
1335 dev_link_t *link = &smc->link;
1338 DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n",
1339 dev->name, dev, inw(dev->base_addr + BANK_SELECT));
1340 if (pc_debug > 1) smc_dump(dev);
1343 /* Check that the PCMCIA card is still here. */
1346 /* Physical device present signature. */
1347 if (check_sig(link) < 0) {
1348 printk("smc91c92_cs: Yikes! Bad chip signature!\n");
1353 netif_start_queue(dev);
1354 smc->saved_skb = NULL;
1355 smc->packets_waiting = 0;
1358 init_timer(&smc->media);
1359 smc->media.function = &media_check;
1360 smc->media.data = (u_long) dev;
1361 smc->media.expires = jiffies + HZ;
1362 add_timer(&smc->media);
1367 /*====================================================================*/
1369 static int smc_close(struct net_device *dev)
1371 struct smc_private *smc = netdev_priv(dev);
1372 dev_link_t *link = &smc->link;
1373 kio_addr_t ioaddr = dev->base_addr;
1375 DEBUG(0, "%s: smc_close(), status %4.4x.\n",
1376 dev->name, inw(ioaddr + BANK_SELECT));
1378 netif_stop_queue(dev);
1380 /* Shut off all interrupts, and turn off the Tx and Rx sections.
1381 Don't bother to check for chip present. */
1382 SMC_SELECT_BANK(2); /* Nominally paranoia, but do no assume... */
1383 outw(0, ioaddr + INTERRUPT);
1385 mask_bits(0xff00, ioaddr + RCR);
1386 mask_bits(0xff00, ioaddr + TCR);
1388 /* Put the chip into power-down mode. */
1390 outw(CTL_POWERDOWN, ioaddr + CONTROL );
1393 del_timer_sync(&smc->media);
1398 /*======================================================================
1400 Transfer a packet to the hardware and trigger the packet send.
1401 This may be called at either from either the Tx queue code
1402 or the interrupt handler.
1404 ======================================================================*/
1406 static void smc_hardware_send_packet(struct net_device * dev)
1408 struct smc_private *smc = netdev_priv(dev);
1409 struct sk_buff *skb = smc->saved_skb;
1410 kio_addr_t ioaddr = dev->base_addr;
1414 printk(KERN_ERR "%s: In XMIT with no packet to send.\n", dev->name);
1418 /* There should be a packet slot waiting. */
1419 packet_no = inw(ioaddr + PNR_ARR) >> 8;
1420 if (packet_no & 0x80) {
1421 /* If not, there is a hardware problem! Likely an ejected card. */
1422 printk(KERN_WARNING "%s: 91c92 hardware Tx buffer allocation"
1423 " failed, status %#2.2x.\n", dev->name, packet_no);
1424 dev_kfree_skb_irq(skb);
1425 smc->saved_skb = NULL;
1426 netif_start_queue(dev);
1430 smc->stats.tx_bytes += skb->len;
1431 /* The card should use the just-allocated buffer. */
1432 outw(packet_no, ioaddr + PNR_ARR);
1433 /* point to the beginning of the packet */
1434 outw(PTR_AUTOINC , ioaddr + POINTER);
1436 /* Send the packet length (+6 for status, length and ctl byte)
1437 and the status word (set to zeros). */
1439 u_char *buf = skb->data;
1440 u_int length = skb->len; /* The chip will pad to ethernet min. */
1442 DEBUG(2, "%s: Trying to xmit packet of length %d.\n",
1445 /* send the packet length: +6 for status word, length, and ctl */
1446 outw(0, ioaddr + DATA_1);
1447 outw(length + 6, ioaddr + DATA_1);
1448 outsw(ioaddr + DATA_1, buf, length >> 1);
1450 /* The odd last byte, if there is one, goes in the control word. */
1451 outw((length & 1) ? 0x2000 | buf[length-1] : 0, ioaddr + DATA_1);
1454 /* Enable the Tx interrupts, both Tx (TxErr) and TxEmpty. */
1455 outw(((IM_TX_INT|IM_TX_EMPTY_INT)<<8) |
1456 (inw(ioaddr + INTERRUPT) & 0xff00),
1457 ioaddr + INTERRUPT);
1459 /* The chip does the rest of the work. */
1460 outw(MC_ENQUEUE , ioaddr + MMU_CMD);
1462 smc->saved_skb = NULL;
1463 dev_kfree_skb_irq(skb);
1464 dev->trans_start = jiffies;
1465 netif_start_queue(dev);
1469 /*====================================================================*/
1471 static void smc_tx_timeout(struct net_device *dev)
1473 struct smc_private *smc = netdev_priv(dev);
1474 kio_addr_t ioaddr = dev->base_addr;
1476 printk(KERN_NOTICE "%s: SMC91c92 transmit timed out, "
1477 "Tx_status %2.2x status %4.4x.\n",
1478 dev->name, inw(ioaddr)&0xff, inw(ioaddr + 2));
1479 smc->stats.tx_errors++;
1481 dev->trans_start = jiffies;
1482 smc->saved_skb = NULL;
1483 netif_wake_queue(dev);
1486 static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev)
1488 struct smc_private *smc = netdev_priv(dev);
1489 kio_addr_t ioaddr = dev->base_addr;
1493 netif_stop_queue(dev);
1495 DEBUG(2, "%s: smc_start_xmit(length = %d) called,"
1496 " status %4.4x.\n", dev->name, skb->len, inw(ioaddr + 2));
1498 if (smc->saved_skb) {
1499 /* THIS SHOULD NEVER HAPPEN. */
1500 smc->stats.tx_aborted_errors++;
1501 printk(KERN_DEBUG "%s: Internal error -- sent packet while busy.\n",
1505 smc->saved_skb = skb;
1507 num_pages = skb->len >> 8;
1509 if (num_pages > 7) {
1510 printk(KERN_ERR "%s: Far too big packet error.\n", dev->name);
1511 dev_kfree_skb (skb);
1512 smc->saved_skb = NULL;
1513 smc->stats.tx_dropped++;
1514 return 0; /* Do not re-queue this packet. */
1516 /* A packet is now waiting. */
1517 smc->packets_waiting++;
1519 SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */
1521 /* need MC_RESET to keep the memory consistent. errata? */
1523 outw(MC_RESET, ioaddr + MMU_CMD);
1527 /* Allocate the memory; send the packet now if we win. */
1528 outw(MC_ALLOC | num_pages, ioaddr + MMU_CMD);
1529 for (time_out = MEMORY_WAIT_TIME; time_out >= 0; time_out--) {
1530 ir = inw(ioaddr+INTERRUPT);
1531 if (ir & IM_ALLOC_INT) {
1532 /* Acknowledge the interrupt, send the packet. */
1533 outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT);
1534 smc_hardware_send_packet(dev); /* Send the packet now.. */
1539 /* Otherwise defer until the Tx-space-allocated interrupt. */
1540 DEBUG(2, "%s: memory allocation deferred.\n", dev->name);
1541 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT);
1546 /*======================================================================
1548 Handle a Tx anomolous event. Entered while in Window 2.
1550 ======================================================================*/
1552 static void smc_tx_err(struct net_device * dev)
1554 struct smc_private *smc = netdev_priv(dev);
1555 kio_addr_t ioaddr = dev->base_addr;
1556 int saved_packet = inw(ioaddr + PNR_ARR) & 0xff;
1557 int packet_no = inw(ioaddr + FIFO_PORTS) & 0x7f;
1560 /* select this as the packet to read from */
1561 outw(packet_no, ioaddr + PNR_ARR);
1563 /* read the first word from this packet */
1564 outw(PTR_AUTOINC | PTR_READ | 0, ioaddr + POINTER);
1566 tx_status = inw(ioaddr + DATA_1);
1568 smc->stats.tx_errors++;
1569 if (tx_status & TS_LOSTCAR) smc->stats.tx_carrier_errors++;
1570 if (tx_status & TS_LATCOL) smc->stats.tx_window_errors++;
1571 if (tx_status & TS_16COL) {
1572 smc->stats.tx_aborted_errors++;
1576 if (tx_status & TS_SUCCESS) {
1577 printk(KERN_NOTICE "%s: Successful packet caused error "
1578 "interrupt?\n", dev->name);
1580 /* re-enable transmit */
1582 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1585 outw(MC_FREEPKT, ioaddr + MMU_CMD); /* Free the packet memory. */
1587 /* one less packet waiting for me */
1588 smc->packets_waiting--;
1590 outw(saved_packet, ioaddr + PNR_ARR);
1594 /*====================================================================*/
1596 static void smc_eph_irq(struct net_device *dev)
1598 struct smc_private *smc = netdev_priv(dev);
1599 kio_addr_t ioaddr = dev->base_addr;
1600 u_short card_stats, ephs;
1603 ephs = inw(ioaddr + EPH);
1604 DEBUG(2, "%s: Ethernet protocol handler interrupt, status"
1605 " %4.4x.\n", dev->name, ephs);
1606 /* Could be a counter roll-over warning: update stats. */
1607 card_stats = inw(ioaddr + COUNTER);
1608 /* single collisions */
1609 smc->stats.collisions += card_stats & 0xF;
1611 /* multiple collisions */
1612 smc->stats.collisions += card_stats & 0xF;
1613 #if 0 /* These are for when linux supports these statistics */
1614 card_stats >>= 4; /* deferred */
1615 card_stats >>= 4; /* excess deferred */
1617 /* If we had a transmit error we must re-enable the transmitter. */
1618 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1620 /* Clear a link error interrupt. */
1622 outw(CTL_AUTO_RELEASE | 0x0000, ioaddr + CONTROL);
1623 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1628 /*====================================================================*/
1630 static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1632 struct net_device *dev = dev_id;
1633 struct smc_private *smc = netdev_priv(dev);
1635 u_short saved_bank, saved_pointer, mask, status;
1636 unsigned int handled = 1;
1637 char bogus_cnt = INTR_WORK; /* Work we are willing to do. */
1639 if (!netif_device_present(dev))
1642 ioaddr = dev->base_addr;
1644 DEBUG(3, "%s: SMC91c92 interrupt %d at %#x.\n", dev->name,
1648 saved_bank = inw(ioaddr + BANK_SELECT);
1649 if ((saved_bank & 0xff00) != 0x3300) {
1650 /* The device does not exist -- the card could be off-line, or
1651 maybe it has been ejected. */
1652 DEBUG(1, "%s: SMC91c92 interrupt %d for non-existent"
1653 "/ejected device.\n", dev->name, irq);
1659 saved_pointer = inw(ioaddr + POINTER);
1660 mask = inw(ioaddr + INTERRUPT) >> 8;
1661 /* clear all interrupts */
1662 outw(0, ioaddr + INTERRUPT);
1664 do { /* read the status flag, and mask it */
1665 status = inw(ioaddr + INTERRUPT) & 0xff;
1666 DEBUG(3, "%s: Status is %#2.2x (mask %#2.2x).\n", dev->name,
1668 if ((status & mask) == 0) {
1669 if (bogus_cnt == INTR_WORK)
1673 if (status & IM_RCV_INT) {
1674 /* Got a packet(s). */
1677 if (status & IM_TX_INT) {
1679 outw(IM_TX_INT, ioaddr + INTERRUPT);
1682 if (status & IM_TX_EMPTY_INT) {
1683 outw(IM_TX_EMPTY_INT, ioaddr + INTERRUPT);
1684 mask &= ~IM_TX_EMPTY_INT;
1685 smc->stats.tx_packets += smc->packets_waiting;
1686 smc->packets_waiting = 0;
1688 if (status & IM_ALLOC_INT) {
1689 /* Clear this interrupt so it doesn't happen again */
1690 mask &= ~IM_ALLOC_INT;
1692 smc_hardware_send_packet(dev);
1694 /* enable xmit interrupts based on this */
1695 mask |= (IM_TX_EMPTY_INT | IM_TX_INT);
1697 /* and let the card send more packets to me */
1698 netif_wake_queue(dev);
1700 if (status & IM_RX_OVRN_INT) {
1701 smc->stats.rx_errors++;
1702 smc->stats.rx_fifo_errors++;
1704 smc->rx_ovrn = 1; /* need MC_RESET outside smc_interrupt */
1705 outw(IM_RX_OVRN_INT, ioaddr + INTERRUPT);
1707 if (status & IM_EPH_INT)
1709 } while (--bogus_cnt);
1711 DEBUG(3, " Restoring saved registers mask %2.2x bank %4.4x"
1712 " pointer %4.4x.\n", mask, saved_bank, saved_pointer);
1714 /* restore state register */
1715 outw((mask<<8), ioaddr + INTERRUPT);
1716 outw(saved_pointer, ioaddr + POINTER);
1717 SMC_SELECT_BANK(saved_bank);
1719 DEBUG(3, "%s: Exiting interrupt IRQ%d.\n", dev->name, irq);
1723 if ((smc->manfid == MANFID_OSITECH) &&
1724 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1725 /* Retrigger interrupt if needed */
1726 mask_bits(0x00ff, ioaddr-0x10+OSITECH_RESET_ISR);
1727 set_bits(0x0300, ioaddr-0x10+OSITECH_RESET_ISR);
1729 if (smc->manfid == MANFID_MOTOROLA) {
1731 cor = readb(smc->base + MOT_UART + CISREG_COR);
1732 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_UART + CISREG_COR);
1733 writeb(cor, smc->base + MOT_UART + CISREG_COR);
1734 cor = readb(smc->base + MOT_LAN + CISREG_COR);
1735 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_LAN + CISREG_COR);
1736 writeb(cor, smc->base + MOT_LAN + CISREG_COR);
1738 #ifdef DOES_NOT_WORK
1739 if (smc->base != NULL) { /* Megahertz MFC's */
1740 readb(smc->base+MEGAHERTZ_ISR);
1741 readb(smc->base+MEGAHERTZ_ISR);
1744 return IRQ_RETVAL(handled);
1747 /*====================================================================*/
1749 static void smc_rx(struct net_device *dev)
1751 struct smc_private *smc = netdev_priv(dev);
1752 kio_addr_t ioaddr = dev->base_addr;
1754 int packet_length; /* Caution: not frame length, rather words
1755 to transfer from the chip. */
1757 /* Assertion: we are in Window 2. */
1759 if (inw(ioaddr + FIFO_PORTS) & FP_RXEMPTY) {
1760 printk(KERN_ERR "%s: smc_rx() with nothing on Rx FIFO.\n",
1765 /* Reset the read pointer, and read the status and packet length. */
1766 outw(PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER);
1767 rx_status = inw(ioaddr + DATA_1);
1768 packet_length = inw(ioaddr + DATA_1) & 0x07ff;
1770 DEBUG(2, "%s: Receive status %4.4x length %d.\n",
1771 dev->name, rx_status, packet_length);
1773 if (!(rx_status & RS_ERRORS)) {
1774 /* do stuff to make a new packet */
1775 struct sk_buff *skb;
1777 /* Note: packet_length adds 5 or 6 extra bytes here! */
1778 skb = dev_alloc_skb(packet_length+2);
1781 DEBUG(1, "%s: Low memory, packet dropped.\n", dev->name);
1782 smc->stats.rx_dropped++;
1783 outw(MC_RELEASE, ioaddr + MMU_CMD);
1787 packet_length -= (rx_status & RS_ODDFRAME ? 5 : 6);
1788 skb_reserve(skb, 2);
1789 insw(ioaddr+DATA_1, skb_put(skb, packet_length),
1790 (packet_length+1)>>1);
1791 skb->protocol = eth_type_trans(skb, dev);
1795 dev->last_rx = jiffies;
1796 smc->stats.rx_packets++;
1797 smc->stats.rx_bytes += packet_length;
1798 if (rx_status & RS_MULTICAST)
1799 smc->stats.multicast++;
1802 smc->stats.rx_errors++;
1804 if (rx_status & RS_ALGNERR) smc->stats.rx_frame_errors++;
1805 if (rx_status & (RS_TOOSHORT | RS_TOOLONG))
1806 smc->stats.rx_length_errors++;
1807 if (rx_status & RS_BADCRC) smc->stats.rx_crc_errors++;
1809 /* Let the MMU free the memory of this packet. */
1810 outw(MC_RELEASE, ioaddr + MMU_CMD);
1815 /*====================================================================*/
1817 static struct net_device_stats *smc_get_stats(struct net_device *dev)
1819 struct smc_private *smc = netdev_priv(dev);
1820 /* Nothing to update - the 91c92 is a pretty primative chip. */
1824 /*======================================================================
1826 Calculate values for the hardware multicast filter hash table.
1828 ======================================================================*/
1830 static void fill_multicast_tbl(int count, struct dev_mc_list *addrs,
1831 u_char *multicast_table)
1833 struct dev_mc_list *mc_addr;
1835 for (mc_addr = addrs; mc_addr && count-- > 0; mc_addr = mc_addr->next) {
1836 u_int position = ether_crc(6, mc_addr->dmi_addr);
1837 #ifndef final_version /* Verify multicast address. */
1838 if ((mc_addr->dmi_addr[0] & 1) == 0)
1841 multicast_table[position >> 29] |= 1 << ((position >> 26) & 7);
1845 /*======================================================================
1847 Set the receive mode.
1849 This routine is used by both the protocol level to notify us of
1850 promiscuous/multicast mode changes, and by the open/reset code to
1851 initialize the Rx registers. We always set the multicast list and
1852 leave the receiver running.
1854 ======================================================================*/
1856 static void set_rx_mode(struct net_device *dev)
1858 kio_addr_t ioaddr = dev->base_addr;
1859 struct smc_private *smc = netdev_priv(dev);
1860 u_int multicast_table[ 2 ] = { 0, };
1861 unsigned long flags;
1862 u_short rx_cfg_setting;
1864 if (dev->flags & IFF_PROMISC) {
1865 printk(KERN_NOTICE "%s: setting Rx mode to promiscuous.\n", dev->name);
1866 rx_cfg_setting = RxStripCRC | RxEnable | RxPromisc | RxAllMulti;
1867 } else if (dev->flags & IFF_ALLMULTI)
1868 rx_cfg_setting = RxStripCRC | RxEnable | RxAllMulti;
1870 if (dev->mc_count) {
1871 fill_multicast_tbl(dev->mc_count, dev->mc_list,
1872 (u_char *)multicast_table);
1874 rx_cfg_setting = RxStripCRC | RxEnable;
1877 /* Load MC table and Rx setting into the chip without interrupts. */
1878 spin_lock_irqsave(&smc->lock, flags);
1880 outl(multicast_table[0], ioaddr + MULTICAST0);
1881 outl(multicast_table[1], ioaddr + MULTICAST4);
1883 outw(rx_cfg_setting, ioaddr + RCR);
1885 spin_unlock_irqrestore(&smc->lock, flags);
1890 /*======================================================================
1892 Senses when a card's config changes. Here, it's coax or TP.
1894 ======================================================================*/
1896 static int s9k_config(struct net_device *dev, struct ifmap *map)
1898 struct smc_private *smc = netdev_priv(dev);
1899 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
1900 if (smc->cfg & CFG_MII_SELECT)
1902 else if (map->port > 2)
1904 dev->if_port = map->port;
1905 printk(KERN_INFO "%s: switched to %s port\n",
1906 dev->name, if_names[dev->if_port]);
1912 /*======================================================================
1914 Reset the chip, reloading every register that might be corrupted.
1916 ======================================================================*/
1919 Set transceiver type, perhaps to something other than what the user
1920 specified in dev->if_port.
1922 static void smc_set_xcvr(struct net_device *dev, int if_port)
1924 struct smc_private *smc = netdev_priv(dev);
1925 kio_addr_t ioaddr = dev->base_addr;
1928 saved_bank = inw(ioaddr + BANK_SELECT);
1931 outw(smc->cfg | CFG_AUI_SELECT, ioaddr + CONFIG);
1932 if ((smc->manfid == MANFID_OSITECH) &&
1933 (smc->cardid != PRODID_OSITECH_SEVEN))
1934 set_bits(OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1935 smc->media_status = ((dev->if_port == 0) ? 0x0001 : 0x0002);
1937 outw(smc->cfg, ioaddr + CONFIG);
1938 if ((smc->manfid == MANFID_OSITECH) &&
1939 (smc->cardid != PRODID_OSITECH_SEVEN))
1940 mask_bits(~OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1941 smc->media_status = ((dev->if_port == 0) ? 0x0012 : 0x4001);
1943 SMC_SELECT_BANK(saved_bank);
1946 static void smc_reset(struct net_device *dev)
1948 kio_addr_t ioaddr = dev->base_addr;
1949 struct smc_private *smc = netdev_priv(dev);
1952 DEBUG(0, "%s: smc91c92 reset called.\n", dev->name);
1954 /* The first interaction must be a write to bring the chip out
1957 /* Reset the chip. */
1958 outw(RCR_SOFTRESET, ioaddr + RCR);
1961 /* Clear the transmit and receive configuration registers. */
1962 outw(RCR_CLEAR, ioaddr + RCR);
1963 outw(TCR_CLEAR, ioaddr + TCR);
1965 /* Set the Window 1 control, configuration and station addr registers.
1966 No point in writing the I/O base register ;-> */
1968 /* Automatically release succesfully transmitted packets,
1969 Accept link errors, counter and Tx error interrupts. */
1970 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1972 smc_set_xcvr(dev, dev->if_port);
1973 if ((smc->manfid == MANFID_OSITECH) &&
1974 (smc->cardid != PRODID_OSITECH_SEVEN))
1975 outw((dev->if_port == 2 ? OSI_AUI_PWR : 0) |
1976 (inw(ioaddr-0x10+OSITECH_AUI_PWR) & 0xff00),
1977 ioaddr - 0x10 + OSITECH_AUI_PWR);
1979 /* Fill in the physical address. The databook is wrong about the order! */
1980 for (i = 0; i < 6; i += 2)
1981 outw((dev->dev_addr[i+1]<<8)+dev->dev_addr[i],
1982 ioaddr + ADDR0 + i);
1986 outw(MC_RESET, ioaddr + MMU_CMD);
1987 outw(0, ioaddr + INTERRUPT);
1989 /* Re-enable the chip. */
1991 outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) |
1992 TCR_ENABLE | TCR_PAD_EN | smc->duplex, ioaddr + TCR);
1995 if (smc->cfg & CFG_MII_SELECT) {
1999 mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000);
2001 /* Advertise 100F, 100H, 10F, 10H */
2002 mdio_write(dev, smc->mii_if.phy_id, 4, 0x01e1);
2004 /* Restart MII autonegotiation */
2005 mdio_write(dev, smc->mii_if.phy_id, 0, 0x0000);
2006 mdio_write(dev, smc->mii_if.phy_id, 0, 0x1200);
2009 /* Enable interrupts. */
2011 outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,
2012 ioaddr + INTERRUPT);
2015 /*======================================================================
2017 Media selection timer routine
2019 ======================================================================*/
2021 static void media_check(u_long arg)
2023 struct net_device *dev = (struct net_device *) arg;
2024 struct smc_private *smc = netdev_priv(dev);
2025 kio_addr_t ioaddr = dev->base_addr;
2026 u_short i, media, saved_bank;
2029 saved_bank = inw(ioaddr + BANK_SELECT);
2031 if (!netif_device_present(dev))
2036 /* need MC_RESET to keep the memory consistent. errata? */
2038 outw(MC_RESET, ioaddr + MMU_CMD);
2041 i = inw(ioaddr + INTERRUPT);
2043 media = inw(ioaddr + EPH) & EPH_LINK_OK;
2045 media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1;
2047 /* Check for pending interrupt with watchdog flag set: with
2048 this, we can limp along even if the interrupt is blocked */
2049 if (smc->watchdog++ && ((i>>8) & i)) {
2050 if (!smc->fast_poll)
2051 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
2052 smc_interrupt(dev->irq, smc, NULL);
2053 smc->fast_poll = HZ;
2055 if (smc->fast_poll) {
2057 smc->media.expires = jiffies + HZ/100;
2058 add_timer(&smc->media);
2059 SMC_SELECT_BANK(saved_bank);
2063 if (smc->cfg & CFG_MII_SELECT) {
2064 if (smc->mii_if.phy_id < 0)
2068 link = mdio_read(dev, smc->mii_if.phy_id, 1);
2069 if (!link || (link == 0xffff)) {
2070 printk(KERN_INFO "%s: MII is missing!\n", dev->name);
2071 smc->mii_if.phy_id = -1;
2076 if (link != smc->link_status) {
2077 u_short p = mdio_read(dev, smc->mii_if.phy_id, 5);
2078 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2079 (link) ? "found" : "lost");
2080 smc->duplex = (((p & 0x0100) || ((p & 0x1c0) == 0x40))
2083 printk(KERN_INFO "%s: autonegotiation complete: "
2084 "%sbaseT-%cD selected\n", dev->name,
2085 ((p & 0x0180) ? "100" : "10"),
2086 (smc->duplex ? 'F' : 'H'));
2089 outw(inw(ioaddr + TCR) | smc->duplex, ioaddr + TCR);
2090 smc->link_status = link;
2095 /* Ignore collisions unless we've had no rx's recently */
2096 if (time_after(jiffies, dev->last_rx + HZ)) {
2097 if (smc->tx_err || (smc->media_status & EPH_16COL))
2102 if (media != smc->media_status) {
2103 if ((media & smc->media_status & 1) &&
2104 ((smc->media_status ^ media) & EPH_LINK_OK))
2105 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2106 (smc->media_status & EPH_LINK_OK ? "lost" : "found"));
2107 else if ((media & smc->media_status & 2) &&
2108 ((smc->media_status ^ media) & EPH_16COL))
2109 printk(KERN_INFO "%s: coax cable %s\n", dev->name,
2110 (media & EPH_16COL ? "problem" : "ok"));
2111 if (dev->if_port == 0) {
2113 if (media & EPH_LINK_OK)
2114 printk(KERN_INFO "%s: flipped to 10baseT\n",
2117 smc_set_xcvr(dev, 2);
2119 if (media & EPH_16COL)
2120 smc_set_xcvr(dev, 1);
2122 printk(KERN_INFO "%s: flipped to 10base2\n",
2126 smc->media_status = media;
2130 smc->media.expires = jiffies + HZ;
2131 add_timer(&smc->media);
2132 SMC_SELECT_BANK(saved_bank);
2135 static int smc_link_ok(struct net_device *dev)
2137 kio_addr_t ioaddr = dev->base_addr;
2138 struct smc_private *smc = netdev_priv(dev);
2140 if (smc->cfg & CFG_MII_SELECT) {
2141 return mii_link_ok(&smc->mii_if);
2144 return inw(ioaddr + EPH) & EPH_LINK_OK;
2148 static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2151 kio_addr_t ioaddr = dev->base_addr;
2153 ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |
2154 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);
2157 tmp = inw(ioaddr + CONFIG);
2158 ecmd->port = (tmp & CFG_AUI_SELECT) ? PORT_AUI : PORT_TP;
2159 ecmd->transceiver = XCVR_INTERNAL;
2160 ecmd->speed = SPEED_10;
2161 ecmd->phy_address = ioaddr + MGMT;
2164 tmp = inw(ioaddr + TCR);
2165 ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF;
2170 static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2173 kio_addr_t ioaddr = dev->base_addr;
2175 if (ecmd->speed != SPEED_10)
2177 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
2179 if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI)
2181 if (ecmd->transceiver != XCVR_INTERNAL)
2184 if (ecmd->port == PORT_AUI)
2185 smc_set_xcvr(dev, 1);
2187 smc_set_xcvr(dev, 0);
2190 tmp = inw(ioaddr + TCR);
2191 if (ecmd->duplex == DUPLEX_FULL)
2195 outw(tmp, ioaddr + TCR);
2200 static int check_if_running(struct net_device *dev)
2202 if (!netif_running(dev))
2207 static void smc_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2209 strcpy(info->driver, DRV_NAME);
2210 strcpy(info->version, DRV_VERSION);
2213 static int smc_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2215 struct smc_private *smc = netdev_priv(dev);
2216 kio_addr_t ioaddr = dev->base_addr;
2217 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2221 spin_lock_irq(&smc->lock);
2222 if (smc->cfg & CFG_MII_SELECT)
2223 ret = mii_ethtool_gset(&smc->mii_if, ecmd);
2225 ret = smc_netdev_get_ecmd(dev, ecmd);
2226 spin_unlock_irq(&smc->lock);
2227 SMC_SELECT_BANK(saved_bank);
2231 static int smc_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2233 struct smc_private *smc = netdev_priv(dev);
2234 kio_addr_t ioaddr = dev->base_addr;
2235 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2239 spin_lock_irq(&smc->lock);
2240 if (smc->cfg & CFG_MII_SELECT)
2241 ret = mii_ethtool_sset(&smc->mii_if, ecmd);
2243 ret = smc_netdev_set_ecmd(dev, ecmd);
2244 spin_unlock_irq(&smc->lock);
2245 SMC_SELECT_BANK(saved_bank);
2249 static u32 smc_get_link(struct net_device *dev)
2251 struct smc_private *smc = netdev_priv(dev);
2252 kio_addr_t ioaddr = dev->base_addr;
2253 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2257 spin_lock_irq(&smc->lock);
2258 ret = smc_link_ok(dev);
2259 spin_unlock_irq(&smc->lock);
2260 SMC_SELECT_BANK(saved_bank);
2265 static u32 smc_get_msglevel(struct net_device *dev)
2270 static void smc_set_msglevel(struct net_device *dev, u32 val)
2276 static int smc_nway_reset(struct net_device *dev)
2278 struct smc_private *smc = netdev_priv(dev);
2279 if (smc->cfg & CFG_MII_SELECT) {
2280 kio_addr_t ioaddr = dev->base_addr;
2281 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2285 res = mii_nway_restart(&smc->mii_if);
2286 SMC_SELECT_BANK(saved_bank);
2293 static struct ethtool_ops ethtool_ops = {
2294 .begin = check_if_running,
2295 .get_drvinfo = smc_get_drvinfo,
2296 .get_settings = smc_get_settings,
2297 .set_settings = smc_set_settings,
2298 .get_link = smc_get_link,
2300 .get_msglevel = smc_get_msglevel,
2301 .set_msglevel = smc_set_msglevel,
2303 .nway_reset = smc_nway_reset,
2306 static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
2308 struct smc_private *smc = netdev_priv(dev);
2309 struct mii_ioctl_data *mii = if_mii(rq);
2312 kio_addr_t ioaddr = dev->base_addr;
2314 if (!netif_running(dev))
2317 spin_lock_irq(&smc->lock);
2318 saved_bank = inw(ioaddr + BANK_SELECT);
2320 rc = generic_mii_ioctl(&smc->mii_if, mii, cmd, NULL);
2321 SMC_SELECT_BANK(saved_bank);
2322 spin_unlock_irq(&smc->lock);
2326 static struct pcmcia_device_id smc91c92_ids[] = {
2327 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0109, 0x0501),
2328 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0140, 0x000a),
2329 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63),
2330 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63),
2331 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef),
2332 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
2333 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
2334 PCMCIA_PFC_DEVICE_PROD_ID12(0, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
2335 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Diamonds Modem+Ethernet", 0xc2f80cd, 0x656947b9),
2336 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Hearts Modem+Ethernet", 0xc2f80cd, 0xdc9ba5ed),
2337 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x016c, 0x0020),
2338 PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0023),
2339 PCMCIA_DEVICE_PROD_ID123("BASICS by New Media Corporation", "Ethernet", "SMC91C94", 0x23c78a9d, 0x00b2e941, 0xcef397fb),
2340 PCMCIA_DEVICE_PROD_ID12("ARGOSY", "Fast Ethernet PCCard", 0x78f308dc, 0xdcea68bc),
2341 PCMCIA_DEVICE_PROD_ID12("dit Co., Ltd.", "PC Card-10/100BTX", 0xe59365c8, 0x6a2161d1),
2342 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L100C", 0x6a26d1cf, 0xc16ce9c5),
2343 PCMCIA_DEVICE_PROD_ID12("Farallon", "Farallon Enet", 0x58d93fc4, 0x244734e9),
2344 PCMCIA_DEVICE_PROD_ID12("Megahertz", "CC10BT/2", 0x33234748, 0x3c95b953),
2345 PCMCIA_DEVICE_PROD_ID12("MELCO/SMC", "LPC-TX", 0xa2cd8e6d, 0x42da662a),
2346 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Four of Diamonds Ethernet", 0xc2f80cd, 0xb3466314),
2347 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Seven of Diamonds Ethernet", 0xc2f80cd, 0x194b650a),
2348 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast Ethernet PCCard", 0x281f1c5d, 0xdcea68bc),
2349 PCMCIA_DEVICE_PROD_ID12("Psion", "10Mb Ethernet", 0x4ef00b21, 0x844be9e9),
2350 PCMCIA_DEVICE_PROD_ID12("SMC", "EtherEZ Ethernet 8020", 0xc4f8b18b, 0x4a0eeb2d),
2351 /* These conflict with other cards! */
2352 /* PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0100), */
2353 /* PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab), */
2356 MODULE_DEVICE_TABLE(pcmcia, smc91c92_ids);
2358 static struct pcmcia_driver smc91c92_cs_driver = {
2359 .owner = THIS_MODULE,
2361 .name = "smc91c92_cs",
2363 .attach = smc91c92_attach,
2364 .event = smc91c92_event,
2365 .detach = smc91c92_detach,
2366 .id_table = smc91c92_ids,
2369 static int __init init_smc91c92_cs(void)
2371 return pcmcia_register_driver(&smc91c92_cs_driver);
2374 static void __exit exit_smc91c92_cs(void)
2376 pcmcia_unregister_driver(&smc91c92_cs_driver);
2377 BUG_ON(dev_list != NULL);
2380 module_init(init_smc91c92_cs);
2381 module_exit(exit_smc91c92_cs);