1 /*======================================================================
3 A PCMCIA ethernet driver for SMC91c92-based cards.
5 This driver supports Megahertz PCMCIA ethernet cards; and
6 Megahertz, Motorola, Ositech, and Psion Dacom ethernet/modem
9 Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net
11 smc91c92_cs.c 1.122 2002/10/25 06:26:39
13 This driver contains code written by Donald Becker
14 (becker@scyld.com), Rowan Hughes (x-csrdh@jcu.edu.au),
15 David Hinds (dahinds@users.sourceforge.net), and Erik Stahlman
16 (erik@vt.edu). Donald wrote the SMC 91c92 code using parts of
17 Erik's SMC 91c94 driver. Rowan wrote a similar driver, and I've
18 incorporated some parts of his driver here. I (Dave) wrote most
19 of the PCMCIA glue code, and the Ositech support code. Kelly
20 Stephens (kstephen@holli.com) added support for the Motorola
21 Mariner, with help from Allen Brost.
23 This software may be used and distributed according to the terms of
24 the GNU General Public License, incorporated herein by reference.
26 ======================================================================*/
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/string.h>
33 #include <linux/timer.h>
34 #include <linux/interrupt.h>
35 #include <linux/delay.h>
36 #include <linux/crc32.h>
37 #include <linux/netdevice.h>
38 #include <linux/etherdevice.h>
39 #include <linux/skbuff.h>
40 #include <linux/if_arp.h>
41 #include <linux/ioport.h>
42 #include <linux/ethtool.h>
43 #include <linux/mii.h>
45 #include <pcmcia/version.h>
46 #include <pcmcia/cs_types.h>
47 #include <pcmcia/cs.h>
48 #include <pcmcia/cistpl.h>
49 #include <pcmcia/cisreg.h>
50 #include <pcmcia/ciscode.h>
51 #include <pcmcia/ds.h>
54 #include <asm/system.h>
55 #include <asm/uaccess.h>
57 /* Ositech Seven of Diamonds firmware */
60 /*====================================================================*/
62 static char *if_names
[] = { "auto", "10baseT", "10base2"};
64 /* Module parameters */
66 MODULE_DESCRIPTION("SMC 91c92 series PCMCIA ethernet driver");
67 MODULE_LICENSE("GPL");
69 #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
72 Transceiver/media type.
74 1 = 10baseT (and autoselect if #define AUTOSELECT),
77 INT_MODULE_PARM(if_port
, 0);
80 INT_MODULE_PARM(pc_debug
, PCMCIA_DEBUG
);
81 static const char *version
=
82 "smc91c92_cs.c 0.09 1996/8/4 Donald Becker, becker@scyld.com.\n";
83 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
85 #define DEBUG(n, args...)
88 #define DRV_NAME "smc91c92_cs"
89 #define DRV_VERSION "1.122"
91 /*====================================================================*/
93 /* Operational parameter that usually are not changed. */
95 /* Time in jiffies before concluding Tx hung */
96 #define TX_TIMEOUT ((400*HZ)/1000)
98 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
101 /* Times to check the check the chip before concluding that it doesn't
102 currently have room for another Tx packet. */
103 #define MEMORY_WAIT_TIME 8
105 static dev_info_t dev_info
= "smc91c92_cs";
107 static dev_link_t
*dev_list
;
114 struct net_device_stats stats
;
116 struct sk_buff
*saved_skb
;
120 struct timer_list media
;
121 int watchdog
, tx_err
;
122 u_short media_status
;
125 struct mii_if_info mii_if
;
130 /* Special definitions for Megahertz multifunction cards */
131 #define MEGAHERTZ_ISR 0x0380
133 /* Special function registers for Motorola Mariner */
134 #define MOT_LAN 0x0000
135 #define MOT_UART 0x0020
136 #define MOT_EEPROM 0x20
139 (COR_LEVEL_REQ | COR_FUNC_ENA | COR_ADDR_DECODE | COR_IREQ_ENA)
141 /* Special function registers for Ositech cards */
142 #define OSITECH_AUI_CTL 0x0c
143 #define OSITECH_PWRDOWN 0x0d
144 #define OSITECH_RESET 0x0e
145 #define OSITECH_ISR 0x0f
146 #define OSITECH_AUI_PWR 0x0c
147 #define OSITECH_RESET_ISR 0x0e
149 #define OSI_AUI_PWR 0x40
150 #define OSI_LAN_PWRDOWN 0x02
151 #define OSI_MODEM_PWRDOWN 0x01
152 #define OSI_LAN_RESET 0x02
153 #define OSI_MODEM_RESET 0x01
155 /* Symbolic constants for the SMC91c9* series chips, from Erik Stahlman. */
156 #define BANK_SELECT 14 /* Window select register. */
157 #define SMC_SELECT_BANK(x) { outw(x, ioaddr + BANK_SELECT); }
159 /* Bank 0 registers. */
160 #define TCR 0 /* transmit control register */
161 #define TCR_CLEAR 0 /* do NOTHING */
162 #define TCR_ENABLE 0x0001 /* if this is 1, we can transmit */
163 #define TCR_PAD_EN 0x0080 /* pads short packets to 64 bytes */
164 #define TCR_MONCSN 0x0400 /* Monitor Carrier. */
165 #define TCR_FDUPLX 0x0800 /* Full duplex mode. */
166 #define TCR_NORMAL TCR_ENABLE | TCR_PAD_EN
168 #define EPH 2 /* Ethernet Protocol Handler report. */
169 #define EPH_TX_SUC 0x0001
170 #define EPH_SNGLCOL 0x0002
171 #define EPH_MULCOL 0x0004
172 #define EPH_LTX_MULT 0x0008
173 #define EPH_16COL 0x0010
174 #define EPH_SQET 0x0020
175 #define EPH_LTX_BRD 0x0040
176 #define EPH_TX_DEFR 0x0080
177 #define EPH_LAT_COL 0x0200
178 #define EPH_LOST_CAR 0x0400
179 #define EPH_EXC_DEF 0x0800
180 #define EPH_CTR_ROL 0x1000
181 #define EPH_RX_OVRN 0x2000
182 #define EPH_LINK_OK 0x4000
183 #define EPH_TX_UNRN 0x8000
184 #define MEMINFO 8 /* Memory Information Register */
185 #define MEMCFG 10 /* Memory Configuration Register */
187 /* Bank 1 registers. */
189 #define CFG_MII_SELECT 0x8000 /* 91C100 only */
190 #define CFG_NO_WAIT 0x1000
191 #define CFG_FULL_STEP 0x0400
192 #define CFG_SET_SQLCH 0x0200
193 #define CFG_AUI_SELECT 0x0100
194 #define CFG_16BIT 0x0080
195 #define CFG_DIS_LINK 0x0040
196 #define CFG_STATIC 0x0030
197 #define CFG_IRQ_SEL_1 0x0004
198 #define CFG_IRQ_SEL_0 0x0002
203 #define CTL_STORE 0x0001
204 #define CTL_RELOAD 0x0002
205 #define CTL_EE_SELECT 0x0004
206 #define CTL_TE_ENABLE 0x0020
207 #define CTL_CR_ENABLE 0x0040
208 #define CTL_LE_ENABLE 0x0080
209 #define CTL_AUTO_RELEASE 0x0800
210 #define CTL_POWERDOWN 0x2000
212 /* Bank 2 registers. */
214 #define MC_ALLOC 0x20 /* or with number of 256 byte packets */
215 #define MC_RESET 0x40
216 #define MC_RELEASE 0x80 /* remove and release the current rx packet */
217 #define MC_FREEPKT 0xA0 /* Release packet in PNR register */
218 #define MC_ENQUEUE 0xC0 /* Enqueue the packet for transmit */
221 #define FP_RXEMPTY 0x8000
223 #define PTR_AUTO_INC 0x0040
224 #define PTR_READ 0x2000
225 #define PTR_AUTOINC 0x4000
226 #define PTR_RCV 0x8000
229 #define IM_RCV_INT 0x1
230 #define IM_TX_INT 0x2
231 #define IM_TX_EMPTY_INT 0x4
232 #define IM_ALLOC_INT 0x8
233 #define IM_RX_OVRN_INT 0x10
234 #define IM_EPH_INT 0x20
237 enum RxCfg
{ RxAllMulti
= 0x0004, RxPromisc
= 0x0002,
238 RxEnable
= 0x0100, RxStripCRC
= 0x0200};
239 #define RCR_SOFTRESET 0x8000 /* resets the chip */
240 #define RCR_STRIP_CRC 0x200 /* strips CRC */
241 #define RCR_ENABLE 0x100 /* IFF this is set, we can receive packets */
242 #define RCR_ALMUL 0x4 /* receive all multicast packets */
243 #define RCR_PROMISC 0x2 /* enable promiscuous mode */
245 /* the normal settings for the RCR register : */
246 #define RCR_NORMAL (RCR_STRIP_CRC | RCR_ENABLE)
247 #define RCR_CLEAR 0x0 /* set it to a base state */
250 /* BANK 3 -- not the same values as in smc9194! */
256 #define REVISION 0x0a
258 /* Transmit status bits. */
259 #define TS_SUCCESS 0x0001
260 #define TS_16COL 0x0010
261 #define TS_LATCOL 0x0200
262 #define TS_LOSTCAR 0x0400
264 /* Receive status bits. */
265 #define RS_ALGNERR 0x8000
266 #define RS_BADCRC 0x2000
267 #define RS_ODDFRAME 0x1000
268 #define RS_TOOLONG 0x0800
269 #define RS_TOOSHORT 0x0400
270 #define RS_MULTICAST 0x0001
271 #define RS_ERRORS (RS_ALGNERR | RS_BADCRC | RS_TOOLONG | RS_TOOSHORT)
273 #define set_bits(v, p) outw(inw(p)|(v), (p))
274 #define mask_bits(v, p) outw(inw(p)&(v), (p))
276 /*====================================================================*/
278 static dev_link_t
*smc91c92_attach(void);
279 static void smc91c92_detach(dev_link_t
*);
280 static void smc91c92_config(dev_link_t
*link
);
281 static void smc91c92_release(dev_link_t
*link
);
282 static int smc91c92_event(event_t event
, int priority
,
283 event_callback_args_t
*args
);
285 static int smc_open(struct net_device
*dev
);
286 static int smc_close(struct net_device
*dev
);
287 static int smc_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
288 static void smc_tx_timeout(struct net_device
*dev
);
289 static int smc_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
290 static irqreturn_t
smc_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
291 static void smc_rx(struct net_device
*dev
);
292 static struct net_device_stats
*smc_get_stats(struct net_device
*dev
);
293 static void set_rx_mode(struct net_device
*dev
);
294 static int s9k_config(struct net_device
*dev
, struct ifmap
*map
);
295 static void smc_set_xcvr(struct net_device
*dev
, int if_port
);
296 static void smc_reset(struct net_device
*dev
);
297 static void media_check(u_long arg
);
298 static void mdio_sync(kio_addr_t addr
);
299 static int mdio_read(struct net_device
*dev
, int phy_id
, int loc
);
300 static void mdio_write(struct net_device
*dev
, int phy_id
, int loc
, int value
);
301 static int smc_link_ok(struct net_device
*dev
);
302 static struct ethtool_ops ethtool_ops
;
304 /*======================================================================
306 smc91c92_attach() creates an "instance" of the driver, allocating
307 local data structures for one device. The device is registered
310 ======================================================================*/
312 static dev_link_t
*smc91c92_attach(void)
314 client_reg_t client_reg
;
315 struct smc_private
*smc
;
317 struct net_device
*dev
;
320 DEBUG(0, "smc91c92_attach()\n");
322 /* Create new ethernet device */
323 dev
= alloc_etherdev(sizeof(struct smc_private
));
326 smc
= netdev_priv(dev
);
330 spin_lock_init(&smc
->lock
);
331 link
->io
.NumPorts1
= 16;
332 link
->io
.Attributes1
= IO_DATA_PATH_WIDTH_AUTO
;
333 link
->io
.IOAddrLines
= 4;
334 link
->irq
.Attributes
= IRQ_TYPE_EXCLUSIVE
| IRQ_HANDLE_PRESENT
;
335 link
->irq
.IRQInfo1
= IRQ_LEVEL_ID
;
336 link
->irq
.Handler
= &smc_interrupt
;
337 link
->irq
.Instance
= dev
;
338 link
->conf
.Attributes
= CONF_ENABLE_IRQ
;
340 link
->conf
.IntType
= INT_MEMORY_AND_IO
;
342 /* The SMC91c92-specific entries in the device structure. */
343 SET_MODULE_OWNER(dev
);
344 dev
->hard_start_xmit
= &smc_start_xmit
;
345 dev
->get_stats
= &smc_get_stats
;
346 dev
->set_config
= &s9k_config
;
347 dev
->set_multicast_list
= &set_rx_mode
;
348 dev
->open
= &smc_open
;
349 dev
->stop
= &smc_close
;
350 dev
->do_ioctl
= &smc_ioctl
;
351 SET_ETHTOOL_OPS(dev
, ðtool_ops
);
352 #ifdef HAVE_TX_TIMEOUT
353 dev
->tx_timeout
= smc_tx_timeout
;
354 dev
->watchdog_timeo
= TX_TIMEOUT
;
357 smc
->mii_if
.dev
= dev
;
358 smc
->mii_if
.mdio_read
= mdio_read
;
359 smc
->mii_if
.mdio_write
= mdio_write
;
360 smc
->mii_if
.phy_id_mask
= 0x1f;
361 smc
->mii_if
.reg_num_mask
= 0x1f;
363 /* Register with Card Services */
364 link
->next
= dev_list
;
366 client_reg
.dev_info
= &dev_info
;
367 client_reg
.EventMask
= CS_EVENT_CARD_INSERTION
| CS_EVENT_CARD_REMOVAL
|
368 CS_EVENT_RESET_PHYSICAL
| CS_EVENT_CARD_RESET
|
369 CS_EVENT_PM_SUSPEND
| CS_EVENT_PM_RESUME
;
370 client_reg
.event_handler
= &smc91c92_event
;
371 client_reg
.Version
= 0x0210;
372 client_reg
.event_callback_args
.client_data
= link
;
373 ret
= pcmcia_register_client(&link
->handle
, &client_reg
);
375 cs_error(link
->handle
, RegisterClient
, ret
);
376 smc91c92_detach(link
);
381 } /* smc91c92_attach */
383 /*======================================================================
385 This deletes a driver "instance". The device is de-registered
386 with Card Services. If it has been released, all local data
387 structures are freed. Otherwise, the structures will be freed
388 when the device is released.
390 ======================================================================*/
392 static void smc91c92_detach(dev_link_t
*link
)
394 struct net_device
*dev
= link
->priv
;
397 DEBUG(0, "smc91c92_detach(0x%p)\n", link
);
399 /* Locate device structure */
400 for (linkp
= &dev_list
; *linkp
; linkp
= &(*linkp
)->next
)
401 if (*linkp
== link
) break;
406 unregister_netdev(dev
);
408 if (link
->state
& DEV_CONFIG
)
409 smc91c92_release(link
);
412 pcmcia_deregister_client(link
->handle
);
414 /* Unlink device structure, free bits */
417 } /* smc91c92_detach */
419 /*====================================================================*/
421 static int cvt_ascii_address(struct net_device
*dev
, char *s
)
427 for (i
= 0; i
< 6; i
++) {
429 for (j
= 0; j
< 2; j
++) {
432 da
+= ((c
>= '0') && (c
<= '9')) ?
433 (c
- '0') : ((c
& 0x0f) + 9);
435 dev
->dev_addr
[i
] = da
;
440 /*====================================================================*/
442 static int first_tuple(client_handle_t handle
, tuple_t
*tuple
,
447 if ((i
= pcmcia_get_first_tuple(handle
, tuple
)) != CS_SUCCESS
||
448 (i
= pcmcia_get_tuple_data(handle
, tuple
)) != CS_SUCCESS
)
450 return pcmcia_parse_tuple(handle
, tuple
, parse
);
453 static int next_tuple(client_handle_t handle
, tuple_t
*tuple
,
458 if ((i
= pcmcia_get_next_tuple(handle
, tuple
)) != CS_SUCCESS
||
459 (i
= pcmcia_get_tuple_data(handle
, tuple
)) != CS_SUCCESS
)
461 return pcmcia_parse_tuple(handle
, tuple
, parse
);
464 /*======================================================================
466 Configuration stuff for Megahertz cards
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
473 ======================================================================*/
475 static int mhz_3288_power(dev_link_t
*link
)
477 struct net_device
*dev
= link
->priv
;
478 struct smc_private
*smc
= netdev_priv(dev
);
481 /* Read the ISR twice... */
482 readb(smc
->base
+MEGAHERTZ_ISR
);
484 readb(smc
->base
+MEGAHERTZ_ISR
);
489 /* Now read and write the COR... */
490 tmp
= readb(smc
->base
+ link
->conf
.ConfigBase
+ CISREG_COR
);
492 writeb(tmp
, smc
->base
+ link
->conf
.ConfigBase
+ CISREG_COR
);
497 static int mhz_mfc_config(dev_link_t
*link
)
499 struct net_device
*dev
= link
->priv
;
500 struct smc_private
*smc
= netdev_priv(dev
);
504 cistpl_cftable_entry_t
*cf
= &parse
.cftable_entry
;
509 link
->conf
.Attributes
|= CONF_ENABLE_SPKR
;
510 link
->conf
.Status
= CCSR_AUDIO_ENA
;
511 link
->irq
.Attributes
=
512 IRQ_TYPE_DYNAMIC_SHARING
|IRQ_FIRST_SHARED
|IRQ_HANDLE_PRESENT
;
513 link
->io
.IOAddrLines
= 16;
514 link
->io
.Attributes2
= IO_DATA_PATH_WIDTH_8
;
515 link
->io
.NumPorts2
= 8;
517 tuple
.Attributes
= tuple
.TupleOffset
= 0;
518 tuple
.TupleData
= (cisdata_t
*)buf
;
519 tuple
.TupleDataMax
= sizeof(buf
);
520 tuple
.DesiredTuple
= CISTPL_CFTABLE_ENTRY
;
522 i
= first_tuple(link
->handle
, &tuple
, &parse
);
523 /* The Megahertz combo cards have modem-like CIS entries, so
524 we have to explicitly try a bunch of port combinations. */
525 while (i
== CS_SUCCESS
) {
526 link
->conf
.ConfigIndex
= cf
->index
;
527 link
->io
.BasePort2
= cf
->io
.win
[0].base
;
528 for (k
= 0; k
< 0x400; k
+= 0x10) {
529 if (k
& 0x80) continue;
530 link
->io
.BasePort1
= k
^ 0x300;
531 i
= pcmcia_request_io(link
->handle
, &link
->io
);
532 if (i
== CS_SUCCESS
) break;
534 if (i
== CS_SUCCESS
) break;
535 i
= next_tuple(link
->handle
, &tuple
, &parse
);
539 dev
->base_addr
= link
->io
.BasePort1
;
541 /* Allocate a memory window, for accessing the ISR */
542 req
.Attributes
= WIN_DATA_WIDTH_8
|WIN_MEMORY_TYPE_AM
|WIN_ENABLE
;
543 req
.Base
= req
.Size
= 0;
545 i
= pcmcia_request_window(&link
->handle
, &req
, &link
->win
);
548 smc
->base
= ioremap(req
.Base
, req
.Size
);
549 mem
.CardOffset
= mem
.Page
= 0;
550 if (smc
->manfid
== MANFID_MOTOROLA
)
551 mem
.CardOffset
= link
->conf
.ConfigBase
;
552 i
= pcmcia_map_mem_page(link
->win
, &mem
);
554 if ((i
== CS_SUCCESS
)
555 && (smc
->manfid
== MANFID_MEGAHERTZ
)
556 && (smc
->cardid
== PRODID_MEGAHERTZ_EM3288
))
557 mhz_3288_power(link
);
562 static int mhz_setup(dev_link_t
*link
)
564 client_handle_t handle
= link
->handle
;
565 struct net_device
*dev
= link
->priv
;
568 u_char buf
[255], *station_addr
;
570 tuple
.Attributes
= tuple
.TupleOffset
= 0;
571 tuple
.TupleData
= buf
;
572 tuple
.TupleDataMax
= sizeof(buf
);
574 /* Read the station address from the CIS. It is stored as the last
575 (fourth) string in the Version 1 Version/ID tuple. */
576 tuple
.DesiredTuple
= CISTPL_VERS_1
;
577 if (first_tuple(handle
, &tuple
, &parse
) != CS_SUCCESS
)
579 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
580 if (next_tuple(handle
, &tuple
, &parse
) != CS_SUCCESS
)
581 first_tuple(handle
, &tuple
, &parse
);
582 if (parse
.version_1
.ns
> 3) {
583 station_addr
= parse
.version_1
.str
+ parse
.version_1
.ofs
[3];
584 if (cvt_ascii_address(dev
, station_addr
) == 0)
588 /* Another possibility: for the EM3288, in a special tuple */
589 tuple
.DesiredTuple
= 0x81;
590 if (pcmcia_get_first_tuple(handle
, &tuple
) != CS_SUCCESS
)
592 if (pcmcia_get_tuple_data(handle
, &tuple
) != CS_SUCCESS
)
595 if (cvt_ascii_address(dev
, buf
) == 0)
601 /*======================================================================
603 Configuration stuff for the Motorola Mariner
605 mot_config() writes directly to the Mariner configuration
606 registers because the CIS is just bogus.
608 ======================================================================*/
610 static void mot_config(dev_link_t
*link
)
612 struct net_device
*dev
= link
->priv
;
613 struct smc_private
*smc
= netdev_priv(dev
);
614 kio_addr_t ioaddr
= dev
->base_addr
;
615 kio_addr_t iouart
= link
->io
.BasePort2
;
617 /* Set UART base address and force map with COR bit 1 */
618 writeb(iouart
& 0xff, smc
->base
+ MOT_UART
+ CISREG_IOBASE_0
);
619 writeb((iouart
>> 8) & 0xff, smc
->base
+ MOT_UART
+ CISREG_IOBASE_1
);
620 writeb(MOT_NORMAL
, smc
->base
+ MOT_UART
+ CISREG_COR
);
622 /* Set SMC base address and force map with COR bit 1 */
623 writeb(ioaddr
& 0xff, smc
->base
+ MOT_LAN
+ CISREG_IOBASE_0
);
624 writeb((ioaddr
>> 8) & 0xff, smc
->base
+ MOT_LAN
+ CISREG_IOBASE_1
);
625 writeb(MOT_NORMAL
, smc
->base
+ MOT_LAN
+ CISREG_COR
);
627 /* Wait for things to settle down */
631 static int mot_setup(dev_link_t
*link
)
633 struct net_device
*dev
= link
->priv
;
634 kio_addr_t ioaddr
= dev
->base_addr
;
638 /* Read Ethernet address from Serial EEPROM */
640 for (i
= 0; i
< 3; i
++) {
642 outw(MOT_EEPROM
+ i
, ioaddr
+ POINTER
);
644 outw((CTL_RELOAD
| CTL_EE_SELECT
), ioaddr
+ CONTROL
);
646 for (loop
= wait
= 0; loop
< 200; loop
++) {
648 wait
= ((CTL_RELOAD
| CTL_STORE
) & inw(ioaddr
+ CONTROL
));
649 if (wait
== 0) break;
655 addr
= inw(ioaddr
+ GENERAL
);
656 dev
->dev_addr
[2*i
] = addr
& 0xff;
657 dev
->dev_addr
[2*i
+1] = (addr
>> 8) & 0xff;
663 /*====================================================================*/
665 static int smc_config(dev_link_t
*link
)
667 struct net_device
*dev
= link
->priv
;
671 cistpl_cftable_entry_t
*cf
= &parse
.cftable_entry
;
674 tuple
.Attributes
= tuple
.TupleOffset
= 0;
675 tuple
.TupleData
= (cisdata_t
*)buf
;
676 tuple
.TupleDataMax
= sizeof(buf
);
677 tuple
.DesiredTuple
= CISTPL_CFTABLE_ENTRY
;
679 link
->io
.NumPorts1
= 16;
680 i
= first_tuple(link
->handle
, &tuple
, &parse
);
681 while (i
!= CS_NO_MORE_ITEMS
) {
682 if (i
== CS_SUCCESS
) {
683 link
->conf
.ConfigIndex
= cf
->index
;
684 link
->io
.BasePort1
= cf
->io
.win
[0].base
;
685 link
->io
.IOAddrLines
= cf
->io
.flags
& CISTPL_IO_LINES_MASK
;
686 i
= pcmcia_request_io(link
->handle
, &link
->io
);
687 if (i
== CS_SUCCESS
) break;
689 i
= next_tuple(link
->handle
, &tuple
, &parse
);
692 dev
->base_addr
= link
->io
.BasePort1
;
696 static int smc_setup(dev_link_t
*link
)
698 client_handle_t handle
= link
->handle
;
699 struct net_device
*dev
= link
->priv
;
702 cistpl_lan_node_id_t
*node_id
;
703 u_char buf
[255], *station_addr
;
706 tuple
.Attributes
= tuple
.TupleOffset
= 0;
707 tuple
.TupleData
= buf
;
708 tuple
.TupleDataMax
= sizeof(buf
);
710 /* Check for a LAN function extension tuple */
711 tuple
.DesiredTuple
= CISTPL_FUNCE
;
712 i
= first_tuple(handle
, &tuple
, &parse
);
713 while (i
== CS_SUCCESS
) {
714 if (parse
.funce
.type
== CISTPL_FUNCE_LAN_NODE_ID
)
716 i
= next_tuple(handle
, &tuple
, &parse
);
718 if (i
== CS_SUCCESS
) {
719 node_id
= (cistpl_lan_node_id_t
*)parse
.funce
.data
;
720 if (node_id
->nb
== 6) {
721 for (i
= 0; i
< 6; i
++)
722 dev
->dev_addr
[i
] = node_id
->id
[i
];
726 /* Try the third string in the Version 1 Version/ID tuple. */
727 tuple
.DesiredTuple
= CISTPL_VERS_1
;
728 if (first_tuple(handle
, &tuple
, &parse
) != CS_SUCCESS
)
730 station_addr
= parse
.version_1
.str
+ parse
.version_1
.ofs
[2];
731 if (cvt_ascii_address(dev
, station_addr
) == 0)
737 /*====================================================================*/
739 static int osi_config(dev_link_t
*link
)
741 struct net_device
*dev
= link
->priv
;
742 static kio_addr_t com
[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
745 link
->conf
.Attributes
|= CONF_ENABLE_SPKR
;
746 link
->conf
.Status
= CCSR_AUDIO_ENA
;
747 link
->irq
.Attributes
=
748 IRQ_TYPE_DYNAMIC_SHARING
|IRQ_FIRST_SHARED
|IRQ_HANDLE_PRESENT
;
749 link
->io
.NumPorts1
= 64;
750 link
->io
.Attributes2
= IO_DATA_PATH_WIDTH_8
;
751 link
->io
.NumPorts2
= 8;
752 link
->io
.IOAddrLines
= 16;
754 /* Enable Hard Decode, LAN, Modem */
755 link
->conf
.ConfigIndex
= 0x23;
757 for (i
= j
= 0; j
< 4; j
++) {
758 link
->io
.BasePort2
= com
[j
];
759 i
= pcmcia_request_io(link
->handle
, &link
->io
);
760 if (i
== CS_SUCCESS
) break;
762 if (i
!= CS_SUCCESS
) {
763 /* Fallback: turn off hard decode */
764 link
->conf
.ConfigIndex
= 0x03;
765 link
->io
.NumPorts2
= 0;
766 i
= pcmcia_request_io(link
->handle
, &link
->io
);
768 dev
->base_addr
= link
->io
.BasePort1
+ 0x10;
772 static int osi_setup(dev_link_t
*link
, u_short manfid
, u_short cardid
)
774 client_handle_t handle
= link
->handle
;
775 struct net_device
*dev
= link
->priv
;
780 tuple
.Attributes
= TUPLE_RETURN_COMMON
;
781 tuple
.TupleData
= buf
;
782 tuple
.TupleDataMax
= sizeof(buf
);
783 tuple
.TupleOffset
= 0;
785 /* Read the station address from tuple 0x90, subtuple 0x04 */
786 tuple
.DesiredTuple
= 0x90;
787 i
= pcmcia_get_first_tuple(handle
, &tuple
);
788 while (i
== CS_SUCCESS
) {
789 i
= pcmcia_get_tuple_data(handle
, &tuple
);
790 if ((i
!= CS_SUCCESS
) || (buf
[0] == 0x04))
792 i
= pcmcia_get_next_tuple(handle
, &tuple
);
796 for (i
= 0; i
< 6; i
++)
797 dev
->dev_addr
[i
] = buf
[i
+2];
799 if (((manfid
== MANFID_OSITECH
) &&
800 (cardid
== PRODID_OSITECH_SEVEN
)) ||
801 ((manfid
== MANFID_PSION
) &&
802 (cardid
== PRODID_PSION_NET100
))) {
803 /* Download the Seven of Diamonds firmware */
804 for (i
= 0; i
< sizeof(__Xilinx7OD
); i
++) {
805 outb(__Xilinx7OD
[i
], link
->io
.BasePort1
+2);
808 } else if (manfid
== MANFID_OSITECH
) {
809 /* Make sure both functions are powered up */
810 set_bits(0x300, link
->io
.BasePort1
+ OSITECH_AUI_PWR
);
811 /* Now, turn on the interrupt for both card functions */
812 set_bits(0x300, link
->io
.BasePort1
+ OSITECH_RESET_ISR
);
813 DEBUG(2, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n",
814 inw(link
->io
.BasePort1
+ OSITECH_AUI_PWR
),
815 inw(link
->io
.BasePort1
+ OSITECH_RESET_ISR
));
821 /*======================================================================
823 This verifies that the chip is some SMC91cXX variant, and returns
824 the revision code if successful. Otherwise, it returns -ENODEV.
826 ======================================================================*/
828 static int check_sig(dev_link_t
*link
)
830 struct net_device
*dev
= link
->priv
;
831 kio_addr_t ioaddr
= dev
->base_addr
;
836 if (inw(ioaddr
+ BANK_SELECT
) >> 8 != 0x33) {
837 /* Try powering up the chip */
838 outw(0, ioaddr
+ CONTROL
);
842 /* Try setting bus width */
843 width
= (link
->io
.Attributes1
== IO_DATA_PATH_WIDTH_AUTO
);
844 s
= inb(ioaddr
+ CONFIG
);
849 outb(s
, ioaddr
+ CONFIG
);
851 /* Check Base Address Register to make sure bus width is OK */
852 s
= inw(ioaddr
+ BASE_ADDR
);
853 if ((inw(ioaddr
+ BANK_SELECT
) >> 8 == 0x33) &&
854 ((s
>> 8) != (s
& 0xff))) {
856 s
= inw(ioaddr
+ REVISION
);
861 event_callback_args_t args
;
862 printk(KERN_INFO
"smc91c92_cs: using 8-bit IO window.\n");
863 args
.client_data
= link
;
864 smc91c92_event(CS_EVENT_RESET_PHYSICAL
, 0, &args
);
865 pcmcia_release_io(link
->handle
, &link
->io
);
866 link
->io
.Attributes1
= IO_DATA_PATH_WIDTH_8
;
867 pcmcia_request_io(link
->handle
, &link
->io
);
868 smc91c92_event(CS_EVENT_CARD_RESET
, 0, &args
);
869 return check_sig(link
);
874 /*======================================================================
876 smc91c92_config() is scheduled to run after a CARD_INSERTION event
877 is received, to configure the PCMCIA socket, and to make the
878 ethernet device available to the system.
880 ======================================================================*/
882 #define CS_EXIT_TEST(ret, svc, label) \
883 if (ret != CS_SUCCESS) { cs_error(link->handle, svc, ret); goto label; }
885 static void smc91c92_config(dev_link_t
*link
)
887 client_handle_t handle
= link
->handle
;
888 struct net_device
*dev
= link
->priv
;
889 struct smc_private
*smc
= netdev_priv(dev
);
898 DEBUG(0, "smc91c92_config(0x%p)\n", link
);
900 tuple
.Attributes
= tuple
.TupleOffset
= 0;
901 tuple
.TupleData
= (cisdata_t
*)buf
;
902 tuple
.TupleDataMax
= sizeof(buf
);
904 tuple
.DesiredTuple
= CISTPL_CONFIG
;
905 i
= first_tuple(handle
, &tuple
, &parse
);
906 CS_EXIT_TEST(i
, ParseTuple
, config_failed
);
907 link
->conf
.ConfigBase
= parse
.config
.base
;
908 link
->conf
.Present
= parse
.config
.rmask
[0];
910 tuple
.DesiredTuple
= CISTPL_MANFID
;
911 tuple
.Attributes
= TUPLE_RETURN_COMMON
;
912 if (first_tuple(handle
, &tuple
, &parse
) == CS_SUCCESS
) {
913 smc
->manfid
= parse
.manfid
.manf
;
914 smc
->cardid
= parse
.manfid
.card
;
918 link
->state
|= DEV_CONFIG
;
920 if ((smc
->manfid
== MANFID_OSITECH
) &&
921 (smc
->cardid
!= PRODID_OSITECH_SEVEN
)) {
922 i
= osi_config(link
);
923 } else if ((smc
->manfid
== MANFID_MOTOROLA
) ||
924 ((smc
->manfid
== MANFID_MEGAHERTZ
) &&
925 ((smc
->cardid
== PRODID_MEGAHERTZ_VARIOUS
) ||
926 (smc
->cardid
== PRODID_MEGAHERTZ_EM3288
)))) {
927 i
= mhz_mfc_config(link
);
929 i
= smc_config(link
);
931 CS_EXIT_TEST(i
, RequestIO
, config_failed
);
933 i
= pcmcia_request_irq(link
->handle
, &link
->irq
);
934 CS_EXIT_TEST(i
, RequestIRQ
, config_failed
);
935 i
= pcmcia_request_configuration(link
->handle
, &link
->conf
);
936 CS_EXIT_TEST(i
, RequestConfiguration
, config_failed
);
938 if (smc
->manfid
== MANFID_MOTOROLA
)
941 dev
->irq
= link
->irq
.AssignedIRQ
;
943 if ((if_port
>= 0) && (if_port
<= 2))
944 dev
->if_port
= if_port
;
946 printk(KERN_NOTICE
"smc91c92_cs: invalid if_port requested\n");
948 switch (smc
->manfid
) {
951 i
= osi_setup(link
, smc
->manfid
, smc
->cardid
); break;
953 case MANFID_NEW_MEDIA
:
954 i
= smc_setup(link
); break;
955 case 0x128: /* For broken Megahertz cards */
956 case MANFID_MEGAHERTZ
:
957 i
= mhz_setup(link
); break;
958 case MANFID_MOTOROLA
:
959 default: /* get the hw address from EEPROM */
960 i
= mot_setup(link
); break;
964 printk(KERN_NOTICE
"smc91c92_cs: Unable to find hardware address.\n");
971 rev
= check_sig(link
);
975 case 3: name
= "92"; break;
976 case 4: name
= ((rev
& 15) >= 6) ? "96" : "94"; break;
977 case 5: name
= "95"; break;
978 case 7: name
= "100"; break;
979 case 8: name
= "100-FD"; break;
980 case 9: name
= "110"; break;
983 ioaddr
= dev
->base_addr
;
987 mir
= inw(ioaddr
+ MEMINFO
) & 0xff;
988 if (mir
== 0xff) mir
++;
989 /* Get scale factor for memory size */
990 mcr
= ((rev
>> 4) > 3) ? inw(ioaddr
+ MEMCFG
) : 0x0200;
991 mir
*= 128 * (1<<((mcr
>> 9) & 7));
993 smc
->cfg
= inw(ioaddr
+ CONFIG
) & ~CFG_AUI_SELECT
;
994 smc
->cfg
|= CFG_NO_WAIT
| CFG_16BIT
| CFG_STATIC
;
995 if (smc
->manfid
== MANFID_OSITECH
)
996 smc
->cfg
|= CFG_IRQ_SEL_1
| CFG_IRQ_SEL_0
;
998 smc
->cfg
|= CFG_MII_SELECT
;
1002 if (smc
->cfg
& CFG_MII_SELECT
) {
1005 for (i
= 0; i
< 32; i
++) {
1006 j
= mdio_read(dev
, i
, 1);
1007 if ((j
!= 0) && (j
!= 0xffff)) break;
1009 smc
->mii_if
.phy_id
= (i
< 32) ? i
: -1;
1014 link
->dev
= &smc
->node
;
1015 link
->state
&= ~DEV_CONFIG_PENDING
;
1016 SET_NETDEV_DEV(dev
, &handle_to_dev(handle
));
1018 if (register_netdev(dev
) != 0) {
1019 printk(KERN_ERR
"smc91c92_cs: register_netdev() failed\n");
1024 strcpy(smc
->node
.dev_name
, dev
->name
);
1026 printk(KERN_INFO
"%s: smc91c%s rev %d: io %#3lx, irq %d, "
1027 "hw_addr ", dev
->name
, name
, (rev
& 0x0f), dev
->base_addr
,
1029 for (i
= 0; i
< 6; i
++)
1030 printk("%02X%s", dev
->dev_addr
[i
], ((i
<5) ? ":" : "\n"));
1034 printk(KERN_INFO
" %lu byte", mir
);
1036 printk(KERN_INFO
" %lu kb", mir
>>10);
1037 printk(" buffer, %s xcvr\n", (smc
->cfg
& CFG_MII_SELECT
) ?
1038 "MII" : if_names
[dev
->if_port
]);
1041 if (smc
->cfg
& CFG_MII_SELECT
) {
1042 if (smc
->mii_if
.phy_id
!= -1) {
1043 DEBUG(0, " MII transceiver at index %d, status %x.\n",
1044 smc
->mii_if
.phy_id
, j
);
1046 printk(KERN_NOTICE
" No MII transceivers found!\n");
1053 unregister_netdev(dev
);
1054 config_failed
: /* CS_EXIT_TEST() calls jump to here... */
1055 smc91c92_release(link
);
1056 link
->state
&= ~DEV_CONFIG_PENDING
;
1058 } /* smc91c92_config */
1060 /*======================================================================
1062 After a card is removed, smc91c92_release() will unregister the net
1063 device, and release the PCMCIA configuration. If the device is
1064 still open, this will be postponed until it is closed.
1066 ======================================================================*/
1068 static void smc91c92_release(dev_link_t
*link
)
1071 DEBUG(0, "smc91c92_release(0x%p)\n", link
);
1073 pcmcia_release_configuration(link
->handle
);
1074 pcmcia_release_io(link
->handle
, &link
->io
);
1075 pcmcia_release_irq(link
->handle
, &link
->irq
);
1077 struct net_device
*dev
= link
->priv
;
1078 struct smc_private
*smc
= netdev_priv(dev
);
1080 pcmcia_release_window(link
->win
);
1083 link
->state
&= ~DEV_CONFIG
;
1086 /*======================================================================
1088 The card status event handler. Mostly, this schedules other
1089 stuff to run after an event is received. A CARD_REMOVAL event
1090 also sets some flags to discourage the net drivers from trying
1091 to talk to the card any more.
1093 ======================================================================*/
1095 static int smc91c92_event(event_t event
, int priority
,
1096 event_callback_args_t
*args
)
1098 dev_link_t
*link
= args
->client_data
;
1099 struct net_device
*dev
= link
->priv
;
1100 struct smc_private
*smc
= netdev_priv(dev
);
1103 DEBUG(1, "smc91c92_event(0x%06x)\n", event
);
1106 case CS_EVENT_CARD_REMOVAL
:
1107 link
->state
&= ~DEV_PRESENT
;
1108 if (link
->state
& DEV_CONFIG
)
1109 netif_device_detach(dev
);
1111 case CS_EVENT_CARD_INSERTION
:
1112 link
->state
|= DEV_PRESENT
| DEV_CONFIG_PENDING
;
1113 smc91c92_config(link
);
1115 case CS_EVENT_PM_SUSPEND
:
1116 link
->state
|= DEV_SUSPEND
;
1117 /* Fall through... */
1118 case CS_EVENT_RESET_PHYSICAL
:
1119 if (link
->state
& DEV_CONFIG
) {
1121 netif_device_detach(dev
);
1122 pcmcia_release_configuration(link
->handle
);
1125 case CS_EVENT_PM_RESUME
:
1126 link
->state
&= ~DEV_SUSPEND
;
1127 /* Fall through... */
1128 case CS_EVENT_CARD_RESET
:
1129 if (link
->state
& DEV_CONFIG
) {
1130 if ((smc
->manfid
== MANFID_MEGAHERTZ
) &&
1131 (smc
->cardid
== PRODID_MEGAHERTZ_EM3288
))
1132 mhz_3288_power(link
);
1133 pcmcia_request_configuration(link
->handle
, &link
->conf
);
1134 if (smc
->manfid
== MANFID_MOTOROLA
)
1136 if ((smc
->manfid
== MANFID_OSITECH
) &&
1137 (smc
->cardid
!= PRODID_OSITECH_SEVEN
)) {
1138 /* Power up the card and enable interrupts */
1139 set_bits(0x0300, dev
->base_addr
-0x10+OSITECH_AUI_PWR
);
1140 set_bits(0x0300, dev
->base_addr
-0x10+OSITECH_RESET_ISR
);
1142 if (((smc
->manfid
== MANFID_OSITECH
) &&
1143 (smc
->cardid
== PRODID_OSITECH_SEVEN
)) ||
1144 ((smc
->manfid
== MANFID_PSION
) &&
1145 (smc
->cardid
== PRODID_PSION_NET100
))) {
1146 /* Download the Seven of Diamonds firmware */
1147 for (i
= 0; i
< sizeof(__Xilinx7OD
); i
++) {
1148 outb(__Xilinx7OD
[i
], link
->io
.BasePort1
+2);
1154 netif_device_attach(dev
);
1160 } /* smc91c92_event */
1162 /*======================================================================
1164 MII interface support for SMC91cXX based cards
1165 ======================================================================*/
1167 #define MDIO_SHIFT_CLK 0x04
1168 #define MDIO_DATA_OUT 0x01
1169 #define MDIO_DIR_WRITE 0x08
1170 #define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
1171 #define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
1172 #define MDIO_DATA_READ 0x02
1174 static void mdio_sync(kio_addr_t addr
)
1177 for (bits
= 0; bits
< 32; bits
++) {
1178 outb(MDIO_DATA_WRITE1
, addr
);
1179 outb(MDIO_DATA_WRITE1
| MDIO_SHIFT_CLK
, addr
);
1183 static int mdio_read(struct net_device
*dev
, int phy_id
, int loc
)
1185 kio_addr_t addr
= dev
->base_addr
+ MGMT
;
1186 u_int cmd
= (0x06<<10)|(phy_id
<<5)|loc
;
1190 for (i
= 13; i
>= 0; i
--) {
1191 int dat
= (cmd
&(1<<i
)) ? MDIO_DATA_WRITE1
: MDIO_DATA_WRITE0
;
1193 outb(dat
| MDIO_SHIFT_CLK
, addr
);
1195 for (i
= 19; i
> 0; i
--) {
1197 retval
= (retval
<< 1) | ((inb(addr
) & MDIO_DATA_READ
) != 0);
1198 outb(MDIO_SHIFT_CLK
, addr
);
1200 return (retval
>>1) & 0xffff;
1203 static void mdio_write(struct net_device
*dev
, int phy_id
, int loc
, int value
)
1205 kio_addr_t addr
= dev
->base_addr
+ MGMT
;
1206 u_int cmd
= (0x05<<28)|(phy_id
<<23)|(loc
<<18)|(1<<17)|value
;
1210 for (i
= 31; i
>= 0; i
--) {
1211 int dat
= (cmd
&(1<<i
)) ? MDIO_DATA_WRITE1
: MDIO_DATA_WRITE0
;
1213 outb(dat
| MDIO_SHIFT_CLK
, addr
);
1215 for (i
= 1; i
>= 0; i
--) {
1217 outb(MDIO_SHIFT_CLK
, addr
);
1221 /*======================================================================
1223 The driver core code, most of which should be common with a
1224 non-PCMCIA implementation.
1226 ======================================================================*/
1229 static void smc_dump(struct net_device
*dev
)
1231 kio_addr_t ioaddr
= dev
->base_addr
;
1233 save
= inw(ioaddr
+ BANK_SELECT
);
1234 for (w
= 0; w
< 4; w
++) {
1236 printk(KERN_DEBUG
"bank %d: ", w
);
1237 for (i
= 0; i
< 14; i
+= 2)
1238 printk(" %04x", inw(ioaddr
+ i
));
1241 outw(save
, ioaddr
+ BANK_SELECT
);
1245 static int smc_open(struct net_device
*dev
)
1247 struct smc_private
*smc
= netdev_priv(dev
);
1248 dev_link_t
*link
= &smc
->link
;
1251 DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n",
1252 dev
->name
, dev
, inw(dev
->base_addr
+ BANK_SELECT
));
1253 if (pc_debug
> 1) smc_dump(dev
);
1256 /* Check that the PCMCIA card is still here. */
1259 /* Physical device present signature. */
1260 if (check_sig(link
) < 0) {
1261 printk("smc91c92_cs: Yikes! Bad chip signature!\n");
1266 netif_start_queue(dev
);
1267 smc
->saved_skb
= NULL
;
1268 smc
->packets_waiting
= 0;
1271 init_timer(&smc
->media
);
1272 smc
->media
.function
= &media_check
;
1273 smc
->media
.data
= (u_long
) dev
;
1274 smc
->media
.expires
= jiffies
+ HZ
;
1275 add_timer(&smc
->media
);
1280 /*====================================================================*/
1282 static int smc_close(struct net_device
*dev
)
1284 struct smc_private
*smc
= netdev_priv(dev
);
1285 dev_link_t
*link
= &smc
->link
;
1286 kio_addr_t ioaddr
= dev
->base_addr
;
1288 DEBUG(0, "%s: smc_close(), status %4.4x.\n",
1289 dev
->name
, inw(ioaddr
+ BANK_SELECT
));
1291 netif_stop_queue(dev
);
1293 /* Shut off all interrupts, and turn off the Tx and Rx sections.
1294 Don't bother to check for chip present. */
1295 SMC_SELECT_BANK(2); /* Nominally paranoia, but do no assume... */
1296 outw(0, ioaddr
+ INTERRUPT
);
1298 mask_bits(0xff00, ioaddr
+ RCR
);
1299 mask_bits(0xff00, ioaddr
+ TCR
);
1301 /* Put the chip into power-down mode. */
1303 outw(CTL_POWERDOWN
, ioaddr
+ CONTROL
);
1306 del_timer_sync(&smc
->media
);
1311 /*======================================================================
1313 Transfer a packet to the hardware and trigger the packet send.
1314 This may be called at either from either the Tx queue code
1315 or the interrupt handler.
1317 ======================================================================*/
1319 static void smc_hardware_send_packet(struct net_device
* dev
)
1321 struct smc_private
*smc
= netdev_priv(dev
);
1322 struct sk_buff
*skb
= smc
->saved_skb
;
1323 kio_addr_t ioaddr
= dev
->base_addr
;
1327 printk(KERN_ERR
"%s: In XMIT with no packet to send.\n", dev
->name
);
1331 /* There should be a packet slot waiting. */
1332 packet_no
= inw(ioaddr
+ PNR_ARR
) >> 8;
1333 if (packet_no
& 0x80) {
1334 /* If not, there is a hardware problem! Likely an ejected card. */
1335 printk(KERN_WARNING
"%s: 91c92 hardware Tx buffer allocation"
1336 " failed, status %#2.2x.\n", dev
->name
, packet_no
);
1337 dev_kfree_skb_irq(skb
);
1338 smc
->saved_skb
= NULL
;
1339 netif_start_queue(dev
);
1343 smc
->stats
.tx_bytes
+= skb
->len
;
1344 /* The card should use the just-allocated buffer. */
1345 outw(packet_no
, ioaddr
+ PNR_ARR
);
1346 /* point to the beginning of the packet */
1347 outw(PTR_AUTOINC
, ioaddr
+ POINTER
);
1349 /* Send the packet length (+6 for status, length and ctl byte)
1350 and the status word (set to zeros). */
1352 u_char
*buf
= skb
->data
;
1353 u_int length
= skb
->len
; /* The chip will pad to ethernet min. */
1355 DEBUG(2, "%s: Trying to xmit packet of length %d.\n",
1358 /* send the packet length: +6 for status word, length, and ctl */
1359 outw(0, ioaddr
+ DATA_1
);
1360 outw(length
+ 6, ioaddr
+ DATA_1
);
1361 outsw(ioaddr
+ DATA_1
, buf
, length
>> 1);
1363 /* The odd last byte, if there is one, goes in the control word. */
1364 outw((length
& 1) ? 0x2000 | buf
[length
-1] : 0, ioaddr
+ DATA_1
);
1367 /* Enable the Tx interrupts, both Tx (TxErr) and TxEmpty. */
1368 outw(((IM_TX_INT
|IM_TX_EMPTY_INT
)<<8) |
1369 (inw(ioaddr
+ INTERRUPT
) & 0xff00),
1370 ioaddr
+ INTERRUPT
);
1372 /* The chip does the rest of the work. */
1373 outw(MC_ENQUEUE
, ioaddr
+ MMU_CMD
);
1375 smc
->saved_skb
= NULL
;
1376 dev_kfree_skb_irq(skb
);
1377 dev
->trans_start
= jiffies
;
1378 netif_start_queue(dev
);
1382 /*====================================================================*/
1384 static void smc_tx_timeout(struct net_device
*dev
)
1386 struct smc_private
*smc
= netdev_priv(dev
);
1387 kio_addr_t ioaddr
= dev
->base_addr
;
1389 printk(KERN_NOTICE
"%s: SMC91c92 transmit timed out, "
1390 "Tx_status %2.2x status %4.4x.\n",
1391 dev
->name
, inw(ioaddr
)&0xff, inw(ioaddr
+ 2));
1392 smc
->stats
.tx_errors
++;
1394 dev
->trans_start
= jiffies
;
1395 smc
->saved_skb
= NULL
;
1396 netif_wake_queue(dev
);
1399 static int smc_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1401 struct smc_private
*smc
= netdev_priv(dev
);
1402 kio_addr_t ioaddr
= dev
->base_addr
;
1406 netif_stop_queue(dev
);
1408 DEBUG(2, "%s: smc_start_xmit(length = %d) called,"
1409 " status %4.4x.\n", dev
->name
, skb
->len
, inw(ioaddr
+ 2));
1411 if (smc
->saved_skb
) {
1412 /* THIS SHOULD NEVER HAPPEN. */
1413 smc
->stats
.tx_aborted_errors
++;
1414 printk(KERN_DEBUG
"%s: Internal error -- sent packet while busy.\n",
1418 smc
->saved_skb
= skb
;
1420 num_pages
= skb
->len
>> 8;
1422 if (num_pages
> 7) {
1423 printk(KERN_ERR
"%s: Far too big packet error.\n", dev
->name
);
1424 dev_kfree_skb (skb
);
1425 smc
->saved_skb
= NULL
;
1426 smc
->stats
.tx_dropped
++;
1427 return 0; /* Do not re-queue this packet. */
1429 /* A packet is now waiting. */
1430 smc
->packets_waiting
++;
1432 SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */
1434 /* need MC_RESET to keep the memory consistent. errata? */
1436 outw(MC_RESET
, ioaddr
+ MMU_CMD
);
1440 /* Allocate the memory; send the packet now if we win. */
1441 outw(MC_ALLOC
| num_pages
, ioaddr
+ MMU_CMD
);
1442 for (time_out
= MEMORY_WAIT_TIME
; time_out
>= 0; time_out
--) {
1443 ir
= inw(ioaddr
+INTERRUPT
);
1444 if (ir
& IM_ALLOC_INT
) {
1445 /* Acknowledge the interrupt, send the packet. */
1446 outw((ir
&0xff00) | IM_ALLOC_INT
, ioaddr
+ INTERRUPT
);
1447 smc_hardware_send_packet(dev
); /* Send the packet now.. */
1452 /* Otherwise defer until the Tx-space-allocated interrupt. */
1453 DEBUG(2, "%s: memory allocation deferred.\n", dev
->name
);
1454 outw((IM_ALLOC_INT
<< 8) | (ir
& 0xff00), ioaddr
+ INTERRUPT
);
1459 /*======================================================================
1461 Handle a Tx anomolous event. Entered while in Window 2.
1463 ======================================================================*/
1465 static void smc_tx_err(struct net_device
* dev
)
1467 struct smc_private
*smc
= netdev_priv(dev
);
1468 kio_addr_t ioaddr
= dev
->base_addr
;
1469 int saved_packet
= inw(ioaddr
+ PNR_ARR
) & 0xff;
1470 int packet_no
= inw(ioaddr
+ FIFO_PORTS
) & 0x7f;
1473 /* select this as the packet to read from */
1474 outw(packet_no
, ioaddr
+ PNR_ARR
);
1476 /* read the first word from this packet */
1477 outw(PTR_AUTOINC
| PTR_READ
| 0, ioaddr
+ POINTER
);
1479 tx_status
= inw(ioaddr
+ DATA_1
);
1481 smc
->stats
.tx_errors
++;
1482 if (tx_status
& TS_LOSTCAR
) smc
->stats
.tx_carrier_errors
++;
1483 if (tx_status
& TS_LATCOL
) smc
->stats
.tx_window_errors
++;
1484 if (tx_status
& TS_16COL
) {
1485 smc
->stats
.tx_aborted_errors
++;
1489 if (tx_status
& TS_SUCCESS
) {
1490 printk(KERN_NOTICE
"%s: Successful packet caused error "
1491 "interrupt?\n", dev
->name
);
1493 /* re-enable transmit */
1495 outw(inw(ioaddr
+ TCR
) | TCR_ENABLE
| smc
->duplex
, ioaddr
+ TCR
);
1498 outw(MC_FREEPKT
, ioaddr
+ MMU_CMD
); /* Free the packet memory. */
1500 /* one less packet waiting for me */
1501 smc
->packets_waiting
--;
1503 outw(saved_packet
, ioaddr
+ PNR_ARR
);
1507 /*====================================================================*/
1509 static void smc_eph_irq(struct net_device
*dev
)
1511 struct smc_private
*smc
= netdev_priv(dev
);
1512 kio_addr_t ioaddr
= dev
->base_addr
;
1513 u_short card_stats
, ephs
;
1516 ephs
= inw(ioaddr
+ EPH
);
1517 DEBUG(2, "%s: Ethernet protocol handler interrupt, status"
1518 " %4.4x.\n", dev
->name
, ephs
);
1519 /* Could be a counter roll-over warning: update stats. */
1520 card_stats
= inw(ioaddr
+ COUNTER
);
1521 /* single collisions */
1522 smc
->stats
.collisions
+= card_stats
& 0xF;
1524 /* multiple collisions */
1525 smc
->stats
.collisions
+= card_stats
& 0xF;
1526 #if 0 /* These are for when linux supports these statistics */
1527 card_stats
>>= 4; /* deferred */
1528 card_stats
>>= 4; /* excess deferred */
1530 /* If we had a transmit error we must re-enable the transmitter. */
1531 outw(inw(ioaddr
+ TCR
) | TCR_ENABLE
| smc
->duplex
, ioaddr
+ TCR
);
1533 /* Clear a link error interrupt. */
1535 outw(CTL_AUTO_RELEASE
| 0x0000, ioaddr
+ CONTROL
);
1536 outw(CTL_AUTO_RELEASE
| CTL_TE_ENABLE
| CTL_CR_ENABLE
,
1541 /*====================================================================*/
1543 static irqreturn_t
smc_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1545 struct net_device
*dev
= dev_id
;
1546 struct smc_private
*smc
= netdev_priv(dev
);
1548 u_short saved_bank
, saved_pointer
, mask
, status
;
1549 unsigned int handled
= 1;
1550 char bogus_cnt
= INTR_WORK
; /* Work we are willing to do. */
1552 if (!netif_device_present(dev
))
1555 ioaddr
= dev
->base_addr
;
1557 DEBUG(3, "%s: SMC91c92 interrupt %d at %#x.\n", dev
->name
,
1561 saved_bank
= inw(ioaddr
+ BANK_SELECT
);
1562 if ((saved_bank
& 0xff00) != 0x3300) {
1563 /* The device does not exist -- the card could be off-line, or
1564 maybe it has been ejected. */
1565 DEBUG(1, "%s: SMC91c92 interrupt %d for non-existent"
1566 "/ejected device.\n", dev
->name
, irq
);
1572 saved_pointer
= inw(ioaddr
+ POINTER
);
1573 mask
= inw(ioaddr
+ INTERRUPT
) >> 8;
1574 /* clear all interrupts */
1575 outw(0, ioaddr
+ INTERRUPT
);
1577 do { /* read the status flag, and mask it */
1578 status
= inw(ioaddr
+ INTERRUPT
) & 0xff;
1579 DEBUG(3, "%s: Status is %#2.2x (mask %#2.2x).\n", dev
->name
,
1581 if ((status
& mask
) == 0) {
1582 if (bogus_cnt
== INTR_WORK
)
1586 if (status
& IM_RCV_INT
) {
1587 /* Got a packet(s). */
1590 if (status
& IM_TX_INT
) {
1592 outw(IM_TX_INT
, ioaddr
+ INTERRUPT
);
1595 if (status
& IM_TX_EMPTY_INT
) {
1596 outw(IM_TX_EMPTY_INT
, ioaddr
+ INTERRUPT
);
1597 mask
&= ~IM_TX_EMPTY_INT
;
1598 smc
->stats
.tx_packets
+= smc
->packets_waiting
;
1599 smc
->packets_waiting
= 0;
1601 if (status
& IM_ALLOC_INT
) {
1602 /* Clear this interrupt so it doesn't happen again */
1603 mask
&= ~IM_ALLOC_INT
;
1605 smc_hardware_send_packet(dev
);
1607 /* enable xmit interrupts based on this */
1608 mask
|= (IM_TX_EMPTY_INT
| IM_TX_INT
);
1610 /* and let the card send more packets to me */
1611 netif_wake_queue(dev
);
1613 if (status
& IM_RX_OVRN_INT
) {
1614 smc
->stats
.rx_errors
++;
1615 smc
->stats
.rx_fifo_errors
++;
1617 smc
->rx_ovrn
= 1; /* need MC_RESET outside smc_interrupt */
1618 outw(IM_RX_OVRN_INT
, ioaddr
+ INTERRUPT
);
1620 if (status
& IM_EPH_INT
)
1622 } while (--bogus_cnt
);
1624 DEBUG(3, " Restoring saved registers mask %2.2x bank %4.4x"
1625 " pointer %4.4x.\n", mask
, saved_bank
, saved_pointer
);
1627 /* restore state register */
1628 outw((mask
<<8), ioaddr
+ INTERRUPT
);
1629 outw(saved_pointer
, ioaddr
+ POINTER
);
1630 SMC_SELECT_BANK(saved_bank
);
1632 DEBUG(3, "%s: Exiting interrupt IRQ%d.\n", dev
->name
, irq
);
1636 if ((smc
->manfid
== MANFID_OSITECH
) &&
1637 (smc
->cardid
!= PRODID_OSITECH_SEVEN
)) {
1638 /* Retrigger interrupt if needed */
1639 mask_bits(0x00ff, ioaddr
-0x10+OSITECH_RESET_ISR
);
1640 set_bits(0x0300, ioaddr
-0x10+OSITECH_RESET_ISR
);
1642 if (smc
->manfid
== MANFID_MOTOROLA
) {
1644 cor
= readb(smc
->base
+ MOT_UART
+ CISREG_COR
);
1645 writeb(cor
& ~COR_IREQ_ENA
, smc
->base
+ MOT_UART
+ CISREG_COR
);
1646 writeb(cor
, smc
->base
+ MOT_UART
+ CISREG_COR
);
1647 cor
= readb(smc
->base
+ MOT_LAN
+ CISREG_COR
);
1648 writeb(cor
& ~COR_IREQ_ENA
, smc
->base
+ MOT_LAN
+ CISREG_COR
);
1649 writeb(cor
, smc
->base
+ MOT_LAN
+ CISREG_COR
);
1651 #ifdef DOES_NOT_WORK
1652 if (smc
->base
!= NULL
) { /* Megahertz MFC's */
1653 readb(smc
->base
+MEGAHERTZ_ISR
);
1654 readb(smc
->base
+MEGAHERTZ_ISR
);
1657 return IRQ_RETVAL(handled
);
1660 /*====================================================================*/
1662 static void smc_rx(struct net_device
*dev
)
1664 struct smc_private
*smc
= netdev_priv(dev
);
1665 kio_addr_t ioaddr
= dev
->base_addr
;
1667 int packet_length
; /* Caution: not frame length, rather words
1668 to transfer from the chip. */
1670 /* Assertion: we are in Window 2. */
1672 if (inw(ioaddr
+ FIFO_PORTS
) & FP_RXEMPTY
) {
1673 printk(KERN_ERR
"%s: smc_rx() with nothing on Rx FIFO.\n",
1678 /* Reset the read pointer, and read the status and packet length. */
1679 outw(PTR_READ
| PTR_RCV
| PTR_AUTOINC
, ioaddr
+ POINTER
);
1680 rx_status
= inw(ioaddr
+ DATA_1
);
1681 packet_length
= inw(ioaddr
+ DATA_1
) & 0x07ff;
1683 DEBUG(2, "%s: Receive status %4.4x length %d.\n",
1684 dev
->name
, rx_status
, packet_length
);
1686 if (!(rx_status
& RS_ERRORS
)) {
1687 /* do stuff to make a new packet */
1688 struct sk_buff
*skb
;
1690 /* Note: packet_length adds 5 or 6 extra bytes here! */
1691 skb
= dev_alloc_skb(packet_length
+2);
1694 DEBUG(1, "%s: Low memory, packet dropped.\n", dev
->name
);
1695 smc
->stats
.rx_dropped
++;
1696 outw(MC_RELEASE
, ioaddr
+ MMU_CMD
);
1700 packet_length
-= (rx_status
& RS_ODDFRAME
? 5 : 6);
1701 skb_reserve(skb
, 2);
1702 insw(ioaddr
+DATA_1
, skb_put(skb
, packet_length
),
1703 (packet_length
+1)>>1);
1704 skb
->protocol
= eth_type_trans(skb
, dev
);
1708 dev
->last_rx
= jiffies
;
1709 smc
->stats
.rx_packets
++;
1710 smc
->stats
.rx_bytes
+= packet_length
;
1711 if (rx_status
& RS_MULTICAST
)
1712 smc
->stats
.multicast
++;
1715 smc
->stats
.rx_errors
++;
1717 if (rx_status
& RS_ALGNERR
) smc
->stats
.rx_frame_errors
++;
1718 if (rx_status
& (RS_TOOSHORT
| RS_TOOLONG
))
1719 smc
->stats
.rx_length_errors
++;
1720 if (rx_status
& RS_BADCRC
) smc
->stats
.rx_crc_errors
++;
1722 /* Let the MMU free the memory of this packet. */
1723 outw(MC_RELEASE
, ioaddr
+ MMU_CMD
);
1728 /*====================================================================*/
1730 static struct net_device_stats
*smc_get_stats(struct net_device
*dev
)
1732 struct smc_private
*smc
= netdev_priv(dev
);
1733 /* Nothing to update - the 91c92 is a pretty primative chip. */
1737 /*======================================================================
1739 Calculate values for the hardware multicast filter hash table.
1741 ======================================================================*/
1743 static void fill_multicast_tbl(int count
, struct dev_mc_list
*addrs
,
1744 u_char
*multicast_table
)
1746 struct dev_mc_list
*mc_addr
;
1748 for (mc_addr
= addrs
; mc_addr
&& --count
> 0; mc_addr
= mc_addr
->next
) {
1749 u_int position
= ether_crc(6, mc_addr
->dmi_addr
);
1750 #ifndef final_version /* Verify multicast address. */
1751 if ((mc_addr
->dmi_addr
[0] & 1) == 0)
1754 multicast_table
[position
>> 29] |= 1 << ((position
>> 26) & 7);
1758 /*======================================================================
1760 Set the receive mode.
1762 This routine is used by both the protocol level to notify us of
1763 promiscuous/multicast mode changes, and by the open/reset code to
1764 initialize the Rx registers. We always set the multicast list and
1765 leave the receiver running.
1767 ======================================================================*/
1769 static void set_rx_mode(struct net_device
*dev
)
1771 kio_addr_t ioaddr
= dev
->base_addr
;
1772 struct smc_private
*smc
= netdev_priv(dev
);
1773 u_int multicast_table
[ 2 ] = { 0, };
1774 unsigned long flags
;
1775 u_short rx_cfg_setting
;
1777 if (dev
->flags
& IFF_PROMISC
) {
1778 printk(KERN_NOTICE
"%s: setting Rx mode to promiscuous.\n", dev
->name
);
1779 rx_cfg_setting
= RxStripCRC
| RxEnable
| RxPromisc
| RxAllMulti
;
1780 } else if (dev
->flags
& IFF_ALLMULTI
)
1781 rx_cfg_setting
= RxStripCRC
| RxEnable
| RxAllMulti
;
1783 if (dev
->mc_count
) {
1784 fill_multicast_tbl(dev
->mc_count
, dev
->mc_list
,
1785 (u_char
*)multicast_table
);
1787 rx_cfg_setting
= RxStripCRC
| RxEnable
;
1790 /* Load MC table and Rx setting into the chip without interrupts. */
1791 spin_lock_irqsave(&smc
->lock
, flags
);
1793 outl(multicast_table
[0], ioaddr
+ MULTICAST0
);
1794 outl(multicast_table
[1], ioaddr
+ MULTICAST4
);
1796 outw(rx_cfg_setting
, ioaddr
+ RCR
);
1798 spin_unlock_irqrestore(&smc
->lock
, flags
);
1803 /*======================================================================
1805 Senses when a card's config changes. Here, it's coax or TP.
1807 ======================================================================*/
1809 static int s9k_config(struct net_device
*dev
, struct ifmap
*map
)
1811 struct smc_private
*smc
= netdev_priv(dev
);
1812 if ((map
->port
!= (u_char
)(-1)) && (map
->port
!= dev
->if_port
)) {
1813 if (smc
->cfg
& CFG_MII_SELECT
)
1815 else if (map
->port
> 2)
1817 dev
->if_port
= map
->port
;
1818 printk(KERN_INFO
"%s: switched to %s port\n",
1819 dev
->name
, if_names
[dev
->if_port
]);
1825 /*======================================================================
1827 Reset the chip, reloading every register that might be corrupted.
1829 ======================================================================*/
1832 Set transceiver type, perhaps to something other than what the user
1833 specified in dev->if_port.
1835 static void smc_set_xcvr(struct net_device
*dev
, int if_port
)
1837 struct smc_private
*smc
= netdev_priv(dev
);
1838 kio_addr_t ioaddr
= dev
->base_addr
;
1841 saved_bank
= inw(ioaddr
+ BANK_SELECT
);
1844 outw(smc
->cfg
| CFG_AUI_SELECT
, ioaddr
+ CONFIG
);
1845 if ((smc
->manfid
== MANFID_OSITECH
) &&
1846 (smc
->cardid
!= PRODID_OSITECH_SEVEN
))
1847 set_bits(OSI_AUI_PWR
, ioaddr
- 0x10 + OSITECH_AUI_PWR
);
1848 smc
->media_status
= ((dev
->if_port
== 0) ? 0x0001 : 0x0002);
1850 outw(smc
->cfg
, ioaddr
+ CONFIG
);
1851 if ((smc
->manfid
== MANFID_OSITECH
) &&
1852 (smc
->cardid
!= PRODID_OSITECH_SEVEN
))
1853 mask_bits(~OSI_AUI_PWR
, ioaddr
- 0x10 + OSITECH_AUI_PWR
);
1854 smc
->media_status
= ((dev
->if_port
== 0) ? 0x0012 : 0x4001);
1856 SMC_SELECT_BANK(saved_bank
);
1859 static void smc_reset(struct net_device
*dev
)
1861 kio_addr_t ioaddr
= dev
->base_addr
;
1862 struct smc_private
*smc
= netdev_priv(dev
);
1865 DEBUG(0, "%s: smc91c92 reset called.\n", dev
->name
);
1867 /* The first interaction must be a write to bring the chip out
1870 /* Reset the chip. */
1871 outw(RCR_SOFTRESET
, ioaddr
+ RCR
);
1874 /* Clear the transmit and receive configuration registers. */
1875 outw(RCR_CLEAR
, ioaddr
+ RCR
);
1876 outw(TCR_CLEAR
, ioaddr
+ TCR
);
1878 /* Set the Window 1 control, configuration and station addr registers.
1879 No point in writing the I/O base register ;-> */
1881 /* Automatically release succesfully transmitted packets,
1882 Accept link errors, counter and Tx error interrupts. */
1883 outw(CTL_AUTO_RELEASE
| CTL_TE_ENABLE
| CTL_CR_ENABLE
,
1885 smc_set_xcvr(dev
, dev
->if_port
);
1886 if ((smc
->manfid
== MANFID_OSITECH
) &&
1887 (smc
->cardid
!= PRODID_OSITECH_SEVEN
))
1888 outw((dev
->if_port
== 2 ? OSI_AUI_PWR
: 0) |
1889 (inw(ioaddr
-0x10+OSITECH_AUI_PWR
) & 0xff00),
1890 ioaddr
- 0x10 + OSITECH_AUI_PWR
);
1892 /* Fill in the physical address. The databook is wrong about the order! */
1893 for (i
= 0; i
< 6; i
+= 2)
1894 outw((dev
->dev_addr
[i
+1]<<8)+dev
->dev_addr
[i
],
1895 ioaddr
+ ADDR0
+ i
);
1899 outw(MC_RESET
, ioaddr
+ MMU_CMD
);
1900 outw(0, ioaddr
+ INTERRUPT
);
1902 /* Re-enable the chip. */
1904 outw(((smc
->cfg
& CFG_MII_SELECT
) ? 0 : TCR_MONCSN
) |
1905 TCR_ENABLE
| TCR_PAD_EN
| smc
->duplex
, ioaddr
+ TCR
);
1908 if (smc
->cfg
& CFG_MII_SELECT
) {
1912 mdio_write(dev
, smc
->mii_if
.phy_id
, 0, 0x8000);
1914 /* Advertise 100F, 100H, 10F, 10H */
1915 mdio_write(dev
, smc
->mii_if
.phy_id
, 4, 0x01e1);
1917 /* Restart MII autonegotiation */
1918 mdio_write(dev
, smc
->mii_if
.phy_id
, 0, 0x0000);
1919 mdio_write(dev
, smc
->mii_if
.phy_id
, 0, 0x1200);
1922 /* Enable interrupts. */
1924 outw((IM_EPH_INT
| IM_RX_OVRN_INT
| IM_RCV_INT
) << 8,
1925 ioaddr
+ INTERRUPT
);
1928 /*======================================================================
1930 Media selection timer routine
1932 ======================================================================*/
1934 static void media_check(u_long arg
)
1936 struct net_device
*dev
= (struct net_device
*) arg
;
1937 struct smc_private
*smc
= netdev_priv(dev
);
1938 kio_addr_t ioaddr
= dev
->base_addr
;
1939 u_short i
, media
, saved_bank
;
1942 saved_bank
= inw(ioaddr
+ BANK_SELECT
);
1944 if (!netif_device_present(dev
))
1949 /* need MC_RESET to keep the memory consistent. errata? */
1951 outw(MC_RESET
, ioaddr
+ MMU_CMD
);
1954 i
= inw(ioaddr
+ INTERRUPT
);
1956 media
= inw(ioaddr
+ EPH
) & EPH_LINK_OK
;
1958 media
|= (inw(ioaddr
+ CONFIG
) & CFG_AUI_SELECT
) ? 2 : 1;
1960 /* Check for pending interrupt with watchdog flag set: with
1961 this, we can limp along even if the interrupt is blocked */
1962 if (smc
->watchdog
++ && ((i
>>8) & i
)) {
1963 if (!smc
->fast_poll
)
1964 printk(KERN_INFO
"%s: interrupt(s) dropped!\n", dev
->name
);
1965 smc_interrupt(dev
->irq
, smc
, NULL
);
1966 smc
->fast_poll
= HZ
;
1968 if (smc
->fast_poll
) {
1970 smc
->media
.expires
= jiffies
+ HZ
/100;
1971 add_timer(&smc
->media
);
1972 SMC_SELECT_BANK(saved_bank
);
1976 if (smc
->cfg
& CFG_MII_SELECT
) {
1977 if (smc
->mii_if
.phy_id
< 0)
1981 link
= mdio_read(dev
, smc
->mii_if
.phy_id
, 1);
1982 if (!link
|| (link
== 0xffff)) {
1983 printk(KERN_INFO
"%s: MII is missing!\n", dev
->name
);
1984 smc
->mii_if
.phy_id
= -1;
1989 if (link
!= smc
->link_status
) {
1990 u_short p
= mdio_read(dev
, smc
->mii_if
.phy_id
, 5);
1991 printk(KERN_INFO
"%s: %s link beat\n", dev
->name
,
1992 (link
) ? "found" : "lost");
1993 smc
->duplex
= (((p
& 0x0100) || ((p
& 0x1c0) == 0x40))
1996 printk(KERN_INFO
"%s: autonegotiation complete: "
1997 "%sbaseT-%cD selected\n", dev
->name
,
1998 ((p
& 0x0180) ? "100" : "10"),
1999 (smc
->duplex
? 'F' : 'H'));
2002 outw(inw(ioaddr
+ TCR
) | smc
->duplex
, ioaddr
+ TCR
);
2003 smc
->link_status
= link
;
2008 /* Ignore collisions unless we've had no rx's recently */
2009 if (jiffies
- dev
->last_rx
> HZ
) {
2010 if (smc
->tx_err
|| (smc
->media_status
& EPH_16COL
))
2015 if (media
!= smc
->media_status
) {
2016 if ((media
& smc
->media_status
& 1) &&
2017 ((smc
->media_status
^ media
) & EPH_LINK_OK
))
2018 printk(KERN_INFO
"%s: %s link beat\n", dev
->name
,
2019 (smc
->media_status
& EPH_LINK_OK
? "lost" : "found"));
2020 else if ((media
& smc
->media_status
& 2) &&
2021 ((smc
->media_status
^ media
) & EPH_16COL
))
2022 printk(KERN_INFO
"%s: coax cable %s\n", dev
->name
,
2023 (media
& EPH_16COL
? "problem" : "ok"));
2024 if (dev
->if_port
== 0) {
2026 if (media
& EPH_LINK_OK
)
2027 printk(KERN_INFO
"%s: flipped to 10baseT\n",
2030 smc_set_xcvr(dev
, 2);
2032 if (media
& EPH_16COL
)
2033 smc_set_xcvr(dev
, 1);
2035 printk(KERN_INFO
"%s: flipped to 10base2\n",
2039 smc
->media_status
= media
;
2043 smc
->media
.expires
= jiffies
+ HZ
;
2044 add_timer(&smc
->media
);
2045 SMC_SELECT_BANK(saved_bank
);
2048 static int smc_link_ok(struct net_device
*dev
)
2050 kio_addr_t ioaddr
= dev
->base_addr
;
2051 struct smc_private
*smc
= netdev_priv(dev
);
2053 if (smc
->cfg
& CFG_MII_SELECT
) {
2054 return mii_link_ok(&smc
->mii_if
);
2057 return inw(ioaddr
+ EPH
) & EPH_LINK_OK
;
2061 static int smc_netdev_get_ecmd(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
2064 kio_addr_t ioaddr
= dev
->base_addr
;
2066 ecmd
->supported
= (SUPPORTED_TP
| SUPPORTED_AUI
|
2067 SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
);
2070 tmp
= inw(ioaddr
+ CONFIG
);
2071 ecmd
->port
= (tmp
& CFG_AUI_SELECT
) ? PORT_AUI
: PORT_TP
;
2072 ecmd
->transceiver
= XCVR_INTERNAL
;
2073 ecmd
->speed
= SPEED_10
;
2074 ecmd
->phy_address
= ioaddr
+ MGMT
;
2077 tmp
= inw(ioaddr
+ TCR
);
2078 ecmd
->duplex
= (tmp
& TCR_FDUPLX
) ? DUPLEX_FULL
: DUPLEX_HALF
;
2083 static int smc_netdev_set_ecmd(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
2086 kio_addr_t ioaddr
= dev
->base_addr
;
2088 if (ecmd
->speed
!= SPEED_10
)
2090 if (ecmd
->duplex
!= DUPLEX_HALF
&& ecmd
->duplex
!= DUPLEX_FULL
)
2092 if (ecmd
->port
!= PORT_TP
&& ecmd
->port
!= PORT_AUI
)
2094 if (ecmd
->transceiver
!= XCVR_INTERNAL
)
2097 if (ecmd
->port
== PORT_AUI
)
2098 smc_set_xcvr(dev
, 1);
2100 smc_set_xcvr(dev
, 0);
2103 tmp
= inw(ioaddr
+ TCR
);
2104 if (ecmd
->duplex
== DUPLEX_FULL
)
2108 outw(tmp
, ioaddr
+ TCR
);
2113 static int check_if_running(struct net_device
*dev
)
2115 if (!netif_running(dev
))
2120 static void smc_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
2122 strcpy(info
->driver
, DRV_NAME
);
2123 strcpy(info
->version
, DRV_VERSION
);
2126 static int smc_get_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
2128 struct smc_private
*smc
= netdev_priv(dev
);
2129 kio_addr_t ioaddr
= dev
->base_addr
;
2130 u16 saved_bank
= inw(ioaddr
+ BANK_SELECT
);
2134 spin_lock_irq(&smc
->lock
);
2135 if (smc
->cfg
& CFG_MII_SELECT
)
2136 ret
= mii_ethtool_gset(&smc
->mii_if
, ecmd
);
2138 ret
= smc_netdev_get_ecmd(dev
, ecmd
);
2139 spin_unlock_irq(&smc
->lock
);
2140 SMC_SELECT_BANK(saved_bank
);
2144 static int smc_set_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
2146 struct smc_private
*smc
= netdev_priv(dev
);
2147 kio_addr_t ioaddr
= dev
->base_addr
;
2148 u16 saved_bank
= inw(ioaddr
+ BANK_SELECT
);
2152 spin_lock_irq(&smc
->lock
);
2153 if (smc
->cfg
& CFG_MII_SELECT
)
2154 ret
= mii_ethtool_sset(&smc
->mii_if
, ecmd
);
2156 ret
= smc_netdev_set_ecmd(dev
, ecmd
);
2157 spin_unlock_irq(&smc
->lock
);
2158 SMC_SELECT_BANK(saved_bank
);
2162 static u32
smc_get_link(struct net_device
*dev
)
2164 struct smc_private
*smc
= netdev_priv(dev
);
2165 kio_addr_t ioaddr
= dev
->base_addr
;
2166 u16 saved_bank
= inw(ioaddr
+ BANK_SELECT
);
2170 spin_lock_irq(&smc
->lock
);
2171 ret
= smc_link_ok(dev
);
2172 spin_unlock_irq(&smc
->lock
);
2173 SMC_SELECT_BANK(saved_bank
);
2178 static u32
smc_get_msglevel(struct net_device
*dev
)
2183 static void smc_set_msglevel(struct net_device
*dev
, u32 val
)
2189 static int smc_nway_reset(struct net_device
*dev
)
2191 struct smc_private
*smc
= netdev_priv(dev
);
2192 if (smc
->cfg
& CFG_MII_SELECT
) {
2193 kio_addr_t ioaddr
= dev
->base_addr
;
2194 u16 saved_bank
= inw(ioaddr
+ BANK_SELECT
);
2198 res
= mii_nway_restart(&smc
->mii_if
);
2199 SMC_SELECT_BANK(saved_bank
);
2206 static struct ethtool_ops ethtool_ops
= {
2207 .begin
= check_if_running
,
2208 .get_drvinfo
= smc_get_drvinfo
,
2209 .get_settings
= smc_get_settings
,
2210 .set_settings
= smc_set_settings
,
2211 .get_link
= smc_get_link
,
2213 .get_msglevel
= smc_get_msglevel
,
2214 .set_msglevel
= smc_set_msglevel
,
2216 .nway_reset
= smc_nway_reset
,
2219 static int smc_ioctl (struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2221 struct smc_private
*smc
= netdev_priv(dev
);
2222 struct mii_ioctl_data
*mii
= if_mii(rq
);
2225 kio_addr_t ioaddr
= dev
->base_addr
;
2227 if (!netif_running(dev
))
2230 spin_lock_irq(&smc
->lock
);
2231 saved_bank
= inw(ioaddr
+ BANK_SELECT
);
2233 rc
= generic_mii_ioctl(&smc
->mii_if
, mii
, cmd
, NULL
);
2234 SMC_SELECT_BANK(saved_bank
);
2235 spin_unlock_irq(&smc
->lock
);
2239 static struct pcmcia_driver smc91c92_cs_driver
= {
2240 .owner
= THIS_MODULE
,
2242 .name
= "smc91c92_cs",
2244 .attach
= smc91c92_attach
,
2245 .detach
= smc91c92_detach
,
2248 static int __init
init_smc91c92_cs(void)
2250 return pcmcia_register_driver(&smc91c92_cs_driver
);
2253 static void __exit
exit_smc91c92_cs(void)
2255 pcmcia_unregister_driver(&smc91c92_cs_driver
);
2256 BUG_ON(dev_list
!= NULL
);
2259 module_init(init_smc91c92_cs
);
2260 module_exit(exit_smc91c92_cs
);