Skip to contentSkip to conversation

net: fec_mxc: Fix DM driver issue in recv

PATCH In review Peng Fan 2 participants 13 messages Mar 28, 2018 – Apr 15, 2018 Network drivers

lore
Share & tools
lore

Peng Fan

author
#0 lore raw

PATCH v3 1/6 net: fec_mxc: Fix DM driver issue in recv

From: Ye Li <[email protected]>

When using ethernet DM driver, the recv interface has a change with non-DM interface, that driver needs to set the packet pointer and provide it to upper layer to process.

In fec driver, the fecmxc_recv functions does not handle the packet pointer parameter. This may cause crash in upper layer processing because the packet pointer is not set.

This patch allocates a buffer for the packet pointer and free it through free_pkt interface.

---

V3: None
V2:
Fix build warning for mx28

 drivers/net/fec_mxc.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/net/fec_mxc.c +23 -0
index ff7ad91116..617e504293 100644
@@ -806,7 +806,16 @@ static int fec_recv(struct eth_device *dev)
 	uint16_t bd_status;
 	ulong addr, size, end;
 	int i;
+
+#ifdef CONFIG_DM_ETH
+	*packetp = memalign(ARCH_DMA_MINALIGN, FEC_MAX_PKT_SIZE);
+	if (*packetp == 0) {
+		printf("%s: error allocating packetp\n", __func__);
+		return -ENOMEM;
+	}
+#else
 	ALLOC_CACHE_ALIGN_BUFFER(uchar, buff, FEC_MAX_PKT_SIZE);
+#endif
 
 	/* Check if any critical events have happened */
 	ievent = readl(&fec->eth->ievent);
@@ -882,8 +891,13 @@ static int fec_recv(struct eth_device *dev)
 #ifdef CONFIG_FEC_MXC_SWAP_PACKET
 			swap_packet((uint32_t *)addr, frame_length);
 #endif
+
+#ifdef CONFIG_DM_ETH
+			memcpy(*packetp, (char *)addr, frame_length);
+#else
 			memcpy(buff, (char *)addr, frame_length);
 			net_process_received_packet(buff, frame_length);
+#endif
 			len = frame_length;
 		} else {
 			if (bd_status & FEC_RBD_ERR)
@@ -1201,10 +1215,19 @@ static int fecmxc_read_rom_hwaddr(struct udevice *dev)
 	return fec_get_hwaddr(priv->dev_id, pdata->enetaddr);
 }
 
+static int fecmxc_free_pkt(struct udevice *dev, uchar *packet, int length)
+{
+	if (packet)
+		free(packet);
+
+	return 0;
+}
+
 static const struct eth_ops fecmxc_ops = {
 	.start			= fecmxc_init,
 	.send			= fecmxc_send,
 	.recv			= fecmxc_recv,
+	.free_pkt		= fecmxc_free_pkt,
 	.stop			= fecmxc_halt,
 	.write_hwaddr		= fecmxc_set_hwaddr,
 	.read_rom_hwaddr	= fecmxc_read_rom_hwaddr,
Signature · 1 line
2.14.1
author
#1 lore raw

PATCH v3 2/6 net: fec_mxc: simplify fec_get_miibus

No need to provide two prototype for this function. Use ulong for the first parameter, then this function could be shared for DM/non DM case.

---

V3:
None
V2:
Drop uneccessary ulong

 drivers/net/fec_mxc.c | 15 +++------------
 include/netdev.h      |  6 +-----
 2 files changed, 4 insertions(+), 17 deletions(-)
drivers/net/fec_mxc.c +3 -12
index 617e504293..953252a92e 100644
@@ -1011,18 +1011,9 @@ static void fec_free_descs(struct fec_priv *fec)
 	free(fec->tbd_base);
 }
 
