Lines Matching +full:ctrl +full:- +full:len
3 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
29 int rae = le32_to_cpu(req->cmd->common.cdw10[0]) & 1 << 15; in nvmet_clear_aen()
32 clear_bit(aen_bit, &req->sq->ctrl->aen_masked); in nvmet_clear_aen()
37 u32 len = le16_to_cpu(cmd->get_log_page.numdu); in nvmet_get_log_page_len() local
39 len <<= 16; in nvmet_get_log_page_len()
40 len += le16_to_cpu(cmd->get_log_page.numdl); in nvmet_get_log_page_len()
42 len += 1; in nvmet_get_log_page_len()
43 len *= sizeof(u32); in nvmet_get_log_page_len()
45 return len; in nvmet_get_log_page_len()
50 nvmet_req_complete(req, nvmet_zero_sgl(req, 0, req->data_len)); in nvmet_execute_get_log_page_noop()
59 ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->get_log_page.nsid); in nvmet_get_smart_log_nsid()
62 le32_to_cpu(req->cmd->get_log_page.nsid)); in nvmet_get_smart_log_nsid()
67 if (!ns->bdev) in nvmet_get_smart_log_nsid()
70 host_reads = part_stat_read(ns->bdev->bd_part, ios[READ]); in nvmet_get_smart_log_nsid()
71 data_units_read = DIV_ROUND_UP(part_stat_read(ns->bdev->bd_part, in nvmet_get_smart_log_nsid()
73 host_writes = part_stat_read(ns->bdev->bd_part, ios[WRITE]); in nvmet_get_smart_log_nsid()
74 data_units_written = DIV_ROUND_UP(part_stat_read(ns->bdev->bd_part, in nvmet_get_smart_log_nsid()
77 put_unaligned_le64(host_reads, &slog->host_reads[0]); in nvmet_get_smart_log_nsid()
78 put_unaligned_le64(data_units_read, &slog->data_units_read[0]); in nvmet_get_smart_log_nsid()
79 put_unaligned_le64(host_writes, &slog->host_writes[0]); in nvmet_get_smart_log_nsid()
80 put_unaligned_le64(data_units_written, &slog->data_units_written[0]); in nvmet_get_smart_log_nsid()
93 struct nvmet_ctrl *ctrl; in nvmet_get_smart_log_all() local
95 ctrl = req->sq->ctrl; in nvmet_get_smart_log_all()
98 list_for_each_entry_rcu(ns, &ctrl->subsys->namespaces, dev_link) { in nvmet_get_smart_log_all()
100 if (!ns->bdev) in nvmet_get_smart_log_all()
102 host_reads += part_stat_read(ns->bdev->bd_part, ios[READ]); in nvmet_get_smart_log_all()
104 part_stat_read(ns->bdev->bd_part, sectors[READ]), 1000); in nvmet_get_smart_log_all()
105 host_writes += part_stat_read(ns->bdev->bd_part, ios[WRITE]); in nvmet_get_smart_log_all()
107 part_stat_read(ns->bdev->bd_part, sectors[WRITE]), 1000); in nvmet_get_smart_log_all()
112 put_unaligned_le64(host_reads, &slog->host_reads[0]); in nvmet_get_smart_log_all()
113 put_unaligned_le64(data_units_read, &slog->data_units_read[0]); in nvmet_get_smart_log_all()
114 put_unaligned_le64(host_writes, &slog->host_writes[0]); in nvmet_get_smart_log_all()
115 put_unaligned_le64(data_units_written, &slog->data_units_written[0]); in nvmet_get_smart_log_all()
125 if (req->data_len != sizeof(*log)) in nvmet_execute_get_log_page_smart()
132 if (req->cmd->get_log_page.nsid == cpu_to_le32(NVME_NSID_ALL)) in nvmet_execute_get_log_page_smart()
155 log->acs[nvme_admin_get_log_page] = cpu_to_le32(1 << 0); in nvmet_execute_get_log_cmd_effects_ns()
156 log->acs[nvme_admin_identify] = cpu_to_le32(1 << 0); in nvmet_execute_get_log_cmd_effects_ns()
157 log->acs[nvme_admin_abort_cmd] = cpu_to_le32(1 << 0); in nvmet_execute_get_log_cmd_effects_ns()
158 log->acs[nvme_admin_set_features] = cpu_to_le32(1 << 0); in nvmet_execute_get_log_cmd_effects_ns()
159 log->acs[nvme_admin_get_features] = cpu_to_le32(1 << 0); in nvmet_execute_get_log_cmd_effects_ns()
160 log->acs[nvme_admin_async_event] = cpu_to_le32(1 << 0); in nvmet_execute_get_log_cmd_effects_ns()
161 log->acs[nvme_admin_keep_alive] = cpu_to_le32(1 << 0); in nvmet_execute_get_log_cmd_effects_ns()
163 log->iocs[nvme_cmd_read] = cpu_to_le32(1 << 0); in nvmet_execute_get_log_cmd_effects_ns()
164 log->iocs[nvme_cmd_write] = cpu_to_le32(1 << 0); in nvmet_execute_get_log_cmd_effects_ns()
165 log->iocs[nvme_cmd_flush] = cpu_to_le32(1 << 0); in nvmet_execute_get_log_cmd_effects_ns()
166 log->iocs[nvme_cmd_dsm] = cpu_to_le32(1 << 0); in nvmet_execute_get_log_cmd_effects_ns()
167 log->iocs[nvme_cmd_write_zeroes] = cpu_to_le32(1 << 0); in nvmet_execute_get_log_cmd_effects_ns()
178 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_execute_get_log_changed_ns() local
180 size_t len; in nvmet_execute_get_log_changed_ns() local
182 if (req->data_len != NVME_MAX_CHANGED_NAMESPACES * sizeof(__le32)) in nvmet_execute_get_log_changed_ns()
185 mutex_lock(&ctrl->lock); in nvmet_execute_get_log_changed_ns()
186 if (ctrl->nr_changed_ns == U32_MAX) in nvmet_execute_get_log_changed_ns()
187 len = sizeof(__le32); in nvmet_execute_get_log_changed_ns()
189 len = ctrl->nr_changed_ns * sizeof(__le32); in nvmet_execute_get_log_changed_ns()
190 status = nvmet_copy_to_sgl(req, 0, ctrl->changed_ns_list, len); in nvmet_execute_get_log_changed_ns()
192 status = nvmet_zero_sgl(req, len, req->data_len - len); in nvmet_execute_get_log_changed_ns()
193 ctrl->nr_changed_ns = 0; in nvmet_execute_get_log_changed_ns()
195 mutex_unlock(&ctrl->lock); in nvmet_execute_get_log_changed_ns()
203 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_format_ana_group() local
207 if (!(req->cmd->get_log_page.lsp & NVME_ANA_LOG_RGO)) { in nvmet_format_ana_group()
209 list_for_each_entry_rcu(ns, &ctrl->subsys->namespaces, dev_link) in nvmet_format_ana_group()
210 if (ns->anagrpid == grpid) in nvmet_format_ana_group()
211 desc->nsids[count++] = cpu_to_le32(ns->nsid); in nvmet_format_ana_group()
215 desc->grpid = cpu_to_le32(grpid); in nvmet_format_ana_group()
216 desc->nnsids = cpu_to_le32(count); in nvmet_format_ana_group()
217 desc->chgcnt = cpu_to_le64(nvmet_ana_chgcnt); in nvmet_format_ana_group()
218 desc->state = req->port->ana_state[grpid]; in nvmet_format_ana_group()
219 memset(desc->rsvd17, 0, sizeof(desc->rsvd17)); in nvmet_format_ana_group()
228 size_t len; in nvmet_execute_get_log_page_ana() local
243 len = nvmet_format_ana_group(req, grpid, desc); in nvmet_execute_get_log_page_ana()
244 status = nvmet_copy_to_sgl(req, offset, desc, len); in nvmet_execute_get_log_page_ana()
247 offset += len; in nvmet_execute_get_log_page_ana()
270 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_execute_identify_ctrl() local
282 id->vid = 0; in nvmet_execute_identify_ctrl()
283 id->ssvid = 0; in nvmet_execute_identify_ctrl()
285 memset(id->sn, ' ', sizeof(id->sn)); in nvmet_execute_identify_ctrl()
286 bin2hex(id->sn, &ctrl->subsys->serial, in nvmet_execute_identify_ctrl()
287 min(sizeof(ctrl->subsys->serial), sizeof(id->sn) / 2)); in nvmet_execute_identify_ctrl()
288 memcpy_and_pad(id->mn, sizeof(id->mn), model, sizeof(model) - 1, ' '); in nvmet_execute_identify_ctrl()
289 memcpy_and_pad(id->fr, sizeof(id->fr), in nvmet_execute_identify_ctrl()
292 id->rab = 6; in nvmet_execute_identify_ctrl()
300 id->cmic = (1 << 0) | (1 << 1) | (1 << 3); in nvmet_execute_identify_ctrl()
303 id->mdts = 0; in nvmet_execute_identify_ctrl()
304 id->cntlid = cpu_to_le16(ctrl->cntlid); in nvmet_execute_identify_ctrl()
305 id->ver = cpu_to_le32(ctrl->subsys->ver); in nvmet_execute_identify_ctrl()
308 id->oaes = cpu_to_le32(NVMET_AEN_CFG_OPTIONAL); in nvmet_execute_identify_ctrl()
309 id->ctratt = cpu_to_le32(1 << 0); in nvmet_execute_identify_ctrl()
311 id->oacs = 0; in nvmet_execute_identify_ctrl()
318 id->acl = 3; in nvmet_execute_identify_ctrl()
320 id->aerl = NVMET_ASYNC_EVENTS - 1; in nvmet_execute_identify_ctrl()
322 /* first slot is read-only, only one slot supported */ in nvmet_execute_identify_ctrl()
323 id->frmw = (1 << 0) | (1 << 1); in nvmet_execute_identify_ctrl()
324 id->lpa = (1 << 0) | (1 << 1) | (1 << 2); in nvmet_execute_identify_ctrl()
325 id->elpe = NVMET_ERROR_LOG_SLOTS - 1; in nvmet_execute_identify_ctrl()
326 id->npss = 0; in nvmet_execute_identify_ctrl()
328 /* We support keep-alive timeout in granularity of seconds */ in nvmet_execute_identify_ctrl()
329 id->kas = cpu_to_le16(NVMET_KAS); in nvmet_execute_identify_ctrl()
331 id->sqes = (0x6 << 4) | 0x6; in nvmet_execute_identify_ctrl()
332 id->cqes = (0x4 << 4) | 0x4; in nvmet_execute_identify_ctrl()
334 /* no enforcement soft-limit for maxcmd - pick arbitrary high value */ in nvmet_execute_identify_ctrl()
335 id->maxcmd = cpu_to_le16(NVMET_MAX_CMD); in nvmet_execute_identify_ctrl()
337 id->nn = cpu_to_le32(ctrl->subsys->max_nsid); in nvmet_execute_identify_ctrl()
338 id->mnan = cpu_to_le32(NVMET_MAX_NAMESPACES); in nvmet_execute_identify_ctrl()
339 id->oncs = cpu_to_le16(NVME_CTRL_ONCS_DSM | in nvmet_execute_identify_ctrl()
343 id->vwc = NVME_CTRL_VWC_PRESENT; in nvmet_execute_identify_ctrl()
349 id->awun = 0; in nvmet_execute_identify_ctrl()
350 id->awupf = 0; in nvmet_execute_identify_ctrl()
352 id->sgls = cpu_to_le32(1 << 0); /* we always support SGLs */ in nvmet_execute_identify_ctrl()
353 if (ctrl->ops->has_keyed_sgls) in nvmet_execute_identify_ctrl()
354 id->sgls |= cpu_to_le32(1 << 2); in nvmet_execute_identify_ctrl()
355 if (req->port->inline_data_size) in nvmet_execute_identify_ctrl()
356 id->sgls |= cpu_to_le32(1 << 20); in nvmet_execute_identify_ctrl()
358 strcpy(id->subnqn, ctrl->subsys->subsysnqn); in nvmet_execute_identify_ctrl()
360 /* Max command capsule size is sqe + single page of in-capsule data */ in nvmet_execute_identify_ctrl()
361 id->ioccsz = cpu_to_le32((sizeof(struct nvme_command) + in nvmet_execute_identify_ctrl()
362 req->port->inline_data_size) / 16); in nvmet_execute_identify_ctrl()
364 id->iorcsz = cpu_to_le32(sizeof(struct nvme_completion) / 16); in nvmet_execute_identify_ctrl()
366 id->msdbd = ctrl->ops->msdbd; in nvmet_execute_identify_ctrl()
368 id->anacap = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4); in nvmet_execute_identify_ctrl()
369 id->anatt = 10; /* random value */ in nvmet_execute_identify_ctrl()
370 id->anagrpmax = cpu_to_le32(NVMET_MAX_ANAGRPS); in nvmet_execute_identify_ctrl()
371 id->nanagrpid = cpu_to_le32(NVMET_MAX_ANAGRPS); in nvmet_execute_identify_ctrl()
377 id->psd[0].max_power = cpu_to_le16(0x9c4); in nvmet_execute_identify_ctrl()
378 id->psd[0].entry_lat = cpu_to_le32(0x10); in nvmet_execute_identify_ctrl()
379 id->psd[0].exit_lat = cpu_to_le32(0x4); in nvmet_execute_identify_ctrl()
381 id->nwpc = 1 << 0; /* write protect and no write protect */ in nvmet_execute_identify_ctrl()
396 if (le32_to_cpu(req->cmd->identify.nsid) == NVME_NSID_ALL) { in nvmet_execute_identify_ns()
408 ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->identify.nsid); in nvmet_execute_identify_ns()
416 id->ncap = id->nsze = cpu_to_le64(ns->size >> ns->blksize_shift); in nvmet_execute_identify_ns()
417 switch (req->port->ana_state[ns->anagrpid]) { in nvmet_execute_identify_ns()
422 id->nuse = id->nsze; in nvmet_execute_identify_ns()
430 id->nlbaf = 0; in nvmet_execute_identify_ns()
431 id->flbas = 0; in nvmet_execute_identify_ns()
437 id->nmic = (1 << 0); in nvmet_execute_identify_ns()
438 id->anagrpid = cpu_to_le32(ns->anagrpid); in nvmet_execute_identify_ns()
440 memcpy(&id->nguid, &ns->nguid, sizeof(id->nguid)); in nvmet_execute_identify_ns()
442 id->lbaf[0].ds = ns->blksize_shift; in nvmet_execute_identify_ns()
444 if (ns->readonly) in nvmet_execute_identify_ns()
445 id->nsattr |= (1 << 0); in nvmet_execute_identify_ns()
457 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_execute_identify_nslist() local
459 u32 min_nsid = le32_to_cpu(req->cmd->identify.nsid); in nvmet_execute_identify_nslist()
471 list_for_each_entry_rcu(ns, &ctrl->subsys->namespaces, dev_link) { in nvmet_execute_identify_nslist()
472 if (ns->nsid <= min_nsid) in nvmet_execute_identify_nslist()
474 list[i++] = cpu_to_le32(ns->nsid); in nvmet_execute_identify_nslist()
487 static u16 nvmet_copy_ns_identifier(struct nvmet_req *req, u8 type, u8 len, in nvmet_copy_ns_identifier() argument
492 .nidl = len, in nvmet_copy_ns_identifier()
501 status = nvmet_copy_to_sgl(req, *off, id, len); in nvmet_copy_ns_identifier()
504 *off += len; in nvmet_copy_ns_identifier()
515 ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->identify.nsid); in nvmet_execute_identify_desclist()
521 if (memchr_inv(&ns->uuid, 0, sizeof(ns->uuid))) { in nvmet_execute_identify_desclist()
524 &ns->uuid, &off); in nvmet_execute_identify_desclist()
528 if (memchr_inv(ns->nguid, 0, sizeof(ns->nguid))) { in nvmet_execute_identify_desclist()
531 &ns->nguid, &off); in nvmet_execute_identify_desclist()
536 if (sg_zero_buffer(req->sg, req->sg_cnt, NVME_IDENTIFY_DATA_SIZE - off, in nvmet_execute_identify_desclist()
537 off) != NVME_IDENTIFY_DATA_SIZE - off) in nvmet_execute_identify_desclist()
562 if (req->ns->file) in nvmet_write_protect_flush_sync()
568 pr_err("write protect flush failed nsid: %u\n", req->ns->nsid); in nvmet_write_protect_flush_sync()
574 u32 write_protect = le32_to_cpu(req->cmd->common.cdw10[1]); in nvmet_set_feat_write_protect()
575 struct nvmet_subsys *subsys = req->sq->ctrl->subsys; in nvmet_set_feat_write_protect()
578 req->ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->rw.nsid); in nvmet_set_feat_write_protect()
579 if (unlikely(!req->ns)) in nvmet_set_feat_write_protect()
582 mutex_lock(&subsys->lock); in nvmet_set_feat_write_protect()
585 req->ns->readonly = true; in nvmet_set_feat_write_protect()
588 req->ns->readonly = false; in nvmet_set_feat_write_protect()
591 req->ns->readonly = false; in nvmet_set_feat_write_protect()
599 nvmet_ns_changed(subsys, req->ns->nsid); in nvmet_set_feat_write_protect()
600 mutex_unlock(&subsys->lock); in nvmet_set_feat_write_protect()
606 struct nvmet_subsys *subsys = req->sq->ctrl->subsys; in nvmet_execute_set_features()
607 u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10[0]); in nvmet_execute_set_features()
614 (subsys->max_qid - 1) | ((subsys->max_qid - 1) << 16)); in nvmet_execute_set_features()
617 val32 = le32_to_cpu(req->cmd->common.cdw10[1]); in nvmet_execute_set_features()
618 req->sq->ctrl->kato = DIV_ROUND_UP(val32, 1000); in nvmet_execute_set_features()
619 nvmet_set_result(req, req->sq->ctrl->kato); in nvmet_execute_set_features()
622 val32 = le32_to_cpu(req->cmd->common.cdw10[1]); in nvmet_execute_set_features()
628 WRITE_ONCE(req->sq->ctrl->aen_enabled, val32); in nvmet_execute_set_features()
647 struct nvmet_subsys *subsys = req->sq->ctrl->subsys; in nvmet_get_feat_write_protect()
650 req->ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->common.nsid); in nvmet_get_feat_write_protect()
651 if (!req->ns) in nvmet_get_feat_write_protect()
654 mutex_lock(&subsys->lock); in nvmet_get_feat_write_protect()
655 if (req->ns->readonly == true) in nvmet_get_feat_write_protect()
660 mutex_unlock(&subsys->lock); in nvmet_get_feat_write_protect()
667 struct nvmet_subsys *subsys = req->sq->ctrl->subsys; in nvmet_execute_get_features()
668 u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10[0]); in nvmet_execute_get_features()
694 nvmet_set_result(req, READ_ONCE(req->sq->ctrl->aen_enabled)); in nvmet_execute_get_features()
701 (subsys->max_qid-1) | ((subsys->max_qid-1) << 16)); in nvmet_execute_get_features()
704 nvmet_set_result(req, req->sq->ctrl->kato * 1000); in nvmet_execute_get_features()
707 /* need 128-bit host identifier flag */ in nvmet_execute_get_features()
708 if (!(req->cmd->common.cdw10[1] & cpu_to_le32(1 << 0))) { in nvmet_execute_get_features()
713 status = nvmet_copy_to_sgl(req, 0, &req->sq->ctrl->hostid, in nvmet_execute_get_features()
714 sizeof(req->sq->ctrl->hostid)); in nvmet_execute_get_features()
729 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_execute_async_event() local
731 mutex_lock(&ctrl->lock); in nvmet_execute_async_event()
732 if (ctrl->nr_async_event_cmds >= NVMET_ASYNC_EVENTS) { in nvmet_execute_async_event()
733 mutex_unlock(&ctrl->lock); in nvmet_execute_async_event()
737 ctrl->async_event_cmds[ctrl->nr_async_event_cmds++] = req; in nvmet_execute_async_event()
738 mutex_unlock(&ctrl->lock); in nvmet_execute_async_event()
740 schedule_work(&ctrl->async_event_work); in nvmet_execute_async_event()
745 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_execute_keep_alive() local
747 pr_debug("ctrl %d update keep-alive timer for %d secs\n", in nvmet_execute_keep_alive()
748 ctrl->cntlid, ctrl->kato); in nvmet_execute_keep_alive()
750 mod_delayed_work(system_wq, &ctrl->ka_work, ctrl->kato * HZ); in nvmet_execute_keep_alive()
756 struct nvme_command *cmd = req->cmd; in nvmet_parse_admin_cmd()
763 switch (cmd->common.opcode) { in nvmet_parse_admin_cmd()
765 req->data_len = nvmet_get_log_page_len(cmd); in nvmet_parse_admin_cmd()
767 switch (cmd->get_log_page.lid) { in nvmet_parse_admin_cmd()
775 req->execute = nvmet_execute_get_log_page_noop; in nvmet_parse_admin_cmd()
778 req->execute = nvmet_execute_get_log_page_smart; in nvmet_parse_admin_cmd()
787 req->execute = nvmet_execute_get_log_page_noop; in nvmet_parse_admin_cmd()
790 req->execute = nvmet_execute_get_log_changed_ns; in nvmet_parse_admin_cmd()
793 req->execute = nvmet_execute_get_log_cmd_effects_ns; in nvmet_parse_admin_cmd()
796 req->execute = nvmet_execute_get_log_page_ana; in nvmet_parse_admin_cmd()
801 req->data_len = NVME_IDENTIFY_DATA_SIZE; in nvmet_parse_admin_cmd()
802 switch (cmd->identify.cns) { in nvmet_parse_admin_cmd()
804 req->execute = nvmet_execute_identify_ns; in nvmet_parse_admin_cmd()
807 req->execute = nvmet_execute_identify_ctrl; in nvmet_parse_admin_cmd()
810 req->execute = nvmet_execute_identify_nslist; in nvmet_parse_admin_cmd()
813 req->execute = nvmet_execute_identify_desclist; in nvmet_parse_admin_cmd()
818 req->execute = nvmet_execute_abort; in nvmet_parse_admin_cmd()
819 req->data_len = 0; in nvmet_parse_admin_cmd()
822 req->execute = nvmet_execute_set_features; in nvmet_parse_admin_cmd()
823 req->data_len = 0; in nvmet_parse_admin_cmd()
826 req->execute = nvmet_execute_get_features; in nvmet_parse_admin_cmd()
827 req->data_len = 0; in nvmet_parse_admin_cmd()
830 req->execute = nvmet_execute_async_event; in nvmet_parse_admin_cmd()
831 req->data_len = 0; in nvmet_parse_admin_cmd()
834 req->execute = nvmet_execute_keep_alive; in nvmet_parse_admin_cmd()
835 req->data_len = 0; in nvmet_parse_admin_cmd()
839 pr_err("unhandled cmd %d on qid %d\n", cmd->common.opcode, in nvmet_parse_admin_cmd()
840 req->sq->qid); in nvmet_parse_admin_cmd()