1*b76f01e8Sfcambus.\" $OpenBSD: mq_init.9,v 1.13 2020/08/28 09:15:16 fcambus Exp $ 2162361b3Smpi.\" 3162361b3Smpi.\" Copyright (c) 2015 David Gwynne <dlg@openbsd.org> 4162361b3Smpi.\" 5162361b3Smpi.\" Permission to use, copy, modify, and distribute this software for any 6162361b3Smpi.\" purpose with or without fee is hereby granted, provided that the above 7162361b3Smpi.\" copyright notice and this permission notice appear in all copies. 8162361b3Smpi.\" 9162361b3Smpi.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10162361b3Smpi.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11162361b3Smpi.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12162361b3Smpi.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13162361b3Smpi.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14162361b3Smpi.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15162361b3Smpi.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16162361b3Smpi.\" 17*b76f01e8Sfcambus.Dd $Mdocdate: August 28 2020 $ 18162361b3Smpi.Dt MQ_INIT 9 19162361b3Smpi.Os 20162361b3Smpi.Sh NAME 21162361b3Smpi.Nm mq_init , 22162361b3Smpi.Nm mq_enqueue , 235d717772Sdlg.Nm mq_push , 24162361b3Smpi.Nm mq_dequeue , 25162361b3Smpi.Nm mq_enlist , 26162361b3Smpi.Nm mq_delist , 27162361b3Smpi.Nm mq_dechain , 28162361b3Smpi.Nm mq_len , 29162361b3Smpi.Nm mq_empty , 306fa80849Spatrick.Nm mq_full , 317b44842eSdlg.Nm mq_hdatalen , 32164d10c5Sdlg.Nm mq_purge , 33162361b3Smpi.Nm mq_drops , 34162361b3Smpi.Nm mq_set_maxlen , 35162361b3Smpi.Nm MBUF_QUEUE_INITIALIZER 36162361b3Smpi.Nd mbuf queue API 37162361b3Smpi.Sh SYNOPSIS 38162361b3Smpi.In sys/mbuf.h 39db5275bdSdlg.Ft void 405dfee228Sschwarze.Fn mq_init "struct mbuf_queue *mq" "unsigned int maxlen" "int ipl" 41162361b3Smpi.Ft int 425dfee228Sschwarze.Fn mq_enqueue "struct mbuf_queue *mq" "struct mbuf *m" 435d717772Sdlg.Ft int 445d717772Sdlg.Fn mq_push "struct mbuf_queue *mq" "struct mbuf *m" 45162361b3Smpi.Ft struct mbuf * 465dfee228Sschwarze.Fn mq_dequeue "struct mbuf_queue *mq" 47162361b3Smpi.Ft int 485dfee228Sschwarze.Fn mq_enlist "struct mbuf_queue *mq" "struct mbuf_list *ml" 49162361b3Smpi.Ft void 505dfee228Sschwarze.Fn mq_delist "struct mbuf_queue *mq" "struct mbuf_list *ml" 51162361b3Smpi.Ft struct mbuf * 525dfee228Sschwarze.Fn mq_dechain "struct mbuf_queue *mq" 53162361b3Smpi.Ft unsigned int 545dfee228Sschwarze.Fn mq_len "struct mbuf_queue *mq" 55162361b3Smpi.Ft int 565dfee228Sschwarze.Fn mq_empty "struct mbuf_queue *mq" 576fa80849Spatrick.Ft int 586fa80849Spatrick.Fn mq_full "struct mbuf_queue *mq" 59162361b3Smpi.Ft unsigned int 607b44842eSdlg.Fn mq_hdatalen "struct mbuf_queue *mq" 617b44842eSdlg.Ft unsigned int 62164d10c5Sdlg.Fn mq_purge "struct mbuf_queue *mq" 63164d10c5Sdlg.Ft unsigned int 645dfee228Sschwarze.Fn mq_drops "struct mbuf_queue *mq" 65162361b3Smpi.Ft void 665dfee228Sschwarze.Fn mq_set_maxlen "struct mbuf_queue *mq" "unsigned int" 67162361b3Smpi.Ft struct mbuf_queue 685dfee228Sschwarze.Fn MBUF_QUEUE_INITIALIZER "unsigned int maxlen" "int ipl" 69162361b3Smpi.Sh DESCRIPTION 70*b76f01e8SfcambusThe mbuf queue API provides implementations of data structures and operations 71162361b3Smpifor queueing mbufs and lists of mbufs between contexts. 72162361b3Smpi.Pp 73162361b3Smpimbuf_queue data structures provide a superset of the functionality 74162361b3Smpiavailable in mbuf_lists, and protect themselves internally with a 75162361b3Smpi.Xr mutex 9 , 76162361b3Smpimaking them useful for moving mbufs between contexts or subsystems. 77162361b3SmpiAdditionally, mbuf_queues provide a limit on the number of mbufs that 78162361b3Smpimay be queued. 79162361b3Smpi.Pp 80162361b3Smpimbuf_queue structures support the following functionality: 81162361b3Smpi.Pp 82162361b3Smpi.Bl -enum -compact -offset indent 83162361b3Smpi.It 84162361b3SmpiInsertion of a new mbuf at the end of the queue. 85162361b3Smpi.It 86162361b3SmpiRemoval of an mbuf from the head of the queue. 87162361b3Smpi.It 8863676e14SdlgReinsertion of an mbuf at the head of the queue. 8963676e14Sdlg.It 90162361b3SmpiRemoval of the entire chain of mbufs on the queue. 91162361b3Smpi.It 92162361b3SmpiInsertion of the mbufs in an mbuf_list at the end of the queue. 93162361b3Smpi.It 94162361b3SmpiRemoval of all the mbufs on the queue as an mbuf_list. 95162361b3Smpi.El 96162361b3Smpi.Bl -tag -width Ds 975dfee228Sschwarze.It Fn mq_init "struct mbuf_queue *mq" "unsigned int maxlen" "int ipl" 98162361b3SmpiInitialises the mbuf queue structure 99162361b3Smpi.Fa mq . 10063676e14SdlgThe maximum number of mbufs that should be queued is specified with 101162361b3Smpi.Fa maxlen . 102162361b3SmpiThe highest interrupt priority level the queue will be operated at is 103162361b3Smpispecified via 104162361b3Smpi.Fa ipl . 1055dfee228Sschwarze.It Fn MBUF_QUEUE_INITIALIZER "unsigned int maxlen" "int ipl" 106162361b3SmpiInitialises an mbuf queue structure declaration. 10763676e14SdlgThe maximum number of mbufs that should be queued is specified with 108162361b3Smpi.Fa maxlen . 109162361b3SmpiThe highest interrupt priority level the queue will be operated at is 110162361b3Smpispecified via 111162361b3Smpi.Fa ipl . 1125dfee228Sschwarze.It Fn mq_enqueue "struct mbuf_queue *mq" "struct mbuf *m" 113162361b3SmpiEnqueue mbuf 114162361b3Smpi.Fa m 115162361b3Smpion the end of the 116162361b3Smpi.Fa mq 117162361b3Smpimbuf queue. 1185d717772SdlgIf the queue is full then 1195d717772Sdlg.Fa m 1205d717772Sdlgwill be dropped. 1215d717772Sdlg.It Fn mq_push "struct mbuf_queue *mq" "struct mbuf *m" 1225d717772SdlgEnqueue mbuf 1235d717772Sdlg.Fa m 1245d717772Sdlgon the end of the 1255d717772Sdlg.Fa mq 1265d717772Sdlgmbuf queue. 1275d717772SdlgIf the queue is full then the mbuf at the head of the queue 1285d717772Sdlgwill be dropped. 1295dfee228Sschwarze.It Fn mq_dequeue "struct mbuf_queue *mq" 130162361b3SmpiDequeue an mbuf from the front of the 131162361b3Smpi.Fa mq 132162361b3Smpimbuf queue. 1335dfee228Sschwarze.It Fn mq_enlist "struct mbuf_queue *mq" "struct mbuf_list *ml" 134162361b3SmpiEnqueue all the mbufs on the 135162361b3Smpi.Fa ml 136162361b3Smpimbuf list on to the end of the 137162361b3Smpi.Fa mq 138162361b3Smpimbuf queue. 139162361b3SmpiNote, the number of mbufs placed on the queue may exceed its maximum length. 1405dfee228Sschwarze.It Fn mq_delist "struct mbuf_queue *mq" "struct mbuf_list *ml" 141162361b3SmpiDequeue all the mbufs on the 142162361b3Smpi.Fa mq 143162361b3Smpimbuf queue on to the 144162361b3Smpi.Fa ml 145162361b3Smpimbuf list. 1465dfee228Sschwarze.It Fn mq_dechain "struct mbuf_queue *mq" 147162361b3SmpiDequeue all mbufs from the 148162361b3Smpi.Fa mq 149162361b3Smpimbuf queue. 1505dfee228Sschwarze.It Fn mq_len "struct mbuf_queue *mq" 151162361b3SmpiReturn the number of mbufs on the 152162361b3Smpi.Fa mq 153162361b3Smpimbuf queue. 1545dfee228Sschwarze.It Fn mq_empty "struct mbuf_queue *mq" 155162361b3SmpiReturn if the 156162361b3Smpi.Fa mq 157162361b3Smpimbuf queue is empty. 1586fa80849Spatrick.It Fn mq_full "struct mbuf_queue *mq" 1596fa80849SpatrickReturn if the 1606fa80849Spatrick.Fa mq 1616fa80849Spatrickmbuf queue is full. 1627b44842eSdlg.It Fn mq_hdatalen "struct mbuf_queue *mq" 1637b44842eSdlgReturn the number of bytes in the packet at the head of the 1647b44842eSdlg.Fa mq 1657b44842eSdlgmbuf queue. 166164d10c5Sdlg.It Fn mq_purge "struct mbuf_queue *mq" 167164d10c5SdlgFree all the mbufs on the 168164d10c5Sdlg.Fa mq 169164d10c5Sdlgmbuf queue. 1705dfee228Sschwarze.It Fn mq_drops "struct mbuf_queue *mq" 171162361b3SmpiReturn how many mbufs were dropped and freed by 172162361b3Smpi.Xr m_freem 9 173162361b3Smpiif the 174162361b3Smpi.Fa mq 175162361b3Smpimbuf queue was too full. 1765dfee228Sschwarze.It Fn mq_set_maxlen "struct mbuf_queue *mq" "unsigned int" 17763676e14SdlgAlter the maximum number of mbufs that should be queued on the 178162361b3Smpi.Fa mq 179162361b3Smpimbuf queue. 180162361b3SmpiNote, 181162361b3Smpi.Fn mq_set_maxlen 182162361b3Smpiwill only set a new limit, it will not free any excess mbufs that may 183162361b3Smpialready exist on the queue. 184162361b3Smpi.El 185162361b3Smpi.Sh CONTEXT 186162361b3Smpi.Fn mq_init , 187162361b3Smpi.Fn mq_enqueue , 1885d717772Sdlg.Fn mq_push , 189162361b3Smpi.Fn mq_dequeue , 190162361b3Smpi.Fn mq_enlist , 191162361b3Smpi.Fn mq_delist , 192162361b3Smpi.Fn mq_dechain , 193162361b3Smpi.Fn mq_len , 194162361b3Smpi.Fn mq_empty , 1956fa80849Spatrick.Fn mq_full , 196164d10c5Sdlg.Fn mq_purge , 197162361b3Smpi.Fn mq_drops , 198162361b3Smpi.Fn mq_set_maxlen , 199162361b3Smpiand 200162361b3Smpi.Fn MBUF_QUEUE_INITIALIZER 201162361b3Smpican be called during autoconf, from process context, or from interrupt context. 202162361b3Smpi.Sh RETURN VALUES 203162361b3Smpi.Fn mq_dequeue 204162361b3Smpireturns the mbuf that was at the head of its queue. 205162361b3SmpiIf the queue was empty, 206162361b3Smpi.Dv NULL 207162361b3Smpiis returned. 208162361b3Smpi.Pp 209162361b3Smpi.Fn mq_dechain 210162361b3Smpireturns all the mbufs that were on its queues via a pointer to an mbuf 211162361b3Smpiwith the chain accessible via m_nextpkt members. 212162361b3SmpiIf the queue was empty, 213162361b3Smpi.Dv NULL 214162361b3Smpiis returned. 215162361b3Smpi.Pp 216162361b3Smpi.Fn mq_len 217162361b3Smpireturns the number of mbufs on the queue. 218162361b3Smpi.Pp 219162361b3Smpi.Fn mq_empty 220162361b3Smpireturns a non-zero value if the queue is empty, otherwise 0. 221162361b3Smpi.Pp 2226fa80849Spatrick.Fn mq_full 2236fa80849Spatrickreturns a non-zero value if the queue is full, otherwise 0. 2246fa80849Spatrick.Pp 225162361b3Smpi.Fn mq_enqueue 226162361b3Smpireturns 0 if the mbuf was successfully queued, or non-zero if the 227162361b3Smpimbuf was freed because it would cause the queue to exceed its maximum 228162361b3Smpilength. 229162361b3Smpi.Pp 2305d717772Sdlg.Fn mq_push 2315d717772Sdlgreturns 0 if there was space on the queue for the mbuf, or non-zero 2325d717772Sdlgif the head of the queue was freed to make space for it. 2335d717772Sdlg.Pp 234162361b3Smpi.Fn mq_enlist 235162361b3Smpireturns the number of mbufs that were dropped from the list if the 236162361b3Smpilength of the queue exceeded its maximum length. 237162361b3Smpi.Pp 2387b44842eSdlg.Fn mq_hdatalen 239eb6d7a50Sjmcreturns the size of a packet on the queue, or 0 if the queue is empty. 2407b44842eSdlg.Pp 241164d10c5Sdlg.Fn mq_purge 242164d10c5Sdlgreturns the number of mbufs that were freed. 243164d10c5Sdlg.Pp 244162361b3Smpi.Fn mq_drops 245162361b3Smpireturns the number of mbufs that were freed during 246162361b3Smpi.Fn mq_enqueue 247162361b3Smpioperations that would have caused the queue to exceed its maximum length. 248162361b3Smpi.Sh SEE ALSO 249162361b3Smpi.Xr mbuf 9 , 250162361b3Smpi.Xr ml_init 9 , 251162361b3Smpi.Xr mutex 9 252