From patchwork Thu Aug 19 12:56:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Reimar_D=C3=B6ffinger?= X-Patchwork-Id: 1518663 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ide-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Gr4XL3r6Jz9sVw for ; Thu, 19 Aug 2021 22:56:34 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230505AbhHSM5J (ORCPT ); Thu, 19 Aug 2021 08:57:09 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:57697 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbhHSM5J (ORCPT ); Thu, 19 Aug 2021 08:57:09 -0400 Received: from localhost ([98.128.181.94]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MGi6k-1mKZSn4BTW-00Dr8B; Thu, 19 Aug 2021 14:56:24 +0200 From: =?utf-8?q?Reimar_D=C3=B6ffinger?= To: Damien Le Moal , linux-ide@vger.kernel.org, Jens Axboe , hch@infradead.org Subject: [PATCH] libata: fix checking of DMA state Date: Thu, 19 Aug 2021 14:56:23 +0200 Message-Id: <20210819125623.22059-1-Reimar.Doeffinger@gmx.de> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210819081340.4362-1-Reimar.Doeffinger@gmx.de> References: <20210819081340.4362-1-Reimar.Doeffinger@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:raIt20G29od/WIa2awOwv6xo90JFrXiAICAiqZrvI2f5OoCPuai dBsdnC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RBWDs9ErToBaxqaR04nJlEAJFJg36HttBmXcmVPAFJwdgLAzWKYECQishRD1y LVshRq8a3gWkH7nlcs8A== Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org Checking if DMA is enabled should be done via the ata_dma_enabled helper function, since the init state 0xff indicates disabled. Only the libata-core logic is tested on actual devices, the other changes are based on code review only. --- Changes v3: - found and updated more cases in pata_ali, pata_amd and pata_radisys. Changes v2: - removed initialization change for SATA. I got confused by the ping-pong between libata-eh and libata-core and thought SATA did not set up xfermode - reviewed other cases that used dma_mode in boolean context and those seemed to need changing as well, so added them to patch. I did not see any places that would set dma_mode to 0 ever, so I do think they were all indeed wrong. drivers/ata/libata-core.c | 2 +- drivers/ata/libata-scsi.c | 4 ++-- drivers/ata/pata_ali.c | 4 ++-- drivers/ata/pata_amd.c | 2 +- drivers/ata/pata_optidma.c | 4 ++-- drivers/ata/pata_radisys.c | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 9934f6c465f4..52469b39d424 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2004,7 +2004,7 @@ unsigned int ata_read_log_page(struct ata_device *dev, u8 log, retry: ata_tf_init(dev, &tf); - if (dev->dma_mode && ata_id_has_read_log_dma_ext(dev->id) && + if (ata_dma_enabled(dev) && ata_id_has_read_log_dma_ext(dev->id) && !(dev->horkage & ATA_HORKAGE_NO_DMA_LOG)) { tf.command = ATA_CMD_READ_LOG_DMA_EXT; tf.protocol = ATA_PROT_DMA; diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index b9588c52815d..9e51251161e9 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -3023,7 +3023,7 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) ata_qc_set_pc_nbytes(qc); /* We may not issue DMA commands if no DMA mode is set */ - if (tf->protocol == ATA_PROT_DMA && dev->dma_mode == 0) { + if (tf->protocol == ATA_PROT_DMA && !ata_dma_enabled(dev)) { fp = 1; goto invalid_fld; } @@ -3173,7 +3173,7 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc) u8 unmap = cdb[1] & 0x8; /* we may not issue DMA commands if no DMA mode is set */ - if (unlikely(!dev->dma_mode)) + if (unlikely(!ata_dma_enabled(dev))) goto invalid_opcode; /* diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c index 557ecf466102..b7ff63ed3bbb 100644 --- a/drivers/ata/pata_ali.c +++ b/drivers/ata/pata_ali.c @@ -215,7 +215,7 @@ static void ali_set_piomode(struct ata_port *ap, struct ata_device *adev) struct ata_timing p; ata_timing_compute(pair, pair->pio_mode, &p, T, 1); ata_timing_merge(&p, &t, &t, ATA_TIMING_SETUP|ATA_TIMING_8BIT); - if (pair->dma_mode) { + if (ata_dma_enabled(pair)) { ata_timing_compute(pair, pair->dma_mode, &p, T, 1); ata_timing_merge(&p, &t, &t, ATA_TIMING_SETUP|ATA_TIMING_8BIT); } @@ -264,7 +264,7 @@ static void ali_set_dmamode(struct ata_port *ap, struct ata_device *adev) struct ata_timing p; ata_timing_compute(pair, pair->pio_mode, &p, T, 1); ata_timing_merge(&p, &t, &t, ATA_TIMING_SETUP|ATA_TIMING_8BIT); - if (pair->dma_mode) { + if (ata_dma_enabled(pair)) { ata_timing_compute(pair, pair->dma_mode, &p, T, 1); ata_timing_merge(&p, &t, &t, ATA_TIMING_SETUP|ATA_TIMING_8BIT); } diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c index c8acba162d02..154748cfcc79 100644 --- a/drivers/ata/pata_amd.c +++ b/drivers/ata/pata_amd.c @@ -66,7 +66,7 @@ static void timing_setup(struct ata_port *ap, struct ata_device *adev, int offse if (peer) { /* This may be over conservative */ - if (peer->dma_mode) { + if (ata_dma_enabled(peer)) { ata_timing_compute(peer, peer->dma_mode, &apeer, T, UT); ata_timing_merge(&apeer, &at, &at, ATA_TIMING_8BIT); } diff --git a/drivers/ata/pata_optidma.c b/drivers/ata/pata_optidma.c index f6278d9de348..ad1090b90e52 100644 --- a/drivers/ata/pata_optidma.c +++ b/drivers/ata/pata_optidma.c @@ -153,7 +153,7 @@ static void optidma_mode_setup(struct ata_port *ap, struct ata_device *adev, u8 if (pair) { u8 pair_addr; /* Hardware constraint */ - if (pair->dma_mode) + if (ata_dma_enabled(pair)) pair_addr = 0; else pair_addr = addr_timing[pci_clock][pair->pio_mode - XFER_PIO_0]; @@ -301,7 +301,7 @@ static u8 optidma_make_bits43(struct ata_device *adev) }; if (!ata_dev_enabled(adev)) return 0; - if (adev->dma_mode) + if (ata_dma_enabled(adev)) return adev->dma_mode - XFER_MW_DMA_0; return bits43[adev->pio_mode - XFER_PIO_0]; } diff --git a/drivers/ata/pata_radisys.c b/drivers/ata/pata_radisys.c index 8fde4a86401b..3aca8fe3fdb6 100644 --- a/drivers/ata/pata_radisys.c +++ b/drivers/ata/pata_radisys.c @@ -172,8 +172,8 @@ static unsigned int radisys_qc_issue(struct ata_queued_cmd *qc) if (adev != ap->private_data) { /* UDMA timing is not shared */ - if (adev->dma_mode < XFER_UDMA_0) { - if (adev->dma_mode) + if (adev->dma_mode < XFER_UDMA_0 || !ata_dma_enabled(adev)) { + if (ata_dma_enabled(adev)) radisys_set_dmamode(ap, adev); else if (adev->pio_mode) radisys_set_piomode(ap, adev);