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