phy: marvell: comphy: Convert internal SMCC firmware return codes to errno
authorPali Rohár <pali@kernel.org>
Wed, 2 Sep 2020 14:43:43 +0000 (16:43 +0200)
committerLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Fri, 2 Oct 2020 13:29:41 +0000 (14:29 +0100)
Driver ->power_on and ->power_off callbacks leaks internal SMCC firmware
return codes to phy caller. This patch converts SMCC error codes to
standard linux errno codes. Include file linux/arm-smccc.h already provides
defines for SMCC error codes, so use them instead of custom driver defines.
Note that return value is signed 32bit, but stored in unsigned long type
with zero padding.

Tested-by: Tomasz Maciej Nowak <tmn505@gmail.com>
Link: https://lore.kernel.org/r/20200902144344.16684-2-pali@kernel.org
Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Rob Herring <robh@kernel.org>
drivers/phy/marvell/phy-mvebu-a3700-comphy.c
drivers/phy/marvell/phy-mvebu-cp110-comphy.c

index 1a138be..810f25a 100644 (file)
@@ -26,7 +26,6 @@
 #define COMPHY_SIP_POWER_ON                    0x82000001
 #define COMPHY_SIP_POWER_OFF                   0x82000002
 #define COMPHY_SIP_PLL_LOCK                    0x82000003
-#define COMPHY_FW_NOT_SUPPORTED                        (-1)
 
 #define COMPHY_FW_MODE_SATA                    0x1
 #define COMPHY_FW_MODE_SGMII                   0x2
@@ -112,10 +111,19 @@ static int mvebu_a3700_comphy_smc(unsigned long function, unsigned long lane,
                                  unsigned long mode)
 {
        struct arm_smccc_res res;
+       s32 ret;
 
        arm_smccc_smc(function, lane, mode, 0, 0, 0, 0, 0, &res);
+       ret = res.a0;
 
-       return res.a0;
+       switch (ret) {
+       case SMCCC_RET_SUCCESS:
+               return 0;
+       case SMCCC_RET_NOT_SUPPORTED:
+               return -EOPNOTSUPP;
+       default:
+               return -EINVAL;
+       }
 }
 
 static int mvebu_a3700_comphy_get_fw_mode(int lane, int port,
@@ -220,7 +228,7 @@ static int mvebu_a3700_comphy_power_on(struct phy *phy)
        }
 
        ret = mvebu_a3700_comphy_smc(COMPHY_SIP_POWER_ON, lane->id, fw_param);
-       if (ret == COMPHY_FW_NOT_SUPPORTED)
+       if (ret == -EOPNOTSUPP)
                dev_err(lane->dev,
                        "unsupported SMC call, try updating your firmware\n");
 
index e41367f..53ad127 100644 (file)
 
 #define COMPHY_SIP_POWER_ON    0x82000001
 #define COMPHY_SIP_POWER_OFF   0x82000002
-#define COMPHY_FW_NOT_SUPPORTED        (-1)
 
 /*
  * A lane is described by the following bitfields:
@@ -273,10 +272,19 @@ static int mvebu_comphy_smc(unsigned long function, unsigned long phys,
                            unsigned long lane, unsigned long mode)
 {
        struct arm_smccc_res res;
+       s32 ret;
 
        arm_smccc_smc(function, phys, lane, mode, 0, 0, 0, 0, &res);
+       ret = res.a0;
 
-       return res.a0;
+       switch (ret) {
+       case SMCCC_RET_SUCCESS:
+               return 0;
+       case SMCCC_RET_NOT_SUPPORTED:
+               return -EOPNOTSUPP;
+       default:
+               return -EINVAL;
+       }
 }
 
 static int mvebu_comphy_get_mode(bool fw_mode, int lane, int port,
@@ -819,7 +827,7 @@ static int mvebu_comphy_power_on(struct phy *phy)
        if (!ret)
                return ret;
 
-       if (ret == COMPHY_FW_NOT_SUPPORTED)
+       if (ret == -EOPNOTSUPP)
                dev_err(priv->dev,
                        "unsupported SMC call, try updating your firmware\n");