svn commit: r229344 - in stable/8/sys: conf dev/usb/net

Pyun YongHyeon yongari at FreeBSD.org
Mon Jan 2 23:47:51 UTC 2012


Author: yongari
Date: Mon Jan  2 23:47:51 2012
New Revision: 229344
URL: http://svn.freebsd.org/changeset/base/229344

Log:
  MFC r226709:
    This change makes it possible to define driver specific attach
    handler such that driver can announce interface capabilities and
    can do its own MII attach.  Currently all USB ethernet controllers
    have no way to establish a link with pause capabilities. Lack of
    checksum offloading support also was one of reason to bring this
    change in.
  
    This change adds a couple of wrappers to USB ethernet drivers
    (uether_ifmedia_upd, uether_init and uether_start). All exported
    functions in uether has prefix uether_ so I think it's more
    consistent to have wrappers that follow the convention.
    This change preserves ABI/KPI so it should be safe to merge this
    change to stable/8.
  
    While I'm here add missing __FBSDID and clean up headers.

Modified:
  stable/8/sys/dev/usb/net/usb_ethernet.c
  stable/8/sys/dev/usb/net/usb_ethernet.h
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/conf/ldscript.mips.octeon1.32   (props changed)
  stable/8/sys/conf/ldscript.mips.octeon1.64   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)

Modified: stable/8/sys/dev/usb/net/usb_ethernet.c
==============================================================================
--- stable/8/sys/dev/usb/net/usb_ethernet.c	Mon Jan  2 23:44:07 2012	(r229343)
+++ stable/8/sys/dev/usb/net/usb_ethernet.c	Mon Jan  2 23:47:51 2012	(r229344)
@@ -24,24 +24,32 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/stdint.h>
-#include <sys/stddef.h>
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
 #include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/types.h>
 #include <sys/systm.h>
-#include <sys/kernel.h>
 #include <sys/bus.h>
-#include <sys/module.h>
+#include <sys/condvar.h>
+#include <sys/kernel.h>
 #include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/module.h>
 #include <sys/mutex.h>
-#include <sys/condvar.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
 #include <sys/sysctl.h>
 #include <sys/sx.h>
