[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211223011358.4031459-19-davidm@egauge.net>
Date: Thu, 23 Dec 2021 01:14:06 +0000 (UTC)
From: David Mosberger-Tang <davidm@...uge.net>
To: Ajay Singh <ajay.kathat@...rochip.com>
Cc: Claudiu Beznea <claudiu.beznea@...rochip.com>,
Kalle Valo <kvalo@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
linux-wireless@...r.kernel.org, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org,
David Mosberger-Tang <davidm@...uge.net>
Subject: [PATCH v2 18/50] wilc1000: split huge tx handler into subfunctions
This makes the code easier to read and less error prone. There are no
functional changes in this patch.
Signed-off-by: David Mosberger-Tang <davidm@...uge.net>
---
.../net/wireless/microchip/wilc1000/wlan.c | 206 +++++++++++++-----
1 file changed, 157 insertions(+), 49 deletions(-)
diff --git a/drivers/net/wireless/microchip/wilc1000/wlan.c b/drivers/net/wireless/microchip/wilc1000/wlan.c
index 8bff1d8050b11..54dfb2b9f3524 100644
--- a/drivers/net/wireless/microchip/wilc1000/wlan.c
+++ b/drivers/net/wireless/microchip/wilc1000/wlan.c
@@ -605,43 +605,43 @@ void host_sleep_notify(struct wilc *wilc)
}
EXPORT_SYMBOL_GPL(host_sleep_notify);
-int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count)
+/**
+ * fill_vmm_table() - Fill VMM table with packets to be sent
+ * @wilc: Pointer to the wilc structure.
+ * @ac_desired_ratio: First-round limit on number of packets to add from the
+ * respective queue.
+ * @vmm_table: Pointer to the VMM table to fill.
+ * @vmm_entries_ac: Pointer to the queue-number table to fill.
+ * For each packet added to the VMM table, this will be filled in
+ * with the queue-number (access-category) that the packet is coming
+ * from.
+ *
+ * Fill VMM table with packets waiting to be sent. The packets are
+ * added based on access category (priority) but also balanced to
+ * provide fairness.
+ *
+ * Context: Since this function peeks at the packet queues, the
+ * txq_add_to_head_cs mutex must be acquired before calling this
+ * function.
+ *
+ * Return:
+ * The number of VMM entries filled in. The table is 0-terminated
+ * so the returned number is at most WILC_VMM_TBL_SIZE-1.
+ */
+static int fill_vmm_table(const struct wilc *wilc,
+ u8 ac_desired_ratio[NQUEUES],
+ u32 vmm_table[WILC_VMM_TBL_SIZE],
+ u8 vmm_entries_ac[WILC_VMM_TBL_SIZE])
{
- int i, entries = 0;
+ int i;
u8 k, ac;
u32 sum;
- u32 reg;
- u8 ac_desired_ratio[NQUEUES] = {0, 0, 0, 0};
u8 ac_preserve_ratio[NQUEUES] = {1, 1, 1, 1};
u8 *num_pkts_to_add;
- u8 vmm_entries_ac[WILC_VMM_TBL_SIZE];
- u32 offset = 0;
bool max_size_over = 0, ac_exist = 0;
int vmm_sz = 0;
struct sk_buff *tqe_q[NQUEUES];
struct wilc_skb_tx_cb *tx_cb;
- int ret = 0;
- int counter;
- int timeout;
- u32 vmm_table[WILC_VMM_TBL_SIZE];
- u8 ac_pkt_num_to_chip[NQUEUES] = {0, 0, 0, 0};
- const struct wilc_hif_func *func;
- int srcu_idx;
- u8 *txb = wilc->tx_buffer;
- struct wilc_vif *vif;
-
- if (wilc->quit)
- goto out_update_cnt;
-
- if (ac_balance(wilc, ac_desired_ratio))
- return -EINVAL;
-
- mutex_lock(&wilc->txq_add_to_head_cs);
-
- srcu_idx = srcu_read_lock(&wilc->srcu);
- list_for_each_entry_rcu(vif, &wilc->vif_list, list)
- wilc_wlan_txq_filter_dup_tcp_ack(vif->ndev);
- srcu_read_unlock(&wilc->srcu, srcu_idx);
for (ac = 0; ac < NQUEUES; ac++)
tqe_q[ac] = skb_peek(&wilc->txq[ac]);
@@ -695,11 +695,31 @@ int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count)
num_pkts_to_add = ac_preserve_ratio;
} while (!max_size_over && ac_exist);
- if (i == 0)
- goto out_unlock;
vmm_table[i] = 0x0;
+ return i;
+}
+
+/**
+ * send_vmm_table() - Send the VMM table to the chip
+ * @wilc: Pointer to the wilc structure.
+ * @i: The number of entries in the VMM table.
+ * @vmm_table: The VMM table to send.
+ *
+ * Send the VMM table to the chip and get back the number of entries
+ * that the chip can accept.
+ *
+ * Context: The bus must have been acquired before calling this
+ * function.
+ *
+ * Return:
+ * The number of VMM table entries the chip can accept.
+ */
+static int send_vmm_table(struct wilc *wilc, int i, const u32 *vmm_table)
+{
+ const struct wilc_hif_func *func;
+ int ret, counter, entries, timeout;
+ u32 reg;
- acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
counter = 0;
func = wilc->hif_func;
do {
@@ -721,7 +741,7 @@ int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count)
} while (!wilc->quit);
if (ret)
- goto out_release_bus;
+ return ret;
timeout = 200;
do {
@@ -759,22 +779,38 @@ int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count)
break;
reg &= ~BIT(0);
ret = func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, reg);
+ } else {
+ ret = entries;
}
} while (0);
+ return ret;
+}
- if (ret)
- goto out_release_bus;
-
- if (entries == 0) {
- /*
- * No VMM space available in firmware so retry to transmit
- * the packet from tx queue.
- */
- ret = WILC_VMM_ENTRY_FULL_RETRY;
- goto out_release_bus;
- }
-
- release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
+/**
+ * copy_packets() - Copy packets to the transmit buffer
+ * @wilc: Pointer to the wilc structure.
+ * @entries: The number of packets to send from the VMM table.
+ * @vmm_table: The VMM table to send.
+ * @vmm_entries_ac: Table index i contains the number of the queue to
+ * take the i-th packet from.
+ *
+ * Copy a set of packets to the transmit buffer.
+ *
+ * Context: The txq_add_to_head_cs mutex must still be held when
+ * calling this function.
+ *
+ * Return:
+ * Negative number on error, 0 on success.
+ */
+static int copy_packets(struct wilc *wilc, int entries, u32 *vmm_table,
+ u8 *vmm_entries_ac)
+{
+ u8 ac_pkt_num_to_chip[NQUEUES] = {0, 0, 0, 0};
+ struct wilc_skb_tx_cb *tx_cb;
+ u8 *txb = wilc->tx_buffer;
+ struct wilc_vif *vif;
+ int i, vmm_sz;
+ u32 offset;
offset = 0;
i = 0;
@@ -829,16 +865,88 @@ int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count)
} while (--entries);
for (i = 0; i < NQUEUES; i++)
wilc->fw[i].count += ac_pkt_num_to_chip[i];
+ return offset;
+}
- acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
+/**
+ * send_packets() - Send packets to the chip
+ * @wilc: Pointer to the wilc structure.
+ * @len: The length of the buffer containing the packets to be sent to
+ * the chip.
+ *
+ * Send the packets in the VMM table to the chip.
+ *
+ * Context: The bus must have been acquired.
+ *
+ * Return:
+ * Negative number on error, 0 on success.
+ */
+static int send_packets(struct wilc *wilc, int len)
+{
+ const struct wilc_hif_func *func = wilc->hif_func;
+ int ret;
+ u8 *txb = wilc->tx_buffer;
ret = func->hif_clear_int_ext(wilc, ENABLE_TX_VMM);
if (ret)
- goto out_release_bus;
+ return ret;
+
+ return func->hif_block_tx_ext(wilc, 0, txb, len);
+}
+
+int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count)
+{
+ int i, entries, len;
+ u8 ac_desired_ratio[NQUEUES] = {0, 0, 0, 0};
+ u8 vmm_entries_ac[WILC_VMM_TBL_SIZE];
+ int ret = 0;
+ u32 vmm_table[WILC_VMM_TBL_SIZE];
+ int srcu_idx;
+ struct wilc_vif *vif;
+
+ if (wilc->quit)
+ goto out_update_cnt;
+
+ if (ac_balance(wilc, ac_desired_ratio))
+ return -EINVAL;
+
+ mutex_lock(&wilc->txq_add_to_head_cs);
+
+ srcu_idx = srcu_read_lock(&wilc->srcu);
+ list_for_each_entry_rcu(vif, &wilc->vif_list, list)
+ wilc_wlan_txq_filter_dup_tcp_ack(vif->ndev);
+ srcu_read_unlock(&wilc->srcu, srcu_idx);
+
+ i = fill_vmm_table(wilc, ac_desired_ratio, vmm_table, vmm_entries_ac);
+ if (i == 0)
+ goto out_unlock;
+
+ acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
+
+ ret = send_vmm_table(wilc, i, vmm_table);
+
+ release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
+
+ if (ret < 0)
+ goto out_unlock;
+
+ entries = ret;
+ if (entries == 0) {
+ /* No VMM space available in firmware. Inform caller
+ * to retry later.
+ */
+ ret = WILC_VMM_ENTRY_FULL_RETRY;
+ goto out_unlock;
+ }
+
+ len = copy_packets(wilc, entries, vmm_table, vmm_entries_ac);
+ if (len <= 0)
+ goto out_unlock;
+
+ acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
- ret = func->hif_block_tx_ext(wilc, 0, txb, offset);
+ ret = send_packets(wilc, len);
-out_release_bus:
release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
out_unlock:
--
2.25.1
Powered by blists - more mailing lists