Index: /freebsd-mos-driver/if_mos.c
===================================================================
--- /freebsd-mos-driver/if_mos.c	(revision 272)
+++ /freebsd-mos-driver/if_mos.c	(revision 273)
@@ -1,5 +1,4 @@
 /*	$OpenBSD: if_mos.c,v 1.7 2009/10/13 19:33:17 pirofti Exp $	*/
-#define USB_DEBUG 1
-/*
+/*-
  * Copyright (c) 2011 Rick van der Zwet <info@rickvanderzwet.nl>
  *
@@ -17,5 +16,5 @@
  */
 
-/*
+/*-
  * Copyright (c) 2008 Johann Christian Rode <jcrode@gmx.net>
  *
@@ -33,5 +32,5 @@
  */
 
-/*
+/*-
  * Copyright (c) 2005, 2006, 2007 Jonathan Gray <jsg@openbsd.org>
  *
@@ -49,5 +48,5 @@
  */
 
-/*
+/*-
  * Copyright (c) 1997, 1998, 1999, 2000-2003
  *	Bill Paul <wpaul@windriver.com>.  All rights reserved.
@@ -84,6 +83,6 @@
 
 /*
- * Moschip MCS7730/MCS7830 USB to Ethernet controller 
- * The datasheet is available at the following URL: 
+ * Moschip MCS7730/MCS7830 USB to Ethernet controller
+ * The datasheet is available at the following URL:
  * http://www.moschip.com/data/products/MCS7830/Data%20Sheet_7830.pdf
  */
@@ -96,5 +95,5 @@
  * Mixed together with the OpenBSD if_mos.c driver for validation and checking
  * and the FreeBSD if_reu.c as reference for the USB Ethernet framework.
- */ 
+ */
 
 #include <sys/stdint.h>
@@ -143,6 +142,6 @@
   DPRINTF("mos: %s: " fmt "\n",__FUNCTION__,## __VA_ARGS__)
 
-#define	USB_PRODUCT_MOSCHIP_MCS7730	0x7730		/* MCS7730 Ethernet */
-#define	USB_PRODUCT_SITECOMEU_LN030	0x0021		/* LN-030 */
+#define	USB_PRODUCT_MOSCHIP_MCS7730	0x7730	/* MCS7730 Ethernet */
+#define	USB_PRODUCT_SITECOMEU_LN030	0x0021	/* LN-030 */
 
 
@@ -152,7 +151,7 @@
  */
 static const struct usb_device_id mos_devs[] = {
-	{ USB_VPI(USB_VENDOR_MOSCHIP, USB_PRODUCT_MOSCHIP_MCS7730, MCS7730) },
-	{ USB_VPI(USB_VENDOR_MOSCHIP, USB_PRODUCT_MOSCHIP_MCS7830 , MCS7830) },
-	{ USB_VPI( USB_VENDOR_SITECOMEU, USB_PRODUCT_SITECOMEU_LN030 , MCS7830) },
+	{USB_VPI(USB_VENDOR_MOSCHIP, USB_PRODUCT_MOSCHIP_MCS7730, MCS7730)},
+	{USB_VPI(USB_VENDOR_MOSCHIP, USB_PRODUCT_MOSCHIP_MCS7830, MCS7830)},
+	{USB_VPI(USB_VENDOR_SITECOMEU, USB_PRODUCT_SITECOMEU_LN030, MCS7830)},
 };
 
@@ -170,6 +169,6 @@
 static void mos_chip_init(struct mos_softc *);
 static void mos_stop(struct usb_ether *);
-static int mos_miibus_readreg(device_t , int, int);
-static int mos_miibus_writereg(device_t , int, int, int);
+static int mos_miibus_readreg(device_t, int, int);
+static int mos_miibus_writereg(device_t, int, int, int);
 static void mos_miibus_statchg(device_t);
 static int mos_ifmedia_upd(struct ifnet *);
@@ -214,5 +213,5 @@
 		.direction = UE_DIR_IN,
 		.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
-		.bufsize = 0,	/* use wMaxPacketSize */
+		.bufsize = 0,		/* use wMaxPacketSize */
 		.callback = mos_intr_callback,
 	},
