netmap: import changes from upstream
- make sure rings are disabled during resets - introduce netmap_update_hostrings_mode(), with support for multiple host rings - always initialize ni_bufs_head in netmap_if ni_bufs_head was not properly initialized when no external buffers were requestedx and contained the ni_bufs_head from the last request. This was causing spurious buffer frees when alternating between apps that used external buffers and apps that did not use them. - check na validitity under lock on detach - netmap_mem: fix leak on error path - nm_dispatch: fix compilation on Raspberry Pi MFC after: 2 weeks
This commit is contained in:
parent
f8c1b1a929
commit
98399ab06f
@ -1002,6 +1002,22 @@ netmap_mem_drop(struct netmap_adapter *na)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
netmap_update_hostrings_mode(struct netmap_adapter *na)
|
||||
{
|
||||
enum txrx t;
|
||||
struct netmap_kring *kring;
|
||||
int i;
|
||||
|
||||
for_rx_tx(t) {
|
||||
for (i = nma_get_nrings(na, t);
|
||||
i < netmap_real_rings(na, t); i++) {
|
||||
kring = NMR(na, t)[i];
|
||||
kring->nr_mode = kring->nr_pending_mode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Undo everything that was done in netmap_do_regif(). In particular,
|
||||
* call nm_register(ifp,0) to stop netmap mode on the interface and
|
||||
@ -1032,7 +1048,9 @@ netmap_do_unregif(struct netmap_priv_d *priv)
|
||||
#endif
|
||||
|
||||
if (na->active_fds <= 0 || nm_kring_pending(priv)) {
|
||||
netmap_set_all_rings(na, NM_KR_LOCKED);
|
||||
na->nm_register(na, 0);
|
||||
netmap_set_all_rings(na, 0);
|
||||
}
|
||||
|
||||
/* delete rings and buffers that are no longer needed */
|
||||
@ -2630,7 +2648,9 @@ netmap_do_regif(struct netmap_priv_d *priv, struct netmap_adapter *na,
|
||||
if (nm_kring_pending(priv)) {
|
||||
/* Some kring is switching mode, tell the adapter to
|
||||
* react on this. */
|
||||
netmap_set_all_rings(na, NM_KR_LOCKED);
|
||||
error = na->nm_register(na, 1);
|
||||
netmap_set_all_rings(na, 0);
|
||||
if (error)
|
||||
goto err_del_if;
|
||||
}
|
||||
@ -2858,6 +2878,8 @@ netmap_ioctl(struct netmap_priv_d *priv, u_long cmd, caddr_t data,
|
||||
&nifp->ni_bufs_head, req->nr_extra_bufs);
|
||||
if (netmap_verbose)
|
||||
nm_prinf("got %d extra buffers", req->nr_extra_bufs);
|
||||
} else {
|
||||
nifp->ni_bufs_head = 0;
|
||||
}
|
||||
req->nr_offset = netmap_mem_if_offset(na->nm_mem, nifp);
|
||||
|
||||
@ -4178,12 +4200,16 @@ netmap_hw_krings_create(struct netmap_adapter *na)
|
||||
void
|
||||
netmap_detach(struct ifnet *ifp)
|
||||
{
|
||||
struct netmap_adapter *na = NA(ifp);
|
||||
|
||||
if (!na)
|
||||
return;
|
||||
struct netmap_adapter *na;
|
||||
|
||||
NMG_LOCK();
|
||||
|
||||
if (!NM_NA_VALID(ifp)) {
|
||||
NMG_UNLOCK();
|
||||
return;
|
||||
}
|
||||
|
||||
na = NA(ifp);
|
||||
netmap_set_all_rings(na, NM_KR_LOCKED);
|
||||
/*
|
||||
* if the netmap adapter is not native, somebody
|
||||
@ -4491,7 +4517,7 @@ nm_set_native_flags(struct netmap_adapter *na)
|
||||
|
||||
na->na_flags |= NAF_NETMAP_ON;
|
||||
nm_os_onenter(ifp);
|
||||
nm_update_hostrings_mode(na);
|
||||
netmap_update_hostrings_mode(na);
|
||||
}
|
||||
|
||||
void
|
||||
@ -4505,7 +4531,7 @@ nm_clear_native_flags(struct netmap_adapter *na)
|
||||
return;
|
||||
}
|
||||
|
||||
nm_update_hostrings_mode(na);
|
||||
netmap_update_hostrings_mode(na);
|
||||
nm_os_onexit(ifp);
|
||||
|
||||
na->na_flags &= ~NAF_NETMAP_ON;
|
||||
|
@ -1435,16 +1435,6 @@ nm_iszombie(struct netmap_adapter *na)
|
||||
return na == NULL || (na->na_flags & NAF_ZOMBIE);
|
||||
}
|
||||
|
||||
static inline void
|
||||
nm_update_hostrings_mode(struct netmap_adapter *na)
|
||||
{
|
||||
/* Process nr_mode and nr_pending_mode for host rings. */
|
||||
na->tx_rings[na->num_tx_rings]->nr_mode =
|
||||
na->tx_rings[na->num_tx_rings]->nr_pending_mode;
|
||||
na->rx_rings[na->num_rx_rings]->nr_mode =
|
||||
na->rx_rings[na->num_rx_rings]->nr_pending_mode;
|
||||
}
|
||||
|
||||
void nm_set_native_flags(struct netmap_adapter *);
|
||||
void nm_clear_native_flags(struct netmap_adapter *);
|
||||
|
||||
|
@ -1706,7 +1706,7 @@ _netmap_mem_private_new(size_t size, struct netmap_obj_params *p, int grp_id,
|
||||
if (memtotal < poolsz) {
|
||||
nm_prerr("%s: request too large", d->pools[i].name);
|
||||
err = ENOMEM;
|
||||
goto error;
|
||||
goto error_rel_id;
|
||||
}
|
||||
memtotal -= poolsz;
|
||||
}
|
||||
@ -1731,14 +1731,15 @@ _netmap_mem_private_new(size_t size, struct netmap_obj_params *p, int grp_id,
|
||||
|
||||
err = netmap_mem_config(d);
|
||||
if (err)
|
||||
goto error_rel_id;
|
||||
goto error_destroy_lock;
|
||||
|
||||
d->flags &= ~NETMAP_MEM_FINALIZED;
|
||||
|
||||
return d;
|
||||
|
||||
error_rel_id:
|
||||
error_destroy_lock:
|
||||
NMA_LOCK_DESTROY(d);
|
||||
error_rel_id:
|
||||
nm_mem_release_id(d);
|
||||
error_free:
|
||||
nm_os_free(d);
|
||||
|
@ -1131,7 +1131,7 @@ nm_dispatch(struct nm_desc *d, int cnt, nm_cb_t cb, u_char *arg)
|
||||
slot = &ring->slot[i];
|
||||
d->hdr.len += slot->len;
|
||||
nbuf = (u_char *)NETMAP_BUF(ring, slot->buf_idx);
|
||||
if (oldbuf != NULL && nbuf - oldbuf == ring->nr_buf_size &&
|
||||
if (oldbuf != NULL && (uint32_t)(nbuf - oldbuf) == ring->nr_buf_size &&
|
||||
oldlen == ring->nr_buf_size) {
|
||||
d->hdr.caplen += slot->len;
|
||||
oldbuf = nbuf;
|
||||
|
Loading…
x
Reference in New Issue
Block a user