Date: Fri, 19 Jul 2024 16:18:22 GMT From: Navdeep Parhar <np@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: cfcfd3c7bf5b - main - cxgbe(4): Make no assumptions about the start and size of the L2T table. Message-ID: <202407191618.46JGIMP2043523@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by np: URL: https://cgit.FreeBSD.org/src/commit/?id=cfcfd3c7bf5b60da42b13ac5d8085c762613c302 commit cfcfd3c7bf5b60da42b13ac5d8085c762613c302 Author: Navdeep Parhar <np@FreeBSD.org> AuthorDate: 2024-07-18 20:16:30 +0000 Commit: Navdeep Parhar <np@FreeBSD.org> CommitDate: 2024-07-19 16:12:46 +0000 cxgbe(4): Make no assumptions about the start and size of the L2T table. Do not assume that the table starts at index 0 and is typically 4K in size. The only thing the driver needs to verify is that its use of F_SYNC_WR doesn't collide with the L2T hwidx range. Reviewed by: jhb MFC after: 1 week Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D46028 --- sys/dev/cxgbe/t4_l2t.c | 17 +++++++++++------ sys/dev/cxgbe/t4_l2t.h | 2 -- sys/dev/cxgbe/t4_main.c | 6 +++--- sys/dev/cxgbe/tom/t4_tom_l2t.c | 21 +++++++++++++-------- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/sys/dev/cxgbe/t4_l2t.c b/sys/dev/cxgbe/t4_l2t.c index 005dce826ccb..90f184f5e666 100644 --- a/sys/dev/cxgbe/t4_l2t.c +++ b/sys/dev/cxgbe/t4_l2t.c @@ -369,14 +369,19 @@ int do_l2t_write_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m) { + struct adapter *sc = iq->adapter; const struct cpl_l2t_write_rpl *rpl = (const void *)(rss + 1); - unsigned int tid = GET_TID(rpl); - unsigned int idx = tid % L2T_SIZE; + const u_int hwidx = GET_TID(rpl) & ~(F_SYNC_WR | V_TID_QID(M_TID_QID)); + const bool sync = GET_TID(rpl) & F_SYNC_WR; - if (__predict_false(rpl->status != CPL_ERR_NONE)) { - log(LOG_ERR, - "Unexpected L2T_WRITE_RPL (%u) for entry at hw_idx %u\n", - rpl->status, idx); + MPASS(iq->abs_id == G_TID_QID(GET_TID(rpl))); + + if (__predict_false(hwidx < sc->vres.l2t.start) || + __predict_false(hwidx >= sc->vres.l2t.start + sc->vres.l2t.size) || + __predict_false(rpl->status != CPL_ERR_NONE)) { + CH_ERR(sc, "%s: hwidx %u, rpl %u, sync %u; L2T st %u, sz %u\n", + __func__, hwidx, rpl->status, sync, sc->vres.l2t.start, + sc->vres.l2t.size); return (EINVAL); } diff --git a/sys/dev/cxgbe/t4_l2t.h b/sys/dev/cxgbe/t4_l2t.h index 36a41e459a5d..991b4476eb61 100644 --- a/sys/dev/cxgbe/t4_l2t.h +++ b/sys/dev/cxgbe/t4_l2t.h @@ -35,8 +35,6 @@ #define V_SYNC_WR(x) ((x) << S_SYNC_WR) #define F_SYNC_WR V_SYNC_WR(1) -enum { L2T_SIZE = 4096 }; /* # of L2T entries */ - enum { L2T_STATE_VALID, /* entry is up to date */ L2T_STATE_STALE, /* entry may be used but needs revalidation */ diff --git a/sys/dev/cxgbe/t4_main.c b/sys/dev/cxgbe/t4_main.c index 99400dc9aadb..11dd9e1d24a3 100644 --- a/sys/dev/cxgbe/t4_main.c +++ b/sys/dev/cxgbe/t4_main.c @@ -5262,9 +5262,9 @@ get_params__post_init(struct adapter *sc) } sc->vres.l2t.start = val[4]; sc->vres.l2t.size = val[5] - val[4] + 1; - KASSERT(sc->vres.l2t.size <= L2T_SIZE, - ("%s: L2 table size (%u) larger than expected (%u)", - __func__, sc->vres.l2t.size, L2T_SIZE)); + /* val[5] is the last hwidx and it must not collide with F_SYNC_WR */ + if (sc->vres.l2t.size > 0) + MPASS(fls(val[5]) <= S_SYNC_WR); sc->params.core_vdd = val[6]; param[0] = FW_PARAM_PFVF(IQFLINT_END); diff --git a/sys/dev/cxgbe/tom/t4_tom_l2t.c b/sys/dev/cxgbe/tom/t4_tom_l2t.c index c397196d9cca..ee442f023970 100644 --- a/sys/dev/cxgbe/tom/t4_tom_l2t.c +++ b/sys/dev/cxgbe/tom/t4_tom_l2t.c @@ -318,18 +318,23 @@ do_l2t_write_rpl2(struct sge_iq *iq, const struct rss_header *rss, { struct adapter *sc = iq->adapter; const struct cpl_l2t_write_rpl *rpl = (const void *)(rss + 1); - unsigned int tid = GET_TID(rpl); - unsigned int idx = tid % L2T_SIZE; + const u_int hwidx = GET_TID(rpl) & ~(F_SYNC_WR | V_TID_QID(M_TID_QID)); + const bool sync = GET_TID(rpl) & F_SYNC_WR; - if (__predict_false(rpl->status != CPL_ERR_NONE)) { - log(LOG_ERR, - "Unexpected L2T_WRITE_RPL (%u) for entry at hw_idx %u\n", - rpl->status, idx); + MPASS(iq->abs_id == G_TID_QID(GET_TID(rpl))); + + if (__predict_false(hwidx < sc->vres.l2t.start) || + __predict_false(hwidx >= sc->vres.l2t.start + sc->vres.l2t.size) || + __predict_false(rpl->status != CPL_ERR_NONE)) { + CH_ERR(sc, "%s: hwidx %u, rpl %u, sync %u; L2T st %u, sz %u\n", + __func__, hwidx, rpl->status, sync, sc->vres.l2t.start, + sc->vres.l2t.size); return (EINVAL); } - if (tid & F_SYNC_WR) { - struct l2t_entry *e = &sc->l2t->l2tab[idx - sc->vres.l2t.start]; + if (sync) { + const u_int idx = hwidx - sc->vres.l2t.start; + struct l2t_entry *e = &sc->l2t->l2tab[idx]; mtx_lock(&e->lock); if (e->state != L2T_STATE_SWITCHING) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202407191618.46JGIMP2043523>