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