Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2017 Intel Corporation
3 : : */
4 : :
5 : : #include <ctype.h>
6 : : #include <sys/queue.h>
7 : : #include <stdalign.h>
8 : : #include <stdio.h>
9 : : #include <errno.h>
10 : : #include <stdint.h>
11 : : #include <string.h>
12 : : #include <unistd.h>
13 : : #include <stdarg.h>
14 : : #include <inttypes.h>
15 : : #include <rte_byteorder.h>
16 : : #include <rte_common.h>
17 : : #include <rte_os_shim.h>
18 : :
19 : : #include <rte_interrupts.h>
20 : : #include <rte_debug.h>
21 : : #include <rte_pci.h>
22 : : #include <rte_alarm.h>
23 : : #include <rte_atomic.h>
24 : : #include <rte_cycles.h>
25 : : #include <rte_eal.h>
26 : : #include <rte_ether.h>
27 : : #include <ethdev_driver.h>
28 : : #include <ethdev_pci.h>
29 : : #include <rte_malloc.h>
30 : : #include <rte_memzone.h>
31 : : #include <dev_driver.h>
32 : : #include <eal_export.h>
33 : :
34 : : #include "iavf.h"
35 : : #include "iavf_rxtx.h"
36 : : #include "iavf_generic_flow.h"
37 : : #include "rte_pmd_iavf.h"
38 : : #include "iavf_ipsec_crypto.h"
39 : :
40 : : /* devargs */
41 : : #define IAVF_PROTO_XTR_ARG "proto_xtr"
42 : : #define IAVF_QUANTA_SIZE_ARG "quanta_size"
43 : : #define IAVF_RESET_WATCHDOG_ARG "watchdog_period"
44 : : #define IAVF_ENABLE_AUTO_RESET_ARG "auto_reset"
45 : : #define IAVF_ENABLE_AUTO_RECONFIG_ARG "auto_reconfig"
46 : : #define IAVF_NO_POLL_ON_LINK_DOWN_ARG "no-poll-on-link-down"
47 : : #define IAVF_MBUF_CHECK_ARG "mbuf_check"
48 : : #define IAVF_ENABLE_PTYPE_LLDP_ARG "enable_ptype_lldp"
49 : : uint64_t iavf_timestamp_dynflag;
50 : : int iavf_timestamp_dynfield_offset = -1;
51 : : int rte_pmd_iavf_tx_lldp_dynfield_offset = -1;
52 : :
53 : : static const char * const iavf_valid_args[] = {
54 : : IAVF_PROTO_XTR_ARG,
55 : : IAVF_QUANTA_SIZE_ARG,
56 : : IAVF_RESET_WATCHDOG_ARG,
57 : : IAVF_ENABLE_AUTO_RESET_ARG,
58 : : IAVF_ENABLE_AUTO_RECONFIG_ARG,
59 : : IAVF_NO_POLL_ON_LINK_DOWN_ARG,
60 : : IAVF_MBUF_CHECK_ARG,
61 : : IAVF_ENABLE_PTYPE_LLDP_ARG,
62 : : NULL
63 : : };
64 : :
65 : : static const struct rte_mbuf_dynfield iavf_proto_xtr_metadata_param = {
66 : : .name = "intel_pmd_dynfield_proto_xtr_metadata",
67 : : .size = sizeof(uint32_t),
68 : : .align = alignof(uint32_t),
69 : : .flags = 0,
70 : : };
71 : :
72 : : struct iavf_proto_xtr_ol {
73 : : const struct rte_mbuf_dynflag param;
74 : : uint64_t *ol_flag;
75 : : bool required;
76 : : };
77 : :
78 : : static struct iavf_proto_xtr_ol iavf_proto_xtr_params[] = {
79 : : [IAVF_PROTO_XTR_VLAN] = {
80 : : .param = { .name = "intel_pmd_dynflag_proto_xtr_vlan" },
81 : : .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_vlan_mask },
82 : : [IAVF_PROTO_XTR_IPV4] = {
83 : : .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv4" },
84 : : .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_ipv4_mask },
85 : : [IAVF_PROTO_XTR_IPV6] = {
86 : : .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv6" },
87 : : .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_ipv6_mask },
88 : : [IAVF_PROTO_XTR_IPV6_FLOW] = {
89 : : .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv6_flow" },
90 : : .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_ipv6_flow_mask },
91 : : [IAVF_PROTO_XTR_TCP] = {
92 : : .param = { .name = "intel_pmd_dynflag_proto_xtr_tcp" },
93 : : .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_tcp_mask },
94 : : [IAVF_PROTO_XTR_IP_OFFSET] = {
95 : : .param = { .name = "intel_pmd_dynflag_proto_xtr_ip_offset" },
96 : : .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_ip_offset_mask },
97 : : [IAVF_PROTO_XTR_IPSEC_CRYPTO_SAID] = {
98 : : .param = {
99 : : .name = "intel_pmd_dynflag_proto_xtr_ipsec_crypto_said" },
100 : : .ol_flag =
101 : : &rte_pmd_ifd_dynflag_proto_xtr_ipsec_crypto_said_mask },
102 : : };
103 : :
104 : : static int iavf_dev_configure(struct rte_eth_dev *dev);
105 : : static int iavf_dev_start(struct rte_eth_dev *dev);
106 : : static int iavf_dev_stop(struct rte_eth_dev *dev);
107 : : static int iavf_dev_close(struct rte_eth_dev *dev);
108 : : static int iavf_dev_reset(struct rte_eth_dev *dev);
109 : : static bool iavf_is_reset_detected(struct iavf_adapter *adapter);
110 : : static int iavf_dev_info_get(struct rte_eth_dev *dev,
111 : : struct rte_eth_dev_info *dev_info);
112 : : static const uint32_t *iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev,
113 : : size_t *no_of_elements);
114 : : static int iavf_dev_stats_get(struct rte_eth_dev *dev,
115 : : struct rte_eth_stats *stats, struct eth_queue_stats *qstats);
116 : : static int iavf_dev_stats_reset(struct rte_eth_dev *dev);
117 : : static int iavf_dev_xstats_reset(struct rte_eth_dev *dev);
118 : : static int iavf_dev_xstats_get(struct rte_eth_dev *dev,
119 : : struct rte_eth_xstat *xstats, unsigned int n);
120 : : static int iavf_dev_xstats_get_names(struct rte_eth_dev *dev,
121 : : struct rte_eth_xstat_name *xstats_names,
122 : : unsigned int limit);
123 : : static int iavf_dev_promiscuous_enable(struct rte_eth_dev *dev);
124 : : static int iavf_dev_promiscuous_disable(struct rte_eth_dev *dev);
125 : : static int iavf_dev_allmulticast_enable(struct rte_eth_dev *dev);
126 : : static int iavf_dev_allmulticast_disable(struct rte_eth_dev *dev);
127 : : static int iavf_dev_add_mac_addr(struct rte_eth_dev *dev,
128 : : struct rte_ether_addr *addr,
129 : : uint32_t index,
130 : : uint32_t pool);
131 : : static void iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index);
132 : : static int iavf_dev_vlan_filter_set(struct rte_eth_dev *dev,
133 : : uint16_t vlan_id, int on);
134 : : static int iavf_vlan_tpid_set(struct rte_eth_dev *dev,
135 : : enum rte_vlan_type vlan_type, uint16_t tpid);
136 : : static int iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask);
137 : : static int iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
138 : : struct rte_eth_rss_reta_entry64 *reta_conf,
139 : : uint16_t reta_size);
140 : : static int iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
141 : : struct rte_eth_rss_reta_entry64 *reta_conf,
142 : : uint16_t reta_size);
143 : : static int iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
144 : : struct rte_eth_rss_conf *rss_conf);
145 : : static int iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
146 : : struct rte_eth_rss_conf *rss_conf);
147 : : static int iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
148 : : static int iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
149 : : struct rte_ether_addr *mac_addr);
150 : : static int iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
151 : : uint16_t queue_id);
152 : : static int iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
153 : : uint16_t queue_id);
154 : : static void iavf_dev_interrupt_handler(void *param);
155 : : static void iavf_disable_irq0(struct iavf_hw *hw);
156 : : static struct ci_rx_queue *iavf_phc_sync_rxq_get(struct rte_eth_dev *dev);
157 : : static void iavf_phc_sync_update_all_rxq(struct rte_eth_dev *dev,
158 : : uint64_t phc_time,
159 : : uint64_t sw_cur_time);
160 : : static bool iavf_phc_sync_alarm_needed(struct rte_eth_dev *dev);
161 : : static void iavf_phc_sync_tick(struct rte_eth_dev *dev);
162 : : static int iavf_dev_flow_ops_get(struct rte_eth_dev *dev,
163 : : const struct rte_flow_ops **ops);
164 : : static int iavf_set_mc_addr_list(struct rte_eth_dev *dev,
165 : : struct rte_ether_addr *mc_addrs,
166 : : uint32_t mc_addrs_num);
167 : : static int iavf_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg);
168 : :
169 : : static const struct rte_pci_id pci_id_iavf_map[] = {
170 : : { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
171 : : { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_VF) },
172 : : { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_VF_HV) },
173 : : { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_X722_VF) },
174 : : { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_X722_A0_VF) },
175 : : { .vendor_id = 0, /* sentinel */ },
176 : : };
177 : :
178 : : struct rte_iavf_xstats_name_off {
179 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
180 : : unsigned int offset;
181 : : };
182 : :
183 : : #define _OFF_OF(a) offsetof(struct iavf_eth_xstats, a)
184 : : static const struct rte_iavf_xstats_name_off rte_iavf_stats_strings[] = {
185 : : {"rx_bytes", _OFF_OF(eth_stats.rx_bytes)},
186 : : {"rx_unicast_packets", _OFF_OF(eth_stats.rx_unicast)},
187 : : {"rx_multicast_packets", _OFF_OF(eth_stats.rx_multicast)},
188 : : {"rx_broadcast_packets", _OFF_OF(eth_stats.rx_broadcast)},
189 : : {"rx_dropped_packets", _OFF_OF(eth_stats.rx_discards)},
190 : : {"rx_unknown_protocol_packets", offsetof(struct iavf_eth_stats,
191 : : rx_unknown_protocol)},
192 : : {"tx_bytes", _OFF_OF(eth_stats.tx_bytes)},
193 : : {"tx_unicast_packets", _OFF_OF(eth_stats.tx_unicast)},
194 : : {"tx_multicast_packets", _OFF_OF(eth_stats.tx_multicast)},
195 : : {"tx_broadcast_packets", _OFF_OF(eth_stats.tx_broadcast)},
196 : : {"tx_dropped_packets", _OFF_OF(eth_stats.tx_discards)},
197 : : {"tx_error_packets", _OFF_OF(eth_stats.tx_errors)},
198 : : {"tx_mbuf_error_packets", _OFF_OF(mbuf_stats.tx_pkt_errors)},
199 : :
200 : : {"inline_ipsec_crypto_ipackets", _OFF_OF(ips_stats.icount)},
201 : : {"inline_ipsec_crypto_ibytes", _OFF_OF(ips_stats.ibytes)},
202 : : {"inline_ipsec_crypto_ierrors", _OFF_OF(ips_stats.ierrors.count)},
203 : : {"inline_ipsec_crypto_ierrors_sad_lookup",
204 : : _OFF_OF(ips_stats.ierrors.sad_miss)},
205 : : {"inline_ipsec_crypto_ierrors_not_processed",
206 : : _OFF_OF(ips_stats.ierrors.not_processed)},
207 : : {"inline_ipsec_crypto_ierrors_icv_fail",
208 : : _OFF_OF(ips_stats.ierrors.icv_check)},
209 : : {"inline_ipsec_crypto_ierrors_length",
210 : : _OFF_OF(ips_stats.ierrors.ipsec_length)},
211 : : {"inline_ipsec_crypto_ierrors_misc",
212 : : _OFF_OF(ips_stats.ierrors.misc)},
213 : : };
214 : : #undef _OFF_OF
215 : :
216 : : #define IAVF_NB_XSTATS (sizeof(rte_iavf_stats_strings) / \
217 : : sizeof(rte_iavf_stats_strings[0]))
218 : :
219 : : static const struct eth_dev_ops iavf_eth_dev_ops = {
220 : : .dev_configure = iavf_dev_configure,
221 : : .dev_start = iavf_dev_start,
222 : : .dev_stop = iavf_dev_stop,
223 : : .dev_close = iavf_dev_close,
224 : : .dev_reset = iavf_dev_reset,
225 : : .dev_infos_get = iavf_dev_info_get,
226 : : .dev_supported_ptypes_get = iavf_dev_supported_ptypes_get,
227 : : .link_update = iavf_dev_link_update,
228 : : .stats_get = iavf_dev_stats_get,
229 : : .stats_reset = iavf_dev_stats_reset,
230 : : .xstats_get = iavf_dev_xstats_get,
231 : : .xstats_get_names = iavf_dev_xstats_get_names,
232 : : .xstats_reset = iavf_dev_xstats_reset,
233 : : .promiscuous_enable = iavf_dev_promiscuous_enable,
234 : : .promiscuous_disable = iavf_dev_promiscuous_disable,
235 : : .allmulticast_enable = iavf_dev_allmulticast_enable,
236 : : .allmulticast_disable = iavf_dev_allmulticast_disable,
237 : : .mac_addr_add = iavf_dev_add_mac_addr,
238 : : .mac_addr_remove = iavf_dev_del_mac_addr,
239 : : .set_mc_addr_list = iavf_set_mc_addr_list,
240 : : .vlan_filter_set = iavf_dev_vlan_filter_set,
241 : : .vlan_tpid_set = iavf_vlan_tpid_set,
242 : : .vlan_offload_set = iavf_dev_vlan_offload_set,
243 : : .rx_queue_start = iavf_dev_rx_queue_start,
244 : : .rx_queue_stop = iavf_dev_rx_queue_stop,
245 : : .tx_queue_start = iavf_dev_tx_queue_start,
246 : : .tx_queue_stop = iavf_dev_tx_queue_stop,
247 : : .rx_queue_setup = iavf_dev_rx_queue_setup,
248 : : .rx_queue_release = iavf_dev_rx_queue_release,
249 : : .tx_queue_setup = iavf_dev_tx_queue_setup,
250 : : .tx_queue_release = iavf_dev_tx_queue_release,
251 : : .mac_addr_set = iavf_dev_set_default_mac_addr,
252 : : .reta_update = iavf_dev_rss_reta_update,
253 : : .reta_query = iavf_dev_rss_reta_query,
254 : : .rss_hash_update = iavf_dev_rss_hash_update,
255 : : .rss_hash_conf_get = iavf_dev_rss_hash_conf_get,
256 : : .rxq_info_get = iavf_dev_rxq_info_get,
257 : : .txq_info_get = iavf_dev_txq_info_get,
258 : : .rx_burst_mode_get = iavf_rx_burst_mode_get,
259 : : .tx_burst_mode_get = iavf_tx_burst_mode_get,
260 : : .mtu_set = iavf_dev_mtu_set,
261 : : .rx_queue_intr_enable = iavf_dev_rx_queue_intr_enable,
262 : : .rx_queue_intr_disable = iavf_dev_rx_queue_intr_disable,
263 : : .flow_ops_get = iavf_dev_flow_ops_get,
264 : : .tx_done_cleanup = iavf_dev_tx_done_cleanup,
265 : : .get_monitor_addr = iavf_get_monitor_addr,
266 : : .tm_ops_get = iavf_tm_ops_get,
267 : : };
268 : :
269 : : static int
270 : 0 : iavf_tm_ops_get(struct rte_eth_dev *dev,
271 : : void *arg)
272 : : {
273 : 0 : struct iavf_adapter *adapter =
274 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
275 : :
276 [ # # ]: 0 : if (adapter->closed)
277 : : return -EIO;
278 : :
279 [ # # ]: 0 : if (!arg)
280 : : return -EINVAL;
281 : :
282 : 0 : *(const void **)arg = &iavf_tm_ops;
283 : :
284 : 0 : return 0;
285 : : }
286 : :
287 : : __rte_unused
288 : : static int
289 : 0 : iavf_vfr_inprogress(struct iavf_hw *hw)
290 : : {
291 : : int inprogress = 0;
292 : :
293 [ # # ]: 0 : if ((IAVF_READ_REG(hw, IAVF_VFGEN_RSTAT) &
294 : : IAVF_VFGEN_RSTAT_VFR_STATE_MASK) ==
295 : : VIRTCHNL_VFR_INPROGRESS)
296 : : inprogress = 1;
297 : :
298 : : if (inprogress)
299 : 0 : PMD_DRV_LOG(INFO, "Watchdog detected VFR in progress");
300 : :
301 : 0 : return inprogress;
302 : : }
303 : :
304 : : __rte_unused
305 : : static void
306 : 0 : iavf_dev_watchdog(void *cb_arg)
307 : : {
308 : : struct iavf_adapter *adapter = cb_arg;
309 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
310 : : int vfr_inprogress = 0, rc = 0;
311 : :
312 : : /* check if watchdog has been disabled since last call */
313 [ # # ]: 0 : if (!adapter->vf.watchdog_enabled)
314 : : return;
315 : :
316 : : /* If in reset then poll vfr_inprogress register for completion */
317 [ # # ]: 0 : if (adapter->vf.vf_reset) {
318 : 0 : vfr_inprogress = iavf_vfr_inprogress(hw);
319 : :
320 [ # # ]: 0 : if (!vfr_inprogress) {
321 : 0 : PMD_DRV_LOG(INFO, "VF \"%s\" reset has completed",
322 : : adapter->vf.eth_dev->data->name);
323 : 0 : adapter->vf.vf_reset = false;
324 : 0 : iavf_set_no_poll(adapter, false);
325 : : }
326 : : /* If not in reset then poll vfr_inprogress register for VFLR event */
327 : : } else {
328 : 0 : vfr_inprogress = iavf_vfr_inprogress(hw);
329 : :
330 [ # # ]: 0 : if (vfr_inprogress) {
331 : 0 : PMD_DRV_LOG(INFO,
332 : : "VF \"%s\" reset event detected by watchdog",
333 : : adapter->vf.eth_dev->data->name);
334 : :
335 : : /* enter reset state with VFLR event */
336 : 0 : adapter->vf.vf_reset = true;
337 : 0 : iavf_set_no_poll(adapter, false);
338 : 0 : adapter->vf.link_up = false;
339 : :
340 : 0 : iavf_dev_event_post(adapter->vf.eth_dev, RTE_ETH_EVENT_INTR_RESET,
341 : : NULL, 0);
342 : : }
343 : : }
344 : :
345 [ # # ]: 0 : if (adapter->devargs.watchdog_period) {
346 : : /* re-alarm watchdog */
347 : 0 : rc = rte_eal_alarm_set(adapter->devargs.watchdog_period,
348 : : &iavf_dev_watchdog, cb_arg);
349 : :
350 [ # # ]: 0 : if (rc)
351 : 0 : PMD_DRV_LOG(ERR, "Failed \"%s\" to reset device watchdog alarm",
352 : : adapter->vf.eth_dev->data->name);
353 : : }
354 : : }
355 : :
356 : : void
357 : 0 : iavf_dev_watchdog_enable(struct iavf_adapter *adapter)
358 : : {
359 [ # # ]: 0 : if (!adapter->devargs.watchdog_period) {
360 : 0 : PMD_DRV_LOG(INFO, "Device watchdog is disabled");
361 : : } else {
362 [ # # ]: 0 : if (!adapter->vf.watchdog_enabled) {
363 : 0 : PMD_DRV_LOG(INFO, "Enabling device watchdog, period is %dμs",
364 : : adapter->devargs.watchdog_period);
365 : 0 : adapter->vf.watchdog_enabled = true;
366 [ # # ]: 0 : if (rte_eal_alarm_set(adapter->devargs.watchdog_period,
367 : : &iavf_dev_watchdog, (void *)adapter))
368 : 0 : PMD_DRV_LOG(ERR, "Failed to enable device watchdog");
369 : : }
370 : : }
371 : 0 : }
372 : :
373 : : void
374 : 0 : iavf_dev_watchdog_disable(struct iavf_adapter *adapter)
375 : : {
376 [ # # ]: 0 : if (!adapter->devargs.watchdog_period) {
377 : 0 : PMD_DRV_LOG(INFO, "Device watchdog is not enabled");
378 : : } else {
379 [ # # ]: 0 : if (adapter->vf.watchdog_enabled) {
380 : 0 : PMD_DRV_LOG(INFO, "Disabling device watchdog");
381 : 0 : adapter->vf.watchdog_enabled = false;
382 : 0 : rte_eal_alarm_cancel(&iavf_dev_watchdog, (void *)adapter);
383 : : }
384 : : }
385 : 0 : }
386 : :
387 : : static int
388 : 0 : iavf_set_mc_addr_list(struct rte_eth_dev *dev,
389 : : struct rte_ether_addr *mc_addrs,
390 : : uint32_t mc_addrs_num)
391 : : {
392 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
393 : : struct iavf_adapter *adapter =
394 : : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
395 : : int err, ret;
396 : :
397 [ # # ]: 0 : if (mc_addrs_num > IAVF_NUM_MACADDR_MAX) {
398 : 0 : PMD_DRV_LOG(ERR,
399 : : "can't add more than a limited number (%u) of addresses.",
400 : : (uint32_t)IAVF_NUM_MACADDR_MAX);
401 : 0 : return -EINVAL;
402 : : }
403 : :
404 [ # # ]: 0 : if (adapter->closed)
405 : : return -EIO;
406 : :
407 : : /* flush previous addresses */
408 : 0 : err = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
409 : : false);
410 [ # # ]: 0 : if (err)
411 : : return err;
412 : :
413 : : /* add new ones */
414 : 0 : err = iavf_add_del_mc_addr_list(adapter, mc_addrs, mc_addrs_num, true);
415 : :
416 [ # # ]: 0 : if (err) {
417 : : /* if adding mac address list fails, should add the previous
418 : : * addresses back.
419 : : */
420 : 0 : ret = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs,
421 : 0 : vf->mc_addrs_num, true);
422 [ # # ]: 0 : if (ret)
423 : 0 : return ret;
424 : : } else {
425 : 0 : vf->mc_addrs_num = mc_addrs_num;
426 : 0 : memcpy(vf->mc_addrs,
427 : : mc_addrs, mc_addrs_num * sizeof(*mc_addrs));
428 : : }
429 : :
430 : : return err;
431 : : }
432 : :
433 : : static void
434 : 0 : iavf_config_rss_hf(struct iavf_adapter *adapter, uint64_t rss_hf)
435 : : {
436 : : static const uint64_t map_hena_rss[] = {
437 : : /* IPv4 */
438 : : [IAVF_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
439 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP,
440 : : [IAVF_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
441 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP,
442 : : [IAVF_FILTER_PCTYPE_NONF_IPV4_UDP] =
443 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP,
444 : : [IAVF_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
445 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP,
446 : : [IAVF_FILTER_PCTYPE_NONF_IPV4_TCP] =
447 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP,
448 : : [IAVF_FILTER_PCTYPE_NONF_IPV4_SCTP] =
449 : : RTE_ETH_RSS_NONFRAG_IPV4_SCTP,
450 : : [IAVF_FILTER_PCTYPE_NONF_IPV4_OTHER] =
451 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
452 : : [IAVF_FILTER_PCTYPE_FRAG_IPV4] = RTE_ETH_RSS_FRAG_IPV4,
453 : :
454 : : /* IPv6 */
455 : : [IAVF_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
456 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP,
457 : : [IAVF_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
458 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP,
459 : : [IAVF_FILTER_PCTYPE_NONF_IPV6_UDP] =
460 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP,
461 : : [IAVF_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
462 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP,
463 : : [IAVF_FILTER_PCTYPE_NONF_IPV6_TCP] =
464 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP,
465 : : [IAVF_FILTER_PCTYPE_NONF_IPV6_SCTP] =
466 : : RTE_ETH_RSS_NONFRAG_IPV6_SCTP,
467 : : [IAVF_FILTER_PCTYPE_NONF_IPV6_OTHER] =
468 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
469 : : [IAVF_FILTER_PCTYPE_FRAG_IPV6] = RTE_ETH_RSS_FRAG_IPV6,
470 : :
471 : : /* L2 Payload */
472 : : [IAVF_FILTER_PCTYPE_L2_PAYLOAD] = RTE_ETH_RSS_L2_PAYLOAD
473 : : };
474 : :
475 : : const uint64_t ipv4_rss = RTE_ETH_RSS_NONFRAG_IPV4_UDP |
476 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP |
477 : : RTE_ETH_RSS_NONFRAG_IPV4_SCTP |
478 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER |
479 : : RTE_ETH_RSS_FRAG_IPV4;
480 : :
481 : : const uint64_t ipv6_rss = RTE_ETH_RSS_NONFRAG_IPV6_UDP |
482 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP |
483 : : RTE_ETH_RSS_NONFRAG_IPV6_SCTP |
484 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER |
485 : : RTE_ETH_RSS_FRAG_IPV6;
486 : :
487 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
488 : 0 : uint64_t caps = 0, hena = 0, valid_rss_hf = 0;
489 : : uint32_t i;
490 : : int ret;
491 : :
492 : 0 : ret = iavf_get_hena_caps(adapter, &caps);
493 [ # # ]: 0 : if (ret) {
494 : : /**
495 : : * RSS offload type configuration is not a necessary feature
496 : : * for VF, so here just print a warning and return.
497 : : */
498 : 0 : PMD_DRV_LOG(WARNING,
499 : : "fail to get RSS offload type caps, ret: %d", ret);
500 : 0 : return;
501 : : }
502 : :
503 : : /**
504 : : * RTE_ETH_RSS_IPV4 and RTE_ETH_RSS_IPV6 can be considered as 2
505 : : * generalizations of all other IPv4 and IPv6 RSS types.
506 : : */
507 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4)
508 : 0 : rss_hf |= ipv4_rss;
509 : :
510 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6)
511 : 0 : rss_hf |= ipv6_rss;
512 : :
513 : : RTE_BUILD_BUG_ON(RTE_DIM(map_hena_rss) > sizeof(uint64_t) * CHAR_BIT);
514 : :
515 [ # # ]: 0 : for (i = 0; i < RTE_DIM(map_hena_rss); i++) {
516 : 0 : uint64_t bit = BIT_ULL(i);
517 : :
518 [ # # # # ]: 0 : if ((caps & bit) && (map_hena_rss[i] & rss_hf)) {
519 : 0 : valid_rss_hf |= map_hena_rss[i];
520 : 0 : hena |= bit;
521 : : }
522 : : }
523 : :
524 : 0 : ret = iavf_set_hena(adapter, hena);
525 [ # # ]: 0 : if (ret) {
526 : : /**
527 : : * RSS offload type configuration is not a necessary feature
528 : : * for VF, so here just print a warning and return.
529 : : */
530 : 0 : PMD_DRV_LOG(WARNING,
531 : : "fail to set RSS offload types, ret: %d", ret);
532 : 0 : return;
533 : : }
534 : :
535 [ # # ]: 0 : if (valid_rss_hf & ipv4_rss)
536 : 0 : valid_rss_hf |= rss_hf & RTE_ETH_RSS_IPV4;
537 : :
538 [ # # ]: 0 : if (valid_rss_hf & ipv6_rss)
539 : 0 : valid_rss_hf |= rss_hf & RTE_ETH_RSS_IPV6;
540 : :
541 [ # # ]: 0 : if (rss_hf & ~valid_rss_hf)
542 : 0 : PMD_DRV_LOG(WARNING, "Unsupported rss_hf 0x%" PRIx64,
543 : : rss_hf & ~valid_rss_hf);
544 : :
545 : 0 : vf->rss_hf = valid_rss_hf;
546 : : }
547 : :
548 : : static int
549 : 0 : iavf_init_rss(struct iavf_adapter *adapter)
550 : : {
551 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
552 : : struct rte_eth_rss_conf *rss_conf;
553 : : uint16_t i, j, nb_q;
554 : : int ret;
555 : :
556 : 0 : rss_conf = &adapter->dev_data->dev_conf.rx_adv_conf.rss_conf;
557 : 0 : nb_q = RTE_MIN(adapter->dev_data->nb_rx_queues,
558 : : vf->max_rss_qregion);
559 : :
560 [ # # ]: 0 : if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF)) {
561 : 0 : PMD_DRV_LOG(DEBUG, "RSS is not supported");
562 : 0 : return -ENOTSUP;
563 : : }
564 : :
565 : : /* configure RSS key */
566 [ # # ]: 0 : if (!rss_conf->rss_key) {
567 : : /* Calculate the default hash key */
568 [ # # ]: 0 : for (i = 0; i < vf->vf_res->rss_key_size; i++)
569 : 0 : vf->rss_key[i] = (uint8_t)rte_rand();
570 : : } else
571 : 0 : memcpy(vf->rss_key, rss_conf->rss_key,
572 : 0 : RTE_MIN(rss_conf->rss_key_len,
573 : : vf->vf_res->rss_key_size));
574 : :
575 : : /* init RSS LUT table */
576 [ # # ]: 0 : for (i = 0, j = 0; i < vf->vf_res->rss_lut_size; i++, j++) {
577 [ # # ]: 0 : if (j >= nb_q)
578 : : j = 0;
579 : 0 : vf->rss_lut[i] = j;
580 : : }
581 : : /* send virtchnl ops to configure RSS */
582 : 0 : ret = iavf_configure_rss_lut(adapter);
583 [ # # ]: 0 : if (ret)
584 : : return ret;
585 : 0 : ret = iavf_configure_rss_key(adapter);
586 [ # # ]: 0 : if (ret)
587 : : return ret;
588 : :
589 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF) {
590 : : /* Set RSS hash configuration based on rss_conf->rss_hf. */
591 : 0 : ret = iavf_rss_hash_set(adapter, rss_conf->rss_hf, true);
592 [ # # ]: 0 : if (ret) {
593 : 0 : PMD_DRV_LOG(ERR, "fail to set default RSS");
594 : 0 : return ret;
595 : : }
596 : : } else {
597 : 0 : iavf_config_rss_hf(adapter, rss_conf->rss_hf);
598 : : }
599 : :
600 : : return 0;
601 : : }
602 : :
603 : : static int
604 : 0 : iavf_queues_req_reset(struct rte_eth_dev *dev, uint16_t num)
605 : : {
606 : 0 : struct iavf_adapter *ad =
607 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
608 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(ad);
609 : : int ret;
610 : :
611 : 0 : ret = iavf_request_queues(dev, num);
612 [ # # ]: 0 : if (ret) {
613 : 0 : PMD_DRV_LOG(ERR, "request queues from PF failed");
614 : 0 : return ret;
615 : : }
616 : 0 : PMD_DRV_LOG(INFO, "change queue pairs from %u to %u",
617 : : vf->vsi_res->num_queue_pairs, num);
618 : :
619 : 0 : iavf_dev_watchdog_disable(ad);
620 : 0 : ret = iavf_dev_reset(dev);
621 [ # # ]: 0 : if (ret) {
622 : 0 : PMD_DRV_LOG(ERR, "vf reset failed");
623 : 0 : return ret;
624 : : }
625 : :
626 : : return 0;
627 : : }
628 : :
629 : : static int
630 : 0 : iavf_dev_vlan_insert_set(struct rte_eth_dev *dev)
631 : : {
632 : 0 : struct iavf_adapter *adapter =
633 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
634 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
635 : : bool enable;
636 : :
637 [ # # ]: 0 : if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2))
638 : : return 0;
639 : :
640 : 0 : enable = !!(dev->data->dev_conf.txmode.offloads &
641 : : (RTE_ETH_TX_OFFLOAD_VLAN_INSERT | RTE_ETH_TX_OFFLOAD_QINQ_INSERT));
642 : 0 : iavf_config_vlan_insert_v2(adapter, enable);
643 : :
644 : 0 : return 0;
645 : : }
646 : :
647 : : static int
648 : 0 : iavf_dev_init_vlan(struct rte_eth_dev *dev)
649 : : {
650 : : int err;
651 : :
652 : 0 : err = iavf_dev_vlan_offload_set(dev,
653 : : RTE_ETH_VLAN_STRIP_MASK |
654 : : RTE_ETH_QINQ_STRIP_MASK |
655 : : RTE_ETH_VLAN_FILTER_MASK |
656 : : RTE_ETH_VLAN_EXTEND_MASK);
657 [ # # ]: 0 : if (err) {
658 : 0 : PMD_DRV_LOG(INFO,
659 : : "VLAN offloading is not supported, or offloading was refused by the PF");
660 : 0 : return err;
661 : : }
662 : :
663 : 0 : err = iavf_dev_vlan_insert_set(dev);
664 [ # # ]: 0 : if (err)
665 : 0 : PMD_DRV_LOG(ERR, "Failed to update vlan insertion");
666 : :
667 : : return err;
668 : : }
669 : :
670 : : static int
671 : 0 : iavf_dev_configure(struct rte_eth_dev *dev)
672 : : {
673 : 0 : struct iavf_adapter *ad =
674 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
675 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(ad);
676 : 0 : uint16_t num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
677 : : dev->data->nb_tx_queues);
678 : : int ret;
679 : :
680 [ # # ]: 0 : if (ad->closed)
681 : : return -EIO;
682 : :
683 : 0 : ad->rx_bulk_alloc_allowed = true;
684 : :
685 : 0 : ad->tx_func_type = IAVF_TX_DEFAULT;
686 : :
687 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
688 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
689 : :
690 : : /* Large VF setting */
691 [ # # ]: 0 : if (num_queue_pairs > IAVF_MAX_NUM_QUEUES_DFLT) {
692 [ # # ]: 0 : if (!(vf->vf_res->vf_cap_flags &
693 : : VIRTCHNL_VF_LARGE_NUM_QPAIRS)) {
694 : 0 : PMD_DRV_LOG(ERR, "large VF is not supported");
695 : 0 : return -1;
696 : : }
697 : :
698 [ # # ]: 0 : if (num_queue_pairs > IAVF_MAX_NUM_QUEUES_LV) {
699 : 0 : PMD_DRV_LOG(ERR, "queue pairs number cannot be larger than %u",
700 : : IAVF_MAX_NUM_QUEUES_LV);
701 : 0 : return -1;
702 : : }
703 : :
704 : 0 : ret = iavf_queues_req_reset(dev, num_queue_pairs);
705 [ # # ]: 0 : if (ret)
706 : : return ret;
707 : :
708 : 0 : ret = iavf_get_max_rss_queue_region(ad);
709 [ # # ]: 0 : if (ret) {
710 : 0 : PMD_INIT_LOG(ERR, "get max rss queue region failed");
711 : 0 : return ret;
712 : : }
713 : :
714 : 0 : vf->lv_enabled = true;
715 : : } else {
716 : : /* Check if large VF is already enabled. If so, disable and
717 : : * release redundant queue resource.
718 : : * Or check if enough queue pairs. If not, request them from PF.
719 : : */
720 [ # # ]: 0 : if (vf->lv_enabled ||
721 [ # # ]: 0 : num_queue_pairs > vf->vsi_res->num_queue_pairs) {
722 : 0 : ret = iavf_queues_req_reset(dev, num_queue_pairs);
723 [ # # ]: 0 : if (ret)
724 : : return ret;
725 : :
726 : 0 : vf->lv_enabled = false;
727 : : }
728 : : /* if large VF is not required, use default rss queue region */
729 : 0 : vf->max_rss_qregion = IAVF_MAX_NUM_QUEUES_DFLT;
730 : : }
731 : :
732 : 0 : iavf_dev_init_vlan(dev);
733 : :
734 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
735 [ # # ]: 0 : if (iavf_init_rss(ad) != 0) {
736 : 0 : PMD_DRV_LOG(ERR, "configure rss failed");
737 : 0 : return -1;
738 : : }
739 : : }
740 : : return 0;
741 : : }
742 : :
743 : : static int
744 : 0 : iavf_init_rxq(struct rte_eth_dev *dev, struct ci_rx_queue *rxq)
745 : : {
746 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
747 : : struct rte_eth_dev_data *dev_data = dev->data;
748 : : uint16_t buf_size, max_pkt_len;
749 : 0 : uint32_t frame_size = dev->data->mtu + IAVF_ETH_OVERHEAD;
750 : : enum iavf_status err;
751 : :
752 [ # # ]: 0 : buf_size = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
753 : :
754 : : /* Calculate the maximum packet length allowed */
755 : 0 : max_pkt_len = RTE_MIN((uint32_t)
756 : : rxq->rx_buf_len * IAVF_MAX_CHAINED_RX_BUFFERS,
757 : : frame_size);
758 : :
759 : : /* Check if maximum packet length is set correctly. */
760 [ # # ]: 0 : if (max_pkt_len <= RTE_ETHER_MIN_LEN ||
761 : : max_pkt_len > IAVF_FRAME_SIZE_MAX) {
762 : 0 : PMD_DRV_LOG(ERR, "maximum packet length must be "
763 : : "larger than %u and smaller than %u",
764 : : (uint32_t)IAVF_ETH_MAX_LEN,
765 : : (uint32_t)IAVF_FRAME_SIZE_MAX);
766 : 0 : return -EINVAL;
767 : : }
768 : :
769 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
770 : : /* Register mbuf field and flag for Rx timestamp */
771 : 0 : err = rte_mbuf_dyn_rx_timestamp_register(
772 : : &iavf_timestamp_dynfield_offset,
773 : : &iavf_timestamp_dynflag);
774 [ # # ]: 0 : if (err) {
775 : 0 : PMD_DRV_LOG(ERR,
776 : : "Cannot register mbuf field/flag for timestamp");
777 : 0 : return -EINVAL;
778 : : }
779 : : }
780 : :
781 : 0 : rxq->max_pkt_len = max_pkt_len;
782 [ # # # # ]: 0 : if ((dev_data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) ||
783 : : rxq->max_pkt_len > buf_size) {
784 : 0 : dev_data->scattered_rx = 1;
785 : : }
786 : 0 : IAVF_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
787 : 0 : IAVF_WRITE_FLUSH(hw);
788 : :
789 : 0 : return 0;
790 : : }
791 : :
792 : : static int
793 : 0 : iavf_init_queues(struct rte_eth_dev *dev)
794 : : {
795 : 0 : struct ci_rx_queue **rxq = (struct ci_rx_queue **)dev->data->rx_queues;
796 : : int i, ret = IAVF_SUCCESS;
797 : :
798 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
799 [ # # # # ]: 0 : if (!rxq[i] || !rxq[i]->q_set)
800 : 0 : continue;
801 : 0 : ret = iavf_init_rxq(dev, rxq[i]);
802 [ # # ]: 0 : if (ret != IAVF_SUCCESS)
803 : : break;
804 : : }
805 : : /* set rx/tx function to vector/scatter/single-segment
806 : : * according to parameters
807 : : */
808 : 0 : iavf_set_rx_function(dev);
809 : 0 : iavf_set_tx_function(dev);
810 : :
811 : 0 : return ret;
812 : : }
813 : :
814 : 0 : static int iavf_config_rx_queues_irqs(struct rte_eth_dev *dev,
815 : : struct rte_intr_handle *intr_handle)
816 : : {
817 : 0 : struct iavf_adapter *adapter =
818 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
819 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
820 : : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
821 : : struct iavf_qv_map *qv_map;
822 : : uint16_t interval, i;
823 : : int vec;
824 : :
825 [ # # ]: 0 : if (rte_intr_cap_multiple(intr_handle) &&
826 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq) {
827 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, dev->data->nb_rx_queues))
828 : : return -1;
829 : : }
830 : :
831 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
832 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
833 : 0 : dev->data->nb_rx_queues)) {
834 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate %d rx intr_vec",
835 : : dev->data->nb_rx_queues);
836 : 0 : return -1;
837 : : }
838 : : }
839 : :
840 : :
841 : 0 : qv_map = rte_zmalloc("qv_map",
842 : 0 : dev->data->nb_rx_queues * sizeof(struct iavf_qv_map), 0);
843 [ # # ]: 0 : if (!qv_map) {
844 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate %d queue-vector map",
845 : : dev->data->nb_rx_queues);
846 : 0 : goto qv_map_alloc_err;
847 : : }
848 : :
849 [ # # # # ]: 0 : if (!dev->data->dev_conf.intr_conf.rxq ||
850 : 0 : !rte_intr_dp_is_en(intr_handle)) {
851 : : /* Rx interrupt disabled, Map interrupt only for writeback */
852 : 0 : vf->nb_msix = 1;
853 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags &
854 : : VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
855 : : /* If WB_ON_ITR supports, enable it */
856 : 0 : vf->msix_base = IAVF_RX_VEC_START;
857 : : /* Set the ITR for index zero, to 2us to make sure that
858 : : * we leave time for aggregation to occur, but don't
859 : : * increase latency dramatically.
860 : : */
861 : 0 : IAVF_WRITE_REG(hw,
862 : : IAVF_VFINT_DYN_CTLN1(vf->msix_base - 1),
863 : : (0 << IAVF_VFINT_DYN_CTLN1_ITR_INDX_SHIFT) |
864 : : IAVF_VFINT_DYN_CTLN1_WB_ON_ITR_MASK |
865 : : (2UL << IAVF_VFINT_DYN_CTLN1_INTERVAL_SHIFT));
866 : : /* debug - check for success! the return value
867 : : * should be 2, offset is 0x2800
868 : : */
869 : : /* IAVF_READ_REG(hw, IAVF_VFINT_ITRN1(0, 0)); */
870 : : } else {
871 : : /* If no WB_ON_ITR offload flags, need to set
872 : : * interrupt for descriptor write back.
873 : : */
874 : 0 : vf->msix_base = IAVF_MISC_VEC_ID;
875 : :
876 : : /* set ITR to default */
877 : : interval = iavf_calc_itr_interval(
878 : : IAVF_QUEUE_ITR_INTERVAL_DEFAULT);
879 : 0 : IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
880 : : IAVF_VFINT_DYN_CTL01_INTENA_MASK |
881 : : (IAVF_ITR_INDEX_DEFAULT <<
882 : : IAVF_VFINT_DYN_CTL01_ITR_INDX_SHIFT) |
883 : : (interval <<
884 : : IAVF_VFINT_DYN_CTL01_INTERVAL_SHIFT));
885 : : }
886 : 0 : IAVF_WRITE_FLUSH(hw);
887 : : /* map all queues to the same interrupt */
888 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
889 : 0 : qv_map[i].queue_id = i;
890 : 0 : qv_map[i].vector_id = vf->msix_base;
891 : : }
892 : 0 : vf->qv_map = qv_map;
893 : : } else {
894 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle)) {
895 : 0 : vf->nb_msix = 1;
896 : 0 : vf->msix_base = IAVF_MISC_VEC_ID;
897 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
898 : 0 : qv_map[i].queue_id = i;
899 : 0 : qv_map[i].vector_id = vf->msix_base;
900 : 0 : rte_intr_vec_list_index_set(intr_handle,
901 : : i, IAVF_MISC_VEC_ID);
902 : : }
903 : 0 : vf->qv_map = qv_map;
904 : 0 : PMD_DRV_LOG(DEBUG,
905 : : "vector %u are mapping to all Rx queues",
906 : : vf->msix_base);
907 : : } else {
908 : : /* If Rx interrupt is required, and we can use
909 : : * multi interrupts, then the vec is from 1
910 : : */
911 : 0 : vf->nb_msix =
912 : 0 : RTE_MIN(rte_intr_nb_efd_get(intr_handle),
913 : : (uint16_t)(vf->vf_res->max_vectors - 1));
914 : 0 : vf->msix_base = IAVF_RX_VEC_START;
915 : : vec = IAVF_RX_VEC_START;
916 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
917 : 0 : qv_map[i].queue_id = i;
918 : 0 : qv_map[i].vector_id = vec;
919 : 0 : rte_intr_vec_list_index_set(intr_handle,
920 : : i, vec++);
921 [ # # ]: 0 : if (vec >= vf->nb_msix + IAVF_RX_VEC_START)
922 : : vec = IAVF_RX_VEC_START;
923 : : }
924 : 0 : vf->qv_map = qv_map;
925 : 0 : PMD_DRV_LOG(DEBUG,
926 : : "%u vectors are mapping to %u Rx queues",
927 : : vf->nb_msix, dev->data->nb_rx_queues);
928 : : }
929 : : }
930 : :
931 [ # # ]: 0 : if (!vf->lv_enabled) {
932 [ # # ]: 0 : if (iavf_config_irq_map(adapter)) {
933 : 0 : PMD_DRV_LOG(ERR, "config interrupt mapping failed");
934 : 0 : goto config_irq_map_err;
935 : : }
936 : : } else {
937 [ # # ]: 0 : if (iavf_config_irq_map_lv(adapter, dev->data->nb_rx_queues)) {
938 : 0 : PMD_DRV_LOG(ERR, "config interrupt mapping for large VF failed");
939 : 0 : goto config_irq_map_err;
940 : : }
941 : : }
942 : : return 0;
943 : :
944 : 0 : config_irq_map_err:
945 : 0 : rte_free(vf->qv_map);
946 : 0 : vf->qv_map = NULL;
947 : :
948 : 0 : qv_map_alloc_err:
949 : 0 : rte_intr_vec_list_free(intr_handle);
950 : :
951 : 0 : return -1;
952 : : }
953 : :
954 : : static int
955 : 0 : iavf_start_queues(struct rte_eth_dev *dev)
956 : : {
957 : : struct ci_rx_queue *rxq;
958 : : struct ci_tx_queue *txq;
959 : : int i;
960 : : uint16_t nb_txq, nb_rxq;
961 : :
962 [ # # ]: 0 : for (nb_txq = 0; nb_txq < dev->data->nb_tx_queues; nb_txq++) {
963 : 0 : txq = dev->data->tx_queues[nb_txq];
964 [ # # ]: 0 : if (txq->tx_deferred_start)
965 : 0 : continue;
966 [ # # ]: 0 : if (iavf_dev_tx_queue_start(dev, nb_txq) != 0) {
967 : 0 : PMD_DRV_LOG(ERR, "Fail to start tx queue %u", nb_txq);
968 : 0 : goto tx_err;
969 : : }
970 : : }
971 : :
972 [ # # ]: 0 : for (nb_rxq = 0; nb_rxq < dev->data->nb_rx_queues; nb_rxq++) {
973 : 0 : rxq = dev->data->rx_queues[nb_rxq];
974 [ # # ]: 0 : if (rxq->rx_deferred_start)
975 : 0 : continue;
976 [ # # ]: 0 : if (iavf_dev_rx_queue_start(dev, nb_rxq) != 0) {
977 : 0 : PMD_DRV_LOG(ERR, "Fail to start rx queue %u", nb_rxq);
978 : 0 : goto rx_err;
979 : : }
980 : : }
981 : :
982 : : return 0;
983 : :
984 : : rx_err:
985 [ # # ]: 0 : for (i = 0; i < nb_rxq; i++)
986 : 0 : iavf_dev_rx_queue_stop(dev, i);
987 : 0 : tx_err:
988 [ # # ]: 0 : for (i = 0; i < nb_txq; i++)
989 : 0 : iavf_dev_tx_queue_stop(dev, i);
990 : :
991 : : return -1;
992 : : }
993 : :
994 : : static int
995 : 0 : iavf_dev_start(struct rte_eth_dev *dev)
996 : : {
997 : 0 : struct iavf_adapter *adapter =
998 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
999 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1000 : 0 : struct rte_intr_handle *intr_handle = dev->intr_handle;
1001 : : uint16_t num_queue_pairs;
1002 : : uint16_t index = 0;
1003 : :
1004 : 0 : PMD_INIT_FUNC_TRACE();
1005 : :
1006 [ # # ]: 0 : if (adapter->closed)
1007 : : return -1;
1008 : :
1009 : 0 : adapter->stopped = 0;
1010 : :
1011 : 0 : vf->max_pkt_len = dev->data->mtu + IAVF_ETH_OVERHEAD;
1012 : 0 : vf->num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
1013 : : dev->data->nb_tx_queues);
1014 : : num_queue_pairs = vf->num_queue_pairs;
1015 : :
1016 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_QOS)
1017 [ # # ]: 0 : if (iavf_get_qos_cap(adapter)) {
1018 : 0 : PMD_INIT_LOG(ERR, "Failed to get qos capability");
1019 : 0 : return -1;
1020 : : }
1021 : :
1022 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP) {
1023 [ # # ]: 0 : if (iavf_get_ptp_cap(adapter)) {
1024 : 0 : PMD_INIT_LOG(ERR, "Failed to get ptp capability");
1025 : 0 : return -1;
1026 : : }
1027 : : }
1028 : :
1029 : : /* Check Tx LLDP dynfield */
1030 : 0 : rte_pmd_iavf_tx_lldp_dynfield_offset =
1031 : 0 : rte_mbuf_dynfield_lookup(IAVF_TX_LLDP_DYNFIELD, NULL);
1032 [ # # ]: 0 : if (rte_pmd_iavf_tx_lldp_dynfield_offset > 0) {
1033 : 0 : PMD_DRV_LOG(WARNING,
1034 : : "Using a dynamic mbuf field to identify LLDP packets is deprecated. "
1035 : : "Set the 'enable_ptype_lldp' driver option and mbuf LLDP ptypes instead.");
1036 [ # # ]: 0 : if (adapter->devargs.enable_ptype_lldp)
1037 : 0 : PMD_DRV_LOG(WARNING,
1038 : : "Both ptype and dynfield LLDP enabled; ptype takes precedence.");
1039 : : }
1040 : :
1041 [ # # ]: 0 : for (uint16_t i = 0; i < dev->data->nb_tx_queues; i++) {
1042 : 0 : struct ci_tx_queue *txq = dev->data->tx_queues[i];
1043 [ # # ]: 0 : if (txq) {
1044 [ # # ]: 0 : if (adapter->devargs.enable_ptype_lldp)
1045 : 0 : txq->lldp_mode = IAVF_LLDP_PTYPE;
1046 [ # # ]: 0 : else if (rte_pmd_iavf_tx_lldp_dynfield_offset > 0)
1047 : 0 : txq->lldp_mode = IAVF_LLDP_DYNFIELD;
1048 : : else
1049 : 0 : txq->lldp_mode = IAVF_LLDP_DISABLED;
1050 : : }
1051 : : }
1052 : :
1053 [ # # ]: 0 : if (iavf_init_queues(dev) != 0) {
1054 : 0 : PMD_DRV_LOG(ERR, "failed to do Queue init");
1055 : 0 : return -1;
1056 : : }
1057 : :
1058 [ # # ]: 0 : if (iavf_set_vf_quanta_size(adapter, index, num_queue_pairs) != 0)
1059 : 0 : PMD_DRV_LOG(WARNING, "configure quanta size failed");
1060 : :
1061 [ # # ]: 0 : if (iavf_configure_queues(adapter, num_queue_pairs) != 0) {
1062 : 0 : PMD_DRV_LOG(ERR, "configure queues failed");
1063 : 0 : goto error;
1064 : : }
1065 : :
1066 [ # # ]: 0 : if (iavf_config_rx_queues_irqs(dev, intr_handle) != 0) {
1067 : 0 : PMD_DRV_LOG(ERR, "configure irq failed");
1068 : 0 : goto error;
1069 : : }
1070 : : /* re-enable intr again, because efd assign may change */
1071 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq != 0) {
1072 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
1073 : 0 : rte_intr_disable(intr_handle);
1074 : 0 : rte_intr_enable(intr_handle);
1075 : : }
1076 : :
1077 : : /* Set all mac addrs */
1078 : 0 : iavf_add_del_all_mac_addr(adapter, true);
1079 : :
1080 [ # # ]: 0 : if (!adapter->mac_primary_set)
1081 : 0 : adapter->mac_primary_set = true;
1082 : :
1083 : : /* Set all multicast addresses */
1084 : 0 : iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
1085 : : true);
1086 : :
1087 : : rte_spinlock_init(&vf->phc_time_aq_lock);
1088 : :
1089 [ # # ]: 0 : if (iavf_start_queues(dev) != 0) {
1090 : 0 : PMD_DRV_LOG(ERR, "enable queues failed");
1091 : 0 : goto error;
1092 : : }
1093 : :
1094 : 0 : iavf_phc_sync_alarm_start(dev);
1095 : :
1096 : 0 : return 0;
1097 : :
1098 : : error:
1099 : : return -1;
1100 : : }
1101 : :
1102 : : static int
1103 : 0 : iavf_dev_stop(struct rte_eth_dev *dev)
1104 : : {
1105 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1106 : : struct iavf_adapter *adapter =
1107 : : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1108 : 0 : struct rte_intr_handle *intr_handle = dev->intr_handle;
1109 : :
1110 : 0 : PMD_INIT_FUNC_TRACE();
1111 : :
1112 [ # # ]: 0 : if (adapter->closed)
1113 : : return -1;
1114 : :
1115 [ # # ]: 0 : if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) &&
1116 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq != 0)
1117 : 0 : rte_intr_disable(intr_handle);
1118 : :
1119 [ # # ]: 0 : if (adapter->stopped == 1)
1120 : : return 0;
1121 : :
1122 : 0 : iavf_phc_sync_alarm_stop(dev);
1123 : :
1124 : : /* Disable the interrupt for Rx */
1125 : 0 : rte_intr_efd_disable(intr_handle);
1126 : : /* Rx interrupt vector mapping free */
1127 : 0 : rte_intr_vec_list_free(intr_handle);
1128 : :
1129 : 0 : iavf_stop_queues(dev);
1130 : :
1131 : 0 : adapter->stopped = 1;
1132 : 0 : dev->data->dev_started = 0;
1133 : :
1134 : 0 : return 0;
1135 : : }
1136 : :
1137 : : static int
1138 : 0 : iavf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1139 : : {
1140 : 0 : struct iavf_adapter *adapter =
1141 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1142 : : struct iavf_info *vf = &adapter->vf;
1143 : : uint16_t max_queue_pairs;
1144 : :
1145 [ # # ]: 0 : if (adapter->closed)
1146 : : return -EIO;
1147 : :
1148 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_LARGE_NUM_QPAIRS)
1149 : : max_queue_pairs = IAVF_MAX_NUM_QUEUES_LV;
1150 : : else
1151 : : max_queue_pairs = IAVF_MAX_NUM_QUEUES_DFLT;
1152 : :
1153 : 0 : dev_info->max_rx_queues = max_queue_pairs;
1154 : 0 : dev_info->max_tx_queues = max_queue_pairs;
1155 : 0 : dev_info->min_rx_bufsize = IAVF_BUF_SIZE_MIN;
1156 : 0 : dev_info->max_rx_pktlen = IAVF_FRAME_SIZE_MAX;
1157 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - IAVF_ETH_OVERHEAD;
1158 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
1159 : 0 : dev_info->hash_key_size = vf->vf_res->rss_key_size;
1160 : 0 : dev_info->reta_size = vf->vf_res->rss_lut_size;
1161 : 0 : dev_info->flow_type_rss_offloads = IAVF_RSS_OFFLOAD_ALL;
1162 : 0 : dev_info->max_mac_addrs = IAVF_NUM_MACADDR_MAX;
1163 : 0 : dev_info->dev_capa =
1164 : : RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
1165 : : RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
1166 : 0 : dev_info->rx_offload_capa =
1167 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
1168 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
1169 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
1170 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
1171 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
1172 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
1173 : : RTE_ETH_RX_OFFLOAD_SCATTER |
1174 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
1175 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
1176 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
1177 : :
1178 : 0 : dev_info->tx_offload_capa =
1179 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
1180 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
1181 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
1182 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
1183 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
1184 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
1185 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
1186 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
1187 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
1188 : : RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
1189 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
1190 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
1191 : : RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
1192 : :
1193 : : /* X710 does not support outer udp checksum */
1194 [ # # ]: 0 : if (adapter->hw.mac.type != IAVF_MAC_XL710)
1195 : 0 : dev_info->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
1196 : :
1197 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_CRC)
1198 : 0 : dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
1199 : :
1200 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP &&
1201 [ # # ]: 0 : vf->ptp_caps & VIRTCHNL_1588_PTP_CAP_RX_TSTAMP)
1202 : 0 : dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_TIMESTAMP;
1203 : :
1204 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2 &&
1205 [ # # ]: 0 : vf->vlan_v2_caps.offloads.insertion_support.inner &&
1206 [ # # ]: 0 : vf->vlan_v2_caps.offloads.insertion_support.outer)
1207 : 0 : dev_info->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_QINQ_INSERT;
1208 : :
1209 [ # # ]: 0 : if (iavf_ipsec_crypto_supported(adapter)) {
1210 : 0 : dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_SECURITY;
1211 : 0 : dev_info->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_SECURITY;
1212 : : }
1213 : :
1214 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
1215 : : .rx_free_thresh = IAVF_DEFAULT_RX_FREE_THRESH,
1216 : : .rx_drop_en = 0,
1217 : : .offloads = 0,
1218 : : };
1219 : :
1220 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
1221 : : .tx_free_thresh = IAVF_DEFAULT_TX_FREE_THRESH,
1222 : : .tx_rs_thresh = IAVF_DEFAULT_TX_RS_THRESH,
1223 : : .offloads = 0,
1224 : : };
1225 : :
1226 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
1227 : : .nb_max = IAVF_MAX_RING_DESC,
1228 : : .nb_min = IAVF_MIN_RING_DESC,
1229 : : .nb_align = IAVF_ALIGN_RING_DESC,
1230 : : };
1231 : :
1232 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
1233 : : .nb_max = IAVF_MAX_RING_DESC,
1234 : : .nb_min = IAVF_MIN_RING_DESC,
1235 : : .nb_align = IAVF_ALIGN_RING_DESC,
1236 : : .nb_mtu_seg_max = IAVF_TX_MAX_MTU_SEG,
1237 : : .nb_seg_max = IAVF_MAX_RING_DESC,
1238 : : };
1239 : :
1240 : 0 : dev_info->err_handle_mode = RTE_ETH_ERROR_HANDLE_MODE_PASSIVE;
1241 : :
1242 : 0 : return 0;
1243 : : }
1244 : :
1245 : : static const uint32_t *
1246 : 0 : iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused,
1247 : : size_t *no_of_elements)
1248 : : {
1249 : : static const uint32_t ptypes[] = {
1250 : : RTE_PTYPE_L2_ETHER,
1251 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1252 : : RTE_PTYPE_L4_FRAG,
1253 : : RTE_PTYPE_L4_ICMP,
1254 : : RTE_PTYPE_L4_NONFRAG,
1255 : : RTE_PTYPE_L4_SCTP,
1256 : : RTE_PTYPE_L4_TCP,
1257 : : RTE_PTYPE_L4_UDP,
1258 : : };
1259 : 0 : *no_of_elements = RTE_DIM(ptypes);
1260 : 0 : return ptypes;
1261 : : }
1262 : :
1263 : : int
1264 : 0 : iavf_dev_link_update(struct rte_eth_dev *dev,
1265 : : __rte_unused int wait_to_complete)
1266 : : {
1267 : : struct rte_eth_link new_link;
1268 [ # # # # : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
# # # # #
# ]
1269 : :
1270 : : memset(&new_link, 0, sizeof(new_link));
1271 : :
1272 : : /* Only read status info stored in VF, and the info is updated
1273 : : * when receive LINK_CHANGE evnet from PF by Virtchnnl.
1274 : : */
1275 [ # # # # : 0 : switch (vf->link_speed) {
# # # # #
# ]
1276 : 0 : case 10:
1277 : 0 : new_link.link_speed = RTE_ETH_SPEED_NUM_10M;
1278 : 0 : break;
1279 : 0 : case 100:
1280 : 0 : new_link.link_speed = RTE_ETH_SPEED_NUM_100M;
1281 : 0 : break;
1282 : 0 : case 1000:
1283 : 0 : new_link.link_speed = RTE_ETH_SPEED_NUM_1G;
1284 : 0 : break;
1285 : 0 : case 10000:
1286 : 0 : new_link.link_speed = RTE_ETH_SPEED_NUM_10G;
1287 : 0 : break;
1288 : 0 : case 20000:
1289 : 0 : new_link.link_speed = RTE_ETH_SPEED_NUM_20G;
1290 : 0 : break;
1291 : 0 : case 25000:
1292 : 0 : new_link.link_speed = RTE_ETH_SPEED_NUM_25G;
1293 : 0 : break;
1294 : 0 : case 40000:
1295 : 0 : new_link.link_speed = RTE_ETH_SPEED_NUM_40G;
1296 : 0 : break;
1297 : 0 : case 50000:
1298 : 0 : new_link.link_speed = RTE_ETH_SPEED_NUM_50G;
1299 : 0 : break;
1300 : 0 : case 100000:
1301 : 0 : new_link.link_speed = RTE_ETH_SPEED_NUM_100G;
1302 : 0 : break;
1303 : : default:
1304 : : new_link.link_speed = RTE_ETH_SPEED_NUM_NONE;
1305 : : break;
1306 : : }
1307 : :
1308 : 0 : new_link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
1309 : 0 : new_link.link_status = vf->link_up ? RTE_ETH_LINK_UP :
1310 : : RTE_ETH_LINK_DOWN;
1311 [ # # ]: 0 : new_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
1312 : : RTE_ETH_LINK_SPEED_FIXED);
1313 : :
1314 : 0 : return rte_eth_linkstatus_set(dev, &new_link);
1315 : : }
1316 : :
1317 : : static int
1318 : 0 : iavf_dev_promiscuous_enable(struct rte_eth_dev *dev)
1319 : : {
1320 : 0 : struct iavf_adapter *adapter =
1321 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1322 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1323 : :
1324 : 0 : return iavf_config_promisc(adapter,
1325 : 0 : true, vf->promisc_multicast_enabled);
1326 : : }
1327 : :
1328 : : static int
1329 : 0 : iavf_dev_promiscuous_disable(struct rte_eth_dev *dev)
1330 : : {
1331 : 0 : struct iavf_adapter *adapter =
1332 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1333 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1334 : :
1335 : 0 : return iavf_config_promisc(adapter,
1336 : 0 : false, vf->promisc_multicast_enabled);
1337 : : }
1338 : :
1339 : : static int
1340 : 0 : iavf_dev_allmulticast_enable(struct rte_eth_dev *dev)
1341 : : {
1342 : 0 : struct iavf_adapter *adapter =
1343 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1344 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1345 : :
1346 : 0 : return iavf_config_promisc(adapter,
1347 : 0 : vf->promisc_unicast_enabled, true);
1348 : : }
1349 : :
1350 : : static int
1351 : 0 : iavf_dev_allmulticast_disable(struct rte_eth_dev *dev)
1352 : : {
1353 : 0 : struct iavf_adapter *adapter =
1354 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1355 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1356 : :
1357 : 0 : return iavf_config_promisc(adapter,
1358 : 0 : vf->promisc_unicast_enabled, false);
1359 : : }
1360 : :
1361 : : static int
1362 : 0 : iavf_dev_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr,
1363 : : __rte_unused uint32_t index,
1364 : : __rte_unused uint32_t pool)
1365 : : {
1366 : 0 : struct iavf_adapter *adapter =
1367 [ # # ]: 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1368 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1369 : : int err;
1370 : :
1371 [ # # ]: 0 : if (rte_is_zero_ether_addr(addr)) {
1372 : 0 : PMD_DRV_LOG(ERR, "Invalid Ethernet Address");
1373 : 0 : return -EINVAL;
1374 : : }
1375 : :
1376 : 0 : err = iavf_add_del_eth_addr(adapter, addr, true, VIRTCHNL_ETHER_ADDR_EXTRA);
1377 [ # # ]: 0 : if (err) {
1378 : 0 : PMD_DRV_LOG(ERR, "fail to add MAC address");
1379 : 0 : return -EIO;
1380 : : }
1381 : :
1382 : 0 : vf->mac_num++;
1383 : :
1384 : 0 : return 0;
1385 : : }
1386 : :
1387 : : static void
1388 : 0 : iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index)
1389 : : {
1390 : 0 : struct iavf_adapter *adapter =
1391 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1392 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1393 : : struct rte_ether_addr *addr;
1394 : : int err;
1395 : :
1396 : 0 : addr = &dev->data->mac_addrs[index];
1397 : :
1398 : 0 : err = iavf_add_del_eth_addr(adapter, addr, false, VIRTCHNL_ETHER_ADDR_EXTRA);
1399 [ # # ]: 0 : if (err)
1400 : 0 : PMD_DRV_LOG(ERR, "fail to delete MAC address");
1401 : :
1402 : 0 : vf->mac_num--;
1403 : 0 : }
1404 : :
1405 : : static int
1406 : 0 : iavf_vlan_tpid_set(struct rte_eth_dev *dev, enum rte_vlan_type vlan_type, uint16_t tpid)
1407 : : {
1408 : 0 : struct iavf_adapter *adapter =
1409 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1410 : : struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1411 : 0 : int qinq = dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
1412 : :
1413 [ # # ]: 0 : if (vlan_type != RTE_ETH_VLAN_TYPE_OUTER) {
1414 : 0 : PMD_DRV_LOG(ERR, "Unsupported vlan type.");
1415 : 0 : return -EINVAL;
1416 [ # # ]: 0 : } else if (!qinq) {
1417 : 0 : PMD_DRV_LOG(ERR, "VLAN-extend disabled.");
1418 : 0 : return -ENOSYS;
1419 : 0 : } else if (tpid != RTE_ETHER_TYPE_VLAN &&
1420 [ # # ]: 0 : tpid != RTE_ETHER_TYPE_QINQ) {
1421 : 0 : PMD_DRV_LOG(ERR, "tpid supported 0x8100/0x88A8");
1422 : 0 : return -ENOTSUP;
1423 : : }
1424 : :
1425 : : /* This API only fills internal iavf_adapter structure
1426 : : * and does not send any signal to hardware.
1427 : : * Inner VLAN always 0x8100, so not set explicitly.
1428 : : */
1429 : : if (qinq && vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
1430 : 0 : adapter->tpid = tpid; /* Outer VLAN can be 0x88a8 or 0x8100 */
1431 : :
1432 : 0 : return 0;
1433 : : }
1434 : :
1435 : : static int
1436 : 0 : iavf_disable_vlan_strip_ex(struct rte_eth_dev *dev, int on)
1437 : : {
1438 : : /* For i40e kernel drivers which supports both vlan(v1 & v2) VIRTCHNL OP,
1439 : : * it will set strip on when setting filter on but dpdk side will not
1440 : : * change strip flag. To be consistent with dpdk side, explicitly disable
1441 : : * strip again.
1442 : : *
1443 : : */
1444 : 0 : struct iavf_adapter *adapter =
1445 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1446 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1447 : : struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1448 : : int err;
1449 : :
1450 : 0 : if (adapter->hw.mac.type == IAVF_MAC_XL710 ||
1451 [ # # ]: 0 : adapter->hw.mac.type == IAVF_MAC_VF ||
1452 : : adapter->hw.mac.type == IAVF_MAC_X722_VF) {
1453 [ # # # # ]: 0 : if (on && !(dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)) {
1454 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2)
1455 : 0 : err = iavf_config_vlan_strip_v2(adapter, false);
1456 : : else
1457 : 0 : err = iavf_disable_vlan_strip(adapter);
1458 [ # # ]: 0 : if (err)
1459 : 0 : return -EIO;
1460 : : }
1461 : : }
1462 : : return 0;
1463 : : }
1464 : :
1465 : : static int
1466 : 0 : iavf_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1467 : : {
1468 : 0 : struct iavf_adapter *adapter =
1469 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1470 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1471 : : int err;
1472 : :
1473 [ # # ]: 0 : if (adapter->closed)
1474 : : return -EIO;
1475 : :
1476 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
1477 : 0 : err = iavf_add_del_vlan_v2(adapter, vlan_id, on);
1478 [ # # ]: 0 : if (err)
1479 : : return -EIO;
1480 : :
1481 : 0 : return iavf_disable_vlan_strip_ex(dev, on);
1482 : : }
1483 : :
1484 [ # # ]: 0 : if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
1485 : : return -ENOTSUP;
1486 : :
1487 : 0 : err = iavf_add_del_vlan(adapter, vlan_id, on);
1488 [ # # ]: 0 : if (err)
1489 : : return -EIO;
1490 : :
1491 : 0 : return iavf_disable_vlan_strip_ex(dev, on);
1492 : : }
1493 : :
1494 : : static void
1495 : 0 : iavf_iterate_vlan_filters_v2(struct rte_eth_dev *dev, bool enable)
1496 : : {
1497 : 0 : struct rte_vlan_filter_conf *vfc = &dev->data->vlan_filter_conf;
1498 : 0 : struct iavf_adapter *adapter =
1499 : : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1500 : : uint32_t i, j;
1501 : : uint64_t ids;
1502 : :
1503 [ # # ]: 0 : for (i = 0; i < RTE_DIM(vfc->ids); i++) {
1504 [ # # ]: 0 : if (vfc->ids[i] == 0)
1505 : 0 : continue;
1506 : :
1507 : : ids = vfc->ids[i];
1508 [ # # ]: 0 : for (j = 0; ids != 0 && j < 64; j++, ids >>= 1) {
1509 [ # # ]: 0 : if (ids & 1)
1510 : 0 : iavf_add_del_vlan_v2(adapter,
1511 : 0 : 64 * i + j, enable);
1512 : : }
1513 : : }
1514 : 0 : }
1515 : :
1516 : : static int
1517 : 0 : iavf_dev_vlan_offload_set_v2(struct rte_eth_dev *dev, int mask)
1518 : : {
1519 : 0 : struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
1520 : 0 : struct iavf_adapter *adapter =
1521 : : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1522 : : bool enable;
1523 : 0 : int qinq = dev->data->dev_conf.rxmode.offloads &
1524 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
1525 : : int err;
1526 : :
1527 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
1528 : 0 : enable = !!(rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER);
1529 : :
1530 : 0 : iavf_iterate_vlan_filters_v2(dev, enable);
1531 : : }
1532 : :
1533 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
1534 : 0 : enable = !!(rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
1535 : :
1536 : 0 : err = iavf_config_vlan_strip_v2(adapter, enable);
1537 : : /* If not support, the stripping is already disabled by PF */
1538 [ # # ]: 0 : if (err == -ENOTSUP && !enable)
1539 : : err = 0;
1540 [ # # ]: 0 : if (err)
1541 : : return -EIO;
1542 : : }
1543 : :
1544 [ # # ]: 0 : if (mask & RTE_ETH_QINQ_STRIP_MASK) {
1545 [ # # ]: 0 : if (!qinq) {
1546 : 0 : PMD_DRV_LOG(ERR, "VLAN-extend disabled");
1547 : 0 : return -ENOSYS;
1548 : : }
1549 : 0 : enable = !!(rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP);
1550 : 0 : err = iavf_config_outer_vlan_strip_v2(adapter, enable);
1551 : : /* If not support, the stripping is already disabled by PF */
1552 [ # # ]: 0 : if (err == -ENOTSUP && !enable)
1553 : : err = 0;
1554 [ # # ]: 0 : if (err)
1555 : 0 : return -EIO;
1556 : : }
1557 : :
1558 : : return 0;
1559 : : }
1560 : :
1561 : : static int
1562 : 0 : iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1563 : : {
1564 : 0 : struct iavf_adapter *adapter =
1565 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1566 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1567 : : struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1568 : : int err;
1569 : :
1570 [ # # ]: 0 : if (adapter->closed)
1571 : : return -EIO;
1572 : :
1573 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2)
1574 : 0 : return iavf_dev_vlan_offload_set_v2(dev, mask);
1575 : :
1576 [ # # ]: 0 : if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
1577 : : return -ENOTSUP;
1578 : :
1579 : : /* Vlan stripping setting */
1580 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
1581 : : /* Enable or disable VLAN stripping */
1582 [ # # ]: 0 : if (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
1583 : 0 : err = iavf_enable_vlan_strip(adapter);
1584 : : else
1585 : 0 : err = iavf_disable_vlan_strip(adapter);
1586 : :
1587 [ # # ]: 0 : if (err)
1588 : 0 : return -EIO;
1589 : : }
1590 : : return 0;
1591 : : }
1592 : :
1593 : : static int
1594 : 0 : iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
1595 : : struct rte_eth_rss_reta_entry64 *reta_conf,
1596 : : uint16_t reta_size)
1597 : : {
1598 : 0 : struct iavf_adapter *adapter =
1599 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1600 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1601 : : uint8_t *lut;
1602 : : uint16_t i, idx, shift;
1603 : : int ret;
1604 : :
1605 [ # # ]: 0 : if (adapter->closed)
1606 : : return -EIO;
1607 : :
1608 [ # # ]: 0 : if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1609 : : return -ENOTSUP;
1610 : :
1611 [ # # ]: 0 : if (reta_size != vf->vf_res->rss_lut_size) {
1612 : 0 : PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
1613 : : "(%d) doesn't match the number of hardware can "
1614 : : "support (%d)", reta_size, vf->vf_res->rss_lut_size);
1615 : 0 : return -EINVAL;
1616 : : }
1617 : :
1618 : 0 : lut = calloc(1, reta_size);
1619 [ # # ]: 0 : if (!lut) {
1620 : 0 : PMD_DRV_LOG(ERR, "No memory can be allocated");
1621 : 0 : return -ENOMEM;
1622 : : }
1623 : : /* store the old lut table temporarily */
1624 : 0 : memcpy(lut, vf->rss_lut, reta_size);
1625 : :
1626 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
1627 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
1628 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
1629 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << shift))
1630 : 0 : lut[i] = reta_conf[idx].reta[shift];
1631 : : }
1632 : :
1633 : : memcpy(vf->rss_lut, lut, reta_size);
1634 : : /* send virtchnl ops to configure RSS */
1635 : 0 : ret = iavf_configure_rss_lut(adapter);
1636 [ # # ]: 0 : if (ret) /* revert back */
1637 : 0 : memcpy(vf->rss_lut, lut, reta_size);
1638 : 0 : free(lut);
1639 : :
1640 : 0 : return ret;
1641 : : }
1642 : :
1643 : : static int
1644 : 0 : iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
1645 : : struct rte_eth_rss_reta_entry64 *reta_conf,
1646 : : uint16_t reta_size)
1647 : : {
1648 : 0 : struct iavf_adapter *adapter =
1649 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1650 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1651 : : uint16_t i, idx, shift;
1652 : :
1653 [ # # ]: 0 : if (adapter->closed)
1654 : : return -EIO;
1655 : :
1656 [ # # ]: 0 : if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1657 : : return -ENOTSUP;
1658 : :
1659 [ # # ]: 0 : if (reta_size != vf->vf_res->rss_lut_size) {
1660 : 0 : PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
1661 : : "(%d) doesn't match the number of hardware can "
1662 : : "support (%d)", reta_size, vf->vf_res->rss_lut_size);
1663 : 0 : return -EINVAL;
1664 : : }
1665 : :
1666 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
1667 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
1668 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
1669 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << shift))
1670 : 0 : reta_conf[idx].reta[shift] = vf->rss_lut[i];
1671 : : }
1672 : :
1673 : : return 0;
1674 : : }
1675 : :
1676 : : static int
1677 : 0 : iavf_set_rss_key(struct iavf_adapter *adapter, uint8_t *key, uint8_t key_len)
1678 : : {
1679 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1680 : :
1681 : : /* HENA setting, it is enabled by default, no change */
1682 [ # # ]: 0 : if (!key || key_len == 0) {
1683 : 0 : PMD_DRV_LOG(DEBUG, "No key to be configured");
1684 : 0 : return 0;
1685 [ # # ]: 0 : } else if (key_len != vf->vf_res->rss_key_size) {
1686 : 0 : PMD_DRV_LOG(ERR, "The size of hash key configured "
1687 : : "(%d) doesn't match the size of hardware can "
1688 : : "support (%d)", key_len,
1689 : : vf->vf_res->rss_key_size);
1690 : 0 : return -EINVAL;
1691 : : }
1692 : :
1693 : 0 : memcpy(vf->rss_key, key, key_len);
1694 : :
1695 : 0 : return iavf_configure_rss_key(adapter);
1696 : : }
1697 : :
1698 : : static int
1699 : 0 : iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
1700 : : struct rte_eth_rss_conf *rss_conf)
1701 : : {
1702 : 0 : struct iavf_adapter *adapter =
1703 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1704 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1705 : : int ret;
1706 : :
1707 : 0 : adapter->dev_data->dev_conf.rx_adv_conf.rss_conf = *rss_conf;
1708 : :
1709 [ # # ]: 0 : if (adapter->closed)
1710 : : return -EIO;
1711 : :
1712 [ # # ]: 0 : if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1713 : : return -ENOTSUP;
1714 : :
1715 : : /* Set hash key. */
1716 : 0 : ret = iavf_set_rss_key(adapter, rss_conf->rss_key,
1717 : 0 : rss_conf->rss_key_len);
1718 [ # # ]: 0 : if (ret)
1719 : : return ret;
1720 : :
1721 [ # # ]: 0 : if (rss_conf->rss_hf == 0) {
1722 : 0 : vf->rss_hf = 0;
1723 : 0 : ret = iavf_set_hena(adapter, 0);
1724 : :
1725 : : /* It is a workaround, temporarily allow error to be returned
1726 : : * due to possible lack of PF handling for hena = 0.
1727 : : */
1728 [ # # ]: 0 : if (ret)
1729 : 0 : PMD_DRV_LOG(WARNING, "fail to clean existing RSS, lack PF support");
1730 : 0 : return 0;
1731 : : }
1732 : :
1733 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF) {
1734 : : /* Clear existing RSS. */
1735 : 0 : ret = iavf_set_hena(adapter, 0);
1736 : :
1737 : : /* It is a workaround, temporarily allow error to be returned
1738 : : * due to possible lack of PF handling for hena = 0.
1739 : : */
1740 [ # # ]: 0 : if (ret)
1741 : 0 : PMD_DRV_LOG(WARNING, "fail to clean existing RSS,"
1742 : : "lack PF support");
1743 : :
1744 : : /* Set new RSS configuration. */
1745 : 0 : ret = iavf_rss_hash_set(adapter, rss_conf->rss_hf, true);
1746 [ # # ]: 0 : if (ret) {
1747 : 0 : PMD_DRV_LOG(ERR, "fail to set new RSS");
1748 : 0 : return ret;
1749 : : }
1750 : : } else {
1751 : 0 : iavf_config_rss_hf(adapter, rss_conf->rss_hf);
1752 : : }
1753 : :
1754 : : return 0;
1755 : : }
1756 : :
1757 : : static int
1758 : 0 : iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1759 : : struct rte_eth_rss_conf *rss_conf)
1760 : : {
1761 : 0 : struct iavf_adapter *adapter =
1762 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1763 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1764 : :
1765 [ # # ]: 0 : if (adapter->closed)
1766 : : return -EIO;
1767 : :
1768 [ # # ]: 0 : if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1769 : : return -ENOTSUP;
1770 : :
1771 : 0 : rss_conf->rss_hf = vf->rss_hf;
1772 : :
1773 [ # # ]: 0 : if (!rss_conf->rss_key)
1774 : : return 0;
1775 : :
1776 : 0 : rss_conf->rss_key_len = vf->vf_res->rss_key_size;
1777 : 0 : memcpy(rss_conf->rss_key, vf->rss_key, rss_conf->rss_key_len);
1778 : :
1779 : 0 : return 0;
1780 : : }
1781 : :
1782 : : static int
1783 : 0 : iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
1784 : : {
1785 : : /* mtu setting is forbidden if port is start */
1786 [ # # ]: 0 : if (dev->data->dev_started) {
1787 : 0 : PMD_DRV_LOG(ERR, "port must be stopped before configuration");
1788 : 0 : return -EBUSY;
1789 : : }
1790 : :
1791 : : return 0;
1792 : : }
1793 : :
1794 : : static int
1795 : 0 : iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
1796 : : struct rte_ether_addr *mac_addr)
1797 : : {
1798 : 0 : struct iavf_adapter *adapter =
1799 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1800 : : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1801 : : struct rte_ether_addr *old_addr;
1802 : : int ret;
1803 : :
1804 [ # # ]: 0 : old_addr = (struct rte_ether_addr *)hw->mac.addr;
1805 : :
1806 [ # # ]: 0 : if (rte_is_same_ether_addr(old_addr, mac_addr))
1807 : : return 0;
1808 : :
1809 [ # # ]: 0 : if (adapter->mac_primary_set) { /* delete old PRIMARY MAC only if set */
1810 : 0 : ret = iavf_add_del_eth_addr(adapter, old_addr, false, VIRTCHNL_ETHER_ADDR_PRIMARY);
1811 [ # # ]: 0 : if (ret)
1812 : 0 : PMD_DRV_LOG(ERR, "Fail to delete old MAC:"
1813 : : RTE_ETHER_ADDR_PRT_FMT,
1814 : : RTE_ETHER_ADDR_BYTES(old_addr));
1815 : : }
1816 : :
1817 : 0 : ret = iavf_add_del_eth_addr(adapter, mac_addr, true, VIRTCHNL_ETHER_ADDR_PRIMARY);
1818 [ # # ]: 0 : if (ret)
1819 : 0 : PMD_DRV_LOG(ERR, "Fail to add new MAC:"
1820 : : RTE_ETHER_ADDR_PRT_FMT,
1821 : : RTE_ETHER_ADDR_BYTES(mac_addr));
1822 : :
1823 [ # # ]: 0 : if (ret)
1824 : : return -EIO;
1825 : :
1826 [ # # ]: 0 : if (!adapter->mac_primary_set)
1827 : 0 : adapter->mac_primary_set = true;
1828 : :
1829 : : rte_ether_addr_copy(mac_addr, (struct rte_ether_addr *)hw->mac.addr);
1830 : 0 : return 0;
1831 : : }
1832 : :
1833 : : static void
1834 : : iavf_stat_update_48(uint64_t *offset, uint64_t *stat)
1835 : : {
1836 [ # # ]: 0 : if (*stat >= *offset)
1837 : 0 : *stat = *stat - *offset;
1838 : : else
1839 : 0 : *stat = (uint64_t)((*stat +
1840 : : ((uint64_t)1 << IAVF_48_BIT_WIDTH)) - *offset);
1841 : :
1842 [ # # # # : 0 : *stat &= IAVF_48_BIT_MASK;
# # # # #
# # # ]
1843 : : }
1844 : :
1845 : : static void
1846 : : iavf_stat_update_32(uint64_t *offset, uint64_t *stat)
1847 : : {
1848 [ # # # # : 0 : if (*stat >= *offset)
# # ]
1849 : 0 : *stat = (uint64_t)(*stat - *offset);
1850 : : else
1851 : 0 : *stat = (uint64_t)((*stat +
1852 : : ((uint64_t)1 << IAVF_32_BIT_WIDTH)) - *offset);
1853 : : }
1854 : :
1855 : : static void
1856 [ # # ]: 0 : iavf_update_stats(struct iavf_vsi *vsi, struct virtchnl_eth_stats *nes)
1857 : : {
1858 : : struct virtchnl_eth_stats *oes = &vsi->eth_stats_offset.eth_stats;
1859 : :
1860 : : iavf_stat_update_48(&oes->rx_bytes, &nes->rx_bytes);
1861 : : iavf_stat_update_48(&oes->rx_unicast, &nes->rx_unicast);
1862 : : iavf_stat_update_48(&oes->rx_multicast, &nes->rx_multicast);
1863 : : iavf_stat_update_48(&oes->rx_broadcast, &nes->rx_broadcast);
1864 : : iavf_stat_update_32(&oes->rx_discards, &nes->rx_discards);
1865 : : iavf_stat_update_48(&oes->tx_bytes, &nes->tx_bytes);
1866 : : iavf_stat_update_48(&oes->tx_unicast, &nes->tx_unicast);
1867 : : iavf_stat_update_48(&oes->tx_multicast, &nes->tx_multicast);
1868 : : iavf_stat_update_48(&oes->tx_broadcast, &nes->tx_broadcast);
1869 : : iavf_stat_update_32(&oes->tx_errors, &nes->tx_errors);
1870 : : iavf_stat_update_32(&oes->tx_discards, &nes->tx_discards);
1871 : 0 : }
1872 : :
1873 : : static int
1874 : 0 : iavf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
1875 : : struct eth_queue_stats *qstats __rte_unused)
1876 : : {
1877 : 0 : struct iavf_adapter *adapter =
1878 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1879 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1880 : 0 : struct iavf_vsi *vsi = &vf->vsi;
1881 : : struct virtchnl_eth_stats pstats;
1882 : : int ret;
1883 : :
1884 : 0 : ret = iavf_query_stats(adapter, &pstats);
1885 [ # # ]: 0 : if (ret == 0) {
1886 [ # # ]: 0 : uint8_t crc_stats_len = (dev->data->dev_conf.rxmode.offloads &
1887 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC) ? 0 :
1888 : : RTE_ETHER_CRC_LEN;
1889 : 0 : iavf_update_stats(vsi, &pstats);
1890 : 0 : stats->ipackets = pstats.rx_unicast + pstats.rx_multicast + pstats.rx_broadcast;
1891 : : /*
1892 : : * Unicast/multicast/broadcast counters include discarded packets, so subtract
1893 : : * rx_discards to report only the packets delivered to the application. The
1894 : : * counters are sampled from separate sources and can be momentarily inconsistent
1895 : : * under load. If rx_discards exceeds their sum then essentially nothing was
1896 : : * delivered, so saturate at zero rather than underflow.
1897 : : */
1898 : 0 : stats->ipackets = stats->ipackets >= pstats.rx_discards ?
1899 [ # # ]: 0 : stats->ipackets - pstats.rx_discards : 0;
1900 : 0 : stats->opackets = pstats.tx_broadcast + pstats.tx_multicast +
1901 : 0 : pstats.tx_unicast;
1902 : 0 : stats->imissed = pstats.rx_discards;
1903 : 0 : stats->oerrors = pstats.tx_errors + pstats.tx_discards;
1904 : 0 : stats->ibytes = pstats.rx_bytes;
1905 : 0 : stats->ibytes -= stats->ipackets * crc_stats_len;
1906 : 0 : stats->obytes = pstats.tx_bytes;
1907 : : } else {
1908 : 0 : PMD_DRV_LOG(ERR, "Get statistics failed");
1909 : : }
1910 : 0 : return ret;
1911 : : }
1912 : :
1913 : : static int
1914 : 0 : iavf_dev_stats_reset(struct rte_eth_dev *dev)
1915 : : {
1916 : : int ret;
1917 : 0 : struct iavf_adapter *adapter =
1918 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1919 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1920 : : struct iavf_vsi *vsi = &vf->vsi;
1921 : : struct virtchnl_eth_stats stats;
1922 : :
1923 : : /* read stat values to clear hardware registers */
1924 : 0 : ret = iavf_query_stats(adapter, &stats);
1925 [ # # ]: 0 : if (ret != 0)
1926 : : return ret;
1927 : :
1928 : : /* set stats offset base on current values */
1929 : 0 : vsi->eth_stats_offset.eth_stats = stats;
1930 : :
1931 : 0 : return 0;
1932 : : }
1933 : :
1934 : : static int
1935 : 0 : iavf_dev_xstats_reset(struct rte_eth_dev *dev)
1936 : : {
1937 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1938 : 0 : iavf_dev_stats_reset(dev);
1939 : 0 : memset(&vf->vsi.eth_stats_offset.ips_stats, 0,
1940 : : sizeof(struct iavf_ipsec_crypto_stats));
1941 : 0 : memset(&vf->vsi.eth_stats_offset.mbuf_stats, 0,
1942 : : sizeof(struct iavf_mbuf_stats));
1943 : :
1944 : 0 : return 0;
1945 : : }
1946 : :
1947 : 0 : static int iavf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1948 : : struct rte_eth_xstat_name *xstats_names,
1949 : : __rte_unused unsigned int limit)
1950 : : {
1951 : : unsigned int i;
1952 : :
1953 [ # # ]: 0 : if (xstats_names != NULL)
1954 [ # # ]: 0 : for (i = 0; i < IAVF_NB_XSTATS; i++) {
1955 : 0 : snprintf(xstats_names[i].name,
1956 : : sizeof(xstats_names[i].name),
1957 : 0 : "%s", rte_iavf_stats_strings[i].name);
1958 : : }
1959 : 0 : return IAVF_NB_XSTATS;
1960 : : }
1961 : :
1962 : : static void
1963 : 0 : iavf_dev_update_ipsec_xstats(struct rte_eth_dev *ethdev,
1964 : : struct iavf_ipsec_crypto_stats *ips)
1965 : : {
1966 : : uint16_t idx;
1967 [ # # ]: 0 : for (idx = 0; idx < ethdev->data->nb_rx_queues; idx++) {
1968 : : struct ci_rx_queue *rxq;
1969 : : struct iavf_ipsec_crypto_stats *stats;
1970 : 0 : rxq = (struct ci_rx_queue *)ethdev->data->rx_queues[idx];
1971 : 0 : stats = &rxq->stats->ipsec_crypto;
1972 : 0 : ips->icount += stats->icount;
1973 : 0 : ips->ibytes += stats->ibytes;
1974 : 0 : ips->ierrors.count += stats->ierrors.count;
1975 : 0 : ips->ierrors.sad_miss += stats->ierrors.sad_miss;
1976 : 0 : ips->ierrors.not_processed += stats->ierrors.not_processed;
1977 : 0 : ips->ierrors.icv_check += stats->ierrors.icv_check;
1978 : 0 : ips->ierrors.ipsec_length += stats->ierrors.ipsec_length;
1979 : 0 : ips->ierrors.misc += stats->ierrors.misc;
1980 : : }
1981 : 0 : }
1982 : :
1983 : : static void
1984 : : iavf_dev_update_mbuf_stats(struct rte_eth_dev *ethdev,
1985 : : struct iavf_mbuf_stats *mbuf_stats)
1986 : : {
1987 : : uint16_t idx;
1988 : : struct ci_tx_queue *txq;
1989 : :
1990 [ # # ]: 0 : for (idx = 0; idx < ethdev->data->nb_tx_queues; idx++) {
1991 : 0 : txq = ethdev->data->tx_queues[idx];
1992 : 0 : mbuf_stats->tx_pkt_errors += txq->mbuf_errors;
1993 : : }
1994 : : }
1995 : :
1996 : 0 : static int iavf_dev_xstats_get(struct rte_eth_dev *dev,
1997 : : struct rte_eth_xstat *xstats, unsigned int n)
1998 : : {
1999 : : int ret;
2000 : : unsigned int i;
2001 : 0 : struct iavf_adapter *adapter =
2002 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2003 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2004 : 0 : struct iavf_vsi *vsi = &vf->vsi;
2005 : : struct virtchnl_eth_stats stats;
2006 : 0 : struct iavf_eth_xstats iavf_xtats = {{0}};
2007 : :
2008 [ # # ]: 0 : if (n < IAVF_NB_XSTATS)
2009 : : return IAVF_NB_XSTATS;
2010 : :
2011 : 0 : ret = iavf_query_stats(adapter, &stats);
2012 [ # # ]: 0 : if (ret != 0)
2013 : : return 0;
2014 : :
2015 [ # # ]: 0 : if (!xstats)
2016 : : return 0;
2017 : :
2018 : 0 : iavf_update_stats(vsi, &stats);
2019 : 0 : iavf_xtats.eth_stats = stats;
2020 : :
2021 [ # # ]: 0 : if (iavf_ipsec_crypto_supported(adapter))
2022 : 0 : iavf_dev_update_ipsec_xstats(dev, &iavf_xtats.ips_stats);
2023 : :
2024 [ # # ]: 0 : if (adapter->devargs.mbuf_check)
2025 : : iavf_dev_update_mbuf_stats(dev, &iavf_xtats.mbuf_stats);
2026 : :
2027 : : /* loop over xstats array and values from pstats */
2028 [ # # ]: 0 : for (i = 0; i < IAVF_NB_XSTATS; i++) {
2029 : 0 : xstats[i].id = i;
2030 : 0 : xstats[i].value = *(uint64_t *)(((char *)&iavf_xtats) +
2031 : 0 : rte_iavf_stats_strings[i].offset);
2032 : : }
2033 : :
2034 : : return IAVF_NB_XSTATS;
2035 : : }
2036 : :
2037 : :
2038 : : static int
2039 : 0 : iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
2040 : : {
2041 : 0 : struct iavf_adapter *adapter =
2042 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2043 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2044 : : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
2045 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2046 : : uint16_t msix_intr;
2047 : :
2048 [ # # ]: 0 : if (adapter->closed)
2049 : : return -EIO;
2050 : :
2051 : 0 : msix_intr = rte_intr_vec_list_index_get(pci_dev->intr_handle,
2052 : : queue_id);
2053 [ # # ]: 0 : if (msix_intr == IAVF_MISC_VEC_ID) {
2054 : 0 : PMD_DRV_LOG(INFO, "MISC is also enabled for control");
2055 : 0 : IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
2056 : : IAVF_VFINT_DYN_CTL01_INTENA_MASK |
2057 : : IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
2058 : : IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
2059 : : } else {
2060 : 0 : IAVF_WRITE_REG(hw,
2061 : : IAVF_VFINT_DYN_CTLN1
2062 : : (msix_intr - IAVF_RX_VEC_START),
2063 : : IAVF_VFINT_DYN_CTLN1_INTENA_MASK |
2064 : : IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
2065 : : IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK);
2066 : : }
2067 : :
2068 : 0 : IAVF_WRITE_FLUSH(hw);
2069 : :
2070 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
2071 : 0 : rte_intr_ack(pci_dev->intr_handle);
2072 : :
2073 : : return 0;
2074 : : }
2075 : :
2076 : : static int
2077 : 0 : iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
2078 : : {
2079 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2080 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2081 : : uint16_t msix_intr;
2082 : :
2083 : 0 : msix_intr = rte_intr_vec_list_index_get(pci_dev->intr_handle,
2084 : : queue_id);
2085 [ # # ]: 0 : if (msix_intr == IAVF_MISC_VEC_ID) {
2086 : 0 : PMD_DRV_LOG(ERR, "MISC is used for control, cannot disable it");
2087 : 0 : return -EIO;
2088 : : }
2089 : :
2090 : 0 : IAVF_WRITE_REG(hw,
2091 : : IAVF_VFINT_DYN_CTLN1(msix_intr - IAVF_RX_VEC_START),
2092 : : IAVF_VFINT_DYN_CTLN1_WB_ON_ITR_MASK);
2093 : :
2094 : 0 : IAVF_WRITE_FLUSH(hw);
2095 : 0 : return 0;
2096 : : }
2097 : :
2098 : : static int
2099 : : iavf_check_vf_reset_done(struct iavf_hw *hw)
2100 : : {
2101 : : int i, reset;
2102 : :
2103 [ # # # # ]: 0 : for (i = 0; i < IAVF_RESET_WAIT_CNT; i++) {
2104 : 0 : reset = IAVF_READ_REG(hw, IAVF_VFGEN_RSTAT) &
2105 : : IAVF_VFGEN_RSTAT_VFR_STATE_MASK;
2106 : : reset = reset >> IAVF_VFGEN_RSTAT_VFR_STATE_SHIFT;
2107 [ # # # # ]: 0 : if (reset == VIRTCHNL_VFR_VFACTIVE ||
2108 : : reset == VIRTCHNL_VFR_COMPLETED)
2109 : : break;
2110 : : rte_delay_ms(20);
2111 : : }
2112 : :
2113 [ # # # # ]: 0 : if (i >= IAVF_RESET_WAIT_CNT)
2114 : : return -1;
2115 : :
2116 : : return 0;
2117 : : }
2118 : :
2119 : : static int
2120 : 0 : iavf_lookup_proto_xtr_type(const char *flex_name)
2121 : : {
2122 : : static struct {
2123 : : const char *name;
2124 : : enum iavf_proto_xtr_type type;
2125 : : } xtr_type_map[] = {
2126 : : { "vlan", IAVF_PROTO_XTR_VLAN },
2127 : : { "ipv4", IAVF_PROTO_XTR_IPV4 },
2128 : : { "ipv6", IAVF_PROTO_XTR_IPV6 },
2129 : : { "ipv6_flow", IAVF_PROTO_XTR_IPV6_FLOW },
2130 : : { "tcp", IAVF_PROTO_XTR_TCP },
2131 : : { "ip_offset", IAVF_PROTO_XTR_IP_OFFSET },
2132 : : { "ipsec_crypto_said", IAVF_PROTO_XTR_IPSEC_CRYPTO_SAID },
2133 : : };
2134 : : uint32_t i;
2135 : :
2136 [ # # ]: 0 : for (i = 0; i < RTE_DIM(xtr_type_map); i++) {
2137 [ # # ]: 0 : if (strcmp(flex_name, xtr_type_map[i].name) == 0)
2138 : 0 : return xtr_type_map[i].type;
2139 : : }
2140 : :
2141 : 0 : PMD_DRV_LOG(ERR, "wrong proto_xtr type, it should be: "
2142 : : "vlan|ipv4|ipv6|ipv6_flow|tcp|ip_offset|ipsec_crypto_said");
2143 : :
2144 : 0 : return -1;
2145 : : }
2146 : :
2147 : : /**
2148 : : * Parse elem, the elem could be single number/range or '(' ')' group
2149 : : * 1) A single number elem, it's just a simple digit. e.g. 9
2150 : : * 2) A single range elem, two digits with a '-' between. e.g. 2-6
2151 : : * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
2152 : : * Within group elem, '-' used for a range separator;
2153 : : * ',' used for a single number.
2154 : : */
2155 : : static int
2156 : 0 : iavf_parse_queue_set(const char *input, int xtr_type,
2157 : : struct iavf_devargs *devargs)
2158 : : {
2159 : : const char *str = input;
2160 : 0 : char *end = NULL;
2161 : : uint32_t min, max;
2162 : : uint32_t idx;
2163 : :
2164 [ # # ]: 0 : while (isblank(*str))
2165 : 0 : str++;
2166 : :
2167 [ # # # # ]: 0 : if (!isdigit(*str) && *str != '(')
2168 : : return -1;
2169 : :
2170 : : /* process single number or single range of number */
2171 [ # # ]: 0 : if (*str != '(') {
2172 : 0 : errno = 0;
2173 : 0 : idx = strtoul(str, &end, 10);
2174 [ # # # # : 0 : if (errno || !end || idx >= IAVF_MAX_QUEUE_NUM)
# # ]
2175 : : return -1;
2176 : :
2177 [ # # ]: 0 : while (isblank(*end))
2178 : 0 : end++;
2179 : :
2180 : : min = idx;
2181 : : max = idx;
2182 : :
2183 : : /* process single <number>-<number> */
2184 [ # # ]: 0 : if (*end == '-') {
2185 : 0 : end++;
2186 [ # # ]: 0 : while (isblank(*end))
2187 : 0 : end++;
2188 [ # # ]: 0 : if (!isdigit(*end))
2189 : : return -1;
2190 : :
2191 : 0 : errno = 0;
2192 : 0 : idx = strtoul(end, &end, 10);
2193 [ # # # # : 0 : if (errno || !end || idx >= IAVF_MAX_QUEUE_NUM)
# # ]
2194 : : return -1;
2195 : :
2196 : : max = idx;
2197 [ # # ]: 0 : while (isblank(*end))
2198 : 0 : end++;
2199 : : }
2200 : :
2201 [ # # ]: 0 : if (*end != ':')
2202 : : return -1;
2203 : :
2204 : 0 : for (idx = RTE_MIN(min, max);
2205 [ # # ]: 0 : idx <= RTE_MAX(min, max); idx++)
2206 : 0 : devargs->proto_xtr[idx] = xtr_type;
2207 : :
2208 : : return 0;
2209 : : }
2210 : :
2211 : : /* process set within bracket */
2212 : 0 : str++;
2213 [ # # ]: 0 : while (isblank(*str))
2214 : 0 : str++;
2215 [ # # ]: 0 : if (*str == '\0')
2216 : : return -1;
2217 : :
2218 : : min = IAVF_MAX_QUEUE_NUM;
2219 : : do {
2220 : : /* go ahead to the first digit */
2221 [ # # ]: 0 : while (isblank(*str))
2222 : 0 : str++;
2223 [ # # ]: 0 : if (!isdigit(*str))
2224 : : return -1;
2225 : :
2226 : : /* get the digit value */
2227 : 0 : errno = 0;
2228 : 0 : idx = strtoul(str, &end, 10);
2229 [ # # # # : 0 : if (errno || !end || idx >= IAVF_MAX_QUEUE_NUM)
# # ]
2230 : : return -1;
2231 : :
2232 : : /* go ahead to separator '-',',' and ')' */
2233 [ # # ]: 0 : while (isblank(*end))
2234 : 0 : end++;
2235 [ # # ]: 0 : if (*end == '-') {
2236 [ # # ]: 0 : if (min == IAVF_MAX_QUEUE_NUM)
2237 : : min = idx;
2238 : : else /* avoid continuous '-' */
2239 : : return -1;
2240 [ # # ]: 0 : } else if (*end == ',' || *end == ')') {
2241 : : max = idx;
2242 [ # # ]: 0 : if (min == IAVF_MAX_QUEUE_NUM)
2243 : : min = idx;
2244 : :
2245 : 0 : for (idx = RTE_MIN(min, max);
2246 [ # # ]: 0 : idx <= RTE_MAX(min, max); idx++)
2247 : 0 : devargs->proto_xtr[idx] = xtr_type;
2248 : :
2249 : : min = IAVF_MAX_QUEUE_NUM;
2250 : : } else {
2251 : : return -1;
2252 : : }
2253 : :
2254 : 0 : str = end + 1;
2255 [ # # ]: 0 : } while (*end != ')' && *end != '\0');
2256 : :
2257 : : return 0;
2258 : : }
2259 : :
2260 : : static int
2261 : 0 : iavf_parse_queue_proto_xtr(const char *queues, struct iavf_devargs *devargs)
2262 : : {
2263 : : const char *queue_start;
2264 : : uint32_t idx;
2265 : : int xtr_type;
2266 : : char flex_name[32];
2267 : :
2268 [ # # ]: 0 : while (isblank(*queues))
2269 : 0 : queues++;
2270 : :
2271 [ # # ]: 0 : if (*queues != '[') {
2272 : 0 : xtr_type = iavf_lookup_proto_xtr_type(queues);
2273 [ # # ]: 0 : if (xtr_type < 0)
2274 : : return -1;
2275 : :
2276 : 0 : devargs->proto_xtr_dflt = xtr_type;
2277 : :
2278 : 0 : return 0;
2279 : : }
2280 : :
2281 : 0 : queues++;
2282 : : do {
2283 [ # # ]: 0 : while (isblank(*queues))
2284 : 0 : queues++;
2285 [ # # ]: 0 : if (*queues == '\0')
2286 : : return -1;
2287 : :
2288 : : queue_start = queues;
2289 : :
2290 : : /* go across a complete bracket */
2291 [ # # ]: 0 : if (*queue_start == '(') {
2292 : 0 : queues += strcspn(queues, ")");
2293 [ # # ]: 0 : if (*queues != ')')
2294 : : return -1;
2295 : : }
2296 : :
2297 : : /* scan the separator ':' */
2298 : 0 : queues += strcspn(queues, ":");
2299 [ # # ]: 0 : if (*queues++ != ':')
2300 : : return -1;
2301 [ # # ]: 0 : while (isblank(*queues))
2302 : 0 : queues++;
2303 : :
2304 : 0 : for (idx = 0; ; idx++) {
2305 [ # # # # ]: 0 : if (isblank(queues[idx]) ||
2306 [ # # ]: 0 : queues[idx] == ',' ||
2307 [ # # ]: 0 : queues[idx] == ']' ||
2308 : : queues[idx] == '\0')
2309 : : break;
2310 : :
2311 [ # # ]: 0 : if (idx > sizeof(flex_name) - 2)
2312 : : return -1;
2313 : :
2314 : 0 : flex_name[idx] = queues[idx];
2315 : : }
2316 : 0 : flex_name[idx] = '\0';
2317 : 0 : xtr_type = iavf_lookup_proto_xtr_type(flex_name);
2318 [ # # ]: 0 : if (xtr_type < 0)
2319 : : return -1;
2320 : :
2321 : : queues += idx;
2322 : :
2323 [ # # # # : 0 : while (isblank(*queues) || *queues == ',' || *queues == ']')
# # ]
2324 : 0 : queues++;
2325 : :
2326 [ # # ]: 0 : if (iavf_parse_queue_set(queue_start, xtr_type, devargs) < 0)
2327 : : return -1;
2328 [ # # ]: 0 : } while (*queues != '\0');
2329 : :
2330 : : return 0;
2331 : : }
2332 : :
2333 : : static int
2334 : 0 : iavf_handle_proto_xtr_arg(__rte_unused const char *key, const char *value,
2335 : : void *extra_args)
2336 : : {
2337 : : struct iavf_devargs *devargs = extra_args;
2338 : :
2339 [ # # ]: 0 : if (!value || !extra_args)
2340 : : return -EINVAL;
2341 : :
2342 [ # # ]: 0 : if (iavf_parse_queue_proto_xtr(value, devargs) < 0) {
2343 : 0 : PMD_DRV_LOG(ERR, "the proto_xtr's parameter is wrong : '%s'",
2344 : : value);
2345 : 0 : return -1;
2346 : : }
2347 : :
2348 : : return 0;
2349 : : }
2350 : :
2351 : : static int
2352 : 0 : parse_u16(__rte_unused const char *key, const char *value, void *args)
2353 : : {
2354 : : u16 *num = (u16 *)args;
2355 : : u16 tmp;
2356 : :
2357 : 0 : errno = 0;
2358 : 0 : tmp = strtoull(value, NULL, 10);
2359 [ # # # # ]: 0 : if (errno || !tmp) {
2360 : 0 : PMD_DRV_LOG(WARNING, "%s: \"%s\" is not a valid u16",
2361 : : key, value);
2362 : 0 : return -1;
2363 : : }
2364 : :
2365 : 0 : *num = tmp;
2366 : :
2367 : 0 : return 0;
2368 : : }
2369 : :
2370 : : static int
2371 : 0 : parse_bool(const char *key, const char *value, void *args)
2372 : : {
2373 : : int *i = (int *)args;
2374 : : char *end;
2375 : : int num;
2376 : :
2377 : 0 : num = strtoul(value, &end, 10);
2378 : :
2379 [ # # ]: 0 : if (num != 0 && num != 1) {
2380 : 0 : PMD_DRV_LOG(WARNING, "invalid value:\"%s\" for key:\"%s\", "
2381 : : "value must be 0 or 1",
2382 : : value, key);
2383 : 0 : return -1;
2384 : : }
2385 : :
2386 : 0 : *i = num;
2387 : 0 : return 0;
2388 : : }
2389 : :
2390 : : static int
2391 : 0 : iavf_parse_watchdog_period(__rte_unused const char *key, const char *value, void *args)
2392 : : {
2393 : : int *num = (int *)args;
2394 : : int tmp;
2395 : :
2396 : 0 : errno = 0;
2397 : : tmp = atoi(value);
2398 [ # # ]: 0 : if (tmp < 0) {
2399 : 0 : PMD_DRV_LOG(WARNING, "%s: \"%s\" is not greater than or equal to zero",
2400 : : key, value);
2401 : 0 : return -1;
2402 : : }
2403 : :
2404 : 0 : *num = tmp;
2405 : :
2406 : 0 : return 0;
2407 : : }
2408 : :
2409 : : static int
2410 : 0 : iavf_parse_mbuf_check(__rte_unused const char *key, const char *value, void *args)
2411 : : {
2412 : : char *cur;
2413 : : char *tmp;
2414 : : int str_len;
2415 : : int valid_len;
2416 : : int ret = 0;
2417 : : uint64_t *mc_flags = args;
2418 : 0 : char *str2 = strdup(value);
2419 : :
2420 [ # # ]: 0 : if (str2 == NULL)
2421 : : return -1;
2422 : :
2423 : 0 : str_len = strlen(str2);
2424 [ # # ]: 0 : if (str_len == 0) {
2425 : : ret = -1;
2426 : 0 : goto err_end;
2427 : : }
2428 : :
2429 : : /* Try stripping the outer square brackets of the parameter string. */
2430 [ # # # # ]: 0 : if (str2[0] == '[' && str2[str_len - 1] == ']') {
2431 [ # # ]: 0 : if (str_len < 3) {
2432 : : ret = -1;
2433 : 0 : goto err_end;
2434 : : }
2435 : 0 : valid_len = str_len - 2;
2436 : 0 : memmove(str2, str2 + 1, valid_len);
2437 : 0 : memset(str2 + valid_len, '\0', 2);
2438 : : }
2439 : :
2440 : 0 : cur = strtok_r(str2, ",", &tmp);
2441 [ # # ]: 0 : while (cur != NULL) {
2442 [ # # ]: 0 : if (!strcmp(cur, "mbuf"))
2443 : 0 : *mc_flags |= IAVF_MBUF_CHECK_F_TX_MBUF;
2444 [ # # ]: 0 : else if (!strcmp(cur, "size"))
2445 : 0 : *mc_flags |= IAVF_MBUF_CHECK_F_TX_SIZE;
2446 [ # # ]: 0 : else if (!strcmp(cur, "segment"))
2447 : 0 : *mc_flags |= IAVF_MBUF_CHECK_F_TX_SEGMENT;
2448 [ # # ]: 0 : else if (!strcmp(cur, "offload"))
2449 : 0 : *mc_flags |= IAVF_MBUF_CHECK_F_TX_OFFLOAD;
2450 : : else
2451 : 0 : PMD_DRV_LOG(ERR, "Unsupported diagnostic type: %s", cur);
2452 : 0 : cur = strtok_r(NULL, ",", &tmp);
2453 : : }
2454 : :
2455 : 0 : err_end:
2456 : 0 : free(str2);
2457 : 0 : return ret;
2458 : : }
2459 : :
2460 : 0 : static int iavf_parse_devargs(struct rte_eth_dev *dev)
2461 : : {
2462 : 0 : struct iavf_adapter *ad =
2463 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2464 : 0 : struct rte_devargs *devargs = dev->device->devargs;
2465 : : struct rte_kvargs *kvlist;
2466 : : int ret;
2467 : 0 : int watchdog_period = -1;
2468 : :
2469 : 0 : ad->devargs.auto_reset = 1;
2470 : 0 : ad->devargs.no_poll_on_link_down = 1;
2471 : 0 : ad->devargs.auto_reconfig = 1;
2472 : :
2473 [ # # ]: 0 : if (!devargs)
2474 : : return 0;
2475 : :
2476 : 0 : kvlist = rte_kvargs_parse(devargs->args, iavf_valid_args);
2477 [ # # ]: 0 : if (!kvlist) {
2478 : 0 : PMD_INIT_LOG(ERR, "invalid kvargs key");
2479 : 0 : return -EINVAL;
2480 : : }
2481 : :
2482 : 0 : ad->devargs.proto_xtr_dflt = IAVF_PROTO_XTR_NONE;
2483 : 0 : memset(ad->devargs.proto_xtr, IAVF_PROTO_XTR_NONE,
2484 : : sizeof(ad->devargs.proto_xtr));
2485 : :
2486 : 0 : ret = rte_kvargs_process(kvlist, IAVF_PROTO_XTR_ARG,
2487 : 0 : &iavf_handle_proto_xtr_arg, &ad->devargs);
2488 [ # # ]: 0 : if (ret)
2489 : 0 : goto bail;
2490 : :
2491 : 0 : ret = rte_kvargs_process(kvlist, IAVF_QUANTA_SIZE_ARG,
2492 : 0 : &parse_u16, &ad->devargs.quanta_size);
2493 [ # # ]: 0 : if (ret)
2494 : 0 : goto bail;
2495 : :
2496 : 0 : ret = rte_kvargs_process(kvlist, IAVF_RESET_WATCHDOG_ARG,
2497 : : &iavf_parse_watchdog_period, &watchdog_period);
2498 [ # # ]: 0 : if (ret)
2499 : 0 : goto bail;
2500 [ # # ]: 0 : if (watchdog_period == -1)
2501 : 0 : ad->devargs.watchdog_period = IAVF_DEV_WATCHDOG_PERIOD;
2502 : : else
2503 : 0 : ad->devargs.watchdog_period = watchdog_period;
2504 : :
2505 : 0 : ret = rte_kvargs_process(kvlist, IAVF_NO_POLL_ON_LINK_DOWN_ARG,
2506 : 0 : &parse_bool, &ad->devargs.no_poll_on_link_down);
2507 [ # # ]: 0 : if (ret)
2508 : 0 : goto bail;
2509 : :
2510 [ # # ]: 0 : if (ad->devargs.quanta_size != 0 &&
2511 [ # # # # ]: 0 : (ad->devargs.quanta_size < 256 || ad->devargs.quanta_size > 4096 ||
2512 : : ad->devargs.quanta_size & 0x40)) {
2513 : 0 : PMD_INIT_LOG(ERR, "invalid quanta size");
2514 : : ret = -EINVAL;
2515 : 0 : goto bail;
2516 : : }
2517 : :
2518 : 0 : ret = rte_kvargs_process(kvlist, IAVF_MBUF_CHECK_ARG,
2519 : 0 : &iavf_parse_mbuf_check, &ad->devargs.mbuf_check);
2520 [ # # ]: 0 : if (ret)
2521 : 0 : goto bail;
2522 : :
2523 : 0 : ret = rte_kvargs_process(kvlist, IAVF_ENABLE_AUTO_RESET_ARG,
2524 : 0 : &parse_bool, &ad->devargs.auto_reset);
2525 [ # # ]: 0 : if (ret)
2526 : 0 : goto bail;
2527 : :
2528 [ # # # # ]: 0 : if (ad->devargs.auto_reset != 0 && ad->devargs.no_poll_on_link_down == 0) {
2529 : 0 : PMD_INIT_LOG(WARNING,
2530 : : "no-poll-on-link-down=0 is incompatible with auto_reset=1, ignoring");
2531 : 0 : ad->devargs.no_poll_on_link_down = 1;
2532 : : }
2533 : :
2534 : 0 : ret = rte_kvargs_process(kvlist, IAVF_ENABLE_AUTO_RECONFIG_ARG,
2535 : 0 : &parse_bool, &ad->devargs.auto_reconfig);
2536 [ # # ]: 0 : if (ret)
2537 : 0 : goto bail;
2538 : :
2539 : 0 : ret = rte_kvargs_process(kvlist, IAVF_ENABLE_PTYPE_LLDP_ARG,
2540 : 0 : &parse_bool, &ad->devargs.enable_ptype_lldp);
2541 [ # # ]: 0 : if (ret)
2542 : 0 : goto bail;
2543 : :
2544 : 0 : bail:
2545 : 0 : rte_kvargs_free(kvlist);
2546 : 0 : return ret;
2547 : : }
2548 : :
2549 : : static void
2550 : 0 : iavf_init_proto_xtr(struct rte_eth_dev *dev)
2551 : : {
2552 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2553 : : struct iavf_adapter *ad =
2554 : : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2555 : : const struct iavf_proto_xtr_ol *xtr_ol;
2556 : : bool proto_xtr_enable = false;
2557 : : int offset;
2558 : : uint16_t i;
2559 : :
2560 : 0 : vf->proto_xtr = rte_zmalloc("vf proto xtr",
2561 : 0 : vf->vsi_res->num_queue_pairs, 0);
2562 [ # # ]: 0 : if (unlikely(!(vf->proto_xtr))) {
2563 : 0 : PMD_DRV_LOG(ERR, "no memory for setting up proto_xtr's table");
2564 : 0 : return;
2565 : : }
2566 : :
2567 [ # # ]: 0 : for (i = 0; i < vf->vsi_res->num_queue_pairs; i++) {
2568 [ # # ]: 0 : vf->proto_xtr[i] = ad->devargs.proto_xtr[i] !=
2569 : : IAVF_PROTO_XTR_NONE ?
2570 : : ad->devargs.proto_xtr[i] :
2571 : : ad->devargs.proto_xtr_dflt;
2572 : :
2573 [ # # ]: 0 : if (vf->proto_xtr[i] != IAVF_PROTO_XTR_NONE) {
2574 : : uint8_t type = vf->proto_xtr[i];
2575 : :
2576 : 0 : iavf_proto_xtr_params[type].required = true;
2577 : : proto_xtr_enable = true;
2578 : : }
2579 : : }
2580 : :
2581 [ # # ]: 0 : if (likely(!proto_xtr_enable))
2582 : : return;
2583 : :
2584 : 0 : offset = rte_mbuf_dynfield_register(&iavf_proto_xtr_metadata_param);
2585 [ # # ]: 0 : if (unlikely(offset == -1)) {
2586 : 0 : PMD_DRV_LOG(ERR,
2587 : : "failed to extract protocol metadata, error %d",
2588 : : -rte_errno);
2589 : 0 : return;
2590 : : }
2591 : :
2592 : 0 : PMD_DRV_LOG(DEBUG,
2593 : : "proto_xtr metadata offset in mbuf is : %d",
2594 : : offset);
2595 : 0 : rte_pmd_ifd_dynfield_proto_xtr_metadata_offs = offset;
2596 : :
2597 [ # # ]: 0 : for (i = 0; i < RTE_DIM(iavf_proto_xtr_params); i++) {
2598 : 0 : xtr_ol = &iavf_proto_xtr_params[i];
2599 : :
2600 : 0 : uint8_t rxdid = iavf_proto_xtr_type_to_rxdid((uint8_t)i);
2601 : :
2602 [ # # ]: 0 : if (!xtr_ol->required)
2603 : 0 : continue;
2604 : :
2605 [ # # ]: 0 : if (!(vf->supported_rxdid & RTE_BIT64(rxdid))) {
2606 : 0 : PMD_DRV_LOG(ERR,
2607 : : "rxdid[%u] is not supported in hardware",
2608 : : rxdid);
2609 : 0 : rte_pmd_ifd_dynfield_proto_xtr_metadata_offs = -1;
2610 : 0 : break;
2611 : : }
2612 : :
2613 : 0 : offset = rte_mbuf_dynflag_register(&xtr_ol->param);
2614 [ # # ]: 0 : if (unlikely(offset == -1)) {
2615 : 0 : PMD_DRV_LOG(ERR,
2616 : : "failed to register proto_xtr offload '%s', error %d",
2617 : : xtr_ol->param.name, -rte_errno);
2618 : :
2619 : 0 : rte_pmd_ifd_dynfield_proto_xtr_metadata_offs = -1;
2620 : 0 : break;
2621 : : }
2622 : :
2623 : 0 : PMD_DRV_LOG(DEBUG,
2624 : : "proto_xtr offload '%s' offset in mbuf is : %d",
2625 : : xtr_ol->param.name, offset);
2626 : 0 : *xtr_ol->ol_flag = 1ULL << offset;
2627 : : }
2628 : : }
2629 : :
2630 : : static int
2631 : 0 : iavf_init_vf(struct rte_eth_dev *dev)
2632 : : {
2633 : : int err, bufsz;
2634 : 0 : struct iavf_adapter *adapter =
2635 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2636 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2637 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2638 : :
2639 : 0 : vf->eth_dev = dev;
2640 : :
2641 : 0 : err = iavf_parse_devargs(dev);
2642 [ # # ]: 0 : if (err) {
2643 : 0 : PMD_INIT_LOG(ERR, "Failed to parse devargs");
2644 : 0 : goto err;
2645 : : }
2646 : :
2647 : 0 : err = iavf_set_mac_type(hw);
2648 [ # # ]: 0 : if (err) {
2649 : 0 : PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
2650 : 0 : goto err;
2651 : : }
2652 : :
2653 : : err = iavf_check_vf_reset_done(hw);
2654 : : if (err) {
2655 : 0 : PMD_INIT_LOG(ERR, "VF is still resetting");
2656 : 0 : goto err;
2657 : : }
2658 : :
2659 : : iavf_init_adminq_parameter(hw);
2660 : 0 : err = iavf_init_adminq(hw);
2661 [ # # ]: 0 : if (err) {
2662 : 0 : PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
2663 : 0 : goto err;
2664 : : }
2665 : :
2666 [ # # ]: 0 : if (iavf_check_api_version(adapter) != 0) {
2667 : 0 : PMD_INIT_LOG(ERR, "check_api version failed");
2668 : 0 : goto err_api;
2669 : : }
2670 : :
2671 : : bufsz = sizeof(struct virtchnl_vf_resource) +
2672 : : (IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource));
2673 : 0 : vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
2674 [ # # ]: 0 : if (!vf->vf_res) {
2675 : 0 : PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
2676 : 0 : goto err_api;
2677 : : }
2678 : :
2679 [ # # ]: 0 : if (iavf_get_vf_resource(adapter) != 0) {
2680 : 0 : PMD_INIT_LOG(ERR, "iavf_get_vf_config failed");
2681 : 0 : goto err_alloc;
2682 : : }
2683 : : /* Allocate memort for RSS info */
2684 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
2685 : 0 : vf->rss_key = rte_zmalloc("rss_key",
2686 : 0 : vf->vf_res->rss_key_size, 0);
2687 [ # # ]: 0 : if (!vf->rss_key) {
2688 : 0 : PMD_INIT_LOG(ERR, "unable to allocate rss_key memory");
2689 : 0 : goto err_rss;
2690 : : }
2691 : 0 : vf->rss_lut = rte_zmalloc("rss_lut",
2692 : 0 : vf->vf_res->rss_lut_size, 0);
2693 [ # # ]: 0 : if (!vf->rss_lut) {
2694 : 0 : PMD_INIT_LOG(ERR, "unable to allocate rss_lut memory");
2695 : 0 : goto err_rss;
2696 : : }
2697 : : }
2698 : :
2699 [ # # ]: 0 : if (vf->vsi_res->num_queue_pairs > IAVF_MAX_NUM_QUEUES_DFLT)
2700 : 0 : vf->lv_enabled = true;
2701 : :
2702 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
2703 [ # # ]: 0 : if (iavf_get_supported_rxdid(adapter) != 0) {
2704 : 0 : PMD_INIT_LOG(ERR, "failed to do get supported rxdid");
2705 : 0 : goto err_rss;
2706 : : }
2707 : : }
2708 : :
2709 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
2710 [ # # ]: 0 : if (iavf_get_vlan_offload_caps_v2(adapter) != 0) {
2711 : 0 : PMD_INIT_LOG(ERR, "failed to do get VLAN offload v2 capabilities");
2712 : 0 : goto err_rss;
2713 : : }
2714 : : }
2715 : :
2716 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_QOS) {
2717 : : bufsz = sizeof(struct virtchnl_qos_cap_list) +
2718 : : IAVF_MAX_TRAFFIC_CLASS *
2719 : : sizeof(struct virtchnl_qos_cap_elem);
2720 : 0 : vf->qos_cap = rte_zmalloc("qos_cap", bufsz, 0);
2721 [ # # ]: 0 : if (!vf->qos_cap) {
2722 : 0 : PMD_INIT_LOG(ERR, "unable to allocate qos_cap memory");
2723 : 0 : goto err_rss;
2724 : : }
2725 : 0 : iavf_tm_conf_init(dev);
2726 : : }
2727 : :
2728 : 0 : iavf_init_proto_xtr(dev);
2729 : :
2730 : 0 : return 0;
2731 : 0 : err_rss:
2732 : 0 : rte_free(vf->rss_key);
2733 : 0 : rte_free(vf->rss_lut);
2734 : 0 : err_alloc:
2735 : 0 : rte_free(vf->qos_cap);
2736 : 0 : rte_free(vf->vf_res);
2737 : 0 : vf->vsi_res = NULL;
2738 : 0 : err_api:
2739 : 0 : iavf_shutdown_adminq(hw);
2740 : : err:
2741 : : return -1;
2742 : : }
2743 : :
2744 : : static void
2745 : 0 : iavf_uninit_vf(struct rte_eth_dev *dev)
2746 : : {
2747 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2748 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2749 : :
2750 : 0 : iavf_shutdown_adminq(hw);
2751 : :
2752 : 0 : rte_free(vf->vf_res);
2753 : 0 : vf->vsi_res = NULL;
2754 : 0 : vf->vf_res = NULL;
2755 : :
2756 : 0 : rte_free(vf->qos_cap);
2757 : 0 : vf->qos_cap = NULL;
2758 : 0 : free(vf->qtc_map);
2759 : 0 : vf->qtc_map = NULL;
2760 : 0 : rte_free(vf->proto_xtr);
2761 : 0 : vf->proto_xtr = NULL;
2762 : :
2763 : 0 : rte_free(vf->rss_lut);
2764 : 0 : vf->rss_lut = NULL;
2765 : 0 : rte_free(vf->rss_key);
2766 : 0 : vf->rss_key = NULL;
2767 : 0 : }
2768 : :
2769 : : /* Enable default admin queue interrupt setting */
2770 : : static inline void
2771 : : iavf_enable_irq0(struct iavf_hw *hw)
2772 : : {
2773 : : /* Enable admin queue interrupt trigger */
2774 : 0 : IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1,
2775 : : IAVF_VFINT_ICR0_ENA1_ADMINQ_MASK);
2776 : :
2777 : 0 : IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
2778 : : IAVF_VFINT_DYN_CTL01_INTENA_MASK |
2779 : : IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
2780 : : IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
2781 : :
2782 : 0 : IAVF_WRITE_FLUSH(hw);
2783 : 0 : }
2784 : :
2785 : : static inline void
2786 : : iavf_disable_irq0(struct iavf_hw *hw)
2787 : : {
2788 : : /* Disable all interrupt types */
2789 : 0 : IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1, 0);
2790 : 0 : IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
2791 : : IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
2792 : 0 : IAVF_WRITE_FLUSH(hw);
2793 : : }
2794 : :
2795 : : static void
2796 : 0 : iavf_dev_interrupt_handler(void *param)
2797 : : {
2798 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2799 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2800 : :
2801 : : iavf_disable_irq0(hw);
2802 : :
2803 : 0 : iavf_handle_virtchnl_msg(dev);
2804 : :
2805 : : iavf_enable_irq0(hw);
2806 : 0 : }
2807 : :
2808 : : static struct ci_rx_queue *
2809 : : iavf_phc_sync_rxq_get(struct rte_eth_dev *dev)
2810 : : {
2811 : : struct ci_rx_queue *rxq;
2812 : : uint16_t i;
2813 : :
2814 [ # # # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2815 : 0 : rxq = dev->data->rx_queues[i];
2816 [ # # # # ]: 0 : if (rxq != NULL)
2817 : : return rxq;
2818 : : }
2819 : :
2820 : : return NULL;
2821 : : }
2822 : :
2823 : : static void
2824 : : iavf_phc_sync_update_all_rxq(struct rte_eth_dev *dev,
2825 : : uint64_t phc_time,
2826 : : uint64_t sw_cur_time)
2827 : : {
2828 : : struct ci_rx_queue *rxq;
2829 : : uint16_t i;
2830 : :
2831 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2832 : 0 : rxq = dev->data->rx_queues[i];
2833 [ # # ]: 0 : if (rxq == NULL)
2834 : 0 : continue;
2835 : :
2836 : 0 : rxq->phc_time = phc_time;
2837 : 0 : rxq->hw_time_update = sw_cur_time;
2838 : : }
2839 : : }
2840 : :
2841 : : static void
2842 : 0 : iavf_phc_sync_tick(struct rte_eth_dev *dev)
2843 : : {
2844 : : struct iavf_adapter *adapter;
2845 : : const uint16_t phc_sync_ticks_max = RTE_MAX((uint16_t)1,
2846 : : (uint16_t)(IAVF_PHC_SYNC_ALARM_INTERVAL_US / IAVF_ALARM_INTERVAL));
2847 : : struct ci_rx_queue *sync_rxq;
2848 : : uint64_t sw_cur_time;
2849 : :
2850 : 0 : adapter = IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2851 : :
2852 : 0 : rte_spinlock_lock(&adapter->phc_sync_lock);
2853 [ # # # # ]: 0 : if (adapter->phc_sync_paused || !iavf_phc_sync_alarm_needed(dev)) {
2854 : 0 : adapter->phc_sync_ticks = 0;
2855 : 0 : goto unlock;
2856 : : }
2857 : :
2858 [ # # ]: 0 : if (++adapter->phc_sync_ticks < phc_sync_ticks_max)
2859 : 0 : goto unlock;
2860 : :
2861 : 0 : adapter->phc_sync_ticks = 0;
2862 : : sync_rxq = iavf_phc_sync_rxq_get(dev);
2863 [ # # ]: 0 : if (sync_rxq == NULL)
2864 : 0 : goto unlock;
2865 : :
2866 [ # # ]: 0 : if (iavf_get_phc_time(sync_rxq) != 0) {
2867 : 0 : PMD_DRV_LOG(ERR, "get physical time failed");
2868 : 0 : goto unlock;
2869 : : }
2870 : :
2871 : 0 : sw_cur_time = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
2872 : 0 : iavf_phc_sync_update_all_rxq(dev, sync_rxq->phc_time, sw_cur_time);
2873 : :
2874 : 0 : unlock:
2875 : : rte_spinlock_unlock(&adapter->phc_sync_lock);
2876 : 0 : }
2877 : :
2878 : : void
2879 : 0 : iavf_dev_alarm_handler(void *param)
2880 : : {
2881 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2882 : : struct iavf_info *vf;
2883 [ # # # # : 0 : if (dev == NULL || dev->data == NULL || dev->data->dev_private == NULL)
# # ]
2884 : : return;
2885 : :
2886 : : vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2887 : : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2888 : : uint32_t icr0;
2889 : :
2890 [ # # ]: 0 : if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)) {
2891 : : iavf_disable_irq0(hw);
2892 : :
2893 : : /* read out interrupt causes */
2894 : 0 : icr0 = IAVF_READ_REG(hw, IAVF_VFINT_ICR01);
2895 : :
2896 [ # # ]: 0 : if (icr0 & IAVF_VFINT_ICR01_ADMINQ_MASK) {
2897 : 0 : PMD_DRV_LOG(DEBUG, "ICR01_ADMINQ is reported");
2898 : 0 : iavf_handle_virtchnl_msg(dev);
2899 : : }
2900 : :
2901 : : iavf_enable_irq0(hw);
2902 : : }
2903 : :
2904 : 0 : iavf_phc_sync_tick(dev);
2905 : :
2906 : 0 : rte_eal_alarm_set(IAVF_ALARM_INTERVAL,
2907 : : iavf_dev_alarm_handler, dev);
2908 : : }
2909 : :
2910 : : static bool
2911 : 0 : iavf_phc_sync_alarm_needed(struct rte_eth_dev *dev)
2912 : : {
2913 : : struct iavf_adapter *adapter;
2914 : :
2915 : 0 : adapter = IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2916 : :
2917 [ # # ]: 0 : if (adapter->closed || adapter->stopped)
2918 : : return false;
2919 : :
2920 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP))
2921 : : return false;
2922 : :
2923 [ # # ]: 0 : if (dev->data->nb_rx_queues == 0)
2924 : : return false;
2925 : :
2926 [ # # ]: 0 : if (iavf_phc_sync_rxq_get(dev) == NULL)
2927 : 0 : return false;
2928 : :
2929 : : return true;
2930 : : }
2931 : :
2932 : : void
2933 : 0 : iavf_phc_sync_alarm_start(struct rte_eth_dev *dev)
2934 : : {
2935 : : struct iavf_adapter *adapter;
2936 : :
2937 [ # # ]: 0 : if (!iavf_phc_sync_alarm_needed(dev))
2938 : : return;
2939 : :
2940 : 0 : adapter = IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2941 : 0 : rte_spinlock_lock(&adapter->phc_sync_lock);
2942 : 0 : adapter->phc_sync_paused = false;
2943 : 0 : adapter->phc_sync_ticks = 0;
2944 : : rte_spinlock_unlock(&adapter->phc_sync_lock);
2945 : : }
2946 : :
2947 : : void
2948 : 0 : iavf_phc_sync_alarm_stop(struct rte_eth_dev *dev)
2949 : : {
2950 : : struct iavf_adapter *adapter;
2951 : :
2952 [ # # # # : 0 : if (dev == NULL || dev->data == NULL || dev->data->dev_private == NULL)
# # ]
2953 : : return;
2954 : :
2955 : : adapter = IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2956 : 0 : rte_spinlock_lock(&adapter->phc_sync_lock);
2957 : 0 : adapter->phc_sync_paused = true;
2958 : 0 : adapter->phc_sync_ticks = 0;
2959 : : rte_spinlock_unlock(&adapter->phc_sync_lock);
2960 : : }
2961 : :
2962 : : static int
2963 : 0 : iavf_dev_flow_ops_get(struct rte_eth_dev *dev,
2964 : : const struct rte_flow_ops **ops)
2965 : : {
2966 : 0 : struct iavf_adapter *adapter =
2967 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2968 : :
2969 [ # # ]: 0 : if (adapter->closed)
2970 : : return -EIO;
2971 : :
2972 : 0 : *ops = &iavf_flow_ops;
2973 : 0 : return 0;
2974 : : }
2975 : :
2976 : : static void
2977 : 0 : iavf_default_rss_disable(struct iavf_adapter *adapter)
2978 : : {
2979 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2980 : : int ret = 0;
2981 : :
2982 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
2983 : : /* Set hena = 0 to ask PF to cleanup all existing RSS. */
2984 : 0 : ret = iavf_set_hena(adapter, 0);
2985 [ # # ]: 0 : if (ret)
2986 : : /* It is a workaround, temporarily allow error to be
2987 : : * returned due to possible lack of PF handling for
2988 : : * hena = 0.
2989 : : */
2990 : 0 : PMD_INIT_LOG(WARNING, "fail to disable default RSS,"
2991 : : "lack PF support");
2992 : : }
2993 : 0 : }
2994 : :
2995 : : static int
2996 : 0 : iavf_dev_init(struct rte_eth_dev *eth_dev)
2997 : : {
2998 : 0 : struct iavf_adapter *adapter =
2999 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
3000 : : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
3001 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
3002 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(eth_dev, *pci_dev);
3003 : : int ret = 0;
3004 : :
3005 : 0 : PMD_INIT_FUNC_TRACE();
3006 : :
3007 : : /* assign ops func pointer */
3008 : 0 : eth_dev->dev_ops = &iavf_eth_dev_ops;
3009 : 0 : eth_dev->rx_queue_count = iavf_dev_rxq_count;
3010 : 0 : eth_dev->rx_descriptor_status = iavf_dev_rx_desc_status;
3011 : 0 : eth_dev->tx_descriptor_status = iavf_dev_tx_desc_status;
3012 : 0 : eth_dev->rx_pkt_burst = &iavf_recv_pkts;
3013 : 0 : eth_dev->tx_pkt_burst = &iavf_xmit_pkts;
3014 : 0 : eth_dev->tx_pkt_prepare = &iavf_prep_pkts;
3015 : :
3016 : : /* For secondary processes, we don't initialise any further as primary
3017 : : * has already done this work.
3018 : : */
3019 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
3020 : 0 : iavf_set_rx_function(eth_dev);
3021 : : /* LLDP may have been enabled by the primary process. Store the offset before
3022 : : * setting the TX function because it may be used in the selection function.
3023 : : */
3024 : 0 : rte_pmd_iavf_tx_lldp_dynfield_offset =
3025 : 0 : rte_mbuf_dynfield_lookup(IAVF_TX_LLDP_DYNFIELD, NULL);
3026 : 0 : iavf_set_tx_function(eth_dev);
3027 : 0 : return 0;
3028 : : }
3029 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
3030 : :
3031 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
3032 : 0 : hw->device_id = pci_dev->id.device_id;
3033 : 0 : hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
3034 : 0 : hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
3035 : 0 : hw->bus.bus_id = pci_dev->addr.bus;
3036 : 0 : hw->bus.device = pci_dev->addr.devid;
3037 : 0 : hw->bus.func = pci_dev->addr.function;
3038 : 0 : hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
3039 : 0 : hw->back = IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
3040 : 0 : adapter->dev_data = eth_dev->data;
3041 : 0 : adapter->stopped = 1;
3042 : 0 : adapter->mac_primary_set = false;
3043 [ # # ]: 0 : adapter->tpid = RTE_ETHER_TYPE_VLAN; /* VLAN TPID set to 0x8100 by default */
3044 : : rte_spinlock_init(&adapter->phc_sync_lock);
3045 : :
3046 [ # # # # ]: 0 : if (!vf->in_reset_recovery && iavf_dev_event_handler_init())
3047 : 0 : goto init_vf_err;
3048 : :
3049 [ # # ]: 0 : if (iavf_init_vf(eth_dev) != 0) {
3050 : 0 : PMD_INIT_LOG(ERR, "Init vf failed");
3051 : 0 : return -1;
3052 : : }
3053 : :
3054 : : /* set default ptype table */
3055 : 0 : iavf_set_default_ptype_table(eth_dev);
3056 : :
3057 : : /* copy mac addr */
3058 : 0 : eth_dev->data->mac_addrs = rte_zmalloc(
3059 : : "iavf_mac", RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX, 0);
3060 [ # # ]: 0 : if (!eth_dev->data->mac_addrs) {
3061 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to"
3062 : : " store MAC addresses",
3063 : : RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX);
3064 : : ret = -ENOMEM;
3065 : 0 : goto init_vf_err;
3066 : : }
3067 : : /* If the MAC address is not configured by host,
3068 : : * generate a random one.
3069 : : */
3070 : : if (!rte_is_valid_assigned_ether_addr(
3071 : : (struct rte_ether_addr *)hw->mac.addr))
3072 : 0 : rte_eth_random_addr(hw->mac.addr);
3073 : 0 : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
3074 [ # # ]: 0 : ð_dev->data->mac_addrs[0]);
3075 : :
3076 : :
3077 [ # # # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR &&
3078 : : /* register callback func to eal lib */
3079 : 0 : rte_intr_callback_register(pci_dev->intr_handle,
3080 : : iavf_dev_interrupt_handler, (void *)eth_dev) == 0)
3081 : :
3082 : : /* enable uio intr after callback register */
3083 : 0 : rte_intr_enable(pci_dev->intr_handle);
3084 : :
3085 : 0 : rte_eal_alarm_set(IAVF_ALARM_INTERVAL,
3086 : : iavf_dev_alarm_handler, eth_dev);
3087 : :
3088 : : /* configure and enable device interrupt */
3089 : : iavf_enable_irq0(hw);
3090 : 0 : vf->aq_intr_enabled = true;
3091 : :
3092 : 0 : ret = iavf_flow_init(adapter);
3093 [ # # ]: 0 : if (ret) {
3094 : 0 : PMD_INIT_LOG(ERR, "Failed to initialize flow");
3095 : 0 : goto flow_init_err;
3096 : : }
3097 : :
3098 : : /** Check if the IPsec Crypto offload is supported and create
3099 : : * security_ctx if it is.
3100 : : */
3101 [ # # ]: 0 : if (iavf_ipsec_crypto_supported(adapter)) {
3102 : : /* Initialize security_ctx only for primary process*/
3103 : 0 : ret = iavf_security_ctx_create(adapter);
3104 [ # # ]: 0 : if (ret) {
3105 : 0 : PMD_INIT_LOG(ERR, "failed to create ipsec crypto security instance");
3106 : 0 : goto flow_init_err;
3107 : : }
3108 : :
3109 : 0 : ret = iavf_security_init(adapter);
3110 [ # # ]: 0 : if (ret) {
3111 : 0 : PMD_INIT_LOG(ERR, "failed to initialized ipsec crypto resources");
3112 : 0 : goto security_init_err;
3113 : : }
3114 : : }
3115 : :
3116 : : /* Get PTP caps early to verify device capabilities */
3117 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP) {
3118 [ # # ]: 0 : if (iavf_get_ptp_cap(adapter)) {
3119 : 0 : PMD_INIT_LOG(ERR, "Failed to get ptp capability");
3120 : 0 : goto security_init_err;
3121 : : }
3122 : : }
3123 : :
3124 : 0 : iavf_default_rss_disable(adapter);
3125 : :
3126 : 0 : iavf_dev_stats_reset(eth_dev);
3127 : :
3128 : : /* Start device watchdog */
3129 : 0 : iavf_dev_watchdog_enable(adapter);
3130 : 0 : adapter->closed = false;
3131 : :
3132 : 0 : return 0;
3133 : :
3134 : 0 : security_init_err:
3135 : 0 : iavf_security_ctx_destroy(adapter);
3136 : :
3137 : 0 : flow_init_err:
3138 : 0 : vf->aq_intr_enabled = false;
3139 : : iavf_disable_irq0(hw);
3140 : :
3141 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
3142 : : /* disable uio intr before callback unregiser */
3143 : 0 : rte_intr_disable(pci_dev->intr_handle);
3144 : :
3145 : : /* unregister callback func from eal lib */
3146 : 0 : rte_intr_callback_unregister(pci_dev->intr_handle,
3147 : : iavf_dev_interrupt_handler, eth_dev);
3148 : : }
3149 : 0 : iavf_phc_sync_alarm_stop(eth_dev);
3150 : 0 : rte_eal_alarm_cancel(iavf_dev_alarm_handler, eth_dev);
3151 : :
3152 : 0 : rte_free(eth_dev->data->mac_addrs);
3153 : 0 : eth_dev->data->mac_addrs = NULL;
3154 : :
3155 : 0 : init_vf_err:
3156 : 0 : iavf_uninit_vf(eth_dev);
3157 : :
3158 : 0 : return ret;
3159 : : }
3160 : :
3161 : : static int
3162 : 0 : iavf_dev_close(struct rte_eth_dev *dev)
3163 : : {
3164 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3165 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
3166 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
3167 : : struct iavf_adapter *adapter =
3168 : : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3169 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
3170 : : int ret;
3171 : :
3172 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3173 : : return 0;
3174 : :
3175 [ # # ]: 0 : if (adapter->closed) {
3176 : : ret = 0;
3177 : 0 : goto out;
3178 : : }
3179 : :
3180 : 0 : ret = iavf_dev_stop(dev);
3181 : :
3182 : : /*
3183 : : * Prevent sending close-time virtchnl messages to the AdminQ
3184 : : * during PF-initiated reset recovery.
3185 : : */
3186 [ # # ]: 0 : if (!vf->pf_reset_in_progress) {
3187 : :
3188 : : /*
3189 : : * Release redundant queue resource when close the dev
3190 : : * so that other vfs can re-use the queues.
3191 : : */
3192 [ # # ]: 0 : if (vf->lv_enabled) {
3193 : 0 : ret = iavf_request_queues(dev, IAVF_MAX_NUM_QUEUES_DFLT);
3194 [ # # ]: 0 : if (ret)
3195 : 0 : PMD_DRV_LOG(ERR, "Reset the num of queues failed");
3196 : 0 : vf->max_rss_qregion = IAVF_MAX_NUM_QUEUES_DFLT;
3197 : : }
3198 : :
3199 : : /*
3200 : : * Disable promiscuous mode before resetting the VF. This is to avoid
3201 : : * potential issues when the PF is bound to the kernel driver.
3202 : : */
3203 [ # # ]: 0 : if (vf->promisc_unicast_enabled || vf->promisc_multicast_enabled)
3204 : 0 : iavf_config_promisc(adapter, false, false);
3205 : : }
3206 : :
3207 : 0 : adapter->closed = true;
3208 : :
3209 : : /* free iAVF security device context all related resources */
3210 : 0 : iavf_security_ctx_destroy(adapter);
3211 : :
3212 : : /* remove RSS configuration */
3213 : 0 : iavf_hash_uninit(adapter);
3214 : :
3215 : 0 : iavf_flow_flush(dev, NULL);
3216 : 0 : iavf_flow_uninit(adapter);
3217 : :
3218 : : /*
3219 : : * Prevent sending VIRTCHNL_OP_RESET_VF during PF-initiated
3220 : : * reset recovery.
3221 : : */
3222 [ # # ]: 0 : if (!vf->pf_reset_in_progress)
3223 : 0 : iavf_vf_reset(hw);
3224 : : /*
3225 : : * If a reset is pending, wait for the PF to disable the VF's admin
3226 : : * receive queue (its first reset action) before we shut it down
3227 : : * ourselves. This ensures iavf_check_vf_reset_done() does not see
3228 : : * a stale VFACTIVE value on the re-init path.
3229 : : */
3230 [ # # ]: 0 : if (vf->reset_pending)
3231 : : iavf_is_reset_detected(adapter);
3232 : 0 : vf->aq_intr_enabled = false;
3233 : 0 : iavf_shutdown_adminq(hw);
3234 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
3235 : : /* disable uio intr before callback unregister */
3236 : 0 : rte_intr_disable(intr_handle);
3237 : :
3238 : : /* unregister callback func from eal lib */
3239 : 0 : rte_intr_callback_unregister(intr_handle,
3240 : : iavf_dev_interrupt_handler, dev);
3241 : : }
3242 : 0 : iavf_phc_sync_alarm_stop(dev);
3243 : 0 : rte_eal_alarm_cancel(iavf_dev_alarm_handler, dev);
3244 : : iavf_disable_irq0(hw);
3245 : :
3246 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_QOS)
3247 : 0 : iavf_tm_conf_uninit(dev);
3248 : :
3249 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
3250 [ # # ]: 0 : if (vf->rss_lut) {
3251 : 0 : rte_free(vf->rss_lut);
3252 : 0 : vf->rss_lut = NULL;
3253 : : }
3254 [ # # ]: 0 : if (vf->rss_key) {
3255 : 0 : rte_free(vf->rss_key);
3256 : 0 : vf->rss_key = NULL;
3257 : : }
3258 : : }
3259 : :
3260 : 0 : rte_free(vf->proto_xtr);
3261 : 0 : vf->proto_xtr = NULL;
3262 : :
3263 : 0 : rte_free(vf->vf_res);
3264 : 0 : vf->vsi_res = NULL;
3265 : 0 : vf->vf_res = NULL;
3266 : :
3267 : : /*
3268 : : * If the VF is reset via VFLR, the device will be knocked out of bus
3269 : : * master mode, and the driver will fail to recover from the reset. Fix
3270 : : * this by enabling bus mastering after every reset. In a non-VFLR case,
3271 : : * the bus master bit will not be disabled, and this call will have no
3272 : : * effect.
3273 : : */
3274 : 0 : out:
3275 [ # # # # ]: 0 : if (vf->vf_reset && !rte_pci_set_bus_master(pci_dev, true)) {
3276 : 0 : vf->vf_reset = false;
3277 : 0 : iavf_set_no_poll(adapter, false);
3278 : : }
3279 : :
3280 : : /* disable watchdog */
3281 : 0 : iavf_dev_watchdog_disable(adapter);
3282 : :
3283 : 0 : return ret;
3284 : : }
3285 : :
3286 : : static int
3287 : 0 : iavf_dev_uninit(struct rte_eth_dev *dev)
3288 : : {
3289 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
3290 : :
3291 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3292 : : return -EPERM;
3293 : :
3294 : 0 : iavf_dev_close(dev);
3295 : :
3296 [ # # ]: 0 : if (!vf->in_reset_recovery)
3297 : 0 : iavf_dev_event_handler_fini();
3298 : :
3299 : : return 0;
3300 : : }
3301 : :
3302 : : /*
3303 : : * Reset VF device only to re-initialize resources in PMD layer
3304 : : */
3305 : : static int
3306 : 0 : iavf_dev_reset(struct rte_eth_dev *dev)
3307 : : {
3308 : : int ret;
3309 : 0 : struct iavf_adapter *adapter =
3310 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3311 : : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3312 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
3313 : : /*
3314 : : * Check whether the VF reset has been done and inform application,
3315 : : * to avoid calling the virtual channel command, which may cause
3316 : : * the device to be abnormal.
3317 : : */
3318 : : ret = iavf_check_vf_reset_done(hw);
3319 : : if (ret) {
3320 : 0 : PMD_DRV_LOG(ERR, "Wait too long for reset done!");
3321 : 0 : return ret;
3322 : : }
3323 : 0 : iavf_set_no_poll(adapter, false);
3324 : :
3325 : 0 : vf->reset_pending = true;
3326 : 0 : PMD_DRV_LOG(DEBUG, "Start dev_reset ...");
3327 : 0 : ret = iavf_dev_uninit(dev);
3328 : 0 : vf->reset_pending = false;
3329 [ # # ]: 0 : if (ret)
3330 : : return ret;
3331 : :
3332 : 0 : return iavf_dev_init(dev);
3333 : : }
3334 : :
3335 : : static inline bool
3336 : : iavf_is_reset(struct iavf_hw *hw)
3337 : : {
3338 : 0 : return !(IAVF_READ_REG(hw, IAVF_VF_ARQLEN1) &
3339 : : IAVF_VF_ARQLEN1_ARQENABLE_MASK);
3340 : : }
3341 : :
3342 : : static bool
3343 : : iavf_is_reset_detected(struct iavf_adapter *adapter)
3344 : : {
3345 : : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
3346 : : int i;
3347 : :
3348 : : /* poll until we see the reset actually happen */
3349 [ # # # # ]: 0 : for (i = 0; i < IAVF_RESET_DETECTED_CNT; i++) {
3350 [ # # # # ]: 0 : if (iavf_is_reset(hw))
3351 : : return true;
3352 : : rte_delay_ms(20);
3353 : : }
3354 : :
3355 : : return false;
3356 : : }
3357 : :
3358 : : static int
3359 : 0 : iavf_post_reset_reconfig(struct rte_eth_dev *dev)
3360 : : {
3361 : : int ret, status = 0;
3362 : : bool allmulti = false, allunicast = false;
3363 : 0 : struct iavf_adapter *adapter = IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3364 : :
3365 : : /* Restore pre-reset unicast promiscuous and multicast promiscuous states */
3366 [ # # ]: 0 : if (dev->data->promiscuous)
3367 : : allunicast = true;
3368 [ # # ]: 0 : if (dev->data->all_multicast)
3369 : : allmulti = true;
3370 [ # # ]: 0 : if (allmulti || allunicast) {
3371 : 0 : ret = iavf_config_promisc(adapter, allunicast, allmulti);
3372 [ # # ]: 0 : if (ret)
3373 [ # # # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to restore unicast promiscuous mode (%s) "
3374 : : "and multicast promiscuous mode (%s)",
3375 : : allunicast ? "on" : "off", allmulti ? "on" : "off");
3376 : : else
3377 [ # # # # ]: 0 : PMD_DRV_LOG(DEBUG, "Restored unicast promiscuous mode (%s) "
3378 : : "and multicast promiscuous mode (%s)",
3379 : : allunicast ? "on" : "off", allmulti ? "on" : "off");
3380 : : status |= ret;
3381 : : }
3382 : :
3383 : 0 : return status;
3384 : : }
3385 : :
3386 : : /*
3387 : : * Handle hardware reset
3388 : : */
3389 : : void
3390 : 0 : iavf_handle_hw_reset(struct rte_eth_dev *dev, bool vf_initiated_reset)
3391 : : {
3392 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
3393 : : struct iavf_adapter *adapter = dev->data->dev_private;
3394 : : int ret;
3395 : : bool restart_device = false;
3396 : :
3397 [ # # ]: 0 : if (vf_initiated_reset) {
3398 : 0 : restart_device = dev->data->dev_started;
3399 : : } else {
3400 [ # # ]: 0 : if (!dev->data->dev_started)
3401 : : return;
3402 : :
3403 [ # # ]: 0 : if (!iavf_is_reset_detected(adapter)) {
3404 : 0 : PMD_DRV_LOG(DEBUG, "reset not start");
3405 : 0 : return;
3406 : : }
3407 : : }
3408 : :
3409 : 0 : vf->in_reset_recovery = true;
3410 : 0 : vf->pf_reset_in_progress = !vf_initiated_reset;
3411 : 0 : iavf_set_no_poll(adapter, false);
3412 : :
3413 : : /* Call the pre reset callback */
3414 [ # # ]: 0 : if (vf->pre_reset_cb != NULL)
3415 : 0 : vf->pre_reset_cb(dev->data->port_id, vf->pre_reset_cb_arg);
3416 : :
3417 : 0 : ret = iavf_dev_reset(dev);
3418 [ # # ]: 0 : if (ret)
3419 : 0 : goto error;
3420 : :
3421 : : /* VF states restore */
3422 : 0 : ret = iavf_dev_configure(dev);
3423 [ # # ]: 0 : if (ret)
3424 : 0 : goto error;
3425 : :
3426 : 0 : iavf_dev_xstats_reset(dev);
3427 : :
3428 [ # # ]: 0 : if (!vf_initiated_reset || restart_device) {
3429 : : /* start the device */
3430 : 0 : ret = iavf_dev_start(dev);
3431 [ # # ]: 0 : if (ret)
3432 : 0 : goto error;
3433 : :
3434 : 0 : dev->data->dev_started = 1;
3435 : : }
3436 : :
3437 : : /* Restore settings after the reset */
3438 [ # # ]: 0 : if (adapter->devargs.auto_reconfig) {
3439 : 0 : ret = iavf_post_reset_reconfig(dev);
3440 [ # # ]: 0 : if (ret) {
3441 : 0 : PMD_DRV_LOG(ERR, "Failed to restore VF settings after reset");
3442 : 0 : goto error;
3443 : : }
3444 : : } else {
3445 : 0 : dev->data->promiscuous = 0;
3446 : 0 : dev->data->all_multicast = 0;
3447 : 0 : vf->promisc_unicast_enabled = false;
3448 : 0 : vf->promisc_multicast_enabled = false;
3449 : : }
3450 : :
3451 : 0 : goto exit;
3452 : :
3453 : 0 : error:
3454 : 0 : PMD_DRV_LOG(DEBUG, "RESET recover with error code=%d", ret);
3455 : 0 : exit:
3456 : : /* Call the post reset callback */
3457 [ # # ]: 0 : if (vf->post_reset_cb != NULL)
3458 : 0 : vf->post_reset_cb(dev->data->port_id, ret, vf->post_reset_cb_arg);
3459 : :
3460 : 0 : vf->in_reset_recovery = false;
3461 : 0 : vf->pf_reset_in_progress = false;
3462 : 0 : iavf_set_no_poll(adapter, false);
3463 : :
3464 : 0 : return;
3465 : : }
3466 : :
3467 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_iavf_reinit, 25.11)
3468 : : int
3469 : 0 : rte_pmd_iavf_reinit(uint16_t port)
3470 : : {
3471 : : struct rte_eth_dev *dev;
3472 : : struct iavf_adapter *adapter;
3473 : :
3474 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
3475 : :
3476 : 0 : dev = &rte_eth_devices[port];
3477 : :
3478 [ # # ]: 0 : if (!is_iavf_supported(dev)) {
3479 : 0 : PMD_DRV_LOG(ERR, "Cannot reinit VF, port %u is not an IAVF device.", port);
3480 : 0 : return -ENOTSUP;
3481 : : }
3482 : :
3483 [ # # ]: 0 : if (!dev->data->dev_configured) {
3484 : 0 : PMD_DRV_LOG(ERR, "Cannot reinit unconfigured port %u.", port);
3485 : 0 : return -EINVAL;
3486 : : }
3487 : :
3488 : 0 : adapter = dev->data->dev_private;
3489 [ # # # # ]: 0 : if (dev->data->dev_started && !adapter->devargs.no_poll_on_link_down) {
3490 : 0 : PMD_DRV_LOG(ERR, "Cannot reinit started port %u. Either stop the port or enable "
3491 : : "no-poll-on-link-down in devargs.", port);
3492 : 0 : return -EINVAL;
3493 : : }
3494 : :
3495 : 0 : iavf_handle_hw_reset(dev, true);
3496 : :
3497 : 0 : return 0;
3498 : : }
3499 : :
3500 : : static int
3501 : 0 : iavf_validate_reset_cb(uint16_t port, void *cb, void *cb_arg)
3502 : : {
3503 : : struct rte_eth_dev *dev;
3504 : : struct iavf_info *vf;
3505 : :
3506 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
3507 : :
3508 [ # # ]: 0 : if (cb == NULL && cb_arg != NULL) {
3509 : 0 : PMD_DRV_LOG(ERR, "Cannot unregister reset cb on port %u, arg must be NULL.", port);
3510 : 0 : return -EINVAL;
3511 : : }
3512 : :
3513 : 0 : dev = &rte_eth_devices[port];
3514 [ # # ]: 0 : if (!is_iavf_supported(dev)) {
3515 : 0 : PMD_DRV_LOG(ERR, "Cannot modify reset cb, port %u not an IAVF device.", port);
3516 : 0 : return -ENOTSUP;
3517 : : }
3518 : :
3519 : 0 : vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
3520 [ # # ]: 0 : if (vf->in_reset_recovery) {
3521 : 0 : PMD_DRV_LOG(ERR, "Cannot modify reset cb on port %u, VF is resetting.", port);
3522 : 0 : return -EBUSY;
3523 : : }
3524 : :
3525 : : return 0;
3526 : : }
3527 : :
3528 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_iavf_register_pre_reset_cb, 26.03)
3529 : : int
3530 : 0 : rte_pmd_iavf_register_pre_reset_cb(uint16_t port,
3531 : : iavf_pre_reset_cb_t pre_reset_cb,
3532 : : void *pre_reset_cb_arg)
3533 : : {
3534 : : struct rte_eth_dev *dev;
3535 : : struct iavf_info *vf;
3536 : : int ret;
3537 : :
3538 : 0 : ret = iavf_validate_reset_cb(port, pre_reset_cb, pre_reset_cb_arg);
3539 [ # # ]: 0 : if (ret)
3540 : : return ret;
3541 : :
3542 : : dev = &rte_eth_devices[port];
3543 : 0 : vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
3544 : 0 : vf->pre_reset_cb = pre_reset_cb;
3545 : 0 : vf->pre_reset_cb_arg = pre_reset_cb_arg;
3546 : :
3547 : 0 : return 0;
3548 : : }
3549 : :
3550 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_iavf_register_post_reset_cb, 26.03)
3551 : : int
3552 : 0 : rte_pmd_iavf_register_post_reset_cb(uint16_t port,
3553 : : iavf_post_reset_cb_t post_reset_cb,
3554 : : void *post_reset_cb_arg)
3555 : : {
3556 : : struct rte_eth_dev *dev;
3557 : : struct iavf_info *vf;
3558 : : int ret;
3559 : :
3560 : 0 : ret = iavf_validate_reset_cb(port, post_reset_cb, post_reset_cb_arg);
3561 [ # # ]: 0 : if (ret)
3562 : : return ret;
3563 : :
3564 : : dev = &rte_eth_devices[port];
3565 : 0 : vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
3566 : 0 : vf->post_reset_cb = post_reset_cb;
3567 : 0 : vf->post_reset_cb_arg = post_reset_cb_arg;
3568 : :
3569 : 0 : return 0;
3570 : : }
3571 : :
3572 : : void
3573 : 0 : iavf_set_no_poll(struct iavf_adapter *adapter, bool link_change)
3574 : : {
3575 : : struct iavf_info *vf = &adapter->vf;
3576 : :
3577 : 0 : adapter->no_poll = (link_change & !vf->link_up) ||
3578 [ # # # # : 0 : vf->vf_reset || vf->in_reset_recovery;
# # ]
3579 : 0 : }
3580 : :
3581 : : static int
3582 : 0 : iavf_dcf_cap_check_handler(__rte_unused const char *key,
3583 : : const char *value, __rte_unused void *opaque)
3584 : : {
3585 [ # # ]: 0 : if (strcmp(value, "dcf"))
3586 : 0 : return -1;
3587 : :
3588 : : return 0;
3589 : : }
3590 : :
3591 : : static int
3592 : 0 : iavf_dcf_cap_selected(struct rte_devargs *devargs)
3593 : : {
3594 : : struct rte_kvargs *kvlist;
3595 : : const char *key = "cap";
3596 : : int ret = 0;
3597 : :
3598 [ # # ]: 0 : if (devargs == NULL)
3599 : : return 0;
3600 : :
3601 : 0 : kvlist = rte_kvargs_parse(devargs->args, NULL);
3602 [ # # ]: 0 : if (kvlist == NULL)
3603 : : return 0;
3604 : :
3605 [ # # ]: 0 : if (!rte_kvargs_count(kvlist, key))
3606 : 0 : goto exit;
3607 : :
3608 : : /* dcf capability selected when there's a key-value pair: cap=dcf */
3609 [ # # ]: 0 : if (rte_kvargs_process(kvlist, key,
3610 : : iavf_dcf_cap_check_handler, NULL) < 0)
3611 : 0 : goto exit;
3612 : :
3613 : : ret = 1;
3614 : :
3615 : 0 : exit:
3616 : 0 : rte_kvargs_free(kvlist);
3617 : 0 : return ret;
3618 : : }
3619 : :
3620 : 0 : static int eth_iavf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
3621 : : struct rte_pci_device *pci_dev)
3622 : : {
3623 [ # # ]: 0 : if (iavf_dcf_cap_selected(pci_dev->device.devargs))
3624 : : return 1;
3625 : :
3626 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
3627 : : sizeof(struct iavf_adapter), iavf_dev_init);
3628 : : }
3629 : :
3630 : 0 : static int eth_iavf_pci_remove(struct rte_pci_device *pci_dev)
3631 : : {
3632 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, iavf_dev_uninit);
3633 : : }
3634 : :
3635 : : /* Adaptive virtual function driver struct */
3636 : : static struct rte_pci_driver rte_iavf_pmd = {
3637 : : .id_table = pci_id_iavf_map,
3638 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
3639 : : .probe = eth_iavf_pci_probe,
3640 : : .remove = eth_iavf_pci_remove,
3641 : : };
3642 : :
3643 : 0 : bool is_iavf_supported(struct rte_eth_dev *dev)
3644 : : {
3645 : 0 : return !strcmp(dev->device->driver->name, rte_iavf_pmd.driver.name);
3646 : : }
3647 : :
3648 : 303 : RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
3649 : : RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
3650 : : RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
3651 : : RTE_PMD_REGISTER_PARAM_STRING(net_iavf, "cap=dcf");
3652 [ - + ]: 303 : RTE_LOG_REGISTER_SUFFIX(iavf_logtype_init, init, NOTICE);
3653 [ - + ]: 303 : RTE_LOG_REGISTER_SUFFIX(iavf_logtype_driver, driver, NOTICE);
3654 : : #ifdef RTE_ETHDEV_DEBUG_RX
3655 : : RTE_LOG_REGISTER_SUFFIX(iavf_logtype_rx, rx, DEBUG);
3656 : : #endif
3657 : : #ifdef RTE_ETHDEV_DEBUG_TX
3658 : : RTE_LOG_REGISTER_SUFFIX(iavf_logtype_tx, tx, DEBUG);
3659 : : #endif
|