1*41ce3b17Snaddy.\" $OpenBSD: ifq_enqueue.9,v 1.13 2022/03/31 17:27:23 naddy Exp $ 2db314722Sdlg.\" 3db314722Sdlg.\" Copyright (c) 2015 David Gwynne <dlg@openbsd.org> 4db314722Sdlg.\" 5db314722Sdlg.\" Permission to use, copy, modify, and distribute this software for any 6db314722Sdlg.\" purpose with or without fee is hereby granted, provided that the above 7db314722Sdlg.\" copyright notice and this permission notice appear in all copies. 8db314722Sdlg.\" 9db314722Sdlg.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10db314722Sdlg.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11db314722Sdlg.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12db314722Sdlg.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13db314722Sdlg.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14db314722Sdlg.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15db314722Sdlg.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16db314722Sdlg.\" 17*41ce3b17Snaddy.Dd $Mdocdate: March 31 2022 $ 18db314722Sdlg.Dt IFQ_ENQUEUE 9 19db314722Sdlg.Os 20db314722Sdlg.Sh NAME 21db314722Sdlg.Nm ifq_enqueue , 22db314722Sdlg.Nm ifq_dequeue , 23db314722Sdlg.Nm ifq_purge , 24db314722Sdlg.Nm ifq_len , 25de6cd8fbSdlg.Nm ifq_empty , 2646b9fd90Sdlg.Nm ifq_hdatalen , 27de6cd8fbSdlg.Nm ifq_set_oactive , 28de6cd8fbSdlg.Nm ifq_clr_oactive , 2967c15d4fSdlg.Nm ifq_is_oactive , 3002ec1fbbSdlg.Nm ifq_restart , 3102ec1fbbSdlg.Nm ifq_barrier 32db314722Sdlg.Nd interface send queue API 33db314722Sdlg.Sh SYNOPSIS 34db314722Sdlg.In net/if_var.h 35db314722Sdlg.Ft int 36db314722Sdlg.Fn ifq_enqueue "struct ifqueue *ifq" "struct mbuf *m" 379066b682Ssthen.Ft struct mbuf * 38db314722Sdlg.Fn ifq_dequeue "struct ifqueue *ifq" 39db314722Sdlg.Ft unsigned int 40db314722Sdlg.Fn ifq_purge "struct ifqueue *ifq" 41db314722Sdlg.Ft unsigned int 42db314722Sdlg.Fn ifq_len "struct ifqueue *ifq" 43db314722Sdlg.Ft unsigned int 44db314722Sdlg.Fn ifq_empty "struct ifqueue *ifq" 4546b9fd90Sdlg.Ft int 4646b9fd90Sdlg.Fn ifq_hdatalen "struct ifqueue *ifq" 47de6cd8fbSdlg.Ft void 48de6cd8fbSdlg.Fn ifq_set_oactive "struct ifqueue *ifq" 49de6cd8fbSdlg.Ft void 50de6cd8fbSdlg.Fn ifq_clr_oactive "struct ifqueue *ifq" 51de6cd8fbSdlg.Ft unsigned int 52de6cd8fbSdlg.Fn ifq_is_oactive "struct ifqueue *ifq" 5367c15d4fSdlg.Ft void 5467c15d4fSdlg.Fn ifq_restart "struct ifqueue *ifq" 5502ec1fbbSdlg.Ft void 5602ec1fbbSdlg.Fn ifq_barrier "struct ifqueue *ifq" 57db314722Sdlg.Sh DESCRIPTION 58b76f01e8SfcambusThe ifqueue API provides implementations of data structures and 59db314722Sdlgoperations for the network stack to queue mbufs for a network driver 60db314722Sdlgto dequeue from its start routine for transmission. 61db314722Sdlg.Bl -tag -width Ds 62db314722Sdlg.It Fn ifq_enqueue "struct ifqueue *ifq" "struct mbuf *m" 63db314722SdlgEnqueue mbuf 64db314722Sdlg.Fa m 65db314722Sdlgon the 66db314722Sdlg.Fa ifq 67db314722Sdlginterface send queue. 68*41ce3b17SnaddyIf the queue rejects the packet, it will be freed with 69db314722Sdlg.Xr m_freem 9 70db314722Sdlgand counted as a drop. 71db314722Sdlg.It Fn ifq_dequeue "struct ifqueue *ifq" 72db314722SdlgDequeue the next mbuf to be transmitted from the 73db314722Sdlg.Fa ifq 74db314722Sdlginterface send queue. 75db314722Sdlg.It Fn ifq_purge "struct ifqueue *ifq" 76db314722SdlgFree all the mbufs on the interface send queue 77db314722Sdlg.Fa ifq . 78db314722SdlgFreed mbufs will be accounted as drops. 79db314722Sdlg.It Fn ifq_len "struct ifqueue *ifq" 80db314722SdlgReturn the number of mbufs on the interface send queue 81db314722Sdlg.Fa ifq . 82db314722SdlgNote that while 83db314722Sdlg.Fn ifq_len 84db314722Sdlgmay report that mbufs are on the queue, the current queue 85db314722Sdlgdiscipline may not make them available for dequeueing with 86db314722Sdlg.Fn ifq_dequeue 87db314722Sdlgor 88db314722Sdlg.Fn ifq_deq_begin . 89db314722Sdlg.It Fn ifq_empty "struct ifqueue *ifq" 90db314722SdlgReturn if the interface send queue 91db314722Sdlg.Fa ifq 92db314722Sdlgis empty. 9346b9fd90Sdlg.It Fn ifq_hdatalen "struct ifqueue *ifq" 9446b9fd90SdlgReturn the number of bytes in the mbuf at the head of the interface 9546b9fd90Sdlgsend queue 9646b9fd90Sdlg.Fa ifq . 97de6cd8fbSdlg.It Fn ifq_set_oactive "struct ifqueue *ifq" 98de6cd8fbSdlg.Fn ifq_set_oactive 99de6cd8fbSdlgis called by the relevant driver to mark the hardware associated 100de6cd8fbSdlgwith the interface send queue 101de6cd8fbSdlg.Fa ifq 102de6cd8fbSdlgas unable to transmit more packets. 103de6cd8fbSdlg.It Fn ifq_clr_oactive "struct ifqueue *ifq" 104de6cd8fbSdlg.Fn ifq_clr_oactive 105de6cd8fbSdlgis called by the relevant driver to clear the "active" mark on the 106de6cd8fbSdlghardware associated with the interface send queue 107de6cd8fbSdlg.Fa ifq , 108de6cd8fbSdlgmeaning it is now able to transmit packets. 109de6cd8fbSdlg.It Fn ifq_is_oactive "struct ifqueue *ifq" 110de6cd8fbSdlgReturn if the hardware associated with the interface send queue 111de6cd8fbSdlg.Fa ifq 112de6cd8fbSdlgis unable to transmit more packets. 11367c15d4fSdlg.It Fn ifq_restart "struct ifqueue *ifq" 11467c15d4fSdlgDispatch a call to 11567c15d4fSdlg.Fn ifq_clr_oactive 1165dc39c3eSjmcand the interface's start routine. 11767c15d4fSdlgThis call is serialised with other calls to the start routine via 11867c15d4fSdlg.Fn if_start 11967c15d4fSdlgand therefore provides race free modification of the "active" mark. 12002ec1fbbSdlg.It Fn ifq_barrier "struct ifqueue *ifq" 12102ec1fbbSdlg.Fn ifq_barrier 122dd1d6ea6Sjmcguarantees that any work currently running in the interface queue 123dd1d6ea6Sjmcserialiser (e.g. work dispatched by 12402ec1fbbSdlg.Fn ifq_restart 125dd1d6ea6Sjmcor the interface's start routine) has finished before 12602ec1fbbSdlg.Fn ifq_barrier 12702ec1fbbSdlgreturns. 128db314722Sdlg.El 129db314722Sdlg.Sh CONTEXT 130db314722Sdlg.Fn ifq_enqueue , 131db314722Sdlg.Fn ifq_dequeue , 132db314722Sdlg.Fn ifq_purge , 133db314722Sdlg.Fn ifq_len , 134de6cd8fbSdlg.Fn ifq_empty , 13546b9fd90Sdlg.Fn ifq_hdatalen , 136de6cd8fbSdlg.Fn ifq_set_oactive , 137de6cd8fbSdlg.Fn ifq_clr_oactive , 138f6c70747Sdlg.Fn ifq_is_oactive , 139db314722Sdlgand 140f6c70747Sdlg.Fn ifq_restart 141db314722Sdlgcan be called during autoconf, from process context, or from interrupt context. 14202ec1fbbSdlg.Pp 14302ec1fbbSdlg.Fn ifq_barrier 14402ec1fbbSdlgcan be called from process context. 145db314722Sdlg.Sh RETURN VALUES 146db314722Sdlg.Fn ifq_enqueue 147db314722Sdlgreturns 0 if the mbuf was successfully queued, or non-zero if mbuf was freed. 148db314722Sdlg.Pp 149db314722Sdlg.Fn ifq_dequeue 1503417d412Sjmcreturns the next mbuf to be transmitted by the interface. 151db314722SdlgIf no packet is available for transmission, 152db314722Sdlg.Dv NULL 153db314722Sdlgis returned. 154db314722Sdlg.Pp 155db314722Sdlg.Fn ifq_purge 156db314722Sdlgreturns the number of mbufs that were removed from the queue and freed. 157db314722Sdlg.Pp 158db314722Sdlg.Fn ifq_len 159db314722Sdlgreturns the number of mbufs on the queue. 160db314722Sdlg.Pp 161db314722Sdlg.Fn ifq_empty 162db314722Sdlgreturns a non-zero value if the queue is empty, otherwise 0. 163de6cd8fbSdlg.Pp 16446b9fd90Sdlg.Fn ifq_hdatalen 16546b9fd90Sdlgreturns the size of a packet on the queue, or 0 if the queue is empty; 16646b9fd90Sdlg.Pp 167de6cd8fbSdlg.Fn ifq_is_oactive 168de6cd8fbSdlgreturns a non-zero value if the hardware associated with the interface 169de6cd8fbSdlgsend queue is unable to transmit more packets, otherwise 0. 170db314722Sdlg.Sh SEE ALSO 171fa9f24a2Smpi.Xr ifq_deq_begin 9 , 172db314722Sdlg.Xr m_freem 9 173