blob: f6540c0ae595ed22fbeb20cac0905488304134af [file] [log] [blame]
Yuval Mintz32a47e72016-05-11 16:36:12 +03001/* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
3 *
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
6 * this source tree.
7 */
8
Yuval Mintzdacd88d2016-05-11 16:36:16 +03009#include <linux/etherdevice.h>
Yuval Mintz36558c32016-05-11 16:36:17 +030010#include <linux/crc32.h>
Yuval Mintz0b55e272016-05-11 16:36:15 +030011#include <linux/qed/qed_iov_if.h>
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030012#include "qed_cxt.h"
13#include "qed_hsi.h"
Yuval Mintz32a47e72016-05-11 16:36:12 +030014#include "qed_hw.h"
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030015#include "qed_init_ops.h"
Yuval Mintz32a47e72016-05-11 16:36:12 +030016#include "qed_int.h"
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030017#include "qed_mcp.h"
Yuval Mintz32a47e72016-05-11 16:36:12 +030018#include "qed_reg_addr.h"
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030019#include "qed_sp.h"
Yuval Mintz32a47e72016-05-11 16:36:12 +030020#include "qed_sriov.h"
21#include "qed_vf.h"
22
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030023/* IOV ramrods */
24static int qed_sp_vf_start(struct qed_hwfn *p_hwfn,
25 u32 concrete_vfid, u16 opaque_vfid)
26{
27 struct vf_start_ramrod_data *p_ramrod = NULL;
28 struct qed_spq_entry *p_ent = NULL;
29 struct qed_sp_init_data init_data;
30 int rc = -EINVAL;
31
32 /* Get SPQ entry */
33 memset(&init_data, 0, sizeof(init_data));
34 init_data.cid = qed_spq_get_cid(p_hwfn);
35 init_data.opaque_fid = opaque_vfid;
36 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
37
38 rc = qed_sp_init_request(p_hwfn, &p_ent,
39 COMMON_RAMROD_VF_START,
40 PROTOCOLID_COMMON, &init_data);
41 if (rc)
42 return rc;
43
44 p_ramrod = &p_ent->ramrod.vf_start;
45
46 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
47 p_ramrod->opaque_fid = cpu_to_le16(opaque_vfid);
48
49 p_ramrod->personality = PERSONALITY_ETH;
50
51 return qed_spq_post(p_hwfn, p_ent, NULL);
52}
53
Yuval Mintz0b55e272016-05-11 16:36:15 +030054static int qed_sp_vf_stop(struct qed_hwfn *p_hwfn,
55 u32 concrete_vfid, u16 opaque_vfid)
56{
57 struct vf_stop_ramrod_data *p_ramrod = NULL;
58 struct qed_spq_entry *p_ent = NULL;
59 struct qed_sp_init_data init_data;
60 int rc = -EINVAL;
61
62 /* Get SPQ entry */
63 memset(&init_data, 0, sizeof(init_data));
64 init_data.cid = qed_spq_get_cid(p_hwfn);
65 init_data.opaque_fid = opaque_vfid;
66 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
67
68 rc = qed_sp_init_request(p_hwfn, &p_ent,
69 COMMON_RAMROD_VF_STOP,
70 PROTOCOLID_COMMON, &init_data);
71 if (rc)
72 return rc;
73
74 p_ramrod = &p_ent->ramrod.vf_stop;
75
76 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
77
78 return qed_spq_post(p_hwfn, p_ent, NULL);
79}
80
Yuval Mintz32a47e72016-05-11 16:36:12 +030081bool qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn,
82 int rel_vf_id, bool b_enabled_only)
83{
84 if (!p_hwfn->pf_iov_info) {
85 DP_NOTICE(p_hwfn->cdev, "No iov info\n");
86 return false;
87 }
88
89 if ((rel_vf_id >= p_hwfn->cdev->p_iov_info->total_vfs) ||
90 (rel_vf_id < 0))
91 return false;
92
93 if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
94 b_enabled_only)
95 return false;
96
97 return true;
98}
99
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300100static struct qed_vf_info *qed_iov_get_vf_info(struct qed_hwfn *p_hwfn,
101 u16 relative_vf_id,
102 bool b_enabled_only)
103{
104 struct qed_vf_info *vf = NULL;
105
106 if (!p_hwfn->pf_iov_info) {
107 DP_NOTICE(p_hwfn->cdev, "No iov info\n");
108 return NULL;
109 }
110
111 if (qed_iov_is_valid_vfid(p_hwfn, relative_vf_id, b_enabled_only))
112 vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
113 else
114 DP_ERR(p_hwfn, "qed_iov_get_vf_info: VF[%d] is not enabled\n",
115 relative_vf_id);
116
117 return vf;
118}
119
Yuval Mintz36558c32016-05-11 16:36:17 +0300120int qed_iov_post_vf_bulletin(struct qed_hwfn *p_hwfn,
121 int vfid, struct qed_ptt *p_ptt)
122{
123 struct qed_bulletin_content *p_bulletin;
124 int crc_size = sizeof(p_bulletin->crc);
125 struct qed_dmae_params params;
126 struct qed_vf_info *p_vf;
127
128 p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
129 if (!p_vf)
130 return -EINVAL;
131
132 if (!p_vf->vf_bulletin)
133 return -EINVAL;
134
135 p_bulletin = p_vf->bulletin.p_virt;
136
137 /* Increment bulletin board version and compute crc */
138 p_bulletin->version++;
139 p_bulletin->crc = crc32(0, (u8 *)p_bulletin + crc_size,
140 p_vf->bulletin.size - crc_size);
141
142 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
143 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
144 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
145
146 /* propagate bulletin board via dmae to vm memory */
147 memset(&params, 0, sizeof(params));
148 params.flags = QED_DMAE_FLAG_VF_DST;
149 params.dst_vfid = p_vf->abs_vf_id;
150 return qed_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
151 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
152 &params);
153}
154
Yuval Mintz32a47e72016-05-11 16:36:12 +0300155static int qed_iov_pci_cfg_info(struct qed_dev *cdev)
156{
157 struct qed_hw_sriov_info *iov = cdev->p_iov_info;
158 int pos = iov->pos;
159
160 DP_VERBOSE(cdev, QED_MSG_IOV, "sriov ext pos %d\n", pos);
161 pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
162
163 pci_read_config_word(cdev->pdev,
164 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
165 pci_read_config_word(cdev->pdev,
166 pos + PCI_SRIOV_INITIAL_VF, &iov->initial_vfs);
167
168 pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
169 if (iov->num_vfs) {
170 DP_VERBOSE(cdev,
171 QED_MSG_IOV,
172 "Number of VFs are already set to non-zero value. Ignoring PCI configuration value\n");
173 iov->num_vfs = 0;
174 }
175
176 pci_read_config_word(cdev->pdev,
177 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
178
179 pci_read_config_word(cdev->pdev,
180 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
181
182 pci_read_config_word(cdev->pdev,
183 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
184
185 pci_read_config_dword(cdev->pdev,
186 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
187
188 pci_read_config_dword(cdev->pdev, pos + PCI_SRIOV_CAP, &iov->cap);
189
190 pci_read_config_byte(cdev->pdev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
191
192 DP_VERBOSE(cdev,
193 QED_MSG_IOV,
194 "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",
195 iov->nres,
196 iov->cap,
197 iov->ctrl,
198 iov->total_vfs,
199 iov->initial_vfs,
200 iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz);
201
202 /* Some sanity checks */
203 if (iov->num_vfs > NUM_OF_VFS(cdev) ||
204 iov->total_vfs > NUM_OF_VFS(cdev)) {
205 /* This can happen only due to a bug. In this case we set
206 * num_vfs to zero to avoid memory corruption in the code that
207 * assumes max number of vfs
208 */
209 DP_NOTICE(cdev,
210 "IOV: Unexpected number of vfs set: %d setting num_vf to zero\n",
211 iov->num_vfs);
212
213 iov->num_vfs = 0;
214 iov->total_vfs = 0;
215 }
216
217 return 0;
218}
219
220static void qed_iov_clear_vf_igu_blocks(struct qed_hwfn *p_hwfn,
221 struct qed_ptt *p_ptt)
222{
223 struct qed_igu_block *p_sb;
224 u16 sb_id;
225 u32 val;
226
227 if (!p_hwfn->hw_info.p_igu_info) {
228 DP_ERR(p_hwfn,
229 "qed_iov_clear_vf_igu_blocks IGU Info not initialized\n");
230 return;
231 }
232
233 for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(p_hwfn->cdev);
234 sb_id++) {
235 p_sb = &p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks[sb_id];
236 if ((p_sb->status & QED_IGU_STATUS_FREE) &&
237 !(p_sb->status & QED_IGU_STATUS_PF)) {
238 val = qed_rd(p_hwfn, p_ptt,
239 IGU_REG_MAPPING_MEMORY + sb_id * 4);
240 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
241 qed_wr(p_hwfn, p_ptt,
242 IGU_REG_MAPPING_MEMORY + 4 * sb_id, val);
243 }
244 }
245}
246
247static void qed_iov_setup_vfdb(struct qed_hwfn *p_hwfn)
248{
249 struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
250 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
251 struct qed_bulletin_content *p_bulletin_virt;
252 dma_addr_t req_p, rply_p, bulletin_p;
253 union pfvf_tlvs *p_reply_virt_addr;
254 union vfpf_tlvs *p_req_virt_addr;
255 u8 idx = 0;
256
257 memset(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
258
259 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
260 req_p = p_iov_info->mbx_msg_phys_addr;
261 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
262 rply_p = p_iov_info->mbx_reply_phys_addr;
263 p_bulletin_virt = p_iov_info->p_bulletins;
264 bulletin_p = p_iov_info->bulletins_phys;
265 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
266 DP_ERR(p_hwfn,
267 "qed_iov_setup_vfdb called without allocating mem first\n");
268 return;
269 }
270
271 for (idx = 0; idx < p_iov->total_vfs; idx++) {
272 struct qed_vf_info *vf = &p_iov_info->vfs_array[idx];
273 u32 concrete;
274
275 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
276 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
277 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
278 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
279
280 vf->state = VF_STOPPED;
281 vf->b_init = false;
282
283 vf->bulletin.phys = idx *
284 sizeof(struct qed_bulletin_content) +
285 bulletin_p;
286 vf->bulletin.p_virt = p_bulletin_virt + idx;
287 vf->bulletin.size = sizeof(struct qed_bulletin_content);
288
289 vf->relative_vf_id = idx;
290 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
291 concrete = qed_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
292 vf->concrete_fid = concrete;
293 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
294 (vf->abs_vf_id << 8);
295 vf->vport_id = idx + 1;
296 }
297}
298
299static int qed_iov_allocate_vfdb(struct qed_hwfn *p_hwfn)
300{
301 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
302 void **p_v_addr;
303 u16 num_vfs = 0;
304
305 num_vfs = p_hwfn->cdev->p_iov_info->total_vfs;
306
307 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
308 "qed_iov_allocate_vfdb for %d VFs\n", num_vfs);
309
310 /* Allocate PF Mailbox buffer (per-VF) */
311 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
312 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
313 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
314 p_iov_info->mbx_msg_size,
315 &p_iov_info->mbx_msg_phys_addr,
316 GFP_KERNEL);
317 if (!*p_v_addr)
318 return -ENOMEM;
319
320 /* Allocate PF Mailbox Reply buffer (per-VF) */
321 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
322 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
323 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
324 p_iov_info->mbx_reply_size,
325 &p_iov_info->mbx_reply_phys_addr,
326 GFP_KERNEL);
327 if (!*p_v_addr)
328 return -ENOMEM;
329
330 p_iov_info->bulletins_size = sizeof(struct qed_bulletin_content) *
331 num_vfs;
332 p_v_addr = &p_iov_info->p_bulletins;
333 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
334 p_iov_info->bulletins_size,
335 &p_iov_info->bulletins_phys,
336 GFP_KERNEL);
337 if (!*p_v_addr)
338 return -ENOMEM;
339
340 DP_VERBOSE(p_hwfn,
341 QED_MSG_IOV,
342 "PF's Requests mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys] Bulletins [%p virt 0x%llx phys]\n",
343 p_iov_info->mbx_msg_virt_addr,
344 (u64) p_iov_info->mbx_msg_phys_addr,
345 p_iov_info->mbx_reply_virt_addr,
346 (u64) p_iov_info->mbx_reply_phys_addr,
347 p_iov_info->p_bulletins, (u64) p_iov_info->bulletins_phys);
348
349 return 0;
350}
351
352static void qed_iov_free_vfdb(struct qed_hwfn *p_hwfn)
353{
354 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
355
356 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
357 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
358 p_iov_info->mbx_msg_size,
359 p_iov_info->mbx_msg_virt_addr,
360 p_iov_info->mbx_msg_phys_addr);
361
362 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
363 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
364 p_iov_info->mbx_reply_size,
365 p_iov_info->mbx_reply_virt_addr,
366 p_iov_info->mbx_reply_phys_addr);
367
368 if (p_iov_info->p_bulletins)
369 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
370 p_iov_info->bulletins_size,
371 p_iov_info->p_bulletins,
372 p_iov_info->bulletins_phys);
373}
374
375int qed_iov_alloc(struct qed_hwfn *p_hwfn)
376{
377 struct qed_pf_iov *p_sriov;
378
379 if (!IS_PF_SRIOV(p_hwfn)) {
380 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
381 "No SR-IOV - no need for IOV db\n");
382 return 0;
383 }
384
385 p_sriov = kzalloc(sizeof(*p_sriov), GFP_KERNEL);
386 if (!p_sriov) {
387 DP_NOTICE(p_hwfn, "Failed to allocate `struct qed_sriov'\n");
388 return -ENOMEM;
389 }
390
391 p_hwfn->pf_iov_info = p_sriov;
392
393 return qed_iov_allocate_vfdb(p_hwfn);
394}
395
396void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
397{
398 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
399 return;
400
401 qed_iov_setup_vfdb(p_hwfn);
402 qed_iov_clear_vf_igu_blocks(p_hwfn, p_ptt);
403}
404
405void qed_iov_free(struct qed_hwfn *p_hwfn)
406{
407 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
408 qed_iov_free_vfdb(p_hwfn);
409 kfree(p_hwfn->pf_iov_info);
410 }
411}
412
413void qed_iov_free_hw_info(struct qed_dev *cdev)
414{
415 kfree(cdev->p_iov_info);
416 cdev->p_iov_info = NULL;
417}
418
419int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
420{
421 struct qed_dev *cdev = p_hwfn->cdev;
422 int pos;
423 int rc;
424
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300425 if (IS_VF(p_hwfn->cdev))
426 return 0;
427
Yuval Mintz32a47e72016-05-11 16:36:12 +0300428 /* Learn the PCI configuration */
429 pos = pci_find_ext_capability(p_hwfn->cdev->pdev,
430 PCI_EXT_CAP_ID_SRIOV);
431 if (!pos) {
432 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "No PCIe IOV support\n");
433 return 0;
434 }
435
436 /* Allocate a new struct for IOV information */
437 cdev->p_iov_info = kzalloc(sizeof(*cdev->p_iov_info), GFP_KERNEL);
438 if (!cdev->p_iov_info) {
439 DP_NOTICE(p_hwfn, "Can't support IOV due to lack of memory\n");
440 return -ENOMEM;
441 }
442 cdev->p_iov_info->pos = pos;
443
444 rc = qed_iov_pci_cfg_info(cdev);
445 if (rc)
446 return rc;
447
448 /* We want PF IOV to be synonemous with the existance of p_iov_info;
449 * In case the capability is published but there are no VFs, simply
450 * de-allocate the struct.
451 */
452 if (!cdev->p_iov_info->total_vfs) {
453 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
454 "IOV capabilities, but no VFs are published\n");
455 kfree(cdev->p_iov_info);
456 cdev->p_iov_info = NULL;
457 return 0;
458 }
459
460 /* Calculate the first VF index - this is a bit tricky; Basically,
461 * VFs start at offset 16 relative to PF0, and 2nd engine VFs begin
462 * after the first engine's VFs.
463 */
464 cdev->p_iov_info->first_vf_in_pf = p_hwfn->cdev->p_iov_info->offset +
465 p_hwfn->abs_pf_id - 16;
466 if (QED_PATH_ID(p_hwfn))
467 cdev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
468
469 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
470 "First VF in hwfn 0x%08x\n",
471 cdev->p_iov_info->first_vf_in_pf);
472
473 return 0;
474}
475
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300476static bool qed_iov_pf_sanity_check(struct qed_hwfn *p_hwfn, int vfid)
477{
478 /* Check PF supports sriov */
479 if (!IS_QED_SRIOV(p_hwfn->cdev) || !IS_PF_SRIOV_ALLOC(p_hwfn))
480 return false;
481
482 /* Check VF validity */
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300483 if (IS_VF(p_hwfn->cdev) || !IS_QED_SRIOV(p_hwfn->cdev) ||
484 !IS_PF_SRIOV_ALLOC(p_hwfn))
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300485 return false;
486
487 return true;
488}
489
Yuval Mintz0b55e272016-05-11 16:36:15 +0300490static void qed_iov_set_vf_to_disable(struct qed_dev *cdev,
491 u16 rel_vf_id, u8 to_disable)
492{
493 struct qed_vf_info *vf;
494 int i;
495
496 for_each_hwfn(cdev, i) {
497 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
498
499 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
500 if (!vf)
501 continue;
502
503 vf->to_disable = to_disable;
504 }
505}
506
507void qed_iov_set_vfs_to_disable(struct qed_dev *cdev, u8 to_disable)
508{
509 u16 i;
510
511 if (!IS_QED_SRIOV(cdev))
512 return;
513
514 for (i = 0; i < cdev->p_iov_info->total_vfs; i++)
515 qed_iov_set_vf_to_disable(cdev, i, to_disable);
516}
517
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300518static void qed_iov_vf_pglue_clear_err(struct qed_hwfn *p_hwfn,
519 struct qed_ptt *p_ptt, u8 abs_vfid)
520{
521 qed_wr(p_hwfn, p_ptt,
522 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
523 1 << (abs_vfid & 0x1f));
524}
525
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300526static void qed_iov_vf_igu_reset(struct qed_hwfn *p_hwfn,
527 struct qed_ptt *p_ptt, struct qed_vf_info *vf)
528{
529 u16 igu_sb_id;
530 int i;
531
532 /* Set VF masks and configuration - pretend */
533 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
534
535 qed_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
536
537 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
538 "value in VF_CONFIGURATION of vf %d after write %x\n",
539 vf->abs_vf_id,
540 qed_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION));
541
542 /* unpretend */
543 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
544
545 /* iterate over all queues, clear sb consumer */
546 for (i = 0; i < vf->num_sbs; i++) {
547 igu_sb_id = vf->igu_sbs[i];
548 /* Set then clear... */
549 qed_int_igu_cleanup_sb(p_hwfn, p_ptt, igu_sb_id, 1,
550 vf->opaque_fid);
551 qed_int_igu_cleanup_sb(p_hwfn, p_ptt, igu_sb_id, 0,
552 vf->opaque_fid);
553 }
554}
555
Yuval Mintz0b55e272016-05-11 16:36:15 +0300556static void qed_iov_vf_igu_set_int(struct qed_hwfn *p_hwfn,
557 struct qed_ptt *p_ptt,
558 struct qed_vf_info *vf, bool enable)
559{
560 u32 igu_vf_conf;
561
562 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
563
564 igu_vf_conf = qed_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
565
566 if (enable)
567 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
568 else
569 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
570
571 qed_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
572
573 /* unpretend */
574 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
575}
576
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300577static int qed_iov_enable_vf_access(struct qed_hwfn *p_hwfn,
578 struct qed_ptt *p_ptt,
579 struct qed_vf_info *vf)
580{
581 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
582 int rc;
583
Yuval Mintz0b55e272016-05-11 16:36:15 +0300584 if (vf->to_disable)
585 return 0;
586
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300587 DP_VERBOSE(p_hwfn,
588 QED_MSG_IOV,
589 "Enable internal access for vf %x [abs %x]\n",
590 vf->abs_vf_id, QED_VF_ABS_ID(p_hwfn, vf));
591
592 qed_iov_vf_pglue_clear_err(p_hwfn, p_ptt, QED_VF_ABS_ID(p_hwfn, vf));
593
594 rc = qed_mcp_config_vf_msix(p_hwfn, p_ptt, vf->abs_vf_id, vf->num_sbs);
595 if (rc)
596 return rc;
597
598 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
599
600 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
601 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
602
603 qed_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
604 p_hwfn->hw_info.hw_mode);
605
606 /* unpretend */
607 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
608
609 if (vf->state != VF_STOPPED) {
610 DP_NOTICE(p_hwfn, "VF[%02x] is already started\n",
611 vf->abs_vf_id);
612 return -EINVAL;
613 }
614
615 /* Start VF */
616 rc = qed_sp_vf_start(p_hwfn, vf->concrete_fid, vf->opaque_fid);
617 if (rc)
618 DP_NOTICE(p_hwfn, "Failed to start VF[%02x]\n", vf->abs_vf_id);
619
620 vf->state = VF_FREE;
621
622 return rc;
623}
624
Yuval Mintz0b55e272016-05-11 16:36:15 +0300625/**
626 * @brief qed_iov_config_perm_table - configure the permission
627 * zone table.
628 * In E4, queue zone permission table size is 320x9. There
629 * are 320 VF queues for single engine device (256 for dual
630 * engine device), and each entry has the following format:
631 * {Valid, VF[7:0]}
632 * @param p_hwfn
633 * @param p_ptt
634 * @param vf
635 * @param enable
636 */
637static void qed_iov_config_perm_table(struct qed_hwfn *p_hwfn,
638 struct qed_ptt *p_ptt,
639 struct qed_vf_info *vf, u8 enable)
640{
641 u32 reg_addr, val;
642 u16 qzone_id = 0;
643 int qid;
644
645 for (qid = 0; qid < vf->num_rxqs; qid++) {
646 qed_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
647 &qzone_id);
648
649 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
650 val = enable ? (vf->abs_vf_id | (1 << 8)) : 0;
651 qed_wr(p_hwfn, p_ptt, reg_addr, val);
652 }
653}
654
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300655static void qed_iov_enable_vf_traffic(struct qed_hwfn *p_hwfn,
656 struct qed_ptt *p_ptt,
657 struct qed_vf_info *vf)
658{
659 /* Reset vf in IGU - interrupts are still disabled */
660 qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
661
662 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
663
664 /* Permission Table */
665 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
666}
667
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300668static u8 qed_iov_alloc_vf_igu_sbs(struct qed_hwfn *p_hwfn,
669 struct qed_ptt *p_ptt,
670 struct qed_vf_info *vf, u16 num_rx_queues)
671{
672 struct qed_igu_block *igu_blocks;
673 int qid = 0, igu_id = 0;
674 u32 val = 0;
675
676 igu_blocks = p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks;
677
678 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->free_blks)
679 num_rx_queues = p_hwfn->hw_info.p_igu_info->free_blks;
680 p_hwfn->hw_info.p_igu_info->free_blks -= num_rx_queues;
681
682 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
683 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
684 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
685
686 while ((qid < num_rx_queues) &&
687 (igu_id < QED_MAPPING_MEMORY_SIZE(p_hwfn->cdev))) {
688 if (igu_blocks[igu_id].status & QED_IGU_STATUS_FREE) {
689 struct cau_sb_entry sb_entry;
690
691 vf->igu_sbs[qid] = (u16)igu_id;
692 igu_blocks[igu_id].status &= ~QED_IGU_STATUS_FREE;
693
694 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
695
696 qed_wr(p_hwfn, p_ptt,
697 IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id,
698 val);
699
700 /* Configure igu sb in CAU which were marked valid */
701 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
702 p_hwfn->rel_pf_id,
703 vf->abs_vf_id, 1);
704 qed_dmae_host2grc(p_hwfn, p_ptt,
705 (u64)(uintptr_t)&sb_entry,
706 CAU_REG_SB_VAR_MEMORY +
707 igu_id * sizeof(u64), 2, 0);
708 qid++;
709 }
710 igu_id++;
711 }
712
713 vf->num_sbs = (u8) num_rx_queues;
714
715 return vf->num_sbs;
716}
717
Yuval Mintz0b55e272016-05-11 16:36:15 +0300718static void qed_iov_free_vf_igu_sbs(struct qed_hwfn *p_hwfn,
719 struct qed_ptt *p_ptt,
720 struct qed_vf_info *vf)
721{
722 struct qed_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
723 int idx, igu_id;
724 u32 addr, val;
725
726 /* Invalidate igu CAM lines and mark them as free */
727 for (idx = 0; idx < vf->num_sbs; idx++) {
728 igu_id = vf->igu_sbs[idx];
729 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
730
731 val = qed_rd(p_hwfn, p_ptt, addr);
732 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
733 qed_wr(p_hwfn, p_ptt, addr, val);
734
735 p_info->igu_map.igu_blocks[igu_id].status |=
736 QED_IGU_STATUS_FREE;
737
738 p_hwfn->hw_info.p_igu_info->free_blks++;
739 }
740
741 vf->num_sbs = 0;
742}
743
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300744static int qed_iov_init_hw_for_vf(struct qed_hwfn *p_hwfn,
745 struct qed_ptt *p_ptt,
746 u16 rel_vf_id, u16 num_rx_queues)
747{
748 u8 num_of_vf_avaiable_chains = 0;
749 struct qed_vf_info *vf = NULL;
750 int rc = 0;
751 u32 cids;
752 u8 i;
753
754 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
755 if (!vf) {
756 DP_ERR(p_hwfn, "qed_iov_init_hw_for_vf : vf is NULL\n");
757 return -EINVAL;
758 }
759
760 if (vf->b_init) {
761 DP_NOTICE(p_hwfn, "VF[%d] is already active.\n", rel_vf_id);
762 return -EINVAL;
763 }
764
765 /* Limit number of queues according to number of CIDs */
766 qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
767 DP_VERBOSE(p_hwfn,
768 QED_MSG_IOV,
769 "VF[%d] - requesting to initialize for 0x%04x queues [0x%04x CIDs available]\n",
770 vf->relative_vf_id, num_rx_queues, (u16) cids);
771 num_rx_queues = min_t(u16, num_rx_queues, ((u16) cids));
772
773 num_of_vf_avaiable_chains = qed_iov_alloc_vf_igu_sbs(p_hwfn,
774 p_ptt,
775 vf,
776 num_rx_queues);
777 if (!num_of_vf_avaiable_chains) {
778 DP_ERR(p_hwfn, "no available igu sbs\n");
779 return -ENOMEM;
780 }
781
782 /* Choose queue number and index ranges */
783 vf->num_rxqs = num_of_vf_avaiable_chains;
784 vf->num_txqs = num_of_vf_avaiable_chains;
785
786 for (i = 0; i < vf->num_rxqs; i++) {
787 u16 queue_id = qed_int_queue_id_from_sb_id(p_hwfn,
788 vf->igu_sbs[i]);
789
790 if (queue_id > RESC_NUM(p_hwfn, QED_L2_QUEUE)) {
791 DP_NOTICE(p_hwfn,
792 "VF[%d] will require utilizing of out-of-bounds queues - %04x\n",
793 vf->relative_vf_id, queue_id);
794 return -EINVAL;
795 }
796
797 /* CIDs are per-VF, so no problem having them 0-based. */
798 vf->vf_queues[i].fw_rx_qid = queue_id;
799 vf->vf_queues[i].fw_tx_qid = queue_id;
800 vf->vf_queues[i].fw_cid = i;
801
802 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
803 "VF[%d] - [%d] SB %04x, Tx/Rx queue %04x CID %04x\n",
804 vf->relative_vf_id, i, vf->igu_sbs[i], queue_id, i);
805 }
806 rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, vf);
807 if (!rc) {
808 vf->b_init = true;
809
810 if (IS_LEAD_HWFN(p_hwfn))
811 p_hwfn->cdev->p_iov_info->num_vfs++;
812 }
813
814 return rc;
815}
816
Yuval Mintz0b55e272016-05-11 16:36:15 +0300817static int qed_iov_release_hw_for_vf(struct qed_hwfn *p_hwfn,
818 struct qed_ptt *p_ptt, u16 rel_vf_id)
819{
820 struct qed_vf_info *vf = NULL;
821 int rc = 0;
822
823 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
824 if (!vf) {
825 DP_ERR(p_hwfn, "qed_iov_release_hw_for_vf : vf is NULL\n");
826 return -EINVAL;
827 }
828
Yuval Mintz36558c32016-05-11 16:36:17 +0300829 if (vf->bulletin.p_virt)
830 memset(vf->bulletin.p_virt, 0, sizeof(*vf->bulletin.p_virt));
831
832 memset(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
833
Yuval Mintz0b55e272016-05-11 16:36:15 +0300834 if (vf->state != VF_STOPPED) {
835 /* Stopping the VF */
836 rc = qed_sp_vf_stop(p_hwfn, vf->concrete_fid, vf->opaque_fid);
837
838 if (rc != 0) {
839 DP_ERR(p_hwfn, "qed_sp_vf_stop returned error %d\n",
840 rc);
841 return rc;
842 }
843
844 vf->state = VF_STOPPED;
845 }
846
847 /* disablng interrupts and resetting permission table was done during
848 * vf-close, however, we could get here without going through vf_close
849 */
850 /* Disable Interrupts for VF */
851 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
852
853 /* Reset Permission table */
854 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
855
856 vf->num_rxqs = 0;
857 vf->num_txqs = 0;
858 qed_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
859
860 if (vf->b_init) {
861 vf->b_init = false;
862
863 if (IS_LEAD_HWFN(p_hwfn))
864 p_hwfn->cdev->p_iov_info->num_vfs--;
865 }
866
867 return 0;
868}
869
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300870static bool qed_iov_tlv_supported(u16 tlvtype)
871{
872 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
873}
874
875/* place a given tlv on the tlv buffer, continuing current tlv list */
876void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length)
877{
878 struct channel_tlv *tl = (struct channel_tlv *)*offset;
879
880 tl->type = type;
881 tl->length = length;
882
883 /* Offset should keep pointing to next TLV (the end of the last) */
884 *offset += length;
885
886 /* Return a pointer to the start of the added tlv */
887 return *offset - length;
888}
889
890/* list the types and lengths of the tlvs on the buffer */
891void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list)
892{
893 u16 i = 1, total_length = 0;
894 struct channel_tlv *tlv;
895
896 do {
897 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
898
899 /* output tlv */
900 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
901 "TLV number %d: type %d, length %d\n",
902 i, tlv->type, tlv->length);
903
904 if (tlv->type == CHANNEL_TLV_LIST_END)
905 return;
906
907 /* Validate entry - protect against malicious VFs */
908 if (!tlv->length) {
909 DP_NOTICE(p_hwfn, "TLV of length 0 found\n");
910 return;
911 }
912
913 total_length += tlv->length;
914
915 if (total_length >= sizeof(struct tlv_buffer_size)) {
916 DP_NOTICE(p_hwfn, "TLV ==> Buffer overflow\n");
917 return;
918 }
919
920 i++;
921 } while (1);
922}
923
924static void qed_iov_send_response(struct qed_hwfn *p_hwfn,
925 struct qed_ptt *p_ptt,
926 struct qed_vf_info *p_vf,
927 u16 length, u8 status)
928{
929 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
930 struct qed_dmae_params params;
931 u8 eng_vf_id;
932
933 mbx->reply_virt->default_resp.hdr.status = status;
934
935 qed_dp_tlv_list(p_hwfn, mbx->reply_virt);
936
937 eng_vf_id = p_vf->abs_vf_id;
938
939 memset(&params, 0, sizeof(struct qed_dmae_params));
940 params.flags = QED_DMAE_FLAG_VF_DST;
941 params.dst_vfid = eng_vf_id;
942
943 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
944 mbx->req_virt->first_tlv.reply_address +
945 sizeof(u64),
946 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
947 &params);
948
949 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
950 mbx->req_virt->first_tlv.reply_address,
951 sizeof(u64) / 4, &params);
952
953 REG_WR(p_hwfn,
954 GTT_BAR0_MAP_REG_USDM_RAM +
955 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
956}
957
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300958static u16 qed_iov_vport_to_tlv(struct qed_hwfn *p_hwfn,
959 enum qed_iov_vport_update_flag flag)
960{
961 switch (flag) {
962 case QED_IOV_VP_UPDATE_ACTIVATE:
963 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
964 case QED_IOV_VP_UPDATE_MCAST:
965 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
966 case QED_IOV_VP_UPDATE_ACCEPT_PARAM:
967 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
968 case QED_IOV_VP_UPDATE_RSS:
969 return CHANNEL_TLV_VPORT_UPDATE_RSS;
970 default:
971 return 0;
972 }
973}
974
975static u16 qed_iov_prep_vp_update_resp_tlvs(struct qed_hwfn *p_hwfn,
976 struct qed_vf_info *p_vf,
977 struct qed_iov_vf_mbx *p_mbx,
978 u8 status,
979 u16 tlvs_mask, u16 tlvs_accepted)
980{
981 struct pfvf_def_resp_tlv *resp;
982 u16 size, total_len, i;
983
984 memset(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
985 p_mbx->offset = (u8 *)p_mbx->reply_virt;
986 size = sizeof(struct pfvf_def_resp_tlv);
987 total_len = size;
988
989 qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
990
991 /* Prepare response for all extended tlvs if they are found by PF */
992 for (i = 0; i < QED_IOV_VP_UPDATE_MAX; i++) {
993 if (!(tlvs_mask & (1 << i)))
994 continue;
995
996 resp = qed_add_tlv(p_hwfn, &p_mbx->offset,
997 qed_iov_vport_to_tlv(p_hwfn, i), size);
998
999 if (tlvs_accepted & (1 << i))
1000 resp->hdr.status = status;
1001 else
1002 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1003
1004 DP_VERBOSE(p_hwfn,
1005 QED_MSG_IOV,
1006 "VF[%d] - vport_update response: TLV %d, status %02x\n",
1007 p_vf->relative_vf_id,
1008 qed_iov_vport_to_tlv(p_hwfn, i), resp->hdr.status);
1009
1010 total_len += size;
1011 }
1012
1013 qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_LIST_END,
1014 sizeof(struct channel_list_end_tlv));
1015
1016 return total_len;
1017}
1018
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001019static void qed_iov_prepare_resp(struct qed_hwfn *p_hwfn,
1020 struct qed_ptt *p_ptt,
1021 struct qed_vf_info *vf_info,
1022 u16 type, u16 length, u8 status)
1023{
1024 struct qed_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1025
1026 mbx->offset = (u8 *)mbx->reply_virt;
1027
1028 qed_add_tlv(p_hwfn, &mbx->offset, type, length);
1029 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1030 sizeof(struct channel_list_end_tlv));
1031
1032 qed_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1033}
1034
Yuval Mintz0b55e272016-05-11 16:36:15 +03001035struct qed_public_vf_info *qed_iov_get_public_vf_info(struct qed_hwfn *p_hwfn,
1036 u16 relative_vf_id,
1037 bool b_enabled_only)
1038{
1039 struct qed_vf_info *vf = NULL;
1040
1041 vf = qed_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1042 if (!vf)
1043 return NULL;
1044
1045 return &vf->p_vf_info;
1046}
1047
1048void qed_iov_clean_vf(struct qed_hwfn *p_hwfn, u8 vfid)
1049{
1050 struct qed_public_vf_info *vf_info;
1051
1052 vf_info = qed_iov_get_public_vf_info(p_hwfn, vfid, false);
1053
1054 if (!vf_info)
1055 return;
1056
1057 /* Clear the VF mac */
1058 memset(vf_info->mac, 0, ETH_ALEN);
1059}
1060
1061static void qed_iov_vf_cleanup(struct qed_hwfn *p_hwfn,
1062 struct qed_vf_info *p_vf)
1063{
1064 u32 i;
1065
1066 p_vf->vf_bulletin = 0;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001067 p_vf->vport_instance = 0;
Yuval Mintz0b55e272016-05-11 16:36:15 +03001068 p_vf->num_mac_filters = 0;
1069 p_vf->num_vlan_filters = 0;
1070
1071 /* If VF previously requested less resources, go back to default */
1072 p_vf->num_rxqs = p_vf->num_sbs;
1073 p_vf->num_txqs = p_vf->num_sbs;
1074
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001075 p_vf->num_active_rxqs = 0;
1076
Yuval Mintz0b55e272016-05-11 16:36:15 +03001077 for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++)
1078 p_vf->vf_queues[i].rxq_active = 0;
1079
1080 qed_iov_clean_vf(p_hwfn, p_vf->relative_vf_id);
1081}
1082
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001083static void qed_iov_vf_mbx_acquire(struct qed_hwfn *p_hwfn,
1084 struct qed_ptt *p_ptt,
1085 struct qed_vf_info *vf)
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001086{
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001087 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1088 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1089 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1090 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1091 u8 i, vfpf_status = PFVF_STATUS_SUCCESS;
1092 struct pf_vf_resc *resc = &resp->resc;
1093
1094 /* Validate FW compatibility */
1095 if (req->vfdev_info.fw_major != FW_MAJOR_VERSION ||
1096 req->vfdev_info.fw_minor != FW_MINOR_VERSION ||
1097 req->vfdev_info.fw_revision != FW_REVISION_VERSION ||
1098 req->vfdev_info.fw_engineering != FW_ENGINEERING_VERSION) {
1099 DP_INFO(p_hwfn,
1100 "VF[%d] is running an incompatible driver [VF needs FW %02x:%02x:%02x:%02x but Hypervisor is using %02x:%02x:%02x:%02x]\n",
1101 vf->abs_vf_id,
1102 req->vfdev_info.fw_major,
1103 req->vfdev_info.fw_minor,
1104 req->vfdev_info.fw_revision,
1105 req->vfdev_info.fw_engineering,
1106 FW_MAJOR_VERSION,
1107 FW_MINOR_VERSION,
1108 FW_REVISION_VERSION, FW_ENGINEERING_VERSION);
1109 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1110 goto out;
1111 }
1112
1113 /* On 100g PFs, prevent old VFs from loading */
1114 if ((p_hwfn->cdev->num_hwfns > 1) &&
1115 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1116 DP_INFO(p_hwfn,
1117 "VF[%d] is running an old driver that doesn't support 100g\n",
1118 vf->abs_vf_id);
1119 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1120 goto out;
1121 }
1122
1123 memset(resp, 0, sizeof(*resp));
1124
1125 /* Fill in vf info stuff */
1126 vf->opaque_fid = req->vfdev_info.opaque_fid;
1127 vf->num_mac_filters = 1;
1128 vf->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
1129
1130 vf->vf_bulletin = req->bulletin_addr;
1131 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1132 vf->bulletin.size : req->bulletin_size;
1133
1134 /* fill in pfdev info */
1135 pfdev_info->chip_num = p_hwfn->cdev->chip_num;
1136 pfdev_info->db_size = 0;
1137 pfdev_info->indices_per_sb = PIS_PER_SB;
1138
1139 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1140 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1141 if (p_hwfn->cdev->num_hwfns > 1)
1142 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1143
1144 pfdev_info->stats_info.mstats.address =
1145 PXP_VF_BAR0_START_MSDM_ZONE_B +
1146 offsetof(struct mstorm_vf_zone, non_trigger.eth_queue_stat);
1147 pfdev_info->stats_info.mstats.len =
1148 sizeof(struct eth_mstorm_per_queue_stat);
1149
1150 pfdev_info->stats_info.ustats.address =
1151 PXP_VF_BAR0_START_USDM_ZONE_B +
1152 offsetof(struct ustorm_vf_zone, non_trigger.eth_queue_stat);
1153 pfdev_info->stats_info.ustats.len =
1154 sizeof(struct eth_ustorm_per_queue_stat);
1155
1156 pfdev_info->stats_info.pstats.address =
1157 PXP_VF_BAR0_START_PSDM_ZONE_B +
1158 offsetof(struct pstorm_vf_zone, non_trigger.eth_queue_stat);
1159 pfdev_info->stats_info.pstats.len =
1160 sizeof(struct eth_pstorm_per_queue_stat);
1161
1162 pfdev_info->stats_info.tstats.address = 0;
1163 pfdev_info->stats_info.tstats.len = 0;
1164
1165 memcpy(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr, ETH_ALEN);
1166
1167 pfdev_info->fw_major = FW_MAJOR_VERSION;
1168 pfdev_info->fw_minor = FW_MINOR_VERSION;
1169 pfdev_info->fw_rev = FW_REVISION_VERSION;
1170 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1171 pfdev_info->os_type = VFPF_ACQUIRE_OS_LINUX;
1172 qed_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver, NULL);
1173
1174 pfdev_info->dev_type = p_hwfn->cdev->type;
1175 pfdev_info->chip_rev = p_hwfn->cdev->chip_rev;
1176
1177 resc->num_rxqs = vf->num_rxqs;
1178 resc->num_txqs = vf->num_txqs;
1179 resc->num_sbs = vf->num_sbs;
1180 for (i = 0; i < resc->num_sbs; i++) {
1181 resc->hw_sbs[i].hw_sb_id = vf->igu_sbs[i];
1182 resc->hw_sbs[i].sb_qid = 0;
1183 }
1184
1185 for (i = 0; i < resc->num_rxqs; i++) {
1186 qed_fw_l2_queue(p_hwfn, vf->vf_queues[i].fw_rx_qid,
1187 (u16 *)&resc->hw_qid[i]);
1188 resc->cid[i] = vf->vf_queues[i].fw_cid;
1189 }
1190
1191 resc->num_mac_filters = min_t(u8, vf->num_mac_filters,
1192 req->resc_request.num_mac_filters);
1193 resc->num_vlan_filters = min_t(u8, vf->num_vlan_filters,
1194 req->resc_request.num_vlan_filters);
1195
1196 /* This isn't really required as VF isn't limited, but some VFs might
1197 * actually test this value, so need to provide it.
1198 */
1199 resc->num_mc_filters = req->resc_request.num_mc_filters;
1200
1201 /* Fill agreed size of bulletin board in response */
1202 resp->bulletin_size = vf->bulletin.size;
Yuval Mintz36558c32016-05-11 16:36:17 +03001203 qed_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001204
1205 DP_VERBOSE(p_hwfn,
1206 QED_MSG_IOV,
1207 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%llx\n"
1208 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d\n",
1209 vf->abs_vf_id,
1210 resp->pfdev_info.chip_num,
1211 resp->pfdev_info.db_size,
1212 resp->pfdev_info.indices_per_sb,
1213 resp->pfdev_info.capabilities,
1214 resc->num_rxqs,
1215 resc->num_txqs,
1216 resc->num_sbs,
1217 resc->num_mac_filters,
1218 resc->num_vlan_filters);
1219 vf->state = VF_ACQUIRED;
1220
1221 /* Prepare Response */
1222out:
1223 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1224 sizeof(struct pfvf_acquire_resp_tlv), vfpf_status);
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001225}
1226
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001227static void qed_iov_vf_mbx_start_vport(struct qed_hwfn *p_hwfn,
1228 struct qed_ptt *p_ptt,
1229 struct qed_vf_info *vf)
1230{
1231 struct qed_sp_vport_start_params params = { 0 };
1232 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1233 struct vfpf_vport_start_tlv *start;
1234 u8 status = PFVF_STATUS_SUCCESS;
1235 struct qed_vf_info *vf_info;
1236 int sb_id;
1237 int rc;
1238
1239 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vf->relative_vf_id, true);
1240 if (!vf_info) {
1241 DP_NOTICE(p_hwfn->cdev,
1242 "Failed to get VF info, invalid vfid [%d]\n",
1243 vf->relative_vf_id);
1244 return;
1245 }
1246
1247 vf->state = VF_ENABLED;
1248 start = &mbx->req_virt->start_vport;
1249
1250 /* Initialize Status block in CAU */
1251 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
1252 if (!start->sb_addr[sb_id]) {
1253 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1254 "VF[%d] did not fill the address of SB %d\n",
1255 vf->relative_vf_id, sb_id);
1256 break;
1257 }
1258
1259 qed_int_cau_conf_sb(p_hwfn, p_ptt,
1260 start->sb_addr[sb_id],
1261 vf->igu_sbs[sb_id],
1262 vf->abs_vf_id, 1);
1263 }
1264 qed_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
1265
1266 vf->mtu = start->mtu;
1267
1268 params.tpa_mode = start->tpa_mode;
1269 params.remove_inner_vlan = start->inner_vlan_removal;
1270
1271 params.drop_ttl0 = false;
1272 params.concrete_fid = vf->concrete_fid;
1273 params.opaque_fid = vf->opaque_fid;
1274 params.vport_id = vf->vport_id;
1275 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
1276 params.mtu = vf->mtu;
1277
1278 rc = qed_sp_eth_vport_start(p_hwfn, &params);
1279 if (rc != 0) {
1280 DP_ERR(p_hwfn,
1281 "qed_iov_vf_mbx_start_vport returned error %d\n", rc);
1282 status = PFVF_STATUS_FAILURE;
1283 } else {
1284 vf->vport_instance++;
1285 }
1286 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
1287 sizeof(struct pfvf_def_resp_tlv), status);
1288}
1289
1290static void qed_iov_vf_mbx_stop_vport(struct qed_hwfn *p_hwfn,
1291 struct qed_ptt *p_ptt,
1292 struct qed_vf_info *vf)
1293{
1294 u8 status = PFVF_STATUS_SUCCESS;
1295 int rc;
1296
1297 vf->vport_instance--;
1298
1299 rc = qed_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
1300 if (rc != 0) {
1301 DP_ERR(p_hwfn, "qed_iov_vf_mbx_stop_vport returned error %d\n",
1302 rc);
1303 status = PFVF_STATUS_FAILURE;
1304 }
1305
1306 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
1307 sizeof(struct pfvf_def_resp_tlv), status);
1308}
1309
1310#define TSTORM_QZONE_START PXP_VF_BAR0_START_SDM_ZONE_A
1311#define MSTORM_QZONE_START(dev) (TSTORM_QZONE_START + \
1312 (TSTORM_QZONE_SIZE * NUM_OF_L2_QUEUES(dev)))
1313
1314static void qed_iov_vf_mbx_start_rxq_resp(struct qed_hwfn *p_hwfn,
1315 struct qed_ptt *p_ptt,
1316 struct qed_vf_info *vf, u8 status)
1317{
1318 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1319 struct pfvf_start_queue_resp_tlv *p_tlv;
1320 struct vfpf_start_rxq_tlv *req;
1321
1322 mbx->offset = (u8 *)mbx->reply_virt;
1323
1324 p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_RXQ,
1325 sizeof(*p_tlv));
1326 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1327 sizeof(struct channel_list_end_tlv));
1328
1329 /* Update the TLV with the response */
1330 if (status == PFVF_STATUS_SUCCESS) {
1331 u16 hw_qid = 0;
1332
1333 req = &mbx->req_virt->start_rxq;
1334 qed_fw_l2_queue(p_hwfn, vf->vf_queues[req->rx_qid].fw_rx_qid,
1335 &hw_qid);
1336
1337 p_tlv->offset = MSTORM_QZONE_START(p_hwfn->cdev) +
1338 hw_qid * MSTORM_QZONE_SIZE +
1339 offsetof(struct mstorm_eth_queue_zone,
1340 rx_producers);
1341 }
1342
1343 qed_iov_send_response(p_hwfn, p_ptt, vf, sizeof(*p_tlv), status);
1344}
1345
1346static void qed_iov_vf_mbx_start_rxq(struct qed_hwfn *p_hwfn,
1347 struct qed_ptt *p_ptt,
1348 struct qed_vf_info *vf)
1349{
1350 struct qed_queue_start_common_params params;
1351 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1352 u8 status = PFVF_STATUS_SUCCESS;
1353 struct vfpf_start_rxq_tlv *req;
1354 int rc;
1355
1356 memset(&params, 0, sizeof(params));
1357 req = &mbx->req_virt->start_rxq;
1358 params.queue_id = vf->vf_queues[req->rx_qid].fw_rx_qid;
1359 params.vport_id = vf->vport_id;
1360 params.sb = req->hw_sb;
1361 params.sb_idx = req->sb_index;
1362
1363 rc = qed_sp_eth_rxq_start_ramrod(p_hwfn, vf->opaque_fid,
1364 vf->vf_queues[req->rx_qid].fw_cid,
1365 &params,
1366 vf->abs_vf_id + 0x10,
1367 req->bd_max_bytes,
1368 req->rxq_addr,
1369 req->cqe_pbl_addr, req->cqe_pbl_size);
1370
1371 if (rc) {
1372 status = PFVF_STATUS_FAILURE;
1373 } else {
1374 vf->vf_queues[req->rx_qid].rxq_active = true;
1375 vf->num_active_rxqs++;
1376 }
1377
1378 qed_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status);
1379}
1380
1381static void qed_iov_vf_mbx_start_txq(struct qed_hwfn *p_hwfn,
1382 struct qed_ptt *p_ptt,
1383 struct qed_vf_info *vf)
1384{
1385 u16 length = sizeof(struct pfvf_def_resp_tlv);
1386 struct qed_queue_start_common_params params;
1387 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1388 union qed_qm_pq_params pq_params;
1389 u8 status = PFVF_STATUS_SUCCESS;
1390 struct vfpf_start_txq_tlv *req;
1391 int rc;
1392
1393 /* Prepare the parameters which would choose the right PQ */
1394 memset(&pq_params, 0, sizeof(pq_params));
1395 pq_params.eth.is_vf = 1;
1396 pq_params.eth.vf_id = vf->relative_vf_id;
1397
1398 memset(&params, 0, sizeof(params));
1399 req = &mbx->req_virt->start_txq;
1400 params.queue_id = vf->vf_queues[req->tx_qid].fw_tx_qid;
1401 params.vport_id = vf->vport_id;
1402 params.sb = req->hw_sb;
1403 params.sb_idx = req->sb_index;
1404
1405 rc = qed_sp_eth_txq_start_ramrod(p_hwfn,
1406 vf->opaque_fid,
1407 vf->vf_queues[req->tx_qid].fw_cid,
1408 &params,
1409 vf->abs_vf_id + 0x10,
1410 req->pbl_addr,
1411 req->pbl_size, &pq_params);
1412
1413 if (rc)
1414 status = PFVF_STATUS_FAILURE;
1415 else
1416 vf->vf_queues[req->tx_qid].txq_active = true;
1417
1418 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_START_TXQ,
1419 length, status);
1420}
1421
1422static int qed_iov_vf_stop_rxqs(struct qed_hwfn *p_hwfn,
1423 struct qed_vf_info *vf,
1424 u16 rxq_id, u8 num_rxqs, bool cqe_completion)
1425{
1426 int rc = 0;
1427 int qid;
1428
1429 if (rxq_id + num_rxqs > ARRAY_SIZE(vf->vf_queues))
1430 return -EINVAL;
1431
1432 for (qid = rxq_id; qid < rxq_id + num_rxqs; qid++) {
1433 if (vf->vf_queues[qid].rxq_active) {
1434 rc = qed_sp_eth_rx_queue_stop(p_hwfn,
1435 vf->vf_queues[qid].
1436 fw_rx_qid, false,
1437 cqe_completion);
1438
1439 if (rc)
1440 return rc;
1441 }
1442 vf->vf_queues[qid].rxq_active = false;
1443 vf->num_active_rxqs--;
1444 }
1445
1446 return rc;
1447}
1448
1449static int qed_iov_vf_stop_txqs(struct qed_hwfn *p_hwfn,
1450 struct qed_vf_info *vf, u16 txq_id, u8 num_txqs)
1451{
1452 int rc = 0;
1453 int qid;
1454
1455 if (txq_id + num_txqs > ARRAY_SIZE(vf->vf_queues))
1456 return -EINVAL;
1457
1458 for (qid = txq_id; qid < txq_id + num_txqs; qid++) {
1459 if (vf->vf_queues[qid].txq_active) {
1460 rc = qed_sp_eth_tx_queue_stop(p_hwfn,
1461 vf->vf_queues[qid].
1462 fw_tx_qid);
1463
1464 if (rc)
1465 return rc;
1466 }
1467 vf->vf_queues[qid].txq_active = false;
1468 }
1469 return rc;
1470}
1471
1472static void qed_iov_vf_mbx_stop_rxqs(struct qed_hwfn *p_hwfn,
1473 struct qed_ptt *p_ptt,
1474 struct qed_vf_info *vf)
1475{
1476 u16 length = sizeof(struct pfvf_def_resp_tlv);
1477 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1478 u8 status = PFVF_STATUS_SUCCESS;
1479 struct vfpf_stop_rxqs_tlv *req;
1480 int rc;
1481
1482 /* We give the option of starting from qid != 0, in this case we
1483 * need to make sure that qid + num_qs doesn't exceed the actual
1484 * amount of queues that exist.
1485 */
1486 req = &mbx->req_virt->stop_rxqs;
1487 rc = qed_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
1488 req->num_rxqs, req->cqe_completion);
1489 if (rc)
1490 status = PFVF_STATUS_FAILURE;
1491
1492 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
1493 length, status);
1494}
1495
1496static void qed_iov_vf_mbx_stop_txqs(struct qed_hwfn *p_hwfn,
1497 struct qed_ptt *p_ptt,
1498 struct qed_vf_info *vf)
1499{
1500 u16 length = sizeof(struct pfvf_def_resp_tlv);
1501 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1502 u8 status = PFVF_STATUS_SUCCESS;
1503 struct vfpf_stop_txqs_tlv *req;
1504 int rc;
1505
1506 /* We give the option of starting from qid != 0, in this case we
1507 * need to make sure that qid + num_qs doesn't exceed the actual
1508 * amount of queues that exist.
1509 */
1510 req = &mbx->req_virt->stop_txqs;
1511 rc = qed_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid, req->num_txqs);
1512 if (rc)
1513 status = PFVF_STATUS_FAILURE;
1514
1515 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
1516 length, status);
1517}
1518
1519void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
1520 void *p_tlvs_list, u16 req_type)
1521{
1522 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
1523 int len = 0;
1524
1525 do {
1526 if (!p_tlv->length) {
1527 DP_NOTICE(p_hwfn, "Zero length TLV found\n");
1528 return NULL;
1529 }
1530
1531 if (p_tlv->type == req_type) {
1532 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1533 "Extended tlv type %d, length %d found\n",
1534 p_tlv->type, p_tlv->length);
1535 return p_tlv;
1536 }
1537
1538 len += p_tlv->length;
1539 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
1540
1541 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
1542 DP_NOTICE(p_hwfn, "TLVs has overrun the buffer size\n");
1543 return NULL;
1544 }
1545 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
1546
1547 return NULL;
1548}
1549
1550static void
1551qed_iov_vp_update_act_param(struct qed_hwfn *p_hwfn,
1552 struct qed_sp_vport_update_params *p_data,
1553 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
1554{
1555 struct vfpf_vport_update_activate_tlv *p_act_tlv;
1556 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1557
1558 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
1559 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
1560 if (!p_act_tlv)
1561 return;
1562
1563 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
1564 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
1565 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
1566 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
1567 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACTIVATE;
1568}
1569
1570static void
1571qed_iov_vp_update_mcast_bin_param(struct qed_hwfn *p_hwfn,
1572 struct qed_sp_vport_update_params *p_data,
1573 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
1574{
1575 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
1576 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
1577
1578 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
1579 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
1580 if (!p_mcast_tlv)
1581 return;
1582
1583 p_data->update_approx_mcast_flg = 1;
1584 memcpy(p_data->bins, p_mcast_tlv->bins,
1585 sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS);
1586 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_MCAST;
1587}
1588
1589static void
1590qed_iov_vp_update_accept_flag(struct qed_hwfn *p_hwfn,
1591 struct qed_sp_vport_update_params *p_data,
1592 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
1593{
1594 struct qed_filter_accept_flags *p_flags = &p_data->accept_flags;
1595 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
1596 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1597
1598 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
1599 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
1600 if (!p_accept_tlv)
1601 return;
1602
1603 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
1604 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
1605 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
1606 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
1607 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_PARAM;
1608}
1609
1610static void
1611qed_iov_vp_update_rss_param(struct qed_hwfn *p_hwfn,
1612 struct qed_vf_info *vf,
1613 struct qed_sp_vport_update_params *p_data,
1614 struct qed_rss_params *p_rss,
1615 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
1616{
1617 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
1618 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
1619 u16 i, q_idx, max_q_idx;
1620 u16 table_size;
1621
1622 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
1623 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
1624 if (!p_rss_tlv) {
1625 p_data->rss_params = NULL;
1626 return;
1627 }
1628
1629 memset(p_rss, 0, sizeof(struct qed_rss_params));
1630
1631 p_rss->update_rss_config = !!(p_rss_tlv->update_rss_flags &
1632 VFPF_UPDATE_RSS_CONFIG_FLAG);
1633 p_rss->update_rss_capabilities = !!(p_rss_tlv->update_rss_flags &
1634 VFPF_UPDATE_RSS_CAPS_FLAG);
1635 p_rss->update_rss_ind_table = !!(p_rss_tlv->update_rss_flags &
1636 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
1637 p_rss->update_rss_key = !!(p_rss_tlv->update_rss_flags &
1638 VFPF_UPDATE_RSS_KEY_FLAG);
1639
1640 p_rss->rss_enable = p_rss_tlv->rss_enable;
1641 p_rss->rss_eng_id = vf->relative_vf_id + 1;
1642 p_rss->rss_caps = p_rss_tlv->rss_caps;
1643 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
1644 memcpy(p_rss->rss_ind_table, p_rss_tlv->rss_ind_table,
1645 sizeof(p_rss->rss_ind_table));
1646 memcpy(p_rss->rss_key, p_rss_tlv->rss_key, sizeof(p_rss->rss_key));
1647
1648 table_size = min_t(u16, ARRAY_SIZE(p_rss->rss_ind_table),
1649 (1 << p_rss_tlv->rss_table_size_log));
1650
1651 max_q_idx = ARRAY_SIZE(vf->vf_queues);
1652
1653 for (i = 0; i < table_size; i++) {
1654 u16 index = vf->vf_queues[0].fw_rx_qid;
1655
1656 q_idx = p_rss->rss_ind_table[i];
1657 if (q_idx >= max_q_idx)
1658 DP_NOTICE(p_hwfn,
1659 "rss_ind_table[%d] = %d, rxq is out of range\n",
1660 i, q_idx);
1661 else if (!vf->vf_queues[q_idx].rxq_active)
1662 DP_NOTICE(p_hwfn,
1663 "rss_ind_table[%d] = %d, rxq is not active\n",
1664 i, q_idx);
1665 else
1666 index = vf->vf_queues[q_idx].fw_rx_qid;
1667 p_rss->rss_ind_table[i] = index;
1668 }
1669
1670 p_data->rss_params = p_rss;
1671 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_RSS;
1672}
1673
1674static void qed_iov_vf_mbx_vport_update(struct qed_hwfn *p_hwfn,
1675 struct qed_ptt *p_ptt,
1676 struct qed_vf_info *vf)
1677{
1678 struct qed_sp_vport_update_params params;
1679 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1680 struct qed_rss_params rss_params;
1681 u8 status = PFVF_STATUS_SUCCESS;
1682 u16 tlvs_mask = 0;
1683 u16 length;
1684 int rc;
1685
1686 memset(&params, 0, sizeof(params));
1687 params.opaque_fid = vf->opaque_fid;
1688 params.vport_id = vf->vport_id;
1689 params.rss_params = NULL;
1690
1691 /* Search for extended tlvs list and update values
1692 * from VF in struct qed_sp_vport_update_params.
1693 */
1694 qed_iov_vp_update_act_param(p_hwfn, &params, mbx, &tlvs_mask);
1695 qed_iov_vp_update_mcast_bin_param(p_hwfn, &params, mbx, &tlvs_mask);
1696 qed_iov_vp_update_accept_flag(p_hwfn, &params, mbx, &tlvs_mask);
1697 qed_iov_vp_update_rss_param(p_hwfn, vf, &params, &rss_params,
1698 mbx, &tlvs_mask);
1699
1700 /* Just log a message if there is no single extended tlv in buffer.
1701 * When all features of vport update ramrod would be requested by VF
1702 * as extended TLVs in buffer then an error can be returned in response
1703 * if there is no extended TLV present in buffer.
1704 */
1705 if (!tlvs_mask) {
1706 DP_NOTICE(p_hwfn,
1707 "No feature tlvs found for vport update\n");
1708 status = PFVF_STATUS_NOT_SUPPORTED;
1709 goto out;
1710 }
1711
1712 rc = qed_sp_vport_update(p_hwfn, &params, QED_SPQ_MODE_EBLOCK, NULL);
1713
1714 if (rc)
1715 status = PFVF_STATUS_FAILURE;
1716
1717out:
1718 length = qed_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
1719 tlvs_mask, tlvs_mask);
1720 qed_iov_send_response(p_hwfn, p_ptt, vf, length, status);
1721}
1722
1723int qed_iov_chk_ucast(struct qed_hwfn *hwfn,
1724 int vfid, struct qed_filter_ucast *params)
1725{
1726 struct qed_public_vf_info *vf;
1727
1728 vf = qed_iov_get_public_vf_info(hwfn, vfid, true);
1729 if (!vf)
1730 return -EINVAL;
1731
1732 /* No real decision to make; Store the configured MAC */
1733 if (params->type == QED_FILTER_MAC ||
1734 params->type == QED_FILTER_MAC_VLAN)
1735 ether_addr_copy(vf->mac, params->mac);
1736
1737 return 0;
1738}
1739
1740static void qed_iov_vf_mbx_ucast_filter(struct qed_hwfn *p_hwfn,
1741 struct qed_ptt *p_ptt,
1742 struct qed_vf_info *vf)
1743{
1744 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1745 struct vfpf_ucast_filter_tlv *req;
1746 u8 status = PFVF_STATUS_SUCCESS;
1747 struct qed_filter_ucast params;
1748 int rc;
1749
1750 /* Prepare the unicast filter params */
1751 memset(&params, 0, sizeof(struct qed_filter_ucast));
1752 req = &mbx->req_virt->ucast_filter;
1753 params.opcode = (enum qed_filter_opcode)req->opcode;
1754 params.type = (enum qed_filter_ucast_type)req->type;
1755
1756 params.is_rx_filter = 1;
1757 params.is_tx_filter = 1;
1758 params.vport_to_remove_from = vf->vport_id;
1759 params.vport_to_add_to = vf->vport_id;
1760 memcpy(params.mac, req->mac, ETH_ALEN);
1761 params.vlan = req->vlan;
1762
1763 DP_VERBOSE(p_hwfn,
1764 QED_MSG_IOV,
1765 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x] MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
1766 vf->abs_vf_id, params.opcode, params.type,
1767 params.is_rx_filter ? "RX" : "",
1768 params.is_tx_filter ? "TX" : "",
1769 params.vport_to_add_to,
1770 params.mac[0], params.mac[1],
1771 params.mac[2], params.mac[3],
1772 params.mac[4], params.mac[5], params.vlan);
1773
1774 if (!vf->vport_instance) {
1775 DP_VERBOSE(p_hwfn,
1776 QED_MSG_IOV,
1777 "No VPORT instance available for VF[%d], failing ucast MAC configuration\n",
1778 vf->abs_vf_id);
1779 status = PFVF_STATUS_FAILURE;
1780 goto out;
1781 }
1782
1783 rc = qed_iov_chk_ucast(p_hwfn, vf->relative_vf_id, &params);
1784 if (rc) {
1785 status = PFVF_STATUS_FAILURE;
1786 goto out;
1787 }
1788
1789 rc = qed_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, &params,
1790 QED_SPQ_MODE_CB, NULL);
1791 if (rc)
1792 status = PFVF_STATUS_FAILURE;
1793
1794out:
1795 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
1796 sizeof(struct pfvf_def_resp_tlv), status);
1797}
1798
Yuval Mintz0b55e272016-05-11 16:36:15 +03001799static void qed_iov_vf_mbx_int_cleanup(struct qed_hwfn *p_hwfn,
1800 struct qed_ptt *p_ptt,
1801 struct qed_vf_info *vf)
1802{
1803 int i;
1804
1805 /* Reset the SBs */
1806 for (i = 0; i < vf->num_sbs; i++)
1807 qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
1808 vf->igu_sbs[i],
1809 vf->opaque_fid, false);
1810
1811 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
1812 sizeof(struct pfvf_def_resp_tlv),
1813 PFVF_STATUS_SUCCESS);
1814}
1815
1816static void qed_iov_vf_mbx_close(struct qed_hwfn *p_hwfn,
1817 struct qed_ptt *p_ptt, struct qed_vf_info *vf)
1818{
1819 u16 length = sizeof(struct pfvf_def_resp_tlv);
1820 u8 status = PFVF_STATUS_SUCCESS;
1821
1822 /* Disable Interrupts for VF */
1823 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1824
1825 /* Reset Permission table */
1826 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1827
1828 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
1829 length, status);
1830}
1831
1832static void qed_iov_vf_mbx_release(struct qed_hwfn *p_hwfn,
1833 struct qed_ptt *p_ptt,
1834 struct qed_vf_info *p_vf)
1835{
1836 u16 length = sizeof(struct pfvf_def_resp_tlv);
1837
1838 qed_iov_vf_cleanup(p_hwfn, p_vf);
1839
1840 qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
1841 length, PFVF_STATUS_SUCCESS);
1842}
1843
1844static int
1845qed_iov_vf_flr_poll_dorq(struct qed_hwfn *p_hwfn,
1846 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
1847{
1848 int cnt;
1849 u32 val;
1850
1851 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_vf->concrete_fid);
1852
1853 for (cnt = 0; cnt < 50; cnt++) {
1854 val = qed_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
1855 if (!val)
1856 break;
1857 msleep(20);
1858 }
1859 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
1860
1861 if (cnt == 50) {
1862 DP_ERR(p_hwfn,
1863 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
1864 p_vf->abs_vf_id, val);
1865 return -EBUSY;
1866 }
1867
1868 return 0;
1869}
1870
1871static int
1872qed_iov_vf_flr_poll_pbf(struct qed_hwfn *p_hwfn,
1873 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
1874{
1875 u32 cons[MAX_NUM_VOQS], distance[MAX_NUM_VOQS];
1876 int i, cnt;
1877
1878 /* Read initial consumers & producers */
1879 for (i = 0; i < MAX_NUM_VOQS; i++) {
1880 u32 prod;
1881
1882 cons[i] = qed_rd(p_hwfn, p_ptt,
1883 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
1884 i * 0x40);
1885 prod = qed_rd(p_hwfn, p_ptt,
1886 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
1887 i * 0x40);
1888 distance[i] = prod - cons[i];
1889 }
1890
1891 /* Wait for consumers to pass the producers */
1892 i = 0;
1893 for (cnt = 0; cnt < 50; cnt++) {
1894 for (; i < MAX_NUM_VOQS; i++) {
1895 u32 tmp;
1896
1897 tmp = qed_rd(p_hwfn, p_ptt,
1898 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
1899 i * 0x40);
1900 if (distance[i] > tmp - cons[i])
1901 break;
1902 }
1903
1904 if (i == MAX_NUM_VOQS)
1905 break;
1906
1907 msleep(20);
1908 }
1909
1910 if (cnt == 50) {
1911 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
1912 p_vf->abs_vf_id, i);
1913 return -EBUSY;
1914 }
1915
1916 return 0;
1917}
1918
1919static int qed_iov_vf_flr_poll(struct qed_hwfn *p_hwfn,
1920 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
1921{
1922 int rc;
1923
1924 rc = qed_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
1925 if (rc)
1926 return rc;
1927
1928 rc = qed_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
1929 if (rc)
1930 return rc;
1931
1932 return 0;
1933}
1934
1935static int
1936qed_iov_execute_vf_flr_cleanup(struct qed_hwfn *p_hwfn,
1937 struct qed_ptt *p_ptt,
1938 u16 rel_vf_id, u32 *ack_vfs)
1939{
1940 struct qed_vf_info *p_vf;
1941 int rc = 0;
1942
1943 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
1944 if (!p_vf)
1945 return 0;
1946
1947 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
1948 (1ULL << (rel_vf_id % 64))) {
1949 u16 vfid = p_vf->abs_vf_id;
1950
1951 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1952 "VF[%d] - Handling FLR\n", vfid);
1953
1954 qed_iov_vf_cleanup(p_hwfn, p_vf);
1955
1956 /* If VF isn't active, no need for anything but SW */
1957 if (!p_vf->b_init)
1958 goto cleanup;
1959
1960 rc = qed_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
1961 if (rc)
1962 goto cleanup;
1963
1964 rc = qed_final_cleanup(p_hwfn, p_ptt, vfid, true);
1965 if (rc) {
1966 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
1967 return rc;
1968 }
1969
1970 /* VF_STOPPED has to be set only after final cleanup
1971 * but prior to re-enabling the VF.
1972 */
1973 p_vf->state = VF_STOPPED;
1974
1975 rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
1976 if (rc) {
1977 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
1978 vfid);
1979 return rc;
1980 }
1981cleanup:
1982 /* Mark VF for ack and clean pending state */
1983 if (p_vf->state == VF_RESET)
1984 p_vf->state = VF_STOPPED;
1985 ack_vfs[vfid / 32] |= (1 << (vfid % 32));
1986 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
1987 ~(1ULL << (rel_vf_id % 64));
1988 p_hwfn->pf_iov_info->pending_events[rel_vf_id / 64] &=
1989 ~(1ULL << (rel_vf_id % 64));
1990 }
1991
1992 return rc;
1993}
1994
1995int qed_iov_vf_flr_cleanup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1996{
1997 u32 ack_vfs[VF_MAX_STATIC / 32];
1998 int rc = 0;
1999 u16 i;
2000
2001 memset(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
2002
2003 /* Since BRB <-> PRS interface can't be tested as part of the flr
2004 * polling due to HW limitations, simply sleep a bit. And since
2005 * there's no need to wait per-vf, do it before looping.
2006 */
2007 msleep(100);
2008
2009 for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++)
2010 qed_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
2011
2012 rc = qed_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
2013 return rc;
2014}
2015
2016int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *p_disabled_vfs)
2017{
2018 u16 i, found = 0;
2019
2020 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "Marking FLR-ed VFs\n");
2021 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
2022 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2023 "[%08x,...,%08x]: %08x\n",
2024 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
2025
2026 if (!p_hwfn->cdev->p_iov_info) {
2027 DP_NOTICE(p_hwfn, "VF flr but no IOV\n");
2028 return 0;
2029 }
2030
2031 /* Mark VFs */
2032 for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++) {
2033 struct qed_vf_info *p_vf;
2034 u8 vfid;
2035
2036 p_vf = qed_iov_get_vf_info(p_hwfn, i, false);
2037 if (!p_vf)
2038 continue;
2039
2040 vfid = p_vf->abs_vf_id;
2041 if ((1 << (vfid % 32)) & p_disabled_vfs[vfid / 32]) {
2042 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
2043 u16 rel_vf_id = p_vf->relative_vf_id;
2044
2045 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2046 "VF[%d] [rel %d] got FLR-ed\n",
2047 vfid, rel_vf_id);
2048
2049 p_vf->state = VF_RESET;
2050
2051 /* No need to lock here, since pending_flr should
2052 * only change here and before ACKing MFw. Since
2053 * MFW will not trigger an additional attention for
2054 * VF flr until ACKs, we're safe.
2055 */
2056 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
2057 found = 1;
2058 }
2059 }
2060
2061 return found;
2062}
2063
Yuval Mintz36558c32016-05-11 16:36:17 +03002064void qed_iov_set_link(struct qed_hwfn *p_hwfn,
2065 u16 vfid,
2066 struct qed_mcp_link_params *params,
2067 struct qed_mcp_link_state *link,
2068 struct qed_mcp_link_capabilities *p_caps)
2069{
2070 struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
2071 vfid,
2072 false);
2073 struct qed_bulletin_content *p_bulletin;
2074
2075 if (!p_vf)
2076 return;
2077
2078 p_bulletin = p_vf->bulletin.p_virt;
2079 p_bulletin->req_autoneg = params->speed.autoneg;
2080 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
2081 p_bulletin->req_forced_speed = params->speed.forced_speed;
2082 p_bulletin->req_autoneg_pause = params->pause.autoneg;
2083 p_bulletin->req_forced_rx = params->pause.forced_rx;
2084 p_bulletin->req_forced_tx = params->pause.forced_tx;
2085 p_bulletin->req_loopback = params->loopback_mode;
2086
2087 p_bulletin->link_up = link->link_up;
2088 p_bulletin->speed = link->speed;
2089 p_bulletin->full_duplex = link->full_duplex;
2090 p_bulletin->autoneg = link->an;
2091 p_bulletin->autoneg_complete = link->an_complete;
2092 p_bulletin->parallel_detection = link->parallel_detection;
2093 p_bulletin->pfc_enabled = link->pfc_enabled;
2094 p_bulletin->partner_adv_speed = link->partner_adv_speed;
2095 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
2096 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
2097 p_bulletin->partner_adv_pause = link->partner_adv_pause;
2098 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
2099
2100 p_bulletin->capability_speed = p_caps->speed_capabilities;
2101}
2102
Yuval Mintz37bff2b2016-05-11 16:36:13 +03002103static void qed_iov_process_mbx_req(struct qed_hwfn *p_hwfn,
2104 struct qed_ptt *p_ptt, int vfid)
2105{
2106 struct qed_iov_vf_mbx *mbx;
2107 struct qed_vf_info *p_vf;
2108 int i;
2109
2110 p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
2111 if (!p_vf)
2112 return;
2113
2114 mbx = &p_vf->vf_mbx;
2115
2116 /* qed_iov_process_mbx_request */
2117 DP_VERBOSE(p_hwfn,
2118 QED_MSG_IOV,
2119 "qed_iov_process_mbx_req vfid %d\n", p_vf->abs_vf_id);
2120
2121 mbx->first_tlv = mbx->req_virt->first_tlv;
2122
2123 /* check if tlv type is known */
2124 if (qed_iov_tlv_supported(mbx->first_tlv.tl.type)) {
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002125 switch (mbx->first_tlv.tl.type) {
2126 case CHANNEL_TLV_ACQUIRE:
2127 qed_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
2128 break;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002129 case CHANNEL_TLV_VPORT_START:
2130 qed_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
2131 break;
2132 case CHANNEL_TLV_VPORT_TEARDOWN:
2133 qed_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
2134 break;
2135 case CHANNEL_TLV_START_RXQ:
2136 qed_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
2137 break;
2138 case CHANNEL_TLV_START_TXQ:
2139 qed_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
2140 break;
2141 case CHANNEL_TLV_STOP_RXQS:
2142 qed_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
2143 break;
2144 case CHANNEL_TLV_STOP_TXQS:
2145 qed_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
2146 break;
2147 case CHANNEL_TLV_VPORT_UPDATE:
2148 qed_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
2149 break;
2150 case CHANNEL_TLV_UCAST_FILTER:
2151 qed_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
2152 break;
Yuval Mintz0b55e272016-05-11 16:36:15 +03002153 case CHANNEL_TLV_CLOSE:
2154 qed_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
2155 break;
2156 case CHANNEL_TLV_INT_CLEANUP:
2157 qed_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
2158 break;
2159 case CHANNEL_TLV_RELEASE:
2160 qed_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
2161 break;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002162 }
Yuval Mintz37bff2b2016-05-11 16:36:13 +03002163 } else {
2164 /* unknown TLV - this may belong to a VF driver from the future
2165 * - a version written after this PF driver was written, which
2166 * supports features unknown as of yet. Too bad since we don't
2167 * support them. Or this may be because someone wrote a crappy
2168 * VF driver and is sending garbage over the channel.
2169 */
2170 DP_ERR(p_hwfn,
2171 "unknown TLV. type %d length %d. first 20 bytes of mailbox buffer:\n",
2172 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length);
2173
2174 for (i = 0; i < 20; i++) {
2175 DP_VERBOSE(p_hwfn,
2176 QED_MSG_IOV,
2177 "%x ",
2178 mbx->req_virt->tlv_buf_size.tlv_buffer[i]);
2179 }
2180 }
2181}
2182
2183void qed_iov_pf_add_pending_events(struct qed_hwfn *p_hwfn, u8 vfid)
2184{
2185 u64 add_bit = 1ULL << (vfid % 64);
2186
2187 p_hwfn->pf_iov_info->pending_events[vfid / 64] |= add_bit;
2188}
2189
2190static void qed_iov_pf_get_and_clear_pending_events(struct qed_hwfn *p_hwfn,
2191 u64 *events)
2192{
2193 u64 *p_pending_events = p_hwfn->pf_iov_info->pending_events;
2194
2195 memcpy(events, p_pending_events, sizeof(u64) * QED_VF_ARRAY_LENGTH);
2196 memset(p_pending_events, 0, sizeof(u64) * QED_VF_ARRAY_LENGTH);
2197}
2198
2199static int qed_sriov_vfpf_msg(struct qed_hwfn *p_hwfn,
2200 u16 abs_vfid, struct regpair *vf_msg)
2201{
2202 u8 min = (u8)p_hwfn->cdev->p_iov_info->first_vf_in_pf;
2203 struct qed_vf_info *p_vf;
2204
2205 if (!qed_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min)) {
2206 DP_VERBOSE(p_hwfn,
2207 QED_MSG_IOV,
2208 "Got a message from VF [abs 0x%08x] that cannot be handled by PF\n",
2209 abs_vfid);
2210 return 0;
2211 }
2212 p_vf = &p_hwfn->pf_iov_info->vfs_array[(u8)abs_vfid - min];
2213
2214 /* List the physical address of the request so that handler
2215 * could later on copy the message from it.
2216 */
2217 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
2218
2219 /* Mark the event and schedule the workqueue */
2220 qed_iov_pf_add_pending_events(p_hwfn, p_vf->relative_vf_id);
2221 qed_schedule_iov(p_hwfn, QED_IOV_WQ_MSG_FLAG);
2222
2223 return 0;
2224}
2225
2226int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
2227 u8 opcode, __le16 echo, union event_ring_data *data)
2228{
2229 switch (opcode) {
2230 case COMMON_EVENT_VF_PF_CHANNEL:
2231 return qed_sriov_vfpf_msg(p_hwfn, le16_to_cpu(echo),
2232 &data->vf_pf_channel.msg_addr);
2233 default:
2234 DP_INFO(p_hwfn->cdev, "Unknown sriov eqe event 0x%02x\n",
2235 opcode);
2236 return -EINVAL;
2237 }
2238}
2239
Yuval Mintz32a47e72016-05-11 16:36:12 +03002240u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id)
2241{
2242 struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
2243 u16 i;
2244
2245 if (!p_iov)
2246 goto out;
2247
2248 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
2249 if (qed_iov_is_valid_vfid(p_hwfn, rel_vf_id, true))
2250 return i;
2251
2252out:
2253 return MAX_NUM_VFS;
2254}
Yuval Mintz37bff2b2016-05-11 16:36:13 +03002255
2256static int qed_iov_copy_vf_msg(struct qed_hwfn *p_hwfn, struct qed_ptt *ptt,
2257 int vfid)
2258{
2259 struct qed_dmae_params params;
2260 struct qed_vf_info *vf_info;
2261
2262 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
2263 if (!vf_info)
2264 return -EINVAL;
2265
2266 memset(&params, 0, sizeof(struct qed_dmae_params));
2267 params.flags = QED_DMAE_FLAG_VF_SRC | QED_DMAE_FLAG_COMPLETION_DST;
2268 params.src_vfid = vf_info->abs_vf_id;
2269
2270 if (qed_dmae_host2host(p_hwfn, ptt,
2271 vf_info->vf_mbx.pending_req,
2272 vf_info->vf_mbx.req_phys,
2273 sizeof(union vfpf_tlvs) / 4, &params)) {
2274 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2275 "Failed to copy message from VF 0x%02x\n", vfid);
2276
2277 return -EIO;
2278 }
2279
2280 return 0;
2281}
2282
Yuval Mintz0b55e272016-05-11 16:36:15 +03002283bool qed_iov_is_vf_stopped(struct qed_hwfn *p_hwfn, int vfid)
2284{
2285 struct qed_vf_info *p_vf_info;
2286
2287 p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
2288 if (!p_vf_info)
2289 return true;
2290
2291 return p_vf_info->state == VF_STOPPED;
2292}
2293
Yuval Mintz37bff2b2016-05-11 16:36:13 +03002294/**
2295 * qed_schedule_iov - schedules IOV task for VF and PF
2296 * @hwfn: hardware function pointer
2297 * @flag: IOV flag for VF/PF
2298 */
2299void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag)
2300{
2301 smp_mb__before_atomic();
2302 set_bit(flag, &hwfn->iov_task_flags);
2303 smp_mb__after_atomic();
2304 DP_VERBOSE(hwfn, QED_MSG_IOV, "Scheduling iov task [Flag: %d]\n", flag);
2305 queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, 0);
2306}
2307
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002308void qed_vf_start_iov_wq(struct qed_dev *cdev)
2309{
2310 int i;
2311
2312 for_each_hwfn(cdev, i)
2313 queue_delayed_work(cdev->hwfns[i].iov_wq,
2314 &cdev->hwfns[i].iov_task, 0);
2315}
2316
Yuval Mintz0b55e272016-05-11 16:36:15 +03002317int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
2318{
2319 int i, j;
2320
2321 for_each_hwfn(cdev, i)
2322 if (cdev->hwfns[i].iov_wq)
2323 flush_workqueue(cdev->hwfns[i].iov_wq);
2324
2325 /* Mark VFs for disablement */
2326 qed_iov_set_vfs_to_disable(cdev, true);
2327
2328 if (cdev->p_iov_info && cdev->p_iov_info->num_vfs && pci_enabled)
2329 pci_disable_sriov(cdev->pdev);
2330
2331 for_each_hwfn(cdev, i) {
2332 struct qed_hwfn *hwfn = &cdev->hwfns[i];
2333 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
2334
2335 /* Failure to acquire the ptt in 100g creates an odd error
2336 * where the first engine has already relased IOV.
2337 */
2338 if (!ptt) {
2339 DP_ERR(hwfn, "Failed to acquire ptt\n");
2340 return -EBUSY;
2341 }
2342
2343 qed_for_each_vf(hwfn, j) {
2344 int k;
2345
2346 if (!qed_iov_is_valid_vfid(hwfn, j, true))
2347 continue;
2348
2349 /* Wait until VF is disabled before releasing */
2350 for (k = 0; k < 100; k++) {
2351 if (!qed_iov_is_vf_stopped(hwfn, j))
2352 msleep(20);
2353 else
2354 break;
2355 }
2356
2357 if (k < 100)
2358 qed_iov_release_hw_for_vf(&cdev->hwfns[i],
2359 ptt, j);
2360 else
2361 DP_ERR(hwfn,
2362 "Timeout waiting for VF's FLR to end\n");
2363 }
2364
2365 qed_ptt_release(hwfn, ptt);
2366 }
2367
2368 qed_iov_set_vfs_to_disable(cdev, false);
2369
2370 return 0;
2371}
2372
2373static int qed_sriov_enable(struct qed_dev *cdev, int num)
2374{
2375 struct qed_sb_cnt_info sb_cnt_info;
2376 int i, j, rc;
2377
2378 if (num >= RESC_NUM(&cdev->hwfns[0], QED_VPORT)) {
2379 DP_NOTICE(cdev, "Can start at most %d VFs\n",
2380 RESC_NUM(&cdev->hwfns[0], QED_VPORT) - 1);
2381 return -EINVAL;
2382 }
2383
2384 /* Initialize HW for VF access */
2385 for_each_hwfn(cdev, j) {
2386 struct qed_hwfn *hwfn = &cdev->hwfns[j];
2387 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
2388 int num_sbs = 0, limit = 16;
2389
2390 if (!ptt) {
2391 DP_ERR(hwfn, "Failed to acquire ptt\n");
2392 rc = -EBUSY;
2393 goto err;
2394 }
2395
2396 memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
2397 qed_int_get_num_sbs(hwfn, &sb_cnt_info);
2398 num_sbs = min_t(int, sb_cnt_info.sb_free_blk, limit);
2399
2400 for (i = 0; i < num; i++) {
2401 if (!qed_iov_is_valid_vfid(hwfn, i, false))
2402 continue;
2403
2404 rc = qed_iov_init_hw_for_vf(hwfn,
2405 ptt, i, num_sbs / num);
2406 if (rc) {
2407 DP_ERR(cdev, "Failed to enable VF[%d]\n", i);
2408 qed_ptt_release(hwfn, ptt);
2409 goto err;
2410 }
2411 }
2412
2413 qed_ptt_release(hwfn, ptt);
2414 }
2415
2416 /* Enable SRIOV PCIe functions */
2417 rc = pci_enable_sriov(cdev->pdev, num);
2418 if (rc) {
2419 DP_ERR(cdev, "Failed to enable sriov [%d]\n", rc);
2420 goto err;
2421 }
2422
2423 return num;
2424
2425err:
2426 qed_sriov_disable(cdev, false);
2427 return rc;
2428}
2429
2430static int qed_sriov_configure(struct qed_dev *cdev, int num_vfs_param)
2431{
2432 if (!IS_QED_SRIOV(cdev)) {
2433 DP_VERBOSE(cdev, QED_MSG_IOV, "SR-IOV is not supported\n");
2434 return -EOPNOTSUPP;
2435 }
2436
2437 if (num_vfs_param)
2438 return qed_sriov_enable(cdev, num_vfs_param);
2439 else
2440 return qed_sriov_disable(cdev, true);
2441}
2442
Yuval Mintz36558c32016-05-11 16:36:17 +03002443void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
2444{
2445 struct qed_mcp_link_capabilities caps;
2446 struct qed_mcp_link_params params;
2447 struct qed_mcp_link_state link;
2448 int i;
2449
2450 if (!hwfn->pf_iov_info)
2451 return;
2452
2453 /* Update bulletin of all future possible VFs with link configuration */
2454 for (i = 0; i < hwfn->cdev->p_iov_info->total_vfs; i++) {
2455 memcpy(&params, qed_mcp_get_link_params(hwfn), sizeof(params));
2456 memcpy(&link, qed_mcp_get_link_state(hwfn), sizeof(link));
2457 memcpy(&caps, qed_mcp_get_link_capabilities(hwfn),
2458 sizeof(caps));
2459
2460 qed_iov_set_link(hwfn, i, &params, &link, &caps);
2461 }
2462
2463 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
2464}
2465
Yuval Mintz37bff2b2016-05-11 16:36:13 +03002466static void qed_handle_vf_msg(struct qed_hwfn *hwfn)
2467{
2468 u64 events[QED_VF_ARRAY_LENGTH];
2469 struct qed_ptt *ptt;
2470 int i;
2471
2472 ptt = qed_ptt_acquire(hwfn);
2473 if (!ptt) {
2474 DP_VERBOSE(hwfn, QED_MSG_IOV,
2475 "Can't acquire PTT; re-scheduling\n");
2476 qed_schedule_iov(hwfn, QED_IOV_WQ_MSG_FLAG);
2477 return;
2478 }
2479
2480 qed_iov_pf_get_and_clear_pending_events(hwfn, events);
2481
2482 DP_VERBOSE(hwfn, QED_MSG_IOV,
2483 "Event mask of VF events: 0x%llx 0x%llx 0x%llx\n",
2484 events[0], events[1], events[2]);
2485
2486 qed_for_each_vf(hwfn, i) {
2487 /* Skip VFs with no pending messages */
2488 if (!(events[i / 64] & (1ULL << (i % 64))))
2489 continue;
2490
2491 DP_VERBOSE(hwfn, QED_MSG_IOV,
2492 "Handling VF message from VF 0x%02x [Abs 0x%02x]\n",
2493 i, hwfn->cdev->p_iov_info->first_vf_in_pf + i);
2494
2495 /* Copy VF's message to PF's request buffer for that VF */
2496 if (qed_iov_copy_vf_msg(hwfn, ptt, i))
2497 continue;
2498
2499 qed_iov_process_mbx_req(hwfn, ptt, i);
2500 }
2501
2502 qed_ptt_release(hwfn, ptt);
2503}
2504
Yuval Mintz36558c32016-05-11 16:36:17 +03002505static void qed_handle_bulletin_post(struct qed_hwfn *hwfn)
2506{
2507 struct qed_ptt *ptt;
2508 int i;
2509
2510 ptt = qed_ptt_acquire(hwfn);
2511 if (!ptt) {
2512 DP_NOTICE(hwfn, "Failed allocating a ptt entry\n");
2513 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
2514 return;
2515 }
2516
2517 qed_for_each_vf(hwfn, i)
2518 qed_iov_post_vf_bulletin(hwfn, i, ptt);
2519
2520 qed_ptt_release(hwfn, ptt);
2521}
2522
Yuval Mintz37bff2b2016-05-11 16:36:13 +03002523void qed_iov_pf_task(struct work_struct *work)
2524{
2525 struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
2526 iov_task.work);
Yuval Mintz0b55e272016-05-11 16:36:15 +03002527 int rc;
Yuval Mintz37bff2b2016-05-11 16:36:13 +03002528
2529 if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
2530 return;
2531
Yuval Mintz0b55e272016-05-11 16:36:15 +03002532 if (test_and_clear_bit(QED_IOV_WQ_FLR_FLAG, &hwfn->iov_task_flags)) {
2533 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
2534
2535 if (!ptt) {
2536 qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG);
2537 return;
2538 }
2539
2540 rc = qed_iov_vf_flr_cleanup(hwfn, ptt);
2541 if (rc)
2542 qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG);
2543
2544 qed_ptt_release(hwfn, ptt);
2545 }
2546
Yuval Mintz37bff2b2016-05-11 16:36:13 +03002547 if (test_and_clear_bit(QED_IOV_WQ_MSG_FLAG, &hwfn->iov_task_flags))
2548 qed_handle_vf_msg(hwfn);
Yuval Mintz36558c32016-05-11 16:36:17 +03002549 if (test_and_clear_bit(QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
2550 &hwfn->iov_task_flags))
2551 qed_handle_bulletin_post(hwfn);
Yuval Mintz37bff2b2016-05-11 16:36:13 +03002552}
2553
2554void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
2555{
2556 int i;
2557
2558 for_each_hwfn(cdev, i) {
2559 if (!cdev->hwfns[i].iov_wq)
2560 continue;
2561
2562 if (schedule_first) {
2563 qed_schedule_iov(&cdev->hwfns[i],
2564 QED_IOV_WQ_STOP_WQ_FLAG);
2565 cancel_delayed_work_sync(&cdev->hwfns[i].iov_task);
2566 }
2567
2568 flush_workqueue(cdev->hwfns[i].iov_wq);
2569 destroy_workqueue(cdev->hwfns[i].iov_wq);
2570 }
2571}
2572
2573int qed_iov_wq_start(struct qed_dev *cdev)
2574{
2575 char name[NAME_SIZE];
2576 int i;
2577
2578 for_each_hwfn(cdev, i) {
2579 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2580
Yuval Mintz36558c32016-05-11 16:36:17 +03002581 /* PFs needs a dedicated workqueue only if they support IOV.
2582 * VFs always require one.
2583 */
2584 if (IS_PF(p_hwfn->cdev) && !IS_PF_SRIOV(p_hwfn))
Yuval Mintz37bff2b2016-05-11 16:36:13 +03002585 continue;
2586
2587 snprintf(name, NAME_SIZE, "iov-%02x:%02x.%02x",
2588 cdev->pdev->bus->number,
2589 PCI_SLOT(cdev->pdev->devfn), p_hwfn->abs_pf_id);
2590
2591 p_hwfn->iov_wq = create_singlethread_workqueue(name);
2592 if (!p_hwfn->iov_wq) {
2593 DP_NOTICE(p_hwfn, "Cannot create iov workqueue\n");
2594 return -ENOMEM;
2595 }
2596
Yuval Mintz36558c32016-05-11 16:36:17 +03002597 if (IS_PF(cdev))
2598 INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_pf_task);
2599 else
2600 INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_vf_task);
Yuval Mintz37bff2b2016-05-11 16:36:13 +03002601 }
2602
2603 return 0;
2604}
Yuval Mintz0b55e272016-05-11 16:36:15 +03002605
2606const struct qed_iov_hv_ops qed_iov_ops_pass = {
2607 .configure = &qed_sriov_configure,
2608};