Skip to contentSkip to conversation

net: fec: check DMA addressing limitations

PATCH Superseded Stefan Agner 2 participants 5 messages Aug 1, 2018 – Aug 2, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: fec: check DMA addressing limitations

Check DMA addressing limitations as suggested by the DMA API how-to. This does not fix a particular issue seen but is considered good style.

---
 drivers/net/ethernet/freescale/fec_main.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/freescale/fec_main.c +6 -0
index c729665107f5..af0fb200e936 100644
@@ -3146,6 +3146,12 @@ static int fec_enet_init(struct net_device *ndev)
 	fep->tx_align = 0x3;
 #endif
 
+	/* Check mask of the streaming and coherent API */
+	if (dma_set_mask_and_coherent(&fep->pdev->dev, DMA_BIT_MASK(32))) {
+		dev_warn(&fep->pdev->dev, "No suitable DMA available\n");
+		return -ENODEV;
+	}
+
 	fec_enet_alloc_queue(ndev);
 
 	bd_size = (fep->total_tx_ring_size + fep->total_rx_ring_size) * dsize;
Signature · 1 line
2.18.0
#1 lore raw

From: Stefan Agner <[email protected]> Sent: 2018年8月1日 19:45

Quoted 14 lines

Check DMA addressing limitations as suggested by the DMA API how-to. This does not fix a particular issue seen but is considered good style.

---
 drivers/net/ethernet/freescale/fec_main.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/freescale/fec_main.c +0 -0
index c729665107f5..af0fb200e936 100644

