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