-#ifdef CONFIG_DM_ETH
-struct mii_dev *fec_get_miibus(struct udevice *dev, int dev_id)
-#else
-struct mii_dev *fec_get_miibus(uint32_t base_addr, int dev_id)
-#endif
+struct mii_dev *fec_get_miibus(ulong base_addr, int dev_id)
 {
-#ifdef CONFIG_DM_ETH
-	struct fec_priv *priv = dev_get_priv(dev);
-	struct ethernet_regs *eth = priv->eth;
-#else
-	struct ethernet_regs *eth = (struct ethernet_regs *)(ulong)base_addr;
-#endif
+	struct ethernet_regs *eth = (struct ethernet_regs *)base_addr;
 	struct mii_dev *bus;
 	int ret;
 
@@ -1282,7 +1273,7 @@ static int fecmxc_probe(struct udevice *dev)
 	fec_reg_setup(priv);
 	priv->dev_id = (dev_id == -1) ? 0 : dev_id;
 
-	bus = fec_get_miibus(dev, dev_id);
+	bus = fec_get_miibus((ulong)priv->eth, dev_id);
 	if (!bus) {
 		ret = -ENOMEM;
 		goto err_mii;
include/netdev.h +1 -5
index 3958a4cd32..c96f851be0 100644
@@ -119,11 +119,7 @@ static inline int pci_eth_init(bd_t *bis)
 	return num;
 }
 
-#ifdef CONFIG_DM_ETH
-struct mii_dev *fec_get_miibus(struct udevice *dev, int dev_id);
-#else
-struct mii_dev *fec_get_miibus(uint32_t base_addr, int dev_id);
-#endif
+struct mii_dev *fec_get_miibus(ulong base_addr, int dev_id);
 
 #ifdef CONFIG_PHYLIB
 struct phy_device;
Signature · 1 line
2.14.1
author
#3 lore raw

PATCH v3 3/6 net: fec: set dev->seq to priv->dev_id

In reply to Peng Fan

To platforms has two enet interface, using dev->seq could avoid conflict.

i.MX6UL/ULL evk board net get the wrong MAC address from fuse, eth1 get MAC0 address, eth0 get MAC1 address from fuse. Set the priv->dev_id to device->seq as the real net interface alias id then .fec_get_hwaddr() read the related MAC address from fuse.

---

V3: None
V2: None

 drivers/net/fec_mxc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/fec_mxc.c +2 -3
index 953252a92e..4f1c906a72 100644
@@ -1250,7 +1250,6 @@ static int fecmxc_probe(struct udevice *dev)
 	struct eth_pdata *pdata = dev_get_platdata(dev);
 	struct fec_priv *priv = dev_get_priv(dev);
 	struct mii_dev *bus = NULL;
-	int dev_id = -1;
 	uint32_t start;
 	int ret;
 
@@ -1271,9 +1270,9 @@ static int fecmxc_probe(struct udevice *dev)
 	}
 
 	fec_reg_setup(priv);
-	priv->dev_id = (dev_id == -1) ? 0 : dev_id;
 
