Skip to content

Commit 776b71e

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: felix: use ocelot's ndo_get_stats64 method
Move the logic from the ocelot switchdev driver's ocelot_get_stats64() method to the common switch lib and reuse it for the DSA driver. Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d50e41b commit 776b71e

File tree

4 files changed

+78
-61
lines changed

4 files changed

+78
-61
lines changed

drivers/net/dsa/ocelot/felix.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,14 @@ static void felix_port_qos_map_init(struct ocelot *ocelot, int port)
10341034
}
10351035
}
10361036

1037+
static void felix_get_stats64(struct dsa_switch *ds, int port,
1038+
struct rtnl_link_stats64 *stats)
1039+
{
1040+
struct ocelot *ocelot = ds->priv;
1041+
1042+
ocelot_port_get_stats64(ocelot, port, stats);
1043+
}
1044+
10371045
static void felix_get_strings(struct dsa_switch *ds, int port,
10381046
u32 stringset, u8 *data)
10391047
{
@@ -1848,6 +1856,7 @@ const struct dsa_switch_ops felix_switch_ops = {
18481856
.setup = felix_setup,
18491857
.teardown = felix_teardown,
18501858
.set_ageing_time = felix_set_ageing_time,
1859+
.get_stats64 = felix_get_stats64,
18511860
.get_strings = felix_get_strings,
18521861
.get_ethtool_stats = felix_get_ethtool_stats,
18531862
.get_sset_count = felix_get_sset_count,

drivers/net/ethernet/mscc/ocelot_net.c

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -732,67 +732,8 @@ static void ocelot_get_stats64(struct net_device *dev,
732732
struct ocelot_port_private *priv = netdev_priv(dev);
733733
struct ocelot *ocelot = priv->port.ocelot;
734734
int port = priv->port.index;
735-
u64 *s;
736-
737-
spin_lock(&ocelot->stats_lock);
738-
739-
s = &ocelot->stats[port * OCELOT_NUM_STATS];
740-
741-
/* Get Rx stats */
742-
stats->rx_bytes = s[OCELOT_STAT_RX_OCTETS];
743-
stats->rx_packets = s[OCELOT_STAT_RX_SHORTS] +
744-
s[OCELOT_STAT_RX_FRAGMENTS] +
745-
s[OCELOT_STAT_RX_JABBERS] +
746-
s[OCELOT_STAT_RX_LONGS] +
747-
s[OCELOT_STAT_RX_64] +
748-
s[OCELOT_STAT_RX_65_127] +
749-
s[OCELOT_STAT_RX_128_255] +
750-
s[OCELOT_STAT_RX_256_511] +
751-
s[OCELOT_STAT_RX_512_1023] +
752-
s[OCELOT_STAT_RX_1024_1526] +
753-
s[OCELOT_STAT_RX_1527_MAX];
754-
stats->multicast = s[OCELOT_STAT_RX_MULTICAST];
755-
stats->rx_missed_errors = s[OCELOT_STAT_DROP_TAIL];
756-
stats->rx_dropped = s[OCELOT_STAT_RX_RED_PRIO_0] +
757-
s[OCELOT_STAT_RX_RED_PRIO_1] +
758-
s[OCELOT_STAT_RX_RED_PRIO_2] +
759-
s[OCELOT_STAT_RX_RED_PRIO_3] +
760-
s[OCELOT_STAT_RX_RED_PRIO_4] +
761-
s[OCELOT_STAT_RX_RED_PRIO_5] +
762-
s[OCELOT_STAT_RX_RED_PRIO_6] +
763-
s[OCELOT_STAT_RX_RED_PRIO_7] +
764-
s[OCELOT_STAT_DROP_LOCAL] +
765-
s[OCELOT_STAT_DROP_YELLOW_PRIO_0] +
766-
s[OCELOT_STAT_DROP_YELLOW_PRIO_1] +
767-
s[OCELOT_STAT_DROP_YELLOW_PRIO_2] +
768-
s[OCELOT_STAT_DROP_YELLOW_PRIO_3] +
769-
s[OCELOT_STAT_DROP_YELLOW_PRIO_4] +
770-
s[OCELOT_STAT_DROP_YELLOW_PRIO_5] +
771-
s[OCELOT_STAT_DROP_YELLOW_PRIO_6] +
772-
s[OCELOT_STAT_DROP_YELLOW_PRIO_7] +
773-
s[OCELOT_STAT_DROP_GREEN_PRIO_0] +
774-
s[OCELOT_STAT_DROP_GREEN_PRIO_1] +
775-
s[OCELOT_STAT_DROP_GREEN_PRIO_2] +
776-
s[OCELOT_STAT_DROP_GREEN_PRIO_3] +
777-
s[OCELOT_STAT_DROP_GREEN_PRIO_4] +
778-
s[OCELOT_STAT_DROP_GREEN_PRIO_5] +
779-
s[OCELOT_STAT_DROP_GREEN_PRIO_6] +
780-
s[OCELOT_STAT_DROP_GREEN_PRIO_7];
781-
782-
/* Get Tx stats */
783-
stats->tx_bytes = s[OCELOT_STAT_TX_OCTETS];
784-
stats->tx_packets = s[OCELOT_STAT_TX_64] +
785-
s[OCELOT_STAT_TX_65_127] +
786-
s[OCELOT_STAT_TX_128_255] +
787-
s[OCELOT_STAT_TX_256_511] +
788-
s[OCELOT_STAT_TX_512_1023] +
789-
s[OCELOT_STAT_TX_1024_1526] +
790-
s[OCELOT_STAT_TX_1527_MAX];
791-
stats->tx_dropped = s[OCELOT_STAT_TX_DROPS] +
792-
s[OCELOT_STAT_TX_AGED];
793-
stats->collisions = s[OCELOT_STAT_TX_COLLISION];
794-
795-
spin_unlock(&ocelot->stats_lock);
735+
736+
return ocelot_port_get_stats64(ocelot, port, stats);
796737
}
797738

798739
static int ocelot_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],

drivers/net/ethernet/mscc/ocelot_stats.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,71 @@ int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset)
148148
}
149149
EXPORT_SYMBOL(ocelot_get_sset_count);
150150

