Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/netmap/netmap_mem2.c
Show First 20 Lines • Show All 2,112 Lines • ▼ Show 20 Lines | netmap_mem2_if_new(struct netmap_mem_d *nmd, | ||||
nifp = netmap_if_malloc(nmd, len); | nifp = netmap_if_malloc(nmd, len); | ||||
if (nifp == NULL) { | if (nifp == NULL) { | ||||
return NULL; | return NULL; | ||||
} | } | ||||
/* initialize base fields -- override const */ | /* initialize base fields -- override const */ | ||||
*(u_int *)(uintptr_t)&nifp->ni_tx_rings = na->num_tx_rings; | *(u_int *)(uintptr_t)&nifp->ni_tx_rings = na->num_tx_rings; | ||||
*(u_int *)(uintptr_t)&nifp->ni_rx_rings = na->num_rx_rings; | *(u_int *)(uintptr_t)&nifp->ni_rx_rings = na->num_rx_rings; | ||||
*(u_int *)(uintptr_t)&nifp->ni_host_tx_rings = | *(u_int *)(uintptr_t)&nifp->ni_host_tx_rings = | ||||
zlei: Drop spaces at the end of the lines. | |||||
(na->num_host_tx_rings ? na->num_host_tx_rings : 1); | (na->num_host_tx_rings ? na->num_host_tx_rings : 1); | ||||
*(u_int *)(uintptr_t)&nifp->ni_host_rx_rings = | *(u_int *)(uintptr_t)&nifp->ni_host_rx_rings = | ||||
(na->num_host_rx_rings ? na->num_host_rx_rings : 1); | (na->num_host_rx_rings ? na->num_host_rx_rings : 1); | ||||
strlcpy(nifp->ni_name, na->name, sizeof(nifp->ni_name)); | strlcpy(nifp->ni_name, na->name, sizeof(nifp->ni_name)); | ||||
Not Done Inline ActionsYou can drop all of these. Not related to struct ifnet. vmaffione: You can drop all of these. Not related to `struct ifnet`. | |||||
Not Done Inline ActionsPlease drop also the space added at the end of the lines. vmaffione: Please drop also the space added at the end of the lines. | |||||
/* | /* | ||||
* fill the slots for the rx and tx rings. They contain the offset | * fill the slots for the rx and tx rings. They contain the offset | ||||
* between the ring and nifp, so the information is usable in | * between the ring and nifp, so the information is usable in | ||||
* userspace to reach the ring from the nifp. | * userspace to reach the ring from the nifp. | ||||
*/ | */ | ||||
base = netmap_if_offset(nmd, nifp); | base = netmap_if_offset(nmd, nifp); | ||||
for (i = 0; i < n[NR_TX]; i++) { | for (i = 0; i < n[NR_TX]; i++) { | ||||
/* XXX instead of ofs == 0 maybe use the offset of an error | /* XXX instead of ofs == 0 maybe use the offset of an error | ||||
* ring, like we do for buffers? */ | * ring, like we do for buffers? */ | ||||
ssize_t ofs = 0; | ssize_t ofs = 0; | ||||
if (na->tx_rings[i]->ring != NULL && i >= priv->np_qfirst[NR_TX] | if (na->tx_rings[i]->ring != NULL && i >= priv->np_qfirst[NR_TX] | ||||
&& i < priv->np_qlast[NR_TX]) { | && i < priv->np_qlast[NR_TX]) { | ||||
ofs = netmap_ring_offset(nmd, | ofs = netmap_ring_offset(nmd, | ||||
na->tx_rings[i]->ring) - base; | na->tx_rings[i]->ring) - base; | ||||
} | } | ||||
*(ssize_t *)(uintptr_t)&nifp->ring_ofs[i] = ofs; | *(ssize_t *)(uintptr_t)&nifp->ring_ofs[i] = ofs; | ||||
Not Done Inline ActionsDrop. vmaffione: Drop. | |||||
} | } | ||||
for (i = 0; i < n[NR_RX]; i++) { | for (i = 0; i < n[NR_RX]; i++) { | ||||
/* XXX instead of ofs == 0 maybe use the offset of an error | /* XXX instead of ofs == 0 maybe use the offset of an error | ||||
* ring, like we do for buffers? */ | * ring, like we do for buffers? */ | ||||
ssize_t ofs = 0; | ssize_t ofs = 0; | ||||
if (na->rx_rings[i]->ring != NULL && i >= priv->np_qfirst[NR_RX] | if (na->rx_rings[i]->ring != NULL && i >= priv->np_qfirst[NR_RX] | ||||
&& i < priv->np_qlast[NR_RX]) { | && i < priv->np_qlast[NR_RX]) { | ||||
ofs = netmap_ring_offset(nmd, | ofs = netmap_ring_offset(nmd, | ||||
na->rx_rings[i]->ring) - base; | na->rx_rings[i]->ring) - base; | ||||
} | } | ||||
*(ssize_t *)(uintptr_t)&nifp->ring_ofs[i+n[NR_TX]] = ofs; | *(ssize_t *)(uintptr_t)&nifp->ring_ofs[i+n[NR_TX]] = ofs; | ||||
} | } | ||||
Not Done Inline ActionsDrop. vmaffione: Drop. | |||||
return (nifp); | return (nifp); | ||||
} | } | ||||
static void | static void | ||||
netmap_mem2_if_delete(struct netmap_mem_d *nmd, | netmap_mem2_if_delete(struct netmap_mem_d *nmd, | ||||
struct netmap_adapter *na, struct netmap_if *nifp) | struct netmap_adapter *na, struct netmap_if *nifp) | ||||
{ | { | ||||
if (nifp == NULL) | if (nifp == NULL) | ||||
/* nothing to do */ | /* nothing to do */ | ||||
return; | return; | ||||
if (nifp->ni_bufs_head) | if (nifp->ni_bufs_head) | ||||
netmap_extra_free(na, nifp->ni_bufs_head); | netmap_extra_free(na, nifp->ni_bufs_head); | ||||
netmap_if_free(nmd, nifp); | netmap_if_free(nmd, nifp); | ||||
Not Done Inline ActionsDrop. vmaffione: Drop. | |||||
} | } | ||||
static void | static void | ||||
netmap_mem2_deref(struct netmap_mem_d *nmd, struct netmap_adapter *na) | netmap_mem2_deref(struct netmap_mem_d *nmd, struct netmap_adapter *na) | ||||
{ | { | ||||
if (netmap_debug & NM_DEBUG_MEM) | if (netmap_debug & NM_DEBUG_MEM) | ||||
nm_prinf("active = %d", nmd->active); | nm_prinf("active = %d", nmd->active); | ||||
▲ Show 20 Lines • Show All 292 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
#endif /* WITH_EXTMEM */ | #endif /* WITH_EXTMEM */ | ||||
#ifdef WITH_PTNETMAP | #ifdef WITH_PTNETMAP | ||||
struct mem_pt_if { | struct mem_pt_if { | ||||
struct mem_pt_if *next; | struct mem_pt_if *next; | ||||
struct ifnet *ifp; | if_t ifp; | ||||
unsigned int nifp_offset; | unsigned int nifp_offset; | ||||
}; | }; | ||||
/* Netmap allocator for ptnetmap guests. */ | /* Netmap allocator for ptnetmap guests. */ | ||||
struct netmap_mem_ptg { | struct netmap_mem_ptg { | ||||
struct netmap_mem_d up; | struct netmap_mem_d up; | ||||
vm_paddr_t nm_paddr; /* physical address in the guest */ | vm_paddr_t nm_paddr; /* physical address in the guest */ | ||||
void *nm_addr; /* virtual address in the guest */ | void *nm_addr; /* virtual address in the guest */ | ||||
struct netmap_lut buf_lut; /* lookup table for BUF pool in the guest */ | struct netmap_lut buf_lut; /* lookup table for BUF pool in the guest */ | ||||
nm_memid_t host_mem_id; /* allocator identifier in the host */ | nm_memid_t host_mem_id; /* allocator identifier in the host */ | ||||
struct ptnetmap_memdev *ptn_dev;/* ptnetmap memdev */ | struct ptnetmap_memdev *ptn_dev;/* ptnetmap memdev */ | ||||
struct mem_pt_if *pt_ifs; /* list of interfaces in passthrough */ | struct mem_pt_if *pt_ifs; /* list of interfaces in passthrough */ | ||||
}; | }; | ||||
/* Link a passthrough interface to a passthrough netmap allocator. */ | /* Link a passthrough interface to a passthrough netmap allocator. */ | ||||
static int | static int | ||||
netmap_mem_pt_guest_ifp_add(struct netmap_mem_d *nmd, struct ifnet *ifp, | netmap_mem_pt_guest_ifp_add(struct netmap_mem_d *nmd, if_t ifp, | ||||
unsigned int nifp_offset) | unsigned int nifp_offset) | ||||
{ | { | ||||
struct netmap_mem_ptg *ptnmd = (struct netmap_mem_ptg *)nmd; | struct netmap_mem_ptg *ptnmd = (struct netmap_mem_ptg *)nmd; | ||||
struct mem_pt_if *ptif = nm_os_malloc(sizeof(*ptif)); | struct mem_pt_if *ptif = nm_os_malloc(sizeof(*ptif)); | ||||
if (!ptif) { | if (!ptif) { | ||||
return ENOMEM; | return ENOMEM; | ||||
} | } | ||||
NMA_LOCK(nmd); | NMA_LOCK(nmd); | ||||
ptif->ifp = ifp; | ptif->ifp = ifp; | ||||
ptif->nifp_offset = nifp_offset; | ptif->nifp_offset = nifp_offset; | ||||
if (ptnmd->pt_ifs) { | if (ptnmd->pt_ifs) { | ||||
ptif->next = ptnmd->pt_ifs; | ptif->next = ptnmd->pt_ifs; | ||||
} | } | ||||
ptnmd->pt_ifs = ptif; | ptnmd->pt_ifs = ptif; | ||||
NMA_UNLOCK(nmd); | NMA_UNLOCK(nmd); | ||||
nm_prinf("ifp=%s,nifp_offset=%u", | nm_prinf("ifp=%s,nifp_offset=%u", | ||||
ptif->ifp->if_xname, ptif->nifp_offset); | if_name(ptif->ifp), ptif->nifp_offset); | ||||
Done Inline ActionsThis should be if_name(ptif->ifp) vmaffione: This should be `if_name(ptif->ifp)` | |||||
return 0; | return 0; | ||||
} | } | ||||
/* Called with NMA_LOCK(nmd) held. */ | /* Called with NMA_LOCK(nmd) held. */ | ||||
static struct mem_pt_if * | static struct mem_pt_if * | ||||
netmap_mem_pt_guest_ifp_lookup(struct netmap_mem_d *nmd, struct ifnet *ifp) | netmap_mem_pt_guest_ifp_lookup(struct netmap_mem_d *nmd, if_t ifp) | ||||
{ | { | ||||
struct netmap_mem_ptg *ptnmd = (struct netmap_mem_ptg *)nmd; | struct netmap_mem_ptg *ptnmd = (struct netmap_mem_ptg *)nmd; | ||||
struct mem_pt_if *curr; | struct mem_pt_if *curr; | ||||
for (curr = ptnmd->pt_ifs; curr; curr = curr->next) { | for (curr = ptnmd->pt_ifs; curr; curr = curr->next) { | ||||
if (curr->ifp == ifp) { | if (curr->ifp == ifp) { | ||||
return curr; | return curr; | ||||
} | } | ||||
} | } | ||||
return NULL; | return NULL; | ||||
} | } | ||||
/* Unlink a passthrough interface from a passthrough netmap allocator. */ | /* Unlink a passthrough interface from a passthrough netmap allocator. */ | ||||
int | int | ||||
netmap_mem_pt_guest_ifp_del(struct netmap_mem_d *nmd, struct ifnet *ifp) | netmap_mem_pt_guest_ifp_del(struct netmap_mem_d *nmd, if_t ifp) | ||||
{ | { | ||||
struct netmap_mem_ptg *ptnmd = (struct netmap_mem_ptg *)nmd; | struct netmap_mem_ptg *ptnmd = (struct netmap_mem_ptg *)nmd; | ||||
struct mem_pt_if *prev = NULL; | struct mem_pt_if *prev = NULL; | ||||
struct mem_pt_if *curr; | struct mem_pt_if *curr; | ||||
int ret = -1; | int ret = -1; | ||||
NMA_LOCK(nmd); | NMA_LOCK(nmd); | ||||
for (curr = ptnmd->pt_ifs; curr; curr = curr->next) { | for (curr = ptnmd->pt_ifs; curr; curr = curr->next) { | ||||
if (curr->ifp == ifp) { | if (curr->ifp == ifp) { | ||||
if (prev) { | if (prev) { | ||||
prev->next = curr->next; | prev->next = curr->next; | ||||
} else { | } else { | ||||
ptnmd->pt_ifs = curr->next; | ptnmd->pt_ifs = curr->next; | ||||
} | } | ||||
nm_prinf("removed (ifp=%s,nifp_offset=%u)", | nm_prinf("removed (ifp=%s,nifp_offset=%u)", | ||||
curr->ifp->if_xname, curr->nifp_offset); | if_name(curr->ifp), curr->nifp_offset); | ||||
Done Inline ActionsThis should be if_name(curr->ifp) vmaffione: This should be `if_name(curr->ifp)` | |||||
nm_os_free(curr); | nm_os_free(curr); | ||||
ret = 0; | ret = 0; | ||||
break; | break; | ||||
} | } | ||||
prev = curr; | prev = curr; | ||||
} | } | ||||
NMA_UNLOCK(nmd); | NMA_UNLOCK(nmd); | ||||
▲ Show 20 Lines • Show All 219 Lines • ▼ Show 20 Lines | netmap_mem_pt_guest_rings_create(struct netmap_mem_d *nmd, | ||||
/* point each kring to the corresponding backend ring */ | /* point each kring to the corresponding backend ring */ | ||||
nifp = (struct netmap_if *)((char *)ptnmd->nm_addr + ptif->nifp_offset); | nifp = (struct netmap_if *)((char *)ptnmd->nm_addr + ptif->nifp_offset); | ||||
for (i = 0; i < netmap_all_rings(na, NR_TX); i++) { | for (i = 0; i < netmap_all_rings(na, NR_TX); i++) { | ||||
struct netmap_kring *kring = na->tx_rings[i]; | struct netmap_kring *kring = na->tx_rings[i]; | ||||
if (kring->ring) | if (kring->ring) | ||||
continue; | continue; | ||||
kring->ring = (struct netmap_ring *) | kring->ring = (struct netmap_ring *) | ||||
((char *)nifp + nifp->ring_ofs[i]); | ((char *)nifp + nifp->ring_ofs[i]); | ||||
Not Done Inline ActionsDrop vmaffione: Drop | |||||
} | } | ||||
for (i = 0; i < netmap_all_rings(na, NR_RX); i++) { | for (i = 0; i < netmap_all_rings(na, NR_RX); i++) { | ||||
struct netmap_kring *kring = na->rx_rings[i]; | struct netmap_kring *kring = na->rx_rings[i]; | ||||
if (kring->ring) | if (kring->ring) | ||||
continue; | continue; | ||||
kring->ring = (struct netmap_ring *) | kring->ring = (struct netmap_ring *) | ||||
((char *)nifp + | ((char *)nifp + | ||||
nifp->ring_ofs[netmap_all_rings(na, NR_TX) + i]); | nifp->ring_ofs[netmap_all_rings(na, NR_TX) + i]); | ||||
Not Done Inline ActionsDrop vmaffione: Drop | |||||
} | } | ||||
error = 0; | error = 0; | ||||
out: | out: | ||||
return error; | return error; | ||||
} | } | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | if (nmd) { | ||||
ptnmd->ptn_dev = ptn_dev; | ptnmd->ptn_dev = ptn_dev; | ||||
} | } | ||||
return nmd; | return nmd; | ||||
} | } | ||||
/* Called when ptnet device is attaching */ | /* Called when ptnet device is attaching */ | ||||
struct netmap_mem_d * | struct netmap_mem_d * | ||||
netmap_mem_pt_guest_new(struct ifnet *ifp, | netmap_mem_pt_guest_new(if_t ifp, | ||||
unsigned int nifp_offset, | unsigned int nifp_offset, | ||||
unsigned int memid) | unsigned int memid) | ||||
{ | { | ||||
struct netmap_mem_d *nmd; | struct netmap_mem_d *nmd; | ||||
if (ifp == NULL) { | if (ifp == NULL) { | ||||
return NULL; | return NULL; | ||||
} | } | ||||
Show All 11 Lines |
Drop spaces at the end of the lines.