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