Skip to contentSkip to conversation

staging: octeon: repair "fixed-link" support

PATCH In review Alexander A Sverdlin 3 participants 9 messages Oct 16, 2020 – Oct 25, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 staging: octeon: repair "fixed-link" support

From: Alexander Sverdlin <[email protected]>

The PHYs must be registered once in device probe function, not in device open callback because it's only possible to register them once.

Fixes a25e278020 ("staging: octeon: support fixed-link phys")
---
 drivers/staging/octeon/ethernet-mdio.c | 6 ------
 drivers/staging/octeon/ethernet.c      | 9 +++++++++
 2 files changed, 9 insertions(+), 6 deletions(-)

Changes in v2:
- removed the usage of non-upstream local variable "r"

drivers/staging/octeon/ethernet-mdio.c +0 -6
index cfb673a..0bf54584 100644
@@ -147,12 +147,6 @@ int cvm_oct_phy_setup_device(struct net_device *dev)
 
 	phy_node = of_parse_phandle(priv->of_node, "phy-handle", 0);
 	if (!phy_node && of_phy_is_fixed_link(priv->of_node)) {
-		int rc;
-
-		rc = of_phy_register_fixed_link(priv->of_node);
-		if (rc)
-			return rc;
-
 		phy_node = of_node_get(priv->of_node);
 	}
 	if (!phy_node)
drivers/staging/octeon/ethernet.c +9 -0
index 204f0b1..5dea6e9 100644
@@ -13,6 +13,7 @@
 #include <linux/phy.h>
 #include <linux/slab.h>
 #include <linux/interrupt.h>
+#include <linux/of_mdio.h>
 #include <linux/of_net.h>
 #include <linux/if_ether.h>
 #include <linux/if_vlan.h>
@@ -892,6 +893,14 @@ static int cvm_oct_probe(struct platform_device *pdev)
 				break;
 			}
 
+			if (priv->of_node && of_phy_is_fixed_link(priv->of_node)) {
+				if (of_phy_register_fixed_link(priv->of_node)) {
+					netdev_err(dev, "Failed to register fixed link for interface %d, port %d\n",
+						   interface, priv->port);
+					dev->netdev_ops = NULL;
+				}
+			}
+
 			if (!dev->netdev_ops) {
 				free_netdev(dev);
 			} else if (register_netdev(dev) < 0) {
Signature · 1 line
2.10.2
#1 lore raw

PATCH v2 1/1 staging: octeon: Drop on uncorrectable alignment or FCS error

From: Alexander Sverdlin <[email protected]>

Currently in case of alignment or FCS error if the packet cannot be corrected it's still not dropped. Report the error properly and drop the packet while making the code around a little bit more readable.

Fixes 80ff0fd3ab ("Staging: Add octeon-ethernet driver files.")

Change-Id: Ie1fadcc57cb5e221cf3e83c169b53a5533b8edff

---
 drivers/staging/octeon/ethernet-rx.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

Changes in v2:
- whitespace alignment fix as suggested by Dan Carpenter
- fixed the logic to accept "corrected" packets (preambles 0xd, 0xd5)

drivers/staging/octeon/ethernet-rx.c +19 -15
index 2c16230..9ebd665 100644
@@ -69,15 +69,17 @@ static inline int cvm_oct_check_rcv_error(struct cvmx_wqe *work)
 	else
 		port = work->word1.cn38xx.ipprt;
 
-	if ((work->word2.snoip.err_code == 10) && (work->word1.len <= 64)) {
+	if ((work->word2.snoip.err_code == 10) && (work->word1.len <= 64))
 		/*
 		 * Ignore length errors on min size packets. Some
 		 * equipment incorrectly pads packets to 64+4FCS
 		 * instead of 60+4FCS.  Note these packets still get
 		 * counted as frame errors.
 		 */
-	} else if (work->word2.snoip.err_code == 5 ||
-		   work->word2.snoip.err_code == 7) {
+		return 0;
+
+	if (work->word2.snoip.err_code == 5 ||
+	    work->word2.snoip.err_code == 7) {
 		/*
 		 * We received a packet with either an alignment error
 		 * or a FCS error. This may be signalling that we are
@@ -108,7 +110,10 @@ static inline int cvm_oct_check_rcv_error(struct cvmx_wqe *work)
 				/* Port received 0xd5 preamble */
 				work->packet_ptr.s.addr += i + 1;
 				work->word1.len -= i + 5;
-			} else if ((*ptr & 0xf) == 0xd) {
+				return 0;
+			}
+
+			if ((*ptr & 0xf) == 0xd) {
 				/* Port received 0xd preamble */
 				work->packet_ptr.s.addr += i;
 				work->word1.len -= i + 4;
@@ -118,21 +123,20 @@ static inline int cvm_oct_check_rcv_error(struct cvmx_wqe *work)
 					    ((*(ptr + 1) & 0xf) << 4);
 					ptr++;
 				}
-			} else {
-				printk_ratelimited("Port %d unknown preamble, packet dropped\n",
-						   port);
-				cvm_oct_free_work(work);
-				return 1;
+				return 0;
 			}
+
+			printk_ratelimited("Port %d unknown preamble, packet dropped\n",
+					   port);
+			cvm_oct_free_work(work);
+			return 1;
 		}
