Commit | Line | Data |
---|---|---|
7461fd91 | 1 | /* Intel Ethernet Switch Host Interface Driver |
de445199 | 2 | * Copyright(c) 2013 - 2015 Intel Corporation. |
7461fd91 AD |
3 | * |
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. | |
7 | * | |
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. | |
12 | * | |
13 | * The full GNU General Public License is included in this distribution in | |
14 | * the file called "COPYING". | |
15 | * | |
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 | |
19 | */ | |
20 | ||
21 | #ifdef CONFIG_DEBUG_FS | |
22 | ||
23 | #include "fm10k.h" | |
24 | ||
25 | #include <linux/debugfs.h> | |
26 | #include <linux/seq_file.h> | |
27 | ||
28 | static struct dentry *dbg_root; | |
29 | ||
30 | /* Descriptor Seq Functions */ | |
31 | ||
32 | static void *fm10k_dbg_desc_seq_start(struct seq_file *s, loff_t *pos) | |
33 | { | |
34 | struct fm10k_ring *ring = s->private; | |
35 | ||
36 | return (*pos < ring->count) ? pos : NULL; | |
37 | } | |
38 | ||
de445199 JK |
39 | static void *fm10k_dbg_desc_seq_next(struct seq_file *s, |
40 | void __always_unused *v, loff_t *pos) | |
7461fd91 AD |
41 | { |
42 | struct fm10k_ring *ring = s->private; | |
43 | ||
44 | return (++(*pos) < ring->count) ? pos : NULL; | |
45 | } | |
46 | ||
de445199 JK |
47 | static void fm10k_dbg_desc_seq_stop(struct seq_file __always_unused *s, |
48 | __always_unused void *v) | |
7461fd91 AD |
49 | { |
50 | /* Do nothing. */ | |
51 | } | |
52 | ||
53 | static void fm10k_dbg_desc_break(struct seq_file *s, int i) | |
54 | { | |
55 | while (i--) | |
56 | seq_puts(s, "-"); | |
57 | ||
58 | seq_puts(s, "\n"); | |
59 | } | |
60 | ||
61 | static int fm10k_dbg_tx_desc_seq_show(struct seq_file *s, void *v) | |
62 | { | |
63 | struct fm10k_ring *ring = s->private; | |
64 | int i = *(loff_t *)v; | |
65 | static const char tx_desc_hdr[] = | |
66 | "DES BUFFER_ADDRESS LENGTH VLAN MSS HDRLEN FLAGS\n"; | |
67 | ||
68 | /* Generate header */ | |
69 | if (!i) { | |
70 | seq_printf(s, tx_desc_hdr); | |
71 | fm10k_dbg_desc_break(s, sizeof(tx_desc_hdr) - 1); | |
72 | } | |
73 | ||
74 | /* Validate descriptor allocation */ | |
75 | if (!ring->desc) { | |
76 | seq_printf(s, "%03X Descriptor ring not allocated.\n", i); | |
77 | } else { | |
78 | struct fm10k_tx_desc *txd = FM10K_TX_DESC(ring, i); | |
79 | ||
80 | seq_printf(s, "%03X %#018llx %#06x %#06x %#06x %#06x %#04x\n", | |
81 | i, txd->buffer_addr, txd->buflen, txd->vlan, | |
82 | txd->mss, txd->hdrlen, txd->flags); | |
83 | } | |
84 | ||
85 | return 0; | |
86 | } | |
87 | ||
88 | static int fm10k_dbg_rx_desc_seq_show(struct seq_file *s, void *v) | |
89 | { | |
90 | struct fm10k_ring *ring = s->private; | |
91 | int i = *(loff_t *)v; | |
92 | static const char rx_desc_hdr[] = | |
93 | "DES DATA RSS STATERR LENGTH VLAN DGLORT SGLORT TIMESTAMP\n"; | |
94 | ||
95 | /* Generate header */ | |
96 | if (!i) { | |
97 | seq_printf(s, rx_desc_hdr); | |
98 | fm10k_dbg_desc_break(s, sizeof(rx_desc_hdr) - 1); | |
99 | } | |
100 | ||
101 | /* Validate descriptor allocation */ | |
102 | if (!ring->desc) { | |
103 | seq_printf(s, "%03X Descriptor ring not allocated.\n", i); | |
104 | } else { | |
105 | union fm10k_rx_desc *rxd = FM10K_RX_DESC(ring, i); | |
106 | ||
107 | seq_printf(s, | |
108 | "%03X %#010x %#010x %#010x %#06x %#06x %#06x %#06x %#018llx\n", | |
109 | i, rxd->d.data, rxd->d.rss, rxd->d.staterr, | |
110 | rxd->w.length, rxd->w.vlan, rxd->w.dglort, | |
111 | rxd->w.sglort, rxd->q.timestamp); | |
112 | } | |
113 | ||
114 | return 0; | |
115 | } | |
116 | ||
117 | static const struct seq_operations fm10k_dbg_tx_desc_seq_ops = { | |
118 | .start = fm10k_dbg_desc_seq_start, | |
119 | .next = fm10k_dbg_desc_seq_next, | |
120 | .stop = fm10k_dbg_desc_seq_stop, | |
121 | .show = fm10k_dbg_tx_desc_seq_show, | |
122 | }; | |
123 | ||
124 | static const struct seq_operations fm10k_dbg_rx_desc_seq_ops = { | |
125 | .start = fm10k_dbg_desc_seq_start, | |
126 | .next = fm10k_dbg_desc_seq_next, | |
127 | .stop = fm10k_dbg_desc_seq_stop, | |
128 | .show = fm10k_dbg_rx_desc_seq_show, | |
129 | }; | |
130 | ||
131 | static int fm10k_dbg_desc_open(struct inode *inode, struct file *filep) | |
132 | { | |
133 | struct fm10k_ring *ring = inode->i_private; | |
134 | struct fm10k_q_vector *q_vector = ring->q_vector; | |
135 | const struct seq_operations *desc_seq_ops; | |
136 | int err; | |
137 | ||
138 | if (ring < q_vector->rx.ring) | |
139 | desc_seq_ops = &fm10k_dbg_tx_desc_seq_ops; | |
140 | else | |
141 | desc_seq_ops = &fm10k_dbg_rx_desc_seq_ops; | |
142 | ||
143 | err = seq_open(filep, desc_seq_ops); | |
144 | if (err) | |
145 | return err; | |
146 | ||
147 | ((struct seq_file *)filep->private_data)->private = ring; | |
148 | ||
149 | return 0; | |
150 | } | |
151 | ||
152 | static const struct file_operations fm10k_dbg_desc_fops = { | |
153 | .owner = THIS_MODULE, | |
154 | .open = fm10k_dbg_desc_open, | |
155 | .read = seq_read, | |
156 | .llseek = seq_lseek, | |
157 | .release = seq_release, | |
158 | }; | |
159 | ||
160 | /** | |
161 | * fm10k_dbg_q_vector_init - setup debugfs for the q_vectors | |
162 | * @q_vector: q_vector to allocate directories for | |
163 | * | |
164 | * A folder is created for each q_vector found. In each q_vector | |
165 | * folder, a debugfs file is created for each tx and rx ring | |
166 | * allocated to the q_vector. | |
167 | **/ | |
168 | void fm10k_dbg_q_vector_init(struct fm10k_q_vector *q_vector) | |
169 | { | |
170 | struct fm10k_intfc *interface = q_vector->interface; | |
171 | char name[16]; | |
172 | int i; | |
173 | ||
174 | if (!interface->dbg_intfc) | |
175 | return; | |
176 | ||
177 | /* Generate a folder for each q_vector */ | |
178 | sprintf(name, "q_vector.%03d", q_vector->v_idx); | |
179 | ||
180 | q_vector->dbg_q_vector = debugfs_create_dir(name, interface->dbg_intfc); | |
181 | if (!q_vector->dbg_q_vector) | |
182 | return; | |
183 | ||
184 | /* Generate a file for each rx ring in the q_vector */ | |
185 | for (i = 0; i < q_vector->tx.count; i++) { | |
186 | struct fm10k_ring *ring = &q_vector->tx.ring[i]; | |
187 | ||
188 | sprintf(name, "tx_ring.%03d", ring->queue_index); | |
189 | ||
190 | debugfs_create_file(name, 0600, | |
191 | q_vector->dbg_q_vector, ring, | |
192 | &fm10k_dbg_desc_fops); | |
193 | } | |
194 | ||
195 | /* Generate a file for each rx ring in the q_vector */ | |
196 | for (i = 0; i < q_vector->rx.count; i++) { | |
197 | struct fm10k_ring *ring = &q_vector->rx.ring[i]; | |
198 | ||
199 | sprintf(name, "rx_ring.%03d", ring->queue_index); | |
200 | ||
201 | debugfs_create_file(name, 0600, | |
202 | q_vector->dbg_q_vector, ring, | |
203 | &fm10k_dbg_desc_fops); | |
204 | } | |
205 | } | |
206 | ||
207 | /** | |
208 | * fm10k_dbg_free_q_vector_dir - setup debugfs for the q_vectors | |
209 | * @q_vector: q_vector to allocate directories for | |
210 | **/ | |
211 | void fm10k_dbg_q_vector_exit(struct fm10k_q_vector *q_vector) | |
212 | { | |
213 | struct fm10k_intfc *interface = q_vector->interface; | |
214 | ||
215 | if (interface->dbg_intfc) | |
216 | debugfs_remove_recursive(q_vector->dbg_q_vector); | |
217 | q_vector->dbg_q_vector = NULL; | |
218 | } | |
219 | ||
220 | /** | |
221 | * fm10k_dbg_intfc_init - setup the debugfs directory for the intferface | |
222 | * @interface: the interface that is starting up | |
223 | **/ | |
224 | ||
225 | void fm10k_dbg_intfc_init(struct fm10k_intfc *interface) | |
226 | { | |
227 | const char *name = pci_name(interface->pdev); | |
228 | ||
229 | if (dbg_root) | |
230 | interface->dbg_intfc = debugfs_create_dir(name, dbg_root); | |
231 | } | |
232 | ||
233 | /** | |
234 | * fm10k_dbg_intfc_exit - clean out the interface's debugfs entries | |
235 | * @interface: the interface that is stopping | |
236 | **/ | |
237 | void fm10k_dbg_intfc_exit(struct fm10k_intfc *interface) | |
238 | { | |
239 | if (dbg_root) | |
240 | debugfs_remove_recursive(interface->dbg_intfc); | |
241 | interface->dbg_intfc = NULL; | |
242 | } | |
243 | ||
244 | /** | |
245 | * fm10k_dbg_init - start up debugfs for the driver | |
246 | **/ | |
247 | void fm10k_dbg_init(void) | |
248 | { | |
249 | dbg_root = debugfs_create_dir(fm10k_driver_name, NULL); | |
250 | } | |
251 | ||
252 | /** | |
253 | * fm10k_dbg_exit - clean out the driver's debugfs entries | |
254 | **/ | |
255 | void fm10k_dbg_exit(void) | |
256 | { | |
257 | debugfs_remove_recursive(dbg_root); | |
258 | dbg_root = NULL; | |
259 | } | |
260 | ||
261 | #endif /* CONFIG_DEBUG_FS */ |