Skip to contentSkip to conversation

firmware: arm_scmi: Extend SMC/HVC to support multiple channels

PATCH In review Sudeep Holla 2 participants 16 messages Mar 27, 2020 – Apr 1, 2020 System control & power/management interface (SCPI/SCMI) Message Protocol drivers

lore
Share & tools
lore
#0 lore raw

cover firmware: arm_scmi: Extend SMC/HVC to support multiple channels

Hi,

While merging SMC/HVC transport to SCMI, I did a quick hack to extend it to support multiple channels. I may be missing something obvious, if not the changes required look simple. Some of them could be merged into original patch, but since I am unable to test, I preferred to keep them separate, easy to revert if things break.

Regards,
Sudeep
--

Sudeep Holla (4):
firmware: arm_scmi: Make mutex channel specific
firmware: arm_scmi: Drop empty stub for smc_mark_txdone
firmware: arm_scmi: Check shmem property for channel availablity
firmware: arm_scmi: Drop checking for shmem property in parent node

 drivers/firmware/arm_scmi/smc.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

--
2.17.1

#1 lore raw

PATCH 1/4 firmware: arm_scmi: Make mutex channel specific

In order to support multiple SMC/HVC transport channels with associated shared memory, it is better to maintain the mutex per channel instead of existing global one.

Move the smc_mutex into the scmi_smc structure and also rename it to shmem_lock which is more appropriate for it's use.

---
 drivers/firmware/arm_scmi/smc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/firmware/arm_scmi/smc.c +4 -4
index 336168e40f49..6dc8a88cc91b 100644
@@ -27,11 +27,10 @@
 struct scmi_smc {
 	struct scmi_chan_info *cinfo;
 	struct scmi_shared_mem __iomem *shmem;
+	struct mutex shmem_lock;
 	u32 func_id;
 };
 
-static DEFINE_MUTEX(smc_mutex);
-
 static bool smc_chan_available(struct device *dev, int idx)
 {
 	return true;
@@ -78,6 +77,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 
 	scmi_info->func_id = func_id;
 	scmi_info->cinfo = cinfo;
+	mutex_init(&scmi_info->shmem_lock);
 	cinfo->transport_info = scmi_info;
 
 	return 0;
@@ -102,14 +102,14 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
 	struct scmi_smc *scmi_info = cinfo->transport_info;
 	struct arm_smccc_res res;
 
-	mutex_lock(&smc_mutex);
+	mutex_lock(&scmi_info->shmem_lock);
 
 	shmem_tx_prepare(scmi_info->shmem, xfer);
 
 	arm_smccc_1_1_invoke(scmi_info->func_id, 0, 0, 0, 0, 0, 0, 0, &res);
 	scmi_rx_callback(scmi_info->cinfo, shmem_read_header(scmi_info->shmem));
 
-	mutex_unlock(&smc_mutex);
+	mutex_unlock(&scmi_info->shmem_lock);
 
 	return res.a0;
 }
Signature · 1 line
2.17.1
#2 lore raw

RE: [PATCH 1/4] firmware: arm_scmi: Make mutex channel specific

Hi Sudeep,

Quoted 4 lines

Subject: [PATCH 1/4] firmware: arm_scmi: Make mutex channel specific

In order to support multiple SMC/HVC transport channels with associated shared memory,

Does this mean each channel will have its own shared memory? Or All channels share the same shared memory?

it is better to maintain the mutex per channel instead of

Quoted 1 line

existing global one.

If all channels shared the same memory, use per channel mutex lock will not be able to prevent other channels accessing shared memory at the same time.

Thanks,
Peng.

Quoted 56 lines

Move the smc_mutex into the scmi_smc structure and also rename it to shmem_lock which is more appropriate for it's use.

---
 drivers/firmware/arm_scmi/smc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/firmware/arm_scmi/smc.c index 336168e40f49..6dc8a88cc91b 100644

