From patchwork Wed Nov 16 06:50:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 9430965 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DC6FF6021C for ; Wed, 16 Nov 2016 06:51:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD24A28DEC for ; Wed, 16 Nov 2016 06:51:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C070D28E01; Wed, 16 Nov 2016 06:51:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67B4D28DEC for ; Wed, 16 Nov 2016 06:51:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752169AbcKPGvL (ORCPT ); Wed, 16 Nov 2016 01:51:11 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33926 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751245AbcKPGvK (ORCPT ); Wed, 16 Nov 2016 01:51:10 -0500 Received: by mail-pf0-f193.google.com with SMTP id y68so9295279pfb.1 for ; Tue, 15 Nov 2016 22:51:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5rwF+Dnl1AdDYgXvXpwgzSF8wG7gPacPzhFPoCguRLo=; b=XK/v2z5Lx1grHJ4YWQkWCcEqcZUgjpL3OvDzcpUOwBIIFnKf0V6UnIJpomVUK+Nutp uxiCT72hekUTy8CEyeey9u8OHgLBq688Hgj6NnRv2TyHBV07plyj8DmlQuK30zSfL1me 7Rp9b/gVxpvJa4UMLrdCwJScTSf9j2N6BDeGsmnHqDFVoRV9G2HFZLmo96hUwm8TpXIv oDdtzD6hsqy6bzUyyrKCY/9Sl+o3TEZBzWG2SJisI77yPMDfaveE907OvjNs6cfovZXr I15AxkPs9XHM0PuO/7CC302uB5RcGnWz3alNYD0IvrOwbFgE9paDklmUGmchR1Hr2+fU ho6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5rwF+Dnl1AdDYgXvXpwgzSF8wG7gPacPzhFPoCguRLo=; b=IKtX8CBUkq28e0022qjBua1v+aKpHeSNpD1SWWtHnNtKT5+JpiNlIYKt43tz9F8j6f GksZGZuLb4Vco/YtdZOYgh1lSwNCz7uNM7yBhLSJ6xfuZXyM5FRc3RLHZEtOCMtqN3BW PNbd+RFX37u/6lY1tVie0Bn4JvExx6SWggIdj2HrQ5TGji5pBmMU5dVf2iJ7InjwdEe5 wD3sh+6vb3WHRZYBKruz5ATsLevz8lvu+8E3Y+JzU+Mjif4IuGU5zAmSK+c4X3S+UnSl f7r5OTN6Jj09lsfH17uMvfh9s7FvJyRwBLXjc822yYC0qGOg8gtSz4Q9VqhIcEum4DMl zozQ== X-Gm-Message-State: ABUngvdcYP6qdOkwIURAgxjtnuatWyGzsqKevBcZxAQ1wMei+S/5Xj6HRrZVmeyOVcxSvQ== X-Received: by 10.98.56.149 with SMTP id f143mr2363169pfa.106.1479279069827; Tue, 15 Nov 2016 22:51:09 -0800 (PST) Received: from ztester-Precision-T3600.hgst.com (sjc00ib2.hgst.com. [199.255.44.5]) by smtp.googlemail.com with ESMTPSA id 16sm30902972pfk.54.2016.11.15.22.51.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Nov 2016 22:51:09 -0800 (PST) From: Chaitanya Kulkarni X-Google-Original-From: Chaitanya Kulkarni To: axboe@fb.com Cc: martin.petersen@oracle.com, keith.busch@intel.com, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, Chaitanya Kulkarni Subject: [PATCH 4/5] nvme: add support for the Write Zeroes command Date: Tue, 15 Nov 2016 22:50:38 -0800 Message-Id: <1479279039-25818-5-git-send-email-chaitanya.kulkarni@hgst.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1479279039-25818-1-git-send-email-chaitanya.kulkarni@hgst.com> References: <1479279039-25818-1-git-send-email-chaitanya.kulkarni@hgst.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allow write zeroes operations (REQ_OP_WRITE_ZEROES) on the queue if device supports optinal command bit set for write zeroes. Add support to setup write zeroes command. Signed-off-by: Chaitanya Kulkarni Reviewed-by: Sagi Grimberg --- drivers/nvme/host/core.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 3fcd1f4..d1ebb2c 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -272,6 +272,21 @@ static inline int nvme_setup_discard(struct nvme_ns *ns, struct request *req, return 0; } +static inline void nvme_setup_write_zeroes(struct nvme_ns *ns, + struct request *req, struct nvme_command *cmnd) +{ + struct nvme_write_zeroes_cmd *write_zeroes = &cmnd->write_zeroes; + + memset(cmnd, 0, sizeof(*cmnd)); + write_zeroes->opcode = nvme_cmd_write_zeroes; + write_zeroes->nsid = cpu_to_le32(ns->ns_id); + write_zeroes->slba = + cpu_to_le64(nvme_block_nr(ns, blk_rq_pos(req))); + write_zeroes->length = + cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1); + write_zeroes->control = 0; +} + static inline void nvme_setup_rw(struct nvme_ns *ns, struct request *req, struct nvme_command *cmnd) { @@ -325,6 +340,8 @@ int nvme_setup_cmd(struct nvme_ns *ns, struct request *req, nvme_setup_flush(ns, cmd); else if (req_op(req) == REQ_OP_DISCARD) ret = nvme_setup_discard(ns, req, cmd); + else if (req_op(req) == REQ_OP_WRITE_ZEROES) + nvme_setup_write_zeroes(ns, req, cmd); else nvme_setup_rw(ns, req, cmd); @@ -943,6 +960,10 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id) if (ns->ctrl->oncs & NVME_CTRL_ONCS_DSM) nvme_config_discard(ns); + + if (ns->ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) + queue_flag_set_unlocked(QUEUE_FLAG_WRITE_ZEROES, ns->queue); + blk_mq_unfreeze_queue(disk->queue); }