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