mlx5_en_ethtool.c revision 331570
1290650Shselasky/*- 2290650Shselasky * Copyright (c) 2015 Mellanox Technologies. All rights reserved. 3290650Shselasky * 4290650Shselasky * Redistribution and use in source and binary forms, with or without 5290650Shselasky * modification, are permitted provided that the following conditions 6290650Shselasky * are met: 7290650Shselasky * 1. Redistributions of source code must retain the above copyright 8290650Shselasky * notice, this list of conditions and the following disclaimer. 9290650Shselasky * 2. Redistributions in binary form must reproduce the above copyright 10290650Shselasky * notice, this list of conditions and the following disclaimer in the 11290650Shselasky * documentation and/or other materials provided with the distribution. 12290650Shselasky * 13290650Shselasky * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND 14290650Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15290650Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16290650Shselasky * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 17290650Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18290650Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19290650Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20290650Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21290650Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22290650Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23290650Shselasky * SUCH DAMAGE. 24290650Shselasky * 25290650Shselasky * $FreeBSD: stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c 331570 2018-03-26 20:01:58Z hselasky $ 26290650Shselasky */ 27290650Shselasky 28290650Shselasky#include "en.h" 29290650Shselasky#include <net/sff8472.h> 30290650Shselasky 31290650Shselaskyvoid 32290650Shselaskymlx5e_create_stats(struct sysctl_ctx_list *ctx, 33290650Shselasky struct sysctl_oid_list *parent, const char *buffer, 34290650Shselasky const char **desc, unsigned num, u64 * arg) 35290650Shselasky{ 36290650Shselasky struct sysctl_oid *node; 37290650Shselasky unsigned x; 38290650Shselasky 39290650Shselasky sysctl_ctx_init(ctx); 40290650Shselasky 41290650Shselasky node = SYSCTL_ADD_NODE(ctx, parent, OID_AUTO, 42290650Shselasky buffer, CTLFLAG_RD, NULL, "Statistics"); 43290650Shselasky if (node == NULL) 44290650Shselasky return; 45290650Shselasky for (x = 0; x != num; x++) { 46290650Shselasky SYSCTL_ADD_UQUAD(ctx, SYSCTL_CHILDREN(node), OID_AUTO, 47290650Shselasky desc[2 * x], CTLFLAG_RD, arg + x, desc[2 * x + 1]); 48290650Shselasky } 49290650Shselasky} 50290650Shselasky 51300277Shselaskystatic void 52300277Shselaskymlx5e_ethtool_sync_tx_completion_fact(struct mlx5e_priv *priv) 53300277Shselasky{ 54300277Shselasky /* 55300277Shselasky * Limit the maximum distance between completion events to 56300277Shselasky * half of the currently set TX queue size. 57300277Shselasky * 58300277Shselasky * The maximum number of queue entries a single IP packet can 59300277Shselasky * consume is given by MLX5_SEND_WQE_MAX_WQEBBS. 60300277Shselasky * 61300277Shselasky * The worst case max value is then given as below: 62300277Shselasky */ 63300277Shselasky uint64_t max = priv->params_ethtool.tx_queue_size / 64300277Shselasky (2 * MLX5_SEND_WQE_MAX_WQEBBS); 65300277Shselasky 66300277Shselasky /* 67300277Shselasky * Update the maximum completion factor value in case the 68300277Shselasky * tx_queue_size field changed. Ensure we don't overflow 69300277Shselasky * 16-bits. 70300277Shselasky */ 71300277Shselasky if (max < 1) 72300277Shselasky max = 1; 73300277Shselasky else if (max > 65535) 74300277Shselasky max = 65535; 75300277Shselasky priv->params_ethtool.tx_completion_fact_max = max; 76300277Shselasky 77300277Shselasky /* 78300277Shselasky * Verify that the current TX completion factor is within the 79300277Shselasky * given limits: 80300277Shselasky */ 81300277Shselasky if (priv->params_ethtool.tx_completion_fact < 1) 82300277Shselasky priv->params_ethtool.tx_completion_fact = 1; 83300277Shselasky else if (priv->params_ethtool.tx_completion_fact > max) 84300277Shselasky priv->params_ethtool.tx_completion_fact = max; 85300277Shselasky} 86300277Shselasky 87300282Shselasky#define MLX5_PARAM_OFFSET(n) \ 88300282Shselasky __offsetof(struct mlx5e_priv, params_ethtool.n) 89300282Shselasky 90290650Shselaskystatic int 91290650Shselaskymlx5e_ethtool_handler(SYSCTL_HANDLER_ARGS) 92290650Shselasky{ 93290650Shselasky struct mlx5e_priv *priv = arg1; 94290650Shselasky uint64_t value; 95321995Shselasky int mode_modify; 96290650Shselasky int was_opened; 97290650Shselasky int error; 98290650Shselasky 99290650Shselasky PRIV_LOCK(priv); 100290650Shselasky value = priv->params_ethtool.arg[arg2]; 101292837Shselasky if (req != NULL) { 102292837Shselasky error = sysctl_handle_64(oidp, &value, 0, req); 103292837Shselasky if (error || req->newptr == NULL || 104292837Shselasky value == priv->params_ethtool.arg[arg2]) 105292837Shselasky goto done; 106290650Shselasky 107292837Shselasky /* assign new value */ 108292837Shselasky priv->params_ethtool.arg[arg2] = value; 109292837Shselasky } else { 110292837Shselasky error = 0; 111292837Shselasky } 112290650Shselasky /* check if device is gone */ 113290650Shselasky if (priv->gone) { 114290650Shselasky error = ENXIO; 115290650Shselasky goto done; 116290650Shselasky } 117300282Shselasky was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state); 118321995Shselasky mode_modify = MLX5_CAP_GEN(priv->mdev, cq_period_mode_modify); 119290650Shselasky 120300282Shselasky switch (MLX5_PARAM_OFFSET(arg[arg2])) { 121300282Shselasky case MLX5_PARAM_OFFSET(rx_coalesce_usecs): 122300282Shselasky /* import RX coal time */ 123300282Shselasky if (priv->params_ethtool.rx_coalesce_usecs < 1) 124300282Shselasky priv->params_ethtool.rx_coalesce_usecs = 0; 125300282Shselasky else if (priv->params_ethtool.rx_coalesce_usecs > 126300282Shselasky MLX5E_FLD_MAX(cqc, cq_period)) { 127300282Shselasky priv->params_ethtool.rx_coalesce_usecs = 128300282Shselasky MLX5E_FLD_MAX(cqc, cq_period); 129300282Shselasky } 130300282Shselasky priv->params.rx_cq_moderation_usec = 131300282Shselasky priv->params_ethtool.rx_coalesce_usecs; 132292949Shselasky 133300282Shselasky /* check to avoid down and up the network interface */ 134300282Shselasky if (was_opened) 135300282Shselasky error = mlx5e_refresh_channel_params(priv); 136300282Shselasky break; 137292949Shselasky 138300282Shselasky case MLX5_PARAM_OFFSET(rx_coalesce_pkts): 139300282Shselasky /* import RX coal pkts */ 140300282Shselasky if (priv->params_ethtool.rx_coalesce_pkts < 1) 141300282Shselasky priv->params_ethtool.rx_coalesce_pkts = 0; 142300282Shselasky else if (priv->params_ethtool.rx_coalesce_pkts > 143300282Shselasky MLX5E_FLD_MAX(cqc, cq_max_count)) { 144300282Shselasky priv->params_ethtool.rx_coalesce_pkts = 145300282Shselasky MLX5E_FLD_MAX(cqc, cq_max_count); 146300282Shselasky } 147300282Shselasky priv->params.rx_cq_moderation_pkts = 148300282Shselasky priv->params_ethtool.rx_coalesce_pkts; 149292949Shselasky 150300282Shselasky /* check to avoid down and up the network interface */ 151300282Shselasky if (was_opened) 152300282Shselasky error = mlx5e_refresh_channel_params(priv); 153300282Shselasky break; 154292949Shselasky 155300282Shselasky case MLX5_PARAM_OFFSET(tx_coalesce_usecs): 156300282Shselasky /* import TX coal time */ 157300282Shselasky if (priv->params_ethtool.tx_coalesce_usecs < 1) 158300282Shselasky priv->params_ethtool.tx_coalesce_usecs = 0; 159300282Shselasky else if (priv->params_ethtool.tx_coalesce_usecs > 160300282Shselasky MLX5E_FLD_MAX(cqc, cq_period)) { 161300282Shselasky priv->params_ethtool.tx_coalesce_usecs = 162300282Shselasky MLX5E_FLD_MAX(cqc, cq_period); 163300282Shselasky } 164300282Shselasky priv->params.tx_cq_moderation_usec = 165300282Shselasky priv->params_ethtool.tx_coalesce_usecs; 166300282Shselasky 167300282Shselasky /* check to avoid down and up the network interface */ 168300282Shselasky if (was_opened) 169292949Shselasky error = mlx5e_refresh_channel_params(priv); 170300282Shselasky break; 171300282Shselasky 172300282Shselasky case MLX5_PARAM_OFFSET(tx_coalesce_pkts): 173300282Shselasky /* import TX coal pkts */ 174300282Shselasky if (priv->params_ethtool.tx_coalesce_pkts < 1) 175300282Shselasky priv->params_ethtool.tx_coalesce_pkts = 0; 176300282Shselasky else if (priv->params_ethtool.tx_coalesce_pkts > 177300282Shselasky MLX5E_FLD_MAX(cqc, cq_max_count)) { 178300282Shselasky priv->params_ethtool.tx_coalesce_pkts = 179300282Shselasky MLX5E_FLD_MAX(cqc, cq_max_count); 180292949Shselasky } 181300282Shselasky priv->params.tx_cq_moderation_pkts = 182300282Shselasky priv->params_ethtool.tx_coalesce_pkts; 183300282Shselasky 184300282Shselasky /* check to avoid down and up the network interface */ 185300282Shselasky if (was_opened) 186300282Shselasky error = mlx5e_refresh_channel_params(priv); 187300282Shselasky break; 188300282Shselasky 189300282Shselasky case MLX5_PARAM_OFFSET(tx_queue_size): 190300282Shselasky /* network interface must be down */ 191300282Shselasky if (was_opened) 192300282Shselasky mlx5e_close_locked(priv->ifp); 193300282Shselasky 194300282Shselasky /* import TX queue size */ 195300282Shselasky if (priv->params_ethtool.tx_queue_size < 196300282Shselasky (1 << MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE)) { 197300282Shselasky priv->params_ethtool.tx_queue_size = 198300282Shselasky (1 << MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE); 199300282Shselasky } else if (priv->params_ethtool.tx_queue_size > 200300282Shselasky priv->params_ethtool.tx_queue_size_max) { 201300282Shselasky priv->params_ethtool.tx_queue_size = 202300282Shselasky priv->params_ethtool.tx_queue_size_max; 203300282Shselasky } 204300282Shselasky /* store actual TX queue size */ 205300282Shselasky priv->params.log_sq_size = 206300282Shselasky order_base_2(priv->params_ethtool.tx_queue_size); 207290650Shselasky priv->params_ethtool.tx_queue_size = 208300282Shselasky 1 << priv->params.log_sq_size; 209290650Shselasky 210300282Shselasky /* verify TX completion factor */ 211300282Shselasky mlx5e_ethtool_sync_tx_completion_fact(priv); 212300282Shselasky 213300282Shselasky /* restart network interface, if any */ 214300282Shselasky if (was_opened) 215300282Shselasky mlx5e_open_locked(priv->ifp); 216300282Shselasky break; 217300282Shselasky 218300282Shselasky case MLX5_PARAM_OFFSET(rx_queue_size): 219300282Shselasky /* network interface must be down */ 220300282Shselasky if (was_opened) 221300282Shselasky mlx5e_close_locked(priv->ifp); 222300282Shselasky 223300282Shselasky /* import RX queue size */ 224300282Shselasky if (priv->params_ethtool.rx_queue_size < 225300282Shselasky (1 << MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE)) { 226300282Shselasky priv->params_ethtool.rx_queue_size = 227300282Shselasky (1 << MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE); 228300282Shselasky } else if (priv->params_ethtool.rx_queue_size > 229300282Shselasky priv->params_ethtool.rx_queue_size_max) { 230300282Shselasky priv->params_ethtool.rx_queue_size = 231300282Shselasky priv->params_ethtool.rx_queue_size_max; 232300282Shselasky } 233300282Shselasky /* store actual RX queue size */ 234300282Shselasky priv->params.log_rq_size = 235300282Shselasky order_base_2(priv->params_ethtool.rx_queue_size); 236290650Shselasky priv->params_ethtool.rx_queue_size = 237300282Shselasky 1 << priv->params.log_rq_size; 238290650Shselasky 239300282Shselasky /* update least number of RX WQEs */ 240300282Shselasky priv->params.min_rx_wqes = min( 241300282Shselasky priv->params_ethtool.rx_queue_size - 1, 242300282Shselasky MLX5E_PARAMS_DEFAULT_MIN_RX_WQES); 243290650Shselasky 244300282Shselasky /* restart network interface, if any */ 245300282Shselasky if (was_opened) 246300282Shselasky mlx5e_open_locked(priv->ifp); 247300282Shselasky break; 248290650Shselasky 249300282Shselasky case MLX5_PARAM_OFFSET(channels): 250300282Shselasky /* network interface must be down */ 251300282Shselasky if (was_opened) 252300282Shselasky mlx5e_close_locked(priv->ifp); 253290650Shselasky 254300282Shselasky /* import number of channels */ 255300282Shselasky if (priv->params_ethtool.channels < 1) 256300282Shselasky priv->params_ethtool.channels = 1; 257300282Shselasky else if (priv->params_ethtool.channels > 258300282Shselasky (u64) priv->mdev->priv.eq_table.num_comp_vectors) { 259300282Shselasky priv->params_ethtool.channels = 260300282Shselasky (u64) priv->mdev->priv.eq_table.num_comp_vectors; 261300282Shselasky } 262300282Shselasky priv->params.num_channels = priv->params_ethtool.channels; 263291932Shselasky 264300282Shselasky /* restart network interface, if any */ 265300282Shselasky if (was_opened) 266300282Shselasky mlx5e_open_locked(priv->ifp); 267300282Shselasky break; 268300282Shselasky 269300282Shselasky case MLX5_PARAM_OFFSET(rx_coalesce_mode): 270300282Shselasky /* network interface must be down */ 271321995Shselasky if (was_opened != 0 && mode_modify == 0) 272300282Shselasky mlx5e_close_locked(priv->ifp); 273300282Shselasky 274300282Shselasky /* import RX coalesce mode */ 275300282Shselasky if (priv->params_ethtool.rx_coalesce_mode != 0) 276300282Shselasky priv->params_ethtool.rx_coalesce_mode = 1; 277300282Shselasky priv->params.rx_cq_moderation_mode = 278300282Shselasky priv->params_ethtool.rx_coalesce_mode; 279300282Shselasky 280300282Shselasky /* restart network interface, if any */ 281321995Shselasky if (was_opened != 0) { 282321995Shselasky if (mode_modify == 0) 283321995Shselasky mlx5e_open_locked(priv->ifp); 284321995Shselasky else 285321995Shselasky error = mlx5e_refresh_channel_params(priv); 286321995Shselasky } 287300282Shselasky break; 288300282Shselasky 289300282Shselasky case MLX5_PARAM_OFFSET(tx_coalesce_mode): 290300282Shselasky /* network interface must be down */ 291321995Shselasky if (was_opened != 0 && mode_modify == 0) 292300282Shselasky mlx5e_close_locked(priv->ifp); 293300282Shselasky 294300282Shselasky /* import TX coalesce mode */ 295300282Shselasky if (priv->params_ethtool.tx_coalesce_mode != 0) 296300282Shselasky priv->params_ethtool.tx_coalesce_mode = 1; 297300282Shselasky priv->params.tx_cq_moderation_mode = 298300282Shselasky priv->params_ethtool.tx_coalesce_mode; 299300282Shselasky 300300282Shselasky /* restart network interface, if any */ 301321995Shselasky if (was_opened != 0) { 302321995Shselasky if (mode_modify == 0) 303321995Shselasky mlx5e_open_locked(priv->ifp); 304321995Shselasky else 305321995Shselasky error = mlx5e_refresh_channel_params(priv); 306321995Shselasky } 307300282Shselasky break; 308300282Shselasky 309300282Shselasky case MLX5_PARAM_OFFSET(hw_lro): 310300282Shselasky /* network interface must be down */ 311300282Shselasky if (was_opened) 312300282Shselasky mlx5e_close_locked(priv->ifp); 313300282Shselasky 314300282Shselasky /* import HW LRO mode */ 315300282Shselasky if (priv->params_ethtool.hw_lro != 0) { 316300282Shselasky if ((priv->ifp->if_capenable & IFCAP_LRO) && 317300282Shselasky MLX5_CAP_ETH(priv->mdev, lro_cap)) { 318300282Shselasky priv->params.hw_lro_en = 1; 319300282Shselasky priv->params_ethtool.hw_lro = 1; 320300282Shselasky } else { 321300282Shselasky priv->params.hw_lro_en = 0; 322300282Shselasky priv->params_ethtool.hw_lro = 0; 323300282Shselasky error = EINVAL; 324300282Shselasky 325300282Shselasky if_printf(priv->ifp, "Can't enable HW LRO: " 326300282Shselasky "The HW or SW LRO feature is disabled\n"); 327300282Shselasky } 328294319Shselasky } else { 329294319Shselasky priv->params.hw_lro_en = 0; 330291068Shselasky } 331300282Shselasky /* restart network interface, if any */ 332300282Shselasky if (was_opened) 333300282Shselasky mlx5e_open_locked(priv->ifp); 334300282Shselasky break; 335290650Shselasky 336300282Shselasky case MLX5_PARAM_OFFSET(cqe_zipping): 337300282Shselasky /* network interface must be down */ 338300282Shselasky if (was_opened) 339300282Shselasky mlx5e_close_locked(priv->ifp); 340300282Shselasky 341300282Shselasky /* import CQE zipping mode */ 342292838Shselasky if (priv->params_ethtool.cqe_zipping && 343292838Shselasky MLX5_CAP_GEN(priv->mdev, cqe_compression)) { 344292838Shselasky priv->params.cqe_zipping_en = true; 345292838Shselasky priv->params_ethtool.cqe_zipping = 1; 346292838Shselasky } else { 347292838Shselasky priv->params.cqe_zipping_en = false; 348292838Shselasky priv->params_ethtool.cqe_zipping = 0; 349292838Shselasky } 350300282Shselasky /* restart network interface, if any */ 351300282Shselasky if (was_opened) 352300282Shselasky mlx5e_open_locked(priv->ifp); 353300282Shselasky break; 354300277Shselasky 355321999Shselasky case MLX5_PARAM_OFFSET(tx_bufring_disable): 356321999Shselasky /* rangecheck input value */ 357321999Shselasky priv->params_ethtool.tx_bufring_disable = 358321999Shselasky priv->params_ethtool.tx_bufring_disable ? 1 : 0; 359321999Shselasky 360321999Shselasky /* reconfigure the sendqueues, if any */ 361321999Shselasky if (was_opened) { 362321999Shselasky mlx5e_close_locked(priv->ifp); 363321999Shselasky mlx5e_open_locked(priv->ifp); 364321999Shselasky } 365321999Shselasky break; 366321999Shselasky 367300282Shselasky case MLX5_PARAM_OFFSET(tx_completion_fact): 368300282Shselasky /* network interface must be down */ 369300282Shselasky if (was_opened) 370300282Shselasky mlx5e_close_locked(priv->ifp); 371300282Shselasky 372300277Shselasky /* verify parameter */ 373300277Shselasky mlx5e_ethtool_sync_tx_completion_fact(priv); 374300282Shselasky 375300282Shselasky /* restart network interface, if any */ 376300282Shselasky if (was_opened) 377300282Shselasky mlx5e_open_locked(priv->ifp); 378300282Shselasky break; 379300282Shselasky 380331568Shselasky case MLX5_PARAM_OFFSET(modify_tx_dma): 381331568Shselasky /* check if network interface is opened */ 382331568Shselasky if (was_opened) { 383331568Shselasky priv->params_ethtool.modify_tx_dma = 384331568Shselasky priv->params_ethtool.modify_tx_dma ? 1 : 0; 385331568Shselasky /* modify tx according to value */ 386331568Shselasky mlx5e_modify_tx_dma(priv, value != 0); 387331568Shselasky } else { 388331568Shselasky /* if closed force enable tx */ 389331568Shselasky priv->params_ethtool.modify_tx_dma = 0; 390331568Shselasky } 391331568Shselasky break; 392331568Shselasky 393331568Shselasky case MLX5_PARAM_OFFSET(modify_rx_dma): 394331568Shselasky /* check if network interface is opened */ 395331568Shselasky if (was_opened) { 396331568Shselasky priv->params_ethtool.modify_rx_dma = 397331568Shselasky priv->params_ethtool.modify_rx_dma ? 1 : 0; 398331568Shselasky /* modify rx according to value */ 399331568Shselasky mlx5e_modify_rx_dma(priv, value != 0); 400331568Shselasky } else { 401331568Shselasky /* if closed force enable rx */ 402331568Shselasky priv->params_ethtool.modify_rx_dma = 0; 403331568Shselasky } 404331568Shselasky break; 405331568Shselasky 406322006Shselasky case MLX5_PARAM_OFFSET(diag_pci_enable): 407322006Shselasky priv->params_ethtool.diag_pci_enable = 408322006Shselasky priv->params_ethtool.diag_pci_enable ? 1 : 0; 409322006Shselasky 410322006Shselasky error = -mlx5_core_set_diagnostics_full(priv->mdev, 411322006Shselasky priv->params_ethtool.diag_pci_enable, 412322006Shselasky priv->params_ethtool.diag_general_enable); 413322006Shselasky break; 414322006Shselasky 415322006Shselasky case MLX5_PARAM_OFFSET(diag_general_enable): 416322006Shselasky priv->params_ethtool.diag_general_enable = 417322006Shselasky priv->params_ethtool.diag_general_enable ? 1 : 0; 418322006Shselasky 419322006Shselasky error = -mlx5_core_set_diagnostics_full(priv->mdev, 420322006Shselasky priv->params_ethtool.diag_pci_enable, 421322006Shselasky priv->params_ethtool.diag_general_enable); 422322006Shselasky break; 423322006Shselasky 424331569Shselasky case MLX5_PARAM_OFFSET(mc_local_lb): 425331569Shselasky priv->params_ethtool.mc_local_lb = 426331569Shselasky priv->params_ethtool.mc_local_lb ? 1 : 0; 427331569Shselasky 428331569Shselasky if (MLX5_CAP_GEN(priv->mdev, disable_local_lb)) { 429331569Shselasky error = mlx5_nic_vport_modify_local_lb(priv->mdev, 430331569Shselasky MLX5_LOCAL_MC_LB, priv->params_ethtool.mc_local_lb); 431331569Shselasky } else { 432331569Shselasky error = EOPNOTSUPP; 433331569Shselasky } 434331569Shselasky break; 435331569Shselasky 436331569Shselasky case MLX5_PARAM_OFFSET(uc_local_lb): 437331569Shselasky priv->params_ethtool.uc_local_lb = 438331569Shselasky priv->params_ethtool.uc_local_lb ? 1 : 0; 439331569Shselasky 440331569Shselasky if (MLX5_CAP_GEN(priv->mdev, disable_local_lb)) { 441331569Shselasky error = mlx5_nic_vport_modify_local_lb(priv->mdev, 442331569Shselasky MLX5_LOCAL_UC_LB, priv->params_ethtool.uc_local_lb); 443331569Shselasky } else { 444331569Shselasky error = EOPNOTSUPP; 445331569Shselasky } 446331569Shselasky break; 447331569Shselasky 448300282Shselasky default: 449300282Shselasky break; 450300277Shselasky } 451290650Shselaskydone: 452290650Shselasky PRIV_UNLOCK(priv); 453290650Shselasky return (error); 454290650Shselasky} 455290650Shselasky 456290650Shselasky/* 457290650Shselasky * Read the first three bytes of the eeprom in order to get the needed info 458290650Shselasky * for the whole reading. 459290650Shselasky * Byte 0 - Identifier byte 460290650Shselasky * Byte 1 - Revision byte 461290650Shselasky * Byte 2 - Status byte 462290650Shselasky */ 463290650Shselaskystatic int 464290650Shselaskymlx5e_get_eeprom_info(struct mlx5e_priv *priv, struct mlx5e_eeprom *eeprom) 465290650Shselasky{ 466290650Shselasky struct mlx5_core_dev *dev = priv->mdev; 467290650Shselasky u32 data = 0; 468290650Shselasky int size_read = 0; 469290650Shselasky int ret; 470290650Shselasky 471290650Shselasky ret = mlx5_query_module_num(dev, &eeprom->module_num); 472290650Shselasky if (ret) { 473290650Shselasky if_printf(priv->ifp, "%s:%d: Failed query module error=%d\n", 474290650Shselasky __func__, __LINE__, ret); 475290650Shselasky return (ret); 476290650Shselasky } 477290650Shselasky 478290650Shselasky /* Read the first three bytes to get Identifier, Revision and Status */ 479290650Shselasky ret = mlx5_query_eeprom(dev, eeprom->i2c_addr, eeprom->page_num, 480290650Shselasky eeprom->device_addr, MLX5E_EEPROM_INFO_BYTES, eeprom->module_num, &data, 481290650Shselasky &size_read); 482290650Shselasky if (ret) { 483290650Shselasky if_printf(priv->ifp, "%s:%d: Failed query eeprom module error=0x%x\n", 484290650Shselasky __func__, __LINE__, ret); 485290650Shselasky return (ret); 486290650Shselasky } 487290650Shselasky 488290650Shselasky switch (data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK) { 489290650Shselasky case SFF_8024_ID_QSFP: 490290650Shselasky eeprom->type = MLX5E_ETH_MODULE_SFF_8436; 491290650Shselasky eeprom->len = MLX5E_ETH_MODULE_SFF_8436_LEN; 492290650Shselasky break; 493290650Shselasky case SFF_8024_ID_QSFPPLUS: 494290650Shselasky case SFF_8024_ID_QSFP28: 495290650Shselasky if ((data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK) == SFF_8024_ID_QSFP28 || 496291070Shselasky ((data & MLX5_EEPROM_REVISION_ID_BYTE_MASK) >> 8) >= 0x3) { 497290650Shselasky eeprom->type = MLX5E_ETH_MODULE_SFF_8636; 498290650Shselasky eeprom->len = MLX5E_ETH_MODULE_SFF_8636_LEN; 499290650Shselasky } else { 500290650Shselasky eeprom->type = MLX5E_ETH_MODULE_SFF_8436; 501290650Shselasky eeprom->len = MLX5E_ETH_MODULE_SFF_8436_LEN; 502290650Shselasky } 503290650Shselasky if ((data & MLX5_EEPROM_PAGE_3_VALID_BIT_MASK) == 0) 504290650Shselasky eeprom->page_valid = 1; 505290650Shselasky break; 506290650Shselasky case SFF_8024_ID_SFP: 507290650Shselasky eeprom->type = MLX5E_ETH_MODULE_SFF_8472; 508290650Shselasky eeprom->len = MLX5E_ETH_MODULE_SFF_8472_LEN; 509290650Shselasky break; 510290650Shselasky default: 511291067Shselasky if_printf(priv->ifp, "%s:%d: Not recognized cable type = 0x%x(%s)\n", 512291067Shselasky __func__, __LINE__, data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK, 513291067Shselasky sff_8024_id[data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK]); 514290650Shselasky return (EINVAL); 515290650Shselasky } 516290650Shselasky return (0); 517290650Shselasky} 518290650Shselasky 519290650Shselasky/* Read both low and high pages of the eeprom */ 520290650Shselaskystatic int 521290650Shselaskymlx5e_get_eeprom(struct mlx5e_priv *priv, struct mlx5e_eeprom *ee) 522290650Shselasky{ 523290650Shselasky struct mlx5_core_dev *dev = priv->mdev; 524290650Shselasky int size_read = 0; 525290650Shselasky int ret; 526290650Shselasky 527290650Shselasky if (ee->len == 0) 528290650Shselasky return (EINVAL); 529290650Shselasky 530290650Shselasky /* Read low page of the eeprom */ 531290650Shselasky while (ee->device_addr < ee->len) { 532290650Shselasky ret = mlx5_query_eeprom(dev, ee->i2c_addr, ee->page_num, ee->device_addr, 533290650Shselasky ee->len - ee->device_addr, ee->module_num, 534291070Shselasky ee->data + (ee->device_addr / 4), &size_read); 535290650Shselasky if (ret) { 536290650Shselasky if_printf(priv->ifp, "%s:%d: Failed reading eeprom, " 537290650Shselasky "error = 0x%02x\n", __func__, __LINE__, ret); 538290650Shselasky return (ret); 539290650Shselasky } 540290650Shselasky ee->device_addr += size_read; 541290650Shselasky } 542290650Shselasky 543290650Shselasky /* Read high page of the eeprom */ 544290650Shselasky if (ee->page_valid) { 545290650Shselasky ee->device_addr = MLX5E_EEPROM_HIGH_PAGE_OFFSET; 546290650Shselasky ee->page_num = MLX5E_EEPROM_HIGH_PAGE; 547290650Shselasky size_read = 0; 548290650Shselasky while (ee->device_addr < MLX5E_EEPROM_PAGE_LENGTH) { 549290650Shselasky ret = mlx5_query_eeprom(dev, ee->i2c_addr, ee->page_num, 550290650Shselasky ee->device_addr, MLX5E_EEPROM_PAGE_LENGTH - ee->device_addr, 551291070Shselasky ee->module_num, ee->data + (ee->len / 4) + 552291070Shselasky ((ee->device_addr - MLX5E_EEPROM_HIGH_PAGE_OFFSET) / 4), 553290650Shselasky &size_read); 554290650Shselasky if (ret) { 555290650Shselasky if_printf(priv->ifp, "%s:%d: Failed reading eeprom, " 556290650Shselasky "error = 0x%02x\n", __func__, __LINE__, ret); 557290650Shselasky return (ret); 558290650Shselasky } 559290650Shselasky ee->device_addr += size_read; 560290650Shselasky } 561290650Shselasky } 562290650Shselasky return (0); 563290650Shselasky} 564290650Shselasky 565290650Shselaskystatic void 566290650Shselaskymlx5e_print_eeprom(struct mlx5e_eeprom *eeprom) 567290650Shselasky{ 568292835Shselasky int row; 569292835Shselasky int index_in_row; 570292835Shselasky int byte_to_write = 0; 571292835Shselasky int line_length = 16; 572290650Shselasky 573290650Shselasky printf("\nOffset\t\tValues\n"); 574292835Shselasky printf("------\t\t------"); 575292835Shselasky while (byte_to_write < eeprom->len) { 576292835Shselasky printf("\n0x%04X\t\t", byte_to_write); 577292835Shselasky for (index_in_row = 0; index_in_row < line_length; index_in_row++) { 578292835Shselasky printf("%02X ", ((u8 *)eeprom->data)[byte_to_write]); 579292835Shselasky byte_to_write++; 580290650Shselasky } 581290650Shselasky } 582290650Shselasky 583290650Shselasky if (eeprom->page_valid) { 584290650Shselasky row = MLX5E_EEPROM_HIGH_PAGE_OFFSET; 585292835Shselasky printf("\n\nUpper Page 0x03\n"); 586290650Shselasky printf("\nOffset\t\tValues\n"); 587292835Shselasky printf("------\t\t------"); 588290650Shselasky while (row < MLX5E_EEPROM_PAGE_LENGTH) { 589292835Shselasky printf("\n0x%04X\t\t", row); 590292835Shselasky for (index_in_row = 0; index_in_row < line_length; index_in_row++) { 591292835Shselasky printf("%02X ", ((u8 *)eeprom->data)[byte_to_write]); 592292835Shselasky byte_to_write++; 593290650Shselasky row++; 594290650Shselasky } 595290650Shselasky } 596290650Shselasky } 597290650Shselasky} 598290650Shselasky 599290650Shselasky/* 600290650Shselasky * Read cable EEPROM module information by first inspecting the first 601290650Shselasky * three bytes to get the initial information for a whole reading. 602290650Shselasky * Information will be printed to dmesg. 603290650Shselasky */ 604290650Shselaskystatic int 605290650Shselaskymlx5e_read_eeprom(SYSCTL_HANDLER_ARGS) 606290650Shselasky{ 607290650Shselasky struct mlx5e_priv *priv = arg1; 608290650Shselasky struct mlx5e_eeprom eeprom; 609290650Shselasky int error; 610290650Shselasky int result = 0; 611290650Shselasky 612290650Shselasky PRIV_LOCK(priv); 613290650Shselasky error = sysctl_handle_int(oidp, &result, 0, req); 614290650Shselasky if (error || !req->newptr) 615290650Shselasky goto done; 616290650Shselasky 617290650Shselasky /* Check if device is gone */ 618290650Shselasky if (priv->gone) { 619290650Shselasky error = ENXIO; 620290650Shselasky goto done; 621290650Shselasky } 622290650Shselasky 623290650Shselasky if (result == 1) { 624290650Shselasky eeprom.i2c_addr = MLX5E_I2C_ADDR_LOW; 625290650Shselasky eeprom.device_addr = 0; 626290650Shselasky eeprom.page_num = MLX5E_EEPROM_LOW_PAGE; 627290650Shselasky eeprom.page_valid = 0; 628290650Shselasky 629290650Shselasky /* Read three first bytes to get important info */ 630290650Shselasky error = mlx5e_get_eeprom_info(priv, &eeprom); 631290650Shselasky if (error) { 632290650Shselasky if_printf(priv->ifp, "%s:%d: Failed reading eeprom's " 633290650Shselasky "initial information\n", __func__, __LINE__); 634290650Shselasky error = 0; 635290650Shselasky goto done; 636290650Shselasky } 637291070Shselasky /* 638291070Shselasky * Allocate needed length buffer and additional space for 639291070Shselasky * page 0x03 640291070Shselasky */ 641290650Shselasky eeprom.data = malloc(eeprom.len + MLX5E_EEPROM_PAGE_LENGTH, 642290650Shselasky M_MLX5EN, M_WAITOK | M_ZERO); 643290650Shselasky 644290650Shselasky /* Read the whole eeprom information */ 645290650Shselasky error = mlx5e_get_eeprom(priv, &eeprom); 646290650Shselasky if (error) { 647290650Shselasky if_printf(priv->ifp, "%s:%d: Failed reading eeprom\n", 648290650Shselasky __func__, __LINE__); 649290650Shselasky error = 0; 650291070Shselasky /* 651291070Shselasky * Continue printing partial information in case of 652291070Shselasky * an error 653291070Shselasky */ 654290650Shselasky } 655290650Shselasky mlx5e_print_eeprom(&eeprom); 656290650Shselasky free(eeprom.data, M_MLX5EN); 657290650Shselasky } 658290650Shselaskydone: 659290650Shselasky PRIV_UNLOCK(priv); 660290650Shselasky return (error); 661290650Shselasky} 662290650Shselasky 663290650Shselaskystatic const char *mlx5e_params_desc[] = { 664290650Shselasky MLX5E_PARAMS(MLX5E_STATS_DESC) 665290650Shselasky}; 666290650Shselasky 667290650Shselaskystatic const char *mlx5e_port_stats_debug_desc[] = { 668290650Shselasky MLX5E_PORT_STATS_DEBUG(MLX5E_STATS_DESC) 669290650Shselasky}; 670290650Shselasky 671290650Shselaskystatic int 672290650Shselaskymlx5e_ethtool_debug_stats(SYSCTL_HANDLER_ARGS) 673290650Shselasky{ 674290650Shselasky struct mlx5e_priv *priv = arg1; 675290650Shselasky int error; 676290650Shselasky int sys_debug; 677290650Shselasky 678290650Shselasky sys_debug = priv->sysctl_debug; 679290650Shselasky error = sysctl_handle_int(oidp, &priv->sysctl_debug, 0, req); 680290650Shselasky if (error || !req->newptr) 681290650Shselasky return (error); 682290650Shselasky priv->sysctl_debug = !!priv->sysctl_debug; 683290650Shselasky if (sys_debug == priv->sysctl_debug) 684290650Shselasky return (error); 685290650Shselasky if (priv->sysctl_debug) 686290650Shselasky mlx5e_create_stats(&priv->stats.port_stats_debug.ctx, 687290650Shselasky SYSCTL_CHILDREN(priv->sysctl_ifnet), "debug_stats", 688290650Shselasky mlx5e_port_stats_debug_desc, MLX5E_PORT_STATS_DEBUG_NUM, 689290650Shselasky priv->stats.port_stats_debug.arg); 690290650Shselasky else 691290650Shselasky sysctl_ctx_free(&priv->stats.port_stats_debug.ctx); 692290650Shselasky return (error); 693290650Shselasky} 694290650Shselasky 695322006Shselaskystatic void 696322006Shselaskymlx5e_create_diagnostics(struct mlx5e_priv *priv) 697322006Shselasky{ 698322006Shselasky struct mlx5_core_diagnostics_entry entry; 699322006Shselasky struct sysctl_ctx_list *ctx; 700322006Shselasky struct sysctl_oid *node; 701322006Shselasky int x; 702322006Shselasky 703322006Shselasky /* sysctl context we are using */ 704322006Shselasky ctx = &priv->sysctl_ctx; 705322006Shselasky 706322006Shselasky /* create root node */ 707322006Shselasky node = SYSCTL_ADD_NODE(ctx, 708322006Shselasky SYSCTL_CHILDREN(priv->sysctl_ifnet), OID_AUTO, 709322006Shselasky "diagnostics", CTLFLAG_RD, NULL, "Diagnostics"); 710322006Shselasky if (node == NULL) 711322006Shselasky return; 712322006Shselasky 713322006Shselasky /* create PCI diagnostics */ 714322006Shselasky for (x = 0; x != MLX5_CORE_PCI_DIAGNOSTICS_NUM; x++) { 715322006Shselasky entry = mlx5_core_pci_diagnostics_table[x]; 716322006Shselasky if (mlx5_core_supports_diagnostics(priv->mdev, entry.counter_id) == 0) 717322006Shselasky continue; 718322006Shselasky SYSCTL_ADD_UQUAD(ctx, SYSCTL_CHILDREN(node), OID_AUTO, 719322006Shselasky entry.desc, CTLFLAG_RD, priv->params_pci.array + x, 720322006Shselasky "PCI diagnostics counter"); 721322006Shselasky } 722322006Shselasky 723322006Shselasky /* create general diagnostics */ 724322006Shselasky for (x = 0; x != MLX5_CORE_GENERAL_DIAGNOSTICS_NUM; x++) { 725322006Shselasky entry = mlx5_core_general_diagnostics_table[x]; 726322006Shselasky if (mlx5_core_supports_diagnostics(priv->mdev, entry.counter_id) == 0) 727322006Shselasky continue; 728322006Shselasky SYSCTL_ADD_UQUAD(ctx, SYSCTL_CHILDREN(node), OID_AUTO, 729322006Shselasky entry.desc, CTLFLAG_RD, priv->params_general.array + x, 730322006Shselasky "General diagnostics counter"); 731322006Shselasky } 732322006Shselasky} 733322006Shselasky 734290650Shselaskyvoid 735290650Shselaskymlx5e_create_ethtool(struct mlx5e_priv *priv) 736290650Shselasky{ 737290650Shselasky struct sysctl_oid *node; 738290650Shselasky const char *pnameunit; 739290650Shselasky unsigned x; 740290650Shselasky 741290650Shselasky /* set some defaults */ 742290650Shselasky priv->params_ethtool.tx_queue_size_max = 1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE; 743290650Shselasky priv->params_ethtool.rx_queue_size_max = 1 << MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE; 744290650Shselasky priv->params_ethtool.tx_queue_size = 1 << priv->params.log_sq_size; 745290650Shselasky priv->params_ethtool.rx_queue_size = 1 << priv->params.log_rq_size; 746290650Shselasky priv->params_ethtool.channels = priv->params.num_channels; 747290650Shselasky priv->params_ethtool.coalesce_pkts_max = MLX5E_FLD_MAX(cqc, cq_max_count); 748290650Shselasky priv->params_ethtool.coalesce_usecs_max = MLX5E_FLD_MAX(cqc, cq_period); 749290650Shselasky priv->params_ethtool.rx_coalesce_mode = priv->params.rx_cq_moderation_mode; 750290650Shselasky priv->params_ethtool.rx_coalesce_usecs = priv->params.rx_cq_moderation_usec; 751290650Shselasky priv->params_ethtool.rx_coalesce_pkts = priv->params.rx_cq_moderation_pkts; 752291932Shselasky priv->params_ethtool.tx_coalesce_mode = priv->params.tx_cq_moderation_mode; 753290650Shselasky priv->params_ethtool.tx_coalesce_usecs = priv->params.tx_cq_moderation_usec; 754290650Shselasky priv->params_ethtool.tx_coalesce_pkts = priv->params.tx_cq_moderation_pkts; 755290650Shselasky priv->params_ethtool.hw_lro = priv->params.hw_lro_en; 756292838Shselasky priv->params_ethtool.cqe_zipping = priv->params.cqe_zipping_en; 757300277Shselasky mlx5e_ethtool_sync_tx_completion_fact(priv); 758290650Shselasky 759331569Shselasky /* get default values for local loopback, if any */ 760331569Shselasky if (MLX5_CAP_GEN(priv->mdev, disable_local_lb)) { 761331569Shselasky int err; 762331569Shselasky u8 val; 763331569Shselasky 764331569Shselasky err = mlx5_nic_vport_query_local_lb(priv->mdev, MLX5_LOCAL_MC_LB, &val); 765331569Shselasky if (err == 0) 766331569Shselasky priv->params_ethtool.mc_local_lb = val; 767331569Shselasky 768331569Shselasky err = mlx5_nic_vport_query_local_lb(priv->mdev, MLX5_LOCAL_UC_LB, &val); 769331569Shselasky if (err == 0) 770331569Shselasky priv->params_ethtool.uc_local_lb = val; 771331569Shselasky } 772331569Shselasky 773290650Shselasky /* create root node */ 774290650Shselasky node = SYSCTL_ADD_NODE(&priv->sysctl_ctx, 775290650Shselasky SYSCTL_CHILDREN(priv->sysctl_ifnet), OID_AUTO, 776290650Shselasky "conf", CTLFLAG_RW, NULL, "Configuration"); 777290650Shselasky if (node == NULL) 778290650Shselasky return; 779290650Shselasky for (x = 0; x != MLX5E_PARAMS_NUM; x++) { 780290650Shselasky /* check for read-only parameter */ 781331570Shselasky if (strstr(mlx5e_params_desc[2 * x], "_max") != NULL || 782331570Shselasky strstr(mlx5e_params_desc[2 * x], "_mtu") != NULL) { 783290650Shselasky SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO, 784290650Shselasky mlx5e_params_desc[2 * x], CTLTYPE_U64 | CTLFLAG_RD | 785290650Shselasky CTLFLAG_MPSAFE, priv, x, &mlx5e_ethtool_handler, "QU", 786290650Shselasky mlx5e_params_desc[2 * x + 1]); 787290650Shselasky } else { 788292837Shselasky#if (__FreeBSD_version < 1100000) 789292837Shselasky char path[64]; 790292837Shselasky#endif 791292837Shselasky /* 792292837Shselasky * NOTE: In FreeBSD-11 and newer the 793292837Shselasky * CTLFLAG_RWTUN flag will take care of 794292837Shselasky * loading default sysctl value from the 795292837Shselasky * kernel environment, if any: 796292837Shselasky */ 797290650Shselasky SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO, 798290650Shselasky mlx5e_params_desc[2 * x], CTLTYPE_U64 | CTLFLAG_RWTUN | 799290650Shselasky CTLFLAG_MPSAFE, priv, x, &mlx5e_ethtool_handler, "QU", 800290650Shselasky mlx5e_params_desc[2 * x + 1]); 801292837Shselasky 802292837Shselasky#if (__FreeBSD_version < 1100000) 803292837Shselasky /* compute path for sysctl */ 804292837Shselasky snprintf(path, sizeof(path), "dev.mce.%d.conf.%s", 805292837Shselasky device_get_unit(priv->mdev->pdev->dev.bsddev), 806292837Shselasky mlx5e_params_desc[2 * x]); 807292837Shselasky 808292837Shselasky /* try to fetch tunable, if any */ 809292837Shselasky if (TUNABLE_QUAD_FETCH(path, &priv->params_ethtool.arg[x])) 810292837Shselasky mlx5e_ethtool_handler(NULL, priv, x, NULL); 811292837Shselasky#endif 812290650Shselasky } 813290650Shselasky } 814290650Shselasky 815290650Shselasky SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO, 816290650Shselasky "debug_stats", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv, 817290650Shselasky 0, &mlx5e_ethtool_debug_stats, "I", "Extended debug statistics"); 818290650Shselasky 819290650Shselasky pnameunit = device_get_nameunit(priv->mdev->pdev->dev.bsddev); 820290650Shselasky 821290650Shselasky SYSCTL_ADD_STRING(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), 822290650Shselasky OID_AUTO, "device_name", CTLFLAG_RD, 823290650Shselasky __DECONST(void *, pnameunit), 0, 824290650Shselasky "PCI device name"); 825290650Shselasky 826290650Shselasky /* EEPROM support */ 827290650Shselasky SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO, "eeprom_info", 828290650Shselasky CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv, 0, 829290650Shselasky mlx5e_read_eeprom, "I", "EEPROM information"); 830322006Shselasky 831322006Shselasky /* Diagnostics support */ 832322006Shselasky mlx5e_create_diagnostics(priv); 833290650Shselasky} 834