From nobody Sun Feb 8 19:53:16 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 416CA130E27; Sun, 8 Sep 2024 09:46:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725788795; cv=none; b=JBHb4k/VGuLXM1xeldYk6RoGACQx/FzTmrZNsVd9xmA5uCcJFNiwqRIR89Q7Gs9q+FuOMT5mTZFHkYssf638tnBBRL6MS8GxkfvqVT4VF9MgLUzccr2wHXpLdcmIolyV/nmifj0SWZRF8CSKNJxVuBXMpU6QMlaxEYr3JXmGJ+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725788795; c=relaxed/simple; bh=HPB6S1zTcBrTniRyCdi2PB/DUIQzNIeGo660PwAq+C4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=RxdUm59iMvw7r/YZquxo4qkmHEZL015M4ZUgOJHV5FpR3J3QOCCyJPm2Rn0AYCZj7eoz8Wp70Z4gSCxD24XlMBBNfZVuy8O+pGjiFS83zev0YeKSE2ouRow3MDlXP1kG3y9ARGnK8nHo8qKp1qeHxMOdCY0cjwvK+yqkCQEBTdo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C145EC4CEC3; Sun, 8 Sep 2024 09:46:32 +0000 (UTC) From: Huacai Chen To: Damien Le Moal , Niklas Cassel Cc: linux-ide@vger.kernel.org, Huacai Chen , Xuerui Wang , Jiaxun Yang , linux-kernel@vger.kernel.org, Huacai Chen Subject: [PATCH] ahci: Marvell controllers prefer DMA for ATAPI Date: Sun, 8 Sep 2024 17:46:04 +0800 Message-ID: <20240908094604.433035-1-chenhuacai@loongson.cn> X-Mailer: git-send-email 2.43.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We use Marvell CD/DVD controllers on many Loongson-based machines. We found its PIO doesn't work well, and on the opposite its DMA seems work very well. We don't know the detail of the controller, but we can set the ATA_FLAG_ATAPI_DMA and ATA_HORKAGE_ATAPI_MOD16_DMA flags on these controllers to prefer ATAPI DMA. BTW, return -EOPNOTSUPP instead of 1 if ATAPI DMA is not supported in atapi_check_dma(). Signed-off-by: Huacai Chen Reported-by: WangYuli Tested-by: Erpeng Xu Tested-by: Jie Fan Tested-by: WangYuli --- drivers/ata/ahci.c | 3 +++ drivers/ata/libata-core.c | 6 +++++- include/linux/libata.h | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index a05c17249448..b195e87e7109 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c @@ -1939,6 +1939,9 @@ static int ahci_init_one(struct pci_dev *pdev, const = struct pci_device_id *ent) if (hpriv->cap & HOST_CAP_PMP) pi.flags |=3D ATA_FLAG_PMP; =20 + if (pdev->vendor =3D=3D PCI_VENDOR_ID_MARVELL_EXT) + pi.flags |=3D ATA_FLAG_ATAPI_DMA; + ahci_set_em_messages(hpriv, &pi); =20 if (ahci_broken_system_poweroff(pdev)) { diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 30932552437a..49d7d064f31b 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -3040,6 +3040,10 @@ int ata_dev_configure(struct ata_device *dev) dev->max_sectors =3D ATA_MAX_SECTORS; } =20 + if ((dev->class =3D=3D ATA_DEV_ATAPI) && + (ap->flags & ATA_FLAG_ATAPI_DMA)) + dev->horkage |=3D ATA_HORKAGE_ATAPI_MOD16_DMA; + if ((dev->class =3D=3D ATA_DEV_ATAPI) && (atapi_command_packet_set(id) =3D=3D TYPE_TAPE)) { dev->max_sectors =3D ATA_MAX_SECTORS_TAPE; @@ -4590,7 +4594,7 @@ int atapi_check_dma(struct ata_queued_cmd *qc) */ if (!(qc->dev->horkage & ATA_HORKAGE_ATAPI_MOD16_DMA) && unlikely(qc->nbytes & 15)) - return 1; + return -EOPNOTSUPP; =20 if (ap->ops->check_atapi_dma) return ap->ops->check_atapi_dma(qc); diff --git a/include/linux/libata.h b/include/linux/libata.h index 17394098bee9..e2834c7564df 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -154,6 +154,7 @@ enum { /* (doesn't imply presence) */ ATA_FLAG_SATA =3D (1 << 1), ATA_FLAG_NO_LPM =3D (1 << 2), /* host not happy with LPM */ + ATA_FLAG_ATAPI_DMA =3D (1 << 4), /* ATAPI use DMA */ ATA_FLAG_NO_LOG_PAGE =3D (1 << 5), /* do not issue log page read */ ATA_FLAG_NO_ATAPI =3D (1 << 6), /* No ATAPI support */ ATA_FLAG_PIO_DMA =3D (1 << 7), /* PIO cmds via DMA */ --=20 2.43.5