@@ -268,7 +267,7 @@
 mos_reg_read_1(struct mos_softc *sc, int reg)
 {
-	struct usb_device_request	req;
-	usb_error_t 			err;
-	uByte				val = 0;
+	struct usb_device_request req;
+	usb_error_t err;
+	uByte val = 0;
 
 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
@@ -284,5 +283,4 @@
 		return (-1);
 	}
-
 	return (val);
 }
@@ -291,24 +289,23 @@
 mos_reg_read_2(struct mos_softc *sc, int reg)
 {
-	struct usb_device_request	req;
-	usb_error_t 			err;
-	uWord				val;
-
-	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 = uether_do_request(&sc->sc_ue, &req, &val, 1000);
-
-	if (err) {
-		MOS_DPRINTFN("mos_reg_read_2 error, reg: %d", reg);
-		return (-1);
-	}
-
-	return(UGETW(val));
+struct usb_device_request req;
+usb_error_t err;
+uWord val;
+
+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 = uether_do_request(&sc->sc_ue, &req, &val, 1000);
+
+if (err) {
+	MOS_DPRINTFN("mos_reg_read_2 error, reg: %d", reg);
+	return (-1);
+}
+return (UGETW(val));
 }
 
@@ -316,7 +313,7 @@
 mos_reg_write_1(struct mos_softc *sc, int reg, int aval)
 {
-	struct usb_device_request	req;
-	usb_error_t 			err;
-	uByte				val;
+	struct usb_device_request req;
+	usb_error_t err;
+	uByte val;
 
 	val = aval;
@@ -334,6 +331,5 @@
 		return (-1);
 	}
-
-	return(0);
+	return (0);
 }
 
@@ -341,7 +337,7 @@
 mos_reg_write_2(struct mos_softc *sc, int reg, int aval)
 {
-	struct usb_device_request	req;
-	usb_error_t 			err;
-	uWord				val;
+	struct usb_device_request req;
+	usb_error_t err;
+	uWord val;
 
 	USETW(val, aval);
@@ -359,5 +355,4 @@
 		return (-1);
 	}
-
 	return (0);
 }
@@ -366,6 +361,6 @@
 mos_readmac(struct mos_softc *sc, u_char *mac)
 {
-	struct usb_device_request	req;
-	usb_error_t 			err;
+	struct usb_device_request req;
+	usb_error_t err;
 
 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
@@ -380,5 +375,4 @@
 		return (-1);
 	}
-
 	return (0);
 }
@@ -387,6 +381,6 @@
 mos_writemac(struct mos_softc *sc, uint8_t *mac)
 {
-	struct usb_device_request	req;
-	usb_error_t 			err;
+	struct usb_device_request req;
+	usb_error_t err;
 
 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
@@ -402,5 +396,4 @@
 		return (-1);
 	}
-
 	return (0);
 }
@@ -409,6 +402,6 @@
 mos_write_mcast(struct mos_softc *sc, u_char *hashtbl)
 {
-	struct usb_device_request	req;
-	usb_error_t 			err;
+	struct usb_device_request req;
+	usb_error_t err;
 
 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
@@ -422,8 +415,7 @@
 	if (err) {
 		MOS_DPRINTFN("mos_reg_mcast error");
-		return(-1);
-	}
-
-	return(0);
+		return (-1);
+	}
+	return (0);
 }
 
@@ -432,6 +424,6 @@
 {
 	struct mos_softc *sc = device_get_softc(dev);
-	uWord			val;
-	int			i,res, locked;
+	uWord val;
+	int i, res, locked;
 
 	USETW(val, 0);
@@ -454,5 +446,4 @@
 		MOS_DPRINTFN("MII read timeout");
 	}
