Skip to contentSkip to conversation

dsa: lan9303: Add 3 ethtool stats

PATCH In review Jerry Ray 3 participants 8 messages Nov 30, 2022 – Dec 6, 2022

Subsystems (3)
lore
Share & tools
lore

Jerry Ray

author
#0 lore raw

PATCH v4 1/1 dsa: lan9303: Add 3 ethtool stats

Adding Buffer Manager and Switch Engine counters to the reported statistics. As these stats are kept by the switch rather than the port instance, they are indexed differently.

These statistics are maintained by the switch and count the packets dropped due to buffer limits. Note that the rtnl_link_stats: rx_dropped statistic does not include dropped packets due to buffer exhaustion and as such, part of this counter would more appropriately fall under the rx_missed_errors.

Migrating to phylink will be a pre-requisite for adding the stats64 API, at which point the rtnl_link_stats will come into play.

---
v3->v4:
added returning stat of 0 if there is a device read failure. removed unrelated change.
v2->v3:
Isolating this patch to include only the added counters. Renamed the new statsistic labels to better identify them. Added the SWE Filtered counter to the reported statistics. Added comments to explain the added counters.
v1->v2:
Split patch into 2 pieces.
Removed the adding of a module number to the driver.

---
 drivers/net/dsa/lan9303-core.c | 57 +++++++++++++++++++++++++++++++---
 1 file changed, 53 insertions(+), 4 deletions(-)
drivers/net/dsa/lan9303-core.c +53 -4
index 80f07bd20593..93c2a3c549cb 100644
@@ -176,11 +176,14 @@
 # define LAN9303_SWE_PORT_MIRROR_DISABLED 0
 #define LAN9303_SWE_INGRESS_PORT_TYPE 0x1847
 #define  LAN9303_SWE_INGRESS_PORT_TYPE_VLAN 3
+#define LAN9303_SWE_FILTERED_CNT_SRC_0 0x1850
 #define LAN9303_BM_CFG 0x1c00
+#define LAN9303_BM_DRP_CNT_SRC_0 0x1c05
 #define LAN9303_BM_EGRSS_PORT_TYPE 0x1c0c
 # define LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT2 (BIT(17) | BIT(16))
 # define LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT1 (BIT(9) | BIT(8))
 # define LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT0 (BIT(1) | BIT(0))
+#define LAN9303_BM_RATE_DRP_CNT_SRC_0 0x1c16
 
 #define LAN9303_SWITCH_PORT_REG(port, reg0) (0x400 * (port) + (reg0))
 
@@ -978,10 +981,33 @@ static const struct lan9303_mib_desc lan9303_mib[] = {
 	{ .offset = LAN9303_MAC_TX_LATECOL_0, .name = "TxLateCol", },
 };
 
