diff --git a/examples/nvme/arbitration/arbitration.c b/examples/nvme/arbitration/arbitration.c index dcddb56de1..e31539f52f 100644 --- a/examples/nvme/arbitration/arbitration.c +++ b/examples/nvme/arbitration/arbitration.c @@ -1063,8 +1063,6 @@ set_arb_feature(struct spdk_nvme_ctrlr *ctrlr) { int ret; struct spdk_nvme_cmd cmd = {}; - uint32_t arb = 0; - unsigned ab, lpw, mpw, hpw; cmd.opc = SPDK_NVME_OPC_SET_FEATURES; cmd.cdw10_bits.set_features.fid = SPDK_NVME_FEAT_ARBITRATION; @@ -1072,12 +1070,10 @@ set_arb_feature(struct spdk_nvme_ctrlr *ctrlr) g_arbitration.outstanding_commands = 0; if (features[SPDK_NVME_FEAT_ARBITRATION].valid) { - ab = USER_SPECIFIED_ARBITRATION_BURST & SPDK_NVME_ARB_BURST_MASK; - hpw = USER_SPECIFIED_HIGH_PRIORITY_WEIGHT << SPDK_NVME_HIGH_PRIO_WEIGHT_SHIFT; - mpw = USER_SPECIFIED_MEDIUM_PRIORITY_WEIGHT << SPDK_NVME_MED_PRIO_WEIGHT_SHIFT; - lpw = USER_SPECIFIED_LOW_PRIORITY_WEIGHT << SPDK_NVME_LOW_PRIO_WEIGHT_SHIFT; - arb = hpw | mpw | lpw | ab; - cmd.cdw11 = arb; + cmd.cdw11_bits.feat_arbitration.bits.ab = USER_SPECIFIED_ARBITRATION_BURST; + cmd.cdw11_bits.feat_arbitration.bits.lpw = USER_SPECIFIED_LOW_PRIORITY_WEIGHT; + cmd.cdw11_bits.feat_arbitration.bits.mpw = USER_SPECIFIED_MEDIUM_PRIORITY_WEIGHT; + cmd.cdw11_bits.feat_arbitration.bits.hpw = USER_SPECIFIED_HIGH_PRIORITY_WEIGHT; } ret = spdk_nvme_ctrlr_cmd_admin_raw(ctrlr, &cmd, NULL, 0, diff --git a/include/spdk/nvme_spec.h b/include/spdk/nvme_spec.h index 3cbf7af3cc..fd237a6afb 100644 --- a/include/spdk/nvme_spec.h +++ b/include/spdk/nvme_spec.h @@ -1013,8 +1013,12 @@ struct spdk_nvme_cmd { uint32_t cdw10; union spdk_nvme_cmd_cdw10 cdw10_bits; }; - /* dword 11-15 */ - uint32_t cdw11; /* command-specific */ + /* command-specific */ + union { + uint32_t cdw11; + union spdk_nvme_cmd_cdw11 cdw11_bits; + }; + /* dword 12-15 */ uint32_t cdw12; /* command-specific */ uint32_t cdw13; /* command-specific */ uint32_t cdw14; /* command-specific */ diff --git a/lib/nvme/nvme_ctrlr_cmd.c b/lib/nvme/nvme_ctrlr_cmd.c index 33a9e3e289..e425b97735 100644 --- a/lib/nvme/nvme_ctrlr_cmd.c +++ b/lib/nvme/nvme_ctrlr_cmd.c @@ -430,10 +430,14 @@ int nvme_ctrlr_cmd_set_num_queues(struct spdk_nvme_ctrlr *ctrlr, uint32_t num_queues, spdk_nvme_cmd_cb cb_fn, void *cb_arg) { - uint32_t cdw11; + union spdk_nvme_feat_number_of_queues feat_num_queues; - cdw11 = ((num_queues - 1) << 16) | (num_queues - 1); - return spdk_nvme_ctrlr_cmd_set_feature(ctrlr, SPDK_NVME_FEAT_NUMBER_OF_QUEUES, cdw11, 0, + feat_num_queues.raw = 0; + feat_num_queues.bits.nsqr = num_queues - 1; + feat_num_queues.bits.ncqr = num_queues - 1; + + return spdk_nvme_ctrlr_cmd_set_feature(ctrlr, SPDK_NVME_FEAT_NUMBER_OF_QUEUES, feat_num_queues.raw, + 0, NULL, 0, cb_fn, cb_arg); } @@ -462,20 +466,22 @@ int nvme_ctrlr_cmd_set_host_id(struct spdk_nvme_ctrlr *ctrlr, void *host_id, uint32_t host_id_size, spdk_nvme_cmd_cb cb_fn, void *cb_arg) { - uint32_t cdw11; + union spdk_nvme_feat_host_identifier feat_host_identifier; + feat_host_identifier.raw = 0; if (host_id_size == 16) { /* 128-bit extended host identifier */ - cdw11 = 1; + feat_host_identifier.bits.exhid = 1; } else if (host_id_size == 8) { /* 64-bit host identifier */ - cdw11 = 0; + feat_host_identifier.bits.exhid = 0; } else { SPDK_ERRLOG("Invalid host ID size %u\n", host_id_size); return -EINVAL; } - return spdk_nvme_ctrlr_cmd_set_feature(ctrlr, SPDK_NVME_FEAT_HOST_IDENTIFIER, cdw11, 0, + return spdk_nvme_ctrlr_cmd_set_feature(ctrlr, SPDK_NVME_FEAT_HOST_IDENTIFIER, + feat_host_identifier.raw, 0, host_id, host_id_size, cb_fn, cb_arg); } @@ -525,7 +531,7 @@ spdk_nvme_ctrlr_cmd_get_log_page(struct spdk_nvme_ctrlr *ctrlr, uint8_t log_page cmd->cdw10_bits.get_log_page.numdl = numdl; cmd->cdw10_bits.get_log_page.lid = log_page; - cmd->cdw11 = numdu; + cmd->cdw11_bits.get_log_page.numdu = numdu; cmd->cdw12 = lpol; cmd->cdw13 = lpou; diff --git a/lib/nvme/nvme_pcie.c b/lib/nvme/nvme_pcie.c index 28fdd9eac9..cf4aa2b2c3 100644 --- a/lib/nvme/nvme_pcie.c +++ b/lib/nvme/nvme_pcie.c @@ -1473,11 +1473,7 @@ nvme_pcie_ctrlr_cmd_create_io_cq(struct spdk_nvme_ctrlr *ctrlr, cmd->cdw10_bits.create_io_q.qid = io_que->id; cmd->cdw10_bits.create_io_q.qsize = pqpair->num_entries - 1; - /* - * 0x2 = interrupts enabled - * 0x1 = physically contiguous - */ - cmd->cdw11 = 0x1; + cmd->cdw11_bits.create_io_cq.pc = 1; cmd->dptr.prp.prp1 = pqpair->cpl_bus_addr; return nvme_ctrlr_submit_admin_request(ctrlr, req); @@ -1501,8 +1497,9 @@ nvme_pcie_ctrlr_cmd_create_io_sq(struct spdk_nvme_ctrlr *ctrlr, cmd->cdw10_bits.create_io_q.qid = io_que->id; cmd->cdw10_bits.create_io_q.qsize = pqpair->num_entries - 1; - /* 0x1 = physically contiguous */ - cmd->cdw11 = (io_que->id << 16) | (io_que->qprio << 1) | 0x1; + cmd->cdw11_bits.create_io_sq.pc = 1; + cmd->cdw11_bits.create_io_sq.qprio = io_que->qprio; + cmd->cdw11_bits.create_io_sq.cqid = io_que->id; cmd->dptr.prp.prp1 = pqpair->cmd_bus_addr; return nvme_ctrlr_submit_admin_request(ctrlr, req); diff --git a/lib/nvmf/ctrlr.c b/lib/nvmf/ctrlr.c index 5581832da0..5b74e93b21 100644 --- a/lib/nvmf/ctrlr.c +++ b/lib/nvmf/ctrlr.c @@ -861,17 +861,15 @@ spdk_nvmf_ctrlr_set_features_arbitration(struct spdk_nvmf_request *req) static int spdk_nvmf_ctrlr_set_features_power_management(struct spdk_nvmf_request *req) { - union spdk_nvme_feat_power_management opts; struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr; struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd; struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl; SPDK_DEBUGLOG(SPDK_LOG_NVMF, "Set Features - Power Management (cdw11 = 0x%0x)\n", cmd->cdw11); - opts.raw = cmd->cdw11; /* Only PS = 0 is allowed, since we report NPSS = 0 */ - if (opts.bits.ps != 0) { - SPDK_ERRLOG("Invalid power state %u\n", opts.bits.ps); + if (cmd->cdw11_bits.feat_power_management.bits.ps != 0) { + SPDK_ERRLOG("Invalid power state %u\n", cmd->cdw11_bits.feat_power_management.bits.ps); rsp->status.sct = SPDK_NVME_SCT_GENERIC; rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD; return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; @@ -914,14 +912,12 @@ temp_threshold_opts_valid(const union spdk_nvme_feat_temperature_threshold *opts static int spdk_nvmf_ctrlr_set_features_temperature_threshold(struct spdk_nvmf_request *req) { - union spdk_nvme_feat_temperature_threshold opts; struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd; struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl; SPDK_DEBUGLOG(SPDK_LOG_NVMF, "Set Features - Temperature Threshold (cdw11 = 0x%0x)\n", cmd->cdw11); - opts.raw = cmd->cdw11; - if (!temp_threshold_opts_valid(&opts)) { + if (!temp_threshold_opts_valid(&cmd->cdw11_bits.feat_temp_threshold)) { rsp->status.sct = SPDK_NVME_SCT_GENERIC; rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD; return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; @@ -934,14 +930,12 @@ spdk_nvmf_ctrlr_set_features_temperature_threshold(struct spdk_nvmf_request *req static int spdk_nvmf_ctrlr_get_features_temperature_threshold(struct spdk_nvmf_request *req) { - union spdk_nvme_feat_temperature_threshold opts; struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd; struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl; SPDK_DEBUGLOG(SPDK_LOG_NVMF, "Get Features - Temperature Threshold (cdw11 = 0x%0x)\n", cmd->cdw11); - opts.raw = cmd->cdw11; - if (!temp_threshold_opts_valid(&opts)) { + if (!temp_threshold_opts_valid(&cmd->cdw11_bits.feat_temp_threshold)) { rsp->status.sct = SPDK_NVME_SCT_GENERIC; rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD; return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; @@ -956,15 +950,13 @@ spdk_nvmf_ctrlr_get_features_temperature_threshold(struct spdk_nvmf_request *req static int spdk_nvmf_ctrlr_set_features_error_recovery(struct spdk_nvmf_request *req) { - union spdk_nvme_feat_error_recovery opts; struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr; struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd; struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl; SPDK_DEBUGLOG(SPDK_LOG_NVMF, "Set Features - Error Recovery (cdw11 = 0x%0x)\n", cmd->cdw11); - opts.raw = cmd->cdw11; - if (opts.bits.dulbe) { + if (cmd->cdw11_bits.feat_error_recovery.bits.dulbe) { /* * Host is not allowed to set this bit, since we don't advertise it in * Identify Namespace. @@ -1027,12 +1019,10 @@ spdk_nvmf_ctrlr_get_features_host_identifier(struct spdk_nvmf_request *req) struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr; struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd; struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl; - union spdk_nvme_feat_host_identifier opts; SPDK_DEBUGLOG(SPDK_LOG_NVMF, "Get Features - Host Identifier\n"); - opts.raw = cmd->cdw11; - if (!opts.bits.exhid) { + if (!cmd->cdw11_bits.feat_host_identifier.bits.exhid) { /* NVMe over Fabrics requires EXHID=1 (128-bit/16-byte host ID) */ SPDK_ERRLOG("Get Features - Host Identifier with EXHID=0 not allowed\n"); response->status.sc = SPDK_NVME_SC_INVALID_FIELD; @@ -1144,7 +1134,7 @@ spdk_nvmf_ctrlr_set_features_reservation_persistence(struct spdk_nvmf_request *r SPDK_DEBUGLOG(SPDK_LOG_NVMF, "Set Features - Reservation Persistence\n"); ns = _spdk_nvmf_subsystem_get_ns(ctrlr->subsys, cmd->nsid); - ptpl = cmd->cdw11 & 0x1u; + ptpl = cmd->cdw11_bits.feat_rsv_persistence.bits.ptpl; if (cmd->nsid != 0xffffffffu && ns && ns->ptpl_file) { ns->ptpl_activated = ptpl; @@ -1179,14 +1169,15 @@ spdk_nvmf_ctrlr_set_features_keep_alive_timer(struct spdk_nvmf_request *req) * if attempts to disable keep alive by setting kato to 0h * a status value of keep alive invalid shall be returned */ - if (cmd->cdw11 == 0) { + if (cmd->cdw11_bits.feat_keep_alive_timer.bits.kato == 0) { rsp->status.sc = SPDK_NVME_SC_KEEP_ALIVE_INVALID; - } else if (cmd->cdw11 < MIN_KEEP_ALIVE_TIMEOUT_IN_MS) { + } else if (cmd->cdw11_bits.feat_keep_alive_timer.bits.kato < MIN_KEEP_ALIVE_TIMEOUT_IN_MS) { ctrlr->feat.keep_alive_timer.bits.kato = MIN_KEEP_ALIVE_TIMEOUT_IN_MS; } else { /* round up to milliseconds */ - ctrlr->feat.keep_alive_timer.bits.kato = spdk_divide_round_up(cmd->cdw11, - KAS_DEFAULT_VALUE * KAS_TIME_UNIT_IN_MS) * + ctrlr->feat.keep_alive_timer.bits.kato = spdk_divide_round_up( + cmd->cdw11_bits.feat_keep_alive_timer.bits.kato, + KAS_DEFAULT_VALUE * KAS_TIME_UNIT_IN_MS) * KAS_DEFAULT_VALUE * KAS_TIME_UNIT_IN_MS; } @@ -1194,7 +1185,7 @@ spdk_nvmf_ctrlr_set_features_keep_alive_timer(struct spdk_nvmf_request *req) * if change the keep alive timeout value successfully * update the keep alive poller. */ - if (cmd->cdw11 != 0) { + if (cmd->cdw11_bits.feat_keep_alive_timer.bits.kato != 0) { if (ctrlr->keep_alive_poller != NULL) { spdk_poller_unregister(&ctrlr->keep_alive_poller); } @@ -1472,7 +1463,7 @@ spdk_nvmf_ctrlr_get_log_page(struct spdk_nvmf_request *req) } numdl = cmd->cdw10_bits.get_log_page.numdl; - numdu = (cmd->cdw11) & 0xFFFFu; + numdu = cmd->cdw11_bits.get_log_page.numdu; len = ((numdu << 16) + numdl + (uint64_t)1) * 4; if (len > req->length) { SPDK_ERRLOG("Get log page: len (%" PRIu64 ") > buf size (%u)\n", diff --git a/lib/nvmf/ctrlr_bdev.c b/lib/nvmf/ctrlr_bdev.c index 7d8ae0fed0..327db16669 100644 --- a/lib/nvmf/ctrlr_bdev.c +++ b/lib/nvmf/ctrlr_bdev.c @@ -498,12 +498,10 @@ int spdk_nvmf_bdev_ctrlr_dsm_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, struct spdk_nvmf_request *req) { - uint32_t attribute; struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd; struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl; - attribute = cmd->cdw11 & 0x00000007; - if (attribute & SPDK_NVME_DSM_ATTR_DEALLOCATE) { + if (cmd->cdw11_bits.dsm.ad) { return nvmf_bdev_ctrlr_unmap(bdev, desc, ch, req, NULL); } diff --git a/lib/nvmf/subsystem.c b/lib/nvmf/subsystem.c index ffec55f5c9..a47d792857 100644 --- a/lib/nvmf/subsystem.c +++ b/lib/nvmf/subsystem.c @@ -2337,8 +2337,7 @@ nvmf_ns_reservation_report(struct spdk_nvmf_ns *ns, goto exit; } - /* NVMeoF uses Extended Data Structure */ - if ((cmd->cdw11 & 0x00000001u) == 0) { + if (!cmd->cdw11_bits.resv_report.eds) { SPDK_ERRLOG("NVMeoF uses extended controller data structure, " "please set EDS bit in cdw11 and try again\n"); status = SPDK_NVME_SC_HOSTID_INCONSISTENT_FORMAT; diff --git a/test/nvme/aer/aer.c b/test/nvme/aer/aer.c index 946ee9eae1..22171bb707 100644 --- a/test/nvme/aer/aer.c +++ b/test/nvme/aer/aer.c @@ -96,7 +96,7 @@ set_temp_threshold(struct dev *dev, uint32_t temp) cmd.opc = SPDK_NVME_OPC_SET_FEATURES; cmd.cdw10_bits.set_features.fid = SPDK_NVME_FEAT_TEMPERATURE_THRESHOLD; - cmd.cdw11 = temp; + cmd.cdw11_bits.feat_temp_threshold.bits.tmpth = temp; rc = spdk_nvme_ctrlr_cmd_admin_raw(dev->ctrlr, &cmd, NULL, 0, set_temp_completion, dev); if (rc == 0) { diff --git a/test/unit/lib/nvme/nvme_ns_cmd.c/nvme_ns_cmd_ut.c b/test/unit/lib/nvme/nvme_ns_cmd.c/nvme_ns_cmd_ut.c index 93e6ee6e9e..c5ba02c829 100644 --- a/test/unit/lib/nvme/nvme_ns_cmd.c/nvme_ns_cmd_ut.c +++ b/test/unit/lib/nvme/nvme_ns_cmd.c/nvme_ns_cmd_ut.c @@ -619,7 +619,7 @@ test_nvme_ns_cmd_dataset_management(void) CU_ASSERT(g_request->cmd.opc == SPDK_NVME_OPC_DATASET_MANAGEMENT); CU_ASSERT(g_request->cmd.nsid == ns.id); CU_ASSERT(g_request->cmd.cdw10 == 0); - CU_ASSERT(g_request->cmd.cdw11 == SPDK_NVME_DSM_ATTR_DEALLOCATE); + CU_ASSERT(g_request->cmd.cdw11_bits.dsm.ad == 1); spdk_free(g_request->payload.contig_or_cb_arg); nvme_free_request(g_request); @@ -631,7 +631,7 @@ test_nvme_ns_cmd_dataset_management(void) CU_ASSERT(g_request->cmd.opc == SPDK_NVME_OPC_DATASET_MANAGEMENT); CU_ASSERT(g_request->cmd.nsid == ns.id); CU_ASSERT(g_request->cmd.cdw10 == 255u); - CU_ASSERT(g_request->cmd.cdw11 == SPDK_NVME_DSM_ATTR_DEALLOCATE); + CU_ASSERT(g_request->cmd.cdw11_bits.dsm.ad == 1); spdk_free(g_request->payload.contig_or_cb_arg); nvme_free_request(g_request); diff --git a/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c b/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c index 8aee340c17..f0002ad153 100644 --- a/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c +++ b/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c @@ -913,7 +913,7 @@ test_set_get_features(void) /* Set SPDK_NVME_FEAT_HOST_RESERVE_PERSIST feature */ cmd.nvme_cmd.opc = SPDK_NVME_OPC_SET_FEATURES; - cmd.nvme_cmd.cdw11 = 0x1u; + cmd.nvme_cmd.cdw11_bits.feat_rsv_persistence.bits.ptpl = 1; ns[0].ptpl_file = "testcfg"; rc = spdk_nvmf_ctrlr_set_features_reservation_persistence(&req); CU_ASSERT(rc == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE);