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 <generated/utsrelease.h>
34 #include <linux/mlx5/fs.h>
35 #include <net/switchdev.h>
36 #include <net/pkt_cls.h>
37 #include <net/act_api.h>
38 #include <net/netevent.h>
40 #include <net/devlink.h>
41 #include <net/ipv6_stubs.h>
47 #include "en/tc_tun.h"
49 #include "lib/port_tun.h"
51 #define CREATE_TRACE_POINTS
52 #include "diag/en_rep_tracepoint.h"
54 #define MLX5E_REP_PARAMS_DEF_LOG_SQ_SIZE \
55 max(0x7, MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE)
56 #define MLX5E_REP_PARAMS_DEF_NUM_CHANNELS 1
58 static const char mlx5e_rep_driver_name
[] = "mlx5e_rep";
60 struct mlx5e_rep_indr_block_priv
{
61 struct net_device
*netdev
;
62 struct mlx5e_rep_priv
*rpriv
;
64 struct list_head list
;
67 static void mlx5e_rep_indr_unregister_block(struct mlx5e_rep_priv
*rpriv
,
68 struct net_device
*netdev
);
70 static void mlx5e_rep_get_drvinfo(struct net_device
*dev
,
71 struct ethtool_drvinfo
*drvinfo
)
73 struct mlx5e_priv
*priv
= netdev_priv(dev
);
74 struct mlx5_core_dev
*mdev
= priv
->mdev
;
76 strlcpy(drvinfo
->driver
, mlx5e_rep_driver_name
,
77 sizeof(drvinfo
->driver
));
78 strlcpy(drvinfo
->version
, UTS_RELEASE
, sizeof(drvinfo
->version
));
79 snprintf(drvinfo
->fw_version
, sizeof(drvinfo
->fw_version
),
81 fw_rev_maj(mdev
), fw_rev_min(mdev
),
82 fw_rev_sub(mdev
), mdev
->board_id
);
85 static void mlx5e_uplink_rep_get_drvinfo(struct net_device
*dev
,
86 struct ethtool_drvinfo
*drvinfo
)
88 struct mlx5e_priv
*priv
= netdev_priv(dev
);
90 mlx5e_rep_get_drvinfo(dev
, drvinfo
);
91 strlcpy(drvinfo
->bus_info
, pci_name(priv
->mdev
->pdev
),
92 sizeof(drvinfo
->bus_info
));
95 static const struct counter_desc sw_rep_stats_desc
[] = {
96 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats
, rx_packets
) },
97 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats
, rx_bytes
) },
98 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats
, tx_packets
) },
99 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats
, tx_bytes
) },
103 u64 vport_rx_packets
;
104 u64 vport_tx_packets
;
109 static const struct counter_desc vport_rep_stats_desc
[] = {
110 { MLX5E_DECLARE_STAT(struct vport_stats
, vport_rx_packets
) },
111 { MLX5E_DECLARE_STAT(struct vport_stats
, vport_rx_bytes
) },
112 { MLX5E_DECLARE_STAT(struct vport_stats
, vport_tx_packets
) },
113 { MLX5E_DECLARE_STAT(struct vport_stats
, vport_tx_bytes
) },
116 #define NUM_VPORT_REP_SW_COUNTERS ARRAY_SIZE(sw_rep_stats_desc)
117 #define NUM_VPORT_REP_HW_COUNTERS ARRAY_SIZE(vport_rep_stats_desc)
119 static void mlx5e_rep_get_strings(struct net_device
*dev
,
120 u32 stringset
, uint8_t *data
)
126 for (i
= 0; i
< NUM_VPORT_REP_SW_COUNTERS
; i
++)
127 strcpy(data
+ (i
* ETH_GSTRING_LEN
),
128 sw_rep_stats_desc
[i
].format
);
129 for (j
= 0; j
< NUM_VPORT_REP_HW_COUNTERS
; j
++, i
++)
130 strcpy(data
+ (i
* ETH_GSTRING_LEN
),
131 vport_rep_stats_desc
[j
].format
);
136 static void mlx5e_rep_update_hw_counters(struct mlx5e_priv
*priv
)
138 struct mlx5_eswitch
*esw
= priv
->mdev
->priv
.eswitch
;
139 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
140 struct mlx5_eswitch_rep
*rep
= rpriv
->rep
;
141 struct rtnl_link_stats64
*vport_stats
;
142 struct ifla_vf_stats vf_stats
;
145 err
= mlx5_eswitch_get_vport_stats(esw
, rep
->vport
, &vf_stats
);
147 pr_warn("vport %d error %d reading stats\n", rep
->vport
, err
);
151 vport_stats
= &priv
->stats
.vf_vport
;
152 /* flip tx/rx as we are reporting the counters for the switch vport */
153 vport_stats
->rx_packets
= vf_stats
.tx_packets
;
154 vport_stats
->rx_bytes
= vf_stats
.tx_bytes
;
155 vport_stats
->tx_packets
= vf_stats
.rx_packets
;
156 vport_stats
->tx_bytes
= vf_stats
.rx_bytes
;
159 static void mlx5e_uplink_rep_update_hw_counters(struct mlx5e_priv
*priv
)
161 struct mlx5e_pport_stats
*pstats
= &priv
->stats
.pport
;
162 struct rtnl_link_stats64
*vport_stats
;
164 mlx5e_grp_802_3_update_stats(priv
);
166 vport_stats
= &priv
->stats
.vf_vport
;
168 vport_stats
->rx_packets
= PPORT_802_3_GET(pstats
, a_frames_received_ok
);
169 vport_stats
->rx_bytes
= PPORT_802_3_GET(pstats
, a_octets_received_ok
);
170 vport_stats
->tx_packets
= PPORT_802_3_GET(pstats
, a_frames_transmitted_ok
);
171 vport_stats
->tx_bytes
= PPORT_802_3_GET(pstats
, a_octets_transmitted_ok
);
174 static void mlx5e_rep_update_sw_counters(struct mlx5e_priv
*priv
)
176 struct mlx5e_sw_stats
*s
= &priv
->stats
.sw
;
177 struct rtnl_link_stats64 stats64
= {};
179 memset(s
, 0, sizeof(*s
));
180 mlx5e_fold_sw_stats64(priv
, &stats64
);
182 s
->rx_packets
= stats64
.rx_packets
;
183 s
->rx_bytes
= stats64
.rx_bytes
;
184 s
->tx_packets
= stats64
.tx_packets
;
185 s
->tx_bytes
= stats64
.tx_bytes
;
186 s
->tx_queue_dropped
= stats64
.tx_dropped
;
189 static void mlx5e_rep_get_ethtool_stats(struct net_device
*dev
,
190 struct ethtool_stats
*stats
, u64
*data
)
192 struct mlx5e_priv
*priv
= netdev_priv(dev
);
198 mutex_lock(&priv
->state_lock
);
199 mlx5e_rep_update_sw_counters(priv
);
200 priv
->profile
->update_stats(priv
);
201 mutex_unlock(&priv
->state_lock
);
203 for (i
= 0; i
< NUM_VPORT_REP_SW_COUNTERS
; i
++)
204 data
[i
] = MLX5E_READ_CTR64_CPU(&priv
->stats
.sw
,
205 sw_rep_stats_desc
, i
);
207 for (j
= 0; j
< NUM_VPORT_REP_HW_COUNTERS
; j
++, i
++)
208 data
[i
] = MLX5E_READ_CTR64_CPU(&priv
->stats
.vf_vport
,
209 vport_rep_stats_desc
, j
);
212 static int mlx5e_rep_get_sset_count(struct net_device
*dev
, int sset
)
216 return NUM_VPORT_REP_SW_COUNTERS
+ NUM_VPORT_REP_HW_COUNTERS
;
222 static void mlx5e_rep_get_ringparam(struct net_device
*dev
,
223 struct ethtool_ringparam
*param
)
225 struct mlx5e_priv
*priv
= netdev_priv(dev
);
227 mlx5e_ethtool_get_ringparam(priv
, param
);
230 static int mlx5e_rep_set_ringparam(struct net_device
*dev
,
231 struct ethtool_ringparam
*param
)
233 struct mlx5e_priv
*priv
= netdev_priv(dev
);
235 return mlx5e_ethtool_set_ringparam(priv
, param
);
238 static int mlx5e_replace_rep_vport_rx_rule(struct mlx5e_priv
*priv
,
239 struct mlx5_flow_destination
*dest
)
241 struct mlx5_eswitch
*esw
= priv
->mdev
->priv
.eswitch
;
242 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
243 struct mlx5_eswitch_rep
*rep
= rpriv
->rep
;
244 struct mlx5_flow_handle
*flow_rule
;
246 flow_rule
= mlx5_eswitch_create_vport_rx_rule(esw
,
249 if (IS_ERR(flow_rule
))
250 return PTR_ERR(flow_rule
);
252 mlx5_del_flow_rules(rpriv
->vport_rx_rule
);
253 rpriv
->vport_rx_rule
= flow_rule
;
257 static void mlx5e_rep_get_channels(struct net_device
*dev
,
258 struct ethtool_channels
*ch
)
260 struct mlx5e_priv
*priv
= netdev_priv(dev
);
262 mlx5e_ethtool_get_channels(priv
, ch
);
265 static int mlx5e_rep_set_channels(struct net_device
*dev
,
266 struct ethtool_channels
*ch
)
268 struct mlx5e_priv
*priv
= netdev_priv(dev
);
269 u16 curr_channels_amount
= priv
->channels
.params
.num_channels
;
270 u32 new_channels_amount
= ch
->combined_count
;
271 struct mlx5_flow_destination new_dest
;
274 err
= mlx5e_ethtool_set_channels(priv
, ch
);
278 if (curr_channels_amount
== 1 && new_channels_amount
> 1) {
279 new_dest
.type
= MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE
;
280 new_dest
.ft
= priv
->fs
.ttc
.ft
.t
;
281 } else if (new_channels_amount
== 1 && curr_channels_amount
> 1) {
282 new_dest
.type
= MLX5_FLOW_DESTINATION_TYPE_TIR
;
283 new_dest
.tir_num
= priv
->direct_tir
[0].tirn
;
288 err
= mlx5e_replace_rep_vport_rx_rule(priv
, &new_dest
);
290 netdev_warn(priv
->netdev
, "Failed to update vport rx rule, when going from (%d) channels to (%d) channels\n",
291 curr_channels_amount
, new_channels_amount
);
298 static int mlx5e_rep_get_coalesce(struct net_device
*netdev
,
299 struct ethtool_coalesce
*coal
)
301 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
303 return mlx5e_ethtool_get_coalesce(priv
, coal
);
306 static int mlx5e_rep_set_coalesce(struct net_device
*netdev
,
307 struct ethtool_coalesce
*coal
)
309 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
311 return mlx5e_ethtool_set_coalesce(priv
, coal
);
314 static u32
mlx5e_rep_get_rxfh_key_size(struct net_device
*netdev
)
316 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
318 return mlx5e_ethtool_get_rxfh_key_size(priv
);
321 static u32
mlx5e_rep_get_rxfh_indir_size(struct net_device
*netdev
)
323 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
325 return mlx5e_ethtool_get_rxfh_indir_size(priv
);
328 static void mlx5e_uplink_rep_get_pauseparam(struct net_device
*netdev
,
329 struct ethtool_pauseparam
*pauseparam
)
331 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
333 mlx5e_ethtool_get_pauseparam(priv
, pauseparam
);
336 static int mlx5e_uplink_rep_set_pauseparam(struct net_device
*netdev
,
337 struct ethtool_pauseparam
*pauseparam
)
339 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
341 return mlx5e_ethtool_set_pauseparam(priv
, pauseparam
);
344 static int mlx5e_uplink_rep_get_link_ksettings(struct net_device
*netdev
,
345 struct ethtool_link_ksettings
*link_ksettings
)
347 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
349 return mlx5e_ethtool_get_link_ksettings(priv
, link_ksettings
);
352 static int mlx5e_uplink_rep_set_link_ksettings(struct net_device
*netdev
,
353 const struct ethtool_link_ksettings
*link_ksettings
)
355 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
357 return mlx5e_ethtool_set_link_ksettings(priv
, link_ksettings
);
360 static const struct ethtool_ops mlx5e_rep_ethtool_ops
= {
361 .get_drvinfo
= mlx5e_rep_get_drvinfo
,
362 .get_link
= ethtool_op_get_link
,
363 .get_strings
= mlx5e_rep_get_strings
,
364 .get_sset_count
= mlx5e_rep_get_sset_count
,
365 .get_ethtool_stats
= mlx5e_rep_get_ethtool_stats
,
366 .get_ringparam
= mlx5e_rep_get_ringparam
,
367 .set_ringparam
= mlx5e_rep_set_ringparam
,
368 .get_channels
= mlx5e_rep_get_channels
,
369 .set_channels
= mlx5e_rep_set_channels
,
370 .get_coalesce
= mlx5e_rep_get_coalesce
,
371 .set_coalesce
= mlx5e_rep_set_coalesce
,
372 .get_rxfh_key_size
= mlx5e_rep_get_rxfh_key_size
,
373 .get_rxfh_indir_size
= mlx5e_rep_get_rxfh_indir_size
,
376 static const struct ethtool_ops mlx5e_uplink_rep_ethtool_ops
= {
377 .get_drvinfo
= mlx5e_uplink_rep_get_drvinfo
,
378 .get_link
= ethtool_op_get_link
,
379 .get_strings
= mlx5e_rep_get_strings
,
380 .get_sset_count
= mlx5e_rep_get_sset_count
,
381 .get_ethtool_stats
= mlx5e_rep_get_ethtool_stats
,
382 .get_ringparam
= mlx5e_rep_get_ringparam
,
383 .set_ringparam
= mlx5e_rep_set_ringparam
,
384 .get_channels
= mlx5e_rep_get_channels
,
385 .set_channels
= mlx5e_rep_set_channels
,
386 .get_coalesce
= mlx5e_rep_get_coalesce
,
387 .set_coalesce
= mlx5e_rep_set_coalesce
,
388 .get_link_ksettings
= mlx5e_uplink_rep_get_link_ksettings
,
389 .set_link_ksettings
= mlx5e_uplink_rep_set_link_ksettings
,
390 .get_rxfh_key_size
= mlx5e_rep_get_rxfh_key_size
,
391 .get_rxfh_indir_size
= mlx5e_rep_get_rxfh_indir_size
,
392 .get_pauseparam
= mlx5e_uplink_rep_get_pauseparam
,
393 .set_pauseparam
= mlx5e_uplink_rep_set_pauseparam
,
396 static void mlx5e_rep_get_port_parent_id(struct net_device
*dev
,
397 struct netdev_phys_item_id
*ppid
)
399 struct mlx5e_priv
*priv
;
402 priv
= netdev_priv(dev
);
404 parent_id
= mlx5_query_nic_system_image_guid(priv
->mdev
);
405 ppid
->id_len
= sizeof(parent_id
);
406 memcpy(ppid
->id
, &parent_id
, sizeof(parent_id
));
409 static void mlx5e_sqs2vport_stop(struct mlx5_eswitch
*esw
,
410 struct mlx5_eswitch_rep
*rep
)
412 struct mlx5e_rep_sq
*rep_sq
, *tmp
;
413 struct mlx5e_rep_priv
*rpriv
;
415 if (esw
->mode
!= MLX5_ESWITCH_OFFLOADS
)
418 rpriv
= mlx5e_rep_to_rep_priv(rep
);
419 list_for_each_entry_safe(rep_sq
, tmp
, &rpriv
->vport_sqs_list
, list
) {
420 mlx5_eswitch_del_send_to_vport_rule(rep_sq
->send_to_vport_rule
);
421 list_del(&rep_sq
->list
);
426 static int mlx5e_sqs2vport_start(struct mlx5_eswitch
*esw
,
427 struct mlx5_eswitch_rep
*rep
,
428 u32
*sqns_array
, int sqns_num
)
430 struct mlx5_flow_handle
*flow_rule
;
431 struct mlx5e_rep_priv
*rpriv
;
432 struct mlx5e_rep_sq
*rep_sq
;
436 if (esw
->mode
!= MLX5_ESWITCH_OFFLOADS
)
439 rpriv
= mlx5e_rep_to_rep_priv(rep
);
440 for (i
= 0; i
< sqns_num
; i
++) {
441 rep_sq
= kzalloc(sizeof(*rep_sq
), GFP_KERNEL
);
447 /* Add re-inject rule to the PF/representor sqs */
448 flow_rule
= mlx5_eswitch_add_send_to_vport_rule(esw
,
451 if (IS_ERR(flow_rule
)) {
452 err
= PTR_ERR(flow_rule
);
456 rep_sq
->send_to_vport_rule
= flow_rule
;
457 list_add(&rep_sq
->list
, &rpriv
->vport_sqs_list
);
462 mlx5e_sqs2vport_stop(esw
, rep
);
466 int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv
*priv
)
468 struct mlx5_eswitch
*esw
= priv
->mdev
->priv
.eswitch
;
469 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
470 struct mlx5_eswitch_rep
*rep
= rpriv
->rep
;
471 struct mlx5e_channel
*c
;
472 int n
, tc
, num_sqs
= 0;
476 sqs
= kcalloc(priv
->channels
.num
* priv
->channels
.params
.num_tc
, sizeof(*sqs
), GFP_KERNEL
);
480 for (n
= 0; n
< priv
->channels
.num
; n
++) {
481 c
= priv
->channels
.c
[n
];
482 for (tc
= 0; tc
< c
->num_tc
; tc
++)
483 sqs
[num_sqs
++] = c
->sq
[tc
].sqn
;
486 err
= mlx5e_sqs2vport_start(esw
, rep
, sqs
, num_sqs
);
491 netdev_warn(priv
->netdev
, "Failed to add SQs FWD rules %d\n", err
);
495 void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv
*priv
)
497 struct mlx5_eswitch
*esw
= priv
->mdev
->priv
.eswitch
;
498 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
499 struct mlx5_eswitch_rep
*rep
= rpriv
->rep
;
501 mlx5e_sqs2vport_stop(esw
, rep
);
504 static unsigned long mlx5e_rep_ipv6_interval(void)
506 if (IS_ENABLED(CONFIG_IPV6
) && ipv6_stub
->nd_tbl
)
507 return NEIGH_VAR(&ipv6_stub
->nd_tbl
->parms
, DELAY_PROBE_TIME
);
512 static void mlx5e_rep_neigh_update_init_interval(struct mlx5e_rep_priv
*rpriv
)
514 unsigned long ipv4_interval
= NEIGH_VAR(&arp_tbl
.parms
, DELAY_PROBE_TIME
);
515 unsigned long ipv6_interval
= mlx5e_rep_ipv6_interval();
516 struct net_device
*netdev
= rpriv
->netdev
;
517 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
519 rpriv
->neigh_update
.min_interval
= min_t(unsigned long, ipv6_interval
, ipv4_interval
);
520 mlx5_fc_update_sampling_interval(priv
->mdev
, rpriv
->neigh_update
.min_interval
);
523 void mlx5e_rep_queue_neigh_stats_work(struct mlx5e_priv
*priv
)
525 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
526 struct mlx5e_neigh_update_table
*neigh_update
= &rpriv
->neigh_update
;
528 mlx5_fc_queue_stats_work(priv
->mdev
,
529 &neigh_update
->neigh_stats_work
,
530 neigh_update
->min_interval
);
533 static bool mlx5e_rep_neigh_entry_hold(struct mlx5e_neigh_hash_entry
*nhe
)
535 return refcount_inc_not_zero(&nhe
->refcnt
);
538 static void mlx5e_rep_neigh_entry_remove(struct mlx5e_neigh_hash_entry
*nhe
);
540 static void mlx5e_rep_neigh_entry_release(struct mlx5e_neigh_hash_entry
*nhe
)
542 if (refcount_dec_and_test(&nhe
->refcnt
)) {
543 mlx5e_rep_neigh_entry_remove(nhe
);
548 static struct mlx5e_neigh_hash_entry
*
549 mlx5e_get_next_nhe(struct mlx5e_rep_priv
*rpriv
,
550 struct mlx5e_neigh_hash_entry
*nhe
)
552 struct mlx5e_neigh_hash_entry
*next
= NULL
;
557 list_next_or_null_rcu(&rpriv
->neigh_update
.neigh_list
,
559 struct mlx5e_neigh_hash_entry
,
561 list_first_or_null_rcu(&rpriv
->neigh_update
.neigh_list
,
562 struct mlx5e_neigh_hash_entry
,
565 next
= list_next_or_null_rcu(&rpriv
->neigh_update
.neigh_list
,
567 struct mlx5e_neigh_hash_entry
,
569 if (mlx5e_rep_neigh_entry_hold(next
))
575 mlx5e_rep_neigh_entry_release(nhe
);
580 static void mlx5e_rep_neigh_stats_work(struct work_struct
*work
)
582 struct mlx5e_rep_priv
*rpriv
= container_of(work
, struct mlx5e_rep_priv
,
583 neigh_update
.neigh_stats_work
.work
);
584 struct net_device
*netdev
= rpriv
->netdev
;
585 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
586 struct mlx5e_neigh_hash_entry
*nhe
= NULL
;
589 if (!list_empty(&rpriv
->neigh_update
.neigh_list
))
590 mlx5e_rep_queue_neigh_stats_work(priv
);
592 while ((nhe
= mlx5e_get_next_nhe(rpriv
, nhe
)) != NULL
)
593 mlx5e_tc_update_neigh_used_value(nhe
);
598 static void mlx5e_rep_update_flows(struct mlx5e_priv
*priv
,
599 struct mlx5e_encap_entry
*e
,
600 bool neigh_connected
,
601 unsigned char ha
[ETH_ALEN
])
603 struct ethhdr
*eth
= (struct ethhdr
*)e
->encap_header
;
604 struct mlx5_eswitch
*esw
= priv
->mdev
->priv
.eswitch
;
605 bool encap_connected
;
606 LIST_HEAD(flow_list
);
610 /* wait for encap to be fully initialized */
611 wait_for_completion(&e
->res_ready
);
613 mutex_lock(&esw
->offloads
.encap_tbl_lock
);
614 encap_connected
= !!(e
->flags
& MLX5_ENCAP_ENTRY_VALID
);
615 if (e
->compl_result
< 0 || (encap_connected
== neigh_connected
&&
616 ether_addr_equal(e
->h_dest
, ha
)))
619 mlx5e_take_all_encap_flows(e
, &flow_list
);
621 if ((e
->flags
& MLX5_ENCAP_ENTRY_VALID
) &&
622 (!neigh_connected
|| !ether_addr_equal(e
->h_dest
, ha
)))
623 mlx5e_tc_encap_flows_del(priv
, e
, &flow_list
);
625 if (neigh_connected
&& !(e
->flags
& MLX5_ENCAP_ENTRY_VALID
)) {
626 ether_addr_copy(e
->h_dest
, ha
);
627 ether_addr_copy(eth
->h_dest
, ha
);
628 /* Update the encap source mac, in case that we delete
629 * the flows when encap source mac changed.
631 ether_addr_copy(eth
->h_source
, e
->route_dev
->dev_addr
);
633 mlx5e_tc_encap_flows_add(priv
, e
, &flow_list
);
636 mutex_unlock(&esw
->offloads
.encap_tbl_lock
);
637 mlx5e_put_encap_flow_list(priv
, &flow_list
);
640 static void mlx5e_rep_neigh_update(struct work_struct
*work
)
642 struct mlx5e_neigh_hash_entry
*nhe
=
643 container_of(work
, struct mlx5e_neigh_hash_entry
, neigh_update_work
);
644 struct neighbour
*n
= nhe
->n
;
645 struct mlx5e_encap_entry
*e
;
646 unsigned char ha
[ETH_ALEN
];
647 struct mlx5e_priv
*priv
;
648 bool neigh_connected
;
653 /* If these parameters are changed after we release the lock,
654 * we'll receive another event letting us know about it.
655 * We use this lock to avoid inconsistency between the neigh validity
656 * and it's hw address.
658 read_lock_bh(&n
->lock
);
659 memcpy(ha
, n
->ha
, ETH_ALEN
);
660 nud_state
= n
->nud_state
;
662 read_unlock_bh(&n
->lock
);
664 neigh_connected
= (nud_state
& NUD_VALID
) && !dead
;
666 trace_mlx5e_rep_neigh_update(nhe
, ha
, neigh_connected
);
668 list_for_each_entry(e
, &nhe
->encap_list
, encap_list
) {
669 if (!mlx5e_encap_take(e
))
672 priv
= netdev_priv(e
->out_dev
);
673 mlx5e_rep_update_flows(priv
, e
, neigh_connected
, ha
);
674 mlx5e_encap_put(priv
, e
);
676 mlx5e_rep_neigh_entry_release(nhe
);
681 static struct mlx5e_rep_indr_block_priv
*
682 mlx5e_rep_indr_block_priv_lookup(struct mlx5e_rep_priv
*rpriv
,
683 struct net_device
*netdev
)
685 struct mlx5e_rep_indr_block_priv
*cb_priv
;
687 /* All callback list access should be protected by RTNL. */
690 list_for_each_entry(cb_priv
,
691 &rpriv
->uplink_priv
.tc_indr_block_priv_list
,
693 if (cb_priv
->netdev
== netdev
)
699 static void mlx5e_rep_indr_clean_block_privs(struct mlx5e_rep_priv
*rpriv
)
701 struct mlx5e_rep_indr_block_priv
*cb_priv
, *temp
;
702 struct list_head
*head
= &rpriv
->uplink_priv
.tc_indr_block_priv_list
;
704 list_for_each_entry_safe(cb_priv
, temp
, head
, list
) {
705 mlx5e_rep_indr_unregister_block(rpriv
, cb_priv
->netdev
);
711 mlx5e_rep_indr_offload(struct net_device
*netdev
,
712 struct flow_cls_offload
*flower
,
713 struct mlx5e_rep_indr_block_priv
*indr_priv
)
715 unsigned long flags
= MLX5_TC_FLAG(EGRESS
) | MLX5_TC_FLAG(ESW_OFFLOAD
);
716 struct mlx5e_priv
*priv
= netdev_priv(indr_priv
->rpriv
->netdev
);
719 switch (flower
->command
) {
720 case FLOW_CLS_REPLACE
:
721 err
= mlx5e_configure_flower(netdev
, priv
, flower
, flags
);
723 case FLOW_CLS_DESTROY
:
724 err
= mlx5e_delete_flower(netdev
, priv
, flower
, flags
);
727 err
= mlx5e_stats_flower(netdev
, priv
, flower
, flags
);
736 static int mlx5e_rep_indr_setup_block_cb(enum tc_setup_type type
,
737 void *type_data
, void *indr_priv
)
739 struct mlx5e_rep_indr_block_priv
*priv
= indr_priv
;
742 case TC_SETUP_CLSFLOWER
:
743 return mlx5e_rep_indr_offload(priv
->netdev
, type_data
, priv
);
749 static void mlx5e_rep_indr_tc_block_unbind(void *cb_priv
)
751 struct mlx5e_rep_indr_block_priv
*indr_priv
= cb_priv
;
753 list_del(&indr_priv
->list
);
757 static LIST_HEAD(mlx5e_block_cb_list
);
760 mlx5e_rep_indr_setup_tc_block(struct net_device
*netdev
,
761 struct mlx5e_rep_priv
*rpriv
,
762 struct flow_block_offload
*f
)
764 struct mlx5e_rep_indr_block_priv
*indr_priv
;
765 struct flow_block_cb
*block_cb
;
767 if (f
->binder_type
!= FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS
)
770 f
->unlocked_driver_cb
= true;
771 f
->driver_block_list
= &mlx5e_block_cb_list
;
773 switch (f
->command
) {
774 case FLOW_BLOCK_BIND
:
775 indr_priv
= mlx5e_rep_indr_block_priv_lookup(rpriv
, netdev
);
779 indr_priv
= kmalloc(sizeof(*indr_priv
), GFP_KERNEL
);
783 indr_priv
->netdev
= netdev
;
784 indr_priv
->rpriv
= rpriv
;
785 list_add(&indr_priv
->list
,
786 &rpriv
->uplink_priv
.tc_indr_block_priv_list
);
788 block_cb
= flow_block_cb_alloc(mlx5e_rep_indr_setup_block_cb
,
789 indr_priv
, indr_priv
,
790 mlx5e_rep_indr_tc_block_unbind
);
791 if (IS_ERR(block_cb
)) {
792 list_del(&indr_priv
->list
);
794 return PTR_ERR(block_cb
);
796 flow_block_cb_add(block_cb
, f
);
797 list_add_tail(&block_cb
->driver_list
, &mlx5e_block_cb_list
);
800 case FLOW_BLOCK_UNBIND
:
801 indr_priv
= mlx5e_rep_indr_block_priv_lookup(rpriv
, netdev
);
805 block_cb
= flow_block_cb_lookup(f
->block
,
806 mlx5e_rep_indr_setup_block_cb
,
811 flow_block_cb_remove(block_cb
, f
);
812 list_del(&block_cb
->driver_list
);
821 int mlx5e_rep_indr_setup_tc_cb(struct net_device
*netdev
, void *cb_priv
,
822 enum tc_setup_type type
, void *type_data
)
826 return mlx5e_rep_indr_setup_tc_block(netdev
, cb_priv
,
833 static int mlx5e_rep_indr_register_block(struct mlx5e_rep_priv
*rpriv
,
834 struct net_device
*netdev
)
838 err
= __flow_indr_block_cb_register(netdev
, rpriv
,
839 mlx5e_rep_indr_setup_tc_cb
,
842 struct mlx5e_priv
*priv
= netdev_priv(rpriv
->netdev
);
844 mlx5_core_err(priv
->mdev
, "Failed to register remote block notifier for %s err=%d\n",
845 netdev_name(netdev
), err
);
850 static void mlx5e_rep_indr_unregister_block(struct mlx5e_rep_priv
*rpriv
,
851 struct net_device
*netdev
)
853 __flow_indr_block_cb_unregister(netdev
, mlx5e_rep_indr_setup_tc_cb
,
857 static int mlx5e_nic_rep_netdevice_event(struct notifier_block
*nb
,
858 unsigned long event
, void *ptr
)
860 struct mlx5e_rep_priv
*rpriv
= container_of(nb
, struct mlx5e_rep_priv
,
861 uplink_priv
.netdevice_nb
);
862 struct mlx5e_priv
*priv
= netdev_priv(rpriv
->netdev
);
863 struct net_device
*netdev
= netdev_notifier_info_to_dev(ptr
);
865 if (!mlx5e_tc_tun_device_to_offload(priv
, netdev
) &&
866 !(is_vlan_dev(netdev
) && vlan_dev_real_dev(netdev
) == rpriv
->netdev
))
870 case NETDEV_REGISTER
:
871 mlx5e_rep_indr_register_block(rpriv
, netdev
);
873 case NETDEV_UNREGISTER
:
874 mlx5e_rep_indr_unregister_block(rpriv
, netdev
);
881 mlx5e_rep_queue_neigh_update_work(struct mlx5e_priv
*priv
,
882 struct mlx5e_neigh_hash_entry
*nhe
,
885 /* Take a reference to ensure the neighbour and mlx5 encap
886 * entry won't be destructed until we drop the reference in
891 /* This assignment is valid as long as the the neigh reference
896 if (!queue_work(priv
->wq
, &nhe
->neigh_update_work
)) {
897 mlx5e_rep_neigh_entry_release(nhe
);
902 static struct mlx5e_neigh_hash_entry
*
903 mlx5e_rep_neigh_entry_lookup(struct mlx5e_priv
*priv
,
904 struct mlx5e_neigh
*m_neigh
);
906 static int mlx5e_rep_netevent_event(struct notifier_block
*nb
,
907 unsigned long event
, void *ptr
)
909 struct mlx5e_rep_priv
*rpriv
= container_of(nb
, struct mlx5e_rep_priv
,
910 neigh_update
.netevent_nb
);
911 struct mlx5e_neigh_update_table
*neigh_update
= &rpriv
->neigh_update
;
912 struct net_device
*netdev
= rpriv
->netdev
;
913 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
914 struct mlx5e_neigh_hash_entry
*nhe
= NULL
;
915 struct mlx5e_neigh m_neigh
= {};
916 struct neigh_parms
*p
;
921 case NETEVENT_NEIGH_UPDATE
:
923 #if IS_ENABLED(CONFIG_IPV6)
924 if (n
->tbl
!= ipv6_stub
->nd_tbl
&& n
->tbl
!= &arp_tbl
)
926 if (n
->tbl
!= &arp_tbl
)
930 m_neigh
.dev
= n
->dev
;
931 m_neigh
.family
= n
->ops
->family
;
932 memcpy(&m_neigh
.dst_ip
, n
->primary_key
, n
->tbl
->key_len
);
935 nhe
= mlx5e_rep_neigh_entry_lookup(priv
, &m_neigh
);
940 mlx5e_rep_queue_neigh_update_work(priv
, nhe
, n
);
943 case NETEVENT_DELAY_PROBE_TIME_UPDATE
:
946 /* We check the device is present since we don't care about
947 * changes in the default table, we only care about changes
948 * done per device delay prob time parameter.
950 #if IS_ENABLED(CONFIG_IPV6)
951 if (!p
->dev
|| (p
->tbl
!= ipv6_stub
->nd_tbl
&& p
->tbl
!= &arp_tbl
))
953 if (!p
->dev
|| p
->tbl
!= &arp_tbl
)
958 list_for_each_entry_rcu(nhe
, &neigh_update
->neigh_list
,
960 if (p
->dev
== nhe
->m_neigh
.dev
) {
969 neigh_update
->min_interval
= min_t(unsigned long,
970 NEIGH_VAR(p
, DELAY_PROBE_TIME
),
971 neigh_update
->min_interval
);
972 mlx5_fc_update_sampling_interval(priv
->mdev
,
973 neigh_update
->min_interval
);
979 static const struct rhashtable_params mlx5e_neigh_ht_params
= {
980 .head_offset
= offsetof(struct mlx5e_neigh_hash_entry
, rhash_node
),
981 .key_offset
= offsetof(struct mlx5e_neigh_hash_entry
, m_neigh
),
982 .key_len
= sizeof(struct mlx5e_neigh
),
983 .automatic_shrinking
= true,
986 static int mlx5e_rep_neigh_init(struct mlx5e_rep_priv
*rpriv
)
988 struct mlx5e_neigh_update_table
*neigh_update
= &rpriv
->neigh_update
;
991 err
= rhashtable_init(&neigh_update
->neigh_ht
, &mlx5e_neigh_ht_params
);
995 INIT_LIST_HEAD(&neigh_update
->neigh_list
);
996 mutex_init(&neigh_update
->encap_lock
);
997 INIT_DELAYED_WORK(&neigh_update
->neigh_stats_work
,
998 mlx5e_rep_neigh_stats_work
);
999 mlx5e_rep_neigh_update_init_interval(rpriv
);
1001 rpriv
->neigh_update
.netevent_nb
.notifier_call
= mlx5e_rep_netevent_event
;
1002 err
= register_netevent_notifier(&rpriv
->neigh_update
.netevent_nb
);
1008 rhashtable_destroy(&neigh_update
->neigh_ht
);
1012 static void mlx5e_rep_neigh_cleanup(struct mlx5e_rep_priv
*rpriv
)
1014 struct mlx5e_neigh_update_table
*neigh_update
= &rpriv
->neigh_update
;
1015 struct mlx5e_priv
*priv
= netdev_priv(rpriv
->netdev
);
1017 unregister_netevent_notifier(&neigh_update
->netevent_nb
);
1019 flush_workqueue(priv
->wq
); /* flush neigh update works */
1021 cancel_delayed_work_sync(&rpriv
->neigh_update
.neigh_stats_work
);
1023 mutex_destroy(&neigh_update
->encap_lock
);
1024 rhashtable_destroy(&neigh_update
->neigh_ht
);
1027 static int mlx5e_rep_neigh_entry_insert(struct mlx5e_priv
*priv
,
1028 struct mlx5e_neigh_hash_entry
*nhe
)
1030 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1033 err
= rhashtable_insert_fast(&rpriv
->neigh_update
.neigh_ht
,
1035 mlx5e_neigh_ht_params
);
1039 list_add_rcu(&nhe
->neigh_list
, &rpriv
->neigh_update
.neigh_list
);
1044 static void mlx5e_rep_neigh_entry_remove(struct mlx5e_neigh_hash_entry
*nhe
)
1046 struct mlx5e_rep_priv
*rpriv
= nhe
->priv
->ppriv
;
1048 mutex_lock(&rpriv
->neigh_update
.encap_lock
);
1050 list_del_rcu(&nhe
->neigh_list
);
1052 rhashtable_remove_fast(&rpriv
->neigh_update
.neigh_ht
,
1054 mlx5e_neigh_ht_params
);
1055 mutex_unlock(&rpriv
->neigh_update
.encap_lock
);
1058 /* This function must only be called under the representor's encap_lock or
1059 * inside rcu read lock section.
1061 static struct mlx5e_neigh_hash_entry
*
1062 mlx5e_rep_neigh_entry_lookup(struct mlx5e_priv
*priv
,
1063 struct mlx5e_neigh
*m_neigh
)
1065 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1066 struct mlx5e_neigh_update_table
*neigh_update
= &rpriv
->neigh_update
;
1067 struct mlx5e_neigh_hash_entry
*nhe
;
1069 nhe
= rhashtable_lookup_fast(&neigh_update
->neigh_ht
, m_neigh
,
1070 mlx5e_neigh_ht_params
);
1071 return nhe
&& mlx5e_rep_neigh_entry_hold(nhe
) ? nhe
: NULL
;
1074 static int mlx5e_rep_neigh_entry_create(struct mlx5e_priv
*priv
,
1075 struct mlx5e_encap_entry
*e
,
1076 struct mlx5e_neigh_hash_entry
**nhe
)
1080 *nhe
= kzalloc(sizeof(**nhe
), GFP_KERNEL
);
1084 (*nhe
)->priv
= priv
;
1085 memcpy(&(*nhe
)->m_neigh
, &e
->m_neigh
, sizeof(e
->m_neigh
));
1086 INIT_WORK(&(*nhe
)->neigh_update_work
, mlx5e_rep_neigh_update
);
1087 spin_lock_init(&(*nhe
)->encap_list_lock
);
1088 INIT_LIST_HEAD(&(*nhe
)->encap_list
);
1089 refcount_set(&(*nhe
)->refcnt
, 1);
1091 err
= mlx5e_rep_neigh_entry_insert(priv
, *nhe
);
1101 int mlx5e_rep_encap_entry_attach(struct mlx5e_priv
*priv
,
1102 struct mlx5e_encap_entry
*e
)
1104 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1105 struct mlx5_rep_uplink_priv
*uplink_priv
= &rpriv
->uplink_priv
;
1106 struct mlx5_tun_entropy
*tun_entropy
= &uplink_priv
->tun_entropy
;
1107 struct mlx5e_neigh_hash_entry
*nhe
;
1110 err
= mlx5_tun_entropy_refcount_inc(tun_entropy
, e
->reformat_type
);
1114 mutex_lock(&rpriv
->neigh_update
.encap_lock
);
1115 nhe
= mlx5e_rep_neigh_entry_lookup(priv
, &e
->m_neigh
);
1117 err
= mlx5e_rep_neigh_entry_create(priv
, e
, &nhe
);
1119 mutex_unlock(&rpriv
->neigh_update
.encap_lock
);
1120 mlx5_tun_entropy_refcount_dec(tun_entropy
,
1127 spin_lock(&nhe
->encap_list_lock
);
1128 list_add_rcu(&e
->encap_list
, &nhe
->encap_list
);
1129 spin_unlock(&nhe
->encap_list_lock
);
1131 mutex_unlock(&rpriv
->neigh_update
.encap_lock
);
1136 void mlx5e_rep_encap_entry_detach(struct mlx5e_priv
*priv
,
1137 struct mlx5e_encap_entry
*e
)
1139 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1140 struct mlx5_rep_uplink_priv
*uplink_priv
= &rpriv
->uplink_priv
;
1141 struct mlx5_tun_entropy
*tun_entropy
= &uplink_priv
->tun_entropy
;
1146 spin_lock(&e
->nhe
->encap_list_lock
);
1147 list_del_rcu(&e
->encap_list
);
1148 spin_unlock(&e
->nhe
->encap_list_lock
);
1150 mlx5e_rep_neigh_entry_release(e
->nhe
);
1152 mlx5_tun_entropy_refcount_dec(tun_entropy
, e
->reformat_type
);
1155 static int mlx5e_rep_open(struct net_device
*dev
)
1157 struct mlx5e_priv
*priv
= netdev_priv(dev
);
1158 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1159 struct mlx5_eswitch_rep
*rep
= rpriv
->rep
;
1162 mutex_lock(&priv
->state_lock
);
1163 err
= mlx5e_open_locked(dev
);
1167 if (!mlx5_modify_vport_admin_state(priv
->mdev
,
1168 MLX5_VPORT_STATE_OP_MOD_ESW_VPORT
,
1170 MLX5_VPORT_ADMIN_STATE_UP
))
1171 netif_carrier_on(dev
);
1174 mutex_unlock(&priv
->state_lock
);
1178 static int mlx5e_rep_close(struct net_device
*dev
)
1180 struct mlx5e_priv
*priv
= netdev_priv(dev
);
1181 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1182 struct mlx5_eswitch_rep
*rep
= rpriv
->rep
;
1185 mutex_lock(&priv
->state_lock
);
1186 mlx5_modify_vport_admin_state(priv
->mdev
,
1187 MLX5_VPORT_STATE_OP_MOD_ESW_VPORT
,
1189 MLX5_VPORT_ADMIN_STATE_DOWN
);
1190 ret
= mlx5e_close_locked(dev
);
1191 mutex_unlock(&priv
->state_lock
);
1196 mlx5e_rep_setup_tc_cls_flower(struct mlx5e_priv
*priv
,
1197 struct flow_cls_offload
*cls_flower
, int flags
)
1199 switch (cls_flower
->command
) {
1200 case FLOW_CLS_REPLACE
:
1201 return mlx5e_configure_flower(priv
->netdev
, priv
, cls_flower
,
1203 case FLOW_CLS_DESTROY
:
1204 return mlx5e_delete_flower(priv
->netdev
, priv
, cls_flower
,
1206 case FLOW_CLS_STATS
:
1207 return mlx5e_stats_flower(priv
->netdev
, priv
, cls_flower
,
1215 int mlx5e_rep_setup_tc_cls_matchall(struct mlx5e_priv
*priv
,
1216 struct tc_cls_matchall_offload
*ma
)
1218 switch (ma
->command
) {
1219 case TC_CLSMATCHALL_REPLACE
:
1220 return mlx5e_tc_configure_matchall(priv
, ma
);
1221 case TC_CLSMATCHALL_DESTROY
:
1222 return mlx5e_tc_delete_matchall(priv
, ma
);
1223 case TC_CLSMATCHALL_STATS
:
1224 mlx5e_tc_stats_matchall(priv
, ma
);
1231 static int mlx5e_rep_setup_tc_cb(enum tc_setup_type type
, void *type_data
,
1234 unsigned long flags
= MLX5_TC_FLAG(INGRESS
) | MLX5_TC_FLAG(ESW_OFFLOAD
);
1235 struct mlx5e_priv
*priv
= cb_priv
;
1238 case TC_SETUP_CLSFLOWER
:
1239 return mlx5e_rep_setup_tc_cls_flower(priv
, type_data
, flags
);
1240 case TC_SETUP_CLSMATCHALL
:
1241 return mlx5e_rep_setup_tc_cls_matchall(priv
, type_data
);
1247 static int mlx5e_rep_setup_ft_cb(enum tc_setup_type type
, void *type_data
,
1250 struct flow_cls_offload
*f
= type_data
;
1251 struct flow_cls_offload cls_flower
;
1252 struct mlx5e_priv
*priv
= cb_priv
;
1253 struct mlx5_eswitch
*esw
;
1254 unsigned long flags
;
1257 flags
= MLX5_TC_FLAG(INGRESS
) |
1258 MLX5_TC_FLAG(ESW_OFFLOAD
) |
1259 MLX5_TC_FLAG(FT_OFFLOAD
);
1260 esw
= priv
->mdev
->priv
.eswitch
;
1263 case TC_SETUP_CLSFLOWER
:
1264 if (!mlx5_eswitch_prios_supported(esw
) || f
->common
.chain_index
)
1267 /* Re-use tc offload path by moving the ft flow to the
1268 * reserved ft chain.
1270 memcpy(&cls_flower
, f
, sizeof(*f
));
1271 cls_flower
.common
.chain_index
= FDB_FT_CHAIN
;
1272 err
= mlx5e_rep_setup_tc_cls_flower(priv
, &cls_flower
, flags
);
1273 memcpy(&f
->stats
, &cls_flower
.stats
, sizeof(f
->stats
));
1280 static LIST_HEAD(mlx5e_rep_block_tc_cb_list
);
1281 static LIST_HEAD(mlx5e_rep_block_ft_cb_list
);
1282 static int mlx5e_rep_setup_tc(struct net_device
*dev
, enum tc_setup_type type
,
1285 struct mlx5e_priv
*priv
= netdev_priv(dev
);
1286 struct flow_block_offload
*f
= type_data
;
1288 f
->unlocked_driver_cb
= true;
1291 case TC_SETUP_BLOCK
:
1292 return flow_block_cb_setup_simple(type_data
,
1293 &mlx5e_rep_block_tc_cb_list
,
1294 mlx5e_rep_setup_tc_cb
,
1297 return flow_block_cb_setup_simple(type_data
,
1298 &mlx5e_rep_block_ft_cb_list
,
1299 mlx5e_rep_setup_ft_cb
,
1306 bool mlx5e_is_uplink_rep(struct mlx5e_priv
*priv
)
1308 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1309 struct mlx5_eswitch_rep
*rep
;
1311 if (!MLX5_ESWITCH_MANAGER(priv
->mdev
))
1314 if (!rpriv
) /* non vport rep mlx5e instances don't use this field */
1318 return (rep
->vport
== MLX5_VPORT_UPLINK
);
1321 static bool mlx5e_rep_has_offload_stats(const struct net_device
*dev
, int attr_id
)
1324 case IFLA_OFFLOAD_XSTATS_CPU_HIT
:
1332 mlx5e_get_sw_stats64(const struct net_device
*dev
,
1333 struct rtnl_link_stats64
*stats
)
1335 struct mlx5e_priv
*priv
= netdev_priv(dev
);
1337 mlx5e_fold_sw_stats64(priv
, stats
);
1341 static int mlx5e_rep_get_offload_stats(int attr_id
, const struct net_device
*dev
,
1345 case IFLA_OFFLOAD_XSTATS_CPU_HIT
:
1346 return mlx5e_get_sw_stats64(dev
, sp
);
1353 mlx5e_rep_get_stats(struct net_device
*dev
, struct rtnl_link_stats64
*stats
)
1355 struct mlx5e_priv
*priv
= netdev_priv(dev
);
1357 /* update HW stats in background for next time */
1358 mlx5e_queue_update_stats(priv
);
1359 memcpy(stats
, &priv
->stats
.vf_vport
, sizeof(*stats
));
1362 static int mlx5e_rep_change_mtu(struct net_device
*netdev
, int new_mtu
)
1364 return mlx5e_change_mtu(netdev
, new_mtu
, NULL
);
1367 static int mlx5e_uplink_rep_change_mtu(struct net_device
*netdev
, int new_mtu
)
1369 return mlx5e_change_mtu(netdev
, new_mtu
, mlx5e_set_dev_port_mtu
);
1372 static int mlx5e_uplink_rep_set_mac(struct net_device
*netdev
, void *addr
)
1374 struct sockaddr
*saddr
= addr
;
1376 if (!is_valid_ether_addr(saddr
->sa_data
))
1377 return -EADDRNOTAVAIL
;
1379 ether_addr_copy(netdev
->dev_addr
, saddr
->sa_data
);
1383 static int mlx5e_uplink_rep_set_vf_vlan(struct net_device
*dev
, int vf
, u16 vlan
, u8 qos
,
1386 netdev_warn_once(dev
, "legacy vf vlan setting isn't supported in switchdev mode\n");
1391 /* allow setting 0-vid for compatibility with libvirt */
1395 static struct devlink_port
*mlx5e_get_devlink_port(struct net_device
*dev
)
1397 struct mlx5e_priv
*priv
= netdev_priv(dev
);
1398 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1400 return &rpriv
->dl_port
;
1403 static const struct net_device_ops mlx5e_netdev_ops_rep
= {
1404 .ndo_open
= mlx5e_rep_open
,
1405 .ndo_stop
= mlx5e_rep_close
,
1406 .ndo_start_xmit
= mlx5e_xmit
,
1407 .ndo_setup_tc
= mlx5e_rep_setup_tc
,
1408 .ndo_get_devlink_port
= mlx5e_get_devlink_port
,
1409 .ndo_get_stats64
= mlx5e_rep_get_stats
,
1410 .ndo_has_offload_stats
= mlx5e_rep_has_offload_stats
,
1411 .ndo_get_offload_stats
= mlx5e_rep_get_offload_stats
,
1412 .ndo_change_mtu
= mlx5e_rep_change_mtu
,
1415 static const struct net_device_ops mlx5e_netdev_ops_uplink_rep
= {
1416 .ndo_open
= mlx5e_open
,
1417 .ndo_stop
= mlx5e_close
,
1418 .ndo_start_xmit
= mlx5e_xmit
,
1419 .ndo_set_mac_address
= mlx5e_uplink_rep_set_mac
,
1420 .ndo_setup_tc
= mlx5e_rep_setup_tc
,
1421 .ndo_get_devlink_port
= mlx5e_get_devlink_port
,
1422 .ndo_get_stats64
= mlx5e_get_stats
,
1423 .ndo_has_offload_stats
= mlx5e_rep_has_offload_stats
,
1424 .ndo_get_offload_stats
= mlx5e_rep_get_offload_stats
,
1425 .ndo_change_mtu
= mlx5e_uplink_rep_change_mtu
,
1426 .ndo_udp_tunnel_add
= mlx5e_add_vxlan_port
,
1427 .ndo_udp_tunnel_del
= mlx5e_del_vxlan_port
,
1428 .ndo_features_check
= mlx5e_features_check
,
1429 .ndo_set_vf_mac
= mlx5e_set_vf_mac
,
1430 .ndo_set_vf_rate
= mlx5e_set_vf_rate
,
1431 .ndo_get_vf_config
= mlx5e_get_vf_config
,
1432 .ndo_get_vf_stats
= mlx5e_get_vf_stats
,
1433 .ndo_set_vf_vlan
= mlx5e_uplink_rep_set_vf_vlan
,
1434 .ndo_set_features
= mlx5e_set_features
,
1437 bool mlx5e_eswitch_rep(struct net_device
*netdev
)
1439 if (netdev
->netdev_ops
== &mlx5e_netdev_ops_rep
||
1440 netdev
->netdev_ops
== &mlx5e_netdev_ops_uplink_rep
)
1446 static void mlx5e_build_rep_params(struct net_device
*netdev
)
1448 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
1449 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1450 struct mlx5_eswitch_rep
*rep
= rpriv
->rep
;
1451 struct mlx5_core_dev
*mdev
= priv
->mdev
;
1452 struct mlx5e_params
*params
;
1454 u8 cq_period_mode
= MLX5_CAP_GEN(mdev
, cq_period_start_from_cqe
) ?
1455 MLX5_CQ_PERIOD_MODE_START_FROM_CQE
:
1456 MLX5_CQ_PERIOD_MODE_START_FROM_EQE
;
1458 params
= &priv
->channels
.params
;
1459 params
->hard_mtu
= MLX5E_ETH_HARD_MTU
;
1460 params
->sw_mtu
= netdev
->mtu
;
1463 if (rep
->vport
== MLX5_VPORT_UPLINK
)
1464 params
->log_sq_size
= MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE
;
1466 params
->log_sq_size
= MLX5E_REP_PARAMS_DEF_LOG_SQ_SIZE
;
1469 mlx5e_build_rq_params(mdev
, params
);
1471 /* CQ moderation params */
1472 params
->rx_dim_enabled
= MLX5_CAP_GEN(mdev
, cq_moderation
);
1473 mlx5e_set_rx_cq_mode_params(params
, cq_period_mode
);
1476 params
->tunneled_offload_en
= false;
1478 mlx5_query_min_inline(mdev
, ¶ms
->tx_min_inline_mode
);
1481 mlx5e_build_rss_params(&priv
->rss_params
, params
->num_channels
);
1484 static void mlx5e_build_rep_netdev(struct net_device
*netdev
)
1486 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
1487 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1488 struct mlx5_eswitch_rep
*rep
= rpriv
->rep
;
1489 struct mlx5_core_dev
*mdev
= priv
->mdev
;
1491 if (rep
->vport
== MLX5_VPORT_UPLINK
) {
1492 SET_NETDEV_DEV(netdev
, mdev
->device
);
1493 netdev
->netdev_ops
= &mlx5e_netdev_ops_uplink_rep
;
1494 /* we want a persistent mac for the uplink rep */
1495 mlx5_query_mac_address(mdev
, netdev
->dev_addr
);
1496 netdev
->ethtool_ops
= &mlx5e_uplink_rep_ethtool_ops
;
1497 #ifdef CONFIG_MLX5_CORE_EN_DCB
1498 if (MLX5_CAP_GEN(mdev
, qos
))
1499 netdev
->dcbnl_ops
= &mlx5e_dcbnl_ops
;
1502 netdev
->netdev_ops
= &mlx5e_netdev_ops_rep
;
1503 eth_hw_addr_random(netdev
);
1504 netdev
->ethtool_ops
= &mlx5e_rep_ethtool_ops
;
1507 netdev
->watchdog_timeo
= 15 * HZ
;
1509 netdev
->features
|= NETIF_F_NETNS_LOCAL
;
1511 netdev
->hw_features
|= NETIF_F_HW_TC
;
1512 netdev
->hw_features
|= NETIF_F_SG
;
1513 netdev
->hw_features
|= NETIF_F_IP_CSUM
;
1514 netdev
->hw_features
|= NETIF_F_IPV6_CSUM
;
1515 netdev
->hw_features
|= NETIF_F_GRO
;
1516 netdev
->hw_features
|= NETIF_F_TSO
;
1517 netdev
->hw_features
|= NETIF_F_TSO6
;
1518 netdev
->hw_features
|= NETIF_F_RXCSUM
;
1520 if (rep
->vport
== MLX5_VPORT_UPLINK
)
1521 netdev
->hw_features
|= NETIF_F_HW_VLAN_CTAG_RX
;
1523 netdev
->features
|= NETIF_F_VLAN_CHALLENGED
;
1525 netdev
->features
|= netdev
->hw_features
;
1528 static int mlx5e_init_rep(struct mlx5_core_dev
*mdev
,
1529 struct net_device
*netdev
,
1530 const struct mlx5e_profile
*profile
,
1533 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
1536 err
= mlx5e_netdev_init(netdev
, priv
, mdev
, profile
, ppriv
);
1540 priv
->channels
.params
.num_channels
= MLX5E_REP_PARAMS_DEF_NUM_CHANNELS
;
1542 mlx5e_build_rep_params(netdev
);
1543 mlx5e_build_rep_netdev(netdev
);
1545 mlx5e_timestamp_init(priv
);
1550 static void mlx5e_cleanup_rep(struct mlx5e_priv
*priv
)
1552 mlx5e_netdev_cleanup(priv
->netdev
, priv
);
1555 static int mlx5e_create_rep_ttc_table(struct mlx5e_priv
*priv
)
1557 struct ttc_params ttc_params
= {};
1560 priv
->fs
.ns
= mlx5_get_flow_namespace(priv
->mdev
,
1561 MLX5_FLOW_NAMESPACE_KERNEL
);
1563 /* The inner_ttc in the ttc params is intentionally not set */
1564 ttc_params
.any_tt_tirn
= priv
->direct_tir
[0].tirn
;
1565 mlx5e_set_ttc_ft_params(&ttc_params
);
1566 for (tt
= 0; tt
< MLX5E_NUM_INDIR_TIRS
; tt
++)
1567 ttc_params
.indir_tirn
[tt
] = priv
->indir_tir
[tt
].tirn
;
1569 err
= mlx5e_create_ttc_table(priv
, &ttc_params
, &priv
->fs
.ttc
);
1571 netdev_err(priv
->netdev
, "Failed to create rep ttc table, err=%d\n", err
);
1577 static int mlx5e_create_rep_vport_rx_rule(struct mlx5e_priv
*priv
)
1579 struct mlx5_eswitch
*esw
= priv
->mdev
->priv
.eswitch
;
1580 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1581 struct mlx5_eswitch_rep
*rep
= rpriv
->rep
;
1582 struct mlx5_flow_handle
*flow_rule
;
1583 struct mlx5_flow_destination dest
;
1585 dest
.type
= MLX5_FLOW_DESTINATION_TYPE_TIR
;
1586 dest
.tir_num
= priv
->direct_tir
[0].tirn
;
1587 flow_rule
= mlx5_eswitch_create_vport_rx_rule(esw
,
1590 if (IS_ERR(flow_rule
))
1591 return PTR_ERR(flow_rule
);
1592 rpriv
->vport_rx_rule
= flow_rule
;
1596 static int mlx5e_init_rep_rx(struct mlx5e_priv
*priv
)
1598 struct mlx5_core_dev
*mdev
= priv
->mdev
;
1601 mlx5e_init_l2_addr(priv
);
1603 err
= mlx5e_open_drop_rq(priv
, &priv
->drop_rq
);
1605 mlx5_core_err(mdev
, "open drop rq failed, %d\n", err
);
1609 err
= mlx5e_create_indirect_rqt(priv
);
1611 goto err_close_drop_rq
;
1613 err
= mlx5e_create_direct_rqts(priv
, priv
->direct_tir
);
1615 goto err_destroy_indirect_rqts
;
1617 err
= mlx5e_create_indirect_tirs(priv
, false);
1619 goto err_destroy_direct_rqts
;
1621 err
= mlx5e_create_direct_tirs(priv
, priv
->direct_tir
);
1623 goto err_destroy_indirect_tirs
;
1625 err
= mlx5e_create_rep_ttc_table(priv
);
1627 goto err_destroy_direct_tirs
;
1629 err
= mlx5e_create_rep_vport_rx_rule(priv
);
1631 goto err_destroy_ttc_table
;
1635 err_destroy_ttc_table
:
1636 mlx5e_destroy_ttc_table(priv
, &priv
->fs
.ttc
);
1637 err_destroy_direct_tirs
:
1638 mlx5e_destroy_direct_tirs(priv
, priv
->direct_tir
);
1639 err_destroy_indirect_tirs
:
1640 mlx5e_destroy_indirect_tirs(priv
, false);
1641 err_destroy_direct_rqts
:
1642 mlx5e_destroy_direct_rqts(priv
, priv
->direct_tir
);
1643 err_destroy_indirect_rqts
:
1644 mlx5e_destroy_rqt(priv
, &priv
->indir_rqt
);
1646 mlx5e_close_drop_rq(&priv
->drop_rq
);
1650 static void mlx5e_cleanup_rep_rx(struct mlx5e_priv
*priv
)
1652 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1654 mlx5_del_flow_rules(rpriv
->vport_rx_rule
);
1655 mlx5e_destroy_ttc_table(priv
, &priv
->fs
.ttc
);
1656 mlx5e_destroy_direct_tirs(priv
, priv
->direct_tir
);
1657 mlx5e_destroy_indirect_tirs(priv
, false);
1658 mlx5e_destroy_direct_rqts(priv
, priv
->direct_tir
);
1659 mlx5e_destroy_rqt(priv
, &priv
->indir_rqt
);
1660 mlx5e_close_drop_rq(&priv
->drop_rq
);
1663 static int mlx5e_init_rep_tx(struct mlx5e_priv
*priv
)
1665 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1666 struct mlx5_rep_uplink_priv
*uplink_priv
;
1669 err
= mlx5e_create_tises(priv
);
1671 mlx5_core_warn(priv
->mdev
, "create tises failed, %d\n", err
);
1675 if (rpriv
->rep
->vport
== MLX5_VPORT_UPLINK
) {
1676 uplink_priv
= &rpriv
->uplink_priv
;
1678 mutex_init(&uplink_priv
->unready_flows_lock
);
1679 INIT_LIST_HEAD(&uplink_priv
->unready_flows
);
1681 /* init shared tc flow table */
1682 err
= mlx5e_tc_esw_init(&uplink_priv
->tc_ht
);
1686 mlx5_init_port_tun_entropy(&uplink_priv
->tun_entropy
, priv
->mdev
);
1688 /* init indirect block notifications */
1689 INIT_LIST_HEAD(&uplink_priv
->tc_indr_block_priv_list
);
1690 uplink_priv
->netdevice_nb
.notifier_call
= mlx5e_nic_rep_netdevice_event
;
1691 err
= register_netdevice_notifier(&uplink_priv
->netdevice_nb
);
1693 mlx5_core_err(priv
->mdev
, "Failed to register netdev notifier\n");
1694 goto tc_esw_cleanup
;
1701 mlx5e_tc_esw_cleanup(&uplink_priv
->tc_ht
);
1703 mlx5e_destroy_tises(priv
);
1707 static void mlx5e_cleanup_rep_tx(struct mlx5e_priv
*priv
)
1709 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1711 mlx5e_destroy_tises(priv
);
1713 if (rpriv
->rep
->vport
== MLX5_VPORT_UPLINK
) {
1714 /* clean indirect TC block notifications */
1715 unregister_netdevice_notifier(&rpriv
->uplink_priv
.netdevice_nb
);
1716 mlx5e_rep_indr_clean_block_privs(rpriv
);
1718 /* delete shared tc flow table */
1719 mlx5e_tc_esw_cleanup(&rpriv
->uplink_priv
.tc_ht
);
1720 mutex_destroy(&rpriv
->uplink_priv
.unready_flows_lock
);
1724 static void mlx5e_rep_enable(struct mlx5e_priv
*priv
)
1726 mlx5e_set_netdev_mtu_boundaries(priv
);
1729 static int mlx5e_update_rep_rx(struct mlx5e_priv
*priv
)
1734 static int uplink_rep_async_event(struct notifier_block
*nb
, unsigned long event
, void *data
)
1736 struct mlx5e_priv
*priv
= container_of(nb
, struct mlx5e_priv
, events_nb
);
1738 if (event
== MLX5_EVENT_TYPE_PORT_CHANGE
) {
1739 struct mlx5_eqe
*eqe
= data
;
1741 switch (eqe
->sub_type
) {
1742 case MLX5_PORT_CHANGE_SUBTYPE_DOWN
:
1743 case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE
:
1744 queue_work(priv
->wq
, &priv
->update_carrier_work
);
1753 if (event
== MLX5_DEV_EVENT_PORT_AFFINITY
) {
1754 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1756 queue_work(priv
->wq
, &rpriv
->uplink_priv
.reoffload_flows_work
);
1764 static void mlx5e_uplink_rep_enable(struct mlx5e_priv
*priv
)
1766 struct net_device
*netdev
= priv
->netdev
;
1767 struct mlx5_core_dev
*mdev
= priv
->mdev
;
1768 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1771 netdev
->min_mtu
= ETH_MIN_MTU
;
1772 mlx5_query_port_max_mtu(priv
->mdev
, &max_mtu
, 1);
1773 netdev
->max_mtu
= MLX5E_HW2SW_MTU(&priv
->channels
.params
, max_mtu
);
1774 mlx5e_set_dev_port_mtu(priv
);
1776 INIT_WORK(&rpriv
->uplink_priv
.reoffload_flows_work
,
1777 mlx5e_tc_reoffload_flows_work
);
1779 mlx5_lag_add(mdev
, netdev
);
1780 priv
->events_nb
.notifier_call
= uplink_rep_async_event
;
1781 mlx5_notifier_register(mdev
, &priv
->events_nb
);
1782 #ifdef CONFIG_MLX5_CORE_EN_DCB
1783 mlx5e_dcbnl_initialize(priv
);
1784 mlx5e_dcbnl_init_app(priv
);
1788 static void mlx5e_uplink_rep_disable(struct mlx5e_priv
*priv
)
1790 struct mlx5_core_dev
*mdev
= priv
->mdev
;
1791 struct mlx5e_rep_priv
*rpriv
= priv
->ppriv
;
1793 #ifdef CONFIG_MLX5_CORE_EN_DCB
1794 mlx5e_dcbnl_delete_app(priv
);
1796 mlx5_notifier_unregister(mdev
, &priv
->events_nb
);
1797 cancel_work_sync(&rpriv
->uplink_priv
.reoffload_flows_work
);
1798 mlx5_lag_remove(mdev
);
1801 static const struct mlx5e_profile mlx5e_rep_profile
= {
1802 .init
= mlx5e_init_rep
,
1803 .cleanup
= mlx5e_cleanup_rep
,
1804 .init_rx
= mlx5e_init_rep_rx
,
1805 .cleanup_rx
= mlx5e_cleanup_rep_rx
,
1806 .init_tx
= mlx5e_init_rep_tx
,
1807 .cleanup_tx
= mlx5e_cleanup_rep_tx
,
1808 .enable
= mlx5e_rep_enable
,
1809 .update_rx
= mlx5e_update_rep_rx
,
1810 .update_stats
= mlx5e_rep_update_hw_counters
,
1811 .rx_handlers
.handle_rx_cqe
= mlx5e_handle_rx_cqe_rep
,
1812 .rx_handlers
.handle_rx_cqe_mpwqe
= mlx5e_handle_rx_cqe_mpwrq
,
1814 .rq_groups
= MLX5E_NUM_RQ_GROUPS(REGULAR
),
1817 static const struct mlx5e_profile mlx5e_uplink_rep_profile
= {
1818 .init
= mlx5e_init_rep
,
1819 .cleanup
= mlx5e_cleanup_rep
,
1820 .init_rx
= mlx5e_init_rep_rx
,
1821 .cleanup_rx
= mlx5e_cleanup_rep_rx
,
1822 .init_tx
= mlx5e_init_rep_tx
,
1823 .cleanup_tx
= mlx5e_cleanup_rep_tx
,
1824 .enable
= mlx5e_uplink_rep_enable
,
1825 .disable
= mlx5e_uplink_rep_disable
,
1826 .update_rx
= mlx5e_update_rep_rx
,
1827 .update_stats
= mlx5e_uplink_rep_update_hw_counters
,
1828 .update_carrier
= mlx5e_update_carrier
,
1829 .rx_handlers
.handle_rx_cqe
= mlx5e_handle_rx_cqe_rep
,
1830 .rx_handlers
.handle_rx_cqe_mpwqe
= mlx5e_handle_rx_cqe_mpwrq
,
1831 .max_tc
= MLX5E_MAX_NUM_TC
,
1832 .rq_groups
= MLX5E_NUM_RQ_GROUPS(REGULAR
),
1836 is_devlink_port_supported(const struct mlx5_core_dev
*dev
,
1837 const struct mlx5e_rep_priv
*rpriv
)
1839 return rpriv
->rep
->vport
== MLX5_VPORT_UPLINK
||
1840 rpriv
->rep
->vport
== MLX5_VPORT_PF
||
1841 mlx5_eswitch_is_vf_vport(dev
->priv
.eswitch
, rpriv
->rep
->vport
);
1845 vport_to_devlink_port_index(const struct mlx5_core_dev
*dev
, u16 vport_num
)
1847 return (MLX5_CAP_GEN(dev
, vhca_id
) << 16) | vport_num
;
1850 static int register_devlink_port(struct mlx5_core_dev
*dev
,
1851 struct mlx5e_rep_priv
*rpriv
)
1853 struct devlink
*devlink
= priv_to_devlink(dev
);
1854 struct mlx5_eswitch_rep
*rep
= rpriv
->rep
;
1855 struct netdev_phys_item_id ppid
= {};
1856 unsigned int dl_port_index
= 0;
1858 if (!is_devlink_port_supported(dev
, rpriv
))
1861 mlx5e_rep_get_port_parent_id(rpriv
->netdev
, &ppid
);
1863 if (rep
->vport
== MLX5_VPORT_UPLINK
) {
1864 devlink_port_attrs_set(&rpriv
->dl_port
,
1865 DEVLINK_PORT_FLAVOUR_PHYSICAL
,
1866 PCI_FUNC(dev
->pdev
->devfn
), false, 0,
1867 &ppid
.id
[0], ppid
.id_len
);
1868 dl_port_index
= vport_to_devlink_port_index(dev
, rep
->vport
);
1869 } else if (rep
->vport
== MLX5_VPORT_PF
) {
1870 devlink_port_attrs_pci_pf_set(&rpriv
->dl_port
,
1871 &ppid
.id
[0], ppid
.id_len
,
1873 dl_port_index
= rep
->vport
;
1874 } else if (mlx5_eswitch_is_vf_vport(dev
->priv
.eswitch
,
1875 rpriv
->rep
->vport
)) {
1876 devlink_port_attrs_pci_vf_set(&rpriv
->dl_port
,
1877 &ppid
.id
[0], ppid
.id_len
,
1880 dl_port_index
= vport_to_devlink_port_index(dev
, rep
->vport
);
1883 return devlink_port_register(devlink
, &rpriv
->dl_port
, dl_port_index
);
1886 static void unregister_devlink_port(struct mlx5_core_dev
*dev
,
1887 struct mlx5e_rep_priv
*rpriv
)
1889 if (is_devlink_port_supported(dev
, rpriv
))
1890 devlink_port_unregister(&rpriv
->dl_port
);
1893 /* e-Switch vport representors */
1895 mlx5e_vport_rep_load(struct mlx5_core_dev
*dev
, struct mlx5_eswitch_rep
*rep
)
1897 const struct mlx5e_profile
*profile
;
1898 struct mlx5e_rep_priv
*rpriv
;
1899 struct net_device
*netdev
;
1902 rpriv
= kzalloc(sizeof(*rpriv
), GFP_KERNEL
);
1906 /* rpriv->rep to be looked up when profile->init() is called */
1909 nch
= mlx5e_get_max_num_channels(dev
);
1910 profile
= (rep
->vport
== MLX5_VPORT_UPLINK
) ?
1911 &mlx5e_uplink_rep_profile
: &mlx5e_rep_profile
;
1912 netdev
= mlx5e_create_netdev(dev
, profile
, nch
, rpriv
);
1914 pr_warn("Failed to create representor netdev for vport %d\n",
1920 dev_net_set(netdev
, mlx5_core_net(dev
));
1921 rpriv
->netdev
= netdev
;
1922 rep
->rep_data
[REP_ETH
].priv
= rpriv
;
1923 INIT_LIST_HEAD(&rpriv
->vport_sqs_list
);
1925 if (rep
->vport
== MLX5_VPORT_UPLINK
) {
1926 err
= mlx5e_create_mdev_resources(dev
);
1928 goto err_destroy_netdev
;
1931 err
= mlx5e_attach_netdev(netdev_priv(netdev
));
1933 pr_warn("Failed to attach representor netdev for vport %d\n",
1935 goto err_destroy_mdev_resources
;
1938 err
= mlx5e_rep_neigh_init(rpriv
);
1940 pr_warn("Failed to initialized neighbours handling for vport %d\n",
1942 goto err_detach_netdev
;
1945 err
= register_devlink_port(dev
, rpriv
);
1947 esw_warn(dev
, "Failed to register devlink port %d\n",
1949 goto err_neigh_cleanup
;
1952 err
= register_netdev(netdev
);
1954 pr_warn("Failed to register representor netdev for vport %d\n",
1956 goto err_devlink_cleanup
;
1959 if (is_devlink_port_supported(dev
, rpriv
))
1960 devlink_port_type_eth_set(&rpriv
->dl_port
, netdev
);
1963 err_devlink_cleanup
:
1964 unregister_devlink_port(dev
, rpriv
);
1967 mlx5e_rep_neigh_cleanup(rpriv
);
1970 mlx5e_detach_netdev(netdev_priv(netdev
));
1972 err_destroy_mdev_resources
:
1973 if (rep
->vport
== MLX5_VPORT_UPLINK
)
1974 mlx5e_destroy_mdev_resources(dev
);
1977 mlx5e_destroy_netdev(netdev_priv(netdev
));
1983 mlx5e_vport_rep_unload(struct mlx5_eswitch_rep
*rep
)
1985 struct mlx5e_rep_priv
*rpriv
= mlx5e_rep_to_rep_priv(rep
);
1986 struct net_device
*netdev
= rpriv
->netdev
;
1987 struct mlx5e_priv
*priv
= netdev_priv(netdev
);
1988 struct mlx5_core_dev
*dev
= priv
->mdev
;
1989 void *ppriv
= priv
->ppriv
;
1991 if (is_devlink_port_supported(dev
, rpriv
))
1992 devlink_port_type_clear(&rpriv
->dl_port
);
1993 unregister_netdev(netdev
);
1994 unregister_devlink_port(dev
, rpriv
);
1995 mlx5e_rep_neigh_cleanup(rpriv
);
1996 mlx5e_detach_netdev(priv
);
1997 if (rep
->vport
== MLX5_VPORT_UPLINK
)
1998 mlx5e_destroy_mdev_resources(priv
->mdev
);
1999 mlx5e_destroy_netdev(priv
);
2000 kfree(ppriv
); /* mlx5e_rep_priv */
2003 static void *mlx5e_vport_rep_get_proto_dev(struct mlx5_eswitch_rep
*rep
)
2005 struct mlx5e_rep_priv
*rpriv
;
2007 rpriv
= mlx5e_rep_to_rep_priv(rep
);
2009 return rpriv
->netdev
;
2012 static const struct mlx5_eswitch_rep_ops rep_ops
= {
2013 .load
= mlx5e_vport_rep_load
,
2014 .unload
= mlx5e_vport_rep_unload
,
2015 .get_proto_dev
= mlx5e_vport_rep_get_proto_dev
2018 void mlx5e_rep_register_vport_reps(struct mlx5_core_dev
*mdev
)
2020 struct mlx5_eswitch
*esw
= mdev
->priv
.eswitch
;
2022 mlx5_eswitch_register_vport_reps(esw
, &rep_ops
, REP_ETH
);
2025 void mlx5e_rep_unregister_vport_reps(struct mlx5_core_dev
*mdev
)
2027 struct mlx5_eswitch
*esw
= mdev
->priv
.eswitch
;
2029 mlx5_eswitch_unregister_vport_reps(esw
, REP_ETH
);