-	} else {
-		printk_ratelimited("Port %d receive error code %d, packet dropped\n",
-				   port, work->word2.snoip.err_code);
-		cvm_oct_free_work(work);
-		return 1;
 	}
 
-	return 0;
+	printk_ratelimited("Port %d receive error code %d, packet dropped\n",
+			   port, work->word2.snoip.err_code);
+	cvm_oct_free_work(work);
+	return 1;
 }
 
 static void copy_segments_to_skb(struct cvmx_wqe *work, struct sk_buff *skb)
Signature · 1 line
2.10.2
#2 lore raw

Re: [PATCH v2 net] staging: octeon: Drop on uncorrectable alignment or FCS error

Quoted 10 lines · Alexander A Sverdlin

From: Alexander Sverdlin <[email protected]>

Currently in case of alignment or FCS error if the packet cannot be corrected it's still not dropped. Report the error properly and drop the packet while making the code around a little bit more readable.

Fixes 80ff0fd3ab ("Staging: Add octeon-ethernet driver files.")

Change-Id: Ie1fadcc57cb5e221cf3e83c169b53a5533b8edff

You didn't run checkpatch :(

#3 lore raw

Re: [PATCH v2 net] staging: octeon: Drop on uncorrectable alignment or FCS error

In reply to Alexander A Sverdlin
Quoted 10 lines · Alexander A Sverdlin

From: Alexander Sverdlin <[email protected]>

Currently in case of alignment or FCS error if the packet cannot be corrected it's still not dropped. Report the error properly and drop the packet while making the code around a little bit more readable.

Fixes 80ff0fd3ab ("Staging: Add octeon-ethernet driver files.")

Change-Id: Ie1fadcc57cb5e221cf3e83c169b53a5533b8edff

Why is the change-id still here???

#4 lore raw

Re: [PATCH v2 net] staging: octeon: Drop on uncorrectable alignment or FCS error

In reply to Alexander A Sverdlin

drivers/staging/octeon/ethernet-rx.c static inline int cvm_oct_check_rcv_error(struct cvmx_wqe *work) · line 72

Quoted 10 lines
drivers/staging/octeon/ethernet-rx.c +1 -1
index 2c16230..9ebd665 100644
@@ -69,15 +69,17 @@ static inline int cvm_oct_check_rcv_error(struct cvmx_wqe *work)
 	else
 		port = work->word1.cn38xx.ipprt;
 
