From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F252C388F7 for ; Thu, 5 Nov 2020 21:28:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1D0F20735 for ; Thu, 5 Nov 2020 21:28:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732439AbgKEV2h (ORCPT ); Thu, 5 Nov 2020 16:28:37 -0500 Received: from plasma4.jpberlin.de ([80.241.57.33]:49279 "EHLO plasma4.jpberlin.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732046AbgKEV2O (ORCPT ); Thu, 5 Nov 2020 16:28:14 -0500 Received: from spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) by plasma.jpberlin.de (Postfix) with ESMTP id 7B8F6AB751; Thu, 5 Nov 2020 22:21:46 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from plasma.jpberlin.de ([80.241.56.68]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id TLcSij56-UPX; Thu, 5 Nov 2020 22:21:45 +0100 (CET) Received: from webmail.opensynergy.com (unknown [217.66.60.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client CN "*.opensynergy.com", Issuer "Starfield Secure Certificate Authority - G2" (not verified)) (Authenticated sender: opensynergy@jpberlin.de) by plasma.jpberlin.de (Postfix) with ESMTPSA id 49265AB788; Thu, 5 Nov 2020 22:21:45 +0100 (CET) From: Peter Hilber To: , CC: Igor Skalkin , Peter Hilber , Rob Herring , , , , , , , Subject: [RFC PATCH v2 03/10] firmware: arm_scmi: Add op to override max message # Date: Thu, 5 Nov 2020 22:21:09 +0100 Message-ID: <20201105212116.411422-4-peter.hilber@opensynergy.com> In-Reply-To: <20201105212116.411422-1-peter.hilber@opensynergy.com> References: <20201105212116.411422-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-01.open-synergy.com (10.26.10.21) X-MBO-SPAM-Probability: X-Rspamd-Score: -3.39 / 15.00 / 15.00 X-Rspamd-Queue-Id: 7B8F6AB751 X-Rspamd-UID: 3f77b1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Igor Skalkin The number of messages that the upcoming scmi-virtio transport can support depends on the virtio device (SCMI platform) and can differ for each channel. (The scmi-virtio transport does only have one tx and at most 1 rx channel.) Add an optional transport op so that scmi-virtio can report the actual max message # for each channel type. Respect these new limits. Co-developed-by: Peter Hilber Signed-off-by: Peter Hilber Signed-off-by: Igor Skalkin --- drivers/firmware/arm_scmi/common.h | 8 ++++- drivers/firmware/arm_scmi/driver.c | 49 ++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 38e6aabbe3dd..9a8359ecd220 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -203,6 +203,9 @@ struct scmi_chan_info { * @chan_available: Callback to check if channel is available or not * @chan_setup: Callback to allocate and setup a channel * @chan_free: Callback to free a channel + * @get_max_msg: Optional callback to provide max_msg dynamically + * @max_msg: Maximum number of messages for the channel type (tx or rx) + * that can be pending simultaneously in the system * @send_message: Callback to send a message * @mark_txdone: Callback to mark tx as done * @fetch_response: Callback to fetch response @@ -215,6 +218,8 @@ struct scmi_transport_ops { int (*chan_setup)(struct scmi_chan_info *cinfo, struct device *dev, bool tx); int (*chan_free)(int id, void *p, void *data); + int (*get_max_msg)(bool tx, struct scmi_chan_info *base_cinfo, + int *max_msg); int (*send_message)(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer); void (*mark_txdone)(struct scmi_chan_info *cinfo, int ret); @@ -232,7 +237,8 @@ struct scmi_transport_ops { * @ops: Pointer to the transport specific ops structure * @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds) * @max_msg: Maximum number of messages for a channel type (tx or rx) that can - * be pending simultaneously in the system + * be pending simultaneously in the system. May be overridden by the + * get_max_msg op. * @max_msg_size: Maximum size of data per message that can be handled. */ struct scmi_desc { diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 9e2f36127793..e2faa526dfce 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -61,11 +61,13 @@ static atomic_t transfer_last_id; * Index of this bitmap table is also used for message * sequence identifier. * @xfer_lock: Protection for message allocation + * @max_msg: Maximum number of messages that can be pending */ struct scmi_xfers_info { struct scmi_xfer *xfer_block; unsigned long *xfer_alloc_table; spinlock_t xfer_lock; + int max_msg; }; /** @@ -157,13 +159,11 @@ static struct scmi_xfer *scmi_xfer_get(const struct scmi_handle *handle, u16 xfer_id; struct scmi_xfer *xfer; unsigned long flags, bit_pos; - struct scmi_info *info = handle_to_scmi_info(handle); /* Keep the locked section as small as possible */ spin_lock_irqsave(&minfo->xfer_lock, flags); - bit_pos = find_first_zero_bit(minfo->xfer_alloc_table, - info->desc->max_msg); - if (bit_pos == info->desc->max_msg) { + bit_pos = find_first_zero_bit(minfo->xfer_alloc_table, minfo->max_msg); + if (bit_pos == minfo->max_msg) { spin_unlock_irqrestore(&minfo->xfer_lock, flags); return ERR_PTR(-ENOMEM); } @@ -602,32 +602,44 @@ int scmi_handle_put(const struct scmi_handle *handle) } static int __scmi_xfer_info_init(struct scmi_info *sinfo, - struct scmi_xfers_info *info) + struct scmi_xfers_info *info, + bool tx, + struct scmi_chan_info *base_cinfo) { int i; struct scmi_xfer *xfer; struct device *dev = sinfo->dev; const struct scmi_desc *desc = sinfo->desc; + info->max_msg = desc->max_msg; + + if (desc->ops->get_max_msg) { + int ret = + desc->ops->get_max_msg(tx, base_cinfo, &info->max_msg); + + if (ret) + return ret; + } + /* Pre-allocated messages, no more than what hdr.seq can support */ - if (WARN_ON(desc->max_msg >= MSG_TOKEN_MAX)) { + if (WARN_ON(info->max_msg >= MSG_TOKEN_MAX)) { dev_err(dev, "Maximum message of %d exceeds supported %ld\n", - desc->max_msg, MSG_TOKEN_MAX); + info->max_msg, MSG_TOKEN_MAX); return -EINVAL; } - info->xfer_block = devm_kcalloc(dev, desc->max_msg, + info->xfer_block = devm_kcalloc(dev, info->max_msg, sizeof(*info->xfer_block), GFP_KERNEL); if (!info->xfer_block) return -ENOMEM; - info->xfer_alloc_table = devm_kcalloc(dev, BITS_TO_LONGS(desc->max_msg), + info->xfer_alloc_table = devm_kcalloc(dev, BITS_TO_LONGS(info->max_msg), sizeof(long), GFP_KERNEL); if (!info->xfer_alloc_table) return -ENOMEM; /* Pre-initialize the buffer pointer to pre-allocated buffers */ - for (i = 0, xfer = info->xfer_block; i < desc->max_msg; i++, xfer++) { + for (i = 0, xfer = info->xfer_block; i < info->max_msg; i++, xfer++) { xfer->rx.buf = devm_kcalloc(dev, sizeof(u8), desc->max_msg_size, GFP_KERNEL); if (!xfer->rx.buf) @@ -644,10 +656,21 @@ static int __scmi_xfer_info_init(struct scmi_info *sinfo, static int scmi_xfer_info_init(struct scmi_info *sinfo) { - int ret = __scmi_xfer_info_init(sinfo, &sinfo->tx_minfo); + int ret; + struct scmi_chan_info *base_tx_cinfo; + struct scmi_chan_info *base_rx_cinfo; + + base_tx_cinfo = idr_find(&sinfo->tx_idr, SCMI_PROTOCOL_BASE); + if (unlikely(!base_tx_cinfo)) + return -EINVAL; + + ret = __scmi_xfer_info_init(sinfo, &sinfo->tx_minfo, true, + base_tx_cinfo); - if (!ret && idr_find(&sinfo->rx_idr, SCMI_PROTOCOL_BASE)) - ret = __scmi_xfer_info_init(sinfo, &sinfo->rx_minfo); + base_rx_cinfo = idr_find(&sinfo->rx_idr, SCMI_PROTOCOL_BASE); + if (!ret && base_rx_cinfo) + ret = __scmi_xfer_info_init(sinfo, &sinfo->rx_minfo, false, + base_rx_cinfo); return ret; } -- 2.25.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29715C4741F for ; Thu, 5 Nov 2020 21:23:59 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 98A8720724 for ; Thu, 5 Nov 2020 21:23:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="zyfOXc+G" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98A8720724 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=T5+BRhr7NbH/u3cYdnJ8nOCW+/45ADmQqxqkI+hyjms=; b=zyfOXc+G60L6pqciFfwHnaGmn Xsq8BRJWNWRSIZxUDHlOmD/5hjfUMM5aGTe4/IE/tX0fJtw81fw97nU1Xe9JC8yUcqbdt0JjZ+B9t V3+aHG6bnS7J7v0jU6rxEZQzKKX8oseJqrrKQA62zVpEXBtssr4GAQwXdq6pSSimjckGqpc7BYscC mDQ5ltSnxWzDkwvp3I70an3kUQ0CeIzm2W9RcZrxD+O45C7DaG2ed6I5eTNU1QJk3IgD+B72jCUdL Ki60ihDJkCVj7qj7oWFfiIA4wJxkIh8J69Dx5km3hYJeXjtlFccNE/riSLRZr8k9CJXLBzar2aq7L VqVvj6T5Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kamhl-0003t0-Hs; Thu, 05 Nov 2020 21:22:01 +0000 Received: from plasma4.jpberlin.de ([80.241.57.33]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kamhb-0003oh-OR for linux-arm-kernel@lists.infradead.org; Thu, 05 Nov 2020 21:21:54 +0000 Received: from spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) by plasma.jpberlin.de (Postfix) with ESMTP id 7B8F6AB751; Thu, 5 Nov 2020 22:21:46 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from plasma.jpberlin.de ([80.241.56.68]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id TLcSij56-UPX; Thu, 5 Nov 2020 22:21:45 +0100 (CET) Received: from webmail.opensynergy.com (unknown [217.66.60.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client CN "*.opensynergy.com", Issuer "Starfield Secure Certificate Authority - G2" (not verified)) (Authenticated sender: opensynergy@jpberlin.de) by plasma.jpberlin.de (Postfix) with ESMTPSA id 49265AB788; Thu, 5 Nov 2020 22:21:45 +0100 (CET) From: Peter Hilber To: , Subject: [RFC PATCH v2 03/10] firmware: arm_scmi: Add op to override max message # Date: Thu, 5 Nov 2020 22:21:09 +0100 Message-ID: <20201105212116.411422-4-peter.hilber@opensynergy.com> In-Reply-To: <20201105212116.411422-1-peter.hilber@opensynergy.com> References: <20201105212116.411422-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-01.open-synergy.com (10.26.10.21) X-MBO-SPAM-Probability: X-Rspamd-Score: -3.39 / 15.00 / 15.00 X-Rspamd-Queue-Id: 7B8F6AB751 X-Rspamd-UID: 3f77b1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201105_162151_967922_91B0066B X-CRM114-Status: GOOD ( 22.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jean-philippe@linaro.org, mikhail.golubev@opensynergy.com, souvik.chakravarty@arm.com, Igor Skalkin , linux-kernel@vger.kernel.org, Rob Herring , Peter Hilber , anton.yakovlev@opensynergy.com, sudeep.holla@arm.com, alex.bennee@linaro.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Igor Skalkin The number of messages that the upcoming scmi-virtio transport can support depends on the virtio device (SCMI platform) and can differ for each channel. (The scmi-virtio transport does only have one tx and at most 1 rx channel.) Add an optional transport op so that scmi-virtio can report the actual max message # for each channel type. Respect these new limits. Co-developed-by: Peter Hilber Signed-off-by: Peter Hilber Signed-off-by: Igor Skalkin --- drivers/firmware/arm_scmi/common.h | 8 ++++- drivers/firmware/arm_scmi/driver.c | 49 ++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 38e6aabbe3dd..9a8359ecd220 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -203,6 +203,9 @@ struct scmi_chan_info { * @chan_available: Callback to check if channel is available or not * @chan_setup: Callback to allocate and setup a channel * @chan_free: Callback to free a channel + * @get_max_msg: Optional callback to provide max_msg dynamically + * @max_msg: Maximum number of messages for the channel type (tx or rx) + * that can be pending simultaneously in the system * @send_message: Callback to send a message * @mark_txdone: Callback to mark tx as done * @fetch_response: Callback to fetch response @@ -215,6 +218,8 @@ struct scmi_transport_ops { int (*chan_setup)(struct scmi_chan_info *cinfo, struct device *dev, bool tx); int (*chan_free)(int id, void *p, void *data); + int (*get_max_msg)(bool tx, struct scmi_chan_info *base_cinfo, + int *max_msg); int (*send_message)(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer); void (*mark_txdone)(struct scmi_chan_info *cinfo, int ret); @@ -232,7 +237,8 @@ struct scmi_transport_ops { * @ops: Pointer to the transport specific ops structure * @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds) * @max_msg: Maximum number of messages for a channel type (tx or rx) that can - * be pending simultaneously in the system + * be pending simultaneously in the system. May be overridden by the + * get_max_msg op. * @max_msg_size: Maximum size of data per message that can be handled. */ struct scmi_desc { diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 9e2f36127793..e2faa526dfce 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -61,11 +61,13 @@ static atomic_t transfer_last_id; * Index of this bitmap table is also used for message * sequence identifier. * @xfer_lock: Protection for message allocation + * @max_msg: Maximum number of messages that can be pending */ struct scmi_xfers_info { struct scmi_xfer *xfer_block; unsigned long *xfer_alloc_table; spinlock_t xfer_lock; + int max_msg; }; /** @@ -157,13 +159,11 @@ static struct scmi_xfer *scmi_xfer_get(const struct scmi_handle *handle, u16 xfer_id; struct scmi_xfer *xfer; unsigned long flags, bit_pos; - struct scmi_info *info = handle_to_scmi_info(handle); /* Keep the locked section as small as possible */ spin_lock_irqsave(&minfo->xfer_lock, flags); - bit_pos = find_first_zero_bit(minfo->xfer_alloc_table, - info->desc->max_msg); - if (bit_pos == info->desc->max_msg) { + bit_pos = find_first_zero_bit(minfo->xfer_alloc_table, minfo->max_msg); + if (bit_pos == minfo->max_msg) { spin_unlock_irqrestore(&minfo->xfer_lock, flags); return ERR_PTR(-ENOMEM); } @@ -602,32 +602,44 @@ int scmi_handle_put(const struct scmi_handle *handle) } static int __scmi_xfer_info_init(struct scmi_info *sinfo, - struct scmi_xfers_info *info) + struct scmi_xfers_info *info, + bool tx, + struct scmi_chan_info *base_cinfo) { int i; struct scmi_xfer *xfer; struct device *dev = sinfo->dev; const struct scmi_desc *desc = sinfo->desc; + info->max_msg = desc->max_msg; + + if (desc->ops->get_max_msg) { + int ret = + desc->ops->get_max_msg(tx, base_cinfo, &info->max_msg); + + if (ret) + return ret; + } + /* Pre-allocated messages, no more than what hdr.seq can support */ - if (WARN_ON(desc->max_msg >= MSG_TOKEN_MAX)) { + if (WARN_ON(info->max_msg >= MSG_TOKEN_MAX)) { dev_err(dev, "Maximum message of %d exceeds supported %ld\n", - desc->max_msg, MSG_TOKEN_MAX); + info->max_msg, MSG_TOKEN_MAX); return -EINVAL; } - info->xfer_block = devm_kcalloc(dev, desc->max_msg, + info->xfer_block = devm_kcalloc(dev, info->max_msg, sizeof(*info->xfer_block), GFP_KERNEL); if (!info->xfer_block) return -ENOMEM; - info->xfer_alloc_table = devm_kcalloc(dev, BITS_TO_LONGS(desc->max_msg), + info->xfer_alloc_table = devm_kcalloc(dev, BITS_TO_LONGS(info->max_msg), sizeof(long), GFP_KERNEL); if (!info->xfer_alloc_table) return -ENOMEM; /* Pre-initialize the buffer pointer to pre-allocated buffers */ - for (i = 0, xfer = info->xfer_block; i < desc->max_msg; i++, xfer++) { + for (i = 0, xfer = info->xfer_block; i < info->max_msg; i++, xfer++) { xfer->rx.buf = devm_kcalloc(dev, sizeof(u8), desc->max_msg_size, GFP_KERNEL); if (!xfer->rx.buf) @@ -644,10 +656,21 @@ static int __scmi_xfer_info_init(struct scmi_info *sinfo, static int scmi_xfer_info_init(struct scmi_info *sinfo) { - int ret = __scmi_xfer_info_init(sinfo, &sinfo->tx_minfo); + int ret; + struct scmi_chan_info *base_tx_cinfo; + struct scmi_chan_info *base_rx_cinfo; + + base_tx_cinfo = idr_find(&sinfo->tx_idr, SCMI_PROTOCOL_BASE); + if (unlikely(!base_tx_cinfo)) + return -EINVAL; + + ret = __scmi_xfer_info_init(sinfo, &sinfo->tx_minfo, true, + base_tx_cinfo); - if (!ret && idr_find(&sinfo->rx_idr, SCMI_PROTOCOL_BASE)) - ret = __scmi_xfer_info_init(sinfo, &sinfo->rx_minfo); + base_rx_cinfo = idr_find(&sinfo->rx_idr, SCMI_PROTOCOL_BASE); + if (!ret && base_rx_cinfo) + ret = __scmi_xfer_info_init(sinfo, &sinfo->rx_minfo, false, + base_rx_cinfo); return ret; } -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel