[14/38] net/sfc/base: move EVQ descs number check to generic place

Message ID 1549556983-10896-15-git-send-email-arybchenko@solarflare.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series net/sfc: update base driver |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Andrew Rybchenko Feb. 7, 2019, 4:29 p.m. UTC
  From: Igor Romanov <igor.romanov@oktetlabs.ru>

Now we have min/max limits in NIC config, so we can do check against
min/max in a generic place instead of NIC family specific functions.
Check that the descriptors number is a power of 2 is also can be
made common. It removes code duplication and makes NIC family
specific functions a bit shorter.

Signed-off-by: Igor Romanov <igor.romanov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
---
 drivers/net/sfc/base/ef10_ev.c | 19 ++++-----------
 drivers/net/sfc/base/efx_ev.c  | 42 ++++++++++++++++++----------------
 2 files changed, 26 insertions(+), 35 deletions(-)
  

Patch

diff --git a/drivers/net/sfc/base/ef10_ev.c b/drivers/net/sfc/base/ef10_ev.c
index 12125c6db..4f711992e 100644
--- a/drivers/net/sfc/base/ef10_ev.c
+++ b/drivers/net/sfc/base/ef10_ev.c
@@ -446,24 +446,15 @@  ef10_ev_qcreate(
 	efx_rc_t rc;
 
 	_NOTE(ARGUNUSED(id))	/* buftbl id managed by MC */
-	EFSYS_ASSERT(ISP2(encp->enc_evq_max_nevs));
-	EFSYS_ASSERT(ISP2(encp->enc_evq_min_nevs));
-
-	if (!ISP2(ndescs) ||
-	    (ndescs < encp->enc_evq_min_nevs) ||
-	    (ndescs > encp->enc_evq_max_nevs)) {
-		rc = EINVAL;
-		goto fail1;
-	}
 
 	if (index >= encp->enc_evq_limit) {
 		rc = EINVAL;
-		goto fail2;
+		goto fail1;
 	}
 
 	if (us > encp->enc_evq_timer_max_us) {
 		rc = EINVAL;
-		goto fail3;
+		goto fail2;
 	}
 
 	/* Set up the handler table */
@@ -503,7 +494,7 @@  ef10_ev_qcreate(
 		rc = efx_mcdi_init_evq_v2(enp, index, esmp, ndescs, irq, us,
 		    flags);
 		if (rc != 0)
-			goto fail4;
+			goto fail3;
 	} else {
 		/*
 		 * On Huntington we need to specify the settings to use.
@@ -520,13 +511,11 @@  ef10_ev_qcreate(
 		rc = efx_mcdi_init_evq(enp, index, esmp, ndescs, irq, us, flags,
 		    low_latency);
 		if (rc != 0)
-			goto fail5;
+			goto fail4;
 	}
 
 	return (0);
 
-fail5:
-	EFSYS_PROBE(fail5);
 fail4:
 	EFSYS_PROBE(fail4);
 fail3:
diff --git a/drivers/net/sfc/base/efx_ev.c b/drivers/net/sfc/base/efx_ev.c
index f1788cad2..51c422c2d 100644
--- a/drivers/net/sfc/base/efx_ev.c
+++ b/drivers/net/sfc/base/efx_ev.c
@@ -206,6 +206,7 @@  efx_ev_qcreate(
 {
 	const efx_ev_ops_t *eevop = enp->en_eevop;
 	efx_evq_t *eep;
+	const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
 	efx_rc_t rc;
 
 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
@@ -228,11 +229,21 @@  efx_ev_qcreate(
 		goto fail2;
 	}
 
+	EFSYS_ASSERT(ISP2(encp->enc_evq_max_nevs));
+	EFSYS_ASSERT(ISP2(encp->enc_evq_min_nevs));
+
+	if (!ISP2(ndescs) ||
+	    ndescs < encp->enc_evq_min_nevs ||
+	    ndescs > encp->enc_evq_max_nevs) {
+		rc = EINVAL;
+		goto fail3;
+	}
+
 	/* Allocate an EVQ object */
 	EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (efx_evq_t), eep);
 	if (eep == NULL) {
 		rc = ENOMEM;
-		goto fail3;
+		goto fail4;
 	}
 
 	eep->ee_magic = EFX_EVQ_MAGIC;
@@ -255,16 +266,18 @@  efx_ev_qcreate(
 
 	if ((rc = eevop->eevo_qcreate(enp, index, esmp, ndescs, id, us, flags,
 	    eep)) != 0)
-		goto fail4;
+		goto fail5;
 
 	return (0);
 
-fail4:
-	EFSYS_PROBE(fail4);
+fail5:
+	EFSYS_PROBE(fail5);
 
 	*eepp = NULL;
 	enp->en_ev_qcount--;
 	EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_evq_t), eep);
+fail4:
+	EFSYS_PROBE(fail4);
 fail3:
 	EFSYS_PROBE(fail3);
 fail2:
@@ -1285,24 +1298,15 @@  siena_ev_qcreate(
 
 	_NOTE(ARGUNUSED(esmp))
 
-	EFSYS_ASSERT(ISP2(encp->enc_evq_max_nevs));
-	EFSYS_ASSERT(ISP2(encp->enc_evq_min_nevs));
-
-	if (!ISP2(ndescs) ||
-	    (ndescs < encp->enc_evq_min_nevs) ||
-	    (ndescs > encp->enc_evq_max_nevs)) {
-		rc = EINVAL;
-		goto fail1;
-	}
 	if (index >= encp->enc_evq_limit) {
 		rc = EINVAL;
-		goto fail2;
+		goto fail1;
 	}
 #if EFSYS_OPT_RX_SCALE
 	if (enp->en_intr.ei_type == EFX_INTR_LINE &&
 	    index >= EFX_MAXRSS_LEGACY) {
 		rc = EINVAL;
-		goto fail3;
+		goto fail2;
 	}
 #endif
 	for (size = 0;
@@ -1312,7 +1316,7 @@  siena_ev_qcreate(
 			break;
 	if (id + (1 << size) >= encp->enc_buftbl_limit) {
 		rc = EINVAL;
-		goto fail4;
+		goto fail3;
 	}
 
 	/* Set up the handler table */
@@ -1344,14 +1348,12 @@  siena_ev_qcreate(
 
 	return (0);
 
-fail4:
-	EFSYS_PROBE(fail4);
-#if EFSYS_OPT_RX_SCALE
 fail3:
 	EFSYS_PROBE(fail3);
-#endif
+#if EFSYS_OPT_RX_SCALE
 fail2:
 	EFSYS_PROBE(fail2);
+#endif
 fail1:
 	EFSYS_PROBE1(fail1, efx_rc_t, rc);