Module Name:    src
Committed By:   mrg
Date:           Fri Sep 20 10:34:54 UTC 2019

Modified Files:
        src/distrib/sets/lists/man: mi
        src/doc: CHANGES
        src/share/man/man4: Makefile usbnet.4
        src/sys/dev/usb: files.usb usbdevices.config
Added Files:
        src/share/man/man4: mos.4
        src/sys/dev/usb: if_mos.c if_mosreg.h

Log Message:
add mos(4) driver for Moschip MCS7730/MCS7830/MCS7832 usb ethernet.
ported from openbsd.  usbnet version loses about 40% of code.


To generate a diff of this commit:
cvs rdiff -u -r1.1653 -r1.1654 src/distrib/sets/lists/man/mi
cvs rdiff -u -r1.2583 -r1.2584 src/doc/CHANGES
cvs rdiff -u -r1.681 -r1.682 src/share/man/man4/Makefile
cvs rdiff -u -r0 -r1.1 src/share/man/man4/mos.4
cvs rdiff -u -r1.3 -r1.4 src/share/man/man4/usbnet.4
cvs rdiff -u -r1.167 -r1.168 src/sys/dev/usb/files.usb
cvs rdiff -u -r0 -r1.1 src/sys/dev/usb/if_mos.c src/sys/dev/usb/if_mosreg.h
cvs rdiff -u -r1.35 -r1.36 src/sys/dev/usb/usbdevices.config

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/man/mi
diff -u src/distrib/sets/lists/man/mi:1.1653 src/distrib/sets/lists/man/mi:1.1654
--- src/distrib/sets/lists/man/mi:1.1653	Mon Sep 16 08:31:05 2019
+++ src/distrib/sets/lists/man/mi	Fri Sep 20 10:34:54 2019
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1653 2019/09/16 08:31:05 mlelstv Exp $
+# $NetBSD: mi,v 1.1654 2019/09/20 10:34:54 mrg Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -1454,6 +1454,7 @@
 ./usr/share/man/cat4/mlx.0			man-sys-catman		.cat
 ./usr/share/man/cat4/mly.0			man-sys-catman		.cat
 ./usr/share/man/cat4/module.0			man-obsolete		obsolete
+./usr/share/man/cat4/mos.0			man-sys-catman		.cat
 ./usr/share/man/cat4/mpii.0			man-sys-catman		.cat
 ./usr/share/man/cat4/mpl115a.0			man-sys-catman		.cat
 ./usr/share/man/cat4/mpls.0			man-sys-catman		.cat
@@ -4586,6 +4587,7 @@
 ./usr/share/man/html4/mlx.html			man-sys-htmlman		html
 ./usr/share/man/html4/mly.html			man-sys-htmlman		html
 ./usr/share/man/html4/module.html		man-obsolete		obsolete
+./usr/share/man/html4/mos.html			man-sys-htmlman		html
 ./usr/share/man/html4/mpii.html			man-sys-htmlman		html
 ./usr/share/man/html4/mpl115a.html		man-sys-htmlman		html
 ./usr/share/man/html4/mpls.html			man-sys-htmlman		html
@@ -7568,6 +7570,7 @@
 ./usr/share/man/man4/mlx.4			man-sys-man		.man
 ./usr/share/man/man4/mly.4			man-sys-man		.man
 ./usr/share/man/man4/module.4			man-obsolete		obsolete
+./usr/share/man/man4/mos.4			man-sys-man		.man
 ./usr/share/man/man4/mpii.4			man-sys-man		.man
 ./usr/share/man/man4/mpl115a.4			man-sys-man		.man
 ./usr/share/man/man4/mpls.4			man-sys-man		.man

Index: src/doc/CHANGES
diff -u src/doc/CHANGES:1.2583 src/doc/CHANGES:1.2584
--- src/doc/CHANGES:1.2583	Sun Sep 15 15:19:49 2019
+++ src/doc/CHANGES	Fri Sep 20 10:34:54 2019
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2583 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2584 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -43,3 +43,5 @@ Changes from NetBSD 9.0 to NetBSD 10.0:
 	dhcpcd(8): Import dhcpcd-8.0.6 [roy 20190913]
 	kernel: Add vHCI, a driver that allows to send and receive USB
 		packets from userland. [maxv 20190914]
+	mos(4): Ported driver for MosChip MCS7730/7830/7832 USB ethernet.
+		[mrg 20190814]

Index: src/share/man/man4/Makefile
diff -u src/share/man/man4/Makefile:1.681 src/share/man/man4/Makefile:1.682
--- src/share/man/man4/Makefile:1.681	Fri Aug 30 08:54:58 2019
+++ src/share/man/man4/Makefile	Fri Sep 20 10:34:54 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.681 2019/08/30 08:54:58 mrg Exp $
+#	$NetBSD: Makefile,v 1.682 2019/09/20 10:34:54 mrg Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/18/93
 
 MAN=	aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -64,7 +64,8 @@ MAN=	aac.4 ac97.4 acardide.4 aceride.4 a
 	tap.4 tc.4 tcds.4 tcp.4 tcu.4 tdvfb.4 tea5767radio.4 termios.4 tfb.4 \
 	thinkpad.4 ti.4 tl.4 tlp.4 tlphy.4 tpm.4 tprof.4 tr.4 tra.4 \
 	trm.4 tsllux.4 tty.4 tun.4 tqphy.4 twa.4 twe.4 txp.4 \