-#include <sys/unistd.h>
-#include <sys/callout.h>
-#include <sys/malloc.h>
-#include <sys/priv.h>
+
+#include <net/if.h>
+#include <net/ethernet.h>
+#include <net/if_types.h>
+#include <net/if_media.h>
+#include <net/if_vlan_var.h>
+
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
@@ -197,42 +205,53 @@ ue_attach_post_task(struct usb_proc_msg 
 	usb_callout_init_mtx(&ue->ue_watchdog, ue->ue_mtx, 0);
 	sysctl_ctx_init(&ue->ue_sysctl_ctx);
 
+	error = 0;
 	ifp = if_alloc(IFT_ETHER);
 	if (ifp == NULL) {
 		device_printf(ue->ue_dev, "could not allocate ifnet\n");
-		goto error;
+		goto fail;
 	}
 
 	ifp->if_softc = ue;
 	if_initname(ifp, "ue", ue->ue_unit);
-	ifp->if_mtu = ETHERMTU;
-	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
-	if (ue->ue_methods->ue_ioctl != NULL)
-		ifp->if_ioctl = ue->ue_methods->ue_ioctl;
-	else
-		ifp->if_ioctl = uether_ioctl;
-	ifp->if_start = ue_start;
-	ifp->if_init = ue_init;
-	IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
-	ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
-	IFQ_SET_READY(&ifp->if_snd);
-	ue->ue_ifp = ifp;
-
-	if (ue->ue_methods->ue_mii_upd != NULL && 
-	    ue->ue_methods->ue_mii_sts != NULL) {
-		mtx_lock(&Giant);	/* device_xxx() depends on this */
-		error = mii_attach(ue->ue_dev, &ue->ue_miibus, ifp,
-		    ue_ifmedia_upd, ue->ue_methods->ue_mii_sts,
-		    BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0);
-		mtx_unlock(&Giant);
-		if (error) {
-			device_printf(ue->ue_dev, "attaching PHYs failed\n");
-			goto error;
+	if (ue->ue_methods->ue_attach_post_sub != NULL) {
+		ue->ue_ifp = ifp;
+		error = ue->ue_methods->ue_attach_post_sub(ue);
+	} else {
+		ifp->if_mtu = ETHERMTU;
+		ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
+		if (ue->ue_methods->ue_ioctl != NULL)
+			ifp->if_ioctl = ue->ue_methods->ue_ioctl;
+		else
+			ifp->if_ioctl = uether_ioctl;
+		ifp->if_start = ue_start;
+		ifp->if_init = ue_init;
+		IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
+		ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
+		IFQ_SET_READY(&ifp->if_snd);
+		ue->ue_ifp = ifp;
+
+		if (ue->ue_methods->ue_mii_upd != NULL &&
+		    ue->ue_methods->ue_mii_sts != NULL) {
+			/* device_xxx() depends on this */
+			mtx_lock(&Giant);
+			error = mii_attach(ue->ue_dev, &ue->ue_miibus, ifp,
+			    ue_ifmedia_upd, ue->ue_methods->ue_mii_sts,
+			    BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0);
+			mtx_unlock(&Giant);
 		}
 	}
 
+	if (error) {
+		device_printf(ue->ue_dev, "attaching PHYs failed\n");
+		goto fail;
+	}
+
 	if_printf(ifp, "<USB Ethernet> on %s\n", device_get_nameunit(ue->ue_dev));
 	ether_ifattach(ifp, ue->ue_eaddr);
+	/* Tell upper layer we support VLAN oversized frames. */
+	if (ifp->if_capabilities & IFCAP_VLAN_MTU)
+		ifp->if_hdrlen = sizeof(struct ether_vlan_header);
 
 	snprintf(num, sizeof(num), "%u", ue->ue_unit);
 	ue->ue_sysctl_oid = SYSCTL_ADD_NODE(&ue->ue_sysctl_ctx,
@@ -246,7 +265,7 @@ ue_attach_post_task(struct usb_proc_msg 
 	UE_LOCK(ue);
 	return;
 
-error:
+fail:
 	free_unr(ueunit, ue->ue_unit);
 	if (ue->ue_ifp != NULL) {
 		if_free(ue->ue_ifp);
@@ -307,6 +326,13 @@ uether_is_gone(struct usb_ether *ue)
 	return (usb_proc_is_gone(&ue->ue_tq));
 }
 
+void
+uether_init(void *arg)
+{
+
+	ue_init(arg);
+}
+
 static void
 ue_init(void *arg)
 {
@@ -352,6 +378,13 @@ ue_stop_task(struct usb_proc_msg *_task)
 	ue->ue_methods->ue_stop(ue);
 }
 
+void
+uether_start(struct ifnet *ifp)
+{
+
+	ue_start(ifp);
+}
+
 static void
 ue_start(struct ifnet *ifp)
 {
@@ -385,6 +418,13 @@ ue_setmulti_task(struct usb_proc_msg *_t
 	ue->ue_methods->ue_setmulti(ue);
 }
 
+int
+uether_ifmedia_upd(struct ifnet *ifp)
+{
+
+	return (ue_ifmedia_upd(ifp));
+}
+
 static int
 ue_ifmedia_upd(struct ifnet *ifp)
 {

Modified: stable/8/sys/dev/usb/net/usb_ethernet.h
==============================================================================
--- stable/8/sys/dev/usb/net/usb_ethernet.h	Mon Jan  2 23:44:07 2012	(r229343)
+++ stable/8/sys/dev/usb/net/usb_ethernet.h	Mon Jan  2 23:47:51 2012	(r229344)
@@ -22,6 +22,8 @@
  * 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$
  */
 
 #ifndef _USB_ETHERNET_H_
@@ -66,7 +68,7 @@ struct usb_ether_methods {
 	void			(*ue_mii_sts)(struct ifnet *,
 				    struct ifmediareq *);
 	int			(*ue_ioctl)(struct ifnet *, u_long, caddr_t);
-
+	int			(*ue_attach_post_sub)(struct usb_ether *);
 };
 
 struct usb_ether_cfg_task {
@@ -110,6 +112,8 @@ struct mii_data *uether_getmii(struct us
 void		*uether_getsc(struct usb_ether *);
 int		uether_ifattach(struct usb_ether *);
 void		uether_ifdetach(struct usb_ether *);
+int		uether_ifmedia_upd(struct ifnet *);
+void		uether_init(void *);
 int		uether_ioctl(struct ifnet *, u_long, caddr_t);
 struct mbuf	*uether_newbuf(void);
 int		uether_rxmbuf(struct usb_ether *, struct mbuf *, 
@@ -119,4 +123,5 @@ int		uether_rxbuf(struct usb_ether *,
 		    unsigned int, unsigned int);
 void		uether_rxflush(struct usb_ether *);
 uint8_t		uether_is_gone(struct usb_ether *);
+void		uether_start(struct ifnet *);
 #endif					/* _USB_ETHERNET_H_ */


More information about the svn-src-all mailing list