2 * Copyright (c) 2015, Mellanox Technologies. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 static void mlx5e_get_drvinfo(struct net_device
*dev
,
36 struct ethtool_drvinfo
*drvinfo
)
38 struct mlx5e_priv
*priv
= netdev_priv(dev
);
39 struct mlx5_core_dev
*mdev
= priv
->mdev
;
41 strlcpy(drvinfo
->driver
, DRIVER_NAME
, sizeof(drvinfo
->driver
));
42 strlcpy(drvinfo
->version
, DRIVER_VERSION
" (" DRIVER_RELDATE
")",
43 sizeof(drvinfo
->version
));
44 snprintf(drvinfo
->fw_version
, sizeof(drvinfo
->fw_version
),
46 fw_rev_maj(mdev
), fw_rev_min(mdev
), fw_rev_sub(mdev
));
47 strlcpy(drvinfo
->bus_info
, pci_name(mdev
->pdev
),
48 sizeof(drvinfo
->bus_info
));
51 struct ptys2ethtool_config
{
52 __ETHTOOL_DECLARE_LINK_MODE_MASK(supported
);
53 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertised
);
57 static struct ptys2ethtool_config ptys2ethtool_table
[MLX5E_LINK_MODES_NUMBER
];
59 #define MLX5_BUILD_PTYS2ETHTOOL_CONFIG(reg_, speed_, ...) \
61 struct ptys2ethtool_config *cfg; \
62 const unsigned int modes[] = { __VA_ARGS__ }; \
64 cfg = &ptys2ethtool_table[reg_]; \
65 cfg->speed = speed_; \
66 bitmap_zero(cfg->supported, \
67 __ETHTOOL_LINK_MODE_MASK_NBITS); \
68 bitmap_zero(cfg->advertised, \
69 __ETHTOOL_LINK_MODE_MASK_NBITS); \
70 for (i = 0 ; i < ARRAY_SIZE(modes) ; ++i) { \
71 __set_bit(modes[i], cfg->supported); \
72 __set_bit(modes[i], cfg->advertised); \
76 void mlx5e_build_ptys2ethtool_map(void)
78 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_1000BASE_CX_SGMII
, SPEED_1000
,
79 ETHTOOL_LINK_MODE_1000baseKX_Full_BIT
);
80 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_1000BASE_KX
, SPEED_1000
,
81 ETHTOOL_LINK_MODE_1000baseKX_Full_BIT
);
82 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_10GBASE_CX4
, SPEED_10000
,
83 ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT
);
84 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_10GBASE_KX4
, SPEED_10000
,
85 ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT
);
86 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_10GBASE_KR
, SPEED_10000
,
87 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT
);
88 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_20GBASE_KR2
, SPEED_20000
,
89 ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT
);
90 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_40GBASE_CR4
, SPEED_40000
,
91 ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT
);
92 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_40GBASE_KR4
, SPEED_40000
,
93 ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT
);
94 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_56GBASE_R4
, SPEED_56000
,
95 ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT
);
96 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_10GBASE_CR
, SPEED_10000
,
97 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT
);
98 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_10GBASE_SR
, SPEED_10000
,
99 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT
);
100 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_10GBASE_ER
, SPEED_10000
,
101 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT
);
102 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_40GBASE_SR4
, SPEED_40000
,
103 ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT
);
104 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_40GBASE_LR4
, SPEED_40000
,
105 ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT
);
106 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_50GBASE_SR2
, SPEED_50000
,
107 ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT
);
108 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_100GBASE_CR4
, SPEED_100000
,
109 ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT
);
110 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_100GBASE_SR4
, SPEED_100000
,
111 ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT
);
112 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_100GBASE_KR4
, SPEED_100000
,
113 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT
);
114 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_100GBASE_LR4
, SPEED_100000
,
115 ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT
);
116 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_10GBASE_T
, SPEED_10000
,
117 ETHTOOL_LINK_MODE_10000baseT_Full_BIT
);
118 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_25GBASE_CR
, SPEED_25000
,
119 ETHTOOL_LINK_MODE_25000baseCR_Full_BIT
);
120 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_25GBASE_KR
, SPEED_25000
,
121 ETHTOOL_LINK_MODE_25000baseKR_Full_BIT
);
122 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_25GBASE_SR
, SPEED_25000
,
123 ETHTOOL_LINK_MODE_25000baseSR_Full_BIT
);
124 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_50GBASE_CR2
, SPEED_50000
,
125 ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT
);
126 MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_50GBASE_KR2
, SPEED_50000
,
127 ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT
);
130 static unsigned long mlx5e_query_pfc_combined(struct mlx5e_priv
*priv
)
132 struct mlx5_core_dev
*mdev
= priv
->mdev
;
137 err
= mlx5_query_port_pfc(mdev
, &pfc_en_tx
, &pfc_en_rx
);
139 return err
? 0 : pfc_en_tx
| pfc_en_rx
;
142 static bool mlx5e_query_global_pause_combined(struct mlx5e_priv
*priv
)
144 struct mlx5_core_dev
*mdev
= priv
->mdev
;
149 err
= mlx5_query_port_pause(mdev
, &rx_pause
, &tx_pause
);
151 return err
? false : rx_pause
| tx_pause
;
154 #define MLX5E_NUM_Q_CNTRS(priv) (NUM_Q_COUNTERS * (!!priv->q_counter))
155 #define MLX5E_NUM_RQ_STATS(priv) \
156 (NUM_RQ_STATS * priv->params.num_channels * \
157 test_bit(MLX5E_STATE_OPENED, &priv->state))
158 #define MLX5E_NUM_SQ_STATS(priv) \
159 (NUM_SQ_STATS * priv->params.num_channels * priv->params.num_tc * \
160 test_bit(MLX5E_STATE_OPENED, &priv->state))
161 #define MLX5E_NUM_PFC_COUNTERS(priv) \
162 ((mlx5e_query_global_pause_combined(priv) + hweight8(mlx5e_query_pfc_combined(priv))) * \
163 NUM_PPORT_PER_PRIO_PFC_COUNTERS)
165 static int mlx5e_get_sset_count(struct net_device
*dev
, int sset
)
167 struct mlx5e_priv
*priv
= netdev_priv(dev
);
171 return NUM_SW_COUNTERS
+
172 MLX5E_NUM_Q_CNTRS(priv
) +
173 NUM_VPORT_COUNTERS
+ NUM_PPORT_COUNTERS
+
174 MLX5E_NUM_RQ_STATS(priv
) +
175 MLX5E_NUM_SQ_STATS(priv
) +
176 MLX5E_NUM_PFC_COUNTERS(priv
);
177 case ETH_SS_PRIV_FLAGS
:
178 return ARRAY_SIZE(mlx5e_priv_flags
);
185 static void mlx5e_fill_stats_strings(struct mlx5e_priv
*priv
, uint8_t *data
)
187 int i
, j
, tc
, prio
, idx
= 0;
188 unsigned long pfc_combined
;
191 for (i
= 0; i
< NUM_SW_COUNTERS
; i
++)
192 strcpy(data
+ (idx
++) * ETH_GSTRING_LEN
, sw_stats_desc
[i
].format
);
195 for (i
= 0; i
< MLX5E_NUM_Q_CNTRS(priv
); i
++)
196 strcpy(data
+ (idx
++) * ETH_GSTRING_LEN
, q_stats_desc
[i
].format
);
199 for (i
= 0; i
< NUM_VPORT_COUNTERS
; i
++)
200 strcpy(data
+ (idx
++) * ETH_GSTRING_LEN
,
201 vport_stats_desc
[i
].format
);
204 for (i
= 0; i
< NUM_PPORT_802_3_COUNTERS
; i
++)
205 strcpy(data
+ (idx
++) * ETH_GSTRING_LEN
,
206 pport_802_3_stats_desc
[i
].format
);
208 for (i
= 0; i
< NUM_PPORT_2863_COUNTERS
; i
++)
209 strcpy(data
+ (idx
++) * ETH_GSTRING_LEN
,
210 pport_2863_stats_desc
[i
].format
);
212 for (i
= 0; i
< NUM_PPORT_2819_COUNTERS
; i
++)
213 strcpy(data
+ (idx
++) * ETH_GSTRING_LEN
,
214 pport_2819_stats_desc
[i
].format
);
216 for (prio
= 0; prio
< NUM_PPORT_PRIO
; prio
++) {
217 for (i
= 0; i
< NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS
; i
++)
218 sprintf(data
+ (idx
++) * ETH_GSTRING_LEN
,
219 pport_per_prio_traffic_stats_desc
[i
].format
, prio
);
222 pfc_combined
= mlx5e_query_pfc_combined(priv
);
223 for_each_set_bit(prio
, &pfc_combined
, NUM_PPORT_PRIO
) {
224 for (i
= 0; i
< NUM_PPORT_PER_PRIO_PFC_COUNTERS
; i
++) {
225 char pfc_string
[ETH_GSTRING_LEN
];
227 snprintf(pfc_string
, sizeof(pfc_string
), "prio%d", prio
);
228 sprintf(data
+ (idx
++) * ETH_GSTRING_LEN
,
229 pport_per_prio_pfc_stats_desc
[i
].format
, pfc_string
);
233 if (mlx5e_query_global_pause_combined(priv
)) {
234 for (i
= 0; i
< NUM_PPORT_PER_PRIO_PFC_COUNTERS
; i
++) {
235 sprintf(data
+ (idx
++) * ETH_GSTRING_LEN
,
236 pport_per_prio_pfc_stats_desc
[i
].format
, "global");
240 if (!test_bit(MLX5E_STATE_OPENED
, &priv
->state
))
243 /* per channel counters */
244 for (i
= 0; i
< priv
->params
.num_channels
; i
++)
245 for (j
= 0; j
< NUM_RQ_STATS
; j
++)
246 sprintf(data
+ (idx
++) * ETH_GSTRING_LEN
,
247 rq_stats_desc
[j
].format
, i
);
249 for (tc
= 0; tc
< priv
->params
.num_tc
; tc
++)
250 for (i
= 0; i
< priv
->params
.num_channels
; i
++)
251 for (j
= 0; j
< NUM_SQ_STATS
; j
++)
252 sprintf(data
+ (idx
++) * ETH_GSTRING_LEN
,
253 sq_stats_desc
[j
].format
,
254 priv
->channeltc_to_txq_map
[i
][tc
]);
257 static void mlx5e_get_strings(struct net_device
*dev
,
258 uint32_t stringset
, uint8_t *data
)
260 struct mlx5e_priv
*priv
= netdev_priv(dev
);
264 case ETH_SS_PRIV_FLAGS
:
265 for (i
= 0; i
< ARRAY_SIZE(mlx5e_priv_flags
); i
++)
266 strcpy(data
+ i
* ETH_GSTRING_LEN
, mlx5e_priv_flags
[i
]);
273 mlx5e_fill_stats_strings(priv
, data
);
278 static void mlx5e_get_ethtool_stats(struct net_device
*dev
,
279 struct ethtool_stats
*stats
, u64
*data
)
281 struct mlx5e_priv
*priv
= netdev_priv(dev
);
282 int i
, j
, tc
, prio
, idx
= 0;
283 unsigned long pfc_combined
;
288 mutex_lock(&priv
->state_lock
);
289 if (test_bit(MLX5E_STATE_OPENED
, &priv
->state
))
290 mlx5e_update_stats(priv
);
291 mutex_unlock(&priv
->state_lock
);
293 for (i
= 0; i
< NUM_SW_COUNTERS
; i
++)
294 data
[idx
++] = MLX5E_READ_CTR64_CPU(&priv
->stats
.sw
,
297 for (i
= 0; i
< MLX5E_NUM_Q_CNTRS(priv
); i
++)
298 data
[idx
++] = MLX5E_READ_CTR32_CPU(&priv
->stats
.qcnt
,
301 for (i
= 0; i
< NUM_VPORT_COUNTERS
; i
++)
302 data
[idx
++] = MLX5E_READ_CTR64_BE(priv
->stats
.vport
.query_vport_out
,
303 vport_stats_desc
, i
);
305 for (i
= 0; i
< NUM_PPORT_802_3_COUNTERS
; i
++)
306 data
[idx
++] = MLX5E_READ_CTR64_BE(&priv
->stats
.pport
.IEEE_802_3_counters
,
307 pport_802_3_stats_desc
, i
);
309 for (i
= 0; i
< NUM_PPORT_2863_COUNTERS
; i
++)
310 data
[idx
++] = MLX5E_READ_CTR64_BE(&priv
->stats
.pport
.RFC_2863_counters
,
311 pport_2863_stats_desc
, i
);
313 for (i
= 0; i
< NUM_PPORT_2819_COUNTERS
; i
++)
314 data
[idx
++] = MLX5E_READ_CTR64_BE(&priv
->stats
.pport
.RFC_2819_counters
,
315 pport_2819_stats_desc
, i
);
317 for (prio
= 0; prio
< NUM_PPORT_PRIO
; prio
++) {
318 for (i
= 0; i
< NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS
; i
++)
319 data
[idx
++] = MLX5E_READ_CTR64_BE(&priv
->stats
.pport
.per_prio_counters
[prio
],
320 pport_per_prio_traffic_stats_desc
, i
);
323 pfc_combined
= mlx5e_query_pfc_combined(priv
);
324 for_each_set_bit(prio
, &pfc_combined
, NUM_PPORT_PRIO
) {
325 for (i
= 0; i
< NUM_PPORT_PER_PRIO_PFC_COUNTERS
; i
++) {
326 data
[idx
++] = MLX5E_READ_CTR64_BE(&priv
->stats
.pport
.per_prio_counters
[prio
],
327 pport_per_prio_pfc_stats_desc
, i
);
331 if (mlx5e_query_global_pause_combined(priv
)) {
332 for (i
= 0; i
< NUM_PPORT_PER_PRIO_PFC_COUNTERS
; i
++) {
333 data
[idx
++] = MLX5E_READ_CTR64_BE(&priv
->stats
.pport
.per_prio_counters
[0],
334 pport_per_prio_pfc_stats_desc
, 0);
338 if (!test_bit(MLX5E_STATE_OPENED
, &priv
->state
))
341 /* per channel counters */
342 for (i
= 0; i
< priv
->params
.num_channels
; i
++)
343 for (j
= 0; j
< NUM_RQ_STATS
; j
++)
345 MLX5E_READ_CTR64_CPU(&priv
->channel
[i
]->rq
.stats
,
348 for (tc
= 0; tc
< priv
->params
.num_tc
; tc
++)
349 for (i
= 0; i
< priv
->params
.num_channels
; i
++)
350 for (j
= 0; j
< NUM_SQ_STATS
; j
++)
351 data
[idx
++] = MLX5E_READ_CTR64_CPU(&priv
->channel
[i
]->sq
[tc
].stats
,
355 static void mlx5e_get_ringparam(struct net_device
*dev
,
356 struct ethtool_ringparam
*param
)
358 struct mlx5e_priv
*priv
= netdev_priv(dev
);
359 int rq_wq_type
= priv
->params
.rq_wq_type
;
361 param
->rx_max_pending
= 1 << mlx5_max_log_rq_size(rq_wq_type
);
362 param
->tx_max_pending
= 1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE
;
363 param
->rx_pending
= 1 << priv
->params
.log_rq_size
;
364 param
->tx_pending
= 1 << priv
->params
.log_sq_size
;
367 static int mlx5e_set_ringparam(struct net_device
*dev
,
368 struct ethtool_ringparam
*param
)
370 struct mlx5e_priv
*priv
= netdev_priv(dev
);
372 int rq_wq_type
= priv
->params
.rq_wq_type
;
378 if (param
->rx_jumbo_pending
) {
379 netdev_info(dev
, "%s: rx_jumbo_pending not supported\n",
383 if (param
->rx_mini_pending
) {
384 netdev_info(dev
, "%s: rx_mini_pending not supported\n",
388 if (param
->rx_pending
< (1 << mlx5_min_log_rq_size(rq_wq_type
))) {
389 netdev_info(dev
, "%s: rx_pending (%d) < min (%d)\n",
390 __func__
, param
->rx_pending
,
391 1 << mlx5_min_log_rq_size(rq_wq_type
));
394 if (param
->rx_pending
> (1 << mlx5_max_log_rq_size(rq_wq_type
))) {
395 netdev_info(dev
, "%s: rx_pending (%d) > max (%d)\n",
396 __func__
, param
->rx_pending
,
397 1 << mlx5_max_log_rq_size(rq_wq_type
));
400 if (param
->tx_pending
< (1 << MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE
)) {
401 netdev_info(dev
, "%s: tx_pending (%d) < min (%d)\n",
402 __func__
, param
->tx_pending
,
403 1 << MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE
);
406 if (param
->tx_pending
> (1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE
)) {
407 netdev_info(dev
, "%s: tx_pending (%d) > max (%d)\n",
408 __func__
, param
->tx_pending
,
409 1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE
);
413 log_rq_size
= order_base_2(param
->rx_pending
);
414 log_sq_size
= order_base_2(param
->tx_pending
);
415 min_rx_wqes
= mlx5_min_rx_wqes(rq_wq_type
, param
->rx_pending
);
417 if (log_rq_size
== priv
->params
.log_rq_size
&&
418 log_sq_size
== priv
->params
.log_sq_size
&&
419 min_rx_wqes
== priv
->params
.min_rx_wqes
)
422 mutex_lock(&priv
->state_lock
);
424 was_opened
= test_bit(MLX5E_STATE_OPENED
, &priv
->state
);
426 mlx5e_close_locked(dev
);
428 priv
->params
.log_rq_size
= log_rq_size
;
429 priv
->params
.log_sq_size
= log_sq_size
;
430 priv
->params
.min_rx_wqes
= min_rx_wqes
;
433 err
= mlx5e_open_locked(dev
);
435 mutex_unlock(&priv
->state_lock
);
440 static void mlx5e_get_channels(struct net_device
*dev
,
441 struct ethtool_channels
*ch
)
443 struct mlx5e_priv
*priv
= netdev_priv(dev
);
445 ch
->max_combined
= mlx5e_get_max_num_channels(priv
->mdev
);
446 ch
->combined_count
= priv
->params
.num_channels
;
449 static int mlx5e_set_channels(struct net_device
*dev
,
450 struct ethtool_channels
*ch
)
452 struct mlx5e_priv
*priv
= netdev_priv(dev
);
453 int ncv
= mlx5e_get_max_num_channels(priv
->mdev
);
454 unsigned int count
= ch
->combined_count
;
460 netdev_info(dev
, "%s: combined_count=0 not supported\n",
464 if (ch
->rx_count
|| ch
->tx_count
) {
465 netdev_info(dev
, "%s: separate rx/tx count not supported\n",
470 netdev_info(dev
, "%s: count (%d) > max (%d)\n",
471 __func__
, count
, ncv
);
475 if (priv
->params
.num_channels
== count
)
478 mutex_lock(&priv
->state_lock
);
480 was_opened
= test_bit(MLX5E_STATE_OPENED
, &priv
->state
);
482 mlx5e_close_locked(dev
);
484 arfs_enabled
= dev
->features
& NETIF_F_NTUPLE
;
486 mlx5e_arfs_disable(priv
);
488 priv
->params
.num_channels
= count
;
489 mlx5e_build_default_indir_rqt(priv
->mdev
, priv
->params
.indirection_rqt
,
490 MLX5E_INDIR_RQT_SIZE
, count
);
493 err
= mlx5e_open_locked(dev
);
498 err
= mlx5e_arfs_enable(priv
);
500 netdev_err(dev
, "%s: mlx5e_arfs_enable failed: %d\n",
505 mutex_unlock(&priv
->state_lock
);
510 static int mlx5e_get_coalesce(struct net_device
*netdev
,
511 struct ethtool_coalesce
*coal
)
513 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
515 if (!MLX5_CAP_GEN(priv
->mdev
, cq_moderation
))
518 coal
->rx_coalesce_usecs
= priv
->params
.rx_cq_moderation
.usec
;
519 coal
->rx_max_coalesced_frames
= priv
->params
.rx_cq_moderation
.pkts
;
520 coal
->tx_coalesce_usecs
= priv
->params
.tx_cq_moderation
.usec
;
521 coal
->tx_max_coalesced_frames
= priv
->params
.tx_cq_moderation
.pkts
;
522 coal
->use_adaptive_rx_coalesce
= priv
->params
.rx_am_enabled
;
527 static int mlx5e_set_coalesce(struct net_device
*netdev
,
528 struct ethtool_coalesce
*coal
)
530 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
531 struct mlx5_core_dev
*mdev
= priv
->mdev
;
532 struct mlx5e_channel
*c
;
534 !!coal
->use_adaptive_rx_coalesce
!= priv
->params
.rx_am_enabled
;
540 if (!MLX5_CAP_GEN(mdev
, cq_moderation
))
543 mutex_lock(&priv
->state_lock
);
545 was_opened
= test_bit(MLX5E_STATE_OPENED
, &priv
->state
);
546 if (was_opened
&& restart
) {
547 mlx5e_close_locked(netdev
);
548 priv
->params
.rx_am_enabled
= !!coal
->use_adaptive_rx_coalesce
;
551 priv
->params
.tx_cq_moderation
.usec
= coal
->tx_coalesce_usecs
;
552 priv
->params
.tx_cq_moderation
.pkts
= coal
->tx_max_coalesced_frames
;
553 priv
->params
.rx_cq_moderation
.usec
= coal
->rx_coalesce_usecs
;
554 priv
->params
.rx_cq_moderation
.pkts
= coal
->rx_max_coalesced_frames
;
556 if (!was_opened
|| restart
)
559 for (i
= 0; i
< priv
->params
.num_channels
; ++i
) {
560 c
= priv
->channel
[i
];
562 for (tc
= 0; tc
< c
->num_tc
; tc
++) {
563 mlx5_core_modify_cq_moderation(mdev
,
565 coal
->tx_coalesce_usecs
,
566 coal
->tx_max_coalesced_frames
);
569 mlx5_core_modify_cq_moderation(mdev
, &c
->rq
.cq
.mcq
,
570 coal
->rx_coalesce_usecs
,
571 coal
->rx_max_coalesced_frames
);
575 if (was_opened
&& restart
)
576 err
= mlx5e_open_locked(netdev
);
578 mutex_unlock(&priv
->state_lock
);
582 static void ptys2ethtool_supported_link(unsigned long *supported_modes
,
587 for_each_set_bit(proto
, (unsigned long *)ð_proto_cap
, MLX5E_LINK_MODES_NUMBER
)
588 bitmap_or(supported_modes
, supported_modes
,
589 ptys2ethtool_table
[proto
].supported
,
590 __ETHTOOL_LINK_MODE_MASK_NBITS
);
593 static void ptys2ethtool_adver_link(unsigned long *advertising_modes
,
598 for_each_set_bit(proto
, (unsigned long *)ð_proto_cap
, MLX5E_LINK_MODES_NUMBER
)
599 bitmap_or(advertising_modes
, advertising_modes
,
600 ptys2ethtool_table
[proto
].advertised
,
601 __ETHTOOL_LINK_MODE_MASK_NBITS
);
604 static void ptys2ethtool_supported_port(struct ethtool_link_ksettings
*link_ksettings
,
607 if (eth_proto_cap
& (MLX5E_PROT_MASK(MLX5E_10GBASE_CR
)
608 | MLX5E_PROT_MASK(MLX5E_10GBASE_SR
)
609 | MLX5E_PROT_MASK(MLX5E_40GBASE_CR4
)
610 | MLX5E_PROT_MASK(MLX5E_40GBASE_SR4
)
611 | MLX5E_PROT_MASK(MLX5E_100GBASE_SR4
)
612 | MLX5E_PROT_MASK(MLX5E_1000BASE_CX_SGMII
))) {
613 ethtool_link_ksettings_add_link_mode(link_ksettings
, supported
, FIBRE
);
616 if (eth_proto_cap
& (MLX5E_PROT_MASK(MLX5E_100GBASE_KR4
)
617 | MLX5E_PROT_MASK(MLX5E_40GBASE_KR4
)
618 | MLX5E_PROT_MASK(MLX5E_10GBASE_KR
)
619 | MLX5E_PROT_MASK(MLX5E_10GBASE_KX4
)
620 | MLX5E_PROT_MASK(MLX5E_1000BASE_KX
))) {
621 ethtool_link_ksettings_add_link_mode(link_ksettings
, supported
, Backplane
);
625 int mlx5e_get_max_linkspeed(struct mlx5_core_dev
*mdev
, u32
*speed
)
632 err
= mlx5_query_port_proto_cap(mdev
, &proto_cap
, MLX5_PTYS_EN
);
636 for (i
= 0; i
< MLX5E_LINK_MODES_NUMBER
; ++i
)
637 if (proto_cap
& MLX5E_PROT_MASK(i
))
638 max_speed
= max(max_speed
, ptys2ethtool_table
[i
].speed
);
644 static void get_speed_duplex(struct net_device
*netdev
,
646 struct ethtool_link_ksettings
*link_ksettings
)
649 u32 speed
= SPEED_UNKNOWN
;
650 u8 duplex
= DUPLEX_UNKNOWN
;
652 if (!netif_carrier_ok(netdev
))
655 for (i
= 0; i
< MLX5E_LINK_MODES_NUMBER
; ++i
) {
656 if (eth_proto_oper
& MLX5E_PROT_MASK(i
)) {
657 speed
= ptys2ethtool_table
[i
].speed
;
658 duplex
= DUPLEX_FULL
;
663 link_ksettings
->base
.speed
= speed
;
664 link_ksettings
->base
.duplex
= duplex
;
667 static void get_supported(u32 eth_proto_cap
,
668 struct ethtool_link_ksettings
*link_ksettings
)
670 unsigned long *supported
= link_ksettings
->link_modes
.supported
;
672 ptys2ethtool_supported_port(link_ksettings
, eth_proto_cap
);
673 ptys2ethtool_supported_link(supported
, eth_proto_cap
);
674 ethtool_link_ksettings_add_link_mode(link_ksettings
, supported
, Pause
);
675 ethtool_link_ksettings_add_link_mode(link_ksettings
, supported
, Asym_Pause
);
678 static void get_advertising(u32 eth_proto_cap
, u8 tx_pause
,
680 struct ethtool_link_ksettings
*link_ksettings
)
682 unsigned long *advertising
= link_ksettings
->link_modes
.advertising
;
684 ptys2ethtool_adver_link(advertising
, eth_proto_cap
);
686 ethtool_link_ksettings_add_link_mode(link_ksettings
, advertising
, Pause
);
687 if (tx_pause
^ rx_pause
)
688 ethtool_link_ksettings_add_link_mode(link_ksettings
, advertising
, Asym_Pause
);
691 static u8
get_connector_port(u32 eth_proto
)
693 if (eth_proto
& (MLX5E_PROT_MASK(MLX5E_10GBASE_SR
)
694 | MLX5E_PROT_MASK(MLX5E_40GBASE_SR4
)
695 | MLX5E_PROT_MASK(MLX5E_100GBASE_SR4
)
696 | MLX5E_PROT_MASK(MLX5E_1000BASE_CX_SGMII
))) {
700 if (eth_proto
& (MLX5E_PROT_MASK(MLX5E_40GBASE_CR4
)
701 | MLX5E_PROT_MASK(MLX5E_10GBASE_CR
)
702 | MLX5E_PROT_MASK(MLX5E_100GBASE_CR4
))) {
706 if (eth_proto
& (MLX5E_PROT_MASK(MLX5E_10GBASE_KX4
)
707 | MLX5E_PROT_MASK(MLX5E_10GBASE_KR
)
708 | MLX5E_PROT_MASK(MLX5E_40GBASE_KR4
)
709 | MLX5E_PROT_MASK(MLX5E_100GBASE_KR4
))) {
716 static void get_lp_advertising(u32 eth_proto_lp
,
717 struct ethtool_link_ksettings
*link_ksettings
)
719 unsigned long *lp_advertising
= link_ksettings
->link_modes
.lp_advertising
;
721 ptys2ethtool_adver_link(lp_advertising
, eth_proto_lp
);
724 static int mlx5e_get_link_ksettings(struct net_device
*netdev
,
725 struct ethtool_link_ksettings
*link_ksettings
)
727 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
728 struct mlx5_core_dev
*mdev
= priv
->mdev
;
729 u32 out
[MLX5_ST_SZ_DW(ptys_reg
)];
738 err
= mlx5_query_port_ptys(mdev
, out
, sizeof(out
), MLX5_PTYS_EN
, 1);
741 netdev_err(netdev
, "%s: query port ptys failed: %d\n",
746 eth_proto_cap
= MLX5_GET(ptys_reg
, out
, eth_proto_capability
);
747 eth_proto_admin
= MLX5_GET(ptys_reg
, out
, eth_proto_admin
);
748 eth_proto_oper
= MLX5_GET(ptys_reg
, out
, eth_proto_oper
);
749 eth_proto_lp
= MLX5_GET(ptys_reg
, out
, eth_proto_lp_advertise
);
750 an_disable_admin
= MLX5_GET(ptys_reg
, out
, an_disable_admin
);
751 an_status
= MLX5_GET(ptys_reg
, out
, an_status
);
753 ethtool_link_ksettings_zero_link_mode(link_ksettings
, supported
);
754 ethtool_link_ksettings_zero_link_mode(link_ksettings
, advertising
);
756 get_supported(eth_proto_cap
, link_ksettings
);
757 get_advertising(eth_proto_admin
, 0, 0, link_ksettings
);
758 get_speed_duplex(netdev
, eth_proto_oper
, link_ksettings
);
760 eth_proto_oper
= eth_proto_oper
? eth_proto_oper
: eth_proto_cap
;
762 link_ksettings
->base
.port
= get_connector_port(eth_proto_oper
);
763 get_lp_advertising(eth_proto_lp
, link_ksettings
);
765 if (an_status
== MLX5_AN_COMPLETE
)
766 ethtool_link_ksettings_add_link_mode(link_ksettings
,
767 lp_advertising
, Autoneg
);
769 link_ksettings
->base
.autoneg
= an_disable_admin
? AUTONEG_DISABLE
:
771 ethtool_link_ksettings_add_link_mode(link_ksettings
, supported
,
773 if (!an_disable_admin
)
774 ethtool_link_ksettings_add_link_mode(link_ksettings
,
775 advertising
, Autoneg
);
781 static u32
mlx5e_ethtool2ptys_adver_link(const unsigned long *link_modes
)
783 u32 i
, ptys_modes
= 0;
785 for (i
= 0; i
< MLX5E_LINK_MODES_NUMBER
; ++i
) {
786 if (bitmap_intersects(ptys2ethtool_table
[i
].advertised
,
788 __ETHTOOL_LINK_MODE_MASK_NBITS
))
789 ptys_modes
|= MLX5E_PROT_MASK(i
);
795 static u32
mlx5e_ethtool2ptys_speed_link(u32 speed
)
797 u32 i
, speed_links
= 0;
799 for (i
= 0; i
< MLX5E_LINK_MODES_NUMBER
; ++i
) {
800 if (ptys2ethtool_table
[i
].speed
== speed
)
801 speed_links
|= MLX5E_PROT_MASK(i
);
807 static int mlx5e_set_link_ksettings(struct net_device
*netdev
,
808 const struct ethtool_link_ksettings
*link_ksettings
)
810 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
811 struct mlx5_core_dev
*mdev
= priv
->mdev
;
812 u32 eth_proto_cap
, eth_proto_admin
;
813 bool an_changes
= false;
822 speed
= link_ksettings
->base
.speed
;
824 link_modes
= link_ksettings
->base
.autoneg
== AUTONEG_ENABLE
?
825 mlx5e_ethtool2ptys_adver_link(link_ksettings
->link_modes
.advertising
) :
826 mlx5e_ethtool2ptys_speed_link(speed
);
828 err
= mlx5_query_port_proto_cap(mdev
, ð_proto_cap
, MLX5_PTYS_EN
);
830 netdev_err(netdev
, "%s: query port eth proto cap failed: %d\n",
835 link_modes
= link_modes
& eth_proto_cap
;
837 netdev_err(netdev
, "%s: Not supported link mode(s) requested",
843 err
= mlx5_query_port_proto_admin(mdev
, ð_proto_admin
, MLX5_PTYS_EN
);
845 netdev_err(netdev
, "%s: query port eth proto admin failed: %d\n",
850 mlx5_query_port_autoneg(mdev
, MLX5_PTYS_EN
, &an_status
,
851 &an_disable_cap
, &an_disable_admin
);
853 an_disable
= link_ksettings
->base
.autoneg
== AUTONEG_DISABLE
;
854 an_changes
= ((!an_disable
&& an_disable_admin
) ||
855 (an_disable
&& !an_disable_admin
));
857 if (!an_changes
&& link_modes
== eth_proto_admin
)
860 mlx5_set_port_ptys(mdev
, an_disable
, link_modes
, MLX5_PTYS_EN
);
861 mlx5_toggle_port_link(mdev
);
867 static u32
mlx5e_get_rxfh_key_size(struct net_device
*netdev
)
869 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
871 return sizeof(priv
->params
.toeplitz_hash_key
);
874 static u32
mlx5e_get_rxfh_indir_size(struct net_device
*netdev
)
876 return MLX5E_INDIR_RQT_SIZE
;
879 static int mlx5e_get_rxfh(struct net_device
*netdev
, u32
*indir
, u8
*key
,
882 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
885 memcpy(indir
, priv
->params
.indirection_rqt
,
886 sizeof(priv
->params
.indirection_rqt
));
889 memcpy(key
, priv
->params
.toeplitz_hash_key
,
890 sizeof(priv
->params
.toeplitz_hash_key
));
893 *hfunc
= priv
->params
.rss_hfunc
;
898 static void mlx5e_modify_tirs_hash(struct mlx5e_priv
*priv
, void *in
, int inlen
)
900 struct mlx5_core_dev
*mdev
= priv
->mdev
;
901 void *tirc
= MLX5_ADDR_OF(modify_tir_in
, in
, ctx
);
904 MLX5_SET(modify_tir_in
, in
, bitmask
.hash
, 1);
905 mlx5e_build_tir_ctx_hash(tirc
, priv
);
907 for (i
= 0; i
< MLX5E_NUM_INDIR_TIRS
; i
++)
908 mlx5_core_modify_tir(mdev
, priv
->indir_tir
[i
].tirn
, in
, inlen
);
911 static int mlx5e_set_rxfh(struct net_device
*dev
, const u32
*indir
,
912 const u8
*key
, const u8 hfunc
)
914 struct mlx5e_priv
*priv
= netdev_priv(dev
);
915 int inlen
= MLX5_ST_SZ_BYTES(modify_tir_in
);
918 if ((hfunc
!= ETH_RSS_HASH_NO_CHANGE
) &&
919 (hfunc
!= ETH_RSS_HASH_XOR
) &&
920 (hfunc
!= ETH_RSS_HASH_TOP
))
923 in
= mlx5_vzalloc(inlen
);
927 mutex_lock(&priv
->state_lock
);
930 u32 rqtn
= priv
->indir_rqt
.rqtn
;
932 memcpy(priv
->params
.indirection_rqt
, indir
,
933 sizeof(priv
->params
.indirection_rqt
));
934 mlx5e_redirect_rqt(priv
, rqtn
, MLX5E_INDIR_RQT_SIZE
, 0);
938 memcpy(priv
->params
.toeplitz_hash_key
, key
,
939 sizeof(priv
->params
.toeplitz_hash_key
));
941 if (hfunc
!= ETH_RSS_HASH_NO_CHANGE
)
942 priv
->params
.rss_hfunc
= hfunc
;
944 mlx5e_modify_tirs_hash(priv
, in
, inlen
);
946 mutex_unlock(&priv
->state_lock
);
953 static int mlx5e_get_rxnfc(struct net_device
*netdev
,
954 struct ethtool_rxnfc
*info
, u32
*rule_locs
)
956 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
960 case ETHTOOL_GRXRINGS
:
961 info
->data
= priv
->params
.num_channels
;
963 case ETHTOOL_GRXCLSRLCNT
:
964 info
->rule_cnt
= priv
->fs
.ethtool
.tot_num_rules
;
966 case ETHTOOL_GRXCLSRULE
:
967 err
= mlx5e_ethtool_get_flow(priv
, info
, info
->fs
.location
);
969 case ETHTOOL_GRXCLSRLALL
:
970 err
= mlx5e_ethtool_get_all_flows(priv
, info
, rule_locs
);
980 static int mlx5e_get_tunable(struct net_device
*dev
,
981 const struct ethtool_tunable
*tuna
,
984 const struct mlx5e_priv
*priv
= netdev_priv(dev
);
988 case ETHTOOL_TX_COPYBREAK
:
989 *(u32
*)data
= priv
->params
.tx_max_inline
;
999 static int mlx5e_set_tunable(struct net_device
*dev
,
1000 const struct ethtool_tunable
*tuna
,
1003 struct mlx5e_priv
*priv
= netdev_priv(dev
);
1004 struct mlx5_core_dev
*mdev
= priv
->mdev
;
1010 case ETHTOOL_TX_COPYBREAK
:
1012 if (val
> mlx5e_get_max_inline_cap(mdev
)) {
1017 mutex_lock(&priv
->state_lock
);
1019 was_opened
= test_bit(MLX5E_STATE_OPENED
, &priv
->state
);
1021 mlx5e_close_locked(dev
);
1023 priv
->params
.tx_max_inline
= val
;
1026 err
= mlx5e_open_locked(dev
);
1028 mutex_unlock(&priv
->state_lock
);
1038 static void mlx5e_get_pauseparam(struct net_device
*netdev
,
1039 struct ethtool_pauseparam
*pauseparam
)
1041 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
1042 struct mlx5_core_dev
*mdev
= priv
->mdev
;
1045 err
= mlx5_query_port_pause(mdev
, &pauseparam
->rx_pause
,
1046 &pauseparam
->tx_pause
);
1048 netdev_err(netdev
, "%s: mlx5_query_port_pause failed:0x%x\n",
1053 static int mlx5e_set_pauseparam(struct net_device
*netdev
,
1054 struct ethtool_pauseparam
*pauseparam
)
1056 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
1057 struct mlx5_core_dev
*mdev
= priv
->mdev
;
1060 if (pauseparam
->autoneg
)
1063 err
= mlx5_set_port_pause(mdev
,
1064 pauseparam
->rx_pause
? 1 : 0,
1065 pauseparam
->tx_pause
? 1 : 0);
1067 netdev_err(netdev
, "%s: mlx5_set_port_pause failed:0x%x\n",
1074 static int mlx5e_get_ts_info(struct net_device
*dev
,
1075 struct ethtool_ts_info
*info
)
1077 struct mlx5e_priv
*priv
= netdev_priv(dev
);
1080 ret
= ethtool_op_get_ts_info(dev
, info
);
1084 info
->phc_index
= priv
->tstamp
.ptp
?
1085 ptp_clock_index(priv
->tstamp
.ptp
) : -1;
1087 if (!MLX5_CAP_GEN(priv
->mdev
, device_frequency_khz
))
1090 info
->so_timestamping
|= SOF_TIMESTAMPING_TX_HARDWARE
|
1091 SOF_TIMESTAMPING_RX_HARDWARE
|
1092 SOF_TIMESTAMPING_RAW_HARDWARE
;
1094 info
->tx_types
= (BIT(1) << HWTSTAMP_TX_OFF
) |
1095 (BIT(1) << HWTSTAMP_TX_ON
);
1097 info
->rx_filters
= (BIT(1) << HWTSTAMP_FILTER_NONE
) |
1098 (BIT(1) << HWTSTAMP_FILTER_ALL
);
1103 static __u32
mlx5e_get_wol_supported(struct mlx5_core_dev
*mdev
)
1107 if (MLX5_CAP_GEN(mdev
, wol_g
))
1110 if (MLX5_CAP_GEN(mdev
, wol_s
))
1111 ret
|= WAKE_MAGICSECURE
;
1113 if (MLX5_CAP_GEN(mdev
, wol_a
))
1116 if (MLX5_CAP_GEN(mdev
, wol_b
))
1119 if (MLX5_CAP_GEN(mdev
, wol_m
))
1122 if (MLX5_CAP_GEN(mdev
, wol_u
))
1125 if (MLX5_CAP_GEN(mdev
, wol_p
))
1131 static __u32
mlx5e_refomrat_wol_mode_mlx5_to_linux(u8 mode
)
1135 if (mode
& MLX5_WOL_MAGIC
)
1138 if (mode
& MLX5_WOL_SECURED_MAGIC
)
1139 ret
|= WAKE_MAGICSECURE
;
1141 if (mode
& MLX5_WOL_ARP
)
1144 if (mode
& MLX5_WOL_BROADCAST
)
1147 if (mode
& MLX5_WOL_MULTICAST
)
1150 if (mode
& MLX5_WOL_UNICAST
)
1153 if (mode
& MLX5_WOL_PHY_ACTIVITY
)
1159 static u8
mlx5e_refomrat_wol_mode_linux_to_mlx5(__u32 mode
)
1163 if (mode
& WAKE_MAGIC
)
1164 ret
|= MLX5_WOL_MAGIC
;
1166 if (mode
& WAKE_MAGICSECURE
)
1167 ret
|= MLX5_WOL_SECURED_MAGIC
;
1169 if (mode
& WAKE_ARP
)
1170 ret
|= MLX5_WOL_ARP
;
1172 if (mode
& WAKE_BCAST
)
1173 ret
|= MLX5_WOL_BROADCAST
;
1175 if (mode
& WAKE_MCAST
)
1176 ret
|= MLX5_WOL_MULTICAST
;
1178 if (mode
& WAKE_UCAST
)
1179 ret
|= MLX5_WOL_UNICAST
;
1181 if (mode
& WAKE_PHY
)
1182 ret
|= MLX5_WOL_PHY_ACTIVITY
;
1187 static void mlx5e_get_wol(struct net_device
*netdev
,
1188 struct ethtool_wolinfo
*wol
)
1190 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
1191 struct mlx5_core_dev
*mdev
= priv
->mdev
;
1195 memset(wol
, 0, sizeof(*wol
));
1197 wol
->supported
= mlx5e_get_wol_supported(mdev
);
1198 if (!wol
->supported
)
1201 err
= mlx5_query_port_wol(mdev
, &mlx5_wol_mode
);
1205 wol
->wolopts
= mlx5e_refomrat_wol_mode_mlx5_to_linux(mlx5_wol_mode
);
1208 static int mlx5e_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
1210 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
1211 struct mlx5_core_dev
*mdev
= priv
->mdev
;
1212 __u32 wol_supported
= mlx5e_get_wol_supported(mdev
);
1218 if (wol
->wolopts
& ~wol_supported
)
1221 mlx5_wol_mode
= mlx5e_refomrat_wol_mode_linux_to_mlx5(wol
->wolopts
);
1223 return mlx5_set_port_wol(mdev
, mlx5_wol_mode
);
1226 static int mlx5e_set_phys_id(struct net_device
*dev
,
1227 enum ethtool_phys_id_state state
)
1229 struct mlx5e_priv
*priv
= netdev_priv(dev
);
1230 struct mlx5_core_dev
*mdev
= priv
->mdev
;
1231 u16 beacon_duration
;
1233 if (!MLX5_CAP_GEN(mdev
, beacon_led
))
1237 case ETHTOOL_ID_ACTIVE
:
1238 beacon_duration
= MLX5_BEACON_DURATION_INF
;
1240 case ETHTOOL_ID_INACTIVE
:
1241 beacon_duration
= MLX5_BEACON_DURATION_OFF
;
1247 return mlx5_set_port_beacon(mdev
, beacon_duration
);
1250 static int mlx5e_get_module_info(struct net_device
*netdev
,
1251 struct ethtool_modinfo
*modinfo
)
1253 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
1254 struct mlx5_core_dev
*dev
= priv
->mdev
;
1258 size_read
= mlx5_query_module_eeprom(dev
, 0, 2, data
);
1262 /* data[0] = identifier byte */
1264 case MLX5_MODULE_ID_QSFP
:
1265 modinfo
->type
= ETH_MODULE_SFF_8436
;
1266 modinfo
->eeprom_len
= ETH_MODULE_SFF_8436_LEN
;
1268 case MLX5_MODULE_ID_QSFP_PLUS
:
1269 case MLX5_MODULE_ID_QSFP28
:
1270 /* data[1] = revision id */
1271 if (data
[0] == MLX5_MODULE_ID_QSFP28
|| data
[1] >= 0x3) {
1272 modinfo
->type
= ETH_MODULE_SFF_8636
;
1273 modinfo
->eeprom_len
= ETH_MODULE_SFF_8636_LEN
;
1275 modinfo
->type
= ETH_MODULE_SFF_8436
;
1276 modinfo
->eeprom_len
= ETH_MODULE_SFF_8436_LEN
;
1279 case MLX5_MODULE_ID_SFP
:
1280 modinfo
->type
= ETH_MODULE_SFF_8472
;
1281 modinfo
->eeprom_len
= ETH_MODULE_SFF_8472_LEN
;
1284 netdev_err(priv
->netdev
, "%s: cable type not recognized:0x%x\n",
1292 static int mlx5e_get_module_eeprom(struct net_device
*netdev
,
1293 struct ethtool_eeprom
*ee
,
1296 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
1297 struct mlx5_core_dev
*mdev
= priv
->mdev
;
1298 int offset
= ee
->offset
;
1305 memset(data
, 0, ee
->len
);
1307 while (i
< ee
->len
) {
1308 size_read
= mlx5_query_module_eeprom(mdev
, offset
, ee
->len
- i
,
1315 if (size_read
< 0) {
1316 netdev_err(priv
->netdev
, "%s: mlx5_query_eeprom failed:0x%x\n",
1317 __func__
, size_read
);
1322 offset
+= size_read
;
1328 typedef int (*mlx5e_pflag_handler
)(struct net_device
*netdev
, bool enable
);
1330 static int set_pflag_rx_cqe_based_moder(struct net_device
*netdev
, bool enable
)
1332 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
1333 struct mlx5_core_dev
*mdev
= priv
->mdev
;
1334 bool rx_mode_changed
;
1335 u8 rx_cq_period_mode
;
1339 rx_cq_period_mode
= enable
?
1340 MLX5_CQ_PERIOD_MODE_START_FROM_CQE
:
1341 MLX5_CQ_PERIOD_MODE_START_FROM_EQE
;
1342 rx_mode_changed
= rx_cq_period_mode
!= priv
->params
.rx_cq_period_mode
;
1344 if (rx_cq_period_mode
== MLX5_CQ_PERIOD_MODE_START_FROM_CQE
&&
1345 !MLX5_CAP_GEN(mdev
, cq_period_start_from_cqe
))
1348 if (!rx_mode_changed
)
1351 reset
= test_bit(MLX5E_STATE_OPENED
, &priv
->state
);
1353 mlx5e_close_locked(netdev
);
1355 mlx5e_set_rx_cq_mode_params(&priv
->params
, rx_cq_period_mode
);
1358 err
= mlx5e_open_locked(netdev
);
1363 static int mlx5e_handle_pflag(struct net_device
*netdev
,
1365 enum mlx5e_priv_flag flag
,
1366 mlx5e_pflag_handler pflag_handler
)
1368 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
1369 bool enable
= !!(wanted_flags
& flag
);
1370 u32 changes
= wanted_flags
^ priv
->pflags
;
1373 if (!(changes
& flag
))
1376 err
= pflag_handler(netdev
, enable
);
1378 netdev_err(netdev
, "%s private flag 0x%x failed err %d\n",
1379 enable
? "Enable" : "Disable", flag
, err
);
1383 MLX5E_SET_PRIV_FLAG(priv
, flag
, enable
);
1387 static int mlx5e_set_priv_flags(struct net_device
*netdev
, u32 pflags
)
1389 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
1392 mutex_lock(&priv
->state_lock
);
1394 err
= mlx5e_handle_pflag(netdev
, pflags
,
1395 MLX5E_PFLAG_RX_CQE_BASED_MODER
,
1396 set_pflag_rx_cqe_based_moder
);
1398 mutex_unlock(&priv
->state_lock
);
1399 return err
? -EINVAL
: 0;
1402 static u32
mlx5e_get_priv_flags(struct net_device
*netdev
)
1404 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
1406 return priv
->pflags
;
1409 static int mlx5e_set_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
)
1412 struct mlx5e_priv
*priv
= netdev_priv(dev
);
1415 case ETHTOOL_SRXCLSRLINS
:
1416 err
= mlx5e_ethtool_flow_replace(priv
, &cmd
->fs
);
1418 case ETHTOOL_SRXCLSRLDEL
:
1419 err
= mlx5e_ethtool_flow_remove(priv
, cmd
->fs
.location
);
1429 const struct ethtool_ops mlx5e_ethtool_ops
= {
1430 .get_drvinfo
= mlx5e_get_drvinfo
,
1431 .get_link
= ethtool_op_get_link
,
1432 .get_strings
= mlx5e_get_strings
,
1433 .get_sset_count
= mlx5e_get_sset_count
,
1434 .get_ethtool_stats
= mlx5e_get_ethtool_stats
,
1435 .get_ringparam
= mlx5e_get_ringparam
,
1436 .set_ringparam
= mlx5e_set_ringparam
,
1437 .get_channels
= mlx5e_get_channels
,
1438 .set_channels
= mlx5e_set_channels
,
1439 .get_coalesce
= mlx5e_get_coalesce
,
1440 .set_coalesce
= mlx5e_set_coalesce
,
1441 .get_link_ksettings
= mlx5e_get_link_ksettings
,
1442 .set_link_ksettings
= mlx5e_set_link_ksettings
,
1443 .get_rxfh_key_size
= mlx5e_get_rxfh_key_size
,
1444 .get_rxfh_indir_size
= mlx5e_get_rxfh_indir_size
,
1445 .get_rxfh
= mlx5e_get_rxfh
,
1446 .set_rxfh
= mlx5e_set_rxfh
,
1447 .get_rxnfc
= mlx5e_get_rxnfc
,
1448 .set_rxnfc
= mlx5e_set_rxnfc
,
1449 .get_tunable
= mlx5e_get_tunable
,
1450 .set_tunable
= mlx5e_set_tunable
,
1451 .get_pauseparam
= mlx5e_get_pauseparam
,
1452 .set_pauseparam
= mlx5e_set_pauseparam
,
1453 .get_ts_info
= mlx5e_get_ts_info
,
1454 .set_phys_id
= mlx5e_set_phys_id
,
1455 .get_wol
= mlx5e_get_wol
,
1456 .set_wol
= mlx5e_set_wol
,
1457 .get_module_info
= mlx5e_get_module_info
,
1458 .get_module_eeprom
= mlx5e_get_module_eeprom
,
1459 .get_priv_flags
= mlx5e_get_priv_flags
,
1460 .set_priv_flags
= mlx5e_set_priv_flags