-
 	res = mos_reg_read_2(sc, MOS_PHY_DATA);
 
@@ -466,5 +457,5 @@
 {
 	struct mos_softc *sc = device_get_softc(dev);
-	int			i, locked;
+	int i, locked;
 
 	locked = mtx_owned(&sc->sc_mtx);
@@ -485,5 +476,4 @@
 		MOS_DPRINTFN("MII write timeout");
 	}
-
 	if (!locked)
 		MOS_UNLOCK(sc);
@@ -496,5 +486,5 @@
 	struct mos_softc *sc = device_get_softc(dev);
 	struct mii_data *mii = GET_MII(sc);
-	int			val, err, locked;
+	int val, err, locked;
 
 	locked = mtx_owned(&sc->sc_mtx);
@@ -516,10 +506,10 @@
 
 	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;
+	case IFM_100_TX:
+		val |= MOS_CTL_SPEEDSEL;
+		break;
+	case IFM_10_T:
+		val &= ~(MOS_CTL_SPEEDSEL);
+		break;
 	}
 
@@ -541,6 +531,6 @@
 mos_ifmedia_upd(struct ifnet *ifp)
 {
-	struct mos_softc	*sc = ifp->if_softc;
-	struct mii_data		*mii = GET_MII(sc);
+	struct mos_softc *sc = ifp->if_softc;
+	struct mii_data *mii = GET_MII(sc);
 
 	MOS_LOCK_ASSERT(sc, MA_OWNED);
@@ -551,5 +541,5 @@
 
 		LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
-			mii_phy_reset(miisc);
+		    mii_phy_reset(miisc);
 	}
 	mii_mediachg(mii);
@@ -563,6 +553,6 @@
 mos_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
 {
-	struct mos_softc	*sc = ifp->if_softc;
-	struct mii_data		*mii = GET_MII(sc);
+	struct mos_softc *sc = ifp->if_softc;
+	struct mii_data *mii = GET_MII(sc);
 
 	MOS_LOCK(sc);
@@ -580,5 +570,5 @@
 	struct ifnet *ifp = uether_getifp(ue);
 
-	u_int8_t		rxmode;
+	u_int8_t rxmode;
 
 	MOS_LOCK_ASSERT(sc, MA_OWNED);
@@ -589,7 +579,7 @@
 	if (ifp->if_flags & IFF_PROMISC) {
 		rxmode |= MOS_CTL_RX_PROMISC;
-        } else {
-                rxmode &= ~MOS_CTL_RX_PROMISC;
-        }
+	} else {
+		rxmode &= ~MOS_CTL_RX_PROMISC;
+	}
 
 	mos_reg_write_1(sc, MOS_CTL, rxmode);
@@ -603,10 +593,10 @@
 	struct mos_softc *sc = uether_getsc(ue);
 	struct ifnet *ifp = uether_getifp(ue);
-	struct ifmultiaddr 	*ifma;
-
-	u_int32_t		h = 0;
-	u_int8_t		rxmode;
-	u_int8_t		hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
-	int			allmulti = 0;
+	struct ifmultiaddr *ifma;
+
+	u_int32_t h = 0;
+	u_int8_t rxmode;
+	u_int8_t hashtbl[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+	int allmulti = 0;
 
 	MOS_LOCK_ASSERT(sc, MA_OWNED);
@@ -625,5 +615,5 @@
 		};
 		h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
-		    ifma->ifma_addr), ETHER_ADDR_LEN)  >> 26;
+		    ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
 		//h = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26;
 		hashtbl[h / 8] |= 1 << (h % 8);
@@ -664,5 +654,5 @@
 mos_chip_init(struct mos_softc *sc)
 {
-	int	i;
+	int i;
 
 	/*
@@ -671,9 +661,9 @@
 	 */
 	if (mos_reg_read_1(sc, MOS_PAUSE_TRHD) != -1) {
-		for (i=0;i<MOS_PAUSE_REWRITES;i++)
+		for (i = 0; i < MOS_PAUSE_REWRITES; i++)
 			mos_reg_write_1(sc, MOS_PAUSE_TRHD, 0);
 	}
-
-	sc->mos_phyaddrs[0] = 1; sc->mos_phyaddrs[1] = 0xFF;
+	sc->mos_phyaddrs[0] = 1;
+	sc->mos_phyaddrs[1] = 0xFF;
 }
 
@@ -691,11 +681,7 @@
 		return (ENXIO);
 	}
-        //uint8_t bIfaceIndex;
-        //uint8_t bIfaceNum;
-        //uint8_t bConfigIndex;
-        //uint8_t bConfigNum;
 
 	if (uaa->info.bConfigNum != MOS_CONFIG_NO) {
-		DPRINTFN(11, "mos: not MOS_CONFIG_NO %i vs %i\n", uaa->info.bConfigNum , MOS_CONFIG_NO);
+		DPRINTFN(11, "mos: not MOS_CONFIG_NO %i vs %i\n", uaa->info.bConfigNum, MOS_CONFIG_NO);
 		return (ENXIO);
 	}
@@ -704,7 +690,7 @@
 		return (ENXIO);
 	}
-
 	DPRINTFN(11, "mos: probe by generic means\n");
 	int retval = usbd_lookup_id_by_uaa(mos_devs, sizeof(mos_devs), uaa);
+
 	DPRINTFN(11, "mos: probe retval: %i (ENXIO:%i)\n", retval, ENXIO);
 	return retval;
@@ -715,5 +701,5 @@
  * setup and ethernet/BPF attach.
  */
-static int 
+static int
 mos_attach(device_t dev)
 {
@@ -739,5 +725,4 @@
 		goto detach;
 	}
-
 	ue->ue_sc = sc;
 	ue->ue_dev = dev;
@@ -752,5 +737,4 @@
 		DPRINTF("model: MCS7830\n");
 	}