-	if ((work->word2.snoip.err_code == 10) && (work->word1.len <= 64)) {
+	if ((work->word2.snoip.err_code == 10) && (work->word1.len <= 64))

It would be nice to replace all these err_code magic numbers with #defines.

You should also replace 64 with ETH_ZLEN + ETH_FCS_LEN. I also wonder if <= should be just < ?

Quoted 16 lines
drivers/staging/octeon/ethernet-rx.c +4 -2
 		/*
 		 * Ignore length errors on min size packets. Some
 		 * equipment incorrectly pads packets to 64+4FCS
 		 * instead of 60+4FCS.  Note these packets still get
 		 * counted as frame errors.
 		 */
-	} else if (work->word2.snoip.err_code == 5 ||
-		   work->word2.snoip.err_code == 7) {
+		return 0;
+
+	if (work->word2.snoip.err_code == 5 ||
+	    work->word2.snoip.err_code == 7) {
 		/*
 		 * We received a packet with either an alignment error
 		 * or a FCS error. This may be signalling that we are

drivers/staging/octeon/ethernet-rx.c static inline int cvm_oct_check_rcv_error(struct cvmx_wqe *work) · line 116

Quoted 8 lines
drivers/staging/octeon/ethernet-rx.c +4 -1
@@ -108,7 +110,10 @@ static inline int cvm_oct_check_rcv_error(struct cvmx_wqe *work)
 				/* Port received 0xd5 preamble */
 				work->packet_ptr.s.addr += i + 1;
 				work->word1.len -= i + 5;
-			} else if ((*ptr & 0xf) == 0xd) {
+				return 0;
+			}
+
+			if ((*ptr & 0xf) == 0xd) {

The comments are not so clear what is going on here. Can this incorrectly match a destination MAC address of xD:XX:XX:XX:XX:XX.

drivers/staging/octeon/ethernet-rx.c static inline int cvm_oct_check_rcv_error(struct cvmx_wqe *work) · line 119

Quoted 3 lines
drivers/staging/octeon/ethernet-rx.c +0 -0
 				/* Port received 0xd preamble */
 				work->packet_ptr.s.addr += i;
 				work->word1.len -= i + 4;

Andrew

#5 lore raw

Re: [PATCH v2 net] staging: octeon: Drop on uncorrectable alignment or FCS error

Hello Andrew,

thank you for your review!

Quoted 8 lines · Andrew Lunn
Quoted 8 lines
drivers/staging/octeon/ethernet-rx.c +0 -0
index 2c16230..9ebd665 100644
@@ -69,15 +69,17 @@ static inline int cvm_oct_check_rcv_error(struct cvmx_wqe *work)
 	else
 		port = work->word1.cn38xx.ipprt;
 
Quoted 6 lines

drivers/staging/octeon/ethernet-rx.c static inline int cvm_oct_check_rcv_error(struct cvmx_wqe *work) · line 72

Quoted 2 lines
drivers/staging/octeon/ethernet-rx.c +1 -1
-	if ((work->word2.snoip.err_code == 10) && (work->word1.len <= 64)) {
+	if ((work->word2.snoip.err_code == 10) && (work->word1.len <= 64))

It would be nice to replace all these err_code magic numbers with #defines.

You should also replace 64 with ETH_ZLEN + ETH_FCS_LEN. I also wonder if <= should be just < ?

I think all your comments are valid points, but are rather topics for separate patches. In this one I've addressed one issue: the structure of ifs and elses is so deeply nested, that it lead to one logic mistake:
broken packets which cannot be corrected are still not dropped.

Even my patch has two changes in one: error correction and style correction, but I consider this justified because one was a result of another.

Quoted 30 lines
Quoted 16 lines
drivers/staging/octeon/ethernet-rx.c +4 -2
 		/*
 		 * Ignore length errors on min size packets. Some
 		 * equipment incorrectly pads packets to 64+4FCS
 		 * instead of 60+4FCS.  Note these packets still get
 		 * counted as frame errors.
 		 */
-	} else if (work->word2.snoip.err_code == 5 ||
-		   work->word2.snoip.err_code == 7) {
+		return 0;
+
+	if (work->word2.snoip.err_code == 5 ||
+	    work->word2.snoip.err_code == 7) {
 		/*
 		 * We received a packet with either an alignment error
 		 * or a FCS error. This may be signalling that we are

drivers/staging/octeon/ethernet-rx.c static inline int cvm_oct_check_rcv_error(struct cvmx_wqe *work) · line 116

Quoted 8 lines
drivers/staging/octeon/ethernet-rx.c +4 -1
@@ -108,7 +110,10 @@ static inline int cvm_oct_check_rcv_error(struct cvmx_wqe *work)
 				/* Port received 0xd5 preamble */
 				work->packet_ptr.s.addr += i + 1;
 				work->word1.len -= i + 5;
-			} else if ((*ptr & 0xf) == 0xd) {
+				return 0;
+			}
+
+			if ((*ptr & 0xf) == 0xd) {

The comments are not so clear what is going on here. Can this incorrectly match a destination MAC address of xD:XX:XX:XX:XX:XX.

Quoted 3 lines
drivers/staging/octeon/ethernet-rx.c +0 -0
 				/* Port received 0xd preamble */
 				work->packet_ptr.s.addr += i;
 				work->word1.len -= i + 4;
Signature · 2 lines
Best regards,
Alexander Sverdlin.
#6 lore raw

Re: [PATCH v2 net] staging: octeon: Drop on uncorrectable alignment or FCS error

In reply to Alexander A Sverdlin
Quoted 10 lines · Alexander A Sverdlin

From: Alexander Sverdlin <[email protected]>

Currently in case of alignment or FCS error if the packet cannot be corrected it's still not dropped. Report the error properly and drop the packet while making the code around a little bit more readable.

Fixes 80ff0fd3ab ("Staging: Add octeon-ethernet driver files.")

Change-Id: Ie1fadcc57cb5e221cf3e83c169b53a5533b8edff

Please stop using gerrit for patches destined for upstream development :(

#7 lore raw
In reply to Alexander A Sverdlin

drivers/staging/octeon/ethernet.c static int cvm_oct_probe(struct platform_device *pdev) · line 905

Quoted 10 lines
drivers/staging/octeon/ethernet.c +8 -0
+			if (priv->of_node && of_phy_is_fixed_link(priv->of_node)) {
+				if (of_phy_register_fixed_link(priv->of_node)) {
+					netdev_err(dev, "Failed to register fixed link for interface %d, port %d\n",
+						   interface, priv->port);
+					dev->netdev_ops = NULL;
+				}
+			}
+
 			if (!dev->netdev_ops) {
 				free_netdev(dev);

Setting dev->netdev_ops to NULL to indicate an error is pretty odd. But this is staging. How about cleaning this
up. of_phy_register_fixed_link() returns an -errno which you should return.

Andrew

#8 lore raw
In reply to Alexander A Sverdlin
Quoted 27 lines
drivers/staging/octeon/ethernet.c +9 -0
@@ -13,6 +13,7 @@
 #include <linux/phy.h>
 #include <linux/slab.h>
 #include <linux/interrupt.h>
+#include <linux/of_mdio.h>
 #include <linux/of_net.h>
 #include <linux/if_ether.h>
 #include <linux/if_vlan.h>
@@ -892,6 +893,14 @@ static int cvm_oct_probe(struct platform_device *pdev)
 				break;
 			}
 
+			if (priv->of_node && of_phy_is_fixed_link(priv->of_node)) {
+				if (of_phy_register_fixed_link(priv->of_node)) {
+					netdev_err(dev, "Failed to register fixed link for interface %d, port %d\n",
+						   interface, priv->port);
+					dev->netdev_ops = NULL;
+				}
+			}
+
 			if (!dev->netdev_ops) {
 				free_netdev(dev);
 			} else if (register_netdev(dev) < 0) {
Signature · 1 line
2.10.2

I would also expect a call to of_phy_deregister_fixed_link() somewhere in the driver.

Andrew