Linux wireless drivers development
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: linux-kernel@vger.kernel.org, Stanislaw Gruszka <stf_xl@wp.pl>,
	Kalle Valo <kvalo@kernel.org>,
	Gregory Greenman <gregory.greenman@intel.com>,
	Hans de Goede <hdegoede@redhat.com>,
	Johannes Berg <johannes.berg@intel.com>,
	Kees Cook <keescook@chromium.org>,
	Yury Norov <yury.norov@gmail.com>,
	Miri Korenblit <miriam.rachel.korenblit@intel.com>,
	linux-wireless@vger.kernel.org
Cc: Jan Kara <jack@suse.cz>,
	Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>,
	Matthew Wilcox <willy@infradead.org>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org>,
	Alexey Klimov <klimov.linux@gmail.com>
Subject: [PATCH 12/34] wifi: intel: use atomic find_bit() API where appropriate
Date: Sat, 18 Nov 2023 07:50:43 -0800	[thread overview]
Message-ID: <20231118155105.25678-13-yury.norov@gmail.com> (raw)
In-Reply-To: <20231118155105.25678-1-yury.norov@gmail.com>

iwlegacy and iwlwifi code opencodes atomic bit allocation/traversing by
using loops. Switch it to use dedicated functions.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 .../net/wireless/intel/iwlegacy/4965-mac.c    |  7 ++-----
 drivers/net/wireless/intel/iwlegacy/common.c  |  8 ++------
 drivers/net/wireless/intel/iwlwifi/dvm/sta.c  |  8 ++------
 drivers/net/wireless/intel/iwlwifi/dvm/tx.c   | 19 ++++++++-----------
 4 files changed, 14 insertions(+), 28 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlegacy/4965-mac.c b/drivers/net/wireless/intel/iwlegacy/4965-mac.c
index 69276266ce6f..8fb738c95cb4 100644
--- a/drivers/net/wireless/intel/iwlegacy/4965-mac.c
+++ b/drivers/net/wireless/intel/iwlegacy/4965-mac.c
@@ -2089,12 +2089,9 @@ il4965_txq_ctx_stop(struct il_priv *il)
 static int
 il4965_txq_ctx_activate_free(struct il_priv *il)
 {
-	int txq_id;
+	int txq_id = find_and_set_bit(&il->txq_ctx_active_msk, il->hw_params.max_txq_num);
 
-	for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++)
-		if (!test_and_set_bit(txq_id, &il->txq_ctx_active_msk))
-			return txq_id;
-	return -1;
+	return txq_id < il->hw_params.max_txq_num ? txq_id : -1;
 }
 
 /*
diff --git a/drivers/net/wireless/intel/iwlegacy/common.c b/drivers/net/wireless/intel/iwlegacy/common.c
index 054fef680aba..c6353e17be50 100644
--- a/drivers/net/wireless/intel/iwlegacy/common.c
+++ b/drivers/net/wireless/intel/iwlegacy/common.c
@@ -2303,13 +2303,9 @@ EXPORT_SYMBOL(il_restore_stations);
 int
 il_get_free_ucode_key_idx(struct il_priv *il)
 {
-	int i;
-
-	for (i = 0; i < il->sta_key_max_num; i++)
-		if (!test_and_set_bit(i, &il->ucode_key_table))
-			return i;
+	int i = find_and_set_bit(&il->ucode_key_table, il->sta_key_max_num);
 
-	return WEP_INVALID_OFFSET;
+	return i < il->sta_key_max_num ? i : WEP_INVALID_OFFSET;
 }
 EXPORT_SYMBOL(il_get_free_ucode_key_idx);
 
diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/sta.c b/drivers/net/wireless/intel/iwlwifi/dvm/sta.c
index 8b01ab986cb1..21e663d2bc44 100644
--- a/drivers/net/wireless/intel/iwlwifi/dvm/sta.c
+++ b/drivers/net/wireless/intel/iwlwifi/dvm/sta.c
@@ -719,13 +719,9 @@ void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
 
 int iwl_get_free_ucode_key_offset(struct iwl_priv *priv)
 {
-	int i;
-
-	for (i = 0; i < priv->sta_key_max_num; i++)
-		if (!test_and_set_bit(i, &priv->ucode_key_table))
-			return i;
+	int i = find_and_set_bit(&priv->ucode_key_table, priv->sta_key_max_num);
 
-	return WEP_INVALID_OFFSET;
+	return i < priv->sta_key_max_num ? i : WEP_INVALID_OFFSET;
 }
 
 void iwl_dealloc_bcast_stations(struct iwl_priv *priv)
diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/tx.c b/drivers/net/wireless/intel/iwlwifi/dvm/tx.c
index 111ed1873006..1b3dc99b968c 100644
--- a/drivers/net/wireless/intel/iwlwifi/dvm/tx.c
+++ b/drivers/net/wireless/intel/iwlwifi/dvm/tx.c
@@ -460,17 +460,14 @@ int iwlagn_tx_skb(struct iwl_priv *priv,
 
 static int iwlagn_alloc_agg_txq(struct iwl_priv *priv, int mq)
 {
-	int q;
-
-	for (q = IWLAGN_FIRST_AMPDU_QUEUE;
-	     q < priv->trans->trans_cfg->base_params->num_of_queues; q++) {
-		if (!test_and_set_bit(q, priv->agg_q_alloc)) {
-			priv->queue_to_mac80211[q] = mq;
-			return q;
-		}
-	}
-
-	return -ENOSPC;
+	int q = find_and_set_next_bit(priv->agg_q_alloc,
+				      priv->trans->trans_cfg->base_params->num_of_queues,
+				      IWLAGN_FIRST_AMPDU_QUEUE);
+	if (q >= priv->trans->trans_cfg->base_params->num_of_queues)
+		return -ENOSPC;
+
+	priv->queue_to_mac80211[q] = mq;
+	return q;
 }
 
 static void iwlagn_dealloc_agg_txq(struct iwl_priv *priv, int q)
-- 
2.39.2


  parent reply	other threads:[~2023-11-18 15:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-18 15:50 [PATCH 00/34] biops: add atomig find_bit() operations Yury Norov
2023-11-18 15:50 ` [PATCH 01/34] lib/find: add atomic find_bit() primitives Yury Norov
2023-11-18 16:23   ` Bart Van Assche
2023-11-18 15:50 ` [PATCH 10/34] ath10k: optimize ath10k_snoc_napi_poll() by using find_bit() Yury Norov
2023-11-18 15:50 ` [PATCH 11/34] wifi: rtw88: optimize rtw_pci_tx_kick_off() " Yury Norov
2023-11-18 15:50 ` Yury Norov [this message]
2023-11-19 19:58   ` [PATCH 12/34] wifi: intel: use atomic find_bit() API where appropriate Johannes Berg
2023-11-21 16:36     ` Yury Norov
2023-11-18 16:18 ` [PATCH 00/34] biops: add atomig find_bit() operations Bart Van Assche
2023-11-18 19:06   ` Sergey Shtylyov

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=20231118155105.25678-13-yury.norov@gmail.com \
    --to=yury.norov@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=gregory.greenman@intel.com \
    --cc=hdegoede@redhat.com \
    --cc=jack@suse.cz \
    --cc=johannes.berg@intel.com \
    --cc=keescook@chromium.org \
    --cc=klimov.linux@gmail.com \
    --cc=kvalo@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=maxim.kuvyrkov@linaro.org \
    --cc=miriam.rachel.korenblit@intel.com \
    --cc=mirsad.todorovac@alu.unizg.hr \
    --cc=stf_xl@wp.pl \
    --cc=willy@infradead.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