-
 	error = uether_ifattach(ue);
 	if (error) {
@@ -771,8 +755,10 @@
 {
 	struct mos_softc *sc = uether_getsc(ue);
+
 	/*
 	 * Read MAC address, inform the world.
 	 */
 	int err = mos_readmac(sc, ue->ue_eaddr);
+
 	if (err) {
 		MOS_DPRINTFN("couldn't get MAC address");
@@ -781,17 +767,4 @@
 
 	mos_chip_init(sc);
-
-	// ifp = GET_IFP(sc);
-	// ifp->if_softc = sc;
-	// ifp->if_flags = IFF_SIMPLEX | IFF_MULTICAST;
-	// ifp->if_ioctl = mos_ioctl;
-	// ifp->if_start = mos_start;
-	// ifp->if_watchdog = mos_watchdog;
-	// strlcpy(ifp->if_xname, sc->mos_dev.dv_xname, IFNAMSIZ);
-
-	// IFQ_SET_READY(&ifp->if_snd);
-	// ifp->if_capabilities = IFCAP_VLAN_MTU;
-
-	sc->mos_attached = 1;
 }
 
@@ -819,11 +792,11 @@
 mos_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
 {
-	struct mos_softc 	*sc = usbd_xfer_softc(xfer);
-	struct usb_ether 	*ue = &sc->sc_ue;
-	struct ifnet 		*ifp = uether_getifp(ue);
-
-	uint8_t 		rxstat = 0;
-	uint32_t		actlen;
-	uint16_t		pktlen = 0;
+	struct mos_softc *sc = usbd_xfer_softc(xfer);
+	struct usb_ether *ue = &sc->sc_ue;
+	struct ifnet *ifp = uether_getifp(ue);
+
+	uint8_t rxstat = 0;
+	uint32_t actlen;
+	uint16_t pktlen = 0;
 	struct usb_page_cache *pc;
 
@@ -836,8 +809,7 @@
 		MOS_DPRINTFN("actlen : %d", actlen);
 		if (actlen <= 1) {
- 			ifp->if_ierrors++;
+			ifp->if_ierrors++;
 			goto tr_setup;
-                }
-
+		}
 		/* evaluate status byte at the end */
 		usbd_copy_out(pc, actlen - sizeof(rxstat), &rxstat,
@@ -857,15 +829,13 @@
 			goto tr_setup;
 		}
-
-                /* Remember the last byte was used for the status fields */
-                pktlen = actlen - 1;
-		if ( pktlen < sizeof(struct ether_header) ) {
-                        MOS_DPRINTFN("error: pktlen %i is smaller than ether_header %i", pktlen, sizeof(struct ether_header));
+		/* Remember the last byte was used for the status fields */
+		pktlen = actlen - 1;
+		if (pktlen < sizeof(struct ether_header)) {
+			MOS_DPRINTFN("error: pktlen %i is smaller than ether_header %i", pktlen, sizeof(struct ether_header));
 			ifp->if_ierrors++;
 			goto tr_setup;
 		}
-
 		uether_rxbuf(ue, pc, 0, actlen);
-  /* FALLTHROUGH */
+		/* FALLTHROUGH */
 	case USB_ST_SETUP:
 tr_setup:
@@ -874,5 +844,5 @@
 		uether_rxflush(ue);
 		return;
-	default: /* Error */
+	default:			/* Error */
 		MOS_DPRINTFN("bulk read error, %s", usbd_errstr(error));
 		if (error != USB_ERR_CANCELLED) {
@@ -912,8 +882,8 @@
 		 */
 		IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
-                if (m == NULL)
-                        return;
-
-	        pc = usbd_xfer_get_frame(xfer, 0);
+		if (m == NULL)
+			return;
+
+		pc = usbd_xfer_get_frame(xfer, 0);
 		usbd_m_copy_in(pc, 0, m, 0, m->m_pkthdr.len);
 
@@ -933,13 +903,13 @@
 		ifp->if_opackets++;
 		return;
-        default: /* Error */
+	default:			/* Error */
 		MOS_DPRINTFN("usb error on tx: %s\n", usbd_errstr(error));
 		ifp->if_oerrors++;
 		if (error != USB_ERR_CANCELLED) {
-		  /* try to clear stall first */
-		  usbd_xfer_set_stall(xfer);
-		  goto tr_setup;
+			/* try to clear stall first */
+			usbd_xfer_set_stall(xfer);
+			goto tr_setup;
 		}
-                return;
+		return;
 	}
 }
@@ -981,5 +951,5 @@
 	struct mos_softc *sc = uether_getsc(ue);
 	struct ifnet *ifp = uether_getifp(ue);
-	u_int8_t		rxmode;
+	u_int8_t rxmode;
 
 	MOS_LOCK_ASSERT(sc, MA_OWNED);
@@ -1003,10 +973,13 @@
 	mos_reg_write_1(sc, MOS_IPG1, sc->mos_ipgs[1]);
 
-	/* Enable receiver and transmitter, bridge controls speed/duplex mode */
+	/*
+	 * Enable receiver and transmitter, bridge controls speed/duplex
+	 * mode
+	 */
 	rxmode = mos_reg_read_1(sc, MOS_CTL);
 	rxmode |= MOS_CTL_RX_ENB | MOS_CTL_TX_ENB | MOS_CTL_BS_ENB;
 	rxmode &= ~(MOS_CTL_SLEEP);
 
-        mos_setpromisc(ue);
+	mos_setpromisc(ue);
 
 	/* XXX: broadcast mode? */
@@ -1029,16 +1002,16 @@
 	struct usb_page_cache *pc;
 	int actlen;
-        long pkt;
+	long pkt;
 
 	ifp->if_oerrors++;
 
 	usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
-        MOS_DPRINTFN("actlen %i", actlen);
+	MOS_DPRINTFN("actlen %i", actlen);
 
 	switch (USB_GET_STATE(xfer)) {
 	case USB_ST_TRANSFERRED:
 
-	        pc = usbd_xfer_get_frame(xfer, 0);
-	        usbd_copy_out(pc, 0, &pkt, sizeof(pkt));
+		pc = usbd_xfer_get_frame(xfer, 0);
+		usbd_copy_out(pc, 0, &pkt, sizeof(pkt));
 		/* FALLTHROUGH */
 	case USB_ST_SETUP:
@@ -1080,3 +1053,2 @@
 	sc->mos_link = 0;
 }
-
Index: /freebsd-mos-driver/if_mosreg.h
===================================================================
--- /freebsd-mos-driver/if_mosreg.h	(revision 272)
+++ /freebsd-mos-driver/if_mosreg.h	(revision 273)
@@ -1,5 +1,4 @@
-/*	$OpenBSD: if_mosreg.h,v 1.3 2008/11/22 09:46:12 deraadt Exp $	*/
-/*
- * Copyright (c) 2010 Rick van der Zwet <info@rickvanderzwet.nl>
+/*-
+ * Copyright (c) 2010, 2011 Rick van der Zwet <info@rickvanderzwet.nl>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -16,5 +15,5 @@
  */
 
-/*
+/*-
  * Copyright (c) 2008 Johann Christian Rode <jcrode@gmx.net>
  *
@@ -32,5 +31,5 @@
  */
 
-/*
+/*-
  * Copyright (c) 1997, 1998, 1999, 2000-2003
  *	Bill Paul <wpaul@windriver.com>.  All rights reserved.
@@ -151,30 +150,8 @@
 #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 MOS_INC(x, y)           (x) = (x + 1) % y
-
-//struct mos_softc;
-//
-struct mos_chain {
-	char			*mos_buf;
-	struct mbuf		*mos_mbuf;
-	int			mos_accum;
-	int			mos_idx;
-};
-//
-//struct mos_cdata {
-//	struct mos_chain	mos_tx_chain[MOS_TX_LIST_CNT];
-//	struct mos_chain	mos_rx_chain[MOS_RX_LIST_CNT];
-//	int			mos_tx_prod;
-//	int			mos_tx_cons;
-//	int			mos_tx_cnt;
-//	int			mos_rx_prod;
-//};
 
 struct mos_softc {
@@ -182,40 +159,12 @@
         struct ifnet            ifp;
 
-//	struct device		mos_dev;
-//#define GET_MII(sc) (&(sc)->mos_mii)
-//#define GET_IFP(sc) (&(sc)->arpcom.ac_if)
-//	struct mii_data		mos_mii;
-//	usbd_device_handle	mos_udev;
-//	usbd_interface_handle	mos_iface;
-
 	u_int16_t		mos_flags;
-
-//	int			mos_ed[MOS_ENDPT_MAX];
-//	usbd_pipe_handle	mos_ep[MOS_ENDPT_MAX];
-	int			mos_unit;
-	int			mos_if_flags;
-//	struct mos_cdata	mos_cdata;
-//	struct timeout		mos_stat_ch;
-
-	int			mos_refcnt;
-	char			mos_dying;
-	char			mos_attached;
 
 	int			mos_link;
 	unsigned char		mos_ipgs[2];
 	unsigned char 		mos_phyaddrs[2];
-	struct timeval		mos_rx_notice;
-
-	u_int16_t		mos_tspeed;
-	u_int16_t		mos_maxpacket;
-
-//	struct usb_task		mos_tick_task;
-//	struct usb_task		mos_stop_task;
-
 
 	struct mtx		sc_mtx;
 	struct usb_xfer	*sc_xfer[MOS_ENDPT_MAX];
-
-	u_int			mos_bufsz;
 };
 
