forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 297b60346df8beafee954a0fd7c2d64f33f3b9bc
kernel/drivers/net/ethernet/qlogic/qed/qed_sriov.c
....@@ -1,38 +1,13 @@
1
+// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
12 /* QLogic qed NIC Driver
23 * Copyright (c) 2015-2017 QLogic Corporation
3
- *
4
- * This software is available to you under a choice of one of two
5
- * licenses. You may choose to be licensed under the terms of the GNU
6
- * General Public License (GPL) Version 2, available from the file
7
- * COPYING in the main directory of this source tree, or the
8
- * OpenIB.org BSD license below:
9
- *
10
- * Redistribution and use in source and binary forms, with or
11
- * without modification, are permitted provided that the following
12
- * conditions are met:
13
- *
14
- * - Redistributions of source code must retain the above
15
- * copyright notice, this list of conditions and the following
16
- * disclaimer.
17
- *
18
- * - Redistributions in binary form must reproduce the above
19
- * copyright notice, this list of conditions and the following
20
- * disclaimer in the documentation and /or other materials
21
- * provided with the distribution.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
- * SOFTWARE.
4
+ * Copyright (c) 2019-2020 Marvell International Ltd.
315 */
326
337 #include <linux/etherdevice.h>
348 #include <linux/crc32.h>
359 #include <linux/vmalloc.h>
10
+#include <linux/crash_dump.h>
3611 #include <linux/qed/qed_iov_if.h>
3712 #include "qed_cxt.h"
3813 #include "qed_hsi.h"
....@@ -353,7 +328,7 @@
353328
354329 /* propagate bulletin board via dmae to vm memory */
355330 memset(&params, 0, sizeof(params));
356
- params.flags = QED_DMAE_FLAG_VF_DST;
331
+ SET_FIELD(params.flags, QED_DMAE_PARAMS_DST_VF_VALID, 0x1);
357332 params.dst_vfid = p_vf->abs_vf_id;
358333 return qed_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
359334 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
....@@ -608,6 +583,9 @@
608583 int pos;
609584 int rc;
610585
586
+ if (is_kdump_kernel())
587
+ return 0;
588
+
611589 if (IS_VF(p_hwfn->cdev))
612590 return 0;
613591
....@@ -846,16 +824,17 @@
846824 }
847825
848826 /**
849
- * @brief qed_iov_config_perm_table - configure the permission
850
- * zone table.
851
- * In E4, queue zone permission table size is 320x9. There
852
- * are 320 VF queues for single engine device (256 for dual
853
- * engine device), and each entry has the following format:
854
- * {Valid, VF[7:0]}
855
- * @param p_hwfn
856
- * @param p_ptt
857
- * @param vf
858
- * @param enable
827
+ * qed_iov_config_perm_table() - Configure the permission zone table.
828
+ *
829
+ * @p_hwfn: HW device data.
830
+ * @p_ptt: PTT window for writing the registers.
831
+ * @vf: VF info data.
832
+ * @enable: The actual permision for this VF.
833
+ *
834
+ * In E4, queue zone permission table size is 320x9. There
835
+ * are 320 VF queues for single engine device (256 for dual
836
+ * engine device), and each entry has the following format:
837
+ * {Valid, VF[7:0]}
859838 */
860839 static void qed_iov_config_perm_table(struct qed_hwfn *p_hwfn,
861840 struct qed_ptt *p_ptt,
....@@ -918,10 +897,11 @@
918897 /* Configure igu sb in CAU which were marked valid */
919898 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
920899 p_hwfn->rel_pf_id, vf->abs_vf_id, 1);
900
+
921901 qed_dmae_host2grc(p_hwfn, p_ptt,
922902 (u64)(uintptr_t)&sb_entry,
923903 CAU_REG_SB_VAR_MEMORY +
924
- p_block->igu_sb_id * sizeof(u64), 2, 0);
904
+ p_block->igu_sb_id * sizeof(u64), 2, NULL);
925905 }
926906
927907 vf->num_sbs = (u8) num_rx_queues;
....@@ -1225,8 +1205,8 @@
12251205
12261206 eng_vf_id = p_vf->abs_vf_id;
12271207
1228
- memset(&params, 0, sizeof(struct qed_dmae_params));
1229
- params.flags = QED_DMAE_FLAG_VF_DST;
1208
+ memset(&params, 0, sizeof(params));
1209
+ SET_FIELD(params.flags, QED_DMAE_PARAMS_DST_VF_VALID, 0x1);
12301210 params.dst_vfid = eng_vf_id;
12311211
12321212 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
....@@ -1592,7 +1572,7 @@
15921572 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
15931573 } else {
15941574 DP_INFO(p_hwfn,
1595
- "VF[%d] needs fastpath HSI %02x.%02x, which is incompatible with loaded FW's faspath HSI %02x.%02x\n",
1575
+ "VF[%d] needs fastpath HSI %02x.%02x, which is incompatible with loaded FW's fastpath HSI %02x.%02x\n",
15961576 vf->abs_vf_id,
15971577 req->vfdev_info.eth_fp_hsi_major,
15981578 req->vfdev_info.eth_fp_hsi_minor,
....@@ -2005,7 +1985,7 @@
20051985 (qed_iov_validate_active_txq(p_hwfn, vf))) {
20061986 vf->b_malicious = true;
20071987 DP_NOTICE(p_hwfn,
2008
- "VF [%02x] - considered malicious; Unable to stop RX/TX queuess\n",
1988
+ "VF [%02x] - considered malicious; Unable to stop RX/TX queues\n",
20091989 vf->abs_vf_id);
20101990 status = PFVF_STATUS_MALICIOUS;
20111991 goto out;
....@@ -3002,12 +2982,16 @@
30022982 u8 mask = QED_ACCEPT_UCAST_UNMATCHED | QED_ACCEPT_MCAST_UNMATCHED;
30032983 struct qed_filter_accept_flags *flags = &params->accept_flags;
30042984 struct qed_public_vf_info *vf_info;
2985
+ u16 tlv_mask;
2986
+
2987
+ tlv_mask = BIT(QED_IOV_VP_UPDATE_ACCEPT_PARAM) |
2988
+ BIT(QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN);
30052989
30062990 /* Untrusted VFs can't even be trusted to know that fact.
30072991 * Simply indicate everything is configured fine, and trace
30082992 * configuration 'behind their back'.
30092993 */
3010
- if (!(*tlvs & BIT(QED_IOV_VP_UPDATE_ACCEPT_PARAM)))
2994
+ if (!(*tlvs & tlv_mask))
30112995 return 0;
30122996
30132997 vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
....@@ -3022,6 +3006,13 @@
30223006 vf_info->tx_accept_mode = flags->tx_accept_filter;
30233007 if (!vf_info->is_trusted_configured)
30243008 flags->tx_accept_filter &= ~mask;
3009
+ }
3010
+
3011
+ if (params->update_accept_any_vlan_flg) {
3012
+ vf_info->accept_any_vlan = params->accept_any_vlan;
3013
+
3014
+ if (vf_info->forced_vlan && !vf_info->is_trusted_configured)
3015
+ params->accept_any_vlan = false;
30253016 }
30263017
30273018 return 0;
....@@ -3297,14 +3288,12 @@
32973288
32983289 DP_VERBOSE(p_hwfn,
32993290 QED_MSG_IOV,
3300
- "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x] MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
3291
+ "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x] MAC %pM, vlan 0x%04x\n",
33013292 vf->abs_vf_id, params.opcode, params.type,
33023293 params.is_rx_filter ? "RX" : "",
33033294 params.is_tx_filter ? "TX" : "",
33043295 params.vport_to_add_to,
3305
- params.mac[0], params.mac[1],
3306
- params.mac[2], params.mac[3],
3307
- params.mac[4], params.mac[5], params.vlan);
3296
+ params.mac, params.vlan);
33083297
33093298 if (!vf->vport_instance) {
33103299 DP_VERBOSE(p_hwfn,
....@@ -3800,11 +3789,11 @@
38003789 return found;
38013790 }
38023791
3803
-static void qed_iov_get_link(struct qed_hwfn *p_hwfn,
3804
- u16 vfid,
3805
- struct qed_mcp_link_params *p_params,
3806
- struct qed_mcp_link_state *p_link,
3807
- struct qed_mcp_link_capabilities *p_caps)
3792
+static int qed_iov_get_link(struct qed_hwfn *p_hwfn,
3793
+ u16 vfid,
3794
+ struct qed_mcp_link_params *p_params,
3795
+ struct qed_mcp_link_state *p_link,
3796
+ struct qed_mcp_link_capabilities *p_caps)
38083797 {
38093798 struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
38103799 vfid,
....@@ -3812,7 +3801,7 @@
38123801 struct qed_bulletin_content *p_bulletin;
38133802
38143803 if (!p_vf)
3815
- return;
3804
+ return -EINVAL;
38163805
38173806 p_bulletin = p_vf->bulletin.p_virt;
38183807
....@@ -3822,6 +3811,7 @@
38223811 __qed_vf_get_link_state(p_hwfn, p_link, p_bulletin);
38233812 if (p_caps)
38243813 __qed_vf_get_link_caps(p_hwfn, p_caps, p_bulletin);
3814
+ return 0;
38253815 }
38263816
38273817 static int
....@@ -4026,7 +4016,7 @@
40264016 /* List the physical address of the request so that handler
40274017 * could later on copy the message from it.
40284018 */
4029
- p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
4019
+ p_vf->vf_mbx.pending_req = HILO_64(vf_msg->hi, vf_msg->lo);
40304020
40314021 /* Mark the event and schedule the workqueue */
40324022 p_vf->vf_mbx.b_pending_msg = true;
....@@ -4058,9 +4048,7 @@
40584048 }
40594049 }
40604050
4061
-static int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
4062
- u8 opcode,
4063
- __le16 echo,
4051
+static int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn, u8 opcode, __le16 echo,
40644052 union event_ring_data *data, u8 fw_return_code)
40654053 {
40664054 switch (opcode) {
....@@ -4103,8 +4091,9 @@
41034091 if (!vf_info)
41044092 return -EINVAL;
41054093
4106
- memset(&params, 0, sizeof(struct qed_dmae_params));
4107
- params.flags = QED_DMAE_FLAG_VF_SRC | QED_DMAE_FLAG_COMPLETION_DST;
4094
+ memset(&params, 0, sizeof(params));
4095
+ SET_FIELD(params.flags, QED_DMAE_PARAMS_SRC_VF_VALID, 0x1);
4096
+ SET_FIELD(params.flags, QED_DMAE_PARAMS_COMPLETION_DST, 0x1);
41084097 params.src_vfid = vf_info->abs_vf_id;
41094098
41104099 if (qed_dmae_host2host(p_hwfn, ptt,
....@@ -4354,9 +4343,9 @@
43544343 static int qed_iov_configure_tx_rate(struct qed_hwfn *p_hwfn,
43554344 struct qed_ptt *p_ptt, int vfid, int val)
43564345 {
4357
- struct qed_mcp_link_state *p_link;
43584346 struct qed_vf_info *vf;
43594347 u8 abs_vp_id = 0;
4348
+ u16 rl_id;
43604349 int rc;
43614350
43624351 vf = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
....@@ -4367,10 +4356,8 @@
43674356 if (rc)
43684357 return rc;
43694358
4370
- p_link = &QED_LEADING_HWFN(p_hwfn->cdev)->mcp_info->link_output;
4371
-
4372
- return qed_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val,
4373
- p_link->speed);
4359
+ rl_id = abs_vp_id; /* The "rl_id" is set as the "vport_id" */
4360
+ return qed_init_global_rl(p_hwfn, p_ptt, rl_id, (u32)val);
43744361 }
43754362
43764363 static int
....@@ -4391,6 +4378,9 @@
43914378 }
43924379
43934380 vf = qed_iov_get_vf_info(QED_LEADING_HWFN(cdev), (u16)vfid, true);
4381
+ if (!vf)
4382
+ return -EINVAL;
4383
+
43944384 vport_id = vf->vport_id;
43954385
43964386 return qed_configure_vport_wfq(cdev, vport_id, rate);
....@@ -4450,6 +4440,13 @@
44504440 if (cdev->p_iov_info && cdev->p_iov_info->num_vfs && pci_enabled)
44514441 pci_disable_sriov(cdev->pdev);
44524442
4443
+ if (cdev->recov_in_prog) {
4444
+ DP_VERBOSE(cdev,
4445
+ QED_MSG_IOV,
4446
+ "Skip SRIOV disable operations in the device since a recovery is in progress\n");
4447
+ goto out;
4448
+ }
4449
+
44534450 for_each_hwfn(cdev, i) {
44544451 struct qed_hwfn *hwfn = &cdev->hwfns[i];
44554452 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
....@@ -4489,7 +4486,7 @@
44894486
44904487 qed_ptt_release(hwfn, ptt);
44914488 }
4492
-
4489
+out:
44934490 qed_iov_set_vfs_to_disable(cdev, false);
44944491
44954492 return 0;
....@@ -4676,6 +4673,7 @@
46764673 struct qed_public_vf_info *vf_info;
46774674 struct qed_mcp_link_state link;
46784675 u32 tx_rate;
4676
+ int ret;
46794677
46804678 /* Sanitize request */
46814679 if (IS_VF(cdev))
....@@ -4689,7 +4687,9 @@
46894687
46904688 vf_info = qed_iov_get_public_vf_info(hwfn, vf_id, true);
46914689
4692
- qed_iov_get_link(hwfn, vf_id, NULL, &link, NULL);
4690
+ ret = qed_iov_get_link(hwfn, vf_id, NULL, &link, NULL);
4691
+ if (ret)
4692
+ return ret;
46934693
46944694 /* Fill information about VF */
46954695 ivi->vf = vf_id;
....@@ -4705,6 +4705,7 @@
47054705 tx_rate = vf_info->tx_rate;
47064706 ivi->max_tx_rate = tx_rate ? tx_rate : link.speed;
47074707 ivi->min_tx_rate = qed_iov_get_vf_min_rate(hwfn, vf_id);
4708
+ ivi->trusted = vf_info->is_trusted_request;
47084709
47094710 return 0;
47104711 }
....@@ -5057,8 +5058,7 @@
50575058 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++) {
50585059 if (ether_addr_equal(vf->shadow_config.macs[i],
50595060 vf_info->mac)) {
5060
- memset(vf->shadow_config.macs[i], 0,
5061
- ETH_ALEN);
5061
+ eth_zero_addr(vf->shadow_config.macs[i]);
50625062 DP_VERBOSE(hwfn, QED_MSG_IOV,
50635063 "Shadow MAC %pM removed for VF 0x%02x, VF trust mode is ON\n",
50645064 vf_info->mac, vf_id);
....@@ -5067,7 +5067,7 @@
50675067 }
50685068
50695069 ether_addr_copy(vf_info->mac, force_mac);
5070
- memset(vf_info->forced_mac, 0, ETH_ALEN);
5070
+ eth_zero_addr(vf_info->forced_mac);
50715071 vf->bulletin.p_virt->valid_bitmap &=
50725072 ~BIT(MAC_ADDR_FORCED);
50735073 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
....@@ -5078,7 +5078,7 @@
50785078 if (!vf_info->is_trusted_configured) {
50795079 u8 empty_mac[ETH_ALEN];
50805080
5081
- memset(empty_mac, 0, ETH_ALEN);
5081
+ eth_zero_addr(empty_mac);
50825082 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++) {
50835083 if (ether_addr_equal(vf->shadow_config.macs[i],
50845084 empty_mac)) {
....@@ -5126,7 +5126,7 @@
51265126
51275127 /* Validate that the VF has a configured vport */
51285128 vf = qed_iov_get_vf_info(hwfn, i, true);
5129
- if (!vf->vport_instance)
5129
+ if (!vf || !vf->vport_instance)
51305130 continue;
51315131
51325132 memset(&params, 0, sizeof(params));
....@@ -5135,6 +5135,12 @@
51355135
51365136 params.update_ctl_frame_check = 1;
51375137 params.mac_chk_en = !vf_info->is_trusted_configured;
5138
+ params.update_accept_any_vlan_flg = 0;
5139
+
5140
+ if (vf_info->accept_any_vlan && vf_info->forced_vlan) {
5141
+ params.update_accept_any_vlan_flg = 1;
5142
+ params.accept_any_vlan = vf_info->accept_any_vlan;
5143
+ }
51385144
51395145 if (vf_info->rx_accept_mode & mask) {
51405146 flags->update_rx_mode_config = 1;
....@@ -5150,13 +5156,20 @@
51505156 if (!vf_info->is_trusted_configured) {
51515157 flags->rx_accept_filter &= ~mask;
51525158 flags->tx_accept_filter &= ~mask;
5159
+ params.accept_any_vlan = false;
51535160 }
51545161
51555162 if (flags->update_rx_mode_config ||
51565163 flags->update_tx_mode_config ||
5157
- params.update_ctl_frame_check)
5164
+ params.update_ctl_frame_check ||
5165
+ params.update_accept_any_vlan_flg) {
5166
+ DP_VERBOSE(hwfn, QED_MSG_IOV,
5167
+ "vport update config for %s VF[abs 0x%x rel 0x%x]\n",
5168
+ vf_info->is_trusted_configured ? "trusted" : "untrusted",
5169
+ vf->abs_vf_id, vf->relative_vf_id);
51585170 qed_sp_vport_update(hwfn, &params,
51595171 QED_SPQ_MODE_EBLOCK, NULL);
5172
+ }
51605173 }
51615174 }
51625175