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"
60 #define MLX5E_REP_PARAMS_DEF_LOG_SQ_SIZE \
61 max(0x7, MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE)
62 #define MLX5E_REP_PARAMS_DEF_NUM_CHANNELS 1
64 static const char mlx5e_rep_driver_name[] = "mlx5e_rep";
66 static void mlx5e_rep_get_drvinfo(struct net_device *dev,
67 struct ethtool_drvinfo *drvinfo)
69 struct mlx5e_priv *priv = netdev_priv(dev);
70 struct mlx5_core_dev *mdev = priv->mdev;
72 strlcpy(drvinfo->driver, mlx5e_rep_driver_name,
73 sizeof(drvinfo->driver));
74 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
76 fw_rev_maj(mdev), fw_rev_min(mdev),
77 fw_rev_sub(mdev), mdev->board_id);
80 static const struct counter_desc sw_rep_stats_desc[] = {
81 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_packets) },
82 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_bytes) },
83 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_packets) },
84 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_bytes) },
94 static const struct counter_desc vport_rep_stats_desc[] = {
95 { MLX5E_DECLARE_STAT(struct vport_stats, vport_rx_packets) },
96 { MLX5E_DECLARE_STAT(struct vport_stats, vport_rx_bytes) },
97 { MLX5E_DECLARE_STAT(struct vport_stats, vport_tx_packets) },
98 { MLX5E_DECLARE_STAT(struct vport_stats, vport_tx_bytes) },
101 #define NUM_VPORT_REP_SW_COUNTERS ARRAY_SIZE(sw_rep_stats_desc)
102 #define NUM_VPORT_REP_HW_COUNTERS ARRAY_SIZE(vport_rep_stats_desc)
104 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(sw_rep)
106 return NUM_VPORT_REP_SW_COUNTERS;
109 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(sw_rep)
113 for (i = 0; i < NUM_VPORT_REP_SW_COUNTERS; i++)
114 strcpy(data + (idx++) * ETH_GSTRING_LEN,
115 sw_rep_stats_desc[i].format);
119 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(sw_rep)
123 for (i = 0; i < NUM_VPORT_REP_SW_COUNTERS; i++)
124 data[idx++] = MLX5E_READ_CTR64_CPU(&priv->stats.sw,
125 sw_rep_stats_desc, i);
129 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(sw_rep)
131 struct mlx5e_sw_stats *s = &priv->stats.sw;
132 struct rtnl_link_stats64 stats64 = {};
134 memset(s, 0, sizeof(*s));
135 mlx5e_fold_sw_stats64(priv, &stats64);
137 s->rx_packets = stats64.rx_packets;
138 s->rx_bytes = stats64.rx_bytes;
139 s->tx_packets = stats64.tx_packets;
140 s->tx_bytes = stats64.tx_bytes;
141 s->tx_queue_dropped = stats64.tx_dropped;
144 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(vport_rep)
146 return NUM_VPORT_REP_HW_COUNTERS;
149 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(vport_rep)
153 for (i = 0; i < NUM_VPORT_REP_HW_COUNTERS; i++)
154 strcpy(data + (idx++) * ETH_GSTRING_LEN, vport_rep_stats_desc[i].format);
158 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(vport_rep)
162 for (i = 0; i < NUM_VPORT_REP_HW_COUNTERS; i++)
163 data[idx++] = MLX5E_READ_CTR64_CPU(&priv->stats.vf_vport,
164 vport_rep_stats_desc, i);
168 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(vport_rep)
170 struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
171 struct mlx5e_rep_priv *rpriv = priv->ppriv;
172 struct mlx5_eswitch_rep *rep = rpriv->rep;
173 struct rtnl_link_stats64 *vport_stats;
174 struct ifla_vf_stats vf_stats;
177 err = mlx5_eswitch_get_vport_stats(esw, rep->vport, &vf_stats);
179 netdev_warn(priv->netdev, "vport %d error %d reading stats\n",
184 vport_stats = &priv->stats.vf_vport;
185 /* flip tx/rx as we are reporting the counters for the switch vport */
186 vport_stats->rx_packets = vf_stats.tx_packets;
187 vport_stats->rx_bytes = vf_stats.tx_bytes;
188 vport_stats->tx_packets = vf_stats.rx_packets;
189 vport_stats->tx_bytes = vf_stats.rx_bytes;
192 static void mlx5e_rep_get_strings(struct net_device *dev,
193 u32 stringset, uint8_t *data)
195 struct mlx5e_priv *priv = netdev_priv(dev);
199 mlx5e_stats_fill_strings(priv, data);
204 static void mlx5e_rep_get_ethtool_stats(struct net_device *dev,
205 struct ethtool_stats *stats, u64 *data)
207 struct mlx5e_priv *priv = netdev_priv(dev);
209 mlx5e_ethtool_get_ethtool_stats(priv, stats, data);
212 static int mlx5e_rep_get_sset_count(struct net_device *dev, int sset)
214 struct mlx5e_priv *priv = netdev_priv(dev);
218 return mlx5e_stats_total_num(priv);
225 mlx5e_rep_get_ringparam(struct net_device *dev,
226 struct ethtool_ringparam *param,
227 struct kernel_ethtool_ringparam *kernel_param,
228 struct netlink_ext_ack *extack)
230 struct mlx5e_priv *priv = netdev_priv(dev);
232 mlx5e_ethtool_get_ringparam(priv, param, kernel_param);
236 mlx5e_rep_set_ringparam(struct net_device *dev,
237 struct ethtool_ringparam *param,
238 struct kernel_ethtool_ringparam *kernel_param,
239 struct netlink_ext_ack *extack)
241 struct mlx5e_priv *priv = netdev_priv(dev);
243 return mlx5e_ethtool_set_ringparam(priv, param);
246 static void mlx5e_rep_get_channels(struct net_device *dev,
247 struct ethtool_channels *ch)
249 struct mlx5e_priv *priv = netdev_priv(dev);
251 mlx5e_ethtool_get_channels(priv, ch);
254 static int mlx5e_rep_set_channels(struct net_device *dev,
255 struct ethtool_channels *ch)
257 struct mlx5e_priv *priv = netdev_priv(dev);
259 return mlx5e_ethtool_set_channels(priv, ch);
262 static int mlx5e_rep_get_coalesce(struct net_device *netdev,
263 struct ethtool_coalesce *coal,
264 struct kernel_ethtool_coalesce *kernel_coal,
265 struct netlink_ext_ack *extack)
267 struct mlx5e_priv *priv = netdev_priv(netdev);
269 return mlx5e_ethtool_get_coalesce(priv, coal, kernel_coal);
272 static int mlx5e_rep_set_coalesce(struct net_device *netdev,
273 struct ethtool_coalesce *coal,
274 struct kernel_ethtool_coalesce *kernel_coal,
275 struct netlink_ext_ack *extack)
277 struct mlx5e_priv *priv = netdev_priv(netdev);
279 return mlx5e_ethtool_set_coalesce(priv, coal, kernel_coal, extack);
282 static u32 mlx5e_rep_get_rxfh_key_size(struct net_device *netdev)
284 struct mlx5e_priv *priv = netdev_priv(netdev);
286 return mlx5e_ethtool_get_rxfh_key_size(priv);
289 static u32 mlx5e_rep_get_rxfh_indir_size(struct net_device *netdev)
291 struct mlx5e_priv *priv = netdev_priv(netdev);
293 return mlx5e_ethtool_get_rxfh_indir_size(priv);
296 static const struct ethtool_ops mlx5e_rep_ethtool_ops = {
297 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
298 ETHTOOL_COALESCE_MAX_FRAMES |
299 ETHTOOL_COALESCE_USE_ADAPTIVE,
300 .get_drvinfo = mlx5e_rep_get_drvinfo,
301 .get_link = ethtool_op_get_link,
302 .get_strings = mlx5e_rep_get_strings,
303 .get_sset_count = mlx5e_rep_get_sset_count,
304 .get_ethtool_stats = mlx5e_rep_get_ethtool_stats,
305 .get_ringparam = mlx5e_rep_get_ringparam,
306 .set_ringparam = mlx5e_rep_set_ringparam,
307 .get_channels = mlx5e_rep_get_channels,
308 .set_channels = mlx5e_rep_set_channels,
309 .get_coalesce = mlx5e_rep_get_coalesce,
310 .set_coalesce = mlx5e_rep_set_coalesce,
311 .get_rxfh_key_size = mlx5e_rep_get_rxfh_key_size,
312 .get_rxfh_indir_size = mlx5e_rep_get_rxfh_indir_size,
315 static void mlx5e_sqs2vport_stop(struct mlx5_eswitch *esw,
316 struct mlx5_eswitch_rep *rep)
318 struct mlx5e_rep_sq *rep_sq, *tmp;
319 struct mlx5e_rep_priv *rpriv;
321 if (esw->mode != MLX5_ESWITCH_OFFLOADS)
324 rpriv = mlx5e_rep_to_rep_priv(rep);
325 list_for_each_entry_safe(rep_sq, tmp, &rpriv->vport_sqs_list, list) {
326 mlx5_eswitch_del_send_to_vport_rule(rep_sq->send_to_vport_rule);
327 if (rep_sq->send_to_vport_rule_peer)
328 mlx5_eswitch_del_send_to_vport_rule(rep_sq->send_to_vport_rule_peer);
329 list_del(&rep_sq->list);
334 static int mlx5e_sqs2vport_start(struct mlx5_eswitch *esw,
335 struct mlx5_eswitch_rep *rep,
336 u32 *sqns_array, int sqns_num)
338 struct mlx5_eswitch *peer_esw = NULL;
339 struct mlx5_flow_handle *flow_rule;
340 struct mlx5e_rep_priv *rpriv;
341 struct mlx5e_rep_sq *rep_sq;
345 if (esw->mode != MLX5_ESWITCH_OFFLOADS)
348 rpriv = mlx5e_rep_to_rep_priv(rep);
349 if (mlx5_devcom_is_paired(esw->dev->priv.devcom, MLX5_DEVCOM_ESW_OFFLOADS))
350 peer_esw = mlx5_devcom_get_peer_data(esw->dev->priv.devcom,
351 MLX5_DEVCOM_ESW_OFFLOADS);
353 for (i = 0; i < sqns_num; i++) {
354 rep_sq = kzalloc(sizeof(*rep_sq), GFP_KERNEL);
360 /* Add re-inject rule to the PF/representor sqs */
361 flow_rule = mlx5_eswitch_add_send_to_vport_rule(esw, esw, rep,
363 if (IS_ERR(flow_rule)) {
364 err = PTR_ERR(flow_rule);
368 rep_sq->send_to_vport_rule = flow_rule;
369 rep_sq->sqn = sqns_array[i];
372 flow_rule = mlx5_eswitch_add_send_to_vport_rule(peer_esw, esw,
374 if (IS_ERR(flow_rule)) {
375 err = PTR_ERR(flow_rule);
376 mlx5_eswitch_del_send_to_vport_rule(rep_sq->send_to_vport_rule);
380 rep_sq->send_to_vport_rule_peer = flow_rule;
383 list_add(&rep_sq->list, &rpriv->vport_sqs_list);
387 mlx5_devcom_release_peer_data(esw->dev->priv.devcom, MLX5_DEVCOM_ESW_OFFLOADS);
392 mlx5e_sqs2vport_stop(esw, rep);
395 mlx5_devcom_release_peer_data(esw->dev->priv.devcom, MLX5_DEVCOM_ESW_OFFLOADS);
400 int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv)
402 int sqs_per_channel = mlx5e_get_dcb_num_tc(&priv->channels.params);
403 struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
404 bool is_uplink_rep = mlx5e_is_uplink_rep(priv);
405 struct mlx5e_rep_priv *rpriv = priv->ppriv;
406 struct mlx5_eswitch_rep *rep = rpriv->rep;
407 int n, tc, nch, num_sqs = 0;
408 struct mlx5e_channel *c;
413 ptp_sq = !!(priv->channels.ptp &&
414 MLX5E_GET_PFLAG(&priv->channels.params, MLX5E_PFLAG_TX_PORT_TS));
415 nch = priv->channels.num + ptp_sq;
416 /* +2 for xdpsqs, they don't exist on the ptp channel but will not be
417 * counted for by num_sqs.
420 sqs_per_channel += 2;
422 sqs = kvcalloc(nch * sqs_per_channel, sizeof(*sqs), GFP_KERNEL);
426 for (n = 0; n < priv->channels.num; n++) {
427 c = priv->channels.c[n];
428 for (tc = 0; tc < c->num_tc; tc++)
429 sqs[num_sqs++] = c->sq[tc].sqn;
433 sqs[num_sqs++] = c->rq_xdpsq.sqn;
435 sqs[num_sqs++] = c->xdpsq.sqn;
439 struct mlx5e_ptp *ptp_ch = priv->channels.ptp;
441 for (tc = 0; tc < ptp_ch->num_tc; tc++)
442 sqs[num_sqs++] = ptp_ch->ptpsq[tc].txqsq.sqn;
445 err = mlx5e_sqs2vport_start(esw, rep, sqs, num_sqs);
450 netdev_warn(priv->netdev, "Failed to add SQs FWD rules %d\n", err);
454 void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv)
456 struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
457 struct mlx5e_rep_priv *rpriv = priv->ppriv;
458 struct mlx5_eswitch_rep *rep = rpriv->rep;
460 mlx5e_sqs2vport_stop(esw, rep);
463 static int mlx5e_rep_open(struct net_device *dev)
465 struct mlx5e_priv *priv = netdev_priv(dev);
466 struct mlx5e_rep_priv *rpriv = priv->ppriv;
467 struct mlx5_eswitch_rep *rep = rpriv->rep;
470 mutex_lock(&priv->state_lock);
471 err = mlx5e_open_locked(dev);
475 if (!mlx5_modify_vport_admin_state(priv->mdev,
476 MLX5_VPORT_STATE_OP_MOD_ESW_VPORT,
478 MLX5_VPORT_ADMIN_STATE_UP))
479 netif_carrier_on(dev);
482 mutex_unlock(&priv->state_lock);
486 static int mlx5e_rep_close(struct net_device *dev)
488 struct mlx5e_priv *priv = netdev_priv(dev);
489 struct mlx5e_rep_priv *rpriv = priv->ppriv;
490 struct mlx5_eswitch_rep *rep = rpriv->rep;
493 mutex_lock(&priv->state_lock);
494 mlx5_modify_vport_admin_state(priv->mdev,
495 MLX5_VPORT_STATE_OP_MOD_ESW_VPORT,
497 MLX5_VPORT_ADMIN_STATE_DOWN);
498 ret = mlx5e_close_locked(dev);
499 mutex_unlock(&priv->state_lock);
503 bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv)
505 struct mlx5e_rep_priv *rpriv = priv->ppriv;
506 struct mlx5_eswitch_rep *rep;
508 if (!MLX5_ESWITCH_MANAGER(priv->mdev))
511 if (!rpriv) /* non vport rep mlx5e instances don't use this field */
515 return (rep->vport == MLX5_VPORT_UPLINK);
518 bool mlx5e_rep_has_offload_stats(const struct net_device *dev, int attr_id)
521 case IFLA_OFFLOAD_XSTATS_CPU_HIT:
529 mlx5e_get_sw_stats64(const struct net_device *dev,
530 struct rtnl_link_stats64 *stats)
532 struct mlx5e_priv *priv = netdev_priv(dev);
534 mlx5e_fold_sw_stats64(priv, stats);
538 int mlx5e_rep_get_offload_stats(int attr_id, const struct net_device *dev,
542 case IFLA_OFFLOAD_XSTATS_CPU_HIT:
543 return mlx5e_get_sw_stats64(dev, sp);
550 mlx5e_rep_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
552 struct mlx5e_priv *priv = netdev_priv(dev);
554 /* update HW stats in background for next time */
555 mlx5e_queue_update_stats(priv);
556 memcpy(stats, &priv->stats.vf_vport, sizeof(*stats));
559 static int mlx5e_rep_change_mtu(struct net_device *netdev, int new_mtu)
561 return mlx5e_change_mtu(netdev, new_mtu, NULL);
564 static struct devlink_port *mlx5e_rep_get_devlink_port(struct net_device *netdev)
566 struct mlx5e_priv *priv = netdev_priv(netdev);
567 struct mlx5e_rep_priv *rpriv = priv->ppriv;
568 struct mlx5_core_dev *dev = priv->mdev;
570 return mlx5_esw_offloads_devlink_port(dev->priv.eswitch, rpriv->rep->vport);
573 static int mlx5e_rep_change_carrier(struct net_device *dev, bool new_carrier)
575 struct mlx5e_priv *priv = netdev_priv(dev);
576 struct mlx5e_rep_priv *rpriv = priv->ppriv;
577 struct mlx5_eswitch_rep *rep = rpriv->rep;
581 err = mlx5_modify_vport_admin_state(priv->mdev, MLX5_VPORT_STATE_OP_MOD_ESW_VPORT,
582 rep->vport, 1, MLX5_VPORT_ADMIN_STATE_UP);
585 netif_carrier_on(dev);
587 err = mlx5_modify_vport_admin_state(priv->mdev, MLX5_VPORT_STATE_OP_MOD_ESW_VPORT,
588 rep->vport, 1, MLX5_VPORT_ADMIN_STATE_DOWN);
591 netif_carrier_off(dev);
596 static const struct net_device_ops mlx5e_netdev_ops_rep = {
597 .ndo_open = mlx5e_rep_open,
598 .ndo_stop = mlx5e_rep_close,
599 .ndo_start_xmit = mlx5e_xmit,
600 .ndo_setup_tc = mlx5e_rep_setup_tc,
601 .ndo_get_devlink_port = mlx5e_rep_get_devlink_port,
602 .ndo_get_stats64 = mlx5e_rep_get_stats,
603 .ndo_has_offload_stats = mlx5e_rep_has_offload_stats,
604 .ndo_get_offload_stats = mlx5e_rep_get_offload_stats,
605 .ndo_change_mtu = mlx5e_rep_change_mtu,
606 .ndo_change_carrier = mlx5e_rep_change_carrier,
609 bool mlx5e_eswitch_uplink_rep(const struct net_device *netdev)
611 return netdev->netdev_ops == &mlx5e_netdev_ops &&
612 mlx5e_is_uplink_rep(netdev_priv(netdev));
615 bool mlx5e_eswitch_vf_rep(const struct net_device *netdev)
617 return netdev->netdev_ops == &mlx5e_netdev_ops_rep;
620 /* One indirect TIR set for outer. Inner not supported in reps. */
621 #define REP_NUM_INDIR_TIRS MLX5E_NUM_INDIR_TIRS
623 static int mlx5e_rep_max_nch_limit(struct mlx5_core_dev *mdev)
625 int max_tir_num = 1 << MLX5_CAP_GEN(mdev, log_max_tir);
626 int num_vports = mlx5_eswitch_get_total_vports(mdev);
628 return (max_tir_num - mlx5e_get_pf_num_tirs(mdev)
629 - (num_vports * REP_NUM_INDIR_TIRS)) / num_vports;
632 static void mlx5e_build_rep_params(struct net_device *netdev)
634 struct mlx5e_priv *priv = netdev_priv(netdev);
635 struct mlx5e_rep_priv *rpriv = priv->ppriv;
636 struct mlx5_eswitch_rep *rep = rpriv->rep;
637 struct mlx5_core_dev *mdev = priv->mdev;
638 struct mlx5e_params *params;
640 u8 cq_period_mode = MLX5_CAP_GEN(mdev, cq_period_start_from_cqe) ?
641 MLX5_CQ_PERIOD_MODE_START_FROM_CQE :
642 MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
644 params = &priv->channels.params;
646 params->num_channels = MLX5E_REP_PARAMS_DEF_NUM_CHANNELS;
647 params->hard_mtu = MLX5E_ETH_HARD_MTU;
648 params->sw_mtu = netdev->mtu;
651 if (rep->vport == MLX5_VPORT_UPLINK)
652 params->log_sq_size = MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE;
654 params->log_sq_size = MLX5E_REP_PARAMS_DEF_LOG_SQ_SIZE;
657 mlx5e_build_rq_params(mdev, params);
659 /* CQ moderation params */
660 params->rx_dim_enabled = MLX5_CAP_GEN(mdev, cq_moderation);
661 mlx5e_set_rx_cq_mode_params(params, cq_period_mode);
663 params->mqprio.num_tc = 1;
664 params->tunneled_offload_en = false;
666 mlx5_query_min_inline(mdev, ¶ms->tx_min_inline_mode);
669 static void mlx5e_build_rep_netdev(struct net_device *netdev,
670 struct mlx5_core_dev *mdev)
672 SET_NETDEV_DEV(netdev, mdev->device);
673 netdev->netdev_ops = &mlx5e_netdev_ops_rep;
674 eth_hw_addr_random(netdev);
675 netdev->ethtool_ops = &mlx5e_rep_ethtool_ops;
677 netdev->watchdog_timeo = 15 * HZ;
679 #if IS_ENABLED(CONFIG_MLX5_CLS_ACT)
680 netdev->hw_features |= NETIF_F_HW_TC;
682 netdev->hw_features |= NETIF_F_SG;
683 netdev->hw_features |= NETIF_F_IP_CSUM;
684 netdev->hw_features |= NETIF_F_IPV6_CSUM;
685 netdev->hw_features |= NETIF_F_GRO;
686 netdev->hw_features |= NETIF_F_TSO;
687 netdev->hw_features |= NETIF_F_TSO6;
688 netdev->hw_features |= NETIF_F_RXCSUM;
690 netdev->features |= netdev->hw_features;
691 netdev->features |= NETIF_F_NETNS_LOCAL;
694 static int mlx5e_init_rep(struct mlx5_core_dev *mdev,
695 struct net_device *netdev)
697 struct mlx5e_priv *priv = netdev_priv(netdev);
699 mlx5e_build_rep_params(netdev);
700 mlx5e_timestamp_init(priv);
705 static int mlx5e_init_ul_rep(struct mlx5_core_dev *mdev,
706 struct net_device *netdev)
708 struct mlx5e_priv *priv = netdev_priv(netdev);
711 err = mlx5e_ipsec_init(priv);
713 mlx5_core_err(mdev, "Uplink rep IPsec initialization failed, %d\n", err);
715 mlx5e_vxlan_set_netdev_info(priv);
716 return mlx5e_init_rep(mdev, netdev);
719 static void mlx5e_cleanup_rep(struct mlx5e_priv *priv)
721 mlx5e_fs_cleanup(priv->fs);
722 mlx5e_ipsec_cleanup(priv);
725 static int mlx5e_create_rep_ttc_table(struct mlx5e_priv *priv)
727 struct mlx5e_rep_priv *rpriv = priv->ppriv;
728 struct mlx5_eswitch_rep *rep = rpriv->rep;
729 struct ttc_params ttc_params = {};
732 priv->fs->ns = mlx5_get_flow_namespace(priv->mdev,
733 MLX5_FLOW_NAMESPACE_KERNEL);
735 /* The inner_ttc in the ttc params is intentionally not set */
736 mlx5e_set_ttc_params(priv, &ttc_params, false);
738 if (rep->vport != MLX5_VPORT_UPLINK)
739 /* To give uplik rep TTC a lower level for chaining from root ft */
740 ttc_params.ft_attr.level = MLX5E_TTC_FT_LEVEL + 1;
742 priv->fs->ttc = mlx5_create_ttc_table(priv->mdev, &ttc_params);
743 if (IS_ERR(priv->fs->ttc)) {
744 err = PTR_ERR(priv->fs->ttc);
745 netdev_err(priv->netdev, "Failed to create rep ttc table, err=%d\n",
752 static int mlx5e_create_rep_root_ft(struct mlx5e_priv *priv)
754 struct mlx5e_rep_priv *rpriv = priv->ppriv;
755 struct mlx5_eswitch_rep *rep = rpriv->rep;
756 struct mlx5_flow_table_attr ft_attr = {};
757 struct mlx5_flow_namespace *ns;
760 if (rep->vport != MLX5_VPORT_UPLINK) {
761 /* non uplik reps will skip any bypass tables and go directly to
764 rpriv->root_ft = mlx5_get_ttc_flow_table(priv->fs->ttc);
768 /* uplink root ft will be used to auto chain, to ethtool or ttc tables */
769 ns = mlx5_get_flow_namespace(priv->mdev, MLX5_FLOW_NAMESPACE_OFFLOADS);
771 netdev_err(priv->netdev, "Failed to get reps offloads namespace\n");
775 ft_attr.max_fte = 0; /* Empty table, miss rule will always point to next table */
779 rpriv->root_ft = mlx5_create_flow_table(ns, &ft_attr);
780 if (IS_ERR(rpriv->root_ft)) {
781 err = PTR_ERR(rpriv->root_ft);
782 rpriv->root_ft = NULL;
788 static void mlx5e_destroy_rep_root_ft(struct mlx5e_priv *priv)
790 struct mlx5e_rep_priv *rpriv = priv->ppriv;
791 struct mlx5_eswitch_rep *rep = rpriv->rep;
793 if (rep->vport != MLX5_VPORT_UPLINK)
795 mlx5_destroy_flow_table(rpriv->root_ft);
798 static int mlx5e_create_rep_vport_rx_rule(struct mlx5e_priv *priv)
800 struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
801 struct mlx5e_rep_priv *rpriv = priv->ppriv;
802 struct mlx5_eswitch_rep *rep = rpriv->rep;
803 struct mlx5_flow_handle *flow_rule;
804 struct mlx5_flow_destination dest;
806 dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
807 dest.ft = rpriv->root_ft;
809 flow_rule = mlx5_eswitch_create_vport_rx_rule(esw, rep->vport, &dest);
810 if (IS_ERR(flow_rule))
811 return PTR_ERR(flow_rule);
812 rpriv->vport_rx_rule = flow_rule;
816 static void rep_vport_rx_rule_destroy(struct mlx5e_priv *priv)
818 struct mlx5e_rep_priv *rpriv = priv->ppriv;
820 if (!rpriv->vport_rx_rule)
823 mlx5_del_flow_rules(rpriv->vport_rx_rule);
824 rpriv->vport_rx_rule = NULL;
827 int mlx5e_rep_bond_update(struct mlx5e_priv *priv, bool cleanup)
829 rep_vport_rx_rule_destroy(priv);
831 return cleanup ? 0 : mlx5e_create_rep_vport_rx_rule(priv);
834 static int mlx5e_init_rep_rx(struct mlx5e_priv *priv)
836 struct mlx5_core_dev *mdev = priv->mdev;
839 priv->fs = mlx5e_fs_init(priv->profile, mdev,
840 !test_bit(MLX5E_STATE_DESTROYING, &priv->state));
842 netdev_err(priv->netdev, "FS allocation failed\n");
846 priv->rx_res = mlx5e_rx_res_alloc();
852 mlx5e_fs_init_l2_addr(priv->fs, priv->netdev);
854 err = mlx5e_open_drop_rq(priv, &priv->drop_rq);
856 mlx5_core_err(mdev, "open drop rq failed, %d\n", err);
860 err = mlx5e_rx_res_init(priv->rx_res, priv->mdev, 0,
861 priv->max_nch, priv->drop_rq.rqn,
862 &priv->channels.params.packet_merge,
863 priv->channels.params.num_channels);
865 goto err_close_drop_rq;
867 err = mlx5e_create_rep_ttc_table(priv);
869 goto err_destroy_rx_res;
871 err = mlx5e_create_rep_root_ft(priv);
873 goto err_destroy_ttc_table;
875 err = mlx5e_create_rep_vport_rx_rule(priv);
877 goto err_destroy_root_ft;
879 mlx5e_ethtool_init_steering(priv);
884 mlx5e_destroy_rep_root_ft(priv);
885 err_destroy_ttc_table:
886 mlx5_destroy_ttc_table(priv->fs->ttc);
888 mlx5e_rx_res_destroy(priv->rx_res);
890 mlx5e_close_drop_rq(&priv->drop_rq);
891 mlx5e_rx_res_free(priv->rx_res);
894 mlx5e_fs_cleanup(priv->fs);
898 static void mlx5e_cleanup_rep_rx(struct mlx5e_priv *priv)
900 mlx5e_ethtool_cleanup_steering(priv);
901 rep_vport_rx_rule_destroy(priv);
902 mlx5e_destroy_rep_root_ft(priv);
903 mlx5_destroy_ttc_table(priv->fs->ttc);
904 mlx5e_rx_res_destroy(priv->rx_res);
905 mlx5e_close_drop_rq(&priv->drop_rq);
906 mlx5e_rx_res_free(priv->rx_res);
910 static int mlx5e_init_ul_rep_rx(struct mlx5e_priv *priv)
914 mlx5e_create_q_counters(priv);
915 err = mlx5e_init_rep_rx(priv);
919 mlx5e_tc_int_port_init_rep_rx(priv);
925 static void mlx5e_cleanup_ul_rep_rx(struct mlx5e_priv *priv)
927 mlx5e_tc_int_port_cleanup_rep_rx(priv);
928 mlx5e_cleanup_rep_rx(priv);
929 mlx5e_destroy_q_counters(priv);
932 static int mlx5e_init_uplink_rep_tx(struct mlx5e_rep_priv *rpriv)
934 struct mlx5_rep_uplink_priv *uplink_priv;
935 struct net_device *netdev;
936 struct mlx5e_priv *priv;
939 netdev = rpriv->netdev;
940 priv = netdev_priv(netdev);
941 uplink_priv = &rpriv->uplink_priv;
943 err = mlx5e_rep_tc_init(rpriv);
947 mlx5_init_port_tun_entropy(&uplink_priv->tun_entropy, priv->mdev);
949 mlx5e_rep_bond_init(rpriv);
950 err = mlx5e_rep_tc_netdevice_event_register(rpriv);
952 mlx5_core_err(priv->mdev, "Failed to register netdev notifier, err: %d\n",
960 mlx5e_rep_bond_cleanup(rpriv);
961 mlx5e_rep_tc_cleanup(rpriv);
965 static void mlx5e_cleanup_uplink_rep_tx(struct mlx5e_rep_priv *rpriv)
967 mlx5e_rep_tc_netdevice_event_unregister(rpriv);
968 mlx5e_rep_bond_cleanup(rpriv);
969 mlx5e_rep_tc_cleanup(rpriv);
972 static int mlx5e_init_rep_tx(struct mlx5e_priv *priv)
974 struct mlx5e_rep_priv *rpriv = priv->ppriv;
977 err = mlx5e_create_tises(priv);
979 mlx5_core_warn(priv->mdev, "create tises failed, %d\n", err);
983 if (rpriv->rep->vport == MLX5_VPORT_UPLINK) {
984 err = mlx5e_init_uplink_rep_tx(rpriv);
989 err = mlx5e_tc_ht_init(&rpriv->tc_ht);
996 if (rpriv->rep->vport == MLX5_VPORT_UPLINK)
997 mlx5e_cleanup_uplink_rep_tx(rpriv);
999 mlx5e_destroy_tises(priv);
1003 static void mlx5e_cleanup_rep_tx(struct mlx5e_priv *priv)
1005 struct mlx5e_rep_priv *rpriv = priv->ppriv;
1007 mlx5e_tc_ht_cleanup(&rpriv->tc_ht);
1009 if (rpriv->rep->vport == MLX5_VPORT_UPLINK)
1010 mlx5e_cleanup_uplink_rep_tx(rpriv);
1012 mlx5e_destroy_tises(priv);
1015 static void mlx5e_rep_enable(struct mlx5e_priv *priv)
1017 struct mlx5e_rep_priv *rpriv = priv->ppriv;
1019 mlx5e_set_netdev_mtu_boundaries(priv);
1020 mlx5e_rep_neigh_init(rpriv);
1023 static void mlx5e_rep_disable(struct mlx5e_priv *priv)
1025 struct mlx5e_rep_priv *rpriv = priv->ppriv;
1027 mlx5e_rep_neigh_cleanup(rpriv);
1030 static int mlx5e_update_rep_rx(struct mlx5e_priv *priv)
1035 static int uplink_rep_async_event(struct notifier_block *nb, unsigned long event, void *data)
1037 struct mlx5e_priv *priv = container_of(nb, struct mlx5e_priv, events_nb);
1039 if (event == MLX5_EVENT_TYPE_PORT_CHANGE) {
1040 struct mlx5_eqe *eqe = data;
1042 switch (eqe->sub_type) {
1043 case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
1044 case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
1045 queue_work(priv->wq, &priv->update_carrier_work);
1054 if (event == MLX5_DEV_EVENT_PORT_AFFINITY)
1055 return mlx5e_rep_tc_event_port_affinity(priv);
1060 static void mlx5e_uplink_rep_enable(struct mlx5e_priv *priv)
1062 struct mlx5e_rep_priv *rpriv = priv->ppriv;
1063 struct net_device *netdev = priv->netdev;
1064 struct mlx5_core_dev *mdev = priv->mdev;
1067 netdev->min_mtu = ETH_MIN_MTU;
1068 mlx5_query_port_max_mtu(priv->mdev, &max_mtu, 1);
1069 netdev->max_mtu = MLX5E_HW2SW_MTU(&priv->channels.params, max_mtu);
1070 mlx5e_set_dev_port_mtu(priv);
1072 mlx5e_rep_tc_enable(priv);
1074 if (MLX5_CAP_GEN(mdev, uplink_follow))
1075 mlx5_modify_vport_admin_state(mdev, MLX5_VPORT_STATE_OP_MOD_UPLINK,
1076 0, 0, MLX5_VPORT_ADMIN_STATE_AUTO);
1077 mlx5_lag_add_netdev(mdev, netdev);
1078 priv->events_nb.notifier_call = uplink_rep_async_event;
1079 mlx5_notifier_register(mdev, &priv->events_nb);
1080 mlx5e_dcbnl_initialize(priv);
1081 mlx5e_dcbnl_init_app(priv);
1082 mlx5e_rep_neigh_init(rpriv);
1083 mlx5e_rep_bridge_init(priv);
1085 netdev->wanted_features |= NETIF_F_HW_TC;
1088 if (netif_running(netdev))
1090 udp_tunnel_nic_reset_ntf(priv->netdev);
1091 netif_device_attach(netdev);
1095 static void mlx5e_uplink_rep_disable(struct mlx5e_priv *priv)
1097 struct mlx5e_rep_priv *rpriv = priv->ppriv;
1098 struct mlx5_core_dev *mdev = priv->mdev;
1101 if (netif_running(priv->netdev))
1102 mlx5e_close(priv->netdev);
1103 netif_device_detach(priv->netdev);
1106 mlx5e_rep_bridge_cleanup(priv);
1107 mlx5e_rep_neigh_cleanup(rpriv);
1108 mlx5e_dcbnl_delete_app(priv);
1109 mlx5_notifier_unregister(mdev, &priv->events_nb);
1110 mlx5e_rep_tc_disable(priv);
1111 mlx5_lag_remove_netdev(mdev, priv->netdev);
1112 mlx5_vxlan_reset_to_default(mdev->vxlan);
1115 static MLX5E_DEFINE_STATS_GRP(sw_rep, 0);
1116 static MLX5E_DEFINE_STATS_GRP(vport_rep, MLX5E_NDO_UPDATE_STATS);
1118 /* The stats groups order is opposite to the update_stats() order calls */
1119 static mlx5e_stats_grp_t mlx5e_rep_stats_grps[] = {
1120 &MLX5E_STATS_GRP(sw_rep),
1121 &MLX5E_STATS_GRP(vport_rep),
1124 static unsigned int mlx5e_rep_stats_grps_num(struct mlx5e_priv *priv)
1126 return ARRAY_SIZE(mlx5e_rep_stats_grps);
1129 /* The stats groups order is opposite to the update_stats() order calls */
1130 static mlx5e_stats_grp_t mlx5e_ul_rep_stats_grps[] = {
1131 &MLX5E_STATS_GRP(sw),
1132 &MLX5E_STATS_GRP(qcnt),
1133 &MLX5E_STATS_GRP(vnic_env),
1134 &MLX5E_STATS_GRP(vport),
1135 &MLX5E_STATS_GRP(802_3),
1136 &MLX5E_STATS_GRP(2863),
1137 &MLX5E_STATS_GRP(2819),
1138 &MLX5E_STATS_GRP(phy),
1139 &MLX5E_STATS_GRP(eth_ext),
1140 &MLX5E_STATS_GRP(pcie),
1141 &MLX5E_STATS_GRP(per_prio),
1142 &MLX5E_STATS_GRP(pme),
1143 &MLX5E_STATS_GRP(channels),
1144 &MLX5E_STATS_GRP(per_port_buff_congest),
1145 #ifdef CONFIG_MLX5_EN_IPSEC
1146 &MLX5E_STATS_GRP(ipsec_sw),
1148 &MLX5E_STATS_GRP(ptp),
1151 static unsigned int mlx5e_ul_rep_stats_grps_num(struct mlx5e_priv *priv)
1153 return ARRAY_SIZE(mlx5e_ul_rep_stats_grps);
1156 static const struct mlx5e_profile mlx5e_rep_profile = {
1157 .init = mlx5e_init_rep,
1158 .cleanup = mlx5e_cleanup_rep,
1159 .init_rx = mlx5e_init_rep_rx,
1160 .cleanup_rx = mlx5e_cleanup_rep_rx,
1161 .init_tx = mlx5e_init_rep_tx,
1162 .cleanup_tx = mlx5e_cleanup_rep_tx,
1163 .enable = mlx5e_rep_enable,
1164 .disable = mlx5e_rep_disable,
1165 .update_rx = mlx5e_update_rep_rx,
1166 .update_stats = mlx5e_stats_update_ndo_stats,
1167 .rx_handlers = &mlx5e_rx_handlers_rep,
1169 .rq_groups = MLX5E_NUM_RQ_GROUPS(REGULAR),
1170 .stats_grps = mlx5e_rep_stats_grps,
1171 .stats_grps_num = mlx5e_rep_stats_grps_num,
1172 .max_nch_limit = mlx5e_rep_max_nch_limit,
1175 static const struct mlx5e_profile mlx5e_uplink_rep_profile = {
1176 .init = mlx5e_init_ul_rep,
1177 .cleanup = mlx5e_cleanup_rep,
1178 .init_rx = mlx5e_init_ul_rep_rx,
1179 .cleanup_rx = mlx5e_cleanup_ul_rep_rx,
1180 .init_tx = mlx5e_init_rep_tx,
1181 .cleanup_tx = mlx5e_cleanup_rep_tx,
1182 .enable = mlx5e_uplink_rep_enable,
1183 .disable = mlx5e_uplink_rep_disable,
1184 .update_rx = mlx5e_update_rep_rx,
1185 .update_stats = mlx5e_stats_update_ndo_stats,
1186 .update_carrier = mlx5e_update_carrier,
1187 .rx_handlers = &mlx5e_rx_handlers_rep,
1188 .max_tc = MLX5E_MAX_NUM_TC,
1189 /* XSK is needed so we can replace profile with NIC netdev */
1190 .rq_groups = MLX5E_NUM_RQ_GROUPS(XSK),
1191 .stats_grps = mlx5e_ul_rep_stats_grps,
1192 .stats_grps_num = mlx5e_ul_rep_stats_grps_num,
1195 /* e-Switch vport representors */
1197 mlx5e_vport_uplink_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
1199 struct mlx5e_priv *priv = netdev_priv(mlx5_uplink_netdev_get(dev));
1200 struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
1201 struct devlink_port *dl_port;
1204 rpriv->netdev = priv->netdev;
1206 err = mlx5e_netdev_change_profile(priv, &mlx5e_uplink_rep_profile,
1211 dl_port = mlx5_esw_offloads_devlink_port(dev->priv.eswitch, rpriv->rep->vport);
1213 devlink_port_type_eth_set(dl_port, rpriv->netdev);
1219 mlx5e_vport_uplink_rep_unload(struct mlx5e_rep_priv *rpriv)
1221 struct net_device *netdev = rpriv->netdev;
1222 struct devlink_port *dl_port;
1223 struct mlx5_core_dev *dev;
1224 struct mlx5e_priv *priv;
1226 priv = netdev_priv(netdev);
1229 dl_port = mlx5_esw_offloads_devlink_port(dev->priv.eswitch, rpriv->rep->vport);
1231 devlink_port_type_clear(dl_port);
1232 mlx5e_netdev_attach_nic_profile(priv);
1236 mlx5e_vport_vf_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
1238 struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
1239 const struct mlx5e_profile *profile;
1240 struct devlink_port *dl_port;
1241 struct net_device *netdev;
1242 struct mlx5e_priv *priv;
1245 profile = &mlx5e_rep_profile;
1246 netdev = mlx5e_create_netdev(dev, profile);
1249 "Failed to create representor netdev for vport %d\n",
1254 mlx5e_build_rep_netdev(netdev, dev);
1255 rpriv->netdev = netdev;
1257 priv = netdev_priv(netdev);
1258 priv->profile = profile;
1259 priv->ppriv = rpriv;
1260 err = profile->init(dev, netdev);
1262 netdev_warn(netdev, "rep profile init failed, %d\n", err);
1263 goto err_destroy_netdev;
1266 err = mlx5e_attach_netdev(netdev_priv(netdev));
1269 "Failed to attach representor netdev for vport %d\n",
1271 goto err_cleanup_profile;
1274 err = register_netdev(netdev);
1277 "Failed to register representor netdev for vport %d\n",
1279 goto err_detach_netdev;
1282 dl_port = mlx5_esw_offloads_devlink_port(dev->priv.eswitch, rpriv->rep->vport);
1284 devlink_port_type_eth_set(dl_port, netdev);
1288 mlx5e_detach_netdev(netdev_priv(netdev));
1290 err_cleanup_profile:
1291 priv->profile->cleanup(priv);
1294 mlx5e_destroy_netdev(netdev_priv(netdev));
1299 mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
1301 struct mlx5e_rep_priv *rpriv;
1304 rpriv = kvzalloc(sizeof(*rpriv), GFP_KERNEL);
1308 /* rpriv->rep to be looked up when profile->init() is called */
1310 rep->rep_data[REP_ETH].priv = rpriv;
1311 INIT_LIST_HEAD(&rpriv->vport_sqs_list);
1313 if (rep->vport == MLX5_VPORT_UPLINK)
1314 err = mlx5e_vport_uplink_rep_load(dev, rep);
1316 err = mlx5e_vport_vf_rep_load(dev, rep);
1325 mlx5e_vport_rep_unload(struct mlx5_eswitch_rep *rep)
1327 struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
1328 struct net_device *netdev = rpriv->netdev;
1329 struct mlx5e_priv *priv = netdev_priv(netdev);
1330 struct mlx5_core_dev *dev = priv->mdev;
1331 struct devlink_port *dl_port;
1332 void *ppriv = priv->ppriv;
1334 if (rep->vport == MLX5_VPORT_UPLINK) {
1335 mlx5e_vport_uplink_rep_unload(rpriv);
1339 dl_port = mlx5_esw_offloads_devlink_port(dev->priv.eswitch, rpriv->rep->vport);
1341 devlink_port_type_clear(dl_port);
1342 unregister_netdev(netdev);
1343 mlx5e_detach_netdev(priv);
1344 priv->profile->cleanup(priv);
1345 mlx5e_destroy_netdev(priv);
1347 kvfree(ppriv); /* mlx5e_rep_priv */
1350 static void *mlx5e_vport_rep_get_proto_dev(struct mlx5_eswitch_rep *rep)
1352 struct mlx5e_rep_priv *rpriv;
1354 rpriv = mlx5e_rep_to_rep_priv(rep);
1356 return rpriv->netdev;
1359 static void mlx5e_vport_rep_event_unpair(struct mlx5_eswitch_rep *rep)
1361 struct mlx5e_rep_priv *rpriv;
1362 struct mlx5e_rep_sq *rep_sq;
1364 rpriv = mlx5e_rep_to_rep_priv(rep);
1365 list_for_each_entry(rep_sq, &rpriv->vport_sqs_list, list) {
1366 if (!rep_sq->send_to_vport_rule_peer)
1368 mlx5_eswitch_del_send_to_vport_rule(rep_sq->send_to_vport_rule_peer);
1369 rep_sq->send_to_vport_rule_peer = NULL;
1373 static int mlx5e_vport_rep_event_pair(struct mlx5_eswitch *esw,
1374 struct mlx5_eswitch_rep *rep,
1375 struct mlx5_eswitch *peer_esw)
1377 struct mlx5_flow_handle *flow_rule;
1378 struct mlx5e_rep_priv *rpriv;
1379 struct mlx5e_rep_sq *rep_sq;
1381 rpriv = mlx5e_rep_to_rep_priv(rep);
1382 list_for_each_entry(rep_sq, &rpriv->vport_sqs_list, list) {
1383 if (rep_sq->send_to_vport_rule_peer)
1385 flow_rule = mlx5_eswitch_add_send_to_vport_rule(peer_esw, esw, rep, rep_sq->sqn);
1386 if (IS_ERR(flow_rule))
1388 rep_sq->send_to_vport_rule_peer = flow_rule;
1393 mlx5e_vport_rep_event_unpair(rep);
1394 return PTR_ERR(flow_rule);
1397 static int mlx5e_vport_rep_event(struct mlx5_eswitch *esw,
1398 struct mlx5_eswitch_rep *rep,
1399 enum mlx5_switchdev_event event,
1404 if (event == MLX5_SWITCHDEV_EVENT_PAIR)
1405 err = mlx5e_vport_rep_event_pair(esw, rep, data);
1406 else if (event == MLX5_SWITCHDEV_EVENT_UNPAIR)
1407 mlx5e_vport_rep_event_unpair(rep);
1412 static const struct mlx5_eswitch_rep_ops rep_ops = {
1413 .load = mlx5e_vport_rep_load,
1414 .unload = mlx5e_vport_rep_unload,
1415 .get_proto_dev = mlx5e_vport_rep_get_proto_dev,
1416 .event = mlx5e_vport_rep_event,
1419 static int mlx5e_rep_probe(struct auxiliary_device *adev,
1420 const struct auxiliary_device_id *id)
1422 struct mlx5_adev *edev = container_of(adev, struct mlx5_adev, adev);
1423 struct mlx5_core_dev *mdev = edev->mdev;
1424 struct mlx5_eswitch *esw;
1426 esw = mdev->priv.eswitch;
1427 mlx5_eswitch_register_vport_reps(esw, &rep_ops, REP_ETH);
1431 static void mlx5e_rep_remove(struct auxiliary_device *adev)
1433 struct mlx5_adev *vdev = container_of(adev, struct mlx5_adev, adev);
1434 struct mlx5_core_dev *mdev = vdev->mdev;
1435 struct mlx5_eswitch *esw;
1437 esw = mdev->priv.eswitch;
1438 mlx5_eswitch_unregister_vport_reps(esw, REP_ETH);
1441 static const struct auxiliary_device_id mlx5e_rep_id_table[] = {
1442 { .name = MLX5_ADEV_NAME ".eth-rep", },
1446 MODULE_DEVICE_TABLE(auxiliary, mlx5e_rep_id_table);
1448 static struct auxiliary_driver mlx5e_rep_driver = {
1450 .probe = mlx5e_rep_probe,
1451 .remove = mlx5e_rep_remove,
1452 .id_table = mlx5e_rep_id_table,
1455 int mlx5e_rep_init(void)
1457 return auxiliary_driver_register(&mlx5e_rep_driver);
1460 void mlx5e_rep_cleanup(void)
1462 auxiliary_driver_unregister(&mlx5e_rep_driver);