powerpc/opal: Add inline function to get rc from an ASYNC_COMP opal_msg
authorSuraj Jitindar Singh <sjitindarsingh@gmail.com>
Wed, 29 Jun 2016 03:38:38 +0000 (13:38 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 29 Jun 2016 07:33:18 +0000 (17:33 +1000)
An opal_msg of type OPAL_MSG_ASYNC_COMP contains the return code in the
params[1] struct member. However this isn't intuitive or obvious when
reading the code and requires that a user look at the skiboot
documentation or opal-api.h to verify this.

Add an inline function to get the return code from an opal_msg and update
call sites accordingly.

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/opal.h
arch/powerpc/platforms/powernv/opal-sensor.c
arch/powerpc/platforms/powernv/opal-sysparam.c
drivers/i2c/busses/i2c-opal.c
drivers/leds/leds-powernv.c
drivers/mtd/devices/powernv_flash.c
drivers/rtc/rtc-opal.c

index fa71fea3b6eeb59bfa97828d8304537c175a8d7d..9ab52e27cf712e26a8088af8f22ef00061cf5513 100644 (file)
@@ -282,6 +282,14 @@ extern int opal_error_code(int rc);
 
 ssize_t opal_msglog_copy(char *to, loff_t pos, size_t count);
 
+static inline int opal_get_async_rc(struct opal_msg msg)
+{
+       if (msg.msg_type != OPAL_MSG_ASYNC_COMP)
+               return OPAL_PARAMETER;
+       else
+               return be64_to_cpu(msg.params[1]);
+}
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_OPAL_H */
index a06059df9239202d660a5f7579034b715f9ee18a..308efd170c271182a940e649007fc1218a71bb79 100644 (file)
@@ -55,7 +55,7 @@ int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data)
                        goto out_token;
                }
 
-               ret = opal_error_code(be64_to_cpu(msg.params[1]));
+               ret = opal_error_code(opal_get_async_rc(msg));
                *sensor_data = be32_to_cpu(data);
                break;
 
index afe66c576a385f4204860766fa69b9d6fd3e590f..23fb6647dced6b49967f1e977dd57cf91257526d 100644 (file)
@@ -67,7 +67,7 @@ static ssize_t opal_get_sys_param(u32 param_id, u32 length, void *buffer)
                goto out_token;
        }
 
-       ret = opal_error_code(be64_to_cpu(msg.params[1]));
+       ret = opal_error_code(opal_get_async_rc(msg));
 
 out_token:
        opal_async_release_token(token);
@@ -103,7 +103,7 @@ static int opal_set_sys_param(u32 param_id, u32 length, void *buffer)
                goto out_token;
        }
 
-       ret = opal_error_code(be64_to_cpu(msg.params[1]));
+       ret = opal_error_code(opal_get_async_rc(msg));
 
 out_token:
        opal_async_release_token(token);
index 75dd6d04124128957e95a2bf8a0d1b18eeda34dc..11e2a1fc10e9c8f55d7bc1333e8993ebb23c6a54 100644 (file)
@@ -71,7 +71,7 @@ static int i2c_opal_send_request(u32 bus_id, struct opal_i2c_request *req)
        if (rc)
                goto exit;
 
-       rc = be64_to_cpu(msg.params[1]);
+       rc = opal_get_async_rc(msg);
        if (rc != OPAL_SUCCESS) {
                rc = i2c_opal_translate_error(rc);
                goto exit;
index dfb8bd390125357fd6e1660d4257ba564a5ab72c..b2a98c7b521b2208dc0234a2b0803601b6d03fc8 100644 (file)
@@ -118,7 +118,7 @@ static int powernv_led_set(struct powernv_led_data *powernv_led,
                goto out_token;
        }
 
-       rc = be64_to_cpu(msg.params[1]);
+       rc = opal_get_async_rc(msg);
        if (rc != OPAL_SUCCESS)
                dev_err(dev, "%s : OAPL async call returned failed [rc=%d]\n",
                        __func__, rc);
index d5b870b3fd4ed9b93accbefb2639a445048a21c8..f5396f26ddb48c38a2d74e8f070be912e8ff461f 100644 (file)
@@ -95,7 +95,7 @@ static int powernv_flash_async_op(struct mtd_info *mtd, enum flash_op op,
                return -EIO;
        }
 
-       rc = be64_to_cpu(msg.params[1]);
+       rc = opal_get_async_rc(msg);
        if (rc == OPAL_SUCCESS) {
                rc = 0;
                if (retlen)
index 9c18d6fd8107599914558b0d3fe87a80ac38fb1c..ea20f627dabea3617b52e9ad1476245f42a5fc94 100644 (file)
@@ -134,7 +134,7 @@ static int opal_get_tpo_time(struct device *dev, struct rtc_wkalrm *alarm)
                goto exit;
        }
 
-       rc = be64_to_cpu(msg.params[1]);
+       rc = opal_get_async_rc(msg);
        if (rc != OPAL_SUCCESS) {
                rc = -EIO;
                goto exit;
@@ -181,7 +181,7 @@ static int opal_set_tpo_time(struct device *dev, struct rtc_wkalrm *alarm)
                goto exit;
        }
 
-       rc = be64_to_cpu(msg.params[1]);
+       rc = opal_get_async_rc(msg);
        if (rc != OPAL_SUCCESS)
                rc = -EIO;