admin-cmd.c (463c5fabb8dfca4941c4c50365bb7749ac5c9916) admin-cmd.c (136cc1ffcf0a3309c59d844cb1a4ddad964ea3d8)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * NVMe admin command implementation.
4 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
5 */
6#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7#include <linux/module.h>
8#include <linux/rculist.h>

--- 281 unchanged lines hidden (view full) ---

290 /* copy the header last once we know the number of groups */
291 status = nvmet_copy_to_sgl(req, 0, &hdr, sizeof(hdr));
292out:
293 nvmet_req_complete(req, status);
294}
295
296static void nvmet_execute_get_log_page(struct nvmet_req *req)
297{
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * NVMe admin command implementation.
4 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
5 */
6#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7#include <linux/module.h>
8#include <linux/rculist.h>

--- 281 unchanged lines hidden (view full) ---

290 /* copy the header last once we know the number of groups */
291 status = nvmet_copy_to_sgl(req, 0, &hdr, sizeof(hdr));
292out:
293 nvmet_req_complete(req, status);
294}
295
296static void nvmet_execute_get_log_page(struct nvmet_req *req)
297{
298 if (!nvmet_check_data_len(req, nvmet_get_log_page_len(req->cmd)))
298 if (!nvmet_check_transfer_len(req, nvmet_get_log_page_len(req->cmd)))
299 return;
300
301 switch (req->cmd->get_log_page.lid) {
302 case NVME_LOG_ERROR:
303 return nvmet_execute_get_log_page_error(req);
304 case NVME_LOG_SMART:
305 return nvmet_execute_get_log_page_smart(req);
306 case NVME_LOG_FW_SLOT:

--- 315 unchanged lines hidden (view full) ---

622out_put_ns:
623 nvmet_put_namespace(ns);
624out:
625 nvmet_req_complete(req, status);
626}
627
628static void nvmet_execute_identify(struct nvmet_req *req)
629{
299 return;
300
301 switch (req->cmd->get_log_page.lid) {
302 case NVME_LOG_ERROR:
303 return nvmet_execute_get_log_page_error(req);
304 case NVME_LOG_SMART:
305 return nvmet_execute_get_log_page_smart(req);
306 case NVME_LOG_FW_SLOT:

--- 315 unchanged lines hidden (view full) ---

622out_put_ns:
623 nvmet_put_namespace(ns);
624out:
625 nvmet_req_complete(req, status);
626}
627
628static void nvmet_execute_identify(struct nvmet_req *req)
629{
630 if (!nvmet_check_data_len(req, NVME_IDENTIFY_DATA_SIZE))
630 if (!nvmet_check_transfer_len(req, NVME_IDENTIFY_DATA_SIZE))
631 return;
632
633 switch (req->cmd->identify.cns) {
634 case NVME_ID_CNS_NS:
635 return nvmet_execute_identify_ns(req);
636 case NVME_ID_CNS_CTRL:
637 return nvmet_execute_identify_ctrl(req);
638 case NVME_ID_CNS_NS_ACTIVE_LIST:

--- 12 unchanged lines hidden (view full) ---

651 * A "minimum viable" abort implementation: the command is mandatory in the
652 * spec, but we are not required to do any useful work. We couldn't really
653 * do a useful abort, so don't bother even with waiting for the command
654 * to be exectuted and return immediately telling the command to abort
655 * wasn't found.
656 */
657static void nvmet_execute_abort(struct nvmet_req *req)
658{
631 return;
632
633 switch (req->cmd->identify.cns) {
634 case NVME_ID_CNS_NS:
635 return nvmet_execute_identify_ns(req);
636 case NVME_ID_CNS_CTRL:
637 return nvmet_execute_identify_ctrl(req);
638 case NVME_ID_CNS_NS_ACTIVE_LIST:

--- 12 unchanged lines hidden (view full) ---

651 * A "minimum viable" abort implementation: the command is mandatory in the
652 * spec, but we are not required to do any useful work. We couldn't really
653 * do a useful abort, so don't bother even with waiting for the command
654 * to be exectuted and return immediately telling the command to abort
655 * wasn't found.
656 */
657static void nvmet_execute_abort(struct nvmet_req *req)
658{
659 if (!nvmet_check_data_len(req, 0))
659 if (!nvmet_check_transfer_len(req, 0))
660 return;
661 nvmet_set_result(req, 1);
662 nvmet_req_complete(req, 0);
663}
664
665static u16 nvmet_write_protect_flush_sync(struct nvmet_req *req)
666{
667 u16 status;

--- 72 unchanged lines hidden (view full) ---

740{
741 struct nvmet_subsys *subsys = req->sq->ctrl->subsys;
742 u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10);
743 u32 cdw11 = le32_to_cpu(req->cmd->common.cdw11);
744 u16 status = 0;
745 u16 nsqr;
746 u16 ncqr;
747
660 return;
661 nvmet_set_result(req, 1);
662 nvmet_req_complete(req, 0);
663}
664
665static u16 nvmet_write_protect_flush_sync(struct nvmet_req *req)
666{
667 u16 status;

--- 72 unchanged lines hidden (view full) ---

740{
741 struct nvmet_subsys *subsys = req->sq->ctrl->subsys;
742 u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10);
743 u32 cdw11 = le32_to_cpu(req->cmd->common.cdw11);
744 u16 status = 0;
745 u16 nsqr;
746 u16 ncqr;
747
748 if (!nvmet_check_data_len(req, 0))
748 if (!nvmet_check_transfer_len(req, 0))
749 return;
750
751 switch (cdw10 & 0xff) {
752 case NVME_FEAT_NUM_QUEUES:
753 ncqr = (cdw11 >> 16) & 0xffff;
754 nsqr = cdw11 & 0xffff;
755 if (ncqr == 0xffff || nsqr == 0xffff) {
756 status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;

--- 55 unchanged lines hidden (view full) ---

812}
813
814static void nvmet_execute_get_features(struct nvmet_req *req)
815{
816 struct nvmet_subsys *subsys = req->sq->ctrl->subsys;
817 u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10);
818 u16 status = 0;
819
749 return;
750
751 switch (cdw10 & 0xff) {
752 case NVME_FEAT_NUM_QUEUES:
753 ncqr = (cdw11 >> 16) & 0xffff;
754 nsqr = cdw11 & 0xffff;
755 if (ncqr == 0xffff || nsqr == 0xffff) {
756 status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;

--- 55 unchanged lines hidden (view full) ---

812}
813
814static void nvmet_execute_get_features(struct nvmet_req *req)
815{
816 struct nvmet_subsys *subsys = req->sq->ctrl->subsys;
817 u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10);
818 u16 status = 0;
819
820 if (!nvmet_check_data_len(req, nvmet_feat_data_len(req, cdw10)))
820 if (!nvmet_check_transfer_len(req, nvmet_feat_data_len(req, cdw10)))
821 return;
822
823 switch (cdw10 & 0xff) {
824 /*
825 * These features are mandatory in the spec, but we don't
826 * have a useful way to implement them. We'll eventually
827 * need to come up with some fake values for these.
828 */

--- 50 unchanged lines hidden (view full) ---

879
880 nvmet_req_complete(req, status);
881}
882
883void nvmet_execute_async_event(struct nvmet_req *req)
884{
885 struct nvmet_ctrl *ctrl = req->sq->ctrl;
886
821 return;
822
823 switch (cdw10 & 0xff) {
824 /*
825 * These features are mandatory in the spec, but we don't
826 * have a useful way to implement them. We'll eventually
827 * need to come up with some fake values for these.
828 */

--- 50 unchanged lines hidden (view full) ---

879
880 nvmet_req_complete(req, status);
881}
882
883void nvmet_execute_async_event(struct nvmet_req *req)
884{
885 struct nvmet_ctrl *ctrl = req->sq->ctrl;
886
887 if (!nvmet_check_data_len(req, 0))
887 if (!nvmet_check_transfer_len(req, 0))
888 return;
889
890 mutex_lock(&ctrl->lock);
891 if (ctrl->nr_async_event_cmds >= NVMET_ASYNC_EVENTS) {
892 mutex_unlock(&ctrl->lock);
893 nvmet_req_complete(req, NVME_SC_ASYNC_LIMIT | NVME_SC_DNR);
894 return;
895 }
896 ctrl->async_event_cmds[ctrl->nr_async_event_cmds++] = req;
897 mutex_unlock(&ctrl->lock);
898
899 schedule_work(&ctrl->async_event_work);
900}
901
902void nvmet_execute_keep_alive(struct nvmet_req *req)
903{
904 struct nvmet_ctrl *ctrl = req->sq->ctrl;
905
888 return;
889
890 mutex_lock(&ctrl->lock);
891 if (ctrl->nr_async_event_cmds >= NVMET_ASYNC_EVENTS) {
892 mutex_unlock(&ctrl->lock);
893 nvmet_req_complete(req, NVME_SC_ASYNC_LIMIT | NVME_SC_DNR);
894 return;
895 }
896 ctrl->async_event_cmds[ctrl->nr_async_event_cmds++] = req;
897 mutex_unlock(&ctrl->lock);
898
899 schedule_work(&ctrl->async_event_work);
900}
901
902void nvmet_execute_keep_alive(struct nvmet_req *req)
903{
904 struct nvmet_ctrl *ctrl = req->sq->ctrl;
905
906 if (!nvmet_check_data_len(req, 0))
906 if (!nvmet_check_transfer_len(req, 0))
907 return;
908
909 pr_debug("ctrl %d update keep-alive timer for %d secs\n",
910 ctrl->cntlid, ctrl->kato);
911
912 mod_delayed_work(system_wq, &ctrl->ka_work, ctrl->kato * HZ);
913 nvmet_req_complete(req, 0);
914}

--- 44 unchanged lines hidden ---
907 return;
908
909 pr_debug("ctrl %d update keep-alive timer for %d secs\n",
910 ctrl->cntlid, ctrl->kato);
911
912 mod_delayed_work(system_wq, &ctrl->ka_work, ctrl->kato * HZ);
913 nvmet_req_complete(req, 0);
914}

--- 44 unchanged lines hidden ---