blob: 7aae0561c9c5a4eb8721b593c6bab4123552d876 [file] [log] [blame]
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Greg Rosedc641b72013-12-18 13:45:51 +00004 * Copyright(c) 2013 - 2014 Intel Corporation.
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburg02e9c292013-09-11 08:40:17 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27#ifdef CONFIG_DEBUG_FS
28
29#include <linux/fs.h>
30#include <linux/debugfs.h>
31
32#include "i40e.h"
33
34static struct dentry *i40e_dbg_root;
35
36/**
37 * i40e_dbg_find_vsi - searches for the vsi with the given seid
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000038 * @pf - the PF structure to search for the vsi
Jesse Brandeburg02e9c292013-09-11 08:40:17 +000039 * @seid - seid of the vsi it is searching for
40 **/
41static struct i40e_vsi *i40e_dbg_find_vsi(struct i40e_pf *pf, int seid)
42{
43 int i;
44
45 if (seid < 0)
46 dev_info(&pf->pdev->dev, "%d: bad seid\n", seid);
47 else
Mitch Williams505682c2014-05-20 08:01:37 +000048 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg02e9c292013-09-11 08:40:17 +000049 if (pf->vsi[i] && (pf->vsi[i]->seid == seid))
50 return pf->vsi[i];
51
52 return NULL;
53}
54
55/**
56 * i40e_dbg_find_veb - searches for the veb with the given seid
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000057 * @pf - the PF structure to search for the veb
Jesse Brandeburg02e9c292013-09-11 08:40:17 +000058 * @seid - seid of the veb it is searching for
59 **/
60static struct i40e_veb *i40e_dbg_find_veb(struct i40e_pf *pf, int seid)
61{
62 int i;
63
64 if ((seid < I40E_BASE_VEB_SEID) ||
65 (seid > (I40E_BASE_VEB_SEID + I40E_MAX_VEB)))
66 dev_info(&pf->pdev->dev, "%d: bad seid\n", seid);
67 else
68 for (i = 0; i < I40E_MAX_VEB; i++)
69 if (pf->veb[i] && pf->veb[i]->seid == seid)
70 return pf->veb[i];
71 return NULL;
72}
73
74/**************************************************************
75 * dump
76 * The dump entry in debugfs is for getting a data snapshow of
77 * the driver's current configuration and runtime details.
78 * When the filesystem entry is written, a snapshot is taken.
79 * When the entry is read, the most recent snapshot data is dumped.
80 **************************************************************/
81static char *i40e_dbg_dump_buf;
82static ssize_t i40e_dbg_dump_data_len;
83static ssize_t i40e_dbg_dump_buffer_len;
84
85/**
86 * i40e_dbg_dump_read - read the dump data
87 * @filp: the opened file
88 * @buffer: where to write the data for the user to read
89 * @count: the size of the user's buffer
90 * @ppos: file position offset
91 **/
92static ssize_t i40e_dbg_dump_read(struct file *filp, char __user *buffer,
93 size_t count, loff_t *ppos)
94{
95 int bytes_not_copied;
96 int len;
97
98 /* is *ppos bigger than the available data? */
99 if (*ppos >= i40e_dbg_dump_data_len || !i40e_dbg_dump_buf)
100 return 0;
101
102 /* be sure to not read beyond the end of available data */
103 len = min_t(int, count, (i40e_dbg_dump_data_len - *ppos));
104
105 bytes_not_copied = copy_to_user(buffer, &i40e_dbg_dump_buf[*ppos], len);
Rasmus Villemoes0286c672015-10-17 22:58:19 +0200106 if (bytes_not_copied)
107 return -EFAULT;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000108
109 *ppos += len;
110 return len;
111}
112
113/**
114 * i40e_dbg_prep_dump_buf
Jeff Kirsherb40c82e62015-02-27 09:18:34 +0000115 * @pf: the PF we're working with
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000116 * @buflen: the desired buffer length
117 *
118 * Return positive if success, 0 if failed
119 **/
120static int i40e_dbg_prep_dump_buf(struct i40e_pf *pf, int buflen)
121{
122 /* if not already big enough, prep for re alloc */
123 if (i40e_dbg_dump_buffer_len && i40e_dbg_dump_buffer_len < buflen) {
124 kfree(i40e_dbg_dump_buf);
125 i40e_dbg_dump_buffer_len = 0;
126 i40e_dbg_dump_buf = NULL;
127 }
128
129 /* get a new buffer if needed */
130 if (!i40e_dbg_dump_buf) {
131 i40e_dbg_dump_buf = kzalloc(buflen, GFP_KERNEL);
132 if (i40e_dbg_dump_buf != NULL)
133 i40e_dbg_dump_buffer_len = buflen;
134 }
135
136 return i40e_dbg_dump_buffer_len;
137}
138
139/**
140 * i40e_dbg_dump_write - trigger a datadump snapshot
141 * @filp: the opened file
142 * @buffer: where to find the user's data
143 * @count: the length of the user's data
144 * @ppos: file position offset
145 *
146 * Any write clears the stats
147 **/
148static ssize_t i40e_dbg_dump_write(struct file *filp,
149 const char __user *buffer,
150 size_t count, loff_t *ppos)
151{
152 struct i40e_pf *pf = filp->private_data;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000153 bool seid_found = false;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000154 long seid = -1;
155 int buflen = 0;
156 int i, ret;
157 int len;
158 u8 *p;
159
160 /* don't allow partial writes */
161 if (*ppos != 0)
162 return 0;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000163
164 /* decode the SEID given to be dumped */
Jesse Brandeburg004173c2013-09-28 07:13:44 +0000165 ret = kstrtol_from_user(buffer, count, 0, &seid);
166
167 if (ret) {
168 dev_info(&pf->pdev->dev, "bad seid value\n");
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000169 } else if (seid == 0) {
170 seid_found = true;
171
172 kfree(i40e_dbg_dump_buf);
173 i40e_dbg_dump_buffer_len = 0;
174 i40e_dbg_dump_data_len = 0;
175 i40e_dbg_dump_buf = NULL;
176 dev_info(&pf->pdev->dev, "debug buffer freed\n");
177
178 } else if (seid == pf->pf_seid || seid == 1) {
179 seid_found = true;
180
181 buflen = sizeof(struct i40e_pf);
182 buflen += (sizeof(struct i40e_aq_desc)
183 * (pf->hw.aq.num_arq_entries + pf->hw.aq.num_asq_entries));
184
185 if (i40e_dbg_prep_dump_buf(pf, buflen)) {
186 p = i40e_dbg_dump_buf;
187
188 len = sizeof(struct i40e_pf);
189 memcpy(p, pf, len);
190 p += len;
191
192 len = (sizeof(struct i40e_aq_desc)
193 * pf->hw.aq.num_asq_entries);
David Cassard90bb7762013-11-28 06:39:35 +0000194 memcpy(p, pf->hw.aq.asq.desc_buf.va, len);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000195 p += len;
196
197 len = (sizeof(struct i40e_aq_desc)
198 * pf->hw.aq.num_arq_entries);
David Cassard90bb7762013-11-28 06:39:35 +0000199 memcpy(p, pf->hw.aq.arq.desc_buf.va, len);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000200 p += len;
201
202 i40e_dbg_dump_data_len = buflen;
203 dev_info(&pf->pdev->dev,
204 "PF seid %ld dumped %d bytes\n",
205 seid, (int)i40e_dbg_dump_data_len);
206 }
207 } else if (seid >= I40E_BASE_VSI_SEID) {
208 struct i40e_vsi *vsi = NULL;
209 struct i40e_mac_filter *f;
210 int filter_count = 0;
211
212 mutex_lock(&pf->switch_mutex);
213 vsi = i40e_dbg_find_vsi(pf, seid);
214 if (!vsi) {
215 mutex_unlock(&pf->switch_mutex);
216 goto write_exit;
217 }
218
219 buflen = sizeof(struct i40e_vsi);
220 buflen += sizeof(struct i40e_q_vector) * vsi->num_q_vectors;
221 buflen += sizeof(struct i40e_ring) * 2 * vsi->num_queue_pairs;
222 buflen += sizeof(struct i40e_tx_buffer) * vsi->num_queue_pairs;
223 buflen += sizeof(struct i40e_rx_buffer) * vsi->num_queue_pairs;
224 list_for_each_entry(f, &vsi->mac_filter_list, list)
225 filter_count++;
226 buflen += sizeof(struct i40e_mac_filter) * filter_count;
227
228 if (i40e_dbg_prep_dump_buf(pf, buflen)) {
229 p = i40e_dbg_dump_buf;
230 seid_found = true;
231
232 len = sizeof(struct i40e_vsi);
233 memcpy(p, vsi, len);
234 p += len;
235
Shannon Nelson59072ba2013-09-28 07:14:09 +0000236 if (vsi->num_q_vectors) {
237 len = (sizeof(struct i40e_q_vector)
238 * vsi->num_q_vectors);
239 memcpy(p, vsi->q_vectors, len);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000240 p += len;
241 }
Shannon Nelson59072ba2013-09-28 07:14:09 +0000242
243 if (vsi->num_queue_pairs) {
244 len = (sizeof(struct i40e_ring) *
245 vsi->num_queue_pairs);
246 memcpy(p, vsi->tx_rings, len);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000247 p += len;
Shannon Nelson59072ba2013-09-28 07:14:09 +0000248 memcpy(p, vsi->rx_rings, len);
249 p += len;
250 }
251
252 if (vsi->tx_rings[0]) {
253 len = sizeof(struct i40e_tx_buffer);
254 for (i = 0; i < vsi->num_queue_pairs; i++) {
255 memcpy(p, vsi->tx_rings[i]->tx_bi, len);
256 p += len;
257 }
258 len = sizeof(struct i40e_rx_buffer);
259 for (i = 0; i < vsi->num_queue_pairs; i++) {
260 memcpy(p, vsi->rx_rings[i]->rx_bi, len);
261 p += len;
262 }
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000263 }
264
265 /* macvlan filter list */
266 len = sizeof(struct i40e_mac_filter);
267 list_for_each_entry(f, &vsi->mac_filter_list, list) {
268 memcpy(p, f, len);
269 p += len;
270 }
271
272 i40e_dbg_dump_data_len = buflen;
273 dev_info(&pf->pdev->dev,
274 "VSI seid %ld dumped %d bytes\n",
275 seid, (int)i40e_dbg_dump_data_len);
276 }
277 mutex_unlock(&pf->switch_mutex);
278 } else if (seid >= I40E_BASE_VEB_SEID) {
279 struct i40e_veb *veb = NULL;
280
281 mutex_lock(&pf->switch_mutex);
282 veb = i40e_dbg_find_veb(pf, seid);
283 if (!veb) {
284 mutex_unlock(&pf->switch_mutex);
285 goto write_exit;
286 }
287
288 buflen = sizeof(struct i40e_veb);
289 if (i40e_dbg_prep_dump_buf(pf, buflen)) {
290 seid_found = true;
291 memcpy(i40e_dbg_dump_buf, veb, buflen);
292 i40e_dbg_dump_data_len = buflen;
293 dev_info(&pf->pdev->dev,
294 "VEB seid %ld dumped %d bytes\n",
295 seid, (int)i40e_dbg_dump_data_len);
296 }
297 mutex_unlock(&pf->switch_mutex);
298 }
299
300write_exit:
301 if (!seid_found)
302 dev_info(&pf->pdev->dev, "unknown seid %ld\n", seid);
303
304 return count;
305}
306
307static const struct file_operations i40e_dbg_dump_fops = {
308 .owner = THIS_MODULE,
309 .open = simple_open,
310 .read = i40e_dbg_dump_read,
311 .write = i40e_dbg_dump_write,
312};
313
314/**************************************************************
315 * command
316 * The command entry in debugfs is for giving the driver commands
317 * to be executed - these may be for changing the internal switch
318 * setup, adding or removing filters, or other things. Many of
319 * these will be useful for some forms of unit testing.
320 **************************************************************/
Greg Rosed1da3ac2015-02-27 09:18:29 +0000321static char i40e_dbg_command_buf[256] = "";
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000322
323/**
324 * i40e_dbg_command_read - read for command datum
325 * @filp: the opened file
326 * @buffer: where to write the data for the user to read
327 * @count: the size of the user's buffer
328 * @ppos: file position offset
329 **/
330static ssize_t i40e_dbg_command_read(struct file *filp, char __user *buffer,
331 size_t count, loff_t *ppos)
332{
333 struct i40e_pf *pf = filp->private_data;
334 int bytes_not_copied;
335 int buf_size = 256;
336 char *buf;
337 int len;
338
339 /* don't allow partial reads */
340 if (*ppos != 0)
341 return 0;
342 if (count < buf_size)
343 return -ENOSPC;
344
345 buf = kzalloc(buf_size, GFP_KERNEL);
346 if (!buf)
347 return -ENOSPC;
348
349 len = snprintf(buf, buf_size, "%s: %s\n",
350 pf->vsi[pf->lan_vsi]->netdev->name,
351 i40e_dbg_command_buf);
352
353 bytes_not_copied = copy_to_user(buffer, buf, len);
354 kfree(buf);
355
Rasmus Villemoes0286c672015-10-17 22:58:19 +0200356 if (bytes_not_copied)
357 return -EFAULT;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000358
359 *ppos = len;
360 return len;
361}
362
363/**
Shannon Nelsone625f712013-11-26 10:49:31 +0000364 * i40e_dbg_dump_vsi_seid - handles dump vsi seid write into command datum
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000365 * @pf: the i40e_pf created in command write
366 * @seid: the seid the user put in
367 **/
368static void i40e_dbg_dump_vsi_seid(struct i40e_pf *pf, int seid)
369{
370 struct rtnl_link_stats64 *nstat;
371 struct i40e_mac_filter *f;
372 struct i40e_vsi *vsi;
373 int i;
374
375 vsi = i40e_dbg_find_vsi(pf, seid);
376 if (!vsi) {
377 dev_info(&pf->pdev->dev,
378 "dump %d: seid not found\n", seid);
379 return;
380 }
381 dev_info(&pf->pdev->dev, "vsi seid %d\n", seid);
Shannon Nelsonde1017f2015-12-23 12:05:53 -0800382 if (vsi->netdev) {
383 struct net_device *nd = vsi->netdev;
384
385 dev_info(&pf->pdev->dev, " netdev: name = %s, state = %lu, flags = 0x%08x\n",
386 nd->name, nd->state, nd->flags);
387 dev_info(&pf->pdev->dev, " features = 0x%08lx\n",
388 (unsigned long int)nd->features);
389 dev_info(&pf->pdev->dev, " hw_features = 0x%08lx\n",
390 (unsigned long int)nd->hw_features);
391 dev_info(&pf->pdev->dev, " vlan_features = 0x%08lx\n",
392 (unsigned long int)nd->vlan_features);
393 }
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000394 if (vsi->active_vlans)
395 dev_info(&pf->pdev->dev,
396 " vlgrp: & = %p\n", vsi->active_vlans);
397 dev_info(&pf->pdev->dev,
Shannon Nelsonde1017f2015-12-23 12:05:53 -0800398 " state = %li flags = 0x%08lx, netdev_registered = %i, current_netdev_flags = 0x%04x\n",
399 vsi->state, vsi->flags,
400 vsi->netdev_registered, vsi->current_netdev_flags);
Shannon Nelson2ddb80c2015-02-27 09:18:36 +0000401 if (vsi == pf->vsi[pf->lan_vsi])
Shannon Nelsonde1017f2015-12-23 12:05:53 -0800402 dev_info(&pf->pdev->dev, " MAC address: %pM SAN MAC: %pM Port MAC: %pM\n",
Shannon Nelson2ddb80c2015-02-27 09:18:36 +0000403 pf->hw.mac.addr,
404 pf->hw.mac.san_addr,
405 pf->hw.mac.port_addr);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000406 list_for_each_entry(f, &vsi->mac_filter_list, list) {
407 dev_info(&pf->pdev->dev,
408 " mac_filter_list: %pM vid=%d, is_netdev=%d is_vf=%d counter=%d\n",
409 f->macaddr, f->vlan, f->is_netdev, f->is_vf,
410 f->counter);
411 }
412 nstat = i40e_get_vsi_stats_struct(vsi);
413 dev_info(&pf->pdev->dev,
414 " net_stats: rx_packets = %lu, rx_bytes = %lu, rx_errors = %lu, rx_dropped = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400415 (unsigned long int)nstat->rx_packets,
416 (unsigned long int)nstat->rx_bytes,
417 (unsigned long int)nstat->rx_errors,
418 (unsigned long int)nstat->rx_dropped);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000419 dev_info(&pf->pdev->dev,
420 " net_stats: tx_packets = %lu, tx_bytes = %lu, tx_errors = %lu, tx_dropped = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400421 (unsigned long int)nstat->tx_packets,
422 (unsigned long int)nstat->tx_bytes,
423 (unsigned long int)nstat->tx_errors,
424 (unsigned long int)nstat->tx_dropped);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000425 dev_info(&pf->pdev->dev,
426 " net_stats: multicast = %lu, collisions = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400427 (unsigned long int)nstat->multicast,
428 (unsigned long int)nstat->collisions);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000429 dev_info(&pf->pdev->dev,
430 " net_stats: rx_length_errors = %lu, rx_over_errors = %lu, rx_crc_errors = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400431 (unsigned long int)nstat->rx_length_errors,
432 (unsigned long int)nstat->rx_over_errors,
433 (unsigned long int)nstat->rx_crc_errors);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000434 dev_info(&pf->pdev->dev,
435 " net_stats: rx_frame_errors = %lu, rx_fifo_errors = %lu, rx_missed_errors = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400436 (unsigned long int)nstat->rx_frame_errors,
437 (unsigned long int)nstat->rx_fifo_errors,
438 (unsigned long int)nstat->rx_missed_errors);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000439 dev_info(&pf->pdev->dev,
440 " net_stats: tx_aborted_errors = %lu, tx_carrier_errors = %lu, tx_fifo_errors = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400441 (unsigned long int)nstat->tx_aborted_errors,
442 (unsigned long int)nstat->tx_carrier_errors,
443 (unsigned long int)nstat->tx_fifo_errors);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000444 dev_info(&pf->pdev->dev,
445 " net_stats: tx_heartbeat_errors = %lu, tx_window_errors = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400446 (unsigned long int)nstat->tx_heartbeat_errors,
447 (unsigned long int)nstat->tx_window_errors);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000448 dev_info(&pf->pdev->dev,
449 " net_stats: rx_compressed = %lu, tx_compressed = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400450 (unsigned long int)nstat->rx_compressed,
451 (unsigned long int)nstat->tx_compressed);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000452 dev_info(&pf->pdev->dev,
453 " net_stats_offsets: rx_packets = %lu, rx_bytes = %lu, rx_errors = %lu, rx_dropped = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400454 (unsigned long int)vsi->net_stats_offsets.rx_packets,
455 (unsigned long int)vsi->net_stats_offsets.rx_bytes,
456 (unsigned long int)vsi->net_stats_offsets.rx_errors,
457 (unsigned long int)vsi->net_stats_offsets.rx_dropped);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000458 dev_info(&pf->pdev->dev,
459 " net_stats_offsets: tx_packets = %lu, tx_bytes = %lu, tx_errors = %lu, tx_dropped = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400460 (unsigned long int)vsi->net_stats_offsets.tx_packets,
461 (unsigned long int)vsi->net_stats_offsets.tx_bytes,
462 (unsigned long int)vsi->net_stats_offsets.tx_errors,
463 (unsigned long int)vsi->net_stats_offsets.tx_dropped);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000464 dev_info(&pf->pdev->dev,
465 " net_stats_offsets: multicast = %lu, collisions = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400466 (unsigned long int)vsi->net_stats_offsets.multicast,
467 (unsigned long int)vsi->net_stats_offsets.collisions);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000468 dev_info(&pf->pdev->dev,
469 " net_stats_offsets: rx_length_errors = %lu, rx_over_errors = %lu, rx_crc_errors = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400470 (unsigned long int)vsi->net_stats_offsets.rx_length_errors,
471 (unsigned long int)vsi->net_stats_offsets.rx_over_errors,
472 (unsigned long int)vsi->net_stats_offsets.rx_crc_errors);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000473 dev_info(&pf->pdev->dev,
474 " net_stats_offsets: rx_frame_errors = %lu, rx_fifo_errors = %lu, rx_missed_errors = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400475 (unsigned long int)vsi->net_stats_offsets.rx_frame_errors,
476 (unsigned long int)vsi->net_stats_offsets.rx_fifo_errors,
477 (unsigned long int)vsi->net_stats_offsets.rx_missed_errors);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000478 dev_info(&pf->pdev->dev,
479 " net_stats_offsets: tx_aborted_errors = %lu, tx_carrier_errors = %lu, tx_fifo_errors = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400480 (unsigned long int)vsi->net_stats_offsets.tx_aborted_errors,
481 (unsigned long int)vsi->net_stats_offsets.tx_carrier_errors,
482 (unsigned long int)vsi->net_stats_offsets.tx_fifo_errors);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000483 dev_info(&pf->pdev->dev,
484 " net_stats_offsets: tx_heartbeat_errors = %lu, tx_window_errors = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400485 (unsigned long int)vsi->net_stats_offsets.tx_heartbeat_errors,
486 (unsigned long int)vsi->net_stats_offsets.tx_window_errors);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000487 dev_info(&pf->pdev->dev,
488 " net_stats_offsets: rx_compressed = %lu, tx_compressed = %lu\n",
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400489 (unsigned long int)vsi->net_stats_offsets.rx_compressed,
490 (unsigned long int)vsi->net_stats_offsets.tx_compressed);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000491 dev_info(&pf->pdev->dev,
492 " tx_restart = %d, tx_busy = %d, rx_buf_failed = %d, rx_page_failed = %d\n",
493 vsi->tx_restart, vsi->tx_busy,
494 vsi->rx_buf_failed, vsi->rx_page_failed);
Alexander Duyck9f65e152013-09-28 06:00:58 +0000495 rcu_read_lock();
496 for (i = 0; i < vsi->num_queue_pairs; i++) {
497 struct i40e_ring *rx_ring = ACCESS_ONCE(vsi->rx_rings[i]);
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400498
Alexander Duyck9f65e152013-09-28 06:00:58 +0000499 if (!rx_ring)
500 continue;
501
502 dev_info(&pf->pdev->dev,
503 " rx_rings[%i]: desc = %p\n",
504 i, rx_ring->desc);
505 dev_info(&pf->pdev->dev,
506 " rx_rings[%i]: dev = %p, netdev = %p, rx_bi = %p\n",
507 i, rx_ring->dev,
508 rx_ring->netdev,
509 rx_ring->rx_bi);
510 dev_info(&pf->pdev->dev,
511 " rx_rings[%i]: state = %li, queue_index = %d, reg_idx = %d\n",
512 i, rx_ring->state,
513 rx_ring->queue_index,
514 rx_ring->reg_idx);
515 dev_info(&pf->pdev->dev,
516 " rx_rings[%i]: rx_hdr_len = %d, rx_buf_len = %d, dtype = %d\n",
517 i, rx_ring->rx_hdr_len,
518 rx_ring->rx_buf_len,
519 rx_ring->dtype);
520 dev_info(&pf->pdev->dev,
521 " rx_rings[%i]: hsplit = %d, next_to_use = %d, next_to_clean = %d, ring_active = %i\n",
522 i, rx_ring->hsplit,
523 rx_ring->next_to_use,
524 rx_ring->next_to_clean,
525 rx_ring->ring_active);
526 dev_info(&pf->pdev->dev,
527 " rx_rings[%i]: rx_stats: packets = %lld, bytes = %lld, non_eop_descs = %lld\n",
528 i, rx_ring->stats.packets,
529 rx_ring->stats.bytes,
530 rx_ring->rx_stats.non_eop_descs);
531 dev_info(&pf->pdev->dev,
Mitch Williams420136c2013-12-18 13:45:59 +0000532 " rx_rings[%i]: rx_stats: alloc_page_failed = %lld, alloc_buff_failed = %lld\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000533 i,
Mitch Williams420136c2013-12-18 13:45:59 +0000534 rx_ring->rx_stats.alloc_page_failed,
535 rx_ring->rx_stats.alloc_buff_failed);
Alexander Duyck9f65e152013-09-28 06:00:58 +0000536 dev_info(&pf->pdev->dev,
537 " rx_rings[%i]: size = %i, dma = 0x%08lx\n",
538 i, rx_ring->size,
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400539 (unsigned long int)rx_ring->dma);
Alexander Duyck9f65e152013-09-28 06:00:58 +0000540 dev_info(&pf->pdev->dev,
541 " rx_rings[%i]: vsi = %p, q_vector = %p\n",
542 i, rx_ring->vsi,
543 rx_ring->q_vector);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000544 }
Alexander Duyck9f65e152013-09-28 06:00:58 +0000545 for (i = 0; i < vsi->num_queue_pairs; i++) {
546 struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400547
Alexander Duyck9f65e152013-09-28 06:00:58 +0000548 if (!tx_ring)
549 continue;
Jesse Brandeburg1b60f3c2013-11-28 06:39:35 +0000550
Alexander Duyck9f65e152013-09-28 06:00:58 +0000551 dev_info(&pf->pdev->dev,
552 " tx_rings[%i]: desc = %p\n",
553 i, tx_ring->desc);
554 dev_info(&pf->pdev->dev,
555 " tx_rings[%i]: dev = %p, netdev = %p, tx_bi = %p\n",
556 i, tx_ring->dev,
557 tx_ring->netdev,
558 tx_ring->tx_bi);
559 dev_info(&pf->pdev->dev,
560 " tx_rings[%i]: state = %li, queue_index = %d, reg_idx = %d\n",
561 i, tx_ring->state,
562 tx_ring->queue_index,
563 tx_ring->reg_idx);
564 dev_info(&pf->pdev->dev,
565 " tx_rings[%i]: dtype = %d\n",
566 i, tx_ring->dtype);
567 dev_info(&pf->pdev->dev,
568 " tx_rings[%i]: hsplit = %d, next_to_use = %d, next_to_clean = %d, ring_active = %i\n",
569 i, tx_ring->hsplit,
570 tx_ring->next_to_use,
571 tx_ring->next_to_clean,
572 tx_ring->ring_active);
573 dev_info(&pf->pdev->dev,
574 " tx_rings[%i]: tx_stats: packets = %lld, bytes = %lld, restart_queue = %lld\n",
575 i, tx_ring->stats.packets,
576 tx_ring->stats.bytes,
577 tx_ring->tx_stats.restart_queue);
578 dev_info(&pf->pdev->dev,
579 " tx_rings[%i]: tx_stats: tx_busy = %lld, tx_done_old = %lld\n",
580 i,
581 tx_ring->tx_stats.tx_busy,
582 tx_ring->tx_stats.tx_done_old);
583 dev_info(&pf->pdev->dev,
584 " tx_rings[%i]: size = %i, dma = 0x%08lx\n",
585 i, tx_ring->size,
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400586 (unsigned long int)tx_ring->dma);
Alexander Duyck9f65e152013-09-28 06:00:58 +0000587 dev_info(&pf->pdev->dev,
588 " tx_rings[%i]: vsi = %p, q_vector = %p\n",
589 i, tx_ring->vsi,
590 tx_ring->q_vector);
591 dev_info(&pf->pdev->dev,
592 " tx_rings[%i]: DCB tc = %d\n",
593 i, tx_ring->dcb_tc);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000594 }
Alexander Duyck9f65e152013-09-28 06:00:58 +0000595 rcu_read_unlock();
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000596 dev_info(&pf->pdev->dev,
597 " work_limit = %d, rx_itr_setting = %d (%s), tx_itr_setting = %d (%s)\n",
598 vsi->work_limit, vsi->rx_itr_setting,
599 ITR_IS_DYNAMIC(vsi->rx_itr_setting) ? "dynamic" : "fixed",
600 vsi->tx_itr_setting,
601 ITR_IS_DYNAMIC(vsi->tx_itr_setting) ? "dynamic" : "fixed");
602 dev_info(&pf->pdev->dev,
603 " max_frame = %d, rx_hdr_len = %d, rx_buf_len = %d dtype = %d\n",
604 vsi->max_frame, vsi->rx_hdr_len, vsi->rx_buf_len, vsi->dtype);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000605 dev_info(&pf->pdev->dev,
606 " num_q_vectors = %i, base_vector = %i\n",
607 vsi->num_q_vectors, vsi->base_vector);
608 dev_info(&pf->pdev->dev,
609 " seid = %d, id = %d, uplink_seid = %d\n",
610 vsi->seid, vsi->id, vsi->uplink_seid);
611 dev_info(&pf->pdev->dev,
612 " base_queue = %d, num_queue_pairs = %d, num_desc = %d\n",
613 vsi->base_queue, vsi->num_queue_pairs, vsi->num_desc);
614 dev_info(&pf->pdev->dev, " type = %i\n", vsi->type);
615 dev_info(&pf->pdev->dev,
616 " info: valid_sections = 0x%04x, switch_id = 0x%04x\n",
617 vsi->info.valid_sections, vsi->info.switch_id);
618 dev_info(&pf->pdev->dev,
619 " info: sw_reserved[] = 0x%02x 0x%02x\n",
620 vsi->info.sw_reserved[0], vsi->info.sw_reserved[1]);
621 dev_info(&pf->pdev->dev,
622 " info: sec_flags = 0x%02x, sec_reserved = 0x%02x\n",
623 vsi->info.sec_flags, vsi->info.sec_reserved);
624 dev_info(&pf->pdev->dev,
625 " info: pvid = 0x%04x, fcoe_pvid = 0x%04x, port_vlan_flags = 0x%02x\n",
626 vsi->info.pvid, vsi->info.fcoe_pvid,
627 vsi->info.port_vlan_flags);
628 dev_info(&pf->pdev->dev,
629 " info: pvlan_reserved[] = 0x%02x 0x%02x 0x%02x\n",
630 vsi->info.pvlan_reserved[0], vsi->info.pvlan_reserved[1],
631 vsi->info.pvlan_reserved[2]);
632 dev_info(&pf->pdev->dev,
633 " info: ingress_table = 0x%08x, egress_table = 0x%08x\n",
634 vsi->info.ingress_table, vsi->info.egress_table);
635 dev_info(&pf->pdev->dev,
636 " info: cas_pv_stag = 0x%04x, cas_pv_flags= 0x%02x, cas_pv_reserved = 0x%02x\n",
637 vsi->info.cas_pv_tag, vsi->info.cas_pv_flags,
638 vsi->info.cas_pv_reserved);
639 dev_info(&pf->pdev->dev,
640 " info: queue_mapping[0..7 ] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
641 vsi->info.queue_mapping[0], vsi->info.queue_mapping[1],
642 vsi->info.queue_mapping[2], vsi->info.queue_mapping[3],
643 vsi->info.queue_mapping[4], vsi->info.queue_mapping[5],
644 vsi->info.queue_mapping[6], vsi->info.queue_mapping[7]);
645 dev_info(&pf->pdev->dev,
646 " info: queue_mapping[8..15] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
647 vsi->info.queue_mapping[8], vsi->info.queue_mapping[9],
648 vsi->info.queue_mapping[10], vsi->info.queue_mapping[11],
649 vsi->info.queue_mapping[12], vsi->info.queue_mapping[13],
650 vsi->info.queue_mapping[14], vsi->info.queue_mapping[15]);
651 dev_info(&pf->pdev->dev,
652 " info: tc_mapping[] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
653 vsi->info.tc_mapping[0], vsi->info.tc_mapping[1],
654 vsi->info.tc_mapping[2], vsi->info.tc_mapping[3],
655 vsi->info.tc_mapping[4], vsi->info.tc_mapping[5],
656 vsi->info.tc_mapping[6], vsi->info.tc_mapping[7]);
657 dev_info(&pf->pdev->dev,
658 " info: queueing_opt_flags = 0x%02x queueing_opt_reserved[0..2] = 0x%02x 0x%02x 0x%02x\n",
659 vsi->info.queueing_opt_flags,
660 vsi->info.queueing_opt_reserved[0],
661 vsi->info.queueing_opt_reserved[1],
662 vsi->info.queueing_opt_reserved[2]);
663 dev_info(&pf->pdev->dev,
664 " info: up_enable_bits = 0x%02x\n",
665 vsi->info.up_enable_bits);
666 dev_info(&pf->pdev->dev,
667 " info: sched_reserved = 0x%02x, outer_up_table = 0x%04x\n",
668 vsi->info.sched_reserved, vsi->info.outer_up_table);
669 dev_info(&pf->pdev->dev,
670 " info: cmd_reserved[] = 0x%02x 0x%02x 0x%02x 0x0%02x 0x%02x 0x%02x 0x%02x 0x0%02x\n",
671 vsi->info.cmd_reserved[0], vsi->info.cmd_reserved[1],
672 vsi->info.cmd_reserved[2], vsi->info.cmd_reserved[3],
673 vsi->info.cmd_reserved[4], vsi->info.cmd_reserved[5],
674 vsi->info.cmd_reserved[6], vsi->info.cmd_reserved[7]);
675 dev_info(&pf->pdev->dev,
676 " info: qs_handle[] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
677 vsi->info.qs_handle[0], vsi->info.qs_handle[1],
678 vsi->info.qs_handle[2], vsi->info.qs_handle[3],
679 vsi->info.qs_handle[4], vsi->info.qs_handle[5],
680 vsi->info.qs_handle[6], vsi->info.qs_handle[7]);
681 dev_info(&pf->pdev->dev,
682 " info: stat_counter_idx = 0x%04x, sched_id = 0x%04x\n",
683 vsi->info.stat_counter_idx, vsi->info.sched_id);
684 dev_info(&pf->pdev->dev,
685 " info: resp_reserved[] = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
686 vsi->info.resp_reserved[0], vsi->info.resp_reserved[1],
687 vsi->info.resp_reserved[2], vsi->info.resp_reserved[3],
688 vsi->info.resp_reserved[4], vsi->info.resp_reserved[5],
689 vsi->info.resp_reserved[6], vsi->info.resp_reserved[7],
690 vsi->info.resp_reserved[8], vsi->info.resp_reserved[9],
691 vsi->info.resp_reserved[10], vsi->info.resp_reserved[11]);
692 if (vsi->back)
Jeff Kirsherb40c82e62015-02-27 09:18:34 +0000693 dev_info(&pf->pdev->dev, " PF = %p\n", vsi->back);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000694 dev_info(&pf->pdev->dev, " idx = %d\n", vsi->idx);
695 dev_info(&pf->pdev->dev,
696 " tc_config: numtc = %d, enabled_tc = 0x%x\n",
697 vsi->tc_config.numtc, vsi->tc_config.enabled_tc);
698 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
699 dev_info(&pf->pdev->dev,
700 " tc_config: tc = %d, qoffset = %d, qcount = %d, netdev_tc = %d\n",
701 i, vsi->tc_config.tc_info[i].qoffset,
702 vsi->tc_config.tc_info[i].qcount,
703 vsi->tc_config.tc_info[i].netdev_tc);
704 }
705 dev_info(&pf->pdev->dev,
706 " bw: bw_limit = %d, bw_max_quanta = %d\n",
707 vsi->bw_limit, vsi->bw_max_quanta);
708 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
709 dev_info(&pf->pdev->dev,
710 " bw[%d]: ets_share_credits = %d, ets_limit_credits = %d, max_quanta = %d\n",
711 i, vsi->bw_ets_share_credits[i],
712 vsi->bw_ets_limit_credits[i],
713 vsi->bw_ets_max_quanta[i]);
714 }
Vasu Dev38e00432014-08-01 13:27:03 -0700715#ifdef I40E_FCOE
716 if (vsi->type == I40E_VSI_FCOE) {
717 dev_info(&pf->pdev->dev,
718 " fcoe_stats: rx_packets = %llu, rx_dwords = %llu, rx_dropped = %llu\n",
719 vsi->fcoe_stats.rx_fcoe_packets,
720 vsi->fcoe_stats.rx_fcoe_dwords,
721 vsi->fcoe_stats.rx_fcoe_dropped);
722 dev_info(&pf->pdev->dev,
723 " fcoe_stats: tx_packets = %llu, tx_dwords = %llu\n",
724 vsi->fcoe_stats.tx_fcoe_packets,
725 vsi->fcoe_stats.tx_fcoe_dwords);
726 dev_info(&pf->pdev->dev,
727 " fcoe_stats: bad_crc = %llu, last_error = %llu\n",
728 vsi->fcoe_stats.fcoe_bad_fccrc,
729 vsi->fcoe_stats.fcoe_last_error);
730 dev_info(&pf->pdev->dev, " fcoe_stats: ddp_count = %llu\n",
731 vsi->fcoe_stats.fcoe_ddp_count);
732 }
733#endif
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000734}
735
736/**
737 * i40e_dbg_dump_aq_desc - handles dump aq_desc write into command datum
738 * @pf: the i40e_pf created in command write
739 **/
740static void i40e_dbg_dump_aq_desc(struct i40e_pf *pf)
741{
742 struct i40e_adminq_ring *ring;
743 struct i40e_hw *hw = &pf->hw;
Shannon Nelsone625f712013-11-26 10:49:31 +0000744 char hdr[32];
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000745 int i;
746
Shannon Nelsone625f712013-11-26 10:49:31 +0000747 snprintf(hdr, sizeof(hdr), "%s %s: ",
748 dev_driver_string(&pf->pdev->dev),
749 dev_name(&pf->pdev->dev));
750
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000751 /* first the send (command) ring, then the receive (event) ring */
752 dev_info(&pf->pdev->dev, "AdminQ Tx Ring\n");
753 ring = &(hw->aq.asq);
754 for (i = 0; i < ring->count; i++) {
755 struct i40e_aq_desc *d = I40E_ADMINQ_DESC(*ring, i);
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400756
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000757 dev_info(&pf->pdev->dev,
758 " at[%02d] flags=0x%04x op=0x%04x dlen=0x%04x ret=0x%04x cookie_h=0x%08x cookie_l=0x%08x\n",
759 i, d->flags, d->opcode, d->datalen, d->retval,
760 d->cookie_high, d->cookie_low);
Shannon Nelsone625f712013-11-26 10:49:31 +0000761 print_hex_dump(KERN_INFO, hdr, DUMP_PREFIX_NONE,
762 16, 1, d->params.raw, 16, 0);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000763 }
764
765 dev_info(&pf->pdev->dev, "AdminQ Rx Ring\n");
766 ring = &(hw->aq.arq);
767 for (i = 0; i < ring->count; i++) {
768 struct i40e_aq_desc *d = I40E_ADMINQ_DESC(*ring, i);
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400769
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000770 dev_info(&pf->pdev->dev,
771 " ar[%02d] flags=0x%04x op=0x%04x dlen=0x%04x ret=0x%04x cookie_h=0x%08x cookie_l=0x%08x\n",
772 i, d->flags, d->opcode, d->datalen, d->retval,
773 d->cookie_high, d->cookie_low);
Shannon Nelsone625f712013-11-26 10:49:31 +0000774 print_hex_dump(KERN_INFO, hdr, DUMP_PREFIX_NONE,
775 16, 1, d->params.raw, 16, 0);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000776 }
777}
778
779/**
780 * i40e_dbg_dump_desc - handles dump desc write into command datum
781 * @cnt: number of arguments that the user supplied
782 * @vsi_seid: vsi id entered by user
783 * @ring_id: ring id entered by user
784 * @desc_n: descriptor number entered by user
785 * @pf: the i40e_pf created in command write
786 * @is_rx_ring: true if rx, false if tx
787 **/
788static void i40e_dbg_dump_desc(int cnt, int vsi_seid, int ring_id, int desc_n,
789 struct i40e_pf *pf, bool is_rx_ring)
790{
Shannon Nelson68bf94a2014-01-15 15:18:23 -0800791 struct i40e_tx_desc *txd;
792 union i40e_rx_desc *rxd;
Joe Perchese6c97232014-11-18 05:53:00 +0000793 struct i40e_ring *ring;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000794 struct i40e_vsi *vsi;
795 int i;
796
797 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
798 if (!vsi) {
Shannon Nelson7792fe42013-11-26 10:49:29 +0000799 dev_info(&pf->pdev->dev, "vsi %d not found\n", vsi_seid);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000800 return;
801 }
802 if (ring_id >= vsi->num_queue_pairs || ring_id < 0) {
803 dev_info(&pf->pdev->dev, "ring %d not found\n", ring_id);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000804 return;
805 }
Shannon Nelson68bf94a2014-01-15 15:18:23 -0800806 if (!vsi->tx_rings || !vsi->tx_rings[0]->desc) {
Shannon Nelson29d07902013-11-26 10:49:26 +0000807 dev_info(&pf->pdev->dev,
808 "descriptor rings have not been allocated for vsi %d\n",
809 vsi_seid);
810 return;
811 }
Joe Perchese6c97232014-11-18 05:53:00 +0000812
813 ring = kmemdup(is_rx_ring
814 ? vsi->rx_rings[ring_id] : vsi->tx_rings[ring_id],
815 sizeof(*ring), GFP_KERNEL);
816 if (!ring)
817 return;
818
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000819 if (cnt == 2) {
820 dev_info(&pf->pdev->dev, "vsi = %02i %s ring = %02i\n",
821 vsi_seid, is_rx_ring ? "rx" : "tx", ring_id);
Joe Perchese6c97232014-11-18 05:53:00 +0000822 for (i = 0; i < ring->count; i++) {
Shannon Nelson68bf94a2014-01-15 15:18:23 -0800823 if (!is_rx_ring) {
Joe Perchese6c97232014-11-18 05:53:00 +0000824 txd = I40E_TX_DESC(ring, i);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000825 dev_info(&pf->pdev->dev,
Shannon Nelson68bf94a2014-01-15 15:18:23 -0800826 " d[%03i] = 0x%016llx 0x%016llx\n",
827 i, txd->buffer_addr,
828 txd->cmd_type_offset_bsz);
829 } else if (sizeof(union i40e_rx_desc) ==
830 sizeof(union i40e_16byte_rx_desc)) {
Joe Perchese6c97232014-11-18 05:53:00 +0000831 rxd = I40E_RX_DESC(ring, i);
Shannon Nelson68bf94a2014-01-15 15:18:23 -0800832 dev_info(&pf->pdev->dev,
833 " d[%03i] = 0x%016llx 0x%016llx\n",
834 i, rxd->read.pkt_addr,
835 rxd->read.hdr_addr);
836 } else {
Joe Perchese6c97232014-11-18 05:53:00 +0000837 rxd = I40E_RX_DESC(ring, i);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000838 dev_info(&pf->pdev->dev,
839 " d[%03i] = 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",
Shannon Nelson68bf94a2014-01-15 15:18:23 -0800840 i, rxd->read.pkt_addr,
841 rxd->read.hdr_addr,
842 rxd->read.rsvd1, rxd->read.rsvd2);
843 }
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000844 }
845 } else if (cnt == 3) {
Joe Perchese6c97232014-11-18 05:53:00 +0000846 if (desc_n >= ring->count || desc_n < 0) {
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000847 dev_info(&pf->pdev->dev,
848 "descriptor %d not found\n", desc_n);
Joe Perchese3fe44c2014-12-08 04:28:39 +0000849 goto out;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000850 }
Shannon Nelson68bf94a2014-01-15 15:18:23 -0800851 if (!is_rx_ring) {
Joe Perchese6c97232014-11-18 05:53:00 +0000852 txd = I40E_TX_DESC(ring, desc_n);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000853 dev_info(&pf->pdev->dev,
Shannon Nelson68bf94a2014-01-15 15:18:23 -0800854 "vsi = %02i tx ring = %02i d[%03i] = 0x%016llx 0x%016llx\n",
855 vsi_seid, ring_id, desc_n,
856 txd->buffer_addr, txd->cmd_type_offset_bsz);
857 } else if (sizeof(union i40e_rx_desc) ==
858 sizeof(union i40e_16byte_rx_desc)) {
Joe Perchese6c97232014-11-18 05:53:00 +0000859 rxd = I40E_RX_DESC(ring, desc_n);
Shannon Nelson68bf94a2014-01-15 15:18:23 -0800860 dev_info(&pf->pdev->dev,
861 "vsi = %02i rx ring = %02i d[%03i] = 0x%016llx 0x%016llx\n",
862 vsi_seid, ring_id, desc_n,
863 rxd->read.pkt_addr, rxd->read.hdr_addr);
864 } else {
Joe Perchese6c97232014-11-18 05:53:00 +0000865 rxd = I40E_RX_DESC(ring, desc_n);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000866 dev_info(&pf->pdev->dev,
867 "vsi = %02i rx ring = %02i d[%03i] = 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",
Shannon Nelson68bf94a2014-01-15 15:18:23 -0800868 vsi_seid, ring_id, desc_n,
869 rxd->read.pkt_addr, rxd->read.hdr_addr,
870 rxd->read.rsvd1, rxd->read.rsvd2);
871 }
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000872 } else {
Shannon Nelson7792fe42013-11-26 10:49:29 +0000873 dev_info(&pf->pdev->dev, "dump desc rx/tx <vsi_seid> <ring_id> [<desc_n>]\n");
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000874 }
Joe Perchese3fe44c2014-12-08 04:28:39 +0000875
876out:
Joe Perchese6c97232014-11-18 05:53:00 +0000877 kfree(ring);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000878}
879
880/**
881 * i40e_dbg_dump_vsi_no_seid - handles dump vsi write into command datum
882 * @pf: the i40e_pf created in command write
883 **/
884static void i40e_dbg_dump_vsi_no_seid(struct i40e_pf *pf)
885{
886 int i;
887
Mitch Williams505682c2014-05-20 08:01:37 +0000888 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000889 if (pf->vsi[i])
890 dev_info(&pf->pdev->dev, "dump vsi[%d]: %d\n",
891 i, pf->vsi[i]->seid);
892}
893
894/**
895 * i40e_dbg_dump_stats - handles dump stats write into command datum
896 * @pf: the i40e_pf created in command write
897 * @estats: the eth stats structure to be dumped
898 **/
899static void i40e_dbg_dump_eth_stats(struct i40e_pf *pf,
900 struct i40e_eth_stats *estats)
901{
902 dev_info(&pf->pdev->dev, " ethstats:\n");
903 dev_info(&pf->pdev->dev,
904 " rx_bytes = \t%lld \trx_unicast = \t\t%lld \trx_multicast = \t%lld\n",
905 estats->rx_bytes, estats->rx_unicast, estats->rx_multicast);
906 dev_info(&pf->pdev->dev,
Shannon Nelson03da6f62014-04-23 04:50:19 +0000907 " rx_broadcast = \t%lld \trx_discards = \t\t%lld\n",
908 estats->rx_broadcast, estats->rx_discards);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000909 dev_info(&pf->pdev->dev,
Shannon Nelson03da6f62014-04-23 04:50:19 +0000910 " rx_unknown_protocol = \t%lld \ttx_bytes = \t%lld\n",
911 estats->rx_unknown_protocol, estats->tx_bytes);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000912 dev_info(&pf->pdev->dev,
913 " tx_unicast = \t%lld \ttx_multicast = \t\t%lld \ttx_broadcast = \t%lld\n",
914 estats->tx_unicast, estats->tx_multicast, estats->tx_broadcast);
915 dev_info(&pf->pdev->dev,
916 " tx_discards = \t%lld \ttx_errors = \t\t%lld\n",
917 estats->tx_discards, estats->tx_errors);
918}
919
920/**
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000921 * i40e_dbg_dump_veb_seid - handles dump stats of a single given veb
922 * @pf: the i40e_pf created in command write
923 * @seid: the seid the user put in
924 **/
925static void i40e_dbg_dump_veb_seid(struct i40e_pf *pf, int seid)
926{
927 struct i40e_veb *veb;
928
929 if ((seid < I40E_BASE_VEB_SEID) ||
930 (seid >= (I40E_MAX_VEB + I40E_BASE_VEB_SEID))) {
931 dev_info(&pf->pdev->dev, "%d: bad seid\n", seid);
932 return;
933 }
934
935 veb = i40e_dbg_find_veb(pf, seid);
936 if (!veb) {
Shannon Nelsone625f712013-11-26 10:49:31 +0000937 dev_info(&pf->pdev->dev, "can't find veb %d\n", seid);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000938 return;
939 }
940 dev_info(&pf->pdev->dev,
Neerav Parikh51616012015-02-06 08:52:14 +0000941 "veb idx=%d,%d stats_ic=%d seid=%d uplink=%d mode=%s\n",
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000942 veb->idx, veb->veb_idx, veb->stats_idx, veb->seid,
Neerav Parikh51616012015-02-06 08:52:14 +0000943 veb->uplink_seid,
944 veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000945 i40e_dbg_dump_eth_stats(pf, &veb->stats);
946}
947
948/**
949 * i40e_dbg_dump_veb_all - dumps all known veb's stats
950 * @pf: the i40e_pf created in command write
951 **/
952static void i40e_dbg_dump_veb_all(struct i40e_pf *pf)
953{
954 struct i40e_veb *veb;
955 int i;
956
957 for (i = 0; i < I40E_MAX_VEB; i++) {
958 veb = pf->veb[i];
959 if (veb)
960 i40e_dbg_dump_veb_seid(pf, veb->seid);
961 }
962}
963
964#define I40E_MAX_DEBUG_OUT_BUFFER (4096*4)
965/**
966 * i40e_dbg_command_write - write into command datum
967 * @filp: the opened file
968 * @buffer: where to find the user's data
969 * @count: the length of the user's data
970 * @ppos: file position offset
971 **/
972static ssize_t i40e_dbg_command_write(struct file *filp,
973 const char __user *buffer,
974 size_t count, loff_t *ppos)
975{
976 struct i40e_pf *pf = filp->private_data;
Jesse Brandeburg004173c2013-09-28 07:13:44 +0000977 char *cmd_buf, *cmd_buf_tmp;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000978 int bytes_not_copied;
979 struct i40e_vsi *vsi;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000980 int vsi_seid;
981 int veb_seid;
982 int cnt;
983
984 /* don't allow partial writes */
985 if (*ppos != 0)
986 return 0;
987
988 cmd_buf = kzalloc(count + 1, GFP_KERNEL);
989 if (!cmd_buf)
990 return count;
991 bytes_not_copied = copy_from_user(cmd_buf, buffer, count);
Rasmus Villemoes0286c672015-10-17 22:58:19 +0200992 if (bytes_not_copied) {
Alexey Khoroshilovdda094a2015-02-21 07:32:47 +0000993 kfree(cmd_buf);
Rasmus Villemoes0286c672015-10-17 22:58:19 +0200994 return -EFAULT;
Alexey Khoroshilovdda094a2015-02-21 07:32:47 +0000995 }
Jesse Brandeburg02e9c292013-09-11 08:40:17 +0000996 cmd_buf[count] = '\0';
997
Jesse Brandeburg004173c2013-09-28 07:13:44 +0000998 cmd_buf_tmp = strchr(cmd_buf, '\n');
999 if (cmd_buf_tmp) {
1000 *cmd_buf_tmp = '\0';
1001 count = cmd_buf_tmp - cmd_buf + 1;
1002 }
1003
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001004 if (strncmp(cmd_buf, "add vsi", 7) == 0) {
1005 vsi_seid = -1;
1006 cnt = sscanf(&cmd_buf[7], "%i", &vsi_seid);
1007 if (cnt == 0) {
1008 /* default to PF VSI */
1009 vsi_seid = pf->vsi[pf->lan_vsi]->seid;
1010 } else if (vsi_seid < 0) {
1011 dev_info(&pf->pdev->dev, "add VSI %d: bad vsi seid\n",
1012 vsi_seid);
1013 goto command_write_done;
1014 }
1015
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07001016 /* By default we are in VEPA mode, if this is the first VF/VMDq
1017 * VSI to be added switch to VEB mode.
1018 */
1019 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
1020 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
1021 i40e_do_reset_safe(pf,
1022 BIT_ULL(__I40E_PF_RESET_REQUESTED));
1023 }
1024
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001025 vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, vsi_seid, 0);
1026 if (vsi)
1027 dev_info(&pf->pdev->dev, "added VSI %d to relay %d\n",
1028 vsi->seid, vsi->uplink_seid);
1029 else
1030 dev_info(&pf->pdev->dev, "'%s' failed\n", cmd_buf);
1031
1032 } else if (strncmp(cmd_buf, "del vsi", 7) == 0) {
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001033 cnt = sscanf(&cmd_buf[7], "%i", &vsi_seid);
1034 if (cnt != 1) {
1035 dev_info(&pf->pdev->dev,
1036 "del vsi: bad command string, cnt=%d\n",
1037 cnt);
1038 goto command_write_done;
1039 }
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001040 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1041 if (!vsi) {
1042 dev_info(&pf->pdev->dev, "del VSI %d: seid not found\n",
1043 vsi_seid);
1044 goto command_write_done;
1045 }
1046
1047 dev_info(&pf->pdev->dev, "deleting VSI %d\n", vsi_seid);
1048 i40e_vsi_release(vsi);
1049
1050 } else if (strncmp(cmd_buf, "add relay", 9) == 0) {
1051 struct i40e_veb *veb;
1052 int uplink_seid, i;
1053
1054 cnt = sscanf(&cmd_buf[9], "%i %i", &uplink_seid, &vsi_seid);
1055 if (cnt != 2) {
1056 dev_info(&pf->pdev->dev,
1057 "add relay: bad command string, cnt=%d\n",
1058 cnt);
1059 goto command_write_done;
1060 } else if (uplink_seid < 0) {
1061 dev_info(&pf->pdev->dev,
1062 "add relay %d: bad uplink seid\n",
1063 uplink_seid);
1064 goto command_write_done;
1065 }
1066
1067 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1068 if (!vsi) {
1069 dev_info(&pf->pdev->dev,
Shannon Nelsonc07019e2013-12-21 05:44:51 +00001070 "add relay: VSI %d not found\n", vsi_seid);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001071 goto command_write_done;
1072 }
1073
1074 for (i = 0; i < I40E_MAX_VEB; i++)
1075 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid)
1076 break;
1077 if (i >= I40E_MAX_VEB && uplink_seid != 0 &&
1078 uplink_seid != pf->mac_seid) {
1079 dev_info(&pf->pdev->dev,
1080 "add relay: relay uplink %d not found\n",
1081 uplink_seid);
1082 goto command_write_done;
1083 }
1084
1085 veb = i40e_veb_setup(pf, 0, uplink_seid, vsi_seid,
1086 vsi->tc_config.enabled_tc);
1087 if (veb)
1088 dev_info(&pf->pdev->dev, "added relay %d\n", veb->seid);
1089 else
1090 dev_info(&pf->pdev->dev, "add relay failed\n");
1091
1092 } else if (strncmp(cmd_buf, "del relay", 9) == 0) {
1093 int i;
1094 cnt = sscanf(&cmd_buf[9], "%i", &veb_seid);
1095 if (cnt != 1) {
1096 dev_info(&pf->pdev->dev,
1097 "del relay: bad command string, cnt=%d\n",
1098 cnt);
1099 goto command_write_done;
1100 } else if (veb_seid < 0) {
1101 dev_info(&pf->pdev->dev,
1102 "del relay %d: bad relay seid\n", veb_seid);
1103 goto command_write_done;
1104 }
1105
1106 /* find the veb */
1107 for (i = 0; i < I40E_MAX_VEB; i++)
1108 if (pf->veb[i] && pf->veb[i]->seid == veb_seid)
1109 break;
1110 if (i >= I40E_MAX_VEB) {
1111 dev_info(&pf->pdev->dev,
1112 "del relay: relay %d not found\n", veb_seid);
1113 goto command_write_done;
1114 }
1115
1116 dev_info(&pf->pdev->dev, "deleting relay %d\n", veb_seid);
1117 i40e_veb_release(pf->veb[i]);
1118
1119 } else if (strncmp(cmd_buf, "add macaddr", 11) == 0) {
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001120 struct i40e_mac_filter *f;
Shannon Nelson738a9e92013-09-28 07:14:04 +00001121 int vlan = 0;
1122 u8 ma[6];
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001123 int ret;
1124
1125 cnt = sscanf(&cmd_buf[11],
1126 "%i %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %i",
1127 &vsi_seid,
1128 &ma[0], &ma[1], &ma[2], &ma[3], &ma[4], &ma[5],
1129 &vlan);
1130 if (cnt == 7) {
1131 vlan = 0;
1132 } else if (cnt != 8) {
1133 dev_info(&pf->pdev->dev,
1134 "add macaddr: bad command string, cnt=%d\n",
1135 cnt);
1136 goto command_write_done;
1137 }
1138
1139 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1140 if (!vsi) {
1141 dev_info(&pf->pdev->dev,
1142 "add macaddr: VSI %d not found\n", vsi_seid);
1143 goto command_write_done;
1144 }
1145
Anjali Singhai Jain10dc0352015-10-01 14:37:35 -04001146 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001147 f = i40e_add_filter(vsi, ma, vlan, false, false);
Anjali Singhai Jain10dc0352015-10-01 14:37:35 -04001148 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg17652c62015-11-05 17:01:02 -08001149 ret = i40e_sync_vsi_filters(vsi);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001150 if (f && !ret)
1151 dev_info(&pf->pdev->dev,
1152 "add macaddr: %pM vlan=%d added to VSI %d\n",
1153 ma, vlan, vsi_seid);
1154 else
1155 dev_info(&pf->pdev->dev,
1156 "add macaddr: %pM vlan=%d to VSI %d failed, f=%p ret=%d\n",
1157 ma, vlan, vsi_seid, f, ret);
1158
1159 } else if (strncmp(cmd_buf, "del macaddr", 11) == 0) {
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001160 int vlan = 0;
Shannon Nelson738a9e92013-09-28 07:14:04 +00001161 u8 ma[6];
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001162 int ret;
1163
1164 cnt = sscanf(&cmd_buf[11],
1165 "%i %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %i",
1166 &vsi_seid,
1167 &ma[0], &ma[1], &ma[2], &ma[3], &ma[4], &ma[5],
1168 &vlan);
1169 if (cnt == 7) {
1170 vlan = 0;
1171 } else if (cnt != 8) {
1172 dev_info(&pf->pdev->dev,
1173 "del macaddr: bad command string, cnt=%d\n",
1174 cnt);
1175 goto command_write_done;
1176 }
1177
1178 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1179 if (!vsi) {
1180 dev_info(&pf->pdev->dev,
1181 "del macaddr: VSI %d not found\n", vsi_seid);
1182 goto command_write_done;
1183 }
1184
Anjali Singhai Jain10dc0352015-10-01 14:37:35 -04001185 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001186 i40e_del_filter(vsi, ma, vlan, false, false);
Anjali Singhai Jain10dc0352015-10-01 14:37:35 -04001187 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg17652c62015-11-05 17:01:02 -08001188 ret = i40e_sync_vsi_filters(vsi);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001189 if (!ret)
1190 dev_info(&pf->pdev->dev,
1191 "del macaddr: %pM vlan=%d removed from VSI %d\n",
1192 ma, vlan, vsi_seid);
1193 else
1194 dev_info(&pf->pdev->dev,
1195 "del macaddr: %pM vlan=%d from VSI %d failed, ret=%d\n",
1196 ma, vlan, vsi_seid, ret);
1197
1198 } else if (strncmp(cmd_buf, "add pvid", 8) == 0) {
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001199 i40e_status ret;
Shannon Nelson738a9e92013-09-28 07:14:04 +00001200 u16 vid;
Toralf Försterefe1ac22014-05-20 08:23:00 +00001201 unsigned int v;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001202
1203 cnt = sscanf(&cmd_buf[8], "%i %u", &vsi_seid, &v);
1204 if (cnt != 2) {
1205 dev_info(&pf->pdev->dev,
1206 "add pvid: bad command string, cnt=%d\n", cnt);
1207 goto command_write_done;
1208 }
1209
1210 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1211 if (!vsi) {
1212 dev_info(&pf->pdev->dev, "add pvid: VSI %d not found\n",
1213 vsi_seid);
1214 goto command_write_done;
1215 }
1216
Toralf Försterefe1ac22014-05-20 08:23:00 +00001217 vid = v;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001218 ret = i40e_vsi_add_pvid(vsi, vid);
1219 if (!ret)
1220 dev_info(&pf->pdev->dev,
1221 "add pvid: %d added to VSI %d\n",
1222 vid, vsi_seid);
1223 else
1224 dev_info(&pf->pdev->dev,
1225 "add pvid: %d to VSI %d failed, ret=%d\n",
1226 vid, vsi_seid, ret);
1227
1228 } else if (strncmp(cmd_buf, "del pvid", 8) == 0) {
1229
1230 cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
1231 if (cnt != 1) {
1232 dev_info(&pf->pdev->dev,
1233 "del pvid: bad command string, cnt=%d\n",
1234 cnt);
1235 goto command_write_done;
1236 }
1237
1238 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1239 if (!vsi) {
1240 dev_info(&pf->pdev->dev,
1241 "del pvid: VSI %d not found\n", vsi_seid);
1242 goto command_write_done;
1243 }
1244
1245 i40e_vsi_remove_pvid(vsi);
1246 dev_info(&pf->pdev->dev,
1247 "del pvid: removed from VSI %d\n", vsi_seid);
1248
1249 } else if (strncmp(cmd_buf, "dump", 4) == 0) {
1250 if (strncmp(&cmd_buf[5], "switch", 6) == 0) {
1251 i40e_fetch_switch_configuration(pf, true);
1252 } else if (strncmp(&cmd_buf[5], "vsi", 3) == 0) {
1253 cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
1254 if (cnt > 0)
1255 i40e_dbg_dump_vsi_seid(pf, vsi_seid);
1256 else
1257 i40e_dbg_dump_vsi_no_seid(pf);
1258 } else if (strncmp(&cmd_buf[5], "veb", 3) == 0) {
1259 cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
1260 if (cnt > 0)
1261 i40e_dbg_dump_veb_seid(pf, vsi_seid);
1262 else
1263 i40e_dbg_dump_veb_all(pf);
1264 } else if (strncmp(&cmd_buf[5], "desc", 4) == 0) {
1265 int ring_id, desc_n;
1266 if (strncmp(&cmd_buf[10], "rx", 2) == 0) {
1267 cnt = sscanf(&cmd_buf[12], "%i %i %i",
1268 &vsi_seid, &ring_id, &desc_n);
1269 i40e_dbg_dump_desc(cnt, vsi_seid, ring_id,
1270 desc_n, pf, true);
1271 } else if (strncmp(&cmd_buf[10], "tx", 2)
1272 == 0) {
1273 cnt = sscanf(&cmd_buf[12], "%i %i %i",
1274 &vsi_seid, &ring_id, &desc_n);
1275 i40e_dbg_dump_desc(cnt, vsi_seid, ring_id,
1276 desc_n, pf, false);
1277 } else if (strncmp(&cmd_buf[10], "aq", 2) == 0) {
1278 i40e_dbg_dump_aq_desc(pf);
1279 } else {
1280 dev_info(&pf->pdev->dev,
1281 "dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n");
1282 dev_info(&pf->pdev->dev,
1283 "dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n");
1284 dev_info(&pf->pdev->dev, "dump desc aq\n");
1285 }
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001286 } else if (strncmp(&cmd_buf[5], "reset stats", 11) == 0) {
1287 dev_info(&pf->pdev->dev,
1288 "core reset count: %d\n", pf->corer_count);
1289 dev_info(&pf->pdev->dev,
1290 "global reset count: %d\n", pf->globr_count);
1291 dev_info(&pf->pdev->dev,
1292 "emp reset count: %d\n", pf->empr_count);
1293 dev_info(&pf->pdev->dev,
1294 "pf reset count: %d\n", pf->pfr_count);
Anjali Singhai Jain810b3ae2014-07-10 07:58:25 +00001295 dev_info(&pf->pdev->dev,
1296 "pf tx sluggish count: %d\n",
1297 pf->tx_sluggish_count);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001298 } else if (strncmp(&cmd_buf[5], "port", 4) == 0) {
1299 struct i40e_aqc_query_port_ets_config_resp *bw_data;
1300 struct i40e_dcbx_config *cfg =
1301 &pf->hw.local_dcbx_config;
1302 struct i40e_dcbx_config *r_cfg =
1303 &pf->hw.remote_dcbx_config;
1304 int i, ret;
1305
1306 bw_data = kzalloc(sizeof(
1307 struct i40e_aqc_query_port_ets_config_resp),
1308 GFP_KERNEL);
1309 if (!bw_data) {
1310 ret = -ENOMEM;
1311 goto command_write_done;
1312 }
1313
1314 ret = i40e_aq_query_port_ets_config(&pf->hw,
1315 pf->mac_seid,
1316 bw_data, NULL);
1317 if (ret) {
1318 dev_info(&pf->pdev->dev,
1319 "Query Port ETS Config AQ command failed =0x%x\n",
1320 pf->hw.aq.asq_last_status);
1321 kfree(bw_data);
1322 bw_data = NULL;
1323 goto command_write_done;
1324 }
1325 dev_info(&pf->pdev->dev,
1326 "port bw: tc_valid=0x%x tc_strict_prio=0x%x, tc_bw_max=0x%04x,0x%04x\n",
1327 bw_data->tc_valid_bits,
1328 bw_data->tc_strict_priority_bits,
1329 le16_to_cpu(bw_data->tc_bw_max[0]),
1330 le16_to_cpu(bw_data->tc_bw_max[1]));
1331 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1332 dev_info(&pf->pdev->dev, "port bw: tc_bw_share=%d tc_bw_limit=%d\n",
1333 bw_data->tc_bw_share_credits[i],
1334 le16_to_cpu(bw_data->tc_bw_limits[i]));
1335 }
1336
1337 kfree(bw_data);
1338 bw_data = NULL;
1339
1340 dev_info(&pf->pdev->dev,
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00001341 "port dcbx_mode=%d\n", cfg->dcbx_mode);
1342 dev_info(&pf->pdev->dev,
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001343 "port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n",
1344 cfg->etscfg.willing, cfg->etscfg.cbs,
1345 cfg->etscfg.maxtcs);
1346 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1347 dev_info(&pf->pdev->dev, "port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n",
1348 i, cfg->etscfg.prioritytable[i],
1349 cfg->etscfg.tcbwtable[i],
1350 cfg->etscfg.tsatable[i]);
1351 }
1352 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1353 dev_info(&pf->pdev->dev, "port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n",
1354 i, cfg->etsrec.prioritytable[i],
1355 cfg->etsrec.tcbwtable[i],
1356 cfg->etsrec.tsatable[i]);
1357 }
1358 dev_info(&pf->pdev->dev,
1359 "port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n",
1360 cfg->pfc.willing, cfg->pfc.mbc,
1361 cfg->pfc.pfccap, cfg->pfc.pfcenable);
1362 dev_info(&pf->pdev->dev,
1363 "port app_table: num_apps=%d\n", cfg->numapps);
1364 for (i = 0; i < cfg->numapps; i++) {
1365 dev_info(&pf->pdev->dev, "port app_table: %d prio=%d selector=%d protocol=0x%x\n",
1366 i, cfg->app[i].priority,
1367 cfg->app[i].selector,
1368 cfg->app[i].protocolid);
1369 }
1370 /* Peer TLV DCBX data */
1371 dev_info(&pf->pdev->dev,
1372 "remote port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n",
1373 r_cfg->etscfg.willing,
1374 r_cfg->etscfg.cbs, r_cfg->etscfg.maxtcs);
1375 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1376 dev_info(&pf->pdev->dev, "remote port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n",
1377 i, r_cfg->etscfg.prioritytable[i],
1378 r_cfg->etscfg.tcbwtable[i],
1379 r_cfg->etscfg.tsatable[i]);
1380 }
1381 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1382 dev_info(&pf->pdev->dev, "remote port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n",
1383 i, r_cfg->etsrec.prioritytable[i],
1384 r_cfg->etsrec.tcbwtable[i],
1385 r_cfg->etsrec.tsatable[i]);
1386 }
1387 dev_info(&pf->pdev->dev,
1388 "remote port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n",
1389 r_cfg->pfc.willing,
1390 r_cfg->pfc.mbc,
1391 r_cfg->pfc.pfccap,
1392 r_cfg->pfc.pfcenable);
1393 dev_info(&pf->pdev->dev,
1394 "remote port app_table: num_apps=%d\n",
1395 r_cfg->numapps);
1396 for (i = 0; i < r_cfg->numapps; i++) {
1397 dev_info(&pf->pdev->dev, "remote port app_table: %d prio=%d selector=%d protocol=0x%x\n",
1398 i, r_cfg->app[i].priority,
1399 r_cfg->app[i].selector,
1400 r_cfg->app[i].protocolid);
1401 }
Jesse Brandeburg3169c322015-04-07 19:45:37 -04001402 } else if (strncmp(&cmd_buf[5], "debug fwdata", 12) == 0) {
1403 int cluster_id, table_id;
1404 int index, ret;
1405 u16 buff_len = 4096;
1406 u32 next_index;
1407 u8 next_table;
1408 u8 *buff;
1409 u16 rlen;
1410
1411 cnt = sscanf(&cmd_buf[18], "%i %i %i",
1412 &cluster_id, &table_id, &index);
1413 if (cnt != 3) {
1414 dev_info(&pf->pdev->dev,
1415 "dump debug fwdata <cluster_id> <table_id> <index>\n");
1416 goto command_write_done;
1417 }
1418
1419 dev_info(&pf->pdev->dev,
1420 "AQ debug dump fwdata params %x %x %x %x\n",
1421 cluster_id, table_id, index, buff_len);
1422 buff = kzalloc(buff_len, GFP_KERNEL);
1423 if (!buff)
1424 goto command_write_done;
1425
1426 ret = i40e_aq_debug_dump(&pf->hw, cluster_id, table_id,
1427 index, buff_len, buff, &rlen,
1428 &next_table, &next_index,
1429 NULL);
1430 if (ret) {
1431 dev_info(&pf->pdev->dev,
1432 "debug dump fwdata AQ Failed %d 0x%x\n",
1433 ret, pf->hw.aq.asq_last_status);
1434 kfree(buff);
1435 buff = NULL;
1436 goto command_write_done;
1437 }
1438 dev_info(&pf->pdev->dev,
1439 "AQ debug dump fwdata rlen=0x%x next_table=0x%x next_index=0x%x\n",
1440 rlen, next_table, next_index);
1441 print_hex_dump(KERN_INFO, "AQ buffer WB: ",
1442 DUMP_PREFIX_OFFSET, 16, 1,
1443 buff, rlen, true);
1444 kfree(buff);
1445 buff = NULL;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001446 } else {
1447 dev_info(&pf->pdev->dev,
1448 "dump desc tx <vsi_seid> <ring_id> [<desc_n>], dump desc rx <vsi_seid> <ring_id> [<desc_n>],\n");
Shannon Nelson7204a782014-10-17 03:14:47 +00001449 dev_info(&pf->pdev->dev, "dump switch\n");
1450 dev_info(&pf->pdev->dev, "dump vsi [seid]\n");
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001451 dev_info(&pf->pdev->dev, "dump reset stats\n");
1452 dev_info(&pf->pdev->dev, "dump port\n");
1453 dev_info(&pf->pdev->dev,
1454 "dump debug fwdata <cluster_id> <table_id> <index>\n");
1455 }
1456
1457 } else if (strncmp(cmd_buf, "msg_enable", 10) == 0) {
1458 u32 level;
1459 cnt = sscanf(&cmd_buf[10], "%i", &level);
1460 if (cnt) {
1461 if (I40E_DEBUG_USER & level) {
1462 pf->hw.debug_mask = level;
1463 dev_info(&pf->pdev->dev,
1464 "set hw.debug_mask = 0x%08x\n",
1465 pf->hw.debug_mask);
1466 }
1467 pf->msg_enable = level;
1468 dev_info(&pf->pdev->dev, "set msg_enable = 0x%08x\n",
1469 pf->msg_enable);
1470 } else {
1471 dev_info(&pf->pdev->dev, "msg_enable = 0x%08x\n",
1472 pf->msg_enable);
1473 }
1474 } else if (strncmp(cmd_buf, "pfr", 3) == 0) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00001475 dev_info(&pf->pdev->dev, "debugfs: forcing PFR\n");
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001476 i40e_do_reset_safe(pf, BIT(__I40E_PF_RESET_REQUESTED));
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001477
1478 } else if (strncmp(cmd_buf, "corer", 5) == 0) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00001479 dev_info(&pf->pdev->dev, "debugfs: forcing CoreR\n");
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001480 i40e_do_reset_safe(pf, BIT(__I40E_CORE_RESET_REQUESTED));
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001481
1482 } else if (strncmp(cmd_buf, "globr", 5) == 0) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00001483 dev_info(&pf->pdev->dev, "debugfs: forcing GlobR\n");
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001484 i40e_do_reset_safe(pf, BIT(__I40E_GLOBAL_RESET_REQUESTED));
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001485
Shannon Nelson7823fe32013-11-16 10:00:45 +00001486 } else if (strncmp(cmd_buf, "empr", 4) == 0) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00001487 dev_info(&pf->pdev->dev, "debugfs: forcing EMPR\n");
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001488 i40e_do_reset_safe(pf, BIT(__I40E_EMP_RESET_REQUESTED));
Shannon Nelson7823fe32013-11-16 10:00:45 +00001489
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001490 } else if (strncmp(cmd_buf, "read", 4) == 0) {
1491 u32 address;
1492 u32 value;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001493
Shannon Nelson2706a202013-11-26 10:49:30 +00001494 cnt = sscanf(&cmd_buf[4], "%i", &address);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001495 if (cnt != 1) {
1496 dev_info(&pf->pdev->dev, "read <reg>\n");
1497 goto command_write_done;
1498 }
1499
1500 /* check the range on address */
Shannon Nelson2ac8b672015-07-23 16:54:37 -04001501 if (address > (pf->ioremap_len - sizeof(u32))) {
1502 dev_info(&pf->pdev->dev, "read reg address 0x%08x too large, max=0x%08lx\n",
Jesse Brandeburge88ae662015-08-13 18:54:26 -07001503 address, (unsigned long int)(pf->ioremap_len - sizeof(u32)));
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001504 goto command_write_done;
1505 }
1506
1507 value = rd32(&pf->hw, address);
1508 dev_info(&pf->pdev->dev, "read: 0x%08x = 0x%08x\n",
1509 address, value);
1510
1511 } else if (strncmp(cmd_buf, "write", 5) == 0) {
1512 u32 address, value;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001513
Shannon Nelson2706a202013-11-26 10:49:30 +00001514 cnt = sscanf(&cmd_buf[5], "%i %i", &address, &value);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001515 if (cnt != 2) {
1516 dev_info(&pf->pdev->dev, "write <reg> <value>\n");
1517 goto command_write_done;
1518 }
1519
1520 /* check the range on address */
Shannon Nelson2ac8b672015-07-23 16:54:37 -04001521 if (address > (pf->ioremap_len - sizeof(u32))) {
1522 dev_info(&pf->pdev->dev, "write reg address 0x%08x too large, max=0x%08lx\n",
Jesse Brandeburge88ae662015-08-13 18:54:26 -07001523 address, (unsigned long int)(pf->ioremap_len - sizeof(u32)));
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001524 goto command_write_done;
1525 }
1526 wr32(&pf->hw, address, value);
1527 value = rd32(&pf->hw, address);
1528 dev_info(&pf->pdev->dev, "write: 0x%08x = 0x%08x\n",
1529 address, value);
1530 } else if (strncmp(cmd_buf, "clear_stats", 11) == 0) {
1531 if (strncmp(&cmd_buf[12], "vsi", 3) == 0) {
Shannon Nelson2706a202013-11-26 10:49:30 +00001532 cnt = sscanf(&cmd_buf[15], "%i", &vsi_seid);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001533 if (cnt == 0) {
1534 int i;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001535
Mitch Williams505682c2014-05-20 08:01:37 +00001536 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001537 i40e_vsi_reset_stats(pf->vsi[i]);
1538 dev_info(&pf->pdev->dev, "vsi clear stats called for all vsi's\n");
1539 } else if (cnt == 1) {
1540 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1541 if (!vsi) {
1542 dev_info(&pf->pdev->dev,
1543 "clear_stats vsi: bad vsi %d\n",
1544 vsi_seid);
1545 goto command_write_done;
1546 }
1547 i40e_vsi_reset_stats(vsi);
1548 dev_info(&pf->pdev->dev,
1549 "vsi clear stats called for vsi %d\n",
1550 vsi_seid);
1551 } else {
1552 dev_info(&pf->pdev->dev, "clear_stats vsi [seid]\n");
1553 }
Shannon Nelson694dc1c2015-01-24 09:58:34 +00001554 } else if (strncmp(&cmd_buf[12], "port", 4) == 0) {
1555 if (pf->hw.partition_id == 1) {
1556 i40e_pf_reset_stats(pf);
1557 dev_info(&pf->pdev->dev, "port stats cleared\n");
1558 } else {
1559 dev_info(&pf->pdev->dev, "clear port stats not allowed on this port partition\n");
1560 }
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001561 } else {
Shannon Nelson694dc1c2015-01-24 09:58:34 +00001562 dev_info(&pf->pdev->dev, "clear_stats vsi [seid] or clear_stats port\n");
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001563 }
Anjali Singhai Jainf1143c42013-11-28 06:42:38 +00001564 } else if (strncmp(cmd_buf, "send aq_cmd", 11) == 0) {
1565 struct i40e_aq_desc *desc;
1566 i40e_status ret;
1567
1568 desc = kzalloc(sizeof(struct i40e_aq_desc), GFP_KERNEL);
1569 if (!desc)
1570 goto command_write_done;
1571 cnt = sscanf(&cmd_buf[11],
Shannon Nelsonfbe82102014-11-11 20:05:13 +00001572 "%hi %hi %hi %hi %i %i %i %i %i %i",
Anjali Singhai Jainf1143c42013-11-28 06:42:38 +00001573 &desc->flags,
1574 &desc->opcode, &desc->datalen, &desc->retval,
1575 &desc->cookie_high, &desc->cookie_low,
1576 &desc->params.internal.param0,
1577 &desc->params.internal.param1,
1578 &desc->params.internal.param2,
1579 &desc->params.internal.param3);
1580 if (cnt != 10) {
1581 dev_info(&pf->pdev->dev,
1582 "send aq_cmd: bad command string, cnt=%d\n",
1583 cnt);
1584 kfree(desc);
1585 desc = NULL;
1586 goto command_write_done;
1587 }
1588 ret = i40e_asq_send_command(&pf->hw, desc, NULL, 0, NULL);
1589 if (!ret) {
1590 dev_info(&pf->pdev->dev, "AQ command sent Status : Success\n");
1591 } else if (ret == I40E_ERR_ADMIN_QUEUE_ERROR) {
1592 dev_info(&pf->pdev->dev,
1593 "AQ command send failed Opcode %x AQ Error: %d\n",
1594 desc->opcode, pf->hw.aq.asq_last_status);
1595 } else {
1596 dev_info(&pf->pdev->dev,
1597 "AQ command send failed Opcode %x Status: %d\n",
1598 desc->opcode, ret);
1599 }
1600 dev_info(&pf->pdev->dev,
1601 "AQ desc WB 0x%04x 0x%04x 0x%04x 0x%04x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
1602 desc->flags, desc->opcode, desc->datalen, desc->retval,
1603 desc->cookie_high, desc->cookie_low,
1604 desc->params.internal.param0,
1605 desc->params.internal.param1,
1606 desc->params.internal.param2,
1607 desc->params.internal.param3);
1608 kfree(desc);
1609 desc = NULL;
1610 } else if (strncmp(cmd_buf, "send indirect aq_cmd", 20) == 0) {
1611 struct i40e_aq_desc *desc;
1612 i40e_status ret;
1613 u16 buffer_len;
1614 u8 *buff;
1615
1616 desc = kzalloc(sizeof(struct i40e_aq_desc), GFP_KERNEL);
1617 if (!desc)
1618 goto command_write_done;
1619 cnt = sscanf(&cmd_buf[20],
Shannon Nelsonfbe82102014-11-11 20:05:13 +00001620 "%hi %hi %hi %hi %i %i %i %i %i %i %hi",
Anjali Singhai Jainf1143c42013-11-28 06:42:38 +00001621 &desc->flags,
1622 &desc->opcode, &desc->datalen, &desc->retval,
1623 &desc->cookie_high, &desc->cookie_low,
1624 &desc->params.internal.param0,
1625 &desc->params.internal.param1,
1626 &desc->params.internal.param2,
1627 &desc->params.internal.param3,
1628 &buffer_len);
1629 if (cnt != 11) {
1630 dev_info(&pf->pdev->dev,
1631 "send indirect aq_cmd: bad command string, cnt=%d\n",
1632 cnt);
1633 kfree(desc);
1634 desc = NULL;
1635 goto command_write_done;
1636 }
1637 /* Just stub a buffer big enough in case user messed up */
1638 if (buffer_len == 0)
1639 buffer_len = 1280;
1640
1641 buff = kzalloc(buffer_len, GFP_KERNEL);
1642 if (!buff) {
1643 kfree(desc);
1644 desc = NULL;
1645 goto command_write_done;
1646 }
1647 desc->flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
1648 ret = i40e_asq_send_command(&pf->hw, desc, buff,
1649 buffer_len, NULL);
1650 if (!ret) {
1651 dev_info(&pf->pdev->dev, "AQ command sent Status : Success\n");
1652 } else if (ret == I40E_ERR_ADMIN_QUEUE_ERROR) {
1653 dev_info(&pf->pdev->dev,
1654 "AQ command send failed Opcode %x AQ Error: %d\n",
1655 desc->opcode, pf->hw.aq.asq_last_status);
1656 } else {
1657 dev_info(&pf->pdev->dev,
1658 "AQ command send failed Opcode %x Status: %d\n",
1659 desc->opcode, ret);
1660 }
1661 dev_info(&pf->pdev->dev,
1662 "AQ desc WB 0x%04x 0x%04x 0x%04x 0x%04x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
1663 desc->flags, desc->opcode, desc->datalen, desc->retval,
1664 desc->cookie_high, desc->cookie_low,
1665 desc->params.internal.param0,
1666 desc->params.internal.param1,
1667 desc->params.internal.param2,
1668 desc->params.internal.param3);
1669 print_hex_dump(KERN_INFO, "AQ buffer WB: ",
1670 DUMP_PREFIX_OFFSET, 16, 1,
1671 buff, buffer_len, true);
1672 kfree(buff);
1673 buff = NULL;
1674 kfree(desc);
1675 desc = NULL;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001676 } else if ((strncmp(cmd_buf, "add fd_filter", 13) == 0) ||
1677 (strncmp(cmd_buf, "rem fd_filter", 13) == 0)) {
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001678 struct i40e_fdir_filter fd_data;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001679 u16 packet_len, i, j = 0;
1680 char *asc_packet;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001681 u8 *raw_packet;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001682 bool add = false;
Shannon Nelson738a9e92013-09-28 07:14:04 +00001683 int ret;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001684
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001685 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
1686 goto command_write_done;
1687
1688 if (strncmp(cmd_buf, "add", 3) == 0)
1689 add = true;
1690
1691 if (add && (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED))
1692 goto command_write_done;
1693
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001694 asc_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_SIZE,
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001695 GFP_KERNEL);
1696 if (!asc_packet)
1697 goto command_write_done;
1698
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001699 raw_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_SIZE,
1700 GFP_KERNEL);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001701
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001702 if (!raw_packet) {
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001703 kfree(asc_packet);
1704 asc_packet = NULL;
1705 goto command_write_done;
1706 }
1707
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001708 cnt = sscanf(&cmd_buf[13],
Alan Cox5561b6a2013-12-12 02:44:24 +00001709 "%hx %2hhx %2hhx %hx %2hhx %2hhx %hx %x %hd %511s",
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001710 &fd_data.q_index,
1711 &fd_data.flex_off, &fd_data.pctype,
1712 &fd_data.dest_vsi, &fd_data.dest_ctl,
1713 &fd_data.fd_status, &fd_data.cnt_index,
1714 &fd_data.fd_id, &packet_len, asc_packet);
1715 if (cnt != 10) {
1716 dev_info(&pf->pdev->dev,
1717 "program fd_filter: bad command string, cnt=%d\n",
1718 cnt);
1719 kfree(asc_packet);
1720 asc_packet = NULL;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001721 kfree(raw_packet);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001722 goto command_write_done;
1723 }
1724
1725 /* fix packet length if user entered 0 */
1726 if (packet_len == 0)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001727 packet_len = I40E_FDIR_MAX_RAW_PACKET_SIZE;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001728
1729 /* make sure to check the max as well */
1730 packet_len = min_t(u16,
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001731 packet_len, I40E_FDIR_MAX_RAW_PACKET_SIZE);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001732
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001733 for (i = 0; i < packet_len; i++) {
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001734 cnt = sscanf(&asc_packet[j], "%2hhx ", &raw_packet[i]);
1735 if (!cnt)
1736 break;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001737 j += 3;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001738 }
Neerav Parikh3753cb22013-11-26 10:49:25 +00001739 dev_info(&pf->pdev->dev, "FD raw packet dump\n");
1740 print_hex_dump(KERN_INFO, "FD raw packet: ",
1741 DUMP_PREFIX_OFFSET, 16, 1,
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001742 raw_packet, packet_len, true);
1743 ret = i40e_program_fdir_filter(&fd_data, raw_packet, pf, add);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001744 if (!ret) {
1745 dev_info(&pf->pdev->dev, "Filter command send Status : Success\n");
1746 } else {
1747 dev_info(&pf->pdev->dev,
1748 "Filter command send failed %d\n", ret);
1749 }
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001750 kfree(raw_packet);
1751 raw_packet = NULL;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001752 kfree(asc_packet);
1753 asc_packet = NULL;
Anjali Singhai Jaine17ff052014-06-04 04:22:48 +00001754 } else if (strncmp(cmd_buf, "fd current cnt", 14) == 0) {
1755 dev_info(&pf->pdev->dev, "FD current total filter count for this interface: %d\n",
1756 i40e_get_current_fd_count(pf));
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001757 } else if (strncmp(cmd_buf, "lldp", 4) == 0) {
1758 if (strncmp(&cmd_buf[5], "stop", 4) == 0) {
1759 int ret;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001760
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001761 ret = i40e_aq_stop_lldp(&pf->hw, false, NULL);
1762 if (ret) {
1763 dev_info(&pf->pdev->dev,
1764 "Stop LLDP AQ command failed =0x%x\n",
1765 pf->hw.aq.asq_last_status);
1766 goto command_write_done;
1767 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001768 ret = i40e_aq_add_rem_control_packet_filter(&pf->hw,
1769 pf->hw.mac.addr,
1770 I40E_ETH_P_LLDP, 0,
1771 pf->vsi[pf->lan_vsi]->seid,
1772 0, true, NULL, NULL);
1773 if (ret) {
1774 dev_info(&pf->pdev->dev,
1775 "%s: Add Control Packet Filter AQ command failed =0x%x\n",
1776 __func__, pf->hw.aq.asq_last_status);
1777 goto command_write_done;
1778 }
1779#ifdef CONFIG_I40E_DCB
1780 pf->dcbx_cap = DCB_CAP_DCBX_HOST |
1781 DCB_CAP_DCBX_VER_IEEE;
1782#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001783 } else if (strncmp(&cmd_buf[5], "start", 5) == 0) {
1784 int ret;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001785
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001786 ret = i40e_aq_add_rem_control_packet_filter(&pf->hw,
1787 pf->hw.mac.addr,
1788 I40E_ETH_P_LLDP, 0,
1789 pf->vsi[pf->lan_vsi]->seid,
1790 0, false, NULL, NULL);
1791 if (ret) {
1792 dev_info(&pf->pdev->dev,
1793 "%s: Remove Control Packet Filter AQ command failed =0x%x\n",
1794 __func__, pf->hw.aq.asq_last_status);
1795 /* Continue and start FW LLDP anyways */
1796 }
1797
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001798 ret = i40e_aq_start_lldp(&pf->hw, NULL);
1799 if (ret) {
1800 dev_info(&pf->pdev->dev,
1801 "Start LLDP AQ command failed =0x%x\n",
1802 pf->hw.aq.asq_last_status);
1803 goto command_write_done;
1804 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001805#ifdef CONFIG_I40E_DCB
1806 pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
1807 DCB_CAP_DCBX_VER_IEEE;
1808#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001809 } else if (strncmp(&cmd_buf[5],
1810 "get local", 9) == 0) {
Shannon Nelson738a9e92013-09-28 07:14:04 +00001811 u16 llen, rlen;
Neerav Parikh3753cb22013-11-26 10:49:25 +00001812 int ret;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001813 u8 *buff;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001814
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001815 buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL);
1816 if (!buff)
1817 goto command_write_done;
1818
1819 ret = i40e_aq_get_lldp_mib(&pf->hw, 0,
1820 I40E_AQ_LLDP_MIB_LOCAL,
1821 buff, I40E_LLDPDU_SIZE,
1822 &llen, &rlen, NULL);
1823 if (ret) {
1824 dev_info(&pf->pdev->dev,
1825 "Get LLDP MIB (local) AQ command failed =0x%x\n",
1826 pf->hw.aq.asq_last_status);
1827 kfree(buff);
1828 buff = NULL;
1829 goto command_write_done;
1830 }
Neerav Parikh3753cb22013-11-26 10:49:25 +00001831 dev_info(&pf->pdev->dev, "LLDP MIB (local)\n");
1832 print_hex_dump(KERN_INFO, "LLDP MIB (local): ",
1833 DUMP_PREFIX_OFFSET, 16, 1,
1834 buff, I40E_LLDPDU_SIZE, true);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001835 kfree(buff);
1836 buff = NULL;
1837 } else if (strncmp(&cmd_buf[5], "get remote", 10) == 0) {
Shannon Nelson738a9e92013-09-28 07:14:04 +00001838 u16 llen, rlen;
Neerav Parikh3753cb22013-11-26 10:49:25 +00001839 int ret;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001840 u8 *buff;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001841
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001842 buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL);
1843 if (!buff)
1844 goto command_write_done;
1845
1846 ret = i40e_aq_get_lldp_mib(&pf->hw,
1847 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
Neerav Parikhc27936e2014-06-03 23:50:16 +00001848 I40E_AQ_LLDP_MIB_REMOTE,
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001849 buff, I40E_LLDPDU_SIZE,
1850 &llen, &rlen, NULL);
1851 if (ret) {
1852 dev_info(&pf->pdev->dev,
1853 "Get LLDP MIB (remote) AQ command failed =0x%x\n",
1854 pf->hw.aq.asq_last_status);
1855 kfree(buff);
1856 buff = NULL;
1857 goto command_write_done;
1858 }
Neerav Parikh3753cb22013-11-26 10:49:25 +00001859 dev_info(&pf->pdev->dev, "LLDP MIB (remote)\n");
1860 print_hex_dump(KERN_INFO, "LLDP MIB (remote): ",
1861 DUMP_PREFIX_OFFSET, 16, 1,
1862 buff, I40E_LLDPDU_SIZE, true);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001863 kfree(buff);
1864 buff = NULL;
1865 } else if (strncmp(&cmd_buf[5], "event on", 8) == 0) {
1866 int ret;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001867
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001868 ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw,
1869 true, NULL);
1870 if (ret) {
1871 dev_info(&pf->pdev->dev,
1872 "Config LLDP MIB Change Event (on) AQ command failed =0x%x\n",
1873 pf->hw.aq.asq_last_status);
1874 goto command_write_done;
1875 }
1876 } else if (strncmp(&cmd_buf[5], "event off", 9) == 0) {
1877 int ret;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001878
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001879 ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw,
1880 false, NULL);
1881 if (ret) {
1882 dev_info(&pf->pdev->dev,
1883 "Config LLDP MIB Change Event (off) AQ command failed =0x%x\n",
1884 pf->hw.aq.asq_last_status);
1885 goto command_write_done;
1886 }
1887 }
1888 } else if (strncmp(cmd_buf, "nvm read", 8) == 0) {
Neerav Parikh3753cb22013-11-26 10:49:25 +00001889 u16 buffer_len, bytes;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001890 u16 module;
1891 u32 offset;
1892 u16 *buff;
1893 int ret;
1894
1895 cnt = sscanf(&cmd_buf[8], "%hx %x %hx",
1896 &module, &offset, &buffer_len);
1897 if (cnt == 0) {
1898 module = 0;
1899 offset = 0;
1900 buffer_len = 0;
1901 } else if (cnt == 1) {
1902 offset = 0;
1903 buffer_len = 0;
1904 } else if (cnt == 2) {
1905 buffer_len = 0;
1906 } else if (cnt > 3) {
1907 dev_info(&pf->pdev->dev,
1908 "nvm read: bad command string, cnt=%d\n", cnt);
1909 goto command_write_done;
1910 }
1911
Jesse Brandeburg520dfd82013-09-28 07:13:39 +00001912 /* set the max length */
1913 buffer_len = min_t(u16, buffer_len, I40E_MAX_AQ_BUF_SIZE/2);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001914
1915 bytes = 2 * buffer_len;
Jesse Brandeburg520dfd82013-09-28 07:13:39 +00001916
1917 /* read at least 1k bytes, no more than 4kB */
1918 bytes = clamp(bytes, (u16)1024, (u16)I40E_MAX_AQ_BUF_SIZE);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001919 buff = kzalloc(bytes, GFP_KERNEL);
1920 if (!buff)
1921 goto command_write_done;
1922
1923 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
1924 if (ret) {
1925 dev_info(&pf->pdev->dev,
1926 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1927 ret, pf->hw.aq.asq_last_status);
1928 kfree(buff);
1929 goto command_write_done;
1930 }
1931
1932 ret = i40e_aq_read_nvm(&pf->hw, module, (2 * offset),
1933 bytes, (u8 *)buff, true, NULL);
1934 i40e_release_nvm(&pf->hw);
1935 if (ret) {
1936 dev_info(&pf->pdev->dev,
1937 "Read NVM AQ failed err=%d status=0x%x\n",
1938 ret, pf->hw.aq.asq_last_status);
1939 } else {
1940 dev_info(&pf->pdev->dev,
1941 "Read NVM module=0x%x offset=0x%x words=%d\n",
1942 module, offset, buffer_len);
Anjali Singhai Jaina45e88c2013-11-28 06:39:26 +00001943 if (bytes)
Neerav Parikh3753cb22013-11-26 10:49:25 +00001944 print_hex_dump(KERN_INFO, "NVM Dump: ",
1945 DUMP_PREFIX_OFFSET, 16, 2,
Anjali Singhai Jaina45e88c2013-11-28 06:39:26 +00001946 buff, bytes, true);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001947 }
1948 kfree(buff);
1949 buff = NULL;
1950 } else {
1951 dev_info(&pf->pdev->dev, "unknown command '%s'\n", cmd_buf);
1952 dev_info(&pf->pdev->dev, "available commands\n");
1953 dev_info(&pf->pdev->dev, " add vsi [relay_seid]\n");
1954 dev_info(&pf->pdev->dev, " del vsi [vsi_seid]\n");
1955 dev_info(&pf->pdev->dev, " add relay <uplink_seid> <vsi_seid>\n");
1956 dev_info(&pf->pdev->dev, " del relay <relay_seid>\n");
1957 dev_info(&pf->pdev->dev, " add macaddr <vsi_seid> <aa:bb:cc:dd:ee:ff> [vlan]\n");
1958 dev_info(&pf->pdev->dev, " del macaddr <vsi_seid> <aa:bb:cc:dd:ee:ff> [vlan]\n");
1959 dev_info(&pf->pdev->dev, " add pvid <vsi_seid> <vid>\n");
1960 dev_info(&pf->pdev->dev, " del pvid <vsi_seid>\n");
1961 dev_info(&pf->pdev->dev, " dump switch\n");
1962 dev_info(&pf->pdev->dev, " dump vsi [seid]\n");
1963 dev_info(&pf->pdev->dev, " dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n");
1964 dev_info(&pf->pdev->dev, " dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n");
1965 dev_info(&pf->pdev->dev, " dump desc aq\n");
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001966 dev_info(&pf->pdev->dev, " dump reset stats\n");
Jesse Brandeburg3169c322015-04-07 19:45:37 -04001967 dev_info(&pf->pdev->dev, " dump debug fwdata <cluster_id> <table_id> <index>\n");
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001968 dev_info(&pf->pdev->dev, " msg_enable [level]\n");
1969 dev_info(&pf->pdev->dev, " read <reg>\n");
1970 dev_info(&pf->pdev->dev, " write <reg> <value>\n");
1971 dev_info(&pf->pdev->dev, " clear_stats vsi [seid]\n");
Shannon Nelson694dc1c2015-01-24 09:58:34 +00001972 dev_info(&pf->pdev->dev, " clear_stats port\n");
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001973 dev_info(&pf->pdev->dev, " pfr\n");
1974 dev_info(&pf->pdev->dev, " corer\n");
1975 dev_info(&pf->pdev->dev, " globr\n");
Anjali Singhai Jainf1143c42013-11-28 06:42:38 +00001976 dev_info(&pf->pdev->dev, " send aq_cmd <flags> <opcode> <datalen> <retval> <cookie_h> <cookie_l> <param0> <param1> <param2> <param3>\n");
1977 dev_info(&pf->pdev->dev, " send indirect aq_cmd <flags> <opcode> <datalen> <retval> <cookie_h> <cookie_l> <param0> <param1> <param2> <param3> <buffer_len>\n");
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001978 dev_info(&pf->pdev->dev, " add fd_filter <dest q_index> <flex_off> <pctype> <dest_vsi> <dest_ctl> <fd_status> <cnt_index> <fd_id> <packet_len> <packet>\n");
1979 dev_info(&pf->pdev->dev, " rem fd_filter <dest q_index> <flex_off> <pctype> <dest_vsi> <dest_ctl> <fd_status> <cnt_index> <fd_id> <packet_len> <packet>\n");
Anjali Singhai Jaine17ff052014-06-04 04:22:48 +00001980 dev_info(&pf->pdev->dev, " fd current cnt");
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001981 dev_info(&pf->pdev->dev, " lldp start\n");
1982 dev_info(&pf->pdev->dev, " lldp stop\n");
1983 dev_info(&pf->pdev->dev, " lldp get local\n");
1984 dev_info(&pf->pdev->dev, " lldp get remote\n");
1985 dev_info(&pf->pdev->dev, " lldp event on\n");
1986 dev_info(&pf->pdev->dev, " lldp event off\n");
1987 dev_info(&pf->pdev->dev, " nvm read [module] [word_offset] [word_count]\n");
1988 }
1989
1990command_write_done:
1991 kfree(cmd_buf);
1992 cmd_buf = NULL;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00001993 return count;
1994}
1995
1996static const struct file_operations i40e_dbg_command_fops = {
1997 .owner = THIS_MODULE,
1998 .open = simple_open,
1999 .read = i40e_dbg_command_read,
2000 .write = i40e_dbg_command_write,
2001};
2002
2003/**************************************************************
2004 * netdev_ops
2005 * The netdev_ops entry in debugfs is for giving the driver commands
2006 * to be executed from the netdev operations.
2007 **************************************************************/
Greg Rosed1da3ac2015-02-27 09:18:29 +00002008static char i40e_dbg_netdev_ops_buf[256] = "";
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002009
2010/**
2011 * i40e_dbg_netdev_ops - read for netdev_ops datum
2012 * @filp: the opened file
2013 * @buffer: where to write the data for the user to read
2014 * @count: the size of the user's buffer
2015 * @ppos: file position offset
2016 **/
2017static ssize_t i40e_dbg_netdev_ops_read(struct file *filp, char __user *buffer,
2018 size_t count, loff_t *ppos)
2019{
2020 struct i40e_pf *pf = filp->private_data;
2021 int bytes_not_copied;
2022 int buf_size = 256;
2023 char *buf;
2024 int len;
2025
2026 /* don't allow partal reads */
2027 if (*ppos != 0)
2028 return 0;
2029 if (count < buf_size)
2030 return -ENOSPC;
2031
2032 buf = kzalloc(buf_size, GFP_KERNEL);
2033 if (!buf)
2034 return -ENOSPC;
2035
2036 len = snprintf(buf, buf_size, "%s: %s\n",
2037 pf->vsi[pf->lan_vsi]->netdev->name,
2038 i40e_dbg_netdev_ops_buf);
2039
2040 bytes_not_copied = copy_to_user(buffer, buf, len);
2041 kfree(buf);
2042
Rasmus Villemoes0286c672015-10-17 22:58:19 +02002043 if (bytes_not_copied)
2044 return -EFAULT;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002045
2046 *ppos = len;
2047 return len;
2048}
2049
2050/**
2051 * i40e_dbg_netdev_ops_write - write into netdev_ops datum
2052 * @filp: the opened file
2053 * @buffer: where to find the user's data
2054 * @count: the length of the user's data
2055 * @ppos: file position offset
2056 **/
2057static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
2058 const char __user *buffer,
2059 size_t count, loff_t *ppos)
2060{
2061 struct i40e_pf *pf = filp->private_data;
2062 int bytes_not_copied;
2063 struct i40e_vsi *vsi;
Jesse Brandeburg004173c2013-09-28 07:13:44 +00002064 char *buf_tmp;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002065 int vsi_seid;
2066 int i, cnt;
2067
2068 /* don't allow partial writes */
2069 if (*ppos != 0)
2070 return 0;
2071 if (count >= sizeof(i40e_dbg_netdev_ops_buf))
2072 return -ENOSPC;
2073
2074 memset(i40e_dbg_netdev_ops_buf, 0, sizeof(i40e_dbg_netdev_ops_buf));
2075 bytes_not_copied = copy_from_user(i40e_dbg_netdev_ops_buf,
2076 buffer, count);
Rasmus Villemoes0286c672015-10-17 22:58:19 +02002077 if (bytes_not_copied)
2078 return -EFAULT;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002079 i40e_dbg_netdev_ops_buf[count] = '\0';
2080
Jesse Brandeburg004173c2013-09-28 07:13:44 +00002081 buf_tmp = strchr(i40e_dbg_netdev_ops_buf, '\n');
2082 if (buf_tmp) {
2083 *buf_tmp = '\0';
2084 count = buf_tmp - i40e_dbg_netdev_ops_buf + 1;
2085 }
2086
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002087 if (strncmp(i40e_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) {
2088 cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid);
2089 if (cnt != 1) {
2090 dev_info(&pf->pdev->dev, "tx_timeout <vsi_seid>\n");
2091 goto netdev_ops_write_done;
2092 }
2093 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
2094 if (!vsi) {
2095 dev_info(&pf->pdev->dev,
2096 "tx_timeout: VSI %d not found\n", vsi_seid);
Shannon Nelsonca046572014-03-06 09:00:02 +00002097 } else if (!vsi->netdev) {
2098 dev_info(&pf->pdev->dev, "tx_timeout: no netdev for VSI %d\n",
2099 vsi_seid);
2100 } else if (test_bit(__I40E_DOWN, &vsi->state)) {
2101 dev_info(&pf->pdev->dev, "tx_timeout: VSI %d not UP\n",
2102 vsi_seid);
2103 } else if (rtnl_trylock()) {
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002104 vsi->netdev->netdev_ops->ndo_tx_timeout(vsi->netdev);
2105 rtnl_unlock();
2106 dev_info(&pf->pdev->dev, "tx_timeout called\n");
2107 } else {
2108 dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
2109 }
2110 } else if (strncmp(i40e_dbg_netdev_ops_buf, "change_mtu", 10) == 0) {
2111 int mtu;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002112
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002113 cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i %i",
2114 &vsi_seid, &mtu);
2115 if (cnt != 2) {
2116 dev_info(&pf->pdev->dev, "change_mtu <vsi_seid> <mtu>\n");
2117 goto netdev_ops_write_done;
2118 }
2119 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
2120 if (!vsi) {
2121 dev_info(&pf->pdev->dev,
2122 "change_mtu: VSI %d not found\n", vsi_seid);
Shannon Nelsonca046572014-03-06 09:00:02 +00002123 } else if (!vsi->netdev) {
2124 dev_info(&pf->pdev->dev, "change_mtu: no netdev for VSI %d\n",
2125 vsi_seid);
2126 } else if (rtnl_trylock()) {
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002127 vsi->netdev->netdev_ops->ndo_change_mtu(vsi->netdev,
2128 mtu);
2129 rtnl_unlock();
2130 dev_info(&pf->pdev->dev, "change_mtu called\n");
2131 } else {
2132 dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
2133 }
2134
2135 } else if (strncmp(i40e_dbg_netdev_ops_buf, "set_rx_mode", 11) == 0) {
2136 cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid);
2137 if (cnt != 1) {
2138 dev_info(&pf->pdev->dev, "set_rx_mode <vsi_seid>\n");
2139 goto netdev_ops_write_done;
2140 }
2141 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
2142 if (!vsi) {
2143 dev_info(&pf->pdev->dev,
2144 "set_rx_mode: VSI %d not found\n", vsi_seid);
Shannon Nelsonca046572014-03-06 09:00:02 +00002145 } else if (!vsi->netdev) {
2146 dev_info(&pf->pdev->dev, "set_rx_mode: no netdev for VSI %d\n",
2147 vsi_seid);
2148 } else if (rtnl_trylock()) {
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002149 vsi->netdev->netdev_ops->ndo_set_rx_mode(vsi->netdev);
2150 rtnl_unlock();
2151 dev_info(&pf->pdev->dev, "set_rx_mode called\n");
2152 } else {
2153 dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
2154 }
2155
2156 } else if (strncmp(i40e_dbg_netdev_ops_buf, "napi", 4) == 0) {
2157 cnt = sscanf(&i40e_dbg_netdev_ops_buf[4], "%i", &vsi_seid);
2158 if (cnt != 1) {
2159 dev_info(&pf->pdev->dev, "napi <vsi_seid>\n");
2160 goto netdev_ops_write_done;
2161 }
2162 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
2163 if (!vsi) {
2164 dev_info(&pf->pdev->dev, "napi: VSI %d not found\n",
2165 vsi_seid);
Shannon Nelsonca046572014-03-06 09:00:02 +00002166 } else if (!vsi->netdev) {
2167 dev_info(&pf->pdev->dev, "napi: no netdev for VSI %d\n",
2168 vsi_seid);
2169 } else {
2170 for (i = 0; i < vsi->num_q_vectors; i++)
2171 napi_schedule(&vsi->q_vectors[i]->napi);
2172 dev_info(&pf->pdev->dev, "napi called\n");
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002173 }
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002174 } else {
2175 dev_info(&pf->pdev->dev, "unknown command '%s'\n",
2176 i40e_dbg_netdev_ops_buf);
2177 dev_info(&pf->pdev->dev, "available commands\n");
2178 dev_info(&pf->pdev->dev, " tx_timeout <vsi_seid>\n");
2179 dev_info(&pf->pdev->dev, " change_mtu <vsi_seid> <mtu>\n");
2180 dev_info(&pf->pdev->dev, " set_rx_mode <vsi_seid>\n");
2181 dev_info(&pf->pdev->dev, " napi <vsi_seid>\n");
2182 }
2183netdev_ops_write_done:
2184 return count;
2185}
2186
2187static const struct file_operations i40e_dbg_netdev_ops_fops = {
2188 .owner = THIS_MODULE,
2189 .open = simple_open,
2190 .read = i40e_dbg_netdev_ops_read,
2191 .write = i40e_dbg_netdev_ops_write,
2192};
2193
2194/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00002195 * i40e_dbg_pf_init - setup the debugfs directory for the PF
2196 * @pf: the PF that is starting up
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002197 **/
2198void i40e_dbg_pf_init(struct i40e_pf *pf)
2199{
Jesse Brandeburg63010022013-09-28 07:13:33 +00002200 struct dentry *pfile;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002201 const char *name = pci_name(pf->pdev);
Jesse Brandeburg63010022013-09-28 07:13:33 +00002202 const struct device *dev = &pf->pdev->dev;
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002203
2204 pf->i40e_dbg_pf = debugfs_create_dir(name, i40e_dbg_root);
Jesse Brandeburg63010022013-09-28 07:13:33 +00002205 if (!pf->i40e_dbg_pf)
2206 return;
2207
2208 pfile = debugfs_create_file("command", 0600, pf->i40e_dbg_pf, pf,
2209 &i40e_dbg_command_fops);
2210 if (!pfile)
2211 goto create_failed;
2212
2213 pfile = debugfs_create_file("dump", 0600, pf->i40e_dbg_pf, pf,
2214 &i40e_dbg_dump_fops);
2215 if (!pfile)
2216 goto create_failed;
2217
2218 pfile = debugfs_create_file("netdev_ops", 0600, pf->i40e_dbg_pf, pf,
2219 &i40e_dbg_netdev_ops_fops);
2220 if (!pfile)
2221 goto create_failed;
2222
2223 return;
2224
2225create_failed:
2226 dev_info(dev, "debugfs dir/file for %s failed\n", name);
2227 debugfs_remove_recursive(pf->i40e_dbg_pf);
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002228}
2229
2230/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00002231 * i40e_dbg_pf_exit - clear out the PF's debugfs entries
2232 * @pf: the PF that is stopping
Jesse Brandeburg02e9c292013-09-11 08:40:17 +00002233 **/
2234void i40e_dbg_pf_exit(struct i40e_pf *pf)
2235{
2236 debugfs_remove_recursive(pf->i40e_dbg_pf);
2237 pf->i40e_dbg_pf = NULL;
2238
2239 kfree(i40e_dbg_dump_buf);
2240 i40e_dbg_dump_buf = NULL;
2241}
2242
2243/**
2244 * i40e_dbg_init - start up debugfs for the driver
2245 **/
2246void i40e_dbg_init(void)
2247{
2248 i40e_dbg_root = debugfs_create_dir(i40e_driver_name, NULL);
2249 if (!i40e_dbg_root)
2250 pr_info("init of debugfs failed\n");
2251}
2252
2253/**
2254 * i40e_dbg_exit - clean out the driver's debugfs entries
2255 **/
2256void i40e_dbg_exit(void)
2257{
2258 debugfs_remove_recursive(i40e_dbg_root);
2259 i40e_dbg_root = NULL;
2260}
2261
2262#endif /* CONFIG_DEBUG_FS */