Re: [PATCH net-next v3] net: mvpp2: add ethtool GOP statistics

2017-11-07 Thread Miquel RAYNAL
Hi David,

> > On Wed, Nov 08, 2017 at 01:54:56PM +0900, David Miller wrote:  
> >> From: Miquel Raynal 
> >> Date: Mon,  6 Nov 2017 22:56:53 +0100
> >>   
> >> > Add ethtool statistics support by reading the GOP statistics
> >> > from the hardware counters. Also implement a workqueue to gather
> >> > the statistics every second or some 32-bit counters could
> >> > overflow.
> >> > 
> >> > Suggested-by: Stefan Chulski 
> >> > Signed-off-by: Miquel Raynal   
> >> 
> >> Applied, thanks.  
> > 
> > Miquèl actually sent a v4 of this patch, fixing an issue found in
> > previous versions (including this one) of this patch.  
> 
> Oops, Miquel please send a relative fix.

No problem, I will send you a fix.

Thanks,
Miquèl



Re: [PATCH net-next v3] net: mvpp2: add ethtool GOP statistics

2017-11-07 Thread David Miller
From: Antoine Tenart 
Date: Wed, 8 Nov 2017 06:17:10 +0100

> Hi David,
> 
> On Wed, Nov 08, 2017 at 01:54:56PM +0900, David Miller wrote:
>> From: Miquel Raynal 
>> Date: Mon,  6 Nov 2017 22:56:53 +0100
>> 
>> > Add ethtool statistics support by reading the GOP statistics from the
>> > hardware counters. Also implement a workqueue to gather the statistics
>> > every second or some 32-bit counters could overflow.
>> > 
>> > Suggested-by: Stefan Chulski 
>> > Signed-off-by: Miquel Raynal 
>> 
>> Applied, thanks.
> 
> Miquèl actually sent a v4 of this patch, fixing an issue found in
> previous versions (including this one) of this patch.

Oops, Miquel please send a relative fix.

Thank you.


Re: [PATCH net-next v3] net: mvpp2: add ethtool GOP statistics

2017-11-07 Thread Antoine Tenart
Hi David,

On Wed, Nov 08, 2017 at 01:54:56PM +0900, David Miller wrote:
> From: Miquel Raynal 
> Date: Mon,  6 Nov 2017 22:56:53 +0100
> 
> > Add ethtool statistics support by reading the GOP statistics from the
> > hardware counters. Also implement a workqueue to gather the statistics
> > every second or some 32-bit counters could overflow.
> > 
> > Suggested-by: Stefan Chulski 
> > Signed-off-by: Miquel Raynal 
> 
> Applied, thanks.

Miquèl actually sent a v4 of this patch, fixing an issue found in
previous versions (including this one) of this patch.

Thanks,
Antoine

-- 
Antoine Ténart, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com


Re: [PATCH net-next v3] net: mvpp2: add ethtool GOP statistics

2017-11-07 Thread David Miller
From: Miquel Raynal 
Date: Mon,  6 Nov 2017 22:56:53 +0100

> Add ethtool statistics support by reading the GOP statistics from the
> hardware counters. Also implement a workqueue to gather the statistics
> every second or some 32-bit counters could overflow.
> 
> Suggested-by: Stefan Chulski 
> Signed-off-by: Miquel Raynal 

Applied, thanks.


Re: [PATCH net-next v3] net: mvpp2: add ethtool GOP statistics

2017-11-06 Thread Andrew Lunn
On Mon, Nov 06, 2017 at 10:56:53PM +0100, Miquel Raynal wrote:
> Add ethtool statistics support by reading the GOP statistics from the
> hardware counters. Also implement a workqueue to gather the statistics
> every second or some 32-bit counters could overflow.
> 
> Suggested-by: Stefan Chulski 
> Signed-off-by: Miquel Raynal 

Reviewed-by: Andrew Lunn 

Andrew


[PATCH net-next v3] net: mvpp2: add ethtool GOP statistics

2017-11-06 Thread Miquel Raynal
Add ethtool statistics support by reading the GOP statistics from the
hardware counters. Also implement a workqueue to gather the statistics
every second or some 32-bit counters could overflow.

Suggested-by: Stefan Chulski 
Signed-off-by: Miquel Raynal 
---

Changes since v2:
  - Use netdev_name() to get a unique identifier for the workqueue name
instead of IDA.
  - Save for each port the base address where the counters are, to avoid
doing the same maths over and over each time a counter is read.
  - Protect with mutexes the copy of the statistics array.
  - Remove the useless plain kfree() now that devm_* is used on the
ethtool_stats structure.

 drivers/net/ethernet/marvell/mvpp2.c | 228 ++-
 1 file changed, 223 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2.c 
b/drivers/net/ethernet/marvell/mvpp2.c
index 965b6a829a5d..aa38bca597f2 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -799,6 +799,42 @@ enum mvpp2_bm_type {
MVPP2_BM_SWF_SHORT
 };
 
