blob: 8a5e52c40e461de7360b078bae0a302d8e18ab52 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*======================================================================
2
3 A PCMCIA ethernet driver for SMC91c92-based cards.
4
5 This driver supports Megahertz PCMCIA ethernet cards; and
6 Megahertz, Motorola, Ositech, and Psion Dacom ethernet/modem
7 multifunction cards.
8
9 Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net
10
11 smc91c92_cs.c 1.122 2002/10/25 06:26:39
12
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.
22
23 This software may be used and distributed according to the terms of
24 the GNU General Public License, incorporated herein by reference.
25
26======================================================================*/
27
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
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>
52
53#include <asm/io.h>
54#include <asm/system.h>
55#include <asm/uaccess.h>
56
57/* Ositech Seven of Diamonds firmware */
58#include "ositech.h"
59
60/*====================================================================*/
61
62static char *if_names[] = { "auto", "10baseT", "10base2"};
63
64/* Module parameters */
65
66MODULE_DESCRIPTION("SMC 91c92 series PCMCIA ethernet driver");
67MODULE_LICENSE("GPL");
68
69#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
70
71/*
72 Transceiver/media type.
73 0 = auto
74 1 = 10baseT (and autoselect if #define AUTOSELECT),
75 2 = AUI/10base2,
76*/
77INT_MODULE_PARM(if_port, 0);
78
79#ifdef PCMCIA_DEBUG
80INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
81static 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)
84#else
85#define DEBUG(n, args...)
86#endif
87
88#define DRV_NAME "smc91c92_cs"
89#define DRV_VERSION "1.122"
90
91/*====================================================================*/
92
93/* Operational parameter that usually are not changed. */
94
95/* Time in jiffies before concluding Tx hung */
96#define TX_TIMEOUT ((400*HZ)/1000)
97
98/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
99#define INTR_WORK 4
100
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
104
105static dev_info_t dev_info = "smc91c92_cs";
106
107static dev_link_t *dev_list;
108
109struct smc_private {
110 dev_link_t link;
111 spinlock_t lock;
112 u_short manfid;
113 u_short cardid;
114 struct net_device_stats stats;
115 dev_node_t node;
116 struct sk_buff *saved_skb;
117 int packets_waiting;
118 void __iomem *base;
119 u_short cfg;
120 struct timer_list media;
121 int watchdog, tx_err;
122 u_short media_status;
123 u_short fast_poll;
124 u_short link_status;
125 struct mii_if_info mii_if;
126 int duplex;
127 int rx_ovrn;
128};
129
Yum Rayan4638aef42005-05-05 15:14:10 -0700130struct smc_cfg_mem {
131 tuple_t tuple;
132 cisparse_t parse;
133 u_char buf[255];
134};
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136/* Special definitions for Megahertz multifunction cards */
137#define MEGAHERTZ_ISR 0x0380
138
139/* Special function registers for Motorola Mariner */
140#define MOT_LAN 0x0000
141#define MOT_UART 0x0020
142#define MOT_EEPROM 0x20
143
144#define MOT_NORMAL \
145(COR_LEVEL_REQ | COR_FUNC_ENA | COR_ADDR_DECODE | COR_IREQ_ENA)
146
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
154
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
160
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); }
164
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
173
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 */
192
193/* Bank 1 registers. */
194#define CONFIG 0
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
205#define BASE_ADDR 2
206#define ADDR0 4
207#define GENERAL 10
208#define CONTROL 12
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
217
218/* Bank 2 registers. */
219#define MMU_CMD 0
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 */
225#define PNR_ARR 2
226#define FIFO_PORTS 4
227#define FP_RXEMPTY 0x8000
228#define POINTER 6
229#define PTR_AUTO_INC 0x0040
230#define PTR_READ 0x2000
231#define PTR_AUTOINC 0x4000
232#define PTR_RCV 0x8000
233#define DATA_1 8
234#define INTERRUPT 12
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
241
242#define RCR 4
243enum 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 */
250
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 */
254#define COUNTER 6
255
256/* BANK 3 -- not the same values as in smc9194! */
257#define MULTICAST0 0
258#define MULTICAST2 2
259#define MULTICAST4 4
260#define MULTICAST6 6
261#define MGMT 8
262#define REVISION 0x0a
263
264/* Transmit status bits. */
265#define TS_SUCCESS 0x0001
266#define TS_16COL 0x0010
267#define TS_LATCOL 0x0200
268#define TS_LOSTCAR 0x0400
269
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)
278
279#define set_bits(v, p) outw(inw(p)|(v), (p))
280#define mask_bits(v, p) outw(inw(p)&(v), (p))
281
282/*====================================================================*/
283
284static dev_link_t *smc91c92_attach(void);
285static void smc91c92_detach(dev_link_t *);
286static void smc91c92_config(dev_link_t *link);
287static void smc91c92_release(dev_link_t *link);
288static int smc91c92_event(event_t event, int priority,
289 event_callback_args_t *args);
290
291static int smc_open(struct net_device *dev);
292static int smc_close(struct net_device *dev);
293static int smc_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
294static void smc_tx_timeout(struct net_device *dev);
295static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev);
296static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
297static void smc_rx(struct net_device *dev);
298static struct net_device_stats *smc_get_stats(struct net_device *dev);
299static void set_rx_mode(struct net_device *dev);
300static int s9k_config(struct net_device *dev, struct ifmap *map);
301static void smc_set_xcvr(struct net_device *dev, int if_port);
302static void smc_reset(struct net_device *dev);
303static void media_check(u_long arg);
304static void mdio_sync(kio_addr_t addr);
305static int mdio_read(struct net_device *dev, int phy_id, int loc);
306static void mdio_write(struct net_device *dev, int phy_id, int loc, int value);
307static int smc_link_ok(struct net_device *dev);
308static struct ethtool_ops ethtool_ops;
309
310/*======================================================================
311
312 smc91c92_attach() creates an "instance" of the driver, allocating
313 local data structures for one device. The device is registered
314 with Card Services.
315
316======================================================================*/
317
318static dev_link_t *smc91c92_attach(void)
319{
320 client_reg_t client_reg;
321 struct smc_private *smc;
322 dev_link_t *link;
323 struct net_device *dev;
324 int ret;
325
326 DEBUG(0, "smc91c92_attach()\n");
327
328 /* Create new ethernet device */
329 dev = alloc_etherdev(sizeof(struct smc_private));
330 if (!dev)
331 return NULL;
332 smc = netdev_priv(dev);
333 link = &smc->link;
334 link->priv = dev;
335
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;
345 link->conf.Vcc = 50;
346 link->conf.IntType = INT_MEMORY_AND_IO;
347
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, &ethtool_ops);
358#ifdef HAVE_TX_TIMEOUT
359 dev->tx_timeout = smc_tx_timeout;
360 dev->watchdog_timeo = TX_TIMEOUT;
361#endif
362
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;
368
369 /* Register with Card Services */
370 link->next = dev_list;
371 dev_list = link;
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);
380 if (ret != 0) {
381 cs_error(link->handle, RegisterClient, ret);
382 smc91c92_detach(link);
383 return NULL;
384 }
385
386 return link;
387} /* smc91c92_attach */
388
389/*======================================================================
390
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.
395
396======================================================================*/
397
398static void smc91c92_detach(dev_link_t *link)
399{
400 struct net_device *dev = link->priv;
401 dev_link_t **linkp;
402
403 DEBUG(0, "smc91c92_detach(0x%p)\n", link);
404
405 /* Locate device structure */
406 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
407 if (*linkp == link) break;
408 if (*linkp == NULL)
409 return;
410
411 if (link->dev)
412 unregister_netdev(dev);
413
414 if (link->state & DEV_CONFIG)
415 smc91c92_release(link);
416
417 if (link->handle)
418 pcmcia_deregister_client(link->handle);
419
420 /* Unlink device structure, free bits */
421 *linkp = link->next;
422 free_netdev(dev);
423} /* smc91c92_detach */
424
425/*====================================================================*/
426
427static int cvt_ascii_address(struct net_device *dev, char *s)
428{
429 int i, j, da, c;
430
431 if (strlen(s) != 12)
432 return -1;
433 for (i = 0; i < 6; i++) {
434 da = 0;
435 for (j = 0; j < 2; j++) {
436 c = *s++;
437 da <<= 4;
438 da += ((c >= '0') && (c <= '9')) ?
439 (c - '0') : ((c & 0x0f) + 9);
440 }
441 dev->dev_addr[i] = da;
442 }
443 return 0;
444}
445
446/*====================================================================*/
447
448static int first_tuple(client_handle_t handle, tuple_t *tuple,
449 cisparse_t *parse)
450{
451 int i;
452
453 if ((i = pcmcia_get_first_tuple(handle, tuple)) != CS_SUCCESS ||
454 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
455 return i;
456 return pcmcia_parse_tuple(handle, tuple, parse);
457}
458
459static int next_tuple(client_handle_t handle, tuple_t *tuple,
460 cisparse_t *parse)
461{
462 int i;
463
464 if ((i = pcmcia_get_next_tuple(handle, tuple)) != CS_SUCCESS ||
465 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
466 return i;
467 return pcmcia_parse_tuple(handle, tuple, parse);
468}
469
470/*======================================================================
471
472 Configuration stuff for Megahertz cards
473
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
477 address.
478
479======================================================================*/
480
481static int mhz_3288_power(dev_link_t *link)
482{
483 struct net_device *dev = link->priv;
484 struct smc_private *smc = netdev_priv(dev);
485 u_char tmp;
486
487 /* Read the ISR twice... */
488 readb(smc->base+MEGAHERTZ_ISR);
489 udelay(5);
490 readb(smc->base+MEGAHERTZ_ISR);
491
492 /* Pause 200ms... */
493 mdelay(200);
494
495 /* Now read and write the COR... */
496 tmp = readb(smc->base + link->conf.ConfigBase + CISREG_COR);
497 udelay(5);
498 writeb(tmp, smc->base + link->conf.ConfigBase + CISREG_COR);
499
500 return 0;
501}
502
503static int mhz_mfc_config(dev_link_t *link)
504{
505 struct net_device *dev = link->priv;
506 struct smc_private *smc = netdev_priv(dev);
Yum Rayan4638aef42005-05-05 15:14:10 -0700507 struct smc_cfg_mem *cfg_mem;
508 tuple_t *tuple;
509 cisparse_t *parse;
510 cistpl_cftable_entry_t *cf;
511 u_char *buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 win_req_t req;
513 memreq_t mem;
514 int i, k;
515
Yum Rayan4638aef42005-05-05 15:14:10 -0700516 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
517 if (!cfg_mem)
518 return CS_OUT_OF_RESOURCE;
519
520 tuple = &cfg_mem->tuple;
521 parse = &cfg_mem->parse;
522 cf = &parse->cftable_entry;
523 buf = cfg_mem->buf;
524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 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;
532
Yum Rayan4638aef42005-05-05 15:14:10 -0700533 tuple->Attributes = tuple->TupleOffset = 0;
534 tuple->TupleData = (cisdata_t *)buf;
535 tuple->TupleDataMax = 255;
536 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Yum Rayan4638aef42005-05-05 15:14:10 -0700538 i = first_tuple(link->handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 /* 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;
549 }
550 if (i == CS_SUCCESS) break;
Yum Rayan4638aef42005-05-05 15:14:10 -0700551 i = next_tuple(link->handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 }
553 if (i != CS_SUCCESS)
Yum Rayan4638aef42005-05-05 15:14:10 -0700554 goto free_cfg_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 dev->base_addr = link->io.BasePort1;
556
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;
560 req.AccessSpeed = 0;
561 i = pcmcia_request_window(&link->handle, &req, &link->win);
562 if (i != CS_SUCCESS)
Yum Rayan4638aef42005-05-05 15:14:10 -0700563 goto free_cfg_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 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);
569
570 if ((i == CS_SUCCESS)
571 && (smc->manfid == MANFID_MEGAHERTZ)
572 && (smc->cardid == PRODID_MEGAHERTZ_EM3288))
573 mhz_3288_power(link);
574
Yum Rayan4638aef42005-05-05 15:14:10 -0700575free_cfg_mem:
576 kfree(cfg_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 return i;
578}
579
580static int mhz_setup(dev_link_t *link)
581{
582 client_handle_t handle = link->handle;
583 struct net_device *dev = link->priv;
Yum Rayan4638aef42005-05-05 15:14:10 -0700584 struct smc_cfg_mem *cfg_mem;
585 tuple_t *tuple;
586 cisparse_t *parse;
587 u_char *buf, *station_addr;
588 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Yum Rayan4638aef42005-05-05 15:14:10 -0700590 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
591 if (!cfg_mem)
592 return -1;
593
594 tuple = &cfg_mem->tuple;
595 parse = &cfg_mem->parse;
596 buf = cfg_mem->buf;
597
598 tuple->Attributes = tuple->TupleOffset = 0;
599 tuple->TupleData = (cisdata_t *)buf;
600 tuple->TupleDataMax = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602 /* Read the station address from the CIS. It is stored as the last
603 (fourth) string in the Version 1 Version/ID tuple. */
Yum Rayan4638aef42005-05-05 15:14:10 -0700604 tuple->DesiredTuple = CISTPL_VERS_1;
605 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {
606 rc = -1;
607 goto free_cfg_mem;
608 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
Yum Rayan4638aef42005-05-05 15:14:10 -0700610 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) {
615 rc = 0;
616 goto free_cfg_mem;
617 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 }
619
620 /* Another possibility: for the EM3288, in a special tuple */
Yum Rayan4638aef42005-05-05 15:14:10 -0700621 tuple->DesiredTuple = 0x81;
622 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) {
623 rc = -1;
624 goto free_cfg_mem;
625 }
626 if (pcmcia_get_tuple_data(handle, tuple) != CS_SUCCESS) {
627 rc = -1;
628 goto free_cfg_mem;
629 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 buf[12] = '\0';
Yum Rayan4638aef42005-05-05 15:14:10 -0700631 if (cvt_ascii_address(dev, buf) == 0) {
632 rc = 0;
633 goto free_cfg_mem;
634 }
635 rc = -1;
636free_cfg_mem:
637 kfree(cfg_mem);
638 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639}
640
641/*======================================================================
642
643 Configuration stuff for the Motorola Mariner
644
645 mot_config() writes directly to the Mariner configuration
646 registers because the CIS is just bogus.
647
648======================================================================*/
649
650static void mot_config(dev_link_t *link)
651{
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;
656
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);
661
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);
666
667 /* Wait for things to settle down */
668 mdelay(100);
669}
670
671static int mot_setup(dev_link_t *link)
672{
673 struct net_device *dev = link->priv;
674 kio_addr_t ioaddr = dev->base_addr;
675 int i, wait, loop;
676 u_int addr;
677
678 /* Read Ethernet address from Serial EEPROM */
679
680 for (i = 0; i < 3; i++) {
681 SMC_SELECT_BANK(2);
682 outw(MOT_EEPROM + i, ioaddr + POINTER);
683 SMC_SELECT_BANK(1);
684 outw((CTL_RELOAD | CTL_EE_SELECT), ioaddr + CONTROL);
685
686 for (loop = wait = 0; loop < 200; loop++) {
687 udelay(10);
688 wait = ((CTL_RELOAD | CTL_STORE) & inw(ioaddr + CONTROL));
689 if (wait == 0) break;
690 }
691
692 if (wait)
693 return -1;
694
695 addr = inw(ioaddr + GENERAL);
696 dev->dev_addr[2*i] = addr & 0xff;
697 dev->dev_addr[2*i+1] = (addr >> 8) & 0xff;
698 }
699
700 return 0;
701}
702
703/*====================================================================*/
704
705static int smc_config(dev_link_t *link)
706{
707 struct net_device *dev = link->priv;
Yum Rayan4638aef42005-05-05 15:14:10 -0700708 struct smc_cfg_mem *cfg_mem;
709 tuple_t *tuple;
710 cisparse_t *parse;
711 cistpl_cftable_entry_t *cf;
712 u_char *buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 int i;
714
Yum Rayan4638aef42005-05-05 15:14:10 -0700715 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
716 if (!cfg_mem)
717 return CS_OUT_OF_RESOURCE;
718
719 tuple = &cfg_mem->tuple;
720 parse = &cfg_mem->parse;
721 cf = &parse->cftable_entry;
722 buf = cfg_mem->buf;
723
724 tuple->Attributes = tuple->TupleOffset = 0;
725 tuple->TupleData = (cisdata_t *)buf;
726 tuple->TupleDataMax = 255;
727 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
729 link->io.NumPorts1 = 16;
Yum Rayan4638aef42005-05-05 15:14:10 -0700730 i = first_tuple(link->handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 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;
738 }
Yum Rayan4638aef42005-05-05 15:14:10 -0700739 i = next_tuple(link->handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 }
741 if (i == CS_SUCCESS)
742 dev->base_addr = link->io.BasePort1;
Yum Rayan4638aef42005-05-05 15:14:10 -0700743
744 kfree(cfg_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 return i;
746}
747
748static int smc_setup(dev_link_t *link)
749{
750 client_handle_t handle = link->handle;
751 struct net_device *dev = link->priv;
Yum Rayan4638aef42005-05-05 15:14:10 -0700752 struct smc_cfg_mem *cfg_mem;
753 tuple_t *tuple;
754 cisparse_t *parse;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 cistpl_lan_node_id_t *node_id;
Yum Rayan4638aef42005-05-05 15:14:10 -0700756 u_char *buf, *station_addr;
757 int i, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Yum Rayan4638aef42005-05-05 15:14:10 -0700759 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
760 if (!cfg_mem)
761 return CS_OUT_OF_RESOURCE;
762
763 tuple = &cfg_mem->tuple;
764 parse = &cfg_mem->parse;
765 buf = cfg_mem->buf;
766
767 tuple->Attributes = tuple->TupleOffset = 0;
768 tuple->TupleData = (cisdata_t *)buf;
769 tuple->TupleDataMax = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
771 /* Check for a LAN function extension tuple */
Yum Rayan4638aef42005-05-05 15:14:10 -0700772 tuple->DesiredTuple = CISTPL_FUNCE;
773 i = first_tuple(handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 while (i == CS_SUCCESS) {
Yum Rayan4638aef42005-05-05 15:14:10 -0700775 if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 break;
Yum Rayan4638aef42005-05-05 15:14:10 -0700777 i = next_tuple(handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 }
779 if (i == CS_SUCCESS) {
Yum Rayan4638aef42005-05-05 15:14:10 -0700780 node_id = (cistpl_lan_node_id_t *)parse->funce.data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 if (node_id->nb == 6) {
782 for (i = 0; i < 6; i++)
783 dev->dev_addr[i] = node_id->id[i];
Yum Rayan4638aef42005-05-05 15:14:10 -0700784 rc = 0;
785 goto free_cfg_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 }
787 }
788 /* Try the third string in the Version 1 Version/ID tuple. */
Yum Rayan4638aef42005-05-05 15:14:10 -0700789 tuple->DesiredTuple = CISTPL_VERS_1;
790 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {
791 rc = -1;
792 goto free_cfg_mem;
793 }
794 station_addr = parse->version_1.str + parse->version_1.ofs[2];
795 if (cvt_ascii_address(dev, station_addr) == 0) {
796 rc = 0;
797 goto free_cfg_mem;
798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Yum Rayan4638aef42005-05-05 15:14:10 -0700800 rc = -1;
801free_cfg_mem:
802 kfree(cfg_mem);
803 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804}
805
806/*====================================================================*/
807
808static int osi_config(dev_link_t *link)
809{
810 struct net_device *dev = link->priv;
811 static kio_addr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
812 int i, j;
813
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;
822
823 /* Enable Hard Decode, LAN, Modem */
824 link->conf.ConfigIndex = 0x23;
825
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;
830 }
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);
836 }
837 dev->base_addr = link->io.BasePort1 + 0x10;
838 return i;
839}
840
841static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid)
842{
843 client_handle_t handle = link->handle;
844 struct net_device *dev = link->priv;
Yum Rayan4638aef42005-05-05 15:14:10 -0700845 struct smc_cfg_mem *cfg_mem;
846 tuple_t *tuple;
847 u_char *buf;
848 int i, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Yum Rayan4638aef42005-05-05 15:14:10 -0700850 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
851 if (!cfg_mem)
852 return -1;
853
854 tuple = &cfg_mem->tuple;
855 buf = cfg_mem->buf;
856
857 tuple->Attributes = TUPLE_RETURN_COMMON;
858 tuple->TupleData = (cisdata_t *)buf;
859 tuple->TupleDataMax = 255;
860 tuple->TupleOffset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
862 /* Read the station address from tuple 0x90, subtuple 0x04 */
Yum Rayan4638aef42005-05-05 15:14:10 -0700863 tuple->DesiredTuple = 0x90;
864 i = pcmcia_get_first_tuple(handle, tuple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 while (i == CS_SUCCESS) {
Yum Rayan4638aef42005-05-05 15:14:10 -0700866 i = pcmcia_get_tuple_data(handle, tuple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 if ((i != CS_SUCCESS) || (buf[0] == 0x04))
868 break;
Yum Rayan4638aef42005-05-05 15:14:10 -0700869 i = pcmcia_get_next_tuple(handle, tuple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 }
Yum Rayan4638aef42005-05-05 15:14:10 -0700871 if (i != CS_SUCCESS) {
872 rc = -1;
873 goto free_cfg_mem;
874 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 for (i = 0; i < 6; i++)
876 dev->dev_addr[i] = buf[i+2];
877
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);
885 udelay(50);
886 }
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));
895 }
Yum Rayan4638aef42005-05-05 15:14:10 -0700896 rc = 0;
897free_cfg_mem:
898 kfree(cfg_mem);
899 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900}
901
902/*======================================================================
903
904 This verifies that the chip is some SMC91cXX variant, and returns
905 the revision code if successful. Otherwise, it returns -ENODEV.
906
907======================================================================*/
908
909static int check_sig(dev_link_t *link)
910{
911 struct net_device *dev = link->priv;
912 kio_addr_t ioaddr = dev->base_addr;
913 int width;
914 u_short s;
915
916 SMC_SELECT_BANK(1);
917 if (inw(ioaddr + BANK_SELECT) >> 8 != 0x33) {
918 /* Try powering up the chip */
919 outw(0, ioaddr + CONTROL);
920 mdelay(55);
921 }
922
923 /* Try setting bus width */
924 width = (link->io.Attributes1 == IO_DATA_PATH_WIDTH_AUTO);
925 s = inb(ioaddr + CONFIG);
926 if (width)
927 s |= CFG_16BIT;
928 else
929 s &= ~CFG_16BIT;
930 outb(s, ioaddr + CONFIG);
931
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))) {
936 SMC_SELECT_BANK(3);
937 s = inw(ioaddr + REVISION);
938 return (s & 0xff);
939 }
940
941 if (width) {
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);
951 }
952 return -ENODEV;
953}
954
955/*======================================================================
956
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.
960
961======================================================================*/
962
963#define CS_EXIT_TEST(ret, svc, label) \
964if (ret != CS_SUCCESS) { cs_error(link->handle, svc, ret); goto label; }
965
966static void smc91c92_config(dev_link_t *link)
967{
968 client_handle_t handle = link->handle;
969 struct net_device *dev = link->priv;
970 struct smc_private *smc = netdev_priv(dev);
Yum Rayan4638aef42005-05-05 15:14:10 -0700971 struct smc_cfg_mem *cfg_mem;
972 tuple_t *tuple;
973 cisparse_t *parse;
974 u_char *buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 char *name;
976 int i, j, rev;
977 kio_addr_t ioaddr;
978 u_long mir;
979
980 DEBUG(0, "smc91c92_config(0x%p)\n", link);
981
Yum Rayan4638aef42005-05-05 15:14:10 -0700982 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
983 if (!cfg_mem)
984 goto config_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Yum Rayan4638aef42005-05-05 15:14:10 -0700986 tuple = &cfg_mem->tuple;
987 parse = &cfg_mem->parse;
988 buf = cfg_mem->buf;
989
990 tuple->Attributes = tuple->TupleOffset = 0;
991 tuple->TupleData = (cisdata_t *)buf;
992 tuple->TupleDataMax = 64;
993
994 tuple->DesiredTuple = CISTPL_CONFIG;
995 i = first_tuple(handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 CS_EXIT_TEST(i, ParseTuple, config_failed);
Yum Rayan4638aef42005-05-05 15:14:10 -0700997 link->conf.ConfigBase = parse->config.base;
998 link->conf.Present = parse->config.rmask[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
Yum Rayan4638aef42005-05-05 15:14:10 -07001000 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 }
1006
1007 /* Configure card */
1008 link->state |= DEV_CONFIG;
1009
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);
1018 } else {
1019 i = smc_config(link);
1020 }
1021 CS_EXIT_TEST(i, RequestIO, config_failed);
1022
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);
1027
1028 if (smc->manfid == MANFID_MOTOROLA)
1029 mot_config(link);
1030
1031 dev->irq = link->irq.AssignedIRQ;
1032
1033 if ((if_port >= 0) && (if_port <= 2))
1034 dev->if_port = if_port;
1035 else
1036 printk(KERN_NOTICE "smc91c92_cs: invalid if_port requested\n");
1037
1038 switch (smc->manfid) {
1039 case MANFID_OSITECH:
1040 case MANFID_PSION:
1041 i = osi_setup(link, smc->manfid, smc->cardid); break;
1042 case MANFID_SMC:
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;
1051 }
1052
1053 if (i != 0) {
1054 printk(KERN_NOTICE "smc91c92_cs: Unable to find hardware address.\n");
1055 goto config_undo;
1056 }
1057
1058 smc->duplex = 0;
1059 smc->rx_ovrn = 0;
1060
1061 rev = check_sig(link);
1062 name = "???";
1063 if (rev > 0)
1064 switch (rev >> 4) {
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;
1071 }
1072
1073 ioaddr = dev->base_addr;
1074 if (rev > 0) {
1075 u_long mcr;
1076 SMC_SELECT_BANK(0);
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));
1082 SMC_SELECT_BANK(1);
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;
1089 } else
1090 mir = 0;
1091
1092 if (smc->cfg & CFG_MII_SELECT) {
1093 SMC_SELECT_BANK(3);
1094
1095 for (i = 0; i < 32; i++) {
1096 j = mdio_read(dev, i, 1);
1097 if ((j != 0) && (j != 0xffff)) break;
1098 }
1099 smc->mii_if.phy_id = (i < 32) ? i : -1;
1100
1101 SMC_SELECT_BANK(0);
1102 }
1103
1104 link->dev = &smc->node;
1105 link->state &= ~DEV_CONFIG_PENDING;
1106 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
1107
1108 if (register_netdev(dev) != 0) {
1109 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n");
1110 link->dev = NULL;
1111 goto config_undo;
1112 }
1113
1114 strcpy(smc->node.dev_name, dev->name);
1115
1116 printk(KERN_INFO "%s: smc91c%s rev %d: io %#3lx, irq %d, "
1117 "hw_addr ", dev->name, name, (rev & 0x0f), dev->base_addr,
1118 dev->irq);
1119 for (i = 0; i < 6; i++)
1120 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
1121
1122 if (rev > 0) {
1123 if (mir & 0x3ff)
1124 printk(KERN_INFO " %lu byte", mir);
1125 else
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]);
1129 }
1130
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);
1135 } else {
1136 printk(KERN_NOTICE " No MII transceivers found!\n");
1137 }
1138 }
Yum Rayan4638aef42005-05-05 15:14:10 -07001139 kfree(cfg_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 return;
1141
1142config_undo:
1143 unregister_netdev(dev);
1144config_failed: /* CS_EXIT_TEST() calls jump to here... */
1145 smc91c92_release(link);
1146 link->state &= ~DEV_CONFIG_PENDING;
Yum Rayan4638aef42005-05-05 15:14:10 -07001147 kfree(cfg_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
1149} /* smc91c92_config */
1150
1151/*======================================================================
1152
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.
1156
1157======================================================================*/
1158
1159static void smc91c92_release(dev_link_t *link)
1160{
1161
1162 DEBUG(0, "smc91c92_release(0x%p)\n", link);
1163
1164 pcmcia_release_configuration(link->handle);
1165 pcmcia_release_io(link->handle, &link->io);
1166 pcmcia_release_irq(link->handle, &link->irq);
1167 if (link->win) {
1168 struct net_device *dev = link->priv;
1169 struct smc_private *smc = netdev_priv(dev);
1170 iounmap(smc->base);
1171 pcmcia_release_window(link->win);
1172 }
1173
1174 link->state &= ~DEV_CONFIG;
1175}
1176
1177/*======================================================================
1178
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.
1183
1184======================================================================*/
1185
1186static int smc91c92_event(event_t event, int priority,
1187 event_callback_args_t *args)
1188{
1189 dev_link_t *link = args->client_data;
1190 struct net_device *dev = link->priv;
1191 struct smc_private *smc = netdev_priv(dev);
1192 int i;
1193
1194 DEBUG(1, "smc91c92_event(0x%06x)\n", event);
1195
1196 switch (event) {
1197 case CS_EVENT_CARD_REMOVAL:
1198 link->state &= ~DEV_PRESENT;
1199 if (link->state & DEV_CONFIG)
1200 netif_device_detach(dev);
1201 break;
1202 case CS_EVENT_CARD_INSERTION:
1203 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1204 smc91c92_config(link);
1205 break;
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) {
1211 if (link->open)
1212 netif_device_detach(dev);
1213 pcmcia_release_configuration(link->handle);
1214 }
1215 break;
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)
1226 mot_config(link);
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);
1232 }
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);
1240 udelay(50);
1241 }
1242 }
1243 if (link->open) {
1244 smc_reset(dev);
1245 netif_device_attach(dev);
1246 }
1247 }
1248 break;
1249 }
1250 return 0;
1251} /* smc91c92_event */
1252
1253/*======================================================================
1254
1255 MII interface support for SMC91cXX based cards
1256======================================================================*/
1257
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
1264
1265static void mdio_sync(kio_addr_t addr)
1266{
1267 int bits;
1268 for (bits = 0; bits < 32; bits++) {
1269 outb(MDIO_DATA_WRITE1, addr);
1270 outb(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
1271 }
1272}
1273
1274static int mdio_read(struct net_device *dev, int phy_id, int loc)
1275{
1276 kio_addr_t addr = dev->base_addr + MGMT;
1277 u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
1278 int i, retval = 0;
1279
1280 mdio_sync(addr);
1281 for (i = 13; i >= 0; i--) {
1282 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1283 outb(dat, addr);
1284 outb(dat | MDIO_SHIFT_CLK, addr);
1285 }
1286 for (i = 19; i > 0; i--) {
1287 outb(0, addr);
1288 retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
1289 outb(MDIO_SHIFT_CLK, addr);
1290 }
1291 return (retval>>1) & 0xffff;
1292}
1293
1294static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
1295{
1296 kio_addr_t addr = dev->base_addr + MGMT;
1297 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
1298 int i;
1299
1300 mdio_sync(addr);
1301 for (i = 31; i >= 0; i--) {
1302 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1303 outb(dat, addr);
1304 outb(dat | MDIO_SHIFT_CLK, addr);
1305 }
1306 for (i = 1; i >= 0; i--) {
1307 outb(0, addr);
1308 outb(MDIO_SHIFT_CLK, addr);
1309 }
1310}
1311
1312/*======================================================================
1313
1314 The driver core code, most of which should be common with a
1315 non-PCMCIA implementation.
1316
1317======================================================================*/
1318
1319#ifdef PCMCIA_DEBUG
1320static void smc_dump(struct net_device *dev)
1321{
1322 kio_addr_t ioaddr = dev->base_addr;
1323 u_short i, w, save;
1324 save = inw(ioaddr + BANK_SELECT);
1325 for (w = 0; w < 4; w++) {
1326 SMC_SELECT_BANK(w);
1327 printk(KERN_DEBUG "bank %d: ", w);
1328 for (i = 0; i < 14; i += 2)
1329 printk(" %04x", inw(ioaddr + i));
1330 printk("\n");
1331 }
1332 outw(save, ioaddr + BANK_SELECT);
1333}
1334#endif
1335
1336static int smc_open(struct net_device *dev)
1337{
1338 struct smc_private *smc = netdev_priv(dev);
1339 dev_link_t *link = &smc->link;
1340
1341#ifdef PCMCIA_DEBUG
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);
1345#endif
1346
1347 /* Check that the PCMCIA card is still here. */
1348 if (!DEV_OK(link))
1349 return -ENODEV;
1350 /* Physical device present signature. */
1351 if (check_sig(link) < 0) {
1352 printk("smc91c92_cs: Yikes! Bad chip signature!\n");
1353 return -ENODEV;
1354 }
1355 link->open++;
1356
1357 netif_start_queue(dev);
1358 smc->saved_skb = NULL;
1359 smc->packets_waiting = 0;
1360
1361 smc_reset(dev);
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);
1367
1368 return 0;
1369} /* smc_open */
1370
1371/*====================================================================*/
1372
1373static int smc_close(struct net_device *dev)
1374{
1375 struct smc_private *smc = netdev_priv(dev);
1376 dev_link_t *link = &smc->link;
1377 kio_addr_t ioaddr = dev->base_addr;
1378
1379 DEBUG(0, "%s: smc_close(), status %4.4x.\n",
1380 dev->name, inw(ioaddr + BANK_SELECT));
1381
1382 netif_stop_queue(dev);
1383
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);
1388 SMC_SELECT_BANK(0);
1389 mask_bits(0xff00, ioaddr + RCR);
1390 mask_bits(0xff00, ioaddr + TCR);
1391
1392 /* Put the chip into power-down mode. */
1393 SMC_SELECT_BANK(1);
1394 outw(CTL_POWERDOWN, ioaddr + CONTROL );
1395
1396 link->open--;
1397 del_timer_sync(&smc->media);
1398
1399 return 0;
1400} /* smc_close */
1401
1402/*======================================================================
1403
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.
1407
1408======================================================================*/
1409
1410static void smc_hardware_send_packet(struct net_device * dev)
1411{
1412 struct smc_private *smc = netdev_priv(dev);
1413 struct sk_buff *skb = smc->saved_skb;
1414 kio_addr_t ioaddr = dev->base_addr;
1415 u_char packet_no;
1416
1417 if (!skb) {
1418 printk(KERN_ERR "%s: In XMIT with no packet to send.\n", dev->name);
1419 return;
1420 }
1421
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);
1431 return;
1432 }
1433
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);
1439
1440 /* Send the packet length (+6 for status, length and ctl byte)
1441 and the status word (set to zeros). */
1442 {
1443 u_char *buf = skb->data;
1444 u_int length = skb->len; /* The chip will pad to ethernet min. */
1445
1446 DEBUG(2, "%s: Trying to xmit packet of length %d.\n",
1447 dev->name, length);
1448
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);
1453
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);
1456 }
1457
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);
1462
1463 /* The chip does the rest of the work. */
1464 outw(MC_ENQUEUE , ioaddr + MMU_CMD);
1465
1466 smc->saved_skb = NULL;
1467 dev_kfree_skb_irq(skb);
1468 dev->trans_start = jiffies;
1469 netif_start_queue(dev);
1470 return;
1471}
1472
1473/*====================================================================*/
1474
1475static void smc_tx_timeout(struct net_device *dev)
1476{
1477 struct smc_private *smc = netdev_priv(dev);
1478 kio_addr_t ioaddr = dev->base_addr;
1479
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++;
1484 smc_reset(dev);
1485 dev->trans_start = jiffies;
1486 smc->saved_skb = NULL;
1487 netif_wake_queue(dev);
1488}
1489
1490static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev)
1491{
1492 struct smc_private *smc = netdev_priv(dev);
1493 kio_addr_t ioaddr = dev->base_addr;
1494 u_short num_pages;
1495 short time_out, ir;
1496
1497 netif_stop_queue(dev);
1498
1499 DEBUG(2, "%s: smc_start_xmit(length = %d) called,"
1500 " status %4.4x.\n", dev->name, skb->len, inw(ioaddr + 2));
1501
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",
1506 dev->name);
1507 return 1;
1508 }
1509 smc->saved_skb = skb;
1510
1511 num_pages = skb->len >> 8;
1512
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. */
1519 }
1520 /* A packet is now waiting. */
1521 smc->packets_waiting++;
1522
1523 SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */
1524
1525 /* need MC_RESET to keep the memory consistent. errata? */
1526 if (smc->rx_ovrn) {
1527 outw(MC_RESET, ioaddr + MMU_CMD);
1528 smc->rx_ovrn = 0;
1529 }
1530
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.. */
1539 return 0;
1540 }
1541 }
1542
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);
1546
1547 return 0;
1548}
1549
1550/*======================================================================
1551
1552 Handle a Tx anomolous event. Entered while in Window 2.
1553
1554======================================================================*/
1555
1556static void smc_tx_err(struct net_device * dev)
1557{
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;
1562 int tx_status;
1563
1564 /* select this as the packet to read from */
1565 outw(packet_no, ioaddr + PNR_ARR);
1566
1567 /* read the first word from this packet */
1568 outw(PTR_AUTOINC | PTR_READ | 0, ioaddr + POINTER);
1569
1570 tx_status = inw(ioaddr + DATA_1);
1571
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++;
1577 smc->tx_err++;
1578 }
1579
1580 if (tx_status & TS_SUCCESS) {
1581 printk(KERN_NOTICE "%s: Successful packet caused error "
1582 "interrupt?\n", dev->name);
1583 }
1584 /* re-enable transmit */
1585 SMC_SELECT_BANK(0);
1586 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1587 SMC_SELECT_BANK(2);
1588
1589 outw(MC_FREEPKT, ioaddr + MMU_CMD); /* Free the packet memory. */
1590
1591 /* one less packet waiting for me */
1592 smc->packets_waiting--;
1593
1594 outw(saved_packet, ioaddr + PNR_ARR);
1595 return;
1596}
1597
1598/*====================================================================*/
1599
1600static void smc_eph_irq(struct net_device *dev)
1601{
1602 struct smc_private *smc = netdev_priv(dev);
1603 kio_addr_t ioaddr = dev->base_addr;
1604 u_short card_stats, ephs;
1605
1606 SMC_SELECT_BANK(0);
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;
1614 card_stats >>= 4;
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 */
1620#endif
1621 /* If we had a transmit error we must re-enable the transmitter. */
1622 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1623
1624 /* Clear a link error interrupt. */
1625 SMC_SELECT_BANK(1);
1626 outw(CTL_AUTO_RELEASE | 0x0000, ioaddr + CONTROL);
1627 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1628 ioaddr + CONTROL);
1629 SMC_SELECT_BANK(2);
1630}
1631
1632/*====================================================================*/
1633
1634static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1635{
1636 struct net_device *dev = dev_id;
1637 struct smc_private *smc = netdev_priv(dev);
1638 kio_addr_t ioaddr;
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. */
1642
1643 if (!netif_device_present(dev))
1644 return IRQ_NONE;
1645
1646 ioaddr = dev->base_addr;
1647
1648 DEBUG(3, "%s: SMC91c92 interrupt %d at %#x.\n", dev->name,
1649 irq, ioaddr);
1650
1651 smc->watchdog = 0;
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);
1658 handled = 0;
1659 goto irq_done;
1660 }
1661
1662 SMC_SELECT_BANK(2);
1663 saved_pointer = inw(ioaddr + POINTER);
1664 mask = inw(ioaddr + INTERRUPT) >> 8;
1665 /* clear all interrupts */
1666 outw(0, ioaddr + INTERRUPT);
1667
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,
1671 status, mask);
1672 if ((status & mask) == 0) {
1673 if (bogus_cnt == INTR_WORK)
1674 handled = 0;
1675 break;
1676 }
1677 if (status & IM_RCV_INT) {
1678 /* Got a packet(s). */
1679 smc_rx(dev);
1680 }
1681 if (status & IM_TX_INT) {
1682 smc_tx_err(dev);
1683 outw(IM_TX_INT, ioaddr + INTERRUPT);
1684 }
1685 status &= mask;
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;
1691 }
1692 if (status & IM_ALLOC_INT) {
1693 /* Clear this interrupt so it doesn't happen again */
1694 mask &= ~IM_ALLOC_INT;
1695
1696 smc_hardware_send_packet(dev);
1697
1698 /* enable xmit interrupts based on this */
1699 mask |= (IM_TX_EMPTY_INT | IM_TX_INT);
1700
1701 /* and let the card send more packets to me */
1702 netif_wake_queue(dev);
1703 }
1704 if (status & IM_RX_OVRN_INT) {
1705 smc->stats.rx_errors++;
1706 smc->stats.rx_fifo_errors++;
1707 if (smc->duplex)
1708 smc->rx_ovrn = 1; /* need MC_RESET outside smc_interrupt */
1709 outw(IM_RX_OVRN_INT, ioaddr + INTERRUPT);
1710 }
1711 if (status & IM_EPH_INT)
1712 smc_eph_irq(dev);
1713 } while (--bogus_cnt);
1714
1715 DEBUG(3, " Restoring saved registers mask %2.2x bank %4.4x"
1716 " pointer %4.4x.\n", mask, saved_bank, saved_pointer);
1717
1718 /* restore state register */
1719 outw((mask<<8), ioaddr + INTERRUPT);
1720 outw(saved_pointer, ioaddr + POINTER);
1721 SMC_SELECT_BANK(saved_bank);
1722
1723 DEBUG(3, "%s: Exiting interrupt IRQ%d.\n", dev->name, irq);
1724
1725irq_done:
1726
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);
1732 }
1733 if (smc->manfid == MANFID_MOTOROLA) {
1734 u_char cor;
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);
1741 }
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);
1746 }
1747#endif
1748 return IRQ_RETVAL(handled);
1749}
1750
1751/*====================================================================*/
1752
1753static void smc_rx(struct net_device *dev)
1754{
1755 struct smc_private *smc = netdev_priv(dev);
1756 kio_addr_t ioaddr = dev->base_addr;
1757 int rx_status;
1758 int packet_length; /* Caution: not frame length, rather words
1759 to transfer from the chip. */
1760
1761 /* Assertion: we are in Window 2. */
1762
1763 if (inw(ioaddr + FIFO_PORTS) & FP_RXEMPTY) {
1764 printk(KERN_ERR "%s: smc_rx() with nothing on Rx FIFO.\n",
1765 dev->name);
1766 return;
1767 }
1768
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;
1773
1774 DEBUG(2, "%s: Receive status %4.4x length %d.\n",
1775 dev->name, rx_status, packet_length);
1776
1777 if (!(rx_status & RS_ERRORS)) {
1778 /* do stuff to make a new packet */
1779 struct sk_buff *skb;
1780
1781 /* Note: packet_length adds 5 or 6 extra bytes here! */
1782 skb = dev_alloc_skb(packet_length+2);
1783
1784 if (skb == NULL) {
1785 DEBUG(1, "%s: Low memory, packet dropped.\n", dev->name);
1786 smc->stats.rx_dropped++;
1787 outw(MC_RELEASE, ioaddr + MMU_CMD);
1788 return;
1789 }
1790
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);
1796
1797 skb->dev = dev;
1798 netif_rx(skb);
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++;
1804 } else {
1805 /* error ... */
1806 smc->stats.rx_errors++;
1807
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++;
1812 }
1813 /* Let the MMU free the memory of this packet. */
1814 outw(MC_RELEASE, ioaddr + MMU_CMD);
1815
1816 return;
1817}
1818
1819/*====================================================================*/
1820
1821static struct net_device_stats *smc_get_stats(struct net_device *dev)
1822{
1823 struct smc_private *smc = netdev_priv(dev);
1824 /* Nothing to update - the 91c92 is a pretty primative chip. */
1825 return &smc->stats;
1826}
1827
1828/*======================================================================
1829
1830 Calculate values for the hardware multicast filter hash table.
1831
1832======================================================================*/
1833
1834static void fill_multicast_tbl(int count, struct dev_mc_list *addrs,
1835 u_char *multicast_table)
1836{
1837 struct dev_mc_list *mc_addr;
1838
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)
1843 continue;
1844#endif
1845 multicast_table[position >> 29] |= 1 << ((position >> 26) & 7);
1846 }
1847}
1848
1849/*======================================================================
1850
1851 Set the receive mode.
1852
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.
1857
1858======================================================================*/
1859
1860static void set_rx_mode(struct net_device *dev)
1861{
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;
1867
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;
1873 else {
1874 if (dev->mc_count) {
1875 fill_multicast_tbl(dev->mc_count, dev->mc_list,
1876 (u_char *)multicast_table);
1877 }
1878 rx_cfg_setting = RxStripCRC | RxEnable;
1879 }
1880
1881 /* Load MC table and Rx setting into the chip without interrupts. */
1882 spin_lock_irqsave(&smc->lock, flags);
1883 SMC_SELECT_BANK(3);
1884 outl(multicast_table[0], ioaddr + MULTICAST0);
1885 outl(multicast_table[1], ioaddr + MULTICAST4);
1886 SMC_SELECT_BANK(0);
1887 outw(rx_cfg_setting, ioaddr + RCR);
1888 SMC_SELECT_BANK(2);
1889 spin_unlock_irqrestore(&smc->lock, flags);
1890
1891 return;
1892}
1893
1894/*======================================================================
1895
1896 Senses when a card's config changes. Here, it's coax or TP.
1897
1898======================================================================*/
1899
1900static int s9k_config(struct net_device *dev, struct ifmap *map)
1901{
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)
1905 return -EOPNOTSUPP;
1906 else if (map->port > 2)
1907 return -EINVAL;
1908 dev->if_port = map->port;
1909 printk(KERN_INFO "%s: switched to %s port\n",
1910 dev->name, if_names[dev->if_port]);
1911 smc_reset(dev);
1912 }
1913 return 0;
1914}
1915
1916/*======================================================================
1917
1918 Reset the chip, reloading every register that might be corrupted.
1919
1920======================================================================*/
1921
1922/*
1923 Set transceiver type, perhaps to something other than what the user
1924 specified in dev->if_port.
1925*/
1926static void smc_set_xcvr(struct net_device *dev, int if_port)
1927{
1928 struct smc_private *smc = netdev_priv(dev);
1929 kio_addr_t ioaddr = dev->base_addr;
1930 u_short saved_bank;
1931
1932 saved_bank = inw(ioaddr + BANK_SELECT);
1933 SMC_SELECT_BANK(1);
1934 if (if_port == 2) {
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);
1940 } else {
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);
1946 }
1947 SMC_SELECT_BANK(saved_bank);
1948}
1949
1950static void smc_reset(struct net_device *dev)
1951{
1952 kio_addr_t ioaddr = dev->base_addr;
1953 struct smc_private *smc = netdev_priv(dev);
1954 int i;
1955
1956 DEBUG(0, "%s: smc91c92 reset called.\n", dev->name);
1957
1958 /* The first interaction must be a write to bring the chip out
1959 of sleep mode. */
1960 SMC_SELECT_BANK(0);
1961 /* Reset the chip. */
1962 outw(RCR_SOFTRESET, ioaddr + RCR);
1963 udelay(10);
1964
1965 /* Clear the transmit and receive configuration registers. */
1966 outw(RCR_CLEAR, ioaddr + RCR);
1967 outw(TCR_CLEAR, ioaddr + TCR);
1968
1969 /* Set the Window 1 control, configuration and station addr registers.
1970 No point in writing the I/O base register ;-> */
1971 SMC_SELECT_BANK(1);
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,
1975 ioaddr + CONTROL);
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);
1982
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);
1987
1988 /* Reset the MMU */
1989 SMC_SELECT_BANK(2);
1990 outw(MC_RESET, ioaddr + MMU_CMD);
1991 outw(0, ioaddr + INTERRUPT);
1992
1993 /* Re-enable the chip. */
1994 SMC_SELECT_BANK(0);
1995 outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) |
1996 TCR_ENABLE | TCR_PAD_EN | smc->duplex, ioaddr + TCR);
1997 set_rx_mode(dev);
1998
1999 if (smc->cfg & CFG_MII_SELECT) {
2000 SMC_SELECT_BANK(3);
2001
2002 /* Reset MII */
2003 mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000);
2004
2005 /* Advertise 100F, 100H, 10F, 10H */
2006 mdio_write(dev, smc->mii_if.phy_id, 4, 0x01e1);
2007
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);
2011 }
2012
2013 /* Enable interrupts. */
2014 SMC_SELECT_BANK(2);
2015 outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,
2016 ioaddr + INTERRUPT);
2017}
2018
2019/*======================================================================
2020
2021 Media selection timer routine
2022
2023======================================================================*/
2024
2025static void media_check(u_long arg)
2026{
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;
2031 u_short link;
2032
2033 saved_bank = inw(ioaddr + BANK_SELECT);
2034
2035 if (!netif_device_present(dev))
2036 goto reschedule;
2037
2038 SMC_SELECT_BANK(2);
2039
2040 /* need MC_RESET to keep the memory consistent. errata? */
2041 if (smc->rx_ovrn) {
2042 outw(MC_RESET, ioaddr + MMU_CMD);
2043 smc->rx_ovrn = 0;
2044 }
2045 i = inw(ioaddr + INTERRUPT);
2046 SMC_SELECT_BANK(0);
2047 media = inw(ioaddr + EPH) & EPH_LINK_OK;
2048 SMC_SELECT_BANK(1);
2049 media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1;
2050
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;
2058 }
2059 if (smc->fast_poll) {
2060 smc->fast_poll--;
2061 smc->media.expires = jiffies + HZ/100;
2062 add_timer(&smc->media);
2063 SMC_SELECT_BANK(saved_bank);
2064 return;
2065 }
2066
2067 if (smc->cfg & CFG_MII_SELECT) {
2068 if (smc->mii_if.phy_id < 0)
2069 goto reschedule;
2070
2071 SMC_SELECT_BANK(3);
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;
2076 goto reschedule;
2077 }
2078
2079 link &= 0x0004;
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))
2085 ? TCR_FDUPLX : 0);
2086 if (link) {
2087 printk(KERN_INFO "%s: autonegotiation complete: "
2088 "%sbaseT-%cD selected\n", dev->name,
2089 ((p & 0x0180) ? "100" : "10"),
2090 (smc->duplex ? 'F' : 'H'));
2091 }
2092 SMC_SELECT_BANK(0);
2093 outw(inw(ioaddr + TCR) | smc->duplex, ioaddr + TCR);
2094 smc->link_status = link;
2095 }
2096 goto reschedule;
2097 }
2098
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))
2102 media |= EPH_16COL;
2103 }
2104 smc->tx_err = 0;
2105
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) {
2116 if (media & 1) {
2117 if (media & EPH_LINK_OK)
2118 printk(KERN_INFO "%s: flipped to 10baseT\n",
2119 dev->name);
2120 else
2121 smc_set_xcvr(dev, 2);
2122 } else {
2123 if (media & EPH_16COL)
2124 smc_set_xcvr(dev, 1);
2125 else
2126 printk(KERN_INFO "%s: flipped to 10base2\n",
2127 dev->name);
2128 }
2129 }
2130 smc->media_status = media;
2131 }
2132
2133reschedule:
2134 smc->media.expires = jiffies + HZ;
2135 add_timer(&smc->media);
2136 SMC_SELECT_BANK(saved_bank);
2137}
2138
2139static int smc_link_ok(struct net_device *dev)
2140{
2141 kio_addr_t ioaddr = dev->base_addr;
2142 struct smc_private *smc = netdev_priv(dev);
2143
2144 if (smc->cfg & CFG_MII_SELECT) {
2145 return mii_link_ok(&smc->mii_if);
2146 } else {
2147 SMC_SELECT_BANK(0);
2148 return inw(ioaddr + EPH) & EPH_LINK_OK;
2149 }
2150}
2151
2152static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2153{
2154 u16 tmp;
2155 kio_addr_t ioaddr = dev->base_addr;
2156
2157 ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |
2158 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);
2159
2160 SMC_SELECT_BANK(1);
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;
2166
2167 SMC_SELECT_BANK(0);
2168 tmp = inw(ioaddr + TCR);
2169 ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF;
2170
2171 return 0;
2172}
2173
2174static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2175{
2176 u16 tmp;
2177 kio_addr_t ioaddr = dev->base_addr;
2178
2179 if (ecmd->speed != SPEED_10)
2180 return -EINVAL;
2181 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
2182 return -EINVAL;
2183 if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI)
2184 return -EINVAL;
2185 if (ecmd->transceiver != XCVR_INTERNAL)
2186 return -EINVAL;
2187
2188 if (ecmd->port == PORT_AUI)
2189 smc_set_xcvr(dev, 1);
2190 else
2191 smc_set_xcvr(dev, 0);
2192
2193 SMC_SELECT_BANK(0);
2194 tmp = inw(ioaddr + TCR);
2195 if (ecmd->duplex == DUPLEX_FULL)
2196 tmp |= TCR_FDUPLX;
2197 else
2198 tmp &= ~TCR_FDUPLX;
2199 outw(tmp, ioaddr + TCR);
2200
2201 return 0;
2202}
2203
2204static int check_if_running(struct net_device *dev)
2205{
2206 if (!netif_running(dev))
2207 return -EINVAL;
2208 return 0;
2209}
2210
2211static void smc_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2212{
2213 strcpy(info->driver, DRV_NAME);
2214 strcpy(info->version, DRV_VERSION);
2215}
2216
2217static int smc_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2218{
2219 struct smc_private *smc = netdev_priv(dev);
2220 kio_addr_t ioaddr = dev->base_addr;
2221 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2222 int ret;
2223
2224 SMC_SELECT_BANK(3);
2225 spin_lock_irq(&smc->lock);
2226 if (smc->cfg & CFG_MII_SELECT)
2227 ret = mii_ethtool_gset(&smc->mii_if, ecmd);
2228 else
2229 ret = smc_netdev_get_ecmd(dev, ecmd);
2230 spin_unlock_irq(&smc->lock);
2231 SMC_SELECT_BANK(saved_bank);
2232 return ret;
2233}
2234
2235static int smc_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2236{
2237 struct smc_private *smc = netdev_priv(dev);
2238 kio_addr_t ioaddr = dev->base_addr;
2239 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2240 int ret;
2241
2242 SMC_SELECT_BANK(3);
2243 spin_lock_irq(&smc->lock);
2244 if (smc->cfg & CFG_MII_SELECT)
2245 ret = mii_ethtool_sset(&smc->mii_if, ecmd);
2246 else
2247 ret = smc_netdev_set_ecmd(dev, ecmd);
2248 spin_unlock_irq(&smc->lock);
2249 SMC_SELECT_BANK(saved_bank);
2250 return ret;
2251}
2252
2253static u32 smc_get_link(struct net_device *dev)
2254{
2255 struct smc_private *smc = netdev_priv(dev);
2256 kio_addr_t ioaddr = dev->base_addr;
2257 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2258 u32 ret;
2259
2260 SMC_SELECT_BANK(3);
2261 spin_lock_irq(&smc->lock);
2262 ret = smc_link_ok(dev);
2263 spin_unlock_irq(&smc->lock);
2264 SMC_SELECT_BANK(saved_bank);
2265 return ret;
2266}
2267
2268#ifdef PCMCIA_DEBUG
2269static u32 smc_get_msglevel(struct net_device *dev)
2270{
2271 return pc_debug;
2272}
2273
2274static void smc_set_msglevel(struct net_device *dev, u32 val)
2275{
2276 pc_debug = val;
2277}
2278#endif
2279
2280static int smc_nway_reset(struct net_device *dev)
2281{
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);
2286 int res;
2287
2288 SMC_SELECT_BANK(3);
2289 res = mii_nway_restart(&smc->mii_if);
2290 SMC_SELECT_BANK(saved_bank);
2291
2292 return res;
2293 } else
2294 return -EOPNOTSUPP;
2295}
2296
2297static 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,
2303#ifdef PCMCIA_DEBUG
2304 .get_msglevel = smc_get_msglevel,
2305 .set_msglevel = smc_set_msglevel,
2306#endif
2307 .nway_reset = smc_nway_reset,
2308};
2309
2310static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
2311{
2312 struct smc_private *smc = netdev_priv(dev);
2313 struct mii_ioctl_data *mii = if_mii(rq);
2314 int rc = 0;
2315 u16 saved_bank;
2316 kio_addr_t ioaddr = dev->base_addr;
2317
2318 if (!netif_running(dev))
2319 return -EINVAL;
2320
2321 spin_lock_irq(&smc->lock);
2322 saved_bank = inw(ioaddr + BANK_SELECT);
2323 SMC_SELECT_BANK(3);
2324 rc = generic_mii_ioctl(&smc->mii_if, mii, cmd, NULL);
2325 SMC_SELECT_BANK(saved_bank);
2326 spin_unlock_irq(&smc->lock);
2327 return rc;
2328}
2329
2330static struct pcmcia_driver smc91c92_cs_driver = {
2331 .owner = THIS_MODULE,
2332 .drv = {
2333 .name = "smc91c92_cs",
2334 },
2335 .attach = smc91c92_attach,
2336 .detach = smc91c92_detach,
2337};
2338
2339static int __init init_smc91c92_cs(void)
2340{
2341 return pcmcia_register_driver(&smc91c92_cs_driver);
2342}
2343
2344static void __exit exit_smc91c92_cs(void)
2345{
2346 pcmcia_unregister_driver(&smc91c92_cs_driver);
2347 BUG_ON(dev_list != NULL);
2348}
2349
2350module_init(init_smc91c92_cs);
2351module_exit(exit_smc91c92_cs);