From nobody Mon Nov 16 21:00:34 2026 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 4jT0cy64hSz70wJ6 for ; Mon, 16 Nov 2026 21:00: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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jT0cy3kTsz4C9d for ; Mon, 16 Nov 2026 21:00:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794862834; 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=KhvBInPxKzRQvfbN1kvBvSi29TfBO9+l9oubSnFcrhs=; b=Ti5qBVyq2ccWqeJ4XPHt/GyE83dZecVpMoqPYbNnXjBOjBgJeIN/5Bd9Sk0o6/E6DkQImH k2OK+Md4zuZXydnk+i3Cf0UWH1OY6cYQX3VomRmiEEfHMzg4owm4eVTCpyuLh3R0RLh/cW 7o+6O3/wM1glUtGF9vGFi+lpKz/G43Y7D0HzKmzIA59DC9SQbj6uMCT2S+p0a7NJ/LIirO DrYVkyA6nSQaLJHKVgWQ17KuYPXl7NWke9BMRrIWqtfvLekVC2WFFPCjQapvB+lpuxYsBO Ka3HXrcaqABFSddN8cZ7xn6OoGUkDvverxnxeTAHaN76KpYVOI8xfB37MlMy2Q== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794862834; b=DWczL6veSnRl2reH07QfrphfufxMjqkJYx1bn8TeS8ZoVht/4q+COKh5fneQW84NaLKc2V ++2p+ngzfRZsEq3zFzeJI2H+BRxiYBcxTzS4+3/jKqphhKCCgOc73EyLcEe6Bz9vsqUrNg kqWrhleOnURlbwWoAZdUl9iSIvmG4s6jzZVMNLyzrhQI+zuRIWlAL5e2ZMrqdTCfX/vxMH EEcTGlYY0lGa9HlT5Ncy1mTXaRcfCkteG8aYChvryKevsAwCEKtkxDYYhlWuFV/SdJqXr0 a30kgLaVIsEvKmjfixi89DbQDFfyxVJswXc1ijlYEmKU+aRAGO222xIyP3DESQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794862834; 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=KhvBInPxKzRQvfbN1kvBvSi29TfBO9+l9oubSnFcrhs=; b=WTTjW8Uxa/xeHXerweNytYPncnv69k0st0DbwD5oaNozw+mbIf4jN+icbrOnpIX5XGI8e8 31R9NHO4gWEJef22/se5VbmiWHYq79ruti9ak2EGqXOdEMtCL6fUF86xf+9dZlazseSjcT VFh3YTZ7hMGvNnTYO5t6jjLT9NF/1kPOTXDoKTxyrV999hUntUsunpnOOG1ycX58GJJHg2 YLe6450jDnBuS0BJKm7y7Cui6CKybc4OBryrgOhxH3ClW/W8Gi6MYZH+BoD+utIrWI0u9t FiCb696ekujHdJThMEEH3KzHbVRnzcAFCnPxaWsUuX/hlfjDzBGk32JZT3JKnA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jT0cy0T9Hz19HS for ; Mon, 16 Nov 2026 21:00:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 8f42 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 16 Nov 2026 21:00:34 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kenneth D. Merry Subject: git: b67a5156bae9 - stable/15 - camcontrol: Add support for NVMe namespace Identify List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ken X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: b67a5156bae9b0b857b2c10bd4a2e3f7a71e4054 Auto-Submitted: auto-generated Date: Mon, 16 Nov 2026 21:00:34 +0000 Message-Id: <6afb6ef2.8f42.10d7e338@gitrepo.freebsd.org> The branch stable/15 has been updated by ken: URL: https://cgit.FreeBSD.org/src/commit/?id=b67a5156bae9b0b857b2c10bd4a2e3f7a71e4054 commit b67a5156bae9b0b857b2c10bd4a2e3f7a71e4054 Author: Kenneth D. Merry AuthorDate: 2026-11-07 01:05:55 +0000 Commit: Kenneth D. Merry CommitDate: 2026-11-16 16:12:21 +0000 camcontrol: Add support for NVMe namespace Identify Add a -N argument to camcontrol identify. This will fetch and display namespace Identify data for NVMe drives, using nvme_print_namespace() from nvmecontrol(8). This gets the namespace Identify data via XPT_DEV_ADVINFO (i.e. data cached in the kernel) like the standard NVMe identify command does, and so works even on NVMe devices that do not support NVMe Namespace Management. sbin/camcontrol/camcontrol.c: Add a -N argument to camcontrol identify. Rename nvme_get_cdata() to nvme_get_data(), and give it the ability to fetch controller or namespace Identify data. While here, improve its error reporting with cam_error_print(), and only look at the CAM status bits of the returned CCB. Change identify(), ataidentify(), and nvmeidentify() to handle the extra arguments. Give nvmeidentify() the ability to fetch and print NVMe namespace data, using nvme_print_namespace() from nvmecontrol(8). sbin/camcontrol/camcontrol.h: Add the nvme_get_data() prototype, for use by future NVMe subcommands living outside camcontrol.c. sbin/camcontrol/camcontrol.8: Document camcontrol identify -N. Make it clear that the NVMe data is from data cached in the kernel. Add a cross reference to nvmecontrol(8). Co-authored-by: Claude Fable 5 Reviewed by: imp MFC after: 1 week Sponsored by: Spectra Logic Differential Revision: https://reviews.freebsd.org/D59533 (cherry picked from commit 961fa195b3486a0c3a02a8cf7aa95ccbc91c95de) --- sbin/camcontrol/camcontrol.8 | 14 +++++- sbin/camcontrol/camcontrol.c | 113 +++++++++++++++++++++++++++++++++---------- sbin/camcontrol/camcontrol.h | 2 + 3 files changed, 101 insertions(+), 28 deletions(-) diff --git a/sbin/camcontrol/camcontrol.8 b/sbin/camcontrol/camcontrol.8 index 4963615fe6f6..0a6d69fada5b 100644 --- a/sbin/camcontrol/camcontrol.8 +++ b/sbin/camcontrol/camcontrol.8 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd December 28, 2023 +.Dd August 21, 2026 .Dt CAMCONTROL 8 .Os .Sh NAME @@ -67,6 +67,7 @@ .Ic identify .Op device id .Op generic args +.Op Fl N .Op Fl v .Nm .Ic reportluns @@ -524,7 +525,15 @@ This is to aid in script writing. Print out transfer rate information. .El .It Ic identify -Send an ATA identify command (0xec) to a device. +Send a ATA identify command (0xec) or NVMe identify command to a device. +For NVMe devices, this displays Identify data cached in the kernel, and +does not send commands to the drive. +.Bl -tag -width 8n +.It Fl N +Display NVMe Identify Namespace data. +This shows the capacity of the namespace (CAM peripheral drivers are attached +to a NVMe namespace) as opposed to the entire drive. +.El .It Ic reportluns Send the SCSI REPORT LUNS (0xA0) command to the given device. By default, @@ -2935,6 +2944,7 @@ camcontrol timestamp sa0 -s -f "%a, %d %b %Y %T %z" \e .Xr pass 4 , .Xr xpt 4 , .Xr diskinfo 8 , +.Xr nvmecontrol 8 , .Xr trim 8 , .Xr zonectl 8 .Sh HISTORY diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c index 7ad177c3e4b6..bec8756324e6 100644 --- a/sbin/camcontrol/camcontrol.c +++ b/sbin/camcontrol/camcontrol.c @@ -185,7 +185,7 @@ static char pwd_opt; static struct camcontrol_opts option_table[] = { {"tur", CAM_CMD_TUR, CAM_ARG_NONE, NULL}, {"inquiry", CAM_CMD_INQUIRY, CAM_ARG_NONE, "DSR"}, - {"identify", CAM_CMD_IDENTIFY, CAM_ARG_NONE, NULL}, + {"identify", CAM_CMD_IDENTIFY, CAM_ARG_NONE, "N"}, {"start", CAM_CMD_STARTSTOP, CAM_ARG_START_UNIT, NULL}, {"stop", CAM_CMD_STARTSTOP, CAM_ARG_NONE, NULL}, {"load", CAM_CMD_STARTSTOP, CAM_ARG_START_UNIT | CAM_ARG_EJECT, NULL}, @@ -779,12 +779,35 @@ print_dev_mmcsd(struct device_match_result *dev_result, char *tmpstr) return (0); } -static int -nvme_get_cdata(struct cam_device *dev, struct nvme_controller_data *cdata) +int +nvme_get_data(struct cam_device *dev, int nvme_data_type, void *data, + size_t data_len) { union ccb *ccb; + struct nvme_controller_data *cdata; + struct nvme_namespace_data *nsdata; struct ccb_dev_advinfo *advi; + switch (nvme_data_type) { + case CDAI_TYPE_NVME_CNTRL: + if (data_len != sizeof(*cdata)) { + warnx("%s: supplied data length %zu != controller data " + "length %zu", __func__, data_len, sizeof(*nsdata)); + goto bailout_error; + } + break; + case CDAI_TYPE_NVME_NS: + if (data_len != sizeof(*nsdata)) { + warnx("%s: supplied data length %zu != namespace data " + "length %zu", __func__, data_len, sizeof(*nsdata)); + goto bailout_error; + } + break; + default: + warnx("Unknown NVMe data type %d", nvme_data_type); + goto bailout_error; + } + ccb = cam_getccb(dev); if (ccb == NULL) { warnx("couldn't allocate CCB"); @@ -792,28 +815,31 @@ nvme_get_cdata(struct cam_device *dev, struct nvme_controller_data *cdata) return (1); } + CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cdai); advi = &ccb->cdai; advi->ccb_h.flags = CAM_DIR_IN; advi->ccb_h.func_code = XPT_DEV_ADVINFO; advi->flags = CDAI_FLAG_NONE; - advi->buftype = CDAI_TYPE_NVME_CNTRL; - advi->bufsiz = sizeof(struct nvme_controller_data); - advi->buf = (uint8_t *)cdata; + advi->buftype = nvme_data_type; + advi->bufsiz = data_len; + advi->buf = data; if (cam_send_ccb(dev, ccb) < 0) { - warn("error sending XPT_DEV_ADVINFO CCB"); + warn("%s: error sending XPT_DEV_ADVINFO CCB", __func__); cam_freeccb(ccb); - cam_close_device(dev); - return(1); + goto bailout_error; } - if (advi->ccb_h.status != CAM_REQ_CMP) { - warnx("got CAM error %#x", advi->ccb_h.status); + if ((advi->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { + cam_error_print(dev, ccb, CAM_ESF_ALL, CAM_EPF_ALL, stderr); cam_freeccb(ccb); - cam_close_device(dev); - return(1); + goto bailout_error; } cam_freeccb(ccb); return 0; + +bailout_error: + cam_close_device(dev); + return (1); } static int @@ -830,7 +856,7 @@ print_dev_nvme(struct device_match_result *dev_result, char *tmpstr) return (1); } - if (nvme_get_cdata(dev, &cdata)) + if (nvme_get_data(dev, CDAI_TYPE_NVME_CNTRL, &cdata, sizeof(cdata))) return (1); cam_strvis(vendor, cdata.mn, sizeof(cdata.mn), sizeof(vendor)); @@ -2470,7 +2496,8 @@ retry: static int -ataidentify(struct cam_device *device, int retry_count, int timeout) +ataidentify(struct cam_device *device, int argc __unused, char **argv __unused, + char *combinedopt __unused, int retry_count, int timeout) { union ccb *ccb; struct ata_params *ident_buf; @@ -2515,19 +2542,47 @@ ataidentify(struct cam_device *device, int retry_count, int timeout) } static int -nvmeidentify(struct cam_device *device, int retry_count __unused, int timeout __unused) +nvmeidentify(struct cam_device *device, int argc, char **argv, + char *combinedopt, int retry_count __unused, int timeout __unused) { - struct nvme_controller_data cdata; + int ns_identify = 0; + int c; - if (nvme_get_cdata(device, &cdata)) - return (1); - nvme_print_controller(&cdata); + + while ((c = getopt(argc, argv, combinedopt)) != -1) { + switch (c) { + case 'N': + ns_identify = 1; + break; + default: + break; + } + } + + if (ns_identify == 0) { + struct nvme_controller_data cdata; + + if (nvme_get_data(device, CDAI_TYPE_NVME_CNTRL, &cdata, + sizeof(cdata))) + return (1); + + nvme_print_controller(&cdata); + } else { + struct nvme_namespace_data ns_data; + + if (nvme_get_data(device, CDAI_TYPE_NVME_NS, &ns_data, + sizeof(ns_data))) + return (1); + + nvme_print_namespace(&ns_data); + } return (0); } static int -identify(struct cam_device *device, int retry_count, int timeout) +identify(struct cam_device *device, int argc, char **argv, char *combinedopt, + int retry_count, int timeout) { struct ccb_pathinq cpi; @@ -2537,9 +2592,12 @@ identify(struct cam_device *device, int retry_count, int timeout) } if (cpi.protocol == PROTO_NVME) { - return (nvmeidentify(device, retry_count, timeout)); + return (nvmeidentify(device, argc, argv, combinedopt, + retry_count, timeout)); + } else { + return (ataidentify(device, argc, argv, combinedopt, + retry_count, timeout)); } - return (ataidentify(device, retry_count, timeout)); } @@ -10030,7 +10088,7 @@ usage(int printlong) " camcontrol tur [dev_id][generic args]\n" " camcontrol sense [dev_id][generic args][-D][-x]\n" " camcontrol inquiry [dev_id][generic args] [-D] [-S] [-R]\n" -" camcontrol identify [dev_id][generic args] [-v]\n" +" camcontrol identify [dev_id][generic args] [-N] [-v]\n" " camcontrol reportluns [dev_id][generic args] [-c] [-l] [-r report]\n" " camcontrol readcap [dev_id][generic args] [-b] [-h] [-H] [-N]\n" " [-q] [-s] [-l]\n" @@ -10120,7 +10178,7 @@ usage(int printlong) "sense send a request sense command to the named device\n" "tur send a test unit ready to the named device\n" "inquiry send a SCSI inquiry command to the named device\n" -"identify send a ATA identify command to the named device\n" +"identify send a ATA or NVMe identify command to the named device\n" "reportluns send a SCSI report luns command to the device\n" "readcap send a SCSI read capacity command to the device\n" "start send a Start Unit command to the device\n" @@ -10189,6 +10247,8 @@ usage(int printlong) "-D get the standard inquiry data\n" "-S get the serial number\n" "-R get the transfer rate, etc.\n" +"identify arguments:\n" +"-N send identify to the NVMe namespace\n" "reportluns arguments:\n" "-c only report a count of available LUNs\n" "-l only print out luns, and not a count\n" @@ -10668,7 +10728,8 @@ main(int argc, char **argv) task_attr, retry_count, timeout); break; case CAM_CMD_IDENTIFY: - error = identify(cam_dev, retry_count, timeout); + error = identify(cam_dev, argc, argv, combinedopt, retry_count, + timeout); break; case CAM_CMD_STARTSTOP: error = scsistart(cam_dev, arglist & CAM_ARG_START_UNIT, diff --git a/sbin/camcontrol/camcontrol.h b/sbin/camcontrol/camcontrol.h index ebc6d4039f8f..6417fea97bfd 100644 --- a/sbin/camcontrol/camcontrol.h +++ b/sbin/camcontrol/camcontrol.h @@ -75,6 +75,8 @@ int build_ata_cmd(union ccb *ccb, uint32_t retry_count, uint32_t flags, int get_ata_status(struct cam_device *dev, union ccb *ccb, uint8_t *error, uint16_t *count, uint64_t *lba, uint8_t *device, uint8_t *status); +int nvme_get_data(struct cam_device *dev, int nvme_data_type, void *data, + size_t data_len); int camxferrate(struct cam_device *device); int fwdownload(struct cam_device *device, int argc, char **argv, char *combinedopt, int printerrors, int task_attr,