imx.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Frank Li <Frank.Li@nxp.com>
To: manivannan.sadhasivam@linaro.org, imx@lists.linux.dev
Cc: Frank.Li@nxp.com, arnd@arndb.de, cassel@kernel.org,
	gregkh@linuxfoundation.org, kishon@kernel.org, kw@linux.com,
	linux-pci@vger.kernel.org
Subject: [PATCH v2 1/1] misc: pci_endpoint_test: Refactor dma_set_mask_and_coherent() logic
Date: Thu,  2 May 2024 15:59:03 -0400	[thread overview]
Message-ID: <20240502195903.3191049-1-Frank.Li@nxp.com> (raw)

dma_set_mask_and_coherent() should never fail when the mask is >= 32bit,
unless the architecture has no DMA support. So no need check for the error
and also no need to set dma_set_mask_and_coherent(32) as a fallback.

Even if dma_set_mask_and_coherent(48) fails due to the lack of DMA support
(theoretically), then dma_set_mask_and_coherent(32) will also fail for the
same reason. So the fallback doesn't make sense.

Due to the above reasons, let's simplify the code by setting the streaming
and coherent DMA mask to 48 bits.

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---

Notes:
    Change from v1 to v2:
    - Rework commit message according to mani's feedback.
    - Not sure why set to 48bit at original patch.
    
    Ref: https://lore.kernel.org/linux-pci/20240328154827.809286-1-Frank.Li@nxp.com/T/#u
    
    for document change patch. DMA document sample code is miss leading.
    fixed patch already accepted:
    https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=f7ae20f2fc4e6a5e32f43c4fa2acab3281a61c81

 drivers/misc/pci_endpoint_test.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index c38a6083f0a73..56ac6969a8f59 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -824,11 +824,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 	init_completion(&test->irq_raised);
 	mutex_init(&test->mutex);
 
-	if ((dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48)) != 0) &&
-	    dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
-		dev_err(dev, "Cannot set DMA mask\n");
-		return -EINVAL;
-	}
+	dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48));
 
 	err = pci_enable_device(pdev);
 	if (err) {
-- 
2.34.1


             reply	other threads:[~2024-05-02 19:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-02 19:59 Frank Li [this message]
2024-05-07  7:48 ` [PATCH v2 1/1] misc: pci_endpoint_test: Refactor dma_set_mask_and_coherent() logic Niklas Cassel
2024-05-17 10:03 ` Krzysztof Wilczyński

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240502195903.3191049-1-Frank.Li@nxp.com \
    --to=frank.li@nxp.com \
    --cc=arnd@arndb.de \
    --cc=cassel@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=imx@lists.linux.dev \
    --cc=kishon@kernel.org \
    --cc=kw@linux.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).