1 /* $NetBSD: smc91cxx.c,v 1.75 2009/05/12 14:25:18 cegger Exp $ */
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1996 Gardner Buchanan <gbuchanan@shl.com>
35 * All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by Gardner Buchanan.
48 * 4. The name of Gardner Buchanan may not be used to endorse or promote
49 * products derived from this software without specific prior written
52 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
54 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
56 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
57 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
61 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 * from FreeBSD Id: if_sn.c,v 1.4 1996/03/18 15:47:16 gardner Exp
67 * Core driver for the SMC 91Cxx family of Ethernet chips.
69 * Memory allocation interrupt logic is drived from an SMC 91C90 driver
70 * written for NetBSD/amiga by Michael Hitch.
73 #include <sys/cdefs.h>
74 __KERNEL_RCSID(0, "$NetBSD: smc91cxx.c,v 1.75 2009/05/12 14:25:18 cegger Exp $");
80 #include <sys/param.h>
81 #include <sys/systm.h>
83 #include <sys/syslog.h>
84 #include <sys/socket.h>
85 #include <sys/device.h>
86 #include <sys/kernel.h>
87 #include <sys/malloc.h>
88 #include <sys/ioctl.h>
89 #include <sys/errno.h>
97 #include <uvm/uvm_extern.h>
100 #include <net/if_dl.h>
101 #include <net/if_ether.h>
102 #include <net/if_media.h>
105 #include <netinet/in.h>
106 #include <netinet/if_inarp.h>
107 #include <netinet/in_systm.h>
108 #include <netinet/in_var.h>
109 #include <netinet/ip.h>
114 #include <net/bpfdesc.h>
117 #include <dev/mii/mii.h>
118 #include <dev/mii/miivar.h>
119 #include <dev/mii/mii_bitbang.h>
121 #include <dev/ic/smc91cxxreg.h>
122 #include <dev/ic/smc91cxxvar.h>
124 #ifndef __BUS_SPACE_HAS_STREAM_METHODS
125 #define bus_space_write_multi_stream_2 bus_space_write_multi_2
126 #define bus_space_write_multi_stream_4 bus_space_write_multi_4
127 #define bus_space_read_multi_stream_2 bus_space_read_multi_2
128 #define bus_space_read_multi_stream_4 bus_space_read_multi_4
130 #define bus_space_write_stream_4 bus_space_write_4
131 #define bus_space_read_stream_4 bus_space_read_4
132 #endif /* __BUS_SPACE_HAS_STREAM_METHODS */
134 /* XXX Hardware padding doesn't work yet(?) */
135 #define SMC91CXX_SW_PAD
137 const char *smc91cxx_idstrs
[] = {
141 "SMC91C90/91C92", /* 3 */
142 "SMC91C94/91C96", /* 4 */
146 "SMC91C100FD", /* 8 */
156 /* Supported media types. */
157 const int smc91cxx_media
[] = {
161 #define NSMC91CxxMEDIA (sizeof(smc91cxx_media) / sizeof(smc91cxx_media[0]))
166 u_int32_t
smc91cxx_mii_bitbang_read(device_t
);
167 void smc91cxx_mii_bitbang_write(device_t
, u_int32_t
);
169 const struct mii_bitbang_ops smc91cxx_mii_bitbang_ops
= {
170 smc91cxx_mii_bitbang_read
,
171 smc91cxx_mii_bitbang_write
,
173 MR_MDO
, /* MII_BIT_MDO */
174 MR_MDI
, /* MII_BIT_MDI */
175 MR_MCLK
, /* MII_BIT_MDC */
176 MR_MDOE
, /* MII_BIT_DIR_HOST_PHY */
177 0, /* MII_BIT_DIR_PHY_HOST */
182 int smc91cxx_mii_readreg(device_t
, int, int);
183 void smc91cxx_mii_writereg(device_t
, int, int, int);
184 void smc91cxx_statchg(device_t
);
185 void smc91cxx_tick(void *);
187 int smc91cxx_mediachange(struct ifnet
*);
188 void smc91cxx_mediastatus(struct ifnet
*, struct ifmediareq
*);
190 int smc91cxx_set_media(struct smc91cxx_softc
*, int);
192 void smc91cxx_init(struct smc91cxx_softc
*);
193 void smc91cxx_read(struct smc91cxx_softc
*);
194 void smc91cxx_reset(struct smc91cxx_softc
*);
195 void smc91cxx_start(struct ifnet
*);
196 uint8_t smc91cxx_copy_tx_frame(struct smc91cxx_softc
*, struct mbuf
*);
197 void smc91cxx_resume(struct smc91cxx_softc
*);
198 void smc91cxx_stop(struct smc91cxx_softc
*);
199 void smc91cxx_watchdog(struct ifnet
*);
200 int smc91cxx_ioctl(struct ifnet
*, u_long
, void *);
202 static inline int ether_cmp(const void *, const void *);
204 ether_cmp(const void *va
, const void *vb
)
206 const u_int8_t
*a
= va
;
207 const u_int8_t
*b
= vb
;
209 return ((a
[5] != b
[5]) || (a
[4] != b
[4]) || (a
[3] != b
[3]) ||
210 (a
[2] != b
[2]) || (a
[1] != b
[1]) || (a
[0] != b
[0]));
214 smc91cxx_intr_mask_write(bus_space_tag_t bst
, bus_space_handle_t bsh
,
217 KDASSERT((mask
& IM_ERCV_INT
) == 0);
218 #ifdef SMC91CXX_NO_BYTE_WRITE
219 #if BYTE_ORDER == LITTLE_ENDIAN
220 bus_space_write_2(bst
, bsh
, INTR_STAT_REG_B
, mask
<< 8);
222 bus_space_write_2(bst
, bsh
, INTR_STAT_REG_B
, mask
);
225 bus_space_write_1(bst
, bsh
, INTR_MASK_REG_B
, mask
);
227 KDASSERT(!(bus_space_read_1(bst
, bsh
, INTR_MASK_REG_B
) & IM_ERCV_INT
));
231 smc91cxx_intr_ack_write(bus_space_tag_t bst
, bus_space_handle_t bsh
,
234 #ifdef SMC91CXX_NO_BYTE_WRITE
235 #if BYTE_ORDER == LITTLE_ENDIAN
236 bus_space_write_2(bst
, bsh
, INTR_ACK_REG_B
,
237 mask
| (bus_space_read_2(bst
, bsh
, INTR_ACK_REG_B
) & 0xff00));
239 bus_space_write_2(bst
, bsh
, INTR_ACK_REG_B
,
240 (mask
<< 8) | (bus_space_read_2(bst
, bsh
, INTR_ACK_REG_B
) & 0xff));
243 bus_space_write_1(bst
, bsh
, INTR_ACK_REG_B
, mask
);
245 KDASSERT(!(bus_space_read_1(bst
, bsh
, INTR_MASK_REG_B
) & IM_ERCV_INT
));
249 smc91cxx_attach(struct smc91cxx_softc
*sc
, u_int8_t
*myea
)
251 struct ifnet
*ifp
= &sc
->sc_ec
.ec_if
;
252 bus_space_tag_t bst
= sc
->sc_bst
;
253 bus_space_handle_t bsh
= sc
->sc_bsh
;
254 struct ifmedia
*ifm
= &sc
->sc_mii
.mii_media
;
256 u_int32_t miicapabilities
;
258 u_int8_t enaddr
[ETHER_ADDR_LEN
];
259 int i
, aui
, mult
, scale
, memsize
;
262 tmp
= bus_space_read_2(bst
, bsh
, BANK_SELECT_REG_W
);
263 /* check magic number */
264 if ((tmp
& BSR_DETECT_MASK
) != BSR_DETECT_VALUE
) {
265 aprint_error_dev(&sc
->sc_dev
, "failed to detect chip, bsr=%04x\n", tmp
);
269 /* Make sure the chip is stopped. */
272 SMC_SELECT_BANK(sc
, 3);
273 tmp
= bus_space_read_2(bst
, bsh
, REVISION_REG_W
);
274 sc
->sc_chipid
= RR_ID(tmp
);
275 idstr
= smc91cxx_idstrs
[sc
->sc_chipid
];
277 aprint_normal_dev(&sc
->sc_dev
, "");
279 aprint_normal("%s, ", idstr
);
281 aprint_normal("unknown chip id %d, ", sc
->sc_chipid
);
282 aprint_normal("revision %d, ", RR_REV(tmp
));
284 SMC_SELECT_BANK(sc
, 0);
285 switch (sc
->sc_chipid
) {
287 mult
= MCR_MEM_MULT(bus_space_read_2(bst
, bsh
, MEM_CFG_REG_W
));
288 scale
= MIR_SCALE_91C9x
;
292 mult
= MIR_MULT_91C111
;
293 scale
= MIR_SCALE_91C111
;
295 memsize
= bus_space_read_2(bst
, bsh
, MEM_INFO_REG_W
) & MIR_TOTAL_MASK
;
296 if (memsize
== 255) memsize
++;
297 memsize
*= scale
* mult
;
299 format_bytes(pbuf
, sizeof(pbuf
), memsize
);
300 aprint_normal("buffer size: %s\n", pbuf
);
302 /* Read the station address from the chip. */
303 SMC_SELECT_BANK(sc
, 1);
306 for (i
= 0; i
< ETHER_ADDR_LEN
; i
+= 2) {
307 tmp
= bus_space_read_2(bst
, bsh
, IAR_ADDR0_REG_W
+ i
);
308 myea
[i
+ 1] = (tmp
>> 8) & 0xff;
309 myea
[i
] = tmp
& 0xff;
312 aprint_normal_dev(&sc
->sc_dev
, "MAC address %s, ",
313 ether_sprintf(myea
));
315 /* Initialize the ifnet structure. */
316 strlcpy(ifp
->if_xname
, device_xname(&sc
->sc_dev
), IFNAMSIZ
);
318 ifp
->if_start
= smc91cxx_start
;
319 ifp
->if_ioctl
= smc91cxx_ioctl
;
320 ifp
->if_watchdog
= smc91cxx_watchdog
;
322 IFF_BROADCAST
| IFF_SIMPLEX
| IFF_NOTRAILERS
| IFF_MULTICAST
;
323 IFQ_SET_READY(&ifp
->if_snd
);
325 /* Attach the interface. */
327 ether_ifattach(ifp
, myea
);
330 * Initialize our media structures and MII info. We will
331 * probe the MII if we are on the SMC91Cxx
333 sc
->sc_mii
.mii_ifp
= ifp
;
334 sc
->sc_mii
.mii_readreg
= smc91cxx_mii_readreg
;
335 sc
->sc_mii
.mii_writereg
= smc91cxx_mii_writereg
;
336 sc
->sc_mii
.mii_statchg
= smc91cxx_statchg
;
337 ifmedia_init(ifm
, IFM_IMASK
, smc91cxx_mediachange
, smc91cxx_mediastatus
);
339 SMC_SELECT_BANK(sc
, 1);
340 tmp
= bus_space_read_2(bst
, bsh
, CONFIG_REG_W
);
342 miicapabilities
= BMSR_MEDIAMASK
|BMSR_ANEG
;
343 switch (sc
->sc_chipid
) {
346 * The 91100 does not have full-duplex capabilities,
347 * even if the PHY does.
349 miicapabilities
&= ~(BMSR_100TXFDX
| BMSR_10TFDX
);
352 if (tmp
& CR_MII_SELECT
) {
353 aprint_normal("default media MII");
354 if (sc
->sc_chipid
== CHIP_91C111
) {
355 aprint_normal(" (%s PHY)\n", (tmp
& CR_AUI_SELECT
) ?
356 "external" : "internal");
357 sc
->sc_internal_phy
= !(tmp
& CR_AUI_SELECT
);
360 mii_attach(&sc
->sc_dev
, &sc
->sc_mii
, miicapabilities
,
361 MII_PHY_ANY
, MII_OFFSET_ANY
, 0);
362 if (LIST_FIRST(&sc
->sc_mii
.mii_phys
) == NULL
) {
363 ifmedia_add(&sc
->sc_mii
.mii_media
,
364 IFM_ETHER
|IFM_NONE
, 0, NULL
);
365 ifmedia_set(&sc
->sc_mii
.mii_media
,
368 ifmedia_set(&sc
->sc_mii
.mii_media
,
371 sc
->sc_flags
|= SMC_FLAGS_HAS_MII
;
374 if (sc
->sc_chipid
== CHIP_91C111
) {
376 * XXX: Should bring it out of low-power mode
378 aprint_normal("EPH interface in low power mode\n");
379 sc
->sc_internal_phy
= 0;
384 aprint_normal("default media %s\n", (aui
= (tmp
& CR_AUI_SELECT
)) ?
386 for (i
= 0; i
< NSMC91CxxMEDIA
; i
++)
387 ifmedia_add(ifm
, smc91cxx_media
[i
], 0, NULL
);
388 ifmedia_set(ifm
, IFM_ETHER
| (aui
? IFM_10_5
: IFM_10_T
));
393 rnd_attach_source(&sc
->rnd_source
, device_xname(&sc
->sc_dev
),
397 callout_init(&sc
->sc_mii_callout
, 0);
399 /* The attach is successful. */
400 sc
->sc_flags
|= SMC_FLAGS_ATTACHED
;
404 * Change media according to request.
407 smc91cxx_mediachange(struct ifnet
*ifp
)
409 struct smc91cxx_softc
*sc
= ifp
->if_softc
;
411 return (smc91cxx_set_media(sc
, sc
->sc_mii
.mii_media
.ifm_media
));
415 smc91cxx_set_media(struct smc91cxx_softc
*sc
, int media
)
417 bus_space_tag_t bst
= sc
->sc_bst
;
418 bus_space_handle_t bsh
= sc
->sc_bsh
;
423 * If the interface is not currently powered on, just return.
424 * When it is enabled later, smc91cxx_init() will properly set
425 * up the media for us.
427 if ((sc
->sc_flags
& SMC_FLAGS_ENABLED
) == 0)
430 if (IFM_TYPE(media
) != IFM_ETHER
)
433 if ((sc
->sc_flags
& SMC_FLAGS_HAS_MII
) == 0 ||
434 (rc
= mii_mediachg(&sc
->sc_mii
)) == ENXIO
)
437 switch (IFM_SUBTYPE(media
)) {
440 SMC_SELECT_BANK(sc
, 1);
441 tmp
= bus_space_read_2(bst
, bsh
, CONFIG_REG_W
);
442 if (IFM_SUBTYPE(media
) == IFM_10_5
)
443 tmp
|= CR_AUI_SELECT
;
445 tmp
&= ~CR_AUI_SELECT
;
446 bus_space_write_2(bst
, bsh
, CONFIG_REG_W
, tmp
);
447 delay(20000); /* XXX is this needed? */
458 * Notify the world which media we're using.
461 smc91cxx_mediastatus(struct ifnet
*ifp
, struct ifmediareq
*ifmr
)
463 struct smc91cxx_softc
*sc
= ifp
->if_softc
;
464 bus_space_tag_t bst
= sc
->sc_bst
;
465 bus_space_handle_t bsh
= sc
->sc_bsh
;
468 if ((sc
->sc_flags
& SMC_FLAGS_ENABLED
) == 0) {
469 ifmr
->ifm_active
= IFM_ETHER
| IFM_NONE
;
470 ifmr
->ifm_status
= 0;
475 * If we have MII, go ask the PHY what's going on.
477 if (sc
->sc_flags
& SMC_FLAGS_HAS_MII
) {
478 mii_pollstat(&sc
->sc_mii
);
479 ifmr
->ifm_active
= sc
->sc_mii
.mii_media_active
;
480 ifmr
->ifm_status
= sc
->sc_mii
.mii_media_status
;
484 SMC_SELECT_BANK(sc
, 1);
485 tmp
= bus_space_read_2(bst
, bsh
, CONFIG_REG_W
);
487 IFM_ETHER
| ((tmp
& CR_AUI_SELECT
) ? IFM_10_5
: IFM_10_T
);
491 * Reset and initialize the chip.
494 smc91cxx_init(struct smc91cxx_softc
*sc
)
496 struct ifnet
*ifp
= &sc
->sc_ec
.ec_if
;
497 bus_space_tag_t bst
= sc
->sc_bst
;
498 bus_space_handle_t bsh
= sc
->sc_bsh
;
500 const u_int8_t
*enaddr
;
506 * This resets the registers mostly to defaults, but doesn't
507 * affect the EEPROM. After the reset cycle, we pause briefly
508 * for the chip to recover.
510 * XXX how long are we really supposed to delay? --thorpej
512 SMC_SELECT_BANK(sc
, 0);
513 bus_space_write_2(bst
, bsh
, RECV_CONTROL_REG_W
, RCR_SOFTRESET
);
515 bus_space_write_2(bst
, bsh
, RECV_CONTROL_REG_W
, 0);
518 bus_space_write_2(bst
, bsh
, TXMIT_CONTROL_REG_W
, 0);
520 /* Set the Ethernet address. */
521 SMC_SELECT_BANK(sc
, 1);
522 enaddr
= (const u_int8_t
*)CLLADDR(ifp
->if_sadl
);
523 for (i
= 0; i
< ETHER_ADDR_LEN
; i
+= 2) {
524 tmp
= enaddr
[i
+ 1] << 8 | enaddr
[i
];
525 bus_space_write_2(bst
, bsh
, IAR_ADDR0_REG_W
+ i
, tmp
);
529 * Set the control register to automatically release successfully
530 * transmitted packets (making the best use of our limited memory)
531 * and enable the EPH interrupt on certain TX errors.
533 bus_space_write_2(bst
, bsh
, CONTROL_REG_W
, (CTR_AUTO_RELEASE
|
534 CTR_TE_ENABLE
| CTR_CR_ENABLE
| CTR_LE_ENABLE
));
537 * Reset the MMU and wait for it to be un-busy.
539 SMC_SELECT_BANK(sc
, 2);
540 bus_space_write_2(bst
, bsh
, MMU_CMD_REG_W
, MMUCR_RESET
);
541 sc
->sc_txpacketno
= ARR_FAILED
;
543 tmp
= bus_space_read_2(bst
, bsh
, MMU_CMD_REG_W
);
544 if (tmp
== 0xffff) /* card went away! */
546 if ((tmp
& MMUCR_BUSY
) == 0)
551 * Disable all interrupts.
553 smc91cxx_intr_mask_write(bst
, bsh
, 0);
556 * On the 91c111, enable auto-negotiation, and set the LED
557 * status pins to something sane.
558 * XXX: Should be some way for MD code to decide the latter.
560 SMC_SELECT_BANK(sc
, 0);
561 if (sc
->sc_chipid
== CHIP_91C111
) {
562 bus_space_write_2(bst
, bsh
, RX_PHY_CONTROL_REG_W
,
564 (RPC_LS_LINK_DETECT
<< RPC_LSA_SHIFT
) |
565 (RPC_LS_TXRX
<< RPC_LSB_SHIFT
));
571 smc91cxx_set_media(sc
, sc
->sc_mii
.mii_media
.ifm_cur
->ifm_media
);
574 * Set the receive filter. We want receive enable and auto
575 * strip of CRC from received packet. If we are in promisc. mode,
576 * then set that bit as well.
578 * XXX Initialize multicast filter. For now, we just accept
581 SMC_SELECT_BANK(sc
, 0);
583 tmp
= RCR_ENABLE
| RCR_STRIP_CRC
| RCR_ALMUL
;
584 if (ifp
->if_flags
& IFF_PROMISC
)
587 bus_space_write_2(bst
, bsh
, RECV_CONTROL_REG_W
, tmp
);
590 * Set transmitter control to "enabled".
594 #ifndef SMC91CXX_SW_PAD
596 * Enable hardware padding of transmitted packets.
599 tmp
|= TCR_PAD_ENABLE
;
602 bus_space_write_2(bst
, bsh
, TXMIT_CONTROL_REG_W
, tmp
);
605 * Now, enable interrupts.
607 SMC_SELECT_BANK(sc
, 2);
609 sc
->sc_intmask
= IM_EPH_INT
| IM_RX_OVRN_INT
| IM_RCV_INT
;
610 if (sc
->sc_chipid
== CHIP_91C111
&& sc
->sc_internal_phy
) {
611 sc
->sc_intmask
|= IM_MD_INT
;
613 smc91cxx_intr_mask_write(bst
, bsh
, sc
->sc_intmask
);
615 /* Interface is now running, with no output active. */
616 ifp
->if_flags
|= IFF_RUNNING
;
617 ifp
->if_flags
&= ~IFF_OACTIVE
;
619 if (sc
->sc_flags
& SMC_FLAGS_HAS_MII
) {
620 /* Start the one second clock. */
621 callout_reset(&sc
->sc_mii_callout
, hz
, smc91cxx_tick
, sc
);
625 * Attempt to start any pending transmission.
633 * Start output on an interface.
634 * Must be called at splnet or interrupt level.
637 smc91cxx_start(struct ifnet
*ifp
)
639 struct smc91cxx_softc
*sc
= ifp
->if_softc
;
640 bus_space_tag_t bst
= sc
->sc_bst
;
641 bus_space_handle_t bsh
= sc
->sc_bsh
;
644 u_int16_t length
, npages
;
649 if ((ifp
->if_flags
& (IFF_RUNNING
|IFF_OACTIVE
)) != IFF_RUNNING
)
654 * Peek at the next packet.
656 IFQ_POLL(&ifp
->if_snd
, m
);
661 * Compute the frame length and set pad to give an overall even
662 * number of bytes. Below, we assume that the packet length
665 for (len
= 0; m
!= NULL
; m
= m
->m_next
)
670 * We drop packets that are too large. Perhaps we should
671 * truncate them instead?
673 if ((len
+ pad
) > (ETHER_MAX_LEN
- ETHER_CRC_LEN
)) {
674 printf("%s: large packet discarded\n", device_xname(&sc
->sc_dev
));
676 IFQ_DEQUEUE(&ifp
->if_snd
, m
);
681 #ifdef SMC91CXX_SW_PAD
683 * Not using hardware padding; pad to ETHER_MIN_LEN.
685 if (len
< (ETHER_MIN_LEN
- ETHER_CRC_LEN
))
686 pad
= ETHER_MIN_LEN
- ETHER_CRC_LEN
- len
;
692 * The MMU has a 256 byte page size. The MMU expects us to
693 * ask for "npages - 1". We include space for the status word,
694 * byte count, and control bytes in the allocation request.
696 npages
= ((length
& ~1) + 6) >> 8;
699 * Now allocate the memory.
701 SMC_SELECT_BANK(sc
, 2);
702 bus_space_write_2(bst
, bsh
, MMU_CMD_REG_W
, MMUCR_ALLOC
| npages
);
704 timo
= MEMORY_WAIT_TIME
;
705 if (__predict_false((sc
->sc_txpacketno
& ARR_FAILED
) == 0)) {
706 packetno
= sc
->sc_txpacketno
;
707 sc
->sc_txpacketno
= ARR_FAILED
;
710 if (bus_space_read_1(bst
, bsh
,
711 INTR_STAT_REG_B
) & IM_ALLOC_INT
)
717 packetno
= bus_space_read_1(bst
, bsh
, ALLOC_RESULT_REG_B
);
719 if (packetno
& ARR_FAILED
|| timo
== 0) {
721 * No transmit memory is available. Record the number
722 * of requestd pages and enable the allocation completion
723 * interrupt. Set up the watchdog timer in case we miss
724 * the interrupt. Mark the interface as active so that
725 * no one else attempts to transmit while we're allocating
728 sc
->sc_intmask
|= IM_ALLOC_INT
;
729 smc91cxx_intr_mask_write(bst
, bsh
, sc
->sc_intmask
);
731 ifp
->if_flags
|= IFF_OACTIVE
;
737 * We have a packet number - set the data window.
739 bus_space_write_1(bst
, bsh
, PACKET_NUM_REG_B
, packetno
);
742 * Point to the beginning of the packet.
744 bus_space_write_2(bst
, bsh
, POINTER_REG_W
, PTR_AUTOINC
/* | 0x0000 */);
747 * Send the packet length (+6 for stats, length, and control bytes)
748 * and the status word (set to zeros).
750 bus_space_write_2(bst
, bsh
, DATA_REG_W
, 0);
751 bus_space_write_2(bst
, bsh
, DATA_REG_W
, (length
+ 6) & 0x7ff);
754 * Get the packet from the kernel. This will include the Ethernet
755 * frame header, MAC address, etc.
757 IFQ_DEQUEUE(&ifp
->if_snd
, m
);
760 * Push the packet out to the card.
762 oddbyte
= smc91cxx_copy_tx_frame(sc
, m
);
764 #ifdef SMC91CXX_SW_PAD
765 #ifdef SMC91CXX_NO_BYTE_WRITE
766 #if BYTE_ORDER == LITTLE_ENDIAN
767 if (pad
> 1 && (pad
& 1)) {
768 bus_space_write_2(bst
, bsh
, DATA_REG_W
, oddbyte
<< 0);
772 if (pad
> 1 && (pad
& 1)) {
773 bus_space_write_2(bst
, bsh
, DATA_REG_W
, oddbyte
<< 8);
783 bus_space_write_2(bst
, bsh
, DATA_REG_W
, 0);
788 #ifdef SMC91CXX_NO_BYTE_WRITE
790 * Push out control byte and unused packet byte. The control byte
791 * is 0, meaning the packet is even lengthed and no special
792 * CRC handling is necessary.
794 #if BYTE_ORDER == LITTLE_ENDIAN
795 bus_space_write_2(bst
, bsh
, DATA_REG_W
,
796 oddbyte
| (pad
? (CTLB_ODD
<< 8) : 0));
798 bus_space_write_2(bst
, bsh
, DATA_REG_W
,
799 (oddbyte
<< 8) | (pad
? CTLB_ODD
: 0));
803 bus_space_write_1(bst
, bsh
, DATA_REG_B
, 0);
807 * Enable transmit interrupts and let the chip go. Set a watchdog
808 * in case we miss the interrupt.
810 sc
->sc_intmask
|= IM_TX_INT
| IM_TX_EMPTY_INT
;
811 smc91cxx_intr_mask_write(bst
, bsh
, sc
->sc_intmask
);
813 bus_space_write_2(bst
, bsh
, MMU_CMD_REG_W
, MMUCR_ENQUEUE
);
818 /* Hand off a copy to the bpf. */
820 bpf_mtap(ifp
->if_bpf
, m
);
828 * Check for incoming pcakets. We don't want to overflow the small
829 * RX FIFO. If nothing has arrived, attempt to queue another
832 if (bus_space_read_2(bst
, bsh
, FIFO_PORTS_REG_W
) & FIFO_REMPTY
)
837 * Squirt a (possibly misaligned) mbuf to the device
840 smc91cxx_copy_tx_frame(struct smc91cxx_softc
*sc
, struct mbuf
*m0
)
842 bus_space_tag_t bst
= sc
->sc_bst
;
843 bus_space_handle_t bsh
= sc
->sc_bsh
;
852 /* start out with no leftover data */
856 /* Process the chain of mbufs */
857 for (m
= m0
; m
!= NULL
; m
= m
->m_next
) {
859 * Process all of the data in a single mbuf.
861 p
= mtod(m
, u_int8_t
*);
870 * Data left over (from mbuf or realignment).
871 * Buffer the next byte, and write it and
872 * the leftover data out.
876 bus_space_write_2(bst
, bsh
, DATA_REG_W
, dbuf
);
878 } else if ((long) p
& 1) {
880 * Misaligned data. Buffer the next byte.
887 * Aligned data. This is the case we like.
889 * Write-region out as much as we can, then
890 * buffer the remaining byte (if any).
894 bus_space_write_multi_stream_2(bst
, bsh
,
895 DATA_REG_W
, (u_int16_t
*)p
, len
>> 1);
904 panic("smc91cxx_copy_tx_frame: negative len");
907 panic("smc91cxx_copy_tx_frame: p != lim");
910 #ifndef SMC91CXX_NO_BYTE_WRITE
912 bus_space_write_1(bst
, bsh
, DATA_REG_B
, dbuf
);
918 * Interrupt service routine.
921 smc91cxx_intr(void *arg
)
923 struct smc91cxx_softc
*sc
= arg
;
924 struct ifnet
*ifp
= &sc
->sc_ec
.ec_if
;
925 bus_space_tag_t bst
= sc
->sc_bst
;
926 bus_space_handle_t bsh
= sc
->sc_bsh
;
927 u_int8_t mask
, interrupts
, status
;
928 u_int16_t packetno
, tx_status
, card_stats
;
929 #ifdef SMC91CXX_NO_BYTE_WRITE
933 if ((sc
->sc_flags
& SMC_FLAGS_ENABLED
) == 0 ||
934 !device_is_active(&sc
->sc_dev
))
937 SMC_SELECT_BANK(sc
, 2);
940 * Obtain the current interrupt status and mask.
942 #ifdef SMC91CXX_NO_BYTE_WRITE
943 v
= bus_space_read_2(bst
, bsh
, INTR_STAT_REG_B
);
946 * Get the set of interrupt which occurred and eliminate any
947 * which are not enabled.
949 #if BYTE_ORDER == LITTLE_ENDIAN
951 interrupts
= v
& 0xff;
956 KDASSERT(mask
== sc
->sc_intmask
);
958 mask
= bus_space_read_1(bst
, bsh
, INTR_MASK_REG_B
);
961 * Get the set of interrupt which occurred and eliminate any
962 * which are not enabled.
964 interrupts
= bus_space_read_1(bst
, bsh
, INTR_STAT_REG_B
);
966 status
= interrupts
& mask
;
973 * It's ours; disable all interrupts while we process them.
975 smc91cxx_intr_mask_write(bst
, bsh
, 0);
978 * Receive overrun interrupts.
980 if (status
& IM_RX_OVRN_INT
) {
981 smc91cxx_intr_ack_write(bst
, bsh
, IM_RX_OVRN_INT
);
986 * Receive interrupts.
988 if (status
& IM_RCV_INT
) {
989 #if 1 /* DIAGNOSTIC */
990 packetno
= bus_space_read_2(bst
, bsh
, FIFO_PORTS_REG_W
);
991 if (packetno
& FIFO_REMPTY
) {
992 aprint_error_dev(&sc
->sc_dev
, "receive interrupt on empty fifo\n");
1000 * Memory allocation interrupts.
1002 if (status
& IM_ALLOC_INT
) {
1003 /* Disable this interrupt. */
1004 mask
&= ~IM_ALLOC_INT
;
1005 sc
->sc_intmask
&= ~IM_ALLOC_INT
;
1008 * Save allocated packet number for use in start
1010 packetno
= bus_space_read_1(bst
, bsh
, ALLOC_RESULT_REG_B
);
1011 KASSERT(sc
->sc_txpacketno
& ARR_FAILED
);
1012 sc
->sc_txpacketno
= packetno
;
1015 * We can transmit again!
1017 ifp
->if_flags
&= ~IFF_OACTIVE
;
1022 * Transmit complete interrupt. Handle transmission error messages.
1023 * This will only be called on error condition because of AUTO RELEASE
1026 if (status
& IM_TX_INT
) {
1027 smc91cxx_intr_ack_write(bst
, bsh
, IM_TX_INT
);
1029 packetno
= bus_space_read_2(bst
, bsh
, FIFO_PORTS_REG_W
) &
1033 * Select this as the packet to read from.
1035 bus_space_write_1(bst
, bsh
, PACKET_NUM_REG_B
, packetno
);
1038 * Position the pointer to the beginning of the packet.
1040 bus_space_write_2(bst
, bsh
, POINTER_REG_W
,
1041 PTR_AUTOINC
| PTR_READ
/* | 0x0000 */);
1044 * Fetch the TX status word. This will be a copy of
1045 * the EPH_STATUS_REG_W at the time of the transmission
1048 tx_status
= bus_space_read_2(bst
, bsh
, DATA_REG_W
);
1050 if (tx_status
& EPHSR_TX_SUC
) {
1051 static struct timeval txsuc_last
;
1052 static int txsuc_count
;
1053 if (ppsratecheck(&txsuc_last
, &txsuc_count
, 1))
1054 printf("%s: successful packet caused TX"
1055 " interrupt?!\n", device_xname(&sc
->sc_dev
));
1059 if (tx_status
& EPHSR_LATCOL
)
1060 ifp
->if_collisions
++;
1062 /* Disable this interrupt (start will reenable if needed). */
1064 sc
->sc_intmask
&= ~IM_TX_INT
;
1067 * Some of these errors disable the transmitter; reenable it.
1069 SMC_SELECT_BANK(sc
, 0);
1070 #ifdef SMC91CXX_SW_PAD
1071 bus_space_write_2(bst
, bsh
, TXMIT_CONTROL_REG_W
, TCR_ENABLE
);
1073 bus_space_write_2(bst
, bsh
, TXMIT_CONTROL_REG_W
,
1074 TCR_ENABLE
| TCR_PAD_ENABLE
);
1078 * Kill the failed packet and wait for the MMU to unbusy.
1080 SMC_SELECT_BANK(sc
, 2);
1081 while (bus_space_read_2(bst
, bsh
, MMU_CMD_REG_W
) & MMUCR_BUSY
)
1082 /* XXX bound this loop! */ ;
1083 bus_space_write_2(bst
, bsh
, MMU_CMD_REG_W
, MMUCR_FREEPKT
);
1089 * Transmit underrun interrupts. We use this opportunity to
1090 * update transmit statistics from the card.
1092 if (status
& IM_TX_EMPTY_INT
) {
1093 smc91cxx_intr_ack_write(bst
, bsh
, IM_TX_EMPTY_INT
);
1095 /* Disable this interrupt. */
1096 mask
&= ~IM_TX_EMPTY_INT
;
1097 sc
->sc_intmask
&= ~IM_TX_EMPTY_INT
;
1099 SMC_SELECT_BANK(sc
, 0);
1100 card_stats
= bus_space_read_2(bst
, bsh
, COUNTER_REG_W
);
1102 /* Single collisions. */
1103 ifp
->if_collisions
+= card_stats
& ECR_COLN_MASK
;
1105 /* Multiple collisions. */
1106 ifp
->if_collisions
+= (card_stats
& ECR_MCOLN_MASK
) >> 4;
1108 SMC_SELECT_BANK(sc
, 2);
1113 if (sc
->sc_chipid
== CHIP_91C111
&& sc
->sc_internal_phy
&&
1114 (status
& IM_MD_INT
)) {
1116 * Internal PHY status change
1118 mii_tick(&sc
->sc_mii
);
1122 * Other errors. Reset the interface.
1124 if (status
& IM_EPH_INT
) {
1130 * Attempt to queue more packets for transmission.
1132 smc91cxx_start(ifp
);
1136 * Reenable the interrupts we wish to receive now that processing
1139 mask
|= sc
->sc_intmask
;
1140 smc91cxx_intr_mask_write(bst
, bsh
, mask
);
1144 rnd_add_uint32(&sc
->rnd_source
, status
);
1151 * Read a packet from the card and pass it up to the kernel.
1152 * NOTE! WE EXPECT TO BE IN REGISTER WINDOW 2!
1155 smc91cxx_read(struct smc91cxx_softc
*sc
)
1157 struct ifnet
*ifp
= &sc
->sc_ec
.ec_if
;
1158 bus_space_tag_t bst
= sc
->sc_bst
;
1159 bus_space_handle_t bsh
= sc
->sc_bsh
;
1160 struct ether_header
*eh
;
1162 u_int16_t status
, packetno
, packetlen
;
1168 * Set data pointer to the beginning of the packet. Since
1169 * PTR_RCV is set, the packet number will be found automatically
1170 * in FIFO_PORTS_REG_W, FIFO_RX_MASK.
1172 packetno
= bus_space_read_2(bst
, bsh
, FIFO_PORTS_REG_W
);
1173 if (packetno
& FIFO_REMPTY
)
1176 bus_space_write_2(bst
, bsh
, POINTER_REG_W
,
1177 PTR_READ
| PTR_RCV
| PTR_AUTOINC
/* | 0x0000 */);
1180 * First two words are status and packet length.
1182 if ((sc
->sc_flags
& SMC_FLAGS_32BIT_READ
) == 0) {
1183 status
= bus_space_read_2(bst
, bsh
, DATA_REG_W
);
1184 packetlen
= bus_space_read_2(bst
, bsh
, DATA_REG_W
);
1186 dr
= bus_space_read_4(bst
, bsh
, DATA_REG_W
);
1187 #if BYTE_ORDER == LITTLE_ENDIAN
1188 status
= (u_int16_t
)dr
;
1189 packetlen
= (u_int16_t
)(dr
>> 16);
1191 packetlen
= (u_int16_t
)dr
;
1192 status
= (u_int16_t
)(dr
>> 16);
1196 packetlen
&= RLEN_MASK
;
1197 if (packetlen
< ETHER_MIN_LEN
- ETHER_CRC_LEN
+ 6 || packetlen
> 1534) {
1203 * The packet length includes 3 extra words: status, length,
1204 * and an extra word that includes the control byte.
1209 * Account for receive errors and discard.
1211 if (status
& RS_ERRORS
) {
1217 * Adjust for odd-length packet.
1219 if (status
& RS_ODDFRAME
)
1223 * Allocate a header mbuf.
1225 MGETHDR(m
, M_DONTWAIT
, MT_DATA
);
1228 m
->m_pkthdr
.rcvif
= ifp
;
1229 m
->m_pkthdr
.len
= packetlen
;
1232 * Always put the packet in a cluster.
1233 * XXX should chain small mbufs if less than threshold.
1235 MCLGET(m
, M_DONTWAIT
);
1236 if ((m
->m_flags
& M_EXT
) == 0) {
1239 aprint_error_dev(&sc
->sc_dev
, "can't allocate cluster for incoming packet\n");
1244 * Pull the packet off the interface. Make sure the payload
1247 if ((sc
->sc_flags
& SMC_FLAGS_32BIT_READ
) == 0) {
1248 m
->m_data
= (char *) ALIGN(mtod(m
, char *) +
1249 sizeof(struct ether_header
)) - sizeof(struct ether_header
);
1251 eh
= mtod(m
, struct ether_header
*);
1252 data
= mtod(m
, u_int8_t
*);
1253 KASSERT(trunc_page((uintptr_t)data
) == trunc_page((uintptr_t)data
+ packetlen
- 1));
1255 bus_space_read_multi_stream_2(bst
, bsh
, DATA_REG_W
,
1256 (u_int16_t
*)data
, packetlen
>> 1);
1257 if (packetlen
& 1) {
1258 data
+= packetlen
& ~1;
1259 *data
= bus_space_read_1(bst
, bsh
, DATA_REG_B
);
1264 m
->m_data
= (void *) ALIGN(mtod(m
, void *));
1265 eh
= mtod(m
, struct ether_header
*);
1266 dp
= data
= mtod(m
, u_int8_t
*);
1267 KASSERT(trunc_page((uintptr_t)data
) == trunc_page((uintptr_t)data
+ packetlen
- 1));
1269 bus_space_read_multi_stream_4(bst
, bsh
, DATA_REG_W
,
1270 (u_int32_t
*)data
, packetlen
>> 2);
1271 if (packetlen
& 3) {
1272 data
+= packetlen
& ~3;
1273 *((u_int32_t
*)data
) =
1274 bus_space_read_stream_4(bst
, bsh
, DATA_REG_W
);
1281 * Make sure to behave as IFF_SIMPLEX in all cases.
1282 * This is to cope with SMC91C92 (Megahertz XJ10BT), which
1283 * loops back packets to itself on promiscuous mode.
1284 * (should be ensured by chipset configuration)
1286 if ((ifp
->if_flags
& IFF_PROMISC
) != 0) {
1288 * Drop packet looped back from myself.
1290 if (ether_cmp(eh
->ether_shost
, CLLADDR(ifp
->if_sadl
)) == 0) {
1296 m
->m_pkthdr
.len
= m
->m_len
= packetlen
;
1300 * Hand the packet off to bpf listeners.
1303 bpf_mtap(ifp
->if_bpf
, m
);
1306 (*ifp
->if_input
)(ifp
, m
);
1310 * Tell the card to free the memory occupied by this packet.
1312 while (bus_space_read_2(bst
, bsh
, MMU_CMD_REG_W
) & MMUCR_BUSY
)
1313 /* XXX bound this loop! */ ;
1314 bus_space_write_2(bst
, bsh
, MMU_CMD_REG_W
, MMUCR_RELEASE
);
1317 * Check for another packet.
1319 packetno
= bus_space_read_2(bst
, bsh
, FIFO_PORTS_REG_W
);
1320 if (packetno
& FIFO_REMPTY
)
1326 * Process an ioctl request.
1329 smc91cxx_ioctl(struct ifnet
*ifp
, u_long cmd
, void *data
)
1331 struct smc91cxx_softc
*sc
= ifp
->if_softc
;
1332 struct ifaddr
*ifa
= (struct ifaddr
*)data
;
1333 struct ifreq
*ifr
= (struct ifreq
*)data
;
1339 case SIOCINITIFADDR
:
1340 if ((error
= smc91cxx_enable(sc
)) != 0)
1342 ifp
->if_flags
|= IFF_UP
;
1344 switch (ifa
->ifa_addr
->sa_family
) {
1347 arp_ifinit(ifp
, ifa
);
1357 if ((error
= ifioctl_common(ifp
, cmd
, data
)) != 0)
1359 /* XXX re-use ether_ioctl() */
1360 switch (ifp
->if_flags
& (IFF_UP
|IFF_RUNNING
)) {
1363 * If interface is marked down and it is running,
1367 ifp
->if_flags
&= ~IFF_RUNNING
;
1368 smc91cxx_disable(sc
);
1372 * If interface is marked up and it is stopped,
1375 if ((error
= smc91cxx_enable(sc
)) != 0)
1379 case IFF_UP
|IFF_RUNNING
:
1381 * Reset the interface to pick up changes in any
1382 * other flags that affect hardware registers.
1393 if ((sc
->sc_flags
& SMC_FLAGS_ENABLED
) == 0) {
1398 if ((error
= ether_ioctl(ifp
, cmd
, data
)) == ENETRESET
) {
1400 * Multicast list has changed; set the hardware
1401 * filter accordingly.
1403 if (ifp
->if_flags
& IFF_RUNNING
)
1411 error
= ifmedia_ioctl(ifp
, ifr
, &sc
->sc_mii
.mii_media
, cmd
);
1415 error
= ether_ioctl(ifp
, cmd
, data
);
1424 * Reset the interface.
1427 smc91cxx_reset(struct smc91cxx_softc
*sc
)
1441 smc91cxx_watchdog(struct ifnet
*ifp
)
1443 struct smc91cxx_softc
*sc
= ifp
->if_softc
;
1445 log(LOG_ERR
, "%s: device timeout\n", device_xname(&sc
->sc_dev
));
1451 * Stop output on the interface.
1454 smc91cxx_stop(struct smc91cxx_softc
*sc
)
1456 bus_space_tag_t bst
= sc
->sc_bst
;
1457 bus_space_handle_t bsh
= sc
->sc_bsh
;
1460 * Clear interrupt mask; disable all interrupts.
1462 SMC_SELECT_BANK(sc
, 2);
1463 smc91cxx_intr_mask_write(bst
, bsh
, 0);
1466 * Disable transmitter and receiver.
1468 SMC_SELECT_BANK(sc
, 0);
1469 bus_space_write_2(bst
, bsh
, RECV_CONTROL_REG_W
, 0);
1470 bus_space_write_2(bst
, bsh
, TXMIT_CONTROL_REG_W
, 0);
1473 * Cancel watchdog timer.
1475 sc
->sc_ec
.ec_if
.if_timer
= 0;
1479 * Enable power on the interface.
1482 smc91cxx_enable(struct smc91cxx_softc
*sc
)
1485 if ((sc
->sc_flags
& SMC_FLAGS_ENABLED
) == 0 && sc
->sc_enable
!= NULL
) {
1486 if ((*sc
->sc_enable
)(sc
) != 0) {
1487 aprint_error_dev(&sc
->sc_dev
, "device enable failed\n");
1492 sc
->sc_flags
|= SMC_FLAGS_ENABLED
;
1497 * Disable power on the interface.
1500 smc91cxx_disable(struct smc91cxx_softc
*sc
)
1503 if ((sc
->sc_flags
& SMC_FLAGS_ENABLED
) != 0 && sc
->sc_disable
!= NULL
) {
1504 (*sc
->sc_disable
)(sc
);
1505 sc
->sc_flags
&= ~SMC_FLAGS_ENABLED
;
1510 smc91cxx_activate(device_t self
, enum devact act
)
1512 struct smc91cxx_softc
*sc
= device_private(self
);
1515 case DVACT_DEACTIVATE
:
1516 if_deactivate(&sc
->sc_ec
.ec_if
);
1524 smc91cxx_detach(device_t self
, int flags
)
1526 struct smc91cxx_softc
*sc
= (struct smc91cxx_softc
*)self
;
1527 struct ifnet
*ifp
= &sc
->sc_ec
.ec_if
;
1529 /* Succeed now if there's no work to do. */
1530 if ((sc
->sc_flags
& SMC_FLAGS_ATTACHED
) == 0)
1534 /* smc91cxx_disable() checks SMC_FLAGS_ENABLED */
1535 smc91cxx_disable(sc
);
1537 /* smc91cxx_attach() never fails */
1539 /* Delete all media. */
1540 ifmedia_delete_instance(&sc
->sc_mii
.mii_media
, IFM_INST_ANY
);
1543 rnd_detach_source(&sc
->rnd_source
);
1545 ether_ifdetach(ifp
);
1552 smc91cxx_mii_bitbang_read(device_t self
)
1554 struct smc91cxx_softc
*sc
= (void *) self
;
1556 /* We're already in bank 3. */
1557 return (bus_space_read_2(sc
->sc_bst
, sc
->sc_bsh
, MGMT_REG_W
));
1561 smc91cxx_mii_bitbang_write(device_t self
, u_int32_t val
)
1563 struct smc91cxx_softc
*sc
= (void *) self
;
1565 /* We're already in bank 3. */
1566 bus_space_write_2(sc
->sc_bst
, sc
->sc_bsh
, MGMT_REG_W
, val
);
1570 smc91cxx_mii_readreg(device_t self
, int phy
, int reg
)
1572 struct smc91cxx_softc
*sc
= (void *) self
;
1575 SMC_SELECT_BANK(sc
, 3);
1577 val
= mii_bitbang_readreg(self
, &smc91cxx_mii_bitbang_ops
, phy
, reg
);
1579 SMC_SELECT_BANK(sc
, 2);
1585 smc91cxx_mii_writereg(device_t self
, int phy
, int reg
, int val
)
1587 struct smc91cxx_softc
*sc
= (void *) self
;
1589 SMC_SELECT_BANK(sc
, 3);
1591 mii_bitbang_writereg(self
, &smc91cxx_mii_bitbang_ops
, phy
, reg
, val
);
1593 SMC_SELECT_BANK(sc
, 2);
1597 smc91cxx_statchg(device_t self
)
1599 struct smc91cxx_softc
*sc
= (struct smc91cxx_softc
*)self
;
1600 bus_space_tag_t bst
= sc
->sc_bst
;
1601 bus_space_handle_t bsh
= sc
->sc_bsh
;
1604 SMC_SELECT_BANK(sc
, 0);
1605 mctl
= bus_space_read_2(bst
, bsh
, TXMIT_CONTROL_REG_W
);
1606 if (sc
->sc_mii
.mii_media_active
& IFM_FDX
)
1609 mctl
&= ~TCR_SWFDUP
;
1610 bus_space_write_2(bst
, bsh
, TXMIT_CONTROL_REG_W
, mctl
);
1611 SMC_SELECT_BANK(sc
, 2); /* back to operating window */
1615 * One second timer, used to tick the MII.
1618 smc91cxx_tick(void *arg
)
1620 struct smc91cxx_softc
*sc
= arg
;
1624 if ((sc
->sc_flags
& SMC_FLAGS_HAS_MII
) == 0)
1625 panic("smc91cxx_tick");
1628 if (!device_is_active(&sc
->sc_dev
))
1632 mii_tick(&sc
->sc_mii
);
1635 callout_reset(&sc
->sc_mii_callout
, hz
, smc91cxx_tick
, sc
);