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 +
1891 : 0 : pstats.rx_broadcast - pstats.rx_discards;
1892 : 0 : stats->opackets = pstats.tx_broadcast + pstats.tx_multicast +
1893 : 0 : pstats.tx_unicast;
1894 : 0 : stats->imissed = pstats.rx_discards;
1895 : 0 : stats->oerrors = pstats.tx_errors + pstats.tx_discards;
1896 : 0 : stats->ibytes = pstats.rx_bytes;
1897 : 0 : stats->ibytes -= stats->ipackets * crc_stats_len;
1898 : 0 : stats->obytes = pstats.tx_bytes;
1899 : : } else {
1900 : 0 : PMD_DRV_LOG(ERR, "Get statistics failed");
1901 : : }
1902 : 0 : return ret;
1903 : : }
1904 : :
1905 : : static int
1906 : 0 : iavf_dev_stats_reset(struct rte_eth_dev *dev)
1907 : : {
1908 : : int ret;
1909 : 0 : struct iavf_adapter *adapter =
1910 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1911 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1912 : : struct iavf_vsi *vsi = &vf->vsi;
1913 : : struct virtchnl_eth_stats stats;
1914 : :
1915 : : /* read stat values to clear hardware registers */
1916 : 0 : ret = iavf_query_stats(adapter, &stats);
1917 [ # # ]: 0 : if (ret != 0)
1918 : : return ret;
1919 : :
1920 : : /* set stats offset base on current values */
1921 : 0 : vsi->eth_stats_offset.eth_stats = stats;
1922 : :
1923 : 0 : return 0;
1924 : : }
1925 : :
1926 : : static int
1927 : 0 : iavf_dev_xstats_reset(struct rte_eth_dev *dev)
1928 : : {
1929 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1930 : 0 : iavf_dev_stats_reset(dev);
1931 : 0 : memset(&vf->vsi.eth_stats_offset.ips_stats, 0,
1932 : : sizeof(struct iavf_ipsec_crypto_stats));
1933 : 0 : memset(&vf->vsi.eth_stats_offset.mbuf_stats, 0,
1934 : : sizeof(struct iavf_mbuf_stats));
1935 : :
1936 : 0 : return 0;
1937 : : }
1938 : :
1939 : 0 : static int iavf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1940 : : struct rte_eth_xstat_name *xstats_names,
1941 : : __rte_unused unsigned int limit)
1942 : : {
1943 : : unsigned int i;
1944 : :
1945 [ # # ]: 0 : if (xstats_names != NULL)
1946 [ # # ]: 0 : for (i = 0; i < IAVF_NB_XSTATS; i++) {
1947 : 0 : snprintf(xstats_names[i].name,
1948 : : sizeof(xstats_names[i].name),
1949 : 0 : "%s", rte_iavf_stats_strings[i].name);
1950 : : }
1951 : 0 : return IAVF_NB_XSTATS;
1952 : : }
1953 : :
1954 : : static void
1955 : 0 : iavf_dev_update_ipsec_xstats(struct rte_eth_dev *ethdev,
1956 : : struct iavf_ipsec_crypto_stats *ips)
1957 : : {
1958 : : uint16_t idx;
1959 [ # # ]: 0 : for (idx = 0; idx < ethdev->data->nb_rx_queues; idx++) {
1960 : : struct ci_rx_queue *rxq;
1961 : : struct iavf_ipsec_crypto_stats *stats;
1962 : 0 : rxq = (struct ci_rx_queue *)ethdev->data->rx_queues[idx];
1963 : 0 : stats = &rxq->stats->ipsec_crypto;
1964 : 0 : ips->icount += stats->icount;
1965 : 0 : ips->ibytes += stats->ibytes;
1966 : 0 : ips->ierrors.count += stats->ierrors.count;
1967 : 0 : ips->ierrors.sad_miss += stats->ierrors.sad_miss;
1968 : 0 : ips->ierrors.not_processed += stats->ierrors.not_processed;
1969 : 0 : ips->ierrors.icv_check += stats->ierrors.icv_check;
1970 : 0 : ips->ierrors.ipsec_length += stats->ierrors.ipsec_length;
1971 : 0 : ips->ierrors.misc += stats->ierrors.misc;
1972 : : }
1973 : 0 : }
1974 : :
1975 : : static void
1976 : : iavf_dev_update_mbuf_stats(struct rte_eth_dev *ethdev,
1977 : : struct iavf_mbuf_stats *mbuf_stats)
1978 : : {
1979 : : uint16_t idx;
1980 : : struct ci_tx_queue *txq;
1981 : :
1982 [ # # ]: 0 : for (idx = 0; idx < ethdev->data->nb_tx_queues; idx++) {
1983 : 0 : txq = ethdev->data->tx_queues[idx];
1984 : 0 : mbuf_stats->tx_pkt_errors += txq->mbuf_errors;
1985 : : }
1986 : : }
1987 : :
1988 : 0 : static int iavf_dev_xstats_get(struct rte_eth_dev *dev,
1989 : : struct rte_eth_xstat *xstats, unsigned int n)
1990 : : {
1991 : : int ret;
1992 : : unsigned int i;
1993 : 0 : struct iavf_adapter *adapter =
1994 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1995 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1996 : 0 : struct iavf_vsi *vsi = &vf->vsi;
1997 : : struct virtchnl_eth_stats stats;
1998 : 0 : struct iavf_eth_xstats iavf_xtats = {{0}};
1999 : :
2000 [ # # ]: 0 : if (n < IAVF_NB_XSTATS)
2001 : : return IAVF_NB_XSTATS;
2002 : :
2003 : 0 : ret = iavf_query_stats(adapter, &stats);
2004 [ # # ]: 0 : if (ret != 0)
2005 : : return 0;
2006 : :
2007 [ # # ]: 0 : if (!xstats)
2008 : : return 0;
2009 : :
2010 : 0 : iavf_update_stats(vsi, &stats);
2011 : 0 : iavf_xtats.eth_stats = stats;
2012 : :
2013 [ # # ]: 0 : if (iavf_ipsec_crypto_supported(adapter))
2014 : 0 : iavf_dev_update_ipsec_xstats(dev, &iavf_xtats.ips_stats);
2015 : :
2016 [ # # ]: 0 : if (adapter->devargs.mbuf_check)
2017 : : iavf_dev_update_mbuf_stats(dev, &iavf_xtats.mbuf_stats);
2018 : :
2019 : : /* loop over xstats array and values from pstats */
2020 [ # # ]: 0 : for (i = 0; i < IAVF_NB_XSTATS; i++) {
2021 : 0 : xstats[i].id = i;
2022 : 0 : xstats[i].value = *(uint64_t *)(((char *)&iavf_xtats) +
2023 : 0 : rte_iavf_stats_strings[i].offset);
2024 : : }
2025 : :
2026 : : return IAVF_NB_XSTATS;
2027 : : }
2028 : :
2029 : :
2030 : : static int
2031 : 0 : iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
2032 : : {
2033 : 0 : struct iavf_adapter *adapter =
2034 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2035 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2036 : : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
2037 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2038 : : uint16_t msix_intr;
2039 : :
2040 [ # # ]: 0 : if (adapter->closed)
2041 : : return -EIO;
2042 : :
2043 : 0 : msix_intr = rte_intr_vec_list_index_get(pci_dev->intr_handle,
2044 : : queue_id);
2045 [ # # ]: 0 : if (msix_intr == IAVF_MISC_VEC_ID) {
2046 : 0 : PMD_DRV_LOG(INFO, "MISC is also enabled for control");
2047 : 0 : IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
2048 : : IAVF_VFINT_DYN_CTL01_INTENA_MASK |
2049 : : IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
2050 : : IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
2051 : : } else {
2052 : 0 : IAVF_WRITE_REG(hw,
2053 : : IAVF_VFINT_DYN_CTLN1
2054 : : (msix_intr - IAVF_RX_VEC_START),
2055 : : IAVF_VFINT_DYN_CTLN1_INTENA_MASK |
2056 : : IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
2057 : : IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK);
2058 : : }
2059 : :
2060 : 0 : IAVF_WRITE_FLUSH(hw);
2061 : :
2062 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
2063 : 0 : rte_intr_ack(pci_dev->intr_handle);
2064 : :
2065 : : return 0;
2066 : : }
2067 : :
2068 : : static int
2069 : 0 : iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
2070 : : {
2071 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2072 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2073 : : uint16_t msix_intr;
2074 : :
2075 : 0 : msix_intr = rte_intr_vec_list_index_get(pci_dev->intr_handle,
2076 : : queue_id);
2077 [ # # ]: 0 : if (msix_intr == IAVF_MISC_VEC_ID) {
2078 : 0 : PMD_DRV_LOG(ERR, "MISC is used for control, cannot disable it");
2079 : 0 : return -EIO;
2080 : : }
2081 : :
2082 : 0 : IAVF_WRITE_REG(hw,
2083 : : IAVF_VFINT_DYN_CTLN1(msix_intr - IAVF_RX_VEC_START),
2084 : : IAVF_VFINT_DYN_CTLN1_WB_ON_ITR_MASK);
2085 : :
2086 : 0 : IAVF_WRITE_FLUSH(hw);
2087 : 0 : return 0;
2088 : : }
2089 : :
2090 : : static int
2091 : : iavf_check_vf_reset_done(struct iavf_hw *hw)
2092 : : {
2093 : : int i, reset;
2094 : :
2095 [ # # # # ]: 0 : for (i = 0; i < IAVF_RESET_WAIT_CNT; i++) {
2096 : 0 : reset = IAVF_READ_REG(hw, IAVF_VFGEN_RSTAT) &
2097 : : IAVF_VFGEN_RSTAT_VFR_STATE_MASK;
2098 : : reset = reset >> IAVF_VFGEN_RSTAT_VFR_STATE_SHIFT;
2099 [ # # # # ]: 0 : if (reset == VIRTCHNL_VFR_VFACTIVE ||
2100 : : reset == VIRTCHNL_VFR_COMPLETED)
2101 : : break;
2102 : : rte_delay_ms(20);
2103 : : }
2104 : :
2105 [ # # # # ]: 0 : if (i >= IAVF_RESET_WAIT_CNT)
2106 : : return -1;
2107 : :
2108 : : return 0;
2109 : : }
2110 : :
2111 : : static int
2112 : 0 : iavf_lookup_proto_xtr_type(const char *flex_name)
2113 : : {
2114 : : static struct {
2115 : : const char *name;
2116 : : enum iavf_proto_xtr_type type;
2117 : : } xtr_type_map[] = {
2118 : : { "vlan", IAVF_PROTO_XTR_VLAN },
2119 : : { "ipv4", IAVF_PROTO_XTR_IPV4 },
2120 : : { "ipv6", IAVF_PROTO_XTR_IPV6 },
2121 : : { "ipv6_flow", IAVF_PROTO_XTR_IPV6_FLOW },
2122 : : { "tcp", IAVF_PROTO_XTR_TCP },
2123 : : { "ip_offset", IAVF_PROTO_XTR_IP_OFFSET },
2124 : : { "ipsec_crypto_said", IAVF_PROTO_XTR_IPSEC_CRYPTO_SAID },
2125 : : };
2126 : : uint32_t i;
2127 : :
2128 [ # # ]: 0 : for (i = 0; i < RTE_DIM(xtr_type_map); i++) {
2129 [ # # ]: 0 : if (strcmp(flex_name, xtr_type_map[i].name) == 0)
2130 : 0 : return xtr_type_map[i].type;
2131 : : }
2132 : :
2133 : 0 : PMD_DRV_LOG(ERR, "wrong proto_xtr type, it should be: "
2134 : : "vlan|ipv4|ipv6|ipv6_flow|tcp|ip_offset|ipsec_crypto_said");
2135 : :
2136 : 0 : return -1;
2137 : : }
2138 : :
2139 : : /**
2140 : : * Parse elem, the elem could be single number/range or '(' ')' group
2141 : : * 1) A single number elem, it's just a simple digit. e.g. 9
2142 : : * 2) A single range elem, two digits with a '-' between. e.g. 2-6
2143 : : * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
2144 : : * Within group elem, '-' used for a range separator;
2145 : : * ',' used for a single number.
2146 : : */
2147 : : static int
2148 : 0 : iavf_parse_queue_set(const char *input, int xtr_type,
2149 : : struct iavf_devargs *devargs)
2150 : : {
2151 : : const char *str = input;
2152 : 0 : char *end = NULL;
2153 : : uint32_t min, max;
2154 : : uint32_t idx;
2155 : :
2156 [ # # ]: 0 : while (isblank(*str))
2157 : 0 : str++;
2158 : :
2159 [ # # # # ]: 0 : if (!isdigit(*str) && *str != '(')
2160 : : return -1;
2161 : :
2162 : : /* process single number or single range of number */
2163 [ # # ]: 0 : if (*str != '(') {
2164 : 0 : errno = 0;
2165 : 0 : idx = strtoul(str, &end, 10);
2166 [ # # # # : 0 : if (errno || !end || idx >= IAVF_MAX_QUEUE_NUM)
# # ]
2167 : : return -1;
2168 : :
2169 [ # # ]: 0 : while (isblank(*end))
2170 : 0 : end++;
2171 : :
2172 : : min = idx;
2173 : : max = idx;
2174 : :
2175 : : /* process single <number>-<number> */
2176 [ # # ]: 0 : if (*end == '-') {
2177 : 0 : end++;
2178 [ # # ]: 0 : while (isblank(*end))
2179 : 0 : end++;
2180 [ # # ]: 0 : if (!isdigit(*end))
2181 : : return -1;
2182 : :
2183 : 0 : errno = 0;
2184 : 0 : idx = strtoul(end, &end, 10);
2185 [ # # # # : 0 : if (errno || !end || idx >= IAVF_MAX_QUEUE_NUM)
# # ]
2186 : : return -1;
2187 : :
2188 : : max = idx;
2189 [ # # ]: 0 : while (isblank(*end))
2190 : 0 : end++;
2191 : : }
2192 : :
2193 [ # # ]: 0 : if (*end != ':')
2194 : : return -1;
2195 : :
2196 : 0 : for (idx = RTE_MIN(min, max);
2197 [ # # ]: 0 : idx <= RTE_MAX(min, max); idx++)
2198 : 0 : devargs->proto_xtr[idx] = xtr_type;
2199 : :
2200 : : return 0;
2201 : : }
2202 : :
2203 : : /* process set within bracket */
2204 : 0 : str++;
2205 [ # # ]: 0 : while (isblank(*str))
2206 : 0 : str++;
2207 [ # # ]: 0 : if (*str == '\0')
2208 : : return -1;
2209 : :
2210 : : min = IAVF_MAX_QUEUE_NUM;
2211 : : do {
2212 : : /* go ahead to the first digit */
2213 [ # # ]: 0 : while (isblank(*str))
2214 : 0 : str++;
2215 [ # # ]: 0 : if (!isdigit(*str))
2216 : : return -1;
2217 : :
2218 : : /* get the digit value */
2219 : 0 : errno = 0;
2220 : 0 : idx = strtoul(str, &end, 10);
2221 [ # # # # : 0 : if (errno || !end || idx >= IAVF_MAX_QUEUE_NUM)
# # ]
2222 : : return -1;
2223 : :
2224 : : /* go ahead to separator '-',',' and ')' */
2225 [ # # ]: 0 : while (isblank(*end))
2226 : 0 : end++;
2227 [ # # ]: 0 : if (*end == '-') {
2228 [ # # ]: 0 : if (min == IAVF_MAX_QUEUE_NUM)
2229 : : min = idx;
2230 : : else /* avoid continuous '-' */
2231 : : return -1;
2232 [ # # ]: 0 : } else if (*end == ',' || *end == ')') {
2233 : : max = idx;
2234 [ # # ]: 0 : if (min == IAVF_MAX_QUEUE_NUM)
2235 : : min = idx;
2236 : :
2237 : 0 : for (idx = RTE_MIN(min, max);
2238 [ # # ]: 0 : idx <= RTE_MAX(min, max); idx++)
2239 : 0 : devargs->proto_xtr[idx] = xtr_type;
2240 : :
2241 : : min = IAVF_MAX_QUEUE_NUM;
2242 : : } else {
2243 : : return -1;
2244 : : }
2245 : :
2246 : 0 : str = end + 1;
2247 [ # # ]: 0 : } while (*end != ')' && *end != '\0');
2248 : :
2249 : : return 0;
2250 : : }
2251 : :
2252 : : static int
2253 : 0 : iavf_parse_queue_proto_xtr(const char *queues, struct iavf_devargs *devargs)
2254 : : {
2255 : : const char *queue_start;
2256 : : uint32_t idx;
2257 : : int xtr_type;
2258 : : char flex_name[32];
2259 : :
2260 [ # # ]: 0 : while (isblank(*queues))
2261 : 0 : queues++;
2262 : :
2263 [ # # ]: 0 : if (*queues != '[') {
2264 : 0 : xtr_type = iavf_lookup_proto_xtr_type(queues);
2265 [ # # ]: 0 : if (xtr_type < 0)
2266 : : return -1;
2267 : :
2268 : 0 : devargs->proto_xtr_dflt = xtr_type;
2269 : :
2270 : 0 : return 0;
2271 : : }
2272 : :
2273 : 0 : queues++;
2274 : : do {
2275 [ # # ]: 0 : while (isblank(*queues))
2276 : 0 : queues++;
2277 [ # # ]: 0 : if (*queues == '\0')
2278 : : return -1;
2279 : :
2280 : : queue_start = queues;
2281 : :
2282 : : /* go across a complete bracket */
2283 [ # # ]: 0 : if (*queue_start == '(') {
2284 : 0 : queues += strcspn(queues, ")");
2285 [ # # ]: 0 : if (*queues != ')')
2286 : : return -1;
2287 : : }
2288 : :
2289 : : /* scan the separator ':' */
2290 : 0 : queues += strcspn(queues, ":");
2291 [ # # ]: 0 : if (*queues++ != ':')
2292 : : return -1;
2293 [ # # ]: 0 : while (isblank(*queues))
2294 : 0 : queues++;
2295 : :
2296 : 0 : for (idx = 0; ; idx++) {
2297 [ # # # # ]: 0 : if (isblank(queues[idx]) ||
2298 [ # # ]: 0 : queues[idx] == ',' ||
2299 [ # # ]: 0 : queues[idx] == ']' ||
2300 : : queues[idx] == '\0')
2301 : : break;
2302 : :
2303 [ # # ]: 0 : if (idx > sizeof(flex_name) - 2)
2304 : : return -1;
2305 : :
2306 : 0 : flex_name[idx] = queues[idx];
2307 : : }
2308 : 0 : flex_name[idx] = '\0';
2309 : 0 : xtr_type = iavf_lookup_proto_xtr_type(flex_name);
2310 [ # # ]: 0 : if (xtr_type < 0)
2311 : : return -1;
2312 : :
2313 : : queues += idx;
2314 : :
2315 [ # # # # : 0 : while (isblank(*queues) || *queues == ',' || *queues == ']')
# # ]
2316 : 0 : queues++;
2317 : :
2318 [ # # ]: 0 : if (iavf_parse_queue_set(queue_start, xtr_type, devargs) < 0)
2319 : : return -1;
2320 [ # # ]: 0 : } while (*queues != '\0');
2321 : :
2322 : : return 0;
2323 : : }
2324 : :
2325 : : static int
2326 : 0 : iavf_handle_proto_xtr_arg(__rte_unused const char *key, const char *value,
2327 : : void *extra_args)
2328 : : {
2329 : : struct iavf_devargs *devargs = extra_args;
2330 : :
2331 [ # # ]: 0 : if (!value || !extra_args)
2332 : : return -EINVAL;
2333 : :
2334 [ # # ]: 0 : if (iavf_parse_queue_proto_xtr(value, devargs) < 0) {
2335 : 0 : PMD_DRV_LOG(ERR, "the proto_xtr's parameter is wrong : '%s'",
2336 : : value);
2337 : 0 : return -1;
2338 : : }
2339 : :
2340 : : return 0;
2341 : : }
2342 : :
2343 : : static int
2344 : 0 : parse_u16(__rte_unused const char *key, const char *value, void *args)
2345 : : {
2346 : : u16 *num = (u16 *)args;
2347 : : u16 tmp;
2348 : :
2349 : 0 : errno = 0;
2350 : 0 : tmp = strtoull(value, NULL, 10);
2351 [ # # # # ]: 0 : if (errno || !tmp) {
2352 : 0 : PMD_DRV_LOG(WARNING, "%s: \"%s\" is not a valid u16",
2353 : : key, value);
2354 : 0 : return -1;
2355 : : }
2356 : :
2357 : 0 : *num = tmp;
2358 : :
2359 : 0 : return 0;
2360 : : }
2361 : :
2362 : : static int
2363 : 0 : parse_bool(const char *key, const char *value, void *args)
2364 : : {
2365 : : int *i = (int *)args;
2366 : : char *end;
2367 : : int num;
2368 : :
2369 : 0 : num = strtoul(value, &end, 10);
2370 : :
2371 [ # # ]: 0 : if (num != 0 && num != 1) {
2372 : 0 : PMD_DRV_LOG(WARNING, "invalid value:\"%s\" for key:\"%s\", "
2373 : : "value must be 0 or 1",
2374 : : value, key);
2375 : 0 : return -1;
2376 : : }
2377 : :
2378 : 0 : *i = num;
2379 : 0 : return 0;
2380 : : }
2381 : :
2382 : : static int
2383 : 0 : iavf_parse_watchdog_period(__rte_unused const char *key, const char *value, void *args)
2384 : : {
2385 : : int *num = (int *)args;
2386 : : int tmp;
2387 : :
2388 : 0 : errno = 0;
2389 : : tmp = atoi(value);
2390 [ # # ]: 0 : if (tmp < 0) {
2391 : 0 : PMD_DRV_LOG(WARNING, "%s: \"%s\" is not greater than or equal to zero",
2392 : : key, value);
2393 : 0 : return -1;
2394 : : }
2395 : :
2396 : 0 : *num = tmp;
2397 : :
2398 : 0 : return 0;
2399 : : }
2400 : :
2401 : : static int
2402 : 0 : iavf_parse_mbuf_check(__rte_unused const char *key, const char *value, void *args)
2403 : : {
2404 : : char *cur;
2405 : : char *tmp;
2406 : : int str_len;
2407 : : int valid_len;
2408 : : int ret = 0;
2409 : : uint64_t *mc_flags = args;
2410 : 0 : char *str2 = strdup(value);
2411 : :
2412 [ # # ]: 0 : if (str2 == NULL)
2413 : : return -1;
2414 : :
2415 : 0 : str_len = strlen(str2);
2416 [ # # ]: 0 : if (str_len == 0) {
2417 : : ret = -1;
2418 : 0 : goto err_end;
2419 : : }
2420 : :
2421 : : /* Try stripping the outer square brackets of the parameter string. */
2422 [ # # # # ]: 0 : if (str2[0] == '[' && str2[str_len - 1] == ']') {
2423 [ # # ]: 0 : if (str_len < 3) {
2424 : : ret = -1;
2425 : 0 : goto err_end;
2426 : : }
2427 : 0 : valid_len = str_len - 2;
2428 : 0 : memmove(str2, str2 + 1, valid_len);
2429 : 0 : memset(str2 + valid_len, '\0', 2);
2430 : : }
2431 : :
2432 : 0 : cur = strtok_r(str2, ",", &tmp);
2433 [ # # ]: 0 : while (cur != NULL) {
2434 [ # # ]: 0 : if (!strcmp(cur, "mbuf"))
2435 : 0 : *mc_flags |= IAVF_MBUF_CHECK_F_TX_MBUF;
2436 [ # # ]: 0 : else if (!strcmp(cur, "size"))
2437 : 0 : *mc_flags |= IAVF_MBUF_CHECK_F_TX_SIZE;
2438 [ # # ]: 0 : else if (!strcmp(cur, "segment"))
2439 : 0 : *mc_flags |= IAVF_MBUF_CHECK_F_TX_SEGMENT;
2440 [ # # ]: 0 : else if (!strcmp(cur, "offload"))
2441 : 0 : *mc_flags |= IAVF_MBUF_CHECK_F_TX_OFFLOAD;
2442 : : else
2443 : 0 : PMD_DRV_LOG(ERR, "Unsupported diagnostic type: %s", cur);
2444 : 0 : cur = strtok_r(NULL, ",", &tmp);
2445 : : }
2446 : :
2447 : 0 : err_end:
2448 : 0 : free(str2);
2449 : 0 : return ret;
2450 : : }
2451 : :
2452 : 0 : static int iavf_parse_devargs(struct rte_eth_dev *dev)
2453 : : {
2454 : 0 : struct iavf_adapter *ad =
2455 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2456 : 0 : struct rte_devargs *devargs = dev->device->devargs;
2457 : : struct rte_kvargs *kvlist;
2458 : : int ret;
2459 : 0 : int watchdog_period = -1;
2460 : :
2461 : 0 : ad->devargs.auto_reset = 1;
2462 : 0 : ad->devargs.no_poll_on_link_down = 1;
2463 : 0 : ad->devargs.auto_reconfig = 1;
2464 : :
2465 [ # # ]: 0 : if (!devargs)
2466 : : return 0;
2467 : :
2468 : 0 : kvlist = rte_kvargs_parse(devargs->args, iavf_valid_args);
2469 [ # # ]: 0 : if (!kvlist) {
2470 : 0 : PMD_INIT_LOG(ERR, "invalid kvargs key");
2471 : 0 : return -EINVAL;
2472 : : }
2473 : :
2474 : 0 : ad->devargs.proto_xtr_dflt = IAVF_PROTO_XTR_NONE;
2475 : 0 : memset(ad->devargs.proto_xtr, IAVF_PROTO_XTR_NONE,
2476 : : sizeof(ad->devargs.proto_xtr));
2477 : :
2478 : 0 : ret = rte_kvargs_process(kvlist, IAVF_PROTO_XTR_ARG,
2479 : 0 : &iavf_handle_proto_xtr_arg, &ad->devargs);
2480 [ # # ]: 0 : if (ret)
2481 : 0 : goto bail;
2482 : :
2483 : 0 : ret = rte_kvargs_process(kvlist, IAVF_QUANTA_SIZE_ARG,
2484 : 0 : &parse_u16, &ad->devargs.quanta_size);
2485 [ # # ]: 0 : if (ret)
2486 : 0 : goto bail;
2487 : :
2488 : 0 : ret = rte_kvargs_process(kvlist, IAVF_RESET_WATCHDOG_ARG,
2489 : : &iavf_parse_watchdog_period, &watchdog_period);
2490 [ # # ]: 0 : if (ret)
2491 : 0 : goto bail;
2492 [ # # ]: 0 : if (watchdog_period == -1)
2493 : 0 : ad->devargs.watchdog_period = IAVF_DEV_WATCHDOG_PERIOD;
2494 : : else
2495 : 0 : ad->devargs.watchdog_period = watchdog_period;
2496 : :
2497 : 0 : ret = rte_kvargs_process(kvlist, IAVF_NO_POLL_ON_LINK_DOWN_ARG,
2498 : 0 : &parse_bool, &ad->devargs.no_poll_on_link_down);
2499 [ # # ]: 0 : if (ret)
2500 : 0 : goto bail;
2501 : :
2502 [ # # ]: 0 : if (ad->devargs.quanta_size != 0 &&
2503 [ # # # # ]: 0 : (ad->devargs.quanta_size < 256 || ad->devargs.quanta_size > 4096 ||
2504 : : ad->devargs.quanta_size & 0x40)) {
2505 : 0 : PMD_INIT_LOG(ERR, "invalid quanta size");
2506 : : ret = -EINVAL;
2507 : 0 : goto bail;
2508 : : }
2509 : :
2510 : 0 : ret = rte_kvargs_process(kvlist, IAVF_MBUF_CHECK_ARG,
2511 : 0 : &iavf_parse_mbuf_check, &ad->devargs.mbuf_check);
2512 [ # # ]: 0 : if (ret)
2513 : 0 : goto bail;
2514 : :
2515 : 0 : ret = rte_kvargs_process(kvlist, IAVF_ENABLE_AUTO_RESET_ARG,
2516 : 0 : &parse_bool, &ad->devargs.auto_reset);
2517 [ # # ]: 0 : if (ret)
2518 : 0 : goto bail;
2519 : :
2520 [ # # # # ]: 0 : if (ad->devargs.auto_reset != 0 && ad->devargs.no_poll_on_link_down == 0) {
2521 : 0 : PMD_INIT_LOG(WARNING,
2522 : : "no-poll-on-link-down=0 is incompatible with auto_reset=1, ignoring");
2523 : 0 : ad->devargs.no_poll_on_link_down = 1;
2524 : : }
2525 : :
2526 : 0 : ret = rte_kvargs_process(kvlist, IAVF_ENABLE_AUTO_RECONFIG_ARG,
2527 : 0 : &parse_bool, &ad->devargs.auto_reconfig);
2528 [ # # ]: 0 : if (ret)
2529 : 0 : goto bail;
2530 : :
2531 : 0 : ret = rte_kvargs_process(kvlist, IAVF_ENABLE_PTYPE_LLDP_ARG,
2532 : 0 : &parse_bool, &ad->devargs.enable_ptype_lldp);
2533 [ # # ]: 0 : if (ret)
2534 : 0 : goto bail;
2535 : :
2536 : 0 : bail:
2537 : 0 : rte_kvargs_free(kvlist);
2538 : 0 : return ret;
2539 : : }
2540 : :
2541 : : static void
2542 : 0 : iavf_init_proto_xtr(struct rte_eth_dev *dev)
2543 : : {
2544 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2545 : : struct iavf_adapter *ad =
2546 : : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2547 : : const struct iavf_proto_xtr_ol *xtr_ol;
2548 : : bool proto_xtr_enable = false;
2549 : : int offset;
2550 : : uint16_t i;
2551 : :
2552 : 0 : vf->proto_xtr = rte_zmalloc("vf proto xtr",
2553 : 0 : vf->vsi_res->num_queue_pairs, 0);
2554 [ # # ]: 0 : if (unlikely(!(vf->proto_xtr))) {
2555 : 0 : PMD_DRV_LOG(ERR, "no memory for setting up proto_xtr's table");
2556 : 0 : return;
2557 : : }
2558 : :
2559 [ # # ]: 0 : for (i = 0; i < vf->vsi_res->num_queue_pairs; i++) {
2560 [ # # ]: 0 : vf->proto_xtr[i] = ad->devargs.proto_xtr[i] !=
2561 : : IAVF_PROTO_XTR_NONE ?
2562 : : ad->devargs.proto_xtr[i] :
2563 : : ad->devargs.proto_xtr_dflt;
2564 : :
2565 [ # # ]: 0 : if (vf->proto_xtr[i] != IAVF_PROTO_XTR_NONE) {
2566 : : uint8_t type = vf->proto_xtr[i];
2567 : :
2568 : 0 : iavf_proto_xtr_params[type].required = true;
2569 : : proto_xtr_enable = true;
2570 : : }
2571 : : }
2572 : :
2573 [ # # ]: 0 : if (likely(!proto_xtr_enable))
2574 : : return;
2575 : :
2576 : 0 : offset = rte_mbuf_dynfield_register(&iavf_proto_xtr_metadata_param);
2577 [ # # ]: 0 : if (unlikely(offset == -1)) {
2578 : 0 : PMD_DRV_LOG(ERR,
2579 : : "failed to extract protocol metadata, error %d",
2580 : : -rte_errno);
2581 : 0 : return;
2582 : : }
2583 : :
2584 : 0 : PMD_DRV_LOG(DEBUG,
2585 : : "proto_xtr metadata offset in mbuf is : %d",
2586 : : offset);
2587 : 0 : rte_pmd_ifd_dynfield_proto_xtr_metadata_offs = offset;
2588 : :
2589 [ # # ]: 0 : for (i = 0; i < RTE_DIM(iavf_proto_xtr_params); i++) {
2590 : 0 : xtr_ol = &iavf_proto_xtr_params[i];
2591 : :
2592 : 0 : uint8_t rxdid = iavf_proto_xtr_type_to_rxdid((uint8_t)i);
2593 : :
2594 [ # # ]: 0 : if (!xtr_ol->required)
2595 : 0 : continue;
2596 : :
2597 [ # # ]: 0 : if (!(vf->supported_rxdid & RTE_BIT64(rxdid))) {
2598 : 0 : PMD_DRV_LOG(ERR,
2599 : : "rxdid[%u] is not supported in hardware",
2600 : : rxdid);
2601 : 0 : rte_pmd_ifd_dynfield_proto_xtr_metadata_offs = -1;
2602 : 0 : break;
2603 : : }
2604 : :
2605 : 0 : offset = rte_mbuf_dynflag_register(&xtr_ol->param);
2606 [ # # ]: 0 : if (unlikely(offset == -1)) {
2607 : 0 : PMD_DRV_LOG(ERR,
2608 : : "failed to register proto_xtr offload '%s', error %d",
2609 : : xtr_ol->param.name, -rte_errno);
2610 : :
2611 : 0 : rte_pmd_ifd_dynfield_proto_xtr_metadata_offs = -1;
2612 : 0 : break;
2613 : : }
2614 : :
2615 : 0 : PMD_DRV_LOG(DEBUG,
2616 : : "proto_xtr offload '%s' offset in mbuf is : %d",
2617 : : xtr_ol->param.name, offset);
2618 : 0 : *xtr_ol->ol_flag = 1ULL << offset;
2619 : : }
2620 : : }
2621 : :
2622 : : static int
2623 : 0 : iavf_init_vf(struct rte_eth_dev *dev)
2624 : : {
2625 : : int err, bufsz;
2626 : 0 : struct iavf_adapter *adapter =
2627 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2628 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2629 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2630 : :
2631 : 0 : vf->eth_dev = dev;
2632 : :
2633 : 0 : err = iavf_parse_devargs(dev);
2634 [ # # ]: 0 : if (err) {
2635 : 0 : PMD_INIT_LOG(ERR, "Failed to parse devargs");
2636 : 0 : goto err;
2637 : : }
2638 : :
2639 : 0 : err = iavf_set_mac_type(hw);
2640 [ # # ]: 0 : if (err) {
2641 : 0 : PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
2642 : 0 : goto err;
2643 : : }
2644 : :
2645 : : err = iavf_check_vf_reset_done(hw);
2646 : : if (err) {
2647 : 0 : PMD_INIT_LOG(ERR, "VF is still resetting");
2648 : 0 : goto err;
2649 : : }
2650 : :
2651 : : iavf_init_adminq_parameter(hw);
2652 : 0 : err = iavf_init_adminq(hw);
2653 [ # # ]: 0 : if (err) {
2654 : 0 : PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
2655 : 0 : goto err;
2656 : : }
2657 : :
2658 [ # # ]: 0 : if (iavf_check_api_version(adapter) != 0) {
2659 : 0 : PMD_INIT_LOG(ERR, "check_api version failed");
2660 : 0 : goto err_api;
2661 : : }
2662 : :
2663 : : bufsz = sizeof(struct virtchnl_vf_resource) +
2664 : : (IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource));
2665 : 0 : vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
2666 [ # # ]: 0 : if (!vf->vf_res) {
2667 : 0 : PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
2668 : 0 : goto err_api;
2669 : : }
2670 : :
2671 [ # # ]: 0 : if (iavf_get_vf_resource(adapter) != 0) {
2672 : 0 : PMD_INIT_LOG(ERR, "iavf_get_vf_config failed");
2673 : 0 : goto err_alloc;
2674 : : }
2675 : : /* Allocate memort for RSS info */
2676 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
2677 : 0 : vf->rss_key = rte_zmalloc("rss_key",
2678 : 0 : vf->vf_res->rss_key_size, 0);
2679 [ # # ]: 0 : if (!vf->rss_key) {
2680 : 0 : PMD_INIT_LOG(ERR, "unable to allocate rss_key memory");
2681 : 0 : goto err_rss;
2682 : : }
2683 : 0 : vf->rss_lut = rte_zmalloc("rss_lut",
2684 : 0 : vf->vf_res->rss_lut_size, 0);
2685 [ # # ]: 0 : if (!vf->rss_lut) {
2686 : 0 : PMD_INIT_LOG(ERR, "unable to allocate rss_lut memory");
2687 : 0 : goto err_rss;
2688 : : }
2689 : : }
2690 : :
2691 [ # # ]: 0 : if (vf->vsi_res->num_queue_pairs > IAVF_MAX_NUM_QUEUES_DFLT)
2692 : 0 : vf->lv_enabled = true;
2693 : :
2694 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
2695 [ # # ]: 0 : if (iavf_get_supported_rxdid(adapter) != 0) {
2696 : 0 : PMD_INIT_LOG(ERR, "failed to do get supported rxdid");
2697 : 0 : goto err_rss;
2698 : : }
2699 : : }
2700 : :
2701 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
2702 [ # # ]: 0 : if (iavf_get_vlan_offload_caps_v2(adapter) != 0) {
2703 : 0 : PMD_INIT_LOG(ERR, "failed to do get VLAN offload v2 capabilities");
2704 : 0 : goto err_rss;
2705 : : }
2706 : : }
2707 : :
2708 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_QOS) {
2709 : : bufsz = sizeof(struct virtchnl_qos_cap_list) +
2710 : : IAVF_MAX_TRAFFIC_CLASS *
2711 : : sizeof(struct virtchnl_qos_cap_elem);
2712 : 0 : vf->qos_cap = rte_zmalloc("qos_cap", bufsz, 0);
2713 [ # # ]: 0 : if (!vf->qos_cap) {
2714 : 0 : PMD_INIT_LOG(ERR, "unable to allocate qos_cap memory");
2715 : 0 : goto err_rss;
2716 : : }
2717 : 0 : iavf_tm_conf_init(dev);
2718 : : }
2719 : :
2720 : 0 : iavf_init_proto_xtr(dev);
2721 : :
2722 : 0 : return 0;
2723 : 0 : err_rss:
2724 : 0 : rte_free(vf->rss_key);
2725 : 0 : rte_free(vf->rss_lut);
2726 : 0 : err_alloc:
2727 : 0 : rte_free(vf->qos_cap);
2728 : 0 : rte_free(vf->vf_res);
2729 : 0 : vf->vsi_res = NULL;
2730 : 0 : err_api:
2731 : 0 : iavf_shutdown_adminq(hw);
2732 : : err:
2733 : : return -1;
2734 : : }
2735 : :
2736 : : static void
2737 : 0 : iavf_uninit_vf(struct rte_eth_dev *dev)
2738 : : {
2739 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2740 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2741 : :
2742 : 0 : iavf_shutdown_adminq(hw);
2743 : :
2744 : 0 : rte_free(vf->vf_res);
2745 : 0 : vf->vsi_res = NULL;
2746 : 0 : vf->vf_res = NULL;
2747 : :
2748 : 0 : rte_free(vf->qos_cap);
2749 : 0 : vf->qos_cap = NULL;
2750 : :
2751 : 0 : rte_free(vf->rss_lut);
2752 : 0 : vf->rss_lut = NULL;
2753 : 0 : rte_free(vf->rss_key);
2754 : 0 : vf->rss_key = NULL;
2755 : 0 : }
2756 : :
2757 : : /* Enable default admin queue interrupt setting */
2758 : : static inline void
2759 : : iavf_enable_irq0(struct iavf_hw *hw)
2760 : : {
2761 : : /* Enable admin queue interrupt trigger */
2762 : 0 : IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1,
2763 : : IAVF_VFINT_ICR0_ENA1_ADMINQ_MASK);
2764 : :
2765 : 0 : IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
2766 : : IAVF_VFINT_DYN_CTL01_INTENA_MASK |
2767 : : IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
2768 : : IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
2769 : :
2770 : 0 : IAVF_WRITE_FLUSH(hw);
2771 : 0 : }
2772 : :
2773 : : static inline void
2774 : : iavf_disable_irq0(struct iavf_hw *hw)
2775 : : {
2776 : : /* Disable all interrupt types */
2777 : 0 : IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1, 0);
2778 : 0 : IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
2779 : : IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
2780 : 0 : IAVF_WRITE_FLUSH(hw);
2781 : : }
2782 : :
2783 : : static void
2784 : 0 : iavf_dev_interrupt_handler(void *param)
2785 : : {
2786 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2787 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2788 : :
2789 : : iavf_disable_irq0(hw);
2790 : :
2791 : 0 : iavf_handle_virtchnl_msg(dev);
2792 : :
2793 : : iavf_enable_irq0(hw);
2794 : 0 : }
2795 : :
2796 : : static struct ci_rx_queue *
2797 : : iavf_phc_sync_rxq_get(struct rte_eth_dev *dev)
2798 : : {
2799 : : struct ci_rx_queue *rxq;
2800 : : uint16_t i;
2801 : :
2802 [ # # # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2803 : 0 : rxq = dev->data->rx_queues[i];
2804 [ # # # # ]: 0 : if (rxq != NULL)
2805 : : return rxq;
2806 : : }
2807 : :
2808 : : return NULL;
2809 : : }
2810 : :
2811 : : static void
2812 : : iavf_phc_sync_update_all_rxq(struct rte_eth_dev *dev,
2813 : : uint64_t phc_time,
2814 : : uint64_t sw_cur_time)
2815 : : {
2816 : : struct ci_rx_queue *rxq;
2817 : : uint16_t i;
2818 : :
2819 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2820 : 0 : rxq = dev->data->rx_queues[i];
2821 [ # # ]: 0 : if (rxq == NULL)
2822 : 0 : continue;
2823 : :
2824 : 0 : rxq->phc_time = phc_time;
2825 : 0 : rxq->hw_time_update = sw_cur_time;
2826 : : }
2827 : : }
2828 : :
2829 : : static void
2830 : 0 : iavf_phc_sync_tick(struct rte_eth_dev *dev)
2831 : : {
2832 : : struct iavf_adapter *adapter;
2833 : : const uint16_t phc_sync_ticks_max = RTE_MAX((uint16_t)1,
2834 : : (uint16_t)(IAVF_PHC_SYNC_ALARM_INTERVAL_US / IAVF_ALARM_INTERVAL));
2835 : : struct ci_rx_queue *sync_rxq;
2836 : : uint64_t sw_cur_time;
2837 : :
2838 : 0 : adapter = IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2839 : :
2840 : 0 : rte_spinlock_lock(&adapter->phc_sync_lock);
2841 [ # # # # ]: 0 : if (adapter->phc_sync_paused || !iavf_phc_sync_alarm_needed(dev)) {
2842 : 0 : adapter->phc_sync_ticks = 0;
2843 : 0 : goto unlock;
2844 : : }
2845 : :
2846 [ # # ]: 0 : if (++adapter->phc_sync_ticks < phc_sync_ticks_max)
2847 : 0 : goto unlock;
2848 : :
2849 : 0 : adapter->phc_sync_ticks = 0;
2850 : : sync_rxq = iavf_phc_sync_rxq_get(dev);
2851 [ # # ]: 0 : if (sync_rxq == NULL)
2852 : 0 : goto unlock;
2853 : :
2854 [ # # ]: 0 : if (iavf_get_phc_time(sync_rxq) != 0) {
2855 : 0 : PMD_DRV_LOG(ERR, "get physical time failed");
2856 : 0 : goto unlock;
2857 : : }
2858 : :
2859 : 0 : sw_cur_time = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
2860 : 0 : iavf_phc_sync_update_all_rxq(dev, sync_rxq->phc_time, sw_cur_time);
2861 : :
2862 : 0 : unlock:
2863 : : rte_spinlock_unlock(&adapter->phc_sync_lock);
2864 : 0 : }
2865 : :
2866 : : void
2867 : 0 : iavf_dev_alarm_handler(void *param)
2868 : : {
2869 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2870 : : struct iavf_info *vf;
2871 [ # # # # : 0 : if (dev == NULL || dev->data == NULL || dev->data->dev_private == NULL)
# # ]
2872 : : return;
2873 : :
2874 : : vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2875 : : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2876 : : uint32_t icr0;
2877 : :
2878 [ # # ]: 0 : if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)) {
2879 : : iavf_disable_irq0(hw);
2880 : :
2881 : : /* read out interrupt causes */
2882 : 0 : icr0 = IAVF_READ_REG(hw, IAVF_VFINT_ICR01);
2883 : :
2884 [ # # ]: 0 : if (icr0 & IAVF_VFINT_ICR01_ADMINQ_MASK) {
2885 : 0 : PMD_DRV_LOG(DEBUG, "ICR01_ADMINQ is reported");
2886 : 0 : iavf_handle_virtchnl_msg(dev);
2887 : : }
2888 : :
2889 : : iavf_enable_irq0(hw);
2890 : : }
2891 : :
2892 : 0 : iavf_phc_sync_tick(dev);
2893 : :
2894 : 0 : rte_eal_alarm_set(IAVF_ALARM_INTERVAL,
2895 : : iavf_dev_alarm_handler, dev);
2896 : : }
2897 : :
2898 : : static bool
2899 : 0 : iavf_phc_sync_alarm_needed(struct rte_eth_dev *dev)
2900 : : {
2901 : : struct iavf_adapter *adapter;
2902 : :
2903 : 0 : adapter = IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2904 : :
2905 [ # # ]: 0 : if (adapter->closed || adapter->stopped)
2906 : : return false;
2907 : :
2908 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP))
2909 : : return false;
2910 : :
2911 [ # # ]: 0 : if (dev->data->nb_rx_queues == 0)
2912 : : return false;
2913 : :
2914 [ # # ]: 0 : if (iavf_phc_sync_rxq_get(dev) == NULL)
2915 : 0 : return false;
2916 : :
2917 : : return true;
2918 : : }
2919 : :
2920 : : void
2921 : 0 : iavf_phc_sync_alarm_start(struct rte_eth_dev *dev)
2922 : : {
2923 : : struct iavf_adapter *adapter;
2924 : :
2925 [ # # ]: 0 : if (!iavf_phc_sync_alarm_needed(dev))
2926 : : return;
2927 : :
2928 : 0 : adapter = IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2929 : 0 : rte_spinlock_lock(&adapter->phc_sync_lock);
2930 : 0 : adapter->phc_sync_paused = false;
2931 : 0 : adapter->phc_sync_ticks = 0;
2932 : : rte_spinlock_unlock(&adapter->phc_sync_lock);
2933 : : }
2934 : :
2935 : : void
2936 : 0 : iavf_phc_sync_alarm_stop(struct rte_eth_dev *dev)
2937 : : {
2938 : : struct iavf_adapter *adapter;
2939 : :
2940 [ # # # # : 0 : if (dev == NULL || dev->data == NULL || dev->data->dev_private == NULL)
# # ]
2941 : : return;
2942 : :
2943 : : adapter = IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2944 : 0 : rte_spinlock_lock(&adapter->phc_sync_lock);
2945 : 0 : adapter->phc_sync_paused = true;
2946 : 0 : adapter->phc_sync_ticks = 0;
2947 : : rte_spinlock_unlock(&adapter->phc_sync_lock);
2948 : : }
2949 : :
2950 : : static int
2951 : 0 : iavf_dev_flow_ops_get(struct rte_eth_dev *dev,
2952 : : const struct rte_flow_ops **ops)
2953 : : {
2954 : 0 : struct iavf_adapter *adapter =
2955 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2956 : :
2957 [ # # ]: 0 : if (adapter->closed)
2958 : : return -EIO;
2959 : :
2960 : 0 : *ops = &iavf_flow_ops;
2961 : 0 : return 0;
2962 : : }
2963 : :
2964 : : static void
2965 : 0 : iavf_default_rss_disable(struct iavf_adapter *adapter)
2966 : : {
2967 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2968 : : int ret = 0;
2969 : :
2970 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
2971 : : /* Set hena = 0 to ask PF to cleanup all existing RSS. */
2972 : 0 : ret = iavf_set_hena(adapter, 0);
2973 [ # # ]: 0 : if (ret)
2974 : : /* It is a workaround, temporarily allow error to be
2975 : : * returned due to possible lack of PF handling for
2976 : : * hena = 0.
2977 : : */
2978 : 0 : PMD_INIT_LOG(WARNING, "fail to disable default RSS,"
2979 : : "lack PF support");
2980 : : }
2981 : 0 : }
2982 : :
2983 : : static int
2984 : 0 : iavf_dev_init(struct rte_eth_dev *eth_dev)
2985 : : {
2986 : 0 : struct iavf_adapter *adapter =
2987 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
2988 : : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
2989 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2990 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(eth_dev, *pci_dev);
2991 : : int ret = 0;
2992 : :
2993 : 0 : PMD_INIT_FUNC_TRACE();
2994 : :
2995 : : /* assign ops func pointer */
2996 : 0 : eth_dev->dev_ops = &iavf_eth_dev_ops;
2997 : 0 : eth_dev->rx_queue_count = iavf_dev_rxq_count;
2998 : 0 : eth_dev->rx_descriptor_status = iavf_dev_rx_desc_status;
2999 : 0 : eth_dev->tx_descriptor_status = iavf_dev_tx_desc_status;
3000 : 0 : eth_dev->rx_pkt_burst = &iavf_recv_pkts;
3001 : 0 : eth_dev->tx_pkt_burst = &iavf_xmit_pkts;
3002 : 0 : eth_dev->tx_pkt_prepare = &iavf_prep_pkts;
3003 : :
3004 : : /* For secondary processes, we don't initialise any further as primary
3005 : : * has already done this work.
3006 : : */
3007 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
3008 : 0 : iavf_set_rx_function(eth_dev);
3009 : : /* LLDP may have been enabled by the primary process. Store the offset before
3010 : : * setting the TX function because it may be used in the selection function.
3011 : : */
3012 : 0 : rte_pmd_iavf_tx_lldp_dynfield_offset =
3013 : 0 : rte_mbuf_dynfield_lookup(IAVF_TX_LLDP_DYNFIELD, NULL);
3014 : 0 : iavf_set_tx_function(eth_dev);
3015 : 0 : return 0;
3016 : : }
3017 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
3018 : :
3019 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
3020 : 0 : hw->device_id = pci_dev->id.device_id;
3021 : 0 : hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
3022 : 0 : hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
3023 : 0 : hw->bus.bus_id = pci_dev->addr.bus;
3024 : 0 : hw->bus.device = pci_dev->addr.devid;
3025 : 0 : hw->bus.func = pci_dev->addr.function;
3026 : 0 : hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
3027 : 0 : hw->back = IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
3028 : 0 : adapter->dev_data = eth_dev->data;
3029 : 0 : adapter->stopped = 1;
3030 : 0 : adapter->mac_primary_set = false;
3031 [ # # ]: 0 : adapter->tpid = RTE_ETHER_TYPE_VLAN; /* VLAN TPID set to 0x8100 by default */
3032 : : rte_spinlock_init(&adapter->phc_sync_lock);
3033 : :
3034 [ # # # # ]: 0 : if (!vf->in_reset_recovery && iavf_dev_event_handler_init())
3035 : 0 : goto init_vf_err;
3036 : :
3037 [ # # ]: 0 : if (iavf_init_vf(eth_dev) != 0) {
3038 : 0 : PMD_INIT_LOG(ERR, "Init vf failed");
3039 : 0 : return -1;
3040 : : }
3041 : :
3042 : : /* set default ptype table */
3043 : 0 : iavf_set_default_ptype_table(eth_dev);
3044 : :
3045 : : /* copy mac addr */
3046 : 0 : eth_dev->data->mac_addrs = rte_zmalloc(
3047 : : "iavf_mac", RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX, 0);
3048 [ # # ]: 0 : if (!eth_dev->data->mac_addrs) {
3049 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to"
3050 : : " store MAC addresses",
3051 : : RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX);
3052 : : ret = -ENOMEM;
3053 : 0 : goto init_vf_err;
3054 : : }
3055 : : /* If the MAC address is not configured by host,
3056 : : * generate a random one.
3057 : : */
3058 : : if (!rte_is_valid_assigned_ether_addr(
3059 : : (struct rte_ether_addr *)hw->mac.addr))
3060 : 0 : rte_eth_random_addr(hw->mac.addr);
3061 : 0 : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
3062 [ # # ]: 0 : ð_dev->data->mac_addrs[0]);
3063 : :
3064 : :
3065 [ # # # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR &&
3066 : : /* register callback func to eal lib */
3067 : 0 : rte_intr_callback_register(pci_dev->intr_handle,
3068 : : iavf_dev_interrupt_handler, (void *)eth_dev) == 0)
3069 : :
3070 : : /* enable uio intr after callback register */
3071 : 0 : rte_intr_enable(pci_dev->intr_handle);
3072 : :
3073 : 0 : rte_eal_alarm_set(IAVF_ALARM_INTERVAL,
3074 : : iavf_dev_alarm_handler, eth_dev);
3075 : :
3076 : : /* configure and enable device interrupt */
3077 : : iavf_enable_irq0(hw);
3078 : 0 : vf->aq_intr_enabled = true;
3079 : :
3080 : 0 : ret = iavf_flow_init(adapter);
3081 [ # # ]: 0 : if (ret) {
3082 : 0 : PMD_INIT_LOG(ERR, "Failed to initialize flow");
3083 : 0 : goto flow_init_err;
3084 : : }
3085 : :
3086 : : /** Check if the IPsec Crypto offload is supported and create
3087 : : * security_ctx if it is.
3088 : : */
3089 [ # # ]: 0 : if (iavf_ipsec_crypto_supported(adapter)) {
3090 : : /* Initialize security_ctx only for primary process*/
3091 : 0 : ret = iavf_security_ctx_create(adapter);
3092 [ # # ]: 0 : if (ret) {
3093 : 0 : PMD_INIT_LOG(ERR, "failed to create ipsec crypto security instance");
3094 : 0 : goto flow_init_err;
3095 : : }
3096 : :
3097 : 0 : ret = iavf_security_init(adapter);
3098 [ # # ]: 0 : if (ret) {
3099 : 0 : PMD_INIT_LOG(ERR, "failed to initialized ipsec crypto resources");
3100 : 0 : goto security_init_err;
3101 : : }
3102 : : }
3103 : :
3104 : : /* Get PTP caps early to verify device capabilities */
3105 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP) {
3106 [ # # ]: 0 : if (iavf_get_ptp_cap(adapter)) {
3107 : 0 : PMD_INIT_LOG(ERR, "Failed to get ptp capability");
3108 : 0 : goto security_init_err;
3109 : : }
3110 : : }
3111 : :
3112 : 0 : iavf_default_rss_disable(adapter);
3113 : :
3114 : 0 : iavf_dev_stats_reset(eth_dev);
3115 : :
3116 : : /* Start device watchdog */
3117 : 0 : iavf_dev_watchdog_enable(adapter);
3118 : 0 : adapter->closed = false;
3119 : :
3120 : 0 : return 0;
3121 : :
3122 : 0 : security_init_err:
3123 : 0 : iavf_security_ctx_destroy(adapter);
3124 : :
3125 : 0 : flow_init_err:
3126 : 0 : vf->aq_intr_enabled = false;
3127 : : iavf_disable_irq0(hw);
3128 : :
3129 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
3130 : : /* disable uio intr before callback unregiser */
3131 : 0 : rte_intr_disable(pci_dev->intr_handle);
3132 : :
3133 : : /* unregister callback func from eal lib */
3134 : 0 : rte_intr_callback_unregister(pci_dev->intr_handle,
3135 : : iavf_dev_interrupt_handler, eth_dev);
3136 : : }
3137 : 0 : iavf_phc_sync_alarm_stop(eth_dev);
3138 : 0 : rte_eal_alarm_cancel(iavf_dev_alarm_handler, eth_dev);
3139 : :
3140 : 0 : rte_free(eth_dev->data->mac_addrs);
3141 : 0 : eth_dev->data->mac_addrs = NULL;
3142 : :
3143 : 0 : init_vf_err:
3144 : 0 : iavf_uninit_vf(eth_dev);
3145 : :
3146 : 0 : return ret;
3147 : : }
3148 : :
3149 : : static int
3150 : 0 : iavf_dev_close(struct rte_eth_dev *dev)
3151 : : {
3152 : 0 : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3153 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
3154 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
3155 : : struct iavf_adapter *adapter =
3156 : : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3157 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
3158 : : int ret;
3159 : :
3160 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3161 : : return 0;
3162 : :
3163 [ # # ]: 0 : if (adapter->closed) {
3164 : : ret = 0;
3165 : 0 : goto out;
3166 : : }
3167 : :
3168 : 0 : ret = iavf_dev_stop(dev);
3169 : :
3170 : : /*
3171 : : * Release redundant queue resource when close the dev
3172 : : * so that other vfs can re-use the queues.
3173 : : */
3174 [ # # ]: 0 : if (vf->lv_enabled) {
3175 : 0 : ret = iavf_request_queues(dev, IAVF_MAX_NUM_QUEUES_DFLT);
3176 [ # # ]: 0 : if (ret)
3177 : 0 : PMD_DRV_LOG(ERR, "Reset the num of queues failed");
3178 : :
3179 : 0 : vf->max_rss_qregion = IAVF_MAX_NUM_QUEUES_DFLT;
3180 : : }
3181 : :
3182 : : /* Disable promiscuous mode before resetting the VF. This is to avoid
3183 : : * potential issues when the PF is bound to the kernel driver.
3184 : : */
3185 [ # # ]: 0 : if (vf->promisc_unicast_enabled || vf->promisc_multicast_enabled)
3186 : 0 : iavf_config_promisc(adapter, false, false);
3187 : :
3188 : 0 : adapter->closed = true;
3189 : :
3190 : : /* free iAVF security device context all related resources */
3191 : 0 : iavf_security_ctx_destroy(adapter);
3192 : :
3193 : : /* remove RSS configuration */
3194 : 0 : iavf_hash_uninit(adapter);
3195 : :
3196 : 0 : iavf_flow_flush(dev, NULL);
3197 : 0 : iavf_flow_uninit(adapter);
3198 : :
3199 : 0 : iavf_vf_reset(hw);
3200 : : /*
3201 : : * If a reset is pending, wait for the PF to disable the VF's admin
3202 : : * receive queue (its first reset action) before we shut it down
3203 : : * ourselves. This ensures iavf_check_vf_reset_done() does not see
3204 : : * a stale VFACTIVE value on the re-init path.
3205 : : */
3206 [ # # ]: 0 : if (vf->reset_pending)
3207 : : iavf_is_reset_detected(adapter);
3208 : 0 : vf->aq_intr_enabled = false;
3209 : 0 : iavf_shutdown_adminq(hw);
3210 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
3211 : : /* disable uio intr before callback unregister */
3212 : 0 : rte_intr_disable(intr_handle);
3213 : :
3214 : : /* unregister callback func from eal lib */
3215 : 0 : rte_intr_callback_unregister(intr_handle,
3216 : : iavf_dev_interrupt_handler, dev);
3217 : : }
3218 : 0 : iavf_phc_sync_alarm_stop(dev);
3219 : 0 : rte_eal_alarm_cancel(iavf_dev_alarm_handler, dev);
3220 : : iavf_disable_irq0(hw);
3221 : :
3222 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_QOS)
3223 : 0 : iavf_tm_conf_uninit(dev);
3224 : :
3225 [ # # ]: 0 : if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
3226 [ # # ]: 0 : if (vf->rss_lut) {
3227 : 0 : rte_free(vf->rss_lut);
3228 : 0 : vf->rss_lut = NULL;
3229 : : }
3230 [ # # ]: 0 : if (vf->rss_key) {
3231 : 0 : rte_free(vf->rss_key);
3232 : 0 : vf->rss_key = NULL;
3233 : : }
3234 : : }
3235 : :
3236 : 0 : rte_free(vf->vf_res);
3237 : 0 : vf->vsi_res = NULL;
3238 : 0 : vf->vf_res = NULL;
3239 : :
3240 : : /*
3241 : : * If the VF is reset via VFLR, the device will be knocked out of bus
3242 : : * master mode, and the driver will fail to recover from the reset. Fix
3243 : : * this by enabling bus mastering after every reset. In a non-VFLR case,
3244 : : * the bus master bit will not be disabled, and this call will have no
3245 : : * effect.
3246 : : */
3247 : 0 : out:
3248 [ # # # # ]: 0 : if (vf->vf_reset && !rte_pci_set_bus_master(pci_dev, true)) {
3249 : 0 : vf->vf_reset = false;
3250 : 0 : iavf_set_no_poll(adapter, false);
3251 : : }
3252 : :
3253 : : /* disable watchdog */
3254 : 0 : iavf_dev_watchdog_disable(adapter);
3255 : :
3256 : 0 : return ret;
3257 : : }
3258 : :
3259 : : static int
3260 : 0 : iavf_dev_uninit(struct rte_eth_dev *dev)
3261 : : {
3262 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
3263 : :
3264 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3265 : : return -EPERM;
3266 : :
3267 : 0 : iavf_dev_close(dev);
3268 : :
3269 [ # # ]: 0 : if (!vf->in_reset_recovery)
3270 : 0 : iavf_dev_event_handler_fini();
3271 : :
3272 : : return 0;
3273 : : }
3274 : :
3275 : : /*
3276 : : * Reset VF device only to re-initialize resources in PMD layer
3277 : : */
3278 : : static int
3279 : 0 : iavf_dev_reset(struct rte_eth_dev *dev)
3280 : : {
3281 : : int ret;
3282 : 0 : struct iavf_adapter *adapter =
3283 : 0 : IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3284 : : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3285 : : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
3286 : : /*
3287 : : * Check whether the VF reset has been done and inform application,
3288 : : * to avoid calling the virtual channel command, which may cause
3289 : : * the device to be abnormal.
3290 : : */
3291 : : ret = iavf_check_vf_reset_done(hw);
3292 : : if (ret) {
3293 : 0 : PMD_DRV_LOG(ERR, "Wait too long for reset done!");
3294 : 0 : return ret;
3295 : : }
3296 : 0 : iavf_set_no_poll(adapter, false);
3297 : :
3298 : 0 : vf->reset_pending = true;
3299 : 0 : PMD_DRV_LOG(DEBUG, "Start dev_reset ...");
3300 : 0 : ret = iavf_dev_uninit(dev);
3301 : 0 : vf->reset_pending = false;
3302 [ # # ]: 0 : if (ret)
3303 : : return ret;
3304 : :
3305 : 0 : return iavf_dev_init(dev);
3306 : : }
3307 : :
3308 : : static inline bool
3309 : : iavf_is_reset(struct iavf_hw *hw)
3310 : : {
3311 : 0 : return !(IAVF_READ_REG(hw, IAVF_VF_ARQLEN1) &
3312 : : IAVF_VF_ARQLEN1_ARQENABLE_MASK);
3313 : : }
3314 : :
3315 : : static bool
3316 : : iavf_is_reset_detected(struct iavf_adapter *adapter)
3317 : : {
3318 : : struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
3319 : : int i;
3320 : :
3321 : : /* poll until we see the reset actually happen */
3322 [ # # # # ]: 0 : for (i = 0; i < IAVF_RESET_DETECTED_CNT; i++) {
3323 [ # # # # ]: 0 : if (iavf_is_reset(hw))
3324 : : return true;
3325 : : rte_delay_ms(20);
3326 : : }
3327 : :
3328 : : return false;
3329 : : }
3330 : :
3331 : : static int
3332 : 0 : iavf_post_reset_reconfig(struct rte_eth_dev *dev)
3333 : : {
3334 : : int ret, status = 0;
3335 : : bool allmulti = false, allunicast = false;
3336 : 0 : struct iavf_adapter *adapter = IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3337 : :
3338 : : /* Restore pre-reset unicast promiscuous and multicast promiscuous states */
3339 [ # # ]: 0 : if (dev->data->promiscuous)
3340 : : allunicast = true;
3341 [ # # ]: 0 : if (dev->data->all_multicast)
3342 : : allmulti = true;
3343 [ # # ]: 0 : if (allmulti || allunicast) {
3344 : 0 : ret = iavf_config_promisc(adapter, allunicast, allmulti);
3345 [ # # ]: 0 : if (ret)
3346 [ # # # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to restore unicast promiscuous mode (%s) "
3347 : : "and multicast promiscuous mode (%s)",
3348 : : allunicast ? "on" : "off", allmulti ? "on" : "off");
3349 : : else
3350 [ # # # # ]: 0 : PMD_DRV_LOG(DEBUG, "Restored unicast promiscuous mode (%s) "
3351 : : "and multicast promiscuous mode (%s)",
3352 : : allunicast ? "on" : "off", allmulti ? "on" : "off");
3353 : : status |= ret;
3354 : : }
3355 : :
3356 : 0 : return status;
3357 : : }
3358 : :
3359 : : /*
3360 : : * Handle hardware reset
3361 : : */
3362 : : void
3363 : 0 : iavf_handle_hw_reset(struct rte_eth_dev *dev, bool vf_initiated_reset)
3364 : : {
3365 : 0 : struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
3366 : : struct iavf_adapter *adapter = dev->data->dev_private;
3367 : : int ret;
3368 : : bool restart_device = false;
3369 : :
3370 [ # # ]: 0 : if (vf_initiated_reset) {
3371 : 0 : restart_device = dev->data->dev_started;
3372 : : } else {
3373 [ # # ]: 0 : if (!dev->data->dev_started)
3374 : : return;
3375 : :
3376 [ # # ]: 0 : if (!iavf_is_reset_detected(adapter)) {
3377 : 0 : PMD_DRV_LOG(DEBUG, "reset not start");
3378 : 0 : return;
3379 : : }
3380 : : }
3381 : :
3382 : 0 : vf->in_reset_recovery = true;
3383 : 0 : iavf_set_no_poll(adapter, false);
3384 : :
3385 : : /* Call the pre reset callback */
3386 [ # # ]: 0 : if (vf->pre_reset_cb != NULL)
3387 : 0 : vf->pre_reset_cb(dev->data->port_id, vf->pre_reset_cb_arg);
3388 : :
3389 : 0 : ret = iavf_dev_reset(dev);
3390 [ # # ]: 0 : if (ret)
3391 : 0 : goto error;
3392 : :
3393 : : /* VF states restore */
3394 : 0 : ret = iavf_dev_configure(dev);
3395 [ # # ]: 0 : if (ret)
3396 : 0 : goto error;
3397 : :
3398 : 0 : iavf_dev_xstats_reset(dev);
3399 : :
3400 [ # # ]: 0 : if (!vf_initiated_reset || restart_device) {
3401 : : /* start the device */
3402 : 0 : ret = iavf_dev_start(dev);
3403 [ # # ]: 0 : if (ret)
3404 : 0 : goto error;
3405 : :
3406 : 0 : dev->data->dev_started = 1;
3407 : : }
3408 : :
3409 : : /* Restore settings after the reset */
3410 [ # # ]: 0 : if (adapter->devargs.auto_reconfig) {
3411 : 0 : ret = iavf_post_reset_reconfig(dev);
3412 [ # # ]: 0 : if (ret) {
3413 : 0 : PMD_DRV_LOG(ERR, "Failed to restore VF settings after reset");
3414 : 0 : goto error;
3415 : : }
3416 : : } else {
3417 : 0 : dev->data->promiscuous = 0;
3418 : 0 : dev->data->all_multicast = 0;
3419 : 0 : vf->promisc_unicast_enabled = false;
3420 : 0 : vf->promisc_multicast_enabled = false;
3421 : : }
3422 : :
3423 : 0 : goto exit;
3424 : :
3425 : 0 : error:
3426 : 0 : PMD_DRV_LOG(DEBUG, "RESET recover with error code=%d", ret);
3427 : 0 : exit:
3428 : : /* Call the post reset callback */
3429 [ # # ]: 0 : if (vf->post_reset_cb != NULL)
3430 : 0 : vf->post_reset_cb(dev->data->port_id, ret, vf->post_reset_cb_arg);
3431 : :
3432 : 0 : vf->in_reset_recovery = false;
3433 : 0 : iavf_set_no_poll(adapter, false);
3434 : :
3435 : 0 : return;
3436 : : }
3437 : :
3438 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_iavf_reinit, 25.11)
3439 : : int
3440 : 0 : rte_pmd_iavf_reinit(uint16_t port)
3441 : : {
3442 : : struct rte_eth_dev *dev;
3443 : : struct iavf_adapter *adapter;
3444 : :
3445 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
3446 : :
3447 : 0 : dev = &rte_eth_devices[port];
3448 : :
3449 [ # # ]: 0 : if (!is_iavf_supported(dev)) {
3450 : 0 : PMD_DRV_LOG(ERR, "Cannot reinit VF, port %u is not an IAVF device.", port);
3451 : 0 : return -ENOTSUP;
3452 : : }
3453 : :
3454 [ # # ]: 0 : if (!dev->data->dev_configured) {
3455 : 0 : PMD_DRV_LOG(ERR, "Cannot reinit unconfigured port %u.", port);
3456 : 0 : return -EINVAL;
3457 : : }
3458 : :
3459 : 0 : adapter = dev->data->dev_private;
3460 [ # # # # ]: 0 : if (dev->data->dev_started && !adapter->devargs.no_poll_on_link_down) {
3461 : 0 : PMD_DRV_LOG(ERR, "Cannot reinit started port %u. Either stop the port or enable "
3462 : : "no-poll-on-link-down in devargs.", port);
3463 : 0 : return -EINVAL;
3464 : : }
3465 : :
3466 : 0 : iavf_handle_hw_reset(dev, true);
3467 : :
3468 : 0 : return 0;
3469 : : }
3470 : :
3471 : : static int
3472 : 0 : iavf_validate_reset_cb(uint16_t port, void *cb, void *cb_arg)
3473 : : {
3474 : : struct rte_eth_dev *dev;
3475 : : struct iavf_info *vf;
3476 : :
3477 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
3478 : :
3479 [ # # ]: 0 : if (cb == NULL && cb_arg != NULL) {
3480 : 0 : PMD_DRV_LOG(ERR, "Cannot unregister reset cb on port %u, arg must be NULL.", port);
3481 : 0 : return -EINVAL;
3482 : : }
3483 : :
3484 : 0 : dev = &rte_eth_devices[port];
3485 [ # # ]: 0 : if (!is_iavf_supported(dev)) {
3486 : 0 : PMD_DRV_LOG(ERR, "Cannot modify reset cb, port %u not an IAVF device.", port);
3487 : 0 : return -ENOTSUP;
3488 : : }
3489 : :
3490 : 0 : vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
3491 [ # # ]: 0 : if (vf->in_reset_recovery) {
3492 : 0 : PMD_DRV_LOG(ERR, "Cannot modify reset cb on port %u, VF is resetting.", port);
3493 : 0 : return -EBUSY;
3494 : : }
3495 : :
3496 : : return 0;
3497 : : }
3498 : :
3499 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_iavf_register_pre_reset_cb, 26.03)
3500 : : int
3501 : 0 : rte_pmd_iavf_register_pre_reset_cb(uint16_t port,
3502 : : iavf_pre_reset_cb_t pre_reset_cb,
3503 : : void *pre_reset_cb_arg)
3504 : : {
3505 : : struct rte_eth_dev *dev;
3506 : : struct iavf_info *vf;
3507 : : int ret;
3508 : :
3509 : 0 : ret = iavf_validate_reset_cb(port, pre_reset_cb, pre_reset_cb_arg);
3510 [ # # ]: 0 : if (ret)
3511 : : return ret;
3512 : :
3513 : : dev = &rte_eth_devices[port];
3514 : 0 : vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
3515 : 0 : vf->pre_reset_cb = pre_reset_cb;
3516 : 0 : vf->pre_reset_cb_arg = pre_reset_cb_arg;
3517 : :
3518 : 0 : return 0;
3519 : : }
3520 : :
3521 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_iavf_register_post_reset_cb, 26.03)
3522 : : int
3523 : 0 : rte_pmd_iavf_register_post_reset_cb(uint16_t port,
3524 : : iavf_post_reset_cb_t post_reset_cb,
3525 : : void *post_reset_cb_arg)
3526 : : {
3527 : : struct rte_eth_dev *dev;
3528 : : struct iavf_info *vf;
3529 : : int ret;
3530 : :
3531 : 0 : ret = iavf_validate_reset_cb(port, post_reset_cb, post_reset_cb_arg);
3532 [ # # ]: 0 : if (ret)
3533 : : return ret;
3534 : :
3535 : : dev = &rte_eth_devices[port];
3536 : 0 : vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
3537 : 0 : vf->post_reset_cb = post_reset_cb;
3538 : 0 : vf->post_reset_cb_arg = post_reset_cb_arg;
3539 : :
3540 : 0 : return 0;
3541 : : }
3542 : :
3543 : : void
3544 : 0 : iavf_set_no_poll(struct iavf_adapter *adapter, bool link_change)
3545 : : {
3546 : : struct iavf_info *vf = &adapter->vf;
3547 : :
3548 : 0 : adapter->no_poll = (link_change & !vf->link_up) ||
3549 [ # # # # : 0 : vf->vf_reset || vf->in_reset_recovery;
# # ]
3550 : 0 : }
3551 : :
3552 : : static int
3553 : 0 : iavf_dcf_cap_check_handler(__rte_unused const char *key,
3554 : : const char *value, __rte_unused void *opaque)
3555 : : {
3556 [ # # ]: 0 : if (strcmp(value, "dcf"))
3557 : 0 : return -1;
3558 : :
3559 : : return 0;
3560 : : }
3561 : :
3562 : : static int
3563 : 0 : iavf_dcf_cap_selected(struct rte_devargs *devargs)
3564 : : {
3565 : : struct rte_kvargs *kvlist;
3566 : : const char *key = "cap";
3567 : : int ret = 0;
3568 : :
3569 [ # # ]: 0 : if (devargs == NULL)
3570 : : return 0;
3571 : :
3572 : 0 : kvlist = rte_kvargs_parse(devargs->args, NULL);
3573 [ # # ]: 0 : if (kvlist == NULL)
3574 : : return 0;
3575 : :
3576 [ # # ]: 0 : if (!rte_kvargs_count(kvlist, key))
3577 : 0 : goto exit;
3578 : :
3579 : : /* dcf capability selected when there's a key-value pair: cap=dcf */
3580 [ # # ]: 0 : if (rte_kvargs_process(kvlist, key,
3581 : : iavf_dcf_cap_check_handler, NULL) < 0)
3582 : 0 : goto exit;
3583 : :
3584 : : ret = 1;
3585 : :
3586 : 0 : exit:
3587 : 0 : rte_kvargs_free(kvlist);
3588 : 0 : return ret;
3589 : : }
3590 : :
3591 : 0 : static int eth_iavf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
3592 : : struct rte_pci_device *pci_dev)
3593 : : {
3594 [ # # ]: 0 : if (iavf_dcf_cap_selected(pci_dev->device.devargs))
3595 : : return 1;
3596 : :
3597 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
3598 : : sizeof(struct iavf_adapter), iavf_dev_init);
3599 : : }
3600 : :
3601 : 0 : static int eth_iavf_pci_remove(struct rte_pci_device *pci_dev)
3602 : : {
3603 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, iavf_dev_uninit);
3604 : : }
3605 : :
3606 : : /* Adaptive virtual function driver struct */
3607 : : static struct rte_pci_driver rte_iavf_pmd = {
3608 : : .id_table = pci_id_iavf_map,
3609 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
3610 : : .probe = eth_iavf_pci_probe,
3611 : : .remove = eth_iavf_pci_remove,
3612 : : };
3613 : :
3614 : 0 : bool is_iavf_supported(struct rte_eth_dev *dev)
3615 : : {
3616 : 0 : return !strcmp(dev->device->driver->name, rte_iavf_pmd.driver.name);
3617 : : }
3618 : :
3619 : 301 : RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
3620 : : RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
3621 : : RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
3622 : : RTE_PMD_REGISTER_PARAM_STRING(net_iavf, "cap=dcf");
3623 [ - + ]: 301 : RTE_LOG_REGISTER_SUFFIX(iavf_logtype_init, init, NOTICE);
3624 [ - + ]: 301 : RTE_LOG_REGISTER_SUFFIX(iavf_logtype_driver, driver, NOTICE);
3625 : : #ifdef RTE_ETHDEV_DEBUG_RX
3626 : : RTE_LOG_REGISTER_SUFFIX(iavf_logtype_rx, rx, DEBUG);
3627 : : #endif
3628 : : #ifdef RTE_ETHDEV_DEBUG_TX
3629 : : RTE_LOG_REGISTER_SUFFIX(iavf_logtype_tx, tx, DEBUG);
3630 : : #endif
|