-	uark.4 ubsec.4 udp.4 uep.4 ug.4 uha.4 uk.4 ukphy.4 umb.4 unix.4 userconf.4 \
+	uark.4 ubsec.4 udp.4 uep.4 ug.4 uha.4 uk.4 ukphy.4 umb.4 \
+	unix.4 userconf.4 \
 	vald.4 valz.4 veriexec.4 vga.4 vge.4 viaide.4 video.4 vioif.4 viomb.4 \
 	viornd.4 vioscsi.4 virt.4 \
 	virtio.4 vlan.4 vmmon.4 vmnet.4 vnd.4 voodoofb.4 vr.4 vte.4 \
@@ -75,7 +76,8 @@ MAN=	aac.4 ac97.4 acardide.4 aceride.4 a
 	zero.4 zstty.4 zyd.4
 
 # USB devices
-MAN+=	atu.4 aubtfwl.4 aue.4 axe.4 axen.4 cdce.4 cue.4 ehci.4 kue.4 mue.4 \
+MAN+=	atu.4 aubtfwl.4 aue.4 axe.4 axen.4 cdce.4 cue.4 ehci.4 kue.4 \
+	mos.4 mue.4 \
 	ohci.4 \
 	slhci.4 stuirda.4 u3g.4 ualea.4 uatp.4 uaudio.4 uberry.4 ubsa.4 ubt.4 \
 	uchcom.4 \

Index: src/share/man/man4/usbnet.4
diff -u src/share/man/man4/usbnet.4:1.3 src/share/man/man4/usbnet.4:1.4
--- src/share/man/man4/usbnet.4:1.3	Fri Aug 30 09:24:19 2019
+++ src/share/man/man4/usbnet.4	Fri Sep 20 10:34:54 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: usbnet.4,v 1.3 2019/08/30 09:24:19 wiz Exp $
+.\"	$NetBSD: usbnet.4,v 1.4 2019/09/20 10:34:54 mrg Exp $
 .\"
 .\" Copyright (c) 2019 Matthew R. Green
 .\" All rights reserved.
@@ -81,7 +81,7 @@ manual lists generic diagnostics generat
 .Xr ifmedia 4 ,
 .Xr intro 4 ,
 .Xr kue 4 ,
-.\" Xr mos 4 ,
+.Xr mos 4 ,
 .Xr mue 4 ,
 .Xr netintro 4 ,
 .Xr smsc 4 ,

Index: src/sys/dev/usb/files.usb
diff -u src/sys/dev/usb/files.usb:1.167 src/sys/dev/usb/files.usb:1.168
--- src/sys/dev/usb/files.usb:1.167	Fri Aug 23 08:45:25 2019
+++ src/sys/dev/usb/files.usb	Fri Sep 20 10:34:54 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: files.usb,v 1.167 2019/08/23 08:45:25 mrg Exp $
+#	$NetBSD: files.usb,v 1.168 2019/09/20 10:34:54 mrg Exp $
 #
 # Config file and device description for machine-independent USB code.
 # Included by ports that need it.  Ports that use it must provide
@@ -373,21 +373,26 @@ device	axen: arp, ether, ifnet, mii, usb
 attach	axen at usbdevif
 file	dev/usb/if_axen.c		axen
 
+# Moscom MCS7730, MCS7830, and MCS7832
+device	mos: arp, ether, ifnet, mii, mii_phy, usbnet
+attach	mos at usbdevif
+file	dev/usb/if_mos.c		mos
+
 # Microchip LAN750x and LAN85xx
 device	mue: arp, ether, ifnet, mii, mii_phy, usbnet
 attach	mue at usbdevif
 file	dev/usb/if_mue.c		mue
 
-# DAVICOM DM9601
-device	udav: arp, ether, ifnet, mii, mii_phy, usbnet
-attach	udav at usbdevif
-file	dev/usb/if_udav.c		udav
-
 # Atheros AR9170
 device	otus: arp, ether, firmload, ifnet, wlan
 attach	otus at usbdevif
 file	dev/usb/if_otus.c		otus
 
+# DAVICOM DM9601
+device	udav: arp, ether, ifnet, mii, mii_phy, usbnet
+attach	udav at usbdevif
+file	dev/usb/if_udav.c		udav
+
 # Mobile Broadband Interface Model
 device	umb: ifnet
 attach	umb at usbifif

Index: src/sys/dev/usb/usbdevices.config
diff -u src/sys/dev/usb/usbdevices.config:1.35 src/sys/dev/usb/usbdevices.config:1.36
--- src/sys/dev/usb/usbdevices.config:1.35	Wed Feb  6 11:58:32 2019
+++ src/sys/dev/usb/usbdevices.config	Fri Sep 20 10:34:54 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: usbdevices.config,v 1.35 2019/02/06 11:58:32 rin Exp $
+#	$NetBSD: usbdevices.config,v 1.36 2019/09/20 10:34:54 mrg Exp $
 #
 # This file contains all USB related configuration.
 # It is suitable for inclusion in a kernel config(5) file.
@@ -126,7 +126,7 @@ axen*	at uhub? port ?		# ASIX AX88178a/A
 cdce*	at uhub? port ?		# CDC, Ethernet Networking Control Model
 cue*	at uhub? port ?		# CATC USB-EL1201A based adapters
 kue*	at uhub? port ?		# Kawasaki LSI KL5KUSB101B based adapters
-#mos*	at uhub? port ?		# Moschip MCS7730/MCS7830/MCS7832 based adapters
+mos*	at uhub? port ?		# Moschip MCS7730/MCS7830/MCS7832 based adapters
 mue*	at uhub? port ?		# Microchip LAN75xx/LAN78xx based adapters
 udav*	at uhub? port ?		# Davicom DM9601 based adapters
 #umb*	at uhub? port ?		# Mobile Broadband Interface Model (EXPERIMENTAL)

Added files:

