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_tc_maxrate_handler(SYSCTL_HANDLER_ARGS)
126 struct mlx5e_priv *priv = arg1;
127 int prio_index = arg2;
128 struct mlx5_core_dev *mdev = priv->mdev;
129 u8 max_bw_unit[IEEE_8021QAZ_MAX_TCS];
130 u8 max_bw_value[IEEE_8021QAZ_MAX_TCS];
133 u64 result = priv->params_ethtool.max_bw_value[prio_index];
134 const u64 upper_limit_mbps = 255 * MLX5E_100MB;
135 const u64 upper_limit_gbps = 255 * MLX5E_1GB;
138 err = sysctl_handle_64(oidp, &result, 0, req);
139 if (err || !req->newptr ||
140 result == priv->params_ethtool.max_bw_value[prio_index])
143 if (result % MLX5E_100MB) {
148 memset(max_bw_value, 0, sizeof(max_bw_value));
149 memset(max_bw_unit, 0, sizeof(max_bw_unit));
151 for (i = 0; i <= mlx5_max_tc(mdev); i++) {
152 bw_val = (i == prio_index) ? result : priv->params_ethtool.max_bw_value[i];
155 max_bw_unit[i] = MLX5_BW_NO_LIMIT;
156 } else if (bw_val > upper_limit_gbps) {
158 max_bw_unit[i] = MLX5_BW_NO_LIMIT;
159 } else if (bw_val <= upper_limit_mbps) {
160 max_bw_value[i] = howmany(bw_val, MLX5E_100MB);
161 max_bw_unit[i] = MLX5_100_MBPS_UNIT;
163 max_bw_value[i] = howmany(bw_val, MLX5E_1GB);
164 max_bw_unit[i] = MLX5_GBPS_UNIT;
168 err = -mlx5_modify_port_tc_rate_limit(mdev, max_bw_value, max_bw_unit);
172 priv->params_ethtool.max_bw_value[prio_index] = result;
179 mlx5e_get_prio_tc(struct mlx5e_priv *priv)
181 struct mlx5_core_dev *mdev = priv->mdev;
186 if (!MLX5_CAP_GEN(priv->mdev, ets)) {
191 for (i = 0; i <= mlx5_max_tc(priv->mdev); i++) {
192 err = -mlx5_query_port_prio_tc(mdev, i, &(priv->params_ethtool.prio_tc[i]));
202 mlx5e_prio_to_tc_handler(SYSCTL_HANDLER_ARGS)
204 struct mlx5e_priv *priv = arg1;
205 int prio_index = arg2;
206 struct mlx5_core_dev *mdev = priv->mdev;
208 uint8_t result = priv->params_ethtool.prio_tc[prio_index];
211 err = sysctl_handle_8(oidp, &result, 0, req);
212 if (err || !req->newptr ||
213 result == priv->params_ethtool.prio_tc[prio_index])
216 if (result > mlx5_max_tc(mdev)) {
221 err = -mlx5_set_port_prio_tc(mdev, prio_index, result);
225 priv->params_ethtool.prio_tc[prio_index] = result;
232 #define MLX5_PARAM_OFFSET(n) \
233 __offsetof(struct mlx5e_priv, params_ethtool.n)
236 mlx5e_ethtool_handler(SYSCTL_HANDLER_ARGS)
238 struct mlx5e_priv *priv = arg1;
245 value = priv->params_ethtool.arg[arg2];
247 error = sysctl_handle_64(oidp, &value, 0, req);
248 if (error || req->newptr == NULL ||
249 value == priv->params_ethtool.arg[arg2])
252 /* assign new value */
253 priv->params_ethtool.arg[arg2] = value;
257 /* check if device is gone */
262 was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
263 mode_modify = MLX5_CAP_GEN(priv->mdev, cq_period_mode_modify);
265 switch (MLX5_PARAM_OFFSET(arg[arg2])) {
266 case MLX5_PARAM_OFFSET(rx_coalesce_usecs):
267 /* import RX coal time */
268 if (priv->params_ethtool.rx_coalesce_usecs < 1)
269 priv->params_ethtool.rx_coalesce_usecs = 0;
270 else if (priv->params_ethtool.rx_coalesce_usecs >
271 MLX5E_FLD_MAX(cqc, cq_period)) {
272 priv->params_ethtool.rx_coalesce_usecs =
273 MLX5E_FLD_MAX(cqc, cq_period);
275 priv->params.rx_cq_moderation_usec =
276 priv->params_ethtool.rx_coalesce_usecs;
278 /* check to avoid down and up the network interface */
280 error = mlx5e_refresh_channel_params(priv);
283 case MLX5_PARAM_OFFSET(rx_coalesce_pkts):
284 /* import RX coal pkts */
285 if (priv->params_ethtool.rx_coalesce_pkts < 1)
286 priv->params_ethtool.rx_coalesce_pkts = 0;
287 else if (priv->params_ethtool.rx_coalesce_pkts >
288 MLX5E_FLD_MAX(cqc, cq_max_count)) {
289 priv->params_ethtool.rx_coalesce_pkts =
290 MLX5E_FLD_MAX(cqc, cq_max_count);
292 priv->params.rx_cq_moderation_pkts =
293 priv->params_ethtool.rx_coalesce_pkts;
295 /* check to avoid down and up the network interface */
297 error = mlx5e_refresh_channel_params(priv);
300 case MLX5_PARAM_OFFSET(tx_coalesce_usecs):
301 /* import TX coal time */
302 if (priv->params_ethtool.tx_coalesce_usecs < 1)
303 priv->params_ethtool.tx_coalesce_usecs = 0;
304 else if (priv->params_ethtool.tx_coalesce_usecs >
305 MLX5E_FLD_MAX(cqc, cq_period)) {
306 priv->params_ethtool.tx_coalesce_usecs =
307 MLX5E_FLD_MAX(cqc, cq_period);
309 priv->params.tx_cq_moderation_usec =
310 priv->params_ethtool.tx_coalesce_usecs;
312 /* check to avoid down and up the network interface */
314 error = mlx5e_refresh_channel_params(priv);
317 case MLX5_PARAM_OFFSET(tx_coalesce_pkts):
318 /* import TX coal pkts */
319 if (priv->params_ethtool.tx_coalesce_pkts < 1)
320 priv->params_ethtool.tx_coalesce_pkts = 0;
321 else if (priv->params_ethtool.tx_coalesce_pkts >
322 MLX5E_FLD_MAX(cqc, cq_max_count)) {
323 priv->params_ethtool.tx_coalesce_pkts =
324 MLX5E_FLD_MAX(cqc, cq_max_count);
326 priv->params.tx_cq_moderation_pkts =
327 priv->params_ethtool.tx_coalesce_pkts;
329 /* check to avoid down and up the network interface */
331 error = mlx5e_refresh_channel_params(priv);
334 case MLX5_PARAM_OFFSET(tx_queue_size):
335 /* network interface must be down */
337 mlx5e_close_locked(priv->ifp);
339 /* import TX queue size */
340 if (priv->params_ethtool.tx_queue_size <
341 (1 << MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE)) {
342 priv->params_ethtool.tx_queue_size =
343 (1 << MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE);
344 } else if (priv->params_ethtool.tx_queue_size >
345 priv->params_ethtool.tx_queue_size_max) {
346 priv->params_ethtool.tx_queue_size =
347 priv->params_ethtool.tx_queue_size_max;
349 /* store actual TX queue size */
350 priv->params.log_sq_size =
351 order_base_2(priv->params_ethtool.tx_queue_size);
352 priv->params_ethtool.tx_queue_size =
353 1 << priv->params.log_sq_size;
355 /* verify TX completion factor */
356 mlx5e_ethtool_sync_tx_completion_fact(priv);
358 /* restart network interface, if any */
360 mlx5e_open_locked(priv->ifp);
363 case MLX5_PARAM_OFFSET(rx_queue_size):
364 /* network interface must be down */
366 mlx5e_close_locked(priv->ifp);
368 /* import RX queue size */
369 if (priv->params_ethtool.rx_queue_size <
370 (1 << MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE)) {
371 priv->params_ethtool.rx_queue_size =
372 (1 << MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE);
373 } else if (priv->params_ethtool.rx_queue_size >
374 priv->params_ethtool.rx_queue_size_max) {
375 priv->params_ethtool.rx_queue_size =
376 priv->params_ethtool.rx_queue_size_max;
378 /* store actual RX queue size */
379 priv->params.log_rq_size =
380 order_base_2(priv->params_ethtool.rx_queue_size);
381 priv->params_ethtool.rx_queue_size =
382 1 << priv->params.log_rq_size;
384 /* update least number of RX WQEs */
385 priv->params.min_rx_wqes = min(
386 priv->params_ethtool.rx_queue_size - 1,
387 MLX5E_PARAMS_DEFAULT_MIN_RX_WQES);
389 /* restart network interface, if any */
391 mlx5e_open_locked(priv->ifp);
394 case MLX5_PARAM_OFFSET(channels):
395 /* network interface must be down */
397 mlx5e_close_locked(priv->ifp);
399 /* import number of channels */
400 if (priv->params_ethtool.channels < 1)
401 priv->params_ethtool.channels = 1;
402 else if (priv->params_ethtool.channels >
403 (u64) priv->mdev->priv.eq_table.num_comp_vectors) {
404 priv->params_ethtool.channels =
405 (u64) priv->mdev->priv.eq_table.num_comp_vectors;
407 priv->params.num_channels = priv->params_ethtool.channels;
409 /* restart network interface, if any */
411 mlx5e_open_locked(priv->ifp);
414 case MLX5_PARAM_OFFSET(rx_coalesce_mode):
415 /* network interface must be down */
416 if (was_opened != 0 && mode_modify == 0)
417 mlx5e_close_locked(priv->ifp);
419 /* import RX coalesce mode */
420 if (priv->params_ethtool.rx_coalesce_mode != 0)
421 priv->params_ethtool.rx_coalesce_mode = 1;
422 priv->params.rx_cq_moderation_mode =
423 priv->params_ethtool.rx_coalesce_mode;
425 /* restart network interface, if any */
426 if (was_opened != 0) {
427 if (mode_modify == 0)
428 mlx5e_open_locked(priv->ifp);
430 error = mlx5e_refresh_channel_params(priv);
434 case MLX5_PARAM_OFFSET(tx_coalesce_mode):
435 /* network interface must be down */
436 if (was_opened != 0 && mode_modify == 0)
437 mlx5e_close_locked(priv->ifp);
439 /* import TX coalesce mode */
440 if (priv->params_ethtool.tx_coalesce_mode != 0)
441 priv->params_ethtool.tx_coalesce_mode = 1;
442 priv->params.tx_cq_moderation_mode =
443 priv->params_ethtool.tx_coalesce_mode;
445 /* restart network interface, if any */
446 if (was_opened != 0) {
447 if (mode_modify == 0)
448 mlx5e_open_locked(priv->ifp);
450 error = mlx5e_refresh_channel_params(priv);
454 case MLX5_PARAM_OFFSET(hw_lro):
455 /* network interface must be down */
457 mlx5e_close_locked(priv->ifp);
459 /* import HW LRO mode */
460 if (priv->params_ethtool.hw_lro != 0) {
461 if ((priv->ifp->if_capenable & IFCAP_LRO) &&
462 MLX5_CAP_ETH(priv->mdev, lro_cap)) {
463 priv->params.hw_lro_en = 1;
464 priv->params_ethtool.hw_lro = 1;
466 priv->params.hw_lro_en = 0;
467 priv->params_ethtool.hw_lro = 0;
470 if_printf(priv->ifp, "Can't enable HW LRO: "
471 "The HW or SW LRO feature is disabled\n");
474 priv->params.hw_lro_en = 0;
476 /* restart network interface, if any */
478 mlx5e_open_locked(priv->ifp);
481 case MLX5_PARAM_OFFSET(cqe_zipping):
482 /* network interface must be down */
484 mlx5e_close_locked(priv->ifp);
486 /* import CQE zipping mode */
487 if (priv->params_ethtool.cqe_zipping &&
488 MLX5_CAP_GEN(priv->mdev, cqe_compression)) {
489 priv->params.cqe_zipping_en = true;
490 priv->params_ethtool.cqe_zipping = 1;
492 priv->params.cqe_zipping_en = false;
493 priv->params_ethtool.cqe_zipping = 0;
495 /* restart network interface, if any */
497 mlx5e_open_locked(priv->ifp);
500 case MLX5_PARAM_OFFSET(tx_bufring_disable):
501 /* rangecheck input value */
502 priv->params_ethtool.tx_bufring_disable =
503 priv->params_ethtool.tx_bufring_disable ? 1 : 0;
505 /* reconfigure the sendqueues, if any */
507 mlx5e_close_locked(priv->ifp);
508 mlx5e_open_locked(priv->ifp);
512 case MLX5_PARAM_OFFSET(tx_completion_fact):
513 /* network interface must be down */
515 mlx5e_close_locked(priv->ifp);
517 /* verify parameter */
518 mlx5e_ethtool_sync_tx_completion_fact(priv);
520 /* restart network interface, if any */
522 mlx5e_open_locked(priv->ifp);
525 case MLX5_PARAM_OFFSET(modify_tx_dma):
526 /* check if network interface is opened */
528 priv->params_ethtool.modify_tx_dma =
529 priv->params_ethtool.modify_tx_dma ? 1 : 0;
530 /* modify tx according to value */
531 mlx5e_modify_tx_dma(priv, value != 0);
533 /* if closed force enable tx */
534 priv->params_ethtool.modify_tx_dma = 0;
538 case MLX5_PARAM_OFFSET(modify_rx_dma):
539 /* check if network interface is opened */
541 priv->params_ethtool.modify_rx_dma =
542 priv->params_ethtool.modify_rx_dma ? 1 : 0;
543 /* modify rx according to value */
544 mlx5e_modify_rx_dma(priv, value != 0);
546 /* if closed force enable rx */
547 priv->params_ethtool.modify_rx_dma = 0;
551 case MLX5_PARAM_OFFSET(diag_pci_enable):
552 priv->params_ethtool.diag_pci_enable =
553 priv->params_ethtool.diag_pci_enable ? 1 : 0;
555 error = -mlx5_core_set_diagnostics_full(priv->mdev,
556 priv->params_ethtool.diag_pci_enable,
557 priv->params_ethtool.diag_general_enable);
560 case MLX5_PARAM_OFFSET(diag_general_enable):
561 priv->params_ethtool.diag_general_enable =
562 priv->params_ethtool.diag_general_enable ? 1 : 0;
564 error = -mlx5_core_set_diagnostics_full(priv->mdev,
565 priv->params_ethtool.diag_pci_enable,
566 priv->params_ethtool.diag_general_enable);
569 case MLX5_PARAM_OFFSET(mc_local_lb):
570 priv->params_ethtool.mc_local_lb =
571 priv->params_ethtool.mc_local_lb ? 1 : 0;
573 if (MLX5_CAP_GEN(priv->mdev, disable_local_lb)) {
574 error = mlx5_nic_vport_modify_local_lb(priv->mdev,
575 MLX5_LOCAL_MC_LB, priv->params_ethtool.mc_local_lb);
581 case MLX5_PARAM_OFFSET(uc_local_lb):
582 priv->params_ethtool.uc_local_lb =
583 priv->params_ethtool.uc_local_lb ? 1 : 0;
585 if (MLX5_CAP_GEN(priv->mdev, disable_local_lb)) {
586 error = mlx5_nic_vport_modify_local_lb(priv->mdev,
587 MLX5_LOCAL_UC_LB, priv->params_ethtool.uc_local_lb);
602 * Read the first three bytes of the eeprom in order to get the needed info
603 * for the whole reading.
604 * Byte 0 - Identifier byte
605 * Byte 1 - Revision byte
606 * Byte 2 - Status byte
609 mlx5e_get_eeprom_info(struct mlx5e_priv *priv, struct mlx5e_eeprom *eeprom)
611 struct mlx5_core_dev *dev = priv->mdev;
616 ret = mlx5_query_module_num(dev, &eeprom->module_num);
618 if_printf(priv->ifp, "%s:%d: Failed query module error=%d\n",
619 __func__, __LINE__, ret);
623 /* Read the first three bytes to get Identifier, Revision and Status */
624 ret = mlx5_query_eeprom(dev, eeprom->i2c_addr, eeprom->page_num,
625 eeprom->device_addr, MLX5E_EEPROM_INFO_BYTES, eeprom->module_num, &data,
628 if_printf(priv->ifp, "%s:%d: Failed query eeprom module error=0x%x\n",
629 __func__, __LINE__, ret);
633 switch (data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK) {
634 case SFF_8024_ID_QSFP:
635 eeprom->type = MLX5E_ETH_MODULE_SFF_8436;
636 eeprom->len = MLX5E_ETH_MODULE_SFF_8436_LEN;
638 case SFF_8024_ID_QSFPPLUS:
639 case SFF_8024_ID_QSFP28:
640 if ((data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK) == SFF_8024_ID_QSFP28 ||
641 ((data & MLX5_EEPROM_REVISION_ID_BYTE_MASK) >> 8) >= 0x3) {
642 eeprom->type = MLX5E_ETH_MODULE_SFF_8636;
643 eeprom->len = MLX5E_ETH_MODULE_SFF_8636_LEN;
645 eeprom->type = MLX5E_ETH_MODULE_SFF_8436;
646 eeprom->len = MLX5E_ETH_MODULE_SFF_8436_LEN;
648 if ((data & MLX5_EEPROM_PAGE_3_VALID_BIT_MASK) == 0)
649 eeprom->page_valid = 1;
651 case SFF_8024_ID_SFP:
652 eeprom->type = MLX5E_ETH_MODULE_SFF_8472;
653 eeprom->len = MLX5E_ETH_MODULE_SFF_8472_LEN;
656 if_printf(priv->ifp, "%s:%d: Not recognized cable type = 0x%x(%s)\n",
657 __func__, __LINE__, data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK,
658 sff_8024_id[data & MLX5_EEPROM_IDENTIFIER_BYTE_MASK]);
664 /* Read both low and high pages of the eeprom */
666 mlx5e_get_eeprom(struct mlx5e_priv *priv, struct mlx5e_eeprom *ee)
668 struct mlx5_core_dev *dev = priv->mdev;
675 /* Read low page of the eeprom */
676 while (ee->device_addr < ee->len) {
677 ret = mlx5_query_eeprom(dev, ee->i2c_addr, ee->page_num, ee->device_addr,
678 ee->len - ee->device_addr, ee->module_num,
679 ee->data + (ee->device_addr / 4), &size_read);
681 if_printf(priv->ifp, "%s:%d: Failed reading eeprom, "
682 "error = 0x%02x\n", __func__, __LINE__, ret);
685 ee->device_addr += size_read;
688 /* Read high page of the eeprom */
689 if (ee->page_valid) {
690 ee->device_addr = MLX5E_EEPROM_HIGH_PAGE_OFFSET;
691 ee->page_num = MLX5E_EEPROM_HIGH_PAGE;
693 while (ee->device_addr < MLX5E_EEPROM_PAGE_LENGTH) {
694 ret = mlx5_query_eeprom(dev, ee->i2c_addr, ee->page_num,
695 ee->device_addr, MLX5E_EEPROM_PAGE_LENGTH - ee->device_addr,
696 ee->module_num, ee->data + (ee->len / 4) +
697 ((ee->device_addr - MLX5E_EEPROM_HIGH_PAGE_OFFSET) / 4),
700 if_printf(priv->ifp, "%s:%d: Failed reading eeprom, "
701 "error = 0x%02x\n", __func__, __LINE__, ret);
704 ee->device_addr += size_read;
711 mlx5e_print_eeprom(struct mlx5e_eeprom *eeprom)
715 int byte_to_write = 0;
716 int line_length = 16;
718 printf("\nOffset\t\tValues\n");
719 printf("------\t\t------");
720 while (byte_to_write < eeprom->len) {
721 printf("\n0x%04X\t\t", byte_to_write);
722 for (index_in_row = 0; index_in_row < line_length; index_in_row++) {
723 printf("%02X ", ((u8 *)eeprom->data)[byte_to_write]);
728 if (eeprom->page_valid) {
729 row = MLX5E_EEPROM_HIGH_PAGE_OFFSET;
730 printf("\n\nUpper Page 0x03\n");
731 printf("\nOffset\t\tValues\n");
732 printf("------\t\t------");
733 while (row < MLX5E_EEPROM_PAGE_LENGTH) {
734 printf("\n0x%04X\t\t", row);
735 for (index_in_row = 0; index_in_row < line_length; index_in_row++) {
736 printf("%02X ", ((u8 *)eeprom->data)[byte_to_write]);
745 * Read cable EEPROM module information by first inspecting the first
746 * three bytes to get the initial information for a whole reading.
747 * Information will be printed to dmesg.
750 mlx5e_read_eeprom(SYSCTL_HANDLER_ARGS)
752 struct mlx5e_priv *priv = arg1;
753 struct mlx5e_eeprom eeprom;
758 error = sysctl_handle_int(oidp, &result, 0, req);
759 if (error || !req->newptr)
762 /* Check if device is gone */
769 eeprom.i2c_addr = MLX5E_I2C_ADDR_LOW;
770 eeprom.device_addr = 0;
771 eeprom.page_num = MLX5E_EEPROM_LOW_PAGE;
772 eeprom.page_valid = 0;
774 /* Read three first bytes to get important info */
775 error = mlx5e_get_eeprom_info(priv, &eeprom);
777 if_printf(priv->ifp, "%s:%d: Failed reading eeprom's "
778 "initial information\n", __func__, __LINE__);
783 * Allocate needed length buffer and additional space for
786 eeprom.data = malloc(eeprom.len + MLX5E_EEPROM_PAGE_LENGTH,
787 M_MLX5EN, M_WAITOK | M_ZERO);
789 /* Read the whole eeprom information */
790 error = mlx5e_get_eeprom(priv, &eeprom);
792 if_printf(priv->ifp, "%s:%d: Failed reading eeprom\n",
796 * Continue printing partial information in case of
800 mlx5e_print_eeprom(&eeprom);
801 free(eeprom.data, M_MLX5EN);
808 static const char *mlx5e_params_desc[] = {
809 MLX5E_PARAMS(MLX5E_STATS_DESC)
812 static const char *mlx5e_port_stats_debug_desc[] = {
813 MLX5E_PORT_STATS_DEBUG(MLX5E_STATS_DESC)
817 mlx5e_ethtool_debug_stats(SYSCTL_HANDLER_ARGS)
819 struct mlx5e_priv *priv = arg1;
823 sys_debug = priv->sysctl_debug;
824 error = sysctl_handle_int(oidp, &priv->sysctl_debug, 0, req);
825 if (error || !req->newptr)
827 priv->sysctl_debug = !!priv->sysctl_debug;
828 if (sys_debug == priv->sysctl_debug)
830 if (priv->sysctl_debug)
831 mlx5e_create_stats(&priv->stats.port_stats_debug.ctx,
832 SYSCTL_CHILDREN(priv->sysctl_ifnet), "debug_stats",
833 mlx5e_port_stats_debug_desc, MLX5E_PORT_STATS_DEBUG_NUM,
834 priv->stats.port_stats_debug.arg);
836 sysctl_ctx_free(&priv->stats.port_stats_debug.ctx);
841 mlx5e_create_diagnostics(struct mlx5e_priv *priv)
843 struct mlx5_core_diagnostics_entry entry;
844 struct sysctl_ctx_list *ctx;
845 struct sysctl_oid *node;
848 /* sysctl context we are using */
849 ctx = &priv->sysctl_ctx;
851 /* create root node */
852 node = SYSCTL_ADD_NODE(ctx,
853 SYSCTL_CHILDREN(priv->sysctl_ifnet), OID_AUTO,
854 "diagnostics", CTLFLAG_RD, NULL, "Diagnostics");
858 /* create PCI diagnostics */
859 for (x = 0; x != MLX5_CORE_PCI_DIAGNOSTICS_NUM; x++) {
860 entry = mlx5_core_pci_diagnostics_table[x];
861 if (mlx5_core_supports_diagnostics(priv->mdev, entry.counter_id) == 0)
863 SYSCTL_ADD_UQUAD(ctx, SYSCTL_CHILDREN(node), OID_AUTO,
864 entry.desc, CTLFLAG_RD, priv->params_pci.array + x,
865 "PCI diagnostics counter");
868 /* create general diagnostics */
869 for (x = 0; x != MLX5_CORE_GENERAL_DIAGNOSTICS_NUM; x++) {
870 entry = mlx5_core_general_diagnostics_table[x];
871 if (mlx5_core_supports_diagnostics(priv->mdev, entry.counter_id) == 0)
873 SYSCTL_ADD_UQUAD(ctx, SYSCTL_CHILDREN(node), OID_AUTO,
874 entry.desc, CTLFLAG_RD, priv->params_general.array + x,
875 "General diagnostics counter");
880 mlx5e_create_ethtool(struct mlx5e_priv *priv)
882 struct mlx5_core_dev *mdev = priv->mdev;
883 struct sysctl_oid *node, *qos_node;
884 const char *pnameunit;
888 /* set some defaults */
889 priv->params_ethtool.tx_queue_size_max = 1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE;
890 priv->params_ethtool.rx_queue_size_max = 1 << MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE;
891 priv->params_ethtool.tx_queue_size = 1 << priv->params.log_sq_size;
892 priv->params_ethtool.rx_queue_size = 1 << priv->params.log_rq_size;
893 priv->params_ethtool.channels = priv->params.num_channels;
894 priv->params_ethtool.coalesce_pkts_max = MLX5E_FLD_MAX(cqc, cq_max_count);
895 priv->params_ethtool.coalesce_usecs_max = MLX5E_FLD_MAX(cqc, cq_period);
896 priv->params_ethtool.rx_coalesce_mode = priv->params.rx_cq_moderation_mode;
897 priv->params_ethtool.rx_coalesce_usecs = priv->params.rx_cq_moderation_usec;
898 priv->params_ethtool.rx_coalesce_pkts = priv->params.rx_cq_moderation_pkts;
899 priv->params_ethtool.tx_coalesce_mode = priv->params.tx_cq_moderation_mode;
900 priv->params_ethtool.tx_coalesce_usecs = priv->params.tx_cq_moderation_usec;
901 priv->params_ethtool.tx_coalesce_pkts = priv->params.tx_cq_moderation_pkts;
902 priv->params_ethtool.hw_lro = priv->params.hw_lro_en;
903 priv->params_ethtool.cqe_zipping = priv->params.cqe_zipping_en;
904 mlx5e_ethtool_sync_tx_completion_fact(priv);
906 /* get default values for local loopback, if any */
907 if (MLX5_CAP_GEN(priv->mdev, disable_local_lb)) {
911 err = mlx5_nic_vport_query_local_lb(priv->mdev, MLX5_LOCAL_MC_LB, &val);
913 priv->params_ethtool.mc_local_lb = val;
915 err = mlx5_nic_vport_query_local_lb(priv->mdev, MLX5_LOCAL_UC_LB, &val);
917 priv->params_ethtool.uc_local_lb = val;
920 /* create root node */
921 node = SYSCTL_ADD_NODE(&priv->sysctl_ctx,
922 SYSCTL_CHILDREN(priv->sysctl_ifnet), OID_AUTO,
923 "conf", CTLFLAG_RW, NULL, "Configuration");
926 for (x = 0; x != MLX5E_PARAMS_NUM; x++) {
927 /* check for read-only parameter */
928 if (strstr(mlx5e_params_desc[2 * x], "_max") != NULL ||
929 strstr(mlx5e_params_desc[2 * x], "_mtu") != NULL) {
930 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO,
931 mlx5e_params_desc[2 * x], CTLTYPE_U64 | CTLFLAG_RD |
932 CTLFLAG_MPSAFE, priv, x, &mlx5e_ethtool_handler, "QU",
933 mlx5e_params_desc[2 * x + 1]);
935 #if (__FreeBSD_version < 1100000)
939 * NOTE: In FreeBSD-11 and newer the
940 * CTLFLAG_RWTUN flag will take care of
941 * loading default sysctl value from the
942 * kernel environment, if any:
944 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO,
945 mlx5e_params_desc[2 * x], CTLTYPE_U64 | CTLFLAG_RWTUN |
946 CTLFLAG_MPSAFE, priv, x, &mlx5e_ethtool_handler, "QU",
947 mlx5e_params_desc[2 * x + 1]);
949 #if (__FreeBSD_version < 1100000)
950 /* compute path for sysctl */
951 snprintf(path, sizeof(path), "dev.mce.%d.conf.%s",
952 device_get_unit(priv->mdev->pdev->dev.bsddev),
953 mlx5e_params_desc[2 * x]);
955 /* try to fetch tunable, if any */
956 if (TUNABLE_QUAD_FETCH(path, &priv->params_ethtool.arg[x]))
957 mlx5e_ethtool_handler(NULL, priv, x, NULL);
962 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO,
963 "debug_stats", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv,
964 0, &mlx5e_ethtool_debug_stats, "I", "Extended debug statistics");
966 pnameunit = device_get_nameunit(priv->mdev->pdev->dev.bsddev);
968 SYSCTL_ADD_STRING(&priv->sysctl_ctx, SYSCTL_CHILDREN(node),
969 OID_AUTO, "device_name", CTLFLAG_RD,
970 __DECONST(void *, pnameunit), 0,
974 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO, "eeprom_info",
975 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv, 0,
976 mlx5e_read_eeprom, "I", "EEPROM information");
978 /* Diagnostics support */
979 mlx5e_create_diagnostics(priv);
981 /* create qos node */
982 qos_node = SYSCTL_ADD_NODE(&priv->sysctl_ctx,
983 SYSCTL_CHILDREN(node), OID_AUTO,
984 "qos", CTLFLAG_RW, NULL, "Quality Of Service configuration");
988 /* Prioriry rate limit support */
989 if (mlx5e_getmaxrate(priv))
992 for (i = 0; i <= mlx5_max_tc(mdev); i++) {
994 snprintf(name, sizeof(name), "tc_%d_max_rate", i);
995 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(qos_node),
996 OID_AUTO, name, CTLTYPE_U64 | CTLFLAG_RW | CTLFLAG_MPSAFE,
997 priv, i, mlx5e_tc_maxrate_handler, "QU",
998 "Max rate for priority, specified in kilobits, where kilo=1000, \
999 max_rate must be divisible by 100000");
1002 if (mlx5e_get_prio_tc(priv))
1005 for (i = 0; i <= mlx5_max_tc(mdev); i++) {
1007 snprintf(name, sizeof(name), "prio_%d_to_tc", i);
1008 SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(qos_node),
1009 OID_AUTO, name, CTLTYPE_U8 | CTLFLAG_RW | CTLFLAG_MPSAFE,
1010 priv, i, mlx5e_prio_to_tc_handler, "CU",
1011 "Set priority to traffic class");