1 /*======================================================================
3 A PCMCIA ethernet driver for SMC91c92-based cards.
5 This driver supports Megahertz PCMCIA ethernet cards; and
6 Megahertz, Motorola, Ositech, and Psion Dacom ethernet/modem
9 Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net
11 smc91c92_cs.c 1.122 2002/10/25 06:26:39
13 This driver contains code written by Donald Becker
14 (becker@scyld.com), Rowan Hughes (x-csrdh@jcu.edu.au),
15 David Hinds (dahinds@users.sourceforge.net), and Erik Stahlman
16 (erik@vt.edu). Donald wrote the SMC 91c92 code using parts of
17 Erik's SMC 91c94 driver. Rowan wrote a similar driver, and I've
18 incorporated some parts of his driver here. I (Dave) wrote most
19 of the PCMCIA glue code, and the Ositech support code. Kelly
20 Stephens (kstephen@holli.com) added support for the Motorola
21 Mariner, with help from Allen Brost.
23 This software may be used and distributed according to the terms of
24 the GNU General Public License, incorporated herein by reference.
26 ======================================================================*/
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/string.h>
33 #include <linux/timer.h>
34 #include <linux/interrupt.h>
35 #include <linux/delay.h>
36 #include <linux/crc32.h>
37 #include <linux/netdevice.h>
38 #include <linux/etherdevice.h>
39 #include <linux/skbuff.h>
40 #include <linux/if_arp.h>
41 #include <linux/ioport.h>
42 #include <linux/ethtool.h>
43 #include <linux/mii.h>
45 #include <pcmcia/version.h>
46 #include <pcmcia/cs_types.h>
47 #include <pcmcia/cs.h>
48 #include <pcmcia/cistpl.h>
49 #include <pcmcia/cisreg.h>
50 #include <pcmcia/ciscode.h>
51 #include <pcmcia/ds.h>
54 #include <asm/system.h>
55 #include <asm/uaccess.h>
57 /* Ositech Seven of Diamonds firmware */
60 /*====================================================================*/
62 static char *if_names[] = { "auto", "10baseT", "10base2"};
64 /* Module parameters */
66 MODULE_DESCRIPTION("SMC 91c92 series PCMCIA ethernet driver");
67 MODULE_LICENSE("GPL");
69 #define INT_MODULE_PARM(n, v) static int n = v; module_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.EventMask = CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
374 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
375 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
376 client_reg.event_handler = &smc91c92_event;
377 client_reg.Version = 0x0210;
378 client_reg.event_callback_args.client_data = link;
379 ret = pcmcia_register_client(&link->handle, &client_reg);
381 cs_error(link->handle, RegisterClient, ret);
382 smc91c92_detach(link);
387 } /* smc91c92_attach */
389 /*======================================================================
391 This deletes a driver "instance". The device is de-registered
392 with Card Services. If it has been released, all local data
393 structures are freed. Otherwise, the structures will be freed
394 when the device is released.
396 ======================================================================*/
398 static void smc91c92_detach(dev_link_t *link)
400 struct net_device *dev = link->priv;
403 DEBUG(0, "smc91c92_detach(0x%p)\n", link);
405 /* Locate device structure */
406 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
407 if (*linkp == link) break;
412 unregister_netdev(dev);
414 if (link->state & DEV_CONFIG)
415 smc91c92_release(link);
418 pcmcia_deregister_client(link->handle);
420 /* Unlink device structure, free bits */
423 } /* smc91c92_detach */
425 /*====================================================================*/
427 static int cvt_ascii_address(struct net_device *dev, char *s)
433 for (i = 0; i < 6; i++) {
435 for (j = 0; j < 2; j++) {
438 da += ((c >= '0') && (c <= '9')) ?
439 (c - '0') : ((c & 0x0f) + 9);
441 dev->dev_addr[i] = da;
446 /*====================================================================*/
448 static int first_tuple(client_handle_t handle, tuple_t *tuple,
453 if ((i = pcmcia_get_first_tuple(handle, tuple)) != CS_SUCCESS ||
454 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
456 return pcmcia_parse_tuple(handle, tuple, parse);
459 static int next_tuple(client_handle_t handle, tuple_t *tuple,
464 if ((i = pcmcia_get_next_tuple(handle, tuple)) != CS_SUCCESS ||
465 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
467 return pcmcia_parse_tuple(handle, tuple, parse);
470 /*======================================================================
472 Configuration stuff for Megahertz cards
474 mhz_3288_power() is used to power up a 3288's ethernet chip.
475 mhz_mfc_config() handles socket setup for multifunction (1144
476 and 3288) cards. mhz_setup() gets a card's hardware ethernet
479 ======================================================================*/
481 static int mhz_3288_power(dev_link_t *link)
483 struct net_device *dev = link->priv;
484 struct smc_private *smc = netdev_priv(dev);
487 /* Read the ISR twice... */
488 readb(smc->base+MEGAHERTZ_ISR);
490 readb(smc->base+MEGAHERTZ_ISR);
495 /* Now read and write the COR... */
496 tmp = readb(smc->base + link->conf.ConfigBase + CISREG_COR);
498 writeb(tmp, smc->base + link->conf.ConfigBase + CISREG_COR);
503 static int mhz_mfc_config(dev_link_t *link)
505 struct net_device *dev = link->priv;
506 struct smc_private *smc = netdev_priv(dev);
507 struct smc_cfg_mem *cfg_mem;
510 cistpl_cftable_entry_t *cf;
516 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
518 return CS_OUT_OF_RESOURCE;
520 tuple = &cfg_mem->tuple;
521 parse = &cfg_mem->parse;
522 cf = &parse->cftable_entry;
525 link->conf.Attributes |= CONF_ENABLE_SPKR;
526 link->conf.Status = CCSR_AUDIO_ENA;
527 link->irq.Attributes =
528 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
529 link->io.IOAddrLines = 16;
530 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
531 link->io.NumPorts2 = 8;
533 tuple->Attributes = tuple->TupleOffset = 0;
534 tuple->TupleData = (cisdata_t *)buf;
535 tuple->TupleDataMax = 255;
536 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
538 i = first_tuple(link->handle, tuple, parse);
539 /* The Megahertz combo cards have modem-like CIS entries, so
540 we have to explicitly try a bunch of port combinations. */
541 while (i == CS_SUCCESS) {
542 link->conf.ConfigIndex = cf->index;
543 link->io.BasePort2 = cf->io.win[0].base;
544 for (k = 0; k < 0x400; k += 0x10) {
545 if (k & 0x80) continue;
546 link->io.BasePort1 = k ^ 0x300;
547 i = pcmcia_request_io(link->handle, &link->io);
548 if (i == CS_SUCCESS) break;
550 if (i == CS_SUCCESS) break;
551 i = next_tuple(link->handle, tuple, parse);
555 dev->base_addr = link->io.BasePort1;
557 /* Allocate a memory window, for accessing the ISR */
558 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
559 req.Base = req.Size = 0;
561 i = pcmcia_request_window(&link->handle, &req, &link->win);
564 smc->base = ioremap(req.Base, req.Size);
565 mem.CardOffset = mem.Page = 0;
566 if (smc->manfid == MANFID_MOTOROLA)
567 mem.CardOffset = link->conf.ConfigBase;
568 i = pcmcia_map_mem_page(link->win, &mem);
570 if ((i == CS_SUCCESS)
571 && (smc->manfid == MANFID_MEGAHERTZ)
572 && (smc->cardid == PRODID_MEGAHERTZ_EM3288))
573 mhz_3288_power(link);
580 static int mhz_setup(dev_link_t *link)
582 client_handle_t handle = link->handle;
583 struct net_device *dev = link->priv;
584 struct smc_cfg_mem *cfg_mem;
587 u_char *buf, *station_addr;
590 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
594 tuple = &cfg_mem->tuple;
595 parse = &cfg_mem->parse;
598 tuple->Attributes = tuple->TupleOffset = 0;
599 tuple->TupleData = (cisdata_t *)buf;
600 tuple->TupleDataMax = 255;
602 /* Read the station address from the CIS. It is stored as the last
603 (fourth) string in the Version 1 Version/ID tuple. */
604 tuple->DesiredTuple = CISTPL_VERS_1;
605 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {
609 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
610 if (next_tuple(handle, tuple, parse) != CS_SUCCESS)
611 first_tuple(handle, tuple, parse);
612 if (parse->version_1.ns > 3) {
613 station_addr = parse->version_1.str + parse->version_1.ofs[3];
614 if (cvt_ascii_address(dev, station_addr) == 0) {
620 /* Another possibility: for the EM3288, in a special tuple */
621 tuple->DesiredTuple = 0x81;
622 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) {
626 if (pcmcia_get_tuple_data(handle, tuple) != CS_SUCCESS) {
631 if (cvt_ascii_address(dev, buf) == 0) {
641 /*======================================================================
643 Configuration stuff for the Motorola Mariner
645 mot_config() writes directly to the Mariner configuration
646 registers because the CIS is just bogus.
648 ======================================================================*/
650 static void mot_config(dev_link_t *link)
652 struct net_device *dev = link->priv;
653 struct smc_private *smc = netdev_priv(dev);
654 kio_addr_t ioaddr = dev->base_addr;
655 kio_addr_t iouart = link->io.BasePort2;
657 /* Set UART base address and force map with COR bit 1 */
658 writeb(iouart & 0xff, smc->base + MOT_UART + CISREG_IOBASE_0);
659 writeb((iouart >> 8) & 0xff, smc->base + MOT_UART + CISREG_IOBASE_1);
660 writeb(MOT_NORMAL, smc->base + MOT_UART + CISREG_COR);
662 /* Set SMC base address and force map with COR bit 1 */
663 writeb(ioaddr & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_0);
664 writeb((ioaddr >> 8) & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_1);
665 writeb(MOT_NORMAL, smc->base + MOT_LAN + CISREG_COR);
667 /* Wait for things to settle down */
671 static int mot_setup(dev_link_t *link)
673 struct net_device *dev = link->priv;
674 kio_addr_t ioaddr = dev->base_addr;
678 /* Read Ethernet address from Serial EEPROM */
680 for (i = 0; i < 3; i++) {
682 outw(MOT_EEPROM + i, ioaddr + POINTER);
684 outw((CTL_RELOAD | CTL_EE_SELECT), ioaddr + CONTROL);
686 for (loop = wait = 0; loop < 200; loop++) {
688 wait = ((CTL_RELOAD | CTL_STORE) & inw(ioaddr + CONTROL));
689 if (wait == 0) break;
695 addr = inw(ioaddr + GENERAL);
696 dev->dev_addr[2*i] = addr & 0xff;
697 dev->dev_addr[2*i+1] = (addr >> 8) & 0xff;
703 /*====================================================================*/
705 static int smc_config(dev_link_t *link)
707 struct net_device *dev = link->priv;
708 struct smc_cfg_mem *cfg_mem;
711 cistpl_cftable_entry_t *cf;
715 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
717 return CS_OUT_OF_RESOURCE;
719 tuple = &cfg_mem->tuple;
720 parse = &cfg_mem->parse;
721 cf = &parse->cftable_entry;
724 tuple->Attributes = tuple->TupleOffset = 0;
725 tuple->TupleData = (cisdata_t *)buf;
726 tuple->TupleDataMax = 255;
727 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
729 link->io.NumPorts1 = 16;
730 i = first_tuple(link->handle, tuple, parse);
731 while (i != CS_NO_MORE_ITEMS) {
732 if (i == CS_SUCCESS) {
733 link->conf.ConfigIndex = cf->index;
734 link->io.BasePort1 = cf->io.win[0].base;
735 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
736 i = pcmcia_request_io(link->handle, &link->io);
737 if (i == CS_SUCCESS) break;
739 i = next_tuple(link->handle, tuple, parse);
742 dev->base_addr = link->io.BasePort1;
748 static int smc_setup(dev_link_t *link)
750 client_handle_t handle = link->handle;
751 struct net_device *dev = link->priv;
752 struct smc_cfg_mem *cfg_mem;
755 cistpl_lan_node_id_t *node_id;
756 u_char *buf, *station_addr;
759 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
761 return CS_OUT_OF_RESOURCE;
763 tuple = &cfg_mem->tuple;
764 parse = &cfg_mem->parse;
767 tuple->Attributes = tuple->TupleOffset = 0;
768 tuple->TupleData = (cisdata_t *)buf;
769 tuple->TupleDataMax = 255;
771 /* Check for a LAN function extension tuple */
772 tuple->DesiredTuple = CISTPL_FUNCE;
773 i = first_tuple(handle, tuple, parse);
774 while (i == CS_SUCCESS) {
775 if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID)
777 i = next_tuple(handle, tuple, parse);
779 if (i == CS_SUCCESS) {
780 node_id = (cistpl_lan_node_id_t *)parse->funce.data;
781 if (node_id->nb == 6) {
782 for (i = 0; i < 6; i++)
783 dev->dev_addr[i] = node_id->id[i];
788 /* Try the third string in the Version 1 Version/ID tuple. */
789 tuple->DesiredTuple = CISTPL_VERS_1;
790 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {
794 station_addr = parse->version_1.str + parse->version_1.ofs[2];
795 if (cvt_ascii_address(dev, station_addr) == 0) {
806 /*====================================================================*/
808 static int osi_config(dev_link_t *link)
810 struct net_device *dev = link->priv;
811 static kio_addr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
814 link->conf.Attributes |= CONF_ENABLE_SPKR;
815 link->conf.Status = CCSR_AUDIO_ENA;
816 link->irq.Attributes =
817 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
818 link->io.NumPorts1 = 64;
819 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
820 link->io.NumPorts2 = 8;
821 link->io.IOAddrLines = 16;
823 /* Enable Hard Decode, LAN, Modem */
824 link->conf.ConfigIndex = 0x23;
826 for (i = j = 0; j < 4; j++) {
827 link->io.BasePort2 = com[j];
828 i = pcmcia_request_io(link->handle, &link->io);
829 if (i == CS_SUCCESS) break;
831 if (i != CS_SUCCESS) {
832 /* Fallback: turn off hard decode */
833 link->conf.ConfigIndex = 0x03;
834 link->io.NumPorts2 = 0;
835 i = pcmcia_request_io(link->handle, &link->io);
837 dev->base_addr = link->io.BasePort1 + 0x10;
841 static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid)
843 client_handle_t handle = link->handle;
844 struct net_device *dev = link->priv;
845 struct smc_cfg_mem *cfg_mem;
850 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
854 tuple = &cfg_mem->tuple;
857 tuple->Attributes = TUPLE_RETURN_COMMON;
858 tuple->TupleData = (cisdata_t *)buf;
859 tuple->TupleDataMax = 255;
860 tuple->TupleOffset = 0;
862 /* Read the station address from tuple 0x90, subtuple 0x04 */
863 tuple->DesiredTuple = 0x90;
864 i = pcmcia_get_first_tuple(handle, tuple);
865 while (i == CS_SUCCESS) {
866 i = pcmcia_get_tuple_data(handle, tuple);
867 if ((i != CS_SUCCESS) || (buf[0] == 0x04))
869 i = pcmcia_get_next_tuple(handle, tuple);
871 if (i != CS_SUCCESS) {
875 for (i = 0; i < 6; i++)
876 dev->dev_addr[i] = buf[i+2];
878 if (((manfid == MANFID_OSITECH) &&
879 (cardid == PRODID_OSITECH_SEVEN)) ||
880 ((manfid == MANFID_PSION) &&
881 (cardid == PRODID_PSION_NET100))) {
882 /* Download the Seven of Diamonds firmware */
883 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
884 outb(__Xilinx7OD[i], link->io.BasePort1+2);
887 } else if (manfid == MANFID_OSITECH) {
888 /* Make sure both functions are powered up */
889 set_bits(0x300, link->io.BasePort1 + OSITECH_AUI_PWR);
890 /* Now, turn on the interrupt for both card functions */
891 set_bits(0x300, link->io.BasePort1 + OSITECH_RESET_ISR);
892 DEBUG(2, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n",
893 inw(link->io.BasePort1 + OSITECH_AUI_PWR),
894 inw(link->io.BasePort1 + OSITECH_RESET_ISR));
902 /*======================================================================
904 This verifies that the chip is some SMC91cXX variant, and returns
905 the revision code if successful. Otherwise, it returns -ENODEV.
907 ======================================================================*/
909 static int check_sig(dev_link_t *link)
911 struct net_device *dev = link->priv;
912 kio_addr_t ioaddr = dev->base_addr;
917 if (inw(ioaddr + BANK_SELECT) >> 8 != 0x33) {
918 /* Try powering up the chip */
919 outw(0, ioaddr + CONTROL);
923 /* Try setting bus width */
924 width = (link->io.Attributes1 == IO_DATA_PATH_WIDTH_AUTO);
925 s = inb(ioaddr + CONFIG);
930 outb(s, ioaddr + CONFIG);
932 /* Check Base Address Register to make sure bus width is OK */
933 s = inw(ioaddr + BASE_ADDR);
934 if ((inw(ioaddr + BANK_SELECT) >> 8 == 0x33) &&
935 ((s >> 8) != (s & 0xff))) {
937 s = inw(ioaddr + REVISION);
942 event_callback_args_t args;
943 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n");
944 args.client_data = link;
945 smc91c92_event(CS_EVENT_RESET_PHYSICAL, 0, &args);
946 pcmcia_release_io(link->handle, &link->io);
947 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
948 pcmcia_request_io(link->handle, &link->io);
949 smc91c92_event(CS_EVENT_CARD_RESET, 0, &args);
950 return check_sig(link);
955 /*======================================================================
957 smc91c92_config() is scheduled to run after a CARD_INSERTION event
958 is received, to configure the PCMCIA socket, and to make the
959 ethernet device available to the system.
961 ======================================================================*/
963 #define CS_EXIT_TEST(ret, svc, label) \
964 if (ret != CS_SUCCESS) { cs_error(link->handle, svc, ret); goto label; }
966 static void smc91c92_config(dev_link_t *link)
968 client_handle_t handle = link->handle;
969 struct net_device *dev = link->priv;
970 struct smc_private *smc = netdev_priv(dev);
971 struct smc_cfg_mem *cfg_mem;
980 DEBUG(0, "smc91c92_config(0x%p)\n", link);
982 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
986 tuple = &cfg_mem->tuple;
987 parse = &cfg_mem->parse;
990 tuple->Attributes = tuple->TupleOffset = 0;
991 tuple->TupleData = (cisdata_t *)buf;
992 tuple->TupleDataMax = 64;
994 tuple->DesiredTuple = CISTPL_CONFIG;
995 i = first_tuple(handle, tuple, parse);
996 CS_EXIT_TEST(i, ParseTuple, config_failed);
997 link->conf.ConfigBase = parse->config.base;
998 link->conf.Present = parse->config.rmask[0];
1000 tuple->DesiredTuple = CISTPL_MANFID;
1001 tuple->Attributes = TUPLE_RETURN_COMMON;
1002 if (first_tuple(handle, tuple, parse) == CS_SUCCESS) {
1003 smc->manfid = parse->manfid.manf;
1004 smc->cardid = parse->manfid.card;
1007 /* Configure card */
1008 link->state |= DEV_CONFIG;
1010 if ((smc->manfid == MANFID_OSITECH) &&
1011 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1012 i = osi_config(link);
1013 } else if ((smc->manfid == MANFID_MOTOROLA) ||
1014 ((smc->manfid == MANFID_MEGAHERTZ) &&
1015 ((smc->cardid == PRODID_MEGAHERTZ_VARIOUS) ||
1016 (smc->cardid == PRODID_MEGAHERTZ_EM3288)))) {
1017 i = mhz_mfc_config(link);
1019 i = smc_config(link);
1021 CS_EXIT_TEST(i, RequestIO, config_failed);
1023 i = pcmcia_request_irq(link->handle, &link->irq);
1024 CS_EXIT_TEST(i, RequestIRQ, config_failed);
1025 i = pcmcia_request_configuration(link->handle, &link->conf);
1026 CS_EXIT_TEST(i, RequestConfiguration, config_failed);
1028 if (smc->manfid == MANFID_MOTOROLA)
1031 dev->irq = link->irq.AssignedIRQ;
1033 if ((if_port >= 0) && (if_port <= 2))
1034 dev->if_port = if_port;
1036 printk(KERN_NOTICE "smc91c92_cs: invalid if_port requested\n");
1038 switch (smc->manfid) {
1039 case MANFID_OSITECH:
1041 i = osi_setup(link, smc->manfid, smc->cardid); break;
1043 case MANFID_NEW_MEDIA:
1044 i = smc_setup(link); break;
1045 case 0x128: /* For broken Megahertz cards */
1046 case MANFID_MEGAHERTZ:
1047 i = mhz_setup(link); break;
1048 case MANFID_MOTOROLA:
1049 default: /* get the hw address from EEPROM */
1050 i = mot_setup(link); break;
1054 printk(KERN_NOTICE "smc91c92_cs: Unable to find hardware address.\n");
1061 rev = check_sig(link);
1065 case 3: name = "92"; break;
1066 case 4: name = ((rev & 15) >= 6) ? "96" : "94"; break;
1067 case 5: name = "95"; break;
1068 case 7: name = "100"; break;
1069 case 8: name = "100-FD"; break;
1070 case 9: name = "110"; break;
1073 ioaddr = dev->base_addr;
1077 mir = inw(ioaddr + MEMINFO) & 0xff;
1078 if (mir == 0xff) mir++;
1079 /* Get scale factor for memory size */
1080 mcr = ((rev >> 4) > 3) ? inw(ioaddr + MEMCFG) : 0x0200;
1081 mir *= 128 * (1<<((mcr >> 9) & 7));
1083 smc->cfg = inw(ioaddr + CONFIG) & ~CFG_AUI_SELECT;
1084 smc->cfg |= CFG_NO_WAIT | CFG_16BIT | CFG_STATIC;
1085 if (smc->manfid == MANFID_OSITECH)
1086 smc->cfg |= CFG_IRQ_SEL_1 | CFG_IRQ_SEL_0;
1087 if ((rev >> 4) >= 7)
1088 smc->cfg |= CFG_MII_SELECT;
1092 if (smc->cfg & CFG_MII_SELECT) {
1095 for (i = 0; i < 32; i++) {
1096 j = mdio_read(dev, i, 1);
1097 if ((j != 0) && (j != 0xffff)) break;
1099 smc->mii_if.phy_id = (i < 32) ? i : -1;
1104 link->dev = &smc->node;
1105 link->state &= ~DEV_CONFIG_PENDING;
1106 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
1108 if (register_netdev(dev) != 0) {
1109 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n");
1114 strcpy(smc->node.dev_name, dev->name);
1116 printk(KERN_INFO "%s: smc91c%s rev %d: io %#3lx, irq %d, "
1117 "hw_addr ", dev->name, name, (rev & 0x0f), dev->base_addr,
1119 for (i = 0; i < 6; i++)
1120 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
1124 printk(KERN_INFO " %lu byte", mir);
1126 printk(KERN_INFO " %lu kb", mir>>10);
1127 printk(" buffer, %s xcvr\n", (smc->cfg & CFG_MII_SELECT) ?
1128 "MII" : if_names[dev->if_port]);
1131 if (smc->cfg & CFG_MII_SELECT) {
1132 if (smc->mii_if.phy_id != -1) {
1133 DEBUG(0, " MII transceiver at index %d, status %x.\n",
1134 smc->mii_if.phy_id, j);
1136 printk(KERN_NOTICE " No MII transceivers found!\n");
1143 unregister_netdev(dev);
1144 config_failed: /* CS_EXIT_TEST() calls jump to here... */
1145 smc91c92_release(link);
1146 link->state &= ~DEV_CONFIG_PENDING;
1149 } /* smc91c92_config */
1151 /*======================================================================
1153 After a card is removed, smc91c92_release() will unregister the net
1154 device, and release the PCMCIA configuration. If the device is
1155 still open, this will be postponed until it is closed.
1157 ======================================================================*/
1159 static void smc91c92_release(dev_link_t *link)
1162 DEBUG(0, "smc91c92_release(0x%p)\n", link);
1164 pcmcia_release_configuration(link->handle);
1165 pcmcia_release_io(link->handle, &link->io);
1166 pcmcia_release_irq(link->handle, &link->irq);
1168 struct net_device *dev = link->priv;
1169 struct smc_private *smc = netdev_priv(dev);
1171 pcmcia_release_window(link->win);
1174 link->state &= ~DEV_CONFIG;
1177 /*======================================================================
1179 The card status event handler. Mostly, this schedules other
1180 stuff to run after an event is received. A CARD_REMOVAL event
1181 also sets some flags to discourage the net drivers from trying
1182 to talk to the card any more.
1184 ======================================================================*/
1186 static int smc91c92_event(event_t event, int priority,
1187 event_callback_args_t *args)
1189 dev_link_t *link = args->client_data;
1190 struct net_device *dev = link->priv;
1191 struct smc_private *smc = netdev_priv(dev);
1194 DEBUG(1, "smc91c92_event(0x%06x)\n", event);
1197 case CS_EVENT_CARD_REMOVAL:
1198 link->state &= ~DEV_PRESENT;
1199 if (link->state & DEV_CONFIG)
1200 netif_device_detach(dev);
1202 case CS_EVENT_CARD_INSERTION:
1203 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1204 smc91c92_config(link);
1206 case CS_EVENT_PM_SUSPEND:
1207 link->state |= DEV_SUSPEND;
1208 /* Fall through... */
1209 case CS_EVENT_RESET_PHYSICAL:
1210 if (link->state & DEV_CONFIG) {
1212 netif_device_detach(dev);
1213 pcmcia_release_configuration(link->handle);
1216 case CS_EVENT_PM_RESUME:
1217 link->state &= ~DEV_SUSPEND;
1218 /* Fall through... */
1219 case CS_EVENT_CARD_RESET:
1220 if (link->state & DEV_CONFIG) {
1221 if ((smc->manfid == MANFID_MEGAHERTZ) &&
1222 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
1223 mhz_3288_power(link);
1224 pcmcia_request_configuration(link->handle, &link->conf);
1225 if (smc->manfid == MANFID_MOTOROLA)
1227 if ((smc->manfid == MANFID_OSITECH) &&
1228 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1229 /* Power up the card and enable interrupts */
1230 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR);
1231 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR);
1233 if (((smc->manfid == MANFID_OSITECH) &&
1234 (smc->cardid == PRODID_OSITECH_SEVEN)) ||
1235 ((smc->manfid == MANFID_PSION) &&
1236 (smc->cardid == PRODID_PSION_NET100))) {
1237 /* Download the Seven of Diamonds firmware */
1238 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
1239 outb(__Xilinx7OD[i], link->io.BasePort1+2);
1245 netif_device_attach(dev);
1251 } /* smc91c92_event */
1253 /*======================================================================
1255 MII interface support for SMC91cXX based cards
1256 ======================================================================*/
1258 #define MDIO_SHIFT_CLK 0x04
1259 #define MDIO_DATA_OUT 0x01
1260 #define MDIO_DIR_WRITE 0x08
1261 #define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
1262 #define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
1263 #define MDIO_DATA_READ 0x02
1265 static void mdio_sync(kio_addr_t addr)
1268 for (bits = 0; bits < 32; bits++) {
1269 outb(MDIO_DATA_WRITE1, addr);
1270 outb(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
1274 static int mdio_read(struct net_device *dev, int phy_id, int loc)
1276 kio_addr_t addr = dev->base_addr + MGMT;
1277 u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
1281 for (i = 13; i >= 0; i--) {
1282 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1284 outb(dat | MDIO_SHIFT_CLK, addr);
1286 for (i = 19; i > 0; i--) {
1288 retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
1289 outb(MDIO_SHIFT_CLK, addr);
1291 return (retval>>1) & 0xffff;
1294 static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
1296 kio_addr_t addr = dev->base_addr + MGMT;
1297 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
1301 for (i = 31; i >= 0; i--) {
1302 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1304 outb(dat | MDIO_SHIFT_CLK, addr);
1306 for (i = 1; i >= 0; i--) {
1308 outb(MDIO_SHIFT_CLK, addr);
1312 /*======================================================================
1314 The driver core code, most of which should be common with a
1315 non-PCMCIA implementation.
1317 ======================================================================*/
1320 static void smc_dump(struct net_device *dev)
1322 kio_addr_t ioaddr = dev->base_addr;
1324 save = inw(ioaddr + BANK_SELECT);
1325 for (w = 0; w < 4; w++) {
1327 printk(KERN_DEBUG "bank %d: ", w);
1328 for (i = 0; i < 14; i += 2)
1329 printk(" %04x", inw(ioaddr + i));
1332 outw(save, ioaddr + BANK_SELECT);
1336 static int smc_open(struct net_device *dev)
1338 struct smc_private *smc = netdev_priv(dev);
1339 dev_link_t *link = &smc->link;
1342 DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n",
1343 dev->name, dev, inw(dev->base_addr + BANK_SELECT));
1344 if (pc_debug > 1) smc_dump(dev);
1347 /* Check that the PCMCIA card is still here. */
1350 /* Physical device present signature. */
1351 if (check_sig(link) < 0) {
1352 printk("smc91c92_cs: Yikes! Bad chip signature!\n");
1357 netif_start_queue(dev);
1358 smc->saved_skb = NULL;
1359 smc->packets_waiting = 0;
1362 init_timer(&smc->media);
1363 smc->media.function = &media_check;
1364 smc->media.data = (u_long) dev;
1365 smc->media.expires = jiffies + HZ;
1366 add_timer(&smc->media);
1371 /*====================================================================*/
1373 static int smc_close(struct net_device *dev)
1375 struct smc_private *smc = netdev_priv(dev);
1376 dev_link_t *link = &smc->link;
1377 kio_addr_t ioaddr = dev->base_addr;
1379 DEBUG(0, "%s: smc_close(), status %4.4x.\n",
1380 dev->name, inw(ioaddr + BANK_SELECT));
1382 netif_stop_queue(dev);
1384 /* Shut off all interrupts, and turn off the Tx and Rx sections.
1385 Don't bother to check for chip present. */
1386 SMC_SELECT_BANK(2); /* Nominally paranoia, but do no assume... */
1387 outw(0, ioaddr + INTERRUPT);
1389 mask_bits(0xff00, ioaddr + RCR);
1390 mask_bits(0xff00, ioaddr + TCR);
1392 /* Put the chip into power-down mode. */
1394 outw(CTL_POWERDOWN, ioaddr + CONTROL );
1397 del_timer_sync(&smc->media);
1402 /*======================================================================
1404 Transfer a packet to the hardware and trigger the packet send.
1405 This may be called at either from either the Tx queue code
1406 or the interrupt handler.
1408 ======================================================================*/
1410 static void smc_hardware_send_packet(struct net_device * dev)
1412 struct smc_private *smc = netdev_priv(dev);
1413 struct sk_buff *skb = smc->saved_skb;
1414 kio_addr_t ioaddr = dev->base_addr;
1418 printk(KERN_ERR "%s: In XMIT with no packet to send.\n", dev->name);
1422 /* There should be a packet slot waiting. */
1423 packet_no = inw(ioaddr + PNR_ARR) >> 8;
1424 if (packet_no & 0x80) {
1425 /* If not, there is a hardware problem! Likely an ejected card. */
1426 printk(KERN_WARNING "%s: 91c92 hardware Tx buffer allocation"
1427 " failed, status %#2.2x.\n", dev->name, packet_no);
1428 dev_kfree_skb_irq(skb);
1429 smc->saved_skb = NULL;
1430 netif_start_queue(dev);
1434 smc->stats.tx_bytes += skb->len;
1435 /* The card should use the just-allocated buffer. */
1436 outw(packet_no, ioaddr + PNR_ARR);
1437 /* point to the beginning of the packet */
1438 outw(PTR_AUTOINC , ioaddr + POINTER);
1440 /* Send the packet length (+6 for status, length and ctl byte)
1441 and the status word (set to zeros). */
1443 u_char *buf = skb->data;
1444 u_int length = skb->len; /* The chip will pad to ethernet min. */
1446 DEBUG(2, "%s: Trying to xmit packet of length %d.\n",
1449 /* send the packet length: +6 for status word, length, and ctl */
1450 outw(0, ioaddr + DATA_1);
1451 outw(length + 6, ioaddr + DATA_1);
1452 outsw(ioaddr + DATA_1, buf, length >> 1);
1454 /* The odd last byte, if there is one, goes in the control word. */
1455 outw((length & 1) ? 0x2000 | buf[length-1] : 0, ioaddr + DATA_1);
1458 /* Enable the Tx interrupts, both Tx (TxErr) and TxEmpty. */
1459 outw(((IM_TX_INT|IM_TX_EMPTY_INT)<<8) |
1460 (inw(ioaddr + INTERRUPT) & 0xff00),
1461 ioaddr + INTERRUPT);
1463 /* The chip does the rest of the work. */
1464 outw(MC_ENQUEUE , ioaddr + MMU_CMD);
1466 smc->saved_skb = NULL;
1467 dev_kfree_skb_irq(skb);
1468 dev->trans_start = jiffies;
1469 netif_start_queue(dev);
1473 /*====================================================================*/
1475 static void smc_tx_timeout(struct net_device *dev)
1477 struct smc_private *smc = netdev_priv(dev);
1478 kio_addr_t ioaddr = dev->base_addr;
1480 printk(KERN_NOTICE "%s: SMC91c92 transmit timed out, "
1481 "Tx_status %2.2x status %4.4x.\n",
1482 dev->name, inw(ioaddr)&0xff, inw(ioaddr + 2));
1483 smc->stats.tx_errors++;
1485 dev->trans_start = jiffies;
1486 smc->saved_skb = NULL;
1487 netif_wake_queue(dev);
1490 static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev)
1492 struct smc_private *smc = netdev_priv(dev);
1493 kio_addr_t ioaddr = dev->base_addr;
1497 netif_stop_queue(dev);
1499 DEBUG(2, "%s: smc_start_xmit(length = %d) called,"
1500 " status %4.4x.\n", dev->name, skb->len, inw(ioaddr + 2));
1502 if (smc->saved_skb) {
1503 /* THIS SHOULD NEVER HAPPEN. */
1504 smc->stats.tx_aborted_errors++;
1505 printk(KERN_DEBUG "%s: Internal error -- sent packet while busy.\n",
1509 smc->saved_skb = skb;
1511 num_pages = skb->len >> 8;
1513 if (num_pages > 7) {
1514 printk(KERN_ERR "%s: Far too big packet error.\n", dev->name);
1515 dev_kfree_skb (skb);
1516 smc->saved_skb = NULL;
1517 smc->stats.tx_dropped++;
1518 return 0; /* Do not re-queue this packet. */
1520 /* A packet is now waiting. */
1521 smc->packets_waiting++;
1523 SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */
1525 /* need MC_RESET to keep the memory consistent. errata? */
1527 outw(MC_RESET, ioaddr + MMU_CMD);
1531 /* Allocate the memory; send the packet now if we win. */
1532 outw(MC_ALLOC | num_pages, ioaddr + MMU_CMD);
1533 for (time_out = MEMORY_WAIT_TIME; time_out >= 0; time_out--) {
1534 ir = inw(ioaddr+INTERRUPT);
1535 if (ir & IM_ALLOC_INT) {
1536 /* Acknowledge the interrupt, send the packet. */
1537 outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT);
1538 smc_hardware_send_packet(dev); /* Send the packet now.. */
1543 /* Otherwise defer until the Tx-space-allocated interrupt. */
1544 DEBUG(2, "%s: memory allocation deferred.\n", dev->name);
1545 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT);
1550 /*======================================================================
1552 Handle a Tx anomolous event. Entered while in Window 2.
1554 ======================================================================*/
1556 static void smc_tx_err(struct net_device * dev)
1558 struct smc_private *smc = netdev_priv(dev);
1559 kio_addr_t ioaddr = dev->base_addr;
1560 int saved_packet = inw(ioaddr + PNR_ARR) & 0xff;
1561 int packet_no = inw(ioaddr + FIFO_PORTS) & 0x7f;
1564 /* select this as the packet to read from */
1565 outw(packet_no, ioaddr + PNR_ARR);
1567 /* read the first word from this packet */
1568 outw(PTR_AUTOINC | PTR_READ | 0, ioaddr + POINTER);
1570 tx_status = inw(ioaddr + DATA_1);
1572 smc->stats.tx_errors++;
1573 if (tx_status & TS_LOSTCAR) smc->stats.tx_carrier_errors++;
1574 if (tx_status & TS_LATCOL) smc->stats.tx_window_errors++;
1575 if (tx_status & TS_16COL) {
1576 smc->stats.tx_aborted_errors++;
1580 if (tx_status & TS_SUCCESS) {
1581 printk(KERN_NOTICE "%s: Successful packet caused error "
1582 "interrupt?\n", dev->name);
1584 /* re-enable transmit */
1586 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1589 outw(MC_FREEPKT, ioaddr + MMU_CMD); /* Free the packet memory. */
1591 /* one less packet waiting for me */
1592 smc->packets_waiting--;
1594 outw(saved_packet, ioaddr + PNR_ARR);
1598 /*====================================================================*/
1600 static void smc_eph_irq(struct net_device *dev)
1602 struct smc_private *smc = netdev_priv(dev);
1603 kio_addr_t ioaddr = dev->base_addr;
1604 u_short card_stats, ephs;
1607 ephs = inw(ioaddr + EPH);
1608 DEBUG(2, "%s: Ethernet protocol handler interrupt, status"
1609 " %4.4x.\n", dev->name, ephs);
1610 /* Could be a counter roll-over warning: update stats. */
1611 card_stats = inw(ioaddr + COUNTER);
1612 /* single collisions */
1613 smc->stats.collisions += card_stats & 0xF;
1615 /* multiple collisions */
1616 smc->stats.collisions += card_stats & 0xF;
1617 #if 0 /* These are for when linux supports these statistics */
1618 card_stats >>= 4; /* deferred */
1619 card_stats >>= 4; /* excess deferred */
1621 /* If we had a transmit error we must re-enable the transmitter. */
1622 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1624 /* Clear a link error interrupt. */
1626 outw(CTL_AUTO_RELEASE | 0x0000, ioaddr + CONTROL);
1627 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1632 /*====================================================================*/
1634 static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1636 struct net_device *dev = dev_id;
1637 struct smc_private *smc = netdev_priv(dev);
1639 u_short saved_bank, saved_pointer, mask, status;
1640 unsigned int handled = 1;
1641 char bogus_cnt = INTR_WORK; /* Work we are willing to do. */
1643 if (!netif_device_present(dev))
1646 ioaddr = dev->base_addr;
1648 DEBUG(3, "%s: SMC91c92 interrupt %d at %#x.\n", dev->name,
1652 saved_bank = inw(ioaddr + BANK_SELECT);
1653 if ((saved_bank & 0xff00) != 0x3300) {
1654 /* The device does not exist -- the card could be off-line, or
1655 maybe it has been ejected. */
1656 DEBUG(1, "%s: SMC91c92 interrupt %d for non-existent"
1657 "/ejected device.\n", dev->name, irq);
1663 saved_pointer = inw(ioaddr + POINTER);
1664 mask = inw(ioaddr + INTERRUPT) >> 8;
1665 /* clear all interrupts */
1666 outw(0, ioaddr + INTERRUPT);
1668 do { /* read the status flag, and mask it */
1669 status = inw(ioaddr + INTERRUPT) & 0xff;
1670 DEBUG(3, "%s: Status is %#2.2x (mask %#2.2x).\n", dev->name,
1672 if ((status & mask) == 0) {
1673 if (bogus_cnt == INTR_WORK)
1677 if (status & IM_RCV_INT) {
1678 /* Got a packet(s). */
1681 if (status & IM_TX_INT) {
1683 outw(IM_TX_INT, ioaddr + INTERRUPT);
1686 if (status & IM_TX_EMPTY_INT) {
1687 outw(IM_TX_EMPTY_INT, ioaddr + INTERRUPT);
1688 mask &= ~IM_TX_EMPTY_INT;
1689 smc->stats.tx_packets += smc->packets_waiting;
1690 smc->packets_waiting = 0;
1692 if (status & IM_ALLOC_INT) {
1693 /* Clear this interrupt so it doesn't happen again */
1694 mask &= ~IM_ALLOC_INT;
1696 smc_hardware_send_packet(dev);
1698 /* enable xmit interrupts based on this */
1699 mask |= (IM_TX_EMPTY_INT | IM_TX_INT);
1701 /* and let the card send more packets to me */
1702 netif_wake_queue(dev);
1704 if (status & IM_RX_OVRN_INT) {
1705 smc->stats.rx_errors++;
1706 smc->stats.rx_fifo_errors++;
1708 smc->rx_ovrn = 1; /* need MC_RESET outside smc_interrupt */
1709 outw(IM_RX_OVRN_INT, ioaddr + INTERRUPT);
1711 if (status & IM_EPH_INT)
1713 } while (--bogus_cnt);
1715 DEBUG(3, " Restoring saved registers mask %2.2x bank %4.4x"
1716 " pointer %4.4x.\n", mask, saved_bank, saved_pointer);
1718 /* restore state register */
1719 outw((mask<<8), ioaddr + INTERRUPT);
1720 outw(saved_pointer, ioaddr + POINTER);
1721 SMC_SELECT_BANK(saved_bank);
1723 DEBUG(3, "%s: Exiting interrupt IRQ%d.\n", dev->name, irq);
1727 if ((smc->manfid == MANFID_OSITECH) &&
1728 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1729 /* Retrigger interrupt if needed */
1730 mask_bits(0x00ff, ioaddr-0x10+OSITECH_RESET_ISR);
1731 set_bits(0x0300, ioaddr-0x10+OSITECH_RESET_ISR);
1733 if (smc->manfid == MANFID_MOTOROLA) {
1735 cor = readb(smc->base + MOT_UART + CISREG_COR);
1736 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_UART + CISREG_COR);
1737 writeb(cor, smc->base + MOT_UART + CISREG_COR);
1738 cor = readb(smc->base + MOT_LAN + CISREG_COR);
1739 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_LAN + CISREG_COR);
1740 writeb(cor, smc->base + MOT_LAN + CISREG_COR);
1742 #ifdef DOES_NOT_WORK
1743 if (smc->base != NULL) { /* Megahertz MFC's */
1744 readb(smc->base+MEGAHERTZ_ISR);
1745 readb(smc->base+MEGAHERTZ_ISR);
1748 return IRQ_RETVAL(handled);
1751 /*====================================================================*/
1753 static void smc_rx(struct net_device *dev)
1755 struct smc_private *smc = netdev_priv(dev);
1756 kio_addr_t ioaddr = dev->base_addr;
1758 int packet_length; /* Caution: not frame length, rather words
1759 to transfer from the chip. */
1761 /* Assertion: we are in Window 2. */
1763 if (inw(ioaddr + FIFO_PORTS) & FP_RXEMPTY) {
1764 printk(KERN_ERR "%s: smc_rx() with nothing on Rx FIFO.\n",
1769 /* Reset the read pointer, and read the status and packet length. */
1770 outw(PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER);
1771 rx_status = inw(ioaddr + DATA_1);
1772 packet_length = inw(ioaddr + DATA_1) & 0x07ff;
1774 DEBUG(2, "%s: Receive status %4.4x length %d.\n",
1775 dev->name, rx_status, packet_length);
1777 if (!(rx_status & RS_ERRORS)) {
1778 /* do stuff to make a new packet */
1779 struct sk_buff *skb;
1781 /* Note: packet_length adds 5 or 6 extra bytes here! */
1782 skb = dev_alloc_skb(packet_length+2);
1785 DEBUG(1, "%s: Low memory, packet dropped.\n", dev->name);
1786 smc->stats.rx_dropped++;
1787 outw(MC_RELEASE, ioaddr + MMU_CMD);
1791 packet_length -= (rx_status & RS_ODDFRAME ? 5 : 6);
1792 skb_reserve(skb, 2);
1793 insw(ioaddr+DATA_1, skb_put(skb, packet_length),
1794 (packet_length+1)>>1);
1795 skb->protocol = eth_type_trans(skb, dev);
1799 dev->last_rx = jiffies;
1800 smc->stats.rx_packets++;
1801 smc->stats.rx_bytes += packet_length;
1802 if (rx_status & RS_MULTICAST)
1803 smc->stats.multicast++;
1806 smc->stats.rx_errors++;
1808 if (rx_status & RS_ALGNERR) smc->stats.rx_frame_errors++;
1809 if (rx_status & (RS_TOOSHORT | RS_TOOLONG))
1810 smc->stats.rx_length_errors++;
1811 if (rx_status & RS_BADCRC) smc->stats.rx_crc_errors++;
1813 /* Let the MMU free the memory of this packet. */
1814 outw(MC_RELEASE, ioaddr + MMU_CMD);
1819 /*====================================================================*/
1821 static struct net_device_stats *smc_get_stats(struct net_device *dev)
1823 struct smc_private *smc = netdev_priv(dev);
1824 /* Nothing to update - the 91c92 is a pretty primative chip. */
1828 /*======================================================================
1830 Calculate values for the hardware multicast filter hash table.
1832 ======================================================================*/
1834 static void fill_multicast_tbl(int count, struct dev_mc_list *addrs,
1835 u_char *multicast_table)
1837 struct dev_mc_list *mc_addr;
1839 for (mc_addr = addrs; mc_addr && --count > 0; mc_addr = mc_addr->next) {
1840 u_int position = ether_crc(6, mc_addr->dmi_addr);
1841 #ifndef final_version /* Verify multicast address. */
1842 if ((mc_addr->dmi_addr[0] & 1) == 0)
1845 multicast_table[position >> 29] |= 1 << ((position >> 26) & 7);
1849 /*======================================================================
1851 Set the receive mode.
1853 This routine is used by both the protocol level to notify us of
1854 promiscuous/multicast mode changes, and by the open/reset code to
1855 initialize the Rx registers. We always set the multicast list and
1856 leave the receiver running.
1858 ======================================================================*/
1860 static void set_rx_mode(struct net_device *dev)
1862 kio_addr_t ioaddr = dev->base_addr;
1863 struct smc_private *smc = netdev_priv(dev);
1864 u_int multicast_table[ 2 ] = { 0, };
1865 unsigned long flags;
1866 u_short rx_cfg_setting;
1868 if (dev->flags & IFF_PROMISC) {
1869 printk(KERN_NOTICE "%s: setting Rx mode to promiscuous.\n", dev->name);
1870 rx_cfg_setting = RxStripCRC | RxEnable | RxPromisc | RxAllMulti;
1871 } else if (dev->flags & IFF_ALLMULTI)
1872 rx_cfg_setting = RxStripCRC | RxEnable | RxAllMulti;
1874 if (dev->mc_count) {
1875 fill_multicast_tbl(dev->mc_count, dev->mc_list,
1876 (u_char *)multicast_table);
1878 rx_cfg_setting = RxStripCRC | RxEnable;
1881 /* Load MC table and Rx setting into the chip without interrupts. */
1882 spin_lock_irqsave(&smc->lock, flags);
1884 outl(multicast_table[0], ioaddr + MULTICAST0);
1885 outl(multicast_table[1], ioaddr + MULTICAST4);
1887 outw(rx_cfg_setting, ioaddr + RCR);
1889 spin_unlock_irqrestore(&smc->lock, flags);
1894 /*======================================================================
1896 Senses when a card's config changes. Here, it's coax or TP.
1898 ======================================================================*/
1900 static int s9k_config(struct net_device *dev, struct ifmap *map)
1902 struct smc_private *smc = netdev_priv(dev);
1903 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
1904 if (smc->cfg & CFG_MII_SELECT)
1906 else if (map->port > 2)
1908 dev->if_port = map->port;
1909 printk(KERN_INFO "%s: switched to %s port\n",
1910 dev->name, if_names[dev->if_port]);
1916 /*======================================================================
1918 Reset the chip, reloading every register that might be corrupted.
1920 ======================================================================*/
1923 Set transceiver type, perhaps to something other than what the user
1924 specified in dev->if_port.
1926 static void smc_set_xcvr(struct net_device *dev, int if_port)
1928 struct smc_private *smc = netdev_priv(dev);
1929 kio_addr_t ioaddr = dev->base_addr;
1932 saved_bank = inw(ioaddr + BANK_SELECT);
1935 outw(smc->cfg | CFG_AUI_SELECT, ioaddr + CONFIG);
1936 if ((smc->manfid == MANFID_OSITECH) &&
1937 (smc->cardid != PRODID_OSITECH_SEVEN))
1938 set_bits(OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1939 smc->media_status = ((dev->if_port == 0) ? 0x0001 : 0x0002);
1941 outw(smc->cfg, ioaddr + CONFIG);
1942 if ((smc->manfid == MANFID_OSITECH) &&
1943 (smc->cardid != PRODID_OSITECH_SEVEN))
1944 mask_bits(~OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1945 smc->media_status = ((dev->if_port == 0) ? 0x0012 : 0x4001);
1947 SMC_SELECT_BANK(saved_bank);
1950 static void smc_reset(struct net_device *dev)
1952 kio_addr_t ioaddr = dev->base_addr;
1953 struct smc_private *smc = netdev_priv(dev);
1956 DEBUG(0, "%s: smc91c92 reset called.\n", dev->name);
1958 /* The first interaction must be a write to bring the chip out
1961 /* Reset the chip. */
1962 outw(RCR_SOFTRESET, ioaddr + RCR);
1965 /* Clear the transmit and receive configuration registers. */
1966 outw(RCR_CLEAR, ioaddr + RCR);
1967 outw(TCR_CLEAR, ioaddr + TCR);
1969 /* Set the Window 1 control, configuration and station addr registers.
1970 No point in writing the I/O base register ;-> */
1972 /* Automatically release succesfully transmitted packets,
1973 Accept link errors, counter and Tx error interrupts. */
1974 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1976 smc_set_xcvr(dev, dev->if_port);
1977 if ((smc->manfid == MANFID_OSITECH) &&
1978 (smc->cardid != PRODID_OSITECH_SEVEN))
1979 outw((dev->if_port == 2 ? OSI_AUI_PWR : 0) |
1980 (inw(ioaddr-0x10+OSITECH_AUI_PWR) & 0xff00),
1981 ioaddr - 0x10 + OSITECH_AUI_PWR);
1983 /* Fill in the physical address. The databook is wrong about the order! */
1984 for (i = 0; i < 6; i += 2)
1985 outw((dev->dev_addr[i+1]<<8)+dev->dev_addr[i],
1986 ioaddr + ADDR0 + i);
1990 outw(MC_RESET, ioaddr + MMU_CMD);
1991 outw(0, ioaddr + INTERRUPT);
1993 /* Re-enable the chip. */
1995 outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) |
1996 TCR_ENABLE | TCR_PAD_EN | smc->duplex, ioaddr + TCR);
1999 if (smc->cfg & CFG_MII_SELECT) {
2003 mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000);
2005 /* Advertise 100F, 100H, 10F, 10H */
2006 mdio_write(dev, smc->mii_if.phy_id, 4, 0x01e1);
2008 /* Restart MII autonegotiation */
2009 mdio_write(dev, smc->mii_if.phy_id, 0, 0x0000);
2010 mdio_write(dev, smc->mii_if.phy_id, 0, 0x1200);
2013 /* Enable interrupts. */
2015 outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,
2016 ioaddr + INTERRUPT);
2019 /*======================================================================
2021 Media selection timer routine
2023 ======================================================================*/
2025 static void media_check(u_long arg)
2027 struct net_device *dev = (struct net_device *) arg;
2028 struct smc_private *smc = netdev_priv(dev);
2029 kio_addr_t ioaddr = dev->base_addr;
2030 u_short i, media, saved_bank;
2033 saved_bank = inw(ioaddr + BANK_SELECT);
2035 if (!netif_device_present(dev))
2040 /* need MC_RESET to keep the memory consistent. errata? */
2042 outw(MC_RESET, ioaddr + MMU_CMD);
2045 i = inw(ioaddr + INTERRUPT);
2047 media = inw(ioaddr + EPH) & EPH_LINK_OK;
2049 media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1;
2051 /* Check for pending interrupt with watchdog flag set: with
2052 this, we can limp along even if the interrupt is blocked */
2053 if (smc->watchdog++ && ((i>>8) & i)) {
2054 if (!smc->fast_poll)
2055 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
2056 smc_interrupt(dev->irq, smc, NULL);
2057 smc->fast_poll = HZ;
2059 if (smc->fast_poll) {
2061 smc->media.expires = jiffies + HZ/100;
2062 add_timer(&smc->media);
2063 SMC_SELECT_BANK(saved_bank);
2067 if (smc->cfg & CFG_MII_SELECT) {
2068 if (smc->mii_if.phy_id < 0)
2072 link = mdio_read(dev, smc->mii_if.phy_id, 1);
2073 if (!link || (link == 0xffff)) {
2074 printk(KERN_INFO "%s: MII is missing!\n", dev->name);
2075 smc->mii_if.phy_id = -1;
2080 if (link != smc->link_status) {
2081 u_short p = mdio_read(dev, smc->mii_if.phy_id, 5);
2082 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2083 (link) ? "found" : "lost");
2084 smc->duplex = (((p & 0x0100) || ((p & 0x1c0) == 0x40))
2087 printk(KERN_INFO "%s: autonegotiation complete: "
2088 "%sbaseT-%cD selected\n", dev->name,
2089 ((p & 0x0180) ? "100" : "10"),
2090 (smc->duplex ? 'F' : 'H'));
2093 outw(inw(ioaddr + TCR) | smc->duplex, ioaddr + TCR);
2094 smc->link_status = link;
2099 /* Ignore collisions unless we've had no rx's recently */
2100 if (jiffies - dev->last_rx > HZ) {
2101 if (smc->tx_err || (smc->media_status & EPH_16COL))
2106 if (media != smc->media_status) {
2107 if ((media & smc->media_status & 1) &&
2108 ((smc->media_status ^ media) & EPH_LINK_OK))
2109 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2110 (smc->media_status & EPH_LINK_OK ? "lost" : "found"));
2111 else if ((media & smc->media_status & 2) &&
2112 ((smc->media_status ^ media) & EPH_16COL))
2113 printk(KERN_INFO "%s: coax cable %s\n", dev->name,
2114 (media & EPH_16COL ? "problem" : "ok"));
2115 if (dev->if_port == 0) {
2117 if (media & EPH_LINK_OK)
2118 printk(KERN_INFO "%s: flipped to 10baseT\n",
2121 smc_set_xcvr(dev, 2);
2123 if (media & EPH_16COL)
2124 smc_set_xcvr(dev, 1);
2126 printk(KERN_INFO "%s: flipped to 10base2\n",
2130 smc->media_status = media;
2134 smc->media.expires = jiffies + HZ;
2135 add_timer(&smc->media);
2136 SMC_SELECT_BANK(saved_bank);
2139 static int smc_link_ok(struct net_device *dev)
2141 kio_addr_t ioaddr = dev->base_addr;
2142 struct smc_private *smc = netdev_priv(dev);
2144 if (smc->cfg & CFG_MII_SELECT) {
2145 return mii_link_ok(&smc->mii_if);
2148 return inw(ioaddr + EPH) & EPH_LINK_OK;
2152 static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2155 kio_addr_t ioaddr = dev->base_addr;
2157 ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |
2158 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);
2161 tmp = inw(ioaddr + CONFIG);
2162 ecmd->port = (tmp & CFG_AUI_SELECT) ? PORT_AUI : PORT_TP;
2163 ecmd->transceiver = XCVR_INTERNAL;
2164 ecmd->speed = SPEED_10;
2165 ecmd->phy_address = ioaddr + MGMT;
2168 tmp = inw(ioaddr + TCR);
2169 ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF;
2174 static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2177 kio_addr_t ioaddr = dev->base_addr;
2179 if (ecmd->speed != SPEED_10)
2181 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
2183 if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI)
2185 if (ecmd->transceiver != XCVR_INTERNAL)
2188 if (ecmd->port == PORT_AUI)
2189 smc_set_xcvr(dev, 1);
2191 smc_set_xcvr(dev, 0);
2194 tmp = inw(ioaddr + TCR);
2195 if (ecmd->duplex == DUPLEX_FULL)
2199 outw(tmp, ioaddr + TCR);
2204 static int check_if_running(struct net_device *dev)
2206 if (!netif_running(dev))
2211 static void smc_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2213 strcpy(info->driver, DRV_NAME);
2214 strcpy(info->version, DRV_VERSION);
2217 static int smc_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2219 struct smc_private *smc = netdev_priv(dev);
2220 kio_addr_t ioaddr = dev->base_addr;
2221 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2225 spin_lock_irq(&smc->lock);
2226 if (smc->cfg & CFG_MII_SELECT)
2227 ret = mii_ethtool_gset(&smc->mii_if, ecmd);
2229 ret = smc_netdev_get_ecmd(dev, ecmd);
2230 spin_unlock_irq(&smc->lock);
2231 SMC_SELECT_BANK(saved_bank);
2235 static int smc_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2237 struct smc_private *smc = netdev_priv(dev);
2238 kio_addr_t ioaddr = dev->base_addr;
2239 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2243 spin_lock_irq(&smc->lock);
2244 if (smc->cfg & CFG_MII_SELECT)
2245 ret = mii_ethtool_sset(&smc->mii_if, ecmd);
2247 ret = smc_netdev_set_ecmd(dev, ecmd);
2248 spin_unlock_irq(&smc->lock);
2249 SMC_SELECT_BANK(saved_bank);
2253 static u32 smc_get_link(struct net_device *dev)
2255 struct smc_private *smc = netdev_priv(dev);
2256 kio_addr_t ioaddr = dev->base_addr;
2257 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2261 spin_lock_irq(&smc->lock);
2262 ret = smc_link_ok(dev);
2263 spin_unlock_irq(&smc->lock);
2264 SMC_SELECT_BANK(saved_bank);
2269 static u32 smc_get_msglevel(struct net_device *dev)
2274 static void smc_set_msglevel(struct net_device *dev, u32 val)
2280 static int smc_nway_reset(struct net_device *dev)
2282 struct smc_private *smc = netdev_priv(dev);
2283 if (smc->cfg & CFG_MII_SELECT) {
2284 kio_addr_t ioaddr = dev->base_addr;
2285 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2289 res = mii_nway_restart(&smc->mii_if);
2290 SMC_SELECT_BANK(saved_bank);
2297 static struct ethtool_ops ethtool_ops = {
2298 .begin = check_if_running,
2299 .get_drvinfo = smc_get_drvinfo,
2300 .get_settings = smc_get_settings,
2301 .set_settings = smc_set_settings,
2302 .get_link = smc_get_link,
2304 .get_msglevel = smc_get_msglevel,
2305 .set_msglevel = smc_set_msglevel,
2307 .nway_reset = smc_nway_reset,
2310 static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
2312 struct smc_private *smc = netdev_priv(dev);
2313 struct mii_ioctl_data *mii = if_mii(rq);
2316 kio_addr_t ioaddr = dev->base_addr;
2318 if (!netif_running(dev))
2321 spin_lock_irq(&smc->lock);
2322 saved_bank = inw(ioaddr + BANK_SELECT);
2324 rc = generic_mii_ioctl(&smc->mii_if, mii, cmd, NULL);
2325 SMC_SELECT_BANK(saved_bank);
2326 spin_unlock_irq(&smc->lock);
2330 static struct pcmcia_device_id smc91c92_ids[] = {
2331 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0109, 0x0501),
2332 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0140, 0x000a),
2333 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63),
2334 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63),
2335 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef),
2336 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
2337 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
2338 PCMCIA_PFC_DEVICE_PROD_ID12(0, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
2339 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2340 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2341 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x016c, 0x0020),
2342 PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0023),
2343 PCMCIA_DEVICE_PROD_ID123("BASICS by New Media Corporation", "Ethernet", "SMC91C94", 0x23c78a9d, 0x00b2e941, 0xcef397fb),
2344 PCMCIA_DEVICE_PROD_ID12("ARGOSY", "Fast Ethernet PCCard", 0x78f308dc, 0xdcea68bc),
2345 PCMCIA_DEVICE_PROD_ID12("dit Co., Ltd.", "PC Card-10/100BTX", 0xe59365c8, 0x6a2161d1),
2346 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L100C", 0x6a26d1cf, 0xc16ce9c5),
2347 PCMCIA_DEVICE_PROD_ID12("Farallon", "Farallon Enet", 0x58d93fc4, 0x244734e9),
2348 PCMCIA_DEVICE_PROD_ID12("Megahertz", "CC10BT/2", 0x33234748, 0x3c95b953),
2349 PCMCIA_DEVICE_PROD_ID12("MELCO/SMC", "LPC-TX", 0xa2cd8e6d, 0x42da662a),
2350 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2351 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2352 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast Ethernet PCCard", 0x281f1c5d, 0xdcea68bc),
2353 PCMCIA_DEVICE_PROD_ID12("Psion", "10Mb Ethernet", 0x4ef00b21, 0x844be9e9),
2354 PCMCIA_DEVICE_PROD_ID12("SMC", "EtherEZ Ethernet 8020", 0xc4f8b18b, 0x4a0eeb2d),
2355 /* These conflict with other cards! */
2356 /* PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0100), */
2357 /* PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab), */
2360 MODULE_DEVICE_TABLE(pcmcia, smc91c92_ids);
2362 static struct pcmcia_driver smc91c92_cs_driver = {
2363 .owner = THIS_MODULE,
2365 .name = "smc91c92_cs",
2367 .attach = smc91c92_attach,
2368 .detach = smc91c92_detach,
2369 .id_table = smc91c92_ids,
2372 static int __init init_smc91c92_cs(void)
2374 return pcmcia_register_driver(&smc91c92_cs_driver);
2377 static void __exit exit_smc91c92_cs(void)
2379 pcmcia_unregister_driver(&smc91c92_cs_driver);
2380 BUG_ON(dev_list != NULL);
2383 module_init(init_smc91c92_cs);
2384 module_exit(exit_smc91c92_cs);