135f8bc5fSChristian Brueffer.\" Copyright (c) 2009 Bitgravity Inc 235f8bc5fSChristian Brueffer.\" Written by: Kip Macy <kmacy@@FreeBSD.org> 335f8bc5fSChristian Brueffer.\" All rights reserved. 435f8bc5fSChristian Brueffer.\" 535f8bc5fSChristian Brueffer.\" Redistribution and use in source and binary forms, with or without 635f8bc5fSChristian Brueffer.\" modification, are permitted provided that the following conditions 735f8bc5fSChristian Brueffer.\" are met: 835f8bc5fSChristian Brueffer.\" 1. Redistributions of source code must retain the above copyright 935f8bc5fSChristian Brueffer.\" notice, this list of conditions and the following disclaimer. 1035f8bc5fSChristian Brueffer.\" 2. Redistributions in binary form must reproduce the above copyright 1135f8bc5fSChristian Brueffer.\" notice, this list of conditions and the following disclaimer in the 1235f8bc5fSChristian Brueffer.\" documentation and/or other materials provided with the distribution. 1335f8bc5fSChristian Brueffer.\" 1435f8bc5fSChristian Brueffer.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1535f8bc5fSChristian Brueffer.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1635f8bc5fSChristian Brueffer.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1735f8bc5fSChristian Brueffer.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1835f8bc5fSChristian Brueffer.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1935f8bc5fSChristian Brueffer.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2035f8bc5fSChristian Brueffer.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2135f8bc5fSChristian Brueffer.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2235f8bc5fSChristian Brueffer.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2335f8bc5fSChristian Brueffer.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2435f8bc5fSChristian Brueffer.\" SUCH DAMAGE. 2535f8bc5fSChristian Brueffer.\" 26063efed2SGleb Smirnoff.Dd September 27, 2012 2735f8bc5fSChristian Brueffer.Dt DRBR 9 2835f8bc5fSChristian Brueffer.Os 2935f8bc5fSChristian Brueffer.Sh NAME 3035f8bc5fSChristian Brueffer.Nm drbr , 3135f8bc5fSChristian Brueffer.Nm drbr_free , 3235f8bc5fSChristian Brueffer.Nm drbr_enqueue , 3335f8bc5fSChristian Brueffer.Nm drbr_dequeue , 3435f8bc5fSChristian Brueffer.Nm drbr_dequeue_cond , 3535f8bc5fSChristian Brueffer.Nm drbr_flush , 3635f8bc5fSChristian Brueffer.Nm drbr_empty , 37*32068667SChristian Brueffer.Nm drbr_inuse 3835f8bc5fSChristian Brueffer.Nd network driver interface to buf_ring 3935f8bc5fSChristian Brueffer.Sh SYNOPSIS 4035f8bc5fSChristian Brueffer.In sys/param.h 4135f8bc5fSChristian Brueffer.In net/if.h 4235f8bc5fSChristian Brueffer.In net/if_var.h 4335f8bc5fSChristian Brueffer.Ft void 4435f8bc5fSChristian Brueffer.Fn drbr_free "struct buf_ring *br" "struct malloc_type *type" 4535f8bc5fSChristian Brueffer.Ft int 4635f8bc5fSChristian Brueffer.Fn drbr_enqueue "struct ifnet *ifp" "struct buf_ring *br" "struct mbuf *m" 4735f8bc5fSChristian Brueffer.Ft struct mbuf * 4835f8bc5fSChristian Brueffer.Fn drbr_dequeue "struct ifnet *ifp" "struct buf_ring *br" 4935f8bc5fSChristian Brueffer.Ft struct mbuf * 5035f8bc5fSChristian Brueffer.Fn drbr_dequeue_cond "struct ifnet *ifp" "struct buf_ring *br" "int (*func) (struct mbuf *, void *)" "void *arg" 5135f8bc5fSChristian Brueffer.Ft void 5235f8bc5fSChristian Brueffer.Fn drbr_flush "struct ifnet *ifp" "struct buf_ring *br" 5335f8bc5fSChristian Brueffer.Ft int 5435f8bc5fSChristian Brueffer.Fn drbr_empty "struct ifnet *ifp" "struct buf_ring *br" 5535f8bc5fSChristian Brueffer.Ft int 5635f8bc5fSChristian Brueffer.Fn drbr_inuse "struct ifnet *ifp" "struct buf_ring *br" 5735f8bc5fSChristian Brueffer.Sh DESCRIPTION 5835f8bc5fSChristian BruefferThe 5935f8bc5fSChristian Brueffer.Nm 6035f8bc5fSChristian Bruefferfunctions provide an API to network drivers for using 6135f8bc5fSChristian Brueffer.Xr buf_ring 9 6235f8bc5fSChristian Bruefferfor enqueueing and dequeueing packets. 6335f8bc5fSChristian BruefferThis is meant as a replacement for the IFQ interface for packet queuing. 6435f8bc5fSChristian BruefferIt allows a packet to be enqueued with a single atomic and packet 6535f8bc5fSChristian Bruefferdequeue to be done without any per-packet atomics as it is protected 6635f8bc5fSChristian Bruefferby the driver's tx queue lock. 6735f8bc5fSChristian BruefferIf 6835f8bc5fSChristian Brueffer.Dv INVARIANTS 6935f8bc5fSChristian Bruefferis enabled, 7035f8bc5fSChristian Brueffer.Fn drbr_dequeue 7135f8bc5fSChristian Bruefferwill assert that the tx queue lock is held when it is called. 7235f8bc5fSChristian Brueffer.Pp 7335f8bc5fSChristian BruefferThe 7435f8bc5fSChristian Brueffer.Fn drbr_free 7535f8bc5fSChristian Bruefferfunction frees all the enqueued mbufs and then frees the buf_ring. 7635f8bc5fSChristian Brueffer.Pp 7735f8bc5fSChristian BruefferThe 7835f8bc5fSChristian Brueffer.Fn drbr_enqueue 7935f8bc5fSChristian Bruefferfunction is used to enqueue an mbuf to a buf_ring, falling back to the 8035f8bc5fSChristian Bruefferifnet's IFQ if 8135f8bc5fSChristian Brueffer.Xr ALTQ 4 8235f8bc5fSChristian Bruefferis enabled. 8335f8bc5fSChristian Brueffer.Pp 8435f8bc5fSChristian BruefferThe 8535f8bc5fSChristian Brueffer.Fn drbr_dequeue 8635f8bc5fSChristian Bruefferfunction is used to dequeue an mbuf from a buf_ring or, if 8735f8bc5fSChristian Brueffer.Xr ALTQ 4 8835f8bc5fSChristian Bruefferis enabled, from the ifnet's IFQ. 8935f8bc5fSChristian Brueffer.Pp 9035f8bc5fSChristian BruefferThe 9135f8bc5fSChristian Brueffer.Fn drbr_dequeue_cond 9235f8bc5fSChristian Bruefferfunction is used to conditionally dequeue an mbuf from a buf_ring based 9335f8bc5fSChristian Bruefferon whether 9435f8bc5fSChristian Brueffer.Fa func 9535f8bc5fSChristian Bruefferreturns 9635f8bc5fSChristian Brueffer.Dv TRUE 9735f8bc5fSChristian Bruefferor 9835f8bc5fSChristian Brueffer.Dv FALSE . 9935f8bc5fSChristian Brueffer.Pp 10035f8bc5fSChristian BruefferThe 10135f8bc5fSChristian Brueffer.Fn drbr_flush 10235f8bc5fSChristian Bruefferfunction frees all mbufs enqueued in the buf_ring and the ifnet's IFQ. 10335f8bc5fSChristian Brueffer.Pp 10435f8bc5fSChristian BruefferThe 10535f8bc5fSChristian Brueffer.Fn drbr_empty 10635f8bc5fSChristian Bruefferfunction returns 10735f8bc5fSChristian Brueffer.Dv TRUE 10835f8bc5fSChristian Bruefferif there are no mbufs enqueued, 10935f8bc5fSChristian Brueffer.Dv FALSE 11035f8bc5fSChristian Bruefferotherwise. 11135f8bc5fSChristian Brueffer.Pp 11235f8bc5fSChristian BruefferThe 11335f8bc5fSChristian Brueffer.Fn drbr_inuse 11435f8bc5fSChristian Bruefferfunction returns the number of mbufs enqueued. 11535f8bc5fSChristian BruefferNote to users that this is intrinsically racy as there is no guarantee that 11635f8bc5fSChristian Bruefferthere will not be more mbufs when 11735f8bc5fSChristian Brueffer.Fn drbr_dequeue 11835f8bc5fSChristian Bruefferis actually called. 11935f8bc5fSChristian BruefferProvided the tx queue lock is held there will not be less. 12035f8bc5fSChristian Brueffer.Sh RETURN VALUES 12135f8bc5fSChristian BruefferThe 12235f8bc5fSChristian Brueffer.Fn drbr_enqueue 12335f8bc5fSChristian Bruefferfunction returns 12435f8bc5fSChristian Brueffer.Er ENOBUFS 12535f8bc5fSChristian Bruefferif there are no slots available in the buf_ring and 12635f8bc5fSChristian Brueffer.Dv 0 12735f8bc5fSChristian Bruefferon success. 12835f8bc5fSChristian Brueffer.Pp 12935f8bc5fSChristian BruefferThe 13035f8bc5fSChristian Brueffer.Fn drbr_dequeue 13135f8bc5fSChristian Bruefferand 13235f8bc5fSChristian Brueffer.Fn drbr_dequeue_cond 13335f8bc5fSChristian Bruefferfunctions return an mbuf on success and 13435f8bc5fSChristian Brueffer.Dv NULL 13535f8bc5fSChristian Bruefferif the buf_ring is empty. 13635f8bc5fSChristian Brueffer.Sh HISTORY 13735f8bc5fSChristian BruefferThese functions were introduced in 13835f8bc5fSChristian Brueffer.Fx 8.0 . 139