Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4572600yba; Wed, 17 Apr 2019 14:32:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEftVdr0TOw+qBB5FKxPJeBmhz/kIKgyTR7G0HhehSkRViYwx7knOh6VyzAJYuWAy8TrJk X-Received: by 2002:a62:524e:: with SMTP id g75mr90242500pfb.106.1555536766330; Wed, 17 Apr 2019 14:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555536766; cv=none; d=google.com; s=arc-20160816; b=KG8uq2f8ajN/ewMN7UZnA+ZSDgZ7jKZwlcjewwvxR+kNxJGhXZij1YfNFGH9rhlp60 NydNqBO1s+vTskGhUHGbEOTTZI5EtOF3gWBKlY4y+9utWN/XPolgGfy81WTbl6HN7lZB U3O/wDtyMZAe6HwzK9wnLc1oiwLnwT5RajBxtMGgDVy6KjY+4x95Di4AqoBIqaTFgC5b IUN10TtJSONQKYOkE/fmF19E0HFiNRaEJLgQ9pN97RMezUFt3g36SNTUXK00149n52cv CEAElb2Dg5VU8HCNF5FEIfPGFcDkOq1tKOnTghSNwr90D5kiqk9W90wIOI4Tv2Zp6VxQ X44Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=UDomdzyZTZup4EOGSaPJuyg3NDPnNWzjsCTMNgGlulE=; b=uiMAWWUK4/EsphCQ34nRGVYp2U95lrV2REpTooaY2M3Ib9nVGfo1y1mjTlMIflZp7X UyDAiUTzY4YYCVyFt6EIYCOXobOZed7dpgbCTtcodCCXtM9jFQzoTgpo/Y601PKAXgXd /u9edOi7d5AP5ZiIQlLP0LRiS2Na6PPQpIKW2w4Uz34zetbkLytb8U5HeBcWcN+v6GDF zUtDqHmuJGYHth5kbAF+O0AKCr+n7RGjWEegD8DybqEYpZjNnyK8dQ8FlRV+XbU6SVj9 6dETPOEw4fjxsCA22K3eatetSjg/GOy6S0x5AWamy+4HJLM3P4Ax7ibiOvkGui555zay 2VPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iLnYDhLA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b3si50245697pgq.325.2019.04.17.14.32.30; Wed, 17 Apr 2019 14:32:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iLnYDhLA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730456AbfDQVaV (ORCPT + 99 others); Wed, 17 Apr 2019 17:30:21 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:35957 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725848AbfDQVaU (ORCPT ); Wed, 17 Apr 2019 17:30:20 -0400 Received: by mail-pl1-f193.google.com with SMTP id ck15so104931plb.3 for ; Wed, 17 Apr 2019 14:30:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=UDomdzyZTZup4EOGSaPJuyg3NDPnNWzjsCTMNgGlulE=; b=iLnYDhLALoEyptEO7vYKL20g+IWsawH5T6vdUOmHRogsjMhrAxf61lawdw1zSg4dbF lzxBstRir++GMuFR9y7sZS1so1Nce8McQGuxAdAA7lG39E9ReUa3mEy1holMa/0S/uAT 0CKoexNPevXP+UAh9KUzspFOGPM1vlwtoHsg+jtFN3892/sJvB0+2w3pEh+xFN6kGZgf YG0Ln4UtnEsoEOFXdtLUYIDDZcmkAJOrhOfizeYwKicg6dx0m9yvFI+cbAgFE1EB58WE GOWbV8CYqethwQzOBss5L648FVoXPCgkfs3cWxIsZdhHqMryaYH7xExn4/EGDM53nzku 60eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=UDomdzyZTZup4EOGSaPJuyg3NDPnNWzjsCTMNgGlulE=; b=Sjpr8m27FOQAnjgjbsthEzmdnFl2LNeksisroE4zb/DF5qsBJqeCBaqdh/NOMShPSF gLF5T28D3CupubfZjuAJVymFil3ms9u3mWp+v4XSM9/zzHYZzIfIKV4GJZrP3C+jm0jS t0MC6qkb8mxO92NNsk236GAtIGj4c3I9u5UcVApqiHYulCZxMi2B/iWbPDMDxEquF9LJ yKaXRxPDWQC7VwRhWnaYS+PK1cOLBUdPJSS0XIfKxv6mc/LSjpzRQAfNsUje/sWrj0NG LC4+ABaFoQf/ytxJKk86GQ5oHT1gdI0DRhX3PKoDSAkHVLAcdkwxxwLHcgmqhsZHXygi eShg== X-Gm-Message-State: APjAAAWxZ7QcRpXyup9sqGWcrrJKCvZkCG5KpSi5aI2pOPRsVgkeFmCe 0LHP7q/vKyEsta4owHKQR5A= X-Received: by 2002:a17:902:7893:: with SMTP id q19mr90885686pll.154.1555536620417; Wed, 17 Apr 2019 14:30:20 -0700 (PDT) Received: from localhost.localdomain ([2001:4898:80e8:2:4415:95ba:6d7:2a33]) by smtp.gmail.com with ESMTPSA id v20sm149151pfe.118.2019.04.17.14.30.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 14:30:19 -0700 (PDT) Subject: Re: [PATCH] nvme: determine the number of IO queues To: Aaron Ma , linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, keith.busch@intel.com, axboe@fb.com References: <1555510379-20199-1-git-send-email-aaron.ma@canonical.com> From: "Edmund Nadolski (Microsoft)" Message-ID: <08ac5733-596b-598d-c821-f1aa2dc32650@gmail.com> Date: Wed, 17 Apr 2019 14:30:18 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <1555510379-20199-1-git-send-email-aaron.ma@canonical.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/17/19 7:12 AM, Aaron Ma wrote: > Some controllers support limited IO queues, when over set > the number, it will return invalid field error. > Then NVME will be removed by driver. > > Find the max number of IO queues that controller supports. > When it still got invalid result, set 1 IO queue at least to > bring NVME online. > > Signed-off-by: Aaron Ma > --- > drivers/nvme/host/core.c | 29 ++++++++++++++++++----------- > 1 file changed, 18 insertions(+), 11 deletions(-) > > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c > index 2c43e12b70af..fb7f05c310c8 100644 > --- a/drivers/nvme/host/core.c > +++ b/drivers/nvme/host/core.c > @@ -1134,14 +1134,24 @@ static int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dword > > int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count) > { > - u32 q_count = (*count - 1) | ((*count - 1) << 16); > + u32 q_count; > u32 result; > - int status, nr_io_queues; > - > - status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES, q_count, NULL, 0, > - &result); > - if (status < 0) > - return status; > + int status = -1; > + int nr_io_queues; > + int try_count; > + > + for (try_count = *count; try_count > 0; try_count--) { > + q_count = (try_count - 1) | ((try_count - 1) << 16); A macro here might help readability. > + status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES, > + q_count, NULL, 0, &result); > + if (status < 0) > + return status; > + else if (status == 0) { else following return is not needed. > + nr_io_queues = min(result & 0xffff, result >> 16) + 1; Likewise, a macro as above. Ed > + *count = min(try_count, nr_io_queues); > + break; > + } > + } > > /* > * Degraded controllers might return an error when setting the queue > @@ -1150,10 +1160,7 @@ int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count) > */ > if (status > 0) { > dev_err(ctrl->device, "Could not set queue count (%d)\n", status); > - *count = 0; > - } else { > - nr_io_queues = min(result & 0xffff, result >> 16) + 1; > - *count = min(*count, nr_io_queues); > + *count = 1; > } > > return 0; >