From nobody Wed Jul 17 14:24:47 2024 X-Original-To: dev-commits-src-all@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 4WPJ9W686Vz5RQ00; Wed, 17 Jul 2024 14:24:47 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WPJ9W43rTz41G4; Wed, 17 Jul 2024 14:24:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721226287; 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=U+PfeL5VQ2ACFh5fMwo24PLf8iaI0bqT+xuv+Xu+M2s=; b=Pa7uu0hPS8nDQs3Dr5L6bx5vmYFSQjOQpC0To22f3hMgxGZEAj3X+gvgWWpAvP6WmjS+To gcu7lwhLXrwvrdvif3QckW8yIHG/1Jrq/QI0v0oD5Ka7qGu7VBEugSAKjGtdUHAS6aVq4D i0z1BQxoW3MCCfA6trdeHYBz8FooD/sN/r6zQDr/jJwU9iB7JQzylBd5nKwv/d/5aBGXwu XYiPOdBdsweMVmvuPyQQfSqfWj0Ulg4bFZ301gXJ4qnGcHkLC5e1Uzmkz4xQym7aY3Z626 FnsoLTraBUOHjKHOlExEu8qvtU/U1q+2esKZYC9FSQmzXD1Q383QDFnh2GViLQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1721226287; a=rsa-sha256; cv=none; b=WhcUEZud0VUSLP3kESY+3X2k8BanZIcJOJU+NTyww8GEHrs5GIvhznD/dA+xJyBshNMBzT Qp2/cr/4hHd1Viua4jht6kJXBK79bpe+VWu7pWluRMUtv5ODBBZfsveZNEshGjeQokLkJz H8PcYOe1gxD0dLNmKGhxxCRlXjJc0MmBrjiltd6MeTRi2J+kQGFrc+R1emxHW95276mHu4 Ssa+2o6jFWtfx0Usjbzhgqrwps7AwZlEKm5Hs9ZOcf4FHjaGn/RI27fLWnrFMzJdXQr9dU FXswIY2gZXh6wZhRO5ITlR68wn3rNTFCJk15ZNdNxDHHTK5sRTeZzZlIQ4kOiw== 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=1721226287; 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=U+PfeL5VQ2ACFh5fMwo24PLf8iaI0bqT+xuv+Xu+M2s=; b=j/TeH/hxDw7ym0DyRLlvOwbE6HkIeu6ROqn19+5KRQ6uX0IFXuNKcZ3HqDcrYdfWs0Mr4k F+wIl9RH/PCI+lE0Xl2ycd6IcixJyz0OpzJX76qu3VorlRf6lALVZklhZQaDnG+zfCGWVh Olg6r2INRHfOpqLsYiDh/qOGu6ThQMQdvY3xEwGZ/DsX7px0fbfFRJIRUOQCbHpJI9xG5Z As55Oxfilwf/2V+vpYKdFsHIyG6/xvx/gm9OLZSOcuqSATF8nKHVGv+ikO31T+cruoLD5f bBJJ2U4yzCUFIEU4g2WNcyC1pa6kYFOs/tMf96Zs64h+ONcl89jN+yyvCS/Puw== 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 4WPJ9W38r3z1N0n; Wed, 17 Jul 2024 14:24:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46HEOlsL033562; Wed, 17 Jul 2024 14:24:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46HEOlKZ033559; Wed, 17 Jul 2024 14:24:47 GMT (envelope-from git) Date: Wed, 17 Jul 2024 14:24:47 GMT Message-Id: <202407171424.46HEOlKZ033559@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Navdeep Parhar Subject: git: 1d0abfccc47f - stable/13 - cxgbetool(8): Be flexible about the nexus name. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 1d0abfccc47f7f70c6dfd12dc96768259babf1f6 Auto-Submitted: auto-generated The branch stable/13 has been updated by np: URL: https://cgit.FreeBSD.org/src/commit/?id=1d0abfccc47f7f70c6dfd12dc96768259babf1f6 commit 1d0abfccc47f7f70c6dfd12dc96768259babf1f6 Author: Navdeep Parhar AuthorDate: 2024-06-13 20:17:55 +0000 Commit: Navdeep Parhar CommitDate: 2024-07-17 07:18:12 +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. Sponsored by: Chelsio Communications (cherry picked from commit e827b61cacddd4bc9a2f1657ad8c6d2bcd70d52e) --- 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 c02bc7fdc054..7b2b495a0292 100644 --- a/usr.sbin/cxgbetool/cxgbetool.c +++ b/usr.sbin/cxgbetool/cxgbetool.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -56,9 +57,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; @@ -88,7 +96,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" @@ -137,27 +145,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) @@ -523,7 +516,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); } @@ -915,7 +908,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"); @@ -934,7 +927,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; @@ -1925,10 +1918,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); } @@ -2244,7 +2237,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); @@ -2448,7 +2441,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}; @@ -3495,7 +3488,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); @@ -3650,14 +3643,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 @@ -3665,7 +3701,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")) { @@ -3679,7 +3715,7 @@ main(int argc, const char *argv[]) exit(EINVAL); } - parse_nexus_name(argv[1]); + open_nexus_device(argv[1]); /* progname and nexus */ argc -= 2;