* [PATCH v2 1/2] net: macb: call pm_runtime_put_sync on failure path
@ 2020-06-24 10:08 Claudiu Beznea
2020-06-24 10:08 ` [PATCH v2 2/2] net: macb: free resources on failure path of at91ether_open() Claudiu Beznea
2020-06-25 23:00 ` [PATCH v2 1/2] net: macb: call pm_runtime_put_sync on failure path David Miller
0 siblings, 2 replies; 4+ messages in thread
From: Claudiu Beznea @ 2020-06-24 10:08 UTC (permalink / raw)
To: nicolas.ferre, davem, kuba
Cc: alexandre.belloni, antoine.tenart, netdev, linux-kernel, Claudiu Beznea
Call pm_runtime_put_sync() on failure path of at91ether_open.
Fixes: e6a41c23df0d ("net: macb: ensure interface is not suspended on at91rm9200")
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
Changes in v2:
- this patch is new in v2
- patch 2/2 in this series is based on this one
drivers/net/ethernet/cadence/macb_main.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 67933079aeea..96d62d73b933 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -3835,7 +3835,7 @@ static int at91ether_open(struct net_device *dev)
ret = at91ether_start(dev);
if (ret)
- return ret;
+ goto pm_exit;
/* Enable MAC interrupts */
macb_writel(lp, IER, MACB_BIT(RCOMP) |
@@ -3848,11 +3848,15 @@ static int at91ether_open(struct net_device *dev)
ret = macb_phylink_connect(lp);
if (ret)
- return ret;
+ goto pm_exit;
netif_start_queue(dev);
return 0;
+
+pm_exit:
+ pm_runtime_put_sync(&lp->pdev->dev);
+ return ret;
}
/* Close the interface */
--
2.7.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] net: macb: free resources on failure path of at91ether_open()
2020-06-24 10:08 [PATCH v2 1/2] net: macb: call pm_runtime_put_sync on failure path Claudiu Beznea
@ 2020-06-24 10:08 ` Claudiu Beznea
2020-06-25 23:00 ` David Miller
2020-06-25 23:00 ` [PATCH v2 1/2] net: macb: call pm_runtime_put_sync on failure path David Miller
1 sibling, 1 reply; 4+ messages in thread
From: Claudiu Beznea @ 2020-06-24 10:08 UTC (permalink / raw)
To: nicolas.ferre, davem, kuba
Cc: alexandre.belloni, antoine.tenart, netdev, linux-kernel, Claudiu Beznea
DMA buffers were not freed on failure path of at91ether_open().
Along with changes for freeing the DMA buffers the enable/disable
interrupt instructions were moved to at91ether_start()/at91ether_stop()
functions and the operations on at91ether_stop() were done in
their reverse order (compared with how is done in at91ether_start()):
before this patch the operation order on interface open path
was as follows:
1/ alloc DMA buffers
2/ enable tx, rx
3/ enable interrupts
and the order on interface close path was as follows:
1/ disable tx, rx
2/ disable interrupts
3/ free dma buffers.
Fixes: 7897b071ac3b ("net: macb: convert to phylink")
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
Changes in v2:
- none
drivers/net/ethernet/cadence/macb_main.c | 116 +++++++++++++++++++------------
1 file changed, 73 insertions(+), 43 deletions(-)
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 96d62d73b933..87854dfb44e4 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -3760,15 +3760,9 @@ static int macb_init(struct platform_device *pdev)
static struct sifive_fu540_macb_mgmt *mgmt;
-/* Initialize and start the Receiver and Transmit subsystems */
-static int at91ether_start(struct net_device *dev)
+static int at91ether_alloc_coherent(struct macb *lp)
{
- struct macb *lp = netdev_priv(dev);
struct macb_queue *q = &lp->queues[0];
- struct macb_dma_desc *desc;
- dma_addr_t addr;
- u32 ctl;
- int i;
q->rx_ring = dma_alloc_coherent(&lp->pdev->dev,
(AT91ETHER_MAX_RX_DESCR *
@@ -3790,6 +3784,43 @@ static int at91ether_start(struct net_device *dev)
return -ENOMEM;
}
+ return 0;
+}
+
+static void at91ether_free_coherent(struct macb *lp)
+{
+ struct macb_queue *q = &lp->queues[0];
+
+ if (q->rx_ring) {
+ dma_free_coherent(&lp->pdev->dev,
+ AT91ETHER_MAX_RX_DESCR *
+ macb_dma_desc_get_size(lp),
+ q->rx_ring, q->rx_ring_dma);
+ q->rx_ring = NULL;
+ }
+
+ if (q->rx_buffers) {
+ dma_free_coherent(&lp->pdev->dev,
+ AT91ETHER_MAX_RX_DESCR *
+ AT91ETHER_MAX_RBUFF_SZ,
+ q->rx_buffers, q->rx_buffers_dma);
+ q->rx_buffers = NULL;
+ }
+}
+
+/* Initialize and start the Receiver and Transmit subsystems */
+static int at91ether_start(struct macb *lp)
+{
+ struct macb_queue *q = &lp->queues[0];
+ struct macb_dma_desc *desc;
+ dma_addr_t addr;
+ u32 ctl;
+ int i, ret;
+
+ ret = at91ether_alloc_coherent(lp);
+ if (ret)
+ return ret;
+
addr = q->rx_buffers_dma;
for (i = 0; i < AT91ETHER_MAX_RX_DESCR; i++) {
desc = macb_rx_desc(q, i);
@@ -3811,9 +3842,39 @@ static int at91ether_start(struct net_device *dev)
ctl = macb_readl(lp, NCR);
macb_writel(lp, NCR, ctl | MACB_BIT(RE) | MACB_BIT(TE));
+ /* Enable MAC interrupts */
+ macb_writel(lp, IER, MACB_BIT(RCOMP) |
+ MACB_BIT(RXUBR) |
+ MACB_BIT(ISR_TUND) |
+ MACB_BIT(ISR_RLE) |
+ MACB_BIT(TCOMP) |
+ MACB_BIT(ISR_ROVR) |
+ MACB_BIT(HRESP));
+
return 0;
}
+static void at91ether_stop(struct macb *lp)
+{
+ u32 ctl;
+
+ /* Disable MAC interrupts */
+ macb_writel(lp, IDR, MACB_BIT(RCOMP) |
+ MACB_BIT(RXUBR) |
+ MACB_BIT(ISR_TUND) |
+ MACB_BIT(ISR_RLE) |
+ MACB_BIT(TCOMP) |
+ MACB_BIT(ISR_ROVR) |
+ MACB_BIT(HRESP));
+
+ /* Disable Receiver and Transmitter */
+ ctl = macb_readl(lp, NCR);
+ macb_writel(lp, NCR, ctl & ~(MACB_BIT(TE) | MACB_BIT(RE)));
+
+ /* Free resources. */
+ at91ether_free_coherent(lp);
+}
+
/* Open the ethernet interface */
static int at91ether_open(struct net_device *dev)
{
@@ -3833,27 +3894,20 @@ static int at91ether_open(struct net_device *dev)
macb_set_hwaddr(lp);
- ret = at91ether_start(dev);
+ ret = at91ether_start(lp);
if (ret)
goto pm_exit;
- /* Enable MAC interrupts */
- macb_writel(lp, IER, MACB_BIT(RCOMP) |
- MACB_BIT(RXUBR) |
- MACB_BIT(ISR_TUND) |
- MACB_BIT(ISR_RLE) |
- MACB_BIT(TCOMP) |
- MACB_BIT(ISR_ROVR) |
- MACB_BIT(HRESP));
-
ret = macb_phylink_connect(lp);
if (ret)
- goto pm_exit;
+ goto stop;
netif_start_queue(dev);
return 0;
+stop:
+ at91ether_stop(lp);
pm_exit:
pm_runtime_put_sync(&lp->pdev->dev);
return ret;
@@ -3863,37 +3917,13 @@ static int at91ether_open(struct net_device *dev)
static int at91ether_close(struct net_device *dev)
{
struct macb *lp = netdev_priv(dev);
- struct macb_queue *q = &lp->queues[0];
- u32 ctl;
-
- /* Disable Receiver and Transmitter */
- ctl = macb_readl(lp, NCR);
- macb_writel(lp, NCR, ctl & ~(MACB_BIT(TE) | MACB_BIT(RE)));
-
- /* Disable MAC interrupts */
- macb_writel(lp, IDR, MACB_BIT(RCOMP) |
- MACB_BIT(RXUBR) |
- MACB_BIT(ISR_TUND) |
- MACB_BIT(ISR_RLE) |
- MACB_BIT(TCOMP) |
- MACB_BIT(ISR_ROVR) |
- MACB_BIT(HRESP));
netif_stop_queue(dev);
phylink_stop(lp->phylink);
phylink_disconnect_phy(lp->phylink);
- dma_free_coherent(&lp->pdev->dev,
- AT91ETHER_MAX_RX_DESCR *
- macb_dma_desc_get_size(lp),
- q->rx_ring, q->rx_ring_dma);
- q->rx_ring = NULL;
-
- dma_free_coherent(&lp->pdev->dev,
- AT91ETHER_MAX_RX_DESCR * AT91ETHER_MAX_RBUFF_SZ,
- q->rx_buffers, q->rx_buffers_dma);
- q->rx_buffers = NULL;
+ at91ether_stop(lp);
return pm_runtime_put(&lp->pdev->dev);
}
--
2.7.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] net: macb: call pm_runtime_put_sync on failure path
2020-06-24 10:08 [PATCH v2 1/2] net: macb: call pm_runtime_put_sync on failure path Claudiu Beznea
2020-06-24 10:08 ` [PATCH v2 2/2] net: macb: free resources on failure path of at91ether_open() Claudiu Beznea
@ 2020-06-25 23:00 ` David Miller
1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2020-06-25 23:00 UTC (permalink / raw)
To: claudiu.beznea
Cc: nicolas.ferre, kuba, alexandre.belloni, antoine.tenart, netdev,
linux-kernel
From: Claudiu Beznea <claudiu.beznea@microchip.com>
Date: Wed, 24 Jun 2020 13:08:17 +0300
> Call pm_runtime_put_sync() on failure path of at91ether_open.
>
> Fixes: e6a41c23df0d ("net: macb: ensure interface is not suspended on at91rm9200")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Applied and queued up for -stable.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] net: macb: free resources on failure path of at91ether_open()
2020-06-24 10:08 ` [PATCH v2 2/2] net: macb: free resources on failure path of at91ether_open() Claudiu Beznea
@ 2020-06-25 23:00 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2020-06-25 23:00 UTC (permalink / raw)
To: claudiu.beznea
Cc: nicolas.ferre, kuba, alexandre.belloni, antoine.tenart, netdev,
linux-kernel
From: Claudiu Beznea <claudiu.beznea@microchip.com>
Date: Wed, 24 Jun 2020 13:08:18 +0300
> DMA buffers were not freed on failure path of at91ether_open().
> Along with changes for freeing the DMA buffers the enable/disable
> interrupt instructions were moved to at91ether_start()/at91ether_stop()
> functions and the operations on at91ether_stop() were done in
> their reverse order (compared with how is done in at91ether_start()):
> before this patch the operation order on interface open path
> was as follows:
> 1/ alloc DMA buffers
> 2/ enable tx, rx
> 3/ enable interrupts
> and the order on interface close path was as follows:
> 1/ disable tx, rx
> 2/ disable interrupts
> 3/ free dma buffers.
>
> Fixes: 7897b071ac3b ("net: macb: convert to phylink")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Also applied and queued up for -stable.
Please submit a proper header posting "[PATCH 0/N] " in the future
when you submit a patch series. Thank you.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-06-25 23:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-24 10:08 [PATCH v2 1/2] net: macb: call pm_runtime_put_sync on failure path Claudiu Beznea
2020-06-24 10:08 ` [PATCH v2 2/2] net: macb: free resources on failure path of at91ether_open() Claudiu Beznea
2020-06-25 23:00 ` David Miller
2020-06-25 23:00 ` [PATCH v2 1/2] net: macb: call pm_runtime_put_sync on failure path David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®