git: 8254a276ad89 - main - cxgbe/iw_cxgbe: Replace the fatal error flag with a stopped flag.

From: Navdeep Parhar <np_at_FreeBSD.org>
Date: Wed, 28 Aug 2024 19:30:46 UTC
The branch main has been updated by np:

URL: https://cgit.FreeBSD.org/src/commit/?id=8254a276ad893ae2a1b35fcbbad255f06e29b8c6

commit 8254a276ad893ae2a1b35fcbbad255f06e29b8c6
Author:     Navdeep Parhar <np@FreeBSD.org>
AuthorDate: 2024-08-28 18:41:10 +0000
Commit:     Navdeep Parhar <np@FreeBSD.org>
CommitDate: 2024-08-28 19:19:23 +0000

    cxgbe/iw_cxgbe: Replace the fatal error flag with a stopped flag.
    
    Now that suspend/resume is supported by the base driver, a fatal error
    isn't the only reason that the RNIC can stop abruptly.  Also, this state
    is no longer permanent as it's possible to resume operations after a
    stop.  Rename the flag and associated routines to match the new state of
    affairs.
    
    MFC after:      1 week
    Sponsored by:   Chelsio Communications
---
 sys/dev/cxgbe/iw_cxgbe/cm.c       | 10 +++++-----
 sys/dev/cxgbe/iw_cxgbe/device.c   | 11 ++++++++---
 sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h | 10 +++++-----
 sys/dev/cxgbe/iw_cxgbe/mem.c      |  2 +-
 4 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/sys/dev/cxgbe/iw_cxgbe/cm.c b/sys/dev/cxgbe/iw_cxgbe/cm.c
index e0e48fdff9ba..257dec81f384 100644
--- a/sys/dev/cxgbe/iw_cxgbe/cm.c
+++ b/sys/dev/cxgbe/iw_cxgbe/cm.c
@@ -1080,7 +1080,7 @@ c4iw_so_upcall(struct socket *so, void *arg, int waitflag)
 	 * Wake up any threads waiting in rdma_init()/rdma_fini(),
 	 * with locks held.
 	 */
-	if (so->so_error || (ep->com.dev->rdev.flags & T4_FATAL_ERROR))
+	if (so->so_error || c4iw_stopped(&ep->com.dev->rdev))
 		c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
 	add_ep_to_req_list(ep, C4IW_EVENT_SOCKET);
 
@@ -2708,8 +2708,8 @@ c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
 
 	CTR3(KTR_IW_CXGBE, "%s: cm_id %p, backlog %s", __func__, cm_id,
 			backlog);
-	if (c4iw_fatal_error(&dev->rdev)) {
-		CTR2(KTR_IW_CXGBE, "%s: cm_id %p, fatal error", __func__,
+	if (c4iw_stopped(&dev->rdev)) {
+		CTR2(KTR_IW_CXGBE, "%s: cm_id %p, stopped", __func__,
 			       cm_id);
 		return -EIO;
 	}
@@ -2821,8 +2821,8 @@ int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
 
 	rdev = &ep->com.dev->rdev;
 
-	if (c4iw_fatal_error(rdev)) {
-		CTR3(KTR_IW_CXGBE, "%s:ced1 fatal error %p %s", __func__, ep,
+	if (c4iw_stopped(rdev)) {
+		CTR3(KTR_IW_CXGBE, "%s:ced1 stopped %p %s", __func__, ep,
 					states[ep->com.state]);
 		if (ep->com.state != DEAD) {
 			send_abort(ep);
diff --git a/sys/dev/cxgbe/iw_cxgbe/device.c b/sys/dev/cxgbe/iw_cxgbe/device.c
index 209d12767a1c..3c4d269f6c69 100644
--- a/sys/dev/cxgbe/iw_cxgbe/device.c
+++ b/sys/dev/cxgbe/iw_cxgbe/device.c
@@ -335,9 +335,8 @@ c4iw_stop(struct adapter *sc)
 	if (iwsc) {
 		struct ib_event event = {0};
 
-		device_printf(sc->dev,
-			      "iWARP driver received FATAL ERROR event.\n");
-		iwsc->rdev.flags |= T4_FATAL_ERROR;
+		device_printf(sc->dev, "iWARP driver stopped.\n");
+		iwsc->rdev.flags |= T4_IW_STOPPED;
 		event.event  = IB_EVENT_DEVICE_FATAL;
 		event.device = &iwsc->ibdev;
 		ib_dispatch_event(&event);
@@ -349,6 +348,12 @@ c4iw_stop(struct adapter *sc)
 static int
 c4iw_restart(struct adapter *sc)
 {
+	struct c4iw_dev *iwsc = sc->iwarp_softc;
+
+	if (iwsc) {
+		device_printf(sc->dev, "iWARP driver restarted.\n");
+		iwsc->rdev.flags &= ~T4_IW_STOPPED;
+	}
 	return (0);
 }
 
diff --git a/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h b/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h
index 5715b7e53863..ca2595b65b02 100644
--- a/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h
+++ b/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h
@@ -116,7 +116,7 @@ struct c4iw_dev_ucontext {
 };
 
 enum c4iw_rdev_flags {
-	T4_FATAL_ERROR = (1<<0),
+	T4_IW_STOPPED = (1<<0),
 	T4_STATUS_PAGE_DISABLED = (1<<1),
 };
 
@@ -167,9 +167,9 @@ struct c4iw_rdev {
 	struct workqueue_struct *free_workq;
 };
 
-static inline int c4iw_fatal_error(struct c4iw_rdev *rdev)
+static inline int c4iw_stopped(struct c4iw_rdev *rdev)
 {
-	return rdev->flags & T4_FATAL_ERROR;
+	return rdev->flags & T4_IW_STOPPED;
 }
 
 static inline int c4iw_num_stags(struct c4iw_rdev *rdev)
@@ -214,7 +214,7 @@ c4iw_wait_for_reply(struct c4iw_rdev *rdev, struct c4iw_wr_wait *wr_waitp,
 	int timedout = 0;
 	struct timeval t1, t2;
 
-	if (c4iw_fatal_error(rdev)) {
+	if (c4iw_stopped(rdev)) {
 		wr_waitp->ret = -EIO;
 		goto out;
 	}
@@ -240,7 +240,7 @@ c4iw_wait_for_reply(struct c4iw_rdev *rdev, struct c4iw_wr_wait *wr_waitp,
 			    "seconds - tid %u qpid %u\n", func,
 			    device_get_nameunit(sc->dev), t2.tv_sec, t2.tv_usec,
 			    hwtid, qpid);
-			if (c4iw_fatal_error(rdev)) {
+			if (c4iw_stopped(rdev)) {
 				wr_waitp->ret = -EIO;
 				break;
 			}
diff --git a/sys/dev/cxgbe/iw_cxgbe/mem.c b/sys/dev/cxgbe/iw_cxgbe/mem.c
index 5b8c7391514f..348cd3985e87 100644
--- a/sys/dev/cxgbe/iw_cxgbe/mem.c
+++ b/sys/dev/cxgbe/iw_cxgbe/mem.c
@@ -256,7 +256,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
 	u32 stag_idx;
 	static atomic_t key;
 
-	if (c4iw_fatal_error(rdev))
+	if (c4iw_stopped(rdev))
 		return -EIO;
 
 	stag_state = stag_state > 0;