blob: 0d8bb4cccbb76e876a2903ad0fa3d2330905041d [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>
Marcelo Feitoza Parisi4851d3a2005-07-15 10:00:41 -070044#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 client_reg.Version = 0x0210;
374 client_reg.event_callback_args.client_data = link;
375 ret = pcmcia_register_client(&link->handle, &client_reg);
376 if (ret != 0) {
377 cs_error(link->handle, RegisterClient, ret);
378 smc91c92_detach(link);
379 return NULL;
380 }
381
382 return link;
383} /* smc91c92_attach */
384
385/*======================================================================
386
387 This deletes a driver "instance". The device is de-registered
388 with Card Services. If it has been released, all local data
389 structures are freed. Otherwise, the structures will be freed
390 when the device is released.
391
392======================================================================*/
393
394static void smc91c92_detach(dev_link_t *link)
395{
396 struct net_device *dev = link->priv;
397 dev_link_t **linkp;
398
399 DEBUG(0, "smc91c92_detach(0x%p)\n", link);
400
401 /* Locate device structure */
402 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
403 if (*linkp == link) break;
404 if (*linkp == NULL)
405 return;
406
407 if (link->dev)
408 unregister_netdev(dev);
409
410 if (link->state & DEV_CONFIG)
411 smc91c92_release(link);
412
413 if (link->handle)
414 pcmcia_deregister_client(link->handle);
415
416 /* Unlink device structure, free bits */
417 *linkp = link->next;
418 free_netdev(dev);
419} /* smc91c92_detach */
420
421/*====================================================================*/
422
423static int cvt_ascii_address(struct net_device *dev, char *s)
424{
425 int i, j, da, c;
426
427 if (strlen(s) != 12)
428 return -1;
429 for (i = 0; i < 6; i++) {
430 da = 0;
431 for (j = 0; j < 2; j++) {
432 c = *s++;
433 da <<= 4;
434 da += ((c >= '0') && (c <= '9')) ?
435 (c - '0') : ((c & 0x0f) + 9);
436 }
437 dev->dev_addr[i] = da;
438 }
439 return 0;
440}
441
442/*====================================================================*/
443
444static int first_tuple(client_handle_t handle, tuple_t *tuple,
445 cisparse_t *parse)
446{
447 int i;
448
449 if ((i = pcmcia_get_first_tuple(handle, tuple)) != CS_SUCCESS ||
450 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
451 return i;
452 return pcmcia_parse_tuple(handle, tuple, parse);
453}
454
455static int next_tuple(client_handle_t handle, tuple_t *tuple,
456 cisparse_t *parse)
457{
458 int i;
459
460 if ((i = pcmcia_get_next_tuple(handle, tuple)) != CS_SUCCESS ||
461 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
462 return i;
463 return pcmcia_parse_tuple(handle, tuple, parse);
464}
465
466/*======================================================================
467
468 Configuration stuff for Megahertz cards
469
470 mhz_3288_power() is used to power up a 3288's ethernet chip.
471 mhz_mfc_config() handles socket setup for multifunction (1144
472 and 3288) cards. mhz_setup() gets a card's hardware ethernet
473 address.
474
475======================================================================*/
476
477static int mhz_3288_power(dev_link_t *link)
478{
479 struct net_device *dev = link->priv;
480 struct smc_private *smc = netdev_priv(dev);
481 u_char tmp;
482
483 /* Read the ISR twice... */
484 readb(smc->base+MEGAHERTZ_ISR);
485 udelay(5);
486 readb(smc->base+MEGAHERTZ_ISR);
487
488 /* Pause 200ms... */
489 mdelay(200);
490
491 /* Now read and write the COR... */
492 tmp = readb(smc->base + link->conf.ConfigBase + CISREG_COR);
493 udelay(5);
494 writeb(tmp, smc->base + link->conf.ConfigBase + CISREG_COR);
495
496 return 0;
497}
498
499static int mhz_mfc_config(dev_link_t *link)
500{
501 struct net_device *dev = link->priv;
502 struct smc_private *smc = netdev_priv(dev);
Yum Rayan4638aef42005-05-05 15:14:10 -0700503 struct smc_cfg_mem *cfg_mem;
504 tuple_t *tuple;
505 cisparse_t *parse;
506 cistpl_cftable_entry_t *cf;
507 u_char *buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 win_req_t req;
509 memreq_t mem;
510 int i, k;
511
Yum Rayan4638aef42005-05-05 15:14:10 -0700512 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
513 if (!cfg_mem)
514 return CS_OUT_OF_RESOURCE;
515
516 tuple = &cfg_mem->tuple;
517 parse = &cfg_mem->parse;
518 cf = &parse->cftable_entry;
519 buf = cfg_mem->buf;
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 link->conf.Attributes |= CONF_ENABLE_SPKR;
522 link->conf.Status = CCSR_AUDIO_ENA;
523 link->irq.Attributes =
524 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
525 link->io.IOAddrLines = 16;
526 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
527 link->io.NumPorts2 = 8;
528
Yum Rayan4638aef42005-05-05 15:14:10 -0700529 tuple->Attributes = tuple->TupleOffset = 0;
530 tuple->TupleData = (cisdata_t *)buf;
531 tuple->TupleDataMax = 255;
532 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Yum Rayan4638aef42005-05-05 15:14:10 -0700534 i = first_tuple(link->handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 /* The Megahertz combo cards have modem-like CIS entries, so
536 we have to explicitly try a bunch of port combinations. */
537 while (i == CS_SUCCESS) {
538 link->conf.ConfigIndex = cf->index;
539 link->io.BasePort2 = cf->io.win[0].base;
540 for (k = 0; k < 0x400; k += 0x10) {
541 if (k & 0x80) continue;
542 link->io.BasePort1 = k ^ 0x300;
543 i = pcmcia_request_io(link->handle, &link->io);
544 if (i == CS_SUCCESS) break;
545 }
546 if (i == CS_SUCCESS) break;
Yum Rayan4638aef42005-05-05 15:14:10 -0700547 i = next_tuple(link->handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 }
549 if (i != CS_SUCCESS)
Yum Rayan4638aef42005-05-05 15:14:10 -0700550 goto free_cfg_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 dev->base_addr = link->io.BasePort1;
552
553 /* Allocate a memory window, for accessing the ISR */
554 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
555 req.Base = req.Size = 0;
556 req.AccessSpeed = 0;
557 i = pcmcia_request_window(&link->handle, &req, &link->win);
558 if (i != CS_SUCCESS)
Yum Rayan4638aef42005-05-05 15:14:10 -0700559 goto free_cfg_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 smc->base = ioremap(req.Base, req.Size);
561 mem.CardOffset = mem.Page = 0;
562 if (smc->manfid == MANFID_MOTOROLA)
563 mem.CardOffset = link->conf.ConfigBase;
564 i = pcmcia_map_mem_page(link->win, &mem);
565
566 if ((i == CS_SUCCESS)
567 && (smc->manfid == MANFID_MEGAHERTZ)
568 && (smc->cardid == PRODID_MEGAHERTZ_EM3288))
569 mhz_3288_power(link);
570
Yum Rayan4638aef42005-05-05 15:14:10 -0700571free_cfg_mem:
572 kfree(cfg_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 return i;
574}
575
576static int mhz_setup(dev_link_t *link)
577{
578 client_handle_t handle = link->handle;
579 struct net_device *dev = link->priv;
Yum Rayan4638aef42005-05-05 15:14:10 -0700580 struct smc_cfg_mem *cfg_mem;
581 tuple_t *tuple;
582 cisparse_t *parse;
583 u_char *buf, *station_addr;
584 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Yum Rayan4638aef42005-05-05 15:14:10 -0700586 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
587 if (!cfg_mem)
588 return -1;
589
590 tuple = &cfg_mem->tuple;
591 parse = &cfg_mem->parse;
592 buf = cfg_mem->buf;
593
594 tuple->Attributes = tuple->TupleOffset = 0;
595 tuple->TupleData = (cisdata_t *)buf;
596 tuple->TupleDataMax = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598 /* Read the station address from the CIS. It is stored as the last
599 (fourth) string in the Version 1 Version/ID tuple. */
Yum Rayan4638aef42005-05-05 15:14:10 -0700600 tuple->DesiredTuple = CISTPL_VERS_1;
601 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {
602 rc = -1;
603 goto free_cfg_mem;
604 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
Yum Rayan4638aef42005-05-05 15:14:10 -0700606 if (next_tuple(handle, tuple, parse) != CS_SUCCESS)
607 first_tuple(handle, tuple, parse);
608 if (parse->version_1.ns > 3) {
609 station_addr = parse->version_1.str + parse->version_1.ofs[3];
610 if (cvt_ascii_address(dev, station_addr) == 0) {
611 rc = 0;
612 goto free_cfg_mem;
613 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 }
615
616 /* Another possibility: for the EM3288, in a special tuple */
Yum Rayan4638aef42005-05-05 15:14:10 -0700617 tuple->DesiredTuple = 0x81;
618 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) {
619 rc = -1;
620 goto free_cfg_mem;
621 }
622 if (pcmcia_get_tuple_data(handle, tuple) != CS_SUCCESS) {
623 rc = -1;
624 goto free_cfg_mem;
625 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 buf[12] = '\0';
Yum Rayan4638aef42005-05-05 15:14:10 -0700627 if (cvt_ascii_address(dev, buf) == 0) {
628 rc = 0;
629 goto free_cfg_mem;
630 }
631 rc = -1;
632free_cfg_mem:
633 kfree(cfg_mem);
634 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635}
636
637/*======================================================================
638
639 Configuration stuff for the Motorola Mariner
640
641 mot_config() writes directly to the Mariner configuration
642 registers because the CIS is just bogus.
643
644======================================================================*/
645
646static void mot_config(dev_link_t *link)
647{
648 struct net_device *dev = link->priv;
649 struct smc_private *smc = netdev_priv(dev);
650 kio_addr_t ioaddr = dev->base_addr;
651 kio_addr_t iouart = link->io.BasePort2;
652
653 /* Set UART base address and force map with COR bit 1 */
654 writeb(iouart & 0xff, smc->base + MOT_UART + CISREG_IOBASE_0);
655 writeb((iouart >> 8) & 0xff, smc->base + MOT_UART + CISREG_IOBASE_1);
656 writeb(MOT_NORMAL, smc->base + MOT_UART + CISREG_COR);
657
658 /* Set SMC base address and force map with COR bit 1 */
659 writeb(ioaddr & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_0);
660 writeb((ioaddr >> 8) & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_1);
661 writeb(MOT_NORMAL, smc->base + MOT_LAN + CISREG_COR);
662
663 /* Wait for things to settle down */
664 mdelay(100);
665}
666
667static int mot_setup(dev_link_t *link)
668{
669 struct net_device *dev = link->priv;
670 kio_addr_t ioaddr = dev->base_addr;
671 int i, wait, loop;
672 u_int addr;
673
674 /* Read Ethernet address from Serial EEPROM */
675
676 for (i = 0; i < 3; i++) {
677 SMC_SELECT_BANK(2);
678 outw(MOT_EEPROM + i, ioaddr + POINTER);
679 SMC_SELECT_BANK(1);
680 outw((CTL_RELOAD | CTL_EE_SELECT), ioaddr + CONTROL);
681
682 for (loop = wait = 0; loop < 200; loop++) {
683 udelay(10);
684 wait = ((CTL_RELOAD | CTL_STORE) & inw(ioaddr + CONTROL));
685 if (wait == 0) break;
686 }
687
688 if (wait)
689 return -1;
690
691 addr = inw(ioaddr + GENERAL);
692 dev->dev_addr[2*i] = addr & 0xff;
693 dev->dev_addr[2*i+1] = (addr >> 8) & 0xff;
694 }
695
696 return 0;
697}
698
699/*====================================================================*/
700
701static int smc_config(dev_link_t *link)
702{
703 struct net_device *dev = link->priv;
Yum Rayan4638aef42005-05-05 15:14:10 -0700704 struct smc_cfg_mem *cfg_mem;
705 tuple_t *tuple;
706 cisparse_t *parse;
707 cistpl_cftable_entry_t *cf;
708 u_char *buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 int i;
710
Yum Rayan4638aef42005-05-05 15:14:10 -0700711 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
712 if (!cfg_mem)
713 return CS_OUT_OF_RESOURCE;
714
715 tuple = &cfg_mem->tuple;
716 parse = &cfg_mem->parse;
717 cf = &parse->cftable_entry;
718 buf = cfg_mem->buf;
719
720 tuple->Attributes = tuple->TupleOffset = 0;
721 tuple->TupleData = (cisdata_t *)buf;
722 tuple->TupleDataMax = 255;
723 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
725 link->io.NumPorts1 = 16;
Yum Rayan4638aef42005-05-05 15:14:10 -0700726 i = first_tuple(link->handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 while (i != CS_NO_MORE_ITEMS) {
728 if (i == CS_SUCCESS) {
729 link->conf.ConfigIndex = cf->index;
730 link->io.BasePort1 = cf->io.win[0].base;
731 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
732 i = pcmcia_request_io(link->handle, &link->io);
733 if (i == CS_SUCCESS) break;
734 }
Yum Rayan4638aef42005-05-05 15:14:10 -0700735 i = next_tuple(link->handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 }
737 if (i == CS_SUCCESS)
738 dev->base_addr = link->io.BasePort1;
Yum Rayan4638aef42005-05-05 15:14:10 -0700739
740 kfree(cfg_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 return i;
742}
743
744static int smc_setup(dev_link_t *link)
745{
746 client_handle_t handle = link->handle;
747 struct net_device *dev = link->priv;
Yum Rayan4638aef42005-05-05 15:14:10 -0700748 struct smc_cfg_mem *cfg_mem;
749 tuple_t *tuple;
750 cisparse_t *parse;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 cistpl_lan_node_id_t *node_id;
Yum Rayan4638aef42005-05-05 15:14:10 -0700752 u_char *buf, *station_addr;
753 int i, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Yum Rayan4638aef42005-05-05 15:14:10 -0700755 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
756 if (!cfg_mem)
757 return CS_OUT_OF_RESOURCE;
758
759 tuple = &cfg_mem->tuple;
760 parse = &cfg_mem->parse;
761 buf = cfg_mem->buf;
762
763 tuple->Attributes = tuple->TupleOffset = 0;
764 tuple->TupleData = (cisdata_t *)buf;
765 tuple->TupleDataMax = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
767 /* Check for a LAN function extension tuple */
Yum Rayan4638aef42005-05-05 15:14:10 -0700768 tuple->DesiredTuple = CISTPL_FUNCE;
769 i = first_tuple(handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 while (i == CS_SUCCESS) {
Yum Rayan4638aef42005-05-05 15:14:10 -0700771 if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 break;
Yum Rayan4638aef42005-05-05 15:14:10 -0700773 i = next_tuple(handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 }
775 if (i == CS_SUCCESS) {
Yum Rayan4638aef42005-05-05 15:14:10 -0700776 node_id = (cistpl_lan_node_id_t *)parse->funce.data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 if (node_id->nb == 6) {
778 for (i = 0; i < 6; i++)
779 dev->dev_addr[i] = node_id->id[i];
Yum Rayan4638aef42005-05-05 15:14:10 -0700780 rc = 0;
781 goto free_cfg_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 }
783 }
784 /* Try the third string in the Version 1 Version/ID tuple. */
Yum Rayan4638aef42005-05-05 15:14:10 -0700785 tuple->DesiredTuple = CISTPL_VERS_1;
786 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {
787 rc = -1;
788 goto free_cfg_mem;
789 }
790 station_addr = parse->version_1.str + parse->version_1.ofs[2];
791 if (cvt_ascii_address(dev, station_addr) == 0) {
792 rc = 0;
793 goto free_cfg_mem;
794 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Yum Rayan4638aef42005-05-05 15:14:10 -0700796 rc = -1;
797free_cfg_mem:
798 kfree(cfg_mem);
799 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800}
801
802/*====================================================================*/
803
804static int osi_config(dev_link_t *link)
805{
806 struct net_device *dev = link->priv;
807 static kio_addr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
808 int i, j;
809
810 link->conf.Attributes |= CONF_ENABLE_SPKR;
811 link->conf.Status = CCSR_AUDIO_ENA;
812 link->irq.Attributes =
813 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
814 link->io.NumPorts1 = 64;
815 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
816 link->io.NumPorts2 = 8;
817 link->io.IOAddrLines = 16;
818
819 /* Enable Hard Decode, LAN, Modem */
820 link->conf.ConfigIndex = 0x23;
821
822 for (i = j = 0; j < 4; j++) {
823 link->io.BasePort2 = com[j];
824 i = pcmcia_request_io(link->handle, &link->io);
825 if (i == CS_SUCCESS) break;
826 }
827 if (i != CS_SUCCESS) {
828 /* Fallback: turn off hard decode */
829 link->conf.ConfigIndex = 0x03;
830 link->io.NumPorts2 = 0;
831 i = pcmcia_request_io(link->handle, &link->io);
832 }
833 dev->base_addr = link->io.BasePort1 + 0x10;
834 return i;
835}
836
837static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid)
838{
839 client_handle_t handle = link->handle;
840 struct net_device *dev = link->priv;
Yum Rayan4638aef42005-05-05 15:14:10 -0700841 struct smc_cfg_mem *cfg_mem;
842 tuple_t *tuple;
843 u_char *buf;
844 int i, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Yum Rayan4638aef42005-05-05 15:14:10 -0700846 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
847 if (!cfg_mem)
848 return -1;
849
850 tuple = &cfg_mem->tuple;
851 buf = cfg_mem->buf;
852
853 tuple->Attributes = TUPLE_RETURN_COMMON;
854 tuple->TupleData = (cisdata_t *)buf;
855 tuple->TupleDataMax = 255;
856 tuple->TupleOffset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
858 /* Read the station address from tuple 0x90, subtuple 0x04 */
Yum Rayan4638aef42005-05-05 15:14:10 -0700859 tuple->DesiredTuple = 0x90;
860 i = pcmcia_get_first_tuple(handle, tuple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 while (i == CS_SUCCESS) {
Yum Rayan4638aef42005-05-05 15:14:10 -0700862 i = pcmcia_get_tuple_data(handle, tuple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 if ((i != CS_SUCCESS) || (buf[0] == 0x04))
864 break;
Yum Rayan4638aef42005-05-05 15:14:10 -0700865 i = pcmcia_get_next_tuple(handle, tuple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 }
Yum Rayan4638aef42005-05-05 15:14:10 -0700867 if (i != CS_SUCCESS) {
868 rc = -1;
869 goto free_cfg_mem;
870 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 for (i = 0; i < 6; i++)
872 dev->dev_addr[i] = buf[i+2];
873
874 if (((manfid == MANFID_OSITECH) &&
875 (cardid == PRODID_OSITECH_SEVEN)) ||
876 ((manfid == MANFID_PSION) &&
877 (cardid == PRODID_PSION_NET100))) {
878 /* Download the Seven of Diamonds firmware */
879 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
880 outb(__Xilinx7OD[i], link->io.BasePort1+2);
881 udelay(50);
882 }
883 } else if (manfid == MANFID_OSITECH) {
884 /* Make sure both functions are powered up */
885 set_bits(0x300, link->io.BasePort1 + OSITECH_AUI_PWR);
886 /* Now, turn on the interrupt for both card functions */
887 set_bits(0x300, link->io.BasePort1 + OSITECH_RESET_ISR);
888 DEBUG(2, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n",
889 inw(link->io.BasePort1 + OSITECH_AUI_PWR),
890 inw(link->io.BasePort1 + OSITECH_RESET_ISR));
891 }
Yum Rayan4638aef42005-05-05 15:14:10 -0700892 rc = 0;
893free_cfg_mem:
894 kfree(cfg_mem);
895 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896}
897
898/*======================================================================
899
900 This verifies that the chip is some SMC91cXX variant, and returns
901 the revision code if successful. Otherwise, it returns -ENODEV.
902
903======================================================================*/
904
905static int check_sig(dev_link_t *link)
906{
907 struct net_device *dev = link->priv;
908 kio_addr_t ioaddr = dev->base_addr;
909 int width;
910 u_short s;
911
912 SMC_SELECT_BANK(1);
913 if (inw(ioaddr + BANK_SELECT) >> 8 != 0x33) {
914 /* Try powering up the chip */
915 outw(0, ioaddr + CONTROL);
916 mdelay(55);
917 }
918
919 /* Try setting bus width */
920 width = (link->io.Attributes1 == IO_DATA_PATH_WIDTH_AUTO);
921 s = inb(ioaddr + CONFIG);
922 if (width)
923 s |= CFG_16BIT;
924 else
925 s &= ~CFG_16BIT;
926 outb(s, ioaddr + CONFIG);
927
928 /* Check Base Address Register to make sure bus width is OK */
929 s = inw(ioaddr + BASE_ADDR);
930 if ((inw(ioaddr + BANK_SELECT) >> 8 == 0x33) &&
931 ((s >> 8) != (s & 0xff))) {
932 SMC_SELECT_BANK(3);
933 s = inw(ioaddr + REVISION);
934 return (s & 0xff);
935 }
936
937 if (width) {
938 event_callback_args_t args;
939 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n");
940 args.client_data = link;
941 smc91c92_event(CS_EVENT_RESET_PHYSICAL, 0, &args);
942 pcmcia_release_io(link->handle, &link->io);
943 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
944 pcmcia_request_io(link->handle, &link->io);
945 smc91c92_event(CS_EVENT_CARD_RESET, 0, &args);
946 return check_sig(link);
947 }
948 return -ENODEV;
949}
950
951/*======================================================================
952
953 smc91c92_config() is scheduled to run after a CARD_INSERTION event
954 is received, to configure the PCMCIA socket, and to make the
955 ethernet device available to the system.
956
957======================================================================*/
958
959#define CS_EXIT_TEST(ret, svc, label) \
960if (ret != CS_SUCCESS) { cs_error(link->handle, svc, ret); goto label; }
961
962static void smc91c92_config(dev_link_t *link)
963{
964 client_handle_t handle = link->handle;
965 struct net_device *dev = link->priv;
966 struct smc_private *smc = netdev_priv(dev);
Yum Rayan4638aef42005-05-05 15:14:10 -0700967 struct smc_cfg_mem *cfg_mem;
968 tuple_t *tuple;
969 cisparse_t *parse;
970 u_char *buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 char *name;
972 int i, j, rev;
973 kio_addr_t ioaddr;
974 u_long mir;
975
976 DEBUG(0, "smc91c92_config(0x%p)\n", link);
977
Yum Rayan4638aef42005-05-05 15:14:10 -0700978 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
979 if (!cfg_mem)
980 goto config_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Yum Rayan4638aef42005-05-05 15:14:10 -0700982 tuple = &cfg_mem->tuple;
983 parse = &cfg_mem->parse;
984 buf = cfg_mem->buf;
985
986 tuple->Attributes = tuple->TupleOffset = 0;
987 tuple->TupleData = (cisdata_t *)buf;
988 tuple->TupleDataMax = 64;
989
990 tuple->DesiredTuple = CISTPL_CONFIG;
991 i = first_tuple(handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 CS_EXIT_TEST(i, ParseTuple, config_failed);
Yum Rayan4638aef42005-05-05 15:14:10 -0700993 link->conf.ConfigBase = parse->config.base;
994 link->conf.Present = parse->config.rmask[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Yum Rayan4638aef42005-05-05 15:14:10 -0700996 tuple->DesiredTuple = CISTPL_MANFID;
997 tuple->Attributes = TUPLE_RETURN_COMMON;
998 if (first_tuple(handle, tuple, parse) == CS_SUCCESS) {
999 smc->manfid = parse->manfid.manf;
1000 smc->cardid = parse->manfid.card;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 }
1002
1003 /* Configure card */
1004 link->state |= DEV_CONFIG;
1005
1006 if ((smc->manfid == MANFID_OSITECH) &&
1007 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1008 i = osi_config(link);
1009 } else if ((smc->manfid == MANFID_MOTOROLA) ||
1010 ((smc->manfid == MANFID_MEGAHERTZ) &&
1011 ((smc->cardid == PRODID_MEGAHERTZ_VARIOUS) ||
1012 (smc->cardid == PRODID_MEGAHERTZ_EM3288)))) {
1013 i = mhz_mfc_config(link);
1014 } else {
1015 i = smc_config(link);
1016 }
1017 CS_EXIT_TEST(i, RequestIO, config_failed);
1018
1019 i = pcmcia_request_irq(link->handle, &link->irq);
1020 CS_EXIT_TEST(i, RequestIRQ, config_failed);
1021 i = pcmcia_request_configuration(link->handle, &link->conf);
1022 CS_EXIT_TEST(i, RequestConfiguration, config_failed);
1023
1024 if (smc->manfid == MANFID_MOTOROLA)
1025 mot_config(link);
1026
1027 dev->irq = link->irq.AssignedIRQ;
1028
1029 if ((if_port >= 0) && (if_port <= 2))
1030 dev->if_port = if_port;
1031 else
1032 printk(KERN_NOTICE "smc91c92_cs: invalid if_port requested\n");
1033
1034 switch (smc->manfid) {
1035 case MANFID_OSITECH:
1036 case MANFID_PSION:
1037 i = osi_setup(link, smc->manfid, smc->cardid); break;
1038 case MANFID_SMC:
1039 case MANFID_NEW_MEDIA:
1040 i = smc_setup(link); break;
1041 case 0x128: /* For broken Megahertz cards */
1042 case MANFID_MEGAHERTZ:
1043 i = mhz_setup(link); break;
1044 case MANFID_MOTOROLA:
1045 default: /* get the hw address from EEPROM */
1046 i = mot_setup(link); break;
1047 }
1048
1049 if (i != 0) {
1050 printk(KERN_NOTICE "smc91c92_cs: Unable to find hardware address.\n");
1051 goto config_undo;
1052 }
1053
1054 smc->duplex = 0;
1055 smc->rx_ovrn = 0;
1056
1057 rev = check_sig(link);
1058 name = "???";
1059 if (rev > 0)
1060 switch (rev >> 4) {
1061 case 3: name = "92"; break;
1062 case 4: name = ((rev & 15) >= 6) ? "96" : "94"; break;
1063 case 5: name = "95"; break;
1064 case 7: name = "100"; break;
1065 case 8: name = "100-FD"; break;
1066 case 9: name = "110"; break;
1067 }
1068
1069 ioaddr = dev->base_addr;
1070 if (rev > 0) {
1071 u_long mcr;
1072 SMC_SELECT_BANK(0);
1073 mir = inw(ioaddr + MEMINFO) & 0xff;
1074 if (mir == 0xff) mir++;
1075 /* Get scale factor for memory size */
1076 mcr = ((rev >> 4) > 3) ? inw(ioaddr + MEMCFG) : 0x0200;
1077 mir *= 128 * (1<<((mcr >> 9) & 7));
1078 SMC_SELECT_BANK(1);
1079 smc->cfg = inw(ioaddr + CONFIG) & ~CFG_AUI_SELECT;
1080 smc->cfg |= CFG_NO_WAIT | CFG_16BIT | CFG_STATIC;
1081 if (smc->manfid == MANFID_OSITECH)
1082 smc->cfg |= CFG_IRQ_SEL_1 | CFG_IRQ_SEL_0;
1083 if ((rev >> 4) >= 7)
1084 smc->cfg |= CFG_MII_SELECT;
1085 } else
1086 mir = 0;
1087
1088 if (smc->cfg & CFG_MII_SELECT) {
1089 SMC_SELECT_BANK(3);
1090
1091 for (i = 0; i < 32; i++) {
1092 j = mdio_read(dev, i, 1);
1093 if ((j != 0) && (j != 0xffff)) break;
1094 }
1095 smc->mii_if.phy_id = (i < 32) ? i : -1;
1096
1097 SMC_SELECT_BANK(0);
1098 }
1099
1100 link->dev = &smc->node;
1101 link->state &= ~DEV_CONFIG_PENDING;
1102 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
1103
1104 if (register_netdev(dev) != 0) {
1105 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n");
1106 link->dev = NULL;
1107 goto config_undo;
1108 }
1109
1110 strcpy(smc->node.dev_name, dev->name);
1111
1112 printk(KERN_INFO "%s: smc91c%s rev %d: io %#3lx, irq %d, "
1113 "hw_addr ", dev->name, name, (rev & 0x0f), dev->base_addr,
1114 dev->irq);
1115 for (i = 0; i < 6; i++)
1116 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
1117
1118 if (rev > 0) {
1119 if (mir & 0x3ff)
1120 printk(KERN_INFO " %lu byte", mir);
1121 else
1122 printk(KERN_INFO " %lu kb", mir>>10);
1123 printk(" buffer, %s xcvr\n", (smc->cfg & CFG_MII_SELECT) ?
1124 "MII" : if_names[dev->if_port]);
1125 }
1126
1127 if (smc->cfg & CFG_MII_SELECT) {
1128 if (smc->mii_if.phy_id != -1) {
1129 DEBUG(0, " MII transceiver at index %d, status %x.\n",
1130 smc->mii_if.phy_id, j);
1131 } else {
1132 printk(KERN_NOTICE " No MII transceivers found!\n");
1133 }
1134 }
Yum Rayan4638aef42005-05-05 15:14:10 -07001135 kfree(cfg_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 return;
1137
1138config_undo:
1139 unregister_netdev(dev);
1140config_failed: /* CS_EXIT_TEST() calls jump to here... */
1141 smc91c92_release(link);
1142 link->state &= ~DEV_CONFIG_PENDING;
Yum Rayan4638aef42005-05-05 15:14:10 -07001143 kfree(cfg_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
1145} /* smc91c92_config */
1146
1147/*======================================================================
1148
1149 After a card is removed, smc91c92_release() will unregister the net
1150 device, and release the PCMCIA configuration. If the device is
1151 still open, this will be postponed until it is closed.
1152
1153======================================================================*/
1154
1155static void smc91c92_release(dev_link_t *link)
1156{
1157
1158 DEBUG(0, "smc91c92_release(0x%p)\n", link);
1159
1160 pcmcia_release_configuration(link->handle);
1161 pcmcia_release_io(link->handle, &link->io);
1162 pcmcia_release_irq(link->handle, &link->irq);
1163 if (link->win) {
1164 struct net_device *dev = link->priv;
1165 struct smc_private *smc = netdev_priv(dev);
1166 iounmap(smc->base);
1167 pcmcia_release_window(link->win);
1168 }
1169
1170 link->state &= ~DEV_CONFIG;
1171}
1172
1173/*======================================================================
1174
1175 The card status event handler. Mostly, this schedules other
1176 stuff to run after an event is received. A CARD_REMOVAL event
1177 also sets some flags to discourage the net drivers from trying
1178 to talk to the card any more.
1179
1180======================================================================*/
1181
1182static int smc91c92_event(event_t event, int priority,
1183 event_callback_args_t *args)
1184{
1185 dev_link_t *link = args->client_data;
1186 struct net_device *dev = link->priv;
1187 struct smc_private *smc = netdev_priv(dev);
1188 int i;
1189
1190 DEBUG(1, "smc91c92_event(0x%06x)\n", event);
1191
1192 switch (event) {
1193 case CS_EVENT_CARD_REMOVAL:
1194 link->state &= ~DEV_PRESENT;
1195 if (link->state & DEV_CONFIG)
1196 netif_device_detach(dev);
1197 break;
1198 case CS_EVENT_CARD_INSERTION:
1199 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1200 smc91c92_config(link);
1201 break;
1202 case CS_EVENT_PM_SUSPEND:
1203 link->state |= DEV_SUSPEND;
1204 /* Fall through... */
1205 case CS_EVENT_RESET_PHYSICAL:
1206 if (link->state & DEV_CONFIG) {
1207 if (link->open)
1208 netif_device_detach(dev);
1209 pcmcia_release_configuration(link->handle);
1210 }
1211 break;
1212 case CS_EVENT_PM_RESUME:
1213 link->state &= ~DEV_SUSPEND;
1214 /* Fall through... */
1215 case CS_EVENT_CARD_RESET:
1216 if (link->state & DEV_CONFIG) {
1217 if ((smc->manfid == MANFID_MEGAHERTZ) &&
1218 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
1219 mhz_3288_power(link);
1220 pcmcia_request_configuration(link->handle, &link->conf);
1221 if (smc->manfid == MANFID_MOTOROLA)
1222 mot_config(link);
1223 if ((smc->manfid == MANFID_OSITECH) &&
1224 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1225 /* Power up the card and enable interrupts */
1226 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR);
1227 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR);
1228 }
1229 if (((smc->manfid == MANFID_OSITECH) &&
1230 (smc->cardid == PRODID_OSITECH_SEVEN)) ||
1231 ((smc->manfid == MANFID_PSION) &&
1232 (smc->cardid == PRODID_PSION_NET100))) {
1233 /* Download the Seven of Diamonds firmware */
1234 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
1235 outb(__Xilinx7OD[i], link->io.BasePort1+2);
1236 udelay(50);
1237 }
1238 }
1239 if (link->open) {
1240 smc_reset(dev);
1241 netif_device_attach(dev);
1242 }
1243 }
1244 break;
1245 }
1246 return 0;
1247} /* smc91c92_event */
1248
1249/*======================================================================
1250
1251 MII interface support for SMC91cXX based cards
1252======================================================================*/
1253
1254#define MDIO_SHIFT_CLK 0x04
1255#define MDIO_DATA_OUT 0x01
1256#define MDIO_DIR_WRITE 0x08
1257#define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
1258#define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
1259#define MDIO_DATA_READ 0x02
1260
1261static void mdio_sync(kio_addr_t addr)
1262{
1263 int bits;
1264 for (bits = 0; bits < 32; bits++) {
1265 outb(MDIO_DATA_WRITE1, addr);
1266 outb(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
1267 }
1268}
1269
1270static int mdio_read(struct net_device *dev, int phy_id, int loc)
1271{
1272 kio_addr_t addr = dev->base_addr + MGMT;
1273 u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
1274 int i, retval = 0;
1275
1276 mdio_sync(addr);
1277 for (i = 13; i >= 0; i--) {
1278 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1279 outb(dat, addr);
1280 outb(dat | MDIO_SHIFT_CLK, addr);
1281 }
1282 for (i = 19; i > 0; i--) {
1283 outb(0, addr);
1284 retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
1285 outb(MDIO_SHIFT_CLK, addr);
1286 }
1287 return (retval>>1) & 0xffff;
1288}
1289
1290static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
1291{
1292 kio_addr_t addr = dev->base_addr + MGMT;
1293 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
1294 int i;
1295
1296 mdio_sync(addr);
1297 for (i = 31; i >= 0; i--) {
1298 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1299 outb(dat, addr);
1300 outb(dat | MDIO_SHIFT_CLK, addr);
1301 }
1302 for (i = 1; i >= 0; i--) {
1303 outb(0, addr);
1304 outb(MDIO_SHIFT_CLK, addr);
1305 }
1306}
1307
1308/*======================================================================
1309
1310 The driver core code, most of which should be common with a
1311 non-PCMCIA implementation.
1312
1313======================================================================*/
1314
1315#ifdef PCMCIA_DEBUG
1316static void smc_dump(struct net_device *dev)
1317{
1318 kio_addr_t ioaddr = dev->base_addr;
1319 u_short i, w, save;
1320 save = inw(ioaddr + BANK_SELECT);
1321 for (w = 0; w < 4; w++) {
1322 SMC_SELECT_BANK(w);
1323 printk(KERN_DEBUG "bank %d: ", w);
1324 for (i = 0; i < 14; i += 2)
1325 printk(" %04x", inw(ioaddr + i));
1326 printk("\n");
1327 }
1328 outw(save, ioaddr + BANK_SELECT);
1329}
1330#endif
1331
1332static int smc_open(struct net_device *dev)
1333{
1334 struct smc_private *smc = netdev_priv(dev);
1335 dev_link_t *link = &smc->link;
1336
1337#ifdef PCMCIA_DEBUG
1338 DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n",
1339 dev->name, dev, inw(dev->base_addr + BANK_SELECT));
1340 if (pc_debug > 1) smc_dump(dev);
1341#endif
1342
1343 /* Check that the PCMCIA card is still here. */
1344 if (!DEV_OK(link))
1345 return -ENODEV;
1346 /* Physical device present signature. */
1347 if (check_sig(link) < 0) {
1348 printk("smc91c92_cs: Yikes! Bad chip signature!\n");
1349 return -ENODEV;
1350 }
1351 link->open++;
1352
1353 netif_start_queue(dev);
1354 smc->saved_skb = NULL;
1355 smc->packets_waiting = 0;
1356
1357 smc_reset(dev);
1358 init_timer(&smc->media);
1359 smc->media.function = &media_check;
1360 smc->media.data = (u_long) dev;
1361 smc->media.expires = jiffies + HZ;
1362 add_timer(&smc->media);
1363
1364 return 0;
1365} /* smc_open */
1366
1367/*====================================================================*/
1368
1369static int smc_close(struct net_device *dev)
1370{
1371 struct smc_private *smc = netdev_priv(dev);
1372 dev_link_t *link = &smc->link;
1373 kio_addr_t ioaddr = dev->base_addr;
1374
1375 DEBUG(0, "%s: smc_close(), status %4.4x.\n",
1376 dev->name, inw(ioaddr + BANK_SELECT));
1377
1378 netif_stop_queue(dev);
1379
1380 /* Shut off all interrupts, and turn off the Tx and Rx sections.
1381 Don't bother to check for chip present. */
1382 SMC_SELECT_BANK(2); /* Nominally paranoia, but do no assume... */
1383 outw(0, ioaddr + INTERRUPT);
1384 SMC_SELECT_BANK(0);
1385 mask_bits(0xff00, ioaddr + RCR);
1386 mask_bits(0xff00, ioaddr + TCR);
1387
1388 /* Put the chip into power-down mode. */
1389 SMC_SELECT_BANK(1);
1390 outw(CTL_POWERDOWN, ioaddr + CONTROL );
1391
1392 link->open--;
1393 del_timer_sync(&smc->media);
1394
1395 return 0;
1396} /* smc_close */
1397
1398/*======================================================================
1399
1400 Transfer a packet to the hardware and trigger the packet send.
1401 This may be called at either from either the Tx queue code
1402 or the interrupt handler.
1403
1404======================================================================*/
1405
1406static void smc_hardware_send_packet(struct net_device * dev)
1407{
1408 struct smc_private *smc = netdev_priv(dev);
1409 struct sk_buff *skb = smc->saved_skb;
1410 kio_addr_t ioaddr = dev->base_addr;
1411 u_char packet_no;
1412
1413 if (!skb) {
1414 printk(KERN_ERR "%s: In XMIT with no packet to send.\n", dev->name);
1415 return;
1416 }
1417
1418 /* There should be a packet slot waiting. */
1419 packet_no = inw(ioaddr + PNR_ARR) >> 8;
1420 if (packet_no & 0x80) {
1421 /* If not, there is a hardware problem! Likely an ejected card. */
1422 printk(KERN_WARNING "%s: 91c92 hardware Tx buffer allocation"
1423 " failed, status %#2.2x.\n", dev->name, packet_no);
1424 dev_kfree_skb_irq(skb);
1425 smc->saved_skb = NULL;
1426 netif_start_queue(dev);
1427 return;
1428 }
1429
1430 smc->stats.tx_bytes += skb->len;
1431 /* The card should use the just-allocated buffer. */
1432 outw(packet_no, ioaddr + PNR_ARR);
1433 /* point to the beginning of the packet */
1434 outw(PTR_AUTOINC , ioaddr + POINTER);
1435
1436 /* Send the packet length (+6 for status, length and ctl byte)
1437 and the status word (set to zeros). */
1438 {
1439 u_char *buf = skb->data;
1440 u_int length = skb->len; /* The chip will pad to ethernet min. */
1441
1442 DEBUG(2, "%s: Trying to xmit packet of length %d.\n",
1443 dev->name, length);
1444
1445 /* send the packet length: +6 for status word, length, and ctl */
1446 outw(0, ioaddr + DATA_1);
1447 outw(length + 6, ioaddr + DATA_1);
1448 outsw(ioaddr + DATA_1, buf, length >> 1);
1449
1450 /* The odd last byte, if there is one, goes in the control word. */
1451 outw((length & 1) ? 0x2000 | buf[length-1] : 0, ioaddr + DATA_1);
1452 }
1453
1454 /* Enable the Tx interrupts, both Tx (TxErr) and TxEmpty. */
1455 outw(((IM_TX_INT|IM_TX_EMPTY_INT)<<8) |
1456 (inw(ioaddr + INTERRUPT) & 0xff00),
1457 ioaddr + INTERRUPT);
1458
1459 /* The chip does the rest of the work. */
1460 outw(MC_ENQUEUE , ioaddr + MMU_CMD);
1461
1462 smc->saved_skb = NULL;
1463 dev_kfree_skb_irq(skb);
1464 dev->trans_start = jiffies;
1465 netif_start_queue(dev);
1466 return;
1467}
1468
1469/*====================================================================*/
1470
1471static void smc_tx_timeout(struct net_device *dev)
1472{
1473 struct smc_private *smc = netdev_priv(dev);
1474 kio_addr_t ioaddr = dev->base_addr;
1475
1476 printk(KERN_NOTICE "%s: SMC91c92 transmit timed out, "
1477 "Tx_status %2.2x status %4.4x.\n",
1478 dev->name, inw(ioaddr)&0xff, inw(ioaddr + 2));
1479 smc->stats.tx_errors++;
1480 smc_reset(dev);
1481 dev->trans_start = jiffies;
1482 smc->saved_skb = NULL;
1483 netif_wake_queue(dev);
1484}
1485
1486static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev)
1487{
1488 struct smc_private *smc = netdev_priv(dev);
1489 kio_addr_t ioaddr = dev->base_addr;
1490 u_short num_pages;
1491 short time_out, ir;
1492
1493 netif_stop_queue(dev);
1494
1495 DEBUG(2, "%s: smc_start_xmit(length = %d) called,"
1496 " status %4.4x.\n", dev->name, skb->len, inw(ioaddr + 2));
1497
1498 if (smc->saved_skb) {
1499 /* THIS SHOULD NEVER HAPPEN. */
1500 smc->stats.tx_aborted_errors++;
1501 printk(KERN_DEBUG "%s: Internal error -- sent packet while busy.\n",
1502 dev->name);
1503 return 1;
1504 }
1505 smc->saved_skb = skb;
1506
1507 num_pages = skb->len >> 8;
1508
1509 if (num_pages > 7) {
1510 printk(KERN_ERR "%s: Far too big packet error.\n", dev->name);
1511 dev_kfree_skb (skb);
1512 smc->saved_skb = NULL;
1513 smc->stats.tx_dropped++;
1514 return 0; /* Do not re-queue this packet. */
1515 }
1516 /* A packet is now waiting. */
1517 smc->packets_waiting++;
1518
1519 SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */
1520
1521 /* need MC_RESET to keep the memory consistent. errata? */
1522 if (smc->rx_ovrn) {
1523 outw(MC_RESET, ioaddr + MMU_CMD);
1524 smc->rx_ovrn = 0;
1525 }
1526
1527 /* Allocate the memory; send the packet now if we win. */
1528 outw(MC_ALLOC | num_pages, ioaddr + MMU_CMD);
1529 for (time_out = MEMORY_WAIT_TIME; time_out >= 0; time_out--) {
1530 ir = inw(ioaddr+INTERRUPT);
1531 if (ir & IM_ALLOC_INT) {
1532 /* Acknowledge the interrupt, send the packet. */
1533 outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT);
1534 smc_hardware_send_packet(dev); /* Send the packet now.. */
1535 return 0;
1536 }
1537 }
1538
1539 /* Otherwise defer until the Tx-space-allocated interrupt. */
1540 DEBUG(2, "%s: memory allocation deferred.\n", dev->name);
1541 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT);
1542
1543 return 0;
1544}
1545
1546/*======================================================================
1547
1548 Handle a Tx anomolous event. Entered while in Window 2.
1549
1550======================================================================*/
1551
1552static void smc_tx_err(struct net_device * dev)
1553{
1554 struct smc_private *smc = netdev_priv(dev);
1555 kio_addr_t ioaddr = dev->base_addr;
1556 int saved_packet = inw(ioaddr + PNR_ARR) & 0xff;
1557 int packet_no = inw(ioaddr + FIFO_PORTS) & 0x7f;
1558 int tx_status;
1559
1560 /* select this as the packet to read from */
1561 outw(packet_no, ioaddr + PNR_ARR);
1562
1563 /* read the first word from this packet */
1564 outw(PTR_AUTOINC | PTR_READ | 0, ioaddr + POINTER);
1565
1566 tx_status = inw(ioaddr + DATA_1);
1567
1568 smc->stats.tx_errors++;
1569 if (tx_status & TS_LOSTCAR) smc->stats.tx_carrier_errors++;
1570 if (tx_status & TS_LATCOL) smc->stats.tx_window_errors++;
1571 if (tx_status & TS_16COL) {
1572 smc->stats.tx_aborted_errors++;
1573 smc->tx_err++;
1574 }
1575
1576 if (tx_status & TS_SUCCESS) {
1577 printk(KERN_NOTICE "%s: Successful packet caused error "
1578 "interrupt?\n", dev->name);
1579 }
1580 /* re-enable transmit */
1581 SMC_SELECT_BANK(0);
1582 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1583 SMC_SELECT_BANK(2);
1584
1585 outw(MC_FREEPKT, ioaddr + MMU_CMD); /* Free the packet memory. */
1586
1587 /* one less packet waiting for me */
1588 smc->packets_waiting--;
1589
1590 outw(saved_packet, ioaddr + PNR_ARR);
1591 return;
1592}
1593
1594/*====================================================================*/
1595
1596static void smc_eph_irq(struct net_device *dev)
1597{
1598 struct smc_private *smc = netdev_priv(dev);
1599 kio_addr_t ioaddr = dev->base_addr;
1600 u_short card_stats, ephs;
1601
1602 SMC_SELECT_BANK(0);
1603 ephs = inw(ioaddr + EPH);
1604 DEBUG(2, "%s: Ethernet protocol handler interrupt, status"
1605 " %4.4x.\n", dev->name, ephs);
1606 /* Could be a counter roll-over warning: update stats. */
1607 card_stats = inw(ioaddr + COUNTER);
1608 /* single collisions */
1609 smc->stats.collisions += card_stats & 0xF;
1610 card_stats >>= 4;
1611 /* multiple collisions */
1612 smc->stats.collisions += card_stats & 0xF;
1613#if 0 /* These are for when linux supports these statistics */
1614 card_stats >>= 4; /* deferred */
1615 card_stats >>= 4; /* excess deferred */
1616#endif
1617 /* If we had a transmit error we must re-enable the transmitter. */
1618 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1619
1620 /* Clear a link error interrupt. */
1621 SMC_SELECT_BANK(1);
1622 outw(CTL_AUTO_RELEASE | 0x0000, ioaddr + CONTROL);
1623 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1624 ioaddr + CONTROL);
1625 SMC_SELECT_BANK(2);
1626}
1627
1628/*====================================================================*/
1629
1630static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1631{
1632 struct net_device *dev = dev_id;
1633 struct smc_private *smc = netdev_priv(dev);
1634 kio_addr_t ioaddr;
1635 u_short saved_bank, saved_pointer, mask, status;
1636 unsigned int handled = 1;
1637 char bogus_cnt = INTR_WORK; /* Work we are willing to do. */
1638
1639 if (!netif_device_present(dev))
1640 return IRQ_NONE;
1641
1642 ioaddr = dev->base_addr;
1643
1644 DEBUG(3, "%s: SMC91c92 interrupt %d at %#x.\n", dev->name,
1645 irq, ioaddr);
1646
1647 smc->watchdog = 0;
1648 saved_bank = inw(ioaddr + BANK_SELECT);
1649 if ((saved_bank & 0xff00) != 0x3300) {
1650 /* The device does not exist -- the card could be off-line, or
1651 maybe it has been ejected. */
1652 DEBUG(1, "%s: SMC91c92 interrupt %d for non-existent"
1653 "/ejected device.\n", dev->name, irq);
1654 handled = 0;
1655 goto irq_done;
1656 }
1657
1658 SMC_SELECT_BANK(2);
1659 saved_pointer = inw(ioaddr + POINTER);
1660 mask = inw(ioaddr + INTERRUPT) >> 8;
1661 /* clear all interrupts */
1662 outw(0, ioaddr + INTERRUPT);
1663
1664 do { /* read the status flag, and mask it */
1665 status = inw(ioaddr + INTERRUPT) & 0xff;
1666 DEBUG(3, "%s: Status is %#2.2x (mask %#2.2x).\n", dev->name,
1667 status, mask);
1668 if ((status & mask) == 0) {
1669 if (bogus_cnt == INTR_WORK)
1670 handled = 0;
1671 break;
1672 }
1673 if (status & IM_RCV_INT) {
1674 /* Got a packet(s). */
1675 smc_rx(dev);
1676 }
1677 if (status & IM_TX_INT) {
1678 smc_tx_err(dev);
1679 outw(IM_TX_INT, ioaddr + INTERRUPT);
1680 }
1681 status &= mask;
1682 if (status & IM_TX_EMPTY_INT) {
1683 outw(IM_TX_EMPTY_INT, ioaddr + INTERRUPT);
1684 mask &= ~IM_TX_EMPTY_INT;
1685 smc->stats.tx_packets += smc->packets_waiting;
1686 smc->packets_waiting = 0;
1687 }
1688 if (status & IM_ALLOC_INT) {
1689 /* Clear this interrupt so it doesn't happen again */
1690 mask &= ~IM_ALLOC_INT;
1691
1692 smc_hardware_send_packet(dev);
1693
1694 /* enable xmit interrupts based on this */
1695 mask |= (IM_TX_EMPTY_INT | IM_TX_INT);
1696
1697 /* and let the card send more packets to me */
1698 netif_wake_queue(dev);
1699 }
1700 if (status & IM_RX_OVRN_INT) {
1701 smc->stats.rx_errors++;
1702 smc->stats.rx_fifo_errors++;
1703 if (smc->duplex)
1704 smc->rx_ovrn = 1; /* need MC_RESET outside smc_interrupt */
1705 outw(IM_RX_OVRN_INT, ioaddr + INTERRUPT);
1706 }
1707 if (status & IM_EPH_INT)
1708 smc_eph_irq(dev);
1709 } while (--bogus_cnt);
1710
1711 DEBUG(3, " Restoring saved registers mask %2.2x bank %4.4x"
1712 " pointer %4.4x.\n", mask, saved_bank, saved_pointer);
1713
1714 /* restore state register */
1715 outw((mask<<8), ioaddr + INTERRUPT);
1716 outw(saved_pointer, ioaddr + POINTER);
1717 SMC_SELECT_BANK(saved_bank);
1718
1719 DEBUG(3, "%s: Exiting interrupt IRQ%d.\n", dev->name, irq);
1720
1721irq_done:
1722
1723 if ((smc->manfid == MANFID_OSITECH) &&
1724 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1725 /* Retrigger interrupt if needed */
1726 mask_bits(0x00ff, ioaddr-0x10+OSITECH_RESET_ISR);
1727 set_bits(0x0300, ioaddr-0x10+OSITECH_RESET_ISR);
1728 }
1729 if (smc->manfid == MANFID_MOTOROLA) {
1730 u_char cor;
1731 cor = readb(smc->base + MOT_UART + CISREG_COR);
1732 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_UART + CISREG_COR);
1733 writeb(cor, smc->base + MOT_UART + CISREG_COR);
1734 cor = readb(smc->base + MOT_LAN + CISREG_COR);
1735 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_LAN + CISREG_COR);
1736 writeb(cor, smc->base + MOT_LAN + CISREG_COR);
1737 }
1738#ifdef DOES_NOT_WORK
1739 if (smc->base != NULL) { /* Megahertz MFC's */
1740 readb(smc->base+MEGAHERTZ_ISR);
1741 readb(smc->base+MEGAHERTZ_ISR);
1742 }
1743#endif
1744 return IRQ_RETVAL(handled);
1745}
1746
1747/*====================================================================*/
1748
1749static void smc_rx(struct net_device *dev)
1750{
1751 struct smc_private *smc = netdev_priv(dev);
1752 kio_addr_t ioaddr = dev->base_addr;
1753 int rx_status;
1754 int packet_length; /* Caution: not frame length, rather words
1755 to transfer from the chip. */
1756
1757 /* Assertion: we are in Window 2. */
1758
1759 if (inw(ioaddr + FIFO_PORTS) & FP_RXEMPTY) {
1760 printk(KERN_ERR "%s: smc_rx() with nothing on Rx FIFO.\n",
1761 dev->name);
1762 return;
1763 }
1764
1765 /* Reset the read pointer, and read the status and packet length. */
1766 outw(PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER);
1767 rx_status = inw(ioaddr + DATA_1);
1768 packet_length = inw(ioaddr + DATA_1) & 0x07ff;
1769
1770 DEBUG(2, "%s: Receive status %4.4x length %d.\n",
1771 dev->name, rx_status, packet_length);
1772
1773 if (!(rx_status & RS_ERRORS)) {
1774 /* do stuff to make a new packet */
1775 struct sk_buff *skb;
1776
1777 /* Note: packet_length adds 5 or 6 extra bytes here! */
1778 skb = dev_alloc_skb(packet_length+2);
1779
1780 if (skb == NULL) {
1781 DEBUG(1, "%s: Low memory, packet dropped.\n", dev->name);
1782 smc->stats.rx_dropped++;
1783 outw(MC_RELEASE, ioaddr + MMU_CMD);
1784 return;
1785 }
1786
1787 packet_length -= (rx_status & RS_ODDFRAME ? 5 : 6);
1788 skb_reserve(skb, 2);
1789 insw(ioaddr+DATA_1, skb_put(skb, packet_length),
1790 (packet_length+1)>>1);
1791 skb->protocol = eth_type_trans(skb, dev);
1792
1793 skb->dev = dev;
1794 netif_rx(skb);
1795 dev->last_rx = jiffies;
1796 smc->stats.rx_packets++;
1797 smc->stats.rx_bytes += packet_length;
1798 if (rx_status & RS_MULTICAST)
1799 smc->stats.multicast++;
1800 } else {
1801 /* error ... */
1802 smc->stats.rx_errors++;
1803
1804 if (rx_status & RS_ALGNERR) smc->stats.rx_frame_errors++;
1805 if (rx_status & (RS_TOOSHORT | RS_TOOLONG))
1806 smc->stats.rx_length_errors++;
1807 if (rx_status & RS_BADCRC) smc->stats.rx_crc_errors++;
1808 }
1809 /* Let the MMU free the memory of this packet. */
1810 outw(MC_RELEASE, ioaddr + MMU_CMD);
1811
1812 return;
1813}
1814
1815/*====================================================================*/
1816
1817static struct net_device_stats *smc_get_stats(struct net_device *dev)
1818{
1819 struct smc_private *smc = netdev_priv(dev);
1820 /* Nothing to update - the 91c92 is a pretty primative chip. */
1821 return &smc->stats;
1822}
1823
1824/*======================================================================
1825
1826 Calculate values for the hardware multicast filter hash table.
1827
1828======================================================================*/
1829
1830static void fill_multicast_tbl(int count, struct dev_mc_list *addrs,
1831 u_char *multicast_table)
1832{
1833 struct dev_mc_list *mc_addr;
1834
1835 for (mc_addr = addrs; mc_addr && --count > 0; mc_addr = mc_addr->next) {
1836 u_int position = ether_crc(6, mc_addr->dmi_addr);
1837#ifndef final_version /* Verify multicast address. */
1838 if ((mc_addr->dmi_addr[0] & 1) == 0)
1839 continue;
1840#endif
1841 multicast_table[position >> 29] |= 1 << ((position >> 26) & 7);
1842 }
1843}
1844
1845/*======================================================================
1846
1847 Set the receive mode.
1848
1849 This routine is used by both the protocol level to notify us of
1850 promiscuous/multicast mode changes, and by the open/reset code to
1851 initialize the Rx registers. We always set the multicast list and
1852 leave the receiver running.
1853
1854======================================================================*/
1855
1856static void set_rx_mode(struct net_device *dev)
1857{
1858 kio_addr_t ioaddr = dev->base_addr;
1859 struct smc_private *smc = netdev_priv(dev);
1860 u_int multicast_table[ 2 ] = { 0, };
1861 unsigned long flags;
1862 u_short rx_cfg_setting;
1863
1864 if (dev->flags & IFF_PROMISC) {
1865 printk(KERN_NOTICE "%s: setting Rx mode to promiscuous.\n", dev->name);
1866 rx_cfg_setting = RxStripCRC | RxEnable | RxPromisc | RxAllMulti;
1867 } else if (dev->flags & IFF_ALLMULTI)
1868 rx_cfg_setting = RxStripCRC | RxEnable | RxAllMulti;
1869 else {
1870 if (dev->mc_count) {
1871 fill_multicast_tbl(dev->mc_count, dev->mc_list,
1872 (u_char *)multicast_table);
1873 }
1874 rx_cfg_setting = RxStripCRC | RxEnable;
1875 }
1876
1877 /* Load MC table and Rx setting into the chip without interrupts. */
1878 spin_lock_irqsave(&smc->lock, flags);
1879 SMC_SELECT_BANK(3);
1880 outl(multicast_table[0], ioaddr + MULTICAST0);
1881 outl(multicast_table[1], ioaddr + MULTICAST4);
1882 SMC_SELECT_BANK(0);
1883 outw(rx_cfg_setting, ioaddr + RCR);
1884 SMC_SELECT_BANK(2);
1885 spin_unlock_irqrestore(&smc->lock, flags);
1886
1887 return;
1888}
1889
1890/*======================================================================
1891
1892 Senses when a card's config changes. Here, it's coax or TP.
1893
1894======================================================================*/
1895
1896static int s9k_config(struct net_device *dev, struct ifmap *map)
1897{
1898 struct smc_private *smc = netdev_priv(dev);
1899 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
1900 if (smc->cfg & CFG_MII_SELECT)
1901 return -EOPNOTSUPP;
1902 else if (map->port > 2)
1903 return -EINVAL;
1904 dev->if_port = map->port;
1905 printk(KERN_INFO "%s: switched to %s port\n",
1906 dev->name, if_names[dev->if_port]);
1907 smc_reset(dev);
1908 }
1909 return 0;
1910}
1911
1912/*======================================================================
1913
1914 Reset the chip, reloading every register that might be corrupted.
1915
1916======================================================================*/
1917
1918/*
1919 Set transceiver type, perhaps to something other than what the user
1920 specified in dev->if_port.
1921*/
1922static void smc_set_xcvr(struct net_device *dev, int if_port)
1923{
1924 struct smc_private *smc = netdev_priv(dev);
1925 kio_addr_t ioaddr = dev->base_addr;
1926 u_short saved_bank;
1927
1928 saved_bank = inw(ioaddr + BANK_SELECT);
1929 SMC_SELECT_BANK(1);
1930 if (if_port == 2) {
1931 outw(smc->cfg | CFG_AUI_SELECT, ioaddr + CONFIG);
1932 if ((smc->manfid == MANFID_OSITECH) &&
1933 (smc->cardid != PRODID_OSITECH_SEVEN))
1934 set_bits(OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1935 smc->media_status = ((dev->if_port == 0) ? 0x0001 : 0x0002);
1936 } else {
1937 outw(smc->cfg, ioaddr + CONFIG);
1938 if ((smc->manfid == MANFID_OSITECH) &&
1939 (smc->cardid != PRODID_OSITECH_SEVEN))
1940 mask_bits(~OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1941 smc->media_status = ((dev->if_port == 0) ? 0x0012 : 0x4001);
1942 }
1943 SMC_SELECT_BANK(saved_bank);
1944}
1945
1946static void smc_reset(struct net_device *dev)
1947{
1948 kio_addr_t ioaddr = dev->base_addr;
1949 struct smc_private *smc = netdev_priv(dev);
1950 int i;
1951
1952 DEBUG(0, "%s: smc91c92 reset called.\n", dev->name);
1953
1954 /* The first interaction must be a write to bring the chip out
1955 of sleep mode. */
1956 SMC_SELECT_BANK(0);
1957 /* Reset the chip. */
1958 outw(RCR_SOFTRESET, ioaddr + RCR);
1959 udelay(10);
1960
1961 /* Clear the transmit and receive configuration registers. */
1962 outw(RCR_CLEAR, ioaddr + RCR);
1963 outw(TCR_CLEAR, ioaddr + TCR);
1964
1965 /* Set the Window 1 control, configuration and station addr registers.
1966 No point in writing the I/O base register ;-> */
1967 SMC_SELECT_BANK(1);
1968 /* Automatically release succesfully transmitted packets,
1969 Accept link errors, counter and Tx error interrupts. */
1970 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1971 ioaddr + CONTROL);
1972 smc_set_xcvr(dev, dev->if_port);
1973 if ((smc->manfid == MANFID_OSITECH) &&
1974 (smc->cardid != PRODID_OSITECH_SEVEN))
1975 outw((dev->if_port == 2 ? OSI_AUI_PWR : 0) |
1976 (inw(ioaddr-0x10+OSITECH_AUI_PWR) & 0xff00),
1977 ioaddr - 0x10 + OSITECH_AUI_PWR);
1978
1979 /* Fill in the physical address. The databook is wrong about the order! */
1980 for (i = 0; i < 6; i += 2)
1981 outw((dev->dev_addr[i+1]<<8)+dev->dev_addr[i],
1982 ioaddr + ADDR0 + i);
1983
1984 /* Reset the MMU */
1985 SMC_SELECT_BANK(2);
1986 outw(MC_RESET, ioaddr + MMU_CMD);
1987 outw(0, ioaddr + INTERRUPT);
1988
1989 /* Re-enable the chip. */
1990 SMC_SELECT_BANK(0);
1991 outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) |
1992 TCR_ENABLE | TCR_PAD_EN | smc->duplex, ioaddr + TCR);
1993 set_rx_mode(dev);
1994
1995 if (smc->cfg & CFG_MII_SELECT) {
1996 SMC_SELECT_BANK(3);
1997
1998 /* Reset MII */
1999 mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000);
2000
2001 /* Advertise 100F, 100H, 10F, 10H */
2002 mdio_write(dev, smc->mii_if.phy_id, 4, 0x01e1);
2003
2004 /* Restart MII autonegotiation */
2005 mdio_write(dev, smc->mii_if.phy_id, 0, 0x0000);
2006 mdio_write(dev, smc->mii_if.phy_id, 0, 0x1200);
2007 }
2008
2009 /* Enable interrupts. */
2010 SMC_SELECT_BANK(2);
2011 outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,
2012 ioaddr + INTERRUPT);
2013}
2014
2015/*======================================================================
2016
2017 Media selection timer routine
2018
2019======================================================================*/
2020
2021static void media_check(u_long arg)
2022{
2023 struct net_device *dev = (struct net_device *) arg;
2024 struct smc_private *smc = netdev_priv(dev);
2025 kio_addr_t ioaddr = dev->base_addr;
2026 u_short i, media, saved_bank;
2027 u_short link;
2028
2029 saved_bank = inw(ioaddr + BANK_SELECT);
2030
2031 if (!netif_device_present(dev))
2032 goto reschedule;
2033
2034 SMC_SELECT_BANK(2);
2035
2036 /* need MC_RESET to keep the memory consistent. errata? */
2037 if (smc->rx_ovrn) {
2038 outw(MC_RESET, ioaddr + MMU_CMD);
2039 smc->rx_ovrn = 0;
2040 }
2041 i = inw(ioaddr + INTERRUPT);
2042 SMC_SELECT_BANK(0);
2043 media = inw(ioaddr + EPH) & EPH_LINK_OK;
2044 SMC_SELECT_BANK(1);
2045 media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1;
2046
2047 /* Check for pending interrupt with watchdog flag set: with
2048 this, we can limp along even if the interrupt is blocked */
2049 if (smc->watchdog++ && ((i>>8) & i)) {
2050 if (!smc->fast_poll)
2051 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
2052 smc_interrupt(dev->irq, smc, NULL);
2053 smc->fast_poll = HZ;
2054 }
2055 if (smc->fast_poll) {
2056 smc->fast_poll--;
2057 smc->media.expires = jiffies + HZ/100;
2058 add_timer(&smc->media);
2059 SMC_SELECT_BANK(saved_bank);
2060 return;
2061 }
2062
2063 if (smc->cfg & CFG_MII_SELECT) {
2064 if (smc->mii_if.phy_id < 0)
2065 goto reschedule;
2066
2067 SMC_SELECT_BANK(3);
2068 link = mdio_read(dev, smc->mii_if.phy_id, 1);
2069 if (!link || (link == 0xffff)) {
2070 printk(KERN_INFO "%s: MII is missing!\n", dev->name);
2071 smc->mii_if.phy_id = -1;
2072 goto reschedule;
2073 }
2074
2075 link &= 0x0004;
2076 if (link != smc->link_status) {
2077 u_short p = mdio_read(dev, smc->mii_if.phy_id, 5);
2078 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2079 (link) ? "found" : "lost");
2080 smc->duplex = (((p & 0x0100) || ((p & 0x1c0) == 0x40))
2081 ? TCR_FDUPLX : 0);
2082 if (link) {
2083 printk(KERN_INFO "%s: autonegotiation complete: "
2084 "%sbaseT-%cD selected\n", dev->name,
2085 ((p & 0x0180) ? "100" : "10"),
2086 (smc->duplex ? 'F' : 'H'));
2087 }
2088 SMC_SELECT_BANK(0);
2089 outw(inw(ioaddr + TCR) | smc->duplex, ioaddr + TCR);
2090 smc->link_status = link;
2091 }
2092 goto reschedule;
2093 }
2094
2095 /* Ignore collisions unless we've had no rx's recently */
Marcelo Feitoza Parisi4851d3a2005-07-15 10:00:41 -07002096 if (time_after(jiffies, dev->last_rx + HZ)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 if (smc->tx_err || (smc->media_status & EPH_16COL))
2098 media |= EPH_16COL;
2099 }
2100 smc->tx_err = 0;
2101
2102 if (media != smc->media_status) {
2103 if ((media & smc->media_status & 1) &&
2104 ((smc->media_status ^ media) & EPH_LINK_OK))
2105 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2106 (smc->media_status & EPH_LINK_OK ? "lost" : "found"));
2107 else if ((media & smc->media_status & 2) &&
2108 ((smc->media_status ^ media) & EPH_16COL))
2109 printk(KERN_INFO "%s: coax cable %s\n", dev->name,
2110 (media & EPH_16COL ? "problem" : "ok"));
2111 if (dev->if_port == 0) {
2112 if (media & 1) {
2113 if (media & EPH_LINK_OK)
2114 printk(KERN_INFO "%s: flipped to 10baseT\n",
2115 dev->name);
2116 else
2117 smc_set_xcvr(dev, 2);
2118 } else {
2119 if (media & EPH_16COL)
2120 smc_set_xcvr(dev, 1);
2121 else
2122 printk(KERN_INFO "%s: flipped to 10base2\n",
2123 dev->name);
2124 }
2125 }
2126 smc->media_status = media;
2127 }
2128
2129reschedule:
2130 smc->media.expires = jiffies + HZ;
2131 add_timer(&smc->media);
2132 SMC_SELECT_BANK(saved_bank);
2133}
2134
2135static int smc_link_ok(struct net_device *dev)
2136{
2137 kio_addr_t ioaddr = dev->base_addr;
2138 struct smc_private *smc = netdev_priv(dev);
2139
2140 if (smc->cfg & CFG_MII_SELECT) {
2141 return mii_link_ok(&smc->mii_if);
2142 } else {
2143 SMC_SELECT_BANK(0);
2144 return inw(ioaddr + EPH) & EPH_LINK_OK;
2145 }
2146}
2147
2148static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2149{
2150 u16 tmp;
2151 kio_addr_t ioaddr = dev->base_addr;
2152
2153 ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |
2154 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);
2155
2156 SMC_SELECT_BANK(1);
2157 tmp = inw(ioaddr + CONFIG);
2158 ecmd->port = (tmp & CFG_AUI_SELECT) ? PORT_AUI : PORT_TP;
2159 ecmd->transceiver = XCVR_INTERNAL;
2160 ecmd->speed = SPEED_10;
2161 ecmd->phy_address = ioaddr + MGMT;
2162
2163 SMC_SELECT_BANK(0);
2164 tmp = inw(ioaddr + TCR);
2165 ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF;
2166
2167 return 0;
2168}
2169
2170static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2171{
2172 u16 tmp;
2173 kio_addr_t ioaddr = dev->base_addr;
2174
2175 if (ecmd->speed != SPEED_10)
2176 return -EINVAL;
2177 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
2178 return -EINVAL;
2179 if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI)
2180 return -EINVAL;
2181 if (ecmd->transceiver != XCVR_INTERNAL)
2182 return -EINVAL;
2183
2184 if (ecmd->port == PORT_AUI)
2185 smc_set_xcvr(dev, 1);
2186 else
2187 smc_set_xcvr(dev, 0);
2188
2189 SMC_SELECT_BANK(0);
2190 tmp = inw(ioaddr + TCR);
2191 if (ecmd->duplex == DUPLEX_FULL)
2192 tmp |= TCR_FDUPLX;
2193 else
2194 tmp &= ~TCR_FDUPLX;
2195 outw(tmp, ioaddr + TCR);
2196
2197 return 0;
2198}
2199
2200static int check_if_running(struct net_device *dev)
2201{
2202 if (!netif_running(dev))
2203 return -EINVAL;
2204 return 0;
2205}
2206
2207static void smc_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2208{
2209 strcpy(info->driver, DRV_NAME);
2210 strcpy(info->version, DRV_VERSION);
2211}
2212
2213static int smc_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2214{
2215 struct smc_private *smc = netdev_priv(dev);
2216 kio_addr_t ioaddr = dev->base_addr;
2217 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2218 int ret;
2219
2220 SMC_SELECT_BANK(3);
2221 spin_lock_irq(&smc->lock);
2222 if (smc->cfg & CFG_MII_SELECT)
2223 ret = mii_ethtool_gset(&smc->mii_if, ecmd);
2224 else
2225 ret = smc_netdev_get_ecmd(dev, ecmd);
2226 spin_unlock_irq(&smc->lock);
2227 SMC_SELECT_BANK(saved_bank);
2228 return ret;
2229}
2230
2231static int smc_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2232{
2233 struct smc_private *smc = netdev_priv(dev);
2234 kio_addr_t ioaddr = dev->base_addr;
2235 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2236 int ret;
2237
2238 SMC_SELECT_BANK(3);
2239 spin_lock_irq(&smc->lock);
2240 if (smc->cfg & CFG_MII_SELECT)
2241 ret = mii_ethtool_sset(&smc->mii_if, ecmd);
2242 else
2243 ret = smc_netdev_set_ecmd(dev, ecmd);
2244 spin_unlock_irq(&smc->lock);
2245 SMC_SELECT_BANK(saved_bank);
2246 return ret;
2247}
2248
2249static u32 smc_get_link(struct net_device *dev)
2250{
2251 struct smc_private *smc = netdev_priv(dev);
2252 kio_addr_t ioaddr = dev->base_addr;
2253 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2254 u32 ret;
2255
2256 SMC_SELECT_BANK(3);
2257 spin_lock_irq(&smc->lock);
2258 ret = smc_link_ok(dev);
2259 spin_unlock_irq(&smc->lock);
2260 SMC_SELECT_BANK(saved_bank);
2261 return ret;
2262}
2263
2264#ifdef PCMCIA_DEBUG
2265static u32 smc_get_msglevel(struct net_device *dev)
2266{
2267 return pc_debug;
2268}
2269
2270static void smc_set_msglevel(struct net_device *dev, u32 val)
2271{
2272 pc_debug = val;
2273}
2274#endif
2275
2276static int smc_nway_reset(struct net_device *dev)
2277{
2278 struct smc_private *smc = netdev_priv(dev);
2279 if (smc->cfg & CFG_MII_SELECT) {
2280 kio_addr_t ioaddr = dev->base_addr;
2281 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2282 int res;
2283
2284 SMC_SELECT_BANK(3);
2285 res = mii_nway_restart(&smc->mii_if);
2286 SMC_SELECT_BANK(saved_bank);
2287
2288 return res;
2289 } else
2290 return -EOPNOTSUPP;
2291}
2292
2293static struct ethtool_ops ethtool_ops = {
2294 .begin = check_if_running,
2295 .get_drvinfo = smc_get_drvinfo,
2296 .get_settings = smc_get_settings,
2297 .set_settings = smc_set_settings,
2298 .get_link = smc_get_link,
2299#ifdef PCMCIA_DEBUG
2300 .get_msglevel = smc_get_msglevel,
2301 .set_msglevel = smc_set_msglevel,
2302#endif
2303 .nway_reset = smc_nway_reset,
2304};
2305
2306static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
2307{
2308 struct smc_private *smc = netdev_priv(dev);
2309 struct mii_ioctl_data *mii = if_mii(rq);
2310 int rc = 0;
2311 u16 saved_bank;
2312 kio_addr_t ioaddr = dev->base_addr;
2313
2314 if (!netif_running(dev))
2315 return -EINVAL;
2316
2317 spin_lock_irq(&smc->lock);
2318 saved_bank = inw(ioaddr + BANK_SELECT);
2319 SMC_SELECT_BANK(3);
2320 rc = generic_mii_ioctl(&smc->mii_if, mii, cmd, NULL);
2321 SMC_SELECT_BANK(saved_bank);
2322 spin_unlock_irq(&smc->lock);
2323 return rc;
2324}
2325
Dominik Brodowski5c672222005-06-27 16:28:27 -07002326static struct pcmcia_device_id smc91c92_ids[] = {
2327 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0109, 0x0501),
2328 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0140, 0x000a),
2329 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63),
2330 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63),
2331 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef),
2332 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
2333 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
2334 PCMCIA_PFC_DEVICE_PROD_ID12(0, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
2335 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2336 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2337 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x016c, 0x0020),
2338 PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0023),
2339 PCMCIA_DEVICE_PROD_ID123("BASICS by New Media Corporation", "Ethernet", "SMC91C94", 0x23c78a9d, 0x00b2e941, 0xcef397fb),
2340 PCMCIA_DEVICE_PROD_ID12("ARGOSY", "Fast Ethernet PCCard", 0x78f308dc, 0xdcea68bc),
2341 PCMCIA_DEVICE_PROD_ID12("dit Co., Ltd.", "PC Card-10/100BTX", 0xe59365c8, 0x6a2161d1),
2342 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L100C", 0x6a26d1cf, 0xc16ce9c5),
2343 PCMCIA_DEVICE_PROD_ID12("Farallon", "Farallon Enet", 0x58d93fc4, 0x244734e9),
2344 PCMCIA_DEVICE_PROD_ID12("Megahertz", "CC10BT/2", 0x33234748, 0x3c95b953),
2345 PCMCIA_DEVICE_PROD_ID12("MELCO/SMC", "LPC-TX", 0xa2cd8e6d, 0x42da662a),
2346 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2347 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2348 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast Ethernet PCCard", 0x281f1c5d, 0xdcea68bc),
2349 PCMCIA_DEVICE_PROD_ID12("Psion", "10Mb Ethernet", 0x4ef00b21, 0x844be9e9),
2350 PCMCIA_DEVICE_PROD_ID12("SMC", "EtherEZ Ethernet 8020", 0xc4f8b18b, 0x4a0eeb2d),
2351 /* These conflict with other cards! */
2352 /* PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0100), */
2353 /* PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab), */
2354 PCMCIA_DEVICE_NULL,
2355};
2356MODULE_DEVICE_TABLE(pcmcia, smc91c92_ids);
2357
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358static struct pcmcia_driver smc91c92_cs_driver = {
2359 .owner = THIS_MODULE,
2360 .drv = {
2361 .name = "smc91c92_cs",
2362 },
2363 .attach = smc91c92_attach,
Dominik Brodowski1e212f32005-07-07 17:59:00 -07002364 .event = smc91c92_event,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 .detach = smc91c92_detach,
Dominik Brodowski5c672222005-06-27 16:28:27 -07002366 .id_table = smc91c92_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367};
2368
2369static int __init init_smc91c92_cs(void)
2370{
2371 return pcmcia_register_driver(&smc91c92_cs_driver);
2372}
2373
2374static void __exit exit_smc91c92_cs(void)
2375{
2376 pcmcia_unregister_driver(&smc91c92_cs_driver);
2377 BUG_ON(dev_list != NULL);
2378}
2379
2380module_init(init_smc91c92_cs);
2381module_exit(exit_smc91c92_cs);