You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
152 lines
4.8 KiB
152 lines
4.8 KiB
From 5ad60432be4bc7b015baeba7013d74fba3130363 Mon Sep 17 00:00:00 2001
|
|
From: Jonathan Toppins <jtoppins@redhat.com>
|
|
Date: Fri, 6 Dec 2019 20:12:42 -0500
|
|
Subject: [PATCH 86/96] [netdrv] bnxt_en: Fix devlink NVRAM related byte order
|
|
related issues
|
|
|
|
Message-id: <be3b99bbac7d76d0ecca750c548a160334e37a09.1575651771.git.jtoppins@redhat.com>
|
|
Patchwork-id: 291377
|
|
O-Subject: [PATCH rhel8 02/13] bnxt_en: Fix devlink NVRAM related byte order related issues.
|
|
Bugzilla: 1773724
|
|
RH-Acked-by: Steve Best <sbest@redhat.com>
|
|
RH-Acked-by: David Arcari <darcari@redhat.com>
|
|
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
|
|
RH-Acked-by: John Linville <linville@redhat.com>
|
|
|
|
The current code does not do endian swapping between the devlink
|
|
parameter and the internal NVRAM representation. Define a union to
|
|
represent the little endian NVRAM data and add 2 helper functions to
|
|
copy to and from the NVRAM data with the proper byte swapping.
|
|
|
|
Fixes: 782a624d00fa ("bnxt_en: Add bnxt_en initial port params table and register it")
|
|
Cc: Jiri Pirko <jiri@mellanox.com>
|
|
Reviewed-by: Vasundhara Volam <vasundhara-v.volam@broadcom.com>
|
|
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
|
|
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
|
|
(cherry picked from commit 83a46a82b96c1928ad82958752523fb0c7d9fcce)
|
|
Bugzilla: 1773724
|
|
Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=25154853
|
|
Tested: simple boot test
|
|
Signed-off-by: Jonathan Toppins <jtoppins@redhat.com>
|
|
Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
|
|
---
|
|
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 81 +++++++++++++++--------
|
|
1 file changed, 54 insertions(+), 27 deletions(-)
|
|
|
|
Index: src/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
|
|
===================================================================
|
|
--- src.orig/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c 2020-02-06 16:23:21.809457168 +0100
|
|
+++ src/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c 2020-02-06 16:23:21.942455948 +0100
|
|
@@ -226,12 +226,55 @@
|
|
BNXT_NVM_SHARED_CFG, 1, 1},
|
|
};
|
|
|
|
+union bnxt_nvm_data {
|
|
+ u8 val8;
|
|
+ __le32 val32;
|
|
+};
|
|
+
|
|
+static void bnxt_copy_to_nvm_data(union bnxt_nvm_data *dst,
|
|
+ union devlink_param_value *src,
|
|
+ int nvm_num_bits, int dl_num_bytes)
|
|
+{
|
|
+ u32 val32 = 0;
|
|
+
|
|
+ if (nvm_num_bits == 1) {
|
|
+ dst->val8 = src->vbool;
|
|
+ return;
|
|
+ }
|
|
+ if (dl_num_bytes == 4)
|
|
+ val32 = src->vu32;
|
|
+ else if (dl_num_bytes == 2)
|
|
+ val32 = (u32)src->vu16;
|
|
+ else if (dl_num_bytes == 1)
|
|
+ val32 = (u32)src->vu8;
|
|
+ dst->val32 = cpu_to_le32(val32);
|
|
+}
|
|
+
|
|
+static void bnxt_copy_from_nvm_data(union devlink_param_value *dst,
|
|
+ union bnxt_nvm_data *src,
|
|
+ int nvm_num_bits, int dl_num_bytes)
|
|
+{
|
|
+ u32 val32;
|
|
+
|
|
+ if (nvm_num_bits == 1) {
|
|
+ dst->vbool = src->val8;
|
|
+ return;
|
|
+ }
|
|
+ val32 = le32_to_cpu(src->val32);
|
|
+ if (dl_num_bytes == 4)
|
|
+ dst->vu32 = val32;
|
|
+ else if (dl_num_bytes == 2)
|
|
+ dst->vu16 = (u16)val32;
|
|
+ else if (dl_num_bytes == 1)
|
|
+ dst->vu8 = (u8)val32;
|
|
+}
|
|
+
|
|
static int bnxt_hwrm_nvm_req(struct bnxt *bp, u32 param_id, void *msg,
|
|
int msg_len, union devlink_param_value *val)
|
|
{
|
|
struct hwrm_nvm_get_variable_input *req = msg;
|
|
- void *data_addr = NULL, *buf = NULL;
|
|
struct bnxt_dl_nvm_param nvm_param;
|
|
+ union bnxt_nvm_data *data;
|
|
dma_addr_t data_dma_addr;
|
|
int idx = 0, rc, i;
|
|
|
|
@@ -254,26 +297,9 @@
|
|
else if (nvm_param.dir_type == BNXT_NVM_FUNC_CFG)
|
|
idx = bp->pf.fw_fid - BNXT_FIRST_PF_FID;
|
|
|
|
- switch (nvm_param.dl_num_bytes) {
|
|
- case 1:
|
|
- if (nvm_param.nvm_num_bits == 1)
|
|
- buf = &val->vbool;
|
|
- else
|
|
- buf = &val->vu8;
|
|
- break;
|
|
- case 2:
|
|
- buf = &val->vu16;
|
|
- break;
|
|
- case 4:
|
|
- buf = &val->vu32;
|
|
- break;
|
|
- default:
|
|
- return -EFAULT;
|
|
- }
|
|
-
|
|
- data_addr = dma_alloc_coherent(&bp->pdev->dev, nvm_param.dl_num_bytes,
|
|
- &data_dma_addr, GFP_KERNEL);
|
|
- if (!data_addr)
|
|
+ data = dma_alloc_coherent(&bp->pdev->dev, sizeof(*data),
|
|
+ &data_dma_addr, GFP_KERNEL);
|
|
+ if (!data)
|
|
return -ENOMEM;
|
|
|
|
req->dest_data_addr = cpu_to_le64(data_dma_addr);
|
|
@@ -284,17 +310,18 @@
|
|
req->dimensions = cpu_to_le16(1);
|
|
|
|
if (req->req_type == cpu_to_le16(HWRM_NVM_SET_VARIABLE)) {
|
|
- memcpy(data_addr, buf, nvm_param.dl_num_bytes);
|
|
+ bnxt_copy_to_nvm_data(data, val, nvm_param.nvm_num_bits,
|
|
+ nvm_param.dl_num_bytes);
|
|
rc = hwrm_send_message(bp, msg, msg_len, HWRM_CMD_TIMEOUT);
|
|
} else {
|
|
rc = hwrm_send_message_silent(bp, msg, msg_len,
|
|
HWRM_CMD_TIMEOUT);
|
|
+ if (!rc)
|
|
+ bnxt_copy_from_nvm_data(val, data,
|
|
+ nvm_param.nvm_num_bits,
|
|
+ nvm_param.dl_num_bytes);
|
|
}
|
|
- if (!rc && req->req_type == cpu_to_le16(HWRM_NVM_GET_VARIABLE))
|
|
- memcpy(buf, data_addr, nvm_param.dl_num_bytes);
|
|
-
|
|
- dma_free_coherent(&bp->pdev->dev, nvm_param.dl_num_bytes, data_addr,
|
|
- data_dma_addr);
|
|
+ dma_free_coherent(&bp->pdev->dev, sizeof(*data), data, data_dma_addr);
|
|
if (rc == -EACCES)
|
|
netdev_err(bp->dev, "PF does not have admin privileges to modify NVM config\n");
|
|
return rc;
|