[PATCH 3/6] net: ldpaa_eth: extend debug capabilities with DPNI statistics

Ramon Fried rfried.dev at gmail.com
Sat Jun 10 12:47:23 CEST 2023


On Tue, May 23, 2023 at 4:48 PM Ioana Ciornei <ioana.ciornei at nxp.com> wrote:
>
> The ldpaa_eth driver already had a DPNI statistics dump, this patch
> extends the list of stats and adds a bit more structure to the code.
>
> For a bit more context, the DPAA2 u-boot software architecture uses a
> default network interface object - a DPNI - which, at runtime, will get
> connected to the currently used DPMAC object.
> Each time the .stop() eth callback is called, the DPNI is reset to its
> original state, including its counters.
>
> As a preparation for the next patches, we add a software kept set of
> DPNI counters which will get updated before each reset operation takes
> place.
>
> Signed-off-by: Ioana Ciornei <ioana.ciornei at nxp.com>
> ---
>  drivers/net/ldpaa_eth/ldpaa_eth.c | 106 +++++++++++++++---------------
>  drivers/net/ldpaa_eth/ldpaa_eth.h |  30 +++++++++
>  2 files changed, 82 insertions(+), 54 deletions(-)
>
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
> index fe901baf5a4e..907e51da6e1e 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> @@ -38,68 +38,56 @@ static void init_phy(struct udevice *dev)
>  }
>  #endif
>
> -#ifdef DEBUG
> +static void ldpaa_eth_collect_dpni_stats(struct udevice *dev, u64 *data)
> +{
> +       union dpni_statistics dpni_stats;
> +       int dpni_stats_page_size[DPNI_STATISTICS_CNT] = {
> +               sizeof(dpni_stats.page_0),
> +               sizeof(dpni_stats.page_1),
> +               sizeof(dpni_stats.page_2),
> +               sizeof(dpni_stats.page_3),
> +               sizeof(dpni_stats.page_4),
> +               sizeof(dpni_stats.page_5),
> +               sizeof(dpni_stats.page_6),
> +       };
> +       int j, k, num_cnt, err, i = 0;
>
> -#define DPNI_STATS_PER_PAGE 6
> -
> -static const char *dpni_statistics[][DPNI_STATS_PER_PAGE] = {
> -       {
> -       "DPNI_CNT_ING_ALL_FRAMES",
> -       "DPNI_CNT_ING_ALL_BYTES",
> -       "DPNI_CNT_ING_MCAST_FRAMES",
> -       "DPNI_CNT_ING_MCAST_BYTES",
> -       "DPNI_CNT_ING_BCAST_FRAMES",
> -       "DPNI_CNT_ING_BCAST_BYTES",
> -       }, {
> -       "DPNI_CNT_EGR_ALL_FRAMES",
> -       "DPNI_CNT_EGR_ALL_BYTES",
> -       "DPNI_CNT_EGR_MCAST_FRAMES",
> -       "DPNI_CNT_EGR_MCAST_BYTES",
> -       "DPNI_CNT_EGR_BCAST_FRAMES",
> -       "DPNI_CNT_EGR_BCAST_BYTES",
> -       }, {
> -       "DPNI_CNT_ING_FILTERED_FRAMES",
> -       "DPNI_CNT_ING_DISCARDED_FRAMES",
> -       "DPNI_CNT_ING_NOBUFFER_DISCARDS",
> -       "DPNI_CNT_EGR_DISCARDED_FRAMES",
> -       "DPNI_CNT_EGR_CNF_FRAMES",
> -       ""
> -       },
> -};
> +       for (j = 0; j <= 6; j++) {
> +               /* We're not interested in pages 4 & 5 for now */
> +               if (j == 4 || j == 5)
> +                       continue;
> +               err = dpni_get_statistics(dflt_mc_io, MC_CMD_NO_FLAGS,
> +                                         dflt_dpni->dpni_handle,
> +                                         j, &dpni_stats);
> +               if (err) {
> +                       memset(&dpni_stats, 0, sizeof(dpni_stats));
> +                       printf("dpni_get_stats(%d) failed\n", j);
> +               }
> +
> +               num_cnt = dpni_stats_page_size[j] / sizeof(u64);
> +               for (k = 0; k < num_cnt; k++)
> +                       *(data + i++) = dpni_stats.raw.counter[k];
> +       }
> +}
>
> -static void print_dpni_stats(const char *strings[],
> -                            union dpni_statistics dpni_stats)
> +static void ldpaa_eth_add_dpni_stats(struct udevice *dev, u64 *data)
>  {
> -       uint64_t *stat;
> +       struct ldpaa_eth_priv *priv = dev_get_priv(dev);
>         int i;
>
> -       stat = (uint64_t *)&dpni_stats;
> -       for (i = 0; i < DPNI_STATS_PER_PAGE; i++) {
> -               if (strcmp(strings[i], "\0") == 0)
> -                       break;
> -               printf("%s= %llu\n", strings[i], *stat);
> -               stat++;
> -       }
> +       for (i = 0; i < LDPAA_ETH_DPNI_NUM_STATS; i++)
> +               priv->dpni_stats[i] += data[i];
>  }
>
> -static void ldpaa_eth_get_dpni_counter(void)
> +#ifdef DEBUG
> +
> +static void ldpaa_eth_dump_dpni_stats(struct udevice *dev, u64 *data)
>  {
> -       int err = 0;
> -       unsigned int page = 0;
> -       union dpni_statistics dpni_stats;
> +       int i;
>
> -       printf("DPNI counters ..\n");
> -       for (page = 0; page < 3; page++) {
> -               err = dpni_get_statistics(dflt_mc_io, MC_CMD_NO_FLAGS,
> -                                         dflt_dpni->dpni_handle, page,
> -                                         &dpni_stats);
> -               if (err < 0) {
> -                       printf("dpni_get_statistics: failed:");
> -                       printf("%d for page[%d]\n", err, page);
> -                       return;
> -               }
> -               print_dpni_stats(dpni_statistics[page], dpni_stats);
> -       }
> +       printf("DPNI counters:\n");
> +       for (i = 0; i < LDPAA_ETH_DPNI_NUM_STATS; i++)
> +               printf("  %s: %llu\n", ldpaa_eth_dpni_stat_strings[i], data[i]);
>  }
>
>  static void ldpaa_eth_get_dpmac_counter(struct udevice *dev)
> @@ -556,12 +544,22 @@ static void ldpaa_eth_stop(struct udevice *dev)
>         struct ldpaa_eth_priv *priv = dev_get_priv(dev);
>         struct phy_device *phydev = NULL;
>         int err = 0;
> +       u64 *data;
>
>         if (!eth_is_active(dev))
>                 return;
>
> +       data = kzalloc(sizeof(u64) * LDPAA_ETH_DPNI_NUM_STATS, GFP_KERNEL);
> +       if (data) {
> +               ldpaa_eth_collect_dpni_stats(dev, data);
> +               ldpaa_eth_add_dpni_stats(dev, data);
> +#ifdef DEBUG
> +               ldpaa_eth_dump_dpni_stats(dev, data);
> +#endif
> +       }
> +       kfree(data);
> +
>  #ifdef DEBUG
> -       ldpaa_eth_get_dpni_counter();
>         ldpaa_eth_get_dpmac_counter(dev);
>  #endif
>
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.h b/drivers/net/ldpaa_eth/ldpaa_eth.h
> index 16d0106233e0..62dc9dd31029 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.h
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.h
> @@ -115,6 +115,33 @@ struct ldpaa_fas {
>                                          LDPAA_ETH_FAS_MNLE     | \
>                                          LDPAA_ETH_FAS_TIDE)
>
> +static const char ldpaa_eth_dpni_stat_strings[][ETH_GSTRING_LEN] = {
> +       "[dpni ] rx frames",
> +       "[dpni ] rx bytes",
> +       "[dpni ] rx mcast frames",
> +       "[dpni ] rx mcast bytes",
> +       "[dpni ] rx bcast frames",
> +       "[dpni ] rx bcast bytes",
> +       "[dpni ] tx frames",
> +       "[dpni ] tx bytes",
> +       "[dpni ] tx mcast frames",
> +       "[dpni ] tx mcast bytes",
> +       "[dpni ] tx bcast frames",
> +       "[dpni ] tx bcast bytes",
> +       "[dpni ] rx filtered frames",
> +       "[dpni ] rx discarded frames",
> +       "[dpni ] rx nobuffer discards",
> +       "[dpni ] tx discarded frames",
> +       "[dpni ] tx confirmed frames",
> +       "[dpni ] tx dequeued bytes",
> +       "[dpni ] tx dequeued frames",
> +       "[dpni ] tx rejected bytes",
> +       "[dpni ] tx rejected frames",
> +       "[dpni ] tx pending frames",
> +};
> +
> +#define LDPAA_ETH_DPNI_NUM_STATS       ARRAY_SIZE(ldpaa_eth_dpni_stat_strings)
> +
>  struct ldpaa_eth_priv {
>         struct phy_device *phy;
>         int phy_mode;
> @@ -129,6 +156,9 @@ struct ldpaa_eth_priv {
>         uint16_t tx_flow_id;
>
>         enum ldpaa_eth_type type;       /* 1G or 10G ethernet */
> +
> +       /* SW kept statistics */
> +       u64 dpni_stats[LDPAA_ETH_DPNI_NUM_STATS];
>  };
>
>  struct dprc_endpoint dpmac_endpoint;
> --
> 2.25.1
>
Reviewed-by: Ramon Fried <rfried.dev at gmail.com>


More information about the U-Boot mailing list