]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/dev/cxgb/sys/mbufq.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / dev / cxgb / sys / mbufq.h
1 /**************************************************************************
2
3 Copyright (c) 2007-2008, Chelsio Inc.
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, 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
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 POSSIBILITY OF SUCH DAMAGE.
27
28 $FreeBSD$
29
30 ***************************************************************************/
31
32 #ifndef CXGB_MBUFQ_H_
33 #define CXGB_MBUFQ_H_
34
35 struct mbuf_head {
36         struct mbuf *head;
37         struct mbuf *tail;
38         uint32_t     qlen;
39         uint32_t     qsize;
40         struct mtx   lock;
41 };
42
43 static __inline void
44 mbufq_init(struct mbuf_head *l)
45 {
46         l->head = l->tail = NULL;
47         l->qlen = l->qsize = 0;
48 }
49
50 static __inline int
51 mbufq_empty(struct mbuf_head *l)
52 {
53         return (l->head == NULL);
54 }
55
56 static __inline int
57 mbufq_len(struct mbuf_head *l)
58 {
59         return (l->qlen);
60 }
61
62 static __inline int
63 mbufq_size(struct mbuf_head *l)
64 {
65         return (l->qsize);
66 }
67
68 static __inline int
69 mbufq_head_size(struct mbuf_head *l)
70 {
71         return (l->head ? l->head->m_pkthdr.len : 0);
72 }
73
74 static __inline void
75 mbufq_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
86 static __inline struct mbuf *
87 mbufq_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
105 static __inline struct mbuf *
106 mbufq_peek(const struct mbuf_head *l)
107 {
108         return (l->head);
109 }
110
111 static __inline void
112 mbufq_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_ */