[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH V3 8/8] hw/block/nvme: Add Identify Active Namespace ID List
From: |
Minwoo Im |
Subject: |
[RFC PATCH V3 8/8] hw/block/nvme: Add Identify Active Namespace ID List |
Date: |
Wed, 20 Jan 2021 02:01:47 +0900 |
Spec v1.4b 6.1.4 "Active and Inactive NSID Types" says:
"Active NSIDs for a controller refer to namespaces that are attached to
that controller. Allocated NSIDs that are inactive for a controller refer
to namespaces that are not attached to that controller."
This patch introduced for Identify Active Namespace ID List (CNS 02h).
Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
---
hw/block/nvme.c | 39 ++++++++++++++++++++++++++++++++++-----
1 file changed, 34 insertions(+), 5 deletions(-)
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 2b2c07b36c2b..7247167b0ee6 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -2883,6 +2883,39 @@ static uint16_t nvme_identify_ns_csi(NvmeCtrl *n,
NvmeRequest *req)
return NVME_INVALID_FIELD | NVME_DNR;
}
+static uint16_t nvme_identify_nslist_active(NvmeCtrl *n, NvmeRequest *req)
+{
+ NvmeNamespace *ns;
+ NvmeIdentify *c = (NvmeIdentify *)&req->cmd;
+ uint32_t min_nsid = le32_to_cpu(c->nsid);
+ uint8_t list[NVME_IDENTIFY_DATA_SIZE] = {};
+ static const int data_len = sizeof(list);
+ uint32_t *list_ptr = (uint32_t *)list;
+ int i, j = 0;
+
+ if (min_nsid >= NVME_NSID_BROADCAST - 1) {
+ return NVME_INVALID_NSID | NVME_DNR;
+ }
+
+ for (i = 1; i <= n->num_namespaces; i++) {
+ ns = nvme_ns(n, i);
+ if (!ns || ns->params.nsid <= min_nsid) {
+ continue;
+ }
+
+ if (!nvme_ns_is_attached(n, ns)) {
+ continue;
+ }
+
+ list_ptr[j++] = cpu_to_le32(ns->params.nsid);
+ if (j == data_len / sizeof(uint32_t)) {
+ break;
+ }
+ }
+
+ return nvme_dma(n, list, data_len, DMA_DIRECTION_FROM_DEVICE, req);
+}
+
static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeRequest *req)
{
NvmeNamespace *ns;
@@ -2914,10 +2947,6 @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n,
NvmeRequest *req)
continue;
}
- if (!nvme_ns_is_attached(n, ns)) {
- continue;
- }
-
list_ptr[j++] = cpu_to_le32(ns->params.nsid);
if (j == data_len / sizeof(uint32_t)) {
break;
@@ -3045,7 +3074,7 @@ static uint16_t nvme_identify(NvmeCtrl *n, NvmeRequest
*req)
case NVME_ID_CNS_CS_CTRL:
return nvme_identify_ctrl_csi(n, req);
case NVME_ID_CNS_NS_ACTIVE_LIST:
- /* fall through */
+ return nvme_identify_nslist_active(n, req);
case NVME_ID_CNS_NS_PRESENT_LIST:
return nvme_identify_nslist(n, req);
case NVME_ID_CNS_CS_NS_ACTIVE_LIST:
--
2.17.1
- [RFC PATCH V3 0/8] hw/block/nvme: support multi-path for ctrl/ns, Minwoo Im, 2021/01/19
- [RFC PATCH V3 1/8] hw/block/nvme: introduce nvme-subsys device, Minwoo Im, 2021/01/19
- [RFC PATCH V3 2/8] hw/block/nvme: support to map controller to a subsystem, Minwoo Im, 2021/01/19
- [RFC PATCH V3 3/8] hw/block/nvme: add CMIC enum value for Identify Controller, Minwoo Im, 2021/01/19
- [RFC PATCH V3 4/8] hw/block/nvme: support for multi-controller in subsystem, Minwoo Im, 2021/01/19
- [RFC PATCH V3 5/8] hw/block/nvme: add NMIC enum value for Identify Namespace, Minwoo Im, 2021/01/19
- [RFC PATCH V3 7/8] hw/block/nvme: add 'detached' param not to attach namespace, Minwoo Im, 2021/01/19
- [RFC PATCH V3 6/8] hw/block/nvme: support for shared namespace in subsystem, Minwoo Im, 2021/01/19
- [RFC PATCH V3 8/8] hw/block/nvme: Add Identify Active Namespace ID List,
Minwoo Im <=
- Re: [RFC PATCH V3 0/8] hw/block/nvme: support multi-path for ctrl/ns, Klaus Jensen, 2021/01/19