ntb.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] ntb: Clean up tx tail index on link down
@ 2023-08-22 16:04 Dave Jiang
  2023-08-22 16:04 ` [PATCH v2 1/4] " Dave Jiang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Dave Jiang @ 2023-08-22 16:04 UTC (permalink / raw)
  To: jdmason, allenbh; +Cc: Yuan Y Lu, Logan Gunthorpe, renlonglong, ntb

v2:
- Add Logan's review tag
- Add check to qp->remote_rx_info before reset entry (1/4) since it could be NULL. (longlong)

Several ntb_transport fixes after doing long term continous netdev up/down
testing.

---

Dave Jiang (4):
      ntb: Clean up tx tail index on link down
      ntb: Drop packets when qp link is down
      ntb: Fix calculation ntb_transport_tx_free_entry()
      ntb: Check tx descriptors outstanding instead of head/tail for tx queue


 drivers/ntb/ntb_transport.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

--


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/4] ntb: Clean up tx tail index on link down
  2023-08-22 16:04 [PATCH v2 0/4] ntb: Clean up tx tail index on link down Dave Jiang
@ 2023-08-22 16:04 ` Dave Jiang
  2023-08-22 16:04 ` [PATCH v2 2/4] ntb: Drop packets when qp link is down Dave Jiang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Dave Jiang @ 2023-08-22 16:04 UTC (permalink / raw)
  To: jdmason, allenbh; +Cc: Yuan Y Lu, Yuan Y Lu, Logan Gunthorpe, ntb

The tx tail index is not reset when the link goes down. This causes the
tail index to go out of sync when the link goes down and comes back up.
Refactor the ntb_qp_link_down_reset() and reset the tail index as well.

Fixes: 2849b5d70641 ("NTB: Reset transport QP link stats on down")
Reported-by: Yuan Y Lu <yuan.y.lu@intel.com>
Tested-by: Yuan Y Lu <yuan.y.lu@intel.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 drivers/ntb/ntb_transport.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index a9b97ebc71ac..28cd6c814343 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -909,7 +909,7 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw,
 	return 0;
 }
 
-static void ntb_qp_link_down_reset(struct ntb_transport_qp *qp)
+static void ntb_qp_link_context_reset(struct ntb_transport_qp *qp)
 {
 	qp->link_is_up = false;
 	qp->active = false;
@@ -932,6 +932,13 @@ static void ntb_qp_link_down_reset(struct ntb_transport_qp *qp)
 	qp->tx_async = 0;
 }
 
+static void ntb_qp_link_down_reset(struct ntb_transport_qp *qp)
+{
+	ntb_qp_link_context_reset(qp);
+	if (qp->remote_rx_info)
+		qp->remote_rx_info->entry = qp->rx_max_entry - 1;
+}
+
 static void ntb_qp_link_cleanup(struct ntb_transport_qp *qp)
 {
 	struct ntb_transport_ctx *nt = qp->transport;
@@ -1174,7 +1181,7 @@ static int ntb_transport_init_queue(struct ntb_transport_ctx *nt,
 	qp->ndev = nt->ndev;
 	qp->client_ready = false;
 	qp->event_handler = NULL;
-	ntb_qp_link_down_reset(qp);
+	ntb_qp_link_context_reset(qp);
 
 	if (mw_num < qp_count % mw_count)
 		num_qps_mw = qp_count / mw_count + 1;



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/4] ntb: Drop packets when qp link is down
  2023-08-22 16:04 [PATCH v2 0/4] ntb: Clean up tx tail index on link down Dave Jiang
  2023-08-22 16:04 ` [PATCH v2 1/4] " Dave Jiang
