1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) 2 /* QLogic qede NIC Driver 3 * Copyright (c) 2015-2017 QLogic Corporation 4 * Copyright (c) 2019-2020 Marvell International Ltd. 5 */ 6 7 #include <linux/types.h> 8 #include <linux/netdevice.h> 9 #include <linux/etherdevice.h> 10 #include <linux/ethtool.h> 11 #include <linux/string.h> 12 #include <linux/pci.h> 13 #include <linux/capability.h> 14 #include <linux/vmalloc.h> 15 #include <linux/phylink.h> 16 17 #include "qede.h" 18 #include "qede_ptp.h" 19 20 #define QEDE_RQSTAT_OFFSET(stat_name) \ 21 (offsetof(struct qede_rx_queue, stat_name)) 22 #define QEDE_RQSTAT_STRING(stat_name) (#stat_name) 23 #define QEDE_RQSTAT(stat_name) \ 24 {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)} 25 26 #define QEDE_SELFTEST_POLL_COUNT 100 27 #define QEDE_DUMP_VERSION 0x1 28 #define QEDE_DUMP_NVM_ARG_COUNT 2 29 30 static const struct { 31 u64 offset; 32 char string[ETH_GSTRING_LEN]; 33 } qede_rqstats_arr[] = { 34 QEDE_RQSTAT(rcv_pkts), 35 QEDE_RQSTAT(rx_hw_errors), 36 QEDE_RQSTAT(rx_alloc_errors), 37 QEDE_RQSTAT(rx_ip_frags), 38 QEDE_RQSTAT(xdp_no_pass), 39 }; 40 41 #define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr) 42 #define QEDE_TQSTAT_OFFSET(stat_name) \ 43 (offsetof(struct qede_tx_queue, stat_name)) 44 #define QEDE_TQSTAT_STRING(stat_name) (#stat_name) 45 #define QEDE_TQSTAT(stat_name) \ 46 {QEDE_TQSTAT_OFFSET(stat_name), QEDE_TQSTAT_STRING(stat_name)} 47 #define QEDE_NUM_TQSTATS ARRAY_SIZE(qede_tqstats_arr) 48 static const struct { 49 u64 offset; 50 char string[ETH_GSTRING_LEN]; 51 } qede_tqstats_arr[] = { 52 QEDE_TQSTAT(xmit_pkts), 53 QEDE_TQSTAT(stopped_cnt), 54 QEDE_TQSTAT(tx_mem_alloc_err), 55 }; 56 57 #define QEDE_STAT_OFFSET(stat_name, type, base) \ 58 (offsetof(type, stat_name) + (base)) 59 #define QEDE_STAT_STRING(stat_name) (#stat_name) 60 #define _QEDE_STAT(stat_name, type, base, attr) \ 61 {QEDE_STAT_OFFSET(stat_name, type, base), \ 62 QEDE_STAT_STRING(stat_name), \ 63 attr} 64 #define QEDE_STAT(stat_name) \ 65 _QEDE_STAT(stat_name, struct qede_stats_common, 0, 0x0) 66 #define QEDE_PF_STAT(stat_name) \ 67 _QEDE_STAT(stat_name, struct qede_stats_common, 0, \ 68 BIT(QEDE_STAT_PF_ONLY)) 69 #define QEDE_PF_BB_STAT(stat_name) \ 70 _QEDE_STAT(stat_name, struct qede_stats_bb, \ 71 offsetof(struct qede_stats, bb), \ 72 BIT(QEDE_STAT_PF_ONLY) | BIT(QEDE_STAT_BB_ONLY)) 73 #define QEDE_PF_AH_STAT(stat_name) \ 74 _QEDE_STAT(stat_name, struct qede_stats_ah, \ 75 offsetof(struct qede_stats, ah), \ 76 BIT(QEDE_STAT_PF_ONLY) | BIT(QEDE_STAT_AH_ONLY)) 77 static const struct { 78 u64 offset; 79 char string[ETH_GSTRING_LEN]; 80 unsigned long attr; 81 #define QEDE_STAT_PF_ONLY 0 82 #define QEDE_STAT_BB_ONLY 1 83 #define QEDE_STAT_AH_ONLY 2 84 } qede_stats_arr[] = { 85 QEDE_STAT(rx_ucast_bytes), 86 QEDE_STAT(rx_mcast_bytes), 87 QEDE_STAT(rx_bcast_bytes), 88 QEDE_STAT(rx_ucast_pkts), 89 QEDE_STAT(rx_mcast_pkts), 90 QEDE_STAT(rx_bcast_pkts), 91 92 QEDE_STAT(tx_ucast_bytes), 93 QEDE_STAT(tx_mcast_bytes), 94 QEDE_STAT(tx_bcast_bytes), 95 QEDE_STAT(tx_ucast_pkts), 96 QEDE_STAT(tx_mcast_pkts), 97 QEDE_STAT(tx_bcast_pkts), 98 99 QEDE_PF_STAT(rx_64_byte_packets), 100 QEDE_PF_STAT(rx_65_to_127_byte_packets), 101 QEDE_PF_STAT(rx_128_to_255_byte_packets), 102 QEDE_PF_STAT(rx_256_to_511_byte_packets), 103 QEDE_PF_STAT(rx_512_to_1023_byte_packets), 104 QEDE_PF_STAT(rx_1024_to_1518_byte_packets), 105 QEDE_PF_BB_STAT(rx_1519_to_1522_byte_packets), 106 QEDE_PF_BB_STAT(rx_1519_to_2047_byte_packets), 107 QEDE_PF_BB_STAT(rx_2048_to_4095_byte_packets), 108 QEDE_PF_BB_STAT(rx_4096_to_9216_byte_packets), 109 QEDE_PF_BB_STAT(rx_9217_to_16383_byte_packets), 110 QEDE_PF_AH_STAT(rx_1519_to_max_byte_packets), 111 QEDE_PF_STAT(tx_64_byte_packets), 112 QEDE_PF_STAT(tx_65_to_127_byte_packets), 113 QEDE_PF_STAT(tx_128_to_255_byte_packets), 114 QEDE_PF_STAT(tx_256_to_511_byte_packets), 115 QEDE_PF_STAT(tx_512_to_1023_byte_packets), 116 QEDE_PF_STAT(tx_1024_to_1518_byte_packets), 117 QEDE_PF_BB_STAT(tx_1519_to_2047_byte_packets), 118 QEDE_PF_BB_STAT(tx_2048_to_4095_byte_packets), 119 QEDE_PF_BB_STAT(tx_4096_to_9216_byte_packets), 120 QEDE_PF_BB_STAT(tx_9217_to_16383_byte_packets), 121 QEDE_PF_AH_STAT(tx_1519_to_max_byte_packets), 122 QEDE_PF_STAT(rx_mac_crtl_frames), 123 QEDE_PF_STAT(tx_mac_ctrl_frames), 124 QEDE_PF_STAT(rx_pause_frames), 125 QEDE_PF_STAT(tx_pause_frames), 126 QEDE_PF_STAT(rx_pfc_frames), 127 QEDE_PF_STAT(tx_pfc_frames), 128 129 QEDE_PF_STAT(rx_crc_errors), 130 QEDE_PF_STAT(rx_align_errors), 131 QEDE_PF_STAT(rx_carrier_errors), 132 QEDE_PF_STAT(rx_oversize_packets), 133 QEDE_PF_STAT(rx_jabbers), 134 QEDE_PF_STAT(rx_undersize_packets), 135 QEDE_PF_STAT(rx_fragments), 136 QEDE_PF_BB_STAT(tx_lpi_entry_count), 137 QEDE_PF_BB_STAT(tx_total_collisions), 138 QEDE_PF_STAT(brb_truncates), 139 QEDE_PF_STAT(brb_discards), 140 QEDE_STAT(no_buff_discards), 141 QEDE_PF_STAT(mftag_filter_discards), 142 QEDE_PF_STAT(mac_filter_discards), 143 QEDE_PF_STAT(gft_filter_drop), 144 QEDE_STAT(tx_err_drop_pkts), 145 QEDE_STAT(ttl0_discard), 146 QEDE_STAT(packet_too_big_discard), 147 148 QEDE_STAT(coalesced_pkts), 149 QEDE_STAT(coalesced_events), 150 QEDE_STAT(coalesced_aborts_num), 151 QEDE_STAT(non_coalesced_pkts), 152 QEDE_STAT(coalesced_bytes), 153 154 QEDE_STAT(link_change_count), 155 QEDE_STAT(ptp_skip_txts), 156 }; 157 158 #define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr) 159 #define QEDE_STAT_IS_PF_ONLY(i) \ 160 test_bit(QEDE_STAT_PF_ONLY, &qede_stats_arr[i].attr) 161 #define QEDE_STAT_IS_BB_ONLY(i) \ 162 test_bit(QEDE_STAT_BB_ONLY, &qede_stats_arr[i].attr) 163 #define QEDE_STAT_IS_AH_ONLY(i) \ 164 test_bit(QEDE_STAT_AH_ONLY, &qede_stats_arr[i].attr) 165 166 enum { 167 QEDE_PRI_FLAG_CMT, 168 QEDE_PRI_FLAG_SMART_AN_SUPPORT, /* MFW supports SmartAN */ 169 QEDE_PRI_FLAG_RECOVER_ON_ERROR, 170 QEDE_PRI_FLAG_ESL_SUPPORT, /* MFW supports Enhanced System Lockdown */ 171 QEDE_PRI_FLAG_ESL_ACTIVE, /* Enhanced System Lockdown Active status */ 172 QEDE_PRI_FLAG_LEN, 173 }; 174 175 static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = { 176 "Coupled-Function", 177 "SmartAN capable", 178 "Recover on error", 179 "ESL capable", 180 "ESL active", 181 }; 182 183 enum qede_ethtool_tests { 184 QEDE_ETHTOOL_INT_LOOPBACK, 185 QEDE_ETHTOOL_INTERRUPT_TEST, 186 QEDE_ETHTOOL_MEMORY_TEST, 187 QEDE_ETHTOOL_REGISTER_TEST, 188 QEDE_ETHTOOL_CLOCK_TEST, 189 QEDE_ETHTOOL_NVRAM_TEST, 190 QEDE_ETHTOOL_TEST_MAX 191 }; 192 193 static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = { 194 "Internal loopback (offline)", 195 "Interrupt (online)\t", 196 "Memory (online)\t\t", 197 "Register (online)\t", 198 "Clock (online)\t\t", 199 "Nvram (online)\t\t", 200 }; 201 202 /* Forced speed capabilities maps */ 203 204 struct qede_forced_speed_map { 205 u32 speed; 206 __ETHTOOL_DECLARE_LINK_MODE_MASK(caps); 207 208 const u32 *cap_arr; 209 u32 arr_size; 210 }; 211 212 #define QEDE_FORCED_SPEED_MAP(value) \ 213 { \ 214 .speed = SPEED_##value, \ 215 .cap_arr = qede_forced_speed_##value, \ 216 .arr_size = ARRAY_SIZE(qede_forced_speed_##value), \ 217 } 218 219 static const u32 qede_forced_speed_1000[] __initconst = { 220 ETHTOOL_LINK_MODE_1000baseT_Full_BIT, 221 ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, 222 ETHTOOL_LINK_MODE_1000baseX_Full_BIT, 223 }; 224 225 static const u32 qede_forced_speed_10000[] __initconst = { 226 ETHTOOL_LINK_MODE_10000baseT_Full_BIT, 227 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT, 228 ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT, 229 ETHTOOL_LINK_MODE_10000baseR_FEC_BIT, 230 ETHTOOL_LINK_MODE_10000baseCR_Full_BIT, 231 ETHTOOL_LINK_MODE_10000baseSR_Full_BIT, 232 ETHTOOL_LINK_MODE_10000baseLR_Full_BIT, 233 ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT, 234 }; 235 236 static const u32 qede_forced_speed_20000[] __initconst = { 237 ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT, 238 }; 239 240 static const u32 qede_forced_speed_25000[] __initconst = { 241 ETHTOOL_LINK_MODE_25000baseKR_Full_BIT, 242 ETHTOOL_LINK_MODE_25000baseCR_Full_BIT, 243 ETHTOOL_LINK_MODE_25000baseSR_Full_BIT, 244 }; 245 246 static const u32 qede_forced_speed_40000[] __initconst = { 247 ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT, 248 ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT, 249 ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT, 250 ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT, 251 }; 252 253 static const u32 qede_forced_speed_50000[] __initconst = { 254 ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT, 255 ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT, 256 ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT, 257 }; 258 259 static const u32 qede_forced_speed_100000[] __initconst = { 260 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT, 261 ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT, 262 ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT, 263 ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT, 264 }; 265 266 static struct qede_forced_speed_map qede_forced_speed_maps[] __ro_after_init = { 267 QEDE_FORCED_SPEED_MAP(1000), 268 QEDE_FORCED_SPEED_MAP(10000), 269 QEDE_FORCED_SPEED_MAP(20000), 270 QEDE_FORCED_SPEED_MAP(25000), 271 QEDE_FORCED_SPEED_MAP(40000), 272 QEDE_FORCED_SPEED_MAP(50000), 273 QEDE_FORCED_SPEED_MAP(100000), 274 }; 275 276 void __init qede_forced_speed_maps_init(void) 277 { 278 struct qede_forced_speed_map *map; 279 u32 i; 280 281 for (i = 0; i < ARRAY_SIZE(qede_forced_speed_maps); i++) { 282 map = qede_forced_speed_maps + i; 283 284 linkmode_set_bit_array(map->cap_arr, map->arr_size, map->caps); 285 map->cap_arr = NULL; 286 map->arr_size = 0; 287 } 288 } 289 290 /* Ethtool callbacks */ 291 292 static void qede_get_strings_stats_txq(struct qede_dev *edev, 293 struct qede_tx_queue *txq, u8 **buf) 294 { 295 int i; 296 297 for (i = 0; i < QEDE_NUM_TQSTATS; i++) { 298 if (txq->is_xdp) 299 sprintf(*buf, "%d [XDP]: %s", 300 QEDE_TXQ_XDP_TO_IDX(edev, txq), 301 qede_tqstats_arr[i].string); 302 else 303 sprintf(*buf, "%d_%d: %s", txq->index, txq->cos, 304 qede_tqstats_arr[i].string); 305 *buf += ETH_GSTRING_LEN; 306 } 307 } 308 309 static void qede_get_strings_stats_rxq(struct qede_dev *edev, 310 struct qede_rx_queue *rxq, u8 **buf) 311 { 312 int i; 313 314 for (i = 0; i < QEDE_NUM_RQSTATS; i++) { 315 sprintf(*buf, "%d: %s", rxq->rxq_id, 316 qede_rqstats_arr[i].string); 317 *buf += ETH_GSTRING_LEN; 318 } 319 } 320 321 static bool qede_is_irrelevant_stat(struct qede_dev *edev, int stat_index) 322 { 323 return (IS_VF(edev) && QEDE_STAT_IS_PF_ONLY(stat_index)) || 324 (QEDE_IS_BB(edev) && QEDE_STAT_IS_AH_ONLY(stat_index)) || 325 (QEDE_IS_AH(edev) && QEDE_STAT_IS_BB_ONLY(stat_index)); 326 } 327 328 static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf) 329 { 330 struct qede_fastpath *fp; 331 int i; 332 333 /* Account for queue statistics */ 334 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) { 335 fp = &edev->fp_array[i]; 336 337 if (fp->type & QEDE_FASTPATH_RX) 338 qede_get_strings_stats_rxq(edev, fp->rxq, &buf); 339 340 if (fp->type & QEDE_FASTPATH_XDP) 341 qede_get_strings_stats_txq(edev, fp->xdp_tx, &buf); 342 343 if (fp->type & QEDE_FASTPATH_TX) { 344 int cos; 345 346 for_each_cos_in_txq(edev, cos) 347 qede_get_strings_stats_txq(edev, 348 &fp->txq[cos], &buf); 349 } 350 } 351 352 /* Account for non-queue statistics */ 353 for (i = 0; i < QEDE_NUM_STATS; i++) { 354 if (qede_is_irrelevant_stat(edev, i)) 355 continue; 356 strcpy(buf, qede_stats_arr[i].string); 357 buf += ETH_GSTRING_LEN; 358 } 359 } 360 361 static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf) 362 { 363 struct qede_dev *edev = netdev_priv(dev); 364 365 switch (stringset) { 366 case ETH_SS_STATS: 367 qede_get_strings_stats(edev, buf); 368 break; 369 case ETH_SS_PRIV_FLAGS: 370 memcpy(buf, qede_private_arr, 371 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN); 372 break; 373 case ETH_SS_TEST: 374 memcpy(buf, qede_tests_str_arr, 375 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX); 376 break; 377 default: 378 DP_VERBOSE(edev, QED_MSG_DEBUG, 379 "Unsupported stringset 0x%08x\n", stringset); 380 } 381 } 382 383 static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf) 384 { 385 int i; 386 387 for (i = 0; i < QEDE_NUM_TQSTATS; i++) { 388 **buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset)); 389 (*buf)++; 390 } 391 } 392 393 static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf) 394 { 395 int i; 396 397 for (i = 0; i < QEDE_NUM_RQSTATS; i++) { 398 **buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset)); 399 (*buf)++; 400 } 401 } 402 403 static void qede_get_ethtool_stats(struct net_device *dev, 404 struct ethtool_stats *stats, u64 *buf) 405 { 406 struct qede_dev *edev = netdev_priv(dev); 407 struct qede_fastpath *fp; 408 int i; 409 410 qede_fill_by_demand_stats(edev); 411 412 /* Need to protect the access to the fastpath array */ 413 __qede_lock(edev); 414 415 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) { 416 fp = &edev->fp_array[i]; 417 418 if (fp->type & QEDE_FASTPATH_RX) 419 qede_get_ethtool_stats_rxq(fp->rxq, &buf); 420 421 if (fp->type & QEDE_FASTPATH_XDP) 422 qede_get_ethtool_stats_txq(fp->xdp_tx, &buf); 423 424 if (fp->type & QEDE_FASTPATH_TX) { 425 int cos; 426 427 for_each_cos_in_txq(edev, cos) 428 qede_get_ethtool_stats_txq(&fp->txq[cos], &buf); 429 } 430 } 431 432 for (i = 0; i < QEDE_NUM_STATS; i++) { 433 if (qede_is_irrelevant_stat(edev, i)) 434 continue; 435 *buf = *((u64 *)(((void *)&edev->stats) + 436 qede_stats_arr[i].offset)); 437 438 buf++; 439 } 440 441 __qede_unlock(edev); 442 } 443 444 static int qede_get_sset_count(struct net_device *dev, int stringset) 445 { 446 struct qede_dev *edev = netdev_priv(dev); 447 int num_stats = QEDE_NUM_STATS, i; 448 449 switch (stringset) { 450 case ETH_SS_STATS: 451 for (i = 0; i < QEDE_NUM_STATS; i++) 452 if (qede_is_irrelevant_stat(edev, i)) 453 num_stats--; 454 455 /* Account for the Regular Tx statistics */ 456 num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS * 457 edev->dev_info.num_tc; 458 459 /* Account for the Regular Rx statistics */ 460 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS; 461 462 /* Account for XDP statistics [if needed] */ 463 if (edev->xdp_prog) 464 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_TQSTATS; 465 return num_stats; 466 467 case ETH_SS_PRIV_FLAGS: 468 return QEDE_PRI_FLAG_LEN; 469 case ETH_SS_TEST: 470 if (!IS_VF(edev)) 471 return QEDE_ETHTOOL_TEST_MAX; 472 else 473 return 0; 474 default: 475 DP_VERBOSE(edev, QED_MSG_DEBUG, 476 "Unsupported stringset 0x%08x\n", stringset); 477 return -EINVAL; 478 } 479 } 480 481 static u32 qede_get_priv_flags(struct net_device *dev) 482 { 483 struct qede_dev *edev = netdev_priv(dev); 484 bool esl_active; 485 u32 flags = 0; 486 487 if (edev->dev_info.common.num_hwfns > 1) 488 flags |= BIT(QEDE_PRI_FLAG_CMT); 489 490 if (edev->dev_info.common.smart_an) 491 flags |= BIT(QEDE_PRI_FLAG_SMART_AN_SUPPORT); 492 493 if (edev->err_flags & BIT(QEDE_ERR_IS_RECOVERABLE)) 494 flags |= BIT(QEDE_PRI_FLAG_RECOVER_ON_ERROR); 495 496 if (edev->dev_info.common.esl) 497 flags |= BIT(QEDE_PRI_FLAG_ESL_SUPPORT); 498 499 edev->ops->common->get_esl_status(edev->cdev, &esl_active); 500 501 if (esl_active) 502 flags |= BIT(QEDE_PRI_FLAG_ESL_ACTIVE); 503 504 return flags; 505 } 506 507 static int qede_set_priv_flags(struct net_device *dev, u32 flags) 508 { 509 struct qede_dev *edev = netdev_priv(dev); 510 u32 cflags = qede_get_priv_flags(dev); 511 u32 dflags = flags ^ cflags; 512 513 /* can only change RECOVER_ON_ERROR flag */ 514 if (dflags & ~BIT(QEDE_PRI_FLAG_RECOVER_ON_ERROR)) 515 return -EINVAL; 516 517 if (flags & BIT(QEDE_PRI_FLAG_RECOVER_ON_ERROR)) 518 set_bit(QEDE_ERR_IS_RECOVERABLE, &edev->err_flags); 519 else 520 clear_bit(QEDE_ERR_IS_RECOVERABLE, &edev->err_flags); 521 522 return 0; 523 } 524 525 static int qede_get_link_ksettings(struct net_device *dev, 526 struct ethtool_link_ksettings *cmd) 527 { 528 typeof(cmd->link_modes) *link_modes = &cmd->link_modes; 529 struct ethtool_link_settings *base = &cmd->base; 530 struct qede_dev *edev = netdev_priv(dev); 531 struct qed_link_output current_link; 532 533 __qede_lock(edev); 534 535 memset(¤t_link, 0, sizeof(current_link)); 536 edev->ops->common->get_link(edev->cdev, ¤t_link); 537 538 linkmode_copy(link_modes->supported, current_link.supported_caps); 539 linkmode_copy(link_modes->advertising, current_link.advertised_caps); 540 linkmode_copy(link_modes->lp_advertising, current_link.lp_caps); 541 542 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) { 543 base->speed = current_link.speed; 544 base->duplex = current_link.duplex; 545 } else { 546 base->speed = SPEED_UNKNOWN; 547 base->duplex = DUPLEX_UNKNOWN; 548 } 549 550 __qede_unlock(edev); 551 552 base->port = current_link.port; 553 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE : 554 AUTONEG_DISABLE; 555 556 return 0; 557 } 558 559 static int qede_set_link_ksettings(struct net_device *dev, 560 const struct ethtool_link_ksettings *cmd) 561 { 562 const struct ethtool_link_settings *base = &cmd->base; 563 struct qede_dev *edev = netdev_priv(dev); 564 const struct qede_forced_speed_map *map; 565 struct qed_link_output current_link; 566 struct qed_link_params params; 567 u32 i; 568 569 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) { 570 DP_INFO(edev, "Link settings are not allowed to be changed\n"); 571 return -EOPNOTSUPP; 572 } 573 memset(¤t_link, 0, sizeof(current_link)); 574 memset(¶ms, 0, sizeof(params)); 575 edev->ops->common->get_link(edev->cdev, ¤t_link); 576 577 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS; 578 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG; 579 580 if (base->autoneg == AUTONEG_ENABLE) { 581 if (!phylink_test(current_link.supported_caps, Autoneg)) { 582 DP_INFO(edev, "Auto negotiation is not supported\n"); 583 return -EOPNOTSUPP; 584 } 585 586 params.autoneg = true; 587 params.forced_speed = 0; 588 589 linkmode_copy(params.adv_speeds, cmd->link_modes.advertising); 590 } else { /* forced speed */ 591 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED; 592 params.autoneg = false; 593 params.forced_speed = base->speed; 594 595 for (i = 0; i < ARRAY_SIZE(qede_forced_speed_maps); i++) { 596 map = qede_forced_speed_maps + i; 597 598 if (base->speed != map->speed || 599 !linkmode_intersects(current_link.supported_caps, 600 map->caps)) 601 continue; 602 603 linkmode_and(params.adv_speeds, 604 current_link.supported_caps, map->caps); 605 goto set_link; 606 } 607 608 DP_INFO(edev, "Unsupported speed %u\n", base->speed); 609 return -EINVAL; 610 } 611 612 set_link: 613 params.link_up = true; 614 edev->ops->common->set_link(edev->cdev, ¶ms); 615 616 return 0; 617 } 618 619 static void qede_get_drvinfo(struct net_device *ndev, 620 struct ethtool_drvinfo *info) 621 { 622 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN]; 623 struct qede_dev *edev = netdev_priv(ndev); 624 char mbi[ETHTOOL_FWVERS_LEN]; 625 626 strscpy(info->driver, "qede", sizeof(info->driver)); 627 628 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d", 629 edev->dev_info.common.fw_major, 630 edev->dev_info.common.fw_minor, 631 edev->dev_info.common.fw_rev, 632 edev->dev_info.common.fw_eng); 633 634 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d", 635 (edev->dev_info.common.mfw_rev >> 24) & 0xFF, 636 (edev->dev_info.common.mfw_rev >> 16) & 0xFF, 637 (edev->dev_info.common.mfw_rev >> 8) & 0xFF, 638 edev->dev_info.common.mfw_rev & 0xFF); 639 640 if ((strlen(storm) + strlen("[storm]")) < 641 sizeof(info->version)) 642 snprintf(info->version, sizeof(info->version), 643 "[storm %s]", storm); 644 else 645 snprintf(info->version, sizeof(info->version), 646 "%s", storm); 647 648 if (edev->dev_info.common.mbi_version) { 649 snprintf(mbi, ETHTOOL_FWVERS_LEN, "%d.%d.%d", 650 (edev->dev_info.common.mbi_version & 651 QED_MBI_VERSION_2_MASK) >> QED_MBI_VERSION_2_OFFSET, 652 (edev->dev_info.common.mbi_version & 653 QED_MBI_VERSION_1_MASK) >> QED_MBI_VERSION_1_OFFSET, 654 (edev->dev_info.common.mbi_version & 655 QED_MBI_VERSION_0_MASK) >> QED_MBI_VERSION_0_OFFSET); 656 snprintf(info->fw_version, sizeof(info->fw_version), 657 "mbi %s [mfw %s]", mbi, mfw); 658 } else { 659 snprintf(info->fw_version, sizeof(info->fw_version), 660 "mfw %s", mfw); 661 } 662 663 strscpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info)); 664 } 665 666 static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) 667 { 668 struct qede_dev *edev = netdev_priv(ndev); 669 670 if (edev->dev_info.common.wol_support) { 671 wol->supported = WAKE_MAGIC; 672 wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0; 673 } 674 } 675 676 static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) 677 { 678 struct qede_dev *edev = netdev_priv(ndev); 679 bool wol_requested; 680 int rc; 681 682 if (wol->wolopts & ~WAKE_MAGIC) { 683 DP_INFO(edev, 684 "Can't support WoL options other than magic-packet\n"); 685 return -EINVAL; 686 } 687 688 wol_requested = !!(wol->wolopts & WAKE_MAGIC); 689 if (wol_requested == edev->wol_enabled) 690 return 0; 691 692 /* Need to actually change configuration */ 693 if (!edev->dev_info.common.wol_support) { 694 DP_INFO(edev, "Device doesn't support WoL\n"); 695 return -EINVAL; 696 } 697 698 rc = edev->ops->common->update_wol(edev->cdev, wol_requested); 699 if (!rc) 700 edev->wol_enabled = wol_requested; 701 702 return rc; 703 } 704 705 static u32 qede_get_msglevel(struct net_device *ndev) 706 { 707 struct qede_dev *edev = netdev_priv(ndev); 708 709 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module; 710 } 711 712 static void qede_set_msglevel(struct net_device *ndev, u32 level) 713 { 714 struct qede_dev *edev = netdev_priv(ndev); 715 u32 dp_module = 0; 716 u8 dp_level = 0; 717 718 qede_config_debug(level, &dp_module, &dp_level); 719 720 edev->dp_level = dp_level; 721 edev->dp_module = dp_module; 722 edev->ops->common->update_msglvl(edev->cdev, 723 dp_module, dp_level); 724 } 725 726 static int qede_nway_reset(struct net_device *dev) 727 { 728 struct qede_dev *edev = netdev_priv(dev); 729 struct qed_link_output current_link; 730 struct qed_link_params link_params; 731 732 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) { 733 DP_INFO(edev, "Link settings are not allowed to be changed\n"); 734 return -EOPNOTSUPP; 735 } 736 737 if (!netif_running(dev)) 738 return 0; 739 740 memset(¤t_link, 0, sizeof(current_link)); 741 edev->ops->common->get_link(edev->cdev, ¤t_link); 742 if (!current_link.link_up) 743 return 0; 744 745 /* Toggle the link */ 746 memset(&link_params, 0, sizeof(link_params)); 747 link_params.link_up = false; 748 edev->ops->common->set_link(edev->cdev, &link_params); 749 link_params.link_up = true; 750 edev->ops->common->set_link(edev->cdev, &link_params); 751 752 return 0; 753 } 754 755 static u32 qede_get_link(struct net_device *dev) 756 { 757 struct qede_dev *edev = netdev_priv(dev); 758 struct qed_link_output current_link; 759 760 memset(¤t_link, 0, sizeof(current_link)); 761 edev->ops->common->get_link(edev->cdev, ¤t_link); 762 763 return current_link.link_up; 764 } 765 766 static int qede_flash_device(struct net_device *dev, 767 struct ethtool_flash *flash) 768 { 769 struct qede_dev *edev = netdev_priv(dev); 770 771 return edev->ops->common->nvm_flash(edev->cdev, flash->data); 772 } 773 774 static int qede_get_coalesce(struct net_device *dev, 775 struct ethtool_coalesce *coal, 776 struct kernel_ethtool_coalesce *kernel_coal, 777 struct netlink_ext_ack *extack) 778 { 779 void *rx_handle = NULL, *tx_handle = NULL; 780 struct qede_dev *edev = netdev_priv(dev); 781 u16 rx_coal, tx_coal, i, rc = 0; 782 struct qede_fastpath *fp; 783 784 rx_coal = QED_DEFAULT_RX_USECS; 785 tx_coal = QED_DEFAULT_TX_USECS; 786 787 memset(coal, 0, sizeof(struct ethtool_coalesce)); 788 789 __qede_lock(edev); 790 if (edev->state == QEDE_STATE_OPEN) { 791 for_each_queue(i) { 792 fp = &edev->fp_array[i]; 793 794 if (fp->type & QEDE_FASTPATH_RX) { 795 rx_handle = fp->rxq->handle; 796 break; 797 } 798 } 799 800 rc = edev->ops->get_coalesce(edev->cdev, &rx_coal, rx_handle); 801 if (rc) { 802 DP_INFO(edev, "Read Rx coalesce error\n"); 803 goto out; 804 } 805 806 for_each_queue(i) { 807 struct qede_tx_queue *txq; 808 809 fp = &edev->fp_array[i]; 810 811 /* All TX queues of given fastpath uses same 812 * coalescing value, so no need to iterate over 813 * all TCs, TC0 txq should suffice. 814 */ 815 if (fp->type & QEDE_FASTPATH_TX) { 816 txq = QEDE_FP_TC0_TXQ(fp); 817 tx_handle = txq->handle; 818 break; 819 } 820 } 821 822 rc = edev->ops->get_coalesce(edev->cdev, &tx_coal, tx_handle); 823 if (rc) 824 DP_INFO(edev, "Read Tx coalesce error\n"); 825 } 826 827 out: 828 __qede_unlock(edev); 829 830 coal->rx_coalesce_usecs = rx_coal; 831 coal->tx_coalesce_usecs = tx_coal; 832 833 return rc; 834 } 835 836 int qede_set_coalesce(struct net_device *dev, struct ethtool_coalesce *coal, 837 struct kernel_ethtool_coalesce *kernel_coal, 838 struct netlink_ext_ack *extack) 839 { 840 struct qede_dev *edev = netdev_priv(dev); 841 struct qede_fastpath *fp; 842 int i, rc = 0; 843 u16 rxc, txc; 844 845 if (!netif_running(dev)) { 846 DP_INFO(edev, "Interface is down\n"); 847 return -EINVAL; 848 } 849 850 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX || 851 coal->tx_coalesce_usecs > QED_COALESCE_MAX) { 852 DP_INFO(edev, 853 "Can't support requested %s coalesce value [max supported value %d]\n", 854 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx" : 855 "tx", QED_COALESCE_MAX); 856 return -EINVAL; 857 } 858 859 rxc = (u16)coal->rx_coalesce_usecs; 860 txc = (u16)coal->tx_coalesce_usecs; 861 for_each_queue(i) { 862 fp = &edev->fp_array[i]; 863 864 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) { 865 rc = edev->ops->common->set_coalesce(edev->cdev, 866 rxc, 0, 867 fp->rxq->handle); 868 if (rc) { 869 DP_INFO(edev, 870 "Set RX coalesce error, rc = %d\n", rc); 871 return rc; 872 } 873 edev->coal_entry[i].rxc = rxc; 874 edev->coal_entry[i].isvalid = true; 875 } 876 877 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) { 878 struct qede_tx_queue *txq; 879 880 /* All TX queues of given fastpath uses same 881 * coalescing value, so no need to iterate over 882 * all TCs, TC0 txq should suffice. 883 */ 884 txq = QEDE_FP_TC0_TXQ(fp); 885 886 rc = edev->ops->common->set_coalesce(edev->cdev, 887 0, txc, 888 txq->handle); 889 if (rc) { 890 DP_INFO(edev, 891 "Set TX coalesce error, rc = %d\n", rc); 892 return rc; 893 } 894 edev->coal_entry[i].txc = txc; 895 edev->coal_entry[i].isvalid = true; 896 } 897 } 898 899 return rc; 900 } 901 902 static void qede_get_ringparam(struct net_device *dev, 903 struct ethtool_ringparam *ering, 904 struct kernel_ethtool_ringparam *kernel_ering, 905 struct netlink_ext_ack *extack) 906 { 907 struct qede_dev *edev = netdev_priv(dev); 908 909 ering->rx_max_pending = NUM_RX_BDS_MAX; 910 ering->rx_pending = edev->q_num_rx_buffers; 911 ering->tx_max_pending = NUM_TX_BDS_MAX; 912 ering->tx_pending = edev->q_num_tx_buffers; 913 } 914 915 static int qede_set_ringparam(struct net_device *dev, 916 struct ethtool_ringparam *ering, 917 struct kernel_ethtool_ringparam *kernel_ering, 918 struct netlink_ext_ack *extack) 919 { 920 struct qede_dev *edev = netdev_priv(dev); 921 922 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 923 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n", 924 ering->rx_pending, ering->tx_pending); 925 926 /* Validate legality of configuration */ 927 if (ering->rx_pending > NUM_RX_BDS_MAX || 928 ering->rx_pending < NUM_RX_BDS_MIN || 929 ering->tx_pending > NUM_TX_BDS_MAX || 930 ering->tx_pending < NUM_TX_BDS_MIN) { 931 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 932 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n", 933 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX, 934 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX); 935 return -EINVAL; 936 } 937 938 /* Change ring size and re-load */ 939 edev->q_num_rx_buffers = ering->rx_pending; 940 edev->q_num_tx_buffers = ering->tx_pending; 941 942 qede_reload(edev, NULL, false); 943 944 return 0; 945 } 946 947 static void qede_get_pauseparam(struct net_device *dev, 948 struct ethtool_pauseparam *epause) 949 { 950 struct qede_dev *edev = netdev_priv(dev); 951 struct qed_link_output current_link; 952 953 memset(¤t_link, 0, sizeof(current_link)); 954 edev->ops->common->get_link(edev->cdev, ¤t_link); 955 956 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE) 957 epause->autoneg = true; 958 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE) 959 epause->rx_pause = true; 960 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE) 961 epause->tx_pause = true; 962 963 DP_VERBOSE(edev, QED_MSG_DEBUG, 964 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n", 965 epause->cmd, epause->autoneg, epause->rx_pause, 966 epause->tx_pause); 967 } 968 969 static int qede_set_pauseparam(struct net_device *dev, 970 struct ethtool_pauseparam *epause) 971 { 972 struct qede_dev *edev = netdev_priv(dev); 973 struct qed_link_params params; 974 struct qed_link_output current_link; 975 976 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) { 977 DP_INFO(edev, 978 "Pause settings are not allowed to be changed\n"); 979 return -EOPNOTSUPP; 980 } 981 982 memset(¤t_link, 0, sizeof(current_link)); 983 edev->ops->common->get_link(edev->cdev, ¤t_link); 984 985 memset(¶ms, 0, sizeof(params)); 986 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG; 987 988 if (epause->autoneg) { 989 if (!phylink_test(current_link.supported_caps, Autoneg)) { 990 DP_INFO(edev, "autoneg not supported\n"); 991 return -EINVAL; 992 } 993 994 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE; 995 } 996 997 if (epause->rx_pause) 998 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE; 999 if (epause->tx_pause) 1000 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE; 1001 1002 params.link_up = true; 1003 edev->ops->common->set_link(edev->cdev, ¶ms); 1004 1005 return 0; 1006 } 1007 1008 static void qede_get_regs(struct net_device *ndev, 1009 struct ethtool_regs *regs, void *buffer) 1010 { 1011 struct qede_dev *edev = netdev_priv(ndev); 1012 1013 regs->version = 0; 1014 memset(buffer, 0, regs->len); 1015 1016 if (edev->ops && edev->ops->common) 1017 edev->ops->common->dbg_all_data(edev->cdev, buffer); 1018 } 1019 1020 static int qede_get_regs_len(struct net_device *ndev) 1021 { 1022 struct qede_dev *edev = netdev_priv(ndev); 1023 1024 if (edev->ops && edev->ops->common) 1025 return edev->ops->common->dbg_all_data_size(edev->cdev); 1026 else 1027 return -EINVAL; 1028 } 1029 1030 static void qede_update_mtu(struct qede_dev *edev, 1031 struct qede_reload_args *args) 1032 { 1033 edev->ndev->mtu = args->u.mtu; 1034 } 1035 1036 /* Netdevice NDOs */ 1037 int qede_change_mtu(struct net_device *ndev, int new_mtu) 1038 { 1039 struct qede_dev *edev = netdev_priv(ndev); 1040 struct qede_reload_args args; 1041 1042 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 1043 "Configuring MTU size of %d\n", new_mtu); 1044 1045 if (new_mtu > PAGE_SIZE) 1046 ndev->features &= ~NETIF_F_GRO_HW; 1047 1048 /* Set the mtu field and re-start the interface if needed */ 1049 args.u.mtu = new_mtu; 1050 args.func = &qede_update_mtu; 1051 qede_reload(edev, &args, false); 1052 #if IS_ENABLED(CONFIG_QED_RDMA) 1053 qede_rdma_event_change_mtu(edev); 1054 #endif 1055 edev->ops->common->update_mtu(edev->cdev, new_mtu); 1056 1057 return 0; 1058 } 1059 1060 static void qede_get_channels(struct net_device *dev, 1061 struct ethtool_channels *channels) 1062 { 1063 struct qede_dev *edev = netdev_priv(dev); 1064 1065 channels->max_combined = QEDE_MAX_RSS_CNT(edev); 1066 channels->max_rx = QEDE_MAX_RSS_CNT(edev); 1067 channels->max_tx = QEDE_MAX_RSS_CNT(edev); 1068 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx - 1069 edev->fp_num_rx; 1070 channels->tx_count = edev->fp_num_tx; 1071 channels->rx_count = edev->fp_num_rx; 1072 } 1073 1074 static int qede_set_channels(struct net_device *dev, 1075 struct ethtool_channels *channels) 1076 { 1077 struct qede_dev *edev = netdev_priv(dev); 1078 u32 count; 1079 1080 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 1081 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n", 1082 channels->rx_count, channels->tx_count, 1083 channels->other_count, channels->combined_count); 1084 1085 count = channels->rx_count + channels->tx_count + 1086 channels->combined_count; 1087 1088 /* We don't support `other' channels */ 1089 if (channels->other_count) { 1090 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 1091 "command parameters not supported\n"); 1092 return -EINVAL; 1093 } 1094 1095 if (!(channels->combined_count || (channels->rx_count && 1096 channels->tx_count))) { 1097 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 1098 "need to request at least one transmit and one receive channel\n"); 1099 return -EINVAL; 1100 } 1101 1102 if (count > QEDE_MAX_RSS_CNT(edev)) { 1103 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 1104 "requested channels = %d max supported channels = %d\n", 1105 count, QEDE_MAX_RSS_CNT(edev)); 1106 return -EINVAL; 1107 } 1108 1109 /* Check if there was a change in the active parameters */ 1110 if ((count == QEDE_QUEUE_CNT(edev)) && 1111 (channels->tx_count == edev->fp_num_tx) && 1112 (channels->rx_count == edev->fp_num_rx)) { 1113 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 1114 "No change in active parameters\n"); 1115 return 0; 1116 } 1117 1118 /* We need the number of queues to be divisible between the hwfns */ 1119 if ((count % edev->dev_info.common.num_hwfns) || 1120 (channels->tx_count % edev->dev_info.common.num_hwfns) || 1121 (channels->rx_count % edev->dev_info.common.num_hwfns)) { 1122 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 1123 "Number of channels must be divisible by %04x\n", 1124 edev->dev_info.common.num_hwfns); 1125 return -EINVAL; 1126 } 1127 1128 /* Set number of queues and reload if necessary */ 1129 edev->req_queues = count; 1130 edev->req_num_tx = channels->tx_count; 1131 edev->req_num_rx = channels->rx_count; 1132 /* Reset the indirection table if rx queue count is updated */ 1133 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) { 1134 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED; 1135 memset(edev->rss_ind_table, 0, sizeof(edev->rss_ind_table)); 1136 } 1137 1138 qede_reload(edev, NULL, false); 1139 1140 return 0; 1141 } 1142 1143 static int qede_get_ts_info(struct net_device *dev, 1144 struct ethtool_ts_info *info) 1145 { 1146 struct qede_dev *edev = netdev_priv(dev); 1147 1148 return qede_ptp_get_ts_info(edev, info); 1149 } 1150 1151 static int qede_set_phys_id(struct net_device *dev, 1152 enum ethtool_phys_id_state state) 1153 { 1154 struct qede_dev *edev = netdev_priv(dev); 1155 u8 led_state = 0; 1156 1157 switch (state) { 1158 case ETHTOOL_ID_ACTIVE: 1159 return 1; /* cycle on/off once per second */ 1160 1161 case ETHTOOL_ID_ON: 1162 led_state = QED_LED_MODE_ON; 1163 break; 1164 1165 case ETHTOOL_ID_OFF: 1166 led_state = QED_LED_MODE_OFF; 1167 break; 1168 1169 case ETHTOOL_ID_INACTIVE: 1170 led_state = QED_LED_MODE_RESTORE; 1171 break; 1172 } 1173 1174 edev->ops->common->set_led(edev->cdev, led_state); 1175 1176 return 0; 1177 } 1178 1179 static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info) 1180 { 1181 info->data = RXH_IP_SRC | RXH_IP_DST; 1182 1183 switch (info->flow_type) { 1184 case TCP_V4_FLOW: 1185 case TCP_V6_FLOW: 1186 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 1187 break; 1188 case UDP_V4_FLOW: 1189 if (edev->rss_caps & QED_RSS_IPV4_UDP) 1190 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 1191 break; 1192 case UDP_V6_FLOW: 1193 if (edev->rss_caps & QED_RSS_IPV6_UDP) 1194 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 1195 break; 1196 case IPV4_FLOW: 1197 case IPV6_FLOW: 1198 break; 1199 default: 1200 info->data = 0; 1201 break; 1202 } 1203 1204 return 0; 1205 } 1206 1207 static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info, 1208 u32 *rule_locs) 1209 { 1210 struct qede_dev *edev = netdev_priv(dev); 1211 int rc = 0; 1212 1213 switch (info->cmd) { 1214 case ETHTOOL_GRXRINGS: 1215 info->data = QEDE_RSS_COUNT(edev); 1216 break; 1217 case ETHTOOL_GRXFH: 1218 rc = qede_get_rss_flags(edev, info); 1219 break; 1220 case ETHTOOL_GRXCLSRLCNT: 1221 info->rule_cnt = qede_get_arfs_filter_count(edev); 1222 info->data = QEDE_RFS_MAX_FLTR; 1223 break; 1224 case ETHTOOL_GRXCLSRULE: 1225 rc = qede_get_cls_rule_entry(edev, info); 1226 break; 1227 case ETHTOOL_GRXCLSRLALL: 1228 rc = qede_get_cls_rule_all(edev, info, rule_locs); 1229 break; 1230 default: 1231 DP_ERR(edev, "Command parameters not supported\n"); 1232 rc = -EOPNOTSUPP; 1233 } 1234 1235 return rc; 1236 } 1237 1238 static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info) 1239 { 1240 struct qed_update_vport_params *vport_update_params; 1241 u8 set_caps = 0, clr_caps = 0; 1242 int rc = 0; 1243 1244 DP_VERBOSE(edev, QED_MSG_DEBUG, 1245 "Set rss flags command parameters: flow type = %d, data = %llu\n", 1246 info->flow_type, info->data); 1247 1248 switch (info->flow_type) { 1249 case TCP_V4_FLOW: 1250 case TCP_V6_FLOW: 1251 /* For TCP only 4-tuple hash is supported */ 1252 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST | 1253 RXH_L4_B_0_1 | RXH_L4_B_2_3)) { 1254 DP_INFO(edev, "Command parameters not supported\n"); 1255 return -EINVAL; 1256 } 1257 return 0; 1258 case UDP_V4_FLOW: 1259 /* For UDP either 2-tuple hash or 4-tuple hash is supported */ 1260 if (info->data == (RXH_IP_SRC | RXH_IP_DST | 1261 RXH_L4_B_0_1 | RXH_L4_B_2_3)) { 1262 set_caps = QED_RSS_IPV4_UDP; 1263 DP_VERBOSE(edev, QED_MSG_DEBUG, 1264 "UDP 4-tuple enabled\n"); 1265 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) { 1266 clr_caps = QED_RSS_IPV4_UDP; 1267 DP_VERBOSE(edev, QED_MSG_DEBUG, 1268 "UDP 4-tuple disabled\n"); 1269 } else { 1270 return -EINVAL; 1271 } 1272 break; 1273 case UDP_V6_FLOW: 1274 /* For UDP either 2-tuple hash or 4-tuple hash is supported */ 1275 if (info->data == (RXH_IP_SRC | RXH_IP_DST | 1276 RXH_L4_B_0_1 | RXH_L4_B_2_3)) { 1277 set_caps = QED_RSS_IPV6_UDP; 1278 DP_VERBOSE(edev, QED_MSG_DEBUG, 1279 "UDP 4-tuple enabled\n"); 1280 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) { 1281 clr_caps = QED_RSS_IPV6_UDP; 1282 DP_VERBOSE(edev, QED_MSG_DEBUG, 1283 "UDP 4-tuple disabled\n"); 1284 } else { 1285 return -EINVAL; 1286 } 1287 break; 1288 case IPV4_FLOW: 1289 case IPV6_FLOW: 1290 /* For IP only 2-tuple hash is supported */ 1291 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) { 1292 DP_INFO(edev, "Command parameters not supported\n"); 1293 return -EINVAL; 1294 } 1295 return 0; 1296 case SCTP_V4_FLOW: 1297 case AH_ESP_V4_FLOW: 1298 case AH_V4_FLOW: 1299 case ESP_V4_FLOW: 1300 case SCTP_V6_FLOW: 1301 case AH_ESP_V6_FLOW: 1302 case AH_V6_FLOW: 1303 case ESP_V6_FLOW: 1304 case IP_USER_FLOW: 1305 case ETHER_FLOW: 1306 /* RSS is not supported for these protocols */ 1307 if (info->data) { 1308 DP_INFO(edev, "Command parameters not supported\n"); 1309 return -EINVAL; 1310 } 1311 return 0; 1312 default: 1313 return -EINVAL; 1314 } 1315 1316 /* No action is needed if there is no change in the rss capability */ 1317 if (edev->rss_caps == ((edev->rss_caps & ~clr_caps) | set_caps)) 1318 return 0; 1319 1320 /* Update internal configuration */ 1321 edev->rss_caps = ((edev->rss_caps & ~clr_caps) | set_caps); 1322 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED; 1323 1324 /* Re-configure if possible */ 1325 __qede_lock(edev); 1326 if (edev->state == QEDE_STATE_OPEN) { 1327 vport_update_params = vzalloc(sizeof(*vport_update_params)); 1328 if (!vport_update_params) { 1329 __qede_unlock(edev); 1330 return -ENOMEM; 1331 } 1332 qede_fill_rss_params(edev, &vport_update_params->rss_params, 1333 &vport_update_params->update_rss_flg); 1334 rc = edev->ops->vport_update(edev->cdev, vport_update_params); 1335 vfree(vport_update_params); 1336 } 1337 __qede_unlock(edev); 1338 1339 return rc; 1340 } 1341 1342 static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info) 1343 { 1344 struct qede_dev *edev = netdev_priv(dev); 1345 int rc; 1346 1347 switch (info->cmd) { 1348 case ETHTOOL_SRXFH: 1349 rc = qede_set_rss_flags(edev, info); 1350 break; 1351 case ETHTOOL_SRXCLSRLINS: 1352 rc = qede_add_cls_rule(edev, info); 1353 break; 1354 case ETHTOOL_SRXCLSRLDEL: 1355 rc = qede_delete_flow_filter(edev, info->fs.location); 1356 break; 1357 default: 1358 DP_INFO(edev, "Command parameters not supported\n"); 1359 rc = -EOPNOTSUPP; 1360 } 1361 1362 return rc; 1363 } 1364 1365 static u32 qede_get_rxfh_indir_size(struct net_device *dev) 1366 { 1367 return QED_RSS_IND_TABLE_SIZE; 1368 } 1369 1370 static u32 qede_get_rxfh_key_size(struct net_device *dev) 1371 { 1372 struct qede_dev *edev = netdev_priv(dev); 1373 1374 return sizeof(edev->rss_key); 1375 } 1376 1377 static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc) 1378 { 1379 struct qede_dev *edev = netdev_priv(dev); 1380 int i; 1381 1382 if (hfunc) 1383 *hfunc = ETH_RSS_HASH_TOP; 1384 1385 if (!indir) 1386 return 0; 1387 1388 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) 1389 indir[i] = edev->rss_ind_table[i]; 1390 1391 if (key) 1392 memcpy(key, edev->rss_key, qede_get_rxfh_key_size(dev)); 1393 1394 return 0; 1395 } 1396 1397 static int qede_set_rxfh(struct net_device *dev, const u32 *indir, 1398 const u8 *key, const u8 hfunc) 1399 { 1400 struct qed_update_vport_params *vport_update_params; 1401 struct qede_dev *edev = netdev_priv(dev); 1402 int i, rc = 0; 1403 1404 if (edev->dev_info.common.num_hwfns > 1) { 1405 DP_INFO(edev, 1406 "RSS configuration is not supported for 100G devices\n"); 1407 return -EOPNOTSUPP; 1408 } 1409 1410 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) 1411 return -EOPNOTSUPP; 1412 1413 if (!indir && !key) 1414 return 0; 1415 1416 if (indir) { 1417 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) 1418 edev->rss_ind_table[i] = indir[i]; 1419 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED; 1420 } 1421 1422 if (key) { 1423 memcpy(&edev->rss_key, key, qede_get_rxfh_key_size(dev)); 1424 edev->rss_params_inited |= QEDE_RSS_KEY_INITED; 1425 } 1426 1427 __qede_lock(edev); 1428 if (edev->state == QEDE_STATE_OPEN) { 1429 vport_update_params = vzalloc(sizeof(*vport_update_params)); 1430 if (!vport_update_params) { 1431 __qede_unlock(edev); 1432 return -ENOMEM; 1433 } 1434 qede_fill_rss_params(edev, &vport_update_params->rss_params, 1435 &vport_update_params->update_rss_flg); 1436 rc = edev->ops->vport_update(edev->cdev, vport_update_params); 1437 vfree(vport_update_params); 1438 } 1439 __qede_unlock(edev); 1440 1441 return rc; 1442 } 1443 1444 /* This function enables the interrupt generation and the NAPI on the device */ 1445 static void qede_netif_start(struct qede_dev *edev) 1446 { 1447 int i; 1448 1449 if (!netif_running(edev->ndev)) 1450 return; 1451 1452 for_each_queue(i) { 1453 /* Update and reenable interrupts */ 1454 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1); 1455 napi_enable(&edev->fp_array[i].napi); 1456 } 1457 } 1458 1459 /* This function disables the NAPI and the interrupt generation on the device */ 1460 static void qede_netif_stop(struct qede_dev *edev) 1461 { 1462 int i; 1463 1464 for_each_queue(i) { 1465 napi_disable(&edev->fp_array[i].napi); 1466 /* Disable interrupts */ 1467 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0); 1468 } 1469 } 1470 1471 static int qede_selftest_transmit_traffic(struct qede_dev *edev, 1472 struct sk_buff *skb) 1473 { 1474 struct qede_tx_queue *txq = NULL; 1475 struct eth_tx_1st_bd *first_bd; 1476 dma_addr_t mapping; 1477 int i, idx; 1478 u16 val; 1479 1480 for_each_queue(i) { 1481 struct qede_fastpath *fp = &edev->fp_array[i]; 1482 1483 if (fp->type & QEDE_FASTPATH_TX) { 1484 txq = QEDE_FP_TC0_TXQ(fp); 1485 break; 1486 } 1487 } 1488 1489 if (!txq) { 1490 DP_NOTICE(edev, "Tx path is not available\n"); 1491 return -1; 1492 } 1493 1494 /* Fill the entry in the SW ring and the BDs in the FW ring */ 1495 idx = txq->sw_tx_prod; 1496 txq->sw_tx_ring.skbs[idx].skb = skb; 1497 first_bd = qed_chain_produce(&txq->tx_pbl); 1498 memset(first_bd, 0, sizeof(*first_bd)); 1499 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT; 1500 first_bd->data.bd_flags.bitfields = val; 1501 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK; 1502 val = val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT; 1503 first_bd->data.bitfields |= cpu_to_le16(val); 1504 1505 /* Map skb linear data for DMA and set in the first BD */ 1506 mapping = dma_map_single(&edev->pdev->dev, skb->data, 1507 skb_headlen(skb), DMA_TO_DEVICE); 1508 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) { 1509 DP_NOTICE(edev, "SKB mapping failed\n"); 1510 return -ENOMEM; 1511 } 1512 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb)); 1513 1514 /* update the first BD with the actual num BDs */ 1515 first_bd->data.nbds = 1; 1516 txq->sw_tx_prod = (txq->sw_tx_prod + 1) % txq->num_tx_buffers; 1517 /* 'next page' entries are counted in the producer value */ 1518 val = qed_chain_get_prod_idx(&txq->tx_pbl); 1519 txq->tx_db.data.bd_prod = cpu_to_le16(val); 1520 1521 /* wmb makes sure that the BDs data is updated before updating the 1522 * producer, otherwise FW may read old data from the BDs. 1523 */ 1524 wmb(); 1525 barrier(); 1526 writel(txq->tx_db.raw, txq->doorbell_addr); 1527 1528 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) { 1529 if (qede_txq_has_work(txq)) 1530 break; 1531 usleep_range(100, 200); 1532 } 1533 1534 if (!qede_txq_has_work(txq)) { 1535 DP_NOTICE(edev, "Tx completion didn't happen\n"); 1536 return -1; 1537 } 1538 1539 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl); 1540 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd), 1541 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE); 1542 txq->sw_tx_cons = (txq->sw_tx_cons + 1) % txq->num_tx_buffers; 1543 txq->sw_tx_ring.skbs[idx].skb = NULL; 1544 1545 return 0; 1546 } 1547 1548 static int qede_selftest_receive_traffic(struct qede_dev *edev) 1549 { 1550 u16 sw_rx_index, len; 1551 struct eth_fast_path_rx_reg_cqe *fp_cqe; 1552 struct qede_rx_queue *rxq = NULL; 1553 struct sw_rx_data *sw_rx_data; 1554 union eth_rx_cqe *cqe; 1555 int i, iter, rc = 0; 1556 u8 *data_ptr; 1557 1558 for_each_queue(i) { 1559 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) { 1560 rxq = edev->fp_array[i].rxq; 1561 break; 1562 } 1563 } 1564 1565 if (!rxq) { 1566 DP_NOTICE(edev, "Rx path is not available\n"); 1567 return -1; 1568 } 1569 1570 /* The packet is expected to receive on rx-queue 0 even though RSS is 1571 * enabled. This is because the queue 0 is configured as the default 1572 * queue and that the loopback traffic is not IP. 1573 */ 1574 for (iter = 0; iter < QEDE_SELFTEST_POLL_COUNT; iter++) { 1575 if (!qede_has_rx_work(rxq)) { 1576 usleep_range(100, 200); 1577 continue; 1578 } 1579 1580 /* Get the CQE from the completion ring */ 1581 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring); 1582 1583 /* Get the data from the SW ring */ 1584 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX; 1585 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index]; 1586 fp_cqe = &cqe->fast_path_regular; 1587 len = le16_to_cpu(fp_cqe->len_on_first_bd); 1588 data_ptr = (u8 *)(page_address(sw_rx_data->data) + 1589 fp_cqe->placement_offset + 1590 sw_rx_data->page_offset + 1591 rxq->rx_headroom); 1592 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) && 1593 ether_addr_equal(data_ptr + ETH_ALEN, 1594 edev->ndev->dev_addr)) { 1595 for (i = ETH_HLEN; i < len; i++) 1596 if (data_ptr[i] != (unsigned char)(i & 0xff)) { 1597 rc = -1; 1598 break; 1599 } 1600 1601 qede_recycle_rx_bd_ring(rxq, 1); 1602 qed_chain_recycle_consumed(&rxq->rx_comp_ring); 1603 break; 1604 } 1605 1606 DP_INFO(edev, "Not the transmitted packet\n"); 1607 qede_recycle_rx_bd_ring(rxq, 1); 1608 qed_chain_recycle_consumed(&rxq->rx_comp_ring); 1609 } 1610 1611 if (iter == QEDE_SELFTEST_POLL_COUNT) { 1612 DP_NOTICE(edev, "Failed to receive the traffic\n"); 1613 return -1; 1614 } 1615 1616 qede_update_rx_prod(edev, rxq); 1617 1618 return rc; 1619 } 1620 1621 static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode) 1622 { 1623 struct qed_link_params link_params; 1624 struct sk_buff *skb = NULL; 1625 int rc = 0, i; 1626 u32 pkt_size; 1627 u8 *packet; 1628 1629 if (!netif_running(edev->ndev)) { 1630 DP_NOTICE(edev, "Interface is down\n"); 1631 return -EINVAL; 1632 } 1633 1634 qede_netif_stop(edev); 1635 1636 /* Bring up the link in Loopback mode */ 1637 memset(&link_params, 0, sizeof(link_params)); 1638 link_params.link_up = true; 1639 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE; 1640 link_params.loopback_mode = loopback_mode; 1641 edev->ops->common->set_link(edev->cdev, &link_params); 1642 1643 /* Wait for loopback configuration to apply */ 1644 msleep_interruptible(500); 1645 1646 /* Setting max packet size to 1.5K to avoid data being split over 1647 * multiple BDs in cases where MTU > PAGE_SIZE. 1648 */ 1649 pkt_size = (((edev->ndev->mtu < ETH_DATA_LEN) ? 1650 edev->ndev->mtu : ETH_DATA_LEN) + ETH_HLEN); 1651 1652 skb = netdev_alloc_skb(edev->ndev, pkt_size); 1653 if (!skb) { 1654 DP_INFO(edev, "Can't allocate skb\n"); 1655 rc = -ENOMEM; 1656 goto test_loopback_exit; 1657 } 1658 packet = skb_put(skb, pkt_size); 1659 ether_addr_copy(packet, edev->ndev->dev_addr); 1660 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr); 1661 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN))); 1662 for (i = ETH_HLEN; i < pkt_size; i++) 1663 packet[i] = (unsigned char)(i & 0xff); 1664 1665 rc = qede_selftest_transmit_traffic(edev, skb); 1666 if (rc) 1667 goto test_loopback_exit; 1668 1669 rc = qede_selftest_receive_traffic(edev); 1670 if (rc) 1671 goto test_loopback_exit; 1672 1673 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n"); 1674 1675 test_loopback_exit: 1676 dev_kfree_skb(skb); 1677 1678 /* Bring up the link in Normal mode */ 1679 memset(&link_params, 0, sizeof(link_params)); 1680 link_params.link_up = true; 1681 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE; 1682 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE; 1683 edev->ops->common->set_link(edev->cdev, &link_params); 1684 1685 /* Wait for loopback configuration to apply */ 1686 msleep_interruptible(500); 1687 1688 qede_netif_start(edev); 1689 1690 return rc; 1691 } 1692 1693 static void qede_self_test(struct net_device *dev, 1694 struct ethtool_test *etest, u64 *buf) 1695 { 1696 struct qede_dev *edev = netdev_priv(dev); 1697 1698 DP_VERBOSE(edev, QED_MSG_DEBUG, 1699 "Self-test command parameters: offline = %d, external_lb = %d\n", 1700 (etest->flags & ETH_TEST_FL_OFFLINE), 1701 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2); 1702 1703 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX); 1704 1705 if (etest->flags & ETH_TEST_FL_OFFLINE) { 1706 if (qede_selftest_run_loopback(edev, 1707 QED_LINK_LOOPBACK_INT_PHY)) { 1708 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1; 1709 etest->flags |= ETH_TEST_FL_FAILED; 1710 } 1711 } 1712 1713 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) { 1714 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1; 1715 etest->flags |= ETH_TEST_FL_FAILED; 1716 } 1717 1718 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) { 1719 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1; 1720 etest->flags |= ETH_TEST_FL_FAILED; 1721 } 1722 1723 if (edev->ops->common->selftest->selftest_register(edev->cdev)) { 1724 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1; 1725 etest->flags |= ETH_TEST_FL_FAILED; 1726 } 1727 1728 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) { 1729 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1; 1730 etest->flags |= ETH_TEST_FL_FAILED; 1731 } 1732 1733 if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) { 1734 buf[QEDE_ETHTOOL_NVRAM_TEST] = 1; 1735 etest->flags |= ETH_TEST_FL_FAILED; 1736 } 1737 } 1738 1739 static int qede_set_tunable(struct net_device *dev, 1740 const struct ethtool_tunable *tuna, 1741 const void *data) 1742 { 1743 struct qede_dev *edev = netdev_priv(dev); 1744 u32 val; 1745 1746 switch (tuna->id) { 1747 case ETHTOOL_RX_COPYBREAK: 1748 val = *(u32 *)data; 1749 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) { 1750 DP_VERBOSE(edev, QED_MSG_DEBUG, 1751 "Invalid rx copy break value, range is [%u, %u]", 1752 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE); 1753 return -EINVAL; 1754 } 1755 1756 edev->rx_copybreak = *(u32 *)data; 1757 break; 1758 default: 1759 return -EOPNOTSUPP; 1760 } 1761 1762 return 0; 1763 } 1764 1765 static int qede_get_tunable(struct net_device *dev, 1766 const struct ethtool_tunable *tuna, void *data) 1767 { 1768 struct qede_dev *edev = netdev_priv(dev); 1769 1770 switch (tuna->id) { 1771 case ETHTOOL_RX_COPYBREAK: 1772 *(u32 *)data = edev->rx_copybreak; 1773 break; 1774 default: 1775 return -EOPNOTSUPP; 1776 } 1777 1778 return 0; 1779 } 1780 1781 static int qede_get_eee(struct net_device *dev, struct ethtool_eee *edata) 1782 { 1783 struct qede_dev *edev = netdev_priv(dev); 1784 struct qed_link_output current_link; 1785 1786 memset(¤t_link, 0, sizeof(current_link)); 1787 edev->ops->common->get_link(edev->cdev, ¤t_link); 1788 1789 if (!current_link.eee_supported) { 1790 DP_INFO(edev, "EEE is not supported\n"); 1791 return -EOPNOTSUPP; 1792 } 1793 1794 if (current_link.eee.adv_caps & QED_EEE_1G_ADV) 1795 edata->advertised = ADVERTISED_1000baseT_Full; 1796 if (current_link.eee.adv_caps & QED_EEE_10G_ADV) 1797 edata->advertised |= ADVERTISED_10000baseT_Full; 1798 if (current_link.sup_caps & QED_EEE_1G_ADV) 1799 edata->supported = ADVERTISED_1000baseT_Full; 1800 if (current_link.sup_caps & QED_EEE_10G_ADV) 1801 edata->supported |= ADVERTISED_10000baseT_Full; 1802 if (current_link.eee.lp_adv_caps & QED_EEE_1G_ADV) 1803 edata->lp_advertised = ADVERTISED_1000baseT_Full; 1804 if (current_link.eee.lp_adv_caps & QED_EEE_10G_ADV) 1805 edata->lp_advertised |= ADVERTISED_10000baseT_Full; 1806 1807 edata->tx_lpi_timer = current_link.eee.tx_lpi_timer; 1808 edata->eee_enabled = current_link.eee.enable; 1809 edata->tx_lpi_enabled = current_link.eee.tx_lpi_enable; 1810 edata->eee_active = current_link.eee_active; 1811 1812 return 0; 1813 } 1814 1815 static int qede_set_eee(struct net_device *dev, struct ethtool_eee *edata) 1816 { 1817 struct qede_dev *edev = netdev_priv(dev); 1818 struct qed_link_output current_link; 1819 struct qed_link_params params; 1820 1821 if (!edev->ops->common->can_link_change(edev->cdev)) { 1822 DP_INFO(edev, "Link settings are not allowed to be changed\n"); 1823 return -EOPNOTSUPP; 1824 } 1825 1826 memset(¤t_link, 0, sizeof(current_link)); 1827 edev->ops->common->get_link(edev->cdev, ¤t_link); 1828 1829 if (!current_link.eee_supported) { 1830 DP_INFO(edev, "EEE is not supported\n"); 1831 return -EOPNOTSUPP; 1832 } 1833 1834 memset(¶ms, 0, sizeof(params)); 1835 params.override_flags |= QED_LINK_OVERRIDE_EEE_CONFIG; 1836 1837 if (!(edata->advertised & (ADVERTISED_1000baseT_Full | 1838 ADVERTISED_10000baseT_Full)) || 1839 ((edata->advertised & (ADVERTISED_1000baseT_Full | 1840 ADVERTISED_10000baseT_Full)) != 1841 edata->advertised)) { 1842 DP_VERBOSE(edev, QED_MSG_DEBUG, 1843 "Invalid advertised capabilities %d\n", 1844 edata->advertised); 1845 return -EINVAL; 1846 } 1847 1848 if (edata->advertised & ADVERTISED_1000baseT_Full) 1849 params.eee.adv_caps = QED_EEE_1G_ADV; 1850 if (edata->advertised & ADVERTISED_10000baseT_Full) 1851 params.eee.adv_caps |= QED_EEE_10G_ADV; 1852 params.eee.enable = edata->eee_enabled; 1853 params.eee.tx_lpi_enable = edata->tx_lpi_enabled; 1854 params.eee.tx_lpi_timer = edata->tx_lpi_timer; 1855 1856 params.link_up = true; 1857 edev->ops->common->set_link(edev->cdev, ¶ms); 1858 1859 return 0; 1860 } 1861 1862 static u32 qede_link_to_ethtool_fec(u32 link_fec) 1863 { 1864 u32 eth_fec = 0; 1865 1866 if (link_fec & QED_FEC_MODE_NONE) 1867 eth_fec |= ETHTOOL_FEC_OFF; 1868 if (link_fec & QED_FEC_MODE_FIRECODE) 1869 eth_fec |= ETHTOOL_FEC_BASER; 1870 if (link_fec & QED_FEC_MODE_RS) 1871 eth_fec |= ETHTOOL_FEC_RS; 1872 if (link_fec & QED_FEC_MODE_AUTO) 1873 eth_fec |= ETHTOOL_FEC_AUTO; 1874 if (link_fec & QED_FEC_MODE_UNSUPPORTED) 1875 eth_fec |= ETHTOOL_FEC_NONE; 1876 1877 return eth_fec; 1878 } 1879 1880 static u32 qede_ethtool_to_link_fec(u32 eth_fec) 1881 { 1882 u32 link_fec = 0; 1883 1884 if (eth_fec & ETHTOOL_FEC_OFF) 1885 link_fec |= QED_FEC_MODE_NONE; 1886 if (eth_fec & ETHTOOL_FEC_BASER) 1887 link_fec |= QED_FEC_MODE_FIRECODE; 1888 if (eth_fec & ETHTOOL_FEC_RS) 1889 link_fec |= QED_FEC_MODE_RS; 1890 if (eth_fec & ETHTOOL_FEC_AUTO) 1891 link_fec |= QED_FEC_MODE_AUTO; 1892 if (eth_fec & ETHTOOL_FEC_NONE) 1893 link_fec |= QED_FEC_MODE_UNSUPPORTED; 1894 1895 return link_fec; 1896 } 1897 1898 static int qede_get_fecparam(struct net_device *dev, 1899 struct ethtool_fecparam *fecparam) 1900 { 1901 struct qede_dev *edev = netdev_priv(dev); 1902 struct qed_link_output curr_link; 1903 1904 memset(&curr_link, 0, sizeof(curr_link)); 1905 edev->ops->common->get_link(edev->cdev, &curr_link); 1906 1907 fecparam->active_fec = qede_link_to_ethtool_fec(curr_link.active_fec); 1908 fecparam->fec = qede_link_to_ethtool_fec(curr_link.sup_fec); 1909 1910 return 0; 1911 } 1912 1913 static int qede_set_fecparam(struct net_device *dev, 1914 struct ethtool_fecparam *fecparam) 1915 { 1916 struct qede_dev *edev = netdev_priv(dev); 1917 struct qed_link_params params; 1918 1919 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) { 1920 DP_INFO(edev, "Link settings are not allowed to be changed\n"); 1921 return -EOPNOTSUPP; 1922 } 1923 1924 memset(¶ms, 0, sizeof(params)); 1925 params.override_flags |= QED_LINK_OVERRIDE_FEC_CONFIG; 1926 params.fec = qede_ethtool_to_link_fec(fecparam->fec); 1927 params.link_up = true; 1928 1929 edev->ops->common->set_link(edev->cdev, ¶ms); 1930 1931 return 0; 1932 } 1933 1934 static int qede_get_module_info(struct net_device *dev, 1935 struct ethtool_modinfo *modinfo) 1936 { 1937 struct qede_dev *edev = netdev_priv(dev); 1938 u8 buf[4]; 1939 int rc; 1940 1941 /* Read first 4 bytes to find the sfp type */ 1942 rc = edev->ops->common->read_module_eeprom(edev->cdev, buf, 1943 QED_I2C_DEV_ADDR_A0, 0, 4); 1944 if (rc) { 1945 DP_ERR(edev, "Failed reading EEPROM data %d\n", rc); 1946 return rc; 1947 } 1948 1949 switch (buf[0]) { 1950 case 0x3: /* SFP, SFP+, SFP-28 */ 1951 modinfo->type = ETH_MODULE_SFF_8472; 1952 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; 1953 break; 1954 case 0xc: /* QSFP */ 1955 case 0xd: /* QSFP+ */ 1956 modinfo->type = ETH_MODULE_SFF_8436; 1957 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 1958 break; 1959 case 0x11: /* QSFP-28 */ 1960 modinfo->type = ETH_MODULE_SFF_8636; 1961 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN; 1962 break; 1963 default: 1964 DP_ERR(edev, "Unknown transceiver type 0x%x\n", buf[0]); 1965 return -EINVAL; 1966 } 1967 1968 return 0; 1969 } 1970 1971 static int qede_get_module_eeprom(struct net_device *dev, 1972 struct ethtool_eeprom *ee, u8 *data) 1973 { 1974 struct qede_dev *edev = netdev_priv(dev); 1975 u32 start_addr = ee->offset, size = 0; 1976 u8 *buf = data; 1977 int rc = 0; 1978 1979 /* Read A0 section */ 1980 if (ee->offset < ETH_MODULE_SFF_8079_LEN) { 1981 /* Limit transfer size to the A0 section boundary */ 1982 if (ee->offset + ee->len > ETH_MODULE_SFF_8079_LEN) 1983 size = ETH_MODULE_SFF_8079_LEN - ee->offset; 1984 else 1985 size = ee->len; 1986 1987 rc = edev->ops->common->read_module_eeprom(edev->cdev, buf, 1988 QED_I2C_DEV_ADDR_A0, 1989 start_addr, size); 1990 if (rc) { 1991 DP_ERR(edev, "Failed reading A0 section %d\n", rc); 1992 return rc; 1993 } 1994 1995 buf += size; 1996 start_addr += size; 1997 } 1998 1999 /* Read A2 section */ 2000 if (start_addr >= ETH_MODULE_SFF_8079_LEN && 2001 start_addr < ETH_MODULE_SFF_8472_LEN) { 2002 size = ee->len - size; 2003 /* Limit transfer size to the A2 section boundary */ 2004 if (start_addr + size > ETH_MODULE_SFF_8472_LEN) 2005 size = ETH_MODULE_SFF_8472_LEN - start_addr; 2006 start_addr -= ETH_MODULE_SFF_8079_LEN; 2007 rc = edev->ops->common->read_module_eeprom(edev->cdev, buf, 2008 QED_I2C_DEV_ADDR_A2, 2009 start_addr, size); 2010 if (rc) { 2011 DP_VERBOSE(edev, QED_MSG_DEBUG, 2012 "Failed reading A2 section %d\n", rc); 2013 return 0; 2014 } 2015 } 2016 2017 return rc; 2018 } 2019 2020 static int qede_set_dump(struct net_device *dev, struct ethtool_dump *val) 2021 { 2022 struct qede_dev *edev = netdev_priv(dev); 2023 int rc = 0; 2024 2025 if (edev->dump_info.cmd == QEDE_DUMP_CMD_NONE) { 2026 if (val->flag > QEDE_DUMP_CMD_MAX) { 2027 DP_ERR(edev, "Invalid command %d\n", val->flag); 2028 return -EINVAL; 2029 } 2030 edev->dump_info.cmd = val->flag; 2031 edev->dump_info.num_args = 0; 2032 return 0; 2033 } 2034 2035 if (edev->dump_info.num_args == QEDE_DUMP_MAX_ARGS) { 2036 DP_ERR(edev, "Arg count = %d\n", edev->dump_info.num_args); 2037 return -EINVAL; 2038 } 2039 2040 switch (edev->dump_info.cmd) { 2041 case QEDE_DUMP_CMD_NVM_CFG: 2042 edev->dump_info.args[edev->dump_info.num_args] = val->flag; 2043 edev->dump_info.num_args++; 2044 break; 2045 case QEDE_DUMP_CMD_GRCDUMP: 2046 rc = edev->ops->common->set_grc_config(edev->cdev, 2047 val->flag, 1); 2048 break; 2049 default: 2050 break; 2051 } 2052 2053 return rc; 2054 } 2055 2056 static int qede_get_dump_flag(struct net_device *dev, 2057 struct ethtool_dump *dump) 2058 { 2059 struct qede_dev *edev = netdev_priv(dev); 2060 2061 if (!edev->ops || !edev->ops->common) { 2062 DP_ERR(edev, "Edev ops not populated\n"); 2063 return -EINVAL; 2064 } 2065 2066 dump->version = QEDE_DUMP_VERSION; 2067 switch (edev->dump_info.cmd) { 2068 case QEDE_DUMP_CMD_NVM_CFG: 2069 dump->flag = QEDE_DUMP_CMD_NVM_CFG; 2070 dump->len = edev->ops->common->read_nvm_cfg_len(edev->cdev, 2071 edev->dump_info.args[0]); 2072 break; 2073 case QEDE_DUMP_CMD_GRCDUMP: 2074 dump->flag = QEDE_DUMP_CMD_GRCDUMP; 2075 dump->len = edev->ops->common->dbg_all_data_size(edev->cdev); 2076 break; 2077 default: 2078 DP_ERR(edev, "Invalid cmd = %d\n", edev->dump_info.cmd); 2079 return -EINVAL; 2080 } 2081 2082 DP_VERBOSE(edev, QED_MSG_DEBUG, 2083 "dump->version = 0x%x dump->flag = %d dump->len = %d\n", 2084 dump->version, dump->flag, dump->len); 2085 return 0; 2086 } 2087 2088 static int qede_get_dump_data(struct net_device *dev, 2089 struct ethtool_dump *dump, void *buf) 2090 { 2091 struct qede_dev *edev = netdev_priv(dev); 2092 int rc = 0; 2093 2094 if (!edev->ops || !edev->ops->common) { 2095 DP_ERR(edev, "Edev ops not populated\n"); 2096 rc = -EINVAL; 2097 goto err; 2098 } 2099 2100 switch (edev->dump_info.cmd) { 2101 case QEDE_DUMP_CMD_NVM_CFG: 2102 if (edev->dump_info.num_args != QEDE_DUMP_NVM_ARG_COUNT) { 2103 DP_ERR(edev, "Arg count = %d required = %d\n", 2104 edev->dump_info.num_args, 2105 QEDE_DUMP_NVM_ARG_COUNT); 2106 rc = -EINVAL; 2107 goto err; 2108 } 2109 rc = edev->ops->common->read_nvm_cfg(edev->cdev, (u8 **)&buf, 2110 edev->dump_info.args[0], 2111 edev->dump_info.args[1]); 2112 break; 2113 case QEDE_DUMP_CMD_GRCDUMP: 2114 memset(buf, 0, dump->len); 2115 rc = edev->ops->common->dbg_all_data(edev->cdev, buf); 2116 break; 2117 default: 2118 DP_ERR(edev, "Invalid cmd = %d\n", edev->dump_info.cmd); 2119 rc = -EINVAL; 2120 break; 2121 } 2122 2123 err: 2124 edev->dump_info.cmd = QEDE_DUMP_CMD_NONE; 2125 edev->dump_info.num_args = 0; 2126 memset(edev->dump_info.args, 0, sizeof(edev->dump_info.args)); 2127 2128 return rc; 2129 } 2130 2131 int qede_set_per_coalesce(struct net_device *dev, u32 queue, 2132 struct ethtool_coalesce *coal) 2133 { 2134 struct qede_dev *edev = netdev_priv(dev); 2135 struct qede_fastpath *fp; 2136 u16 rxc, txc; 2137 int rc = 0; 2138 2139 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX || 2140 coal->tx_coalesce_usecs > QED_COALESCE_MAX) { 2141 DP_INFO(edev, 2142 "Can't support requested %s coalesce value [max supported value %d]\n", 2143 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx" 2144 : "tx", 2145 QED_COALESCE_MAX); 2146 return -EINVAL; 2147 } 2148 2149 rxc = (u16)coal->rx_coalesce_usecs; 2150 txc = (u16)coal->tx_coalesce_usecs; 2151 2152 __qede_lock(edev); 2153 if (queue >= edev->num_queues) { 2154 DP_INFO(edev, "Invalid queue\n"); 2155 rc = -EINVAL; 2156 goto out; 2157 } 2158 2159 if (edev->state != QEDE_STATE_OPEN) { 2160 rc = -EINVAL; 2161 goto out; 2162 } 2163 2164 fp = &edev->fp_array[queue]; 2165 2166 if (edev->fp_array[queue].type & QEDE_FASTPATH_RX) { 2167 rc = edev->ops->common->set_coalesce(edev->cdev, 2168 rxc, 0, 2169 fp->rxq->handle); 2170 if (rc) { 2171 DP_INFO(edev, 2172 "Set RX coalesce error, rc = %d\n", rc); 2173 goto out; 2174 } 2175 edev->coal_entry[queue].rxc = rxc; 2176 edev->coal_entry[queue].isvalid = true; 2177 } 2178 2179 if (edev->fp_array[queue].type & QEDE_FASTPATH_TX) { 2180 rc = edev->ops->common->set_coalesce(edev->cdev, 2181 0, txc, 2182 fp->txq->handle); 2183 if (rc) { 2184 DP_INFO(edev, 2185 "Set TX coalesce error, rc = %d\n", rc); 2186 goto out; 2187 } 2188 edev->coal_entry[queue].txc = txc; 2189 edev->coal_entry[queue].isvalid = true; 2190 } 2191 out: 2192 __qede_unlock(edev); 2193 2194 return rc; 2195 } 2196 2197 static int qede_get_per_coalesce(struct net_device *dev, 2198 u32 queue, 2199 struct ethtool_coalesce *coal) 2200 { 2201 void *rx_handle = NULL, *tx_handle = NULL; 2202 struct qede_dev *edev = netdev_priv(dev); 2203 struct qede_fastpath *fp; 2204 u16 rx_coal, tx_coal; 2205 int rc = 0; 2206 2207 rx_coal = QED_DEFAULT_RX_USECS; 2208 tx_coal = QED_DEFAULT_TX_USECS; 2209 2210 memset(coal, 0, sizeof(struct ethtool_coalesce)); 2211 2212 __qede_lock(edev); 2213 if (queue >= edev->num_queues) { 2214 DP_INFO(edev, "Invalid queue\n"); 2215 rc = -EINVAL; 2216 goto out; 2217 } 2218 2219 if (edev->state != QEDE_STATE_OPEN) { 2220 rc = -EINVAL; 2221 goto out; 2222 } 2223 2224 fp = &edev->fp_array[queue]; 2225 2226 if (fp->type & QEDE_FASTPATH_RX) 2227 rx_handle = fp->rxq->handle; 2228 2229 rc = edev->ops->get_coalesce(edev->cdev, &rx_coal, 2230 rx_handle); 2231 if (rc) { 2232 DP_INFO(edev, "Read Rx coalesce error\n"); 2233 goto out; 2234 } 2235 2236 fp = &edev->fp_array[queue]; 2237 if (fp->type & QEDE_FASTPATH_TX) 2238 tx_handle = fp->txq->handle; 2239 2240 rc = edev->ops->get_coalesce(edev->cdev, &tx_coal, 2241 tx_handle); 2242 if (rc) 2243 DP_INFO(edev, "Read Tx coalesce error\n"); 2244 2245 out: 2246 __qede_unlock(edev); 2247 2248 coal->rx_coalesce_usecs = rx_coal; 2249 coal->tx_coalesce_usecs = tx_coal; 2250 2251 return rc; 2252 } 2253 2254 static const struct ethtool_ops qede_ethtool_ops = { 2255 .supported_coalesce_params = ETHTOOL_COALESCE_USECS, 2256 .get_link_ksettings = qede_get_link_ksettings, 2257 .set_link_ksettings = qede_set_link_ksettings, 2258 .get_drvinfo = qede_get_drvinfo, 2259 .get_regs_len = qede_get_regs_len, 2260 .get_regs = qede_get_regs, 2261 .get_wol = qede_get_wol, 2262 .set_wol = qede_set_wol, 2263 .get_msglevel = qede_get_msglevel, 2264 .set_msglevel = qede_set_msglevel, 2265 .nway_reset = qede_nway_reset, 2266 .get_link = qede_get_link, 2267 .get_coalesce = qede_get_coalesce, 2268 .set_coalesce = qede_set_coalesce, 2269 .get_ringparam = qede_get_ringparam, 2270 .set_ringparam = qede_set_ringparam, 2271 .get_pauseparam = qede_get_pauseparam, 2272 .set_pauseparam = qede_set_pauseparam, 2273 .get_strings = qede_get_strings, 2274 .set_phys_id = qede_set_phys_id, 2275 .get_ethtool_stats = qede_get_ethtool_stats, 2276 .get_priv_flags = qede_get_priv_flags, 2277 .set_priv_flags = qede_set_priv_flags, 2278 .get_sset_count = qede_get_sset_count, 2279 .get_rxnfc = qede_get_rxnfc, 2280 .set_rxnfc = qede_set_rxnfc, 2281 .get_rxfh_indir_size = qede_get_rxfh_indir_size, 2282 .get_rxfh_key_size = qede_get_rxfh_key_size, 2283 .get_rxfh = qede_get_rxfh, 2284 .set_rxfh = qede_set_rxfh, 2285 .get_ts_info = qede_get_ts_info, 2286 .get_channels = qede_get_channels, 2287 .set_channels = qede_set_channels, 2288 .self_test = qede_self_test, 2289 .get_module_info = qede_get_module_info, 2290 .get_module_eeprom = qede_get_module_eeprom, 2291 .get_eee = qede_get_eee, 2292 .set_eee = qede_set_eee, 2293 .get_fecparam = qede_get_fecparam, 2294 .set_fecparam = qede_set_fecparam, 2295 .get_tunable = qede_get_tunable, 2296 .set_tunable = qede_set_tunable, 2297 .get_per_queue_coalesce = qede_get_per_coalesce, 2298 .set_per_queue_coalesce = qede_set_per_coalesce, 2299 .flash_device = qede_flash_device, 2300 .get_dump_flag = qede_get_dump_flag, 2301 .get_dump_data = qede_get_dump_data, 2302 .set_dump = qede_set_dump, 2303 }; 2304 2305 static const struct ethtool_ops qede_vf_ethtool_ops = { 2306 .supported_coalesce_params = ETHTOOL_COALESCE_USECS, 2307 .get_link_ksettings = qede_get_link_ksettings, 2308 .get_drvinfo = qede_get_drvinfo, 2309 .get_msglevel = qede_get_msglevel, 2310 .set_msglevel = qede_set_msglevel, 2311 .get_link = qede_get_link, 2312 .get_coalesce = qede_get_coalesce, 2313 .set_coalesce = qede_set_coalesce, 2314 .get_ringparam = qede_get_ringparam, 2315 .set_ringparam = qede_set_ringparam, 2316 .get_strings = qede_get_strings, 2317 .get_ethtool_stats = qede_get_ethtool_stats, 2318 .get_priv_flags = qede_get_priv_flags, 2319 .get_sset_count = qede_get_sset_count, 2320 .get_rxnfc = qede_get_rxnfc, 2321 .set_rxnfc = qede_set_rxnfc, 2322 .get_rxfh_indir_size = qede_get_rxfh_indir_size, 2323 .get_rxfh_key_size = qede_get_rxfh_key_size, 2324 .get_rxfh = qede_get_rxfh, 2325 .set_rxfh = qede_set_rxfh, 2326 .get_channels = qede_get_channels, 2327 .set_channels = qede_set_channels, 2328 .get_per_queue_coalesce = qede_get_per_coalesce, 2329 .set_per_queue_coalesce = qede_set_per_coalesce, 2330 .get_tunable = qede_get_tunable, 2331 .set_tunable = qede_set_tunable, 2332 }; 2333 2334 void qede_set_ethtool_ops(struct net_device *dev) 2335 { 2336 struct qede_dev *edev = netdev_priv(dev); 2337 2338 if (IS_VF(edev)) 2339 dev->ethtool_ops = &qede_vf_ethtool_ops; 2340 else 2341 dev->ethtool_ops = &qede_ethtool_ops; 2342 } 2343