+/* Buffer Management Statistics (indexed by port) */
+/* Switch Engine Statistics (indexed by port) */
+static const struct lan9303_mib_desc lan9303_switch_mib[] = {
+	{ .offset = LAN9303_BM_DRP_CNT_SRC_0, .name = "TotalDropped", },
+	{ .offset = LAN9303_BM_RATE_DRP_CNT_SRC_0, .name = "LimitDropped", },
+	{ .offset = LAN9303_SWE_FILTERED_CNT_SRC_0, .name = "SweFiltered", },
+};
+
+/* TotalDropped:     This register counts the total number of packets dropped
+ * by the Buffer Manager that were received on the given port. This count
+ * includes packets dropped due to buffer space limits and ingress rate limit
+ * discarding (Red and random Yellow dropping).
+ *
+ * LimitDropped:     This register counts the number of packets received on a
+ * port that were dropped by the Buffer Manager solely due to ingress rate
+ * limiting (discarding packets due to Red and random Yellow dropping).
+ *
+ * SweFiltered:      This counter contains the number of packets filtered by
+ * the Switch Engine at ingress for a given port. The count includes packets
+ * filtered due to broadcast throttling, but does not include packets dropped
+ * due to ingress rate limiting.
+ */
+
 static void lan9303_get_strings(struct dsa_switch *ds, int port,
 				u32 stringset, uint8_t *data)
 {
-	unsigned int u;
+	unsigned int i, u;
 
 	if (stringset != ETH_SS_STATS)
 		return;
@@ -990,26 +1016,49 @@ static void lan9303_get_strings(struct dsa_switch *ds, int port,
 		strncpy(data + u * ETH_GSTRING_LEN, lan9303_mib[u].name,
 			ETH_GSTRING_LEN);
 	}
+	for (i = 0; i < ARRAY_SIZE(lan9303_switch_mib); i++) {
+		strncpy(data + (u + i) * ETH_GSTRING_LEN,
+			lan9303_switch_mib[i].name, ETH_GSTRING_LEN);
+	}
 }
 
 static void lan9303_get_ethtool_stats(struct dsa_switch *ds, int port,
 				      uint64_t *data)
 {
 	struct lan9303 *chip = ds->priv;
-	unsigned int u;
+	unsigned int i, u;
 
 	for (u = 0; u < ARRAY_SIZE(lan9303_mib); u++) {
 		u32 reg;
 		int ret;
 
+		/* Read Port-based MIB stats. */
 		ret = lan9303_read_switch_port(
 			chip, port, lan9303_mib[u].offset, &reg);
 
-		if (ret)
+		if (ret) {
 			dev_warn(chip->dev, "Reading status port %d reg %u failed\n",
 				 port, lan9303_mib[u].offset);
+			reg = 0;
+		}
 		data[u] = reg;
 	}
+	for (i = 0; i < ARRAY_SIZE(lan9303_switch_mib); i++) {
+		u32 reg;
+		int ret;
+
+		/* Read Switch stats indexed by port. */
+		ret = lan9303_read_switch_reg(chip,
+					      (lan9303_switch_mib[i].offset +
+					       port), &reg);
+
+		if (ret) {
+			dev_warn(chip->dev, "Reading status port %d reg %u failed\n",
+				 port, lan9303_switch_mib[i].offset + port);
+			reg = 0;
+		}
+		data[i + u] = reg;
+	}
 }
 
 static int lan9303_get_sset_count(struct dsa_switch *ds, int port, int sset)
@@ -1017,7 +1066,7 @@ static int lan9303_get_sset_count(struct dsa_switch *ds, int port, int sset)
 	if (sset != ETH_SS_STATS)
 		return 0;
 
-	return ARRAY_SIZE(lan9303_mib);
+	return ARRAY_SIZE(lan9303_mib) + ARRAY_SIZE(lan9303_switch_mib);
 }
 
 static int lan9303_phy_read(struct dsa_switch *ds, int phy, int regnum)
Signature · 1 line
2.17.1
maintainer
#1 lore raw

Hi Jerry,

Quoted 9 lines · Jerry Ray

