xref: /dflybsd-src/sys/net/netmap/netmap_mbq.h (revision bf9f7c1693a1645a30af161719c4687c7547c467)
1fb578518SFranco Fichtner /*
2fb578518SFranco Fichtner  * Copyright (C) 2013 Vincenzo Maffione. All rights reserved.
3fb578518SFranco Fichtner  *
4fb578518SFranco Fichtner  * Redistribution and use in source and binary forms, with or without
5fb578518SFranco Fichtner  * modification, are permitted provided that the following conditions
6fb578518SFranco Fichtner  * are met:
7fb578518SFranco Fichtner  *   1. Redistributions of source code must retain the above copyright
8fb578518SFranco Fichtner  *      notice, this list of conditions and the following disclaimer.
9fb578518SFranco Fichtner  *   2. Redistributions in binary form must reproduce the above copyright
10fb578518SFranco Fichtner  *      notice, this list of conditions and the following disclaimer in the
11fb578518SFranco Fichtner  *    documentation and/or other materials provided with the distribution.
12fb578518SFranco Fichtner  *
13fb578518SFranco Fichtner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14fb578518SFranco Fichtner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15fb578518SFranco Fichtner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16fb578518SFranco Fichtner  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17fb578518SFranco Fichtner  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18fb578518SFranco Fichtner  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19fb578518SFranco Fichtner  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20fb578518SFranco Fichtner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21fb578518SFranco Fichtner  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22fb578518SFranco Fichtner  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23fb578518SFranco Fichtner  * SUCH DAMAGE.
24fb578518SFranco Fichtner  */
25fb578518SFranco Fichtner 
26fb578518SFranco Fichtner /*
27fb578518SFranco Fichtner  * $FreeBSD$
28fb578518SFranco Fichtner  */
29fb578518SFranco Fichtner 
30fb578518SFranco Fichtner 
31fb578518SFranco Fichtner #ifndef __NETMAP_MBQ_H__
32fb578518SFranco Fichtner #define __NETMAP_MBQ_H__
33fb578518SFranco Fichtner 
34fb578518SFranco Fichtner /*
35fb578518SFranco Fichtner  * These function implement an mbuf tailq with an optional lock.
36fb578518SFranco Fichtner  * The base functions act ONLY ON THE QUEUE, whereas the "safe"
37fb578518SFranco Fichtner  * variants (mbq_safe_*) also handle the lock.
38fb578518SFranco Fichtner  */
39fb578518SFranco Fichtner 
40*bf9f7c16SFranco Fichtner /* XXX probably rely on a previous definition of SPINLOCK_T */
41*bf9f7c16SFranco Fichtner #define SPINLOCK_T  struct spinlock
42fb578518SFranco Fichtner 
43fb578518SFranco Fichtner /* A FIFO queue of mbufs with an optional lock. */
44fb578518SFranco Fichtner struct mbq {
45fb578518SFranco Fichtner     struct mbuf *head;
46fb578518SFranco Fichtner     struct mbuf *tail;
47fb578518SFranco Fichtner     int count;
48fb578518SFranco Fichtner     SPINLOCK_T lock;
49fb578518SFranco Fichtner };
50fb578518SFranco Fichtner 
51fb578518SFranco Fichtner /* XXX "destroy" does not match "init" as a name.
52fb578518SFranco Fichtner  * We should also clarify whether init can be used while
53fb578518SFranco Fichtner  * holding a lock, and whether mbq_safe_destroy() is a NOP.
54fb578518SFranco Fichtner  */
55fb578518SFranco Fichtner void mbq_init(struct mbq *q);
56fb578518SFranco Fichtner void mbq_destroy(struct mbq *q);
57fb578518SFranco Fichtner void mbq_enqueue(struct mbq *q, struct mbuf *m);
58fb578518SFranco Fichtner struct mbuf *mbq_dequeue(struct mbq *q);
59fb578518SFranco Fichtner void mbq_purge(struct mbq *q);
60fb578518SFranco Fichtner 
61fb578518SFranco Fichtner /* XXX missing mbq_lock() and mbq_unlock */
62fb578518SFranco Fichtner 
63fb578518SFranco Fichtner void mbq_safe_init(struct mbq *q);
64fb578518SFranco Fichtner void mbq_safe_destroy(struct mbq *q);
65fb578518SFranco Fichtner void mbq_safe_enqueue(struct mbq *q, struct mbuf *m);
66fb578518SFranco Fichtner struct mbuf *mbq_safe_dequeue(struct mbq *q);
67fb578518SFranco Fichtner void mbq_safe_purge(struct mbq *q);
68fb578518SFranco Fichtner 
mbq_len(struct mbq * q)69fb578518SFranco Fichtner static inline unsigned int mbq_len(struct mbq *q)
70fb578518SFranco Fichtner {
71fb578518SFranco Fichtner     return q->count;
72fb578518SFranco Fichtner }
73fb578518SFranco Fichtner 
74fb578518SFranco Fichtner #endif /* __NETMAP_MBQ_H_ */
75