Merge branch 'irq-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / net / ethernet / intel / fm10k / fm10k_debugfs.c
blob5304bc1fbecd4e218497ea7b7680b7b81d964411
1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2015 Intel Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
16 * Contact Information:
17 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
18 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
21 #ifdef CONFIG_DEBUG_FS
23 #include "fm10k.h"
25 #include <linux/debugfs.h>
26 #include <linux/seq_file.h>
28 static struct dentry *dbg_root;
30 /* Descriptor Seq Functions */
32 static void *fm10k_dbg_desc_seq_start(struct seq_file *s, loff_t *pos)
34 struct fm10k_ring *ring = s->private;
36 return (*pos < ring->count) ? pos : NULL;
39 static void *fm10k_dbg_desc_seq_next(struct seq_file *s,
40 void __always_unused *v,
41 loff_t *pos)
43 struct fm10k_ring *ring = s->private;
45 return (++(*pos) < ring->count) ? pos : NULL;
48 static void fm10k_dbg_desc_seq_stop(struct seq_file __always_unused *s,
49 void __always_unused *v)
51 /* Do nothing. */
54 static void fm10k_dbg_desc_break(struct seq_file *s, int i)
56 while (i--)
57 seq_puts(s, "-");
59 seq_puts(s, "\n");
62 static int fm10k_dbg_tx_desc_seq_show(struct seq_file *s, void *v)
64 struct fm10k_ring *ring = s->private;
65 int i = *(loff_t *)v;
66 static const char tx_desc_hdr[] =
67 "DES BUFFER_ADDRESS LENGTH VLAN MSS HDRLEN FLAGS\n";
69 /* Generate header */
70 if (!i) {
71 seq_printf(s, tx_desc_hdr);
72 fm10k_dbg_desc_break(s, sizeof(tx_desc_hdr) - 1);
75 /* Validate descriptor allocation */
76 if (!ring->desc) {
77 seq_printf(s, "%03X Descriptor ring not allocated.\n", i);
78 } else {
79 struct fm10k_tx_desc *txd = FM10K_TX_DESC(ring, i);
81 seq_printf(s, "%03X %#018llx %#06x %#06x %#06x %#06x %#04x\n",
82 i, txd->buffer_addr, txd->buflen, txd->vlan,
83 txd->mss, txd->hdrlen, txd->flags);
86 return 0;
89 static int fm10k_dbg_rx_desc_seq_show(struct seq_file *s, void *v)
91 struct fm10k_ring *ring = s->private;
92 int i = *(loff_t *)v;
93 static const char rx_desc_hdr[] =
94 "DES DATA RSS STATERR LENGTH VLAN DGLORT SGLORT TIMESTAMP\n";
96 /* Generate header */
97 if (!i) {
98 seq_printf(s, rx_desc_hdr);
99 fm10k_dbg_desc_break(s, sizeof(rx_desc_hdr) - 1);
102 /* Validate descriptor allocation */
103 if (!ring->desc) {
104 seq_printf(s, "%03X Descriptor ring not allocated.\n", i);
105 } else {
106 union fm10k_rx_desc *rxd = FM10K_RX_DESC(ring, i);
108 seq_printf(s,
109 "%03X %#010x %#010x %#010x %#06x %#06x %#06x %#06x %#018llx\n",
110 i, rxd->d.data, rxd->d.rss, rxd->d.staterr,
111 rxd->w.length, rxd->w.vlan, rxd->w.dglort,
112 rxd->w.sglort, rxd->q.timestamp);
115 return 0;
118 static const struct seq_operations fm10k_dbg_tx_desc_seq_ops = {
119 .start = fm10k_dbg_desc_seq_start,
120 .next = fm10k_dbg_desc_seq_next,
121 .stop = fm10k_dbg_desc_seq_stop,
122 .show = fm10k_dbg_tx_desc_seq_show,
125 static const struct seq_operations fm10k_dbg_rx_desc_seq_ops = {
126 .start = fm10k_dbg_desc_seq_start,
127 .next = fm10k_dbg_desc_seq_next,
128 .stop = fm10k_dbg_desc_seq_stop,
129 .show = fm10k_dbg_rx_desc_seq_show,
132 static int fm10k_dbg_desc_open(struct inode *inode, struct file *filep)
134 struct fm10k_ring *ring = inode->i_private;
135 struct fm10k_q_vector *q_vector = ring->q_vector;
136 const struct seq_operations *desc_seq_ops;
137 int err;
139 if (ring < q_vector->rx.ring)
140 desc_seq_ops = &fm10k_dbg_tx_desc_seq_ops;
141 else
142 desc_seq_ops = &fm10k_dbg_rx_desc_seq_ops;
144 err = seq_open(filep, desc_seq_ops);
145 if (err)
146 return err;
148 ((struct seq_file *)filep->private_data)->private = ring;
150 return 0;
153 static const struct file_operations fm10k_dbg_desc_fops = {
154 .owner = THIS_MODULE,
155 .open = fm10k_dbg_desc_open,
156 .read = seq_read,
157 .llseek = seq_lseek,
158 .release = seq_release,
162 * fm10k_dbg_q_vector_init - setup debugfs for the q_vectors
163 * @q_vector: q_vector to allocate directories for
165 * A folder is created for each q_vector found. In each q_vector
166 * folder, a debugfs file is created for each tx and rx ring
167 * allocated to the q_vector.
169 void fm10k_dbg_q_vector_init(struct fm10k_q_vector *q_vector)
171 struct fm10k_intfc *interface = q_vector->interface;
172 char name[16];
173 int i;
175 if (!interface->dbg_intfc)
176 return;
178 /* Generate a folder for each q_vector */
179 snprintf(name, sizeof(name), "q_vector.%03d", q_vector->v_idx);
181 q_vector->dbg_q_vector = debugfs_create_dir(name, interface->dbg_intfc);
182 if (!q_vector->dbg_q_vector)
183 return;
185 /* Generate a file for each rx ring in the q_vector */
186 for (i = 0; i < q_vector->tx.count; i++) {
187 struct fm10k_ring *ring = &q_vector->tx.ring[i];
189 snprintf(name, sizeof(name), "tx_ring.%03d", ring->queue_index);
191 debugfs_create_file(name, 0600,
192 q_vector->dbg_q_vector, ring,
193 &fm10k_dbg_desc_fops);
196 /* Generate a file for each rx ring in the q_vector */
197 for (i = 0; i < q_vector->rx.count; i++) {
198 struct fm10k_ring *ring = &q_vector->rx.ring[i];
200 snprintf(name, sizeof(name), "rx_ring.%03d", ring->queue_index);
202 debugfs_create_file(name, 0600,
203 q_vector->dbg_q_vector, ring,
204 &fm10k_dbg_desc_fops);
209 * fm10k_dbg_free_q_vector_dir - setup debugfs for the q_vectors
210 * @q_vector: q_vector to allocate directories for
212 void fm10k_dbg_q_vector_exit(struct fm10k_q_vector *q_vector)
214 struct fm10k_intfc *interface = q_vector->interface;
216 if (interface->dbg_intfc)
217 debugfs_remove_recursive(q_vector->dbg_q_vector);
218 q_vector->dbg_q_vector = NULL;
222 * fm10k_dbg_intfc_init - setup the debugfs directory for the intferface
223 * @interface: the interface that is starting up
226 void fm10k_dbg_intfc_init(struct fm10k_intfc *interface)
228 const char *name = pci_name(interface->pdev);
230 if (dbg_root)
231 interface->dbg_intfc = debugfs_create_dir(name, dbg_root);
235 * fm10k_dbg_intfc_exit - clean out the interface's debugfs entries
236 * @interface: the interface that is stopping
238 void fm10k_dbg_intfc_exit(struct fm10k_intfc *interface)
240 if (dbg_root)
241 debugfs_remove_recursive(interface->dbg_intfc);
242 interface->dbg_intfc = NULL;
246 * fm10k_dbg_init - start up debugfs for the driver
248 void fm10k_dbg_init(void)
250 dbg_root = debugfs_create_dir(fm10k_driver_name, NULL);
254 * fm10k_dbg_exit - clean out the driver's debugfs entries
256 void fm10k_dbg_exit(void)
258 debugfs_remove_recursive(dbg_root);
259 dbg_root = NULL;
262 #endif /* CONFIG_DEBUG_FS */