1ca853deeSEric Joyner /* SPDX-License-Identifier: BSD-3-Clause */
2ca853deeSEric Joyner /* Copyright (c) 2021, Intel Corporation
3ca853deeSEric Joyner * All rights reserved.
4ca853deeSEric Joyner *
5ca853deeSEric Joyner * Redistribution and use in source and binary forms, with or without
6ca853deeSEric Joyner * modification, are permitted provided that the following conditions are met:
7ca853deeSEric Joyner *
8ca853deeSEric Joyner * 1. Redistributions of source code must retain the above copyright notice,
9ca853deeSEric Joyner * this list of conditions and the following disclaimer.
10ca853deeSEric Joyner *
11ca853deeSEric Joyner * 2. Redistributions in binary form must reproduce the above copyright
12ca853deeSEric Joyner * notice, this list of conditions and the following disclaimer in the
13ca853deeSEric Joyner * documentation and/or other materials provided with the distribution.
14ca853deeSEric Joyner *
15ca853deeSEric Joyner * 3. Neither the name of the Intel Corporation nor the names of its
16ca853deeSEric Joyner * contributors may be used to endorse or promote products derived from
17ca853deeSEric Joyner * this software without specific prior written permission.
18ca853deeSEric Joyner *
19ca853deeSEric Joyner * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20ca853deeSEric Joyner * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21ca853deeSEric Joyner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22ca853deeSEric Joyner * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23ca853deeSEric Joyner * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24ca853deeSEric Joyner * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25ca853deeSEric Joyner * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26ca853deeSEric Joyner * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27ca853deeSEric Joyner * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28ca853deeSEric Joyner * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29ca853deeSEric Joyner * POSSIBILITY OF SUCH DAMAGE.
30ca853deeSEric Joyner */
31ca853deeSEric Joyner
32ca853deeSEric Joyner /**
33ca853deeSEric Joyner * @file iavf_lib.h
34ca853deeSEric Joyner * @brief header for structures and functions common to legacy and iflib
35ca853deeSEric Joyner *
36ca853deeSEric Joyner * Contains definitions and function declarations which are shared between the
37ca853deeSEric Joyner * legacy and iflib driver implementation.
38ca853deeSEric Joyner */
39ca853deeSEric Joyner #ifndef _IAVF_LIB_H_
40ca853deeSEric Joyner #define _IAVF_LIB_H_
41ca853deeSEric Joyner
42ca853deeSEric Joyner #include <sys/malloc.h>
43ca853deeSEric Joyner #include <machine/stdarg.h>
44ca853deeSEric Joyner #include <sys/sysctl.h>
455577aa33SEric Joyner #ifdef RSS
465577aa33SEric Joyner #include <net/rss_config.h>
475577aa33SEric Joyner #endif
48ca853deeSEric Joyner
49ca853deeSEric Joyner #include "iavf_debug.h"
50ca853deeSEric Joyner #include "iavf_osdep.h"
51ca853deeSEric Joyner #include "iavf_type.h"
52ca853deeSEric Joyner #include "iavf_prototype.h"
53ca853deeSEric Joyner
54ca853deeSEric Joyner MALLOC_DECLARE(M_IAVF);
55ca853deeSEric Joyner
56ca853deeSEric Joyner /*
57ca853deeSEric Joyner * Ring Descriptors Valid Range: 32-4096 Default Value: 1024 This value is the
58ca853deeSEric Joyner * number of tx/rx descriptors allocated by the driver. Increasing this
59ca853deeSEric Joyner * value allows the driver to queue more operations.
60ca853deeSEric Joyner *
61ca853deeSEric Joyner * Tx descriptors are always 16 bytes, but Rx descriptors can be 32 bytes.
62ca853deeSEric Joyner * The driver currently always uses 32 byte Rx descriptors.
63ca853deeSEric Joyner */
64ca853deeSEric Joyner #define IAVF_DEFAULT_RING 1024
65ca853deeSEric Joyner #define IAVF_MAX_RING 4096
66ca853deeSEric Joyner #define IAVF_MIN_RING 64
67ca853deeSEric Joyner #define IAVF_RING_INCREMENT 32
68ca853deeSEric Joyner
69ca853deeSEric Joyner #define IAVF_AQ_LEN 256
70ca853deeSEric Joyner #define IAVF_AQ_LEN_MAX 1024
71ca853deeSEric Joyner
72ca853deeSEric Joyner /*
73ca853deeSEric Joyner ** Default number of entries in Tx queue buf_ring.
74ca853deeSEric Joyner */
75ca853deeSEric Joyner #define DEFAULT_TXBRSZ 4096
76ca853deeSEric Joyner
77ca853deeSEric Joyner /* Alignment for rings */
78ca853deeSEric Joyner #define DBA_ALIGN 128
79ca853deeSEric Joyner
80ca853deeSEric Joyner /*
81ca853deeSEric Joyner * Max number of multicast MAC addrs added to the driver's
82ca853deeSEric Joyner * internal lists before converting to promiscuous mode
83ca853deeSEric Joyner */
84ca853deeSEric Joyner #define MAX_MULTICAST_ADDR 128
85ca853deeSEric Joyner
86ca853deeSEric Joyner /* Byte alignment for Tx/Rx descriptor rings */
87ca853deeSEric Joyner #define DBA_ALIGN 128
88ca853deeSEric Joyner
89ca853deeSEric Joyner #define IAVF_MSIX_BAR 3
90ca853deeSEric Joyner #define IAVF_ADM_LIMIT 2
91ca853deeSEric Joyner #define IAVF_TSO_SIZE ((255*1024)-1)
92ca853deeSEric Joyner #define IAVF_AQ_BUF_SZ ((u32) 4096)
93ca853deeSEric Joyner #define IAVF_RX_HDR 128
94ca853deeSEric Joyner #define IAVF_RX_LIMIT 512
95ca853deeSEric Joyner #define IAVF_RX_ITR 0
96ca853deeSEric Joyner #define IAVF_TX_ITR 1
97ca853deeSEric Joyner /**
98ca853deeSEric Joyner * The maximum packet length allowed to be sent or received by the adapter.
99ca853deeSEric Joyner */
100ca853deeSEric Joyner #define IAVF_MAX_FRAME 9728
101ca853deeSEric Joyner /**
102ca853deeSEric Joyner * The minimum packet length allowed to be sent by the adapter.
103ca853deeSEric Joyner */
104ca853deeSEric Joyner #define IAVF_MIN_FRAME 17
105ca853deeSEric Joyner #define IAVF_MAX_TX_SEGS 8
106ca853deeSEric Joyner #define IAVF_MAX_RX_SEGS 5
107ca853deeSEric Joyner #define IAVF_MAX_TSO_SEGS 128
108ca853deeSEric Joyner #define IAVF_SPARSE_CHAIN 7
109ca853deeSEric Joyner #define IAVF_MIN_TSO_MSS 64
110ca853deeSEric Joyner #define IAVF_MAX_TSO_MSS 9668
111ca853deeSEric Joyner #define IAVF_MAX_DMA_SEG_SIZE ((16 * 1024) - 1)
112ca853deeSEric Joyner #define IAVF_AQ_MAX_ERR 30
113ca853deeSEric Joyner #define IAVF_MAX_INIT_WAIT 120
114ca853deeSEric Joyner #define IAVF_AQ_TIMEOUT (1 * hz)
115ca853deeSEric Joyner #define IAVF_ADV_LINK_SPEED_SCALE ((u64)1000000)
116ca853deeSEric Joyner #define IAVF_MAX_DIS_Q_RETRY 10
117ca853deeSEric Joyner
118ca853deeSEric Joyner #define IAVF_RSS_KEY_SIZE_REG 13
119ca853deeSEric Joyner #define IAVF_RSS_KEY_SIZE (IAVF_RSS_KEY_SIZE_REG * 4)
120ca853deeSEric Joyner #define IAVF_RSS_VSI_LUT_SIZE 64 /* X722 -> VSI, X710 -> VF */
121ca853deeSEric Joyner #define IAVF_RSS_VSI_LUT_ENTRY_MASK 0x3F
122ca853deeSEric Joyner #define IAVF_RSS_VF_LUT_ENTRY_MASK 0xF
123ca853deeSEric Joyner
124ca853deeSEric Joyner /* Maximum MTU size */
125ca853deeSEric Joyner #define IAVF_MAX_MTU (IAVF_MAX_FRAME - \
126ca853deeSEric Joyner ETHER_HDR_LEN - ETHER_CRC_LEN - ETHER_VLAN_ENCAP_LEN)
127ca853deeSEric Joyner
128ca853deeSEric Joyner /*
129ca853deeSEric Joyner * Hardware requires that TSO packets have an segment size of at least 64
130ca853deeSEric Joyner * bytes. To avoid sending bad frames to the hardware, the driver forces the
131ca853deeSEric Joyner * MSS for all TSO packets to have a segment size of at least 64 bytes.
132ca853deeSEric Joyner *
133ca853deeSEric Joyner * However, if the MTU is reduced below a certain size, then the resulting
134ca853deeSEric Joyner * larger MSS can result in transmitting segmented frames with a packet size
135ca853deeSEric Joyner * larger than the MTU.
136ca853deeSEric Joyner *
137ca853deeSEric Joyner * Avoid this by preventing the MTU from being lowered below this limit.
138ca853deeSEric Joyner * Alternative solutions require changing the TCP stack to disable offloading
139ca853deeSEric Joyner * the segmentation when the requested segment size goes below 64 bytes.
140ca853deeSEric Joyner */
141ca853deeSEric Joyner #define IAVF_MIN_MTU 112
142ca853deeSEric Joyner
143ca853deeSEric Joyner /*
144ca853deeSEric Joyner * Interrupt Moderation parameters
145ca853deeSEric Joyner * Multiply ITR values by 2 for real ITR value
146ca853deeSEric Joyner */
147ca853deeSEric Joyner #define IAVF_MAX_ITR 0x0FF0
148ca853deeSEric Joyner #define IAVF_ITR_100K 0x0005
149ca853deeSEric Joyner #define IAVF_ITR_20K 0x0019
150ca853deeSEric Joyner #define IAVF_ITR_8K 0x003E
151ca853deeSEric Joyner #define IAVF_ITR_4K 0x007A
152ca853deeSEric Joyner #define IAVF_ITR_1K 0x01F4
153ca853deeSEric Joyner #define IAVF_ITR_DYNAMIC 0x8000
154ca853deeSEric Joyner #define IAVF_LOW_LATENCY 0
155ca853deeSEric Joyner #define IAVF_AVE_LATENCY 1
156ca853deeSEric Joyner #define IAVF_BULK_LATENCY 2
157ca853deeSEric Joyner
158ca853deeSEric Joyner /* MacVlan Flags */
159ca853deeSEric Joyner #define IAVF_FILTER_USED (u16)(1 << 0)
160ca853deeSEric Joyner #define IAVF_FILTER_VLAN (u16)(1 << 1)
161ca853deeSEric Joyner #define IAVF_FILTER_ADD (u16)(1 << 2)
162ca853deeSEric Joyner #define IAVF_FILTER_DEL (u16)(1 << 3)
163ca853deeSEric Joyner #define IAVF_FILTER_MC (u16)(1 << 4)
164ca853deeSEric Joyner /* used in the vlan field of the filter when not a vlan */
165ca853deeSEric Joyner #define IAVF_VLAN_ANY -1
166ca853deeSEric Joyner
167ca853deeSEric Joyner #define CSUM_OFFLOAD_IPV4 (CSUM_IP|CSUM_TCP|CSUM_UDP|CSUM_SCTP)
168ca853deeSEric Joyner #define CSUM_OFFLOAD_IPV6 (CSUM_TCP_IPV6|CSUM_UDP_IPV6|CSUM_SCTP_IPV6)
169ca853deeSEric Joyner #define CSUM_OFFLOAD (CSUM_OFFLOAD_IPV4|CSUM_OFFLOAD_IPV6|CSUM_TSO)
170ca853deeSEric Joyner
171ca853deeSEric Joyner /* Misc flags for iavf_vsi.flags */
172ca853deeSEric Joyner #define IAVF_FLAGS_KEEP_TSO4 (1 << 0)
173ca853deeSEric Joyner #define IAVF_FLAGS_KEEP_TSO6 (1 << 1)
174ca853deeSEric Joyner
175ca853deeSEric Joyner #define IAVF_DEFAULT_RSS_HENA_BASE (\
176ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_NONF_IPV4_UDP) | \
177ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_NONF_IPV4_TCP) | \
178ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_NONF_IPV4_SCTP) | \
179ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_NONF_IPV4_OTHER) | \
180ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_FRAG_IPV4) | \
181ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_NONF_IPV6_UDP) | \
182ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_NONF_IPV6_TCP) | \
183ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_NONF_IPV6_SCTP) | \
184ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_NONF_IPV6_OTHER) | \
185ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_FRAG_IPV6))
186ca853deeSEric Joyner
187ca853deeSEric Joyner #define IAVF_DEFAULT_ADV_RSS_HENA (\
188ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) | \
189ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) | \
190ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | \
191ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) | \
192ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK) | \
193ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK))
194ca853deeSEric Joyner
195ca853deeSEric Joyner #define IAVF_DEFAULT_RSS_HENA_XL710 (\
196ca853deeSEric Joyner IAVF_DEFAULT_RSS_HENA_BASE | \
197ca853deeSEric Joyner BIT_ULL(IAVF_FILTER_PCTYPE_L2_PAYLOAD))
198ca853deeSEric Joyner
199ca853deeSEric Joyner #define IAVF_DEFAULT_RSS_HENA_X722 (\
200ca853deeSEric Joyner IAVF_DEFAULT_RSS_HENA_XL710 | \
201ca853deeSEric Joyner IAVF_DEFAULT_ADV_RSS_HENA)
202ca853deeSEric Joyner
203ca853deeSEric Joyner #define IAVF_DEFAULT_RSS_HENA_AVF (\
204ca853deeSEric Joyner IAVF_DEFAULT_RSS_HENA_BASE | \
205ca853deeSEric Joyner IAVF_DEFAULT_ADV_RSS_HENA)
206ca853deeSEric Joyner
207ca853deeSEric Joyner /* For stats sysctl naming */
208ca853deeSEric Joyner #define IAVF_QUEUE_NAME_LEN 32
209ca853deeSEric Joyner
210ca853deeSEric Joyner #define IAVF_FLAG_AQ_ENABLE_QUEUES (u32)(1 << 0)
211ca853deeSEric Joyner #define IAVF_FLAG_AQ_DISABLE_QUEUES (u32)(1 << 1)
212ca853deeSEric Joyner #define IAVF_FLAG_AQ_ADD_MAC_FILTER (u32)(1 << 2)
213ca853deeSEric Joyner #define IAVF_FLAG_AQ_ADD_VLAN_FILTER (u32)(1 << 3)
214ca853deeSEric Joyner #define IAVF_FLAG_AQ_DEL_MAC_FILTER (u32)(1 << 4)
215ca853deeSEric Joyner #define IAVF_FLAG_AQ_DEL_VLAN_FILTER (u32)(1 << 5)
216ca853deeSEric Joyner #define IAVF_FLAG_AQ_CONFIGURE_QUEUES (u32)(1 << 6)
217ca853deeSEric Joyner #define IAVF_FLAG_AQ_MAP_VECTORS (u32)(1 << 7)
218ca853deeSEric Joyner #define IAVF_FLAG_AQ_HANDLE_RESET (u32)(1 << 8)
219ca853deeSEric Joyner #define IAVF_FLAG_AQ_CONFIGURE_PROMISC (u32)(1 << 9)
220ca853deeSEric Joyner #define IAVF_FLAG_AQ_GET_STATS (u32)(1 << 10)
221ca853deeSEric Joyner #define IAVF_FLAG_AQ_CONFIG_RSS_KEY (u32)(1 << 11)
222ca853deeSEric Joyner #define IAVF_FLAG_AQ_SET_RSS_HENA (u32)(1 << 12)
223ca853deeSEric Joyner #define IAVF_FLAG_AQ_GET_RSS_HENA_CAPS (u32)(1 << 13)
224ca853deeSEric Joyner #define IAVF_FLAG_AQ_CONFIG_RSS_LUT (u32)(1 << 14)
225ca853deeSEric Joyner
226ca853deeSEric Joyner #define IAVF_CAP_ADV_LINK_SPEED(_sc) \
227ca853deeSEric Joyner ((_sc)->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
228ca853deeSEric Joyner
229ca853deeSEric Joyner #define IAVF_NRXQS(_vsi) ((_vsi)->num_rx_queues)
230ca853deeSEric Joyner #define IAVF_NTXQS(_vsi) ((_vsi)->num_tx_queues)
231ca853deeSEric Joyner
232ca853deeSEric Joyner /**
233ca853deeSEric Joyner * printf %b flag args
234ca853deeSEric Joyner */
235ca853deeSEric Joyner #define IAVF_FLAGS \
236ca853deeSEric Joyner "\20\1ENABLE_QUEUES\2DISABLE_QUEUES\3ADD_MAC_FILTER" \
237ca853deeSEric Joyner "\4ADD_VLAN_FILTER\5DEL_MAC_FILTER\6DEL_VLAN_FILTER" \
238ca853deeSEric Joyner "\7CONFIGURE_QUEUES\10MAP_VECTORS\11HANDLE_RESET" \
239ca853deeSEric Joyner "\12CONFIGURE_PROMISC\13GET_STATS\14CONFIG_RSS_KEY" \
240ca853deeSEric Joyner "\15SET_RSS_HENA\16GET_RSS_HENA_CAPS\17CONFIG_RSS_LUT"
241ca853deeSEric Joyner /**
242ca853deeSEric Joyner * printf %b flag args for offloads from virtchnl.h
243ca853deeSEric Joyner */
244ca853deeSEric Joyner #define IAVF_PRINTF_VF_OFFLOAD_FLAGS \
245ca853deeSEric Joyner "\20\1L2" \
246ca853deeSEric Joyner "\2IWARP" \
247ca853deeSEric Joyner "\3FCOE" \
248ca853deeSEric Joyner "\4RSS_AQ" \
249ca853deeSEric Joyner "\5RSS_REG" \
250ca853deeSEric Joyner "\6WB_ON_ITR" \
251ca853deeSEric Joyner "\7REQ_QUEUES" \
252ca853deeSEric Joyner "\10ADV_LINK_SPEED" \
253ca853deeSEric Joyner "\21VLAN" \
254ca853deeSEric Joyner "\22RX_POLLING" \
255ca853deeSEric Joyner "\23RSS_PCTYPE_V2" \
256ca853deeSEric Joyner "\24RSS_PF" \
257ca853deeSEric Joyner "\25ENCAP" \
258ca853deeSEric Joyner "\26ENCAP_CSUM" \
259ca853deeSEric Joyner "\27RX_ENCAP_CSUM" \
260ca853deeSEric Joyner "\30ADQ"
261ca853deeSEric Joyner
262ca853deeSEric Joyner /**
263ca853deeSEric Joyner * @enum iavf_ext_link_speed
264ca853deeSEric Joyner * @brief Extended link speed enumeration
265ca853deeSEric Joyner *
266ca853deeSEric Joyner * Enumeration of possible link speeds that the device could be operating in.
267ca853deeSEric Joyner * Contains an extended list compared to the virtchnl_link_speed, including
268ca853deeSEric Joyner * additional higher speeds such as 50GB, and 100GB.
269ca853deeSEric Joyner *
270ca853deeSEric Joyner * The enumeration is used to convert between the old virtchnl_link_speed, the
271ca853deeSEric Joyner * newer advanced speed reporting value specified in Mb/s, and the ifmedia
272ca853deeSEric Joyner * link speeds reported to the operating system.
273ca853deeSEric Joyner */
274ca853deeSEric Joyner enum iavf_ext_link_speed {
275ca853deeSEric Joyner IAVF_EXT_LINK_SPEED_UNKNOWN,
276ca853deeSEric Joyner IAVF_EXT_LINK_SPEED_10MB,
277ca853deeSEric Joyner IAVF_EXT_LINK_SPEED_100MB,
278ca853deeSEric Joyner IAVF_EXT_LINK_SPEED_1000MB,
279ca853deeSEric Joyner IAVF_EXT_LINK_SPEED_2500MB,
280ca853deeSEric Joyner IAVF_EXT_LINK_SPEED_5GB,
281ca853deeSEric Joyner IAVF_EXT_LINK_SPEED_10GB,
282ca853deeSEric Joyner IAVF_EXT_LINK_SPEED_20GB,
283ca853deeSEric Joyner IAVF_EXT_LINK_SPEED_25GB,
284ca853deeSEric Joyner IAVF_EXT_LINK_SPEED_40GB,
285ca853deeSEric Joyner IAVF_EXT_LINK_SPEED_50GB,
286ca853deeSEric Joyner IAVF_EXT_LINK_SPEED_100GB,
287ca853deeSEric Joyner };
288ca853deeSEric Joyner
289ca853deeSEric Joyner /**
290ca853deeSEric Joyner * @struct iavf_sysctl_info
291ca853deeSEric Joyner * @brief sysctl statistic info
292ca853deeSEric Joyner *
293ca853deeSEric Joyner * Structure describing a single statistics sysctl, used for reporting
294ca853deeSEric Joyner * specific hardware and software statistics via the sysctl interface.
295ca853deeSEric Joyner */
296ca853deeSEric Joyner struct iavf_sysctl_info {
297ca853deeSEric Joyner u64 *stat;
298ca853deeSEric Joyner char *name;
299ca853deeSEric Joyner char *description;
300ca853deeSEric Joyner };
301ca853deeSEric Joyner
302ca853deeSEric Joyner /* Forward struct declarations */
303ca853deeSEric Joyner struct iavf_sc;
304ca853deeSEric Joyner struct iavf_vsi;
305ca853deeSEric Joyner
306ca853deeSEric Joyner /**
307ca853deeSEric Joyner * @enum iavf_state
308ca853deeSEric Joyner * @brief Driver state flags
309ca853deeSEric Joyner *
310ca853deeSEric Joyner * Used to indicate the status of various driver events. Intended to be
311ca853deeSEric Joyner * modified only using atomic operations, so that we can use it even in places
312ca853deeSEric Joyner * which aren't locked.
313ca853deeSEric Joyner */
314ca853deeSEric Joyner enum iavf_state {
315ca853deeSEric Joyner IAVF_STATE_INITIALIZED,
316ca853deeSEric Joyner IAVF_STATE_RESET_REQUIRED,
317ca853deeSEric Joyner IAVF_STATE_RESET_PENDING,
318ca853deeSEric Joyner IAVF_STATE_RUNNING,
319ca853deeSEric Joyner /* This entry must be last */
320ca853deeSEric Joyner IAVF_STATE_LAST,
321ca853deeSEric Joyner };
322ca853deeSEric Joyner
323ca853deeSEric Joyner /* Functions for setting and checking driver state. Note the functions take
324ca853deeSEric Joyner * bit positions, not bitmasks. The atomic_testandset_32 and
325ca853deeSEric Joyner * atomic_testandclear_32 operations require bit positions, while the
326ca853deeSEric Joyner * atomic_set_32 and atomic_clear_32 require bitmasks. This can easily lead to
327ca853deeSEric Joyner * programming error, so we provide wrapper functions to avoid this.
328ca853deeSEric Joyner */
329ca853deeSEric Joyner
330ca853deeSEric Joyner /**
331ca853deeSEric Joyner * iavf_set_state - Set the specified state
332ca853deeSEric Joyner * @s: the state bitmap
333ca853deeSEric Joyner * @bit: the state to set
334ca853deeSEric Joyner *
335ca853deeSEric Joyner * Atomically update the state bitmap with the specified bit set.
336ca853deeSEric Joyner */
337ca853deeSEric Joyner static inline void
iavf_set_state(volatile u32 * s,enum iavf_state bit)338ca853deeSEric Joyner iavf_set_state(volatile u32 *s, enum iavf_state bit)
339ca853deeSEric Joyner {
340ca853deeSEric Joyner /* atomic_set_32 expects a bitmask */
341ca853deeSEric Joyner atomic_set_32(s, BIT(bit));
342ca853deeSEric Joyner }
343ca853deeSEric Joyner
344ca853deeSEric Joyner /**
345ca853deeSEric Joyner * iavf_clear_state - Clear the specified state
346ca853deeSEric Joyner * @s: the state bitmap
347ca853deeSEric Joyner * @bit: the state to clear
348ca853deeSEric Joyner *
349ca853deeSEric Joyner * Atomically update the state bitmap with the specified bit cleared.
350ca853deeSEric Joyner */
351ca853deeSEric Joyner static inline void
iavf_clear_state(volatile u32 * s,enum iavf_state bit)352ca853deeSEric Joyner iavf_clear_state(volatile u32 *s, enum iavf_state bit)
353ca853deeSEric Joyner {
354ca853deeSEric Joyner /* atomic_clear_32 expects a bitmask */
355ca853deeSEric Joyner atomic_clear_32(s, BIT(bit));
356ca853deeSEric Joyner }
357ca853deeSEric Joyner
358ca853deeSEric Joyner /**
359ca853deeSEric Joyner * iavf_testandset_state - Test and set the specified state
360ca853deeSEric Joyner * @s: the state bitmap
361ca853deeSEric Joyner * @bit: the bit to test
362ca853deeSEric Joyner *
363ca853deeSEric Joyner * Atomically update the state bitmap, setting the specified bit.
364ca853deeSEric Joyner *
365ca853deeSEric Joyner * @returns the previous value of the bit.
366ca853deeSEric Joyner */
367ca853deeSEric Joyner static inline u32
iavf_testandset_state(volatile u32 * s,enum iavf_state bit)368ca853deeSEric Joyner iavf_testandset_state(volatile u32 *s, enum iavf_state bit)
369ca853deeSEric Joyner {
370ca853deeSEric Joyner /* atomic_testandset_32 expects a bit position */
371ca853deeSEric Joyner return atomic_testandset_32(s, bit);
372ca853deeSEric Joyner }
373ca853deeSEric Joyner
374ca853deeSEric Joyner /**
375ca853deeSEric Joyner * iavf_testandclear_state - Test and clear the specified state
376ca853deeSEric Joyner * @s: the state bitmap
377ca853deeSEric Joyner * @bit: the bit to test
378ca853deeSEric Joyner *
379ca853deeSEric Joyner * Atomically update the state bitmap, clearing the specified bit.
380ca853deeSEric Joyner *
381ca853deeSEric Joyner * @returns the previous value of the bit.
382ca853deeSEric Joyner */
383ca853deeSEric Joyner static inline u32
iavf_testandclear_state(volatile u32 * s,enum iavf_state bit)384ca853deeSEric Joyner iavf_testandclear_state(volatile u32 *s, enum iavf_state bit)
385ca853deeSEric Joyner {
386ca853deeSEric Joyner /* atomic_testandclear_32 expects a bit position */
387ca853deeSEric Joyner return atomic_testandclear_32(s, bit);
388ca853deeSEric Joyner }
389ca853deeSEric Joyner
390ca853deeSEric Joyner /**
391ca853deeSEric Joyner * iavf_test_state - Test the specified state
392ca853deeSEric Joyner * @s: the state bitmap
393ca853deeSEric Joyner * @bit: the bit to test
394ca853deeSEric Joyner *
395ca853deeSEric Joyner * @returns true if the state is set, false otherwise.
396ca853deeSEric Joyner *
397ca853deeSEric Joyner * @remark Use this only if the flow does not need to update the state. If you
398ca853deeSEric Joyner * must update the state as well, prefer iavf_testandset_state or
399ca853deeSEric Joyner * iavf_testandclear_state.
400ca853deeSEric Joyner */
401ca853deeSEric Joyner static inline u32
iavf_test_state(volatile u32 * s,enum iavf_state bit)402ca853deeSEric Joyner iavf_test_state(volatile u32 *s, enum iavf_state bit)
403ca853deeSEric Joyner {
404ca853deeSEric Joyner return (*s & BIT(bit)) ? true : false;
405ca853deeSEric Joyner }
406ca853deeSEric Joyner
407ca853deeSEric Joyner /**
408ca853deeSEric Joyner * cmp_etheraddr - Compare two ethernet addresses
409ca853deeSEric Joyner * @ea1: first ethernet address
410ca853deeSEric Joyner * @ea2: second ethernet address
411ca853deeSEric Joyner *
412ca853deeSEric Joyner * Compares two ethernet addresses.
413ca853deeSEric Joyner *
414ca853deeSEric Joyner * @returns true if the addresses are equal, false otherwise.
415ca853deeSEric Joyner */
416ca853deeSEric Joyner static inline bool
cmp_etheraddr(const u8 * ea1,const u8 * ea2)417ca853deeSEric Joyner cmp_etheraddr(const u8 *ea1, const u8 *ea2)
418ca853deeSEric Joyner {
419ca853deeSEric Joyner bool cmp = FALSE;
420ca853deeSEric Joyner
421ca853deeSEric Joyner if ((ea1[0] == ea2[0]) && (ea1[1] == ea2[1]) &&
422ca853deeSEric Joyner (ea1[2] == ea2[2]) && (ea1[3] == ea2[3]) &&
423ca853deeSEric Joyner (ea1[4] == ea2[4]) && (ea1[5] == ea2[5]))
424ca853deeSEric Joyner cmp = TRUE;
425ca853deeSEric Joyner
426ca853deeSEric Joyner return (cmp);
427ca853deeSEric Joyner }
428ca853deeSEric Joyner
429ca853deeSEric Joyner int iavf_send_vc_msg(struct iavf_sc *sc, u32 op);
430ca853deeSEric Joyner int iavf_send_vc_msg_sleep(struct iavf_sc *sc, u32 op);
431ca853deeSEric Joyner void iavf_update_link_status(struct iavf_sc *);
432ca853deeSEric Joyner bool iavf_driver_is_detaching(struct iavf_sc *sc);
433ca853deeSEric Joyner void iavf_msec_pause(int msecs);
434ca853deeSEric Joyner void iavf_get_default_rss_key(u32 *key);
435ca853deeSEric Joyner int iavf_allocate_pci_resources_common(struct iavf_sc *sc);
436ca853deeSEric Joyner int iavf_reset_complete(struct iavf_hw *hw);
437ca853deeSEric Joyner int iavf_setup_vc(struct iavf_sc *sc);
438ca853deeSEric Joyner int iavf_reset(struct iavf_sc *sc);
439ca853deeSEric Joyner void iavf_enable_adminq_irq(struct iavf_hw *hw);
440ca853deeSEric Joyner void iavf_disable_adminq_irq(struct iavf_hw *hw);
441ca853deeSEric Joyner int iavf_vf_config(struct iavf_sc *sc);
442ca853deeSEric Joyner void iavf_print_device_info(struct iavf_sc *sc);
443ca853deeSEric Joyner int iavf_get_vsi_res_from_vf_res(struct iavf_sc *sc);
444ca853deeSEric Joyner void iavf_set_mac_addresses(struct iavf_sc *sc);
445ca853deeSEric Joyner void iavf_init_filters(struct iavf_sc *sc);
446ca853deeSEric Joyner void iavf_free_filters(struct iavf_sc *sc);
447ca853deeSEric Joyner void iavf_add_device_sysctls_common(struct iavf_sc *sc);
448ca853deeSEric Joyner void iavf_configure_tx_itr(struct iavf_sc *sc);
449ca853deeSEric Joyner void iavf_configure_rx_itr(struct iavf_sc *sc);
450ca853deeSEric Joyner struct sysctl_oid_list *
451ca853deeSEric Joyner iavf_create_debug_sysctl_tree(struct iavf_sc *sc);
452ca853deeSEric Joyner void iavf_add_debug_sysctls_common(struct iavf_sc *sc,
453ca853deeSEric Joyner struct sysctl_oid_list *debug_list);
454ca853deeSEric Joyner void iavf_add_vsi_sysctls(device_t dev, struct iavf_vsi *vsi,
455ca853deeSEric Joyner struct sysctl_ctx_list *ctx, const char *sysctl_name);
456ca853deeSEric Joyner void iavf_add_sysctls_eth_stats(struct sysctl_ctx_list *ctx,
457ca853deeSEric Joyner struct sysctl_oid_list *child, struct iavf_eth_stats *eth_stats);
458ca853deeSEric Joyner void iavf_media_status_common(struct iavf_sc *sc,
459ca853deeSEric Joyner struct ifmediareq *ifmr);
460*d8096b2dSJustin Hibbits int iavf_media_change_common(if_t ifp);
461*d8096b2dSJustin Hibbits void iavf_set_initial_baudrate(if_t ifp);
462ca853deeSEric Joyner u64 iavf_max_vc_speed_to_value(u8 link_speeds);
463ca853deeSEric Joyner void iavf_config_rss_reg(struct iavf_sc *sc);
464ca853deeSEric Joyner void iavf_config_rss_pf(struct iavf_sc *sc);
465ca853deeSEric Joyner void iavf_config_rss(struct iavf_sc *sc);
466ca853deeSEric Joyner int iavf_config_promisc(struct iavf_sc *sc, int flags);
467ca853deeSEric Joyner void iavf_init_multi(struct iavf_sc *sc);
468ca853deeSEric Joyner void iavf_multi_set(struct iavf_sc *sc);
469ca853deeSEric Joyner int iavf_add_mac_filter(struct iavf_sc *sc, u8 *macaddr, u16 flags);
470ca853deeSEric Joyner struct iavf_mac_filter *
471ca853deeSEric Joyner iavf_find_mac_filter(struct iavf_sc *sc, u8 *macaddr);
472ca853deeSEric Joyner struct iavf_mac_filter *
473ca853deeSEric Joyner iavf_get_mac_filter(struct iavf_sc *sc);
474ca853deeSEric Joyner u64 iavf_baudrate_from_link_speed(struct iavf_sc *sc);
475ca853deeSEric Joyner void iavf_add_vlan_filter(struct iavf_sc *sc, u16 vtag);
476ca853deeSEric Joyner int iavf_mark_del_vlan_filter(struct iavf_sc *sc, u16 vtag);
477ca853deeSEric Joyner void iavf_update_msix_devinfo(device_t dev);
478ca853deeSEric Joyner void iavf_disable_queues_with_retries(struct iavf_sc *);
479ca853deeSEric Joyner
480ca853deeSEric Joyner int iavf_sysctl_current_speed(SYSCTL_HANDLER_ARGS);
481ca853deeSEric Joyner int iavf_sysctl_tx_itr(SYSCTL_HANDLER_ARGS);
482ca853deeSEric Joyner int iavf_sysctl_rx_itr(SYSCTL_HANDLER_ARGS);
483ca853deeSEric Joyner int iavf_sysctl_sw_filter_list(SYSCTL_HANDLER_ARGS);
484ca853deeSEric Joyner
485ca853deeSEric Joyner #endif /* _IAVF_LIB_H_ */
486