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