diff mbox series

[v2,40/50] wilc1000: introduce schedule_packets() function

Message ID 20211223011358.4031459-41-davidm@egauge.net
State New
Headers show
Series wilc1000: rework tx path to use sk_buffs throughout | expand

Commit Message

David Mosberger-Tang Dec. 23, 2021, 1:14 a.m. UTC
Move the packet scheduling code in its own function for improved
readability.

Signed-off-by: David Mosberger-Tang <davidm@egauge.net>
---
 .../net/wireless/microchip/wilc1000/wlan.c    | 78 ++++++++++++-------
 1 file changed, 50 insertions(+), 28 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/wireless/microchip/wilc1000/wlan.c b/drivers/net/wireless/microchip/wilc1000/wlan.c
index 67f5293370d35..f01f7bade6189 100644
--- a/drivers/net/wireless/microchip/wilc1000/wlan.c
+++ b/drivers/net/wireless/microchip/wilc1000/wlan.c
@@ -669,22 +669,20 @@  static void set_header(struct wilc *wilc, struct sk_buff *tqe,
 }
 
 /**
- * fill_vmm_table() - fill VMM table with packets to be sent
+ * schedule_packets() - schedule packets for transmission
  * @wilc: Pointer to the wilc structure.
+ * @vmm_table_len: Current length of the VMM table.
  * @vmm_table: Pointer to the VMM table to fill.
  *
- * Fill VMM table with packets waiting to be sent.  The packets are
- * added based on access category (priority) but also balanced to
- * provide fairness.
- *
- * 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.
+ * Schedule packets from the access-category queues for transmission.
+ * The scheduling is primarily in order of priority, but also takes
+ * fairness into account.  As many packets as possible are moved to
+ * the chip queue.  The chip queue has space for up to
+ * WILC_VMM_TBL_SIZE packets or up to WILC_TX_BUFF_SIZE bytes.
  */
-static int fill_vmm_table(struct wilc *wilc,
-			  u32 vmm_table[WILC_VMM_TBL_SIZE])
+static int schedule_packets(struct wilc *wilc,
+			    int i, u32 vmm_table[WILC_VMM_TBL_SIZE])
 {
-	int i;
 	u8 k, ac;
 	static const u8 ac_preserve_ratio[NQUEUES] = {1, 1, 1, 1};
 	u8 ac_desired_ratio[NQUEUES];
@@ -694,19 +692,6 @@  static int fill_vmm_table(struct wilc *wilc,
 	struct sk_buff *tqe;
 	struct wilc_skb_tx_cb *tx_cb;
 
-	i = 0;
-
-	if (unlikely(wilc->chipq_bytes > 0)) {
-		/* fill in packets that are already on the chipq: */
-		skb_queue_walk(&wilc->chipq, tqe) {
-			tx_cb = WILC_SKB_TX_CB(tqe);
-			vmm_sz = tx_hdr_len(tx_cb->type);
-			vmm_sz += tqe->len;
-			vmm_sz = ALIGN(vmm_sz, 4);
-			vmm_table[i++] = vmm_table_entry(tqe, vmm_sz);
-		}
-	}
-
 	ac_balance(wilc, ac_desired_ratio);
 	num_pkts_to_add = ac_desired_ratio;
 	do {
@@ -718,7 +703,7 @@  static int fill_vmm_table(struct wilc *wilc,
 			ac_exist = 1;
 			for (k = 0; k < num_pkts_to_add[ac]; k++) {
 				if (i >= WILC_VMM_TBL_SIZE - 1)
-					goto out;
+					return i;
 
 				tqe = skb_dequeue(&wilc->txq[ac]);
 				if (!tqe)
@@ -732,7 +717,7 @@  static int fill_vmm_table(struct wilc *wilc,
 				if (wilc->chipq_bytes + vmm_sz > WILC_TX_BUFF_SIZE) {
 					/* return packet to its queue */
 					skb_queue_head(&wilc->txq[ac], tqe);
-					goto out;
+					return i;
 				}
 				atomic_dec(&wilc->txq_entries);
 
@@ -746,8 +731,45 @@  static int fill_vmm_table(struct wilc *wilc,
 		}
 		num_pkts_to_add = ac_preserve_ratio;
 	} while (ac_exist);
-out:
-	vmm_table[i] = 0x0;
+	return i;
+}
+
+/**
+ * fill_vmm_table() - fill VMM table with packets to be sent
+ * @wilc: Pointer to the wilc structure.
+ * @vmm_table: Pointer to the VMM table to fill.
+ *
+ * Fill VMM table with packets waiting to be sent.
+ *
+ * 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(struct wilc *wilc, u32 vmm_table[WILC_VMM_TBL_SIZE])
+{
+	int i;
+	int vmm_sz = 0;
+	struct sk_buff *tqe;
+	struct wilc_skb_tx_cb *tx_cb;
+
+	i = 0;
+
+	if (unlikely(wilc->chipq_bytes > 0)) {
+		/* fill in packets that are already on the chipq: */
+		skb_queue_walk(&wilc->chipq, tqe) {
+			tx_cb = WILC_SKB_TX_CB(tqe);
+			vmm_sz = tx_hdr_len(tx_cb->type);
+			vmm_sz += tqe->len;
+			vmm_sz = ALIGN(vmm_sz, 4);
+			vmm_table[i++] = vmm_table_entry(tqe, vmm_sz);
+		}
+	}
+
+	i = schedule_packets(wilc, i, vmm_table);
+	if (i > 0) {
+		WARN_ON(i >= WILC_VMM_TBL_SIZE);
+		vmm_table[i] = 0x0;
+	}
 	return i;
 }