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_STAT(tx_err_drop_pkts), 165 QEDE_STAT(ttl0_discard), 166 QEDE_STAT(packet_too_big_discard), 167 168 QEDE_STAT(coalesced_pkts), 169 QEDE_STAT(coalesced_events), 170 QEDE_STAT(coalesced_aborts_num), 171 QEDE_STAT(non_coalesced_pkts), 172 QEDE_STAT(coalesced_bytes), 173 }; 174 175 #define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr) 176 #define QEDE_STAT_IS_PF_ONLY(i) \ 177 test_bit(QEDE_STAT_PF_ONLY, &qede_stats_arr[i].attr) 178 #define QEDE_STAT_IS_BB_ONLY(i) \ 179 test_bit(QEDE_STAT_BB_ONLY, &qede_stats_arr[i].attr) 180 #define QEDE_STAT_IS_AH_ONLY(i) \ 181 test_bit(QEDE_STAT_AH_ONLY, &qede_stats_arr[i].attr) 182 183 enum { 184 QEDE_PRI_FLAG_CMT, 185 QEDE_PRI_FLAG_LEN, 186 }; 187 188 static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = { 189 "Coupled-Function", 190 }; 191 192 enum qede_ethtool_tests { 193 QEDE_ETHTOOL_INT_LOOPBACK, 194 QEDE_ETHTOOL_INTERRUPT_TEST, 195 QEDE_ETHTOOL_MEMORY_TEST, 196 QEDE_ETHTOOL_REGISTER_TEST, 197 QEDE_ETHTOOL_CLOCK_TEST, 198 QEDE_ETHTOOL_NVRAM_TEST, 199 QEDE_ETHTOOL_TEST_MAX 200 }; 201 202 static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = { 203 "Internal loopback (offline)", 204 "Interrupt (online)\t", 205 "Memory (online)\t\t", 206 "Register (online)\t", 207 "Clock (online)\t\t", 208 "Nvram (online)\t\t", 209 }; 210 211 static void qede_get_strings_stats_txq(struct qede_dev *edev, 212 struct qede_tx_queue *txq, u8 **buf) 213 { 214 int i; 215 216 for (i = 0; i < QEDE_NUM_TQSTATS; i++) { 217 if (txq->is_xdp) 218 sprintf(*buf, "%d [XDP]: %s", 219 QEDE_TXQ_XDP_TO_IDX(edev, txq), 220 qede_tqstats_arr[i].string); 221 else 222 sprintf(*buf, "%d: %s", txq->index, 223 qede_tqstats_arr[i].string); 224 *buf += ETH_GSTRING_LEN; 225 } 226 } 227 228 static void qede_get_strings_stats_rxq(struct qede_dev *edev, 229 struct qede_rx_queue *rxq, u8 **buf) 230 { 231 int i; 232 233 for (i = 0; i < QEDE_NUM_RQSTATS; i++) { 234 sprintf(*buf, "%d: %s", rxq->rxq_id, 235 qede_rqstats_arr[i].string); 236 *buf += ETH_GSTRING_LEN; 237 } 238 } 239 240 static bool qede_is_irrelevant_stat(struct qede_dev *edev, int stat_index) 241 { 242 return (IS_VF(edev) && QEDE_STAT_IS_PF_ONLY(stat_index)) || 243 (QEDE_IS_BB(edev) && QEDE_STAT_IS_AH_ONLY(stat_index)) || 244 (QEDE_IS_AH(edev) && QEDE_STAT_IS_BB_ONLY(stat_index)); 245 } 246 247 static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf) 248 { 249 struct qede_fastpath *fp; 250 int i; 251 252 /* Account for queue statistics */ 253 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) { 254 fp = &edev->fp_array[i]; 255 256 if (fp->type & QEDE_FASTPATH_RX) 257 qede_get_strings_stats_rxq(edev, fp->rxq, &buf); 258 259 if (fp->type & QEDE_FASTPATH_XDP) 260 qede_get_strings_stats_txq(edev, fp->xdp_tx, &buf); 261 262 if (fp->type & QEDE_FASTPATH_TX) 263 qede_get_strings_stats_txq(edev, fp->txq, &buf); 264 } 265 266 /* Account for non-queue statistics */ 267 for (i = 0; i < QEDE_NUM_STATS; i++) { 268 if (qede_is_irrelevant_stat(edev, i)) 269 continue; 270 strcpy(buf, qede_stats_arr[i].string); 271 buf += ETH_GSTRING_LEN; 272 } 273 } 274 275 static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf) 276 { 277 struct qede_dev *edev = netdev_priv(dev); 278 279 switch (stringset) { 280 case ETH_SS_STATS: 281 qede_get_strings_stats(edev, buf); 282 break; 283 case ETH_SS_PRIV_FLAGS: 284 memcpy(buf, qede_private_arr, 285 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN); 286 break; 287 case ETH_SS_TEST: 288 memcpy(buf, qede_tests_str_arr, 289 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX); 290 break; 291 default: 292 DP_VERBOSE(edev, QED_MSG_DEBUG, 293 "Unsupported stringset 0x%08x\n", stringset); 294 } 295 } 296 297 static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf) 298 { 299 int i; 300 301 for (i = 0; i < QEDE_NUM_TQSTATS; i++) { 302 **buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset)); 303 (*buf)++; 304 } 305 } 306 307 static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf) 308 { 309 int i; 310 311 for (i = 0; i < QEDE_NUM_RQSTATS; i++) { 312 **buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset)); 313 (*buf)++; 314 } 315 } 316 317 static void qede_get_ethtool_stats(struct net_device *dev, 318 struct ethtool_stats *stats, u64 *buf) 319 { 320 struct qede_dev *edev = netdev_priv(dev); 321 struct qede_fastpath *fp; 322 int i; 323 324 qede_fill_by_demand_stats(edev); 325 326 /* Need to protect the access to the fastpath array */ 327 __qede_lock(edev); 328 329 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) { 330 fp = &edev->fp_array[i]; 331 332 if (fp->type & QEDE_FASTPATH_RX) 333 qede_get_ethtool_stats_rxq(fp->rxq, &buf); 334 335 if (fp->type & QEDE_FASTPATH_XDP) 336 qede_get_ethtool_stats_txq(fp->xdp_tx, &buf); 337 338 if (fp->type & QEDE_FASTPATH_TX) 339 qede_get_ethtool_stats_txq(fp->txq, &buf); 340 } 341 342 for (i = 0; i < QEDE_NUM_STATS; i++) { 343 if (qede_is_irrelevant_stat(edev, i)) 344 continue; 345 *buf = *((u64 *)(((void *)&edev->stats) + 346 qede_stats_arr[i].offset)); 347 348 buf++; 349 } 350 351 __qede_unlock(edev); 352 } 353 354 static int qede_get_sset_count(struct net_device *dev, int stringset) 355 { 356 struct qede_dev *edev = netdev_priv(dev); 357 int num_stats = QEDE_NUM_STATS, i; 358 359 switch (stringset) { 360 case ETH_SS_STATS: 361 for (i = 0; i < QEDE_NUM_STATS; i++) 362 if (qede_is_irrelevant_stat(edev, i)) 363 num_stats--; 364 365 /* Account for the Regular Tx statistics */ 366 num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS; 367 368 /* Account for the Regular Rx statistics */ 369 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS; 370 371 /* Account for XDP statistics [if needed] */ 372 if (edev->xdp_prog) 373 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_TQSTATS; 374 return num_stats; 375 376 case ETH_SS_PRIV_FLAGS: 377 return QEDE_PRI_FLAG_LEN; 378 case ETH_SS_TEST: 379 if (!IS_VF(edev)) 380 return QEDE_ETHTOOL_TEST_MAX; 381 else 382 return 0; 383 default: 384 DP_VERBOSE(edev, QED_MSG_DEBUG, 385 "Unsupported stringset 0x%08x\n", stringset); 386 return -EINVAL; 387 } 388 } 389 390 static u32 qede_get_priv_flags(struct net_device *dev) 391 { 392 struct qede_dev *edev = netdev_priv(dev); 393 394 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT; 395 } 396 397 struct qede_link_mode_mapping { 398 u32 qed_link_mode; 399 u32 ethtool_link_mode; 400 }; 401 402 static const struct qede_link_mode_mapping qed_lm_map[] = { 403 {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT}, 404 {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT}, 405 {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT}, 406 {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT}, 407 {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT}, 408 {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT}, 409 {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT}, 410 {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT}, 411 {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT}, 412 {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT}, 413 {QED_LM_100000baseKR4_Full_BIT, 414 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT}, 415 }; 416 417 #define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \ 418 { \ 419 int i; \ 420 \ 421 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \ 422 if ((caps) & (qed_lm_map[i].qed_link_mode)) \ 423 __set_bit(qed_lm_map[i].ethtool_link_mode,\ 424 lk_ksettings->link_modes.name); \ 425 } \ 426 } 427 428 #define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \ 429 { \ 430 int i; \ 431 \ 432 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \ 433 if (test_bit(qed_lm_map[i].ethtool_link_mode, \ 434 lk_ksettings->link_modes.name)) \ 435 caps |= qed_lm_map[i].qed_link_mode; \ 436 } \ 437 } 438 439 static int qede_get_link_ksettings(struct net_device *dev, 440 struct ethtool_link_ksettings *cmd) 441 { 442 struct ethtool_link_settings *base = &cmd->base; 443 struct qede_dev *edev = netdev_priv(dev); 444 struct qed_link_output current_link; 445 446 __qede_lock(edev); 447 448 memset(¤t_link, 0, sizeof(current_link)); 449 edev->ops->common->get_link(edev->cdev, ¤t_link); 450 451 ethtool_link_ksettings_zero_link_mode(cmd, supported); 452 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported) 453 454 ethtool_link_ksettings_zero_link_mode(cmd, advertising); 455 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising) 456 457 ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising); 458 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising) 459 460 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) { 461 base->speed = current_link.speed; 462 base->duplex = current_link.duplex; 463 } else { 464 base->speed = SPEED_UNKNOWN; 465 base->duplex = DUPLEX_UNKNOWN; 466 } 467 468 __qede_unlock(edev); 469 470 base->port = current_link.port; 471 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE : 472 AUTONEG_DISABLE; 473 474 return 0; 475 } 476 477 static int qede_set_link_ksettings(struct net_device *dev, 478 const struct ethtool_link_ksettings *cmd) 479 { 480 const struct ethtool_link_settings *base = &cmd->base; 481 struct qede_dev *edev = netdev_priv(dev); 482 struct qed_link_output current_link; 483 struct qed_link_params params; 484 485 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) { 486 DP_INFO(edev, "Link settings are not allowed to be changed\n"); 487 return -EOPNOTSUPP; 488 } 489 memset(¤t_link, 0, sizeof(current_link)); 490 memset(¶ms, 0, sizeof(params)); 491 edev->ops->common->get_link(edev->cdev, ¤t_link); 492 493 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS; 494 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG; 495 if (base->autoneg == AUTONEG_ENABLE) { 496 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) { 497 DP_INFO(edev, "Auto negotiation is not supported\n"); 498 return -EOPNOTSUPP; 499 } 500 501 params.autoneg = true; 502 params.forced_speed = 0; 503 QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising) 504 } else { /* forced speed */ 505 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED; 506 params.autoneg = false; 507 params.forced_speed = base->speed; 508 switch (base->speed) { 509 case SPEED_10000: 510 if (!(current_link.supported_caps & 511 QED_LM_10000baseKR_Full_BIT)) { 512 DP_INFO(edev, "10G speed not supported\n"); 513 return -EINVAL; 514 } 515 params.adv_speeds = QED_LM_10000baseKR_Full_BIT; 516 break; 517 case SPEED_25000: 518 if (!(current_link.supported_caps & 519 QED_LM_25000baseKR_Full_BIT)) { 520 DP_INFO(edev, "25G speed not supported\n"); 521 return -EINVAL; 522 } 523 params.adv_speeds = QED_LM_25000baseKR_Full_BIT; 524 break; 525 case SPEED_40000: 526 if (!(current_link.supported_caps & 527 QED_LM_40000baseLR4_Full_BIT)) { 528 DP_INFO(edev, "40G speed not supported\n"); 529 return -EINVAL; 530 } 531 params.adv_speeds = QED_LM_40000baseLR4_Full_BIT; 532 break; 533 case SPEED_50000: 534 if (!(current_link.supported_caps & 535 QED_LM_50000baseKR2_Full_BIT)) { 536 DP_INFO(edev, "50G speed not supported\n"); 537 return -EINVAL; 538 } 539 params.adv_speeds = QED_LM_50000baseKR2_Full_BIT; 540 break; 541 case SPEED_100000: 542 if (!(current_link.supported_caps & 543 QED_LM_100000baseKR4_Full_BIT)) { 544 DP_INFO(edev, "100G speed not supported\n"); 545 return -EINVAL; 546 } 547 params.adv_speeds = QED_LM_100000baseKR4_Full_BIT; 548 break; 549 default: 550 DP_INFO(edev, "Unsupported speed %u\n", base->speed); 551 return -EINVAL; 552 } 553 } 554 555 params.link_up = true; 556 edev->ops->common->set_link(edev->cdev, ¶ms); 557 558 return 0; 559 } 560 561 static void qede_get_drvinfo(struct net_device *ndev, 562 struct ethtool_drvinfo *info) 563 { 564 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN]; 565 struct qede_dev *edev = netdev_priv(ndev); 566 567 strlcpy(info->driver, "qede", sizeof(info->driver)); 568 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); 569 570 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d", 571 edev->dev_info.common.fw_major, 572 edev->dev_info.common.fw_minor, 573 edev->dev_info.common.fw_rev, 574 edev->dev_info.common.fw_eng); 575 576 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d", 577 (edev->dev_info.common.mfw_rev >> 24) & 0xFF, 578 (edev->dev_info.common.mfw_rev >> 16) & 0xFF, 579 (edev->dev_info.common.mfw_rev >> 8) & 0xFF, 580 edev->dev_info.common.mfw_rev & 0xFF); 581 582 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) < 583 sizeof(info->fw_version)) { 584 snprintf(info->fw_version, sizeof(info->fw_version), 585 "mfw %s storm %s", mfw, storm); 586 } else { 587 snprintf(info->fw_version, sizeof(info->fw_version), 588 "%s %s", mfw, storm); 589 } 590 591 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info)); 592 } 593 594 static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) 595 { 596 struct qede_dev *edev = netdev_priv(ndev); 597 598 if (edev->dev_info.common.wol_support) { 599 wol->supported = WAKE_MAGIC; 600 wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0; 601 } 602 } 603 604 static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) 605 { 606 struct qede_dev *edev = netdev_priv(ndev); 607 bool wol_requested; 608 int rc; 609 610 if (wol->wolopts & ~WAKE_MAGIC) { 611 DP_INFO(edev, 612 "Can't support WoL options other than magic-packet\n"); 613 return -EINVAL; 614 } 615 616 wol_requested = !!(wol->wolopts & WAKE_MAGIC); 617 if (wol_requested == edev->wol_enabled) 618 return 0; 619 620 /* Need to actually change configuration */ 621 if (!edev->dev_info.common.wol_support) { 622 DP_INFO(edev, "Device doesn't support WoL\n"); 623 return -EINVAL; 624 } 625 626 rc = edev->ops->common->update_wol(edev->cdev, wol_requested); 627 if (!rc) 628 edev->wol_enabled = wol_requested; 629 630 return rc; 631 } 632 633 static u32 qede_get_msglevel(struct net_device *ndev) 634 { 635 struct qede_dev *edev = netdev_priv(ndev); 636 637 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module; 638 } 639 640 static void qede_set_msglevel(struct net_device *ndev, u32 level) 641 { 642 struct qede_dev *edev = netdev_priv(ndev); 643 u32 dp_module = 0; 644 u8 dp_level = 0; 645 646 qede_config_debug(level, &dp_module, &dp_level); 647 648 edev->dp_level = dp_level; 649 edev->dp_module = dp_module; 650 edev->ops->common->update_msglvl(edev->cdev, 651 dp_module, dp_level); 652 } 653 654 static int qede_nway_reset(struct net_device *dev) 655 { 656 struct qede_dev *edev = netdev_priv(dev); 657 struct qed_link_output current_link; 658 struct qed_link_params link_params; 659 660 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) { 661 DP_INFO(edev, "Link settings are not allowed to be changed\n"); 662 return -EOPNOTSUPP; 663 } 664 665 if (!netif_running(dev)) 666 return 0; 667 668 memset(¤t_link, 0, sizeof(current_link)); 669 edev->ops->common->get_link(edev->cdev, ¤t_link); 670 if (!current_link.link_up) 671 return 0; 672 673 /* Toggle the link */ 674 memset(&link_params, 0, sizeof(link_params)); 675 link_params.link_up = false; 676 edev->ops->common->set_link(edev->cdev, &link_params); 677 link_params.link_up = true; 678 edev->ops->common->set_link(edev->cdev, &link_params); 679 680 return 0; 681 } 682 683 static u32 qede_get_link(struct net_device *dev) 684 { 685 struct qede_dev *edev = netdev_priv(dev); 686 struct qed_link_output current_link; 687 688 memset(¤t_link, 0, sizeof(current_link)); 689 edev->ops->common->get_link(edev->cdev, ¤t_link); 690 691 return current_link.link_up; 692 } 693 694 static int qede_get_coalesce(struct net_device *dev, 695 struct ethtool_coalesce *coal) 696 { 697 struct qede_dev *edev = netdev_priv(dev); 698 u16 rxc, txc; 699 700 memset(coal, 0, sizeof(struct ethtool_coalesce)); 701 edev->ops->common->get_coalesce(edev->cdev, &rxc, &txc); 702 703 coal->rx_coalesce_usecs = rxc; 704 coal->tx_coalesce_usecs = txc; 705 706 return 0; 707 } 708 709 static int qede_set_coalesce(struct net_device *dev, 710 struct ethtool_coalesce *coal) 711 { 712 struct qede_dev *edev = netdev_priv(dev); 713 int i, rc = 0; 714 u16 rxc, txc, sb_id; 715 716 if (!netif_running(dev)) { 717 DP_INFO(edev, "Interface is down\n"); 718 return -EINVAL; 719 } 720 721 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX || 722 coal->tx_coalesce_usecs > QED_COALESCE_MAX) { 723 DP_INFO(edev, 724 "Can't support requested %s coalesce value [max supported value %d]\n", 725 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx" 726 : "tx", 727 QED_COALESCE_MAX); 728 return -EINVAL; 729 } 730 731 rxc = (u16)coal->rx_coalesce_usecs; 732 txc = (u16)coal->tx_coalesce_usecs; 733 for_each_queue(i) { 734 sb_id = edev->fp_array[i].sb_info->igu_sb_id; 735 rc = edev->ops->common->set_coalesce(edev->cdev, rxc, txc, 736 (u16)i, sb_id); 737 if (rc) { 738 DP_INFO(edev, "Set coalesce error, rc = %d\n", rc); 739 return rc; 740 } 741 } 742 743 return rc; 744 } 745 746 static void qede_get_ringparam(struct net_device *dev, 747 struct ethtool_ringparam *ering) 748 { 749 struct qede_dev *edev = netdev_priv(dev); 750 751 ering->rx_max_pending = NUM_RX_BDS_MAX; 752 ering->rx_pending = edev->q_num_rx_buffers; 753 ering->tx_max_pending = NUM_TX_BDS_MAX; 754 ering->tx_pending = edev->q_num_tx_buffers; 755 } 756 757 static int qede_set_ringparam(struct net_device *dev, 758 struct ethtool_ringparam *ering) 759 { 760 struct qede_dev *edev = netdev_priv(dev); 761 762 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 763 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n", 764 ering->rx_pending, ering->tx_pending); 765 766 /* Validate legality of configuration */ 767 if (ering->rx_pending > NUM_RX_BDS_MAX || 768 ering->rx_pending < NUM_RX_BDS_MIN || 769 ering->tx_pending > NUM_TX_BDS_MAX || 770 ering->tx_pending < NUM_TX_BDS_MIN) { 771 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 772 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n", 773 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX, 774 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX); 775 return -EINVAL; 776 } 777 778 /* Change ring size and re-load */ 779 edev->q_num_rx_buffers = ering->rx_pending; 780 edev->q_num_tx_buffers = ering->tx_pending; 781 782 qede_reload(edev, NULL, false); 783 784 return 0; 785 } 786 787 static void qede_get_pauseparam(struct net_device *dev, 788 struct ethtool_pauseparam *epause) 789 { 790 struct qede_dev *edev = netdev_priv(dev); 791 struct qed_link_output current_link; 792 793 memset(¤t_link, 0, sizeof(current_link)); 794 edev->ops->common->get_link(edev->cdev, ¤t_link); 795 796 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE) 797 epause->autoneg = true; 798 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE) 799 epause->rx_pause = true; 800 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE) 801 epause->tx_pause = true; 802 803 DP_VERBOSE(edev, QED_MSG_DEBUG, 804 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n", 805 epause->cmd, epause->autoneg, epause->rx_pause, 806 epause->tx_pause); 807 } 808 809 static int qede_set_pauseparam(struct net_device *dev, 810 struct ethtool_pauseparam *epause) 811 { 812 struct qede_dev *edev = netdev_priv(dev); 813 struct qed_link_params params; 814 struct qed_link_output current_link; 815 816 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) { 817 DP_INFO(edev, 818 "Pause settings are not allowed to be changed\n"); 819 return -EOPNOTSUPP; 820 } 821 822 memset(¤t_link, 0, sizeof(current_link)); 823 edev->ops->common->get_link(edev->cdev, ¤t_link); 824 825 memset(¶ms, 0, sizeof(params)); 826 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG; 827 if (epause->autoneg) { 828 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) { 829 DP_INFO(edev, "autoneg not supported\n"); 830 return -EINVAL; 831 } 832 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE; 833 } 834 if (epause->rx_pause) 835 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE; 836 if (epause->tx_pause) 837 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE; 838 839 params.link_up = true; 840 edev->ops->common->set_link(edev->cdev, ¶ms); 841 842 return 0; 843 } 844 845 static void qede_get_regs(struct net_device *ndev, 846 struct ethtool_regs *regs, void *buffer) 847 { 848 struct qede_dev *edev = netdev_priv(ndev); 849 850 regs->version = 0; 851 memset(buffer, 0, regs->len); 852 853 if (edev->ops && edev->ops->common) 854 edev->ops->common->dbg_all_data(edev->cdev, buffer); 855 } 856 857 static int qede_get_regs_len(struct net_device *ndev) 858 { 859 struct qede_dev *edev = netdev_priv(ndev); 860 861 if (edev->ops && edev->ops->common) 862 return edev->ops->common->dbg_all_data_size(edev->cdev); 863 else 864 return -EINVAL; 865 } 866 867 static void qede_update_mtu(struct qede_dev *edev, 868 struct qede_reload_args *args) 869 { 870 edev->ndev->mtu = args->u.mtu; 871 } 872 873 /* Netdevice NDOs */ 874 int qede_change_mtu(struct net_device *ndev, int new_mtu) 875 { 876 struct qede_dev *edev = netdev_priv(ndev); 877 struct qede_reload_args args; 878 879 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 880 "Configuring MTU size of %d\n", new_mtu); 881 882 /* Set the mtu field and re-start the interface if needed */ 883 args.u.mtu = new_mtu; 884 args.func = &qede_update_mtu; 885 qede_reload(edev, &args, false); 886 887 edev->ops->common->update_mtu(edev->cdev, new_mtu); 888 889 return 0; 890 } 891 892 static void qede_get_channels(struct net_device *dev, 893 struct ethtool_channels *channels) 894 { 895 struct qede_dev *edev = netdev_priv(dev); 896 897 channels->max_combined = QEDE_MAX_RSS_CNT(edev); 898 channels->max_rx = QEDE_MAX_RSS_CNT(edev); 899 channels->max_tx = QEDE_MAX_RSS_CNT(edev); 900 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx - 901 edev->fp_num_rx; 902 channels->tx_count = edev->fp_num_tx; 903 channels->rx_count = edev->fp_num_rx; 904 } 905 906 static int qede_set_channels(struct net_device *dev, 907 struct ethtool_channels *channels) 908 { 909 struct qede_dev *edev = netdev_priv(dev); 910 u32 count; 911 912 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 913 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n", 914 channels->rx_count, channels->tx_count, 915 channels->other_count, channels->combined_count); 916 917 count = channels->rx_count + channels->tx_count + 918 channels->combined_count; 919 920 /* We don't support `other' channels */ 921 if (channels->other_count) { 922 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 923 "command parameters not supported\n"); 924 return -EINVAL; 925 } 926 927 if (!(channels->combined_count || (channels->rx_count && 928 channels->tx_count))) { 929 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 930 "need to request at least one transmit and one receive channel\n"); 931 return -EINVAL; 932 } 933 934 if (count > QEDE_MAX_RSS_CNT(edev)) { 935 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 936 "requested channels = %d max supported channels = %d\n", 937 count, QEDE_MAX_RSS_CNT(edev)); 938 return -EINVAL; 939 } 940 941 /* Check if there was a change in the active parameters */ 942 if ((count == QEDE_QUEUE_CNT(edev)) && 943 (channels->tx_count == edev->fp_num_tx) && 944 (channels->rx_count == edev->fp_num_rx)) { 945 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 946 "No change in active parameters\n"); 947 return 0; 948 } 949 950 /* We need the number of queues to be divisible between the hwfns */ 951 if ((count % edev->dev_info.common.num_hwfns) || 952 (channels->tx_count % edev->dev_info.common.num_hwfns) || 953 (channels->rx_count % edev->dev_info.common.num_hwfns)) { 954 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), 955 "Number of channels must be divisible by %04x\n", 956 edev->dev_info.common.num_hwfns); 957 return -EINVAL; 958 } 959 960 /* Set number of queues and reload if necessary */ 961 edev->req_queues = count; 962 edev->req_num_tx = channels->tx_count; 963 edev->req_num_rx = channels->rx_count; 964 /* Reset the indirection table if rx queue count is updated */ 965 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) { 966 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED; 967 memset(edev->rss_ind_table, 0, sizeof(edev->rss_ind_table)); 968 } 969 970 qede_reload(edev, NULL, false); 971 972 return 0; 973 } 974 975 static int qede_get_ts_info(struct net_device *dev, 976 struct ethtool_ts_info *info) 977 { 978 struct qede_dev *edev = netdev_priv(dev); 979 980 return qede_ptp_get_ts_info(edev, info); 981 } 982 983 static int qede_set_phys_id(struct net_device *dev, 984 enum ethtool_phys_id_state state) 985 { 986 struct qede_dev *edev = netdev_priv(dev); 987 u8 led_state = 0; 988 989 switch (state) { 990 case ETHTOOL_ID_ACTIVE: 991 return 1; /* cycle on/off once per second */ 992 993 case ETHTOOL_ID_ON: 994 led_state = QED_LED_MODE_ON; 995 break; 996 997 case ETHTOOL_ID_OFF: 998 led_state = QED_LED_MODE_OFF; 999 break; 1000 1001 case ETHTOOL_ID_INACTIVE: 1002 led_state = QED_LED_MODE_RESTORE; 1003 break; 1004 } 1005 1006 edev->ops->common->set_led(edev->cdev, led_state); 1007 1008 return 0; 1009 } 1010 1011 static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info) 1012 { 1013 info->data = RXH_IP_SRC | RXH_IP_DST; 1014 1015 switch (info->flow_type) { 1016 case TCP_V4_FLOW: 1017 case TCP_V6_FLOW: 1018 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 1019 break; 1020 case UDP_V4_FLOW: 1021 if (edev->rss_caps & QED_RSS_IPV4_UDP) 1022 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 1023 break; 1024 case UDP_V6_FLOW: 1025 if (edev->rss_caps & QED_RSS_IPV6_UDP) 1026 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 1027 break; 1028 case IPV4_FLOW: 1029 case IPV6_FLOW: 1030 break; 1031 default: 1032 info->data = 0; 1033 break; 1034 } 1035 1036 return 0; 1037 } 1038 1039 static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info, 1040 u32 *rules __always_unused) 1041 { 1042 struct qede_dev *edev = netdev_priv(dev); 1043 1044 switch (info->cmd) { 1045 case ETHTOOL_GRXRINGS: 1046 info->data = QEDE_RSS_COUNT(edev); 1047 return 0; 1048 case ETHTOOL_GRXFH: 1049 return qede_get_rss_flags(edev, info); 1050 default: 1051 DP_ERR(edev, "Command parameters not supported\n"); 1052 return -EOPNOTSUPP; 1053 } 1054 } 1055 1056 static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info) 1057 { 1058 struct qed_update_vport_params *vport_update_params; 1059 u8 set_caps = 0, clr_caps = 0; 1060 int rc = 0; 1061 1062 DP_VERBOSE(edev, QED_MSG_DEBUG, 1063 "Set rss flags command parameters: flow type = %d, data = %llu\n", 1064 info->flow_type, info->data); 1065 1066 switch (info->flow_type) { 1067 case TCP_V4_FLOW: 1068 case TCP_V6_FLOW: 1069 /* For TCP only 4-tuple hash is supported */ 1070 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST | 1071 RXH_L4_B_0_1 | RXH_L4_B_2_3)) { 1072 DP_INFO(edev, "Command parameters not supported\n"); 1073 return -EINVAL; 1074 } 1075 return 0; 1076 case UDP_V4_FLOW: 1077 /* For UDP either 2-tuple hash or 4-tuple hash is supported */ 1078 if (info->data == (RXH_IP_SRC | RXH_IP_DST | 1079 RXH_L4_B_0_1 | RXH_L4_B_2_3)) { 1080 set_caps = QED_RSS_IPV4_UDP; 1081 DP_VERBOSE(edev, QED_MSG_DEBUG, 1082 "UDP 4-tuple enabled\n"); 1083 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) { 1084 clr_caps = QED_RSS_IPV4_UDP; 1085 DP_VERBOSE(edev, QED_MSG_DEBUG, 1086 "UDP 4-tuple disabled\n"); 1087 } else { 1088 return -EINVAL; 1089 } 1090 break; 1091 case UDP_V6_FLOW: 1092 /* For UDP either 2-tuple hash or 4-tuple hash is supported */ 1093 if (info->data == (RXH_IP_SRC | RXH_IP_DST | 1094 RXH_L4_B_0_1 | RXH_L4_B_2_3)) { 1095 set_caps = QED_RSS_IPV6_UDP; 1096 DP_VERBOSE(edev, QED_MSG_DEBUG, 1097 "UDP 4-tuple enabled\n"); 1098 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) { 1099 clr_caps = QED_RSS_IPV6_UDP; 1100 DP_VERBOSE(edev, QED_MSG_DEBUG, 1101 "UDP 4-tuple disabled\n"); 1102 } else { 1103 return -EINVAL; 1104 } 1105 break; 1106 case IPV4_FLOW: 1107 case IPV6_FLOW: 1108 /* For IP only 2-tuple hash is supported */ 1109 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) { 1110 DP_INFO(edev, "Command parameters not supported\n"); 1111 return -EINVAL; 1112 } 1113 return 0; 1114 case SCTP_V4_FLOW: 1115 case AH_ESP_V4_FLOW: 1116 case AH_V4_FLOW: 1117 case ESP_V4_FLOW: 1118 case SCTP_V6_FLOW: 1119 case AH_ESP_V6_FLOW: 1120 case AH_V6_FLOW: 1121 case ESP_V6_FLOW: 1122 case IP_USER_FLOW: 1123 case ETHER_FLOW: 1124 /* RSS is not supported for these protocols */ 1125 if (info->data) { 1126 DP_INFO(edev, "Command parameters not supported\n"); 1127 return -EINVAL; 1128 } 1129 return 0; 1130 default: 1131 return -EINVAL; 1132 } 1133 1134 /* No action is needed if there is no change in the rss capability */ 1135 if (edev->rss_caps == ((edev->rss_caps & ~clr_caps) | set_caps)) 1136 return 0; 1137 1138 /* Update internal configuration */ 1139 edev->rss_caps = ((edev->rss_caps & ~clr_caps) | set_caps); 1140 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED; 1141 1142 /* Re-configure if possible */ 1143 __qede_lock(edev); 1144 if (edev->state == QEDE_STATE_OPEN) { 1145 vport_update_params = vzalloc(sizeof(*vport_update_params)); 1146 if (!vport_update_params) { 1147 __qede_unlock(edev); 1148 return -ENOMEM; 1149 } 1150 qede_fill_rss_params(edev, &vport_update_params->rss_params, 1151 &vport_update_params->update_rss_flg); 1152 rc = edev->ops->vport_update(edev->cdev, vport_update_params); 1153 vfree(vport_update_params); 1154 } 1155 __qede_unlock(edev); 1156 1157 return rc; 1158 } 1159 1160 static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info) 1161 { 1162 struct qede_dev *edev = netdev_priv(dev); 1163 1164 switch (info->cmd) { 1165 case ETHTOOL_SRXFH: 1166 return qede_set_rss_flags(edev, info); 1167 default: 1168 DP_INFO(edev, "Command parameters not supported\n"); 1169 return -EOPNOTSUPP; 1170 } 1171 } 1172 1173 static u32 qede_get_rxfh_indir_size(struct net_device *dev) 1174 { 1175 return QED_RSS_IND_TABLE_SIZE; 1176 } 1177 1178 static u32 qede_get_rxfh_key_size(struct net_device *dev) 1179 { 1180 struct qede_dev *edev = netdev_priv(dev); 1181 1182 return sizeof(edev->rss_key); 1183 } 1184 1185 static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc) 1186 { 1187 struct qede_dev *edev = netdev_priv(dev); 1188 int i; 1189 1190 if (hfunc) 1191 *hfunc = ETH_RSS_HASH_TOP; 1192 1193 if (!indir) 1194 return 0; 1195 1196 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) 1197 indir[i] = edev->rss_ind_table[i]; 1198 1199 if (key) 1200 memcpy(key, edev->rss_key, qede_get_rxfh_key_size(dev)); 1201 1202 return 0; 1203 } 1204 1205 static int qede_set_rxfh(struct net_device *dev, const u32 *indir, 1206 const u8 *key, const u8 hfunc) 1207 { 1208 struct qed_update_vport_params *vport_update_params; 1209 struct qede_dev *edev = netdev_priv(dev); 1210 int i, rc = 0; 1211 1212 if (edev->dev_info.common.num_hwfns > 1) { 1213 DP_INFO(edev, 1214 "RSS configuration is not supported for 100G devices\n"); 1215 return -EOPNOTSUPP; 1216 } 1217 1218 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) 1219 return -EOPNOTSUPP; 1220 1221 if (!indir && !key) 1222 return 0; 1223 1224 if (indir) { 1225 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) 1226 edev->rss_ind_table[i] = indir[i]; 1227 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED; 1228 } 1229 1230 if (key) { 1231 memcpy(&edev->rss_key, key, qede_get_rxfh_key_size(dev)); 1232 edev->rss_params_inited |= QEDE_RSS_KEY_INITED; 1233 } 1234 1235 __qede_lock(edev); 1236 if (edev->state == QEDE_STATE_OPEN) { 1237 vport_update_params = vzalloc(sizeof(*vport_update_params)); 1238 if (!vport_update_params) { 1239 __qede_unlock(edev); 1240 return -ENOMEM; 1241 } 1242 qede_fill_rss_params(edev, &vport_update_params->rss_params, 1243 &vport_update_params->update_rss_flg); 1244 rc = edev->ops->vport_update(edev->cdev, vport_update_params); 1245 vfree(vport_update_params); 1246 } 1247 __qede_unlock(edev); 1248 1249 return rc; 1250 } 1251 1252 /* This function enables the interrupt generation and the NAPI on the device */ 1253 static void qede_netif_start(struct qede_dev *edev) 1254 { 1255 int i; 1256 1257 if (!netif_running(edev->ndev)) 1258 return; 1259 1260 for_each_queue(i) { 1261 /* Update and reenable interrupts */ 1262 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1); 1263 napi_enable(&edev->fp_array[i].napi); 1264 } 1265 } 1266 1267 /* This function disables the NAPI and the interrupt generation on the device */ 1268 static void qede_netif_stop(struct qede_dev *edev) 1269 { 1270 int i; 1271 1272 for_each_queue(i) { 1273 napi_disable(&edev->fp_array[i].napi); 1274 /* Disable interrupts */ 1275 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0); 1276 } 1277 } 1278 1279 static int qede_selftest_transmit_traffic(struct qede_dev *edev, 1280 struct sk_buff *skb) 1281 { 1282 struct qede_tx_queue *txq = NULL; 1283 struct eth_tx_1st_bd *first_bd; 1284 dma_addr_t mapping; 1285 int i, idx, val; 1286 1287 for_each_queue(i) { 1288 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) { 1289 txq = edev->fp_array[i].txq; 1290 break; 1291 } 1292 } 1293 1294 if (!txq) { 1295 DP_NOTICE(edev, "Tx path is not available\n"); 1296 return -1; 1297 } 1298 1299 /* Fill the entry in the SW ring and the BDs in the FW ring */ 1300 idx = txq->sw_tx_prod & NUM_TX_BDS_MAX; 1301 txq->sw_tx_ring.skbs[idx].skb = skb; 1302 first_bd = qed_chain_produce(&txq->tx_pbl); 1303 memset(first_bd, 0, sizeof(*first_bd)); 1304 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT; 1305 first_bd->data.bd_flags.bitfields = val; 1306 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK; 1307 first_bd->data.bitfields |= (val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT); 1308 1309 /* Map skb linear data for DMA and set in the first BD */ 1310 mapping = dma_map_single(&edev->pdev->dev, skb->data, 1311 skb_headlen(skb), DMA_TO_DEVICE); 1312 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) { 1313 DP_NOTICE(edev, "SKB mapping failed\n"); 1314 return -ENOMEM; 1315 } 1316 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb)); 1317 1318 /* update the first BD with the actual num BDs */ 1319 first_bd->data.nbds = 1; 1320 txq->sw_tx_prod++; 1321 /* 'next page' entries are counted in the producer value */ 1322 val = cpu_to_le16(qed_chain_get_prod_idx(&txq->tx_pbl)); 1323 txq->tx_db.data.bd_prod = val; 1324 1325 /* wmb makes sure that the BDs data is updated before updating the 1326 * producer, otherwise FW may read old data from the BDs. 1327 */ 1328 wmb(); 1329 barrier(); 1330 writel(txq->tx_db.raw, txq->doorbell_addr); 1331 1332 /* mmiowb is needed to synchronize doorbell writes from more than one 1333 * processor. It guarantees that the write arrives to the device before 1334 * the queue lock is released and another start_xmit is called (possibly 1335 * on another CPU). Without this barrier, the next doorbell can bypass 1336 * this doorbell. This is applicable to IA64/Altix systems. 1337 */ 1338 mmiowb(); 1339 1340 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) { 1341 if (qede_txq_has_work(txq)) 1342 break; 1343 usleep_range(100, 200); 1344 } 1345 1346 if (!qede_txq_has_work(txq)) { 1347 DP_NOTICE(edev, "Tx completion didn't happen\n"); 1348 return -1; 1349 } 1350 1351 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl); 1352 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd), 1353 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE); 1354 txq->sw_tx_cons++; 1355 txq->sw_tx_ring.skbs[idx].skb = NULL; 1356 1357 return 0; 1358 } 1359 1360 static int qede_selftest_receive_traffic(struct qede_dev *edev) 1361 { 1362 u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len; 1363 struct eth_fast_path_rx_reg_cqe *fp_cqe; 1364 struct qede_rx_queue *rxq = NULL; 1365 struct sw_rx_data *sw_rx_data; 1366 union eth_rx_cqe *cqe; 1367 int i, iter, rc = 0; 1368 u8 *data_ptr; 1369 1370 for_each_queue(i) { 1371 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) { 1372 rxq = edev->fp_array[i].rxq; 1373 break; 1374 } 1375 } 1376 1377 if (!rxq) { 1378 DP_NOTICE(edev, "Rx path is not available\n"); 1379 return -1; 1380 } 1381 1382 /* The packet is expected to receive on rx-queue 0 even though RSS is 1383 * enabled. This is because the queue 0 is configured as the default 1384 * queue and that the loopback traffic is not IP. 1385 */ 1386 for (iter = 0; iter < QEDE_SELFTEST_POLL_COUNT; iter++) { 1387 if (!qede_has_rx_work(rxq)) { 1388 usleep_range(100, 200); 1389 continue; 1390 } 1391 1392 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr); 1393 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring); 1394 1395 /* Memory barrier to prevent the CPU from doing speculative 1396 * reads of CQE/BD before reading hw_comp_cons. If the CQE is 1397 * read before it is written by FW, then FW writes CQE and SB, 1398 * and then the CPU reads the hw_comp_cons, it will use an old 1399 * CQE. 1400 */ 1401 rmb(); 1402 1403 /* Get the CQE from the completion ring */ 1404 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring); 1405 1406 /* Get the data from the SW ring */ 1407 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX; 1408 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index]; 1409 fp_cqe = &cqe->fast_path_regular; 1410 len = le16_to_cpu(fp_cqe->len_on_first_bd); 1411 data_ptr = (u8 *)(page_address(sw_rx_data->data) + 1412 fp_cqe->placement_offset + 1413 sw_rx_data->page_offset); 1414 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) && 1415 ether_addr_equal(data_ptr + ETH_ALEN, 1416 edev->ndev->dev_addr)) { 1417 for (i = ETH_HLEN; i < len; i++) 1418 if (data_ptr[i] != (unsigned char)(i & 0xff)) { 1419 rc = -1; 1420 break; 1421 } 1422 1423 qede_recycle_rx_bd_ring(rxq, 1); 1424 qed_chain_recycle_consumed(&rxq->rx_comp_ring); 1425 break; 1426 } 1427 1428 DP_INFO(edev, "Not the transmitted packet\n"); 1429 qede_recycle_rx_bd_ring(rxq, 1); 1430 qed_chain_recycle_consumed(&rxq->rx_comp_ring); 1431 } 1432 1433 if (iter == QEDE_SELFTEST_POLL_COUNT) { 1434 DP_NOTICE(edev, "Failed to receive the traffic\n"); 1435 return -1; 1436 } 1437 1438 qede_update_rx_prod(edev, rxq); 1439 1440 return rc; 1441 } 1442 1443 static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode) 1444 { 1445 struct qed_link_params link_params; 1446 struct sk_buff *skb = NULL; 1447 int rc = 0, i; 1448 u32 pkt_size; 1449 u8 *packet; 1450 1451 if (!netif_running(edev->ndev)) { 1452 DP_NOTICE(edev, "Interface is down\n"); 1453 return -EINVAL; 1454 } 1455 1456 qede_netif_stop(edev); 1457 1458 /* Bring up the link in Loopback mode */ 1459 memset(&link_params, 0, sizeof(link_params)); 1460 link_params.link_up = true; 1461 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE; 1462 link_params.loopback_mode = loopback_mode; 1463 edev->ops->common->set_link(edev->cdev, &link_params); 1464 1465 /* Wait for loopback configuration to apply */ 1466 msleep_interruptible(500); 1467 1468 /* prepare the loopback packet */ 1469 pkt_size = edev->ndev->mtu + ETH_HLEN; 1470 1471 skb = netdev_alloc_skb(edev->ndev, pkt_size); 1472 if (!skb) { 1473 DP_INFO(edev, "Can't allocate skb\n"); 1474 rc = -ENOMEM; 1475 goto test_loopback_exit; 1476 } 1477 packet = skb_put(skb, pkt_size); 1478 ether_addr_copy(packet, edev->ndev->dev_addr); 1479 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr); 1480 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN))); 1481 for (i = ETH_HLEN; i < pkt_size; i++) 1482 packet[i] = (unsigned char)(i & 0xff); 1483 1484 rc = qede_selftest_transmit_traffic(edev, skb); 1485 if (rc) 1486 goto test_loopback_exit; 1487 1488 rc = qede_selftest_receive_traffic(edev); 1489 if (rc) 1490 goto test_loopback_exit; 1491 1492 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n"); 1493 1494 test_loopback_exit: 1495 dev_kfree_skb(skb); 1496 1497 /* Bring up the link in Normal mode */ 1498 memset(&link_params, 0, sizeof(link_params)); 1499 link_params.link_up = true; 1500 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE; 1501 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE; 1502 edev->ops->common->set_link(edev->cdev, &link_params); 1503 1504 /* Wait for loopback configuration to apply */ 1505 msleep_interruptible(500); 1506 1507 qede_netif_start(edev); 1508 1509 return rc; 1510 } 1511 1512 static void qede_self_test(struct net_device *dev, 1513 struct ethtool_test *etest, u64 *buf) 1514 { 1515 struct qede_dev *edev = netdev_priv(dev); 1516 1517 DP_VERBOSE(edev, QED_MSG_DEBUG, 1518 "Self-test command parameters: offline = %d, external_lb = %d\n", 1519 (etest->flags & ETH_TEST_FL_OFFLINE), 1520 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2); 1521 1522 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX); 1523 1524 if (etest->flags & ETH_TEST_FL_OFFLINE) { 1525 if (qede_selftest_run_loopback(edev, 1526 QED_LINK_LOOPBACK_INT_PHY)) { 1527 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1; 1528 etest->flags |= ETH_TEST_FL_FAILED; 1529 } 1530 } 1531 1532 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) { 1533 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1; 1534 etest->flags |= ETH_TEST_FL_FAILED; 1535 } 1536 1537 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) { 1538 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1; 1539 etest->flags |= ETH_TEST_FL_FAILED; 1540 } 1541 1542 if (edev->ops->common->selftest->selftest_register(edev->cdev)) { 1543 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1; 1544 etest->flags |= ETH_TEST_FL_FAILED; 1545 } 1546 1547 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) { 1548 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1; 1549 etest->flags |= ETH_TEST_FL_FAILED; 1550 } 1551 1552 if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) { 1553 buf[QEDE_ETHTOOL_NVRAM_TEST] = 1; 1554 etest->flags |= ETH_TEST_FL_FAILED; 1555 } 1556 } 1557 1558 static int qede_set_tunable(struct net_device *dev, 1559 const struct ethtool_tunable *tuna, 1560 const void *data) 1561 { 1562 struct qede_dev *edev = netdev_priv(dev); 1563 u32 val; 1564 1565 switch (tuna->id) { 1566 case ETHTOOL_RX_COPYBREAK: 1567 val = *(u32 *)data; 1568 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) { 1569 DP_VERBOSE(edev, QED_MSG_DEBUG, 1570 "Invalid rx copy break value, range is [%u, %u]", 1571 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE); 1572 return -EINVAL; 1573 } 1574 1575 edev->rx_copybreak = *(u32 *)data; 1576 break; 1577 default: 1578 return -EOPNOTSUPP; 1579 } 1580 1581 return 0; 1582 } 1583 1584 static int qede_get_tunable(struct net_device *dev, 1585 const struct ethtool_tunable *tuna, void *data) 1586 { 1587 struct qede_dev *edev = netdev_priv(dev); 1588 1589 switch (tuna->id) { 1590 case ETHTOOL_RX_COPYBREAK: 1591 *(u32 *)data = edev->rx_copybreak; 1592 break; 1593 default: 1594 return -EOPNOTSUPP; 1595 } 1596 1597 return 0; 1598 } 1599 1600 static const struct ethtool_ops qede_ethtool_ops = { 1601 .get_link_ksettings = qede_get_link_ksettings, 1602 .set_link_ksettings = qede_set_link_ksettings, 1603 .get_drvinfo = qede_get_drvinfo, 1604 .get_regs_len = qede_get_regs_len, 1605 .get_regs = qede_get_regs, 1606 .get_wol = qede_get_wol, 1607 .set_wol = qede_set_wol, 1608 .get_msglevel = qede_get_msglevel, 1609 .set_msglevel = qede_set_msglevel, 1610 .nway_reset = qede_nway_reset, 1611 .get_link = qede_get_link, 1612 .get_coalesce = qede_get_coalesce, 1613 .set_coalesce = qede_set_coalesce, 1614 .get_ringparam = qede_get_ringparam, 1615 .set_ringparam = qede_set_ringparam, 1616 .get_pauseparam = qede_get_pauseparam, 1617 .set_pauseparam = qede_set_pauseparam, 1618 .get_strings = qede_get_strings, 1619 .set_phys_id = qede_set_phys_id, 1620 .get_ethtool_stats = qede_get_ethtool_stats, 1621 .get_priv_flags = qede_get_priv_flags, 1622 .get_sset_count = qede_get_sset_count, 1623 .get_rxnfc = qede_get_rxnfc, 1624 .set_rxnfc = qede_set_rxnfc, 1625 .get_rxfh_indir_size = qede_get_rxfh_indir_size, 1626 .get_rxfh_key_size = qede_get_rxfh_key_size, 1627 .get_rxfh = qede_get_rxfh, 1628 .set_rxfh = qede_set_rxfh, 1629 .get_ts_info = qede_get_ts_info, 1630 .get_channels = qede_get_channels, 1631 .set_channels = qede_set_channels, 1632 .self_test = qede_self_test, 1633 .get_tunable = qede_get_tunable, 1634 .set_tunable = qede_set_tunable, 1635 }; 1636 1637 static const struct ethtool_ops qede_vf_ethtool_ops = { 1638 .get_link_ksettings = qede_get_link_ksettings, 1639 .get_drvinfo = qede_get_drvinfo, 1640 .get_msglevel = qede_get_msglevel, 1641 .set_msglevel = qede_set_msglevel, 1642 .get_link = qede_get_link, 1643 .get_ringparam = qede_get_ringparam, 1644 .set_ringparam = qede_set_ringparam, 1645 .get_strings = qede_get_strings, 1646 .get_ethtool_stats = qede_get_ethtool_stats, 1647 .get_priv_flags = qede_get_priv_flags, 1648 .get_sset_count = qede_get_sset_count, 1649 .get_rxnfc = qede_get_rxnfc, 1650 .set_rxnfc = qede_set_rxnfc, 1651 .get_rxfh_indir_size = qede_get_rxfh_indir_size, 1652 .get_rxfh_key_size = qede_get_rxfh_key_size, 1653 .get_rxfh = qede_get_rxfh, 1654 .set_rxfh = qede_set_rxfh, 1655 .get_channels = qede_get_channels, 1656 .set_channels = qede_set_channels, 1657 .get_tunable = qede_get_tunable, 1658 .set_tunable = qede_set_tunable, 1659 }; 1660 1661 void qede_set_ethtool_ops(struct net_device *dev) 1662 { 1663 struct qede_dev *edev = netdev_priv(dev); 1664 1665 if (IS_VF(edev)) 1666 dev->ethtool_ops = &qede_vf_ethtool_ops; 1667 else 1668 dev->ethtool_ops = &qede_ethtool_ops; 1669 } 1670