All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read
@ 2015-03-25 17:50 Cédric Le Goater
  2015-03-25 23:07 ` Stewart Smith
  0 siblings, 1 reply; 25+ messages in thread
From: Cédric Le Goater @ 2015-03-25 17:50 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Stewart Smith, Neelesh Gupta, Cédric Le Goater, skiboot

Currently, when a sensor value is read, the kernel calls OPAL, which in
turn builds a message for the FSP, and waits for a message back. 

The new device tree for OPAL sensors [1] adds new sensors that can be 
read synchronously (core temperatures for instance) and that don't need 
to wait for a response.

This patch modifies the opal call to accept an OPAL_SUCCESS return value
and cover the case above.

[1] https://lists.ozlabs.org/pipermail/skiboot/2015-March/000639.html

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---

 We still uselessly reserve a token (for the response) and take a
 lock, which might raise the need of a new 'opal_sensor_read_sync' 
 call.

 arch/powerpc/platforms/powernv/opal-sensor.c |   29 +++++++++++++++++---------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/opal-sensor.c b/arch/powerpc/platforms/powernv/opal-sensor.c
index 4ab67ef7abc9..99d6d9a371ab 100644
--- a/arch/powerpc/platforms/powernv/opal-sensor.c
+++ b/arch/powerpc/platforms/powernv/opal-sensor.c
@@ -46,18 +46,27 @@ 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)
-		goto out_token;
+	switch (ret) {
+	case OPAL_ASYNC_COMPLETION:
+		ret = opal_async_wait_response(token, &msg);
+		if (ret) {
+			pr_err("%s: Failed to wait for the async response, %d\n",
+			       __func__, ret);
+			goto out_token;
+		}
 
-	ret = opal_async_wait_response(token, &msg);
-	if (ret) {
-		pr_err("%s: Failed to wait for the async response, %d\n",
-				__func__, ret);
-		goto out_token;
-	}
+		ret = be64_to_cpu(msg.params[1]);
+
+		*sensor_data = be32_to_cpu(data);
+		break;
 
-	*sensor_data = be32_to_cpu(data);
-	ret = be64_to_cpu(msg.params[1]);
+	case OPAL_SUCCESS:
+		*sensor_data = be32_to_cpu(data);
+		break;
+
+	default:
+		break;
+	}
 
 out_token:
 	mutex_unlock(&opal_sensor_mutex);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read
  2015-03-25 17:50 [PATCH] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read Cédric Le Goater
@ 2015-03-25 23:07 ` Stewart Smith
  2015-03-26  9:44   ` Cedric Le Goater
  0 siblings, 1 reply; 25+ messages in thread
From: Stewart Smith @ 2015-03-25 23:07 UTC (permalink / raw)
  To: Cédric Le Goater, linuxppc-dev
  Cc: Neelesh Gupta, Cédric Le Goater, skiboot

C=C3=A9dric Le Goater <clg@fr.ibm.com> writes:
> Currently, when a sensor value is read, the kernel calls OPAL, which in
> turn builds a message for the FSP, and waits for a message back.=20
>
> The new device tree for OPAL sensors [1] adds new sensors that can be=20
> read synchronously (core temperatures for instance) and that don't need=20
> to wait for a response.
>
> This patch modifies the opal call to accept an OPAL_SUCCESS return value
> and cover the case above.
>
> [1] https://lists.ozlabs.org/pipermail/skiboot/2015-March/000639.html
>
> Signed-off-by: C=C3=A9dric Le Goater <clg@fr.ibm.com>
> ---
>
>  We still uselessly reserve a token (for the response) and take a
>  lock, which might raise the need of a new 'opal_sensor_read_sync'=20
>  call.

Actually.... why do we take a lock around the OPAL calls at all?

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read
  2015-03-25 23:07 ` Stewart Smith
@ 2015-03-26  9:44   ` Cedric Le Goater
  2015-03-26 12:58     ` Cedric Le Goater
  2015-03-27  6:05     ` [PATCH] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read Stewart Smith
  0 siblings, 2 replies; 25+ messages in thread
From: Cedric Le Goater @ 2015-03-26  9:44 UTC (permalink / raw)
  To: Stewart Smith, linuxppc-dev; +Cc: Neelesh Gupta, skiboot

On 03/26/2015 12:07 AM, Stewart Smith wrote:
> Cédric Le Goater <clg@fr.ibm.com> writes:
>> Currently, when a sensor value is read, the kernel calls OPAL, which in
>> turn builds a message for the FSP, and waits for a message back. 
>>
>> The new device tree for OPAL sensors [1] adds new sensors that can be 
>> read synchronously (core temperatures for instance) and that don't need 
>> to wait for a response.
>>
>> This patch modifies the opal call to accept an OPAL_SUCCESS return value
>> and cover the case above.
>>
>> [1] https://lists.ozlabs.org/pipermail/skiboot/2015-March/000639.html
>>
>> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
>> ---
>>
>>  We still uselessly reserve a token (for the response) and take a
>>  lock, which might raise the need of a new 'opal_sensor_read_sync' 
>>  call.
> 
> Actually.... why do we take a lock around the OPAL calls at all?

The sensor service in OPAL only handles one FSP request at a time and 
returns OPAL_BUSY if one is already in progress. The lock covers this case 
but we could also remove it return EBUSY to the driver or even retry the 
call. That might be dangerous though. 

Changing OPAL to handle simultaneously multiple requests does not seem really 
necessary, it won't speed up the communication with the FSP and that is the
main bottleneck.

C.


 

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read
  2015-03-26  9:44   ` Cedric Le Goater
@ 2015-03-26 12:58     ` Cedric Le Goater
  2015-03-26 16:04       ` [PATCH v2 1/3] powerpc/powernv: convert codes returned by OPAL calls Cédric Le Goater
  2015-03-27  6:05     ` [PATCH] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read Stewart Smith
  1 sibling, 1 reply; 25+ messages in thread
From: Cedric Le Goater @ 2015-03-26 12:58 UTC (permalink / raw)
  To: Stewart Smith, linuxppc-dev; +Cc: Neelesh Gupta, skiboot

On 03/26/2015 10:44 AM, Cedric Le Goater wrote:
> On 03/26/2015 12:07 AM, Stewart Smith wrote:
>> Cédric Le Goater <clg@fr.ibm.com> writes:
>>> Currently, when a sensor value is read, the kernel calls OPAL, which in
>>> turn builds a message for the FSP, and waits for a message back. 
>>>
>>> The new device tree for OPAL sensors [1] adds new sensors that can be 
>>> read synchronously (core temperatures for instance) and that don't need 
>>> to wait for a response.
>>>
>>> This patch modifies the opal call to accept an OPAL_SUCCESS return value
>>> and cover the case above.
>>>
>>> [1] https://lists.ozlabs.org/pipermail/skiboot/2015-March/000639.html
>>>
>>> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
>>> ---
>>>
>>>  We still uselessly reserve a token (for the response) and take a
>>>  lock, which might raise the need of a new 'opal_sensor_read_sync' 
>>>  call.
>>
>> Actually.... why do we take a lock around the OPAL calls at all?
> 
> The sensor service in OPAL only handles one FSP request at a time and 
> returns OPAL_BUSY if one is already in progress. The lock covers this case 
> but we could also remove it return EBUSY to the driver or even retry the 
> call. That might be dangerous though. 
> 
> Changing OPAL to handle simultaneously multiple requests does not seem really 
> necessary, it won't speed up the communication with the FSP and that is the
> main bottleneck.

opal_get_sensor_data() is mixing OPAL return codes and errnos. I will send
a v2 addressing this problem first.

C. 

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v2 1/3] powerpc/powernv: convert codes returned by OPAL calls
  2015-03-26 12:58     ` Cedric Le Goater
