]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
dsa: mv88x6xxx: Refactor getting a single statistic
authorAndrew Lunn <andrew@lunn.ch>
Sat, 20 Jun 2015 16:42:30 +0000 (18:42 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 23 Jun 2015 13:33:40 +0000 (06:33 -0700)
Move the code to retrieve a statistics counter into a function of its
own, so it can later be reused.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/mv88e6xxx.c
drivers/net/dsa/mv88e6xxx.h

index 6e684f3d377c3152a72fb16a7a2531b7d2c2296a..43c1515a831912a7a5d715dd2c8d6e0df2586e06 100644 (file)
@@ -681,6 +681,40 @@ static void _mv88e6xxx_get_strings(struct dsa_switch *ds,
        }
 }
 
+static uint64_t _mv88e6xxx_get_ethtool_stat(struct dsa_switch *ds,
+                                           int stat,
+                                           struct mv88e6xxx_hw_stat *stats,
+                                           int port)
+{
+       struct mv88e6xxx_hw_stat *s = stats + stat;
+       u32 low;
+       u32 high = 0;
+       int ret;
+       u64 value;
+
+       if (s->reg >= 0x100) {
+               ret = _mv88e6xxx_reg_read(ds, REG_PORT(port),
+                                         s->reg - 0x100);
+               if (ret < 0)
+                       return UINT64_MAX;
+
+               low = ret;
+               if (s->sizeof_stat == 4) {
+                       ret = _mv88e6xxx_reg_read(ds, REG_PORT(port),
+                                                 s->reg - 0x100 + 1);
+                       if (ret < 0)
+                               return UINT64_MAX;
+                       high = ret;
+               }
+       } else {
+               _mv88e6xxx_stats_read(ds, s->reg, &low);
+               if (s->sizeof_stat == 8)
+                       _mv88e6xxx_stats_read(ds, s->reg + 1, &high);
+       }
+       value = (((u64)high) << 16) | low;
+       return value;
+}
+
 static void _mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds,
                                         int nr_stats,
                                         struct mv88e6xxx_hw_stat *stats,
@@ -699,34 +733,9 @@ static void _mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds,
        }
 
        /* Read each of the counters. */
-       for (i = 0; i < nr_stats; i++) {
-               struct mv88e6xxx_hw_stat *s = stats + i;
-               u32 low;
-               u32 high = 0;
+       for (i = 0; i < nr_stats; i++)
+               data[i] = _mv88e6xxx_get_ethtool_stat(ds, i, stats, port);
 
-               if (s->reg >= 0x100) {
-                       ret = _mv88e6xxx_reg_read(ds, REG_PORT(port),
-                                                 s->reg - 0x100);
-                       if (ret < 0)
-                               goto error;
-                       low = ret;
-                       if (s->sizeof_stat == 4) {
-                               ret = _mv88e6xxx_reg_read(ds, REG_PORT(port),
-                                                         s->reg - 0x100 + 1);
-                               if (ret < 0)
-                                       goto error;
-                               high = ret;
-                       }
-                       data[i] = (((u64)high) << 16) | low;
-                       continue;
-               }
-               _mv88e6xxx_stats_read(ds, s->reg, &low);
-               if (s->sizeof_stat == 8)
-                       _mv88e6xxx_stats_read(ds, s->reg + 1, &high);
-
-               data[i] = (((u64)high) << 32) | low;
-       }
-error:
        mutex_unlock(&ps->smi_mutex);
 }
 
index 8b9c76b66ddbed816179c5f0b2cee60c51d33746..7cccff20258643f394166bff06a20fcb5c4933a4 100644 (file)
 #ifndef __MV88E6XXX_H
 #define __MV88E6XXX_H
 
+#ifndef UINT64_MAX
+#define UINT64_MAX             (u64)(~((u64)0))
+#endif
+
 #define SMI_CMD                        0x00
 #define SMI_CMD_BUSY           BIT(15)
 #define SMI_CMD_CLAUSE_22      BIT(12)