[PATCH v6 08/18] nvme: Implement cross-controller reset recovery
Daniel Wagner
dwagner at suse.de
Tue Oct 20 01:55:10 PDT 2026
> +static int nvme_issue_wait_ccr(struct nvme_ctrl *sctrl, struct nvme_ctrl *ictrl,
> + unsigned long deadline)
> +{
> + struct nvme_ccr_entry ccr = { };
> + union nvme_result res = { 0 };
> + struct nvme_command c = { };
> + unsigned long flags, now, tmo = 0;
> + bool completed = false;
> + int ret = 0;
> + u32 result;
> +
> + init_completion(&ccr.complete);
> + ccr.ictrl = ictrl;
> +
> + spin_lock_irqsave(&sctrl->lock, flags);
> + list_add_tail(&ccr.list, &sctrl->ccr_list);
> + spin_unlock_irqrestore(&sctrl->lock, flags);
> +
> + c.ccr.opcode = nvme_admin_cross_ctrl_reset;
> + c.ccr.ciu = ictrl->ciu;
> + c.ccr.icid = cpu_to_le16(ictrl->cntlid);
> + c.ccr.cirn = cpu_to_le64(ictrl->cirn);
> + ret = __nvme_submit_sync_cmd(sctrl->admin_q, &c, &res,
> + NULL, 0, NVME_QID_ANY, 0);
> + if (ret) {
> + ret = -EIO;
> + goto out;
> + }
> +
> + result = le32_to_cpu(res.u32);
> + if (result & 0x01) /* Immediate Reset Successful */
> + goto out;
> +
> + now = jiffies;
> + if (time_before(now, deadline))
> + tmo = min_t(unsigned long,
> + secs_to_jiffies(ictrl->kato), deadline - now);
> +
> + if (!wait_for_completion_timeout(&ccr.complete, tmo)) {
> + ret = -ETIMEDOUT;
> + goto out;
> + }
> +
> + completed = true;
> +
> +out:
> + spin_lock_irqsave(&sctrl->lock, flags);
> + list_del(&ccr.list);
> + spin_unlock_irqrestore(&sctrl->lock, flags);
> + if (completed) {
> + if (ccr.ccrs == NVME_CCR_STATUS_SUCCESS)
> + return 0;
> + return -EREMOTEIO;
> + }
> + return ret;
This part could be made a bit simpler and there is no need for the local
completed variable:
[...]
if (!wait_for_completion_timeout(&ccr.complete, tmo))
ret = -ETIMEDOUT;
out:
spin_lock_irqsave(&sctrl->lock, flags);
list_del(&ccr.list);
spin_unlock_irqrestore(&sctrl->lock, flags);
if (ret || !completion_done(&ccr.complete))
return ret;
if (ccr.ccrs == NVME_CCR_STATUS_SUCCESS)
return 0;
return -EREMOTEIO;
}
More information about the Linux-nvme
mailing list