]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/net/ethernet/intel/i40e/i40e_debugfs.c
Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetoot...
[mirror_ubuntu-hirsute-kernel.git] / drivers / net / ethernet / intel / i40e / i40e_debugfs.c
1 /*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2016 Intel Corporation.
5 *
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 *
15 * 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/>.
17 *
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
34 static struct dentry *i40e_dbg_root;
35
36 /**
37 * i40e_dbg_find_vsi - searches for the vsi with the given seid
38 * @pf - the PF structure to search for the vsi
39 * @seid - seid of the vsi it is searching for
40 **/
41 static 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
48 for (i = 0; i < pf->num_alloc_vsi; i++)
49 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
57 * @pf - the PF structure to search for the veb
58 * @seid - seid of the veb it is searching for
59 **/
60 static struct i40e_veb *i40e_dbg_find_veb(struct i40e_pf *pf, int seid)
61 {
62 int i;
63
64 for (i = 0; i < I40E_MAX_VEB; i++)
65 if (pf->veb[i] && pf->veb[i]->seid == seid)
66 return pf->veb[i];
67 return NULL;
68 }
69
70 /**************************************************************
71 * command
72 * The command entry in debugfs is for giving the driver commands
73 * to be executed - these may be for changing the internal switch
74 * setup, adding or removing filters, or other things. Many of
75 * these will be useful for some forms of unit testing.
76 **************************************************************/
77 static char i40e_dbg_command_buf[256] = "";
78
79 /**
80 * i40e_dbg_command_read - read for command datum
81 * @filp: the opened file
82 * @buffer: where to write the data for the user to read
83 * @count: the size of the user's buffer
84 * @ppos: file position offset
85 **/
86 static ssize_t i40e_dbg_command_read(struct file *filp, char __user *buffer,
87 size_t count, loff_t *ppos)
88 {
89 struct i40e_pf *pf = filp->private_data;
90 int bytes_not_copied;
91 int buf_size = 256;
92 char *buf;
93 int len;
94
95 /* don't allow partial reads */
96 if (*ppos != 0)
97 return 0;
98 if (count < buf_size)
99 return -ENOSPC;
100
101 buf = kzalloc(buf_size, GFP_KERNEL);
102 if (!buf)
103 return -ENOSPC;
104
105 len = snprintf(buf, buf_size, "%s: %s\n",
106 pf->vsi[pf->lan_vsi]->netdev->name,
107 i40e_dbg_command_buf);
108
109 bytes_not_copied = copy_to_user(buffer, buf, len);
110 kfree(buf);
111
112 if (bytes_not_copied)
113 return -EFAULT;
114
115 *ppos = len;
116 return len;
117 }
118
119 /**
120 * i40e_dbg_dump_vsi_seid - handles dump vsi seid write into command datum
121 * @pf: the i40e_pf created in command write
122 * @seid: the seid the user put in
123 **/
124 static void i40e_dbg_dump_vsi_seid(struct i40e_pf *pf, int seid)
125 {
126 struct rtnl_link_stats64 *nstat;
127 struct i40e_mac_filter *f;
128 struct i40e_vsi *vsi;
129 int i;
130
131 vsi = i40e_dbg_find_vsi(pf, seid);
132 if (!vsi) {
133 dev_info(&pf->pdev->dev,
134 "dump %d: seid not found\n", seid);
135 return;
136 }
137 dev_info(&pf->pdev->dev, "vsi seid %d\n", seid);
138 if (vsi->netdev) {
139 struct net_device *nd = vsi->netdev;
140
141 dev_info(&pf->pdev->dev, " netdev: name = %s, state = %lu, flags = 0x%08x\n",
142 nd->name, nd->state, nd->flags);
143 dev_info(&pf->pdev->dev, " features = 0x%08lx\n",
144 (unsigned long int)nd->features);
145 dev_info(&pf->pdev->dev, " hw_features = 0x%08lx\n",
146 (unsigned long int)nd->hw_features);
147 dev_info(&pf->pdev->dev, " vlan_features = 0x%08lx\n",
148 (unsigned long int)nd->vlan_features);
149 }
150 dev_info(&pf->pdev->dev,
151 " vlgrp: & = %p\n", vsi->active_vlans);
152 dev_info(&pf->pdev->dev,
153 " state = %li flags = 0x%08lx, netdev_registered = %i, current_netdev_flags = 0x%04x\n",
154 vsi->state, vsi->flags,
155 vsi->netdev_registered, vsi->current_netdev_flags);
156 if (vsi == pf->vsi[pf->lan_vsi])
157 dev_info(&pf->pdev->dev, " MAC address: %pM SAN MAC: %pM Port MAC: %pM\n",
158 pf->hw.mac.addr,
159 pf->hw.mac.san_addr,
160 pf->hw.mac.port_addr);
161 list_for_each_entry(f, &vsi->mac_filter_list, list) {
162 dev_info(&pf->pdev->dev,
163 " mac_filter_list: %pM vid=%d, is_netdev=%d is_vf=%d counter=%d\n",
164 f->macaddr, f->vlan, f->is_netdev, f->is_vf,
165 f->counter);
166 }
167 nstat = i40e_get_vsi_stats_struct(vsi);
168 dev_info(&pf->pdev->dev,
169 " net_stats: rx_packets = %lu, rx_bytes = %lu, rx_errors = %lu, rx_dropped = %lu\n",
170 (unsigned long int)nstat->rx_packets,
171 (unsigned long int)nstat->rx_bytes,
172 (unsigned long int)nstat->rx_errors,
173 (unsigned long int)nstat->rx_dropped);
174 dev_info(&pf->pdev->dev,
175 " net_stats: tx_packets = %lu, tx_bytes = %lu, tx_errors = %lu, tx_dropped = %lu\n",
176 (unsigned long int)nstat->tx_packets,
177 (unsigned long int)nstat->tx_bytes,
178 (unsigned long int)nstat->tx_errors,
179 (unsigned long int)nstat->tx_dropped);
180 dev_info(&pf->pdev->dev,
181 " net_stats: multicast = %lu, collisions = %lu\n",
182 (unsigned long int)nstat->multicast,
183 (unsigned long int)nstat->collisions);
184 dev_info(&pf->pdev->dev,
185 " net_stats: rx_length_errors = %lu, rx_over_errors = %lu, rx_crc_errors = %lu\n",
186 (unsigned long int)nstat->rx_length_errors,
187 (unsigned long int)nstat->rx_over_errors,
188 (unsigned long int)nstat->rx_crc_errors);
189 dev_info(&pf->pdev->dev,
190 " net_stats: rx_frame_errors = %lu, rx_fifo_errors = %lu, rx_missed_errors = %lu\n",
191 (unsigned long int)nstat->rx_frame_errors,
192 (unsigned long int)nstat->rx_fifo_errors,
193 (unsigned long int)nstat->rx_missed_errors);
194 dev_info(&pf->pdev->dev,
195 " net_stats: tx_aborted_errors = %lu, tx_carrier_errors = %lu, tx_fifo_errors = %lu\n",
196 (unsigned long int)nstat->tx_aborted_errors,
197 (unsigned long int)nstat->tx_carrier_errors,
198 (unsigned long int)nstat->tx_fifo_errors);
199 dev_info(&pf->pdev->dev,
200 " net_stats: tx_heartbeat_errors = %lu, tx_window_errors = %lu\n",
201 (unsigned long int)nstat->tx_heartbeat_errors,
202 (unsigned long int)nstat->tx_window_errors);
203 dev_info(&pf->pdev->dev,
204 " net_stats: rx_compressed = %lu, tx_compressed = %lu\n",
205 (unsigned long int)nstat->rx_compressed,
206 (unsigned long int)nstat->tx_compressed);
207 dev_info(&pf->pdev->dev,
208 " net_stats_offsets: rx_packets = %lu, rx_bytes = %lu, rx_errors = %lu, rx_dropped = %lu\n",
209 (unsigned long int)vsi->net_stats_offsets.rx_packets,
210 (unsigned long int)vsi->net_stats_offsets.rx_bytes,
211 (unsigned long int)vsi->net_stats_offsets.rx_errors,
212 (unsigned long int)vsi->net_stats_offsets.rx_dropped);
213 dev_info(&pf->pdev->dev,
214 " net_stats_offsets: tx_packets = %lu, tx_bytes = %lu, tx_errors = %lu, tx_dropped = %lu\n",
215 (unsigned long int)vsi->net_stats_offsets.tx_packets,
216 (unsigned long int)vsi->net_stats_offsets.tx_bytes,
217 (unsigned long int)vsi->net_stats_offsets.tx_errors,
218 (unsigned long int)vsi->net_stats_offsets.tx_dropped);
219 dev_info(&pf->pdev->dev,
220 " net_stats_offsets: multicast = %lu, collisions = %lu\n",
221 (unsigned long int)vsi->net_stats_offsets.multicast,
222 (unsigned long int)vsi->net_stats_offsets.collisions);
223 dev_info(&pf->pdev->dev,
224 " net_stats_offsets: rx_length_errors = %lu, rx_over_errors = %lu, rx_crc_errors = %lu\n",
225 (unsigned long int)vsi->net_stats_offsets.rx_length_errors,
226 (unsigned long int)vsi->net_stats_offsets.rx_over_errors,
227 (unsigned long int)vsi->net_stats_offsets.rx_crc_errors);
228 dev_info(&pf->pdev->dev,
229 " net_stats_offsets: rx_frame_errors = %lu, rx_fifo_errors = %lu, rx_missed_errors = %lu\n",
230 (unsigned long int)vsi->net_stats_offsets.rx_frame_errors,
231 (unsigned long int)vsi->net_stats_offsets.rx_fifo_errors,
232 (unsigned long int)vsi->net_stats_offsets.rx_missed_errors);
233 dev_info(&pf->pdev->dev,
234 " net_stats_offsets: tx_aborted_errors = %lu, tx_carrier_errors = %lu, tx_fifo_errors = %lu\n",
235 (unsigned long int)vsi->net_stats_offsets.tx_aborted_errors,
236 (unsigned long int)vsi->net_stats_offsets.tx_carrier_errors,
237 (unsigned long int)vsi->net_stats_offsets.tx_fifo_errors);
238 dev_info(&pf->pdev->dev,
239 " net_stats_offsets: tx_heartbeat_errors = %lu, tx_window_errors = %lu\n",
240 (unsigned long int)vsi->net_stats_offsets.tx_heartbeat_errors,
241 (unsigned long int)vsi->net_stats_offsets.tx_window_errors);
242 dev_info(&pf->pdev->dev,
243 " net_stats_offsets: rx_compressed = %lu, tx_compressed = %lu\n",
244 (unsigned long int)vsi->net_stats_offsets.rx_compressed,
245 (unsigned long int)vsi->net_stats_offsets.tx_compressed);
246 dev_info(&pf->pdev->dev,
247 " tx_restart = %d, tx_busy = %d, rx_buf_failed = %d, rx_page_failed = %d\n",
248 vsi->tx_restart, vsi->tx_busy,
249 vsi->rx_buf_failed, vsi->rx_page_failed);
250 rcu_read_lock();
251 for (i = 0; i < vsi->num_queue_pairs; i++) {
252 struct i40e_ring *rx_ring = ACCESS_ONCE(vsi->rx_rings[i]);
253
254 if (!rx_ring)
255 continue;
256
257 dev_info(&pf->pdev->dev,
258 " rx_rings[%i]: desc = %p\n",
259 i, rx_ring->desc);
260 dev_info(&pf->pdev->dev,
261 " rx_rings[%i]: dev = %p, netdev = %p, rx_bi = %p\n",
262 i, rx_ring->dev,
263 rx_ring->netdev,
264 rx_ring->rx_bi);
265 dev_info(&pf->pdev->dev,
266 " rx_rings[%i]: state = %li, queue_index = %d, reg_idx = %d\n",
267 i, rx_ring->state,
268 rx_ring->queue_index,
269 rx_ring->reg_idx);
270 dev_info(&pf->pdev->dev,
271 " rx_rings[%i]: rx_hdr_len = %d, rx_buf_len = %d, dtype = %d\n",
272 i, rx_ring->rx_hdr_len,
273 rx_ring->rx_buf_len,
274 rx_ring->dtype);
275 dev_info(&pf->pdev->dev,
276 " rx_rings[%i]: hsplit = %d, next_to_use = %d, next_to_clean = %d, ring_active = %i\n",
277 i, ring_is_ps_enabled(rx_ring),
278 rx_ring->next_to_use,
279 rx_ring->next_to_clean,
280 rx_ring->ring_active);
281 dev_info(&pf->pdev->dev,
282 " rx_rings[%i]: rx_stats: packets = %lld, bytes = %lld, non_eop_descs = %lld\n",
283 i, rx_ring->stats.packets,
284 rx_ring->stats.bytes,
285 rx_ring->rx_stats.non_eop_descs);
286 dev_info(&pf->pdev->dev,
287 " rx_rings[%i]: rx_stats: alloc_page_failed = %lld, alloc_buff_failed = %lld\n",
288 i,
289 rx_ring->rx_stats.alloc_page_failed,
290 rx_ring->rx_stats.alloc_buff_failed);
291 dev_info(&pf->pdev->dev,
292 " rx_rings[%i]: rx_stats: realloc_count = %lld, page_reuse_count = %lld\n",
293 i,
294 rx_ring->rx_stats.realloc_count,
295 rx_ring->rx_stats.page_reuse_count);
296 dev_info(&pf->pdev->dev,
297 " rx_rings[%i]: size = %i, dma = 0x%08lx\n",
298 i, rx_ring->size,
299 (unsigned long int)rx_ring->dma);
300 dev_info(&pf->pdev->dev,
301 " rx_rings[%i]: vsi = %p, q_vector = %p\n",
302 i, rx_ring->vsi,
303 rx_ring->q_vector);
304 dev_info(&pf->pdev->dev,
305 " rx_rings[%i]: rx_itr_setting = %d (%s)\n",
306 i, rx_ring->rx_itr_setting,
307 ITR_IS_DYNAMIC(rx_ring->rx_itr_setting) ? "dynamic" : "fixed");
308 }
309 for (i = 0; i < vsi->num_queue_pairs; i++) {
310 struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
311
312 if (!tx_ring)
313 continue;
314
315 dev_info(&pf->pdev->dev,
316 " tx_rings[%i]: desc = %p\n",
317 i, tx_ring->desc);
318 dev_info(&pf->pdev->dev,
319 " tx_rings[%i]: dev = %p, netdev = %p, tx_bi = %p\n",
320 i, tx_ring->dev,
321 tx_ring->netdev,
322 tx_ring->tx_bi);
323 dev_info(&pf->pdev->dev,
324 " tx_rings[%i]: state = %li, queue_index = %d, reg_idx = %d\n",
325 i, tx_ring->state,
326 tx_ring->queue_index,
327 tx_ring->reg_idx);
328 dev_info(&pf->pdev->dev,
329 " tx_rings[%i]: dtype = %d\n",
330 i, tx_ring->dtype);
331 dev_info(&pf->pdev->dev,
332 " tx_rings[%i]: next_to_use = %d, next_to_clean = %d, ring_active = %i\n",
333 i,
334 tx_ring->next_to_use,
335 tx_ring->next_to_clean,
336 tx_ring->ring_active);
337 dev_info(&pf->pdev->dev,
338 " tx_rings[%i]: tx_stats: packets = %lld, bytes = %lld, restart_queue = %lld\n",
339 i, tx_ring->stats.packets,
340 tx_ring->stats.bytes,
341 tx_ring->tx_stats.restart_queue);
342 dev_info(&pf->pdev->dev,
343 " tx_rings[%i]: tx_stats: tx_busy = %lld, tx_done_old = %lld\n",
344 i,
345 tx_ring->tx_stats.tx_busy,
346 tx_ring->tx_stats.tx_done_old);
347 dev_info(&pf->pdev->dev,
348 " tx_rings[%i]: size = %i, dma = 0x%08lx\n",
349 i, tx_ring->size,
350 (unsigned long int)tx_ring->dma);
351 dev_info(&pf->pdev->dev,
352 " tx_rings[%i]: vsi = %p, q_vector = %p\n",
353 i, tx_ring->vsi,
354 tx_ring->q_vector);
355 dev_info(&pf->pdev->dev,
356 " tx_rings[%i]: DCB tc = %d\n",
357 i, tx_ring->dcb_tc);
358 dev_info(&pf->pdev->dev,
359 " tx_rings[%i]: tx_itr_setting = %d (%s)\n",
360 i, tx_ring->tx_itr_setting,
361 ITR_IS_DYNAMIC(tx_ring->tx_itr_setting) ? "dynamic" : "fixed");
362 }
363 rcu_read_unlock();
364 dev_info(&pf->pdev->dev,
365 " work_limit = %d\n",
366 vsi->work_limit);
367 dev_info(&pf->pdev->dev,
368 " max_frame = %d, rx_hdr_len = %d, rx_buf_len = %d dtype = %d\n",
369 vsi->max_frame, vsi->rx_hdr_len, vsi->rx_buf_len, vsi->dtype);
370 dev_info(&pf->pdev->dev,
371 " num_q_vectors = %i, base_vector = %i\n",
372 vsi->num_q_vectors, vsi->base_vector);
373 dev_info(&pf->pdev->dev,
374 " seid = %d, id = %d, uplink_seid = %d\n",
375 vsi->seid, vsi->id, vsi->uplink_seid);
376 dev_info(&pf->pdev->dev,
377 " base_queue = %d, num_queue_pairs = %d, num_desc = %d\n",
378 vsi->base_queue, vsi->num_queue_pairs, vsi->num_desc);
379 dev_info(&pf->pdev->dev, " type = %i\n", vsi->type);
380 dev_info(&pf->pdev->dev,
381 " info: valid_sections = 0x%04x, switch_id = 0x%04x\n",
382 vsi->info.valid_sections, vsi->info.switch_id);
383 dev_info(&pf->pdev->dev,
384 " info: sw_reserved[] = 0x%02x 0x%02x\n",
385 vsi->info.sw_reserved[0], vsi->info.sw_reserved[1]);
386 dev_info(&pf->pdev->dev,
387 " info: sec_flags = 0x%02x, sec_reserved = 0x%02x\n",
388 vsi->info.sec_flags, vsi->info.sec_reserved);
389 dev_info(&pf->pdev->dev,
390 " info: pvid = 0x%04x, fcoe_pvid = 0x%04x, port_vlan_flags = 0x%02x\n",
391 vsi->info.pvid, vsi->info.fcoe_pvid,
392 vsi->info.port_vlan_flags);
393 dev_info(&pf->pdev->dev,
394 " info: pvlan_reserved[] = 0x%02x 0x%02x 0x%02x\n",
395 vsi->info.pvlan_reserved[0], vsi->info.pvlan_reserved[1],
396 vsi->info.pvlan_reserved[2]);
397 dev_info(&pf->pdev->dev,
398 " info: ingress_table = 0x%08x, egress_table = 0x%08x\n",
399 vsi->info.ingress_table, vsi->info.egress_table);
400 dev_info(&pf->pdev->dev,
401 " info: cas_pv_stag = 0x%04x, cas_pv_flags= 0x%02x, cas_pv_reserved = 0x%02x\n",
402 vsi->info.cas_pv_tag, vsi->info.cas_pv_flags,
403 vsi->info.cas_pv_reserved);
404 dev_info(&pf->pdev->dev,
405 " info: queue_mapping[0..7 ] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
406 vsi->info.queue_mapping[0], vsi->info.queue_mapping[1],
407 vsi->info.queue_mapping[2], vsi->info.queue_mapping[3],
408 vsi->info.queue_mapping[4], vsi->info.queue_mapping[5],
409 vsi->info.queue_mapping[6], vsi->info.queue_mapping[7]);
410 dev_info(&pf->pdev->dev,
411 " info: queue_mapping[8..15] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
412 vsi->info.queue_mapping[8], vsi->info.queue_mapping[9],
413 vsi->info.queue_mapping[10], vsi->info.queue_mapping[11],
414 vsi->info.queue_mapping[12], vsi->info.queue_mapping[13],
415 vsi->info.queue_mapping[14], vsi->info.queue_mapping[15]);
416 dev_info(&pf->pdev->dev,
417 " info: tc_mapping[] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
418 vsi->info.tc_mapping[0], vsi->info.tc_mapping[1],
419 vsi->info.tc_mapping[2], vsi->info.tc_mapping[3],
420 vsi->info.tc_mapping[4], vsi->info.tc_mapping[5],
421 vsi->info.tc_mapping[6], vsi->info.tc_mapping[7]);
422 dev_info(&pf->pdev->dev,
423 " info: queueing_opt_flags = 0x%02x queueing_opt_reserved[0..2] = 0x%02x 0x%02x 0x%02x\n",
424 vsi->info.queueing_opt_flags,
425 vsi->info.queueing_opt_reserved[0],
426 vsi->info.queueing_opt_reserved[1],
427 vsi->info.queueing_opt_reserved[2]);
428 dev_info(&pf->pdev->dev,
429 " info: up_enable_bits = 0x%02x\n",
430 vsi->info.up_enable_bits);
431 dev_info(&pf->pdev->dev,
432 " info: sched_reserved = 0x%02x, outer_up_table = 0x%04x\n",
433 vsi->info.sched_reserved, vsi->info.outer_up_table);
434 dev_info(&pf->pdev->dev,
435 " info: cmd_reserved[] = 0x%02x 0x%02x 0x%02x 0x0%02x 0x%02x 0x%02x 0x%02x 0x0%02x\n",
436 vsi->info.cmd_reserved[0], vsi->info.cmd_reserved[1],
437 vsi->info.cmd_reserved[2], vsi->info.cmd_reserved[3],
438 vsi->info.cmd_reserved[4], vsi->info.cmd_reserved[5],
439 vsi->info.cmd_reserved[6], vsi->info.cmd_reserved[7]);
440 dev_info(&pf->pdev->dev,
441 " info: qs_handle[] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
442 vsi->info.qs_handle[0], vsi->info.qs_handle[1],
443 vsi->info.qs_handle[2], vsi->info.qs_handle[3],
444 vsi->info.qs_handle[4], vsi->info.qs_handle[5],
445 vsi->info.qs_handle[6], vsi->info.qs_handle[7]);
446 dev_info(&pf->pdev->dev,
447 " info: stat_counter_idx = 0x%04x, sched_id = 0x%04x\n",
448 vsi->info.stat_counter_idx, vsi->info.sched_id);
449 dev_info(&pf->pdev->dev,
450 " 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",
451 vsi->info.resp_reserved[0], vsi->info.resp_reserved[1],
452 vsi->info.resp_reserved[2], vsi->info.resp_reserved[3],
453 vsi->info.resp_reserved[4], vsi->info.resp_reserved[5],
454 vsi->info.resp_reserved[6], vsi->info.resp_reserved[7],
455 vsi->info.resp_reserved[8], vsi->info.resp_reserved[9],
456 vsi->info.resp_reserved[10], vsi->info.resp_reserved[11]);
457 if (vsi->back)
458 dev_info(&pf->pdev->dev, " PF = %p\n", vsi->back);
459 dev_info(&pf->pdev->dev, " idx = %d\n", vsi->idx);
460 dev_info(&pf->pdev->dev,
461 " tc_config: numtc = %d, enabled_tc = 0x%x\n",
462 vsi->tc_config.numtc, vsi->tc_config.enabled_tc);
463 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
464 dev_info(&pf->pdev->dev,
465 " tc_config: tc = %d, qoffset = %d, qcount = %d, netdev_tc = %d\n",
466 i, vsi->tc_config.tc_info[i].qoffset,
467 vsi->tc_config.tc_info[i].qcount,
468 vsi->tc_config.tc_info[i].netdev_tc);
469 }
470 dev_info(&pf->pdev->dev,
471 " bw: bw_limit = %d, bw_max_quanta = %d\n",
472 vsi->bw_limit, vsi->bw_max_quanta);
473 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
474 dev_info(&pf->pdev->dev,
475 " bw[%d]: ets_share_credits = %d, ets_limit_credits = %d, max_quanta = %d\n",
476 i, vsi->bw_ets_share_credits[i],
477 vsi->bw_ets_limit_credits[i],
478 vsi->bw_ets_max_quanta[i]);
479 }
480 #ifdef I40E_FCOE
481 if (vsi->type == I40E_VSI_FCOE) {
482 dev_info(&pf->pdev->dev,
483 " fcoe_stats: rx_packets = %llu, rx_dwords = %llu, rx_dropped = %llu\n",
484 vsi->fcoe_stats.rx_fcoe_packets,
485 vsi->fcoe_stats.rx_fcoe_dwords,
486 vsi->fcoe_stats.rx_fcoe_dropped);
487 dev_info(&pf->pdev->dev,
488 " fcoe_stats: tx_packets = %llu, tx_dwords = %llu\n",
489 vsi->fcoe_stats.tx_fcoe_packets,
490 vsi->fcoe_stats.tx_fcoe_dwords);
491 dev_info(&pf->pdev->dev,
492 " fcoe_stats: bad_crc = %llu, last_error = %llu\n",
493 vsi->fcoe_stats.fcoe_bad_fccrc,
494 vsi->fcoe_stats.fcoe_last_error);
495 dev_info(&pf->pdev->dev, " fcoe_stats: ddp_count = %llu\n",
496 vsi->fcoe_stats.fcoe_ddp_count);
497 }
498 #endif
499 }
500
501 /**
502 * i40e_dbg_dump_aq_desc - handles dump aq_desc write into command datum
503 * @pf: the i40e_pf created in command write
504 **/
505 static void i40e_dbg_dump_aq_desc(struct i40e_pf *pf)
506 {
507 struct i40e_adminq_ring *ring;
508 struct i40e_hw *hw = &pf->hw;
509 char hdr[32];
510 int i;
511
512 snprintf(hdr, sizeof(hdr), "%s %s: ",
513 dev_driver_string(&pf->pdev->dev),
514 dev_name(&pf->pdev->dev));
515
516 /* first the send (command) ring, then the receive (event) ring */
517 dev_info(&pf->pdev->dev, "AdminQ Tx Ring\n");
518 ring = &(hw->aq.asq);
519 for (i = 0; i < ring->count; i++) {
520 struct i40e_aq_desc *d = I40E_ADMINQ_DESC(*ring, i);
521
522 dev_info(&pf->pdev->dev,
523 " at[%02d] flags=0x%04x op=0x%04x dlen=0x%04x ret=0x%04x cookie_h=0x%08x cookie_l=0x%08x\n",
524 i, d->flags, d->opcode, d->datalen, d->retval,
525 d->cookie_high, d->cookie_low);
526 print_hex_dump(KERN_INFO, hdr, DUMP_PREFIX_NONE,
527 16, 1, d->params.raw, 16, 0);
528 }
529
530 dev_info(&pf->pdev->dev, "AdminQ Rx Ring\n");
531 ring = &(hw->aq.arq);
532 for (i = 0; i < ring->count; i++) {
533 struct i40e_aq_desc *d = I40E_ADMINQ_DESC(*ring, i);
534
535 dev_info(&pf->pdev->dev,
536 " ar[%02d] flags=0x%04x op=0x%04x dlen=0x%04x ret=0x%04x cookie_h=0x%08x cookie_l=0x%08x\n",
537 i, d->flags, d->opcode, d->datalen, d->retval,
538 d->cookie_high, d->cookie_low);
539 print_hex_dump(KERN_INFO, hdr, DUMP_PREFIX_NONE,
540 16, 1, d->params.raw, 16, 0);
541 }
542 }
543
544 /**
545 * i40e_dbg_dump_desc - handles dump desc write into command datum
546 * @cnt: number of arguments that the user supplied
547 * @vsi_seid: vsi id entered by user
548 * @ring_id: ring id entered by user
549 * @desc_n: descriptor number entered by user
550 * @pf: the i40e_pf created in command write
551 * @is_rx_ring: true if rx, false if tx
552 **/
553 static void i40e_dbg_dump_desc(int cnt, int vsi_seid, int ring_id, int desc_n,
554 struct i40e_pf *pf, bool is_rx_ring)
555 {
556 struct i40e_tx_desc *txd;
557 union i40e_rx_desc *rxd;
558 struct i40e_ring *ring;
559 struct i40e_vsi *vsi;
560 int i;
561
562 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
563 if (!vsi) {
564 dev_info(&pf->pdev->dev, "vsi %d not found\n", vsi_seid);
565 return;
566 }
567 if (ring_id >= vsi->num_queue_pairs || ring_id < 0) {
568 dev_info(&pf->pdev->dev, "ring %d not found\n", ring_id);
569 return;
570 }
571 if (!vsi->tx_rings || !vsi->tx_rings[0]->desc) {
572 dev_info(&pf->pdev->dev,
573 "descriptor rings have not been allocated for vsi %d\n",
574 vsi_seid);
575 return;
576 }
577
578 ring = kmemdup(is_rx_ring
579 ? vsi->rx_rings[ring_id] : vsi->tx_rings[ring_id],
580 sizeof(*ring), GFP_KERNEL);
581 if (!ring)
582 return;
583
584 if (cnt == 2) {
585 dev_info(&pf->pdev->dev, "vsi = %02i %s ring = %02i\n",
586 vsi_seid, is_rx_ring ? "rx" : "tx", ring_id);
587 for (i = 0; i < ring->count; i++) {
588 if (!is_rx_ring) {
589 txd = I40E_TX_DESC(ring, i);
590 dev_info(&pf->pdev->dev,
591 " d[%03x] = 0x%016llx 0x%016llx\n",
592 i, txd->buffer_addr,
593 txd->cmd_type_offset_bsz);
594 } else if (sizeof(union i40e_rx_desc) ==
595 sizeof(union i40e_16byte_rx_desc)) {
596 rxd = I40E_RX_DESC(ring, i);
597 dev_info(&pf->pdev->dev,
598 " d[%03x] = 0x%016llx 0x%016llx\n",
599 i, rxd->read.pkt_addr,
600 rxd->read.hdr_addr);
601 } else {
602 rxd = I40E_RX_DESC(ring, i);
603 dev_info(&pf->pdev->dev,
604 " d[%03x] = 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",
605 i, rxd->read.pkt_addr,
606 rxd->read.hdr_addr,
607 rxd->read.rsvd1, rxd->read.rsvd2);
608 }
609 }
610 } else if (cnt == 3) {
611 if (desc_n >= ring->count || desc_n < 0) {
612 dev_info(&pf->pdev->dev,
613 "descriptor %d not found\n", desc_n);
614 goto out;
615 }
616 if (!is_rx_ring) {
617 txd = I40E_TX_DESC(ring, desc_n);
618 dev_info(&pf->pdev->dev,
619 "vsi = %02i tx ring = %02i d[%03x] = 0x%016llx 0x%016llx\n",
620 vsi_seid, ring_id, desc_n,
621 txd->buffer_addr, txd->cmd_type_offset_bsz);
622 } else if (sizeof(union i40e_rx_desc) ==
623 sizeof(union i40e_16byte_rx_desc)) {
624 rxd = I40E_RX_DESC(ring, desc_n);
625 dev_info(&pf->pdev->dev,
626 "vsi = %02i rx ring = %02i d[%03x] = 0x%016llx 0x%016llx\n",
627 vsi_seid, ring_id, desc_n,
628 rxd->read.pkt_addr, rxd->read.hdr_addr);
629 } else {
630 rxd = I40E_RX_DESC(ring, desc_n);
631 dev_info(&pf->pdev->dev,
632 "vsi = %02i rx ring = %02i d[%03x] = 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",
633 vsi_seid, ring_id, desc_n,
634 rxd->read.pkt_addr, rxd->read.hdr_addr,
635 rxd->read.rsvd1, rxd->read.rsvd2);
636 }
637 } else {
638 dev_info(&pf->pdev->dev, "dump desc rx/tx <vsi_seid> <ring_id> [<desc_n>]\n");
639 }
640
641 out:
642 kfree(ring);
643 }
644
645 /**
646 * i40e_dbg_dump_vsi_no_seid - handles dump vsi write into command datum
647 * @pf: the i40e_pf created in command write
648 **/
649 static void i40e_dbg_dump_vsi_no_seid(struct i40e_pf *pf)
650 {
651 int i;
652
653 for (i = 0; i < pf->num_alloc_vsi; i++)
654 if (pf->vsi[i])
655 dev_info(&pf->pdev->dev, "dump vsi[%d]: %d\n",
656 i, pf->vsi[i]->seid);
657 }
658
659 /**
660 * i40e_dbg_dump_stats - handles dump stats write into command datum
661 * @pf: the i40e_pf created in command write
662 * @estats: the eth stats structure to be dumped
663 **/
664 static void i40e_dbg_dump_eth_stats(struct i40e_pf *pf,
665 struct i40e_eth_stats *estats)
666 {
667 dev_info(&pf->pdev->dev, " ethstats:\n");
668 dev_info(&pf->pdev->dev,
669 " rx_bytes = \t%lld \trx_unicast = \t\t%lld \trx_multicast = \t%lld\n",
670 estats->rx_bytes, estats->rx_unicast, estats->rx_multicast);
671 dev_info(&pf->pdev->dev,
672 " rx_broadcast = \t%lld \trx_discards = \t\t%lld\n",
673 estats->rx_broadcast, estats->rx_discards);
674 dev_info(&pf->pdev->dev,
675 " rx_unknown_protocol = \t%lld \ttx_bytes = \t%lld\n",
676 estats->rx_unknown_protocol, estats->tx_bytes);
677 dev_info(&pf->pdev->dev,
678 " tx_unicast = \t%lld \ttx_multicast = \t\t%lld \ttx_broadcast = \t%lld\n",
679 estats->tx_unicast, estats->tx_multicast, estats->tx_broadcast);
680 dev_info(&pf->pdev->dev,
681 " tx_discards = \t%lld \ttx_errors = \t\t%lld\n",
682 estats->tx_discards, estats->tx_errors);
683 }
684
685 /**
686 * i40e_dbg_dump_veb_seid - handles dump stats of a single given veb
687 * @pf: the i40e_pf created in command write
688 * @seid: the seid the user put in
689 **/
690 static void i40e_dbg_dump_veb_seid(struct i40e_pf *pf, int seid)
691 {
692 struct i40e_veb *veb;
693
694 veb = i40e_dbg_find_veb(pf, seid);
695 if (!veb) {
696 dev_info(&pf->pdev->dev, "can't find veb %d\n", seid);
697 return;
698 }
699 dev_info(&pf->pdev->dev,
700 "veb idx=%d,%d stats_ic=%d seid=%d uplink=%d mode=%s\n",
701 veb->idx, veb->veb_idx, veb->stats_idx, veb->seid,
702 veb->uplink_seid,
703 veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
704 i40e_dbg_dump_eth_stats(pf, &veb->stats);
705 }
706
707 /**
708 * i40e_dbg_dump_veb_all - dumps all known veb's stats
709 * @pf: the i40e_pf created in command write
710 **/
711 static void i40e_dbg_dump_veb_all(struct i40e_pf *pf)
712 {
713 struct i40e_veb *veb;
714 int i;
715
716 for (i = 0; i < I40E_MAX_VEB; i++) {
717 veb = pf->veb[i];
718 if (veb)
719 i40e_dbg_dump_veb_seid(pf, veb->seid);
720 }
721 }
722
723 #define I40E_MAX_DEBUG_OUT_BUFFER (4096*4)
724 /**
725 * i40e_dbg_command_write - write into command datum
726 * @filp: the opened file
727 * @buffer: where to find the user's data
728 * @count: the length of the user's data
729 * @ppos: file position offset
730 **/
731 static ssize_t i40e_dbg_command_write(struct file *filp,
732 const char __user *buffer,
733 size_t count, loff_t *ppos)
734 {
735 struct i40e_pf *pf = filp->private_data;
736 char *cmd_buf, *cmd_buf_tmp;
737 int bytes_not_copied;
738 struct i40e_vsi *vsi;
739 int vsi_seid;
740 int veb_seid;
741 int cnt;
742
743 /* don't allow partial writes */
744 if (*ppos != 0)
745 return 0;
746
747 cmd_buf = kzalloc(count + 1, GFP_KERNEL);
748 if (!cmd_buf)
749 return count;
750 bytes_not_copied = copy_from_user(cmd_buf, buffer, count);
751 if (bytes_not_copied) {
752 kfree(cmd_buf);
753 return -EFAULT;
754 }
755 cmd_buf[count] = '\0';
756
757 cmd_buf_tmp = strchr(cmd_buf, '\n');
758 if (cmd_buf_tmp) {
759 *cmd_buf_tmp = '\0';
760 count = cmd_buf_tmp - cmd_buf + 1;
761 }
762
763 if (strncmp(cmd_buf, "add vsi", 7) == 0) {
764 vsi_seid = -1;
765 cnt = sscanf(&cmd_buf[7], "%i", &vsi_seid);
766 if (cnt == 0) {
767 /* default to PF VSI */
768 vsi_seid = pf->vsi[pf->lan_vsi]->seid;
769 } else if (vsi_seid < 0) {
770 dev_info(&pf->pdev->dev, "add VSI %d: bad vsi seid\n",
771 vsi_seid);
772 goto command_write_done;
773 }
774
775 /* By default we are in VEPA mode, if this is the first VF/VMDq
776 * VSI to be added switch to VEB mode.
777 */
778 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
779 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
780 i40e_do_reset_safe(pf,
781 BIT_ULL(__I40E_PF_RESET_REQUESTED));
782 }
783
784 vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, vsi_seid, 0);
785 if (vsi)
786 dev_info(&pf->pdev->dev, "added VSI %d to relay %d\n",
787 vsi->seid, vsi->uplink_seid);
788 else
789 dev_info(&pf->pdev->dev, "'%s' failed\n", cmd_buf);
790
791 } else if (strncmp(cmd_buf, "del vsi", 7) == 0) {
792 cnt = sscanf(&cmd_buf[7], "%i", &vsi_seid);
793 if (cnt != 1) {
794 dev_info(&pf->pdev->dev,
795 "del vsi: bad command string, cnt=%d\n",
796 cnt);
797 goto command_write_done;
798 }
799 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
800 if (!vsi) {
801 dev_info(&pf->pdev->dev, "del VSI %d: seid not found\n",
802 vsi_seid);
803 goto command_write_done;
804 }
805
806 dev_info(&pf->pdev->dev, "deleting VSI %d\n", vsi_seid);
807 i40e_vsi_release(vsi);
808
809 } else if (strncmp(cmd_buf, "add relay", 9) == 0) {
810 struct i40e_veb *veb;
811 int uplink_seid, i;
812
813 cnt = sscanf(&cmd_buf[9], "%i %i", &uplink_seid, &vsi_seid);
814 if (cnt != 2) {
815 dev_info(&pf->pdev->dev,
816 "add relay: bad command string, cnt=%d\n",
817 cnt);
818 goto command_write_done;
819 } else if (uplink_seid < 0) {
820 dev_info(&pf->pdev->dev,
821 "add relay %d: bad uplink seid\n",
822 uplink_seid);
823 goto command_write_done;
824 }
825
826 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
827 if (!vsi) {
828 dev_info(&pf->pdev->dev,
829 "add relay: VSI %d not found\n", vsi_seid);
830 goto command_write_done;
831 }
832
833 for (i = 0; i < I40E_MAX_VEB; i++)
834 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid)
835 break;
836 if (i >= I40E_MAX_VEB && uplink_seid != 0 &&
837 uplink_seid != pf->mac_seid) {
838 dev_info(&pf->pdev->dev,
839 "add relay: relay uplink %d not found\n",
840 uplink_seid);
841 goto command_write_done;
842 }
843
844 veb = i40e_veb_setup(pf, 0, uplink_seid, vsi_seid,
845 vsi->tc_config.enabled_tc);
846 if (veb)
847 dev_info(&pf->pdev->dev, "added relay %d\n", veb->seid);
848 else
849 dev_info(&pf->pdev->dev, "add relay failed\n");
850
851 } else if (strncmp(cmd_buf, "del relay", 9) == 0) {
852 int i;
853 cnt = sscanf(&cmd_buf[9], "%i", &veb_seid);
854 if (cnt != 1) {
855 dev_info(&pf->pdev->dev,
856 "del relay: bad command string, cnt=%d\n",
857 cnt);
858 goto command_write_done;
859 } else if (veb_seid < 0) {
860 dev_info(&pf->pdev->dev,
861 "del relay %d: bad relay seid\n", veb_seid);
862 goto command_write_done;
863 }
864
865 /* find the veb */
866 for (i = 0; i < I40E_MAX_VEB; i++)
867 if (pf->veb[i] && pf->veb[i]->seid == veb_seid)
868 break;
869 if (i >= I40E_MAX_VEB) {
870 dev_info(&pf->pdev->dev,
871 "del relay: relay %d not found\n", veb_seid);
872 goto command_write_done;
873 }
874
875 dev_info(&pf->pdev->dev, "deleting relay %d\n", veb_seid);
876 i40e_veb_release(pf->veb[i]);
877
878 } else if (strncmp(cmd_buf, "add macaddr", 11) == 0) {
879 struct i40e_mac_filter *f;
880 int vlan = 0;
881 u8 ma[6];
882 int ret;
883
884 cnt = sscanf(&cmd_buf[11],
885 "%i %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %i",
886 &vsi_seid,
887 &ma[0], &ma[1], &ma[2], &ma[3], &ma[4], &ma[5],
888 &vlan);
889 if (cnt == 7) {
890 vlan = 0;
891 } else if (cnt != 8) {
892 dev_info(&pf->pdev->dev,
893 "add macaddr: bad command string, cnt=%d\n",
894 cnt);
895 goto command_write_done;
896 }
897
898 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
899 if (!vsi) {
900 dev_info(&pf->pdev->dev,
901 "add macaddr: VSI %d not found\n", vsi_seid);
902 goto command_write_done;
903 }
904
905 spin_lock_bh(&vsi->mac_filter_list_lock);
906 f = i40e_add_filter(vsi, ma, vlan, false, false);
907 spin_unlock_bh(&vsi->mac_filter_list_lock);
908 ret = i40e_sync_vsi_filters(vsi);
909 if (f && !ret)
910 dev_info(&pf->pdev->dev,
911 "add macaddr: %pM vlan=%d added to VSI %d\n",
912 ma, vlan, vsi_seid);
913 else
914 dev_info(&pf->pdev->dev,
915 "add macaddr: %pM vlan=%d to VSI %d failed, f=%p ret=%d\n",
916 ma, vlan, vsi_seid, f, ret);
917
918 } else if (strncmp(cmd_buf, "del macaddr", 11) == 0) {
919 int vlan = 0;
920 u8 ma[6];
921 int ret;
922
923 cnt = sscanf(&cmd_buf[11],
924 "%i %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %i",
925 &vsi_seid,
926 &ma[0], &ma[1], &ma[2], &ma[3], &ma[4], &ma[5],
927 &vlan);
928 if (cnt == 7) {
929 vlan = 0;
930 } else if (cnt != 8) {
931 dev_info(&pf->pdev->dev,
932 "del macaddr: bad command string, cnt=%d\n",
933 cnt);
934 goto command_write_done;
935 }
936
937 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
938 if (!vsi) {
939 dev_info(&pf->pdev->dev,
940 "del macaddr: VSI %d not found\n", vsi_seid);
941 goto command_write_done;
942 }
943
944 spin_lock_bh(&vsi->mac_filter_list_lock);
945 i40e_del_filter(vsi, ma, vlan, false, false);
946 spin_unlock_bh(&vsi->mac_filter_list_lock);
947 ret = i40e_sync_vsi_filters(vsi);
948 if (!ret)
949 dev_info(&pf->pdev->dev,
950 "del macaddr: %pM vlan=%d removed from VSI %d\n",
951 ma, vlan, vsi_seid);
952 else
953 dev_info(&pf->pdev->dev,
954 "del macaddr: %pM vlan=%d from VSI %d failed, ret=%d\n",
955 ma, vlan, vsi_seid, ret);
956
957 } else if (strncmp(cmd_buf, "add pvid", 8) == 0) {
958 i40e_status ret;
959 u16 vid;
960 unsigned int v;
961
962 cnt = sscanf(&cmd_buf[8], "%i %u", &vsi_seid, &v);
963 if (cnt != 2) {
964 dev_info(&pf->pdev->dev,
965 "add pvid: bad command string, cnt=%d\n", cnt);
966 goto command_write_done;
967 }
968
969 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
970 if (!vsi) {
971 dev_info(&pf->pdev->dev, "add pvid: VSI %d not found\n",
972 vsi_seid);
973 goto command_write_done;
974 }
975
976 vid = v;
977 ret = i40e_vsi_add_pvid(vsi, vid);
978 if (!ret)
979 dev_info(&pf->pdev->dev,
980 "add pvid: %d added to VSI %d\n",
981 vid, vsi_seid);
982 else
983 dev_info(&pf->pdev->dev,
984 "add pvid: %d to VSI %d failed, ret=%d\n",
985 vid, vsi_seid, ret);
986
987 } else if (strncmp(cmd_buf, "del pvid", 8) == 0) {
988
989 cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
990 if (cnt != 1) {
991 dev_info(&pf->pdev->dev,
992 "del pvid: bad command string, cnt=%d\n",
993 cnt);
994 goto command_write_done;
995 }
996
997 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
998 if (!vsi) {
999 dev_info(&pf->pdev->dev,
1000 "del pvid: VSI %d not found\n", vsi_seid);
1001 goto command_write_done;
1002 }
1003
1004 i40e_vsi_remove_pvid(vsi);
1005 dev_info(&pf->pdev->dev,
1006 "del pvid: removed from VSI %d\n", vsi_seid);
1007
1008 } else if (strncmp(cmd_buf, "dump", 4) == 0) {
1009 if (strncmp(&cmd_buf[5], "switch", 6) == 0) {
1010 i40e_fetch_switch_configuration(pf, true);
1011 } else if (strncmp(&cmd_buf[5], "vsi", 3) == 0) {
1012 cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
1013 if (cnt > 0)
1014 i40e_dbg_dump_vsi_seid(pf, vsi_seid);
1015 else
1016 i40e_dbg_dump_vsi_no_seid(pf);
1017 } else if (strncmp(&cmd_buf[5], "veb", 3) == 0) {
1018 cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
1019 if (cnt > 0)
1020 i40e_dbg_dump_veb_seid(pf, vsi_seid);
1021 else
1022 i40e_dbg_dump_veb_all(pf);
1023 } else if (strncmp(&cmd_buf[5], "desc", 4) == 0) {
1024 int ring_id, desc_n;
1025 if (strncmp(&cmd_buf[10], "rx", 2) == 0) {
1026 cnt = sscanf(&cmd_buf[12], "%i %i %i",
1027 &vsi_seid, &ring_id, &desc_n);
1028 i40e_dbg_dump_desc(cnt, vsi_seid, ring_id,
1029 desc_n, pf, true);
1030 } else if (strncmp(&cmd_buf[10], "tx", 2)
1031 == 0) {
1032 cnt = sscanf(&cmd_buf[12], "%i %i %i",
1033 &vsi_seid, &ring_id, &desc_n);
1034 i40e_dbg_dump_desc(cnt, vsi_seid, ring_id,
1035 desc_n, pf, false);
1036 } else if (strncmp(&cmd_buf[10], "aq", 2) == 0) {
1037 i40e_dbg_dump_aq_desc(pf);
1038 } else {
1039 dev_info(&pf->pdev->dev,
1040 "dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n");
1041 dev_info(&pf->pdev->dev,
1042 "dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n");
1043 dev_info(&pf->pdev->dev, "dump desc aq\n");
1044 }
1045 } else if (strncmp(&cmd_buf[5], "reset stats", 11) == 0) {
1046 dev_info(&pf->pdev->dev,
1047 "core reset count: %d\n", pf->corer_count);
1048 dev_info(&pf->pdev->dev,
1049 "global reset count: %d\n", pf->globr_count);
1050 dev_info(&pf->pdev->dev,
1051 "emp reset count: %d\n", pf->empr_count);
1052 dev_info(&pf->pdev->dev,
1053 "pf reset count: %d\n", pf->pfr_count);
1054 dev_info(&pf->pdev->dev,
1055 "pf tx sluggish count: %d\n",
1056 pf->tx_sluggish_count);
1057 } else if (strncmp(&cmd_buf[5], "port", 4) == 0) {
1058 struct i40e_aqc_query_port_ets_config_resp *bw_data;
1059 struct i40e_dcbx_config *cfg =
1060 &pf->hw.local_dcbx_config;
1061 struct i40e_dcbx_config *r_cfg =
1062 &pf->hw.remote_dcbx_config;
1063 int i, ret;
1064
1065 bw_data = kzalloc(sizeof(
1066 struct i40e_aqc_query_port_ets_config_resp),
1067 GFP_KERNEL);
1068 if (!bw_data) {
1069 ret = -ENOMEM;
1070 goto command_write_done;
1071 }
1072
1073 ret = i40e_aq_query_port_ets_config(&pf->hw,
1074 pf->mac_seid,
1075 bw_data, NULL);
1076 if (ret) {
1077 dev_info(&pf->pdev->dev,
1078 "Query Port ETS Config AQ command failed =0x%x\n",
1079 pf->hw.aq.asq_last_status);
1080 kfree(bw_data);
1081 bw_data = NULL;
1082 goto command_write_done;
1083 }
1084 dev_info(&pf->pdev->dev,
1085 "port bw: tc_valid=0x%x tc_strict_prio=0x%x, tc_bw_max=0x%04x,0x%04x\n",
1086 bw_data->tc_valid_bits,
1087 bw_data->tc_strict_priority_bits,
1088 le16_to_cpu(bw_data->tc_bw_max[0]),
1089 le16_to_cpu(bw_data->tc_bw_max[1]));
1090 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1091 dev_info(&pf->pdev->dev, "port bw: tc_bw_share=%d tc_bw_limit=%d\n",
1092 bw_data->tc_bw_share_credits[i],
1093 le16_to_cpu(bw_data->tc_bw_limits[i]));
1094 }
1095
1096 kfree(bw_data);
1097 bw_data = NULL;
1098
1099 dev_info(&pf->pdev->dev,
1100 "port dcbx_mode=%d\n", cfg->dcbx_mode);
1101 dev_info(&pf->pdev->dev,
1102 "port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n",
1103 cfg->etscfg.willing, cfg->etscfg.cbs,
1104 cfg->etscfg.maxtcs);
1105 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1106 dev_info(&pf->pdev->dev, "port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n",
1107 i, cfg->etscfg.prioritytable[i],
1108 cfg->etscfg.tcbwtable[i],
1109 cfg->etscfg.tsatable[i]);
1110 }
1111 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1112 dev_info(&pf->pdev->dev, "port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n",
1113 i, cfg->etsrec.prioritytable[i],
1114 cfg->etsrec.tcbwtable[i],
1115 cfg->etsrec.tsatable[i]);
1116 }
1117 dev_info(&pf->pdev->dev,
1118 "port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n",
1119 cfg->pfc.willing, cfg->pfc.mbc,
1120 cfg->pfc.pfccap, cfg->pfc.pfcenable);
1121 dev_info(&pf->pdev->dev,
1122 "port app_table: num_apps=%d\n", cfg->numapps);
1123 for (i = 0; i < cfg->numapps; i++) {
1124 dev_info(&pf->pdev->dev, "port app_table: %d prio=%d selector=%d protocol=0x%x\n",
1125 i, cfg->app[i].priority,
1126 cfg->app[i].selector,
1127 cfg->app[i].protocolid);
1128 }
1129 /* Peer TLV DCBX data */
1130 dev_info(&pf->pdev->dev,
1131 "remote port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n",
1132 r_cfg->etscfg.willing,
1133 r_cfg->etscfg.cbs, r_cfg->etscfg.maxtcs);
1134 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1135 dev_info(&pf->pdev->dev, "remote port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n",
1136 i, r_cfg->etscfg.prioritytable[i],
1137 r_cfg->etscfg.tcbwtable[i],
1138 r_cfg->etscfg.tsatable[i]);
1139 }
1140 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1141 dev_info(&pf->pdev->dev, "remote port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n",
1142 i, r_cfg->etsrec.prioritytable[i],
1143 r_cfg->etsrec.tcbwtable[i],
1144 r_cfg->etsrec.tsatable[i]);
1145 }
1146 dev_info(&pf->pdev->dev,
1147 "remote port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n",
1148 r_cfg->pfc.willing,
1149 r_cfg->pfc.mbc,
1150 r_cfg->pfc.pfccap,
1151 r_cfg->pfc.pfcenable);
1152 dev_info(&pf->pdev->dev,
1153 "remote port app_table: num_apps=%d\n",
1154 r_cfg->numapps);
1155 for (i = 0; i < r_cfg->numapps; i++) {
1156 dev_info(&pf->pdev->dev, "remote port app_table: %d prio=%d selector=%d protocol=0x%x\n",
1157 i, r_cfg->app[i].priority,
1158 r_cfg->app[i].selector,
1159 r_cfg->app[i].protocolid);
1160 }
1161 } else if (strncmp(&cmd_buf[5], "debug fwdata", 12) == 0) {
1162 int cluster_id, table_id;
1163 int index, ret;
1164 u16 buff_len = 4096;
1165 u32 next_index;
1166 u8 next_table;
1167 u8 *buff;
1168 u16 rlen;
1169
1170 cnt = sscanf(&cmd_buf[18], "%i %i %i",
1171 &cluster_id, &table_id, &index);
1172 if (cnt != 3) {
1173 dev_info(&pf->pdev->dev,
1174 "dump debug fwdata <cluster_id> <table_id> <index>\n");
1175 goto command_write_done;
1176 }
1177
1178 dev_info(&pf->pdev->dev,
1179 "AQ debug dump fwdata params %x %x %x %x\n",
1180 cluster_id, table_id, index, buff_len);
1181 buff = kzalloc(buff_len, GFP_KERNEL);
1182 if (!buff)
1183 goto command_write_done;
1184
1185 ret = i40e_aq_debug_dump(&pf->hw, cluster_id, table_id,
1186 index, buff_len, buff, &rlen,
1187 &next_table, &next_index,
1188 NULL);
1189 if (ret) {
1190 dev_info(&pf->pdev->dev,
1191 "debug dump fwdata AQ Failed %d 0x%x\n",
1192 ret, pf->hw.aq.asq_last_status);
1193 kfree(buff);
1194 buff = NULL;
1195 goto command_write_done;
1196 }
1197 dev_info(&pf->pdev->dev,
1198 "AQ debug dump fwdata rlen=0x%x next_table=0x%x next_index=0x%x\n",
1199 rlen, next_table, next_index);
1200 print_hex_dump(KERN_INFO, "AQ buffer WB: ",
1201 DUMP_PREFIX_OFFSET, 16, 1,
1202 buff, rlen, true);
1203 kfree(buff);
1204 buff = NULL;
1205 } else {
1206 dev_info(&pf->pdev->dev,
1207 "dump desc tx <vsi_seid> <ring_id> [<desc_n>], dump desc rx <vsi_seid> <ring_id> [<desc_n>],\n");
1208 dev_info(&pf->pdev->dev, "dump switch\n");
1209 dev_info(&pf->pdev->dev, "dump vsi [seid]\n");
1210 dev_info(&pf->pdev->dev, "dump reset stats\n");
1211 dev_info(&pf->pdev->dev, "dump port\n");
1212 dev_info(&pf->pdev->dev,
1213 "dump debug fwdata <cluster_id> <table_id> <index>\n");
1214 }
1215
1216 } else if (strncmp(cmd_buf, "msg_enable", 10) == 0) {
1217 u32 level;
1218 cnt = sscanf(&cmd_buf[10], "%i", &level);
1219 if (cnt) {
1220 if (I40E_DEBUG_USER & level) {
1221 pf->hw.debug_mask = level;
1222 dev_info(&pf->pdev->dev,
1223 "set hw.debug_mask = 0x%08x\n",
1224 pf->hw.debug_mask);
1225 }
1226 pf->msg_enable = level;
1227 dev_info(&pf->pdev->dev, "set msg_enable = 0x%08x\n",
1228 pf->msg_enable);
1229 } else {
1230 dev_info(&pf->pdev->dev, "msg_enable = 0x%08x\n",
1231 pf->msg_enable);
1232 }
1233 } else if (strncmp(cmd_buf, "pfr", 3) == 0) {
1234 dev_info(&pf->pdev->dev, "debugfs: forcing PFR\n");
1235 i40e_do_reset_safe(pf, BIT(__I40E_PF_RESET_REQUESTED));
1236
1237 } else if (strncmp(cmd_buf, "corer", 5) == 0) {
1238 dev_info(&pf->pdev->dev, "debugfs: forcing CoreR\n");
1239 i40e_do_reset_safe(pf, BIT(__I40E_CORE_RESET_REQUESTED));
1240
1241 } else if (strncmp(cmd_buf, "globr", 5) == 0) {
1242 dev_info(&pf->pdev->dev, "debugfs: forcing GlobR\n");
1243 i40e_do_reset_safe(pf, BIT(__I40E_GLOBAL_RESET_REQUESTED));
1244
1245 } else if (strncmp(cmd_buf, "empr", 4) == 0) {
1246 dev_info(&pf->pdev->dev, "debugfs: forcing EMPR\n");
1247 i40e_do_reset_safe(pf, BIT(__I40E_EMP_RESET_REQUESTED));
1248
1249 } else if (strncmp(cmd_buf, "read", 4) == 0) {
1250 u32 address;
1251 u32 value;
1252
1253 cnt = sscanf(&cmd_buf[4], "%i", &address);
1254 if (cnt != 1) {
1255 dev_info(&pf->pdev->dev, "read <reg>\n");
1256 goto command_write_done;
1257 }
1258
1259 /* check the range on address */
1260 if (address > (pf->ioremap_len - sizeof(u32))) {
1261 dev_info(&pf->pdev->dev, "read reg address 0x%08x too large, max=0x%08lx\n",
1262 address, (unsigned long int)(pf->ioremap_len - sizeof(u32)));
1263 goto command_write_done;
1264 }
1265
1266 value = rd32(&pf->hw, address);
1267 dev_info(&pf->pdev->dev, "read: 0x%08x = 0x%08x\n",
1268 address, value);
1269
1270 } else if (strncmp(cmd_buf, "write", 5) == 0) {
1271 u32 address, value;
1272
1273 cnt = sscanf(&cmd_buf[5], "%i %i", &address, &value);
1274 if (cnt != 2) {
1275 dev_info(&pf->pdev->dev, "write <reg> <value>\n");
1276 goto command_write_done;
1277 }
1278
1279 /* check the range on address */
1280 if (address > (pf->ioremap_len - sizeof(u32))) {
1281 dev_info(&pf->pdev->dev, "write reg address 0x%08x too large, max=0x%08lx\n",
1282 address, (unsigned long int)(pf->ioremap_len - sizeof(u32)));
1283 goto command_write_done;
1284 }
1285 wr32(&pf->hw, address, value);
1286 value = rd32(&pf->hw, address);
1287 dev_info(&pf->pdev->dev, "write: 0x%08x = 0x%08x\n",
1288 address, value);
1289 } else if (strncmp(cmd_buf, "clear_stats", 11) == 0) {
1290 if (strncmp(&cmd_buf[12], "vsi", 3) == 0) {
1291 cnt = sscanf(&cmd_buf[15], "%i", &vsi_seid);
1292 if (cnt == 0) {
1293 int i;
1294
1295 for (i = 0; i < pf->num_alloc_vsi; i++)
1296 i40e_vsi_reset_stats(pf->vsi[i]);
1297 dev_info(&pf->pdev->dev, "vsi clear stats called for all vsi's\n");
1298 } else if (cnt == 1) {
1299 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1300 if (!vsi) {
1301 dev_info(&pf->pdev->dev,
1302 "clear_stats vsi: bad vsi %d\n",
1303 vsi_seid);
1304 goto command_write_done;
1305 }
1306 i40e_vsi_reset_stats(vsi);
1307 dev_info(&pf->pdev->dev,
1308 "vsi clear stats called for vsi %d\n",
1309 vsi_seid);
1310 } else {
1311 dev_info(&pf->pdev->dev, "clear_stats vsi [seid]\n");
1312 }
1313 } else if (strncmp(&cmd_buf[12], "port", 4) == 0) {
1314 if (pf->hw.partition_id == 1) {
1315 i40e_pf_reset_stats(pf);
1316 dev_info(&pf->pdev->dev, "port stats cleared\n");
1317 } else {
1318 dev_info(&pf->pdev->dev, "clear port stats not allowed on this port partition\n");
1319 }
1320 } else {
1321 dev_info(&pf->pdev->dev, "clear_stats vsi [seid] or clear_stats port\n");
1322 }
1323 } else if (strncmp(cmd_buf, "send aq_cmd", 11) == 0) {
1324 struct i40e_aq_desc *desc;
1325 i40e_status ret;
1326
1327 desc = kzalloc(sizeof(struct i40e_aq_desc), GFP_KERNEL);
1328 if (!desc)
1329 goto command_write_done;
1330 cnt = sscanf(&cmd_buf[11],
1331 "%hi %hi %hi %hi %i %i %i %i %i %i",
1332 &desc->flags,
1333 &desc->opcode, &desc->datalen, &desc->retval,
1334 &desc->cookie_high, &desc->cookie_low,
1335 &desc->params.internal.param0,
1336 &desc->params.internal.param1,
1337 &desc->params.internal.param2,
1338 &desc->params.internal.param3);
1339 if (cnt != 10) {
1340 dev_info(&pf->pdev->dev,
1341 "send aq_cmd: bad command string, cnt=%d\n",
1342 cnt);
1343 kfree(desc);
1344 desc = NULL;
1345 goto command_write_done;
1346 }
1347 ret = i40e_asq_send_command(&pf->hw, desc, NULL, 0, NULL);
1348 if (!ret) {
1349 dev_info(&pf->pdev->dev, "AQ command sent Status : Success\n");
1350 } else if (ret == I40E_ERR_ADMIN_QUEUE_ERROR) {
1351 dev_info(&pf->pdev->dev,
1352 "AQ command send failed Opcode %x AQ Error: %d\n",
1353 desc->opcode, pf->hw.aq.asq_last_status);
1354 } else {
1355 dev_info(&pf->pdev->dev,
1356 "AQ command send failed Opcode %x Status: %d\n",
1357 desc->opcode, ret);
1358 }
1359 dev_info(&pf->pdev->dev,
1360 "AQ desc WB 0x%04x 0x%04x 0x%04x 0x%04x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
1361 desc->flags, desc->opcode, desc->datalen, desc->retval,
1362 desc->cookie_high, desc->cookie_low,
1363 desc->params.internal.param0,
1364 desc->params.internal.param1,
1365 desc->params.internal.param2,
1366 desc->params.internal.param3);
1367 kfree(desc);
1368 desc = NULL;
1369 } else if (strncmp(cmd_buf, "send indirect aq_cmd", 20) == 0) {
1370 struct i40e_aq_desc *desc;
1371 i40e_status ret;
1372 u16 buffer_len;
1373 u8 *buff;
1374
1375 desc = kzalloc(sizeof(struct i40e_aq_desc), GFP_KERNEL);
1376 if (!desc)
1377 goto command_write_done;
1378 cnt = sscanf(&cmd_buf[20],
1379 "%hi %hi %hi %hi %i %i %i %i %i %i %hi",
1380 &desc->flags,
1381 &desc->opcode, &desc->datalen, &desc->retval,
1382 &desc->cookie_high, &desc->cookie_low,
1383 &desc->params.internal.param0,
1384 &desc->params.internal.param1,
1385 &desc->params.internal.param2,
1386 &desc->params.internal.param3,
1387 &buffer_len);
1388 if (cnt != 11) {
1389 dev_info(&pf->pdev->dev,
1390 "send indirect aq_cmd: bad command string, cnt=%d\n",
1391 cnt);
1392 kfree(desc);
1393 desc = NULL;
1394 goto command_write_done;
1395 }
1396 /* Just stub a buffer big enough in case user messed up */
1397 if (buffer_len == 0)
1398 buffer_len = 1280;
1399
1400 buff = kzalloc(buffer_len, GFP_KERNEL);
1401 if (!buff) {
1402 kfree(desc);
1403 desc = NULL;
1404 goto command_write_done;
1405 }
1406 desc->flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
1407 ret = i40e_asq_send_command(&pf->hw, desc, buff,
1408 buffer_len, NULL);
1409 if (!ret) {
1410 dev_info(&pf->pdev->dev, "AQ command sent Status : Success\n");
1411 } else if (ret == I40E_ERR_ADMIN_QUEUE_ERROR) {
1412 dev_info(&pf->pdev->dev,
1413 "AQ command send failed Opcode %x AQ Error: %d\n",
1414 desc->opcode, pf->hw.aq.asq_last_status);
1415 } else {
1416 dev_info(&pf->pdev->dev,
1417 "AQ command send failed Opcode %x Status: %d\n",
1418 desc->opcode, ret);
1419 }
1420 dev_info(&pf->pdev->dev,
1421 "AQ desc WB 0x%04x 0x%04x 0x%04x 0x%04x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
1422 desc->flags, desc->opcode, desc->datalen, desc->retval,
1423 desc->cookie_high, desc->cookie_low,
1424 desc->params.internal.param0,
1425 desc->params.internal.param1,
1426 desc->params.internal.param2,
1427 desc->params.internal.param3);
1428 print_hex_dump(KERN_INFO, "AQ buffer WB: ",
1429 DUMP_PREFIX_OFFSET, 16, 1,
1430 buff, buffer_len, true);
1431 kfree(buff);
1432 buff = NULL;
1433 kfree(desc);
1434 desc = NULL;
1435 } else if ((strncmp(cmd_buf, "add fd_filter", 13) == 0) ||
1436 (strncmp(cmd_buf, "rem fd_filter", 13) == 0)) {
1437 struct i40e_fdir_filter fd_data;
1438 u16 packet_len, i, j = 0;
1439 char *asc_packet;
1440 u8 *raw_packet;
1441 bool add = false;
1442 int ret;
1443
1444 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
1445 goto command_write_done;
1446
1447 if (strncmp(cmd_buf, "add", 3) == 0)
1448 add = true;
1449
1450 if (add && (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED))
1451 goto command_write_done;
1452
1453 asc_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_SIZE,
1454 GFP_KERNEL);
1455 if (!asc_packet)
1456 goto command_write_done;
1457
1458 raw_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_SIZE,
1459 GFP_KERNEL);
1460
1461 if (!raw_packet) {
1462 kfree(asc_packet);
1463 asc_packet = NULL;
1464 goto command_write_done;
1465 }
1466
1467 cnt = sscanf(&cmd_buf[13],
1468 "%hx %2hhx %2hhx %hx %2hhx %2hhx %hx %x %hd %511s",
1469 &fd_data.q_index,
1470 &fd_data.flex_off, &fd_data.pctype,
1471 &fd_data.dest_vsi, &fd_data.dest_ctl,
1472 &fd_data.fd_status, &fd_data.cnt_index,
1473 &fd_data.fd_id, &packet_len, asc_packet);
1474 if (cnt != 10) {
1475 dev_info(&pf->pdev->dev,
1476 "program fd_filter: bad command string, cnt=%d\n",
1477 cnt);
1478 kfree(asc_packet);
1479 asc_packet = NULL;
1480 kfree(raw_packet);
1481 goto command_write_done;
1482 }
1483
1484 /* fix packet length if user entered 0 */
1485 if (packet_len == 0)
1486 packet_len = I40E_FDIR_MAX_RAW_PACKET_SIZE;
1487
1488 /* make sure to check the max as well */
1489 packet_len = min_t(u16,
1490 packet_len, I40E_FDIR_MAX_RAW_PACKET_SIZE);
1491
1492 for (i = 0; i < packet_len; i++) {
1493 cnt = sscanf(&asc_packet[j], "%2hhx ", &raw_packet[i]);
1494 if (!cnt)
1495 break;
1496 j += 3;
1497 }
1498 dev_info(&pf->pdev->dev, "FD raw packet dump\n");
1499 print_hex_dump(KERN_INFO, "FD raw packet: ",
1500 DUMP_PREFIX_OFFSET, 16, 1,
1501 raw_packet, packet_len, true);
1502 ret = i40e_program_fdir_filter(&fd_data, raw_packet, pf, add);
1503 if (!ret) {
1504 dev_info(&pf->pdev->dev, "Filter command send Status : Success\n");
1505 } else {
1506 dev_info(&pf->pdev->dev,
1507 "Filter command send failed %d\n", ret);
1508 }
1509 kfree(raw_packet);
1510 raw_packet = NULL;
1511 kfree(asc_packet);
1512 asc_packet = NULL;
1513 } else if (strncmp(cmd_buf, "fd current cnt", 14) == 0) {
1514 dev_info(&pf->pdev->dev, "FD current total filter count for this interface: %d\n",
1515 i40e_get_current_fd_count(pf));
1516 } else if (strncmp(cmd_buf, "lldp", 4) == 0) {
1517 if (strncmp(&cmd_buf[5], "stop", 4) == 0) {
1518 int ret;
1519
1520 ret = i40e_aq_stop_lldp(&pf->hw, false, NULL);
1521 if (ret) {
1522 dev_info(&pf->pdev->dev,
1523 "Stop LLDP AQ command failed =0x%x\n",
1524 pf->hw.aq.asq_last_status);
1525 goto command_write_done;
1526 }
1527 ret = i40e_aq_add_rem_control_packet_filter(&pf->hw,
1528 pf->hw.mac.addr,
1529 I40E_ETH_P_LLDP, 0,
1530 pf->vsi[pf->lan_vsi]->seid,
1531 0, true, NULL, NULL);
1532 if (ret) {
1533 dev_info(&pf->pdev->dev,
1534 "%s: Add Control Packet Filter AQ command failed =0x%x\n",
1535 __func__, pf->hw.aq.asq_last_status);
1536 goto command_write_done;
1537 }
1538 #ifdef CONFIG_I40E_DCB
1539 pf->dcbx_cap = DCB_CAP_DCBX_HOST |
1540 DCB_CAP_DCBX_VER_IEEE;
1541 #endif /* CONFIG_I40E_DCB */
1542 } else if (strncmp(&cmd_buf[5], "start", 5) == 0) {
1543 int ret;
1544
1545 ret = i40e_aq_add_rem_control_packet_filter(&pf->hw,
1546 pf->hw.mac.addr,
1547 I40E_ETH_P_LLDP, 0,
1548 pf->vsi[pf->lan_vsi]->seid,
1549 0, false, NULL, NULL);
1550 if (ret) {
1551 dev_info(&pf->pdev->dev,
1552 "%s: Remove Control Packet Filter AQ command failed =0x%x\n",
1553 __func__, pf->hw.aq.asq_last_status);
1554 /* Continue and start FW LLDP anyways */
1555 }
1556
1557 ret = i40e_aq_start_lldp(&pf->hw, NULL);
1558 if (ret) {
1559 dev_info(&pf->pdev->dev,
1560 "Start LLDP AQ command failed =0x%x\n",
1561 pf->hw.aq.asq_last_status);
1562 goto command_write_done;
1563 }
1564 #ifdef CONFIG_I40E_DCB
1565 pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
1566 DCB_CAP_DCBX_VER_IEEE;
1567 #endif /* CONFIG_I40E_DCB */
1568 } else if (strncmp(&cmd_buf[5],
1569 "get local", 9) == 0) {
1570 u16 llen, rlen;
1571 int ret;
1572 u8 *buff;
1573
1574 buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL);
1575 if (!buff)
1576 goto command_write_done;
1577
1578 ret = i40e_aq_get_lldp_mib(&pf->hw, 0,
1579 I40E_AQ_LLDP_MIB_LOCAL,
1580 buff, I40E_LLDPDU_SIZE,
1581 &llen, &rlen, NULL);
1582 if (ret) {
1583 dev_info(&pf->pdev->dev,
1584 "Get LLDP MIB (local) AQ command failed =0x%x\n",
1585 pf->hw.aq.asq_last_status);
1586 kfree(buff);
1587 buff = NULL;
1588 goto command_write_done;
1589 }
1590 dev_info(&pf->pdev->dev, "LLDP MIB (local)\n");
1591 print_hex_dump(KERN_INFO, "LLDP MIB (local): ",
1592 DUMP_PREFIX_OFFSET, 16, 1,
1593 buff, I40E_LLDPDU_SIZE, true);
1594 kfree(buff);
1595 buff = NULL;
1596 } else if (strncmp(&cmd_buf[5], "get remote", 10) == 0) {
1597 u16 llen, rlen;
1598 int ret;
1599 u8 *buff;
1600
1601 buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL);
1602 if (!buff)
1603 goto command_write_done;
1604
1605 ret = i40e_aq_get_lldp_mib(&pf->hw,
1606 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
1607 I40E_AQ_LLDP_MIB_REMOTE,
1608 buff, I40E_LLDPDU_SIZE,
1609 &llen, &rlen, NULL);
1610 if (ret) {
1611 dev_info(&pf->pdev->dev,
1612 "Get LLDP MIB (remote) AQ command failed =0x%x\n",
1613 pf->hw.aq.asq_last_status);
1614 kfree(buff);
1615 buff = NULL;
1616 goto command_write_done;
1617 }
1618 dev_info(&pf->pdev->dev, "LLDP MIB (remote)\n");
1619 print_hex_dump(KERN_INFO, "LLDP MIB (remote): ",
1620 DUMP_PREFIX_OFFSET, 16, 1,
1621 buff, I40E_LLDPDU_SIZE, true);
1622 kfree(buff);
1623 buff = NULL;
1624 } else if (strncmp(&cmd_buf[5], "event on", 8) == 0) {
1625 int ret;
1626
1627 ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw,
1628 true, NULL);
1629 if (ret) {
1630 dev_info(&pf->pdev->dev,
1631 "Config LLDP MIB Change Event (on) AQ command failed =0x%x\n",
1632 pf->hw.aq.asq_last_status);
1633 goto command_write_done;
1634 }
1635 } else if (strncmp(&cmd_buf[5], "event off", 9) == 0) {
1636 int ret;
1637
1638 ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw,
1639 false, NULL);
1640 if (ret) {
1641 dev_info(&pf->pdev->dev,
1642 "Config LLDP MIB Change Event (off) AQ command failed =0x%x\n",
1643 pf->hw.aq.asq_last_status);
1644 goto command_write_done;
1645 }
1646 }
1647 } else if (strncmp(cmd_buf, "nvm read", 8) == 0) {
1648 u16 buffer_len, bytes;
1649 u16 module;
1650 u32 offset;
1651 u16 *buff;
1652 int ret;
1653
1654 cnt = sscanf(&cmd_buf[8], "%hx %x %hx",
1655 &module, &offset, &buffer_len);
1656 if (cnt == 0) {
1657 module = 0;
1658 offset = 0;
1659 buffer_len = 0;
1660 } else if (cnt == 1) {
1661 offset = 0;
1662 buffer_len = 0;
1663 } else if (cnt == 2) {
1664 buffer_len = 0;
1665 } else if (cnt > 3) {
1666 dev_info(&pf->pdev->dev,
1667 "nvm read: bad command string, cnt=%d\n", cnt);
1668 goto command_write_done;
1669 }
1670
1671 /* set the max length */
1672 buffer_len = min_t(u16, buffer_len, I40E_MAX_AQ_BUF_SIZE/2);
1673
1674 bytes = 2 * buffer_len;
1675
1676 /* read at least 1k bytes, no more than 4kB */
1677 bytes = clamp(bytes, (u16)1024, (u16)I40E_MAX_AQ_BUF_SIZE);
1678 buff = kzalloc(bytes, GFP_KERNEL);
1679 if (!buff)
1680 goto command_write_done;
1681
1682 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
1683 if (ret) {
1684 dev_info(&pf->pdev->dev,
1685 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1686 ret, pf->hw.aq.asq_last_status);
1687 kfree(buff);
1688 goto command_write_done;
1689 }
1690
1691 ret = i40e_aq_read_nvm(&pf->hw, module, (2 * offset),
1692 bytes, (u8 *)buff, true, NULL);
1693 i40e_release_nvm(&pf->hw);
1694 if (ret) {
1695 dev_info(&pf->pdev->dev,
1696 "Read NVM AQ failed err=%d status=0x%x\n",
1697 ret, pf->hw.aq.asq_last_status);
1698 } else {
1699 dev_info(&pf->pdev->dev,
1700 "Read NVM module=0x%x offset=0x%x words=%d\n",
1701 module, offset, buffer_len);
1702 if (bytes)
1703 print_hex_dump(KERN_INFO, "NVM Dump: ",
1704 DUMP_PREFIX_OFFSET, 16, 2,
1705 buff, bytes, true);
1706 }
1707 kfree(buff);
1708 buff = NULL;
1709 } else {
1710 dev_info(&pf->pdev->dev, "unknown command '%s'\n", cmd_buf);
1711 dev_info(&pf->pdev->dev, "available commands\n");
1712 dev_info(&pf->pdev->dev, " add vsi [relay_seid]\n");
1713 dev_info(&pf->pdev->dev, " del vsi [vsi_seid]\n");
1714 dev_info(&pf->pdev->dev, " add relay <uplink_seid> <vsi_seid>\n");
1715 dev_info(&pf->pdev->dev, " del relay <relay_seid>\n");
1716 dev_info(&pf->pdev->dev, " add macaddr <vsi_seid> <aa:bb:cc:dd:ee:ff> [vlan]\n");
1717 dev_info(&pf->pdev->dev, " del macaddr <vsi_seid> <aa:bb:cc:dd:ee:ff> [vlan]\n");
1718 dev_info(&pf->pdev->dev, " add pvid <vsi_seid> <vid>\n");
1719 dev_info(&pf->pdev->dev, " del pvid <vsi_seid>\n");
1720 dev_info(&pf->pdev->dev, " dump switch\n");
1721 dev_info(&pf->pdev->dev, " dump vsi [seid]\n");
1722 dev_info(&pf->pdev->dev, " dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n");
1723 dev_info(&pf->pdev->dev, " dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n");
1724 dev_info(&pf->pdev->dev, " dump desc aq\n");
1725 dev_info(&pf->pdev->dev, " dump reset stats\n");
1726 dev_info(&pf->pdev->dev, " dump debug fwdata <cluster_id> <table_id> <index>\n");
1727 dev_info(&pf->pdev->dev, " msg_enable [level]\n");
1728 dev_info(&pf->pdev->dev, " read <reg>\n");
1729 dev_info(&pf->pdev->dev, " write <reg> <value>\n");
1730 dev_info(&pf->pdev->dev, " clear_stats vsi [seid]\n");
1731 dev_info(&pf->pdev->dev, " clear_stats port\n");
1732 dev_info(&pf->pdev->dev, " pfr\n");
1733 dev_info(&pf->pdev->dev, " corer\n");
1734 dev_info(&pf->pdev->dev, " globr\n");
1735 dev_info(&pf->pdev->dev, " send aq_cmd <flags> <opcode> <datalen> <retval> <cookie_h> <cookie_l> <param0> <param1> <param2> <param3>\n");
1736 dev_info(&pf->pdev->dev, " send indirect aq_cmd <flags> <opcode> <datalen> <retval> <cookie_h> <cookie_l> <param0> <param1> <param2> <param3> <buffer_len>\n");
1737 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");
1738 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");
1739 dev_info(&pf->pdev->dev, " fd current cnt");
1740 dev_info(&pf->pdev->dev, " lldp start\n");
1741 dev_info(&pf->pdev->dev, " lldp stop\n");
1742 dev_info(&pf->pdev->dev, " lldp get local\n");
1743 dev_info(&pf->pdev->dev, " lldp get remote\n");
1744 dev_info(&pf->pdev->dev, " lldp event on\n");
1745 dev_info(&pf->pdev->dev, " lldp event off\n");
1746 dev_info(&pf->pdev->dev, " nvm read [module] [word_offset] [word_count]\n");
1747 }
1748
1749 command_write_done:
1750 kfree(cmd_buf);
1751 cmd_buf = NULL;
1752 return count;
1753 }
1754
1755 static const struct file_operations i40e_dbg_command_fops = {
1756 .owner = THIS_MODULE,
1757 .open = simple_open,
1758 .read = i40e_dbg_command_read,
1759 .write = i40e_dbg_command_write,
1760 };
1761
1762 /**************************************************************
1763 * netdev_ops
1764 * The netdev_ops entry in debugfs is for giving the driver commands
1765 * to be executed from the netdev operations.
1766 **************************************************************/
1767 static char i40e_dbg_netdev_ops_buf[256] = "";
1768
1769 /**
1770 * i40e_dbg_netdev_ops - read for netdev_ops datum
1771 * @filp: the opened file
1772 * @buffer: where to write the data for the user to read
1773 * @count: the size of the user's buffer
1774 * @ppos: file position offset
1775 **/
1776 static ssize_t i40e_dbg_netdev_ops_read(struct file *filp, char __user *buffer,
1777 size_t count, loff_t *ppos)
1778 {
1779 struct i40e_pf *pf = filp->private_data;
1780 int bytes_not_copied;
1781 int buf_size = 256;
1782 char *buf;
1783 int len;
1784
1785 /* don't allow partal reads */
1786 if (*ppos != 0)
1787 return 0;
1788 if (count < buf_size)
1789 return -ENOSPC;
1790
1791 buf = kzalloc(buf_size, GFP_KERNEL);
1792 if (!buf)
1793 return -ENOSPC;
1794
1795 len = snprintf(buf, buf_size, "%s: %s\n",
1796 pf->vsi[pf->lan_vsi]->netdev->name,
1797 i40e_dbg_netdev_ops_buf);
1798
1799 bytes_not_copied = copy_to_user(buffer, buf, len);
1800 kfree(buf);
1801
1802 if (bytes_not_copied)
1803 return -EFAULT;
1804
1805 *ppos = len;
1806 return len;
1807 }
1808
1809 /**
1810 * i40e_dbg_netdev_ops_write - write into netdev_ops datum
1811 * @filp: the opened file
1812 * @buffer: where to find the user's data
1813 * @count: the length of the user's data
1814 * @ppos: file position offset
1815 **/
1816 static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
1817 const char __user *buffer,
1818 size_t count, loff_t *ppos)
1819 {
1820 struct i40e_pf *pf = filp->private_data;
1821 int bytes_not_copied;
1822 struct i40e_vsi *vsi;
1823 char *buf_tmp;
1824 int vsi_seid;
1825 int i, cnt;
1826
1827 /* don't allow partial writes */
1828 if (*ppos != 0)
1829 return 0;
1830 if (count >= sizeof(i40e_dbg_netdev_ops_buf))
1831 return -ENOSPC;
1832
1833 memset(i40e_dbg_netdev_ops_buf, 0, sizeof(i40e_dbg_netdev_ops_buf));
1834 bytes_not_copied = copy_from_user(i40e_dbg_netdev_ops_buf,
1835 buffer, count);
1836 if (bytes_not_copied)
1837 return -EFAULT;
1838 i40e_dbg_netdev_ops_buf[count] = '\0';
1839
1840 buf_tmp = strchr(i40e_dbg_netdev_ops_buf, '\n');
1841 if (buf_tmp) {
1842 *buf_tmp = '\0';
1843 count = buf_tmp - i40e_dbg_netdev_ops_buf + 1;
1844 }
1845
1846 if (strncmp(i40e_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) {
1847 cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid);
1848 if (cnt != 1) {
1849 dev_info(&pf->pdev->dev, "tx_timeout <vsi_seid>\n");
1850 goto netdev_ops_write_done;
1851 }
1852 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1853 if (!vsi) {
1854 dev_info(&pf->pdev->dev,
1855 "tx_timeout: VSI %d not found\n", vsi_seid);
1856 } else if (!vsi->netdev) {
1857 dev_info(&pf->pdev->dev, "tx_timeout: no netdev for VSI %d\n",
1858 vsi_seid);
1859 } else if (test_bit(__I40E_DOWN, &vsi->state)) {
1860 dev_info(&pf->pdev->dev, "tx_timeout: VSI %d not UP\n",
1861 vsi_seid);
1862 } else if (rtnl_trylock()) {
1863 vsi->netdev->netdev_ops->ndo_tx_timeout(vsi->netdev);
1864 rtnl_unlock();
1865 dev_info(&pf->pdev->dev, "tx_timeout called\n");
1866 } else {
1867 dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
1868 }
1869 } else if (strncmp(i40e_dbg_netdev_ops_buf, "change_mtu", 10) == 0) {
1870 int mtu;
1871
1872 cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i %i",
1873 &vsi_seid, &mtu);
1874 if (cnt != 2) {
1875 dev_info(&pf->pdev->dev, "change_mtu <vsi_seid> <mtu>\n");
1876 goto netdev_ops_write_done;
1877 }
1878 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1879 if (!vsi) {
1880 dev_info(&pf->pdev->dev,
1881 "change_mtu: VSI %d not found\n", vsi_seid);
1882 } else if (!vsi->netdev) {
1883 dev_info(&pf->pdev->dev, "change_mtu: no netdev for VSI %d\n",
1884 vsi_seid);
1885 } else if (rtnl_trylock()) {
1886 vsi->netdev->netdev_ops->ndo_change_mtu(vsi->netdev,
1887 mtu);
1888 rtnl_unlock();
1889 dev_info(&pf->pdev->dev, "change_mtu called\n");
1890 } else {
1891 dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
1892 }
1893
1894 } else if (strncmp(i40e_dbg_netdev_ops_buf, "set_rx_mode", 11) == 0) {
1895 cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid);
1896 if (cnt != 1) {
1897 dev_info(&pf->pdev->dev, "set_rx_mode <vsi_seid>\n");
1898 goto netdev_ops_write_done;
1899 }
1900 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1901 if (!vsi) {
1902 dev_info(&pf->pdev->dev,
1903 "set_rx_mode: VSI %d not found\n", vsi_seid);
1904 } else if (!vsi->netdev) {
1905 dev_info(&pf->pdev->dev, "set_rx_mode: no netdev for VSI %d\n",
1906 vsi_seid);
1907 } else if (rtnl_trylock()) {
1908 vsi->netdev->netdev_ops->ndo_set_rx_mode(vsi->netdev);
1909 rtnl_unlock();
1910 dev_info(&pf->pdev->dev, "set_rx_mode called\n");
1911 } else {
1912 dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
1913 }
1914
1915 } else if (strncmp(i40e_dbg_netdev_ops_buf, "napi", 4) == 0) {
1916 cnt = sscanf(&i40e_dbg_netdev_ops_buf[4], "%i", &vsi_seid);
1917 if (cnt != 1) {
1918 dev_info(&pf->pdev->dev, "napi <vsi_seid>\n");
1919 goto netdev_ops_write_done;
1920 }
1921 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1922 if (!vsi) {
1923 dev_info(&pf->pdev->dev, "napi: VSI %d not found\n",
1924 vsi_seid);
1925 } else if (!vsi->netdev) {
1926 dev_info(&pf->pdev->dev, "napi: no netdev for VSI %d\n",
1927 vsi_seid);
1928 } else {
1929 for (i = 0; i < vsi->num_q_vectors; i++)
1930 napi_schedule(&vsi->q_vectors[i]->napi);
1931 dev_info(&pf->pdev->dev, "napi called\n");
1932 }
1933 } else {
1934 dev_info(&pf->pdev->dev, "unknown command '%s'\n",
1935 i40e_dbg_netdev_ops_buf);
1936 dev_info(&pf->pdev->dev, "available commands\n");
1937 dev_info(&pf->pdev->dev, " tx_timeout <vsi_seid>\n");
1938 dev_info(&pf->pdev->dev, " change_mtu <vsi_seid> <mtu>\n");
1939 dev_info(&pf->pdev->dev, " set_rx_mode <vsi_seid>\n");
1940 dev_info(&pf->pdev->dev, " napi <vsi_seid>\n");
1941 }
1942 netdev_ops_write_done:
1943 return count;
1944 }
1945
1946 static const struct file_operations i40e_dbg_netdev_ops_fops = {
1947 .owner = THIS_MODULE,
1948 .open = simple_open,
1949 .read = i40e_dbg_netdev_ops_read,
1950 .write = i40e_dbg_netdev_ops_write,
1951 };
1952
1953 /**
1954 * i40e_dbg_pf_init - setup the debugfs directory for the PF
1955 * @pf: the PF that is starting up
1956 **/
1957 void i40e_dbg_pf_init(struct i40e_pf *pf)
1958 {
1959 struct dentry *pfile;
1960 const char *name = pci_name(pf->pdev);
1961 const struct device *dev = &pf->pdev->dev;
1962
1963 pf->i40e_dbg_pf = debugfs_create_dir(name, i40e_dbg_root);
1964 if (!pf->i40e_dbg_pf)
1965 return;
1966
1967 pfile = debugfs_create_file("command", 0600, pf->i40e_dbg_pf, pf,
1968 &i40e_dbg_command_fops);
1969 if (!pfile)
1970 goto create_failed;
1971
1972 pfile = debugfs_create_file("netdev_ops", 0600, pf->i40e_dbg_pf, pf,
1973 &i40e_dbg_netdev_ops_fops);
1974 if (!pfile)
1975 goto create_failed;
1976
1977 return;
1978
1979 create_failed:
1980 dev_info(dev, "debugfs dir/file for %s failed\n", name);
1981 debugfs_remove_recursive(pf->i40e_dbg_pf);
1982 }
1983
1984 /**
1985 * i40e_dbg_pf_exit - clear out the PF's debugfs entries
1986 * @pf: the PF that is stopping
1987 **/
1988 void i40e_dbg_pf_exit(struct i40e_pf *pf)
1989 {
1990 debugfs_remove_recursive(pf->i40e_dbg_pf);
1991 pf->i40e_dbg_pf = NULL;
1992 }
1993
1994 /**
1995 * i40e_dbg_init - start up debugfs for the driver
1996 **/
1997 void i40e_dbg_init(void)
1998 {
1999 i40e_dbg_root = debugfs_create_dir(i40e_driver_name, NULL);
2000 if (!i40e_dbg_root)
2001 pr_info("init of debugfs failed\n");
2002 }
2003
2004 /**
2005 * i40e_dbg_exit - clean out the driver's debugfs entries
2006 **/
2007 void i40e_dbg_exit(void)
2008 {
2009 debugfs_remove_recursive(i40e_dbg_root);
2010 i40e_dbg_root = NULL;
2011 }
2012
2013 #endif /* CONFIG_DEBUG_FS */