drivers/net/ethernet/freescale/fec_main.c static int fec_enet_init(struct net_device · line 3154

Quoted 9 lines
drivers/net/ethernet/freescale/fec_main.c +4 -0
@@ -3146,6 +3146,12 @@ static int fec_enet_init(struct net_device
 *ndev)
 	fep->tx_align = 0x3;
 #endif
 
+	/* Check mask of the streaming and coherent API */
+	if (dma_set_mask_and_coherent(&fep->pdev->dev,
 DMA_BIT_MASK(32))) {
+		dev_warn(&fep->pdev->dev, "No suitable DMA available\n");
+		return -ENODEV;

It is better:

ret = dma_set_mask_and_coherent(&fep->pdev->dev, DMA_BIT_MASK(32));

if (ret < 0) {
	dev_warn(&fep->pdev->dev, "No suitable DMA available\n");
	return ret;
}

If the patch aim to "OF: Don't set default coherent DMA mask", I think not only this driver need to add the DMA mask limitations, many other drivers also need.

Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c +2 -0
+	}
+
 	fec_enet_alloc_queue(ndev);

bd_size = (fep->total_tx_ring_size + fep->total_rx_ring_size) * dsize;
--
2.18.0

#2 lore raw
Quoted 26 lines · Andy Duan

From: Stefan Agner <[email protected]> Sent: 2018年8月1日 19:45

Quoted 14 lines

Check DMA addressing limitations as suggested by the DMA API how-to. This does not fix a particular issue seen but is considered good style.

---
 drivers/net/ethernet/freescale/fec_main.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/freescale/fec_main.c +0 -0
index c729665107f5..af0fb200e936 100644

drivers/net/ethernet/freescale/fec_main.c static int fec_enet_init(struct net_device · line 3154

Quoted 9 lines
drivers/net/ethernet/freescale/fec_main.c +4 -0
@@ -3146,6 +3146,12 @@ static int fec_enet_init(struct net_device
 *ndev)
 	fep->tx_align = 0x3;
 #endif
 
+	/* Check mask of the streaming and coherent API */
+	if (dma_set_mask_and_coherent(&fep->pdev->dev,
 DMA_BIT_MASK(32))) {
+		dev_warn(&fep->pdev->dev, "No suitable DMA available\n");
+		return -ENODEV;

It is better:

Quoted 5 lines

ret = dma_set_mask_and_coherent(&fep->pdev->dev, DMA_BIT_MASK(32));

if (ret < 0) {
	dev_warn(&fep->pdev->dev, "No suitable DMA available\n");
	return ret;
}

The code comes from the example in Documentation/DMA-API-HOWTO.txt.

I can rearrange if you prefer.

Quoted 5 lines

If the patch aim to "OF: Don't set default coherent DMA mask", I think not only this driver need to add the DMA mask limitations, many other drivers also need.

It doesn't exactly address the issue since with that patch DMA mask wasn't set at all. This code would just make the driver fail with -ENODEV instead of -ENOMEM.

To force a DMA mask I would have to set the DMA mask using dma_coerce_mask_and_coherent(). But as discussed with Robin it is safe to assume that an initial mask is set by the bus code:
http://lkml.kernel.org/r/[email protected]

Setting the DMA mask on DT buses has been addressed by Robin with "of/platform: Initialise default DMA masks". So everything should be fine again.

I agree, other drivers need fixing too.

--
Stefan

Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/freescale/fec_main.c +2 -0
+	}
+
 	fec_enet_alloc_queue(ndev);

bd_size = (fep->total_tx_ring_size + fep->total_rx_ring_size) * dsize;
--
2.18.0

#3 lore raw

From: Stefan Agner <[email protected]> Sent: 2018年8月2日 15:16

Quoted 35 lines · Andy Duan
Quoted 19 lines

From: Stefan Agner <[email protected]> Sent: 2018年8月1日 19:45

Quoted 18 lines

Check DMA addressing limitations as suggested by the DMA API how-to. This does not fix a particular issue seen but is considered good style.

---
 drivers/net/ethernet/freescale/fec_main.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/freescale/fec_main.c +0 -0
index c729665107f5..af0fb200e936 100644
@@ -3146,6 +3146,12 @@ static int fec_enet_init(struct net_device
 *ndev)
 	fep->tx_align = 0x3;
 #endif
 
Quoted 4 lines

drivers/net/ethernet/freescale/fec_main.c static int fec_enet_init(struct net_device · line 3153

Quoted 4 lines
drivers/net/ethernet/freescale/fec_main.c +3 -0
+	/* Check mask of the streaming and coherent API */
+	if (dma_set_mask_and_coherent(&fep->pdev->dev,
 DMA_BIT_MASK(32))) {
+		dev_warn(&fep->pdev->dev, "No suitable DMA

available\n");

Quoted 4 lines

drivers/net/ethernet/freescale/fec_main.c static int fec_enet_init(struct net_device *ndev) · line 3152

Quoted 1 line
drivers/net/ethernet/freescale/fec_main.c +1 -0
+		return -ENODEV;

It is better:

ret = dma_set_mask_and_coherent(&fep->pdev->dev,

DMA_BIT_MASK(32)); if

Quoted 4 lines
(ret < 0) {
	dev_warn(&fep->pdev->dev, "No suitable DMA available\n");
	return ret;
}
Quoted 5 lines

The code comes from the example in
Documentation/DMA-API-HOWTO.txt.

I can rearrange if you prefer.

It is better to return the real error code like -EIO if dma_mask is not initialized.

Quoted 10 lines
Quoted 5 lines

If the patch aim to "OF: Don't set default coherent DMA mask", I think not only this driver need to add the DMA mask limitations, many other drivers also need.

It doesn't exactly address the issue since with that patch DMA mask wasn't set at all. This code would just make the driver fail with -ENODEV instead of -ENOMEM.

Yes, I agree. It doesn't address the issue if no patch "of/platform: Initialise default DMA masks".

For non-DT, it seems dma_coerce_mask_and_coherent() much better.

Quoted 10 lines

To force a DMA mask I would have to set the DMA mask using dma_coerce_mask_and_coherent(). But as discussed with Robin it is safe to assume that an initial mask is set by the bus code:
https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flk
ml.kernel.org%2Fr%2F892f9d14-e6fd-7b1b-d07b-af0be6e623fa%40arm.c om&amp;data=02%7C01%7Cfugang.duan%40nxp.com%7C618543fb9b4e 4f9fa49908d5f847c47f%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0% 7C0%7C636687909487381876&amp;sdata=hyeeh0KSC3Fu7VDl4A8JbcCO %2FwocUpTEMvTv1hjba0E%3D&amp;reserved=0

Quoted 4 lines

Setting the DMA mask on DT buses has been addressed by Robin with "of/platform: Initialise default DMA masks". So everything should be fine again.

Anyway, I am fine with the patch except the return code. Thanks.

Quoted 15 lines

I agree, other drivers need fixing too.

--
Stefan

Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +2 -0
+	}
+
 	fec_enet_alloc_queue(ndev);

bd_size = (fep->total_tx_ring_size + fep->total_rx_ring_size) *
dsize;
--
2.18.0

#4 lore raw
Quoted 36 lines · Andy Duan

From: Stefan Agner <[email protected]> Sent: 2018年8月2日 15:16

Quoted 35 lines · Andy Duan
Quoted 19 lines

From: Stefan Agner <[email protected]> Sent: 2018年8月1日 19:45

Quoted 18 lines

Check DMA addressing limitations as suggested by the DMA API how-to. This does not fix a particular issue seen but is considered good style.

---
 drivers/net/ethernet/freescale/fec_main.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/freescale/fec_main.c +0 -0
index c729665107f5..af0fb200e936 100644
@@ -3146,6 +3146,12 @@ static int fec_enet_init(struct net_device
 *ndev)
 	fep->tx_align = 0x3;
 #endif
 
Quoted 4 lines

drivers/net/ethernet/freescale/fec_main.c static int fec_enet_init(struct net_device · line 3153

Quoted 4 lines
drivers/net/ethernet/freescale/fec_main.c +3 -0
+	/* Check mask of the streaming and coherent API */
+	if (dma_set_mask_and_coherent(&fep->pdev->dev,
 DMA_BIT_MASK(32))) {
+		dev_warn(&fep->pdev->dev, "No suitable DMA

available\n");

Quoted 4 lines

drivers/net/ethernet/freescale/fec_main.c static int fec_enet_init(struct net_device *ndev) · line 3152

Quoted 1 line
drivers/net/ethernet/freescale/fec_main.c +1 -0
+		return -ENODEV;

It is better:

ret = dma_set_mask_and_coherent(&fep->pdev->dev,

DMA_BIT_MASK(32)); if

Quoted 4 lines
(ret < 0) {
	dev_warn(&fep->pdev->dev, "No suitable DMA available\n");
	return ret;
}
Quoted 7 lines
Quoted 5 lines

The code comes from the example in
Documentation/DMA-API-HOWTO.txt.

I can rearrange if you prefer.

It is better to return the real error code like -EIO if dma_mask is not initialized.

Good point. Will send a v2.

--
Stefan

Quoted 48 lines
Quoted 11 lines
Quoted 6 lines

If the patch aim to "OF: Don't set default coherent DMA mask", I think not only this driver need to add the DMA mask limitations, many other drivers also need.

It doesn't exactly address the issue since with that patch DMA mask wasn't set at all. This code would just make the driver fail with -ENODEV instead of -ENOMEM.

Yes, I agree. It doesn't address the issue if no patch "of/platform:
Initialise default DMA masks".

For non-DT, it seems dma_coerce_mask_and_coherent() much better.

Quoted 10 lines

To force a DMA mask I would have to set the DMA mask using dma_coerce_mask_and_coherent(). But as discussed with Robin it is safe to assume that an initial mask is set by the bus code:
https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flk
ml.kernel.org%2Fr%2F892f9d14-e6fd-7b1b-d07b-af0be6e623fa%40arm.c om&amp;data=02%7C01%7Cfugang.duan%40nxp.com%7C618543fb9b4e 4f9fa49908d5f847c47f%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0% 7C0%7C636687909487381876&amp;sdata=hyeeh0KSC3Fu7VDl4A8JbcCO %2FwocUpTEMvTv1hjba0E%3D&amp;reserved=0

Quoted 4 lines

Setting the DMA mask on DT buses has been addressed by Robin with "of/platform: Initialise default DMA masks". So everything should be fine again.

Anyway, I am fine with the patch except the return code. Thanks.

Quoted 15 lines

I agree, other drivers need fixing too.

--
Stefan

Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +2 -0
+	}
+
 	fec_enet_alloc_queue(ndev);

bd_size = (fep->total_tx_ring_size + fep->total_rx_ring_size) *
dsize;
--
2.18.0