Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp597872pxu; Fri, 11 Dec 2020 09:35:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIBloCx8IWwYvTtRtwvGKG4Tsjt+ZCTchcHTSamo7U8jKfTCOhRio/yN/fw0NvcR5nGa7y X-Received: by 2002:a05:6402:19b0:: with SMTP id o16mr12955191edz.270.1607708116574; Fri, 11 Dec 2020 09:35:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607708116; cv=none; d=google.com; s=arc-20160816; b=hj1jADxqhqigVFdFUFhMuEEnt6Mb8BhRUJJQ7YLpmTp1pd9gkewUU/0azDmNQmABs8 Ng8gd6pFGNytotl3Swc7Fnpu48wDuP9S33DdoFk0dHXXqDPKqUAPkuD9mrK+docb/owy EUtoD5mlNMBHQnjP0vi16drj4WVhtlxUF9SvwsFpnZtEe8e+1PdeHpZ+W26rQ9V/OSZm LCiFFLdDnuAinBE1cXzCvod5cq0qE3n+3NGQph1nfOdNXVBFLUuAOfDwcSGarEadUgzx PB9+bSUISoB5jJR4NtiltEL4Wp0t6nvNrz222ZOgA7wd1NsYnOs9w7/zzPHkBThUv+Sv u9Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :mime-version:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=R5FcDS/TS17GZcZwvPhvmqWTKtggijaSfKGhePCYnr4=; b=cJCIR4k7+PkUXnjh0seVmokdFavmd+mERSJmUsp+Urtf70FzIlwvU/ARUz/C3OoP9k dLfGhUGvzIcrZ4WCnvPRvMXD74xaHn5tnllqdVV6Wfvr7wgIm2G+0A4sux+Kwu7ja4et S5lWbwHHgxhV6ae9n658f0iJXsRgP2y2peErvX+8aZ0l6w3hYwaPDxTZDXYj7CrkLsDC beVDIdoCxetYvqi29ekY8nGIZWKdKk86krOxA6EN10nV1xn0jJo1jB6ftXv01VjCiwik XkgFSMch9yZuIQe3Gx/vF++ozlNSc1i85YUtCy9H4aF7ifAW22TVyejpZi5HV+2jvsaJ WLxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=rkFvPXtP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hq10si4868489ejc.616.2020.12.11.09.34.50; Fri, 11 Dec 2020 09:35:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=rkFvPXtP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406403AbgLKO6U (ORCPT + 99 others); Fri, 11 Dec 2020 09:58:20 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:64046 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406402AbgLKO6N (ORCPT ); Fri, 11 Dec 2020 09:58:13 -0500 Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20201211145730epoutp0210d63531f3f98005404055c09639727e~PsWek_o9e1723917239epoutp02N for ; Fri, 11 Dec 2020 14:57:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20201211145730epoutp0210d63531f3f98005404055c09639727e~PsWek_o9e1723917239epoutp02N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1607698650; bh=R5FcDS/TS17GZcZwvPhvmqWTKtggijaSfKGhePCYnr4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rkFvPXtPj7TrGoz33ISud3AqLVKNron7cU2pR82daTE3Mo8zGQ4R+yqtQKdcHJdSM AMpjUtv04PB8b1ygvztSfaXPayWupWyF6CGlkMu1g0XYaf9TkEdvKGo3RQgy0i8jIW 4N8oUzufesiikJzp2IePGXWVaO/3iHFZkAYVEQeo= Received: from epsmges5p2new.samsung.com (unknown [182.195.42.74]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20201211145729epcas5p32c66a0996a1c53b24668c1be9d615611~PsWdpWNVp2218722187epcas5p35; Fri, 11 Dec 2020 14:57:29 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 0E.00.50652.9D883DF5; Fri, 11 Dec 2020 23:57:29 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20201211135205epcas5p1f1696075e1354f0f4c7af04b950d514c~PrdW6fQb60154201542epcas5p1m; Fri, 11 Dec 2020 13:52:05 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20201211135205epsmtrp2fe2f38d12e5212d5f5464f91ae3d27ce~PrdW5WhCB0569205692epsmtrp2S; Fri, 11 Dec 2020 13:52:05 +0000 (GMT) X-AuditID: b6c32a4a-6b3ff7000000c5dc-24-5fd388d96153 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id D5.71.08745.58973DF5; Fri, 11 Dec 2020 22:52:05 +0900 (KST) Received: from localhost.localdomain (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20201211135202epsmtip26706456da2bdcb8021663f93a8476308~PrdTz_pmh2927029270epsmtip2H; Fri, 11 Dec 2020 13:52:02 +0000 (GMT) From: SelvaKumar S To: linux-nvme@lists.infradead.org Cc: kbusch@kernel.org, axboe@kernel.dk, damien.lemoal@wdc.com, Johannes.Thumshirn@wdc.com, hch@lst.de, sagi@grimberg.me, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, martin.petersen@oracle.com, bvanassche@acm.org, mpatocka@redhat.com, hare@suse.de, dm-devel@redhat.com, snitzer@redhat.com, selvajove@gmail.com, nj.shetty@samsung.com, joshi.k@samsung.com, javier.gonz@samsung.com, SelvaKumar S Subject: [RFC PATCH v3 2/2] nvme: add simple copy support Date: Fri, 11 Dec 2020 19:21:39 +0530 Message-Id: <20201211135139.49232-3-selvakuma.s1@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201211135139.49232-1-selvakuma.s1@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA02Sf0wTZxjH996dd9eykgORvaJzS5PpcLPIhtvLVFyyut00S7YRFkKywbme hQmla+lQt2hxY0LZUJg/YpFhCMFRfzBKB11piSlzhbpftCCipYFAySbR8mM4tCvO9lj0v8/7 PJ8n3zxPXhqPLyOT6AJVCa9RcYVSUkx09CSv2zBc4c3deOymFJ0bOUKiE9N3cVR++A6GHLfr liF7Yy2GWs5dxtC4b45CYYMfQ5fv3yJRrfMqQI7rzyGv7TSJGpoDFKoaspLorGsRQzUVgxjq CDXgaOBYI44uTgUJNBocotDUQh+JvmybB68mst6BneyPxhGK/d3fRrDeX3Ws2VRJsu1NB9mu YT3JzgSuE2ywe5Bkqy0mwLZf+ZSdM69hD1+qwt6W5Ii3KPjCgk94TUpGnjjfXbmIqQ9t3mua byX0wC0zAJqGTBoc/y3HAER0PNMFYMD9sgGIH/AsgKNlnaTwmANw2GAgI1ZkwOlvXmrYACz/ ZuahZZ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qTmZZalF+nYJXBmnOv8xFTRZV6z6up6lgfGUXhcjJ4eEgInEoXvL 2LoYuTiEBHYwSvyZ1cYOkZCRWHu3kw3CFpZY+e85O0TRR0aJuefPMYIk2AR0Ja4t2cQCYosI KEn8Xd/EAlLELPCZWWL+rjawhLCApcSdf3OZQWwWAVWJZ0dWgdm8ArYSn/6+ZYTYIC8x89J3 sM2cAnYSfVvugNUIAdXcP9nPClEvKHFy5hOgmRxAC9Ql1s8TAgkzA7U2b53NPIFRcBaSqlkI VbOQVC1gZF7FKJlaUJybnltsWGCUl1quV5yYW1yal66XnJ+7iREc4VpaOxj3rPqgd4iRiYPx EKMEB7OSCK8sy6V4Id6UxMqq1KL8+KLSnNTiQ4zSHCxK4rwXuk7GCwmkJ5akZqemFqQWwWSZ ODilGpiWNjy2vW/y8cV5nRVPNrSZ560yKDywskhy0uv/BYdXv0vUTr/6/K/CsUUu79lzE9v2 76nSXf3e6XjQXm8hqSMzpGofOoqG8yT0sj7/fP7W/RtTb16rduk/9sY8pmKzYC+znGKtHP+k I3tjbKdZyb8Qvpyd86twxbO/OryTjXqzTNK2ur/YHx59OiLjg3+53T6LI/+uq+zOn+nrJDLJ 0b/Pndsp4vH0fcfLpu38dzPlzvb5DSqOW/57tKUXl9bon4/s5BBJvz9t/tHVna/1rt9Z+rvm 2KaPoTHaur3yP+urXBe/3ayyZP+7QIevHV+2trsttjeNuucs/lju4Z9/Qi4mb17vmnDbiedK iyRL37I2JZbijERDLeai4kQAJ1oB6F8DAAA= X-CMS-MailID: 20201211135205epcas5p1f1696075e1354f0f4c7af04b950d514c X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20201211135205epcas5p1f1696075e1354f0f4c7af04b950d514c References: <20201211135139.49232-1-selvakuma.s1@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for TP 4065a ("Simple Copy Command"), v2020.05.04 ("Ratified") The implementation uses the payload passed from the block layer to form simple copy command. Set the device copy limits to queue limits. Signed-off-by: SelvaKumar S Signed-off-by: Kanchan Joshi Signed-off-by: Nitesh Shetty Signed-off-by: Javier González --- drivers/nvme/host/core.c | 89 ++++++++++++++++++++++++++++++++++++++++ include/linux/nvme.h | 43 +++++++++++++++++-- 2 files changed, 129 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 9b6ebeb29cca..d235156ff565 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -647,6 +647,65 @@ static inline void nvme_setup_flush(struct nvme_ns *ns, cmnd->common.nsid = cpu_to_le32(ns->head->ns_id); } +static inline blk_status_t nvme_setup_copy(struct nvme_ns *ns, + struct request *req, struct nvme_command *cmnd) +{ + struct nvme_ctrl *ctrl = ns->ctrl; + struct nvme_copy_range *range = NULL; + struct blk_copy_payload *payload; + unsigned short nr_range = 0; + u16 control = 0, ssrl; + u32 dsmgmt = 0; + u64 slba; + int i; + + payload = bio_data(req->bio); + nr_range = payload->copy_range; + + if (req->cmd_flags & REQ_FUA) + control |= NVME_RW_FUA; + + if (req->cmd_flags & REQ_FAILFAST_DEV) + control |= NVME_RW_LR; + + cmnd->copy.opcode = nvme_cmd_copy; + cmnd->copy.nsid = cpu_to_le32(ns->head->ns_id); + cmnd->copy.sdlba = cpu_to_le64(blk_rq_pos(req) >> (ns->lba_shift - 9)); + + range = kmalloc_array(nr_range, sizeof(*range), + GFP_ATOMIC | __GFP_NOWARN); + if (!range) + return BLK_STS_RESOURCE; + + for (i = 0; i < nr_range; i++) { + slba = payload->range[i].src; + slba = slba >> (ns->lba_shift - 9); + + ssrl = payload->range[i].len; + ssrl = ssrl >> (ns->lba_shift - 9); + + range[i].slba = cpu_to_le64(slba); + range[i].nlb = cpu_to_le16(ssrl - 1); + } + + cmnd->copy.nr_range = nr_range - 1; + + req->special_vec.bv_page = virt_to_page(range); + req->special_vec.bv_offset = offset_in_page(range); + req->special_vec.bv_len = sizeof(*range) * nr_range; + req->rq_flags |= RQF_SPECIAL_PAYLOAD; + + if (ctrl->nr_streams) + nvme_assign_write_stream(ctrl, req, &control, &dsmgmt); + + //TBD end-to-end + + cmnd->rw.control = cpu_to_le16(control); + cmnd->rw.dsmgmt = cpu_to_le32(dsmgmt); + + return BLK_STS_OK; +} + static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req, struct nvme_command *cmnd) { @@ -829,6 +888,9 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req, case REQ_OP_DISCARD: ret = nvme_setup_discard(ns, req, cmd); break; + case REQ_OP_COPY: + ret = nvme_setup_copy(ns, req, cmd); + break; case REQ_OP_READ: ret = nvme_setup_rw(ns, req, cmd, nvme_cmd_read); break; @@ -1850,6 +1912,31 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns) blk_queue_max_write_zeroes_sectors(queue, UINT_MAX); } +static void nvme_config_copy(struct gendisk *disk, struct nvme_ns *ns, + struct nvme_id_ns *id) +{ + struct nvme_ctrl *ctrl = ns->ctrl; + struct request_queue *queue = disk->queue; + + if (!(ctrl->oncs & NVME_CTRL_ONCS_COPY)) { + queue->limits.copy_offload = 0; + queue->limits.max_copy_sectors = 0; + queue->limits.max_copy_range_sectors = 0; + queue->limits.max_copy_nr_ranges = 0; + blk_queue_flag_clear(QUEUE_FLAG_COPY, queue); + return; + } + + /* setting copy limits */ + blk_queue_flag_test_and_set(QUEUE_FLAG_COPY, queue); + queue->limits.copy_offload = 0; + queue->limits.max_copy_sectors = le64_to_cpu(id->mcl) * + (1 << (ns->lba_shift - 9)); + queue->limits.max_copy_range_sectors = le32_to_cpu(id->mssrl) * + (1 << (ns->lba_shift - 9)); + queue->limits.max_copy_nr_ranges = id->msrc + 1; +} + static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns) { u64 max_blocks; @@ -2045,6 +2132,7 @@ static void nvme_update_disk_info(struct gendisk *disk, set_capacity_and_notify(disk, capacity); nvme_config_discard(disk, ns); + nvme_config_copy(disk, ns, id); nvme_config_write_zeroes(disk, ns); if (id->nsattr & NVME_NS_ATTR_RO) @@ -4616,6 +4704,7 @@ static inline void _nvme_check_size(void) BUILD_BUG_ON(sizeof(struct nvme_download_firmware) != 64); BUILD_BUG_ON(sizeof(struct nvme_format_cmd) != 64); BUILD_BUG_ON(sizeof(struct nvme_dsm_cmd) != 64); + BUILD_BUG_ON(sizeof(struct nvme_copy_command) != 64); BUILD_BUG_ON(sizeof(struct nvme_write_zeroes_cmd) != 64); BUILD_BUG_ON(sizeof(struct nvme_abort_cmd) != 64); BUILD_BUG_ON(sizeof(struct nvme_get_log_page_command) != 64); diff --git a/include/linux/nvme.h b/include/linux/nvme.h index d92535997687..11ed72a2164d 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -289,7 +289,7 @@ struct nvme_id_ctrl { __u8 nvscc; __u8 nwpc; __le16 acwu; - __u8 rsvd534[2]; + __le16 ocfs; __le32 sgls; __le32 mnan; __u8 rsvd544[224]; @@ -314,6 +314,7 @@ enum { NVME_CTRL_ONCS_WRITE_ZEROES = 1 << 3, NVME_CTRL_ONCS_RESERVATIONS = 1 << 5, NVME_CTRL_ONCS_TIMESTAMP = 1 << 6, + NVME_CTRL_ONCS_COPY = 1 << 8, NVME_CTRL_VWC_PRESENT = 1 << 0, NVME_CTRL_OACS_SEC_SUPP = 1 << 0, NVME_CTRL_OACS_DIRECTIVES = 1 << 5, @@ -362,7 +363,10 @@ struct nvme_id_ns { __le16 npdg; __le16 npda; __le16 nows; - __u8 rsvd74[18]; + __le16 mssrl; + __le32 mcl; + __u8 msrc; + __u8 rsvd91[11]; __le32 anagrpid; __u8 rsvd96[3]; __u8 nsattr; @@ -673,6 +677,7 @@ enum nvme_opcode { nvme_cmd_resv_report = 0x0e, nvme_cmd_resv_acquire = 0x11, nvme_cmd_resv_release = 0x15, + nvme_cmd_copy = 0x19, nvme_cmd_zone_mgmt_send = 0x79, nvme_cmd_zone_mgmt_recv = 0x7a, nvme_cmd_zone_append = 0x7d, @@ -691,7 +696,8 @@ enum nvme_opcode { nvme_opcode_name(nvme_cmd_resv_register), \ nvme_opcode_name(nvme_cmd_resv_report), \ nvme_opcode_name(nvme_cmd_resv_acquire), \ - nvme_opcode_name(nvme_cmd_resv_release)) + nvme_opcode_name(nvme_cmd_resv_release), \ + nvme_opcode_name(nvme_cmd_copy)) /* @@ -863,6 +869,36 @@ struct nvme_dsm_range { __le64 slba; }; +struct nvme_copy_command { + __u8 opcode; + __u8 flags; + __u16 command_id; + __le32 nsid; + __u64 rsvd2; + __le64 metadata; + union nvme_data_ptr dptr; + __le64 sdlba; + __u8 nr_range; + __u8 rsvd12; + __le16 control; + __le16 rsvd13; + __le16 dspec; + __le32 ilbrt; + __le16 lbat; + __le16 lbatm; +}; + +struct nvme_copy_range { + __le64 rsvd0; + __le64 slba; + __le16 nlb; + __le16 rsvd18; + __le32 rsvd20; + __le32 eilbrt; + __le16 elbat; + __le16 elbatm; +}; + struct nvme_write_zeroes_cmd { __u8 opcode; __u8 flags; @@ -1400,6 +1436,7 @@ struct nvme_command { struct nvme_download_firmware dlfw; struct nvme_format_cmd format; struct nvme_dsm_cmd dsm; + struct nvme_copy_command copy; struct nvme_write_zeroes_cmd write_zeroes; struct nvme_zone_mgmt_send_cmd zms; struct nvme_zone_mgmt_recv_cmd zmr; -- 2.25.1