Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4225256yba; Wed, 17 Apr 2019 07:14:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2UquURSBBJeeLNPHXDqTXarDtxpQOor2zA9rn/W6mDCDoMI8DgdvMOqtAZf5fshwAo7Lw X-Received: by 2002:a17:902:2ba6:: with SMTP id l35mr34285972plb.56.1555510471992; Wed, 17 Apr 2019 07:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555510471; cv=none; d=google.com; s=arc-20160816; b=n0RHJPpAr8s3ppXgqCSv9gfXeV++jrcU06vBJIHVRd75+zg8822R4sMGyNz1zhBlEO nYM71ylIHtgMmxNrERICvmmbi4A8KQk6+psZTQB15oYaO3ICXvydgUCipCNKhXJQoVI0 NibYESct86uSV7a3/xaw3AlqEq4iC3wAqj5bbTOdTdgh6wXiRdmu6HSS8W8uBfjZAAGa 0djEMfyeYpvJtZKCXoUMeqwdFnONQWxU2OMMkLzg2PY1tleCjE0WcxdlL3fypvf2cNBs h9DYzLMxM04OvWSrIwkGbzbxMnlGjT7E1ZrpkL7DUNuSH2dcWUsRpFe/z+9gZtMMNEg2 SiqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from; bh=u2uqTMaSmvZhLBCdx8KMrSjI9/iD+uu8EIKjpXkvq3Q=; b=ySA5mE3GXCy2QKGnAH2MGFF1ialGHrxguCE2+DnMk8IHe5AJRJQO+f4NevDR8Vfcpf EZHD6TRQk35ZmQikQ0N4EByxPiSPQlnpgp4AXX1fZ9KqQC0an8A2/pxvedTET5u0Taaq sEa06lxqvqv3rPoE1lo5mHyu1nhRRp12MAN4yMCRLvw7HyRdPAvdEzks1XePb8Rw5ngs MEkWIf/u+AvI8PuCdDrwU6I//4IS4pTvzOdYlr+YNm5pV7JfL6jnua22W+EKQYAnt5HO ONGQQfmzRNqMnR3jysyJ35i2mDAIKBHXkwVZjfENQDsskcYjYrJ8Mn6uIJ8RAt+RRewy 1H+A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i96si32473787plb.331.2019.04.17.07.14.16; Wed, 17 Apr 2019 07:14:31 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732288AbfDQONI (ORCPT + 99 others); Wed, 17 Apr 2019 10:13:08 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:38593 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728335AbfDQONI (ORCPT ); Wed, 17 Apr 2019 10:13:08 -0400 Received: from [123.118.215.169] (helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1hGlJC-0004gI-JJ; Wed, 17 Apr 2019 14:13:07 +0000 From: Aaron Ma To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, keith.busch@intel.com, axboe@fb.com, aaron.ma@canonical.com Subject: [PATCH] nvme: determine the number of IO queues Date: Wed, 17 Apr 2019 22:12:59 +0800 Message-Id: <1555510379-20199-1-git-send-email-aaron.ma@canonical.com> X-Mailer: git-send-email 1.8.5.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); + status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES, + q_count, NULL, 0, &result); + if (status < 0) + return status; + else if (status == 0) { + nr_io_queues = min(result & 0xffff, result >> 16) + 1; + *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; -- 2.20.1