mlx5_en_ethtool.c revision 322006
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 322006 2017-08-03 14:12:23Z 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 380322006Shselasky case MLX5_PARAM_OFFSET(diag_pci_enable): 381322006Shselasky priv->params_ethtool.diag_pci_enable = 382322006Shselasky priv->params_ethtool.diag_pci_enable ? 1 : 0; 383322006Shselasky 384322006Shselasky error = -mlx5_core_set_diagnostics_full(priv->mdev, 385322006Shselasky priv->params_ethtool.diag_pci_enable, 386322006Shselasky priv->params_ethtool.diag_general_enable); 387322006Shselasky break; 388322006Shselasky 389322006Shselasky case MLX5_PARAM_OFFSET(diag_general_enable): 390322006Shselasky priv->params_ethtool.diag_general_enable = 391322006Shselasky priv->params_ethtool.diag_general_enable ? 1 : 0; 392322006Shselasky 393322006Shselasky error = -mlx5_core_set_diagnostics_full(priv->mdev, 394322006Shselasky priv->params_ethtool.diag_pci_enable, 395322006Shselasky priv->params_ethtool.diag_general_enable); 396322006Shselasky break; 397322006Shselasky 398300282Shselasky default: 399300282Shselasky break; 400300277Shselasky } 401290650Shselaskydone: 402290650Shselasky PRIV_UNLOCK(priv); 403290650Shselasky return (error); 404290650Shselasky} 405290650Shselasky 406290650Shselasky/* 407290650Shselasky * Read the first three bytes of the eeprom in order to get the needed info 408290650Shselasky * for the whole reading. 409290650Shselasky * Byte 0 - Identifier byte 410290650Shselasky * Byte 1 - Revision byte 411290650Shselasky * Byte 2 - Status byte 412290650Shselasky */ 413290650Shselaskystatic int 414290650Shselaskymlx5e_get_eeprom_info(struct mlx5e_priv *priv, struct mlx5e_eeprom *eeprom) 415290650Shselasky{ 416290650Shselasky struct mlx5_core_dev *dev = priv->mdev; 417290650Shselasky u32 data = 0; 418290650Shselasky int size_read = 0; 419290650Shselasky int ret; 420290650Shselasky 421290650Shselasky ret = mlx5_query_module_num(dev, &eeprom->module_num); 422290650Shselasky if (ret) { 423290650Shselasky if_printf(priv->ifp, "%s:%d: Failed query module error=%d\n", 424290650Shselasky __func__, __LINE__, ret); 425290650Shselasky return (ret); 426290650Shselasky } 427290650Shselasky 428290650Shselasky /* Read the first three bytes to get Identifier, Revision and Status */ 429290650Shselasky ret = mlx5_query_eeprom(dev, eeprom->i2c_addr, eeprom->page_num, 430290650Shselasky eeprom->device_addr, MLX5E_EEPROM_INFO_BYTES, eeprom->module_num, &data, 431290650Shselasky &size_read); 432290650Shselasky if (ret) { 433290650Shselasky if_printf(priv->ifp, "%s:%d: Failed query eeprom module error=0x%x\n", 434290650Shselasky __func__, __LINE__, ret); 435290650Shselasky return (ret); 436290650Shselasky } 437290650Shselasky 438290650Shselasky switch (data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK) { 439290650Shselasky case SFF_8024_ID_QSFP: 440290650Shselasky eeprom->type = MLX5E_ETH_MODULE_SFF_8436; 441290650Shselasky eeprom->len = MLX5E_ETH_MODULE_SFF_8436_LEN; 442290650Shselasky break; 443290650Shselasky case SFF_8024_ID_QSFPPLUS: 444290650Shselasky case SFF_8024_ID_QSFP28: 445290650Shselasky if ((data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK) == SFF_8024_ID_QSFP28 || 446291070Shselasky ((data & MLX5_EEPROM_REVISION_ID_BYTE_MASK) >> 8) >= 0x3) { 447290650Shselasky eeprom->type = MLX5E_ETH_MODULE_SFF_8636; 448290650Shselasky eeprom->len = MLX5E_ETH_MODULE_SFF_8636_LEN; 449290650Shselasky } else { 450290650Shselasky eeprom->type = MLX5E_ETH_MODULE_SFF_8436; 451290650Shselasky eeprom->len = MLX5E_ETH_MODULE_SFF_8436_LEN; 452290650Shselasky } 453290650Shselasky if ((data & MLX5_EEPROM_PAGE_3_VALID_BIT_MASK) == 0) 454290650Shselasky eeprom->page_valid = 1; 455290650Shselasky break; 456290650Shselasky case SFF_8024_ID_SFP: 457290650Shselasky eeprom->type = MLX5E_ETH_MODULE_SFF_8472; 458290650Shselasky eeprom->len = MLX5E_ETH_MODULE_SFF_8472_LEN; 459290650Shselasky break; 460290650Shselasky default: 461291067Shselasky if_printf(priv->ifp, "%s:%d: Not recognized cable type = 0x%x(%s)\n", 462291067Shselasky __func__, __LINE__, data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK, 463291067Shselasky sff_8024_id[data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK]); 464290650Shselasky return (EINVAL); 465290650Shselasky } 466290650Shselasky return (0); 467290650Shselasky} 468290650Shselasky 469290650Shselasky/* Read both low and high pages of the eeprom */ 470290650Shselaskystatic int 471290650Shselaskymlx5e_get_eeprom(struct mlx5e_priv *priv, struct mlx5e_eeprom *ee) 472290650Shselasky{ 473290650Shselasky struct mlx5_core_dev *dev = priv->mdev; 474290650Shselasky int size_read = 0; 475290650Shselasky int ret; 476290650Shselasky 477290650Shselasky if (ee->len == 0) 478290650Shselasky return (EINVAL); 479290650Shselasky 480290650Shselasky /* Read low page of the eeprom */ 481290650Shselasky while (ee->device_addr < ee->len) { 482290650Shselasky ret = mlx5_query_eeprom(dev, ee->i2c_addr, ee->page_num, ee->device_addr, 483290650Shselasky ee->len - ee->device_addr, ee->module_num, 484291070Shselasky ee->data + (ee->device_addr / 4), &size_read); 485290650Shselasky if (ret) { 486290650Shselasky if_printf(priv->ifp, "%s:%d: Failed reading eeprom, " 487290650Shselasky "error = 0x%02x\n", __func__, __LINE__, ret); 488290650Shselasky return (ret); 489290650Shselasky } 490290650Shselasky ee->device_addr += size_read; 491290650Shselasky } 492290650Shselasky 493290650Shselasky /* Read high page of the eeprom */ 494290650Shselasky if (ee->page_valid) { 495290650Shselasky ee->device_addr = MLX5E_EEPROM_HIGH_PAGE_OFFSET; 496290650Shselasky ee->page_num = MLX5E_EEPROM_HIGH_PAGE; 497290650Shselasky size_read = 0; 498290650Shselasky while (ee->device_addr < MLX5E_EEPROM_PAGE_LENGTH) { 499290650Shselasky ret = mlx5_query_eeprom(dev, ee->i2c_addr, ee->page_num, 500290650Shselasky ee->device_addr, MLX5E_EEPROM_PAGE_LENGTH - ee->device_addr, 501291070Shselasky ee->module_num, ee->data + (ee->len / 4) + 502291070Shselasky ((ee->device_addr - MLX5E_EEPROM_HIGH_PAGE_OFFSET) / 4), 503290650Shselasky &size_read); 504290650Shselasky if (ret) { 505290650Shselasky if_printf(priv->ifp, "%s:%d: Failed reading eeprom, " 506290650Shselasky "error = 0x%02x\n", __func__, __LINE__, ret); 507290650Shselasky return (ret); 508290650Shselasky } 509290650Shselasky ee->device_addr += size_read; 510290650Shselasky } 511290650Shselasky } 512290650Shselasky return (0); 513290650Shselasky} 514290650Shselasky 515290650Shselaskystatic void 516290650Shselaskymlx5e_print_eeprom(struct mlx5e_eeprom *eeprom) 517290650Shselasky{ 518292835Shselasky int row; 519292835Shselasky int index_in_row; 520292835Shselasky int byte_to_write = 0; 521292835Shselasky int line_length = 16; 522290650Shselasky 523290650Shselasky printf("\nOffset\t\tValues\n"); 524292835Shselasky printf("------\t\t------"); 525292835Shselasky while (byte_to_write < eeprom->len) { 526292835Shselasky printf("\n0x%04X\t\t", byte_to_write); 527292835Shselasky for (index_in_row = 0; index_in_row < line_length; index_in_row++) { 528292835Shselasky printf("%02X ", ((u8 *)eeprom->data)[byte_to_write]); 529292835Shselasky byte_to_write++; 530290650Shselasky } 531290650Shselasky } 532290650Shselasky 533290650Shselasky if (eeprom->page_valid) { 534290650Shselasky row = MLX5E_EEPROM_HIGH_PAGE_OFFSET; 535292835Shselasky printf("\n\nUpper Page 0x03\n"); 536290650Shselasky printf("\nOffset\t\tValues\n"); 537292835Shselasky printf("------\t\t------"); 538290650Shselasky while (row < MLX5E_EEPROM_PAGE_LENGTH) { 539292835Shselasky printf("\n0x%04X\t\t", row); 540292835Shselasky for (index_in_row = 0; index_in_row < line_length; index_in_row++) { 541292835Shselasky printf("%02X ", ((u8 *)eeprom->data)[byte_to_write]); 542292835Shselasky byte_to_write++; 543290650Shselasky row++; 544290650Shselasky } 545290650Shselasky } 546290650Shselasky } 547290650Shselasky} 548290650Shselasky 549290650Shselasky/* 550290650Shselasky * Read cable EEPROM module information by first inspecting the first 551290650Shselasky * three bytes to get the initial information for a whole reading. 552290650Shselasky * Information will be printed to dmesg. 553290650Shselasky */ 554290650Shselaskystatic int 555290650Shselaskymlx5e_read_eeprom(SYSCTL_HANDLER_ARGS) 556290650Shselasky{ 557290650Shselasky struct mlx5e_priv *priv = arg1; 558290650Shselasky struct mlx5e_eeprom eeprom; 559290650Shselasky int error; 560290650Shselasky int result = 0; 561290650Shselasky 562290650Shselasky PRIV_LOCK(priv); 563290650Shselasky error = sysctl_handle_int(oidp, &result, 0, req); 564290650Shselasky if (error || !req->newptr) 565290650Shselasky goto done; 566290650Shselasky 567290650Shselasky /* Check if device is gone */ 568290650Shselasky if (priv->gone) { 569290650Shselasky error = ENXIO; 570290650Shselasky goto done; 571290650Shselasky } 572290650Shselasky 573290650Shselasky if (result == 1) { 574290650Shselasky eeprom.i2c_addr = MLX5E_I2C_ADDR_LOW; 575290650Shselasky eeprom.device_addr = 0; 576290650Shselasky eeprom.page_num = MLX5E_EEPROM_LOW_PAGE; 577290650Shselasky eeprom.page_valid = 0; 578290650Shselasky 579290650Shselasky /* Read three first bytes to get important info */ 580290650Shselasky error = mlx5e_get_eeprom_info(priv, &eeprom); 581290650Shselasky if (error) { 582290650Shselasky if_printf(priv->ifp, "%s:%d: Failed reading eeprom's " 583290650Shselasky "initial information\n", __func__, __LINE__); 584290650Shselasky error = 0; 585290650Shselasky goto done; 586290650Shselasky } 587291070Shselasky /* 588291070Shselasky * Allocate needed length buffer and additional space for 589291070Shselasky * page 0x03 590291070Shselasky */ 591290650Shselasky eeprom.data = malloc(eeprom.len + MLX5E_EEPROM_PAGE_LENGTH, 592290650Shselasky M_MLX5EN, M_WAITOK | M_ZERO); 593290650Shselasky 594290650Shselasky /* Read the whole eeprom information */ 595290650Shselasky error = mlx5e_get_eeprom(priv, &eeprom); 596290650Shselasky if (error) { 597290650Shselasky if_printf(priv->ifp, "%s:%d: Failed reading eeprom\n", 598290650Shselasky __func__, __LINE__); 599290650Shselasky error = 0; 600291070Shselasky /* 601291070Shselasky * Continue printing partial information in case of 602291070Shselasky * an error 603291070Shselasky */ 604290650Shselasky } 605290650Shselasky mlx5e_print_eeprom(&eeprom); 606290650Shselasky free(eeprom.data, M_MLX5EN); 607290650Shselasky } 608290650Shselaskydone: 609290650Shselasky PRIV_UNLOCK(priv); 610290650Shselasky return (error); 611290650Shselasky} 612290650Shselasky 613290650Shselaskystatic const char *mlx5e_params_desc[] = { 614290650Shselasky MLX5E_PARAMS(MLX5E_STATS_DESC) 615290650Shselasky}; 616290650Shselasky 617290650Shselaskystatic const char *mlx5e_port_stats_debug_desc[] = { 618290650Shselasky MLX5E_PORT_STATS_DEBUG(MLX5E_STATS_DESC) 619290650Shselasky}; 620290650Shselasky 621290650Shselaskystatic int 622290650Shselaskymlx5e_ethtool_debug_stats(SYSCTL_HANDLER_ARGS) 623290650Shselasky{ 624290650Shselasky struct mlx5e_priv *priv = arg1; 625290650Shselasky int error; 626290650Shselasky int sys_debug; 627290650Shselasky 628290650Shselasky sys_debug = priv->sysctl_debug; 629290650Shselasky error = sysctl_handle_int(oidp, &priv->sysctl_debug, 0, req); 630290650Shselasky if (error || !req->newptr) 631290650Shselasky return (error); 632290650Shselasky priv->sysctl_debug = !!priv->sysctl_debug; 633290650Shselasky if (sys_debug == priv->sysctl_debug) 634290650Shselasky return (error); 635290650Shselasky if (priv->sysctl_debug) 636290650Shselasky mlx5e_create_stats(&priv->stats.port_stats_debug.ctx, 637290650Shselasky SYSCTL_CHILDREN(priv->sysctl_ifnet), "debug_stats", 638290650Shselasky mlx5e_port_stats_debug_desc, MLX5E_PORT_STATS_DEBUG_NUM, 639290650Shselasky priv->stats.port_stats_debug.arg); 640290650Shselasky else 641290650Shselasky sysctl_ctx_free(&priv->stats.port_stats_debug.ctx); 642290650Shselasky return (error); 643290650Shselasky} 644290650Shselasky 645322006Shselaskystatic void 646322006Shselaskymlx5e_create_diagnostics(struct mlx5e_priv *priv) 647322006Shselasky{ 648322006Shselasky struct mlx5_core_diagnostics_entry entry; 649322006Shselasky struct sysctl_ctx_list *ctx; 650322006Shselasky struct sysctl_oid *node; 651322006Shselasky int x; 652322006Shselasky 653322006Shselasky /* sysctl context we are using */ 654322006Shselasky ctx = &priv->sysctl_ctx; 655322006Shselasky 656322006Shselasky /* create root node */ 657322006Shselasky node = SYSCTL_ADD_NODE(ctx, 658322006Shselasky SYSCTL_CHILDREN(priv->sysctl_ifnet), OID_AUTO, 659322006Shselasky "diagnostics", CTLFLAG_RD, NULL, "Diagnostics"); 660322006Shselasky if (node == NULL) 661322006Shselasky return; 662322006Shselasky 663322006Shselasky /* create PCI diagnostics */ 664322006Shselasky for (x = 0; x != MLX5_CORE_PCI_DIAGNOSTICS_NUM; x++) { 665322006Shselasky entry = mlx5_core_pci_diagnostics_table[x]; 666322006Shselasky if (mlx5_core_supports_diagnostics(priv->mdev, entry.counter_id) == 0) 667322006Shselasky continue; 668322006Shselasky SYSCTL_ADD_UQUAD(ctx, SYSCTL_CHILDREN(node), OID_AUTO, 669322006Shselasky entry.desc, CTLFLAG_RD, priv->params_pci.array + x, 670322006Shselasky "PCI diagnostics counter"); 671322006Shselasky } 672322006Shselasky 673322006Shselasky /* create general diagnostics */ 674322006Shselasky for (x = 0; x != MLX5_CORE_GENERAL_DIAGNOSTICS_NUM; x++) { 675322006Shselasky entry = mlx5_core_general_diagnostics_table[x]; 676322006Shselasky if (mlx5_core_supports_diagnostics(priv->mdev, entry.counter_id) == 0) 677322006Shselasky continue; 678322006Shselasky SYSCTL_ADD_UQUAD(ctx, SYSCTL_CHILDREN(node), OID_AUTO, 679322006Shselasky entry.desc, CTLFLAG_RD, priv->params_general.array + x, 680322006Shselasky "General diagnostics counter"); 681322006Shselasky } 682322006Shselasky} 683322006Shselasky 684290650Shselaskyvoid 685290650Shselaskymlx5e_create_ethtool(struct mlx5e_priv *priv) 686290650Shselasky{ 687290650Shselasky struct sysctl_oid *node; 688290650Shselasky const char *pnameunit; 689290650Shselasky unsigned x; 690290650Shselasky 691290650Shselasky /* set some defaults */ 692290650Shselasky priv->params_ethtool.tx_queue_size_max = 1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE; 693290650Shselasky priv->params_ethtool.rx_queue_size_max = 1 << MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE; 694290650Shselasky priv->params_ethtool.tx_queue_size = 1 << priv->params.log_sq_size; 695290650Shselasky priv->params_ethtool.rx_queue_size = 1 << priv->params.log_rq_size; 696290650Shselasky priv->params_ethtool.channels = priv->params.num_channels; 697290650Shselasky priv->params_ethtool.coalesce_pkts_max = MLX5E_FLD_MAX(cqc, cq_max_count); 698290650Shselasky priv->params_ethtool.coalesce_usecs_max = MLX5E_FLD_MAX(cqc, cq_period); 699290650Shselasky priv->params_ethtool.rx_coalesce_mode = priv->params.rx_cq_moderation_mode; 700290650Shselasky priv->params_ethtool.rx_coalesce_usecs = priv->params.rx_cq_moderation_usec; 701290650Shselasky priv->params_ethtool.rx_coalesce_pkts = priv->params.rx_cq_moderation_pkts; 702291932Shselasky priv->params_ethtool.tx_coalesce_mode = priv->params.tx_cq_moderation_mode; 703290650Shselasky priv->params_ethtool.tx_coalesce_usecs = priv->params.tx_cq_moderation_usec; 704290650Shselasky priv->params_ethtool.tx_coalesce_pkts = priv->params.tx_cq_moderation_pkts; 705290650Shselasky priv->params_ethtool.hw_lro = priv->params.hw_lro_en; 706292838Shselasky priv->params_ethtool.cqe_zipping = priv->params.cqe_zipping_en; 707300277Shselasky mlx5e_ethtool_sync_tx_completion_fact(priv); 708290650Shselasky 709290650Shselasky /* create root node */ 710290650Shselasky node = SYSCTL_ADD_NODE(&priv->sysctl_ctx, 711290650Shselasky SYSCTL_CHILDREN(priv->sysctl_ifnet), OID_AUTO, 712290650Shselasky "conf", CTLFLAG_RW, NULL, "Configuration"); 713290650Shselasky if (node == NULL) 714290650Shselasky return; 715290650Shselasky for (x = 0; x != MLX5E_PARAMS_NUM; x++) { 716290650Shselasky /* check for read-only parameter */ 717290650Shselasky if (strstr(mlx5e_params_desc[2 * x], "_max") != NULL) { 718290650Shselasky SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO, 719290650Shselasky mlx5e_params_desc[2 * x], CTLTYPE_U64 | CTLFLAG_RD | 720290650Shselasky CTLFLAG_MPSAFE, priv, x, &mlx5e_ethtool_handler, "QU", 721290650Shselasky mlx5e_params_desc[2 * x + 1]); 722290650Shselasky } else { 723292837Shselasky#if (__FreeBSD_version < 1100000) 724292837Shselasky char path[64]; 725292837Shselasky#endif 726292837Shselasky /* 727292837Shselasky * NOTE: In FreeBSD-11 and newer the 728292837Shselasky * CTLFLAG_RWTUN flag will take care of 729292837Shselasky * loading default sysctl value from the 730292837Shselasky * kernel environment, if any: 731292837Shselasky */ 732290650Shselasky SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO, 733290650Shselasky mlx5e_params_desc[2 * x], CTLTYPE_U64 | CTLFLAG_RWTUN | 734290650Shselasky CTLFLAG_MPSAFE, priv, x, &mlx5e_ethtool_handler, "QU", 735290650Shselasky mlx5e_params_desc[2 * x + 1]); 736292837Shselasky 737292837Shselasky#if (__FreeBSD_version < 1100000) 738292837Shselasky /* compute path for sysctl */ 739292837Shselasky snprintf(path, sizeof(path), "dev.mce.%d.conf.%s", 740292837Shselasky device_get_unit(priv->mdev->pdev->dev.bsddev), 741292837Shselasky mlx5e_params_desc[2 * x]); 742292837Shselasky 743292837Shselasky /* try to fetch tunable, if any */ 744292837Shselasky if (TUNABLE_QUAD_FETCH(path, &priv->params_ethtool.arg[x])) 745292837Shselasky mlx5e_ethtool_handler(NULL, priv, x, NULL); 746292837Shselasky#endif 747290650Shselasky } 748290650Shselasky } 749290650Shselasky 750290650Shselasky SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO, 751290650Shselasky "debug_stats", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv, 752290650Shselasky 0, &mlx5e_ethtool_debug_stats, "I", "Extended debug statistics"); 753290650Shselasky 754290650Shselasky pnameunit = device_get_nameunit(priv->mdev->pdev->dev.bsddev); 755290650Shselasky 756290650Shselasky SYSCTL_ADD_STRING(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), 757290650Shselasky OID_AUTO, "device_name", CTLFLAG_RD, 758290650Shselasky __DECONST(void *, pnameunit), 0, 759290650Shselasky "PCI device name"); 760290650Shselasky 761290650Shselasky /* EEPROM support */ 762290650Shselasky SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO, "eeprom_info", 763290650Shselasky CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv, 0, 764290650Shselasky mlx5e_read_eeprom, "I", "EEPROM information"); 765322006Shselasky 766322006Shselasky /* Diagnostics support */ 767322006Shselasky mlx5e_create_diagnostics(priv); 768290650Shselasky} 769