git: 8f72d933cd18 - main - cxgbe(4): minor changes in code dealing with ncores

From: Navdeep Parhar <np_at_FreeBSD.org>
Date: Mon, 09 Mar 2026 05:50:51 UTC
The branch main has been updated by np:

URL: https://cgit.FreeBSD.org/src/commit/?id=8f72d933cd18664c73b92f282503017bc6c87cf9

commit 8f72d933cd18664c73b92f282503017bc6c87cf9
Author:     Navdeep Parhar <np@FreeBSD.org>
AuthorDate: 2026-03-08 19:59:07 +0000
Commit:     Navdeep Parhar <np@FreeBSD.org>
CommitDate: 2026-03-09 05:44:13 +0000

    cxgbe(4): minor changes in code dealing with ncores
    
    1. ncores and devlog information is read as a combination so it makes
       sense to validate them in the same routine (and nowhere else).
    2. ncores is never 0 and idx % ncores is always a valid coreid.
    
    MFC after:      1 week
    Sponsored by:   Chelsio Communications
---
 sys/dev/cxgbe/t4_main.c | 14 ++++++++------
 sys/dev/cxgbe/t4_sge.c  | 10 ++++------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/sys/dev/cxgbe/t4_main.c b/sys/dev/cxgbe/t4_main.c
index cb0ad2342e7c..40cc7777bd71 100644
--- a/sys/dev/cxgbe/t4_main.c
+++ b/sys/dev/cxgbe/t4_main.c
@@ -806,7 +806,7 @@ static int validate_mem_range(struct adapter *, uint32_t, uint32_t);
 static int fwmtype_to_hwmtype(int);
 static int validate_mt_off_len(struct adapter *, int, uint32_t, uint32_t,
     uint32_t *);
-static int fixup_devlog_params(struct adapter *);
+static int fixup_devlog_ncores_params(struct adapter *);
 static int cfg_itype_and_nqueues(struct adapter *, struct intrs_and_queues *);
 static int contact_firmware(struct adapter *);
 static int partition_resources(struct adapter *);
@@ -1425,7 +1425,7 @@ t4_attach(device_t dev)
 	 */
 	setup_memwin(sc);
 	if (t4_init_devlog_ncores_params(sc, 0) == 0)
-		fixup_devlog_params(sc);
+		fixup_devlog_ncores_params(sc);
 	make_dev_args_init(&mda);
 	mda.mda_devsw = &t4_cdevsw;
 	mda.mda_uid = UID_ROOT;
@@ -4565,11 +4565,15 @@ validate_mt_off_len(struct adapter *sc, int mtype, uint32_t off, uint32_t len,
 }
 
 static int
-fixup_devlog_params(struct adapter *sc)
+fixup_devlog_ncores_params(struct adapter *sc)
 {
 	struct devlog_params *dparams = &sc->params.devlog;
 	int rc;
 
+#ifdef INVARIANTS
+	if (sc->params.ncores > 1)
+		MPASS(chip_id(sc) >= CHELSIO_T7);
+#endif
 	rc = validate_mt_off_len(sc, dparams->memtype, dparams->start,
 	    dparams->size, &dparams->addr);
 
@@ -5559,7 +5563,7 @@ get_params__pre_init(struct adapter *sc)
 	/* Read device log parameters. */
 	rc = -t4_init_devlog_ncores_params(sc, 1);
 	if (rc == 0)
-		fixup_devlog_params(sc);
+		fixup_devlog_ncores_params(sc);
 	else {
 		device_printf(sc->dev,
 		    "failed to get devlog parameters: %d.\n", rc);
@@ -5712,8 +5716,6 @@ get_params__post_init(struct adapter *sc)
 	}
 
 	if (sc->params.ncores > 1) {
-		MPASS(chip_id(sc) >= CHELSIO_T7);
-
 		param[0] = FW_PARAM_DEV(TID_QID_SEL_MASK);
 		rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val);
 		sc->params.tid_qid_sel_mask = rc == 0 ? val[0] : 0;
diff --git a/sys/dev/cxgbe/t4_sge.c b/sys/dev/cxgbe/t4_sge.c
index a9243ff121a6..07e4165db4a0 100644
--- a/sys/dev/cxgbe/t4_sge.c
+++ b/sys/dev/cxgbe/t4_sge.c
@@ -4372,18 +4372,17 @@ qsize_to_fthresh(int qsize)
 static int
 ctrl_eq_alloc(struct adapter *sc, struct sge_eq *eq, int idx)
 {
-	int rc, cntxt_id, core;
+	int rc, cntxt_id;
 	struct fw_eq_ctrl_cmd c;
 	int qsize = eq->sidx + sc->params.sge.spg_len / EQ_ESIZE;
 
-	core = sc->params.tid_qid_sel_mask != 0 ? idx % sc->params.ncores : 0;
 	bzero(&c, sizeof(c));
 
 	c.op_to_vfn = htobe32(V_FW_CMD_OP(FW_EQ_CTRL_CMD) | F_FW_CMD_REQUEST |
 	    F_FW_CMD_WRITE | F_FW_CMD_EXEC | V_FW_EQ_CTRL_CMD_PFN(sc->pf) |
 	    V_FW_EQ_CTRL_CMD_VFN(0));
 	c.alloc_to_len16 = htobe32(F_FW_EQ_CTRL_CMD_ALLOC |
-	    V_FW_EQ_CTRL_CMD_COREGROUP(core) |
+	    V_FW_EQ_CTRL_CMD_COREGROUP(idx % sc->params.ncores) |
 	    F_FW_EQ_CTRL_CMD_EQSTART | FW_LEN16(c));
 	c.cmpliqid_eqid = htonl(V_FW_EQ_CTRL_CMD_CMPLIQID(eq->iqid));
 	c.physeqid_pkd = htobe32(0);
@@ -4420,18 +4419,17 @@ ctrl_eq_alloc(struct adapter *sc, struct sge_eq *eq, int idx)
 static int
 eth_eq_alloc(struct adapter *sc, struct vi_info *vi, struct sge_eq *eq, int idx)
 {
-	int rc, cntxt_id, core;
+	int rc, cntxt_id;
 	struct fw_eq_eth_cmd c;
 	int qsize = eq->sidx + sc->params.sge.spg_len / EQ_ESIZE;
 
-	core = sc->params.ncores > 1 ? idx % sc->params.ncores : 0;
 	bzero(&c, sizeof(c));
 
 	c.op_to_vfn = htobe32(V_FW_CMD_OP(FW_EQ_ETH_CMD) | F_FW_CMD_REQUEST |
 	    F_FW_CMD_WRITE | F_FW_CMD_EXEC | V_FW_EQ_ETH_CMD_PFN(sc->pf) |
 	    V_FW_EQ_ETH_CMD_VFN(0));
 	c.alloc_to_len16 = htobe32(F_FW_EQ_ETH_CMD_ALLOC |
-	    V_FW_EQ_ETH_CMD_COREGROUP(core) |
+	    V_FW_EQ_ETH_CMD_COREGROUP(idx % sc->params.ncores) |
 	    F_FW_EQ_ETH_CMD_EQSTART | FW_LEN16(c));
 	c.autoequiqe_to_viid = htobe32(F_FW_EQ_ETH_CMD_AUTOEQUIQE |
 	    F_FW_EQ_ETH_CMD_AUTOEQUEQE | V_FW_EQ_ETH_CMD_VIID(vi->viid));