mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/6] fsl-fman patches
@ 2019-11-14 13:00 Sascha Hauer
  2019-11-14 13:00 ` [PATCH 1/6] net: fsl-fman: reset device before leaving Sascha Hauer
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Sascha Hauer @ 2019-11-14 13:00 UTC (permalink / raw)
  To: Barebox List

This series contains some patches for the fsl-fman ethernet controller.
Most important is the first one which makes the controller work when
barebox is started second stage from another barebox. The other patches
are some cleanups I stumbled upon while searching for the issue.

Sascha

Sascha Hauer (6):
  net: fsl-fman: reset device before leaving
  net: fsl-fman: Store index for txbd
  net: fsl-fman: move status read into loop
  net: fsl-fman: Store index for rxbd
  net: fsl-fman: simplify setting next offset
  net: fsl-fman: do not leave not transmitted DMA buffers mapped

 drivers/net/fsl-fman.c     | 90 +++++++++++++++++++++-----------------
 include/soc/fsl/fsl_fman.h |  3 ++
 2 files changed, 53 insertions(+), 40 deletions(-)

-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/6] net: fsl-fman: reset device before leaving
  2019-11-14 13:00 [PATCH 0/6] fsl-fman patches Sascha Hauer
@ 2019-11-14 13:00 ` Sascha Hauer
  2019-11-14 13:23   ` Ahmad Fatoum
  2019-11-14 13:00 ` [PATCH 2/6] net: fsl-fman: Store index for txbd Sascha Hauer
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Sascha Hauer @ 2019-11-14 13:00 UTC (permalink / raw)
  To: Barebox List

edev->halt is implemented, but not called by the core during shutdown.
We have to call it manually during device remove. With this and also
resetting the whole FMan during shutdown the driver now works properly
when started second stage from another barebox.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/fsl-fman.c     | 19 +++++++++++++++++++
 include/soc/fsl/fsl_fman.h |  3 +++
 2 files changed, 22 insertions(+)

diff --git a/drivers/net/fsl-fman.c b/drivers/net/fsl-fman.c
index 4e6bb2ecfd..287a891a63 100644
--- a/drivers/net/fsl-fman.c
+++ b/drivers/net/fsl-fman.c
@@ -1175,6 +1175,8 @@ static int fsl_fman_memac_probe(struct device_d *dev)
 	/* alloc the FMan ethernet private struct */
 	fm_eth = xzalloc(sizeof(*fm_eth));
 
+	dev->priv = fm_eth;
+
 	fm_eth->dev = dev;
 
 	ret = fsl_fman_memac_port_bind(fm_eth, FMAN_PORT_TYPE_TX);
@@ -1216,6 +1218,13 @@ static int fsl_fman_memac_probe(struct device_d *dev)
 	return 0;
 }
 
