blob: b46b7e1483904c996cf4106f5685c73d0f66d730 [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>
Dominik Brodowski50db3fd2006-01-15 10:05:19 +010052#include <pcmcia/ss.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#include <asm/io.h>
55#include <asm/system.h>
56#include <asm/uaccess.h>
57
58/* Ositech Seven of Diamonds firmware */
59#include "ositech.h"
60
61/*====================================================================*/
62
Arjan van de Venf71e1302006-03-03 21:33:57 -050063static const char *if_names[] = { "auto", "10baseT", "10base2"};
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65/* Module parameters */
66
67MODULE_DESCRIPTION("SMC 91c92 series PCMCIA ethernet driver");
68MODULE_LICENSE("GPL");
69
70#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
71
72/*
73 Transceiver/media type.
74 0 = auto
75 1 = 10baseT (and autoselect if #define AUTOSELECT),
76 2 = AUI/10base2,
77*/
78INT_MODULE_PARM(if_port, 0);
79
80#ifdef PCMCIA_DEBUG
81INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
82static const char *version =
83"smc91c92_cs.c 0.09 1996/8/4 Donald Becker, becker@scyld.com.\n";
84#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
85#else
86#define DEBUG(n, args...)
87#endif
88
89#define DRV_NAME "smc91c92_cs"
90#define DRV_VERSION "1.122"
91
92/*====================================================================*/
93
94/* Operational parameter that usually are not changed. */
95
96/* Time in jiffies before concluding Tx hung */
97#define TX_TIMEOUT ((400*HZ)/1000)
98
99/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
100#define INTR_WORK 4
101
102/* Times to check the check the chip before concluding that it doesn't
103 currently have room for another Tx packet. */
104#define MEMORY_WAIT_TIME 8
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106struct smc_private {
107 dev_link_t link;
108 spinlock_t lock;
109 u_short manfid;
110 u_short cardid;
111 struct net_device_stats stats;
112 dev_node_t node;
113 struct sk_buff *saved_skb;
114 int packets_waiting;
115 void __iomem *base;
116 u_short cfg;
117 struct timer_list media;
118 int watchdog, tx_err;
119 u_short media_status;
120 u_short fast_poll;
121 u_short link_status;
122 struct mii_if_info mii_if;
123 int duplex;
124 int rx_ovrn;
125};
126
Yum Rayan4638aef42005-05-05 15:14:10 -0700127struct smc_cfg_mem {
128 tuple_t tuple;
129 cisparse_t parse;
130 u_char buf[255];
131};
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133/* Special definitions for Megahertz multifunction cards */
134#define MEGAHERTZ_ISR 0x0380
135
136/* Special function registers for Motorola Mariner */
137#define MOT_LAN 0x0000
138#define MOT_UART 0x0020
139#define MOT_EEPROM 0x20
140
141#define MOT_NORMAL \
142(COR_LEVEL_REQ | COR_FUNC_ENA | COR_ADDR_DECODE | COR_IREQ_ENA)
143
144/* Special function registers for Ositech cards */
145#define OSITECH_AUI_CTL 0x0c
146#define OSITECH_PWRDOWN 0x0d
147#define OSITECH_RESET 0x0e
148#define OSITECH_ISR 0x0f
149#define OSITECH_AUI_PWR 0x0c
150#define OSITECH_RESET_ISR 0x0e
151
152#define OSI_AUI_PWR 0x40
153#define OSI_LAN_PWRDOWN 0x02
154#define OSI_MODEM_PWRDOWN 0x01
155#define OSI_LAN_RESET 0x02
156#define OSI_MODEM_RESET 0x01
157
158/* Symbolic constants for the SMC91c9* series chips, from Erik Stahlman. */
159#define BANK_SELECT 14 /* Window select register. */
160#define SMC_SELECT_BANK(x) { outw(x, ioaddr + BANK_SELECT); }
161
162/* Bank 0 registers. */
163#define TCR 0 /* transmit control register */
164#define TCR_CLEAR 0 /* do NOTHING */
165#define TCR_ENABLE 0x0001 /* if this is 1, we can transmit */
166#define TCR_PAD_EN 0x0080 /* pads short packets to 64 bytes */
167#define TCR_MONCSN 0x0400 /* Monitor Carrier. */
168#define TCR_FDUPLX 0x0800 /* Full duplex mode. */
169#define TCR_NORMAL TCR_ENABLE | TCR_PAD_EN
170
171#define EPH 2 /* Ethernet Protocol Handler report. */
172#define EPH_TX_SUC 0x0001
173#define EPH_SNGLCOL 0x0002
174#define EPH_MULCOL 0x0004
175#define EPH_LTX_MULT 0x0008
176#define EPH_16COL 0x0010
177#define EPH_SQET 0x0020
178#define EPH_LTX_BRD 0x0040
179#define EPH_TX_DEFR 0x0080
180#define EPH_LAT_COL 0x0200
181#define EPH_LOST_CAR 0x0400
182#define EPH_EXC_DEF 0x0800
183#define EPH_CTR_ROL 0x1000
184#define EPH_RX_OVRN 0x2000
185#define EPH_LINK_OK 0x4000
186#define EPH_TX_UNRN 0x8000
187#define MEMINFO 8 /* Memory Information Register */
188#define MEMCFG 10 /* Memory Configuration Register */
189
190/* Bank 1 registers. */
191#define CONFIG 0
192#define CFG_MII_SELECT 0x8000 /* 91C100 only */
193#define CFG_NO_WAIT 0x1000
194#define CFG_FULL_STEP 0x0400
195#define CFG_SET_SQLCH 0x0200
196#define CFG_AUI_SELECT 0x0100
197#define CFG_16BIT 0x0080
198#define CFG_DIS_LINK 0x0040
199#define CFG_STATIC 0x0030
200#define CFG_IRQ_SEL_1 0x0004
201#define CFG_IRQ_SEL_0 0x0002
202#define BASE_ADDR 2
203#define ADDR0 4
204#define GENERAL 10
205#define CONTROL 12
206#define CTL_STORE 0x0001
207#define CTL_RELOAD 0x0002
208#define CTL_EE_SELECT 0x0004
209#define CTL_TE_ENABLE 0x0020
210#define CTL_CR_ENABLE 0x0040
211#define CTL_LE_ENABLE 0x0080
212#define CTL_AUTO_RELEASE 0x0800
213#define CTL_POWERDOWN 0x2000
214
215/* Bank 2 registers. */
216#define MMU_CMD 0
217#define MC_ALLOC 0x20 /* or with number of 256 byte packets */
218#define MC_RESET 0x40
219#define MC_RELEASE 0x80 /* remove and release the current rx packet */
220#define MC_FREEPKT 0xA0 /* Release packet in PNR register */
221#define MC_ENQUEUE 0xC0 /* Enqueue the packet for transmit */
222#define PNR_ARR 2
223#define FIFO_PORTS 4
224#define FP_RXEMPTY 0x8000
225#define POINTER 6
226#define PTR_AUTO_INC 0x0040
227#define PTR_READ 0x2000
228#define PTR_AUTOINC 0x4000
229#define PTR_RCV 0x8000
230#define DATA_1 8
231#define INTERRUPT 12
232#define IM_RCV_INT 0x1
233#define IM_TX_INT 0x2
234#define IM_TX_EMPTY_INT 0x4
235#define IM_ALLOC_INT 0x8
236#define IM_RX_OVRN_INT 0x10
237#define IM_EPH_INT 0x20
238
239#define RCR 4
240enum RxCfg { RxAllMulti = 0x0004, RxPromisc = 0x0002,
241 RxEnable = 0x0100, RxStripCRC = 0x0200};
242#define RCR_SOFTRESET 0x8000 /* resets the chip */
243#define RCR_STRIP_CRC 0x200 /* strips CRC */
244#define RCR_ENABLE 0x100 /* IFF this is set, we can receive packets */
245#define RCR_ALMUL 0x4 /* receive all multicast packets */
246#define RCR_PROMISC 0x2 /* enable promiscuous mode */
247
248/* the normal settings for the RCR register : */
249#define RCR_NORMAL (RCR_STRIP_CRC | RCR_ENABLE)
250#define RCR_CLEAR 0x0 /* set it to a base state */
251#define COUNTER 6
252
253/* BANK 3 -- not the same values as in smc9194! */
254#define MULTICAST0 0
255#define MULTICAST2 2
256#define MULTICAST4 4
257#define MULTICAST6 6
258#define MGMT 8
259#define REVISION 0x0a
260
261/* Transmit status bits. */
262#define TS_SUCCESS 0x0001
263#define TS_16COL 0x0010
264#define TS_LATCOL 0x0200
265#define TS_LOSTCAR 0x0400
266
267/* Receive status bits. */
268#define RS_ALGNERR 0x8000
269#define RS_BADCRC 0x2000
270#define RS_ODDFRAME 0x1000
271#define RS_TOOLONG 0x0800
272#define RS_TOOSHORT 0x0400
273#define RS_MULTICAST 0x0001
274#define RS_ERRORS (RS_ALGNERR | RS_BADCRC | RS_TOOLONG | RS_TOOSHORT)
275
276#define set_bits(v, p) outw(inw(p)|(v), (p))
277#define mask_bits(v, p) outw(inw(p)&(v), (p))
278
279/*====================================================================*/
280
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100281static void smc91c92_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282static void smc91c92_config(dev_link_t *link);
283static void smc91c92_release(dev_link_t *link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285static int smc_open(struct net_device *dev);
286static int smc_close(struct net_device *dev);
287static int smc_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
288static void smc_tx_timeout(struct net_device *dev);
289static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev);
290static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
291static void smc_rx(struct net_device *dev);
292static struct net_device_stats *smc_get_stats(struct net_device *dev);
293static void set_rx_mode(struct net_device *dev);
294static int s9k_config(struct net_device *dev, struct ifmap *map);
295static void smc_set_xcvr(struct net_device *dev, int if_port);
296static void smc_reset(struct net_device *dev);
297static void media_check(u_long arg);
298static void mdio_sync(kio_addr_t addr);
299static int mdio_read(struct net_device *dev, int phy_id, int loc);
300static void mdio_write(struct net_device *dev, int phy_id, int loc, int value);
301static int smc_link_ok(struct net_device *dev);
302static struct ethtool_ops ethtool_ops;
303
304/*======================================================================
305
306 smc91c92_attach() creates an "instance" of the driver, allocating
307 local data structures for one device. The device is registered
308 with Card Services.
309
310======================================================================*/
311
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100312static int smc91c92_attach(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 struct smc_private *smc;
315 dev_link_t *link;
316 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
318 DEBUG(0, "smc91c92_attach()\n");
319
320 /* Create new ethernet device */
321 dev = alloc_etherdev(sizeof(struct smc_private));
322 if (!dev)
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100323 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 smc = netdev_priv(dev);
325 link = &smc->link;
326 link->priv = dev;
327
328 spin_lock_init(&smc->lock);
329 link->io.NumPorts1 = 16;
330 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
331 link->io.IOAddrLines = 4;
332 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
333 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
334 link->irq.Handler = &smc_interrupt;
335 link->irq.Instance = dev;
336 link->conf.Attributes = CONF_ENABLE_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 link->conf.IntType = INT_MEMORY_AND_IO;
338
339 /* The SMC91c92-specific entries in the device structure. */
340 SET_MODULE_OWNER(dev);
341 dev->hard_start_xmit = &smc_start_xmit;
342 dev->get_stats = &smc_get_stats;
343 dev->set_config = &s9k_config;
344 dev->set_multicast_list = &set_rx_mode;
345 dev->open = &smc_open;
346 dev->stop = &smc_close;
347 dev->do_ioctl = &smc_ioctl;
348 SET_ETHTOOL_OPS(dev, &ethtool_ops);
349#ifdef HAVE_TX_TIMEOUT
350 dev->tx_timeout = smc_tx_timeout;
351 dev->watchdog_timeo = TX_TIMEOUT;
352#endif
353
354 smc->mii_if.dev = dev;
355 smc->mii_if.mdio_read = mdio_read;
356 smc->mii_if.mdio_write = mdio_write;
357 smc->mii_if.phy_id_mask = 0x1f;
358 smc->mii_if.reg_num_mask = 0x1f;
359
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100360 link->handle = p_dev;
361 p_dev->instance = link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100363 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
364 smc91c92_config(link);
365
366 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367} /* smc91c92_attach */
368
369/*======================================================================
370
371 This deletes a driver "instance". The device is de-registered
372 with Card Services. If it has been released, all local data
373 structures are freed. Otherwise, the structures will be freed
374 when the device is released.
375
376======================================================================*/
377
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100378static void smc91c92_detach(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100380 dev_link_t *link = dev_to_instance(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 struct net_device *dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 DEBUG(0, "smc91c92_detach(0x%p)\n", link);
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 if (link->dev)
386 unregister_netdev(dev);
387
388 if (link->state & DEV_CONFIG)
389 smc91c92_release(link);
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 free_netdev(dev);
392} /* smc91c92_detach */
393
394/*====================================================================*/
395
396static int cvt_ascii_address(struct net_device *dev, char *s)
397{
398 int i, j, da, c;
399
400 if (strlen(s) != 12)
401 return -1;
402 for (i = 0; i < 6; i++) {
403 da = 0;
404 for (j = 0; j < 2; j++) {
405 c = *s++;
406 da <<= 4;
407 da += ((c >= '0') && (c <= '9')) ?
408 (c - '0') : ((c & 0x0f) + 9);
409 }
410 dev->dev_addr[i] = da;
411 }
412 return 0;
413}
414
415/*====================================================================*/
416
417static int first_tuple(client_handle_t handle, tuple_t *tuple,
418 cisparse_t *parse)
419{
420 int i;
421
422 if ((i = pcmcia_get_first_tuple(handle, tuple)) != CS_SUCCESS ||
423 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
424 return i;
425 return pcmcia_parse_tuple(handle, tuple, parse);
426}
427
428static int next_tuple(client_handle_t handle, tuple_t *tuple,
429 cisparse_t *parse)
430{
431 int i;
432
433 if ((i = pcmcia_get_next_tuple(handle, tuple)) != CS_SUCCESS ||
434 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
435 return i;
436 return pcmcia_parse_tuple(handle, tuple, parse);
437}
438
439/*======================================================================
440
441 Configuration stuff for Megahertz cards
442
443 mhz_3288_power() is used to power up a 3288's ethernet chip.
444 mhz_mfc_config() handles socket setup for multifunction (1144
445 and 3288) cards. mhz_setup() gets a card's hardware ethernet
446 address.
447
448======================================================================*/
449
450static int mhz_3288_power(dev_link_t *link)
451{
452 struct net_device *dev = link->priv;
453 struct smc_private *smc = netdev_priv(dev);
454 u_char tmp;
455
456 /* Read the ISR twice... */
457 readb(smc->base+MEGAHERTZ_ISR);
458 udelay(5);
459 readb(smc->base+MEGAHERTZ_ISR);
460
461 /* Pause 200ms... */
462 mdelay(200);
463
464 /* Now read and write the COR... */
465 tmp = readb(smc->base + link->conf.ConfigBase + CISREG_COR);
466 udelay(5);
467 writeb(tmp, smc->base + link->conf.ConfigBase + CISREG_COR);
468
469 return 0;
470}
471
472static int mhz_mfc_config(dev_link_t *link)
473{
474 struct net_device *dev = link->priv;
475 struct smc_private *smc = netdev_priv(dev);
Yum Rayan4638aef42005-05-05 15:14:10 -0700476 struct smc_cfg_mem *cfg_mem;
477 tuple_t *tuple;
478 cisparse_t *parse;
479 cistpl_cftable_entry_t *cf;
480 u_char *buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 win_req_t req;
482 memreq_t mem;
483 int i, k;
484
Yum Rayan4638aef42005-05-05 15:14:10 -0700485 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
486 if (!cfg_mem)
487 return CS_OUT_OF_RESOURCE;
488
489 tuple = &cfg_mem->tuple;
490 parse = &cfg_mem->parse;
491 cf = &parse->cftable_entry;
492 buf = cfg_mem->buf;
493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 link->conf.Attributes |= CONF_ENABLE_SPKR;
495 link->conf.Status = CCSR_AUDIO_ENA;
496 link->irq.Attributes =
497 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
498 link->io.IOAddrLines = 16;
499 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
500 link->io.NumPorts2 = 8;
501
Yum Rayan4638aef42005-05-05 15:14:10 -0700502 tuple->Attributes = tuple->TupleOffset = 0;
503 tuple->TupleData = (cisdata_t *)buf;
504 tuple->TupleDataMax = 255;
505 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Yum Rayan4638aef42005-05-05 15:14:10 -0700507 i = first_tuple(link->handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 /* The Megahertz combo cards have modem-like CIS entries, so
509 we have to explicitly try a bunch of port combinations. */
510 while (i == CS_SUCCESS) {
511 link->conf.ConfigIndex = cf->index;
512 link->io.BasePort2 = cf->io.win[0].base;
513 for (k = 0; k < 0x400; k += 0x10) {
514 if (k & 0x80) continue;
515 link->io.BasePort1 = k ^ 0x300;
516 i = pcmcia_request_io(link->handle, &link->io);
517 if (i == CS_SUCCESS) break;
518 }
519 if (i == CS_SUCCESS) break;
Yum Rayan4638aef42005-05-05 15:14:10 -0700520 i = next_tuple(link->handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
522 if (i != CS_SUCCESS)
Yum Rayan4638aef42005-05-05 15:14:10 -0700523 goto free_cfg_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 dev->base_addr = link->io.BasePort1;
525
526 /* Allocate a memory window, for accessing the ISR */
527 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
528 req.Base = req.Size = 0;
529 req.AccessSpeed = 0;
530 i = pcmcia_request_window(&link->handle, &req, &link->win);
531 if (i != CS_SUCCESS)
Yum Rayan4638aef42005-05-05 15:14:10 -0700532 goto free_cfg_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 smc->base = ioremap(req.Base, req.Size);
534 mem.CardOffset = mem.Page = 0;
535 if (smc->manfid == MANFID_MOTOROLA)
536 mem.CardOffset = link->conf.ConfigBase;
537 i = pcmcia_map_mem_page(link->win, &mem);
538
539 if ((i == CS_SUCCESS)
540 && (smc->manfid == MANFID_MEGAHERTZ)
541 && (smc->cardid == PRODID_MEGAHERTZ_EM3288))
542 mhz_3288_power(link);
543
Yum Rayan4638aef42005-05-05 15:14:10 -0700544free_cfg_mem:
545 kfree(cfg_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 return i;
547}
548
549static int mhz_setup(dev_link_t *link)
550{
551 client_handle_t handle = link->handle;
552 struct net_device *dev = link->priv;
Yum Rayan4638aef42005-05-05 15:14:10 -0700553 struct smc_cfg_mem *cfg_mem;
554 tuple_t *tuple;
555 cisparse_t *parse;
556 u_char *buf, *station_addr;
557 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Yum Rayan4638aef42005-05-05 15:14:10 -0700559 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
560 if (!cfg_mem)
561 return -1;
562
563 tuple = &cfg_mem->tuple;
564 parse = &cfg_mem->parse;
565 buf = cfg_mem->buf;
566
567 tuple->Attributes = tuple->TupleOffset = 0;
568 tuple->TupleData = (cisdata_t *)buf;
569 tuple->TupleDataMax = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
571 /* Read the station address from the CIS. It is stored as the last
572 (fourth) string in the Version 1 Version/ID tuple. */
Yum Rayan4638aef42005-05-05 15:14:10 -0700573 tuple->DesiredTuple = CISTPL_VERS_1;
574 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {
575 rc = -1;
576 goto free_cfg_mem;
577 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
Yum Rayan4638aef42005-05-05 15:14:10 -0700579 if (next_tuple(handle, tuple, parse) != CS_SUCCESS)
580 first_tuple(handle, tuple, parse);
581 if (parse->version_1.ns > 3) {
582 station_addr = parse->version_1.str + parse->version_1.ofs[3];
583 if (cvt_ascii_address(dev, station_addr) == 0) {
584 rc = 0;
585 goto free_cfg_mem;
586 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
588
589 /* Another possibility: for the EM3288, in a special tuple */
Yum Rayan4638aef42005-05-05 15:14:10 -0700590 tuple->DesiredTuple = 0x81;
591 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) {
592 rc = -1;
593 goto free_cfg_mem;
594 }
595 if (pcmcia_get_tuple_data(handle, tuple) != CS_SUCCESS) {
596 rc = -1;
597 goto free_cfg_mem;
598 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 buf[12] = '\0';
Yum Rayan4638aef42005-05-05 15:14:10 -0700600 if (cvt_ascii_address(dev, buf) == 0) {
601 rc = 0;
602 goto free_cfg_mem;
603 }
604 rc = -1;
605free_cfg_mem:
606 kfree(cfg_mem);
607 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608}
609
610/*======================================================================
611
612 Configuration stuff for the Motorola Mariner
613
614 mot_config() writes directly to the Mariner configuration
615 registers because the CIS is just bogus.
616
617======================================================================*/
618
619static void mot_config(dev_link_t *link)
620{
621 struct net_device *dev = link->priv;
622 struct smc_private *smc = netdev_priv(dev);
623 kio_addr_t ioaddr = dev->base_addr;
624 kio_addr_t iouart = link->io.BasePort2;
625
626 /* Set UART base address and force map with COR bit 1 */
627 writeb(iouart & 0xff, smc->base + MOT_UART + CISREG_IOBASE_0);
628 writeb((iouart >> 8) & 0xff, smc->base + MOT_UART + CISREG_IOBASE_1);
629 writeb(MOT_NORMAL, smc->base + MOT_UART + CISREG_COR);
630
631 /* Set SMC base address and force map with COR bit 1 */
632 writeb(ioaddr & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_0);
633 writeb((ioaddr >> 8) & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_1);
634 writeb(MOT_NORMAL, smc->base + MOT_LAN + CISREG_COR);
635
636 /* Wait for things to settle down */
637 mdelay(100);
638}
639
640static int mot_setup(dev_link_t *link)
641{
642 struct net_device *dev = link->priv;
643 kio_addr_t ioaddr = dev->base_addr;
644 int i, wait, loop;
645 u_int addr;
646
647 /* Read Ethernet address from Serial EEPROM */
648
649 for (i = 0; i < 3; i++) {
650 SMC_SELECT_BANK(2);
651 outw(MOT_EEPROM + i, ioaddr + POINTER);
652 SMC_SELECT_BANK(1);
653 outw((CTL_RELOAD | CTL_EE_SELECT), ioaddr + CONTROL);
654
655 for (loop = wait = 0; loop < 200; loop++) {
656 udelay(10);
657 wait = ((CTL_RELOAD | CTL_STORE) & inw(ioaddr + CONTROL));
658 if (wait == 0) break;
659 }
660
661 if (wait)
662 return -1;
663
664 addr = inw(ioaddr + GENERAL);
665 dev->dev_addr[2*i] = addr & 0xff;
666 dev->dev_addr[2*i+1] = (addr >> 8) & 0xff;
667 }
668
669 return 0;
670}
671
672/*====================================================================*/
673
674static int smc_config(dev_link_t *link)
675{
676 struct net_device *dev = link->priv;
Yum Rayan4638aef42005-05-05 15:14:10 -0700677 struct smc_cfg_mem *cfg_mem;
678 tuple_t *tuple;
679 cisparse_t *parse;
680 cistpl_cftable_entry_t *cf;
681 u_char *buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 int i;
683
Yum Rayan4638aef42005-05-05 15:14:10 -0700684 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
685 if (!cfg_mem)
686 return CS_OUT_OF_RESOURCE;
687
688 tuple = &cfg_mem->tuple;
689 parse = &cfg_mem->parse;
690 cf = &parse->cftable_entry;
691 buf = cfg_mem->buf;
692
693 tuple->Attributes = tuple->TupleOffset = 0;
694 tuple->TupleData = (cisdata_t *)buf;
695 tuple->TupleDataMax = 255;
696 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
698 link->io.NumPorts1 = 16;
Yum Rayan4638aef42005-05-05 15:14:10 -0700699 i = first_tuple(link->handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 while (i != CS_NO_MORE_ITEMS) {
701 if (i == CS_SUCCESS) {
702 link->conf.ConfigIndex = cf->index;
703 link->io.BasePort1 = cf->io.win[0].base;
704 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
705 i = pcmcia_request_io(link->handle, &link->io);
706 if (i == CS_SUCCESS) break;
707 }
Yum Rayan4638aef42005-05-05 15:14:10 -0700708 i = next_tuple(link->handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 }
710 if (i == CS_SUCCESS)
711 dev->base_addr = link->io.BasePort1;
Yum Rayan4638aef42005-05-05 15:14:10 -0700712
713 kfree(cfg_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 return i;
715}
716
717static int smc_setup(dev_link_t *link)
718{
719 client_handle_t handle = link->handle;
720 struct net_device *dev = link->priv;
Yum Rayan4638aef42005-05-05 15:14:10 -0700721 struct smc_cfg_mem *cfg_mem;
722 tuple_t *tuple;
723 cisparse_t *parse;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 cistpl_lan_node_id_t *node_id;
Yum Rayan4638aef42005-05-05 15:14:10 -0700725 u_char *buf, *station_addr;
726 int i, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Yum Rayan4638aef42005-05-05 15:14:10 -0700728 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
729 if (!cfg_mem)
730 return CS_OUT_OF_RESOURCE;
731
732 tuple = &cfg_mem->tuple;
733 parse = &cfg_mem->parse;
734 buf = cfg_mem->buf;
735
736 tuple->Attributes = tuple->TupleOffset = 0;
737 tuple->TupleData = (cisdata_t *)buf;
738 tuple->TupleDataMax = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
740 /* Check for a LAN function extension tuple */
Yum Rayan4638aef42005-05-05 15:14:10 -0700741 tuple->DesiredTuple = CISTPL_FUNCE;
742 i = first_tuple(handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 while (i == CS_SUCCESS) {
Yum Rayan4638aef42005-05-05 15:14:10 -0700744 if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 break;
Yum Rayan4638aef42005-05-05 15:14:10 -0700746 i = next_tuple(handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 }
748 if (i == CS_SUCCESS) {
Yum Rayan4638aef42005-05-05 15:14:10 -0700749 node_id = (cistpl_lan_node_id_t *)parse->funce.data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 if (node_id->nb == 6) {
751 for (i = 0; i < 6; i++)
752 dev->dev_addr[i] = node_id->id[i];
Yum Rayan4638aef42005-05-05 15:14:10 -0700753 rc = 0;
754 goto free_cfg_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 }
756 }
757 /* Try the third string in the Version 1 Version/ID tuple. */
Yum Rayan4638aef42005-05-05 15:14:10 -0700758 tuple->DesiredTuple = CISTPL_VERS_1;
759 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {
760 rc = -1;
761 goto free_cfg_mem;
762 }
763 station_addr = parse->version_1.str + parse->version_1.ofs[2];
764 if (cvt_ascii_address(dev, station_addr) == 0) {
765 rc = 0;
766 goto free_cfg_mem;
767 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Yum Rayan4638aef42005-05-05 15:14:10 -0700769 rc = -1;
770free_cfg_mem:
771 kfree(cfg_mem);
772 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773}
774
775/*====================================================================*/
776
777static int osi_config(dev_link_t *link)
778{
779 struct net_device *dev = link->priv;
Arjan van de Venf71e1302006-03-03 21:33:57 -0500780 static const kio_addr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 int i, j;
782
783 link->conf.Attributes |= CONF_ENABLE_SPKR;
784 link->conf.Status = CCSR_AUDIO_ENA;
785 link->irq.Attributes =
786 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
787 link->io.NumPorts1 = 64;
788 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
789 link->io.NumPorts2 = 8;
790 link->io.IOAddrLines = 16;
791
792 /* Enable Hard Decode, LAN, Modem */
793 link->conf.ConfigIndex = 0x23;
794
795 for (i = j = 0; j < 4; j++) {
796 link->io.BasePort2 = com[j];
797 i = pcmcia_request_io(link->handle, &link->io);
798 if (i == CS_SUCCESS) break;
799 }
800 if (i != CS_SUCCESS) {
801 /* Fallback: turn off hard decode */
802 link->conf.ConfigIndex = 0x03;
803 link->io.NumPorts2 = 0;
804 i = pcmcia_request_io(link->handle, &link->io);
805 }
806 dev->base_addr = link->io.BasePort1 + 0x10;
807 return i;
808}
809
810static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid)
811{
812 client_handle_t handle = link->handle;
813 struct net_device *dev = link->priv;
Yum Rayan4638aef42005-05-05 15:14:10 -0700814 struct smc_cfg_mem *cfg_mem;
815 tuple_t *tuple;
816 u_char *buf;
817 int i, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Yum Rayan4638aef42005-05-05 15:14:10 -0700819 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
820 if (!cfg_mem)
821 return -1;
822
823 tuple = &cfg_mem->tuple;
824 buf = cfg_mem->buf;
825
826 tuple->Attributes = TUPLE_RETURN_COMMON;
827 tuple->TupleData = (cisdata_t *)buf;
828 tuple->TupleDataMax = 255;
829 tuple->TupleOffset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831 /* Read the station address from tuple 0x90, subtuple 0x04 */
Yum Rayan4638aef42005-05-05 15:14:10 -0700832 tuple->DesiredTuple = 0x90;
833 i = pcmcia_get_first_tuple(handle, tuple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 while (i == CS_SUCCESS) {
Yum Rayan4638aef42005-05-05 15:14:10 -0700835 i = pcmcia_get_tuple_data(handle, tuple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 if ((i != CS_SUCCESS) || (buf[0] == 0x04))
837 break;
Yum Rayan4638aef42005-05-05 15:14:10 -0700838 i = pcmcia_get_next_tuple(handle, tuple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 }
Yum Rayan4638aef42005-05-05 15:14:10 -0700840 if (i != CS_SUCCESS) {
841 rc = -1;
842 goto free_cfg_mem;
843 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 for (i = 0; i < 6; i++)
845 dev->dev_addr[i] = buf[i+2];
846
847 if (((manfid == MANFID_OSITECH) &&
848 (cardid == PRODID_OSITECH_SEVEN)) ||
849 ((manfid == MANFID_PSION) &&
850 (cardid == PRODID_PSION_NET100))) {
851 /* Download the Seven of Diamonds firmware */
852 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
853 outb(__Xilinx7OD[i], link->io.BasePort1+2);
854 udelay(50);
855 }
856 } else if (manfid == MANFID_OSITECH) {
857 /* Make sure both functions are powered up */
858 set_bits(0x300, link->io.BasePort1 + OSITECH_AUI_PWR);
859 /* Now, turn on the interrupt for both card functions */
860 set_bits(0x300, link->io.BasePort1 + OSITECH_RESET_ISR);
861 DEBUG(2, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n",
862 inw(link->io.BasePort1 + OSITECH_AUI_PWR),
863 inw(link->io.BasePort1 + OSITECH_RESET_ISR));
864 }
Yum Rayan4638aef42005-05-05 15:14:10 -0700865 rc = 0;
866free_cfg_mem:
867 kfree(cfg_mem);
868 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869}
870
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100871static int smc91c92_suspend(struct pcmcia_device *p_dev)
872{
873 dev_link_t *link = dev_to_instance(p_dev);
874 struct net_device *dev = link->priv;
875
Dominik Brodowski4bbed522006-01-15 11:18:12 +0100876 if ((link->state & DEV_CONFIG) && (link->open))
877 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100878
879 return 0;
880}
881
882static int smc91c92_resume(struct pcmcia_device *p_dev)
883{
884 dev_link_t *link = dev_to_instance(p_dev);
885 struct net_device *dev = link->priv;
886 struct smc_private *smc = netdev_priv(dev);
887 int i;
888
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100889 if (link->state & DEV_CONFIG) {
890 if ((smc->manfid == MANFID_MEGAHERTZ) &&
891 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
892 mhz_3288_power(link);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100893 if (smc->manfid == MANFID_MOTOROLA)
894 mot_config(link);
895 if ((smc->manfid == MANFID_OSITECH) &&
896 (smc->cardid != PRODID_OSITECH_SEVEN)) {
897 /* Power up the card and enable interrupts */
898 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR);
899 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR);
900 }
901 if (((smc->manfid == MANFID_OSITECH) &&
902 (smc->cardid == PRODID_OSITECH_SEVEN)) ||
903 ((smc->manfid == MANFID_PSION) &&
904 (smc->cardid == PRODID_PSION_NET100))) {
905 /* Download the Seven of Diamonds firmware */
906 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
907 outb(__Xilinx7OD[i], link->io.BasePort1+2);
908 udelay(50);
909 }
910 }
911 if (link->open) {
912 smc_reset(dev);
913 netif_device_attach(dev);
914 }
915 }
916
917 return 0;
918}
919
920
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921/*======================================================================
922
923 This verifies that the chip is some SMC91cXX variant, and returns
924 the revision code if successful. Otherwise, it returns -ENODEV.
925
926======================================================================*/
927
928static int check_sig(dev_link_t *link)
929{
930 struct net_device *dev = link->priv;
931 kio_addr_t ioaddr = dev->base_addr;
932 int width;
933 u_short s;
934
935 SMC_SELECT_BANK(1);
936 if (inw(ioaddr + BANK_SELECT) >> 8 != 0x33) {
937 /* Try powering up the chip */
938 outw(0, ioaddr + CONTROL);
939 mdelay(55);
940 }
941
942 /* Try setting bus width */
943 width = (link->io.Attributes1 == IO_DATA_PATH_WIDTH_AUTO);
944 s = inb(ioaddr + CONFIG);
945 if (width)
946 s |= CFG_16BIT;
947 else
948 s &= ~CFG_16BIT;
949 outb(s, ioaddr + CONFIG);
950
951 /* Check Base Address Register to make sure bus width is OK */
952 s = inw(ioaddr + BASE_ADDR);
953 if ((inw(ioaddr + BANK_SELECT) >> 8 == 0x33) &&
954 ((s >> 8) != (s & 0xff))) {
955 SMC_SELECT_BANK(3);
956 s = inw(ioaddr + REVISION);
957 return (s & 0xff);
958 }
959
960 if (width) {
Dominik Brodowski4bbed522006-01-15 11:18:12 +0100961 modconf_t mod = {
962 .Attributes = CONF_IO_CHANGE_WIDTH,
963 };
964 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n");
Dominik Brodowski50db3fd2006-01-15 10:05:19 +0100965
Dominik Brodowski4bbed522006-01-15 11:18:12 +0100966 smc91c92_suspend(link->handle);
967 pcmcia_modify_configuration(link->handle, &mod);
968 smc91c92_resume(link->handle);
969 return check_sig(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 }
971 return -ENODEV;
972}
973
974/*======================================================================
975
976 smc91c92_config() is scheduled to run after a CARD_INSERTION event
977 is received, to configure the PCMCIA socket, and to make the
978 ethernet device available to the system.
979
980======================================================================*/
981
982#define CS_EXIT_TEST(ret, svc, label) \
983if (ret != CS_SUCCESS) { cs_error(link->handle, svc, ret); goto label; }
984
985static void smc91c92_config(dev_link_t *link)
986{
987 client_handle_t handle = link->handle;
988 struct net_device *dev = link->priv;
989 struct smc_private *smc = netdev_priv(dev);
Yum Rayan4638aef42005-05-05 15:14:10 -0700990 struct smc_cfg_mem *cfg_mem;
991 tuple_t *tuple;
992 cisparse_t *parse;
993 u_char *buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 char *name;
995 int i, j, rev;
996 kio_addr_t ioaddr;
997 u_long mir;
998
999 DEBUG(0, "smc91c92_config(0x%p)\n", link);
1000
Yum Rayan4638aef42005-05-05 15:14:10 -07001001 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
1002 if (!cfg_mem)
1003 goto config_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
Yum Rayan4638aef42005-05-05 15:14:10 -07001005 tuple = &cfg_mem->tuple;
1006 parse = &cfg_mem->parse;
1007 buf = cfg_mem->buf;
1008
1009 tuple->Attributes = tuple->TupleOffset = 0;
1010 tuple->TupleData = (cisdata_t *)buf;
1011 tuple->TupleDataMax = 64;
1012
1013 tuple->DesiredTuple = CISTPL_CONFIG;
1014 i = first_tuple(handle, tuple, parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 CS_EXIT_TEST(i, ParseTuple, config_failed);
Yum Rayan4638aef42005-05-05 15:14:10 -07001016 link->conf.ConfigBase = parse->config.base;
1017 link->conf.Present = parse->config.rmask[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
Yum Rayan4638aef42005-05-05 15:14:10 -07001019 tuple->DesiredTuple = CISTPL_MANFID;
1020 tuple->Attributes = TUPLE_RETURN_COMMON;
1021 if (first_tuple(handle, tuple, parse) == CS_SUCCESS) {
1022 smc->manfid = parse->manfid.manf;
1023 smc->cardid = parse->manfid.card;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 }
1025
1026 /* Configure card */
1027 link->state |= DEV_CONFIG;
1028
1029 if ((smc->manfid == MANFID_OSITECH) &&
1030 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1031 i = osi_config(link);
1032 } else if ((smc->manfid == MANFID_MOTOROLA) ||
1033 ((smc->manfid == MANFID_MEGAHERTZ) &&
1034 ((smc->cardid == PRODID_MEGAHERTZ_VARIOUS) ||
1035 (smc->cardid == PRODID_MEGAHERTZ_EM3288)))) {
1036 i = mhz_mfc_config(link);
1037 } else {
1038 i = smc_config(link);
1039 }
1040 CS_EXIT_TEST(i, RequestIO, config_failed);
1041
1042 i = pcmcia_request_irq(link->handle, &link->irq);
1043 CS_EXIT_TEST(i, RequestIRQ, config_failed);
1044 i = pcmcia_request_configuration(link->handle, &link->conf);
1045 CS_EXIT_TEST(i, RequestConfiguration, config_failed);
1046
1047 if (smc->manfid == MANFID_MOTOROLA)
1048 mot_config(link);
1049
1050 dev->irq = link->irq.AssignedIRQ;
1051
1052 if ((if_port >= 0) && (if_port <= 2))
1053 dev->if_port = if_port;
1054 else
1055 printk(KERN_NOTICE "smc91c92_cs: invalid if_port requested\n");
1056
1057 switch (smc->manfid) {
1058 case MANFID_OSITECH:
1059 case MANFID_PSION:
1060 i = osi_setup(link, smc->manfid, smc->cardid); break;
1061 case MANFID_SMC:
1062 case MANFID_NEW_MEDIA:
1063 i = smc_setup(link); break;
1064 case 0x128: /* For broken Megahertz cards */
1065 case MANFID_MEGAHERTZ:
1066 i = mhz_setup(link); break;
1067 case MANFID_MOTOROLA:
1068 default: /* get the hw address from EEPROM */
1069 i = mot_setup(link); break;
1070 }
1071
1072 if (i != 0) {
1073 printk(KERN_NOTICE "smc91c92_cs: Unable to find hardware address.\n");
1074 goto config_undo;
1075 }
1076
1077 smc->duplex = 0;
1078 smc->rx_ovrn = 0;
1079
1080 rev = check_sig(link);
1081 name = "???";
1082 if (rev > 0)
1083 switch (rev >> 4) {
1084 case 3: name = "92"; break;
1085 case 4: name = ((rev & 15) >= 6) ? "96" : "94"; break;
1086 case 5: name = "95"; break;
1087 case 7: name = "100"; break;
1088 case 8: name = "100-FD"; break;
1089 case 9: name = "110"; break;
1090 }
1091
1092 ioaddr = dev->base_addr;
1093 if (rev > 0) {
1094 u_long mcr;
1095 SMC_SELECT_BANK(0);
1096 mir = inw(ioaddr + MEMINFO) & 0xff;
1097 if (mir == 0xff) mir++;
1098 /* Get scale factor for memory size */
1099 mcr = ((rev >> 4) > 3) ? inw(ioaddr + MEMCFG) : 0x0200;
1100 mir *= 128 * (1<<((mcr >> 9) & 7));
1101 SMC_SELECT_BANK(1);
1102 smc->cfg = inw(ioaddr + CONFIG) & ~CFG_AUI_SELECT;
1103 smc->cfg |= CFG_NO_WAIT | CFG_16BIT | CFG_STATIC;
1104 if (smc->manfid == MANFID_OSITECH)
1105 smc->cfg |= CFG_IRQ_SEL_1 | CFG_IRQ_SEL_0;
1106 if ((rev >> 4) >= 7)
1107 smc->cfg |= CFG_MII_SELECT;
1108 } else
1109 mir = 0;
1110
1111 if (smc->cfg & CFG_MII_SELECT) {
1112 SMC_SELECT_BANK(3);
1113
1114 for (i = 0; i < 32; i++) {
1115 j = mdio_read(dev, i, 1);
1116 if ((j != 0) && (j != 0xffff)) break;
1117 }
1118 smc->mii_if.phy_id = (i < 32) ? i : -1;
1119
1120 SMC_SELECT_BANK(0);
1121 }
1122
1123 link->dev = &smc->node;
1124 link->state &= ~DEV_CONFIG_PENDING;
1125 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
1126
1127 if (register_netdev(dev) != 0) {
1128 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n");
1129 link->dev = NULL;
1130 goto config_undo;
1131 }
1132
1133 strcpy(smc->node.dev_name, dev->name);
1134
1135 printk(KERN_INFO "%s: smc91c%s rev %d: io %#3lx, irq %d, "
1136 "hw_addr ", dev->name, name, (rev & 0x0f), dev->base_addr,
1137 dev->irq);
1138 for (i = 0; i < 6; i++)
1139 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
1140
1141 if (rev > 0) {
1142 if (mir & 0x3ff)
1143 printk(KERN_INFO " %lu byte", mir);
1144 else
1145 printk(KERN_INFO " %lu kb", mir>>10);
1146 printk(" buffer, %s xcvr\n", (smc->cfg & CFG_MII_SELECT) ?
1147 "MII" : if_names[dev->if_port]);
1148 }
1149
1150 if (smc->cfg & CFG_MII_SELECT) {
1151 if (smc->mii_if.phy_id != -1) {
1152 DEBUG(0, " MII transceiver at index %d, status %x.\n",
1153 smc->mii_if.phy_id, j);
1154 } else {
1155 printk(KERN_NOTICE " No MII transceivers found!\n");
1156 }
1157 }
Yum Rayan4638aef42005-05-05 15:14:10 -07001158 kfree(cfg_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 return;
1160
1161config_undo:
1162 unregister_netdev(dev);
1163config_failed: /* CS_EXIT_TEST() calls jump to here... */
1164 smc91c92_release(link);
1165 link->state &= ~DEV_CONFIG_PENDING;
Yum Rayan4638aef42005-05-05 15:14:10 -07001166 kfree(cfg_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168} /* smc91c92_config */
1169
1170/*======================================================================
1171
1172 After a card is removed, smc91c92_release() will unregister the net
1173 device, and release the PCMCIA configuration. If the device is
1174 still open, this will be postponed until it is closed.
1175
1176======================================================================*/
1177
1178static void smc91c92_release(dev_link_t *link)
1179{
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +01001180 DEBUG(0, "smc91c92_release(0x%p)\n", link);
1181 if (link->win) {
1182 struct net_device *dev = link->priv;
1183 struct smc_private *smc = netdev_priv(dev);
1184 iounmap(smc->base);
1185 }
1186 pcmcia_disable_device(link->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}
1188
1189/*======================================================================
1190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 MII interface support for SMC91cXX based cards
1192======================================================================*/
1193
1194#define MDIO_SHIFT_CLK 0x04
1195#define MDIO_DATA_OUT 0x01
1196#define MDIO_DIR_WRITE 0x08
1197#define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
1198#define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
1199#define MDIO_DATA_READ 0x02
1200
1201static void mdio_sync(kio_addr_t addr)
1202{
1203 int bits;
1204 for (bits = 0; bits < 32; bits++) {
1205 outb(MDIO_DATA_WRITE1, addr);
1206 outb(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
1207 }
1208}
1209
1210static int mdio_read(struct net_device *dev, int phy_id, int loc)
1211{
1212 kio_addr_t addr = dev->base_addr + MGMT;
1213 u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
1214 int i, retval = 0;
1215
1216 mdio_sync(addr);
1217 for (i = 13; i >= 0; i--) {
1218 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1219 outb(dat, addr);
1220 outb(dat | MDIO_SHIFT_CLK, addr);
1221 }
1222 for (i = 19; i > 0; i--) {
1223 outb(0, addr);
1224 retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
1225 outb(MDIO_SHIFT_CLK, addr);
1226 }
1227 return (retval>>1) & 0xffff;
1228}
1229
1230static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
1231{
1232 kio_addr_t addr = dev->base_addr + MGMT;
1233 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
1234 int i;
1235
1236 mdio_sync(addr);
1237 for (i = 31; i >= 0; i--) {
1238 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1239 outb(dat, addr);
1240 outb(dat | MDIO_SHIFT_CLK, addr);
1241 }
1242 for (i = 1; i >= 0; i--) {
1243 outb(0, addr);
1244 outb(MDIO_SHIFT_CLK, addr);
1245 }
1246}
1247
1248/*======================================================================
1249
1250 The driver core code, most of which should be common with a
1251 non-PCMCIA implementation.
1252
1253======================================================================*/
1254
1255#ifdef PCMCIA_DEBUG
1256static void smc_dump(struct net_device *dev)
1257{
1258 kio_addr_t ioaddr = dev->base_addr;
1259 u_short i, w, save;
1260 save = inw(ioaddr + BANK_SELECT);
1261 for (w = 0; w < 4; w++) {
1262 SMC_SELECT_BANK(w);
1263 printk(KERN_DEBUG "bank %d: ", w);
1264 for (i = 0; i < 14; i += 2)
1265 printk(" %04x", inw(ioaddr + i));
1266 printk("\n");
1267 }
1268 outw(save, ioaddr + BANK_SELECT);
1269}
1270#endif
1271
1272static int smc_open(struct net_device *dev)
1273{
1274 struct smc_private *smc = netdev_priv(dev);
1275 dev_link_t *link = &smc->link;
1276
1277#ifdef PCMCIA_DEBUG
1278 DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n",
1279 dev->name, dev, inw(dev->base_addr + BANK_SELECT));
1280 if (pc_debug > 1) smc_dump(dev);
1281#endif
1282
1283 /* Check that the PCMCIA card is still here. */
1284 if (!DEV_OK(link))
1285 return -ENODEV;
1286 /* Physical device present signature. */
1287 if (check_sig(link) < 0) {
1288 printk("smc91c92_cs: Yikes! Bad chip signature!\n");
1289 return -ENODEV;
1290 }
1291 link->open++;
1292
1293 netif_start_queue(dev);
1294 smc->saved_skb = NULL;
1295 smc->packets_waiting = 0;
1296
1297 smc_reset(dev);
1298 init_timer(&smc->media);
1299 smc->media.function = &media_check;
1300 smc->media.data = (u_long) dev;
1301 smc->media.expires = jiffies + HZ;
1302 add_timer(&smc->media);
1303
1304 return 0;
1305} /* smc_open */
1306
1307/*====================================================================*/
1308
1309static int smc_close(struct net_device *dev)
1310{
1311 struct smc_private *smc = netdev_priv(dev);
1312 dev_link_t *link = &smc->link;
1313 kio_addr_t ioaddr = dev->base_addr;
1314
1315 DEBUG(0, "%s: smc_close(), status %4.4x.\n",
1316 dev->name, inw(ioaddr + BANK_SELECT));
1317
1318 netif_stop_queue(dev);
1319
1320 /* Shut off all interrupts, and turn off the Tx and Rx sections.
1321 Don't bother to check for chip present. */
1322 SMC_SELECT_BANK(2); /* Nominally paranoia, but do no assume... */
1323 outw(0, ioaddr + INTERRUPT);
1324 SMC_SELECT_BANK(0);
1325 mask_bits(0xff00, ioaddr + RCR);
1326 mask_bits(0xff00, ioaddr + TCR);
1327
1328 /* Put the chip into power-down mode. */
1329 SMC_SELECT_BANK(1);
1330 outw(CTL_POWERDOWN, ioaddr + CONTROL );
1331
1332 link->open--;
1333 del_timer_sync(&smc->media);
1334
1335 return 0;
1336} /* smc_close */
1337
1338/*======================================================================
1339
1340 Transfer a packet to the hardware and trigger the packet send.
1341 This may be called at either from either the Tx queue code
1342 or the interrupt handler.
1343
1344======================================================================*/
1345
1346static void smc_hardware_send_packet(struct net_device * dev)
1347{
1348 struct smc_private *smc = netdev_priv(dev);
1349 struct sk_buff *skb = smc->saved_skb;
1350 kio_addr_t ioaddr = dev->base_addr;
1351 u_char packet_no;
1352
1353 if (!skb) {
1354 printk(KERN_ERR "%s: In XMIT with no packet to send.\n", dev->name);
1355 return;
1356 }
1357
1358 /* There should be a packet slot waiting. */
1359 packet_no = inw(ioaddr + PNR_ARR) >> 8;
1360 if (packet_no & 0x80) {
1361 /* If not, there is a hardware problem! Likely an ejected card. */
1362 printk(KERN_WARNING "%s: 91c92 hardware Tx buffer allocation"
1363 " failed, status %#2.2x.\n", dev->name, packet_no);
1364 dev_kfree_skb_irq(skb);
1365 smc->saved_skb = NULL;
1366 netif_start_queue(dev);
1367 return;
1368 }
1369
1370 smc->stats.tx_bytes += skb->len;
1371 /* The card should use the just-allocated buffer. */
1372 outw(packet_no, ioaddr + PNR_ARR);
1373 /* point to the beginning of the packet */
1374 outw(PTR_AUTOINC , ioaddr + POINTER);
1375
1376 /* Send the packet length (+6 for status, length and ctl byte)
1377 and the status word (set to zeros). */
1378 {
1379 u_char *buf = skb->data;
1380 u_int length = skb->len; /* The chip will pad to ethernet min. */
1381
1382 DEBUG(2, "%s: Trying to xmit packet of length %d.\n",
1383 dev->name, length);
1384
1385 /* send the packet length: +6 for status word, length, and ctl */
1386 outw(0, ioaddr + DATA_1);
1387 outw(length + 6, ioaddr + DATA_1);
1388 outsw(ioaddr + DATA_1, buf, length >> 1);
1389
1390 /* The odd last byte, if there is one, goes in the control word. */
1391 outw((length & 1) ? 0x2000 | buf[length-1] : 0, ioaddr + DATA_1);
1392 }
1393
1394 /* Enable the Tx interrupts, both Tx (TxErr) and TxEmpty. */
1395 outw(((IM_TX_INT|IM_TX_EMPTY_INT)<<8) |
1396 (inw(ioaddr + INTERRUPT) & 0xff00),
1397 ioaddr + INTERRUPT);
1398
1399 /* The chip does the rest of the work. */
1400 outw(MC_ENQUEUE , ioaddr + MMU_CMD);
1401
1402 smc->saved_skb = NULL;
1403 dev_kfree_skb_irq(skb);
1404 dev->trans_start = jiffies;
1405 netif_start_queue(dev);
1406 return;
1407}
1408
1409/*====================================================================*/
1410
1411static void smc_tx_timeout(struct net_device *dev)
1412{
1413 struct smc_private *smc = netdev_priv(dev);
1414 kio_addr_t ioaddr = dev->base_addr;
1415
1416 printk(KERN_NOTICE "%s: SMC91c92 transmit timed out, "
1417 "Tx_status %2.2x status %4.4x.\n",
1418 dev->name, inw(ioaddr)&0xff, inw(ioaddr + 2));
1419 smc->stats.tx_errors++;
1420 smc_reset(dev);
1421 dev->trans_start = jiffies;
1422 smc->saved_skb = NULL;
1423 netif_wake_queue(dev);
1424}
1425
1426static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev)
1427{
1428 struct smc_private *smc = netdev_priv(dev);
1429 kio_addr_t ioaddr = dev->base_addr;
1430 u_short num_pages;
1431 short time_out, ir;
1432
1433 netif_stop_queue(dev);
1434
1435 DEBUG(2, "%s: smc_start_xmit(length = %d) called,"
1436 " status %4.4x.\n", dev->name, skb->len, inw(ioaddr + 2));
1437
1438 if (smc->saved_skb) {
1439 /* THIS SHOULD NEVER HAPPEN. */
1440 smc->stats.tx_aborted_errors++;
1441 printk(KERN_DEBUG "%s: Internal error -- sent packet while busy.\n",
1442 dev->name);
1443 return 1;
1444 }
1445 smc->saved_skb = skb;
1446
1447 num_pages = skb->len >> 8;
1448
1449 if (num_pages > 7) {
1450 printk(KERN_ERR "%s: Far too big packet error.\n", dev->name);
1451 dev_kfree_skb (skb);
1452 smc->saved_skb = NULL;
1453 smc->stats.tx_dropped++;
1454 return 0; /* Do not re-queue this packet. */
1455 }
1456 /* A packet is now waiting. */
1457 smc->packets_waiting++;
1458
1459 SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */
1460
1461 /* need MC_RESET to keep the memory consistent. errata? */
1462 if (smc->rx_ovrn) {
1463 outw(MC_RESET, ioaddr + MMU_CMD);
1464 smc->rx_ovrn = 0;
1465 }
1466
1467 /* Allocate the memory; send the packet now if we win. */
1468 outw(MC_ALLOC | num_pages, ioaddr + MMU_CMD);
1469 for (time_out = MEMORY_WAIT_TIME; time_out >= 0; time_out--) {
1470 ir = inw(ioaddr+INTERRUPT);
1471 if (ir & IM_ALLOC_INT) {
1472 /* Acknowledge the interrupt, send the packet. */
1473 outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT);
1474 smc_hardware_send_packet(dev); /* Send the packet now.. */
1475 return 0;
1476 }
1477 }
1478
1479 /* Otherwise defer until the Tx-space-allocated interrupt. */
1480 DEBUG(2, "%s: memory allocation deferred.\n", dev->name);
1481 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT);
1482
1483 return 0;
1484}
1485
1486/*======================================================================
1487
1488 Handle a Tx anomolous event. Entered while in Window 2.
1489
1490======================================================================*/
1491
1492static void smc_tx_err(struct net_device * dev)
1493{
1494 struct smc_private *smc = netdev_priv(dev);
1495 kio_addr_t ioaddr = dev->base_addr;
1496 int saved_packet = inw(ioaddr + PNR_ARR) & 0xff;
1497 int packet_no = inw(ioaddr + FIFO_PORTS) & 0x7f;
1498 int tx_status;
1499
1500 /* select this as the packet to read from */
1501 outw(packet_no, ioaddr + PNR_ARR);
1502
1503 /* read the first word from this packet */
1504 outw(PTR_AUTOINC | PTR_READ | 0, ioaddr + POINTER);
1505
1506 tx_status = inw(ioaddr + DATA_1);
1507
1508 smc->stats.tx_errors++;
1509 if (tx_status & TS_LOSTCAR) smc->stats.tx_carrier_errors++;
1510 if (tx_status & TS_LATCOL) smc->stats.tx_window_errors++;
1511 if (tx_status & TS_16COL) {
1512 smc->stats.tx_aborted_errors++;
1513 smc->tx_err++;
1514 }
1515
1516 if (tx_status & TS_SUCCESS) {
1517 printk(KERN_NOTICE "%s: Successful packet caused error "
1518 "interrupt?\n", dev->name);
1519 }
1520 /* re-enable transmit */
1521 SMC_SELECT_BANK(0);
1522 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1523 SMC_SELECT_BANK(2);
1524
1525 outw(MC_FREEPKT, ioaddr + MMU_CMD); /* Free the packet memory. */
1526
1527 /* one less packet waiting for me */
1528 smc->packets_waiting--;
1529
1530 outw(saved_packet, ioaddr + PNR_ARR);
1531 return;
1532}
1533
1534/*====================================================================*/
1535
1536static void smc_eph_irq(struct net_device *dev)
1537{
1538 struct smc_private *smc = netdev_priv(dev);
1539 kio_addr_t ioaddr = dev->base_addr;
1540 u_short card_stats, ephs;
1541
1542 SMC_SELECT_BANK(0);
1543 ephs = inw(ioaddr + EPH);
1544 DEBUG(2, "%s: Ethernet protocol handler interrupt, status"
1545 " %4.4x.\n", dev->name, ephs);
1546 /* Could be a counter roll-over warning: update stats. */
1547 card_stats = inw(ioaddr + COUNTER);
1548 /* single collisions */
1549 smc->stats.collisions += card_stats & 0xF;
1550 card_stats >>= 4;
1551 /* multiple collisions */
1552 smc->stats.collisions += card_stats & 0xF;
1553#if 0 /* These are for when linux supports these statistics */
1554 card_stats >>= 4; /* deferred */
1555 card_stats >>= 4; /* excess deferred */
1556#endif
1557 /* If we had a transmit error we must re-enable the transmitter. */
1558 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1559
1560 /* Clear a link error interrupt. */
1561 SMC_SELECT_BANK(1);
1562 outw(CTL_AUTO_RELEASE | 0x0000, ioaddr + CONTROL);
1563 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1564 ioaddr + CONTROL);
1565 SMC_SELECT_BANK(2);
1566}
1567
1568/*====================================================================*/
1569
1570static irqreturn_t smc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1571{
1572 struct net_device *dev = dev_id;
1573 struct smc_private *smc = netdev_priv(dev);
1574 kio_addr_t ioaddr;
1575 u_short saved_bank, saved_pointer, mask, status;
1576 unsigned int handled = 1;
1577 char bogus_cnt = INTR_WORK; /* Work we are willing to do. */
1578
1579 if (!netif_device_present(dev))
1580 return IRQ_NONE;
1581
1582 ioaddr = dev->base_addr;
1583
1584 DEBUG(3, "%s: SMC91c92 interrupt %d at %#x.\n", dev->name,
1585 irq, ioaddr);
1586
1587 smc->watchdog = 0;
1588 saved_bank = inw(ioaddr + BANK_SELECT);
1589 if ((saved_bank & 0xff00) != 0x3300) {
1590 /* The device does not exist -- the card could be off-line, or
1591 maybe it has been ejected. */
1592 DEBUG(1, "%s: SMC91c92 interrupt %d for non-existent"
1593 "/ejected device.\n", dev->name, irq);
1594 handled = 0;
1595 goto irq_done;
1596 }
1597
1598 SMC_SELECT_BANK(2);
1599 saved_pointer = inw(ioaddr + POINTER);
1600 mask = inw(ioaddr + INTERRUPT) >> 8;
1601 /* clear all interrupts */
1602 outw(0, ioaddr + INTERRUPT);
1603
1604 do { /* read the status flag, and mask it */
1605 status = inw(ioaddr + INTERRUPT) & 0xff;
1606 DEBUG(3, "%s: Status is %#2.2x (mask %#2.2x).\n", dev->name,
1607 status, mask);
1608 if ((status & mask) == 0) {
1609 if (bogus_cnt == INTR_WORK)
1610 handled = 0;
1611 break;
1612 }
1613 if (status & IM_RCV_INT) {
1614 /* Got a packet(s). */
1615 smc_rx(dev);
1616 }
1617 if (status & IM_TX_INT) {
1618 smc_tx_err(dev);
1619 outw(IM_TX_INT, ioaddr + INTERRUPT);
1620 }
1621 status &= mask;
1622 if (status & IM_TX_EMPTY_INT) {
1623 outw(IM_TX_EMPTY_INT, ioaddr + INTERRUPT);
1624 mask &= ~IM_TX_EMPTY_INT;
1625 smc->stats.tx_packets += smc->packets_waiting;
1626 smc->packets_waiting = 0;
1627 }
1628 if (status & IM_ALLOC_INT) {
1629 /* Clear this interrupt so it doesn't happen again */
1630 mask &= ~IM_ALLOC_INT;
1631
1632 smc_hardware_send_packet(dev);
1633
1634 /* enable xmit interrupts based on this */
1635 mask |= (IM_TX_EMPTY_INT | IM_TX_INT);
1636
1637 /* and let the card send more packets to me */
1638 netif_wake_queue(dev);
1639 }
1640 if (status & IM_RX_OVRN_INT) {
1641 smc->stats.rx_errors++;
1642 smc->stats.rx_fifo_errors++;
1643 if (smc->duplex)
1644 smc->rx_ovrn = 1; /* need MC_RESET outside smc_interrupt */
1645 outw(IM_RX_OVRN_INT, ioaddr + INTERRUPT);
1646 }
1647 if (status & IM_EPH_INT)
1648 smc_eph_irq(dev);
1649 } while (--bogus_cnt);
1650
1651 DEBUG(3, " Restoring saved registers mask %2.2x bank %4.4x"
1652 " pointer %4.4x.\n", mask, saved_bank, saved_pointer);
1653
1654 /* restore state register */
1655 outw((mask<<8), ioaddr + INTERRUPT);
1656 outw(saved_pointer, ioaddr + POINTER);
1657 SMC_SELECT_BANK(saved_bank);
1658
1659 DEBUG(3, "%s: Exiting interrupt IRQ%d.\n", dev->name, irq);
1660
1661irq_done:
1662
1663 if ((smc->manfid == MANFID_OSITECH) &&
1664 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1665 /* Retrigger interrupt if needed */
1666 mask_bits(0x00ff, ioaddr-0x10+OSITECH_RESET_ISR);
1667 set_bits(0x0300, ioaddr-0x10+OSITECH_RESET_ISR);
1668 }
1669 if (smc->manfid == MANFID_MOTOROLA) {
1670 u_char cor;
1671 cor = readb(smc->base + MOT_UART + CISREG_COR);
1672 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_UART + CISREG_COR);
1673 writeb(cor, smc->base + MOT_UART + CISREG_COR);
1674 cor = readb(smc->base + MOT_LAN + CISREG_COR);
1675 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_LAN + CISREG_COR);
1676 writeb(cor, smc->base + MOT_LAN + CISREG_COR);
1677 }
1678#ifdef DOES_NOT_WORK
1679 if (smc->base != NULL) { /* Megahertz MFC's */
1680 readb(smc->base+MEGAHERTZ_ISR);
1681 readb(smc->base+MEGAHERTZ_ISR);
1682 }
1683#endif
1684 return IRQ_RETVAL(handled);
1685}
1686
1687/*====================================================================*/
1688
1689static void smc_rx(struct net_device *dev)
1690{
1691 struct smc_private *smc = netdev_priv(dev);
1692 kio_addr_t ioaddr = dev->base_addr;
1693 int rx_status;
1694 int packet_length; /* Caution: not frame length, rather words
1695 to transfer from the chip. */
1696
1697 /* Assertion: we are in Window 2. */
1698
1699 if (inw(ioaddr + FIFO_PORTS) & FP_RXEMPTY) {
1700 printk(KERN_ERR "%s: smc_rx() with nothing on Rx FIFO.\n",
1701 dev->name);
1702 return;
1703 }
1704
1705 /* Reset the read pointer, and read the status and packet length. */
1706 outw(PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER);
1707 rx_status = inw(ioaddr + DATA_1);
1708 packet_length = inw(ioaddr + DATA_1) & 0x07ff;
1709
1710 DEBUG(2, "%s: Receive status %4.4x length %d.\n",
1711 dev->name, rx_status, packet_length);
1712
1713 if (!(rx_status & RS_ERRORS)) {
1714 /* do stuff to make a new packet */
1715 struct sk_buff *skb;
1716
1717 /* Note: packet_length adds 5 or 6 extra bytes here! */
1718 skb = dev_alloc_skb(packet_length+2);
1719
1720 if (skb == NULL) {
1721 DEBUG(1, "%s: Low memory, packet dropped.\n", dev->name);
1722 smc->stats.rx_dropped++;
1723 outw(MC_RELEASE, ioaddr + MMU_CMD);
1724 return;
1725 }
1726
1727 packet_length -= (rx_status & RS_ODDFRAME ? 5 : 6);
1728 skb_reserve(skb, 2);
1729 insw(ioaddr+DATA_1, skb_put(skb, packet_length),
1730 (packet_length+1)>>1);
1731 skb->protocol = eth_type_trans(skb, dev);
1732
1733 skb->dev = dev;
1734 netif_rx(skb);
1735 dev->last_rx = jiffies;
1736 smc->stats.rx_packets++;
1737 smc->stats.rx_bytes += packet_length;
1738 if (rx_status & RS_MULTICAST)
1739 smc->stats.multicast++;
1740 } else {
1741 /* error ... */
1742 smc->stats.rx_errors++;
1743
1744 if (rx_status & RS_ALGNERR) smc->stats.rx_frame_errors++;
1745 if (rx_status & (RS_TOOSHORT | RS_TOOLONG))
1746 smc->stats.rx_length_errors++;
1747 if (rx_status & RS_BADCRC) smc->stats.rx_crc_errors++;
1748 }
1749 /* Let the MMU free the memory of this packet. */
1750 outw(MC_RELEASE, ioaddr + MMU_CMD);
1751
1752 return;
1753}
1754
1755/*====================================================================*/
1756
1757static struct net_device_stats *smc_get_stats(struct net_device *dev)
1758{
1759 struct smc_private *smc = netdev_priv(dev);
1760 /* Nothing to update - the 91c92 is a pretty primative chip. */
1761 return &smc->stats;
1762}
1763
1764/*======================================================================
1765
1766 Calculate values for the hardware multicast filter hash table.
1767
1768======================================================================*/
1769
1770static void fill_multicast_tbl(int count, struct dev_mc_list *addrs,
1771 u_char *multicast_table)
1772{
1773 struct dev_mc_list *mc_addr;
1774
Komurobb53d6d2005-10-03 22:03:28 -04001775 for (mc_addr = addrs; mc_addr && count-- > 0; mc_addr = mc_addr->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 u_int position = ether_crc(6, mc_addr->dmi_addr);
1777#ifndef final_version /* Verify multicast address. */
1778 if ((mc_addr->dmi_addr[0] & 1) == 0)
1779 continue;
1780#endif
1781 multicast_table[position >> 29] |= 1 << ((position >> 26) & 7);
1782 }
1783}
1784
1785/*======================================================================
1786
1787 Set the receive mode.
1788
1789 This routine is used by both the protocol level to notify us of
1790 promiscuous/multicast mode changes, and by the open/reset code to
1791 initialize the Rx registers. We always set the multicast list and
1792 leave the receiver running.
1793
1794======================================================================*/
1795
1796static void set_rx_mode(struct net_device *dev)
1797{
1798 kio_addr_t ioaddr = dev->base_addr;
1799 struct smc_private *smc = netdev_priv(dev);
1800 u_int multicast_table[ 2 ] = { 0, };
1801 unsigned long flags;
1802 u_short rx_cfg_setting;
1803
1804 if (dev->flags & IFF_PROMISC) {
1805 printk(KERN_NOTICE "%s: setting Rx mode to promiscuous.\n", dev->name);
1806 rx_cfg_setting = RxStripCRC | RxEnable | RxPromisc | RxAllMulti;
1807 } else if (dev->flags & IFF_ALLMULTI)
1808 rx_cfg_setting = RxStripCRC | RxEnable | RxAllMulti;
1809 else {
1810 if (dev->mc_count) {
1811 fill_multicast_tbl(dev->mc_count, dev->mc_list,
1812 (u_char *)multicast_table);
1813 }
1814 rx_cfg_setting = RxStripCRC | RxEnable;
1815 }
1816
1817 /* Load MC table and Rx setting into the chip without interrupts. */
1818 spin_lock_irqsave(&smc->lock, flags);
1819 SMC_SELECT_BANK(3);
1820 outl(multicast_table[0], ioaddr + MULTICAST0);
1821 outl(multicast_table[1], ioaddr + MULTICAST4);
1822 SMC_SELECT_BANK(0);
1823 outw(rx_cfg_setting, ioaddr + RCR);
1824 SMC_SELECT_BANK(2);
1825 spin_unlock_irqrestore(&smc->lock, flags);
1826
1827 return;
1828}
1829
1830/*======================================================================
1831
1832 Senses when a card's config changes. Here, it's coax or TP.
1833
1834======================================================================*/
1835
1836static int s9k_config(struct net_device *dev, struct ifmap *map)
1837{
1838 struct smc_private *smc = netdev_priv(dev);
1839 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
1840 if (smc->cfg & CFG_MII_SELECT)
1841 return -EOPNOTSUPP;
1842 else if (map->port > 2)
1843 return -EINVAL;
1844 dev->if_port = map->port;
1845 printk(KERN_INFO "%s: switched to %s port\n",
1846 dev->name, if_names[dev->if_port]);
1847 smc_reset(dev);
1848 }
1849 return 0;
1850}
1851
1852/*======================================================================
1853
1854 Reset the chip, reloading every register that might be corrupted.
1855
1856======================================================================*/
1857
1858/*
1859 Set transceiver type, perhaps to something other than what the user
1860 specified in dev->if_port.
1861*/
1862static void smc_set_xcvr(struct net_device *dev, int if_port)
1863{
1864 struct smc_private *smc = netdev_priv(dev);
1865 kio_addr_t ioaddr = dev->base_addr;
1866 u_short saved_bank;
1867
1868 saved_bank = inw(ioaddr + BANK_SELECT);
1869 SMC_SELECT_BANK(1);
1870 if (if_port == 2) {
1871 outw(smc->cfg | CFG_AUI_SELECT, ioaddr + CONFIG);
1872 if ((smc->manfid == MANFID_OSITECH) &&
1873 (smc->cardid != PRODID_OSITECH_SEVEN))
1874 set_bits(OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1875 smc->media_status = ((dev->if_port == 0) ? 0x0001 : 0x0002);
1876 } else {
1877 outw(smc->cfg, ioaddr + CONFIG);
1878 if ((smc->manfid == MANFID_OSITECH) &&
1879 (smc->cardid != PRODID_OSITECH_SEVEN))
1880 mask_bits(~OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1881 smc->media_status = ((dev->if_port == 0) ? 0x0012 : 0x4001);
1882 }
1883 SMC_SELECT_BANK(saved_bank);
1884}
1885
1886static void smc_reset(struct net_device *dev)
1887{
1888 kio_addr_t ioaddr = dev->base_addr;
1889 struct smc_private *smc = netdev_priv(dev);
1890 int i;
1891
1892 DEBUG(0, "%s: smc91c92 reset called.\n", dev->name);
1893
1894 /* The first interaction must be a write to bring the chip out
1895 of sleep mode. */
1896 SMC_SELECT_BANK(0);
1897 /* Reset the chip. */
1898 outw(RCR_SOFTRESET, ioaddr + RCR);
1899 udelay(10);
1900
1901 /* Clear the transmit and receive configuration registers. */
1902 outw(RCR_CLEAR, ioaddr + RCR);
1903 outw(TCR_CLEAR, ioaddr + TCR);
1904
1905 /* Set the Window 1 control, configuration and station addr registers.
1906 No point in writing the I/O base register ;-> */
1907 SMC_SELECT_BANK(1);
1908 /* Automatically release succesfully transmitted packets,
1909 Accept link errors, counter and Tx error interrupts. */
1910 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1911 ioaddr + CONTROL);
1912 smc_set_xcvr(dev, dev->if_port);
1913 if ((smc->manfid == MANFID_OSITECH) &&
1914 (smc->cardid != PRODID_OSITECH_SEVEN))
1915 outw((dev->if_port == 2 ? OSI_AUI_PWR : 0) |
1916 (inw(ioaddr-0x10+OSITECH_AUI_PWR) & 0xff00),
1917 ioaddr - 0x10 + OSITECH_AUI_PWR);
1918
1919 /* Fill in the physical address. The databook is wrong about the order! */
1920 for (i = 0; i < 6; i += 2)
1921 outw((dev->dev_addr[i+1]<<8)+dev->dev_addr[i],
1922 ioaddr + ADDR0 + i);
1923
1924 /* Reset the MMU */
1925 SMC_SELECT_BANK(2);
1926 outw(MC_RESET, ioaddr + MMU_CMD);
1927 outw(0, ioaddr + INTERRUPT);
1928
1929 /* Re-enable the chip. */
1930 SMC_SELECT_BANK(0);
1931 outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) |
1932 TCR_ENABLE | TCR_PAD_EN | smc->duplex, ioaddr + TCR);
1933 set_rx_mode(dev);
1934
1935 if (smc->cfg & CFG_MII_SELECT) {
1936 SMC_SELECT_BANK(3);
1937
1938 /* Reset MII */
1939 mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000);
1940
1941 /* Advertise 100F, 100H, 10F, 10H */
1942 mdio_write(dev, smc->mii_if.phy_id, 4, 0x01e1);
1943
1944 /* Restart MII autonegotiation */
1945 mdio_write(dev, smc->mii_if.phy_id, 0, 0x0000);
1946 mdio_write(dev, smc->mii_if.phy_id, 0, 0x1200);
1947 }
1948
1949 /* Enable interrupts. */
1950 SMC_SELECT_BANK(2);
1951 outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,
1952 ioaddr + INTERRUPT);
1953}
1954
1955/*======================================================================
1956
1957 Media selection timer routine
1958
1959======================================================================*/
1960
1961static void media_check(u_long arg)
1962{
1963 struct net_device *dev = (struct net_device *) arg;
1964 struct smc_private *smc = netdev_priv(dev);
1965 kio_addr_t ioaddr = dev->base_addr;
1966 u_short i, media, saved_bank;
1967 u_short link;
1968
1969 saved_bank = inw(ioaddr + BANK_SELECT);
1970
1971 if (!netif_device_present(dev))
1972 goto reschedule;
1973
1974 SMC_SELECT_BANK(2);
1975
1976 /* need MC_RESET to keep the memory consistent. errata? */
1977 if (smc->rx_ovrn) {
1978 outw(MC_RESET, ioaddr + MMU_CMD);
1979 smc->rx_ovrn = 0;
1980 }
1981 i = inw(ioaddr + INTERRUPT);
1982 SMC_SELECT_BANK(0);
1983 media = inw(ioaddr + EPH) & EPH_LINK_OK;
1984 SMC_SELECT_BANK(1);
1985 media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1;
1986
1987 /* Check for pending interrupt with watchdog flag set: with
1988 this, we can limp along even if the interrupt is blocked */
1989 if (smc->watchdog++ && ((i>>8) & i)) {
1990 if (!smc->fast_poll)
1991 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
1992 smc_interrupt(dev->irq, smc, NULL);
1993 smc->fast_poll = HZ;
1994 }
1995 if (smc->fast_poll) {
1996 smc->fast_poll--;
1997 smc->media.expires = jiffies + HZ/100;
1998 add_timer(&smc->media);
1999 SMC_SELECT_BANK(saved_bank);
2000 return;
2001 }
2002
2003 if (smc->cfg & CFG_MII_SELECT) {
2004 if (smc->mii_if.phy_id < 0)
2005 goto reschedule;
2006
2007 SMC_SELECT_BANK(3);
2008 link = mdio_read(dev, smc->mii_if.phy_id, 1);
2009 if (!link || (link == 0xffff)) {
2010 printk(KERN_INFO "%s: MII is missing!\n", dev->name);
2011 smc->mii_if.phy_id = -1;
2012 goto reschedule;
2013 }
2014
2015 link &= 0x0004;
2016 if (link != smc->link_status) {
2017 u_short p = mdio_read(dev, smc->mii_if.phy_id, 5);
2018 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2019 (link) ? "found" : "lost");
2020 smc->duplex = (((p & 0x0100) || ((p & 0x1c0) == 0x40))
2021 ? TCR_FDUPLX : 0);
2022 if (link) {
2023 printk(KERN_INFO "%s: autonegotiation complete: "
2024 "%sbaseT-%cD selected\n", dev->name,
2025 ((p & 0x0180) ? "100" : "10"),
2026 (smc->duplex ? 'F' : 'H'));
2027 }
2028 SMC_SELECT_BANK(0);
2029 outw(inw(ioaddr + TCR) | smc->duplex, ioaddr + TCR);
2030 smc->link_status = link;
2031 }
2032 goto reschedule;
2033 }
2034
2035 /* Ignore collisions unless we've had no rx's recently */
Marcelo Feitoza Parisi4851d3a2005-07-15 10:00:41 -07002036 if (time_after(jiffies, dev->last_rx + HZ)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 if (smc->tx_err || (smc->media_status & EPH_16COL))
2038 media |= EPH_16COL;
2039 }
2040 smc->tx_err = 0;
2041
2042 if (media != smc->media_status) {
2043 if ((media & smc->media_status & 1) &&
2044 ((smc->media_status ^ media) & EPH_LINK_OK))
2045 printk(KERN_INFO "%s: %s link beat\n", dev->name,
2046 (smc->media_status & EPH_LINK_OK ? "lost" : "found"));
2047 else if ((media & smc->media_status & 2) &&
2048 ((smc->media_status ^ media) & EPH_16COL))
2049 printk(KERN_INFO "%s: coax cable %s\n", dev->name,
2050 (media & EPH_16COL ? "problem" : "ok"));
2051 if (dev->if_port == 0) {
2052 if (media & 1) {
2053 if (media & EPH_LINK_OK)
2054 printk(KERN_INFO "%s: flipped to 10baseT\n",
2055 dev->name);
2056 else
2057 smc_set_xcvr(dev, 2);
2058 } else {
2059 if (media & EPH_16COL)
2060 smc_set_xcvr(dev, 1);
2061 else
2062 printk(KERN_INFO "%s: flipped to 10base2\n",
2063 dev->name);
2064 }
2065 }
2066 smc->media_status = media;
2067 }
2068
2069reschedule:
2070 smc->media.expires = jiffies + HZ;
2071 add_timer(&smc->media);
2072 SMC_SELECT_BANK(saved_bank);
2073}
2074
2075static int smc_link_ok(struct net_device *dev)
2076{
2077 kio_addr_t ioaddr = dev->base_addr;
2078 struct smc_private *smc = netdev_priv(dev);
2079
2080 if (smc->cfg & CFG_MII_SELECT) {
2081 return mii_link_ok(&smc->mii_if);
2082 } else {
2083 SMC_SELECT_BANK(0);
2084 return inw(ioaddr + EPH) & EPH_LINK_OK;
2085 }
2086}
2087
2088static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2089{
2090 u16 tmp;
2091 kio_addr_t ioaddr = dev->base_addr;
2092
2093 ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |
2094 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);
2095
2096 SMC_SELECT_BANK(1);
2097 tmp = inw(ioaddr + CONFIG);
2098 ecmd->port = (tmp & CFG_AUI_SELECT) ? PORT_AUI : PORT_TP;
2099 ecmd->transceiver = XCVR_INTERNAL;
2100 ecmd->speed = SPEED_10;
2101 ecmd->phy_address = ioaddr + MGMT;
2102
2103 SMC_SELECT_BANK(0);
2104 tmp = inw(ioaddr + TCR);
2105 ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF;
2106
2107 return 0;
2108}
2109
2110static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
2111{
2112 u16 tmp;
2113 kio_addr_t ioaddr = dev->base_addr;
2114
2115 if (ecmd->speed != SPEED_10)
2116 return -EINVAL;
2117 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
2118 return -EINVAL;
2119 if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI)
2120 return -EINVAL;
2121 if (ecmd->transceiver != XCVR_INTERNAL)
2122 return -EINVAL;
2123
2124 if (ecmd->port == PORT_AUI)
2125 smc_set_xcvr(dev, 1);
2126 else
2127 smc_set_xcvr(dev, 0);
2128
2129 SMC_SELECT_BANK(0);
2130 tmp = inw(ioaddr + TCR);
2131 if (ecmd->duplex == DUPLEX_FULL)
2132 tmp |= TCR_FDUPLX;
2133 else
2134 tmp &= ~TCR_FDUPLX;
2135 outw(tmp, ioaddr + TCR);
2136
2137 return 0;
2138}
2139
2140static int check_if_running(struct net_device *dev)
2141{
2142 if (!netif_running(dev))
2143 return -EINVAL;
2144 return 0;
2145}
2146
2147static void smc_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2148{
2149 strcpy(info->driver, DRV_NAME);
2150 strcpy(info->version, DRV_VERSION);
2151}
2152
2153static int smc_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2154{
2155 struct smc_private *smc = netdev_priv(dev);
2156 kio_addr_t ioaddr = dev->base_addr;
2157 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2158 int ret;
2159
2160 SMC_SELECT_BANK(3);
2161 spin_lock_irq(&smc->lock);
2162 if (smc->cfg & CFG_MII_SELECT)
2163 ret = mii_ethtool_gset(&smc->mii_if, ecmd);
2164 else
2165 ret = smc_netdev_get_ecmd(dev, ecmd);
2166 spin_unlock_irq(&smc->lock);
2167 SMC_SELECT_BANK(saved_bank);
2168 return ret;
2169}
2170
2171static int smc_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2172{
2173 struct smc_private *smc = netdev_priv(dev);
2174 kio_addr_t ioaddr = dev->base_addr;
2175 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2176 int ret;
2177
2178 SMC_SELECT_BANK(3);
2179 spin_lock_irq(&smc->lock);
2180 if (smc->cfg & CFG_MII_SELECT)
2181 ret = mii_ethtool_sset(&smc->mii_if, ecmd);
2182 else
2183 ret = smc_netdev_set_ecmd(dev, ecmd);
2184 spin_unlock_irq(&smc->lock);
2185 SMC_SELECT_BANK(saved_bank);
2186 return ret;
2187}
2188
2189static u32 smc_get_link(struct net_device *dev)
2190{
2191 struct smc_private *smc = netdev_priv(dev);
2192 kio_addr_t ioaddr = dev->base_addr;
2193 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2194 u32 ret;
2195
2196 SMC_SELECT_BANK(3);
2197 spin_lock_irq(&smc->lock);
2198 ret = smc_link_ok(dev);
2199 spin_unlock_irq(&smc->lock);
2200 SMC_SELECT_BANK(saved_bank);
2201 return ret;
2202}
2203
2204#ifdef PCMCIA_DEBUG
2205static u32 smc_get_msglevel(struct net_device *dev)
2206{
2207 return pc_debug;
2208}
2209
2210static void smc_set_msglevel(struct net_device *dev, u32 val)
2211{
2212 pc_debug = val;
2213}
2214#endif
2215
2216static int smc_nway_reset(struct net_device *dev)
2217{
2218 struct smc_private *smc = netdev_priv(dev);
2219 if (smc->cfg & CFG_MII_SELECT) {
2220 kio_addr_t ioaddr = dev->base_addr;
2221 u16 saved_bank = inw(ioaddr + BANK_SELECT);
2222 int res;
2223
2224 SMC_SELECT_BANK(3);
2225 res = mii_nway_restart(&smc->mii_if);
2226 SMC_SELECT_BANK(saved_bank);
2227
2228 return res;
2229 } else
2230 return -EOPNOTSUPP;
2231}
2232
2233static struct ethtool_ops ethtool_ops = {
2234 .begin = check_if_running,
2235 .get_drvinfo = smc_get_drvinfo,
2236 .get_settings = smc_get_settings,
2237 .set_settings = smc_set_settings,
2238 .get_link = smc_get_link,
2239#ifdef PCMCIA_DEBUG
2240 .get_msglevel = smc_get_msglevel,
2241 .set_msglevel = smc_set_msglevel,
2242#endif
2243 .nway_reset = smc_nway_reset,
2244};
2245
2246static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
2247{
2248 struct smc_private *smc = netdev_priv(dev);
2249 struct mii_ioctl_data *mii = if_mii(rq);
2250 int rc = 0;
2251 u16 saved_bank;
2252 kio_addr_t ioaddr = dev->base_addr;
2253
2254 if (!netif_running(dev))
2255 return -EINVAL;
2256
2257 spin_lock_irq(&smc->lock);
2258 saved_bank = inw(ioaddr + BANK_SELECT);
2259 SMC_SELECT_BANK(3);
2260 rc = generic_mii_ioctl(&smc->mii_if, mii, cmd, NULL);
2261 SMC_SELECT_BANK(saved_bank);
2262 spin_unlock_irq(&smc->lock);
2263 return rc;
2264}
2265
Dominik Brodowski5c672222005-06-27 16:28:27 -07002266static struct pcmcia_device_id smc91c92_ids[] = {
2267 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0109, 0x0501),
2268 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0140, 0x000a),
2269 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63),
2270 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63),
2271 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef),
2272 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
2273 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
2274 PCMCIA_PFC_DEVICE_PROD_ID12(0, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
Komurod277ad02005-07-28 01:07:24 -07002275 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Diamonds Modem+Ethernet", 0xc2f80cd, 0x656947b9),
2276 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Hearts Modem+Ethernet", 0xc2f80cd, 0xdc9ba5ed),
Dominik Brodowski5c672222005-06-27 16:28:27 -07002277 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x016c, 0x0020),
2278 PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0023),
2279 PCMCIA_DEVICE_PROD_ID123("BASICS by New Media Corporation", "Ethernet", "SMC91C94", 0x23c78a9d, 0x00b2e941, 0xcef397fb),
2280 PCMCIA_DEVICE_PROD_ID12("ARGOSY", "Fast Ethernet PCCard", 0x78f308dc, 0xdcea68bc),
2281 PCMCIA_DEVICE_PROD_ID12("dit Co., Ltd.", "PC Card-10/100BTX", 0xe59365c8, 0x6a2161d1),
2282 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L100C", 0x6a26d1cf, 0xc16ce9c5),
2283 PCMCIA_DEVICE_PROD_ID12("Farallon", "Farallon Enet", 0x58d93fc4, 0x244734e9),
2284 PCMCIA_DEVICE_PROD_ID12("Megahertz", "CC10BT/2", 0x33234748, 0x3c95b953),
2285 PCMCIA_DEVICE_PROD_ID12("MELCO/SMC", "LPC-TX", 0xa2cd8e6d, 0x42da662a),
Komurod277ad02005-07-28 01:07:24 -07002286 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Four of Diamonds Ethernet", 0xc2f80cd, 0xb3466314),
2287 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Seven of Diamonds Ethernet", 0xc2f80cd, 0x194b650a),
Dominik Brodowski5c672222005-06-27 16:28:27 -07002288 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast Ethernet PCCard", 0x281f1c5d, 0xdcea68bc),
2289 PCMCIA_DEVICE_PROD_ID12("Psion", "10Mb Ethernet", 0x4ef00b21, 0x844be9e9),
2290 PCMCIA_DEVICE_PROD_ID12("SMC", "EtherEZ Ethernet 8020", 0xc4f8b18b, 0x4a0eeb2d),
2291 /* These conflict with other cards! */
2292 /* PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0100), */
2293 /* PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab), */
2294 PCMCIA_DEVICE_NULL,
2295};
2296MODULE_DEVICE_TABLE(pcmcia, smc91c92_ids);
2297
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298static struct pcmcia_driver smc91c92_cs_driver = {
2299 .owner = THIS_MODULE,
2300 .drv = {
2301 .name = "smc91c92_cs",
2302 },
Dominik Brodowskif8cfa612005-11-14 21:25:51 +01002303 .probe = smc91c92_attach,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +01002304 .remove = smc91c92_detach,
Dominik Brodowski5c672222005-06-27 16:28:27 -07002305 .id_table = smc91c92_ids,
Dominik Brodowski98e4c282005-11-14 21:21:18 +01002306 .suspend = smc91c92_suspend,
2307 .resume = smc91c92_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308};
2309
2310static int __init init_smc91c92_cs(void)
2311{
2312 return pcmcia_register_driver(&smc91c92_cs_driver);
2313}
2314
2315static void __exit exit_smc91c92_cs(void)
2316{
2317 pcmcia_unregister_driver(&smc91c92_cs_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318}
2319
2320module_init(init_smc91c92_cs);
2321module_exit(exit_smc91c92_cs);