@ 2015-03-26 16:04       ` Cédric Le Goater
  2015-03-26 16:04         ` [PATCH v2 2/3] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read Cédric Le Goater
                           ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Cédric Le Goater @ 2015-03-26 16:04 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Stewart Smith, Neelesh Gupta, Cédric Le Goater, skiboot

OPAL has its own list of return codes. The patch provides a translation
of such codes in errnos for the opal_sensor_read call.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---
 arch/powerpc/platforms/powernv/opal-sensor.c |   37 ++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

Index: linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
===================================================================
--- linux.git.orig/arch/powerpc/platforms/powernv/opal-sensor.c
+++ linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
@@ -26,6 +26,38 @@
 
 static DEFINE_MUTEX(opal_sensor_mutex);
 
+
+/*
+ * opal_sensor_read() return codes
+ *
+ * OPAL_PARAMETER - invalid sensor handler
+ * OPAL_UNSUPPORTED - plateform does not support reading sensors.
+ *
+ *     in case of communication with the FSP on IBM systems
+ *
+ * OPAL_ASYNC_COMPLETION - a request was sent and an async completion will
+ *	be triggered with the @token argument
+ * OPAL_PARTIAL - the request completed but the data returned is invalid
+ * OPAL_BUSY_EVENT - a previous request is still pending
+ * OPAL_NO_MEM - allocation failed
+ * OPAL_INTERNAL_ERROR - communication failure with the FSP
+ * OPAL_HARDWARE - FSP is not available
+ */
+static int convert_opal_code(int ret)
+{
+	switch (ret) {
+	case OPAL_SUCCESS:		return 0;
+	case OPAL_PARAMETER:		return -EINVAL;
+	case OPAL_UNSUPPORTED:		return -ENOSYS;
+	case OPAL_ASYNC_COMPLETION:	return -EAGAIN;
+	case OPAL_BUSY_EVENT:		return -EBUSY;
+	case OPAL_NO_MEM:		return -ENOMEM;
+	case OPAL_HARDWARE:		return -ENOENT;
+	case OPAL_INTERNAL_ERROR:	return -EIO;
+	default:			return -EIO;
+	}
+}
+
 /*
  * This will return sensor information to driver based on the requested sensor
  * handle. A handle is an opaque id for the powernv, read by the driver from the
@@ -46,8 +78,10 @@ int opal_get_sensor_data(u32 sensor_hndl
 
 	mutex_lock(&opal_sensor_mutex);
 	ret = opal_sensor_read(sensor_hndl, token, &data);
-	if (ret != OPAL_ASYNC_COMPLETION)
+	if (ret != OPAL_ASYNC_COMPLETION) {
+		ret = convert_opal_code(ret);
 		goto out_token;
+	}
 
 	ret = opal_async_wait_response(token, &msg);
 	if (ret) {
@@ -58,6 +92,7 @@ int opal_get_sensor_data(u32 sensor_hndl
 
 	*sensor_data = be32_to_cpu(data);
 	ret = be64_to_cpu(msg.params[1]);
+	ret = convert_opal_code(ret);
 
 out_token:
 	mutex_unlock(&opal_sensor_mutex);

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v2 2/3] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read
  2015-03-26 16:04       ` [PATCH v2 1/3] powerpc/powernv: convert codes returned by OPAL calls Cédric Le Goater
@ 2015-03-26 16:04         ` Cédric Le Goater
  2015-03-26 16:04         ` [PATCH v2 3/3] powerpc/powernv: remove opal_sensor_mutex Cédric Le Goater
  2015-03-27  9:59         ` [v2,1/3] powerpc/powernv: convert codes returned by OPAL calls Michael Ellerman
  2 siblings, 0 replies; 25+ messages in thread
From: Cédric Le Goater @ 2015-03-26 16:04 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Stewart Smith, Neelesh Gupta, Cédric Le Goater, skiboot

Currently, when a sensor value is read, the kernel calls OPAL, which in
turn builds a message for the FSP, and waits for a message back. 

The new device tree for OPAL sensors [1] adds new sensors that can be 
read synchronously (core temperatures for instance) and that don't need 
to wait for a response.

This patch modifies the opal call to accept an OPAL_SUCCESS return value
and cover the case above.

[1] https://lists.ozlabs.org/pipermail/skiboot/2015-March/000639.html

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---

 We still uselessly reserve a token (for the response) and take a
 lock, which might raise the need of a new 'opal_sensor_read_sync' 
 call.

 arch/powerpc/platforms/powernv/opal-sensor.c |   31 ++++++++++++++++-----------
 1 file changed, 19 insertions(+), 12 deletions(-)

Index: linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
===================================================================
--- linux.git.orig/arch/powerpc/platforms/powernv/opal-sensor.c
+++ linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
@@ -78,21 +78,28 @@ int opal_get_sensor_data(u32 sensor_hndl
 
 	mutex_lock(&opal_sensor_mutex);
 	ret = opal_sensor_read(sensor_hndl, token, &data);
-	if (ret != OPAL_ASYNC_COMPLETION) {
+	switch (ret) {
+	case OPAL_ASYNC_COMPLETION:
+		ret = opal_async_wait_response(token, &msg);
+		if (ret) {
+			pr_err("%s: Failed to wait for the async response, %d\n",
+			       __func__, ret);
+			goto out_token;
+		}
+
+		*sensor_data = be32_to_cpu(data);
+		ret = be64_to_cpu(msg.params[1]);
 		ret = convert_opal_code(ret);
-		goto out_token;
-	}
+		break;
 
-	ret = opal_async_wait_response(token, &msg);
-	if (ret) {
-		pr_err("%s: Failed to wait for the async response, %d\n",
-				__func__, ret);
-		goto out_token;
-	}
+	case OPAL_SUCCESS:
+		*sensor_data = be32_to_cpu(data);
+		break;
 
-	*sensor_data = be32_to_cpu(data);
-	ret = be64_to_cpu(msg.params[1]);
-	ret = convert_opal_code(ret);
+	default:
+		ret = convert_opal_code(ret);
+		break;
+	}
 
 out_token:
 	mutex_unlock(&opal_sensor_mutex);

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v2 3/3] powerpc/powernv: remove opal_sensor_mutex
  2015-03-26 16:04       ` [PATCH v2 1/3] powerpc/powernv: convert codes returned by OPAL calls Cédric Le Goater
  2015-03-26 16:04         ` [PATCH v2 2/3] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read Cédric Le Goater
@ 2015-03-26 16:04         ` Cédric Le Goater
  2015-03-27  9:59         ` [v2,1/3] powerpc/powernv: convert codes returned by OPAL calls Michael Ellerman
  2 siblings, 0 replies; 25+ messages in thread
From: Cédric Le Goater @ 2015-03-26 16:04 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Stewart Smith, Neelesh Gupta, Cédric Le Goater, skiboot

The opal sensor mutex protects the opal_sensor_read call which
can return a OPAL_BUSY code on IBM Power systems if a previous 
request is in progress.

This can be handled at user level with a retry.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---
 arch/powerpc/platforms/powernv/opal-sensor.c |    5 -----
 1 file changed, 5 deletions(-)

Index: linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
===================================================================
--- linux.git.orig/arch/powerpc/platforms/powernv/opal-sensor.c
+++ linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
@@ -24,9 +24,6 @@
 #include <asm/opal.h>
 #include <asm/machdep.h>
 
-static DEFINE_MUTEX(opal_sensor_mutex);
-
-
 /*
  * opal_sensor_read() return codes
  *
@@ -76,7 +73,6 @@ int opal_get_sensor_data(u32 sensor_hndl
 		goto out;
 	}
 
-	mutex_lock(&opal_sensor_mutex);
 	ret = opal_sensor_read(sensor_hndl, token, &data);
 	switch (ret) {
 	case OPAL_ASYNC_COMPLETION:
@@ -102,7 +98,6 @@ int opal_get_sensor_data(u32 sensor_hndl
 	}
 
 out_token:
-	mutex_unlock(&opal_sensor_mutex);
 	opal_async_release_token(token);
 out:
 	return ret;

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read
  2015-03-26  9:44   ` Cedric Le Goater
  2015-03-26 12:58     ` Cedric Le Goater
@ 2015-03-27  6:05     ` Stewart Smith
  1 sibling, 0 replies; 25+ messages in thread
From: Stewart Smith @ 2015-03-27  6:05 UTC (permalink / raw)
  To: Cedric Le Goater, linuxppc-dev; +Cc: Neelesh Gupta, skiboot

Cedric Le Goater <clg@fr.ibm.com> writes:
> The sensor service in OPAL only handles one FSP request at a time and 
> returns OPAL_BUSY if one is already in progress. The lock covers this case 
> but we could also remove it return EBUSY to the driver or even retry the 
> call. That might be dangerous though. 

Retrying the call should be okay.

Just because FSP wants to do things serially doesn't mean non-FSP does :)

> Changing OPAL to handle simultaneously multiple requests does not seem really 
> necessary, it won't speed up the communication with the FSP and that is the
> main bottleneck.

Only on FSP systems though, and all of the OpenPower machines don't have
FSPs :)

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [v2,1/3] powerpc/powernv: convert codes returned by OPAL calls
  2015-03-26 16:04       ` [PATCH v2 1/3] powerpc/powernv: convert codes returned by OPAL calls Cédric Le Goater
  2015-03-26 16:04         ` [PATCH v2 2/3] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read Cédric Le Goater
  2015-03-26 16:04         ` [PATCH v2 3/3] powerpc/powernv: remove opal_sensor_mutex Cédric Le Goater
@ 2015-03-27  9:59         ` Michael Ellerman
  2015-03-27 10:36           ` [Skiboot] [v2, 1/3] " Benjamin Herrenschmidt
                             ` (4 more replies)
  2 siblings, 5 replies; 25+ messages in thread
From: Michael Ellerman @ 2015-03-27  9:59 UTC (permalink / raw)
  To: Cédric Le Goater, linuxppc-dev
  Cc: Stewart Smith, Neelesh Gupta, Cédric Le Goater, skiboot

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2587 bytes --]

On Thu, 2015-26-03 at 16:04:45 UTC, =?utf-8?q?C=C3=A9dric_Le_Goater?= wrote:
> OPAL has its own list of return codes. The patch provides a translation
> of such codes in errnos for the opal_sensor_read call.
> 
> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
> ---
>  arch/powerpc/platforms/powernv/opal-sensor.c |   37 ++++++++++++++++++++++++++-
>  1 file changed, 36 insertions(+), 1 deletion(-)
> 
> Index: linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
> ===================================================================
> --- linux.git.orig/arch/powerpc/platforms/powernv/opal-sensor.c
> +++ linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
> @@ -26,6 +26,38 @@
  
> +static int convert_opal_code(int ret)
> +{
> +	switch (ret) {
> +	case OPAL_SUCCESS:		return 0;
> +	case OPAL_PARAMETER:		return -EINVAL;
> +	case OPAL_UNSUPPORTED:		return -ENOSYS;
> +	case OPAL_ASYNC_COMPLETION:	return -EAGAIN;
> +	case OPAL_BUSY_EVENT:		return -EBUSY;
> +	case OPAL_NO_MEM:		return -ENOMEM;
> +	case OPAL_HARDWARE:		return -ENOENT;
> +	case OPAL_INTERNAL_ERROR:	return -EIO;
> +	default:			return -EIO;
> +	}
> +}

That looks a bit familiar :)

static int rtas_error_rc(int rtas_rc)
{
	int rc;

	switch (rtas_rc) {
		case -1: 		/* Hardware Error */
			rc = -EIO;
			break;
		case -3:		/* Bad indicator/domain/etc */
			rc = -EINVAL;
			break;
		case -9000:		/* Isolation error */
			rc = -EFAULT;
			break;
		case -9001:		/* Outstanding TCE/PTE */
			rc = -EEXIST;
			break;
		case -9002:		/* No usable slot */
			rc = -ENODEV;
			break;
		default:
			printk(KERN_ERR "%s: unexpected RTAS error %d\n",
					__func__, rtas_rc);
			rc = -ERANGE;
			break;
	}
	return rc;
}


