Home | History | Annotate | Line # | Download | only in pci
if_msk.c revision 1.3.2.3
      1  1.3.2.3  ad /* $NetBSD: if_msk.c,v 1.3.2.3 2007/01/12 00:57:41 ad Exp $ */
      2  1.3.2.2  ad /*	$OpenBSD: if_msk.c,v 1.11 2006/08/17 22:07:40 brad Exp $	*/
      3  1.3.2.2  ad 
      4  1.3.2.2  ad /*
      5  1.3.2.2  ad  * Copyright (c) 1997, 1998, 1999, 2000
      6  1.3.2.2  ad  *	Bill Paul <wpaul (at) ctr.columbia.edu>.  All rights reserved.
      7  1.3.2.2  ad  *
      8  1.3.2.2  ad  * Redistribution and use in source and binary forms, with or without
      9  1.3.2.2  ad  * modification, are permitted provided that the following conditions
     10  1.3.2.2  ad  * are met:
     11  1.3.2.2  ad  * 1. Redistributions of source code must retain the above copyright
     12  1.3.2.2  ad  *    notice, this list of conditions and the following disclaimer.
     13  1.3.2.2  ad  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.3.2.2  ad  *    notice, this list of conditions and the following disclaimer in the
     15  1.3.2.2  ad  *    documentation and/or other materials provided with the distribution.
     16  1.3.2.2  ad  * 3. All advertising materials mentioning features or use of this software
     17  1.3.2.2  ad  *    must display the following acknowledgement:
     18  1.3.2.2  ad  *	This product includes software developed by Bill Paul.
     19  1.3.2.2  ad  * 4. Neither the name of the author nor the names of any co-contributors
     20  1.3.2.2  ad  *    may be used to endorse or promote products derived from this software
     21  1.3.2.2  ad  *    without specific prior written permission.
     22  1.3.2.2  ad  *
     23  1.3.2.2  ad  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
     24  1.3.2.2  ad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.3.2.2  ad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.3.2.2  ad  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
     27  1.3.2.2  ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28  1.3.2.2  ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  1.3.2.2  ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  1.3.2.2  ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31  1.3.2.2  ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32  1.3.2.2  ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     33  1.3.2.2  ad  * THE POSSIBILITY OF SUCH DAMAGE.
     34  1.3.2.2  ad  *
     35  1.3.2.2  ad  * $FreeBSD: /c/ncvs/src/sys/pci/if_sk.c,v 1.20 2000/04/22 02:16:37 wpaul Exp $
     36  1.3.2.2  ad  */
     37  1.3.2.2  ad 
     38  1.3.2.2  ad /*
     39  1.3.2.2  ad  * Copyright (c) 2003 Nathan L. Binkert <binkertn (at) umich.edu>
     40  1.3.2.2  ad  *
     41  1.3.2.2  ad  * Permission to use, copy, modify, and distribute this software for any
     42  1.3.2.2  ad  * purpose with or without fee is hereby granted, provided that the above
     43  1.3.2.2  ad  * copyright notice and this permission notice appear in all copies.
     44  1.3.2.2  ad  *
     45  1.3.2.2  ad  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     46  1.3.2.2  ad  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     47  1.3.2.2  ad  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     48  1.3.2.2  ad  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     49  1.3.2.2  ad  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     50  1.3.2.2  ad  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     51  1.3.2.2  ad  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     52  1.3.2.2  ad  */
     53  1.3.2.2  ad 
     54  1.3.2.2  ad #include "bpfilter.h"
     55  1.3.2.2  ad #include "rnd.h"
     56  1.3.2.2  ad 
     57  1.3.2.2  ad #include <sys/param.h>
     58  1.3.2.2  ad #include <sys/systm.h>
     59  1.3.2.2  ad #include <sys/sockio.h>
     60  1.3.2.2  ad #include <sys/mbuf.h>
     61  1.3.2.2  ad #include <sys/malloc.h>
     62  1.3.2.2  ad #include <sys/kernel.h>
     63  1.3.2.2  ad #include <sys/socket.h>
     64  1.3.2.2  ad #include <sys/device.h>
     65  1.3.2.2  ad #include <sys/queue.h>
     66  1.3.2.2  ad #include <sys/callout.h>
     67  1.3.2.2  ad #include <sys/sysctl.h>
     68  1.3.2.2  ad #include <sys/endian.h>
     69  1.3.2.2  ad #ifdef __NetBSD__
     70  1.3.2.2  ad  #define letoh16 htole16
     71  1.3.2.2  ad  #define letoh32 htole32
     72  1.3.2.2  ad #endif
     73  1.3.2.2  ad 
     74  1.3.2.2  ad #include <net/if.h>
     75  1.3.2.2  ad #include <net/if_dl.h>
     76  1.3.2.2  ad #include <net/if_types.h>
     77  1.3.2.2  ad 
     78  1.3.2.2  ad #include <net/if_media.h>
     79  1.3.2.2  ad 
     80  1.3.2.2  ad #if NBPFILTER > 0
     81  1.3.2.2  ad #include <net/bpf.h>
     82  1.3.2.2  ad #endif
     83  1.3.2.2  ad #if NRND > 0
     84  1.3.2.2  ad #include <sys/rnd.h>
     85  1.3.2.2  ad #endif
     86  1.3.2.2  ad 
     87  1.3.2.2  ad #include <dev/mii/mii.h>
     88  1.3.2.2  ad #include <dev/mii/miivar.h>
     89  1.3.2.2  ad #include <dev/mii/brgphyreg.h>
     90  1.3.2.2  ad 
     91  1.3.2.2  ad #include <dev/pci/pcireg.h>
     92  1.3.2.2  ad #include <dev/pci/pcivar.h>
     93  1.3.2.2  ad #include <dev/pci/pcidevs.h>
     94  1.3.2.2  ad 
     95  1.3.2.2  ad #include <dev/pci/if_skreg.h>
     96  1.3.2.2  ad #include <dev/pci/if_mskvar.h>
     97  1.3.2.2  ad 
     98  1.3.2.2  ad int mskc_probe(struct device *, struct cfdata *, void *);
     99  1.3.2.2  ad void mskc_attach(struct device *, struct device *self, void *aux);
    100  1.3.2.2  ad void mskc_shutdown(void *);
    101  1.3.2.2  ad int msk_probe(struct device *, struct cfdata *, void *);
    102  1.3.2.2  ad void msk_attach(struct device *, struct device *self, void *aux);
    103  1.3.2.2  ad int mskcprint(void *, const char *);
    104  1.3.2.2  ad int msk_intr(void *);
    105  1.3.2.2  ad void msk_intr_yukon(struct sk_if_softc *);
    106  1.3.2.2  ad __inline int msk_rxvalid(struct sk_softc *, u_int32_t, u_int32_t);
    107  1.3.2.2  ad void msk_rxeof(struct sk_if_softc *, u_int16_t, u_int32_t);
    108  1.3.2.2  ad void msk_txeof(struct sk_if_softc *);
    109  1.3.2.2  ad int msk_encap(struct sk_if_softc *, struct mbuf *, u_int32_t *);
    110  1.3.2.2  ad void msk_start(struct ifnet *);
    111  1.3.2.2  ad int msk_ioctl(struct ifnet *, u_long, caddr_t);
    112  1.3.2.2  ad int msk_init(struct ifnet *);
    113  1.3.2.2  ad void msk_init_yukon(struct sk_if_softc *);
    114  1.3.2.2  ad void msk_stop(struct ifnet *, int);
    115  1.3.2.2  ad void msk_watchdog(struct ifnet *);
    116  1.3.2.2  ad int msk_ifmedia_upd(struct ifnet *);
    117  1.3.2.2  ad void msk_ifmedia_sts(struct ifnet *, struct ifmediareq *);
    118  1.3.2.2  ad void msk_reset(struct sk_softc *);
    119  1.3.2.2  ad int msk_newbuf(struct sk_if_softc *, int, struct mbuf *, bus_dmamap_t);
    120  1.3.2.2  ad int msk_alloc_jumbo_mem(struct sk_if_softc *);
    121  1.3.2.2  ad void *msk_jalloc(struct sk_if_softc *);
    122  1.3.2.2  ad void msk_jfree(struct mbuf *, caddr_t, size_t, void *);
    123  1.3.2.2  ad int msk_init_rx_ring(struct sk_if_softc *);
    124  1.3.2.2  ad int msk_init_tx_ring(struct sk_if_softc *);
    125  1.3.2.2  ad 
    126  1.3.2.2  ad void msk_update_int_mod(struct sk_softc *);
    127  1.3.2.2  ad 
    128  1.3.2.2  ad int msk_marv_miibus_readreg(struct device *, int, int);
    129  1.3.2.2  ad void msk_marv_miibus_writereg(struct device *, int, int, int);
    130  1.3.2.2  ad void msk_marv_miibus_statchg(struct device *);
    131  1.3.2.2  ad 
    132  1.3.2.2  ad u_int32_t msk_yukon_hash(caddr_t);
    133  1.3.2.2  ad void msk_setfilt(struct sk_if_softc *, caddr_t, int);
    134  1.3.2.2  ad void msk_setmulti(struct sk_if_softc *);
    135  1.3.2.2  ad void msk_setpromisc(struct sk_if_softc *);
    136  1.3.2.2  ad void msk_yukon_tick(void *);
    137  1.3.2.2  ad 
    138  1.3.2.2  ad /* #define MSK_DEBUG 1 */
    139  1.3.2.2  ad #ifdef MSK_DEBUG
    140  1.3.2.2  ad #define DPRINTF(x)	if (mskdebug) printf x
    141  1.3.2.2  ad #define DPRINTFN(n,x)	if (mskdebug >= (n)) printf x
    142  1.3.2.2  ad int	mskdebug = MSK_DEBUG;
    143  1.3.2.2  ad 
    144  1.3.2.2  ad void msk_dump_txdesc(struct msk_tx_desc *, int);
    145  1.3.2.2  ad void msk_dump_mbuf(struct mbuf *);
    146  1.3.2.2  ad void msk_dump_bytes(const char *, int);
    147  1.3.2.2  ad #else
    148  1.3.2.2  ad #define DPRINTF(x)
    149  1.3.2.2  ad #define DPRINTFN(n,x)
    150  1.3.2.2  ad #endif
    151  1.3.2.2  ad 
    152  1.3.2.2  ad static int msk_sysctl_handler(SYSCTLFN_PROTO);
    153  1.3.2.2  ad static int msk_root_num;
    154  1.3.2.2  ad 
    155  1.3.2.2  ad /* supported device vendors */
    156  1.3.2.2  ad static const struct msk_product {
    157  1.3.2.2  ad         pci_vendor_id_t         msk_vendor;
    158  1.3.2.2  ad         pci_product_id_t        msk_product;
    159  1.3.2.2  ad } msk_products[] = {
    160  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKON_8035 },
    161  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKON_8036 },
    162  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKON_8038 },
    163  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKON_8052 },
    164  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKON_8050 },
    165  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKON_8053 },
    166  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKONII_8021CU },
    167  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKONII_8022CU },
    168  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKONII_8021X },
    169  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKONII_8022X },
    170  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKONII_8061CU },
    171  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKONII_8062CU },
    172  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKONII_8061X },
    173  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKONII_8062X },
    174  1.3.2.2  ad 	{ PCI_VENDOR_MARVELL,		PCI_PRODUCT_MARVELL_YUKON_3 },
    175  1.3.2.2  ad 	{ PCI_VENDOR_SCHNEIDERKOCH,	PCI_PRODUCT_SCHNEIDERKOCH_SK_9SXX },
    176  1.3.2.2  ad 	{ PCI_VENDOR_SCHNEIDERKOCH,	PCI_PRODUCT_SCHNEIDERKOCH_SK_9E21 }
    177  1.3.2.2  ad };
    178  1.3.2.2  ad 
    179  1.3.2.2  ad static inline u_int32_t
    180  1.3.2.2  ad sk_win_read_4(struct sk_softc *sc, u_int32_t reg)
    181  1.3.2.2  ad {
    182  1.3.2.2  ad 	return CSR_READ_4(sc, reg);
    183  1.3.2.2  ad }
    184  1.3.2.2  ad 
    185  1.3.2.2  ad static inline u_int16_t
    186  1.3.2.2  ad sk_win_read_2(struct sk_softc *sc, u_int32_t reg)
    187  1.3.2.2  ad {
    188  1.3.2.2  ad 	return CSR_READ_2(sc, reg);
    189  1.3.2.2  ad }
    190  1.3.2.2  ad 
    191  1.3.2.2  ad static inline u_int8_t
    192  1.3.2.2  ad sk_win_read_1(struct sk_softc *sc, u_int32_t reg)
    193  1.3.2.2  ad {
    194  1.3.2.2  ad 	return CSR_READ_1(sc, reg);
    195  1.3.2.2  ad }
    196  1.3.2.2  ad 
    197  1.3.2.2  ad static inline void
    198  1.3.2.2  ad sk_win_write_4(struct sk_softc *sc, u_int32_t reg, u_int32_t x)
    199  1.3.2.2  ad {
    200  1.3.2.2  ad 	CSR_WRITE_4(sc, reg, x);
    201  1.3.2.2  ad }
    202  1.3.2.2  ad 
    203  1.3.2.2  ad static inline void
    204  1.3.2.2  ad sk_win_write_2(struct sk_softc *sc, u_int32_t reg, u_int16_t x)
    205  1.3.2.2  ad {
    206  1.3.2.2  ad 	CSR_WRITE_2(sc, reg, x);
    207  1.3.2.2  ad }
    208  1.3.2.2  ad 
    209  1.3.2.2  ad static inline void
    210  1.3.2.2  ad sk_win_write_1(struct sk_softc *sc, u_int32_t reg, u_int8_t x)
    211  1.3.2.2  ad {
    212  1.3.2.2  ad 	CSR_WRITE_1(sc, reg, x);
    213  1.3.2.2  ad }
    214  1.3.2.2  ad 
    215  1.3.2.2  ad int
    216  1.3.2.2  ad msk_marv_miibus_readreg(struct device *dev, int phy, int reg)
    217  1.3.2.2  ad {
    218  1.3.2.2  ad 	struct sk_if_softc *sc_if = (struct sk_if_softc *)dev;
    219  1.3.2.2  ad 	u_int16_t val;
    220  1.3.2.2  ad 	int i;
    221  1.3.2.2  ad 
    222  1.3.2.2  ad 	if (phy != 0 ||
    223  1.3.2.2  ad 	    (sc_if->sk_phytype != SK_PHYTYPE_MARV_COPPER &&
    224  1.3.2.2  ad 	     sc_if->sk_phytype != SK_PHYTYPE_MARV_FIBER)) {
    225  1.3.2.2  ad 		DPRINTFN(9, ("msk_marv_miibus_readreg (skip) phy=%d, reg=%#x\n",
    226  1.3.2.2  ad 			     phy, reg));
    227  1.3.2.2  ad 		return (0);
    228  1.3.2.2  ad 	}
    229  1.3.2.2  ad 
    230  1.3.2.2  ad         SK_YU_WRITE_2(sc_if, YUKON_SMICR, YU_SMICR_PHYAD(phy) |
    231  1.3.2.2  ad 		      YU_SMICR_REGAD(reg) | YU_SMICR_OP_READ);
    232  1.3.2.2  ad 
    233  1.3.2.2  ad 	for (i = 0; i < SK_TIMEOUT; i++) {
    234  1.3.2.2  ad 		DELAY(1);
    235  1.3.2.2  ad 		val = SK_YU_READ_2(sc_if, YUKON_SMICR);
    236  1.3.2.2  ad 		if (val & YU_SMICR_READ_VALID)
    237  1.3.2.2  ad 			break;
    238  1.3.2.2  ad 	}
    239  1.3.2.2  ad 
    240  1.3.2.2  ad 	if (i == SK_TIMEOUT) {
    241  1.3.2.2  ad 		aprint_error("%s: phy failed to come ready\n",
    242  1.3.2.2  ad 		       sc_if->sk_dev.dv_xname);
    243  1.3.2.2  ad 		return (0);
    244  1.3.2.2  ad 	}
    245  1.3.2.2  ad 
    246  1.3.2.2  ad  	DPRINTFN(9, ("msk_marv_miibus_readreg: i=%d, timeout=%d\n", i,
    247  1.3.2.2  ad 		     SK_TIMEOUT));
    248  1.3.2.2  ad 
    249  1.3.2.2  ad         val = SK_YU_READ_2(sc_if, YUKON_SMIDR);
    250  1.3.2.2  ad 
    251  1.3.2.2  ad 	DPRINTFN(9, ("msk_marv_miibus_readreg phy=%d, reg=%#x, val=%#x\n",
    252  1.3.2.2  ad 		     phy, reg, val));
    253  1.3.2.2  ad 
    254  1.3.2.2  ad 	return (val);
    255  1.3.2.2  ad }
    256  1.3.2.2  ad 
    257  1.3.2.2  ad void
    258  1.3.2.2  ad msk_marv_miibus_writereg(struct device *dev, int phy, int reg, int val)
    259  1.3.2.2  ad {
    260  1.3.2.2  ad 	struct sk_if_softc *sc_if = (struct sk_if_softc *)dev;
    261  1.3.2.2  ad 	int i;
    262  1.3.2.2  ad 
    263  1.3.2.2  ad 	DPRINTFN(9, ("msk_marv_miibus_writereg phy=%d reg=%#x val=%#x\n",
    264  1.3.2.2  ad 		     phy, reg, val));
    265  1.3.2.2  ad 
    266  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_SMIDR, val);
    267  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_SMICR, YU_SMICR_PHYAD(phy) |
    268  1.3.2.2  ad 		      YU_SMICR_REGAD(reg) | YU_SMICR_OP_WRITE);
    269  1.3.2.2  ad 
    270  1.3.2.2  ad 	for (i = 0; i < SK_TIMEOUT; i++) {
    271  1.3.2.2  ad 		DELAY(1);
    272  1.3.2.3  ad 		if (!(SK_YU_READ_2(sc_if, YUKON_SMICR) & YU_SMICR_BUSY))
    273  1.3.2.2  ad 			break;
    274  1.3.2.2  ad 	}
    275  1.3.2.2  ad 
    276  1.3.2.2  ad 	if (i == SK_TIMEOUT)
    277  1.3.2.2  ad 		aprint_error("%s: phy write timed out\n", sc_if->sk_dev.dv_xname);
    278  1.3.2.2  ad }
    279  1.3.2.2  ad 
    280  1.3.2.2  ad void
    281  1.3.2.2  ad msk_marv_miibus_statchg(struct device *dev)
    282  1.3.2.2  ad {
    283  1.3.2.2  ad 	DPRINTFN(9, ("msk_marv_miibus_statchg: gpcr=%x\n",
    284  1.3.2.2  ad 		     SK_YU_READ_2(((struct sk_if_softc *)dev), YUKON_GPCR)));
    285  1.3.2.2  ad }
    286  1.3.2.2  ad 
    287  1.3.2.2  ad #define HASH_BITS	6
    288  1.3.2.2  ad 
    289  1.3.2.2  ad u_int32_t
    290  1.3.2.2  ad msk_yukon_hash(caddr_t addr)
    291  1.3.2.2  ad {
    292  1.3.2.2  ad 	u_int32_t crc;
    293  1.3.2.2  ad 
    294  1.3.2.2  ad 	crc = ether_crc32_be(addr, ETHER_ADDR_LEN);
    295  1.3.2.2  ad 	return (crc & ((1 << HASH_BITS) - 1));
    296  1.3.2.2  ad }
    297  1.3.2.2  ad 
    298  1.3.2.2  ad void
    299  1.3.2.2  ad msk_setfilt(struct sk_if_softc *sc_if, caddr_t addr, int slot)
    300  1.3.2.2  ad {
    301  1.3.2.2  ad 	int base = XM_RXFILT_ENTRY(slot);
    302  1.3.2.2  ad 
    303  1.3.2.2  ad 	SK_XM_WRITE_2(sc_if, base, *(u_int16_t *)(&addr[0]));
    304  1.3.2.2  ad 	SK_XM_WRITE_2(sc_if, base + 2, *(u_int16_t *)(&addr[2]));
    305  1.3.2.2  ad 	SK_XM_WRITE_2(sc_if, base + 4, *(u_int16_t *)(&addr[4]));
    306  1.3.2.2  ad }
    307  1.3.2.2  ad 
    308  1.3.2.2  ad void
    309  1.3.2.2  ad msk_setmulti(struct sk_if_softc *sc_if)
    310  1.3.2.2  ad {
    311  1.3.2.2  ad 	struct ifnet *ifp= &sc_if->sk_ethercom.ec_if;
    312  1.3.2.2  ad 	u_int32_t hashes[2] = { 0, 0 };
    313  1.3.2.2  ad 	int h;
    314  1.3.2.2  ad 	struct ethercom *ec = &sc_if->sk_ethercom;
    315  1.3.2.2  ad 	struct ether_multi *enm;
    316  1.3.2.2  ad 	struct ether_multistep step;
    317  1.3.2.2  ad 
    318  1.3.2.2  ad 	/* First, zot all the existing filters. */
    319  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_MCAH1, 0);
    320  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_MCAH2, 0);
    321  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_MCAH3, 0);
    322  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_MCAH4, 0);
    323  1.3.2.2  ad 
    324  1.3.2.2  ad 
    325  1.3.2.2  ad 	/* Now program new ones. */
    326  1.3.2.2  ad allmulti:
    327  1.3.2.2  ad 	if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
    328  1.3.2.2  ad 		hashes[0] = 0xFFFFFFFF;
    329  1.3.2.2  ad 		hashes[1] = 0xFFFFFFFF;
    330  1.3.2.2  ad 	} else {
    331  1.3.2.2  ad 		/* First find the tail of the list. */
    332  1.3.2.2  ad 		ETHER_FIRST_MULTI(step, ec, enm);
    333  1.3.2.2  ad 		while (enm != NULL) {
    334  1.3.2.2  ad 			if (bcmp(enm->enm_addrlo, enm->enm_addrhi,
    335  1.3.2.2  ad 				 ETHER_ADDR_LEN)) {
    336  1.3.2.2  ad 				ifp->if_flags |= IFF_ALLMULTI;
    337  1.3.2.2  ad 				goto allmulti;
    338  1.3.2.2  ad 			}
    339  1.3.2.2  ad 			h = msk_yukon_hash(enm->enm_addrlo);
    340  1.3.2.2  ad 			if (h < 32)
    341  1.3.2.2  ad 				hashes[0] |= (1 << h);
    342  1.3.2.2  ad 			else
    343  1.3.2.2  ad 				hashes[1] |= (1 << (h - 32));
    344  1.3.2.2  ad 
    345  1.3.2.2  ad 			ETHER_NEXT_MULTI(step, enm);
    346  1.3.2.2  ad 		}
    347  1.3.2.2  ad 	}
    348  1.3.2.2  ad 
    349  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_MCAH1, hashes[0] & 0xffff);
    350  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_MCAH2, (hashes[0] >> 16) & 0xffff);
    351  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_MCAH3, hashes[1] & 0xffff);
    352  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_MCAH4, (hashes[1] >> 16) & 0xffff);
    353  1.3.2.2  ad }
    354  1.3.2.2  ad 
    355  1.3.2.2  ad void
    356  1.3.2.2  ad msk_setpromisc(struct sk_if_softc *sc_if)
    357  1.3.2.2  ad {
    358  1.3.2.2  ad 	struct ifnet *ifp = &sc_if->sk_ethercom.ec_if;
    359  1.3.2.2  ad 
    360  1.3.2.2  ad 	if (ifp->if_flags & IFF_PROMISC)
    361  1.3.2.2  ad 		SK_YU_CLRBIT_2(sc_if, YUKON_RCR,
    362  1.3.2.2  ad 		    YU_RCR_UFLEN | YU_RCR_MUFLEN);
    363  1.3.2.2  ad 	else
    364  1.3.2.2  ad 		SK_YU_SETBIT_2(sc_if, YUKON_RCR,
    365  1.3.2.2  ad 		    YU_RCR_UFLEN | YU_RCR_MUFLEN);
    366  1.3.2.2  ad }
    367  1.3.2.2  ad 
    368  1.3.2.2  ad int
    369  1.3.2.2  ad msk_init_rx_ring(struct sk_if_softc *sc_if)
    370  1.3.2.2  ad {
    371  1.3.2.2  ad 	struct msk_chain_data	*cd = &sc_if->sk_cdata;
    372  1.3.2.2  ad 	struct msk_ring_data	*rd = sc_if->sk_rdata;
    373  1.3.2.2  ad 	int			i, nexti;
    374  1.3.2.2  ad 
    375  1.3.2.2  ad 	bzero((char *)rd->sk_rx_ring,
    376  1.3.2.2  ad 	    sizeof(struct msk_rx_desc) * MSK_RX_RING_CNT);
    377  1.3.2.2  ad 
    378  1.3.2.2  ad 	for (i = 0; i < MSK_RX_RING_CNT; i++) {
    379  1.3.2.2  ad 		cd->sk_rx_chain[i].sk_le = &rd->sk_rx_ring[i];
    380  1.3.2.2  ad 		if (i == (MSK_RX_RING_CNT - 1))
    381  1.3.2.2  ad 			nexti = 0;
    382  1.3.2.2  ad 		else
    383  1.3.2.2  ad 			nexti = i + 1;
    384  1.3.2.2  ad 		cd->sk_rx_chain[i].sk_next = &cd->sk_rx_chain[nexti];
    385  1.3.2.2  ad 	}
    386  1.3.2.2  ad 
    387  1.3.2.2  ad 	for (i = 0; i < MSK_RX_RING_CNT; i++) {
    388  1.3.2.2  ad 		if (msk_newbuf(sc_if, i, NULL,
    389  1.3.2.2  ad 		    sc_if->sk_cdata.sk_rx_jumbo_map) == ENOBUFS) {
    390  1.3.2.2  ad 			aprint_error("%s: failed alloc of %dth mbuf\n",
    391  1.3.2.2  ad 			    sc_if->sk_dev.dv_xname, i);
    392  1.3.2.2  ad 			return (ENOBUFS);
    393  1.3.2.2  ad 		}
    394  1.3.2.2  ad 	}
    395  1.3.2.2  ad 
    396  1.3.2.2  ad 	sc_if->sk_cdata.sk_rx_prod = MSK_RX_RING_CNT - 1;
    397  1.3.2.2  ad 	sc_if->sk_cdata.sk_rx_cons = 0;
    398  1.3.2.2  ad 
    399  1.3.2.2  ad 	return (0);
    400  1.3.2.2  ad }
    401  1.3.2.2  ad 
    402  1.3.2.2  ad int
    403  1.3.2.2  ad msk_init_tx_ring(struct sk_if_softc *sc_if)
    404  1.3.2.2  ad {
    405  1.3.2.2  ad 	struct sk_softc		*sc = sc_if->sk_softc;
    406  1.3.2.2  ad 	struct msk_chain_data	*cd = &sc_if->sk_cdata;
    407  1.3.2.2  ad 	struct msk_ring_data	*rd = sc_if->sk_rdata;
    408  1.3.2.2  ad 	bus_dmamap_t		dmamap;
    409  1.3.2.2  ad 	struct sk_txmap_entry	*entry;
    410  1.3.2.2  ad 	int			i, nexti;
    411  1.3.2.2  ad 
    412  1.3.2.2  ad 	bzero((char *)sc_if->sk_rdata->sk_tx_ring,
    413  1.3.2.2  ad 	    sizeof(struct msk_tx_desc) * MSK_TX_RING_CNT);
    414  1.3.2.2  ad 
    415  1.3.2.2  ad 	SIMPLEQ_INIT(&sc_if->sk_txmap_head);
    416  1.3.2.2  ad 	for (i = 0; i < MSK_TX_RING_CNT; i++) {
    417  1.3.2.2  ad 		cd->sk_tx_chain[i].sk_le = &rd->sk_tx_ring[i];
    418  1.3.2.2  ad 		if (i == (MSK_TX_RING_CNT - 1))
    419  1.3.2.2  ad 			nexti = 0;
    420  1.3.2.2  ad 		else
    421  1.3.2.2  ad 			nexti = i + 1;
    422  1.3.2.2  ad 		cd->sk_tx_chain[i].sk_next = &cd->sk_tx_chain[nexti];
    423  1.3.2.2  ad 
    424  1.3.2.2  ad 		if (bus_dmamap_create(sc->sc_dmatag, SK_JLEN, SK_NTXSEG,
    425  1.3.2.2  ad 		   SK_JLEN, 0, BUS_DMA_NOWAIT, &dmamap))
    426  1.3.2.2  ad 			return (ENOBUFS);
    427  1.3.2.2  ad 
    428  1.3.2.2  ad 		entry = malloc(sizeof(*entry), M_DEVBUF, M_NOWAIT);
    429  1.3.2.2  ad 		if (!entry) {
    430  1.3.2.2  ad 			bus_dmamap_destroy(sc->sc_dmatag, dmamap);
    431  1.3.2.2  ad 			return (ENOBUFS);
    432  1.3.2.2  ad 		}
    433  1.3.2.2  ad 		entry->dmamap = dmamap;
    434  1.3.2.2  ad 		SIMPLEQ_INSERT_HEAD(&sc_if->sk_txmap_head, entry, link);
    435  1.3.2.2  ad 	}
    436  1.3.2.2  ad 
    437  1.3.2.2  ad 	sc_if->sk_cdata.sk_tx_prod = 0;
    438  1.3.2.2  ad 	sc_if->sk_cdata.sk_tx_cons = 0;
    439  1.3.2.2  ad 	sc_if->sk_cdata.sk_tx_cnt = 0;
    440  1.3.2.2  ad 
    441  1.3.2.2  ad 	MSK_CDTXSYNC(sc_if, 0, MSK_TX_RING_CNT,
    442  1.3.2.2  ad 	    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
    443  1.3.2.2  ad 
    444  1.3.2.2  ad 	return (0);
    445  1.3.2.2  ad }
    446  1.3.2.2  ad 
    447  1.3.2.2  ad int
    448  1.3.2.2  ad msk_newbuf(struct sk_if_softc *sc_if, int i, struct mbuf *m,
    449  1.3.2.2  ad 	  bus_dmamap_t dmamap)
    450  1.3.2.2  ad {
    451  1.3.2.2  ad 	struct mbuf		*m_new = NULL;
    452  1.3.2.2  ad 	struct sk_chain		*c;
    453  1.3.2.2  ad 	struct msk_rx_desc	*r;
    454  1.3.2.2  ad 
    455  1.3.2.2  ad 	if (m == NULL) {
    456  1.3.2.2  ad 		caddr_t buf = NULL;
    457  1.3.2.2  ad 
    458  1.3.2.2  ad 		MGETHDR(m_new, M_DONTWAIT, MT_DATA);
    459  1.3.2.2  ad 		if (m_new == NULL)
    460  1.3.2.2  ad 			return (ENOBUFS);
    461  1.3.2.2  ad 
    462  1.3.2.2  ad 		/* Allocate the jumbo buffer */
    463  1.3.2.2  ad 		buf = msk_jalloc(sc_if);
    464  1.3.2.2  ad 		if (buf == NULL) {
    465  1.3.2.2  ad 			m_freem(m_new);
    466  1.3.2.2  ad 			DPRINTFN(1, ("%s jumbo allocation failed -- packet "
    467  1.3.2.2  ad 			    "dropped!\n", sc_if->sk_ethercom.ec_if.if_xname));
    468  1.3.2.2  ad 			return (ENOBUFS);
    469  1.3.2.2  ad 		}
    470  1.3.2.2  ad 
    471  1.3.2.2  ad 		/* Attach the buffer to the mbuf */
    472  1.3.2.2  ad 		m_new->m_len = m_new->m_pkthdr.len = SK_JLEN;
    473  1.3.2.2  ad 		MEXTADD(m_new, buf, SK_JLEN, 0, msk_jfree, sc_if);
    474  1.3.2.2  ad 	} else {
    475  1.3.2.2  ad 		/*
    476  1.3.2.2  ad 	 	 * We're re-using a previously allocated mbuf;
    477  1.3.2.2  ad 		 * be sure to re-init pointers and lengths to
    478  1.3.2.2  ad 		 * default values.
    479  1.3.2.2  ad 		 */
    480  1.3.2.2  ad 		m_new = m;
    481  1.3.2.2  ad 		m_new->m_len = m_new->m_pkthdr.len = SK_JLEN;
    482  1.3.2.2  ad 		m_new->m_data = m_new->m_ext.ext_buf;
    483  1.3.2.2  ad 	}
    484  1.3.2.2  ad 	m_adj(m_new, ETHER_ALIGN);
    485  1.3.2.2  ad 
    486  1.3.2.2  ad 	c = &sc_if->sk_cdata.sk_rx_chain[i];
    487  1.3.2.2  ad 	r = c->sk_le;
    488  1.3.2.2  ad 	c->sk_mbuf = m_new;
    489  1.3.2.2  ad 	r->sk_addr = htole32(dmamap->dm_segs[0].ds_addr +
    490  1.3.2.2  ad 	    (((vaddr_t)m_new->m_data
    491  1.3.2.2  ad              - (vaddr_t)sc_if->sk_cdata.sk_jumbo_buf)));
    492  1.3.2.2  ad 	r->sk_len = htole16(SK_JLEN);
    493  1.3.2.2  ad 	r->sk_ctl = 0;
    494  1.3.2.2  ad 	r->sk_opcode = SK_Y2_RXOPC_PACKET | SK_Y2_RXOPC_OWN;
    495  1.3.2.2  ad 
    496  1.3.2.2  ad 	MSK_CDRXSYNC(sc_if, i, BUS_DMASYNC_PREWRITE|BUS_DMASYNC_PREREAD);
    497  1.3.2.2  ad 
    498  1.3.2.2  ad 	return (0);
    499  1.3.2.2  ad }
    500  1.3.2.2  ad 
    501  1.3.2.2  ad /*
    502  1.3.2.2  ad  * Memory management for jumbo frames.
    503  1.3.2.2  ad  */
    504  1.3.2.2  ad 
    505  1.3.2.2  ad int
    506  1.3.2.2  ad msk_alloc_jumbo_mem(struct sk_if_softc *sc_if)
    507  1.3.2.2  ad {
    508  1.3.2.2  ad 	struct sk_softc		*sc = sc_if->sk_softc;
    509  1.3.2.2  ad 	caddr_t			ptr, kva;
    510  1.3.2.2  ad 	bus_dma_segment_t	seg;
    511  1.3.2.2  ad 	int		i, rseg, state, error;
    512  1.3.2.2  ad 	struct sk_jpool_entry   *entry;
    513  1.3.2.2  ad 
    514  1.3.2.2  ad 	state = error = 0;
    515  1.3.2.2  ad 
    516  1.3.2.2  ad 	/* Grab a big chunk o' storage. */
    517  1.3.2.2  ad 	if (bus_dmamem_alloc(sc->sc_dmatag, MSK_JMEM, PAGE_SIZE, 0,
    518  1.3.2.2  ad 			     &seg, 1, &rseg, BUS_DMA_NOWAIT)) {
    519  1.3.2.2  ad 		aprint_error(": can't alloc rx buffers");
    520  1.3.2.2  ad 		return (ENOBUFS);
    521  1.3.2.2  ad 	}
    522  1.3.2.2  ad 
    523  1.3.2.2  ad 	state = 1;
    524  1.3.2.2  ad 	if (bus_dmamem_map(sc->sc_dmatag, &seg, rseg, MSK_JMEM, &kva,
    525  1.3.2.2  ad 			   BUS_DMA_NOWAIT)) {
    526  1.3.2.2  ad 		aprint_error(": can't map dma buffers (%d bytes)", MSK_JMEM);
    527  1.3.2.2  ad 		error = ENOBUFS;
    528  1.3.2.2  ad 		goto out;
    529  1.3.2.2  ad 	}
    530  1.3.2.2  ad 
    531  1.3.2.2  ad 	state = 2;
    532  1.3.2.2  ad 	if (bus_dmamap_create(sc->sc_dmatag, MSK_JMEM, 1, MSK_JMEM, 0,
    533  1.3.2.2  ad 	    BUS_DMA_NOWAIT, &sc_if->sk_cdata.sk_rx_jumbo_map)) {
    534  1.3.2.2  ad 		aprint_error(": can't create dma map");
    535  1.3.2.2  ad 		error = ENOBUFS;
    536  1.3.2.2  ad 		goto out;
    537  1.3.2.2  ad 	}
    538  1.3.2.2  ad 
    539  1.3.2.2  ad 	state = 3;
    540  1.3.2.2  ad 	if (bus_dmamap_load(sc->sc_dmatag, sc_if->sk_cdata.sk_rx_jumbo_map,
    541  1.3.2.2  ad 			    kva, MSK_JMEM, NULL, BUS_DMA_NOWAIT)) {
    542  1.3.2.2  ad 		aprint_error(": can't load dma map");
    543  1.3.2.2  ad 		error = ENOBUFS;
    544  1.3.2.2  ad 		goto out;
    545  1.3.2.2  ad 	}
    546  1.3.2.2  ad 
    547  1.3.2.2  ad 	state = 4;
    548  1.3.2.2  ad 	sc_if->sk_cdata.sk_jumbo_buf = (caddr_t)kva;
    549  1.3.2.2  ad 	DPRINTFN(1,("msk_jumbo_buf = %p\n", (caddr_t)sc_if->sk_cdata.sk_jumbo_buf));
    550  1.3.2.2  ad 
    551  1.3.2.2  ad 	LIST_INIT(&sc_if->sk_jfree_listhead);
    552  1.3.2.2  ad 	LIST_INIT(&sc_if->sk_jinuse_listhead);
    553  1.3.2.2  ad 
    554  1.3.2.2  ad 	/*
    555  1.3.2.2  ad 	 * Now divide it up into 9K pieces and save the addresses
    556  1.3.2.2  ad 	 * in an array.
    557  1.3.2.2  ad 	 */
    558  1.3.2.2  ad 	ptr = sc_if->sk_cdata.sk_jumbo_buf;
    559  1.3.2.2  ad 	for (i = 0; i < MSK_JSLOTS; i++) {
    560  1.3.2.2  ad 		sc_if->sk_cdata.sk_jslots[i] = ptr;
    561  1.3.2.2  ad 		ptr += SK_JLEN;
    562  1.3.2.2  ad 		entry = malloc(sizeof(struct sk_jpool_entry),
    563  1.3.2.2  ad 		    M_DEVBUF, M_NOWAIT);
    564  1.3.2.2  ad 		if (entry == NULL) {
    565  1.3.2.2  ad 			aprint_error(": no memory for jumbo buffer queue!");
    566  1.3.2.2  ad 			error = ENOBUFS;
    567  1.3.2.2  ad 			goto out;
    568  1.3.2.2  ad 		}
    569  1.3.2.2  ad 		entry->slot = i;
    570  1.3.2.2  ad 		if (i)
    571  1.3.2.2  ad 			LIST_INSERT_HEAD(&sc_if->sk_jfree_listhead,
    572  1.3.2.2  ad 				 entry, jpool_entries);
    573  1.3.2.2  ad 		else
    574  1.3.2.2  ad 			LIST_INSERT_HEAD(&sc_if->sk_jinuse_listhead,
    575  1.3.2.2  ad 				 entry, jpool_entries);
    576  1.3.2.2  ad 	}
    577  1.3.2.2  ad out:
    578  1.3.2.2  ad 	if (error != 0) {
    579  1.3.2.2  ad 		switch (state) {
    580  1.3.2.2  ad 		case 4:
    581  1.3.2.2  ad 			bus_dmamap_unload(sc->sc_dmatag,
    582  1.3.2.2  ad 			    sc_if->sk_cdata.sk_rx_jumbo_map);
    583  1.3.2.2  ad 		case 3:
    584  1.3.2.2  ad 			bus_dmamap_destroy(sc->sc_dmatag,
    585  1.3.2.2  ad 			    sc_if->sk_cdata.sk_rx_jumbo_map);
    586  1.3.2.2  ad 		case 2:
    587  1.3.2.2  ad 			bus_dmamem_unmap(sc->sc_dmatag, kva, MSK_JMEM);
    588  1.3.2.2  ad 		case 1:
    589  1.3.2.2  ad 			bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
    590  1.3.2.2  ad 			break;
    591  1.3.2.2  ad 		default:
    592  1.3.2.2  ad 			break;
    593  1.3.2.2  ad 		}
    594  1.3.2.2  ad 	}
    595  1.3.2.2  ad 
    596  1.3.2.2  ad 	return (error);
    597  1.3.2.2  ad }
    598  1.3.2.2  ad 
    599  1.3.2.2  ad /*
    600  1.3.2.2  ad  * Allocate a jumbo buffer.
    601  1.3.2.2  ad  */
    602  1.3.2.2  ad void *
    603  1.3.2.2  ad msk_jalloc(struct sk_if_softc *sc_if)
    604  1.3.2.2  ad {
    605  1.3.2.2  ad 	struct sk_jpool_entry   *entry;
    606  1.3.2.2  ad 
    607  1.3.2.2  ad 	entry = LIST_FIRST(&sc_if->sk_jfree_listhead);
    608  1.3.2.2  ad 
    609  1.3.2.2  ad 	if (entry == NULL)
    610  1.3.2.2  ad 		return (NULL);
    611  1.3.2.2  ad 
    612  1.3.2.2  ad 	LIST_REMOVE(entry, jpool_entries);
    613  1.3.2.2  ad 	LIST_INSERT_HEAD(&sc_if->sk_jinuse_listhead, entry, jpool_entries);
    614  1.3.2.2  ad 	return (sc_if->sk_cdata.sk_jslots[entry->slot]);
    615  1.3.2.2  ad }
    616  1.3.2.2  ad 
    617  1.3.2.2  ad /*
    618  1.3.2.2  ad  * Release a jumbo buffer.
    619  1.3.2.2  ad  */
    620  1.3.2.2  ad void
    621  1.3.2.2  ad msk_jfree(struct mbuf *m, caddr_t buf, size_t size, void *arg)
    622  1.3.2.2  ad {
    623  1.3.2.2  ad 	struct sk_jpool_entry *entry;
    624  1.3.2.2  ad 	struct sk_if_softc *sc;
    625  1.3.2.2  ad 	int i, s;
    626  1.3.2.2  ad 
    627  1.3.2.2  ad 	/* Extract the softc struct pointer. */
    628  1.3.2.2  ad 	sc = (struct sk_if_softc *)arg;
    629  1.3.2.2  ad 
    630  1.3.2.2  ad 	if (sc == NULL)
    631  1.3.2.2  ad 		panic("msk_jfree: can't find softc pointer!");
    632  1.3.2.2  ad 
    633  1.3.2.2  ad 	/* calculate the slot this buffer belongs to */
    634  1.3.2.2  ad 
    635  1.3.2.2  ad 	i = ((vaddr_t)buf
    636  1.3.2.2  ad 	     - (vaddr_t)sc->sk_cdata.sk_jumbo_buf) / SK_JLEN;
    637  1.3.2.2  ad 
    638  1.3.2.2  ad 	if ((i < 0) || (i >= MSK_JSLOTS))
    639  1.3.2.2  ad 		panic("sk_jfree: asked to free buffer that we don't manage!");
    640  1.3.2.2  ad 
    641  1.3.2.2  ad 	s = splvm();
    642  1.3.2.2  ad 	entry = LIST_FIRST(&sc->sk_jinuse_listhead);
    643  1.3.2.2  ad 	if (entry == NULL)
    644  1.3.2.2  ad 		panic("msk_jfree: buffer not in use!");
    645  1.3.2.2  ad 	entry->slot = i;
    646  1.3.2.2  ad 	LIST_REMOVE(entry, jpool_entries);
    647  1.3.2.2  ad 	LIST_INSERT_HEAD(&sc->sk_jfree_listhead, entry, jpool_entries);
    648  1.3.2.2  ad 
    649  1.3.2.2  ad 	if (__predict_true(m != NULL))
    650  1.3.2.2  ad 		pool_cache_put(&mbpool_cache, m);
    651  1.3.2.2  ad 	splx(s);
    652  1.3.2.2  ad }
    653  1.3.2.2  ad 
    654  1.3.2.2  ad /*
    655  1.3.2.2  ad  * Set media options.
    656  1.3.2.2  ad  */
    657  1.3.2.2  ad int
    658  1.3.2.2  ad msk_ifmedia_upd(struct ifnet *ifp)
    659  1.3.2.2  ad {
    660  1.3.2.2  ad 	struct sk_if_softc *sc_if = ifp->if_softc;
    661  1.3.2.2  ad 
    662  1.3.2.2  ad 	msk_init(ifp);
    663  1.3.2.2  ad 	mii_mediachg(&sc_if->sk_mii);
    664  1.3.2.2  ad 	return (0);
    665  1.3.2.2  ad }
    666  1.3.2.2  ad 
    667  1.3.2.2  ad /*
    668  1.3.2.2  ad  * Report current media status.
    669  1.3.2.2  ad  */
    670  1.3.2.2  ad void
    671  1.3.2.2  ad msk_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
    672  1.3.2.2  ad {
    673  1.3.2.2  ad 	struct sk_if_softc *sc_if = ifp->if_softc;
    674  1.3.2.2  ad 
    675  1.3.2.2  ad 	mii_pollstat(&sc_if->sk_mii);
    676  1.3.2.2  ad 	ifmr->ifm_active = sc_if->sk_mii.mii_media_active;
    677  1.3.2.2  ad 	ifmr->ifm_status = sc_if->sk_mii.mii_media_status;
    678  1.3.2.2  ad }
    679  1.3.2.2  ad 
    680  1.3.2.2  ad int
    681  1.3.2.2  ad msk_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
    682  1.3.2.2  ad {
    683  1.3.2.2  ad 	struct sk_if_softc *sc_if = ifp->if_softc;
    684  1.3.2.2  ad 	struct ifreq *ifr = (struct ifreq *) data;
    685  1.3.2.2  ad 	struct mii_data *mii;
    686  1.3.2.2  ad 	int s, error = 0;
    687  1.3.2.2  ad 
    688  1.3.2.2  ad 	s = splnet();
    689  1.3.2.2  ad 
    690  1.3.2.2  ad 	switch(command) {
    691  1.3.2.2  ad 	case SIOCGIFMEDIA:
    692  1.3.2.2  ad 	case SIOCSIFMEDIA:
    693  1.3.2.2  ad 		DPRINTFN(2,("msk_ioctl: SIOC[GS]IFMEDIA\n"));
    694  1.3.2.2  ad 		mii = &sc_if->sk_mii;
    695  1.3.2.2  ad 		error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
    696  1.3.2.2  ad 		DPRINTFN(2,("msk_ioctl: SIOC[GS]IFMEDIA done\n"));
    697  1.3.2.2  ad 		break;
    698  1.3.2.2  ad 	default:
    699  1.3.2.2  ad 		DPRINTFN(2, ("msk_ioctl ETHER\n"));
    700  1.3.2.2  ad 		error = ether_ioctl(ifp, command, data);
    701  1.3.2.2  ad 
    702  1.3.2.2  ad 		if (error == ENETRESET) {
    703  1.3.2.2  ad 			/*
    704  1.3.2.2  ad 			 * Multicast list has changed; set the hardware
    705  1.3.2.2  ad 			 * filter accordingly.
    706  1.3.2.2  ad 			 */
    707  1.3.2.2  ad 			if (ifp->if_flags & IFF_RUNNING)
    708  1.3.2.2  ad 				msk_setmulti(sc_if);
    709  1.3.2.2  ad 			error = 0;
    710  1.3.2.2  ad 		}
    711  1.3.2.2  ad 		break;
    712  1.3.2.2  ad 	}
    713  1.3.2.2  ad 
    714  1.3.2.2  ad 	splx(s);
    715  1.3.2.2  ad 	return (error);
    716  1.3.2.2  ad }
    717  1.3.2.2  ad 
    718  1.3.2.2  ad void
    719  1.3.2.2  ad msk_update_int_mod(struct sk_softc *sc)
    720  1.3.2.2  ad {
    721  1.3.2.2  ad 	u_int32_t sk_imtimer_ticks;
    722  1.3.2.2  ad 
    723  1.3.2.2  ad 	/*
    724  1.3.2.2  ad  	 * Configure interrupt moderation. The moderation timer
    725  1.3.2.2  ad 	 * defers interrupts specified in the interrupt moderation
    726  1.3.2.2  ad 	 * timer mask based on the timeout specified in the interrupt
    727  1.3.2.2  ad 	 * moderation timer init register. Each bit in the timer
    728  1.3.2.2  ad 	 * register represents one tick, so to specify a timeout in
    729  1.3.2.2  ad 	 * microseconds, we have to multiply by the correct number of
    730  1.3.2.2  ad 	 * ticks-per-microsecond.
    731  1.3.2.2  ad 	 */
    732  1.3.2.2  ad 	switch (sc->sk_type) {
    733  1.3.2.2  ad 	case SK_YUKON_EC:
    734  1.3.2.2  ad 		sk_imtimer_ticks = SK_IMTIMER_TICKS_YUKON_EC;
    735  1.3.2.2  ad 		break;
    736  1.3.2.2  ad 	default:
    737  1.3.2.2  ad 		sk_imtimer_ticks = SK_IMTIMER_TICKS_YUKON;
    738  1.3.2.2  ad 	}
    739  1.3.2.2  ad 	aprint_verbose("%s: interrupt moderation is %d us\n",
    740  1.3.2.2  ad 	    sc->sk_dev.dv_xname, sc->sk_int_mod);
    741  1.3.2.2  ad         sk_win_write_4(sc, SK_IMTIMERINIT, SK_IM_USECS(sc->sk_int_mod));
    742  1.3.2.2  ad         sk_win_write_4(sc, SK_IMMR, SK_ISR_TX1_S_EOF|SK_ISR_TX2_S_EOF|
    743  1.3.2.2  ad 	    SK_ISR_RX1_EOF|SK_ISR_RX2_EOF);
    744  1.3.2.2  ad         sk_win_write_1(sc, SK_IMTIMERCTL, SK_IMCTL_START);
    745  1.3.2.2  ad 	sc->sk_int_mod_pending = 0;
    746  1.3.2.2  ad }
    747  1.3.2.2  ad 
    748  1.3.2.2  ad static int
    749  1.3.2.2  ad msk_lookup(const struct pci_attach_args *pa)
    750  1.3.2.2  ad {
    751  1.3.2.2  ad 	const struct msk_product *pmsk;
    752  1.3.2.2  ad 
    753  1.3.2.2  ad 	for ( pmsk = &msk_products[0]; pmsk->msk_vendor != 0; pmsk++) {
    754  1.3.2.2  ad 		if (PCI_VENDOR(pa->pa_id) == pmsk->msk_vendor &&
    755  1.3.2.2  ad 		    PCI_PRODUCT(pa->pa_id) == pmsk->msk_product)
    756  1.3.2.2  ad 			return 1;
    757  1.3.2.2  ad 	}
    758  1.3.2.2  ad 	return 0;
    759  1.3.2.2  ad }
    760  1.3.2.2  ad 
    761  1.3.2.2  ad /*
    762  1.3.2.2  ad  * Probe for a SysKonnect GEnesis chip. Check the PCI vendor and device
    763  1.3.2.2  ad  * IDs against our list and return a device name if we find a match.
    764  1.3.2.2  ad  */
    765  1.3.2.2  ad int
    766  1.3.2.2  ad mskc_probe(struct device *parent, struct cfdata *match,
    767  1.3.2.2  ad     void *aux)
    768  1.3.2.2  ad {
    769  1.3.2.2  ad 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
    770  1.3.2.2  ad 
    771  1.3.2.2  ad 	return msk_lookup(pa);
    772  1.3.2.2  ad }
    773  1.3.2.2  ad 
    774  1.3.2.2  ad /*
    775  1.3.2.2  ad  * Force the GEnesis into reset, then bring it out of reset.
    776  1.3.2.2  ad  */
    777  1.3.2.2  ad void msk_reset(struct sk_softc *sc)
    778  1.3.2.2  ad {
    779  1.3.2.2  ad 	u_int32_t sk_imtimer_ticks;
    780  1.3.2.2  ad 	int reg;
    781  1.3.2.2  ad 
    782  1.3.2.2  ad 	DPRINTFN(2, ("msk_reset\n"));
    783  1.3.2.2  ad 
    784  1.3.2.2  ad 	CSR_WRITE_1(sc, SK_CSR, SK_CSR_SW_RESET);
    785  1.3.2.2  ad 	CSR_WRITE_1(sc, SK_CSR, SK_CSR_MASTER_RESET);
    786  1.3.2.2  ad 	CSR_WRITE_2(sc, SK_LINK_CTRL, SK_LINK_RESET_SET);
    787  1.3.2.2  ad 
    788  1.3.2.2  ad 	DELAY(1000);
    789  1.3.2.2  ad 	CSR_WRITE_1(sc, SK_CSR, SK_CSR_SW_UNRESET);
    790  1.3.2.2  ad 	DELAY(2);
    791  1.3.2.2  ad 	CSR_WRITE_1(sc, SK_CSR, SK_CSR_MASTER_UNRESET);
    792  1.3.2.2  ad 	CSR_WRITE_2(sc, SK_LINK_CTRL, SK_LINK_RESET_CLEAR);
    793  1.3.2.2  ad 
    794  1.3.2.2  ad 	DPRINTFN(2, ("msk_reset: sk_csr=%x\n", CSR_READ_1(sc, SK_CSR)));
    795  1.3.2.2  ad 	DPRINTFN(2, ("msk_reset: sk_link_ctrl=%x\n",
    796  1.3.2.2  ad 		     CSR_READ_2(sc, SK_LINK_CTRL)));
    797  1.3.2.2  ad 
    798  1.3.2.2  ad 	/* Disable ASF */
    799  1.3.2.2  ad 	CSR_WRITE_1(sc, SK_Y2_ASF_CSR, SK_Y2_ASF_RESET);
    800  1.3.2.2  ad 	CSR_WRITE_2(sc, SK_CSR, SK_CSR_ASF_OFF);
    801  1.3.2.2  ad 
    802  1.3.2.2  ad 	/* Clear I2C IRQ noise */
    803  1.3.2.2  ad 	CSR_WRITE_4(sc, SK_I2CHWIRQ, 1);
    804  1.3.2.2  ad 
    805  1.3.2.2  ad 	/* Disable hardware timer */
    806  1.3.2.2  ad 	CSR_WRITE_1(sc, SK_TIMERCTL, SK_IMCTL_STOP);
    807  1.3.2.2  ad 	CSR_WRITE_1(sc, SK_TIMERCTL, SK_IMCTL_IRQ_CLEAR);
    808  1.3.2.2  ad 
    809  1.3.2.2  ad 	/* Disable descriptor polling */
    810  1.3.2.2  ad 	CSR_WRITE_4(sc, SK_DPT_TIMER_CTRL, SK_DPT_TCTL_STOP);
    811  1.3.2.2  ad 
    812  1.3.2.2  ad 	/* Disable time stamps */
    813  1.3.2.2  ad 	CSR_WRITE_1(sc, SK_TSTAMP_CTL, SK_TSTAMP_STOP);
    814  1.3.2.2  ad 	CSR_WRITE_1(sc, SK_TSTAMP_CTL, SK_TSTAMP_IRQ_CLEAR);
    815  1.3.2.2  ad 
    816  1.3.2.2  ad 	/* Enable RAM interface */
    817  1.3.2.2  ad 	sk_win_write_1(sc, SK_RAMCTL, SK_RAMCTL_UNRESET);
    818  1.3.2.2  ad 	for (reg = SK_TO0;reg <= SK_TO11; reg++)
    819  1.3.2.2  ad 		sk_win_write_1(sc, reg, 36);
    820  1.3.2.2  ad 
    821  1.3.2.2  ad 	/*
    822  1.3.2.2  ad 	 * Configure interrupt moderation. The moderation timer
    823  1.3.2.2  ad 	 * defers interrupts specified in the interrupt moderation
    824  1.3.2.2  ad 	 * timer mask based on the timeout specified in the interrupt
    825  1.3.2.2  ad 	 * moderation timer init register. Each bit in the timer
    826  1.3.2.2  ad 	 * register represents one tick, so to specify a timeout in
    827  1.3.2.2  ad 	 * microseconds, we have to multiply by the correct number of
    828  1.3.2.2  ad 	 * ticks-per-microsecond.
    829  1.3.2.2  ad 	 */
    830  1.3.2.2  ad 	switch (sc->sk_type) {
    831  1.3.2.2  ad 	case SK_YUKON_EC:
    832  1.3.2.2  ad 	case SK_YUKON_XL:
    833  1.3.2.2  ad 	case SK_YUKON_FE:
    834  1.3.2.2  ad 		sk_imtimer_ticks = SK_IMTIMER_TICKS_YUKON_EC;
    835  1.3.2.2  ad 		break;
    836  1.3.2.2  ad 	default:
    837  1.3.2.2  ad 		sk_imtimer_ticks = SK_IMTIMER_TICKS_YUKON;
    838  1.3.2.2  ad 	}
    839  1.3.2.2  ad 
    840  1.3.2.2  ad 	/* Reset status ring. */
    841  1.3.2.2  ad 	bzero((char *)sc->sk_status_ring,
    842  1.3.2.2  ad 	    MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc));
    843  1.3.2.2  ad 	sc->sk_status_idx = 0;
    844  1.3.2.2  ad 
    845  1.3.2.2  ad 	sk_win_write_4(sc, SK_STAT_BMU_CSR, SK_STAT_BMU_RESET);
    846  1.3.2.2  ad 	sk_win_write_4(sc, SK_STAT_BMU_CSR, SK_STAT_BMU_UNRESET);
    847  1.3.2.2  ad 
    848  1.3.2.2  ad 	sk_win_write_2(sc, SK_STAT_BMU_LIDX, MSK_STATUS_RING_CNT - 1);
    849  1.3.2.2  ad 	sk_win_write_4(sc, SK_STAT_BMU_ADDRLO,
    850  1.3.2.2  ad 	    sc->sk_status_map->dm_segs[0].ds_addr);
    851  1.3.2.2  ad 	sk_win_write_4(sc, SK_STAT_BMU_ADDRHI,
    852  1.3.2.2  ad 	    (u_int64_t)sc->sk_status_map->dm_segs[0].ds_addr >> 32);
    853  1.3.2.2  ad 	sk_win_write_2(sc, SK_STAT_BMU_TX_THRESH, 10);
    854  1.3.2.2  ad 	sk_win_write_1(sc, SK_STAT_BMU_FIFOWM, 16);
    855  1.3.2.2  ad 	sk_win_write_1(sc, SK_STAT_BMU_FIFOIWM, 16);
    856  1.3.2.2  ad 
    857  1.3.2.2  ad #if 0
    858  1.3.2.2  ad 	sk_win_write_4(sc, SK_Y2_LEV_ITIMERINIT, SK_IM_USECS(100));
    859  1.3.2.2  ad 	sk_win_write_4(sc, SK_Y2_TX_ITIMERINIT, SK_IM_USECS(1000));
    860  1.3.2.2  ad 
    861  1.3.2.2  ad 	sk_win_write_4(sc, SK_Y2_ISR_ITIMERINIT, SK_IM_USECS(20));
    862  1.3.2.2  ad #else
    863  1.3.2.2  ad 	sk_win_write_4(sc, SK_Y2_ISR_ITIMERINIT, SK_IM_USECS(4));
    864  1.3.2.2  ad #endif
    865  1.3.2.2  ad 
    866  1.3.2.2  ad 	sk_win_write_4(sc, SK_STAT_BMU_CSR, SK_STAT_BMU_ON);
    867  1.3.2.2  ad 
    868  1.3.2.2  ad 	sk_win_write_1(sc, SK_Y2_LEV_ITIMERCTL, SK_IMCTL_START);
    869  1.3.2.2  ad 	sk_win_write_1(sc, SK_Y2_TX_ITIMERCTL, SK_IMCTL_START);
    870  1.3.2.2  ad 	sk_win_write_1(sc, SK_Y2_ISR_ITIMERCTL, SK_IMCTL_START);
    871  1.3.2.2  ad 
    872  1.3.2.2  ad 	msk_update_int_mod(sc);
    873  1.3.2.2  ad }
    874  1.3.2.2  ad 
    875  1.3.2.2  ad int
    876  1.3.2.2  ad msk_probe(struct device *parent, struct cfdata *match,
    877  1.3.2.2  ad     void *aux)
    878  1.3.2.2  ad {
    879  1.3.2.2  ad 	struct skc_attach_args *sa = aux;
    880  1.3.2.2  ad 
    881  1.3.2.2  ad 	if (sa->skc_port != SK_PORT_A && sa->skc_port != SK_PORT_B)
    882  1.3.2.2  ad 		return (0);
    883  1.3.2.2  ad 
    884  1.3.2.2  ad 	switch (sa->skc_type) {
    885  1.3.2.2  ad 	case SK_YUKON_XL:
    886  1.3.2.2  ad 	case SK_YUKON_EC_U:
    887  1.3.2.2  ad 	case SK_YUKON_EC:
    888  1.3.2.2  ad 	case SK_YUKON_FE:
    889  1.3.2.2  ad 		return (1);
    890  1.3.2.2  ad 	}
    891  1.3.2.2  ad 
    892  1.3.2.2  ad 	return (0);
    893  1.3.2.2  ad }
    894  1.3.2.2  ad 
    895  1.3.2.2  ad /*
    896  1.3.2.2  ad  * Each XMAC chip is attached as a separate logical IP interface.
    897  1.3.2.2  ad  * Single port cards will have only one logical interface of course.
    898  1.3.2.2  ad  */
    899  1.3.2.2  ad void
    900  1.3.2.2  ad msk_attach(struct device *parent, struct device *self, void *aux)
    901  1.3.2.2  ad {
    902  1.3.2.2  ad 	struct sk_if_softc *sc_if = (struct sk_if_softc *) self;
    903  1.3.2.2  ad 	struct sk_softc *sc = (struct sk_softc *)parent;
    904  1.3.2.2  ad 	struct skc_attach_args *sa = aux;
    905  1.3.2.2  ad 	struct ifnet *ifp;
    906  1.3.2.2  ad 	caddr_t kva;
    907  1.3.2.2  ad 	bus_dma_segment_t seg;
    908  1.3.2.2  ad 	int i, rseg;
    909  1.3.2.2  ad 	u_int32_t chunk, val;
    910  1.3.2.2  ad 
    911  1.3.2.2  ad 	sc_if->sk_port = sa->skc_port;
    912  1.3.2.2  ad 	sc_if->sk_softc = sc;
    913  1.3.2.2  ad 	sc->sk_if[sa->skc_port] = sc_if;
    914  1.3.2.2  ad 
    915  1.3.2.2  ad 	DPRINTFN(2, ("begin msk_attach: port=%d\n", sc_if->sk_port));
    916  1.3.2.2  ad 
    917  1.3.2.2  ad 	/*
    918  1.3.2.2  ad 	 * Get station address for this interface. Note that
    919  1.3.2.2  ad 	 * dual port cards actually come with three station
    920  1.3.2.2  ad 	 * addresses: one for each port, plus an extra. The
    921  1.3.2.2  ad 	 * extra one is used by the SysKonnect driver software
    922  1.3.2.2  ad 	 * as a 'virtual' station address for when both ports
    923  1.3.2.2  ad 	 * are operating in failover mode. Currently we don't
    924  1.3.2.2  ad 	 * use this extra address.
    925  1.3.2.2  ad 	 */
    926  1.3.2.2  ad 	for (i = 0; i < ETHER_ADDR_LEN; i++)
    927  1.3.2.2  ad 		sc_if->sk_enaddr[i] =
    928  1.3.2.2  ad 		    sk_win_read_1(sc, SK_MAC0_0 + (sa->skc_port * 8) + i);
    929  1.3.2.2  ad 
    930  1.3.2.2  ad 	aprint_normal(": Ethernet address %s\n",
    931  1.3.2.2  ad 	    ether_sprintf(sc_if->sk_enaddr));
    932  1.3.2.2  ad 
    933  1.3.2.2  ad 	/*
    934  1.3.2.2  ad 	 * Set up RAM buffer addresses. The NIC will have a certain
    935  1.3.2.2  ad 	 * amount of SRAM on it, somewhere between 512K and 2MB. We
    936  1.3.2.2  ad 	 * need to divide this up a) between the transmitter and
    937  1.3.2.2  ad  	 * receiver and b) between the two XMACs, if this is a
    938  1.3.2.2  ad 	 * dual port NIC. Our algorithm is to divide up the memory
    939  1.3.2.2  ad 	 * evenly so that everyone gets a fair share.
    940  1.3.2.2  ad 	 *
    941  1.3.2.2  ad 	 * Just to be contrary, Yukon2 appears to have separate memory
    942  1.3.2.2  ad 	 * for each MAC.
    943  1.3.2.2  ad 	 */
    944  1.3.2.2  ad 	chunk = sc->sk_ramsize  - (sc->sk_ramsize + 2) / 3;
    945  1.3.2.2  ad 	val = sc->sk_rboff / sizeof(u_int64_t);
    946  1.3.2.2  ad 	sc_if->sk_rx_ramstart = val;
    947  1.3.2.2  ad 	val += (chunk / sizeof(u_int64_t));
    948  1.3.2.2  ad 	sc_if->sk_rx_ramend = val - 1;
    949  1.3.2.2  ad 	chunk = sc->sk_ramsize - chunk;
    950  1.3.2.2  ad 	sc_if->sk_tx_ramstart = val;
    951  1.3.2.2  ad 	val += (chunk / sizeof(u_int64_t));
    952  1.3.2.2  ad 	sc_if->sk_tx_ramend = val - 1;
    953  1.3.2.2  ad 
    954  1.3.2.2  ad 	DPRINTFN(2, ("msk_attach: rx_ramstart=%#x rx_ramend=%#x\n"
    955  1.3.2.2  ad 		     "           tx_ramstart=%#x tx_ramend=%#x\n",
    956  1.3.2.2  ad 		     sc_if->sk_rx_ramstart, sc_if->sk_rx_ramend,
    957  1.3.2.2  ad 		     sc_if->sk_tx_ramstart, sc_if->sk_tx_ramend));
    958  1.3.2.2  ad 
    959  1.3.2.2  ad 	/* Read and save PHY type */
    960  1.3.2.2  ad 	sc_if->sk_phytype = sk_win_read_1(sc, SK_EPROM1) & 0xF;
    961  1.3.2.2  ad 
    962  1.3.2.2  ad 	/* Set PHY address */
    963  1.3.2.2  ad 	if ((sc_if->sk_phytype < SK_PHYTYPE_MARV_COPPER &&
    964  1.3.2.2  ad 	     sc->sk_pmd != 'L' && sc->sk_pmd != 'S')) {
    965  1.3.2.2  ad 		/* not initialized, punt */
    966  1.3.2.2  ad 		sc_if->sk_phytype = SK_PHYTYPE_MARV_COPPER;
    967  1.3.2.2  ad 
    968  1.3.2.2  ad 		sc->sk_coppertype = 1;
    969  1.3.2.2  ad 	}
    970  1.3.2.2  ad 
    971  1.3.2.2  ad 	sc_if->sk_phyaddr = SK_PHYADDR_MARV;
    972  1.3.2.2  ad 
    973  1.3.2.2  ad 	if (!(sc->sk_coppertype))
    974  1.3.2.2  ad 		sc_if->sk_phytype = SK_PHYTYPE_MARV_FIBER;
    975  1.3.2.2  ad 
    976  1.3.2.2  ad 	/* Allocate the descriptor queues. */
    977  1.3.2.2  ad 	if (bus_dmamem_alloc(sc->sc_dmatag, sizeof(struct msk_ring_data),
    978  1.3.2.2  ad 	    PAGE_SIZE, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT)) {
    979  1.3.2.2  ad 		aprint_error(": can't alloc rx buffers\n");
    980  1.3.2.2  ad 		goto fail;
    981  1.3.2.2  ad 	}
    982  1.3.2.2  ad 	if (bus_dmamem_map(sc->sc_dmatag, &seg, rseg,
    983  1.3.2.2  ad 	    sizeof(struct msk_ring_data), &kva, BUS_DMA_NOWAIT)) {
    984  1.3.2.2  ad 		aprint_error(": can't map dma buffers (%zu bytes)\n",
    985  1.3.2.2  ad 		       sizeof(struct msk_ring_data));
    986  1.3.2.2  ad 		goto fail_1;
    987  1.3.2.2  ad 	}
    988  1.3.2.2  ad 	if (bus_dmamap_create(sc->sc_dmatag, sizeof(struct msk_ring_data), 1,
    989  1.3.2.2  ad 	    sizeof(struct msk_ring_data), 0, BUS_DMA_NOWAIT,
    990  1.3.2.2  ad             &sc_if->sk_ring_map)) {
    991  1.3.2.2  ad 		aprint_error(": can't create dma map\n");
    992  1.3.2.2  ad 		goto fail_2;
    993  1.3.2.2  ad 	}
    994  1.3.2.2  ad 	if (bus_dmamap_load(sc->sc_dmatag, sc_if->sk_ring_map, kva,
    995  1.3.2.2  ad 	    sizeof(struct msk_ring_data), NULL, BUS_DMA_NOWAIT)) {
    996  1.3.2.2  ad 		aprint_error(": can't load dma map\n");
    997  1.3.2.2  ad 		goto fail_3;
    998  1.3.2.2  ad 	}
    999  1.3.2.2  ad         sc_if->sk_rdata = (struct msk_ring_data *)kva;
   1000  1.3.2.2  ad 	bzero(sc_if->sk_rdata, sizeof(struct msk_ring_data));
   1001  1.3.2.2  ad 
   1002  1.3.2.2  ad 	ifp = &sc_if->sk_ethercom.ec_if;
   1003  1.3.2.2  ad 	/* Try to allocate memory for jumbo buffers. */
   1004  1.3.2.2  ad 	if (msk_alloc_jumbo_mem(sc_if)) {
   1005  1.3.2.2  ad 		aprint_error(": jumbo buffer allocation failed\n");
   1006  1.3.2.2  ad 		goto fail_3;
   1007  1.3.2.2  ad 	}
   1008  1.3.2.2  ad 	sc_if->sk_ethercom.ec_capabilities = ETHERCAP_VLAN_MTU
   1009  1.3.2.2  ad 		| ETHERCAP_JUMBO_MTU;
   1010  1.3.2.2  ad 
   1011  1.3.2.2  ad 	ifp->if_softc = sc_if;
   1012  1.3.2.2  ad 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
   1013  1.3.2.2  ad 	ifp->if_ioctl = msk_ioctl;
   1014  1.3.2.2  ad 	ifp->if_start = msk_start;
   1015  1.3.2.2  ad 	ifp->if_stop = msk_stop;
   1016  1.3.2.2  ad 	ifp->if_init = msk_init;
   1017  1.3.2.2  ad 	ifp->if_watchdog = msk_watchdog;
   1018  1.3.2.2  ad 	ifp->if_baudrate = 1000000000;
   1019  1.3.2.2  ad 	IFQ_SET_MAXLEN(&ifp->if_snd, MSK_TX_RING_CNT - 1);
   1020  1.3.2.2  ad 	IFQ_SET_READY(&ifp->if_snd);
   1021  1.3.2.2  ad 	strcpy(ifp->if_xname, sc_if->sk_dev.dv_xname);
   1022  1.3.2.2  ad 
   1023  1.3.2.2  ad 	/*
   1024  1.3.2.2  ad 	 * Do miibus setup.
   1025  1.3.2.2  ad 	 */
   1026  1.3.2.2  ad 	msk_init_yukon(sc_if);
   1027  1.3.2.2  ad 
   1028  1.3.2.2  ad  	DPRINTFN(2, ("msk_attach: 1\n"));
   1029  1.3.2.2  ad 
   1030  1.3.2.2  ad 	sc_if->sk_mii.mii_ifp = ifp;
   1031  1.3.2.2  ad 	sc_if->sk_mii.mii_readreg = msk_marv_miibus_readreg;
   1032  1.3.2.2  ad 	sc_if->sk_mii.mii_writereg = msk_marv_miibus_writereg;
   1033  1.3.2.2  ad 	sc_if->sk_mii.mii_statchg = msk_marv_miibus_statchg;
   1034  1.3.2.2  ad 
   1035  1.3.2.2  ad 	ifmedia_init(&sc_if->sk_mii.mii_media, 0,
   1036  1.3.2.2  ad 	    msk_ifmedia_upd, msk_ifmedia_sts);
   1037  1.3.2.2  ad 	mii_attach(self, &sc_if->sk_mii, 0xffffffff, MII_PHY_ANY,
   1038  1.3.2.2  ad 	    MII_OFFSET_ANY, 0);
   1039  1.3.2.2  ad 	if (LIST_FIRST(&sc_if->sk_mii.mii_phys) == NULL) {
   1040  1.3.2.2  ad 		aprint_error("%s: no PHY found!\n", sc_if->sk_dev.dv_xname);
   1041  1.3.2.2  ad 		ifmedia_add(&sc_if->sk_mii.mii_media, IFM_ETHER|IFM_MANUAL,
   1042  1.3.2.2  ad 			    0, NULL);
   1043  1.3.2.2  ad 		ifmedia_set(&sc_if->sk_mii.mii_media, IFM_ETHER|IFM_MANUAL);
   1044  1.3.2.2  ad 	} else
   1045  1.3.2.2  ad 		ifmedia_set(&sc_if->sk_mii.mii_media, IFM_ETHER|IFM_AUTO);
   1046  1.3.2.2  ad 
   1047  1.3.2.2  ad 	callout_init(&sc_if->sk_tick_ch);
   1048  1.3.2.2  ad 	callout_setfunc(&sc_if->sk_tick_ch, msk_yukon_tick, sc_if);
   1049  1.3.2.2  ad 	callout_schedule(&sc_if->sk_tick_ch, hz);
   1050  1.3.2.2  ad 
   1051  1.3.2.2  ad 	/*
   1052  1.3.2.2  ad 	 * Call MI attach routines.
   1053  1.3.2.2  ad 	 */
   1054  1.3.2.2  ad 	if_attach(ifp);
   1055  1.3.2.2  ad 	ether_ifattach(ifp, sc_if->sk_enaddr);
   1056  1.3.2.2  ad 
   1057  1.3.2.2  ad 	shutdownhook_establish(mskc_shutdown, sc);
   1058  1.3.2.2  ad 
   1059  1.3.2.2  ad #if NRND > 0
   1060  1.3.2.2  ad 	rnd_attach_source(&sc->rnd_source, sc->sk_dev.dv_xname,
   1061  1.3.2.2  ad 		RND_TYPE_NET, 0);
   1062  1.3.2.2  ad #endif
   1063  1.3.2.2  ad 
   1064  1.3.2.2  ad 	DPRINTFN(2, ("msk_attach: end\n"));
   1065  1.3.2.2  ad 	return;
   1066  1.3.2.2  ad 
   1067  1.3.2.2  ad fail_3:
   1068  1.3.2.2  ad 	bus_dmamap_destroy(sc->sc_dmatag, sc_if->sk_ring_map);
   1069  1.3.2.2  ad fail_2:
   1070  1.3.2.2  ad 	bus_dmamem_unmap(sc->sc_dmatag, kva, sizeof(struct msk_ring_data));
   1071  1.3.2.2  ad fail_1:
   1072  1.3.2.2  ad 	bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
   1073  1.3.2.2  ad fail:
   1074  1.3.2.2  ad 	sc->sk_if[sa->skc_port] = NULL;
   1075  1.3.2.2  ad }
   1076  1.3.2.2  ad 
   1077  1.3.2.2  ad int
   1078  1.3.2.2  ad mskcprint(void *aux, const char *pnp)
   1079  1.3.2.2  ad {
   1080  1.3.2.2  ad 	struct skc_attach_args *sa = aux;
   1081  1.3.2.2  ad 
   1082  1.3.2.2  ad 	if (pnp)
   1083  1.3.2.2  ad 		aprint_normal("sk port %c at %s",
   1084  1.3.2.2  ad 		    (sa->skc_port == SK_PORT_A) ? 'A' : 'B', pnp);
   1085  1.3.2.2  ad 	else
   1086  1.3.2.2  ad 		aprint_normal(" port %c", (sa->skc_port == SK_PORT_A) ? 'A' : 'B');
   1087  1.3.2.2  ad 	return (UNCONF);
   1088  1.3.2.2  ad }
   1089  1.3.2.2  ad 
   1090  1.3.2.2  ad /*
   1091  1.3.2.2  ad  * Attach the interface. Allocate softc structures, do ifmedia
   1092  1.3.2.2  ad  * setup and ethernet/BPF attach.
   1093  1.3.2.2  ad  */
   1094  1.3.2.2  ad void
   1095  1.3.2.2  ad mskc_attach(struct device *parent, struct device *self, void *aux)
   1096  1.3.2.2  ad {
   1097  1.3.2.2  ad 	struct sk_softc *sc = (struct sk_softc *)self;
   1098  1.3.2.2  ad 	struct pci_attach_args *pa = aux;
   1099  1.3.2.2  ad 	struct skc_attach_args skca;
   1100  1.3.2.2  ad 	pci_chipset_tag_t pc = pa->pa_pc;
   1101  1.3.2.2  ad 	pcireg_t command, memtype;
   1102  1.3.2.2  ad 	pci_intr_handle_t ih;
   1103  1.3.2.2  ad 	const char *intrstr = NULL;
   1104  1.3.2.2  ad 	bus_size_t size;
   1105  1.3.2.2  ad 	int rc, sk_nodenum;
   1106  1.3.2.2  ad 	u_int8_t hw, skrs;
   1107  1.3.2.2  ad 	const char *revstr = NULL;
   1108  1.3.2.2  ad 	const struct sysctlnode *node;
   1109  1.3.2.2  ad 	caddr_t kva;
   1110  1.3.2.2  ad 	bus_dma_segment_t seg;
   1111  1.3.2.2  ad 	int rseg;
   1112  1.3.2.2  ad 
   1113  1.3.2.2  ad 	DPRINTFN(2, ("begin mskc_attach\n"));
   1114  1.3.2.2  ad 
   1115  1.3.2.2  ad 	/*
   1116  1.3.2.2  ad 	 * Handle power management nonsense.
   1117  1.3.2.2  ad 	 */
   1118  1.3.2.2  ad 	command = pci_conf_read(pc, pa->pa_tag, SK_PCI_CAPID) & 0x000000FF;
   1119  1.3.2.2  ad 
   1120  1.3.2.2  ad 	if (command == 0x01) {
   1121  1.3.2.2  ad 		command = pci_conf_read(pc, pa->pa_tag, SK_PCI_PWRMGMTCTRL);
   1122  1.3.2.2  ad 		if (command & SK_PSTATE_MASK) {
   1123  1.3.2.2  ad 			u_int32_t		iobase, membase, irq;
   1124  1.3.2.2  ad 
   1125  1.3.2.2  ad 			/* Save important PCI config data. */
   1126  1.3.2.2  ad 			iobase = pci_conf_read(pc, pa->pa_tag, SK_PCI_LOIO);
   1127  1.3.2.2  ad 			membase = pci_conf_read(pc, pa->pa_tag, SK_PCI_LOMEM);
   1128  1.3.2.2  ad 			irq = pci_conf_read(pc, pa->pa_tag, SK_PCI_INTLINE);
   1129  1.3.2.2  ad 
   1130  1.3.2.2  ad 			/* Reset the power state. */
   1131  1.3.2.2  ad 			aprint_normal("%s chip is in D%d power mode "
   1132  1.3.2.2  ad 			    "-- setting to D0\n", sc->sk_dev.dv_xname,
   1133  1.3.2.2  ad 			    command & SK_PSTATE_MASK);
   1134  1.3.2.2  ad 			command &= 0xFFFFFFFC;
   1135  1.3.2.2  ad 			pci_conf_write(pc, pa->pa_tag,
   1136  1.3.2.2  ad 			    SK_PCI_PWRMGMTCTRL, command);
   1137  1.3.2.2  ad 
   1138  1.3.2.2  ad 			/* Restore PCI config data. */
   1139  1.3.2.2  ad 			pci_conf_write(pc, pa->pa_tag, SK_PCI_LOIO, iobase);
   1140  1.3.2.2  ad 			pci_conf_write(pc, pa->pa_tag, SK_PCI_LOMEM, membase);
   1141  1.3.2.2  ad 			pci_conf_write(pc, pa->pa_tag, SK_PCI_INTLINE, irq);
   1142  1.3.2.2  ad 		}
   1143  1.3.2.2  ad 	}
   1144  1.3.2.2  ad 
   1145  1.3.2.2  ad 	/*
   1146  1.3.2.2  ad 	 * Map control/status registers.
   1147  1.3.2.2  ad 	 */
   1148  1.3.2.2  ad 
   1149  1.3.2.2  ad 	memtype = pci_mapreg_type(pc, pa->pa_tag, SK_PCI_LOMEM);
   1150  1.3.2.2  ad 	switch (memtype) {
   1151  1.3.2.2  ad 	case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT:
   1152  1.3.2.2  ad 	case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT:
   1153  1.3.2.2  ad 		if (pci_mapreg_map(pa, SK_PCI_LOMEM,
   1154  1.3.2.2  ad 				   memtype, 0, &sc->sk_btag, &sc->sk_bhandle,
   1155  1.3.2.2  ad 				   NULL, &size) == 0)
   1156  1.3.2.2  ad 			break;
   1157  1.3.2.2  ad 	default:
   1158  1.3.2.2  ad 		aprint_error(": can't map mem space\n");
   1159  1.3.2.2  ad 		return;
   1160  1.3.2.2  ad 	}
   1161  1.3.2.2  ad 
   1162  1.3.2.2  ad 	sc->sc_dmatag = pa->pa_dmat;
   1163  1.3.2.2  ad 
   1164  1.3.2.2  ad 	sc->sk_type = sk_win_read_1(sc, SK_CHIPVER);
   1165  1.3.2.2  ad 	sc->sk_rev = (sk_win_read_1(sc, SK_CONFIG) >> 4);
   1166  1.3.2.2  ad 
   1167  1.3.2.2  ad 	/* bail out here if chip is not recognized */
   1168  1.3.2.2  ad 	if (!(SK_IS_YUKON(sc))) {
   1169  1.3.2.2  ad 		aprint_error(": unknown chip type: %d\n", sc->sk_type);
   1170  1.3.2.2  ad 		goto fail_1;
   1171  1.3.2.2  ad 	}
   1172  1.3.2.2  ad 	DPRINTFN(2, ("mskc_attach: allocate interrupt\n"));
   1173  1.3.2.2  ad 
   1174  1.3.2.2  ad 	/* Allocate interrupt */
   1175  1.3.2.2  ad 	if (pci_intr_map(pa, &ih)) {
   1176  1.3.2.2  ad 		aprint_error(": couldn't map interrupt\n");
   1177  1.3.2.2  ad 		goto fail_1;
   1178  1.3.2.2  ad 	}
   1179  1.3.2.2  ad 
   1180  1.3.2.2  ad 	intrstr = pci_intr_string(pc, ih);
   1181  1.3.2.2  ad 	sc->sk_intrhand = pci_intr_establish(pc, ih, IPL_NET, msk_intr, sc);
   1182  1.3.2.2  ad 	if (sc->sk_intrhand == NULL) {
   1183  1.3.2.2  ad 		aprint_error(": couldn't establish interrupt");
   1184  1.3.2.2  ad 		if (intrstr != NULL)
   1185  1.3.2.2  ad 			aprint_error(" at %s", intrstr);
   1186  1.3.2.2  ad 		aprint_error("\n");
   1187  1.3.2.2  ad 		goto fail_1;
   1188  1.3.2.2  ad 	}
   1189  1.3.2.2  ad 
   1190  1.3.2.2  ad 	if (bus_dmamem_alloc(sc->sc_dmatag,
   1191  1.3.2.2  ad 	    MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc),
   1192  1.3.2.2  ad 	    PAGE_SIZE, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT)) {
   1193  1.3.2.2  ad 		aprint_error(": can't alloc status buffers\n");
   1194  1.3.2.2  ad 		goto fail_2;
   1195  1.3.2.2  ad 	}
   1196  1.3.2.2  ad 
   1197  1.3.2.2  ad 	if (bus_dmamem_map(sc->sc_dmatag, &seg, rseg,
   1198  1.3.2.2  ad 	    MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc),
   1199  1.3.2.2  ad 	    &kva, BUS_DMA_NOWAIT)) {
   1200  1.3.2.2  ad 		aprint_error(": can't map dma buffers (%zu bytes)\n",
   1201  1.3.2.2  ad 		    MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc));
   1202  1.3.2.2  ad 		goto fail_3;
   1203  1.3.2.2  ad 	}
   1204  1.3.2.2  ad 	if (bus_dmamap_create(sc->sc_dmatag,
   1205  1.3.2.2  ad 	    MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc), 1,
   1206  1.3.2.2  ad 	    MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc), 0,
   1207  1.3.2.2  ad 	    BUS_DMA_NOWAIT, &sc->sk_status_map)) {
   1208  1.3.2.2  ad 		aprint_error(": can't create dma map\n");
   1209  1.3.2.2  ad 		goto fail_4;
   1210  1.3.2.2  ad 	}
   1211  1.3.2.2  ad 	if (bus_dmamap_load(sc->sc_dmatag, sc->sk_status_map, kva,
   1212  1.3.2.2  ad 	    MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc),
   1213  1.3.2.2  ad 	    NULL, BUS_DMA_NOWAIT)) {
   1214  1.3.2.2  ad 		aprint_error(": can't load dma map\n");
   1215  1.3.2.2  ad 		goto fail_5;
   1216  1.3.2.2  ad 	}
   1217  1.3.2.2  ad 	sc->sk_status_ring = (struct msk_status_desc *)kva;
   1218  1.3.2.2  ad 	bzero(sc->sk_status_ring,
   1219  1.3.2.2  ad 	    MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc));
   1220  1.3.2.2  ad 
   1221  1.3.2.2  ad 	/* Reset the adapter. */
   1222  1.3.2.2  ad 	msk_reset(sc);
   1223  1.3.2.2  ad 
   1224  1.3.2.2  ad 	skrs = sk_win_read_1(sc, SK_EPROM0);
   1225  1.3.2.2  ad 	if (skrs == 0x00)
   1226  1.3.2.2  ad 		sc->sk_ramsize = 0x20000;
   1227  1.3.2.2  ad 	else
   1228  1.3.2.2  ad 		sc->sk_ramsize = skrs * (1<<12);
   1229  1.3.2.2  ad 	sc->sk_rboff = SK_RBOFF_0;
   1230  1.3.2.2  ad 
   1231  1.3.2.2  ad 	DPRINTFN(2, ("mskc_attach: ramsize=%d (%dk), rboff=%d\n",
   1232  1.3.2.2  ad 		     sc->sk_ramsize, sc->sk_ramsize / 1024,
   1233  1.3.2.2  ad 		     sc->sk_rboff));
   1234  1.3.2.2  ad 
   1235  1.3.2.2  ad 	/* Read and save physical media type */
   1236  1.3.2.2  ad 	sc->sk_pmd = sk_win_read_1(sc, SK_PMDTYPE);
   1237  1.3.2.2  ad 
   1238  1.3.2.2  ad 	if (sc->sk_pmd == 'T' || sc->sk_pmd == '1' ||
   1239  1.3.2.2  ad 	    (SK_IS_YUKON2(sc) && !(sc->sk_pmd == 'L' ||
   1240  1.3.2.2  ad 	    sc->sk_pmd == 'S')))
   1241  1.3.2.2  ad 		sc->sk_coppertype = 1;
   1242  1.3.2.2  ad 	else
   1243  1.3.2.2  ad 		sc->sk_coppertype = 0;
   1244  1.3.2.2  ad 
   1245  1.3.2.2  ad 	switch (sc->sk_type) {
   1246  1.3.2.2  ad 	case SK_YUKON_XL:
   1247  1.3.2.2  ad 		sc->sk_name = "Marvell Yukon-2 XL";
   1248  1.3.2.2  ad 		break;
   1249  1.3.2.2  ad 	case SK_YUKON_EC_U:
   1250  1.3.2.2  ad 		sc->sk_name = "Marvell Yukon-2 EC Ultra";
   1251  1.3.2.2  ad 		break;
   1252  1.3.2.2  ad 	case SK_YUKON_EC:
   1253  1.3.2.2  ad 		sc->sk_name = "Marvell Yukon-2 EC";
   1254  1.3.2.2  ad 		break;
   1255  1.3.2.2  ad 	case SK_YUKON_FE:
   1256  1.3.2.2  ad 		sc->sk_name = "Marvell Yukon-2 FE";
   1257  1.3.2.2  ad 		break;
   1258  1.3.2.2  ad 	default:
   1259  1.3.2.2  ad 		sc->sk_name = "Marvell Yukon (Unknown)";
   1260  1.3.2.2  ad 	}
   1261  1.3.2.2  ad 
   1262  1.3.2.2  ad 	if (sc->sk_type == SK_YUKON_XL) {
   1263  1.3.2.2  ad 		switch (sc->sk_rev) {
   1264  1.3.2.2  ad 		case SK_YUKON_XL_REV_A0:
   1265  1.3.2.2  ad 			revstr = "A0";
   1266  1.3.2.2  ad 			break;
   1267  1.3.2.2  ad 		case SK_YUKON_XL_REV_A1:
   1268  1.3.2.2  ad 			revstr = "A1";
   1269  1.3.2.2  ad 			break;
   1270  1.3.2.2  ad 		case SK_YUKON_XL_REV_A2:
   1271  1.3.2.2  ad 			revstr = "A2";
   1272  1.3.2.2  ad 			break;
   1273  1.3.2.2  ad 		case SK_YUKON_XL_REV_A3:
   1274  1.3.2.2  ad 			revstr = "A3";
   1275  1.3.2.2  ad 			break;
   1276  1.3.2.2  ad 		default:
   1277  1.3.2.2  ad 			;
   1278  1.3.2.2  ad 		}
   1279  1.3.2.2  ad 	}
   1280  1.3.2.2  ad 
   1281  1.3.2.2  ad 	if (sc->sk_type == SK_YUKON_EC) {
   1282  1.3.2.2  ad 		switch (sc->sk_rev) {
   1283  1.3.2.2  ad 		case SK_YUKON_EC_REV_A1:
   1284  1.3.2.2  ad 			revstr = "A1";
   1285  1.3.2.2  ad 			break;
   1286  1.3.2.2  ad 		case SK_YUKON_EC_REV_A2:
   1287  1.3.2.2  ad 			revstr = "A2";
   1288  1.3.2.2  ad 			break;
   1289  1.3.2.2  ad 		case SK_YUKON_EC_REV_A3:
   1290  1.3.2.2  ad 			revstr = "A3";
   1291  1.3.2.2  ad 			break;
   1292  1.3.2.2  ad 		default:
   1293  1.3.2.2  ad 			;
   1294  1.3.2.2  ad 		}
   1295  1.3.2.2  ad 	}
   1296  1.3.2.2  ad 
   1297  1.3.2.2  ad 	if (sc->sk_type == SK_YUKON_EC_U) {
   1298  1.3.2.2  ad 		switch (sc->sk_rev) {
   1299  1.3.2.2  ad 		case SK_YUKON_EC_U_REV_A0:
   1300  1.3.2.2  ad 			revstr = "A0";
   1301  1.3.2.2  ad 			break;
   1302  1.3.2.2  ad 		case SK_YUKON_EC_U_REV_A1:
   1303  1.3.2.2  ad 			revstr = "A1";
   1304  1.3.2.2  ad 			break;
   1305  1.3.2.2  ad 		default:
   1306  1.3.2.2  ad 			;
   1307  1.3.2.2  ad 		}
   1308  1.3.2.2  ad 	}
   1309  1.3.2.2  ad 
   1310  1.3.2.2  ad 	/* Announce the product name. */
   1311  1.3.2.2  ad 	aprint_normal(", %s", sc->sk_name);
   1312  1.3.2.2  ad 	if (revstr != NULL)
   1313  1.3.2.2  ad 		aprint_normal(" rev. %s", revstr);
   1314  1.3.2.2  ad 	aprint_normal(" (0x%x): %s\n", sc->sk_rev, intrstr);
   1315  1.3.2.2  ad 
   1316  1.3.2.2  ad 
   1317  1.3.2.2  ad 	sc->sk_macs = 1;
   1318  1.3.2.2  ad 
   1319  1.3.2.2  ad 	hw = sk_win_read_1(sc, SK_Y2_HWRES);
   1320  1.3.2.2  ad 	if ((hw & SK_Y2_HWRES_LINK_MASK) == SK_Y2_HWRES_LINK_DUAL) {
   1321  1.3.2.2  ad 		if ((sk_win_read_1(sc, SK_Y2_CLKGATE) &
   1322  1.3.2.2  ad 		    SK_Y2_CLKGATE_LINK2_INACTIVE) == 0)
   1323  1.3.2.2  ad 			sc->sk_macs++;
   1324  1.3.2.2  ad 	}
   1325  1.3.2.2  ad 
   1326  1.3.2.2  ad 	skca.skc_port = SK_PORT_A;
   1327  1.3.2.2  ad 	skca.skc_type = sc->sk_type;
   1328  1.3.2.2  ad 	skca.skc_rev = sc->sk_rev;
   1329  1.3.2.2  ad 	(void)config_found(&sc->sk_dev, &skca, mskcprint);
   1330  1.3.2.2  ad 
   1331  1.3.2.2  ad 	if (sc->sk_macs > 1) {
   1332  1.3.2.2  ad 		skca.skc_port = SK_PORT_B;
   1333  1.3.2.2  ad 		skca.skc_type = sc->sk_type;
   1334  1.3.2.2  ad 		skca.skc_rev = sc->sk_rev;
   1335  1.3.2.2  ad 		(void)config_found(&sc->sk_dev, &skca, mskcprint);
   1336  1.3.2.2  ad 	}
   1337  1.3.2.2  ad 
   1338  1.3.2.2  ad 	/* Turn on the 'driver is loaded' LED. */
   1339  1.3.2.2  ad 	CSR_WRITE_2(sc, SK_LED, SK_LED_GREEN_ON);
   1340  1.3.2.2  ad 
   1341  1.3.2.2  ad 	/* skc sysctl setup */
   1342  1.3.2.2  ad 
   1343  1.3.2.2  ad 	sc->sk_int_mod = SK_IM_DEFAULT;
   1344  1.3.2.2  ad 	sc->sk_int_mod_pending = 0;
   1345  1.3.2.2  ad 
   1346  1.3.2.2  ad 	if ((rc = sysctl_createv(&sc->sk_clog, 0, NULL, &node,
   1347  1.3.2.2  ad 	    0, CTLTYPE_NODE, sc->sk_dev.dv_xname,
   1348  1.3.2.2  ad 	    SYSCTL_DESCR("mskc per-controller controls"),
   1349  1.3.2.2  ad 	    NULL, 0, NULL, 0, CTL_HW, msk_root_num, CTL_CREATE,
   1350  1.3.2.2  ad 	    CTL_EOL)) != 0) {
   1351  1.3.2.2  ad 		aprint_normal("%s: couldn't create sysctl node\n",
   1352  1.3.2.2  ad 		    sc->sk_dev.dv_xname);
   1353  1.3.2.2  ad 		goto fail_6;
   1354  1.3.2.2  ad 	}
   1355  1.3.2.2  ad 
   1356  1.3.2.2  ad 	sk_nodenum = node->sysctl_num;
   1357  1.3.2.2  ad 
   1358  1.3.2.2  ad 	/* interrupt moderation time in usecs */
   1359  1.3.2.2  ad 	if ((rc = sysctl_createv(&sc->sk_clog, 0, NULL, &node,
   1360  1.3.2.2  ad 	    CTLFLAG_READWRITE,
   1361  1.3.2.2  ad 	    CTLTYPE_INT, "int_mod",
   1362  1.3.2.2  ad 	    SYSCTL_DESCR("msk interrupt moderation timer"),
   1363  1.3.2.2  ad 	    msk_sysctl_handler, 0, sc,
   1364  1.3.2.2  ad 	    0, CTL_HW, msk_root_num, sk_nodenum, CTL_CREATE,
   1365  1.3.2.2  ad 	    CTL_EOL)) != 0) {
   1366  1.3.2.2  ad 		aprint_normal("%s: couldn't create int_mod sysctl node\n",
   1367  1.3.2.2  ad 		    sc->sk_dev.dv_xname);
   1368  1.3.2.2  ad 		goto fail_6;
   1369  1.3.2.2  ad 	}
   1370  1.3.2.2  ad 
   1371  1.3.2.2  ad 	return;
   1372  1.3.2.2  ad 
   1373  1.3.2.2  ad  fail_6:
   1374  1.3.2.2  ad 	bus_dmamap_unload(sc->sc_dmatag, sc->sk_status_map);
   1375  1.3.2.2  ad fail_5:
   1376  1.3.2.2  ad 	bus_dmamap_destroy(sc->sc_dmatag, sc->sk_status_map);
   1377  1.3.2.2  ad fail_4:
   1378  1.3.2.2  ad 	bus_dmamem_unmap(sc->sc_dmatag, kva,
   1379  1.3.2.2  ad 	    MSK_STATUS_RING_CNT * sizeof(struct msk_status_desc));
   1380  1.3.2.2  ad fail_3:
   1381  1.3.2.2  ad 	bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
   1382  1.3.2.2  ad fail_2:
   1383  1.3.2.2  ad 	pci_intr_disestablish(pc, sc->sk_intrhand);
   1384  1.3.2.2  ad fail_1:
   1385  1.3.2.2  ad 	bus_space_unmap(sc->sk_btag, sc->sk_bhandle, size);
   1386  1.3.2.2  ad }
   1387  1.3.2.2  ad 
   1388  1.3.2.2  ad int
   1389  1.3.2.2  ad msk_encap(struct sk_if_softc *sc_if, struct mbuf *m_head, u_int32_t *txidx)
   1390  1.3.2.2  ad {
   1391  1.3.2.2  ad 	struct sk_softc		*sc = sc_if->sk_softc;
   1392  1.3.2.2  ad 	struct msk_tx_desc		*f = NULL;
   1393  1.3.2.2  ad 	u_int32_t		frag, cur, cnt = 0;
   1394  1.3.2.2  ad 	int			i;
   1395  1.3.2.2  ad 	struct sk_txmap_entry	*entry;
   1396  1.3.2.2  ad 	bus_dmamap_t		txmap;
   1397  1.3.2.2  ad 
   1398  1.3.2.2  ad 	DPRINTFN(2, ("msk_encap\n"));
   1399  1.3.2.2  ad 
   1400  1.3.2.2  ad 	entry = SIMPLEQ_FIRST(&sc_if->sk_txmap_head);
   1401  1.3.2.2  ad 	if (entry == NULL) {
   1402  1.3.2.2  ad 		DPRINTFN(2, ("msk_encap: no txmap available\n"));
   1403  1.3.2.2  ad 		return (ENOBUFS);
   1404  1.3.2.2  ad 	}
   1405  1.3.2.2  ad 	txmap = entry->dmamap;
   1406  1.3.2.2  ad 
   1407  1.3.2.2  ad 	cur = frag = *txidx;
   1408  1.3.2.2  ad 
   1409  1.3.2.2  ad #ifdef MSK_DEBUG
   1410  1.3.2.2  ad 	if (mskdebug >= 2)
   1411  1.3.2.2  ad 		msk_dump_mbuf(m_head);
   1412  1.3.2.2  ad #endif
   1413  1.3.2.2  ad 
   1414  1.3.2.2  ad 	/*
   1415  1.3.2.2  ad 	 * Start packing the mbufs in this chain into
   1416  1.3.2.2  ad 	 * the fragment pointers. Stop when we run out
   1417  1.3.2.2  ad 	 * of fragments or hit the end of the mbuf chain.
   1418  1.3.2.2  ad 	 */
   1419  1.3.2.2  ad 	if (bus_dmamap_load_mbuf(sc->sc_dmatag, txmap, m_head,
   1420  1.3.2.2  ad 	    BUS_DMA_NOWAIT)) {
   1421  1.3.2.2  ad 		DPRINTFN(2, ("msk_encap: dmamap failed\n"));
   1422  1.3.2.2  ad 		return (ENOBUFS);
   1423  1.3.2.2  ad 	}
   1424  1.3.2.2  ad 
   1425  1.3.2.2  ad 	DPRINTFN(2, ("msk_encap: dm_nsegs=%d\n", txmap->dm_nsegs));
   1426  1.3.2.2  ad 
   1427  1.3.2.2  ad 	/* Sync the DMA map. */
   1428  1.3.2.2  ad 	bus_dmamap_sync(sc->sc_dmatag, txmap, 0, txmap->dm_mapsize,
   1429  1.3.2.2  ad 	    BUS_DMASYNC_PREWRITE);
   1430  1.3.2.2  ad 
   1431  1.3.2.2  ad 	for (i = 0; i < txmap->dm_nsegs; i++) {
   1432  1.3.2.2  ad 		if ((MSK_TX_RING_CNT - (sc_if->sk_cdata.sk_tx_cnt + cnt)) < 2) {
   1433  1.3.2.2  ad 			DPRINTFN(2, ("msk_encap: too few descriptors free\n"));
   1434  1.3.2.2  ad 			return (ENOBUFS);
   1435  1.3.2.2  ad 		}
   1436  1.3.2.2  ad 		f = &sc_if->sk_rdata->sk_tx_ring[frag];
   1437  1.3.2.2  ad 		f->sk_addr = htole32(txmap->dm_segs[i].ds_addr);
   1438  1.3.2.2  ad 		f->sk_len = htole16(txmap->dm_segs[i].ds_len);
   1439  1.3.2.2  ad 		f->sk_ctl = 0;
   1440  1.3.2.2  ad 		if (cnt == 0)
   1441  1.3.2.2  ad 			f->sk_opcode = SK_Y2_TXOPC_PACKET;
   1442  1.3.2.2  ad 		else
   1443  1.3.2.2  ad 			f->sk_opcode = SK_Y2_TXOPC_BUFFER | SK_Y2_TXOPC_OWN;
   1444  1.3.2.2  ad 		cur = frag;
   1445  1.3.2.2  ad 		SK_INC(frag, MSK_TX_RING_CNT);
   1446  1.3.2.2  ad 		cnt++;
   1447  1.3.2.2  ad 	}
   1448  1.3.2.2  ad 
   1449  1.3.2.2  ad 	sc_if->sk_cdata.sk_tx_chain[cur].sk_mbuf = m_head;
   1450  1.3.2.2  ad 	SIMPLEQ_REMOVE_HEAD(&sc_if->sk_txmap_head, link);
   1451  1.3.2.2  ad 
   1452  1.3.2.2  ad 	sc_if->sk_cdata.sk_tx_map[cur] = entry;
   1453  1.3.2.2  ad 	sc_if->sk_rdata->sk_tx_ring[cur].sk_ctl |= SK_Y2_TXCTL_LASTFRAG;
   1454  1.3.2.2  ad 
   1455  1.3.2.2  ad 	/* Sync descriptors before handing to chip */
   1456  1.3.2.2  ad 	MSK_CDTXSYNC(sc_if, *txidx, txmap->dm_nsegs,
   1457  1.3.2.2  ad             BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   1458  1.3.2.2  ad 
   1459  1.3.2.2  ad 	sc_if->sk_rdata->sk_tx_ring[*txidx].sk_opcode |= SK_Y2_TXOPC_OWN;
   1460  1.3.2.2  ad 
   1461  1.3.2.2  ad 	/* Sync first descriptor to hand it off */
   1462  1.3.2.2  ad 	MSK_CDTXSYNC(sc_if, *txidx, 1,
   1463  1.3.2.2  ad 	    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   1464  1.3.2.2  ad 
   1465  1.3.2.2  ad 	sc_if->sk_cdata.sk_tx_cnt += cnt;
   1466  1.3.2.2  ad 
   1467  1.3.2.2  ad #ifdef MSK_DEBUG
   1468  1.3.2.2  ad 	if (mskdebug >= 2) {
   1469  1.3.2.2  ad 		struct msk_tx_desc *le;
   1470  1.3.2.2  ad 		u_int32_t idx;
   1471  1.3.2.2  ad 		for (idx = *txidx; idx != frag; SK_INC(idx, MSK_TX_RING_CNT)) {
   1472  1.3.2.2  ad 			le = &sc_if->sk_rdata->sk_tx_ring[idx];
   1473  1.3.2.2  ad 			msk_dump_txdesc(le, idx);
   1474  1.3.2.2  ad 		}
   1475  1.3.2.2  ad 	}
   1476  1.3.2.2  ad #endif
   1477  1.3.2.2  ad 
   1478  1.3.2.2  ad 	*txidx = frag;
   1479  1.3.2.2  ad 
   1480  1.3.2.2  ad 	DPRINTFN(2, ("msk_encap: completed successfully\n"));
   1481  1.3.2.2  ad 
   1482  1.3.2.2  ad 	return (0);
   1483  1.3.2.2  ad }
   1484  1.3.2.2  ad 
   1485  1.3.2.2  ad void
   1486  1.3.2.2  ad msk_start(struct ifnet *ifp)
   1487  1.3.2.2  ad {
   1488  1.3.2.2  ad         struct sk_if_softc	*sc_if = ifp->if_softc;
   1489  1.3.2.2  ad         struct mbuf		*m_head = NULL;
   1490  1.3.2.2  ad         u_int32_t		idx = sc_if->sk_cdata.sk_tx_prod;
   1491  1.3.2.2  ad 	int			pkts = 0;
   1492  1.3.2.2  ad 
   1493  1.3.2.2  ad 	DPRINTFN(2, ("msk_start\n"));
   1494  1.3.2.2  ad 
   1495  1.3.2.2  ad 	while (sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf == NULL) {
   1496  1.3.2.2  ad 		IFQ_POLL(&ifp->if_snd, m_head);
   1497  1.3.2.2  ad 		if (m_head == NULL)
   1498  1.3.2.2  ad 			break;
   1499  1.3.2.2  ad 
   1500  1.3.2.2  ad 		/*
   1501  1.3.2.2  ad 		 * Pack the data into the transmit ring. If we
   1502  1.3.2.2  ad 		 * don't have room, set the OACTIVE flag and wait
   1503  1.3.2.2  ad 		 * for the NIC to drain the ring.
   1504  1.3.2.2  ad 		 */
   1505  1.3.2.2  ad 		if (msk_encap(sc_if, m_head, &idx)) {
   1506  1.3.2.2  ad 			ifp->if_flags |= IFF_OACTIVE;
   1507  1.3.2.2  ad 			break;
   1508  1.3.2.2  ad 		}
   1509  1.3.2.2  ad 
   1510  1.3.2.2  ad 		/* now we are committed to transmit the packet */
   1511  1.3.2.2  ad 		IFQ_DEQUEUE(&ifp->if_snd, m_head);
   1512  1.3.2.2  ad 		pkts++;
   1513  1.3.2.2  ad 
   1514  1.3.2.2  ad 		/*
   1515  1.3.2.2  ad 		 * If there's a BPF listener, bounce a copy of this frame
   1516  1.3.2.2  ad 		 * to him.
   1517  1.3.2.2  ad 		 */
   1518  1.3.2.2  ad #if NBPFILTER > 0
   1519  1.3.2.2  ad 		if (ifp->if_bpf)
   1520  1.3.2.2  ad 			bpf_mtap(ifp->if_bpf, m_head);
   1521  1.3.2.2  ad #endif
   1522  1.3.2.2  ad 	}
   1523  1.3.2.2  ad 	if (pkts == 0)
   1524  1.3.2.2  ad 		return;
   1525  1.3.2.2  ad 
   1526  1.3.2.2  ad 	/* Transmit */
   1527  1.3.2.2  ad 	if (idx != sc_if->sk_cdata.sk_tx_prod) {
   1528  1.3.2.2  ad 		sc_if->sk_cdata.sk_tx_prod = idx;
   1529  1.3.2.2  ad 		SK_IF_WRITE_2(sc_if, 1, SK_TXQA1_Y2_PREF_PUTIDX, idx);
   1530  1.3.2.2  ad 
   1531  1.3.2.2  ad 		/* Set a timeout in case the chip goes out to lunch. */
   1532  1.3.2.2  ad 		ifp->if_timer = 5;
   1533  1.3.2.2  ad 	}
   1534  1.3.2.2  ad }
   1535  1.3.2.2  ad 
   1536  1.3.2.2  ad void
   1537  1.3.2.2  ad msk_watchdog(struct ifnet *ifp)
   1538  1.3.2.2  ad {
   1539  1.3.2.2  ad 	struct sk_if_softc *sc_if = ifp->if_softc;
   1540  1.3.2.2  ad 
   1541  1.3.2.2  ad 	/*
   1542  1.3.2.2  ad 	 * Reclaim first as there is a possibility of losing Tx completion
   1543  1.3.2.2  ad 	 * interrupts.
   1544  1.3.2.2  ad 	 */
   1545  1.3.2.2  ad 	msk_txeof(sc_if);
   1546  1.3.2.2  ad 	if (sc_if->sk_cdata.sk_tx_cnt != 0) {
   1547  1.3.2.2  ad 		aprint_error("%s: watchdog timeout\n", sc_if->sk_dev.dv_xname);
   1548  1.3.2.2  ad 
   1549  1.3.2.2  ad 		ifp->if_oerrors++;
   1550  1.3.2.2  ad 
   1551  1.3.2.2  ad 		/* XXX Resets both ports; we shouldn't do that. */
   1552  1.3.2.2  ad 		msk_reset(sc_if->sk_softc);
   1553  1.3.2.2  ad 		msk_init(ifp);
   1554  1.3.2.2  ad 	}
   1555  1.3.2.2  ad }
   1556  1.3.2.2  ad 
   1557  1.3.2.2  ad void
   1558  1.3.2.2  ad mskc_shutdown(void *v)
   1559  1.3.2.2  ad {
   1560  1.3.2.2  ad 	struct sk_softc		*sc = v;
   1561  1.3.2.2  ad 
   1562  1.3.2.2  ad 	DPRINTFN(2, ("msk_shutdown\n"));
   1563  1.3.2.2  ad 
   1564  1.3.2.2  ad 	/* Turn off the 'driver is loaded' LED. */
   1565  1.3.2.2  ad 	CSR_WRITE_2(sc, SK_LED, SK_LED_GREEN_OFF);
   1566  1.3.2.2  ad 
   1567  1.3.2.2  ad 	msk_reset(sc);
   1568  1.3.2.2  ad }
   1569  1.3.2.2  ad 
   1570  1.3.2.2  ad __inline int
   1571  1.3.2.2  ad msk_rxvalid(struct sk_softc *sc, u_int32_t stat, u_int32_t len)
   1572  1.3.2.2  ad {
   1573  1.3.2.2  ad 	if ((stat & (YU_RXSTAT_CRCERR | YU_RXSTAT_LONGERR |
   1574  1.3.2.2  ad 	    YU_RXSTAT_MIIERR | YU_RXSTAT_BADFC | YU_RXSTAT_GOODFC |
   1575  1.3.2.2  ad 	    YU_RXSTAT_JABBER)) != 0 ||
   1576  1.3.2.2  ad 	    (stat & YU_RXSTAT_RXOK) != YU_RXSTAT_RXOK ||
   1577  1.3.2.2  ad 	    YU_RXSTAT_BYTES(stat) != len)
   1578  1.3.2.2  ad 		return (0);
   1579  1.3.2.2  ad 
   1580  1.3.2.2  ad 	return (1);
   1581  1.3.2.2  ad }
   1582  1.3.2.2  ad 
   1583  1.3.2.2  ad void
   1584  1.3.2.2  ad msk_rxeof(struct sk_if_softc *sc_if, u_int16_t len, u_int32_t rxstat)
   1585  1.3.2.2  ad {
   1586  1.3.2.2  ad 	struct sk_softc		*sc = sc_if->sk_softc;
   1587  1.3.2.2  ad 	struct ifnet		*ifp = &sc_if->sk_ethercom.ec_if;
   1588  1.3.2.2  ad 	struct mbuf		*m;
   1589  1.3.2.2  ad 	struct sk_chain		*cur_rx;
   1590  1.3.2.2  ad 	int			cur, total_len = len;
   1591  1.3.2.2  ad 	bus_dmamap_t		dmamap;
   1592  1.3.2.2  ad 
   1593  1.3.2.2  ad 	DPRINTFN(2, ("msk_rxeof\n"));
   1594  1.3.2.2  ad 
   1595  1.3.2.2  ad 	cur = sc_if->sk_cdata.sk_rx_cons;
   1596  1.3.2.2  ad 	SK_INC(sc_if->sk_cdata.sk_rx_cons, MSK_RX_RING_CNT);
   1597  1.3.2.2  ad 	SK_INC(sc_if->sk_cdata.sk_rx_prod, MSK_RX_RING_CNT);
   1598  1.3.2.2  ad 
   1599  1.3.2.2  ad 	/* Sync the descriptor */
   1600  1.3.2.2  ad 	MSK_CDRXSYNC(sc_if, cur, BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
   1601  1.3.2.2  ad 
   1602  1.3.2.2  ad 	cur_rx = &sc_if->sk_cdata.sk_rx_chain[cur];
   1603  1.3.2.2  ad 	dmamap = sc_if->sk_cdata.sk_rx_jumbo_map;
   1604  1.3.2.2  ad 
   1605  1.3.2.2  ad 	bus_dmamap_sync(sc_if->sk_softc->sc_dmatag, dmamap, 0,
   1606  1.3.2.2  ad 	    dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD);
   1607  1.3.2.2  ad 
   1608  1.3.2.2  ad 	m = cur_rx->sk_mbuf;
   1609  1.3.2.2  ad 	cur_rx->sk_mbuf = NULL;
   1610  1.3.2.2  ad 
   1611  1.3.2.2  ad 	if (total_len < SK_MIN_FRAMELEN ||
   1612  1.3.2.2  ad 	    total_len > SK_JUMBO_FRAMELEN ||
   1613  1.3.2.2  ad 	    msk_rxvalid(sc, rxstat, total_len) == 0) {
   1614  1.3.2.2  ad 		ifp->if_ierrors++;
   1615  1.3.2.2  ad 		msk_newbuf(sc_if, cur, m, dmamap);
   1616  1.3.2.2  ad 		return;
   1617  1.3.2.2  ad 	}
   1618  1.3.2.2  ad 
   1619  1.3.2.2  ad 	/*
   1620  1.3.2.2  ad 	 * Try to allocate a new jumbo buffer. If that fails, copy the
   1621  1.3.2.2  ad 	 * packet to mbufs and put the jumbo buffer back in the ring
   1622  1.3.2.2  ad 	 * so it can be re-used. If allocating mbufs fails, then we
   1623  1.3.2.2  ad 	 * have to drop the packet.
   1624  1.3.2.2  ad 	 */
   1625  1.3.2.2  ad 	if (msk_newbuf(sc_if, cur, NULL, dmamap) == ENOBUFS) {
   1626  1.3.2.2  ad 		struct mbuf		*m0;
   1627  1.3.2.2  ad 		m0 = m_devget(mtod(m, char *) - ETHER_ALIGN,
   1628  1.3.2.2  ad 		    total_len + ETHER_ALIGN, 0, ifp, NULL);
   1629  1.3.2.2  ad 		msk_newbuf(sc_if, cur, m, dmamap);
   1630  1.3.2.2  ad 		if (m0 == NULL) {
   1631  1.3.2.2  ad 			ifp->if_ierrors++;
   1632  1.3.2.2  ad 			return;
   1633  1.3.2.2  ad 		}
   1634  1.3.2.2  ad 		m_adj(m0, ETHER_ALIGN);
   1635  1.3.2.2  ad 		m = m0;
   1636  1.3.2.2  ad 	} else {
   1637  1.3.2.2  ad 		m->m_pkthdr.rcvif = ifp;
   1638  1.3.2.2  ad 		m->m_pkthdr.len = m->m_len = total_len;
   1639  1.3.2.2  ad 	}
   1640  1.3.2.2  ad 
   1641  1.3.2.2  ad 	ifp->if_ipackets++;
   1642  1.3.2.2  ad 
   1643  1.3.2.2  ad #if NBPFILTER > 0
   1644  1.3.2.2  ad 	if (ifp->if_bpf)
   1645  1.3.2.2  ad 		bpf_mtap(ifp->if_bpf, m);
   1646  1.3.2.2  ad #endif
   1647  1.3.2.2  ad 
   1648  1.3.2.2  ad 	/* pass it on. */
   1649  1.3.2.2  ad 	(*ifp->if_input)(ifp, m);
   1650  1.3.2.2  ad }
   1651  1.3.2.2  ad 
   1652  1.3.2.2  ad void
   1653  1.3.2.2  ad msk_txeof(struct sk_if_softc *sc_if)
   1654  1.3.2.2  ad {
   1655  1.3.2.2  ad 	struct sk_softc		*sc = sc_if->sk_softc;
   1656  1.3.2.2  ad 	struct msk_tx_desc	*cur_tx;
   1657  1.3.2.2  ad 	struct ifnet		*ifp = &sc_if->sk_ethercom.ec_if;
   1658  1.3.2.2  ad 	u_int32_t		idx, sk_ctl;
   1659  1.3.2.2  ad 	struct sk_txmap_entry	*entry;
   1660  1.3.2.2  ad 
   1661  1.3.2.2  ad 	DPRINTFN(2, ("msk_txeof\n"));
   1662  1.3.2.2  ad 
   1663  1.3.2.2  ad 	/*
   1664  1.3.2.2  ad 	 * Go through our tx ring and free mbufs for those
   1665  1.3.2.2  ad 	 * frames that have been sent.
   1666  1.3.2.2  ad 	 */
   1667  1.3.2.2  ad 	idx = sc_if->sk_cdata.sk_tx_cons;
   1668  1.3.2.2  ad 	while (idx != sk_win_read_2(sc, SK_STAT_BMU_TXA1_RIDX)) {
   1669  1.3.2.2  ad 		MSK_CDTXSYNC(sc_if, idx, 1,
   1670  1.3.2.2  ad 		    BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
   1671  1.3.2.2  ad 
   1672  1.3.2.2  ad 		cur_tx = &sc_if->sk_rdata->sk_tx_ring[idx];
   1673  1.3.2.2  ad 		sk_ctl = letoh32(cur_tx->sk_ctl);
   1674  1.3.2.2  ad #ifdef MSK_DEBUG
   1675  1.3.2.2  ad 		if (mskdebug >= 2)
   1676  1.3.2.2  ad 			msk_dump_txdesc(cur_tx, idx);
   1677  1.3.2.2  ad #endif
   1678  1.3.2.2  ad 		if (sk_ctl & SK_TXCTL_LASTFRAG)
   1679  1.3.2.2  ad 			ifp->if_opackets++;
   1680  1.3.2.2  ad 		if (sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf != NULL) {
   1681  1.3.2.2  ad 			entry = sc_if->sk_cdata.sk_tx_map[idx];
   1682  1.3.2.2  ad 
   1683  1.3.2.2  ad 			m_freem(sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf);
   1684  1.3.2.2  ad 			sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf = NULL;
   1685  1.3.2.2  ad 
   1686  1.3.2.2  ad 			bus_dmamap_sync(sc->sc_dmatag, entry->dmamap, 0,
   1687  1.3.2.2  ad 			    entry->dmamap->dm_mapsize, BUS_DMASYNC_POSTWRITE);
   1688  1.3.2.2  ad 
   1689  1.3.2.2  ad 			bus_dmamap_unload(sc->sc_dmatag, entry->dmamap);
   1690  1.3.2.2  ad 			SIMPLEQ_INSERT_TAIL(&sc_if->sk_txmap_head, entry,
   1691  1.3.2.2  ad 					  link);
   1692  1.3.2.2  ad 			sc_if->sk_cdata.sk_tx_map[idx] = NULL;
   1693  1.3.2.2  ad 		}
   1694  1.3.2.2  ad 		sc_if->sk_cdata.sk_tx_cnt--;
   1695  1.3.2.2  ad 		SK_INC(idx, MSK_TX_RING_CNT);
   1696  1.3.2.2  ad 	}
   1697  1.3.2.2  ad 	ifp->if_timer = sc_if->sk_cdata.sk_tx_cnt > 0 ? 5 : 0;
   1698  1.3.2.2  ad 
   1699  1.3.2.2  ad 	if (sc_if->sk_cdata.sk_tx_cnt < MSK_TX_RING_CNT - 2)
   1700  1.3.2.2  ad 		ifp->if_flags &= ~IFF_OACTIVE;
   1701  1.3.2.2  ad 
   1702  1.3.2.2  ad 	sc_if->sk_cdata.sk_tx_cons = idx;
   1703  1.3.2.2  ad }
   1704  1.3.2.2  ad 
   1705  1.3.2.2  ad void
   1706  1.3.2.2  ad msk_yukon_tick(void *xsc_if)
   1707  1.3.2.2  ad {
   1708  1.3.2.2  ad 	struct sk_if_softc *sc_if = xsc_if;
   1709  1.3.2.2  ad 	struct mii_data *mii = &sc_if->sk_mii;
   1710  1.3.2.2  ad 
   1711  1.3.2.2  ad 	mii_tick(mii);
   1712  1.3.2.2  ad 	callout_schedule(&sc_if->sk_tick_ch, hz);
   1713  1.3.2.2  ad }
   1714  1.3.2.2  ad 
   1715  1.3.2.2  ad void
   1716  1.3.2.2  ad msk_intr_yukon(struct sk_if_softc *sc_if)
   1717  1.3.2.2  ad {
   1718  1.3.2.2  ad 	u_int8_t status;
   1719  1.3.2.2  ad 
   1720  1.3.2.2  ad 	status = SK_IF_READ_1(sc_if, 0, SK_GMAC_ISR);
   1721  1.3.2.2  ad 	/* RX overrun */
   1722  1.3.2.2  ad 	if ((status & SK_GMAC_INT_RX_OVER) != 0) {
   1723  1.3.2.2  ad 		SK_IF_WRITE_1(sc_if, 0, SK_RXMF1_CTRL_TEST,
   1724  1.3.2.2  ad 		    SK_RFCTL_RX_FIFO_OVER);
   1725  1.3.2.2  ad 	}
   1726  1.3.2.2  ad 	/* TX underrun */
   1727  1.3.2.2  ad 	if ((status & SK_GMAC_INT_TX_UNDER) != 0) {
   1728  1.3.2.2  ad 		SK_IF_WRITE_1(sc_if, 0, SK_RXMF1_CTRL_TEST,
   1729  1.3.2.2  ad 		    SK_TFCTL_TX_FIFO_UNDER);
   1730  1.3.2.2  ad 	}
   1731  1.3.2.2  ad 
   1732  1.3.2.2  ad 	DPRINTFN(2, ("msk_intr_yukon status=%#x\n", status));
   1733  1.3.2.2  ad }
   1734  1.3.2.2  ad 
   1735  1.3.2.2  ad int
   1736  1.3.2.2  ad msk_intr(void *xsc)
   1737  1.3.2.2  ad {
   1738  1.3.2.2  ad 	struct sk_softc		*sc = xsc;
   1739  1.3.2.2  ad 	struct sk_if_softc	*sc_if0 = sc->sk_if[SK_PORT_A];
   1740  1.3.2.2  ad 	struct sk_if_softc	*sc_if1 = sc->sk_if[SK_PORT_B];
   1741  1.3.2.2  ad 	struct ifnet		*ifp0 = NULL, *ifp1 = NULL;
   1742  1.3.2.2  ad 	int			claimed = 0;
   1743  1.3.2.2  ad 	u_int32_t		status;
   1744  1.3.2.2  ad 	u_int16_t		idx;
   1745  1.3.2.2  ad 	struct msk_status_desc	*cur_st;
   1746  1.3.2.2  ad 
   1747  1.3.2.2  ad 	status = CSR_READ_4(sc, SK_Y2_ISSR2);
   1748  1.3.2.2  ad 	if (status == 0) {
   1749  1.3.2.2  ad 		CSR_WRITE_4(sc, SK_Y2_ICR, 2);
   1750  1.3.2.2  ad 		return (0);
   1751  1.3.2.2  ad 	}
   1752  1.3.2.2  ad 
   1753  1.3.2.2  ad 	status = CSR_READ_4(sc, SK_ISR);
   1754  1.3.2.2  ad 
   1755  1.3.2.2  ad 	if (sc_if0 != NULL)
   1756  1.3.2.2  ad 		ifp0 = &sc_if0->sk_ethercom.ec_if;
   1757  1.3.2.2  ad 	if (sc_if1 != NULL)
   1758  1.3.2.2  ad 		ifp1 = &sc_if1->sk_ethercom.ec_if;
   1759  1.3.2.2  ad 
   1760  1.3.2.2  ad 	if (sc_if0 && (status & SK_Y2_IMR_MAC1) &&
   1761  1.3.2.2  ad 	    (ifp0->if_flags & IFF_RUNNING)) {
   1762  1.3.2.2  ad 		msk_intr_yukon(sc_if0);
   1763  1.3.2.2  ad 	}
   1764  1.3.2.2  ad 
   1765  1.3.2.2  ad 	if (sc_if1 && (status & SK_Y2_IMR_MAC2) &&
   1766  1.3.2.2  ad 	    (ifp1->if_flags & IFF_RUNNING)) {
   1767  1.3.2.2  ad 		msk_intr_yukon(sc_if1);
   1768  1.3.2.2  ad 	}
   1769  1.3.2.2  ad 
   1770  1.3.2.2  ad 	idx = CSR_READ_2(sc, SK_STAT_BMU_PUTIDX);
   1771  1.3.2.2  ad 	while (sc->sk_status_idx != idx) {
   1772  1.3.2.2  ad 		MSK_CDSTSYNC(sc, sc->sk_status_idx,
   1773  1.3.2.2  ad 		    BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
   1774  1.3.2.2  ad 
   1775  1.3.2.2  ad 		cur_st = &sc->sk_status_ring[sc->sk_status_idx];
   1776  1.3.2.2  ad 		switch (cur_st->sk_opcode & ~SK_Y2_STOPC_OWN) {
   1777  1.3.2.2  ad 		case SK_Y2_STOPC_RXSTAT:
   1778  1.3.2.2  ad 			msk_rxeof(sc->sk_if[cur_st->sk_link],
   1779  1.3.2.2  ad 			    letoh16(cur_st->sk_len),
   1780  1.3.2.2  ad 			    letoh32(cur_st->sk_status));
   1781  1.3.2.2  ad 			SK_IF_WRITE_2(sc->sk_if[cur_st->sk_link], 0,
   1782  1.3.2.2  ad 			    SK_RXQ1_Y2_PREF_PUTIDX,
   1783  1.3.2.2  ad 			    sc->sk_if[cur_st->sk_link]->sk_cdata.sk_rx_prod);
   1784  1.3.2.2  ad 			break;
   1785  1.3.2.2  ad 		case SK_Y2_STOPC_TXSTAT:
   1786  1.3.2.2  ad 			msk_txeof(sc->sk_if[cur_st->sk_link]);
   1787  1.3.2.2  ad 			break;
   1788  1.3.2.2  ad 		default:
   1789  1.3.2.2  ad 			aprint_error("opcode=0x%x\n", cur_st->sk_opcode);
   1790  1.3.2.2  ad 			break;
   1791  1.3.2.2  ad 		}
   1792  1.3.2.2  ad 		SK_INC(sc->sk_status_idx, MSK_STATUS_RING_CNT);
   1793  1.3.2.2  ad 		idx = CSR_READ_2(sc, SK_STAT_BMU_PUTIDX);
   1794  1.3.2.2  ad 	}
   1795  1.3.2.2  ad 
   1796  1.3.2.2  ad 	if (status & SK_Y2_IMR_BMU) {
   1797  1.3.2.2  ad 		CSR_WRITE_4(sc, SK_STAT_BMU_CSR, SK_STAT_BMU_IRQ_CLEAR);
   1798  1.3.2.2  ad 		claimed = 1;
   1799  1.3.2.2  ad 	}
   1800  1.3.2.2  ad 
   1801  1.3.2.2  ad 	CSR_WRITE_4(sc, SK_Y2_ICR, 2);
   1802  1.3.2.2  ad 
   1803  1.3.2.2  ad 	if (ifp0 != NULL && !IFQ_IS_EMPTY(&ifp0->if_snd))
   1804  1.3.2.2  ad 		msk_start(ifp0);
   1805  1.3.2.2  ad 	if (ifp1 != NULL && !IFQ_IS_EMPTY(&ifp1->if_snd))
   1806  1.3.2.2  ad 		msk_start(ifp1);
   1807  1.3.2.2  ad 
   1808  1.3.2.2  ad #if NRND > 0
   1809  1.3.2.2  ad 	if (RND_ENABLED(&sc->rnd_source))
   1810  1.3.2.2  ad 		rnd_add_uint32(&sc->rnd_source, status);
   1811  1.3.2.2  ad #endif
   1812  1.3.2.2  ad 
   1813  1.3.2.2  ad 	if (sc->sk_int_mod_pending)
   1814  1.3.2.2  ad 		msk_update_int_mod(sc);
   1815  1.3.2.2  ad 
   1816  1.3.2.2  ad 	return claimed;
   1817  1.3.2.2  ad }
   1818  1.3.2.2  ad 
   1819  1.3.2.2  ad void
   1820  1.3.2.2  ad msk_init_yukon(struct sk_if_softc *sc_if)
   1821  1.3.2.2  ad {
   1822  1.3.2.2  ad 	u_int32_t		phy, v;
   1823  1.3.2.2  ad 	u_int16_t		reg;
   1824  1.3.2.2  ad 	struct sk_softc		*sc;
   1825  1.3.2.2  ad 	int			i;
   1826  1.3.2.2  ad 
   1827  1.3.2.2  ad 	sc = sc_if->sk_softc;
   1828  1.3.2.2  ad 
   1829  1.3.2.2  ad 	DPRINTFN(2, ("msk_init_yukon: start: sk_csr=%#x\n",
   1830  1.3.2.2  ad 		     CSR_READ_4(sc_if->sk_softc, SK_CSR)));
   1831  1.3.2.2  ad 
   1832  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: 1\n"));
   1833  1.3.2.2  ad 
   1834  1.3.2.2  ad 	/* GMAC and GPHY Reset */
   1835  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_GPHY_CTRL, SK_GPHY_RESET_SET);
   1836  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_GMAC_CTRL, SK_GMAC_RESET_SET);
   1837  1.3.2.2  ad 	DELAY(1000);
   1838  1.3.2.2  ad 
   1839  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: 2\n"));
   1840  1.3.2.2  ad 
   1841  1.3.2.2  ad #if 0
   1842  1.3.2.2  ad 	phy = SK_GPHY_INT_POL_HI | SK_GPHY_DIS_FC | SK_GPHY_DIS_SLEEP |
   1843  1.3.2.2  ad 		SK_GPHY_ENA_XC | SK_GPHY_ANEG_ALL | SK_GPHY_ENA_PAUSE;
   1844  1.3.2.2  ad #else
   1845  1.3.2.2  ad 	phy = SK_GPHY_ENA_PAUSE;
   1846  1.3.2.2  ad #endif
   1847  1.3.2.2  ad 
   1848  1.3.2.2  ad 	if (sc->sk_coppertype)
   1849  1.3.2.2  ad 		phy |= SK_GPHY_COPPER;
   1850  1.3.2.2  ad 	else
   1851  1.3.2.2  ad 		phy |= SK_GPHY_FIBER;
   1852  1.3.2.2  ad 
   1853  1.3.2.2  ad 	DPRINTFN(3, ("msk_init_yukon: phy=%#x\n", phy));
   1854  1.3.2.2  ad 
   1855  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_GPHY_CTRL, phy | SK_GPHY_RESET_SET);
   1856  1.3.2.2  ad 	DELAY(1000);
   1857  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_GPHY_CTRL, phy | SK_GPHY_RESET_CLEAR);
   1858  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_GMAC_CTRL, SK_GMAC_LOOP_OFF |
   1859  1.3.2.2  ad 		      SK_GMAC_PAUSE_ON | SK_GMAC_RESET_CLEAR);
   1860  1.3.2.2  ad 
   1861  1.3.2.2  ad 	DPRINTFN(3, ("msk_init_yukon: gmac_ctrl=%#x\n",
   1862  1.3.2.2  ad 		     SK_IF_READ_4(sc_if, 0, SK_GMAC_CTRL)));
   1863  1.3.2.2  ad 
   1864  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: 3\n"));
   1865  1.3.2.2  ad 
   1866  1.3.2.2  ad 	/* unused read of the interrupt source register */
   1867  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: 4\n"));
   1868  1.3.2.2  ad 	SK_IF_READ_2(sc_if, 0, SK_GMAC_ISR);
   1869  1.3.2.2  ad 
   1870  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: 4a\n"));
   1871  1.3.2.2  ad 	reg = SK_YU_READ_2(sc_if, YUKON_PAR);
   1872  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: YUKON_PAR=%#x\n", reg));
   1873  1.3.2.2  ad 
   1874  1.3.2.2  ad 	/* MIB Counter Clear Mode set */
   1875  1.3.2.2  ad         reg |= YU_PAR_MIB_CLR;
   1876  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: YUKON_PAR=%#x\n", reg));
   1877  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: 4b\n"));
   1878  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_PAR, reg);
   1879  1.3.2.2  ad 
   1880  1.3.2.2  ad 	/* MIB Counter Clear Mode clear */
   1881  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: 5\n"));
   1882  1.3.2.2  ad         reg &= ~YU_PAR_MIB_CLR;
   1883  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_PAR, reg);
   1884  1.3.2.2  ad 
   1885  1.3.2.2  ad 	/* receive control reg */
   1886  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: 7\n"));
   1887  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_RCR, YU_RCR_CRCR);
   1888  1.3.2.2  ad 
   1889  1.3.2.2  ad 	/* transmit parameter register */
   1890  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: 8\n"));
   1891  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_TPR, YU_TPR_JAM_LEN(0x3) |
   1892  1.3.2.2  ad 		      YU_TPR_JAM_IPG(0xb) | YU_TPR_JAM2DATA_IPG(0x1a) );
   1893  1.3.2.2  ad 
   1894  1.3.2.2  ad 	/* serial mode register */
   1895  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: 9\n"));
   1896  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_SMR, YU_SMR_DATA_BLIND(0x1c) |
   1897  1.3.2.2  ad 		      YU_SMR_MFL_VLAN | YU_SMR_MFL_JUMBO |
   1898  1.3.2.2  ad 		      YU_SMR_IPG_DATA(0x1e));
   1899  1.3.2.2  ad 
   1900  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: 10\n"));
   1901  1.3.2.2  ad 	/* Setup Yukon's address */
   1902  1.3.2.2  ad 	for (i = 0; i < 3; i++) {
   1903  1.3.2.2  ad 		/* Write Source Address 1 (unicast filter) */
   1904  1.3.2.2  ad 		SK_YU_WRITE_2(sc_if, YUKON_SAL1 + i * 4,
   1905  1.3.2.2  ad 			      sc_if->sk_enaddr[i * 2] |
   1906  1.3.2.2  ad 			      sc_if->sk_enaddr[i * 2 + 1] << 8);
   1907  1.3.2.2  ad 	}
   1908  1.3.2.2  ad 
   1909  1.3.2.2  ad 	for (i = 0; i < 3; i++) {
   1910  1.3.2.2  ad 		reg = sk_win_read_2(sc_if->sk_softc,
   1911  1.3.2.2  ad 				    SK_MAC1_0 + i * 2 + sc_if->sk_port * 8);
   1912  1.3.2.2  ad 		SK_YU_WRITE_2(sc_if, YUKON_SAL2 + i * 4, reg);
   1913  1.3.2.2  ad 	}
   1914  1.3.2.2  ad 
   1915  1.3.2.2  ad 	/* Set promiscuous mode */
   1916  1.3.2.2  ad 	msk_setpromisc(sc_if);
   1917  1.3.2.2  ad 
   1918  1.3.2.2  ad 	/* Set multicast filter */
   1919  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: 11\n"));
   1920  1.3.2.2  ad 	msk_setmulti(sc_if);
   1921  1.3.2.2  ad 
   1922  1.3.2.2  ad 	/* enable interrupt mask for counter overflows */
   1923  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: 12\n"));
   1924  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_TIMR, 0);
   1925  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_RIMR, 0);
   1926  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_TRIMR, 0);
   1927  1.3.2.2  ad 
   1928  1.3.2.2  ad 	/* Configure RX MAC FIFO Flush Mask */
   1929  1.3.2.2  ad 	v = YU_RXSTAT_FOFL | YU_RXSTAT_CRCERR | YU_RXSTAT_MIIERR |
   1930  1.3.2.2  ad 	    YU_RXSTAT_BADFC | YU_RXSTAT_GOODFC | YU_RXSTAT_RUNT |
   1931  1.3.2.2  ad 	    YU_RXSTAT_JABBER;
   1932  1.3.2.2  ad 	SK_IF_WRITE_2(sc_if, 0, SK_RXMF1_FLUSH_MASK, v);
   1933  1.3.2.2  ad 
   1934  1.3.2.2  ad 	/* Disable RX MAC FIFO Flush for YUKON-Lite Rev. A0 only */
   1935  1.3.2.2  ad 	if (sc->sk_type == SK_YUKON_LITE && sc->sk_rev == SK_YUKON_LITE_REV_A0)
   1936  1.3.2.2  ad 		v = SK_TFCTL_OPERATION_ON;
   1937  1.3.2.2  ad 	else
   1938  1.3.2.2  ad 		v = SK_TFCTL_OPERATION_ON | SK_RFCTL_FIFO_FLUSH_ON;
   1939  1.3.2.2  ad 	/* Configure RX MAC FIFO */
   1940  1.3.2.2  ad 	SK_IF_WRITE_1(sc_if, 0, SK_RXMF1_CTRL_TEST, SK_RFCTL_RESET_CLEAR);
   1941  1.3.2.2  ad 	SK_IF_WRITE_2(sc_if, 0, SK_RXMF1_CTRL_TEST, v);
   1942  1.3.2.2  ad 
   1943  1.3.2.2  ad 	/* Increase flush threshould to 64 bytes */
   1944  1.3.2.2  ad 	SK_IF_WRITE_2(sc_if, 0, SK_RXMF1_FLUSH_THRESHOLD,
   1945  1.3.2.2  ad 	    SK_RFCTL_FIFO_THRESHOLD + 1);
   1946  1.3.2.2  ad 
   1947  1.3.2.2  ad 	/* Configure TX MAC FIFO */
   1948  1.3.2.2  ad 	SK_IF_WRITE_1(sc_if, 0, SK_TXMF1_CTRL_TEST, SK_TFCTL_RESET_CLEAR);
   1949  1.3.2.2  ad 	SK_IF_WRITE_2(sc_if, 0, SK_TXMF1_CTRL_TEST, SK_TFCTL_OPERATION_ON);
   1950  1.3.2.2  ad 
   1951  1.3.2.2  ad #if 1
   1952  1.3.2.2  ad 	SK_YU_WRITE_2(sc_if, YUKON_GPCR, YU_GPCR_TXEN | YU_GPCR_RXEN);
   1953  1.3.2.2  ad #endif
   1954  1.3.2.2  ad 	DPRINTFN(6, ("msk_init_yukon: end\n"));
   1955  1.3.2.2  ad }
   1956  1.3.2.2  ad 
   1957  1.3.2.2  ad /*
   1958  1.3.2.2  ad  * Note that to properly initialize any part of the GEnesis chip,
   1959  1.3.2.2  ad  * you first have to take it out of reset mode.
   1960  1.3.2.2  ad  */
   1961  1.3.2.2  ad int
   1962  1.3.2.2  ad msk_init(struct ifnet *ifp)
   1963  1.3.2.2  ad {
   1964  1.3.2.2  ad 	struct sk_if_softc	*sc_if = ifp->if_softc;
   1965  1.3.2.2  ad 	struct sk_softc		*sc = sc_if->sk_softc;
   1966  1.3.2.2  ad 	struct mii_data		*mii = &sc_if->sk_mii;
   1967  1.3.2.2  ad 	int			s;
   1968  1.3.2.2  ad 	uint32_t		imr, sk_imtimer_ticks;
   1969  1.3.2.2  ad 
   1970  1.3.2.2  ad 
   1971  1.3.2.2  ad 	DPRINTFN(2, ("msk_init\n"));
   1972  1.3.2.2  ad 
   1973  1.3.2.2  ad 	s = splnet();
   1974  1.3.2.2  ad 
   1975  1.3.2.2  ad 	/* Cancel pending I/O and free all RX/TX buffers. */
   1976  1.3.2.2  ad 	msk_stop(ifp,0);
   1977  1.3.2.2  ad 
   1978  1.3.2.2  ad 	/* Configure I2C registers */
   1979  1.3.2.2  ad 
   1980  1.3.2.2  ad 	/* Configure XMAC(s) */
   1981  1.3.2.2  ad 	msk_init_yukon(sc_if);
   1982  1.3.2.2  ad 	mii_mediachg(mii);
   1983  1.3.2.2  ad 
   1984  1.3.2.2  ad 	/* Configure transmit arbiter(s) */
   1985  1.3.2.2  ad 	SK_IF_WRITE_1(sc_if, 0, SK_TXAR1_COUNTERCTL, SK_TXARCTL_ON);
   1986  1.3.2.2  ad #if 0
   1987  1.3.2.2  ad 	    SK_TXARCTL_ON|SK_TXARCTL_FSYNC_ON);
   1988  1.3.2.2  ad #endif
   1989  1.3.2.2  ad 
   1990  1.3.2.2  ad 	/* Configure RAMbuffers */
   1991  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_CTLTST, SK_RBCTL_UNRESET);
   1992  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_START, sc_if->sk_rx_ramstart);
   1993  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_WR_PTR, sc_if->sk_rx_ramstart);
   1994  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_RD_PTR, sc_if->sk_rx_ramstart);
   1995  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_END, sc_if->sk_rx_ramend);
   1996  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_CTLTST, SK_RBCTL_ON);
   1997  1.3.2.2  ad 
   1998  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_CTLTST, SK_RBCTL_UNRESET);
   1999  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_CTLTST, SK_RBCTL_STORENFWD_ON);
   2000  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_START, sc_if->sk_tx_ramstart);
   2001  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_WR_PTR, sc_if->sk_tx_ramstart);
   2002  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_RD_PTR, sc_if->sk_tx_ramstart);
   2003  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_END, sc_if->sk_tx_ramend);
   2004  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_CTLTST, SK_RBCTL_ON);
   2005  1.3.2.2  ad 
   2006  1.3.2.2  ad 	/* Configure BMUs */
   2007  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_BMU_CSR, 0x00000016);
   2008  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_BMU_CSR, 0x00000d28);
   2009  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_BMU_CSR, 0x00000080);
   2010  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_WATERMARK, 0x00000600);
   2011  1.3.2.2  ad 
   2012  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_BMU_CSR, 0x00000016);
   2013  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_BMU_CSR, 0x00000d28);
   2014  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_BMU_CSR, 0x00000080);
   2015  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_WATERMARK, 0x00000600);
   2016  1.3.2.2  ad 
   2017  1.3.2.2  ad 	/* Make sure the sync transmit queue is disabled. */
   2018  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_CTLTST, SK_RBCTL_RESET);
   2019  1.3.2.2  ad 
   2020  1.3.2.2  ad 	/* Init descriptors */
   2021  1.3.2.2  ad 	if (msk_init_rx_ring(sc_if) == ENOBUFS) {
   2022  1.3.2.2  ad 		aprint_error("%s: initialization failed: no "
   2023  1.3.2.2  ad 		    "memory for rx buffers\n", sc_if->sk_dev.dv_xname);
   2024  1.3.2.2  ad 		msk_stop(ifp,0);
   2025  1.3.2.2  ad 		splx(s);
   2026  1.3.2.2  ad 		return ENOBUFS;
   2027  1.3.2.2  ad 	}
   2028  1.3.2.2  ad 
   2029  1.3.2.2  ad 	if (msk_init_tx_ring(sc_if) == ENOBUFS) {
   2030  1.3.2.2  ad 		aprint_error("%s: initialization failed: no "
   2031  1.3.2.2  ad 		    "memory for tx buffers\n", sc_if->sk_dev.dv_xname);
   2032  1.3.2.2  ad 		msk_stop(ifp,0);
   2033  1.3.2.2  ad 		splx(s);
   2034  1.3.2.2  ad 		return ENOBUFS;
   2035  1.3.2.2  ad 	}
   2036  1.3.2.2  ad 
   2037  1.3.2.2  ad 	/* Set interrupt moderation if changed via sysctl. */
   2038  1.3.2.2  ad 	switch (sc->sk_type) {
   2039  1.3.2.2  ad 	case SK_YUKON_EC:
   2040  1.3.2.2  ad 		sk_imtimer_ticks = SK_IMTIMER_TICKS_YUKON_EC;
   2041  1.3.2.2  ad 		break;
   2042  1.3.2.2  ad 	default:
   2043  1.3.2.2  ad 		sk_imtimer_ticks = SK_IMTIMER_TICKS_YUKON;
   2044  1.3.2.2  ad 	}
   2045  1.3.2.2  ad 	imr = sk_win_read_4(sc, SK_IMTIMERINIT);
   2046  1.3.2.2  ad 	if (imr != SK_IM_USECS(sc->sk_int_mod)) {
   2047  1.3.2.2  ad 		sk_win_write_4(sc, SK_IMTIMERINIT,
   2048  1.3.2.2  ad 		    SK_IM_USECS(sc->sk_int_mod));
   2049  1.3.2.2  ad 		aprint_verbose("%s: interrupt moderation is %d us\n",
   2050  1.3.2.2  ad 		    sc->sk_dev.dv_xname, sc->sk_int_mod);
   2051  1.3.2.2  ad 	}
   2052  1.3.2.2  ad 
   2053  1.3.2.2  ad 	/* Initialize prefetch engine. */
   2054  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_Y2_PREF_CSR, 0x00000001);
   2055  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_Y2_PREF_CSR, 0x00000002);
   2056  1.3.2.2  ad 	SK_IF_WRITE_2(sc_if, 0, SK_RXQ1_Y2_PREF_LIDX, MSK_RX_RING_CNT - 1);
   2057  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_Y2_PREF_ADDRLO,
   2058  1.3.2.2  ad 	    MSK_RX_RING_ADDR(sc_if, 0));
   2059  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_Y2_PREF_ADDRHI,
   2060  1.3.2.2  ad 	    (u_int64_t)MSK_RX_RING_ADDR(sc_if, 0) >> 32);
   2061  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_Y2_PREF_CSR, 0x00000008);
   2062  1.3.2.2  ad 	SK_IF_READ_4(sc_if, 0, SK_RXQ1_Y2_PREF_CSR);
   2063  1.3.2.2  ad 
   2064  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_Y2_PREF_CSR, 0x00000001);
   2065  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_Y2_PREF_CSR, 0x00000002);
   2066  1.3.2.2  ad 	SK_IF_WRITE_2(sc_if, 1, SK_TXQA1_Y2_PREF_LIDX, MSK_TX_RING_CNT - 1);
   2067  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_Y2_PREF_ADDRLO,
   2068  1.3.2.2  ad 	    MSK_TX_RING_ADDR(sc_if, 0));
   2069  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_Y2_PREF_ADDRHI,
   2070  1.3.2.2  ad 	    (u_int64_t)MSK_TX_RING_ADDR(sc_if, 0) >> 32);
   2071  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_Y2_PREF_CSR, 0x00000008);
   2072  1.3.2.2  ad 	SK_IF_READ_4(sc_if, 1, SK_TXQA1_Y2_PREF_CSR);
   2073  1.3.2.2  ad 
   2074  1.3.2.2  ad 	SK_IF_WRITE_2(sc_if, 0, SK_RXQ1_Y2_PREF_PUTIDX,
   2075  1.3.2.2  ad 	    sc_if->sk_cdata.sk_rx_prod);
   2076  1.3.2.2  ad 
   2077  1.3.2.2  ad 	/* Configure interrupt handling */
   2078  1.3.2.2  ad 	if (sc_if->sk_port == SK_PORT_A)
   2079  1.3.2.2  ad 		sc->sk_intrmask |= SK_Y2_INTRS1;
   2080  1.3.2.2  ad 	else
   2081  1.3.2.2  ad 		sc->sk_intrmask |= SK_Y2_INTRS2;
   2082  1.3.2.2  ad 	sc->sk_intrmask |= SK_Y2_IMR_BMU;
   2083  1.3.2.2  ad 	CSR_WRITE_4(sc, SK_IMR, sc->sk_intrmask);
   2084  1.3.2.2  ad 
   2085  1.3.2.2  ad 	ifp->if_flags |= IFF_RUNNING;
   2086  1.3.2.2  ad 	ifp->if_flags &= ~IFF_OACTIVE;
   2087  1.3.2.2  ad 
   2088  1.3.2.2  ad 	callout_schedule(&sc_if->sk_tick_ch, hz);
   2089  1.3.2.2  ad 
   2090  1.3.2.2  ad 	splx(s);
   2091  1.3.2.2  ad 	return 0;
   2092  1.3.2.2  ad }
   2093  1.3.2.2  ad 
   2094  1.3.2.2  ad void
   2095  1.3.2.2  ad msk_stop(struct ifnet *ifp, int disable)
   2096  1.3.2.2  ad {
   2097  1.3.2.2  ad 	struct sk_if_softc	*sc_if = ifp->if_softc;
   2098  1.3.2.2  ad 	struct sk_softc		*sc = sc_if->sk_softc;
   2099  1.3.2.2  ad 	struct sk_txmap_entry	*dma;
   2100  1.3.2.2  ad 	int			i;
   2101  1.3.2.2  ad 
   2102  1.3.2.2  ad 	DPRINTFN(2, ("msk_stop\n"));
   2103  1.3.2.2  ad 
   2104  1.3.2.2  ad 	callout_stop(&sc_if->sk_tick_ch);
   2105  1.3.2.2  ad 
   2106  1.3.2.2  ad 	ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
   2107  1.3.2.2  ad 
   2108  1.3.2.2  ad 	/* Stop transfer of Tx descriptors */
   2109  1.3.2.2  ad 
   2110  1.3.2.2  ad 	/* Stop transfer of Rx descriptors */
   2111  1.3.2.2  ad 
   2112  1.3.2.2  ad 	/* Turn off various components of this interface. */
   2113  1.3.2.2  ad 	SK_XM_SETBIT_2(sc_if, XM_GPIO, XM_GPIO_RESETMAC);
   2114  1.3.2.2  ad 	SK_IF_WRITE_1(sc_if,0, SK_RXMF1_CTRL_TEST, SK_RFCTL_RESET_SET);
   2115  1.3.2.2  ad 	SK_IF_WRITE_1(sc_if,0, SK_TXMF1_CTRL_TEST, SK_TFCTL_RESET_SET);
   2116  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_BMU_CSR, SK_RXBMU_OFFLINE);
   2117  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_CTLTST, SK_RBCTL_RESET|SK_RBCTL_OFF);
   2118  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_BMU_CSR, SK_TXBMU_OFFLINE);
   2119  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXRBA1_CTLTST, SK_RBCTL_RESET|SK_RBCTL_OFF);
   2120  1.3.2.2  ad 	SK_IF_WRITE_1(sc_if, 0, SK_TXAR1_COUNTERCTL, SK_TXARCTL_OFF);
   2121  1.3.2.2  ad 	SK_IF_WRITE_1(sc_if, 0, SK_RXLED1_CTL, SK_RXLEDCTL_COUNTER_STOP);
   2122  1.3.2.2  ad 	SK_IF_WRITE_1(sc_if, 0, SK_TXLED1_CTL, SK_RXLEDCTL_COUNTER_STOP);
   2123  1.3.2.2  ad 	SK_IF_WRITE_1(sc_if, 0, SK_LINKLED1_CTL, SK_LINKLED_OFF);
   2124  1.3.2.2  ad 	SK_IF_WRITE_1(sc_if, 0, SK_LINKLED1_CTL, SK_LINKLED_LINKSYNC_OFF);
   2125  1.3.2.2  ad 
   2126  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_Y2_PREF_CSR, 0x00000001);
   2127  1.3.2.2  ad 	SK_IF_WRITE_4(sc_if, 1, SK_TXQA1_Y2_PREF_CSR, 0x00000001);
   2128  1.3.2.2  ad 
   2129  1.3.2.2  ad 	/* Disable interrupts */
   2130  1.3.2.2  ad 	if (sc_if->sk_port == SK_PORT_A)
   2131  1.3.2.2  ad 		sc->sk_intrmask &= ~SK_Y2_INTRS1;
   2132  1.3.2.2  ad 	else
   2133  1.3.2.2  ad 		sc->sk_intrmask &= ~SK_Y2_INTRS2;
   2134  1.3.2.2  ad 	CSR_WRITE_4(sc, SK_IMR, sc->sk_intrmask);
   2135  1.3.2.2  ad 
   2136  1.3.2.2  ad 	SK_XM_READ_2(sc_if, XM_ISR);
   2137  1.3.2.2  ad 	SK_XM_WRITE_2(sc_if, XM_IMR, 0xFFFF);
   2138  1.3.2.2  ad 
   2139  1.3.2.2  ad 	/* Free RX and TX mbufs still in the queues. */
   2140  1.3.2.2  ad 	for (i = 0; i < MSK_RX_RING_CNT; i++) {
   2141  1.3.2.2  ad 		if (sc_if->sk_cdata.sk_rx_chain[i].sk_mbuf != NULL) {
   2142  1.3.2.2  ad 			m_freem(sc_if->sk_cdata.sk_rx_chain[i].sk_mbuf);
   2143  1.3.2.2  ad 			sc_if->sk_cdata.sk_rx_chain[i].sk_mbuf = NULL;
   2144  1.3.2.2  ad 		}
   2145  1.3.2.2  ad 	}
   2146  1.3.2.2  ad 
   2147  1.3.2.2  ad 	for (i = 0; i < MSK_TX_RING_CNT; i++) {
   2148  1.3.2.2  ad 		if (sc_if->sk_cdata.sk_tx_chain[i].sk_mbuf != NULL) {
   2149  1.3.2.2  ad 			m_freem(sc_if->sk_cdata.sk_tx_chain[i].sk_mbuf);
   2150  1.3.2.2  ad 			sc_if->sk_cdata.sk_tx_chain[i].sk_mbuf = NULL;
   2151  1.3.2.2  ad #if 1
   2152  1.3.2.2  ad 			SIMPLEQ_INSERT_HEAD(&sc_if->sk_txmap_head,
   2153  1.3.2.2  ad 			    sc_if->sk_cdata.sk_tx_map[i], link);
   2154  1.3.2.2  ad 			sc_if->sk_cdata.sk_tx_map[i] = 0;
   2155  1.3.2.2  ad #endif
   2156  1.3.2.2  ad 		}
   2157  1.3.2.2  ad 	}
   2158  1.3.2.2  ad 
   2159  1.3.2.2  ad #if 1
   2160  1.3.2.2  ad 	while ((dma = SIMPLEQ_FIRST(&sc_if->sk_txmap_head))) {
   2161  1.3.2.2  ad 		SIMPLEQ_REMOVE_HEAD(&sc_if->sk_txmap_head, link);
   2162  1.3.2.2  ad 		bus_dmamap_destroy(sc->sc_dmatag, dma->dmamap);
   2163  1.3.2.2  ad 		free(dma, M_DEVBUF);
   2164  1.3.2.2  ad 	}
   2165  1.3.2.2  ad #endif
   2166  1.3.2.2  ad }
   2167  1.3.2.2  ad 
   2168  1.3.2.2  ad CFATTACH_DECL(mskc, sizeof(struct sk_softc), mskc_probe, mskc_attach,
   2169  1.3.2.2  ad 	NULL, NULL);
   2170  1.3.2.2  ad 
   2171  1.3.2.2  ad CFATTACH_DECL(msk, sizeof(struct sk_if_softc), msk_probe, msk_attach,
   2172  1.3.2.2  ad 	NULL, NULL);
   2173  1.3.2.2  ad 
   2174  1.3.2.2  ad #ifdef MSK_DEBUG
   2175  1.3.2.2  ad void
   2176  1.3.2.2  ad msk_dump_txdesc(struct msk_tx_desc *le, int idx)
   2177  1.3.2.2  ad {
   2178  1.3.2.2  ad #define DESC_PRINT(X)					\
   2179  1.3.2.2  ad 	if (X)					\
   2180  1.3.2.2  ad 		printf("txdesc[%d]." #X "=%#x\n",	\
   2181  1.3.2.2  ad 		       idx, X);
   2182  1.3.2.2  ad 
   2183  1.3.2.2  ad 	DESC_PRINT(letoh32(le->sk_addr));
   2184  1.3.2.2  ad 	DESC_PRINT(letoh16(le->sk_len));
   2185  1.3.2.2  ad 	DESC_PRINT(le->sk_ctl);
   2186  1.3.2.2  ad 	DESC_PRINT(le->sk_opcode);
   2187  1.3.2.2  ad #undef DESC_PRINT
   2188  1.3.2.2  ad }
   2189  1.3.2.2  ad 
   2190  1.3.2.2  ad void
   2191  1.3.2.2  ad msk_dump_bytes(const char *data, int len)
   2192  1.3.2.2  ad {
   2193  1.3.2.2  ad 	int c, i, j;
   2194  1.3.2.2  ad 
   2195  1.3.2.2  ad 	for (i = 0; i < len; i += 16) {
   2196  1.3.2.2  ad 		printf("%08x  ", i);
   2197  1.3.2.2  ad 		c = len - i;
   2198  1.3.2.2  ad 		if (c > 16) c = 16;
   2199  1.3.2.2  ad 
   2200  1.3.2.2  ad 		for (j = 0; j < c; j++) {
   2201  1.3.2.2  ad 			printf("%02x ", data[i + j] & 0xff);
   2202  1.3.2.2  ad 			if ((j & 0xf) == 7 && j > 0)
   2203  1.3.2.2  ad 				printf(" ");
   2204  1.3.2.2  ad 		}
   2205  1.3.2.2  ad 
   2206  1.3.2.2  ad 		for (; j < 16; j++)
   2207  1.3.2.2  ad 			printf("   ");
   2208  1.3.2.2  ad 		printf("  ");
   2209  1.3.2.2  ad 
   2210  1.3.2.2  ad 		for (j = 0; j < c; j++) {
   2211  1.3.2.2  ad 			int ch = data[i + j] & 0xff;
   2212  1.3.2.2  ad 			printf("%c", ' ' <= ch && ch <= '~' ? ch : ' ');
   2213  1.3.2.2  ad 		}
   2214  1.3.2.2  ad 
   2215  1.3.2.2  ad 		printf("\n");
   2216  1.3.2.2  ad 
   2217  1.3.2.2  ad 		if (c < 16)
   2218  1.3.2.2  ad 			break;
   2219  1.3.2.2  ad 	}
   2220  1.3.2.2  ad }
   2221  1.3.2.2  ad 
   2222  1.3.2.2  ad void
   2223  1.3.2.2  ad msk_dump_mbuf(struct mbuf *m)
   2224  1.3.2.2  ad {
   2225  1.3.2.2  ad 	int count = m->m_pkthdr.len;
   2226  1.3.2.2  ad 
   2227  1.3.2.2  ad 	printf("m=%p, m->m_pkthdr.len=%d\n", m, m->m_pkthdr.len);
   2228  1.3.2.2  ad 
   2229  1.3.2.2  ad 	while (count > 0 && m) {
   2230  1.3.2.2  ad 		printf("m=%p, m->m_data=%p, m->m_len=%d\n",
   2231  1.3.2.2  ad 		       m, m->m_data, m->m_len);
   2232  1.3.2.2  ad 		msk_dump_bytes(mtod(m, char *), m->m_len);
   2233  1.3.2.2  ad 
   2234  1.3.2.2  ad 		count -= m->m_len;
   2235  1.3.2.2  ad 		m = m->m_next;
   2236  1.3.2.2  ad 	}
   2237  1.3.2.2  ad }
   2238  1.3.2.2  ad #endif
   2239  1.3.2.2  ad 
   2240  1.3.2.2  ad static int
   2241  1.3.2.2  ad msk_sysctl_handler(SYSCTLFN_ARGS)
   2242  1.3.2.2  ad {
   2243  1.3.2.2  ad 	int error, t;
   2244  1.3.2.2  ad 	struct sysctlnode node;
   2245  1.3.2.2  ad 	struct sk_softc *sc;
   2246  1.3.2.2  ad 
   2247  1.3.2.2  ad 	node = *rnode;
   2248  1.3.2.2  ad 	sc = node.sysctl_data;
   2249  1.3.2.2  ad 	t = sc->sk_int_mod;
   2250  1.3.2.2  ad 	node.sysctl_data = &t;
   2251  1.3.2.2  ad 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   2252  1.3.2.2  ad 	if (error || newp == NULL)
   2253  1.3.2.2  ad 		return error;
   2254  1.3.2.2  ad 
   2255  1.3.2.2  ad 	if (t < SK_IM_MIN || t > SK_IM_MAX)
   2256  1.3.2.2  ad 		return EINVAL;
   2257  1.3.2.2  ad 
   2258  1.3.2.2  ad 	/* update the softc with sysctl-changed value, and mark
   2259  1.3.2.2  ad 	   for hardware update */
   2260  1.3.2.2  ad 	sc->sk_int_mod = t;
   2261  1.3.2.2  ad 	sc->sk_int_mod_pending = 1;
   2262  1.3.2.2  ad 	return 0;
   2263  1.3.2.2  ad }
   2264  1.3.2.2  ad 
   2265  1.3.2.2  ad /*
   2266  1.3.2.2  ad  * Set up sysctl(3) MIB, hw.sk.* - Individual controllers will be
   2267  1.3.2.2  ad  * set up in skc_attach()
   2268  1.3.2.2  ad  */
   2269  1.3.2.2  ad SYSCTL_SETUP(sysctl_msk, "sysctl msk subtree setup")
   2270  1.3.2.2  ad {
   2271  1.3.2.2  ad 	int rc;
   2272  1.3.2.2  ad 	const struct sysctlnode *node;
   2273  1.3.2.2  ad 
   2274  1.3.2.2  ad 	if ((rc = sysctl_createv(clog, 0, NULL, NULL,
   2275  1.3.2.2  ad 	    0, CTLTYPE_NODE, "hw", NULL,
   2276  1.3.2.2  ad 	    NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0) {
   2277  1.3.2.2  ad 		goto err;
   2278  1.3.2.2  ad 	}
   2279  1.3.2.2  ad 
   2280  1.3.2.2  ad 	if ((rc = sysctl_createv(clog, 0, NULL, &node,
   2281  1.3.2.2  ad 	    0, CTLTYPE_NODE, "msk",
   2282  1.3.2.2  ad 	    SYSCTL_DESCR("msk interface controls"),
   2283  1.3.2.2  ad 	    NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL)) != 0) {
   2284  1.3.2.2  ad 		goto err;
   2285  1.3.2.2  ad 	}
   2286  1.3.2.2  ad 
   2287  1.3.2.2  ad 	msk_root_num = node->sysctl_num;
   2288  1.3.2.2  ad 	return;
   2289  1.3.2.2  ad 
   2290  1.3.2.2  ad err:
   2291  1.3.2.2  ad 	aprint_error("%s: syctl_createv failed (rc = %d)\n", __func__, rc);
   2292  1.3.2.2  ad }
   2293