Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2023 Intel Corporation
3 : : */
4 : :
5 : : #include "idpf_common_virtchnl.h"
6 : : #include "idpf_common_logs.h"
7 : :
8 : : static int
9 : 0 : idpf_vc_clean(struct idpf_adapter *adapter)
10 : : {
11 : : struct idpf_ctlq_msg *q_msg[IDPF_CTLQ_LEN];
12 : 0 : uint16_t num_q_msg = IDPF_CTLQ_LEN;
13 : : struct idpf_dma_mem *dma_mem;
14 : : int err;
15 : : uint32_t i;
16 : :
17 [ # # ]: 0 : for (i = 0; i < 10; i++) {
18 : 0 : err = idpf_ctlq_clean_sq(adapter->hw.asq, &num_q_msg, q_msg);
19 : 0 : msleep(20);
20 [ # # ]: 0 : if (num_q_msg > 0)
21 : : break;
22 : : }
23 [ # # ]: 0 : if (err != 0)
24 : : return err;
25 : :
26 : : /* Empty queue is not an error */
27 [ # # ]: 0 : for (i = 0; i < num_q_msg; i++) {
28 : 0 : dma_mem = q_msg[i]->ctx.indirect.payload;
29 [ # # ]: 0 : if (dma_mem != NULL) {
30 : : idpf_free_dma_mem(&adapter->hw, dma_mem);
31 : 0 : rte_free(dma_mem);
32 : : }
33 : 0 : rte_free(q_msg[i]);
34 : : }
35 : :
36 : : return 0;
37 : : }
38 : :
39 : : static int
40 : 0 : idpf_send_vc_msg(struct idpf_adapter *adapter, uint32_t op,
41 : : uint16_t msg_size, uint8_t *msg)
42 : : {
43 : : struct idpf_ctlq_msg *ctlq_msg;
44 : : struct idpf_dma_mem *dma_mem;
45 : : int err;
46 : :
47 : 0 : err = idpf_vc_clean(adapter);
48 [ # # ]: 0 : if (err != 0)
49 : 0 : goto err;
50 : :
51 : 0 : ctlq_msg = rte_zmalloc(NULL, sizeof(struct idpf_ctlq_msg), 0);
52 [ # # ]: 0 : if (ctlq_msg == NULL) {
53 : : err = -ENOMEM;
54 : 0 : goto err;
55 : : }
56 : :
57 : 0 : dma_mem = rte_zmalloc(NULL, sizeof(struct idpf_dma_mem), 0);
58 [ # # ]: 0 : if (dma_mem == NULL) {
59 : : err = -ENOMEM;
60 : 0 : goto dma_mem_error;
61 : : }
62 : :
63 : 0 : dma_mem->size = IDPF_DFLT_MBX_BUF_SIZE;
64 : 0 : idpf_alloc_dma_mem(&adapter->hw, dma_mem, dma_mem->size);
65 [ # # ]: 0 : if (dma_mem->va == NULL) {
66 : : err = -ENOMEM;
67 : 0 : goto dma_alloc_error;
68 : : }
69 : :
70 : 0 : memcpy(dma_mem->va, msg, msg_size);
71 : :
72 : 0 : ctlq_msg->opcode = idpf_mbq_opc_send_msg_to_pf;
73 : 0 : ctlq_msg->func_id = 0;
74 : 0 : ctlq_msg->data_len = msg_size;
75 : 0 : ctlq_msg->cookie.mbx.chnl_opcode = op;
76 : 0 : ctlq_msg->cookie.mbx.chnl_retval = VIRTCHNL_STATUS_SUCCESS;
77 : 0 : ctlq_msg->ctx.indirect.payload = dma_mem;
78 : :
79 : 0 : err = idpf_ctlq_send(&adapter->hw, adapter->hw.asq, 1, ctlq_msg);
80 [ # # ]: 0 : if (err != 0)
81 : 0 : goto send_error;
82 : :
83 : : return 0;
84 : :
85 : : send_error:
86 : : idpf_free_dma_mem(&adapter->hw, dma_mem);
87 : 0 : dma_alloc_error:
88 : 0 : rte_free(dma_mem);
89 : 0 : dma_mem_error:
90 : 0 : rte_free(ctlq_msg);
91 : : err:
92 : : return err;
93 : : }
94 : :
95 : : static enum idpf_vc_result
96 : 0 : idpf_read_msg_from_cp(struct idpf_adapter *adapter, uint16_t buf_len,
97 : : uint8_t *buf)
98 : : {
99 : 0 : struct idpf_hw *hw = &adapter->hw;
100 : : struct idpf_ctlq_msg ctlq_msg;
101 : 0 : struct idpf_dma_mem *dma_mem = NULL;
102 : : enum idpf_vc_result result = IDPF_MSG_NON;
103 : : uint32_t opcode;
104 : 0 : uint16_t pending = 1;
105 : : int ret;
106 : :
107 : 0 : ret = idpf_ctlq_recv(hw->arq, &pending, &ctlq_msg);
108 [ # # ]: 0 : if (ret != 0) {
109 : 0 : DRV_LOG(DEBUG, "Can't read msg from AQ");
110 [ # # ]: 0 : if (ret != -ENOMSG)
111 : : result = IDPF_MSG_ERR;
112 : 0 : return result;
113 : : }
114 : :
115 [ # # ]: 0 : rte_memcpy(buf, ctlq_msg.ctx.indirect.payload->va, buf_len);
116 : :
117 : 0 : opcode = rte_le_to_cpu_32(ctlq_msg.cookie.mbx.chnl_opcode);
118 : 0 : adapter->cmd_retval = rte_le_to_cpu_32(ctlq_msg.cookie.mbx.chnl_retval);
119 : :
120 : 0 : DRV_LOG(DEBUG, "CQ from CP carries opcode %u, retval %d",
121 : : opcode, adapter->cmd_retval);
122 : :
123 [ # # ]: 0 : if (opcode == VIRTCHNL2_OP_EVENT) {
124 : 0 : struct virtchnl2_event *ve = ctlq_msg.ctx.indirect.payload->va;
125 : :
126 : : result = IDPF_MSG_SYS;
127 [ # # ]: 0 : switch (ve->event) {
128 : : case VIRTCHNL2_EVENT_LINK_CHANGE:
129 : : /* TBD */
130 : : break;
131 : 0 : default:
132 : 0 : DRV_LOG(ERR, "%s: Unknown event %d from CP",
133 : : __func__, ve->event);
134 : 0 : break;
135 : : }
136 : : } else {
137 : : /* async reply msg on command issued by pf previously */
138 : : result = IDPF_MSG_CMD;
139 [ # # ]: 0 : if (opcode != adapter->pend_cmd) {
140 : 0 : DRV_LOG(WARNING, "command mismatch, expect %u, get %u",
141 : : adapter->pend_cmd, opcode);
142 : : result = IDPF_MSG_ERR;
143 : : }
144 : : }
145 : :
146 [ # # ]: 0 : if (ctlq_msg.data_len != 0)
147 : 0 : dma_mem = ctlq_msg.ctx.indirect.payload;
148 : : else
149 : 0 : pending = 0;
150 : :
151 : 0 : ret = idpf_ctlq_post_rx_buffs(hw, hw->arq, &pending, &dma_mem);
152 [ # # # # ]: 0 : if (ret != 0 && dma_mem != NULL)
153 : : idpf_free_dma_mem(hw, dma_mem);
154 : :
155 : : return result;
156 : : }
157 : :
158 : : #define MAX_TRY_TIMES 200
159 : : #define ASQ_DELAY_MS 10
160 : :
161 : : int
162 : 0 : idpf_vc_one_msg_read(struct idpf_adapter *adapter, uint32_t ops, uint16_t buf_len,
163 : : uint8_t *buf)
164 : : {
165 : : int err = 0;
166 : : int i = 0;
167 : : int ret;
168 : :
169 : : do {
170 : 0 : ret = idpf_read_msg_from_cp(adapter, buf_len, buf);
171 [ # # ]: 0 : if (ret == IDPF_MSG_CMD)
172 : : break;
173 : : rte_delay_ms(ASQ_DELAY_MS);
174 [ # # ]: 0 : } while (i++ < MAX_TRY_TIMES);
175 [ # # ]: 0 : if (i >= MAX_TRY_TIMES ||
176 [ # # ]: 0 : adapter->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
177 : : err = -EBUSY;
178 : 0 : DRV_LOG(ERR, "No response or return failure (%d) for cmd %d",
179 : : adapter->cmd_retval, ops);
180 : : }
181 : :
182 : 0 : return err;
183 : : }
184 : :
185 : : int
186 : 0 : idpf_vc_cmd_execute(struct idpf_adapter *adapter, struct idpf_cmd_info *args)
187 : : {
188 : : int err = 0;
189 : : int i = 0;
190 : : int ret;
191 : :
192 [ # # ]: 0 : if (atomic_set_cmd(adapter, args->ops))
193 : : return -EINVAL;
194 : :
195 : 0 : ret = idpf_send_vc_msg(adapter, args->ops, args->in_args_size, args->in_args);
196 [ # # ]: 0 : if (ret != 0) {
197 : 0 : DRV_LOG(ERR, "fail to send cmd %d", args->ops);
198 : : clear_cmd(adapter);
199 : 0 : return ret;
200 : : }
201 : :
202 [ # # ]: 0 : switch (args->ops) {
203 : 0 : case VIRTCHNL_OP_VERSION:
204 : : case VIRTCHNL2_OP_GET_CAPS:
205 : : case VIRTCHNL2_OP_GET_PTYPE_INFO:
206 : : /* for init virtchnl ops, need to poll the response */
207 : 0 : err = idpf_vc_one_msg_read(adapter, args->ops, args->out_size, args->out_buffer);
208 : : clear_cmd(adapter);
209 : : break;
210 : 0 : default:
211 : : /* For other virtchnl ops in running time,
212 : : * wait for the cmd done flag.
213 : : */
214 : : do {
215 [ # # ]: 0 : if (adapter->pend_cmd == VIRTCHNL_OP_UNKNOWN)
216 : : break;
217 : : rte_delay_ms(ASQ_DELAY_MS);
218 : : /* If don't read msg or read sys event, continue */
219 [ # # ]: 0 : } while (i++ < MAX_TRY_TIMES);
220 : : /* If there's no response is received, clear command */
221 [ # # ]: 0 : if (i >= MAX_TRY_TIMES ||
222 [ # # ]: 0 : adapter->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
223 : : err = -EBUSY;
224 : 0 : DRV_LOG(ERR, "No response or return failure (%d) for cmd %d",
225 : : adapter->cmd_retval, args->ops);
226 : : clear_cmd(adapter);
227 : : }
228 : : break;
229 : : }
230 : :
231 : : return err;
232 : : }
233 : :
234 : : int
235 : 0 : idpf_vc_api_version_check(struct idpf_adapter *adapter)
236 : : {
237 : : struct virtchnl2_version_info version, *pver;
238 : : struct idpf_cmd_info args;
239 : : int err;
240 : :
241 : : memset(&version, 0, sizeof(struct virtchnl_version_info));
242 : 0 : version.major = VIRTCHNL2_VERSION_MAJOR_2;
243 : : version.minor = VIRTCHNL2_VERSION_MINOR_0;
244 : :
245 : 0 : args.ops = VIRTCHNL_OP_VERSION;
246 : 0 : args.in_args = (uint8_t *)&version;
247 : 0 : args.in_args_size = sizeof(version);
248 : 0 : args.out_buffer = adapter->mbx_resp;
249 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
250 : :
251 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
252 [ # # ]: 0 : if (err != 0) {
253 : 0 : DRV_LOG(ERR,
254 : : "Failed to execute command of VIRTCHNL_OP_VERSION");
255 : 0 : return err;
256 : : }
257 : :
258 : 0 : pver = (struct virtchnl2_version_info *)args.out_buffer;
259 : 0 : adapter->virtchnl_version = *pver;
260 : :
261 [ # # ]: 0 : if (adapter->virtchnl_version.major != VIRTCHNL2_VERSION_MAJOR_2 ||
262 : : adapter->virtchnl_version.minor != VIRTCHNL2_VERSION_MINOR_0) {
263 : 0 : DRV_LOG(ERR, "VIRTCHNL API version mismatch:(%u.%u)-(%u.%u)",
264 : : adapter->virtchnl_version.major,
265 : : adapter->virtchnl_version.minor,
266 : : VIRTCHNL2_VERSION_MAJOR_2,
267 : : VIRTCHNL2_VERSION_MINOR_0);
268 : 0 : return -EINVAL;
269 : : }
270 : :
271 : : return 0;
272 : : }
273 : :
274 : : int
275 : 0 : idpf_vc_caps_get(struct idpf_adapter *adapter)
276 : : {
277 : : struct idpf_cmd_info args;
278 : : int err;
279 : :
280 : 0 : args.ops = VIRTCHNL2_OP_GET_CAPS;
281 : 0 : args.in_args = (uint8_t *)&adapter->caps;
282 : 0 : args.in_args_size = sizeof(struct virtchnl2_get_capabilities);
283 : 0 : args.out_buffer = adapter->mbx_resp;
284 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
285 : :
286 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
287 [ # # ]: 0 : if (err != 0) {
288 : 0 : DRV_LOG(ERR,
289 : : "Failed to execute command of VIRTCHNL2_OP_GET_CAPS");
290 : 0 : return err;
291 : : }
292 : :
293 [ # # ]: 0 : rte_memcpy(&adapter->caps, args.out_buffer, sizeof(struct virtchnl2_get_capabilities));
294 : :
295 : : return 0;
296 : : }
297 : :
298 : : int
299 : 0 : idpf_vc_vport_create(struct idpf_vport *vport,
300 : : struct virtchnl2_create_vport *create_vport_info)
301 : : {
302 : 0 : struct idpf_adapter *adapter = vport->adapter;
303 : : struct virtchnl2_create_vport vport_msg;
304 : : struct idpf_cmd_info args;
305 : : int err = -1;
306 : :
307 : : memset(&vport_msg, 0, sizeof(struct virtchnl2_create_vport));
308 : 0 : vport_msg.vport_type = create_vport_info->vport_type;
309 : 0 : vport_msg.txq_model = create_vport_info->txq_model;
310 : 0 : vport_msg.rxq_model = create_vport_info->rxq_model;
311 : 0 : vport_msg.num_tx_q = create_vport_info->num_tx_q;
312 : 0 : vport_msg.num_tx_complq = create_vport_info->num_tx_complq;
313 : 0 : vport_msg.num_rx_q = create_vport_info->num_rx_q;
314 : 0 : vport_msg.num_rx_bufq = create_vport_info->num_rx_bufq;
315 : :
316 : : memset(&args, 0, sizeof(args));
317 : 0 : args.ops = VIRTCHNL2_OP_CREATE_VPORT;
318 : 0 : args.in_args = (uint8_t *)&vport_msg;
319 : 0 : args.in_args_size = sizeof(vport_msg);
320 : 0 : args.out_buffer = adapter->mbx_resp;
321 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
322 : :
323 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
324 [ # # ]: 0 : if (err != 0) {
325 : 0 : DRV_LOG(ERR,
326 : : "Failed to execute command of VIRTCHNL2_OP_CREATE_VPORT");
327 : 0 : return err;
328 : : }
329 : :
330 [ # # ]: 0 : rte_memcpy(&(vport->vport_info.info), args.out_buffer, IDPF_DFLT_MBX_BUF_SIZE);
331 : : return 0;
332 : : }
333 : :
334 : : int
335 : 0 : idpf_vc_vport_destroy(struct idpf_vport *vport)
336 : : {
337 : 0 : struct idpf_adapter *adapter = vport->adapter;
338 : : struct virtchnl2_vport vc_vport;
339 : : struct idpf_cmd_info args;
340 : : int err;
341 : :
342 : 0 : vc_vport.vport_id = vport->vport_id;
343 : :
344 : : memset(&args, 0, sizeof(args));
345 : 0 : args.ops = VIRTCHNL2_OP_DESTROY_VPORT;
346 : 0 : args.in_args = (uint8_t *)&vc_vport;
347 : 0 : args.in_args_size = sizeof(vc_vport);
348 : 0 : args.out_buffer = adapter->mbx_resp;
349 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
350 : :
351 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
352 [ # # ]: 0 : if (err != 0)
353 : 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_DESTROY_VPORT");
354 : :
355 : 0 : return err;
356 : : }
357 : :
358 : : int
359 : 0 : idpf_vc_queue_grps_add(struct idpf_vport *vport,
360 : : struct virtchnl2_add_queue_groups *p2p_queue_grps_info,
361 : : uint8_t *p2p_queue_grps_out)
362 : : {
363 : 0 : struct idpf_adapter *adapter = vport->adapter;
364 : : struct idpf_cmd_info args;
365 : : int size, qg_info_size;
366 : : int err = -1;
367 : :
368 : 0 : size = sizeof(*p2p_queue_grps_info) +
369 : 0 : (p2p_queue_grps_info->qg_info.num_queue_groups - 1) *
370 : : sizeof(struct virtchnl2_queue_group_info);
371 : :
372 : : memset(&args, 0, sizeof(args));
373 : 0 : args.ops = VIRTCHNL2_OP_ADD_QUEUE_GROUPS;
374 : 0 : args.in_args = (uint8_t *)p2p_queue_grps_info;
375 : 0 : args.in_args_size = size;
376 : 0 : args.out_buffer = adapter->mbx_resp;
377 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
378 : :
379 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
380 [ # # ]: 0 : if (err != 0) {
381 : 0 : DRV_LOG(ERR,
382 : : "Failed to execute command of VIRTCHNL2_OP_ADD_QUEUE_GROUPS");
383 : 0 : return err;
384 : : }
385 : :
386 [ # # ]: 0 : rte_memcpy(p2p_queue_grps_out, args.out_buffer, IDPF_DFLT_MBX_BUF_SIZE);
387 : : return 0;
388 : : }
389 : :
390 : 0 : int idpf_vc_queue_grps_del(struct idpf_vport *vport,
391 : : uint16_t num_q_grps,
392 : : struct virtchnl2_queue_group_id *qg_ids)
393 : : {
394 : 0 : struct idpf_adapter *adapter = vport->adapter;
395 : : struct virtchnl2_delete_queue_groups *vc_del_q_grps;
396 : : struct idpf_cmd_info args;
397 : : int size;
398 : : int err;
399 : :
400 : 0 : size = sizeof(*vc_del_q_grps) +
401 : : (num_q_grps - 1) * sizeof(struct virtchnl2_queue_group_id);
402 : 0 : vc_del_q_grps = rte_zmalloc("vc_del_q_grps", size, 0);
403 : :
404 : 0 : vc_del_q_grps->vport_id = vport->vport_id;
405 : 0 : vc_del_q_grps->num_queue_groups = num_q_grps;
406 : 0 : memcpy(vc_del_q_grps->qg_ids, qg_ids,
407 : : num_q_grps * sizeof(struct virtchnl2_queue_group_id));
408 : :
409 : : memset(&args, 0, sizeof(args));
410 : 0 : args.ops = VIRTCHNL2_OP_DEL_QUEUE_GROUPS;
411 : 0 : args.in_args = (uint8_t *)vc_del_q_grps;
412 : 0 : args.in_args_size = size;
413 : 0 : args.out_buffer = adapter->mbx_resp;
414 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
415 : :
416 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
417 [ # # ]: 0 : if (err != 0)
418 : 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_DEL_QUEUE_GROUPS");
419 : :
420 : 0 : rte_free(vc_del_q_grps);
421 : 0 : return err;
422 : : }
423 : :
424 : : int
425 : 0 : idpf_vc_rss_key_set(struct idpf_vport *vport)
426 : : {
427 : 0 : struct idpf_adapter *adapter = vport->adapter;
428 : : struct virtchnl2_rss_key *rss_key;
429 : : struct idpf_cmd_info args;
430 : : int len, err;
431 : :
432 : 0 : len = sizeof(*rss_key) + sizeof(rss_key->key[0]) *
433 : 0 : (vport->rss_key_size - 1);
434 : 0 : rss_key = rte_zmalloc("rss_key", len, 0);
435 [ # # ]: 0 : if (rss_key == NULL)
436 : : return -ENOMEM;
437 : :
438 : 0 : rss_key->vport_id = vport->vport_id;
439 : 0 : rss_key->key_len = vport->rss_key_size;
440 [ # # ]: 0 : rte_memcpy(rss_key->key, vport->rss_key,
441 : : sizeof(rss_key->key[0]) * vport->rss_key_size);
442 : :
443 : : memset(&args, 0, sizeof(args));
444 : 0 : args.ops = VIRTCHNL2_OP_SET_RSS_KEY;
445 : 0 : args.in_args = (uint8_t *)rss_key;
446 : 0 : args.in_args_size = len;
447 : 0 : args.out_buffer = adapter->mbx_resp;
448 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
449 : :
450 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
451 [ # # ]: 0 : if (err != 0)
452 : 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_SET_RSS_KEY");
453 : :
454 : 0 : rte_free(rss_key);
455 : 0 : return err;
456 : : }
457 : :
458 : 0 : int idpf_vc_rss_key_get(struct idpf_vport *vport)
459 : : {
460 : 0 : struct idpf_adapter *adapter = vport->adapter;
461 : : struct virtchnl2_rss_key *rss_key_ret;
462 : : struct virtchnl2_rss_key rss_key;
463 : : struct idpf_cmd_info args;
464 : : int err;
465 : :
466 : : memset(&rss_key, 0, sizeof(rss_key));
467 : 0 : rss_key.vport_id = vport->vport_id;
468 : :
469 : : memset(&args, 0, sizeof(args));
470 : 0 : args.ops = VIRTCHNL2_OP_GET_RSS_KEY;
471 : 0 : args.in_args = (uint8_t *)&rss_key;
472 : 0 : args.in_args_size = sizeof(rss_key);
473 : 0 : args.out_buffer = adapter->mbx_resp;
474 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
475 : :
476 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
477 : :
478 [ # # ]: 0 : if (!err) {
479 : 0 : rss_key_ret = (struct virtchnl2_rss_key *)args.out_buffer;
480 [ # # ]: 0 : if (rss_key_ret->key_len != vport->rss_key_size) {
481 : 0 : rte_free(vport->rss_key);
482 : 0 : vport->rss_key = NULL;
483 : 0 : vport->rss_key_size = RTE_MIN(IDPF_RSS_KEY_LEN,
484 : : rss_key_ret->key_len);
485 : 0 : vport->rss_key = rte_zmalloc("rss_key", vport->rss_key_size, 0);
486 [ # # ]: 0 : if (!vport->rss_key) {
487 : 0 : vport->rss_key_size = 0;
488 : 0 : DRV_LOG(ERR, "Failed to allocate RSS key");
489 : 0 : return -ENOMEM;
490 : : }
491 : : }
492 [ # # ]: 0 : rte_memcpy(vport->rss_key, rss_key_ret->key, vport->rss_key_size);
493 : : } else {
494 : 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_GET_RSS_KEY");
495 : : }
496 : :
497 : : return err;
498 : : }
499 : :
500 : : int
501 : 0 : idpf_vc_rss_lut_set(struct idpf_vport *vport)
502 : : {
503 : 0 : struct idpf_adapter *adapter = vport->adapter;
504 : : struct virtchnl2_rss_lut *rss_lut;
505 : : struct idpf_cmd_info args;
506 : : int len, err;
507 : :
508 : 0 : len = sizeof(*rss_lut) + sizeof(rss_lut->lut[0]) *
509 : 0 : (vport->rss_lut_size - 1);
510 : 0 : rss_lut = rte_zmalloc("rss_lut", len, 0);
511 [ # # ]: 0 : if (rss_lut == NULL)
512 : : return -ENOMEM;
513 : :
514 : 0 : rss_lut->vport_id = vport->vport_id;
515 : 0 : rss_lut->lut_entries = vport->rss_lut_size;
516 : 0 : rte_memcpy(rss_lut->lut, vport->rss_lut,
517 [ # # ]: 0 : sizeof(rss_lut->lut[0]) * vport->rss_lut_size);
518 : :
519 : : memset(&args, 0, sizeof(args));
520 : 0 : args.ops = VIRTCHNL2_OP_SET_RSS_LUT;
521 : 0 : args.in_args = (uint8_t *)rss_lut;
522 : 0 : args.in_args_size = len;
523 : 0 : args.out_buffer = adapter->mbx_resp;
524 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
525 : :
526 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
527 [ # # ]: 0 : if (err != 0)
528 : 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_SET_RSS_LUT");
529 : :
530 : 0 : rte_free(rss_lut);
531 : 0 : return err;
532 : : }
533 : :
534 : : int
535 : 0 : idpf_vc_rss_lut_get(struct idpf_vport *vport)
536 : : {
537 : 0 : struct idpf_adapter *adapter = vport->adapter;
538 : : struct virtchnl2_rss_lut *rss_lut_ret;
539 : : struct virtchnl2_rss_lut rss_lut;
540 : : struct idpf_cmd_info args;
541 : : int err;
542 : :
543 : : memset(&rss_lut, 0, sizeof(rss_lut));
544 : 0 : rss_lut.vport_id = vport->vport_id;
545 : :
546 : : memset(&args, 0, sizeof(args));
547 : 0 : args.ops = VIRTCHNL2_OP_GET_RSS_LUT;
548 : 0 : args.in_args = (uint8_t *)&rss_lut;
549 : 0 : args.in_args_size = sizeof(rss_lut);
550 : 0 : args.out_buffer = adapter->mbx_resp;
551 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
552 : :
553 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
554 : :
555 [ # # ]: 0 : if (!err) {
556 : 0 : rss_lut_ret = (struct virtchnl2_rss_lut *)args.out_buffer;
557 [ # # ]: 0 : if (rss_lut_ret->lut_entries != vport->rss_lut_size) {
558 : 0 : rte_free(vport->rss_lut);
559 : 0 : vport->rss_lut = NULL;
560 : 0 : vport->rss_lut = rte_zmalloc("rss_lut",
561 : 0 : sizeof(uint32_t) * rss_lut_ret->lut_entries, 0);
562 [ # # ]: 0 : if (vport->rss_lut == NULL) {
563 : 0 : DRV_LOG(ERR, "Failed to allocate RSS lut");
564 : 0 : return -ENOMEM;
565 : : }
566 : : }
567 [ # # ]: 0 : rte_memcpy(vport->rss_lut, rss_lut_ret->lut, rss_lut_ret->lut_entries);
568 : 0 : vport->rss_lut_size = rss_lut_ret->lut_entries;
569 : : } else {
570 : 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_GET_RSS_LUT");
571 : : }
572 : :
573 : : return err;
574 : : }
575 : :
576 : : int
577 : 0 : idpf_vc_rss_hash_get(struct idpf_vport *vport)
578 : : {
579 : 0 : struct idpf_adapter *adapter = vport->adapter;
580 : : struct virtchnl2_rss_hash *rss_hash_ret;
581 : : struct virtchnl2_rss_hash rss_hash;
582 : : struct idpf_cmd_info args;
583 : : int err;
584 : :
585 : : memset(&rss_hash, 0, sizeof(rss_hash));
586 : 0 : rss_hash.ptype_groups = vport->rss_hf;
587 : 0 : rss_hash.vport_id = vport->vport_id;
588 : :
589 : : memset(&args, 0, sizeof(args));
590 : 0 : args.ops = VIRTCHNL2_OP_GET_RSS_HASH;
591 : 0 : args.in_args = (uint8_t *)&rss_hash;
592 : 0 : args.in_args_size = sizeof(rss_hash);
593 : 0 : args.out_buffer = adapter->mbx_resp;
594 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
595 : :
596 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
597 : :
598 [ # # ]: 0 : if (!err) {
599 : 0 : rss_hash_ret = (struct virtchnl2_rss_hash *)args.out_buffer;
600 : 0 : vport->rss_hf = rss_hash_ret->ptype_groups;
601 : : } else {
602 : 0 : DRV_LOG(ERR, "Failed to execute command of OP_GET_RSS_HASH");
603 : : }
604 : :
605 : 0 : return err;
606 : : }
607 : :
608 : : int
609 : 0 : idpf_vc_rss_hash_set(struct idpf_vport *vport)
610 : : {
611 : 0 : struct idpf_adapter *adapter = vport->adapter;
612 : : struct virtchnl2_rss_hash rss_hash;
613 : : struct idpf_cmd_info args;
614 : : int err;
615 : :
616 : : memset(&rss_hash, 0, sizeof(rss_hash));
617 : 0 : rss_hash.ptype_groups = vport->rss_hf;
618 : 0 : rss_hash.vport_id = vport->vport_id;
619 : :
620 : : memset(&args, 0, sizeof(args));
621 : 0 : args.ops = VIRTCHNL2_OP_SET_RSS_HASH;
622 : 0 : args.in_args = (uint8_t *)&rss_hash;
623 : 0 : args.in_args_size = sizeof(rss_hash);
624 : 0 : args.out_buffer = adapter->mbx_resp;
625 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
626 : :
627 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
628 [ # # ]: 0 : if (err != 0)
629 : 0 : DRV_LOG(ERR, "Failed to execute command of OP_SET_RSS_HASH");
630 : :
631 : 0 : return err;
632 : : }
633 : :
634 : : int
635 : 0 : idpf_vc_irq_map_unmap_config(struct idpf_vport *vport, uint16_t nb_rxq, bool map)
636 : : {
637 : 0 : struct idpf_adapter *adapter = vport->adapter;
638 : : struct virtchnl2_queue_vector_maps *map_info;
639 : : struct virtchnl2_queue_vector *vecmap;
640 : : struct idpf_cmd_info args;
641 : : int len, i, err = 0;
642 : :
643 : 0 : len = sizeof(struct virtchnl2_queue_vector_maps) +
644 : 0 : (nb_rxq - 1) * sizeof(struct virtchnl2_queue_vector);
645 : :
646 : 0 : map_info = rte_zmalloc("map_info", len, 0);
647 [ # # ]: 0 : if (map_info == NULL)
648 : : return -ENOMEM;
649 : :
650 : 0 : map_info->vport_id = vport->vport_id;
651 : 0 : map_info->num_qv_maps = nb_rxq;
652 [ # # ]: 0 : for (i = 0; i < nb_rxq; i++) {
653 : : vecmap = &map_info->qv_maps[i];
654 : 0 : vecmap->queue_id = vport->qv_map[i].queue_id;
655 : 0 : vecmap->vector_id = vport->qv_map[i].vector_id;
656 : 0 : vecmap->itr_idx = VIRTCHNL2_ITR_IDX_0;
657 : 0 : vecmap->queue_type = VIRTCHNL2_QUEUE_TYPE_RX;
658 : : }
659 : :
660 [ # # ]: 0 : args.ops = map ? VIRTCHNL2_OP_MAP_QUEUE_VECTOR :
661 : : VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR;
662 : 0 : args.in_args = (uint8_t *)map_info;
663 : 0 : args.in_args_size = len;
664 : 0 : args.out_buffer = adapter->mbx_resp;
665 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
666 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
667 [ # # ]: 0 : if (err != 0)
668 [ # # ]: 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_QUEUE_VECTOR",
669 : : map ? "MAP" : "UNMAP");
670 : :
671 : 0 : rte_free(map_info);
672 : 0 : return err;
673 : : }
674 : :
675 : : int
676 : 0 : idpf_vc_vectors_alloc(struct idpf_vport *vport, uint16_t num_vectors)
677 : : {
678 : 0 : struct idpf_adapter *adapter = vport->adapter;
679 : : struct virtchnl2_alloc_vectors *alloc_vec;
680 : : struct idpf_cmd_info args;
681 : : int err, len;
682 : :
683 : 0 : len = sizeof(struct virtchnl2_alloc_vectors) +
684 : : (num_vectors - 1) * sizeof(struct virtchnl2_vector_chunk);
685 : 0 : alloc_vec = rte_zmalloc("alloc_vec", len, 0);
686 [ # # ]: 0 : if (alloc_vec == NULL)
687 : : return -ENOMEM;
688 : :
689 : 0 : alloc_vec->num_vectors = num_vectors;
690 : :
691 : 0 : args.ops = VIRTCHNL2_OP_ALLOC_VECTORS;
692 : 0 : args.in_args = (uint8_t *)alloc_vec;
693 : 0 : args.in_args_size = len;
694 : 0 : args.out_buffer = adapter->mbx_resp;
695 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
696 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
697 [ # # ]: 0 : if (err != 0)
698 : 0 : DRV_LOG(ERR, "Failed to execute command VIRTCHNL2_OP_ALLOC_VECTORS");
699 : :
700 [ # # ]: 0 : rte_memcpy(vport->recv_vectors, args.out_buffer, len);
701 : 0 : rte_free(alloc_vec);
702 : 0 : return err;
703 : : }
704 : :
705 : : int
706 : 0 : idpf_vc_vectors_dealloc(struct idpf_vport *vport)
707 : : {
708 : 0 : struct idpf_adapter *adapter = vport->adapter;
709 : : struct virtchnl2_alloc_vectors *alloc_vec;
710 : : struct virtchnl2_vector_chunks *vcs;
711 : : struct idpf_cmd_info args;
712 : : int err, len;
713 : :
714 : 0 : alloc_vec = vport->recv_vectors;
715 : 0 : vcs = &alloc_vec->vchunks;
716 : :
717 : 0 : len = sizeof(struct virtchnl2_vector_chunks) +
718 : 0 : (vcs->num_vchunks - 1) * sizeof(struct virtchnl2_vector_chunk);
719 : :
720 : 0 : args.ops = VIRTCHNL2_OP_DEALLOC_VECTORS;
721 : 0 : args.in_args = (uint8_t *)vcs;
722 : 0 : args.in_args_size = len;
723 : 0 : args.out_buffer = adapter->mbx_resp;
724 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
725 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
726 [ # # ]: 0 : if (err != 0)
727 : 0 : DRV_LOG(ERR, "Failed to execute command VIRTCHNL2_OP_DEALLOC_VECTORS");
728 : :
729 : 0 : return err;
730 : : }
731 : :
732 : : int
733 : 0 : idpf_vc_ena_dis_one_queue(struct idpf_vport *vport, uint16_t qid,
734 : : uint32_t type, bool on)
735 : : {
736 : 0 : struct idpf_adapter *adapter = vport->adapter;
737 : : struct virtchnl2_del_ena_dis_queues *queue_select;
738 : : struct virtchnl2_queue_chunk *queue_chunk;
739 : : struct idpf_cmd_info args;
740 : : int err, len;
741 : :
742 : : len = sizeof(struct virtchnl2_del_ena_dis_queues);
743 : 0 : queue_select = rte_zmalloc("queue_select", len, 0);
744 [ # # ]: 0 : if (queue_select == NULL)
745 : : return -ENOMEM;
746 : :
747 : : queue_chunk = queue_select->chunks.chunks;
748 : 0 : queue_select->chunks.num_chunks = 1;
749 : 0 : queue_select->vport_id = vport->vport_id;
750 : :
751 : 0 : queue_chunk->type = type;
752 : 0 : queue_chunk->start_queue_id = qid;
753 : 0 : queue_chunk->num_queues = 1;
754 : :
755 [ # # ]: 0 : args.ops = on ? VIRTCHNL2_OP_ENABLE_QUEUES :
756 : : VIRTCHNL2_OP_DISABLE_QUEUES;
757 : 0 : args.in_args = (uint8_t *)queue_select;
758 : 0 : args.in_args_size = len;
759 : 0 : args.out_buffer = adapter->mbx_resp;
760 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
761 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
762 [ # # ]: 0 : if (err != 0)
763 [ # # ]: 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_QUEUES",
764 : : on ? "ENABLE" : "DISABLE");
765 : :
766 : 0 : rte_free(queue_select);
767 : 0 : return err;
768 : : }
769 : :
770 : : int
771 : 0 : idpf_vc_queue_switch(struct idpf_vport *vport, uint16_t qid,
772 : : bool rx, bool on)
773 : : {
774 : : uint32_t type;
775 : : int err, queue_id;
776 : :
777 : : /* switch txq/rxq */
778 : 0 : type = rx ? VIRTCHNL2_QUEUE_TYPE_RX : VIRTCHNL2_QUEUE_TYPE_TX;
779 : :
780 [ # # ]: 0 : if (type == VIRTCHNL2_QUEUE_TYPE_RX)
781 : 0 : queue_id = vport->chunks_info.rx_start_qid + qid;
782 : : else
783 : 0 : queue_id = vport->chunks_info.tx_start_qid + qid;
784 : 0 : err = idpf_vc_ena_dis_one_queue(vport, queue_id, type, on);
785 [ # # ]: 0 : if (err != 0)
786 : : return err;
787 : :
788 : : /* switch tx completion queue */
789 [ # # # # ]: 0 : if (!rx && vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
790 : : type = VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION;
791 : 0 : queue_id = vport->chunks_info.tx_compl_start_qid + qid;
792 : 0 : err = idpf_vc_ena_dis_one_queue(vport, queue_id, type, on);
793 [ # # ]: 0 : if (err != 0)
794 : : return err;
795 : : }
796 : :
797 : : /* switch rx buffer queue */
798 [ # # # # ]: 0 : if (rx && vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
799 : : type = VIRTCHNL2_QUEUE_TYPE_RX_BUFFER;
800 : 0 : queue_id = vport->chunks_info.rx_buf_start_qid + 2 * qid;
801 : 0 : err = idpf_vc_ena_dis_one_queue(vport, queue_id, type, on);
802 [ # # ]: 0 : if (err != 0)
803 : : return err;
804 : 0 : queue_id++;
805 : 0 : err = idpf_vc_ena_dis_one_queue(vport, queue_id, type, on);
806 [ # # ]: 0 : if (err != 0)
807 : 0 : return err;
808 : : }
809 : :
810 : : return err;
811 : : }
812 : :
813 : : #define IDPF_RXTX_QUEUE_CHUNKS_NUM 2
814 : : int
815 : 0 : idpf_vc_queues_ena_dis(struct idpf_vport *vport, bool enable)
816 : : {
817 : 0 : struct idpf_adapter *adapter = vport->adapter;
818 : : struct virtchnl2_del_ena_dis_queues *queue_select;
819 : : struct virtchnl2_queue_chunk *queue_chunk;
820 : : uint32_t type;
821 : : struct idpf_cmd_info args;
822 : : uint16_t num_chunks;
823 : : int err, len;
824 : :
825 : : num_chunks = IDPF_RXTX_QUEUE_CHUNKS_NUM;
826 [ # # ]: 0 : if (vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT)
827 : : num_chunks++;
828 [ # # ]: 0 : if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT)
829 : 0 : num_chunks++;
830 : :
831 : 0 : len = sizeof(struct virtchnl2_del_ena_dis_queues) +
832 : : sizeof(struct virtchnl2_queue_chunk) * (num_chunks - 1);
833 : 0 : queue_select = rte_zmalloc("queue_select", len, 0);
834 [ # # ]: 0 : if (queue_select == NULL)
835 : : return -ENOMEM;
836 : :
837 : : queue_chunk = queue_select->chunks.chunks;
838 : 0 : queue_select->chunks.num_chunks = num_chunks;
839 : 0 : queue_select->vport_id = vport->vport_id;
840 : :
841 : : type = VIRTCHNL_QUEUE_TYPE_RX;
842 : 0 : queue_chunk[type].type = type;
843 : 0 : queue_chunk[type].start_queue_id = vport->chunks_info.rx_start_qid;
844 : 0 : queue_chunk[type].num_queues = vport->num_rx_q;
845 : :
846 : : type = VIRTCHNL2_QUEUE_TYPE_TX;
847 : 0 : queue_chunk[type].type = type;
848 : 0 : queue_chunk[type].start_queue_id = vport->chunks_info.tx_start_qid;
849 : 0 : queue_chunk[type].num_queues = vport->num_tx_q;
850 : :
851 [ # # ]: 0 : if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
852 : : type = VIRTCHNL2_QUEUE_TYPE_RX_BUFFER;
853 : 0 : queue_chunk[type].type = type;
854 : 0 : queue_chunk[type].start_queue_id =
855 : 0 : vport->chunks_info.rx_buf_start_qid;
856 : 0 : queue_chunk[type].num_queues = vport->num_rx_bufq;
857 : : }
858 : :
859 [ # # ]: 0 : if (vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) {
860 : : type = VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION;
861 : 0 : queue_chunk[type].type = type;
862 : 0 : queue_chunk[type].start_queue_id =
863 : 0 : vport->chunks_info.tx_compl_start_qid;
864 : 0 : queue_chunk[type].num_queues = vport->num_tx_complq;
865 : : }
866 : :
867 [ # # ]: 0 : args.ops = enable ? VIRTCHNL2_OP_ENABLE_QUEUES :
868 : : VIRTCHNL2_OP_DISABLE_QUEUES;
869 : 0 : args.in_args = (uint8_t *)queue_select;
870 : 0 : args.in_args_size = len;
871 : 0 : args.out_buffer = adapter->mbx_resp;
872 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
873 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
874 [ # # ]: 0 : if (err != 0)
875 [ # # ]: 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_QUEUES",
876 : : enable ? "ENABLE" : "DISABLE");
877 : :
878 : 0 : rte_free(queue_select);
879 : 0 : return err;
880 : : }
881 : :
882 : : int
883 : 0 : idpf_vc_vport_ena_dis(struct idpf_vport *vport, bool enable)
884 : : {
885 : 0 : struct idpf_adapter *adapter = vport->adapter;
886 : : struct virtchnl2_vport vc_vport;
887 : : struct idpf_cmd_info args;
888 : : int err;
889 : :
890 : 0 : vc_vport.vport_id = vport->vport_id;
891 [ # # ]: 0 : args.ops = enable ? VIRTCHNL2_OP_ENABLE_VPORT :
892 : : VIRTCHNL2_OP_DISABLE_VPORT;
893 : 0 : args.in_args = (uint8_t *)&vc_vport;
894 : 0 : args.in_args_size = sizeof(vc_vport);
895 : 0 : args.out_buffer = adapter->mbx_resp;
896 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
897 : :
898 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
899 [ # # ]: 0 : if (err != 0) {
900 [ # # ]: 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_VPORT",
901 : : enable ? "ENABLE" : "DISABLE");
902 : : }
903 : :
904 : 0 : return err;
905 : : }
906 : :
907 : : int
908 : 0 : idpf_vc_ptype_info_query(struct idpf_adapter *adapter,
909 : : struct virtchnl2_get_ptype_info *req_ptype_info,
910 : : struct virtchnl2_get_ptype_info *recv_ptype_info)
911 : : {
912 : : struct idpf_cmd_info args;
913 : : int err;
914 : :
915 : 0 : args.ops = VIRTCHNL2_OP_GET_PTYPE_INFO;
916 : 0 : args.in_args = (uint8_t *)req_ptype_info;
917 : 0 : args.in_args_size = sizeof(struct virtchnl2_get_ptype_info);
918 : 0 : args.out_buffer = adapter->mbx_resp;
919 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
920 : :
921 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
922 [ # # ]: 0 : if (err != 0)
923 : 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_GET_PTYPE_INFO");
924 : :
925 [ # # ]: 0 : rte_memcpy(recv_ptype_info, args.out_buffer, IDPF_DFLT_MBX_BUF_SIZE);
926 : 0 : return err;
927 : : }
928 : :
929 : : int
930 : 0 : idpf_vc_stats_query(struct idpf_vport *vport,
931 : : struct virtchnl2_vport_stats **pstats)
932 : : {
933 : 0 : struct idpf_adapter *adapter = vport->adapter;
934 : : struct virtchnl2_vport_stats vport_stats;
935 : : struct idpf_cmd_info args;
936 : : int err;
937 : :
938 : 0 : vport_stats.vport_id = vport->vport_id;
939 : 0 : args.ops = VIRTCHNL2_OP_GET_STATS;
940 : 0 : args.in_args = (u8 *)&vport_stats;
941 : 0 : args.in_args_size = sizeof(vport_stats);
942 : 0 : args.out_buffer = adapter->mbx_resp;
943 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
944 : :
945 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
946 [ # # ]: 0 : if (err) {
947 : 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_GET_STATS");
948 : 0 : *pstats = NULL;
949 : 0 : return err;
950 : : }
951 : 0 : *pstats = (struct virtchnl2_vport_stats *)args.out_buffer;
952 : 0 : return 0;
953 : : }
954 : :
955 : : #define IDPF_RX_BUF_STRIDE 64
956 : : int
957 : 0 : idpf_vc_rxq_config(struct idpf_vport *vport, struct idpf_rx_queue *rxq)
958 : : {
959 : 0 : struct idpf_adapter *adapter = vport->adapter;
960 : : struct virtchnl2_config_rx_queues *vc_rxqs = NULL;
961 : : struct virtchnl2_rxq_info *rxq_info;
962 : : struct idpf_cmd_info args;
963 : : uint16_t num_qs;
964 : : int size, err, i;
965 : :
966 [ # # ]: 0 : if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE)
967 : : num_qs = IDPF_RXQ_PER_GRP;
968 : : else
969 : : num_qs = IDPF_RXQ_PER_GRP + IDPF_RX_BUFQ_PER_GRP;
970 : :
971 : 0 : size = sizeof(*vc_rxqs) + (num_qs - 1) *
972 : : sizeof(struct virtchnl2_rxq_info);
973 : 0 : vc_rxqs = rte_zmalloc("cfg_rxqs", size, 0);
974 [ # # ]: 0 : if (vc_rxqs == NULL) {
975 : 0 : DRV_LOG(ERR, "Failed to allocate virtchnl2_config_rx_queues");
976 : : err = -ENOMEM;
977 : 0 : return err;
978 : : }
979 : 0 : vc_rxqs->vport_id = vport->vport_id;
980 : 0 : vc_rxqs->num_qinfo = num_qs;
981 [ # # ]: 0 : if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE) {
982 : : rxq_info = &vc_rxqs->qinfo[0];
983 : 0 : rxq_info->dma_ring_addr = rxq->rx_ring_phys_addr;
984 : 0 : rxq_info->type = VIRTCHNL2_QUEUE_TYPE_RX;
985 : 0 : rxq_info->queue_id = rxq->queue_id;
986 : 0 : rxq_info->model = VIRTCHNL2_QUEUE_MODEL_SINGLE;
987 : 0 : rxq_info->data_buffer_size = rxq->rx_buf_len;
988 : 0 : rxq_info->max_pkt_size = vport->max_pkt_len;
989 : :
990 : 0 : rxq_info->desc_ids = VIRTCHNL2_RXDID_2_FLEX_SQ_NIC_M;
991 : 0 : rxq_info->qflags |= VIRTCHNL2_RX_DESC_SIZE_32BYTE;
992 : :
993 : 0 : rxq_info->ring_len = rxq->nb_rx_desc;
994 : : } else {
995 : : /* Rx queue */
996 : : rxq_info = &vc_rxqs->qinfo[0];
997 : 0 : rxq_info->dma_ring_addr = rxq->rx_ring_phys_addr;
998 : 0 : rxq_info->type = VIRTCHNL2_QUEUE_TYPE_RX;
999 : 0 : rxq_info->queue_id = rxq->queue_id;
1000 : 0 : rxq_info->model = VIRTCHNL2_QUEUE_MODEL_SPLIT;
1001 : 0 : rxq_info->data_buffer_size = rxq->rx_buf_len;
1002 : 0 : rxq_info->max_pkt_size = vport->max_pkt_len;
1003 : :
1004 : 0 : rxq_info->desc_ids = VIRTCHNL2_RXDID_2_FLEX_SPLITQ_M;
1005 : 0 : rxq_info->qflags |= VIRTCHNL2_RX_DESC_SIZE_32BYTE;
1006 : :
1007 : 0 : rxq_info->ring_len = rxq->nb_rx_desc;
1008 : 0 : rxq_info->rx_bufq1_id = rxq->bufq1->queue_id;
1009 : 0 : rxq_info->bufq2_ena = 1;
1010 : 0 : rxq_info->rx_bufq2_id = rxq->bufq2->queue_id;
1011 : 0 : rxq_info->rx_buffer_low_watermark = 64;
1012 : :
1013 : : /* Buffer queue */
1014 [ # # ]: 0 : for (i = 1; i <= IDPF_RX_BUFQ_PER_GRP; i++) {
1015 [ # # ]: 0 : struct idpf_rx_queue *bufq = i == 1 ? rxq->bufq1 : rxq->bufq2;
1016 : : rxq_info = &vc_rxqs->qinfo[i];
1017 : 0 : rxq_info->dma_ring_addr = bufq->rx_ring_phys_addr;
1018 : 0 : rxq_info->type = VIRTCHNL2_QUEUE_TYPE_RX_BUFFER;
1019 : 0 : rxq_info->queue_id = bufq->queue_id;
1020 : 0 : rxq_info->model = VIRTCHNL2_QUEUE_MODEL_SPLIT;
1021 : 0 : rxq_info->data_buffer_size = bufq->rx_buf_len;
1022 : 0 : rxq_info->desc_ids = VIRTCHNL2_RXDID_2_FLEX_SPLITQ_M;
1023 : 0 : rxq_info->ring_len = bufq->nb_rx_desc;
1024 : :
1025 : 0 : rxq_info->buffer_notif_stride = IDPF_RX_BUF_STRIDE;
1026 : 0 : rxq_info->rx_buffer_low_watermark = 64;
1027 : : }
1028 : : }
1029 : :
1030 : : memset(&args, 0, sizeof(args));
1031 : 0 : args.ops = VIRTCHNL2_OP_CONFIG_RX_QUEUES;
1032 : 0 : args.in_args = (uint8_t *)vc_rxqs;
1033 : 0 : args.in_args_size = size;
1034 : 0 : args.out_buffer = adapter->mbx_resp;
1035 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
1036 : :
1037 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
1038 : 0 : rte_free(vc_rxqs);
1039 [ # # ]: 0 : if (err != 0)
1040 : 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_CONFIG_RX_QUEUES");
1041 : :
1042 : : return err;
1043 : : }
1044 : :
1045 : 0 : int idpf_vc_rxq_config_by_info(struct idpf_vport *vport, struct virtchnl2_rxq_info *rxq_info,
1046 : : uint16_t num_qs)
1047 : : {
1048 : 0 : struct idpf_adapter *adapter = vport->adapter;
1049 : : struct virtchnl2_config_rx_queues *vc_rxqs = NULL;
1050 : : struct idpf_cmd_info args;
1051 : : int size, err, i;
1052 : :
1053 : 0 : size = sizeof(*vc_rxqs) + (num_qs - 1) *
1054 : : sizeof(struct virtchnl2_rxq_info);
1055 : 0 : vc_rxqs = rte_zmalloc("cfg_rxqs", size, 0);
1056 [ # # ]: 0 : if (vc_rxqs == NULL) {
1057 : 0 : DRV_LOG(ERR, "Failed to allocate virtchnl2_config_rx_queues");
1058 : : err = -ENOMEM;
1059 : 0 : return err;
1060 : : }
1061 : 0 : vc_rxqs->vport_id = vport->vport_id;
1062 : 0 : vc_rxqs->num_qinfo = num_qs;
1063 : 0 : memcpy(vc_rxqs->qinfo, rxq_info, num_qs * sizeof(struct virtchnl2_rxq_info));
1064 : :
1065 : : memset(&args, 0, sizeof(args));
1066 : 0 : args.ops = VIRTCHNL2_OP_CONFIG_RX_QUEUES;
1067 : 0 : args.in_args = (uint8_t *)vc_rxqs;
1068 : 0 : args.in_args_size = size;
1069 : 0 : args.out_buffer = adapter->mbx_resp;
1070 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
1071 : :
1072 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
1073 : 0 : rte_free(vc_rxqs);
1074 [ # # ]: 0 : if (err != 0)
1075 : 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_CONFIG_RX_QUEUES");
1076 : :
1077 : : return err;
1078 : : }
1079 : :
1080 : : int
1081 : 0 : idpf_vc_txq_config(struct idpf_vport *vport, struct idpf_tx_queue *txq)
1082 : : {
1083 : 0 : struct idpf_adapter *adapter = vport->adapter;
1084 : : struct virtchnl2_config_tx_queues *vc_txqs = NULL;
1085 : : struct virtchnl2_txq_info *txq_info;
1086 : : struct idpf_cmd_info args;
1087 : : uint16_t num_qs;
1088 : : int size, err;
1089 : :
1090 [ # # ]: 0 : if (vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE)
1091 : : num_qs = IDPF_TXQ_PER_GRP;
1092 : : else
1093 : : num_qs = IDPF_TXQ_PER_GRP + IDPF_TX_COMPLQ_PER_GRP;
1094 : :
1095 : 0 : size = sizeof(*vc_txqs) + (num_qs - 1) *
1096 : : sizeof(struct virtchnl2_txq_info);
1097 : 0 : vc_txqs = rte_zmalloc("cfg_txqs", size, 0);
1098 [ # # ]: 0 : if (vc_txqs == NULL) {
1099 : 0 : DRV_LOG(ERR, "Failed to allocate virtchnl2_config_tx_queues");
1100 : : err = -ENOMEM;
1101 : 0 : return err;
1102 : : }
1103 : 0 : vc_txqs->vport_id = vport->vport_id;
1104 : 0 : vc_txqs->num_qinfo = num_qs;
1105 : :
1106 [ # # ]: 0 : if (vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE) {
1107 : : txq_info = &vc_txqs->qinfo[0];
1108 : 0 : txq_info->dma_ring_addr = txq->tx_ring_phys_addr;
1109 : 0 : txq_info->type = VIRTCHNL2_QUEUE_TYPE_TX;
1110 : 0 : txq_info->queue_id = txq->queue_id;
1111 : 0 : txq_info->model = VIRTCHNL2_QUEUE_MODEL_SINGLE;
1112 : 0 : txq_info->sched_mode = VIRTCHNL2_TXQ_SCHED_MODE_QUEUE;
1113 : 0 : txq_info->ring_len = txq->nb_tx_desc;
1114 : : } else {
1115 : : /* txq info */
1116 : : txq_info = &vc_txqs->qinfo[0];
1117 : 0 : txq_info->dma_ring_addr = txq->tx_ring_phys_addr;
1118 : 0 : txq_info->type = VIRTCHNL2_QUEUE_TYPE_TX;
1119 : 0 : txq_info->queue_id = txq->queue_id;
1120 : 0 : txq_info->model = VIRTCHNL2_QUEUE_MODEL_SPLIT;
1121 : 0 : txq_info->sched_mode = VIRTCHNL2_TXQ_SCHED_MODE_FLOW;
1122 : 0 : txq_info->ring_len = txq->nb_tx_desc;
1123 : 0 : txq_info->tx_compl_queue_id = txq->complq->queue_id;
1124 : 0 : txq_info->relative_queue_id = txq_info->queue_id;
1125 : :
1126 : : /* tx completion queue info */
1127 : : txq_info = &vc_txqs->qinfo[1];
1128 : 0 : txq_info->dma_ring_addr = txq->complq->tx_ring_phys_addr;
1129 : 0 : txq_info->type = VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION;
1130 : 0 : txq_info->queue_id = txq->complq->queue_id;
1131 : 0 : txq_info->model = VIRTCHNL2_QUEUE_MODEL_SPLIT;
1132 : 0 : txq_info->sched_mode = VIRTCHNL2_TXQ_SCHED_MODE_FLOW;
1133 : 0 : txq_info->ring_len = txq->complq->nb_tx_desc;
1134 : : }
1135 : :
1136 : : memset(&args, 0, sizeof(args));
1137 : 0 : args.ops = VIRTCHNL2_OP_CONFIG_TX_QUEUES;
1138 : 0 : args.in_args = (uint8_t *)vc_txqs;
1139 : 0 : args.in_args_size = size;
1140 : 0 : args.out_buffer = adapter->mbx_resp;
1141 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
1142 : :
1143 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
1144 : 0 : rte_free(vc_txqs);
1145 [ # # ]: 0 : if (err != 0)
1146 : 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_CONFIG_TX_QUEUES");
1147 : :
1148 : : return err;
1149 : : }
1150 : :
1151 : : int
1152 : 0 : idpf_vc_txq_config_by_info(struct idpf_vport *vport, struct virtchnl2_txq_info *txq_info,
1153 : : uint16_t num_qs)
1154 : : {
1155 : 0 : struct idpf_adapter *adapter = vport->adapter;
1156 : : struct virtchnl2_config_tx_queues *vc_txqs = NULL;
1157 : : struct idpf_cmd_info args;
1158 : : int size, err;
1159 : :
1160 : 0 : size = sizeof(*vc_txqs) + (num_qs - 1) * sizeof(struct virtchnl2_txq_info);
1161 : 0 : vc_txqs = rte_zmalloc("cfg_txqs", size, 0);
1162 [ # # ]: 0 : if (vc_txqs == NULL) {
1163 : 0 : DRV_LOG(ERR, "Failed to allocate virtchnl2_config_tx_queues");
1164 : : err = -ENOMEM;
1165 : 0 : return err;
1166 : : }
1167 : 0 : vc_txqs->vport_id = vport->vport_id;
1168 : 0 : vc_txqs->num_qinfo = num_qs;
1169 : 0 : memcpy(vc_txqs->qinfo, txq_info, num_qs * sizeof(struct virtchnl2_txq_info));
1170 : :
1171 : : memset(&args, 0, sizeof(args));
1172 : 0 : args.ops = VIRTCHNL2_OP_CONFIG_TX_QUEUES;
1173 : 0 : args.in_args = (uint8_t *)vc_txqs;
1174 : 0 : args.in_args_size = size;
1175 : 0 : args.out_buffer = adapter->mbx_resp;
1176 : 0 : args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
1177 : :
1178 : 0 : err = idpf_vc_cmd_execute(adapter, &args);
1179 : 0 : rte_free(vc_txqs);
1180 [ # # ]: 0 : if (err != 0)
1181 : 0 : DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_CONFIG_TX_QUEUES");
1182 : :
1183 : : return err;
1184 : : }
1185 : :
1186 : : int
1187 : 0 : idpf_vc_ctlq_recv(struct idpf_ctlq_info *cq, u16 *num_q_msg,
1188 : : struct idpf_ctlq_msg *q_msg)
1189 : : {
1190 : 0 : return idpf_ctlq_recv(cq, num_q_msg, q_msg);
1191 : : }
1192 : :
1193 : : int
1194 : 0 : idpf_vc_ctlq_post_rx_buffs(struct idpf_hw *hw, struct idpf_ctlq_info *cq,
1195 : : u16 *buff_count, struct idpf_dma_mem **buffs)
1196 : : {
1197 : 0 : return idpf_ctlq_post_rx_buffs(hw, cq, buff_count, buffs);
1198 : : }
|