But I guess we still should have it.

Can you put it in opal.h and give it a better name, maybe opal_error_code() ?

>  /*
>   * This will return sensor information to driver based on the requested sensor
>   * handle. A handle is an opaque id for the powernv, read by the driver from the
> @@ -46,8 +78,10 @@ int opal_get_sensor_data(u32 sensor_hndl
>  
>  	mutex_lock(&opal_sensor_mutex);
>  	ret = opal_sensor_read(sensor_hndl, token, &data);
> -	if (ret != OPAL_ASYNC_COMPLETION)
> +	if (ret != OPAL_ASYNC_COMPLETION) {
> +		ret = convert_opal_code(ret);
>  		goto out_token;
> +	}
>  
>  	ret = opal_async_wait_response(token, &msg);
>  	if (ret) {
> @@ -58,6 +92,7 @@ int opal_get_sensor_data(u32 sensor_hndl
>  
>  	*sensor_data = be32_to_cpu(data);
>  	ret = be64_to_cpu(msg.params[1]);
> +	ret = convert_opal_code(ret);

I'd do:
	ret = convert_opal_code(be64_to_cpu(msg.params[1]));

cheers

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Skiboot] [v2, 1/3] powerpc/powernv: convert codes returned by OPAL calls
  2015-03-27  9:59         ` [v2,1/3] powerpc/powernv: convert codes returned by OPAL calls Michael Ellerman
@ 2015-03-27 10:36           ` Benjamin Herrenschmidt
  2015-03-27 10:39             ` Cedric Le Goater
  2015-03-27 10:45           ` [v2,1/3] " Cedric Le Goater
                             ` (3 subsequent siblings)
  4 siblings, 1 reply; 25+ messages in thread
From: Benjamin Herrenschmidt @ 2015-03-27 10:36 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: skiboot, Cédric Le Goater, linuxppc-dev

On Fri, 2015-03-27 at 20:59 +1100, Michael Ellerman wrote:
> 
> Can you put it in opal.h and give it a better name, maybe
> opal_error_code() ?

Do we want it to be inlined all the time ? Feels more like something we
should have in opal.c

Also we only want to call it when we "forward" the error code up the
food chain, there are a number of cases where we look for specific OPAL
error codes.

Cheers,
Ben.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Skiboot] [v2, 1/3] powerpc/powernv: convert codes returned by OPAL calls
  2015-03-27 10:36           ` [Skiboot] [v2, 1/3] " Benjamin Herrenschmidt
@ 2015-03-27 10:39             ` Cedric Le Goater
  0 siblings, 0 replies; 25+ messages in thread
From: Cedric Le Goater @ 2015-03-27 10:39 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Michael Ellerman; +Cc: skiboot, linuxppc-dev

On 03/27/2015 11:36 AM, Benjamin Herrenschmidt wrote:
> On Fri, 2015-03-27 at 20:59 +1100, Michael Ellerman wrote:
>>
>> Can you put it in opal.h and give it a better name, maybe
>> opal_error_code() ?
> 
> Do we want it to be inlined all the time ? Feels more like something we
> should have in opal.c
> 
> Also we only want to call it when we "forward" the error code up the
> food chain, there are a number of cases where we look for specific OPAL
> error codes.

yes. the forward is not systematic. opal.c looks like a better place.

-ERANGE looks also better when the return code is unexpected. 

C.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [v2,1/3] powerpc/powernv: convert codes returned by OPAL calls
  2015-03-27  9:59         ` [v2,1/3] powerpc/powernv: convert codes returned by OPAL calls Michael Ellerman
  2015-03-27 10:36           ` [Skiboot] [v2, 1/3] " Benjamin Herrenschmidt
@ 2015-03-27 10:45           ` Cedric Le Goater
  2015-03-27 16:39           ` [PATCH v3 1/3] " Cédric Le Goater
                             ` (2 subsequent siblings)
  4 siblings, 0 replies; 25+ messages in thread
From: Cedric Le Goater @ 2015-03-27 10:45 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev; +Cc: Stewart Smith, Neelesh Gupta, skiboot

On 03/27/2015 10:59 AM, Michael Ellerman wrote:
> On Thu, 2015-26-03 at 16:04:45 UTC, =?utf-8?q?C=C3=A9dric_Le_Goater?= wrote:
>> OPAL has its own list of return codes. The patch provides a translation
>> of such codes in errnos for the opal_sensor_read call.
>>
>> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
>> ---
>>  arch/powerpc/platforms/powernv/opal-sensor.c |   37 ++++++++++++++++++++++++++-
>>  1 file changed, 36 insertions(+), 1 deletion(-)
>>
>> Index: linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
>> ===================================================================
>> --- linux.git.orig/arch/powerpc/platforms/powernv/opal-sensor.c
>> +++ linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
>> @@ -26,6 +26,38 @@
>   
>> +static int convert_opal_code(int ret)
>> +{
>> +	switch (ret) {
>> +	case OPAL_SUCCESS:		return 0;
>> +	case OPAL_PARAMETER:		return -EINVAL;
>> +	case OPAL_UNSUPPORTED:		return -ENOSYS;
>> +	case OPAL_ASYNC_COMPLETION:	return -EAGAIN;
>> +	case OPAL_BUSY_EVENT:		return -EBUSY;
>> +	case OPAL_NO_MEM:		return -ENOMEM;
>> +	case OPAL_HARDWARE:		return -ENOENT;
>> +	case OPAL_INTERNAL_ERROR:	return -EIO;
>> +	default:			return -EIO;
>> +	}
>> +}
> 
> That looks a bit familiar :)

Ah ! I only looked in opal ...

> static int rtas_error_rc(int rtas_rc)
> {
> 	int rc;
> 
> 	switch (rtas_rc) {
> 		case -1: 		/* Hardware Error */
> 			rc = -EIO;
> 			break;
> 		case -3:		/* Bad indicator/domain/etc */
> 			rc = -EINVAL;
> 			break;
> 		case -9000:		/* Isolation error */
> 			rc = -EFAULT;
> 			break;
> 		case -9001:		/* Outstanding TCE/PTE */
> 			rc = -EEXIST;
> 			break;
> 		case -9002:		/* No usable slot */
> 			rc = -ENODEV;
> 			break;
> 		default:
> 			printk(KERN_ERR "%s: unexpected RTAS error %d\n",
> 					__func__, rtas_rc);
> 			rc = -ERANGE;

