From patchwork Wed Nov 30 20:29:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 9454859 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 7994C6074E for ; Wed, 30 Nov 2016 20:29:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E2A02015F for ; Wed, 30 Nov 2016 20:29:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62E4A284A2; Wed, 30 Nov 2016 20:29:36 +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_SIGNED, 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 F08212015F for ; Wed, 30 Nov 2016 20:29:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758000AbcK3U3f (ORCPT ); Wed, 30 Nov 2016 15:29:35 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:16841 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757922AbcK3U3e (ORCPT ); Wed, 30 Nov 2016 15:29:34 -0500 X-IronPort-AV: E=Sophos;i="5.31,574,1473091200"; d="scan'";a="41649615" Received: from mail-co1nam03lp0018.outbound.protection.outlook.com (HELO NAM03-CO1-obe.outbound.protection.outlook.com) ([216.32.181.18]) by ob1.hgst.iphmx.com with ESMTP; 01 Dec 2016 04:29:33 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Ok41o9CKa00ZYnj0ekiwqpgSNwrJshEkOxA0edFDA+w=; b=EozKJPGQItgXToEB/MGd7ejJS8mQGPQ340mLnTynmv4nXHzhv4p+sXvWWIIBKo/AQO0PtojsjChotiftB2sl7gHfe6v50SrvceL9VSSNcOgqvYURzeRTKhsOFWTkr4KTcJRFhYuqcES4jaGm/I2kqa5tfiAo3cxiQFLx0qndxRM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Chaitanya.Kulkarni@wdc.com; Received: from ztester-Precision-T3600.hgst.com (199.255.44.5) by CO2PR04MB2184.namprd04.prod.outlook.com (10.166.93.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.747.13; Wed, 30 Nov 2016 20:29:30 +0000 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 V2 4/5] nvme: add support for the Write Zeroes command Date: Wed, 30 Nov 2016 12:29:01 -0800 Message-Id: <1480537742-15190-4-git-send-email-chaitanya.kulkarni@hgst.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1480537742-15190-1-git-send-email-chaitanya.kulkarni@hgst.com> References: <1480537742-15190-1-git-send-email-chaitanya.kulkarni@hgst.com> MIME-Version: 1.0 X-Originating-IP: [199.255.44.5] X-ClientProxiedBy: BY2PR06CA0019.namprd06.prod.outlook.com (10.166.106.157) To CO2PR04MB2184.namprd04.prod.outlook.com (10.166.93.154) X-MS-Office365-Filtering-Correlation-Id: b46c3886-ad69-4456-1579-08d4195f96b5 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:CO2PR04MB2184; X-Microsoft-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pi9uyUo54+AOhRECI9KNdG4h4Fqg8MQuafQ2U5 X-Microsoft-Exchange-Diagnostics: 1; CO2PR04MB2184; 31:XqMP+fzZPAiwCayhkbYb3bdnnO2Clcssr7n53OoqL6/VfaIvS9UQDDbg3Z2q8MOXy0dgRC65io+LR6Y0r+duUfhrwrzq2Y+dz2DlXOb4cJbUFHUjpZt3A3jbRJN3z4uxG6t1fER+Wgocd2Rb9NVAcNLpwOkNljWEAUwyXlaNuYFyNL/CqCZMKCRiK7fkTI3n04O28H0i9FcUrn4GbyaVSzOZHMGLfzmv/TAUEJ/hWXY2TuNtmzBTi4cdcc1Tbv87OHTG4388dcEH5HwpzHE2TOUMhmSgqV0GBaoveTW5Q30=; 20:rzCn+iJsx1OKWEjcnZnBP7XK5yO5gk3giqI0TmO0WthbG3yxVaX7raeb2PvBxn3B+bBh8pWYH5WbeatJAdIiBP4cKJVOnO4BZzZsGRrt2gzPpBJ7NKjoE7X2rq3l0Eft/t3ljplY6ZDiVg9qoGw3Vb2gcpb0k2qbIRwAbw/4DLu2aoniOMqVBXXSAgJ2LrIlwIzxjqakhvFGqd78wjhOM3KFyiAeGd/iLqxowiAzcH+fhhGi3V/WfQ58tXOnp2mhAPPhNULv0OVs1vQjUTmeub9SY8fYpXHAuNN6Ly0ZIhnXmXQPFi7zT9HFSxRMOiVOtQrM7Gwzb5kro2SYAFoN6zHGo4sI4bxd6F8U05rLNOBVgwz0BRg/DRTYcx2JWfOULjNmBxcWqT+J27EOT8a937uB9+x31wGicDxi7ouNshmusZ+kFGxsWyHC+rXZZjkJK6Xt31ENUNXj/ROTJTNPXxG+08YRksKt4d249rjq52XVYBvJa1VQWf5KmAdmyOBH X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(79135771888625); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123555025)(20161123562025)(20161123564025)(6072148); SRVR:CO2PR04MB2184; BCL:0; PCL:0; RULEID:; SRVR:CO2PR04MB2184; X-Microsoft-Exchange-Diagnostics: 1; CO2PR04MB2184; 4:V7qRS4YUEbSa3whQMkqTxwOk2pDuZSnHDWNO9M8IYIpHNEsiXmk+DPIfsyOD/L45wqfkzsqfIWz4TULImUo1D1fE1hYImErKKgynmUtkbCZtoLFGw7qCsuB8YGB6Ao9+dI1AdzJJlg1Y1EyVrDz40T9IgHjToK6ewo1uVIQv4ZhgFN99tXWJdF3GnA0DAk+1w0fkq5KZG5ZFZm5NNGMGDjzcj+ckA9peFmyvic6GADVxX3qSAcpCBd6zCTHSq8kd0QnO2JBITwXBvyR/JUL0fzO/aDSP9aT8XUdqZJydHEqqVH5keeUmTKNeNAp8CW3joKGEmADB+OF50l9Ksmo7ZJrtmRskfP0VafxQ+q34aAvyYkpcKH9TGxN0RNIotatJ4ajhkCSlP0NC4saO8oGMuay0/mNsy4Nke3zSi0D1419iznP7rkFiKkloVVUpgdyIPIzYJxCpBoBYiUDX8tT6WnOdPj6FY/oSP/WTIc39mmKQ9v8c+vbvZUkZC/Ih5r1fEauiu1lr5Ny6Nup5xbz7F8dMJNv5qs2I/C77O8Q1TJhhlxIZhhLG1HS+1DaYUkPePLSCV0xYUCJkJ/WR11dKnquMOPxoBxpvVyzLh8+ePcV1gn9IYIwsG7tEwMhcUzdP X-Forefront-PRVS: 0142F22657 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(979002)(6009001)(7916002)(199003)(189002)(92566002)(81156014)(81166006)(68736007)(38730400001)(2950100002)(39410400001)(50226002)(42882006)(39450400002)(8676002)(733004)(69596002)(6486002)(66066001)(6666003)(50986999)(47776003)(101416001)(76176999)(106356001)(107886002)(33646002)(42186005)(2361001)(53416004)(2351001)(4326007)(36756003)(5003940100001)(189998001)(105586002)(4001430100002)(2906002)(5660300001)(6916009)(3846002)(6116002)(97736004)(305945005)(48376002)(7736002)(50466002)(110136003)(7846002)(7099028)(5005270100013)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1102; SCL:1; SRVR:CO2PR04MB2184; H:ztester-Precision-T3600.hgst.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: wdc.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CO2PR04MB2184; 23:8wfY9GaaCnEQSijipbFDmCj9wtqXDa2KTCEEB959N?= =?us-ascii?Q?XzMHw1hpHRbrNrB7CABunCmKPsoQTAdB+jYEN5qYZIZb+hxDOAxlXtLxcBKr?= =?us-ascii?Q?4q9LshqcKQ0cbXrVI6LhtEv5W/JyO+CGOj0JsFDeehK9m2ofVPklDoGi44j5?= =?us-ascii?Q?5Mp7MvF3MIl4oBHtrvBXDXxMTqdN2JKokyMu130X1V+tlUANAVCx4NQjg4hv?= =?us-ascii?Q?P6Jc5SRaavElhWPQ1dKKbRwIdcwKqjNTVuDFRsQWJU5HFLT3KBpaRCRuOkC7?= =?us-ascii?Q?oWTIqfODgMl4VNJxfl1fAIBHY1S9m6tTLegMk1sGQ0QyZg0DRPXsOINxFME0?= =?us-ascii?Q?0FreIbZbSG56tVRqrpMjyC2J/metf3TJ1J2RYrmlb0h6uEuYC2iIUHuIb738?= =?us-ascii?Q?1m5iTHvva1VmNoDfmy2E3NR+lIbYXVv/erMdDN+AxWIPkIM+baF9rYbWDRjv?= =?us-ascii?Q?DDAnGCAgFnvFiWfDXcK9ZiIHkD0CE70T6jvrp2E63Zvk85PaqQIZ6ozQsU8h?= =?us-ascii?Q?R0DzVgJi2xeYz9US0v0rVQ9NdhtbVo3EsiJ0xfmNzXzVXqFDxRtdt3V7OQF4?= =?us-ascii?Q?NlRMS+P9y791oi9Y1//+cXeSkVKtMi9j2qdyRfH8M+GzXbdv2sY1ZEanoySk?= =?us-ascii?Q?fGiPtTZQ+b+jfD/+Ka1nHJCKystxOV7JIwrz9KU5VEHmpI6qibcxF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4wSPGNnWcN7R7667tZLm1yJ0TNFFleGFqodzX1w==; 20:H9PlUbLqDsHoDIFLqsjIhuhx/uM+WKvHCvzQ2a92qGBCSR3j51pNKm6hNfwP++X70neiiLr2gp6feTCNtXc9UQz1fOlF+wMrvqzKPVr6NzkLEHKLBOBFXWUodbFY6XTm8SdX5OeVL/MCaXUw8fMGv11nEYRES5+ViIvqpn3vHjxWmT8Pi5P4bYUAhS+Bs+k7gjk1Etg8B/kT5Y1gympGMNhvq38griOFhPuJztKrnrZdmA6FJCPQeZuyT5qNyZy3 X-OriginatorOrg: hgst.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2016 20:29:30.0098 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR04MB2184 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 block device, if the device supports optional command bit set for write zeroes. Add support to setup write zeroes command. Set maximum possible write zeroes sectors in one write zeroes command according to nvme write zeroes command definition. Signed-off-by: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig --- 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 44f8a53..16a315d 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 BLK_MQ_RQ_QUEUE_OK; } +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) + blk_queue_max_write_zeroes_sectors(ns->queue, + ((u32)(USHRT_MAX + 1) * bs) >> 9); + blk_mq_unfreeze_queue(disk->queue); }