+/* GMAC MIB Counters register definitions */
+#define MVPP21_MIB_COUNTERS_OFFSET 0x1000
+#define MVPP21_MIB_COUNTERS_PORT_SZ0x400
+#define MVPP22_MIB_COUNTERS_OFFSET 0x0
+#define MVPP22_MIB_COUNTERS_PORT_SZ0x100
+
+#define MVPP2_MIB_GOOD_OCTETS_RCVD 0x0
+#define MVPP2_MIB_BAD_OCTETS_RCVD  0x8
+#define MVPP2_MIB_CRC_ERRORS_SENT  0xc
+#define MVPP2_MIB_UNICAST_FRAMES_RCVD  0x10
+#define MVPP2_MIB_BROADCAST_FRAMES_RCVD0x18
+#define MVPP2_MIB_MULTICAST_FRAMES_RCVD0x1c
+#define MVPP2_MIB_FRAMES_64_OCTETS 0x20
+#define MVPP2_MIB_FRAMES_65_TO_127_OCTETS  0x24
+#define MVPP2_MIB_FRAMES_128_TO_255_OCTETS 0x28
+#define MVPP2_MIB_FRAMES_256_TO_511_OCTETS 0x2c
+#define MVPP2_MIB_FRAMES_512_TO_1023_OCTETS0x30
+#define MVPP2_MIB_FRAMES_1024_TO_MAX_OCTETS0x34
+#define MVPP2_MIB_GOOD_OCTETS_SENT 0x38
+#define MVPP2_MIB_UNICAST_FRAMES_SENT  0x40
+#define MVPP2_MIB_MULTICAST_FRAMES_SENT0x48
+#define MVPP2_MIB_BROADCAST_FRAMES_SENT0x4c
+#define MVPP2_MIB_FC_SENT  0x54
+#define MVPP2_MIB_FC_RCVD  0x58
+#define MVPP2_MIB_RX_FIFO_OVERRUN  0x5c
+#define MVPP2_MIB_UNDERSIZE_RCVD   0x60
+#define MVPP2_MIB_FRAGMENTS_RCVD   0x64
+#define MVPP2_MIB_OVERSIZE_RCVD0x68
+#define MVPP2_MIB_JABBER_RCVD  0x6c
+#define MVPP2_MIB_MAC_RCV_ERROR0x70
+#define MVPP2_MIB_BAD_CRC_EVENT0x74
+#define MVPP2_MIB_COLLISION0x78
+#define MVPP2_MIB_LATE_COLLISION   0x7c
+
+#define MVPP2_MIB_COUNTERS_STATS_DELAY (1 * HZ)
+
 /* Definitions */
 
 /* Shared Packet Processor resources */
@@ -826,6 +862,7 @@ struct mvpp2 {
struct clk *axi_clk;
 
/* List of pointers to port structures */
+   int port_count;
struct mvpp2_port **port_list;
 
/* Aggregated TXQs */
@@ -847,6 +884,12 @@ struct mvpp2 {
 
/* Maximum number of RXQs per port */
unsigned int max_port_rxqs;
+
+   /* Workqueue to gather hardware statistics with its lock */
+   struct mutex gather_stats_lock;
+   struct delayed_work stats_work;
+   char queue_name[30];
+   struct workqueue_struct *stats_queue;
 };
 
 struct mvpp2_pcpu_stats {
@@ -891,6 +934,7 @@ struct mvpp2_port {
 
/* Per-port registers' base address */
void __iomem *base;
+   void __iomem *stats_base;
 
struct mvpp2_rx_queue **rxqs;
unsigned int nrxqs;
@@ -909,6 +953,7 @@ struct mvpp2_port {
u16 tx_ring_size;
u16 rx_ring_size;
struct mvpp2_pcpu_stats __percpu *stats;
+   u64 *ethtool_stats;
 
phy_interface_t phy_interface;
struct device_node *phy_node;
@@ -4778,9 +4823,136 @@ static void mvpp2_port_loopback_set(struct mvpp2_port 
*port)
writel(val, port->base + MVPP2_GMAC_CTRL_1_REG);
 }
 
+struct mvpp2_ethtool_counter {
+   unsigned int offset;
+   const char string[ETH_GSTRING_LEN];
+   bool reg_is_64b;
+};
+
+static u64 mvpp2_read_count(struct mvpp2_port *port,
+   const struct mvpp2_ethtool_counter *counter)
+{
+   u64 val;
+
+   val = readl(port->stats_base + counter->offset);
+   if (counter->reg_is_64b)
+   val += (u64)readl(port->stats_base + counter->offset + 4) << 32;
+
+   return val;
+}
+
+/* Due to the fact that software statistics and hardware statistics are, by
+ * design, incremented at different moments in the chain of packet processing,
+ * it is very likely that incoming packets could have been dropped after being
+ * counted by hardware but before reaching software