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));
55 } ptys2ethtool_table[MLX5E_LINK_MODES_NUMBER] = {
56 [MLX5E_1000BASE_CX_SGMII] = {
57 .supported = SUPPORTED_1000baseKX_Full,
58 .advertised = ADVERTISED_1000baseKX_Full,
61 [MLX5E_1000BASE_KX] = {
62 .supported = SUPPORTED_1000baseKX_Full,
63 .advertised = ADVERTISED_1000baseKX_Full,
66 [MLX5E_10GBASE_CX4] = {
67 .supported = SUPPORTED_10000baseKX4_Full,
68 .advertised = ADVERTISED_10000baseKX4_Full,
71 [MLX5E_10GBASE_KX4] = {
72 .supported = SUPPORTED_10000baseKX4_Full,
73 .advertised = ADVERTISED_10000baseKX4_Full,
76 [MLX5E_10GBASE_KR] = {
77 .supported = SUPPORTED_10000baseKR_Full,
78 .advertised = ADVERTISED_10000baseKR_Full,
81 [MLX5E_20GBASE_KR2] = {
82 .supported = SUPPORTED_20000baseKR2_Full,
83 .advertised = ADVERTISED_20000baseKR2_Full,
86 [MLX5E_40GBASE_CR4] = {
87 .supported = SUPPORTED_40000baseCR4_Full,
88 .advertised = ADVERTISED_40000baseCR4_Full,
91 [MLX5E_40GBASE_KR4] = {
92 .supported = SUPPORTED_40000baseKR4_Full,
93 .advertised = ADVERTISED_40000baseKR4_Full,
96 [MLX5E_56GBASE_R4] = {
97 .supported = SUPPORTED_56000baseKR4_Full,
98 .advertised = ADVERTISED_56000baseKR4_Full,
101 [MLX5E_10GBASE_CR] = {
102 .supported = SUPPORTED_10000baseKR_Full,
103 .advertised = ADVERTISED_10000baseKR_Full,
106 [MLX5E_10GBASE_SR] = {
107 .supported = SUPPORTED_10000baseKR_Full,
108 .advertised = ADVERTISED_10000baseKR_Full,
111 [MLX5E_10GBASE_ER] = {
112 .supported = SUPPORTED_10000baseKR_Full,
113 .advertised = ADVERTISED_10000baseKR_Full,
116 [MLX5E_40GBASE_SR4] = {
117 .supported = SUPPORTED_40000baseSR4_Full,
118 .advertised = ADVERTISED_40000baseSR4_Full,
121 [MLX5E_40GBASE_LR4] = {
122 .supported = SUPPORTED_40000baseLR4_Full,
123 .advertised = ADVERTISED_40000baseLR4_Full,
126 [MLX5E_100GBASE_CR4] = {
129 [MLX5E_100GBASE_SR4] = {
132 [MLX5E_100GBASE_KR4] = {
135 [MLX5E_100GBASE_LR4] = {
138 [MLX5E_100BASE_TX] = {
141 [MLX5E_100BASE_T] = {
142 .supported = SUPPORTED_100baseT_Full,
143 .advertised = ADVERTISED_100baseT_Full,
146 [MLX5E_10GBASE_T] = {
147 .supported = SUPPORTED_10000baseT_Full,
148 .advertised = ADVERTISED_10000baseT_Full,
151 [MLX5E_25GBASE_CR] = {
154 [MLX5E_25GBASE_KR] = {
157 [MLX5E_25GBASE_SR] = {
160 [MLX5E_50GBASE_CR2] = {
163 [MLX5E_50GBASE_KR2] = {
168 static int mlx5e_get_sset_count(struct net_device *dev, int sset)
170 struct mlx5e_priv *priv = netdev_priv(dev);
174 return NUM_VPORT_COUNTERS +
175 priv->params.num_channels * NUM_RQ_STATS +
176 priv->params.num_channels * priv->num_tc *
184 static void mlx5e_get_strings(struct net_device *dev,
185 uint32_t stringset, uint8_t *data)
187 int i, j, tc, idx = 0;
188 struct mlx5e_priv *priv = netdev_priv(dev);
191 case ETH_SS_PRIV_FLAGS:
199 for (i = 0; i < NUM_VPORT_COUNTERS; i++)
200 strcpy(data + (idx++) * ETH_GSTRING_LEN,
203 /* per channel counters */
204 for (i = 0; i < priv->params.num_channels; i++)
205 for (j = 0; j < NUM_RQ_STATS; j++)
206 sprintf(data + (idx++) * ETH_GSTRING_LEN,
207 "rx%d_%s", i, rq_stats_strings[j]);
209 for (i = 0; i < priv->params.num_channels; i++)
210 for (tc = 0; tc < priv->num_tc; tc++)
211 for (j = 0; j < NUM_SQ_STATS; j++)
213 (idx++) * ETH_GSTRING_LEN,
215 sq_stats_strings[j]);
220 static void mlx5e_get_ethtool_stats(struct net_device *dev,
221 struct ethtool_stats *stats, u64 *data)
223 struct mlx5e_priv *priv = netdev_priv(dev);
224 int i, j, tc, idx = 0;
229 mutex_lock(&priv->state_lock);
230 if (test_bit(MLX5E_STATE_OPENED, &priv->state))
231 mlx5e_update_stats(priv);
232 mutex_unlock(&priv->state_lock);
234 for (i = 0; i < NUM_VPORT_COUNTERS; i++)
235 data[idx++] = ((u64 *)&priv->stats.vport)[i];
237 /* per channel counters */
238 for (i = 0; i < priv->params.num_channels; i++)
239 for (j = 0; j < NUM_RQ_STATS; j++)
240 data[idx++] = !test_bit(MLX5E_STATE_OPENED,
242 ((u64 *)&priv->channel[i]->rq.stats)[j];
244 for (i = 0; i < priv->params.num_channels; i++)
245 for (tc = 0; tc < priv->num_tc; tc++)
246 for (j = 0; j < NUM_SQ_STATS; j++)
247 data[idx++] = !test_bit(MLX5E_STATE_OPENED,
249 ((u64 *)&priv->channel[i]->sq[tc].stats)[j];
252 static void mlx5e_get_ringparam(struct net_device *dev,
253 struct ethtool_ringparam *param)
255 struct mlx5e_priv *priv = netdev_priv(dev);
257 param->rx_max_pending = 1 << MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE;
258 param->tx_max_pending = 1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE;
259 param->rx_pending = 1 << priv->params.log_rq_size;
260 param->tx_pending = 1 << priv->params.log_sq_size;
263 static int mlx5e_set_ringparam(struct net_device *dev,
264 struct ethtool_ringparam *param)
266 struct mlx5e_priv *priv = netdev_priv(dev);
267 struct mlx5e_params new_params;
273 if (param->rx_jumbo_pending) {
274 netdev_info(dev, "%s: rx_jumbo_pending not supported\n",
278 if (param->rx_mini_pending) {
279 netdev_info(dev, "%s: rx_mini_pending not supported\n",
283 if (param->rx_pending < (1 << MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE)) {
284 netdev_info(dev, "%s: rx_pending (%d) < min (%d)\n",
285 __func__, param->rx_pending,
286 1 << MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE);
289 if (param->rx_pending > (1 << MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE)) {
290 netdev_info(dev, "%s: rx_pending (%d) > max (%d)\n",
291 __func__, param->rx_pending,
292 1 << MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE);
295 if (param->tx_pending < (1 << MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE)) {
296 netdev_info(dev, "%s: tx_pending (%d) < min (%d)\n",
297 __func__, param->tx_pending,
298 1 << MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE);
301 if (param->tx_pending > (1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE)) {
302 netdev_info(dev, "%s: tx_pending (%d) > max (%d)\n",
303 __func__, param->tx_pending,
304 1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE);
308 log_rq_size = order_base_2(param->rx_pending);
309 log_sq_size = order_base_2(param->tx_pending);
310 min_rx_wqes = min_t(u16, param->rx_pending - 1,
311 MLX5E_PARAMS_DEFAULT_MIN_RX_WQES);
313 if (log_rq_size == priv->params.log_rq_size &&
314 log_sq_size == priv->params.log_sq_size &&
315 min_rx_wqes == priv->params.min_rx_wqes)
318 mutex_lock(&priv->state_lock);
319 new_params = priv->params;
320 new_params.log_rq_size = log_rq_size;
321 new_params.log_sq_size = log_sq_size;
322 new_params.min_rx_wqes = min_rx_wqes;
323 err = mlx5e_update_priv_params(priv, &new_params);
324 mutex_unlock(&priv->state_lock);
329 static void mlx5e_get_channels(struct net_device *dev,
330 struct ethtool_channels *ch)
332 struct mlx5e_priv *priv = netdev_priv(dev);
333 int ncv = priv->mdev->priv.eq_table.num_comp_vectors;
335 ch->max_combined = ncv;
336 ch->combined_count = priv->params.num_channels;
339 static int mlx5e_set_channels(struct net_device *dev,
340 struct ethtool_channels *ch)
342 struct mlx5e_priv *priv = netdev_priv(dev);
343 int ncv = priv->mdev->priv.eq_table.num_comp_vectors;
344 unsigned int count = ch->combined_count;
345 struct mlx5e_params new_params;
349 netdev_info(dev, "%s: combined_count=0 not supported\n",
353 if (ch->rx_count || ch->tx_count) {
354 netdev_info(dev, "%s: separate rx/tx count not supported\n",
359 netdev_info(dev, "%s: count (%d) > max (%d)\n",
360 __func__, count, ncv);
364 if (priv->params.num_channels == count)
367 mutex_lock(&priv->state_lock);
368 new_params = priv->params;
369 new_params.num_channels = count;
370 err = mlx5e_update_priv_params(priv, &new_params);
371 mutex_unlock(&priv->state_lock);
376 static int mlx5e_get_coalesce(struct net_device *netdev,
377 struct ethtool_coalesce *coal)
379 struct mlx5e_priv *priv = netdev_priv(netdev);
381 coal->rx_coalesce_usecs = priv->params.rx_cq_moderation_usec;
382 coal->rx_max_coalesced_frames = priv->params.rx_cq_moderation_pkts;
383 coal->tx_coalesce_usecs = priv->params.tx_cq_moderation_usec;
384 coal->tx_max_coalesced_frames = priv->params.tx_cq_moderation_pkts;
389 static int mlx5e_set_coalesce(struct net_device *netdev,
390 struct ethtool_coalesce *coal)
392 struct mlx5e_priv *priv = netdev_priv(netdev);
393 struct mlx5_core_dev *mdev = priv->mdev;
394 struct mlx5e_channel *c;
398 priv->params.tx_cq_moderation_usec = coal->tx_coalesce_usecs;
399 priv->params.tx_cq_moderation_pkts = coal->tx_max_coalesced_frames;
400 priv->params.rx_cq_moderation_usec = coal->rx_coalesce_usecs;
401 priv->params.rx_cq_moderation_pkts = coal->rx_max_coalesced_frames;
403 for (i = 0; i < priv->params.num_channels; ++i) {
404 c = priv->channel[i];
406 for (tc = 0; tc < c->num_tc; tc++) {
407 mlx5_core_modify_cq_moderation(mdev,
409 coal->tx_coalesce_usecs,
410 coal->tx_max_coalesced_frames);
413 mlx5_core_modify_cq_moderation(mdev, &c->rq.cq.mcq,
414 coal->rx_coalesce_usecs,
415 coal->rx_max_coalesced_frames);
421 static u32 ptys2ethtool_supported_link(u32 eth_proto_cap)
424 u32 supported_modes = 0;
426 for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i) {
427 if (eth_proto_cap & MLX5E_PROT_MASK(i))
428 supported_modes |= ptys2ethtool_table[i].supported;
430 return supported_modes;
433 static u32 ptys2ethtool_adver_link(u32 eth_proto_cap)
436 u32 advertising_modes = 0;
438 for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i) {
439 if (eth_proto_cap & MLX5E_PROT_MASK(i))
440 advertising_modes |= ptys2ethtool_table[i].advertised;
442 return advertising_modes;
445 static u32 ptys2ethtool_supported_port(u32 eth_proto_cap)
447 if (eth_proto_cap & (MLX5E_PROT_MASK(MLX5E_10GBASE_CR)
448 | MLX5E_PROT_MASK(MLX5E_10GBASE_SR)
449 | MLX5E_PROT_MASK(MLX5E_40GBASE_CR4)
450 | MLX5E_PROT_MASK(MLX5E_40GBASE_SR4)
451 | MLX5E_PROT_MASK(MLX5E_100GBASE_SR4)
452 | MLX5E_PROT_MASK(MLX5E_1000BASE_CX_SGMII))) {
453 return SUPPORTED_FIBRE;
456 if (eth_proto_cap & (MLX5E_PROT_MASK(MLX5E_100GBASE_KR4)
457 | MLX5E_PROT_MASK(MLX5E_40GBASE_KR4)
458 | MLX5E_PROT_MASK(MLX5E_10GBASE_KR)
459 | MLX5E_PROT_MASK(MLX5E_10GBASE_KX4)
460 | MLX5E_PROT_MASK(MLX5E_1000BASE_KX))) {
461 return SUPPORTED_Backplane;
466 static void get_speed_duplex(struct net_device *netdev,
468 struct ethtool_cmd *cmd)
471 u32 speed = SPEED_UNKNOWN;
472 u8 duplex = DUPLEX_UNKNOWN;
474 if (!netif_carrier_ok(netdev))
477 for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i) {
478 if (eth_proto_oper & MLX5E_PROT_MASK(i)) {
479 speed = ptys2ethtool_table[i].speed;
480 duplex = DUPLEX_FULL;
485 ethtool_cmd_speed_set(cmd, speed);
486 cmd->duplex = duplex;
489 static void get_supported(u32 eth_proto_cap, u32 *supported)
491 *supported |= ptys2ethtool_supported_port(eth_proto_cap);
492 *supported |= ptys2ethtool_supported_link(eth_proto_cap);
493 *supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
496 static void get_advertising(u32 eth_proto_cap, u8 tx_pause,
497 u8 rx_pause, u32 *advertising)
499 *advertising |= ptys2ethtool_adver_link(eth_proto_cap);
500 *advertising |= tx_pause ? ADVERTISED_Pause : 0;
501 *advertising |= (tx_pause ^ rx_pause) ? ADVERTISED_Asym_Pause : 0;
504 static u8 get_connector_port(u32 eth_proto)
506 if (eth_proto & (MLX5E_PROT_MASK(MLX5E_10GBASE_SR)
507 | MLX5E_PROT_MASK(MLX5E_40GBASE_SR4)
508 | MLX5E_PROT_MASK(MLX5E_100GBASE_SR4)
509 | MLX5E_PROT_MASK(MLX5E_1000BASE_CX_SGMII))) {
513 if (eth_proto & (MLX5E_PROT_MASK(MLX5E_40GBASE_CR4)
514 | MLX5E_PROT_MASK(MLX5E_10GBASE_CR)
515 | MLX5E_PROT_MASK(MLX5E_100GBASE_CR4))) {
519 if (eth_proto & (MLX5E_PROT_MASK(MLX5E_10GBASE_KX4)
520 | MLX5E_PROT_MASK(MLX5E_10GBASE_KR)
521 | MLX5E_PROT_MASK(MLX5E_40GBASE_KR4)
522 | MLX5E_PROT_MASK(MLX5E_100GBASE_KR4))) {
529 static void get_lp_advertising(u32 eth_proto_lp, u32 *lp_advertising)
531 *lp_advertising = ptys2ethtool_adver_link(eth_proto_lp);
534 static int mlx5e_get_settings(struct net_device *netdev,
535 struct ethtool_cmd *cmd)
537 struct mlx5e_priv *priv = netdev_priv(netdev);
538 struct mlx5_core_dev *mdev = priv->mdev;
539 u32 out[MLX5_ST_SZ_DW(ptys_reg)];
546 err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN, 1);
549 netdev_err(netdev, "%s: query port ptys failed: %d\n",
554 eth_proto_cap = MLX5_GET(ptys_reg, out, eth_proto_capability);
555 eth_proto_admin = MLX5_GET(ptys_reg, out, eth_proto_admin);
556 eth_proto_oper = MLX5_GET(ptys_reg, out, eth_proto_oper);
557 eth_proto_lp = MLX5_GET(ptys_reg, out, eth_proto_lp_advertise);
560 cmd->advertising = 0;
562 get_supported(eth_proto_cap, &cmd->supported);
563 get_advertising(eth_proto_admin, 0, 0, &cmd->advertising);
564 get_speed_duplex(netdev, eth_proto_oper, cmd);
566 eth_proto_oper = eth_proto_oper ? eth_proto_oper : eth_proto_cap;
568 cmd->port = get_connector_port(eth_proto_oper);
569 get_lp_advertising(eth_proto_lp, &cmd->lp_advertising);
571 cmd->transceiver = XCVR_INTERNAL;
577 static u32 mlx5e_ethtool2ptys_adver_link(u32 link_modes)
579 u32 i, ptys_modes = 0;
581 for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i) {
582 if (ptys2ethtool_table[i].advertised & link_modes)
583 ptys_modes |= MLX5E_PROT_MASK(i);
589 static u32 mlx5e_ethtool2ptys_speed_link(u32 speed)
591 u32 i, speed_links = 0;
593 for (i = 0; i < MLX5E_LINK_MODES_NUMBER; ++i) {
594 if (ptys2ethtool_table[i].speed == speed)
595 speed_links |= MLX5E_PROT_MASK(i);
601 static int mlx5e_set_settings(struct net_device *netdev,
602 struct ethtool_cmd *cmd)
604 struct mlx5e_priv *priv = netdev_priv(netdev);
605 struct mlx5_core_dev *mdev = priv->mdev;
608 u32 eth_proto_cap, eth_proto_admin;
612 speed = ethtool_cmd_speed(cmd);
614 link_modes = cmd->autoneg == AUTONEG_ENABLE ?
615 mlx5e_ethtool2ptys_adver_link(cmd->advertising) :
616 mlx5e_ethtool2ptys_speed_link(speed);
618 err = mlx5_query_port_proto_cap(mdev, ð_proto_cap, MLX5_PTYS_EN);
620 netdev_err(netdev, "%s: query port eth proto cap failed: %d\n",
625 link_modes = link_modes & eth_proto_cap;
627 netdev_err(netdev, "%s: Not supported link mode(s) requested",
633 err = mlx5_query_port_proto_admin(mdev, ð_proto_admin, MLX5_PTYS_EN);
635 netdev_err(netdev, "%s: query port eth proto admin failed: %d\n",
640 if (link_modes == eth_proto_admin)
643 err = mlx5_set_port_proto(mdev, link_modes, MLX5_PTYS_EN);
645 netdev_err(netdev, "%s: set port eth proto admin failed: %d\n",
650 err = mlx5_query_port_status(mdev, &port_status);
654 if (port_status == MLX5_PORT_DOWN)
657 err = mlx5_set_port_status(mdev, MLX5_PORT_DOWN);
660 err = mlx5_set_port_status(mdev, MLX5_PORT_UP);
665 const struct ethtool_ops mlx5e_ethtool_ops = {
666 .get_drvinfo = mlx5e_get_drvinfo,
667 .get_link = ethtool_op_get_link,
668 .get_strings = mlx5e_get_strings,
669 .get_sset_count = mlx5e_get_sset_count,
670 .get_ethtool_stats = mlx5e_get_ethtool_stats,
671 .get_ringparam = mlx5e_get_ringparam,
672 .set_ringparam = mlx5e_set_ringparam,
673 .get_channels = mlx5e_get_channels,
674 .set_channels = mlx5e_set_channels,
675 .get_coalesce = mlx5e_get_coalesce,
676 .set_coalesce = mlx5e_set_coalesce,
677 .get_settings = mlx5e_get_settings,
678 .set_settings = mlx5e_set_settings,