Index: /freebsd-mos-driver/if_mos.c
===================================================================
--- /freebsd-mos-driver/if_mos.c	(revision 270)
+++ /freebsd-mos-driver/if_mos.c	(revision 271)
@@ -131,4 +131,7 @@
 #endif
 
+#define MOS_DPRINTFN(fmt,...) \
+  DPRINTF("mos: %s: " fmt "\n",__FUNCTION__,## __VA_ARGS__)
+
 #define	USB_PRODUCT_MOSCHIP_MCS7730	0x7730		/* MCS7730 Ethernet */
 #define	USB_PRODUCT_SITECOMEU_LN030	0x0021		/* LN-030 */
@@ -145,35 +148,34 @@
 };
 
-int mos_probe(device_t dev);
-int mos_attach(device_t dev);
-void mos_attach_post(struct usb_ether *ue);
-int mos_detach(device_t dev);
-
-int mos_encap(struct mos_softc *, struct mbuf *, int);
-void mos_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error);
-void mos_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error);
-void mos_intr_callback(struct usb_xfer *xfer, usb_error_t error);
-void mos_tick(struct usb_ether *);
-void mos_start(struct usb_ether *);
-void mos_init(struct usb_ether *);
-void mos_chip_init(struct mos_softc *);
-void mos_stop(struct usb_ether *);
-void mos_watchdog(struct usb_ether *);
-int mos_miibus_readreg(device_t , int, int);
-int mos_miibus_writereg(device_t , int, int, int);
-void mos_miibus_statchg(device_t);
-int mos_ifmedia_upd(struct ifnet *);
-void mos_ifmedia_sts(struct ifnet *, struct ifmediareq *);
-void mos_reset(struct mos_softc *sc);
-
-int mos_reg_read_1(struct mos_softc *, int);
-int mos_reg_read_2(struct mos_softc *, int);
-int mos_reg_write_1(struct mos_softc *, int, int);
-int mos_reg_write_2(struct mos_softc *, int, int);
-int mos_readmac(struct mos_softc *, uint8_t *);
-int mos_writemac(struct mos_softc *, uint8_t *);
-int mos_write_mcast(struct mos_softc *, u_char *);
-
-void mos_setmulti(struct usb_ether *);
+static int mos_probe(device_t dev);
+static int mos_attach(device_t dev);
+static void mos_attach_post(struct usb_ether *ue);
+static int mos_detach(device_t dev);
+
+static void mos_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error);
+static void mos_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error);
+static void mos_intr_callback(struct usb_xfer *xfer, usb_error_t error);
+static void mos_tick(struct usb_ether *);
+static void mos_start(struct usb_ether *);
+static void mos_init(struct usb_ether *);
+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 void mos_miibus_statchg(device_t);
+static int mos_ifmedia_upd(struct ifnet *);
+static void mos_ifmedia_sts(struct ifnet *, struct ifmediareq *);
+static void mos_reset(struct mos_softc *sc);
+
+static int mos_reg_read_1(struct mos_softc *, int);
+static int mos_reg_read_2(struct mos_softc *, int);
+static int mos_reg_write_1(struct mos_softc *, int, int);
+static int mos_reg_write_2(struct mos_softc *, int, int);
+static int mos_readmac(struct mos_softc *, uint8_t *);
+static int mos_writemac(struct mos_softc *, uint8_t *);
+static int mos_write_mcast(struct mos_softc *, u_char *);
+
+static void mos_setmulti(struct usb_ether *);
+static void mos_setpromisc(struct usb_ether *);
 
 static const struct usb_config mos_config[MOS_ENDPT_MAX] = {
@@ -248,5 +250,5 @@
 	.ue_tick = mos_tick,
 	.ue_setmulti = mos_setmulti,
-	//.ue_setpromisc = mos_setpromisc,
+	.ue_setpromisc = mos_setpromisc,
 	.ue_mii_upd = mos_ifmedia_upd,
 	.ue_mii_sts = mos_ifmedia_sts,
@@ -254,5 +256,5 @@
 
 
-int
+static int
 mos_reg_read_1(struct mos_softc *sc, int reg)
 {
@@ -270,5 +272,5 @@
 
 	if (err) {
-		DPRINTF("mos_reg_read_1 error, reg: %d\n", reg);
+		MOS_DPRINTFN("mos_reg_read_1 error, reg: %d\n", reg);
 		return (-1);
 	}
@@ -277,5 +279,5 @@
 }
 
-int
+static int
 mos_reg_read_2(struct mos_softc *sc, int reg)
 {
@@ -295,5 +297,5 @@
 
 	if (err) {
-		DPRINTF("mos_reg_read_2 error, reg: %d\n", reg);
+		MOS_DPRINTFN("mos_reg_read_2 error, reg: %d", reg);
 		return (-1);
 	}
@@ -302,5 +304,5 @@
 }
 
-int
+static int
 mos_reg_write_1(struct mos_softc *sc, int reg, int aval)
 {
@@ -320,5 +322,5 @@
 
 	if (err) {
-		DPRINTF("mos_reg_write_1 error, reg: %d\n", reg);
+		MOS_DPRINTFN("mos_reg_write_1 error, reg: %d", reg);
 		return (-1);
 	}
@@ -327,5 +329,5 @@
 }
 
-int
+static int
 mos_reg_write_2(struct mos_softc *sc, int reg, int aval)
 {
@@ -345,5 +347,5 @@
 
 	if (err) {
-		DPRINTF("mos_reg_write_2 error, reg: %d\n", reg);
+		MOS_DPRINTFN("mos_reg_write_2 error, reg: %d", reg);
 		return (-1);
 	}
@@ -352,5 +354,5 @@
 }
 
-int
+static int
 mos_readmac(struct mos_softc *sc, u_char *mac)
 {
@@ -373,5 +375,5 @@
 }
 
-int
+static int
 mos_writemac(struct mos_softc *sc, uint8_t *mac)
 {
@@ -388,5 +390,5 @@
 
 	if (err) {
-		DPRINTF("mos_writemac error");
+		MOS_DPRINTFN("mos_writemac error");
 		return (-1);
 	}
@@ -395,5 +397,5 @@
 }
 
-int
+static int
 mos_write_mcast(struct mos_softc *sc, u_char *hashtbl)
 {
@@ -410,5 +412,5 @@
 
 	if (err) {
-		DPRINTF("mos_reg_mcast error\n");
+		MOS_DPRINTFN("mos_reg_mcast error");
 		return(-1);
 	}
@@ -417,5 +419,5 @@
 }
 
-int
+static int
 mos_miibus_readreg(struct device *dev, int phy, int reg)
 {
@@ -441,5 +443,5 @@
 	}
 	if (i == MOS_TIMEOUT) {
-		DPRINTF("%s: %s: MII read timeout\n", "mos", __func__);
+		MOS_DPRINTFN("MII read timeout");
 	}
 
@@ -451,10 +453,9 @@
 }
 