static void lan9303_get_ethtool_stats(struct dsa_switch *ds, int port,

drivers/net/dsa/lan9303-core.c +0 -0
 				      uint64_t *data)
 {
 	struct lan9303 *chip = ds->priv;
 	unsigned int u;
 
 	for (u = 0; u < ARRAY_SIZE(lan9303_mib); u++) {
 		u32 reg;
 		int ret;

drivers/net/dsa/lan9303-core.c static void lan9303_get_strings(struct dsa_switch *ds, int port, · line 1043

Quoted 10 lines
drivers/net/dsa/lan9303-core.c +3 -1
 
 		ret = lan9303_read_switch_port(
 			chip, port, lan9303_mib[u].offset, &reg);
 
-		if (ret)
+		if (ret) {
 			dev_warn(chip->dev, "Reading status port %d reg %u failed\n",
 				 port, lan9303_mib[u].offset);
+			reg = 0;
+		}

This part of the change still is unrelated and affects existing code. Bug fixes to existing code are submitted as separate patches. In some kernel trees, they are at the very least tagged with a Fixes: tag and put before other development work. In netdev, they are sent to a different git tree (net.git) which eventually lands in a different set of branches than net-next.git. You need to not mix bug fixes with development code. Andrew also suggested that you separate each logical change into a separate patch.

This, plus the fact that Jakub asked you to also provide standardized counters, not just free-form ones, which you found it ok to disregard.

I hope that only a misunderstanding is involved, because if it isn't, then Jakub will know you, alright, but as the person who disregards review feedback and expects that it'll just disappear. I think Jakub has pretty solid grounds to not expect that you'll come back with what has been requested.

Sorry, this patch has a NACK from me at least until you come back with some clarifications, and split the change.

Quoted 2 lines
drivers/net/dsa/lan9303-core.c +0 -0
 		data[u] = reg;
 	}
#2 lore raw
Quoted 29 lines
Quoted 13 lines

static void lan9303_get_ethtool_stats(struct dsa_switch *ds, int port,

                                    uint64_t *data)
 {
      struct lan9303 *chip = ds->priv;
      unsigned int u;

      for (u = 0; u < ARRAY_SIZE(lan9303_mib); u++) {
              u32 reg;
              int ret;

              ret = lan9303_read_switch_port(
                      chip, port, lan9303_mib[u].offset, &reg);

drivers/net/dsa/lan9303-core.c static void lan9303_get_strings(struct dsa_switch *ds, int port, · line 1043

Quoted 6 lines
drivers/net/dsa/lan9303-core.c +3 -1
-             if (ret)
+             if (ret) {
                      dev_warn(chip->dev, "Reading status port %d reg %u failed\n",
                               port, lan9303_mib[u].offset);
+                     reg = 0;
+             }

This part of the change still is unrelated and affects existing code. Bug fixes to existing code are submitted as separate patches. In some kernel trees, they are at the very least tagged with a Fixes: tag and put before other development work. In netdev, they are sent to a different git tree (net.git) which eventually lands in a different set of branches than net-next.git. You need to not mix bug fixes with development code. Andrew also suggested that you separate each logical change into a separate patch.

Quoted 9 lines

This, plus the fact that Jakub asked you to also provide standardized counters, not just free-form ones, which you found it ok to disregard.

I hope that only a misunderstanding is involved, because if it isn't, then Jakub will know you, alright, but as the person who disregards review feedback and expects that it'll just disappear. I think Jakub has pretty solid grounds to not expect that you'll come back with what has been requested.

I was hoping to get at least this change upstreamed this cycle and address the standardized counters down the road. get_stats64 will require PHYLINK. I replied as such and was hoping to get the benefit of the doubt. I have a patch set under internal review for migrating to phylink and adding support for the port_max_mtu api.

I have been asked to, and have plans for, adding VLAN support and then adding Hardware Timestamping support for the LAN9354 variant. I was hoping to show some progress with this patchset, but if I need to pull it and pick it up later then I'll shuffle things around. I wasn't disregarding Jakub's request and apologize if was viewed that way. I'm simply trying to generate a correct patchset on something relatively simple before moving on to more complicated patchsets.

Quoted 5 lines

Sorry, this patch has a NACK from me at least until you come back with some clarifications, and split the change.

Quoted 2 lines
              data[u] = reg;
      }

My plan is to correct the issues pointed out in this patchset, but not extend it to cover standardized counters. get_stats64 is a separate beast requiring a background thread to keep the stats stored in the driver accumulated and up to date. The current patch simply reads a few more registers from the hardware when asked.

Regards,
Jerry.

maintainer
#3 lore raw
Quoted 1 line · On Thu, 1 Dec 2022 16:42:10 +0000 [email protected] wrote:

get_stats64 will require PHYLINK.

Huh? I'm guessing you're referring to some patches you have queued already and don't want to rebase across? Or some project planning? Otherwise I don't see a connection :S

#4 lore raw
Quoted 7 lines
Quoted 2 lines

get_stats64 will require PHYLINK.

Huh? I'm guessing you're referring to some patches you have queued already and don't want to rebase across? Or some project planning? Otherwise I don't see a connection :S

In looking around at other implementations, I see where the link_up and link_down are used to start or clean up the periodic workqueue used to retrieve and accumulate the mib stats into the driver. Can't tell if that's a requirement or only needed when the device interface is considered too slow. The device interface is not atomic.

J.

maintainer
#5 lore raw
Quoted 9 lines · On Fri, 2 Dec 2022 15:22:55 +0000 [email protected] wrote:
Quoted 3 lines

Huh? I'm guessing you're referring to some patches you have queued already and don't want to rebase across? Or some project planning? Otherwise I don't see a connection :S

In looking around at other implementations, I see where the link_up and link_down are used to start or clean up the periodic workqueue used to retrieve and accumulate the mib stats into the driver. Can't tell if that's a requirement or only needed when the device interface is considered too slow. The device interface is not atomic.

Atomic as in it reads over a bus which requires sleeping? Yes, the stats ndo can't sleep because of the old procfs interface which ifconfig uses and which is invoked under the RCU lock.

maintainer
#6 lore raw
Quoted 11 lines · Jakub Kicinski
Quoted 9 lines · On Fri, 2 Dec 2022 15:22:55 +0000 [email protected] wrote:
Quoted 3 lines

Huh? I'm guessing you're referring to some patches you have queued already and don't want to rebase across? Or some project planning? Otherwise I don't see a connection :S

In looking around at other implementations, I see where the link_up and link_down are used to start or clean up the periodic workqueue used to retrieve and accumulate the mib stats into the driver. Can't tell if that's a requirement or only needed when the device interface is considered too slow. The device interface is not atomic.

Quoted 3 lines

Atomic as in it reads over a bus which requires sleeping? Yes, the stats ndo can't sleep because of the old procfs interface which ifconfig uses and which is invoked under the RCU lock.

Jerry, did you respond to this (what do you mean by "device interface is not atomic")?

Still not clear why transitioning to phylink is a requirement for standardized statistics. You get your link up/link down events with adjust_link too (phydev->link).

Some other drivers only perform periodic stats readout for ports that are up, because those are the only ports where the stats can ever change. That's about all that there is to know. There's no requirement one way or another, it's an optimization.

#7 lore raw
Quoted 17 lines
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

Huh? I'm guessing you're referring to some patches you have queued already and don't want to rebase across? Or some project planning? Otherwise I don't see a connection :S

In looking around at other implementations, I see where the link_up and link_down are used to start or clean up the periodic workqueue used to retrieve and accumulate the mib stats into the driver. Can't tell if that's a requirement or only needed when the device interface is considered too slow. The device interface is not atomic.

Quoted 3 lines

Atomic as in it reads over a bus which requires sleeping? Yes, the stats ndo can't sleep because of the old procfs interface which ifconfig uses and which is invoked under the RCU lock.

Jerry, did you respond to this (what do you mean by "device interface is not atomic")?

Quoted 9 lines

Still not clear why transitioning to phylink is a requirement for standardized statistics. You get your link up/link down events with adjust_link too (phydev->link).

Some other drivers only perform periodic stats readout for ports that are up, because those are the only ports where the stats can ever change. That's about all that there is to know. There's no requirement one way or another, it's an optimization.

Yes, Jakub's understanding is correct. The device is accessed over the mdio bus and as such, will sleep on hardware accesses. This means that the get_stats64 will need to respond with the mib info cached by the driver rather than reading directly from the device. This adds to the driver.

The phylink up/down DSA hooks will be used in controlling the workqueue threads that periodically read and cache the stats info.

You are correct - It's not a hard requirement to first migrate to PHYLINK. It's more of a logical progression of bringing the driver up-to-date. Having adjust_link API still defined, you get the
"Using legacy PHYLIB callbacks. Please migrate to PHYLINK!"
message on board power-up.