From nobody Mon Jun 17 02:11:34 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4W2YKL2mckz5N1m4; Mon, 17 Jun 2024 02:11:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4W2YKL25nbz4dpR; Mon, 17 Jun 2024 02:11:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718590294; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zklmRe8tVKX5FzvWGcR7BXNgL9/DHyRX4gTC1uvqKZk=; b=nmfzTxiXoOXHNw7IJLch3rGH6zqa3UyJe4xgF9iQf1pPJgZ9Rg1QTgWn0qfNMBPte5B1fX 0fdzEnmwNpGLfjAeQh6kk5c14kvBHSm+CpP6utIoMqCd22phTba/pKSyZM0Jxcbwr2FLmZ xjpNkibLcs/zK/fTu2uTNhX5QBXq1OPFkwDH2x5D11WKZOoow3uKuvxftvisjH32/SAjd/ niQs/0vODXAx0kcO2WUfdK1yPgWu6snzQnGeFrlF2NG3NDUL1nTPDgXlQ3b8EleCyxcN1P 9rB86Tawzv5xIs/7HU6HevwKJpM6fqX328I68okFsYbRDBYMpGXPMBTFY3FV3w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1718590294; a=rsa-sha256; cv=none; b=utD2dyGqSsYU1auAouAdPcc8gc1Nc3IPMgavxzpOLMarHZHRlnxc4H4tC8x89yNNwr9TLZ a59KB2dgUsKDBZDHD80jQd8+OkrMm6W2DeWrLMS1C64K2tHH/jZxHSZYT8wNhnxmhGBDwm xr6TsJMrIHLTvwsVCc9JC2PlKUefARb2qAsCQbaVcdaSiq0rSRsdQUO+L0Y6omYeoiFVC5 GqjPvEqxhhCYuQv9ua8vTEJBVx2mNodl+RfV5+ieDo9eSjNBBG8e3PC13U6Tu0sRoJcf9E PSprdLml5Xe5UaHnTDblXLo1ftfHMrUVmltJ8hScEc3pPhIeF5mKhs5cvLmg5Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718590294; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zklmRe8tVKX5FzvWGcR7BXNgL9/DHyRX4gTC1uvqKZk=; b=NHaKch7gc9pRhMl1vvm41mEp5OUboP5cUQml4q5sfULvee8/YTDMDetbw8RQ9yvFmZb/PN g1UzjC0Oiilazld7dzll39E69xx1ES262wqMhAr+s+NRaTA67OqL50q/Ocm4iAwrd3kpqw JuU8tVqVsjGYs8nLqRri96acgFTgTwYl8qp96jSp0c5vPhCUeoWIrobYPZQCwL+NYCJYVN OsY/m7THCts8ZqCZk3XQV5hZezQ8JhCaXs1vSdU5n2Vd9OcDk5dbCWsYBkjBcQ3tJjEOOt 7sRyGSBg3dtiDfvT/DkPoVGsxmrVJ7npmh8FaNton4zBOkEqPs+x2xqcQ90sog== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4W2YKL1j3Yz1By5; Mon, 17 Jun 2024 02:11:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 45H2BYs8046513; Mon, 17 Jun 2024 02:11:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45H2BYGo046510; Mon, 17 Jun 2024 02:11:34 GMT (envelope-from git) Date: Mon, 17 Jun 2024 02:11:34 GMT Message-Id: <202406170211.45H2BYGo046510@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Navdeep Parhar Subject: git: e827b61cacdd - main - cxgbetool(8): Be flexible about the nexus name. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: np X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e827b61cacddd4bc9a2f1657ad8c6d2bcd70d52e Auto-Submitted: auto-generated The branch main has been updated by np: URL: https://cgit.FreeBSD.org/src/commit/?id=e827b61cacddd4bc9a2f1657ad8c6d2bcd70d52e commit e827b61cacddd4bc9a2f1657ad8c6d2bcd70d52e Author: Navdeep Parhar AuthorDate: 2024-06-13 20:17:55 +0000 Commit: Navdeep Parhar CommitDate: 2024-06-17 01:54:02 +0000 cxgbetool(8): Be flexible about the nexus name. Use the name as-is but perform cxgbe specific ioctls on the device to make sure that it is a Terminator device nexus. Determine the chip type, pf/vf, etc. from the device registers rather than the nexus name. This allows cxgbetool to work with the VF driver. MFC after: 1 week Sponsored by: Chelsio Communications --- usr.sbin/cxgbetool/cxgbetool.c | 116 +++++++++++++++++++++++++++-------------- 1 file changed, 76 insertions(+), 40 deletions(-) diff --git a/usr.sbin/cxgbetool/cxgbetool.c b/usr.sbin/cxgbetool/cxgbetool.c index bef99ff0f3da..8f58fe8107dc 100644 --- a/usr.sbin/cxgbetool/cxgbetool.c +++ b/usr.sbin/cxgbetool/cxgbetool.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -55,9 +56,16 @@ #define in_range(val, lo, hi) ( val < 0 || (val <= hi && val >= lo)) #define max(x, y) ((x) > (y) ? (x) : (y)) -static const char *progname, *nexus; -static int chip_id; /* 4 for T4, 5 for T5, and so on. */ -static int inst; /* instance of nexus device */ +static struct { + const char *progname, *nexus; + int chip_id; /* 4 for T4, 5 for T5, and so on. */ + int inst; /* instance of nexus device */ + int pf; /* PF# of the nexus (if not VF). */ + bool vf; /* Nexus is a VF. */ + + int fd; + bool warn_on_ioctl_err; +} g; struct reg_info { const char *name; @@ -87,7 +95,7 @@ struct field_desc { static void usage(FILE *fp) { - fprintf(fp, "Usage: %s [operation]\n", progname); + fprintf(fp, "Usage: %s [operation]\n", g.progname); fprintf(fp, "\tclearstats clear port statistics\n" "\tclip hold|release hold/release an address\n" @@ -136,27 +144,12 @@ get_card_vers(unsigned int version) static int real_doit(unsigned long cmd, void *data, const char *cmdstr) { - static int fd = -1; - int rc = 0; - - if (fd == -1) { - char buf[64]; - - snprintf(buf, sizeof(buf), "/dev/%s", nexus); - if ((fd = open(buf, O_RDWR)) < 0) { - warn("open(%s)", nexus); - rc = errno; - return (rc); - } - } - - rc = ioctl(fd, cmd, data); - if (rc < 0) { - warn("%s", cmdstr); - rc = errno; + if (ioctl(g.fd, cmd, data) < 0) { + if (g.warn_on_ioctl_err) + warn("%s", cmdstr); + return (errno); } - - return (rc); + return (0); } #define doit(x, y) real_doit(x, y, #x) @@ -522,7 +515,7 @@ dump_regs(int argc, const char *argv[]) rc = dump_regs_t6(argc, argv, regs.data); } else { warnx("%s (type %d, rev %d) is not a known card.", - nexus, vers, revision); + g.nexus, vers, revision); return (ENOTSUP); } @@ -914,7 +907,7 @@ do_show_one_filter_info(struct t4_filter *t, uint32_t mode) printf("(hash)"); } } - if (chip_id <= 5 && t->fs.prio) + if (g.chip_id <= 5 && t->fs.prio) printf(" Prio"); if (t->fs.rpttid) printf(" RptTID"); @@ -933,7 +926,7 @@ show_filters(int hash) if (rc != 0) return (rc); - if (!hash && chip_id >= 6) { + if (!hash && g.chip_id >= 6) { header = 0; bzero(&t, sizeof (t)); t.idx = 0; @@ -1924,10 +1917,10 @@ get_sge_context(int argc, const char *argv[]) if (rc != 0) return (rc); - if (chip_id == 4) + if (g.chip_id == 4) show_t4_ctxt(&cntxt); else - show_t5t6_ctxt(&cntxt, chip_id); + show_t5t6_ctxt(&cntxt, g.chip_id); return (0); } @@ -2243,7 +2236,7 @@ show_tcb(uint32_t *buf, uint32_t len) } printf("\n"); } - set_tcb_info(TIDTYPE_TCB, chip_id); + set_tcb_info(TIDTYPE_TCB, g.chip_id); set_print_style(PRNTSTYL_COMP); swizzle_tcb(tcb); parse_n_display_xcb(tcb); @@ -2447,7 +2440,7 @@ static void create_tracing_ifnet() { char *cmd[] = { - "/sbin/ifconfig", __DECONST(char *, nexus), "create", NULL + "/sbin/ifconfig", __DECONST(char *, g.nexus), "create", NULL }; char *env[] = {NULL}; @@ -3494,7 +3487,7 @@ display_clip(void) return (errno); } - snprintf(name, sizeof(name), "dev.t%unex.%u.misc.clip", chip_id, inst); + snprintf(name, sizeof(name), "dev.t%unex.%u.misc.clip", g.chip_id, g.inst); rc = sysctlbyname(name, buf, &clip_buf_size, NULL, 0); if (rc != 0) { warn("sysctl %s", name); @@ -3649,14 +3642,57 @@ run_cmd_loop(void) return (rc); } +#define A_PL_WHOAMI 0x19400 +#define A_PL_REV 0x1943c +#define A_PL_VF_WHOAMI 0x200 +#define A_PL_VF_REV 0x204 + static void -parse_nexus_name(const char *s) +open_nexus_device(const char *s) { - char junk; - - if (sscanf(s, "t%unex%u%c", &chip_id, &inst, &junk) != 2) - errx(EINVAL, "invalid nexus \"%s\"", s); - nexus = s; + const int len = strlen(s); + long long val; + const char *num; + int rc; + u_int chip_id, whoami; + char buf[128]; + + if (len < 2 || isdigit(s[0]) || !isdigit(s[len - 1])) + errx(1, "invalid nexus name \"%s\"", s); + for (num = s + len - 1; isdigit(*num); num--) + continue; + g.inst = strtoll(num, NULL, 0); + g.nexus = s; + snprintf(buf, sizeof(buf), "/dev/%s", g.nexus); + if ((g.fd = open(buf, O_RDWR)) < 0) + err(1, "open(%s)", buf); + + g.warn_on_ioctl_err = false; + rc = read_reg(A_PL_REV, 4, &val); + if (rc == 0) { + /* PF */ + g.vf = false; + whoami = A_PL_WHOAMI; + } else { + rc = read_reg(A_PL_VF_REV, 4, &val); + if (rc != 0) + errx(1, "%s is not a Terminator device.", s); + /* VF */ + g.vf = true; + whoami = A_PL_VF_WHOAMI; + } + chip_id = (val >> 4) & 0xf; + if (chip_id == 0) + chip_id = 4; + if (chip_id < 4 || chip_id > 7) + warnx("%s reports chip_id %d.", s, chip_id); + g.chip_id = chip_id; + + rc = read_reg(whoami, 4, &val); + if (rc != 0) + errx(rc, "failed to read whoami(0x%x): %d", whoami, rc); + g.pf = g.chip_id > 5 ? (val >> 9) & 7 : (val >> 8) & 7; + g.warn_on_ioctl_err = true; } int @@ -3664,7 +3700,7 @@ main(int argc, const char *argv[]) { int rc = -1; - progname = argv[0]; + g.progname = argv[0]; if (argc == 2) { if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { @@ -3678,7 +3714,7 @@ main(int argc, const char *argv[]) exit(EINVAL); } - parse_nexus_name(argv[1]); + open_nexus_device(argv[1]); /* progname and nexus */ argc -= 2;