this a better code default value.


> 			break;
> 	}
> 	return rc;
> }
> 
> 
> But I guess we still should have it.
> 
> Can you put it in opal.h and give it a better name, maybe opal_error_code() ?

Sure. I will change the name but opal.c looks better, knowing that opal.h is 
shared with skiboot.

> 
>>  /*
>>   * This will return sensor information to driver based on the requested sensor
>>   * handle. A handle is an opaque id for the powernv, read by the driver from the
>> @@ -46,8 +78,10 @@ int opal_get_sensor_data(u32 sensor_hndl
>>  
>>  	mutex_lock(&opal_sensor_mutex);
>>  	ret = opal_sensor_read(sensor_hndl, token, &data);
>> -	if (ret != OPAL_ASYNC_COMPLETION)
>> +	if (ret != OPAL_ASYNC_COMPLETION) {
>> +		ret = convert_opal_code(ret);
>>  		goto out_token;
>> +	}
>>  
>>  	ret = opal_async_wait_response(token, &msg);
>>  	if (ret) {
>> @@ -58,6 +92,7 @@ int opal_get_sensor_data(u32 sensor_hndl
>>  
>>  	*sensor_data = be32_to_cpu(data);
>>  	ret = be64_to_cpu(msg.params[1]);
>> +	ret = convert_opal_code(ret);
> 
> I'd do:
> 	ret = convert_opal_code(be64_to_cpu(msg.params[1]));

Yes. the double 'ret =' is ugly.

Thanks,

C. 

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v3 1/3] powerpc/powernv: convert codes returned by OPAL calls
  2015-03-27  9:59         ` [v2,1/3] powerpc/powernv: convert codes returned by OPAL calls Michael Ellerman
  2015-03-27 10:36           ` [Skiboot] [v2, 1/3] " Benjamin Herrenschmidt
  2015-03-27 10:45           ` [v2,1/3] " Cedric Le Goater
@ 2015-03-27 16:39           ` Cédric Le Goater
  2015-03-30  2:05             ` Michael Ellerman
  2015-03-27 16:39           ` [PATCH v3 2/3] " Cédric Le Goater
  2015-03-27 16:39           ` [PATCH v3 3/3] powerpc/powernv: remove opal_sensor_mutex Cédric Le Goater
  4 siblings, 1 reply; 25+ messages in thread
From: Cédric Le Goater @ 2015-03-27 16:39 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Stewart Smith, benh, Cédric Le Goater, Neelesh Gupta, skiboot

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>
---

 Changes since v2 :

 - renamed and moved the routine to opal.[ch]
 - changed default value to ERANGE like rtas

 arch/powerpc/include/asm/opal.h              |    2 ++
 arch/powerpc/platforms/powernv/opal-sensor.c |    6 ++++--
 arch/powerpc/platforms/powernv/opal.c        |   17 +++++++++++++++++
 3 files changed, 23 insertions(+), 2 deletions(-)

Index: linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
===================================================================
--- linux.git.orig/arch/powerpc/platforms/powernv/opal-sensor.c
+++ linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
@@ -46,8 +46,10 @@ int opal_get_sensor_data(u32 sensor_hndl
 
 	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
 	}
 
 	*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: linux.git/arch/powerpc/include/asm/opal.h
===================================================================
--- linux.git.orig/arch/powerpc/include/asm/opal.h
+++ linux.git/arch/powerpc/include/asm/opal.h
@@ -983,6 +983,8 @@ struct opal_sg_list *opal_vmalloc_to_sg_
 					     unsigned long vmalloc_size);
 void opal_free_sg_list(struct opal_sg_list *sg);
 
+extern int opal_error_code(int rc);
+
 /*
  * Dump region ID range usable by the OS
  */
