]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/ethernet/qlogic/qed/qed_sriov.c
qed: Clean VF malicious indication when disabling IOV
[mirror_ubuntu-artful-kernel.git] / drivers / net / ethernet / qlogic / qed / qed_sriov.c
CommitLineData
32a47e72 1/* QLogic qed NIC Driver
e8f1cb50 2 * Copyright (c) 2015-2017 QLogic Corporation
32a47e72 3 *
e8f1cb50
MY
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
32a47e72
YM
31 */
32
dacd88d6 33#include <linux/etherdevice.h>
36558c3d 34#include <linux/crc32.h>
f29ffdb6 35#include <linux/vmalloc.h>
0b55e27d 36#include <linux/qed/qed_iov_if.h>
1408cc1f
YM
37#include "qed_cxt.h"
38#include "qed_hsi.h"
32a47e72 39#include "qed_hw.h"
1408cc1f 40#include "qed_init_ops.h"
32a47e72 41#include "qed_int.h"
1408cc1f 42#include "qed_mcp.h"
32a47e72 43#include "qed_reg_addr.h"
1408cc1f 44#include "qed_sp.h"
32a47e72
YM
45#include "qed_sriov.h"
46#include "qed_vf.h"
47
1408cc1f 48/* IOV ramrods */
1fe614d1 49static int qed_sp_vf_start(struct qed_hwfn *p_hwfn, struct qed_vf_info *p_vf)
1408cc1f
YM
50{
51 struct vf_start_ramrod_data *p_ramrod = NULL;
52 struct qed_spq_entry *p_ent = NULL;
53 struct qed_sp_init_data init_data;
54 int rc = -EINVAL;
1fe614d1 55 u8 fp_minor;
1408cc1f
YM
56
57 /* Get SPQ entry */
58 memset(&init_data, 0, sizeof(init_data));
59 init_data.cid = qed_spq_get_cid(p_hwfn);
1fe614d1 60 init_data.opaque_fid = p_vf->opaque_fid;
1408cc1f
YM
61 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
62
63 rc = qed_sp_init_request(p_hwfn, &p_ent,
64 COMMON_RAMROD_VF_START,
65 PROTOCOLID_COMMON, &init_data);
66 if (rc)
67 return rc;
68
69 p_ramrod = &p_ent->ramrod.vf_start;
70
1fe614d1
YM
71 p_ramrod->vf_id = GET_FIELD(p_vf->concrete_fid, PXP_CONCRETE_FID_VFID);
72 p_ramrod->opaque_fid = cpu_to_le16(p_vf->opaque_fid);
73
74 switch (p_hwfn->hw_info.personality) {
75 case QED_PCI_ETH:
76 p_ramrod->personality = PERSONALITY_ETH;
77 break;
78 case QED_PCI_ETH_ROCE:
79 p_ramrod->personality = PERSONALITY_RDMA_AND_ETH;
80 break;
81 default:
82 DP_NOTICE(p_hwfn, "Unknown VF personality %d\n",
83 p_hwfn->hw_info.personality);
84 return -EINVAL;
85 }
86
87 fp_minor = p_vf->acquire.vfdev_info.eth_fp_hsi_minor;
a044df83
YM
88 if (fp_minor > ETH_HSI_VER_MINOR &&
89 fp_minor != ETH_HSI_VER_NO_PKT_LEN_TUNN) {
1fe614d1
YM
90 DP_VERBOSE(p_hwfn,
91 QED_MSG_IOV,
92 "VF [%d] - Requested fp hsi %02x.%02x which is slightly newer than PF's %02x.%02x; Configuring PFs version\n",
93 p_vf->abs_vf_id,
94 ETH_HSI_VER_MAJOR,
95 fp_minor, ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
96 fp_minor = ETH_HSI_VER_MINOR;
97 }
1408cc1f 98
351a4ded 99 p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR;
1fe614d1
YM
100 p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = fp_minor;
101
102 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
103 "VF[%d] - Starting using HSI %02x.%02x\n",
104 p_vf->abs_vf_id, ETH_HSI_VER_MAJOR, fp_minor);
1408cc1f
YM
105
106 return qed_spq_post(p_hwfn, p_ent, NULL);
107}
108
0b55e27d
YM
109static int qed_sp_vf_stop(struct qed_hwfn *p_hwfn,
110 u32 concrete_vfid, u16 opaque_vfid)
111{
112 struct vf_stop_ramrod_data *p_ramrod = NULL;
113 struct qed_spq_entry *p_ent = NULL;
114 struct qed_sp_init_data init_data;
115 int rc = -EINVAL;
116
117 /* Get SPQ entry */
118 memset(&init_data, 0, sizeof(init_data));
119 init_data.cid = qed_spq_get_cid(p_hwfn);
120 init_data.opaque_fid = opaque_vfid;
121 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
122
123 rc = qed_sp_init_request(p_hwfn, &p_ent,
124 COMMON_RAMROD_VF_STOP,
125 PROTOCOLID_COMMON, &init_data);
126 if (rc)
127 return rc;
128
129 p_ramrod = &p_ent->ramrod.vf_stop;
130
131 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
132
133 return qed_spq_post(p_hwfn, p_ent, NULL);
134}
135
ba56947a 136static bool qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn,
7eff82b0
YM
137 int rel_vf_id,
138 bool b_enabled_only, bool b_non_malicious)
32a47e72
YM
139{
140 if (!p_hwfn->pf_iov_info) {
141 DP_NOTICE(p_hwfn->cdev, "No iov info\n");
142 return false;
143 }
144
145 if ((rel_vf_id >= p_hwfn->cdev->p_iov_info->total_vfs) ||
146 (rel_vf_id < 0))
147 return false;
148
149 if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
150 b_enabled_only)
151 return false;
152
7eff82b0
YM
153 if ((p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_malicious) &&
154 b_non_malicious)
155 return false;
156
32a47e72
YM
157 return true;
158}
159
37bff2b9
YM
160static struct qed_vf_info *qed_iov_get_vf_info(struct qed_hwfn *p_hwfn,
161 u16 relative_vf_id,
162 bool b_enabled_only)
163{
164 struct qed_vf_info *vf = NULL;
165
166 if (!p_hwfn->pf_iov_info) {
167 DP_NOTICE(p_hwfn->cdev, "No iov info\n");
168 return NULL;
169 }
170
7eff82b0
YM
171 if (qed_iov_is_valid_vfid(p_hwfn, relative_vf_id,
172 b_enabled_only, false))
37bff2b9
YM
173 vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
174 else
175 DP_ERR(p_hwfn, "qed_iov_get_vf_info: VF[%d] is not enabled\n",
176 relative_vf_id);
177
178 return vf;
179}
180
41086467
YM
181static bool qed_iov_validate_rxq(struct qed_hwfn *p_hwfn,
182 struct qed_vf_info *p_vf, u16 rx_qid)
183{
184 if (rx_qid >= p_vf->num_rxqs)
185 DP_VERBOSE(p_hwfn,
186 QED_MSG_IOV,
187 "VF[0x%02x] - can't touch Rx queue[%04x]; Only 0x%04x are allocated\n",
188 p_vf->abs_vf_id, rx_qid, p_vf->num_rxqs);
189 return rx_qid < p_vf->num_rxqs;
190}
191
192static bool qed_iov_validate_txq(struct qed_hwfn *p_hwfn,
193 struct qed_vf_info *p_vf, u16 tx_qid)
194{
195 if (tx_qid >= p_vf->num_txqs)
196 DP_VERBOSE(p_hwfn,
197 QED_MSG_IOV,
198 "VF[0x%02x] - can't touch Tx queue[%04x]; Only 0x%04x are allocated\n",
199 p_vf->abs_vf_id, tx_qid, p_vf->num_txqs);
200 return tx_qid < p_vf->num_txqs;
201}
202
203static bool qed_iov_validate_sb(struct qed_hwfn *p_hwfn,
204 struct qed_vf_info *p_vf, u16 sb_idx)
205{
206 int i;
207
208 for (i = 0; i < p_vf->num_sbs; i++)
209 if (p_vf->igu_sbs[i] == sb_idx)
210 return true;
211
212 DP_VERBOSE(p_hwfn,
213 QED_MSG_IOV,
214 "VF[0%02x] - tried using sb_idx %04x which doesn't exist as one of its 0x%02x SBs\n",
215 p_vf->abs_vf_id, sb_idx, p_vf->num_sbs);
216
217 return false;
218}
219
ba56947a
BX
220static int qed_iov_post_vf_bulletin(struct qed_hwfn *p_hwfn,
221 int vfid, struct qed_ptt *p_ptt)
36558c3d
YM
222{
223 struct qed_bulletin_content *p_bulletin;
224 int crc_size = sizeof(p_bulletin->crc);
225 struct qed_dmae_params params;
226 struct qed_vf_info *p_vf;
227
228 p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
229 if (!p_vf)
230 return -EINVAL;
231
232 if (!p_vf->vf_bulletin)
233 return -EINVAL;
234
235 p_bulletin = p_vf->bulletin.p_virt;
236
237 /* Increment bulletin board version and compute crc */
238 p_bulletin->version++;
239 p_bulletin->crc = crc32(0, (u8 *)p_bulletin + crc_size,
240 p_vf->bulletin.size - crc_size);
241
242 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
243 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
244 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
245
246 /* propagate bulletin board via dmae to vm memory */
247 memset(&params, 0, sizeof(params));
248 params.flags = QED_DMAE_FLAG_VF_DST;
249 params.dst_vfid = p_vf->abs_vf_id;
250 return qed_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
251 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
252 &params);
253}
254
32a47e72
YM
255static int qed_iov_pci_cfg_info(struct qed_dev *cdev)
256{
257 struct qed_hw_sriov_info *iov = cdev->p_iov_info;
258 int pos = iov->pos;
259
260 DP_VERBOSE(cdev, QED_MSG_IOV, "sriov ext pos %d\n", pos);
261 pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
262
263 pci_read_config_word(cdev->pdev,
264 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
265 pci_read_config_word(cdev->pdev,
266 pos + PCI_SRIOV_INITIAL_VF, &iov->initial_vfs);
267
268 pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
269 if (iov->num_vfs) {
270 DP_VERBOSE(cdev,
271 QED_MSG_IOV,
272 "Number of VFs are already set to non-zero value. Ignoring PCI configuration value\n");
273 iov->num_vfs = 0;
274 }
275
276 pci_read_config_word(cdev->pdev,
277 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
278
279 pci_read_config_word(cdev->pdev,
280 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
281
282 pci_read_config_word(cdev->pdev,
283 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
284
285 pci_read_config_dword(cdev->pdev,
286 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
287
288 pci_read_config_dword(cdev->pdev, pos + PCI_SRIOV_CAP, &iov->cap);
289
290 pci_read_config_byte(cdev->pdev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
291
292 DP_VERBOSE(cdev,
293 QED_MSG_IOV,
294 "IOV info: nres %d, cap 0x%x, ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d, stride %d, page size 0x%x\n",
295 iov->nres,
296 iov->cap,
297 iov->ctrl,
298 iov->total_vfs,
299 iov->initial_vfs,
300 iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz);
301
302 /* Some sanity checks */
303 if (iov->num_vfs > NUM_OF_VFS(cdev) ||
304 iov->total_vfs > NUM_OF_VFS(cdev)) {
305 /* This can happen only due to a bug. In this case we set
306 * num_vfs to zero to avoid memory corruption in the code that
307 * assumes max number of vfs
308 */
309 DP_NOTICE(cdev,
310 "IOV: Unexpected number of vfs set: %d setting num_vf to zero\n",
311 iov->num_vfs);
312
313 iov->num_vfs = 0;
314 iov->total_vfs = 0;
315 }
316
317 return 0;
318}
319
320static void qed_iov_clear_vf_igu_blocks(struct qed_hwfn *p_hwfn,
321 struct qed_ptt *p_ptt)
322{
323 struct qed_igu_block *p_sb;
324 u16 sb_id;
325 u32 val;
326
327 if (!p_hwfn->hw_info.p_igu_info) {
328 DP_ERR(p_hwfn,
329 "qed_iov_clear_vf_igu_blocks IGU Info not initialized\n");
330 return;
331 }
332
333 for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(p_hwfn->cdev);
334 sb_id++) {
335 p_sb = &p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks[sb_id];
336 if ((p_sb->status & QED_IGU_STATUS_FREE) &&
337 !(p_sb->status & QED_IGU_STATUS_PF)) {
338 val = qed_rd(p_hwfn, p_ptt,
339 IGU_REG_MAPPING_MEMORY + sb_id * 4);
340 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
341 qed_wr(p_hwfn, p_ptt,
342 IGU_REG_MAPPING_MEMORY + 4 * sb_id, val);
343 }
344 }
345}
346
347static void qed_iov_setup_vfdb(struct qed_hwfn *p_hwfn)
348{
349 struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
350 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
351 struct qed_bulletin_content *p_bulletin_virt;
352 dma_addr_t req_p, rply_p, bulletin_p;
353 union pfvf_tlvs *p_reply_virt_addr;
354 union vfpf_tlvs *p_req_virt_addr;
355 u8 idx = 0;
356
357 memset(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
358
359 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
360 req_p = p_iov_info->mbx_msg_phys_addr;
361 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
362 rply_p = p_iov_info->mbx_reply_phys_addr;
363 p_bulletin_virt = p_iov_info->p_bulletins;
364 bulletin_p = p_iov_info->bulletins_phys;
365 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
366 DP_ERR(p_hwfn,
367 "qed_iov_setup_vfdb called without allocating mem first\n");
368 return;
369 }
370
371 for (idx = 0; idx < p_iov->total_vfs; idx++) {
372 struct qed_vf_info *vf = &p_iov_info->vfs_array[idx];
373 u32 concrete;
374
375 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
376 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
377 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
378 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
379
380 vf->state = VF_STOPPED;
381 vf->b_init = false;
382
383 vf->bulletin.phys = idx *
384 sizeof(struct qed_bulletin_content) +
385 bulletin_p;
386 vf->bulletin.p_virt = p_bulletin_virt + idx;
387 vf->bulletin.size = sizeof(struct qed_bulletin_content);
388
389 vf->relative_vf_id = idx;
390 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
391 concrete = qed_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
392 vf->concrete_fid = concrete;
393 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
394 (vf->abs_vf_id << 8);
395 vf->vport_id = idx + 1;
1cf2b1a9
YM
396
397 vf->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
398 vf->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
32a47e72
YM
399 }
400}
401
402static int qed_iov_allocate_vfdb(struct qed_hwfn *p_hwfn)
403{
404 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
405 void **p_v_addr;
406 u16 num_vfs = 0;
407
408 num_vfs = p_hwfn->cdev->p_iov_info->total_vfs;
409
410 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
411 "qed_iov_allocate_vfdb for %d VFs\n", num_vfs);
412
413 /* Allocate PF Mailbox buffer (per-VF) */
414 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
415 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
416 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
417 p_iov_info->mbx_msg_size,
418 &p_iov_info->mbx_msg_phys_addr,
419 GFP_KERNEL);
420 if (!*p_v_addr)
421 return -ENOMEM;
422
423 /* Allocate PF Mailbox Reply buffer (per-VF) */
424 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
425 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
426 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
427 p_iov_info->mbx_reply_size,
428 &p_iov_info->mbx_reply_phys_addr,
429 GFP_KERNEL);
430 if (!*p_v_addr)
431 return -ENOMEM;
432
433 p_iov_info->bulletins_size = sizeof(struct qed_bulletin_content) *
434 num_vfs;
435 p_v_addr = &p_iov_info->p_bulletins;
436 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
437 p_iov_info->bulletins_size,
438 &p_iov_info->bulletins_phys,
439 GFP_KERNEL);
440 if (!*p_v_addr)
441 return -ENOMEM;
442
443 DP_VERBOSE(p_hwfn,
444 QED_MSG_IOV,
445 "PF's Requests mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys] Bulletins [%p virt 0x%llx phys]\n",
446 p_iov_info->mbx_msg_virt_addr,
447 (u64) p_iov_info->mbx_msg_phys_addr,
448 p_iov_info->mbx_reply_virt_addr,
449 (u64) p_iov_info->mbx_reply_phys_addr,
450 p_iov_info->p_bulletins, (u64) p_iov_info->bulletins_phys);
451
452 return 0;
453}
454
455static void qed_iov_free_vfdb(struct qed_hwfn *p_hwfn)
456{
457 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
458
459 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
460 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
461 p_iov_info->mbx_msg_size,
462 p_iov_info->mbx_msg_virt_addr,
463 p_iov_info->mbx_msg_phys_addr);
464
465 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
466 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
467 p_iov_info->mbx_reply_size,
468 p_iov_info->mbx_reply_virt_addr,
469 p_iov_info->mbx_reply_phys_addr);
470
471 if (p_iov_info->p_bulletins)
472 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
473 p_iov_info->bulletins_size,
474 p_iov_info->p_bulletins,
475 p_iov_info->bulletins_phys);
476}
477
478int qed_iov_alloc(struct qed_hwfn *p_hwfn)
479{
480 struct qed_pf_iov *p_sriov;
481
482 if (!IS_PF_SRIOV(p_hwfn)) {
483 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
484 "No SR-IOV - no need for IOV db\n");
485 return 0;
486 }
487
488 p_sriov = kzalloc(sizeof(*p_sriov), GFP_KERNEL);
2591c280 489 if (!p_sriov)
32a47e72 490 return -ENOMEM;
32a47e72
YM
491
492 p_hwfn->pf_iov_info = p_sriov;
493
494 return qed_iov_allocate_vfdb(p_hwfn);
495}
496
497void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
498{
499 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
500 return;
501
502 qed_iov_setup_vfdb(p_hwfn);
503 qed_iov_clear_vf_igu_blocks(p_hwfn, p_ptt);
504}
505
506void qed_iov_free(struct qed_hwfn *p_hwfn)
507{
508 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
509 qed_iov_free_vfdb(p_hwfn);
510 kfree(p_hwfn->pf_iov_info);
511 }
512}
513
514void qed_iov_free_hw_info(struct qed_dev *cdev)
515{
516 kfree(cdev->p_iov_info);
517 cdev->p_iov_info = NULL;
518}
519
520int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
521{
522 struct qed_dev *cdev = p_hwfn->cdev;
523 int pos;
524 int rc;
525
1408cc1f
YM
526 if (IS_VF(p_hwfn->cdev))
527 return 0;
528
32a47e72
YM
529 /* Learn the PCI configuration */
530 pos = pci_find_ext_capability(p_hwfn->cdev->pdev,
531 PCI_EXT_CAP_ID_SRIOV);
532 if (!pos) {
533 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "No PCIe IOV support\n");
534 return 0;
535 }
536
537 /* Allocate a new struct for IOV information */
538 cdev->p_iov_info = kzalloc(sizeof(*cdev->p_iov_info), GFP_KERNEL);
2591c280 539 if (!cdev->p_iov_info)
32a47e72 540 return -ENOMEM;
2591c280 541
32a47e72
YM
542 cdev->p_iov_info->pos = pos;
543
544 rc = qed_iov_pci_cfg_info(cdev);
545 if (rc)
546 return rc;
547
548 /* We want PF IOV to be synonemous with the existance of p_iov_info;
549 * In case the capability is published but there are no VFs, simply
550 * de-allocate the struct.
551 */
552 if (!cdev->p_iov_info->total_vfs) {
553 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
554 "IOV capabilities, but no VFs are published\n");
555 kfree(cdev->p_iov_info);
556 cdev->p_iov_info = NULL;
557 return 0;
558 }
559
9c79ddaa
MY
560 /* First VF index based on offset is tricky:
561 * - If ARI is supported [likely], offset - (16 - pf_id) would
562 * provide the number for eng0. 2nd engine Vfs would begin
563 * after the first engine's VFs.
564 * - If !ARI, VFs would start on next device.
565 * so offset - (256 - pf_id) would provide the number.
566 * Utilize the fact that (256 - pf_id) is achieved only by later
567 * to diffrentiate between the two.
32a47e72 568 */
9c79ddaa
MY
569
570 if (p_hwfn->cdev->p_iov_info->offset < (256 - p_hwfn->abs_pf_id)) {
571 u32 first = p_hwfn->cdev->p_iov_info->offset +
572 p_hwfn->abs_pf_id - 16;
573
574 cdev->p_iov_info->first_vf_in_pf = first;
575
576 if (QED_PATH_ID(p_hwfn))
577 cdev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
578 } else {
579 u32 first = p_hwfn->cdev->p_iov_info->offset +
580 p_hwfn->abs_pf_id - 256;
581
582 cdev->p_iov_info->first_vf_in_pf = first;
583 }
32a47e72
YM
584
585 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
586 "First VF in hwfn 0x%08x\n",
587 cdev->p_iov_info->first_vf_in_pf);
588
589 return 0;
590}
591
7eff82b0
YM
592bool _qed_iov_pf_sanity_check(struct qed_hwfn *p_hwfn,
593 int vfid, bool b_fail_malicious)
37bff2b9
YM
594{
595 /* Check PF supports sriov */
b0409fa0
YM
596 if (IS_VF(p_hwfn->cdev) || !IS_QED_SRIOV(p_hwfn->cdev) ||
597 !IS_PF_SRIOV_ALLOC(p_hwfn))
37bff2b9
YM
598 return false;
599
600 /* Check VF validity */
7eff82b0 601 if (!qed_iov_is_valid_vfid(p_hwfn, vfid, true, b_fail_malicious))
37bff2b9
YM
602 return false;
603
604 return true;
605}
606
7eff82b0
YM
607bool qed_iov_pf_sanity_check(struct qed_hwfn *p_hwfn, int vfid)
608{
609 return _qed_iov_pf_sanity_check(p_hwfn, vfid, true);
610}
611
0b55e27d
YM
612static void qed_iov_set_vf_to_disable(struct qed_dev *cdev,
613 u16 rel_vf_id, u8 to_disable)
614{
615 struct qed_vf_info *vf;
616 int i;
617
618 for_each_hwfn(cdev, i) {
619 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
620
621 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
622 if (!vf)
623 continue;
624
625 vf->to_disable = to_disable;
626 }
627}
628
ba56947a 629static void qed_iov_set_vfs_to_disable(struct qed_dev *cdev, u8 to_disable)
0b55e27d
YM
630{
631 u16 i;
632
633 if (!IS_QED_SRIOV(cdev))
634 return;
635
636 for (i = 0; i < cdev->p_iov_info->total_vfs; i++)
637 qed_iov_set_vf_to_disable(cdev, i, to_disable);
638}
639
1408cc1f
YM
640static void qed_iov_vf_pglue_clear_err(struct qed_hwfn *p_hwfn,
641 struct qed_ptt *p_ptt, u8 abs_vfid)
642{
643 qed_wr(p_hwfn, p_ptt,
644 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
645 1 << (abs_vfid & 0x1f));
646}
647
dacd88d6
YM
648static void qed_iov_vf_igu_reset(struct qed_hwfn *p_hwfn,
649 struct qed_ptt *p_ptt, struct qed_vf_info *vf)
650{
dacd88d6
YM
651 int i;
652
653 /* Set VF masks and configuration - pretend */
654 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
655
656 qed_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
657
dacd88d6
YM
658 /* unpretend */
659 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
660
661 /* iterate over all queues, clear sb consumer */
b2b897eb
YM
662 for (i = 0; i < vf->num_sbs; i++)
663 qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
664 vf->igu_sbs[i],
665 vf->opaque_fid, true);
dacd88d6
YM
666}
667
0b55e27d
YM
668static void qed_iov_vf_igu_set_int(struct qed_hwfn *p_hwfn,
669 struct qed_ptt *p_ptt,
670 struct qed_vf_info *vf, bool enable)
671{
672 u32 igu_vf_conf;
673
674 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
675
676 igu_vf_conf = qed_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
677
678 if (enable)
679 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
680 else
681 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
682
683 qed_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
684
685 /* unpretend */
686 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
687}
688
1408cc1f
YM
689static int qed_iov_enable_vf_access(struct qed_hwfn *p_hwfn,
690 struct qed_ptt *p_ptt,
691 struct qed_vf_info *vf)
692{
693 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
694 int rc;
695
4e9b2a67
MY
696 /* It's possible VF was previously considered malicious -
697 * clear the indication even if we're only going to disable VF.
698 */
699 vf->b_malicious = false;
700
0b55e27d
YM
701 if (vf->to_disable)
702 return 0;
703
1408cc1f
YM
704 DP_VERBOSE(p_hwfn,
705 QED_MSG_IOV,
706 "Enable internal access for vf %x [abs %x]\n",
707 vf->abs_vf_id, QED_VF_ABS_ID(p_hwfn, vf));
708
709 qed_iov_vf_pglue_clear_err(p_hwfn, p_ptt, QED_VF_ABS_ID(p_hwfn, vf));
710
b2b897eb
YM
711 qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
712
1408cc1f
YM
713 rc = qed_mcp_config_vf_msix(p_hwfn, p_ptt, vf->abs_vf_id, vf->num_sbs);
714 if (rc)
715 return rc;
716
717 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
718
719 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
720 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
721
722 qed_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
723 p_hwfn->hw_info.hw_mode);
724
725 /* unpretend */
726 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
727
1408cc1f
YM
728 vf->state = VF_FREE;
729
730 return rc;
731}
732
0b55e27d
YM
733/**
734 * @brief qed_iov_config_perm_table - configure the permission
735 * zone table.
736 * In E4, queue zone permission table size is 320x9. There
737 * are 320 VF queues for single engine device (256 for dual
738 * engine device), and each entry has the following format:
739 * {Valid, VF[7:0]}
740 * @param p_hwfn
741 * @param p_ptt
742 * @param vf
743 * @param enable
744 */
745static void qed_iov_config_perm_table(struct qed_hwfn *p_hwfn,
746 struct qed_ptt *p_ptt,
747 struct qed_vf_info *vf, u8 enable)
748{
749 u32 reg_addr, val;
750 u16 qzone_id = 0;
751 int qid;
752
753 for (qid = 0; qid < vf->num_rxqs; qid++) {
754 qed_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
755 &qzone_id);
756
757 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
1a635e48 758 val = enable ? (vf->abs_vf_id | BIT(8)) : 0;
0b55e27d
YM
759 qed_wr(p_hwfn, p_ptt, reg_addr, val);
760 }
761}
762
dacd88d6
YM
763static void qed_iov_enable_vf_traffic(struct qed_hwfn *p_hwfn,
764 struct qed_ptt *p_ptt,
765 struct qed_vf_info *vf)
766{
767 /* Reset vf in IGU - interrupts are still disabled */
768 qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
769
770 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
771
772 /* Permission Table */
773 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
774}
775
1408cc1f
YM
776static u8 qed_iov_alloc_vf_igu_sbs(struct qed_hwfn *p_hwfn,
777 struct qed_ptt *p_ptt,
778 struct qed_vf_info *vf, u16 num_rx_queues)
779{
780 struct qed_igu_block *igu_blocks;
781 int qid = 0, igu_id = 0;
782 u32 val = 0;
783
784 igu_blocks = p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks;
785
786 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->free_blks)
787 num_rx_queues = p_hwfn->hw_info.p_igu_info->free_blks;
788 p_hwfn->hw_info.p_igu_info->free_blks -= num_rx_queues;
789
790 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
791 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
792 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
793
794 while ((qid < num_rx_queues) &&
795 (igu_id < QED_MAPPING_MEMORY_SIZE(p_hwfn->cdev))) {
796 if (igu_blocks[igu_id].status & QED_IGU_STATUS_FREE) {
797 struct cau_sb_entry sb_entry;
798
799 vf->igu_sbs[qid] = (u16)igu_id;
800 igu_blocks[igu_id].status &= ~QED_IGU_STATUS_FREE;
801
802 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
803
804 qed_wr(p_hwfn, p_ptt,
805 IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id,
806 val);
807
808 /* Configure igu sb in CAU which were marked valid */
809 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
810 p_hwfn->rel_pf_id,
811 vf->abs_vf_id, 1);
812 qed_dmae_host2grc(p_hwfn, p_ptt,
813 (u64)(uintptr_t)&sb_entry,
814 CAU_REG_SB_VAR_MEMORY +
815 igu_id * sizeof(u64), 2, 0);
816 qid++;
817 }
818 igu_id++;
819 }
820
821 vf->num_sbs = (u8) num_rx_queues;
822
823 return vf->num_sbs;
824}
825
0b55e27d
YM
826static void qed_iov_free_vf_igu_sbs(struct qed_hwfn *p_hwfn,
827 struct qed_ptt *p_ptt,
828 struct qed_vf_info *vf)
829{
830 struct qed_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
831 int idx, igu_id;
832 u32 addr, val;
833
834 /* Invalidate igu CAM lines and mark them as free */
835 for (idx = 0; idx < vf->num_sbs; idx++) {
836 igu_id = vf->igu_sbs[idx];
837 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
838
839 val = qed_rd(p_hwfn, p_ptt, addr);
840 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
841 qed_wr(p_hwfn, p_ptt, addr, val);
842
843 p_info->igu_map.igu_blocks[igu_id].status |=
844 QED_IGU_STATUS_FREE;
845
846 p_hwfn->hw_info.p_igu_info->free_blks++;
847 }
848
849 vf->num_sbs = 0;
850}
851
33b2fbd0
MY
852static void qed_iov_set_link(struct qed_hwfn *p_hwfn,
853 u16 vfid,
854 struct qed_mcp_link_params *params,
855 struct qed_mcp_link_state *link,
856 struct qed_mcp_link_capabilities *p_caps)
857{
858 struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
859 vfid,
860 false);
861 struct qed_bulletin_content *p_bulletin;
862
863 if (!p_vf)
864 return;
865
866 p_bulletin = p_vf->bulletin.p_virt;
867 p_bulletin->req_autoneg = params->speed.autoneg;
868 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
869 p_bulletin->req_forced_speed = params->speed.forced_speed;
870 p_bulletin->req_autoneg_pause = params->pause.autoneg;
871 p_bulletin->req_forced_rx = params->pause.forced_rx;
872 p_bulletin->req_forced_tx = params->pause.forced_tx;
873 p_bulletin->req_loopback = params->loopback_mode;
874
875 p_bulletin->link_up = link->link_up;
876 p_bulletin->speed = link->speed;
877 p_bulletin->full_duplex = link->full_duplex;
878 p_bulletin->autoneg = link->an;
879 p_bulletin->autoneg_complete = link->an_complete;
880 p_bulletin->parallel_detection = link->parallel_detection;
881 p_bulletin->pfc_enabled = link->pfc_enabled;
882 p_bulletin->partner_adv_speed = link->partner_adv_speed;
883 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
884 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
885 p_bulletin->partner_adv_pause = link->partner_adv_pause;
886 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
887
888 p_bulletin->capability_speed = p_caps->speed_capabilities;
889}
890
1408cc1f
YM
891static int qed_iov_init_hw_for_vf(struct qed_hwfn *p_hwfn,
892 struct qed_ptt *p_ptt,
3da7a37a 893 struct qed_iov_vf_init_params *p_params)
1408cc1f 894{
33b2fbd0
MY
895 struct qed_mcp_link_capabilities link_caps;
896 struct qed_mcp_link_params link_params;
897 struct qed_mcp_link_state link_state;
1408cc1f
YM
898 u8 num_of_vf_avaiable_chains = 0;
899 struct qed_vf_info *vf = NULL;
3da7a37a 900 u16 qid, num_irqs;
1408cc1f
YM
901 int rc = 0;
902 u32 cids;
903 u8 i;
904
3da7a37a 905 vf = qed_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
1408cc1f
YM
906 if (!vf) {
907 DP_ERR(p_hwfn, "qed_iov_init_hw_for_vf : vf is NULL\n");
908 return -EINVAL;
909 }
910
911 if (vf->b_init) {
3da7a37a
MY
912 DP_NOTICE(p_hwfn, "VF[%d] is already active.\n",
913 p_params->rel_vf_id);
1408cc1f
YM
914 return -EINVAL;
915 }
916
3da7a37a
MY
917 /* Perform sanity checking on the requested queue_id */
918 for (i = 0; i < p_params->num_queues; i++) {
919 u16 min_vf_qzone = FEAT_NUM(p_hwfn, QED_PF_L2_QUE);
920 u16 max_vf_qzone = min_vf_qzone +
921 FEAT_NUM(p_hwfn, QED_VF_L2_QUE) - 1;
922
923 qid = p_params->req_rx_queue[i];
924 if (qid < min_vf_qzone || qid > max_vf_qzone) {
925 DP_NOTICE(p_hwfn,
926 "Can't enable Rx qid [%04x] for VF[%d]: qids [0x%04x,...,0x%04x] available\n",
927 qid,
928 p_params->rel_vf_id,
929 min_vf_qzone, max_vf_qzone);
930 return -EINVAL;
931 }
932
933 qid = p_params->req_tx_queue[i];
934 if (qid > max_vf_qzone) {
935 DP_NOTICE(p_hwfn,
936 "Can't enable Tx qid [%04x] for VF[%d]: max qid 0x%04x\n",
937 qid, p_params->rel_vf_id, max_vf_qzone);
938 return -EINVAL;
939 }
940
941 /* If client *really* wants, Tx qid can be shared with PF */
942 if (qid < min_vf_qzone)
943 DP_VERBOSE(p_hwfn,
944 QED_MSG_IOV,
945 "VF[%d] is using PF qid [0x%04x] for Txq[0x%02x]\n",
946 p_params->rel_vf_id, qid, i);
947 }
948
1408cc1f
YM
949 /* Limit number of queues according to number of CIDs */
950 qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
951 DP_VERBOSE(p_hwfn,
952 QED_MSG_IOV,
953 "VF[%d] - requesting to initialize for 0x%04x queues [0x%04x CIDs available]\n",
3da7a37a
MY
954 vf->relative_vf_id, p_params->num_queues, (u16)cids);
955 num_irqs = min_t(u16, p_params->num_queues, ((u16)cids));
1408cc1f
YM
956
957 num_of_vf_avaiable_chains = qed_iov_alloc_vf_igu_sbs(p_hwfn,
958 p_ptt,
3da7a37a 959 vf, num_irqs);
1408cc1f
YM
960 if (!num_of_vf_avaiable_chains) {
961 DP_ERR(p_hwfn, "no available igu sbs\n");
962 return -ENOMEM;
963 }
964
965 /* Choose queue number and index ranges */
966 vf->num_rxqs = num_of_vf_avaiable_chains;
967 vf->num_txqs = num_of_vf_avaiable_chains;
968
969 for (i = 0; i < vf->num_rxqs; i++) {
3da7a37a 970 struct qed_vf_q_info *p_queue = &vf->vf_queues[i];
1408cc1f 971
3da7a37a
MY
972 p_queue->fw_rx_qid = p_params->req_rx_queue[i];
973 p_queue->fw_tx_qid = p_params->req_tx_queue[i];
1408cc1f
YM
974
975 /* CIDs are per-VF, so no problem having them 0-based. */
3da7a37a 976 p_queue->fw_cid = i;
1408cc1f
YM
977
978 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3da7a37a
MY
979 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x] CID %04x\n",
980 vf->relative_vf_id,
981 i, vf->igu_sbs[i],
982 p_queue->fw_rx_qid,
983 p_queue->fw_tx_qid, p_queue->fw_cid);
1408cc1f 984 }
3da7a37a 985
33b2fbd0
MY
986 /* Update the link configuration in bulletin */
987 memcpy(&link_params, qed_mcp_get_link_params(p_hwfn),
988 sizeof(link_params));
989 memcpy(&link_state, qed_mcp_get_link_state(p_hwfn), sizeof(link_state));
990 memcpy(&link_caps, qed_mcp_get_link_capabilities(p_hwfn),
991 sizeof(link_caps));
992 qed_iov_set_link(p_hwfn, p_params->rel_vf_id,
993 &link_params, &link_state, &link_caps);
994
1408cc1f
YM
995 rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, vf);
996 if (!rc) {
997 vf->b_init = true;
998
999 if (IS_LEAD_HWFN(p_hwfn))
1000 p_hwfn->cdev->p_iov_info->num_vfs++;
1001 }
1002
1003 return rc;
1004}
1005
0b55e27d
YM
1006static int qed_iov_release_hw_for_vf(struct qed_hwfn *p_hwfn,
1007 struct qed_ptt *p_ptt, u16 rel_vf_id)
1008{
079d20a6
MC
1009 struct qed_mcp_link_capabilities caps;
1010 struct qed_mcp_link_params params;
1011 struct qed_mcp_link_state link;
0b55e27d 1012 struct qed_vf_info *vf = NULL;
0b55e27d
YM
1013
1014 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
1015 if (!vf) {
1016 DP_ERR(p_hwfn, "qed_iov_release_hw_for_vf : vf is NULL\n");
1017 return -EINVAL;
1018 }
1019
36558c3d
YM
1020 if (vf->bulletin.p_virt)
1021 memset(vf->bulletin.p_virt, 0, sizeof(*vf->bulletin.p_virt));
1022
1023 memset(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
1024
079d20a6
MC
1025 /* Get the link configuration back in bulletin so
1026 * that when VFs are re-enabled they get the actual
1027 * link configuration.
1028 */
1029 memcpy(&params, qed_mcp_get_link_params(p_hwfn), sizeof(params));
1030 memcpy(&link, qed_mcp_get_link_state(p_hwfn), sizeof(link));
1031 memcpy(&caps, qed_mcp_get_link_capabilities(p_hwfn), sizeof(caps));
1032 qed_iov_set_link(p_hwfn, rel_vf_id, &params, &link, &caps);
1033
1fe614d1
YM
1034 /* Forget the VF's acquisition message */
1035 memset(&vf->acquire, 0, sizeof(vf->acquire));
0b55e27d
YM
1036
1037 /* disablng interrupts and resetting permission table was done during
1038 * vf-close, however, we could get here without going through vf_close
1039 */
1040 /* Disable Interrupts for VF */
1041 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1042
1043 /* Reset Permission table */
1044 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1045
1046 vf->num_rxqs = 0;
1047 vf->num_txqs = 0;
1048 qed_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
1049
1050 if (vf->b_init) {
1051 vf->b_init = false;
1052
1053 if (IS_LEAD_HWFN(p_hwfn))
1054 p_hwfn->cdev->p_iov_info->num_vfs--;
1055 }
1056
1057 return 0;
1058}
1059
37bff2b9
YM
1060static bool qed_iov_tlv_supported(u16 tlvtype)
1061{
1062 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
1063}
1064
1065/* place a given tlv on the tlv buffer, continuing current tlv list */
1066void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length)
1067{
1068 struct channel_tlv *tl = (struct channel_tlv *)*offset;
1069
1070 tl->type = type;
1071 tl->length = length;
1072
1073 /* Offset should keep pointing to next TLV (the end of the last) */
1074 *offset += length;
1075
1076 /* Return a pointer to the start of the added tlv */
1077 return *offset - length;
1078}
1079
1080/* list the types and lengths of the tlvs on the buffer */
1081void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list)
1082{
1083 u16 i = 1, total_length = 0;
1084 struct channel_tlv *tlv;
1085
1086 do {
1087 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
1088
1089 /* output tlv */
1090 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1091 "TLV number %d: type %d, length %d\n",
1092 i, tlv->type, tlv->length);
1093
1094 if (tlv->type == CHANNEL_TLV_LIST_END)
1095 return;
1096
1097 /* Validate entry - protect against malicious VFs */
1098 if (!tlv->length) {
1099 DP_NOTICE(p_hwfn, "TLV of length 0 found\n");
1100 return;
1101 }
1102
1103 total_length += tlv->length;
1104
1105 if (total_length >= sizeof(struct tlv_buffer_size)) {
1106 DP_NOTICE(p_hwfn, "TLV ==> Buffer overflow\n");
1107 return;
1108 }
1109
1110 i++;
1111 } while (1);
1112}
1113
1114static void qed_iov_send_response(struct qed_hwfn *p_hwfn,
1115 struct qed_ptt *p_ptt,
1116 struct qed_vf_info *p_vf,
1117 u16 length, u8 status)
1118{
1119 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1120 struct qed_dmae_params params;
1121 u8 eng_vf_id;
1122
1123 mbx->reply_virt->default_resp.hdr.status = status;
1124
1125 qed_dp_tlv_list(p_hwfn, mbx->reply_virt);
1126
1127 eng_vf_id = p_vf->abs_vf_id;
1128
1129 memset(&params, 0, sizeof(struct qed_dmae_params));
1130 params.flags = QED_DMAE_FLAG_VF_DST;
1131 params.dst_vfid = eng_vf_id;
1132
1133 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1134 mbx->req_virt->first_tlv.reply_address +
1135 sizeof(u64),
1136 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1137 &params);
1138
1139 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1140 mbx->req_virt->first_tlv.reply_address,
1141 sizeof(u64) / 4, &params);
1142
1143 REG_WR(p_hwfn,
1144 GTT_BAR0_MAP_REG_USDM_RAM +
1145 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1146}
1147
dacd88d6
YM
1148static u16 qed_iov_vport_to_tlv(struct qed_hwfn *p_hwfn,
1149 enum qed_iov_vport_update_flag flag)
1150{
1151 switch (flag) {
1152 case QED_IOV_VP_UPDATE_ACTIVATE:
1153 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
17b235c1
YM
1154 case QED_IOV_VP_UPDATE_VLAN_STRIP:
1155 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1156 case QED_IOV_VP_UPDATE_TX_SWITCH:
1157 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
dacd88d6
YM
1158 case QED_IOV_VP_UPDATE_MCAST:
1159 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1160 case QED_IOV_VP_UPDATE_ACCEPT_PARAM:
1161 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1162 case QED_IOV_VP_UPDATE_RSS:
1163 return CHANNEL_TLV_VPORT_UPDATE_RSS;
17b235c1
YM
1164 case QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1165 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1166 case QED_IOV_VP_UPDATE_SGE_TPA:
1167 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
dacd88d6
YM
1168 default:
1169 return 0;
1170 }
1171}
1172
1173static u16 qed_iov_prep_vp_update_resp_tlvs(struct qed_hwfn *p_hwfn,
1174 struct qed_vf_info *p_vf,
1175 struct qed_iov_vf_mbx *p_mbx,
1176 u8 status,
1177 u16 tlvs_mask, u16 tlvs_accepted)
1178{
1179 struct pfvf_def_resp_tlv *resp;
1180 u16 size, total_len, i;
1181
1182 memset(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1183 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1184 size = sizeof(struct pfvf_def_resp_tlv);
1185 total_len = size;
1186
1187 qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1188
1189 /* Prepare response for all extended tlvs if they are found by PF */
1190 for (i = 0; i < QED_IOV_VP_UPDATE_MAX; i++) {
1a635e48 1191 if (!(tlvs_mask & BIT(i)))
dacd88d6
YM
1192 continue;
1193
1194 resp = qed_add_tlv(p_hwfn, &p_mbx->offset,
1195 qed_iov_vport_to_tlv(p_hwfn, i), size);
1196
1a635e48 1197 if (tlvs_accepted & BIT(i))
dacd88d6
YM
1198 resp->hdr.status = status;
1199 else
1200 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1201
1202 DP_VERBOSE(p_hwfn,
1203 QED_MSG_IOV,
1204 "VF[%d] - vport_update response: TLV %d, status %02x\n",
1205 p_vf->relative_vf_id,
1206 qed_iov_vport_to_tlv(p_hwfn, i), resp->hdr.status);
1207
1208 total_len += size;
1209 }
1210
1211 qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_LIST_END,
1212 sizeof(struct channel_list_end_tlv));
1213
1214 return total_len;
1215}
1216
37bff2b9
YM
1217static void qed_iov_prepare_resp(struct qed_hwfn *p_hwfn,
1218 struct qed_ptt *p_ptt,
1219 struct qed_vf_info *vf_info,
1220 u16 type, u16 length, u8 status)
1221{
1222 struct qed_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1223
1224 mbx->offset = (u8 *)mbx->reply_virt;
1225
1226 qed_add_tlv(p_hwfn, &mbx->offset, type, length);
1227 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1228 sizeof(struct channel_list_end_tlv));
1229
1230 qed_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1231}
1232
ba56947a
BX
1233static struct
1234qed_public_vf_info *qed_iov_get_public_vf_info(struct qed_hwfn *p_hwfn,
1235 u16 relative_vf_id,
1236 bool b_enabled_only)
0b55e27d
YM
1237{
1238 struct qed_vf_info *vf = NULL;
1239
1240 vf = qed_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1241 if (!vf)
1242 return NULL;
1243
1244 return &vf->p_vf_info;
1245}
1246
ba56947a 1247static void qed_iov_clean_vf(struct qed_hwfn *p_hwfn, u8 vfid)
0b55e27d
YM
1248{
1249 struct qed_public_vf_info *vf_info;
1250
1251 vf_info = qed_iov_get_public_vf_info(p_hwfn, vfid, false);
1252
1253 if (!vf_info)
1254 return;
1255
1256 /* Clear the VF mac */
0ee28e31 1257 eth_zero_addr(vf_info->mac);
f990c82c
MY
1258
1259 vf_info->rx_accept_mode = 0;
1260 vf_info->tx_accept_mode = 0;
0b55e27d
YM
1261}
1262
1263static void qed_iov_vf_cleanup(struct qed_hwfn *p_hwfn,
1264 struct qed_vf_info *p_vf)
1265{
1266 u32 i;
1267
1268 p_vf->vf_bulletin = 0;
dacd88d6 1269 p_vf->vport_instance = 0;
08feecd7 1270 p_vf->configured_features = 0;
0b55e27d
YM
1271
1272 /* If VF previously requested less resources, go back to default */
1273 p_vf->num_rxqs = p_vf->num_sbs;
1274 p_vf->num_txqs = p_vf->num_sbs;
1275
dacd88d6
YM
1276 p_vf->num_active_rxqs = 0;
1277
3da7a37a
MY
1278 for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++) {
1279 struct qed_vf_q_info *p_queue = &p_vf->vf_queues[i];
1280
1281 if (p_queue->p_rx_cid) {
1282 qed_eth_queue_cid_release(p_hwfn, p_queue->p_rx_cid);
1283 p_queue->p_rx_cid = NULL;
1284 }
1285
1286 if (p_queue->p_tx_cid) {
1287 qed_eth_queue_cid_release(p_hwfn, p_queue->p_tx_cid);
1288 p_queue->p_tx_cid = NULL;
1289 }
1290 }
0b55e27d 1291
08feecd7 1292 memset(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1fe614d1 1293 memset(&p_vf->acquire, 0, sizeof(p_vf->acquire));
0b55e27d
YM
1294 qed_iov_clean_vf(p_hwfn, p_vf->relative_vf_id);
1295}
1296
1cf2b1a9
YM
1297static u8 qed_iov_vf_mbx_acquire_resc(struct qed_hwfn *p_hwfn,
1298 struct qed_ptt *p_ptt,
1299 struct qed_vf_info *p_vf,
1300 struct vf_pf_resc_request *p_req,
1301 struct pf_vf_resc *p_resp)
1302{
1303 int i;
1304
1305 /* Queue related information */
1306 p_resp->num_rxqs = p_vf->num_rxqs;
1307 p_resp->num_txqs = p_vf->num_txqs;
1308 p_resp->num_sbs = p_vf->num_sbs;
1309
1310 for (i = 0; i < p_resp->num_sbs; i++) {
1311 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1312 p_resp->hw_sbs[i].sb_qid = 0;
1313 }
1314
1315 /* These fields are filled for backward compatibility.
1316 * Unused by modern vfs.
1317 */
1318 for (i = 0; i < p_resp->num_rxqs; i++) {
1319 qed_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1320 (u16 *)&p_resp->hw_qid[i]);
1321 p_resp->cid[i] = p_vf->vf_queues[i].fw_cid;
1322 }
1323
1324 /* Filter related information */
1325 p_resp->num_mac_filters = min_t(u8, p_vf->num_mac_filters,
1326 p_req->num_mac_filters);
1327 p_resp->num_vlan_filters = min_t(u8, p_vf->num_vlan_filters,
1328 p_req->num_vlan_filters);
1329
1330 /* This isn't really needed/enforced, but some legacy VFs might depend
1331 * on the correct filling of this field.
1332 */
1333 p_resp->num_mc_filters = QED_MAX_MC_ADDRS;
1334
1335 /* Validate sufficient resources for VF */
1336 if (p_resp->num_rxqs < p_req->num_rxqs ||
1337 p_resp->num_txqs < p_req->num_txqs ||
1338 p_resp->num_sbs < p_req->num_sbs ||
1339 p_resp->num_mac_filters < p_req->num_mac_filters ||
1340 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1341 p_resp->num_mc_filters < p_req->num_mc_filters) {
1342 DP_VERBOSE(p_hwfn,
1343 QED_MSG_IOV,
1344 "VF[%d] - Insufficient resources: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x]\n",
1345 p_vf->abs_vf_id,
1346 p_req->num_rxqs,
1347 p_resp->num_rxqs,
1348 p_req->num_rxqs,
1349 p_resp->num_txqs,
1350 p_req->num_sbs,
1351 p_resp->num_sbs,
1352 p_req->num_mac_filters,
1353 p_resp->num_mac_filters,
1354 p_req->num_vlan_filters,
1355 p_resp->num_vlan_filters,
1356 p_req->num_mc_filters, p_resp->num_mc_filters);
a044df83
YM
1357
1358 /* Some legacy OSes are incapable of correctly handling this
1359 * failure.
1360 */
1361 if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1362 ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
1363 (p_vf->acquire.vfdev_info.os_type ==
1364 VFPF_ACQUIRE_OS_WINDOWS))
1365 return PFVF_STATUS_SUCCESS;
1366
1cf2b1a9
YM
1367 return PFVF_STATUS_NO_RESOURCE;
1368 }
1369
1370 return PFVF_STATUS_SUCCESS;
1371}
1372
1373static void qed_iov_vf_mbx_acquire_stats(struct qed_hwfn *p_hwfn,
1374 struct pfvf_stats_info *p_stats)
1375{
1376 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1377 offsetof(struct mstorm_vf_zone,
1378 non_trigger.eth_queue_stat);
1379 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1380 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1381 offsetof(struct ustorm_vf_zone,
1382 non_trigger.eth_queue_stat);
1383 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1384 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1385 offsetof(struct pstorm_vf_zone,
1386 non_trigger.eth_queue_stat);
1387 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1388 p_stats->tstats.address = 0;
1389 p_stats->tstats.len = 0;
1390}
1391
1408cc1f
YM
1392static void qed_iov_vf_mbx_acquire(struct qed_hwfn *p_hwfn,
1393 struct qed_ptt *p_ptt,
1394 struct qed_vf_info *vf)
37bff2b9 1395{
1408cc1f
YM
1396 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1397 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1398 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1399 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1cf2b1a9 1400 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1408cc1f 1401 struct pf_vf_resc *resc = &resp->resc;
1fe614d1
YM
1402 int rc;
1403
1404 memset(resp, 0, sizeof(*resp));
1408cc1f 1405
05fafbfb
YM
1406 /* Write the PF version so that VF would know which version
1407 * is supported - might be later overriden. This guarantees that
1408 * VF could recognize legacy PF based on lack of versions in reply.
1409 */
1410 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1411 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1412
a044df83
YM
1413 if (vf->state != VF_FREE && vf->state != VF_STOPPED) {
1414 DP_VERBOSE(p_hwfn,
1415 QED_MSG_IOV,
1416 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1417 vf->abs_vf_id, vf->state);
1418 goto out;
1419 }
1420
1408cc1f 1421 /* Validate FW compatibility */
1fe614d1 1422 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
a044df83
YM
1423 if (req->vfdev_info.capabilities &
1424 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
1425 struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
1fe614d1 1426
a044df83
YM
1427 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1428 "VF[%d] is pre-fastpath HSI\n",
1429 vf->abs_vf_id);
1430 p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
1431 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
1432 } else {
1433 DP_INFO(p_hwfn,
1434 "VF[%d] needs fastpath HSI %02x.%02x, which is incompatible with loaded FW's faspath HSI %02x.%02x\n",
1435 vf->abs_vf_id,
1436 req->vfdev_info.eth_fp_hsi_major,
1437 req->vfdev_info.eth_fp_hsi_minor,
1438 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1439
1440 goto out;
1441 }
1408cc1f
YM
1442 }
1443
1444 /* On 100g PFs, prevent old VFs from loading */
1445 if ((p_hwfn->cdev->num_hwfns > 1) &&
1446 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1447 DP_INFO(p_hwfn,
1448 "VF[%d] is running an old driver that doesn't support 100g\n",
1449 vf->abs_vf_id);
1408cc1f
YM
1450 goto out;
1451 }
1452
1fe614d1
YM
1453 /* Store the acquire message */
1454 memcpy(&vf->acquire, req, sizeof(vf->acquire));
1408cc1f 1455
1408cc1f 1456 vf->opaque_fid = req->vfdev_info.opaque_fid;
1408cc1f
YM
1457
1458 vf->vf_bulletin = req->bulletin_addr;
1459 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1460 vf->bulletin.size : req->bulletin_size;
1461
1462 /* fill in pfdev info */
1463 pfdev_info->chip_num = p_hwfn->cdev->chip_num;
1464 pfdev_info->db_size = 0;
1465 pfdev_info->indices_per_sb = PIS_PER_SB;
1466
1467 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1468 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1469 if (p_hwfn->cdev->num_hwfns > 1)
1470 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1471
1cf2b1a9 1472 qed_iov_vf_mbx_acquire_stats(p_hwfn, &pfdev_info->stats_info);
1408cc1f
YM
1473
1474 memcpy(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr, ETH_ALEN);
1475
1476 pfdev_info->fw_major = FW_MAJOR_VERSION;
1477 pfdev_info->fw_minor = FW_MINOR_VERSION;
1478 pfdev_info->fw_rev = FW_REVISION_VERSION;
1479 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
a044df83
YM
1480
1481 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1482 * this field.
1483 */
1a635e48 1484 pfdev_info->minor_fp_hsi = min_t(u8, ETH_HSI_VER_MINOR,
1fe614d1 1485 req->vfdev_info.eth_fp_hsi_minor);
1408cc1f
YM
1486 pfdev_info->os_type = VFPF_ACQUIRE_OS_LINUX;
1487 qed_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver, NULL);
1488
1489 pfdev_info->dev_type = p_hwfn->cdev->type;
1490 pfdev_info->chip_rev = p_hwfn->cdev->chip_rev;
1491
1cf2b1a9
YM
1492 /* Fill resources available to VF; Make sure there are enough to
1493 * satisfy the VF's request.
1408cc1f 1494 */
1cf2b1a9
YM
1495 vfpf_status = qed_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1496 &req->resc_request, resc);
1497 if (vfpf_status != PFVF_STATUS_SUCCESS)
1498 goto out;
1408cc1f 1499
1fe614d1
YM
1500 /* Start the VF in FW */
1501 rc = qed_sp_vf_start(p_hwfn, vf);
1502 if (rc) {
1503 DP_NOTICE(p_hwfn, "Failed to start VF[%02x]\n", vf->abs_vf_id);
1504 vfpf_status = PFVF_STATUS_FAILURE;
1505 goto out;
1506 }
1507
1408cc1f
YM
1508 /* Fill agreed size of bulletin board in response */
1509 resp->bulletin_size = vf->bulletin.size;
36558c3d 1510 qed_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1408cc1f
YM
1511
1512 DP_VERBOSE(p_hwfn,
1513 QED_MSG_IOV,
1514 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%llx\n"
1515 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d\n",
1516 vf->abs_vf_id,
1517 resp->pfdev_info.chip_num,
1518 resp->pfdev_info.db_size,
1519 resp->pfdev_info.indices_per_sb,
1520 resp->pfdev_info.capabilities,
1521 resc->num_rxqs,
1522 resc->num_txqs,
1523 resc->num_sbs,
1524 resc->num_mac_filters,
1525 resc->num_vlan_filters);
1526 vf->state = VF_ACQUIRED;
1527
1528 /* Prepare Response */
1529out:
1530 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1531 sizeof(struct pfvf_acquire_resp_tlv), vfpf_status);
37bff2b9
YM
1532}
1533
6ddc7608
YM
1534static int __qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn,
1535 struct qed_vf_info *p_vf, bool val)
1536{
1537 struct qed_sp_vport_update_params params;
1538 int rc;
1539
1540 if (val == p_vf->spoof_chk) {
1541 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1542 "Spoofchk value[%d] is already configured\n", val);
1543 return 0;
1544 }
1545
1546 memset(&params, 0, sizeof(struct qed_sp_vport_update_params));
1547 params.opaque_fid = p_vf->opaque_fid;
1548 params.vport_id = p_vf->vport_id;
1549 params.update_anti_spoofing_en_flg = 1;
1550 params.anti_spoofing_en = val;
1551
1552 rc = qed_sp_vport_update(p_hwfn, &params, QED_SPQ_MODE_EBLOCK, NULL);
cb1fa088 1553 if (!rc) {
6ddc7608
YM
1554 p_vf->spoof_chk = val;
1555 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1556 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1557 "Spoofchk val[%d] configured\n", val);
1558 } else {
1559 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1560 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1561 val, p_vf->relative_vf_id);
1562 }
1563
1564 return rc;
1565}
1566
08feecd7
YM
1567static int qed_iov_reconfigure_unicast_vlan(struct qed_hwfn *p_hwfn,
1568 struct qed_vf_info *p_vf)
1569{
1570 struct qed_filter_ucast filter;
1571 int rc = 0;
1572 int i;
1573
1574 memset(&filter, 0, sizeof(filter));
1575 filter.is_rx_filter = 1;
1576 filter.is_tx_filter = 1;
1577 filter.vport_to_add_to = p_vf->vport_id;
1578 filter.opcode = QED_FILTER_ADD;
1579
1580 /* Reconfigure vlans */
1581 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1582 if (!p_vf->shadow_config.vlans[i].used)
1583 continue;
1584
1585 filter.type = QED_FILTER_VLAN;
1586 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1a635e48 1587 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
08feecd7
YM
1588 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1589 filter.vlan, p_vf->relative_vf_id);
1a635e48
YM
1590 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1591 &filter, QED_SPQ_MODE_CB, NULL);
08feecd7
YM
1592 if (rc) {
1593 DP_NOTICE(p_hwfn,
1594 "Failed to configure VLAN [%04x] to VF [%04x]\n",
1595 filter.vlan, p_vf->relative_vf_id);
1596 break;
1597 }
1598 }
1599
1600 return rc;
1601}
1602
1603static int
1604qed_iov_reconfigure_unicast_shadow(struct qed_hwfn *p_hwfn,
1605 struct qed_vf_info *p_vf, u64 events)
1606{
1607 int rc = 0;
1608
1a635e48 1609 if ((events & BIT(VLAN_ADDR_FORCED)) &&
08feecd7
YM
1610 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1611 rc = qed_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1612
1613 return rc;
1614}
1615
1616static int qed_iov_configure_vport_forced(struct qed_hwfn *p_hwfn,
1617 struct qed_vf_info *p_vf, u64 events)
1618{
1619 int rc = 0;
1620 struct qed_filter_ucast filter;
1621
1622 if (!p_vf->vport_instance)
1623 return -EINVAL;
1624
1a635e48 1625 if (events & BIT(MAC_ADDR_FORCED)) {
eff16960
YM
1626 /* Since there's no way [currently] of removing the MAC,
1627 * we can always assume this means we need to force it.
1628 */
1629 memset(&filter, 0, sizeof(filter));
1630 filter.type = QED_FILTER_MAC;
1631 filter.opcode = QED_FILTER_REPLACE;
1632 filter.is_rx_filter = 1;
1633 filter.is_tx_filter = 1;
1634 filter.vport_to_add_to = p_vf->vport_id;
1635 ether_addr_copy(filter.mac, p_vf->bulletin.p_virt->mac);
1636
1637 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1638 &filter, QED_SPQ_MODE_CB, NULL);
1639 if (rc) {
1640 DP_NOTICE(p_hwfn,
1641 "PF failed to configure MAC for VF\n");
1642 return rc;
1643 }
1644
1645 p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
1646 }
1647
1a635e48 1648 if (events & BIT(VLAN_ADDR_FORCED)) {
08feecd7
YM
1649 struct qed_sp_vport_update_params vport_update;
1650 u8 removal;
1651 int i;
1652
1653 memset(&filter, 0, sizeof(filter));
1654 filter.type = QED_FILTER_VLAN;
1655 filter.is_rx_filter = 1;
1656 filter.is_tx_filter = 1;
1657 filter.vport_to_add_to = p_vf->vport_id;
1658 filter.vlan = p_vf->bulletin.p_virt->pvid;
1659 filter.opcode = filter.vlan ? QED_FILTER_REPLACE :
1660 QED_FILTER_FLUSH;
1661
1662 /* Send the ramrod */
1663 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1664 &filter, QED_SPQ_MODE_CB, NULL);
1665 if (rc) {
1666 DP_NOTICE(p_hwfn,
1667 "PF failed to configure VLAN for VF\n");
1668 return rc;
1669 }
1670
1671 /* Update the default-vlan & silent vlan stripping */
1672 memset(&vport_update, 0, sizeof(vport_update));
1673 vport_update.opaque_fid = p_vf->opaque_fid;
1674 vport_update.vport_id = p_vf->vport_id;
1675 vport_update.update_default_vlan_enable_flg = 1;
1676 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
1677 vport_update.update_default_vlan_flg = 1;
1678 vport_update.default_vlan = filter.vlan;
1679
1680 vport_update.update_inner_vlan_removal_flg = 1;
1681 removal = filter.vlan ? 1
1682 : p_vf->shadow_config.inner_vlan_removal;
1683 vport_update.inner_vlan_removal_flg = removal;
1684 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
1685 rc = qed_sp_vport_update(p_hwfn,
1686 &vport_update,
1687 QED_SPQ_MODE_EBLOCK, NULL);
1688 if (rc) {
1689 DP_NOTICE(p_hwfn,
1690 "PF failed to configure VF vport for vlan\n");
1691 return rc;
1692 }
1693
1694 /* Update all the Rx queues */
1695 for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++) {
3da7a37a 1696 struct qed_queue_cid *p_cid;
08feecd7 1697
3da7a37a
MY
1698 p_cid = p_vf->vf_queues[i].p_rx_cid;
1699 if (!p_cid)
08feecd7
YM
1700 continue;
1701
3da7a37a
MY
1702 rc = qed_sp_eth_rx_queues_update(p_hwfn,
1703 (void **)&p_cid,
08feecd7
YM
1704 1, 0, 1,
1705 QED_SPQ_MODE_EBLOCK,
1706 NULL);
1707 if (rc) {
1708 DP_NOTICE(p_hwfn,
1709 "Failed to send Rx update fo queue[0x%04x]\n",
3da7a37a 1710 p_cid->rel.queue_id);
08feecd7
YM
1711 return rc;
1712 }
1713 }
1714
1715 if (filter.vlan)
1716 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
1717 else
1a635e48 1718 p_vf->configured_features &= ~BIT(VLAN_ADDR_FORCED);
08feecd7
YM
1719 }
1720
1721 /* If forced features are terminated, we need to configure the shadow
1722 * configuration back again.
1723 */
1724 if (events)
1725 qed_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
1726
1727 return rc;
1728}
1729
dacd88d6
YM
1730static void qed_iov_vf_mbx_start_vport(struct qed_hwfn *p_hwfn,
1731 struct qed_ptt *p_ptt,
1732 struct qed_vf_info *vf)
1733{
1734 struct qed_sp_vport_start_params params = { 0 };
1735 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1736 struct vfpf_vport_start_tlv *start;
1737 u8 status = PFVF_STATUS_SUCCESS;
1738 struct qed_vf_info *vf_info;
08feecd7 1739 u64 *p_bitmap;
dacd88d6
YM
1740 int sb_id;
1741 int rc;
1742
1743 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vf->relative_vf_id, true);
1744 if (!vf_info) {
1745 DP_NOTICE(p_hwfn->cdev,
1746 "Failed to get VF info, invalid vfid [%d]\n",
1747 vf->relative_vf_id);
1748 return;
1749 }
1750
1751 vf->state = VF_ENABLED;
1752 start = &mbx->req_virt->start_vport;
1753
1754 /* Initialize Status block in CAU */
1755 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
1756 if (!start->sb_addr[sb_id]) {
1757 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1758 "VF[%d] did not fill the address of SB %d\n",
1759 vf->relative_vf_id, sb_id);
1760 break;
1761 }
1762
1763 qed_int_cau_conf_sb(p_hwfn, p_ptt,
1764 start->sb_addr[sb_id],
1a635e48 1765 vf->igu_sbs[sb_id], vf->abs_vf_id, 1);
dacd88d6
YM
1766 }
1767 qed_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
1768
1769 vf->mtu = start->mtu;
08feecd7
YM
1770 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
1771
1772 /* Take into consideration configuration forced by hypervisor;
1773 * If none is configured, use the supplied VF values [for old
1774 * vfs that would still be fine, since they passed '0' as padding].
1775 */
1776 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
1a635e48 1777 if (!(*p_bitmap & BIT(VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
08feecd7
YM
1778 u8 vf_req = start->only_untagged;
1779
1780 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
1781 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
1782 }
dacd88d6
YM
1783
1784 params.tpa_mode = start->tpa_mode;
1785 params.remove_inner_vlan = start->inner_vlan_removal;
831bfb0e 1786 params.tx_switching = true;
dacd88d6 1787
08feecd7 1788 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
dacd88d6
YM
1789 params.drop_ttl0 = false;
1790 params.concrete_fid = vf->concrete_fid;
1791 params.opaque_fid = vf->opaque_fid;
1792 params.vport_id = vf->vport_id;
1793 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
1794 params.mtu = vf->mtu;
11a85d75 1795 params.check_mac = true;
dacd88d6
YM
1796
1797 rc = qed_sp_eth_vport_start(p_hwfn, &params);
1a635e48 1798 if (rc) {
dacd88d6
YM
1799 DP_ERR(p_hwfn,
1800 "qed_iov_vf_mbx_start_vport returned error %d\n", rc);
1801 status = PFVF_STATUS_FAILURE;
1802 } else {
1803 vf->vport_instance++;
08feecd7
YM
1804
1805 /* Force configuration if needed on the newly opened vport */
1806 qed_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
6ddc7608
YM
1807
1808 __qed_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
dacd88d6
YM
1809 }
1810 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
1811 sizeof(struct pfvf_def_resp_tlv), status);
1812}
1813
1814static void qed_iov_vf_mbx_stop_vport(struct qed_hwfn *p_hwfn,
1815 struct qed_ptt *p_ptt,
1816 struct qed_vf_info *vf)
1817{
1818 u8 status = PFVF_STATUS_SUCCESS;
1819 int rc;
1820
1821 vf->vport_instance--;
6ddc7608 1822 vf->spoof_chk = false;
dacd88d6
YM
1823
1824 rc = qed_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
1a635e48 1825 if (rc) {
dacd88d6
YM
1826 DP_ERR(p_hwfn, "qed_iov_vf_mbx_stop_vport returned error %d\n",
1827 rc);
1828 status = PFVF_STATUS_FAILURE;
1829 }
1830
08feecd7
YM
1831 /* Forget the configuration on the vport */
1832 vf->configured_features = 0;
1833 memset(&vf->shadow_config, 0, sizeof(vf->shadow_config));
1834
dacd88d6
YM
1835 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
1836 sizeof(struct pfvf_def_resp_tlv), status);
1837}
1838
dacd88d6
YM
1839static void qed_iov_vf_mbx_start_rxq_resp(struct qed_hwfn *p_hwfn,
1840 struct qed_ptt *p_ptt,
a044df83
YM
1841 struct qed_vf_info *vf,
1842 u8 status, bool b_legacy)
dacd88d6
YM
1843{
1844 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1845 struct pfvf_start_queue_resp_tlv *p_tlv;
1846 struct vfpf_start_rxq_tlv *req;
a044df83 1847 u16 length;
dacd88d6
YM
1848
1849 mbx->offset = (u8 *)mbx->reply_virt;
1850
a044df83
YM
1851 /* Taking a bigger struct instead of adding a TLV to list was a
1852 * mistake, but one which we're now stuck with, as some older
1853 * clients assume the size of the previous response.
1854 */
1855 if (!b_legacy)
1856 length = sizeof(*p_tlv);
1857 else
1858 length = sizeof(struct pfvf_def_resp_tlv);
1859
dacd88d6 1860 p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_RXQ,
a044df83 1861 length);
dacd88d6
YM
1862 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1863 sizeof(struct channel_list_end_tlv));
1864
1865 /* Update the TLV with the response */
a044df83 1866 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
dacd88d6 1867 req = &mbx->req_virt->start_rxq;
351a4ded
YM
1868 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
1869 offsetof(struct mstorm_vf_zone,
1870 non_trigger.eth_rx_queue_producers) +
1871 sizeof(struct eth_rx_prod_data) * req->rx_qid;
dacd88d6
YM
1872 }
1873
a044df83 1874 qed_iov_send_response(p_hwfn, p_ptt, vf, length, status);
dacd88d6
YM
1875}
1876
1877static void qed_iov_vf_mbx_start_rxq(struct qed_hwfn *p_hwfn,
1878 struct qed_ptt *p_ptt,
1879 struct qed_vf_info *vf)
1880{
1881 struct qed_queue_start_common_params params;
1882 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
41086467 1883 u8 status = PFVF_STATUS_NO_RESOURCE;
3da7a37a 1884 struct qed_vf_q_info *p_queue;
dacd88d6 1885 struct vfpf_start_rxq_tlv *req;
a044df83 1886 bool b_legacy_vf = false;
dacd88d6
YM
1887 int rc;
1888
dacd88d6 1889 req = &mbx->req_virt->start_rxq;
41086467
YM
1890
1891 if (!qed_iov_validate_rxq(p_hwfn, vf, req->rx_qid) ||
1892 !qed_iov_validate_sb(p_hwfn, vf, req->hw_sb))
1893 goto out;
1894
3da7a37a
MY
1895 /* Acquire a new queue-cid */
1896 p_queue = &vf->vf_queues[req->rx_qid];
1897
1898 memset(&params, 0, sizeof(params));
1899 params.queue_id = p_queue->fw_rx_qid;
dacd88d6 1900 params.vport_id = vf->vport_id;
3da7a37a 1901 params.stats_id = vf->abs_vf_id + 0x10;
dacd88d6
YM
1902 params.sb = req->hw_sb;
1903 params.sb_idx = req->sb_index;
1904
3da7a37a
MY
1905 p_queue->p_rx_cid = _qed_eth_queue_to_cid(p_hwfn,
1906 vf->opaque_fid,
1907 p_queue->fw_cid,
1908 req->rx_qid, &params);
1909 if (!p_queue->p_rx_cid)
1910 goto out;
1911
a044df83
YM
1912 /* Legacy VFs have their Producers in a different location, which they
1913 * calculate on their own and clean the producer prior to this.
1914 */
1915 if (vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1916 ETH_HSI_VER_NO_PKT_LEN_TUNN) {
1917 b_legacy_vf = true;
1918 } else {
1919 REG_WR(p_hwfn,
1920 GTT_BAR0_MAP_REG_MSDM_RAM +
1921 MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id, req->rx_qid),
1922 0);
1923 }
3da7a37a 1924 p_queue->p_rx_cid->b_legacy_vf = b_legacy_vf;
a044df83 1925
3da7a37a
MY
1926 rc = qed_eth_rxq_start_ramrod(p_hwfn,
1927 p_queue->p_rx_cid,
1928 req->bd_max_bytes,
1929 req->rxq_addr,
1930 req->cqe_pbl_addr, req->cqe_pbl_size);
dacd88d6
YM
1931 if (rc) {
1932 status = PFVF_STATUS_FAILURE;
3da7a37a
MY
1933 qed_eth_queue_cid_release(p_hwfn, p_queue->p_rx_cid);
1934 p_queue->p_rx_cid = NULL;
dacd88d6 1935 } else {
41086467 1936 status = PFVF_STATUS_SUCCESS;
dacd88d6
YM
1937 vf->num_active_rxqs++;
1938 }
1939
41086467 1940out:
a044df83 1941 qed_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status, b_legacy_vf);
dacd88d6
YM
1942}
1943
5040acf5
YM
1944static void qed_iov_vf_mbx_start_txq_resp(struct qed_hwfn *p_hwfn,
1945 struct qed_ptt *p_ptt,
1946 struct qed_vf_info *p_vf, u8 status)
1947{
1948 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1949 struct pfvf_start_queue_resp_tlv *p_tlv;
a044df83
YM
1950 bool b_legacy = false;
1951 u16 length;
5040acf5
YM
1952
1953 mbx->offset = (u8 *)mbx->reply_virt;
1954
a044df83
YM
1955 /* Taking a bigger struct instead of adding a TLV to list was a
1956 * mistake, but one which we're now stuck with, as some older
1957 * clients assume the size of the previous response.
1958 */
1959 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1960 ETH_HSI_VER_NO_PKT_LEN_TUNN)
1961 b_legacy = true;
1962
1963 if (!b_legacy)
1964 length = sizeof(*p_tlv);
1965 else
1966 length = sizeof(struct pfvf_def_resp_tlv);
1967
5040acf5 1968 p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_TXQ,
a044df83 1969 length);
5040acf5
YM
1970 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1971 sizeof(struct channel_list_end_tlv));
1972
1973 /* Update the TLV with the response */
a044df83 1974 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
5040acf5
YM
1975 u16 qid = mbx->req_virt->start_txq.tx_qid;
1976
51ff1725
RA
1977 p_tlv->offset = qed_db_addr_vf(p_vf->vf_queues[qid].fw_cid,
1978 DQ_DEMS_LEGACY);
5040acf5
YM
1979 }
1980
a044df83 1981 qed_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
5040acf5
YM
1982}
1983
dacd88d6
YM
1984static void qed_iov_vf_mbx_start_txq(struct qed_hwfn *p_hwfn,
1985 struct qed_ptt *p_ptt,
1986 struct qed_vf_info *vf)
1987{
dacd88d6
YM
1988 struct qed_queue_start_common_params params;
1989 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
41086467 1990 u8 status = PFVF_STATUS_NO_RESOURCE;
dacd88d6 1991 union qed_qm_pq_params pq_params;
dacd88d6 1992 struct vfpf_start_txq_tlv *req;
3da7a37a 1993 struct qed_vf_q_info *p_queue;
dacd88d6 1994 int rc;
3da7a37a 1995 u16 pq;
dacd88d6
YM
1996
1997 /* Prepare the parameters which would choose the right PQ */
1998 memset(&pq_params, 0, sizeof(pq_params));
1999 pq_params.eth.is_vf = 1;
2000 pq_params.eth.vf_id = vf->relative_vf_id;
2001
2002 memset(&params, 0, sizeof(params));
2003 req = &mbx->req_virt->start_txq;
41086467
YM
2004
2005 if (!qed_iov_validate_txq(p_hwfn, vf, req->tx_qid) ||
2006 !qed_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2007 goto out;
2008
3da7a37a
MY
2009 /* Acquire a new queue-cid */
2010 p_queue = &vf->vf_queues[req->tx_qid];
2011
2012 params.queue_id = p_queue->fw_tx_qid;
dacd88d6 2013 params.vport_id = vf->vport_id;
3da7a37a 2014 params.stats_id = vf->abs_vf_id + 0x10;
dacd88d6
YM
2015 params.sb = req->hw_sb;
2016 params.sb_idx = req->sb_index;
2017
3da7a37a
MY
2018 p_queue->p_tx_cid = _qed_eth_queue_to_cid(p_hwfn,
2019 vf->opaque_fid,
2020 p_queue->fw_cid,
2021 req->tx_qid, &params);
2022 if (!p_queue->p_tx_cid)
2023 goto out;
dacd88d6 2024
3da7a37a
MY
2025 pq = qed_get_qm_pq(p_hwfn, PROTOCOLID_ETH, &pq_params);
2026 rc = qed_eth_txq_start_ramrod(p_hwfn, p_queue->p_tx_cid,
2027 req->pbl_addr, req->pbl_size, pq);
41086467 2028 if (rc) {
dacd88d6 2029 status = PFVF_STATUS_FAILURE;
3da7a37a
MY
2030 qed_eth_queue_cid_release(p_hwfn, p_queue->p_tx_cid);
2031 p_queue->p_tx_cid = NULL;
41086467
YM
2032 } else {
2033 status = PFVF_STATUS_SUCCESS;
41086467 2034 }
dacd88d6 2035
41086467 2036out:
5040acf5 2037 qed_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf, status);
dacd88d6
YM
2038}
2039
2040static int qed_iov_vf_stop_rxqs(struct qed_hwfn *p_hwfn,
2041 struct qed_vf_info *vf,
2042 u16 rxq_id, u8 num_rxqs, bool cqe_completion)
2043{
3da7a37a 2044 struct qed_vf_q_info *p_queue;
dacd88d6
YM
2045 int rc = 0;
2046 int qid;
2047
2048 if (rxq_id + num_rxqs > ARRAY_SIZE(vf->vf_queues))
2049 return -EINVAL;
2050
2051 for (qid = rxq_id; qid < rxq_id + num_rxqs; qid++) {
3da7a37a 2052 p_queue = &vf->vf_queues[qid];
dacd88d6 2053
3da7a37a
MY
2054 if (!p_queue->p_rx_cid)
2055 continue;
2056
2057 rc = qed_eth_rx_queue_stop(p_hwfn,
2058 p_queue->p_rx_cid,
2059 false, cqe_completion);
2060 if (rc)
2061 return rc;
2062
2063 vf->vf_queues[qid].p_rx_cid = NULL;
dacd88d6
YM
2064 vf->num_active_rxqs--;
2065 }
2066
2067 return rc;
2068}
2069
2070static int qed_iov_vf_stop_txqs(struct qed_hwfn *p_hwfn,
2071 struct qed_vf_info *vf, u16 txq_id, u8 num_txqs)
2072{
2073 int rc = 0;
3da7a37a 2074 struct qed_vf_q_info *p_queue;
dacd88d6
YM
2075 int qid;
2076
2077 if (txq_id + num_txqs > ARRAY_SIZE(vf->vf_queues))
2078 return -EINVAL;
2079
2080 for (qid = txq_id; qid < txq_id + num_txqs; qid++) {
3da7a37a
MY
2081 p_queue = &vf->vf_queues[qid];
2082 if (!p_queue->p_tx_cid)
2083 continue;
dacd88d6 2084
3da7a37a
MY
2085 rc = qed_eth_tx_queue_stop(p_hwfn, p_queue->p_tx_cid);
2086 if (rc)
2087 return rc;
2088
2089 p_queue->p_tx_cid = NULL;
dacd88d6 2090 }
3da7a37a 2091
dacd88d6
YM
2092 return rc;
2093}
2094
2095static void qed_iov_vf_mbx_stop_rxqs(struct qed_hwfn *p_hwfn,
2096 struct qed_ptt *p_ptt,
2097 struct qed_vf_info *vf)
2098{
2099 u16 length = sizeof(struct pfvf_def_resp_tlv);
2100 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2101 u8 status = PFVF_STATUS_SUCCESS;
2102 struct vfpf_stop_rxqs_tlv *req;
2103 int rc;
2104
2105 /* We give the option of starting from qid != 0, in this case we
2106 * need to make sure that qid + num_qs doesn't exceed the actual
2107 * amount of queues that exist.
2108 */
2109 req = &mbx->req_virt->stop_rxqs;
2110 rc = qed_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
2111 req->num_rxqs, req->cqe_completion);
2112 if (rc)
2113 status = PFVF_STATUS_FAILURE;
2114
2115 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
2116 length, status);
2117}
2118
2119static void qed_iov_vf_mbx_stop_txqs(struct qed_hwfn *p_hwfn,
2120 struct qed_ptt *p_ptt,
2121 struct qed_vf_info *vf)
2122{
2123 u16 length = sizeof(struct pfvf_def_resp_tlv);
2124 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2125 u8 status = PFVF_STATUS_SUCCESS;
2126 struct vfpf_stop_txqs_tlv *req;
2127 int rc;
2128
2129 /* We give the option of starting from qid != 0, in this case we
2130 * need to make sure that qid + num_qs doesn't exceed the actual
2131 * amount of queues that exist.
2132 */
2133 req = &mbx->req_virt->stop_txqs;
2134 rc = qed_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid, req->num_txqs);
2135 if (rc)
2136 status = PFVF_STATUS_FAILURE;
2137
2138 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
2139 length, status);
2140}
2141
17b235c1
YM
2142static void qed_iov_vf_mbx_update_rxqs(struct qed_hwfn *p_hwfn,
2143 struct qed_ptt *p_ptt,
2144 struct qed_vf_info *vf)
2145{
3da7a37a 2146 struct qed_queue_cid *handlers[QED_MAX_VF_CHAINS_PER_PF];
17b235c1
YM
2147 u16 length = sizeof(struct pfvf_def_resp_tlv);
2148 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2149 struct vfpf_update_rxq_tlv *req;
3da7a37a 2150 u8 status = PFVF_STATUS_FAILURE;
17b235c1
YM
2151 u8 complete_event_flg;
2152 u8 complete_cqe_flg;
2153 u16 qid;
2154 int rc;
2155 u8 i;
2156
2157 req = &mbx->req_virt->update_rxq;
2158 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
2159 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
2160
3da7a37a
MY
2161 /* Validate inputs */
2162 if (req->num_rxqs + req->rx_qid > QED_MAX_VF_CHAINS_PER_PF ||
2163 !qed_iov_validate_rxq(p_hwfn, vf, req->rx_qid)) {
2164 DP_INFO(p_hwfn, "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2165 vf->relative_vf_id, req->rx_qid, req->num_rxqs);
2166 goto out;
2167 }
2168
17b235c1
YM
2169 for (i = 0; i < req->num_rxqs; i++) {
2170 qid = req->rx_qid + i;
3da7a37a
MY
2171 if (!vf->vf_queues[qid].p_rx_cid) {
2172 DP_INFO(p_hwfn,
2173 "VF[%d] rx_qid = %d isn`t active!\n",
2174 vf->relative_vf_id, qid);
2175 goto out;
17b235c1
YM
2176 }
2177
3da7a37a 2178 handlers[i] = vf->vf_queues[qid].p_rx_cid;
17b235c1
YM
2179 }
2180
3da7a37a
MY
2181 rc = qed_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
2182 req->num_rxqs,
2183 complete_cqe_flg,
2184 complete_event_flg,
2185 QED_SPQ_MODE_EBLOCK, NULL);
2186 if (rc)
2187 goto out;
2188
2189 status = PFVF_STATUS_SUCCESS;
2190out:
17b235c1
YM
2191 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
2192 length, status);
2193}
2194
dacd88d6
YM
2195void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
2196 void *p_tlvs_list, u16 req_type)
2197{
2198 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
2199 int len = 0;
2200
2201 do {
2202 if (!p_tlv->length) {
2203 DP_NOTICE(p_hwfn, "Zero length TLV found\n");
2204 return NULL;
2205 }
2206
2207 if (p_tlv->type == req_type) {
2208 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2209 "Extended tlv type %d, length %d found\n",
2210 p_tlv->type, p_tlv->length);
2211 return p_tlv;
2212 }
2213
2214 len += p_tlv->length;
2215 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
2216
2217 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
2218 DP_NOTICE(p_hwfn, "TLVs has overrun the buffer size\n");
2219 return NULL;
2220 }
2221 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2222
2223 return NULL;
2224}
2225
2226static void
2227qed_iov_vp_update_act_param(struct qed_hwfn *p_hwfn,
2228 struct qed_sp_vport_update_params *p_data,
2229 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2230{
2231 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2232 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2233
2234 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2235 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2236 if (!p_act_tlv)
2237 return;
2238
2239 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2240 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2241 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
2242 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
2243 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACTIVATE;
2244}
2245
17b235c1
YM
2246static void
2247qed_iov_vp_update_vlan_param(struct qed_hwfn *p_hwfn,
2248 struct qed_sp_vport_update_params *p_data,
2249 struct qed_vf_info *p_vf,
2250 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2251{
2252 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
2253 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
2254
2255 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
2256 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2257 if (!p_vlan_tlv)
2258 return;
2259
08feecd7
YM
2260 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
2261
2262 /* Ignore the VF request if we're forcing a vlan */
1a635e48 2263 if (!(p_vf->configured_features & BIT(VLAN_ADDR_FORCED))) {
08feecd7
YM
2264 p_data->update_inner_vlan_removal_flg = 1;
2265 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
2266 }
17b235c1
YM
2267
2268 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_VLAN_STRIP;
2269}
2270
2271static void
2272qed_iov_vp_update_tx_switch(struct qed_hwfn *p_hwfn,
2273 struct qed_sp_vport_update_params *p_data,
2274 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2275{
2276 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
2277 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
2278
2279 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
2280 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2281 tlv);
2282 if (!p_tx_switch_tlv)
2283 return;
2284
2285 p_data->update_tx_switching_flg = 1;
2286 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
2287 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_TX_SWITCH;
2288}
2289
dacd88d6
YM
2290static void
2291qed_iov_vp_update_mcast_bin_param(struct qed_hwfn *p_hwfn,
2292 struct qed_sp_vport_update_params *p_data,
2293 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2294{
2295 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
2296 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
2297
2298 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
2299 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2300 if (!p_mcast_tlv)
2301 return;
2302
2303 p_data->update_approx_mcast_flg = 1;
2304 memcpy(p_data->bins, p_mcast_tlv->bins,
2305 sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS);
2306 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_MCAST;
2307}
2308
2309static void
2310qed_iov_vp_update_accept_flag(struct qed_hwfn *p_hwfn,
2311 struct qed_sp_vport_update_params *p_data,
2312 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2313{
2314 struct qed_filter_accept_flags *p_flags = &p_data->accept_flags;
2315 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
2316 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
2317
2318 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
2319 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2320 if (!p_accept_tlv)
2321 return;
2322
2323 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
2324 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
2325 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
2326 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
2327 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_PARAM;
2328}
2329
17b235c1
YM
2330static void
2331qed_iov_vp_update_accept_any_vlan(struct qed_hwfn *p_hwfn,
2332 struct qed_sp_vport_update_params *p_data,
2333 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2334{
2335 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
2336 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
2337
2338 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
2339 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2340 tlv);
2341 if (!p_accept_any_vlan)
2342 return;
2343
2344 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
2345 p_data->update_accept_any_vlan_flg =
2346 p_accept_any_vlan->update_accept_any_vlan_flg;
2347 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
2348}
2349
dacd88d6
YM
2350static void
2351qed_iov_vp_update_rss_param(struct qed_hwfn *p_hwfn,
2352 struct qed_vf_info *vf,
2353 struct qed_sp_vport_update_params *p_data,
2354 struct qed_rss_params *p_rss,
f29ffdb6
MY
2355 struct qed_iov_vf_mbx *p_mbx,
2356 u16 *tlvs_mask, u16 *tlvs_accepted)
dacd88d6
YM
2357{
2358 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
2359 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
f29ffdb6 2360 bool b_reject = false;
dacd88d6 2361 u16 table_size;
f29ffdb6 2362 u16 i, q_idx;
dacd88d6
YM
2363
2364 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
2365 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2366 if (!p_rss_tlv) {
2367 p_data->rss_params = NULL;
2368 return;
2369 }
2370
2371 memset(p_rss, 0, sizeof(struct qed_rss_params));
2372
2373 p_rss->update_rss_config = !!(p_rss_tlv->update_rss_flags &
2374 VFPF_UPDATE_RSS_CONFIG_FLAG);
2375 p_rss->update_rss_capabilities = !!(p_rss_tlv->update_rss_flags &
2376 VFPF_UPDATE_RSS_CAPS_FLAG);
2377 p_rss->update_rss_ind_table = !!(p_rss_tlv->update_rss_flags &
2378 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
2379 p_rss->update_rss_key = !!(p_rss_tlv->update_rss_flags &
2380 VFPF_UPDATE_RSS_KEY_FLAG);
2381
2382 p_rss->rss_enable = p_rss_tlv->rss_enable;
2383 p_rss->rss_eng_id = vf->relative_vf_id + 1;
2384 p_rss->rss_caps = p_rss_tlv->rss_caps;
2385 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
dacd88d6
YM
2386 memcpy(p_rss->rss_key, p_rss_tlv->rss_key, sizeof(p_rss->rss_key));
2387
2388 table_size = min_t(u16, ARRAY_SIZE(p_rss->rss_ind_table),
2389 (1 << p_rss_tlv->rss_table_size_log));
2390
dacd88d6 2391 for (i = 0; i < table_size; i++) {
f29ffdb6
MY
2392 q_idx = p_rss_tlv->rss_ind_table[i];
2393 if (!qed_iov_validate_rxq(p_hwfn, vf, q_idx)) {
2394 DP_VERBOSE(p_hwfn,
2395 QED_MSG_IOV,
2396 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
2397 vf->relative_vf_id, q_idx);
2398 b_reject = true;
2399 goto out;
2400 }
dacd88d6 2401
f29ffdb6
MY
2402 if (!vf->vf_queues[q_idx].p_rx_cid) {
2403 DP_VERBOSE(p_hwfn,
2404 QED_MSG_IOV,
2405 "VF[%d]: Omitting RSS due to inactive queue %08x\n",
2406 vf->relative_vf_id, q_idx);
2407 b_reject = true;
2408 goto out;
2409 }
2410
2411 p_rss->rss_ind_table[i] = vf->vf_queues[q_idx].p_rx_cid;
dacd88d6
YM
2412 }
2413
2414 p_data->rss_params = p_rss;
f29ffdb6 2415out:
dacd88d6 2416 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_RSS;
f29ffdb6
MY
2417 if (!b_reject)
2418 *tlvs_accepted |= 1 << QED_IOV_VP_UPDATE_RSS;
dacd88d6
YM
2419}
2420
17b235c1
YM
2421static void
2422qed_iov_vp_update_sge_tpa_param(struct qed_hwfn *p_hwfn,
2423 struct qed_vf_info *vf,
2424 struct qed_sp_vport_update_params *p_data,
2425 struct qed_sge_tpa_params *p_sge_tpa,
2426 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2427{
2428 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
2429 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
2430
2431 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
2432 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2433
2434 if (!p_sge_tpa_tlv) {
2435 p_data->sge_tpa_params = NULL;
2436 return;
2437 }
2438
2439 memset(p_sge_tpa, 0, sizeof(struct qed_sge_tpa_params));
2440
2441 p_sge_tpa->update_tpa_en_flg =
2442 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
2443 p_sge_tpa->update_tpa_param_flg =
2444 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
2445 VFPF_UPDATE_TPA_PARAM_FLAG);
2446
2447 p_sge_tpa->tpa_ipv4_en_flg =
2448 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
2449 p_sge_tpa->tpa_ipv6_en_flg =
2450 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
2451 p_sge_tpa->tpa_pkt_split_flg =
2452 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
2453 p_sge_tpa->tpa_hdr_data_split_flg =
2454 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
2455 p_sge_tpa->tpa_gro_consistent_flg =
2456 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
2457
2458 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
2459 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
2460 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
2461 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
2462 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
2463
2464 p_data->sge_tpa_params = p_sge_tpa;
2465
2466 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_SGE_TPA;
2467}
2468
f990c82c
MY
2469static int qed_iov_pre_update_vport(struct qed_hwfn *hwfn,
2470 u8 vfid,
2471 struct qed_sp_vport_update_params *params,
2472 u16 *tlvs)
2473{
2474 u8 mask = QED_ACCEPT_UCAST_UNMATCHED | QED_ACCEPT_MCAST_UNMATCHED;
2475 struct qed_filter_accept_flags *flags = &params->accept_flags;
2476 struct qed_public_vf_info *vf_info;
2477
2478 /* Untrusted VFs can't even be trusted to know that fact.
2479 * Simply indicate everything is configured fine, and trace
2480 * configuration 'behind their back'.
2481 */
2482 if (!(*tlvs & BIT(QED_IOV_VP_UPDATE_ACCEPT_PARAM)))
2483 return 0;
2484
2485 vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
2486
2487 if (flags->update_rx_mode_config) {
2488 vf_info->rx_accept_mode = flags->rx_accept_filter;
2489 if (!vf_info->is_trusted_configured)
2490 flags->rx_accept_filter &= ~mask;
2491 }
2492
2493 if (flags->update_tx_mode_config) {
2494 vf_info->tx_accept_mode = flags->tx_accept_filter;
2495 if (!vf_info->is_trusted_configured)
2496 flags->tx_accept_filter &= ~mask;
2497 }
2498
2499 return 0;
2500}
2501
dacd88d6
YM
2502static void qed_iov_vf_mbx_vport_update(struct qed_hwfn *p_hwfn,
2503 struct qed_ptt *p_ptt,
2504 struct qed_vf_info *vf)
2505{
f29ffdb6 2506 struct qed_rss_params *p_rss_params = NULL;
dacd88d6
YM
2507 struct qed_sp_vport_update_params params;
2508 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
17b235c1 2509 struct qed_sge_tpa_params sge_tpa_params;
f29ffdb6 2510 u16 tlvs_mask = 0, tlvs_accepted = 0;
dacd88d6 2511 u8 status = PFVF_STATUS_SUCCESS;
dacd88d6
YM
2512 u16 length;
2513 int rc;
2514
41086467
YM
2515 /* Valiate PF can send such a request */
2516 if (!vf->vport_instance) {
2517 DP_VERBOSE(p_hwfn,
2518 QED_MSG_IOV,
2519 "No VPORT instance available for VF[%d], failing vport update\n",
2520 vf->abs_vf_id);
2521 status = PFVF_STATUS_FAILURE;
2522 goto out;
2523 }
f29ffdb6
MY
2524 p_rss_params = vzalloc(sizeof(*p_rss_params));
2525 if (p_rss_params == NULL) {
2526 status = PFVF_STATUS_FAILURE;
2527 goto out;
2528 }
41086467 2529
dacd88d6
YM
2530 memset(&params, 0, sizeof(params));
2531 params.opaque_fid = vf->opaque_fid;
2532 params.vport_id = vf->vport_id;
2533 params.rss_params = NULL;
2534
2535 /* Search for extended tlvs list and update values
2536 * from VF in struct qed_sp_vport_update_params.
2537 */
2538 qed_iov_vp_update_act_param(p_hwfn, &params, mbx, &tlvs_mask);
17b235c1
YM
2539 qed_iov_vp_update_vlan_param(p_hwfn, &params, vf, mbx, &tlvs_mask);
2540 qed_iov_vp_update_tx_switch(p_hwfn, &params, mbx, &tlvs_mask);
dacd88d6
YM
2541 qed_iov_vp_update_mcast_bin_param(p_hwfn, &params, mbx, &tlvs_mask);
2542 qed_iov_vp_update_accept_flag(p_hwfn, &params, mbx, &tlvs_mask);
17b235c1
YM
2543 qed_iov_vp_update_accept_any_vlan(p_hwfn, &params, mbx, &tlvs_mask);
2544 qed_iov_vp_update_sge_tpa_param(p_hwfn, vf, &params,
2545 &sge_tpa_params, mbx, &tlvs_mask);
dacd88d6 2546
f29ffdb6
MY
2547 tlvs_accepted = tlvs_mask;
2548
2549 /* Some of the extended TLVs need to be validated first; In that case,
2550 * they can update the mask without updating the accepted [so that
2551 * PF could communicate to VF it has rejected request].
dacd88d6 2552 */
f29ffdb6
MY
2553 qed_iov_vp_update_rss_param(p_hwfn, vf, &params, p_rss_params,
2554 mbx, &tlvs_mask, &tlvs_accepted);
2555
f990c82c
MY
2556 if (qed_iov_pre_update_vport(p_hwfn, vf->relative_vf_id,
2557 &params, &tlvs_accepted)) {
2558 tlvs_accepted = 0;
2559 status = PFVF_STATUS_NOT_SUPPORTED;
2560 goto out;
2561 }
2562
f29ffdb6
MY
2563 if (!tlvs_accepted) {
2564 if (tlvs_mask)
2565 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2566 "Upper-layer prevents VF vport configuration\n");
2567 else
2568 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2569 "No feature tlvs found for vport update\n");
dacd88d6
YM
2570 status = PFVF_STATUS_NOT_SUPPORTED;
2571 goto out;
2572 }
2573
2574 rc = qed_sp_vport_update(p_hwfn, &params, QED_SPQ_MODE_EBLOCK, NULL);
2575
2576 if (rc)
2577 status = PFVF_STATUS_FAILURE;
2578
2579out:
f29ffdb6 2580 vfree(p_rss_params);
dacd88d6 2581 length = qed_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
f29ffdb6 2582 tlvs_mask, tlvs_accepted);
dacd88d6
YM
2583 qed_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2584}
2585
8246d0b4
YM
2586static int qed_iov_vf_update_vlan_shadow(struct qed_hwfn *p_hwfn,
2587 struct qed_vf_info *p_vf,
2588 struct qed_filter_ucast *p_params)
08feecd7
YM
2589{
2590 int i;
2591
08feecd7
YM
2592 /* First remove entries and then add new ones */
2593 if (p_params->opcode == QED_FILTER_REMOVE) {
2594 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
2595 if (p_vf->shadow_config.vlans[i].used &&
2596 p_vf->shadow_config.vlans[i].vid ==
2597 p_params->vlan) {
2598 p_vf->shadow_config.vlans[i].used = false;
2599 break;
2600 }
2601 if (i == QED_ETH_VF_NUM_VLAN_FILTERS + 1) {
2602 DP_VERBOSE(p_hwfn,
2603 QED_MSG_IOV,
2604 "VF [%d] - Tries to remove a non-existing vlan\n",
2605 p_vf->relative_vf_id);
2606 return -EINVAL;
2607 }
2608 } else if (p_params->opcode == QED_FILTER_REPLACE ||
2609 p_params->opcode == QED_FILTER_FLUSH) {
2610 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
2611 p_vf->shadow_config.vlans[i].used = false;
2612 }
2613
2614 /* In forced mode, we're willing to remove entries - but we don't add
2615 * new ones.
2616 */
1a635e48 2617 if (p_vf->bulletin.p_virt->valid_bitmap & BIT(VLAN_ADDR_FORCED))
08feecd7
YM
2618 return 0;
2619
2620 if (p_params->opcode == QED_FILTER_ADD ||
2621 p_params->opcode == QED_FILTER_REPLACE) {
2622 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
2623 if (p_vf->shadow_config.vlans[i].used)
2624 continue;
2625
2626 p_vf->shadow_config.vlans[i].used = true;
2627 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
2628 break;
2629 }
2630
2631 if (i == QED_ETH_VF_NUM_VLAN_FILTERS + 1) {
2632 DP_VERBOSE(p_hwfn,
2633 QED_MSG_IOV,
2634 "VF [%d] - Tries to configure more than %d vlan filters\n",
2635 p_vf->relative_vf_id,
2636 QED_ETH_VF_NUM_VLAN_FILTERS + 1);
2637 return -EINVAL;
2638 }
2639 }
2640
2641 return 0;
2642}
2643
8246d0b4
YM
2644static int qed_iov_vf_update_mac_shadow(struct qed_hwfn *p_hwfn,
2645 struct qed_vf_info *p_vf,
2646 struct qed_filter_ucast *p_params)
2647{
2648 int i;
2649
2650 /* If we're in forced-mode, we don't allow any change */
1a635e48 2651 if (p_vf->bulletin.p_virt->valid_bitmap & BIT(MAC_ADDR_FORCED))
8246d0b4
YM
2652 return 0;
2653
2654 /* First remove entries and then add new ones */
2655 if (p_params->opcode == QED_FILTER_REMOVE) {
2656 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++) {
2657 if (ether_addr_equal(p_vf->shadow_config.macs[i],
2658 p_params->mac)) {
0ee28e31 2659 eth_zero_addr(p_vf->shadow_config.macs[i]);
8246d0b4
YM
2660 break;
2661 }
2662 }
2663
2664 if (i == QED_ETH_VF_NUM_MAC_FILTERS) {
2665 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2666 "MAC isn't configured\n");
2667 return -EINVAL;
2668 }
2669 } else if (p_params->opcode == QED_FILTER_REPLACE ||
2670 p_params->opcode == QED_FILTER_FLUSH) {
2671 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++)
0ee28e31 2672 eth_zero_addr(p_vf->shadow_config.macs[i]);
8246d0b4
YM
2673 }
2674
2675 /* List the new MAC address */
2676 if (p_params->opcode != QED_FILTER_ADD &&
2677 p_params->opcode != QED_FILTER_REPLACE)
2678 return 0;
2679
2680 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++) {
2681 if (is_zero_ether_addr(p_vf->shadow_config.macs[i])) {
2682 ether_addr_copy(p_vf->shadow_config.macs[i],
2683 p_params->mac);
2684 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2685 "Added MAC at %d entry in shadow\n", i);
2686 break;
2687 }
2688 }
2689
2690 if (i == QED_ETH_VF_NUM_MAC_FILTERS) {
2691 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "No available place for MAC\n");
2692 return -EINVAL;
2693 }
2694
2695 return 0;
2696}
2697
2698static int
2699qed_iov_vf_update_unicast_shadow(struct qed_hwfn *p_hwfn,
2700 struct qed_vf_info *p_vf,
2701 struct qed_filter_ucast *p_params)
2702{
2703 int rc = 0;
2704
2705 if (p_params->type == QED_FILTER_MAC) {
2706 rc = qed_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
2707 if (rc)
2708 return rc;
2709 }
2710
2711 if (p_params->type == QED_FILTER_VLAN)
2712 rc = qed_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
2713
2714 return rc;
2715}
2716
ba56947a
BX
2717static int qed_iov_chk_ucast(struct qed_hwfn *hwfn,
2718 int vfid, struct qed_filter_ucast *params)
dacd88d6
YM
2719{
2720 struct qed_public_vf_info *vf;
2721
2722 vf = qed_iov_get_public_vf_info(hwfn, vfid, true);
2723 if (!vf)
2724 return -EINVAL;
2725
2726 /* No real decision to make; Store the configured MAC */
2727 if (params->type == QED_FILTER_MAC ||
2728 params->type == QED_FILTER_MAC_VLAN)
2729 ether_addr_copy(vf->mac, params->mac);
2730
2731 return 0;
2732}
2733
2734static void qed_iov_vf_mbx_ucast_filter(struct qed_hwfn *p_hwfn,
2735 struct qed_ptt *p_ptt,
2736 struct qed_vf_info *vf)
2737{
08feecd7 2738 struct qed_bulletin_content *p_bulletin = vf->bulletin.p_virt;
dacd88d6
YM
2739 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2740 struct vfpf_ucast_filter_tlv *req;
2741 u8 status = PFVF_STATUS_SUCCESS;
2742 struct qed_filter_ucast params;
2743 int rc;
2744
2745 /* Prepare the unicast filter params */
2746 memset(&params, 0, sizeof(struct qed_filter_ucast));
2747 req = &mbx->req_virt->ucast_filter;
2748 params.opcode = (enum qed_filter_opcode)req->opcode;
2749 params.type = (enum qed_filter_ucast_type)req->type;
2750
2751 params.is_rx_filter = 1;
2752 params.is_tx_filter = 1;
2753 params.vport_to_remove_from = vf->vport_id;
2754 params.vport_to_add_to = vf->vport_id;
2755 memcpy(params.mac, req->mac, ETH_ALEN);
2756 params.vlan = req->vlan;
2757
2758 DP_VERBOSE(p_hwfn,
2759 QED_MSG_IOV,
2760 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x] MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
2761 vf->abs_vf_id, params.opcode, params.type,
2762 params.is_rx_filter ? "RX" : "",
2763 params.is_tx_filter ? "TX" : "",
2764 params.vport_to_add_to,
2765 params.mac[0], params.mac[1],
2766 params.mac[2], params.mac[3],
2767 params.mac[4], params.mac[5], params.vlan);
2768
2769 if (!vf->vport_instance) {
2770 DP_VERBOSE(p_hwfn,
2771 QED_MSG_IOV,
2772 "No VPORT instance available for VF[%d], failing ucast MAC configuration\n",
2773 vf->abs_vf_id);
2774 status = PFVF_STATUS_FAILURE;
2775 goto out;
2776 }
2777
08feecd7
YM
2778 /* Update shadow copy of the VF configuration */
2779 if (qed_iov_vf_update_unicast_shadow(p_hwfn, vf, &params)) {
2780 status = PFVF_STATUS_FAILURE;
2781 goto out;
2782 }
2783
2784 /* Determine if the unicast filtering is acceptible by PF */
1a635e48 2785 if ((p_bulletin->valid_bitmap & BIT(VLAN_ADDR_FORCED)) &&
08feecd7
YM
2786 (params.type == QED_FILTER_VLAN ||
2787 params.type == QED_FILTER_MAC_VLAN)) {
2788 /* Once VLAN is forced or PVID is set, do not allow
2789 * to add/replace any further VLANs.
2790 */
2791 if (params.opcode == QED_FILTER_ADD ||
2792 params.opcode == QED_FILTER_REPLACE)
2793 status = PFVF_STATUS_FORCED;
2794 goto out;
2795 }
2796
1a635e48 2797 if ((p_bulletin->valid_bitmap & BIT(MAC_ADDR_FORCED)) &&
eff16960
YM
2798 (params.type == QED_FILTER_MAC ||
2799 params.type == QED_FILTER_MAC_VLAN)) {
2800 if (!ether_addr_equal(p_bulletin->mac, params.mac) ||
2801 (params.opcode != QED_FILTER_ADD &&
2802 params.opcode != QED_FILTER_REPLACE))
2803 status = PFVF_STATUS_FORCED;
2804 goto out;
2805 }
2806
dacd88d6
YM
2807 rc = qed_iov_chk_ucast(p_hwfn, vf->relative_vf_id, &params);
2808 if (rc) {
2809 status = PFVF_STATUS_FAILURE;
2810 goto out;
2811 }
2812
2813 rc = qed_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, &params,
2814 QED_SPQ_MODE_CB, NULL);
2815 if (rc)
2816 status = PFVF_STATUS_FAILURE;
2817
2818out:
2819 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
2820 sizeof(struct pfvf_def_resp_tlv), status);
2821}
2822
0b55e27d
YM
2823static void qed_iov_vf_mbx_int_cleanup(struct qed_hwfn *p_hwfn,
2824 struct qed_ptt *p_ptt,
2825 struct qed_vf_info *vf)
2826{
2827 int i;
2828
2829 /* Reset the SBs */
2830 for (i = 0; i < vf->num_sbs; i++)
2831 qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
2832 vf->igu_sbs[i],
2833 vf->opaque_fid, false);
2834
2835 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
2836 sizeof(struct pfvf_def_resp_tlv),
2837 PFVF_STATUS_SUCCESS);
2838}
2839
2840static void qed_iov_vf_mbx_close(struct qed_hwfn *p_hwfn,
2841 struct qed_ptt *p_ptt, struct qed_vf_info *vf)
2842{
2843 u16 length = sizeof(struct pfvf_def_resp_tlv);
2844 u8 status = PFVF_STATUS_SUCCESS;
2845
2846 /* Disable Interrupts for VF */
2847 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
2848
2849 /* Reset Permission table */
2850 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
2851
2852 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
2853 length, status);
2854}
2855
2856static void qed_iov_vf_mbx_release(struct qed_hwfn *p_hwfn,
2857 struct qed_ptt *p_ptt,
2858 struct qed_vf_info *p_vf)
2859{
2860 u16 length = sizeof(struct pfvf_def_resp_tlv);
1fe614d1
YM
2861 u8 status = PFVF_STATUS_SUCCESS;
2862 int rc = 0;
0b55e27d
YM
2863
2864 qed_iov_vf_cleanup(p_hwfn, p_vf);
2865
1fe614d1
YM
2866 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
2867 /* Stopping the VF */
2868 rc = qed_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
2869 p_vf->opaque_fid);
2870
2871 if (rc) {
2872 DP_ERR(p_hwfn, "qed_sp_vf_stop returned error %d\n",
2873 rc);
2874 status = PFVF_STATUS_FAILURE;
2875 }
2876
2877 p_vf->state = VF_STOPPED;
2878 }
2879
0b55e27d 2880 qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
1fe614d1 2881 length, status);
0b55e27d
YM
2882}
2883
2884static int
2885qed_iov_vf_flr_poll_dorq(struct qed_hwfn *p_hwfn,
2886 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
2887{
2888 int cnt;
2889 u32 val;
2890
2891 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_vf->concrete_fid);
2892
2893 for (cnt = 0; cnt < 50; cnt++) {
2894 val = qed_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
2895 if (!val)
2896 break;
2897 msleep(20);
2898 }
2899 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
2900
2901 if (cnt == 50) {
2902 DP_ERR(p_hwfn,
2903 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
2904 p_vf->abs_vf_id, val);
2905 return -EBUSY;
2906 }
2907
2908 return 0;
2909}
2910
2911static int
2912qed_iov_vf_flr_poll_pbf(struct qed_hwfn *p_hwfn,
2913 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
2914{
2915 u32 cons[MAX_NUM_VOQS], distance[MAX_NUM_VOQS];
2916 int i, cnt;
2917
2918 /* Read initial consumers & producers */
2919 for (i = 0; i < MAX_NUM_VOQS; i++) {
2920 u32 prod;
2921
2922 cons[i] = qed_rd(p_hwfn, p_ptt,
2923 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
2924 i * 0x40);
2925 prod = qed_rd(p_hwfn, p_ptt,
2926 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
2927 i * 0x40);
2928 distance[i] = prod - cons[i];
2929 }
2930
2931 /* Wait for consumers to pass the producers */
2932 i = 0;
2933 for (cnt = 0; cnt < 50; cnt++) {
2934 for (; i < MAX_NUM_VOQS; i++) {
2935 u32 tmp;
2936
2937 tmp = qed_rd(p_hwfn, p_ptt,
2938 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
2939 i * 0x40);
2940 if (distance[i] > tmp - cons[i])
2941 break;
2942 }
2943
2944 if (i == MAX_NUM_VOQS)
2945 break;
2946
2947 msleep(20);
2948 }
2949
2950 if (cnt == 50) {
2951 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
2952 p_vf->abs_vf_id, i);
2953 return -EBUSY;
2954 }
2955
2956 return 0;
2957}
2958
2959static int qed_iov_vf_flr_poll(struct qed_hwfn *p_hwfn,
2960 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
2961{
2962 int rc;
2963
2964 rc = qed_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
2965 if (rc)
2966 return rc;
2967
2968 rc = qed_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
2969 if (rc)
2970 return rc;
2971
2972 return 0;
2973}
2974
2975static int
2976qed_iov_execute_vf_flr_cleanup(struct qed_hwfn *p_hwfn,
2977 struct qed_ptt *p_ptt,
2978 u16 rel_vf_id, u32 *ack_vfs)
2979{
2980 struct qed_vf_info *p_vf;
2981 int rc = 0;
2982
2983 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
2984 if (!p_vf)
2985 return 0;
2986
2987 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
2988 (1ULL << (rel_vf_id % 64))) {
2989 u16 vfid = p_vf->abs_vf_id;
2990
2991 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2992 "VF[%d] - Handling FLR\n", vfid);
2993
2994 qed_iov_vf_cleanup(p_hwfn, p_vf);
2995
2996 /* If VF isn't active, no need for anything but SW */
2997 if (!p_vf->b_init)
2998 goto cleanup;
2999
3000 rc = qed_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
3001 if (rc)
3002 goto cleanup;
3003
3004 rc = qed_final_cleanup(p_hwfn, p_ptt, vfid, true);
3005 if (rc) {
3006 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
3007 return rc;
3008 }
3009
7eff82b0
YM
3010 /* Workaround to make VF-PF channel ready, as FW
3011 * doesn't do that as a part of FLR.
3012 */
3013 REG_WR(p_hwfn,
3014 GTT_BAR0_MAP_REG_USDM_RAM +
3015 USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid), 1);
3016
0b55e27d
YM
3017 /* VF_STOPPED has to be set only after final cleanup
3018 * but prior to re-enabling the VF.
3019 */
3020 p_vf->state = VF_STOPPED;
3021
3022 rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
3023 if (rc) {
3024 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
3025 vfid);
3026 return rc;
3027 }
3028cleanup:
3029 /* Mark VF for ack and clean pending state */
3030 if (p_vf->state == VF_RESET)
3031 p_vf->state = VF_STOPPED;
1a635e48 3032 ack_vfs[vfid / 32] |= BIT((vfid % 32));
0b55e27d
YM
3033 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
3034 ~(1ULL << (rel_vf_id % 64));
fd3c615a 3035 p_vf->vf_mbx.b_pending_msg = false;
0b55e27d
YM
3036 }
3037
3038 return rc;
3039}
3040
ba56947a
BX
3041static int
3042qed_iov_vf_flr_cleanup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
0b55e27d
YM
3043{
3044 u32 ack_vfs[VF_MAX_STATIC / 32];
3045 int rc = 0;
3046 u16 i;
3047
3048 memset(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3049
3050 /* Since BRB <-> PRS interface can't be tested as part of the flr
3051 * polling due to HW limitations, simply sleep a bit. And since
3052 * there's no need to wait per-vf, do it before looping.
3053 */
3054 msleep(100);
3055
3056 for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++)
3057 qed_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
3058
3059 rc = qed_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3060 return rc;
3061}
3062
3063int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *p_disabled_vfs)
3064{
3065 u16 i, found = 0;
3066
3067 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "Marking FLR-ed VFs\n");
3068 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
3069 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3070 "[%08x,...,%08x]: %08x\n",
3071 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
3072
3073 if (!p_hwfn->cdev->p_iov_info) {
3074 DP_NOTICE(p_hwfn, "VF flr but no IOV\n");
3075 return 0;
3076 }
3077
3078 /* Mark VFs */
3079 for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++) {
3080 struct qed_vf_info *p_vf;
3081 u8 vfid;
3082
3083 p_vf = qed_iov_get_vf_info(p_hwfn, i, false);
3084 if (!p_vf)
3085 continue;
3086
3087 vfid = p_vf->abs_vf_id;
1a635e48 3088 if (BIT((vfid % 32)) & p_disabled_vfs[vfid / 32]) {
0b55e27d
YM
3089 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
3090 u16 rel_vf_id = p_vf->relative_vf_id;
3091
3092 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3093 "VF[%d] [rel %d] got FLR-ed\n",
3094 vfid, rel_vf_id);
3095
3096 p_vf->state = VF_RESET;
3097
3098 /* No need to lock here, since pending_flr should
3099 * only change here and before ACKing MFw. Since
3100 * MFW will not trigger an additional attention for
3101 * VF flr until ACKs, we're safe.
3102 */
3103 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
3104 found = 1;
3105 }
3106 }
3107
3108 return found;
3109}
3110
73390ac9
YM
3111static void qed_iov_get_link(struct qed_hwfn *p_hwfn,
3112 u16 vfid,
3113 struct qed_mcp_link_params *p_params,
3114 struct qed_mcp_link_state *p_link,
3115 struct qed_mcp_link_capabilities *p_caps)
3116{
3117 struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
3118 vfid,
3119 false);
3120 struct qed_bulletin_content *p_bulletin;
3121
3122 if (!p_vf)
3123 return;
3124
3125 p_bulletin = p_vf->bulletin.p_virt;
3126
3127 if (p_params)
3128 __qed_vf_get_link_params(p_hwfn, p_params, p_bulletin);
3129 if (p_link)
3130 __qed_vf_get_link_state(p_hwfn, p_link, p_bulletin);
3131 if (p_caps)
3132 __qed_vf_get_link_caps(p_hwfn, p_caps, p_bulletin);
3133}
3134
37bff2b9
YM
3135static void qed_iov_process_mbx_req(struct qed_hwfn *p_hwfn,
3136 struct qed_ptt *p_ptt, int vfid)
3137{
3138 struct qed_iov_vf_mbx *mbx;
3139 struct qed_vf_info *p_vf;
37bff2b9
YM
3140
3141 p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3142 if (!p_vf)
3143 return;
3144
3145 mbx = &p_vf->vf_mbx;
3146
3147 /* qed_iov_process_mbx_request */
fd3c615a
MY
3148 if (!mbx->b_pending_msg) {
3149 DP_NOTICE(p_hwfn,
3150 "VF[%02x]: Trying to process mailbox message when none is pending\n",
3151 p_vf->abs_vf_id);
3152 return;
3153 }
3154 mbx->b_pending_msg = false;
37bff2b9
YM
3155
3156 mbx->first_tlv = mbx->req_virt->first_tlv;
3157
fd3c615a
MY
3158 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3159 "VF[%02x]: Processing mailbox message [type %04x]\n",
3160 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
3161
37bff2b9 3162 /* check if tlv type is known */
7eff82b0
YM
3163 if (qed_iov_tlv_supported(mbx->first_tlv.tl.type) &&
3164 !p_vf->b_malicious) {
1408cc1f
YM
3165 switch (mbx->first_tlv.tl.type) {
3166 case CHANNEL_TLV_ACQUIRE:
3167 qed_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
3168 break;
dacd88d6
YM
3169 case CHANNEL_TLV_VPORT_START:
3170 qed_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
3171 break;
3172 case CHANNEL_TLV_VPORT_TEARDOWN:
3173 qed_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
3174 break;
3175 case CHANNEL_TLV_START_RXQ:
3176 qed_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
3177 break;
3178 case CHANNEL_TLV_START_TXQ:
3179 qed_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
3180 break;
3181 case CHANNEL_TLV_STOP_RXQS:
3182 qed_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
3183 break;
3184 case CHANNEL_TLV_STOP_TXQS:
3185 qed_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
3186 break;
17b235c1
YM
3187 case CHANNEL_TLV_UPDATE_RXQ:
3188 qed_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
3189 break;
dacd88d6
YM
3190 case CHANNEL_TLV_VPORT_UPDATE:
3191 qed_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
3192 break;
3193 case CHANNEL_TLV_UCAST_FILTER:
3194 qed_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
3195 break;
0b55e27d
YM
3196 case CHANNEL_TLV_CLOSE:
3197 qed_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
3198 break;
3199 case CHANNEL_TLV_INT_CLEANUP:
3200 qed_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
3201 break;
3202 case CHANNEL_TLV_RELEASE:
3203 qed_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
3204 break;
1408cc1f 3205 }
7eff82b0
YM
3206 } else if (qed_iov_tlv_supported(mbx->first_tlv.tl.type)) {
3207 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3208 "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
3209 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
3210
3211 qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
3212 mbx->first_tlv.tl.type,
3213 sizeof(struct pfvf_def_resp_tlv),
3214 PFVF_STATUS_MALICIOUS);
37bff2b9
YM
3215 } else {
3216 /* unknown TLV - this may belong to a VF driver from the future
3217 * - a version written after this PF driver was written, which
3218 * supports features unknown as of yet. Too bad since we don't
3219 * support them. Or this may be because someone wrote a crappy
3220 * VF driver and is sending garbage over the channel.
3221 */
54fdd80f
YM
3222 DP_NOTICE(p_hwfn,
3223 "VF[%02x]: unknown TLV. type %04x length %04x padding %08x reply address %llu\n",
3224 p_vf->abs_vf_id,
3225 mbx->first_tlv.tl.type,
3226 mbx->first_tlv.tl.length,
3227 mbx->first_tlv.padding, mbx->first_tlv.reply_address);
3228
3229 /* Try replying in case reply address matches the acquisition's
3230 * posted address.
3231 */
3232 if (p_vf->acquire.first_tlv.reply_address &&
3233 (mbx->first_tlv.reply_address ==
3234 p_vf->acquire.first_tlv.reply_address)) {
3235 qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
3236 mbx->first_tlv.tl.type,
3237 sizeof(struct pfvf_def_resp_tlv),
3238 PFVF_STATUS_NOT_SUPPORTED);
3239 } else {
37bff2b9
YM
3240 DP_VERBOSE(p_hwfn,
3241 QED_MSG_IOV,
54fdd80f
YM
3242 "VF[%02x]: Can't respond to TLV - no valid reply address\n",
3243 p_vf->abs_vf_id);
37bff2b9
YM
3244 }
3245 }
3246}
3247
fd3c615a 3248void qed_iov_pf_get_pending_events(struct qed_hwfn *p_hwfn, u64 *events)
37bff2b9 3249{
fd3c615a 3250 int i;
37bff2b9 3251
fd3c615a 3252 memset(events, 0, sizeof(u64) * QED_VF_ARRAY_LENGTH);
37bff2b9 3253
fd3c615a
MY
3254 qed_for_each_vf(p_hwfn, i) {
3255 struct qed_vf_info *p_vf;
37bff2b9 3256
fd3c615a
MY
3257 p_vf = &p_hwfn->pf_iov_info->vfs_array[i];
3258 if (p_vf->vf_mbx.b_pending_msg)
3259 events[i / 64] |= 1ULL << (i % 64);
3260 }
37bff2b9
YM
3261}
3262
7eff82b0
YM
3263static struct qed_vf_info *qed_sriov_get_vf_from_absid(struct qed_hwfn *p_hwfn,
3264 u16 abs_vfid)
37bff2b9 3265{
7eff82b0 3266 u8 min = (u8) p_hwfn->cdev->p_iov_info->first_vf_in_pf;
37bff2b9 3267
7eff82b0 3268 if (!_qed_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min, false)) {
37bff2b9
YM
3269 DP_VERBOSE(p_hwfn,
3270 QED_MSG_IOV,
7eff82b0 3271 "Got indication for VF [abs 0x%08x] that cannot be handled by PF\n",
37bff2b9 3272 abs_vfid);
7eff82b0 3273 return NULL;
37bff2b9 3274 }
7eff82b0
YM
3275
3276 return &p_hwfn->pf_iov_info->vfs_array[(u8) abs_vfid - min];
3277}
3278
3279static int qed_sriov_vfpf_msg(struct qed_hwfn *p_hwfn,
3280 u16 abs_vfid, struct regpair *vf_msg)
3281{
3282 struct qed_vf_info *p_vf = qed_sriov_get_vf_from_absid(p_hwfn,
3283 abs_vfid);
3284
3285 if (!p_vf)
3286 return 0;
37bff2b9
YM
3287
3288 /* List the physical address of the request so that handler
3289 * could later on copy the message from it.
3290 */
3291 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
3292
3293 /* Mark the event and schedule the workqueue */
fd3c615a 3294 p_vf->vf_mbx.b_pending_msg = true;
37bff2b9
YM
3295 qed_schedule_iov(p_hwfn, QED_IOV_WQ_MSG_FLAG);
3296
3297 return 0;
3298}
3299
7eff82b0
YM
3300static void qed_sriov_vfpf_malicious(struct qed_hwfn *p_hwfn,
3301 struct malicious_vf_eqe_data *p_data)
3302{
3303 struct qed_vf_info *p_vf;
3304
3305 p_vf = qed_sriov_get_vf_from_absid(p_hwfn, p_data->vf_id);
3306
3307 if (!p_vf)
3308 return;
3309
3310 DP_INFO(p_hwfn,
3311 "VF [%d] - Malicious behavior [%02x]\n",
3312 p_vf->abs_vf_id, p_data->err_id);
3313
3314 p_vf->b_malicious = true;
3315}
3316
37bff2b9
YM
3317int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
3318 u8 opcode, __le16 echo, union event_ring_data *data)
3319{
3320 switch (opcode) {
3321 case COMMON_EVENT_VF_PF_CHANNEL:
3322 return qed_sriov_vfpf_msg(p_hwfn, le16_to_cpu(echo),
3323 &data->vf_pf_channel.msg_addr);
7eff82b0
YM
3324 case COMMON_EVENT_MALICIOUS_VF:
3325 qed_sriov_vfpf_malicious(p_hwfn, &data->malicious_vf);
3326 return 0;
37bff2b9
YM
3327 default:
3328 DP_INFO(p_hwfn->cdev, "Unknown sriov eqe event 0x%02x\n",
3329 opcode);
3330 return -EINVAL;
3331 }
3332}
3333
32a47e72
YM
3334u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id)
3335{
3336 struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
3337 u16 i;
3338
3339 if (!p_iov)
3340 goto out;
3341
3342 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
7eff82b0 3343 if (qed_iov_is_valid_vfid(p_hwfn, rel_vf_id, true, false))
32a47e72
YM
3344 return i;
3345
3346out:
3347 return MAX_NUM_VFS;
3348}
37bff2b9
YM
3349
3350static int qed_iov_copy_vf_msg(struct qed_hwfn *p_hwfn, struct qed_ptt *ptt,
3351 int vfid)
3352{
3353 struct qed_dmae_params params;
3354 struct qed_vf_info *vf_info;
3355
3356 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3357 if (!vf_info)
3358 return -EINVAL;
3359
3360 memset(&params, 0, sizeof(struct qed_dmae_params));
3361 params.flags = QED_DMAE_FLAG_VF_SRC | QED_DMAE_FLAG_COMPLETION_DST;
3362 params.src_vfid = vf_info->abs_vf_id;
3363
3364 if (qed_dmae_host2host(p_hwfn, ptt,
3365 vf_info->vf_mbx.pending_req,
3366 vf_info->vf_mbx.req_phys,
3367 sizeof(union vfpf_tlvs) / 4, &params)) {
3368 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3369 "Failed to copy message from VF 0x%02x\n", vfid);
3370
3371 return -EIO;
3372 }
3373
3374 return 0;
3375}
3376
eff16960
YM
3377static void qed_iov_bulletin_set_forced_mac(struct qed_hwfn *p_hwfn,
3378 u8 *mac, int vfid)
3379{
3380 struct qed_vf_info *vf_info;
3381 u64 feature;
3382
3383 vf_info = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3384 if (!vf_info) {
3385 DP_NOTICE(p_hwfn->cdev,
3386 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
3387 return;
3388 }
3389
7eff82b0
YM
3390 if (vf_info->b_malicious) {
3391 DP_NOTICE(p_hwfn->cdev,
3392 "Can't set forced MAC to malicious VF [%d]\n", vfid);
3393 return;
3394 }
3395
eff16960
YM
3396 feature = 1 << MAC_ADDR_FORCED;
3397 memcpy(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
3398
3399 vf_info->bulletin.p_virt->valid_bitmap |= feature;
3400 /* Forced MAC will disable MAC_ADDR */
1a635e48 3401 vf_info->bulletin.p_virt->valid_bitmap &= ~BIT(VFPF_BULLETIN_MAC_ADDR);
eff16960
YM
3402
3403 qed_iov_configure_vport_forced(p_hwfn, vf_info, feature);
3404}
3405
ba56947a
BX
3406static void qed_iov_bulletin_set_forced_vlan(struct qed_hwfn *p_hwfn,
3407 u16 pvid, int vfid)
08feecd7
YM
3408{
3409 struct qed_vf_info *vf_info;
3410 u64 feature;
3411
3412 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3413 if (!vf_info) {
3414 DP_NOTICE(p_hwfn->cdev,
3415 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
3416 return;
3417 }
3418
7eff82b0
YM
3419 if (vf_info->b_malicious) {
3420 DP_NOTICE(p_hwfn->cdev,
3421 "Can't set forced vlan to malicious VF [%d]\n", vfid);
3422 return;
3423 }
3424
08feecd7
YM
3425 feature = 1 << VLAN_ADDR_FORCED;
3426 vf_info->bulletin.p_virt->pvid = pvid;
3427 if (pvid)
3428 vf_info->bulletin.p_virt->valid_bitmap |= feature;
3429 else
3430 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
3431
3432 qed_iov_configure_vport_forced(p_hwfn, vf_info, feature);
3433}
3434
6ddc7608
YM
3435static bool qed_iov_vf_has_vport_instance(struct qed_hwfn *p_hwfn, int vfid)
3436{
3437 struct qed_vf_info *p_vf_info;
3438
3439 p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3440 if (!p_vf_info)
3441 return false;
3442
3443 return !!p_vf_info->vport_instance;
3444}
3445
ba56947a 3446static bool qed_iov_is_vf_stopped(struct qed_hwfn *p_hwfn, int vfid)
0b55e27d
YM
3447{
3448 struct qed_vf_info *p_vf_info;
3449
3450 p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3451 if (!p_vf_info)
3452 return true;
3453
3454 return p_vf_info->state == VF_STOPPED;
3455}
3456
73390ac9
YM
3457static bool qed_iov_spoofchk_get(struct qed_hwfn *p_hwfn, int vfid)
3458{
3459 struct qed_vf_info *vf_info;
3460
3461 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3462 if (!vf_info)
3463 return false;
3464
3465 return vf_info->spoof_chk;
3466}
3467
ba56947a 3468static int qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn, int vfid, bool val)
6ddc7608
YM
3469{
3470 struct qed_vf_info *vf;
3471 int rc = -EINVAL;
3472
3473 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
3474 DP_NOTICE(p_hwfn,
3475 "SR-IOV sanity check failed, can't set spoofchk\n");
3476 goto out;
3477 }
3478
3479 vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3480 if (!vf)
3481 goto out;
3482
3483 if (!qed_iov_vf_has_vport_instance(p_hwfn, vfid)) {
3484 /* After VF VPORT start PF will configure spoof check */
3485 vf->req_spoofchk_val = val;
3486 rc = 0;
3487 goto out;
3488 }
3489
3490 rc = __qed_iov_spoofchk_set(p_hwfn, vf, val);
3491
3492out:
3493 return rc;
3494}
3495
eff16960
YM
3496static u8 *qed_iov_bulletin_get_forced_mac(struct qed_hwfn *p_hwfn,
3497 u16 rel_vf_id)
3498{
3499 struct qed_vf_info *p_vf;
3500
3501 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
3502 if (!p_vf || !p_vf->bulletin.p_virt)
3503 return NULL;
3504
1a635e48 3505 if (!(p_vf->bulletin.p_virt->valid_bitmap & BIT(MAC_ADDR_FORCED)))
eff16960
YM
3506 return NULL;
3507
3508 return p_vf->bulletin.p_virt->mac;
3509}
3510
ba56947a
BX
3511static u16
3512qed_iov_bulletin_get_forced_vlan(struct qed_hwfn *p_hwfn, u16 rel_vf_id)
08feecd7
YM
3513{
3514 struct qed_vf_info *p_vf;
3515
3516 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
3517 if (!p_vf || !p_vf->bulletin.p_virt)
3518 return 0;
3519
1a635e48 3520 if (!(p_vf->bulletin.p_virt->valid_bitmap & BIT(VLAN_ADDR_FORCED)))
08feecd7
YM
3521 return 0;
3522
3523 return p_vf->bulletin.p_virt->pvid;
3524}
3525
733def6a
YM
3526static int qed_iov_configure_tx_rate(struct qed_hwfn *p_hwfn,
3527 struct qed_ptt *p_ptt, int vfid, int val)
3528{
3529 struct qed_vf_info *vf;
3530 u8 abs_vp_id = 0;
3531 int rc;
3532
3533 vf = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3534 if (!vf)
3535 return -EINVAL;
3536
3537 rc = qed_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
3538 if (rc)
3539 return rc;
3540
3541 return qed_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val);
3542}
3543
ba56947a
BX
3544static int
3545qed_iov_configure_min_tx_rate(struct qed_dev *cdev, int vfid, u32 rate)
733def6a
YM
3546{
3547 struct qed_vf_info *vf;
3548 u8 vport_id;
3549 int i;
3550
3551 for_each_hwfn(cdev, i) {
3552 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3553
3554 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
3555 DP_NOTICE(p_hwfn,
3556 "SR-IOV sanity check failed, can't set min rate\n");
3557 return -EINVAL;
3558 }
3559 }
3560
3561 vf = qed_iov_get_vf_info(QED_LEADING_HWFN(cdev), (u16)vfid, true);
3562 vport_id = vf->vport_id;
3563
3564 return qed_configure_vport_wfq(cdev, vport_id, rate);
3565}
3566
73390ac9
YM
3567static int qed_iov_get_vf_min_rate(struct qed_hwfn *p_hwfn, int vfid)
3568{
3569 struct qed_wfq_data *vf_vp_wfq;
3570 struct qed_vf_info *vf_info;
3571
3572 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3573 if (!vf_info)
3574 return 0;
3575
3576 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
3577
3578 if (vf_vp_wfq->configured)
3579 return vf_vp_wfq->min_speed;
3580 else
3581 return 0;
3582}
3583
37bff2b9
YM
3584/**
3585 * qed_schedule_iov - schedules IOV task for VF and PF
3586 * @hwfn: hardware function pointer
3587 * @flag: IOV flag for VF/PF
3588 */
3589void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag)
3590{
3591 smp_mb__before_atomic();
3592 set_bit(flag, &hwfn->iov_task_flags);
3593 smp_mb__after_atomic();
3594 DP_VERBOSE(hwfn, QED_MSG_IOV, "Scheduling iov task [Flag: %d]\n", flag);
3595 queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, 0);
3596}
3597
1408cc1f
YM
3598void qed_vf_start_iov_wq(struct qed_dev *cdev)
3599{
3600 int i;
3601
3602 for_each_hwfn(cdev, i)
3603 queue_delayed_work(cdev->hwfns[i].iov_wq,
3604 &cdev->hwfns[i].iov_task, 0);
3605}
3606
0b55e27d
YM
3607int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
3608{
3609 int i, j;
3610
3611 for_each_hwfn(cdev, i)
3612 if (cdev->hwfns[i].iov_wq)
3613 flush_workqueue(cdev->hwfns[i].iov_wq);
3614
3615 /* Mark VFs for disablement */
3616 qed_iov_set_vfs_to_disable(cdev, true);
3617
3618 if (cdev->p_iov_info && cdev->p_iov_info->num_vfs && pci_enabled)
3619 pci_disable_sriov(cdev->pdev);
3620
3621 for_each_hwfn(cdev, i) {
3622 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3623 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
3624
3625 /* Failure to acquire the ptt in 100g creates an odd error
3626 * where the first engine has already relased IOV.
3627 */
3628 if (!ptt) {
3629 DP_ERR(hwfn, "Failed to acquire ptt\n");
3630 return -EBUSY;
3631 }
3632
733def6a
YM
3633 /* Clean WFQ db and configure equal weight for all vports */
3634 qed_clean_wfq_db(hwfn, ptt);
3635
0b55e27d
YM
3636 qed_for_each_vf(hwfn, j) {
3637 int k;
3638
7eff82b0 3639 if (!qed_iov_is_valid_vfid(hwfn, j, true, false))
0b55e27d
YM
3640 continue;
3641
3642 /* Wait until VF is disabled before releasing */
3643 for (k = 0; k < 100; k++) {
3644 if (!qed_iov_is_vf_stopped(hwfn, j))
3645 msleep(20);
3646 else
3647 break;
3648 }
3649
3650 if (k < 100)
3651 qed_iov_release_hw_for_vf(&cdev->hwfns[i],
3652 ptt, j);
3653 else
3654 DP_ERR(hwfn,
3655 "Timeout waiting for VF's FLR to end\n");
3656 }
3657
3658 qed_ptt_release(hwfn, ptt);
3659 }
3660
3661 qed_iov_set_vfs_to_disable(cdev, false);
3662
3663 return 0;
3664}
3665
3da7a37a
MY
3666static void qed_sriov_enable_qid_config(struct qed_hwfn *hwfn,
3667 u16 vfid,
3668 struct qed_iov_vf_init_params *params)
3669{
3670 u16 base, i;
3671
3672 /* Since we have an equal resource distribution per-VF, and we assume
3673 * PF has acquired the QED_PF_L2_QUE first queues, we start setting
3674 * sequentially from there.
3675 */
3676 base = FEAT_NUM(hwfn, QED_PF_L2_QUE) + vfid * params->num_queues;
3677
3678 params->rel_vf_id = vfid;
3679 for (i = 0; i < params->num_queues; i++) {
3680 params->req_rx_queue[i] = base + i;
3681 params->req_tx_queue[i] = base + i;
3682 }
3683}
3684
0b55e27d
YM
3685static int qed_sriov_enable(struct qed_dev *cdev, int num)
3686{
3da7a37a 3687 struct qed_iov_vf_init_params params;
0b55e27d
YM
3688 int i, j, rc;
3689
3690 if (num >= RESC_NUM(&cdev->hwfns[0], QED_VPORT)) {
3691 DP_NOTICE(cdev, "Can start at most %d VFs\n",
3692 RESC_NUM(&cdev->hwfns[0], QED_VPORT) - 1);
3693 return -EINVAL;
3694 }
3695
3da7a37a
MY
3696 memset(&params, 0, sizeof(params));
3697
0b55e27d
YM
3698 /* Initialize HW for VF access */
3699 for_each_hwfn(cdev, j) {
3700 struct qed_hwfn *hwfn = &cdev->hwfns[j];
3701 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
5a1f965a
MY
3702
3703 /* Make sure not to use more than 16 queues per VF */
3da7a37a
MY
3704 params.num_queues = min_t(int,
3705 FEAT_NUM(hwfn, QED_VF_L2_QUE) / num,
3706 16);
0b55e27d
YM
3707
3708 if (!ptt) {
3709 DP_ERR(hwfn, "Failed to acquire ptt\n");
3710 rc = -EBUSY;
3711 goto err;
3712 }
3713
0b55e27d 3714 for (i = 0; i < num; i++) {
7eff82b0 3715 if (!qed_iov_is_valid_vfid(hwfn, i, false, true))
0b55e27d
YM
3716 continue;
3717
3da7a37a
MY
3718 qed_sriov_enable_qid_config(hwfn, i, &params);
3719 rc = qed_iov_init_hw_for_vf(hwfn, ptt, &params);
0b55e27d
YM
3720 if (rc) {
3721 DP_ERR(cdev, "Failed to enable VF[%d]\n", i);
3722 qed_ptt_release(hwfn, ptt);
3723 goto err;
3724 }
3725 }
3726
3727 qed_ptt_release(hwfn, ptt);
3728 }
3729
3730 /* Enable SRIOV PCIe functions */
3731 rc = pci_enable_sriov(cdev->pdev, num);
3732 if (rc) {
3733 DP_ERR(cdev, "Failed to enable sriov [%d]\n", rc);
3734 goto err;
3735 }
3736
3737 return num;
3738
3739err:
3740 qed_sriov_disable(cdev, false);
3741 return rc;
3742}
3743
3744static int qed_sriov_configure(struct qed_dev *cdev, int num_vfs_param)
3745{
3746 if (!IS_QED_SRIOV(cdev)) {
3747 DP_VERBOSE(cdev, QED_MSG_IOV, "SR-IOV is not supported\n");
3748 return -EOPNOTSUPP;
3749 }
3750
3751 if (num_vfs_param)
3752 return qed_sriov_enable(cdev, num_vfs_param);
3753 else
3754 return qed_sriov_disable(cdev, true);
3755}
3756
eff16960
YM
3757static int qed_sriov_pf_set_mac(struct qed_dev *cdev, u8 *mac, int vfid)
3758{
3759 int i;
3760
3761 if (!IS_QED_SRIOV(cdev) || !IS_PF_SRIOV_ALLOC(&cdev->hwfns[0])) {
3762 DP_VERBOSE(cdev, QED_MSG_IOV,
3763 "Cannot set a VF MAC; Sriov is not enabled\n");
3764 return -EINVAL;
3765 }
3766
7eff82b0 3767 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vfid, true, true)) {
eff16960
YM
3768 DP_VERBOSE(cdev, QED_MSG_IOV,
3769 "Cannot set VF[%d] MAC (VF is not active)\n", vfid);
3770 return -EINVAL;
3771 }
3772
3773 for_each_hwfn(cdev, i) {
3774 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3775 struct qed_public_vf_info *vf_info;
3776
3777 vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
3778 if (!vf_info)
3779 continue;
3780
3781 /* Set the forced MAC, and schedule the IOV task */
3782 ether_addr_copy(vf_info->forced_mac, mac);
3783 qed_schedule_iov(hwfn, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG);
3784 }
3785
3786 return 0;
3787}
3788
08feecd7
YM
3789static int qed_sriov_pf_set_vlan(struct qed_dev *cdev, u16 vid, int vfid)
3790{
3791 int i;
3792
3793 if (!IS_QED_SRIOV(cdev) || !IS_PF_SRIOV_ALLOC(&cdev->hwfns[0])) {
3794 DP_VERBOSE(cdev, QED_MSG_IOV,
3795 "Cannot set a VF MAC; Sriov is not enabled\n");
3796 return -EINVAL;
3797 }
3798
7eff82b0 3799 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vfid, true, true)) {
08feecd7
YM
3800 DP_VERBOSE(cdev, QED_MSG_IOV,
3801 "Cannot set VF[%d] MAC (VF is not active)\n", vfid);
3802 return -EINVAL;
3803 }
3804
3805 for_each_hwfn(cdev, i) {
3806 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3807 struct qed_public_vf_info *vf_info;
3808
3809 vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
3810 if (!vf_info)
3811 continue;
3812
3813 /* Set the forced vlan, and schedule the IOV task */
3814 vf_info->forced_vlan = vid;
3815 qed_schedule_iov(hwfn, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG);
3816 }
3817
3818 return 0;
3819}
3820
73390ac9
YM
3821static int qed_get_vf_config(struct qed_dev *cdev,
3822 int vf_id, struct ifla_vf_info *ivi)
3823{
3824 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
3825 struct qed_public_vf_info *vf_info;
3826 struct qed_mcp_link_state link;
3827 u32 tx_rate;
3828
3829 /* Sanitize request */
3830 if (IS_VF(cdev))
3831 return -EINVAL;
3832
7eff82b0 3833 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vf_id, true, false)) {
73390ac9
YM
3834 DP_VERBOSE(cdev, QED_MSG_IOV,
3835 "VF index [%d] isn't active\n", vf_id);
3836 return -EINVAL;
3837 }
3838
3839 vf_info = qed_iov_get_public_vf_info(hwfn, vf_id, true);
3840
3841 qed_iov_get_link(hwfn, vf_id, NULL, &link, NULL);
3842
3843 /* Fill information about VF */
3844 ivi->vf = vf_id;
3845
3846 if (is_valid_ether_addr(vf_info->forced_mac))
3847 ether_addr_copy(ivi->mac, vf_info->forced_mac);
3848 else
3849 ether_addr_copy(ivi->mac, vf_info->mac);
3850
3851 ivi->vlan = vf_info->forced_vlan;
3852 ivi->spoofchk = qed_iov_spoofchk_get(hwfn, vf_id);
3853 ivi->linkstate = vf_info->link_state;
3854 tx_rate = vf_info->tx_rate;
3855 ivi->max_tx_rate = tx_rate ? tx_rate : link.speed;
3856 ivi->min_tx_rate = qed_iov_get_vf_min_rate(hwfn, vf_id);
3857
3858 return 0;
3859}
3860
36558c3d
YM
3861void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
3862{
3863 struct qed_mcp_link_capabilities caps;
3864 struct qed_mcp_link_params params;
3865 struct qed_mcp_link_state link;
3866 int i;
3867
3868 if (!hwfn->pf_iov_info)
3869 return;
3870
3871 /* Update bulletin of all future possible VFs with link configuration */
3872 for (i = 0; i < hwfn->cdev->p_iov_info->total_vfs; i++) {
733def6a
YM
3873 struct qed_public_vf_info *vf_info;
3874
3875 vf_info = qed_iov_get_public_vf_info(hwfn, i, false);
3876 if (!vf_info)
3877 continue;
3878
36558c3d
YM
3879 memcpy(&params, qed_mcp_get_link_params(hwfn), sizeof(params));
3880 memcpy(&link, qed_mcp_get_link_state(hwfn), sizeof(link));
3881 memcpy(&caps, qed_mcp_get_link_capabilities(hwfn),
3882 sizeof(caps));
3883
733def6a
YM
3884 /* Modify link according to the VF's configured link state */
3885 switch (vf_info->link_state) {
3886 case IFLA_VF_LINK_STATE_DISABLE:
3887 link.link_up = false;
3888 break;
3889 case IFLA_VF_LINK_STATE_ENABLE:
3890 link.link_up = true;
3891 /* Set speed according to maximum supported by HW.
3892 * that is 40G for regular devices and 100G for CMT
3893 * mode devices.
3894 */
3895 link.speed = (hwfn->cdev->num_hwfns > 1) ?
3896 100000 : 40000;
3897 default:
3898 /* In auto mode pass PF link image to VF */
3899 break;
3900 }
3901
3902 if (link.link_up && vf_info->tx_rate) {
3903 struct qed_ptt *ptt;
3904 int rate;
3905
3906 rate = min_t(int, vf_info->tx_rate, link.speed);
3907
3908 ptt = qed_ptt_acquire(hwfn);
3909 if (!ptt) {
3910 DP_NOTICE(hwfn, "Failed to acquire PTT\n");
3911 return;
3912 }
3913
3914 if (!qed_iov_configure_tx_rate(hwfn, ptt, i, rate)) {
3915 vf_info->tx_rate = rate;
3916 link.speed = rate;
3917 }
3918
3919 qed_ptt_release(hwfn, ptt);
3920 }
3921
36558c3d
YM
3922 qed_iov_set_link(hwfn, i, &params, &link, &caps);
3923 }
3924
3925 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
3926}
3927
733def6a
YM
3928static int qed_set_vf_link_state(struct qed_dev *cdev,
3929 int vf_id, int link_state)
3930{
3931 int i;
3932
3933 /* Sanitize request */
3934 if (IS_VF(cdev))
3935 return -EINVAL;
3936
7eff82b0 3937 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vf_id, true, true)) {
733def6a
YM
3938 DP_VERBOSE(cdev, QED_MSG_IOV,
3939 "VF index [%d] isn't active\n", vf_id);
3940 return -EINVAL;
3941 }
3942
3943 /* Handle configuration of link state */
3944 for_each_hwfn(cdev, i) {
3945 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3946 struct qed_public_vf_info *vf;
3947
3948 vf = qed_iov_get_public_vf_info(hwfn, vf_id, true);
3949 if (!vf)
3950 continue;
3951
3952 if (vf->link_state == link_state)
3953 continue;
3954
3955 vf->link_state = link_state;
3956 qed_inform_vf_link_state(&cdev->hwfns[i]);
3957 }
3958
3959 return 0;
3960}
3961
6ddc7608
YM
3962static int qed_spoof_configure(struct qed_dev *cdev, int vfid, bool val)
3963{
3964 int i, rc = -EINVAL;
3965
3966 for_each_hwfn(cdev, i) {
3967 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3968
3969 rc = qed_iov_spoofchk_set(p_hwfn, vfid, val);
3970 if (rc)
3971 break;
3972 }
3973
3974 return rc;
3975}
3976
733def6a
YM
3977static int qed_configure_max_vf_rate(struct qed_dev *cdev, int vfid, int rate)
3978{
3979 int i;
3980
3981 for_each_hwfn(cdev, i) {
3982 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3983 struct qed_public_vf_info *vf;
3984
3985 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
3986 DP_NOTICE(p_hwfn,
3987 "SR-IOV sanity check failed, can't set tx rate\n");
3988 return -EINVAL;
3989 }
3990
3991 vf = qed_iov_get_public_vf_info(p_hwfn, vfid, true);
3992
3993 vf->tx_rate = rate;
3994
3995 qed_inform_vf_link_state(p_hwfn);
3996 }
3997
3998 return 0;
3999}
4000
4001static int qed_set_vf_rate(struct qed_dev *cdev,
4002 int vfid, u32 min_rate, u32 max_rate)
4003{
4004 int rc_min = 0, rc_max = 0;
4005
4006 if (max_rate)
4007 rc_max = qed_configure_max_vf_rate(cdev, vfid, max_rate);
4008
4009 if (min_rate)
4010 rc_min = qed_iov_configure_min_tx_rate(cdev, vfid, min_rate);
4011
4012 if (rc_max | rc_min)
4013 return -EINVAL;
4014
4015 return 0;
4016}
4017
f990c82c
MY
4018static int qed_set_vf_trust(struct qed_dev *cdev, int vfid, bool trust)
4019{
4020 int i;
4021
4022 for_each_hwfn(cdev, i) {
4023 struct qed_hwfn *hwfn = &cdev->hwfns[i];
4024 struct qed_public_vf_info *vf;
4025
4026 if (!qed_iov_pf_sanity_check(hwfn, vfid)) {
4027 DP_NOTICE(hwfn,
4028 "SR-IOV sanity check failed, can't set trust\n");
4029 return -EINVAL;
4030 }
4031
4032 vf = qed_iov_get_public_vf_info(hwfn, vfid, true);
4033
4034 if (vf->is_trusted_request == trust)
4035 return 0;
4036 vf->is_trusted_request = trust;
4037
4038 qed_schedule_iov(hwfn, QED_IOV_WQ_TRUST_FLAG);
4039 }
4040
4041 return 0;
4042}
4043
37bff2b9
YM
4044static void qed_handle_vf_msg(struct qed_hwfn *hwfn)
4045{
4046 u64 events[QED_VF_ARRAY_LENGTH];
4047 struct qed_ptt *ptt;
4048 int i;
4049
4050 ptt = qed_ptt_acquire(hwfn);
4051 if (!ptt) {
4052 DP_VERBOSE(hwfn, QED_MSG_IOV,
4053 "Can't acquire PTT; re-scheduling\n");
4054 qed_schedule_iov(hwfn, QED_IOV_WQ_MSG_FLAG);
4055 return;
4056 }
4057
fd3c615a 4058 qed_iov_pf_get_pending_events(hwfn, events);
37bff2b9
YM
4059
4060 DP_VERBOSE(hwfn, QED_MSG_IOV,
4061 "Event mask of VF events: 0x%llx 0x%llx 0x%llx\n",
4062 events[0], events[1], events[2]);
4063
4064 qed_for_each_vf(hwfn, i) {
4065 /* Skip VFs with no pending messages */
4066 if (!(events[i / 64] & (1ULL << (i % 64))))
4067 continue;
4068
4069 DP_VERBOSE(hwfn, QED_MSG_IOV,
4070 "Handling VF message from VF 0x%02x [Abs 0x%02x]\n",
4071 i, hwfn->cdev->p_iov_info->first_vf_in_pf + i);
4072
4073 /* Copy VF's message to PF's request buffer for that VF */
4074 if (qed_iov_copy_vf_msg(hwfn, ptt, i))
4075 continue;
4076
4077 qed_iov_process_mbx_req(hwfn, ptt, i);
4078 }
4079
4080 qed_ptt_release(hwfn, ptt);
4081}
4082
08feecd7
YM
4083static void qed_handle_pf_set_vf_unicast(struct qed_hwfn *hwfn)
4084{
4085 int i;
4086
4087 qed_for_each_vf(hwfn, i) {
4088 struct qed_public_vf_info *info;
4089 bool update = false;
eff16960 4090 u8 *mac;
08feecd7
YM
4091
4092 info = qed_iov_get_public_vf_info(hwfn, i, true);
4093 if (!info)
4094 continue;
4095
4096 /* Update data on bulletin board */
eff16960
YM
4097 mac = qed_iov_bulletin_get_forced_mac(hwfn, i);
4098 if (is_valid_ether_addr(info->forced_mac) &&
4099 (!mac || !ether_addr_equal(mac, info->forced_mac))) {
4100 DP_VERBOSE(hwfn,
4101 QED_MSG_IOV,
4102 "Handling PF setting of VF MAC to VF 0x%02x [Abs 0x%02x]\n",
4103 i,
4104 hwfn->cdev->p_iov_info->first_vf_in_pf + i);
4105
4106 /* Update bulletin board with forced MAC */
4107 qed_iov_bulletin_set_forced_mac(hwfn,
4108 info->forced_mac, i);
4109 update = true;
4110 }
08feecd7
YM
4111
4112 if (qed_iov_bulletin_get_forced_vlan(hwfn, i) ^
4113 info->forced_vlan) {
4114 DP_VERBOSE(hwfn,
4115 QED_MSG_IOV,
4116 "Handling PF setting of pvid [0x%04x] to VF 0x%02x [Abs 0x%02x]\n",
4117 info->forced_vlan,
4118 i,
4119 hwfn->cdev->p_iov_info->first_vf_in_pf + i);
4120 qed_iov_bulletin_set_forced_vlan(hwfn,
4121 info->forced_vlan, i);
4122 update = true;
4123 }
4124
4125 if (update)
4126 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
4127 }
4128}
4129
36558c3d
YM
4130static void qed_handle_bulletin_post(struct qed_hwfn *hwfn)
4131{
4132 struct qed_ptt *ptt;
4133 int i;
4134
4135 ptt = qed_ptt_acquire(hwfn);
4136 if (!ptt) {
4137 DP_NOTICE(hwfn, "Failed allocating a ptt entry\n");
4138 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
4139 return;
4140 }
4141
4142 qed_for_each_vf(hwfn, i)
4143 qed_iov_post_vf_bulletin(hwfn, i, ptt);
4144
4145 qed_ptt_release(hwfn, ptt);
4146}
4147
f990c82c
MY
4148static void qed_iov_handle_trust_change(struct qed_hwfn *hwfn)
4149{
4150 struct qed_sp_vport_update_params params;
4151 struct qed_filter_accept_flags *flags;
4152 struct qed_public_vf_info *vf_info;
4153 struct qed_vf_info *vf;
4154 u8 mask;
4155 int i;
4156
4157 mask = QED_ACCEPT_UCAST_UNMATCHED | QED_ACCEPT_MCAST_UNMATCHED;
4158 flags = &params.accept_flags;
4159
4160 qed_for_each_vf(hwfn, i) {
4161 /* Need to make sure current requested configuration didn't
4162 * flip so that we'll end up configuring something that's not
4163 * needed.
4164 */
4165 vf_info = qed_iov_get_public_vf_info(hwfn, i, true);
4166 if (vf_info->is_trusted_configured ==
4167 vf_info->is_trusted_request)
4168 continue;
4169 vf_info->is_trusted_configured = vf_info->is_trusted_request;
4170
4171 /* Validate that the VF has a configured vport */
4172 vf = qed_iov_get_vf_info(hwfn, i, true);
4173 if (!vf->vport_instance)
4174 continue;
4175
4176 memset(&params, 0, sizeof(params));
4177 params.opaque_fid = vf->opaque_fid;
4178 params.vport_id = vf->vport_id;
4179
4180 if (vf_info->rx_accept_mode & mask) {
4181 flags->update_rx_mode_config = 1;
4182 flags->rx_accept_filter = vf_info->rx_accept_mode;
4183 }
4184
4185 if (vf_info->tx_accept_mode & mask) {
4186 flags->update_tx_mode_config = 1;
4187 flags->tx_accept_filter = vf_info->tx_accept_mode;
4188 }
4189
4190 /* Remove if needed; Otherwise this would set the mask */
4191 if (!vf_info->is_trusted_configured) {
4192 flags->rx_accept_filter &= ~mask;
4193 flags->tx_accept_filter &= ~mask;
4194 }
4195
4196 if (flags->update_rx_mode_config ||
4197 flags->update_tx_mode_config)
4198 qed_sp_vport_update(hwfn, &params,
4199 QED_SPQ_MODE_EBLOCK, NULL);
4200 }
4201}
4202
ba56947a
BX
4203static void qed_iov_pf_task(struct work_struct *work)
4204
37bff2b9
YM
4205{
4206 struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
4207 iov_task.work);
0b55e27d 4208 int rc;
37bff2b9
YM
4209
4210 if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
4211 return;
4212
0b55e27d
YM
4213 if (test_and_clear_bit(QED_IOV_WQ_FLR_FLAG, &hwfn->iov_task_flags)) {
4214 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
4215
4216 if (!ptt) {
4217 qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG);
4218 return;
4219 }
4220
4221 rc = qed_iov_vf_flr_cleanup(hwfn, ptt);
4222 if (rc)
4223 qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG);
4224
4225 qed_ptt_release(hwfn, ptt);
4226 }
4227
37bff2b9
YM
4228 if (test_and_clear_bit(QED_IOV_WQ_MSG_FLAG, &hwfn->iov_task_flags))
4229 qed_handle_vf_msg(hwfn);
08feecd7
YM
4230
4231 if (test_and_clear_bit(QED_IOV_WQ_SET_UNICAST_FILTER_FLAG,
4232 &hwfn->iov_task_flags))
4233 qed_handle_pf_set_vf_unicast(hwfn);
4234
36558c3d
YM
4235 if (test_and_clear_bit(QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
4236 &hwfn->iov_task_flags))
4237 qed_handle_bulletin_post(hwfn);
f990c82c
MY
4238
4239 if (test_and_clear_bit(QED_IOV_WQ_TRUST_FLAG, &hwfn->iov_task_flags))
4240 qed_iov_handle_trust_change(hwfn);
37bff2b9
YM
4241}
4242
4243void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
4244{
4245 int i;
4246
4247 for_each_hwfn(cdev, i) {
4248 if (!cdev->hwfns[i].iov_wq)
4249 continue;
4250
4251 if (schedule_first) {
4252 qed_schedule_iov(&cdev->hwfns[i],
4253 QED_IOV_WQ_STOP_WQ_FLAG);
4254 cancel_delayed_work_sync(&cdev->hwfns[i].iov_task);
4255 }
4256
4257 flush_workqueue(cdev->hwfns[i].iov_wq);
4258 destroy_workqueue(cdev->hwfns[i].iov_wq);
4259 }
4260}
4261
4262int qed_iov_wq_start(struct qed_dev *cdev)
4263{
4264 char name[NAME_SIZE];
4265 int i;
4266
4267 for_each_hwfn(cdev, i) {
4268 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
4269
36558c3d
YM
4270 /* PFs needs a dedicated workqueue only if they support IOV.
4271 * VFs always require one.
4272 */
4273 if (IS_PF(p_hwfn->cdev) && !IS_PF_SRIOV(p_hwfn))
37bff2b9
YM
4274 continue;
4275
4276 snprintf(name, NAME_SIZE, "iov-%02x:%02x.%02x",
4277 cdev->pdev->bus->number,
4278 PCI_SLOT(cdev->pdev->devfn), p_hwfn->abs_pf_id);
4279
4280 p_hwfn->iov_wq = create_singlethread_workqueue(name);
4281 if (!p_hwfn->iov_wq) {
4282 DP_NOTICE(p_hwfn, "Cannot create iov workqueue\n");
4283 return -ENOMEM;
4284 }
4285
36558c3d
YM
4286 if (IS_PF(cdev))
4287 INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_pf_task);
4288 else
4289 INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_vf_task);
37bff2b9
YM
4290 }
4291
4292 return 0;
4293}
0b55e27d
YM
4294
4295const struct qed_iov_hv_ops qed_iov_ops_pass = {
4296 .configure = &qed_sriov_configure,
eff16960 4297 .set_mac = &qed_sriov_pf_set_mac,
08feecd7 4298 .set_vlan = &qed_sriov_pf_set_vlan,
73390ac9 4299 .get_config = &qed_get_vf_config,
733def6a 4300 .set_link_state = &qed_set_vf_link_state,
6ddc7608 4301 .set_spoof = &qed_spoof_configure,
733def6a 4302 .set_rate = &qed_set_vf_rate,
f990c82c 4303 .set_trust = &qed_set_vf_trust,
0b55e27d 4304};