netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Poirier <bpoirier@suse.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Manish Chopra <manishc@marvell.com>,
	GR-Linux-NIC-Dev@marvell.com, netdev@vger.kernel.org,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 16/17] staging: qlge: Refill rx buffers up to multiple of 16
Date: Fri, 27 Sep 2019 19:12:10 +0900	[thread overview]
Message-ID: <20190927101210.23856-17-bpoirier@suse.com> (raw)
In-Reply-To: <20190927101210.23856-1-bpoirier@suse.com>

Reading the {s,l}bq_prod_idx registers on a running device, it appears that
the adapter will only use buffers up to prod_idx & 0xfff0. The driver
currently uses fixed-size guard zones (16 for sbq, 32 for lbq - don't know
why this difference). After the previous patch, this approach no longer
guarantees prod_idx values aligned on multiples of 16. While it appears
that we can write unaligned values to prod_idx without ill effects on
device operation, it makes more sense to change qlge_refill_bq() to refill
up to a limit that corresponds with the device's behavior.

Signed-off-by: Benjamin Poirier <bpoirier@suse.com>
---
 drivers/staging/qlge/qlge.h      |  8 ++++++++
 drivers/staging/qlge/qlge_main.c | 29 +++++++++++------------------
 2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/qlge/qlge.h b/drivers/staging/qlge/qlge.h
index 7c48e333d29b..e5a352df8228 100644
--- a/drivers/staging/qlge/qlge.h
+++ b/drivers/staging/qlge/qlge.h
@@ -1423,6 +1423,9 @@ struct qlge_bq {
 	__le64 *base_indirect;
 	dma_addr_t base_indirect_dma;
 	struct qlge_bq_desc *queue;
+	/* prod_idx is the index of the first buffer that may NOT be used by
+	 * hw, ie. one after the last. Advanced by sw.
+	 */
 	void __iomem *prod_idx_db_reg;
 	/* next index where sw should refill a buffer for hw */
 	u16 next_to_use;
@@ -1442,6 +1445,11 @@ struct qlge_bq {
 					  offsetof(struct rx_ring, lbq))); \
 })
 
+/* Experience shows that the device ignores the low 4 bits of the tail index.
+ * Refill up to a x16 multiple.
+ */
+#define QLGE_BQ_ALIGN(index) ALIGN_DOWN(index, 16)
+
 #define QLGE_BQ_WRAP(index) ((index) & (QLGE_BQ_LEN - 1))
 
 struct rx_ring {
diff --git a/drivers/staging/qlge/qlge_main.c b/drivers/staging/qlge/qlge_main.c
index 83e75005688a..02ad0cdf4856 100644
--- a/drivers/staging/qlge/qlge_main.c
+++ b/drivers/staging/qlge/qlge_main.c
@@ -1114,22 +1114,12 @@ static void qlge_refill_bq(struct qlge_bq *bq)
 	struct rx_ring *rx_ring = QLGE_BQ_CONTAINER(bq);
 	struct ql_adapter *qdev = rx_ring->qdev;
 	struct qlge_bq_desc *bq_desc;
-	int free_count, refill_count;
-	unsigned int reserved_count;
+	int refill_count;
 	int i;
 
-	if (bq->type == QLGE_SB)
-		reserved_count = 16;
-	else
-		reserved_count = 32;
-
-	free_count = bq->next_to_clean - bq->next_to_use;
-	if (free_count <= 0)
-		free_count += QLGE_BQ_LEN;
-
-	refill_count = free_count - reserved_count;
-	/* refill batch size */
-	if (refill_count < 16)
+	refill_count = QLGE_BQ_WRAP(QLGE_BQ_ALIGN(bq->next_to_clean - 1) -
+				    bq->next_to_use);
+	if (!refill_count)
 		return;
 
 	i = bq->next_to_use;
@@ -1164,11 +1154,14 @@ static void qlge_refill_bq(struct qlge_bq *bq)
 	i += QLGE_BQ_LEN;
 
 	if (bq->next_to_use != i) {
-		netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
-			     "ring %u %s: updating prod idx = %d.\n",
-			     rx_ring->cq_id, bq_type_name[bq->type], i);
+		if (QLGE_BQ_ALIGN(bq->next_to_use) != QLGE_BQ_ALIGN(i)) {
+			netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
+				     "ring %u %s: updating prod idx = %d.\n",
+				     rx_ring->cq_id, bq_type_name[bq->type],
+				     i);
+			ql_write_db_reg(i, bq->prod_idx_db_reg);
+		}
 		bq->next_to_use = i;
-		ql_write_db_reg(bq->next_to_use, bq->prod_idx_db_reg);
 	}
 }
 
-- 
2.23.0


  parent reply	other threads:[~2019-09-27 10:15 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-27 10:11 [PATCH v2 0/17] staging: qlge: Fix rx stall in case of allocation failures Benjamin Poirier
2019-09-27 10:11 ` [PATCH v2 01/17] staging: qlge: Fix irq masking in INTx mode Benjamin Poirier
2019-09-27 10:11 ` [PATCH v2 02/17] staging: qlge: Remove irq_cnt Benjamin Poirier
2019-09-27 10:11 ` [PATCH v2 03/17] staging: qlge: Remove page_chunk.last_flag Benjamin Poirier
2019-09-27 10:11 ` [PATCH v2 04/17] staging: qlge: Deduplicate lbq_buf_size Benjamin Poirier
2019-09-27 10:11 ` [PATCH v2 05/17] staging: qlge: Remove bq_desc.maplen Benjamin Poirier
2019-09-27 10:12 ` [PATCH v2 06/17] staging: qlge: Remove rx_ring.sbq_buf_size Benjamin Poirier
2019-09-27 10:12 ` [PATCH v2 07/17] staging: qlge: Remove useless dma synchronization calls Benjamin Poirier
2019-09-27 10:12 ` [PATCH v2 08/17] staging: qlge: Deduplicate rx buffer queue management Benjamin Poirier
2019-09-27 10:12 ` [PATCH v2 09/17] staging: qlge: Fix dma_sync_single calls Benjamin Poirier
2019-09-27 10:12 ` [PATCH v2 10/17] staging: qlge: Remove rx_ring.type Benjamin Poirier
2019-09-27 10:12 ` [PATCH v2 11/17] staging: qlge: Factor out duplicated expression Benjamin Poirier
2019-09-27 10:12 ` [PATCH v2 12/17] staging: qlge: Remove qlge_bq.len & size Benjamin Poirier
2019-09-27 10:12 ` [PATCH v2 13/17] staging: qlge: Remove useless memset Benjamin Poirier
2019-09-27 10:12 ` [PATCH v2 14/17] staging: qlge: Replace memset with assignment Benjamin Poirier
2019-09-27 10:12 ` [PATCH v2 15/17] staging: qlge: Update buffer queue prod index despite oom Benjamin Poirier
2019-09-27 10:12 ` Benjamin Poirier [this message]
2019-09-27 10:12 ` [PATCH v2 17/17] staging: qlge: Refill empty buffer queues from wq Benjamin Poirier
2019-10-04  8:19 ` [PATCH v2 0/17] staging: qlge: Fix rx stall in case of allocation failures Greg Kroah-Hartman
2019-10-04  9:15   ` Benjamin Poirier
2019-10-04 15:19     ` Greg Kroah-Hartman

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=20190927101210.23856-17-bpoirier@suse.com \
    --to=bpoirier@suse.com \
    --cc=GR-Linux-NIC-Dev@marvell.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manishc@marvell.com \
    --cc=netdev@vger.kernel.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).