git: da247e0dac2f - main - Mechanically convert ic(4) to IfAPI

From: Justin Hibbits <jhibbits_at_FreeBSD.org>
Date: Mon, 06 Feb 2023 17:54:19 UTC
The branch main has been updated by jhibbits:

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

commit da247e0dac2f845d32560a5f60f09eb521a9c0b3
Author:     Justin Hibbits <jhibbits@FreeBSD.org>
AuthorDate: 2022-09-19 20:53:12 +0000
Commit:     Justin Hibbits <jhibbits@FreeBSD.org>
CommitDate: 2023-02-06 17:32:12 +0000

    Mechanically convert ic(4) to IfAPI
    
    Sponsored by:   Juniper Networks, Inc.
    Differential Revision: https://reviews.freebsd.org/D37851
---
 sys/dev/iicbus/if_ic.c | 55 +++++++++++++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/sys/dev/iicbus/if_ic.c b/sys/dev/iicbus/if_ic.c
index 623ee178e4e8..6f7c0706e079 100644
--- a/sys/dev/iicbus/if_ic.c
+++ b/sys/dev/iicbus/if_ic.c
@@ -72,7 +72,7 @@ __FBSDID("$FreeBSD$");
 #define ICMTU		1500		/* default mtu */
 
 struct ic_softc {
-	struct ifnet *ic_ifp;
+	if_t ic_ifp;
 	device_t ic_dev;
 
 	u_char ic_addr;			/* peer I2C address */
@@ -99,8 +99,8 @@ struct ic_softc {
 static int icprobe(device_t);
 static int icattach(device_t);
 
-static int icioctl(struct ifnet *, u_long, caddr_t);
-static int icoutput(struct ifnet *, struct mbuf *, const struct sockaddr *,
+static int icioctl(if_t, u_long, caddr_t);
+static int icoutput(if_t, struct mbuf *, const struct sockaddr *,
                struct route *);
 
 static int icintr(device_t, int, char *);
@@ -141,7 +141,7 @@ ic_alloc_buffers(struct ic_softc *sc, int mtu)
 	free(sc->ic_ifbuf, M_DEVBUF);
 	sc->ic_obuf = obuf;
 	sc->ic_ifbuf = ifbuf;
-	sc->ic_ifp->if_mtu = mtu;
+	if_setmtu(sc->ic_ifp, mtu);
 	mtx_unlock(&sc->ic_lock);
 }
 
@@ -161,7 +161,7 @@ static int
 icattach(device_t dev)
 {
 	struct ic_softc *sc = (struct ic_softc *)device_get_softc(dev);
-	struct ifnet *ifp;
+	if_t ifp;
 
 	ifp = sc->ic_ifp = if_alloc(IFT_PARA);
 	if (ifp == NULL)
@@ -172,14 +172,13 @@ icattach(device_t dev)
 	sc->ic_addr = PCF_MASTER_ADDRESS;	/* XXX only PCF masters */
 	sc->ic_dev = dev;
 
-	ifp->if_softc = sc;
+	if_setsoftc(ifp, sc);
 	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
-	ifp->if_flags = IFF_SIMPLEX | IFF_POINTOPOINT | IFF_MULTICAST;
-	ifp->if_ioctl = icioctl;
-	ifp->if_output = icoutput;
-	ifp->if_hdrlen = 0;
-	ifp->if_addrlen = 0;
-	ifp->if_snd.ifq_maxlen = ifqmaxlen;
+	if_setflags(ifp, IFF_SIMPLEX | IFF_POINTOPOINT | IFF_MULTICAST);
+	if_setioctlfn(ifp, icioctl);
+	if_setoutputfn(ifp, icoutput);
+	if_setifheaderlen(ifp, 0);
+	if_setsendqlen(ifp, ifqmaxlen);
 
 	ic_alloc_buffers(sc, ICMTU);
 
@@ -194,9 +193,9 @@ icattach(device_t dev)
  * iciotcl()
  */
 static int
-icioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+icioctl(if_t ifp, u_long cmd, caddr_t data)
 {
-	struct ic_softc *sc = ifp->if_softc;
+	struct ic_softc *sc = if_getsoftc(ifp);
 	device_t icdev = sc->ic_dev;
 	device_t parent = device_get_parent(icdev);
 	struct ifaddr *ifa = (struct ifaddr *)data;
@@ -210,31 +209,31 @@ icioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
 		if (ifa->ifa_addr->sa_family != AF_INET)
 			return (EAFNOSUPPORT);
 		mtx_lock(&sc->ic_lock);
-		ifp->if_flags |= IFF_UP;
+		if_setflagbits(ifp, IFF_UP, 0);
 		goto locked;
 	case SIOCSIFFLAGS:
 		mtx_lock(&sc->ic_lock);
 	locked:
-		if ((!(ifp->if_flags & IFF_UP)) &&
-		    (ifp->if_drv_flags & IFF_DRV_RUNNING)) {
+		if ((!(if_getflags(ifp) & IFF_UP)) &&
+		    (if_getdrvflags(ifp) & IFF_DRV_RUNNING)) {
 
 			/* XXX disable PCF */
-			ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
+			if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
 			mtx_unlock(&sc->ic_lock);
 
 			/* IFF_UP is not set, try to release the bus anyway */
 			iicbus_release_bus(parent, icdev);
 			break;
 		}
-		if (((ifp->if_flags & IFF_UP)) &&
-		    (!(ifp->if_drv_flags & IFF_DRV_RUNNING))) {
+		if (((if_getflags(ifp) & IFF_UP)) &&
+		    (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING))) {
 			mtx_unlock(&sc->ic_lock);
 			if ((error = iicbus_request_bus(parent, icdev,
 			    IIC_WAIT | IIC_INTR)))
 				return (error);
 			mtx_lock(&sc->ic_lock);
 			iicbus_reset(parent, IIC_FASTEST, 0, NULL);
-			ifp->if_drv_flags |= IFF_DRV_RUNNING;
+			if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0);
 		}
 		mtx_unlock(&sc->ic_lock);
 		break;
@@ -245,7 +244,7 @@ icioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
 
 	case SIOCGIFMTU:
 		mtx_lock(&sc->ic_lock);
-		ifr->ifr_mtu = sc->ic_ifp->if_mtu;
+		ifr->ifr_mtu = if_getmtu(sc->ic_ifp);
 		mtx_unlock(&sc->ic_lock);
 		break;
 
@@ -310,7 +309,7 @@ icintr(device_t dev, int event, char *ptr)
 			struct epoch_tracker et;
 
 			mtx_unlock(&sc->ic_lock);
-			M_SETFIB(top, sc->ic_ifp->if_fib);
+			M_SETFIB(top, if_getfib(sc->ic_ifp));
 			NET_EPOCH_ENTER(et);
 			netisr_dispatch(NETISR_IP, top);
 			NET_EPOCH_EXIT(et);
@@ -324,7 +323,7 @@ icintr(device_t dev, int event, char *ptr)
 		break;
 
 	case INTR_RECEIVE:
-		if (sc->ic_xfercnt >= sc->ic_ifp->if_mtu + ICHDRLEN) {
+		if (sc->ic_xfercnt >= if_getmtu(sc->ic_ifp) + ICHDRLEN) {
 			sc->ic_iferrs++;
 		} else {
 			*sc->ic_cp++ = *ptr;
@@ -355,10 +354,10 @@ icintr(device_t dev, int event, char *ptr)
  * icoutput()
  */
 static int
-icoutput(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
+icoutput(if_t ifp, struct mbuf *m, const struct sockaddr *dst,
     struct route *ro)
 {
-	struct ic_softc *sc = ifp->if_softc;
+	struct ic_softc *sc = if_getsoftc(ifp);
 	device_t icdev = sc->ic_dev;
 	device_t parent = device_get_parent(icdev);
 	int len, sent;
@@ -373,7 +372,7 @@ icoutput(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
 		hdr = RO_GET_FAMILY(ro, dst);
 
 	mtx_lock(&sc->ic_lock);
-	ifp->if_drv_flags |= IFF_DRV_RUNNING;
+	if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0);
 
 	/* already sending? */
 	if (sc->ic_flags & IC_SENDING) {
@@ -388,7 +387,7 @@ icoutput(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
 	len = 0;
 	mm = m;
 	do {
-		if (len + mm->m_len > sc->ic_ifp->if_mtu) {
+		if (len + mm->m_len > if_getmtu(sc->ic_ifp)) {
 			/* packet too large */
 			if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
 			goto error;