firmware: arm_scmi: miscellaneous fixes/updates
v2 cover firmware: arm_scmi: miscellaneous fixes/updates
Hi,
Here are few miscellaneous fixes and updates to SCMI. Fixes are mostly for the reported issues and updates are based on code inspection during development of new features(delayed response and notifications). The new features will follow this.
--
Regards,
Sudeep
v1->v2:
- Fixed spurious ] in doxygen comment
- Dropped the first patch as it's already merged
- Added a new patch to use correct style for SPDX License in .h
Sudeep Holla (6):
firmware: arm_scmi: Use the correct style for SPDX License Identifier
firmware: arm_scmi: Align few names in sensors protocol with SCMI
specification
firmware: arm_scmi: Remove extra check for invalid length message
responses
firmware: arm_scmi: Fix few trivial typos in comments
firmware: arm_scmi: Use the term 'message' instead of 'command'
firmware: arm_scmi: Check if platform has released shmem before using
drivers/firmware/arm_scmi/common.h | 10 +++++----- drivers/firmware/arm_scmi/driver.c | 24 +++++++++++++----------- drivers/firmware/arm_scmi/sensors.c | 28 +++++++++++++++------------- include/linux/scmi_protocol.h | 14 +++++++------- 4 files changed, 40 insertions(+), 36 deletions(-)
Signature · 7 lines
2.17.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 1/6 firmware: arm_scmi: Use the correct style for SPDX License Identifier
Fix to correct the SPDX License Identifier style in header file related to firmware frivers for ARM SCMI message protocol.
For C header files Documentation/process/license-rules.rst mandates C-like comments(opposed to C source files where C++ style should be used).
While at it, change GPL-2.0 to GPL-2.0-only similar to the ones in psci.h and scpi_protocol.h
--- include/linux/scmi_protocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/scmi_protocol.h +1 -1
@@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +/* SPDX-License-Identifier: GPL-2.0-only */ /* * SCMI Message Protocol driver header *
Signature · 7 lines
2.17.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 2/6 firmware: arm_scmi: Align few names in sensors protocol with SCMI specification
In reply to Sudeep HollaLooks like more code developed during the draft versions of the specification slipped through and they don't match the final released version. This seem to have happened only with sensor protocol.
Renaming few command and function names here to match exactly with the released version of SCMI specification for ease of maintenance.
--- drivers/firmware/arm_scmi/sensors.c | 28 +++++++++++++++------------- include/linux/scmi_protocol.h | 12 ++++++------ 2 files changed, 21 insertions(+), 19 deletions(-)
drivers/firmware/arm_scmi/sensors.c +15 -13
@@ -9,8 +9,8 @@enum scmi_sensor_protocol_cmd {SENSOR_DESCRIPTION_GET =0x3 , -SENSOR_CONFIG_SET =0x4 , -SENSOR_TRIP_POINT_SET =0x5 , +SENSOR_TRIP_POINT_NOTIFY =0x4 , +SENSOR_TRIP_POINT_CONFIG =0x5 ,SENSOR_READING_GET =0x6 , };
@@ -42,9 +42,10 @@ struct scmi_msg_resp_sensor_description { } desc[0 ]; }; -struct scmi_msg_set_sensor_config { +struct scmi_msg_sensor_trip_point_notify {__le32 id;__le32 event_control; +#define SENSOR_TP_NOTIFY_ALL BIT(0) };struct scmi_msg_set_sensor_trip_point {
@@ -160,15 +161,15 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,return ret; } -static int -scmi_sensor_configuration_set (const struct scmi_handle *handle,u32 sensor_id) +static int scmi_sensor_trip_point_notify (const struct scmi_handle *handle, +u32 sensor_id,bool enable) {int ret; -u32 evt_cntl =BIT (0 ); +u32 evt_cntl = enable ?SENSOR_TP_NOTIFY_ALL :0 ;struct scmi_xfer *t; -struct scmi_msg_set_sensor_config *cfg; +struct scmi_msg_sensor_trip_point_notify *cfg; - ret =scmi_xfer_get_init (handle,SENSOR_CONFIG_SET , + ret =scmi_xfer_get_init (handle,SENSOR_TRIP_POINT_NOTIFY ,SCMI_PROTOCOL_SENSOR ,sizeof (*cfg),0 , &t);if (ret)return ret;
@@ -183,15 +184,16 @@ scmi_sensor_configuration_set(const struct scmi_handle *handle, u32 sensor_id)return ret; } -static int scmi_sensor_trip_point_set (const struct scmi_handle *handle, -u32 sensor_id,u8 trip_id,u64 trip_value) +static int +scmi_sensor_trip_point_config (const struct scmi_handle *handle,u32 sensor_id, +u8 trip_id,u64 trip_value) {int ret;u32 evt_cntl =SENSOR_TP_BOTH ;struct scmi_xfer *t;struct scmi_msg_set_sensor_trip_point *trip; - ret =scmi_xfer_get_init (handle,SENSOR_TRIP_POINT_SET , + ret =scmi_xfer_get_init (handle,SENSOR_TRIP_POINT_CONFIG ,SCMI_PROTOCOL_SENSOR ,sizeof (*trip),0 , &t);if (ret)return ret;
@@ -255,8 +257,8 @@ static int scmi_sensor_count_get(const struct scmi_handle *handle)static struct scmi_sensor_ops sensor_ops = { .count_get = scmi_sensor_count_get, .info_get = scmi_sensor_info_get, - .configuration_set = scmi_sensor_configuration_set, - .trip_point_set = scmi_sensor_trip_point_set, + .trip_point_notify = scmi_sensor_trip_point_notify, + .trip_point_config = scmi_sensor_trip_point_config, .reading_get = scmi_sensor_reading_get, };
include/linux/scmi_protocol.h +6 -6
@@ -167,9 +167,9 @@ enum scmi_sensor_class {* * @count_get: get the count of sensors provided by SCMI * @info_get: get the information of the specified sensor -* @configuration_set: control notifications on cross-over events for +* @trip_point_notify: control notifications on cross-over events for * the trip-points -* @trip_point_set: selects and configures a trip-point of interest +* @trip_point_config: selects and configures a trip-point of interest * @reading_get: gets the current value of the sensor */ struct scmi_sensor_ops {
@@ -177,10 +177,10 @@ struct scmi_sensor_ops {const struct scmi_sensor_info *(*info_get) (const struct scmi_handle *handle,u32 sensor_id); -int (*configuration_set)(const struct scmi_handle *handle, -u32 sensor_id); -int (*trip_point_set)(const struct scmi_handle *handle,u32 sensor_id, -u8 trip_id,u64 trip_value); +int (*trip_point_notify)(const struct scmi_handle *handle, +u32 sensor_id,bool enable); +int (*trip_point_config)(const struct scmi_handle *handle, +u32 sensor_id,u8 trip_id,u64 trip_value);int (*reading_get)(const struct scmi_handle *handle,u32 sensor_id,bool async,u64 *value); };
Signature · 7 lines
2.17.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 3/6 firmware: arm_scmi: Remove extra check for invalid length message responses
In reply to Sudeep Hollascmi_xfer_get_init ensures both transmit and receive buffer lengths are within the maximum limits. If receive buffer length is not supplied by the caller, it's set to the maximum limit value. Receive buffer length is never modified after that. So there's no need for the extra check when receive transmit completion for a command essage.
Further, if the response header length is greater than the prescribed receive buffer length, the response buffer is truncated to the latter.
--- drivers/firmware/arm_scmi/driver.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/firmware/arm_scmi/driver.c +0 -6
@@ -230,12 +230,6 @@ static void scmi_rx_callback(struct mbox_client *cl, void *m) xfer = &minfo->xfer_block[xfer_id];scmi_dump_header_dbg (dev, &xfer->hdr); -/* Is the message of valid length? */ -if (xfer->rx.len > info->desc->max_msg_size) { -dev_err (dev,"unable to handle %zu xfer(max %d)\n" , - xfer->rx.len, info->desc->max_msg_size); -return ; - }scmi_fetch_response (xfer, mem);complete (&xfer->done);
Signature · 1 line
2.17.1
PATCH v2 4/6 firmware: arm_scmi: Fix few trivial typos in comments
In reply to Sudeep HollaWhile adding new comments found couple of typos that are better fixed.
s/informfation/information/
s/statues/status/
--- drivers/firmware/arm_scmi/driver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firmware/arm_scmi/driver.c +2 -2
@@ -86,7 +86,7 @@ struct scmi_desc { };/** -* struct scmi_chan_info - Structure representing a SCMI channel informfation +* struct scmi_chan_info - Structure representing a SCMI channel information * * @cl: Mailbox Client * @chan: Transmit/Receive mailbox channel
@@ -190,7 +190,7 @@ static void scmi_fetch_response(struct scmi_xfer *xfer, struct scmi_shared_mem __iomem *mem) { xfer->hdr.status =ioread32 (mem->msg_payload); -/* Skip the length of header and statues in payload area i.e 8 bytes*/ +/* Skip the length of header and status in payload area i.e 8 bytes */ xfer->rx.len =min_t (size_t, xfer->rx.len,ioread32 (&mem->length) -8 );/* Take a copy to the rx buffer.. */
Signature · 1 line
2.17.1
PATCH v2 5/6 firmware: arm_scmi: Use the term 'message' instead of 'command'
In reply to Sudeep HollaIn preparation to adding support for other two types of messages that SCMI specification mentions, let's replace the term 'command' with the correct term 'message'.
As per the specification the messages are of 3 types:
commands(synchronous or asynchronous), delayed responses and notifications.
--- drivers/firmware/arm_scmi/common.h | 10 +++++----- drivers/firmware/arm_scmi/driver.c | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/firmware/arm_scmi/common.h +5 -5
@@ -48,11 +48,11 @@ struct scmi_msg_resp_prot_version {/** * struct scmi_msg_hdr - Message(Tx/Rx) header * -* @id: The identifier of the command being sent -* @protocol_id: The identifier of the protocol used to send @id command -* @seq: The token to identify the message. when a message/command returns, -* the platform returns the whole message header unmodified including -* the token +* @id: The identifier of the message being sent +* @protocol_id: The identifier of the protocol used to send @id message +* @seq: The token to identify the message. When a message returns, the +* platform returns the whole message header unmodified including the +* token * @status: Status of the transfer once it's complete * @poll_completion: Indicate if the transfer needs to be polled for * completion or interrupt mode is used
drivers/firmware/arm_scmi/driver.c +3 -3
@@ -182,7 +182,7 @@ static inline int scmi_to_linux_errno(int errno)static inline void scmi_dump_header_dbg (struct device *dev,struct scmi_msg_hdr *hdr) { -dev_dbg (dev,"Command ID: %x Sequence ID: %x Protocol: %x\n" , +dev_dbg (dev,"Message ID: %x Sequence ID: %x Protocol: %x\n" , hdr->id, hdr->seq, hdr->protocol_id); }
@@ -241,7 +241,7 @@ static void scmi_rx_callback(struct mbox_client *cl, void *m)* @hdr: pointer to header containing all the information on message id, * protocol id and sequence id. * -* Return: 32-bit packed command header to be sent to the platform. +* Return: 32-bit packed message header to be sent to the platform. */ static inline u32 pack_scmi_header (struct scmi_msg_hdr *hdr) {
@@ -280,7 +280,7 @@ static void scmi_tx_prepare(struct mbox_client *cl, void *m)* * @handle: Pointer to SCMI entity handle * -* Helper function which is used by various command functions that are +* Helper function which is used by various message functions that are * exposed to clients of this driver for allocating a message traffic event. * * This function can sleep depending on pending requests already in the system
Signature · 1 line
2.17.1
PATCH v2 6/6 firmware: arm_scmi: Check if platform has released shmem before using
In reply to Sudeep HollaSometimes platfom may take too long to respond to the command and OS might timeout before platform transfer the ownership of the shared memory region to the OS with the response.
Since the mailbox channel associated with the channel is freed and new commands are dispatch on the same channel, OS needs to wait until it gets back the ownership. If not, either OS may end up overwriting the platform response for the last command(which is fine as OS timed out that command) or platform might overwrite the payload for the next command with the response for the old.
The latter is problematic as platform may end up interpretting the response as the payload. In order to avoid such race, let's wait until the OS gets back the ownership before we prepare the shared memory with the payload for the next command.
--- drivers/firmware/arm_scmi/driver.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/firmware/arm_scmi/driver.c +8 -0
@@ -265,6 +265,14 @@ static void scmi_tx_prepare(struct mbox_client *cl, void *m)struct scmi_chan_info *cinfo =client_to_scmi_chan_info (cl);struct scmi_shared_mem __iomem *mem = cinfo->payload; +/* +* Ideally channel must be free by now unless OS timeout last +* request and platform continued to process the same, wait +* until it releases the shared memory, otherwise we may endup +* overwriting it's response with new command payload or vice-versa +*/ +spin_until_cond (ioread32 (&mem->channel_status) & +SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE );/* Mark channel busy + clear error */ iowrite32 (0x0 , &mem->channel_status); iowrite32(t->hdr.poll_completion ? 0 : SCMI_SHMEM_FLAG_INTR_ENABLED,
Signature · 1 line
2.17.1
Re: [PATCH v2 6/6] firmware: arm_scmi: Check if platform has released shmem before using
Hello Sudeep,
Quoted 28 lines · Sudeep Holla
Sometimes platfom may take too long to respond to the command and OS might timeout before platform transfer the ownership of the shared memory region to the OS with the response.
Since the mailbox channel associated with the channel is freed and new commands are dispatch on the same channel, OS needs to wait until it gets back the ownership. If not, either OS may end up overwriting the platform response for the last command(which is fine as OS timed out that command) or platform might overwrite the payload for the next command with the response for the old.
The latter is problematic as platform may end up interpretting the response as the payload. In order to avoid such race, let's wait until the OS gets back the ownership before we prepare the shared memory with the payload for the next command.
Reported-by Jim Quinlan <[email protected]>Signed-off-by Sudeep Holla <[email protected]>--- drivers/firmware/arm_scmi/driver.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/firmware/arm_scmi/driver.c +0
-0
drivers/firmware/arm_scmi/driver.c static void scmi_tx_prepare(struct mbox_client *cl, void *m) · line 272
Quoted 8 lines
drivers/firmware/arm_scmi/driver.c +5
-0@@ -265,6 +265,14 @@ static void scmi_tx_prepare(struct mbox_client *cl, void *m)struct scmi_chan_info *cinfo =client_to_scmi_chan_info (cl);struct scmi_shared_mem __iomem *mem = cinfo->payload; +/* +* Ideally channel must be free by now unless OS timeout last +* request and platform continued to process the same, wait +* until it releases the shared memory, otherwise we may endup +* overwriting it's response with new command payload or vice-versa
minor typo: s/it's/its/
maybe also s/command/message/
regards,
etienne
Quoted 9 lines
drivers/firmware/arm_scmi/driver.c +3
-1+*/ +spin_until_cond (ioread32 (&mem->channel_status) & +SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE );/* Mark channel busy + clear error */ iowrite32 (0x0 , &mem->channel_status); iowrite32(t->hdr.poll_completion ? 0 : SCMI_SHMEM_FLAG_INTR_ENABLED, --2.17.1
Re: [PATCH v2 6/6] firmware: arm_scmi: Check if platform has released shmem before using
Quoted 34 lines · Etienne Carriere
Hello Sudeep,
Quoted 31 lines · Sudeep Holla
Sometimes platfom may take too long to respond to the command and OS might timeout before platform transfer the ownership of the shared memory region to the OS with the response.
Since the mailbox channel associated with the channel is freed and new commands are dispatch on the same channel, OS needs to wait until it gets back the ownership. If not, either OS may end up overwriting the platform response for the last command(which is fine as OS timed out that command) or platform might overwrite the payload for the next command with the response for the old.
The latter is problematic as platform may end up interpretting the response as the payload. In order to avoid such race, let's wait until the OS gets back the ownership before we prepare the shared memory with the payload for the next command.
Reported-by Jim Quinlan <[email protected]>Signed-off-by Sudeep Holla <[email protected]>--- drivers/firmware/arm_scmi/driver.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/firmware/arm_scmi/driver.c +0
-0@@ -265,6 +265,14 @@ static void scmi_tx_prepare(struct mbox_client *cl, void *m)struct scmi_chan_info *cinfo =client_to_scmi_chan_info (cl);struct scmi_shared_mem __iomem *mem = cinfo->payload;
Quoted 9 lines
drivers/firmware/arm_scmi/driver.c static void scmi_tx_prepare(struct mbox_client *cl, void *m) · line 272
Quoted 5 lines
drivers/firmware/arm_scmi/driver.c +5
-0+/* +* Ideally channel must be free by now unless OS timeout last +* request and platform continued to process the same, wait +* until it releases the shared memory, otherwise we may endup +* overwriting it's response with new command payload or vice-versa minor typo: s/it's/its/
maybe also s/command/message/
Thanks for taking a look at this, both are fixed locally now.
--
Regards,
Sudeep