powerpc/powernv: convert codes returned by OPAL calls
authorCédric Le Goater <clg@fr.ibm.com>
Mon, 30 Mar 2015 10:06:09 +0000 (12:06 +0200)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 31 Mar 2015 03:50:33 +0000 (14:50 +1100)
OPAL has its own list of return codes. The patch provides a translation
of such codes in errnos for the opal_sensor_read call, and possibly
others if needed.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.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.c

index c08de77f398af7b835412dc73c97758b4b20c70e..fde90bacc65ef09b27975dacb2554242ddf97177 100644 (file)
@@ -247,6 +247,8 @@ struct opal_sg_list *opal_vmalloc_to_sg_list(void *vmalloc_addr,
                                             unsigned long vmalloc_size);
 void opal_free_sg_list(struct opal_sg_list *sg);
 
+extern int opal_error_code(int rc);
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_OPAL_H */
index 4ab67ef7abc9d8a0d07079795f3801b3d62e035f..e9c5d8f33d4c025223e92f6500e3e8280b71f30e 100644 (file)
@@ -46,8 +46,10 @@ int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data)
 
        mutex_lock(&opal_sensor_mutex);
        ret = opal_sensor_read(sensor_hndl, token, &data);
-       if (ret != OPAL_ASYNC_COMPLETION)
+       if (ret != OPAL_ASYNC_COMPLETION) {
+               ret = opal_error_code(ret);
                goto out_token;
+       }
 
        ret = opal_async_wait_response(token, &msg);
        if (ret) {
@@ -57,7 +59,7 @@ int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data)
        }
 
        *sensor_data = be32_to_cpu(data);
-       ret = be64_to_cpu(msg.params[1]);
+       ret = opal_error_code(be64_to_cpu(msg.params[1]));
 
 out_token:
        mutex_unlock(&opal_sensor_mutex);
index d403b2b0862675d0321ad3014401f4baac1fee53..3fb981c0ca8046757f47e9d40dfd8d594ce66790 100644 (file)
@@ -931,6 +931,25 @@ void opal_free_sg_list(struct opal_sg_list *sg)
        }
 }
 
+int opal_error_code(int rc)
+{
+       switch (rc) {
+       case OPAL_SUCCESS:              return 0;
+
+       case OPAL_PARAMETER:            return -EINVAL;
+       case OPAL_ASYNC_COMPLETION:     return -EINPROGRESS;
+       case OPAL_BUSY_EVENT:           return -EBUSY;
+       case OPAL_NO_MEM:               return -ENOMEM;
+
+       case OPAL_UNSUPPORTED:          return -EIO;
+       case OPAL_HARDWARE:             return -EIO;
+       case OPAL_INTERNAL_ERROR:       return -EIO;
+       default:
+               pr_err("%s: unexpected OPAL error %d\n", __func__, rc);
+               return -EIO;
+       }
+}
+
 EXPORT_SYMBOL_GPL(opal_poll_events);
 EXPORT_SYMBOL_GPL(opal_rtc_read);
 EXPORT_SYMBOL_GPL(opal_rtc_write);