Home | History | Annotate | Line # | Download | only in usb
if_smsc.c revision 1.34.2.2
      1  1.34.2.2    martin /*	$NetBSD: if_smsc.c,v 1.34.2.2 2020/04/13 08:04:49 martin Exp $	*/
      2       1.1     skrll 
      3       1.1     skrll /*	$OpenBSD: if_smsc.c,v 1.4 2012/09/27 12:38:11 jsg Exp $	*/
      4      1.32     skrll /*	$FreeBSD: src/sys/dev/usb/net/if_smsc.c,v 1.1 2012/08/15 04:03:55 gonzo Exp $ */
      5       1.1     skrll /*-
      6       1.1     skrll  * Copyright (c) 2012
      7       1.1     skrll  *	Ben Gray <bgray (at) freebsd.org>.
      8       1.1     skrll  * All rights reserved.
      9       1.1     skrll  *
     10       1.1     skrll  * Redistribution and use in source and binary forms, with or without
     11       1.1     skrll  * modification, are permitted provided that the following conditions
     12       1.1     skrll  * are met:
     13       1.1     skrll  * 1. Redistributions of source code must retain the above copyright
     14       1.1     skrll  *    notice, this list of conditions and the following disclaimer.
     15       1.1     skrll  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1     skrll  *    notice, this list of conditions and the following disclaimer in the
     17       1.1     skrll  *    documentation and/or other materials provided with the distribution.
     18       1.1     skrll  *
     19       1.1     skrll  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20       1.1     skrll  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21       1.1     skrll  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22       1.1     skrll  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23       1.1     skrll  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24       1.1     skrll  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25       1.1     skrll  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26       1.1     skrll  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27       1.1     skrll  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28       1.1     skrll  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29       1.1     skrll  */
     30       1.1     skrll 
     31       1.1     skrll /*
     32       1.1     skrll  * SMSC LAN9xxx devices (http://www.smsc.com/)
     33       1.1     skrll  *
     34       1.1     skrll  * The LAN9500 & LAN9500A devices are stand-alone USB to Ethernet chips that
     35       1.1     skrll  * support USB 2.0 and 10/100 Mbps Ethernet.
     36       1.1     skrll  *
     37       1.1     skrll  * The LAN951x devices are an integrated USB hub and USB to Ethernet adapter.
     38       1.1     skrll  * The driver only covers the Ethernet part, the standard USB hub driver
     39       1.1     skrll  * supports the hub part.
     40       1.1     skrll  *
     41       1.1     skrll  * This driver is closely modelled on the Linux driver written and copyrighted
     42       1.1     skrll  * by SMSC.
     43       1.1     skrll  *
     44       1.1     skrll  * H/W TCP & UDP Checksum Offloading
     45       1.1     skrll  * ---------------------------------
     46       1.1     skrll  * The chip supports both tx and rx offloading of UDP & TCP checksums, this
     47       1.1     skrll  * feature can be dynamically enabled/disabled.
     48       1.1     skrll  *
     49       1.1     skrll  * RX checksuming is performed across bytes after the IPv4 header to the end of
     50       1.1     skrll  * the Ethernet frame, this means if the frame is padded with non-zero values
     51       1.1     skrll  * the H/W checksum will be incorrect, however the rx code compensates for this.
     52       1.1     skrll  *
     53       1.1     skrll  * TX checksuming is more complicated, the device requires a special header to
     54       1.1     skrll  * be prefixed onto the start of the frame which indicates the start and end
     55       1.1     skrll  * positions of the UDP or TCP frame.  This requires the driver to manually
     56       1.1     skrll  * go through the packet data and decode the headers prior to sending.
     57       1.1     skrll  * On Linux they generally provide cues to the location of the csum and the
     58       1.1     skrll  * area to calculate it over, on FreeBSD we seem to have to do it all ourselves,
     59       1.8     skrll  * hence this is not as optimal and therefore h/w TX checksum is currently not
     60       1.1     skrll  * implemented.
     61       1.1     skrll  */
     62       1.1     skrll 
     63  1.34.2.1  christos #include <sys/cdefs.h>
     64  1.34.2.2    martin __KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.34.2.2 2020/04/13 08:04:49 martin Exp $");
     65  1.34.2.1  christos 
     66      1.12     skrll #ifdef _KERNEL_OPT
     67      1.20     skrll #include "opt_usb.h"
     68      1.12     skrll #endif
     69       1.1     skrll 
     70       1.1     skrll #include <sys/param.h>
     71       1.1     skrll 
     72  1.34.2.2    martin #include <dev/usb/usbnet.h>
     73  1.34.2.2    martin #include <dev/usb/usbhist.h>
     74       1.1     skrll 
     75       1.1     skrll #include <dev/usb/if_smscreg.h>
     76       1.1     skrll 
     77       1.1     skrll #include "ioconf.h"
     78       1.1     skrll 
     79  1.34.2.2    martin struct smsc_softc {
     80  1.34.2.2    martin 	struct usbnet		smsc_un;
     81  1.34.2.2    martin 
     82  1.34.2.2    martin 	/*
     83  1.34.2.2    martin 	 * The following stores the settings in the mac control (MAC_CSR)
     84  1.34.2.2    martin 	 * register
     85  1.34.2.2    martin 	 */
     86  1.34.2.2    martin 	uint32_t		sc_mac_csr;
     87  1.34.2.2    martin 	uint32_t		sc_rev_id;
     88  1.34.2.2    martin 
     89  1.34.2.2    martin 	uint32_t		sc_coe_ctrl;
     90  1.34.2.2    martin };
     91  1.34.2.2    martin 
     92  1.34.2.2    martin #define SMSC_MIN_BUFSZ		2048
     93  1.34.2.2    martin #define SMSC_MAX_BUFSZ		18944
     94       1.1     skrll 
     95       1.1     skrll /*
     96       1.1     skrll  * Various supported device vendors/products.
     97       1.1     skrll  */
     98       1.1     skrll static const struct usb_devno smsc_devs[] = {
     99       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_LAN89530 },
    100       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_LAN9530 },
    101       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_LAN9730 },
    102       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9500 },
    103       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9500A },
    104       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9500A_ALT },
    105       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9500A_HAL },
    106       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9500A_SAL10 },
    107       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9500_ALT },
    108       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9500_SAL10 },
    109       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9505 },
    110       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9505A },
    111       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9505A_HAL },
    112       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9505A_SAL10 },
    113       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9505_SAL10 },
    114       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9512_14 },
    115       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9512_14_ALT },
    116       1.2  jakllsch 	{ USB_VENDOR_SMSC,	USB_PRODUCT_SMSC_SMSC9512_14_SAL10 }
    117       1.1     skrll };
    118       1.1     skrll 
    119       1.1     skrll #ifdef USB_DEBUG
    120  1.34.2.2    martin #ifndef USMSC_DEBUG
    121  1.34.2.2    martin #define usmscdebug 0
    122       1.1     skrll #else
    123  1.34.2.2    martin static int usmscdebug = 1;
    124  1.34.2.2    martin 
    125  1.34.2.2    martin SYSCTL_SETUP(sysctl_hw_smsc_setup, "sysctl hw.usmsc setup")
    126  1.34.2.2    martin {
    127  1.34.2.2    martin 	int err;
    128  1.34.2.2    martin 	const struct sysctlnode *rnode;
    129  1.34.2.2    martin 	const struct sysctlnode *cnode;
    130  1.34.2.2    martin 
    131  1.34.2.2    martin 	err = sysctl_createv(clog, 0, NULL, &rnode,
    132  1.34.2.2    martin 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "usmsc",
    133  1.34.2.2    martin 	    SYSCTL_DESCR("usmsc global controls"),
    134  1.34.2.2    martin 	    NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
    135  1.34.2.2    martin 
    136  1.34.2.2    martin 	if (err)
    137  1.34.2.2    martin 		goto fail;
    138  1.34.2.2    martin 
    139  1.34.2.2    martin 	/* control debugging printfs */
    140  1.34.2.2    martin 	err = sysctl_createv(clog, 0, &rnode, &cnode,
    141  1.34.2.2    martin 	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT,
    142  1.34.2.2    martin 	    "debug", SYSCTL_DESCR("Enable debugging output"),
    143  1.34.2.2    martin 	    NULL, 0, &usmscdebug, sizeof(usmscdebug), CTL_CREATE, CTL_EOL);
    144  1.34.2.2    martin 	if (err)
    145  1.34.2.2    martin 		goto fail;
    146  1.34.2.2    martin 
    147  1.34.2.2    martin 	return;
    148  1.34.2.2    martin fail:
    149  1.34.2.2    martin 	aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err);
    150  1.34.2.2    martin }
    151       1.1     skrll 
    152  1.34.2.2    martin #endif /* SMSC_DEBUG */
    153  1.34.2.2    martin #endif /* USB_DEBUG */
    154       1.1     skrll 
    155  1.34.2.2    martin #define DPRINTF(FMT,A,B,C,D)	USBHIST_LOG(usmscdebug,FMT,A,B,C,D)
    156  1.34.2.2    martin #define DPRINTFN(N,FMT,A,B,C,D)	USBHIST_LOGN(usmscdebug,N,FMT,A,B,C,D)
    157  1.34.2.2    martin #define USMSCHIST_FUNC()	USBHIST_FUNC()
    158  1.34.2.2    martin #define USMSCHIST_CALLED()	USBHIST_CALLED(usmscdebug)
    159  1.34.2.2    martin 
    160  1.34.2.2    martin #define smsc_warn_printf(un, fmt, args...) \
    161  1.34.2.2    martin 	printf("%s: warning: " fmt, device_xname((un)->un_dev), ##args)
    162  1.34.2.2    martin 
    163  1.34.2.2    martin #define smsc_err_printf(un, fmt, args...) \
    164  1.34.2.2    martin 	printf("%s: error: " fmt, device_xname((un)->un_dev), ##args)
    165       1.1     skrll 
    166       1.1     skrll /* Function declarations */
    167  1.34.2.2    martin static int	 smsc_match(device_t, cfdata_t, void *);
    168  1.34.2.2    martin static void	 smsc_attach(device_t, device_t, void *);
    169  1.34.2.2    martin 
    170  1.34.2.2    martin CFATTACH_DECL_NEW(usmsc, sizeof(struct smsc_softc),
    171  1.34.2.2    martin     smsc_match, smsc_attach, usbnet_detach, usbnet_activate);
    172       1.1     skrll 
    173  1.34.2.2    martin static int	 smsc_chip_init(struct usbnet *);
    174  1.34.2.2    martin static int	 smsc_setmacaddress(struct usbnet *, const uint8_t *);
    175       1.1     skrll 
    176  1.34.2.2    martin static int	 smsc_uno_init(struct ifnet *);
    177  1.34.2.2    martin static int	 smsc_init_locked(struct ifnet *);
    178  1.34.2.2    martin static void	 smsc_uno_stop(struct ifnet *, int);
    179  1.34.2.2    martin 
    180  1.34.2.2    martin static void	 smsc_reset(struct smsc_softc *);
    181  1.34.2.2    martin 
    182  1.34.2.2    martin static void	 smsc_uno_miibus_statchg(struct ifnet *);
    183  1.34.2.2    martin static int	 smsc_readreg(struct usbnet *, uint32_t, uint32_t *);
    184  1.34.2.2    martin static int	 smsc_writereg(struct usbnet *, uint32_t, uint32_t);
    185  1.34.2.2    martin static int	 smsc_wait_for_bits(struct usbnet *, uint32_t, uint32_t);
    186  1.34.2.2    martin static int	 smsc_uno_miibus_readreg(struct usbnet *, int, int, uint16_t *);
    187  1.34.2.2    martin static int	 smsc_uno_miibus_writereg(struct usbnet *, int, int, uint16_t);
    188  1.34.2.2    martin 
    189  1.34.2.2    martin static int	 smsc_uno_ioctl(struct ifnet *, u_long, void *);
    190  1.34.2.2    martin static unsigned	 smsc_uno_tx_prepare(struct usbnet *, struct mbuf *,
    191  1.34.2.2    martin 		     struct usbnet_chain *);
    192  1.34.2.2    martin static void	 smsc_uno_rx_loop(struct usbnet *, struct usbnet_chain *,
    193  1.34.2.2    martin 		     uint32_t);
    194  1.34.2.2    martin 
    195  1.34.2.2    martin static const struct usbnet_ops smsc_ops = {
    196  1.34.2.2    martin 	.uno_stop = smsc_uno_stop,
    197  1.34.2.2    martin 	.uno_ioctl = smsc_uno_ioctl,
    198  1.34.2.2    martin 	.uno_read_reg = smsc_uno_miibus_readreg,
    199  1.34.2.2    martin 	.uno_write_reg = smsc_uno_miibus_writereg,
    200  1.34.2.2    martin 	.uno_statchg = smsc_uno_miibus_statchg,
    201  1.34.2.2    martin 	.uno_tx_prepare = smsc_uno_tx_prepare,
    202  1.34.2.2    martin 	.uno_rx_loop = smsc_uno_rx_loop,
    203  1.34.2.2    martin 	.uno_init = smsc_uno_init,
    204  1.34.2.2    martin };
    205  1.34.2.2    martin 
    206  1.34.2.2    martin static int
    207  1.34.2.2    martin smsc_readreg(struct usbnet *un, uint32_t off, uint32_t *data)
    208       1.1     skrll {
    209       1.1     skrll 	usb_device_request_t req;
    210       1.1     skrll 	uint32_t buf;
    211       1.1     skrll 	usbd_status err;
    212       1.1     skrll 
    213  1.34.2.2    martin 	usbnet_isowned_core(un);
    214  1.34.2.2    martin 
    215  1.34.2.2    martin 	if (usbnet_isdying(un))
    216  1.34.2.2    martin 		return 0;
    217  1.34.2.2    martin 
    218       1.1     skrll 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
    219       1.1     skrll 	req.bRequest = SMSC_UR_READ_REG;
    220       1.1     skrll 	USETW(req.wValue, 0);
    221       1.1     skrll 	USETW(req.wIndex, off);
    222       1.1     skrll 	USETW(req.wLength, 4);
    223       1.1     skrll 
    224  1.34.2.2    martin 	err = usbd_do_request(un->un_udev, &req, &buf);
    225       1.1     skrll 	if (err != 0)
    226  1.34.2.2    martin 		smsc_warn_printf(un, "Failed to read register 0x%0x\n", off);
    227       1.1     skrll 
    228       1.1     skrll 	*data = le32toh(buf);
    229       1.1     skrll 
    230      1.27     skrll 	return err;
    231       1.1     skrll }
    232       1.1     skrll 
    233  1.34.2.2    martin static int
    234  1.34.2.2    martin smsc_writereg(struct usbnet *un, uint32_t off, uint32_t data)
    235       1.1     skrll {
    236       1.1     skrll 	usb_device_request_t req;
    237       1.1     skrll 	uint32_t buf;
    238       1.1     skrll 	usbd_status err;
    239       1.1     skrll 
    240  1.34.2.2    martin 	usbnet_isowned_core(un);
    241  1.34.2.2    martin 
    242  1.34.2.2    martin 	if (usbnet_isdying(un))
    243  1.34.2.2    martin 		return 0;
    244  1.34.2.2    martin 
    245       1.1     skrll 	buf = htole32(data);
    246       1.1     skrll 
    247       1.1     skrll 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
    248       1.1     skrll 	req.bRequest = SMSC_UR_WRITE_REG;
    249       1.1     skrll 	USETW(req.wValue, 0);
    250       1.1     skrll 	USETW(req.wIndex, off);
    251       1.1     skrll 	USETW(req.wLength, 4);
    252       1.1     skrll 
    253  1.34.2.2    martin 	err = usbd_do_request(un->un_udev, &req, &buf);
    254       1.1     skrll 	if (err != 0)
    255  1.34.2.2    martin 		smsc_warn_printf(un, "Failed to write register 0x%0x\n", off);
    256       1.1     skrll 
    257      1.27     skrll 	return err;
    258       1.1     skrll }
    259       1.1     skrll 
    260  1.34.2.2    martin static int
    261  1.34.2.2    martin smsc_wait_for_bits(struct usbnet *un, uint32_t reg, uint32_t bits)
    262       1.1     skrll {
    263       1.1     skrll 	uint32_t val;
    264       1.1     skrll 	int err, i;
    265       1.1     skrll 
    266       1.1     skrll 	for (i = 0; i < 100; i++) {
    267  1.34.2.2    martin 		if ((err = smsc_readreg(un, reg, &val)) != 0)
    268      1.27     skrll 			return err;
    269       1.1     skrll 		if (!(val & bits))
    270      1.27     skrll 			return 0;
    271       1.1     skrll 		DELAY(5);
    272       1.1     skrll 	}
    273       1.1     skrll 
    274      1.27     skrll 	return 1;
    275       1.1     skrll }
    276       1.1     skrll 
    277  1.34.2.2    martin static int
    278  1.34.2.2    martin smsc_uno_miibus_readreg(struct usbnet *un, int phy, int reg, uint16_t *val)
    279       1.1     skrll {
    280       1.1     skrll 	uint32_t addr;
    281  1.34.2.1  christos 	uint32_t data = 0;
    282       1.1     skrll 
    283  1.34.2.2    martin 	if (un->un_phyno != phy)
    284  1.34.2.2    martin 		return EINVAL;
    285  1.34.2.2    martin 
    286  1.34.2.2    martin 	if (smsc_wait_for_bits(un, SMSC_MII_ADDR, SMSC_MII_BUSY) != 0) {
    287  1.34.2.2    martin 		smsc_warn_printf(un, "MII is busy\n");
    288  1.34.2.2    martin 		return ETIMEDOUT;
    289       1.1     skrll 	}
    290       1.1     skrll 
    291       1.1     skrll 	addr = (phy << 11) | (reg << 6) | SMSC_MII_READ;
    292  1.34.2.2    martin 	smsc_writereg(un, SMSC_MII_ADDR, addr);
    293       1.1     skrll 
    294  1.34.2.2    martin 	if (smsc_wait_for_bits(un, SMSC_MII_ADDR, SMSC_MII_BUSY) != 0) {
    295  1.34.2.2    martin 		smsc_warn_printf(un, "MII read timeout\n");
    296  1.34.2.2    martin 		return ETIMEDOUT;
    297  1.34.2.1  christos 	}
    298       1.1     skrll 
    299  1.34.2.2    martin 	smsc_readreg(un, SMSC_MII_DATA, &data);
    300       1.1     skrll 
    301  1.34.2.1  christos 	*val = data & 0xffff;
    302  1.34.2.2    martin 	return 0;
    303       1.1     skrll }
    304       1.1     skrll 
    305  1.34.2.2    martin static int
    306  1.34.2.2    martin smsc_uno_miibus_writereg(struct usbnet *un, int phy, int reg, uint16_t val)
    307       1.1     skrll {
    308       1.1     skrll 	uint32_t addr;
    309       1.1     skrll 
    310  1.34.2.2    martin 	if (un->un_phyno != phy)
    311  1.34.2.2    martin 		return EINVAL;
    312       1.1     skrll 
    313  1.34.2.2    martin 	if (smsc_wait_for_bits(un, SMSC_MII_ADDR, SMSC_MII_BUSY) != 0) {
    314  1.34.2.2    martin 		smsc_warn_printf(un, "MII is busy\n");
    315  1.34.2.2    martin 		return ETIMEDOUT;
    316       1.1     skrll 	}
    317       1.1     skrll 
    318  1.34.2.2    martin 	smsc_writereg(un, SMSC_MII_DATA, val);
    319       1.1     skrll 
    320       1.1     skrll 	addr = (phy << 11) | (reg << 6) | SMSC_MII_WRITE;
    321  1.34.2.2    martin 	smsc_writereg(un, SMSC_MII_ADDR, addr);
    322       1.1     skrll 
    323  1.34.2.2    martin 	if (smsc_wait_for_bits(un, SMSC_MII_ADDR, SMSC_MII_BUSY) != 0) {
    324  1.34.2.2    martin 		smsc_warn_printf(un, "MII write timeout\n");
    325  1.34.2.1  christos 		return ETIMEDOUT;
    326  1.34.2.1  christos 	}
    327  1.34.2.1  christos 
    328  1.34.2.1  christos 	return 0;
    329       1.1     skrll }
    330       1.1     skrll 
    331  1.34.2.2    martin static void
    332  1.34.2.2    martin smsc_uno_miibus_statchg(struct ifnet *ifp)
    333       1.1     skrll {
    334  1.34.2.2    martin 	USMSCHIST_FUNC(); USMSCHIST_CALLED();
    335  1.34.2.2    martin 	struct usbnet * const un = ifp->if_softc;
    336  1.34.2.1  christos 
    337  1.34.2.2    martin 	if (usbnet_isdying(un))
    338  1.34.2.1  christos 		return;
    339  1.34.2.1  christos 
    340  1.34.2.2    martin 	struct smsc_softc * const sc = usbnet_softc(un);
    341  1.34.2.2    martin 	struct mii_data * const mii = usbnet_mii(un);
    342       1.1     skrll 	uint32_t flow;
    343       1.1     skrll 	uint32_t afc_cfg;
    344       1.1     skrll 
    345       1.1     skrll 	if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
    346       1.1     skrll 	    (IFM_ACTIVE | IFM_AVALID)) {
    347       1.1     skrll 		switch (IFM_SUBTYPE(mii->mii_media_active)) {
    348       1.1     skrll 			case IFM_10_T:
    349       1.1     skrll 			case IFM_100_TX:
    350  1.34.2.2    martin 				usbnet_set_link(un, true);
    351       1.1     skrll 				break;
    352       1.1     skrll 			case IFM_1000_T:
    353       1.1     skrll 				/* Gigabit ethernet not supported by chipset */
    354       1.1     skrll 				break;
    355       1.1     skrll 			default:
    356       1.1     skrll 				break;
    357       1.1     skrll 		}
    358       1.1     skrll 	}
    359       1.1     skrll 
    360       1.1     skrll 	/* Lost link, do nothing. */
    361  1.34.2.2    martin 	if (!usbnet_havelink(un))
    362       1.1     skrll 		return;
    363       1.1     skrll 
    364  1.34.2.2    martin 	int err = smsc_readreg(un, SMSC_AFC_CFG, &afc_cfg);
    365       1.1     skrll 	if (err) {
    366  1.34.2.2    martin 		smsc_warn_printf(un, "failed to read initial AFC_CFG, "
    367       1.1     skrll 		    "error %d\n", err);
    368       1.1     skrll 		return;
    369       1.1     skrll 	}
    370       1.1     skrll 
    371       1.1     skrll 	/* Enable/disable full duplex operation and TX/RX pause */
    372       1.1     skrll 	if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) {
    373  1.34.2.2    martin 		DPRINTF("full duplex operation", 0, 0, 0, 0);
    374       1.1     skrll 		sc->sc_mac_csr &= ~SMSC_MAC_CSR_RCVOWN;
    375       1.1     skrll 		sc->sc_mac_csr |= SMSC_MAC_CSR_FDPX;
    376       1.1     skrll 
    377       1.1     skrll 		if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_RXPAUSE) != 0)
    378       1.1     skrll 			flow = 0xffff0002;
    379       1.1     skrll 		else
    380       1.1     skrll 			flow = 0;
    381       1.1     skrll 
    382       1.1     skrll 		if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_TXPAUSE) != 0)
    383       1.1     skrll 			afc_cfg |= 0xf;
    384       1.1     skrll 		else
    385       1.1     skrll 			afc_cfg &= ~0xf;
    386       1.1     skrll 	} else {
    387  1.34.2.2    martin 		DPRINTF("half duplex operation", 0, 0, 0, 0);
    388       1.1     skrll 		sc->sc_mac_csr &= ~SMSC_MAC_CSR_FDPX;
    389       1.1     skrll 		sc->sc_mac_csr |= SMSC_MAC_CSR_RCVOWN;
    390       1.1     skrll 
    391       1.1     skrll 		flow = 0;
    392       1.1     skrll 		afc_cfg |= 0xf;
    393       1.1     skrll 	}
    394       1.1     skrll 
    395  1.34.2.2    martin 	err = smsc_writereg(un, SMSC_MAC_CSR, sc->sc_mac_csr);
    396  1.34.2.2    martin 	err += smsc_writereg(un, SMSC_FLOW, flow);
    397  1.34.2.2    martin 	err += smsc_writereg(un, SMSC_AFC_CFG, afc_cfg);
    398  1.34.2.1  christos 
    399  1.34.2.2    martin 	if (err)
    400  1.34.2.2    martin 		smsc_warn_printf(un, "media change failed, error %d\n", err);
    401       1.1     skrll }
    402       1.1     skrll 
    403       1.1     skrll static inline uint32_t
    404       1.1     skrll smsc_hash(uint8_t addr[ETHER_ADDR_LEN])
    405       1.1     skrll {
    406      1.32     skrll 
    407       1.1     skrll 	return (ether_crc32_be(addr, ETHER_ADDR_LEN) >> 26) & 0x3f;
    408       1.1     skrll }
    409       1.1     skrll 
    410  1.34.2.2    martin static void
    411  1.34.2.2    martin smsc_setiff_locked(struct usbnet *un)
    412       1.1     skrll {
    413  1.34.2.2    martin 	USMSCHIST_FUNC(); USMSCHIST_CALLED();
    414  1.34.2.2    martin 	struct smsc_softc * const sc = usbnet_softc(un);
    415  1.34.2.2    martin 	struct ifnet * const ifp = usbnet_ifp(un);
    416  1.34.2.2    martin 	struct ethercom *ec = usbnet_ec(un);
    417  1.34.2.1  christos 	struct ether_multi *enm;
    418  1.34.2.1  christos 	struct ether_multistep step;
    419  1.34.2.1  christos 	uint32_t hashtbl[2] = { 0, 0 };
    420  1.34.2.1  christos 	uint32_t hash;
    421  1.34.2.1  christos 
    422  1.34.2.2    martin 	usbnet_isowned_core(un);
    423       1.1     skrll 
    424  1.34.2.2    martin 	if (usbnet_isdying(un))
    425       1.1     skrll 		return;
    426       1.1     skrll 
    427       1.1     skrll 	if (ifp->if_flags & (IFF_ALLMULTI | IFF_PROMISC)) {
    428       1.1     skrll allmulti:
    429  1.34.2.2    martin 		DPRINTF("receive all multicast enabled", 0, 0, 0, 0);
    430       1.1     skrll 		sc->sc_mac_csr |= SMSC_MAC_CSR_MCPAS;
    431       1.1     skrll 		sc->sc_mac_csr &= ~SMSC_MAC_CSR_HPFILT;
    432  1.34.2.2    martin 		smsc_writereg(un, SMSC_MAC_CSR, sc->sc_mac_csr);
    433       1.1     skrll 		return;
    434       1.1     skrll 	} else {
    435       1.1     skrll 		sc->sc_mac_csr |= SMSC_MAC_CSR_HPFILT;
    436       1.1     skrll 		sc->sc_mac_csr &= ~(SMSC_MAC_CSR_PRMS | SMSC_MAC_CSR_MCPAS);
    437       1.1     skrll 	}
    438       1.1     skrll 
    439  1.34.2.1  christos 	ETHER_LOCK(ec);
    440  1.34.2.1  christos 	ETHER_FIRST_MULTI(step, ec, enm);
    441       1.1     skrll 	while (enm != NULL) {
    442  1.34.2.1  christos 		if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
    443  1.34.2.1  christos 			ETHER_UNLOCK(ec);
    444       1.1     skrll 			goto allmulti;
    445  1.34.2.1  christos 		}
    446       1.1     skrll 
    447       1.1     skrll 		hash = smsc_hash(enm->enm_addrlo);
    448       1.1     skrll 		hashtbl[hash >> 5] |= 1 << (hash & 0x1F);
    449       1.1     skrll 		ETHER_NEXT_MULTI(step, enm);
    450       1.1     skrll 	}
    451  1.34.2.1  christos 	ETHER_UNLOCK(ec);
    452       1.1     skrll 
    453       1.1     skrll 	/* Debug */
    454       1.1     skrll 	if (sc->sc_mac_csr & SMSC_MAC_CSR_HPFILT) {
    455  1.34.2.2    martin 		DPRINTF("receive select group of macs", 0, 0, 0, 0);
    456       1.1     skrll 	} else {
    457  1.34.2.2    martin 		DPRINTF("receive own packets only", 0, 0, 0, 0);
    458       1.1     skrll 	}
    459       1.1     skrll 
    460       1.1     skrll 	/* Write the hash table and mac control registers */
    461  1.34.2.2    martin 
    462  1.34.2.2    martin 	//XXX should we be doing this?
    463       1.1     skrll 	ifp->if_flags &= ~IFF_ALLMULTI;
    464  1.34.2.2    martin 	smsc_writereg(un, SMSC_HASHH, hashtbl[1]);
    465  1.34.2.2    martin 	smsc_writereg(un, SMSC_HASHL, hashtbl[0]);
    466  1.34.2.2    martin 	smsc_writereg(un, SMSC_MAC_CSR, sc->sc_mac_csr);
    467       1.1     skrll }
    468       1.1     skrll 
    469  1.34.2.2    martin static int
    470  1.34.2.2    martin smsc_setoe_locked(struct usbnet *un)
    471       1.1     skrll {
    472  1.34.2.2    martin 	struct smsc_softc * const sc = usbnet_softc(un);
    473  1.34.2.2    martin 	struct ifnet * const ifp = usbnet_ifp(un);
    474       1.1     skrll 	uint32_t val;
    475       1.1     skrll 	int err;
    476       1.1     skrll 
    477  1.34.2.2    martin 	usbnet_isowned_core(un);
    478  1.34.2.2    martin 
    479  1.34.2.2    martin 	err = smsc_readreg(un, SMSC_COE_CTRL, &val);
    480       1.1     skrll 	if (err != 0) {
    481  1.34.2.2    martin 		smsc_warn_printf(un, "failed to read SMSC_COE_CTRL (err=%d)\n",
    482       1.1     skrll 		    err);
    483      1.27     skrll 		return err;
    484       1.1     skrll 	}
    485       1.1     skrll 
    486       1.1     skrll 	/* Enable/disable the Rx checksum */
    487  1.34.2.1  christos 	if (ifp->if_capenable & (IFCAP_CSUM_TCPv4_Rx | IFCAP_CSUM_UDPv4_Rx))
    488      1.13   mlelstv 		val |= (SMSC_COE_CTRL_RX_EN | SMSC_COE_CTRL_RX_MODE);
    489       1.1     skrll 	else
    490      1.13   mlelstv 		val &= ~(SMSC_COE_CTRL_RX_EN | SMSC_COE_CTRL_RX_MODE);
    491       1.1     skrll 
    492       1.1     skrll 	/* Enable/disable the Tx checksum (currently not supported) */
    493  1.34.2.1  christos 	if (ifp->if_capenable & (IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_UDPv4_Tx))
    494       1.1     skrll 		val |= SMSC_COE_CTRL_TX_EN;
    495       1.1     skrll 	else
    496       1.1     skrll 		val &= ~SMSC_COE_CTRL_TX_EN;
    497       1.1     skrll 
    498      1.13   mlelstv 	sc->sc_coe_ctrl = val;
    499      1.13   mlelstv 
    500  1.34.2.2    martin 	err = smsc_writereg(un, SMSC_COE_CTRL, val);
    501       1.1     skrll 	if (err != 0) {
    502  1.34.2.2    martin 		smsc_warn_printf(un, "failed to write SMSC_COE_CTRL (err=%d)\n",
    503       1.1     skrll 		    err);
    504      1.27     skrll 		return err;
    505       1.1     skrll 	}
    506       1.1     skrll 
    507      1.27     skrll 	return 0;
    508       1.1     skrll }
    509       1.1     skrll 
    510  1.34.2.2    martin static int
    511  1.34.2.2    martin smsc_setmacaddress(struct usbnet *un, const uint8_t *addr)
    512       1.1     skrll {
    513  1.34.2.2    martin 	USMSCHIST_FUNC(); USMSCHIST_CALLED();
    514       1.1     skrll 	int err;
    515       1.1     skrll 	uint32_t val;
    516       1.1     skrll 
    517  1.34.2.2    martin 	DPRINTF("setting mac address to %02jx:%02jx:%02jx:...", addr[0],
    518  1.34.2.2    martin 	    addr[1], addr[2], 0);
    519  1.34.2.2    martin 
    520  1.34.2.2    martin 	DPRINTF("... %02jx:%02jx:%02jx", addr[3], addr[4], addr[5], 0);
    521       1.1     skrll 
    522  1.34.2.2    martin 	val = ((uint32_t)addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8)
    523  1.34.2.2    martin 	    | addr[0];
    524  1.34.2.2    martin 	if ((err = smsc_writereg(un, SMSC_MAC_ADDRL, val)) != 0)
    525       1.1     skrll 		goto done;
    526       1.1     skrll 
    527       1.1     skrll 	val = (addr[5] << 8) | addr[4];
    528  1.34.2.2    martin 	err = smsc_writereg(un, SMSC_MAC_ADDRH, val);
    529       1.1     skrll 
    530       1.1     skrll done:
    531      1.27     skrll 	return err;
    532       1.1     skrll }
    533       1.1     skrll 
    534  1.34.2.2    martin static void
    535       1.1     skrll smsc_reset(struct smsc_softc *sc)
    536       1.1     skrll {
    537  1.34.2.2    martin 	struct usbnet * const un = &sc->smsc_un;
    538  1.34.2.2    martin 
    539  1.34.2.2    martin 	usbnet_isowned_core(un);
    540  1.34.2.2    martin 	if (usbnet_isdying(un))
    541       1.1     skrll 		return;
    542       1.1     skrll 
    543       1.1     skrll 	/* Wait a little while for the chip to get its brains in order. */
    544       1.1     skrll 	DELAY(1000);
    545       1.1     skrll 
    546       1.1     skrll 	/* Reinitialize controller to achieve full reset. */
    547  1.34.2.2    martin 	smsc_chip_init(un);
    548       1.1     skrll }
    549       1.1     skrll 
    550  1.34.2.2    martin static int
    551  1.34.2.2    martin smsc_uno_init(struct ifnet *ifp)
    552       1.1     skrll {
    553  1.34.2.2    martin 	struct usbnet * const un = ifp->if_softc;
    554  1.34.2.1  christos 
    555  1.34.2.2    martin 	usbnet_lock_core(un);
    556  1.34.2.2    martin 	usbnet_busy(un);
    557  1.34.2.1  christos 	int ret = smsc_init_locked(ifp);
    558  1.34.2.2    martin 	usbnet_unbusy(un);
    559  1.34.2.2    martin 	usbnet_unlock_core(un);
    560  1.34.2.1  christos 
    561  1.34.2.1  christos 	return ret;
    562  1.34.2.1  christos }
    563  1.34.2.1  christos 
    564  1.34.2.2    martin static int
    565  1.34.2.1  christos smsc_init_locked(struct ifnet *ifp)
    566  1.34.2.1  christos {
    567  1.34.2.2    martin 	struct usbnet * const un = ifp->if_softc;
    568  1.34.2.2    martin 	struct smsc_softc * const sc = usbnet_softc(un);
    569  1.34.2.2    martin 
    570  1.34.2.2    martin 	usbnet_isowned_core(un);
    571       1.1     skrll 
    572  1.34.2.2    martin 	if (usbnet_isdying(un))
    573       1.1     skrll 		return EIO;
    574       1.1     skrll 
    575       1.1     skrll 	/* Cancel pending I/O */
    576  1.34.2.2    martin 	usbnet_stop(un, ifp, 1);
    577       1.1     skrll 
    578       1.1     skrll 	/* Reset the ethernet interface. */
    579       1.1     skrll 	smsc_reset(sc);
    580       1.1     skrll 
    581       1.1     skrll 	/* Load the multicast filter. */
    582  1.34.2.2    martin 	smsc_setiff_locked(un);
    583       1.9  christos 
    584      1.13   mlelstv 	/* TCP/UDP checksum offload engines. */
    585  1.34.2.2    martin 	smsc_setoe_locked(un);
    586      1.13   mlelstv 
    587  1.34.2.2    martin 	return usbnet_init_rx_tx(un);
    588       1.1     skrll }
    589       1.1     skrll 
    590  1.34.2.2    martin static void
    591  1.34.2.2    martin smsc_uno_stop(struct ifnet *ifp, int disable)
    592       1.1     skrll {
    593  1.34.2.2    martin 	struct usbnet * const un = ifp->if_softc;
    594  1.34.2.2    martin 	struct smsc_softc * const sc = usbnet_softc(un);
    595  1.34.2.1  christos 
    596  1.34.2.2    martin 	// XXXNH didn't do this before
    597  1.34.2.2    martin 	smsc_reset(sc);
    598       1.1     skrll }
    599       1.1     skrll 
    600  1.34.2.2    martin static int
    601  1.34.2.2    martin smsc_chip_init(struct usbnet *un)
    602       1.1     skrll {
    603  1.34.2.2    martin 	struct smsc_softc * const sc = usbnet_softc(un);
    604       1.1     skrll 	uint32_t reg_val;
    605       1.1     skrll 	int burst_cap;
    606  1.34.2.2    martin 	int err;
    607  1.34.2.2    martin 
    608  1.34.2.2    martin 	usbnet_isowned_core(un);
    609       1.1     skrll 
    610       1.1     skrll 	/* Enter H/W config mode */
    611  1.34.2.2    martin 	smsc_writereg(un, SMSC_HW_CFG, SMSC_HW_CFG_LRST);
    612       1.1     skrll 
    613  1.34.2.2    martin 	if ((err = smsc_wait_for_bits(un, SMSC_HW_CFG,
    614       1.1     skrll 	    SMSC_HW_CFG_LRST)) != 0) {
    615  1.34.2.2    martin 		smsc_warn_printf(un, "timed-out waiting for reset to "
    616       1.1     skrll 		    "complete\n");
    617       1.1     skrll 		goto init_failed;
    618       1.1     skrll 	}
    619       1.1     skrll 
    620       1.1     skrll 	/* Reset the PHY */
    621  1.34.2.2    martin 	smsc_writereg(un, SMSC_PM_CTRL, SMSC_PM_CTRL_PHY_RST);
    622       1.1     skrll 
    623  1.34.2.2    martin 	if ((err = smsc_wait_for_bits(un, SMSC_PM_CTRL,
    624      1.26     skrll 	    SMSC_PM_CTRL_PHY_RST)) != 0) {
    625  1.34.2.2    martin 		smsc_warn_printf(un, "timed-out waiting for phy reset to "
    626       1.1     skrll 		    "complete\n");
    627       1.1     skrll 		goto init_failed;
    628       1.1     skrll 	}
    629  1.34.2.2    martin 	usbd_delay_ms(un->un_udev, 40);
    630       1.1     skrll 
    631       1.1     skrll 	/* Set the mac address */
    632  1.34.2.2    martin 	struct ifnet * const ifp = usbnet_ifp(un);
    633      1.11     skrll 	const char *eaddr = CLLADDR(ifp->if_sadl);
    634  1.34.2.2    martin 	if ((err = smsc_setmacaddress(un, eaddr)) != 0) {
    635  1.34.2.2    martin 		smsc_warn_printf(un, "failed to set the MAC address\n");
    636       1.1     skrll 		goto init_failed;
    637       1.1     skrll 	}
    638       1.1     skrll 
    639       1.1     skrll 	/*
    640       1.1     skrll 	 * Don't know what the HW_CFG_BIR bit is, but following the reset
    641       1.1     skrll 	 * sequence as used in the Linux driver.
    642       1.1     skrll 	 */
    643  1.34.2.2    martin 	if ((err = smsc_readreg(un, SMSC_HW_CFG, &reg_val)) != 0) {
    644  1.34.2.2    martin 		smsc_warn_printf(un, "failed to read HW_CFG: %d\n", err);
    645       1.1     skrll 		goto init_failed;
    646       1.1     skrll 	}
    647       1.1     skrll 	reg_val |= SMSC_HW_CFG_BIR;
    648  1.34.2.2    martin 	smsc_writereg(un, SMSC_HW_CFG, reg_val);
    649       1.1     skrll 
    650       1.1     skrll 	/*
    651       1.1     skrll 	 * There is a so called 'turbo mode' that the linux driver supports, it
    652       1.1     skrll 	 * seems to allow you to jam multiple frames per Rx transaction.
    653       1.1     skrll 	 * By default this driver supports that and therefore allows multiple
    654       1.8     skrll 	 * frames per USB transfer.
    655       1.1     skrll 	 *
    656       1.1     skrll 	 * The xfer buffer size needs to reflect this as well, therefore based
    657       1.1     skrll 	 * on the calculations in the Linux driver the RX bufsize is set to
    658       1.1     skrll 	 * 18944,
    659       1.1     skrll 	 *     bufsz = (16 * 1024 + 5 * 512)
    660       1.1     skrll 	 *
    661       1.1     skrll 	 * Burst capability is the number of URBs that can be in a burst of
    662       1.1     skrll 	 * data/ethernet frames.
    663       1.1     skrll 	 */
    664      1.13   mlelstv 
    665  1.34.2.2    martin 	if (un->un_udev->ud_speed == USB_SPEED_HIGH)
    666       1.1     skrll 		burst_cap = 37;
    667       1.1     skrll 	else
    668       1.1     skrll 		burst_cap = 128;
    669       1.1     skrll 
    670  1.34.2.2    martin 	smsc_writereg(un, SMSC_BURST_CAP, burst_cap);
    671       1.1     skrll 
    672       1.1     skrll 	/* Set the default bulk in delay (magic value from Linux driver) */
    673  1.34.2.2    martin 	smsc_writereg(un, SMSC_BULK_IN_DLY, 0x00002000);
    674       1.1     skrll 
    675       1.1     skrll 	/*
    676       1.1     skrll 	 * Initialise the RX interface
    677       1.1     skrll 	 */
    678  1.34.2.2    martin 	if ((err = smsc_readreg(un, SMSC_HW_CFG, &reg_val)) < 0) {
    679  1.34.2.2    martin 		smsc_warn_printf(un, "failed to read HW_CFG: (err = %d)\n",
    680       1.1     skrll 		    err);
    681       1.1     skrll 		goto init_failed;
    682       1.1     skrll 	}
    683       1.1     skrll 
    684       1.1     skrll 	/*
    685       1.8     skrll 	 * The following settings are used for 'turbo mode', a.k.a multiple
    686       1.1     skrll 	 * frames per Rx transaction (again info taken form Linux driver).
    687       1.1     skrll 	 */
    688      1.14     skrll 	reg_val |= (SMSC_HW_CFG_MEF | SMSC_HW_CFG_BCE);
    689      1.13   mlelstv 
    690      1.18     skrll 	/*
    691      1.13   mlelstv 	 * set Rx data offset to ETHER_ALIGN which will make the IP header
    692      1.13   mlelstv 	 * align on a word boundary.
    693      1.18     skrll 	 */
    694      1.13   mlelstv 	reg_val |= ETHER_ALIGN << SMSC_HW_CFG_RXDOFF_SHIFT;
    695       1.1     skrll 
    696  1.34.2.2    martin 	smsc_writereg(un, SMSC_HW_CFG, reg_val);
    697       1.1     skrll 
    698       1.1     skrll 	/* Clear the status register ? */
    699  1.34.2.2    martin 	smsc_writereg(un, SMSC_INTR_STATUS, 0xffffffff);
    700       1.1     skrll 
    701       1.1     skrll 	/* Read and display the revision register */
    702  1.34.2.2    martin 	if ((err = smsc_readreg(un, SMSC_ID_REV, &sc->sc_rev_id)) < 0) {
    703  1.34.2.2    martin 		smsc_warn_printf(un, "failed to read ID_REV (err = %d)\n", err);
    704       1.1     skrll 		goto init_failed;
    705       1.1     skrll 	}
    706       1.1     skrll 
    707       1.1     skrll 	/* GPIO/LED setup */
    708       1.1     skrll 	reg_val = SMSC_LED_GPIO_CFG_SPD_LED | SMSC_LED_GPIO_CFG_LNK_LED |
    709       1.1     skrll 	    SMSC_LED_GPIO_CFG_FDX_LED;
    710  1.34.2.2    martin 	smsc_writereg(un, SMSC_LED_GPIO_CFG, reg_val);
    711       1.1     skrll 
    712       1.1     skrll 	/*
    713       1.1     skrll 	 * Initialise the TX interface
    714       1.1     skrll 	 */
    715  1.34.2.2    martin 	smsc_writereg(un, SMSC_FLOW, 0);
    716       1.1     skrll 
    717  1.34.2.2    martin 	smsc_writereg(un, SMSC_AFC_CFG, AFC_CFG_DEFAULT);
    718       1.1     skrll 
    719       1.1     skrll 	/* Read the current MAC configuration */
    720  1.34.2.2    martin 	if ((err = smsc_readreg(un, SMSC_MAC_CSR, &sc->sc_mac_csr)) < 0) {
    721  1.34.2.2    martin 		smsc_warn_printf(un, "failed to read MAC_CSR (err=%d)\n", err);
    722       1.1     skrll 		goto init_failed;
    723       1.1     skrll 	}
    724       1.1     skrll 
    725      1.13   mlelstv 	/* disable pad stripping, collides with checksum offload */
    726      1.13   mlelstv 	sc->sc_mac_csr &= ~SMSC_MAC_CSR_PADSTR;
    727      1.13   mlelstv 
    728       1.1     skrll 	/* Vlan */
    729  1.34.2.2    martin 	smsc_writereg(un, SMSC_VLAN1, (uint32_t)ETHERTYPE_VLAN);
    730       1.1     skrll 
    731       1.1     skrll 	/*
    732       1.1     skrll 	 * Start TX
    733       1.1     skrll 	 */
    734       1.1     skrll 	sc->sc_mac_csr |= SMSC_MAC_CSR_TXEN;
    735  1.34.2.2    martin 	smsc_writereg(un, SMSC_MAC_CSR, sc->sc_mac_csr);
    736  1.34.2.2    martin 	smsc_writereg(un, SMSC_TX_CFG, SMSC_TX_CFG_ON);
    737       1.1     skrll 
    738       1.1     skrll 	/*
    739       1.1     skrll 	 * Start RX
    740       1.1     skrll 	 */
    741       1.1     skrll 	sc->sc_mac_csr |= SMSC_MAC_CSR_RXEN;
    742  1.34.2.2    martin 	smsc_writereg(un, SMSC_MAC_CSR, sc->sc_mac_csr);
    743       1.1     skrll 
    744      1.27     skrll 	return 0;
    745       1.1     skrll 
    746       1.1     skrll init_failed:
    747  1.34.2.2    martin 	smsc_err_printf(un, "smsc_chip_init failed (err=%d)\n", err);
    748      1.27     skrll 	return err;
    749       1.1     skrll }
    750       1.1     skrll 
    751  1.34.2.1  christos static int
    752  1.34.2.2    martin smsc_uno_ioctl(struct ifnet *ifp, u_long cmd, void *data)
    753       1.1     skrll {
    754  1.34.2.2    martin 	struct usbnet * const un = ifp->if_softc;
    755       1.1     skrll 
    756  1.34.2.2    martin 	usbnet_lock_core(un);
    757  1.34.2.2    martin 	usbnet_busy(un);
    758  1.34.2.1  christos 
    759  1.34.2.2    martin 	switch (cmd) {
    760  1.34.2.2    martin 	case SIOCSIFFLAGS:
    761  1.34.2.2    martin 	case SIOCSETHERCAP:
    762  1.34.2.2    martin 	case SIOCADDMULTI:
    763  1.34.2.2    martin 	case SIOCDELMULTI:
    764  1.34.2.2    martin 		smsc_setiff_locked(un);
    765  1.34.2.2    martin 		break;
    766  1.34.2.2    martin 	case SIOCSIFCAP:
    767  1.34.2.2    martin 		smsc_setoe_locked(un);
    768  1.34.2.2    martin 		break;
    769  1.34.2.2    martin 	default:
    770  1.34.2.2    martin 		break;
    771  1.34.2.1  christos 	}
    772       1.1     skrll 
    773  1.34.2.2    martin 	usbnet_unbusy(un);
    774  1.34.2.2    martin 	usbnet_unlock_core(un);
    775       1.1     skrll 
    776  1.34.2.1  christos 	return 0;
    777  1.34.2.1  christos }
    778       1.1     skrll 
    779  1.34.2.2    martin static int
    780       1.1     skrll smsc_match(device_t parent, cfdata_t match, void *aux)
    781       1.1     skrll {
    782       1.1     skrll 	struct usb_attach_arg *uaa = aux;
    783       1.1     skrll 
    784      1.27     skrll 	return (usb_lookup(smsc_devs, uaa->uaa_vendor, uaa->uaa_product) != NULL) ?
    785       1.1     skrll 	    UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
    786       1.1     skrll }
    787       1.1     skrll 
    788  1.34.2.2    martin static void
    789       1.1     skrll smsc_attach(device_t parent, device_t self, void *aux)
    790       1.1     skrll {
    791  1.34.2.2    martin 	USBNET_MII_DECL_DEFAULT(unm);
    792  1.34.2.2    martin 	struct smsc_softc * const sc = device_private(self);
    793  1.34.2.2    martin 	struct usbnet * const un = &sc->smsc_un;
    794       1.1     skrll 	struct usb_attach_arg *uaa = aux;
    795      1.27     skrll 	struct usbd_device *dev = uaa->uaa_device;
    796       1.1     skrll 	usb_interface_descriptor_t *id;
    797       1.1     skrll 	usb_endpoint_descriptor_t *ed;
    798       1.1     skrll 	char *devinfop;
    799  1.34.2.2    martin 	unsigned bufsz;
    800  1.34.2.1  christos 	int err, i;
    801       1.1     skrll 	uint32_t mac_h, mac_l;
    802       1.1     skrll 
    803  1.34.2.2    martin 	KASSERT((void *)sc == un);
    804       1.1     skrll 
    805       1.1     skrll 	aprint_naive("\n");
    806       1.1     skrll 	aprint_normal("\n");
    807       1.1     skrll 
    808  1.34.2.2    martin 	un->un_dev = self;
    809  1.34.2.2    martin 	un->un_udev = dev;
    810  1.34.2.2    martin 	un->un_sc = sc;
    811  1.34.2.2    martin 	un->un_ops = &smsc_ops;
    812  1.34.2.2    martin 	un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
    813  1.34.2.2    martin 	un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
    814  1.34.2.2    martin 	un->un_rx_list_cnt = SMSC_RX_LIST_CNT;
    815  1.34.2.2    martin 	un->un_tx_list_cnt = SMSC_TX_LIST_CNT;
    816  1.34.2.2    martin 
    817  1.34.2.2    martin 	devinfop = usbd_devinfo_alloc(un->un_udev, 0);
    818       1.1     skrll 	aprint_normal_dev(self, "%s\n", devinfop);
    819       1.1     skrll 	usbd_devinfo_free(devinfop);
    820       1.1     skrll 
    821       1.1     skrll 	err = usbd_set_config_no(dev, SMSC_CONFIG_INDEX, 1);
    822       1.1     skrll 	if (err) {
    823       1.1     skrll 		aprint_error_dev(self, "failed to set configuration"
    824       1.1     skrll 		    ", err=%s\n", usbd_errstr(err));
    825       1.1     skrll 		return;
    826       1.1     skrll 	}
    827       1.1     skrll 
    828  1.34.2.1  christos 	/* Setup the endpoints for the SMSC LAN95xx device(s) */
    829  1.34.2.2    martin 	err = usbd_device2interface_handle(dev, SMSC_IFACE_IDX, &un->un_iface);
    830       1.1     skrll 	if (err) {
    831       1.1     skrll 		aprint_error_dev(self, "getting interface handle failed\n");
    832       1.1     skrll 		return;
    833       1.1     skrll 	}
    834       1.1     skrll 
    835  1.34.2.2    martin 	id = usbd_get_interface_descriptor(un->un_iface);
    836       1.1     skrll 
    837  1.34.2.2    martin 	if (dev->ud_speed >= USB_SPEED_HIGH) {
    838  1.34.2.2    martin 		bufsz = SMSC_MAX_BUFSZ;
    839  1.34.2.2    martin 	} else {
    840  1.34.2.2    martin 		bufsz = SMSC_MIN_BUFSZ;
    841  1.34.2.2    martin 	}
    842  1.34.2.2    martin 	un->un_rx_bufsz = bufsz;
    843  1.34.2.2    martin 	un->un_tx_bufsz = bufsz;
    844       1.1     skrll 
    845       1.1     skrll 	/* Find endpoints. */
    846       1.1     skrll 	for (i = 0; i < id->bNumEndpoints; i++) {
    847  1.34.2.2    martin 		ed = usbd_interface2endpoint_descriptor(un->un_iface, i);
    848       1.1     skrll 		if (!ed) {
    849       1.1     skrll 			aprint_error_dev(self, "couldn't get ep %d\n", i);
    850       1.1     skrll 			return;
    851       1.1     skrll 		}
    852       1.1     skrll 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    853       1.1     skrll 		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
    854  1.34.2.2    martin 			un->un_ed[USBNET_ENDPT_RX] = ed->bEndpointAddress;
    855       1.1     skrll 		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
    856       1.1     skrll 			   UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
    857  1.34.2.2    martin 			un->un_ed[USBNET_ENDPT_TX] = ed->bEndpointAddress;
    858  1.34.2.2    martin #if 0 /* not used yet */
    859       1.1     skrll 		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    860       1.1     skrll 			   UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
    861  1.34.2.2    martin 			un->un_ed[USBNET_ENDPT_INTR] = ed->bEndpointAddress;
    862  1.34.2.2    martin #endif
    863       1.1     skrll 		}
    864       1.1     skrll 	}
    865       1.1     skrll 
    866  1.34.2.2    martin 	usbnet_attach(un, "smscdet");
    867       1.1     skrll 
    868      1.13   mlelstv #ifdef notyet
    869      1.13   mlelstv 	/*
    870      1.13   mlelstv 	 * We can do TCPv4, and UDPv4 checksums in hardware.
    871      1.13   mlelstv 	 */
    872  1.34.2.2    martin 	struct ifnet *ifp = usbnet_ifp(un);
    873  1.34.2.2    martin 
    874      1.13   mlelstv 	ifp->if_capabilities |=
    875      1.13   mlelstv 	    /*IFCAP_CSUM_TCPv4_Tx |*/ IFCAP_CSUM_TCPv4_Rx |
    876      1.13   mlelstv 	    /*IFCAP_CSUM_UDPv4_Tx |*/ IFCAP_CSUM_UDPv4_Rx;
    877      1.13   mlelstv #endif
    878  1.34.2.2    martin 	struct ethercom *ec = usbnet_ec(un);
    879  1.34.2.2    martin 	ec->ec_capabilities = ETHERCAP_VLAN_MTU;
    880       1.9  christos 
    881       1.1     skrll 	/* Setup some of the basics */
    882  1.34.2.2    martin 	un->un_phyno = 1;
    883       1.1     skrll 
    884  1.34.2.2    martin 	usbnet_lock_core(un);
    885  1.34.2.2    martin 	usbnet_busy(un);
    886       1.1     skrll 	/*
    887       1.1     skrll 	 * Attempt to get the mac address, if an EEPROM is not attached this
    888       1.1     skrll 	 * will just return FF:FF:FF:FF:FF:FF, so in such cases we invent a MAC
    889       1.1     skrll 	 * address based on urandom.
    890       1.1     skrll 	 */
    891  1.34.2.2    martin 	memset(un->un_eaddr, 0xff, ETHER_ADDR_LEN);
    892       1.1     skrll 
    893       1.1     skrll 	prop_dictionary_t dict = device_properties(self);
    894       1.1     skrll 	prop_data_t eaprop = prop_dictionary_get(dict, "mac-address");
    895       1.1     skrll 
    896       1.1     skrll 	if (eaprop != NULL) {
    897       1.1     skrll 		KASSERT(prop_object_type(eaprop) == PROP_TYPE_DATA);
    898       1.1     skrll 		KASSERT(prop_data_size(eaprop) == ETHER_ADDR_LEN);
    899  1.34.2.2    martin 		memcpy(un->un_eaddr, prop_data_data_nocopy(eaprop),
    900       1.1     skrll 		    ETHER_ADDR_LEN);
    901  1.34.2.1  christos 	} else {
    902  1.34.2.1  christos 		/* Check if there is already a MAC address in the register */
    903  1.34.2.2    martin 		if ((smsc_readreg(un, SMSC_MAC_ADDRL, &mac_l) == 0) &&
    904  1.34.2.2    martin 		    (smsc_readreg(un, SMSC_MAC_ADDRH, &mac_h) == 0)) {
    905  1.34.2.2    martin 			un->un_eaddr[5] = (uint8_t)((mac_h >> 8) & 0xff);
    906  1.34.2.2    martin 			un->un_eaddr[4] = (uint8_t)((mac_h) & 0xff);
    907  1.34.2.2    martin 			un->un_eaddr[3] = (uint8_t)((mac_l >> 24) & 0xff);
    908  1.34.2.2    martin 			un->un_eaddr[2] = (uint8_t)((mac_l >> 16) & 0xff);
    909  1.34.2.2    martin 			un->un_eaddr[1] = (uint8_t)((mac_l >> 8) & 0xff);
    910  1.34.2.2    martin 			un->un_eaddr[0] = (uint8_t)((mac_l) & 0xff);
    911  1.34.2.1  christos 		}
    912       1.1     skrll 	}
    913  1.34.2.2    martin 	usbnet_unbusy(un);
    914  1.34.2.2    martin 	usbnet_unlock_core(un);
    915       1.1     skrll 
    916  1.34.2.2    martin 	usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
    917  1.34.2.2    martin 	    0, &unm);
    918       1.1     skrll }
    919       1.1     skrll 
    920  1.34.2.2    martin static void
    921  1.34.2.2    martin smsc_uno_rx_loop(struct usbnet * un, struct usbnet_chain *c, uint32_t total_len)
    922       1.1     skrll {
    923  1.34.2.2    martin 	USMSCHIST_FUNC(); USMSCHIST_CALLED();
    924  1.34.2.2    martin 	struct smsc_softc * const sc = usbnet_softc(un);
    925  1.34.2.2    martin 	struct ifnet *ifp = usbnet_ifp(un);
    926  1.34.2.2    martin 	uint8_t *buf = c->unc_buf;
    927       1.1     skrll 
    928  1.34.2.2    martin 	DPRINTF("total_len %jd/%#jx", total_len, total_len, 0, 0);
    929      1.13   mlelstv 	while (total_len != 0) {
    930  1.34.2.1  christos 		uint32_t rxhdr;
    931       1.1     skrll 		if (total_len < sizeof(rxhdr)) {
    932  1.34.2.2    martin 			DPRINTF("total_len %jd < sizeof(rxhdr) %jd",
    933  1.34.2.2    martin 			    total_len, sizeof(rxhdr), 0, 0);
    934  1.34.2.2    martin 			if_statinc(ifp, if_ierrors);
    935  1.34.2.2    martin 			return;
    936       1.1     skrll 		}
    937       1.1     skrll 
    938       1.1     skrll 		memcpy(&rxhdr, buf, sizeof(rxhdr));
    939       1.1     skrll 		rxhdr = le32toh(rxhdr);
    940      1.13   mlelstv 		buf += sizeof(rxhdr);
    941       1.1     skrll 		total_len -= sizeof(rxhdr);
    942       1.1     skrll 
    943      1.24   mlelstv 		if (rxhdr & SMSC_RX_STAT_COLLISION)
    944  1.34.2.2    martin 			if_statinc(ifp, if_collisions);
    945      1.24   mlelstv 
    946      1.24   mlelstv 		if (rxhdr & (SMSC_RX_STAT_ERROR
    947  1.34.2.1  christos 			   | SMSC_RX_STAT_LENGTH_ERROR
    948  1.34.2.1  christos 			   | SMSC_RX_STAT_MII_ERROR)) {
    949  1.34.2.2    martin 			DPRINTF("rx error (hdr 0x%08jx)", rxhdr, 0, 0, 0);
    950  1.34.2.2    martin 			if_statinc(ifp, if_ierrors);
    951  1.34.2.2    martin 			return;
    952       1.1     skrll 		}
    953       1.1     skrll 
    954  1.34.2.1  christos 		uint16_t pktlen = (uint16_t)SMSC_RX_STAT_FRM_LENGTH(rxhdr);
    955  1.34.2.2    martin 		DPRINTF("total_len %jd pktlen %jd rxhdr 0x%08jx", total_len,
    956  1.34.2.2    martin 		    pktlen, rxhdr, 0);
    957      1.13   mlelstv 
    958      1.22  jmcneill 		if (pktlen < ETHER_HDR_LEN) {
    959  1.34.2.2    martin 			DPRINTF("pktlen %jd < ETHER_HDR_LEN %jd", pktlen,
    960  1.34.2.2    martin 			    ETHER_HDR_LEN, 0, 0);
    961  1.34.2.2    martin 			if_statinc(ifp, if_ierrors);
    962  1.34.2.2    martin 			return;
    963      1.22  jmcneill 		}
    964      1.22  jmcneill 
    965      1.13   mlelstv 		pktlen += ETHER_ALIGN;
    966      1.13   mlelstv 
    967      1.17   mlelstv 		if (pktlen > MCLBYTES) {
    968  1.34.2.2    martin 			DPRINTF("pktlen %jd > MCLBYTES %jd", pktlen, MCLBYTES, 0,
    969  1.34.2.2    martin 			    0);
    970  1.34.2.2    martin 			if_statinc(ifp, if_ierrors);
    971  1.34.2.2    martin 			return;
    972      1.17   mlelstv 		}
    973      1.17   mlelstv 
    974       1.1     skrll 		if (pktlen > total_len) {
    975  1.34.2.2    martin 			DPRINTF("pktlen %jd > total_len %jd", pktlen, total_len,
    976  1.34.2.2    martin 			    0, 0);
    977  1.34.2.2    martin 			if_statinc(ifp, if_ierrors);
    978  1.34.2.2    martin 			return;
    979       1.1     skrll 		}
    980       1.1     skrll 
    981  1.34.2.2    martin 		uint8_t *pktbuf = buf + ETHER_ALIGN;
    982  1.34.2.2    martin 		size_t buflen = pktlen - ETHER_ALIGN;
    983  1.34.2.2    martin 		int mbuf_flags = M_HASFCS;
    984  1.34.2.2    martin 		int csum_flags = 0;
    985  1.34.2.2    martin 		uint16_t csum_data = 0;
    986      1.17   mlelstv 
    987  1.34.2.2    martin  		KASSERT(pktlen < MCLBYTES);
    988       1.1     skrll 
    989      1.13   mlelstv 		/* Check if RX TCP/UDP checksumming is being offloaded */
    990      1.13   mlelstv 		if (sc->sc_coe_ctrl & SMSC_COE_CTRL_RX_EN) {
    991  1.34.2.2    martin 			DPRINTF("RX checksum offload checking", 0, 0, 0, 0);
    992  1.34.2.2    martin 			struct ether_header *eh = (struct ether_header *)pktbuf;
    993  1.34.2.2    martin 			const size_t cssz = sizeof(csum_data);
    994      1.13   mlelstv 
    995      1.13   mlelstv 			/* Remove the extra 2 bytes of the csum */
    996  1.34.2.2    martin 			buflen -= cssz;
    997      1.13   mlelstv 
    998      1.13   mlelstv 			/*
    999      1.13   mlelstv 			 * The checksum appears to be simplistically calculated
   1000      1.13   mlelstv 			 * over the udp/tcp header and data up to the end of the
   1001      1.13   mlelstv 			 * eth frame.  Which means if the eth frame is padded
   1002      1.13   mlelstv 			 * the csum calculation is incorrectly performed over
   1003      1.13   mlelstv 			 * the padding bytes as well. Therefore to be safe we
   1004      1.13   mlelstv 			 * ignore the H/W csum on frames less than or equal to
   1005      1.13   mlelstv 			 * 64 bytes.
   1006      1.13   mlelstv 			 *
   1007      1.13   mlelstv 			 * Ignore H/W csum for non-IPv4 packets.
   1008      1.13   mlelstv 			 */
   1009  1.34.2.2    martin 			DPRINTF("Ethertype %02jx pktlen %02jx",
   1010  1.34.2.2    martin 			    be16toh(eh->ether_type), pktlen, 0, 0);
   1011      1.13   mlelstv 			if (be16toh(eh->ether_type) == ETHERTYPE_IP &&
   1012      1.18     skrll 			    pktlen > ETHER_MIN_LEN) {
   1013      1.13   mlelstv 
   1014  1.34.2.2    martin 				csum_flags |=
   1015      1.18     skrll 				    (M_CSUM_TCPv4 | M_CSUM_UDPv4 | M_CSUM_DATA);
   1016      1.13   mlelstv 
   1017      1.13   mlelstv 				/*
   1018      1.13   mlelstv 				 * Copy the TCP/UDP checksum from the last 2
   1019      1.13   mlelstv 				 * bytes of the transfer and put in the
   1020      1.13   mlelstv 				 * csum_data field.
   1021      1.13   mlelstv 				 */
   1022  1.34.2.2    martin 				memcpy(&csum_data, buf + pktlen - cssz, cssz);
   1023  1.34.2.2    martin 
   1024      1.13   mlelstv 				/*
   1025      1.13   mlelstv 				 * The data is copied in network order, but the
   1026      1.13   mlelstv 				 * csum algorithm in the kernel expects it to be
   1027      1.13   mlelstv 				 * in host network order.
   1028      1.13   mlelstv 				 */
   1029  1.34.2.2    martin 				csum_data = ntohs(csum_data);
   1030  1.34.2.2    martin 				DPRINTF("RX checksum offloaded (0x%04jx)",
   1031  1.34.2.2    martin 				    csum_data, 0, 0, 0);
   1032      1.13   mlelstv 			}
   1033      1.13   mlelstv 		}
   1034      1.13   mlelstv 
   1035      1.17   mlelstv 		/* round up to next longword */
   1036      1.17   mlelstv 		pktlen = (pktlen + 3) & ~0x3;
   1037      1.17   mlelstv 
   1038      1.17   mlelstv 		/* total_len does not include the padding */
   1039      1.17   mlelstv 		if (pktlen > total_len)
   1040      1.17   mlelstv 			pktlen = total_len;
   1041      1.17   mlelstv 
   1042      1.13   mlelstv 		buf += pktlen;
   1043      1.13   mlelstv 		total_len -= pktlen;
   1044       1.1     skrll 
   1045       1.1     skrll 		/* push the packet up */
   1046  1.34.2.2    martin 		usbnet_enqueue(un, pktbuf, buflen, csum_flags, csum_data,
   1047  1.34.2.2    martin 		    mbuf_flags);
   1048       1.1     skrll 	}
   1049       1.1     skrll }
   1050       1.1     skrll 
   1051  1.34.2.2    martin static unsigned
   1052  1.34.2.2    martin smsc_uno_tx_prepare(struct usbnet *un, struct mbuf *m, struct usbnet_chain *c)
   1053       1.1     skrll {
   1054  1.34.2.1  christos 	uint32_t txhdr;
   1055  1.34.2.1  christos 	uint32_t frm_len = 0;
   1056       1.1     skrll 
   1057  1.34.2.2    martin 	const size_t hdrsz = sizeof(txhdr) * 2;
   1058  1.34.2.2    martin 
   1059  1.34.2.2    martin 	if ((unsigned)m->m_pkthdr.len > un->un_tx_bufsz - hdrsz)
   1060  1.34.2.2    martin 		return 0;
   1061  1.34.2.2    martin 
   1062       1.1     skrll 	/*
   1063       1.1     skrll 	 * Each frame is prefixed with two 32-bit values describing the
   1064       1.1     skrll 	 * length of the packet and buffer.
   1065       1.1     skrll 	 */
   1066       1.1     skrll 	txhdr = SMSC_TX_CTRL_0_BUF_SIZE(m->m_pkthdr.len) |
   1067  1.34.2.1  christos 	    SMSC_TX_CTRL_0_FIRST_SEG | SMSC_TX_CTRL_0_LAST_SEG;
   1068       1.1     skrll 	txhdr = htole32(txhdr);
   1069  1.34.2.2    martin 	memcpy(c->unc_buf, &txhdr, sizeof(txhdr));
   1070       1.1     skrll 
   1071       1.1     skrll 	txhdr = SMSC_TX_CTRL_1_PKT_LENGTH(m->m_pkthdr.len);
   1072       1.1     skrll 	txhdr = htole32(txhdr);
   1073  1.34.2.2    martin 	memcpy(c->unc_buf + sizeof(txhdr), &txhdr, sizeof(txhdr));
   1074       1.1     skrll 
   1075  1.34.2.2    martin 	frm_len += hdrsz;
   1076       1.1     skrll 
   1077       1.1     skrll 	/* Next copy in the actual packet */
   1078  1.34.2.2    martin 	m_copydata(m, 0, m->m_pkthdr.len, c->unc_buf + frm_len);
   1079       1.1     skrll 	frm_len += m->m_pkthdr.len;
   1080       1.1     skrll 
   1081  1.34.2.2    martin 	return frm_len;
   1082  1.34.2.2    martin }
   1083       1.1     skrll 
   1084  1.34.2.2    martin #ifdef _MODULE
   1085  1.34.2.2    martin #include "ioconf.c"
   1086  1.34.2.2    martin #endif
   1087       1.1     skrll 
   1088  1.34.2.2    martin USBNET_MODULE(smsc)
   1089