> From: Janne Grunau <[email protected]>
> Date: Fri, 04 Sep 2026 21:22:39 +0200
> 
> Setting the DMA direction for commands that don't do any transfer likely
> triggered the PRP NULL check for which we needed a chicken bit. That bit
> has disappeared starting with macOS 15 so let's just do this correctly
> instead.
> 
> Based on Linux kernel commit 94dd5804938d ("nvme-apple: Don't set a DMA
> direction for commands without a data transfer").

It is probably best to keep this aligned with Linux.  However, on
OpenBSD I set the bits based on the low two bits of the opcode.  Like:

        if (cmd->common.opcode & nvme_cmd_write)
                tcb->flags |= ANS_NVMMU_TCB_READ;
        if (cmd->common.opcode & nvme_cmd_read)
                tcb->flags |= ANS_NVMMU_TCB_WRITE;

(the directions are reversed as the commands are memory -> device
whereas the NVMMU bits are device -> memory).

The NVMe commands are documented like this.  I believe, there aren't
actually any commands that do both a read and a write.  But this would
do the right thing if they ever show up.

Anyway:

Reviewed-by: Mark Kettenis <[email protected]>


> Link: 
> https://lore.kernel.org/asahi/[email protected]/
> Fixes: 50333c94f2de ("nvme: apple: Add driver for Apple NVMe storage 
> controller")
> Signed-off-by: Janne Grunau <[email protected]>
> ---
>  drivers/nvme/nvme_apple.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/nvme/nvme_apple.c b/drivers/nvme/nvme_apple.c
> index e674eda8344..dc94988e2ff 100644
> --- a/drivers/nvme/nvme_apple.c
> +++ b/drivers/nvme/nvme_apple.c
> @@ -122,7 +122,10 @@ static void apple_nvme_submit_cmd(struct nvme_queue 
> *nvmeq,
>       tcb = ((void *)priv->tcbs[nvmeq->qid]) + tail * ANS_NVMMU_TCB_PITCH;
>       memset(tcb, 0, sizeof(*tcb));
>       tcb->opcode = cmd->common.opcode;
> -     tcb->flags = ANS_NVMMU_TCB_WRITE | ANS_NVMMU_TCB_READ;
> +     if (cmd->common.prp1)
> +             tcb->flags = ANS_NVMMU_TCB_WRITE | ANS_NVMMU_TCB_READ;
> +     else
> +             tcb->flags = 0;
>       tcb->slot = tail;
>       tcb->prpl_len = cmd->rw.length;
>       tcb->prp1 = cmd->common.prp1;
> 
> -- 
> 2.55.0
> 
> 

Reply via email to