Skip to content

Commit 497eea9

Browse files
vladimirolteandavem330
authored andcommitted
net: mscc: ocelot: hide access to ocelot_stats_layout behind a helper
Some hardware instances of the ocelot driver support the MAC Merge layer, which gives access to an extra preemptible MAC. This has implications upon the statistics. There will be a stats layout when MM isn't supported, and a different one when it is. The ocelot_stats_layout() helper will return the correct one. In preparation of that, refactor the existing code to use this helper. Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1a733bb commit 497eea9

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

drivers/net/ethernet/mscc/ocelot_stats.c

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ static const struct ocelot_stat_layout ocelot_stats_layout[OCELOT_NUM_STATS] = {
228228
OCELOT_COMMON_STATS,
229229
};
230230

231+
static const struct ocelot_stat_layout *
232+
ocelot_get_stats_layout(struct ocelot *ocelot)
233+
{
234+
return ocelot_stats_layout;
235+
}
236+
231237
/* Read the counters from hardware and keep them in region->buf.
232238
* Caller must hold &ocelot->stat_view_lock.
233239
*/
@@ -306,16 +312,19 @@ static void ocelot_check_stats_work(struct work_struct *work)
306312

307313
void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data)
308314
{
315+
const struct ocelot_stat_layout *layout;
309316
int i;
310317

311318
if (sset != ETH_SS_STATS)
312319
return;
313320

321+
layout = ocelot_get_stats_layout(ocelot);
322+
314323
for (i = 0; i < OCELOT_NUM_STATS; i++) {
315-
if (ocelot_stats_layout[i].name[0] == '\0')
324+
if (layout[i].name[0] == '\0')
316325
continue;
317326

318-
memcpy(data, ocelot_stats_layout[i].name, ETH_GSTRING_LEN);
327+
memcpy(data, layout[i].name, ETH_GSTRING_LEN);
319328
data += ETH_GSTRING_LEN;
320329
}
321330
}
@@ -350,13 +359,16 @@ static void ocelot_port_stats_run(struct ocelot *ocelot, int port, void *priv,
350359

351360
int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset)
352361
{
362+
const struct ocelot_stat_layout *layout;
353363
int i, num_stats = 0;
354364

355365
if (sset != ETH_SS_STATS)
356366
return -EOPNOTSUPP;
357367

368+
layout = ocelot_get_stats_layout(ocelot);
369+
358370
for (i = 0; i < OCELOT_NUM_STATS; i++)
359-
if (ocelot_stats_layout[i].name[0] != '\0')
371+
if (layout[i].name[0] != '\0')
360372
num_stats++;
361373

362374
return num_stats;
@@ -366,14 +378,17 @@ EXPORT_SYMBOL(ocelot_get_sset_count);
366378
static void ocelot_port_ethtool_stats_cb(struct ocelot *ocelot, int port,
367379
void *priv)
368380
{
381+
const struct ocelot_stat_layout *layout;
369382
u64 *data = priv;
370383
int i;
371384

385+
layout = ocelot_get_stats_layout(ocelot);
386+
372387
/* Copy all supported counters */
373388
for (i = 0; i < OCELOT_NUM_STATS; i++) {
374389
int index = port * OCELOT_NUM_STATS + i;
375390

376-
if (ocelot_stats_layout[i].name[0] == '\0')
391+
if (layout[i].name[0] == '\0')
377392
continue;
378393

379394
*data++ = ocelot->stats[index];
@@ -602,16 +617,19 @@ EXPORT_SYMBOL(ocelot_port_get_stats64);
602617
static int ocelot_prepare_stats_regions(struct ocelot *ocelot)
603618
{
604619
struct ocelot_stats_region *region = NULL;
620+
const struct ocelot_stat_layout *layout;
605621
unsigned int last = 0;
606622
int i;
607623

608624
INIT_LIST_HEAD(&ocelot->stats_regions);
609625

626+
layout = ocelot_get_stats_layout(ocelot);
627+
610628
for (i = 0; i < OCELOT_NUM_STATS; i++) {
611-
if (!ocelot_stats_layout[i].reg)
629+
if (!layout[i].reg)
612630
continue;
613631

614-
if (region && ocelot_stats_layout[i].reg == last + 4) {
632+
if (region && layout[i].reg == last + 4) {
615633
region->count++;
616634
} else {
617635
region = devm_kzalloc(ocelot->dev, sizeof(*region),
@@ -620,17 +638,17 @@ static int ocelot_prepare_stats_regions(struct ocelot *ocelot)
620638
return -ENOMEM;
621639

622640
/* enum ocelot_stat must be kept sorted in the same
623-
* order as ocelot_stats_layout[i].reg in order to have
624-
* efficient bulking
641+
* order as layout[i].reg in order to have efficient
642+
* bulking
625643
*/
626-
WARN_ON(last >= ocelot_stats_layout[i].reg);
644+
WARN_ON(last >= layout[i].reg);
627645

628-
region->base = ocelot_stats_layout[i].reg;
646+
region->base = layout[i].reg;
629647
region->count = 1;
630648
list_add_tail(&region->node, &ocelot->stats_regions);
631649
}
632650

633-
last = ocelot_stats_layout[i].reg;
651+
last = layout[i].reg;
634652
}
635653

636654
list_for_each_entry(region, &ocelot->stats_regions, node) {

0 commit comments

Comments
 (0)