From owner-svn-src-head@freebsd.org Tue Jul 19 03:13:53 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4230FB9C46A; Tue, 19 Jul 2016 03:13:53 +0000 (UTC) (envelope-from scottl@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 mx1.freebsd.org (Postfix) with ESMTPS id 172731CBD; Tue, 19 Jul 2016 03:13:53 +0000 (UTC) (envelope-from scottl@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u6J3Dqmi063899; Tue, 19 Jul 2016 03:13:52 GMT (envelope-from scottl@FreeBSD.org) Received: (from scottl@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u6J3DpJU063896; Tue, 19 Jul 2016 03:13:51 GMT (envelope-from scottl@FreeBSD.org) Message-Id: <201607190313.u6J3DpJU063896@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: scottl set sender to scottl@FreeBSD.org using -f From: Scott Long Date: Tue, 19 Jul 2016 03:13:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r303017 - in head/sys/dev: nvd nvme X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jul 2016 03:13:53 -0000 Author: scottl Date: Tue Jul 19 03:13:51 2016 New Revision: 303017 URL: https://svnweb.freebsd.org/changeset/base/303017 Log: Implement crashdump support on NVME MFC after: 3 days Sponsored by: Netflix, Inc. Modified: head/sys/dev/nvd/nvd.c head/sys/dev/nvme/nvme.h head/sys/dev/nvme/nvme_ns_cmd.c Modified: head/sys/dev/nvd/nvd.c ============================================================================== --- head/sys/dev/nvd/nvd.c Tue Jul 19 00:47:00 2016 (r303016) +++ head/sys/dev/nvd/nvd.c Tue Jul 19 03:13:51 2016 (r303017) @@ -47,6 +47,7 @@ struct nvd_disk; static disk_ioctl_t nvd_ioctl; static disk_strategy_t nvd_strategy; +static dumper_t nvd_dump; static void nvd_done(void *arg, const struct nvme_completion *cpl); @@ -226,6 +227,26 @@ nvd_ioctl(struct disk *ndisk, u_long cmd return (ret); } +static int +nvd_dump(void *arg, void *virt, vm_offset_t phys, off_t offset, size_t len) +{ + struct nvd_disk *ndisk; + struct disk *dp; + int error; + + dp = arg; + ndisk = dp->d_drv1; + + if (len > 0) { + if ((error = nvme_ns_dump(ndisk->ns, virt, offset, len)) != 0) + return (error); + } else { + /* XXX sync to stable storage */ + } + + return (0); +} + static void nvd_done(void *arg, const struct nvme_completion *cpl) { @@ -302,6 +323,7 @@ nvd_new_disk(struct nvme_namespace *ns, disk = disk_alloc(); disk->d_strategy = nvd_strategy; disk->d_ioctl = nvd_ioctl; + disk->d_dump = nvd_dump; disk->d_name = NVD_STR; disk->d_drv1 = ndisk; Modified: head/sys/dev/nvme/nvme.h ============================================================================== --- head/sys/dev/nvme/nvme.h Tue Jul 19 00:47:00 2016 (r303016) +++ head/sys/dev/nvme/nvme.h Tue Jul 19 03:13:51 2016 (r303017) @@ -876,6 +876,8 @@ int nvme_ns_cmd_deallocate(struct nvme_n void *cb_arg); int nvme_ns_cmd_flush(struct nvme_namespace *ns, nvme_cb_fn_t cb_fn, void *cb_arg); +int nvme_ns_dump(struct nvme_namespace *ns, void *virt, off_t offset, + size_t len); /* Registration functions */ struct nvme_consumer * nvme_register_consumer(nvme_cons_ns_fn_t ns_fn, Modified: head/sys/dev/nvme/nvme_ns_cmd.c ============================================================================== --- head/sys/dev/nvme/nvme_ns_cmd.c Tue Jul 19 00:47:00 2016 (r303016) +++ head/sys/dev/nvme/nvme_ns_cmd.c Tue Jul 19 03:13:51 2016 (r303017) @@ -151,3 +151,47 @@ nvme_ns_cmd_flush(struct nvme_namespace return (0); } + +/* Timeout = 1 sec */ +#define NVD_DUMP_TIMEOUT 100000 + +int +nvme_ns_dump(struct nvme_namespace *ns, void *virt, off_t offset, size_t len) +{ + struct nvme_completion_poll_status status; + struct nvme_request *req; + struct nvme_command *cmd; + uint64_t lba, lba_count; + int i; + + status.done = FALSE; + req = nvme_allocate_request_vaddr(virt, len, nvme_completion_poll_cb, + &status); + if (req == NULL) + return (ENOMEM); + + cmd = &req->cmd; + cmd->opc = NVME_OPC_WRITE; + cmd->nsid = ns->id; + + lba = offset / nvme_ns_get_sector_size(ns); + lba_count = len / nvme_ns_get_sector_size(ns); + + *(uint64_t *)&cmd->cdw10 = lba; + cmd->cdw12 = lba_count - 1; + + nvme_ctrlr_submit_io_request(ns->ctrlr, req); + if (req->qpair == NULL) + return (ENXIO); + + i = 0; + while ((i++ < NVD_DUMP_TIMEOUT) && (status.done == FALSE)) { + DELAY(10); + nvme_qpair_process_completions(req->qpair); + } + + if (status.done == FALSE) + return (ETIMEDOUT); + + return (0); +}