Index: src/share/man/man4/mos.4
diff -u /dev/null src/share/man/man4/mos.4:1.1
--- /dev/null	Fri Sep 20 10:34:54 2019
+++ src/share/man/man4/mos.4	Fri Sep 20 10:34:54 2019
@@ -0,0 +1,131 @@
+.\"	$NetBSD: mos.4,v 1.1 2019/09/20 10:34:54 mrg Exp $
+.\"
+.\" Copyright (c) 1997, 1998, 1999, 2000-2003
+.\"	Bill Paul <wp...@windriver.com>. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"	This product includes software developed by Bill Paul.
+.\" 4. Neither the name of the author nor the names of any co-contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"   without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+.\" THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $FreeBSD: /repoman/r/ncvs/src/share/man/man4/axe.4,v 1.3 2003/05/29 21:28:35 ru Exp $
+.\" $OpenBSD: mos.4,v 1.11 2014/04/08 01:18:19 brad Exp $
+.\"
+.Dd August 24 2019
+.Dt MOS 4
+.Os
+.Sh NAME
+.Nm mos
+.Nd MosChip MCS7730/7830/7832 10/100 USB Ethernet device
+.Sh SYNOPSIS
+.Cd "mos*   at uhub?"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for USB Ethernet adapters based on the MosChip
+MCS7730, MCS7830 and MCS7832 USB 2.0 chipsets, including the
+following:
+.Pp
+.Bl -tag -width Ds -offset indent -compact
+.It Delock 61147
+.It Sitecom LN-030
+.It Syba SY-U2LAN
+.El
+.Pp
+All adapters operate with either USB 1.x, 2.0, or 3.x controllers,
+though performance with 1.x controllers is limited since
+the USB 1.x standard specifies a maximum transfer speed of 12Mbps.
+Users with USB 1.x controllers should therefore not expect to actually
+achieve 100Mbps speeds with these devices.
+.Pp
+A 64-bit multicast hash table is supported,
+single perfect filter entry for the station address,
+all-multicast mode, and promiscuous mode.
+Packets are
+received and transmitted over separate USB bulk transfer endpoints.
+.Pp
+The
+.Nm
+driver supports the following media types:
+.Bl -tag -width "autoselect"
+.It autoselect
+Enable autoselection of the media type and options (this is the default).
+The user can manually override the autoselected mode by adding media
+options to the appropriate
+.Xr ifconfig.if 5
+file.
+.It 10baseT
+Set 10Mbps operation.
+.It 100baseTX
+Set 100Mbps (Fast Ethernet) operation.
+.El
+.Pp
+The
+.Nm
+driver supports the following media options:
+.Bl -tag -width "full-duplex"
+.It full-duplex
+Force full-duplex operation.
+.It half-duplex
+Force half-duplex operation.
+.El
+.Pp
+For more information on configuring this device, see
+.Xr ifconfig 8 .
+.Sh DIAGNOSTICS
+See
+.Xr usbnet 4
+for diagnostics.
+.Sh SEE ALSO
+.Xr arp 4 ,
+.Xr ifmedia 4 ,
+.Xr intro 4 ,
+.Xr netintro 4 ,
+.Xr usb 4 ,
+.Xr usbnet 4 ,
+.Xr ifconfig.if 5 ,
+.Xr ifconfig 8 ,
+.Xr usbnet 9
+.Rs
+.%T "MosChip India"
+.%U http://www.moschip.com
+.Re
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Ox 4.5 .
+It was ported to
+.Nx
+by
+.An Matthew R. Green Aq Mt m...@eterna.com.au
+and first appeared in
+.Nx 10.0 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Johann Christian Rode Aq Mt jcr...@gmx.net .

