Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reg range support #381

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions sys/dev/netmap/netmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,21 @@ netmap_interp_ringid(struct netmap_priv_d *priv, uint16_t ringid, uint32_t flags
ND("ONE_NIC: %s %d %d", nm_txrx2str(t),
priv->np_qfirst[t], priv->np_qlast[t]);
break;
case NR_REG_RANGE_NIC:
if (i >= nma_get_nrings(na, t)) {
D("invalid ring id %d", i);
return EINVAL;
}
j = (flags & NR_RANGE_END_MASK) >> NR_RANGE_END_SHIFT;
if (j >= nma_get_nrings(na, t)) {
D("invalid range end %d", j);
return EINVAL;
}
priv->np_qfirst[t] = i;
priv->np_qlast[t] = j + 1;
ND("RANGE_NIC: %s %d %d", nm_txrx2str(t),
priv->np_qfirst[t], priv->np_qlast[t]);
break;
default:
D("invalid regif type %d", reg);
return EINVAL;
Expand Down
4 changes: 4 additions & 0 deletions sys/net/netmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ enum { NR_REG_DEFAULT = 0, /* backward compat, should not be used. */
NR_REG_ONE_NIC = 4,
NR_REG_PIPE_MASTER = 5,
NR_REG_PIPE_SLAVE = 6,
NR_REG_RANGE_NIC = 7,
};
/* monitor uses the NR_REG to select the rings to monitor */
#define NR_MONITOR_TX 0x100
Expand All @@ -563,6 +564,9 @@ enum { NR_REG_DEFAULT = 0, /* backward compat, should not be used. */
* NETMAP_VNET_HDR_GET command to figure out the header length. */
#define NR_ACCEPT_VNET_HDR 0x8000

#define NR_RANGE_END_MASK 0xfff00000u /* values for range end parameter */
#define NR_RANGE_END_SHIFT __builtin_ctz(NR_RANGE_END_MASK) /* how much to shr to get the range end number */

#define NM_BDG_NAME "vale" /* prefix for bridge port name */

#ifdef _WIN32
Expand Down
19 changes: 18 additions & 1 deletion sys/net/netmap_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,14 @@ nm_parse(const char *ifname, struct nm_desc *d, char *err)
break;
case P_RNGSFXOK:
switch (*port) {
case '-':
if ((nr_flags & NR_REG_MASK) != NR_REG_ONE_NIC) {
snprintf(errmsg, MAXERRMSG, "invalid range specified");
goto fail;
}
nr_flags |= NR_REG_RANGE_NIC & NR_REG_MASK;
p_state = P_GETNUM;
break;
case '/':
p_state = P_FLAGS;
break;
Expand All @@ -723,7 +731,12 @@ nm_parse(const char *ifname, struct nm_desc *d, char *err)
num, NETMAP_RING_MASK);
goto fail;
}
nr_ringid = num & NETMAP_RING_MASK;
if ((nr_ringid & NETMAP_RING_MASK) == 0) {
nr_ringid = num & NETMAP_RING_MASK;
} else {
nr_flags &= ~NR_RANGE_END_MASK;
nr_flags |= (num << NR_RANGE_END_SHIFT) & NR_RANGE_END_MASK;
}
p_state = P_RNGSFXOK;
break;
case P_FLAGS:
Expand Down Expand Up @@ -908,6 +921,10 @@ nm_open(const char *ifname, const struct nmreq *req,
/* XXX check validity */
d->first_tx_ring = d->last_tx_ring =
d->first_rx_ring = d->last_rx_ring = d->req.nr_ringid & NETMAP_RING_MASK;
} else if (nr_reg == NR_REG_RANGE_NIC) {
/* XXX check validity */
d->first_tx_ring = d->first_rx_ring = d->req.nr_ringid & NETMAP_RING_MASK;
d->last_tx_ring = d->last_rx_ring = (d->req.nr_flags & NR_RANGE_END_MASK) >> NR_RANGE_END_SHIFT;
} else { /* pipes */
d->first_tx_ring = d->last_tx_ring = 0;
d->first_rx_ring = d->last_rx_ring = 0;
Expand Down