2 * Copyright (c) 2016, 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
33 #include <linux/mlx5/fs.h>
34 #include <net/switchdev.h>
35 #include <net/pkt_cls.h>
36 #include <net/act_api.h>
37 #include <net/devlink.h>
38 #include <net/ipv6_stubs.h>
43 #include "en/params.h"
46 #include "en/rep/tc.h"
47 #include "en/rep/neigh.h"
48 #include "en/rep/bridge.h"
49 #include "en/devlink.h"
52 #include "lib/devcom.h"
53 #include "lib/vxlan.h"
54 #define CREATE_TRACE_POINTS
55 #include "diag/en_rep_tracepoint.h"
56 #include "en_accel/ipsec.h"
57 #include "en/tc/int_port.h"
59 #include "en/fs_ethtool.h"
61 #define MLX5E_REP_PARAMS_DEF_LOG_SQ_SIZE \
62 max(0x7, MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE)
63 #define MLX5E_REP_PARAMS_DEF_NUM_CHANNELS 1
65 static const char mlx5e_rep_driver_name[] = "mlx5e_rep";
67 static void mlx5e_rep_get_drvinfo(struct net_device *dev,
68 struct ethtool_drvinfo *drvinfo)
70 struct mlx5e_priv *priv = netdev_priv(dev);
71 struct mlx5_core_dev *mdev = priv->mdev;
73 strlcpy(drvinfo->driver, mlx5e_rep_driver_name,
74 sizeof(drvinfo->driver));
75 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
77 fw_rev_maj(mdev), fw_rev_min(mdev),
78 fw_rev_sub(mdev), mdev->board_id);
81 static const struct counter_desc sw_rep_stats_desc[] = {
82 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_packets) },
83 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_bytes) },
84 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_packets) },
85 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_bytes) },
95 static const struct counter_desc vport_rep_stats_desc[] = {
96 { MLX5E_DECLARE_STAT(struct vport_stats, vport_rx_packets) },
97 { MLX5E_DECLARE_STAT(struct vport_stats, vport_rx_bytes) },
98 { MLX5E_DECLARE_STAT(struct vport_stats, vport_tx_packets) },
99 { MLX5E_DECLARE_STAT(struct vport_stats, vport_tx_bytes) },
102 #define NUM_VPORT_REP_SW_COUNTERS ARRAY_SIZE(sw_rep_stats_desc)
103 #define NUM_VPORT_REP_HW_COUNTERS ARRAY_SIZE(vport_rep_stats_desc)
105 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(sw_rep)
107 return NUM_VPORT_REP_SW_COUNTERS;
110 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(sw_rep)
114 for (i = 0; i < NUM_VPORT_REP_SW_COUNTERS; i++)
115 strcpy(data + (idx++) * ETH_GSTRING_LEN,
116 sw_rep_stats_desc[i].format);
120 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(sw_rep)
124 for (i = 0; i < NUM_VPORT_REP_SW_COUNTERS; i++)
125 data[idx++] = MLX5E_READ_CTR64_CPU(&priv->stats.sw,
126 sw_rep_stats_desc, i);
130 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(sw_rep)
132 struct mlx5e_sw_stats *s = &priv->stats.sw;
133 struct rtnl_link_stats64 stats64 = {};
135 memset(s, 0, sizeof(*s));
136 mlx5e_fold_sw_stats64(priv, &stats64);
138 s->rx_packets = stats64.rx_packets;
139 s->rx_bytes = stats64.rx_bytes;
140 s->tx_packets = stats64.tx_packets;
141 s->tx_bytes = stats64.tx_bytes;
142 s->tx_queue_dropped = stats64.tx_dropped;
145 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(vport_rep)
147 return NUM_VPORT_REP_HW_COUNTERS;
150 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(vport_rep)
154 for (i = 0; i < NUM_VPORT_REP_HW_COUNTERS; i++)
155 strcpy(data + (idx++) * ETH_GSTRING_LEN, vport_rep_stats_desc[i].format);
159 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(vport_rep)
163 for (i = 0; i < NUM_VPORT_REP_HW_COUNTERS; i++)
164 data[idx++] = MLX5E_READ_CTR64_CPU(&priv->stats.vf_vport,
165 vport_rep_stats_desc, i);
169 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(vport_rep)
171 struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
172 struct mlx5e_rep_priv *rpriv = priv->ppriv;
173 struct mlx5_eswitch_rep *rep = rpriv->rep;
174 struct rtnl_link_stats64 *vport_stats;
175 struct ifla_vf_stats vf_stats;
178 err = mlx5_eswitch_get_vport_stats(esw, rep->vport, &vf_stats);
180 netdev_warn(priv->netdev, "vport %d error %d reading stats\n",
185 vport_stats = &priv->stats.vf_vport;
186 /* flip tx/rx as we are reporting the counters for the switch vport */
187 vport_stats->rx_packets = vf_stats.tx_packets;
188 vport_stats->rx_bytes = vf_stats.tx_bytes;
189 vport_stats->tx_packets = vf_stats.rx_packets;
190 vport_stats->tx_bytes = vf_stats.rx_bytes;
193 static void mlx5e_rep_get_strings(struct net_device *dev,
194 u32 stringset, uint8_t *data)
196 struct mlx5e_priv *priv = netdev_priv(dev);
200 mlx5e_stats_fill_strings(priv, data);
205 static void mlx5e_rep_get_ethtool_stats(struct net_device *dev,
206 struct ethtool_stats *stats, u64 *data)
208 struct mlx5e_priv *priv = netdev_priv(dev);
210 mlx5e_ethtool_get_ethtool_stats(priv, stats, data);
213 static int mlx5e_rep_get_sset_count(struct net_device *dev, int sset)
215 struct mlx5e_priv *priv = netdev_priv(dev);
219 return mlx5e_stats_total_num(priv);
226 mlx5e_rep_get_ringparam(struct net_device *dev,
227 struct ethtool_ringparam *param,
228 struct kernel_ethtool_ringparam *kernel_param,
229 struct netlink_ext_ack *extack)
231 struct mlx5e_priv *priv = netdev_priv(dev);
233 mlx5e_ethtool_get_ringparam(priv, param, kernel_param);
237 mlx5e_rep_set_ringparam(struct net_device *dev,
238 struct ethtool_ringparam *param,
239 struct kernel_ethtool_ringparam *kernel_param,
240 struct netlink_ext_ack *extack)
242 struct mlx5e_priv *priv = netdev_priv(dev);
244 return mlx5e_ethtool_set_ringparam(priv, param);
247 static void mlx5e_rep_get_channels(struct net_device *dev,
248 struct ethtool_channels *ch)
250 struct mlx5e_priv *priv = netdev_priv(dev);
252 mlx5e_ethtool_get_channels(priv, ch);
255 static int mlx5e_rep_set_channels(struct net_device *dev,
256 struct ethtool_channels *ch)
258 struct mlx5e_priv *priv = netdev_priv(dev);
260 return mlx5e_ethtool_set_channels(priv, ch);
263 static int mlx5e_rep_get_coalesce(struct net_device *netdev,
264 struct ethtool_coalesce *coal,
265 struct kernel_ethtool_coalesce *kernel_coal,
266 struct netlink_ext_ack *extack)
268 struct mlx5e_priv *priv = netdev_priv(netdev);
270 return mlx5e_ethtool_get_coalesce(priv, coal, kernel_coal);
273 static int mlx5e_rep_set_coalesce(struct net_device *netdev,
274 struct ethtool_coalesce *coal,
275 struct kernel_ethtool_coalesce *kernel_coal,
276 struct netlink_ext_ack *extack)
278 struct mlx5e_priv *priv = netdev_priv(netdev);
280 return mlx5e_ethtool_set_coalesce(priv, coal, kernel_coal, extack);
283 static u32 mlx5e_rep_get_rxfh_key_size(struct net_device *netdev)
285 struct mlx5e_priv *priv = netdev_priv(netdev);
287 return mlx5e_ethtool_get_rxfh_key_size(priv);
290 static u32 mlx5e_rep_get_rxfh_indir_size(struct net_device *netdev)
292 struct mlx5e_priv *priv = netdev_priv(netdev);
294 return mlx5e_ethtool_get_rxfh_indir_size(priv);
297 static const struct ethtool_ops mlx5e_rep_ethtool_ops = {
298 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
299 ETHTOOL_COALESCE_MAX_FRAMES |
300 ETHTOOL_COALESCE_USE_ADAPTIVE,
301 .get_drvinfo = mlx5e_rep_get_drvinfo,
302 .get_link = ethtool_op_get_link,
303 .get_strings = mlx5e_rep_get_strings,
304 .get_sset_count = mlx5e_rep_get_sset_count,
305 .get_ethtool_stats = mlx5e_rep_get_ethtool_stats,
306 .get_ringparam = mlx5e_rep_get_ringparam,
307 .set_ringparam = mlx5e_rep_set_ringparam,
308 .get_channels = mlx5e_rep_get_channels,
309 .set_channels = mlx5e_rep_set_channels,
310 .get_coalesce = mlx5e_rep_get_coalesce,
311 .set_coalesce = mlx5e_rep_set_coalesce,
312 .get_rxfh_key_size = mlx5e_rep_get_rxfh_key_size,
313 .get_rxfh_indir_size = mlx5e_rep_get_rxfh_indir_size,
316 static void mlx5e_sqs2vport_stop(struct mlx5_eswitch *esw,
317 struct mlx5_eswitch_rep *rep)
319 struct mlx5e_rep_sq *rep_sq, *tmp;
320 struct mlx5e_rep_priv *rpriv;
322 if (esw->mode != MLX5_ESWITCH_OFFLOADS)
325 rpriv = mlx5e_rep_to_rep_priv(rep);
326 list_for_each_entry_safe(rep_sq, tmp, &rpriv->vport_sqs_list, list) {
327 mlx5_eswitch_del_send_to_vport_rule(rep_sq->send_to_vport_rule);
328 if (rep_sq->send_to_vport_rule_peer)
329 mlx5_eswitch_del_send_to_vport_rule(rep_sq->send_to_vport_rule_peer);
330 list_del(&rep_sq->list);
335 static int mlx5e_sqs2vport_start(struct mlx5_eswitch *esw,
336 struct mlx5_eswitch_rep *rep,
337 u32 *sqns_array, int sqns_num)
339 struct mlx5_eswitch *peer_esw = NULL;
340 struct mlx5_flow_handle *flow_rule;
341 struct mlx5e_rep_priv *rpriv;
342 struct mlx5e_rep_sq *rep_sq;
346 if (esw->mode != MLX5_ESWITCH_OFFLOADS)
349 rpriv = mlx5e_rep_to_rep_priv(rep);
350 if (mlx5_devcom_is_paired(esw->dev->priv.devcom, MLX5_DEVCOM_ESW_OFFLOADS))
351 peer_esw = mlx5_devcom_get_peer_data(esw->dev->priv.devcom,
352 MLX5_DEVCOM_ESW_OFFLOADS);
354 for (i = 0; i < sqns_num; i++) {
355 rep_sq = kzalloc(sizeof(*rep_sq), GFP_KERNEL);
361 /* Add re-inject rule to the PF/representor sqs */
362 flow_rule = mlx5_eswitch_add_send_to_vport_rule(esw, esw, rep,
364 if (IS_ERR(flow_rule)) {
365 err = PTR_ERR(flow_rule);
369 rep_sq->send_to_vport_rule = flow_rule;
370 rep_sq->sqn = sqns_array[i];
373 flow_rule = mlx5_eswitch_add_send_to_vport_rule(peer_esw, esw,
375 if (IS_ERR(flow_rule)) {
376 err = PTR_ERR(flow_rule);
377 mlx5_eswitch_del_send_to_vport_rule(rep_sq->send_to_vport_rule);
381 rep_sq->send_to_vport_rule_peer = flow_rule;
384 list_add(&rep_sq->list, &rpriv->vport_sqs_list);
388 mlx5_devcom_release_peer_data(esw->dev->priv.devcom, MLX5_DEVCOM_ESW_OFFLOADS);
393 mlx5e_sqs2vport_stop(esw, rep);
396 mlx5_devcom_release_peer_data(esw->dev->priv.devcom, MLX5_DEVCOM_ESW_OFFLOADS);
401 int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv)
403 int sqs_per_channel = mlx5e_get_dcb_num_tc(&priv->channels.params);
404 struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
405 bool is_uplink_rep = mlx5e_is_uplink_rep(priv);
406 struct mlx5e_rep_priv *rpriv = priv->ppriv;
407 struct mlx5_eswitch_rep *rep = rpriv->rep;
408 int n, tc, nch, num_sqs = 0;
409 struct mlx5e_channel *c;
414 ptp_sq = !!(priv->channels.ptp &&
415 MLX5E_GET_PFLAG(&priv->channels.params, MLX5E_PFLAG_TX_PORT_TS));
416 nch = priv->channels.num + ptp_sq;
417 /* +2 for xdpsqs, they don't exist on the ptp channel but will not be
418 * counted for by num_sqs.
421 sqs_per_channel += 2;
423 sqs = kvcalloc(nch * sqs_per_channel, sizeof(*sqs), GFP_KERNEL);
427 for (n = 0; n < priv->channels.num; n++) {
428 c = priv->channels.c[n];
429 for (tc = 0; tc < c->num_tc; tc++)
430 sqs[num_sqs++] = c->sq[tc].sqn;
434 sqs[num_sqs++] = c->rq_xdpsq.sqn;
436 sqs[num_sqs++] = c->xdpsq.sqn;
440 struct mlx5e_ptp *ptp_ch = priv->channels.ptp;
442 for (tc = 0; tc < ptp_ch->num_tc; tc++)
443 sqs[num_sqs++] = ptp_ch->ptpsq[tc].txqsq.sqn;
446 err = mlx5e_sqs2vport_start(esw, rep, sqs, num_sqs);
451 netdev_warn(priv->netdev, "Failed to add SQs FWD rules %d\n", err);
455 void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv)
457 struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
458 struct mlx5e_rep_priv *rpriv = priv->ppriv;
459 struct mlx5_eswitch_rep *rep = rpriv->rep;
461 mlx5e_sqs2vport_stop(esw, rep);
464 static int mlx5e_rep_open(struct net_device *dev)
466 struct mlx5e_priv *priv = netdev_priv(dev);
467 struct mlx5e_rep_priv *rpriv = priv->ppriv;
468 struct mlx5_eswitch_rep *rep = rpriv->rep;
471 mutex_lock(&priv->state_lock);
472 err = mlx5e_open_locked(dev);
476 if (!mlx5_modify_vport_admin_state(priv->mdev,
477 MLX5_VPORT_STATE_OP_MOD_ESW_VPORT,
479 MLX5_VPORT_ADMIN_STATE_UP))
480 netif_carrier_on(dev);
483 mutex_unlock(&priv->state_lock);
487 static int mlx5e_rep_close(struct net_device *dev)
489 struct mlx5e_priv *priv = netdev_priv(dev);
490 struct mlx5e_rep_priv *rpriv = priv->ppriv;
491 struct mlx5_eswitch_rep *rep = rpriv->rep;
494 mutex_lock(&priv->state_lock);
495 mlx5_modify_vport_admin_state(priv->mdev,
496 MLX5_VPORT_STATE_OP_MOD_ESW_VPORT,
498 MLX5_VPORT_ADMIN_STATE_DOWN);
499 ret = mlx5e_close_locked(dev);
500 mutex_unlock(&priv->state_lock);
504 bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv)
506 struct mlx5e_rep_priv *rpriv = priv->ppriv;
507 struct mlx5_eswitch_rep *rep;
509 if (!MLX5_ESWITCH_MANAGER(priv->mdev))
512 if (!rpriv) /* non vport rep mlx5e instances don't use this field */
516 return (rep->vport == MLX5_VPORT_UPLINK);
519 bool mlx5e_rep_has_offload_stats(const struct net_device *dev, int attr_id)
522 case IFLA_OFFLOAD_XSTATS_CPU_HIT:
530 mlx5e_get_sw_stats64(const struct net_device *dev,
531 struct rtnl_link_stats64 *stats)
533 struct mlx5e_priv *priv = netdev_priv(dev);
535 mlx5e_fold_sw_stats64(priv, stats);
539 int mlx5e_rep_get_offload_stats(int attr_id, const struct net_device *dev,
543 case IFLA_OFFLOAD_XSTATS_CPU_HIT:
544 return mlx5e_get_sw_stats64(dev, sp);
551 mlx5e_rep_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
553 struct mlx5e_priv *priv = netdev_priv(dev);
555 /* update HW stats in background for next time */
556 mlx5e_queue_update_stats(priv);
557 memcpy(stats, &priv->stats.vf_vport, sizeof(*stats));
560 static int mlx5e_rep_change_mtu(struct net_device *netdev, int new_mtu)
562 return mlx5e_change_mtu(netdev, new_mtu, NULL);
565 static struct devlink_port *mlx5e_rep_get_devlink_port(struct net_device *netdev)
567 struct mlx5e_priv *priv = netdev_priv(netdev);
568 struct mlx5e_rep_priv *rpriv = priv->ppriv;
569 struct mlx5_core_dev *dev = priv->mdev;
571 return mlx5_esw_offloads_devlink_port(dev->priv.eswitch, rpriv->rep->vport);
574 static int mlx5e_rep_change_carrier(struct net_device *dev, bool new_carrier)
576 struct mlx5e_priv *priv = netdev_priv(dev);
577 struct mlx5e_rep_priv *rpriv = priv->ppriv;
578 struct mlx5_eswitch_rep *rep = rpriv->rep;
582 err = mlx5_modify_vport_admin_state(priv->mdev, MLX5_VPORT_STATE_OP_MOD_ESW_VPORT,
583 rep->vport, 1, MLX5_VPORT_ADMIN_STATE_UP);
586 netif_carrier_on(dev);
588 err = mlx5_modify_vport_admin_state(priv->mdev, MLX5_VPORT_STATE_OP_MOD_ESW_VPORT,
589 rep->vport, 1, MLX5_VPORT_ADMIN_STATE_DOWN);
592 netif_carrier_off(dev);
597 static const struct net_device_ops mlx5e_netdev_ops_rep = {
598 .ndo_open = mlx5e_rep_open,
599 .ndo_stop = mlx5e_rep_close,
600 .ndo_start_xmit = mlx5e_xmit,
601 .ndo_setup_tc = mlx5e_rep_setup_tc,
602 .ndo_get_devlink_port = mlx5e_rep_get_devlink_port,
603 .ndo_get_stats64 = mlx5e_rep_get_stats,
604 .ndo_has_offload_stats = mlx5e_rep_has_offload_stats,
605 .ndo_get_offload_stats = mlx5e_rep_get_offload_stats,
606 .ndo_change_mtu = mlx5e_rep_change_mtu,
607 .ndo_change_carrier = mlx5e_rep_change_carrier,
610 bool mlx5e_eswitch_uplink_rep(const struct net_device *netdev)
612 return netdev->netdev_ops == &mlx5e_netdev_ops &&
613 mlx5e_is_uplink_rep(netdev_priv(netdev));
616 bool mlx5e_eswitch_vf_rep(const struct net_device *netdev)
618 return netdev->netdev_ops == &mlx5e_netdev_ops_rep;
621 /* One indirect TIR set for outer. Inner not supported in reps. */
622 #define REP_NUM_INDIR_TIRS MLX5E_NUM_INDIR_TIRS
624 static int mlx5e_rep_max_nch_limit(struct mlx5_core_dev *mdev)
626 int max_tir_num = 1 << MLX5_CAP_GEN(mdev, log_max_tir);
627 int num_vports = mlx5_eswitch_get_total_vports(mdev);
629 return (max_tir_num - mlx5e_get_pf_num_tirs(mdev)
630 - (num_vports * REP_NUM_INDIR_TIRS)) / num_vports;
633 static void mlx5e_build_rep_params(struct net_device *netdev)
635 struct mlx5e_priv *priv = netdev_priv(netdev);
636 struct mlx5e_rep_priv *rpriv = priv->ppriv;
637 struct mlx5_eswitch_rep *rep = rpriv->rep;
638 struct mlx5_core_dev *mdev = priv->mdev;
639 struct mlx5e_params *params;
641 u8 cq_period_mode = MLX5_CAP_GEN(mdev, cq_period_start_from_cqe) ?
642 MLX5_CQ_PERIOD_MODE_START_FROM_CQE :
643 MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
645 params = &priv->channels.params;
647 params->num_channels = MLX5E_REP_PARAMS_DEF_NUM_CHANNELS;
648 params->hard_mtu = MLX5E_ETH_HARD_MTU;
649 params->sw_mtu = netdev->mtu;
652 if (rep->vport == MLX5_VPORT_UPLINK)
653 params->log_sq_size = MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE;
655 params->log_sq_size = MLX5E_REP_PARAMS_DEF_LOG_SQ_SIZE;
658 mlx5e_build_rq_params(mdev, params);
660 /* CQ moderation params */
661 params->rx_dim_enabled = MLX5_CAP_GEN(mdev, cq_moderation);
662 mlx5e_set_rx_cq_mode_params(params, cq_period_mode);
664 params->mqprio.num_tc = 1;
665 params->tunneled_offload_en = false;
667 mlx5_query_min_inline(mdev, ¶ms->tx_min_inline_mode);
670 static void mlx5e_build_rep_netdev(struct net_device *netdev,
671 struct mlx5_core_dev *mdev)
673 SET_NETDEV_DEV(netdev, mdev->device);
674 netdev->netdev_ops = &mlx5e_netdev_ops_rep;
675 eth_hw_addr_random(netdev);
676 netdev->ethtool_ops = &mlx5e_rep_ethtool_ops;
678 netdev->watchdog_timeo = 15 * HZ;
680 #if IS_ENABLED(CONFIG_MLX5_CLS_ACT)
681 netdev->hw_features |= NETIF_F_HW_TC;
683 netdev->hw_features |= NETIF_F_SG;
684 netdev->hw_features |= NETIF_F_IP_CSUM;
685 netdev->hw_features |= NETIF_F_IPV6_CSUM;
686 netdev->hw_features |= NETIF_F_GRO;
687 netdev->hw_features |= NETIF_F_TSO;
688 netdev->hw_features |= NETIF_F_TSO6;
689 netdev->hw_features |= NETIF_F_RXCSUM;
691 netdev->features |= netdev->hw_features;
692 netdev->features |= NETIF_F_NETNS_LOCAL;
695 static int mlx5e_init_rep(struct mlx5_core_dev *mdev,
696 struct net_device *netdev)
698 struct mlx5e_priv *priv = netdev_priv(netdev);
700 priv->fs = mlx5e_fs_init(priv->profile, mdev,
701 !test_bit(MLX5E_STATE_DESTROYING, &priv->state));
703 netdev_err(priv->netdev, "FS allocation failed\n");
707 mlx5e_build_rep_params(netdev);
708 mlx5e_timestamp_init(priv);
713 static int mlx5e_init_ul_rep(struct mlx5_core_dev *mdev,
714 struct net_device *netdev)
716 struct mlx5e_priv *priv = netdev_priv(netdev);
719 priv->fs = mlx5e_fs_init(priv->profile, mdev,
720 !test_bit(MLX5E_STATE_DESTROYING, &priv->state));
722 netdev_err(priv->netdev, "FS allocation failed\n");
726 err = mlx5e_ipsec_init(priv);
728 mlx5_core_err(mdev, "Uplink rep IPsec initialization failed, %d\n", err);
730 mlx5e_vxlan_set_netdev_info(priv);
731 mlx5e_build_rep_params(netdev);
732 mlx5e_timestamp_init(priv);
736 static void mlx5e_cleanup_rep(struct mlx5e_priv *priv)
738 mlx5e_fs_cleanup(priv->fs);
739 mlx5e_ipsec_cleanup(priv);
742 static int mlx5e_create_rep_ttc_table(struct mlx5e_priv *priv)
744 struct mlx5e_rep_priv *rpriv = priv->ppriv;
745 struct mlx5_eswitch_rep *rep = rpriv->rep;
746 struct ttc_params ttc_params = {};
749 mlx5e_fs_set_ns(priv->fs,
750 mlx5_get_flow_namespace(priv->mdev,
751 MLX5_FLOW_NAMESPACE_KERNEL), false);
753 /* The inner_ttc in the ttc params is intentionally not set */
754 mlx5e_set_ttc_params(priv, &ttc_params, false);
756 if (rep->vport != MLX5_VPORT_UPLINK)
757 /* To give uplik rep TTC a lower level for chaining from root ft */
758 ttc_params.ft_attr.level = MLX5E_TTC_FT_LEVEL + 1;
760 mlx5e_fs_set_ttc(priv->fs, mlx5_create_ttc_table(priv->mdev, &ttc_params), false);
761 if (IS_ERR(mlx5e_fs_get_ttc(priv->fs, false))) {
762 err = PTR_ERR(mlx5e_fs_get_ttc(priv->fs, false));
763 netdev_err(priv->netdev, "Failed to create rep ttc table, err=%d\n",
770 static int mlx5e_create_rep_root_ft(struct mlx5e_priv *priv)
772 struct mlx5e_rep_priv *rpriv = priv->ppriv;
773 struct mlx5_eswitch_rep *rep = rpriv->rep;
774 struct mlx5_flow_table_attr ft_attr = {};
775 struct mlx5_flow_namespace *ns;
778 if (rep->vport != MLX5_VPORT_UPLINK) {
779 /* non uplik reps will skip any bypass tables and go directly to
782 rpriv->root_ft = mlx5_get_ttc_flow_table(mlx5e_fs_get_ttc(priv->fs, false));
786 /* uplink root ft will be used to auto chain, to ethtool or ttc tables */
787 ns = mlx5_get_flow_namespace(priv->mdev, MLX5_FLOW_NAMESPACE_OFFLOADS);
789 netdev_err(priv->netdev, "Failed to get reps offloads namespace\n");
793 ft_attr.max_fte = 0; /* Empty table, miss rule will always point to next table */
797 rpriv->root_ft = mlx5_create_flow_table(ns, &ft_attr);
798 if (IS_ERR(rpriv->root_ft)) {
799 err = PTR_ERR(rpriv->root_ft);
800 rpriv->root_ft = NULL;
806 static void mlx5e_destroy_rep_root_ft(struct mlx5e_priv *priv)
808 struct mlx5e_rep_priv *rpriv = priv->ppriv;
809 struct mlx5_eswitch_rep *rep = rpriv->rep;
811 if (rep->vport != MLX5_VPORT_UPLINK)
813 mlx5_destroy_flow_table(rpriv->root_ft);
816 static int mlx5e_create_rep_vport_rx_rule(struct mlx5e_priv *priv)
818 struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
819 struct mlx5e_rep_priv *rpriv = priv->ppriv;
820 struct mlx5_eswitch_rep *rep = rpriv->rep;
821 struct mlx5_flow_handle *flow_rule;
822 struct mlx5_flow_destination dest;
824 dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
825 dest.ft = rpriv->root_ft;
827 flow_rule = mlx5_eswitch_create_vport_rx_rule(esw, rep->vport, &dest);
828 if (IS_ERR(flow_rule))
829 return PTR_ERR(flow_rule);
830 rpriv->vport_rx_rule = flow_rule;
834 static void rep_vport_rx_rule_destroy(struct mlx5e_priv *priv)
836 struct mlx5e_rep_priv *rpriv = priv->ppriv;
838 if (!rpriv->vport_rx_rule)
841 mlx5_del_flow_rules(rpriv->vport_rx_rule);
842 rpriv->vport_rx_rule = NULL;
845 int mlx5e_rep_bond_update(struct mlx5e_priv *priv, bool cleanup)
847 rep_vport_rx_rule_destroy(priv);
849 return cleanup ? 0 : mlx5e_create_rep_vport_rx_rule(priv);
852 static int mlx5e_init_rep_rx(struct mlx5e_priv *priv)
854 struct mlx5_core_dev *mdev = priv->mdev;
857 priv->rx_res = mlx5e_rx_res_alloc();
863 mlx5e_fs_init_l2_addr(priv->fs, priv->netdev);
865 err = mlx5e_open_drop_rq(priv, &priv->drop_rq);
867 mlx5_core_err(mdev, "open drop rq failed, %d\n", err);
871 err = mlx5e_rx_res_init(priv->rx_res, priv->mdev, 0,
872 priv->max_nch, priv->drop_rq.rqn,
873 &priv->channels.params.packet_merge,
874 priv->channels.params.num_channels);
876 goto err_close_drop_rq;
878 err = mlx5e_create_rep_ttc_table(priv);
880 goto err_destroy_rx_res;
882 err = mlx5e_create_rep_root_ft(priv);
884 goto err_destroy_ttc_table;
886 err = mlx5e_create_rep_vport_rx_rule(priv);
888 goto err_destroy_root_ft;
890 mlx5e_ethtool_init_steering(priv->fs);
895 mlx5e_destroy_rep_root_ft(priv);
896 err_destroy_ttc_table:
897 mlx5_destroy_ttc_table(mlx5e_fs_get_ttc(priv->fs, false));
899 mlx5e_rx_res_destroy(priv->rx_res);
901 mlx5e_close_drop_rq(&priv->drop_rq);
902 mlx5e_rx_res_free(priv->rx_res);
905 mlx5e_fs_cleanup(priv->fs);
909 static void mlx5e_cleanup_rep_rx(struct mlx5e_priv *priv)
911 mlx5e_ethtool_cleanup_steering(priv->fs);
912 rep_vport_rx_rule_destroy(priv);
913 mlx5e_destroy_rep_root_ft(priv);
914 mlx5_destroy_ttc_table(mlx5e_fs_get_ttc(priv->fs, false));
915 mlx5e_rx_res_destroy(priv->rx_res);
916 mlx5e_close_drop_rq(&priv->drop_rq);
917 mlx5e_rx_res_free(priv->rx_res);
921 static int mlx5e_init_ul_rep_rx(struct mlx5e_priv *priv)
925 mlx5e_create_q_counters(priv);
926 err = mlx5e_init_rep_rx(priv);
930 mlx5e_tc_int_port_init_rep_rx(priv);
936 static void mlx5e_cleanup_ul_rep_rx(struct mlx5e_priv *priv)
938 mlx5e_tc_int_port_cleanup_rep_rx(priv);
939 mlx5e_cleanup_rep_rx(priv);
940 mlx5e_destroy_q_counters(priv);
943 static int mlx5e_init_uplink_rep_tx(struct mlx5e_rep_priv *rpriv)
945 struct mlx5_rep_uplink_priv *uplink_priv;
946 struct net_device *netdev;
947 struct mlx5e_priv *priv;
950 netdev = rpriv->netdev;
951 priv = netdev_priv(netdev);
952 uplink_priv = &rpriv->uplink_priv;
954 err = mlx5e_rep_tc_init(rpriv);
958 mlx5_init_port_tun_entropy(&uplink_priv->tun_entropy, priv->mdev);
960 mlx5e_rep_bond_init(rpriv);
961 err = mlx5e_rep_tc_netdevice_event_register(rpriv);
963 mlx5_core_err(priv->mdev, "Failed to register netdev notifier, err: %d\n",
971 mlx5e_rep_bond_cleanup(rpriv);
972 mlx5e_rep_tc_cleanup(rpriv);
976 static void mlx5e_cleanup_uplink_rep_tx(struct mlx5e_rep_priv *rpriv)
978 mlx5e_rep_tc_netdevice_event_unregister(rpriv);
979 mlx5e_rep_bond_cleanup(rpriv);
980 mlx5e_rep_tc_cleanup(rpriv);
983 static int mlx5e_init_rep_tx(struct mlx5e_priv *priv)
985 struct mlx5e_rep_priv *rpriv = priv->ppriv;
988 err = mlx5e_create_tises(priv);
990 mlx5_core_warn(priv->mdev, "create tises failed, %d\n", err);
994 if (rpriv->rep->vport == MLX5_VPORT_UPLINK) {
995 err = mlx5e_init_uplink_rep_tx(rpriv);
1000 err = mlx5e_tc_ht_init(&rpriv->tc_ht);
1007 if (rpriv->rep->vport == MLX5_VPORT_UPLINK)
1008 mlx5e_cleanup_uplink_rep_tx(rpriv);
1010 mlx5e_destroy_tises(priv);
1014 static void mlx5e_cleanup_rep_tx(struct mlx5e_priv *priv)
1016 struct mlx5e_rep_priv *rpriv = priv->ppriv;
1018 mlx5e_tc_ht_cleanup(&rpriv->tc_ht);
1020 if (rpriv->rep->vport == MLX5_VPORT_UPLINK)
1021 mlx5e_cleanup_uplink_rep_tx(rpriv);
1023 mlx5e_destroy_tises(priv);
1026 static void mlx5e_rep_enable(struct mlx5e_priv *priv)
1028 struct mlx5e_rep_priv *rpriv = priv->ppriv;
1030 mlx5e_set_netdev_mtu_boundaries(priv);
1031 mlx5e_rep_neigh_init(rpriv);
1034 static void mlx5e_rep_disable(struct mlx5e_priv *priv)
1036 struct mlx5e_rep_priv *rpriv = priv->ppriv;
1038 mlx5e_rep_neigh_cleanup(rpriv);
1041 static int mlx5e_update_rep_rx(struct mlx5e_priv *priv)
1046 static int uplink_rep_async_event(struct notifier_block *nb, unsigned long event, void *data)
1048 struct mlx5e_priv *priv = container_of(nb, struct mlx5e_priv, events_nb);
1050 if (event == MLX5_EVENT_TYPE_PORT_CHANGE) {
1051 struct mlx5_eqe *eqe = data;
1053 switch (eqe->sub_type) {
1054 case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
1055 case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
1056 queue_work(priv->wq, &priv->update_carrier_work);
1065 if (event == MLX5_DEV_EVENT_PORT_AFFINITY)
1066 return mlx5e_rep_tc_event_port_affinity(priv);
1071 static void mlx5e_uplink_rep_enable(struct mlx5e_priv *priv)
1073 struct mlx5e_rep_priv *rpriv = priv->ppriv;
1074 struct net_device *netdev = priv->netdev;
1075 struct mlx5_core_dev *mdev = priv->mdev;
1078 netdev->min_mtu = ETH_MIN_MTU;
1079 mlx5_query_port_max_mtu(priv->mdev, &max_mtu, 1);
1080 netdev->max_mtu = MLX5E_HW2SW_MTU(&priv->channels.params, max_mtu);
1081 mlx5e_set_dev_port_mtu(priv);
1083 mlx5e_rep_tc_enable(priv);
1085 if (MLX5_CAP_GEN(mdev, uplink_follow))
1086 mlx5_modify_vport_admin_state(mdev, MLX5_VPORT_STATE_OP_MOD_UPLINK,
1087 0, 0, MLX5_VPORT_ADMIN_STATE_AUTO);
1088 mlx5_lag_add_netdev(mdev, netdev);
1089 priv->events_nb.notifier_call = uplink_rep_async_event;
1090 mlx5_notifier_register(mdev, &priv->events_nb);
1091 mlx5e_dcbnl_initialize(priv);
1092 mlx5e_dcbnl_init_app(priv);
1093 mlx5e_rep_neigh_init(rpriv);
1094 mlx5e_rep_bridge_init(priv);
1096 netdev->wanted_features |= NETIF_F_HW_TC;
1099 if (netif_running(netdev))
1101 udp_tunnel_nic_reset_ntf(priv->netdev);
1102 netif_device_attach(netdev);
1106 static void mlx5e_uplink_rep_disable(struct mlx5e_priv *priv)
1108 struct mlx5e_rep_priv *rpriv = priv->ppriv;
1109 struct mlx5_core_dev *mdev = priv->mdev;
1112 if (netif_running(priv->netdev))
1113 mlx5e_close(priv->netdev);
1114 netif_device_detach(priv->netdev);
1117 mlx5e_rep_bridge_cleanup(priv);
1118 mlx5e_rep_neigh_cleanup(rpriv);
1119 mlx5e_dcbnl_delete_app(priv);
1120 mlx5_notifier_unregister(mdev, &priv->events_nb);
1121 mlx5e_rep_tc_disable(priv);
1122 mlx5_lag_remove_netdev(mdev, priv->netdev);
1123 mlx5_vxlan_reset_to_default(mdev->vxlan);
1126 static MLX5E_DEFINE_STATS_GRP(sw_rep, 0);
1127 static MLX5E_DEFINE_STATS_GRP(vport_rep, MLX5E_NDO_UPDATE_STATS);
1129 /* The stats groups order is opposite to the update_stats() order calls */
1130 static mlx5e_stats_grp_t mlx5e_rep_stats_grps[] = {
1131 &MLX5E_STATS_GRP(sw_rep),
1132 &MLX5E_STATS_GRP(vport_rep),
1135 static unsigned int mlx5e_rep_stats_grps_num(struct mlx5e_priv *priv)
1137 return ARRAY_SIZE(mlx5e_rep_stats_grps);
1140 /* The stats groups order is opposite to the update_stats() order calls */
1141 static mlx5e_stats_grp_t mlx5e_ul_rep_stats_grps[] = {
1142 &MLX5E_STATS_GRP(sw),
1143 &MLX5E_STATS_GRP(qcnt),
1144 &MLX5E_STATS_GRP(vnic_env),
1145 &MLX5E_STATS_GRP(vport),
1146 &MLX5E_STATS_GRP(802_3),
1147 &MLX5E_STATS_GRP(2863),
1148 &MLX5E_STATS_GRP(2819),
1149 &MLX5E_STATS_GRP(phy),
1150 &MLX5E_STATS_GRP(eth_ext),
1151 &MLX5E_STATS_GRP(pcie),
1152 &MLX5E_STATS_GRP(per_prio),
1153 &MLX5E_STATS_GRP(pme),
1154 &MLX5E_STATS_GRP(channels),
1155 &MLX5E_STATS_GRP(per_port_buff_congest),
1156 #ifdef CONFIG_MLX5_EN_IPSEC
1157 &MLX5E_STATS_GRP(ipsec_sw),
1159 &MLX5E_STATS_GRP(ptp),
1162 static unsigned int mlx5e_ul_rep_stats_grps_num(struct mlx5e_priv *priv)
1164 return ARRAY_SIZE(mlx5e_ul_rep_stats_grps);
1167 static const struct mlx5e_profile mlx5e_rep_profile = {
1168 .init = mlx5e_init_rep,
1169 .cleanup = mlx5e_cleanup_rep,
1170 .init_rx = mlx5e_init_rep_rx,
1171 .cleanup_rx = mlx5e_cleanup_rep_rx,
1172 .init_tx = mlx5e_init_rep_tx,
1173 .cleanup_tx = mlx5e_cleanup_rep_tx,
1174 .enable = mlx5e_rep_enable,
1175 .disable = mlx5e_rep_disable,
1176 .update_rx = mlx5e_update_rep_rx,
1177 .update_stats = mlx5e_stats_update_ndo_stats,
1178 .rx_handlers = &mlx5e_rx_handlers_rep,
1180 .rq_groups = MLX5E_NUM_RQ_GROUPS(REGULAR),
1181 .stats_grps = mlx5e_rep_stats_grps,
1182 .stats_grps_num = mlx5e_rep_stats_grps_num,
1183 .max_nch_limit = mlx5e_rep_max_nch_limit,
1186 static const struct mlx5e_profile mlx5e_uplink_rep_profile = {
1187 .init = mlx5e_init_ul_rep,
1188 .cleanup = mlx5e_cleanup_rep,
1189 .init_rx = mlx5e_init_ul_rep_rx,
1190 .cleanup_rx = mlx5e_cleanup_ul_rep_rx,
1191 .init_tx = mlx5e_init_rep_tx,
1192 .cleanup_tx = mlx5e_cleanup_rep_tx,
1193 .enable = mlx5e_uplink_rep_enable,
1194 .disable = mlx5e_uplink_rep_disable,
1195 .update_rx = mlx5e_update_rep_rx,
1196 .update_stats = mlx5e_stats_update_ndo_stats,
1197 .update_carrier = mlx5e_update_carrier,
1198 .rx_handlers = &mlx5e_rx_handlers_rep,
1199 .max_tc = MLX5E_MAX_NUM_TC,
1200 /* XSK is needed so we can replace profile with NIC netdev */
1201 .rq_groups = MLX5E_NUM_RQ_GROUPS(XSK),
1202 .stats_grps = mlx5e_ul_rep_stats_grps,
1203 .stats_grps_num = mlx5e_ul_rep_stats_grps_num,
1206 /* e-Switch vport representors */
1208 mlx5e_vport_uplink_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
1210 struct mlx5e_priv *priv = netdev_priv(mlx5_uplink_netdev_get(dev));
1211 struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
1212 struct devlink_port *dl_port;
1215 rpriv->netdev = priv->netdev;
1217 err = mlx5e_netdev_change_profile(priv, &mlx5e_uplink_rep_profile,
1222 dl_port = mlx5_esw_offloads_devlink_port(dev->priv.eswitch, rpriv->rep->vport);
1224 devlink_port_type_eth_set(dl_port, rpriv->netdev);
1230 mlx5e_vport_uplink_rep_unload(struct mlx5e_rep_priv *rpriv)
1232 struct net_device *netdev = rpriv->netdev;
1233 struct devlink_port *dl_port;
1234 struct mlx5_core_dev *dev;
1235 struct mlx5e_priv *priv;
1237 priv = netdev_priv(netdev);
1240 dl_port = mlx5_esw_offloads_devlink_port(dev->priv.eswitch, rpriv->rep->vport);
1242 devlink_port_type_clear(dl_port);
1243 mlx5e_netdev_attach_nic_profile(priv);
1247 mlx5e_vport_vf_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
1249 struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
1250 const struct mlx5e_profile *profile;
1251 struct devlink_port *dl_port;
1252 struct net_device *netdev;
1253 struct mlx5e_priv *priv;
1256 profile = &mlx5e_rep_profile;
1257 netdev = mlx5e_create_netdev(dev, profile);
1260 "Failed to create representor netdev for vport %d\n",
1265 mlx5e_build_rep_netdev(netdev, dev);
1266 rpriv->netdev = netdev;
1268 priv = netdev_priv(netdev);
1269 priv->profile = profile;
1270 priv->ppriv = rpriv;
1271 err = profile->init(dev, netdev);
1273 netdev_warn(netdev, "rep profile init failed, %d\n", err);
1274 goto err_destroy_netdev;
1277 err = mlx5e_attach_netdev(netdev_priv(netdev));
1280 "Failed to attach representor netdev for vport %d\n",
1282 goto err_cleanup_profile;
1285 err = register_netdev(netdev);
1288 "Failed to register representor netdev for vport %d\n",
1290 goto err_detach_netdev;
1293 dl_port = mlx5_esw_offloads_devlink_port(dev->priv.eswitch, rpriv->rep->vport);
1295 devlink_port_type_eth_set(dl_port, netdev);
1299 mlx5e_detach_netdev(netdev_priv(netdev));
1301 err_cleanup_profile:
1302 priv->profile->cleanup(priv);
1305 mlx5e_destroy_netdev(netdev_priv(netdev));
1310 mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
1312 struct mlx5e_rep_priv *rpriv;
1315 rpriv = kvzalloc(sizeof(*rpriv), GFP_KERNEL);
1319 /* rpriv->rep to be looked up when profile->init() is called */
1321 rep->rep_data[REP_ETH].priv = rpriv;
1322 INIT_LIST_HEAD(&rpriv->vport_sqs_list);
1324 if (rep->vport == MLX5_VPORT_UPLINK)
1325 err = mlx5e_vport_uplink_rep_load(dev, rep);
1327 err = mlx5e_vport_vf_rep_load(dev, rep);
1336 mlx5e_vport_rep_unload(struct mlx5_eswitch_rep *rep)
1338 struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
1339 struct net_device *netdev = rpriv->netdev;
1340 struct mlx5e_priv *priv = netdev_priv(netdev);
1341 struct mlx5_core_dev *dev = priv->mdev;
1342 struct devlink_port *dl_port;
1343 void *ppriv = priv->ppriv;
1345 if (rep->vport == MLX5_VPORT_UPLINK) {
1346 mlx5e_vport_uplink_rep_unload(rpriv);
1350 dl_port = mlx5_esw_offloads_devlink_port(dev->priv.eswitch, rpriv->rep->vport);
1352 devlink_port_type_clear(dl_port);
1353 unregister_netdev(netdev);
1354 mlx5e_detach_netdev(priv);
1355 priv->profile->cleanup(priv);
1356 mlx5e_destroy_netdev(priv);
1358 kvfree(ppriv); /* mlx5e_rep_priv */
1361 static void *mlx5e_vport_rep_get_proto_dev(struct mlx5_eswitch_rep *rep)
1363 struct mlx5e_rep_priv *rpriv;
1365 rpriv = mlx5e_rep_to_rep_priv(rep);
1367 return rpriv->netdev;
1370 static void mlx5e_vport_rep_event_unpair(struct mlx5_eswitch_rep *rep)
1372 struct mlx5e_rep_priv *rpriv;
1373 struct mlx5e_rep_sq *rep_sq;
1375 rpriv = mlx5e_rep_to_rep_priv(rep);
1376 list_for_each_entry(rep_sq, &rpriv->vport_sqs_list, list) {
1377 if (!rep_sq->send_to_vport_rule_peer)
1379 mlx5_eswitch_del_send_to_vport_rule(rep_sq->send_to_vport_rule_peer);
1380 rep_sq->send_to_vport_rule_peer = NULL;
1384 static int mlx5e_vport_rep_event_pair(struct mlx5_eswitch *esw,
1385 struct mlx5_eswitch_rep *rep,
1386 struct mlx5_eswitch *peer_esw)
1388 struct mlx5_flow_handle *flow_rule;
1389 struct mlx5e_rep_priv *rpriv;
1390 struct mlx5e_rep_sq *rep_sq;
1392 rpriv = mlx5e_rep_to_rep_priv(rep);
1393 list_for_each_entry(rep_sq, &rpriv->vport_sqs_list, list) {
1394 if (rep_sq->send_to_vport_rule_peer)
1396 flow_rule = mlx5_eswitch_add_send_to_vport_rule(peer_esw, esw, rep, rep_sq->sqn);
1397 if (IS_ERR(flow_rule))
1399 rep_sq->send_to_vport_rule_peer = flow_rule;
1404 mlx5e_vport_rep_event_unpair(rep);
1405 return PTR_ERR(flow_rule);
1408 static int mlx5e_vport_rep_event(struct mlx5_eswitch *esw,
1409 struct mlx5_eswitch_rep *rep,
1410 enum mlx5_switchdev_event event,
1415 if (event == MLX5_SWITCHDEV_EVENT_PAIR)
1416 err = mlx5e_vport_rep_event_pair(esw, rep, data);
1417 else if (event == MLX5_SWITCHDEV_EVENT_UNPAIR)
1418 mlx5e_vport_rep_event_unpair(rep);
1423 static const struct mlx5_eswitch_rep_ops rep_ops = {
1424 .load = mlx5e_vport_rep_load,
1425 .unload = mlx5e_vport_rep_unload,
1426 .get_proto_dev = mlx5e_vport_rep_get_proto_dev,
1427 .event = mlx5e_vport_rep_event,
1430 static int mlx5e_rep_probe(struct auxiliary_device *adev,
1431 const struct auxiliary_device_id *id)
1433 struct mlx5_adev *edev = container_of(adev, struct mlx5_adev, adev);
1434 struct mlx5_core_dev *mdev = edev->mdev;
1435 struct mlx5_eswitch *esw;
1437 esw = mdev->priv.eswitch;
1438 mlx5_eswitch_register_vport_reps(esw, &rep_ops, REP_ETH);
1442 static void mlx5e_rep_remove(struct auxiliary_device *adev)
1444 struct mlx5_adev *vdev = container_of(adev, struct mlx5_adev, adev);
1445 struct mlx5_core_dev *mdev = vdev->mdev;
1446 struct mlx5_eswitch *esw;
1448 esw = mdev->priv.eswitch;
1449 mlx5_eswitch_unregister_vport_reps(esw, REP_ETH);
1452 static const struct auxiliary_device_id mlx5e_rep_id_table[] = {
1453 { .name = MLX5_ADEV_NAME ".eth-rep", },
1457 MODULE_DEVICE_TABLE(auxiliary, mlx5e_rep_id_table);
1459 static struct auxiliary_driver mlx5e_rep_driver = {
1461 .probe = mlx5e_rep_probe,
1462 .remove = mlx5e_rep_remove,
1463 .id_table = mlx5e_rep_id_table,
1466 int mlx5e_rep_init(void)
1468 return auxiliary_driver_register(&mlx5e_rep_driver);
1471 void mlx5e_rep_cleanup(void)
1473 auxiliary_driver_unregister(&mlx5e_rep_driver);