+static void fsl_fman_memac_remove(struct device_d *dev)
+{
+	struct fm_eth *fm_eth = dev->priv;
+
+	fm_eth_halt(&fm_eth->edev);
+}
+
 static int fsl_fman_muram_probe(struct device_d *dev)
 {
 	struct resource *iores;
@@ -1274,6 +1283,7 @@ static struct of_device_id fsl_fman_memac_dt_ids[] = {
 static struct driver_d fman_memac_driver = {
 	.name   = "fsl-fman-memac",
 	.probe  = fsl_fman_memac_probe,
+	.remove = fsl_fman_memac_remove,
 	.of_compatible = DRV_OF_COMPAT(fsl_fman_memac_dt_ids),
 };
 
@@ -1303,6 +1313,7 @@ static int fsl_fman_probe(struct device_d *dev)
 		return PTR_ERR(iores);
 
 	reg = IOMEM(iores->start);
+	dev->priv = reg;
 
 	ret = of_platform_populate(dev->device_node, NULL, dev);
 	if (ret)
@@ -1320,6 +1331,13 @@ static int fsl_fman_probe(struct device_d *dev)
 	return 0;
 }
 
+static void fsl_fman_remove(struct device_d *dev)
+{
+	struct ccsr_fman *reg = dev->priv;
+
+	setbits_be32(&reg->fm_fpm.fmrstc, FMFP_RSTC_RFM);
+}
+
 static struct of_device_id fsl_fman_dt_ids[] = {
 	{
 		.compatible = "fsl,fman",
@@ -1330,6 +1348,7 @@ static struct of_device_id fsl_fman_dt_ids[] = {
 static struct driver_d fman_driver = {
 	.name   = "fsl-fman",
 	.probe  = fsl_fman_probe,
+	.remove = fsl_fman_remove,
 	.of_compatible = DRV_OF_COMPAT(fsl_fman_dt_ids),
 };
 device_platform_driver(fman_driver);
diff --git a/include/soc/fsl/fsl_fman.h b/include/soc/fsl/fsl_fman.h
index 96d61298ef..fd69fded38 100644
--- a/include/soc/fsl/fsl_fman.h
+++ b/include/soc/fsl/fsl_fman.h
@@ -348,6 +348,9 @@ struct fm_fpm {
 /* FPM Flush Control Register */
 #define FMFP_FLC_DISP_LIM_NONE	0x00000000 /* no dispatch limitation */
 
+/* FMan Reset Command Register */
+#define FMFP_RSTC_RFM		0x80000000 /* FMan Soft Reset Command */
+
 /* FMFP_EE - FPM event and enable register */
 #define FMFPEE_DECC		0x80000000 /* double ECC err on FPM ram */
 #define FMFPEE_STL		0x40000000 /* stall of task ... */
-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/6] net: fsl-fman: Store index for txbd
  2019-11-14 13:00 [PATCH 0/6] fsl-fman patches Sascha Hauer
  2019-11-14 13:00 ` [PATCH 1/6] net: fsl-fman: reset device before leaving Sascha Hauer
@ 2019-11-14 13:00 ` Sascha Hauer
  2019-11-14 13:00 ` [PATCH 3/6] net: fsl-fman: move status read into loop Sascha Hauer
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2019-11-14 13:00 UTC (permalink / raw)
  To: Barebox List

Instead of storing a pointer to the current txbd store the index of the
current buffer. This makes the code more straight forward.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/fsl-fman.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/net/fsl-fman.c b/drivers/net/fsl-fman.c
index 287a891a63..b5d617212e 100644
--- a/drivers/net/fsl-fman.c
+++ b/drivers/net/fsl-fman.c
@@ -107,8 +107,8 @@ struct fm_eth {
 	void *rx_bd_ring;		/* Rx BD ring base */
 	void *cur_rxbd;			/* current Rx BD */
 	void *rx_buf;			/* Rx buffer base */
-	void *tx_bd_ring;		/* Tx BD ring base */
-	void *cur_txbd;			/* current Tx BD */
+	struct fm_port_bd *tx_bd_ring;	/* Tx BD ring base */
+	int cur_txbd_idx;		/* current Tx BD index */
 	struct memac *regs;
 };
 
@@ -702,16 +702,16 @@ static int fm_eth_tx_port_parameter_init(struct fm_eth *fm_eth)
 			* TX_BD_RING_SIZE);
 	/* save it to fm_eth */
 	fm_eth->tx_bd_ring = tx_bd_ring_base;
-	fm_eth->cur_txbd = tx_bd_ring_base;
+	fm_eth->cur_txbd_idx = 0;
 
 	/* init Tx BDs ring */
-	txbd = tx_bd_ring_base;
 	for (i = 0; i < TX_BD_RING_SIZE; i++) {
+		txbd = &fm_eth->tx_bd_ring[i];
+
 		muram_writew(&txbd->status, TxBD_LAST);
 		muram_writew(&txbd->len, 0);
 		muram_writew(&txbd->buf_ptr_hi, 0);
 		out_be32(&txbd->buf_ptr_lo, 0);
-		txbd++;
 	}
 
 	/* set the Tx queue decriptor */
@@ -834,13 +834,13 @@ static int fm_eth_send(struct eth_device *edev, void *buf, int len)
 {
 	struct fm_eth *fm_eth = to_fm_eth(edev);
 	struct fm_port_global_pram *pram;
-	struct fm_port_bd *txbd, *txbd_base;
+	struct fm_port_bd *txbd;
 	u16 offset_in;
 	int i;
 	dma_addr_t dma;
 
 	pram = fm_eth->tx_pram;
-	txbd = fm_eth->cur_txbd;
+	txbd = &fm_eth->tx_bd_ring[fm_eth->cur_txbd_idx];
 
 	/* find one empty TxBD */
 	for (i = 0; muram_readw(&txbd->status) & TxBD_READY; i++) {
@@ -882,12 +882,7 @@ static int fm_eth_send(struct eth_device *edev, void *buf, int len)
 	dma_unmap_single(fm_eth->dev, dma, len, DMA_TO_DEVICE);
 
 	/* advance the TxBD */
-	txbd++;
-	txbd_base = fm_eth->tx_bd_ring;
-	if (txbd >= (txbd_base + TX_BD_RING_SIZE))
-		txbd = txbd_base;
-	/* update current txbd */
-	fm_eth->cur_txbd = (void *)txbd;
+	fm_eth->cur_txbd_idx = (fm_eth->cur_txbd_idx + 1) % TX_BD_RING_SIZE;
 
 	return 0;
 }
-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/6] net: fsl-fman: move status read into loop
  2019-11-14 13:00 [PATCH 0/6] fsl-fman patches Sascha Hauer
  2019-11-14 13:00 ` [PATCH 1/6] net: fsl-fman: reset device before leaving Sascha Hauer
  2019-11-14 13:00 ` [PATCH 2/6] net: fsl-fman: Store index for txbd Sascha Hauer
@ 2019-11-14 13:00 ` Sascha Hauer
  2019-11-14 13:00 ` [PATCH 4/6] net: fsl-fman: Store index for rxbd Sascha Hauer
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2019-11-14 13:00 UTC (permalink / raw)
  To: Barebox List

Instead of reading the status once before the loop and then again right
before the next iteration, just read the status in the loop.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/fsl-fman.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/fsl-fman.c b/drivers/net/fsl-fman.c
index b5d617212e..5dc7ed5090 100644
--- a/drivers/net/fsl-fman.c
+++ b/drivers/net/fsl-fman.c
@@ -900,9 +900,12 @@ static int fm_eth_recv(struct eth_device *edev)
 
 	pram = fm_eth->rx_pram;
 	rxbd = fm_eth->cur_rxbd;
-	status = muram_readw(&rxbd->status);
 
-	while (!(status & RxBD_EMPTY)) {
+	while (1) {
+		status = muram_readw(&rxbd->status);
+		if (status & RxBD_EMPTY)
+			break;
+
 		if (!(status & RxBD_ERROR)) {
 			buf_hi = muram_readw(&rxbd->buf_ptr_hi);
 			buf_lo = in_be32(&rxbd->buf_ptr_lo);
@@ -932,8 +935,6 @@ static int fm_eth_recv(struct eth_device *edev)
 		rxbd_base = fm_eth->rx_bd_ring;
 		if (rxbd >= (rxbd_base + RX_BD_RING_SIZE))
 			rxbd = rxbd_base;
-		/* read next status */
-		status = muram_readw(&rxbd->status);
 
 		/* update RxQD */
 		offset_out = muram_readw(&pram->rxqd.offset_out);
-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/6] net: fsl-fman: Store index for rxbd
  2019-11-14 13:00 [PATCH 0/6] fsl-fman patches Sascha Hauer
                   ` (2 preceding siblings ...)
  2019-11-14 13:00 ` [PATCH 3/6] net: fsl-fman: move status read into loop Sascha Hauer
@ 2019-11-14 13:00 ` Sascha Hauer
  2019-11-14 13:00 ` [PATCH 5/6] net: fsl-fman: simplify setting next offset Sascha Hauer
  2019-11-14 13:00 ` [PATCH 6/6] net: fsl-fman: do not leave not transmitted DMA buffers mapped Sascha Hauer
  5 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2019-11-14 13:00 UTC (permalink / raw)
  To: Barebox List

Like done for the txbd, also store the index of the current rxbd in the
driver private data. This makes the code easier to follow.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/fsl-fman.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/net/fsl-fman.c b/drivers/net/fsl-fman.c
index 5dc7ed5090..196be3f6bd 100644
--- a/drivers/net/fsl-fman.c
+++ b/drivers/net/fsl-fman.c
@@ -104,8 +104,8 @@ struct fm_eth {
 	struct device_d *dev;
 	struct fm_port_global_pram *rx_pram; /* Rx parameter table */
 	struct fm_port_global_pram *tx_pram; /* Tx parameter table */
-	void *rx_bd_ring;		/* Rx BD ring base */
-	void *cur_rxbd;			/* current Rx BD */
+	struct fm_port_bd *rx_bd_ring;	/* Rx BD ring base */
+	int cur_rxbd_idx;		/* current Rx BD index */
 	void *rx_buf;			/* Rx buffer base */
 	struct fm_port_bd *tx_bd_ring;	/* Tx BD ring base */
 	int cur_txbd_idx;		/* current Tx BD index */
@@ -628,12 +628,13 @@ static int fm_eth_rx_port_parameter_init(struct fm_eth *fm_eth)
 
 	/* save them to fm_eth */
 	fm_eth->rx_bd_ring = rx_bd_ring_base;
-	fm_eth->cur_rxbd = rx_bd_ring_base;
+	fm_eth->cur_rxbd_idx = 0;
 	fm_eth->rx_buf = rx_buf_pool;
 
 	/* init Rx BDs ring */
-	rxbd = rx_bd_ring_base;
 	for (i = 0; i < RX_BD_RING_SIZE; i++) {
+		rxbd = &fm_eth->rx_bd_ring[i];
+
 		muram_writew(&rxbd->status, RxBD_EMPTY);
 		muram_writew(&rxbd->len, 0);
 		buf_hi = upper_32_bits(virt_to_phys(rx_buf_pool +
@@ -644,7 +645,6 @@ static int fm_eth_rx_port_parameter_init(struct fm_eth *fm_eth)
 					   MAX_RXBUF_LEN, DMA_FROM_DEVICE);
 		muram_writew(&rxbd->buf_ptr_hi, (u16)buf_hi);
 		out_be32(&rxbd->buf_ptr_lo, buf_lo);
-		rxbd++;
 	}
 
 	/* set the Rx queue descriptor */
@@ -891,7 +891,7 @@ static int fm_eth_recv(struct eth_device *edev)
 {
 	struct fm_eth *fm_eth = to_fm_eth(edev);
 	struct fm_port_global_pram *pram;
-	struct fm_port_bd *rxbd, *rxbd_base;
+	struct fm_port_bd *rxbd;
 	u16 status, len;
 	u32 buf_lo, buf_hi;
 	u8 *data;
@@ -899,9 +899,10 @@ static int fm_eth_recv(struct eth_device *edev)
 	int ret = 1;
 
 	pram = fm_eth->rx_pram;
-	rxbd = fm_eth->cur_rxbd;
 
 	while (1) {
+		rxbd = &fm_eth->rx_bd_ring[fm_eth->cur_rxbd_idx];
+
 		status = muram_readw(&rxbd->status);
 		if (status & RxBD_EMPTY)
 			break;
@@ -931,10 +932,7 @@ static int fm_eth_recv(struct eth_device *edev)
 		muram_writew(&rxbd->len, 0);
 
 		/* advance RxBD */
-		rxbd++;
-		rxbd_base = fm_eth->rx_bd_ring;
-		if (rxbd >= (rxbd_base + RX_BD_RING_SIZE))
-			rxbd = rxbd_base;
+		fm_eth->cur_rxbd_idx = (fm_eth->cur_rxbd_idx + 1) % RX_BD_RING_SIZE;
 
 		/* update RxQD */
 		offset_out = muram_readw(&pram->rxqd.offset_out);
@@ -943,7 +941,6 @@ static int fm_eth_recv(struct eth_device *edev)
 			offset_out = 0;
 		muram_writew(&pram->rxqd.offset_out, offset_out);
 	}
-	fm_eth->cur_rxbd = rxbd;
 
 	return ret;
 }
-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/6] net: fsl-fman: simplify setting next offset
  2019-11-14 13:00 [PATCH 0/6] fsl-fman patches Sascha Hauer
                   ` (3 preceding siblings ...)
  2019-11-14 13:00 ` [PATCH 4/6] net: fsl-fman: Store index for rxbd Sascha Hauer
@ 2019-11-14 13:00 ` Sascha Hauer
  2019-11-14 13:00 ` [PATCH 6/6] net: fsl-fman: do not leave not transmitted DMA buffers mapped Sascha Hauer
  5 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2019-11-14 13:00 UTC (permalink / raw)
  To: Barebox List

The offset of the current packet can be retrieved from the current txbd
index, so do this instead of increasing the offset with each new packet.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/fsl-fman.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/net/fsl-fman.c b/drivers/net/fsl-fman.c
index 196be3f6bd..01f7064fd2 100644
--- a/drivers/net/fsl-fman.c
+++ b/drivers/net/fsl-fman.c
@@ -835,7 +835,6 @@ static int fm_eth_send(struct eth_device *edev, void *buf, int len)
 	struct fm_eth *fm_eth = to_fm_eth(edev);
 	struct fm_port_global_pram *pram;
 	struct fm_port_bd *txbd;
-	u16 offset_in;
 	int i;
 	dma_addr_t dma;
 
@@ -862,12 +861,12 @@ static int fm_eth_send(struct eth_device *edev, void *buf, int len)
 	muram_writew(&txbd->len, len);
 	muram_writew(&txbd->status, TxBD_READY | TxBD_LAST);
 
+	/* advance the TxBD */
+	fm_eth->cur_txbd_idx = (fm_eth->cur_txbd_idx + 1) % TX_BD_RING_SIZE;
+
 	/* update TxQD, let RISC to send the packet */
-	offset_in = muram_readw(&pram->txqd.offset_in);
-	offset_in += sizeof(struct fm_port_bd);
-	if (offset_in >= muram_readw(&pram->txqd.bd_ring_size))
-		offset_in = 0;
-	muram_writew(&pram->txqd.offset_in, offset_in);
+	muram_writew(&pram->txqd.offset_in,
+		     fm_eth->cur_txbd_idx * sizeof(struct fm_port_bd));
 
 	/* wait for buffer to be transmitted */
 	for (i = 0; muram_readw(&txbd->status) & TxBD_READY; i++) {
@@ -881,9 +880,6 @@ static int fm_eth_send(struct eth_device *edev, void *buf, int len)
 
 	dma_unmap_single(fm_eth->dev, dma, len, DMA_TO_DEVICE);
 
-	/* advance the TxBD */
-	fm_eth->cur_txbd_idx = (fm_eth->cur_txbd_idx + 1) % TX_BD_RING_SIZE;
-
 	return 0;
 }
 
-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 6/6] net: fsl-fman: do not leave not transmitted DMA buffers mapped
  2019-11-14 13:00 [PATCH 0/6] fsl-fman patches Sascha Hauer
                   ` (4 preceding siblings ...)
  2019-11-14 13:00 ` [PATCH 5/6] net: fsl-fman: simplify setting next offset Sascha Hauer
@ 2019-11-14 13:00 ` Sascha Hauer
  5 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2019-11-14 13:00 UTC (permalink / raw)
  To: Barebox List

When a packet can't be transmitted we should unmap it. This probably
won't change much since when we can't transmit a packet the fman
probably can't recover from it anyway, but still it is cleaner to not
leave the buffers mapped.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/fsl-fman.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/fsl-fman.c b/drivers/net/fsl-fman.c
index 01f7064fd2..467f7840bf 100644
--- a/drivers/net/fsl-fman.c
+++ b/drivers/net/fsl-fman.c
@@ -835,7 +835,7 @@ static int fm_eth_send(struct eth_device *edev, void *buf, int len)
 	struct fm_eth *fm_eth = to_fm_eth(edev);
 	struct fm_port_global_pram *pram;
 	struct fm_port_bd *txbd;
-	int i;
+	int i, ret;
 	dma_addr_t dma;
 
 	pram = fm_eth->tx_pram;
@@ -869,18 +869,20 @@ static int fm_eth_send(struct eth_device *edev, void *buf, int len)
 		     fm_eth->cur_txbd_idx * sizeof(struct fm_port_bd));
 
 	/* wait for buffer to be transmitted */
+	ret = 0;
 	for (i = 0; muram_readw(&txbd->status) & TxBD_READY; i++) {
 		udelay(10);
 		if (i > 0x10000) {
 			dev_err(&edev->dev, "Tx error, txbd->status = 0x%x\n",
 			       muram_readw(&txbd->status));
-			return -EIO;
+			ret = -EIO;
+			break;
 		}
 	}
 
 	dma_unmap_single(fm_eth->dev, dma, len, DMA_TO_DEVICE);
 
-	return 0;
+	return ret;
 }
 
 static int fm_eth_recv(struct eth_device *edev)
-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/6] net: fsl-fman: reset device before leaving
  2019-11-14 13:00 ` [PATCH 1/6] net: fsl-fman: reset device before leaving Sascha Hauer
@ 2019-11-14 13:23   ` Ahmad Fatoum
  2019-11-14 14:36     ` Sascha Hauer
  0 siblings, 1 reply; 9+ messages in thread
From: Ahmad Fatoum @ 2019-11-14 13:23 UTC (permalink / raw)
  To: barebox

Hello Sascha,

On 11/14/19 2:00 PM, Sascha Hauer wrote:
> edev->halt is implemented, but not called by the core during shutdown.

Oh, that's news to me. Apparently only eth_unregister calls ->halt and that
one is only used by drivers. Shouldn't calling eth_unregister be a part of
the barebox shutdown sequence?

Cheers
Ahmad

> We have to call it manually during device remove. With this and also
> resetting the whole FMan during shutdown the driver now works properly
> when started second stage from another barebox.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/net/fsl-fman.c     | 19 +++++++++++++++++++
>  include/soc/fsl/fsl_fman.h |  3 +++
>  2 files changed, 22 insertions(+)
> 
> diff --git a/drivers/net/fsl-fman.c b/drivers/net/fsl-fman.c
> index 4e6bb2ecfd..287a891a63 100644
> --- a/drivers/net/fsl-fman.c
> +++ b/drivers/net/fsl-fman.c
> @@ -1175,6 +1175,8 @@ static int fsl_fman_memac_probe(struct device_d *dev)
>  	/* alloc the FMan ethernet private struct */
>  	fm_eth = xzalloc(sizeof(*fm_eth));
>  
> +	dev->priv = fm_eth;
> +
>  	fm_eth->dev = dev;
>  
>  	ret = fsl_fman_memac_port_bind(fm_eth, FMAN_PORT_TYPE_TX);
> @@ -1216,6 +1218,13 @@ static int fsl_fman_memac_probe(struct device_d *dev)
>  	return 0;
>  }
>  
> +static void fsl_fman_memac_remove(struct device_d *dev)
> +{
> +	struct fm_eth *fm_eth = dev->priv;
> +
> +	fm_eth_halt(&fm_eth->edev);
> +}
> +
>  static int fsl_fman_muram_probe(struct device_d *dev)
>  {
>  	struct resource *iores;
> @@ -1274,6 +1283,7 @@ static struct of_device_id fsl_fman_memac_dt_ids[] = {
>  static struct driver_d fman_memac_driver = {
>  	.name   = "fsl-fman-memac",
>  	.probe  = fsl_fman_memac_probe,
> +	.remove = fsl_fman_memac_remove,
>  	.of_compatible = DRV_OF_COMPAT(fsl_fman_memac_dt_ids),
>  };
>  
> @@ -1303,6 +1313,7 @@ static int fsl_fman_probe(struct device_d *dev)
>  		return PTR_ERR(iores);
>  
>  	reg = IOMEM(iores->start);
> +	dev->priv = reg;
>  
>  	ret = of_platform_populate(dev->device_node, NULL, dev);
>  	if (ret)
> @@ -1320,6 +1331,13 @@ static int fsl_fman_probe(struct device_d *dev)
>  	return 0;
>  }
>  
> +static void fsl_fman_remove(struct device_d *dev)
> +{
> +	struct ccsr_fman *reg = dev->priv;
> +
> +	setbits_be32(&reg->fm_fpm.fmrstc, FMFP_RSTC_RFM);
> +}
> +
>  static struct of_device_id fsl_fman_dt_ids[] = {
>  	{
>  		.compatible = "fsl,fman",
> @@ -1330,6 +1348,7 @@ static struct of_device_id fsl_fman_dt_ids[] = {
>  static struct driver_d fman_driver = {
>  	.name   = "fsl-fman",
>  	.probe  = fsl_fman_probe,
> +	.remove = fsl_fman_remove,
>  	.of_compatible = DRV_OF_COMPAT(fsl_fman_dt_ids),
>  };
>  device_platform_driver(fman_driver);
> diff --git a/include/soc/fsl/fsl_fman.h b/include/soc/fsl/fsl_fman.h
> index 96d61298ef..fd69fded38 100644
> --- a/include/soc/fsl/fsl_fman.h
> +++ b/include/soc/fsl/fsl_fman.h
> @@ -348,6 +348,9 @@ struct fm_fpm {
>  /* FPM Flush Control Register */
>  #define FMFP_FLC_DISP_LIM_NONE	0x00000000 /* no dispatch limitation */
>  
> +/* FMan Reset Command Register */
> +#define FMFP_RSTC_RFM		0x80000000 /* FMan Soft Reset Command */
> +
>  /* FMFP_EE - FPM event and enable register */
>  #define FMFPEE_DECC		0x80000000 /* double ECC err on FPM ram */
>  #define FMFPEE_STL		0x40000000 /* stall of task ... */
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/6] net: fsl-fman: reset device before leaving
  2019-11-14 13:23   ` Ahmad Fatoum
@ 2019-11-14 14:36     ` Sascha Hauer
  0 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2019-11-14 14:36 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Thu, Nov 14, 2019 at 02:23:44PM +0100, Ahmad Fatoum wrote:
> Hello Sascha,
> 
> On 11/14/19 2:00 PM, Sascha Hauer wrote:
> > edev->halt is implemented, but not called by the core during shutdown.
> 
> Oh, that's news to me. Apparently only eth_unregister calls ->halt and that
> one is only used by drivers. Shouldn't calling eth_unregister be a part of
> the barebox shutdown sequence?
> 

I had the same thought as well and have put it on my mental todo list.
It would be easy to put calling of edev->halt() somewhere in the
shutdown path, but this would result in edev->halt() being called twice
for drivers which already do this in their own remove function. I'm not
sure every driver handles this fine so we probably have to make sure it
is called only once.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-11-14 14:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-14 13:00 [PATCH 0/6] fsl-fman patches Sascha Hauer
2019-11-14 13:00 ` [PATCH 1/6] net: fsl-fman: reset device before leaving Sascha Hauer
2019-11-14 13:23   ` Ahmad Fatoum
2019-11-14 14:36     ` Sascha Hauer
2019-11-14 13:00 ` [PATCH 2/6] net: fsl-fman: Store index for txbd Sascha Hauer
2019-11-14 13:00 ` [PATCH 3/6] net: fsl-fman: move status read into loop Sascha Hauer
2019-11-14 13:00 ` [PATCH 4/6] net: fsl-fman: Store index for rxbd Sascha Hauer
2019-11-14 13:00 ` [PATCH 5/6] net: fsl-fman: simplify setting next offset Sascha Hauer
2019-11-14 13:00 ` [PATCH 6/6] net: fsl-fman: do not leave not transmitted DMA buffers mapped Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox