1.Dd September 16, 2026 2.Dt IFLIB 4 3.Os 4.Sh NAME 5.Nm iflib 6.Nd Network Interface Driver Framework 7.Sh SYNOPSIS 8.Cd "device pci" 9.Cd "device iflib" 10.Sh DESCRIPTION 11.Nm 12is a framework for network interface drivers for 13.Fx . 14It is designed to remove a large amount of the boilerplate that is often 15needed for modern network interface devices, allowing driver authors to 16focus on the specific code needed for their hardware. 17This allows for a shared set of 18.Xr sysctl 8 19names, rather than each driver naming them individually. 20.Sh SYSCTL VARIABLES 21These variables must be set before loading the driver, either via 22.Xr loader.conf 5 23or through the use of 24.Xr kenv 1 . 25They are all prefixed by 26.Va dev.X.Y.iflib\&. 27where X is the driver name, and Y is the instance number. 28.Bl -tag -width indent 29.It Va override_nrxds 30Override the number of RX descriptors for each queue. 31The value is a comma separated list of positive integers. 32Some drivers only use a single value, but others may use more. 33These numbers must be powers of two, and zero means to use the default. 34Individual drivers may have additional restrictions on allowable values. 35Defaults to all zeros. 36.It Va override_ntxds 37Override the number of TX descriptors for each queue. 38The value is a comma separated list of positive integers. 39Some drivers only use a single value, but others may use more. 40These numbers must be powers of two, and zero means to use the default. 41Individual drivers may have additional restrictions on allowable values. 42Defaults to all zeros. 43.It Va override_qs_enable 44When set, allows the number of transmit and receive queues to be different. 45If not set, the lower of the number of TX or RX queues will be used for both. 46.It Va override_nrxqs 47Set the number of RX queues. 48If zero, the number of RX queues is derived from the number of cores on the 49socket connected to the controller. 50Defaults to 0. 51.It Va override_ntxqs 52Set the number of TX queues. 53If zero, the number of TX queues is derived from the number of cores on the 54socket connected to the controller. 55.It Va disable_msix 56Disables MSI-X interrupts for the device. 57.It Va core_offset 58Specifies a starting core offset to assign queues to. 59If the value is unspecified or 65535, cores are assigned sequentially across 60controllers. 61.It Va separate_txrx 62Requests that RX and TX queues not be paired on the same core. 63If this is zero or not set, an RX and TX queue pair will be assigned to each 64core. 65When set to a non-zero value, TX queues are assigned to cores following the 66last RX queue. 67.It Va simple_tx 68When set to one, iflib uses a simple transmit routine that sends packets 69directly while the transmit queue mutex is available. 70During contention, packets are deferred through a multi-producer 71.Xr buf_ring 9 72and drained by the mutex holder. 73By default, iflib uses a highly optimized, lockless, transmit queue called 74mp_ring. 75This performs well when there are more CPU cores than NIC 76queues and prevents lock contention for transmit resources. 77Unfortunately, mp_ring incurs unneeded overheads on workloads where 78resource contention is not a problem (well behaved applications on 79systems where there are as many NIC queues as CPU cores). 80Note that when this is enabled, the tx_abdicate sysctl is no longer 81applicable and is ignored. 82By default, this is the inverse of 83.Va net.iflib.prefer_mpring . 84An explicitly configured value takes precedence over that global default. 85.El 86.Pp 87These 88.Xr sysctl 8 89variables can be changed at any time: 90.Bl -tag -width indent 91.It Va tx_abdicate 92Controls how the transmit ring is serviced. 93If set to zero, when a frame is submitted to the transmission ring, the same 94task that is submitting it will service the ring unless there's already a 95task servicing the TX ring. 96This ensures that whenever there is a pending transmission, 97the transmit ring is being serviced. 98This results in higher transmit throughput. 99If set to a non-zero value, task returns immediately and the transmit 100ring is serviced by a different task. 101This returns control to the caller faster and under high receive load, 102may result in fewer dropped RX frames. 103.It Va tx_defer_mfree 104Controls the threshold in packets before iflib will free the memory 105(mbufs) for the packets that it has transmitted. 106When this is nonzero, mbufs will be freed outside the transmit lock. 107Setting this can reduce lock contention and CPU use when using simple_tx. 108Note that this applies only when simple_tx is enabled. 109.It Va tx_reclaim_thresh 110Controls the threshold in packets before iflib will ask the driver 111how many transmitted packets can be reclaimed. 112Determining how many many packets can be reclaimed can be expensive 113on some drivers. 114.It Va tx_reclaim_ticks 115Controls the time in ticks before iflib will ask the driver 116how many transmitted packets can be reclaimed. 117Determining how many many packets can be reclaimed can be expensive 118on some drivers. 119.It Va rx_budget 120Sets the maximum number of frames to be received at a time. 121Zero (the default) indicates the default (currently 16) should be used. 122.El 123.Pp 124There are also some global sysctls which can change behaviour for all drivers, 125and, unless noted otherwise, may be changed at any time. 126.Bl -tag -width indent 127.It Va net.iflib.max_producers 128Limits the number of callers that may concurrently enqueue packets to a 129simple transmit deferral ring without taking the transmit queue mutex. 130The limit is applied separately to each transmit queue. 131If lockless producers from one last-level cache are active, a producer from 132another last-level cache waits for the transmit queue mutex regardless of the 133limit. 134Setting this to zero forces all contending producers to wait for the mutex. 135The default is 8. 136This setting applies only when 137.Va simple_tx 138is enabled. 139.It Va net.iflib.min_tx_latency 140If this is set to a non-zero value, iflib will avoid any attempt to combine 141multiple transmits, and notify the hardware as quickly as possible of 142new descriptors. 143This will lower the maximum throughput, but will also lower transmit latency. 144.It Va net.iflib.no_tx_batch 145Some NICs allow processing completed transmit descriptors in batches. 146Doing so usually increases the transmit throughput by reducing the number of 147transmit interrupts. 148Setting this to a non-zero value will disable the use of this feature. 149.It Va net.iflib.prefer_mpring 150When set, use the 151.Va mp_ring 152transmit path by default instead of the simple transmit path. 153This is a read-only tunable that must be set before 154.Nm 155is loaded. 156An explicitly configured per-device 157.Va simple_tx 158value takes precedence. 159The default is one. 160.It Va net.iflib.simple_drain_quota 161Sets the maximum number of packets that the transmit task may remove from a 162simple transmit deferral ring in one drain operation. 163The default is 8. 164This setting applies only when 165.Va simple_tx 166is enabled. 167.It Va net.iflib.simple_drain_quota_thread 168Sets the maximum number of packets that a transmitting thread holding the 169transmit queue mutex may remove from a simple transmit deferral ring in one 170drain operation. 171A smaller value bounds the time for which a transmitting thread can hold the 172mutex while other producers replenish the ring. 173The default is 65536. 174This setting applies only when 175.Va simple_tx 176is enabled. 177.It Va net.iflib.simple_txbr_size 178Sets the number of entries in each 179.Xr buf_ring 9 180used by the simple transmit path to defer packets. 181The value must be a power of two and at least 64. 182Invalid values are replaced with the default of 1024. 183This is a read-only tunable that must be set before 184.Nm 185is loaded. 186This setting applies only when 187.Va simple_tx 188is enabled. 189.It Va net.iflib.tx_watchdog_periods 190Number of consecutive 191.Va net.iflib.timer_default 192intervals for which a transmit queue must remain frozen under demand before 193.Nm 194asks the hardware whether it has completions pending. 195A queue is frozen when it holds descriptors the hardware has not reported as 196completed while none are reclaimed. 197Demand persists while the outstanding descriptor count grows, the software 198queue is stalled, or the hardware descriptor ring is at its backpressure 199threshold. 200If it reports none, the interface is reset. 201Setting this to zero disables the check. 202.El 203.Pp 204These 205.Xr sysctl 8 206variables are read-only: 207.Bl -tag -width indent 208.It Va driver_version 209A string indicating the internal version of the driver. 210.It Va tx_watchdog_events 211Number of transmit watchdog resets initiated by 212.Nm . 213This counts recovery events, not failed packets, and is not included in the 214interface output error counter. 215.El 216.Pp 217There are a number of queue state 218.Xr sysctl 8 219variables as well: 220.Bl -tag -width indent 221.It Va txqZ 222The following are repeated for each transmit queue, where Z is the transmit 223queue instance number: 224.Bl -tag -width indent 225.It Va r_abdications 226Number of consumer abdications in the MP ring for this queue. 227An abdication occurs on every ring submission when tx_abdicate is true. 228.It Va r_restarts 229Number of consumer restarts in the MP ring for this queue. 230A restart occurs when an attempt to drain a non-empty ring fails, 231and the ring is already in the STALLED state. 232.It Va r_stalls 233Number of consumer stalls in the MP ring for this queue. 234A stall occurs when an attempt to drain a non-empty ring fails. 235.It Va r_starts 236Number of normal consumer starts in the MP ring for this queue. 237A start occurs when the MP ring transitions from IDLE to BUSY. 238.It Va r_drops 239Number of drops in the MP ring for this queue. 240A drop occurs when there is an attempt to add an entry to an MP ring with 241no available space. 242.It Va r_enqueues 243Number of entries which have been enqueued to the MP ring for this queue. 244.It Va ring_state 245MP (soft) ring state. 246This provides a snapshot of the current MP ring state, including the producer 247head and tail indexes, the consumer index, and the state. 248The state is one of "IDLE", "BUSY", 249"STALLED", or "ABDICATED". 250.It Va txq_cleaned 251The number of transmit descriptors which have been reclaimed. 252Total cleaned. 253.It Va txq_processed 254The number of transmit descriptors which have been processed, but may not yet 255have been reclaimed. 256.It Va txq_in_use 257Descriptors which have been added to the transmit queue, 258but have not yet been cleaned. 259This value will include both untransmitted descriptors as well as descriptors 260which have been processed. 261.It Va txq_cidx_processed 262The transmit queue consumer index of the next descriptor to process. 263.It Va txq_cidx 264The transmit queue consumer index of the oldest descriptor to reclaim. 265.It Va txq_pidx 266The transmit queue producer index where the next descriptor to transmit will 267be inserted. 268.It Va no_tx_dma_setup 269Number of times DMA mapping a transmit mbuf failed for reasons other than 270.Er EFBIG . 271.It Va txd_encap_efbig 272Number of times DMA mapping a transmit mbuf failed due to requiring too many 273segments. 274.It Va tx_map_failed 275Number of times DMA mapping a transmit mbuf failed for any reason 276(sum of no_tx_dma_setup and txd_encap_efbig) 277.It Va no_desc_avail 278Number of times a descriptor couldn't be added to the transmit ring because 279the transmit ring was full. 280.It Va mbuf_defrag_failed 281Number of times both 282.Xr m_collapse 9 283and 284.Xr m_defrag 9 285failed after an 286.Er EFBIG 287error 288result from DMA mapping a transmit mbuf. 289.It Va m_pullups 290Number of times 291.Xr m_pullup 9 292was called attempting to parse a header. 293.It Va mbuf_defrag 294Number of times 295.Xr m_defrag 9 296was called. 297.El 298.It Va rxqZ 299The following are repeated for each receive queue, where Z is the 300receive queue instance number: 301.Bl -tag -width indent 302.It Va rxq_fl0.credits 303Credits currently available in the receive ring. 304.It Va rxq_fl0.cidx 305Current receive ring consumer index. 306.It Va rxq_fl0.pidx 307Current receive ring producer index. 308.El 309.El 310.Pp 311Additional OIDs useful for driver and iflib development are exposed when the 312INVARIANTS and/or WITNESS options are enabled in the kernel. 313.Ss FAILURE INJECTION 314Registration failures can be injected for one selected device through the 315.Xr fail 9 316framework. 317Set 318.Va debug.fail_point.iflib.register_device 319to the exact device name and configure one of these fail points: 320.Bl -tag -width "register_before_attach_pre" 321.It Va register_before_attach_pre 322Before the driver's pre-attach method. 323.It Va register_after_attach_pre 324After the driver's pre-attach method succeeds. 325.It Va register_after_taskqueue 326After the private taskqueue is started. 327.It Va register_after_interrupts 328After interrupt resources are allocated. 329.It Va register_after_queues 330After queue setup and core-offset allocation. 331.It Va register_after_attach_post 332After the interface is attached and the driver's post-attach method succeeds. 333.El 334.Pp 335The fail points are under 336.Va debug.fail_point.iflib 337and accept the syntax described by 338.Xr fail 9 . 339A one-shot failure is safest because it permits the next probe to recover the 340device: 341.Bd -literal -offset indent 342sysctl debug.fail_point.iflib.register_device=igc1 343sysctl debug.fail_point.iflib.register_after_attach_pre='1*return(5)' 344devctl detach igc1 345devctl attach pci0:4:0:0 # returns EIO 346devctl attach pci0:4:0:0 # succeeds 347.Ed 348.Pp 349After detach, a device may no longer have its former name. 350Use a bus-specific address, as shown in the PCI example above, to reprobe it. 351.Pp 352The normal detach path can be synchronized with an in-flight admin task to 353test taskqueue teardown. 354Set 355.Va debug.fail_point.iflib.admin_task_device 356to the exact device name, bring the interface up, and set 357.Va debug.fail_point.iflib.admin_task_after_detach_check 358to a one-shot bounded delay, such as 359.Ql 1*print(1)->1*delay(5000000) . 360The delay keeps the admin task active long enough for detach to begin and 361remain blocked in the taskqueue drain. 362As a safety backstop, this fail point is marked nonsleepable and converts a 363configured 364.Sy sleep 365action to a delay. 366Once the execution message appears in the system log, 367detach should wait for the delay to finish. 368This exercises the case where an admin task has passed its detach check but 369has not yet acquired the context lock. 370.Sh SEE ALSO 371.Xr devctl 8 , 372.Xr fail 9 , 373.Xr iflib 9 374.Sh HISTORY 375This framework was introduced in 376.Fx 11.0 . 377