From 1635d9171ccfca38509b37f70bb498bb62b603db Mon Sep 17 00:00:00 2001 From: Kip Macy Date: Wed, 17 Dec 2008 04:00:43 +0000 Subject: [PATCH] merge in 2 buf_ring helper routines for enqueueing and freeing buf_rings --- sys/net/if_var.h | 27 +++++++++++++++++++++++++++ sys/sys/buf_ring.h | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/sys/net/if_var.h b/sys/net/if_var.h index 7b2881ea03fd..6e6d2db08b8a 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -77,6 +77,7 @@ struct ifvlantrunk; #ifdef _KERNEL #include #include +#include #endif /* _KERNEL */ #include /* XXX */ #include /* XXX */ @@ -548,6 +549,32 @@ do { \ IFQ_PURGE(ifq); \ } while (0) +#ifdef _KERNEL +static __inline int +drbr_enqueue(struct buf_ring *br, struct mbuf *m) +{ + int error = 0; + + if ((error = buf_ring_enqueue(br, m)) == ENOBUFS) { + br->br_drops++; + m_freem(m); + } + + return (error); +} + +static __inline void +drbr_free(struct buf_ring *br, struct malloc_type *type) +{ + struct mbuf *m; + + while ((m = buf_ring_dequeue_sc(br)) != NULL) + m_freem(m); + + buf_ring_free(br, type); +} +#endif + /* * 72 was chosen below because it is the size of a TCP/IP * header (40) + the minimum mss (32). diff --git a/sys/sys/buf_ring.h b/sys/sys/buf_ring.h index 6d0cb7d542e2..efea85aa6f0b 100644 --- a/sys/sys/buf_ring.h +++ b/sys/sys/buf_ring.h @@ -48,10 +48,11 @@ struct buf_ring { volatile uint32_t br_prod_tail; int br_prod_size; int br_prod_mask; + uint64_t br_drops; /* * Pad out to next L2 cache line */ - uint64_t _pad0[14]; + uint64_t _pad0[13]; volatile uint32_t br_cons_head; volatile uint32_t br_cons_tail;