Mechanically convert if_cpsw(4) to IfAPI

Reviewed By:	manu
Sponsored by:	Juniper Networks, Inc.
Differential Revision: https://reviews.freebsd.org/D37789
This commit is contained in:
Justin Hibbits
2022-02-25 12:00:25 -06:00
parent 4ee967921a
commit 2c7bc0f551
2 changed files with 54 additions and 55 deletions
+52 -53
View File
@@ -117,7 +117,7 @@ static int cpsw_suspend(device_t);
static int cpsw_resume(device_t); static int cpsw_resume(device_t);
/* Ioctl. */ /* Ioctl. */
static int cpswp_ioctl(struct ifnet *, u_long command, caddr_t data); static int cpswp_ioctl(if_t, u_long command, caddr_t data);
static int cpswp_miibus_readreg(device_t, int phy, int reg); static int cpswp_miibus_readreg(device_t, int phy, int reg);
static int cpswp_miibus_writereg(device_t, int phy, int reg, int value); static int cpswp_miibus_writereg(device_t, int phy, int reg, int value);
@@ -127,7 +127,7 @@ static void cpswp_miibus_statchg(device_t);
static void cpsw_intr_rx(void *arg); static void cpsw_intr_rx(void *arg);
static struct mbuf *cpsw_rx_dequeue(struct cpsw_softc *); static struct mbuf *cpsw_rx_dequeue(struct cpsw_softc *);
static void cpsw_rx_enqueue(struct cpsw_softc *); static void cpsw_rx_enqueue(struct cpsw_softc *);
static void cpswp_start(struct ifnet *); static void cpswp_start(if_t);
static void cpsw_intr_tx(void *); static void cpsw_intr_tx(void *);
static void cpswp_tx_enqueue(struct cpswp_softc *); static void cpswp_tx_enqueue(struct cpswp_softc *);
static int cpsw_tx_dequeue(struct cpsw_softc *); static int cpsw_tx_dequeue(struct cpsw_softc *);
@@ -136,8 +136,8 @@ static int cpsw_tx_dequeue(struct cpsw_softc *);
static void cpsw_intr_rx_thresh(void *); static void cpsw_intr_rx_thresh(void *);
static void cpsw_intr_misc(void *); static void cpsw_intr_misc(void *);
static void cpswp_tick(void *); static void cpswp_tick(void *);
static void cpswp_ifmedia_sts(struct ifnet *, struct ifmediareq *); static void cpswp_ifmedia_sts(if_t, struct ifmediareq *);
static int cpswp_ifmedia_upd(struct ifnet *); static int cpswp_ifmedia_upd(if_t);
static void cpsw_tx_watchdog(void *); static void cpsw_tx_watchdog(void *);
/* ALE support */ /* ALE support */
@@ -997,7 +997,7 @@ static int
cpswp_attach(device_t dev) cpswp_attach(device_t dev)
{ {
int error; int error;
struct ifnet *ifp; if_t ifp;
struct cpswp_softc *sc; struct cpswp_softc *sc;
uint32_t reg; uint32_t reg;
uint8_t mac_addr[ETHER_ADDR_LEN]; uint8_t mac_addr[ETHER_ADDR_LEN];
@@ -1033,18 +1033,17 @@ cpswp_attach(device_t dev)
} }
if_initname(ifp, device_get_name(sc->dev), sc->unit); if_initname(ifp, device_get_name(sc->dev), sc->unit);
ifp->if_softc = sc; if_setsoftc(ifp, sc);
ifp->if_flags = IFF_SIMPLEX | IFF_MULTICAST | IFF_BROADCAST; if_setflags(ifp, IFF_SIMPLEX | IFF_MULTICAST | IFF_BROADCAST);
ifp->if_capabilities = IFCAP_VLAN_MTU | IFCAP_HWCSUM; //FIXME VLAN?
ifp->if_capenable = ifp->if_capabilities;
ifp->if_init = cpswp_init; if_setcapenable(ifp, if_getcapabilities(ifp));
ifp->if_start = cpswp_start;
ifp->if_ioctl = cpswp_ioctl;
ifp->if_snd.ifq_drv_maxlen = sc->swsc->tx.queue_slots; if_setinitfn(ifp, cpswp_init);
IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen); if_setstartfn(ifp, cpswp_start);
IFQ_SET_READY(&ifp->if_snd); if_setioctlfn(ifp, cpswp_ioctl);
if_setsendqlen(ifp, sc->swsc->tx.queue_slots);
if_setsendqready(ifp);
/* FIXME: For now; Go and kidnap syscon from opp-table */ /* FIXME: For now; Go and kidnap syscon from opp-table */
/* ti,cpsw actually have an optional syscon reference but only for am33xx?? */ /* ti,cpsw actually have an optional syscon reference but only for am33xx?? */
@@ -1129,7 +1128,7 @@ static int
cpsw_ports_down(struct cpsw_softc *sc) cpsw_ports_down(struct cpsw_softc *sc)
{ {
struct cpswp_softc *psc; struct cpswp_softc *psc;
struct ifnet *ifp1, *ifp2; if_t ifp1, ifp2;
if (!sc->dualemac) if (!sc->dualemac)
return (1); return (1);
@@ -1161,13 +1160,13 @@ cpswp_init_locked(void *arg)
int i; int i;
#endif #endif
struct cpswp_softc *sc = arg; struct cpswp_softc *sc = arg;
struct ifnet *ifp; if_t ifp;
uint32_t reg; uint32_t reg;
CPSW_DEBUGF(sc->swsc, ("")); CPSW_DEBUGF(sc->swsc, (""));
CPSW_PORT_LOCK_ASSERT(sc); CPSW_PORT_LOCK_ASSERT(sc);
ifp = sc->ifp; ifp = sc->ifp;
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) != 0)
return; return;
getbinuptime(&sc->init_uptime); getbinuptime(&sc->init_uptime);
@@ -1215,8 +1214,8 @@ cpswp_init_locked(void *arg)
mii_mediachg(sc->mii); mii_mediachg(sc->mii);
callout_reset(&sc->mii_callout, hz, cpswp_tick, sc); callout_reset(&sc->mii_callout, hz, cpswp_tick, sc);
ifp->if_drv_flags |= IFF_DRV_RUNNING; if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0);
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE);
} }
static int static int
@@ -1292,19 +1291,19 @@ cpsw_tx_teardown(struct cpsw_softc *sc)
static void static void
cpswp_stop_locked(struct cpswp_softc *sc) cpswp_stop_locked(struct cpswp_softc *sc)
{ {
struct ifnet *ifp; if_t ifp;
uint32_t reg; uint32_t reg;
ifp = sc->ifp; ifp = sc->ifp;
CPSW_DEBUGF(sc->swsc, ("")); CPSW_DEBUGF(sc->swsc, (""));
CPSW_PORT_LOCK_ASSERT(sc); CPSW_PORT_LOCK_ASSERT(sc);
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0)
return; return;
/* Disable interface */ /* Disable interface */
ifp->if_drv_flags &= ~IFF_DRV_RUNNING; if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
ifp->if_drv_flags |= IFF_DRV_OACTIVE; if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0);
/* Stop ticker */ /* Stop ticker */
callout_stop(&sc->mii_callout); callout_stop(&sc->mii_callout);
@@ -1399,7 +1398,7 @@ cpsw_set_allmulti(struct cpswp_softc *sc, int set)
} }
static int static int
cpswp_ioctl(struct ifnet *ifp, u_long command, caddr_t data) cpswp_ioctl(if_t ifp, u_long command, caddr_t data)
{ {
struct cpswp_softc *sc; struct cpswp_softc *sc;
struct ifreq *ifr; struct ifreq *ifr;
@@ -1407,45 +1406,45 @@ cpswp_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
uint32_t changed; uint32_t changed;
error = 0; error = 0;
sc = ifp->if_softc; sc = if_getsoftc(ifp);
ifr = (struct ifreq *)data; ifr = (struct ifreq *)data;
switch (command) { switch (command) {
case SIOCSIFCAP: case SIOCSIFCAP:
changed = ifp->if_capenable ^ ifr->ifr_reqcap; changed = if_getcapenable(ifp) ^ ifr->ifr_reqcap;
if (changed & IFCAP_HWCSUM) { if (changed & IFCAP_HWCSUM) {
if ((ifr->ifr_reqcap & changed) & IFCAP_HWCSUM) if ((ifr->ifr_reqcap & changed) & IFCAP_HWCSUM)
ifp->if_capenable |= IFCAP_HWCSUM; if_setcapenablebit(ifp, IFCAP_HWCSUM, 0);
else else
ifp->if_capenable &= ~IFCAP_HWCSUM; if_setcapenablebit(ifp, 0, IFCAP_HWCSUM);
} }
error = 0; error = 0;
break; break;
case SIOCSIFFLAGS: case SIOCSIFFLAGS:
CPSW_PORT_LOCK(sc); CPSW_PORT_LOCK(sc);
if (ifp->if_flags & IFF_UP) { if (if_getflags(ifp) & IFF_UP) {
if (ifp->if_drv_flags & IFF_DRV_RUNNING) { if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) {
changed = ifp->if_flags ^ sc->if_flags; changed = if_getflags(ifp) ^ sc->if_flags;
CPSW_DEBUGF(sc->swsc, CPSW_DEBUGF(sc->swsc,
("SIOCSIFFLAGS: UP & RUNNING (changed=0x%x)", ("SIOCSIFFLAGS: UP & RUNNING (changed=0x%x)",
changed)); changed));
if (changed & IFF_PROMISC) if (changed & IFF_PROMISC)
cpsw_set_promisc(sc, cpsw_set_promisc(sc,
ifp->if_flags & IFF_PROMISC); if_getflags(ifp) & IFF_PROMISC);
if (changed & IFF_ALLMULTI) if (changed & IFF_ALLMULTI)
cpsw_set_allmulti(sc, cpsw_set_allmulti(sc,
ifp->if_flags & IFF_ALLMULTI); if_getflags(ifp) & IFF_ALLMULTI);
} else { } else {
CPSW_DEBUGF(sc->swsc, CPSW_DEBUGF(sc->swsc,
("SIOCSIFFLAGS: starting up")); ("SIOCSIFFLAGS: starting up"));
cpswp_init_locked(sc); cpswp_init_locked(sc);
} }
} else if (ifp->if_drv_flags & IFF_DRV_RUNNING) { } else if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) {
CPSW_DEBUGF(sc->swsc, ("SIOCSIFFLAGS: shutting down")); CPSW_DEBUGF(sc->swsc, ("SIOCSIFFLAGS: shutting down"));
cpswp_stop_locked(sc); cpswp_stop_locked(sc);
} }
sc->if_flags = ifp->if_flags; sc->if_flags = if_getflags(ifp);
CPSW_PORT_UNLOCK(sc); CPSW_PORT_UNLOCK(sc);
break; break;
case SIOCADDMULTI: case SIOCADDMULTI:
@@ -1582,7 +1581,7 @@ static void
cpsw_intr_rx(void *arg) cpsw_intr_rx(void *arg)
{ {
struct cpsw_softc *sc; struct cpsw_softc *sc;
struct ifnet *ifp; if_t ifp;
struct mbuf *received, *next; struct mbuf *received, *next;
sc = (struct cpsw_softc *)arg; sc = (struct cpsw_softc *)arg;
@@ -1601,7 +1600,7 @@ cpsw_intr_rx(void *arg)
next = received->m_nextpkt; next = received->m_nextpkt;
received->m_nextpkt = NULL; received->m_nextpkt = NULL;
ifp = received->m_pkthdr.rcvif; ifp = received->m_pkthdr.rcvif;
(*ifp->if_input)(ifp, received); if_input(ifp, received);
if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1); if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
received = next; received = next;
} }
@@ -1684,7 +1683,7 @@ cpsw_rx_dequeue(struct cpsw_softc *sc)
nsegs = 0; nsegs = 0;
} }
if ((psc->ifp->if_capenable & IFCAP_RXCSUM) != 0) { if ((if_getcapenable(psc->ifp) & IFCAP_RXCSUM) != 0) {
/* check for valid CRC by looking into pkt_err[5:4] */ /* check for valid CRC by looking into pkt_err[5:4] */
if ((bd.flags & if ((bd.flags &
(CPDMA_BD_SOP | CPDMA_BD_PKT_ERR_MASK)) == (CPDMA_BD_SOP | CPDMA_BD_PKT_ERR_MASK)) ==
@@ -1712,7 +1711,7 @@ cpsw_rx_dequeue(struct cpsw_softc *sc)
if (bootverbose) if (bootverbose)
printf( printf(
"%s: %s: discanding fragment packet w/o header\n", "%s: %s: discanding fragment packet w/o header\n",
__func__, psc->ifp->if_xname); __func__, if_name(psc->ifp));
m_freem(m); m_freem(m);
continue; continue;
} else { } else {
@@ -1816,12 +1815,12 @@ cpsw_rx_enqueue(struct cpsw_softc *sc)
} }
static void static void
cpswp_start(struct ifnet *ifp) cpswp_start(if_t ifp)
{ {
struct cpswp_softc *sc; struct cpswp_softc *sc;
sc = ifp->if_softc; sc = if_getsoftc(ifp);
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 || if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0 ||
sc->swsc->tx.running == 0) { sc->swsc->tx.running == 0) {
return; return;
} }
@@ -1859,7 +1858,7 @@ cpswp_tx_enqueue(struct cpswp_softc *sc)
first_new_slot = NULL; first_new_slot = NULL;
last_old_slot = STAILQ_LAST(&sc->swsc->tx.active, cpsw_slot, next); last_old_slot = STAILQ_LAST(&sc->swsc->tx.active, cpsw_slot, next);
while ((slot = STAILQ_FIRST(&sc->swsc->tx.avail)) != NULL) { while ((slot = STAILQ_FIRST(&sc->swsc->tx.avail)) != NULL) {
IF_DEQUEUE(&sc->ifp->if_snd, m0); m0 = if_dequeue(sc->ifp);
if (m0 == NULL) if (m0 == NULL)
break; break;
@@ -1885,7 +1884,7 @@ cpswp_tx_enqueue(struct cpswp_softc *sc)
} else { } else {
CPSW_DEBUGF(sc->swsc, CPSW_DEBUGF(sc->swsc,
("Requeueing defragmented packet")); ("Requeueing defragmented packet"));
IF_PREPEND(&sc->ifp->if_snd, m0); if_sendq_prepend(sc->ifp, m0);
} }
slot->mbuf = NULL; slot->mbuf = NULL;
continue; continue;
@@ -2075,7 +2074,7 @@ static void
cpsw_intr_rx_thresh(void *arg) cpsw_intr_rx_thresh(void *arg)
{ {
struct cpsw_softc *sc; struct cpsw_softc *sc;
struct ifnet *ifp; if_t ifp;
struct mbuf *received, *next; struct mbuf *received, *next;
sc = (struct cpsw_softc *)arg; sc = (struct cpsw_softc *)arg;
@@ -2089,7 +2088,7 @@ cpsw_intr_rx_thresh(void *arg)
next = received->m_nextpkt; next = received->m_nextpkt;
received->m_nextpkt = NULL; received->m_nextpkt = NULL;
ifp = received->m_pkthdr.rcvif; ifp = received->m_pkthdr.rcvif;
(*ifp->if_input)(ifp, received); if_input(ifp, received);
if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1); if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
received = next; received = next;
} }
@@ -2224,12 +2223,12 @@ cpswp_tick(void *msc)
} }
static void static void
cpswp_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) cpswp_ifmedia_sts(if_t ifp, struct ifmediareq *ifmr)
{ {
struct cpswp_softc *sc; struct cpswp_softc *sc;
struct mii_data *mii; struct mii_data *mii;
sc = ifp->if_softc; sc = if_getsoftc(ifp);
CPSW_DEBUGF(sc->swsc, ("")); CPSW_DEBUGF(sc->swsc, (""));
CPSW_PORT_LOCK(sc); CPSW_PORT_LOCK(sc);
@@ -2242,11 +2241,11 @@ cpswp_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
} }
static int static int
cpswp_ifmedia_upd(struct ifnet *ifp) cpswp_ifmedia_upd(if_t ifp)
{ {
struct cpswp_softc *sc; struct cpswp_softc *sc;
sc = ifp->if_softc; sc = if_getsoftc(ifp);
CPSW_DEBUGF(sc->swsc, ("")); CPSW_DEBUGF(sc->swsc, (""));
CPSW_PORT_LOCK(sc); CPSW_PORT_LOCK(sc);
mii_mediachg(sc->mii); mii_mediachg(sc->mii);
@@ -2478,7 +2477,7 @@ cpswp_ale_update_addresses(struct cpswp_softc *sc, int purge)
* For simplicity, keep this entry at table index 0 for port 1 and * For simplicity, keep this entry at table index 0 for port 1 and
* at index 2 for port 2 in the ALE. * at index 2 for port 2 in the ALE.
*/ */
mac = LLADDR((struct sockaddr_dl *)sc->ifp->if_addr->ifa_addr); mac = LLADDR((struct sockaddr_dl *)if_getifaddr(sc->ifp)->ifa_addr);
ale_entry[0] = mac[2] << 24 | mac[3] << 16 | mac[4] << 8 | mac[5]; ale_entry[0] = mac[2] << 24 | mac[3] << 16 | mac[4] << 8 | mac[5];
ale_entry[1] = ale_type | mac[0] << 8 | mac[1]; /* addr entry + mac */ ale_entry[1] = ale_type | mac[0] << 8 | mac[1]; /* addr entry + mac */
ale_entry[2] = 0; /* port = 0 */ ale_entry[2] = 0; /* port = 0 */
@@ -2668,7 +2667,7 @@ cpsw_stat_uptime(SYSCTL_HANDLER_ARGS)
swsc = arg1; swsc = arg1;
sc = device_get_softc(swsc->port[arg2].dev); sc = device_get_softc(swsc->port[arg2].dev);
if (sc->ifp->if_drv_flags & IFF_DRV_RUNNING) { if (if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) {
getbinuptime(&t); getbinuptime(&t);
bintime_sub(&t, &sc->init_uptime); bintime_sub(&t, &sc->init_uptime);
result = t.sec; result = t.sec;
+2 -2
View File
@@ -55,7 +55,7 @@ struct cpsw_vlangroups {
struct cpsw_slot { struct cpsw_slot {
uint32_t bd_offset; /* Offset of corresponding BD within CPPI RAM. */ uint32_t bd_offset; /* Offset of corresponding BD within CPPI RAM. */
bus_dmamap_t dmamap; bus_dmamap_t dmamap;
struct ifnet *ifp; if_t ifp;
struct mbuf *mbuf; struct mbuf *mbuf;
STAILQ_ENTRY(cpsw_slot) next; STAILQ_ENTRY(cpsw_slot) next;
}; };
@@ -139,7 +139,7 @@ struct cpswp_softc {
struct bintime init_uptime; /* system uptime when init happened. */ struct bintime init_uptime; /* system uptime when init happened. */
struct callout mii_callout; struct callout mii_callout;
struct cpsw_softc *swsc; struct cpsw_softc *swsc;
struct ifnet *ifp; if_t ifp;
struct mii_data *mii; struct mii_data *mii;
struct mtx lock; struct mtx lock;
uint32_t if_flags; uint32_t if_flags;