From owner-svn-src-all@freebsd.org Thu Feb 1 21:11:19 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0AD85EC9A06; Thu, 1 Feb 2018 21:11:19 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B01BA86599; Thu, 1 Feb 2018 21:11:18 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AB17E12528; Thu, 1 Feb 2018 21:11:18 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w11LBIQq078234; Thu, 1 Feb 2018 21:11:18 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w11LBHp7078227; Thu, 1 Feb 2018 21:11:17 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201802012111.w11LBHp7078227@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Thu, 1 Feb 2018 21:11:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r328735 - in stable/11/sys/cam: . nvme X-SVN-Group: stable-11 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: in stable/11/sys/cam: . nvme X-SVN-Commit-Revision: 328735 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Feb 2018 21:11:19 -0000 Author: mav Date: Thu Feb 1 21:11:17 2018 New Revision: 328735 URL: https://svnweb.freebsd.org/changeset/base/328735 Log: MFC r322999 (by imp): Fix NVMe's use of XPT_GDEV_TYPE This patch changes the way XPT_GDEV_TYPE works for NVMe. The current ccb_getdev structure includes pointers to the NVMe Identify Controller and Namespace structures, but these are kernel virtual addresses which are not accessible from user space. As an alternative, the patch changes the pointers into padding in ccb_getdev and adds two new types to ccb_dev_advinfo to retrieve the Identify Controller (CDAI_TYPE_NVME_CNTRL) and Namespace (CDAI_TYPE_NVME_NS) data structures. Modified: stable/11/sys/cam/cam_ccb.h stable/11/sys/cam/cam_xpt.c stable/11/sys/cam/nvme/nvme_all.c stable/11/sys/cam/nvme/nvme_all.h stable/11/sys/cam/nvme/nvme_da.c stable/11/sys/cam/nvme/nvme_xpt.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/cam/cam_ccb.h ============================================================================== --- stable/11/sys/cam/cam_ccb.h Thu Feb 1 21:07:55 2018 (r328734) +++ stable/11/sys/cam/cam_ccb.h Thu Feb 1 21:11:17 2018 (r328735) @@ -362,8 +362,7 @@ struct ccb_getdev { u_int8_t serial_num[252]; u_int8_t inq_flags; u_int8_t serial_num_len; - const struct nvme_controller_data *nvme_cdata; - const struct nvme_namespace_data *nvme_data; + void *padding[2]; }; /* Device Statistics CCB */ @@ -1227,6 +1226,8 @@ struct ccb_dev_advinfo { #define CDAI_TYPE_PHYS_PATH 3 #define CDAI_TYPE_RCAPLONG 4 #define CDAI_TYPE_EXT_INQ 5 +#define CDAI_TYPE_NVME_CNTRL 6 /* NVMe Identify Controller data */ +#define CDAI_TYPE_NVME_NS 7 /* NVMe Identify Namespace data */ off_t bufsiz; /* IN: Size of external buffer */ #define CAM_SCSI_DEVID_MAXLEN 65536 /* length in buffer is an uint16_t */ off_t provsiz; /* OUT: Size required/used */ Modified: stable/11/sys/cam/cam_xpt.c ============================================================================== --- stable/11/sys/cam/cam_xpt.c Thu Feb 1 21:07:55 2018 (r328734) +++ stable/11/sys/cam/cam_xpt.c Thu Feb 1 21:11:17 2018 (r328735) @@ -2693,8 +2693,6 @@ call_sim: cgd->inq_data = dev->inq_data; cgd->ident_data = dev->ident_data; cgd->inq_flags = dev->inq_flags; - cgd->nvme_data = dev->nvme_data; - cgd->nvme_cdata = dev->nvme_cdata; cgd->ccb_h.status = CAM_REQ_CMP; cgd->serial_num_len = dev->serial_num_len; if ((dev->serial_num_len > 0) Modified: stable/11/sys/cam/nvme/nvme_all.c ============================================================================== --- stable/11/sys/cam/nvme/nvme_all.c Thu Feb 1 21:07:55 2018 (r328734) +++ stable/11/sys/cam/nvme/nvme_all.c Thu Feb 1 21:11:17 2018 (r328735) @@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #else #include @@ -54,6 +55,13 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef _KERNEL +#include +#include +#include +#include +#endif + void nvme_ns_cmd(struct ccb_nvmeio *nvmeio, uint8_t cmd, uint32_t nsid, uint32_t cdw10, uint32_t cdw11, uint32_t cdw12, uint32_t cdw13, @@ -121,4 +129,24 @@ nvme_cmd_string(const struct nvme_command *cmd, char * cmd->cdw10, cmd->cdw11, cmd->cdw12, cmd->cdw13, cmd->cdw14, cmd->cdw15); return cmd_string; +} + +const void * +nvme_get_identify_cntrl(struct cam_periph *periph) +{ + struct cam_ed *device; + + device = periph->path->device; + + return device->nvme_cdata; +} + +const void * +nvme_get_identify_ns(struct cam_periph *periph) +{ + struct cam_ed *device; + + device = periph->path->device; + + return device->nvme_data; } Modified: stable/11/sys/cam/nvme/nvme_all.h ============================================================================== --- stable/11/sys/cam/nvme/nvme_all.h Thu Feb 1 21:07:55 2018 (r328734) +++ stable/11/sys/cam/nvme/nvme_all.h Thu Feb 1 21:11:17 2018 (r328735) @@ -44,5 +44,7 @@ int nvme_identify_match(caddr_t identbuffer, caddr_t t void nvme_print_ident(const struct nvme_controller_data *, const struct nvme_namespace_data *); const char *nvme_op_string(const struct nvme_command *); const char *nvme_cmd_string(const struct nvme_command *, char *, size_t); +const void *nvme_get_identify_cntrl(struct cam_periph *); +const void *nvme_get_identify_ns(struct cam_periph *); #endif /* CAM_NVME_NVME_ALL_H */ Modified: stable/11/sys/cam/nvme/nvme_da.c ============================================================================== --- stable/11/sys/cam/nvme/nvme_da.c Thu Feb 1 21:07:55 2018 (r328734) +++ stable/11/sys/cam/nvme/nvme_da.c Thu Feb 1 21:11:17 2018 (r328735) @@ -686,21 +686,14 @@ ndaregister(struct cam_periph *periph, void *arg) struct nda_softc *softc; struct disk *disk; struct ccb_pathinq cpi; - struct ccb_getdev *cgd; const struct nvme_namespace_data *nsd; const struct nvme_controller_data *cd; char announce_buf[80]; -// caddr_t match; u_int maxio; int quirks; - cgd = (struct ccb_getdev *)arg; - if (cgd == NULL) { - printf("ndaregister: no getdev CCB, can't register device\n"); - return(CAM_REQ_CMP_ERR); - } - nsd = cgd->nvme_data; - cd = cgd->nvme_cdata; + nsd = nvme_get_identify_ns(periph); + cd = nvme_get_identify_cntrl(periph); softc = (struct nda_softc *)malloc(sizeof(*softc), M_DEVBUF, M_NOWAIT | M_ZERO); @@ -721,19 +714,7 @@ ndaregister(struct cam_periph *periph, void *arg) periph->softc = softc; -#if 0 - /* - * See if this device has any quirks. - */ - match = cam_quirkmatch((caddr_t)&cgd->ident_data, - (caddr_t)nda_quirk_table, - sizeof(nda_quirk_table)/sizeof(*nda_quirk_table), - sizeof(*nda_quirk_table), ata_identify_match); - if (match != NULL) - softc->quirks = ((struct nda_quirk_entry *)match)->quirks; - else -#endif - softc->quirks = NDA_Q_NONE; + softc->quirks = NDA_Q_NONE; bzero(&cpi, sizeof(cpi)); xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE); Modified: stable/11/sys/cam/nvme/nvme_xpt.c ============================================================================== --- stable/11/sys/cam/nvme/nvme_xpt.c Thu Feb 1 21:07:55 2018 (r328734) +++ stable/11/sys/cam/nvme/nvme_xpt.c Thu Feb 1 21:11:17 2018 (r328735) @@ -519,6 +519,24 @@ nvme_dev_advinfo(union ccb *start_ccb) memcpy(cdai->buf, device->physpath, amt); } break; + case CDAI_TYPE_NVME_CNTRL: + if (cdai->flags & CDAI_FLAG_STORE) + return; + amt = sizeof(struct nvme_controller_data); + cdai->provsiz = amt; + if (amt > cdai->bufsiz) + amt = cdai->bufsiz; + memcpy(cdai->buf, device->nvme_cdata, amt); + break; + case CDAI_TYPE_NVME_NS: + if (cdai->flags & CDAI_FLAG_STORE) + return; + amt = sizeof(struct nvme_namespace_data); + cdai->provsiz = amt; + if (amt > cdai->bufsiz) + amt = cdai->bufsiz; + memcpy(cdai->buf, device->nvme_data, amt); + break; default: return; }