@ 2023-08-22 16:04 ` Dave Jiang
  2023-08-22 16:04 ` [PATCH v2 3/4] ntb: Fix calculation ntb_transport_tx_free_entry() Dave Jiang
  2023-08-22 16:05 ` [PATCH v2 4/4] ntb: Check tx descriptors outstanding instead of head/tail for tx queue Dave Jiang
  3 siblings, 0 replies; 5+ messages in thread
From: Dave Jiang @ 2023-08-22 16:04 UTC (permalink / raw)
  To: jdmason, allenbh; +Cc: Yuan Y Lu, Yuan Y Lu, Logan Gunthorpe, ntb

Currently when the transport receive packets after netdev has closed the
transport returns error and triggers tx errors to be incremented and
carrier to be stopped. There is no reason to return error if the device is
already closed. Drop the packet and return 0.

Fixes: e26a5843f7f5 ("NTB: Split ntb_hw_intel and ntb_transport drivers")
Reported-by: Yuan Y Lu <yuan.y.lu@intel.com>
Tested-by: Yuan Y Lu <yuan.y.lu@intel.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 drivers/ntb/ntb_transport.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 28cd6c814343..48d48b30f908 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -2283,9 +2283,13 @@ int ntb_transport_tx_enqueue(struct ntb_transport_qp *qp, void *cb, void *data,
 	struct ntb_queue_entry *entry;
 	int rc;
 
-	if (!qp || !qp->link_is_up || !len)
+	if (!qp || !len)
 		return -EINVAL;
 
+	/* If the qp link is down already, just ignore. */
+	if (!qp->link_is_up)
+		return 0;
+
 	entry = ntb_list_rm(&qp->ntb_tx_free_q_lock, &qp->tx_free_q);
 	if (!entry) {
 		qp->tx_err_no_buf++;



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 3/4] ntb: Fix calculation ntb_transport_tx_free_entry()
  2023-08-22 16:04 [PATCH v2 0/4] ntb: Clean up tx tail index on link down Dave Jiang
  2023-08-22 16:04 ` [PATCH v2 1/4] " Dave Jiang
  2023-08-22 16:04 ` [PATCH v2 2/4] ntb: Drop packets when qp link is down Dave Jiang
@ 2023-08-22 16:04 ` Dave Jiang
  2023-08-22 16:05 ` [PATCH v2 4/4] ntb: Check tx descriptors outstanding instead of head/tail for tx queue Dave Jiang
  3 siblings, 0 replies; 5+ messages in thread
From: Dave Jiang @ 2023-08-22 16:04 UTC (permalink / raw)
  To: jdmason, allenbh; +Cc: Logan Gunthorpe, renlonglong, ntb

ntb_transport_tx_free_entry() never returns 0 with the current
calculation. If head == tail, then it would return qp->tx_max_entry.
Change compare to tail >= head and when they are equal, a 0 would be
returned.

Fixes: e74bfeedad08 ("NTB: Add flow control to the ntb_netdev")
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: renlonglong <ren.longlong@h3c.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 drivers/ntb/ntb_transport.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 48d48b30f908..92241791eb6c 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -2429,7 +2429,7 @@ unsigned int ntb_transport_tx_free_entry(struct ntb_transport_qp *qp)
 	unsigned int head = qp->tx_index;
 	unsigned int tail = qp->remote_rx_info->entry;
 
-	return tail > head ? tail - head : qp->tx_max_entry + tail - head;
+	return tail >= head ? tail - head : qp->tx_max_entry + tail - head;
 }
 EXPORT_SYMBOL_GPL(ntb_transport_tx_free_entry);
 



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 4/4] ntb: Check tx descriptors outstanding instead of head/tail for tx queue
  2023-08-22 16:04 [PATCH v2 0/4] ntb: Clean up tx tail index on link down Dave Jiang
                   ` (2 preceding siblings ...)
  2023-08-22 16:04 ` [PATCH v2 3/4] ntb: Fix calculation ntb_transport_tx_free_entry() Dave Jiang
@ 2023-08-22 16:05 ` Dave Jiang
  3 siblings, 0 replies; 5+ messages in thread
From: Dave Jiang @ 2023-08-22 16:05 UTC (permalink / raw)
  To: jdmason, allenbh; +Cc: Logan Gunthorpe, ntb

Use existing function ntb_transport_tx_free_entry() instead of open coding
the check to see if there are outstanding tx descriptors.

Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 drivers/ntb/ntb_transport.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 92241791eb6c..0f09dc0a7efe 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -1901,7 +1901,7 @@ static void ntb_async_tx(struct ntb_transport_qp *qp,
 static int ntb_process_tx(struct ntb_transport_qp *qp,
 			  struct ntb_queue_entry *entry)
 {
-	if (qp->tx_index == qp->remote_rx_info->entry) {
+	if (!ntb_transport_tx_free_entry(qp)) {
 		qp->tx_ring_full++;
 		return -EAGAIN;
 	}



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-22 16:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-22 16:04 [PATCH v2 0/4] ntb: Clean up tx tail index on link down Dave Jiang
2023-08-22 16:04 ` [PATCH v2 1/4] " Dave Jiang
2023-08-22 16:04 ` [PATCH v2 2/4] ntb: Drop packets when qp link is down Dave Jiang
2023-08-22 16:04 ` [PATCH v2 3/4] ntb: Fix calculation ntb_transport_tx_free_entry() Dave Jiang
2023-08-22 16:05 ` [PATCH v2 4/4] ntb: Check tx descriptors outstanding instead of head/tail for tx queue Dave Jiang

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).