Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Vladimir Oltean and committed by
David S. Miller
497eea9f 1a733bbd

+29 -11
+29 -11
drivers/net/ethernet/mscc/ocelot_stats.c
··· 228 228 OCELOT_COMMON_STATS, 229 229 }; 230 230 231 + static const struct ocelot_stat_layout * 232 + ocelot_get_stats_layout(struct ocelot *ocelot) 233 + { 234 + return ocelot_stats_layout; 235 + } 236 + 231 237 /* Read the counters from hardware and keep them in region->buf. 232 238 * Caller must hold &ocelot->stat_view_lock. 233 239 */ ··· 312 306 313 307 void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data) 314 308 { 309 + const struct ocelot_stat_layout *layout; 315 310 int i; 316 311 317 312 if (sset != ETH_SS_STATS) 318 313 return; 319 314 315 + layout = ocelot_get_stats_layout(ocelot); 316 + 320 317 for (i = 0; i < OCELOT_NUM_STATS; i++) { 321 - if (ocelot_stats_layout[i].name[0] == '\0') 318 + if (layout[i].name[0] == '\0') 322 319 continue; 323 320 324 - memcpy(data, ocelot_stats_layout[i].name, ETH_GSTRING_LEN); 321 + memcpy(data, layout[i].name, ETH_GSTRING_LEN); 325 322 data += ETH_GSTRING_LEN; 326 323 } 327 324 } ··· 359 350 360 351 int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset) 361 352 { 353 + const struct ocelot_stat_layout *layout; 362 354 int i, num_stats = 0; 363 355 364 356 if (sset != ETH_SS_STATS) 365 357 return -EOPNOTSUPP; 366 358 359 + layout = ocelot_get_stats_layout(ocelot); 360 + 367 361 for (i = 0; i < OCELOT_NUM_STATS; i++) 368 - if (ocelot_stats_layout[i].name[0] != '\0') 362 + if (layout[i].name[0] != '\0') 369 363 num_stats++; 370 364 371 365 return num_stats; ··· 378 366 static void ocelot_port_ethtool_stats_cb(struct ocelot *ocelot, int port, 379 367 void *priv) 380 368 { 369 + const struct ocelot_stat_layout *layout; 381 370 u64 *data = priv; 382 371 int i; 372 + 373 + layout = ocelot_get_stats_layout(ocelot); 383 374 384 375 /* Copy all supported counters */ 385 376 for (i = 0; i < OCELOT_NUM_STATS; i++) { 386 377 int index = port * OCELOT_NUM_STATS + i; 387 378 388 - if (ocelot_stats_layout[i].name[0] == '\0') 379 + if (layout[i].name[0] == '\0') 389 380 continue; 390 381 391 382 *data++ = ocelot->stats[index]; ··· 617 602 static int ocelot_prepare_stats_regions(struct ocelot *ocelot) 618 603 { 619 604 struct ocelot_stats_region *region = NULL; 605 + const struct ocelot_stat_layout *layout; 620 606 unsigned int last = 0; 621 607 int i; 622 608 623 609 INIT_LIST_HEAD(&ocelot->stats_regions); 624 610 611 + layout = ocelot_get_stats_layout(ocelot); 612 + 625 613 for (i = 0; i < OCELOT_NUM_STATS; i++) { 626 - if (!ocelot_stats_layout[i].reg) 614 + if (!layout[i].reg) 627 615 continue; 628 616 629 - if (region && ocelot_stats_layout[i].reg == last + 4) { 617 + if (region && layout[i].reg == last + 4) { 630 618 region->count++; 631 619 } else { 632 620 region = devm_kzalloc(ocelot->dev, sizeof(*region), ··· 638 620 return -ENOMEM; 639 621 640 622 /* enum ocelot_stat must be kept sorted in the same 641 - * order as ocelot_stats_layout[i].reg in order to have 642 - * efficient bulking 623 + * order as layout[i].reg in order to have efficient 624 + * bulking 643 625 */ 644 - WARN_ON(last >= ocelot_stats_layout[i].reg); 626 + WARN_ON(last >= layout[i].reg); 645 627 646 - region->base = ocelot_stats_layout[i].reg; 628 + region->base = layout[i].reg; 647 629 region->count = 1; 648 630 list_add_tail(&region->node, &ocelot->stats_regions); 649 631 } 650 632 651 - last = ocelot_stats_layout[i].reg; 633 + last = layout[i].reg; 652 634 } 653 635 654 636 list_for_each_entry(region, &ocelot->stats_regions, node) {