git: e330262f34fc - main - Mechanically convert netmap(4) to IfAPI
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 14 Feb 2023 15:36:17 UTC
The branch main has been updated by jhibbits:
URL: https://cgit.FreeBSD.org/src/commit/?id=e330262f34fc179ce920c16bb28ba8a1c4a73aff
commit e330262f34fc179ce920c16bb28ba8a1c4a73aff
Author: Justin Hibbits <jhibbits@FreeBSD.org>
AuthorDate: 2023-01-12 18:38:37 +0000
Commit: Justin Hibbits <jhibbits@FreeBSD.org>
CommitDate: 2023-02-14 15:21:19 +0000
Mechanically convert netmap(4) to IfAPI
Reviewed by: vmaffione, zlei
Sponsored by: Juniper Networks, Inc.
Differential Revision: https://reviews.freebsd.org/D37814
---
sys/dev/netmap/if_ptnet.c | 86 +++++++++++++++++++-------------------
sys/dev/netmap/if_re_netmap.h | 14 +++----
sys/dev/netmap/if_vtnet_netmap.h | 22 +++++-----
sys/dev/netmap/netmap.c | 44 ++++++++++----------
sys/dev/netmap/netmap_bdg.c | 4 +-
sys/dev/netmap/netmap_bdg.h | 2 +-
sys/dev/netmap/netmap_freebsd.c | 90 ++++++++++++++++++++--------------------
sys/dev/netmap/netmap_generic.c | 12 +++---
sys/dev/netmap/netmap_kern.h | 74 ++++++++++++++++-----------------
sys/dev/netmap/netmap_kloop.c | 2 +-
sys/dev/netmap/netmap_legacy.c | 4 +-
sys/dev/netmap/netmap_mem2.c | 14 +++----
sys/dev/netmap/netmap_mem2.h | 4 +-
sys/dev/netmap/netmap_monitor.c | 2 +-
sys/dev/netmap/netmap_pipe.c | 2 +-
sys/dev/netmap/netmap_vale.c | 14 +++----
16 files changed, 194 insertions(+), 196 deletions(-)
diff --git a/sys/dev/netmap/if_ptnet.c b/sys/dev/netmap/if_ptnet.c
index be75da2db9dc..5b3332ee5915 100644
--- a/sys/dev/netmap/if_ptnet.c
+++ b/sys/dev/netmap/if_ptnet.c
@@ -408,14 +408,14 @@ ptnet_attach(device_t dev)
}
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
- ifp->if_baudrate = IF_Gbps(10);
- ifp->if_softc = sc;
- ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX;
- ifp->if_init = ptnet_init;
- ifp->if_ioctl = ptnet_ioctl;
- ifp->if_get_counter = ptnet_get_counter;
- ifp->if_transmit = ptnet_transmit;
- ifp->if_qflush = ptnet_qflush;
+ if_setbaudrate(ifp, IF_Gbps(10));
+ if_setsoftc(ifp, sc);
+ if_setflags(ifp, IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX);
+ if_setinitfn(ifp, ptnet_init);
+ if_setioctlfn(ifp, ptnet_ioctl);
+ if_setget_counter(ifp, ptnet_get_counter);
+ if_settransmitfn(ifp, ptnet_transmit);
+ if_setqflushfn(ifp, ptnet_qflush);
ifmedia_init(&sc->media, IFM_IMASK, ptnet_media_change,
ptnet_media_status);
@@ -433,25 +433,25 @@ ptnet_attach(device_t dev)
ether_ifattach(ifp, sc->hwaddr);
- ifp->if_hdrlen = sizeof(struct ether_vlan_header);
- ifp->if_capabilities |= IFCAP_JUMBO_MTU | IFCAP_VLAN_MTU;
+ if_setifheaderlen(ifp, sizeof(struct ether_vlan_header));
+ if_setcapabilitiesbit(ifp, IFCAP_JUMBO_MTU | IFCAP_VLAN_MTU, 0);
if (sc->ptfeatures & PTNETMAP_F_VNET_HDR) {
/* Similarly to what the vtnet driver does, we can emulate
* VLAN offloadings by inserting and removing the 802.1Q
* header during transmit and receive. We are then able
* to do checksum offloading of VLAN frames. */
- ifp->if_capabilities |= IFCAP_HWCSUM | IFCAP_HWCSUM_IPV6
+ if_setcapabilitiesbit(ifp, IFCAP_HWCSUM | IFCAP_HWCSUM_IPV6
| IFCAP_VLAN_HWCSUM
| IFCAP_TSO | IFCAP_LRO
| IFCAP_VLAN_HWTSO
- | IFCAP_VLAN_HWTAGGING;
+ | IFCAP_VLAN_HWTAGGING, 0);
}
- ifp->if_capenable = ifp->if_capabilities;
+ if_setcapenable(ifp, if_getcapabilities(ifp));
#ifdef DEVICE_POLLING
/* Don't enable polling by default. */
- ifp->if_capabilities |= IFCAP_POLLING;
+ if_setcapabilitiesbit(ifp, IFCAP_POLLING, 0);
#endif
snprintf(sc->lock_name, sizeof(sc->lock_name),
"%s", device_get_nameunit(dev));
@@ -517,7 +517,7 @@ ptnet_detach(device_t dev)
ptnet_device_shutdown(sc);
#ifdef DEVICE_POLLING
- if (sc->ifp->if_capenable & IFCAP_POLLING) {
+ if (if_getcapenable(sc->ifp) & IFCAP_POLLING) {
ether_poll_deregister(sc->ifp);
}
#endif
@@ -761,9 +761,9 @@ ptnet_ioctl(if_t ifp, u_long cmd, caddr_t data)
switch (cmd) {
case SIOCSIFFLAGS:
- device_printf(dev, "SIOCSIFFLAGS %x\n", ifp->if_flags);
+ device_printf(dev, "SIOCSIFFLAGS %x\n", if_getflags(ifp));
PTNET_CORE_LOCK(sc);
- if (ifp->if_flags & IFF_UP) {
+ if (if_getflags(ifp) & IFF_UP) {
/* Network stack wants the iff to be up. */
err = ptnet_init_locked(sc);
} else {
@@ -777,8 +777,8 @@ ptnet_ioctl(if_t ifp, u_long cmd, caddr_t data)
case SIOCSIFCAP:
device_printf(dev, "SIOCSIFCAP %x %x\n",
- ifr->ifr_reqcap, ifp->if_capenable);
- mask = ifr->ifr_reqcap ^ ifp->if_capenable;
+ ifr->ifr_reqcap, if_getcapenable(ifp));
+ mask = ifr->ifr_reqcap ^ if_getcapenable(ifp);
#ifdef DEVICE_POLLING
if (mask & IFCAP_POLLING) {
struct ptnet_queue *pq;
@@ -790,7 +790,7 @@ ptnet_ioctl(if_t ifp, u_long cmd, caddr_t data)
break;
}
/* Stop queues and sync with taskqueues. */
- ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
+ if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
for (i = 0; i < sc->num_rings; i++) {
pq = sc-> queues + i;
/* Make sure the worker sees the
@@ -804,7 +804,7 @@ ptnet_ioctl(if_t ifp, u_long cmd, caddr_t data)
&pq->task);
}
}
- ifp->if_drv_flags |= IFF_DRV_RUNNING;
+ if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0);
} else {
err = ether_poll_deregister(ifp);
for (i = 0; i < sc->num_rings; i++) {
@@ -816,7 +816,7 @@ ptnet_ioctl(if_t ifp, u_long cmd, caddr_t data)
}
}
#endif /* DEVICE_POLLING */
- ifp->if_capenable = ifr->ifr_reqcap;
+ if_setcapenable(ifp, ifr->ifr_reqcap);
break;
case SIOCSIFMTU:
@@ -826,7 +826,7 @@ ptnet_ioctl(if_t ifp, u_long cmd, caddr_t data)
err = EINVAL;
} else {
PTNET_CORE_LOCK(sc);
- ifp->if_mtu = ifr->ifr_mtu;
+ if_setmtu(ifp, ifr->ifr_mtu);
PTNET_CORE_UNLOCK(sc);
}
break;
@@ -853,22 +853,22 @@ ptnet_init_locked(struct ptnet_softc *sc)
unsigned int nm_buf_size;
int ret;
- if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
+ if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) {
return 0; /* nothing to do */
}
device_printf(sc->dev, "%s\n", __func__);
/* Translate offload capabilities according to if_capenable. */
- ifp->if_hwassist = 0;
- if (ifp->if_capenable & IFCAP_TXCSUM)
- ifp->if_hwassist |= PTNET_CSUM_OFFLOAD;
- if (ifp->if_capenable & IFCAP_TXCSUM_IPV6)
- ifp->if_hwassist |= PTNET_CSUM_OFFLOAD_IPV6;
- if (ifp->if_capenable & IFCAP_TSO4)
- ifp->if_hwassist |= CSUM_IP_TSO;
- if (ifp->if_capenable & IFCAP_TSO6)
- ifp->if_hwassist |= CSUM_IP6_TSO;
+ if_sethwassist(ifp, 0);
+ if (if_getcapenable(ifp) & IFCAP_TXCSUM)
+ if_sethwassistbits(ifp, PTNET_CSUM_OFFLOAD, 0);
+ if (if_getcapenable(ifp) & IFCAP_TXCSUM_IPV6)
+ if_sethwassistbits(ifp, PTNET_CSUM_OFFLOAD_IPV6, 0);
+ if (if_getcapenable(ifp) & IFCAP_TSO4)
+ if_sethwassistbits(ifp, CSUM_IP_TSO, 0);
+ if (if_getcapenable(ifp) & IFCAP_TSO6)
+ if_sethwassistbits(ifp, CSUM_IP6_TSO, 0);
/*
* Prepare the interface for netmap mode access.
@@ -919,7 +919,7 @@ ptnet_init_locked(struct ptnet_softc *sc)
callout_reset(&sc->tick, hz, ptnet_tick, sc);
#endif
- ifp->if_drv_flags |= IFF_DRV_RUNNING;
+ if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0);
return 0;
@@ -946,14 +946,14 @@ ptnet_stop(struct ptnet_softc *sc)
device_printf(sc->dev, "%s\n", __func__);
- if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
+ if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) {
return 0; /* nothing to do */
}
/* Clear the driver-ready flag, and synchronize with all the queues,
* so that after this loop we are sure nobody is working anymore with
* the device. This scheme is taken from the vtnet driver. */
- ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
+ if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
callout_stop(&sc->tick);
for (i = 0; i < sc->num_rings; i++) {
PTNET_Q_LOCK(sc->queues + i);
@@ -1198,7 +1198,7 @@ ptnet_nm_register(struct netmap_adapter *na, int onoff)
pq = sc->queues + i;
pq->ktoa->kern_need_kick = 1;
pq->atok->appl_need_kick =
- (!(ifp->if_capenable & IFCAP_POLLING)
+ (!(if_getcapenable(ifp) & IFCAP_POLLING)
&& i >= sc->num_tx_rings);
}
@@ -1407,7 +1407,7 @@ ptnet_drain_transmit_queue(struct ptnet_queue *pq, unsigned int budget,
return 0;
}
- if (unlikely(!(ifp->if_drv_flags & IFF_DRV_RUNNING))) {
+ if (unlikely(!(if_getdrvflags(ifp) & IFF_DRV_RUNNING))) {
PTNET_Q_UNLOCK(pq);
nm_prlim(1, "Interface is down");
return ENETDOWN;
@@ -1609,7 +1609,7 @@ ptnet_transmit(if_t ifp, struct mbuf *m)
return err;
}
- if (ifp->if_capenable & IFCAP_POLLING) {
+ if (if_getcapenable(ifp) & IFCAP_POLLING) {
/* If polling is on, the transmit queues will be
* drained by the poller. */
return 0;
@@ -1693,7 +1693,7 @@ ptnet_rx_eof(struct ptnet_queue *pq, unsigned int budget, bool may_resched)
PTNET_Q_LOCK(pq);
- if (unlikely(!(ifp->if_drv_flags & IFF_DRV_RUNNING))) {
+ if (unlikely(!(if_getdrvflags(ifp) & IFF_DRV_RUNNING))) {
goto unlock;
}
@@ -1837,7 +1837,7 @@ host_sync:
mhead->m_pkthdr.flowid = pq->kring_id;
M_HASHTYPE_SET(mhead, M_HASHTYPE_OPAQUE);
- if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) {
+ if (if_getcapenable(ifp) & IFCAP_VLAN_HWTAGGING) {
struct ether_header *eh;
eh = mtod(mhead, struct ether_header *);
@@ -1874,7 +1874,7 @@ skip:
pq->stats.bytes += mhead->m_pkthdr.len;
PTNET_Q_UNLOCK(pq);
- (*ifp->if_input)(ifp, mhead);
+ if_input(ifp, mhead);
PTNET_Q_LOCK(pq);
/* The ring->head index (and related indices) are
* updated under pq lock by ptnet_ring_update().
@@ -1883,7 +1883,7 @@ skip:
* ring from there. */
head = ring->head;
- if (unlikely(!(ifp->if_drv_flags & IFF_DRV_RUNNING))) {
+ if (unlikely(!(if_getdrvflags(ifp) & IFF_DRV_RUNNING))) {
/* The interface has gone down while we didn't
* have the lock. Stop any processing and exit. */
goto unlock;
diff --git a/sys/dev/netmap/if_re_netmap.h b/sys/dev/netmap/if_re_netmap.h
index 7c356ab4bd22..d658a3e5c8a7 100644
--- a/sys/dev/netmap/if_re_netmap.h
+++ b/sys/dev/netmap/if_re_netmap.h
@@ -47,8 +47,8 @@
static int
re_netmap_reg(struct netmap_adapter *na, int onoff)
{
- struct ifnet *ifp = na->ifp;
- struct rl_softc *adapter = ifp->if_softc;
+ if_t ifp = na->ifp;
+ struct rl_softc *adapter = if_getsoftc(ifp);
RL_LOCK(adapter);
re_stop(adapter); /* also clears IFF_DRV_RUNNING */
@@ -59,7 +59,7 @@ re_netmap_reg(struct netmap_adapter *na, int onoff)
}
re_init_locked(adapter); /* also enables intr */
RL_UNLOCK(adapter);
- return (ifp->if_drv_flags & IFF_DRV_RUNNING ? 0 : 1);
+ return (if_getdrvflags(ifp) & IFF_DRV_RUNNING ? 0 : 1);
}
@@ -70,7 +70,7 @@ static int
re_netmap_txsync(struct netmap_kring *kring, int flags)
{
struct netmap_adapter *na = kring->na;
- struct ifnet *ifp = na->ifp;
+ if_t ifp = na->ifp;
struct netmap_ring *ring = kring->ring;
u_int nm_i; /* index into the netmap ring */
u_int nic_i; /* index into the NIC ring */
@@ -79,7 +79,7 @@ re_netmap_txsync(struct netmap_kring *kring, int flags)
u_int const head = kring->rhead;
/* device-specific */
- struct rl_softc *sc = ifp->if_softc;
+ struct rl_softc *sc = if_getsoftc(ifp);
struct rl_txdesc *txd = sc->rl_ldata.rl_tx_desc;
bus_dmamap_sync(sc->rl_ldata.rl_tx_list_tag,
@@ -172,7 +172,7 @@ static int
re_netmap_rxsync(struct netmap_kring *kring, int flags)
{
struct netmap_adapter *na = kring->na;
- struct ifnet *ifp = na->ifp;
+ if_t ifp = na->ifp;
struct netmap_ring *ring = kring->ring;
u_int nm_i; /* index into the netmap ring */
u_int nic_i; /* index into the NIC ring */
@@ -181,7 +181,7 @@ re_netmap_rxsync(struct netmap_kring *kring, int flags)
int force_update = (flags & NAF_FORCE_READ) || kring->nr_kflags & NKR_PENDINTR;
/* device-specific */
- struct rl_softc *sc = ifp->if_softc;
+ struct rl_softc *sc = if_getsoftc(ifp);
struct rl_rxdesc *rxd = sc->rl_ldata.rl_rx_desc;
if (head > lim)
diff --git a/sys/dev/netmap/if_vtnet_netmap.h b/sys/dev/netmap/if_vtnet_netmap.h
index 8bff697b3fdb..fc18976ee023 100644
--- a/sys/dev/netmap/if_vtnet_netmap.h
+++ b/sys/dev/netmap/if_vtnet_netmap.h
@@ -37,15 +37,15 @@
static int
vtnet_netmap_reg(struct netmap_adapter *na, int state)
{
- struct ifnet *ifp = na->ifp;
- struct vtnet_softc *sc = ifp->if_softc;
+ if_t ifp = na->ifp;
+ struct vtnet_softc *sc = if_getsoftc(ifp);
/*
* Trigger a device reinit, asking vtnet_init_locked() to
* also enter or exit netmap mode.
*/
VTNET_CORE_LOCK(sc);
- ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
+ if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
vtnet_init_locked(sc, state ? VTNET_INIT_NETMAP_ENTER
: VTNET_INIT_NETMAP_EXIT);
VTNET_CORE_UNLOCK(sc);
@@ -59,7 +59,7 @@ static int
vtnet_netmap_txsync(struct netmap_kring *kring, int flags)
{
struct netmap_adapter *na = kring->na;
- struct ifnet *ifp = na->ifp;
+ if_t ifp = na->ifp;
struct netmap_ring *ring = kring->ring;
u_int ring_nr = kring->ring_id;
u_int nm_i; /* index into the netmap ring */
@@ -67,7 +67,7 @@ vtnet_netmap_txsync(struct netmap_kring *kring, int flags)
u_int const head = kring->rhead;
/* device-specific */
- struct vtnet_softc *sc = ifp->if_softc;
+ struct vtnet_softc *sc = if_getsoftc(ifp);
struct vtnet_txq *txq = &sc->vtnet_txqs[ring_nr];
struct virtqueue *vq = txq->vtntx_vq;
int interrupts = !(kring->nr_kflags & NKR_NOINTR);
@@ -154,14 +154,14 @@ static int
vtnet_netmap_kring_refill(struct netmap_kring *kring, u_int num)
{
struct netmap_adapter *na = kring->na;
- struct ifnet *ifp = na->ifp;
+ if_t ifp = na->ifp;
struct netmap_ring *ring = kring->ring;
u_int ring_nr = kring->ring_id;
u_int const lim = kring->nkr_num_slots - 1;
u_int nm_i;
/* device-specific */
- struct vtnet_softc *sc = ifp->if_softc;
+ struct vtnet_softc *sc = if_getsoftc(ifp);
struct vtnet_rxq *rxq = &sc->vtnet_rxqs[ring_nr];
struct virtqueue *vq = rxq->vtnrx_vq;
@@ -245,7 +245,7 @@ static int
vtnet_netmap_rxsync(struct netmap_kring *kring, int flags)
{
struct netmap_adapter *na = kring->na;
- struct ifnet *ifp = na->ifp;
+ if_t ifp = na->ifp;
struct netmap_ring *ring = kring->ring;
u_int ring_nr = kring->ring_id;
u_int nm_i; /* index into the netmap ring */
@@ -256,7 +256,7 @@ vtnet_netmap_rxsync(struct netmap_kring *kring, int flags)
int interrupts = !(kring->nr_kflags & NKR_NOINTR);
/* device-specific */
- struct vtnet_softc *sc = ifp->if_softc;
+ struct vtnet_softc *sc = if_getsoftc(ifp);
struct vtnet_rxq *rxq = &sc->vtnet_rxqs[ring_nr];
struct virtqueue *vq = rxq->vtnrx_vq;
@@ -349,7 +349,7 @@ vtnet_netmap_rxsync(struct netmap_kring *kring, int flags)
static void
vtnet_netmap_intr(struct netmap_adapter *na, int state)
{
- struct vtnet_softc *sc = na->ifp->if_softc;
+ struct vtnet_softc *sc = if_getsoftc(na->ifp);
int i;
for (i = 0; i < sc->vtnet_max_vq_pairs; i++) {
@@ -416,7 +416,7 @@ vtnet_netmap_rx_slots(struct vtnet_softc *sc)
static int
vtnet_netmap_config(struct netmap_adapter *na, struct nm_config_info *info)
{
- struct vtnet_softc *sc = na->ifp->if_softc;
+ struct vtnet_softc *sc = if_getsoftc(na->ifp);
info->num_tx_rings = sc->vtnet_act_vq_pairs;
info->num_rx_rings = sc->vtnet_act_vq_pairs;
diff --git a/sys/dev/netmap/netmap.c b/sys/dev/netmap/netmap.c
index 37723fb36fe8..acc05513fbb2 100644
--- a/sys/dev/netmap/netmap.c
+++ b/sys/dev/netmap/netmap.c
@@ -637,7 +637,7 @@ netmap_set_all_rings(struct netmap_adapter *na, int stopped)
* onload).
*/
void
-netmap_disable_all_rings(struct ifnet *ifp)
+netmap_disable_all_rings(if_t ifp)
{
if (NM_NA_VALID(ifp)) {
netmap_set_all_rings(NA(ifp), NM_KR_LOCKED);
@@ -650,7 +650,7 @@ netmap_disable_all_rings(struct ifnet *ifp)
* napi_enable().
*/
void
-netmap_enable_all_rings(struct ifnet *ifp)
+netmap_enable_all_rings(if_t ifp)
{
if (NM_NA_VALID(ifp)) {
netmap_set_all_rings(NA(ifp), 0 /* enabled */);
@@ -658,7 +658,7 @@ netmap_enable_all_rings(struct ifnet *ifp)
}
void
-netmap_make_zombie(struct ifnet *ifp)
+netmap_make_zombie(if_t ifp)
{
if (NM_NA_VALID(ifp)) {
struct netmap_adapter *na = NA(ifp);
@@ -669,7 +669,7 @@ netmap_make_zombie(struct ifnet *ifp)
}
void
-netmap_undo_zombie(struct ifnet *ifp)
+netmap_undo_zombie(if_t ifp)
{
if (NM_NA_VALID(ifp)) {
struct netmap_adapter *na = NA(ifp);
@@ -764,7 +764,7 @@ netmap_update_config(struct netmap_adapter *na)
struct nm_config_info info;
if (na->ifp && !nm_is_bwrap(na)) {
- strlcpy(na->name, na->ifp->if_xname, sizeof(na->name));
+ strlcpy(na->name, if_name(na->ifp), sizeof(na->name));
}
bzero(&info, sizeof(info));
@@ -1194,7 +1194,7 @@ netmap_dtor(void *data)
* After this call the queue is empty.
*/
static void
-netmap_send_up(struct ifnet *dst, struct mbq *q)
+netmap_send_up(if_t dst, struct mbq *q)
{
struct mbuf *m;
struct mbuf *head = NULL, *prev = NULL;
@@ -1465,7 +1465,7 @@ netmap_rxsync_from_host(struct netmap_kring *kring, int flags)
*/
static void netmap_hw_dtor(struct netmap_adapter *); /* needed by NM_IS_NATIVE() */
int
-netmap_get_hw_na(struct ifnet *ifp, struct netmap_mem_d *nmd, struct netmap_adapter **na)
+netmap_get_hw_na(if_t ifp, struct netmap_mem_d *nmd, struct netmap_adapter **na)
{
/* generic support */
int i = netmap_admode; /* Take a snapshot. */
@@ -1555,7 +1555,7 @@ assign_mem:
*/
int
netmap_get_na(struct nmreq_header *hdr,
- struct netmap_adapter **na, struct ifnet **ifp,
+ struct netmap_adapter **na, if_t *ifp,
struct netmap_mem_d *nmd, int create)
{
struct nmreq_register *req = (struct nmreq_register *)(uintptr_t)hdr->nr_body;
@@ -1671,7 +1671,7 @@ out:
/* undo netmap_get_na() */
void
-netmap_unget_na(struct netmap_adapter *na, struct ifnet *ifp)
+netmap_unget_na(struct netmap_adapter *na, if_t ifp)
{
if (ifp)
if_rele(ifp);
@@ -2256,12 +2256,12 @@ netmap_buf_size_validate(const struct netmap_adapter *na, unsigned mtu) {
nm_prerr("error: large MTU (%d) needed "
"but %s does not support "
"NS_MOREFRAG", mtu,
- na->ifp->if_xname);
+ if_name(na->ifp));
return EINVAL;
} else if (nbs < na->rx_buf_maxsize) {
nm_prerr("error: using NS_MOREFRAG on "
"%s requires netmap buf size "
- ">= %u", na->ifp->if_xname,
+ ">= %u", if_name(na->ifp),
na->rx_buf_maxsize);
return EINVAL;
} else {
@@ -2269,7 +2269,7 @@ netmap_buf_size_validate(const struct netmap_adapter *na, unsigned mtu) {
"%s needs to support "
"NS_MOREFRAG "
"(MTU=%u,netmap_buf_size=%u)",
- na->ifp->if_xname, mtu, nbs);
+ if_name(na->ifp), mtu, nbs);
}
}
return 0;
@@ -2744,7 +2744,7 @@ netmap_ioctl(struct netmap_priv_d *priv, u_long cmd, caddr_t data,
struct mbq q; /* packets from RX hw queues to host stack */
struct netmap_adapter *na = NULL;
struct netmap_mem_d *nmd = NULL;
- struct ifnet *ifp = NULL;
+ if_t ifp = NULL;
int error = 0;
u_int i, qfirst, qlast;
struct netmap_kring **krings;
@@ -3039,7 +3039,7 @@ netmap_ioctl(struct netmap_priv_d *priv, u_long cmd, caddr_t data,
/* Build a nmreq_register out of the nmreq_port_hdr,
* so that we can call netmap_get_bdg_na(). */
struct nmreq_register regreq;
- struct ifnet *ifp;
+ if_t ifp;
bzero(®req, sizeof(regreq));
regreq.nr_mode = NR_REG_ALL_NIC;
@@ -3973,7 +3973,7 @@ netmap_attach_common(struct netmap_adapter *na)
#ifdef __FreeBSD__
if (na->na_flags & NAF_HOST_RINGS && na->ifp) {
- na->if_input = na->ifp->if_input; /* for netmap_send_up */
+ na->if_input = if_getinputfn(na->ifp); /* for netmap_send_up */
}
na->pdev = na; /* make sure netmap_mem_map() is called */
#endif /* __FreeBSD__ */
@@ -4063,7 +4063,7 @@ int
netmap_attach_ext(struct netmap_adapter *arg, size_t size, int override_reg)
{
struct netmap_hw_adapter *hwna = NULL;
- struct ifnet *ifp = NULL;
+ if_t ifp = NULL;
if (size < sizeof(struct netmap_hw_adapter)) {
if (netmap_debug & NM_DEBUG_ON)
@@ -4099,7 +4099,7 @@ netmap_attach_ext(struct netmap_adapter *arg, size_t size, int override_reg)
goto fail;
hwna->up = *arg;
hwna->up.na_flags |= NAF_HOST_RINGS | NAF_NATIVE;
- strlcpy(hwna->up.name, ifp->if_xname, sizeof(hwna->up.name));
+ strlcpy(hwna->up.name, if_name(ifp), sizeof(hwna->up.name));
if (override_reg) {
hwna->nm_hw_register = hwna->up.nm_register;
hwna->up.nm_register = netmap_hw_reg;
@@ -4197,7 +4197,7 @@ netmap_hw_krings_create(struct netmap_adapter *na)
* Called on module unload by the netmap-enabled drivers
*/
void
-netmap_detach(struct ifnet *ifp)
+netmap_detach(if_t ifp)
{
struct netmap_adapter *na;
@@ -4243,7 +4243,7 @@ netmap_detach(struct ifnet *ifp)
* we make sure to make the mode change visible here.
*/
int
-netmap_transmit(struct ifnet *ifp, struct mbuf *m)
+netmap_transmit(if_t ifp, struct mbuf *m)
{
struct netmap_adapter *na = NA(ifp);
struct netmap_kring *kring, *tx_kring;
@@ -4483,7 +4483,7 @@ netmap_common_irq(struct netmap_adapter *na, u_int q, u_int *work_done)
* calls the proper forwarding routine.
*/
int
-netmap_rx_irq(struct ifnet *ifp, u_int q, u_int *work_done)
+netmap_rx_irq(if_t ifp, u_int q, u_int *work_done)
{
struct netmap_adapter *na = NA(ifp);
@@ -4508,7 +4508,7 @@ netmap_rx_irq(struct ifnet *ifp, u_int q, u_int *work_done)
void
nm_set_native_flags(struct netmap_adapter *na)
{
- struct ifnet *ifp = na->ifp;
+ if_t ifp = na->ifp;
/* We do the setup for intercepting packets only if we are the
* first user of this adapter. */
@@ -4524,7 +4524,7 @@ nm_set_native_flags(struct netmap_adapter *na)
void
nm_clear_native_flags(struct netmap_adapter *na)
{
- struct ifnet *ifp = na->ifp;
+ if_t ifp = na->ifp;
/* We undo the setup for intercepting packets only if we are the
* last user of this adapter. */
diff --git a/sys/dev/netmap/netmap_bdg.c b/sys/dev/netmap/netmap_bdg.c
index 1d49a97eec12..62b4c8801a47 100644
--- a/sys/dev/netmap/netmap_bdg.c
+++ b/sys/dev/netmap/netmap_bdg.c
@@ -390,7 +390,7 @@ netmap_get_bdg_na(struct nmreq_header *hdr, struct netmap_adapter **na,
{
char *nr_name = hdr->nr_name;
const char *ifname;
- struct ifnet *ifp = NULL;
+ if_t ifp = NULL;
int error = 0;
struct netmap_vp_adapter *vpna, *hostna = NULL;
struct nm_bridge *b;
@@ -1777,7 +1777,7 @@ netmap_bwrap_attach_common(struct netmap_adapter *na,
na->na_flags |= NAF_MOREFRAG;
nm_prdis("%s<->%s txr %d txd %d rxr %d rxd %d",
- na->name, ifp->if_xname,
+ na->name, if_name(ifp),
na->num_tx_rings, na->num_tx_desc,
na->num_rx_rings, na->num_rx_desc);
diff --git a/sys/dev/netmap/netmap_bdg.h b/sys/dev/netmap/netmap_bdg.h
index ac8629141601..f5148c7407b7 100644
--- a/sys/dev/netmap/netmap_bdg.h
+++ b/sys/dev/netmap/netmap_bdg.h
@@ -59,7 +59,7 @@ typedef int (*bdg_config_fn_t)(struct nm_ifreq *);
typedef void (*bdg_dtor_fn_t)(const struct netmap_vp_adapter *);
typedef void *(*bdg_update_private_data_fn_t)(void *private_data, void *callback_data, int *error);
typedef int (*bdg_vp_create_fn_t)(struct nmreq_header *hdr,
- struct ifnet *ifp, struct netmap_mem_d *nmd,
+ if_t ifp, struct netmap_mem_d *nmd,
struct netmap_vp_adapter **ret);
typedef int (*bdg_bwrap_attach_fn_t)(const char *nr_name, struct netmap_adapter *hwna);
struct netmap_bdg_ops {
diff --git a/sys/dev/netmap/netmap_freebsd.c b/sys/dev/netmap/netmap_freebsd.c
index 8c480f2fb092..3b2fdd214f24 100644
--- a/sys/dev/netmap/netmap_freebsd.c
+++ b/sys/dev/netmap/netmap_freebsd.c
@@ -171,13 +171,13 @@ nm_os_put_module(void)
}
static void
-netmap_ifnet_arrival_handler(void *arg __unused, struct ifnet *ifp)
+netmap_ifnet_arrival_handler(void *arg __unused, if_t ifp)
{
netmap_undo_zombie(ifp);
}
static void
-netmap_ifnet_departure_handler(void *arg __unused, struct ifnet *ifp)
+netmap_ifnet_departure_handler(void *arg __unused, if_t ifp)
{
netmap_make_zombie(ifp);
}
@@ -209,9 +209,9 @@ nm_os_ifnet_fini(void)
}
unsigned
-nm_os_ifnet_mtu(struct ifnet *ifp)
+nm_os_ifnet_mtu(if_t ifp)
{
- return ifp->if_mtu;
+ return if_getmtu(ifp);
}
rawsum_t
@@ -294,7 +294,7 @@ nm_os_csum_tcpudp_ipv6(struct nm_ipv6hdr *ip6h, void *data,
/* on FreeBSD we send up one packet at a time */
void *
-nm_os_send_up(struct ifnet *ifp, struct mbuf *m, struct mbuf *prev)
+nm_os_send_up(if_t ifp, struct mbuf *m, struct mbuf *prev)
{
NA(ifp)->if_input(ifp, m);
return NULL;
@@ -315,7 +315,7 @@ nm_os_mbuf_has_seg_offld(struct mbuf *m)
}
static void
-freebsd_generic_rx_handler(struct ifnet *ifp, struct mbuf *m)
+freebsd_generic_rx_handler(if_t ifp, struct mbuf *m)
{
int stolen;
@@ -341,7 +341,7 @@ int
nm_os_catch_rx(struct netmap_generic_adapter *gna, int intercept)
{
struct netmap_adapter *na = &gna->up.up;
- struct ifnet *ifp = na->ifp;
+ if_t ifp = na->ifp;
int ret = 0;
nm_os_ifnet_lock();
@@ -351,10 +351,9 @@ nm_os_catch_rx(struct netmap_generic_adapter *gna, int intercept)
ret = EBUSY; /* already set */
goto out;
}
-
- ifp->if_capenable |= IFCAP_NETMAP;
- gna->save_if_input = ifp->if_input;
- ifp->if_input = freebsd_generic_rx_handler;
+ if_setcapenablebit(ifp, IFCAP_NETMAP, 0);
+ gna->save_if_input = if_getinputfn(ifp);
+ if_setinputfn(ifp, freebsd_generic_rx_handler);
} else {
if (!gna->save_if_input) {
nm_prerr("Failed to undo RX intercept on %s",
@@ -362,9 +361,8 @@ nm_os_catch_rx(struct netmap_generic_adapter *gna, int intercept)
ret = EINVAL; /* not saved */
goto out;
}
-
- ifp->if_capenable &= ~IFCAP_NETMAP;
- ifp->if_input = gna->save_if_input;
+ if_setcapenablebit(ifp, 0, IFCAP_NETMAP);
+ if_setinputfn(ifp, gna->save_if_input);
gna->save_if_input = NULL;
}
out:
@@ -384,14 +382,14 @@ int
nm_os_catch_tx(struct netmap_generic_adapter *gna, int intercept)
{
struct netmap_adapter *na = &gna->up.up;
- struct ifnet *ifp = netmap_generic_getifp(gna);
+ if_t ifp = netmap_generic_getifp(gna);
nm_os_ifnet_lock();
if (intercept) {
- na->if_transmit = ifp->if_transmit;
- ifp->if_transmit = netmap_transmit;
+ na->if_transmit = if_gettransmitfn(ifp);
+ if_settransmitfn(ifp, netmap_transmit);
} else {
- ifp->if_transmit = na->if_transmit;
+ if_settransmitfn(ifp, na->if_transmit);
}
nm_os_ifnet_unlock();
@@ -420,7 +418,7 @@ nm_os_generic_xmit_frame(struct nm_os_gen_arg *a)
{
int ret;
u_int len = a->len;
- struct ifnet *ifp = a->ifp;
+ if_t ifp = a->ifp;
struct mbuf *m = a->m;
/* Link the external storage to
@@ -437,7 +435,7 @@ nm_os_generic_xmit_frame(struct nm_os_gen_arg *a)
M_HASHTYPE_SET(m, M_HASHTYPE_OPAQUE);
m->m_pkthdr.flowid = a->ring_nr;
m->m_pkthdr.rcvif = ifp; /* used for tx notification */
- CURVNET_SET(ifp->if_vnet);
+ CURVNET_SET(if_getvnet(ifp));
ret = NA(ifp)->if_transmit(ifp, m);
CURVNET_RESTORE();
return ret ? -1 : 0;
@@ -447,7 +445,7 @@ nm_os_generic_xmit_frame(struct nm_os_gen_arg *a)
struct netmap_adapter *
netmap_getna(if_t ifp)
{
- return (NA((struct ifnet *)ifp));
+ return (NA(ifp));
}
/*
@@ -455,14 +453,14 @@ netmap_getna(if_t ifp)
* way to extract the info from the ifp
*/
int
-nm_os_generic_find_num_desc(struct ifnet *ifp, unsigned int *tx, unsigned int *rx)
+nm_os_generic_find_num_desc(if_t ifp, unsigned int *tx, unsigned int *rx)
{
return 0;
}
void
-nm_os_generic_find_num_queues(struct ifnet *ifp, u_int *txq, u_int *rxq)
+nm_os_generic_find_num_queues(if_t ifp, u_int *txq, u_int *rxq)
{
unsigned num_rings = netmap_generic_rings ? netmap_generic_rings : 1;
@@ -513,14 +511,14 @@ nm_os_mitigation_cleanup(struct nm_generic_mit *mit)
}
static int
-nm_vi_dummy(struct ifnet *ifp, u_long cmd, caddr_t addr)
+nm_vi_dummy(if_t ifp, u_long cmd, caddr_t addr)
{
return EINVAL;
}
static void
-nm_vi_start(struct ifnet *ifp)
+nm_vi_start(if_t ifp)
{
panic("nm_vi_start() must not be called");
}
@@ -594,9 +592,9 @@ nm_vi_free_index(uint8_t val)
* increment this refcount on if_attach().
*/
int
-nm_os_vi_persist(const char *name, struct ifnet **ret)
+nm_os_vi_persist(const char *name, if_t *ret)
{
- struct ifnet *ifp;
+ if_t ifp;
u_short macaddr_hi;
uint32_t macaddr_mid;
u_char eaddr[6];
@@ -620,14 +618,14 @@ nm_os_vi_persist(const char *name, struct ifnet **ret)
return ENOMEM;
}
if_initname(ifp, name, IF_DUNIT_NONE);
- ifp->if_flags = IFF_UP | IFF_SIMPLEX | IFF_MULTICAST;
- ifp->if_init = (void *)nm_vi_dummy;
- ifp->if_ioctl = nm_vi_dummy;
- ifp->if_start = nm_vi_start;
- ifp->if_mtu = ETHERMTU;
- IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
- ifp->if_capabilities |= IFCAP_LINKSTATE;
- ifp->if_capenable |= IFCAP_LINKSTATE;
+ if_setflags(ifp, IFF_UP | IFF_SIMPLEX | IFF_MULTICAST);
+ if_setinitfn(ifp, (void *)nm_vi_dummy);
+ if_setioctlfn(ifp, nm_vi_dummy);
+ if_setstartfn(ifp, nm_vi_start);
+ if_setmtu(ifp, ETHERMTU);
+ if_setsendqlen(ifp, ifqmaxlen);
+ if_setcapabilitiesbit(ifp, IFCAP_LINKSTATE, 0);
+ if_setcapenablebit(ifp, IFCAP_LINKSTATE, 0);
ether_ifattach(ifp, eaddr);
*ret = ifp;
@@ -636,9 +634,9 @@ nm_os_vi_persist(const char *name, struct ifnet **ret)
/* unregister from the system and drop the final refcount */
void
-nm_os_vi_detach(struct ifnet *ifp)
+nm_os_vi_detach(if_t ifp)
{
- nm_vi_free_index(((char *)IF_LLADDR(ifp))[5]);
+ nm_vi_free_index(((char *)if_getlladdr(ifp))[5]);
ether_ifdetach(ifp);
if_free(ifp);
}
@@ -1502,28 +1500,28 @@ out:
}
void
-nm_os_onattach(struct ifnet *ifp)
+nm_os_onattach(if_t ifp)
{
- ifp->if_capabilities |= IFCAP_NETMAP;
+ if_setcapabilitiesbit(ifp, IFCAP_NETMAP, 0);
}
void
-nm_os_onenter(struct ifnet *ifp)
+nm_os_onenter(if_t ifp)
{
struct netmap_adapter *na = NA(ifp);
- na->if_transmit = ifp->if_transmit;
- ifp->if_transmit = netmap_transmit;
- ifp->if_capenable |= IFCAP_NETMAP;
+ na->if_transmit = if_gettransmitfn(ifp);
+ if_settransmitfn(ifp, netmap_transmit);
+ if_setcapenablebit(ifp, IFCAP_NETMAP, 0);
}
void
-nm_os_onexit(struct ifnet *ifp)
+nm_os_onexit(if_t ifp)
{
struct netmap_adapter *na = NA(ifp);
- ifp->if_transmit = na->if_transmit;
- ifp->if_capenable &= ~IFCAP_NETMAP;
+ if_settransmitfn(ifp, na->if_transmit);
+ if_setcapenablebit(ifp, 0, IFCAP_NETMAP);
}
extern struct cdevsw netmap_cdevsw; /* XXX used in netmap.c, should go elsewhere */
diff --git a/sys/dev/netmap/netmap_generic.c b/sys/dev/netmap/netmap_generic.c
index 83908f10a3fe..038d6efc33f5 100644
--- a/sys/dev/netmap/netmap_generic.c
+++ b/sys/dev/netmap/netmap_generic.c
@@ -647,7 +647,7 @@ generic_netmap_txsync(struct netmap_kring *kring, int flags)
{
struct netmap_adapter *na = kring->na;
struct netmap_generic_adapter *gna = (struct netmap_generic_adapter *)na;
- struct ifnet *ifp = na->ifp;
+ if_t ifp = na->ifp;
struct netmap_ring *ring = kring->ring;
u_int nm_i; /* index into the netmap ring */ // j
u_int const lim = kring->nkr_num_slots - 1;
@@ -811,7 +811,7 @@ generic_netmap_txsync(struct netmap_kring *kring, int flags)
* Returns 1 if the packet was stolen, 0 otherwise.
*/
int
-generic_rx_handler(struct ifnet *ifp, struct mbuf *m)
+generic_rx_handler(if_t ifp, struct mbuf *m)
{
struct netmap_adapter *na = NA(ifp);
struct netmap_generic_adapter *gna = (struct netmap_generic_adapter *)na;
@@ -1019,7 +1019,7 @@ static void
generic_netmap_dtor(struct netmap_adapter *na)
{
struct netmap_generic_adapter *gna = (struct netmap_generic_adapter*)na;
- struct ifnet *ifp = netmap_generic_getifp(gna);
+ if_t ifp = netmap_generic_getifp(gna);
struct netmap_adapter *prev_na = gna->prev;
if (prev_na != NULL) {
@@ -1060,7 +1060,7 @@ na_is_generic(struct netmap_adapter *na)
* actual configuration.
*/
int
-generic_netmap_attach(struct ifnet *ifp)
+generic_netmap_attach(if_t ifp)
{
struct netmap_adapter *na;
struct netmap_generic_adapter *gna;
@@ -1068,7 +1068,7 @@ generic_netmap_attach(struct ifnet *ifp)
u_int num_tx_desc, num_rx_desc;
#ifdef __FreeBSD__
- if (ifp->if_type == IFT_LOOP) {
+ if (if_gettype(ifp) == IFT_LOOP) {
nm_prerr("if_loop is not supported by %s", __func__);
return EINVAL;
}
@@ -1097,7 +1097,7 @@ generic_netmap_attach(struct ifnet *ifp)
return ENOMEM;
}
na = (struct netmap_adapter *)gna;
- strlcpy(na->name, ifp->if_xname, sizeof(na->name));
+ strlcpy(na->name, if_name(ifp), sizeof(na->name));
na->ifp = ifp;
na->num_tx_desc = num_tx_desc;
na->num_rx_desc = num_rx_desc;
diff --git a/sys/dev/netmap/netmap_kern.h b/sys/dev/netmap/netmap_kern.h
index eb708f5a5cc7..b4c7e4c83f6b 100644
--- a/sys/dev/netmap/netmap_kern.h
+++ b/sys/dev/netmap/netmap_kern.h
@@ -110,7 +110,7 @@
#define NM_ATOMIC_TEST_AND_SET(p) (!atomic_cmpset_acq_int((p), 0, 1))
#define NM_ATOMIC_CLEAR(p) atomic_store_rel_int((p), 0)
*** 434 LINES SKIPPED ***