1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
6 #include <linux/debugfs.h>
7 #include <linux/seq_file.h>
9 static struct dentry *dbg_root;
11 /* Descriptor Seq Functions */
13 static void *fm10k_dbg_desc_seq_start(struct seq_file *s, loff_t *pos)
15 struct fm10k_ring *ring = s->private;
17 return (*pos < ring->count) ? pos : NULL;
20 static void *fm10k_dbg_desc_seq_next(struct seq_file *s,
21 void __always_unused *v,
24 struct fm10k_ring *ring = s->private;
26 return (++(*pos) < ring->count) ? pos : NULL;
29 static void fm10k_dbg_desc_seq_stop(struct seq_file __always_unused *s,
30 void __always_unused *v)
35 static void fm10k_dbg_desc_break(struct seq_file *s, int i)
43 static int fm10k_dbg_tx_desc_seq_show(struct seq_file *s, void *v)
45 struct fm10k_ring *ring = s->private;
47 static const char tx_desc_hdr[] =
48 "DES BUFFER_ADDRESS LENGTH VLAN MSS HDRLEN FLAGS\n";
52 seq_printf(s, tx_desc_hdr);
53 fm10k_dbg_desc_break(s, sizeof(tx_desc_hdr) - 1);
56 /* Validate descriptor allocation */
58 seq_printf(s, "%03X Descriptor ring not allocated.\n", i);
60 struct fm10k_tx_desc *txd = FM10K_TX_DESC(ring, i);
62 seq_printf(s, "%03X %#018llx %#06x %#06x %#06x %#06x %#04x\n",
63 i, txd->buffer_addr, txd->buflen, txd->vlan,
64 txd->mss, txd->hdrlen, txd->flags);
70 static int fm10k_dbg_rx_desc_seq_show(struct seq_file *s, void *v)
72 struct fm10k_ring *ring = s->private;
74 static const char rx_desc_hdr[] =
75 "DES DATA RSS STATERR LENGTH VLAN DGLORT SGLORT TIMESTAMP\n";
79 seq_printf(s, rx_desc_hdr);
80 fm10k_dbg_desc_break(s, sizeof(rx_desc_hdr) - 1);
83 /* Validate descriptor allocation */
85 seq_printf(s, "%03X Descriptor ring not allocated.\n", i);
87 union fm10k_rx_desc *rxd = FM10K_RX_DESC(ring, i);
90 "%03X %#010x %#010x %#010x %#06x %#06x %#06x %#06x %#018llx\n",
91 i, rxd->d.data, rxd->d.rss, rxd->d.staterr,
92 rxd->w.length, rxd->w.vlan, rxd->w.dglort,
93 rxd->w.sglort, rxd->q.timestamp);
99 static const struct seq_operations fm10k_dbg_tx_desc_seq_ops = {
100 .start = fm10k_dbg_desc_seq_start,
101 .next = fm10k_dbg_desc_seq_next,
102 .stop = fm10k_dbg_desc_seq_stop,
103 .show = fm10k_dbg_tx_desc_seq_show,
106 static const struct seq_operations fm10k_dbg_rx_desc_seq_ops = {
107 .start = fm10k_dbg_desc_seq_start,
108 .next = fm10k_dbg_desc_seq_next,
109 .stop = fm10k_dbg_desc_seq_stop,
110 .show = fm10k_dbg_rx_desc_seq_show,
113 static int fm10k_dbg_desc_open(struct inode *inode, struct file *filep)
115 struct fm10k_ring *ring = inode->i_private;
116 struct fm10k_q_vector *q_vector = ring->q_vector;
117 const struct seq_operations *desc_seq_ops;
120 if (ring < q_vector->rx.ring)
121 desc_seq_ops = &fm10k_dbg_tx_desc_seq_ops;
123 desc_seq_ops = &fm10k_dbg_rx_desc_seq_ops;
125 err = seq_open(filep, desc_seq_ops);
129 ((struct seq_file *)filep->private_data)->private = ring;
134 static const struct file_operations fm10k_dbg_desc_fops = {
135 .owner = THIS_MODULE,
136 .open = fm10k_dbg_desc_open,
139 .release = seq_release,
143 * fm10k_dbg_q_vector_init - setup debugfs for the q_vectors
144 * @q_vector: q_vector to allocate directories for
146 * A folder is created for each q_vector found. In each q_vector
147 * folder, a debugfs file is created for each tx and rx ring
148 * allocated to the q_vector.
150 void fm10k_dbg_q_vector_init(struct fm10k_q_vector *q_vector)
152 struct fm10k_intfc *interface = q_vector->interface;
156 if (!interface->dbg_intfc)
159 /* Generate a folder for each q_vector */
160 snprintf(name, sizeof(name), "q_vector.%03d", q_vector->v_idx);
162 q_vector->dbg_q_vector = debugfs_create_dir(name, interface->dbg_intfc);
163 if (!q_vector->dbg_q_vector)
166 /* Generate a file for each rx ring in the q_vector */
167 for (i = 0; i < q_vector->tx.count; i++) {
168 struct fm10k_ring *ring = &q_vector->tx.ring[i];
170 snprintf(name, sizeof(name), "tx_ring.%03d", ring->queue_index);
172 debugfs_create_file(name, 0600,
173 q_vector->dbg_q_vector, ring,
174 &fm10k_dbg_desc_fops);
177 /* Generate a file for each rx ring in the q_vector */
178 for (i = 0; i < q_vector->rx.count; i++) {
179 struct fm10k_ring *ring = &q_vector->rx.ring[i];
181 snprintf(name, sizeof(name), "rx_ring.%03d", ring->queue_index);
183 debugfs_create_file(name, 0600,
184 q_vector->dbg_q_vector, ring,
185 &fm10k_dbg_desc_fops);
190 * fm10k_dbg_free_q_vector_dir - setup debugfs for the q_vectors
191 * @q_vector: q_vector to allocate directories for
193 void fm10k_dbg_q_vector_exit(struct fm10k_q_vector *q_vector)
195 struct fm10k_intfc *interface = q_vector->interface;
197 if (interface->dbg_intfc)
198 debugfs_remove_recursive(q_vector->dbg_q_vector);
199 q_vector->dbg_q_vector = NULL;
203 * fm10k_dbg_intfc_init - setup the debugfs directory for the intferface
204 * @interface: the interface that is starting up
207 void fm10k_dbg_intfc_init(struct fm10k_intfc *interface)
209 const char *name = pci_name(interface->pdev);
212 interface->dbg_intfc = debugfs_create_dir(name, dbg_root);
216 * fm10k_dbg_intfc_exit - clean out the interface's debugfs entries
217 * @interface: the interface that is stopping
219 void fm10k_dbg_intfc_exit(struct fm10k_intfc *interface)
222 debugfs_remove_recursive(interface->dbg_intfc);
223 interface->dbg_intfc = NULL;
227 * fm10k_dbg_init - start up debugfs for the driver
229 void fm10k_dbg_init(void)
231 dbg_root = debugfs_create_dir(fm10k_driver_name, NULL);
235 * fm10k_dbg_exit - clean out the driver's debugfs entries
237 void fm10k_dbg_exit(void)
239 debugfs_remove_recursive(dbg_root);