hw/block/nvme: open code for volatile write cache

Volatile Write Cache(VWC) feature is set in nvme_ns_setup() in the
initial time.  This feature is related to block device backed,  but this
feature is controlled in controller level via Set/Get Features command.

This patch removed dependency between nvme and nvme-ns to manage the VWC
flag value.  Also, it open coded the Get Features for VWC to check all
namespaces attached to the controller, and if false detected, return
directly false.

Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
[k.jensen: report write cache preset if present on ANY namespace]
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
This commit is contained in:
Minwoo Im 2021-01-17 23:53:32 +09:00 committed by Klaus Jensen
parent 1490be5a8a
commit aa5e55e3b0
3 changed files with 12 additions and 8 deletions

View File

@ -90,10 +90,6 @@ static int nvme_ns_init_blk(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)
return -1; return -1;
} }
if (blk_enable_write_cache(ns->blkconf.blk)) {
n->features.vwc = 0x1;
}
return 0; return 0;
} }

View File

@ -3097,6 +3097,7 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req)
NvmeGetFeatureSelect sel = NVME_GETFEAT_SELECT(dw10); NvmeGetFeatureSelect sel = NVME_GETFEAT_SELECT(dw10);
uint16_t iv; uint16_t iv;
NvmeNamespace *ns; NvmeNamespace *ns;
int i;
static const uint32_t nvme_feature_default[NVME_FID_MAX] = { static const uint32_t nvme_feature_default[NVME_FID_MAX] = {
[NVME_ARBITRATION] = NVME_ARB_AB_NOLIMIT, [NVME_ARBITRATION] = NVME_ARB_AB_NOLIMIT,
@ -3172,7 +3173,17 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req)
result = ns->features.err_rec; result = ns->features.err_rec;
goto out; goto out;
case NVME_VOLATILE_WRITE_CACHE: case NVME_VOLATILE_WRITE_CACHE:
result = n->features.vwc; for (i = 1; i <= n->num_namespaces; i++) {
ns = nvme_ns(n, i);
if (!ns) {
continue;
}
result = blk_enable_write_cache(ns->blkconf.blk);
if (result) {
break;
}
}
trace_pci_nvme_getfeat_vwcache(result ? "enabled" : "disabled"); trace_pci_nvme_getfeat_vwcache(result ? "enabled" : "disabled");
goto out; goto out;
case NVME_ASYNCHRONOUS_EVENT_CONF: case NVME_ASYNCHRONOUS_EVENT_CONF:
@ -3335,8 +3346,6 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeRequest *req)
ns->features.err_rec = dw11; ns->features.err_rec = dw11;
break; break;
case NVME_VOLATILE_WRITE_CACHE: case NVME_VOLATILE_WRITE_CACHE:
n->features.vwc = dw11 & 0x1;
for (i = 1; i <= n->num_namespaces; i++) { for (i = 1; i <= n->num_namespaces; i++) {
ns = nvme_ns(n, i); ns = nvme_ns(n, i);
if (!ns) { if (!ns) {

View File

@ -121,7 +121,6 @@ typedef struct NvmeFeatureVal {
uint16_t temp_thresh_low; uint16_t temp_thresh_low;
}; };
uint32_t async_config; uint32_t async_config;
uint32_t vwc;
} NvmeFeatureVal; } NvmeFeatureVal;
typedef struct NvmeCtrl { typedef struct NvmeCtrl {