Skip to content

Commit

Permalink
Merge remote-tracking branch 'gitlab/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppelettieri committed Dec 16, 2015
2 parents 676ac34 + 1bff216 commit 6c5f7f6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 81 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ LINUX/netmap-tmp.c
LINUX/i40e
LINUX/failed-patches
examples/bridge
examples/bridge-b
examples/pkt-gen
examples/pkt-gen-b
examples/test_select
Expand Down
2 changes: 1 addition & 1 deletion LINUX/i40e_netmap_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extern int ix_rx_miss, ix_rx_miss_bufs, ix_crcstrip;
SYSCTL_DECL(_dev_netmap);
int ix_rx_miss, ix_rx_miss_bufs, ix_crcstrip;
SYSCTL_INT(_dev_netmap, OID_AUTO, ix_crcstrip,
CTLFLAG_RW, &ix_crcstrip, 0, "strip CRC on rx frames");
CTLFLAG_RW, &ix_crcstrip, 1, "strip CRC on rx frames");
SYSCTL_INT(_dev_netmap, OID_AUTO, ix_rx_miss,
CTLFLAG_RW, &ix_rx_miss, 0, "potentially missed rx intr");
SYSCTL_INT(_dev_netmap, OID_AUTO, ix_rx_miss_bufs,
Expand Down
122 changes: 46 additions & 76 deletions sys/dev/netmap/netmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,20 @@ netmap_unget_na(struct netmap_adapter *na, struct ifnet *ifp)
}


#define NM_FAIL_ON(t) do { \
if (unlikely(t)) { \
RD(5, "%s: fail '" #t "' " \
"h %d c %d t %d " \
"rh %d rc %d rt %d " \
"hc %d ht %d", \
kring->name, \
head, cur, ring->tail, \
kring->rhead, kring->rcur, kring->rtail, \
kring->nr_hwcur, kring->nr_hwtail); \
return kring->nkr_num_slots; \
} \
} while (0)

/*
* validate parameters on entry for *_txsync()
* Returns ring->cur if ok, or something >= kring->nkr_num_slots
Expand All @@ -1507,7 +1521,6 @@ netmap_unget_na(struct netmap_adapter *na, struct ifnet *ifp)
u_int
nm_txsync_prologue(struct netmap_kring *kring, struct netmap_ring *ring)
{
#define NM_ASSERT(t) if (t) { D("fail " #t); goto error; }
u_int head = ring->head; /* read only once */
u_int cur = ring->cur; /* read only once */
u_int n = kring->nkr_num_slots;
Expand All @@ -1517,35 +1530,34 @@ nm_txsync_prologue(struct netmap_kring *kring, struct netmap_ring *ring)
kring->nr_hwcur, kring->nr_hwtail,
ring->head, ring->cur, ring->tail);
#if 1 /* kernel sanity checks; but we can trust the kring. */
if (kring->nr_hwcur >= n || kring->rhead >= n ||
kring->rtail >= n || kring->nr_hwtail >= n)
goto error;
NM_FAIL_ON(kring->nr_hwcur >= n || kring->rhead >= n ||
kring->rtail >= n || kring->nr_hwtail >= n);
#endif /* kernel sanity checks */
/*
* user sanity checks. We only use 'cur',
* A, B, ... are possible positions for cur:
* user sanity checks. We only use head,
* A, B, ... are possible positions for head:
*
* 0 A cur B tail C n-1
* 0 D tail E cur F n-1
* 0 A rhead B rtail C n-1
* 0 D rtail E rhead F n-1
*
* B, F, D are valid. A, C, E are wrong
*/
if (kring->rtail >= kring->rhead) {
/* want rhead <= head <= rtail */
NM_ASSERT(head < kring->rhead || head > kring->rtail);
NM_FAIL_ON(head < kring->rhead || head > kring->rtail);
/* and also head <= cur <= rtail */
NM_ASSERT(cur < head || cur > kring->rtail);
NM_FAIL_ON(cur < head || cur > kring->rtail);
} else { /* here rtail < rhead */
/* we need head outside rtail .. rhead */
NM_ASSERT(head > kring->rtail && head < kring->rhead);
NM_FAIL_ON(head > kring->rtail && head < kring->rhead);

/* two cases now: head <= rtail or head >= rhead */
if (head <= kring->rtail) {
/* want head <= cur <= rtail */
NM_ASSERT(cur < head || cur > kring->rtail);
NM_FAIL_ON(cur < head || cur > kring->rtail);
} else { /* head >= rhead */
/* cur must be outside rtail..head */
NM_ASSERT(cur > kring->rtail && cur < head);
NM_FAIL_ON(cur > kring->rtail && cur < head);
}
}
if (ring->tail != kring->rtail) {
Expand All @@ -1556,15 +1568,6 @@ nm_txsync_prologue(struct netmap_kring *kring, struct netmap_ring *ring)
kring->rhead = head;
kring->rcur = cur;
return head;

error:
RD(5, "%s kring error: head %d cur %d tail %d rhead %d rcur %d rtail %d hwcur %d hwtail %d",
kring->name,
head, cur, ring->tail,
kring->rhead, kring->rcur, kring->rtail,
kring->nr_hwcur, kring->nr_hwtail);
return n;
#undef NM_ASSERT
}


