git: dba12f75604f - main - Mechanically convert if_xae to IfAPI

From: Justin Hibbits <jhibbits_at_FreeBSD.org>
Date: Tue, 07 Feb 2023 19:18:05 UTC
The branch main has been updated by jhibbits:

URL: https://cgit.FreeBSD.org/src/commit/?id=dba12f75604f3d361f2610d3cab85f9eaca6eea4

commit dba12f75604f3d361f2610d3cab85f9eaca6eea4
Author:     Justin Hibbits <jhibbits@FreeBSD.org>
AuthorDate: 2022-03-01 17:00:21 +0000
Commit:     Justin Hibbits <jhibbits@FreeBSD.org>
CommitDate: 2023-02-07 19:15:04 +0000

    Mechanically convert if_xae to IfAPI
    
    Reviewed by:    zlei
    Sponsored by:   Juniper Networks, Inc.
    Differential Revision: https://reviews.freebsd.org/D37797
---
 sys/dev/xilinx/if_xae.c    | 93 +++++++++++++++++++++++-----------------------
 sys/dev/xilinx/if_xaevar.h |  2 +-
 2 files changed, 47 insertions(+), 48 deletions(-)

diff --git a/sys/dev/xilinx/if_xae.c b/sys/dev/xilinx/if_xae.c
index 5b61d19b6f0a..414d45f37514 100644
--- a/sys/dev/xilinx/if_xae.c
+++ b/sys/dev/xilinx/if_xae.c
@@ -177,7 +177,7 @@ xae_xdma_tx_intr(void *arg, xdma_transfer_status_t *status)
 {
 	xdma_transfer_status_t st;
 	struct xae_softc *sc;
-	struct ifnet *ifp;
+	if_t ifp;
 	struct mbuf *m;
 	int err;
 
@@ -200,7 +200,7 @@ xae_xdma_tx_intr(void *arg, xdma_transfer_status_t *status)
 		m_freem(m);
 	}
 
-	ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+	if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE);
 
 	XAE_UNLOCK(sc);
 
@@ -212,7 +212,7 @@ xae_xdma_rx_intr(void *arg, xdma_transfer_status_t *status)
 {
 	xdma_transfer_status_t st;
 	struct xae_softc *sc;
-	struct ifnet *ifp;
+	if_t ifp;
 	struct mbuf *m;
 	int err;
 	uint32_t cnt_processed;
@@ -242,7 +242,7 @@ xae_xdma_rx_intr(void *arg, xdma_transfer_status_t *status)
 		m->m_pkthdr.len = m->m_len = st.transferred;
 		m->m_pkthdr.rcvif = ifp;
 		XAE_UNLOCK(sc);
-		(*ifp->if_input)(ifp, m);
+		if_input(ifp, m);
 		XAE_LOCK(sc);
 	}
 
@@ -254,12 +254,12 @@ xae_xdma_rx_intr(void *arg, xdma_transfer_status_t *status)
 }
 
 static void
-xae_qflush(struct ifnet *ifp)
+xae_qflush(if_t ifp)
 {
 }
 
 static int
-xae_transmit_locked(struct ifnet *ifp)
+xae_transmit_locked(if_t ifp)
 {
 	struct xae_softc *sc;
 	struct mbuf *m;
@@ -269,7 +269,7 @@ xae_transmit_locked(struct ifnet *ifp)
 
 	dprintf("%s\n", __func__);
 
-	sc = ifp->if_softc;
+	sc = if_getsoftc(ifp);
 	br = sc->br;
 
 	enq = 0;
@@ -298,14 +298,14 @@ xae_transmit_locked(struct ifnet *ifp)
 }
 
 static int
-xae_transmit(struct ifnet *ifp, struct mbuf *m)
+xae_transmit(if_t ifp, struct mbuf *m)
 {
 	struct xae_softc *sc;
 	int error;
 
 	dprintf("%s\n", __func__);
 
-	sc = ifp->if_softc;
+	sc = if_getsoftc(ifp);
 
 	XAE_LOCK(sc);
 
@@ -315,7 +315,7 @@ xae_transmit(struct ifnet *ifp, struct mbuf *m)
 		return (error);
 	}
 
