linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Sudeep Holla <sudeep.holla@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Peng Fan <peng.fan@nxp.com>,
	linux-kernel@vger.kernel.org,
	Bo Zhang <bozhang.zhang@broadcom.com>,
	Jim Quinlan <james.quinlan@broadcom.com>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Subject: [PATCH 03/11] firmware: arm_scmi: Add receive channel support for notifications
Date: Mon,  8 Jul 2019 16:47:22 +0100	[thread overview]
Message-ID: <20190708154730.16643-4-sudeep.holla@arm.com> (raw)
In-Reply-To: <20190708154730.16643-1-sudeep.holla@arm.com>

With scmi_mbox_chan_setup enabled to identify and setup both Tx and Rx,
let's consolidate setting up of both the channels under the function
scmi_mbox_txrx_setup.

Since some platforms may opt not to support notifications or delayed
response, they may not need support for Rx. Hence Rx is optional and
failure of setting one up is not considered fatal.

Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/firmware/arm_scmi/driver.c | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index f7fb6d5bfc64..e9b762348eff 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -113,6 +113,7 @@ struct scmi_chan_info {
  *	implementation version and (sub-)vendor identification.
  * @minfo: Message info
  * @tx_idr: IDR object to map protocol id to Tx channel info pointer
+ * @rx_idr: IDR object to map protocol id to Rx channel info pointer
  * @protocols_imp: List of protocols implemented, currently maximum of
  *	MAX_PROTOCOLS_IMP elements allocated by the base protocol
  * @node: List head
@@ -125,6 +126,7 @@ struct scmi_info {
 	struct scmi_handle handle;
 	struct scmi_xfers_info minfo;
 	struct idr tx_idr;
+	struct idr rx_idr;
 	u8 *protocols_imp;
 	struct list_head node;
 	int users;
@@ -655,12 +657,16 @@ static int scmi_mbox_chan_setup(struct scmi_info *info, struct device *dev,
 	struct device_node *shmem, *np = dev->of_node;
 	struct scmi_chan_info *cinfo;
 	struct mbox_client *cl;
+	struct idr *idr;
 
 	/* Transmit channel is first entry i.e. index 0 */
 	idx = tx ? 0 : 1;
+	idr = tx ? &info->tx_idr : &info->rx_idr;
 
 	if (scmi_mailbox_check(np, idx)) {
-		cinfo = idr_find(&info->tx_idr, SCMI_PROTOCOL_BASE);
+		cinfo = idr_find(idr, SCMI_PROTOCOL_BASE);
+		if (unlikely(!cinfo)) /* Possible only if platform has no Rx */
+			return -EINVAL;
 		goto idr_alloc;
 	}
 
@@ -701,7 +707,7 @@ static int scmi_mbox_chan_setup(struct scmi_info *info, struct device *dev,
 	}
 
 idr_alloc:
-	ret = idr_alloc(&info->tx_idr, cinfo, prot_id, prot_id + 1, GFP_KERNEL);
+	ret = idr_alloc(idr, cinfo, prot_id, prot_id + 1, GFP_KERNEL);
 	if (ret != prot_id) {
 		dev_err(dev, "unable to allocate SCMI idr slot err %d\n", ret);
 		return ret;
@@ -711,6 +717,17 @@ static int scmi_mbox_chan_setup(struct scmi_info *info, struct device *dev,
 	return 0;
 }
 
+static inline int
+scmi_mbox_txrx_setup(struct scmi_info *info, struct device *dev, int prot_id)
+{
+	int ret = scmi_mbox_chan_setup(info, dev, prot_id, true);
+
+	if (!ret) /* Rx is optional, hence no error check */
+		scmi_mbox_chan_setup(info, dev, prot_id, false);
+
+	return ret;
+}
+
 static inline void
 scmi_create_protocol_device(struct device_node *np, struct scmi_info *info,
 			    int prot_id)
@@ -724,7 +741,7 @@ scmi_create_protocol_device(struct device_node *np, struct scmi_info *info,
 		return;
 	}
 
-	if (scmi_mbox_chan_setup(info, &sdev->dev, prot_id, true)) {
+	if (scmi_mbox_txrx_setup(info, &sdev->dev, prot_id)) {
 		dev_err(&sdev->dev, "failed to setup transport\n");
 		scmi_device_destroy(sdev);
 		return;
@@ -767,12 +784,13 @@ static int scmi_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, info);
 	idr_init(&info->tx_idr);
+	idr_init(&info->rx_idr);
 
 	handle = &info->handle;
 	handle->dev = info->dev;
 	handle->version = &info->version;
 
-	ret = scmi_mbox_chan_setup(info, dev, SCMI_PROTOCOL_BASE, true);
+	ret = scmi_mbox_txrx_setup(info, dev, SCMI_PROTOCOL_BASE);
 	if (ret)
 		return ret;
 
@@ -842,6 +860,10 @@ static int scmi_remove(struct platform_device *pdev)
 	ret = idr_for_each(idr, scmi_mbox_free_channel, idr);
 	idr_destroy(&info->tx_idr);
 
+	idr = &info->rx_idr;
+	ret = idr_for_each(idr, scmi_mbox_free_channel, idr);
+	idr_destroy(&info->rx_idr);
+
 	return ret;
 }
 
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2019-07-08 15:48 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-08 15:47 [PATCH 00/11] firmware: arm_scmi: Add support for Rx, async commands and delayed response Sudeep Holla
2019-07-08 15:47 ` [PATCH 01/11] firmware: arm_scmi: Reorder some functions to avoid forward declarations Sudeep Holla
2019-07-08 15:47 ` [PATCH 02/11] firmware: arm_scmi: Segregate tx channel handling and prepare to add rx Sudeep Holla
2019-07-18 21:23   ` Jim Quinlan
2019-07-19 10:26     ` Sudeep Holla
2019-07-08 15:47 ` Sudeep Holla [this message]
2019-07-08 15:47 ` [PATCH 04/11] firmware: arm_scmi: Separate out tx buffer " Sudeep Holla
2019-07-08 15:47 ` [PATCH 05/11] firmware: arm_scmi: Add receive buffer support for notifications Sudeep Holla
2019-07-18 21:24   ` Jim Quinlan
     [not found]   ` <CA+-6iNz26xUyrzVSbWA+jwEfj3BC8k8KNCg2SreDK7mfWsbAWg@mail.gmail.com>
2019-07-19 10:29     ` Sudeep Holla
2019-07-08 15:47 ` [PATCH 06/11] firmware: arm_scmi: Add mechanism to unpack message headers Sudeep Holla
2019-07-08 15:47 ` [PATCH 07/11] firmware: arm_scmi: Add support for asynchronous commands and delayed response Sudeep Holla
2019-07-18 21:38   ` Jim Quinlan
2019-07-19 11:03     ` Sudeep Holla
2019-07-19 20:16       ` Jim Quinlan
2019-07-22 13:08         ` Sudeep Holla
2019-07-08 15:47 ` [PATCH 08/11] firmware: arm_scmi: Drop async flag in sensor_ops->reading_get Sudeep Holla
2019-07-08 16:05   ` Guenter Roeck
2019-07-08 15:47 ` [PATCH 09/11] firmware: arm_scmi: Add asynchronous sensor read if it supports Sudeep Holla
2019-07-08 15:47 ` [PATCH 10/11] firmware: arm_scmi: Drop config flag in clk_ops->rate_set Sudeep Holla
2019-07-22 21:30   ` Stephen Boyd
2019-07-08 15:47 ` [PATCH 11/11] firmware: arm_scmi: Use asynchronous CLOCK_RATE_SET when possible Sudeep Holla
2019-07-22 21:29   ` Stephen Boyd
2019-07-23 10:59     ` Sudeep Holla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190708154730.16643-4-sudeep.holla@arm.com \
    --to=sudeep.holla@arm.com \
    --cc=bozhang.zhang@broadcom.com \
    --cc=james.quinlan@broadcom.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peng.fan@nxp.com \
    --cc=volodymyr_babchuk@epam.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).