git: 2fda7967b6d0 - main - Mechanically convert usb_ethernet(4) to IfAPI
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 07 Feb 2023 19:18:06 UTC
The branch main has been updated by jhibbits: URL: https://cgit.FreeBSD.org/src/commit/?id=2fda7967b6d067a7a4a792913d46bd41272830b9 commit 2fda7967b6d067a7a4a792913d46bd41272830b9 Author: Justin Hibbits <jhibbits@FreeBSD.org> AuthorDate: 2022-03-01 19:19:18 +0000 Commit: Justin Hibbits <jhibbits@FreeBSD.org> CommitDate: 2023-02-07 19:15:45 +0000 Mechanically convert usb_ethernet(4) to IfAPI Reviewed by: zlei Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D37802 --- sys/dev/usb/net/usb_ethernet.c | 77 +++++++++++++++++++++--------------------- sys/dev/usb/net/usb_ethernet.h | 18 +++++----- 2 files changed, 47 insertions(+), 48 deletions(-) diff --git a/sys/dev/usb/net/usb_ethernet.c b/sys/dev/usb/net/usb_ethernet.c index 71f4db0cf61a..172bfb15cbc3 100644 --- a/sys/dev/usb/net/usb_ethernet.c +++ b/sys/dev/usb/net/usb_ethernet.c @@ -81,8 +81,8 @@ static usb_proc_callback_t ue_start_task; static usb_proc_callback_t ue_stop_task; static void ue_init(void *); -static void ue_start(struct ifnet *); -static int ue_ifmedia_upd(struct ifnet *); +static void ue_start(if_t); +static int ue_ifmedia_upd(if_t); static void ue_watchdog(void *); /* @@ -132,7 +132,7 @@ ue_queue_command(struct usb_ether *ue, usb_proc_mwait(&ue->ue_tq, t0, t1); } -struct ifnet * +if_t uether_getifp(struct usb_ether *ue) { return (ue->ue_ifp); @@ -207,7 +207,7 @@ ue_attach_post_task(struct usb_proc_msg *_task) struct usb_ether_cfg_task *task = (struct usb_ether_cfg_task *)_task; struct usb_ether *ue = task->ue; - struct ifnet *ifp; + if_t ifp; int error; char num[14]; /* sufficient for 32 bits */ @@ -229,22 +229,21 @@ ue_attach_post_task(struct usb_proc_msg *_task) goto fail; } - ifp->if_softc = ue; + if_setsoftc(ifp, ue); if_initname(ifp, "ue", ue->ue_unit); 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_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST); if (ue->ue_methods->ue_ioctl != NULL) - ifp->if_ioctl = ue->ue_methods->ue_ioctl; + if_setioctlfn(ifp, 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); + if_setioctlfn(ifp, uether_ioctl); + if_setstartfn(ifp, ue_start); + if_setinitfn(ifp, ue_init); + if_setsendqlen(ifp, ifqmaxlen); + if_setsendqready(ifp); ue->ue_ifp = ifp; if (ue->ue_methods->ue_mii_upd != NULL && @@ -265,8 +264,8 @@ ue_attach_post_task(struct usb_proc_msg *_task) 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); + if (if_getcapabilities(ifp) & IFCAP_VLAN_MTU) + if_setifheaderlen(ifp, sizeof(struct ether_vlan_header)); CURVNET_RESTORE(); @@ -301,7 +300,7 @@ fail: void uether_ifdetach(struct usb_ether *ue) { - struct ifnet *ifp; + if_t ifp; /* wait for any post attach or other command to complete */ usb_proc_drain(&ue->ue_tq); @@ -312,7 +311,7 @@ uether_ifdetach(struct usb_ether *ue) if (ifp != NULL) { /* we are not running any more */ UE_LOCK(ue); - ifp->if_drv_flags &= ~IFF_DRV_RUNNING; + if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING); UE_UNLOCK(ue); /* drain any callouts */ @@ -379,13 +378,13 @@ ue_start_task(struct usb_proc_msg *_task) struct usb_ether_cfg_task *task = (struct usb_ether_cfg_task *)_task; struct usb_ether *ue = task->ue; - struct ifnet *ifp = ue->ue_ifp; + if_t ifp = ue->ue_ifp; UE_LOCK_ASSERT(ue, MA_OWNED); ue->ue_methods->ue_init(ue); - if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) + if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0) return; if (ue->ue_methods->ue_tick != NULL) @@ -407,18 +406,18 @@ ue_stop_task(struct usb_proc_msg *_task) } void -uether_start(struct ifnet *ifp) +uether_start(if_t ifp) { ue_start(ifp); } static void -ue_start(struct ifnet *ifp) +ue_start(if_t ifp) { - struct usb_ether *ue = ifp->if_softc; + struct usb_ether *ue = if_getsoftc(ifp); - if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) + if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0) return; UE_LOCK(ue); @@ -447,16 +446,16 @@ ue_setmulti_task(struct usb_proc_msg *_task) } int -uether_ifmedia_upd(struct ifnet *ifp) +uether_ifmedia_upd(if_t ifp) { return (ue_ifmedia_upd(ifp)); } static int -ue_ifmedia_upd(struct ifnet *ifp) +ue_ifmedia_upd(if_t ifp) { - struct usb_ether *ue = ifp->if_softc; + struct usb_ether *ue = if_getsoftc(ifp); /* Defer to process context */ UE_LOCK(ue); @@ -474,7 +473,7 @@ ue_ifmedia_task(struct usb_proc_msg *_task) struct usb_ether_cfg_task *task = (struct usb_ether_cfg_task *)_task; struct usb_ether *ue = task->ue; - struct ifnet *ifp = ue->ue_ifp; + if_t ifp = ue->ue_ifp; ue->ue_methods->ue_mii_upd(ifp); } @@ -483,9 +482,9 @@ static void ue_watchdog(void *arg) { struct usb_ether *ue = arg; - struct ifnet *ifp = ue->ue_ifp; + if_t ifp = ue->ue_ifp; - if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) + if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0) return; ue_queue_command(ue, ue_tick_task, @@ -501,18 +500,18 @@ ue_tick_task(struct usb_proc_msg *_task) struct usb_ether_cfg_task *task = (struct usb_ether_cfg_task *)_task; struct usb_ether *ue = task->ue; - struct ifnet *ifp = ue->ue_ifp; + if_t ifp = ue->ue_ifp; - if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) + if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0) return; ue->ue_methods->ue_tick(ue); } int -uether_ioctl(struct ifnet *ifp, u_long command, caddr_t data) +uether_ioctl(if_t ifp, u_long command, caddr_t data) { - struct usb_ether *ue = ifp->if_softc; + struct usb_ether *ue = if_getsoftc(ifp); struct ifreq *ifr = (struct ifreq *)data; struct mii_data *mii; int error = 0; @@ -520,8 +519,8 @@ uether_ioctl(struct ifnet *ifp, u_long command, caddr_t data) switch (command) { case SIOCSIFFLAGS: UE_LOCK(ue); - if (ifp->if_flags & IFF_UP) { - if (ifp->if_drv_flags & IFF_DRV_RUNNING) + if (if_getflags(ifp) & IFF_UP) { + if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) ue_queue_command(ue, ue_promisc_task, &ue->ue_promisc_task[0].hdr, &ue->ue_promisc_task[1].hdr); @@ -598,7 +597,7 @@ int uether_rxmbuf(struct usb_ether *ue, struct mbuf *m, unsigned len) { - struct ifnet *ifp = ue->ue_ifp; + if_t ifp = ue->ue_ifp; UE_LOCK_ASSERT(ue, MA_OWNED); @@ -616,7 +615,7 @@ int uether_rxbuf(struct usb_ether *ue, struct usb_page_cache *pc, unsigned offset, unsigned len) { - struct ifnet *ifp = ue->ue_ifp; + if_t ifp = ue->ue_ifp; struct mbuf *m; UE_LOCK_ASSERT(ue, MA_OWNED); @@ -645,7 +644,7 @@ uether_rxbuf(struct usb_ether *ue, struct usb_page_cache *pc, void uether_rxflush(struct usb_ether *ue) { - struct ifnet *ifp = ue->ue_ifp; + if_t ifp = ue->ue_ifp; struct epoch_tracker et; struct mbuf *m, *n; @@ -657,7 +656,7 @@ uether_rxflush(struct usb_ether *ue) while ((m = n) != NULL) { n = STAILQ_NEXT(m, m_stailqpkt); m->m_nextpkt = NULL; - ifp->if_input(ifp, m); + if_input(ifp, m); } NET_EPOCH_EXIT(et); UE_LOCK(ue); diff --git a/sys/dev/usb/net/usb_ethernet.h b/sys/dev/usb/net/usb_ethernet.h index dadcc73b2a39..1a4787a60403 100644 --- a/sys/dev/usb/net/usb_ethernet.h +++ b/sys/dev/usb/net/usb_ethernet.h @@ -62,10 +62,10 @@ struct usb_ether_methods { uether_fn_t *ue_setmulti; uether_fn_t *ue_setpromisc; uether_fn_t *ue_tick; - int (*ue_mii_upd)(struct ifnet *); - void (*ue_mii_sts)(struct ifnet *, + int (*ue_mii_upd)(if_t); + void (*ue_mii_sts)(if_t, struct ifmediareq *); - int (*ue_ioctl)(struct ifnet *, u_long, caddr_t); + int (*ue_ioctl)(if_t, u_long, caddr_t); int (*ue_attach_post_sub)(struct usb_ether *); }; @@ -76,7 +76,7 @@ struct usb_ether_cfg_task { struct usb_ether { /* NOTE: the "ue_ifp" pointer must be first --hps */ - struct ifnet *ue_ifp; + if_t ue_ifp; struct mtx *ue_mtx; const struct usb_ether_methods *ue_methods; struct sysctl_oid *ue_sysctl_oid; @@ -104,16 +104,16 @@ struct usb_ether { #define uether_do_request(ue,req,data,timo) \ usbd_do_request_proc((ue)->ue_udev,&(ue)->ue_tq,req,data,0,NULL,timo) -uint8_t uether_pause(struct usb_ether *, unsigned); -struct ifnet *uether_getifp(struct usb_ether *); +uint8_t uether_pause(struct usb_ether *, unsigned int); +if_t uether_getifp(struct usb_ether *); struct mii_data *uether_getmii(struct usb_ether *); void *uether_getsc(struct usb_ether *); int uether_ifattach(struct usb_ether *); void uether_ifattach_wait(struct usb_ether *); void uether_ifdetach(struct usb_ether *); -int uether_ifmedia_upd(struct ifnet *); +int uether_ifmedia_upd(if_t); void uether_init(void *); -int uether_ioctl(struct ifnet *, u_long, caddr_t); +int uether_ioctl(if_t, u_long, caddr_t); struct mbuf *uether_newbuf(void); int uether_rxmbuf(struct usb_ether *, struct mbuf *, unsigned); @@ -122,5 +122,5 @@ int uether_rxbuf(struct usb_ether *, unsigned, unsigned); void uether_rxflush(struct usb_ether *); uint8_t uether_is_gone(struct usb_ether *); -void uether_start(struct ifnet *); +void uether_start(if_t); #endif /* _USB_ETHERNET_H_ */