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***************************************************************************/
29
30#ifndef CXGB_MBUFQ_H_
31#define CXGB_MBUFQ_H_
32
33#include <sys/mbuf.h>
34
35struct mbuf_head {
36    struct mbuf *head;
37    struct mbuf *tail;
38    uint32_t     qlen;
39    struct mtx   lock;
40};
41
42static __inline void
43mbufq_init(struct mbuf_head *l)
44{
45    l->head = l->tail = NULL;
46}
47
48static __inline int
49mbufq_empty(struct mbuf_head *l)
50{
51    return (l->head == NULL);
52}
53
54static __inline int
55mbufq_len(struct mbuf_head *l)
56{
57    return (l->qlen);
58}
59
60
61static __inline void
62mbufq_tail(struct mbuf_head *l, struct mbuf *m)
63{
64    l->qlen++;
65    l->tail->m_nextpkt = m;
66    l->tail = m;
67}
68
69static __inline struct mbuf *
70mbufq_dequeue(struct mbuf_head *l)
71{
72    struct mbuf *m;
73
74    m = l->head;
75    if (m) {
76        if (m == l->tail)
77            l->tail = NULL;
78        l->head = m->m_nextpkt;
79        l->qlen--;
80    }
81
82    return (m);
83}
84
85static __inline struct mbuf *
86mbufq_peek(struct mbuf_head *l)
87{
88    return (l->head);
89}
90
91#endif  /* CXGB_MBUFQ_H_ */
92