ionic_debugfs.c (8965B)
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 14static struct dentry *ionic_dir; 15 16void ionic_debugfs_create(void) 17{ 18 ionic_dir = debugfs_create_dir(IONIC_DRV_NAME, NULL); 19} 20 21void ionic_debugfs_destroy(void) 22{ 23 debugfs_remove_recursive(ionic_dir); 24} 25 26void ionic_debugfs_add_dev(struct ionic *ionic) 27{ 28 ionic->dentry = debugfs_create_dir(ionic_bus_info(ionic), ionic_dir); 29} 30 31void ionic_debugfs_del_dev(struct ionic *ionic) 32{ 33 debugfs_remove_recursive(ionic->dentry); 34 ionic->dentry = NULL; 35} 36 37static 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} 55DEFINE_SHOW_ATTRIBUTE(identity); 56 57void ionic_debugfs_add_ident(struct ionic *ionic) 58{ 59 debugfs_create_file("identity", 0400, ionic->dentry, 60 ionic, &identity_fops); 61} 62 63void 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 75static 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} 83DEFINE_SHOW_ATTRIBUTE(q_tail); 84 85static 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} 93DEFINE_SHOW_ATTRIBUTE(q_head); 94 95static 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} 103DEFINE_SHOW_ATTRIBUTE(cq_tail); 104 105static 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 113void 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 147 debugfs_create_file("tail", 0400, q_dentry, q, &q_tail_fops); 148 debugfs_create_file("head", 0400, q_dentry, q, &q_head_fops); 149 150 desc_blob = devm_kzalloc(dev, sizeof(*desc_blob), GFP_KERNEL); 151 if (!desc_blob) 152 return; 153 desc_blob->data = q->base; 154 desc_blob->size = (unsigned long)q->num_descs * q->desc_size; 155 debugfs_create_blob("desc_blob", 0400, q_dentry, desc_blob); 156 157 if (qcq->flags & IONIC_QCQ_F_SG) { 158 desc_blob = devm_kzalloc(dev, sizeof(*desc_blob), GFP_KERNEL); 159 if (!desc_blob) 160 return; 161 desc_blob->data = q->sg_base; 162 desc_blob->size = (unsigned long)q->num_descs * q->sg_desc_size; 163 debugfs_create_blob("sg_desc_blob", 0400, q_dentry, 164 desc_blob); 165 } 166 167 cq_dentry = debugfs_create_dir("cq", qcq->dentry); 168 169 debugfs_create_x64("base_pa", 0400, cq_dentry, &cq->base_pa); 170 debugfs_create_u32("num_descs", 0400, cq_dentry, &cq->num_descs); 171 debugfs_create_u32("desc_size", 0400, cq_dentry, &cq->desc_size); 172 debugfs_create_bool("done_color", 0400, cq_dentry, &cq->done_color); 173 174 debugfs_create_file("tail", 0400, cq_dentry, cq, &cq_tail_fops); 175 176 desc_blob = devm_kzalloc(dev, sizeof(*desc_blob), GFP_KERNEL); 177 if (!desc_blob) 178 return; 179 desc_blob->data = cq->base; 180 desc_blob->size = (unsigned long)cq->num_descs * cq->desc_size; 181 debugfs_create_blob("desc_blob", 0400, cq_dentry, desc_blob); 182 183 if (qcq->flags & IONIC_QCQ_F_INTR) { 184 intr_dentry = debugfs_create_dir("intr", qcq->dentry); 185 186 debugfs_create_u32("index", 0400, intr_dentry, 187 &intr->index); 188 debugfs_create_u32("vector", 0400, intr_dentry, 189 &intr->vector); 190 debugfs_create_u32("dim_coal_hw", 0400, intr_dentry, 191 &intr->dim_coal_hw); 192 193 intr_ctrl_regset = devm_kzalloc(dev, sizeof(*intr_ctrl_regset), 194 GFP_KERNEL); 195 if (!intr_ctrl_regset) 196 return; 197 intr_ctrl_regset->regs = intr_ctrl_regs; 198 intr_ctrl_regset->nregs = ARRAY_SIZE(intr_ctrl_regs); 199 intr_ctrl_regset->base = &idev->intr_ctrl[intr->index]; 200 201 debugfs_create_regset32("intr_ctrl", 0400, intr_dentry, 202 intr_ctrl_regset); 203 } 204 205 if (qcq->flags & IONIC_QCQ_F_NOTIFYQ) { 206 stats_dentry = debugfs_create_dir("notifyblock", qcq->dentry); 207 208 debugfs_create_u64("eid", 0400, stats_dentry, 209 (u64 *)&lif->info->status.eid); 210 debugfs_create_u16("link_status", 0400, stats_dentry, 211 (u16 *)&lif->info->status.link_status); 212 debugfs_create_u32("link_speed", 0400, stats_dentry, 213 (u32 *)&lif->info->status.link_speed); 214 debugfs_create_u16("link_down_count", 0400, stats_dentry, 215 (u16 *)&lif->info->status.link_down_count); 216 } 217} 218 219static int netdev_show(struct seq_file *seq, void *v) 220{ 221 struct net_device *netdev = seq->private; 222 223 seq_printf(seq, "%s\n", netdev->name); 224 225 return 0; 226} 227DEFINE_SHOW_ATTRIBUTE(netdev); 228 229static int lif_filters_show(struct seq_file *seq, void *v) 230{ 231 struct ionic_lif *lif = seq->private; 232 struct ionic_rx_filter *f; 233 struct hlist_head *head; 234 struct hlist_node *tmp; 235 unsigned int i; 236 237 seq_puts(seq, "id flow state type filter\n"); 238 spin_lock_bh(&lif->rx_filters.lock); 239 for (i = 0; i < IONIC_RX_FILTER_HLISTS; i++) { 240 head = &lif->rx_filters.by_id[i]; 241 hlist_for_each_entry_safe(f, tmp, head, by_id) { 242 switch (le16_to_cpu(f->cmd.match)) { 243 case IONIC_RX_FILTER_MATCH_VLAN: 244 seq_printf(seq, "0x%04x 0x%08x 0x%02x vlan 0x%04x\n", 245 f->filter_id, f->flow_id, f->state, 246 le16_to_cpu(f->cmd.vlan.vlan)); 247 break; 248 case IONIC_RX_FILTER_MATCH_MAC: 249 seq_printf(seq, "0x%04x 0x%08x 0x%02x mac %pM\n", 250 f->filter_id, f->flow_id, f->state, 251 f->cmd.mac.addr); 252 break; 253 case IONIC_RX_FILTER_MATCH_MAC_VLAN: 254 seq_printf(seq, "0x%04x 0x%08x 0x%02x macvl 0x%04x %pM\n", 255 f->filter_id, f->flow_id, f->state, 256 le16_to_cpu(f->cmd.vlan.vlan), 257 f->cmd.mac.addr); 258 break; 259 case IONIC_RX_FILTER_STEER_PKTCLASS: 260 seq_printf(seq, "0x%04x 0x%08x 0x%02x rxstr 0x%llx\n", 261 f->filter_id, f->flow_id, f->state, 262 le64_to_cpu(f->cmd.pkt_class)); 263 break; 264 } 265 } 266 } 267 spin_unlock_bh(&lif->rx_filters.lock); 268 269 return 0; 270} 271DEFINE_SHOW_ATTRIBUTE(lif_filters); 272 273void ionic_debugfs_add_lif(struct ionic_lif *lif) 274{ 275 struct dentry *lif_dentry; 276 277 lif_dentry = debugfs_create_dir(lif->name, lif->ionic->dentry); 278 if (IS_ERR_OR_NULL(lif_dentry)) 279 return; 280 lif->dentry = lif_dentry; 281 282 debugfs_create_file("netdev", 0400, lif->dentry, 283 lif->netdev, &netdev_fops); 284 debugfs_create_file("filters", 0400, lif->dentry, 285 lif, &lif_filters_fops); 286} 287 288void ionic_debugfs_del_lif(struct ionic_lif *lif) 289{ 290 debugfs_remove_recursive(lif->dentry); 291 lif->dentry = NULL; 292} 293 294void ionic_debugfs_del_qcq(struct ionic_qcq *qcq) 295{ 296 debugfs_remove_recursive(qcq->dentry); 297 qcq->dentry = NULL; 298} 299 300#endif