1/************************************************************************** 2 3Copyright (c) 2007, Chelsio Inc. 4All rights reserved. 5 6Redistribution and use in source and binary forms, with or without 7modification, are permitted provided that the following conditions are met: 8 9 1. Redistributions of source code must retain the above copyright notice, 10 this list of conditions and the following disclaimer. 11 12 2. Neither the name of the Chelsio Corporation nor the names of its 13 contributors may be used to endorse or promote products derived from 14 this software without specific prior written permission. 15 16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26POSSIBILITY OF SUCH DAMAGE. 27 28$FreeBSD$ 29 30***************************************************************************/ 31 32#ifndef CXGB_MBUFQ_H_ 33#define CXGB_MBUFQ_H_ 34 35struct mbuf_head { 36 struct mbuf *head; 37 struct mbuf *tail; 38 uint32_t qlen; 39 uint32_t qsize; 40 struct mtx lock; 41}; 42 43static __inline void 44mbufq_init(struct mbuf_head *l) 45{ 46 l->head = l->tail = NULL; 47 l->qlen = l->qsize = 0; 48} 49 50static __inline int 51mbufq_empty(struct mbuf_head *l) 52{ 53 return (l->head == NULL); 54} 55 56static __inline int 57mbufq_len(struct mbuf_head *l) 58{ 59 return (l->qlen); 60} 61 62static __inline int 63mbufq_size(struct mbuf_head *l) 64{ 65 return (l->qsize); 66} 67 68static __inline int 69mbufq_head_size(struct mbuf_head *l) 70{ 71 return (l->head ? l->head->m_pkthdr.len : 0); 72} 73 74static __inline void 75mbufq_tail(struct mbuf_head *l, struct mbuf *m) 76{ 77 l->qlen++; 78 if (l->head == NULL) 79 l->head = m; 80 else 81 l->tail->m_nextpkt = m; 82 l->tail = m; 83 l->qsize += m->m_pkthdr.len; 84} 85 86static __inline struct mbuf * 87mbufq_dequeue(struct mbuf_head *l) 88{ 89 struct mbuf *m; 90 91 m = l->head; 92 if (m) { 93 if (m == l->tail) 94 l->head = l->tail = NULL; 95 else 96 l->head = m->m_nextpkt; 97 m->m_nextpkt = NULL; 98 l->qlen--; 99 l->qsize -= m->m_pkthdr.len; 100 } 101 102 return (m); 103} 104 105static __inline struct mbuf * 106mbufq_peek(struct mbuf_head *l) 107{ 108 return (l->head); 109} 110 111static __inline void 112mbufq_append(struct mbuf_head *a, struct mbuf_head *b) 113{ 114 if (a->tail) 115 a->tail->m_nextpkt = b->head; 116 if (b->tail) 117 a->tail = b->tail; 118 a->qlen += b->qlen; 119 a->qsize += b->qsize; 120 121 122} 123#endif /* CXGB_MBUFQ_H_ */ 124