Expand Down Expand Up @@ -1599,30 +1602,24 @@ nm_rxsync_prologue(struct netmap_kring *kring, struct netmap_ring *ring)
cur = kring->rcur = ring->cur; /* read only once */
head = kring->rhead = ring->head; /* read only once */
#if 1 /* kernel sanity checks */
if (kring->nr_hwcur >= n || kring->nr_hwtail >= n)
goto error;
NM_FAIL_ON(kring->nr_hwcur >= n || kring->nr_hwtail >= n);
#endif /* kernel sanity checks */
/* user sanity checks */
if (kring->nr_hwtail >= kring->nr_hwcur) {
/* want hwcur <= rhead <= hwtail */
if (head < kring->nr_hwcur || head > kring->nr_hwtail)
goto error;
NM_FAIL_ON(head < kring->nr_hwcur || head > kring->nr_hwtail);
/* and also rhead <= rcur <= hwtail */
if (cur < head || cur > kring->nr_hwtail)
goto error;
NM_FAIL_ON(cur < head || cur > kring->nr_hwtail);
} else {
/* we need rhead outside hwtail..hwcur */
if (head < kring->nr_hwcur && head > kring->nr_hwtail)
goto error;
NM_FAIL_ON(head < kring->nr_hwcur && head > kring->nr_hwtail);
/* two cases now: head <= hwtail or head >= hwcur */
if (head <= kring->nr_hwtail) {
/* want head <= cur <= hwtail */
if (cur < head || cur > kring->nr_hwtail)
goto error;
NM_FAIL_ON(cur < head || cur > kring->nr_hwtail);
} else {
/* cur must be outside hwtail..head */
if (cur < head && cur > kring->nr_hwtail)
goto error;
NM_FAIL_ON(cur < head && cur > kring->nr_hwtail);
}
}
if (ring->tail != kring->rtail) {
Expand All @@ -1632,16 +1629,8 @@ nm_rxsync_prologue(struct netmap_kring *kring, struct netmap_ring *ring)
ring->tail = kring->rtail;
}
return head;

error:
RD(5, "kring error: hwcur %d rcur %d hwtail %d head %d cur %d tail %d",
kring->nr_hwcur,
kring->rcur, kring->nr_hwtail,
kring->rhead, kring->rcur, ring->tail);
return n;
}


/*
* Error routine called when txsync/rxsync detects an error.
* Can't do much more than resetting head =cur = hwcur, tail = hwtail
Expand Down Expand Up @@ -1976,9 +1965,8 @@ netmap_rel_exclusive(struct netmap_priv_d *priv)
* (put the adapter in netmap mode)
*
* This may be one of the following:
* (XXX these should be either all *_register or all *_reg 2014-03-15)
*
* * netmap_hw_register (hw ports)
* * netmap_hw_reg (hw ports)
* checks that the ifp is still there, then calls
* the hardware specific callback;
*
Expand All @@ -1996,7 +1984,7 @@ netmap_rel_exclusive(struct netmap_priv_d *priv)
* intercept the sync callbacks of the monitored
* rings
*
* * netmap_bwrap_register (bwraps)
* * netmap_bwrap_reg (bwraps)
* cross-link the bwrap and hwna rings,
* forward the request to the hwna, override
* the hwna notify callback (to get the frames
Expand Down Expand Up @@ -2120,42 +2108,24 @@ netmap_do_regif(struct netmap_priv_d *priv, struct netmap_adapter *na,
return error;
}


/*
* update kring and ring at the end of txsync.
* update kring and ring at the end of rxsync/txsync.
*/
static inline void
nm_txsync_finalize(struct netmap_kring *kring)
nm_sync_finalize(struct netmap_kring *kring)
{
/* update ring tail to what the kernel knows */
/*
* Update ring tail to what the kernel knows
* After txsync: head/rhead/hwcur might be behind cur/rcur
* if no carrier.
*/
kring->ring->tail = kring->rtail = kring->nr_hwtail;

/* note, head/rhead/hwcur might be behind cur/rcur
* if no carrier
*/
ND(5, "%s now hwcur %d hwtail %d head %d cur %d tail %d",
kring->name, kring->nr_hwcur, kring->nr_hwtail,
kring->rhead, kring->rcur, kring->rtail);
}


/*
* update kring and ring at the end of rxsync
*/
static inline void
nm_rxsync_finalize(struct netmap_kring *kring)
{
/* tell userspace that there might be new packets */
//struct netmap_ring *ring = kring->ring;
ND("head %d cur %d tail %d -> %d", ring->head, ring->cur, ring->tail,
kring->nr_hwtail);
kring->ring->tail = kring->rtail = kring->nr_hwtail;
/* make a copy of the state for next round */
kring->rhead = kring->ring->head;
kring->rcur = kring->ring->cur;
}


