Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
0002 /* Copyright 2015 Freescale Semiconductor Inc.
0003  * Copyright 2018-2019 NXP
0004  */
0005 #include <linux/module.h>
0006 #include <linux/debugfs.h>
0007 #include "dpaa2-eth.h"
0008 #include "dpaa2-eth-debugfs.h"
0009 
0010 #define DPAA2_ETH_DBG_ROOT "dpaa2-eth"
0011 
0012 static struct dentry *dpaa2_dbg_root;
0013 
0014 static int dpaa2_dbg_cpu_show(struct seq_file *file, void *offset)
0015 {
0016     struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
0017     struct rtnl_link_stats64 *stats;
0018     struct dpaa2_eth_drv_stats *extras;
0019     int i;
0020 
0021     seq_printf(file, "Per-CPU stats for %s\n", priv->net_dev->name);
0022     seq_printf(file, "%s%16s%16s%16s%16s%16s%16s%16s%16s%16s\n",
0023            "CPU", "Rx", "Rx Err", "Rx SG", "Tx", "Tx Err", "Tx conf",
0024            "Tx SG", "Tx converted to SG", "Enq busy");
0025 
0026     for_each_online_cpu(i) {
0027         stats = per_cpu_ptr(priv->percpu_stats, i);
0028         extras = per_cpu_ptr(priv->percpu_extras, i);
0029         seq_printf(file, "%3d%16llu%16llu%16llu%16llu%16llu%16llu%16llu%16llu%16llu\n",
0030                i,
0031                stats->rx_packets,
0032                stats->rx_errors,
0033                extras->rx_sg_frames,
0034                stats->tx_packets,
0035                stats->tx_errors,
0036                extras->tx_conf_frames,
0037                extras->tx_sg_frames,
0038                extras->tx_converted_sg_frames,
0039                extras->tx_portal_busy);
0040     }
0041 
0042     return 0;
0043 }
0044 
0045 DEFINE_SHOW_ATTRIBUTE(dpaa2_dbg_cpu);
0046 
0047 static char *fq_type_to_str(struct dpaa2_eth_fq *fq)
0048 {
0049     switch (fq->type) {
0050     case DPAA2_RX_FQ:
0051         return "Rx";
0052     case DPAA2_TX_CONF_FQ:
0053         return "Tx conf";
0054     default:
0055         return "N/A";
0056     }
0057 }
0058 
0059 static int dpaa2_dbg_fqs_show(struct seq_file *file, void *offset)
0060 {
0061     struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
0062     struct dpaa2_eth_fq *fq;
0063     u32 fcnt, bcnt;
0064     int i, err;
0065 
0066     seq_printf(file, "FQ stats for %s:\n", priv->net_dev->name);
0067     seq_printf(file, "%s%16s%16s%16s%16s%16s\n",
0068            "VFQID", "CPU", "TC", "Type", "Frames", "Pending frames");
0069 
0070     for (i = 0; i <  priv->num_fqs; i++) {
0071         fq = &priv->fq[i];
0072         err = dpaa2_io_query_fq_count(NULL, fq->fqid, &fcnt, &bcnt);
0073         if (err)
0074             fcnt = 0;
0075 
0076         /* Skip FQs with no traffic */
0077         if (!fq->stats.frames && !fcnt)
0078             continue;
0079 
0080         seq_printf(file, "%5d%16d%16d%16s%16llu%16u\n",
0081                fq->fqid,
0082                fq->target_cpu,
0083                fq->tc,
0084                fq_type_to_str(fq),
0085                fq->stats.frames,
0086                fcnt);
0087     }
0088 
0089     return 0;
0090 }
0091 
0092 DEFINE_SHOW_ATTRIBUTE(dpaa2_dbg_fqs);
0093 
0094 static int dpaa2_dbg_ch_show(struct seq_file *file, void *offset)
0095 {
0096     struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
0097     struct dpaa2_eth_channel *ch;
0098     int i;
0099 
0100     seq_printf(file, "Channel stats for %s:\n", priv->net_dev->name);
0101     seq_printf(file, "%s%16s%16s%16s%16s%16s%16s\n",
0102            "CHID", "CPU", "Deq busy", "Frames", "CDANs",
0103            "Avg Frm/CDAN", "Buf count");
0104 
0105     for (i = 0; i < priv->num_channels; i++) {
0106         ch = priv->channel[i];
0107         seq_printf(file, "%4d%16d%16llu%16llu%16llu%16llu%16d\n",
0108                ch->ch_id,
0109                ch->nctx.desired_cpu,
0110                ch->stats.dequeue_portal_busy,
0111                ch->stats.frames,
0112                ch->stats.cdan,
0113                div64_u64(ch->stats.frames, ch->stats.cdan),
0114                ch->buf_count);
0115     }
0116 
0117     return 0;
0118 }
0119 
0120 DEFINE_SHOW_ATTRIBUTE(dpaa2_dbg_ch);
0121 
0122 void dpaa2_dbg_add(struct dpaa2_eth_priv *priv)
0123 {
0124     struct fsl_mc_device *dpni_dev;
0125     struct dentry *dir;
0126     char name[10];
0127 
0128     /* Create a directory for the interface */
0129     dpni_dev = to_fsl_mc_device(priv->net_dev->dev.parent);
0130     snprintf(name, 10, "dpni.%d", dpni_dev->obj_desc.id);
0131     dir = debugfs_create_dir(name, dpaa2_dbg_root);
0132     priv->dbg.dir = dir;
0133 
0134     /* per-cpu stats file */
0135     debugfs_create_file("cpu_stats", 0444, dir, priv, &dpaa2_dbg_cpu_fops);
0136 
0137     /* per-fq stats file */
0138     debugfs_create_file("fq_stats", 0444, dir, priv, &dpaa2_dbg_fqs_fops);
0139 
0140     /* per-fq stats file */
0141     debugfs_create_file("ch_stats", 0444, dir, priv, &dpaa2_dbg_ch_fops);
0142 }
0143 
0144 void dpaa2_dbg_remove(struct dpaa2_eth_priv *priv)
0145 {
0146     debugfs_remove_recursive(priv->dbg.dir);
0147 }
0148 
0149 void dpaa2_eth_dbg_init(void)
0150 {
0151     dpaa2_dbg_root = debugfs_create_dir(DPAA2_ETH_DBG_ROOT, NULL);
0152     pr_debug("DPAA2-ETH: debugfs created\n");
0153 }
0154 
0155 void dpaa2_eth_dbg_exit(void)
0156 {
0157     debugfs_remove(dpaa2_dbg_root);
0158 }