Home | History | Annotate | Line # | Download | only in cxgb
      1 /**************************************************************************
      2 
      3 Copyright (c) 2007, 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 ***************************************************************************/
     29 
     30 #ifndef CXGB_MBUFQ_H_
     31 #define CXGB_MBUFQ_H_
     32 
     33 #include <sys/mbuf.h>
     34 
     35 struct mbuf_head {
     36     struct mbuf *head;
     37     struct mbuf *tail;
     38     uint32_t     qlen;
     39     struct mtx   lock;
     40 };
     41 
     42 static __inline void
     43 mbufq_init(struct mbuf_head *l)
     44 {
     45     l->head = l->tail = NULL;
     46 }
     47 
     48 static __inline int
     49 mbufq_empty(struct mbuf_head *l)
     50 {
     51     return (l->head == NULL);
     52 }
     53 
     54 static __inline int
     55 mbufq_len(struct mbuf_head *l)
     56 {
     57     return (l->qlen);
     58 }
     59 
     60 
     61 static __inline void
     62 mbufq_tail(struct mbuf_head *l, struct mbuf *m)
     63 {
     64     l->qlen++;
     65     l->tail->m_nextpkt = m;
     66     l->tail = m;
     67 }
     68 
     69 static __inline struct mbuf *
     70 mbufq_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 
     85 static __inline struct mbuf *
     86 mbufq_peek(struct mbuf_head *l)
     87 {
     88     return (l->head);
     89 }
     90 
     91 #endif  /* CXGB_MBUFQ_H_ */
     92