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