drivers/firmware/arm_scmi/smc.c +2 -2
@@ -27,11 +27,10 @@
 struct scmi_smc {
 	struct scmi_chan_info *cinfo;
 	struct scmi_shared_mem __iomem *shmem;
+	struct mutex shmem_lock;
 	u32 func_id;
 };
 
-static DEFINE_MUTEX(smc_mutex);
-
 static bool smc_chan_available(struct device *dev, int idx)  {
 	return true;
@@ -78,6 +77,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo,
 struct device *dev,
 
 	scmi_info->func_id = func_id;
 	scmi_info->cinfo = cinfo;
+	mutex_init(&scmi_info->shmem_lock);
 	cinfo->transport_info = scmi_info;
 
drivers/firmware/arm_scmi/smc.c +2 -2
 	return 0;
@@ -102,14 +102,14 @@ static int smc_send_message(struct
 scmi_chan_info *cinfo,
 	struct scmi_smc *scmi_info = cinfo->transport_info;
 	struct arm_smccc_res res;
 
-	mutex_lock(&smc_mutex);
+	mutex_lock(&scmi_info->shmem_lock);
 
 	shmem_tx_prepare(scmi_info->shmem, xfer);
 
 	arm_smccc_1_1_invoke(scmi_info->func_id, 0, 0, 0, 0, 0, 0, 0, &res);
 	scmi_rx_callback(scmi_info->cinfo,
 shmem_read_header(scmi_info->shmem));
 
-	mutex_unlock(&smc_mutex);
+	mutex_unlock(&scmi_info->shmem_lock);
 

return res.a0;
}
--
2.17.1

#3 lore raw

Re: [PATCH 1/4] firmware: arm_scmi: Make mutex channel specific

Quoted 10 lines · Peng Fan

Hi Sudeep,

Quoted 4 lines

Subject: [PATCH 1/4] firmware: arm_scmi: Make mutex channel specific

In order to support multiple SMC/HVC transport channels with associated shared memory,

Does this mean each channel will have its own shared memory? Or All channels share the same shared memory?

It depends on platform firmware and DT. If there is only one shmem at the top level scmi node, all share that single channel. If some/all protocols have their own channel, they there must be shmem entry in the corresponding child node.

Quoted 7 lines

it is better to maintain the mutex per channel instead of

Quoted 1 line

existing global one.

If all channels shared the same memory, use per channel mutex lock will not be able to prevent other channels accessing shared memory at the same time.

No we don't create channel per protocol. If they share, we just share the channel pointer. Look at:

       if (!info->desc->ops->chan_available(dev, idx)) {
                cinfo = idr_find(idr, SCMI_PROTOCOL_BASE);
                if (unlikely(!cinfo)) /* Possible only if platform has no Rx */
                        return -EINVAL;
                goto idr_alloc;
        }

If a protocol doesn't have a dedicated channel, we just assign the base protocol channel to it. We don't call chan_setup at all on that channel. Your patch assumed so but the core driver never did that.

Hope this clarifies you doubt.

--
Regards,
Sudeep

#4 lore raw

RE: [PATCH 1/4] firmware: arm_scmi: Make mutex channel specific

Quoted 37 lines

Subject: Re: [PATCH 1/4] firmware: arm_scmi: Make mutex channel specific

Quoted 10 lines · Peng Fan

Hi Sudeep,

Quoted 4 lines

Subject: [PATCH 1/4] firmware: arm_scmi: Make mutex channel specific

In order to support multiple SMC/HVC transport channels with associated shared memory,

Does this mean each channel will have its own shared memory? Or All channels share the same shared memory?

It depends on platform firmware and DT. If there is only one shmem at the top level scmi node, all share that single channel. If some/all protocols have their own channel, they there must be shmem entry in the corresponding child node.

Quoted 7 lines

it is better to maintain the mutex per channel instead of

Quoted 1 line

existing global one.

If all channels shared the same memory, use per channel mutex lock will not be able to prevent other channels accessing shared memory at the same time.

No we don't create channel per protocol. If they share, we just share the channel pointer. Look at:

       if (!info->desc->ops->chan_available(dev, idx)) {
                cinfo = idr_find(idr, SCMI_PROTOCOL_BASE);
                if (unlikely(!cinfo)) /* Possible only if platform has no Rx */
                        return -EINVAL;
                goto idr_alloc;
        }
Quoted 5 lines

If a protocol doesn't have a dedicated channel, we just assign the base protocol channel to it. We don't call chan_setup at all on that channel. Your patch assumed so but the core driver never did that.

Hope this clarifies you doubt.

Yes. Thanks for the explainaiton.

Thanks,
Peng.

Quoted 4 lines

--
Regards,
Sudeep

#5 lore raw

Re: [PATCH 1/4] firmware: arm_scmi: Make mutex channel specific

Quoted 37 lines · Peng Fan
Quoted 37 lines

Subject: Re: [PATCH 1/4] firmware: arm_scmi: Make mutex channel specific

Quoted 10 lines · Peng Fan

Hi Sudeep,

Quoted 4 lines

Subject: [PATCH 1/4] firmware: arm_scmi: Make mutex channel specific

In order to support multiple SMC/HVC transport channels with associated shared memory,

Does this mean each channel will have its own shared memory? Or All channels share the same shared memory?

It depends on platform firmware and DT. If there is only one shmem at the top level scmi node, all share that single channel. If some/all protocols have their own channel, they there must be shmem entry in the corresponding child node.

Quoted 7 lines

it is better to maintain the mutex per channel instead of

Quoted 1 line

existing global one.

If all channels shared the same memory, use per channel mutex lock will not be able to prevent other channels accessing shared memory at the same time.

No we don't create channel per protocol. If they share, we just share the channel pointer. Look at:

       if (!info->desc->ops->chan_available(dev, idx)) {
                cinfo = idr_find(idr, SCMI_PROTOCOL_BASE);
                if (unlikely(!cinfo)) /* Possible only if platform has no Rx */
                        return -EINVAL;
                goto idr_alloc;
        }
Quoted 8 lines
Quoted 5 lines

If a protocol doesn't have a dedicated channel, we just assign the base protocol channel to it. We don't call chan_setup at all on that channel. Your patch assumed so but the core driver never did that.

Hope this clarifies you doubt.

Yes. Thanks for the explainaiton.

No worries, I should have seen this during initial review, just missed few trivial things.

--
Regards,
Sudeep

Reviewed-by on v1 1/4
#6 lore raw

RE: [PATCH 1/4] firmware: arm_scmi: Make mutex channel specific

In reply to Sudeep Holla
Quoted 10 lines

Subject: [PATCH 1/4] firmware: arm_scmi: Make mutex channel specific

In order to support multiple SMC/HVC transport channels with associated shared memory, it is better to maintain the mutex per channel instead of existing global one.

Move the smc_mutex into the scmi_smc structure and also rename it to shmem_lock which is more appropriate for it's use.

Quoted 51 lines
---
 drivers/firmware/arm_scmi/smc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/firmware/arm_scmi/smc.c index 336168e40f49..6dc8a88cc91b 100644

drivers/firmware/arm_scmi/smc.c +2 -2
@@ -27,11 +27,10 @@
 struct scmi_smc {
 	struct scmi_chan_info *cinfo;
 	struct scmi_shared_mem __iomem *shmem;
+	struct mutex shmem_lock;
 	u32 func_id;
 };
 
-static DEFINE_MUTEX(smc_mutex);
-
 static bool smc_chan_available(struct device *dev, int idx)  {
 	return true;
@@ -78,6 +77,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo,
 struct device *dev,
 
 	scmi_info->func_id = func_id;
 	scmi_info->cinfo = cinfo;
+	mutex_init(&scmi_info->shmem_lock);
 	cinfo->transport_info = scmi_info;
 
drivers/firmware/arm_scmi/smc.c +2 -2
 	return 0;
@@ -102,14 +102,14 @@ static int smc_send_message(struct
 scmi_chan_info *cinfo,
 	struct scmi_smc *scmi_info = cinfo->transport_info;
 	struct arm_smccc_res res;
 
-	mutex_lock(&smc_mutex);
+	mutex_lock(&scmi_info->shmem_lock);
 
 	shmem_tx_prepare(scmi_info->shmem, xfer);
 
 	arm_smccc_1_1_invoke(scmi_info->func_id, 0, 0, 0, 0, 0, 0, 0, &res);
 	scmi_rx_callback(scmi_info->cinfo,
 shmem_read_header(scmi_info->shmem));
 
-	mutex_unlock(&smc_mutex);
+	mutex_unlock(&scmi_info->shmem_lock);
 

return res.a0;
}
--
2.17.1

#7 lore raw

PATCH 2/4 firmware: arm_scmi: Drop empty stub for smc_mark_txdone

In reply to Sudeep Holla

The scmi protocol core driver check for non NULL mark_txdone before invoking the same. There is no need to provide a empty stub. SMC/HVC calls are synchronous and the call return indicates the completion.

---
 drivers/firmware/arm_scmi/smc.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/firmware/arm_scmi/smc.c +0 -5
index 6dc8a88cc91b..dd4b54c29679 100644
@@ -114,10 +114,6 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
 	return res.a0;
 }
 
-static void smc_mark_txdone(struct scmi_chan_info *cinfo, int ret)
-{
-}
-
 static void smc_fetch_response(struct scmi_chan_info *cinfo,
 			       struct scmi_xfer *xfer)
 {
@@ -139,7 +135,6 @@ static struct scmi_transport_ops scmi_smc_ops = {
 	.chan_setup = smc_chan_setup,
 	.chan_free = smc_chan_free,
 	.send_message = smc_send_message,
-	.mark_txdone = smc_mark_txdone,
 	.fetch_response = smc_fetch_response,
 	.poll_done = smc_poll_done,
 };
Signature · 1 line
2.17.1
Reviewed-by on v1 2/4
#8 lore raw

RE: [PATCH 2/4] firmware: arm_scmi: Drop empty stub for smc_mark_txdone

Quoted 8 lines

Subject: [PATCH 2/4] firmware: arm_scmi: Drop empty stub for smc_mark_txdone

The scmi protocol core driver check for non NULL mark_txdone before invoking the same. There is no need to provide a empty stub. SMC/HVC calls are synchronous and the call return indicates the completion.

Quoted 29 lines
---
 drivers/firmware/arm_scmi/smc.c | 5 -----
 1 file changed, 5 deletions(-)
(quoted diff) +0 -0

b/drivers/firmware/arm_scmi/smc.c index 6dc8a88cc91b..dd4b54c29679 100644

drivers/firmware/arm_scmi/smc.c +0 -4
@@ -114,10 +114,6 @@ static int smc_send_message(struct scmi_chan_info
 *cinfo,
 	return res.a0;
 }
 
-static void smc_mark_txdone(struct scmi_chan_info *cinfo, int ret) -{ -}
-
 static void smc_fetch_response(struct scmi_chan_info *cinfo,
 			       struct scmi_xfer *xfer)
 {
@@ -139,7 +135,6 @@ static struct scmi_transport_ops scmi_smc_ops = {
 	.chan_setup = smc_chan_setup,
 	.chan_free = smc_chan_free,
 	.send_message = smc_send_message,
-	.mark_txdone = smc_mark_txdone,
 	.fetch_response = smc_fetch_response,
 	.poll_done = smc_poll_done,
 };
--

2.17.1

#9 lore raw

PATCH 3/4 firmware: arm_scmi: Check shmem property for channel availablity

In reply to Sudeep Holla

Instead of declaring the channel availabilty unconditionally, let us check for the presence of "shmem" property and return the channel availablity accordingly.

---
 drivers/firmware/arm_scmi/smc.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/firmware/arm_scmi/smc.c +5 -0
index dd4b54c29679..5929c668dc1d 100644
@@ -33,6 +33,11 @@ struct scmi_smc {
 
 static bool smc_chan_available(struct device *dev, int idx)
 {
+	struct device_node *np = of_parse_phandle(dev->of_node, "shmem", 0);
+	if (!np)
+		return false;
+
+	of_node_put(np);
 	return true;
 }
 
Signature · 1 line
2.17.1
Reviewed-by on v1 3/4
#10 lore raw

RE: [PATCH 3/4] firmware: arm_scmi: Check shmem property for channel availablity

Quoted 18 lines

Subject: [PATCH 3/4] firmware: arm_scmi: Check shmem property for channel availablity

Instead of declaring the channel availabilty unconditionally, let us check for the presence of "shmem" property and return the channel availablity accordingly.

---
 drivers/firmware/arm_scmi/smc.c | 5 +++++
 1 file changed, 5 insertions(+)
(quoted diff) +0 -0

b/drivers/firmware/arm_scmi/smc.c index dd4b54c29679..5929c668dc1d 100644

drivers/firmware/arm_scmi/smc.c struct scmi_smc { · line 41

Quoted 9 lines
drivers/firmware/arm_scmi/smc.c +5 -0
@@ -33,6 +33,11 @@ struct scmi_smc {
 
 static bool smc_chan_available(struct device *dev, int idx)  {
+	struct device_node *np = of_parse_phandle(dev->of_node, "shmem", 0);
+	if (!np)
+		return false;
+
+	of_node_put(np);
 	return true;
 }

This is global shared mem:)

Quoted 3 lines
drivers/firmware/arm_scmi/smc.c +0 -1
--

2.17.1

#11 lore raw

Re: [PATCH 3/4] firmware: arm_scmi: Check shmem property for channel availablity

Quoted 19 lines · Peng Fan
Quoted 19 lines

Subject: [PATCH 3/4] firmware: arm_scmi: Check shmem property for channel availablity

Instead of declaring the channel availabilty unconditionally, let us check for the presence of "shmem" property and return the channel availablity accordingly.

---
 drivers/firmware/arm_scmi/smc.c | 5 +++++
 1 file changed, 5 insertions(+)
(quoted diff) +0 -0

b/drivers/firmware/arm_scmi/smc.c index dd4b54c29679..5929c668dc1d 100644

drivers/firmware/arm_scmi/smc.c +0 -0
@@ -33,6 +33,11 @@ struct scmi_smc {
 
Quoted 11 lines

drivers/firmware/arm_scmi/smc.c struct scmi_smc { · line 42

Quoted 8 lines
drivers/firmware/arm_scmi/smc.c +5 -0
 static bool smc_chan_available(struct device *dev, int idx)  {
+	struct device_node *np = of_parse_phandle(dev->of_node, "shmem", 0);
+	if (!np)
+		return false;
+
+	of_node_put(np);
 	return true;
 }

This is global shared mem:)

No, the dev pointer is not the parent node here but the child devices unless I am reading it wrong. But yes global for the base protocol :)

Quoted 2 lines

Thanks for this and other patches too.

--
Regards,
Sudeep

#12 lore raw

PATCH 4/4 firmware: arm_scmi: Drop checking for shmem property in parent node

In reply to Sudeep Holla

The scmi protocol core driver checks for the channel availability before evaluating the shmem property. If the individual protocols don't have separate channel assigned to them, the channel alloted for the BASE protocol is reused automatically.

Therefore there is no need to check for the shmem property in the parent node if it is absent in the child protocol node.

---
 drivers/firmware/arm_scmi/smc.c | 2 --
 1 file changed, 2 deletions(-)
drivers/firmware/arm_scmi/smc.c +0 -2
index 5929c668dc1d..833e793b5391 100644
@@ -60,8 +60,6 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 		return -ENOMEM;
 
 	np = of_parse_phandle(cdev->of_node, "shmem", 0);
-	if (!np)
-		np = of_parse_phandle(dev->of_node, "shmem", 0);
 	ret = of_address_to_resource(np, 0, &res);
 	of_node_put(np);
 	if (ret) {
Signature · 1 line
2.17.1
Reviewed-by on v1 4/4
#13 lore raw

RE: [PATCH 4/4] firmware: arm_scmi: Drop checking for shmem property in parent node

Quoted 17 lines

-----Original Message-----
From: Sudeep Holla <[email protected]>
Sent: 2020年3月28日 0:37
To: [email protected]; [email protected]; Peng Fan <[email protected]>
Cc: Sudeep Holla <[email protected]>; [email protected]; dl-linux-imx <[email protected]>
Subject: [PATCH 4/4] firmware: arm_scmi: Drop checking for shmem property in parent node

The scmi protocol core driver checks for the channel availability before evaluating the shmem property. If the individual protocols don't have separate channel assigned to them, the channel alloted for the BASE protocol is reused automatically.

Quoted 4 lines

Therefore there is no need to check for the shmem property in the parent node if it is absent in the child protocol node.

Quoted 21 lines
---
 drivers/firmware/arm_scmi/smc.c | 2 --
 1 file changed, 2 deletions(-)
(quoted diff) +0 -0

b/drivers/firmware/arm_scmi/smc.c index 5929c668dc1d..833e793b5391 100644

drivers/firmware/arm_scmi/smc.c +0 -2
@@ -60,8 +60,6 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo,
 struct device *dev,
 		return -ENOMEM;
 
 	np = of_parse_phandle(cdev->of_node, "shmem", 0);
-	if (!np)
-		np = of_parse_phandle(dev->of_node, "shmem", 0);
 	ret = of_address_to_resource(np, 0, &res);
 	of_node_put(np);

if (ret) {
--
2.17.1

Tested-by on the v1 series
#14 lore raw
In reply to Sudeep Holla
Quoted 10 lines

Subject: [PATCH 0/4] firmware: arm_scmi: Extend SMC/HVC to support multiple channels

Hi,

While merging SMC/HVC transport to SCMI, I did a quick hack to extend it to support multiple channels. I may be missing something obvious, if not the changes required look simple. Some of them could be merged into original patch, but since I am unable to test, I preferred to keep them separate, easy to revert if things break.

With patchset applied to your scmi tree, my test still work as before.

Thanks,
Peng.

Quoted 16 lines

Regards,
Sudeep
--

Sudeep Holla (4):
firmware: arm_scmi: Make mutex channel specific
firmware: arm_scmi: Drop empty stub for smc_mark_txdone
firmware: arm_scmi: Check shmem property for channel availablity
firmware: arm_scmi: Drop checking for shmem property in parent node

 drivers/firmware/arm_scmi/smc.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

--
2.17.1

#15 lore raw

Hi Peng,

Quoted 11 lines · Peng Fan
Quoted 10 lines

Subject: [PATCH 0/4] firmware: arm_scmi: Extend SMC/HVC to support multiple channels

Hi,

While merging SMC/HVC transport to SCMI, I did a quick hack to extend it to support multiple channels. I may be missing something obvious, if not the changes required look simple. Some of them could be merged into original patch, but since I am unable to test, I preferred to keep them separate, easy to revert if things break.

Quoted 4 lines

With patchset applied to your scmi tree, my test still work as before.

Thanks for testing. If you can give it a quick review as it is very small change, that would be great. I just want more eyes to look at it just to make sure I am not missing something obvious.

--
Regards,
Sudeep