| 1 |
// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) |
| 2 |
/* Copyright 2015 Freescale Semiconductor Inc. |
| 3 |
* Copyright 2018-2019 NXP |
| 4 |
*/ |
| 5 |
#include <linux/module.h> |
| 6 |
#include <linux/debugfs.h> |
| 7 |
#include "dpaa2-eth.h" |
| 8 |
#include "dpaa2-eth-debugfs.h" |
| 9 |
|
| 10 |
#define DPAA2_ETH_DBG_ROOT "dpaa2-eth" |
| 11 |
|
| 12 |
static struct dentry *dpaa2_dbg_root; |
| 13 |
|
| 14 |
static int dpaa2_dbg_cpu_show(struct seq_file *file, void *offset) |
| 15 |
{ |
| 16 |
struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private; |
| 17 |
struct rtnl_link_stats64 *stats; |
| 18 |
struct dpaa2_eth_drv_stats *extras; |
| 19 |
int i; |
| 20 |
|
| 21 |
seq_printf(file, "Per-CPU stats for %s\n", priv->net_dev->name); |
| 22 |
seq_printf(file, "%s%16s%16s%16s%16s%16s%16s%16s%16s%16s\n", |
| 23 |
"CPU", "Rx", "Rx Err", "Rx SG", "Tx", "Tx Err", "Tx conf", |
| 24 |
"Tx SG", "Tx converted to SG", "Enq busy"); |
| 25 |
|
| 26 |
for_each_online_cpu(i) { |
| 27 |
stats = per_cpu_ptr(priv->percpu_stats, i); |
| 28 |
extras = per_cpu_ptr(priv->percpu_extras, i); |
| 29 |
seq_printf(file, "%3d%16llu%16llu%16llu%16llu%16llu%16llu%16llu%16llu%16llu\n", |
| 30 |
i, |
| 31 |
stats->rx_packets, |
| 32 |
stats->rx_errors, |
| 33 |
extras->rx_sg_frames, |
| 34 |
stats->tx_packets, |
| 35 |
stats->tx_errors, |
| 36 |
extras->tx_conf_frames, |
| 37 |
extras->tx_sg_frames, |
| 38 |
extras->tx_converted_sg_frames, |
| 39 |
extras->tx_portal_busy); |
| 40 |
} |
| 41 |
|
| 42 |
return 0; |
| 43 |
} |
| 44 |
|
| 45 |
DEFINE_SHOW_ATTRIBUTE(dpaa2_dbg_cpu); |
| 46 |
|
| 47 |
static char *fq_type_to_str(struct dpaa2_eth_fq *fq) |
| 48 |
{ |
| 49 |
switch (fq->type) { |
| 50 |
case DPAA2_RX_FQ: |
| 51 |
return "Rx"; |
| 52 |
case DPAA2_TX_CONF_FQ: |
| 53 |
return "Tx conf"; |
| 54 |
default: |
| 55 |
return "N/A"; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
static int dpaa2_dbg_fqs_show(struct seq_file *file, void *offset) |
| 60 |
{ |
| 61 |
struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private; |
| 62 |
struct dpaa2_eth_fq *fq; |
| 63 |
u32 fcnt, bcnt; |
| 64 |
int i, err; |
| 65 |
|
| 66 |
seq_printf(file, "FQ stats for %s:\n", priv->net_dev->name); |
| 67 |
seq_printf(file, "%s%16s%16s%16s%16s%16s\n", |
| 68 |
"VFQID", "CPU", "TC", "Type", "Frames", "Pending frames"); |
| 69 |
|
| 70 |
for (i = 0; i < priv->num_fqs; i++) { |
| 71 |
fq = &priv->fq[i]; |
| 72 |
err = dpaa2_io_query_fq_count(NULL, fq->fqid, &fcnt, &bcnt); |
| 73 |
if (err) |
| 74 |
fcnt = 0; |
| 75 |
|
| 76 |
/* Skip FQs with no traffic */ |
| 77 |
if (!fq->stats.frames && !fcnt) |
| 78 |
continue; |
| 79 |
|
| 80 |
seq_printf(file, "%5d%16d%16d%16s%16llu%16u\n", |
| 81 |
fq->fqid, |
| 82 |
fq->target_cpu, |
| 83 |
fq->tc, |
| 84 |
fq_type_to_str(fq), |
| 85 |
fq->stats.frames, |
| 86 |
fcnt); |
| 87 |
} |
| 88 |
|
| 89 |
return 0; |
| 90 |
} |
| 91 |
|
| 92 |
DEFINE_SHOW_ATTRIBUTE(dpaa2_dbg_fqs); |
| 93 |
|
| 94 |
static int dpaa2_dbg_ch_show(struct seq_file *file, void *offset) |
| 95 |
{ |
| 96 |
struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private; |
| 97 |
struct dpaa2_eth_channel *ch; |
| 98 |
int i; |
| 99 |
|
| 100 |
seq_printf(file, "Channel stats for %s:\n", priv->net_dev->name); |
| 101 |
seq_printf(file, "%s %5s%16s%16s%16s%16s%16s%16s\n", |
| 102 |
"IDX", "CHID", "CPU", "Deq busy", "Frames", "CDANs", |
| 103 |
"Avg Frm/CDAN", "Buf count"); |
| 104 |
|
| 105 |
for (i = 0; i < priv->num_channels; i++) { |
| 106 |
ch = priv->channel[i]; |
| 107 |
seq_printf(file, "%3s%d%6d%16d%16llu%16llu%16llu%16llu%16d\n", |
| 108 |
"CH#", i, ch->ch_id, |
| 109 |
ch->nctx.desired_cpu, |
| 110 |
ch->stats.dequeue_portal_busy, |
| 111 |
ch->stats.frames, |
| 112 |
ch->stats.cdan, |
| 113 |
div64_u64(ch->stats.frames, ch->stats.cdan), |
| 114 |
ch->buf_count); |
| 115 |
} |
| 116 |
|
| 117 |
return 0; |
| 118 |
} |
| 119 |
|
| 120 |
DEFINE_SHOW_ATTRIBUTE(dpaa2_dbg_ch); |
| 121 |
|
| 122 |
static int dpaa2_dbg_bp_show(struct seq_file *file, void *offset) |
| 123 |
{ |
| 124 |
struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private; |
| 125 |
int i, j, num_queues, buf_cnt; |
| 126 |
struct dpaa2_eth_bp *bp; |
| 127 |
char ch_name[10]; |
| 128 |
int err; |
| 129 |
|
| 130 |
/* Print out the header */ |
| 131 |
seq_printf(file, "Buffer pool info for %s:\n", priv->net_dev->name); |
| 132 |
seq_printf(file, "%s %10s%15s", "IDX", "BPID", "Buf count"); |
| 133 |
num_queues = dpaa2_eth_queue_count(priv); |
| 134 |
for (i = 0; i < num_queues; i++) { |
| 135 |
snprintf(ch_name, sizeof(ch_name), "CH#%d", i); |
| 136 |
seq_printf(file, "%10s", ch_name); |
| 137 |
} |
| 138 |
seq_printf(file, "\n"); |
| 139 |
|
| 140 |
/* For each buffer pool, print out its BPID, the number of buffers in |
| 141 |
* that buffer pool and the channels which are using it. |
| 142 |
*/ |
| 143 |
for (i = 0; i < priv->num_bps; i++) { |
| 144 |
bp = priv->bp[i]; |
| 145 |
|
| 146 |
err = dpaa2_io_query_bp_count(NULL, bp->bpid, &buf_cnt); |
| 147 |
if (err) { |
| 148 |
netdev_warn(priv->net_dev, "Buffer count query error %d\n", err); |
| 149 |
return err; |
| 150 |
} |
| 151 |
|
| 152 |
seq_printf(file, "%3s%d%10d%15d", "BP#", i, bp->bpid, buf_cnt); |
| 153 |
for (j = 0; j < num_queues; j++) { |
| 154 |
if (priv->channel[j]->bp == bp) |
| 155 |
seq_printf(file, "%10s", "x"); |
| 156 |
else |
| 157 |
seq_printf(file, "%10s", ""); |
| 158 |
} |
| 159 |
seq_printf(file, "\n"); |
| 160 |
} |
| 161 |
|
| 162 |
return 0; |
| 163 |
} |
| 164 |
|
| 165 |
DEFINE_SHOW_ATTRIBUTE(dpaa2_dbg_bp); |
| 166 |
|
| 167 |
void dpaa2_dbg_add(struct dpaa2_eth_priv *priv) |
| 168 |
{ |
| 169 |
struct fsl_mc_device *dpni_dev; |
| 170 |
struct dentry *dir; |
| 171 |
char name[10]; |
| 172 |
|
| 173 |
/* Create a directory for the interface */ |
| 174 |
dpni_dev = to_fsl_mc_device(priv->net_dev->dev.parent); |
| 175 |
snprintf(name, 10, "dpni.%d", dpni_dev->obj_desc.id); |
| 176 |
dir = debugfs_create_dir(name, dpaa2_dbg_root); |
| 177 |
priv->dbg.dir = dir; |
| 178 |
|
| 179 |
/* per-cpu stats file */ |
| 180 |
debugfs_create_file("cpu_stats", 0444, dir, priv, &dpaa2_dbg_cpu_fops); |
| 181 |
|
| 182 |
/* per-fq stats file */ |
| 183 |
debugfs_create_file("fq_stats", 0444, dir, priv, &dpaa2_dbg_fqs_fops); |
| 184 |
|
| 185 |
/* per-fq stats file */ |
| 186 |
debugfs_create_file("ch_stats", 0444, dir, priv, &dpaa2_dbg_ch_fops); |
| 187 |
|
| 188 |
/* per buffer pool stats file */ |
| 189 |
debugfs_create_file("bp_stats", 0444, dir, priv, &dpaa2_dbg_bp_fops); |
| 190 |
|
| 191 |
} |
| 192 |
|
| 193 |
void dpaa2_dbg_remove(struct dpaa2_eth_priv *priv) |
| 194 |
{ |
| 195 |
debugfs_remove_recursive(priv->dbg.dir); |
| 196 |
} |
| 197 |
|
| 198 |
void dpaa2_eth_dbg_init(void) |
| 199 |
{ |
| 200 |
dpaa2_dbg_root = debugfs_create_dir(DPAA2_ETH_DBG_ROOT, NULL); |
| 201 |
pr_debug("DPAA2-ETH: debugfs created\n"); |
| 202 |
} |
| 203 |
|
| 204 |
void dpaa2_eth_dbg_exit(void) |
| 205 |
{ |
| 206 |
debugfs_remove(dpaa2_dbg_root); |
| 207 |
} |