Index: src/sys/dev/usb/if_mos.c
diff -u /dev/null src/sys/dev/usb/if_mos.c:1.1
--- /dev/null	Fri Sep 20 10:34:54 2019
+++ src/sys/dev/usb/if_mos.c	Fri Sep 20 10:34:54 2019
@@ -0,0 +1,816 @@
+/*	$NetBSD: if_mos.c,v 1.1 2019/09/20 10:34:54 mrg Exp $	*/
+/*	$OpenBSD: if_mos.c,v 1.40 2019/07/07 06:40:10 kevlo Exp $	*/
+
+/*
+ * Copyright (c) 2008 Johann Christian Rode <jcr...@gmx.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Copyright (c) 2005, 2006, 2007 Jonathan Gray <j...@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Copyright (c) 1997, 1998, 1999, 2000-2003
+ *	Bill Paul <wp...@windriver.com>.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by Bill Paul.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Moschip MCS7730/MCS7830/MCS7832 USB to Ethernet controller 
+ * The datasheet is available at the following URL: 
+ * http://www.moschip.com/data/products/MCS7830/Data%20Sheet_7830.pdf
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: if_mos.c,v 1.1 2019/09/20 10:34:54 mrg Exp $");
+
+#include <sys/param.h>
+
+#include <dev/usb/usbnet.h>
+#include <dev/usb/if_mosreg.h>
+
+#define MOS_PAUSE_REWRITES	3
+
+#define MOS_TIMEOUT		1000
+
+#define MOS_RX_LIST_CNT		1
+#define MOS_TX_LIST_CNT		1
+
+/* Maximum size of a fast ethernet frame plus one byte for the status */
+#define MOS_BUFSZ	 	(ETHER_MAX_LEN+1)
+
+/*
+ * USB endpoints.
+ */
+#define MOS_ENDPT_RX		0
+#define MOS_ENDPT_TX		1
+#define MOS_ENDPT_INTR		2
+#define MOS_ENDPT_MAX		3
+
+/*
+ * USB vendor requests.
+ */
+#define MOS_UR_READREG		0x0e
+#define MOS_UR_WRITEREG		0x0d
+
+#define MOS_CONFIG_NO		1
+#define MOS_IFACE_IDX		0
+
+struct mos_type {
+	struct usb_devno	mos_dev;
+	u_int16_t		mos_flags;
+#define MCS7730	0x0001		/* MCS7730 */
+#define MCS7830	0x0002		/* MCS7830 */
+#define MCS7832	0x0004		/* MCS7832 */
+};
+
+#define MOS_INC(x, y)           (x) = (x + 1) % y
+
+#ifdef MOS_DEBUG
+#define DPRINTF(x)      do { if (mosdebug) printf x; } while (0)
+#define DPRINTFN(n,x)   do { if (mosdebug >= (n)) printf x; } while (0)
+int     mosdebug = 0;
+#else
+#define DPRINTF(x)	__nothing
+#define DPRINTFN(n,x)	__nothing
+#endif
+
+/*
+ * Various supported device vendors/products.
+ */
+const struct mos_type mos_devs[] = {
+	{ { USB_VENDOR_MOSCHIP, USB_PRODUCT_MOSCHIP_MCS7730 }, MCS7730 },
+	{ { USB_VENDOR_MOSCHIP, USB_PRODUCT_MOSCHIP_MCS7830 }, MCS7830 },
+	{ { USB_VENDOR_MOSCHIP, USB_PRODUCT_MOSCHIP_MCS7832 }, MCS7832 },
+	{ { USB_VENDOR_SITECOMEU, USB_PRODUCT_SITECOMEU_LN030 }, MCS7830 },
+};
+#define mos_lookup(v, p) ((const struct mos_type *)usb_lookup(mos_devs, v, p))
+
+static int mos_match(device_t, cfdata_t, void *);
+static void mos_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(mos, sizeof(struct usbnet),
+	mos_match, mos_attach, usbnet_detach, usbnet_activate);
+
+static void mos_rx_loop(struct usbnet *, struct usbnet_chain *, uint32_t);
+static unsigned mos_tx_prepare(struct usbnet *, struct mbuf *,
+			       struct usbnet_chain *);
+static int mos_ioctl(struct ifnet *, u_long, void *);
+static int mos_init(struct ifnet *);
+static void mos_chip_init(struct usbnet *);
+static void mos_stop(struct ifnet *ifp, int disable);
+static int mos_mii_read_reg(struct usbnet *, int, int, uint16_t *);
+static int mos_mii_write_reg(struct usbnet *, int, int, uint16_t);
+static void mos_mii_statchg(struct ifnet *);
+static void mos_reset(struct usbnet *);
+
+static int mos_reg_read_1(struct usbnet *, int);
+static int mos_reg_read_2(struct usbnet *, int);
+static int mos_reg_write_1(struct usbnet *, int, int);
+static int mos_reg_write_2(struct usbnet *, int, int);
+static int mos_readmac(struct usbnet *);
+static int mos_writemac(struct usbnet *);
+static int mos_write_mcast(struct usbnet *, uint8_t *);
+
+static struct usbnet_ops mos_ops = {
+	.uno_stop = mos_stop,
+	.uno_ioctl = mos_ioctl,
+	.uno_read_reg = mos_mii_read_reg,
+	.uno_write_reg = mos_mii_write_reg,
+	.uno_statchg = mos_mii_statchg,
+	.uno_tx_prepare = mos_tx_prepare,
+	.uno_rx_loop = mos_rx_loop,
+	.uno_init = mos_init,
+};
+
+static int
+mos_reg_read_1(struct usbnet *un, int reg)
+{
+	usb_device_request_t	req;
+	usbd_status		err;
+	uByte			val = 0;
+
+	if (usbnet_isdying(un))
+		return 0;
+
+	req.bmRequestType = UT_READ_VENDOR_DEVICE;
+	req.bRequest = MOS_UR_READREG;
+	USETW(req.wValue, 0);
+	USETW(req.wIndex, reg);
+	USETW(req.wLength, 1);
+
+	err = usbd_do_request(un->un_udev, &req, &val);
+
+	if (err) {
+		aprint_error_dev(un->un_dev, "read reg %x\n", reg);
+		return 0;
+	}
+
+	return val;
+}
+
+static int
+mos_reg_read_2(struct usbnet *un, int reg)
+{
+	usb_device_request_t	req;
+	usbd_status		err;
+	uWord			val;
+
+	if (usbnet_isdying(un))
+		return 0;
+
+	USETW(val,0);
+
+	req.bmRequestType = UT_READ_VENDOR_DEVICE;
+	req.bRequest = MOS_UR_READREG;
+	USETW(req.wValue, 0);
+	USETW(req.wIndex, reg);
+	USETW(req.wLength, 2);
+
+	err = usbd_do_request(un->un_udev, &req, &val);
+
+	if (err) {
+		aprint_error_dev(un->un_dev, "read reg2 %x\n", reg);
+		return 0;
+	}
+
+	return UGETW(val);
+}
+
+static int
+mos_reg_write_1(struct usbnet *un, int reg, int aval)
+{
+	usb_device_request_t	req;
+	usbd_status		err;
+	uByte			val;
+
+	if (usbnet_isdying(un))
+		return 0;
+
+	val = aval;
+
+	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
+	req.bRequest = MOS_UR_WRITEREG;
+	USETW(req.wValue, 0);
+	USETW(req.wIndex, reg);
+	USETW(req.wLength, 1);
+
+	err = usbd_do_request(un->un_udev, &req, &val);
+
+	if (err)
+		aprint_error_dev(un->un_dev, "write reg %x <- %x\n", 
+		    reg, aval);
+
+	return 0;
+}
+
+static int
+mos_reg_write_2(struct usbnet *un, int reg, int aval)
+{
+	usb_device_request_t	req;
+	usbd_status		err;
+	uWord			val;
+
+	USETW(val, aval);
+
+	if (usbnet_isdying(un))
+		return EIO;
+
+	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
+	req.bRequest = MOS_UR_WRITEREG;
+	USETW(req.wValue, 0);
+	USETW(req.wIndex, reg);
+	USETW(req.wLength, 2);
+
+	err = usbd_do_request(un->un_udev, &req, &val);
+
+	if (err)
+		aprint_error_dev(un->un_dev, "write reg2 %x <- %x\n", 
+		    reg, aval);
+
+	return 0;
+}
+
+static int
+mos_readmac(struct usbnet *un)
+{
+	usb_device_request_t	req;
+	usbd_status		err;
+
+	if (usbnet_isdying(un))
+		return 0;
+
+	req.bmRequestType = UT_READ_VENDOR_DEVICE;
+	req.bRequest = MOS_UR_READREG;
+	USETW(req.wValue, 0);
+	USETW(req.wIndex, MOS_MAC);
+	USETW(req.wLength, ETHER_ADDR_LEN);
+
+	err = usbd_do_request(un->un_udev, &req, un->un_eaddr);
+
+	if (err)
+		aprint_error_dev(un->un_dev, "%s: failed", __func__);
+
+	return err;
+}
+
+static int
+mos_writemac(struct usbnet *un)
+{
+	usb_device_request_t	req;
+	usbd_status		err;
+
+	if (usbnet_isdying(un))
+		return 0;
+
+	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
+	req.bRequest = MOS_UR_WRITEREG;
+	USETW(req.wValue, 0);
+	USETW(req.wIndex, MOS_MAC);
+	USETW(req.wLength, ETHER_ADDR_LEN);
+
+	err = usbd_do_request(un->un_udev, &req, un->un_eaddr);
+
+	if (err)
+		aprint_error_dev(un->un_dev, "%s: failed", __func__);
+
+	return 0;
+}
+
+static int
+mos_write_mcast(struct usbnet *un, uint8_t *hashtbl)
+{
+	usb_device_request_t	req;
+	usbd_status		err;
+
+	if (usbnet_isdying(un))
+		return EIO;
+
+	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
+	req.bRequest = MOS_UR_WRITEREG;
+	USETW(req.wValue, 0);
+	USETW(req.wIndex, MOS_MCAST_TABLE);
+	USETW(req.wLength, 8);
+
+	err = usbd_do_request(un->un_udev, &req, hashtbl);
+
+	if (err) {
+		aprint_error_dev(un->un_dev, "%s: failed", __func__);
+		return(-1);
+	}
+
+	return 0;
+}
+
+static int
+mos_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
+{
+	int			i, res;
+
+	mos_reg_write_2(un, MOS_PHY_DATA, 0);
+	mos_reg_write_1(un, MOS_PHY_CTL, (phy & MOS_PHYCTL_PHYADDR) |
+	    MOS_PHYCTL_READ);
+	mos_reg_write_1(un, MOS_PHY_STS, (reg & MOS_PHYSTS_PHYREG) |
+	    MOS_PHYSTS_PENDING);
+
+	for (i = 0; i < MOS_TIMEOUT; i++) {
+		if (mos_reg_read_1(un, MOS_PHY_STS) & MOS_PHYSTS_READY)
+			break;
+	}
+	if (i == MOS_TIMEOUT) {
+		aprint_error_dev(un->un_dev, "read PHY failed\n");
+		return EIO;
+	}
+
+	res = mos_reg_read_2(un, MOS_PHY_DATA);
+	*val = res;
+
+	DPRINTFN(10,("%s: %s: phy %d reg %d val %u\n",
+	    device_xname(un->un_dev), __func__, phy, reg, res));
+
+	return 0;
+}
+
+static int
+mos_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
+{
+	int			i;
+
+	DPRINTFN(10,("%s: %s: phy %d reg %d val %u\n",
+	    device_xname(un->un_dev), __func__, phy, reg, val));
+
+	mos_reg_write_2(un, MOS_PHY_DATA, val);
+	mos_reg_write_1(un, MOS_PHY_CTL, (phy & MOS_PHYCTL_PHYADDR) |
+	    MOS_PHYCTL_WRITE);
+	mos_reg_write_1(un, MOS_PHY_STS, (reg & MOS_PHYSTS_PHYREG) |
+	    MOS_PHYSTS_PENDING);
+
+	for (i = 0; i < MOS_TIMEOUT; i++) {
+		if (mos_reg_read_1(un, MOS_PHY_STS) & MOS_PHYSTS_READY)
+			break;
+	}
+	if (i == MOS_TIMEOUT) {
+		aprint_error_dev(un->un_dev, "write PHY failed\n");
+		return EIO;
+	}
+
+	return 0;
+}
+
+void
+mos_mii_statchg(struct ifnet *ifp)
+{
+	struct usbnet * const		un = ifp->if_softc;
+	struct mii_data * const		mii = usbnet_mii(un);
+	int				val, err;
+
+	if (usbnet_isdying(un))
+		return;
+
+	DPRINTFN(10,("%s: %s: enter\n", device_xname(un->un_dev), __func__));
+
+	usbnet_lock_mii(un);
+
+	/* disable RX, TX prior to changing FDX, SPEEDSEL */
+	val = mos_reg_read_1(un, MOS_CTL);
+	val &= ~(MOS_CTL_TX_ENB | MOS_CTL_RX_ENB);
+	mos_reg_write_1(un, MOS_CTL, val);
+
+	/* reset register which counts dropped frames */
+	mos_reg_write_1(un, MOS_FRAME_DROP_CNT, 0);
+
+	if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
+		val |= MOS_CTL_FDX_ENB;
+	else
+		val &= ~(MOS_CTL_FDX_ENB);
+
+	if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
+	    (IFM_ACTIVE | IFM_AVALID)) {
+		switch (IFM_SUBTYPE(mii->mii_media_active)) {
+		case IFM_100_TX:
+			val |=  MOS_CTL_SPEEDSEL;
+			break;
+		case IFM_10_T:
+			val &= ~(MOS_CTL_SPEEDSEL);
+			break;
+		}
+		usbnet_set_link(un, true);
+	}
+
+	/* re-enable TX, RX */
+	val |= (MOS_CTL_TX_ENB | MOS_CTL_RX_ENB);
+	err = mos_reg_write_1(un, MOS_CTL, val);
+	usbnet_unlock_mii(un);
+
+	if (err)
+		aprint_error_dev(un->un_dev, "media change failed\n");
+}
+
+static void
+mos_setiff_locked(struct usbnet *un)
+{
+	struct ifnet		*ifp = usbnet_ifp(un);
+	struct ethercom		*ec = usbnet_ec(un);
+	struct ether_multi	*enm;
+	struct ether_multistep	step;
+	u_int32_t		h = 0;
+	u_int8_t		rxmode, hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+
+	if (usbnet_isdying(un))
+		return;
+
+	rxmode = mos_reg_read_1(un, MOS_CTL);
+	rxmode &= ~(MOS_CTL_ALLMULTI | MOS_CTL_RX_PROMISC);
+
+	if (ifp->if_flags & IFF_PROMISC || ec->ec_multicnt > 0) {
+allmulti:
+		ETHER_LOCK(ec);
+		ec->ec_flags |= ETHER_F_ALLMULTI;
+		ETHER_UNLOCK(ec);
+		rxmode |= MOS_CTL_ALLMULTI;
+		if (ifp->if_flags & IFF_PROMISC)
+			rxmode |= MOS_CTL_RX_PROMISC;
+	} else {
+		/* now program new ones */
+		ETHER_LOCK(ec);
+		ec->ec_flags &= ~ETHER_F_ALLMULTI;
+
+		ETHER_FIRST_MULTI(step, ec, enm);
+		while (enm != NULL) {
+			if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
+			    ETHER_ADDR_LEN)) {
+				memset(hashtbl, 0, sizeof(hashtbl));
+				ETHER_UNLOCK(ec);
+				goto allmulti;
+			}
+			h = ether_crc32_be(enm->enm_addrlo,
+			    ETHER_ADDR_LEN) >> 26;
+			hashtbl[h / 8] |= 1 << (h % 8);
+
+			ETHER_NEXT_MULTI(step, enm);
+		}
+		ETHER_UNLOCK(ec);
+	}
+
+	/* 
+	 * The datasheet claims broadcast frames were always accepted
+	 * regardless of filter settings. But the hardware seems to
+	 * filter broadcast frames, so pass them explicitly.
+	 */
+	h = ether_crc32_be(etherbroadcastaddr, ETHER_ADDR_LEN) >> 26;
+	hashtbl[h / 8] |= 1 << (h % 8);
+
+	mos_write_mcast(un, hashtbl);
+	mos_reg_write_1(un, MOS_CTL, rxmode);
+}
+
+static void
+mos_setiff(struct usbnet *un)
+{
+	usbnet_lock_mii(un);
+	mos_setiff_locked(un);
+	usbnet_unlock_mii(un);
+}
+
+static void
+mos_reset(struct usbnet *un)
+{
+	u_int8_t ctl;
+
+	if (usbnet_isdying(un))
+		return;
+
+	ctl = mos_reg_read_1(un, MOS_CTL);
+	ctl &= ~(MOS_CTL_RX_PROMISC | MOS_CTL_ALLMULTI | MOS_CTL_TX_ENB |
+	    MOS_CTL_RX_ENB);
+	/* Disable RX, TX, promiscuous and allmulticast mode */
+	mos_reg_write_1(un, MOS_CTL, ctl);
+
+	/* Reset frame drop counter register to zero */
+	mos_reg_write_1(un, MOS_FRAME_DROP_CNT, 0);
+
+	/* Wait a little while for the chip to get its brains in order. */
+	DELAY(1000);
+}
+
+void
+mos_chip_init(struct usbnet *un)
+{
+	int	i;
+
+	/*
+	 * Rev.C devices have a pause threshold register which needs to be set
+	 * at startup.
+	 */
+	if (mos_reg_read_1(un, MOS_PAUSE_TRHD) != -1) {
+		for (i = 0; i < MOS_PAUSE_REWRITES; i++)
+			mos_reg_write_1(un, MOS_PAUSE_TRHD, 0);
+	}
+}
+
+/*
+ * Probe for a MCS7x30 chip.
+ */
+static int
+mos_match(device_t parent, cfdata_t match, void *aux)
+{
+	struct usb_attach_arg *uaa = aux;
+
+	return (mos_lookup(uaa->uaa_vendor, uaa->uaa_product) != NULL ?
+	    UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
+}
+
+/*
+ * Attach the interface.
+ */
+static void
+mos_attach(device_t parent, device_t self, void *aux)
+{
+	USBNET_MII_DECL_DEFAULT(unm);
+	struct usbnet *		un = device_private(self);
+	struct usb_attach_arg	*uaa = aux;
+	struct usbd_device	*dev = uaa->uaa_device;
+	usbd_status		err;
+	usb_interface_descriptor_t 	*id;
+	usb_endpoint_descriptor_t 	*ed;
+	char			*devinfop;
+	int			i;
+
+	aprint_naive("\n");
+	aprint_normal("\n");
+	devinfop = usbd_devinfo_alloc(dev, 0);
+	aprint_normal_dev(self, "%s\n", devinfop);
+	usbd_devinfo_free(devinfop);
+
+	un->un_dev = self;
+	un->un_udev = dev;
+	un->un_sc = un;
+	un->un_ops = &mos_ops;
+	un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
+	un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
+	un->un_rx_list_cnt = MOS_RX_LIST_CNT;
+	un->un_tx_list_cnt = MOS_TX_LIST_CNT;
+	un->un_rx_bufsz = un->un_tx_bufsz = MOS_BUFSZ;
+
+	err = usbd_set_config_no(dev, MOS_CONFIG_NO, 1);
+	if (err) {
+		aprint_error_dev(self, "failed to set configuration"
+		    ", err=%s\n", usbd_errstr(err));
+		return;
+	}
+
+	err = usbd_device2interface_handle(dev, MOS_IFACE_IDX, &un->un_iface);
+	if (err) {
+		aprint_error_dev(self, "failed getting interface handle"
+		    ", err=%s\n", usbd_errstr(err));
+		return;
+	}
+
+	un->un_flags = mos_lookup(uaa->uaa_vendor, uaa->uaa_product)->mos_flags;
+
+	id = usbd_get_interface_descriptor(un->un_iface);
+
+	/* Find endpoints. */
+	for (i = 0; i < id->bNumEndpoints; i++) {
+		ed = usbd_interface2endpoint_descriptor(un->un_iface, i);
+		if (!ed) {
+			aprint_error_dev(self, "couldn't get ep %d\n", i);
+			return;
+		}
+		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
+		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
+			un->un_ed[USBNET_ENDPT_RX] = ed->bEndpointAddress;
+		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
+			   UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
+			un->un_ed[USBNET_ENDPT_TX] = ed->bEndpointAddress;
+		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
+			   UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
+			un->un_ed[USBNET_ENDPT_INTR] = ed->bEndpointAddress;
+		}
+	}
+
+	if (un->un_flags & MCS7730)
+		aprint_normal_dev(self, "MCS7730\n");
+	else if (un->un_flags & MCS7830)
+		aprint_normal_dev(self, "MCS7830\n");
+	else if (un->un_flags & MCS7832)
+		aprint_normal_dev(self, "MCS7832\n");
+
+	/* Set these up now for register access. */
+	usbnet_attach(un, "mosdet");
+
+	mos_chip_init(un);
+
+	/*
+	 * Read MAC address, inform the world.
+	 */
+	err = mos_readmac(un);
+	if (err) {
+		aprint_error_dev(self, "couldn't read MAC address\n");
+		return;
+	}
+
+	struct ifnet *ifp = usbnet_ifp(un);
+	ifp->if_capabilities = ETHERCAP_VLAN_MTU;
+
+	usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
+	    0, &unm);
+}
+
+/*
+ * A frame has been uploaded: pass the resulting mbuf chain up to
+ * the higher level protocols.
+ */
+void
+mos_rx_loop(struct usbnet * un, struct usbnet_chain *c, uint32_t total_len)
+{
+	struct ifnet		*ifp = usbnet_ifp(un);
+	uint8_t			*buf = c->unc_buf;
+	u_int8_t		rxstat;
+	u_int16_t		pktlen = 0;
+
+	DPRINTFN(5,("%s: %s: enter len %u\n",
+	    device_xname(un->un_dev), __func__, total_len));
+
+	if (total_len <= 1)
+		return;
+
+	/* evaluate status byte at the end */
+	pktlen = total_len - 1;
+	if (pktlen > un->un_rx_bufsz) {
+		ifp->if_ierrors++;
+		return;
+	}
+	rxstat = buf[pktlen] & MOS_RXSTS_MASK;
+
+	if (rxstat != MOS_RXSTS_VALID) {
+		DPRINTF(("%s: erroneous frame received: ",
+		    device_xname(un->un_dev)));
+		if (rxstat & MOS_RXSTS_SHORT_FRAME)
+			DPRINTF(("frame size less than 64 bytes\n"));
+		if (rxstat & MOS_RXSTS_LARGE_FRAME)
+			DPRINTF(("frame size larger than 1532 bytes\n"));
+		if (rxstat & MOS_RXSTS_CRC_ERROR)
+			DPRINTF(("CRC error\n"));
+		if (rxstat & MOS_RXSTS_ALIGN_ERROR)
+			DPRINTF(("alignment error\n"));
+		ifp->if_ierrors++;
+		return;
+	}
+
+	if (pktlen < sizeof(struct ether_header) ) {
+		ifp->if_ierrors++;
+		return;
+	}
+
+	usbnet_enqueue(un, c->unc_buf, pktlen, 0, 0, 0);
+}
+
+static unsigned
+mos_tx_prepare(struct usbnet *un, struct mbuf *m, struct usbnet_chain *c)
+{
+	int			length;
+
+	usbnet_isowned_tx(un);
+
+	if ((unsigned)m->m_pkthdr.len > un->un_tx_bufsz)
+		return 0;
+
+	m_copydata(m, 0, m->m_pkthdr.len, c->unc_buf);
+	length = m->m_pkthdr.len;
+
+	DPRINTFN(5,("%s: %s: len %u\n",
+	    device_xname(un->un_dev), __func__, length));
+
+	return length;
+}
+
+static int
+mos_init_locked(struct ifnet *ifp)
+{
+	struct usbnet * const un = ifp->if_softc;
+	u_int8_t		rxmode;
+	unsigned char		ipgs[2];
+
+	if (usbnet_isdying(un))
+		return EIO;
+
+	/* Cancel pending I/O */
+	usbnet_stop(un, ifp, 1);
+
+	usbnet_lock_mii_un_locked(un);
+
+	/* Reset the ethernet interface. */
+	mos_reset(un);
+
+	/* Write MAC address. */
+	mos_writemac(un);
+
+	/* Read and set transmitter IPG values */
+	ipgs[0] = mos_reg_read_1(un, MOS_IPG0);
+	ipgs[1] = mos_reg_read_1(un, MOS_IPG1);
+	mos_reg_write_1(un, MOS_IPG0, ipgs[0]);
+	mos_reg_write_1(un, MOS_IPG1, ipgs[1]);
+
+	/* Program promiscuous mode and multicast filters. */
+	mos_setiff_locked(un);
+
+	/* Enable receiver and transmitter, bridge controls speed/duplex mode */
+	rxmode = mos_reg_read_1(un, MOS_CTL);
+	rxmode |= MOS_CTL_RX_ENB | MOS_CTL_TX_ENB | MOS_CTL_BS_ENB;
+	rxmode &= ~(MOS_CTL_SLEEP);
+	mos_reg_write_1(un, MOS_CTL, rxmode);
+
+	usbnet_unlock_mii_un_locked(un);
+
+	return usbnet_init_rx_tx(un);
+}
+
+static int
+mos_init(struct ifnet *ifp)
+{
+	struct usbnet * const un = ifp->if_softc;
+
+	usbnet_lock(un);
+	int ret = mos_init_locked(ifp);
+	usbnet_unlock(un);
+
+	return ret;
+}
+
+static int
+mos_ioctl(struct ifnet *ifp, u_long cmd, void *data)
+{
+	struct usbnet * const un = ifp->if_softc;
+
+	switch (cmd) {
+	case SIOCADDMULTI:
+	case SIOCDELMULTI:
+		mos_setiff(un);
+		break;
+	default:
+		break;
+	}
+
+	return 0;
+}
+
+void
+mos_stop(struct ifnet *ifp, int disable)
+{
+	struct usbnet * const un = ifp->if_softc;
+
+	usbnet_lock_mii_un_locked(un);
+	mos_reset(un);
+	usbnet_unlock_mii_un_locked(un);
+}
Index: src/sys/dev/usb/if_mosreg.h
diff -u /dev/null src/sys/dev/usb/if_mosreg.h:1.1
--- /dev/null	Fri Sep 20 10:34:54 2019
+++ src/sys/dev/usb/if_mosreg.h	Fri Sep 20 10:34:54 2019
@@ -0,0 +1,109 @@
+/*	$NetBSD: if_mosreg.h,v 1.1 2019/09/20 10:34:54 mrg Exp $	*/
+/*	$OpenBSD: if_mosreg.h,v 1.7 2013/04/15 09:23:01 mglocker Exp $	*/
+
+/*
+ * Copyright (c) 2008 Johann Christian Rode <jcr...@gmx.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Copyright (c) 1997, 1998, 1999, 2000-2003
+ *	Bill Paul <wp...@windriver.com>.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by Ravikanth.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul, THE VOICES IN HIS HEAD OR
+ * THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Register definitions for the Moschip MCS7x30 ethernet controller.
+ */
+#define MOS_MCAST_TABLE 	0x00
+#define MOS_IPG0		0x08
+#define MOS_IPG1		0x09
+#define MOS_PHY_DATA0		0x0a
+#define MOS_PHY_DATA1		0x0b
+#define MOS_PHY_CTL		0x0c
+#define MOS_PHY_STS		0x0d
+#define MOS_PHY_DATA		MOS_PHY_DATA0
+#define MOS_CTL			0x0e
+#define MOS_MAC0		0x0f
+#define MOS_MAC1		0x10
+#define MOS_MAC2		0x11
+#define MOS_MAC3		0x12
+#define MOS_MAC4		0x13
+#define MOS_MAC5		0x14
+#define MOS_MAC			MOS_MAC0
+/* apparently only available on hardware rev. C */
+#define MOS_FRAME_DROP_CNT	0x15
+#define MOS_PAUSE_TRHD		0x16
+
+#define MOS_PHYCTL_PHYADDR	0x1f
+#define MOS_PHYCTL_WRITE	0x20
+#define MOS_PHYCTL_READ		0x40
+
+#define MOS_PHYSTS_PHYREG	0x1f
+#define MOS_PHYSTS_READY	0x40
+#define MOS_PHYSTS_PENDING	0x80
+
+#define MOS_CTL_RX_PROMISC	0x01
+#define MOS_CTL_ALLMULTI	0x02
+#define MOS_CTL_SLEEP		0x04
+#define MOS_CTL_TX_ENB		0x08
+/* 
+ * The documentation calls this bit 'reserved', but in the FreeBSD driver 
+ * provided by the vendor, this enables the receiver.
+ */
+#define MOS_CTL_RX_ENB		0x10
+#define MOS_CTL_FDX_ENB		0x20
+/* 0 = 10 Mbps, 1 = 100 Mbps */
+#define MOS_CTL_SPEEDSEL	0x40
+/* 0 = PHY controls speed/duplex mode, 1 = bridge controls speed/duplex mode */
+#define MOS_CTL_BS_ENB		0x80
+
+#define MOS_RXSTS_SHORT_FRAME	0x01
+#define MOS_RXSTS_LENGTH_ERROR	0x02
+#define MOS_RXSTS_ALIGN_ERROR	0x04
+#define MOS_RXSTS_CRC_ERROR	0x08
+#define MOS_RXSTS_LARGE_FRAME	0x10
+#define MOS_RXSTS_VALID		0x20
+/*
+ * The EtherType field of an Ethernet frame can contain values other than
+ * the frame length, hence length errors are ignored.
+ */
+#define MOS_RXSTS_MASK		0x3d

Reply via email to