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