]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
net/mlx5e: Fix number of PFC counters reported to ethtool
[linux.git] / drivers / net / ethernet / mellanox / mlx5 / core / en_ethtool.c
1 /*
2  * Copyright (c) 2015, Mellanox Technologies. All rights reserved.
3  *
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:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
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.
22  *
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
30  * SOFTWARE.
31  */
32
33 #include "en.h"
34
35 static void mlx5e_get_drvinfo(struct net_device *dev,
36                               struct ethtool_drvinfo *drvinfo)
37 {
38         struct mlx5e_priv *priv = netdev_priv(dev);
39         struct mlx5_core_dev *mdev = priv->mdev;
40
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),
45                  "%d.%d.%d",
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));
49 }
50
51 static const struct {
52         u32 supported;
53         u32 advertised;
54         u32 speed;
55 } ptys2ethtool_table[MLX5E_LINK_MODES_NUMBER] = {
56         [MLX5E_1000BASE_CX_SGMII] = {
57                 .supported  = SUPPORTED_1000baseKX_Full,
58                 .advertised = ADVERTISED_1000baseKX_Full,
59                 .speed      = 1000,
60         },
61         [MLX5E_1000BASE_KX] = {
62                 .supported  = SUPPORTED_1000baseKX_Full,
63                 .advertised = ADVERTISED_1000baseKX_Full,
64                 .speed      = 1000,
65         },
66         [MLX5E_10GBASE_CX4] = {
67                 .supported  = SUPPORTED_10000baseKX4_Full,
68                 .advertised = ADVERTISED_10000baseKX4_Full,
69                 .speed      = 10000,
70         },
71         [MLX5E_10GBASE_KX4] = {
72                 .supported  = SUPPORTED_10000baseKX4_Full,
73                 .advertised = ADVERTISED_10000baseKX4_Full,
74                 .speed      = 10000,
75         },
76         [MLX5E_10GBASE_KR] = {
77                 .supported  = SUPPORTED_10000baseKR_Full,
78                 .advertised = ADVERTISED_10000baseKR_Full,
79                 .speed      = 10000,
80         },
81         [MLX5E_20GBASE_KR2] = {
82                 .supported  = SUPPORTED_20000baseKR2_Full,
83                 .advertised = ADVERTISED_20000baseKR2_Full,
84                 .speed      = 20000,
85         },
86         [MLX5E_40GBASE_CR4] = {
87                 .supported  = SUPPORTED_40000baseCR4_Full,
88                 .advertised = ADVERTISED_40000baseCR4_Full,
89                 .speed      = 40000,
90         },
91         [MLX5E_40GBASE_KR4] = {
92                 .supported  = SUPPORTED_40000baseKR4_Full,
93                 .advertised = ADVERTISED_40000baseKR4_Full,
94                 .speed      = 40000,
95         },
96         [MLX5E_56GBASE_R4] = {
97                 .supported  = SUPPORTED_56000baseKR4_Full,
98                 .advertised = ADVERTISED_56000baseKR4_Full,
99                 .speed      = 56000,
100         },
101         [MLX5E_10GBASE_CR] = {
102                 .supported  = SUPPORTED_10000baseKR_Full,
103                 .advertised = ADVERTISED_10000baseKR_Full,
104                 .speed      = 10000,
105         },
106         [MLX5E_10GBASE_SR] = {
107                 .supported  = SUPPORTED_10000baseKR_Full,
108                 .advertised = ADVERTISED_10000baseKR_Full,
109                 .speed      = 10000,
110         },
111         [MLX5E_10GBASE_ER] = {
112                 .supported  = SUPPORTED_10000baseKR_Full,
113                 .advertised = ADVERTISED_10000baseKR_Full,
114                 .speed      = 10000,
115         },
116         [MLX5E_40GBASE_SR4] = {
117                 .supported  = SUPPORTED_40000baseSR4_Full,
118                 .advertised = ADVERTISED_40000baseSR4_Full,
119                 .speed      = 40000,
120         },
121         [MLX5E_40GBASE_LR4] = {
122                 .supported  = SUPPORTED_40000baseLR4_Full,
123                 .advertised = ADVERTISED_40000baseLR4_Full,
124                 .speed      = 40000,
125         },
126         [MLX5E_100GBASE_CR4] = {
127                 .speed      = 100000,
128         },
129         [MLX5E_100GBASE_SR4] = {
130                 .speed      = 100000,
131         },
132         [MLX5E_100GBASE_KR4] = {
133                 .speed      = 100000,
134         },
135         [MLX5E_100GBASE_LR4] = {
136                 .speed      = 100000,
137         },
138         [MLX5E_100BASE_TX]   = {
139                 .speed      = 100,
140         },
141         [MLX5E_1000BASE_T]    = {
142                 .supported  = SUPPORTED_1000baseT_Full,
143                 .advertised = ADVERTISED_1000baseT_Full,
144                 .speed      = 1000,
145         },
146         [MLX5E_10GBASE_T]    = {
147                 .supported  = SUPPORTED_10000baseT_Full,
148                 .advertised = ADVERTISED_10000baseT_Full,
149                 .speed      = 1000,
150         },
151         [MLX5E_25GBASE_CR]   = {
152                 .speed      = 25000,
153         },
154         [MLX5E_25GBASE_KR]   = {
155                 .speed      = 25000,
156         },
157         [MLX5E_25GBASE_SR]   = {
158                 .speed      = 25000,
159         },
160         [MLX5E_50GBASE_CR2]  = {
161                 .speed      = 50000,
162         },
163         [MLX5E_50GBASE_KR2]  = {
164                 .speed      = 50000,
165         },
166 };
167
168 static unsigned long mlx5e_query_pfc_combined(struct mlx5e_priv *priv)
169 {
170         struct mlx5_core_dev *mdev = priv->mdev;
171         u8 pfc_en_tx;
172         u8 pfc_en_rx;
173         int err;
174
175         err = mlx5_query_port_pfc(mdev, &pfc_en_tx, &pfc_en_rx);
176
177         return err ? 0 : pfc_en_tx | pfc_en_rx;
178 }
179
180 #define MLX5E_NUM_Q_CNTRS(priv) (NUM_Q_COUNTERS * (!!priv->q_counter))
181 #define MLX5E_NUM_RQ_STATS(priv) \
182         (NUM_RQ_STATS * priv->params.num_channels * \
183          test_bit(MLX5E_STATE_OPENED, &priv->state))
184 #define MLX5E_NUM_SQ_STATS(priv) \
185         (NUM_SQ_STATS * priv->params.num_channels * priv->params.num_tc * \
186          test_bit(MLX5E_STATE_OPENED, &priv->state))
187 #define MLX5E_NUM_PFC_COUNTERS(priv) \
188         (hweight8(mlx5e_query_pfc_combined(priv)) * \
189          NUM_PPORT_PER_PRIO_PFC_COUNTERS)
190
191 static int mlx5e_get_sset_count(struct net_device *dev, int sset)
192 {
193         struct mlx5e_priv *priv = netdev_priv(dev);
194
195         switch (sset) {
196         case ETH_SS_STATS:
197                 return NUM_SW_COUNTERS +
198                        MLX5E_NUM_Q_CNTRS(priv) +
199                        NUM_VPORT_COUNTERS + NUM_PPORT_COUNTERS +
200                        MLX5E_NUM_RQ_STATS(priv) +
201                        MLX5E_NUM_SQ_STATS(priv) +
202                        MLX5E_NUM_PFC_COUNTERS(priv);
203         /* fallthrough */
204         default:
205                 return -EOPNOTSUPP;
206         }
207 }
208
209 static void mlx5e_fill_stats_strings(struct mlx5e_priv *priv, uint8_t *data)
210 {
211         int i, j, tc, prio, idx = 0;
212         unsigned long pfc_combined;
213
214         /* SW counters */
215         for (i = 0; i < NUM_SW_COUNTERS; i++)
216                 strcpy(data + (idx++) * ETH_GSTRING_LEN, sw_stats_desc[i].name);
217
218         /* Q counters */
219         for (i = 0; i < MLX5E_NUM_Q_CNTRS(priv); i++)
220                 strcpy(data + (idx++) * ETH_GSTRING_LEN, q_stats_desc[i].name);
221
222         /* VPORT counters */
223         for (i = 0; i < NUM_VPORT_COUNTERS; i++)
224                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
225                        vport_stats_desc[i].name);
226
227         /* PPORT counters */
228         for (i = 0; i < NUM_PPORT_802_3_COUNTERS; i++)
229                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
230                        pport_802_3_stats_desc[i].name);
231
232         for (i = 0; i < NUM_PPORT_2863_COUNTERS; i++)
233                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
234                        pport_2863_stats_desc[i].name);
235
236         for (i = 0; i < NUM_PPORT_2819_COUNTERS; i++)
237                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
238                        pport_2819_stats_desc[i].name);
239
240         for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
241                 for (i = 0; i < NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS; i++)
242                         sprintf(data + (idx++) * ETH_GSTRING_LEN, "prio%d_%s",
243                                 prio,
244                                 pport_per_prio_traffic_stats_desc[i].name);
245         }
246
247         pfc_combined = mlx5e_query_pfc_combined(priv);
248         for_each_set_bit(prio, &pfc_combined, NUM_PPORT_PRIO) {
249                 for (i = 0; i < NUM_PPORT_PER_PRIO_PFC_COUNTERS; i++) {
250                         sprintf(data + (idx++) * ETH_GSTRING_LEN, "prio%d_%s",
251                                 prio, pport_per_prio_pfc_stats_desc[i].name);
252                 }
253         }
254
255         if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
256                 return;
257
258         /* per channel counters */
259         for (i = 0; i < priv->params.num_channels; i++)
260                 for (j = 0; j < NUM_RQ_STATS; j++)
261                         sprintf(data + (idx++) * ETH_GSTRING_LEN, "rx%d_%s", i,
262                                 rq_stats_desc[j].name);
263
264         for (tc = 0; tc < priv->params.num_tc; tc++)
265                 for (i = 0; i < priv->params.num_channels; i++)
266                         for (j = 0; j < NUM_SQ_STATS; j++)
267                                 sprintf(data + (idx++) * ETH_GSTRING_LEN,
268                                         "tx%d_%s",
269                                         priv->channeltc_to_txq_map[i][tc],
270                                         sq_stats_desc[j].name);
271 }
272
273 static void mlx5e_get_strings(struct net_device *dev,
274                               uint32_t stringset, uint8_t *data)
275 {
276         struct mlx5e_priv *priv = netdev_priv(dev);
277
278         switch (stringset) {
279         case ETH_SS_PRIV_FLAGS:
280                 break;
281
282         case ETH_SS_TEST:
283                 break;
284
285         case ETH_SS_STATS:
286                 mlx5e_fill_stats_strings(priv, data);
287                 break;
288         }
289 }
290
291 static void mlx5e_get_ethtool_stats(struct net_device *dev,
292                                     struct ethtool_stats *stats, u64 *data)
293 {
294         struct mlx5e_priv *priv = netdev_priv(dev);
295         int i, j, tc, prio, idx = 0;
296         unsigned long pfc_combined;
297
298         if (!data)
299                 return;
300
301         mutex_lock(&priv->state_lock);
302         if (test_bit(MLX5E_STATE_OPENED, &priv->state))
303                 mlx5e_update_stats(priv);
304         mutex_unlock(&priv->state_lock);
305
306         for (i = 0; i < NUM_SW_COUNTERS; i++)
307                 data[idx++] = MLX5E_READ_CTR64_CPU(&priv->stats.sw,
308                                                    sw_stats_desc, i);
309
310         for (i = 0; i < MLX5E_NUM_Q_CNTRS(priv); i++)
311                 data[idx++] = MLX5E_READ_CTR32_CPU(&priv->stats.qcnt,
312                                                    q_stats_desc, i);
313
314         for (i = 0; i < NUM_VPORT_COUNTERS; i++)
315                 data[idx++] = MLX5E_READ_CTR64_BE(priv->stats.vport.query_vport_out,
316                                                   vport_stats_desc, i);
317
318         for (i = 0; i < NUM_PPORT_802_3_COUNTERS; i++)
319                 data[idx++] = MLX5E_READ_CTR64_BE(&priv->stats.pport.IEEE_802_3_counters,
320                                                   pport_802_3_stats_desc, i);
321
322         for (i = 0; i < NUM_PPORT_2863_COUNTERS; i++)
323                 data[idx++] = MLX5E_READ_CTR64_BE(&priv->stats.pport.RFC_2863_counters,
324                                                   pport_2863_stats_desc, i);
325
326         for (i = 0; i < NUM_PPORT_2819_COUNTERS; i++)
327                 data[idx++] = MLX5E_READ_CTR64_BE(&priv->stats.pport.RFC_2819_counters,
328                                                   pport_2819_stats_desc, i);
329
330         for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
331                 for (i = 0; i < NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS; i++)
332                         data[idx++] = MLX5E_READ_CTR64_BE(&priv->stats.pport.per_prio_counters[prio],
333                                                  pport_per_prio_traffic_stats_desc, i);
334         }
335
336         pfc_combined = mlx5e_query_pfc_combined(priv);
337         for_each_set_bit(prio, &pfc_combined, NUM_PPORT_PRIO) {
338                 for (i = 0; i < NUM_PPORT_PER_PRIO_PFC_COUNTERS; i++) {
339                         data[idx++] = MLX5E_READ_CTR64_BE(&priv->stats.pport.per_prio_counters[prio],
340                                                           pport_per_prio_pfc_stats_desc, i);
341                 }
342         }
343
344         if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
345                 return;
346
347         /* per channel counters */
348         for (i = 0; i < priv->params.num_channels; i++)
349                 for (j = 0; j < NUM_RQ_STATS; j++)
350                         data[idx++] =
351                                MLX5E_READ_CTR64_CPU(&priv->channel[i]->rq.stats,
352                                                     rq_stats_desc, j);
353
354         for (tc = 0; tc < priv->params.num_tc; tc++)
355                 for (i = 0; i < priv->params.num_channels; i++)
356                         for (j = 0; j < NUM_SQ_STATS; j++)
357                                 data[idx++] = MLX5E_READ_CTR64_CPU(&priv->channel[i]->sq[tc].stats,
358                                                                    sq_stats_desc, j);
359 }
360
361 static void mlx5e_get_ringparam(struct net_device *dev,
362                                 struct ethtool_ringparam *param)
363 {
364         struct mlx5e_priv *priv = netdev_priv(dev);
365         int rq_wq_type = priv->params.rq_wq_type;
366
367         param->rx_max_pending = 1 << mlx5_max_log_rq_size(rq_wq_type);
368         param->tx_max_pending = 1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE;
369         param->rx_pending     = 1 << priv->params.log_rq_size;
370         param->tx_pending     = 1 << priv->params.log_sq_size;
371 }
372
373 static int mlx5e_set_ringparam(struct net_device *dev,
374                                struct ethtool_ringparam *param)
375 {
376         struct mlx5e_priv *priv = netdev_priv(dev);
377         bool was_opened;
378         int rq_wq_type = priv->params.rq_wq_type;
379         u16 min_rx_wqes;
380         u8 log_rq_size;
381         u8 log_sq_size;
382         int err = 0;
383
384         if (param->rx_jumbo_pending) {
385                 netdev_info(dev, "%s: rx_jumbo_pending not supported\n",
386                             __func__);
387                 return -EINVAL;
388         }
389         if (param->rx_mini_pending) {
390                 netdev_info(dev, "%s: rx_mini_pending not supported\n",
391                             __func__);
392                 return -EINVAL;
393         }
394         if (param->rx_pending < (1 << mlx5_min_log_rq_size(rq_wq_type))) {
395                 netdev_info(dev, "%s: rx_pending (%d) < min (%d)\n",
396                             __func__, param->rx_pending,
397                             1 << mlx5_min_log_rq_size(rq_wq_type));
398                 return -EINVAL;
399         }
400         if (param->rx_pending > (1 << mlx5_max_log_rq_size(rq_wq_type))) {
401                 netdev_info(dev, "%s: rx_pending (%d) > max (%d)\n",
402                             __func__, param->rx_pending,
403                             1 << mlx5_max_log_rq_size(rq_wq_type));
404                 return -EINVAL;
405         }
406         if (param->tx_pending < (1 << MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE)) {
407                 netdev_info(dev, "%s: tx_pending (%d) < min (%d)\n",
408                             __func__, param->tx_pending,
409                             1 << MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE);
410                 return -EINVAL;
411         }
412         if (param->tx_pending > (1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE)) {
413                 netdev_info(dev, "%s: tx_pending (%d) > max (%d)\n",
414                             __func__, param->tx_pending,
415                             1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE);
416                 return -EINVAL;
417         }
418
419         log_rq_size = order_base_2(param->rx_pending);
420         log_sq_size = order_base_2(param->tx_pending);
421         min_rx_wqes = mlx5_min_rx_wqes(rq_wq_type, param->rx_pending);
422
423         if (log_rq_size == priv->params.log_rq_size &&
424             log_sq_size == priv->params.log_sq_size &&
425             min_rx_wqes == priv->params.min_rx_wqes)
426                 return 0;
427
428         mutex_lock(&priv->state_lock);
429
430         was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
431         if (was_opened)
432                 mlx5e_close_locked(dev);
433
434         priv->params.log_rq_size = log_rq_size;
435         priv->params.log_sq_size = log_sq_size;
436         priv->params.min_rx_wqes = min_rx_wqes;
437
438         if (was_opened)
439                 err = mlx5e_open_locked(dev);
440
441         mutex_unlock(&priv->state_lock);
442
443         return err;
444 }
445
446 static void mlx5e_get_channels(struct net_device *dev,
447                                struct ethtool_channels *ch)
448 {
449         struct mlx5e_priv *priv = netdev_priv(dev);
450
451         ch->max_combined   = mlx5e_get_max_num_channels(priv->mdev);
452         ch->combined_count = priv->params.num_channels;
453 }
454
455 static int mlx5e_set_channels(struct net_device *dev,
456                               struct ethtool_channels *ch)
457 {
458         struct mlx5e_priv *priv = netdev_priv(dev);
459         int ncv = mlx5e_get_max_num_channels(priv->mdev);
460         unsigned int count = ch->combined_count;
461         bool arfs_enabled;
462         bool was_opened;
463         int err = 0;
464
465         if (!count) {
466                 netdev_info(dev, "%s: combined_count=0 not supported\n",
467                             __func__);
468                 return -EINVAL;
469         }
470         if (ch->rx_count || ch->tx_count) {
471                 netdev_info(dev, "%s: separate rx/tx count not supported\n",
472                             __func__);
473                 return -EINVAL;
474         }
475         if (count > ncv) {
476                 netdev_info(dev, "%s: count (%d) > max (%d)\n",
477                             __func__, count, ncv);
478                 return -EINVAL;
479         }
480
481         if (priv->params.num_channels == count)
482                 return 0;
483
484         mutex_lock(&priv->state_lock);
485
486         was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
487         if (was_opened)
488                 mlx5e_close_locked(dev);
489
490         arfs_enabled = dev->features & NETIF_F_NTUPLE;
491         if (arfs_enabled)
492                 mlx5e_arfs_disable(priv);
493
494         priv->params.num_channels = count;
495         mlx5e_build_default_indir_rqt(priv->mdev, priv->params.indirection_rqt,
496                                       MLX5E_INDIR_RQT_SIZE, count);
497
498         if (was_opened)
499                 err = mlx5e_open_locked(dev);
500         if (err)
501                 goto out;
502
503         if (arfs_enabled) {
504                 err = mlx5e_arfs_enable(priv);
505                 if (err)
506                         netdev_err(dev, "%s: mlx5e_arfs_enable failed: %d\n",
507                                    __func__, err);
508         }
509
510 out:
511         mutex_unlock(&priv->state_lock);
512
513         return err;
514 }
515
516 static int mlx5e_get_coalesce(struct net_device *netdev,
517                               struct ethtool_coalesce *coal)
518 {
519         struct mlx5e_priv *priv = netdev_priv(netdev);
520
521         if (!MLX5_CAP_GEN(priv->mdev, cq_moderation))
522                 return -ENOTSUPP;
523
524         coal->rx_coalesce_usecs       = priv->params.rx_cq_moderation_usec;
525         coal->rx_max_coalesced_frames = priv->params.rx_cq_moderation_pkts;
526         coal->tx_coalesce_usecs       = priv->params.tx_cq_moderation_usec;
527         coal->tx_max_coalesced_frames = priv->params.tx_cq_moderation_pkts;
528
529         return 0;
530 }
531
532 static int mlx5e_set_coalesce(struct net_device *netdev,
533                               struct ethtool_coalesce *coal)
534 {
535         struct mlx5e_priv *priv    = netdev_priv(netdev);
536         struct mlx5_core_dev *mdev = priv->mdev;
537         struct mlx5e_channel *c;
538         int tc;
539         int i;
540
541         if (!MLX5_CAP_GEN(mdev, cq_moderation))
542                 return -ENOTSUPP;
543
544         mutex_lock(&priv->state_lock);
545         priv->params.tx_cq_moderation_usec = coal->tx_coalesce_usecs;
546         priv->params.tx_cq_moderation_pkts = coal->tx_max_coalesced_frames;
547         priv->params.rx_cq_moderation_usec = coal->rx_coalesce_usecs;
548         priv->params.rx_cq_moderation_pkts = coal->rx_max_coalesced_frames;
549
550         if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
551                 goto out;
552
553         for (i = 0; i < priv->params.num_channels; ++i) {
554                 c = priv->channel[i];
555
556                 for (tc = 0; tc < c->num_tc; tc++) {
557                         mlx5_core_modify_cq_moderation(mdev,
558                                                 &c->sq[tc].cq.mcq,
559                                                 coal->tx_coalesce_usecs,
560                                                 coal->tx_max_coalesced_frames);
561                 }
562
563                 mlx5_core_modify_cq_moderation(mdev, &c->rq.cq.mcq,
564                                                coal->rx_coalesce_usecs,
565                                                coal->rx_max_coalesced_frames);
566         }
567
568 out:
569         mutex_unlock(&priv->state_lock);
570         return 0;
571 }
572
573 static u32 ptys2ethtool_supported_link(u32 eth_proto_cap)
574 {
575         int i;
576         u32 supported_modes = 0;
577
578         for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i) {
579                 if (eth_proto_cap & MLX5E_PROT_MASK(i))
580                         supported_modes |= ptys2ethtool_table[i].supported;
581         }
582         return supported_modes;
583 }
584
585 static u32 ptys2ethtool_adver_link(u32 eth_proto_cap)
586 {
587         int i;
588         u32 advertising_modes = 0;
589
590         for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i) {
591                 if (eth_proto_cap & MLX5E_PROT_MASK(i))
592                         advertising_modes |= ptys2ethtool_table[i].advertised;
593         }
594         return advertising_modes;
595 }
596
597 static u32 ptys2ethtool_supported_port(u32 eth_proto_cap)
598 {
599         if (eth_proto_cap & (MLX5E_PROT_MASK(MLX5E_10GBASE_CR)
600                            | MLX5E_PROT_MASK(MLX5E_10GBASE_SR)
601                            | MLX5E_PROT_MASK(MLX5E_40GBASE_CR4)
602                            | MLX5E_PROT_MASK(MLX5E_40GBASE_SR4)
603                            | MLX5E_PROT_MASK(MLX5E_100GBASE_SR4)
604                            | MLX5E_PROT_MASK(MLX5E_1000BASE_CX_SGMII))) {
605                 return SUPPORTED_FIBRE;
606         }
607
608         if (eth_proto_cap & (MLX5E_PROT_MASK(MLX5E_100GBASE_KR4)
609                            | MLX5E_PROT_MASK(MLX5E_40GBASE_KR4)
610                            | MLX5E_PROT_MASK(MLX5E_10GBASE_KR)
611                            | MLX5E_PROT_MASK(MLX5E_10GBASE_KX4)
612                            | MLX5E_PROT_MASK(MLX5E_1000BASE_KX))) {
613                 return SUPPORTED_Backplane;
614         }
615         return 0;
616 }
617
618 int mlx5e_get_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed)
619 {
620         u32 max_speed = 0;
621         u32 proto_cap;
622         int err;
623         int i;
624
625         err = mlx5_query_port_proto_cap(mdev, &proto_cap, MLX5_PTYS_EN);
626         if (err)
627                 return err;
628
629         for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i)
630                 if (proto_cap & MLX5E_PROT_MASK(i))
631                         max_speed = max(max_speed, ptys2ethtool_table[i].speed);
632
633         *speed = max_speed;
634         return 0;
635 }
636
637 static void get_speed_duplex(struct net_device *netdev,
638                              u32 eth_proto_oper,
639                              struct ethtool_cmd *cmd)
640 {
641         int i;
642         u32 speed = SPEED_UNKNOWN;
643         u8 duplex = DUPLEX_UNKNOWN;
644
645         if (!netif_carrier_ok(netdev))
646                 goto out;
647
648         for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i) {
649                 if (eth_proto_oper & MLX5E_PROT_MASK(i)) {
650                         speed = ptys2ethtool_table[i].speed;
651                         duplex = DUPLEX_FULL;
652                         break;
653                 }
654         }
655 out:
656         ethtool_cmd_speed_set(cmd, speed);
657         cmd->duplex = duplex;
658 }
659
660 static void get_supported(u32 eth_proto_cap, u32 *supported)
661 {
662         *supported |= ptys2ethtool_supported_port(eth_proto_cap);
663         *supported |= ptys2ethtool_supported_link(eth_proto_cap);
664         *supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
665 }
666
667 static void get_advertising(u32 eth_proto_cap, u8 tx_pause,
668                             u8 rx_pause, u32 *advertising)
669 {
670         *advertising |= ptys2ethtool_adver_link(eth_proto_cap);
671         *advertising |= tx_pause ? ADVERTISED_Pause : 0;
672         *advertising |= (tx_pause ^ rx_pause) ? ADVERTISED_Asym_Pause : 0;
673 }
674
675 static u8 get_connector_port(u32 eth_proto)
676 {
677         if (eth_proto & (MLX5E_PROT_MASK(MLX5E_10GBASE_SR)
678                          | MLX5E_PROT_MASK(MLX5E_40GBASE_SR4)
679                          | MLX5E_PROT_MASK(MLX5E_100GBASE_SR4)
680                          | MLX5E_PROT_MASK(MLX5E_1000BASE_CX_SGMII))) {
681                         return PORT_FIBRE;
682         }
683
684         if (eth_proto & (MLX5E_PROT_MASK(MLX5E_40GBASE_CR4)
685                          | MLX5E_PROT_MASK(MLX5E_10GBASE_CR)
686                          | MLX5E_PROT_MASK(MLX5E_100GBASE_CR4))) {
687                         return PORT_DA;
688         }
689
690         if (eth_proto & (MLX5E_PROT_MASK(MLX5E_10GBASE_KX4)
691                          | MLX5E_PROT_MASK(MLX5E_10GBASE_KR)
692                          | MLX5E_PROT_MASK(MLX5E_40GBASE_KR4)
693                          | MLX5E_PROT_MASK(MLX5E_100GBASE_KR4))) {
694                         return PORT_NONE;
695         }
696
697         return PORT_OTHER;
698 }
699
700 static void get_lp_advertising(u32 eth_proto_lp, u32 *lp_advertising)
701 {
702         *lp_advertising = ptys2ethtool_adver_link(eth_proto_lp);
703 }
704
705 static int mlx5e_get_settings(struct net_device *netdev,
706                               struct ethtool_cmd *cmd)
707 {
708         struct mlx5e_priv *priv    = netdev_priv(netdev);
709         struct mlx5_core_dev *mdev = priv->mdev;
710         u32 out[MLX5_ST_SZ_DW(ptys_reg)];
711         u32 eth_proto_cap;
712         u32 eth_proto_admin;
713         u32 eth_proto_lp;
714         u32 eth_proto_oper;
715         int err;
716
717         err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, 1);
718
719         if (err) {
720                 netdev_err(netdev, "%s: query port ptys failed: %d\n",
721                            __func__, err);
722                 goto err_query_ptys;
723         }
724
725         eth_proto_cap   = MLX5_GET(ptys_reg, out, eth_proto_capability);
726         eth_proto_admin = MLX5_GET(ptys_reg, out, eth_proto_admin);
727         eth_proto_oper  = MLX5_GET(ptys_reg, out, eth_proto_oper);
728         eth_proto_lp    = MLX5_GET(ptys_reg, out, eth_proto_lp_advertise);
729
730         cmd->supported   = 0;
731         cmd->advertising = 0;
732
733         get_supported(eth_proto_cap, &cmd->supported);
734         get_advertising(eth_proto_admin, 0, 0, &cmd->advertising);
735         get_speed_duplex(netdev, eth_proto_oper, cmd);
736
737         eth_proto_oper = eth_proto_oper ? eth_proto_oper : eth_proto_cap;
738
739         cmd->port = get_connector_port(eth_proto_oper);
740         get_lp_advertising(eth_proto_lp, &cmd->lp_advertising);
741
742         cmd->transceiver = XCVR_INTERNAL;
743
744 err_query_ptys:
745         return err;
746 }
747
748 static u32 mlx5e_ethtool2ptys_adver_link(u32 link_modes)
749 {
750         u32 i, ptys_modes = 0;
751
752         for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i) {
753                 if (ptys2ethtool_table[i].advertised & link_modes)
754                         ptys_modes |= MLX5E_PROT_MASK(i);
755         }
756
757         return ptys_modes;
758 }
759
760 static u32 mlx5e_ethtool2ptys_speed_link(u32 speed)
761 {
762         u32 i, speed_links = 0;
763
764         for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i) {
765                 if (ptys2ethtool_table[i].speed == speed)
766                         speed_links |= MLX5E_PROT_MASK(i);
767         }
768
769         return speed_links;
770 }
771
772 static int mlx5e_set_settings(struct net_device *netdev,
773                               struct ethtool_cmd *cmd)
774 {
775         struct mlx5e_priv *priv    = netdev_priv(netdev);
776         struct mlx5_core_dev *mdev = priv->mdev;
777         u32 link_modes;
778         u32 speed;
779         u32 eth_proto_cap, eth_proto_admin;
780         enum mlx5_port_status ps;
781         int err;
782
783         speed = ethtool_cmd_speed(cmd);
784
785         link_modes = cmd->autoneg == AUTONEG_ENABLE ?
786                 mlx5e_ethtool2ptys_adver_link(cmd->advertising) :
787                 mlx5e_ethtool2ptys_speed_link(speed);
788
789         err = mlx5_query_port_proto_cap(mdev, &eth_proto_cap, MLX5_PTYS_EN);
790         if (err) {
791                 netdev_err(netdev, "%s: query port eth proto cap failed: %d\n",
792                            __func__, err);
793                 goto out;
794         }
795
796         link_modes = link_modes & eth_proto_cap;
797         if (!link_modes) {
798                 netdev_err(netdev, "%s: Not supported link mode(s) requested",
799                            __func__);
800                 err = -EINVAL;
801                 goto out;
802         }
803
804         err = mlx5_query_port_proto_admin(mdev, &eth_proto_admin, MLX5_PTYS_EN);
805         if (err) {
806                 netdev_err(netdev, "%s: query port eth proto admin failed: %d\n",
807                            __func__, err);
808                 goto out;
809         }
810
811         if (link_modes == eth_proto_admin)
812                 goto out;
813
814         mlx5_query_port_admin_status(mdev, &ps);
815         if (ps == MLX5_PORT_UP)
816                 mlx5_set_port_admin_status(mdev, MLX5_PORT_DOWN);
817         mlx5_set_port_proto(mdev, link_modes, MLX5_PTYS_EN);
818         if (ps == MLX5_PORT_UP)
819                 mlx5_set_port_admin_status(mdev, MLX5_PORT_UP);
820
821 out:
822         return err;
823 }
824
825 static u32 mlx5e_get_rxfh_key_size(struct net_device *netdev)
826 {
827         struct mlx5e_priv *priv = netdev_priv(netdev);
828
829         return sizeof(priv->params.toeplitz_hash_key);
830 }
831
832 static u32 mlx5e_get_rxfh_indir_size(struct net_device *netdev)
833 {
834         return MLX5E_INDIR_RQT_SIZE;
835 }
836
837 static int mlx5e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
838                           u8 *hfunc)
839 {
840         struct mlx5e_priv *priv = netdev_priv(netdev);
841
842         if (indir)
843                 memcpy(indir, priv->params.indirection_rqt,
844                        sizeof(priv->params.indirection_rqt));
845
846         if (key)
847                 memcpy(key, priv->params.toeplitz_hash_key,
848                        sizeof(priv->params.toeplitz_hash_key));
849
850         if (hfunc)
851                 *hfunc = priv->params.rss_hfunc;
852
853         return 0;
854 }
855
856 static void mlx5e_modify_tirs_hash(struct mlx5e_priv *priv, void *in, int inlen)
857 {
858         struct mlx5_core_dev *mdev = priv->mdev;
859         void *tirc = MLX5_ADDR_OF(modify_tir_in, in, ctx);
860         int i;
861
862         MLX5_SET(modify_tir_in, in, bitmask.hash, 1);
863         mlx5e_build_tir_ctx_hash(tirc, priv);
864
865         for (i = 0; i < MLX5E_NUM_INDIR_TIRS; i++)
866                 mlx5_core_modify_tir(mdev, priv->indir_tirn[i], in, inlen);
867 }
868
869 static int mlx5e_set_rxfh(struct net_device *dev, const u32 *indir,
870                           const u8 *key, const u8 hfunc)
871 {
872         struct mlx5e_priv *priv = netdev_priv(dev);
873         int inlen = MLX5_ST_SZ_BYTES(modify_tir_in);
874         void *in;
875
876         if ((hfunc != ETH_RSS_HASH_NO_CHANGE) &&
877             (hfunc != ETH_RSS_HASH_XOR) &&
878             (hfunc != ETH_RSS_HASH_TOP))
879                 return -EINVAL;
880
881         in = mlx5_vzalloc(inlen);
882         if (!in)
883                 return -ENOMEM;
884
885         mutex_lock(&priv->state_lock);
886
887         if (indir) {
888                 u32 rqtn = priv->indir_rqtn;
889
890                 memcpy(priv->params.indirection_rqt, indir,
891                        sizeof(priv->params.indirection_rqt));
892                 mlx5e_redirect_rqt(priv, rqtn, MLX5E_INDIR_RQT_SIZE, 0);
893         }
894
895         if (key)
896                 memcpy(priv->params.toeplitz_hash_key, key,
897                        sizeof(priv->params.toeplitz_hash_key));
898
899         if (hfunc != ETH_RSS_HASH_NO_CHANGE)
900                 priv->params.rss_hfunc = hfunc;
901
902         mlx5e_modify_tirs_hash(priv, in, inlen);
903
904         mutex_unlock(&priv->state_lock);
905
906         kvfree(in);
907
908         return 0;
909 }
910
911 static int mlx5e_get_rxnfc(struct net_device *netdev,
912                            struct ethtool_rxnfc *info, u32 *rule_locs)
913 {
914         struct mlx5e_priv *priv = netdev_priv(netdev);
915         int err = 0;
916
917         switch (info->cmd) {
918         case ETHTOOL_GRXRINGS:
919                 info->data = priv->params.num_channels;
920                 break;
921         default:
922                 err = -EOPNOTSUPP;
923                 break;
924         }
925
926         return err;
927 }
928
929 static int mlx5e_get_tunable(struct net_device *dev,
930                              const struct ethtool_tunable *tuna,
931                              void *data)
932 {
933         const struct mlx5e_priv *priv = netdev_priv(dev);
934         int err = 0;
935
936         switch (tuna->id) {
937         case ETHTOOL_TX_COPYBREAK:
938                 *(u32 *)data = priv->params.tx_max_inline;
939                 break;
940         default:
941                 err = -EINVAL;
942                 break;
943         }
944
945         return err;
946 }
947
948 static int mlx5e_set_tunable(struct net_device *dev,
949                              const struct ethtool_tunable *tuna,
950                              const void *data)
951 {
952         struct mlx5e_priv *priv = netdev_priv(dev);
953         struct mlx5_core_dev *mdev = priv->mdev;
954         bool was_opened;
955         u32 val;
956         int err = 0;
957
958         switch (tuna->id) {
959         case ETHTOOL_TX_COPYBREAK:
960                 val = *(u32 *)data;
961                 if (val > mlx5e_get_max_inline_cap(mdev)) {
962                         err = -EINVAL;
963                         break;
964                 }
965
966                 mutex_lock(&priv->state_lock);
967
968                 was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
969                 if (was_opened)
970                         mlx5e_close_locked(dev);
971
972                 priv->params.tx_max_inline = val;
973
974                 if (was_opened)
975                         err = mlx5e_open_locked(dev);
976
977                 mutex_unlock(&priv->state_lock);
978                 break;
979         default:
980                 err = -EINVAL;
981                 break;
982         }
983
984         return err;
985 }
986
987 static void mlx5e_get_pauseparam(struct net_device *netdev,
988                                  struct ethtool_pauseparam *pauseparam)
989 {
990         struct mlx5e_priv *priv    = netdev_priv(netdev);
991         struct mlx5_core_dev *mdev = priv->mdev;
992         int err;
993
994         err = mlx5_query_port_pause(mdev, &pauseparam->rx_pause,
995                                     &pauseparam->tx_pause);
996         if (err) {
997                 netdev_err(netdev, "%s: mlx5_query_port_pause failed:0x%x\n",
998                            __func__, err);
999         }
1000 }
1001
1002 static int mlx5e_set_pauseparam(struct net_device *netdev,
1003                                 struct ethtool_pauseparam *pauseparam)
1004 {
1005         struct mlx5e_priv *priv    = netdev_priv(netdev);
1006         struct mlx5_core_dev *mdev = priv->mdev;
1007         int err;
1008
1009         if (pauseparam->autoneg)
1010                 return -EINVAL;
1011
1012         err = mlx5_set_port_pause(mdev,
1013                                   pauseparam->rx_pause ? 1 : 0,
1014                                   pauseparam->tx_pause ? 1 : 0);
1015         if (err) {
1016                 netdev_err(netdev, "%s: mlx5_set_port_pause failed:0x%x\n",
1017                            __func__, err);
1018         }
1019
1020         return err;
1021 }
1022
1023 static int mlx5e_get_ts_info(struct net_device *dev,
1024                              struct ethtool_ts_info *info)
1025 {
1026         struct mlx5e_priv *priv = netdev_priv(dev);
1027         int ret;
1028
1029         ret = ethtool_op_get_ts_info(dev, info);
1030         if (ret)
1031                 return ret;
1032
1033         info->phc_index = priv->tstamp.ptp ?
1034                           ptp_clock_index(priv->tstamp.ptp) : -1;
1035
1036         if (!MLX5_CAP_GEN(priv->mdev, device_frequency_khz))
1037                 return 0;
1038
1039         info->so_timestamping |= SOF_TIMESTAMPING_TX_HARDWARE |
1040                                  SOF_TIMESTAMPING_RX_HARDWARE |
1041                                  SOF_TIMESTAMPING_RAW_HARDWARE;
1042
1043         info->tx_types = (BIT(1) << HWTSTAMP_TX_OFF) |
1044                          (BIT(1) << HWTSTAMP_TX_ON);
1045
1046         info->rx_filters = (BIT(1) << HWTSTAMP_FILTER_NONE) |
1047                            (BIT(1) << HWTSTAMP_FILTER_ALL);
1048
1049         return 0;
1050 }
1051
1052 static __u32 mlx5e_get_wol_supported(struct mlx5_core_dev *mdev)
1053 {
1054         __u32 ret = 0;
1055
1056         if (MLX5_CAP_GEN(mdev, wol_g))
1057                 ret |= WAKE_MAGIC;
1058
1059         if (MLX5_CAP_GEN(mdev, wol_s))
1060                 ret |= WAKE_MAGICSECURE;
1061
1062         if (MLX5_CAP_GEN(mdev, wol_a))
1063                 ret |= WAKE_ARP;
1064
1065         if (MLX5_CAP_GEN(mdev, wol_b))
1066                 ret |= WAKE_BCAST;
1067
1068         if (MLX5_CAP_GEN(mdev, wol_m))
1069                 ret |= WAKE_MCAST;
1070
1071         if (MLX5_CAP_GEN(mdev, wol_u))
1072                 ret |= WAKE_UCAST;
1073
1074         if (MLX5_CAP_GEN(mdev, wol_p))
1075                 ret |= WAKE_PHY;
1076
1077         return ret;
1078 }
1079
1080 static __u32 mlx5e_refomrat_wol_mode_mlx5_to_linux(u8 mode)
1081 {
1082         __u32 ret = 0;
1083
1084         if (mode & MLX5_WOL_MAGIC)
1085                 ret |= WAKE_MAGIC;
1086
1087         if (mode & MLX5_WOL_SECURED_MAGIC)
1088                 ret |= WAKE_MAGICSECURE;
1089
1090         if (mode & MLX5_WOL_ARP)
1091                 ret |= WAKE_ARP;
1092
1093         if (mode & MLX5_WOL_BROADCAST)
1094                 ret |= WAKE_BCAST;
1095
1096         if (mode & MLX5_WOL_MULTICAST)
1097                 ret |= WAKE_MCAST;
1098
1099         if (mode & MLX5_WOL_UNICAST)
1100                 ret |= WAKE_UCAST;
1101
1102         if (mode & MLX5_WOL_PHY_ACTIVITY)
1103                 ret |= WAKE_PHY;
1104
1105         return ret;
1106 }
1107
1108 static u8 mlx5e_refomrat_wol_mode_linux_to_mlx5(__u32 mode)
1109 {
1110         u8 ret = 0;
1111
1112         if (mode & WAKE_MAGIC)
1113                 ret |= MLX5_WOL_MAGIC;
1114
1115         if (mode & WAKE_MAGICSECURE)
1116                 ret |= MLX5_WOL_SECURED_MAGIC;
1117
1118         if (mode & WAKE_ARP)
1119                 ret |= MLX5_WOL_ARP;
1120
1121         if (mode & WAKE_BCAST)
1122                 ret |= MLX5_WOL_BROADCAST;
1123
1124         if (mode & WAKE_MCAST)
1125                 ret |= MLX5_WOL_MULTICAST;
1126
1127         if (mode & WAKE_UCAST)
1128                 ret |= MLX5_WOL_UNICAST;
1129
1130         if (mode & WAKE_PHY)
1131                 ret |= MLX5_WOL_PHY_ACTIVITY;
1132
1133         return ret;
1134 }
1135
1136 static void mlx5e_get_wol(struct net_device *netdev,
1137                           struct ethtool_wolinfo *wol)
1138 {
1139         struct mlx5e_priv *priv = netdev_priv(netdev);
1140         struct mlx5_core_dev *mdev = priv->mdev;
1141         u8 mlx5_wol_mode;
1142         int err;
1143
1144         memset(wol, 0, sizeof(*wol));
1145
1146         wol->supported = mlx5e_get_wol_supported(mdev);
1147         if (!wol->supported)
1148                 return;
1149
1150         err = mlx5_query_port_wol(mdev, &mlx5_wol_mode);
1151         if (err)
1152                 return;
1153
1154         wol->wolopts = mlx5e_refomrat_wol_mode_mlx5_to_linux(mlx5_wol_mode);
1155 }
1156
1157 static int mlx5e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1158 {
1159         struct mlx5e_priv *priv = netdev_priv(netdev);
1160         struct mlx5_core_dev *mdev = priv->mdev;
1161         __u32 wol_supported = mlx5e_get_wol_supported(mdev);
1162         u32 mlx5_wol_mode;
1163
1164         if (!wol_supported)
1165                 return -ENOTSUPP;
1166
1167         if (wol->wolopts & ~wol_supported)
1168                 return -EINVAL;
1169
1170         mlx5_wol_mode = mlx5e_refomrat_wol_mode_linux_to_mlx5(wol->wolopts);
1171
1172         return mlx5_set_port_wol(mdev, mlx5_wol_mode);
1173 }
1174
1175 static int mlx5e_set_phys_id(struct net_device *dev,
1176                              enum ethtool_phys_id_state state)
1177 {
1178         struct mlx5e_priv *priv = netdev_priv(dev);
1179         struct mlx5_core_dev *mdev = priv->mdev;
1180         u16 beacon_duration;
1181
1182         if (!MLX5_CAP_GEN(mdev, beacon_led))
1183                 return -EOPNOTSUPP;
1184
1185         switch (state) {
1186         case ETHTOOL_ID_ACTIVE:
1187                 beacon_duration = MLX5_BEACON_DURATION_INF;
1188                 break;
1189         case ETHTOOL_ID_INACTIVE:
1190                 beacon_duration = MLX5_BEACON_DURATION_OFF;
1191                 break;
1192         default:
1193                 return -EOPNOTSUPP;
1194         }
1195
1196         return mlx5_set_port_beacon(mdev, beacon_duration);
1197 }
1198
1199 static int mlx5e_get_module_info(struct net_device *netdev,
1200                                  struct ethtool_modinfo *modinfo)
1201 {
1202         struct mlx5e_priv *priv = netdev_priv(netdev);
1203         struct mlx5_core_dev *dev = priv->mdev;
1204         int size_read = 0;
1205         u8 data[4];
1206
1207         size_read = mlx5_query_module_eeprom(dev, 0, 2, data);
1208         if (size_read < 2)
1209                 return -EIO;
1210
1211         /* data[0] = identifier byte */
1212         switch (data[0]) {
1213         case MLX5_MODULE_ID_QSFP:
1214                 modinfo->type       = ETH_MODULE_SFF_8436;
1215                 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1216                 break;
1217         case MLX5_MODULE_ID_QSFP_PLUS:
1218         case MLX5_MODULE_ID_QSFP28:
1219                 /* data[1] = revision id */
1220                 if (data[0] == MLX5_MODULE_ID_QSFP28 || data[1] >= 0x3) {
1221                         modinfo->type       = ETH_MODULE_SFF_8636;
1222                         modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
1223                 } else {
1224                         modinfo->type       = ETH_MODULE_SFF_8436;
1225                         modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1226                 }
1227                 break;
1228         case MLX5_MODULE_ID_SFP:
1229                 modinfo->type       = ETH_MODULE_SFF_8472;
1230                 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1231                 break;
1232         default:
1233                 netdev_err(priv->netdev, "%s: cable type not recognized:0x%x\n",
1234                            __func__, data[0]);
1235                 return -EINVAL;
1236         }
1237
1238         return 0;
1239 }
1240
1241 static int mlx5e_get_module_eeprom(struct net_device *netdev,
1242                                    struct ethtool_eeprom *ee,
1243                                    u8 *data)
1244 {
1245         struct mlx5e_priv *priv = netdev_priv(netdev);
1246         struct mlx5_core_dev *mdev = priv->mdev;
1247         int offset = ee->offset;
1248         int size_read;
1249         int i = 0;
1250
1251         if (!ee->len)
1252                 return -EINVAL;
1253
1254         memset(data, 0, ee->len);
1255
1256         while (i < ee->len) {
1257                 size_read = mlx5_query_module_eeprom(mdev, offset, ee->len - i,
1258                                                      data + i);
1259
1260                 if (!size_read)
1261                         /* Done reading */
1262                         return 0;
1263
1264                 if (size_read < 0) {
1265                         netdev_err(priv->netdev, "%s: mlx5_query_eeprom failed:0x%x\n",
1266                                    __func__, size_read);
1267                         return 0;
1268                 }
1269
1270                 i += size_read;
1271                 offset += size_read;
1272         }
1273
1274         return 0;
1275 }
1276
1277 const struct ethtool_ops mlx5e_ethtool_ops = {
1278         .get_drvinfo       = mlx5e_get_drvinfo,
1279         .get_link          = ethtool_op_get_link,
1280         .get_strings       = mlx5e_get_strings,
1281         .get_sset_count    = mlx5e_get_sset_count,
1282         .get_ethtool_stats = mlx5e_get_ethtool_stats,
1283         .get_ringparam     = mlx5e_get_ringparam,
1284         .set_ringparam     = mlx5e_set_ringparam,
1285         .get_channels      = mlx5e_get_channels,
1286         .set_channels      = mlx5e_set_channels,
1287         .get_coalesce      = mlx5e_get_coalesce,
1288         .set_coalesce      = mlx5e_set_coalesce,
1289         .get_settings      = mlx5e_get_settings,
1290         .set_settings      = mlx5e_set_settings,
1291         .get_rxfh_key_size   = mlx5e_get_rxfh_key_size,
1292         .get_rxfh_indir_size = mlx5e_get_rxfh_indir_size,
1293         .get_rxfh          = mlx5e_get_rxfh,
1294         .set_rxfh          = mlx5e_set_rxfh,
1295         .get_rxnfc         = mlx5e_get_rxnfc,
1296         .get_tunable       = mlx5e_get_tunable,
1297         .set_tunable       = mlx5e_set_tunable,
1298         .get_pauseparam    = mlx5e_get_pauseparam,
1299         .set_pauseparam    = mlx5e_set_pauseparam,
1300         .get_ts_info       = mlx5e_get_ts_info,
1301         .set_phys_id       = mlx5e_set_phys_id,
1302         .get_wol           = mlx5e_get_wol,
1303         .set_wol           = mlx5e_set_wol,
1304         .get_module_info   = mlx5e_get_module_info,
1305         .get_module_eeprom = mlx5e_get_module_eeprom,
1306 };