1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
3
4 #include <linux/pci.h>
5 #include <linux/netdevice.h>
6
7 #include "ionic.h"
8 #include "ionic_bus.h"
9 #include "ionic_lif.h"
10 #include "ionic_debugfs.h"
11
12 #ifdef CONFIG_DEBUG_FS
13
14 static struct dentry *ionic_dir;
15
ionic_debugfs_create(void)16 void ionic_debugfs_create(void)
17 {
18 ionic_dir = debugfs_create_dir(IONIC_DRV_NAME, NULL);
19 }
20
ionic_debugfs_destroy(void)21 void ionic_debugfs_destroy(void)
22 {
23 debugfs_remove_recursive(ionic_dir);
24 }
25
ionic_debugfs_add_dev(struct ionic * ionic)26 void ionic_debugfs_add_dev(struct ionic *ionic)
27 {
28 ionic->dentry = debugfs_create_dir(ionic_bus_info(ionic), ionic_dir);
29 }
30
ionic_debugfs_del_dev(struct ionic * ionic)31 void ionic_debugfs_del_dev(struct ionic *ionic)
32 {
33 debugfs_remove_recursive(ionic->dentry);
34 ionic->dentry = NULL;
35 }
36
identity_show(struct seq_file * seq,void * v)37 static int identity_show(struct seq_file *seq, void *v)
38 {
39 struct ionic *ionic = seq->private;
40 struct ionic_identity *ident;
41
42 ident = &ionic->ident;
43
44 seq_printf(seq, "nlifs: %d\n", ident->dev.nlifs);
45 seq_printf(seq, "nintrs: %d\n", ident->dev.nintrs);
46 seq_printf(seq, "ndbpgs_per_lif: %d\n", ident->dev.ndbpgs_per_lif);
47 seq_printf(seq, "intr_coal_mult: %d\n", ident->dev.intr_coal_mult);
48 seq_printf(seq, "intr_coal_div: %d\n", ident->dev.intr_coal_div);
49
50 seq_printf(seq, "max_ucast_filters: %d\n", ident->lif.eth.max_ucast_filters);
51 seq_printf(seq, "max_mcast_filters: %d\n", ident->lif.eth.max_mcast_filters);
52
53 return 0;
54 }
55 DEFINE_SHOW_ATTRIBUTE(identity);
56
ionic_debugfs_add_ident(struct ionic * ionic)57 void ionic_debugfs_add_ident(struct ionic *ionic)
58 {
59 debugfs_create_file("identity", 0400, ionic->dentry,
60 ionic, &identity_fops);
61 }
62
ionic_debugfs_add_sizes(struct ionic * ionic)63 void ionic_debugfs_add_sizes(struct ionic *ionic)
64 {
65 debugfs_create_u32("nlifs", 0400, ionic->dentry,
66 (u32 *)&ionic->ident.dev.nlifs);
67 debugfs_create_u32("nintrs", 0400, ionic->dentry, &ionic->nintrs);
68
69 debugfs_create_u32("ntxqs_per_lif", 0400, ionic->dentry,
70 (u32 *)&ionic->ident.lif.eth.config.queue_count[IONIC_QTYPE_TXQ]);
71 debugfs_create_u32("nrxqs_per_lif", 0400, ionic->dentry,
72 (u32 *)&ionic->ident.lif.eth.config.queue_count[IONIC_QTYPE_RXQ]);
73 }
74
q_tail_show(struct seq_file * seq,void * v)75 static int q_tail_show(struct seq_file *seq, void *v)
76 {
77 struct ionic_queue *q = seq->private;
78
79 seq_printf(seq, "%d\n", q->tail_idx);
80
81 return 0;
82 }
83 DEFINE_SHOW_ATTRIBUTE(q_tail);
84
q_head_show(struct seq_file * seq,void * v)85 static int q_head_show(struct seq_file *seq, void *v)
86 {
87 struct ionic_queue *q = seq->private;
88
89 seq_printf(seq, "%d\n", q->head_idx);
90
91 return 0;
92 }
93 DEFINE_SHOW_ATTRIBUTE(q_head);
94
cq_tail_show(struct seq_file * seq,void * v)95 static int cq_tail_show(struct seq_file *seq, void *v)
96 {
97 struct ionic_cq *cq = seq->private;
98
99 seq_printf(seq, "%d\n", cq->tail_idx);
100
101 return 0;
102 }
103 DEFINE_SHOW_ATTRIBUTE(cq_tail);
104
105 static const struct debugfs_reg32 intr_ctrl_regs[] = {
106 { .name = "coal_init", .offset = 0, },
107 { .name = "mask", .offset = 4, },
108 { .name = "credits", .offset = 8, },
109 { .name = "mask_on_assert", .offset = 12, },
110 { .name = "coal_timer", .offset = 16, },
111 };
112
ionic_debugfs_add_qcq(struct ionic_lif * lif,struct ionic_qcq * qcq)113 void ionic_debugfs_add_qcq(struct ionic_lif *lif, struct ionic_qcq *qcq)
114 {
115 struct dentry *qcq_dentry, *q_dentry, *cq_dentry;
116 struct dentry *intr_dentry, *stats_dentry;
117 struct ionic_dev *idev = &lif->ionic->idev;
118 struct debugfs_regset32 *intr_ctrl_regset;
119 struct ionic_intr_info *intr = &qcq->intr;
120 struct debugfs_blob_wrapper *desc_blob;
121 struct device *dev = lif->ionic->dev;
122 struct ionic_queue *q = &qcq->q;
123 struct ionic_cq *cq = &qcq->cq;
124
125 qcq_dentry = debugfs_create_dir(q->name, lif->dentry);
126 if (IS_ERR_OR_NULL(qcq_dentry))
127 return;
128 qcq->dentry = qcq_dentry;
129
130 debugfs_create_x64("q_base_pa", 0400, qcq_dentry, &qcq->q_base_pa);
131 debugfs_create_x32("q_size", 0400, qcq_dentry, &qcq->q_size);
132 debugfs_create_x64("cq_base_pa", 0400, qcq_dentry, &qcq->cq_base_pa);
133 debugfs_create_x32("cq_size", 0400, qcq_dentry, &qcq->cq_size);
134 debugfs_create_x64("sg_base_pa", 0400, qcq_dentry, &qcq->sg_base_pa);
135 debugfs_create_x32("sg_size", 0400, qcq_dentry, &qcq->sg_size);
136
137 q_dentry = debugfs_create_dir("q", qcq->dentry);
138
139 debugfs_create_u32("index", 0400, q_dentry, &q->index);
140 debugfs_create_u32("num_descs", 0400, q_dentry, &q->num_descs);
141 debugfs_create_u32("desc_size", 0400, q_dentry, &q->desc_size);
142 debugfs_create_u32("pid", 0400, q_dentry, &q->pid);
143 debugfs_create_u32("qid", 0400, q_dentry, &q->hw_index);
144 debugfs_create_u32("qtype", 0400, q_dentry, &q->hw_type);
145 debugfs_create_u64("drop", 0400, q_dentry, &q->drop);
146 debugfs_create_u64("stop", 0400, q_dentry, &q->stop);
147 debugfs_create_u64("wake", 0400, q_dentry, &q->wake);
148
149 debugfs_create_file("tail", 0400, q_dentry, q, &q_tail_fops);
150 debugfs_create_file("head", 0400, q_dentry, q, &q_head_fops);
151
152 desc_blob = devm_kzalloc(dev, sizeof(*desc_blob), GFP_KERNEL);
153 if (!desc_blob)
154 return;
155 desc_blob->data = q->base;
156 desc_blob->size = (unsigned long)q->num_descs * q->desc_size;
157 debugfs_create_blob("desc_blob", 0400, q_dentry, desc_blob);
158
159 if (qcq->flags & IONIC_QCQ_F_SG) {
160 desc_blob = devm_kzalloc(dev, sizeof(*desc_blob), GFP_KERNEL);
161 if (!desc_blob)
162 return;
163 desc_blob->data = q->sg_base;
164 desc_blob->size = (unsigned long)q->num_descs * q->sg_desc_size;
165 debugfs_create_blob("sg_desc_blob", 0400, q_dentry,
166 desc_blob);
167 }
168
169 cq_dentry = debugfs_create_dir("cq", qcq->dentry);
170
171 debugfs_create_x64("base_pa", 0400, cq_dentry, &cq->base_pa);
172 debugfs_create_u32("num_descs", 0400, cq_dentry, &cq->num_descs);
173 debugfs_create_u32("desc_size", 0400, cq_dentry, &cq->desc_size);
174 debugfs_create_bool("done_color", 0400, cq_dentry, &cq->done_color);
175
176 debugfs_create_file("tail", 0400, cq_dentry, cq, &cq_tail_fops);
177
178 desc_blob = devm_kzalloc(dev, sizeof(*desc_blob), GFP_KERNEL);
179 if (!desc_blob)
180 return;
181 desc_blob->data = cq->base;
182 desc_blob->size = (unsigned long)cq->num_descs * cq->desc_size;
183 debugfs_create_blob("desc_blob", 0400, cq_dentry, desc_blob);
184
185 if (qcq->flags & IONIC_QCQ_F_INTR) {
186 intr_dentry = debugfs_create_dir("intr", qcq->dentry);
187
188 debugfs_create_u32("index", 0400, intr_dentry,
189 &intr->index);
190 debugfs_create_u32("vector", 0400, intr_dentry,
191 &intr->vector);
192 debugfs_create_u32("dim_coal_hw", 0400, intr_dentry,
193 &intr->dim_coal_hw);
194
195 intr_ctrl_regset = devm_kzalloc(dev, sizeof(*intr_ctrl_regset),
196 GFP_KERNEL);
197 if (!intr_ctrl_regset)
198 return;
199 intr_ctrl_regset->regs = intr_ctrl_regs;
200 intr_ctrl_regset->nregs = ARRAY_SIZE(intr_ctrl_regs);
201 intr_ctrl_regset->base = &idev->intr_ctrl[intr->index];
202
203 debugfs_create_regset32("intr_ctrl", 0400, intr_dentry,
204 intr_ctrl_regset);
205 }
206
207 if (qcq->flags & IONIC_QCQ_F_NOTIFYQ) {
208 stats_dentry = debugfs_create_dir("notifyblock", qcq->dentry);
209
210 debugfs_create_u64("eid", 0400, stats_dentry,
211 (u64 *)&lif->info->status.eid);
212 debugfs_create_u16("link_status", 0400, stats_dentry,
213 (u16 *)&lif->info->status.link_status);
214 debugfs_create_u32("link_speed", 0400, stats_dentry,
215 (u32 *)&lif->info->status.link_speed);
216 debugfs_create_u16("link_down_count", 0400, stats_dentry,
217 (u16 *)&lif->info->status.link_down_count);
218 }
219 }
220
netdev_show(struct seq_file * seq,void * v)221 static int netdev_show(struct seq_file *seq, void *v)
222 {
223 struct net_device *netdev = seq->private;
224
225 seq_printf(seq, "%s\n", netdev->name);
226
227 return 0;
228 }
229 DEFINE_SHOW_ATTRIBUTE(netdev);
230
ionic_debugfs_add_lif(struct ionic_lif * lif)231 void ionic_debugfs_add_lif(struct ionic_lif *lif)
232 {
233 struct dentry *lif_dentry;
234
235 lif_dentry = debugfs_create_dir(lif->name, lif->ionic->dentry);
236 if (IS_ERR_OR_NULL(lif_dentry))
237 return;
238 lif->dentry = lif_dentry;
239
240 debugfs_create_file("netdev", 0400, lif->dentry,
241 lif->netdev, &netdev_fops);
242 }
243
ionic_debugfs_del_lif(struct ionic_lif * lif)244 void ionic_debugfs_del_lif(struct ionic_lif *lif)
245 {
246 debugfs_remove_recursive(lif->dentry);
247 lif->dentry = NULL;
248 }
249
ionic_debugfs_del_qcq(struct ionic_qcq * qcq)250 void ionic_debugfs_del_qcq(struct ionic_qcq *qcq)
251 {
252 debugfs_remove_recursive(qcq->dentry);
253 qcq->dentry = NULL;
254 }
255
256 #endif
257