aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/xen/netfront
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2015-02-19 01:19:42 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2015-02-19 01:19:42 +0000
commitc578b6aca0e35a3617f85b3e7cf84f33e5bf5bb2 (patch)
tree58c4847d6216a3ece2c63355dd9c2b2f9a3f766a /sys/dev/xen/netfront
parent8935302fe167277900973fd15a9f878fd81e6832 (diff)
downloadsrc-c578b6aca0e35a3617f85b3e7cf84f33e5bf5bb2.tar.gz
src-c578b6aca0e35a3617f85b3e7cf84f33e5bf5bb2.zip
Provide a set of inline functions to manage simple mbuf(9) queues, based
on queue(3)'s STAILQ. Utilize them in cxgb(4) and Xen, deleting home grown implementations. Sponsored by: Netflix Sponsored by: Nginx, Inc.
Notes
Notes: svn path=/head/; revision=278977
Diffstat (limited to 'sys/dev/xen/netfront')
-rw-r--r--sys/dev/xen/netfront/mbufq.h123
-rw-r--r--sys/dev/xen/netfront/netfront.c21
2 files changed, 10 insertions, 134 deletions
diff --git a/sys/dev/xen/netfront/mbufq.h b/sys/dev/xen/netfront/mbufq.h
deleted file mode 100644
index 0d6c60430ae6..000000000000
--- a/sys/dev/xen/netfront/mbufq.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/**************************************************************************
-
-Copyright (c) 2007, Chelsio Inc.
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Neither the name of the Chelsio Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
-$FreeBSD$
-
-***************************************************************************/
-
-#ifndef CXGB_MBUFQ_H_
-#define CXGB_MBUFQ_H_
-
-struct mbuf_head {
- struct mbuf *head;
- struct mbuf *tail;
- uint32_t qlen;
- uint32_t qsize;
- struct mtx lock;
-};
-
-static __inline void
-mbufq_init(struct mbuf_head *l)
-{
- l->head = l->tail = NULL;
- l->qlen = l->qsize = 0;
-}
-
-static __inline int
-mbufq_empty(struct mbuf_head *l)
-{
- return (l->head == NULL);
-}
-
-static __inline int
-mbufq_len(struct mbuf_head *l)
-{
- return (l->qlen);
-}
-
-static __inline int
-mbufq_size(struct mbuf_head *l)
-{
- return (l->qsize);
-}
-
-static __inline int
-mbufq_head_size(struct mbuf_head *l)
-{
- return (l->head ? l->head->m_pkthdr.len : 0);
-}
-
-static __inline void
-mbufq_tail(struct mbuf_head *l, struct mbuf *m)
-{
- l->qlen++;
- if (l->head == NULL)
- l->head = m;
- else
- l->tail->m_nextpkt = m;
- l->tail = m;
- l->qsize += m->m_pkthdr.len;
-}
-
-static __inline struct mbuf *
-mbufq_dequeue(struct mbuf_head *l)
-{
- struct mbuf *m;
-
- m = l->head;
- if (m) {
- if (m == l->tail)
- l->head = l->tail = NULL;
- else
- l->head = m->m_nextpkt;
- m->m_nextpkt = NULL;
- l->qlen--;
- l->qsize -= m->m_pkthdr.len;
- }
-
- return (m);
-}
-
-static __inline struct mbuf *
-mbufq_peek(struct mbuf_head *l)
-{
- return (l->head);
-}
-
-static __inline void
-mbufq_append(struct mbuf_head *a, struct mbuf_head *b)
-{
- if (a->tail)
- a->tail->m_nextpkt = b->head;
- if (b->tail)
- a->tail = b->tail;
- a->qlen += b->qlen;
- a->qsize += b->qsize;
-
-
-}
-#endif /* CXGB_MBUFQ_H_ */
diff --git a/sys/dev/xen/netfront/netfront.c b/sys/dev/xen/netfront/netfront.c
index 8f401ac1ad96..b97af6239ce3 100644
--- a/sys/dev/xen/netfront/netfront.c
+++ b/sys/dev/xen/netfront/netfront.c
@@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/sockio.h>
+#include <sys/limits.h>
#include <sys/mbuf.h>
#include <sys/malloc.h>
#include <sys/module.h>
@@ -87,8 +88,6 @@ __FBSDID("$FreeBSD$");
#include <machine/xen/xenvar.h>
-#include <dev/xen/netfront/mbufq.h>
-
#include "xenbus_if.h"
/* Features supported by all backends. TSO and LRO can be negotiated */
@@ -277,7 +276,7 @@ struct netfront_info {
int rx_ring_ref;
uint8_t mac[ETHER_ADDR_LEN];
struct xn_chain_data xn_cdata; /* mbufs */
- struct mbuf_head xn_rx_batch; /* head of the batch queue */
+ struct mbufq xn_rx_batch; /* batch queue */
int xn_if_flags;
struct callout xn_stat_ch;
@@ -837,7 +836,7 @@ no_mbuf:
m_new->m_len = m_new->m_pkthdr.len = MJUMPAGESIZE;
/* queue the mbufs allocated */
- mbufq_tail(&sc->xn_rx_batch, m_new);
+ (void )mbufq_enqueue(&sc->xn_rx_batch, m_new);
}
/*
@@ -973,7 +972,7 @@ xn_rxeof(struct netfront_info *np)
RING_IDX i, rp;
multicall_entry_t *mcl;
struct mbuf *m;
- struct mbuf_head rxq, errq;
+ struct mbufq rxq, errq;
int err, pages_flipped = 0, work_to_do;
do {
@@ -981,8 +980,9 @@ xn_rxeof(struct netfront_info *np)
if (!netfront_carrier_ok(np))
return;
- mbufq_init(&errq);
- mbufq_init(&rxq);
+ /* XXX: there should be some sane limit. */
+ mbufq_init(&errq, INT_MAX);
+ mbufq_init(&rxq, INT_MAX);
ifp = np->xn_ifp;
@@ -1000,7 +1000,7 @@ xn_rxeof(struct netfront_info *np)
if (__predict_false(err)) {
if (m)
- mbufq_tail(&errq, m);
+ (void )mbufq_enqueue(&errq, m);
np->stats.rx_errors++;
continue;
}
@@ -1022,7 +1022,7 @@ xn_rxeof(struct netfront_info *np)
np->stats.rx_packets++;
np->stats.rx_bytes += m->m_pkthdr.len;
- mbufq_tail(&rxq, m);
+ (void )mbufq_enqueue(&rxq, m);
np->rx.rsp_cons = i;
}
@@ -1046,8 +1046,7 @@ xn_rxeof(struct netfront_info *np)
}
}
- while ((m = mbufq_dequeue(&errq)))
- m_freem(m);
+ mbufq_drain(&errq);
/*
* Process all the mbufs after the remapping is complete.