Index: linux.git/arch/powerpc/platforms/powernv/opal.c
===================================================================
--- linux.git.orig/arch/powerpc/platforms/powernv/opal.c
+++ linux.git/arch/powerpc/platforms/powernv/opal.c
@@ -894,6 +894,23 @@ void opal_free_sg_list(struct opal_sg_li
 	}
 }
 
+int opal_error_code(int rc)
+{
+	switch (rc) {
+	case OPAL_SUCCESS:		return 0;
+	case OPAL_PARAMETER:		return -EINVAL;
+	case OPAL_UNSUPPORTED:		return -ENOSYS;
+	case OPAL_ASYNC_COMPLETION:	return -EAGAIN;
+	case OPAL_BUSY_EVENT:		return -EBUSY;
+	case OPAL_NO_MEM:		return -ENOMEM;
+	case OPAL_HARDWARE:		return -ENOENT;
+	case OPAL_INTERNAL_ERROR:	return -EIO;
+	default:
+		pr_err("%s: unexpected OPAL error %d\n", __func__, rc);
+		return -ERANGE;
+	}
+}
+
 EXPORT_SYMBOL_GPL(opal_poll_events);
 EXPORT_SYMBOL_GPL(opal_rtc_read);
 EXPORT_SYMBOL_GPL(opal_rtc_write);

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v3 2/3] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read
  2015-03-27  9:59         ` [v2,1/3] powerpc/powernv: convert codes returned by OPAL calls Michael Ellerman
                             ` (2 preceding siblings ...)
  2015-03-27 16:39           ` [PATCH v3 1/3] " Cédric Le Goater
@ 2015-03-27 16:39           ` Cédric Le Goater
  2015-03-27 16:39           ` [PATCH v3 3/3] powerpc/powernv: remove opal_sensor_mutex Cédric Le Goater
  4 siblings, 0 replies; 25+ messages in thread
From: Cédric Le Goater @ 2015-03-27 16:39 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Stewart Smith, benh, Cédric Le Goater, Neelesh Gupta, skiboot

Currently, when a sensor value is read, the kernel calls OPAL, which in
turn builds a message for the FSP, and waits for a message back. 

The new device tree for OPAL sensors [1] adds new sensors that can be 
read synchronously (core temperatures for instance) and that don't need 
to wait for a response.

This patch modifies the opal call to accept an OPAL_SUCCESS return value
and cover the case above.

[1] https://lists.ozlabs.org/pipermail/skiboot/2015-March/000639.html

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---

 We still uselessly reserve a token (for the response) and take a
 lock, which might raise the need of a new 'opal_sensor_read_sync' 
 call.

 Changes since v2 :

 - merged the return code assignments in one call

 arch/powerpc/platforms/powernv/opal-sensor.c |   32 ++++++++++++++++-----------
 1 file changed, 20 insertions(+), 12 deletions(-)

Index: linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
===================================================================
--- linux.git.orig/arch/powerpc/platforms/powernv/opal-sensor.c
+++ linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
@@ -46,20 +46,28 @@ int opal_get_sensor_data(u32 sensor_hndl
 
 	mutex_lock(&opal_sensor_mutex);
 	ret = opal_sensor_read(sensor_hndl, token, &data);
-	if (ret != OPAL_ASYNC_COMPLETION) {
-		ret = opal_error_code(ret);
-		goto out_token;
-	}
+	switch (ret) {
+	case OPAL_ASYNC_COMPLETION:
+		ret = opal_async_wait_response(token, &msg);
+		if (ret) {
+			pr_err("%s: Failed to wait for the async response, %d\n",
+			       __func__, ret);
+			goto out_token;
+		}
 
-	ret = opal_async_wait_response(token, &msg);
-	if (ret) {
-		pr_err("%s: Failed to wait for the async response, %d\n",
-				__func__, ret);
-		goto out_token;
-	}
+		ret = opal_error_code(be64_to_cpu(msg.params[1]));
+		*sensor_data = be32_to_cpu(data);
+		break;
 
-	*sensor_data = be32_to_cpu(data);
-	ret = opal_error_code(be64_to_cpu(msg.params[1]));
+	case OPAL_SUCCESS:
+		ret = 0;
+		*sensor_data = be32_to_cpu(data);
+		break;
+
+	default:
+		ret = opal_error_code(ret);
+		break;
+	}
 
 out_token:
 	mutex_unlock(&opal_sensor_mutex);

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v3 3/3] powerpc/powernv: remove opal_sensor_mutex
  2015-03-27  9:59         ` [v2,1/3] powerpc/powernv: convert codes returned by OPAL calls Michael Ellerman
                             ` (3 preceding siblings ...)
  2015-03-27 16:39           ` [PATCH v3 2/3] " Cédric Le Goater
@ 2015-03-27 16:39           ` Cédric Le Goater
  2015-03-30  2:09             ` Michael Ellerman
  4 siblings, 1 reply; 25+ messages in thread
From: Cédric Le Goater @ 2015-03-27 16:39 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Stewart Smith, benh, Cédric Le Goater, Neelesh Gupta, skiboot

The opal sensor mutex protects the opal_sensor_read call which
can return a OPAL_BUSY code on IBM Power systems if a previous 
request is in progress.

This can be handled at user level with a retry.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---

 Changes since v2 :

 - removed a goto label

 arch/powerpc/platforms/powernv/opal-sensor.c |    9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

Index: linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
===================================================================
--- linux.git.orig/arch/powerpc/platforms/powernv/opal-sensor.c
+++ linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
@@ -19,13 +19,10 @@
  */
 
 #include <linux/delay.h>
-#include <linux/mutex.h>
 #include <linux/of_platform.h>
 #include <asm/opal.h>
 #include <asm/machdep.h>
 