-int
+static int
 mos_miibus_writereg(device_t dev, int phy, int reg, int val)
 {
 	struct mos_softc *sc = device_get_softc(dev);
 	int			i, locked;
-	DPRINTF("%s enter\n", __func__);
 
 	locked = mtx_owned(&sc->sc_mtx);
@@ -473,5 +474,5 @@
 	}
 	if (i == MOS_TIMEOUT) {
-		DPRINTF("%s: MII write timeout\n", "mos");
+		MOS_DPRINTFN("MII write timeout");
 	}
 
@@ -481,5 +482,5 @@
 }
 
-void
+static void
 mos_miibus_statchg(device_t dev)
 {
@@ -487,5 +488,4 @@
 	struct mii_data *mii = GET_MII(sc);
 	int			val, err, locked;
-	DPRINTF("%s enter\n", __func__);
 
 	locked = mtx_owned(&sc->sc_mtx);
@@ -520,5 +520,5 @@
 
 	if (err)
-		DPRINTF("%s: media change failed\n", "mos");
+		MOS_DPRINTFN("media change failed");
 
 	if (!locked)
@@ -529,5 +529,5 @@
  * Set media options.
  */
-int
+static int
 mos_ifmedia_upd(struct ifnet *ifp)
 {
@@ -551,5 +551,5 @@
  * Report current media status.
  */
-void
+static void
 mos_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
 {
@@ -565,5 +565,29 @@
 }
 
-void
+static void
+mos_setpromisc(struct usb_ether *ue)
+{
+	struct mos_softc *sc = uether_getsc(ue);
+	struct ifnet *ifp = uether_getifp(ue);
+
+	u_int8_t		rxmode;
+
+	MOS_LOCK_ASSERT(sc, MA_OWNED);
+
+	rxmode = mos_reg_read_1(sc, MOS_CTL);
+
+	/* If we want promiscuous mode, set the allframes bit. */
+	if (ifp->if_flags & IFF_PROMISC) {
+		rxmode |= MOS_CTL_RX_PROMISC;
+        } else {
+                rxmode &= ~MOS_CTL_RX_PROMISC;
+        }
+
+	mos_reg_write_1(sc, MOS_CTL, rxmode);
+}
+
+
+
+static void
 mos_setmulti(struct usb_ether *ue)
 {
@@ -576,5 +600,4 @@
 	u_int8_t		hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
 	int			allmulti = 0;
-	DPRINTF("%s enter\n", __func__);
 
 	MOS_LOCK_ASSERT(sc, MA_OWNED);
@@ -610,9 +633,8 @@
 }
 
-void
+static void
 mos_reset(struct mos_softc *sc)
 {
 	u_int8_t ctl;
-	DPRINTF("%s enter\n", __func__);
 
 	ctl = mos_reg_read_1(sc, MOS_CTL);
@@ -630,9 +652,8 @@
 }
 
-void
+static void
 mos_chip_init(struct mos_softc *sc)
 {
 	int	i;
-	DPRINTF("%s enter\n", __func__);
 
 	/*
@@ -651,5 +672,5 @@
  * Probe for a MCS7x30 chip.
  */
-int
+static int
 mos_probe(device_t dev)
 {
@@ -685,5 +706,5 @@
  * setup and ethernet/BPF attach.
  */
-int 
+static int 
 mos_attach(device_t dev)
 {
@@ -737,5 +758,5 @@
 
 
-void
+static void
 mos_attach_post(struct usb_ether *ue)
 {
@@ -746,7 +767,7 @@
 	int err = mos_readmac(sc, ue->ue_eaddr);
 	if (err) {
-		DPRINTF("couldn't get MAC address\n");
-	}
-	DPRINTF("address: %s\n", ether_sprintf(ue->ue_eaddr));
+		MOS_DPRINTFN("couldn't get MAC address");
+	}
+	MOS_DPRINTFN("address: %s", ether_sprintf(ue->ue_eaddr));
 
 	mos_chip_init(sc);
@@ -766,5 +787,5 @@
 }
 
-int
+static int
 mos_detach(device_t dev)
 {
@@ -786,5 +807,5 @@
  * the higher level protocols.
  */
-void
+static void
 mos_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
 {
@@ -798,5 +819,4 @@
 	struct usb_page_cache *pc;
 
-	DPRINTF("%s: %s: enter\n", "mos",__func__);
 
 	usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
@@ -805,5 +825,5 @@
 	switch (USB_GET_STATE(xfer)) {
 	case USB_ST_TRANSFERRED:
-		DPRINTF("read_callback actlen : %d\n", actlen);
+		MOS_DPRINTFN("actlen : %d", actlen);
 		if (actlen <= 1) {
  			ifp->if_ierrors++;
@@ -816,14 +836,13 @@
 
 		if (rxstat != MOS_RXSTS_VALID) {
-			DPRINTF("%s: erroneous frame received: ", 
-			    "mos");
+			MOS_DPRINTFN("erroneous frame received");
 			if (rxstat & MOS_RXSTS_SHORT_FRAME)
-				DPRINTF("frame size less than 64 bytes\n");
+				MOS_DPRINTFN("frame size less than 64 bytes");
 			if (rxstat & MOS_RXSTS_LARGE_FRAME)
-				DPRINTF("frame size larger than 1532 bytes\n");
+				MOS_DPRINTFN("frame size larger than 1532 bytes");
 			if (rxstat & MOS_RXSTS_CRC_ERROR)
-				DPRINTF("CRC error\n");
+				MOS_DPRINTFN("CRC error");
 			if (rxstat & MOS_RXSTS_ALIGN_ERROR)
-				DPRINTF("alignment error\n");
+				MOS_DPRINTFN("alignment error");
 			ifp->if_ierrors++;
 			goto tr_setup;
@@ -833,5 +852,5 @@
                 pktlen = actlen - 1;
 		if ( pktlen < sizeof(struct ether_header) ) {
-                        DPRINTF("mos: pktlen %i is smaller than ether_header %i\n", 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;
@@ -847,5 +866,5 @@
 		return;
 	default: /* Error */
-		DPRINTF("bulk read error, %s\n", usbd_errstr(error));
+		MOS_DPRINTFN("bulk read error, %s", usbd_errstr(error));
 		if (error != USB_ERR_CANCELLED) {
 			/* try to clear stall first */
@@ -853,5 +872,5 @@
 			goto tr_setup;
 		}
-		DPRINTF("start rx %i\n", usbd_xfer_max_len(xfer));
+		MOS_DPRINTFN("start rx %i", usbd_xfer_max_len(xfer));
 		return;
 	}
@@ -863,5 +882,5 @@
  */
 
-void
+static void
 mos_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
 {
@@ -871,10 +890,9 @@
 	struct mbuf *m;
 
-	DPRINTF("%s: %s: enter\n", "mos",__func__);
 
 
 	switch (USB_GET_STATE(xfer)) {
 	case USB_ST_TRANSFERRED:
-		DPRINTF("transfer of complete\n");
+		MOS_DPRINTFN("transfer of complete");
 		ifp->if_opackets++;
 		/* FALLTHROUGH */
@@ -907,5 +925,5 @@
 		return;
         default: /* Error */
-		DPRINTF("%s: usb error on tx: %s\n", "mos", usbd_errstr(error));
+		MOS_DPRINTFN("usb error on tx: %s\n", usbd_errstr(error));
 		ifp->if_oerrors++;
 		if (error != USB_ERR_CANCELLED) {
@@ -918,5 +936,5 @@
 }
 
-void
+static void
 mos_tick(struct usb_ether *ue)
 {
@@ -925,11 +943,9 @@
 
 	MOS_LOCK_ASSERT(sc, MA_OWNED);
-	DPRINTF("%s: %s: enter\n", "mos", __func__);
 
 	mii_tick(mii);
 	if (!sc->mos_link && mii->mii_media_status & IFM_ACTIVE &&
 	    IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
-		DPRINTF("%s: %s: got link\n",
-			 "mos", __func__);
+		MOS_DPRINTFN("got link");
 		sc->mos_link++;
 		mos_start(ue);
@@ -938,35 +954,5 @@
 
 
-//int
-//mos_encap(struct mos_softc *sc, struct mbuf *m, int idx)
-//{
-//	struct mos_chain	*c;
-//	int err;
-//	int			length;
-//
-//	c = &sc->mos_cdata.mos_tx_chain[idx];
-//
-//	m_copydata(m, 0, m->m_pkthdr.len, c->mos_buf);
-//	length = m->m_pkthdr.len;
-//
-//	c->mos_mbuf = m;
-//
-//	usbd_setup_xfer(c->mos_xfer, sc->mos_ep[MOS_ENDPT_TX],
-//	    c, c->mos_buf, length, USBD_FORCE_SHORT_XFER | USBD_NO_COPY,
-//	    10000, mos_txeof);
-//
-//	/* Transmit */
-//	err = usbd_transfer(c->mos_xfer);
-//	if (err != USBD_IN_PROGRESS) {
-//		mos_stop(sc);
-//		return(EIO);
-//	}
-//
-//	sc->mos_cdata.mos_tx_cnt++;
-//
-//	return(0);
-//}
-
-void
+static void
 mos_start(struct usb_ether *ue)
 {
@@ -981,5 +967,5 @@
 }
 
-void
+static void
 mos_init(struct usb_ether *ue)
 {
@@ -987,5 +973,4 @@
 	struct ifnet *ifp = uether_getifp(ue);
 	u_int8_t		rxmode;
-	DPRINTF("%s enter\n", __func__);
 
 	MOS_LOCK_ASSERT(sc, MA_OWNED);
@@ -1014,7 +999,5 @@
 	rxmode &= ~(MOS_CTL_SLEEP);
 
-	/* If we want promiscuous mode, set the allframes bit. */
-	if (ifp->if_flags & IFF_PROMISC)
-		rxmode |= MOS_CTL_RX_PROMISC;
+        mos_setpromisc(ue);
 
 	/* XXX: broadcast mode? */
@@ -1030,5 +1013,5 @@
 
 
-void
+static void
 mos_intr_callback(struct usb_xfer *xfer, usb_error_t error)
 {
@@ -1039,14 +1022,11 @@
         long pkt;
 
-	//DPRINTF("%s: %s: enter\n", "mos", __func__);
 	ifp->if_oerrors++;
 
 	usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
-        DPRINTF("%s: %s: actlen %i\n", "mos", __func__, actlen);
-
-	//XXX: Porting, how? mos_txeof(c->mos_xfer, c, stat);
+        MOS_DPRINTFN("actlen %i", actlen);
+
 	switch (USB_GET_STATE(xfer)) {
 	case USB_ST_TRANSFERRED:
-                DPRINTF("State is ST_TRANS\n");
 
 	        pc = usbd_xfer_get_frame(xfer, 0);
@@ -1055,10 +1035,6 @@
 	case USB_ST_SETUP:
 tr_setup:
-                DPRINTF("State is ST_SETUP\n");
-		//usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
-		//usbd_transfer_submit(xfer);
 		return;
 	default:			/* Error */
-                DPRINTF("State is default\n");
 		if (error != USB_ERR_CANCELLED) {
 			/* try to clear stall first */
@@ -1075,5 +1051,5 @@
  * RX and TX lists.
  */
-void
+static void
 mos_stop(struct usb_ether *ue)
 {
