Lines Matching full:req
28 static u32 nvmet_feat_data_len(struct nvmet_req *req, u32 cdw10) in nvmet_feat_data_len() argument
32 return sizeof(req->sq->ctrl->hostid); in nvmet_feat_data_len()
43 static void nvmet_execute_get_log_page_noop(struct nvmet_req *req) in nvmet_execute_get_log_page_noop() argument
45 nvmet_req_complete(req, nvmet_zero_sgl(req, 0, req->transfer_len)); in nvmet_execute_get_log_page_noop()
48 static void nvmet_execute_get_log_page_error(struct nvmet_req *req) in nvmet_execute_get_log_page_error() argument
50 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_execute_get_log_page_error()
60 if (nvmet_copy_to_sgl(req, offset, &ctrl->slots[slot], in nvmet_execute_get_log_page_error()
71 nvmet_req_complete(req, 0); in nvmet_execute_get_log_page_error()
74 static u16 nvmet_get_smart_log_nsid(struct nvmet_req *req, in nvmet_get_smart_log_nsid() argument
80 status = nvmet_req_find_ns(req); in nvmet_get_smart_log_nsid()
85 if (!req->ns->bdev) in nvmet_get_smart_log_nsid()
88 host_reads = part_stat_read(req->ns->bdev, ios[READ]); in nvmet_get_smart_log_nsid()
90 DIV_ROUND_UP(part_stat_read(req->ns->bdev, sectors[READ]), 1000); in nvmet_get_smart_log_nsid()
91 host_writes = part_stat_read(req->ns->bdev, ios[WRITE]); in nvmet_get_smart_log_nsid()
93 DIV_ROUND_UP(part_stat_read(req->ns->bdev, sectors[WRITE]), 1000); in nvmet_get_smart_log_nsid()
103 static u16 nvmet_get_smart_log_all(struct nvmet_req *req, in nvmet_get_smart_log_all() argument
112 ctrl = req->sq->ctrl; in nvmet_get_smart_log_all()
133 static void nvmet_execute_get_log_page_smart(struct nvmet_req *req) in nvmet_execute_get_log_page_smart() argument
139 if (req->transfer_len != sizeof(*log)) in nvmet_execute_get_log_page_smart()
146 if (req->cmd->get_log_page.nsid == cpu_to_le32(NVME_NSID_ALL)) in nvmet_execute_get_log_page_smart()
147 status = nvmet_get_smart_log_all(req, log); in nvmet_execute_get_log_page_smart()
149 status = nvmet_get_smart_log_nsid(req, log); in nvmet_execute_get_log_page_smart()
153 spin_lock_irqsave(&req->sq->ctrl->error_lock, flags); in nvmet_execute_get_log_page_smart()
154 put_unaligned_le64(req->sq->ctrl->err_counter, in nvmet_execute_get_log_page_smart()
156 spin_unlock_irqrestore(&req->sq->ctrl->error_lock, flags); in nvmet_execute_get_log_page_smart()
158 status = nvmet_copy_to_sgl(req, 0, log, sizeof(*log)); in nvmet_execute_get_log_page_smart()
162 nvmet_req_complete(req, status); in nvmet_execute_get_log_page_smart()
194 static void nvmet_execute_get_log_cmd_effects_ns(struct nvmet_req *req) in nvmet_execute_get_log_cmd_effects_ns() argument
205 switch (req->cmd->get_log_page.csi) { in nvmet_execute_get_log_cmd_effects_ns()
222 status = nvmet_copy_to_sgl(req, 0, log, sizeof(*log)); in nvmet_execute_get_log_cmd_effects_ns()
226 nvmet_req_complete(req, status); in nvmet_execute_get_log_cmd_effects_ns()
229 static void nvmet_execute_get_log_changed_ns(struct nvmet_req *req) in nvmet_execute_get_log_changed_ns() argument
231 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_execute_get_log_changed_ns()
235 if (req->transfer_len != NVME_MAX_CHANGED_NAMESPACES * sizeof(__le32)) in nvmet_execute_get_log_changed_ns()
243 status = nvmet_copy_to_sgl(req, 0, ctrl->changed_ns_list, len); in nvmet_execute_get_log_changed_ns()
245 status = nvmet_zero_sgl(req, len, req->transfer_len - len); in nvmet_execute_get_log_changed_ns()
247 nvmet_clear_aen_bit(req, NVME_AEN_BIT_NS_ATTR); in nvmet_execute_get_log_changed_ns()
250 nvmet_req_complete(req, status); in nvmet_execute_get_log_changed_ns()
253 static u32 nvmet_format_ana_group(struct nvmet_req *req, u32 grpid, in nvmet_format_ana_group() argument
256 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_format_ana_group()
261 if (!(req->cmd->get_log_page.lsp & NVME_ANA_LOG_RGO)) { in nvmet_format_ana_group()
270 desc->state = req->port->ana_state[grpid]; in nvmet_format_ana_group()
275 static void nvmet_execute_get_log_page_ana(struct nvmet_req *req) in nvmet_execute_get_log_page_ana() argument
295 len = nvmet_format_ana_group(req, grpid, desc); in nvmet_execute_get_log_page_ana()
296 status = nvmet_copy_to_sgl(req, offset, desc, len); in nvmet_execute_get_log_page_ana()
309 nvmet_clear_aen_bit(req, NVME_AEN_BIT_ANA_CHANGE); in nvmet_execute_get_log_page_ana()
315 status = nvmet_copy_to_sgl(req, 0, &hdr, sizeof(hdr)); in nvmet_execute_get_log_page_ana()
317 nvmet_req_complete(req, status); in nvmet_execute_get_log_page_ana()
320 static void nvmet_execute_get_log_page(struct nvmet_req *req) in nvmet_execute_get_log_page() argument
322 if (!nvmet_check_transfer_len(req, nvmet_get_log_page_len(req->cmd))) in nvmet_execute_get_log_page()
325 switch (req->cmd->get_log_page.lid) { in nvmet_execute_get_log_page()
327 return nvmet_execute_get_log_page_error(req); in nvmet_execute_get_log_page()
329 return nvmet_execute_get_log_page_smart(req); in nvmet_execute_get_log_page()
336 return nvmet_execute_get_log_page_noop(req); in nvmet_execute_get_log_page()
338 return nvmet_execute_get_log_changed_ns(req); in nvmet_execute_get_log_page()
340 return nvmet_execute_get_log_cmd_effects_ns(req); in nvmet_execute_get_log_page()
342 return nvmet_execute_get_log_page_ana(req); in nvmet_execute_get_log_page()
345 req->cmd->get_log_page.lid, req->sq->qid); in nvmet_execute_get_log_page()
346 req->error_loc = offsetof(struct nvme_get_log_page_command, lid); in nvmet_execute_get_log_page()
347 nvmet_req_complete(req, NVME_SC_INVALID_FIELD | NVME_SC_DNR); in nvmet_execute_get_log_page()
350 static void nvmet_execute_identify_ctrl(struct nvmet_req *req) in nvmet_execute_identify_ctrl() argument
352 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_execute_identify_ctrl()
451 if (req->port->inline_data_size) in nvmet_execute_identify_ctrl()
462 cmd_capsule_size += req->port->inline_data_size; in nvmet_execute_identify_ctrl()
485 status = nvmet_copy_to_sgl(req, 0, id, sizeof(*id)); in nvmet_execute_identify_ctrl()
489 nvmet_req_complete(req, status); in nvmet_execute_identify_ctrl()
492 static void nvmet_execute_identify_ns(struct nvmet_req *req) in nvmet_execute_identify_ns() argument
497 if (le32_to_cpu(req->cmd->identify.nsid) == NVME_NSID_ALL) { in nvmet_execute_identify_ns()
498 req->error_loc = offsetof(struct nvme_identify, nsid); in nvmet_execute_identify_ns()
510 status = nvmet_req_find_ns(req); in nvmet_execute_identify_ns()
516 if (nvmet_ns_revalidate(req->ns)) { in nvmet_execute_identify_ns()
517 mutex_lock(&req->ns->subsys->lock); in nvmet_execute_identify_ns()
518 nvmet_ns_changed(req->ns->subsys, req->ns->nsid); in nvmet_execute_identify_ns()
519 mutex_unlock(&req->ns->subsys->lock); in nvmet_execute_identify_ns()
527 cpu_to_le64(req->ns->size >> req->ns->blksize_shift); in nvmet_execute_identify_ns()
528 switch (req->port->ana_state[req->ns->anagrpid]) { in nvmet_execute_identify_ns()
537 if (req->ns->bdev) in nvmet_execute_identify_ns()
538 nvmet_bdev_set_limits(req->ns->bdev, id); in nvmet_execute_identify_ns()
552 id->anagrpid = cpu_to_le32(req->ns->anagrpid); in nvmet_execute_identify_ns()
554 memcpy(&id->nguid, &req->ns->nguid, sizeof(id->nguid)); in nvmet_execute_identify_ns()
556 id->lbaf[0].ds = req->ns->blksize_shift; in nvmet_execute_identify_ns()
558 if (req->sq->ctrl->pi_support && nvmet_ns_has_pi(req->ns)) { in nvmet_execute_identify_ns()
563 id->dps = req->ns->pi_type; in nvmet_execute_identify_ns()
565 id->lbaf[0].ms = cpu_to_le16(req->ns->metadata_size); in nvmet_execute_identify_ns()
568 if (req->ns->readonly) in nvmet_execute_identify_ns()
572 status = nvmet_copy_to_sgl(req, 0, id, sizeof(*id)); in nvmet_execute_identify_ns()
576 nvmet_req_complete(req, status); in nvmet_execute_identify_ns()
579 static void nvmet_execute_identify_nslist(struct nvmet_req *req) in nvmet_execute_identify_nslist() argument
582 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_execute_identify_nslist()
585 u32 min_nsid = le32_to_cpu(req->cmd->identify.nsid); in nvmet_execute_identify_nslist()
604 status = nvmet_copy_to_sgl(req, 0, list, buf_size); in nvmet_execute_identify_nslist()
608 nvmet_req_complete(req, status); in nvmet_execute_identify_nslist()
611 static u16 nvmet_copy_ns_identifier(struct nvmet_req *req, u8 type, u8 len, in nvmet_copy_ns_identifier() argument
620 status = nvmet_copy_to_sgl(req, *off, &desc, sizeof(desc)); in nvmet_copy_ns_identifier()
625 status = nvmet_copy_to_sgl(req, *off, id, len); in nvmet_copy_ns_identifier()
633 static void nvmet_execute_identify_desclist(struct nvmet_req *req) in nvmet_execute_identify_desclist() argument
638 status = nvmet_req_find_ns(req); in nvmet_execute_identify_desclist()
642 if (memchr_inv(&req->ns->uuid, 0, sizeof(req->ns->uuid))) { in nvmet_execute_identify_desclist()
643 status = nvmet_copy_ns_identifier(req, NVME_NIDT_UUID, in nvmet_execute_identify_desclist()
645 &req->ns->uuid, &off); in nvmet_execute_identify_desclist()
649 if (memchr_inv(req->ns->nguid, 0, sizeof(req->ns->nguid))) { in nvmet_execute_identify_desclist()
650 status = nvmet_copy_ns_identifier(req, NVME_NIDT_NGUID, in nvmet_execute_identify_desclist()
652 &req->ns->nguid, &off); in nvmet_execute_identify_desclist()
657 status = nvmet_copy_ns_identifier(req, NVME_NIDT_CSI, in nvmet_execute_identify_desclist()
659 &req->ns->csi, &off); in nvmet_execute_identify_desclist()
663 if (sg_zero_buffer(req->sg, req->sg_cnt, NVME_IDENTIFY_DATA_SIZE - off, in nvmet_execute_identify_desclist()
668 nvmet_req_complete(req, status); in nvmet_execute_identify_desclist()
671 static void nvmet_execute_identify_ctrl_nvm(struct nvmet_req *req) in nvmet_execute_identify_ctrl_nvm() argument
674 nvmet_req_complete(req, in nvmet_execute_identify_ctrl_nvm()
675 nvmet_zero_sgl(req, 0, sizeof(struct nvme_id_ctrl_nvm))); in nvmet_execute_identify_ctrl_nvm()
678 static void nvmet_execute_identify(struct nvmet_req *req) in nvmet_execute_identify() argument
680 if (!nvmet_check_transfer_len(req, NVME_IDENTIFY_DATA_SIZE)) in nvmet_execute_identify()
683 switch (req->cmd->identify.cns) { in nvmet_execute_identify()
685 nvmet_execute_identify_ns(req); in nvmet_execute_identify()
688 nvmet_execute_identify_ctrl(req); in nvmet_execute_identify()
691 nvmet_execute_identify_nslist(req); in nvmet_execute_identify()
694 nvmet_execute_identify_desclist(req); in nvmet_execute_identify()
697 switch (req->cmd->identify.csi) { in nvmet_execute_identify()
703 nvmet_execute_identify_ns_zns(req); in nvmet_execute_identify()
710 switch (req->cmd->identify.csi) { in nvmet_execute_identify()
712 nvmet_execute_identify_ctrl_nvm(req); in nvmet_execute_identify()
716 nvmet_execute_identify_ctrl_zns(req); in nvmet_execute_identify()
725 req->cmd->identify.cns, req->sq->qid); in nvmet_execute_identify()
726 req->error_loc = offsetof(struct nvme_identify, cns); in nvmet_execute_identify()
727 nvmet_req_complete(req, NVME_SC_INVALID_FIELD | NVME_SC_DNR); in nvmet_execute_identify()
737 static void nvmet_execute_abort(struct nvmet_req *req) in nvmet_execute_abort() argument
739 if (!nvmet_check_transfer_len(req, 0)) in nvmet_execute_abort()
741 nvmet_set_result(req, 1); in nvmet_execute_abort()
742 nvmet_req_complete(req, 0); in nvmet_execute_abort()
745 static u16 nvmet_write_protect_flush_sync(struct nvmet_req *req) in nvmet_write_protect_flush_sync() argument
749 if (req->ns->file) in nvmet_write_protect_flush_sync()
750 status = nvmet_file_flush(req); in nvmet_write_protect_flush_sync()
752 status = nvmet_bdev_flush(req); in nvmet_write_protect_flush_sync()
755 pr_err("write protect flush failed nsid: %u\n", req->ns->nsid); in nvmet_write_protect_flush_sync()
759 static u16 nvmet_set_feat_write_protect(struct nvmet_req *req) in nvmet_set_feat_write_protect() argument
761 u32 write_protect = le32_to_cpu(req->cmd->common.cdw11); in nvmet_set_feat_write_protect()
762 struct nvmet_subsys *subsys = nvmet_req_subsys(req); in nvmet_set_feat_write_protect()
765 status = nvmet_req_find_ns(req); in nvmet_set_feat_write_protect()
772 req->ns->readonly = true; in nvmet_set_feat_write_protect()
773 status = nvmet_write_protect_flush_sync(req); in nvmet_set_feat_write_protect()
775 req->ns->readonly = false; in nvmet_set_feat_write_protect()
778 req->ns->readonly = false; in nvmet_set_feat_write_protect()
786 nvmet_ns_changed(subsys, req->ns->nsid); in nvmet_set_feat_write_protect()
791 u16 nvmet_set_feat_kato(struct nvmet_req *req) in nvmet_set_feat_kato() argument
793 u32 val32 = le32_to_cpu(req->cmd->common.cdw11); in nvmet_set_feat_kato()
795 nvmet_stop_keep_alive_timer(req->sq->ctrl); in nvmet_set_feat_kato()
796 req->sq->ctrl->kato = DIV_ROUND_UP(val32, 1000); in nvmet_set_feat_kato()
797 nvmet_start_keep_alive_timer(req->sq->ctrl); in nvmet_set_feat_kato()
799 nvmet_set_result(req, req->sq->ctrl->kato); in nvmet_set_feat_kato()
804 u16 nvmet_set_feat_async_event(struct nvmet_req *req, u32 mask) in nvmet_set_feat_async_event() argument
806 u32 val32 = le32_to_cpu(req->cmd->common.cdw11); in nvmet_set_feat_async_event()
809 req->error_loc = offsetof(struct nvme_common_command, cdw11); in nvmet_set_feat_async_event()
813 WRITE_ONCE(req->sq->ctrl->aen_enabled, val32); in nvmet_set_feat_async_event()
814 nvmet_set_result(req, val32); in nvmet_set_feat_async_event()
819 void nvmet_execute_set_features(struct nvmet_req *req) in nvmet_execute_set_features() argument
821 struct nvmet_subsys *subsys = nvmet_req_subsys(req); in nvmet_execute_set_features()
822 u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10); in nvmet_execute_set_features()
823 u32 cdw11 = le32_to_cpu(req->cmd->common.cdw11); in nvmet_execute_set_features()
828 if (!nvmet_check_data_len_lte(req, 0)) in nvmet_execute_set_features()
839 nvmet_set_result(req, in nvmet_execute_set_features()
843 status = nvmet_set_feat_kato(req); in nvmet_execute_set_features()
846 status = nvmet_set_feat_async_event(req, NVMET_AEN_CFG_ALL); in nvmet_execute_set_features()
852 status = nvmet_set_feat_write_protect(req); in nvmet_execute_set_features()
855 req->error_loc = offsetof(struct nvme_common_command, cdw10); in nvmet_execute_set_features()
860 nvmet_req_complete(req, status); in nvmet_execute_set_features()
863 static u16 nvmet_get_feat_write_protect(struct nvmet_req *req) in nvmet_get_feat_write_protect() argument
865 struct nvmet_subsys *subsys = nvmet_req_subsys(req); in nvmet_get_feat_write_protect()
868 result = nvmet_req_find_ns(req); in nvmet_get_feat_write_protect()
873 if (req->ns->readonly == true) in nvmet_get_feat_write_protect()
877 nvmet_set_result(req, result); in nvmet_get_feat_write_protect()
883 void nvmet_get_feat_kato(struct nvmet_req *req) in nvmet_get_feat_kato() argument
885 nvmet_set_result(req, req->sq->ctrl->kato * 1000); in nvmet_get_feat_kato()
888 void nvmet_get_feat_async_event(struct nvmet_req *req) in nvmet_get_feat_async_event() argument
890 nvmet_set_result(req, READ_ONCE(req->sq->ctrl->aen_enabled)); in nvmet_get_feat_async_event()
893 void nvmet_execute_get_features(struct nvmet_req *req) in nvmet_execute_get_features() argument
895 struct nvmet_subsys *subsys = nvmet_req_subsys(req); in nvmet_execute_get_features()
896 u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10); in nvmet_execute_get_features()
899 if (!nvmet_check_transfer_len(req, nvmet_feat_data_len(req, cdw10))) in nvmet_execute_get_features()
925 nvmet_get_feat_async_event(req); in nvmet_execute_get_features()
928 nvmet_set_result(req, 1); in nvmet_execute_get_features()
931 nvmet_set_result(req, in nvmet_execute_get_features()
935 nvmet_get_feat_kato(req); in nvmet_execute_get_features()
939 if (!(req->cmd->common.cdw11 & cpu_to_le32(1 << 0))) { in nvmet_execute_get_features()
940 req->error_loc = in nvmet_execute_get_features()
946 status = nvmet_copy_to_sgl(req, 0, &req->sq->ctrl->hostid, in nvmet_execute_get_features()
947 sizeof(req->sq->ctrl->hostid)); in nvmet_execute_get_features()
950 status = nvmet_get_feat_write_protect(req); in nvmet_execute_get_features()
953 req->error_loc = in nvmet_execute_get_features()
959 nvmet_req_complete(req, status); in nvmet_execute_get_features()
962 void nvmet_execute_async_event(struct nvmet_req *req) in nvmet_execute_async_event() argument
964 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_execute_async_event()
966 if (!nvmet_check_transfer_len(req, 0)) in nvmet_execute_async_event()
972 nvmet_req_complete(req, NVME_SC_ASYNC_LIMIT | NVME_SC_DNR); in nvmet_execute_async_event()
975 ctrl->async_event_cmds[ctrl->nr_async_event_cmds++] = req; in nvmet_execute_async_event()
981 void nvmet_execute_keep_alive(struct nvmet_req *req) in nvmet_execute_keep_alive() argument
983 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_execute_keep_alive()
986 if (!nvmet_check_transfer_len(req, 0)) in nvmet_execute_keep_alive()
998 nvmet_req_complete(req, status); in nvmet_execute_keep_alive()
1001 u16 nvmet_parse_admin_cmd(struct nvmet_req *req) in nvmet_parse_admin_cmd() argument
1003 struct nvme_command *cmd = req->cmd; in nvmet_parse_admin_cmd()
1007 return nvmet_parse_fabrics_admin_cmd(req); in nvmet_parse_admin_cmd()
1008 if (unlikely(!nvmet_check_auth_status(req))) in nvmet_parse_admin_cmd()
1010 if (nvmet_is_disc_subsys(nvmet_req_subsys(req))) in nvmet_parse_admin_cmd()
1011 return nvmet_parse_discovery_cmd(req); in nvmet_parse_admin_cmd()
1013 ret = nvmet_check_ctrl_status(req); in nvmet_parse_admin_cmd()
1017 if (nvmet_is_passthru_req(req)) in nvmet_parse_admin_cmd()
1018 return nvmet_parse_passthru_admin_cmd(req); in nvmet_parse_admin_cmd()
1022 req->execute = nvmet_execute_get_log_page; in nvmet_parse_admin_cmd()
1025 req->execute = nvmet_execute_identify; in nvmet_parse_admin_cmd()
1028 req->execute = nvmet_execute_abort; in nvmet_parse_admin_cmd()
1031 req->execute = nvmet_execute_set_features; in nvmet_parse_admin_cmd()
1034 req->execute = nvmet_execute_get_features; in nvmet_parse_admin_cmd()
1037 req->execute = nvmet_execute_async_event; in nvmet_parse_admin_cmd()
1040 req->execute = nvmet_execute_keep_alive; in nvmet_parse_admin_cmd()
1043 return nvmet_report_invalid_opcode(req); in nvmet_parse_admin_cmd()