-static DEFINE_MUTEX(opal_sensor_mutex);
-
 /*
  * This will return sensor information to driver based on the requested sensor
  * handle. A handle is an opaque id for the powernv, read by the driver from the
@@ -40,11 +37,9 @@ int opal_get_sensor_data(u32 sensor_hndl
 	token = opal_async_get_token_interruptible();
 	if (token < 0) {
 		pr_err("%s: Couldn't get the token, returning\n", __func__);
-		ret = token;
-		goto out;
+		return token;
 	}
 
-	mutex_lock(&opal_sensor_mutex);
 	ret = opal_sensor_read(sensor_hndl, token, &data);
 	switch (ret) {
 	case OPAL_ASYNC_COMPLETION:
@@ -70,9 +65,7 @@ int opal_get_sensor_data(u32 sensor_hndl
 	}
 
 out_token:
-	mutex_unlock(&opal_sensor_mutex);
 	opal_async_release_token(token);
-out:
 	return ret;
 }
 EXPORT_SYMBOL_GPL(opal_get_sensor_data);

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 1/3] powerpc/powernv: convert codes returned by OPAL calls
  2015-03-27 16:39           ` [PATCH v3 1/3] " Cédric Le Goater
@ 2015-03-30  2:05             ` Michael Ellerman
  2015-03-30  6:37               ` Cedric Le Goater
  0 siblings, 1 reply; 25+ messages in thread
From: Michael Ellerman @ 2015-03-30  2:05 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: Stewart Smith, skiboot, benh, linuxppc-dev, Neelesh Gupta

On Fri, 2015-03-27 at 17:39 +0100, Cédric Le Goater wrote:
> 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.
> 
> Index: linux.git/arch/powerpc/platforms/powernv/opal.c
> ===================================================================
> --- linux.git.orig/arch/powerpc/platforms/powernv/opal.c
> +++ linux.git/arch/powerpc/platforms/powernv/opal.c
> @@ -894,6 +894,23 @@ void opal_free_sg_list(struct opal_sg_li
>  	}
>  }
>  
> +int opal_error_code(int rc)
> +{
> +	switch (rc) {
> +	case OPAL_SUCCESS:		return 0;

Obviously correct.

> +	case OPAL_PARAMETER:		return -EINVAL;

Yep.

> +	case OPAL_UNSUPPORTED:		return -ENOSYS;

You shouldn't use ENOSYS here, that should only ever mean "no such syscall",
otherwise you get very confusing results like read() returning ENOSYS.

> +	case OPAL_ASYNC_COMPLETION:	return -EAGAIN;

EAGAIN means "try what you did again", I don't think that's what
ASYNC_COMPLETION means, is it? It looks like it means, "don't try again, but
you need to wait for the result to be ready".

I'm not sure it maps well to any of the Linux codes, maybe EINPROGRESS ?

> +	case OPAL_BUSY_EVENT:		return -EBUSY;

Yep.

> +	case OPAL_NO_MEM:		return -ENOMEM;

Yep.

> +	case OPAL_HARDWARE:		return -ENOENT;

This is another one which I think you shouldn't use as it can lead to confusing
results at user level. eg:

  $ cat /sysfs/some/file
  Error: No such file or directory

Huh?

Looking at the skiboot code this looks like EIO is a good match.

> +	case OPAL_INTERNAL_ERROR:	return -EIO;

Yeah as good as anything I guess.

> +	default:
> +		pr_err("%s: unexpected OPAL error %d\n", __func__, rc);
> +		return -ERANGE;

I'm not sure about this one honestly, it means "Math result not representable".

I suspect the reason RTAS chose it was just that it's not EINVAL.

This should probably also just be EIO.


cheers

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 3/3] powerpc/powernv: remove opal_sensor_mutex
  2015-03-27 16:39           ` [PATCH v3 3/3] powerpc/powernv: remove opal_sensor_mutex Cédric Le Goater
@ 2015-03-30  2:09             ` Michael Ellerman
  2015-03-30  6:51               ` Cedric Le Goater
  0 siblings, 1 reply; 25+ messages in thread
From: Michael Ellerman @ 2015-03-30  2:09 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: Stewart Smith, skiboot, benh, linuxppc-dev, Neelesh Gupta

On Fri, 2015-03-27 at 17:39 +0100, Cédric Le Goater wrote:
> The opal sensor mutex protects the opal_sensor_read call which
> can return a OPAL_BUSY code on IBM Power systems if a previous 
> request is in progress.
> 
> This can be handled at user level with a retry.

It can, but how does it actually look in practice?

It looks like the only use of opal_get_sensor_data() is show_sensor() in
drivers/hwmon/ibmpowernv.c.

Because that's a sysfs attribute folks will be generally just dumping that with
cat, or reading it in a shell script, neither of which will cope nicely with
EBUSY I think?

cheers

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 1/3] powerpc/powernv: convert codes returned by OPAL calls
  2015-03-30  2:05             ` Michael Ellerman
@ 2015-03-30  6:37               ` Cedric Le Goater
  2015-03-30  6:54                 ` Michael Ellerman
  0 siblings, 1 reply; 25+ messages in thread
From: Cedric Le Goater @ 2015-03-30  6:37 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: Stewart Smith, skiboot, benh, linuxppc-dev, Neelesh Gupta

On 03/30/2015 04:05 AM, Michael Ellerman wrote:
> On Fri, 2015-03-27 at 17:39 +0100, Cédric Le Goater wrote:
>> 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.
>>
>> Index: linux.git/arch/powerpc/platforms/powernv/opal.c
>> ===================================================================
>> --- linux.git.orig/arch/powerpc/platforms/powernv/opal.c
>> +++ linux.git/arch/powerpc/platforms/powernv/opal.c
>> @@ -894,6 +894,23 @@ void opal_free_sg_list(struct opal_sg_li
>>  	}
>>  }
>>  
>> +int opal_error_code(int rc)
>> +{
>> +	switch (rc) {
>> +	case OPAL_SUCCESS:		return 0;
> 
> Obviously correct.

He. Initially, I didn't put a case for SUCCESS, but we have code doing :

	ret = be64_to_cpu(msg.params[1]);


>> +	case OPAL_PARAMETER:		return -EINVAL;
> 
> Yep.
> 
>> +	case OPAL_UNSUPPORTED:		return -ENOSYS;
> 
> You shouldn't use ENOSYS here, that should only ever mean "no such syscall",
> otherwise you get very confusing results like read() returning ENOSYS.

Indeed. How about ENODEV then ? 

>> +	case OPAL_ASYNC_COMPLETION:	return -EAGAIN;
> 
> EAGAIN means "try what you did again", I don't think that's what
> ASYNC_COMPLETION means, is it? It looks like it means, "don't try again, but
> you need to wait for the result to be ready".
> 
> I'm not sure it maps well to any of the Linux codes, maybe EINPROGRESS ?

Yes. This is better.

>> +	case OPAL_BUSY_EVENT:		return -EBUSY;
> 
> Yep.
> 
>> +	case OPAL_NO_MEM:		return -ENOMEM;
> 
> Yep.
> 
>> +	case OPAL_HARDWARE:		return -ENOENT;
> 
> This is another one which I think you shouldn't use as it can lead to confusing
> results at user level. eg:
> 
>   $ cat /sysfs/some/file
>   Error: No such file or directory
> 
> Huh?
> 
> Looking at the skiboot code this looks like EIO is a good match.

ok. 

>> +	case OPAL_INTERNAL_ERROR:	return -EIO;
> 
> Yeah as good as anything I guess.
> 
>> +	default:
>> +		pr_err("%s: unexpected OPAL error %d\n", __func__, rc);
>> +		return -ERANGE;
> 
> I'm not sure about this one honestly, it means "Math result not representable".
> 
> I suspect the reason RTAS chose it was just that it's not EINVAL.
> 
> This should probably also just be EIO.

ok. I will change it. 

Thanks,

C.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 3/3] powerpc/powernv: remove opal_sensor_mutex
  2015-03-30  2:09             ` Michael Ellerman
@ 2015-03-30  6:51               ` Cedric Le Goater
  2015-03-30  6:59                 ` Michael Ellerman
  0 siblings, 1 reply; 25+ messages in thread
From: Cedric Le Goater @ 2015-03-30  6:51 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: Stewart Smith, skiboot, benh, linuxppc-dev, Neelesh Gupta

On 03/30/2015 04:09 AM, Michael Ellerman wrote:
> On Fri, 2015-03-27 at 17:39 +0100, Cédric Le Goater wrote:
>> The opal sensor mutex protects the opal_sensor_read call which
>> can return a OPAL_BUSY code on IBM Power systems if a previous 
>> request is in progress.
>>
>> This can be handled at user level with a retry.
> 
> It can, but how does it actually look in practice?
> 
> It looks like the only use of opal_get_sensor_data() is show_sensor() in
> drivers/hwmon/ibmpowernv.c.
> 
> Because that's a sysfs attribute folks will be generally just dumping 
> that with cat, or reading it in a shell script, neither of which will 
> cope nicely with EBUSY I think?

It won't, I agree but it should only happen when running concurrent cat 
commands on the hwmon sysfs files. The event should be rare enough.

Anyhow, this is not a big issue. We can drop that patch. The real "issue"
is the time it takes to get some values back from the FSP. This is what
user space has been most surprised about.

Thanks,

C.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 1/3] powerpc/powernv: convert codes returned by OPAL calls
  2015-03-30  6:37               ` Cedric Le Goater
@ 2015-03-30  6:54                 ` Michael Ellerman
  2015-03-30  6:56                   ` Cedric Le Goater
                                     ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Michael Ellerman @ 2015-03-30  6:54 UTC (permalink / raw)
  To: Cedric Le Goater
  Cc: Stewart Smith, skiboot, benh, linuxppc-dev, Neelesh Gupta

On Mon, 2015-03-30 at 08:37 +0200, Cedric Le Goater wrote:
> On 03/30/2015 04:05 AM, Michael Ellerman wrote:
> > On Fri, 2015-03-27 at 17:39 +0100, Cédric Le Goater wrote:
> >> 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.
> >>
> >> +	case OPAL_UNSUPPORTED:		return -ENOSYS;
> > 
> > You shouldn't use ENOSYS here, that should only ever mean "no such syscall",
> > otherwise you get very confusing results like read() returning ENOSYS.
> 
> Indeed. How about ENODEV then ? 

That can also be confusing from userspace.

I think it's probably best just to use EIO, as far as userspace is concerned if
the kernel lets it call an unsupported OPAL routine that is more or less a
kernel bug.

cheers

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 1/3] powerpc/powernv: convert codes returned by OPAL calls
  2015-03-30  6:54                 ` Michael Ellerman
@ 2015-03-30  6:56                   ` Cedric Le Goater
  2015-03-30 10:06                   ` [PATCH v4 1/2] " Cédric Le Goater
  2015-03-30 10:06                   ` [PATCH v4 2/2] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read Cédric Le Goater
  2 siblings, 0 replies; 25+ messages in thread
From: Cedric Le Goater @ 2015-03-30  6:56 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: Stewart Smith, skiboot, benh, linuxppc-dev, Neelesh Gupta

On 03/30/2015 08:54 AM, Michael Ellerman wrote:
> On Mon, 2015-03-30 at 08:37 +0200, Cedric Le Goater wrote:
>> On 03/30/2015 04:05 AM, Michael Ellerman wrote:
>>> On Fri, 2015-03-27 at 17:39 +0100, Cédric Le Goater wrote:
>>>> 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.
>>>>
>>>> +	case OPAL_UNSUPPORTED:		return -ENOSYS;
>>>
>>> You shouldn't use ENOSYS here, that should only ever mean "no such syscall",
>>> otherwise you get very confusing results like read() returning ENOSYS.
>>
>> Indeed. How about ENODEV then ? 
> 
> That can also be confusing from userspace.
> 
> I think it's probably best just to use EIO, as far as userspace is concerned if
> the kernel lets it call an unsupported OPAL routine that is more or less a
> kernel bug.

OK. Will do.

Thanks,

C.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 3/3] powerpc/powernv: remove opal_sensor_mutex
  2015-03-30  6:51               ` Cedric Le Goater
@ 2015-03-30  6:59                 ` Michael Ellerman
  2015-03-30 10:05                   ` Cedric Le Goater
  0 siblings, 1 reply; 25+ messages in thread
From: Michael Ellerman @ 2015-03-30  6:59 UTC (permalink / raw)
  To: Cedric Le Goater
  Cc: Stewart Smith, skiboot, benh, linuxppc-dev, Neelesh Gupta

On Mon, 2015-03-30 at 08:51 +0200, Cedric Le Goater wrote:
> On 03/30/2015 04:09 AM, Michael Ellerman wrote:
> > On Fri, 2015-03-27 at 17:39 +0100, Cédric Le Goater wrote:
> >> The opal sensor mutex protects the opal_sensor_read call which
> >> can return a OPAL_BUSY code on IBM Power systems if a previous 
> >> request is in progress.
> >>
> >> This can be handled at user level with a retry.
> > 
> > It can, but how does it actually look in practice?
> > 
> > It looks like the only use of opal_get_sensor_data() is show_sensor() in
> > drivers/hwmon/ibmpowernv.c.
> > 
> > Because that's a sysfs attribute folks will be generally just dumping 
> > that with cat, or reading it in a shell script, neither of which will 
> > cope nicely with EBUSY I think?
> 
> It won't, I agree but it should only happen when running concurrent cat 
> commands on the hwmon sysfs files. The event should be rare enough.

Rare enough maybe, but a real pain in the .. to cope with in a shell script if
you're trying to automate something.

> Anyhow, this is not a big issue. We can drop that patch. The real "issue"
> is the time it takes to get some values back from the FSP. This is what
> user space has been most surprised about.

OK. The other option would be to move the mutex into the sysfs show routine, so
only that is synchronous. That would give you nice behaviour from cat, ie. it
would sleep on contention but still be killable with ctrl-c.

cheers

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 3/3] powerpc/powernv: remove opal_sensor_mutex
  2015-03-30  6:59                 ` Michael Ellerman
@ 2015-03-30 10:05                   ` Cedric Le Goater
  0 siblings, 0 replies; 25+ messages in thread
From: Cedric Le Goater @ 2015-03-30 10:05 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: Stewart Smith, skiboot, benh, linuxppc-dev, Neelesh Gupta

On 03/30/2015 08:59 AM, Michael Ellerman wrote:
> On Mon, 2015-03-30 at 08:51 +0200, Cedric Le Goater wrote:
>> On 03/30/2015 04:09 AM, Michael Ellerman wrote:
>>> On Fri, 2015-03-27 at 17:39 +0100, Cédric Le Goater wrote:
>>>> The opal sensor mutex protects the opal_sensor_read call which
>>>> can return a OPAL_BUSY code on IBM Power systems if a previous 
>>>> request is in progress.
>>>>
>>>> This can be handled at user level with a retry.
>>>
>>> It can, but how does it actually look in practice?
>>>
>>> It looks like the only use of opal_get_sensor_data() is show_sensor() in
>>> drivers/hwmon/ibmpowernv.c.
>>>
>>> Because that's a sysfs attribute folks will be generally just dumping 
>>> that with cat, or reading it in a shell script, neither of which will 
>>> cope nicely with EBUSY I think?
>>
>> It won't, I agree but it should only happen when running concurrent cat 
>> commands on the hwmon sysfs files. The event should be rare enough.
> 
> Rare enough maybe, but a real pain in the .. to cope with in a shell script if
> you're trying to automate something.
> 
>> Anyhow, this is not a big issue. We can drop that patch. The real "issue"
>> is the time it takes to get some values back from the FSP. This is what
>> user space has been most surprised about.
> 
> OK. The other option would be to move the mutex into the sysfs show routine, so
> only that is synchronous. That would give you nice behaviour from cat, ie. it
> would sleep on contention but still be killable with ctrl-c.

Let's keep it how it is and see if it is possible to the improve OPAL 
side first. 

I will send you an updated patchset shortly. 

Thanks for the review. 

C.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v4 1/2] powerpc/powernv: convert codes returned by OPAL calls
  2015-03-30  6:54                 ` Michael Ellerman
  2015-03-30  6:56                   ` Cedric Le Goater
@ 2015-03-30 10:06                   ` Cédric Le Goater
  2015-03-30 10:06                   ` [PATCH v4 2/2] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read Cédric Le Goater
  2 siblings, 0 replies; 25+ messages in thread
From: Cédric Le Goater @ 2015-03-30 10:06 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Stewart Smith, benh, Cédric Le Goater, Neelesh Gupta, skiboot

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>
---

 Changes since v3 :

 - reworked the return codes a little as suggested by Michael Ellerman

 Changes since v2 :

 - renamed and moved the routine to opal.[ch]
 - changed default value to ERANGE like rtas

 arch/powerpc/include/asm/opal.h              |    2 ++
 arch/powerpc/platforms/powernv/opal-sensor.c |    6 ++++--
 arch/powerpc/platforms/powernv/opal.c        |   19 +++++++++++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)

Index: linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
===================================================================
--- linux.git.orig/arch/powerpc/platforms/powernv/opal-sensor.c
+++ linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
@@ -46,8 +46,10 @@ int opal_get_sensor_data(u32 sensor_hndl
 
 	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
 	}
 
 	*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: linux.git/arch/powerpc/include/asm/opal.h
===================================================================
--- linux.git.orig/arch/powerpc/include/asm/opal.h
+++ linux.git/arch/powerpc/include/asm/opal.h
@@ -983,6 +983,8 @@ struct opal_sg_list *opal_vmalloc_to_sg_
 					     unsigned long vmalloc_size);
 void opal_free_sg_list(struct opal_sg_list *sg);
 
+extern int opal_error_code(int rc);
+
 /*
  * Dump region ID range usable by the OS
  */
Index: linux.git/arch/powerpc/platforms/powernv/opal.c
===================================================================
--- linux.git.orig/arch/powerpc/platforms/powernv/opal.c
+++ linux.git/arch/powerpc/platforms/powernv/opal.c
@@ -894,6 +894,25 @@ void opal_free_sg_list(struct opal_sg_li
 	}
 }
 
+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);

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v4 2/2] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read
  2015-03-30  6:54                 ` Michael Ellerman
  2015-03-30  6:56                   ` Cedric Le Goater
  2015-03-30 10:06                   ` [PATCH v4 1/2] " Cédric Le Goater
@ 2015-03-30 10:06                   ` Cédric Le Goater
  2 siblings, 0 replies; 25+ messages in thread
From: Cédric Le Goater @ 2015-03-30 10:06 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Stewart Smith, benh, Cédric Le Goater, Neelesh Gupta, skiboot

Currently, when a sensor value is read, the kernel calls OPAL, which in
turn builds a message for the FSP, and waits for a message back. 

The new device tree for OPAL sensors [1] adds new sensors that can be 
read synchronously (core temperatures for instance) and that don't need 
to wait for a response.

This patch modifies the opal call to accept an OPAL_SUCCESS return value
and cover the case above.

[1] https://lists.ozlabs.org/pipermail/skiboot/2015-March/000639.html

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---

 We still uselessly reserve a token (for the response) and take a
 lock, which might raise the need of a new 'opal_sensor_read_sync' 
 call.

 Changes since v2 :

 - merged the return code assignments in one call

 arch/powerpc/platforms/powernv/opal-sensor.c |   32 ++++++++++++++++-----------
 1 file changed, 20 insertions(+), 12 deletions(-)

