Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2017 Intel Corporation
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdio.h>
7 : : #include <errno.h>
8 : : #include <stdint.h>
9 : : #include <string.h>
10 : : #include <unistd.h>
11 : : #include <stdarg.h>
12 : : #include <inttypes.h>
13 : :
14 : : #include <rte_string_fns.h>
15 : : #include <rte_pci.h>
16 : : #include <rte_ether.h>
17 : : #include <ethdev_driver.h>
18 : : #include <rte_malloc.h>
19 : : #include <rte_memcpy.h>
20 : :
21 : : #include "i40e_logs.h"
22 : : #include "base/i40e_prototype.h"
23 : : #include "base/i40e_adminq_cmd.h"
24 : : #include "base/i40e_type.h"
25 : : #include "i40e_ethdev.h"
26 : : #include "i40e_rxtx.h"
27 : : #include "i40e_pf.h"
28 : : #include "rte_pmd_i40e.h"
29 : :
30 : : #define I40E_CFG_CRCSTRIP_DEFAULT 1
31 : :
32 : : /* Supported RSS offloads */
33 : : #define I40E_DEFAULT_RSS_HENA ( \
34 : : BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | \
35 : : BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) | \
36 : : BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP) | \
37 : : BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | \
38 : : BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4) | \
39 : : BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | \
40 : : BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP) | \
41 : : BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) | \
42 : : BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | \
43 : : BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6) | \
44 : : BIT_ULL(I40E_FILTER_PCTYPE_L2_PAYLOAD))
45 : :
46 : : #define I40E_DEFAULT_RSS_HENA_EXPANDED (I40E_DEFAULT_RSS_HENA | \
47 : : BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK) | \
48 : : BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) | \
49 : : BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) | \
50 : : BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK) | \
51 : : BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | \
52 : : BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP))
53 : :
54 : : static int
55 : : i40e_pf_host_switch_queues(struct i40e_pf_vf *vf,
56 : : struct virtchnl_queue_select *qsel,
57 : : bool on);
58 : :
59 : : /**
60 : : * Bind PF queues with VSI and VF.
61 : : **/
62 : : static int
63 : 0 : i40e_pf_vf_queues_mapping(struct i40e_pf_vf *vf)
64 : : {
65 : : int i;
66 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
67 : 0 : uint16_t vsi_id = vf->vsi->vsi_id;
68 : 0 : uint16_t vf_id = vf->vf_idx;
69 : 0 : uint16_t nb_qps = vf->vsi->nb_qps;
70 : 0 : uint16_t qbase = vf->vsi->base_queue;
71 : : uint16_t q1, q2;
72 : : uint32_t val;
73 : :
74 : : /*
75 : : * VF should use scatter range queues. So, it needn't
76 : : * to set QBASE in this register.
77 : : */
78 : 0 : i40e_write_rx_ctl(hw, I40E_VSILAN_QBASE(vsi_id),
79 : : I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
80 : :
81 : : /* Set to enable VFLAN_QTABLE[] registers valid */
82 : 0 : I40E_WRITE_REG(hw, I40E_VPLAN_MAPENA(vf_id),
83 : : I40E_VPLAN_MAPENA_TXRX_ENA_MASK);
84 : :
85 : : /* map PF queues to VF */
86 [ # # ]: 0 : for (i = 0; i < nb_qps; i++) {
87 : 0 : val = ((qbase + i) & I40E_VPLAN_QTABLE_QINDEX_MASK);
88 : 0 : I40E_WRITE_REG(hw, I40E_VPLAN_QTABLE(i, vf_id), val);
89 : : }
90 : :
91 : : /* map PF queues to VSI */
92 [ # # ]: 0 : for (i = 0; i < I40E_MAX_QP_NUM_PER_VF / 2; i++) {
93 [ # # ]: 0 : if (2 * i > nb_qps - 1)
94 : : q1 = I40E_VSILAN_QTABLE_QINDEX_0_MASK;
95 : : else
96 : 0 : q1 = qbase + 2 * i;
97 : :
98 [ # # ]: 0 : if (2 * i + 1 > nb_qps - 1)
99 : : q2 = I40E_VSILAN_QTABLE_QINDEX_0_MASK;
100 : : else
101 : 0 : q2 = qbase + 2 * i + 1;
102 : :
103 : 0 : val = (q2 << I40E_VSILAN_QTABLE_QINDEX_1_SHIFT) + q1;
104 : 0 : i40e_write_rx_ctl(hw, I40E_VSILAN_QTABLE(i, vsi_id), val);
105 : : }
106 : 0 : I40E_WRITE_FLUSH(hw);
107 : :
108 : 0 : return I40E_SUCCESS;
109 : : }
110 : :
111 : :
112 : : /**
113 : : * Proceed VF reset operation.
114 : : */
115 : : int
116 : 0 : i40e_pf_host_vf_reset(struct i40e_pf_vf *vf, bool do_hw_reset)
117 : : {
118 : : uint32_t val, i;
119 : : struct i40e_hw *hw;
120 : : struct i40e_pf *pf;
121 : : uint16_t vf_id, abs_vf_id, vf_msix_num;
122 : : int ret;
123 : : struct virtchnl_queue_select qsel;
124 : :
125 [ # # ]: 0 : if (vf == NULL)
126 : : return -EINVAL;
127 : :
128 : 0 : pf = vf->pf;
129 : 0 : hw = I40E_PF_TO_HW(vf->pf);
130 : 0 : vf_id = vf->vf_idx;
131 : 0 : abs_vf_id = vf_id + hw->func_caps.vf_base_id;
132 : :
133 : : /* Notify VF that we are in VFR progress */
134 : 0 : I40E_WRITE_REG(hw, I40E_VFGEN_RSTAT1(vf_id), VIRTCHNL_VFR_INPROGRESS);
135 : :
136 : : /*
137 : : * If require a SW VF reset, a VFLR interrupt will be generated,
138 : : * this function will be called again. To avoid it,
139 : : * disable interrupt first.
140 : : */
141 [ # # ]: 0 : if (do_hw_reset) {
142 : 0 : vf->state = I40E_VF_INRESET;
143 : 0 : val = I40E_READ_REG(hw, I40E_VPGEN_VFRTRIG(vf_id));
144 : 0 : val |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
145 : 0 : I40E_WRITE_REG(hw, I40E_VPGEN_VFRTRIG(vf_id), val);
146 : 0 : I40E_WRITE_FLUSH(hw);
147 : : }
148 : :
149 : : #define VFRESET_MAX_WAIT_CNT 100
150 : : /* Wait until VF reset is done */
151 [ # # ]: 0 : for (i = 0; i < VFRESET_MAX_WAIT_CNT; i++) {
152 : 0 : rte_delay_us(10);
153 : 0 : val = I40E_READ_REG(hw, I40E_VPGEN_VFRSTAT(vf_id));
154 [ # # ]: 0 : if (val & I40E_VPGEN_VFRSTAT_VFRD_MASK)
155 : : break;
156 : : }
157 : :
158 [ # # ]: 0 : if (i >= VFRESET_MAX_WAIT_CNT) {
159 : 0 : PMD_DRV_LOG(ERR, "VF reset timeout");
160 : 0 : return -ETIMEDOUT;
161 : : }
162 : : /* This is not first time to do reset, do cleanup job first */
163 [ # # ]: 0 : if (vf->vsi) {
164 : : /* Disable queues */
165 : : memset(&qsel, 0, sizeof(qsel));
166 [ # # ]: 0 : for (i = 0; i < vf->vsi->nb_qps; i++)
167 : 0 : qsel.rx_queues |= 1 << i;
168 : 0 : qsel.tx_queues = qsel.rx_queues;
169 : 0 : ret = i40e_pf_host_switch_queues(vf, &qsel, false);
170 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
171 : 0 : PMD_DRV_LOG(ERR, "Disable VF queues failed");
172 : 0 : return -EFAULT;
173 : : }
174 : :
175 : : /* Disable VF interrupt setting */
176 : 0 : vf_msix_num = hw->func_caps.num_msix_vectors_vf;
177 [ # # ]: 0 : for (i = 0; i < vf_msix_num; i++) {
178 [ # # ]: 0 : if (!i)
179 : 0 : val = I40E_VFINT_DYN_CTL0(vf_id);
180 : : else
181 : 0 : val = I40E_VFINT_DYN_CTLN(((vf_msix_num - 1) *
182 : : (vf_id)) + (i - 1));
183 : 0 : I40E_WRITE_REG(hw, val, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
184 : : }
185 : 0 : I40E_WRITE_FLUSH(hw);
186 : :
187 : : /* remove VSI */
188 : 0 : ret = i40e_vsi_release(vf->vsi);
189 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
190 : 0 : PMD_DRV_LOG(ERR, "Release VSI failed");
191 : 0 : return -EFAULT;
192 : : }
193 : : }
194 : :
195 : : #define I40E_VF_PCI_ADDR 0xAA
196 : : #define I40E_VF_PEND_MASK 0x20
197 : : /* Check the pending transactions of this VF */
198 : : /* Use absolute VF id, refer to datasheet for details */
199 : 0 : I40E_WRITE_REG(hw, I40E_PF_PCI_CIAA, I40E_VF_PCI_ADDR |
200 : : (abs_vf_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
201 [ # # ]: 0 : for (i = 0; i < VFRESET_MAX_WAIT_CNT; i++) {
202 : 0 : rte_delay_us(1);
203 : 0 : val = I40E_READ_REG(hw, I40E_PF_PCI_CIAD);
204 [ # # ]: 0 : if ((val & I40E_VF_PEND_MASK) == 0)
205 : : break;
206 : : }
207 : :
208 [ # # ]: 0 : if (i >= VFRESET_MAX_WAIT_CNT) {
209 : 0 : PMD_DRV_LOG(ERR, "Wait VF PCI transaction end timeout");
210 : 0 : return -ETIMEDOUT;
211 : : }
212 : :
213 : : /* Reset done, Set COMPLETE flag and clear reset bit */
214 : 0 : I40E_WRITE_REG(hw, I40E_VFGEN_RSTAT1(vf_id), VIRTCHNL_VFR_COMPLETED);
215 : 0 : val = I40E_READ_REG(hw, I40E_VPGEN_VFRTRIG(vf_id));
216 : 0 : val &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
217 : 0 : I40E_WRITE_REG(hw, I40E_VPGEN_VFRTRIG(vf_id), val);
218 : 0 : vf->reset_cnt++;
219 : 0 : I40E_WRITE_FLUSH(hw);
220 : :
221 : : /* Allocate resource again */
222 [ # # # # ]: 0 : if (pf->floating_veb && pf->floating_veb_list[vf_id]) {
223 : 0 : vf->vsi = i40e_vsi_setup(vf->pf, I40E_VSI_SRIOV,
224 : 0 : NULL, vf->vf_idx);
225 : : } else {
226 : 0 : vf->vsi = i40e_vsi_setup(vf->pf, I40E_VSI_SRIOV,
227 : 0 : vf->pf->main_vsi, vf->vf_idx);
228 : : }
229 : :
230 [ # # ]: 0 : if (vf->vsi == NULL) {
231 : 0 : PMD_DRV_LOG(ERR, "Add vsi failed");
232 : 0 : return -EFAULT;
233 : : }
234 : :
235 : 0 : ret = i40e_pf_vf_queues_mapping(vf);
236 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
237 : 0 : PMD_DRV_LOG(ERR, "queue mapping error");
238 : 0 : i40e_vsi_release(vf->vsi);
239 : 0 : return -EFAULT;
240 : : }
241 : :
242 : 0 : I40E_WRITE_REG(hw, I40E_VFGEN_RSTAT1(vf_id), VIRTCHNL_VFR_VFACTIVE);
243 : :
244 : 0 : return ret;
245 : : }
246 : :
247 : : int
248 : 0 : i40e_pf_host_send_msg_to_vf(struct i40e_pf_vf *vf,
249 : : uint32_t opcode,
250 : : uint32_t retval,
251 : : uint8_t *msg,
252 : : uint16_t msglen)
253 : : {
254 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
255 : 0 : uint16_t abs_vf_id = hw->func_caps.vf_base_id + vf->vf_idx;
256 : : int ret;
257 : :
258 : 0 : ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, opcode, retval,
259 : : msg, msglen, NULL);
260 [ # # ]: 0 : if (ret) {
261 : 0 : PMD_INIT_LOG(ERR, "Fail to send message to VF, err %u",
262 : : hw->aq.asq_last_status);
263 : : }
264 : :
265 : 0 : return ret;
266 : : }
267 : :
268 : : static void
269 : 0 : i40e_pf_host_process_cmd_version(struct i40e_pf_vf *vf, uint8_t *msg,
270 : : bool b_op)
271 : : {
272 : : struct virtchnl_version_info info;
273 : :
274 : : /* VF and PF drivers need to follow the Virtchnl definition, No matter
275 : : * it's DPDK or other kernel drivers.
276 : : * The original DPDK host specific feature
277 : : * like CFG_VLAN_PVID and CONFIG_VSI_QUEUES_EXT will not available.
278 : : */
279 : :
280 : 0 : info.major = VIRTCHNL_VERSION_MAJOR;
281 : 0 : vf->version = *(struct virtchnl_version_info *)msg;
282 [ # # ]: 0 : if (VF_IS_V10(&vf->version))
283 : 0 : info.minor = VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
284 : : else
285 : 0 : info.minor = VIRTCHNL_VERSION_MINOR;
286 : :
287 [ # # ]: 0 : if (b_op)
288 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_VERSION,
289 : : I40E_SUCCESS,
290 : : (uint8_t *)&info,
291 : : sizeof(info));
292 : : else
293 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_VERSION,
294 : : I40E_NOT_SUPPORTED,
295 : : (uint8_t *)&info,
296 : : sizeof(info));
297 : 0 : }
298 : :
299 : : static int
300 : : i40e_pf_host_process_cmd_reset_vf(struct i40e_pf_vf *vf)
301 : : {
302 : 0 : i40e_pf_host_vf_reset(vf, 1);
303 : :
304 : : /* No feedback will be sent to VF for VFLR */
305 : 0 : return I40E_SUCCESS;
306 : : }
307 : :
308 : : static int
309 : 0 : i40e_pf_host_process_cmd_get_vf_resource(struct i40e_pf_vf *vf, uint8_t *msg,
310 : : bool b_op)
311 : : {
312 : : /* only have 1 VSI by default */
313 : : struct {
314 : : struct virtchnl_vf_resource vf_res;
315 : : struct virtchnl_vsi_resource vsi_res;
316 : 0 : } res = {0};
317 : : struct virtchnl_vf_resource *vf_res = &res.vf_res;
318 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
319 : : uint32_t len = sizeof(res);
320 : : uint64_t default_hena = I40E_RSS_HENA_ALL;
321 : : int ret = I40E_SUCCESS;
322 : :
323 [ # # ]: 0 : if (!b_op) {
324 : 0 : i40e_pf_host_send_msg_to_vf(vf,
325 : : VIRTCHNL_OP_GET_VF_RESOURCES,
326 : : I40E_NOT_SUPPORTED, NULL, 0);
327 : 0 : return ret;
328 : : }
329 : :
330 [ # # ]: 0 : if (VF_IS_V10(&vf->version)) /* doesn't support offload negotiate */
331 : 0 : vf->request_caps = VIRTCHNL_VF_OFFLOAD_L2 |
332 : : VIRTCHNL_VF_OFFLOAD_VLAN;
333 : : else
334 : 0 : vf->request_caps = *(uint32_t *)msg;
335 : :
336 : : /* enable all RSS by default,
337 : : * doesn't support hena setting by virtchnl yet.
338 : : */
339 [ # # ]: 0 : if (vf->request_caps & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
340 : 0 : I40E_WRITE_REG(hw, I40E_VFQF_HENA1(0, vf->vf_idx),
341 : : (uint32_t)default_hena);
342 : 0 : I40E_WRITE_REG(hw, I40E_VFQF_HENA1(1, vf->vf_idx),
343 : : (uint32_t)(default_hena >> 32));
344 : 0 : I40E_WRITE_FLUSH(hw);
345 : : }
346 : :
347 : 0 : vf_res->vf_cap_flags = vf->request_caps &
348 : : I40E_VIRTCHNL_OFFLOAD_CAPS;
349 : :
350 [ # # ]: 0 : if (vf->request_caps & VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)
351 : 0 : vf_res->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_REQ_QUEUES;
352 : :
353 : : /* For X722, it supports write back on ITR
354 : : * without binding queue to interrupt vector.
355 : : */
356 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
357 : 0 : vf_res->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
358 : 0 : vf_res->max_vectors = hw->func_caps.num_msix_vectors_vf;
359 : 0 : vf_res->num_queue_pairs = vf->vsi->nb_qps;
360 : 0 : vf_res->num_vsis = I40E_DEFAULT_VF_VSI_NUM;
361 : 0 : vf_res->rss_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) * 4;
362 : 0 : vf_res->rss_lut_size = (I40E_VFQF_HLUT1_MAX_INDEX + 1) * 4;
363 : :
364 : : /* Change below setting if PF host can support more VSIs for VF */
365 : 0 : vf_res->vsi_res[0].vsi_type = VIRTCHNL_VSI_SRIOV;
366 : 0 : vf_res->vsi_res[0].vsi_id = vf->vsi->vsi_id;
367 : 0 : vf_res->vsi_res[0].num_queue_pairs = vf->vsi->nb_qps;
368 : : rte_ether_addr_copy(&vf->mac_addr,
369 : : (struct rte_ether_addr *)vf_res->vsi_res[0].default_mac_addr);
370 : :
371 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_GET_VF_RESOURCES,
372 : : ret, (uint8_t *)vf_res, len);
373 : 0 : return ret;
374 : : }
375 : :
376 : : static int
377 : 0 : i40e_pf_host_hmc_config_rxq(struct i40e_hw *hw,
378 : : struct i40e_pf_vf *vf,
379 : : struct virtchnl_rxq_info *rxq,
380 : : uint8_t crcstrip)
381 : : {
382 : : int err = I40E_SUCCESS;
383 : : struct i40e_hmc_obj_rxq rx_ctx;
384 [ # # ]: 0 : uint16_t abs_queue_id = vf->vsi->base_queue + rxq->queue_id;
385 : :
386 : : /* Clear the context structure first */
387 : : memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
388 : 0 : rx_ctx.dbuff = rxq->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
389 : 0 : rx_ctx.hbuff = rxq->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
390 : 0 : rx_ctx.base = rxq->dma_ring_addr / I40E_QUEUE_BASE_ADDR_UNIT;
391 : 0 : rx_ctx.qlen = rxq->ring_len;
392 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
393 : 0 : rx_ctx.dsize = 1;
394 : : #endif
395 : :
396 [ # # ]: 0 : if (rxq->splithdr_enabled) {
397 : 0 : rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_ALL;
398 : 0 : rx_ctx.dtype = i40e_header_split_enabled;
399 : : } else {
400 : : rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
401 : : rx_ctx.dtype = i40e_header_split_none;
402 : : }
403 : 0 : rx_ctx.rxmax = rxq->max_pkt_size;
404 : 0 : rx_ctx.tphrdesc_ena = 1;
405 : 0 : rx_ctx.tphwdesc_ena = 1;
406 : 0 : rx_ctx.tphdata_ena = 1;
407 : 0 : rx_ctx.tphhead_ena = 1;
408 : 0 : rx_ctx.lrxqthresh = 2;
409 : 0 : rx_ctx.crcstrip = crcstrip;
410 : 0 : rx_ctx.l2tsel = 1;
411 : 0 : rx_ctx.prefena = 1;
412 : :
413 : 0 : err = i40e_clear_lan_rx_queue_context(hw, abs_queue_id);
414 [ # # ]: 0 : if (err != I40E_SUCCESS)
415 : : return err;
416 : 0 : err = i40e_set_lan_rx_queue_context(hw, abs_queue_id, &rx_ctx);
417 : :
418 : 0 : return err;
419 : : }
420 : :
421 : : static inline uint8_t
422 : : i40e_vsi_get_tc_of_queue(struct i40e_vsi *vsi,
423 : : uint16_t queue_id)
424 : : {
425 : : struct i40e_aqc_vsi_properties_data *info = &vsi->info;
426 : : uint16_t bsf, qp_idx;
427 : : uint8_t i;
428 : :
429 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
430 [ # # ]: 0 : if (vsi->enabled_tc & (1 << i)) {
431 : 0 : qp_idx = rte_le_to_cpu_16((info->tc_mapping[i] &
432 : : I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
433 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT);
434 : 0 : bsf = rte_le_to_cpu_16((info->tc_mapping[i] &
435 : : I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
436 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
437 [ # # # # ]: 0 : if (queue_id >= qp_idx && queue_id < qp_idx + (1 << bsf))
438 : : return i;
439 : : }
440 : : }
441 : : return 0;
442 : : }
443 : :
444 : : static int
445 : 0 : i40e_pf_host_hmc_config_txq(struct i40e_hw *hw,
446 : : struct i40e_pf_vf *vf,
447 : : struct virtchnl_txq_info *txq)
448 : : {
449 : : int err = I40E_SUCCESS;
450 : : struct i40e_hmc_obj_txq tx_ctx;
451 : 0 : struct i40e_vsi *vsi = vf->vsi;
452 : : uint32_t qtx_ctl;
453 : 0 : uint16_t abs_queue_id = vsi->base_queue + txq->queue_id;
454 : : uint8_t dcb_tc;
455 : :
456 : : /* clear the context structure first */
457 : : memset(&tx_ctx, 0, sizeof(tx_ctx));
458 : 0 : tx_ctx.base = txq->dma_ring_addr / I40E_QUEUE_BASE_ADDR_UNIT;
459 : 0 : tx_ctx.qlen = txq->ring_len;
460 : 0 : dcb_tc = i40e_vsi_get_tc_of_queue(vsi, txq->queue_id);
461 : 0 : tx_ctx.rdylist = rte_le_to_cpu_16(vsi->info.qs_handle[dcb_tc]);
462 : 0 : tx_ctx.head_wb_ena = txq->headwb_enabled;
463 : 0 : tx_ctx.head_wb_addr = txq->dma_headwb_addr;
464 : :
465 : 0 : err = i40e_clear_lan_tx_queue_context(hw, abs_queue_id);
466 [ # # ]: 0 : if (err != I40E_SUCCESS)
467 : : return err;
468 : :
469 : 0 : err = i40e_set_lan_tx_queue_context(hw, abs_queue_id, &tx_ctx);
470 [ # # ]: 0 : if (err != I40E_SUCCESS)
471 : : return err;
472 : :
473 : : /* bind queue with VF function, since TX/QX will appear in pair,
474 : : * so only has QTX_CTL to set.
475 : : */
476 : 0 : qtx_ctl = (I40E_QTX_CTL_VF_QUEUE << I40E_QTX_CTL_PFVF_Q_SHIFT) |
477 : 0 : ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
478 : : I40E_QTX_CTL_PF_INDX_MASK) |
479 : 0 : (((vf->vf_idx + hw->func_caps.vf_base_id) <<
480 : 0 : I40E_QTX_CTL_VFVM_INDX_SHIFT) &
481 : : I40E_QTX_CTL_VFVM_INDX_MASK);
482 : 0 : I40E_WRITE_REG(hw, I40E_QTX_CTL(abs_queue_id), qtx_ctl);
483 : 0 : I40E_WRITE_FLUSH(hw);
484 : :
485 : 0 : return I40E_SUCCESS;
486 : : }
487 : :
488 : : static int
489 : 0 : i40e_pf_host_process_cmd_config_vsi_queues(struct i40e_pf_vf *vf,
490 : : uint8_t *msg,
491 : : uint16_t msglen,
492 : : bool b_op)
493 : : {
494 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
495 : 0 : struct i40e_vsi *vsi = vf->vsi;
496 : : struct virtchnl_vsi_queue_config_info *vc_vqci =
497 : : (struct virtchnl_vsi_queue_config_info *)msg;
498 : : struct virtchnl_queue_pair_info *vc_qpi;
499 : : int i, ret = I40E_SUCCESS;
500 : :
501 [ # # ]: 0 : if (!b_op) {
502 : 0 : i40e_pf_host_send_msg_to_vf(vf,
503 : : VIRTCHNL_OP_CONFIG_VSI_QUEUES,
504 : : I40E_NOT_SUPPORTED, NULL, 0);
505 : 0 : return ret;
506 : : }
507 : :
508 [ # # # # : 0 : if (!msg || vc_vqci->num_queue_pairs > vsi->nb_qps ||
# # ]
509 : 0 : vc_vqci->num_queue_pairs > I40E_MAX_VSI_QP ||
510 [ # # ]: 0 : msglen < I40E_VIRTCHNL_CONFIG_VSI_QUEUES_SIZE(vc_vqci,
511 : : vc_vqci->num_queue_pairs)) {
512 : 0 : PMD_DRV_LOG(ERR, "vsi_queue_config_info argument wrong");
513 : : ret = I40E_ERR_PARAM;
514 : 0 : goto send_msg;
515 : : }
516 : :
517 : 0 : vc_qpi = vc_vqci->qpair;
518 [ # # ]: 0 : for (i = 0; i < vc_vqci->num_queue_pairs; i++) {
519 [ # # ]: 0 : if (vc_qpi[i].rxq.queue_id > vsi->nb_qps - 1 ||
520 [ # # ]: 0 : vc_qpi[i].txq.queue_id > vsi->nb_qps - 1) {
521 : : ret = I40E_ERR_PARAM;
522 : 0 : goto send_msg;
523 : : }
524 : :
525 : : /*
526 : : * Apply VF RX queue setting to HMC.
527 : : * If the opcode is VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT,
528 : : * then the extra information of
529 : : * 'struct virtchnl_queue_pair_extra_info' is needed,
530 : : * otherwise set the last parameter to NULL.
531 : : */
532 [ # # ]: 0 : if (i40e_pf_host_hmc_config_rxq(hw, vf, &vc_qpi[i].rxq,
533 : : I40E_CFG_CRCSTRIP_DEFAULT) != I40E_SUCCESS) {
534 : 0 : PMD_DRV_LOG(ERR, "Configure RX queue HMC failed");
535 : : ret = I40E_ERR_PARAM;
536 : 0 : goto send_msg;
537 : : }
538 : :
539 : : /* Apply VF TX queue setting to HMC */
540 [ # # ]: 0 : if (i40e_pf_host_hmc_config_txq(hw, vf,
541 : : &vc_qpi[i].txq) != I40E_SUCCESS) {
542 : 0 : PMD_DRV_LOG(ERR, "Configure TX queue HMC failed");
543 : : ret = I40E_ERR_PARAM;
544 : 0 : goto send_msg;
545 : : }
546 : : }
547 : :
548 : 0 : send_msg:
549 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
550 : : ret, NULL, 0);
551 : :
552 : 0 : return ret;
553 : : }
554 : :
555 : : static void
556 : 0 : i40e_pf_config_irq_link_list(struct i40e_pf_vf *vf,
557 : : struct virtchnl_vector_map *vvm)
558 : : {
559 : : #define BITS_PER_CHAR 8
560 : : uint64_t linklistmap = 0, tempmap;
561 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
562 : : uint16_t qid;
563 : : bool b_first_q = true;
564 : : enum i40e_queue_type qtype;
565 : : uint16_t vector_id;
566 : : uint32_t reg, reg_idx;
567 : : uint16_t itr_idx = 0, i;
568 : :
569 : 0 : vector_id = vvm->vector_id;
570 : : /* setup the head */
571 [ # # ]: 0 : if (!vector_id)
572 : 0 : reg_idx = I40E_VPINT_LNKLST0(vf->vf_idx);
573 : : else
574 : 0 : reg_idx = I40E_VPINT_LNKLSTN(
575 : : ((hw->func_caps.num_msix_vectors_vf - 1) * vf->vf_idx)
576 : : + (vector_id - 1));
577 : :
578 [ # # # # ]: 0 : if (vvm->rxq_map == 0 && vvm->txq_map == 0) {
579 : 0 : I40E_WRITE_REG(hw, reg_idx,
580 : : I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK);
581 : 0 : goto cfg_irq_done;
582 : : }
583 : :
584 : : /* sort all rx and tx queues */
585 : 0 : tempmap = vvm->rxq_map;
586 [ # # ]: 0 : for (i = 0; i < sizeof(vvm->rxq_map) * BITS_PER_CHAR; i++) {
587 [ # # ]: 0 : if (tempmap & 0x1)
588 : 0 : linklistmap |= RTE_BIT64(2 * i);
589 : 0 : tempmap >>= 1;
590 : : }
591 : :
592 : 0 : tempmap = vvm->txq_map;
593 [ # # ]: 0 : for (i = 0; i < sizeof(vvm->txq_map) * BITS_PER_CHAR; i++) {
594 [ # # ]: 0 : if (tempmap & 0x1)
595 : 0 : linklistmap |= RTE_BIT64(2 * i + 1);
596 : 0 : tempmap >>= 1;
597 : : }
598 : :
599 : : /* Link all rx and tx queues into a chained list */
600 : : tempmap = linklistmap;
601 : : i = 0;
602 : : b_first_q = true;
603 : : do {
604 [ # # ]: 0 : if (tempmap & 0x1) {
605 : 0 : qtype = (enum i40e_queue_type)(i % 2);
606 : 0 : qid = vf->vsi->base_queue + i / 2;
607 [ # # ]: 0 : if (b_first_q) {
608 : : /* This is header */
609 : : b_first_q = false;
610 : 0 : reg = ((qtype <<
611 : : I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT)
612 : 0 : | qid);
613 : : } else {
614 : : /* element in the link list */
615 : 0 : reg = (vector_id) |
616 : 0 : (qtype << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
617 : 0 : (qid << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
618 : 0 : BIT(I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) |
619 : 0 : (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT);
620 : : }
621 : 0 : I40E_WRITE_REG(hw, reg_idx, reg);
622 : : /* find next register to program */
623 [ # # ]: 0 : switch (qtype) {
624 : 0 : case I40E_QUEUE_TYPE_RX:
625 : 0 : reg_idx = I40E_QINT_RQCTL(qid);
626 : 0 : itr_idx = vvm->rxitr_idx;
627 : 0 : break;
628 : 0 : case I40E_QUEUE_TYPE_TX:
629 : 0 : reg_idx = I40E_QINT_TQCTL(qid);
630 : 0 : itr_idx = vvm->txitr_idx;
631 : 0 : break;
632 : : default:
633 : : break;
634 : : }
635 : : }
636 : 0 : i++;
637 : 0 : tempmap >>= 1;
638 [ # # ]: 0 : } while (tempmap);
639 : :
640 : : /* Terminate the link list */
641 : 0 : reg = (vector_id) |
642 : : (0 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
643 : : (0x7FF << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
644 : : BIT(I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) |
645 : 0 : (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT);
646 : 0 : I40E_WRITE_REG(hw, reg_idx, reg);
647 : :
648 : 0 : cfg_irq_done:
649 : 0 : I40E_WRITE_FLUSH(hw);
650 : 0 : }
651 : :
652 : : static int
653 : 0 : i40e_pf_host_process_cmd_config_irq_map(struct i40e_pf_vf *vf,
654 : : uint8_t *msg, uint16_t msglen,
655 : : bool b_op)
656 : : {
657 : : int ret = I40E_SUCCESS;
658 : 0 : struct i40e_pf *pf = vf->pf;
659 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
660 : : struct virtchnl_irq_map_info *irqmap =
661 : : (struct virtchnl_irq_map_info *)msg;
662 : : struct virtchnl_vector_map *map;
663 : : int i;
664 : : uint16_t vector_id, itr_idx;
665 : : unsigned long qbit_max;
666 : :
667 [ # # ]: 0 : if (!b_op) {
668 : 0 : i40e_pf_host_send_msg_to_vf(
669 : : vf,
670 : : VIRTCHNL_OP_CONFIG_IRQ_MAP,
671 : : I40E_NOT_SUPPORTED, NULL, 0);
672 : 0 : return ret;
673 : : }
674 : :
675 [ # # ]: 0 : if (msg == NULL || msglen < sizeof(struct virtchnl_irq_map_info)) {
676 : 0 : PMD_DRV_LOG(ERR, "buffer too short");
677 : : ret = I40E_ERR_PARAM;
678 : 0 : goto send_msg;
679 : : }
680 : :
681 : : /* PF host will support both DPDK VF or Linux VF driver, identify by
682 : : * number of vectors requested.
683 : : */
684 : :
685 : : /* DPDK VF only requires single vector */
686 [ # # ]: 0 : if (irqmap->num_vectors == 1) {
687 : : /* This MSIX intr store the intr in VF range */
688 : 0 : vf->vsi->msix_intr = irqmap->vecmap[0].vector_id;
689 : 0 : vf->vsi->nb_msix = irqmap->num_vectors;
690 : 0 : vf->vsi->nb_used_qps = vf->vsi->nb_qps;
691 : 0 : itr_idx = irqmap->vecmap[0].rxitr_idx;
692 : :
693 : : /* Don't care how the TX/RX queue mapping with this vector.
694 : : * Link all VF RX queues together. Only did mapping work.
695 : : * VF can disable/enable the intr by itself.
696 : : */
697 : 0 : i40e_vsi_queues_bind_intr(vf->vsi, itr_idx);
698 : 0 : goto send_msg;
699 : : }
700 : :
701 : : /* Then, it's Linux VF driver */
702 : 0 : qbit_max = 1 << pf->vf_nb_qp_max;
703 [ # # ]: 0 : for (i = 0; i < irqmap->num_vectors; i++) {
704 : 0 : map = &irqmap->vecmap[i];
705 : :
706 : 0 : vector_id = map->vector_id;
707 : : /* validate msg params */
708 [ # # ]: 0 : if (vector_id >= hw->func_caps.num_msix_vectors_vf) {
709 : : ret = I40E_ERR_PARAM;
710 : 0 : goto send_msg;
711 : : }
712 : :
713 [ # # # # ]: 0 : if ((map->rxq_map < qbit_max) && (map->txq_map < qbit_max)) {
714 : 0 : i40e_pf_config_irq_link_list(vf, map);
715 : : } else {
716 : : /* configured queue size exceed limit */
717 : : ret = I40E_ERR_PARAM;
718 : 0 : goto send_msg;
719 : : }
720 : : }
721 : :
722 : 0 : send_msg:
723 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_IRQ_MAP,
724 : : ret, NULL, 0);
725 : :
726 : 0 : return ret;
727 : : }
728 : :
729 : : static int
730 : 0 : i40e_pf_host_switch_queues(struct i40e_pf_vf *vf,
731 : : struct virtchnl_queue_select *qsel,
732 : : bool on)
733 : : {
734 : : int ret = I40E_SUCCESS;
735 : : int i;
736 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
737 : 0 : uint16_t baseq = vf->vsi->base_queue;
738 : :
739 [ # # ]: 0 : if (qsel->rx_queues + qsel->tx_queues == 0)
740 : : return I40E_ERR_PARAM;
741 : :
742 : : /* always enable RX first and disable last */
743 : : /* Enable RX if it's enable */
744 [ # # ]: 0 : if (on) {
745 [ # # ]: 0 : for (i = 0; i < I40E_MAX_QP_NUM_PER_VF; i++)
746 [ # # ]: 0 : if (qsel->rx_queues & (1 << i)) {
747 : 0 : ret = i40e_switch_rx_queue(hw, baseq + i, on);
748 [ # # ]: 0 : if (ret != I40E_SUCCESS)
749 : 0 : return ret;
750 : : }
751 : : }
752 : :
753 : : /* Enable/Disable TX */
754 [ # # ]: 0 : for (i = 0; i < I40E_MAX_QP_NUM_PER_VF; i++)
755 [ # # ]: 0 : if (qsel->tx_queues & (1 << i)) {
756 : 0 : ret = i40e_switch_tx_queue(hw, baseq + i, on);
757 [ # # ]: 0 : if (ret != I40E_SUCCESS)
758 : 0 : return ret;
759 : : }
760 : :
761 : : /* disable RX last if it's disable */
762 [ # # ]: 0 : if (!on) {
763 : : /* disable RX */
764 [ # # ]: 0 : for (i = 0; i < I40E_MAX_QP_NUM_PER_VF; i++)
765 [ # # ]: 0 : if (qsel->rx_queues & (1 << i)) {
766 : 0 : ret = i40e_switch_rx_queue(hw, baseq + i, on);
767 [ # # ]: 0 : if (ret != I40E_SUCCESS)
768 : 0 : return ret;
769 : : }
770 : : }
771 : :
772 : : return ret;
773 : : }
774 : :
775 : : static int
776 : 0 : i40e_pf_host_process_cmd_enable_queues(struct i40e_pf_vf *vf,
777 : : uint8_t *msg,
778 : : uint16_t msglen)
779 : : {
780 : : int ret = I40E_SUCCESS;
781 : : struct virtchnl_queue_select *q_sel =
782 : : (struct virtchnl_queue_select *)msg;
783 : :
784 [ # # ]: 0 : if (msg == NULL || msglen != sizeof(*q_sel)) {
785 : : ret = I40E_ERR_PARAM;
786 : 0 : goto send_msg;
787 : : }
788 : 0 : ret = i40e_pf_host_switch_queues(vf, q_sel, true);
789 : :
790 : 0 : send_msg:
791 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_QUEUES,
792 : : ret, NULL, 0);
793 : :
794 : 0 : return ret;
795 : : }
796 : :
797 : : static int
798 : 0 : i40e_pf_host_process_cmd_disable_queues(struct i40e_pf_vf *vf,
799 : : uint8_t *msg,
800 : : uint16_t msglen,
801 : : bool b_op)
802 : : {
803 : : int ret = I40E_SUCCESS;
804 : : struct virtchnl_queue_select *q_sel =
805 : : (struct virtchnl_queue_select *)msg;
806 : :
807 [ # # ]: 0 : if (!b_op) {
808 : 0 : i40e_pf_host_send_msg_to_vf(
809 : : vf,
810 : : VIRTCHNL_OP_DISABLE_QUEUES,
811 : : I40E_NOT_SUPPORTED, NULL, 0);
812 : 0 : return ret;
813 : : }
814 : :
815 [ # # ]: 0 : if (msg == NULL || msglen != sizeof(*q_sel)) {
816 : : ret = I40E_ERR_PARAM;
817 : 0 : goto send_msg;
818 : : }
819 : 0 : ret = i40e_pf_host_switch_queues(vf, q_sel, false);
820 : :
821 : 0 : send_msg:
822 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_QUEUES,
823 : : ret, NULL, 0);
824 : :
825 : 0 : return ret;
826 : : }
827 : :
828 : :
829 : : static int
830 : 0 : i40e_pf_host_process_cmd_add_ether_address(struct i40e_pf_vf *vf,
831 : : uint8_t *msg,
832 : : uint16_t msglen,
833 : : bool b_op)
834 : : {
835 : : int ret = I40E_SUCCESS;
836 : : struct virtchnl_ether_addr_list *addr_list =
837 : : (struct virtchnl_ether_addr_list *)msg;
838 : : struct i40e_mac_filter_info filter;
839 : : int i;
840 : : struct rte_ether_addr *mac;
841 : :
842 [ # # ]: 0 : if (!b_op) {
843 : 0 : i40e_pf_host_send_msg_to_vf(
844 : : vf,
845 : : VIRTCHNL_OP_ADD_ETH_ADDR,
846 : : I40E_NOT_SUPPORTED, NULL, 0);
847 : 0 : return ret;
848 : : }
849 : :
850 : : memset(&filter, 0 , sizeof(struct i40e_mac_filter_info));
851 : :
852 [ # # ]: 0 : if (msg == NULL || msglen <= sizeof(*addr_list)) {
853 : 0 : PMD_DRV_LOG(ERR, "add_ether_address argument too short");
854 : : ret = I40E_ERR_PARAM;
855 : 0 : goto send_msg;
856 : : }
857 : :
858 [ # # ]: 0 : for (i = 0; i < addr_list->num_elements; i++) {
859 [ # # ]: 0 : mac = (struct rte_ether_addr *)(addr_list->list[i].addr);
860 : : rte_memcpy(&filter.mac_addr, mac, RTE_ETHER_ADDR_LEN);
861 [ # # ]: 0 : filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
862 [ # # # # ]: 0 : if (rte_is_zero_ether_addr(mac) ||
863 : 0 : i40e_vsi_add_mac(vf->vsi, &filter)) {
864 : : ret = I40E_ERR_INVALID_MAC_ADDR;
865 : 0 : goto send_msg;
866 : : }
867 : : }
868 : :
869 : 0 : send_msg:
870 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR,
871 : : ret, NULL, 0);
872 : :
873 : 0 : return ret;
874 : : }
875 : :
876 : : static int
877 : 0 : i40e_pf_host_process_cmd_del_ether_address(struct i40e_pf_vf *vf,
878 : : uint8_t *msg,
879 : : uint16_t msglen,
880 : : bool b_op)
881 : : {
882 : : int ret = I40E_SUCCESS;
883 : : struct virtchnl_ether_addr_list *addr_list =
884 : : (struct virtchnl_ether_addr_list *)msg;
885 : : int i;
886 : : struct rte_ether_addr *mac;
887 : :
888 [ # # ]: 0 : if (!b_op) {
889 : 0 : i40e_pf_host_send_msg_to_vf(
890 : : vf,
891 : : VIRTCHNL_OP_DEL_ETH_ADDR,
892 : : I40E_NOT_SUPPORTED, NULL, 0);
893 : 0 : return ret;
894 : : }
895 : :
896 [ # # ]: 0 : if (msg == NULL || msglen <= sizeof(*addr_list)) {
897 : 0 : PMD_DRV_LOG(ERR, "delete_ether_address argument too short");
898 : : ret = I40E_ERR_PARAM;
899 : 0 : goto send_msg;
900 : : }
901 : :
902 [ # # ]: 0 : for (i = 0; i < addr_list->num_elements; i++) {
903 [ # # ]: 0 : mac = (struct rte_ether_addr *)(addr_list->list[i].addr);
904 [ # # # # ]: 0 : if (rte_is_zero_ether_addr(mac) ||
905 : 0 : i40e_vsi_delete_mac(vf->vsi, mac)) {
906 : : ret = I40E_ERR_INVALID_MAC_ADDR;
907 : 0 : goto send_msg;
908 : : }
909 : : }
910 : :
911 : 0 : send_msg:
912 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR,
913 : : ret, NULL, 0);
914 : :
915 : 0 : return ret;
916 : : }
917 : :
918 : : static int
919 : 0 : i40e_pf_host_process_cmd_add_vlan(struct i40e_pf_vf *vf,
920 : : uint8_t *msg, uint16_t msglen,
921 : : bool b_op)
922 : : {
923 : : int ret = I40E_SUCCESS;
924 : : struct virtchnl_vlan_filter_list *vlan_filter_list =
925 : : (struct virtchnl_vlan_filter_list *)msg;
926 : : int i;
927 : : uint16_t *vid;
928 : :
929 [ # # ]: 0 : if (!b_op) {
930 : 0 : i40e_pf_host_send_msg_to_vf(
931 : : vf,
932 : : VIRTCHNL_OP_ADD_VLAN,
933 : : I40E_NOT_SUPPORTED, NULL, 0);
934 : 0 : return ret;
935 : : }
936 : :
937 [ # # ]: 0 : if (msg == NULL || msglen <= sizeof(*vlan_filter_list)) {
938 : 0 : PMD_DRV_LOG(ERR, "add_vlan argument too short");
939 : : ret = I40E_ERR_PARAM;
940 : 0 : goto send_msg;
941 : : }
942 : :
943 : 0 : vid = vlan_filter_list->vlan_id;
944 : :
945 [ # # ]: 0 : for (i = 0; i < vlan_filter_list->num_elements; i++) {
946 : 0 : ret = i40e_vsi_add_vlan(vf->vsi, vid[i]);
947 [ # # ]: 0 : if(ret != I40E_SUCCESS)
948 : 0 : goto send_msg;
949 : : }
950 : :
951 : 0 : send_msg:
952 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN,
953 : : ret, NULL, 0);
954 : :
955 : 0 : return ret;
956 : : }
957 : :
958 : : static int
959 : 0 : i40e_pf_host_process_cmd_del_vlan(struct i40e_pf_vf *vf,
960 : : uint8_t *msg,
961 : : uint16_t msglen,
962 : : bool b_op)
963 : : {
964 : : int ret = I40E_SUCCESS;
965 : : struct virtchnl_vlan_filter_list *vlan_filter_list =
966 : : (struct virtchnl_vlan_filter_list *)msg;
967 : : int i;
968 : : uint16_t *vid;
969 : :
970 [ # # ]: 0 : if (!b_op) {
971 : 0 : i40e_pf_host_send_msg_to_vf(
972 : : vf,
973 : : VIRTCHNL_OP_DEL_VLAN,
974 : : I40E_NOT_SUPPORTED, NULL, 0);
975 : 0 : return ret;
976 : : }
977 : :
978 [ # # ]: 0 : if (msg == NULL || msglen <= sizeof(*vlan_filter_list)) {
979 : 0 : PMD_DRV_LOG(ERR, "delete_vlan argument too short");
980 : : ret = I40E_ERR_PARAM;
981 : 0 : goto send_msg;
982 : : }
983 : :
984 : 0 : vid = vlan_filter_list->vlan_id;
985 [ # # ]: 0 : for (i = 0; i < vlan_filter_list->num_elements; i++) {
986 : 0 : ret = i40e_vsi_delete_vlan(vf->vsi, vid[i]);
987 [ # # ]: 0 : if(ret != I40E_SUCCESS)
988 : 0 : goto send_msg;
989 : : }
990 : :
991 : 0 : send_msg:
992 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN,
993 : : ret, NULL, 0);
994 : :
995 : 0 : return ret;
996 : : }
997 : :
998 : : static int
999 : 0 : i40e_pf_host_process_cmd_config_promisc_mode(
1000 : : struct i40e_pf_vf *vf,
1001 : : uint8_t *msg,
1002 : : uint16_t msglen,
1003 : : bool b_op)
1004 : : {
1005 : : int ret = I40E_SUCCESS;
1006 : : struct virtchnl_promisc_info *promisc =
1007 : : (struct virtchnl_promisc_info *)msg;
1008 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
1009 : : bool unicast = FALSE, multicast = FALSE;
1010 : :
1011 [ # # ]: 0 : if (!b_op) {
1012 : 0 : i40e_pf_host_send_msg_to_vf(
1013 : : vf,
1014 : : VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1015 : : I40E_NOT_SUPPORTED, NULL, 0);
1016 : 0 : return ret;
1017 : : }
1018 : :
1019 [ # # ]: 0 : if (msg == NULL || msglen != sizeof(*promisc)) {
1020 : : ret = I40E_ERR_PARAM;
1021 : 0 : goto send_msg;
1022 : : }
1023 : :
1024 [ # # ]: 0 : if (promisc->flags & FLAG_VF_UNICAST_PROMISC)
1025 : : unicast = TRUE;
1026 : 0 : ret = i40e_aq_set_vsi_unicast_promiscuous(hw,
1027 : 0 : vf->vsi->seid, unicast, NULL, true);
1028 [ # # ]: 0 : if (ret != I40E_SUCCESS)
1029 : 0 : goto send_msg;
1030 : :
1031 [ # # ]: 0 : if (promisc->flags & FLAG_VF_MULTICAST_PROMISC)
1032 : : multicast = TRUE;
1033 : 0 : ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vf->vsi->seid,
1034 : : multicast, NULL);
1035 : :
1036 : 0 : send_msg:
1037 : 0 : i40e_pf_host_send_msg_to_vf(vf,
1038 : : VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, ret, NULL, 0);
1039 : :
1040 : 0 : return ret;
1041 : : }
1042 : :
1043 : : static int
1044 : 0 : i40e_pf_host_process_cmd_get_stats(struct i40e_pf_vf *vf, bool b_op)
1045 : : {
1046 : 0 : i40e_update_vsi_stats(vf->vsi);
1047 : :
1048 [ # # ]: 0 : if (b_op)
1049 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_GET_STATS,
1050 : : I40E_SUCCESS,
1051 : 0 : (uint8_t *)&vf->vsi->eth_stats,
1052 : : sizeof(vf->vsi->eth_stats));
1053 : : else
1054 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_GET_STATS,
1055 : : I40E_NOT_SUPPORTED,
1056 : 0 : (uint8_t *)&vf->vsi->eth_stats,
1057 : : sizeof(vf->vsi->eth_stats));
1058 : :
1059 : 0 : return I40E_SUCCESS;
1060 : : }
1061 : :
1062 : : static int
1063 : 0 : i40e_pf_host_process_cmd_enable_vlan_strip(struct i40e_pf_vf *vf, bool b_op)
1064 : : {
1065 : : int ret = I40E_SUCCESS;
1066 : :
1067 [ # # ]: 0 : if (!b_op) {
1068 : 0 : i40e_pf_host_send_msg_to_vf(
1069 : : vf,
1070 : : VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
1071 : : I40E_NOT_SUPPORTED, NULL, 0);
1072 : 0 : return ret;
1073 : : }
1074 : :
1075 : 0 : ret = i40e_vsi_config_vlan_stripping(vf->vsi, TRUE);
1076 [ # # ]: 0 : if (ret != 0)
1077 : 0 : PMD_DRV_LOG(ERR, "Failed to enable vlan stripping");
1078 : :
1079 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
1080 : : ret, NULL, 0);
1081 : :
1082 : 0 : return ret;
1083 : : }
1084 : :
1085 : : static int
1086 : 0 : i40e_pf_host_process_cmd_disable_vlan_strip(struct i40e_pf_vf *vf, bool b_op)
1087 : : {
1088 : : int ret = I40E_SUCCESS;
1089 : :
1090 [ # # ]: 0 : if (!b_op) {
1091 : 0 : i40e_pf_host_send_msg_to_vf(
1092 : : vf,
1093 : : VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
1094 : : I40E_NOT_SUPPORTED, NULL, 0);
1095 : 0 : return ret;
1096 : : }
1097 : :
1098 : 0 : ret = i40e_vsi_config_vlan_stripping(vf->vsi, FALSE);
1099 [ # # ]: 0 : if (ret != 0)
1100 : 0 : PMD_DRV_LOG(ERR, "Failed to disable vlan stripping");
1101 : :
1102 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
1103 : : ret, NULL, 0);
1104 : :
1105 : 0 : return ret;
1106 : : }
1107 : :
1108 : : static int
1109 : 0 : i40e_pf_host_process_cmd_set_rss_lut(struct i40e_pf_vf *vf,
1110 : : uint8_t *msg,
1111 : : uint16_t msglen,
1112 : : bool b_op)
1113 : : {
1114 : : struct virtchnl_rss_lut *rss_lut = (struct virtchnl_rss_lut *)msg;
1115 : : uint16_t valid_len;
1116 : : int ret = I40E_SUCCESS;
1117 : :
1118 [ # # ]: 0 : if (!b_op) {
1119 : 0 : i40e_pf_host_send_msg_to_vf(
1120 : : vf,
1121 : : VIRTCHNL_OP_CONFIG_RSS_LUT,
1122 : : I40E_NOT_SUPPORTED, NULL, 0);
1123 : 0 : return ret;
1124 : : }
1125 : :
1126 [ # # ]: 0 : if (!msg || msglen <= sizeof(struct virtchnl_rss_lut)) {
1127 : 0 : PMD_DRV_LOG(ERR, "set_rss_lut argument too short");
1128 : : ret = I40E_ERR_PARAM;
1129 : 0 : goto send_msg;
1130 : : }
1131 : 0 : valid_len = sizeof(struct virtchnl_rss_lut) + rss_lut->lut_entries - 1;
1132 [ # # ]: 0 : if (msglen < valid_len) {
1133 : 0 : PMD_DRV_LOG(ERR, "set_rss_lut length mismatch");
1134 : : ret = I40E_ERR_PARAM;
1135 : 0 : goto send_msg;
1136 : : }
1137 : :
1138 : 0 : ret = i40e_set_rss_lut(vf->vsi, rss_lut->lut, rss_lut->lut_entries);
1139 : :
1140 : 0 : send_msg:
1141 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_LUT,
1142 : : ret, NULL, 0);
1143 : :
1144 : 0 : return ret;
1145 : : }
1146 : :
1147 : : static int
1148 : 0 : i40e_pf_host_process_cmd_set_rss_key(struct i40e_pf_vf *vf,
1149 : : uint8_t *msg,
1150 : : uint16_t msglen,
1151 : : bool b_op)
1152 : : {
1153 : : struct virtchnl_rss_key *rss_key = (struct virtchnl_rss_key *)msg;
1154 : : uint16_t valid_len;
1155 : : int ret = I40E_SUCCESS;
1156 : :
1157 [ # # ]: 0 : if (!b_op) {
1158 : 0 : i40e_pf_host_send_msg_to_vf(
1159 : : vf,
1160 : : VIRTCHNL_OP_DEL_VLAN,
1161 : : VIRTCHNL_OP_CONFIG_RSS_KEY, NULL, 0);
1162 : 0 : return ret;
1163 : : }
1164 : :
1165 [ # # ]: 0 : if (!msg || msglen <= sizeof(struct virtchnl_rss_key)) {
1166 : 0 : PMD_DRV_LOG(ERR, "set_rss_key argument too short");
1167 : : ret = I40E_ERR_PARAM;
1168 : 0 : goto send_msg;
1169 : : }
1170 : 0 : valid_len = sizeof(struct virtchnl_rss_key) + rss_key->key_len - 1;
1171 [ # # ]: 0 : if (msglen < valid_len) {
1172 : 0 : PMD_DRV_LOG(ERR, "set_rss_key length mismatch");
1173 : : ret = I40E_ERR_PARAM;
1174 : 0 : goto send_msg;
1175 : : }
1176 : :
1177 : 0 : ret = i40e_set_rss_key(vf->vsi, rss_key->key, rss_key->key_len);
1178 : :
1179 : 0 : send_msg:
1180 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_KEY,
1181 : : ret, NULL, 0);
1182 : :
1183 : 0 : return ret;
1184 : : }
1185 : :
1186 : : void
1187 : 0 : i40e_notify_vf_link_status(struct rte_eth_dev *dev, struct i40e_pf_vf *vf)
1188 : : {
1189 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
1190 : : struct virtchnl_pf_event event;
1191 : 0 : uint16_t vf_id = vf->vf_idx;
1192 : : uint32_t tval, rval;
1193 : :
1194 : 0 : event.event = VIRTCHNL_EVENT_LINK_CHANGE;
1195 : 0 : event.event_data.link_event.link_status =
1196 : 0 : dev->data->dev_link.link_status;
1197 : :
1198 : : /* need to convert the RTE_ETH_SPEED_xxx into VIRTCHNL_LINK_SPEED_xxx */
1199 [ # # # # : 0 : switch (dev->data->dev_link.link_speed) {
# # # ]
1200 : 0 : case RTE_ETH_SPEED_NUM_100M:
1201 : 0 : event.event_data.link_event.link_speed = VIRTCHNL_LINK_SPEED_100MB;
1202 : 0 : break;
1203 : 0 : case RTE_ETH_SPEED_NUM_1G:
1204 : 0 : event.event_data.link_event.link_speed = VIRTCHNL_LINK_SPEED_1GB;
1205 : 0 : break;
1206 : 0 : case RTE_ETH_SPEED_NUM_10G:
1207 : 0 : event.event_data.link_event.link_speed = VIRTCHNL_LINK_SPEED_10GB;
1208 : 0 : break;
1209 : 0 : case RTE_ETH_SPEED_NUM_20G:
1210 : 0 : event.event_data.link_event.link_speed = VIRTCHNL_LINK_SPEED_20GB;
1211 : 0 : break;
1212 : 0 : case RTE_ETH_SPEED_NUM_25G:
1213 : 0 : event.event_data.link_event.link_speed = VIRTCHNL_LINK_SPEED_25GB;
1214 : 0 : break;
1215 : 0 : case RTE_ETH_SPEED_NUM_40G:
1216 : 0 : event.event_data.link_event.link_speed = VIRTCHNL_LINK_SPEED_40GB;
1217 : 0 : break;
1218 : 0 : default:
1219 : 0 : event.event_data.link_event.link_speed =
1220 : : VIRTCHNL_LINK_SPEED_UNKNOWN;
1221 : 0 : break;
1222 : : }
1223 : :
1224 : 0 : tval = I40E_READ_REG(hw, I40E_VF_ATQLEN(vf_id));
1225 : 0 : rval = I40E_READ_REG(hw, I40E_VF_ARQLEN(vf_id));
1226 : :
1227 [ # # # # ]: 0 : if (tval & I40E_VF_ATQLEN_ATQLEN_MASK ||
1228 : 0 : tval & I40E_VF_ATQLEN_ATQENABLE_MASK ||
1229 [ # # # # ]: 0 : rval & I40E_VF_ARQLEN_ARQLEN_MASK ||
1230 : : rval & I40E_VF_ARQLEN_ARQENABLE_MASK)
1231 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_EVENT,
1232 : : I40E_SUCCESS, (uint8_t *)&event, sizeof(event));
1233 : 0 : }
1234 : :
1235 : : /**
1236 : : * i40e_vc_notify_vf_reset
1237 : : * @vf: pointer to the VF structure
1238 : : *
1239 : : * indicate a pending reset to the given VF
1240 : : **/
1241 : : static void
1242 : 0 : i40e_vc_notify_vf_reset(struct i40e_pf_vf *vf)
1243 : : {
1244 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
1245 : : struct virtchnl_pf_event pfe;
1246 : : int abs_vf_id;
1247 : 0 : uint16_t vf_id = vf->vf_idx;
1248 : :
1249 : 0 : abs_vf_id = vf_id + hw->func_caps.vf_base_id;
1250 : 0 : pfe.event = VIRTCHNL_EVENT_RESET_IMPENDING;
1251 : 0 : pfe.severity = PF_EVENT_SEVERITY_CERTAIN_DOOM;
1252 : 0 : i40e_aq_send_msg_to_vf(hw, abs_vf_id, VIRTCHNL_OP_EVENT, 0, (u8 *)&pfe,
1253 : : sizeof(struct virtchnl_pf_event), NULL);
1254 : 0 : }
1255 : :
1256 : : static int
1257 : 0 : i40e_pf_host_process_cmd_request_queues(struct i40e_pf_vf *vf, uint8_t *msg)
1258 : : {
1259 : : struct virtchnl_vf_res_request *vfres =
1260 : : (struct virtchnl_vf_res_request *)msg;
1261 : : struct i40e_pf *pf;
1262 : 0 : uint32_t req_pairs = vfres->num_queue_pairs;
1263 : 0 : uint32_t cur_pairs = vf->vsi->nb_used_qps;
1264 : :
1265 [ # # ]: 0 : pf = vf->pf;
1266 : :
1267 : : if (!rte_is_power_of_2(req_pairs))
1268 : 0 : req_pairs = i40e_align_floor(req_pairs) << 1;
1269 : :
1270 [ # # ]: 0 : if (req_pairs == 0) {
1271 : 0 : PMD_DRV_LOG(ERR, "VF %d tried to request 0 queues. Ignoring.",
1272 : : vf->vf_idx);
1273 [ # # ]: 0 : } else if (req_pairs > I40E_MAX_QP_NUM_PER_VF) {
1274 : 0 : PMD_DRV_LOG(ERR,
1275 : : "VF %d tried to request more than %d queues.",
1276 : : vf->vf_idx,
1277 : : I40E_MAX_QP_NUM_PER_VF);
1278 : 0 : vfres->num_queue_pairs = I40E_MAX_QP_NUM_PER_VF;
1279 [ # # ]: 0 : } else if (req_pairs > cur_pairs + pf->qp_pool.num_free) {
1280 : 0 : PMD_DRV_LOG(ERR, "VF %d requested %d queues (rounded to %d) "
1281 : : "but only %d available",
1282 : : vf->vf_idx,
1283 : : vfres->num_queue_pairs,
1284 : : req_pairs,
1285 : : cur_pairs + pf->qp_pool.num_free);
1286 [ # # ]: 0 : vfres->num_queue_pairs = i40e_align_floor(pf->qp_pool.num_free +
1287 : : cur_pairs);
1288 : : } else {
1289 : 0 : i40e_vc_notify_vf_reset(vf);
1290 : 0 : vf->vsi->nb_qps = req_pairs;
1291 : 0 : pf->vf_nb_qps = req_pairs;
1292 : : i40e_pf_host_process_cmd_reset_vf(vf);
1293 : :
1294 : 0 : return 0;
1295 : : }
1296 : :
1297 : 0 : return i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_REQUEST_QUEUES, 0,
1298 : : (u8 *)vfres, sizeof(*vfres));
1299 : : }
1300 : :
1301 : : static void
1302 : 0 : i40e_pf_host_process_cmd_get_rss_hena(struct i40e_pf_vf *vf)
1303 : : {
1304 : : struct virtchnl_rss_hena vrh = {0};
1305 : 0 : struct i40e_pf *pf = vf->pf;
1306 : :
1307 [ # # ]: 0 : if (pf->adapter->hw.mac.type == I40E_MAC_X722)
1308 : 0 : vrh.hena = I40E_DEFAULT_RSS_HENA_EXPANDED;
1309 : : else
1310 : 0 : vrh.hena = I40E_DEFAULT_RSS_HENA;
1311 : :
1312 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_GET_RSS_HENA_CAPS,
1313 : : I40E_SUCCESS, (uint8_t *)&vrh, sizeof(vrh));
1314 : 0 : }
1315 : :
1316 : : static void
1317 : 0 : i40e_pf_host_process_cmd_set_rss_hena(struct i40e_pf_vf *vf, uint8_t *msg)
1318 : : {
1319 : : struct virtchnl_rss_hena *vrh =
1320 : : (struct virtchnl_rss_hena *)msg;
1321 : 0 : struct i40e_hw *hw = &vf->pf->adapter->hw;
1322 : :
1323 : 0 : i40e_write_rx_ctl(hw, I40E_VFQF_HENA1(0, vf->vf_idx),
1324 : 0 : (uint32_t)vrh->hena);
1325 : 0 : i40e_write_rx_ctl(hw, I40E_VFQF_HENA1(1, vf->vf_idx),
1326 : 0 : (uint32_t)(vrh->hena >> 32));
1327 : :
1328 : 0 : i40e_pf_host_send_msg_to_vf(vf, VIRTCHNL_OP_SET_RSS_HENA,
1329 : : I40E_SUCCESS, NULL, 0);
1330 : 0 : }
1331 : :
1332 : : void
1333 : 0 : i40e_pf_host_handle_vf_msg(struct rte_eth_dev *dev,
1334 : : uint16_t abs_vf_id, uint32_t opcode,
1335 : : __rte_unused uint32_t retval,
1336 : : uint8_t *msg,
1337 : : uint16_t msglen)
1338 : : {
1339 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1340 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1341 : : struct i40e_pf_vf *vf;
1342 : : /* AdminQ will pass absolute VF id, transfer to internal vf id */
1343 : 0 : uint16_t vf_id = abs_vf_id - hw->func_caps.vf_base_id;
1344 : : struct rte_pmd_i40e_mb_event_param ret_param;
1345 : : uint64_t first_cycle, cur_cycle;
1346 : : bool b_op = TRUE;
1347 : : int ret;
1348 : :
1349 [ # # # # ]: 0 : if (vf_id > pf->vf_num - 1 || !pf->vfs) {
1350 : 0 : PMD_DRV_LOG(ERR, "invalid argument");
1351 : 0 : return;
1352 : : }
1353 : :
1354 : 0 : vf = &pf->vfs[vf_id];
1355 : :
1356 : : cur_cycle = rte_get_timer_cycles();
1357 : :
1358 : : /* if the VF being blocked, ignore the message and return */
1359 [ # # ]: 0 : if (cur_cycle < vf->ignore_end_cycle)
1360 : : return;
1361 : :
1362 [ # # ]: 0 : if (!vf->vsi) {
1363 : 0 : PMD_DRV_LOG(ERR, "NO VSI associated with VF found");
1364 : 0 : i40e_pf_host_send_msg_to_vf(vf, opcode,
1365 : : I40E_ERR_NO_AVAILABLE_VSI, NULL, 0);
1366 : 0 : goto check;
1367 : : }
1368 : :
1369 : : /* perform basic checks on the msg */
1370 : 0 : ret = virtchnl_vc_validate_vf_msg(&vf->version, opcode, msg, msglen);
1371 : :
1372 : : /* perform additional checks specific to this driver */
1373 [ # # ]: 0 : if (opcode == VIRTCHNL_OP_CONFIG_RSS_KEY) {
1374 : : struct virtchnl_rss_key *vrk = (struct virtchnl_rss_key *)msg;
1375 : :
1376 [ # # ]: 0 : if (vrk->key_len != ((I40E_PFQF_HKEY_MAX_INDEX + 1) * 4))
1377 : : ret = VIRTCHNL_ERR_PARAM;
1378 [ # # ]: 0 : } else if (opcode == VIRTCHNL_OP_CONFIG_RSS_LUT) {
1379 : : struct virtchnl_rss_lut *vrl = (struct virtchnl_rss_lut *)msg;
1380 : :
1381 [ # # ]: 0 : if (vrl->lut_entries != ((I40E_VFQF_HLUT1_MAX_INDEX + 1) * 4))
1382 : : ret = VIRTCHNL_ERR_PARAM;
1383 : : }
1384 : :
1385 [ # # ]: 0 : if (ret) {
1386 : 0 : PMD_DRV_LOG(ERR, "Invalid message from VF %u, opcode %u, len %u",
1387 : : vf_id, opcode, msglen);
1388 : 0 : i40e_pf_host_send_msg_to_vf(vf, opcode,
1389 : : I40E_ERR_PARAM, NULL, 0);
1390 : 0 : goto check;
1391 : : }
1392 : :
1393 : : /**
1394 : : * initialise structure to send to user application
1395 : : * will return response from user in retval field
1396 : : */
1397 : 0 : ret_param.retval = RTE_PMD_I40E_MB_EVENT_PROCEED;
1398 : 0 : ret_param.vfid = vf_id;
1399 : 0 : ret_param.msg_type = opcode;
1400 : 0 : ret_param.msg = (void *)msg;
1401 : 0 : ret_param.msglen = msglen;
1402 : :
1403 : : /**
1404 : : * Ask user application if we're allowed to perform those functions.
1405 : : * If we get ret_param.retval == RTE_PMD_I40E_MB_EVENT_PROCEED,
1406 : : * then business as usual.
1407 : : * If RTE_PMD_I40E_MB_EVENT_NOOP_ACK or RTE_PMD_I40E_MB_EVENT_NOOP_NACK,
1408 : : * do nothing and send not_supported to VF. As PF must send a response
1409 : : * to VF and ACK/NACK is not defined.
1410 : : */
1411 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_VF_MBOX, &ret_param);
1412 [ # # ]: 0 : if (ret_param.retval != RTE_PMD_I40E_MB_EVENT_PROCEED) {
1413 : 0 : PMD_DRV_LOG(WARNING, "VF to PF message(%d) is not permitted!",
1414 : : opcode);
1415 : : b_op = FALSE;
1416 : : }
1417 : :
1418 [ # # # # : 0 : switch (opcode) {
# # # # #
# # # # #
# # # # #
# # ]
1419 : 0 : case VIRTCHNL_OP_VERSION:
1420 : 0 : PMD_DRV_LOG(INFO, "OP_VERSION received");
1421 : 0 : i40e_pf_host_process_cmd_version(vf, msg, b_op);
1422 : 0 : break;
1423 : 0 : case VIRTCHNL_OP_RESET_VF:
1424 : 0 : PMD_DRV_LOG(INFO, "OP_RESET_VF received");
1425 : : i40e_pf_host_process_cmd_reset_vf(vf);
1426 : : break;
1427 : 0 : case VIRTCHNL_OP_GET_VF_RESOURCES:
1428 : 0 : PMD_DRV_LOG(INFO, "OP_GET_VF_RESOURCES received");
1429 : 0 : i40e_pf_host_process_cmd_get_vf_resource(vf, msg, b_op);
1430 : 0 : break;
1431 : 0 : case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1432 : 0 : PMD_DRV_LOG(INFO, "OP_CONFIG_VSI_QUEUES received");
1433 : 0 : i40e_pf_host_process_cmd_config_vsi_queues(vf, msg,
1434 : : msglen, b_op);
1435 : 0 : break;
1436 : 0 : case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1437 : 0 : PMD_DRV_LOG(INFO, "OP_CONFIG_IRQ_MAP received");
1438 : 0 : i40e_pf_host_process_cmd_config_irq_map(vf, msg, msglen, b_op);
1439 : 0 : break;
1440 : 0 : case VIRTCHNL_OP_ENABLE_QUEUES:
1441 : 0 : PMD_DRV_LOG(INFO, "OP_ENABLE_QUEUES received");
1442 [ # # ]: 0 : if (b_op) {
1443 : 0 : i40e_pf_host_process_cmd_enable_queues(vf, msg, msglen);
1444 : 0 : i40e_notify_vf_link_status(dev, vf);
1445 : : } else {
1446 : 0 : i40e_pf_host_send_msg_to_vf(
1447 : : vf, VIRTCHNL_OP_ENABLE_QUEUES,
1448 : : I40E_NOT_SUPPORTED, NULL, 0);
1449 : : }
1450 : : break;
1451 : 0 : case VIRTCHNL_OP_DISABLE_QUEUES:
1452 : 0 : PMD_DRV_LOG(INFO, "OP_DISABLE_QUEUE received");
1453 : 0 : i40e_pf_host_process_cmd_disable_queues(vf, msg, msglen, b_op);
1454 : 0 : break;
1455 : 0 : case VIRTCHNL_OP_ADD_ETH_ADDR:
1456 : 0 : PMD_DRV_LOG(INFO, "OP_ADD_ETHER_ADDRESS received");
1457 : 0 : i40e_pf_host_process_cmd_add_ether_address(vf, msg,
1458 : : msglen, b_op);
1459 : 0 : break;
1460 : 0 : case VIRTCHNL_OP_DEL_ETH_ADDR:
1461 : 0 : PMD_DRV_LOG(INFO, "OP_DEL_ETHER_ADDRESS received");
1462 : 0 : i40e_pf_host_process_cmd_del_ether_address(vf, msg,
1463 : : msglen, b_op);
1464 : 0 : break;
1465 : 0 : case VIRTCHNL_OP_ADD_VLAN:
1466 : 0 : PMD_DRV_LOG(INFO, "OP_ADD_VLAN received");
1467 : 0 : i40e_pf_host_process_cmd_add_vlan(vf, msg, msglen, b_op);
1468 : 0 : break;
1469 : 0 : case VIRTCHNL_OP_DEL_VLAN:
1470 : 0 : PMD_DRV_LOG(INFO, "OP_DEL_VLAN received");
1471 : 0 : i40e_pf_host_process_cmd_del_vlan(vf, msg, msglen, b_op);
1472 : 0 : break;
1473 : 0 : case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1474 : 0 : PMD_DRV_LOG(INFO, "OP_CONFIG_PROMISCUOUS_MODE received");
1475 : 0 : i40e_pf_host_process_cmd_config_promisc_mode(vf, msg,
1476 : : msglen, b_op);
1477 : 0 : break;
1478 : 0 : case VIRTCHNL_OP_GET_STATS:
1479 : 0 : PMD_DRV_LOG(INFO, "OP_GET_STATS received");
1480 : 0 : i40e_pf_host_process_cmd_get_stats(vf, b_op);
1481 : 0 : break;
1482 : 0 : case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
1483 : 0 : PMD_DRV_LOG(INFO, "OP_ENABLE_VLAN_STRIPPING received");
1484 : 0 : i40e_pf_host_process_cmd_enable_vlan_strip(vf, b_op);
1485 : 0 : break;
1486 : 0 : case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
1487 : 0 : PMD_DRV_LOG(INFO, "OP_DISABLE_VLAN_STRIPPING received");
1488 : 0 : i40e_pf_host_process_cmd_disable_vlan_strip(vf, b_op);
1489 : 0 : break;
1490 : 0 : case VIRTCHNL_OP_CONFIG_RSS_LUT:
1491 : 0 : PMD_DRV_LOG(INFO, "OP_CONFIG_RSS_LUT received");
1492 : 0 : i40e_pf_host_process_cmd_set_rss_lut(vf, msg, msglen, b_op);
1493 : 0 : break;
1494 : 0 : case VIRTCHNL_OP_CONFIG_RSS_KEY:
1495 : 0 : PMD_DRV_LOG(INFO, "OP_CONFIG_RSS_KEY received");
1496 : 0 : i40e_pf_host_process_cmd_set_rss_key(vf, msg, msglen, b_op);
1497 : 0 : break;
1498 : 0 : case VIRTCHNL_OP_REQUEST_QUEUES:
1499 : 0 : PMD_DRV_LOG(INFO, "OP_REQUEST_QUEUES received");
1500 : 0 : i40e_pf_host_process_cmd_request_queues(vf, msg);
1501 : 0 : break;
1502 : 0 : case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
1503 : 0 : PMD_DRV_LOG(INFO, "OP_GET_RSS_HENA_CAPS received");
1504 : 0 : i40e_pf_host_process_cmd_get_rss_hena(vf);
1505 : 0 : break;
1506 : 0 : case VIRTCHNL_OP_SET_RSS_HENA:
1507 : 0 : PMD_DRV_LOG(INFO, "OP_SET_RSS_HENA received");
1508 : 0 : i40e_pf_host_process_cmd_set_rss_hena(vf, msg);
1509 : 0 : break;
1510 : :
1511 : : /* Don't add command supported below, which will
1512 : : * return an error code.
1513 : : */
1514 : 0 : default:
1515 : 0 : PMD_DRV_LOG(ERR, "%u received, not supported", opcode);
1516 : 0 : i40e_pf_host_send_msg_to_vf(vf, opcode, I40E_ERR_PARAM,
1517 : : NULL, 0);
1518 : 0 : break;
1519 : : }
1520 : :
1521 : 0 : check:
1522 : : /* if message validation not enabled */
1523 [ # # ]: 0 : if (!pf->vf_msg_cfg.max_msg)
1524 : : return;
1525 : :
1526 : : /* store current cycle */
1527 : 0 : vf->msg_timestamps[vf->msg_index++] = cur_cycle;
1528 : 0 : vf->msg_index %= pf->vf_msg_cfg.max_msg;
1529 : :
1530 : : /* read the timestamp of earliest message */
1531 : 0 : first_cycle = vf->msg_timestamps[vf->msg_index];
1532 : :
1533 : : /*
1534 : : * If the time span from the arrival time of first message to
1535 : : * the arrival time of current message smaller than `period`,
1536 : : * that mean too much message in this statistic period.
1537 : : */
1538 [ # # ]: 0 : if (first_cycle && cur_cycle < first_cycle +
1539 [ # # ]: 0 : (uint64_t)pf->vf_msg_cfg.period * rte_get_timer_hz()) {
1540 : 0 : PMD_DRV_LOG(WARNING, "VF %u too much messages(%u in %u"
1541 : : " seconds), any new message from which"
1542 : : " will be ignored during next %u seconds!",
1543 : : vf_id, pf->vf_msg_cfg.max_msg,
1544 : : (uint32_t)((cur_cycle - first_cycle +
1545 : : rte_get_timer_hz() - 1) / rte_get_timer_hz()),
1546 : : pf->vf_msg_cfg.ignore_second);
1547 : 0 : vf->ignore_end_cycle = rte_get_timer_cycles() +
1548 : 0 : pf->vf_msg_cfg.ignore_second *
1549 : : rte_get_timer_hz();
1550 : : }
1551 : : }
1552 : :
1553 : : int
1554 : 0 : i40e_pf_host_init(struct rte_eth_dev *dev)
1555 : : {
1556 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1557 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1558 : : size_t size;
1559 : : int ret, i;
1560 : : uint32_t val;
1561 : :
1562 : 0 : PMD_INIT_FUNC_TRACE();
1563 : :
1564 : : /**
1565 : : * return if SRIOV not enabled, VF number not configured or
1566 : : * no queue assigned.
1567 : : */
1568 [ # # # # : 0 : if(!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 || pf->vf_nb_qps == 0)
# # ]
1569 : : return I40E_SUCCESS;
1570 : :
1571 : : /* Allocate memory to store VF structure */
1572 : 0 : pf->vfs = rte_zmalloc("i40e_pf_vf",sizeof(*pf->vfs) * pf->vf_num, 0);
1573 [ # # ]: 0 : if(pf->vfs == NULL)
1574 : : return -ENOMEM;
1575 : :
1576 : : /* Disable irq0 for VFR event */
1577 : 0 : i40e_pf_disable_irq0(hw);
1578 : :
1579 : : /* Disable VF link status interrupt */
1580 : 0 : val = I40E_READ_REG(hw, I40E_PFGEN_PORTMDIO_NUM);
1581 : 0 : val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
1582 : 0 : I40E_WRITE_REG(hw, I40E_PFGEN_PORTMDIO_NUM, val);
1583 : 0 : I40E_WRITE_FLUSH(hw);
1584 : :
1585 : : /* calculate the memory size for storing timestamp of messages */
1586 : 0 : size = pf->vf_msg_cfg.max_msg * sizeof(uint64_t);
1587 : :
1588 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
1589 : 0 : pf->vfs[i].pf = pf;
1590 : 0 : pf->vfs[i].state = I40E_VF_INACTIVE;
1591 : 0 : pf->vfs[i].vf_idx = i;
1592 : :
1593 [ # # ]: 0 : if (size) {
1594 : : /* allocate memory for store timestamp of messages */
1595 : 0 : pf->vfs[i].msg_timestamps =
1596 : 0 : rte_zmalloc("i40e_pf_vf", size, 0);
1597 [ # # ]: 0 : if (pf->vfs[i].msg_timestamps == NULL) {
1598 : : ret = -ENOMEM;
1599 : 0 : goto fail;
1600 : : }
1601 : : }
1602 : :
1603 : 0 : ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
1604 [ # # ]: 0 : if (ret != I40E_SUCCESS)
1605 : 0 : goto fail;
1606 : : }
1607 : :
1608 : 0 : RTE_ETH_DEV_SRIOV(dev).active = pf->vf_num;
1609 : : /* restore irq0 */
1610 : 0 : i40e_pf_enable_irq0(hw);
1611 : :
1612 : 0 : return I40E_SUCCESS;
1613 : :
1614 : 0 : fail:
1615 [ # # ]: 0 : for (; i >= 0; i--)
1616 : 0 : rte_free(pf->vfs[i].msg_timestamps);
1617 : 0 : rte_free(pf->vfs);
1618 : 0 : i40e_pf_enable_irq0(hw);
1619 : :
1620 : 0 : return ret;
1621 : : }
1622 : :
1623 : : int
1624 : 0 : i40e_pf_host_uninit(struct rte_eth_dev *dev)
1625 : : {
1626 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1627 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1628 : : uint32_t val;
1629 : : int i;
1630 : :
1631 : 0 : PMD_INIT_FUNC_TRACE();
1632 : :
1633 : : /**
1634 : : * return if SRIOV not enabled, VF number not configured or
1635 : : * no queue assigned.
1636 : : */
1637 [ # # ]: 0 : if ((!hw->func_caps.sr_iov_1_1) ||
1638 [ # # ]: 0 : (pf->vf_num == 0) ||
1639 [ # # ]: 0 : (pf->vf_nb_qps == 0))
1640 : : return I40E_SUCCESS;
1641 : :
1642 : : /* free memory for store timestamp of messages */
1643 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++)
1644 : 0 : rte_free(pf->vfs[i].msg_timestamps);
1645 : :
1646 : : /* free memory to store VF structure */
1647 : 0 : rte_free(pf->vfs);
1648 : 0 : pf->vfs = NULL;
1649 : :
1650 : : /* Disable irq0 for VFR event */
1651 : 0 : i40e_pf_disable_irq0(hw);
1652 : :
1653 : : /* Disable VF link status interrupt */
1654 : 0 : val = I40E_READ_REG(hw, I40E_PFGEN_PORTMDIO_NUM);
1655 : 0 : val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
1656 : 0 : I40E_WRITE_REG(hw, I40E_PFGEN_PORTMDIO_NUM, val);
1657 : 0 : I40E_WRITE_FLUSH(hw);
1658 : :
1659 : 0 : return I40E_SUCCESS;
1660 : : }
|