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