[RFC 1/6] s390/ism: Set DMA coherent mask

Niklas Schnelle posted 6 patches 3 years, 5 months ago
There is a newer version of this series
[RFC 1/6] s390/ism: Set DMA coherent mask
Posted by Niklas Schnelle 3 years, 5 months ago
A future change will convert the DMA API implementation from the
architecture specific arch/s390/pci/pci_dma.c to using the common code
drivers/iommu/dma-iommu.c which the utilizes the same IOMMU hardware
through the s390-iommu driver. Unlike the s390 specific DMA API this
requires devices to correctly call dma_set_coherent_mask() to be allowed
to use IOVAs >2^32 in dma_alloc_coherent(). This was however not done
for ISM devices which require such addresses since currently the DMA
aperture for PCI devices starts a 2^32 and all calls to
dma_alloc_coherent() would thus fail.

Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
 drivers/s390/net/ism_drv.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/s390/net/ism_drv.c b/drivers/s390/net/ism_drv.c
index d34bb6ec1490..5890c32a9e1f 100644
--- a/drivers/s390/net/ism_drv.c
+++ b/drivers/s390/net/ism_drv.c
@@ -560,6 +560,10 @@ static int ism_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (ret)
 		goto err_resource;
 
+	ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
+	if (ret)
+		goto err_resource;
+
 	dma_set_seg_boundary(&pdev->dev, SZ_1M - 1);
 	dma_set_max_seg_size(&pdev->dev, SZ_1M);
 	pci_set_master(pdev);
-- 
2.34.1
Re: [RFC 1/6] s390/ism: Set DMA coherent mask
Posted by Christoph Hellwig 3 years, 5 months ago
On Wed, Oct 19, 2022 at 04:44:30PM +0200, Niklas Schnelle wrote:
>  	if (ret)
>  		goto err_resource;
>  
> +	ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));

Nit:  but you could also just replace the call to dma_set_mask abobe with
a call to dma_set_mask_and_coherent.
Re: [RFC 1/6] s390/ism: Set DMA coherent mask
Posted by Niklas Schnelle 3 years, 5 months ago
On Thu, 2022-10-20 at 01:07 -0700, Christoph Hellwig wrote:
> On Wed, Oct 19, 2022 at 04:44:30PM +0200, Niklas Schnelle wrote:
> >  	if (ret)
> >  		goto err_resource;
> >  
> > +	ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
> 
> Nit:  but you could also just replace the call to dma_set_mask abobe with
> a call to dma_set_mask_and_coherent.

That makes sense, thanks. Will be added for v2. Also obviously this
change is only a prerequisite and could be applied separately, the
changed coherent mask won't affect use with the existing DMA
implementation.