1 /*- 2 * Copyright (c) 2015-2021 Mellanox Technologies. All rights reserved. 3 * Copyright (c) 2022 NVIDIA corporation & affiliates. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27 #include "opt_ipsec.h" 28 #include "opt_kern_tls.h" 29 #include "opt_rss.h" 30 #include "opt_ratelimit.h" 31 32 #include <dev/mlx5/mlx5_en/en.h> 33 #include <dev/mlx5/mlx5_accel/ipsec.h> 34 35 #include <sys/eventhandler.h> 36 #include <sys/sockio.h> 37 #include <machine/atomic.h> 38 39 #include <net/debugnet.h> 40 #include <netinet/tcp_ratelimit.h> 41 #include <netipsec/keydb.h> 42 #include <netipsec/ipsec_offload.h> 43 44 static int mlx5e_get_wqe_sz(struct mlx5e_priv *priv, u32 *wqe_sz, u32 *nsegs); 45 static if_snd_tag_query_t mlx5e_ul_snd_tag_query; 46 static if_snd_tag_free_t mlx5e_ul_snd_tag_free; 47 48 struct mlx5e_channel_param { 49 struct mlx5e_rq_param rq; 50 struct mlx5e_sq_param sq; 51 struct mlx5e_cq_param rx_cq; 52 struct mlx5e_cq_param tx_cq; 53 }; 54 55 struct media { 56 u32 subtype; 57 u64 baudrate; 58 }; 59 60 static const struct media mlx5e_mode_table[MLX5E_LINK_SPEEDS_NUMBER] = 61 { 62 [MLX5E_1000BASE_CX_SGMII] = { 63 .subtype = IFM_1000_CX_SGMII, 64 .baudrate = IF_Mbps(1000ULL), 65 }, 66 [MLX5E_1000BASE_KX] = { 67 .subtype = IFM_1000_KX, 68 .baudrate = IF_Mbps(1000ULL), 69 }, 70 [MLX5E_10GBASE_CX4] = { 71 .subtype = IFM_10G_CX4, 72 .baudrate = IF_Gbps(10ULL), 73 }, 74 [MLX5E_10GBASE_KX4] = { 75 .subtype = IFM_10G_KX4, 76 .baudrate = IF_Gbps(10ULL), 77 }, 78 [MLX5E_10GBASE_KR] = { 79 .subtype = IFM_10G_KR, 80 .baudrate = IF_Gbps(10ULL), 81 }, 82 [MLX5E_20GBASE_KR2] = { 83 .subtype = IFM_20G_KR2, 84 .baudrate = IF_Gbps(20ULL), 85 }, 86 [MLX5E_40GBASE_CR4] = { 87 .subtype = IFM_40G_CR4, 88 .baudrate = IF_Gbps(40ULL), 89 }, 90 [MLX5E_40GBASE_KR4] = { 91 .subtype = IFM_40G_KR4, 92 .baudrate = IF_Gbps(40ULL), 93 }, 94 [MLX5E_56GBASE_R4] = { 95 .subtype = IFM_56G_R4, 96 .baudrate = IF_Gbps(56ULL), 97 }, 98 [MLX5E_10GBASE_CR] = { 99 .subtype = IFM_10G_CR1, 100 .baudrate = IF_Gbps(10ULL), 101 }, 102 [MLX5E_10GBASE_SR] = { 103 .subtype = IFM_10G_SR, 104 .baudrate = IF_Gbps(10ULL), 105 }, 106 [MLX5E_10GBASE_ER_LR] = { 107 .subtype = IFM_10G_ER, 108 .baudrate = IF_Gbps(10ULL), 109 }, 110 [MLX5E_40GBASE_SR4] = { 111 .subtype = IFM_40G_SR4, 112 .baudrate = IF_Gbps(40ULL), 113 }, 114 [MLX5E_40GBASE_LR4_ER4] = { 115 .subtype = IFM_40G_LR4, 116 .baudrate = IF_Gbps(40ULL), 117 }, 118 [MLX5E_100GBASE_CR4] = { 119 .subtype = IFM_100G_CR4, 120 .baudrate = IF_Gbps(100ULL), 121 }, 122 [MLX5E_100GBASE_SR4] = { 123 .subtype = IFM_100G_SR4, 124 .baudrate = IF_Gbps(100ULL), 125 }, 126 [MLX5E_100GBASE_KR4] = { 127 .subtype = IFM_100G_KR4, 128 .baudrate = IF_Gbps(100ULL), 129 }, 130 [MLX5E_100GBASE_LR4] = { 131 .subtype = IFM_100G_LR4, 132 .baudrate = IF_Gbps(100ULL), 133 }, 134 [MLX5E_100BASE_TX] = { 135 .subtype = IFM_100_TX, 136 .baudrate = IF_Mbps(100ULL), 137 }, 138 [MLX5E_1000BASE_T] = { 139 .subtype = IFM_1000_T, 140 .baudrate = IF_Mbps(1000ULL), 141 }, 142 [MLX5E_10GBASE_T] = { 143 .subtype = IFM_10G_T, 144 .baudrate = IF_Gbps(10ULL), 145 }, 146 [MLX5E_25GBASE_CR] = { 147 .subtype = IFM_25G_CR, 148 .baudrate = IF_Gbps(25ULL), 149 }, 150 [MLX5E_25GBASE_KR] = { 151 .subtype = IFM_25G_KR, 152 .baudrate = IF_Gbps(25ULL), 153 }, 154 [MLX5E_25GBASE_SR] = { 155 .subtype = IFM_25G_SR, 156 .baudrate = IF_Gbps(25ULL), 157 }, 158 [MLX5E_50GBASE_CR2] = { 159 .subtype = IFM_50G_CR2, 160 .baudrate = IF_Gbps(50ULL), 161 }, 162 [MLX5E_50GBASE_KR2] = { 163 .subtype = IFM_50G_KR2, 164 .baudrate = IF_Gbps(50ULL), 165 }, 166 [MLX5E_50GBASE_KR4] = { 167 .subtype = IFM_50G_KR4, 168 .baudrate = IF_Gbps(50ULL), 169 }, 170 }; 171 172 static const struct media mlx5e_ext_mode_table[MLX5E_EXT_LINK_SPEEDS_NUMBER][MLX5E_CONNECTOR_TYPE_NUMBER] = 173 { 174 /**/ 175 [MLX5E_SGMII_100M][MLX5E_PORT_UNKNOWN] = { 176 .subtype = IFM_100_SGMII, 177 .baudrate = IF_Mbps(100), 178 }, 179 180 /**/ 181 [MLX5E_1000BASE_X_SGMII][MLX5E_PORT_UNKNOWN] = { 182 .subtype = IFM_1000_CX, 183 .baudrate = IF_Mbps(1000), 184 }, 185 [MLX5E_1000BASE_X_SGMII][MLX5E_PORT_FIBRE] = { 186 .subtype = IFM_1000_SX, 187 .baudrate = IF_Mbps(1000), 188 }, 189 190 /**/ 191 [MLX5E_5GBASE_R][MLX5E_PORT_UNKNOWN] = { 192 .subtype = IFM_5000_KR, 193 .baudrate = IF_Mbps(5000), 194 }, 195 [MLX5E_5GBASE_R][MLX5E_PORT_TP] = { 196 .subtype = IFM_5000_T, 197 .baudrate = IF_Mbps(5000), 198 }, 199 200 /**/ 201 [MLX5E_10GBASE_XFI_XAUI_1][MLX5E_PORT_UNKNOWN] = { 202 .subtype = IFM_10G_KR, 203 .baudrate = IF_Gbps(10ULL), 204 }, 205 [MLX5E_10GBASE_XFI_XAUI_1][MLX5E_PORT_DA] = { 206 .subtype = IFM_10G_CR1, 207 .baudrate = IF_Gbps(10ULL), 208 }, 209 [MLX5E_10GBASE_XFI_XAUI_1][MLX5E_PORT_FIBRE] = { 210 .subtype = IFM_10G_SR, 211 .baudrate = IF_Gbps(10ULL), 212 }, 213 214 /**/ 215 [MLX5E_40GBASE_XLAUI_4_XLPPI_4][MLX5E_PORT_UNKNOWN] = { 216 .subtype = IFM_40G_KR4, 217 .baudrate = IF_Gbps(40ULL), 218 }, 219 [MLX5E_40GBASE_XLAUI_4_XLPPI_4][MLX5E_PORT_DA] = { 220 .subtype = IFM_40G_CR4, 221 .baudrate = IF_Gbps(40ULL), 222 }, 223 [MLX5E_40GBASE_XLAUI_4_XLPPI_4][MLX5E_PORT_FIBRE] = { 224 .subtype = IFM_40G_SR4, 225 .baudrate = IF_Gbps(40ULL), 226 }, 227 228 /**/ 229 [MLX5E_25GAUI_1_25GBASE_CR_KR][MLX5E_PORT_UNKNOWN] = { 230 .subtype = IFM_25G_KR, 231 .baudrate = IF_Gbps(25ULL), 232 }, 233 [MLX5E_25GAUI_1_25GBASE_CR_KR][MLX5E_PORT_DA] = { 234 .subtype = IFM_25G_CR, 235 .baudrate = IF_Gbps(25ULL), 236 }, 237 [MLX5E_25GAUI_1_25GBASE_CR_KR][MLX5E_PORT_FIBRE] = { 238 .subtype = IFM_25G_SR, 239 .baudrate = IF_Gbps(25ULL), 240 }, 241 [MLX5E_25GAUI_1_25GBASE_CR_KR][MLX5E_PORT_TP] = { 242 .subtype = IFM_25G_T, 243 .baudrate = IF_Gbps(25ULL), 244 }, 245 246 /**/ 247 [MLX5E_50GAUI_2_LAUI_2_50GBASE_CR2_KR2][MLX5E_PORT_UNKNOWN] = { 248 .subtype = IFM_50G_KR2, 249 .baudrate = IF_Gbps(50ULL), 250 }, 251 [MLX5E_50GAUI_2_LAUI_2_50GBASE_CR2_KR2][MLX5E_PORT_DA] = { 252 .subtype = IFM_50G_CR2, 253 .baudrate = IF_Gbps(50ULL), 254 }, 255 [MLX5E_50GAUI_2_LAUI_2_50GBASE_CR2_KR2][MLX5E_PORT_FIBRE] = { 256 .subtype = IFM_50G_SR2, 257 .baudrate = IF_Gbps(50ULL), 258 }, 259 260 /**/ 261 [MLX5E_50GAUI_1_LAUI_1_50GBASE_CR_KR][MLX5E_PORT_UNKNOWN] = { 262 .subtype = IFM_50G_KR_PAM4, 263 .baudrate = IF_Gbps(50ULL), 264 }, 265 [MLX5E_50GAUI_1_LAUI_1_50GBASE_CR_KR][MLX5E_PORT_DA] = { 266 .subtype = IFM_50G_CP, 267 .baudrate = IF_Gbps(50ULL), 268 }, 269 [MLX5E_50GAUI_1_LAUI_1_50GBASE_CR_KR][MLX5E_PORT_FIBRE] = { 270 .subtype = IFM_50G_SR, 271 .baudrate = IF_Gbps(50ULL), 272 }, 273 274 /**/ 275 [MLX5E_CAUI_4_100GBASE_CR4_KR4][MLX5E_PORT_UNKNOWN] = { 276 .subtype = IFM_100G_KR4, 277 .baudrate = IF_Gbps(100ULL), 278 }, 279 [MLX5E_CAUI_4_100GBASE_CR4_KR4][MLX5E_PORT_DA] = { 280 .subtype = IFM_100G_CR4, 281 .baudrate = IF_Gbps(100ULL), 282 }, 283 [MLX5E_CAUI_4_100GBASE_CR4_KR4][MLX5E_PORT_FIBRE] = { 284 .subtype = IFM_100G_SR4, 285 .baudrate = IF_Gbps(100ULL), 286 }, 287 288 /**/ 289 [MLX5E_100GAUI_1_100GBASE_CR_KR][MLX5E_PORT_UNKNOWN] = { 290 .subtype = IFM_100G_KR_PAM4, 291 .baudrate = IF_Gbps(100ULL), 292 }, 293 [MLX5E_100GAUI_1_100GBASE_CR_KR][MLX5E_PORT_DA] = { 294 .subtype = IFM_100G_CR_PAM4, 295 .baudrate = IF_Gbps(100ULL), 296 }, 297 [MLX5E_100GAUI_1_100GBASE_CR_KR][MLX5E_PORT_FIBRE] = { 298 .subtype = IFM_100G_SR2, /* XXX */ 299 .baudrate = IF_Gbps(100ULL), 300 }, 301 302 /**/ 303 [MLX5E_100GAUI_2_100GBASE_CR2_KR2][MLX5E_PORT_UNKNOWN] = { 304 .subtype = IFM_100G_KR4, 305 .baudrate = IF_Gbps(100ULL), 306 }, 307 [MLX5E_100GAUI_2_100GBASE_CR2_KR2][MLX5E_PORT_DA] = { 308 .subtype = IFM_100G_CP2, 309 .baudrate = IF_Gbps(100ULL), 310 }, 311 [MLX5E_100GAUI_2_100GBASE_CR2_KR2][MLX5E_PORT_FIBRE] = { 312 .subtype = IFM_100G_SR2, 313 .baudrate = IF_Gbps(100ULL), 314 }, 315 316 /**/ 317 [MLX5E_200GAUI_2_200GBASE_CR2_KR2][MLX5E_PORT_UNKNOWN] = { 318 .subtype = IFM_200G_KR4_PAM4, /* XXX */ 319 .baudrate = IF_Gbps(200ULL), 320 }, 321 [MLX5E_200GAUI_2_200GBASE_CR2_KR2][MLX5E_PORT_DA] = { 322 .subtype = IFM_200G_CR4_PAM4, /* XXX */ 323 .baudrate = IF_Gbps(200ULL), 324 }, 325 [MLX5E_200GAUI_2_200GBASE_CR2_KR2][MLX5E_PORT_FIBRE] = { 326 .subtype = IFM_200G_SR4, /* XXX */ 327 .baudrate = IF_Gbps(200ULL), 328 }, 329 330 /**/ 331 [MLX5E_200GAUI_4_200GBASE_CR4_KR4][MLX5E_PORT_UNKNOWN] = { 332 .subtype = IFM_200G_KR4_PAM4, 333 .baudrate = IF_Gbps(200ULL), 334 }, 335 [MLX5E_200GAUI_4_200GBASE_CR4_KR4][MLX5E_PORT_DA] = { 336 .subtype = IFM_200G_CR4_PAM4, 337 .baudrate = IF_Gbps(200ULL), 338 }, 339 [MLX5E_200GAUI_4_200GBASE_CR4_KR4][MLX5E_PORT_FIBRE] = { 340 .subtype = IFM_200G_SR4, 341 .baudrate = IF_Gbps(200ULL), 342 }, 343 344 /**/ 345 [MLX5E_400GAUI_8][MLX5E_PORT_UNKNOWN] = { 346 .subtype = IFM_400G_LR8, /* XXX */ 347 .baudrate = IF_Gbps(400ULL), 348 }, 349 350 /**/ 351 [MLX5E_400GAUI_4_400GBASE_CR4_KR4][MLX5E_PORT_UNKNOWN] = { 352 .subtype = IFM_400G_LR8, /* XXX */ 353 .baudrate = IF_Gbps(400ULL), 354 }, 355 }; 356 357 static const struct if_snd_tag_sw mlx5e_ul_snd_tag_sw = { 358 .snd_tag_query = mlx5e_ul_snd_tag_query, 359 .snd_tag_free = mlx5e_ul_snd_tag_free, 360 .type = IF_SND_TAG_TYPE_UNLIMITED 361 }; 362 363 DEBUGNET_DEFINE(mlx5_en); 364 365 MALLOC_DEFINE(M_MLX5EN, "MLX5EN", "MLX5 Ethernet"); 366 367 static void 368 mlx5e_update_carrier(struct mlx5e_priv *priv) 369 { 370 struct mlx5_core_dev *mdev = priv->mdev; 371 u32 out[MLX5_ST_SZ_DW(ptys_reg)]; 372 u32 eth_proto_oper; 373 int error; 374 u8 i; 375 u8 connector_type; 376 u8 port_state; 377 u8 is_er_type; 378 bool ext; 379 struct media media_entry = {}; 380 381 port_state = mlx5_query_vport_state(mdev, 382 MLX5_QUERY_VPORT_STATE_IN_OP_MOD_VNIC_VPORT, 0); 383 384 if (port_state == VPORT_STATE_UP) { 385 priv->media_status_last |= IFM_ACTIVE; 386 } else { 387 priv->media_status_last &= ~IFM_ACTIVE; 388 priv->media_active_last = IFM_ETHER; 389 if_link_state_change(priv->ifp, LINK_STATE_DOWN); 390 return; 391 } 392 393 error = mlx5_query_port_ptys(mdev, out, sizeof(out), 394 MLX5_PTYS_EN, 1); 395 if (error) { 396 priv->media_active_last = IFM_ETHER; 397 if_setbaudrate(priv->ifp, 1); 398 mlx5_en_err(priv->ifp, "query port ptys failed: 0x%x\n", 399 error); 400 return; 401 } 402 403 ext = MLX5_CAP_PCAM_FEATURE(mdev, ptys_extended_ethernet); 404 eth_proto_oper = MLX5_GET_ETH_PROTO(ptys_reg, out, ext, 405 eth_proto_oper); 406 connector_type = MLX5_GET(ptys_reg, out, connector_type); 407 i = ilog2(eth_proto_oper); 408 409 if (ext) { 410 media_entry = mlx5e_ext_mode_table[i][connector_type]; 411 /* check if we should use fallback entry */ 412 if (media_entry.subtype == 0) 413 media_entry = mlx5e_ext_mode_table[i][MLX5E_PORT_UNKNOWN]; 414 } else { 415 media_entry = mlx5e_mode_table[i]; 416 } 417 418 if (media_entry.subtype == 0) { 419 mlx5_en_err(priv->ifp, 420 "Could not find operational media subtype\n"); 421 return; 422 } 423 424 switch (media_entry.subtype) { 425 case IFM_10G_ER: 426 error = mlx5_query_pddr_range_info(mdev, 1, &is_er_type); 427 if (error != 0) { 428 mlx5_en_err(priv->ifp, 429 "query port pddr failed: %d\n", error); 430 } 431 if (error != 0 || is_er_type == 0) 432 media_entry.subtype = IFM_10G_LR; 433 break; 434 case IFM_40G_LR4: 435 error = mlx5_query_pddr_range_info(mdev, 1, &is_er_type); 436 if (error != 0) { 437 mlx5_en_err(priv->ifp, 438 "query port pddr failed: %d\n", error); 439 } 440 if (error == 0 && is_er_type != 0) 441 media_entry.subtype = IFM_40G_ER4; 442 break; 443 } 444 priv->media_active_last = media_entry.subtype | IFM_ETHER | IFM_FDX; 445 if_setbaudrate(priv->ifp, media_entry.baudrate); 446 447 if_link_state_change(priv->ifp, LINK_STATE_UP); 448 } 449 450 static void 451 mlx5e_media_status(if_t dev, struct ifmediareq *ifmr) 452 { 453 struct mlx5e_priv *priv = if_getsoftc(dev); 454 455 ifmr->ifm_status = priv->media_status_last; 456 ifmr->ifm_current = ifmr->ifm_active = priv->media_active_last | 457 (priv->params.rx_pauseframe_control ? IFM_ETH_RXPAUSE : 0) | 458 (priv->params.tx_pauseframe_control ? IFM_ETH_TXPAUSE : 0); 459 460 } 461 462 static u32 463 mlx5e_find_link_mode(u32 subtype, bool ext) 464 { 465 u32 link_mode = 0; 466 467 switch (subtype) { 468 case 0: 469 goto done; 470 case IFM_10G_LR: 471 subtype = IFM_10G_ER; 472 break; 473 case IFM_40G_ER4: 474 subtype = IFM_40G_LR4; 475 break; 476 default: 477 break; 478 } 479 480 if (ext) { 481 for (unsigned i = 0; i != MLX5E_EXT_LINK_SPEEDS_NUMBER; i++) { 482 for (unsigned j = 0; j != MLX5E_CABLE_TYPE_NUMBER; j++) { 483 if (mlx5e_ext_mode_table[i][j].subtype == subtype) 484 link_mode |= MLX5E_PROT_MASK(i); 485 } 486 } 487 } else { 488 for (unsigned i = 0; i != MLX5E_LINK_SPEEDS_NUMBER; i++) { 489 if (mlx5e_mode_table[i].subtype == subtype) 490 link_mode |= MLX5E_PROT_MASK(i); 491 } 492 } 493 done: 494 return (link_mode); 495 } 496 497 static int 498 mlx5e_set_port_pause_and_pfc(struct mlx5e_priv *priv) 499 { 500 return (mlx5_set_port_pause_and_pfc(priv->mdev, 1, 501 priv->params.rx_pauseframe_control, 502 priv->params.tx_pauseframe_control, 503 priv->params.rx_priority_flow_control, 504 priv->params.tx_priority_flow_control)); 505 } 506 507 static int 508 mlx5e_set_port_pfc(struct mlx5e_priv *priv) 509 { 510 int error; 511 512 if (priv->gone != 0) { 513 error = -ENXIO; 514 } else if (priv->params.rx_pauseframe_control || 515 priv->params.tx_pauseframe_control) { 516 mlx5_en_err(priv->ifp, 517 "Global pauseframes must be disabled before enabling PFC.\n"); 518 error = -EINVAL; 519 } else { 520 error = mlx5e_set_port_pause_and_pfc(priv); 521 } 522 return (error); 523 } 524 525 static int 526 mlx5e_media_change(if_t dev) 527 { 528 struct mlx5e_priv *priv = if_getsoftc(dev); 529 struct mlx5_core_dev *mdev = priv->mdev; 530 u32 eth_proto_cap; 531 u32 link_mode; 532 u32 out[MLX5_ST_SZ_DW(ptys_reg)]; 533 int was_opened; 534 int locked; 535 int error; 536 bool ext; 537 538 locked = PRIV_LOCKED(priv); 539 if (!locked) 540 PRIV_LOCK(priv); 541 542 if (IFM_TYPE(priv->media.ifm_media) != IFM_ETHER) { 543 error = EINVAL; 544 goto done; 545 } 546 547 error = mlx5_query_port_ptys(mdev, out, sizeof(out), 548 MLX5_PTYS_EN, 1); 549 if (error != 0) { 550 mlx5_en_err(dev, "Query port media capability failed\n"); 551 goto done; 552 } 553 554 ext = MLX5_CAP_PCAM_FEATURE(mdev, ptys_extended_ethernet); 555 link_mode = mlx5e_find_link_mode(IFM_SUBTYPE(priv->media.ifm_media), ext); 556 557 /* query supported capabilities */ 558 eth_proto_cap = MLX5_GET_ETH_PROTO(ptys_reg, out, ext, 559 eth_proto_capability); 560 561 /* check for autoselect */ 562 if (IFM_SUBTYPE(priv->media.ifm_media) == IFM_AUTO) { 563 link_mode = eth_proto_cap; 564 if (link_mode == 0) { 565 mlx5_en_err(dev, "Port media capability is zero\n"); 566 error = EINVAL; 567 goto done; 568 } 569 } else { 570 link_mode = link_mode & eth_proto_cap; 571 if (link_mode == 0) { 572 mlx5_en_err(dev, "Not supported link mode requested\n"); 573 error = EINVAL; 574 goto done; 575 } 576 } 577 if (priv->media.ifm_media & (IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE)) { 578 /* check if PFC is enabled */ 579 if (priv->params.rx_priority_flow_control || 580 priv->params.tx_priority_flow_control) { 581 mlx5_en_err(dev, "PFC must be disabled before enabling global pauseframes.\n"); 582 error = EINVAL; 583 goto done; 584 } 585 } 586 /* update pauseframe control bits */ 587 priv->params.rx_pauseframe_control = 588 (priv->media.ifm_media & IFM_ETH_RXPAUSE) ? 1 : 0; 589 priv->params.tx_pauseframe_control = 590 (priv->media.ifm_media & IFM_ETH_TXPAUSE) ? 1 : 0; 591 592 /* check if device is opened */ 593 was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state); 594 595 /* reconfigure the hardware */ 596 mlx5_set_port_status(mdev, MLX5_PORT_DOWN); 597 mlx5_set_port_proto(mdev, link_mode, MLX5_PTYS_EN, ext); 598 error = -mlx5e_set_port_pause_and_pfc(priv); 599 if (was_opened) 600 mlx5_set_port_status(mdev, MLX5_PORT_UP); 601 602 done: 603 if (!locked) 604 PRIV_UNLOCK(priv); 605 return (error); 606 } 607 608 static void 609 mlx5e_update_carrier_work(struct work_struct *work) 610 { 611 struct mlx5e_priv *priv = container_of(work, struct mlx5e_priv, 612 update_carrier_work); 613 614 PRIV_LOCK(priv); 615 if (test_bit(MLX5E_STATE_OPENED, &priv->state)) 616 mlx5e_update_carrier(priv); 617 PRIV_UNLOCK(priv); 618 } 619 620 #define MLX5E_PCIE_PERF_GET_64(a,b,c,d,e,f) \ 621 s_debug->c = MLX5_GET64(mpcnt_reg, out, counter_set.f.c); 622 623 #define MLX5E_PCIE_PERF_GET_32(a,b,c,d,e,f) \ 624 s_debug->c = MLX5_GET(mpcnt_reg, out, counter_set.f.c); 625 626 static void 627 mlx5e_update_pcie_counters(struct mlx5e_priv *priv) 628 { 629 struct mlx5_core_dev *mdev = priv->mdev; 630 struct mlx5e_port_stats_debug *s_debug = &priv->stats.port_stats_debug; 631 const unsigned sz = MLX5_ST_SZ_BYTES(mpcnt_reg); 632 void *out; 633 void *in; 634 int err; 635 636 /* allocate firmware request structures */ 637 in = mlx5_vzalloc(sz); 638 out = mlx5_vzalloc(sz); 639 if (in == NULL || out == NULL) 640 goto free_out; 641 642 MLX5_SET(mpcnt_reg, in, grp, MLX5_PCIE_PERFORMANCE_COUNTERS_GROUP); 643 err = mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_MPCNT, 0, 0); 644 if (err != 0) 645 goto free_out; 646 647 MLX5E_PCIE_PERFORMANCE_COUNTERS_64(MLX5E_PCIE_PERF_GET_64) 648 MLX5E_PCIE_PERFORMANCE_COUNTERS_32(MLX5E_PCIE_PERF_GET_32) 649 650 MLX5_SET(mpcnt_reg, in, grp, MLX5_PCIE_TIMERS_AND_STATES_COUNTERS_GROUP); 651 err = mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_MPCNT, 0, 0); 652 if (err != 0) 653 goto free_out; 654 655 MLX5E_PCIE_TIMERS_AND_STATES_COUNTERS_32(MLX5E_PCIE_PERF_GET_32) 656 657 MLX5_SET(mpcnt_reg, in, grp, MLX5_PCIE_LANE_COUNTERS_GROUP); 658 err = mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_MPCNT, 0, 0); 659 if (err != 0) 660 goto free_out; 661 662 MLX5E_PCIE_LANE_COUNTERS_32(MLX5E_PCIE_PERF_GET_32) 663 664 free_out: 665 /* free firmware request structures */ 666 kvfree(in); 667 kvfree(out); 668 } 669 670 /* 671 * This function reads the physical port counters from the firmware 672 * using a pre-defined layout defined by various MLX5E_PPORT_XXX() 673 * macros. The output is converted from big-endian 64-bit values into 674 * host endian ones and stored in the "priv->stats.pport" structure. 675 */ 676 static void 677 mlx5e_update_pport_counters(struct mlx5e_priv *priv) 678 { 679 struct mlx5_core_dev *mdev = priv->mdev; 680 struct mlx5e_pport_stats *s = &priv->stats.pport; 681 struct mlx5e_port_stats_debug *s_debug = &priv->stats.port_stats_debug; 682 u32 *in; 683 u32 *out; 684 const u64 *ptr; 685 unsigned sz = MLX5_ST_SZ_BYTES(ppcnt_reg); 686 unsigned x; 687 unsigned y; 688 unsigned z; 689 690 /* allocate firmware request structures */ 691 in = mlx5_vzalloc(sz); 692 out = mlx5_vzalloc(sz); 693 if (in == NULL || out == NULL) 694 goto free_out; 695 696 /* 697 * Get pointer to the 64-bit counter set which is located at a 698 * fixed offset in the output firmware request structure: 699 */ 700 ptr = (const uint64_t *)MLX5_ADDR_OF(ppcnt_reg, out, counter_set); 701 702 MLX5_SET(ppcnt_reg, in, local_port, 1); 703 704 /* read IEEE802_3 counter group using predefined counter layout */ 705 MLX5_SET(ppcnt_reg, in, grp, MLX5_IEEE_802_3_COUNTERS_GROUP); 706 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0); 707 for (x = 0, y = MLX5E_PPORT_PER_PRIO_STATS_NUM; 708 x != MLX5E_PPORT_IEEE802_3_STATS_NUM; x++, y++) 709 s->arg[y] = be64toh(ptr[x]); 710 711 /* read RFC2819 counter group using predefined counter layout */ 712 MLX5_SET(ppcnt_reg, in, grp, MLX5_RFC_2819_COUNTERS_GROUP); 713 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0); 714 for (x = 0; x != MLX5E_PPORT_RFC2819_STATS_NUM; x++, y++) 715 s->arg[y] = be64toh(ptr[x]); 716 717 for (y = 0; x != MLX5E_PPORT_RFC2819_STATS_NUM + 718 MLX5E_PPORT_RFC2819_STATS_DEBUG_NUM; x++, y++) 719 s_debug->arg[y] = be64toh(ptr[x]); 720 721 /* read RFC2863 counter group using predefined counter layout */ 722 MLX5_SET(ppcnt_reg, in, grp, MLX5_RFC_2863_COUNTERS_GROUP); 723 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0); 724 for (x = 0; x != MLX5E_PPORT_RFC2863_STATS_DEBUG_NUM; x++, y++) 725 s_debug->arg[y] = be64toh(ptr[x]); 726 727 /* read physical layer stats counter group using predefined counter layout */ 728 MLX5_SET(ppcnt_reg, in, grp, MLX5_PHYSICAL_LAYER_COUNTERS_GROUP); 729 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0); 730 for (x = 0; x != MLX5E_PPORT_PHYSICAL_LAYER_STATS_DEBUG_NUM; x++, y++) 731 s_debug->arg[y] = be64toh(ptr[x]); 732 733 /* read Extended Ethernet counter group using predefined counter layout */ 734 MLX5_SET(ppcnt_reg, in, grp, MLX5_ETHERNET_EXTENDED_COUNTERS_GROUP); 735 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0); 736 for (x = 0; x != MLX5E_PPORT_ETHERNET_EXTENDED_STATS_DEBUG_NUM; x++, y++) 737 s_debug->arg[y] = be64toh(ptr[x]); 738 739 /* read Extended Statistical Group */ 740 if (MLX5_CAP_GEN(mdev, pcam_reg) && 741 MLX5_CAP_PCAM_FEATURE(mdev, ppcnt_statistical_group) && 742 MLX5_CAP_PCAM_FEATURE(mdev, per_lane_error_counters)) { 743 /* read Extended Statistical counter group using predefined counter layout */ 744 MLX5_SET(ppcnt_reg, in, grp, MLX5_PHYSICAL_LAYER_STATISTICAL_GROUP); 745 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0); 746 747 for (x = 0; x != MLX5E_PPORT_STATISTICAL_DEBUG_NUM; x++, y++) 748 s_debug->arg[y] = be64toh(ptr[x]); 749 } 750 751 /* read PCIE counters */ 752 mlx5e_update_pcie_counters(priv); 753 754 /* read per-priority counters */ 755 MLX5_SET(ppcnt_reg, in, grp, MLX5_PER_PRIORITY_COUNTERS_GROUP); 756 757 /* iterate all the priorities */ 758 for (y = z = 0; z != MLX5E_PPORT_PER_PRIO_STATS_NUM_PRIO; z++) { 759 MLX5_SET(ppcnt_reg, in, prio_tc, z); 760 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0); 761 762 /* read per priority stats counter group using predefined counter layout */ 763 for (x = 0; x != (MLX5E_PPORT_PER_PRIO_STATS_NUM / 764 MLX5E_PPORT_PER_PRIO_STATS_NUM_PRIO); x++, y++) 765 s->arg[y] = be64toh(ptr[x]); 766 } 767 768 free_out: 769 /* free firmware request structures */ 770 kvfree(in); 771 kvfree(out); 772 } 773 774 static void 775 mlx5e_grp_vnic_env_update_stats(struct mlx5e_priv *priv) 776 { 777 u32 out[MLX5_ST_SZ_DW(query_vnic_env_out)] = {}; 778 u32 in[MLX5_ST_SZ_DW(query_vnic_env_in)] = {}; 779 780 if (!MLX5_CAP_GEN(priv->mdev, nic_receive_steering_discard)) 781 return; 782 783 MLX5_SET(query_vnic_env_in, in, opcode, 784 MLX5_CMD_OP_QUERY_VNIC_ENV); 785 MLX5_SET(query_vnic_env_in, in, op_mod, 0); 786 MLX5_SET(query_vnic_env_in, in, other_vport, 0); 787 788 if (mlx5_cmd_exec(priv->mdev, in, sizeof(in), out, sizeof(out)) != 0) 789 return; 790 791 priv->stats.vport.rx_steer_missed_packets = 792 MLX5_GET64(query_vnic_env_out, out, 793 vport_env.nic_receive_steering_discard); 794 } 795 796 /* 797 * This function is called regularly to collect all statistics 798 * counters from the firmware. The values can be viewed through the 799 * sysctl interface. Execution is serialized using the priv's global 800 * configuration lock. 801 */ 802 static void 803 mlx5e_update_stats_locked(struct mlx5e_priv *priv) 804 { 805 struct mlx5_core_dev *mdev = priv->mdev; 806 struct mlx5e_vport_stats *s = &priv->stats.vport; 807 struct mlx5e_sq_stats *sq_stats; 808 u32 in[MLX5_ST_SZ_DW(query_vport_counter_in)]; 809 u32 *out; 810 int outlen = MLX5_ST_SZ_BYTES(query_vport_counter_out); 811 u64 tso_packets = 0; 812 u64 tso_bytes = 0; 813 u64 tx_queue_dropped = 0; 814 u64 tx_defragged = 0; 815 u64 tx_offload_none = 0; 816 u64 lro_packets = 0; 817 u64 lro_bytes = 0; 818 u64 sw_lro_queued = 0; 819 u64 sw_lro_flushed = 0; 820 u64 rx_csum_none = 0; 821 u64 rx_wqe_err = 0; 822 u64 rx_packets = 0; 823 u64 rx_bytes = 0; 824 u64 rx_decrypted_error = 0; 825 u64 rx_decrypted_ok = 0; 826 u32 rx_out_of_buffer = 0; 827 int error; 828 int i; 829 int j; 830 831 out = mlx5_vzalloc(outlen); 832 if (out == NULL) 833 goto free_out; 834 835 /* Collect firts the SW counters and then HW for consistency */ 836 for (i = 0; i < priv->params.num_channels; i++) { 837 struct mlx5e_channel *pch = priv->channel + i; 838 struct mlx5e_rq *rq = &pch->rq; 839 struct mlx5e_rq_stats *rq_stats = &pch->rq.stats; 840 841 /* collect stats from LRO */ 842 rq_stats->sw_lro_queued = rq->lro.lro_queued; 843 rq_stats->sw_lro_flushed = rq->lro.lro_flushed; 844 sw_lro_queued += rq_stats->sw_lro_queued; 845 sw_lro_flushed += rq_stats->sw_lro_flushed; 846 lro_packets += rq_stats->lro_packets; 847 lro_bytes += rq_stats->lro_bytes; 848 rx_csum_none += rq_stats->csum_none; 849 rx_wqe_err += rq_stats->wqe_err; 850 rx_packets += rq_stats->packets; 851 rx_bytes += rq_stats->bytes; 852 rx_decrypted_error += rq_stats->decrypted_error_packets; 853 rx_decrypted_ok += rq_stats->decrypted_ok_packets; 854 855 for (j = 0; j < priv->num_tc; j++) { 856 sq_stats = &pch->sq[j].stats; 857 858 tso_packets += sq_stats->tso_packets; 859 tso_bytes += sq_stats->tso_bytes; 860 tx_queue_dropped += sq_stats->dropped; 861 tx_queue_dropped += sq_stats->enobuf; 862 tx_defragged += sq_stats->defragged; 863 tx_offload_none += sq_stats->csum_offload_none; 864 } 865 } 866 867 #ifdef RATELIMIT 868 /* Collect statistics from all rate-limit queues */ 869 for (j = 0; j < priv->rl.param.tx_worker_threads_def; j++) { 870 struct mlx5e_rl_worker *rlw = priv->rl.workers + j; 871 872 for (i = 0; i < priv->rl.param.tx_channels_per_worker_def; i++) { 873 struct mlx5e_rl_channel *channel = rlw->channels + i; 874 struct mlx5e_sq *sq = channel->sq; 875 876 if (sq == NULL) 877 continue; 878 879 sq_stats = &sq->stats; 880 881 tso_packets += sq_stats->tso_packets; 882 tso_bytes += sq_stats->tso_bytes; 883 tx_queue_dropped += sq_stats->dropped; 884 tx_queue_dropped += sq_stats->enobuf; 885 tx_defragged += sq_stats->defragged; 886 tx_offload_none += sq_stats->csum_offload_none; 887 } 888 } 889 #endif 890 891 /* update counters */ 892 s->tso_packets = tso_packets; 893 s->tso_bytes = tso_bytes; 894 s->tx_queue_dropped = tx_queue_dropped; 895 s->tx_defragged = tx_defragged; 896 s->lro_packets = lro_packets; 897 s->lro_bytes = lro_bytes; 898 s->sw_lro_queued = sw_lro_queued; 899 s->sw_lro_flushed = sw_lro_flushed; 900 s->rx_csum_none = rx_csum_none; 901 s->rx_wqe_err = rx_wqe_err; 902 s->rx_packets = rx_packets; 903 s->rx_bytes = rx_bytes; 904 s->rx_decrypted_error_packets = rx_decrypted_error; 905 s->rx_decrypted_ok_packets = rx_decrypted_ok; 906 907 mlx5e_grp_vnic_env_update_stats(priv); 908 909 /* HW counters */ 910 memset(in, 0, sizeof(in)); 911 912 MLX5_SET(query_vport_counter_in, in, opcode, 913 MLX5_CMD_OP_QUERY_VPORT_COUNTER); 914 MLX5_SET(query_vport_counter_in, in, op_mod, 0); 915 MLX5_SET(query_vport_counter_in, in, other_vport, 0); 916 917 memset(out, 0, outlen); 918 919 /* get number of out-of-buffer drops first */ 920 if (test_bit(MLX5E_STATE_OPENED, &priv->state) != 0 && 921 mlx5_vport_query_out_of_rx_buffer(mdev, priv->counter_set_id, 922 &rx_out_of_buffer) == 0) { 923 s->rx_out_of_buffer = rx_out_of_buffer; 924 } 925 926 /* get port statistics */ 927 if (mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen) == 0) { 928 #define MLX5_GET_CTR(out, x) \ 929 MLX5_GET64(query_vport_counter_out, out, x) 930 931 s->rx_error_packets = 932 MLX5_GET_CTR(out, received_errors.packets); 933 s->rx_error_bytes = 934 MLX5_GET_CTR(out, received_errors.octets); 935 s->tx_error_packets = 936 MLX5_GET_CTR(out, transmit_errors.packets); 937 s->tx_error_bytes = 938 MLX5_GET_CTR(out, transmit_errors.octets); 939 940 s->rx_unicast_packets = 941 MLX5_GET_CTR(out, received_eth_unicast.packets); 942 s->rx_unicast_bytes = 943 MLX5_GET_CTR(out, received_eth_unicast.octets); 944 s->tx_unicast_packets = 945 MLX5_GET_CTR(out, transmitted_eth_unicast.packets); 946 s->tx_unicast_bytes = 947 MLX5_GET_CTR(out, transmitted_eth_unicast.octets); 948 949 s->rx_multicast_packets = 950 MLX5_GET_CTR(out, received_eth_multicast.packets); 951 s->rx_multicast_bytes = 952 MLX5_GET_CTR(out, received_eth_multicast.octets); 953 s->tx_multicast_packets = 954 MLX5_GET_CTR(out, transmitted_eth_multicast.packets); 955 s->tx_multicast_bytes = 956 MLX5_GET_CTR(out, transmitted_eth_multicast.octets); 957 958 s->rx_broadcast_packets = 959 MLX5_GET_CTR(out, received_eth_broadcast.packets); 960 s->rx_broadcast_bytes = 961 MLX5_GET_CTR(out, received_eth_broadcast.octets); 962 s->tx_broadcast_packets = 963 MLX5_GET_CTR(out, transmitted_eth_broadcast.packets); 964 s->tx_broadcast_bytes = 965 MLX5_GET_CTR(out, transmitted_eth_broadcast.octets); 966 967 s->tx_packets = s->tx_unicast_packets + 968 s->tx_multicast_packets + s->tx_broadcast_packets; 969 s->tx_bytes = s->tx_unicast_bytes + s->tx_multicast_bytes + 970 s->tx_broadcast_bytes; 971 972 /* Update calculated offload counters */ 973 s->tx_csum_offload = s->tx_packets - tx_offload_none; 974 s->rx_csum_good = s->rx_packets - s->rx_csum_none; 975 } 976 977 /* Get physical port counters */ 978 mlx5e_update_pport_counters(priv); 979 980 s->tx_jumbo_packets = 981 priv->stats.port_stats_debug.tx_stat_p1519to2047octets + 982 priv->stats.port_stats_debug.tx_stat_p2048to4095octets + 983 priv->stats.port_stats_debug.tx_stat_p4096to8191octets + 984 priv->stats.port_stats_debug.tx_stat_p8192to10239octets; 985 986 free_out: 987 kvfree(out); 988 989 /* Update diagnostics, if any */ 990 if (priv->params_ethtool.diag_pci_enable || 991 priv->params_ethtool.diag_general_enable) { 992 error = mlx5_core_get_diagnostics_full(mdev, 993 priv->params_ethtool.diag_pci_enable ? &priv->params_pci : NULL, 994 priv->params_ethtool.diag_general_enable ? &priv->params_general : NULL); 995 if (error != 0) 996 mlx5_en_err(priv->ifp, 997 "Failed reading diagnostics: %d\n", error); 998 } 999 1000 /* Update FEC, if any */ 1001 error = mlx5e_fec_update(priv); 1002 if (error != 0 && error != EOPNOTSUPP) { 1003 mlx5_en_err(priv->ifp, 1004 "Updating FEC failed: %d\n", error); 1005 } 1006 1007 /* Update temperature, if any */ 1008 if (priv->params_ethtool.hw_num_temp != 0) { 1009 error = mlx5e_hw_temperature_update(priv); 1010 if (error != 0 && error != EOPNOTSUPP) { 1011 mlx5_en_err(priv->ifp, 1012 "Updating temperature failed: %d\n", error); 1013 } 1014 } 1015 } 1016 1017 static void 1018 mlx5e_update_stats_work(struct work_struct *work) 1019 { 1020 struct mlx5e_priv *priv; 1021 1022 priv = container_of(work, struct mlx5e_priv, update_stats_work); 1023 PRIV_LOCK(priv); 1024 if (test_bit(MLX5E_STATE_OPENED, &priv->state) != 0 && 1025 !test_bit(MLX5_INTERFACE_STATE_TEARDOWN, &priv->mdev->intf_state)) 1026 mlx5e_update_stats_locked(priv); 1027 PRIV_UNLOCK(priv); 1028 } 1029 1030 static void 1031 mlx5e_update_stats(void *arg) 1032 { 1033 struct mlx5e_priv *priv = arg; 1034 1035 queue_work(priv->wq, &priv->update_stats_work); 1036 1037 callout_reset(&priv->watchdog, hz / 4, &mlx5e_update_stats, priv); 1038 } 1039 1040 static void 1041 mlx5e_async_event_sub(struct mlx5e_priv *priv, 1042 enum mlx5_dev_event event) 1043 { 1044 switch (event) { 1045 case MLX5_DEV_EVENT_PORT_UP: 1046 case MLX5_DEV_EVENT_PORT_DOWN: 1047 queue_work(priv->wq, &priv->update_carrier_work); 1048 break; 1049 1050 default: 1051 break; 1052 } 1053 } 1054 1055 static void 1056 mlx5e_async_event(struct mlx5_core_dev *mdev, void *vpriv, 1057 enum mlx5_dev_event event, unsigned long param) 1058 { 1059 struct mlx5e_priv *priv = vpriv; 1060 1061 mtx_lock(&priv->async_events_mtx); 1062 if (test_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLE, &priv->state)) 1063 mlx5e_async_event_sub(priv, event); 1064 mtx_unlock(&priv->async_events_mtx); 1065 } 1066 1067 static void 1068 mlx5e_enable_async_events(struct mlx5e_priv *priv) 1069 { 1070 set_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLE, &priv->state); 1071 } 1072 1073 static void 1074 mlx5e_disable_async_events(struct mlx5e_priv *priv) 1075 { 1076 mtx_lock(&priv->async_events_mtx); 1077 clear_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLE, &priv->state); 1078 mtx_unlock(&priv->async_events_mtx); 1079 } 1080 1081 static void mlx5e_calibration_callout(void *arg); 1082 static int mlx5e_calibration_duration = 20; 1083 static int mlx5e_fast_calibration = 1; 1084 static int mlx5e_normal_calibration = 30; 1085 1086 static SYSCTL_NODE(_hw_mlx5, OID_AUTO, calibr, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 1087 "MLX5 timestamp calibration parameters"); 1088 1089 SYSCTL_INT(_hw_mlx5_calibr, OID_AUTO, duration, CTLFLAG_RWTUN, 1090 &mlx5e_calibration_duration, 0, 1091 "Duration of initial calibration"); 1092 SYSCTL_INT(_hw_mlx5_calibr, OID_AUTO, fast, CTLFLAG_RWTUN, 1093 &mlx5e_fast_calibration, 0, 1094 "Recalibration interval during initial calibration"); 1095 SYSCTL_INT(_hw_mlx5_calibr, OID_AUTO, normal, CTLFLAG_RWTUN, 1096 &mlx5e_normal_calibration, 0, 1097 "Recalibration interval during normal operations"); 1098 1099 /* 1100 * Ignites the calibration process. 1101 */ 1102 static void 1103 mlx5e_reset_calibration_callout(struct mlx5e_priv *priv) 1104 { 1105 1106 if (priv->clbr_done == 0) 1107 mlx5e_calibration_callout(priv); 1108 else 1109 callout_reset_sbt_curcpu(&priv->tstmp_clbr, (priv->clbr_done < 1110 mlx5e_calibration_duration ? mlx5e_fast_calibration : 1111 mlx5e_normal_calibration) * SBT_1S, 0, 1112 mlx5e_calibration_callout, priv, C_DIRECT_EXEC); 1113 } 1114 1115 static uint64_t 1116 mlx5e_timespec2usec(const struct timespec *ts) 1117 { 1118 1119 return ((uint64_t)ts->tv_sec * 1000000000 + ts->tv_nsec); 1120 } 1121 1122 static uint64_t 1123 mlx5e_hw_clock(struct mlx5e_priv *priv) 1124 { 1125 struct mlx5_init_seg *iseg; 1126 uint32_t hw_h, hw_h1, hw_l; 1127 1128 iseg = priv->mdev->iseg; 1129 do { 1130 hw_h = ioread32be(&iseg->internal_timer_h); 1131 hw_l = ioread32be(&iseg->internal_timer_l); 1132 hw_h1 = ioread32be(&iseg->internal_timer_h); 1133 } while (hw_h1 != hw_h); 1134 return (((uint64_t)hw_h << 32) | hw_l); 1135 } 1136 1137 /* 1138 * The calibration callout, it runs either in the context of the 1139 * thread which enables calibration, or in callout. It takes the 1140 * snapshot of system and adapter clocks, then advances the pointers to 1141 * the calibration point to allow rx path to read the consistent data 1142 * lockless. 1143 */ 1144 static void 1145 mlx5e_calibration_callout(void *arg) 1146 { 1147 struct mlx5e_priv *priv; 1148 struct mlx5e_clbr_point *next, *curr; 1149 struct timespec ts; 1150 int clbr_curr_next; 1151 1152 priv = arg; 1153 curr = &priv->clbr_points[priv->clbr_curr]; 1154 clbr_curr_next = priv->clbr_curr + 1; 1155 if (clbr_curr_next >= nitems(priv->clbr_points)) 1156 clbr_curr_next = 0; 1157 next = &priv->clbr_points[clbr_curr_next]; 1158 1159 next->base_prev = curr->base_curr; 1160 next->clbr_hw_prev = curr->clbr_hw_curr; 1161 1162 next->clbr_hw_curr = mlx5e_hw_clock(priv); 1163 if (((next->clbr_hw_curr - curr->clbr_hw_curr) >> MLX5E_TSTMP_PREC) == 1164 0) { 1165 if (priv->clbr_done != 0) { 1166 mlx5_en_err(priv->ifp, 1167 "HW failed tstmp frozen %#jx %#jx, disabling\n", 1168 next->clbr_hw_curr, curr->clbr_hw_prev); 1169 priv->clbr_done = 0; 1170 } 1171 atomic_store_rel_int(&curr->clbr_gen, 0); 1172 return; 1173 } 1174 1175 nanouptime(&ts); 1176 next->base_curr = mlx5e_timespec2usec(&ts); 1177 1178 curr->clbr_gen = 0; 1179 atomic_thread_fence_rel(); 1180 priv->clbr_curr = clbr_curr_next; 1181 atomic_store_rel_int(&next->clbr_gen, ++(priv->clbr_gen)); 1182 1183 if (priv->clbr_done < mlx5e_calibration_duration) 1184 priv->clbr_done++; 1185 mlx5e_reset_calibration_callout(priv); 1186 } 1187 1188 static const char *mlx5e_rq_stats_desc[] = { 1189 MLX5E_RQ_STATS(MLX5E_STATS_DESC) 1190 }; 1191 1192 static int 1193 mlx5e_create_rq(struct mlx5e_channel *c, 1194 struct mlx5e_rq_param *param, 1195 struct mlx5e_rq *rq) 1196 { 1197 struct mlx5e_priv *priv = c->priv; 1198 struct mlx5_core_dev *mdev = priv->mdev; 1199 char buffer[16]; 1200 void *rqc = param->rqc; 1201 void *rqc_wq = MLX5_ADDR_OF(rqc, rqc, wq); 1202 int wq_sz; 1203 int err; 1204 int i; 1205 u32 nsegs, wqe_sz; 1206 1207 err = mlx5e_get_wqe_sz(priv, &wqe_sz, &nsegs); 1208 if (err != 0) 1209 goto done; 1210 1211 /* Create DMA descriptor TAG */ 1212 if ((err = -bus_dma_tag_create( 1213 bus_get_dma_tag(mdev->pdev->dev.bsddev), 1214 1, /* any alignment */ 1215 0, /* no boundary */ 1216 BUS_SPACE_MAXADDR, /* lowaddr */ 1217 BUS_SPACE_MAXADDR, /* highaddr */ 1218 NULL, NULL, /* filter, filterarg */ 1219 nsegs * wqe_sz, /* maxsize */ 1220 nsegs, /* nsegments */ 1221 nsegs * wqe_sz, /* maxsegsize */ 1222 0, /* flags */ 1223 NULL, NULL, /* lockfunc, lockfuncarg */ 1224 &rq->dma_tag))) 1225 goto done; 1226 1227 err = mlx5_wq_ll_create(mdev, ¶m->wq, rqc_wq, &rq->wq, 1228 &rq->wq_ctrl); 1229 if (err) 1230 goto err_free_dma_tag; 1231 1232 rq->wq.db = &rq->wq.db[MLX5_RCV_DBR]; 1233 1234 err = mlx5e_get_wqe_sz(priv, &rq->wqe_sz, &rq->nsegs); 1235 if (err != 0) 1236 goto err_rq_wq_destroy; 1237 1238 wq_sz = mlx5_wq_ll_get_size(&rq->wq); 1239 1240 err = -tcp_lro_init_args(&rq->lro, priv->ifp, TCP_LRO_ENTRIES, wq_sz); 1241 if (err) 1242 goto err_rq_wq_destroy; 1243 1244 rq->mbuf = malloc_domainset(wq_sz * sizeof(rq->mbuf[0]), M_MLX5EN, 1245 mlx5_dev_domainset(mdev), M_WAITOK | M_ZERO); 1246 for (i = 0; i != wq_sz; i++) { 1247 struct mlx5e_rx_wqe *wqe = mlx5_wq_ll_get_wqe(&rq->wq, i); 1248 int j; 1249 1250 err = -bus_dmamap_create(rq->dma_tag, 0, &rq->mbuf[i].dma_map); 1251 if (err != 0) { 1252 while (i--) 1253 bus_dmamap_destroy(rq->dma_tag, rq->mbuf[i].dma_map); 1254 goto err_rq_mbuf_free; 1255 } 1256 1257 /* set value for constant fields */ 1258 for (j = 0; j < rq->nsegs; j++) 1259 wqe->data[j].lkey = cpu_to_be32(priv->mr.key); 1260 } 1261 1262 INIT_WORK(&rq->dim.work, mlx5e_dim_work); 1263 if (priv->params.rx_cq_moderation_mode < 2) { 1264 rq->dim.mode = NET_DIM_CQ_PERIOD_MODE_DISABLED; 1265 } else { 1266 void *cqc = container_of(param, 1267 struct mlx5e_channel_param, rq)->rx_cq.cqc; 1268 1269 switch (MLX5_GET(cqc, cqc, cq_period_mode)) { 1270 case MLX5_CQ_PERIOD_MODE_START_FROM_EQE: 1271 rq->dim.mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE; 1272 break; 1273 case MLX5_CQ_PERIOD_MODE_START_FROM_CQE: 1274 rq->dim.mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_CQE; 1275 break; 1276 default: 1277 rq->dim.mode = NET_DIM_CQ_PERIOD_MODE_DISABLED; 1278 break; 1279 } 1280 } 1281 1282 rq->ifp = priv->ifp; 1283 rq->channel = c; 1284 rq->ix = c->ix; 1285 1286 snprintf(buffer, sizeof(buffer), "rxstat%d", c->ix); 1287 mlx5e_create_stats(&rq->stats.ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet), 1288 buffer, mlx5e_rq_stats_desc, MLX5E_RQ_STATS_NUM, 1289 rq->stats.arg); 1290 return (0); 1291 1292 err_rq_mbuf_free: 1293 free(rq->mbuf, M_MLX5EN); 1294 tcp_lro_free(&rq->lro); 1295 err_rq_wq_destroy: 1296 mlx5_wq_destroy(&rq->wq_ctrl); 1297 err_free_dma_tag: 1298 bus_dma_tag_destroy(rq->dma_tag); 1299 done: 1300 return (err); 1301 } 1302 1303 static void 1304 mlx5e_destroy_rq(struct mlx5e_rq *rq) 1305 { 1306 int wq_sz; 1307 int i; 1308 1309 /* destroy all sysctl nodes */ 1310 sysctl_ctx_free(&rq->stats.ctx); 1311 1312 /* free leftover LRO packets, if any */ 1313 tcp_lro_free(&rq->lro); 1314 1315 wq_sz = mlx5_wq_ll_get_size(&rq->wq); 1316 for (i = 0; i != wq_sz; i++) { 1317 if (rq->mbuf[i].mbuf != NULL) { 1318 if (rq->mbuf[i].ipsec_mtag != NULL) 1319 m_tag_free(&rq->mbuf[i].ipsec_mtag->tag); 1320 bus_dmamap_unload(rq->dma_tag, rq->mbuf[i].dma_map); 1321 m_freem(rq->mbuf[i].mbuf); 1322 } 1323 bus_dmamap_destroy(rq->dma_tag, rq->mbuf[i].dma_map); 1324 } 1325 free(rq->mbuf, M_MLX5EN); 1326 mlx5_wq_destroy(&rq->wq_ctrl); 1327 bus_dma_tag_destroy(rq->dma_tag); 1328 } 1329 1330 static int 1331 mlx5e_enable_rq(struct mlx5e_rq *rq, struct mlx5e_rq_param *param) 1332 { 1333 struct mlx5e_channel *c = rq->channel; 1334 struct mlx5e_priv *priv = c->priv; 1335 struct mlx5_core_dev *mdev = priv->mdev; 1336 void *in; 1337 void *rqc; 1338 void *wq; 1339 int inlen; 1340 int err; 1341 u8 ts_format; 1342 1343 inlen = MLX5_ST_SZ_BYTES(create_rq_in) + 1344 sizeof(u64) * rq->wq_ctrl.buf.npages; 1345 in = mlx5_vzalloc(inlen); 1346 if (in == NULL) 1347 return (-ENOMEM); 1348 1349 ts_format = mlx5_get_rq_default_ts(mdev); 1350 rqc = MLX5_ADDR_OF(create_rq_in, in, ctx); 1351 wq = MLX5_ADDR_OF(rqc, rqc, wq); 1352 1353 memcpy(rqc, param->rqc, sizeof(param->rqc)); 1354 1355 MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RST); 1356 MLX5_SET(rqc, rqc, ts_format, ts_format); 1357 MLX5_SET(rqc, rqc, flush_in_error_en, 1); 1358 if (priv->counter_set_id >= 0) 1359 MLX5_SET(rqc, rqc, counter_set_id, priv->counter_set_id); 1360 MLX5_SET(wq, wq, log_wq_pg_sz, rq->wq_ctrl.buf.page_shift - 1361 MLX5_ADAPTER_PAGE_SHIFT); 1362 MLX5_SET64(wq, wq, dbr_addr, rq->wq_ctrl.db.dma); 1363 1364 mlx5_fill_page_array(&rq->wq_ctrl.buf, 1365 (__be64 *) MLX5_ADDR_OF(wq, wq, pas)); 1366 1367 err = mlx5_core_create_rq(mdev, in, inlen, &rq->rqn); 1368 1369 kvfree(in); 1370 1371 return (err); 1372 } 1373 1374 static int 1375 mlx5e_modify_rq(struct mlx5e_rq *rq, int curr_state, int next_state) 1376 { 1377 struct mlx5e_channel *c = rq->channel; 1378 struct mlx5e_priv *priv = c->priv; 1379 struct mlx5_core_dev *mdev = priv->mdev; 1380 1381 void *in; 1382 void *rqc; 1383 int inlen; 1384 int err; 1385 1386 inlen = MLX5_ST_SZ_BYTES(modify_rq_in); 1387 in = mlx5_vzalloc(inlen); 1388 if (in == NULL) 1389 return (-ENOMEM); 1390 1391 rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx); 1392 1393 MLX5_SET(modify_rq_in, in, rqn, rq->rqn); 1394 MLX5_SET(modify_rq_in, in, rq_state, curr_state); 1395 MLX5_SET(rqc, rqc, state, next_state); 1396 1397 err = mlx5_core_modify_rq(mdev, in, inlen); 1398 1399 kvfree(in); 1400 1401 return (err); 1402 } 1403 1404 static void 1405 mlx5e_disable_rq(struct mlx5e_rq *rq) 1406 { 1407 struct mlx5e_channel *c = rq->channel; 1408 struct mlx5e_priv *priv = c->priv; 1409 struct mlx5_core_dev *mdev = priv->mdev; 1410 1411 mlx5_core_destroy_rq(mdev, rq->rqn); 1412 } 1413 1414 static int 1415 mlx5e_open_rq(struct mlx5e_channel *c, 1416 struct mlx5e_rq_param *param, 1417 struct mlx5e_rq *rq) 1418 { 1419 int err; 1420 1421 err = mlx5e_create_rq(c, param, rq); 1422 if (err) 1423 return (err); 1424 1425 /* set CQN in RQ parameters */ 1426 MLX5_SET(rqc, param->rqc, cqn, c->rq.cq.mcq.cqn); 1427 1428 err = mlx5e_enable_rq(rq, param); 1429 if (err) 1430 goto err_destroy_rq; 1431 1432 err = mlx5e_modify_rq(rq, MLX5_RQC_STATE_RST, MLX5_RQC_STATE_RDY); 1433 if (err) 1434 goto err_disable_rq; 1435 1436 c->rq.enabled = 1; 1437 1438 return (0); 1439 1440 err_disable_rq: 1441 mlx5e_disable_rq(rq); 1442 err_destroy_rq: 1443 mlx5e_destroy_rq(rq); 1444 1445 return (err); 1446 } 1447 1448 static void 1449 mlx5e_close_rq(struct mlx5e_rq *rq) 1450 { 1451 mtx_lock(&rq->mtx); 1452 rq->enabled = 0; 1453 callout_stop(&rq->watchdog); 1454 mtx_unlock(&rq->mtx); 1455 1456 mlx5e_modify_rq(rq, MLX5_RQC_STATE_RDY, MLX5_RQC_STATE_ERR); 1457 } 1458 1459 static void 1460 mlx5e_close_rq_wait(struct mlx5e_rq *rq) 1461 { 1462 1463 mtx_lock(&rq->mtx); 1464 MPASS(rq->enabled == 0); 1465 while (rq->processing > 0) { 1466 /* 1467 * No wakeup, relying on timeout. 1468 * Use msleep_sbt() since msleep() conflicts with linuxkpi. 1469 */ 1470 msleep_sbt(&rq->processing, &rq->mtx, 0, "mlx5ecrq", 1471 tick_sbt * hz, 0, C_HARDCLOCK); 1472 } 1473 mtx_unlock(&rq->mtx); 1474 mlx5e_disable_rq(rq); 1475 mlx5e_close_cq(&rq->cq); 1476 cancel_work_sync(&rq->dim.work); 1477 mlx5e_destroy_rq(rq); 1478 } 1479 1480 /* 1481 * What is a drop RQ and why is it needed? 1482 * 1483 * The RSS indirection table, also called the RQT, selects the 1484 * destination RQ based on the receive queue number, RQN. The RQT is 1485 * frequently referred to by flow steering rules to distribute traffic 1486 * among multiple RQs. The problem is that the RQs cannot be destroyed 1487 * before the RQT referring them is destroyed too. Further, TLS RX 1488 * rules may still be referring to the RQT even if the link went 1489 * down. Because there is no magic RQN for dropping packets, we create 1490 * a dummy RQ, also called drop RQ, which sole purpose is to drop all 1491 * received packets. When the link goes down this RQN is filled in all 1492 * RQT entries, of the main RQT, so the real RQs which are about to be 1493 * destroyed can be released and the TLS RX rules can be sustained. 1494 */ 1495 static void 1496 mlx5e_open_drop_rq_comp(struct mlx5_core_cq *mcq __unused, struct mlx5_eqe *eqe __unused) 1497 { 1498 } 1499 1500 static int 1501 mlx5e_open_drop_rq(struct mlx5e_priv *priv, 1502 struct mlx5e_rq *drop_rq) 1503 { 1504 struct mlx5e_cq_param param_cq = {}; 1505 struct mlx5e_rq_param param_rq = {}; 1506 void *rqc_wq = MLX5_ADDR_OF(rqc, param_rq.rqc, wq); 1507 int err; 1508 1509 /* set channel pointer */ 1510 drop_rq->channel = priv->channel; 1511 1512 /* set basic CQ parameters needed */ 1513 MLX5_SET(cqc, param_cq.cqc, log_cq_size, 0); 1514 MLX5_SET(cqc, param_cq.cqc, uar_page, priv->mdev->priv.uar->index); 1515 1516 /* open receive completion queue */ 1517 err = mlx5e_open_cq(priv, ¶m_cq, &drop_rq->cq, 1518 &mlx5e_open_drop_rq_comp, 0); 1519 if (err) 1520 goto err_done; 1521 1522 /* set basic WQ parameters needed */ 1523 MLX5_SET(wq, rqc_wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST); 1524 MLX5_SET(wq, rqc_wq, end_padding_mode, MLX5_WQ_END_PAD_MODE_ALIGN); 1525 MLX5_SET(wq, rqc_wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe) + sizeof(struct mlx5_wqe_data_seg))); 1526 MLX5_SET(wq, rqc_wq, log_wq_sz, 0); 1527 MLX5_SET(wq, rqc_wq, pd, priv->pdn); 1528 1529 param_rq.wq.linear = 1; 1530 1531 err = mlx5_wq_ll_create(priv->mdev, ¶m_rq.wq, rqc_wq, &drop_rq->wq, 1532 &drop_rq->wq_ctrl); 1533 if (err) 1534 goto err_close_cq; 1535 1536 /* set CQN in RQ parameters */ 1537 MLX5_SET(rqc, param_rq.rqc, cqn, drop_rq->cq.mcq.cqn); 1538 1539 err = mlx5e_enable_rq(drop_rq, ¶m_rq); 1540 if (err) 1541 goto err_wq_destroy; 1542 1543 err = mlx5e_modify_rq(drop_rq, MLX5_RQC_STATE_RST, MLX5_RQC_STATE_RDY); 1544 if (err) 1545 goto err_disable_rq; 1546 1547 return (err); 1548 1549 err_disable_rq: 1550 mlx5e_disable_rq(drop_rq); 1551 err_wq_destroy: 1552 mlx5_wq_destroy(&drop_rq->wq_ctrl); 1553 err_close_cq: 1554 mlx5e_close_cq(&drop_rq->cq); 1555 err_done: 1556 return (err); 1557 } 1558 1559 static void 1560 mlx5e_close_drop_rq(struct mlx5e_rq *drop_rq) 1561 { 1562 mlx5e_modify_rq(drop_rq, MLX5_RQC_STATE_RDY, MLX5_RQC_STATE_ERR); 1563 mlx5e_disable_rq(drop_rq); 1564 mlx5_wq_destroy(&drop_rq->wq_ctrl); 1565 mlx5e_close_cq(&drop_rq->cq); 1566 } 1567 1568 void 1569 mlx5e_free_sq_db(struct mlx5e_sq *sq) 1570 { 1571 int wq_sz = mlx5_wq_cyc_get_size(&sq->wq); 1572 int x; 1573 1574 for (x = 0; x != wq_sz; x++) { 1575 if (sq->mbuf[x].mbuf != NULL) { 1576 bus_dmamap_unload(sq->dma_tag, sq->mbuf[x].dma_map); 1577 m_freem(sq->mbuf[x].mbuf); 1578 } 1579 if (sq->mbuf[x].mst != NULL) { 1580 m_snd_tag_rele(sq->mbuf[x].mst); 1581 sq->mbuf[x].mst = NULL; 1582 } 1583 bus_dmamap_destroy(sq->dma_tag, sq->mbuf[x].dma_map); 1584 } 1585 free(sq->mbuf, M_MLX5EN); 1586 } 1587 1588 int 1589 mlx5e_alloc_sq_db(struct mlx5e_sq *sq) 1590 { 1591 int wq_sz = mlx5_wq_cyc_get_size(&sq->wq); 1592 int err; 1593 int x; 1594 1595 sq->mbuf = malloc_domainset(wq_sz * sizeof(sq->mbuf[0]), M_MLX5EN, 1596 mlx5_dev_domainset(sq->priv->mdev), M_WAITOK | M_ZERO); 1597 1598 /* Create DMA descriptor MAPs */ 1599 for (x = 0; x != wq_sz; x++) { 1600 err = -bus_dmamap_create(sq->dma_tag, 0, &sq->mbuf[x].dma_map); 1601 if (err != 0) { 1602 while (x--) 1603 bus_dmamap_destroy(sq->dma_tag, sq->mbuf[x].dma_map); 1604 free(sq->mbuf, M_MLX5EN); 1605 return (err); 1606 } 1607 } 1608 return (0); 1609 } 1610 1611 static const char *mlx5e_sq_stats_desc[] = { 1612 MLX5E_SQ_STATS(MLX5E_STATS_DESC) 1613 }; 1614 1615 void 1616 mlx5e_update_sq_inline(struct mlx5e_sq *sq) 1617 { 1618 sq->max_inline = sq->priv->params.tx_max_inline; 1619 sq->min_inline_mode = sq->priv->params.tx_min_inline_mode; 1620 1621 /* 1622 * Check if trust state is DSCP or if inline mode is NONE which 1623 * indicates CX-5 or newer hardware. 1624 */ 1625 if (sq->priv->params_ethtool.trust_state != MLX5_QPTS_TRUST_PCP || 1626 sq->min_inline_mode == MLX5_INLINE_MODE_NONE) { 1627 if (MLX5_CAP_ETH(sq->priv->mdev, wqe_vlan_insert)) 1628 sq->min_insert_caps = MLX5E_INSERT_VLAN | MLX5E_INSERT_NON_VLAN; 1629 else 1630 sq->min_insert_caps = MLX5E_INSERT_NON_VLAN; 1631 } else { 1632 sq->min_insert_caps = 0; 1633 } 1634 } 1635 1636 static void 1637 mlx5e_refresh_sq_inline_sub(struct mlx5e_priv *priv, struct mlx5e_channel *c) 1638 { 1639 int i; 1640 1641 for (i = 0; i != priv->num_tc; i++) { 1642 mtx_lock(&c->sq[i].lock); 1643 mlx5e_update_sq_inline(&c->sq[i]); 1644 mtx_unlock(&c->sq[i].lock); 1645 } 1646 } 1647 1648 void 1649 mlx5e_refresh_sq_inline(struct mlx5e_priv *priv) 1650 { 1651 int i; 1652 1653 /* check if channels are closed */ 1654 if (test_bit(MLX5E_STATE_OPENED, &priv->state) == 0) 1655 return; 1656 1657 for (i = 0; i < priv->params.num_channels; i++) 1658 mlx5e_refresh_sq_inline_sub(priv, &priv->channel[i]); 1659 } 1660 1661 static int 1662 mlx5e_create_sq(struct mlx5e_channel *c, 1663 int tc, 1664 struct mlx5e_sq_param *param, 1665 struct mlx5e_sq *sq) 1666 { 1667 struct mlx5e_priv *priv = c->priv; 1668 struct mlx5_core_dev *mdev = priv->mdev; 1669 char buffer[16]; 1670 void *sqc = param->sqc; 1671 void *sqc_wq = MLX5_ADDR_OF(sqc, sqc, wq); 1672 int err; 1673 1674 /* Create DMA descriptor TAG */ 1675 if ((err = -bus_dma_tag_create( 1676 bus_get_dma_tag(mdev->pdev->dev.bsddev), 1677 1, /* any alignment */ 1678 0, /* no boundary */ 1679 BUS_SPACE_MAXADDR, /* lowaddr */ 1680 BUS_SPACE_MAXADDR, /* highaddr */ 1681 NULL, NULL, /* filter, filterarg */ 1682 MLX5E_MAX_TX_PAYLOAD_SIZE, /* maxsize */ 1683 MLX5E_MAX_TX_MBUF_FRAGS, /* nsegments */ 1684 MLX5E_MAX_TX_MBUF_SIZE, /* maxsegsize */ 1685 0, /* flags */ 1686 NULL, NULL, /* lockfunc, lockfuncarg */ 1687 &sq->dma_tag))) 1688 goto done; 1689 1690 sq->mkey_be = cpu_to_be32(priv->mr.key); 1691 sq->ifp = priv->ifp; 1692 sq->priv = priv; 1693 sq->tc = tc; 1694 1695 err = mlx5_wq_cyc_create(mdev, ¶m->wq, sqc_wq, &sq->wq, 1696 &sq->wq_ctrl); 1697 if (err) 1698 goto err_free_dma_tag; 1699 1700 sq->wq.db = &sq->wq.db[MLX5_SND_DBR]; 1701 1702 err = mlx5e_alloc_sq_db(sq); 1703 if (err) 1704 goto err_sq_wq_destroy; 1705 1706 mlx5e_update_sq_inline(sq); 1707 1708 snprintf(buffer, sizeof(buffer), "txstat%dtc%d", c->ix, tc); 1709 mlx5e_create_stats(&sq->stats.ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet), 1710 buffer, mlx5e_sq_stats_desc, MLX5E_SQ_STATS_NUM, 1711 sq->stats.arg); 1712 1713 return (0); 1714 1715 err_sq_wq_destroy: 1716 mlx5_wq_destroy(&sq->wq_ctrl); 1717 1718 err_free_dma_tag: 1719 bus_dma_tag_destroy(sq->dma_tag); 1720 done: 1721 return (err); 1722 } 1723 1724 static void 1725 mlx5e_destroy_sq(struct mlx5e_sq *sq) 1726 { 1727 /* destroy all sysctl nodes */ 1728 sysctl_ctx_free(&sq->stats.ctx); 1729 1730 mlx5e_free_sq_db(sq); 1731 mlx5_wq_destroy(&sq->wq_ctrl); 1732 bus_dma_tag_destroy(sq->dma_tag); 1733 } 1734 1735 int 1736 mlx5e_enable_sq(struct mlx5e_sq *sq, struct mlx5e_sq_param *param, 1737 const struct mlx5_sq_bfreg *bfreg, int tis_num) 1738 { 1739 void *in; 1740 void *sqc; 1741 void *wq; 1742 int inlen; 1743 int err; 1744 u8 ts_format; 1745 1746 inlen = MLX5_ST_SZ_BYTES(create_sq_in) + 1747 sizeof(u64) * sq->wq_ctrl.buf.npages; 1748 in = mlx5_vzalloc(inlen); 1749 if (in == NULL) 1750 return (-ENOMEM); 1751 1752 sq->uar_map = bfreg->map; 1753 1754 ts_format = mlx5_get_sq_default_ts(sq->priv->mdev); 1755 sqc = MLX5_ADDR_OF(create_sq_in, in, ctx); 1756 wq = MLX5_ADDR_OF(sqc, sqc, wq); 1757 1758 memcpy(sqc, param->sqc, sizeof(param->sqc)); 1759 1760 MLX5_SET(sqc, sqc, tis_num_0, tis_num); 1761 MLX5_SET(sqc, sqc, cqn, sq->cq.mcq.cqn); 1762 MLX5_SET(sqc, sqc, state, MLX5_SQC_STATE_RST); 1763 MLX5_SET(sqc, sqc, ts_format, ts_format); 1764 MLX5_SET(sqc, sqc, tis_lst_sz, 1); 1765 MLX5_SET(sqc, sqc, flush_in_error_en, 1); 1766 MLX5_SET(sqc, sqc, allow_swp, 1); 1767 1768 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC); 1769 MLX5_SET(wq, wq, uar_page, bfreg->index); 1770 MLX5_SET(wq, wq, log_wq_pg_sz, sq->wq_ctrl.buf.page_shift - 1771 MLX5_ADAPTER_PAGE_SHIFT); 1772 MLX5_SET64(wq, wq, dbr_addr, sq->wq_ctrl.db.dma); 1773 1774 mlx5_fill_page_array(&sq->wq_ctrl.buf, 1775 (__be64 *) MLX5_ADDR_OF(wq, wq, pas)); 1776 1777 err = mlx5_core_create_sq(sq->priv->mdev, in, inlen, &sq->sqn); 1778 1779 kvfree(in); 1780 1781 return (err); 1782 } 1783 1784 int 1785 mlx5e_modify_sq(struct mlx5e_sq *sq, int curr_state, int next_state) 1786 { 1787 void *in; 1788 void *sqc; 1789 int inlen; 1790 int err; 1791 1792 inlen = MLX5_ST_SZ_BYTES(modify_sq_in); 1793 in = mlx5_vzalloc(inlen); 1794 if (in == NULL) 1795 return (-ENOMEM); 1796 1797 sqc = MLX5_ADDR_OF(modify_sq_in, in, ctx); 1798 1799 MLX5_SET(modify_sq_in, in, sqn, sq->sqn); 1800 MLX5_SET(modify_sq_in, in, sq_state, curr_state); 1801 MLX5_SET(sqc, sqc, state, next_state); 1802 1803 err = mlx5_core_modify_sq(sq->priv->mdev, in, inlen); 1804 1805 kvfree(in); 1806 1807 return (err); 1808 } 1809 1810 void 1811 mlx5e_disable_sq(struct mlx5e_sq *sq) 1812 { 1813 1814 mlx5_core_destroy_sq(sq->priv->mdev, sq->sqn); 1815 } 1816 1817 static int 1818 mlx5e_open_sq(struct mlx5e_channel *c, 1819 int tc, 1820 struct mlx5e_sq_param *param, 1821 struct mlx5e_sq *sq) 1822 { 1823 int err; 1824 1825 sq->cev_factor = c->priv->params_ethtool.tx_completion_fact; 1826 1827 /* ensure the TX completion event factor is not zero */ 1828 if (sq->cev_factor == 0) 1829 sq->cev_factor = 1; 1830 1831 err = mlx5e_create_sq(c, tc, param, sq); 1832 if (err) 1833 return (err); 1834 1835 err = mlx5e_enable_sq(sq, param, &c->bfreg, c->priv->tisn[tc]); 1836 if (err) 1837 goto err_destroy_sq; 1838 1839 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RST, MLX5_SQC_STATE_RDY); 1840 if (err) 1841 goto err_disable_sq; 1842 1843 WRITE_ONCE(sq->running, 1); 1844 1845 return (0); 1846 1847 err_disable_sq: 1848 mlx5e_disable_sq(sq); 1849 err_destroy_sq: 1850 mlx5e_destroy_sq(sq); 1851 1852 return (err); 1853 } 1854 1855 static void 1856 mlx5e_sq_send_nops_locked(struct mlx5e_sq *sq, int can_sleep) 1857 { 1858 /* fill up remainder with NOPs */ 1859 while (sq->cev_counter != 0) { 1860 while (!mlx5e_sq_has_room_for(sq, 1)) { 1861 if (can_sleep != 0) { 1862 mtx_unlock(&sq->lock); 1863 msleep(4); 1864 mtx_lock(&sq->lock); 1865 } else { 1866 goto done; 1867 } 1868 } 1869 /* send a single NOP */ 1870 mlx5e_send_nop(sq, 1); 1871 atomic_thread_fence_rel(); 1872 } 1873 done: 1874 mlx5e_tx_notify_hw(sq, false); 1875 } 1876 1877 void 1878 mlx5e_sq_cev_timeout(void *arg) 1879 { 1880 struct mlx5e_sq *sq = arg; 1881 1882 mtx_assert(&sq->lock, MA_OWNED); 1883 1884 /* check next state */ 1885 switch (sq->cev_next_state) { 1886 case MLX5E_CEV_STATE_SEND_NOPS: 1887 /* fill TX ring with NOPs, if any */ 1888 mlx5e_sq_send_nops_locked(sq, 0); 1889 1890 /* check if completed */ 1891 if (sq->cev_counter == 0) { 1892 sq->cev_next_state = MLX5E_CEV_STATE_INITIAL; 1893 return; 1894 } 1895 break; 1896 default: 1897 /* send NOPs on next timeout */ 1898 sq->cev_next_state = MLX5E_CEV_STATE_SEND_NOPS; 1899 break; 1900 } 1901 1902 /* restart timer */ 1903 callout_reset_curcpu(&sq->cev_callout, hz, mlx5e_sq_cev_timeout, sq); 1904 } 1905 1906 void 1907 mlx5e_drain_sq(struct mlx5e_sq *sq) 1908 { 1909 int error; 1910 struct mlx5_core_dev *mdev= sq->priv->mdev; 1911 1912 /* 1913 * Check if already stopped. 1914 * 1915 * NOTE: Serialization of this function is managed by the 1916 * caller ensuring the priv's state lock is locked or in case 1917 * of rate limit support, a single thread manages drain and 1918 * resume of SQs. The "running" variable can therefore safely 1919 * be read without any locks. 1920 */ 1921 if (READ_ONCE(sq->running) == 0) 1922 return; 1923 1924 /* don't put more packets into the SQ */ 1925 WRITE_ONCE(sq->running, 0); 1926 1927 /* serialize access to DMA rings */ 1928 mtx_lock(&sq->lock); 1929 1930 /* teardown event factor timer, if any */ 1931 sq->cev_next_state = MLX5E_CEV_STATE_HOLD_NOPS; 1932 callout_stop(&sq->cev_callout); 1933 1934 /* send dummy NOPs in order to flush the transmit ring */ 1935 mlx5e_sq_send_nops_locked(sq, 1); 1936 mtx_unlock(&sq->lock); 1937 1938 /* wait till SQ is empty or link is down */ 1939 mtx_lock(&sq->lock); 1940 while (sq->cc != sq->pc && 1941 (sq->priv->media_status_last & IFM_ACTIVE) != 0 && 1942 mdev->state != MLX5_DEVICE_STATE_INTERNAL_ERROR && 1943 pci_channel_offline(mdev->pdev) == 0) { 1944 mtx_unlock(&sq->lock); 1945 msleep(1); 1946 sq->cq.mcq.comp(&sq->cq.mcq, NULL); 1947 mtx_lock(&sq->lock); 1948 } 1949 mtx_unlock(&sq->lock); 1950 1951 /* error out remaining requests */ 1952 error = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RDY, MLX5_SQC_STATE_ERR); 1953 if (error != 0) { 1954 mlx5_en_err(sq->ifp, 1955 "mlx5e_modify_sq() from RDY to ERR failed: %d\n", error); 1956 } 1957 1958 /* wait till SQ is empty */ 1959 mtx_lock(&sq->lock); 1960 while (sq->cc != sq->pc && 1961 mdev->state != MLX5_DEVICE_STATE_INTERNAL_ERROR && 1962 pci_channel_offline(mdev->pdev) == 0) { 1963 mtx_unlock(&sq->lock); 1964 msleep(1); 1965 sq->cq.mcq.comp(&sq->cq.mcq, NULL); 1966 mtx_lock(&sq->lock); 1967 } 1968 mtx_unlock(&sq->lock); 1969 } 1970 1971 static void 1972 mlx5e_close_sq_wait(struct mlx5e_sq *sq) 1973 { 1974 1975 mlx5e_drain_sq(sq); 1976 mlx5e_disable_sq(sq); 1977 mlx5e_destroy_sq(sq); 1978 } 1979 1980 static int 1981 mlx5e_create_cq(struct mlx5e_priv *priv, 1982 struct mlx5e_cq_param *param, 1983 struct mlx5e_cq *cq, 1984 mlx5e_cq_comp_t *comp, 1985 int eq_ix) 1986 { 1987 struct mlx5_core_dev *mdev = priv->mdev; 1988 struct mlx5_core_cq *mcq = &cq->mcq; 1989 int eqn_not_used; 1990 int irqn; 1991 int err; 1992 u32 i; 1993 1994 err = mlx5_vector2eqn(mdev, eq_ix, &eqn_not_used, &irqn); 1995 if (err) 1996 return (err); 1997 1998 err = mlx5_cqwq_create(mdev, ¶m->wq, param->cqc, &cq->wq, 1999 &cq->wq_ctrl); 2000 if (err) 2001 return (err); 2002 2003 mcq->cqe_sz = 64; 2004 mcq->set_ci_db = cq->wq_ctrl.db.db; 2005 mcq->arm_db = cq->wq_ctrl.db.db + 1; 2006 *mcq->set_ci_db = 0; 2007 *mcq->arm_db = 0; 2008 mcq->vector = eq_ix; 2009 mcq->comp = comp; 2010 mcq->event = mlx5e_cq_error_event; 2011 mcq->irqn = irqn; 2012 2013 for (i = 0; i < mlx5_cqwq_get_size(&cq->wq); i++) { 2014 struct mlx5_cqe64 *cqe = mlx5_cqwq_get_wqe(&cq->wq, i); 2015 2016 cqe->op_own = 0xf1; 2017 } 2018 2019 cq->priv = priv; 2020 2021 return (0); 2022 } 2023 2024 static void 2025 mlx5e_destroy_cq(struct mlx5e_cq *cq) 2026 { 2027 mlx5_wq_destroy(&cq->wq_ctrl); 2028 } 2029 2030 static int 2031 mlx5e_enable_cq(struct mlx5e_cq *cq, struct mlx5e_cq_param *param, int eq_ix) 2032 { 2033 struct mlx5_core_cq *mcq = &cq->mcq; 2034 u32 out[MLX5_ST_SZ_DW(create_cq_out)]; 2035 void *in; 2036 void *cqc; 2037 int inlen; 2038 int irqn_not_used; 2039 int eqn; 2040 int err; 2041 2042 inlen = MLX5_ST_SZ_BYTES(create_cq_in) + 2043 sizeof(u64) * cq->wq_ctrl.buf.npages; 2044 in = mlx5_vzalloc(inlen); 2045 if (in == NULL) 2046 return (-ENOMEM); 2047 2048 cqc = MLX5_ADDR_OF(create_cq_in, in, cq_context); 2049 2050 memcpy(cqc, param->cqc, sizeof(param->cqc)); 2051 2052 mlx5_fill_page_array(&cq->wq_ctrl.buf, 2053 (__be64 *) MLX5_ADDR_OF(create_cq_in, in, pas)); 2054 2055 mlx5_vector2eqn(cq->priv->mdev, eq_ix, &eqn, &irqn_not_used); 2056 2057 MLX5_SET(cqc, cqc, c_eqn, eqn); 2058 MLX5_SET(cqc, cqc, log_page_size, cq->wq_ctrl.buf.page_shift - 2059 MLX5_ADAPTER_PAGE_SHIFT); 2060 MLX5_SET64(cqc, cqc, dbr_addr, cq->wq_ctrl.db.dma); 2061 2062 err = mlx5_core_create_cq(cq->priv->mdev, mcq, in, inlen, out, sizeof(out)); 2063 2064 kvfree(in); 2065 2066 if (err) 2067 return (err); 2068 2069 mlx5e_cq_arm(cq, MLX5_GET_DOORBELL_LOCK(&cq->priv->doorbell_lock)); 2070 2071 return (0); 2072 } 2073 2074 static void 2075 mlx5e_disable_cq(struct mlx5e_cq *cq) 2076 { 2077 2078 mlx5_core_destroy_cq(cq->priv->mdev, &cq->mcq); 2079 } 2080 2081 int 2082 mlx5e_open_cq(struct mlx5e_priv *priv, 2083 struct mlx5e_cq_param *param, 2084 struct mlx5e_cq *cq, 2085 mlx5e_cq_comp_t *comp, 2086 int eq_ix) 2087 { 2088 int err; 2089 2090 err = mlx5e_create_cq(priv, param, cq, comp, eq_ix); 2091 if (err) 2092 return (err); 2093 2094 err = mlx5e_enable_cq(cq, param, eq_ix); 2095 if (err) 2096 goto err_destroy_cq; 2097 2098 return (0); 2099 2100 err_destroy_cq: 2101 mlx5e_destroy_cq(cq); 2102 2103 return (err); 2104 } 2105 2106 void 2107 mlx5e_close_cq(struct mlx5e_cq *cq) 2108 { 2109 mlx5e_disable_cq(cq); 2110 mlx5e_destroy_cq(cq); 2111 } 2112 2113 static int 2114 mlx5e_open_tx_cqs(struct mlx5e_channel *c, 2115 struct mlx5e_channel_param *cparam) 2116 { 2117 int err; 2118 int tc; 2119 2120 for (tc = 0; tc < c->priv->num_tc; tc++) { 2121 /* open completion queue */ 2122 err = mlx5e_open_cq(c->priv, &cparam->tx_cq, &c->sq[tc].cq, 2123 &mlx5e_tx_cq_comp, c->ix); 2124 if (err) 2125 goto err_close_tx_cqs; 2126 } 2127 return (0); 2128 2129 err_close_tx_cqs: 2130 for (tc--; tc >= 0; tc--) 2131 mlx5e_close_cq(&c->sq[tc].cq); 2132 2133 return (err); 2134 } 2135 2136 static void 2137 mlx5e_close_tx_cqs(struct mlx5e_channel *c) 2138 { 2139 int tc; 2140 2141 for (tc = 0; tc < c->priv->num_tc; tc++) 2142 mlx5e_close_cq(&c->sq[tc].cq); 2143 } 2144 2145 static int 2146 mlx5e_open_sqs(struct mlx5e_channel *c, 2147 struct mlx5e_channel_param *cparam) 2148 { 2149 int err; 2150 int tc; 2151 2152 for (tc = 0; tc < c->priv->num_tc; tc++) { 2153 err = mlx5e_open_sq(c, tc, &cparam->sq, &c->sq[tc]); 2154 if (err) 2155 goto err_close_sqs; 2156 } 2157 2158 return (0); 2159 2160 err_close_sqs: 2161 for (tc--; tc >= 0; tc--) 2162 mlx5e_close_sq_wait(&c->sq[tc]); 2163 2164 return (err); 2165 } 2166 2167 static void 2168 mlx5e_close_sqs_wait(struct mlx5e_channel *c) 2169 { 2170 int tc; 2171 2172 for (tc = 0; tc < c->priv->num_tc; tc++) 2173 mlx5e_close_sq_wait(&c->sq[tc]); 2174 } 2175 2176 static void 2177 mlx5e_chan_static_init(struct mlx5e_priv *priv, struct mlx5e_channel *c, int ix) 2178 { 2179 int tc; 2180 2181 /* setup priv and channel number */ 2182 c->priv = priv; 2183 c->ix = ix; 2184 2185 /* setup send tag */ 2186 m_snd_tag_init(&c->tag, c->priv->ifp, &mlx5e_ul_snd_tag_sw); 2187 2188 init_completion(&c->completion); 2189 2190 mtx_init(&c->rq.mtx, "mlx5rx", MTX_NETWORK_LOCK, MTX_DEF); 2191 2192 callout_init_mtx(&c->rq.watchdog, &c->rq.mtx, 0); 2193 2194 for (tc = 0; tc != MLX5E_MAX_TX_NUM_TC; tc++) { 2195 struct mlx5e_sq *sq = c->sq + tc; 2196 2197 mtx_init(&sq->lock, "mlx5tx", 2198 MTX_NETWORK_LOCK " TX", MTX_DEF); 2199 mtx_init(&sq->comp_lock, "mlx5comp", 2200 MTX_NETWORK_LOCK " TX", MTX_DEF); 2201 2202 callout_init_mtx(&sq->cev_callout, &sq->lock, 0); 2203 } 2204 2205 mlx5e_iq_static_init(&c->iq); 2206 } 2207 2208 static void 2209 mlx5e_chan_wait_for_completion(struct mlx5e_channel *c) 2210 { 2211 2212 m_snd_tag_rele(&c->tag); 2213 wait_for_completion(&c->completion); 2214 } 2215 2216 static void 2217 mlx5e_priv_wait_for_completion(struct mlx5e_priv *priv, const uint32_t channels) 2218 { 2219 uint32_t x; 2220 2221 for (x = 0; x != channels; x++) 2222 mlx5e_chan_wait_for_completion(&priv->channel[x]); 2223 } 2224 2225 static void 2226 mlx5e_chan_static_destroy(struct mlx5e_channel *c) 2227 { 2228 int tc; 2229 2230 callout_drain(&c->rq.watchdog); 2231 2232 mtx_destroy(&c->rq.mtx); 2233 2234 for (tc = 0; tc != MLX5E_MAX_TX_NUM_TC; tc++) { 2235 callout_drain(&c->sq[tc].cev_callout); 2236 mtx_destroy(&c->sq[tc].lock); 2237 mtx_destroy(&c->sq[tc].comp_lock); 2238 } 2239 2240 mlx5e_iq_static_destroy(&c->iq); 2241 } 2242 2243 static int 2244 mlx5e_open_channel(struct mlx5e_priv *priv, 2245 struct mlx5e_channel_param *cparam, 2246 struct mlx5e_channel *c) 2247 { 2248 struct epoch_tracker et; 2249 int i, err; 2250 2251 /* zero non-persistent data */ 2252 MLX5E_ZERO(&c->rq, mlx5e_rq_zero_start); 2253 for (i = 0; i != priv->num_tc; i++) 2254 MLX5E_ZERO(&c->sq[i], mlx5e_sq_zero_start); 2255 MLX5E_ZERO(&c->iq, mlx5e_iq_zero_start); 2256 2257 /* open transmit completion queue */ 2258 err = mlx5e_open_tx_cqs(c, cparam); 2259 if (err) 2260 goto err_free; 2261 2262 /* open receive completion queue */ 2263 err = mlx5e_open_cq(c->priv, &cparam->rx_cq, &c->rq.cq, 2264 &mlx5e_rx_cq_comp, c->ix); 2265 if (err) 2266 goto err_close_tx_cqs; 2267 2268 err = mlx5e_open_sqs(c, cparam); 2269 if (err) 2270 goto err_close_rx_cq; 2271 2272 err = mlx5e_iq_open(c, &cparam->sq, &cparam->tx_cq, &c->iq); 2273 if (err) 2274 goto err_close_sqs; 2275 2276 err = mlx5e_open_rq(c, &cparam->rq, &c->rq); 2277 if (err) 2278 goto err_close_iq; 2279 2280 /* poll receive queue initially */ 2281 NET_EPOCH_ENTER(et); 2282 c->rq.cq.mcq.comp(&c->rq.cq.mcq, NULL); 2283 NET_EPOCH_EXIT(et); 2284 2285 return (0); 2286 2287 err_close_iq: 2288 mlx5e_iq_close(&c->iq); 2289 2290 err_close_sqs: 2291 mlx5e_close_sqs_wait(c); 2292 2293 err_close_rx_cq: 2294 mlx5e_close_cq(&c->rq.cq); 2295 2296 err_close_tx_cqs: 2297 mlx5e_close_tx_cqs(c); 2298 2299 err_free: 2300 return (err); 2301 } 2302 2303 static void 2304 mlx5e_close_channel(struct mlx5e_channel *c) 2305 { 2306 mlx5e_close_rq(&c->rq); 2307 } 2308 2309 static void 2310 mlx5e_close_channel_wait(struct mlx5e_channel *c) 2311 { 2312 mlx5e_close_rq_wait(&c->rq); 2313 mlx5e_iq_close(&c->iq); 2314 mlx5e_close_sqs_wait(c); 2315 mlx5e_close_tx_cqs(c); 2316 } 2317 2318 static int 2319 mlx5e_get_wqe_sz(struct mlx5e_priv *priv, u32 *wqe_sz, u32 *nsegs) 2320 { 2321 u32 r, n, maxs; 2322 2323 maxs = priv->params.hw_lro_en ? priv->params.lro_wqe_sz : 2324 MLX5E_SW2MB_MTU(if_getmtu(priv->ifp)); 2325 r = maxs > MCLBYTES ? MJUMPAGESIZE : MCLBYTES; 2326 2327 /* 2328 * n + 1 must be a power of two, because stride size must be. 2329 * Stride size is 16 * (n + 1), as the first segment is 2330 * control. 2331 */ 2332 n = roundup_pow_of_two(1 + howmany(maxs, r)) - 1; 2333 if (n > MLX5E_MAX_BUSDMA_RX_SEGS) 2334 return (-ENOMEM); 2335 2336 *wqe_sz = r; 2337 *nsegs = n; 2338 return (0); 2339 } 2340 2341 static void 2342 mlx5e_build_rq_param(struct mlx5e_priv *priv, 2343 struct mlx5e_rq_param *param) 2344 { 2345 void *rqc = param->rqc; 2346 void *wq = MLX5_ADDR_OF(rqc, rqc, wq); 2347 u32 wqe_sz, nsegs; 2348 2349 mlx5e_get_wqe_sz(priv, &wqe_sz, &nsegs); 2350 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST); 2351 MLX5_SET(wq, wq, end_padding_mode, MLX5_WQ_END_PAD_MODE_ALIGN); 2352 MLX5_SET(wq, wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe) + 2353 nsegs * sizeof(struct mlx5_wqe_data_seg))); 2354 MLX5_SET(wq, wq, log_wq_sz, priv->params.log_rq_size); 2355 MLX5_SET(wq, wq, pd, priv->pdn); 2356 2357 param->wq.linear = 1; 2358 } 2359 2360 static void 2361 mlx5e_build_sq_param(struct mlx5e_priv *priv, 2362 struct mlx5e_sq_param *param) 2363 { 2364 void *sqc = param->sqc; 2365 void *wq = MLX5_ADDR_OF(sqc, sqc, wq); 2366 2367 MLX5_SET(wq, wq, log_wq_sz, priv->params.log_sq_size); 2368 MLX5_SET(wq, wq, log_wq_stride, ilog2(MLX5_SEND_WQE_BB)); 2369 MLX5_SET(wq, wq, pd, priv->pdn); 2370 2371 param->wq.linear = 1; 2372 } 2373 2374 static void 2375 mlx5e_build_common_cq_param(struct mlx5e_priv *priv, 2376 struct mlx5e_cq_param *param) 2377 { 2378 void *cqc = param->cqc; 2379 2380 MLX5_SET(cqc, cqc, uar_page, priv->mdev->priv.uar->index); 2381 } 2382 2383 static void 2384 mlx5e_get_default_profile(struct mlx5e_priv *priv, int mode, struct net_dim_cq_moder *ptr) 2385 { 2386 2387 *ptr = net_dim_get_profile(mode, MLX5E_DIM_DEFAULT_PROFILE); 2388 2389 /* apply LRO restrictions */ 2390 if (priv->params.hw_lro_en && 2391 ptr->pkts > MLX5E_DIM_MAX_RX_CQ_MODERATION_PKTS_WITH_LRO) { 2392 ptr->pkts = MLX5E_DIM_MAX_RX_CQ_MODERATION_PKTS_WITH_LRO; 2393 } 2394 } 2395 2396 static void 2397 mlx5e_build_rx_cq_param(struct mlx5e_priv *priv, 2398 struct mlx5e_cq_param *param) 2399 { 2400 struct net_dim_cq_moder curr; 2401 void *cqc = param->cqc; 2402 2403 /* 2404 * We use MLX5_CQE_FORMAT_HASH because the RX hash mini CQE 2405 * format is more beneficial for FreeBSD use case. 2406 * 2407 * Adding support for MLX5_CQE_FORMAT_CSUM will require changes 2408 * in mlx5e_decompress_cqe. 2409 */ 2410 if (priv->params.cqe_zipping_en) { 2411 MLX5_SET(cqc, cqc, mini_cqe_res_format, MLX5_CQE_FORMAT_HASH); 2412 MLX5_SET(cqc, cqc, cqe_compression_en, 1); 2413 } 2414 2415 MLX5_SET(cqc, cqc, log_cq_size, priv->params.log_rq_size); 2416 2417 switch (priv->params.rx_cq_moderation_mode) { 2418 case 0: 2419 MLX5_SET(cqc, cqc, cq_period, priv->params.rx_cq_moderation_usec); 2420 MLX5_SET(cqc, cqc, cq_max_count, priv->params.rx_cq_moderation_pkts); 2421 MLX5_SET(cqc, cqc, cq_period_mode, MLX5_CQ_PERIOD_MODE_START_FROM_EQE); 2422 break; 2423 case 1: 2424 MLX5_SET(cqc, cqc, cq_period, priv->params.rx_cq_moderation_usec); 2425 MLX5_SET(cqc, cqc, cq_max_count, priv->params.rx_cq_moderation_pkts); 2426 if (MLX5_CAP_GEN(priv->mdev, cq_period_start_from_cqe)) 2427 MLX5_SET(cqc, cqc, cq_period_mode, MLX5_CQ_PERIOD_MODE_START_FROM_CQE); 2428 else 2429 MLX5_SET(cqc, cqc, cq_period_mode, MLX5_CQ_PERIOD_MODE_START_FROM_EQE); 2430 break; 2431 case 2: 2432 mlx5e_get_default_profile(priv, NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE, &curr); 2433 MLX5_SET(cqc, cqc, cq_period, curr.usec); 2434 MLX5_SET(cqc, cqc, cq_max_count, curr.pkts); 2435 MLX5_SET(cqc, cqc, cq_period_mode, MLX5_CQ_PERIOD_MODE_START_FROM_EQE); 2436 break; 2437 case 3: 2438 mlx5e_get_default_profile(priv, NET_DIM_CQ_PERIOD_MODE_START_FROM_CQE, &curr); 2439 MLX5_SET(cqc, cqc, cq_period, curr.usec); 2440 MLX5_SET(cqc, cqc, cq_max_count, curr.pkts); 2441 if (MLX5_CAP_GEN(priv->mdev, cq_period_start_from_cqe)) 2442 MLX5_SET(cqc, cqc, cq_period_mode, MLX5_CQ_PERIOD_MODE_START_FROM_CQE); 2443 else 2444 MLX5_SET(cqc, cqc, cq_period_mode, MLX5_CQ_PERIOD_MODE_START_FROM_EQE); 2445 break; 2446 default: 2447 break; 2448 } 2449 2450 mlx5e_dim_build_cq_param(priv, param); 2451 2452 mlx5e_build_common_cq_param(priv, param); 2453 } 2454 2455 static void 2456 mlx5e_build_tx_cq_param(struct mlx5e_priv *priv, 2457 struct mlx5e_cq_param *param) 2458 { 2459 void *cqc = param->cqc; 2460 2461 MLX5_SET(cqc, cqc, log_cq_size, priv->params.log_sq_size); 2462 MLX5_SET(cqc, cqc, cq_period, priv->params.tx_cq_moderation_usec); 2463 MLX5_SET(cqc, cqc, cq_max_count, priv->params.tx_cq_moderation_pkts); 2464 2465 switch (priv->params.tx_cq_moderation_mode) { 2466 case 0: 2467 MLX5_SET(cqc, cqc, cq_period_mode, MLX5_CQ_PERIOD_MODE_START_FROM_EQE); 2468 break; 2469 default: 2470 if (MLX5_CAP_GEN(priv->mdev, cq_period_start_from_cqe)) 2471 MLX5_SET(cqc, cqc, cq_period_mode, MLX5_CQ_PERIOD_MODE_START_FROM_CQE); 2472 else 2473 MLX5_SET(cqc, cqc, cq_period_mode, MLX5_CQ_PERIOD_MODE_START_FROM_EQE); 2474 break; 2475 } 2476 2477 mlx5e_build_common_cq_param(priv, param); 2478 } 2479 2480 static void 2481 mlx5e_build_channel_param(struct mlx5e_priv *priv, 2482 struct mlx5e_channel_param *cparam) 2483 { 2484 memset(cparam, 0, sizeof(*cparam)); 2485 2486 mlx5e_build_rq_param(priv, &cparam->rq); 2487 mlx5e_build_sq_param(priv, &cparam->sq); 2488 mlx5e_build_rx_cq_param(priv, &cparam->rx_cq); 2489 mlx5e_build_tx_cq_param(priv, &cparam->tx_cq); 2490 } 2491 2492 static int 2493 mlx5e_open_channels(struct mlx5e_priv *priv) 2494 { 2495 struct mlx5e_channel_param *cparam; 2496 int err; 2497 int i; 2498 2499 cparam = malloc(sizeof(*cparam), M_MLX5EN, M_WAITOK); 2500 2501 mlx5e_build_channel_param(priv, cparam); 2502 for (i = 0; i < priv->params.num_channels; i++) { 2503 err = mlx5e_open_channel(priv, cparam, &priv->channel[i]); 2504 if (err) 2505 goto err_close_channels; 2506 2507 /* Bind interrupt vectors, if any. */ 2508 if (priv->params_ethtool.irq_cpu_base > -1) { 2509 cpuset_t cpuset; 2510 int cpu; 2511 int irq; 2512 int eqn; 2513 int nirq; 2514 2515 err = mlx5_vector2eqn(priv->mdev, i, 2516 &eqn, &nirq); 2517 2518 /* error here is non-fatal */ 2519 if (err != 0) 2520 continue; 2521 2522 irq = priv->mdev->priv.msix_arr[nirq].vector; 2523 cpu = (unsigned)(priv->params_ethtool.irq_cpu_base + 2524 i * priv->params_ethtool.irq_cpu_stride) % (unsigned)mp_ncpus; 2525 2526 CPU_ZERO(&cpuset); 2527 CPU_SET(cpu, &cpuset); 2528 intr_setaffinity(irq, CPU_WHICH_INTRHANDLER, &cpuset); 2529 } 2530 } 2531 free(cparam, M_MLX5EN); 2532 return (0); 2533 2534 err_close_channels: 2535 while (i--) { 2536 mlx5e_close_channel(&priv->channel[i]); 2537 mlx5e_close_channel_wait(&priv->channel[i]); 2538 } 2539 free(cparam, M_MLX5EN); 2540 return (err); 2541 } 2542 2543 static void 2544 mlx5e_close_channels(struct mlx5e_priv *priv) 2545 { 2546 int i; 2547 2548 for (i = 0; i < priv->params.num_channels; i++) 2549 mlx5e_close_channel(&priv->channel[i]); 2550 for (i = 0; i < priv->params.num_channels; i++) 2551 mlx5e_close_channel_wait(&priv->channel[i]); 2552 } 2553 2554 static int 2555 mlx5e_refresh_sq_params(struct mlx5e_priv *priv, struct mlx5e_sq *sq) 2556 { 2557 2558 if (MLX5_CAP_GEN(priv->mdev, cq_period_mode_modify)) { 2559 uint8_t cq_mode; 2560 2561 switch (priv->params.tx_cq_moderation_mode) { 2562 case 0: 2563 case 2: 2564 cq_mode = MLX5_CQ_PERIOD_MODE_START_FROM_EQE; 2565 break; 2566 default: 2567 cq_mode = MLX5_CQ_PERIOD_MODE_START_FROM_CQE; 2568 break; 2569 } 2570 2571 return (mlx5_core_modify_cq_moderation_mode(priv->mdev, &sq->cq.mcq, 2572 priv->params.tx_cq_moderation_usec, 2573 priv->params.tx_cq_moderation_pkts, 2574 cq_mode)); 2575 } 2576 2577 return (mlx5_core_modify_cq_moderation(priv->mdev, &sq->cq.mcq, 2578 priv->params.tx_cq_moderation_usec, 2579 priv->params.tx_cq_moderation_pkts)); 2580 } 2581 2582 static int 2583 mlx5e_refresh_rq_params(struct mlx5e_priv *priv, struct mlx5e_rq *rq) 2584 { 2585 2586 if (MLX5_CAP_GEN(priv->mdev, cq_period_mode_modify)) { 2587 uint8_t cq_mode; 2588 uint8_t dim_mode; 2589 int retval; 2590 2591 switch (priv->params.rx_cq_moderation_mode) { 2592 case 0: 2593 case 2: 2594 cq_mode = MLX5_CQ_PERIOD_MODE_START_FROM_EQE; 2595 dim_mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE; 2596 break; 2597 default: 2598 cq_mode = MLX5_CQ_PERIOD_MODE_START_FROM_CQE; 2599 dim_mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_CQE; 2600 break; 2601 } 2602 2603 /* tear down dynamic interrupt moderation */ 2604 mtx_lock(&rq->mtx); 2605 rq->dim.mode = NET_DIM_CQ_PERIOD_MODE_DISABLED; 2606 mtx_unlock(&rq->mtx); 2607 2608 /* wait for dynamic interrupt moderation work task, if any */ 2609 cancel_work_sync(&rq->dim.work); 2610 2611 if (priv->params.rx_cq_moderation_mode >= 2) { 2612 struct net_dim_cq_moder curr; 2613 2614 mlx5e_get_default_profile(priv, dim_mode, &curr); 2615 2616 retval = mlx5_core_modify_cq_moderation_mode(priv->mdev, &rq->cq.mcq, 2617 curr.usec, curr.pkts, cq_mode); 2618 2619 /* set dynamic interrupt moderation mode and zero defaults */ 2620 mtx_lock(&rq->mtx); 2621 rq->dim.mode = dim_mode; 2622 rq->dim.state = 0; 2623 rq->dim.profile_ix = MLX5E_DIM_DEFAULT_PROFILE; 2624 mtx_unlock(&rq->mtx); 2625 } else { 2626 retval = mlx5_core_modify_cq_moderation_mode(priv->mdev, &rq->cq.mcq, 2627 priv->params.rx_cq_moderation_usec, 2628 priv->params.rx_cq_moderation_pkts, 2629 cq_mode); 2630 } 2631 return (retval); 2632 } 2633 2634 return (mlx5_core_modify_cq_moderation(priv->mdev, &rq->cq.mcq, 2635 priv->params.rx_cq_moderation_usec, 2636 priv->params.rx_cq_moderation_pkts)); 2637 } 2638 2639 static int 2640 mlx5e_refresh_channel_params_sub(struct mlx5e_priv *priv, struct mlx5e_channel *c) 2641 { 2642 int err; 2643 int i; 2644 2645 err = mlx5e_refresh_rq_params(priv, &c->rq); 2646 if (err) 2647 goto done; 2648 2649 for (i = 0; i != priv->num_tc; i++) { 2650 err = mlx5e_refresh_sq_params(priv, &c->sq[i]); 2651 if (err) 2652 goto done; 2653 } 2654 done: 2655 return (err); 2656 } 2657 2658 int 2659 mlx5e_refresh_channel_params(struct mlx5e_priv *priv) 2660 { 2661 int i; 2662 2663 /* check if channels are closed */ 2664 if (test_bit(MLX5E_STATE_OPENED, &priv->state) == 0) 2665 return (EINVAL); 2666 2667 for (i = 0; i < priv->params.num_channels; i++) { 2668 int err; 2669 2670 err = mlx5e_refresh_channel_params_sub(priv, &priv->channel[i]); 2671 if (err) 2672 return (err); 2673 } 2674 return (0); 2675 } 2676 2677 static int 2678 mlx5e_open_tis(struct mlx5e_priv *priv, int tc) 2679 { 2680 struct mlx5_core_dev *mdev = priv->mdev; 2681 u32 in[MLX5_ST_SZ_DW(create_tis_in)]; 2682 void *tisc = MLX5_ADDR_OF(create_tis_in, in, ctx); 2683 2684 memset(in, 0, sizeof(in)); 2685 2686 MLX5_SET(tisc, tisc, prio, tc); 2687 MLX5_SET(tisc, tisc, transport_domain, priv->tdn); 2688 2689 return (mlx5_core_create_tis(mdev, in, sizeof(in), &priv->tisn[tc])); 2690 } 2691 2692 static void 2693 mlx5e_close_tis(struct mlx5e_priv *priv, int tc) 2694 { 2695 mlx5_core_destroy_tis(priv->mdev, priv->tisn[tc], 0); 2696 } 2697 2698 static int 2699 mlx5e_open_tises(struct mlx5e_priv *priv) 2700 { 2701 int num_tc = priv->num_tc; 2702 int err; 2703 int tc; 2704 2705 for (tc = 0; tc < num_tc; tc++) { 2706 err = mlx5e_open_tis(priv, tc); 2707 if (err) 2708 goto err_close_tises; 2709 } 2710 2711 return (0); 2712 2713 err_close_tises: 2714 for (tc--; tc >= 0; tc--) 2715 mlx5e_close_tis(priv, tc); 2716 2717 return (err); 2718 } 2719 2720 static void 2721 mlx5e_close_tises(struct mlx5e_priv *priv) 2722 { 2723 int num_tc = priv->num_tc; 2724 int tc; 2725 2726 for (tc = 0; tc < num_tc; tc++) 2727 mlx5e_close_tis(priv, tc); 2728 } 2729 2730 static int 2731 mlx5e_open_default_rqt(struct mlx5e_priv *priv, u32 *prqtn, int sz) 2732 { 2733 u32 *in; 2734 void *rqtc; 2735 int inlen; 2736 int err; 2737 int i; 2738 2739 inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + sizeof(u32) * sz; 2740 in = mlx5_vzalloc(inlen); 2741 if (in == NULL) 2742 return (-ENOMEM); 2743 rqtc = MLX5_ADDR_OF(create_rqt_in, in, rqt_context); 2744 2745 MLX5_SET(rqtc, rqtc, rqt_actual_size, sz); 2746 MLX5_SET(rqtc, rqtc, rqt_max_size, sz); 2747 2748 for (i = 0; i != sz; i++) 2749 MLX5_SET(rqtc, rqtc, rq_num[i], priv->drop_rq.rqn); 2750 2751 err = mlx5_core_create_rqt(priv->mdev, in, inlen, prqtn); 2752 kvfree(in); 2753 2754 return (err); 2755 } 2756 2757 static int 2758 mlx5e_open_rqts(struct mlx5e_priv *priv) 2759 { 2760 int err; 2761 int i; 2762 2763 err = mlx5e_open_default_rqt(priv, &priv->rqtn, 2764 1 << priv->params.rx_hash_log_tbl_sz); 2765 if (err) 2766 goto err_default; 2767 2768 for (i = 0; i != priv->mdev->priv.eq_table.num_comp_vectors; i++) { 2769 err = mlx5e_open_default_rqt(priv, &priv->channel[i].rqtn, 1); 2770 if (err) 2771 goto err_channel; 2772 } 2773 return (0); 2774 2775 err_channel: 2776 while (i--) 2777 mlx5_core_destroy_rqt(priv->mdev, priv->channel[i].rqtn, 0); 2778 2779 mlx5_core_destroy_rqt(priv->mdev, priv->rqtn, 0); 2780 2781 err_default: 2782 return (err); 2783 } 2784 2785 static void 2786 mlx5e_close_rqts(struct mlx5e_priv *priv) 2787 { 2788 int i; 2789 2790 for (i = 0; i != priv->mdev->priv.eq_table.num_comp_vectors; i++) 2791 mlx5_core_destroy_rqt(priv->mdev, priv->channel[i].rqtn, 0); 2792 2793 mlx5_core_destroy_rqt(priv->mdev, priv->rqtn, 0); 2794 } 2795 2796 static int 2797 mlx5e_activate_rqt(struct mlx5e_priv *priv) 2798 { 2799 u32 *in; 2800 void *rqtc; 2801 int inlen; 2802 int err; 2803 int sz; 2804 int i; 2805 2806 sz = 1 << priv->params.rx_hash_log_tbl_sz; 2807 2808 inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) + sizeof(u32) * sz; 2809 in = mlx5_vzalloc(inlen); 2810 if (in == NULL) 2811 return (-ENOMEM); 2812 2813 rqtc = MLX5_ADDR_OF(modify_rqt_in, in, ctx); 2814 2815 MLX5_SET(rqtc, rqtc, rqt_actual_size, sz); 2816 MLX5_SET(modify_rqt_in, in, bitmask.rqn_list, 1); 2817 2818 for (i = 0; i != sz; i++) { 2819 int ix; 2820 #ifdef RSS 2821 ix = rss_get_indirection_to_bucket(i); 2822 #else 2823 ix = i; 2824 #endif 2825 /* ensure we don't overflow */ 2826 ix %= priv->params.num_channels; 2827 2828 /* apply receive side scaling stride, if any */ 2829 ix -= ix % (int)priv->params.channels_rsss; 2830 2831 MLX5_SET(rqtc, rqtc, rq_num[i], priv->channel[ix].rq.rqn); 2832 } 2833 2834 err = mlx5_core_modify_rqt(priv->mdev, priv->rqtn, in, inlen); 2835 if (err) 2836 goto err_modify; 2837 2838 inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) + sizeof(u32); 2839 2840 MLX5_SET(rqtc, rqtc, rqt_actual_size, 1); 2841 2842 for (i = 0; i != priv->mdev->priv.eq_table.num_comp_vectors; i++) { 2843 int ix; 2844 #ifdef RSS 2845 ix = rss_get_indirection_to_bucket(i); 2846 #else 2847 ix = i; 2848 #endif 2849 /* ensure we don't overflow */ 2850 ix %= priv->params.num_channels; 2851 2852 /* apply receive side scaling stride, if any */ 2853 ix -= ix % (int)priv->params.channels_rsss; 2854 2855 MLX5_SET(rqtc, rqtc, rq_num[0], priv->channel[ix].rq.rqn); 2856 2857 err = mlx5_core_modify_rqt(priv->mdev, priv->channel[i].rqtn, in, inlen); 2858 if (err) 2859 goto err_modify; 2860 } 2861 2862 err_modify: 2863 kvfree(in); 2864 return (err); 2865 } 2866 2867 static int 2868 mlx5e_deactivate_rqt(struct mlx5e_priv *priv) 2869 { 2870 u32 *in; 2871 void *rqtc; 2872 int inlen; 2873 int err; 2874 int sz; 2875 int i; 2876 2877 sz = 1 << priv->params.rx_hash_log_tbl_sz; 2878 2879 inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) + sizeof(u32) * sz; 2880 in = mlx5_vzalloc(inlen); 2881 if (in == NULL) 2882 return (-ENOMEM); 2883 2884 rqtc = MLX5_ADDR_OF(modify_rqt_in, in, ctx); 2885 2886 MLX5_SET(rqtc, rqtc, rqt_actual_size, sz); 2887 MLX5_SET(modify_rqt_in, in, bitmask.rqn_list, 1); 2888 2889 for (i = 0; i != sz; i++) 2890 MLX5_SET(rqtc, rqtc, rq_num[i], priv->drop_rq.rqn); 2891 2892 err = mlx5_core_modify_rqt(priv->mdev, priv->rqtn, in, inlen); 2893 if (err) 2894 goto err_modify; 2895 2896 inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) + sizeof(u32); 2897 2898 MLX5_SET(rqtc, rqtc, rqt_actual_size, 1); 2899 2900 for (i = 0; i != priv->mdev->priv.eq_table.num_comp_vectors; i++) { 2901 MLX5_SET(rqtc, rqtc, rq_num[0], priv->drop_rq.rqn); 2902 2903 err = mlx5_core_modify_rqt(priv->mdev, priv->channel[i].rqtn, in, inlen); 2904 if (err) 2905 goto err_modify; 2906 } 2907 2908 err_modify: 2909 kvfree(in); 2910 return (err); 2911 } 2912 2913 #define MLX5E_RSS_KEY_SIZE (10 * 4) /* bytes */ 2914 2915 static void 2916 mlx5e_get_rss_key(void *key_ptr) 2917 { 2918 rss_getkey(key_ptr); 2919 } 2920 2921 static void 2922 mlx5e_hw_lro_set_tir_ctx_lro_max_msg_sz(struct mlx5e_priv *priv, u32 *tirc) 2923 { 2924 MLX5_SET(tirc, tirc, lro_max_msg_sz, (priv->params.lro_wqe_sz >> 8) - 2925 (MLX5_CAP_ETH(priv->mdev, lro_max_msg_sz_mode) == 0 ? 1 : 0)); 2926 } 2927 2928 static void 2929 mlx5e_hw_lro_set_tir_ctx(struct mlx5e_priv *priv, u32 *tirc) 2930 { 2931 MLX5_SET(tirc, tirc, lro_enable_mask, 2932 MLX5_TIRC_LRO_ENABLE_MASK_IPV4_LRO | 2933 MLX5_TIRC_LRO_ENABLE_MASK_IPV6_LRO); 2934 /* TODO: add the option to choose timer value dynamically */ 2935 MLX5_SET(tirc, tirc, lro_timeout_period_usecs, 2936 MLX5_CAP_ETH(priv->mdev, lro_timer_supported_periods[2])); 2937 mlx5e_hw_lro_set_tir_ctx_lro_max_msg_sz(priv, tirc); 2938 } 2939 2940 static int 2941 mlx5e_hw_lro_update_tir(struct mlx5e_priv *priv, int tt, bool inner_vxlan) 2942 { 2943 struct mlx5_core_dev *mdev = priv->mdev; 2944 u32 *in; 2945 void *tirc; 2946 int inlen; 2947 int err; 2948 2949 inlen = MLX5_ST_SZ_BYTES(modify_tir_in); 2950 in = mlx5_vzalloc(inlen); 2951 if (in == NULL) 2952 return (-ENOMEM); 2953 tirc = MLX5_ADDR_OF(modify_tir_in, in, tir_context); 2954 2955 /* fill the command part */ 2956 MLX5_SET(modify_tir_in, in, tirn, inner_vxlan ? 2957 priv->tirn_inner_vxlan[tt] : priv->tirn[tt]); 2958 MLX5_SET64(modify_tir_in, in, modify_bitmask, 2959 (1 << MLX5_MODIFY_TIR_BITMASK_LRO)); 2960 2961 /* fill the context */ 2962 if (priv->params.hw_lro_en) 2963 mlx5e_hw_lro_set_tir_ctx(priv, tirc); 2964 2965 err = mlx5_core_modify_tir(mdev, in, inlen); 2966 2967 kvfree(in); 2968 return (err); 2969 } 2970 2971 int 2972 mlx5e_hw_lro_update_tirs(struct mlx5e_priv *priv) 2973 { 2974 int err, err1, i; 2975 2976 err = 0; 2977 for (i = 0; i != 2 * MLX5E_NUM_TT; i++) { 2978 err1 = mlx5e_hw_lro_update_tir(priv, i / 2, (i % 2) ? true : 2979 false); 2980 if (err1 != 0 && err == 0) 2981 err = err1; 2982 } 2983 return (-err); 2984 } 2985 2986 static void 2987 mlx5e_build_tir_ctx(struct mlx5e_priv *priv, u32 * tirc, int tt, bool inner_vxlan) 2988 { 2989 void *hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_outer); 2990 void *hfsi = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_inner); 2991 void *hfs = inner_vxlan ? hfsi : hfso; 2992 __be32 *hkey; 2993 2994 MLX5_SET(tirc, tirc, transport_domain, priv->tdn); 2995 2996 #define MLX5_HASH_IP (MLX5_HASH_FIELD_SEL_SRC_IP |\ 2997 MLX5_HASH_FIELD_SEL_DST_IP) 2998 2999 #define MLX5_HASH_ALL (MLX5_HASH_FIELD_SEL_SRC_IP |\ 3000 MLX5_HASH_FIELD_SEL_DST_IP |\ 3001 MLX5_HASH_FIELD_SEL_L4_SPORT |\ 3002 MLX5_HASH_FIELD_SEL_L4_DPORT) 3003 3004 #define MLX5_HASH_IP_IPSEC_SPI (MLX5_HASH_FIELD_SEL_SRC_IP |\ 3005 MLX5_HASH_FIELD_SEL_DST_IP |\ 3006 MLX5_HASH_FIELD_SEL_IPSEC_SPI) 3007 3008 if (priv->params.hw_lro_en) 3009 mlx5e_hw_lro_set_tir_ctx(priv, tirc); 3010 3011 if (inner_vxlan) 3012 MLX5_SET(tirc, tirc, tunneled_offload_en, 1); 3013 3014 /* 3015 * All packets must go through the indirection table, RQT, 3016 * because it is not possible to modify the RQN of the TIR 3017 * for direct dispatchment after it is created, typically 3018 * when the link goes up and down. 3019 */ 3020 MLX5_SET(tirc, tirc, disp_type, 3021 MLX5_TIRC_DISP_TYPE_INDIRECT); 3022 MLX5_SET(tirc, tirc, indirect_table, 3023 priv->rqtn); 3024 MLX5_SET(tirc, tirc, rx_hash_fn, 3025 MLX5_TIRC_RX_HASH_FN_HASH_TOEPLITZ); 3026 hkey = (__be32 *) MLX5_ADDR_OF(tirc, tirc, rx_hash_toeplitz_key); 3027 3028 CTASSERT(MLX5_FLD_SZ_BYTES(tirc, rx_hash_toeplitz_key) >= 3029 MLX5E_RSS_KEY_SIZE); 3030 3031 /* 3032 * The FreeBSD RSS implementation does currently not 3033 * support symmetric Toeplitz hashes: 3034 */ 3035 MLX5_SET(tirc, tirc, rx_hash_symmetric, 0); 3036 mlx5e_get_rss_key(hkey); 3037 3038 switch (tt) { 3039 case MLX5E_TT_IPV4_TCP: 3040 MLX5_SET(rx_hash_field_select, hfs, l3_prot_type, 3041 MLX5_L3_PROT_TYPE_IPV4); 3042 MLX5_SET(rx_hash_field_select, hfs, l4_prot_type, 3043 MLX5_L4_PROT_TYPE_TCP); 3044 if (!(rss_gethashconfig() & RSS_HASHTYPE_RSS_TCP_IPV4)) { 3045 MLX5_SET(rx_hash_field_select, hfs, selected_fields, 3046 MLX5_HASH_IP); 3047 } else 3048 MLX5_SET(rx_hash_field_select, hfs, selected_fields, 3049 MLX5_HASH_ALL); 3050 break; 3051 3052 case MLX5E_TT_IPV6_TCP: 3053 MLX5_SET(rx_hash_field_select, hfs, l3_prot_type, 3054 MLX5_L3_PROT_TYPE_IPV6); 3055 MLX5_SET(rx_hash_field_select, hfs, l4_prot_type, 3056 MLX5_L4_PROT_TYPE_TCP); 3057 if (!(rss_gethashconfig() & RSS_HASHTYPE_RSS_TCP_IPV6)) { 3058 MLX5_SET(rx_hash_field_select, hfs, selected_fields, 3059 MLX5_HASH_IP); 3060 } else 3061 MLX5_SET(rx_hash_field_select, hfs, selected_fields, 3062 MLX5_HASH_ALL); 3063 break; 3064 3065 case MLX5E_TT_IPV4_UDP: 3066 MLX5_SET(rx_hash_field_select, hfs, l3_prot_type, 3067 MLX5_L3_PROT_TYPE_IPV4); 3068 MLX5_SET(rx_hash_field_select, hfs, l4_prot_type, 3069 MLX5_L4_PROT_TYPE_UDP); 3070 if (!(rss_gethashconfig() & RSS_HASHTYPE_RSS_UDP_IPV4)) { 3071 MLX5_SET(rx_hash_field_select, hfs, selected_fields, 3072 MLX5_HASH_IP); 3073 } else 3074 MLX5_SET(rx_hash_field_select, hfs, selected_fields, 3075 MLX5_HASH_ALL); 3076 break; 3077 3078 case MLX5E_TT_IPV6_UDP: 3079 MLX5_SET(rx_hash_field_select, hfs, l3_prot_type, 3080 MLX5_L3_PROT_TYPE_IPV6); 3081 MLX5_SET(rx_hash_field_select, hfs, l4_prot_type, 3082 MLX5_L4_PROT_TYPE_UDP); 3083 if (!(rss_gethashconfig() & RSS_HASHTYPE_RSS_UDP_IPV6)) { 3084 MLX5_SET(rx_hash_field_select, hfs, selected_fields, 3085 MLX5_HASH_IP); 3086 } else 3087 MLX5_SET(rx_hash_field_select, hfs, selected_fields, 3088 MLX5_HASH_ALL); 3089 break; 3090 3091 case MLX5E_TT_IPV4_IPSEC_AH: 3092 MLX5_SET(rx_hash_field_select, hfs, l3_prot_type, 3093 MLX5_L3_PROT_TYPE_IPV4); 3094 MLX5_SET(rx_hash_field_select, hfs, selected_fields, 3095 MLX5_HASH_IP_IPSEC_SPI); 3096 break; 3097 3098 case MLX5E_TT_IPV6_IPSEC_AH: 3099 MLX5_SET(rx_hash_field_select, hfs, l3_prot_type, 3100 MLX5_L3_PROT_TYPE_IPV6); 3101 MLX5_SET(rx_hash_field_select, hfs, selected_fields, 3102 MLX5_HASH_IP_IPSEC_SPI); 3103 break; 3104 3105 case MLX5E_TT_IPV4_IPSEC_ESP: 3106 MLX5_SET(rx_hash_field_select, hfs, l3_prot_type, 3107 MLX5_L3_PROT_TYPE_IPV4); 3108 MLX5_SET(rx_hash_field_select, hfs, selected_fields, 3109 MLX5_HASH_IP_IPSEC_SPI); 3110 break; 3111 3112 case MLX5E_TT_IPV6_IPSEC_ESP: 3113 MLX5_SET(rx_hash_field_select, hfs, l3_prot_type, 3114 MLX5_L3_PROT_TYPE_IPV6); 3115 MLX5_SET(rx_hash_field_select, hfs, selected_fields, 3116 MLX5_HASH_IP_IPSEC_SPI); 3117 break; 3118 3119 case MLX5E_TT_IPV4: 3120 MLX5_SET(rx_hash_field_select, hfs, l3_prot_type, 3121 MLX5_L3_PROT_TYPE_IPV4); 3122 MLX5_SET(rx_hash_field_select, hfs, selected_fields, 3123 MLX5_HASH_IP); 3124 break; 3125 3126 case MLX5E_TT_IPV6: 3127 MLX5_SET(rx_hash_field_select, hfs, l3_prot_type, 3128 MLX5_L3_PROT_TYPE_IPV6); 3129 MLX5_SET(rx_hash_field_select, hfs, selected_fields, 3130 MLX5_HASH_IP); 3131 break; 3132 3133 default: 3134 break; 3135 } 3136 } 3137 3138 static int 3139 mlx5e_open_tir(struct mlx5e_priv *priv, int tt, bool inner_vxlan) 3140 { 3141 struct mlx5_core_dev *mdev = priv->mdev; 3142 u32 *in; 3143 void *tirc; 3144 int inlen; 3145 int err; 3146 3147 inlen = MLX5_ST_SZ_BYTES(create_tir_in); 3148 in = mlx5_vzalloc(inlen); 3149 if (in == NULL) 3150 return (-ENOMEM); 3151 tirc = MLX5_ADDR_OF(create_tir_in, in, tir_context); 3152 3153 mlx5e_build_tir_ctx(priv, tirc, tt, inner_vxlan); 3154 3155 err = mlx5_core_create_tir(mdev, in, inlen, inner_vxlan ? 3156 &priv->tirn_inner_vxlan[tt] : &priv->tirn[tt]); 3157 3158 kvfree(in); 3159 3160 return (err); 3161 } 3162 3163 static void 3164 mlx5e_close_tir(struct mlx5e_priv *priv, int tt, bool inner_vxlan) 3165 { 3166 mlx5_core_destroy_tir(priv->mdev, inner_vxlan ? 3167 priv->tirn_inner_vxlan[tt] : priv->tirn[tt], 0); 3168 } 3169 3170 static int 3171 mlx5e_open_tirs(struct mlx5e_priv *priv) 3172 { 3173 int err; 3174 int i; 3175 3176 for (i = 0; i != 2 * MLX5E_NUM_TT; i++) { 3177 err = mlx5e_open_tir(priv, i / 2, (i % 2) ? true : false); 3178 if (err) 3179 goto err_close_tirs; 3180 } 3181 3182 return (0); 3183 3184 err_close_tirs: 3185 for (i--; i >= 0; i--) 3186 mlx5e_close_tir(priv, i / 2, (i % 2) ? true : false); 3187 3188 return (err); 3189 } 3190 3191 static void 3192 mlx5e_close_tirs(struct mlx5e_priv *priv) 3193 { 3194 int i; 3195 3196 for (i = 0; i != 2 * MLX5E_NUM_TT; i++) 3197 mlx5e_close_tir(priv, i / 2, (i % 2) ? true : false); 3198 } 3199 3200 /* 3201 * SW MTU does not include headers, 3202 * HW MTU includes all headers and checksums. 3203 */ 3204 static int 3205 mlx5e_set_dev_port_mtu(if_t ifp, int sw_mtu) 3206 { 3207 struct mlx5e_priv *priv = if_getsoftc(ifp); 3208 struct mlx5_core_dev *mdev = priv->mdev; 3209 int hw_mtu; 3210 int err; 3211 3212 hw_mtu = MLX5E_SW2HW_MTU(sw_mtu); 3213 3214 err = mlx5_set_port_mtu(mdev, hw_mtu); 3215 if (err) { 3216 mlx5_en_err(ifp, "mlx5_set_port_mtu failed setting %d, err=%d\n", 3217 sw_mtu, err); 3218 return (err); 3219 } 3220 3221 /* Update vport context MTU */ 3222 err = mlx5_set_vport_mtu(mdev, hw_mtu); 3223 if (err) { 3224 mlx5_en_err(ifp, 3225 "Failed updating vport context with MTU size, err=%d\n", 3226 err); 3227 } 3228 3229 if_setmtu(ifp, sw_mtu); 3230 3231 err = mlx5_query_vport_mtu(mdev, &hw_mtu); 3232 if (err || !hw_mtu) { 3233 /* fallback to port oper mtu */ 3234 err = mlx5_query_port_oper_mtu(mdev, &hw_mtu); 3235 } 3236 if (err) { 3237 mlx5_en_err(ifp, 3238 "Query port MTU, after setting new MTU value, failed\n"); 3239 return (err); 3240 } else if (MLX5E_HW2SW_MTU(hw_mtu) < sw_mtu) { 3241 err = -E2BIG, 3242 mlx5_en_err(ifp, 3243 "Port MTU %d is smaller than ifp mtu %d\n", 3244 hw_mtu, sw_mtu); 3245 } else if (MLX5E_HW2SW_MTU(hw_mtu) > sw_mtu) { 3246 err = -EINVAL; 3247 mlx5_en_err(ifp, 3248 "Port MTU %d is bigger than ifp mtu %d\n", 3249 hw_mtu, sw_mtu); 3250 } 3251 priv->params_ethtool.hw_mtu = hw_mtu; 3252 3253 /* compute MSB */ 3254 while (hw_mtu & (hw_mtu - 1)) 3255 hw_mtu &= (hw_mtu - 1); 3256 priv->params_ethtool.hw_mtu_msb = hw_mtu; 3257 3258 return (err); 3259 } 3260 3261 int 3262 mlx5e_open_locked(if_t ifp) 3263 { 3264 struct mlx5e_priv *priv = if_getsoftc(ifp); 3265 int err; 3266 u16 set_id; 3267 3268 /* check if already opened */ 3269 if (test_bit(MLX5E_STATE_OPENED, &priv->state) != 0) 3270 return (0); 3271 3272 #ifdef RSS 3273 if (rss_getnumbuckets() > priv->params.num_channels) { 3274 mlx5_en_info(ifp, 3275 "NOTE: There are more RSS buckets(%u) than channels(%u) available\n", 3276 rss_getnumbuckets(), priv->params.num_channels); 3277 } 3278 #endif 3279 err = mlx5e_open_tises(priv); 3280 if (err) { 3281 mlx5_en_err(ifp, "mlx5e_open_tises failed, %d\n", err); 3282 return (err); 3283 } 3284 err = mlx5_vport_alloc_q_counter(priv->mdev, 3285 MLX5_INTERFACE_PROTOCOL_ETH, &set_id); 3286 if (err) { 3287 mlx5_en_err(priv->ifp, 3288 "mlx5_vport_alloc_q_counter failed: %d\n", err); 3289 goto err_close_tises; 3290 } 3291 /* store counter set ID */ 3292 priv->counter_set_id = set_id; 3293 3294 err = mlx5e_open_channels(priv); 3295 if (err) { 3296 mlx5_en_err(ifp, 3297 "mlx5e_open_channels failed, %d\n", err); 3298 goto err_dalloc_q_counter; 3299 } 3300 err = mlx5e_activate_rqt(priv); 3301 if (err) { 3302 mlx5_en_err(ifp, "mlx5e_activate_rqt failed, %d\n", err); 3303 goto err_close_channels; 3304 } 3305 3306 set_bit(MLX5E_STATE_OPENED, &priv->state); 3307 3308 mlx5e_update_carrier(priv); 3309 3310 #ifdef KERN_TLS 3311 if ((if_getcapenable(ifp) & (IFCAP_TXTLS4 | IFCAP_TXTLS6)) != 0) 3312 mlx5e_tls_prealloc_tags(priv); 3313 #endif 3314 3315 return (0); 3316 3317 err_close_channels: 3318 mlx5e_close_channels(priv); 3319 3320 err_dalloc_q_counter: 3321 mlx5_vport_dealloc_q_counter(priv->mdev, 3322 MLX5_INTERFACE_PROTOCOL_ETH, priv->counter_set_id); 3323 3324 err_close_tises: 3325 mlx5e_close_tises(priv); 3326 3327 return (err); 3328 } 3329 3330 static void 3331 mlx5e_open(void *arg) 3332 { 3333 struct mlx5e_priv *priv = arg; 3334 3335 PRIV_LOCK(priv); 3336 if (mlx5_set_port_status(priv->mdev, MLX5_PORT_UP)) 3337 mlx5_en_err(priv->ifp, 3338 "Setting port status to up failed\n"); 3339 3340 mlx5e_open_locked(priv->ifp); 3341 if_setdrvflagbits(priv->ifp, IFF_DRV_RUNNING, 0); 3342 PRIV_UNLOCK(priv); 3343 } 3344 3345 int 3346 mlx5e_close_locked(if_t ifp) 3347 { 3348 struct mlx5e_priv *priv = if_getsoftc(ifp); 3349 3350 /* check if already closed */ 3351 if (test_bit(MLX5E_STATE_OPENED, &priv->state) == 0) 3352 return (0); 3353 3354 clear_bit(MLX5E_STATE_OPENED, &priv->state); 3355 3356 if_link_state_change(priv->ifp, LINK_STATE_DOWN); 3357 3358 mlx5e_deactivate_rqt(priv); 3359 mlx5e_close_channels(priv); 3360 mlx5_vport_dealloc_q_counter(priv->mdev, 3361 MLX5_INTERFACE_PROTOCOL_ETH, priv->counter_set_id); 3362 mlx5e_close_tises(priv); 3363 3364 return (0); 3365 } 3366 3367 static uint64_t 3368 mlx5e_get_counter(if_t ifp, ift_counter cnt) 3369 { 3370 struct mlx5e_priv *priv = if_getsoftc(ifp); 3371 u64 retval; 3372 3373 /* PRIV_LOCK(priv); XXX not allowed */ 3374 switch (cnt) { 3375 case IFCOUNTER_IPACKETS: 3376 retval = priv->stats.vport.rx_packets; 3377 break; 3378 case IFCOUNTER_IERRORS: 3379 retval = priv->stats.pport.in_range_len_errors + 3380 priv->stats.pport.out_of_range_len + 3381 priv->stats.pport.too_long_errors + 3382 priv->stats.pport.check_seq_err + 3383 priv->stats.pport.alignment_err; 3384 break; 3385 case IFCOUNTER_IQDROPS: 3386 retval = priv->stats.vport.rx_out_of_buffer; 3387 break; 3388 case IFCOUNTER_OPACKETS: 3389 retval = priv->stats.vport.tx_packets; 3390 break; 3391 case IFCOUNTER_OERRORS: 3392 retval = priv->stats.port_stats_debug.out_discards; 3393 break; 3394 case IFCOUNTER_IBYTES: 3395 retval = priv->stats.vport.rx_bytes; 3396 break; 3397 case IFCOUNTER_OBYTES: 3398 retval = priv->stats.vport.tx_bytes; 3399 break; 3400 case IFCOUNTER_IMCASTS: 3401 retval = priv->stats.vport.rx_multicast_packets; 3402 break; 3403 case IFCOUNTER_OMCASTS: 3404 retval = priv->stats.vport.tx_multicast_packets; 3405 break; 3406 case IFCOUNTER_OQDROPS: 3407 retval = priv->stats.vport.tx_queue_dropped; 3408 break; 3409 case IFCOUNTER_COLLISIONS: 3410 retval = priv->stats.pport.collisions; 3411 break; 3412 default: 3413 retval = if_get_counter_default(ifp, cnt); 3414 break; 3415 } 3416 /* PRIV_UNLOCK(priv); XXX not allowed */ 3417 return (retval); 3418 } 3419 3420 static void 3421 mlx5e_set_rx_mode(if_t ifp) 3422 { 3423 struct mlx5e_priv *priv = if_getsoftc(ifp); 3424 3425 queue_work(priv->wq, &priv->set_rx_mode_work); 3426 } 3427 3428 static bool 3429 mlx5e_is_ipsec_capable(struct mlx5_core_dev *mdev) 3430 { 3431 #ifdef IPSEC_OFFLOAD 3432 if ((mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_PACKET_OFFLOAD) != 0) 3433 return (true); 3434 #endif 3435 return (false); 3436 } 3437 3438 static bool 3439 mlx5e_is_ratelimit_capable(struct mlx5_core_dev *mdev) 3440 { 3441 #ifdef RATELIMIT 3442 if (MLX5_CAP_GEN(mdev, qos) && 3443 MLX5_CAP_QOS(mdev, packet_pacing)) 3444 return (true); 3445 #endif 3446 return (false); 3447 } 3448 3449 static bool 3450 mlx5e_is_tlstx_capable(struct mlx5_core_dev *mdev) 3451 { 3452 #ifdef KERN_TLS 3453 if (MLX5_CAP_GEN(mdev, tls_tx) != 0 && 3454 MLX5_CAP_GEN(mdev, log_max_dek) != 0) 3455 return (true); 3456 #endif 3457 return (false); 3458 } 3459 3460 static bool 3461 mlx5e_is_tlsrx_capable(struct mlx5_core_dev *mdev) 3462 { 3463 #ifdef KERN_TLS 3464 if (MLX5_CAP_GEN(mdev, tls_rx) != 0 && 3465 MLX5_CAP_GEN(mdev, log_max_dek) != 0 && 3466 MLX5_CAP_FLOWTABLE_NIC_RX(mdev, 3467 ft_field_support.outer_ip_version) != 0) 3468 return (true); 3469 #endif 3470 return (false); 3471 } 3472 3473 static int 3474 mlx5e_ioctl(if_t ifp, u_long command, caddr_t data) 3475 { 3476 struct mlx5e_priv *priv; 3477 struct ifreq *ifr; 3478 struct ifdownreason *ifdr; 3479 struct ifi2creq i2c; 3480 struct ifrsskey *ifrk; 3481 struct ifrsshash *ifrh; 3482 struct siocsifcapnv_driver_data *drv_ioctl_data, drv_ioctl_data_d; 3483 int error = 0; 3484 int mask; 3485 int size_read = 0; 3486 int module_status; 3487 int module_num; 3488 int max_mtu; 3489 uint8_t read_addr; 3490 3491 priv = if_getsoftc(ifp); 3492 3493 /* check if detaching */ 3494 if (priv == NULL || priv->gone != 0) 3495 return (ENXIO); 3496 3497 switch (command) { 3498 case SIOCSIFMTU: 3499 ifr = (struct ifreq *)data; 3500 3501 PRIV_LOCK(priv); 3502 mlx5_query_port_max_mtu(priv->mdev, &max_mtu); 3503 3504 if (ifr->ifr_mtu >= MLX5E_MTU_MIN && 3505 ifr->ifr_mtu <= MIN(MLX5E_MTU_MAX, max_mtu)) { 3506 int was_opened; 3507 3508 was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state); 3509 if (was_opened) 3510 mlx5e_close_locked(ifp); 3511 3512 /* set new MTU */ 3513 mlx5e_set_dev_port_mtu(ifp, ifr->ifr_mtu); 3514 3515 if (was_opened) 3516 mlx5e_open_locked(ifp); 3517 } else { 3518 error = EINVAL; 3519 mlx5_en_err(ifp, 3520 "Invalid MTU value. Min val: %d, Max val: %d\n", 3521 MLX5E_MTU_MIN, MIN(MLX5E_MTU_MAX, max_mtu)); 3522 } 3523 PRIV_UNLOCK(priv); 3524 break; 3525 case SIOCSIFFLAGS: 3526 if ((if_getflags(ifp) & IFF_UP) && 3527 (if_getdrvflags(ifp) & IFF_DRV_RUNNING)) { 3528 mlx5e_set_rx_mode(ifp); 3529 break; 3530 } 3531 PRIV_LOCK(priv); 3532 if (if_getflags(ifp) & IFF_UP) { 3533 if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0) { 3534 if (test_bit(MLX5E_STATE_OPENED, &priv->state) == 0) 3535 mlx5e_open_locked(ifp); 3536 if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0); 3537 mlx5_set_port_status(priv->mdev, MLX5_PORT_UP); 3538 } 3539 } else { 3540 if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { 3541 mlx5_set_port_status(priv->mdev, 3542 MLX5_PORT_DOWN); 3543 if (test_bit(MLX5E_STATE_OPENED, &priv->state) != 0) 3544 mlx5e_close_locked(ifp); 3545 mlx5e_update_carrier(priv); 3546 if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING); 3547 } 3548 } 3549 PRIV_UNLOCK(priv); 3550 break; 3551 case SIOCADDMULTI: 3552 case SIOCDELMULTI: 3553 mlx5e_set_rx_mode(ifp); 3554 break; 3555 case SIOCSIFMEDIA: 3556 case SIOCGIFMEDIA: 3557 case SIOCGIFXMEDIA: 3558 ifr = (struct ifreq *)data; 3559 error = ifmedia_ioctl(ifp, ifr, &priv->media, command); 3560 break; 3561 case SIOCGIFCAPNV: 3562 error = 0; 3563 break; 3564 case SIOCSIFCAP: 3565 ifr = (struct ifreq *)data; 3566 drv_ioctl_data = &drv_ioctl_data_d; 3567 drv_ioctl_data->reqcap = ifr->ifr_reqcap; 3568 PRIV_LOCK(priv); 3569 drv_ioctl_data->reqcap2 = if_getcapenable2(ifp); 3570 drv_ioctl_data->nvcap = NULL; 3571 goto siocsifcap_driver; 3572 case SIOCSIFCAPNV: 3573 drv_ioctl_data = (struct siocsifcapnv_driver_data *)data; 3574 PRIV_LOCK(priv); 3575 siocsifcap_driver: 3576 if (!mlx5e_is_tlstx_capable(priv->mdev)) { 3577 drv_ioctl_data->reqcap &= ~(IFCAP_TXTLS4 | 3578 IFCAP_TXTLS6); 3579 } 3580 if (!mlx5e_is_tlsrx_capable(priv->mdev)) { 3581 drv_ioctl_data->reqcap2 &= ~( 3582 IFCAP2_BIT(IFCAP2_RXTLS4) | 3583 IFCAP2_BIT(IFCAP2_RXTLS6)); 3584 } 3585 if (!mlx5e_is_ipsec_capable(priv->mdev)) { 3586 drv_ioctl_data->reqcap2 &= 3587 ~IFCAP2_BIT(IFCAP2_IPSEC_OFFLOAD); 3588 } 3589 if (!mlx5e_is_ratelimit_capable(priv->mdev)) { 3590 drv_ioctl_data->reqcap &= ~(IFCAP_TXTLS_RTLMT | 3591 IFCAP_TXRTLMT); 3592 } 3593 3594 mask = drv_ioctl_data->reqcap ^ if_getcapenable(ifp); 3595 3596 if (mask & IFCAP_TXCSUM) { 3597 if_togglecapenable(ifp, IFCAP_TXCSUM); 3598 if_togglehwassist(ifp, (CSUM_TCP | CSUM_UDP | CSUM_IP)); 3599 3600 if (IFCAP_TSO4 & if_getcapenable(ifp) && 3601 !(IFCAP_TXCSUM & if_getcapenable(ifp))) { 3602 mask &= ~IFCAP_TSO4; 3603 if_setcapenablebit(ifp, 0, IFCAP_TSO4); 3604 if_sethwassistbits(ifp, 0, CSUM_IP_TSO); 3605 mlx5_en_err(ifp, 3606 "tso4 disabled due to -txcsum.\n"); 3607 } 3608 } 3609 if (mask & IFCAP_TXCSUM_IPV6) { 3610 if_togglecapenable(ifp, IFCAP_TXCSUM_IPV6); 3611 if_togglehwassist(ifp, (CSUM_UDP_IPV6 | CSUM_TCP_IPV6)); 3612 3613 if (IFCAP_TSO6 & if_getcapenable(ifp) && 3614 !(IFCAP_TXCSUM_IPV6 & if_getcapenable(ifp))) { 3615 mask &= ~IFCAP_TSO6; 3616 if_setcapenablebit(ifp, 0, IFCAP_TSO6); 3617 if_sethwassistbits(ifp, 0, CSUM_IP6_TSO); 3618 mlx5_en_err(ifp, 3619 "tso6 disabled due to -txcsum6.\n"); 3620 } 3621 } 3622 if (mask & IFCAP_MEXTPG) 3623 if_togglecapenable(ifp, IFCAP_MEXTPG); 3624 if (mask & IFCAP_TXTLS4) 3625 if_togglecapenable(ifp, IFCAP_TXTLS4); 3626 if (mask & IFCAP_TXTLS6) 3627 if_togglecapenable(ifp, IFCAP_TXTLS6); 3628 #ifdef RATELIMIT 3629 if (mask & IFCAP_TXTLS_RTLMT) 3630 if_togglecapenable(ifp, IFCAP_TXTLS_RTLMT); 3631 #endif 3632 if (mask & IFCAP_RXCSUM) 3633 if_togglecapenable(ifp, IFCAP_RXCSUM); 3634 if (mask & IFCAP_RXCSUM_IPV6) 3635 if_togglecapenable(ifp, IFCAP_RXCSUM_IPV6); 3636 if (mask & IFCAP_TSO4) { 3637 if (!(IFCAP_TSO4 & if_getcapenable(ifp)) && 3638 !(IFCAP_TXCSUM & if_getcapenable(ifp))) { 3639 mlx5_en_err(ifp, "enable txcsum first.\n"); 3640 error = EAGAIN; 3641 goto out; 3642 } 3643 if_togglecapenable(ifp, IFCAP_TSO4); 3644 if_togglehwassist(ifp, CSUM_IP_TSO); 3645 } 3646 if (mask & IFCAP_TSO6) { 3647 if (!(IFCAP_TSO6 & if_getcapenable(ifp)) && 3648 !(IFCAP_TXCSUM_IPV6 & if_getcapenable(ifp))) { 3649 mlx5_en_err(ifp, "enable txcsum6 first.\n"); 3650 error = EAGAIN; 3651 goto out; 3652 } 3653 if_togglecapenable(ifp, IFCAP_TSO6); 3654 if_togglehwassist(ifp, CSUM_IP6_TSO); 3655 } 3656 if (mask & IFCAP_VLAN_HWTSO) 3657 if_togglecapenable(ifp, IFCAP_VLAN_HWTSO); 3658 if (mask & IFCAP_VLAN_HWFILTER) { 3659 if (if_getcapenable(ifp) & IFCAP_VLAN_HWFILTER) 3660 mlx5e_disable_vlan_filter(priv); 3661 else 3662 mlx5e_enable_vlan_filter(priv); 3663 3664 if_togglecapenable(ifp, IFCAP_VLAN_HWFILTER); 3665 } 3666 if (mask & IFCAP_VLAN_HWTAGGING) 3667 if_togglecapenable(ifp, IFCAP_VLAN_HWTAGGING); 3668 if (mask & IFCAP_WOL_MAGIC) 3669 if_togglecapenable(ifp, IFCAP_WOL_MAGIC); 3670 if (mask & IFCAP_VXLAN_HWCSUM) { 3671 const bool was_enabled = 3672 (if_getcapenable(ifp) & IFCAP_VXLAN_HWCSUM) != 0; 3673 if (was_enabled) 3674 mlx5e_del_all_vxlan_rules(priv); 3675 if_togglecapenable(ifp, IFCAP_VXLAN_HWCSUM); 3676 if_togglehwassist(ifp, CSUM_INNER_IP | CSUM_INNER_IP_UDP | 3677 CSUM_INNER_IP_TCP | CSUM_INNER_IP6_UDP | 3678 CSUM_INNER_IP6_TCP); 3679 if (!was_enabled) { 3680 int err = mlx5e_add_all_vxlan_rules(priv); 3681 if (err != 0) { 3682 mlx5_en_err(ifp, 3683 "mlx5e_add_all_vxlan_rules() failed, %d (ignored)\n", err); 3684 } 3685 } 3686 } 3687 if (mask & IFCAP_VXLAN_HWTSO) { 3688 if_togglecapenable(ifp, IFCAP_VXLAN_HWTSO); 3689 if_togglehwassist(ifp, CSUM_INNER_IP_TSO | 3690 CSUM_INNER_IP6_TSO); 3691 } 3692 3693 VLAN_CAPABILITIES(ifp); 3694 3695 /* hw_lro and IFCAP_LRO are divorsed, only toggle sw LRO. */ 3696 if (mask & IFCAP_LRO) 3697 if_togglecapenable(ifp, IFCAP_LRO); 3698 3699 if (mask & IFCAP_HWRXTSTMP) { 3700 if_togglecapenable(ifp, IFCAP_HWRXTSTMP); 3701 if (if_getcapenable(ifp) & IFCAP_HWRXTSTMP) { 3702 if (priv->clbr_done == 0) 3703 mlx5e_reset_calibration_callout(priv); 3704 } else { 3705 callout_drain(&priv->tstmp_clbr); 3706 priv->clbr_done = 0; 3707 } 3708 } 3709 mask = drv_ioctl_data->reqcap2 ^ if_getcapenable2(ifp); 3710 if ((mask & IFCAP2_BIT(IFCAP2_RXTLS4)) != 0) 3711 if_togglecapenable2(ifp, IFCAP2_BIT(IFCAP2_RXTLS4)); 3712 if ((mask & IFCAP2_BIT(IFCAP2_RXTLS6)) != 0) 3713 if_togglecapenable2(ifp, IFCAP2_BIT(IFCAP2_RXTLS6)); 3714 #ifdef IPSEC_OFFLOAD 3715 if ((mask & IFCAP2_BIT(IFCAP2_IPSEC_OFFLOAD)) != 0) { 3716 bool was_enabled = (if_getcapenable2(ifp) & 3717 IFCAP2_BIT(IFCAP2_IPSEC_OFFLOAD)) != 0; 3718 mlx5e_close_locked(ifp); 3719 if (was_enabled) 3720 ipsec_accel_on_ifdown(priv->ifp); 3721 if_togglecapenable2(ifp, 3722 IFCAP2_BIT(IFCAP2_IPSEC_OFFLOAD)); 3723 mlx5e_open_locked(ifp); 3724 } 3725 #endif 3726 out: 3727 PRIV_UNLOCK(priv); 3728 break; 3729 3730 case SIOCGI2C: 3731 ifr = (struct ifreq *)data; 3732 3733 /* 3734 * Copy from the user-space address ifr_data to the 3735 * kernel-space address i2c 3736 */ 3737 error = copyin(ifr_data_get_ptr(ifr), &i2c, sizeof(i2c)); 3738 if (error) 3739 break; 3740 3741 if (i2c.len > sizeof(i2c.data)) { 3742 error = EINVAL; 3743 break; 3744 } 3745 3746 PRIV_LOCK(priv); 3747 /* Get module_num which is required for the query_eeprom */ 3748 error = mlx5_query_module_num(priv->mdev, &module_num); 3749 if (error) { 3750 mlx5_en_err(ifp, 3751 "Query module num failed, eeprom reading is not supported\n"); 3752 error = EINVAL; 3753 goto err_i2c; 3754 } 3755 /* Check if module is present before doing an access */ 3756 module_status = mlx5_query_module_status(priv->mdev, module_num); 3757 if (module_status != MLX5_MODULE_STATUS_PLUGGED_ENABLED) { 3758 if (bootverbose) 3759 mlx5_en_err(ifp, 3760 "Query module %d status: not plugged (%d), " 3761 "eeprom reading is not supported\n", 3762 module_num, module_status); 3763 error = EINVAL; 3764 goto err_i2c; 3765 } 3766 /* 3767 * Currently 0XA0 and 0xA2 are the only addresses permitted. 3768 * The internal conversion is as follows: 3769 */ 3770 if (i2c.dev_addr == 0xA0) 3771 read_addr = MLX5_I2C_ADDR_LOW; 3772 else if (i2c.dev_addr == 0xA2) 3773 read_addr = MLX5_I2C_ADDR_HIGH; 3774 else { 3775 mlx5_en_err(ifp, 3776 "Query eeprom failed, Invalid Address: %X\n", 3777 i2c.dev_addr); 3778 error = EINVAL; 3779 goto err_i2c; 3780 } 3781 error = mlx5_query_eeprom(priv->mdev, 3782 read_addr, MLX5_EEPROM_LOW_PAGE, 3783 (uint32_t)i2c.offset, (uint32_t)i2c.len, module_num, 3784 (uint32_t *)i2c.data, &size_read); 3785 if (error) { 3786 mlx5_en_err(ifp, 3787 "Query eeprom failed, eeprom reading is not supported\n"); 3788 error = EINVAL; 3789 goto err_i2c; 3790 } 3791 3792 if (i2c.len > MLX5_EEPROM_MAX_BYTES) { 3793 error = mlx5_query_eeprom(priv->mdev, 3794 read_addr, MLX5_EEPROM_LOW_PAGE, 3795 (uint32_t)(i2c.offset + size_read), 3796 (uint32_t)(i2c.len - size_read), module_num, 3797 (uint32_t *)(i2c.data + size_read), &size_read); 3798 } 3799 if (error) { 3800 mlx5_en_err(ifp, 3801 "Query eeprom failed, eeprom reading is not supported\n"); 3802 error = EINVAL; 3803 goto err_i2c; 3804 } 3805 3806 error = copyout(&i2c, ifr_data_get_ptr(ifr), sizeof(i2c)); 3807 err_i2c: 3808 PRIV_UNLOCK(priv); 3809 break; 3810 case SIOCGIFDOWNREASON: 3811 ifdr = (struct ifdownreason *)data; 3812 bzero(ifdr->ifdr_msg, sizeof(ifdr->ifdr_msg)); 3813 PRIV_LOCK(priv); 3814 error = -mlx5_query_pddr_troubleshooting_info(priv->mdev, NULL, 3815 ifdr->ifdr_msg, sizeof(ifdr->ifdr_msg)); 3816 PRIV_UNLOCK(priv); 3817 if (error == 0) 3818 ifdr->ifdr_reason = IFDR_REASON_MSG; 3819 break; 3820 3821 case SIOCGIFRSSKEY: 3822 ifrk = (struct ifrsskey *)data; 3823 ifrk->ifrk_func = RSS_FUNC_TOEPLITZ; 3824 ifrk->ifrk_keylen = MLX5E_RSS_KEY_SIZE; 3825 CTASSERT(sizeof(ifrk->ifrk_key) >= MLX5E_RSS_KEY_SIZE); 3826 mlx5e_get_rss_key(ifrk->ifrk_key); 3827 break; 3828 3829 case SIOCGIFRSSHASH: 3830 ifrh = (struct ifrsshash *)data; 3831 ifrh->ifrh_func = RSS_FUNC_TOEPLITZ; 3832 ifrh->ifrh_types = 3833 RSS_TYPE_IPV4 | 3834 RSS_TYPE_TCP_IPV4 | 3835 RSS_TYPE_UDP_IPV4 | 3836 RSS_TYPE_IPV6 | 3837 RSS_TYPE_TCP_IPV6 | 3838 RSS_TYPE_UDP_IPV6; 3839 break; 3840 3841 default: 3842 error = ether_ioctl(ifp, command, data); 3843 break; 3844 } 3845 return (error); 3846 } 3847 3848 static int 3849 mlx5e_check_required_hca_cap(struct mlx5_core_dev *mdev) 3850 { 3851 /* 3852 * TODO: uncoment once FW really sets all these bits if 3853 * (!mdev->caps.eth.rss_ind_tbl_cap || !mdev->caps.eth.csum_cap || 3854 * !mdev->caps.eth.max_lso_cap || !mdev->caps.eth.vlan_cap || 3855 * !(mdev->caps.gen.flags & MLX5_DEV_CAP_FLAG_SCQE_BRK_MOD)) return 3856 * -ENOTSUPP; 3857 */ 3858 3859 /* TODO: add more must-to-have features */ 3860 3861 if (MLX5_CAP_GEN(mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH) 3862 return (-ENODEV); 3863 3864 return (0); 3865 } 3866 3867 static u16 3868 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev) 3869 { 3870 const int min_size = ETHER_VLAN_ENCAP_LEN + ETHER_HDR_LEN; 3871 const int max_size = MLX5E_MAX_TX_INLINE; 3872 const int bf_buf_size = 3873 ((1U << MLX5_CAP_GEN(mdev, log_bf_reg_size)) / 2U) - 3874 (sizeof(struct mlx5e_tx_wqe) - 2); 3875 3876 /* verify against driver limits */ 3877 if (bf_buf_size > max_size) 3878 return (max_size); 3879 else if (bf_buf_size < min_size) 3880 return (min_size); 3881 else 3882 return (bf_buf_size); 3883 } 3884 3885 static int 3886 mlx5e_build_ifp_priv(struct mlx5_core_dev *mdev, 3887 struct mlx5e_priv *priv, 3888 int num_comp_vectors) 3889 { 3890 int err; 3891 3892 /* 3893 * TODO: Consider link speed for setting "log_sq_size", 3894 * "log_rq_size" and "cq_moderation_xxx": 3895 */ 3896 priv->params.log_sq_size = 3897 MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE; 3898 priv->params.log_rq_size = 3899 MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE; 3900 priv->params.rx_cq_moderation_usec = 3901 MLX5_CAP_GEN(mdev, cq_period_start_from_cqe) ? 3902 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC_FROM_CQE : 3903 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC; 3904 priv->params.rx_cq_moderation_mode = 3905 MLX5_CAP_GEN(mdev, cq_period_start_from_cqe) ? 1 : 0; 3906 priv->params.rx_cq_moderation_pkts = 3907 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS; 3908 priv->params.tx_cq_moderation_usec = 3909 MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC; 3910 priv->params.tx_cq_moderation_pkts = 3911 MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS; 3912 priv->params.rx_hash_log_tbl_sz = 3913 (order_base_2(num_comp_vectors) > 3914 MLX5E_PARAMS_DEFAULT_RX_HASH_LOG_TBL_SZ) ? 3915 order_base_2(num_comp_vectors) : 3916 MLX5E_PARAMS_DEFAULT_RX_HASH_LOG_TBL_SZ; 3917 priv->params.num_tc = 1; 3918 priv->params.default_vlan_prio = 0; 3919 priv->counter_set_id = -1; 3920 priv->params.tx_max_inline = mlx5e_get_max_inline_cap(mdev); 3921 3922 err = mlx5_query_min_inline(mdev, &priv->params.tx_min_inline_mode); 3923 if (err) 3924 return (err); 3925 3926 /* 3927 * hw lro is currently defaulted to off. when it won't anymore we 3928 * will consider the HW capability: "!!MLX5_CAP_ETH(mdev, lro_cap)" 3929 */ 3930 priv->params.hw_lro_en = false; 3931 priv->params.lro_wqe_sz = MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ; 3932 3933 /* 3934 * CQE zipping is off, because the per-packet 32-bit Toeplitz hash 3935 * is then not supported. The 32-bit Toeplitz hash is needed to 3936 * correctly demultiplex incoming traffic into the expected 3937 * network queues. 3938 */ 3939 priv->params.cqe_zipping_en = false; 3940 3941 priv->mdev = mdev; 3942 priv->params.num_channels = num_comp_vectors; 3943 priv->params.channels_rsss = 1; 3944 priv->order_base_2_num_channels = order_base_2(num_comp_vectors); 3945 priv->queue_mapping_channel_mask = 3946 roundup_pow_of_two(num_comp_vectors) - 1; 3947 priv->num_tc = priv->params.num_tc; 3948 priv->default_vlan_prio = priv->params.default_vlan_prio; 3949 3950 INIT_WORK(&priv->update_stats_work, mlx5e_update_stats_work); 3951 INIT_WORK(&priv->update_carrier_work, mlx5e_update_carrier_work); 3952 INIT_WORK(&priv->set_rx_mode_work, mlx5e_set_rx_mode_work); 3953 3954 return (0); 3955 } 3956 3957 static void 3958 mlx5e_mkey_set_relaxed_ordering(struct mlx5_core_dev *mdev, void *mkc) 3959 { 3960 bool ro_pci_enable = 3961 pci_get_relaxed_ordering_enabled(mdev->pdev->dev.bsddev); 3962 bool ro_write = MLX5_CAP_GEN(mdev, relaxed_ordering_write); 3963 bool ro_read = MLX5_CAP_GEN(mdev, relaxed_ordering_read); 3964 3965 MLX5_SET(mkc, mkc, relaxed_ordering_read, ro_pci_enable && ro_read); 3966 MLX5_SET(mkc, mkc, relaxed_ordering_write, ro_pci_enable && ro_write); 3967 } 3968 3969 static int 3970 mlx5e_create_mkey(struct mlx5e_priv *priv, u32 pdn, 3971 struct mlx5_core_mkey *mkey) 3972 { 3973 if_t ifp = priv->ifp; 3974 struct mlx5_core_dev *mdev = priv->mdev; 3975 int inlen = MLX5_ST_SZ_BYTES(create_mkey_in); 3976 void *mkc; 3977 u32 *in; 3978 int err; 3979 3980 in = mlx5_vzalloc(inlen); 3981 if (in == NULL) { 3982 mlx5_en_err(ifp, "failed to allocate inbox\n"); 3983 return (-ENOMEM); 3984 } 3985 3986 mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry); 3987 MLX5_SET(mkc, mkc, access_mode, MLX5_ACCESS_MODE_PA); 3988 MLX5_SET(mkc, mkc, umr_en, 1); /* used by HW TLS */ 3989 MLX5_SET(mkc, mkc, lw, 1); 3990 MLX5_SET(mkc, mkc, lr, 1); 3991 mlx5e_mkey_set_relaxed_ordering(mdev, mkc); 3992 MLX5_SET(mkc, mkc, pd, pdn); 3993 MLX5_SET(mkc, mkc, length64, 1); 3994 MLX5_SET(mkc, mkc, qpn, 0xffffff); 3995 3996 err = mlx5_core_create_mkey(mdev, mkey, in, inlen); 3997 if (err) 3998 mlx5_en_err(ifp, "mlx5_core_create_mkey failed, %d\n", 3999 err); 4000 4001 kvfree(in); 4002 return (err); 4003 } 4004 4005 static const char *mlx5e_vport_stats_desc[] = { 4006 MLX5E_VPORT_STATS(MLX5E_STATS_DESC) 4007 }; 4008 4009 static const char *mlx5e_pport_stats_desc[] = { 4010 MLX5E_PPORT_STATS(MLX5E_STATS_DESC) 4011 }; 4012 4013 static int 4014 mlx5e_priv_static_init(struct mlx5e_priv *priv, struct mlx5_core_dev *mdev, 4015 const uint32_t channels) 4016 { 4017 uint32_t x; 4018 int err; 4019 4020 mtx_init(&priv->async_events_mtx, "mlx5async", MTX_NETWORK_LOCK, MTX_DEF); 4021 sx_init(&priv->state_lock, "mlx5state"); 4022 callout_init_mtx(&priv->watchdog, &priv->async_events_mtx, 0); 4023 MLX5_INIT_DOORBELL_LOCK(&priv->doorbell_lock); 4024 for (x = 0; x != channels; x++) 4025 mlx5e_chan_static_init(priv, &priv->channel[x], x); 4026 4027 for (x = 0; x != channels; x++) { 4028 err = mlx5_alloc_bfreg(mdev, &priv->channel[x].bfreg, false, false); 4029 if (err) 4030 goto err_alloc_bfreg; 4031 } 4032 return (0); 4033 4034 err_alloc_bfreg: 4035 while (x--) 4036 mlx5_free_bfreg(mdev, &priv->channel[x].bfreg); 4037 4038 for (x = 0; x != channels; x++) 4039 mlx5e_chan_static_destroy(&priv->channel[x]); 4040 callout_drain(&priv->watchdog); 4041 mtx_destroy(&priv->async_events_mtx); 4042 sx_destroy(&priv->state_lock); 4043 return (err); 4044 } 4045 4046 static void 4047 mlx5e_priv_static_destroy(struct mlx5e_priv *priv, struct mlx5_core_dev *mdev, 4048 const uint32_t channels) 4049 { 4050 uint32_t x; 4051 4052 for (x = 0; x != channels; x++) 4053 mlx5_free_bfreg(mdev, &priv->channel[x].bfreg); 4054 for (x = 0; x != channels; x++) 4055 mlx5e_chan_static_destroy(&priv->channel[x]); 4056 callout_drain(&priv->watchdog); 4057 mtx_destroy(&priv->async_events_mtx); 4058 sx_destroy(&priv->state_lock); 4059 } 4060 4061 static int 4062 sysctl_firmware(SYSCTL_HANDLER_ARGS) 4063 { 4064 /* 4065 * %d.%d%.d the string format. 4066 * fw_rev_{maj,min,sub} return u16, 2^16 = 65536. 4067 * We need at most 5 chars to store that. 4068 * It also has: two "." and NULL at the end, which means we need 18 4069 * (5*3 + 3) chars at most. 4070 */ 4071 char fw[18]; 4072 struct mlx5e_priv *priv = arg1; 4073 int error; 4074 4075 snprintf(fw, sizeof(fw), "%d.%d.%d", fw_rev_maj(priv->mdev), fw_rev_min(priv->mdev), 4076 fw_rev_sub(priv->mdev)); 4077 error = sysctl_handle_string(oidp, fw, sizeof(fw), req); 4078 return (error); 4079 } 4080 4081 static void 4082 mlx5e_disable_tx_dma(struct mlx5e_channel *ch) 4083 { 4084 int i; 4085 4086 for (i = 0; i < ch->priv->num_tc; i++) 4087 mlx5e_drain_sq(&ch->sq[i]); 4088 } 4089 4090 static void 4091 mlx5e_reset_sq_doorbell_record(struct mlx5e_sq *sq) 4092 { 4093 4094 sq->doorbell.d32[0] = cpu_to_be32(MLX5_OPCODE_NOP); 4095 sq->doorbell.d32[1] = cpu_to_be32(sq->sqn << 8); 4096 mlx5e_tx_notify_hw(sq, true); 4097 } 4098 4099 void 4100 mlx5e_resume_sq(struct mlx5e_sq *sq) 4101 { 4102 int err; 4103 4104 /* check if already enabled */ 4105 if (READ_ONCE(sq->running) != 0) 4106 return; 4107 4108 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_ERR, 4109 MLX5_SQC_STATE_RST); 4110 if (err != 0) { 4111 mlx5_en_err(sq->ifp, 4112 "mlx5e_modify_sq() from ERR to RST failed: %d\n", err); 4113 } 4114 4115 sq->cc = 0; 4116 sq->pc = 0; 4117 4118 /* reset doorbell prior to moving from RST to RDY */ 4119 mlx5e_reset_sq_doorbell_record(sq); 4120 4121 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RST, 4122 MLX5_SQC_STATE_RDY); 4123 if (err != 0) { 4124 mlx5_en_err(sq->ifp, 4125 "mlx5e_modify_sq() from RST to RDY failed: %d\n", err); 4126 } 4127 4128 sq->cev_next_state = MLX5E_CEV_STATE_INITIAL; 4129 WRITE_ONCE(sq->running, 1); 4130 } 4131 4132 static void 4133 mlx5e_enable_tx_dma(struct mlx5e_channel *ch) 4134 { 4135 int i; 4136 4137 for (i = 0; i < ch->priv->num_tc; i++) 4138 mlx5e_resume_sq(&ch->sq[i]); 4139 } 4140 4141 static void 4142 mlx5e_disable_rx_dma(struct mlx5e_channel *ch) 4143 { 4144 struct mlx5e_rq *rq = &ch->rq; 4145 struct epoch_tracker et; 4146 int err; 4147 4148 mtx_lock(&rq->mtx); 4149 rq->enabled = 0; 4150 callout_stop(&rq->watchdog); 4151 mtx_unlock(&rq->mtx); 4152 4153 err = mlx5e_modify_rq(rq, MLX5_RQC_STATE_RDY, MLX5_RQC_STATE_ERR); 4154 if (err != 0) { 4155 mlx5_en_err(rq->ifp, 4156 "mlx5e_modify_rq() from RDY to RST failed: %d\n", err); 4157 } 4158 4159 while (!mlx5_wq_ll_is_empty(&rq->wq)) { 4160 msleep(1); 4161 NET_EPOCH_ENTER(et); 4162 rq->cq.mcq.comp(&rq->cq.mcq, NULL); 4163 NET_EPOCH_EXIT(et); 4164 } 4165 4166 /* 4167 * Transitioning into RST state will allow the FW to track less ERR state queues, 4168 * thus reducing the recv queue flushing time 4169 */ 4170 err = mlx5e_modify_rq(rq, MLX5_RQC_STATE_ERR, MLX5_RQC_STATE_RST); 4171 if (err != 0) { 4172 mlx5_en_err(rq->ifp, 4173 "mlx5e_modify_rq() from ERR to RST failed: %d\n", err); 4174 } 4175 } 4176 4177 static void 4178 mlx5e_enable_rx_dma(struct mlx5e_channel *ch) 4179 { 4180 struct mlx5e_rq *rq = &ch->rq; 4181 struct epoch_tracker et; 4182 int err; 4183 4184 rq->wq.wqe_ctr = 0; 4185 mlx5_wq_ll_update_db_record(&rq->wq); 4186 err = mlx5e_modify_rq(rq, MLX5_RQC_STATE_RST, MLX5_RQC_STATE_RDY); 4187 if (err != 0) { 4188 mlx5_en_err(rq->ifp, 4189 "mlx5e_modify_rq() from RST to RDY failed: %d\n", err); 4190 } 4191 4192 rq->enabled = 1; 4193 4194 NET_EPOCH_ENTER(et); 4195 rq->cq.mcq.comp(&rq->cq.mcq, NULL); 4196 NET_EPOCH_EXIT(et); 4197 } 4198 4199 void 4200 mlx5e_modify_tx_dma(struct mlx5e_priv *priv, uint8_t value) 4201 { 4202 int i; 4203 4204 if (test_bit(MLX5E_STATE_OPENED, &priv->state) == 0) 4205 return; 4206 4207 for (i = 0; i < priv->params.num_channels; i++) { 4208 if (value) 4209 mlx5e_disable_tx_dma(&priv->channel[i]); 4210 else 4211 mlx5e_enable_tx_dma(&priv->channel[i]); 4212 } 4213 } 4214 4215 void 4216 mlx5e_modify_rx_dma(struct mlx5e_priv *priv, uint8_t value) 4217 { 4218 int i; 4219 4220 if (test_bit(MLX5E_STATE_OPENED, &priv->state) == 0) 4221 return; 4222 4223 for (i = 0; i < priv->params.num_channels; i++) { 4224 if (value) 4225 mlx5e_disable_rx_dma(&priv->channel[i]); 4226 else 4227 mlx5e_enable_rx_dma(&priv->channel[i]); 4228 } 4229 } 4230 4231 static void 4232 mlx5e_add_hw_stats(struct mlx5e_priv *priv) 4233 { 4234 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(priv->sysctl_hw), 4235 OID_AUTO, "fw_version", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, 4236 priv, 0, sysctl_firmware, "A", "HCA firmware version"); 4237 4238 SYSCTL_ADD_STRING(&priv->sysctl_ctx, SYSCTL_CHILDREN(priv->sysctl_hw), 4239 OID_AUTO, "board_id", CTLFLAG_RD, priv->mdev->board_id, 0, 4240 "Board ID"); 4241 } 4242 4243 static int 4244 mlx5e_sysctl_tx_priority_flow_control(SYSCTL_HANDLER_ARGS) 4245 { 4246 struct mlx5e_priv *priv = arg1; 4247 uint8_t temp[MLX5E_MAX_PRIORITY]; 4248 uint32_t tx_pfc; 4249 int err; 4250 int i; 4251 4252 PRIV_LOCK(priv); 4253 4254 tx_pfc = priv->params.tx_priority_flow_control; 4255 4256 for (i = 0; i != MLX5E_MAX_PRIORITY; i++) 4257 temp[i] = (tx_pfc >> i) & 1; 4258 4259 err = SYSCTL_OUT(req, temp, MLX5E_MAX_PRIORITY); 4260 if (err || !req->newptr) 4261 goto done; 4262 err = SYSCTL_IN(req, temp, MLX5E_MAX_PRIORITY); 4263 if (err) 4264 goto done; 4265 4266 priv->params.tx_priority_flow_control = 0; 4267 4268 /* range check input value */ 4269 for (i = 0; i != MLX5E_MAX_PRIORITY; i++) { 4270 if (temp[i] > 1) { 4271 err = ERANGE; 4272 goto done; 4273 } 4274 priv->params.tx_priority_flow_control |= (temp[i] << i); 4275 } 4276 4277 /* check if update is required */ 4278 if (tx_pfc != priv->params.tx_priority_flow_control) 4279 err = -mlx5e_set_port_pfc(priv); 4280 done: 4281 if (err != 0) 4282 priv->params.tx_priority_flow_control= tx_pfc; 4283 PRIV_UNLOCK(priv); 4284 4285 return (err); 4286 } 4287 4288 static int 4289 mlx5e_sysctl_rx_priority_flow_control(SYSCTL_HANDLER_ARGS) 4290 { 4291 struct mlx5e_priv *priv = arg1; 4292 uint8_t temp[MLX5E_MAX_PRIORITY]; 4293 uint32_t rx_pfc; 4294 int err; 4295 int i; 4296 4297 PRIV_LOCK(priv); 4298 4299 rx_pfc = priv->params.rx_priority_flow_control; 4300 4301 for (i = 0; i != MLX5E_MAX_PRIORITY; i++) 4302 temp[i] = (rx_pfc >> i) & 1; 4303 4304 err = SYSCTL_OUT(req, temp, MLX5E_MAX_PRIORITY); 4305 if (err || !req->newptr) 4306 goto done; 4307 err = SYSCTL_IN(req, temp, MLX5E_MAX_PRIORITY); 4308 if (err) 4309 goto done; 4310 4311 priv->params.rx_priority_flow_control = 0; 4312 4313 /* range check input value */ 4314 for (i = 0; i != MLX5E_MAX_PRIORITY; i++) { 4315 if (temp[i] > 1) { 4316 err = ERANGE; 4317 goto done; 4318 } 4319 priv->params.rx_priority_flow_control |= (temp[i] << i); 4320 } 4321 4322 /* check if update is required */ 4323 if (rx_pfc != priv->params.rx_priority_flow_control) { 4324 err = -mlx5e_set_port_pfc(priv); 4325 if (err == 0 && priv->sw_is_port_buf_owner) 4326 err = mlx5e_update_buf_lossy(priv); 4327 } 4328 done: 4329 if (err != 0) 4330 priv->params.rx_priority_flow_control= rx_pfc; 4331 PRIV_UNLOCK(priv); 4332 4333 return (err); 4334 } 4335 4336 static void 4337 mlx5e_setup_pauseframes(struct mlx5e_priv *priv) 4338 { 4339 int error; 4340 4341 /* enable pauseframes by default */ 4342 priv->params.tx_pauseframe_control = 1; 4343 priv->params.rx_pauseframe_control = 1; 4344 4345 /* disable ports flow control, PFC, by default */ 4346 priv->params.tx_priority_flow_control = 0; 4347 priv->params.rx_priority_flow_control = 0; 4348 4349 /* register pauseframe SYSCTLs */ 4350 SYSCTL_ADD_INT(&priv->sysctl_ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet), 4351 OID_AUTO, "tx_pauseframe_control", CTLFLAG_RDTUN, 4352 &priv->params.tx_pauseframe_control, 0, 4353 "Set to enable TX pause frames. Clear to disable."); 4354 4355 SYSCTL_ADD_INT(&priv->sysctl_ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet), 4356 OID_AUTO, "rx_pauseframe_control", CTLFLAG_RDTUN, 4357 &priv->params.rx_pauseframe_control, 0, 4358 "Set to enable RX pause frames. Clear to disable."); 4359 4360 /* register priority flow control, PFC, SYSCTLs */ 4361 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet), 4362 OID_AUTO, "tx_priority_flow_control", CTLTYPE_U8 | CTLFLAG_RWTUN | 4363 CTLFLAG_MPSAFE, priv, 0, &mlx5e_sysctl_tx_priority_flow_control, "CU", 4364 "Set to enable TX ports flow control frames for priorities 0..7. Clear to disable."); 4365 4366 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet), 4367 OID_AUTO, "rx_priority_flow_control", CTLTYPE_U8 | CTLFLAG_RWTUN | 4368 CTLFLAG_MPSAFE, priv, 0, &mlx5e_sysctl_rx_priority_flow_control, "CU", 4369 "Set to enable RX ports flow control frames for priorities 0..7. Clear to disable."); 4370 4371 PRIV_LOCK(priv); 4372 4373 /* range check */ 4374 priv->params.tx_pauseframe_control = 4375 priv->params.tx_pauseframe_control ? 1 : 0; 4376 priv->params.rx_pauseframe_control = 4377 priv->params.rx_pauseframe_control ? 1 : 0; 4378 4379 /* update firmware */ 4380 error = mlx5e_set_port_pause_and_pfc(priv); 4381 if (error == -EINVAL) { 4382 mlx5_en_err(priv->ifp, 4383 "Global pauseframes must be disabled before enabling PFC.\n"); 4384 priv->params.rx_priority_flow_control = 0; 4385 priv->params.tx_priority_flow_control = 0; 4386 4387 /* update firmware */ 4388 (void) mlx5e_set_port_pause_and_pfc(priv); 4389 } 4390 PRIV_UNLOCK(priv); 4391 } 4392 4393 static int 4394 mlx5e_ul_snd_tag_alloc(if_t ifp, 4395 union if_snd_tag_alloc_params *params, 4396 struct m_snd_tag **ppmt) 4397 { 4398 struct mlx5e_priv *priv; 4399 struct mlx5e_channel *pch; 4400 4401 priv = if_getsoftc(ifp); 4402 4403 if (unlikely(priv->gone || params->hdr.flowtype == M_HASHTYPE_NONE)) { 4404 return (EOPNOTSUPP); 4405 } else { 4406 /* keep this code synced with mlx5e_select_queue() */ 4407 u32 ch = priv->params.num_channels; 4408 #ifdef RSS 4409 u32 temp; 4410 4411 if (rss_hash2bucket(params->hdr.flowid, 4412 params->hdr.flowtype, &temp) == 0) 4413 ch = temp % ch; 4414 else 4415 #endif 4416 ch = (params->hdr.flowid % 128) % ch; 4417 4418 /* 4419 * NOTE: The channels array is only freed at detach 4420 * and it safe to return a pointer to the send tag 4421 * inside the channels structure as long as we 4422 * reference the priv. 4423 */ 4424 pch = priv->channel + ch; 4425 4426 /* check if send queue is not running */ 4427 if (unlikely(pch->sq[0].running == 0)) 4428 return (ENXIO); 4429 m_snd_tag_ref(&pch->tag); 4430 *ppmt = &pch->tag; 4431 return (0); 4432 } 4433 } 4434 4435 static int 4436 mlx5e_ul_snd_tag_query(struct m_snd_tag *pmt, union if_snd_tag_query_params *params) 4437 { 4438 struct mlx5e_channel *pch = 4439 container_of(pmt, struct mlx5e_channel, tag); 4440 4441 params->unlimited.max_rate = -1ULL; 4442 params->unlimited.queue_level = mlx5e_sq_queue_level(&pch->sq[0]); 4443 return (0); 4444 } 4445 4446 static void 4447 mlx5e_ul_snd_tag_free(struct m_snd_tag *pmt) 4448 { 4449 struct mlx5e_channel *pch = 4450 container_of(pmt, struct mlx5e_channel, tag); 4451 4452 complete(&pch->completion); 4453 } 4454 4455 static int 4456 mlx5e_snd_tag_alloc(if_t ifp, 4457 union if_snd_tag_alloc_params *params, 4458 struct m_snd_tag **ppmt) 4459 { 4460 4461 switch (params->hdr.type) { 4462 #ifdef RATELIMIT 4463 case IF_SND_TAG_TYPE_RATE_LIMIT: 4464 return (mlx5e_rl_snd_tag_alloc(ifp, params, ppmt)); 4465 #ifdef KERN_TLS 4466 case IF_SND_TAG_TYPE_TLS_RATE_LIMIT: 4467 return (mlx5e_tls_snd_tag_alloc(ifp, params, ppmt)); 4468 #endif 4469 #endif 4470 case IF_SND_TAG_TYPE_UNLIMITED: 4471 return (mlx5e_ul_snd_tag_alloc(ifp, params, ppmt)); 4472 #ifdef KERN_TLS 4473 case IF_SND_TAG_TYPE_TLS: 4474 return (mlx5e_tls_snd_tag_alloc(ifp, params, ppmt)); 4475 case IF_SND_TAG_TYPE_TLS_RX: 4476 return (mlx5e_tls_rx_snd_tag_alloc(ifp, params, ppmt)); 4477 #endif 4478 default: 4479 return (EOPNOTSUPP); 4480 } 4481 } 4482 4483 #ifdef RATELIMIT 4484 #define NUM_HDWR_RATES_MLX 13 4485 static const uint64_t adapter_rates_mlx[NUM_HDWR_RATES_MLX] = { 4486 135375, /* 1,083,000 */ 4487 180500, /* 1,444,000 */ 4488 270750, /* 2,166,000 */ 4489 361000, /* 2,888,000 */ 4490 541500, /* 4,332,000 */ 4491 721875, /* 5,775,000 */ 4492 1082875, /* 8,663,000 */ 4493 1443875, /* 11,551,000 */ 4494 2165750, /* 17,326,000 */ 4495 2887750, /* 23,102,000 */ 4496 4331625, /* 34,653,000 */ 4497 5775500, /* 46,204,000 */ 4498 8663125 /* 69,305,000 */ 4499 }; 4500 4501 static void 4502 mlx5e_ratelimit_query(if_t ifp __unused, struct if_ratelimit_query_results *q) 4503 { 4504 /* 4505 * This function needs updating by the driver maintainer! 4506 * For the MLX card there are currently (ConectX-4?) 13 4507 * pre-set rates and others i.e. ConnectX-5, 6, 7?? 4508 * 4509 * This will change based on later adapters 4510 * and this code should be updated to look at ifp 4511 * and figure out the specific adapter type 4512 * settings i.e. how many rates as well 4513 * as if they are fixed (as is shown here) or 4514 * if they are dynamic (example chelsio t4). Also if there 4515 * is a maximum number of flows that the adapter 4516 * can handle that too needs to be updated in 4517 * the max_flows field. 4518 */ 4519 q->rate_table = adapter_rates_mlx; 4520 q->flags = RT_IS_FIXED_TABLE; 4521 q->max_flows = 0; /* mlx has no limit */ 4522 q->number_of_rates = NUM_HDWR_RATES_MLX; 4523 q->min_segment_burst = 1; 4524 } 4525 #endif 4526 4527 static void 4528 mlx5e_ifm_add(struct mlx5e_priv *priv, int type) 4529 { 4530 ifmedia_add(&priv->media, type | IFM_ETHER, 0, NULL); 4531 ifmedia_add(&priv->media, type | IFM_ETHER | 4532 IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE, 0, NULL); 4533 ifmedia_add(&priv->media, type | IFM_ETHER | IFM_ETH_RXPAUSE, 0, NULL); 4534 ifmedia_add(&priv->media, type | IFM_ETHER | IFM_ETH_TXPAUSE, 0, NULL); 4535 ifmedia_add(&priv->media, type | IFM_ETHER | IFM_FDX, 0, NULL); 4536 ifmedia_add(&priv->media, type | IFM_ETHER | IFM_FDX | 4537 IFM_ETH_RXPAUSE, 0, NULL); 4538 ifmedia_add(&priv->media, type | IFM_ETHER | IFM_FDX | 4539 IFM_ETH_TXPAUSE, 0, NULL); 4540 ifmedia_add(&priv->media, type | IFM_ETHER | IFM_FDX | 4541 IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE, 0, NULL); 4542 } 4543 4544 static void * 4545 mlx5e_create_ifp(struct mlx5_core_dev *mdev) 4546 { 4547 if_t ifp; 4548 struct mlx5e_priv *priv; 4549 u8 dev_addr[ETHER_ADDR_LEN] __aligned(4); 4550 struct sysctl_oid_list *child; 4551 int ncv = mdev->priv.eq_table.num_comp_vectors; 4552 char unit[16]; 4553 struct pfil_head_args pa; 4554 int err; 4555 u32 eth_proto_cap; 4556 u32 out[MLX5_ST_SZ_DW(ptys_reg)]; 4557 bool ext; 4558 struct media media_entry = {}; 4559 4560 if (mlx5e_check_required_hca_cap(mdev)) { 4561 mlx5_core_dbg(mdev, "mlx5e_check_required_hca_cap() failed\n"); 4562 return (NULL); 4563 } 4564 4565 /* 4566 * Try to allocate the priv and make room for worst-case 4567 * number of channel structures: 4568 */ 4569 priv = malloc_domainset(sizeof(*priv) + 4570 (sizeof(priv->channel[0]) * mdev->priv.eq_table.num_comp_vectors), 4571 M_MLX5EN, mlx5_dev_domainset(mdev), M_WAITOK | M_ZERO); 4572 4573 ifp = priv->ifp = if_alloc_dev(IFT_ETHER, mdev->pdev->dev.bsddev); 4574 /* setup all static fields */ 4575 if (mlx5e_priv_static_init(priv, mdev, mdev->priv.eq_table.num_comp_vectors)) { 4576 mlx5_core_err(mdev, "mlx5e_priv_static_init() failed\n"); 4577 goto err_free_ifp; 4578 } 4579 4580 if_setsoftc(ifp, priv); 4581 if_initname(ifp, "mce", device_get_unit(mdev->pdev->dev.bsddev)); 4582 if_setmtu(ifp, ETHERMTU); 4583 if_setinitfn(ifp, mlx5e_open); 4584 if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST); 4585 if_setioctlfn(ifp, mlx5e_ioctl); 4586 if_settransmitfn(ifp, mlx5e_xmit); 4587 if_setqflushfn(ifp, if_qflush); 4588 if_setgetcounterfn(ifp, mlx5e_get_counter); 4589 if_setsendqlen(ifp, ifqmaxlen); 4590 /* 4591 * Set driver features 4592 */ 4593 if_setcapabilities(ifp, IFCAP_NV); 4594 if_setcapabilitiesbit(ifp, IFCAP_HWCSUM | IFCAP_HWCSUM_IPV6, 0); 4595 if_setcapabilitiesbit(ifp, IFCAP_VLAN_MTU | IFCAP_VLAN_HWTAGGING, 0); 4596 if_setcapabilitiesbit(ifp, IFCAP_VLAN_HWCSUM | IFCAP_VLAN_HWFILTER, 0); 4597 if_setcapabilitiesbit(ifp, IFCAP_LINKSTATE | IFCAP_JUMBO_MTU, 0); 4598 if_setcapabilitiesbit(ifp, IFCAP_LRO, 0); 4599 if_setcapabilitiesbit(ifp, IFCAP_TSO | IFCAP_VLAN_HWTSO, 0); 4600 if_setcapabilitiesbit(ifp, IFCAP_HWSTATS | IFCAP_HWRXTSTMP, 0); 4601 if_setcapabilitiesbit(ifp, IFCAP_MEXTPG, 0); 4602 if (mlx5e_is_tlstx_capable(mdev)) 4603 if_setcapabilitiesbit(ifp, IFCAP_TXTLS4 | IFCAP_TXTLS6, 0); 4604 if (mlx5e_is_tlsrx_capable(mdev)) 4605 if_setcapabilities2bit(ifp, IFCAP2_BIT(IFCAP2_RXTLS4) | 4606 IFCAP2_BIT(IFCAP2_RXTLS6), 0); 4607 if (mlx5e_is_ratelimit_capable(mdev)) { 4608 if_setcapabilitiesbit(ifp, IFCAP_TXRTLMT, 0); 4609 if (mlx5e_is_tlstx_capable(mdev)) 4610 if_setcapabilitiesbit(ifp, IFCAP_TXTLS_RTLMT, 0); 4611 } 4612 if_setcapabilitiesbit(ifp, IFCAP_VXLAN_HWCSUM | IFCAP_VXLAN_HWTSO, 0); 4613 if (mlx5e_is_ipsec_capable(mdev)) 4614 if_setcapabilities2bit(ifp, IFCAP2_BIT(IFCAP2_IPSEC_OFFLOAD), 4615 0); 4616 4617 if_setsndtagallocfn(ifp, mlx5e_snd_tag_alloc); 4618 #ifdef RATELIMIT 4619 if_setratelimitqueryfn(ifp, mlx5e_ratelimit_query); 4620 #endif 4621 /* set TSO limits so that we don't have to drop TX packets */ 4622 if_sethwtsomax(ifp, MLX5E_MAX_TX_PAYLOAD_SIZE - (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN)); 4623 if_sethwtsomaxsegcount(ifp, MLX5E_MAX_TX_MBUF_FRAGS - 1 /* hdr */); 4624 if_sethwtsomaxsegsize(ifp, MLX5E_MAX_TX_MBUF_SIZE); 4625 4626 if_setcapenable(ifp, if_getcapabilities(ifp)); 4627 if_setcapenable2(ifp, if_getcapabilities2(ifp)); 4628 if_sethwassist(ifp, 0); 4629 if (if_getcapenable(ifp) & IFCAP_TSO) 4630 if_sethwassistbits(ifp, CSUM_TSO, 0); 4631 if (if_getcapenable(ifp) & IFCAP_TXCSUM) 4632 if_sethwassistbits(ifp, (CSUM_TCP | CSUM_UDP | CSUM_IP), 0); 4633 if (if_getcapenable(ifp) & IFCAP_TXCSUM_IPV6) 4634 if_sethwassistbits(ifp, (CSUM_UDP_IPV6 | CSUM_TCP_IPV6), 0); 4635 if (if_getcapabilities(ifp) & IFCAP_VXLAN_HWCSUM) 4636 if_sethwassistbits(ifp, CSUM_INNER_IP6_UDP | CSUM_INNER_IP6_TCP | 4637 CSUM_INNER_IP | CSUM_INNER_IP_UDP | CSUM_INNER_IP_TCP | 4638 CSUM_ENCAP_VXLAN, 0); 4639 if (if_getcapabilities(ifp) & IFCAP_VXLAN_HWTSO) 4640 if_sethwassistbits(ifp, CSUM_INNER_IP6_TSO | CSUM_INNER_IP_TSO, 0); 4641 4642 /* ifnet sysctl tree */ 4643 sysctl_ctx_init(&priv->sysctl_ctx); 4644 priv->sysctl_ifnet = SYSCTL_ADD_NODE(&priv->sysctl_ctx, SYSCTL_STATIC_CHILDREN(_dev), 4645 OID_AUTO, if_getdname(ifp), CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 4646 "MLX5 ethernet - interface name"); 4647 if (priv->sysctl_ifnet == NULL) { 4648 mlx5_core_err(mdev, "SYSCTL_ADD_NODE() failed\n"); 4649 goto err_free_sysctl; 4650 } 4651 snprintf(unit, sizeof(unit), "%d", if_getdunit(ifp)); 4652 priv->sysctl_ifnet = SYSCTL_ADD_NODE(&priv->sysctl_ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet), 4653 OID_AUTO, unit, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 4654 "MLX5 ethernet - interface unit"); 4655 if (priv->sysctl_ifnet == NULL) { 4656 mlx5_core_err(mdev, "SYSCTL_ADD_NODE() failed\n"); 4657 goto err_free_sysctl; 4658 } 4659 4660 /* HW sysctl tree */ 4661 child = SYSCTL_CHILDREN(device_get_sysctl_tree(mdev->pdev->dev.bsddev)); 4662 priv->sysctl_hw = SYSCTL_ADD_NODE(&priv->sysctl_ctx, child, 4663 OID_AUTO, "hw", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 4664 "MLX5 ethernet dev hw"); 4665 if (priv->sysctl_hw == NULL) { 4666 mlx5_core_err(mdev, "SYSCTL_ADD_NODE() failed\n"); 4667 goto err_free_sysctl; 4668 } 4669 4670 err = mlx5e_build_ifp_priv(mdev, priv, ncv); 4671 if (err) { 4672 mlx5_core_err(mdev, "mlx5e_build_ifp_priv() failed (%d)\n", err); 4673 goto err_free_sysctl; 4674 } 4675 4676 /* reuse mlx5core's watchdog workqueue */ 4677 priv->wq = mdev->priv.health.wq_watchdog; 4678 4679 err = mlx5_core_alloc_pd(mdev, &priv->pdn, 0); 4680 if (err) { 4681 mlx5_en_err(ifp, "mlx5_core_alloc_pd failed, %d\n", err); 4682 goto err_free_wq; 4683 } 4684 err = mlx5_alloc_transport_domain(mdev, &priv->tdn, 0); 4685 if (err) { 4686 mlx5_en_err(ifp, 4687 "mlx5_alloc_transport_domain failed, %d\n", err); 4688 goto err_dealloc_pd; 4689 } 4690 err = mlx5e_create_mkey(priv, priv->pdn, &priv->mr); 4691 if (err) { 4692 mlx5_en_err(ifp, "mlx5e_create_mkey failed, %d\n", err); 4693 goto err_dealloc_transport_domain; 4694 } 4695 mlx5_query_nic_vport_mac_address(priv->mdev, 0, dev_addr); 4696 4697 /* check if we should generate a random MAC address */ 4698 if (MLX5_CAP_GEN(priv->mdev, vport_group_manager) == 0 && 4699 is_zero_ether_addr(dev_addr)) { 4700 random_ether_addr(dev_addr); 4701 mlx5_en_err(ifp, "Assigned random MAC address\n"); 4702 } 4703 4704 err = mlx5e_rl_init(priv); 4705 if (err) { 4706 mlx5_en_err(ifp, "mlx5e_rl_init failed, %d\n", err); 4707 goto err_create_mkey; 4708 } 4709 4710 err = mlx5e_tls_init(priv); 4711 if (err) { 4712 if_printf(ifp, "%s: mlx5e_tls_init failed\n", __func__); 4713 goto err_rl_init; 4714 } 4715 4716 if ((if_getcapenable2(ifp) & IFCAP2_BIT(IFCAP2_IPSEC_OFFLOAD)) != 0) { 4717 err = mlx5e_ipsec_init(priv); 4718 if (err) { 4719 if_printf(ifp, "%s: mlx5e_tls_init failed\n", __func__); 4720 goto err_tls_init; 4721 } 4722 } 4723 4724 err = mlx5e_open_drop_rq(priv, &priv->drop_rq); 4725 if (err) { 4726 if_printf(ifp, "%s: mlx5e_open_drop_rq failed (%d)\n", __func__, err); 4727 goto err_ipsec_init; 4728 } 4729 4730 err = mlx5e_open_rqts(priv); 4731 if (err) { 4732 if_printf(ifp, "%s: mlx5e_open_rqts failed (%d)\n", __func__, err); 4733 goto err_open_drop_rq; 4734 } 4735 4736 err = mlx5e_open_tirs(priv); 4737 if (err) { 4738 mlx5_en_err(ifp, "mlx5e_open_tirs() failed, %d\n", err); 4739 goto err_open_rqts; 4740 } 4741 4742 err = mlx5e_open_flow_tables(priv); 4743 if (err) { 4744 if_printf(ifp, "%s: mlx5e_open_flow_tables failed (%d)\n", __func__, err); 4745 goto err_open_tirs; 4746 } 4747 4748 err = mlx5e_tls_rx_init(priv); 4749 if (err) { 4750 if_printf(ifp, "%s: mlx5e_tls_rx_init() failed, %d\n", __func__, err); 4751 goto err_open_flow_tables; 4752 } 4753 4754 /* set default MTU */ 4755 mlx5e_set_dev_port_mtu(ifp, if_getmtu(ifp)); 4756 4757 /* Set default media status */ 4758 priv->media_status_last = IFM_AVALID; 4759 priv->media_active_last = IFM_ETHER | IFM_AUTO | IFM_FDX; 4760 4761 /* setup default pauseframes configuration */ 4762 mlx5e_setup_pauseframes(priv); 4763 4764 /* Setup supported medias */ 4765 if (!mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, 1)) { 4766 ext = MLX5_CAP_PCAM_FEATURE(mdev, 4767 ptys_extended_ethernet); 4768 eth_proto_cap = MLX5_GET_ETH_PROTO(ptys_reg, out, ext, 4769 eth_proto_capability); 4770 } else { 4771 ext = false; 4772 eth_proto_cap = 0; 4773 mlx5_en_err(ifp, "Query port media capability failed, %d\n", err); 4774 } 4775 4776 ifmedia_init(&priv->media, IFM_IMASK, 4777 mlx5e_media_change, mlx5e_media_status); 4778 4779 if (ext) { 4780 for (unsigned i = 0; i != MLX5E_EXT_LINK_SPEEDS_NUMBER; i++) { 4781 /* check if hardware has the right capability */ 4782 if (MLX5E_PROT_MASK(i) & ~eth_proto_cap) 4783 continue; 4784 for (unsigned j = 0; j != MLX5E_CABLE_TYPE_NUMBER; j++) { 4785 media_entry = mlx5e_ext_mode_table[i][j]; 4786 if (media_entry.subtype == 0) 4787 continue; 4788 /* check if this subtype was already added */ 4789 for (unsigned k = 0; k != i; k++) { 4790 /* check if hardware has the right capability */ 4791 if (MLX5E_PROT_MASK(k) & ~eth_proto_cap) 4792 continue; 4793 for (unsigned m = 0; m != MLX5E_CABLE_TYPE_NUMBER; m++) { 4794 if (media_entry.subtype == mlx5e_ext_mode_table[k][m].subtype) 4795 goto skip_ext_media; 4796 } 4797 } 4798 mlx5e_ifm_add(priv, media_entry.subtype); 4799 skip_ext_media:; 4800 } 4801 } 4802 } else { 4803 for (unsigned i = 0; i != MLX5E_LINK_SPEEDS_NUMBER; i++) { 4804 media_entry = mlx5e_mode_table[i]; 4805 if (media_entry.subtype == 0) 4806 continue; 4807 if (MLX5E_PROT_MASK(i) & ~eth_proto_cap) 4808 continue; 4809 /* check if this subtype was already added */ 4810 for (unsigned k = 0; k != i; k++) { 4811 if (media_entry.subtype == mlx5e_mode_table[k].subtype) 4812 goto skip_media; 4813 } 4814 mlx5e_ifm_add(priv, media_entry.subtype); 4815 4816 /* NOTE: 10G ER and LR shares the same entry */ 4817 if (media_entry.subtype == IFM_10G_ER) 4818 mlx5e_ifm_add(priv, IFM_10G_LR); 4819 skip_media:; 4820 } 4821 } 4822 4823 mlx5e_ifm_add(priv, IFM_AUTO); 4824 4825 /* Set autoselect by default */ 4826 ifmedia_set(&priv->media, IFM_ETHER | IFM_AUTO | IFM_FDX | 4827 IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE); 4828 4829 DEBUGNET_SET(ifp, mlx5_en); 4830 4831 ether_ifattach(ifp, dev_addr); 4832 4833 /* Register for VLAN events */ 4834 priv->vlan_attach = EVENTHANDLER_REGISTER(vlan_config, 4835 mlx5e_vlan_rx_add_vid, priv, EVENTHANDLER_PRI_FIRST); 4836 priv->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig, 4837 mlx5e_vlan_rx_kill_vid, priv, EVENTHANDLER_PRI_FIRST); 4838 4839 /* Register for VxLAN events */ 4840 priv->vxlan_start = EVENTHANDLER_REGISTER(vxlan_start, 4841 mlx5e_vxlan_start, priv, EVENTHANDLER_PRI_ANY); 4842 priv->vxlan_stop = EVENTHANDLER_REGISTER(vxlan_stop, 4843 mlx5e_vxlan_stop, priv, EVENTHANDLER_PRI_ANY); 4844 4845 /* Link is down by default */ 4846 if_link_state_change(ifp, LINK_STATE_DOWN); 4847 4848 mlx5e_enable_async_events(priv); 4849 4850 mlx5e_add_hw_stats(priv); 4851 4852 mlx5e_create_stats(&priv->stats.vport.ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet), 4853 "vstats", mlx5e_vport_stats_desc, MLX5E_VPORT_STATS_NUM, 4854 priv->stats.vport.arg); 4855 4856 mlx5e_create_stats(&priv->stats.pport.ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet), 4857 "pstats", mlx5e_pport_stats_desc, MLX5E_PPORT_STATS_NUM, 4858 priv->stats.pport.arg); 4859 4860 mlx5e_create_ethtool(priv); 4861 4862 mtx_lock(&priv->async_events_mtx); 4863 mlx5e_update_stats(priv); 4864 mtx_unlock(&priv->async_events_mtx); 4865 4866 SYSCTL_ADD_INT(&priv->sysctl_ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet), 4867 OID_AUTO, "rx_clbr_done", CTLFLAG_RD, 4868 &priv->clbr_done, 0, 4869 "RX timestamps calibration state"); 4870 callout_init(&priv->tstmp_clbr, 1); 4871 /* Pull out the frequency of the clock in hz */ 4872 priv->cclk = (uint64_t)MLX5_CAP_GEN(mdev, device_frequency_khz) * 1000ULL; 4873 mlx5e_reset_calibration_callout(priv); 4874 4875 pa.pa_version = PFIL_VERSION; 4876 pa.pa_flags = PFIL_IN; 4877 pa.pa_type = PFIL_TYPE_ETHERNET; 4878 pa.pa_headname = if_name(ifp); 4879 priv->pfil = pfil_head_register(&pa); 4880 4881 PRIV_LOCK(priv); 4882 err = mlx5e_open_flow_rules(priv); 4883 if (err) { 4884 mlx5_en_err(ifp, 4885 "mlx5e_open_flow_rules() failed, %d (ignored)\n", err); 4886 } 4887 PRIV_UNLOCK(priv); 4888 4889 return (priv); 4890 4891 err_open_flow_tables: 4892 mlx5e_close_flow_tables(priv); 4893 4894 err_open_tirs: 4895 mlx5e_close_tirs(priv); 4896 4897 err_open_rqts: 4898 mlx5e_close_rqts(priv); 4899 4900 err_open_drop_rq: 4901 mlx5e_close_drop_rq(&priv->drop_rq); 4902 4903 err_ipsec_init: 4904 mlx5e_ipsec_cleanup(priv); 4905 4906 err_tls_init: 4907 mlx5e_tls_cleanup(priv); 4908 4909 err_rl_init: 4910 mlx5e_rl_cleanup(priv); 4911 4912 err_create_mkey: 4913 mlx5_core_destroy_mkey(priv->mdev, &priv->mr); 4914 4915 err_dealloc_transport_domain: 4916 mlx5_dealloc_transport_domain(mdev, priv->tdn, 0); 4917 4918 err_dealloc_pd: 4919 mlx5_core_dealloc_pd(mdev, priv->pdn, 0); 4920 4921 err_free_wq: 4922 flush_workqueue(priv->wq); 4923 4924 err_free_sysctl: 4925 sysctl_ctx_free(&priv->sysctl_ctx); 4926 if (priv->sysctl_debug) 4927 sysctl_ctx_free(&priv->stats.port_stats_debug.ctx); 4928 mlx5e_priv_static_destroy(priv, mdev, mdev->priv.eq_table.num_comp_vectors); 4929 4930 err_free_ifp: 4931 if_free(ifp); 4932 free(priv, M_MLX5EN); 4933 return (NULL); 4934 } 4935 4936 static void 4937 mlx5e_destroy_ifp(struct mlx5_core_dev *mdev, void *vpriv) 4938 { 4939 struct mlx5e_priv *priv = vpriv; 4940 if_t ifp = priv->ifp; 4941 4942 /* don't allow more IOCTLs */ 4943 priv->gone = 1; 4944 4945 /* XXX wait a bit to allow IOCTL handlers to complete */ 4946 pause("W", hz); 4947 4948 #ifdef RATELIMIT 4949 /* 4950 * Tell the TCP ratelimit code to release the rate-sets attached 4951 * to our ifnet. 4952 */ 4953 tcp_rl_release_ifnet(ifp); 4954 /* 4955 * The kernel can still have reference(s) via the m_snd_tag's into 4956 * the ratelimit channels, and these must go away before 4957 * detaching: 4958 */ 4959 while (READ_ONCE(priv->rl.stats.tx_active_connections) != 0) { 4960 mlx5_en_err(priv->ifp, 4961 "Waiting for all ratelimit connections to terminate\n"); 4962 pause("W", hz); 4963 } 4964 #endif 4965 4966 #ifdef KERN_TLS 4967 /* wait for all TLS tags to get freed */ 4968 while (priv->tls.init != 0 && 4969 uma_zone_get_cur(priv->tls.zone) != 0) { 4970 mlx5_en_err(priv->ifp, 4971 "Waiting for all TLS connections to terminate\n"); 4972 pause("W", hz); 4973 } 4974 4975 /* wait for all TLS RX tags to get freed */ 4976 while (priv->tls_rx.init != 0 && 4977 uma_zone_get_cur(priv->tls_rx.zone) != 0) { 4978 mlx5_en_err(priv->ifp, 4979 "Waiting for all TLS RX connections to terminate\n"); 4980 pause("W", hz); 4981 } 4982 #endif 4983 /* wait for all unlimited send tags to complete */ 4984 mlx5e_priv_wait_for_completion(priv, mdev->priv.eq_table.num_comp_vectors); 4985 4986 /* stop watchdog timer */ 4987 callout_drain(&priv->watchdog); 4988 4989 callout_drain(&priv->tstmp_clbr); 4990 4991 if (priv->vlan_attach != NULL) 4992 EVENTHANDLER_DEREGISTER(vlan_config, priv->vlan_attach); 4993 if (priv->vlan_detach != NULL) 4994 EVENTHANDLER_DEREGISTER(vlan_unconfig, priv->vlan_detach); 4995 if (priv->vxlan_start != NULL) 4996 EVENTHANDLER_DEREGISTER(vxlan_start, priv->vxlan_start); 4997 if (priv->vxlan_stop != NULL) 4998 EVENTHANDLER_DEREGISTER(vxlan_stop, priv->vxlan_stop); 4999 5000 /* make sure device gets closed */ 5001 PRIV_LOCK(priv); 5002 mlx5e_close_locked(ifp); 5003 mlx5e_close_flow_rules(priv); 5004 PRIV_UNLOCK(priv); 5005 5006 /* deregister pfil */ 5007 if (priv->pfil != NULL) { 5008 pfil_head_unregister(priv->pfil); 5009 priv->pfil = NULL; 5010 } 5011 5012 /* unregister device */ 5013 ifmedia_removeall(&priv->media); 5014 ether_ifdetach(ifp); 5015 5016 mlx5e_tls_rx_cleanup(priv); 5017 #ifdef IPSEC_OFFLOAD 5018 ipsec_accel_on_ifdown(priv->ifp); 5019 #endif 5020 mlx5e_close_flow_tables(priv); 5021 mlx5e_close_tirs(priv); 5022 mlx5e_close_rqts(priv); 5023 mlx5e_close_drop_rq(&priv->drop_rq); 5024 mlx5e_ipsec_cleanup(priv); 5025 mlx5e_tls_cleanup(priv); 5026 mlx5e_rl_cleanup(priv); 5027 5028 /* destroy all remaining sysctl nodes */ 5029 sysctl_ctx_free(&priv->stats.vport.ctx); 5030 sysctl_ctx_free(&priv->stats.pport.ctx); 5031 if (priv->sysctl_debug) 5032 sysctl_ctx_free(&priv->stats.port_stats_debug.ctx); 5033 sysctl_ctx_free(&priv->sysctl_ctx); 5034 5035 mlx5_core_destroy_mkey(priv->mdev, &priv->mr); 5036 mlx5_dealloc_transport_domain(priv->mdev, priv->tdn, 0); 5037 mlx5_core_dealloc_pd(priv->mdev, priv->pdn, 0); 5038 mlx5e_disable_async_events(priv); 5039 flush_workqueue(priv->wq); 5040 mlx5e_priv_static_destroy(priv, mdev, mdev->priv.eq_table.num_comp_vectors); 5041 if_free(ifp); 5042 free(priv, M_MLX5EN); 5043 } 5044 5045 #ifdef DEBUGNET 5046 static void 5047 mlx5_en_debugnet_init(if_t dev, int *nrxr, int *ncl, int *clsize) 5048 { 5049 struct mlx5e_priv *priv = if_getsoftc(dev); 5050 5051 PRIV_LOCK(priv); 5052 *nrxr = priv->params.num_channels; 5053 *ncl = DEBUGNET_MAX_IN_FLIGHT; 5054 *clsize = MLX5E_MAX_RX_BYTES; 5055 PRIV_UNLOCK(priv); 5056 } 5057 5058 static void 5059 mlx5_en_debugnet_event(if_t dev, enum debugnet_ev event) 5060 { 5061 } 5062 5063 static int 5064 mlx5_en_debugnet_transmit(if_t dev, struct mbuf *m) 5065 { 5066 struct mlx5e_priv *priv = if_getsoftc(dev); 5067 struct mlx5e_sq *sq; 5068 int err; 5069 5070 if ((if_getdrvflags(dev) & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != 5071 IFF_DRV_RUNNING || (priv->media_status_last & IFM_ACTIVE) == 0) 5072 return (ENOENT); 5073 5074 sq = &priv->channel[0].sq[0]; 5075 5076 if (sq->running == 0) { 5077 m_freem(m); 5078 return (ENOENT); 5079 } 5080 5081 if (mlx5e_sq_xmit(sq, &m) != 0) { 5082 m_freem(m); 5083 err = ENOBUFS; 5084 } else { 5085 err = 0; 5086 } 5087 5088 mlx5e_tx_notify_hw(sq, true); 5089 5090 return (err); 5091 } 5092 5093 static int 5094 mlx5_en_debugnet_poll(if_t dev, int count) 5095 { 5096 struct mlx5e_priv *priv = if_getsoftc(dev); 5097 5098 if ((if_getdrvflags(dev) & IFF_DRV_RUNNING) == 0 || 5099 (priv->media_status_last & IFM_ACTIVE) == 0) 5100 return (ENOENT); 5101 5102 mlx5_poll_interrupts(priv->mdev); 5103 5104 return (0); 5105 } 5106 #endif /* DEBUGNET */ 5107 5108 static void * 5109 mlx5e_get_ifp(void *vpriv) 5110 { 5111 struct mlx5e_priv *priv = vpriv; 5112 5113 return (priv->ifp); 5114 } 5115 5116 static struct mlx5_interface mlx5e_interface = { 5117 .add = mlx5e_create_ifp, 5118 .remove = mlx5e_destroy_ifp, 5119 .event = mlx5e_async_event, 5120 .protocol = MLX5_INTERFACE_PROTOCOL_ETH, 5121 .get_dev = mlx5e_get_ifp, 5122 }; 5123 5124 void 5125 mlx5e_init(void) 5126 { 5127 mlx5_register_interface(&mlx5e_interface); 5128 } 5129 5130 void 5131 mlx5e_cleanup(void) 5132 { 5133 mlx5_unregister_interface(&mlx5e_interface); 5134 } 5135 5136 module_init_order(mlx5e_init, SI_ORDER_SIXTH); 5137 module_exit_order(mlx5e_cleanup, SI_ORDER_SIXTH); 5138 5139 MODULE_DEPEND(mlx5en, ipsec, 1, 1, 1); 5140 MODULE_DEPEND(mlx5en, linuxkpi, 1, 1, 1); 5141 MODULE_DEPEND(mlx5en, mlx5, 1, 1, 1); 5142 MODULE_VERSION(mlx5en, 1); 5143