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