151+
void ocelot_port_get_stats64(struct ocelot *ocelot, int port,
152+
struct rtnl_link_stats64 *stats)
153+
{
154+
u64 *s = &ocelot->stats[port * OCELOT_NUM_STATS];
155+
156+
spin_lock(&ocelot->stats_lock);
157+
158+
/* Get Rx stats */
159+
stats->rx_bytes = s[OCELOT_STAT_RX_OCTETS];
160+
stats->rx_packets = s[OCELOT_STAT_RX_SHORTS] +
161+
s[OCELOT_STAT_RX_FRAGMENTS] +
162+
s[OCELOT_STAT_RX_JABBERS] +
163+
s[OCELOT_STAT_RX_LONGS] +
164+
s[OCELOT_STAT_RX_64] +
165+
s[OCELOT_STAT_RX_65_127] +
166+
s[OCELOT_STAT_RX_128_255] +
167+
s[OCELOT_STAT_RX_256_511] +
168+
s[OCELOT_STAT_RX_512_1023] +
169+
s[OCELOT_STAT_RX_1024_1526] +
170+
s[OCELOT_STAT_RX_1527_MAX];
171+
stats->multicast = s[OCELOT_STAT_RX_MULTICAST];
172+
stats->rx_missed_errors = s[OCELOT_STAT_DROP_TAIL];
173+
stats->rx_dropped = s[OCELOT_STAT_RX_RED_PRIO_0] +
174+
s[OCELOT_STAT_RX_RED_PRIO_1] +
175+
s[OCELOT_STAT_RX_RED_PRIO_2] +
176+
s[OCELOT_STAT_RX_RED_PRIO_3] +
177+
s[OCELOT_STAT_RX_RED_PRIO_4] +
178+
s[OCELOT_STAT_RX_RED_PRIO_5] +
179+
s[OCELOT_STAT_RX_RED_PRIO_6] +
180+
s[OCELOT_STAT_RX_RED_PRIO_7] +
181+
s[OCELOT_STAT_DROP_LOCAL] +
182+
s[OCELOT_STAT_DROP_YELLOW_PRIO_0] +
183+
s[OCELOT_STAT_DROP_YELLOW_PRIO_1] +
184+
s[OCELOT_STAT_DROP_YELLOW_PRIO_2] +
185+
s[OCELOT_STAT_DROP_YELLOW_PRIO_3] +
186+
s[OCELOT_STAT_DROP_YELLOW_PRIO_4] +
187+
s[OCELOT_STAT_DROP_YELLOW_PRIO_5] +
188+
s[OCELOT_STAT_DROP_YELLOW_PRIO_6] +
189+
s[OCELOT_STAT_DROP_YELLOW_PRIO_7] +
190+
s[OCELOT_STAT_DROP_GREEN_PRIO_0] +
191+
s[OCELOT_STAT_DROP_GREEN_PRIO_1] +
192+
s[OCELOT_STAT_DROP_GREEN_PRIO_2] +
193+
s[OCELOT_STAT_DROP_GREEN_PRIO_3] +
194+
s[OCELOT_STAT_DROP_GREEN_PRIO_4] +
195+
s[OCELOT_STAT_DROP_GREEN_PRIO_5] +
196+
s[OCELOT_STAT_DROP_GREEN_PRIO_6] +
197+
s[OCELOT_STAT_DROP_GREEN_PRIO_7];
198+
199+
/* Get Tx stats */
200+
stats->tx_bytes = s[OCELOT_STAT_TX_OCTETS];
201+
stats->tx_packets = s[OCELOT_STAT_TX_64] +
202+
s[OCELOT_STAT_TX_65_127] +
203+
s[OCELOT_STAT_TX_128_255] +
204+
s[OCELOT_STAT_TX_256_511] +
205+
s[OCELOT_STAT_TX_512_1023] +
206+
s[OCELOT_STAT_TX_1024_1526] +
207+
s[OCELOT_STAT_TX_1527_MAX];
208+
stats->tx_dropped = s[OCELOT_STAT_TX_DROPS] +
209+
s[OCELOT_STAT_TX_AGED];
210+
stats->collisions = s[OCELOT_STAT_TX_COLLISION];
211+
212+
spin_unlock(&ocelot->stats_lock);
213+
}
214+
EXPORT_SYMBOL(ocelot_port_get_stats64);
215+
151216
static int ocelot_prepare_stats_regions(struct ocelot *ocelot)
152217
{
153218
struct ocelot_stats_region *region = NULL;

include/soc/mscc/ocelot.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,8 @@ u32 ocelot_port_assigned_dsa_8021q_cpu_mask(struct ocelot *ocelot, int port);
10431043
void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data);
10441044
void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data);
10451045
int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset);
1046+
void ocelot_port_get_stats64(struct ocelot *ocelot, int port,
1047+
struct rtnl_link_stats64 *stats);
10461048
int ocelot_get_ts_info(struct ocelot *ocelot, int port,
10471049
struct ethtool_ts_info *info);
10481050
void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs);

0 commit comments

Comments
 (0)