blob: fd59cf45f4be8cb008d8728398870cc1ab41210b [file] [log] [blame]
Yuval Mintz32a47e72016-05-11 16:36:12 +03001/* QLogic qed NIC Driver
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02002 * Copyright (c) 2015-2017 QLogic Corporation
Yuval Mintz32a47e72016-05-11 16:36:12 +03003 *
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02004 * 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.
Yuval Mintz32a47e72016-05-11 16:36:12 +030031 */
32
Yuval Mintzdacd88d2016-05-11 16:36:16 +030033#include <linux/etherdevice.h>
Yuval Mintz36558c32016-05-11 16:36:17 +030034#include <linux/crc32.h>
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +020035#include <linux/vmalloc.h>
Yuval Mintz0b55e272016-05-11 16:36:15 +030036#include <linux/qed/qed_iov_if.h>
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030037#include "qed_cxt.h"
38#include "qed_hsi.h"
Yuval Mintz32a47e72016-05-11 16:36:12 +030039#include "qed_hw.h"
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030040#include "qed_init_ops.h"
Yuval Mintz32a47e72016-05-11 16:36:12 +030041#include "qed_int.h"
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030042#include "qed_mcp.h"
Yuval Mintz32a47e72016-05-11 16:36:12 +030043#include "qed_reg_addr.h"
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030044#include "qed_sp.h"
Yuval Mintz32a47e72016-05-11 16:36:12 +030045#include "qed_sriov.h"
46#include "qed_vf.h"
Michal Kalderon6c9e80e2017-06-20 16:00:06 +030047static int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
48 u8 opcode,
49 __le16 echo,
50 union event_ring_data *data, u8 fw_return_code);
Shahed Shaikh7425d822018-04-19 05:50:11 -070051static int qed_iov_bulletin_set_mac(struct qed_hwfn *p_hwfn, u8 *mac, int vfid);
Yuval Mintz32a47e72016-05-11 16:36:12 +030052
Mintz, Yuval3b19f472017-06-04 13:31:04 +030053static u8 qed_vf_calculate_legacy(struct qed_vf_info *p_vf)
54{
Mintz, Yuval08bc8f12017-06-04 13:31:06 +030055 u8 legacy = 0;
Mintz, Yuval3b19f472017-06-04 13:31:04 +030056
57 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
58 ETH_HSI_VER_NO_PKT_LEN_TUNN)
59 legacy |= QED_QCID_LEGACY_VF_RX_PROD;
60
Mintz, Yuval08bc8f12017-06-04 13:31:06 +030061 if (!(p_vf->acquire.vfdev_info.capabilities &
62 VFPF_ACQUIRE_CAP_QUEUE_QIDS))
63 legacy |= QED_QCID_LEGACY_VF_CID;
64
Mintz, Yuval3b19f472017-06-04 13:31:04 +030065 return legacy;
66}
67
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030068/* IOV ramrods */
Yuval Mintz1fe614d2016-06-05 13:11:11 +030069static int qed_sp_vf_start(struct qed_hwfn *p_hwfn, struct qed_vf_info *p_vf)
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030070{
71 struct vf_start_ramrod_data *p_ramrod = NULL;
72 struct qed_spq_entry *p_ent = NULL;
73 struct qed_sp_init_data init_data;
74 int rc = -EINVAL;
Yuval Mintz1fe614d2016-06-05 13:11:11 +030075 u8 fp_minor;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030076
77 /* Get SPQ entry */
78 memset(&init_data, 0, sizeof(init_data));
79 init_data.cid = qed_spq_get_cid(p_hwfn);
Yuval Mintz1fe614d2016-06-05 13:11:11 +030080 init_data.opaque_fid = p_vf->opaque_fid;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030081 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
82
83 rc = qed_sp_init_request(p_hwfn, &p_ent,
84 COMMON_RAMROD_VF_START,
85 PROTOCOLID_COMMON, &init_data);
86 if (rc)
87 return rc;
88
89 p_ramrod = &p_ent->ramrod.vf_start;
90
Yuval Mintz1fe614d2016-06-05 13:11:11 +030091 p_ramrod->vf_id = GET_FIELD(p_vf->concrete_fid, PXP_CONCRETE_FID_VFID);
92 p_ramrod->opaque_fid = cpu_to_le16(p_vf->opaque_fid);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030093
Yuval Mintz1fe614d2016-06-05 13:11:11 +030094 switch (p_hwfn->hw_info.personality) {
95 case QED_PCI_ETH:
96 p_ramrod->personality = PERSONALITY_ETH;
97 break;
98 case QED_PCI_ETH_ROCE:
99 p_ramrod->personality = PERSONALITY_RDMA_AND_ETH;
100 break;
101 default:
102 DP_NOTICE(p_hwfn, "Unknown VF personality %d\n",
103 p_hwfn->hw_info.personality);
104 return -EINVAL;
105 }
106
107 fp_minor = p_vf->acquire.vfdev_info.eth_fp_hsi_minor;
Yuval Mintza044df82016-08-22 13:25:09 +0300108 if (fp_minor > ETH_HSI_VER_MINOR &&
109 fp_minor != ETH_HSI_VER_NO_PKT_LEN_TUNN) {
Yuval Mintz1fe614d2016-06-05 13:11:11 +0300110 DP_VERBOSE(p_hwfn,
111 QED_MSG_IOV,
112 "VF [%d] - Requested fp hsi %02x.%02x which is slightly newer than PF's %02x.%02x; Configuring PFs version\n",
113 p_vf->abs_vf_id,
114 ETH_HSI_VER_MAJOR,
115 fp_minor, ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
116 fp_minor = ETH_HSI_VER_MINOR;
117 }
118
Yuval Mintz351a4ded2016-06-02 10:23:29 +0300119 p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR;
Yuval Mintz1fe614d2016-06-05 13:11:11 +0300120 p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = fp_minor;
121
122 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
123 "VF[%d] - Starting using HSI %02x.%02x\n",
124 p_vf->abs_vf_id, ETH_HSI_VER_MAJOR, fp_minor);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300125
126 return qed_spq_post(p_hwfn, p_ent, NULL);
127}
128
Yuval Mintz0b55e272016-05-11 16:36:15 +0300129static int qed_sp_vf_stop(struct qed_hwfn *p_hwfn,
130 u32 concrete_vfid, u16 opaque_vfid)
131{
132 struct vf_stop_ramrod_data *p_ramrod = NULL;
133 struct qed_spq_entry *p_ent = NULL;
134 struct qed_sp_init_data init_data;
135 int rc = -EINVAL;
136
137 /* Get SPQ entry */
138 memset(&init_data, 0, sizeof(init_data));
139 init_data.cid = qed_spq_get_cid(p_hwfn);
140 init_data.opaque_fid = opaque_vfid;
141 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
142
143 rc = qed_sp_init_request(p_hwfn, &p_ent,
144 COMMON_RAMROD_VF_STOP,
145 PROTOCOLID_COMMON, &init_data);
146 if (rc)
147 return rc;
148
149 p_ramrod = &p_ent->ramrod.vf_stop;
150
151 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
152
153 return qed_spq_post(p_hwfn, p_ent, NULL);
154}
155
Tomer Tayarda090912017-12-27 19:30:07 +0200156bool qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn,
157 int rel_vf_id,
158 bool b_enabled_only, bool b_non_malicious)
Yuval Mintz32a47e72016-05-11 16:36:12 +0300159{
160 if (!p_hwfn->pf_iov_info) {
161 DP_NOTICE(p_hwfn->cdev, "No iov info\n");
162 return false;
163 }
164
165 if ((rel_vf_id >= p_hwfn->cdev->p_iov_info->total_vfs) ||
166 (rel_vf_id < 0))
167 return false;
168
169 if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
170 b_enabled_only)
171 return false;
172
Yuval Mintz7eff82b2016-10-14 05:19:22 -0400173 if ((p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_malicious) &&
174 b_non_malicious)
175 return false;
176
Yuval Mintz32a47e72016-05-11 16:36:12 +0300177 return true;
178}
179
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300180static struct qed_vf_info *qed_iov_get_vf_info(struct qed_hwfn *p_hwfn,
181 u16 relative_vf_id,
182 bool b_enabled_only)
183{
184 struct qed_vf_info *vf = NULL;
185
186 if (!p_hwfn->pf_iov_info) {
187 DP_NOTICE(p_hwfn->cdev, "No iov info\n");
188 return NULL;
189 }
190
Yuval Mintz7eff82b2016-10-14 05:19:22 -0400191 if (qed_iov_is_valid_vfid(p_hwfn, relative_vf_id,
192 b_enabled_only, false))
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300193 vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
194 else
195 DP_ERR(p_hwfn, "qed_iov_get_vf_info: VF[%d] is not enabled\n",
196 relative_vf_id);
197
198 return vf;
199}
200
Mintz, Yuval007bc372017-06-04 13:31:05 +0300201static struct qed_queue_cid *
202qed_iov_get_vf_rx_queue_cid(struct qed_vf_queue *p_queue)
203{
204 int i;
205
206 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
207 if (p_queue->cids[i].p_cid && !p_queue->cids[i].b_is_tx)
208 return p_queue->cids[i].p_cid;
209 }
210
211 return NULL;
212}
213
Mintz, Yuvalf109c242017-03-19 13:08:16 +0200214enum qed_iov_validate_q_mode {
215 QED_IOV_VALIDATE_Q_NA,
216 QED_IOV_VALIDATE_Q_ENABLE,
217 QED_IOV_VALIDATE_Q_DISABLE,
218};
219
220static bool qed_iov_validate_queue_mode(struct qed_hwfn *p_hwfn,
221 struct qed_vf_info *p_vf,
222 u16 qid,
223 enum qed_iov_validate_q_mode mode,
224 bool b_is_tx)
Yuval Mintz41086462016-06-05 13:11:13 +0300225{
Mintz, Yuval007bc372017-06-04 13:31:05 +0300226 int i;
227
Mintz, Yuvalf109c242017-03-19 13:08:16 +0200228 if (mode == QED_IOV_VALIDATE_Q_NA)
229 return true;
230
Mintz, Yuval007bc372017-06-04 13:31:05 +0300231 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
232 struct qed_vf_queue_cid *p_qcid;
233
234 p_qcid = &p_vf->vf_queues[qid].cids[i];
235
236 if (!p_qcid->p_cid)
237 continue;
238
239 if (p_qcid->b_is_tx != b_is_tx)
240 continue;
241
Mintz, Yuvalf109c242017-03-19 13:08:16 +0200242 return mode == QED_IOV_VALIDATE_Q_ENABLE;
Mintz, Yuval007bc372017-06-04 13:31:05 +0300243 }
Mintz, Yuvalf109c242017-03-19 13:08:16 +0200244
245 /* In case we haven't found any valid cid, then its disabled */
246 return mode == QED_IOV_VALIDATE_Q_DISABLE;
247}
248
249static bool qed_iov_validate_rxq(struct qed_hwfn *p_hwfn,
250 struct qed_vf_info *p_vf,
251 u16 rx_qid,
252 enum qed_iov_validate_q_mode mode)
253{
254 if (rx_qid >= p_vf->num_rxqs) {
Yuval Mintz41086462016-06-05 13:11:13 +0300255 DP_VERBOSE(p_hwfn,
256 QED_MSG_IOV,
257 "VF[0x%02x] - can't touch Rx queue[%04x]; Only 0x%04x are allocated\n",
258 p_vf->abs_vf_id, rx_qid, p_vf->num_rxqs);
Mintz, Yuvalf109c242017-03-19 13:08:16 +0200259 return false;
260 }
261
262 return qed_iov_validate_queue_mode(p_hwfn, p_vf, rx_qid, mode, false);
Yuval Mintz41086462016-06-05 13:11:13 +0300263}
264
265static bool qed_iov_validate_txq(struct qed_hwfn *p_hwfn,
Mintz, Yuvalf109c242017-03-19 13:08:16 +0200266 struct qed_vf_info *p_vf,
267 u16 tx_qid,
268 enum qed_iov_validate_q_mode mode)
Yuval Mintz41086462016-06-05 13:11:13 +0300269{
Mintz, Yuvalf109c242017-03-19 13:08:16 +0200270 if (tx_qid >= p_vf->num_txqs) {
Yuval Mintz41086462016-06-05 13:11:13 +0300271 DP_VERBOSE(p_hwfn,
272 QED_MSG_IOV,
273 "VF[0x%02x] - can't touch Tx queue[%04x]; Only 0x%04x are allocated\n",
274 p_vf->abs_vf_id, tx_qid, p_vf->num_txqs);
Mintz, Yuvalf109c242017-03-19 13:08:16 +0200275 return false;
276 }
277
278 return qed_iov_validate_queue_mode(p_hwfn, p_vf, tx_qid, mode, true);
Yuval Mintz41086462016-06-05 13:11:13 +0300279}
280
281static bool qed_iov_validate_sb(struct qed_hwfn *p_hwfn,
282 struct qed_vf_info *p_vf, u16 sb_idx)
283{
284 int i;
285
286 for (i = 0; i < p_vf->num_sbs; i++)
287 if (p_vf->igu_sbs[i] == sb_idx)
288 return true;
289
290 DP_VERBOSE(p_hwfn,
291 QED_MSG_IOV,
292 "VF[0%02x] - tried using sb_idx %04x which doesn't exist as one of its 0x%02x SBs\n",
293 p_vf->abs_vf_id, sb_idx, p_vf->num_sbs);
294
295 return false;
296}
297
Mintz, Yuvalf109c242017-03-19 13:08:16 +0200298static bool qed_iov_validate_active_rxq(struct qed_hwfn *p_hwfn,
299 struct qed_vf_info *p_vf)
300{
301 u8 i;
302
303 for (i = 0; i < p_vf->num_rxqs; i++)
304 if (qed_iov_validate_queue_mode(p_hwfn, p_vf, i,
305 QED_IOV_VALIDATE_Q_ENABLE,
306 false))
307 return true;
308
309 return false;
310}
311
312static bool qed_iov_validate_active_txq(struct qed_hwfn *p_hwfn,
313 struct qed_vf_info *p_vf)
314{
315 u8 i;
316
317 for (i = 0; i < p_vf->num_txqs; i++)
318 if (qed_iov_validate_queue_mode(p_hwfn, p_vf, i,
319 QED_IOV_VALIDATE_Q_ENABLE,
320 true))
321 return true;
322
323 return false;
324}
325
Baoyou Xieba569472016-09-09 09:21:15 +0800326static int qed_iov_post_vf_bulletin(struct qed_hwfn *p_hwfn,
327 int vfid, struct qed_ptt *p_ptt)
Yuval Mintz36558c32016-05-11 16:36:17 +0300328{
329 struct qed_bulletin_content *p_bulletin;
330 int crc_size = sizeof(p_bulletin->crc);
331 struct qed_dmae_params params;
332 struct qed_vf_info *p_vf;
333
334 p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
335 if (!p_vf)
336 return -EINVAL;
337
338 if (!p_vf->vf_bulletin)
339 return -EINVAL;
340
341 p_bulletin = p_vf->bulletin.p_virt;
342
343 /* Increment bulletin board version and compute crc */
344 p_bulletin->version++;
345 p_bulletin->crc = crc32(0, (u8 *)p_bulletin + crc_size,
346 p_vf->bulletin.size - crc_size);
347
348 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
349 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
350 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
351
352 /* propagate bulletin board via dmae to vm memory */
353 memset(&params, 0, sizeof(params));
354 params.flags = QED_DMAE_FLAG_VF_DST;
355 params.dst_vfid = p_vf->abs_vf_id;
356 return qed_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
357 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
358 &params);
359}
360
Yuval Mintz32a47e72016-05-11 16:36:12 +0300361static int qed_iov_pci_cfg_info(struct qed_dev *cdev)
362{
363 struct qed_hw_sriov_info *iov = cdev->p_iov_info;
364 int pos = iov->pos;
365
366 DP_VERBOSE(cdev, QED_MSG_IOV, "sriov ext pos %d\n", pos);
367 pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
368
369 pci_read_config_word(cdev->pdev,
370 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
371 pci_read_config_word(cdev->pdev,
372 pos + PCI_SRIOV_INITIAL_VF, &iov->initial_vfs);
373
374 pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
375 if (iov->num_vfs) {
376 DP_VERBOSE(cdev,
377 QED_MSG_IOV,
378 "Number of VFs are already set to non-zero value. Ignoring PCI configuration value\n");
379 iov->num_vfs = 0;
380 }
381
382 pci_read_config_word(cdev->pdev,
383 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
384
385 pci_read_config_word(cdev->pdev,
386 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
387
388 pci_read_config_word(cdev->pdev,
389 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
390
391 pci_read_config_dword(cdev->pdev,
392 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
393
394 pci_read_config_dword(cdev->pdev, pos + PCI_SRIOV_CAP, &iov->cap);
395
396 pci_read_config_byte(cdev->pdev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
397
398 DP_VERBOSE(cdev,
399 QED_MSG_IOV,
400 "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",
401 iov->nres,
402 iov->cap,
403 iov->ctrl,
404 iov->total_vfs,
405 iov->initial_vfs,
406 iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz);
407
408 /* Some sanity checks */
409 if (iov->num_vfs > NUM_OF_VFS(cdev) ||
410 iov->total_vfs > NUM_OF_VFS(cdev)) {
411 /* This can happen only due to a bug. In this case we set
412 * num_vfs to zero to avoid memory corruption in the code that
413 * assumes max number of vfs
414 */
415 DP_NOTICE(cdev,
416 "IOV: Unexpected number of vfs set: %d setting num_vf to zero\n",
417 iov->num_vfs);
418
419 iov->num_vfs = 0;
420 iov->total_vfs = 0;
421 }
422
423 return 0;
424}
425
Yuval Mintz32a47e72016-05-11 16:36:12 +0300426static void qed_iov_setup_vfdb(struct qed_hwfn *p_hwfn)
427{
428 struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
429 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
430 struct qed_bulletin_content *p_bulletin_virt;
431 dma_addr_t req_p, rply_p, bulletin_p;
432 union pfvf_tlvs *p_reply_virt_addr;
433 union vfpf_tlvs *p_req_virt_addr;
434 u8 idx = 0;
435
436 memset(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
437
438 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
439 req_p = p_iov_info->mbx_msg_phys_addr;
440 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
441 rply_p = p_iov_info->mbx_reply_phys_addr;
442 p_bulletin_virt = p_iov_info->p_bulletins;
443 bulletin_p = p_iov_info->bulletins_phys;
444 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
445 DP_ERR(p_hwfn,
446 "qed_iov_setup_vfdb called without allocating mem first\n");
447 return;
448 }
449
450 for (idx = 0; idx < p_iov->total_vfs; idx++) {
451 struct qed_vf_info *vf = &p_iov_info->vfs_array[idx];
452 u32 concrete;
453
454 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
455 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
456 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
457 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
458
459 vf->state = VF_STOPPED;
460 vf->b_init = false;
461
462 vf->bulletin.phys = idx *
463 sizeof(struct qed_bulletin_content) +
464 bulletin_p;
465 vf->bulletin.p_virt = p_bulletin_virt + idx;
466 vf->bulletin.size = sizeof(struct qed_bulletin_content);
467
468 vf->relative_vf_id = idx;
469 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
470 concrete = qed_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
471 vf->concrete_fid = concrete;
472 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
473 (vf->abs_vf_id << 8);
474 vf->vport_id = idx + 1;
Yuval Mintz1cf2b1a2016-06-05 13:11:12 +0300475
476 vf->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
477 vf->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300478 }
479}
480
481static int qed_iov_allocate_vfdb(struct qed_hwfn *p_hwfn)
482{
483 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
484 void **p_v_addr;
485 u16 num_vfs = 0;
486
487 num_vfs = p_hwfn->cdev->p_iov_info->total_vfs;
488
489 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
490 "qed_iov_allocate_vfdb for %d VFs\n", num_vfs);
491
492 /* Allocate PF Mailbox buffer (per-VF) */
493 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
494 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
495 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
496 p_iov_info->mbx_msg_size,
497 &p_iov_info->mbx_msg_phys_addr,
498 GFP_KERNEL);
499 if (!*p_v_addr)
500 return -ENOMEM;
501
502 /* Allocate PF Mailbox Reply buffer (per-VF) */
503 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
504 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
505 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
506 p_iov_info->mbx_reply_size,
507 &p_iov_info->mbx_reply_phys_addr,
508 GFP_KERNEL);
509 if (!*p_v_addr)
510 return -ENOMEM;
511
512 p_iov_info->bulletins_size = sizeof(struct qed_bulletin_content) *
513 num_vfs;
514 p_v_addr = &p_iov_info->p_bulletins;
515 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
516 p_iov_info->bulletins_size,
517 &p_iov_info->bulletins_phys,
518 GFP_KERNEL);
519 if (!*p_v_addr)
520 return -ENOMEM;
521
522 DP_VERBOSE(p_hwfn,
523 QED_MSG_IOV,
524 "PF's Requests mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys] Bulletins [%p virt 0x%llx phys]\n",
525 p_iov_info->mbx_msg_virt_addr,
526 (u64) p_iov_info->mbx_msg_phys_addr,
527 p_iov_info->mbx_reply_virt_addr,
528 (u64) p_iov_info->mbx_reply_phys_addr,
529 p_iov_info->p_bulletins, (u64) p_iov_info->bulletins_phys);
530
531 return 0;
532}
533
534static void qed_iov_free_vfdb(struct qed_hwfn *p_hwfn)
535{
536 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
537
538 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
539 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
540 p_iov_info->mbx_msg_size,
541 p_iov_info->mbx_msg_virt_addr,
542 p_iov_info->mbx_msg_phys_addr);
543
544 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
545 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
546 p_iov_info->mbx_reply_size,
547 p_iov_info->mbx_reply_virt_addr,
548 p_iov_info->mbx_reply_phys_addr);
549
550 if (p_iov_info->p_bulletins)
551 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
552 p_iov_info->bulletins_size,
553 p_iov_info->p_bulletins,
554 p_iov_info->bulletins_phys);
555}
556
557int qed_iov_alloc(struct qed_hwfn *p_hwfn)
558{
559 struct qed_pf_iov *p_sriov;
560
561 if (!IS_PF_SRIOV(p_hwfn)) {
562 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
563 "No SR-IOV - no need for IOV db\n");
564 return 0;
565 }
566
567 p_sriov = kzalloc(sizeof(*p_sriov), GFP_KERNEL);
Joe Perches2591c282016-09-04 14:24:03 -0700568 if (!p_sriov)
Yuval Mintz32a47e72016-05-11 16:36:12 +0300569 return -ENOMEM;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300570
571 p_hwfn->pf_iov_info = p_sriov;
572
Michal Kalderon6c9e80e2017-06-20 16:00:06 +0300573 qed_spq_register_async_cb(p_hwfn, PROTOCOLID_COMMON,
574 qed_sriov_eqe_event);
575
Yuval Mintz32a47e72016-05-11 16:36:12 +0300576 return qed_iov_allocate_vfdb(p_hwfn);
577}
578
Mintz, Yuval1ee240e2017-06-01 15:29:11 +0300579void qed_iov_setup(struct qed_hwfn *p_hwfn)
Yuval Mintz32a47e72016-05-11 16:36:12 +0300580{
581 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
582 return;
583
584 qed_iov_setup_vfdb(p_hwfn);
Yuval Mintz32a47e72016-05-11 16:36:12 +0300585}
586
587void qed_iov_free(struct qed_hwfn *p_hwfn)
588{
Michal Kalderon6c9e80e2017-06-20 16:00:06 +0300589 qed_spq_unregister_async_cb(p_hwfn, PROTOCOLID_COMMON);
590
Yuval Mintz32a47e72016-05-11 16:36:12 +0300591 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
592 qed_iov_free_vfdb(p_hwfn);
593 kfree(p_hwfn->pf_iov_info);
594 }
595}
596
597void qed_iov_free_hw_info(struct qed_dev *cdev)
598{
599 kfree(cdev->p_iov_info);
600 cdev->p_iov_info = NULL;
601}
602
603int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
604{
605 struct qed_dev *cdev = p_hwfn->cdev;
606 int pos;
607 int rc;
608
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300609 if (IS_VF(p_hwfn->cdev))
610 return 0;
611
Yuval Mintz32a47e72016-05-11 16:36:12 +0300612 /* Learn the PCI configuration */
613 pos = pci_find_ext_capability(p_hwfn->cdev->pdev,
614 PCI_EXT_CAP_ID_SRIOV);
615 if (!pos) {
616 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "No PCIe IOV support\n");
617 return 0;
618 }
619
620 /* Allocate a new struct for IOV information */
621 cdev->p_iov_info = kzalloc(sizeof(*cdev->p_iov_info), GFP_KERNEL);
Joe Perches2591c282016-09-04 14:24:03 -0700622 if (!cdev->p_iov_info)
Yuval Mintz32a47e72016-05-11 16:36:12 +0300623 return -ENOMEM;
Joe Perches2591c282016-09-04 14:24:03 -0700624
Yuval Mintz32a47e72016-05-11 16:36:12 +0300625 cdev->p_iov_info->pos = pos;
626
627 rc = qed_iov_pci_cfg_info(cdev);
628 if (rc)
629 return rc;
630
631 /* We want PF IOV to be synonemous with the existance of p_iov_info;
632 * In case the capability is published but there are no VFs, simply
633 * de-allocate the struct.
634 */
635 if (!cdev->p_iov_info->total_vfs) {
636 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
637 "IOV capabilities, but no VFs are published\n");
638 kfree(cdev->p_iov_info);
639 cdev->p_iov_info = NULL;
640 return 0;
641 }
642
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200643 /* First VF index based on offset is tricky:
644 * - If ARI is supported [likely], offset - (16 - pf_id) would
645 * provide the number for eng0. 2nd engine Vfs would begin
646 * after the first engine's VFs.
647 * - If !ARI, VFs would start on next device.
648 * so offset - (256 - pf_id) would provide the number.
649 * Utilize the fact that (256 - pf_id) is achieved only by later
Joe Perches8ac1ed72017-05-08 15:57:56 -0700650 * to differentiate between the two.
Yuval Mintz32a47e72016-05-11 16:36:12 +0300651 */
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200652
653 if (p_hwfn->cdev->p_iov_info->offset < (256 - p_hwfn->abs_pf_id)) {
654 u32 first = p_hwfn->cdev->p_iov_info->offset +
655 p_hwfn->abs_pf_id - 16;
656
657 cdev->p_iov_info->first_vf_in_pf = first;
658
659 if (QED_PATH_ID(p_hwfn))
660 cdev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
661 } else {
662 u32 first = p_hwfn->cdev->p_iov_info->offset +
663 p_hwfn->abs_pf_id - 256;
664
665 cdev->p_iov_info->first_vf_in_pf = first;
666 }
Yuval Mintz32a47e72016-05-11 16:36:12 +0300667
668 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
669 "First VF in hwfn 0x%08x\n",
670 cdev->p_iov_info->first_vf_in_pf);
671
672 return 0;
673}
674
Yuval Mintz7eff82b2016-10-14 05:19:22 -0400675bool _qed_iov_pf_sanity_check(struct qed_hwfn *p_hwfn,
676 int vfid, bool b_fail_malicious)
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300677{
678 /* Check PF supports sriov */
Yuval Mintzb0409fa2016-05-15 14:48:05 +0300679 if (IS_VF(p_hwfn->cdev) || !IS_QED_SRIOV(p_hwfn->cdev) ||
680 !IS_PF_SRIOV_ALLOC(p_hwfn))
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300681 return false;
682
683 /* Check VF validity */
Yuval Mintz7eff82b2016-10-14 05:19:22 -0400684 if (!qed_iov_is_valid_vfid(p_hwfn, vfid, true, b_fail_malicious))
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300685 return false;
686
687 return true;
688}
689
Yuval Mintz7eff82b2016-10-14 05:19:22 -0400690bool qed_iov_pf_sanity_check(struct qed_hwfn *p_hwfn, int vfid)
691{
692 return _qed_iov_pf_sanity_check(p_hwfn, vfid, true);
693}
694
Yuval Mintz0b55e272016-05-11 16:36:15 +0300695static void qed_iov_set_vf_to_disable(struct qed_dev *cdev,
696 u16 rel_vf_id, u8 to_disable)
697{
698 struct qed_vf_info *vf;
699 int i;
700
701 for_each_hwfn(cdev, i) {
702 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
703
704 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
705 if (!vf)
706 continue;
707
708 vf->to_disable = to_disable;
709 }
710}
711
Baoyou Xieba569472016-09-09 09:21:15 +0800712static void qed_iov_set_vfs_to_disable(struct qed_dev *cdev, u8 to_disable)
Yuval Mintz0b55e272016-05-11 16:36:15 +0300713{
714 u16 i;
715
716 if (!IS_QED_SRIOV(cdev))
717 return;
718
719 for (i = 0; i < cdev->p_iov_info->total_vfs; i++)
720 qed_iov_set_vf_to_disable(cdev, i, to_disable);
721}
722
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300723static void qed_iov_vf_pglue_clear_err(struct qed_hwfn *p_hwfn,
724 struct qed_ptt *p_ptt, u8 abs_vfid)
725{
726 qed_wr(p_hwfn, p_ptt,
727 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
728 1 << (abs_vfid & 0x1f));
729}
730
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300731static void qed_iov_vf_igu_reset(struct qed_hwfn *p_hwfn,
732 struct qed_ptt *p_ptt, struct qed_vf_info *vf)
733{
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300734 int i;
735
736 /* Set VF masks and configuration - pretend */
737 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
738
739 qed_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
740
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300741 /* unpretend */
742 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
743
744 /* iterate over all queues, clear sb consumer */
Yuval Mintzb2b897e2016-05-15 14:48:06 +0300745 for (i = 0; i < vf->num_sbs; i++)
746 qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
747 vf->igu_sbs[i],
748 vf->opaque_fid, true);
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300749}
750
Yuval Mintz0b55e272016-05-11 16:36:15 +0300751static void qed_iov_vf_igu_set_int(struct qed_hwfn *p_hwfn,
752 struct qed_ptt *p_ptt,
753 struct qed_vf_info *vf, bool enable)
754{
755 u32 igu_vf_conf;
756
757 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
758
759 igu_vf_conf = qed_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
760
761 if (enable)
762 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
763 else
764 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
765
766 qed_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
767
768 /* unpretend */
769 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
770}
771
Mintz, Yuval88072fd2017-05-29 09:53:08 +0300772static int
773qed_iov_enable_vf_access_msix(struct qed_hwfn *p_hwfn,
774 struct qed_ptt *p_ptt, u8 abs_vf_id, u8 num_sbs)
775{
776 u8 current_max = 0;
777 int i;
778
779 /* For AH onward, configuration is per-PF. Find maximum of all
780 * the currently enabled child VFs, and set the number to be that.
781 */
782 if (!QED_IS_BB(p_hwfn->cdev)) {
783 qed_for_each_vf(p_hwfn, i) {
784 struct qed_vf_info *p_vf;
785
786 p_vf = qed_iov_get_vf_info(p_hwfn, (u16)i, true);
787 if (!p_vf)
788 continue;
789
790 current_max = max_t(u8, current_max, p_vf->num_sbs);
791 }
792 }
793
794 if (num_sbs > current_max)
795 return qed_mcp_config_vf_msix(p_hwfn, p_ptt,
796 abs_vf_id, num_sbs);
797
798 return 0;
799}
800
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300801static int qed_iov_enable_vf_access(struct qed_hwfn *p_hwfn,
802 struct qed_ptt *p_ptt,
803 struct qed_vf_info *vf)
804{
805 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
806 int rc;
807
Mintz, Yuval4e9b2a62017-03-19 13:08:13 +0200808 /* It's possible VF was previously considered malicious -
809 * clear the indication even if we're only going to disable VF.
810 */
811 vf->b_malicious = false;
812
Yuval Mintz0b55e272016-05-11 16:36:15 +0300813 if (vf->to_disable)
814 return 0;
815
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300816 DP_VERBOSE(p_hwfn,
817 QED_MSG_IOV,
818 "Enable internal access for vf %x [abs %x]\n",
819 vf->abs_vf_id, QED_VF_ABS_ID(p_hwfn, vf));
820
821 qed_iov_vf_pglue_clear_err(p_hwfn, p_ptt, QED_VF_ABS_ID(p_hwfn, vf));
822
Yuval Mintzb2b897e2016-05-15 14:48:06 +0300823 qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
824
Mintz, Yuval88072fd2017-05-29 09:53:08 +0300825 rc = qed_iov_enable_vf_access_msix(p_hwfn, p_ptt,
826 vf->abs_vf_id, vf->num_sbs);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300827 if (rc)
828 return rc;
829
830 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
831
832 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
833 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
834
835 qed_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
836 p_hwfn->hw_info.hw_mode);
837
838 /* unpretend */
839 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
840
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300841 vf->state = VF_FREE;
842
843 return rc;
844}
845
Yuval Mintz0b55e272016-05-11 16:36:15 +0300846/**
847 * @brief qed_iov_config_perm_table - configure the permission
848 * zone table.
849 * In E4, queue zone permission table size is 320x9. There
850 * are 320 VF queues for single engine device (256 for dual
851 * engine device), and each entry has the following format:
852 * {Valid, VF[7:0]}
853 * @param p_hwfn
854 * @param p_ptt
855 * @param vf
856 * @param enable
857 */
858static void qed_iov_config_perm_table(struct qed_hwfn *p_hwfn,
859 struct qed_ptt *p_ptt,
860 struct qed_vf_info *vf, u8 enable)
861{
862 u32 reg_addr, val;
863 u16 qzone_id = 0;
864 int qid;
865
866 for (qid = 0; qid < vf->num_rxqs; qid++) {
867 qed_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
868 &qzone_id);
869
870 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
Yuval Mintz1a635e42016-08-15 10:42:43 +0300871 val = enable ? (vf->abs_vf_id | BIT(8)) : 0;
Yuval Mintz0b55e272016-05-11 16:36:15 +0300872 qed_wr(p_hwfn, p_ptt, reg_addr, val);
873 }
874}
875
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300876static void qed_iov_enable_vf_traffic(struct qed_hwfn *p_hwfn,
877 struct qed_ptt *p_ptt,
878 struct qed_vf_info *vf)
879{
880 /* Reset vf in IGU - interrupts are still disabled */
881 qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
882
883 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
884
885 /* Permission Table */
886 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
887}
888
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300889static u8 qed_iov_alloc_vf_igu_sbs(struct qed_hwfn *p_hwfn,
890 struct qed_ptt *p_ptt,
891 struct qed_vf_info *vf, u16 num_rx_queues)
892{
Mintz, Yuval09b6b142017-06-01 15:29:08 +0300893 struct qed_igu_block *p_block;
894 struct cau_sb_entry sb_entry;
895 int qid = 0;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300896 u32 val = 0;
897
Mintz, Yuval726fdbe2017-06-01 15:29:06 +0300898 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov)
899 num_rx_queues = p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov;
900 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov -= num_rx_queues;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300901
902 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
903 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
904 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
905
Mintz, Yuval09b6b142017-06-01 15:29:08 +0300906 for (qid = 0; qid < num_rx_queues; qid++) {
907 p_block = qed_get_igu_free_sb(p_hwfn, false);
908 vf->igu_sbs[qid] = p_block->igu_sb_id;
909 p_block->status &= ~QED_IGU_STATUS_FREE;
910 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300911
Mintz, Yuval09b6b142017-06-01 15:29:08 +0300912 qed_wr(p_hwfn, p_ptt,
913 IGU_REG_MAPPING_MEMORY +
914 sizeof(u32) * p_block->igu_sb_id, val);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300915
Mintz, Yuval09b6b142017-06-01 15:29:08 +0300916 /* Configure igu sb in CAU which were marked valid */
917 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
918 p_hwfn->rel_pf_id, vf->abs_vf_id, 1);
919 qed_dmae_host2grc(p_hwfn, p_ptt,
920 (u64)(uintptr_t)&sb_entry,
921 CAU_REG_SB_VAR_MEMORY +
922 p_block->igu_sb_id * sizeof(u64), 2, 0);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300923 }
924
925 vf->num_sbs = (u8) num_rx_queues;
926
927 return vf->num_sbs;
928}
929
Yuval Mintz0b55e272016-05-11 16:36:15 +0300930static void qed_iov_free_vf_igu_sbs(struct qed_hwfn *p_hwfn,
931 struct qed_ptt *p_ptt,
932 struct qed_vf_info *vf)
933{
934 struct qed_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
935 int idx, igu_id;
936 u32 addr, val;
937
938 /* Invalidate igu CAM lines and mark them as free */
939 for (idx = 0; idx < vf->num_sbs; idx++) {
940 igu_id = vf->igu_sbs[idx];
941 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
942
943 val = qed_rd(p_hwfn, p_ptt, addr);
944 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
945 qed_wr(p_hwfn, p_ptt, addr, val);
946
Mintz, Yuvald749dd02017-06-01 15:29:03 +0300947 p_info->entry[igu_id].status |= QED_IGU_STATUS_FREE;
Mintz, Yuval726fdbe2017-06-01 15:29:06 +0300948 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov++;
Yuval Mintz0b55e272016-05-11 16:36:15 +0300949 }
950
951 vf->num_sbs = 0;
952}
953
Mintz, Yuval33b2fbd2017-02-20 22:43:36 +0200954static void qed_iov_set_link(struct qed_hwfn *p_hwfn,
955 u16 vfid,
956 struct qed_mcp_link_params *params,
957 struct qed_mcp_link_state *link,
958 struct qed_mcp_link_capabilities *p_caps)
959{
960 struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
961 vfid,
962 false);
963 struct qed_bulletin_content *p_bulletin;
964
965 if (!p_vf)
966 return;
967
968 p_bulletin = p_vf->bulletin.p_virt;
969 p_bulletin->req_autoneg = params->speed.autoneg;
970 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
971 p_bulletin->req_forced_speed = params->speed.forced_speed;
972 p_bulletin->req_autoneg_pause = params->pause.autoneg;
973 p_bulletin->req_forced_rx = params->pause.forced_rx;
974 p_bulletin->req_forced_tx = params->pause.forced_tx;
975 p_bulletin->req_loopback = params->loopback_mode;
976
977 p_bulletin->link_up = link->link_up;
978 p_bulletin->speed = link->speed;
979 p_bulletin->full_duplex = link->full_duplex;
980 p_bulletin->autoneg = link->an;
981 p_bulletin->autoneg_complete = link->an_complete;
982 p_bulletin->parallel_detection = link->parallel_detection;
983 p_bulletin->pfc_enabled = link->pfc_enabled;
984 p_bulletin->partner_adv_speed = link->partner_adv_speed;
985 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
986 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
987 p_bulletin->partner_adv_pause = link->partner_adv_pause;
988 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
989
990 p_bulletin->capability_speed = p_caps->speed_capabilities;
991}
992
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300993static int qed_iov_init_hw_for_vf(struct qed_hwfn *p_hwfn,
994 struct qed_ptt *p_ptt,
Mintz, Yuval3da7a372016-11-29 16:47:06 +0200995 struct qed_iov_vf_init_params *p_params)
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300996{
Mintz, Yuval33b2fbd2017-02-20 22:43:36 +0200997 struct qed_mcp_link_capabilities link_caps;
998 struct qed_mcp_link_params link_params;
999 struct qed_mcp_link_state link_state;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001000 u8 num_of_vf_avaiable_chains = 0;
1001 struct qed_vf_info *vf = NULL;
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001002 u16 qid, num_irqs;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001003 int rc = 0;
1004 u32 cids;
1005 u8 i;
1006
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001007 vf = qed_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001008 if (!vf) {
1009 DP_ERR(p_hwfn, "qed_iov_init_hw_for_vf : vf is NULL\n");
1010 return -EINVAL;
1011 }
1012
1013 if (vf->b_init) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001014 DP_NOTICE(p_hwfn, "VF[%d] is already active.\n",
1015 p_params->rel_vf_id);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001016 return -EINVAL;
1017 }
1018
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001019 /* Perform sanity checking on the requested queue_id */
1020 for (i = 0; i < p_params->num_queues; i++) {
1021 u16 min_vf_qzone = FEAT_NUM(p_hwfn, QED_PF_L2_QUE);
1022 u16 max_vf_qzone = min_vf_qzone +
1023 FEAT_NUM(p_hwfn, QED_VF_L2_QUE) - 1;
1024
1025 qid = p_params->req_rx_queue[i];
1026 if (qid < min_vf_qzone || qid > max_vf_qzone) {
1027 DP_NOTICE(p_hwfn,
1028 "Can't enable Rx qid [%04x] for VF[%d]: qids [0x%04x,...,0x%04x] available\n",
1029 qid,
1030 p_params->rel_vf_id,
1031 min_vf_qzone, max_vf_qzone);
1032 return -EINVAL;
1033 }
1034
1035 qid = p_params->req_tx_queue[i];
1036 if (qid > max_vf_qzone) {
1037 DP_NOTICE(p_hwfn,
1038 "Can't enable Tx qid [%04x] for VF[%d]: max qid 0x%04x\n",
1039 qid, p_params->rel_vf_id, max_vf_qzone);
1040 return -EINVAL;
1041 }
1042
1043 /* If client *really* wants, Tx qid can be shared with PF */
1044 if (qid < min_vf_qzone)
1045 DP_VERBOSE(p_hwfn,
1046 QED_MSG_IOV,
1047 "VF[%d] is using PF qid [0x%04x] for Txq[0x%02x]\n",
1048 p_params->rel_vf_id, qid, i);
1049 }
1050
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001051 /* Limit number of queues according to number of CIDs */
1052 qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
1053 DP_VERBOSE(p_hwfn,
1054 QED_MSG_IOV,
1055 "VF[%d] - requesting to initialize for 0x%04x queues [0x%04x CIDs available]\n",
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001056 vf->relative_vf_id, p_params->num_queues, (u16)cids);
1057 num_irqs = min_t(u16, p_params->num_queues, ((u16)cids));
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001058
1059 num_of_vf_avaiable_chains = qed_iov_alloc_vf_igu_sbs(p_hwfn,
1060 p_ptt,
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001061 vf, num_irqs);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001062 if (!num_of_vf_avaiable_chains) {
1063 DP_ERR(p_hwfn, "no available igu sbs\n");
1064 return -ENOMEM;
1065 }
1066
1067 /* Choose queue number and index ranges */
1068 vf->num_rxqs = num_of_vf_avaiable_chains;
1069 vf->num_txqs = num_of_vf_avaiable_chains;
1070
1071 for (i = 0; i < vf->num_rxqs; i++) {
Mintz, Yuval007bc372017-06-04 13:31:05 +03001072 struct qed_vf_queue *p_queue = &vf->vf_queues[i];
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001073
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001074 p_queue->fw_rx_qid = p_params->req_rx_queue[i];
1075 p_queue->fw_tx_qid = p_params->req_tx_queue[i];
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001076
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001077 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
Mintz, Yuval007bc372017-06-04 13:31:05 +03001078 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x]\n",
1079 vf->relative_vf_id, i, vf->igu_sbs[i],
1080 p_queue->fw_rx_qid, p_queue->fw_tx_qid);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001081 }
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001082
Mintz, Yuval33b2fbd2017-02-20 22:43:36 +02001083 /* Update the link configuration in bulletin */
1084 memcpy(&link_params, qed_mcp_get_link_params(p_hwfn),
1085 sizeof(link_params));
1086 memcpy(&link_state, qed_mcp_get_link_state(p_hwfn), sizeof(link_state));
1087 memcpy(&link_caps, qed_mcp_get_link_capabilities(p_hwfn),
1088 sizeof(link_caps));
1089 qed_iov_set_link(p_hwfn, p_params->rel_vf_id,
1090 &link_params, &link_state, &link_caps);
1091
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001092 rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, vf);
1093 if (!rc) {
1094 vf->b_init = true;
1095
1096 if (IS_LEAD_HWFN(p_hwfn))
1097 p_hwfn->cdev->p_iov_info->num_vfs++;
1098 }
1099
1100 return rc;
1101}
1102
Yuval Mintz0b55e272016-05-11 16:36:15 +03001103static int qed_iov_release_hw_for_vf(struct qed_hwfn *p_hwfn,
1104 struct qed_ptt *p_ptt, u16 rel_vf_id)
1105{
Manish Chopra079d20a2016-05-15 14:48:07 +03001106 struct qed_mcp_link_capabilities caps;
1107 struct qed_mcp_link_params params;
1108 struct qed_mcp_link_state link;
Yuval Mintz0b55e272016-05-11 16:36:15 +03001109 struct qed_vf_info *vf = NULL;
Yuval Mintz0b55e272016-05-11 16:36:15 +03001110
1111 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
1112 if (!vf) {
1113 DP_ERR(p_hwfn, "qed_iov_release_hw_for_vf : vf is NULL\n");
1114 return -EINVAL;
1115 }
1116
Yuval Mintz36558c32016-05-11 16:36:17 +03001117 if (vf->bulletin.p_virt)
1118 memset(vf->bulletin.p_virt, 0, sizeof(*vf->bulletin.p_virt));
1119
1120 memset(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
1121
Manish Chopra079d20a2016-05-15 14:48:07 +03001122 /* Get the link configuration back in bulletin so
1123 * that when VFs are re-enabled they get the actual
1124 * link configuration.
1125 */
1126 memcpy(&params, qed_mcp_get_link_params(p_hwfn), sizeof(params));
1127 memcpy(&link, qed_mcp_get_link_state(p_hwfn), sizeof(link));
1128 memcpy(&caps, qed_mcp_get_link_capabilities(p_hwfn), sizeof(caps));
1129 qed_iov_set_link(p_hwfn, rel_vf_id, &params, &link, &caps);
1130
Yuval Mintz1fe614d2016-06-05 13:11:11 +03001131 /* Forget the VF's acquisition message */
1132 memset(&vf->acquire, 0, sizeof(vf->acquire));
Yuval Mintz0b55e272016-05-11 16:36:15 +03001133
1134 /* disablng interrupts and resetting permission table was done during
1135 * vf-close, however, we could get here without going through vf_close
1136 */
1137 /* Disable Interrupts for VF */
1138 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1139
1140 /* Reset Permission table */
1141 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1142
1143 vf->num_rxqs = 0;
1144 vf->num_txqs = 0;
1145 qed_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
1146
1147 if (vf->b_init) {
1148 vf->b_init = false;
1149
1150 if (IS_LEAD_HWFN(p_hwfn))
1151 p_hwfn->cdev->p_iov_info->num_vfs--;
1152 }
1153
1154 return 0;
1155}
1156
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001157static bool qed_iov_tlv_supported(u16 tlvtype)
1158{
1159 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
1160}
1161
1162/* place a given tlv on the tlv buffer, continuing current tlv list */
1163void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length)
1164{
1165 struct channel_tlv *tl = (struct channel_tlv *)*offset;
1166
1167 tl->type = type;
1168 tl->length = length;
1169
1170 /* Offset should keep pointing to next TLV (the end of the last) */
1171 *offset += length;
1172
1173 /* Return a pointer to the start of the added tlv */
1174 return *offset - length;
1175}
1176
1177/* list the types and lengths of the tlvs on the buffer */
1178void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list)
1179{
1180 u16 i = 1, total_length = 0;
1181 struct channel_tlv *tlv;
1182
1183 do {
1184 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
1185
1186 /* output tlv */
1187 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1188 "TLV number %d: type %d, length %d\n",
1189 i, tlv->type, tlv->length);
1190
1191 if (tlv->type == CHANNEL_TLV_LIST_END)
1192 return;
1193
1194 /* Validate entry - protect against malicious VFs */
1195 if (!tlv->length) {
1196 DP_NOTICE(p_hwfn, "TLV of length 0 found\n");
1197 return;
1198 }
1199
1200 total_length += tlv->length;
1201
1202 if (total_length >= sizeof(struct tlv_buffer_size)) {
1203 DP_NOTICE(p_hwfn, "TLV ==> Buffer overflow\n");
1204 return;
1205 }
1206
1207 i++;
1208 } while (1);
1209}
1210
1211static void qed_iov_send_response(struct qed_hwfn *p_hwfn,
1212 struct qed_ptt *p_ptt,
1213 struct qed_vf_info *p_vf,
1214 u16 length, u8 status)
1215{
1216 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1217 struct qed_dmae_params params;
1218 u8 eng_vf_id;
1219
1220 mbx->reply_virt->default_resp.hdr.status = status;
1221
1222 qed_dp_tlv_list(p_hwfn, mbx->reply_virt);
1223
1224 eng_vf_id = p_vf->abs_vf_id;
1225
1226 memset(&params, 0, sizeof(struct qed_dmae_params));
1227 params.flags = QED_DMAE_FLAG_VF_DST;
1228 params.dst_vfid = eng_vf_id;
1229
1230 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1231 mbx->req_virt->first_tlv.reply_address +
1232 sizeof(u64),
1233 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1234 &params);
1235
Mintz, Yuvald9194082017-03-19 13:08:14 +02001236 /* Once PF copies the rc to the VF, the latter can continue
1237 * and send an additional message. So we have to make sure the
1238 * channel would be re-set to ready prior to that.
1239 */
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001240 REG_WR(p_hwfn,
1241 GTT_BAR0_MAP_REG_USDM_RAM +
1242 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
Mintz, Yuvald9194082017-03-19 13:08:14 +02001243
1244 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1245 mbx->req_virt->first_tlv.reply_address,
1246 sizeof(u64) / 4, &params);
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001247}
1248
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001249static u16 qed_iov_vport_to_tlv(struct qed_hwfn *p_hwfn,
1250 enum qed_iov_vport_update_flag flag)
1251{
1252 switch (flag) {
1253 case QED_IOV_VP_UPDATE_ACTIVATE:
1254 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
Yuval Mintz17b235c2016-05-11 16:36:18 +03001255 case QED_IOV_VP_UPDATE_VLAN_STRIP:
1256 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1257 case QED_IOV_VP_UPDATE_TX_SWITCH:
1258 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001259 case QED_IOV_VP_UPDATE_MCAST:
1260 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1261 case QED_IOV_VP_UPDATE_ACCEPT_PARAM:
1262 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1263 case QED_IOV_VP_UPDATE_RSS:
1264 return CHANNEL_TLV_VPORT_UPDATE_RSS;
Yuval Mintz17b235c2016-05-11 16:36:18 +03001265 case QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1266 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1267 case QED_IOV_VP_UPDATE_SGE_TPA:
1268 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001269 default:
1270 return 0;
1271 }
1272}
1273
1274static u16 qed_iov_prep_vp_update_resp_tlvs(struct qed_hwfn *p_hwfn,
1275 struct qed_vf_info *p_vf,
1276 struct qed_iov_vf_mbx *p_mbx,
1277 u8 status,
1278 u16 tlvs_mask, u16 tlvs_accepted)
1279{
1280 struct pfvf_def_resp_tlv *resp;
1281 u16 size, total_len, i;
1282
1283 memset(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1284 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1285 size = sizeof(struct pfvf_def_resp_tlv);
1286 total_len = size;
1287
1288 qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1289
1290 /* Prepare response for all extended tlvs if they are found by PF */
1291 for (i = 0; i < QED_IOV_VP_UPDATE_MAX; i++) {
Yuval Mintz1a635e42016-08-15 10:42:43 +03001292 if (!(tlvs_mask & BIT(i)))
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001293 continue;
1294
1295 resp = qed_add_tlv(p_hwfn, &p_mbx->offset,
1296 qed_iov_vport_to_tlv(p_hwfn, i), size);
1297
Yuval Mintz1a635e42016-08-15 10:42:43 +03001298 if (tlvs_accepted & BIT(i))
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001299 resp->hdr.status = status;
1300 else
1301 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1302
1303 DP_VERBOSE(p_hwfn,
1304 QED_MSG_IOV,
1305 "VF[%d] - vport_update response: TLV %d, status %02x\n",
1306 p_vf->relative_vf_id,
1307 qed_iov_vport_to_tlv(p_hwfn, i), resp->hdr.status);
1308
1309 total_len += size;
1310 }
1311
1312 qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_LIST_END,
1313 sizeof(struct channel_list_end_tlv));
1314
1315 return total_len;
1316}
1317
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001318static void qed_iov_prepare_resp(struct qed_hwfn *p_hwfn,
1319 struct qed_ptt *p_ptt,
1320 struct qed_vf_info *vf_info,
1321 u16 type, u16 length, u8 status)
1322{
1323 struct qed_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1324
1325 mbx->offset = (u8 *)mbx->reply_virt;
1326
1327 qed_add_tlv(p_hwfn, &mbx->offset, type, length);
1328 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1329 sizeof(struct channel_list_end_tlv));
1330
1331 qed_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1332}
1333
Baoyou Xieba569472016-09-09 09:21:15 +08001334static struct
1335qed_public_vf_info *qed_iov_get_public_vf_info(struct qed_hwfn *p_hwfn,
1336 u16 relative_vf_id,
1337 bool b_enabled_only)
Yuval Mintz0b55e272016-05-11 16:36:15 +03001338{
1339 struct qed_vf_info *vf = NULL;
1340
1341 vf = qed_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1342 if (!vf)
1343 return NULL;
1344
1345 return &vf->p_vf_info;
1346}
1347
Baoyou Xieba569472016-09-09 09:21:15 +08001348static void qed_iov_clean_vf(struct qed_hwfn *p_hwfn, u8 vfid)
Yuval Mintz0b55e272016-05-11 16:36:15 +03001349{
1350 struct qed_public_vf_info *vf_info;
1351
1352 vf_info = qed_iov_get_public_vf_info(p_hwfn, vfid, false);
1353
1354 if (!vf_info)
1355 return;
1356
1357 /* Clear the VF mac */
Shyam Saini0ee28e32017-01-17 07:35:04 +05301358 eth_zero_addr(vf_info->mac);
Mintz, Yuvalf990c822017-01-01 13:57:08 +02001359
1360 vf_info->rx_accept_mode = 0;
1361 vf_info->tx_accept_mode = 0;
Yuval Mintz0b55e272016-05-11 16:36:15 +03001362}
1363
1364static void qed_iov_vf_cleanup(struct qed_hwfn *p_hwfn,
1365 struct qed_vf_info *p_vf)
1366{
Mintz, Yuval007bc372017-06-04 13:31:05 +03001367 u32 i, j;
Yuval Mintz0b55e272016-05-11 16:36:15 +03001368
1369 p_vf->vf_bulletin = 0;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001370 p_vf->vport_instance = 0;
Yuval Mintz08feecd2016-05-11 16:36:20 +03001371 p_vf->configured_features = 0;
Yuval Mintz0b55e272016-05-11 16:36:15 +03001372
1373 /* If VF previously requested less resources, go back to default */
1374 p_vf->num_rxqs = p_vf->num_sbs;
1375 p_vf->num_txqs = p_vf->num_sbs;
1376
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001377 p_vf->num_active_rxqs = 0;
1378
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001379 for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++) {
Mintz, Yuval007bc372017-06-04 13:31:05 +03001380 struct qed_vf_queue *p_queue = &p_vf->vf_queues[i];
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001381
Mintz, Yuval007bc372017-06-04 13:31:05 +03001382 for (j = 0; j < MAX_QUEUES_PER_QZONE; j++) {
1383 if (!p_queue->cids[j].p_cid)
1384 continue;
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001385
Mintz, Yuval007bc372017-06-04 13:31:05 +03001386 qed_eth_queue_cid_release(p_hwfn,
1387 p_queue->cids[j].p_cid);
1388 p_queue->cids[j].p_cid = NULL;
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001389 }
1390 }
Yuval Mintz0b55e272016-05-11 16:36:15 +03001391
Yuval Mintz08feecd2016-05-11 16:36:20 +03001392 memset(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
Yuval Mintz1fe614d2016-06-05 13:11:11 +03001393 memset(&p_vf->acquire, 0, sizeof(p_vf->acquire));
Yuval Mintz0b55e272016-05-11 16:36:15 +03001394 qed_iov_clean_vf(p_hwfn, p_vf->relative_vf_id);
1395}
1396
Mintz, Yuval1a850bf2017-06-04 13:31:07 +03001397/* Returns either 0, or log(size) */
1398static u32 qed_iov_vf_db_bar_size(struct qed_hwfn *p_hwfn,
1399 struct qed_ptt *p_ptt)
1400{
1401 u32 val = qed_rd(p_hwfn, p_ptt, PGLUE_B_REG_VF_BAR1_SIZE);
1402
1403 if (val)
1404 return val + 11;
1405 return 0;
1406}
1407
1408static void
1409qed_iov_vf_mbx_acquire_resc_cids(struct qed_hwfn *p_hwfn,
1410 struct qed_ptt *p_ptt,
1411 struct qed_vf_info *p_vf,
1412 struct vf_pf_resc_request *p_req,
1413 struct pf_vf_resc *p_resp)
1414{
1415 u8 num_vf_cons = p_hwfn->pf_params.eth_pf_params.num_vf_cons;
1416 u8 db_size = qed_db_addr_vf(1, DQ_DEMS_LEGACY) -
1417 qed_db_addr_vf(0, DQ_DEMS_LEGACY);
1418 u32 bar_size;
1419
1420 p_resp->num_cids = min_t(u8, p_req->num_cids, num_vf_cons);
1421
1422 /* If VF didn't bother asking for QIDs than don't bother limiting
1423 * number of CIDs. The VF doesn't care about the number, and this
1424 * has the likely result of causing an additional acquisition.
1425 */
1426 if (!(p_vf->acquire.vfdev_info.capabilities &
1427 VFPF_ACQUIRE_CAP_QUEUE_QIDS))
1428 return;
1429
1430 /* If doorbell bar was mapped by VF, limit the VF CIDs to an amount
1431 * that would make sure doorbells for all CIDs fall within the bar.
1432 * If it doesn't, make sure regview window is sufficient.
1433 */
1434 if (p_vf->acquire.vfdev_info.capabilities &
1435 VFPF_ACQUIRE_CAP_PHYSICAL_BAR) {
1436 bar_size = qed_iov_vf_db_bar_size(p_hwfn, p_ptt);
1437 if (bar_size)
1438 bar_size = 1 << bar_size;
1439
1440 if (p_hwfn->cdev->num_hwfns > 1)
1441 bar_size /= 2;
1442 } else {
1443 bar_size = PXP_VF_BAR0_DQ_LENGTH;
1444 }
1445
1446 if (bar_size / db_size < 256)
1447 p_resp->num_cids = min_t(u8, p_resp->num_cids,
1448 (u8)(bar_size / db_size));
1449}
1450
Yuval Mintz1cf2b1a2016-06-05 13:11:12 +03001451static u8 qed_iov_vf_mbx_acquire_resc(struct qed_hwfn *p_hwfn,
1452 struct qed_ptt *p_ptt,
1453 struct qed_vf_info *p_vf,
1454 struct vf_pf_resc_request *p_req,
1455 struct pf_vf_resc *p_resp)
1456{
Mintz, Yuval007bc372017-06-04 13:31:05 +03001457 u8 i;
Yuval Mintz1cf2b1a2016-06-05 13:11:12 +03001458
1459 /* Queue related information */
1460 p_resp->num_rxqs = p_vf->num_rxqs;
1461 p_resp->num_txqs = p_vf->num_txqs;
1462 p_resp->num_sbs = p_vf->num_sbs;
1463
1464 for (i = 0; i < p_resp->num_sbs; i++) {
1465 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1466 p_resp->hw_sbs[i].sb_qid = 0;
1467 }
1468
1469 /* These fields are filled for backward compatibility.
1470 * Unused by modern vfs.
1471 */
1472 for (i = 0; i < p_resp->num_rxqs; i++) {
1473 qed_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1474 (u16 *)&p_resp->hw_qid[i]);
Mintz, Yuval007bc372017-06-04 13:31:05 +03001475 p_resp->cid[i] = i;
Yuval Mintz1cf2b1a2016-06-05 13:11:12 +03001476 }
1477
1478 /* Filter related information */
1479 p_resp->num_mac_filters = min_t(u8, p_vf->num_mac_filters,
1480 p_req->num_mac_filters);
1481 p_resp->num_vlan_filters = min_t(u8, p_vf->num_vlan_filters,
1482 p_req->num_vlan_filters);
1483
Mintz, Yuval1a850bf2017-06-04 13:31:07 +03001484 qed_iov_vf_mbx_acquire_resc_cids(p_hwfn, p_ptt, p_vf, p_req, p_resp);
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03001485
Yuval Mintz1cf2b1a2016-06-05 13:11:12 +03001486 /* This isn't really needed/enforced, but some legacy VFs might depend
1487 * on the correct filling of this field.
1488 */
1489 p_resp->num_mc_filters = QED_MAX_MC_ADDRS;
1490
1491 /* Validate sufficient resources for VF */
1492 if (p_resp->num_rxqs < p_req->num_rxqs ||
1493 p_resp->num_txqs < p_req->num_txqs ||
1494 p_resp->num_sbs < p_req->num_sbs ||
1495 p_resp->num_mac_filters < p_req->num_mac_filters ||
1496 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03001497 p_resp->num_mc_filters < p_req->num_mc_filters ||
1498 p_resp->num_cids < p_req->num_cids) {
Yuval Mintz1cf2b1a2016-06-05 13:11:12 +03001499 DP_VERBOSE(p_hwfn,
1500 QED_MSG_IOV,
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03001501 "VF[%d] - Insufficient resources: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x] cids [%02x/%02x]\n",
Yuval Mintz1cf2b1a2016-06-05 13:11:12 +03001502 p_vf->abs_vf_id,
1503 p_req->num_rxqs,
1504 p_resp->num_rxqs,
1505 p_req->num_rxqs,
1506 p_resp->num_txqs,
1507 p_req->num_sbs,
1508 p_resp->num_sbs,
1509 p_req->num_mac_filters,
1510 p_resp->num_mac_filters,
1511 p_req->num_vlan_filters,
1512 p_resp->num_vlan_filters,
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03001513 p_req->num_mc_filters,
1514 p_resp->num_mc_filters,
1515 p_req->num_cids, p_resp->num_cids);
Yuval Mintza044df82016-08-22 13:25:09 +03001516
1517 /* Some legacy OSes are incapable of correctly handling this
1518 * failure.
1519 */
1520 if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1521 ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
1522 (p_vf->acquire.vfdev_info.os_type ==
1523 VFPF_ACQUIRE_OS_WINDOWS))
1524 return PFVF_STATUS_SUCCESS;
1525
Yuval Mintz1cf2b1a2016-06-05 13:11:12 +03001526 return PFVF_STATUS_NO_RESOURCE;
1527 }
1528
1529 return PFVF_STATUS_SUCCESS;
1530}
1531
1532static void qed_iov_vf_mbx_acquire_stats(struct qed_hwfn *p_hwfn,
1533 struct pfvf_stats_info *p_stats)
1534{
1535 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1536 offsetof(struct mstorm_vf_zone,
1537 non_trigger.eth_queue_stat);
1538 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1539 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1540 offsetof(struct ustorm_vf_zone,
1541 non_trigger.eth_queue_stat);
1542 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1543 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1544 offsetof(struct pstorm_vf_zone,
1545 non_trigger.eth_queue_stat);
1546 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1547 p_stats->tstats.address = 0;
1548 p_stats->tstats.len = 0;
1549}
1550
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001551static void qed_iov_vf_mbx_acquire(struct qed_hwfn *p_hwfn,
1552 struct qed_ptt *p_ptt,
1553 struct qed_vf_info *vf)
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001554{
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001555 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1556 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1557 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1558 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
Yuval Mintz1cf2b1a2016-06-05 13:11:12 +03001559 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001560 struct pf_vf_resc *resc = &resp->resc;
Yuval Mintz1fe614d2016-06-05 13:11:11 +03001561 int rc;
1562
1563 memset(resp, 0, sizeof(*resp));
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001564
Yuval Mintz05fafbf2016-08-19 09:33:31 +03001565 /* Write the PF version so that VF would know which version
1566 * is supported - might be later overriden. This guarantees that
1567 * VF could recognize legacy PF based on lack of versions in reply.
1568 */
1569 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1570 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1571
Yuval Mintza044df82016-08-22 13:25:09 +03001572 if (vf->state != VF_FREE && vf->state != VF_STOPPED) {
1573 DP_VERBOSE(p_hwfn,
1574 QED_MSG_IOV,
1575 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1576 vf->abs_vf_id, vf->state);
1577 goto out;
1578 }
1579
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001580 /* Validate FW compatibility */
Yuval Mintz1fe614d2016-06-05 13:11:11 +03001581 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
Yuval Mintza044df82016-08-22 13:25:09 +03001582 if (req->vfdev_info.capabilities &
1583 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
1584 struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
Yuval Mintz1fe614d2016-06-05 13:11:11 +03001585
Yuval Mintza044df82016-08-22 13:25:09 +03001586 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1587 "VF[%d] is pre-fastpath HSI\n",
1588 vf->abs_vf_id);
1589 p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
1590 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
1591 } else {
1592 DP_INFO(p_hwfn,
1593 "VF[%d] needs fastpath HSI %02x.%02x, which is incompatible with loaded FW's faspath HSI %02x.%02x\n",
1594 vf->abs_vf_id,
1595 req->vfdev_info.eth_fp_hsi_major,
1596 req->vfdev_info.eth_fp_hsi_minor,
1597 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1598
1599 goto out;
1600 }
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001601 }
1602
1603 /* On 100g PFs, prevent old VFs from loading */
1604 if ((p_hwfn->cdev->num_hwfns > 1) &&
1605 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1606 DP_INFO(p_hwfn,
1607 "VF[%d] is running an old driver that doesn't support 100g\n",
1608 vf->abs_vf_id);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001609 goto out;
1610 }
1611
Yuval Mintz1fe614d2016-06-05 13:11:11 +03001612 /* Store the acquire message */
1613 memcpy(&vf->acquire, req, sizeof(vf->acquire));
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001614
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001615 vf->opaque_fid = req->vfdev_info.opaque_fid;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001616
1617 vf->vf_bulletin = req->bulletin_addr;
1618 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1619 vf->bulletin.size : req->bulletin_size;
1620
1621 /* fill in pfdev info */
1622 pfdev_info->chip_num = p_hwfn->cdev->chip_num;
1623 pfdev_info->db_size = 0;
Tomer Tayar21dd79e2017-12-27 19:30:06 +02001624 pfdev_info->indices_per_sb = PIS_PER_SB_E4;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001625
1626 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1627 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1628 if (p_hwfn->cdev->num_hwfns > 1)
1629 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1630
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03001631 /* Share our ability to use multiple queue-ids only with VFs
1632 * that request it.
1633 */
1634 if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_QUEUE_QIDS)
1635 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_QUEUE_QIDS;
1636
Mintz, Yuval1a850bf2017-06-04 13:31:07 +03001637 /* Share the sizes of the bars with VF */
1638 resp->pfdev_info.bar_size = qed_iov_vf_db_bar_size(p_hwfn, p_ptt);
1639
Yuval Mintz1cf2b1a2016-06-05 13:11:12 +03001640 qed_iov_vf_mbx_acquire_stats(p_hwfn, &pfdev_info->stats_info);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001641
1642 memcpy(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr, ETH_ALEN);
1643
1644 pfdev_info->fw_major = FW_MAJOR_VERSION;
1645 pfdev_info->fw_minor = FW_MINOR_VERSION;
1646 pfdev_info->fw_rev = FW_REVISION_VERSION;
1647 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
Yuval Mintza044df82016-08-22 13:25:09 +03001648
1649 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1650 * this field.
1651 */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001652 pfdev_info->minor_fp_hsi = min_t(u8, ETH_HSI_VER_MINOR,
Yuval Mintz1fe614d2016-06-05 13:11:11 +03001653 req->vfdev_info.eth_fp_hsi_minor);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001654 pfdev_info->os_type = VFPF_ACQUIRE_OS_LINUX;
1655 qed_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver, NULL);
1656
1657 pfdev_info->dev_type = p_hwfn->cdev->type;
1658 pfdev_info->chip_rev = p_hwfn->cdev->chip_rev;
1659
Yuval Mintz1cf2b1a2016-06-05 13:11:12 +03001660 /* Fill resources available to VF; Make sure there are enough to
1661 * satisfy the VF's request.
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001662 */
Yuval Mintz1cf2b1a2016-06-05 13:11:12 +03001663 vfpf_status = qed_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1664 &req->resc_request, resc);
1665 if (vfpf_status != PFVF_STATUS_SUCCESS)
1666 goto out;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001667
Yuval Mintz1fe614d2016-06-05 13:11:11 +03001668 /* Start the VF in FW */
1669 rc = qed_sp_vf_start(p_hwfn, vf);
1670 if (rc) {
1671 DP_NOTICE(p_hwfn, "Failed to start VF[%02x]\n", vf->abs_vf_id);
1672 vfpf_status = PFVF_STATUS_FAILURE;
1673 goto out;
1674 }
1675
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001676 /* Fill agreed size of bulletin board in response */
1677 resp->bulletin_size = vf->bulletin.size;
Yuval Mintz36558c32016-05-11 16:36:17 +03001678 qed_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001679
1680 DP_VERBOSE(p_hwfn,
1681 QED_MSG_IOV,
1682 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%llx\n"
1683 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d\n",
1684 vf->abs_vf_id,
1685 resp->pfdev_info.chip_num,
1686 resp->pfdev_info.db_size,
1687 resp->pfdev_info.indices_per_sb,
1688 resp->pfdev_info.capabilities,
1689 resc->num_rxqs,
1690 resc->num_txqs,
1691 resc->num_sbs,
1692 resc->num_mac_filters,
1693 resc->num_vlan_filters);
1694 vf->state = VF_ACQUIRED;
1695
1696 /* Prepare Response */
1697out:
1698 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1699 sizeof(struct pfvf_acquire_resp_tlv), vfpf_status);
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001700}
1701
Yuval Mintz6ddc7602016-05-11 16:36:23 +03001702static int __qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn,
1703 struct qed_vf_info *p_vf, bool val)
1704{
1705 struct qed_sp_vport_update_params params;
1706 int rc;
1707
1708 if (val == p_vf->spoof_chk) {
1709 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1710 "Spoofchk value[%d] is already configured\n", val);
1711 return 0;
1712 }
1713
1714 memset(&params, 0, sizeof(struct qed_sp_vport_update_params));
1715 params.opaque_fid = p_vf->opaque_fid;
1716 params.vport_id = p_vf->vport_id;
1717 params.update_anti_spoofing_en_flg = 1;
1718 params.anti_spoofing_en = val;
1719
1720 rc = qed_sp_vport_update(p_hwfn, &params, QED_SPQ_MODE_EBLOCK, NULL);
Yuval Mintzcb1fa082016-07-27 14:45:20 +03001721 if (!rc) {
Yuval Mintz6ddc7602016-05-11 16:36:23 +03001722 p_vf->spoof_chk = val;
1723 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1724 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1725 "Spoofchk val[%d] configured\n", val);
1726 } else {
1727 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1728 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1729 val, p_vf->relative_vf_id);
1730 }
1731
1732 return rc;
1733}
1734
Yuval Mintz08feecd2016-05-11 16:36:20 +03001735static int qed_iov_reconfigure_unicast_vlan(struct qed_hwfn *p_hwfn,
1736 struct qed_vf_info *p_vf)
1737{
1738 struct qed_filter_ucast filter;
1739 int rc = 0;
1740 int i;
1741
1742 memset(&filter, 0, sizeof(filter));
1743 filter.is_rx_filter = 1;
1744 filter.is_tx_filter = 1;
1745 filter.vport_to_add_to = p_vf->vport_id;
1746 filter.opcode = QED_FILTER_ADD;
1747
1748 /* Reconfigure vlans */
1749 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1750 if (!p_vf->shadow_config.vlans[i].used)
1751 continue;
1752
1753 filter.type = QED_FILTER_VLAN;
1754 filter.vlan = p_vf->shadow_config.vlans[i].vid;
Yuval Mintz1a635e42016-08-15 10:42:43 +03001755 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
Yuval Mintz08feecd2016-05-11 16:36:20 +03001756 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1757 filter.vlan, p_vf->relative_vf_id);
Yuval Mintz1a635e42016-08-15 10:42:43 +03001758 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1759 &filter, QED_SPQ_MODE_CB, NULL);
Yuval Mintz08feecd2016-05-11 16:36:20 +03001760 if (rc) {
1761 DP_NOTICE(p_hwfn,
1762 "Failed to configure VLAN [%04x] to VF [%04x]\n",
1763 filter.vlan, p_vf->relative_vf_id);
1764 break;
1765 }
1766 }
1767
1768 return rc;
1769}
1770
1771static int
1772qed_iov_reconfigure_unicast_shadow(struct qed_hwfn *p_hwfn,
1773 struct qed_vf_info *p_vf, u64 events)
1774{
1775 int rc = 0;
1776
Yuval Mintz1a635e42016-08-15 10:42:43 +03001777 if ((events & BIT(VLAN_ADDR_FORCED)) &&
Yuval Mintz08feecd2016-05-11 16:36:20 +03001778 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1779 rc = qed_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1780
1781 return rc;
1782}
1783
1784static int qed_iov_configure_vport_forced(struct qed_hwfn *p_hwfn,
1785 struct qed_vf_info *p_vf, u64 events)
1786{
1787 int rc = 0;
1788 struct qed_filter_ucast filter;
1789
1790 if (!p_vf->vport_instance)
1791 return -EINVAL;
1792
Shahed Shaikh7425d822018-04-19 05:50:11 -07001793 if ((events & BIT(MAC_ADDR_FORCED)) ||
1794 p_vf->p_vf_info.is_trusted_configured) {
Yuval Mintzeff16962016-05-11 16:36:21 +03001795 /* Since there's no way [currently] of removing the MAC,
1796 * we can always assume this means we need to force it.
1797 */
1798 memset(&filter, 0, sizeof(filter));
1799 filter.type = QED_FILTER_MAC;
1800 filter.opcode = QED_FILTER_REPLACE;
1801 filter.is_rx_filter = 1;
1802 filter.is_tx_filter = 1;
1803 filter.vport_to_add_to = p_vf->vport_id;
1804 ether_addr_copy(filter.mac, p_vf->bulletin.p_virt->mac);
1805
1806 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1807 &filter, QED_SPQ_MODE_CB, NULL);
1808 if (rc) {
1809 DP_NOTICE(p_hwfn,
1810 "PF failed to configure MAC for VF\n");
1811 return rc;
1812 }
Shahed Shaikh7425d822018-04-19 05:50:11 -07001813 if (p_vf->p_vf_info.is_trusted_configured)
1814 p_vf->configured_features |=
1815 BIT(VFPF_BULLETIN_MAC_ADDR);
1816 else
1817 p_vf->configured_features |=
1818 BIT(MAC_ADDR_FORCED);
Yuval Mintzeff16962016-05-11 16:36:21 +03001819 }
1820
Yuval Mintz1a635e42016-08-15 10:42:43 +03001821 if (events & BIT(VLAN_ADDR_FORCED)) {
Yuval Mintz08feecd2016-05-11 16:36:20 +03001822 struct qed_sp_vport_update_params vport_update;
1823 u8 removal;
1824 int i;
1825
1826 memset(&filter, 0, sizeof(filter));
1827 filter.type = QED_FILTER_VLAN;
1828 filter.is_rx_filter = 1;
1829 filter.is_tx_filter = 1;
1830 filter.vport_to_add_to = p_vf->vport_id;
1831 filter.vlan = p_vf->bulletin.p_virt->pvid;
1832 filter.opcode = filter.vlan ? QED_FILTER_REPLACE :
1833 QED_FILTER_FLUSH;
1834
1835 /* Send the ramrod */
1836 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1837 &filter, QED_SPQ_MODE_CB, NULL);
1838 if (rc) {
1839 DP_NOTICE(p_hwfn,
1840 "PF failed to configure VLAN for VF\n");
1841 return rc;
1842 }
1843
1844 /* Update the default-vlan & silent vlan stripping */
1845 memset(&vport_update, 0, sizeof(vport_update));
1846 vport_update.opaque_fid = p_vf->opaque_fid;
1847 vport_update.vport_id = p_vf->vport_id;
1848 vport_update.update_default_vlan_enable_flg = 1;
1849 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
1850 vport_update.update_default_vlan_flg = 1;
1851 vport_update.default_vlan = filter.vlan;
1852
1853 vport_update.update_inner_vlan_removal_flg = 1;
1854 removal = filter.vlan ? 1
1855 : p_vf->shadow_config.inner_vlan_removal;
1856 vport_update.inner_vlan_removal_flg = removal;
1857 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
1858 rc = qed_sp_vport_update(p_hwfn,
1859 &vport_update,
1860 QED_SPQ_MODE_EBLOCK, NULL);
1861 if (rc) {
1862 DP_NOTICE(p_hwfn,
1863 "PF failed to configure VF vport for vlan\n");
1864 return rc;
1865 }
1866
1867 /* Update all the Rx queues */
1868 for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++) {
Mintz, Yuval007bc372017-06-04 13:31:05 +03001869 struct qed_vf_queue *p_queue = &p_vf->vf_queues[i];
1870 struct qed_queue_cid *p_cid = NULL;
Yuval Mintz08feecd2016-05-11 16:36:20 +03001871
Mintz, Yuval007bc372017-06-04 13:31:05 +03001872 /* There can be at most 1 Rx queue on qzone. Find it */
1873 p_cid = qed_iov_get_vf_rx_queue_cid(p_queue);
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001874 if (!p_cid)
Yuval Mintz08feecd2016-05-11 16:36:20 +03001875 continue;
1876
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001877 rc = qed_sp_eth_rx_queues_update(p_hwfn,
1878 (void **)&p_cid,
Yuval Mintz08feecd2016-05-11 16:36:20 +03001879 1, 0, 1,
1880 QED_SPQ_MODE_EBLOCK,
1881 NULL);
1882 if (rc) {
1883 DP_NOTICE(p_hwfn,
1884 "Failed to send Rx update fo queue[0x%04x]\n",
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001885 p_cid->rel.queue_id);
Yuval Mintz08feecd2016-05-11 16:36:20 +03001886 return rc;
1887 }
1888 }
1889
1890 if (filter.vlan)
1891 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
1892 else
Yuval Mintz1a635e42016-08-15 10:42:43 +03001893 p_vf->configured_features &= ~BIT(VLAN_ADDR_FORCED);
Yuval Mintz08feecd2016-05-11 16:36:20 +03001894 }
1895
1896 /* If forced features are terminated, we need to configure the shadow
1897 * configuration back again.
1898 */
1899 if (events)
1900 qed_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
1901
1902 return rc;
1903}
1904
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001905static void qed_iov_vf_mbx_start_vport(struct qed_hwfn *p_hwfn,
1906 struct qed_ptt *p_ptt,
1907 struct qed_vf_info *vf)
1908{
1909 struct qed_sp_vport_start_params params = { 0 };
1910 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1911 struct vfpf_vport_start_tlv *start;
1912 u8 status = PFVF_STATUS_SUCCESS;
1913 struct qed_vf_info *vf_info;
Yuval Mintz08feecd2016-05-11 16:36:20 +03001914 u64 *p_bitmap;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001915 int sb_id;
1916 int rc;
1917
1918 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vf->relative_vf_id, true);
1919 if (!vf_info) {
1920 DP_NOTICE(p_hwfn->cdev,
1921 "Failed to get VF info, invalid vfid [%d]\n",
1922 vf->relative_vf_id);
1923 return;
1924 }
1925
1926 vf->state = VF_ENABLED;
1927 start = &mbx->req_virt->start_vport;
1928
Mintz, Yuvalb801b152017-03-19 13:08:15 +02001929 qed_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
1930
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001931 /* Initialize Status block in CAU */
1932 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
1933 if (!start->sb_addr[sb_id]) {
1934 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1935 "VF[%d] did not fill the address of SB %d\n",
1936 vf->relative_vf_id, sb_id);
1937 break;
1938 }
1939
1940 qed_int_cau_conf_sb(p_hwfn, p_ptt,
1941 start->sb_addr[sb_id],
Yuval Mintz1a635e42016-08-15 10:42:43 +03001942 vf->igu_sbs[sb_id], vf->abs_vf_id, 1);
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001943 }
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001944
1945 vf->mtu = start->mtu;
Yuval Mintz08feecd2016-05-11 16:36:20 +03001946 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
1947
1948 /* Take into consideration configuration forced by hypervisor;
1949 * If none is configured, use the supplied VF values [for old
1950 * vfs that would still be fine, since they passed '0' as padding].
1951 */
1952 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
Yuval Mintz1a635e42016-08-15 10:42:43 +03001953 if (!(*p_bitmap & BIT(VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
Yuval Mintz08feecd2016-05-11 16:36:20 +03001954 u8 vf_req = start->only_untagged;
1955
1956 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
1957 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
1958 }
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001959
1960 params.tpa_mode = start->tpa_mode;
1961 params.remove_inner_vlan = start->inner_vlan_removal;
Yuval Mintz831bfb0e2016-05-11 16:36:25 +03001962 params.tx_switching = true;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001963
Yuval Mintz08feecd2016-05-11 16:36:20 +03001964 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001965 params.drop_ttl0 = false;
1966 params.concrete_fid = vf->concrete_fid;
1967 params.opaque_fid = vf->opaque_fid;
1968 params.vport_id = vf->vport_id;
1969 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
1970 params.mtu = vf->mtu;
Yuval Mintz11a85d72016-08-22 13:25:10 +03001971 params.check_mac = true;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001972
1973 rc = qed_sp_eth_vport_start(p_hwfn, &params);
Yuval Mintz1a635e42016-08-15 10:42:43 +03001974 if (rc) {
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001975 DP_ERR(p_hwfn,
1976 "qed_iov_vf_mbx_start_vport returned error %d\n", rc);
1977 status = PFVF_STATUS_FAILURE;
1978 } else {
1979 vf->vport_instance++;
Yuval Mintz08feecd2016-05-11 16:36:20 +03001980
1981 /* Force configuration if needed on the newly opened vport */
1982 qed_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
Yuval Mintz6ddc7602016-05-11 16:36:23 +03001983
1984 __qed_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001985 }
1986 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
1987 sizeof(struct pfvf_def_resp_tlv), status);
1988}
1989
1990static void qed_iov_vf_mbx_stop_vport(struct qed_hwfn *p_hwfn,
1991 struct qed_ptt *p_ptt,
1992 struct qed_vf_info *vf)
1993{
1994 u8 status = PFVF_STATUS_SUCCESS;
1995 int rc;
1996
1997 vf->vport_instance--;
Yuval Mintz6ddc7602016-05-11 16:36:23 +03001998 vf->spoof_chk = false;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001999
Mintz, Yuvalf109c242017-03-19 13:08:16 +02002000 if ((qed_iov_validate_active_rxq(p_hwfn, vf)) ||
2001 (qed_iov_validate_active_txq(p_hwfn, vf))) {
2002 vf->b_malicious = true;
2003 DP_NOTICE(p_hwfn,
2004 "VF [%02x] - considered malicious; Unable to stop RX/TX queuess\n",
2005 vf->abs_vf_id);
2006 status = PFVF_STATUS_MALICIOUS;
2007 goto out;
2008 }
2009
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002010 rc = qed_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
Yuval Mintz1a635e42016-08-15 10:42:43 +03002011 if (rc) {
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002012 DP_ERR(p_hwfn, "qed_iov_vf_mbx_stop_vport returned error %d\n",
2013 rc);
2014 status = PFVF_STATUS_FAILURE;
2015 }
2016
Yuval Mintz08feecd2016-05-11 16:36:20 +03002017 /* Forget the configuration on the vport */
2018 vf->configured_features = 0;
2019 memset(&vf->shadow_config, 0, sizeof(vf->shadow_config));
2020
Mintz, Yuvalf109c242017-03-19 13:08:16 +02002021out:
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002022 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
2023 sizeof(struct pfvf_def_resp_tlv), status);
2024}
2025
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002026static void qed_iov_vf_mbx_start_rxq_resp(struct qed_hwfn *p_hwfn,
2027 struct qed_ptt *p_ptt,
Yuval Mintza044df82016-08-22 13:25:09 +03002028 struct qed_vf_info *vf,
2029 u8 status, bool b_legacy)
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002030{
2031 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2032 struct pfvf_start_queue_resp_tlv *p_tlv;
2033 struct vfpf_start_rxq_tlv *req;
Yuval Mintza044df82016-08-22 13:25:09 +03002034 u16 length;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002035
2036 mbx->offset = (u8 *)mbx->reply_virt;
2037
Yuval Mintza044df82016-08-22 13:25:09 +03002038 /* Taking a bigger struct instead of adding a TLV to list was a
2039 * mistake, but one which we're now stuck with, as some older
2040 * clients assume the size of the previous response.
2041 */
2042 if (!b_legacy)
2043 length = sizeof(*p_tlv);
2044 else
2045 length = sizeof(struct pfvf_def_resp_tlv);
2046
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002047 p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_RXQ,
Yuval Mintza044df82016-08-22 13:25:09 +03002048 length);
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002049 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2050 sizeof(struct channel_list_end_tlv));
2051
2052 /* Update the TLV with the response */
Yuval Mintza044df82016-08-22 13:25:09 +03002053 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002054 req = &mbx->req_virt->start_rxq;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03002055 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
2056 offsetof(struct mstorm_vf_zone,
2057 non_trigger.eth_rx_queue_producers) +
2058 sizeof(struct eth_rx_prod_data) * req->rx_qid;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002059 }
2060
Yuval Mintza044df82016-08-22 13:25:09 +03002061 qed_iov_send_response(p_hwfn, p_ptt, vf, length, status);
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002062}
2063
Mintz, Yuvalbbe3f232017-06-04 13:31:03 +03002064static u8 qed_iov_vf_mbx_qid(struct qed_hwfn *p_hwfn,
2065 struct qed_vf_info *p_vf, bool b_is_tx)
2066{
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002067 struct qed_iov_vf_mbx *p_mbx = &p_vf->vf_mbx;
2068 struct vfpf_qid_tlv *p_qid_tlv;
2069
2070 /* Search for the qid if the VF published its going to provide it */
2071 if (!(p_vf->acquire.vfdev_info.capabilities &
2072 VFPF_ACQUIRE_CAP_QUEUE_QIDS)) {
2073 if (b_is_tx)
2074 return QED_IOV_LEGACY_QID_TX;
2075 else
2076 return QED_IOV_LEGACY_QID_RX;
2077 }
2078
2079 p_qid_tlv = (struct vfpf_qid_tlv *)
2080 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2081 CHANNEL_TLV_QID);
2082 if (!p_qid_tlv) {
2083 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2084 "VF[%2x]: Failed to provide qid\n",
2085 p_vf->relative_vf_id);
2086
2087 return QED_IOV_QID_INVALID;
2088 }
2089
2090 if (p_qid_tlv->qid >= MAX_QUEUES_PER_QZONE) {
2091 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2092 "VF[%02x]: Provided qid out-of-bounds %02x\n",
2093 p_vf->relative_vf_id, p_qid_tlv->qid);
2094 return QED_IOV_QID_INVALID;
2095 }
2096
2097 return p_qid_tlv->qid;
Mintz, Yuvalbbe3f232017-06-04 13:31:03 +03002098}
2099
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002100static void qed_iov_vf_mbx_start_rxq(struct qed_hwfn *p_hwfn,
2101 struct qed_ptt *p_ptt,
2102 struct qed_vf_info *vf)
2103{
2104 struct qed_queue_start_common_params params;
Mintz, Yuval39464972017-06-04 13:31:02 +03002105 struct qed_queue_cid_vf_params vf_params;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002106 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
Yuval Mintz41086462016-06-05 13:11:13 +03002107 u8 status = PFVF_STATUS_NO_RESOURCE;
Mintz, Yuval3b19f472017-06-04 13:31:04 +03002108 u8 qid_usage_idx, vf_legacy = 0;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002109 struct vfpf_start_rxq_tlv *req;
Mintz, Yuval007bc372017-06-04 13:31:05 +03002110 struct qed_vf_queue *p_queue;
2111 struct qed_queue_cid *p_cid;
Mintz, Yuvalf604b172017-06-04 13:31:01 +03002112 struct qed_sb_info sb_dummy;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002113 int rc;
2114
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002115 req = &mbx->req_virt->start_rxq;
Yuval Mintz41086462016-06-05 13:11:13 +03002116
Mintz, Yuvalf109c242017-03-19 13:08:16 +02002117 if (!qed_iov_validate_rxq(p_hwfn, vf, req->rx_qid,
2118 QED_IOV_VALIDATE_Q_DISABLE) ||
Yuval Mintz41086462016-06-05 13:11:13 +03002119 !qed_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2120 goto out;
2121
Mintz, Yuvalbbe3f232017-06-04 13:31:03 +03002122 qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, false);
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002123 if (qid_usage_idx == QED_IOV_QID_INVALID)
2124 goto out;
2125
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002126 p_queue = &vf->vf_queues[req->rx_qid];
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002127 if (p_queue->cids[qid_usage_idx].p_cid)
2128 goto out;
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002129
Mintz, Yuval3b19f472017-06-04 13:31:04 +03002130 vf_legacy = qed_vf_calculate_legacy(vf);
Mintz, Yuval39464972017-06-04 13:31:02 +03002131
Mintz, Yuvalbbe3f232017-06-04 13:31:03 +03002132 /* Acquire a new queue-cid */
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002133 memset(&params, 0, sizeof(params));
2134 params.queue_id = p_queue->fw_rx_qid;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002135 params.vport_id = vf->vport_id;
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002136 params.stats_id = vf->abs_vf_id + 0x10;
Mintz, Yuvalf604b172017-06-04 13:31:01 +03002137 /* Since IGU index is passed via sb_info, construct a dummy one */
2138 memset(&sb_dummy, 0, sizeof(sb_dummy));
2139 sb_dummy.igu_sb_id = req->hw_sb;
2140 params.p_sb = &sb_dummy;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002141 params.sb_idx = req->sb_index;
2142
Mintz, Yuval39464972017-06-04 13:31:02 +03002143 memset(&vf_params, 0, sizeof(vf_params));
2144 vf_params.vfid = vf->relative_vf_id;
2145 vf_params.vf_qid = (u8)req->rx_qid;
Mintz, Yuval3b19f472017-06-04 13:31:04 +03002146 vf_params.vf_legacy = vf_legacy;
Mintz, Yuvalbbe3f232017-06-04 13:31:03 +03002147 vf_params.qid_usage_idx = qid_usage_idx;
Mintz, Yuval007bc372017-06-04 13:31:05 +03002148 p_cid = qed_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2149 &params, true, &vf_params);
2150 if (!p_cid)
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002151 goto out;
2152
Yuval Mintza044df82016-08-22 13:25:09 +03002153 /* Legacy VFs have their Producers in a different location, which they
2154 * calculate on their own and clean the producer prior to this.
2155 */
Mintz, Yuval3b19f472017-06-04 13:31:04 +03002156 if (!(vf_legacy & QED_QCID_LEGACY_VF_RX_PROD))
Yuval Mintza044df82016-08-22 13:25:09 +03002157 REG_WR(p_hwfn,
2158 GTT_BAR0_MAP_REG_MSDM_RAM +
2159 MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id, req->rx_qid),
2160 0);
Yuval Mintza044df82016-08-22 13:25:09 +03002161
Mintz, Yuval007bc372017-06-04 13:31:05 +03002162 rc = qed_eth_rxq_start_ramrod(p_hwfn, p_cid,
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002163 req->bd_max_bytes,
2164 req->rxq_addr,
2165 req->cqe_pbl_addr, req->cqe_pbl_size);
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002166 if (rc) {
2167 status = PFVF_STATUS_FAILURE;
Mintz, Yuval007bc372017-06-04 13:31:05 +03002168 qed_eth_queue_cid_release(p_hwfn, p_cid);
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002169 } else {
Mintz, Yuval007bc372017-06-04 13:31:05 +03002170 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2171 p_queue->cids[qid_usage_idx].b_is_tx = false;
Yuval Mintz41086462016-06-05 13:11:13 +03002172 status = PFVF_STATUS_SUCCESS;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002173 vf->num_active_rxqs++;
2174 }
2175
Yuval Mintz41086462016-06-05 13:11:13 +03002176out:
Mintz, Yuval3b19f472017-06-04 13:31:04 +03002177 qed_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status,
2178 !!(vf_legacy &
2179 QED_QCID_LEGACY_VF_RX_PROD));
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002180}
2181
Chopra, Manisheaf3c0c2017-04-24 10:00:49 -07002182static void
2183qed_iov_pf_update_tun_response(struct pfvf_update_tunn_param_tlv *p_resp,
2184 struct qed_tunnel_info *p_tun,
2185 u16 tunn_feature_mask)
2186{
2187 p_resp->tunn_feature_mask = tunn_feature_mask;
2188 p_resp->vxlan_mode = p_tun->vxlan.b_mode_enabled;
2189 p_resp->l2geneve_mode = p_tun->l2_geneve.b_mode_enabled;
2190 p_resp->ipgeneve_mode = p_tun->ip_geneve.b_mode_enabled;
2191 p_resp->l2gre_mode = p_tun->l2_gre.b_mode_enabled;
2192 p_resp->ipgre_mode = p_tun->l2_gre.b_mode_enabled;
2193 p_resp->vxlan_clss = p_tun->vxlan.tun_cls;
2194 p_resp->l2gre_clss = p_tun->l2_gre.tun_cls;
2195 p_resp->ipgre_clss = p_tun->ip_gre.tun_cls;
2196 p_resp->l2geneve_clss = p_tun->l2_geneve.tun_cls;
2197 p_resp->ipgeneve_clss = p_tun->ip_geneve.tun_cls;
2198 p_resp->geneve_udp_port = p_tun->geneve_port.port;
2199 p_resp->vxlan_udp_port = p_tun->vxlan_port.port;
2200}
2201
2202static void
2203__qed_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2204 struct qed_tunn_update_type *p_tun,
2205 enum qed_tunn_mode mask, u8 tun_cls)
2206{
2207 if (p_req->tun_mode_update_mask & BIT(mask)) {
2208 p_tun->b_update_mode = true;
2209
2210 if (p_req->tunn_mode & BIT(mask))
2211 p_tun->b_mode_enabled = true;
2212 }
2213
2214 p_tun->tun_cls = tun_cls;
2215}
2216
2217static void
2218qed_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2219 struct qed_tunn_update_type *p_tun,
2220 struct qed_tunn_update_udp_port *p_port,
2221 enum qed_tunn_mode mask,
2222 u8 tun_cls, u8 update_port, u16 port)
2223{
2224 if (update_port) {
2225 p_port->b_update_port = true;
2226 p_port->port = port;
2227 }
2228
2229 __qed_iov_pf_update_tun_param(p_req, p_tun, mask, tun_cls);
2230}
2231
2232static bool
2233qed_iov_pf_validate_tunn_param(struct vfpf_update_tunn_param_tlv *p_req)
2234{
2235 bool b_update_requested = false;
2236
2237 if (p_req->tun_mode_update_mask || p_req->update_tun_cls ||
2238 p_req->update_geneve_port || p_req->update_vxlan_port)
2239 b_update_requested = true;
2240
2241 return b_update_requested;
2242}
2243
2244static void qed_pf_validate_tunn_mode(struct qed_tunn_update_type *tun, int *rc)
2245{
2246 if (tun->b_update_mode && !tun->b_mode_enabled) {
2247 tun->b_update_mode = false;
2248 *rc = -EINVAL;
2249 }
2250}
2251
2252static int
2253qed_pf_validate_modify_tunn_config(struct qed_hwfn *p_hwfn,
2254 u16 *tun_features, bool *update,
2255 struct qed_tunnel_info *tun_src)
2256{
2257 struct qed_eth_cb_ops *ops = p_hwfn->cdev->protocol_ops.eth;
2258 struct qed_tunnel_info *tun = &p_hwfn->cdev->tunnel;
2259 u16 bultn_vxlan_port, bultn_geneve_port;
2260 void *cookie = p_hwfn->cdev->ops_cookie;
2261 int i, rc = 0;
2262
2263 *tun_features = p_hwfn->cdev->tunn_feature_mask;
2264 bultn_vxlan_port = tun->vxlan_port.port;
2265 bultn_geneve_port = tun->geneve_port.port;
2266 qed_pf_validate_tunn_mode(&tun_src->vxlan, &rc);
2267 qed_pf_validate_tunn_mode(&tun_src->l2_geneve, &rc);
2268 qed_pf_validate_tunn_mode(&tun_src->ip_geneve, &rc);
2269 qed_pf_validate_tunn_mode(&tun_src->l2_gre, &rc);
2270 qed_pf_validate_tunn_mode(&tun_src->ip_gre, &rc);
2271
2272 if ((tun_src->b_update_rx_cls || tun_src->b_update_tx_cls) &&
2273 (tun_src->vxlan.tun_cls != QED_TUNN_CLSS_MAC_VLAN ||
2274 tun_src->l2_geneve.tun_cls != QED_TUNN_CLSS_MAC_VLAN ||
2275 tun_src->ip_geneve.tun_cls != QED_TUNN_CLSS_MAC_VLAN ||
2276 tun_src->l2_gre.tun_cls != QED_TUNN_CLSS_MAC_VLAN ||
2277 tun_src->ip_gre.tun_cls != QED_TUNN_CLSS_MAC_VLAN)) {
2278 tun_src->b_update_rx_cls = false;
2279 tun_src->b_update_tx_cls = false;
2280 rc = -EINVAL;
2281 }
2282
2283 if (tun_src->vxlan_port.b_update_port) {
2284 if (tun_src->vxlan_port.port == tun->vxlan_port.port) {
2285 tun_src->vxlan_port.b_update_port = false;
2286 } else {
2287 *update = true;
2288 bultn_vxlan_port = tun_src->vxlan_port.port;
2289 }
2290 }
2291
2292 if (tun_src->geneve_port.b_update_port) {
2293 if (tun_src->geneve_port.port == tun->geneve_port.port) {
2294 tun_src->geneve_port.b_update_port = false;
2295 } else {
2296 *update = true;
2297 bultn_geneve_port = tun_src->geneve_port.port;
2298 }
2299 }
2300
2301 qed_for_each_vf(p_hwfn, i) {
2302 qed_iov_bulletin_set_udp_ports(p_hwfn, i, bultn_vxlan_port,
2303 bultn_geneve_port);
2304 }
2305
2306 qed_schedule_iov(p_hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
2307 ops->ports_update(cookie, bultn_vxlan_port, bultn_geneve_port);
2308
2309 return rc;
2310}
2311
2312static void qed_iov_vf_mbx_update_tunn_param(struct qed_hwfn *p_hwfn,
2313 struct qed_ptt *p_ptt,
2314 struct qed_vf_info *p_vf)
2315{
2316 struct qed_tunnel_info *p_tun = &p_hwfn->cdev->tunnel;
2317 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2318 struct pfvf_update_tunn_param_tlv *p_resp;
2319 struct vfpf_update_tunn_param_tlv *p_req;
2320 u8 status = PFVF_STATUS_SUCCESS;
2321 bool b_update_required = false;
2322 struct qed_tunnel_info tunn;
2323 u16 tunn_feature_mask = 0;
2324 int i, rc = 0;
2325
2326 mbx->offset = (u8 *)mbx->reply_virt;
2327
2328 memset(&tunn, 0, sizeof(tunn));
2329 p_req = &mbx->req_virt->tunn_param_update;
2330
2331 if (!qed_iov_pf_validate_tunn_param(p_req)) {
2332 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2333 "No tunnel update requested by VF\n");
2334 status = PFVF_STATUS_FAILURE;
2335 goto send_resp;
2336 }
2337
2338 tunn.b_update_rx_cls = p_req->update_tun_cls;
2339 tunn.b_update_tx_cls = p_req->update_tun_cls;
2340
2341 qed_iov_pf_update_tun_param(p_req, &tunn.vxlan, &tunn.vxlan_port,
2342 QED_MODE_VXLAN_TUNN, p_req->vxlan_clss,
2343 p_req->update_vxlan_port,
2344 p_req->vxlan_port);
2345 qed_iov_pf_update_tun_param(p_req, &tunn.l2_geneve, &tunn.geneve_port,
2346 QED_MODE_L2GENEVE_TUNN,
2347 p_req->l2geneve_clss,
2348 p_req->update_geneve_port,
2349 p_req->geneve_port);
2350 __qed_iov_pf_update_tun_param(p_req, &tunn.ip_geneve,
2351 QED_MODE_IPGENEVE_TUNN,
2352 p_req->ipgeneve_clss);
2353 __qed_iov_pf_update_tun_param(p_req, &tunn.l2_gre,
2354 QED_MODE_L2GRE_TUNN, p_req->l2gre_clss);
2355 __qed_iov_pf_update_tun_param(p_req, &tunn.ip_gre,
2356 QED_MODE_IPGRE_TUNN, p_req->ipgre_clss);
2357
2358 /* If PF modifies VF's req then it should
2359 * still return an error in case of partial configuration
2360 * or modified configuration as opposed to requested one.
2361 */
2362 rc = qed_pf_validate_modify_tunn_config(p_hwfn, &tunn_feature_mask,
2363 &b_update_required, &tunn);
2364
2365 if (rc)
2366 status = PFVF_STATUS_FAILURE;
2367
2368 /* If QED client is willing to update anything ? */
2369 if (b_update_required) {
2370 u16 geneve_port;
2371
Manish Chopra4f646752017-05-23 09:41:20 +03002372 rc = qed_sp_pf_update_tunn_cfg(p_hwfn, p_ptt, &tunn,
Chopra, Manisheaf3c0c2017-04-24 10:00:49 -07002373 QED_SPQ_MODE_EBLOCK, NULL);
2374 if (rc)
2375 status = PFVF_STATUS_FAILURE;
2376
2377 geneve_port = p_tun->geneve_port.port;
2378 qed_for_each_vf(p_hwfn, i) {
2379 qed_iov_bulletin_set_udp_ports(p_hwfn, i,
2380 p_tun->vxlan_port.port,
2381 geneve_port);
2382 }
2383 }
2384
2385send_resp:
2386 p_resp = qed_add_tlv(p_hwfn, &mbx->offset,
2387 CHANNEL_TLV_UPDATE_TUNN_PARAM, sizeof(*p_resp));
2388
2389 qed_iov_pf_update_tun_response(p_resp, p_tun, tunn_feature_mask);
2390 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2391 sizeof(struct channel_list_end_tlv));
2392
2393 qed_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
2394}
2395
Yuval Mintz5040acf2016-06-05 13:11:14 +03002396static void qed_iov_vf_mbx_start_txq_resp(struct qed_hwfn *p_hwfn,
2397 struct qed_ptt *p_ptt,
Mintz, Yuval007bc372017-06-04 13:31:05 +03002398 struct qed_vf_info *p_vf,
2399 u32 cid, u8 status)
Yuval Mintz5040acf2016-06-05 13:11:14 +03002400{
2401 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2402 struct pfvf_start_queue_resp_tlv *p_tlv;
Yuval Mintza044df82016-08-22 13:25:09 +03002403 bool b_legacy = false;
2404 u16 length;
Yuval Mintz5040acf2016-06-05 13:11:14 +03002405
2406 mbx->offset = (u8 *)mbx->reply_virt;
2407
Yuval Mintza044df82016-08-22 13:25:09 +03002408 /* Taking a bigger struct instead of adding a TLV to list was a
2409 * mistake, but one which we're now stuck with, as some older
2410 * clients assume the size of the previous response.
2411 */
2412 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2413 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2414 b_legacy = true;
2415
2416 if (!b_legacy)
2417 length = sizeof(*p_tlv);
2418 else
2419 length = sizeof(struct pfvf_def_resp_tlv);
2420
Yuval Mintz5040acf2016-06-05 13:11:14 +03002421 p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_TXQ,
Yuval Mintza044df82016-08-22 13:25:09 +03002422 length);
Yuval Mintz5040acf2016-06-05 13:11:14 +03002423 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2424 sizeof(struct channel_list_end_tlv));
2425
2426 /* Update the TLV with the response */
Mintz, Yuval007bc372017-06-04 13:31:05 +03002427 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy)
2428 p_tlv->offset = qed_db_addr_vf(cid, DQ_DEMS_LEGACY);
Yuval Mintz5040acf2016-06-05 13:11:14 +03002429
Yuval Mintza044df82016-08-22 13:25:09 +03002430 qed_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
Yuval Mintz5040acf2016-06-05 13:11:14 +03002431}
2432
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002433static void qed_iov_vf_mbx_start_txq(struct qed_hwfn *p_hwfn,
2434 struct qed_ptt *p_ptt,
2435 struct qed_vf_info *vf)
2436{
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002437 struct qed_queue_start_common_params params;
Mintz, Yuval39464972017-06-04 13:31:02 +03002438 struct qed_queue_cid_vf_params vf_params;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002439 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
Yuval Mintz41086462016-06-05 13:11:13 +03002440 u8 status = PFVF_STATUS_NO_RESOURCE;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002441 struct vfpf_start_txq_tlv *req;
Mintz, Yuval007bc372017-06-04 13:31:05 +03002442 struct qed_vf_queue *p_queue;
2443 struct qed_queue_cid *p_cid;
Mintz, Yuvalf604b172017-06-04 13:31:01 +03002444 struct qed_sb_info sb_dummy;
Mintz, Yuval3b19f472017-06-04 13:31:04 +03002445 u8 qid_usage_idx, vf_legacy;
Mintz, Yuval007bc372017-06-04 13:31:05 +03002446 u32 cid = 0;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002447 int rc;
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002448 u16 pq;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002449
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002450 memset(&params, 0, sizeof(params));
2451 req = &mbx->req_virt->start_txq;
Yuval Mintz41086462016-06-05 13:11:13 +03002452
Mintz, Yuvalf109c242017-03-19 13:08:16 +02002453 if (!qed_iov_validate_txq(p_hwfn, vf, req->tx_qid,
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002454 QED_IOV_VALIDATE_Q_NA) ||
Yuval Mintz41086462016-06-05 13:11:13 +03002455 !qed_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2456 goto out;
2457
Mintz, Yuvalbbe3f232017-06-04 13:31:03 +03002458 qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, true);
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002459 if (qid_usage_idx == QED_IOV_QID_INVALID)
2460 goto out;
2461
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002462 p_queue = &vf->vf_queues[req->tx_qid];
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002463 if (p_queue->cids[qid_usage_idx].p_cid)
2464 goto out;
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002465
Mintz, Yuval3b19f472017-06-04 13:31:04 +03002466 vf_legacy = qed_vf_calculate_legacy(vf);
Mintz, Yuval39464972017-06-04 13:31:02 +03002467
Mintz, Yuvalbbe3f232017-06-04 13:31:03 +03002468 /* Acquire a new queue-cid */
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002469 params.queue_id = p_queue->fw_tx_qid;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002470 params.vport_id = vf->vport_id;
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002471 params.stats_id = vf->abs_vf_id + 0x10;
Mintz, Yuvalf604b172017-06-04 13:31:01 +03002472
2473 /* Since IGU index is passed via sb_info, construct a dummy one */
2474 memset(&sb_dummy, 0, sizeof(sb_dummy));
2475 sb_dummy.igu_sb_id = req->hw_sb;
2476 params.p_sb = &sb_dummy;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002477 params.sb_idx = req->sb_index;
2478
Mintz, Yuval39464972017-06-04 13:31:02 +03002479 memset(&vf_params, 0, sizeof(vf_params));
2480 vf_params.vfid = vf->relative_vf_id;
2481 vf_params.vf_qid = (u8)req->tx_qid;
Mintz, Yuval3b19f472017-06-04 13:31:04 +03002482 vf_params.vf_legacy = vf_legacy;
Mintz, Yuvalbbe3f232017-06-04 13:31:03 +03002483 vf_params.qid_usage_idx = qid_usage_idx;
Mintz, Yuval39464972017-06-04 13:31:02 +03002484
Mintz, Yuval007bc372017-06-04 13:31:05 +03002485 p_cid = qed_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2486 &params, false, &vf_params);
2487 if (!p_cid)
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002488 goto out;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002489
Ariel Eliorb5a9ee72017-04-03 12:21:09 +03002490 pq = qed_get_cm_pq_idx_vf(p_hwfn, vf->relative_vf_id);
Mintz, Yuval007bc372017-06-04 13:31:05 +03002491 rc = qed_eth_txq_start_ramrod(p_hwfn, p_cid,
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002492 req->pbl_addr, req->pbl_size, pq);
Yuval Mintz41086462016-06-05 13:11:13 +03002493 if (rc) {
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002494 status = PFVF_STATUS_FAILURE;
Mintz, Yuval007bc372017-06-04 13:31:05 +03002495 qed_eth_queue_cid_release(p_hwfn, p_cid);
Yuval Mintz41086462016-06-05 13:11:13 +03002496 } else {
2497 status = PFVF_STATUS_SUCCESS;
Mintz, Yuval007bc372017-06-04 13:31:05 +03002498 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2499 p_queue->cids[qid_usage_idx].b_is_tx = true;
2500 cid = p_cid->cid;
Yuval Mintz41086462016-06-05 13:11:13 +03002501 }
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002502
Yuval Mintz41086462016-06-05 13:11:13 +03002503out:
Mintz, Yuval007bc372017-06-04 13:31:05 +03002504 qed_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf, cid, status);
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002505}
2506
2507static int qed_iov_vf_stop_rxqs(struct qed_hwfn *p_hwfn,
2508 struct qed_vf_info *vf,
Mintz, Yuval007bc372017-06-04 13:31:05 +03002509 u16 rxq_id,
2510 u8 qid_usage_idx, bool cqe_completion)
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002511{
Mintz, Yuval007bc372017-06-04 13:31:05 +03002512 struct qed_vf_queue *p_queue;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002513 int rc = 0;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002514
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002515 if (!qed_iov_validate_rxq(p_hwfn, vf, rxq_id, QED_IOV_VALIDATE_Q_NA)) {
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002516 DP_VERBOSE(p_hwfn,
2517 QED_MSG_IOV,
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002518 "VF[%d] Tried Closing Rx 0x%04x.%02x which is inactive\n",
2519 vf->relative_vf_id, rxq_id, qid_usage_idx);
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002520 return -EINVAL;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002521 }
2522
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002523 p_queue = &vf->vf_queues[rxq_id];
2524
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002525 /* We've validated the index and the existence of the active RXQ -
2526 * now we need to make sure that it's using the correct qid.
2527 */
2528 if (!p_queue->cids[qid_usage_idx].p_cid ||
2529 p_queue->cids[qid_usage_idx].b_is_tx) {
2530 struct qed_queue_cid *p_cid;
2531
2532 p_cid = qed_iov_get_vf_rx_queue_cid(p_queue);
2533 DP_VERBOSE(p_hwfn,
2534 QED_MSG_IOV,
2535 "VF[%d] - Tried Closing Rx 0x%04x.%02x, but Rx is at %04x.%02x\n",
2536 vf->relative_vf_id,
2537 rxq_id, qid_usage_idx, rxq_id, p_cid->qid_usage_idx);
2538 return -EINVAL;
2539 }
2540
2541 /* Now that we know we have a valid Rx-queue - close it */
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002542 rc = qed_eth_rx_queue_stop(p_hwfn,
Mintz, Yuval007bc372017-06-04 13:31:05 +03002543 p_queue->cids[qid_usage_idx].p_cid,
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002544 false, cqe_completion);
2545 if (rc)
2546 return rc;
2547
Mintz, Yuval007bc372017-06-04 13:31:05 +03002548 p_queue->cids[qid_usage_idx].p_cid = NULL;
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002549 vf->num_active_rxqs--;
2550
2551 return 0;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002552}
2553
2554static int qed_iov_vf_stop_txqs(struct qed_hwfn *p_hwfn,
Mintz, Yuval007bc372017-06-04 13:31:05 +03002555 struct qed_vf_info *vf,
2556 u16 txq_id, u8 qid_usage_idx)
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002557{
Mintz, Yuval007bc372017-06-04 13:31:05 +03002558 struct qed_vf_queue *p_queue;
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002559 int rc = 0;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002560
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002561 if (!qed_iov_validate_txq(p_hwfn, vf, txq_id, QED_IOV_VALIDATE_Q_NA))
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002562 return -EINVAL;
2563
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002564 p_queue = &vf->vf_queues[txq_id];
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002565 if (!p_queue->cids[qid_usage_idx].p_cid ||
2566 !p_queue->cids[qid_usage_idx].b_is_tx)
2567 return -EINVAL;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002568
Mintz, Yuval007bc372017-06-04 13:31:05 +03002569 rc = qed_eth_tx_queue_stop(p_hwfn, p_queue->cids[qid_usage_idx].p_cid);
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002570 if (rc)
2571 return rc;
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002572
Mintz, Yuval007bc372017-06-04 13:31:05 +03002573 p_queue->cids[qid_usage_idx].p_cid = NULL;
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002574 return 0;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002575}
2576
2577static void qed_iov_vf_mbx_stop_rxqs(struct qed_hwfn *p_hwfn,
2578 struct qed_ptt *p_ptt,
2579 struct qed_vf_info *vf)
2580{
2581 u16 length = sizeof(struct pfvf_def_resp_tlv);
2582 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002583 u8 status = PFVF_STATUS_FAILURE;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002584 struct vfpf_stop_rxqs_tlv *req;
Mintz, Yuval007bc372017-06-04 13:31:05 +03002585 u8 qid_usage_idx;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002586 int rc;
2587
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002588 /* There has never been an official driver that used this interface
2589 * for stopping multiple queues, and it is now considered deprecated.
2590 * Validate this isn't used here.
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002591 */
2592 req = &mbx->req_virt->stop_rxqs;
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002593 if (req->num_rxqs != 1) {
2594 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2595 "Odd; VF[%d] tried stopping multiple Rx queues\n",
2596 vf->relative_vf_id);
2597 status = PFVF_STATUS_NOT_SUPPORTED;
2598 goto out;
2599 }
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002600
Mintz, Yuval007bc372017-06-04 13:31:05 +03002601 /* Find which qid-index is associated with the queue */
2602 qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, false);
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002603 if (qid_usage_idx == QED_IOV_QID_INVALID)
2604 goto out;
Mintz, Yuval007bc372017-06-04 13:31:05 +03002605
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002606 rc = qed_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
Mintz, Yuval007bc372017-06-04 13:31:05 +03002607 qid_usage_idx, req->cqe_completion);
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002608 if (!rc)
2609 status = PFVF_STATUS_SUCCESS;
2610out:
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002611 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
2612 length, status);
2613}
2614
2615static void qed_iov_vf_mbx_stop_txqs(struct qed_hwfn *p_hwfn,
2616 struct qed_ptt *p_ptt,
2617 struct qed_vf_info *vf)
2618{
2619 u16 length = sizeof(struct pfvf_def_resp_tlv);
2620 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002621 u8 status = PFVF_STATUS_FAILURE;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002622 struct vfpf_stop_txqs_tlv *req;
Mintz, Yuval007bc372017-06-04 13:31:05 +03002623 u8 qid_usage_idx;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002624 int rc;
2625
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002626 /* There has never been an official driver that used this interface
2627 * for stopping multiple queues, and it is now considered deprecated.
2628 * Validate this isn't used here.
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002629 */
2630 req = &mbx->req_virt->stop_txqs;
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002631 if (req->num_txqs != 1) {
2632 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2633 "Odd; VF[%d] tried stopping multiple Tx queues\n",
2634 vf->relative_vf_id);
2635 status = PFVF_STATUS_NOT_SUPPORTED;
2636 goto out;
2637 }
Mintz, Yuval007bc372017-06-04 13:31:05 +03002638
2639 /* Find which qid-index is associated with the queue */
2640 qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, true);
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002641 if (qid_usage_idx == QED_IOV_QID_INVALID)
2642 goto out;
Mintz, Yuval007bc372017-06-04 13:31:05 +03002643
2644 rc = qed_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid, qid_usage_idx);
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002645 if (!rc)
2646 status = PFVF_STATUS_SUCCESS;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002647
Mintz, Yuval4c4fa792017-03-19 13:08:17 +02002648out:
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002649 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
2650 length, status);
2651}
2652
Yuval Mintz17b235c2016-05-11 16:36:18 +03002653static void qed_iov_vf_mbx_update_rxqs(struct qed_hwfn *p_hwfn,
2654 struct qed_ptt *p_ptt,
2655 struct qed_vf_info *vf)
2656{
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002657 struct qed_queue_cid *handlers[QED_MAX_VF_CHAINS_PER_PF];
Yuval Mintz17b235c2016-05-11 16:36:18 +03002658 u16 length = sizeof(struct pfvf_def_resp_tlv);
2659 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2660 struct vfpf_update_rxq_tlv *req;
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002661 u8 status = PFVF_STATUS_FAILURE;
Yuval Mintz17b235c2016-05-11 16:36:18 +03002662 u8 complete_event_flg;
2663 u8 complete_cqe_flg;
Mintz, Yuval007bc372017-06-04 13:31:05 +03002664 u8 qid_usage_idx;
Yuval Mintz17b235c2016-05-11 16:36:18 +03002665 int rc;
2666 u8 i;
2667
2668 req = &mbx->req_virt->update_rxq;
2669 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
2670 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
2671
Mintz, Yuval007bc372017-06-04 13:31:05 +03002672 qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, false);
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002673 if (qid_usage_idx == QED_IOV_QID_INVALID)
2674 goto out;
Mintz, Yuval007bc372017-06-04 13:31:05 +03002675
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002676 /* There shouldn't exist a VF that uses queue-qids yet uses this
2677 * API with multiple Rx queues. Validate this.
2678 */
2679 if ((vf->acquire.vfdev_info.capabilities &
2680 VFPF_ACQUIRE_CAP_QUEUE_QIDS) && req->num_rxqs != 1) {
2681 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2682 "VF[%d] supports QIDs but sends multiple queues\n",
2683 vf->relative_vf_id);
2684 goto out;
2685 }
2686
2687 /* Validate inputs - for the legacy case this is still true since
2688 * qid_usage_idx for each Rx queue would be LEGACY_QID_RX.
2689 */
2690 for (i = req->rx_qid; i < req->rx_qid + req->num_rxqs; i++) {
Mintz, Yuvalf109c242017-03-19 13:08:16 +02002691 if (!qed_iov_validate_rxq(p_hwfn, vf, i,
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002692 QED_IOV_VALIDATE_Q_NA) ||
2693 !vf->vf_queues[i].cids[qid_usage_idx].p_cid ||
2694 vf->vf_queues[i].cids[qid_usage_idx].b_is_tx) {
2695 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2696 "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2697 vf->relative_vf_id, req->rx_qid,
2698 req->num_rxqs);
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002699 goto out;
2700 }
Mintz, Yuval08bc8f12017-06-04 13:31:06 +03002701 }
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002702
Mintz, Yuvalf109c242017-03-19 13:08:16 +02002703 /* Prepare the handlers */
2704 for (i = 0; i < req->num_rxqs; i++) {
Mintz, Yuval007bc372017-06-04 13:31:05 +03002705 u16 qid = req->rx_qid + i;
2706
2707 handlers[i] = vf->vf_queues[qid].cids[qid_usage_idx].p_cid;
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002708 }
2709
2710 rc = qed_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
2711 req->num_rxqs,
2712 complete_cqe_flg,
2713 complete_event_flg,
2714 QED_SPQ_MODE_EBLOCK, NULL);
2715 if (rc)
2716 goto out;
2717
2718 status = PFVF_STATUS_SUCCESS;
2719out:
Yuval Mintz17b235c2016-05-11 16:36:18 +03002720 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
2721 length, status);
2722}
2723
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002724void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
2725 void *p_tlvs_list, u16 req_type)
2726{
2727 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
2728 int len = 0;
2729
2730 do {
2731 if (!p_tlv->length) {
2732 DP_NOTICE(p_hwfn, "Zero length TLV found\n");
2733 return NULL;
2734 }
2735
2736 if (p_tlv->type == req_type) {
2737 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2738 "Extended tlv type %d, length %d found\n",
2739 p_tlv->type, p_tlv->length);
2740 return p_tlv;
2741 }
2742
2743 len += p_tlv->length;
2744 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
2745
2746 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
2747 DP_NOTICE(p_hwfn, "TLVs has overrun the buffer size\n");
2748 return NULL;
2749 }
2750 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2751
2752 return NULL;
2753}
2754
2755static void
2756qed_iov_vp_update_act_param(struct qed_hwfn *p_hwfn,
2757 struct qed_sp_vport_update_params *p_data,
2758 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2759{
2760 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2761 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2762
2763 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2764 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2765 if (!p_act_tlv)
2766 return;
2767
2768 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2769 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2770 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
2771 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
2772 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACTIVATE;
2773}
2774
2775static void
Yuval Mintz17b235c2016-05-11 16:36:18 +03002776qed_iov_vp_update_vlan_param(struct qed_hwfn *p_hwfn,
2777 struct qed_sp_vport_update_params *p_data,
2778 struct qed_vf_info *p_vf,
2779 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2780{
2781 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
2782 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
2783
2784 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
2785 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2786 if (!p_vlan_tlv)
2787 return;
2788
Yuval Mintz08feecd2016-05-11 16:36:20 +03002789 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
2790
2791 /* Ignore the VF request if we're forcing a vlan */
Yuval Mintz1a635e42016-08-15 10:42:43 +03002792 if (!(p_vf->configured_features & BIT(VLAN_ADDR_FORCED))) {
Yuval Mintz08feecd2016-05-11 16:36:20 +03002793 p_data->update_inner_vlan_removal_flg = 1;
2794 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
2795 }
Yuval Mintz17b235c2016-05-11 16:36:18 +03002796
2797 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_VLAN_STRIP;
2798}
2799
2800static void
2801qed_iov_vp_update_tx_switch(struct qed_hwfn *p_hwfn,
2802 struct qed_sp_vport_update_params *p_data,
2803 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2804{
2805 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
2806 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
2807
2808 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
2809 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2810 tlv);
2811 if (!p_tx_switch_tlv)
2812 return;
2813
2814 p_data->update_tx_switching_flg = 1;
2815 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
2816 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_TX_SWITCH;
2817}
2818
2819static void
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002820qed_iov_vp_update_mcast_bin_param(struct qed_hwfn *p_hwfn,
2821 struct qed_sp_vport_update_params *p_data,
2822 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2823{
2824 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
2825 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
2826
2827 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
2828 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2829 if (!p_mcast_tlv)
2830 return;
2831
2832 p_data->update_approx_mcast_flg = 1;
2833 memcpy(p_data->bins, p_mcast_tlv->bins,
2834 sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS);
2835 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_MCAST;
2836}
2837
2838static void
2839qed_iov_vp_update_accept_flag(struct qed_hwfn *p_hwfn,
2840 struct qed_sp_vport_update_params *p_data,
2841 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2842{
2843 struct qed_filter_accept_flags *p_flags = &p_data->accept_flags;
2844 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
2845 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
2846
2847 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
2848 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2849 if (!p_accept_tlv)
2850 return;
2851
2852 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
2853 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
2854 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
2855 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
2856 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_PARAM;
2857}
2858
2859static void
Yuval Mintz17b235c2016-05-11 16:36:18 +03002860qed_iov_vp_update_accept_any_vlan(struct qed_hwfn *p_hwfn,
2861 struct qed_sp_vport_update_params *p_data,
2862 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2863{
2864 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
2865 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
2866
2867 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
2868 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2869 tlv);
2870 if (!p_accept_any_vlan)
2871 return;
2872
2873 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
2874 p_data->update_accept_any_vlan_flg =
2875 p_accept_any_vlan->update_accept_any_vlan_flg;
2876 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
2877}
2878
2879static void
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002880qed_iov_vp_update_rss_param(struct qed_hwfn *p_hwfn,
2881 struct qed_vf_info *vf,
2882 struct qed_sp_vport_update_params *p_data,
2883 struct qed_rss_params *p_rss,
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02002884 struct qed_iov_vf_mbx *p_mbx,
2885 u16 *tlvs_mask, u16 *tlvs_accepted)
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002886{
2887 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
2888 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02002889 bool b_reject = false;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002890 u16 table_size;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02002891 u16 i, q_idx;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002892
2893 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
2894 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2895 if (!p_rss_tlv) {
2896 p_data->rss_params = NULL;
2897 return;
2898 }
2899
2900 memset(p_rss, 0, sizeof(struct qed_rss_params));
2901
2902 p_rss->update_rss_config = !!(p_rss_tlv->update_rss_flags &
2903 VFPF_UPDATE_RSS_CONFIG_FLAG);
2904 p_rss->update_rss_capabilities = !!(p_rss_tlv->update_rss_flags &
2905 VFPF_UPDATE_RSS_CAPS_FLAG);
2906 p_rss->update_rss_ind_table = !!(p_rss_tlv->update_rss_flags &
2907 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
2908 p_rss->update_rss_key = !!(p_rss_tlv->update_rss_flags &
2909 VFPF_UPDATE_RSS_KEY_FLAG);
2910
2911 p_rss->rss_enable = p_rss_tlv->rss_enable;
2912 p_rss->rss_eng_id = vf->relative_vf_id + 1;
2913 p_rss->rss_caps = p_rss_tlv->rss_caps;
2914 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002915 memcpy(p_rss->rss_key, p_rss_tlv->rss_key, sizeof(p_rss->rss_key));
2916
2917 table_size = min_t(u16, ARRAY_SIZE(p_rss->rss_ind_table),
2918 (1 << p_rss_tlv->rss_table_size_log));
2919
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002920 for (i = 0; i < table_size; i++) {
Mintz, Yuval007bc372017-06-04 13:31:05 +03002921 struct qed_queue_cid *p_cid;
2922
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02002923 q_idx = p_rss_tlv->rss_ind_table[i];
Mintz, Yuvalf109c242017-03-19 13:08:16 +02002924 if (!qed_iov_validate_rxq(p_hwfn, vf, q_idx,
2925 QED_IOV_VALIDATE_Q_ENABLE)) {
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02002926 DP_VERBOSE(p_hwfn,
2927 QED_MSG_IOV,
2928 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
2929 vf->relative_vf_id, q_idx);
2930 b_reject = true;
2931 goto out;
2932 }
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002933
Mintz, Yuval007bc372017-06-04 13:31:05 +03002934 p_cid = qed_iov_get_vf_rx_queue_cid(&vf->vf_queues[q_idx]);
2935 p_rss->rss_ind_table[i] = p_cid;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002936 }
2937
2938 p_data->rss_params = p_rss;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02002939out:
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002940 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_RSS;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02002941 if (!b_reject)
2942 *tlvs_accepted |= 1 << QED_IOV_VP_UPDATE_RSS;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03002943}
2944
Yuval Mintz17b235c2016-05-11 16:36:18 +03002945static void
2946qed_iov_vp_update_sge_tpa_param(struct qed_hwfn *p_hwfn,
2947 struct qed_vf_info *vf,
2948 struct qed_sp_vport_update_params *p_data,
2949 struct qed_sge_tpa_params *p_sge_tpa,
2950 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2951{
2952 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
2953 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
2954
2955 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
2956 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2957
2958 if (!p_sge_tpa_tlv) {
2959 p_data->sge_tpa_params = NULL;
2960 return;
2961 }
2962
2963 memset(p_sge_tpa, 0, sizeof(struct qed_sge_tpa_params));
2964
2965 p_sge_tpa->update_tpa_en_flg =
2966 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
2967 p_sge_tpa->update_tpa_param_flg =
2968 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
2969 VFPF_UPDATE_TPA_PARAM_FLAG);
2970
2971 p_sge_tpa->tpa_ipv4_en_flg =
2972 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
2973 p_sge_tpa->tpa_ipv6_en_flg =
2974 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
2975 p_sge_tpa->tpa_pkt_split_flg =
2976 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
2977 p_sge_tpa->tpa_hdr_data_split_flg =
2978 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
2979 p_sge_tpa->tpa_gro_consistent_flg =
2980 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
2981
2982 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
2983 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
2984 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
2985 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
2986 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
2987
2988 p_data->sge_tpa_params = p_sge_tpa;
2989
2990 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_SGE_TPA;
2991}
2992
Mintz, Yuvalf990c822017-01-01 13:57:08 +02002993static int qed_iov_pre_update_vport(struct qed_hwfn *hwfn,
2994 u8 vfid,
2995 struct qed_sp_vport_update_params *params,
2996 u16 *tlvs)
2997{
2998 u8 mask = QED_ACCEPT_UCAST_UNMATCHED | QED_ACCEPT_MCAST_UNMATCHED;
2999 struct qed_filter_accept_flags *flags = &params->accept_flags;
3000 struct qed_public_vf_info *vf_info;
3001
3002 /* Untrusted VFs can't even be trusted to know that fact.
3003 * Simply indicate everything is configured fine, and trace
3004 * configuration 'behind their back'.
3005 */
3006 if (!(*tlvs & BIT(QED_IOV_VP_UPDATE_ACCEPT_PARAM)))
3007 return 0;
3008
3009 vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
3010
3011 if (flags->update_rx_mode_config) {
3012 vf_info->rx_accept_mode = flags->rx_accept_filter;
3013 if (!vf_info->is_trusted_configured)
3014 flags->rx_accept_filter &= ~mask;
3015 }
3016
3017 if (flags->update_tx_mode_config) {
3018 vf_info->tx_accept_mode = flags->tx_accept_filter;
3019 if (!vf_info->is_trusted_configured)
3020 flags->tx_accept_filter &= ~mask;
3021 }
3022
3023 return 0;
3024}
3025
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003026static void qed_iov_vf_mbx_vport_update(struct qed_hwfn *p_hwfn,
3027 struct qed_ptt *p_ptt,
3028 struct qed_vf_info *vf)
3029{
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02003030 struct qed_rss_params *p_rss_params = NULL;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003031 struct qed_sp_vport_update_params params;
3032 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
Yuval Mintz17b235c2016-05-11 16:36:18 +03003033 struct qed_sge_tpa_params sge_tpa_params;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02003034 u16 tlvs_mask = 0, tlvs_accepted = 0;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003035 u8 status = PFVF_STATUS_SUCCESS;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003036 u16 length;
3037 int rc;
3038
Yuval Mintz41086462016-06-05 13:11:13 +03003039 /* Valiate PF can send such a request */
3040 if (!vf->vport_instance) {
3041 DP_VERBOSE(p_hwfn,
3042 QED_MSG_IOV,
3043 "No VPORT instance available for VF[%d], failing vport update\n",
3044 vf->abs_vf_id);
3045 status = PFVF_STATUS_FAILURE;
3046 goto out;
3047 }
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02003048 p_rss_params = vzalloc(sizeof(*p_rss_params));
3049 if (p_rss_params == NULL) {
3050 status = PFVF_STATUS_FAILURE;
3051 goto out;
3052 }
Yuval Mintz41086462016-06-05 13:11:13 +03003053
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003054 memset(&params, 0, sizeof(params));
3055 params.opaque_fid = vf->opaque_fid;
3056 params.vport_id = vf->vport_id;
3057 params.rss_params = NULL;
3058
3059 /* Search for extended tlvs list and update values
3060 * from VF in struct qed_sp_vport_update_params.
3061 */
3062 qed_iov_vp_update_act_param(p_hwfn, &params, mbx, &tlvs_mask);
Yuval Mintz17b235c2016-05-11 16:36:18 +03003063 qed_iov_vp_update_vlan_param(p_hwfn, &params, vf, mbx, &tlvs_mask);
3064 qed_iov_vp_update_tx_switch(p_hwfn, &params, mbx, &tlvs_mask);
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003065 qed_iov_vp_update_mcast_bin_param(p_hwfn, &params, mbx, &tlvs_mask);
3066 qed_iov_vp_update_accept_flag(p_hwfn, &params, mbx, &tlvs_mask);
Yuval Mintz17b235c2016-05-11 16:36:18 +03003067 qed_iov_vp_update_accept_any_vlan(p_hwfn, &params, mbx, &tlvs_mask);
3068 qed_iov_vp_update_sge_tpa_param(p_hwfn, vf, &params,
3069 &sge_tpa_params, mbx, &tlvs_mask);
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003070
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02003071 tlvs_accepted = tlvs_mask;
3072
3073 /* Some of the extended TLVs need to be validated first; In that case,
3074 * they can update the mask without updating the accepted [so that
3075 * PF could communicate to VF it has rejected request].
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003076 */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02003077 qed_iov_vp_update_rss_param(p_hwfn, vf, &params, p_rss_params,
3078 mbx, &tlvs_mask, &tlvs_accepted);
3079
Mintz, Yuvalf990c822017-01-01 13:57:08 +02003080 if (qed_iov_pre_update_vport(p_hwfn, vf->relative_vf_id,
3081 &params, &tlvs_accepted)) {
3082 tlvs_accepted = 0;
3083 status = PFVF_STATUS_NOT_SUPPORTED;
3084 goto out;
3085 }
3086
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02003087 if (!tlvs_accepted) {
3088 if (tlvs_mask)
3089 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3090 "Upper-layer prevents VF vport configuration\n");
3091 else
3092 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3093 "No feature tlvs found for vport update\n");
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003094 status = PFVF_STATUS_NOT_SUPPORTED;
3095 goto out;
3096 }
3097
3098 rc = qed_sp_vport_update(p_hwfn, &params, QED_SPQ_MODE_EBLOCK, NULL);
3099
3100 if (rc)
3101 status = PFVF_STATUS_FAILURE;
3102
3103out:
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02003104 vfree(p_rss_params);
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003105 length = qed_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02003106 tlvs_mask, tlvs_accepted);
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003107 qed_iov_send_response(p_hwfn, p_ptt, vf, length, status);
3108}
3109
Yuval Mintz8246d0b2016-06-05 13:11:15 +03003110static int qed_iov_vf_update_vlan_shadow(struct qed_hwfn *p_hwfn,
3111 struct qed_vf_info *p_vf,
3112 struct qed_filter_ucast *p_params)
Yuval Mintz08feecd2016-05-11 16:36:20 +03003113{
3114 int i;
3115
Yuval Mintz08feecd2016-05-11 16:36:20 +03003116 /* First remove entries and then add new ones */
3117 if (p_params->opcode == QED_FILTER_REMOVE) {
3118 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3119 if (p_vf->shadow_config.vlans[i].used &&
3120 p_vf->shadow_config.vlans[i].vid ==
3121 p_params->vlan) {
3122 p_vf->shadow_config.vlans[i].used = false;
3123 break;
3124 }
3125 if (i == QED_ETH_VF_NUM_VLAN_FILTERS + 1) {
3126 DP_VERBOSE(p_hwfn,
3127 QED_MSG_IOV,
3128 "VF [%d] - Tries to remove a non-existing vlan\n",
3129 p_vf->relative_vf_id);
3130 return -EINVAL;
3131 }
3132 } else if (p_params->opcode == QED_FILTER_REPLACE ||
3133 p_params->opcode == QED_FILTER_FLUSH) {
3134 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3135 p_vf->shadow_config.vlans[i].used = false;
3136 }
3137
3138 /* In forced mode, we're willing to remove entries - but we don't add
3139 * new ones.
3140 */
Yuval Mintz1a635e42016-08-15 10:42:43 +03003141 if (p_vf->bulletin.p_virt->valid_bitmap & BIT(VLAN_ADDR_FORCED))
Yuval Mintz08feecd2016-05-11 16:36:20 +03003142 return 0;
3143
3144 if (p_params->opcode == QED_FILTER_ADD ||
3145 p_params->opcode == QED_FILTER_REPLACE) {
3146 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
3147 if (p_vf->shadow_config.vlans[i].used)
3148 continue;
3149
3150 p_vf->shadow_config.vlans[i].used = true;
3151 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
3152 break;
3153 }
3154
3155 if (i == QED_ETH_VF_NUM_VLAN_FILTERS + 1) {
3156 DP_VERBOSE(p_hwfn,
3157 QED_MSG_IOV,
3158 "VF [%d] - Tries to configure more than %d vlan filters\n",
3159 p_vf->relative_vf_id,
3160 QED_ETH_VF_NUM_VLAN_FILTERS + 1);
3161 return -EINVAL;
3162 }
3163 }
3164
3165 return 0;
3166}
3167
Yuval Mintz8246d0b2016-06-05 13:11:15 +03003168static int qed_iov_vf_update_mac_shadow(struct qed_hwfn *p_hwfn,
3169 struct qed_vf_info *p_vf,
3170 struct qed_filter_ucast *p_params)
3171{
3172 int i;
3173
3174 /* If we're in forced-mode, we don't allow any change */
Yuval Mintz1a635e42016-08-15 10:42:43 +03003175 if (p_vf->bulletin.p_virt->valid_bitmap & BIT(MAC_ADDR_FORCED))
Yuval Mintz8246d0b2016-06-05 13:11:15 +03003176 return 0;
3177
Shahed Shaikh7425d822018-04-19 05:50:11 -07003178 /* Don't keep track of shadow copy since we don't intend to restore. */
3179 if (p_vf->p_vf_info.is_trusted_configured)
3180 return 0;
3181
Yuval Mintz8246d0b2016-06-05 13:11:15 +03003182 /* First remove entries and then add new ones */
3183 if (p_params->opcode == QED_FILTER_REMOVE) {
3184 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++) {
3185 if (ether_addr_equal(p_vf->shadow_config.macs[i],
3186 p_params->mac)) {
Shyam Saini0ee28e32017-01-17 07:35:04 +05303187 eth_zero_addr(p_vf->shadow_config.macs[i]);
Yuval Mintz8246d0b2016-06-05 13:11:15 +03003188 break;
3189 }
3190 }
3191
3192 if (i == QED_ETH_VF_NUM_MAC_FILTERS) {
3193 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3194 "MAC isn't configured\n");
3195 return -EINVAL;
3196 }
3197 } else if (p_params->opcode == QED_FILTER_REPLACE ||
3198 p_params->opcode == QED_FILTER_FLUSH) {
3199 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++)
Shyam Saini0ee28e32017-01-17 07:35:04 +05303200 eth_zero_addr(p_vf->shadow_config.macs[i]);
Yuval Mintz8246d0b2016-06-05 13:11:15 +03003201 }
3202
3203 /* List the new MAC address */
3204 if (p_params->opcode != QED_FILTER_ADD &&
3205 p_params->opcode != QED_FILTER_REPLACE)
3206 return 0;
3207
3208 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++) {
3209 if (is_zero_ether_addr(p_vf->shadow_config.macs[i])) {
3210 ether_addr_copy(p_vf->shadow_config.macs[i],
3211 p_params->mac);
3212 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3213 "Added MAC at %d entry in shadow\n", i);
3214 break;
3215 }
3216 }
3217
3218 if (i == QED_ETH_VF_NUM_MAC_FILTERS) {
3219 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "No available place for MAC\n");
3220 return -EINVAL;
3221 }
3222
3223 return 0;
3224}
3225
3226static int
3227qed_iov_vf_update_unicast_shadow(struct qed_hwfn *p_hwfn,
3228 struct qed_vf_info *p_vf,
3229 struct qed_filter_ucast *p_params)
3230{
3231 int rc = 0;
3232
3233 if (p_params->type == QED_FILTER_MAC) {
3234 rc = qed_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
3235 if (rc)
3236 return rc;
3237 }
3238
3239 if (p_params->type == QED_FILTER_VLAN)
3240 rc = qed_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
3241
3242 return rc;
3243}
3244
Baoyou Xieba569472016-09-09 09:21:15 +08003245static int qed_iov_chk_ucast(struct qed_hwfn *hwfn,
3246 int vfid, struct qed_filter_ucast *params)
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003247{
3248 struct qed_public_vf_info *vf;
3249
3250 vf = qed_iov_get_public_vf_info(hwfn, vfid, true);
3251 if (!vf)
3252 return -EINVAL;
3253
3254 /* No real decision to make; Store the configured MAC */
3255 if (params->type == QED_FILTER_MAC ||
Shahed Shaikh7425d822018-04-19 05:50:11 -07003256 params->type == QED_FILTER_MAC_VLAN) {
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003257 ether_addr_copy(vf->mac, params->mac);
3258
Shahed Shaikh7425d822018-04-19 05:50:11 -07003259 if (vf->is_trusted_configured) {
3260 qed_iov_bulletin_set_mac(hwfn, vf->mac, vfid);
3261
3262 /* Update and post bulleitin again */
3263 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
3264 }
3265 }
3266
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003267 return 0;
3268}
3269
3270static void qed_iov_vf_mbx_ucast_filter(struct qed_hwfn *p_hwfn,
3271 struct qed_ptt *p_ptt,
3272 struct qed_vf_info *vf)
3273{
Yuval Mintz08feecd2016-05-11 16:36:20 +03003274 struct qed_bulletin_content *p_bulletin = vf->bulletin.p_virt;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003275 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
3276 struct vfpf_ucast_filter_tlv *req;
3277 u8 status = PFVF_STATUS_SUCCESS;
3278 struct qed_filter_ucast params;
3279 int rc;
3280
3281 /* Prepare the unicast filter params */
3282 memset(&params, 0, sizeof(struct qed_filter_ucast));
3283 req = &mbx->req_virt->ucast_filter;
3284 params.opcode = (enum qed_filter_opcode)req->opcode;
3285 params.type = (enum qed_filter_ucast_type)req->type;
3286
3287 params.is_rx_filter = 1;
3288 params.is_tx_filter = 1;
3289 params.vport_to_remove_from = vf->vport_id;
3290 params.vport_to_add_to = vf->vport_id;
3291 memcpy(params.mac, req->mac, ETH_ALEN);
3292 params.vlan = req->vlan;
3293
3294 DP_VERBOSE(p_hwfn,
3295 QED_MSG_IOV,
3296 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x] MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
3297 vf->abs_vf_id, params.opcode, params.type,
3298 params.is_rx_filter ? "RX" : "",
3299 params.is_tx_filter ? "TX" : "",
3300 params.vport_to_add_to,
3301 params.mac[0], params.mac[1],
3302 params.mac[2], params.mac[3],
3303 params.mac[4], params.mac[5], params.vlan);
3304
3305 if (!vf->vport_instance) {
3306 DP_VERBOSE(p_hwfn,
3307 QED_MSG_IOV,
3308 "No VPORT instance available for VF[%d], failing ucast MAC configuration\n",
3309 vf->abs_vf_id);
3310 status = PFVF_STATUS_FAILURE;
3311 goto out;
3312 }
3313
Yuval Mintz08feecd2016-05-11 16:36:20 +03003314 /* Update shadow copy of the VF configuration */
3315 if (qed_iov_vf_update_unicast_shadow(p_hwfn, vf, &params)) {
3316 status = PFVF_STATUS_FAILURE;
3317 goto out;
3318 }
3319
3320 /* Determine if the unicast filtering is acceptible by PF */
Yuval Mintz1a635e42016-08-15 10:42:43 +03003321 if ((p_bulletin->valid_bitmap & BIT(VLAN_ADDR_FORCED)) &&
Yuval Mintz08feecd2016-05-11 16:36:20 +03003322 (params.type == QED_FILTER_VLAN ||
3323 params.type == QED_FILTER_MAC_VLAN)) {
3324 /* Once VLAN is forced or PVID is set, do not allow
3325 * to add/replace any further VLANs.
3326 */
3327 if (params.opcode == QED_FILTER_ADD ||
3328 params.opcode == QED_FILTER_REPLACE)
3329 status = PFVF_STATUS_FORCED;
3330 goto out;
3331 }
3332
Yuval Mintz1a635e42016-08-15 10:42:43 +03003333 if ((p_bulletin->valid_bitmap & BIT(MAC_ADDR_FORCED)) &&
Yuval Mintzeff16962016-05-11 16:36:21 +03003334 (params.type == QED_FILTER_MAC ||
3335 params.type == QED_FILTER_MAC_VLAN)) {
3336 if (!ether_addr_equal(p_bulletin->mac, params.mac) ||
3337 (params.opcode != QED_FILTER_ADD &&
3338 params.opcode != QED_FILTER_REPLACE))
3339 status = PFVF_STATUS_FORCED;
3340 goto out;
3341 }
3342
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003343 rc = qed_iov_chk_ucast(p_hwfn, vf->relative_vf_id, &params);
3344 if (rc) {
3345 status = PFVF_STATUS_FAILURE;
3346 goto out;
3347 }
3348
3349 rc = qed_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, &params,
3350 QED_SPQ_MODE_CB, NULL);
3351 if (rc)
3352 status = PFVF_STATUS_FAILURE;
3353
3354out:
3355 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
3356 sizeof(struct pfvf_def_resp_tlv), status);
3357}
3358
Yuval Mintz0b55e272016-05-11 16:36:15 +03003359static void qed_iov_vf_mbx_int_cleanup(struct qed_hwfn *p_hwfn,
3360 struct qed_ptt *p_ptt,
3361 struct qed_vf_info *vf)
3362{
3363 int i;
3364
3365 /* Reset the SBs */
3366 for (i = 0; i < vf->num_sbs; i++)
3367 qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
3368 vf->igu_sbs[i],
3369 vf->opaque_fid, false);
3370
3371 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
3372 sizeof(struct pfvf_def_resp_tlv),
3373 PFVF_STATUS_SUCCESS);
3374}
3375
3376static void qed_iov_vf_mbx_close(struct qed_hwfn *p_hwfn,
3377 struct qed_ptt *p_ptt, struct qed_vf_info *vf)
3378{
3379 u16 length = sizeof(struct pfvf_def_resp_tlv);
3380 u8 status = PFVF_STATUS_SUCCESS;
3381
3382 /* Disable Interrupts for VF */
3383 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
3384
3385 /* Reset Permission table */
3386 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
3387
3388 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
3389 length, status);
3390}
3391
3392static void qed_iov_vf_mbx_release(struct qed_hwfn *p_hwfn,
3393 struct qed_ptt *p_ptt,
3394 struct qed_vf_info *p_vf)
3395{
3396 u16 length = sizeof(struct pfvf_def_resp_tlv);
Yuval Mintz1fe614d2016-06-05 13:11:11 +03003397 u8 status = PFVF_STATUS_SUCCESS;
3398 int rc = 0;
Yuval Mintz0b55e272016-05-11 16:36:15 +03003399
3400 qed_iov_vf_cleanup(p_hwfn, p_vf);
3401
Yuval Mintz1fe614d2016-06-05 13:11:11 +03003402 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
3403 /* Stopping the VF */
3404 rc = qed_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
3405 p_vf->opaque_fid);
3406
3407 if (rc) {
3408 DP_ERR(p_hwfn, "qed_sp_vf_stop returned error %d\n",
3409 rc);
3410 status = PFVF_STATUS_FAILURE;
3411 }
3412
3413 p_vf->state = VF_STOPPED;
3414 }
3415
Yuval Mintz0b55e272016-05-11 16:36:15 +03003416 qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
Yuval Mintz1fe614d2016-06-05 13:11:11 +03003417 length, status);
Yuval Mintz0b55e272016-05-11 16:36:15 +03003418}
3419
Rahul Vermabf5a94b2017-07-26 06:07:14 -07003420static void qed_iov_vf_pf_get_coalesce(struct qed_hwfn *p_hwfn,
3421 struct qed_ptt *p_ptt,
3422 struct qed_vf_info *p_vf)
3423{
3424 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
3425 struct pfvf_read_coal_resp_tlv *p_resp;
3426 struct vfpf_read_coal_req_tlv *req;
3427 u8 status = PFVF_STATUS_FAILURE;
3428 struct qed_vf_queue *p_queue;
3429 struct qed_queue_cid *p_cid;
3430 u16 coal = 0, qid, i;
3431 bool b_is_rx;
3432 int rc = 0;
3433
3434 mbx->offset = (u8 *)mbx->reply_virt;
3435 req = &mbx->req_virt->read_coal_req;
3436
3437 qid = req->qid;
3438 b_is_rx = req->is_rx ? true : false;
3439
3440 if (b_is_rx) {
3441 if (!qed_iov_validate_rxq(p_hwfn, p_vf, qid,
3442 QED_IOV_VALIDATE_Q_ENABLE)) {
3443 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3444 "VF[%d]: Invalid Rx queue_id = %d\n",
3445 p_vf->abs_vf_id, qid);
3446 goto send_resp;
3447 }
3448
3449 p_cid = qed_iov_get_vf_rx_queue_cid(&p_vf->vf_queues[qid]);
3450 rc = qed_get_rxq_coalesce(p_hwfn, p_ptt, p_cid, &coal);
3451 if (rc)
3452 goto send_resp;
3453 } else {
3454 if (!qed_iov_validate_txq(p_hwfn, p_vf, qid,
3455 QED_IOV_VALIDATE_Q_ENABLE)) {
3456 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3457 "VF[%d]: Invalid Tx queue_id = %d\n",
3458 p_vf->abs_vf_id, qid);
3459 goto send_resp;
3460 }
3461 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3462 p_queue = &p_vf->vf_queues[qid];
3463 if ((!p_queue->cids[i].p_cid) ||
3464 (!p_queue->cids[i].b_is_tx))
3465 continue;
3466
3467 p_cid = p_queue->cids[i].p_cid;
3468
3469 rc = qed_get_txq_coalesce(p_hwfn, p_ptt, p_cid, &coal);
3470 if (rc)
3471 goto send_resp;
3472 break;
3473 }
3474 }
3475
3476 status = PFVF_STATUS_SUCCESS;
3477
3478send_resp:
3479 p_resp = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_COALESCE_READ,
3480 sizeof(*p_resp));
3481 p_resp->coal = coal;
3482
3483 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
3484 sizeof(struct channel_list_end_tlv));
3485
3486 qed_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
3487}
3488
Rahul Verma477f2d12017-07-26 06:07:13 -07003489static void qed_iov_vf_pf_set_coalesce(struct qed_hwfn *p_hwfn,
3490 struct qed_ptt *p_ptt,
3491 struct qed_vf_info *vf)
3492{
3493 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
3494 struct vfpf_update_coalesce *req;
3495 u8 status = PFVF_STATUS_FAILURE;
3496 struct qed_queue_cid *p_cid;
3497 u16 rx_coal, tx_coal;
3498 int rc = 0, i;
3499 u16 qid;
3500
3501 req = &mbx->req_virt->update_coalesce;
3502
3503 rx_coal = req->rx_coal;
3504 tx_coal = req->tx_coal;
3505 qid = req->qid;
3506
3507 if (!qed_iov_validate_rxq(p_hwfn, vf, qid,
3508 QED_IOV_VALIDATE_Q_ENABLE) && rx_coal) {
3509 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3510 "VF[%d]: Invalid Rx queue_id = %d\n",
3511 vf->abs_vf_id, qid);
3512 goto out;
3513 }
3514
3515 if (!qed_iov_validate_txq(p_hwfn, vf, qid,
3516 QED_IOV_VALIDATE_Q_ENABLE) && tx_coal) {
3517 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3518 "VF[%d]: Invalid Tx queue_id = %d\n",
3519 vf->abs_vf_id, qid);
3520 goto out;
3521 }
3522
3523 DP_VERBOSE(p_hwfn,
3524 QED_MSG_IOV,
3525 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3526 vf->abs_vf_id, rx_coal, tx_coal, qid);
3527
3528 if (rx_coal) {
3529 p_cid = qed_iov_get_vf_rx_queue_cid(&vf->vf_queues[qid]);
3530
3531 rc = qed_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3532 if (rc) {
3533 DP_VERBOSE(p_hwfn,
3534 QED_MSG_IOV,
3535 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3536 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3537 goto out;
3538 }
Rahul Vermabf5a94b2017-07-26 06:07:14 -07003539 vf->rx_coal = rx_coal;
Rahul Verma477f2d12017-07-26 06:07:13 -07003540 }
3541
3542 if (tx_coal) {
3543 struct qed_vf_queue *p_queue = &vf->vf_queues[qid];
3544
3545 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3546 if (!p_queue->cids[i].p_cid)
3547 continue;
3548
3549 if (!p_queue->cids[i].b_is_tx)
3550 continue;
3551
3552 rc = qed_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3553 p_queue->cids[i].p_cid);
3554
3555 if (rc) {
3556 DP_VERBOSE(p_hwfn,
3557 QED_MSG_IOV,
3558 "VF[%d]: Unable to set tx queue coalesce\n",
3559 vf->abs_vf_id);
3560 goto out;
3561 }
3562 }
Rahul Vermabf5a94b2017-07-26 06:07:14 -07003563 vf->tx_coal = tx_coal;
Rahul Verma477f2d12017-07-26 06:07:13 -07003564 }
3565
3566 status = PFVF_STATUS_SUCCESS;
3567out:
3568 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_COALESCE_UPDATE,
3569 sizeof(struct pfvf_def_resp_tlv), status);
3570}
Yuval Mintz0b55e272016-05-11 16:36:15 +03003571static int
3572qed_iov_vf_flr_poll_dorq(struct qed_hwfn *p_hwfn,
3573 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
3574{
3575 int cnt;
3576 u32 val;
3577
3578 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_vf->concrete_fid);
3579
3580 for (cnt = 0; cnt < 50; cnt++) {
3581 val = qed_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
3582 if (!val)
3583 break;
3584 msleep(20);
3585 }
3586 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
3587
3588 if (cnt == 50) {
3589 DP_ERR(p_hwfn,
3590 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
3591 p_vf->abs_vf_id, val);
3592 return -EBUSY;
3593 }
3594
3595 return 0;
3596}
3597
3598static int
3599qed_iov_vf_flr_poll_pbf(struct qed_hwfn *p_hwfn,
3600 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
3601{
Tomer Tayar21dd79e2017-12-27 19:30:06 +02003602 u32 cons[MAX_NUM_VOQS_E4], distance[MAX_NUM_VOQS_E4];
Yuval Mintz0b55e272016-05-11 16:36:15 +03003603 int i, cnt;
3604
3605 /* Read initial consumers & producers */
Tomer Tayar21dd79e2017-12-27 19:30:06 +02003606 for (i = 0; i < MAX_NUM_VOQS_E4; i++) {
Yuval Mintz0b55e272016-05-11 16:36:15 +03003607 u32 prod;
3608
3609 cons[i] = qed_rd(p_hwfn, p_ptt,
3610 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3611 i * 0x40);
3612 prod = qed_rd(p_hwfn, p_ptt,
3613 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
3614 i * 0x40);
3615 distance[i] = prod - cons[i];
3616 }
3617
3618 /* Wait for consumers to pass the producers */
3619 i = 0;
3620 for (cnt = 0; cnt < 50; cnt++) {
Tomer Tayar21dd79e2017-12-27 19:30:06 +02003621 for (; i < MAX_NUM_VOQS_E4; i++) {
Yuval Mintz0b55e272016-05-11 16:36:15 +03003622 u32 tmp;
3623
3624 tmp = qed_rd(p_hwfn, p_ptt,
3625 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3626 i * 0x40);
3627 if (distance[i] > tmp - cons[i])
3628 break;
3629 }
3630
Tomer Tayar21dd79e2017-12-27 19:30:06 +02003631 if (i == MAX_NUM_VOQS_E4)
Yuval Mintz0b55e272016-05-11 16:36:15 +03003632 break;
3633
3634 msleep(20);
3635 }
3636
3637 if (cnt == 50) {
3638 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
3639 p_vf->abs_vf_id, i);
3640 return -EBUSY;
3641 }
3642
3643 return 0;
3644}
3645
3646static int qed_iov_vf_flr_poll(struct qed_hwfn *p_hwfn,
3647 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
3648{
3649 int rc;
3650
3651 rc = qed_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
3652 if (rc)
3653 return rc;
3654
3655 rc = qed_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
3656 if (rc)
3657 return rc;
3658
3659 return 0;
3660}
3661
3662static int
3663qed_iov_execute_vf_flr_cleanup(struct qed_hwfn *p_hwfn,
3664 struct qed_ptt *p_ptt,
3665 u16 rel_vf_id, u32 *ack_vfs)
3666{
3667 struct qed_vf_info *p_vf;
3668 int rc = 0;
3669
3670 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
3671 if (!p_vf)
3672 return 0;
3673
3674 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
3675 (1ULL << (rel_vf_id % 64))) {
3676 u16 vfid = p_vf->abs_vf_id;
3677
3678 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3679 "VF[%d] - Handling FLR\n", vfid);
3680
3681 qed_iov_vf_cleanup(p_hwfn, p_vf);
3682
3683 /* If VF isn't active, no need for anything but SW */
3684 if (!p_vf->b_init)
3685 goto cleanup;
3686
3687 rc = qed_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
3688 if (rc)
3689 goto cleanup;
3690
3691 rc = qed_final_cleanup(p_hwfn, p_ptt, vfid, true);
3692 if (rc) {
3693 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
3694 return rc;
3695 }
3696
Yuval Mintz7eff82b2016-10-14 05:19:22 -04003697 /* Workaround to make VF-PF channel ready, as FW
3698 * doesn't do that as a part of FLR.
3699 */
3700 REG_WR(p_hwfn,
3701 GTT_BAR0_MAP_REG_USDM_RAM +
3702 USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid), 1);
3703
Yuval Mintz0b55e272016-05-11 16:36:15 +03003704 /* VF_STOPPED has to be set only after final cleanup
3705 * but prior to re-enabling the VF.
3706 */
3707 p_vf->state = VF_STOPPED;
3708
3709 rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
3710 if (rc) {
3711 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
3712 vfid);
3713 return rc;
3714 }
3715cleanup:
3716 /* Mark VF for ack and clean pending state */
3717 if (p_vf->state == VF_RESET)
3718 p_vf->state = VF_STOPPED;
Yuval Mintz1a635e42016-08-15 10:42:43 +03003719 ack_vfs[vfid / 32] |= BIT((vfid % 32));
Yuval Mintz0b55e272016-05-11 16:36:15 +03003720 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
3721 ~(1ULL << (rel_vf_id % 64));
Mintz, Yuvalfd3c6152017-02-27 11:06:32 +02003722 p_vf->vf_mbx.b_pending_msg = false;
Yuval Mintz0b55e272016-05-11 16:36:15 +03003723 }
3724
3725 return rc;
3726}
3727
Baoyou Xieba569472016-09-09 09:21:15 +08003728static int
3729qed_iov_vf_flr_cleanup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
Yuval Mintz0b55e272016-05-11 16:36:15 +03003730{
3731 u32 ack_vfs[VF_MAX_STATIC / 32];
3732 int rc = 0;
3733 u16 i;
3734
3735 memset(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3736
3737 /* Since BRB <-> PRS interface can't be tested as part of the flr
3738 * polling due to HW limitations, simply sleep a bit. And since
3739 * there's no need to wait per-vf, do it before looping.
3740 */
3741 msleep(100);
3742
3743 for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++)
3744 qed_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
3745
3746 rc = qed_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3747 return rc;
3748}
3749
Mintz, Yuvalcccf6f52017-03-19 13:08:18 +02003750bool qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *p_disabled_vfs)
Yuval Mintz0b55e272016-05-11 16:36:15 +03003751{
Mintz, Yuvalcccf6f52017-03-19 13:08:18 +02003752 bool found = false;
3753 u16 i;
Yuval Mintz0b55e272016-05-11 16:36:15 +03003754
3755 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "Marking FLR-ed VFs\n");
3756 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
3757 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3758 "[%08x,...,%08x]: %08x\n",
3759 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
3760
3761 if (!p_hwfn->cdev->p_iov_info) {
3762 DP_NOTICE(p_hwfn, "VF flr but no IOV\n");
Mintz, Yuvalcccf6f52017-03-19 13:08:18 +02003763 return false;
Yuval Mintz0b55e272016-05-11 16:36:15 +03003764 }
3765
3766 /* Mark VFs */
3767 for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++) {
3768 struct qed_vf_info *p_vf;
3769 u8 vfid;
3770
3771 p_vf = qed_iov_get_vf_info(p_hwfn, i, false);
3772 if (!p_vf)
3773 continue;
3774
3775 vfid = p_vf->abs_vf_id;
Yuval Mintz1a635e42016-08-15 10:42:43 +03003776 if (BIT((vfid % 32)) & p_disabled_vfs[vfid / 32]) {
Yuval Mintz0b55e272016-05-11 16:36:15 +03003777 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
3778 u16 rel_vf_id = p_vf->relative_vf_id;
3779
3780 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3781 "VF[%d] [rel %d] got FLR-ed\n",
3782 vfid, rel_vf_id);
3783
3784 p_vf->state = VF_RESET;
3785
3786 /* No need to lock here, since pending_flr should
3787 * only change here and before ACKing MFw. Since
3788 * MFW will not trigger an additional attention for
3789 * VF flr until ACKs, we're safe.
3790 */
3791 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
Mintz, Yuvalcccf6f52017-03-19 13:08:18 +02003792 found = true;
Yuval Mintz0b55e272016-05-11 16:36:15 +03003793 }
3794 }
3795
3796 return found;
3797}
3798
Yuval Mintz73390ac2016-05-11 16:36:24 +03003799static void qed_iov_get_link(struct qed_hwfn *p_hwfn,
3800 u16 vfid,
3801 struct qed_mcp_link_params *p_params,
3802 struct qed_mcp_link_state *p_link,
3803 struct qed_mcp_link_capabilities *p_caps)
3804{
3805 struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
3806 vfid,
3807 false);
3808 struct qed_bulletin_content *p_bulletin;
3809
3810 if (!p_vf)
3811 return;
3812
3813 p_bulletin = p_vf->bulletin.p_virt;
3814
3815 if (p_params)
3816 __qed_vf_get_link_params(p_hwfn, p_params, p_bulletin);
3817 if (p_link)
3818 __qed_vf_get_link_state(p_hwfn, p_link, p_bulletin);
3819 if (p_caps)
3820 __qed_vf_get_link_caps(p_hwfn, p_caps, p_bulletin);
3821}
3822
Shahed Shaikh809c45a2018-04-19 05:50:12 -07003823static int
3824qed_iov_vf_pf_bulletin_update_mac(struct qed_hwfn *p_hwfn,
3825 struct qed_ptt *p_ptt,
3826 struct qed_vf_info *p_vf)
3827{
3828 struct qed_bulletin_content *p_bulletin = p_vf->bulletin.p_virt;
3829 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
3830 struct vfpf_bulletin_update_mac_tlv *p_req;
3831 u8 status = PFVF_STATUS_SUCCESS;
3832 int rc = 0;
3833
3834 if (!p_vf->p_vf_info.is_trusted_configured) {
3835 DP_VERBOSE(p_hwfn,
3836 QED_MSG_IOV,
3837 "Blocking bulletin update request from untrusted VF[%d]\n",
3838 p_vf->abs_vf_id);
3839 status = PFVF_STATUS_NOT_SUPPORTED;
3840 rc = -EINVAL;
3841 goto send_status;
3842 }
3843
3844 p_req = &mbx->req_virt->bulletin_update_mac;
3845 ether_addr_copy(p_bulletin->mac, p_req->mac);
3846 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3847 "Updated bulletin of VF[%d] with requested MAC[%pM]\n",
3848 p_vf->abs_vf_id, p_req->mac);
3849
3850send_status:
3851 qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
3852 CHANNEL_TLV_BULLETIN_UPDATE_MAC,
3853 sizeof(struct pfvf_def_resp_tlv), status);
3854 return rc;
3855}
3856
Yuval Mintz37bff2b2016-05-11 16:36:13 +03003857static void qed_iov_process_mbx_req(struct qed_hwfn *p_hwfn,
3858 struct qed_ptt *p_ptt, int vfid)
3859{
3860 struct qed_iov_vf_mbx *mbx;
3861 struct qed_vf_info *p_vf;
Yuval Mintz37bff2b2016-05-11 16:36:13 +03003862
3863 p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3864 if (!p_vf)
3865 return;
3866
3867 mbx = &p_vf->vf_mbx;
3868
3869 /* qed_iov_process_mbx_request */
Mintz, Yuvalfd3c6152017-02-27 11:06:32 +02003870 if (!mbx->b_pending_msg) {
3871 DP_NOTICE(p_hwfn,
3872 "VF[%02x]: Trying to process mailbox message when none is pending\n",
3873 p_vf->abs_vf_id);
3874 return;
3875 }
3876 mbx->b_pending_msg = false;
Yuval Mintz37bff2b2016-05-11 16:36:13 +03003877
3878 mbx->first_tlv = mbx->req_virt->first_tlv;
3879
Mintz, Yuvalfd3c6152017-02-27 11:06:32 +02003880 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3881 "VF[%02x]: Processing mailbox message [type %04x]\n",
3882 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
3883
Yuval Mintz37bff2b2016-05-11 16:36:13 +03003884 /* check if tlv type is known */
Yuval Mintz7eff82b2016-10-14 05:19:22 -04003885 if (qed_iov_tlv_supported(mbx->first_tlv.tl.type) &&
3886 !p_vf->b_malicious) {
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03003887 switch (mbx->first_tlv.tl.type) {
3888 case CHANNEL_TLV_ACQUIRE:
3889 qed_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
3890 break;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003891 case CHANNEL_TLV_VPORT_START:
3892 qed_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
3893 break;
3894 case CHANNEL_TLV_VPORT_TEARDOWN:
3895 qed_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
3896 break;
3897 case CHANNEL_TLV_START_RXQ:
3898 qed_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
3899 break;
3900 case CHANNEL_TLV_START_TXQ:
3901 qed_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
3902 break;
3903 case CHANNEL_TLV_STOP_RXQS:
3904 qed_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
3905 break;
3906 case CHANNEL_TLV_STOP_TXQS:
3907 qed_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
3908 break;
Yuval Mintz17b235c2016-05-11 16:36:18 +03003909 case CHANNEL_TLV_UPDATE_RXQ:
3910 qed_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
3911 break;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03003912 case CHANNEL_TLV_VPORT_UPDATE:
3913 qed_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
3914 break;
3915 case CHANNEL_TLV_UCAST_FILTER:
3916 qed_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
3917 break;
Yuval Mintz0b55e272016-05-11 16:36:15 +03003918 case CHANNEL_TLV_CLOSE:
3919 qed_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
3920 break;
3921 case CHANNEL_TLV_INT_CLEANUP:
3922 qed_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
3923 break;
3924 case CHANNEL_TLV_RELEASE:
3925 qed_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
3926 break;
Chopra, Manisheaf3c0c2017-04-24 10:00:49 -07003927 case CHANNEL_TLV_UPDATE_TUNN_PARAM:
3928 qed_iov_vf_mbx_update_tunn_param(p_hwfn, p_ptt, p_vf);
3929 break;
Rahul Verma477f2d12017-07-26 06:07:13 -07003930 case CHANNEL_TLV_COALESCE_UPDATE:
3931 qed_iov_vf_pf_set_coalesce(p_hwfn, p_ptt, p_vf);
3932 break;
Rahul Vermabf5a94b2017-07-26 06:07:14 -07003933 case CHANNEL_TLV_COALESCE_READ:
3934 qed_iov_vf_pf_get_coalesce(p_hwfn, p_ptt, p_vf);
3935 break;
Shahed Shaikh809c45a2018-04-19 05:50:12 -07003936 case CHANNEL_TLV_BULLETIN_UPDATE_MAC:
3937 qed_iov_vf_pf_bulletin_update_mac(p_hwfn, p_ptt, p_vf);
3938 break;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03003939 }
Yuval Mintz7eff82b2016-10-14 05:19:22 -04003940 } else if (qed_iov_tlv_supported(mbx->first_tlv.tl.type)) {
3941 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3942 "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
3943 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
3944
3945 qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
3946 mbx->first_tlv.tl.type,
3947 sizeof(struct pfvf_def_resp_tlv),
3948 PFVF_STATUS_MALICIOUS);
Yuval Mintz37bff2b2016-05-11 16:36:13 +03003949 } else {
3950 /* unknown TLV - this may belong to a VF driver from the future
3951 * - a version written after this PF driver was written, which
3952 * supports features unknown as of yet. Too bad since we don't
3953 * support them. Or this may be because someone wrote a crappy
3954 * VF driver and is sending garbage over the channel.
3955 */
Yuval Mintz54fdd802016-06-05 13:11:16 +03003956 DP_NOTICE(p_hwfn,
3957 "VF[%02x]: unknown TLV. type %04x length %04x padding %08x reply address %llu\n",
3958 p_vf->abs_vf_id,
3959 mbx->first_tlv.tl.type,
3960 mbx->first_tlv.tl.length,
3961 mbx->first_tlv.padding, mbx->first_tlv.reply_address);
Yuval Mintz37bff2b2016-05-11 16:36:13 +03003962
Yuval Mintz54fdd802016-06-05 13:11:16 +03003963 /* Try replying in case reply address matches the acquisition's
3964 * posted address.
3965 */
3966 if (p_vf->acquire.first_tlv.reply_address &&
3967 (mbx->first_tlv.reply_address ==
3968 p_vf->acquire.first_tlv.reply_address)) {
3969 qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
3970 mbx->first_tlv.tl.type,
3971 sizeof(struct pfvf_def_resp_tlv),
3972 PFVF_STATUS_NOT_SUPPORTED);
3973 } else {
Yuval Mintz37bff2b2016-05-11 16:36:13 +03003974 DP_VERBOSE(p_hwfn,
3975 QED_MSG_IOV,
Yuval Mintz54fdd802016-06-05 13:11:16 +03003976 "VF[%02x]: Can't respond to TLV - no valid reply address\n",
3977 p_vf->abs_vf_id);
Yuval Mintz37bff2b2016-05-11 16:36:13 +03003978 }
3979 }
3980}
3981
Mintz, Yuvalfd3c6152017-02-27 11:06:32 +02003982void qed_iov_pf_get_pending_events(struct qed_hwfn *p_hwfn, u64 *events)
Yuval Mintz37bff2b2016-05-11 16:36:13 +03003983{
Mintz, Yuvalfd3c6152017-02-27 11:06:32 +02003984 int i;
Yuval Mintz37bff2b2016-05-11 16:36:13 +03003985
Mintz, Yuvalfd3c6152017-02-27 11:06:32 +02003986 memset(events, 0, sizeof(u64) * QED_VF_ARRAY_LENGTH);
Yuval Mintz37bff2b2016-05-11 16:36:13 +03003987
Mintz, Yuvalfd3c6152017-02-27 11:06:32 +02003988 qed_for_each_vf(p_hwfn, i) {
3989 struct qed_vf_info *p_vf;
Yuval Mintz37bff2b2016-05-11 16:36:13 +03003990
Mintz, Yuvalfd3c6152017-02-27 11:06:32 +02003991 p_vf = &p_hwfn->pf_iov_info->vfs_array[i];
3992 if (p_vf->vf_mbx.b_pending_msg)
3993 events[i / 64] |= 1ULL << (i % 64);
3994 }
Yuval Mintz37bff2b2016-05-11 16:36:13 +03003995}
3996
Yuval Mintz7eff82b2016-10-14 05:19:22 -04003997static struct qed_vf_info *qed_sriov_get_vf_from_absid(struct qed_hwfn *p_hwfn,
3998 u16 abs_vfid)
3999{
4000 u8 min = (u8) p_hwfn->cdev->p_iov_info->first_vf_in_pf;
4001
4002 if (!_qed_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min, false)) {
4003 DP_VERBOSE(p_hwfn,
4004 QED_MSG_IOV,
4005 "Got indication for VF [abs 0x%08x] that cannot be handled by PF\n",
4006 abs_vfid);
4007 return NULL;
4008 }
4009
4010 return &p_hwfn->pf_iov_info->vfs_array[(u8) abs_vfid - min];
4011}
4012
Yuval Mintz37bff2b2016-05-11 16:36:13 +03004013static int qed_sriov_vfpf_msg(struct qed_hwfn *p_hwfn,
4014 u16 abs_vfid, struct regpair *vf_msg)
4015{
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004016 struct qed_vf_info *p_vf = qed_sriov_get_vf_from_absid(p_hwfn,
Yuval Mintz37bff2b2016-05-11 16:36:13 +03004017 abs_vfid);
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004018
4019 if (!p_vf)
Yuval Mintz37bff2b2016-05-11 16:36:13 +03004020 return 0;
Yuval Mintz37bff2b2016-05-11 16:36:13 +03004021
4022 /* List the physical address of the request so that handler
4023 * could later on copy the message from it.
4024 */
4025 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
4026
4027 /* Mark the event and schedule the workqueue */
Mintz, Yuvalfd3c6152017-02-27 11:06:32 +02004028 p_vf->vf_mbx.b_pending_msg = true;
Yuval Mintz37bff2b2016-05-11 16:36:13 +03004029 qed_schedule_iov(p_hwfn, QED_IOV_WQ_MSG_FLAG);
4030
4031 return 0;
4032}
4033
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004034static void qed_sriov_vfpf_malicious(struct qed_hwfn *p_hwfn,
4035 struct malicious_vf_eqe_data *p_data)
4036{
4037 struct qed_vf_info *p_vf;
4038
4039 p_vf = qed_sriov_get_vf_from_absid(p_hwfn, p_data->vf_id);
4040
4041 if (!p_vf)
4042 return;
4043
Mintz, Yuvale99a21c2017-03-19 13:08:19 +02004044 if (!p_vf->b_malicious) {
4045 DP_NOTICE(p_hwfn,
4046 "VF [%d] - Malicious behavior [%02x]\n",
4047 p_vf->abs_vf_id, p_data->err_id);
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004048
Mintz, Yuvale99a21c2017-03-19 13:08:19 +02004049 p_vf->b_malicious = true;
4050 } else {
4051 DP_INFO(p_hwfn,
4052 "VF [%d] - Malicious behavior [%02x]\n",
4053 p_vf->abs_vf_id, p_data->err_id);
4054 }
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004055}
4056
Michal Kalderon6c9e80e2017-06-20 16:00:06 +03004057static int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
4058 u8 opcode,
4059 __le16 echo,
4060 union event_ring_data *data, u8 fw_return_code)
Yuval Mintz37bff2b2016-05-11 16:36:13 +03004061{
4062 switch (opcode) {
4063 case COMMON_EVENT_VF_PF_CHANNEL:
4064 return qed_sriov_vfpf_msg(p_hwfn, le16_to_cpu(echo),
4065 &data->vf_pf_channel.msg_addr);
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004066 case COMMON_EVENT_MALICIOUS_VF:
4067 qed_sriov_vfpf_malicious(p_hwfn, &data->malicious_vf);
4068 return 0;
Yuval Mintz37bff2b2016-05-11 16:36:13 +03004069 default:
4070 DP_INFO(p_hwfn->cdev, "Unknown sriov eqe event 0x%02x\n",
4071 opcode);
4072 return -EINVAL;
4073 }
4074}
4075
Yuval Mintz32a47e72016-05-11 16:36:12 +03004076u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id)
4077{
4078 struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
4079 u16 i;
4080
4081 if (!p_iov)
4082 goto out;
4083
4084 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004085 if (qed_iov_is_valid_vfid(p_hwfn, rel_vf_id, true, false))
Yuval Mintz32a47e72016-05-11 16:36:12 +03004086 return i;
4087
4088out:
4089 return MAX_NUM_VFS;
4090}
Yuval Mintz37bff2b2016-05-11 16:36:13 +03004091
4092static int qed_iov_copy_vf_msg(struct qed_hwfn *p_hwfn, struct qed_ptt *ptt,
4093 int vfid)
4094{
4095 struct qed_dmae_params params;
4096 struct qed_vf_info *vf_info;
4097
4098 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
4099 if (!vf_info)
4100 return -EINVAL;
4101
4102 memset(&params, 0, sizeof(struct qed_dmae_params));
4103 params.flags = QED_DMAE_FLAG_VF_SRC | QED_DMAE_FLAG_COMPLETION_DST;
4104 params.src_vfid = vf_info->abs_vf_id;
4105
4106 if (qed_dmae_host2host(p_hwfn, ptt,
4107 vf_info->vf_mbx.pending_req,
4108 vf_info->vf_mbx.req_phys,
4109 sizeof(union vfpf_tlvs) / 4, &params)) {
4110 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
4111 "Failed to copy message from VF 0x%02x\n", vfid);
4112
4113 return -EIO;
4114 }
4115
4116 return 0;
4117}
4118
Yuval Mintzeff16962016-05-11 16:36:21 +03004119static void qed_iov_bulletin_set_forced_mac(struct qed_hwfn *p_hwfn,
4120 u8 *mac, int vfid)
4121{
4122 struct qed_vf_info *vf_info;
4123 u64 feature;
4124
4125 vf_info = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4126 if (!vf_info) {
4127 DP_NOTICE(p_hwfn->cdev,
4128 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
4129 return;
4130 }
4131
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004132 if (vf_info->b_malicious) {
4133 DP_NOTICE(p_hwfn->cdev,
4134 "Can't set forced MAC to malicious VF [%d]\n", vfid);
4135 return;
4136 }
4137
Shahed Shaikh7425d822018-04-19 05:50:11 -07004138 if (vf_info->p_vf_info.is_trusted_configured) {
4139 feature = BIT(VFPF_BULLETIN_MAC_ADDR);
4140 /* Trust mode will disable Forced MAC */
4141 vf_info->bulletin.p_virt->valid_bitmap &=
4142 ~BIT(MAC_ADDR_FORCED);
4143 } else {
4144 feature = BIT(MAC_ADDR_FORCED);
4145 /* Forced MAC will disable MAC_ADDR */
4146 vf_info->bulletin.p_virt->valid_bitmap &=
4147 ~BIT(VFPF_BULLETIN_MAC_ADDR);
4148 }
4149
Yuval Mintzeff16962016-05-11 16:36:21 +03004150 memcpy(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
4151
4152 vf_info->bulletin.p_virt->valid_bitmap |= feature;
Yuval Mintzeff16962016-05-11 16:36:21 +03004153
4154 qed_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4155}
4156
Shahed Shaikh7425d822018-04-19 05:50:11 -07004157static int qed_iov_bulletin_set_mac(struct qed_hwfn *p_hwfn, u8 *mac, int vfid)
4158{
4159 struct qed_vf_info *vf_info;
4160 u64 feature;
4161
4162 vf_info = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4163 if (!vf_info) {
4164 DP_NOTICE(p_hwfn->cdev, "Can not set MAC, invalid vfid [%d]\n",
4165 vfid);
4166 return -EINVAL;
4167 }
4168
4169 if (vf_info->b_malicious) {
4170 DP_NOTICE(p_hwfn->cdev, "Can't set MAC to malicious VF [%d]\n",
4171 vfid);
4172 return -EINVAL;
4173 }
4174
4175 if (vf_info->bulletin.p_virt->valid_bitmap & BIT(MAC_ADDR_FORCED)) {
4176 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
4177 "Can not set MAC, Forced MAC is configured\n");
4178 return -EINVAL;
4179 }
4180
4181 feature = BIT(VFPF_BULLETIN_MAC_ADDR);
4182 ether_addr_copy(vf_info->bulletin.p_virt->mac, mac);
4183
4184 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4185
4186 if (vf_info->p_vf_info.is_trusted_configured)
4187 qed_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4188
4189 return 0;
4190}
4191
Baoyou Xieba569472016-09-09 09:21:15 +08004192static void qed_iov_bulletin_set_forced_vlan(struct qed_hwfn *p_hwfn,
4193 u16 pvid, int vfid)
Yuval Mintz08feecd2016-05-11 16:36:20 +03004194{
4195 struct qed_vf_info *vf_info;
4196 u64 feature;
4197
4198 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
4199 if (!vf_info) {
4200 DP_NOTICE(p_hwfn->cdev,
4201 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
4202 return;
4203 }
4204
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004205 if (vf_info->b_malicious) {
4206 DP_NOTICE(p_hwfn->cdev,
4207 "Can't set forced vlan to malicious VF [%d]\n", vfid);
4208 return;
4209 }
4210
Yuval Mintz08feecd2016-05-11 16:36:20 +03004211 feature = 1 << VLAN_ADDR_FORCED;
4212 vf_info->bulletin.p_virt->pvid = pvid;
4213 if (pvid)
4214 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4215 else
4216 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
4217
4218 qed_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4219}
4220
Chopra, Manish97379f12017-04-24 10:00:48 -07004221void qed_iov_bulletin_set_udp_ports(struct qed_hwfn *p_hwfn,
4222 int vfid, u16 vxlan_port, u16 geneve_port)
4223{
4224 struct qed_vf_info *vf_info;
4225
4226 vf_info = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4227 if (!vf_info) {
4228 DP_NOTICE(p_hwfn->cdev,
4229 "Can not set udp ports, invalid vfid [%d]\n", vfid);
4230 return;
4231 }
4232
4233 if (vf_info->b_malicious) {
4234 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
4235 "Can not set udp ports to malicious VF [%d]\n",
4236 vfid);
4237 return;
4238 }
4239
4240 vf_info->bulletin.p_virt->vxlan_udp_port = vxlan_port;
4241 vf_info->bulletin.p_virt->geneve_udp_port = geneve_port;
4242}
4243
Yuval Mintz6ddc7602016-05-11 16:36:23 +03004244static bool qed_iov_vf_has_vport_instance(struct qed_hwfn *p_hwfn, int vfid)
4245{
4246 struct qed_vf_info *p_vf_info;
4247
4248 p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
4249 if (!p_vf_info)
4250 return false;
4251
4252 return !!p_vf_info->vport_instance;
4253}
4254
Baoyou Xieba569472016-09-09 09:21:15 +08004255static bool qed_iov_is_vf_stopped(struct qed_hwfn *p_hwfn, int vfid)
Yuval Mintz0b55e272016-05-11 16:36:15 +03004256{
4257 struct qed_vf_info *p_vf_info;
4258
4259 p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
4260 if (!p_vf_info)
4261 return true;
4262
4263 return p_vf_info->state == VF_STOPPED;
4264}
4265
Yuval Mintz73390ac2016-05-11 16:36:24 +03004266static bool qed_iov_spoofchk_get(struct qed_hwfn *p_hwfn, int vfid)
4267{
4268 struct qed_vf_info *vf_info;
4269
4270 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
4271 if (!vf_info)
4272 return false;
4273
4274 return vf_info->spoof_chk;
4275}
4276
Baoyou Xieba569472016-09-09 09:21:15 +08004277static int qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn, int vfid, bool val)
Yuval Mintz6ddc7602016-05-11 16:36:23 +03004278{
4279 struct qed_vf_info *vf;
4280 int rc = -EINVAL;
4281
4282 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
4283 DP_NOTICE(p_hwfn,
4284 "SR-IOV sanity check failed, can't set spoofchk\n");
4285 goto out;
4286 }
4287
4288 vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
4289 if (!vf)
4290 goto out;
4291
4292 if (!qed_iov_vf_has_vport_instance(p_hwfn, vfid)) {
4293 /* After VF VPORT start PF will configure spoof check */
4294 vf->req_spoofchk_val = val;
4295 rc = 0;
4296 goto out;
4297 }
4298
4299 rc = __qed_iov_spoofchk_set(p_hwfn, vf, val);
4300
4301out:
4302 return rc;
4303}
4304
Shahed Shaikh7425d822018-04-19 05:50:11 -07004305static u8 *qed_iov_bulletin_get_mac(struct qed_hwfn *p_hwfn, u16 rel_vf_id)
4306{
4307 struct qed_vf_info *p_vf;
4308
4309 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4310 if (!p_vf || !p_vf->bulletin.p_virt)
4311 return NULL;
4312
4313 if (!(p_vf->bulletin.p_virt->valid_bitmap &
4314 BIT(VFPF_BULLETIN_MAC_ADDR)))
4315 return NULL;
4316
4317 return p_vf->bulletin.p_virt->mac;
4318}
4319
Yuval Mintzeff16962016-05-11 16:36:21 +03004320static u8 *qed_iov_bulletin_get_forced_mac(struct qed_hwfn *p_hwfn,
4321 u16 rel_vf_id)
4322{
4323 struct qed_vf_info *p_vf;
4324
4325 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4326 if (!p_vf || !p_vf->bulletin.p_virt)
4327 return NULL;
4328
Yuval Mintz1a635e42016-08-15 10:42:43 +03004329 if (!(p_vf->bulletin.p_virt->valid_bitmap & BIT(MAC_ADDR_FORCED)))
Yuval Mintzeff16962016-05-11 16:36:21 +03004330 return NULL;
4331
4332 return p_vf->bulletin.p_virt->mac;
4333}
4334
Baoyou Xieba569472016-09-09 09:21:15 +08004335static u16
4336qed_iov_bulletin_get_forced_vlan(struct qed_hwfn *p_hwfn, u16 rel_vf_id)
Yuval Mintz08feecd2016-05-11 16:36:20 +03004337{
4338 struct qed_vf_info *p_vf;
4339
4340 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4341 if (!p_vf || !p_vf->bulletin.p_virt)
4342 return 0;
4343
Yuval Mintz1a635e42016-08-15 10:42:43 +03004344 if (!(p_vf->bulletin.p_virt->valid_bitmap & BIT(VLAN_ADDR_FORCED)))
Yuval Mintz08feecd2016-05-11 16:36:20 +03004345 return 0;
4346
4347 return p_vf->bulletin.p_virt->pvid;
4348}
4349
Yuval Mintz733def62016-05-11 16:36:22 +03004350static int qed_iov_configure_tx_rate(struct qed_hwfn *p_hwfn,
4351 struct qed_ptt *p_ptt, int vfid, int val)
4352{
Tomer Tayarda090912017-12-27 19:30:07 +02004353 struct qed_mcp_link_state *p_link;
Yuval Mintz733def62016-05-11 16:36:22 +03004354 struct qed_vf_info *vf;
4355 u8 abs_vp_id = 0;
4356 int rc;
4357
4358 vf = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4359 if (!vf)
4360 return -EINVAL;
4361
4362 rc = qed_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
4363 if (rc)
4364 return rc;
4365
Tomer Tayarda090912017-12-27 19:30:07 +02004366 p_link = &QED_LEADING_HWFN(p_hwfn->cdev)->mcp_info->link_output;
4367
4368 return qed_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val,
4369 p_link->speed);
Yuval Mintz733def62016-05-11 16:36:22 +03004370}
4371
Baoyou Xieba569472016-09-09 09:21:15 +08004372static int
4373qed_iov_configure_min_tx_rate(struct qed_dev *cdev, int vfid, u32 rate)
Yuval Mintz733def62016-05-11 16:36:22 +03004374{
4375 struct qed_vf_info *vf;
4376 u8 vport_id;
4377 int i;
4378
4379 for_each_hwfn(cdev, i) {
4380 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
4381
4382 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
4383 DP_NOTICE(p_hwfn,
4384 "SR-IOV sanity check failed, can't set min rate\n");
4385 return -EINVAL;
4386 }
4387 }
4388
4389 vf = qed_iov_get_vf_info(QED_LEADING_HWFN(cdev), (u16)vfid, true);
4390 vport_id = vf->vport_id;
4391
4392 return qed_configure_vport_wfq(cdev, vport_id, rate);
4393}
4394
Yuval Mintz73390ac2016-05-11 16:36:24 +03004395static int qed_iov_get_vf_min_rate(struct qed_hwfn *p_hwfn, int vfid)
4396{
4397 struct qed_wfq_data *vf_vp_wfq;
4398 struct qed_vf_info *vf_info;
4399
4400 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
4401 if (!vf_info)
4402 return 0;
4403
4404 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
4405
4406 if (vf_vp_wfq->configured)
4407 return vf_vp_wfq->min_speed;
4408 else
4409 return 0;
4410}
4411
Yuval Mintz37bff2b2016-05-11 16:36:13 +03004412/**
4413 * qed_schedule_iov - schedules IOV task for VF and PF
4414 * @hwfn: hardware function pointer
4415 * @flag: IOV flag for VF/PF
4416 */
4417void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag)
4418{
4419 smp_mb__before_atomic();
4420 set_bit(flag, &hwfn->iov_task_flags);
4421 smp_mb__after_atomic();
4422 DP_VERBOSE(hwfn, QED_MSG_IOV, "Scheduling iov task [Flag: %d]\n", flag);
4423 queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, 0);
4424}
4425
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03004426void qed_vf_start_iov_wq(struct qed_dev *cdev)
4427{
4428 int i;
4429
4430 for_each_hwfn(cdev, i)
4431 queue_delayed_work(cdev->hwfns[i].iov_wq,
4432 &cdev->hwfns[i].iov_task, 0);
4433}
4434
Yuval Mintz0b55e272016-05-11 16:36:15 +03004435int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
4436{
4437 int i, j;
4438
4439 for_each_hwfn(cdev, i)
4440 if (cdev->hwfns[i].iov_wq)
4441 flush_workqueue(cdev->hwfns[i].iov_wq);
4442
4443 /* Mark VFs for disablement */
4444 qed_iov_set_vfs_to_disable(cdev, true);
4445
4446 if (cdev->p_iov_info && cdev->p_iov_info->num_vfs && pci_enabled)
4447 pci_disable_sriov(cdev->pdev);
4448
4449 for_each_hwfn(cdev, i) {
4450 struct qed_hwfn *hwfn = &cdev->hwfns[i];
4451 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
4452
4453 /* Failure to acquire the ptt in 100g creates an odd error
4454 * where the first engine has already relased IOV.
4455 */
4456 if (!ptt) {
4457 DP_ERR(hwfn, "Failed to acquire ptt\n");
4458 return -EBUSY;
4459 }
4460
Yuval Mintz733def62016-05-11 16:36:22 +03004461 /* Clean WFQ db and configure equal weight for all vports */
4462 qed_clean_wfq_db(hwfn, ptt);
4463
Yuval Mintz0b55e272016-05-11 16:36:15 +03004464 qed_for_each_vf(hwfn, j) {
4465 int k;
4466
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004467 if (!qed_iov_is_valid_vfid(hwfn, j, true, false))
Yuval Mintz0b55e272016-05-11 16:36:15 +03004468 continue;
4469
4470 /* Wait until VF is disabled before releasing */
4471 for (k = 0; k < 100; k++) {
4472 if (!qed_iov_is_vf_stopped(hwfn, j))
4473 msleep(20);
4474 else
4475 break;
4476 }
4477
4478 if (k < 100)
4479 qed_iov_release_hw_for_vf(&cdev->hwfns[i],
4480 ptt, j);
4481 else
4482 DP_ERR(hwfn,
4483 "Timeout waiting for VF's FLR to end\n");
4484 }
4485
4486 qed_ptt_release(hwfn, ptt);
4487 }
4488
4489 qed_iov_set_vfs_to_disable(cdev, false);
4490
4491 return 0;
4492}
4493
Mintz, Yuval3da7a372016-11-29 16:47:06 +02004494static void qed_sriov_enable_qid_config(struct qed_hwfn *hwfn,
4495 u16 vfid,
4496 struct qed_iov_vf_init_params *params)
4497{
4498 u16 base, i;
4499
4500 /* Since we have an equal resource distribution per-VF, and we assume
4501 * PF has acquired the QED_PF_L2_QUE first queues, we start setting
4502 * sequentially from there.
4503 */
4504 base = FEAT_NUM(hwfn, QED_PF_L2_QUE) + vfid * params->num_queues;
4505
4506 params->rel_vf_id = vfid;
4507 for (i = 0; i < params->num_queues; i++) {
4508 params->req_rx_queue[i] = base + i;
4509 params->req_tx_queue[i] = base + i;
4510 }
4511}
4512
Yuval Mintz0b55e272016-05-11 16:36:15 +03004513static int qed_sriov_enable(struct qed_dev *cdev, int num)
4514{
Mintz, Yuval3da7a372016-11-29 16:47:06 +02004515 struct qed_iov_vf_init_params params;
Sudarsana Reddy Kalluru538f8d02018-07-01 20:03:06 -07004516 struct qed_hwfn *hwfn;
4517 struct qed_ptt *ptt;
Yuval Mintz0b55e272016-05-11 16:36:15 +03004518 int i, j, rc;
4519
4520 if (num >= RESC_NUM(&cdev->hwfns[0], QED_VPORT)) {
4521 DP_NOTICE(cdev, "Can start at most %d VFs\n",
4522 RESC_NUM(&cdev->hwfns[0], QED_VPORT) - 1);
4523 return -EINVAL;
4524 }
4525
Mintz, Yuval3da7a372016-11-29 16:47:06 +02004526 memset(&params, 0, sizeof(params));
4527
Yuval Mintz0b55e272016-05-11 16:36:15 +03004528 /* Initialize HW for VF access */
4529 for_each_hwfn(cdev, j) {
Sudarsana Reddy Kalluru538f8d02018-07-01 20:03:06 -07004530 hwfn = &cdev->hwfns[j];
4531 ptt = qed_ptt_acquire(hwfn);
Mintz, Yuval5a1f9652016-10-31 07:14:26 +02004532
4533 /* Make sure not to use more than 16 queues per VF */
Mintz, Yuval3da7a372016-11-29 16:47:06 +02004534 params.num_queues = min_t(int,
4535 FEAT_NUM(hwfn, QED_VF_L2_QUE) / num,
4536 16);
Yuval Mintz0b55e272016-05-11 16:36:15 +03004537
4538 if (!ptt) {
4539 DP_ERR(hwfn, "Failed to acquire ptt\n");
4540 rc = -EBUSY;
4541 goto err;
4542 }
4543
Yuval Mintz0b55e272016-05-11 16:36:15 +03004544 for (i = 0; i < num; i++) {
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004545 if (!qed_iov_is_valid_vfid(hwfn, i, false, true))
Yuval Mintz0b55e272016-05-11 16:36:15 +03004546 continue;
4547
Mintz, Yuval3da7a372016-11-29 16:47:06 +02004548 qed_sriov_enable_qid_config(hwfn, i, &params);
4549 rc = qed_iov_init_hw_for_vf(hwfn, ptt, &params);
Yuval Mintz0b55e272016-05-11 16:36:15 +03004550 if (rc) {
4551 DP_ERR(cdev, "Failed to enable VF[%d]\n", i);
4552 qed_ptt_release(hwfn, ptt);
4553 goto err;
4554 }
4555 }
4556
4557 qed_ptt_release(hwfn, ptt);
4558 }
4559
4560 /* Enable SRIOV PCIe functions */
4561 rc = pci_enable_sriov(cdev->pdev, num);
4562 if (rc) {
4563 DP_ERR(cdev, "Failed to enable sriov [%d]\n", rc);
4564 goto err;
4565 }
4566
Sudarsana Reddy Kalluru538f8d02018-07-01 20:03:06 -07004567 hwfn = QED_LEADING_HWFN(cdev);
4568 ptt = qed_ptt_acquire(hwfn);
4569 if (!ptt) {
4570 DP_ERR(hwfn, "Failed to acquire ptt\n");
4571 rc = -EBUSY;
4572 goto err;
4573 }
4574
4575 rc = qed_mcp_ov_update_eswitch(hwfn, ptt, QED_OV_ESWITCH_VEB);
4576 if (rc)
4577 DP_INFO(cdev, "Failed to update eswitch mode\n");
4578 qed_ptt_release(hwfn, ptt);
4579
Yuval Mintz0b55e272016-05-11 16:36:15 +03004580 return num;
4581
4582err:
4583 qed_sriov_disable(cdev, false);
4584 return rc;
4585}
4586
4587static int qed_sriov_configure(struct qed_dev *cdev, int num_vfs_param)
4588{
4589 if (!IS_QED_SRIOV(cdev)) {
4590 DP_VERBOSE(cdev, QED_MSG_IOV, "SR-IOV is not supported\n");
4591 return -EOPNOTSUPP;
4592 }
4593
4594 if (num_vfs_param)
4595 return qed_sriov_enable(cdev, num_vfs_param);
4596 else
4597 return qed_sriov_disable(cdev, true);
4598}
4599
Yuval Mintzeff16962016-05-11 16:36:21 +03004600static int qed_sriov_pf_set_mac(struct qed_dev *cdev, u8 *mac, int vfid)
4601{
4602 int i;
4603
4604 if (!IS_QED_SRIOV(cdev) || !IS_PF_SRIOV_ALLOC(&cdev->hwfns[0])) {
4605 DP_VERBOSE(cdev, QED_MSG_IOV,
4606 "Cannot set a VF MAC; Sriov is not enabled\n");
4607 return -EINVAL;
4608 }
4609
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004610 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vfid, true, true)) {
Yuval Mintzeff16962016-05-11 16:36:21 +03004611 DP_VERBOSE(cdev, QED_MSG_IOV,
4612 "Cannot set VF[%d] MAC (VF is not active)\n", vfid);
4613 return -EINVAL;
4614 }
4615
4616 for_each_hwfn(cdev, i) {
4617 struct qed_hwfn *hwfn = &cdev->hwfns[i];
4618 struct qed_public_vf_info *vf_info;
4619
4620 vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
4621 if (!vf_info)
4622 continue;
4623
Shahed Shaikh7425d822018-04-19 05:50:11 -07004624 /* Set the MAC, and schedule the IOV task */
4625 if (vf_info->is_trusted_configured)
4626 ether_addr_copy(vf_info->mac, mac);
4627 else
4628 ether_addr_copy(vf_info->forced_mac, mac);
4629
Yuval Mintzeff16962016-05-11 16:36:21 +03004630 qed_schedule_iov(hwfn, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG);
4631 }
4632
4633 return 0;
4634}
4635
Yuval Mintz08feecd2016-05-11 16:36:20 +03004636static int qed_sriov_pf_set_vlan(struct qed_dev *cdev, u16 vid, int vfid)
4637{
4638 int i;
4639
4640 if (!IS_QED_SRIOV(cdev) || !IS_PF_SRIOV_ALLOC(&cdev->hwfns[0])) {
4641 DP_VERBOSE(cdev, QED_MSG_IOV,
4642 "Cannot set a VF MAC; Sriov is not enabled\n");
4643 return -EINVAL;
4644 }
4645
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004646 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vfid, true, true)) {
Yuval Mintz08feecd2016-05-11 16:36:20 +03004647 DP_VERBOSE(cdev, QED_MSG_IOV,
4648 "Cannot set VF[%d] MAC (VF is not active)\n", vfid);
4649 return -EINVAL;
4650 }
4651
4652 for_each_hwfn(cdev, i) {
4653 struct qed_hwfn *hwfn = &cdev->hwfns[i];
4654 struct qed_public_vf_info *vf_info;
4655
4656 vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
4657 if (!vf_info)
4658 continue;
4659
4660 /* Set the forced vlan, and schedule the IOV task */
4661 vf_info->forced_vlan = vid;
4662 qed_schedule_iov(hwfn, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG);
4663 }
4664
4665 return 0;
4666}
4667
Yuval Mintz73390ac2016-05-11 16:36:24 +03004668static int qed_get_vf_config(struct qed_dev *cdev,
4669 int vf_id, struct ifla_vf_info *ivi)
4670{
4671 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
4672 struct qed_public_vf_info *vf_info;
4673 struct qed_mcp_link_state link;
4674 u32 tx_rate;
4675
4676 /* Sanitize request */
4677 if (IS_VF(cdev))
4678 return -EINVAL;
4679
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004680 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vf_id, true, false)) {
Yuval Mintz73390ac2016-05-11 16:36:24 +03004681 DP_VERBOSE(cdev, QED_MSG_IOV,
4682 "VF index [%d] isn't active\n", vf_id);
4683 return -EINVAL;
4684 }
4685
4686 vf_info = qed_iov_get_public_vf_info(hwfn, vf_id, true);
4687
4688 qed_iov_get_link(hwfn, vf_id, NULL, &link, NULL);
4689
4690 /* Fill information about VF */
4691 ivi->vf = vf_id;
4692
4693 if (is_valid_ether_addr(vf_info->forced_mac))
4694 ether_addr_copy(ivi->mac, vf_info->forced_mac);
4695 else
4696 ether_addr_copy(ivi->mac, vf_info->mac);
4697
4698 ivi->vlan = vf_info->forced_vlan;
4699 ivi->spoofchk = qed_iov_spoofchk_get(hwfn, vf_id);
4700 ivi->linkstate = vf_info->link_state;
4701 tx_rate = vf_info->tx_rate;
4702 ivi->max_tx_rate = tx_rate ? tx_rate : link.speed;
4703 ivi->min_tx_rate = qed_iov_get_vf_min_rate(hwfn, vf_id);
4704
4705 return 0;
4706}
4707
Yuval Mintz36558c32016-05-11 16:36:17 +03004708void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
4709{
Mintz, Yuvale50728e2017-03-19 13:08:20 +02004710 struct qed_hwfn *lead_hwfn = QED_LEADING_HWFN(hwfn->cdev);
Yuval Mintz36558c32016-05-11 16:36:17 +03004711 struct qed_mcp_link_capabilities caps;
4712 struct qed_mcp_link_params params;
4713 struct qed_mcp_link_state link;
4714 int i;
4715
4716 if (!hwfn->pf_iov_info)
4717 return;
4718
4719 /* Update bulletin of all future possible VFs with link configuration */
4720 for (i = 0; i < hwfn->cdev->p_iov_info->total_vfs; i++) {
Yuval Mintz733def62016-05-11 16:36:22 +03004721 struct qed_public_vf_info *vf_info;
4722
4723 vf_info = qed_iov_get_public_vf_info(hwfn, i, false);
4724 if (!vf_info)
4725 continue;
4726
Mintz, Yuvale50728e2017-03-19 13:08:20 +02004727 /* Only hwfn0 is actually interested in the link speed.
4728 * But since only it would receive an MFW indication of link,
4729 * need to take configuration from it - otherwise things like
4730 * rate limiting for hwfn1 VF would not work.
4731 */
4732 memcpy(&params, qed_mcp_get_link_params(lead_hwfn),
4733 sizeof(params));
4734 memcpy(&link, qed_mcp_get_link_state(lead_hwfn), sizeof(link));
4735 memcpy(&caps, qed_mcp_get_link_capabilities(lead_hwfn),
Yuval Mintz36558c32016-05-11 16:36:17 +03004736 sizeof(caps));
4737
Yuval Mintz733def62016-05-11 16:36:22 +03004738 /* Modify link according to the VF's configured link state */
4739 switch (vf_info->link_state) {
4740 case IFLA_VF_LINK_STATE_DISABLE:
4741 link.link_up = false;
4742 break;
4743 case IFLA_VF_LINK_STATE_ENABLE:
4744 link.link_up = true;
4745 /* Set speed according to maximum supported by HW.
4746 * that is 40G for regular devices and 100G for CMT
4747 * mode devices.
4748 */
4749 link.speed = (hwfn->cdev->num_hwfns > 1) ?
4750 100000 : 40000;
4751 default:
4752 /* In auto mode pass PF link image to VF */
4753 break;
4754 }
4755
4756 if (link.link_up && vf_info->tx_rate) {
4757 struct qed_ptt *ptt;
4758 int rate;
4759
4760 rate = min_t(int, vf_info->tx_rate, link.speed);
4761
4762 ptt = qed_ptt_acquire(hwfn);
4763 if (!ptt) {
4764 DP_NOTICE(hwfn, "Failed to acquire PTT\n");
4765 return;
4766 }
4767
4768 if (!qed_iov_configure_tx_rate(hwfn, ptt, i, rate)) {
4769 vf_info->tx_rate = rate;
4770 link.speed = rate;
4771 }
4772
4773 qed_ptt_release(hwfn, ptt);
4774 }
4775
Yuval Mintz36558c32016-05-11 16:36:17 +03004776 qed_iov_set_link(hwfn, i, &params, &link, &caps);
4777 }
4778
4779 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
4780}
4781
Yuval Mintz733def62016-05-11 16:36:22 +03004782static int qed_set_vf_link_state(struct qed_dev *cdev,
4783 int vf_id, int link_state)
4784{
4785 int i;
4786
4787 /* Sanitize request */
4788 if (IS_VF(cdev))
4789 return -EINVAL;
4790
Yuval Mintz7eff82b2016-10-14 05:19:22 -04004791 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vf_id, true, true)) {
Yuval Mintz733def62016-05-11 16:36:22 +03004792 DP_VERBOSE(cdev, QED_MSG_IOV,
4793 "VF index [%d] isn't active\n", vf_id);
4794 return -EINVAL;
4795 }
4796
4797 /* Handle configuration of link state */
4798 for_each_hwfn(cdev, i) {
4799 struct qed_hwfn *hwfn = &cdev->hwfns[i];
4800 struct qed_public_vf_info *vf;
4801
4802 vf = qed_iov_get_public_vf_info(hwfn, vf_id, true);
4803 if (!vf)
4804 continue;
4805
4806 if (vf->link_state == link_state)
4807 continue;
4808
4809 vf->link_state = link_state;
4810 qed_inform_vf_link_state(&cdev->hwfns[i]);
4811 }
4812
4813 return 0;
4814}
4815
Yuval Mintz6ddc7602016-05-11 16:36:23 +03004816static int qed_spoof_configure(struct qed_dev *cdev, int vfid, bool val)
4817{
4818 int i, rc = -EINVAL;
4819
4820 for_each_hwfn(cdev, i) {
4821 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
4822
4823 rc = qed_iov_spoofchk_set(p_hwfn, vfid, val);
4824 if (rc)
4825 break;
4826 }
4827
4828 return rc;
4829}
4830
Yuval Mintz733def62016-05-11 16:36:22 +03004831static int qed_configure_max_vf_rate(struct qed_dev *cdev, int vfid, int rate)
4832{
4833 int i;
4834
4835 for_each_hwfn(cdev, i) {
4836 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
4837 struct qed_public_vf_info *vf;
4838
4839 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
4840 DP_NOTICE(p_hwfn,
4841 "SR-IOV sanity check failed, can't set tx rate\n");
4842 return -EINVAL;
4843 }
4844
4845 vf = qed_iov_get_public_vf_info(p_hwfn, vfid, true);
4846
4847 vf->tx_rate = rate;
4848
4849 qed_inform_vf_link_state(p_hwfn);
4850 }
4851
4852 return 0;
4853}
4854
4855static int qed_set_vf_rate(struct qed_dev *cdev,
4856 int vfid, u32 min_rate, u32 max_rate)
4857{
4858 int rc_min = 0, rc_max = 0;
4859
4860 if (max_rate)
4861 rc_max = qed_configure_max_vf_rate(cdev, vfid, max_rate);
4862
4863 if (min_rate)
4864 rc_min = qed_iov_configure_min_tx_rate(cdev, vfid, min_rate);
4865
4866 if (rc_max | rc_min)
4867 return -EINVAL;
4868
4869 return 0;
4870}
4871
Mintz, Yuvalf990c822017-01-01 13:57:08 +02004872static int qed_set_vf_trust(struct qed_dev *cdev, int vfid, bool trust)
4873{
4874 int i;
4875
4876 for_each_hwfn(cdev, i) {
4877 struct qed_hwfn *hwfn = &cdev->hwfns[i];
4878 struct qed_public_vf_info *vf;
4879
4880 if (!qed_iov_pf_sanity_check(hwfn, vfid)) {
4881 DP_NOTICE(hwfn,
4882 "SR-IOV sanity check failed, can't set trust\n");
4883 return -EINVAL;
4884 }
4885
4886 vf = qed_iov_get_public_vf_info(hwfn, vfid, true);
4887
4888 if (vf->is_trusted_request == trust)
4889 return 0;
4890 vf->is_trusted_request = trust;
4891
4892 qed_schedule_iov(hwfn, QED_IOV_WQ_TRUST_FLAG);
4893 }
4894
4895 return 0;
4896}
4897
Yuval Mintz37bff2b2016-05-11 16:36:13 +03004898static void qed_handle_vf_msg(struct qed_hwfn *hwfn)
4899{
4900 u64 events[QED_VF_ARRAY_LENGTH];
4901 struct qed_ptt *ptt;
4902 int i;
4903
4904 ptt = qed_ptt_acquire(hwfn);
4905 if (!ptt) {
4906 DP_VERBOSE(hwfn, QED_MSG_IOV,
4907 "Can't acquire PTT; re-scheduling\n");
4908 qed_schedule_iov(hwfn, QED_IOV_WQ_MSG_FLAG);
4909 return;
4910 }
4911
Mintz, Yuvalfd3c6152017-02-27 11:06:32 +02004912 qed_iov_pf_get_pending_events(hwfn, events);
Yuval Mintz37bff2b2016-05-11 16:36:13 +03004913
4914 DP_VERBOSE(hwfn, QED_MSG_IOV,
4915 "Event mask of VF events: 0x%llx 0x%llx 0x%llx\n",
4916 events[0], events[1], events[2]);
4917
4918 qed_for_each_vf(hwfn, i) {
4919 /* Skip VFs with no pending messages */
4920 if (!(events[i / 64] & (1ULL << (i % 64))))
4921 continue;
4922
4923 DP_VERBOSE(hwfn, QED_MSG_IOV,
4924 "Handling VF message from VF 0x%02x [Abs 0x%02x]\n",
4925 i, hwfn->cdev->p_iov_info->first_vf_in_pf + i);
4926
4927 /* Copy VF's message to PF's request buffer for that VF */
4928 if (qed_iov_copy_vf_msg(hwfn, ptt, i))
4929 continue;
4930
4931 qed_iov_process_mbx_req(hwfn, ptt, i);
4932 }
4933
4934 qed_ptt_release(hwfn, ptt);
4935}
4936
Shahed Shaikh7425d822018-04-19 05:50:11 -07004937static bool qed_pf_validate_req_vf_mac(struct qed_hwfn *hwfn,
4938 u8 *mac,
4939 struct qed_public_vf_info *info)
4940{
4941 if (info->is_trusted_configured) {
4942 if (is_valid_ether_addr(info->mac) &&
4943 (!mac || !ether_addr_equal(mac, info->mac)))
4944 return true;
4945 } else {
4946 if (is_valid_ether_addr(info->forced_mac) &&
4947 (!mac || !ether_addr_equal(mac, info->forced_mac)))
4948 return true;
4949 }
4950
4951 return false;
4952}
4953
4954static void qed_set_bulletin_mac(struct qed_hwfn *hwfn,
4955 struct qed_public_vf_info *info,
4956 int vfid)
4957{
4958 if (info->is_trusted_configured)
4959 qed_iov_bulletin_set_mac(hwfn, info->mac, vfid);
4960 else
4961 qed_iov_bulletin_set_forced_mac(hwfn, info->forced_mac, vfid);
4962}
4963
Yuval Mintz08feecd2016-05-11 16:36:20 +03004964static void qed_handle_pf_set_vf_unicast(struct qed_hwfn *hwfn)
4965{
4966 int i;
4967
4968 qed_for_each_vf(hwfn, i) {
4969 struct qed_public_vf_info *info;
4970 bool update = false;
Yuval Mintzeff16962016-05-11 16:36:21 +03004971 u8 *mac;
Yuval Mintz08feecd2016-05-11 16:36:20 +03004972
4973 info = qed_iov_get_public_vf_info(hwfn, i, true);
4974 if (!info)
4975 continue;
4976
4977 /* Update data on bulletin board */
Shahed Shaikh7425d822018-04-19 05:50:11 -07004978 if (info->is_trusted_configured)
4979 mac = qed_iov_bulletin_get_mac(hwfn, i);
4980 else
4981 mac = qed_iov_bulletin_get_forced_mac(hwfn, i);
4982
4983 if (qed_pf_validate_req_vf_mac(hwfn, mac, info)) {
Yuval Mintzeff16962016-05-11 16:36:21 +03004984 DP_VERBOSE(hwfn,
4985 QED_MSG_IOV,
4986 "Handling PF setting of VF MAC to VF 0x%02x [Abs 0x%02x]\n",
4987 i,
4988 hwfn->cdev->p_iov_info->first_vf_in_pf + i);
4989
Shahed Shaikh7425d822018-04-19 05:50:11 -07004990 /* Update bulletin board with MAC */
4991 qed_set_bulletin_mac(hwfn, info, i);
Yuval Mintzeff16962016-05-11 16:36:21 +03004992 update = true;
4993 }
Yuval Mintz08feecd2016-05-11 16:36:20 +03004994
4995 if (qed_iov_bulletin_get_forced_vlan(hwfn, i) ^
4996 info->forced_vlan) {
4997 DP_VERBOSE(hwfn,
4998 QED_MSG_IOV,
4999 "Handling PF setting of pvid [0x%04x] to VF 0x%02x [Abs 0x%02x]\n",
5000 info->forced_vlan,
5001 i,
5002 hwfn->cdev->p_iov_info->first_vf_in_pf + i);
5003 qed_iov_bulletin_set_forced_vlan(hwfn,
5004 info->forced_vlan, i);
5005 update = true;
5006 }
5007
5008 if (update)
5009 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
5010 }
5011}
5012
Yuval Mintz36558c32016-05-11 16:36:17 +03005013static void qed_handle_bulletin_post(struct qed_hwfn *hwfn)
5014{
5015 struct qed_ptt *ptt;
5016 int i;
5017
5018 ptt = qed_ptt_acquire(hwfn);
5019 if (!ptt) {
5020 DP_NOTICE(hwfn, "Failed allocating a ptt entry\n");
5021 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
5022 return;
5023 }
5024
5025 qed_for_each_vf(hwfn, i)
5026 qed_iov_post_vf_bulletin(hwfn, i, ptt);
5027
5028 qed_ptt_release(hwfn, ptt);
5029}
5030
Shahed Shaikh7425d822018-04-19 05:50:11 -07005031static void qed_update_mac_for_vf_trust_change(struct qed_hwfn *hwfn, int vf_id)
5032{
5033 struct qed_public_vf_info *vf_info;
5034 struct qed_vf_info *vf;
5035 u8 *force_mac;
5036 int i;
5037
5038 vf_info = qed_iov_get_public_vf_info(hwfn, vf_id, true);
5039 vf = qed_iov_get_vf_info(hwfn, vf_id, true);
5040
5041 if (!vf_info || !vf)
5042 return;
5043
5044 /* Force MAC converted to generic MAC in case of VF trust on */
5045 if (vf_info->is_trusted_configured &&
5046 (vf->bulletin.p_virt->valid_bitmap & BIT(MAC_ADDR_FORCED))) {
5047 force_mac = qed_iov_bulletin_get_forced_mac(hwfn, vf_id);
5048
5049 if (force_mac) {
5050 /* Clear existing shadow copy of MAC to have a clean
5051 * slate.
5052 */
5053 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++) {
5054 if (ether_addr_equal(vf->shadow_config.macs[i],
5055 vf_info->mac)) {
5056 memset(vf->shadow_config.macs[i], 0,
5057 ETH_ALEN);
5058 DP_VERBOSE(hwfn, QED_MSG_IOV,
5059 "Shadow MAC %pM removed for VF 0x%02x, VF trust mode is ON\n",
5060 vf_info->mac, vf_id);
5061 break;
5062 }
5063 }
5064
5065 ether_addr_copy(vf_info->mac, force_mac);
5066 memset(vf_info->forced_mac, 0, ETH_ALEN);
5067 vf->bulletin.p_virt->valid_bitmap &=
5068 ~BIT(MAC_ADDR_FORCED);
5069 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
5070 }
5071 }
5072
5073 /* Update shadow copy with VF MAC when trust mode is turned off */
5074 if (!vf_info->is_trusted_configured) {
5075 u8 empty_mac[ETH_ALEN];
5076
5077 memset(empty_mac, 0, ETH_ALEN);
5078 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++) {
5079 if (ether_addr_equal(vf->shadow_config.macs[i],
5080 empty_mac)) {
5081 ether_addr_copy(vf->shadow_config.macs[i],
5082 vf_info->mac);
5083 DP_VERBOSE(hwfn, QED_MSG_IOV,
5084 "Shadow is updated with %pM for VF 0x%02x, VF trust mode is OFF\n",
5085 vf_info->mac, vf_id);
5086 break;
5087 }
5088 }
5089 /* Clear bulletin when trust mode is turned off,
5090 * to have a clean slate for next (normal) operations.
5091 */
5092 qed_iov_bulletin_set_mac(hwfn, empty_mac, vf_id);
5093 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
5094 }
5095}
5096
Mintz, Yuvalf990c822017-01-01 13:57:08 +02005097static void qed_iov_handle_trust_change(struct qed_hwfn *hwfn)
5098{
5099 struct qed_sp_vport_update_params params;
5100 struct qed_filter_accept_flags *flags;
5101 struct qed_public_vf_info *vf_info;
5102 struct qed_vf_info *vf;
5103 u8 mask;
5104 int i;
5105
5106 mask = QED_ACCEPT_UCAST_UNMATCHED | QED_ACCEPT_MCAST_UNMATCHED;
5107 flags = &params.accept_flags;
5108
5109 qed_for_each_vf(hwfn, i) {
5110 /* Need to make sure current requested configuration didn't
5111 * flip so that we'll end up configuring something that's not
5112 * needed.
5113 */
5114 vf_info = qed_iov_get_public_vf_info(hwfn, i, true);
5115 if (vf_info->is_trusted_configured ==
5116 vf_info->is_trusted_request)
5117 continue;
5118 vf_info->is_trusted_configured = vf_info->is_trusted_request;
5119
Shahed Shaikh7425d822018-04-19 05:50:11 -07005120 /* Handle forced MAC mode */
5121 qed_update_mac_for_vf_trust_change(hwfn, i);
5122
Mintz, Yuvalf990c822017-01-01 13:57:08 +02005123 /* Validate that the VF has a configured vport */
5124 vf = qed_iov_get_vf_info(hwfn, i, true);
5125 if (!vf->vport_instance)
5126 continue;
5127
5128 memset(&params, 0, sizeof(params));
5129 params.opaque_fid = vf->opaque_fid;
5130 params.vport_id = vf->vport_id;
5131
5132 if (vf_info->rx_accept_mode & mask) {
5133 flags->update_rx_mode_config = 1;
5134 flags->rx_accept_filter = vf_info->rx_accept_mode;
5135 }
5136
5137 if (vf_info->tx_accept_mode & mask) {
5138 flags->update_tx_mode_config = 1;
5139 flags->tx_accept_filter = vf_info->tx_accept_mode;
5140 }
5141
5142 /* Remove if needed; Otherwise this would set the mask */
5143 if (!vf_info->is_trusted_configured) {
5144 flags->rx_accept_filter &= ~mask;
5145 flags->tx_accept_filter &= ~mask;
5146 }
5147
5148 if (flags->update_rx_mode_config ||
5149 flags->update_tx_mode_config)
5150 qed_sp_vport_update(hwfn, &params,
5151 QED_SPQ_MODE_EBLOCK, NULL);
5152 }
5153}
5154
Baoyou Xieba569472016-09-09 09:21:15 +08005155static void qed_iov_pf_task(struct work_struct *work)
5156
Yuval Mintz37bff2b2016-05-11 16:36:13 +03005157{
5158 struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
5159 iov_task.work);
Yuval Mintz0b55e272016-05-11 16:36:15 +03005160 int rc;
Yuval Mintz37bff2b2016-05-11 16:36:13 +03005161
5162 if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
5163 return;
5164
Yuval Mintz0b55e272016-05-11 16:36:15 +03005165 if (test_and_clear_bit(QED_IOV_WQ_FLR_FLAG, &hwfn->iov_task_flags)) {
5166 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
5167
5168 if (!ptt) {
5169 qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG);
5170 return;
5171 }
5172
5173 rc = qed_iov_vf_flr_cleanup(hwfn, ptt);
5174 if (rc)
5175 qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG);
5176
5177 qed_ptt_release(hwfn, ptt);
5178 }
5179
Yuval Mintz37bff2b2016-05-11 16:36:13 +03005180 if (test_and_clear_bit(QED_IOV_WQ_MSG_FLAG, &hwfn->iov_task_flags))
5181 qed_handle_vf_msg(hwfn);
Yuval Mintz08feecd2016-05-11 16:36:20 +03005182
5183 if (test_and_clear_bit(QED_IOV_WQ_SET_UNICAST_FILTER_FLAG,
5184 &hwfn->iov_task_flags))
5185 qed_handle_pf_set_vf_unicast(hwfn);
5186
Yuval Mintz36558c32016-05-11 16:36:17 +03005187 if (test_and_clear_bit(QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
5188 &hwfn->iov_task_flags))
5189 qed_handle_bulletin_post(hwfn);
Mintz, Yuvalf990c822017-01-01 13:57:08 +02005190
5191 if (test_and_clear_bit(QED_IOV_WQ_TRUST_FLAG, &hwfn->iov_task_flags))
5192 qed_iov_handle_trust_change(hwfn);
Yuval Mintz37bff2b2016-05-11 16:36:13 +03005193}
5194
5195void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
5196{
5197 int i;
5198
5199 for_each_hwfn(cdev, i) {
5200 if (!cdev->hwfns[i].iov_wq)
5201 continue;
5202
5203 if (schedule_first) {
5204 qed_schedule_iov(&cdev->hwfns[i],
5205 QED_IOV_WQ_STOP_WQ_FLAG);
5206 cancel_delayed_work_sync(&cdev->hwfns[i].iov_task);
5207 }
5208
5209 flush_workqueue(cdev->hwfns[i].iov_wq);
5210 destroy_workqueue(cdev->hwfns[i].iov_wq);
5211 }
5212}
5213
5214int qed_iov_wq_start(struct qed_dev *cdev)
5215{
5216 char name[NAME_SIZE];
5217 int i;
5218
5219 for_each_hwfn(cdev, i) {
5220 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
5221
Yuval Mintz36558c32016-05-11 16:36:17 +03005222 /* PFs needs a dedicated workqueue only if they support IOV.
5223 * VFs always require one.
5224 */
5225 if (IS_PF(p_hwfn->cdev) && !IS_PF_SRIOV(p_hwfn))
Yuval Mintz37bff2b2016-05-11 16:36:13 +03005226 continue;
5227
5228 snprintf(name, NAME_SIZE, "iov-%02x:%02x.%02x",
5229 cdev->pdev->bus->number,
5230 PCI_SLOT(cdev->pdev->devfn), p_hwfn->abs_pf_id);
5231
5232 p_hwfn->iov_wq = create_singlethread_workqueue(name);
5233 if (!p_hwfn->iov_wq) {
5234 DP_NOTICE(p_hwfn, "Cannot create iov workqueue\n");
5235 return -ENOMEM;
5236 }
5237
Yuval Mintz36558c32016-05-11 16:36:17 +03005238 if (IS_PF(cdev))
5239 INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_pf_task);
5240 else
5241 INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_vf_task);
Yuval Mintz37bff2b2016-05-11 16:36:13 +03005242 }
5243
5244 return 0;
5245}
Yuval Mintz0b55e272016-05-11 16:36:15 +03005246
5247const struct qed_iov_hv_ops qed_iov_ops_pass = {
5248 .configure = &qed_sriov_configure,
Yuval Mintzeff16962016-05-11 16:36:21 +03005249 .set_mac = &qed_sriov_pf_set_mac,
Yuval Mintz08feecd2016-05-11 16:36:20 +03005250 .set_vlan = &qed_sriov_pf_set_vlan,
Yuval Mintz73390ac2016-05-11 16:36:24 +03005251 .get_config = &qed_get_vf_config,
Yuval Mintz733def62016-05-11 16:36:22 +03005252 .set_link_state = &qed_set_vf_link_state,
Yuval Mintz6ddc7602016-05-11 16:36:23 +03005253 .set_spoof = &qed_spoof_configure,
Yuval Mintz733def62016-05-11 16:36:22 +03005254 .set_rate = &qed_set_vf_rate,
Mintz, Yuvalf990c822017-01-01 13:57:08 +02005255 .set_trust = &qed_set_vf_trust,
Yuval Mintz0b55e272016-05-11 16:36:15 +03005256};