-	if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) !=
+	if ((if_getdrvflags(ifp) & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) !=
 	    IFF_DRV_RUNNING) {
 		XAE_UNLOCK(sc);
 		return (0);
@@ -336,13 +336,13 @@ xae_transmit(struct ifnet *ifp, struct mbuf *m)
 static void
 xae_stop_locked(struct xae_softc *sc)
 {
-	struct ifnet *ifp;
+	if_t ifp;
 	uint32_t reg;
 
 	XAE_ASSERT_LOCKED(sc);
 
 	ifp = sc->ifp;
-	ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
+	if_setdrvflagbits(ifp, 0, (IFF_DRV_RUNNING | IFF_DRV_OACTIVE));
 
 	callout_stop(&sc->xae_callout);
 
@@ -381,7 +381,7 @@ xae_stat(struct xae_softc *sc, int counter_id)
 static void
 xae_harvest_stats(struct xae_softc *sc)
 {
-	struct ifnet *ifp;
+	if_t ifp;
 
 	ifp = sc->ifp;
 
@@ -409,7 +409,7 @@ static void
 xae_tick(void *arg)
 {
 	struct xae_softc *sc;
-	struct ifnet *ifp;
+	if_t ifp;
 	int link_was_up;
 
 	sc = arg;
@@ -418,7 +418,7 @@ xae_tick(void *arg)
 
 	ifp = sc->ifp;
 
-	if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
+	if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING))
 		return;
 
 	/* Gather stats from hardware counters. */
@@ -437,15 +437,15 @@ xae_tick(void *arg)
 static void
 xae_init_locked(struct xae_softc *sc)
 {
-	struct ifnet *ifp;
+	if_t ifp;
 
 	XAE_ASSERT_LOCKED(sc);
 
 	ifp = sc->ifp;
-	if (ifp->if_drv_flags & IFF_DRV_RUNNING)
+	if (if_getdrvflags(ifp) & IFF_DRV_RUNNING)
 		return;
 
-	ifp->if_drv_flags |= IFF_DRV_RUNNING;
+	if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0);
 
 	xae_setup_rxfilter(sc);
 
@@ -476,12 +476,12 @@ xae_init(void *arg)
 }
 
 static void
-xae_media_status(struct ifnet * ifp, struct ifmediareq *ifmr)
+xae_media_status(if_t  ifp, struct ifmediareq *ifmr)
 {
 	struct xae_softc *sc;
 	struct mii_data *mii;
 
-	sc = ifp->if_softc;
+	sc = if_getsoftc(ifp);
 	mii = sc->mii_softc;
 
 	XAE_LOCK(sc);
@@ -499,12 +499,12 @@ xae_media_change_locked(struct xae_softc *sc)
 }
 
 static int
-xae_media_change(struct ifnet * ifp)
+xae_media_change(if_t  ifp)
 {
 	struct xae_softc *sc;
 	int error;
 
-	sc = ifp->if_softc;
+	sc = if_getsoftc(ifp);
 
 	XAE_LOCK(sc);
 	error = xae_media_change_locked(sc);
@@ -545,7 +545,7 @@ xae_write_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt)
 static void
 xae_setup_rxfilter(struct xae_softc *sc)
 {
-	struct ifnet *ifp;
+	if_t ifp;
 	uint32_t reg;
 
 	XAE_ASSERT_LOCKED(sc);
@@ -555,7 +555,7 @@ xae_setup_rxfilter(struct xae_softc *sc)
 	/*
 	 * Set the multicast (group) filter hash.
 	 */
-	if ((ifp->if_flags & (IFF_ALLMULTI | IFF_PROMISC)) != 0) {
+	if ((if_getflags(ifp) & (IFF_ALLMULTI | IFF_PROMISC)) != 0) {
 		reg = READ4(sc, XAE_FFC);
 		reg |= FFC_PM;
 		WRITE4(sc, XAE_FFC, reg);
@@ -582,23 +582,23 @@ xae_setup_rxfilter(struct xae_softc *sc)
 }
 
 static int
-xae_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+xae_ioctl(if_t ifp, u_long cmd, caddr_t data)
 {
 	struct xae_softc *sc;
 	struct mii_data *mii;
 	struct ifreq *ifr;
 	int mask, error;
 
-	sc = ifp->if_softc;
+	sc = if_getsoftc(ifp);
 	ifr = (struct ifreq *)data;
 
 	error = 0;
 	switch (cmd) {
 	case SIOCSIFFLAGS:
 		XAE_LOCK(sc);
-		if (ifp->if_flags & IFF_UP) {
-			if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
-				if ((ifp->if_flags ^ sc->if_flags) &
+		if (if_getflags(ifp) & IFF_UP) {
+			if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) {
+				if ((if_getflags(ifp) ^ sc->if_flags) &
 				    (IFF_PROMISC | IFF_ALLMULTI))
 					xae_setup_rxfilter(sc);
 			} else {
@@ -606,15 +606,15 @@ xae_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
 					xae_init_locked(sc);
 			}
 		} else {
-			if (ifp->if_drv_flags & IFF_DRV_RUNNING)
+			if (if_getdrvflags(ifp) & IFF_DRV_RUNNING)
 				xae_stop_locked(sc);
 		}
-		sc->if_flags = ifp->if_flags;
+		sc->if_flags = if_getflags(ifp);
 		XAE_UNLOCK(sc);
 		break;
 	case SIOCADDMULTI:
 	case SIOCDELMULTI:
-		if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
+		if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) {
 			XAE_LOCK(sc);
 			xae_setup_rxfilter(sc);
 			XAE_UNLOCK(sc);
@@ -626,10 +626,10 @@ xae_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
 		error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, cmd);
 		break;
 	case SIOCSIFCAP:
-		mask = ifp->if_capenable ^ ifr->ifr_reqcap;
+		mask = if_getcapenable(ifp) ^ ifr->ifr_reqcap;
 		if (mask & IFCAP_VLAN_MTU) {
 			/* No work to do except acknowledge the change took */
-			ifp->if_capenable ^= IFCAP_VLAN_MTU;
+			if_togglecapenable(ifp, IFCAP_VLAN_MTU);
 		}
 		break;
 
@@ -934,7 +934,7 @@ static int
 xae_attach(device_t dev)
 {
 	struct xae_softc *sc;
-	struct ifnet *ifp;
+	if_t ifp;
 	phandle_t node;
 	uint32_t reg;
 	int error;
@@ -998,18 +998,17 @@ xae_attach(device_t dev)
 		return (ENXIO);
 	}
 
-	ifp->if_softc = sc;
+	if_setsoftc(ifp, sc);
 	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
-	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
-	ifp->if_capabilities = IFCAP_VLAN_MTU;
-	ifp->if_capenable = ifp->if_capabilities;
-	ifp->if_transmit = xae_transmit;
-	ifp->if_qflush = xae_qflush;
-	ifp->if_ioctl = xae_ioctl;
-	ifp->if_init = xae_init;
-	IFQ_SET_MAXLEN(&ifp->if_snd, TX_DESC_COUNT - 1);
-	ifp->if_snd.ifq_drv_maxlen = TX_DESC_COUNT - 1;
-	IFQ_SET_READY(&ifp->if_snd);
+	if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
+	if_setcapabilities(ifp, IFCAP_VLAN_MTU);
+	if_setcapenable(ifp, if_getcapabilities(ifp));
+	if_settransmitfn(ifp, xae_transmit);
+	if_setqflushfn(ifp, xae_qflush);
+	if_setioctlfn(ifp, xae_ioctl);
+	if_setinitfn(ifp, xae_init);
+	if_setsendqlen(ifp, TX_DESC_COUNT - 1);
+	if_setsendqready(ifp);
 
 	if (xae_get_phyaddr(node, &sc->phy_addr) != 0)
 		return (ENXIO);
@@ -1043,7 +1042,7 @@ static int
 xae_detach(device_t dev)
 {
 	struct xae_softc *sc;
-	struct ifnet *ifp;
+	if_t ifp;
 
 	sc = device_get_softc(dev);
 
diff --git a/sys/dev/xilinx/if_xaevar.h b/sys/dev/xilinx/if_xaevar.h
index 3039653780e9..fab0850989be 100644
--- a/sys/dev/xilinx/if_xaevar.h
+++ b/sys/dev/xilinx/if_xaevar.h
@@ -51,7 +51,7 @@ struct xae_softc {
 	uint8_t			macaddr[ETHER_ADDR_LEN];
 	device_t		miibus;
 	struct mii_data *	mii_softc;
-	struct ifnet		*ifp;
+	if_t			ifp;
 	int			if_flags;
 	struct mtx		mtx;
 	void *			intr_cookie;