xref: /openbsd-src/share/man/man9/if_rxr_init.9 (revision 139410fb3e68569c0361f09ac28029baf78c1fe9)
1*139410fbSjsg.\"	$OpenBSD: if_rxr_init.9,v 1.10 2022/09/10 08:50:53 jsg Exp $
26f6698aaSdlg.\"
36f6698aaSdlg.\" Copyright (c) 2014 David Gwynne <dlg@openbsd.org>
46f6698aaSdlg.\"
56f6698aaSdlg.\" Permission to use, copy, modify, and distribute this software for any
66f6698aaSdlg.\" purpose with or without fee is hereby granted, provided that the above
76f6698aaSdlg.\" copyright notice and this permission notice appear in all copies.
86f6698aaSdlg.\"
96f6698aaSdlg.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
106f6698aaSdlg.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
116f6698aaSdlg.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
126f6698aaSdlg.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
136f6698aaSdlg.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
146f6698aaSdlg.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
156f6698aaSdlg.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
166f6698aaSdlg.\"
17*139410fbSjsg.Dd $Mdocdate: September 10 2022 $
186f6698aaSdlg.Dt IF_RXR_INIT 9
196f6698aaSdlg.Os
206f6698aaSdlg.Sh NAME
216f6698aaSdlg.Nm if_rxr_init ,
226f6698aaSdlg.Nm if_rxr_get ,
236f6698aaSdlg.Nm if_rxr_put ,
24e1d08503Sjmc.Nm if_rxr_livelocked ,
25e1d08503Sjmc.Nm if_rxr_needrefill ,
2633378d91Sjmc.Nm if_rxr_inuse ,
27e1d08503Sjmc.Nm if_rxr_cwm ,
2818f0f09bSjmc.Nm if_rxr_ioctl ,
2918f0f09bSjmc.Nm if_rxr_info_ioctl
306f6698aaSdlg.Nd Interface Receive Ring accounting
316f6698aaSdlg.Sh SYNOPSIS
326f6698aaSdlg.In net/if.h
336f6698aaSdlg.Ft void
345dfee228Sschwarze.Fn if_rxr_init "struct if_rxring *rxr" "unsigned int lwm" "unsigned int hwm"
356f6698aaSdlg.Ft unsigned int
365dfee228Sschwarze.Fn if_rxr_get "struct if_rxring *rxr" "unsigned int max"
376f6698aaSdlg.Ft void
385dfee228Sschwarze.Fn if_rxr_put "struct if_rxring *rxr" "unsigned int n"
392f18dd38Sdlg.Ft void
402f18dd38Sdlg.Fn if_rxr_livelocked "struct if_rxring *rxr"
41ed3e4660Sjan.Ft int
42ed3e4660Sjan.Fn if_rxr_needrefill "struct if_rxring *rxr"
436f6698aaSdlg.Ft unsigned int
445dfee228Sschwarze.Fn if_rxr_inuse "struct if_rxring *rxr"
452f18dd38Sdlg.Ft unsigned int
462f18dd38Sdlg.Fn if_rxr_cwm "struct if_rxring *rxr"
476f6698aaSdlg.Ft int
48c604da87Sdlg.Fo if_rxr_ioctl
49c604da87Sdlg.Fa "struct if_rxrinfo *ifri"
50c604da87Sdlg.Fa "const char *name"
51c604da87Sdlg.Fa "unsigned int size"
52c604da87Sdlg.Fa "struct if_rxring *rxr"
53c604da87Sdlg.Fc
546f6698aaSdlg.Ft int
55c604da87Sdlg.Fo if_rxr_info_ioctl
56c604da87Sdlg.Fa "struct if_rxrinfo *ifri"
57c604da87Sdlg.Fa "unsigned int n"
58c604da87Sdlg.Fa "struct if_rxring_info *rings"
59c604da87Sdlg.Fc
606f6698aaSdlg.Sh DESCRIPTION
616f6698aaSdlgThe Interface Receive Ring accounting API provides a mechanism to
6218f0f09bSjmcmanage the number of available descriptors on a network card's receive
636f6698aaSdlgring.
646f6698aaSdlgThe API restricts the allocation of receive descriptors using a
656f6698aaSdlgheuristic that monitors the use of the ring.
666f6698aaSdlgThe number of descriptors granted on the ring may increase over time
676f6698aaSdlgas the interface proves it uses them.
686f6698aaSdlgAdditionally, if the algorithm detects that the system is livelocked
696f6698aaSdlgas a result of being overwhelmed with network traffic, it will
706f6698aaSdlgrestrict the number of available receive descriptors.
716f6698aaSdlg.Pp
726f6698aaSdlg.Fn if_rxr_init
736f6698aaSdlginitialises the
746f6698aaSdlg.Fa rxr
756f6698aaSdlgstructure.
766f6698aaSdlgThe
776f6698aaSdlg.Fa lwm
786f6698aaSdlgargument defines the minimum number of descriptors the chip needs
796f6698aaSdlgto operate the ring correctly.
806f6698aaSdlg.Fa hwm
816f6698aaSdlgis used to describe the maximum number of descriptors the ring can contain.
826f6698aaSdlg.Pp
836f6698aaSdlg.Fn if_rxr_get
846f6698aaSdlgallocates and accounts for up to
856f6698aaSdlg.Fa max
866f6698aaSdlgdescriptors in the ring as being used.
876f6698aaSdlg.Pp
886f6698aaSdlg.Fn if_rxr_put
896f6698aaSdlgreturns
906f6698aaSdlg.Fa n
916f6698aaSdlgreceive descriptor slots to the ring.
926f6698aaSdlg.Pp
932f18dd38Sdlg.Fn if_rxr_livelocked
94*139410fbSjsgcan signal that the receive ring is generating too much load.
952f18dd38Sdlg.Pp
96ed3e4660Sjan.Fn if_rxr_needrefill
97*139410fbSjsgsignals that the receive ring runs below the low watermark of descriptors.
98ed3e4660Sjan.Pp
996f6698aaSdlg.Fn if_rxr_inuse
1006f6698aaSdlgcan be used to determine how many descriptor slots have been allocated
1016f6698aaSdlgon the ring.
1026f6698aaSdlg.Pp
1032f18dd38Sdlg.Fn if_rxr_cwm
1042f18dd38Sdlgcan be used to determine what the current watermark is for the ring.
1052f18dd38Sdlg.Pp
1066f6698aaSdlgThe
1076f6698aaSdlg.Fn if_rxr_ioctl
1086f6698aaSdlgand
1096f6698aaSdlg.Fn if_rxr_info_ioctl
11018f0f09bSjmcfunctions are provided to assist drivers in reporting their rings'
1116f6698aaSdlgstate to userland via a
1126f6698aaSdlg.Dv SIOCGIFRXR
1136f6698aaSdlgioctl request.
1146f6698aaSdlgThe ioctl data payload will be an ifreq structure, with ifr_data pointing at a
1156f6698aaSdlgstruct if_rxrinfo in userland memory.
1166f6698aaSdlgThis if_rxrinfo pointer should be passed via
1176f6698aaSdlg.Fa ifri .
1186f6698aaSdlg.Pp
1196f6698aaSdlgIf a driver only has a single receive ring, it may pass the ring state to
1206f6698aaSdlg.Fn if_rxr_ioctl
1216f6698aaSdlgvia the
1226f6698aaSdlg.Fa rxr
1236f6698aaSdlgargument.
1246f6698aaSdlg.Fa size
1256f6698aaSdlgis used to describe the size of the mbuf cluster the receive ring uses.
1266f6698aaSdlgIf the driver wishes to name the ring it can pass it via
1276f6698aaSdlg.Fa name ,
1286f6698aaSdlgotherwise
1296f6698aaSdlg.Dv NULL .
1306f6698aaSdlg.Pp
1316f6698aaSdlgIf the driver has multiple receive rings, it can prepare an array
1326f6698aaSdlgof if_rxring_info structures and pass that to
1336f6698aaSdlg.Fn if_rxr_info_ioctl
1346f6698aaSdlgvia
1356f6698aaSdlg.Fa rings
1366f6698aaSdlgwith the number of elements in the array passed via
1376f6698aaSdlg.Fa n .
1386f6698aaSdlg.Pp
1396f6698aaSdlgFor the heuristic to work correctly, a driver using this API should
1406f6698aaSdlgreturn all possible descriptor slots with
1414eb3f797Sdlg.Fn if_rxr_put
1426f6698aaSdlgbefore calling
1434eb3f797Sdlg.Fn if_rxr_get
1446f6698aaSdlgto fill them again.
1456f6698aaSdlg.Sh CONTEXT
1466f6698aaSdlg.Fn if_rxr_init ,
1476f6698aaSdlg.Fn if_rxr_get ,
1486f6698aaSdlg.Fn if_rxr_put ,
1492f18dd38Sdlg.Fn if_rxr_livelocked ,
150ed3e4660Sjan.Fn if_rxr_needrefill ,
1512f18dd38Sdlg.Fn if_rxr_inuse ,
1526f6698aaSdlgand
1532f18dd38Sdlg.Fn if_rxr_cwm
1546f6698aaSdlgcan be called during autoconf, from process context, or from interrupt context.
1556f6698aaSdlg.Pp
1564eb3f797Sdlg.Fn if_rxr_ioctl
1576f6698aaSdlgand
1584eb3f797Sdlg.Fn if_rxr_info_ioctl
1596f6698aaSdlgcan be called from process context, and only from the context of
1606f6698aaSdlgthe process generating an ioctl call.
1616f6698aaSdlg.Pp
1626f6698aaSdlgIt is up to the caller to provide appropriate locking around calls
1636f6698aaSdlgto these functions to prevent inconsistencies in the relevant
1646f6698aaSdlgif_rxring data structure.
1656f6698aaSdlg.Sh RETURN VALUES
1666f6698aaSdlg.Fn if_rxr_get
1676f6698aaSdlgreturns the number of receive descriptors available on the ring.
1686f6698aaSdlgThe number of descriptors may be less than the
1696f6698aaSdlg.Fa max
1706f6698aaSdlgrequested.
1716f6698aaSdlg.Pp
172ed3e4660Sjan.Fn if_rxr_needrefill
173ed3e4660Sjanreturns 1 if the number of receive descriptor slots currently in use on the
174ed3e4660Sjanring is below the value of
175ed3e4660Sjan.Fa lwm .
176ed3e4660SjanOtherwise, zero is returned.
177ed3e4660Sjan.Pp
1786f6698aaSdlg.Fn if_rxr_inuse
1796f6698aaSdlgreturns the number of receive descriptor slots currently in use on the ring.
1802f18dd38Sdlg.Pp
1812f18dd38Sdlg.Fn if_rxr_cwm
1822f18dd38Sdlgreturns the currently allowed allocation watermark.
1836f6698aaSdlg.Sh SEE ALSO
1846f6698aaSdlg.Xr autoconf 9
1856f6698aaSdlg.Sh HISTORY
1866f6698aaSdlgThe Interface Receive Ring API was originally written by
1876f6698aaSdlg.An David Gwynne Aq Mt dlg@openbsd.org .
1886f6698aaSdlgThe API first appeared in
1896f6698aaSdlg.Ox 5.6 .
190