From nobody Mon Feb 9 09:16:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1597942981; cv=none; d=zohomail.com; s=zohoarc; b=Ouc3wBv9gzth9EbmgM5Z3iDK0wfShXXbJtW9i+S7kB3lLf9ZL87ooSbJUUmfpV/UApVIX8X8IkcKjYxTJXyKfVa3PhPVXcDa3O6r7VxY9a4vFUvDuWWp0TQ1v7Io26SKDEaNRD8GZfTuWFQMLnLMGk8WDbegoRZa9eHHSb62uXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597942981; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Dgozex87UGEBPqf+gR831D6Ko3iS5NgJedUVEUZWtuc=; b=Qc5NxoOjkwL2nR0J22jWoc8n2hF/NKQ5aN8ZA1PvKe+qk+4d13VD3O1UMC5K5NE6Ufgsx5mvFugWJtDLxl4c2LK5zXtumb3EodtYdl7xkpOMqh6TxTJ4ujjjg4LglcS+8lpLxjwNVGsG7fYo75SGBfgDFNBa0/xsMD536TltVeM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159794298159448.86790541217056; Thu, 20 Aug 2020 10:03:01 -0700 (PDT) Received: from localhost ([::1]:58168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8nxr-0008DS-E1 for importer@patchew.org; Thu, 20 Aug 2020 13:02:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8nuV-0003Hp-LV for qemu-devel@nongnu.org; Thu, 20 Aug 2020 12:59:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:51399) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k8nuT-0006Ct-Js for qemu-devel@nongnu.org; Thu, 20 Aug 2020 12:59:31 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-532-JJjDNG-iPOuvQ6oc9m02UQ-1; Thu, 20 Aug 2020 12:59:26 -0400 Received: by mail-wr1-f70.google.com with SMTP id z12so858723wrl.16 for ; Thu, 20 Aug 2020 09:59:26 -0700 (PDT) Received: from x1w.redhat.com (121.red-81-40-121.staticip.rima-tde.net. [81.40.121.121]) by smtp.gmail.com with ESMTPSA id x14sm4919186wmj.37.2020.08.20.09.59.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2020 09:59:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597942768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dgozex87UGEBPqf+gR831D6Ko3iS5NgJedUVEUZWtuc=; b=PMSw4xuv2ygqEYP+PUcPeSt95ElqwZElznpohnAmGmP6qwor130JZmdjt8RhZFbkf6wvWf yRlE0vx585RGobk1DZiWMQABQOUufOQY9buSsRdGsMfbMYIPhKNb2WR5jaJA+759GXrdrh vRAphPqypQ63xafEPYXPAplxEXnFzJQ= X-MC-Unique: JJjDNG-iPOuvQ6oc9m02UQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Dgozex87UGEBPqf+gR831D6Ko3iS5NgJedUVEUZWtuc=; b=rKyp0vQX1BzW9vyZM5Urii4SCLIoYVnPwEK/eNh7sVPBcd5t1ebtk5l+UwGzTMMlYG 4r641902IgDBg0gn3qWPZJs+II5gQCmeYQIIYbYnuOC9lpB63R24VOSrR0LmvQ/RolSe pCiBA7vOHJRgJoXmFDCQiC50dw/PKELj16Er9PtjoBdR6r3lJkuujeiEeDxFuaFEQjfa ws72X08lcpZk6SfI/DMgNKlOzAVqWbZlI7iDWIx4T6VxdcNPX3yQUIqOhFHDBrzSIwXs MHvh6bpv3SBN6L2QMGk4+pJtm9ZICoWieAODxX8rewucdGhihDtUIDZEkVCWS44NOJA8 VLgg== X-Gm-Message-State: AOAM533KoYTeLB3E696AK2F7uaKmBcEcPvLC3Z3K3HIPbS/Lwnt0YaQk c5K8/LfVUjderodWu8nFSCdSwAhOGr2W8z8bhi8nTfY7TnCuuIqC5uKLmZ6w1vKaShyZSoSjRTB UxxMtZo9wnSUWtJY= X-Received: by 2002:a05:600c:24cc:: with SMTP id 12mr2908466wmu.117.1597942765140; Thu, 20 Aug 2020 09:59:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaQSYqByxobBWSOTrsdyXm6YNy5kX0Ot1YHSPhgI08QKhZoy7GV/vtL/IGVCmYH1Bn/wZFyA== X-Received: by 2002:a05:600c:24cc:: with SMTP id 12mr2908445wmu.117.1597942764897; Thu, 20 Aug 2020 09:59:24 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 04/15] block/nvme: Define INDEX macros to ease code review Date: Thu, 20 Aug 2020 18:58:50 +0200 Message-Id: <20200820165901.1139109-5-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200820165901.1139109-1-philmd@redhat.com> References: <20200820165901.1139109-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/20 09:00:23 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Use definitions instead of '0' or '1' indexes. Also this will be useful when using multi-queues later. Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefano Garzarella --- block/nvme.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index e1893b4e792..003809fbd83 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -103,6 +103,9 @@ typedef volatile struct { =20 QEMU_BUILD_BUG_ON(offsetof(NVMeRegs, doorbells) !=3D 0x1000); =20 +#define INDEX_ADMIN 0 +#define INDEX_IO(n) (1 + n) + struct BDRVNVMeState { AioContext *aio_context; QEMUVFIOState *vfio; @@ -531,7 +534,7 @@ static void nvme_identify(BlockDriverState *bs, int nam= espace, Error **errp) } cmd.prp1 =3D cpu_to_le64(iova); =20 - if (nvme_cmd_sync(bs, s->queues[0], &cmd)) { + if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to identify controller"); goto out; } @@ -555,7 +558,7 @@ static void nvme_identify(BlockDriverState *bs, int nam= espace, Error **errp) =20 cmd.cdw10 =3D 0; cmd.nsid =3D cpu_to_le32(namespace); - if (nvme_cmd_sync(bs, s->queues[0], &cmd)) { + if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to identify namespace"); goto out; } @@ -644,7 +647,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Err= or **errp) .cdw10 =3D cpu_to_le32(((queue_size - 1) << 16) | (n & 0xFFFF)), .cdw11 =3D cpu_to_le32(0x3), }; - if (nvme_cmd_sync(bs, s->queues[0], &cmd)) { + if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to create io queue [%d]", n); nvme_free_queue_pair(q); return false; @@ -655,7 +658,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Err= or **errp) .cdw10 =3D cpu_to_le32(((queue_size - 1) << 16) | (n & 0xFFFF)), .cdw11 =3D cpu_to_le32(0x1 | (n << 16)), }; - if (nvme_cmd_sync(bs, s->queues[0], &cmd)) { + if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to create io queue [%d]", n); nvme_free_queue_pair(q); return false; @@ -739,16 +742,18 @@ static int nvme_init(BlockDriverState *bs, const char= *device, int namespace, =20 /* Set up admin queue. */ s->queues =3D g_new(NVMeQueuePair *, 1); - s->queues[0] =3D nvme_create_queue_pair(bs, 0, NVME_QUEUE_SIZE, errp); - if (!s->queues[0]) { + s->queues[INDEX_ADMIN] =3D nvme_create_queue_pair(bs, 0, + NVME_QUEUE_SIZE, + errp); + if (!s->queues[INDEX_ADMIN]) { ret =3D -EINVAL; goto out; } s->nr_queues =3D 1; QEMU_BUILD_BUG_ON(NVME_QUEUE_SIZE & 0xF000); s->regs->aqa =3D cpu_to_le32((NVME_QUEUE_SIZE << 16) | NVME_QUEUE_SIZE= ); - s->regs->asq =3D cpu_to_le64(s->queues[0]->sq.iova); - s->regs->acq =3D cpu_to_le64(s->queues[0]->cq.iova); + s->regs->asq =3D cpu_to_le64(s->queues[INDEX_ADMIN]->sq.iova); + s->regs->acq =3D cpu_to_le64(s->queues[INDEX_ADMIN]->cq.iova); =20 /* After setting up all control registers we can enable device now. */ s->regs->cc =3D cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES) << 20) | @@ -839,7 +844,7 @@ static int nvme_enable_disable_write_cache(BlockDriverS= tate *bs, bool enable, .cdw11 =3D cpu_to_le32(enable ? 0x01 : 0x00), }; =20 - ret =3D nvme_cmd_sync(bs, s->queues[0], &cmd); + ret =3D nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd); if (ret) { error_setg(errp, "Failed to configure NVMe write cache"); } @@ -1056,7 +1061,7 @@ static coroutine_fn int nvme_co_prw_aligned(BlockDriv= erState *bs, { int r; BDRVNVMeState *s =3D bs->opaque; - NVMeQueuePair *ioq =3D s->queues[1]; + NVMeQueuePair *ioq =3D s->queues[INDEX_IO(0)]; NVMeRequest *req; =20 uint32_t cdw12 =3D (((bytes >> s->blkshift) - 1) & 0xFFFF) | @@ -1171,7 +1176,7 @@ static coroutine_fn int nvme_co_pwritev(BlockDriverSt= ate *bs, static coroutine_fn int nvme_co_flush(BlockDriverState *bs) { BDRVNVMeState *s =3D bs->opaque; - NVMeQueuePair *ioq =3D s->queues[1]; + NVMeQueuePair *ioq =3D s->queues[INDEX_IO(0)]; NVMeRequest *req; NvmeCmd cmd =3D { .opcode =3D NVME_CMD_FLUSH, @@ -1202,7 +1207,7 @@ static coroutine_fn int nvme_co_pwrite_zeroes(BlockDr= iverState *bs, BdrvRequestFlags flags) { BDRVNVMeState *s =3D bs->opaque; - NVMeQueuePair *ioq =3D s->queues[1]; + NVMeQueuePair *ioq =3D s->queues[INDEX_IO(0)]; NVMeRequest *req; =20 uint32_t cdw12 =3D ((bytes >> s->blkshift) - 1) & 0xFFFF; @@ -1255,7 +1260,7 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverS= tate *bs, int bytes) { BDRVNVMeState *s =3D bs->opaque; - NVMeQueuePair *ioq =3D s->queues[1]; + NVMeQueuePair *ioq =3D s->queues[INDEX_IO(0)]; NVMeRequest *req; NvmeDsmRange *buf; QEMUIOVector local_qiov; @@ -1398,7 +1403,7 @@ static void nvme_aio_unplug(BlockDriverState *bs) BDRVNVMeState *s =3D bs->opaque; assert(s->plugged); s->plugged =3D false; - for (i =3D 1; i < s->nr_queues; i++) { + for (i =3D INDEX_IO(0); i < s->nr_queues; i++) { NVMeQueuePair *q =3D s->queues[i]; qemu_mutex_lock(&q->lock); nvme_kick(q); --=20 2.26.2