2 * Copyright (c) 2015 Mellanox Technologies. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <net/sff8472.h>
32 mlx5e_create_stats(struct sysctl_ctx_list *ctx,
33 struct sysctl_oid_list *parent, const char *buffer,
34 const char **desc, unsigned num, u64 * arg)
36 struct sysctl_oid *node;
41 node = SYSCTL_ADD_NODE(ctx, parent, OID_AUTO,
42 buffer, CTLFLAG_RD, NULL, "Statistics");
45 for (x = 0; x != num; x++) {
46 SYSCTL_ADD_UQUAD(ctx, SYSCTL_CHILDREN(node), OID_AUTO,
47 desc[2 * x], CTLFLAG_RD, arg + x, desc[2 * x + 1]);
52 mlx5e_ethtool_sync_tx_completion_fact(struct mlx5e_priv *priv)
55 * Limit the maximum distance between completion events to
56 * half of the currently set TX queue size.
58 * The maximum number of queue entries a single IP packet can
59 * consume is given by MLX5_SEND_WQE_MAX_WQEBBS.
61 * The worst case max value is then given as below:
63 uint64_t max = priv->params_ethtool.tx_queue_size /
64 (2 * MLX5_SEND_WQE_MAX_WQEBBS);
67 * Update the maximum completion factor value in case the
68 * tx_queue_size field changed. Ensure we don't overflow
75 priv->params_ethtool.tx_completion_fact_max = max;
78 * Verify that the current TX completion factor is within the
81 if (priv->params_ethtool.tx_completion_fact < 1)
82 priv->params_ethtool.tx_completion_fact = 1;
83 else if (priv->params_ethtool.tx_completion_fact > max)
84 priv->params_ethtool.tx_completion_fact = max;
88 mlx5e_getmaxrate(struct mlx5e_priv *priv)
90 struct mlx5_core_dev *mdev = priv->mdev;
91 u8 max_bw_unit[IEEE_8021QAZ_MAX_TCS];
92 u8 max_bw_value[IEEE_8021QAZ_MAX_TCS];
97 err = -mlx5_query_port_tc_rate_limit(mdev, max_bw_value, max_bw_unit);
101 for (i = 0; i <= mlx5_max_tc(mdev); i++) {
102 switch (max_bw_unit[i]) {
103 case MLX5_100_MBPS_UNIT:
104 priv->params_ethtool.max_bw_value[i] = max_bw_value[i] * MLX5E_100MB;
107 priv->params_ethtool.max_bw_value[i] = max_bw_value[i] * MLX5E_1GB;
109 case MLX5_BW_NO_LIMIT:
110 priv->params_ethtool.max_bw_value[i] = 0;
113 priv->params_ethtool.max_bw_value[i] = -1;
114 WARN_ONCE(true, "non-supported BW unit");
124 mlx5e_get_dscp(struct mlx5e_priv *priv)
126 struct mlx5_core_dev *mdev = priv->mdev;
129 if (MLX5_CAP_GEN(mdev, qcam_reg) == 0 ||
130 MLX5_CAP_QCAM_REG(mdev, qpts) == 0 ||
131 MLX5_CAP_QCAM_REG(mdev, qpdpm) == 0)
135 err = -mlx5_query_dscp2prio(mdev, priv->params_ethtool.dscp2prio);
139 err = -mlx5_query_trust_state(mdev, &priv->params_ethtool.trust_state);
148 mlx5e_tc_maxrate_handler(SYSCTL_HANDLER_ARGS)
150 struct mlx5e_priv *priv = arg1;
151 int prio_index = arg2;
152 struct mlx5_core_dev *mdev = priv->mdev;
153 u8 max_bw_unit[IEEE_8021QAZ_MAX_TCS];
154 u8 max_bw_value[IEEE_8021QAZ_MAX_TCS];
157 u64 result = priv->params_ethtool.max_bw_value[prio_index];
158 const u64 upper_limit_mbps = 255 * MLX5E_100MB;
159 const u64 upper_limit_gbps = 255 * MLX5E_1GB;
162 err = sysctl_handle_64(oidp, &result, 0, req);
163 if (err || !req->newptr ||
164 result == priv->params_ethtool.max_bw_value[prio_index])
167 if (result % MLX5E_100MB) {
172 memset(max_bw_value, 0, sizeof(max_bw_value));
173 memset(max_bw_unit, 0, sizeof(max_bw_unit));
175 for (i = 0; i <= mlx5_max_tc(mdev); i++) {
176 bw_val = (i == prio_index) ? result : priv->params_ethtool.max_bw_value[i];
179 max_bw_unit[i] = MLX5_BW_NO_LIMIT;
180 } else if (bw_val > upper_limit_gbps) {
182 max_bw_unit[i] = MLX5_BW_NO_LIMIT;
183 } else if (bw_val <= upper_limit_mbps) {
184 max_bw_value[i] = howmany(bw_val, MLX5E_100MB);
185 max_bw_unit[i] = MLX5_100_MBPS_UNIT;
187 max_bw_value[i] = howmany(bw_val, MLX5E_1GB);
188 max_bw_unit[i] = MLX5_GBPS_UNIT;
192 err = -mlx5_modify_port_tc_rate_limit(mdev, max_bw_value, max_bw_unit);
196 priv->params_ethtool.max_bw_value[prio_index] = result;
203 mlx5e_get_prio_tc(struct mlx5e_priv *priv)
205 struct mlx5_core_dev *mdev = priv->mdev;
210 if (!MLX5_CAP_GEN(priv->mdev, ets)) {
215 for (i = 0; i <= mlx5_max_tc(priv->mdev); i++) {
216 err = -mlx5_query_port_prio_tc(mdev, i, &(priv->params_ethtool.prio_tc[i]));
226 mlx5e_prio_to_tc_handler(SYSCTL_HANDLER_ARGS)
228 struct mlx5e_priv *priv = arg1;
229 int prio_index = arg2;
230 struct mlx5_core_dev *mdev = priv->mdev;
232 uint8_t result = priv->params_ethtool.prio_tc[prio_index];
235 err = sysctl_handle_8(oidp, &result, 0, req);
236 if (err || !req->newptr ||
237 result == priv->params_ethtool.prio_tc[prio_index])
240 if (result > mlx5_max_tc(mdev)) {
245 err = -mlx5_set_port_prio_tc(mdev, prio_index, result);
249 priv->params_ethtool.prio_tc[prio_index] = result;
257 mlx5e_trust_state_handler(SYSCTL_HANDLER_ARGS)
259 struct mlx5e_priv *priv = arg1;
260 struct mlx5_core_dev *mdev = priv->mdev;
265 result = priv->params_ethtool.trust_state;
266 err = sysctl_handle_8(oidp, &result, 0, req);
267 if (err || !req->newptr ||
268 result == priv->params_ethtool.trust_state)
272 case MLX5_QPTS_TRUST_PCP:
273 case MLX5_QPTS_TRUST_DSCP:
275 case MLX5_QPTS_TRUST_BOTH:
276 if (!MLX5_CAP_QCAM_FEATURE(mdev, qpts_trust_both)) {
286 err = -mlx5_set_trust_state(mdev, result);
290 priv->params_ethtool.trust_state = result;
297 mlx5e_dscp_prio_handler(SYSCTL_HANDLER_ARGS)
299 struct mlx5e_priv *priv = arg1;
300 int prio_index = arg2;
301 struct mlx5_core_dev *mdev = priv->mdev;
302 uint8_t dscp2prio[MLX5_MAX_SUPPORTED_DSCP];
307 err = SYSCTL_OUT(req, priv->params_ethtool.dscp2prio + prio_index,
308 sizeof(priv->params_ethtool.dscp2prio) / 8);
309 if (err || !req->newptr)
312 memcpy(dscp2prio, priv->params_ethtool.dscp2prio, sizeof(dscp2prio));
313 err = SYSCTL_IN(req, dscp2prio + prio_index, sizeof(dscp2prio) / 8);
316 for (x = 0; x != MLX5_MAX_SUPPORTED_DSCP; x++) {
317 if (dscp2prio[x] > 7) {
322 err = -mlx5_set_dscp2prio(mdev, dscp2prio);
326 /* update local array */
327 memcpy(priv->params_ethtool.dscp2prio, dscp2prio,
328 sizeof(priv->params_ethtool.dscp2prio));
334 #define MLX5_PARAM_OFFSET(n) \
335 __offsetof(struct mlx5e_priv, params_ethtool.n)
338 mlx5e_ethtool_handler(SYSCTL_HANDLER_ARGS)
340 struct mlx5e_priv *priv = arg1;
347 value = priv->params_ethtool.arg[arg2];
349 error = sysctl_handle_64(oidp, &value, 0, req);
350 if (error || req->newptr == NULL ||
351 value == priv->params_ethtool.arg[arg2])
354 /* assign new value */
355 priv->params_ethtool.arg[arg2] = value;
359 /* check if device is gone */
364 was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
365 mode_modify = MLX5_CAP_GEN(priv->mdev, cq_period_mode_modify);
367 switch (MLX5_PARAM_OFFSET(arg[arg2])) {
368 case MLX5_PARAM_OFFSET(rx_coalesce_usecs):
369 /* import RX coal time */
370 if (priv->params_ethtool.rx_coalesce_usecs < 1)
371 priv->params_ethtool.rx_coalesce_usecs = 0;
372 else if (priv->params_ethtool.rx_coalesce_usecs >
373 MLX5E_FLD_MAX(cqc, cq_period)) {
374 priv->params_ethtool.rx_coalesce_usecs =
375 MLX5E_FLD_MAX(cqc, cq_period);
377 priv->params.rx_cq_moderation_usec =
378 priv->params_ethtool.rx_coalesce_usecs;
380 /* check to avoid down and up the network interface */
382 error = mlx5e_refresh_channel_params(priv);
385 case MLX5_PARAM_OFFSET(rx_coalesce_pkts):
386 /* import RX coal pkts */
387 if (priv->params_ethtool.rx_coalesce_pkts < 1)
388 priv->params_ethtool.rx_coalesce_pkts = 0;
389 else if (priv->params_ethtool.rx_coalesce_pkts >
390 MLX5E_FLD_MAX(cqc, cq_max_count)) {
391 priv->params_ethtool.rx_coalesce_pkts =
392 MLX5E_FLD_MAX(cqc, cq_max_count);
394 priv->params.rx_cq_moderation_pkts =
395 priv->params_ethtool.rx_coalesce_pkts;
397 /* check to avoid down and up the network interface */
399 error = mlx5e_refresh_channel_params(priv);
402 case MLX5_PARAM_OFFSET(tx_coalesce_usecs):
403 /* import TX coal time */
404 if (priv->params_ethtool.tx_coalesce_usecs < 1)
405 priv->params_ethtool.tx_coalesce_usecs = 0;
406 else if (priv->params_ethtool.tx_coalesce_usecs >
407 MLX5E_FLD_MAX(cqc, cq_period)) {
408 priv->params_ethtool.tx_coalesce_usecs =
409 MLX5E_FLD_MAX(cqc, cq_period);
411 priv->params.tx_cq_moderation_usec =
412 priv->params_ethtool.tx_coalesce_usecs;
414 /* check to avoid down and up the network interface */
416 error = mlx5e_refresh_channel_params(priv);
419 case MLX5_PARAM_OFFSET(tx_coalesce_pkts):
420 /* import TX coal pkts */
421 if (priv->params_ethtool.tx_coalesce_pkts < 1)
422 priv->params_ethtool.tx_coalesce_pkts = 0;
423 else if (priv->params_ethtool.tx_coalesce_pkts >
424 MLX5E_FLD_MAX(cqc, cq_max_count)) {
425 priv->params_ethtool.tx_coalesce_pkts =
426 MLX5E_FLD_MAX(cqc, cq_max_count);
428 priv->params.tx_cq_moderation_pkts =
429 priv->params_ethtool.tx_coalesce_pkts;
431 /* check to avoid down and up the network interface */
433 error = mlx5e_refresh_channel_params(priv);
436 case MLX5_PARAM_OFFSET(tx_queue_size):
437 /* network interface must be down */
439 mlx5e_close_locked(priv->ifp);
441 /* import TX queue size */
442 if (priv->params_ethtool.tx_queue_size <
443 (1 << MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE)) {
444 priv->params_ethtool.tx_queue_size =
445 (1 << MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE);
446 } else if (priv->params_ethtool.tx_queue_size >
447 priv->params_ethtool.tx_queue_size_max) {
448 priv->params_ethtool.tx_queue_size =
449 priv->params_ethtool.tx_queue_size_max;
451 /* store actual TX queue size */
452 priv->params.log_sq_size =
453 order_base_2(priv->params_ethtool.tx_queue_size);
454 priv->params_ethtool.tx_queue_size =
455 1 << priv->params.log_sq_size;
457 /* verify TX completion factor */
458 mlx5e_ethtool_sync_tx_completion_fact(priv);
460 /* restart network interface, if any */
462 mlx5e_open_locked(priv->ifp);
465 case MLX5_PARAM_OFFSET(rx_queue_size):
466 /* network interface must be down */
468 mlx5e_close_locked(priv->ifp);
470 /* import RX queue size */
471 if (priv->params_ethtool.rx_queue_size <
472 (1 << MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE)) {
473 priv->params_ethtool.rx_queue_size =
474 (1 << MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE);
475 } else if (priv->params_ethtool.rx_queue_size >
476 priv->params_ethtool.rx_queue_size_max) {
477 priv->params_ethtool.rx_queue_size =
478 priv->params_ethtool.rx_queue_size_max;
480 /* store actual RX queue size */
481 priv->params.log_rq_size =
482 order_base_2(priv->params_ethtool.rx_queue_size);
483 priv->params_ethtool.rx_queue_size =
484 1 << priv->params.log_rq_size;
486 /* update least number of RX WQEs */
487 priv->params.min_rx_wqes = min(
488 priv->params_ethtool.rx_queue_size - 1,
489 MLX5E_PARAMS_DEFAULT_MIN_RX_WQES);
491 /* restart network interface, if any */
493 mlx5e_open_locked(priv->ifp);
496 case MLX5_PARAM_OFFSET(channels):
497 /* network interface must be down */
499 mlx5e_close_locked(priv->ifp);
501 /* import number of channels */
502 if (priv->params_ethtool.channels < 1)
503 priv->params_ethtool.channels = 1;
504 else if (priv->params_ethtool.channels >
505 (u64) priv->mdev->priv.eq_table.num_comp_vectors) {
506 priv->params_ethtool.channels =
507 (u64) priv->mdev->priv.eq_table.num_comp_vectors;
509 priv->params.num_channels = priv->params_ethtool.channels;
511 /* restart network interface, if any */
513 mlx5e_open_locked(priv->ifp);
516 case MLX5_PARAM_OFFSET(rx_coalesce_mode):
517 /* network interface must be down */
518 if (was_opened != 0 && mode_modify == 0)
519 mlx5e_close_locked(priv->ifp);
521 /* import RX coalesce mode */
522 if (priv->params_ethtool.rx_coalesce_mode != 0)
523 priv->params_ethtool.rx_coalesce_mode = 1;
524 priv->params.rx_cq_moderation_mode =
525 priv->params_ethtool.rx_coalesce_mode;
527 /* restart network interface, if any */
528 if (was_opened != 0) {
529 if (mode_modify == 0)
530 mlx5e_open_locked(priv->ifp);
532 error = mlx5e_refresh_channel_params(priv);
536 case MLX5_PARAM_OFFSET(tx_coalesce_mode):
537 /* network interface must be down */
538 if (was_opened != 0 && mode_modify == 0)
539 mlx5e_close_locked(priv->ifp);
541 /* import TX coalesce mode */
542 if (priv->params_ethtool.tx_coalesce_mode != 0)
543 priv->params_ethtool.tx_coalesce_mode = 1;
544 priv->params.tx_cq_moderation_mode =
545 priv->params_ethtool.tx_coalesce_mode;
547 /* restart network interface, if any */
548 if (was_opened != 0) {
549 if (mode_modify == 0)
550 mlx5e_open_locked(priv->ifp);
552 error = mlx5e_refresh_channel_params(priv);
556 case MLX5_PARAM_OFFSET(hw_lro):
557 /* network interface must be down */
559 mlx5e_close_locked(priv->ifp);
561 /* import HW LRO mode */
562 if (priv->params_ethtool.hw_lro != 0) {
563 if ((priv->ifp->if_capenable & IFCAP_LRO) &&
564 MLX5_CAP_ETH(priv->mdev, lro_cap)) {
565 priv->params.hw_lro_en = 1;
566 priv->params_ethtool.hw_lro = 1;
568 priv->params.hw_lro_en = 0;
569 priv->params_ethtool.hw_lro = 0;
572 if_printf(priv->ifp, "Can't enable HW LRO: "
573 "The HW or SW LRO feature is disabled\n");
576 priv->params.hw_lro_en = 0;
578 /* restart network interface, if any */
580 mlx5e_open_locked(priv->ifp);
583 case MLX5_PARAM_OFFSET(cqe_zipping):
584 /* network interface must be down */
586 mlx5e_close_locked(priv->ifp);
588 /* import CQE zipping mode */
589 if (priv->params_ethtool.cqe_zipping &&
590 MLX5_CAP_GEN(priv->mdev, cqe_compression)) {
591 priv->params.cqe_zipping_en = true;
592 priv->params_ethtool.cqe_zipping = 1;
594 priv->params.cqe_zipping_en = false;
595 priv->params_ethtool.cqe_zipping = 0;
597 /* restart network interface, if any */
599 mlx5e_open_locked(priv->ifp);
602 case MLX5_PARAM_OFFSET(tx_bufring_disable):
603 /* rangecheck input value */
604 priv->params_ethtool.tx_bufring_disable =
605 priv->params_ethtool.tx_bufring_disable ? 1 : 0;
607 /* reconfigure the sendqueues, if any */
609 mlx5e_close_locked(priv->ifp);
610 mlx5e_open_locked(priv->ifp);
614 case MLX5_PARAM_OFFSET(tx_completion_fact):
615 /* network interface must be down */
617 mlx5e_close_locked(priv->ifp);
619 /* verify parameter */
620 mlx5e_ethtool_sync_tx_completion_fact(priv);
622 /* restart network interface, if any */
624 mlx5e_open_locked(priv->ifp);
627 case MLX5_PARAM_OFFSET(modify_tx_dma):
628 /* check if network interface is opened */
630 priv->params_ethtool.modify_tx_dma =
631 priv->params_ethtool.modify_tx_dma ? 1 : 0;
632 /* modify tx according to value */
633 mlx5e_modify_tx_dma(priv, value != 0);
635 /* if closed force enable tx */
636 priv->params_ethtool.modify_tx_dma = 0;
640 case MLX5_PARAM_OFFSET(modify_rx_dma):
641 /* check if network interface is opened */
643 priv->params_ethtool.modify_rx_dma =
644 priv->params_ethtool.modify_rx_dma ? 1 : 0;
645 /* modify rx according to value */
646 mlx5e_modify_rx_dma(priv, value != 0);
648 /* if closed force enable rx */
649 priv->params_ethtool.modify_rx_dma = 0;
653 case MLX5_PARAM_OFFSET(diag_pci_enable):
654 priv->params_ethtool.diag_pci_enable =
655 priv->params_ethtool.diag_pci_enable ? 1 : 0;
657 error = -mlx5_core_set_diagnostics_full(priv->mdev,
658 priv->params_ethtool.diag_pci_enable,
659 priv->params_ethtool.diag_general_enable);
662 case MLX5_PARAM_OFFSET(diag_general_enable):
663 priv->params_ethtool.diag_general_enable =
664 priv->params_ethtool.diag_general_enable ? 1 : 0;
666 error = -mlx5_core_set_diagnostics_full(priv->mdev,
667 priv->params_ethtool.diag_pci_enable,
668 priv->params_ethtool.diag_general_enable);
671 case MLX5_PARAM_OFFSET(mc_local_lb):
672 priv->params_ethtool.mc_local_lb =
673 priv->params_ethtool.mc_local_lb ? 1 : 0;
675 if (MLX5_CAP_GEN(priv->mdev, disable_local_lb)) {
676 error = mlx5_nic_vport_modify_local_lb(priv->mdev,
677 MLX5_LOCAL_MC_LB, priv->params_ethtool.mc_local_lb);
683 case MLX5_PARAM_OFFSET(uc_local_lb):
684 priv->params_ethtool.uc_local_lb =
685 priv->params_ethtool.uc_local_lb ? 1 : 0;
687 if (MLX5_CAP_GEN(priv->mdev, disable_local_lb)) {
688 error = mlx5_nic_vport_modify_local_lb(priv->mdev,
689 MLX5_LOCAL_UC_LB, priv->params_ethtool.uc_local_lb);
704 * Read the first three bytes of the eeprom in order to get the needed info
705 * for the whole reading.
706 * Byte 0 - Identifier byte
707 * Byte 1 - Revision byte
708 * Byte 2 - Status byte
711 mlx5e_get_eeprom_info(struct mlx5e_priv *priv, struct mlx5e_eeprom *eeprom)
713 struct mlx5_core_dev *dev = priv->mdev;
718 ret = mlx5_query_module_num(dev, &eeprom->module_num);
720 if_printf(priv->ifp, "%s:%d: Failed query module error=%d\n",
721 __func__, __LINE__, ret);
725 /* Read the first three bytes to get Identifier, Revision and Status */
726 ret = mlx5_query_eeprom(dev, eeprom->i2c_addr, eeprom->page_num,
727 eeprom->device_addr, MLX5E_EEPROM_INFO_BYTES, eeprom->module_num, &data,
730 if_printf(priv->ifp, "%s:%d: Failed query eeprom module error=0x%x\n",
731 __func__, __LINE__, ret);
735 switch (data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK) {
736 case SFF_8024_ID_QSFP:
737 eeprom->type = MLX5E_ETH_MODULE_SFF_8436;
738 eeprom->len = MLX5E_ETH_MODULE_SFF_8436_LEN;
740 case SFF_8024_ID_QSFPPLUS:
741 case SFF_8024_ID_QSFP28:
742 if ((data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK) == SFF_8024_ID_QSFP28 ||
743 ((data & MLX5_EEPROM_REVISION_ID_BYTE_MASK) >> 8) >= 0x3) {
744 eeprom->type = MLX5E_ETH_MODULE_SFF_8636;
745 eeprom->len = MLX5E_ETH_MODULE_SFF_8636_LEN;
747 eeprom->type = MLX5E_ETH_MODULE_SFF_8436;
748 eeprom->len = MLX5E_ETH_MODULE_SFF_8436_LEN;
750 if ((data & MLX5_EEPROM_PAGE_3_VALID_BIT_MASK) == 0)
751 eeprom->page_valid = 1;
753 case SFF_8024_ID_SFP:
754 eeprom->type = MLX5E_ETH_MODULE_SFF_8472;
755 eeprom->len = MLX5E_ETH_MODULE_SFF_8472_LEN;
758 if_printf(priv->ifp, "%s:%d: Not recognized cable type = 0x%x(%s)\n",
759 __func__, __LINE__, data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK,
760 sff_8024_id[data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK]);
766 /* Read both low and high pages of the eeprom */
768 mlx5e_get_eeprom(struct mlx5e_priv *priv, struct mlx5e_eeprom *ee)
770 struct mlx5_core_dev *dev = priv->mdev;
777 /* Read low page of the eeprom */
778 while (ee->device_addr < ee->len) {
779 ret = mlx5_query_eeprom(dev, ee->i2c_addr, ee->page_num, ee->device_addr,
780 ee->len - ee->device_addr, ee->module_num,
781 ee->data + (ee->device_addr / 4), &size_read);
783 if_printf(priv->ifp, "%s:%d: Failed reading eeprom, "
784 "error = 0x%02x\n", __func__, __LINE__, ret);
787 ee->device_addr += size_read;
790 /* Read high page of the eeprom */
791 if (ee->page_valid) {
792 ee->device_addr = MLX5E_EEPROM_HIGH_PAGE_OFFSET;
793 ee->page_num = MLX5E_EEPROM_HIGH_PAGE;
795 while (ee->device_addr < MLX5E_EEPROM_PAGE_LENGTH) {
796 ret = mlx5_query_eeprom(dev, ee->i2c_addr, ee->page_num,
797 ee->device_addr, MLX5E_EEPROM_PAGE_LENGTH - ee->device_addr,
798 ee->module_num, ee->data + (ee->len / 4) +
799 ((ee->device_addr - MLX5E_EEPROM_HIGH_PAGE_OFFSET) / 4),
802 if_printf(priv->ifp, "%s:%d: Failed reading eeprom, "
803 "error = 0x%02x\n", __func__, __LINE__, ret);
806 ee->device_addr += size_read;
813 mlx5e_print_eeprom(struct mlx5e_eeprom *eeprom)
817 int byte_to_write = 0;
818 int line_length = 16;
820 printf("\nOffset\t\tValues\n");
821 printf("------\t\t------");
822 while (byte_to_write < eeprom->len) {
823 printf("\n0x%04X\t\t", byte_to_write);
824 for (index_in_row = 0; index_in_row < line_length; index_in_row++) {
825 printf("%02X ", ((u8 *)eeprom->data)[byte_to_write]);
830 if (eeprom->page_valid) {
831 row = MLX5E_EEPROM_HIGH_PAGE_OFFSET;
832 printf("\n\nUpper Page 0x03\n");
833 printf("\nOffset\t\tValues\n");
834 printf("------\t\t------");
835 while (row < MLX5E_EEPROM_PAGE_LENGTH) {
836 printf("\n0x%04X\t\t", row);
837 for (index_in_row = 0; index_in_row < line_length; index_in_row++) {
838 printf("%02X ", ((u8 *)eeprom->data)[byte_to_write]);
847 * Read cable EEPROM module information by first inspecting the first
848 * three bytes to get the initial information for a whole reading.
849 * Information will be printed to dmesg.
852 mlx5e_read_eeprom(SYSCTL_HANDLER_ARGS)
854 struct mlx5e_priv *priv = arg1;
855 struct mlx5e_eeprom eeprom;
860 error = sysctl_handle_int(oidp, &result, 0, req);
861 if (error || !req->newptr)
864 /* Check if device is gone */
871 eeprom.i2c_addr = MLX5E_I2C_ADDR_LOW;
872 eeprom.device_addr = 0;
873 eeprom.page_num = MLX5E_EEPROM_LOW_PAGE;
874 eeprom.page_valid = 0;
876 /* Read three first bytes to get important info */
877 error = mlx5e_get_eeprom_info(priv, &eeprom);
879 if_printf(priv->ifp, "%s:%d: Failed reading eeprom's "
880 "initial information\n", __func__, __LINE__);
885 * Allocate needed length buffer and additional space for
888 eeprom.data = malloc(eeprom.len + MLX5E_EEPROM_PAGE_LENGTH,
889 M_MLX5EN, M_WAITOK | M_ZERO);
891 /* Read the whole eeprom information */
892 error = mlx5e_get_eeprom(priv, &eeprom);
894 if_printf(priv->ifp, "%s:%d: Failed reading eeprom\n",
898 * Continue printing partial information in case of
902 mlx5e_print_eeprom(&eeprom);
903 free(eeprom.data, M_MLX5EN);
910 static const char *mlx5e_params_desc[] = {
911 MLX5E_PARAMS(MLX5E_STATS_DESC)
914 static const char *mlx5e_port_stats_debug_desc[] = {
915 MLX5E_PORT_STATS_DEBUG(MLX5E_STATS_DESC)
919 mlx5e_ethtool_debug_channel_info(SYSCTL_HANDLER_ARGS)
921 struct mlx5e_priv *priv;
923 struct mlx5e_channel *c;
929 error = sysctl_wire_old_buffer(req, 0);
932 if (sbuf_new_for_sysctl(&sb, NULL, 128, req) == NULL)
934 sbuf_clear_flags(&sb, SBUF_INCLUDENUL);
937 if (test_bit(MLX5E_STATE_OPENED, &priv->state) == 0)
939 for (i = 0; i < priv->params.num_channels; i++) {
940 c = priv->channel[i];
942 sbuf_printf(&sb, "channel %d rq %d cq %d\n",
943 c->ix, rq->rqn, rq->cq.mcq.cqn);
944 for (tc = 0; tc < c->num_tc; tc++) {
946 sbuf_printf(&sb, "channel %d tc %d sq %d cq %d\n",
947 c->ix, tc, sq->sqn, sq->cq.mcq.cqn);
952 error = sbuf_finish(&sb);
958 mlx5e_ethtool_debug_stats(SYSCTL_HANDLER_ARGS)
960 struct mlx5e_priv *priv = arg1;
961 int error, sys_debug;
963 sys_debug = priv->sysctl_debug;
964 error = sysctl_handle_int(oidp, &priv->sysctl_debug, 0, req);
965 if (error != 0 || !req->newptr)
967 priv->sysctl_debug = priv->sysctl_debug != 0;
968 if (sys_debug == priv->sysctl_debug)
972 if (priv->sysctl_debug) {
973 mlx5e_create_stats(&priv->stats.port_stats_debug.ctx,
974 SYSCTL_CHILDREN(priv->sysctl_ifnet), "debug_stats",
975 mlx5e_port_stats_debug_desc, MLX5E_PORT_STATS_DEBUG_NUM,
976 priv->stats.port_stats_debug.arg);
977 SYSCTL_ADD_PROC(&priv->sysctl_ctx_channel_debug,
978 SYSCTL_CHILDREN(priv->sysctl_ifnet), OID_AUTO,
980 CTLFLAG_RD | CTLFLAG_MPSAFE | CTLTYPE_STRING, priv, 0,
981 mlx5e_ethtool_debug_channel_info, "S", "");
983 sysctl_ctx_free(&priv->stats.port_stats_debug.ctx);
984 sysctl_ctx_free(&priv->sysctl_ctx_channel_debug);
991 mlx5e_create_diagnostics(struct mlx5e_priv *priv)
993 struct mlx5_core_diagnostics_entry entry;
994 struct sysctl_ctx_list *ctx;
995 struct sysctl_oid *node;
998 /* sysctl context we are using */
999 ctx = &priv->sysctl_ctx;
1001 /* create root node */
1002 node = SYSCTL_ADD_NODE(ctx,
1003 SYSCTL_CHILDREN(priv->sysctl_ifnet), OID_AUTO,
1004 "diagnostics", CTLFLAG_RD, NULL, "Diagnostics");
1008 /* create PCI diagnostics */
1009 for (x = 0; x != MLX5_CORE_PCI_DIAGNOSTICS_NUM; x++) {
1010 entry = mlx5_core_pci_diagnostics_table[x];
1011 if (mlx5_core_supports_diagnostics(priv->mdev, entry.counter_id) == 0)
1013 SYSCTL_ADD_UQUAD(ctx, SYSCTL_CHILDREN(node), OID_AUTO,
1014 entry.desc, CTLFLAG_RD, priv->params_pci.array + x,
1015 "PCI diagnostics counter");
1018 /* create general diagnostics */
1019 for (x = 0; x != MLX5_CORE_GENERAL_DIAGNOSTICS_NUM; x++) {
1020 entry = mlx5_core_general_diagnostics_table[x];
1021 if (mlx5_core_supports_diagnostics(priv->mdev, entry.counter_id) == 0)
1023 SYSCTL_ADD_UQUAD(ctx, SYSCTL_CHILDREN(node), OID_AUTO,
1024 entry.desc, CTLFLAG_RD, priv->params_general.array + x,
1025 "General diagnostics counter");
1030 mlx5e_create_ethtool(struct mlx5e_priv *priv)
1032 struct mlx5_core_dev *mdev = priv->mdev;
1033 struct sysctl_oid *node, *qos_node;
1034 const char *pnameunit;
1038 /* set some defaults */
1039 priv->params_ethtool.tx_queue_size_max = 1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE;
1040 priv->params_ethtool.rx_queue_size_max = 1 << MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE;
1041 priv->params_ethtool.tx_queue_size = 1 << priv->params.log_sq_size;
1042 priv->params_ethtool.rx_queue_size = 1 << priv->params.log_rq_size;
1043 priv->params_ethtool.channels = priv->params.num_channels;
1044 priv->params_ethtool.coalesce_pkts_max = MLX5E_FLD_MAX(cqc, cq_max_count);
1045 priv->params_ethtool.coalesce_usecs_max = MLX5E_FLD_MAX(cqc, cq_period);
1046 priv->params_ethtool.rx_coalesce_mode = priv->params.rx_cq_moderation_mode;
1047 priv->params_ethtool.rx_coalesce_usecs = priv->params.rx_cq_moderation_usec;
1048 priv->params_ethtool.rx_coalesce_pkts = priv->params.rx_cq_moderation_pkts;
1049 priv->params_ethtool.tx_coalesce_mode = priv->params.tx_cq_moderation_mode;
1050 priv->params_ethtool.tx_coalesce_usecs = priv->params.tx_cq_moderation_usec;
1051 priv->params_ethtool.tx_coalesce_pkts = priv->params.tx_cq_moderation_pkts;
1052 priv->params_ethtool.hw_lro = priv->params.hw_lro_en;
1053 priv->params_ethtool.cqe_zipping = priv->params.cqe_zipping_en;
1054 mlx5e_ethtool_sync_tx_completion_fact(priv);
1056 /* get default values for local loopback, if any */
1057 if (MLX5_CAP_GEN(priv->mdev, disable_local_lb)) {
1061 err = mlx5_nic_vport_query_local_lb(priv->mdev, MLX5_LOCAL_MC_LB, &val);
1063 priv->params_ethtool.mc_local_lb = val;
1065 err = mlx5_nic_vport_query_local_lb(priv->mdev, MLX5_LOCAL_UC_LB, &val);
1067 priv->params_ethtool.uc_local_lb = val;
1070 /* create root node */
1071 node = SYSCTL_ADD_NODE(&priv->sysctl_ctx,
1072 SYSCTL_CHILDREN(priv->sysctl_ifnet), OID_AUTO,
1073 "conf", CTLFLAG_RW, NULL, "Configuration");
1076 for (x = 0; x != MLX5E_PARAMS_NUM; x++) {
1077 /* check for read-only parameter */
1078 if (strstr(mlx5e_params_desc[2 * x], "_max") != NULL ||
1079 strstr(mlx5e_params_desc[2 * x], "_mtu") != NULL) {
1080 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO,
1081 mlx5e_params_desc[2 * x], CTLTYPE_U64 | CTLFLAG_RD |
1082 CTLFLAG_MPSAFE, priv, x, &mlx5e_ethtool_handler, "QU",
1083 mlx5e_params_desc[2 * x + 1]);
1085 #if (__FreeBSD_version < 1100000)
1089 * NOTE: In FreeBSD-11 and newer the
1090 * CTLFLAG_RWTUN flag will take care of
1091 * loading default sysctl value from the
1092 * kernel environment, if any:
1094 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO,
1095 mlx5e_params_desc[2 * x], CTLTYPE_U64 | CTLFLAG_RWTUN |
1096 CTLFLAG_MPSAFE, priv, x, &mlx5e_ethtool_handler, "QU",
1097 mlx5e_params_desc[2 * x + 1]);
1099 #if (__FreeBSD_version < 1100000)
1100 /* compute path for sysctl */
1101 snprintf(path, sizeof(path), "dev.mce.%d.conf.%s",
1102 device_get_unit(priv->mdev->pdev->dev.bsddev),
1103 mlx5e_params_desc[2 * x]);
1105 /* try to fetch tunable, if any */
1106 if (TUNABLE_QUAD_FETCH(path, &priv->params_ethtool.arg[x]))
1107 mlx5e_ethtool_handler(NULL, priv, x, NULL);
1112 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO,
1113 "debug_stats", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv,
1114 0, &mlx5e_ethtool_debug_stats, "I", "Extended debug statistics");
1116 pnameunit = device_get_nameunit(priv->mdev->pdev->dev.bsddev);
1118 SYSCTL_ADD_STRING(&priv->sysctl_ctx, SYSCTL_CHILDREN(node),
1119 OID_AUTO, "device_name", CTLFLAG_RD,
1120 __DECONST(void *, pnameunit), 0,
1123 /* EEPROM support */
1124 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO, "eeprom_info",
1125 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv, 0,
1126 mlx5e_read_eeprom, "I", "EEPROM information");
1128 /* Diagnostics support */
1129 mlx5e_create_diagnostics(priv);
1131 /* create qos node */
1132 qos_node = SYSCTL_ADD_NODE(&priv->sysctl_ctx,
1133 SYSCTL_CHILDREN(node), OID_AUTO,
1134 "qos", CTLFLAG_RW, NULL, "Quality Of Service configuration");
1138 /* Prioriry rate limit support */
1139 if (mlx5e_getmaxrate(priv))
1142 for (i = 0; i <= mlx5_max_tc(mdev); i++) {
1144 snprintf(name, sizeof(name), "tc_%d_max_rate", i);
1145 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(qos_node),
1146 OID_AUTO, name, CTLTYPE_U64 | CTLFLAG_RW | CTLFLAG_MPSAFE,
1147 priv, i, mlx5e_tc_maxrate_handler, "QU",
1148 "Max rate for priority, specified in kilobits, where kilo=1000, \
1149 max_rate must be divisible by 100000");
1152 if (mlx5e_get_prio_tc(priv))
1155 for (i = 0; i <= mlx5_max_tc(mdev); i++) {
1157 snprintf(name, sizeof(name), "prio_%d_to_tc", i);
1158 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(qos_node),
1159 OID_AUTO, name, CTLTYPE_U8 | CTLFLAG_RW | CTLFLAG_MPSAFE,
1160 priv, i, mlx5e_prio_to_tc_handler, "CU",
1161 "Set priority to traffic class");
1165 if (mlx5e_get_dscp(priv) == 0) {
1166 for (i = 0; i != MLX5_MAX_SUPPORTED_DSCP; i += 8) {
1168 snprintf(name, sizeof(name), "dscp_%d_%d_prio", i, i + 7);
1169 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(qos_node),
1170 OID_AUTO, name, CTLTYPE_U8 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1171 priv, i, mlx5e_dscp_prio_handler, "CU",
1172 "Set DSCP to priority mapping, 0..7");
1174 #define A "Set trust state, 1:PCP 2:DSCP"
1176 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(qos_node),
1177 OID_AUTO, "trust_state", CTLTYPE_U8 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1178 priv, 0, mlx5e_trust_state_handler, "CU",
1179 MLX5_CAP_QCAM_FEATURE(mdev, qpts_trust_both) ?