Index: linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
===================================================================
--- linux.git.orig/arch/powerpc/platforms/powernv/opal-sensor.c
+++ linux.git/arch/powerpc/platforms/powernv/opal-sensor.c
@@ -46,20 +46,28 @@ int opal_get_sensor_data(u32 sensor_hndl
 
 	mutex_lock(&opal_sensor_mutex);
 	ret = opal_sensor_read(sensor_hndl, token, &data);
-	if (ret != OPAL_ASYNC_COMPLETION) {
-		ret = opal_error_code(ret);
-		goto out_token;
-	}
+	switch (ret) {
+	case OPAL_ASYNC_COMPLETION:
+		ret = opal_async_wait_response(token, &msg);
+		if (ret) {
+			pr_err("%s: Failed to wait for the async response, %d\n",
+			       __func__, ret);
+			goto out_token;
+		}
 
-	ret = opal_async_wait_response(token, &msg);
-	if (ret) {
-		pr_err("%s: Failed to wait for the async response, %d\n",
-				__func__, ret);
-		goto out_token;
-	}
+		ret = opal_error_code(be64_to_cpu(msg.params[1]));
+		*sensor_data = be32_to_cpu(data);
+		break;
 
-	*sensor_data = be32_to_cpu(data);
-	ret = opal_error_code(be64_to_cpu(msg.params[1]));
+	case OPAL_SUCCESS:
+		ret = 0;
+		*sensor_data = be32_to_cpu(data);
+		break;
+
+	default:
+		ret = opal_error_code(ret);
+		break;
+	}
 
 out_token:
 	mutex_unlock(&opal_sensor_mutex);

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2015-03-30 10:06 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-25 17:50 [PATCH] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read Cédric Le Goater
2015-03-25 23:07 ` Stewart Smith
2015-03-26  9:44   ` Cedric Le Goater
2015-03-26 12:58     ` Cedric Le Goater
2015-03-26 16:04       ` [PATCH v2 1/3] powerpc/powernv: convert codes returned by OPAL calls Cédric Le Goater
2015-03-26 16:04         ` [PATCH v2 2/3] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read Cédric Le Goater
2015-03-26 16:04         ` [PATCH v2 3/3] powerpc/powernv: remove opal_sensor_mutex Cédric Le Goater
2015-03-27  9:59         ` [v2,1/3] powerpc/powernv: convert codes returned by OPAL calls Michael Ellerman
2015-03-27 10:36           ` [Skiboot] [v2, 1/3] " Benjamin Herrenschmidt
2015-03-27 10:39             ` Cedric Le Goater
2015-03-27 10:45           ` [v2,1/3] " Cedric Le Goater
2015-03-27 16:39           ` [PATCH v3 1/3] " Cédric Le Goater
2015-03-30  2:05             ` Michael Ellerman
2015-03-30  6:37               ` Cedric Le Goater
2015-03-30  6:54                 ` Michael Ellerman
2015-03-30  6:56                   ` Cedric Le Goater
2015-03-30 10:06                   ` [PATCH v4 1/2] " Cédric Le Goater
2015-03-30 10:06                   ` [PATCH v4 2/2] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read Cédric Le Goater
2015-03-27 16:39           ` [PATCH v3 2/3] " Cédric Le Goater
2015-03-27 16:39           ` [PATCH v3 3/3] powerpc/powernv: remove opal_sensor_mutex Cédric Le Goater
2015-03-30  2:09             ` Michael Ellerman
2015-03-30  6:51               ` Cedric Le Goater
2015-03-30  6:59                 ` Michael Ellerman
2015-03-30 10:05                   ` Cedric Le Goater
2015-03-27  6:05     ` [PATCH] powerpc/powernv: handle OPAL_SUCCESS return in opal_sensor_read Stewart Smith

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.