-	bus = fec_get_miibus((ulong)priv->eth, dev_id);
+	priv->dev_id = dev->seq;
+	bus = fec_get_miibus((ulong)priv->eth, dev->seq);
 	if (!bus) {
 		ret = -ENOMEM;
 		goto err_mii;
Signature · 1 line
2.14.1
author
#5 lore raw

PATCH v3 4/6 net: fec: sharing MDIO for two enet controllers

In reply to Peng Fan

On i.MX6SX, 6UL and 7D, there are two enet controllers each has a MDIO port. But Some boards share one MDIO port for the two enets. So introduce a configuration CONFIG_FEC_MXC_MDIO_BASE to indicate the MDIO port for sharing.
In Kconfig, user needs enable CONFIG_FEC_MXC_SHARE_MDIO first to enter the CONFIG_FEC_MXC_MDIO_BASE.

To i.MX28, adapt to use the new config

---

V3:
Fix build error. Add a new FEC_MXC_SHARE_MDIO Kconfig for MDIO.

 drivers/net/Kconfig       | 13 ++++++++++++-
 drivers/net/fec_mxc.c     |  8 ++++++--
 include/configs/mx28evk.h |  1 +
 3 files changed, 19 insertions(+), 3 deletions(-)
drivers/net/Kconfig +12 -1
index de1947ccc1..c4cbe34798 100644
@@ -147,9 +147,20 @@ config ETHOC
 	help
 	  This MAC is present in OpenRISC and Xtensa XTFPGA boards.
 
+config FEC_MXC_SHARE_MDIO
+	bool "Share the MDIO bus for FEC controller"
+	depends on FEC_MXC
+
+config FEC_MXC_MDIO_BASE
+	hex "MDIO base address for the FEC controller"
+	depends on FEC_MXC_SHARE_MDIO
+	help
+	  This specifies the MDIO registers base address. It is used when
+	  two FEC controllers share MDIO bus.
+
 config FEC_MXC
 	bool "FEC Ethernet controller"
-	depends on MX5 || MX6
+	depends on MX5 || MX6 || MX7
 	help
 	  This driver supports the 10/100 Fast Ethernet controller for
 	  NXP i.MX processors.
drivers/net/fec_mxc.c +6 -2
index 4f1c906a72..ba66c2f95a 100644
@@ -1145,12 +1145,12 @@ int fecmxc_initialize_multi(bd_t *bd, int dev_id, int phy_id, uint32_t addr)
 #endif
 	int ret;
 
-#ifdef CONFIG_MX28
+#ifdef CONFIG_FEC_MXC_MDIO_BASE
 	/*
 	 * The i.MX28 has two ethernet interfaces, but they are not equal.
 	 * Only the first one can access the MDIO bus.
 	 */
-	base_mii = MXS_ENET0_BASE;
+	base_mii = CONFIG_FEC_MXC_MDIO_BASE;
 #else
 	base_mii = addr;
 #endif
@@ -1272,7 +1272,11 @@ static int fecmxc_probe(struct udevice *dev)
 	fec_reg_setup(priv);
 
 	priv->dev_id = dev->seq;
+#ifdef CONFIG_FEC_MXC_MDIO_BASE
+	bus = fec_get_miibus((ulong)CONFIG_FEC_MXC_MDIO_BASE, dev->seq);
+#else
 	bus = fec_get_miibus((ulong)priv->eth, dev->seq);
+#endif
 	if (!bus) {
 		ret = -ENOMEM;
 		goto err_mii;
include/configs/mx28evk.h +1 -0
index bc58ca5c62..79d4c9b2ce 100644
@@ -65,6 +65,7 @@
 /* FEC Ethernet on SoC */
 #ifdef	CONFIG_CMD_NET
 #define CONFIG_FEC_MXC
+#define CONFIG_FEC_MXC_MDIO_BASE MXS_ENET0_BASE
 #define CONFIG_MX28_FEC_MAC_IN_OCOTP
 #endif
 
Signature · 1 line
2.14.1
author
#7 lore raw

PATCH v3 5/6 net: fex_mxc: add i.MX6UL/SX/SL compatible

In reply to Peng Fan

Add i.MX6UL/SX/SL compatible.

---

V3: None
V2: None

 drivers/net/fec_mxc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/fec_mxc.c +3 -0
index ba66c2f95a..765226e3ab 100644
@@ -1342,6 +1342,9 @@ static int fecmxc_ofdata_to_platdata(struct udevice *dev)
 
 static const struct udevice_id fecmxc_ids[] = {
 	{ .compatible = "fsl,imx6q-fec" },
+	{ .compatible = "fsl,imx6sl-fec" },
+	{ .compatible = "fsl,imx6sx-fec" },
+	{ .compatible = "fsl,imx6ul-fec" },
 	{ }
 };
 
Signature · 1 line
2.14.1
author
#9 lore raw

PATCH v3 6/6 net: fec: Fix issue in DM probe timeout

In reply to Peng Fan

From: Ye Li <[email protected]>

Since the probe function has changed to reset FEC controller prior than setup PHY. If reset FEC controller timeout, the priv->phydev is not initialized, so can't free it.

---

V3: New

 drivers/net/fec_mxc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/fec_mxc.c +1 -2
index 765226e3ab..4caeddb34d 100644
@@ -1291,12 +1291,11 @@ static int fecmxc_probe(struct udevice *dev)
 
 	return 0;
 
-err_timeout:
-	free(priv->phydev);
 err_phy:
 	mdio_unregister(bus);
 	free(bus);
 err_mii:
+err_timeout:
 	fec_free_descs(priv);
 	return ret;
 }
Signature · 1 line
2.14.1