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