[PATCH] nvme-pci: ignore bogus CRTO according to NVME 2.0 spec

Felix Yan felixonmars at archlinux.org
Mon Sep 11 23:26:19 PDT 2023


On 9/12/23 02:00, Keith Busch wrote:
> What do you think about this change instead? We don't need to print a
> warning on every device reset, but we should probably add a comment
> explaining why this is happening.
> 
> ---
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 37b6fa7466620..b4577a860e677 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2245,6 +2245,7 @@ int nvme_enable_ctrl(struct nvme_ctrl *ctrl)
>   	else
>   		ctrl->ctrl_config = NVME_CC_CSS_NVM;
>   
> +	timeout = NVME_CAP_TIMEOUT(ctrl->cap);
>   	if (ctrl->cap & NVME_CAP_CRMS_CRWMS) {
>   		u32 crto;
>   
> @@ -2257,12 +2258,15 @@ int nvme_enable_ctrl(struct nvme_ctrl *ctrl)
>   
>   		if (ctrl->cap & NVME_CAP_CRMS_CRIMS) {
>   			ctrl->ctrl_config |= NVME_CC_CRIME;
> -			timeout = NVME_CRTO_CRIMT(crto);
> +			/*
> +			 * CRIMT should always be greater or equal to CAP.TO,
> +			 * but some devices are known to get this wrong. Use
> +			 * the larger of the two values.
> +			 */
> +			timeout = max(timeout, NVME_CRTO_CRIMT(crto));
>   		} else {
>   			timeout = NVME_CRTO_CRWMT(crto);
>   		}
> -	} else {
> -		timeout = NVME_CAP_TIMEOUT(ctrl->cap);
>   	}
>   
>   	ctrl->ctrl_config |= (NVME_CTRL_PAGE_SHIFT - 12) << NVME_CC_MPS_SHIFT;

I'm fine either way.

Should we also apply the same max() on the NVME_CRTO_CRIMT branch 
though? The spec actually says the same thing (Timeout should be FFh) 
for that too.

-- 
Regards,
Felix Yan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-nvme/attachments/20230912/fc766e38/attachment.sig>


More information about the Linux-nvme mailing list