netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Elder <elder@linaro.org>
To: davem@davemloft.net, kuba@kernel.org
Cc: elder@kernel.org, evgreen@chromium.org,
	bjorn.andersson@linaro.org, cpratapa@codeaurora.org,
	subashab@codeaurora.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH net-next 1/7] net: ipa: restructure a few functions
Date: Wed,  3 Feb 2021 09:28:49 -0600	[thread overview]
Message-ID: <20210203152855.11866-2-elder@linaro.org> (raw)
In-Reply-To: <20210203152855.11866-1-elder@linaro.org>

Make __gsi_channel_start() and __gsi_channel_stop() more structurally
and semantically similar to each other:
  - Restructure __gsi_channel_start() to always return at the end of
    the function, similar to the way __gsi_channel_stop() does.
  - Move the mutex calls out of gsi_channel_stop_retry() and into
    __gsi_channel_stop().

Restructure gsi_channel_stop() to always return at the end of the
function, like gsi_channel_start() does.

Signed-off-by: Alex Elder <elder@linaro.org>
---
 drivers/net/ipa/gsi.c | 45 +++++++++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c
index 53640447bf123..2671b76ebcfe3 100644
--- a/drivers/net/ipa/gsi.c
+++ b/drivers/net/ipa/gsi.c
@@ -873,17 +873,17 @@ static void gsi_channel_deprogram(struct gsi_channel *channel)
 
 static int __gsi_channel_start(struct gsi_channel *channel, bool start)
 {
-	struct gsi *gsi = channel->gsi;
-	int ret;
+	int ret = 0;
 
-	if (!start)
-		return 0;
+	if (start) {
+		struct gsi *gsi = channel->gsi;
 
-	mutex_lock(&gsi->mutex);
+		mutex_lock(&gsi->mutex);
 
-	ret = gsi_channel_start_command(channel);
+		ret = gsi_channel_start_command(channel);
 
-	mutex_unlock(&gsi->mutex);
+		mutex_unlock(&gsi->mutex);
+	}
 
 	return ret;
 }
@@ -910,11 +910,8 @@ int gsi_channel_start(struct gsi *gsi, u32 channel_id)
 static int gsi_channel_stop_retry(struct gsi_channel *channel)
 {
 	u32 retries = GSI_CHANNEL_STOP_RETRIES;
-	struct gsi *gsi = channel->gsi;
 	int ret;
 
-	mutex_lock(&gsi->mutex);
-
 	do {
 		ret = gsi_channel_stop_command(channel);
 		if (ret != -EAGAIN)
@@ -922,19 +919,26 @@ static int gsi_channel_stop_retry(struct gsi_channel *channel)
 		usleep_range(3 * USEC_PER_MSEC, 5 * USEC_PER_MSEC);
 	} while (retries--);
 
-	mutex_unlock(&gsi->mutex);
-
 	return ret;
 }
 
 static int __gsi_channel_stop(struct gsi_channel *channel, bool stop)
 {
-	int ret;
+	int ret = 0;
 
 	/* Wait for any underway transactions to complete before stopping. */
 	gsi_channel_trans_quiesce(channel);
 
-	ret = stop ? gsi_channel_stop_retry(channel) : 0;
+	if (stop) {
+		struct gsi *gsi = channel->gsi;
+
+		mutex_lock(&gsi->mutex);
+
+		ret = gsi_channel_stop_retry(channel);
+
+		mutex_unlock(&gsi->mutex);
+	}
+
 	/* Finally, ensure NAPI polling has finished. */
 	if (!ret)
 		napi_synchronize(&channel->napi);
@@ -948,15 +952,14 @@ int gsi_channel_stop(struct gsi *gsi, u32 channel_id)
 	struct gsi_channel *channel = &gsi->channel[channel_id];
 	int ret;
 
-	/* Only disable the completion interrupt if stop is successful */
 	ret = __gsi_channel_stop(channel, true);
-	if (ret)
-		return ret;
+	if (ret) {
+		/* Disable the completion interrupt and NAPI if successful */
+		gsi_irq_ieob_disable_one(gsi, channel->evt_ring_id);
+		napi_disable(&channel->napi);
+	}
 
-	gsi_irq_ieob_disable_one(gsi, channel->evt_ring_id);
-	napi_disable(&channel->napi);
-
-	return 0;
+	return ret;
 }
 
 /* Reset and reconfigure a channel, (possibly) enabling the doorbell engine */
-- 
2.20.1


  reply	other threads:[~2021-02-03 15:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03 15:28 [PATCH net-next 0/7] net: ipa: a mix of small improvements Alex Elder
2021-02-03 15:28 ` Alex Elder [this message]
2021-02-05  4:50   ` [PATCH net-next 1/7] net: ipa: restructure a few functions Jakub Kicinski
2021-02-05 13:37     ` Alex Elder
2021-02-03 15:28 ` [PATCH net-next 2/7] net: ipa: synchronize NAPI only for suspend Alex Elder
2021-02-05  4:53   ` Jakub Kicinski
2021-02-05 13:39     ` Alex Elder
2021-02-03 15:28 ` [PATCH net-next 3/7] net: ipa: do not cache event ring state Alex Elder
2021-02-03 15:28 ` [PATCH net-next 4/7] net: ipa: remove two unused register definitions Alex Elder
2021-02-03 15:28 ` [PATCH net-next 5/7] net: ipa: use a Boolean rather than count when replenishing Alex Elder
2021-02-03 15:28 ` [PATCH net-next 6/7] net: ipa: get rid of status size constraint Alex Elder
2021-02-03 15:28 ` [PATCH net-next 7/7] net: ipa: avoid field overflow Alex Elder

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=20210203152855.11866-2-elder@linaro.org \
    --to=elder@linaro.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=cpratapa@codeaurora.org \
    --cc=davem@davemloft.net \
    --cc=elder@kernel.org \
    --cc=evgreen@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=subashab@codeaurora.org \
    /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).