1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2014 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
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
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
, void *v
, loff_t
*pos
)
41 struct fm10k_ring
*ring
= s
->private;
43 return (++(*pos
) < ring
->count
) ? pos
: NULL
;
46 static void fm10k_dbg_desc_seq_stop(struct seq_file
*s
, void *v
)
51 static void fm10k_dbg_desc_break(struct seq_file
*s
, int i
)
59 static int fm10k_dbg_tx_desc_seq_show(struct seq_file
*s
, void *v
)
61 struct fm10k_ring
*ring
= s
->private;
63 static const char tx_desc_hdr
[] =
64 "DES BUFFER_ADDRESS LENGTH VLAN MSS HDRLEN FLAGS\n";
68 seq_printf(s
, tx_desc_hdr
);
69 fm10k_dbg_desc_break(s
, sizeof(tx_desc_hdr
) - 1);
72 /* Validate descriptor allocation */
74 seq_printf(s
, "%03X Descriptor ring not allocated.\n", i
);
76 struct fm10k_tx_desc
*txd
= FM10K_TX_DESC(ring
, i
);
78 seq_printf(s
, "%03X %#018llx %#06x %#06x %#06x %#06x %#04x\n",
79 i
, txd
->buffer_addr
, txd
->buflen
, txd
->vlan
,
80 txd
->mss
, txd
->hdrlen
, txd
->flags
);
86 static int fm10k_dbg_rx_desc_seq_show(struct seq_file
*s
, void *v
)
88 struct fm10k_ring
*ring
= s
->private;
90 static const char rx_desc_hdr
[] =
91 "DES DATA RSS STATERR LENGTH VLAN DGLORT SGLORT TIMESTAMP\n";
95 seq_printf(s
, rx_desc_hdr
);
96 fm10k_dbg_desc_break(s
, sizeof(rx_desc_hdr
) - 1);
99 /* Validate descriptor allocation */
101 seq_printf(s
, "%03X Descriptor ring not allocated.\n", i
);
103 union fm10k_rx_desc
*rxd
= FM10K_RX_DESC(ring
, i
);
106 "%03X %#010x %#010x %#010x %#06x %#06x %#06x %#06x %#018llx\n",
107 i
, rxd
->d
.data
, rxd
->d
.rss
, rxd
->d
.staterr
,
108 rxd
->w
.length
, rxd
->w
.vlan
, rxd
->w
.dglort
,
109 rxd
->w
.sglort
, rxd
->q
.timestamp
);
115 static const struct seq_operations fm10k_dbg_tx_desc_seq_ops
= {
116 .start
= fm10k_dbg_desc_seq_start
,
117 .next
= fm10k_dbg_desc_seq_next
,
118 .stop
= fm10k_dbg_desc_seq_stop
,
119 .show
= fm10k_dbg_tx_desc_seq_show
,
122 static const struct seq_operations fm10k_dbg_rx_desc_seq_ops
= {
123 .start
= fm10k_dbg_desc_seq_start
,
124 .next
= fm10k_dbg_desc_seq_next
,
125 .stop
= fm10k_dbg_desc_seq_stop
,
126 .show
= fm10k_dbg_rx_desc_seq_show
,
129 static int fm10k_dbg_desc_open(struct inode
*inode
, struct file
*filep
)
131 struct fm10k_ring
*ring
= inode
->i_private
;
132 struct fm10k_q_vector
*q_vector
= ring
->q_vector
;
133 const struct seq_operations
*desc_seq_ops
;
136 if (ring
< q_vector
->rx
.ring
)
137 desc_seq_ops
= &fm10k_dbg_tx_desc_seq_ops
;
139 desc_seq_ops
= &fm10k_dbg_rx_desc_seq_ops
;
141 err
= seq_open(filep
, desc_seq_ops
);
145 ((struct seq_file
*)filep
->private_data
)->private = ring
;
150 static const struct file_operations fm10k_dbg_desc_fops
= {
151 .owner
= THIS_MODULE
,
152 .open
= fm10k_dbg_desc_open
,
155 .release
= seq_release
,
159 * fm10k_dbg_q_vector_init - setup debugfs for the q_vectors
160 * @q_vector: q_vector to allocate directories for
162 * A folder is created for each q_vector found. In each q_vector
163 * folder, a debugfs file is created for each tx and rx ring
164 * allocated to the q_vector.
166 void fm10k_dbg_q_vector_init(struct fm10k_q_vector
*q_vector
)
168 struct fm10k_intfc
*interface
= q_vector
->interface
;
172 if (!interface
->dbg_intfc
)
175 /* Generate a folder for each q_vector */
176 sprintf(name
, "q_vector.%03d", q_vector
->v_idx
);
178 q_vector
->dbg_q_vector
= debugfs_create_dir(name
, interface
->dbg_intfc
);
179 if (!q_vector
->dbg_q_vector
)
182 /* Generate a file for each rx ring in the q_vector */
183 for (i
= 0; i
< q_vector
->tx
.count
; i
++) {
184 struct fm10k_ring
*ring
= &q_vector
->tx
.ring
[i
];
186 sprintf(name
, "tx_ring.%03d", ring
->queue_index
);
188 debugfs_create_file(name
, 0600,
189 q_vector
->dbg_q_vector
, ring
,
190 &fm10k_dbg_desc_fops
);
193 /* Generate a file for each rx ring in the q_vector */
194 for (i
= 0; i
< q_vector
->rx
.count
; i
++) {
195 struct fm10k_ring
*ring
= &q_vector
->rx
.ring
[i
];
197 sprintf(name
, "rx_ring.%03d", ring
->queue_index
);
199 debugfs_create_file(name
, 0600,
200 q_vector
->dbg_q_vector
, ring
,
201 &fm10k_dbg_desc_fops
);
206 * fm10k_dbg_free_q_vector_dir - setup debugfs for the q_vectors
207 * @q_vector: q_vector to allocate directories for
209 void fm10k_dbg_q_vector_exit(struct fm10k_q_vector
*q_vector
)
211 struct fm10k_intfc
*interface
= q_vector
->interface
;
213 if (interface
->dbg_intfc
)
214 debugfs_remove_recursive(q_vector
->dbg_q_vector
);
215 q_vector
->dbg_q_vector
= NULL
;
219 * fm10k_dbg_intfc_init - setup the debugfs directory for the intferface
220 * @interface: the interface that is starting up
223 void fm10k_dbg_intfc_init(struct fm10k_intfc
*interface
)
225 const char *name
= pci_name(interface
->pdev
);
228 interface
->dbg_intfc
= debugfs_create_dir(name
, dbg_root
);
232 * fm10k_dbg_intfc_exit - clean out the interface's debugfs entries
233 * @interface: the interface that is stopping
235 void fm10k_dbg_intfc_exit(struct fm10k_intfc
*interface
)
238 debugfs_remove_recursive(interface
->dbg_intfc
);
239 interface
->dbg_intfc
= NULL
;
243 * fm10k_dbg_init - start up debugfs for the driver
245 void fm10k_dbg_init(void)
247 dbg_root
= debugfs_create_dir(fm10k_driver_name
, NULL
);
251 * fm10k_dbg_exit - clean out the driver's debugfs entries
253 void fm10k_dbg_exit(void)
255 debugfs_remove_recursive(dbg_root
);
259 #endif /* CONFIG_DEBUG_FS */