bnxt_en: Return linux standard errors in bnxt_ethtool.c
authorVasundhara Volam <vasundhara-v.volam@broadcom.com>
Sun, 16 Dec 2018 23:46:28 +0000 (18:46 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Dec 2019 14:37:29 +0000 (15:37 +0100)
[ Upstream commit 7c675421afef18253a86ffc383f57bc15ef32ea8 ]

Currently firmware specific errors are returned directly in flash_device
and reset ethtool hooks. Modify it to return linux standard errors
to userspace when flashing operations fail.

Signed-off-by: Vasundhara Volam <vasundhara-v.volam@broadcom.com>
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c

index a22336fef66b23bb6718eb05a345b0ef0d68700d..4879371ad0c750610a50fdc767a16b9d1f65596c 100644 (file)
@@ -1339,14 +1339,22 @@ static int bnxt_flash_nvram(struct net_device *dev,
        rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT);
        dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle);
 
+       if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) {
+               netdev_info(dev,
+                           "PF does not have admin privileges to flash the device\n");
+               rc = -EACCES;
+       } else if (rc) {
+               rc = -EIO;
+       }
        return rc;
 }
 
 static int bnxt_firmware_reset(struct net_device *dev,
                               u16 dir_type)
 {
-       struct bnxt *bp = netdev_priv(dev);
        struct hwrm_fw_reset_input req = {0};
+       struct bnxt *bp = netdev_priv(dev);
+       int rc;
 
        bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1);
 
@@ -1380,7 +1388,15 @@ static int bnxt_firmware_reset(struct net_device *dev,
                return -EINVAL;
        }
 
-       return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
+       rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
+       if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) {
+               netdev_info(dev,
+                           "PF does not have admin privileges to reset the device\n");
+               rc = -EACCES;
+       } else if (rc) {
+               rc = -EIO;
+       }
+       return rc;
 }
 
 static int bnxt_flash_firmware(struct net_device *dev,
@@ -1587,9 +1603,9 @@ static int bnxt_flash_package_from_file(struct net_device *dev,
        struct hwrm_nvm_install_update_output *resp = bp->hwrm_cmd_resp_addr;
        struct hwrm_nvm_install_update_input install = {0};
        const struct firmware *fw;
+       int rc, hwrm_err = 0;
        u32 item_len;
        u16 index;
-       int rc;
 
        bnxt_hwrm_fw_set_time(bp);
 
@@ -1632,15 +1648,16 @@ static int bnxt_flash_package_from_file(struct net_device *dev,
                        memcpy(kmem, fw->data, fw->size);
                        modify.host_src_addr = cpu_to_le64(dma_handle);
 
-                       rc = hwrm_send_message(bp, &modify, sizeof(modify),
-                                              FLASH_PACKAGE_TIMEOUT);
+                       hwrm_err = hwrm_send_message(bp, &modify,
+                                                    sizeof(modify),
+                                                    FLASH_PACKAGE_TIMEOUT);
                        dma_free_coherent(&bp->pdev->dev, fw->size, kmem,
                                          dma_handle);
                }
        }
        release_firmware(fw);
-       if (rc)
-               return rc;
+       if (rc || hwrm_err)
+               goto err_exit;
 
        if ((install_type & 0xffff) == 0)
                install_type >>= 16;
@@ -1648,12 +1665,10 @@ static int bnxt_flash_package_from_file(struct net_device *dev,
        install.install_type = cpu_to_le32(install_type);
 
        mutex_lock(&bp->hwrm_cmd_lock);
-       rc = _hwrm_send_message(bp, &install, sizeof(install),
-                               INSTALL_PACKAGE_TIMEOUT);
-       if (rc) {
-               rc = -EOPNOTSUPP;
+       hwrm_err = _hwrm_send_message(bp, &install, sizeof(install),
+                                     INSTALL_PACKAGE_TIMEOUT);
+       if (hwrm_err)
                goto flash_pkg_exit;
-       }
 
        if (resp->error_code) {
                u8 error_code = ((struct hwrm_err_output *)resp)->cmd_err;
@@ -1661,12 +1676,11 @@ static int bnxt_flash_package_from_file(struct net_device *dev,
                if (error_code == NVM_INSTALL_UPDATE_CMD_ERR_CODE_FRAG_ERR) {
                        install.flags |= cpu_to_le16(
                               NVM_INSTALL_UPDATE_REQ_FLAGS_ALLOWED_TO_DEFRAG);
-                       rc = _hwrm_send_message(bp, &install, sizeof(install),
-                                               INSTALL_PACKAGE_TIMEOUT);
-                       if (rc) {
-                               rc = -EOPNOTSUPP;
+                       hwrm_err = _hwrm_send_message(bp, &install,
+                                                     sizeof(install),
+                                                     INSTALL_PACKAGE_TIMEOUT);
+                       if (hwrm_err)
                                goto flash_pkg_exit;
-                       }
                }
        }
 
@@ -1677,6 +1691,14 @@ static int bnxt_flash_package_from_file(struct net_device *dev,
        }
 flash_pkg_exit:
        mutex_unlock(&bp->hwrm_cmd_lock);
+err_exit:
+       if (hwrm_err == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) {
+               netdev_info(dev,
+                           "PF does not have admin privileges to flash the device\n");
+               rc = -EACCES;
+       } else if (hwrm_err) {
+               rc = -EOPNOTSUPP;
+       }
        return rc;
 }