/*
* ioctl(2) support for the "netmap" device.
*
Expand Down Expand Up @@ -2360,7 +2330,7 @@ netmap_ioctl(struct netmap_priv_d *priv, u_long cmd, caddr_t data, struct thread
if (nm_txsync_prologue(kring, ring) >= kring->nkr_num_slots) {
netmap_ring_reinit(kring);
} else if (kring->nm_sync(kring, NAF_FORCE_RECLAIM) == 0) {
nm_txsync_finalize(kring);
nm_sync_finalize(kring);
}
if (netmap_verbose & NM_VERB_TXSYNC)
D("post txsync ring %d cur %d hwcur %d",
Expand All @@ -2370,7 +2340,7 @@ netmap_ioctl(struct netmap_priv_d *priv, u_long cmd, caddr_t data, struct thread
if (nm_rxsync_prologue(kring, ring) >= kring->nkr_num_slots) {
netmap_ring_reinit(kring);
} else if (kring->nm_sync(kring, NAF_FORCE_READ) == 0) {
nm_rxsync_finalize(kring);
nm_sync_finalize(kring);
}
microtime(&ring->ts);
}
Expand Down Expand Up @@ -2546,7 +2516,7 @@ netmap_poll(struct netmap_priv_d *priv, int events, NM_SELRECORD_T *sr)
if (kring->nm_sync(kring, 0))
revents |= POLLERR;
else
nm_txsync_finalize(kring);
nm_sync_finalize(kring);
}

/*
Expand Down Expand Up @@ -2609,7 +2579,7 @@ netmap_poll(struct netmap_priv_d *priv, int events, NM_SELRECORD_T *sr)
if (kring->nm_sync(kring, 0))
revents |= POLLERR;
else
nm_rxsync_finalize(kring);
nm_sync_finalize(kring);
send_down |= (kring->nr_kflags & NR_FORWARD); /* host ring only */
if (netmap_no_timestamp == 0 ||
ring->flags & NR_TIMESTAMP) {
Expand Down Expand Up @@ -2763,7 +2733,7 @@ netmap_detach_common(struct netmap_adapter *na)
* module unloading.
*/
static int
netmap_hw_register(struct netmap_adapter *na, int onoff)
netmap_hw_reg(struct netmap_adapter *na, int onoff)
{
struct netmap_hw_adapter *hwna =
(struct netmap_hw_adapter*)na;
Expand Down Expand Up @@ -2824,7 +2794,7 @@ _netmap_attach(struct netmap_adapter *arg, size_t size)
hwna->up.na_flags |= NAF_HOST_RINGS | NAF_NATIVE;
strncpy(hwna->up.name, ifp->if_xname, sizeof(hwna->up.name));
hwna->nm_hw_register = hwna->up.nm_register;
hwna->up.nm_register = netmap_hw_register;
hwna->up.nm_register = netmap_hw_reg;
if (netmap_attach_common(&hwna->up)) {
free(hwna, M_DEVBUF);
goto fail;
Expand Down
8 changes: 4 additions & 4 deletions sys/dev/netmap/netmap_vale.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ SYSEND;

static int netmap_vp_create(struct nmreq *, struct ifnet *, struct netmap_vp_adapter **);
static int netmap_vp_reg(struct netmap_adapter *na, int onoff);
static int netmap_bwrap_register(struct netmap_adapter *, int onoff);
static int netmap_bwrap_reg(struct netmap_adapter *, int onoff);

/*
* For each output interface, nm_bdg_q is used to construct a list.
Expand Down Expand Up @@ -776,7 +776,7 @@ nm_bdg_ctl_attach(struct nmreq *nmr)
static inline int
nm_is_bwrap(struct netmap_adapter *na)
{
return na->nm_register == netmap_bwrap_register;
return na->nm_register == netmap_bwrap_reg;
}

/* process NETMAP_BDG_DETACH */
Expand Down Expand Up @@ -2271,7 +2271,7 @@ netmap_bwrap_intr_notify(struct netmap_kring *kring, int flags)

/* nm_register callback for bwrap */
static int
netmap_bwrap_register(struct netmap_adapter *na, int onoff)
netmap_bwrap_reg(struct netmap_adapter *na, int onoff)
{
struct netmap_bwrap_adapter *bna =
(struct netmap_bwrap_adapter *)na;
Expand Down Expand Up @@ -2570,7 +2570,7 @@ netmap_bwrap_attach(const char *nr_name, struct netmap_adapter *hwna)
nma_set_ndesc(na, t, nma_get_ndesc(hwna, r));
}
na->nm_dtor = netmap_bwrap_dtor;
na->nm_register = netmap_bwrap_register;
na->nm_register = netmap_bwrap_reg;
// na->nm_txsync = netmap_bwrap_txsync;
// na->nm_rxsync = netmap_bwrap_rxsync;
na->nm_config = netmap_bwrap_config;
Expand Down

0 comments on commit 6c5f7f6

Please sign in to comment.