Merge tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64...
[sfrench/cifs-2.6.git] / drivers / net / ethernet / mellanox / mlx5 / core / en_rep.c
1 /*
2  * Copyright (c) 2016, Mellanox Technologies. All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32
33 #include <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>
39 #include <net/arp.h>
40
41 #include "eswitch.h"
42 #include "en.h"
43 #include "en_rep.h"
44 #include "en_tc.h"
45 #include "fs_core.h"
46
47 static const char mlx5e_rep_driver_name[] = "mlx5e_rep";
48
49 static void mlx5e_rep_get_drvinfo(struct net_device *dev,
50                                   struct ethtool_drvinfo *drvinfo)
51 {
52         strlcpy(drvinfo->driver, mlx5e_rep_driver_name,
53                 sizeof(drvinfo->driver));
54         strlcpy(drvinfo->version, UTS_RELEASE, sizeof(drvinfo->version));
55 }
56
57 static const struct counter_desc sw_rep_stats_desc[] = {
58         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_packets) },
59         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_bytes) },
60         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_packets) },
61         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_bytes) },
62 };
63
64 #define NUM_VPORT_REP_COUNTERS  ARRAY_SIZE(sw_rep_stats_desc)
65
66 static void mlx5e_rep_get_strings(struct net_device *dev,
67                                   u32 stringset, uint8_t *data)
68 {
69         int i;
70
71         switch (stringset) {
72         case ETH_SS_STATS:
73                 for (i = 0; i < NUM_VPORT_REP_COUNTERS; i++)
74                         strcpy(data + (i * ETH_GSTRING_LEN),
75                                sw_rep_stats_desc[i].format);
76                 break;
77         }
78 }
79
80 static void mlx5e_rep_update_hw_counters(struct mlx5e_priv *priv)
81 {
82         struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
83         struct mlx5e_rep_priv *rpriv = priv->ppriv;
84         struct mlx5_eswitch_rep *rep = rpriv->rep;
85         struct rtnl_link_stats64 *vport_stats;
86         struct ifla_vf_stats vf_stats;
87         int err;
88
89         err = mlx5_eswitch_get_vport_stats(esw, rep->vport, &vf_stats);
90         if (err) {
91                 pr_warn("vport %d error %d reading stats\n", rep->vport, err);
92                 return;
93         }
94
95         vport_stats = &priv->stats.vf_vport;
96         /* flip tx/rx as we are reporting the counters for the switch vport */
97         vport_stats->rx_packets = vf_stats.tx_packets;
98         vport_stats->rx_bytes   = vf_stats.tx_bytes;
99         vport_stats->tx_packets = vf_stats.rx_packets;
100         vport_stats->tx_bytes   = vf_stats.rx_bytes;
101 }
102
103 static void mlx5e_rep_update_sw_counters(struct mlx5e_priv *priv)
104 {
105         struct mlx5e_sw_stats *s = &priv->stats.sw;
106         struct mlx5e_rq_stats *rq_stats;
107         struct mlx5e_sq_stats *sq_stats;
108         int i, j;
109
110         memset(s, 0, sizeof(*s));
111         for (i = 0; i < priv->channels.num; i++) {
112                 struct mlx5e_channel *c = priv->channels.c[i];
113
114                 rq_stats = &c->rq.stats;
115
116                 s->rx_packets   += rq_stats->packets;
117                 s->rx_bytes     += rq_stats->bytes;
118
119                 for (j = 0; j < priv->channels.params.num_tc; j++) {
120                         sq_stats = &c->sq[j].stats;
121
122                         s->tx_packets           += sq_stats->packets;
123                         s->tx_bytes             += sq_stats->bytes;
124                 }
125         }
126 }
127
128 static void mlx5e_rep_update_stats(struct mlx5e_priv *priv)
129 {
130         mlx5e_rep_update_sw_counters(priv);
131         mlx5e_rep_update_hw_counters(priv);
132 }
133
134 static void mlx5e_rep_get_ethtool_stats(struct net_device *dev,
135                                         struct ethtool_stats *stats, u64 *data)
136 {
137         struct mlx5e_priv *priv = netdev_priv(dev);
138         int i;
139
140         if (!data)
141                 return;
142
143         mutex_lock(&priv->state_lock);
144         if (test_bit(MLX5E_STATE_OPENED, &priv->state))
145                 mlx5e_rep_update_sw_counters(priv);
146         mutex_unlock(&priv->state_lock);
147
148         for (i = 0; i < NUM_VPORT_REP_COUNTERS; i++)
149                 data[i] = MLX5E_READ_CTR64_CPU(&priv->stats.sw,
150                                                sw_rep_stats_desc, i);
151 }
152
153 static int mlx5e_rep_get_sset_count(struct net_device *dev, int sset)
154 {
155         switch (sset) {
156         case ETH_SS_STATS:
157                 return NUM_VPORT_REP_COUNTERS;
158         default:
159                 return -EOPNOTSUPP;
160         }
161 }
162
163 static const struct ethtool_ops mlx5e_rep_ethtool_ops = {
164         .get_drvinfo       = mlx5e_rep_get_drvinfo,
165         .get_link          = ethtool_op_get_link,
166         .get_strings       = mlx5e_rep_get_strings,
167         .get_sset_count    = mlx5e_rep_get_sset_count,
168         .get_ethtool_stats = mlx5e_rep_get_ethtool_stats,
169 };
170
171 int mlx5e_attr_get(struct net_device *dev, struct switchdev_attr *attr)
172 {
173         struct mlx5e_priv *priv = netdev_priv(dev);
174         struct mlx5e_rep_priv *rpriv = priv->ppriv;
175         struct mlx5_eswitch_rep *rep = rpriv->rep;
176         struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
177
178         if (esw->mode == SRIOV_NONE)
179                 return -EOPNOTSUPP;
180
181         switch (attr->id) {
182         case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
183                 attr->u.ppid.id_len = ETH_ALEN;
184                 ether_addr_copy(attr->u.ppid.id, rep->hw_id);
185                 break;
186         default:
187                 return -EOPNOTSUPP;
188         }
189
190         return 0;
191 }
192
193 static void mlx5e_sqs2vport_stop(struct mlx5_eswitch *esw,
194                                  struct mlx5_eswitch_rep *rep)
195 {
196         struct mlx5e_rep_sq *rep_sq, *tmp;
197         struct mlx5e_rep_priv *rpriv;
198
199         if (esw->mode != SRIOV_OFFLOADS)
200                 return;
201
202         rpriv = mlx5e_rep_to_rep_priv(rep);
203         list_for_each_entry_safe(rep_sq, tmp, &rpriv->vport_sqs_list, list) {
204                 mlx5_eswitch_del_send_to_vport_rule(rep_sq->send_to_vport_rule);
205                 list_del(&rep_sq->list);
206                 kfree(rep_sq);
207         }
208 }
209
210 static int mlx5e_sqs2vport_start(struct mlx5_eswitch *esw,
211                                  struct mlx5_eswitch_rep *rep,
212                                  u16 *sqns_array, int sqns_num)
213 {
214         struct mlx5_flow_handle *flow_rule;
215         struct mlx5e_rep_priv *rpriv;
216         struct mlx5e_rep_sq *rep_sq;
217         int err;
218         int i;
219
220         if (esw->mode != SRIOV_OFFLOADS)
221                 return 0;
222
223         rpriv = mlx5e_rep_to_rep_priv(rep);
224         for (i = 0; i < sqns_num; i++) {
225                 rep_sq = kzalloc(sizeof(*rep_sq), GFP_KERNEL);
226                 if (!rep_sq) {
227                         err = -ENOMEM;
228                         goto out_err;
229                 }
230
231                 /* Add re-inject rule to the PF/representor sqs */
232                 flow_rule = mlx5_eswitch_add_send_to_vport_rule(esw,
233                                                                 rep->vport,
234                                                                 sqns_array[i]);
235                 if (IS_ERR(flow_rule)) {
236                         err = PTR_ERR(flow_rule);
237                         kfree(rep_sq);
238                         goto out_err;
239                 }
240                 rep_sq->send_to_vport_rule = flow_rule;
241                 list_add(&rep_sq->list, &rpriv->vport_sqs_list);
242         }
243         return 0;
244
245 out_err:
246         mlx5e_sqs2vport_stop(esw, rep);
247         return err;
248 }
249
250 int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv)
251 {
252         struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
253         struct mlx5e_rep_priv *rpriv = priv->ppriv;
254         struct mlx5_eswitch_rep *rep = rpriv->rep;
255         struct mlx5e_channel *c;
256         int n, tc, num_sqs = 0;
257         int err = -ENOMEM;
258         u16 *sqs;
259
260         sqs = kcalloc(priv->channels.num * priv->channels.params.num_tc, sizeof(u16), GFP_KERNEL);
261         if (!sqs)
262                 goto out;
263
264         for (n = 0; n < priv->channels.num; n++) {
265                 c = priv->channels.c[n];
266                 for (tc = 0; tc < c->num_tc; tc++)
267                         sqs[num_sqs++] = c->sq[tc].sqn;
268         }
269
270         err = mlx5e_sqs2vport_start(esw, rep, sqs, num_sqs);
271         kfree(sqs);
272
273 out:
274         if (err)
275                 netdev_warn(priv->netdev, "Failed to add SQs FWD rules %d\n", err);
276         return err;
277 }
278
279 void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv)
280 {
281         struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
282         struct mlx5e_rep_priv *rpriv = priv->ppriv;
283         struct mlx5_eswitch_rep *rep = rpriv->rep;
284
285         mlx5e_sqs2vport_stop(esw, rep);
286 }
287
288 static void mlx5e_rep_neigh_update_init_interval(struct mlx5e_rep_priv *rpriv)
289 {
290 #if IS_ENABLED(CONFIG_IPV6)
291         unsigned long ipv6_interval = NEIGH_VAR(&ipv6_stub->nd_tbl->parms,
292                                                 DELAY_PROBE_TIME);
293 #else
294         unsigned long ipv6_interval = ~0UL;
295 #endif
296         unsigned long ipv4_interval = NEIGH_VAR(&arp_tbl.parms,
297                                                 DELAY_PROBE_TIME);
298         struct net_device *netdev = rpriv->netdev;
299         struct mlx5e_priv *priv = netdev_priv(netdev);
300
301         rpriv->neigh_update.min_interval = min_t(unsigned long, ipv6_interval, ipv4_interval);
302         mlx5_fc_update_sampling_interval(priv->mdev, rpriv->neigh_update.min_interval);
303 }
304
305 void mlx5e_rep_queue_neigh_stats_work(struct mlx5e_priv *priv)
306 {
307         struct mlx5e_rep_priv *rpriv = priv->ppriv;
308         struct mlx5e_neigh_update_table *neigh_update = &rpriv->neigh_update;
309
310         mlx5_fc_queue_stats_work(priv->mdev,
311                                  &neigh_update->neigh_stats_work,
312                                  neigh_update->min_interval);
313 }
314
315 static void mlx5e_rep_neigh_stats_work(struct work_struct *work)
316 {
317         struct mlx5e_rep_priv *rpriv = container_of(work, struct mlx5e_rep_priv,
318                                                     neigh_update.neigh_stats_work.work);
319         struct net_device *netdev = rpriv->netdev;
320         struct mlx5e_priv *priv = netdev_priv(netdev);
321         struct mlx5e_neigh_hash_entry *nhe;
322
323         rtnl_lock();
324         if (!list_empty(&rpriv->neigh_update.neigh_list))
325                 mlx5e_rep_queue_neigh_stats_work(priv);
326
327         list_for_each_entry(nhe, &rpriv->neigh_update.neigh_list, neigh_list)
328                 mlx5e_tc_update_neigh_used_value(nhe);
329
330         rtnl_unlock();
331 }
332
333 static void mlx5e_rep_neigh_entry_hold(struct mlx5e_neigh_hash_entry *nhe)
334 {
335         refcount_inc(&nhe->refcnt);
336 }
337
338 static void mlx5e_rep_neigh_entry_release(struct mlx5e_neigh_hash_entry *nhe)
339 {
340         if (refcount_dec_and_test(&nhe->refcnt))
341                 kfree(nhe);
342 }
343
344 static void mlx5e_rep_update_flows(struct mlx5e_priv *priv,
345                                    struct mlx5e_encap_entry *e,
346                                    bool neigh_connected,
347                                    unsigned char ha[ETH_ALEN])
348 {
349         struct ethhdr *eth = (struct ethhdr *)e->encap_header;
350
351         ASSERT_RTNL();
352
353         if ((!neigh_connected && (e->flags & MLX5_ENCAP_ENTRY_VALID)) ||
354             !ether_addr_equal(e->h_dest, ha))
355                 mlx5e_tc_encap_flows_del(priv, e);
356
357         if (neigh_connected && !(e->flags & MLX5_ENCAP_ENTRY_VALID)) {
358                 ether_addr_copy(e->h_dest, ha);
359                 ether_addr_copy(eth->h_dest, ha);
360
361                 mlx5e_tc_encap_flows_add(priv, e);
362         }
363 }
364
365 static void mlx5e_rep_neigh_update(struct work_struct *work)
366 {
367         struct mlx5e_neigh_hash_entry *nhe =
368                 container_of(work, struct mlx5e_neigh_hash_entry, neigh_update_work);
369         struct neighbour *n = nhe->n;
370         struct mlx5e_encap_entry *e;
371         unsigned char ha[ETH_ALEN];
372         struct mlx5e_priv *priv;
373         bool neigh_connected;
374         bool encap_connected;
375         u8 nud_state, dead;
376
377         rtnl_lock();
378
379         /* If these parameters are changed after we release the lock,
380          * we'll receive another event letting us know about it.
381          * We use this lock to avoid inconsistency between the neigh validity
382          * and it's hw address.
383          */
384         read_lock_bh(&n->lock);
385         memcpy(ha, n->ha, ETH_ALEN);
386         nud_state = n->nud_state;
387         dead = n->dead;
388         read_unlock_bh(&n->lock);
389
390         neigh_connected = (nud_state & NUD_VALID) && !dead;
391
392         list_for_each_entry(e, &nhe->encap_list, encap_list) {
393                 encap_connected = !!(e->flags & MLX5_ENCAP_ENTRY_VALID);
394                 priv = netdev_priv(e->out_dev);
395
396                 if (encap_connected != neigh_connected ||
397                     !ether_addr_equal(e->h_dest, ha))
398                         mlx5e_rep_update_flows(priv, e, neigh_connected, ha);
399         }
400         mlx5e_rep_neigh_entry_release(nhe);
401         rtnl_unlock();
402         neigh_release(n);
403 }
404
405 static struct mlx5e_neigh_hash_entry *
406 mlx5e_rep_neigh_entry_lookup(struct mlx5e_priv *priv,
407                              struct mlx5e_neigh *m_neigh);
408
409 static int mlx5e_rep_netevent_event(struct notifier_block *nb,
410                                     unsigned long event, void *ptr)
411 {
412         struct mlx5e_rep_priv *rpriv = container_of(nb, struct mlx5e_rep_priv,
413                                                     neigh_update.netevent_nb);
414         struct mlx5e_neigh_update_table *neigh_update = &rpriv->neigh_update;
415         struct net_device *netdev = rpriv->netdev;
416         struct mlx5e_priv *priv = netdev_priv(netdev);
417         struct mlx5e_neigh_hash_entry *nhe = NULL;
418         struct mlx5e_neigh m_neigh = {};
419         struct neigh_parms *p;
420         struct neighbour *n;
421         bool found = false;
422
423         switch (event) {
424         case NETEVENT_NEIGH_UPDATE:
425                 n = ptr;
426 #if IS_ENABLED(CONFIG_IPV6)
427                 if (n->tbl != ipv6_stub->nd_tbl && n->tbl != &arp_tbl)
428 #else
429                 if (n->tbl != &arp_tbl)
430 #endif
431                         return NOTIFY_DONE;
432
433                 m_neigh.dev = n->dev;
434                 m_neigh.family = n->ops->family;
435                 memcpy(&m_neigh.dst_ip, n->primary_key, n->tbl->key_len);
436
437                 /* We are in atomic context and can't take RTNL mutex, so use
438                  * spin_lock_bh to lookup the neigh table. bh is used since
439                  * netevent can be called from a softirq context.
440                  */
441                 spin_lock_bh(&neigh_update->encap_lock);
442                 nhe = mlx5e_rep_neigh_entry_lookup(priv, &m_neigh);
443                 if (!nhe) {
444                         spin_unlock_bh(&neigh_update->encap_lock);
445                         return NOTIFY_DONE;
446                 }
447
448                 /* This assignment is valid as long as the the neigh reference
449                  * is taken
450                  */
451                 nhe->n = n;
452
453                 /* Take a reference to ensure the neighbour and mlx5 encap
454                  * entry won't be destructed until we drop the reference in
455                  * delayed work.
456                  */
457                 neigh_hold(n);
458                 mlx5e_rep_neigh_entry_hold(nhe);
459
460                 if (!queue_work(priv->wq, &nhe->neigh_update_work)) {
461                         mlx5e_rep_neigh_entry_release(nhe);
462                         neigh_release(n);
463                 }
464                 spin_unlock_bh(&neigh_update->encap_lock);
465                 break;
466
467         case NETEVENT_DELAY_PROBE_TIME_UPDATE:
468                 p = ptr;
469
470                 /* We check the device is present since we don't care about
471                  * changes in the default table, we only care about changes
472                  * done per device delay prob time parameter.
473                  */
474 #if IS_ENABLED(CONFIG_IPV6)
475                 if (!p->dev || (p->tbl != ipv6_stub->nd_tbl && p->tbl != &arp_tbl))
476 #else
477                 if (!p->dev || p->tbl != &arp_tbl)
478 #endif
479                         return NOTIFY_DONE;
480
481                 /* We are in atomic context and can't take RTNL mutex,
482                  * so use spin_lock_bh to walk the neigh list and look for
483                  * the relevant device. bh is used since netevent can be
484                  * called from a softirq context.
485                  */
486                 spin_lock_bh(&neigh_update->encap_lock);
487                 list_for_each_entry(nhe, &neigh_update->neigh_list, neigh_list) {
488                         if (p->dev == nhe->m_neigh.dev) {
489                                 found = true;
490                                 break;
491                         }
492                 }
493                 spin_unlock_bh(&neigh_update->encap_lock);
494                 if (!found)
495                         return NOTIFY_DONE;
496
497                 neigh_update->min_interval = min_t(unsigned long,
498                                                    NEIGH_VAR(p, DELAY_PROBE_TIME),
499                                                    neigh_update->min_interval);
500                 mlx5_fc_update_sampling_interval(priv->mdev,
501                                                  neigh_update->min_interval);
502                 break;
503         }
504         return NOTIFY_DONE;
505 }
506
507 static const struct rhashtable_params mlx5e_neigh_ht_params = {
508         .head_offset = offsetof(struct mlx5e_neigh_hash_entry, rhash_node),
509         .key_offset = offsetof(struct mlx5e_neigh_hash_entry, m_neigh),
510         .key_len = sizeof(struct mlx5e_neigh),
511         .automatic_shrinking = true,
512 };
513
514 static int mlx5e_rep_neigh_init(struct mlx5e_rep_priv *rpriv)
515 {
516         struct mlx5e_neigh_update_table *neigh_update = &rpriv->neigh_update;
517         int err;
518
519         err = rhashtable_init(&neigh_update->neigh_ht, &mlx5e_neigh_ht_params);
520         if (err)
521                 return err;
522
523         INIT_LIST_HEAD(&neigh_update->neigh_list);
524         spin_lock_init(&neigh_update->encap_lock);
525         INIT_DELAYED_WORK(&neigh_update->neigh_stats_work,
526                           mlx5e_rep_neigh_stats_work);
527         mlx5e_rep_neigh_update_init_interval(rpriv);
528
529         rpriv->neigh_update.netevent_nb.notifier_call = mlx5e_rep_netevent_event;
530         err = register_netevent_notifier(&rpriv->neigh_update.netevent_nb);
531         if (err)
532                 goto out_err;
533         return 0;
534
535 out_err:
536         rhashtable_destroy(&neigh_update->neigh_ht);
537         return err;
538 }
539
540 static void mlx5e_rep_neigh_cleanup(struct mlx5e_rep_priv *rpriv)
541 {
542         struct mlx5e_neigh_update_table *neigh_update = &rpriv->neigh_update;
543         struct mlx5e_priv *priv = netdev_priv(rpriv->netdev);
544
545         unregister_netevent_notifier(&neigh_update->netevent_nb);
546
547         flush_workqueue(priv->wq); /* flush neigh update works */
548
549         cancel_delayed_work_sync(&rpriv->neigh_update.neigh_stats_work);
550
551         rhashtable_destroy(&neigh_update->neigh_ht);
552 }
553
554 static int mlx5e_rep_neigh_entry_insert(struct mlx5e_priv *priv,
555                                         struct mlx5e_neigh_hash_entry *nhe)
556 {
557         struct mlx5e_rep_priv *rpriv = priv->ppriv;
558         int err;
559
560         err = rhashtable_insert_fast(&rpriv->neigh_update.neigh_ht,
561                                      &nhe->rhash_node,
562                                      mlx5e_neigh_ht_params);
563         if (err)
564                 return err;
565
566         list_add(&nhe->neigh_list, &rpriv->neigh_update.neigh_list);
567
568         return err;
569 }
570
571 static void mlx5e_rep_neigh_entry_remove(struct mlx5e_priv *priv,
572                                          struct mlx5e_neigh_hash_entry *nhe)
573 {
574         struct mlx5e_rep_priv *rpriv = priv->ppriv;
575
576         spin_lock_bh(&rpriv->neigh_update.encap_lock);
577
578         list_del(&nhe->neigh_list);
579
580         rhashtable_remove_fast(&rpriv->neigh_update.neigh_ht,
581                                &nhe->rhash_node,
582                                mlx5e_neigh_ht_params);
583         spin_unlock_bh(&rpriv->neigh_update.encap_lock);
584 }
585
586 /* This function must only be called under RTNL lock or under the
587  * representor's encap_lock in case RTNL mutex can't be held.
588  */
589 static struct mlx5e_neigh_hash_entry *
590 mlx5e_rep_neigh_entry_lookup(struct mlx5e_priv *priv,
591                              struct mlx5e_neigh *m_neigh)
592 {
593         struct mlx5e_rep_priv *rpriv = priv->ppriv;
594         struct mlx5e_neigh_update_table *neigh_update = &rpriv->neigh_update;
595
596         return rhashtable_lookup_fast(&neigh_update->neigh_ht, m_neigh,
597                                       mlx5e_neigh_ht_params);
598 }
599
600 static int mlx5e_rep_neigh_entry_create(struct mlx5e_priv *priv,
601                                         struct mlx5e_encap_entry *e,
602                                         struct mlx5e_neigh_hash_entry **nhe)
603 {
604         int err;
605
606         *nhe = kzalloc(sizeof(**nhe), GFP_KERNEL);
607         if (!*nhe)
608                 return -ENOMEM;
609
610         memcpy(&(*nhe)->m_neigh, &e->m_neigh, sizeof(e->m_neigh));
611         INIT_WORK(&(*nhe)->neigh_update_work, mlx5e_rep_neigh_update);
612         INIT_LIST_HEAD(&(*nhe)->encap_list);
613         refcount_set(&(*nhe)->refcnt, 1);
614
615         err = mlx5e_rep_neigh_entry_insert(priv, *nhe);
616         if (err)
617                 goto out_free;
618         return 0;
619
620 out_free:
621         kfree(*nhe);
622         return err;
623 }
624
625 static void mlx5e_rep_neigh_entry_destroy(struct mlx5e_priv *priv,
626                                           struct mlx5e_neigh_hash_entry *nhe)
627 {
628         /* The neigh hash entry must be removed from the hash table regardless
629          * of the reference count value, so it won't be found by the next
630          * neigh notification call. The neigh hash entry reference count is
631          * incremented only during creation and neigh notification calls and
632          * protects from freeing the nhe struct.
633          */
634         mlx5e_rep_neigh_entry_remove(priv, nhe);
635         mlx5e_rep_neigh_entry_release(nhe);
636 }
637
638 int mlx5e_rep_encap_entry_attach(struct mlx5e_priv *priv,
639                                  struct mlx5e_encap_entry *e)
640 {
641         struct mlx5e_neigh_hash_entry *nhe;
642         int err;
643
644         nhe = mlx5e_rep_neigh_entry_lookup(priv, &e->m_neigh);
645         if (!nhe) {
646                 err = mlx5e_rep_neigh_entry_create(priv, e, &nhe);
647                 if (err)
648                         return err;
649         }
650         list_add(&e->encap_list, &nhe->encap_list);
651         return 0;
652 }
653
654 void mlx5e_rep_encap_entry_detach(struct mlx5e_priv *priv,
655                                   struct mlx5e_encap_entry *e)
656 {
657         struct mlx5e_neigh_hash_entry *nhe;
658
659         list_del(&e->encap_list);
660         nhe = mlx5e_rep_neigh_entry_lookup(priv, &e->m_neigh);
661
662         if (list_empty(&nhe->encap_list))
663                 mlx5e_rep_neigh_entry_destroy(priv, nhe);
664 }
665
666 static int mlx5e_rep_open(struct net_device *dev)
667 {
668         struct mlx5e_priv *priv = netdev_priv(dev);
669         struct mlx5e_rep_priv *rpriv = priv->ppriv;
670         struct mlx5_eswitch_rep *rep = rpriv->rep;
671         struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
672         int err;
673
674         mutex_lock(&priv->state_lock);
675         err = mlx5e_open_locked(dev);
676         if (err)
677                 goto unlock;
678
679         if (!mlx5_eswitch_set_vport_state(esw, rep->vport,
680                                           MLX5_ESW_VPORT_ADMIN_STATE_UP))
681                 netif_carrier_on(dev);
682
683 unlock:
684         mutex_unlock(&priv->state_lock);
685         return err;
686 }
687
688 static int mlx5e_rep_close(struct net_device *dev)
689 {
690         struct mlx5e_priv *priv = netdev_priv(dev);
691         struct mlx5e_rep_priv *rpriv = priv->ppriv;
692         struct mlx5_eswitch_rep *rep = rpriv->rep;
693         struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
694         int ret;
695
696         mutex_lock(&priv->state_lock);
697         (void)mlx5_eswitch_set_vport_state(esw, rep->vport, MLX5_ESW_VPORT_ADMIN_STATE_DOWN);
698         ret = mlx5e_close_locked(dev);
699         mutex_unlock(&priv->state_lock);
700         return ret;
701 }
702
703 static int mlx5e_rep_get_phys_port_name(struct net_device *dev,
704                                         char *buf, size_t len)
705 {
706         struct mlx5e_priv *priv = netdev_priv(dev);
707         struct mlx5e_rep_priv *rpriv = priv->ppriv;
708         struct mlx5_eswitch_rep *rep = rpriv->rep;
709         int ret;
710
711         ret = snprintf(buf, len, "%d", rep->vport - 1);
712         if (ret >= len)
713                 return -EOPNOTSUPP;
714
715         return 0;
716 }
717
718 static int
719 mlx5e_rep_setup_tc_cls_flower(struct mlx5e_priv *priv,
720                               struct tc_cls_flower_offload *cls_flower)
721 {
722         switch (cls_flower->command) {
723         case TC_CLSFLOWER_REPLACE:
724                 return mlx5e_configure_flower(priv, cls_flower);
725         case TC_CLSFLOWER_DESTROY:
726                 return mlx5e_delete_flower(priv, cls_flower);
727         case TC_CLSFLOWER_STATS:
728                 return mlx5e_stats_flower(priv, cls_flower);
729         default:
730                 return -EOPNOTSUPP;
731         }
732 }
733
734 static int mlx5e_rep_setup_tc_cb(enum tc_setup_type type, void *type_data,
735                                  void *cb_priv)
736 {
737         struct mlx5e_priv *priv = cb_priv;
738
739         if (!tc_cls_can_offload_and_chain0(priv->netdev, type_data))
740                 return -EOPNOTSUPP;
741
742         switch (type) {
743         case TC_SETUP_CLSFLOWER:
744                 return mlx5e_rep_setup_tc_cls_flower(priv, type_data);
745         default:
746                 return -EOPNOTSUPP;
747         }
748 }
749
750 static int mlx5e_rep_setup_tc_block(struct net_device *dev,
751                                     struct tc_block_offload *f)
752 {
753         struct mlx5e_priv *priv = netdev_priv(dev);
754
755         if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
756                 return -EOPNOTSUPP;
757
758         switch (f->command) {
759         case TC_BLOCK_BIND:
760                 return tcf_block_cb_register(f->block, mlx5e_rep_setup_tc_cb,
761                                              priv, priv);
762         case TC_BLOCK_UNBIND:
763                 tcf_block_cb_unregister(f->block, mlx5e_rep_setup_tc_cb, priv);
764                 return 0;
765         default:
766                 return -EOPNOTSUPP;
767         }
768 }
769
770 static int mlx5e_rep_setup_tc(struct net_device *dev, enum tc_setup_type type,
771                               void *type_data)
772 {
773         switch (type) {
774         case TC_SETUP_BLOCK:
775                 return mlx5e_rep_setup_tc_block(dev, type_data);
776         default:
777                 return -EOPNOTSUPP;
778         }
779 }
780
781 bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv)
782 {
783         struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
784         struct mlx5e_rep_priv *rpriv = priv->ppriv;
785         struct mlx5_eswitch_rep *rep;
786
787         if (!MLX5_CAP_GEN(priv->mdev, vport_group_manager))
788                 return false;
789
790         rep = rpriv->rep;
791         if (esw->mode == SRIOV_OFFLOADS &&
792             rep && rep->vport == FDB_UPLINK_VPORT)
793                 return true;
794
795         return false;
796 }
797
798 static bool mlx5e_is_vf_vport_rep(struct mlx5e_priv *priv)
799 {
800         struct mlx5e_rep_priv *rpriv = priv->ppriv;
801         struct mlx5_eswitch_rep *rep = rpriv->rep;
802
803         if (rep && rep->vport != FDB_UPLINK_VPORT)
804                 return true;
805
806         return false;
807 }
808
809 bool mlx5e_has_offload_stats(const struct net_device *dev, int attr_id)
810 {
811         struct mlx5e_priv *priv = netdev_priv(dev);
812
813         switch (attr_id) {
814         case IFLA_OFFLOAD_XSTATS_CPU_HIT:
815                 if (mlx5e_is_vf_vport_rep(priv) || mlx5e_is_uplink_rep(priv))
816                         return true;
817         }
818
819         return false;
820 }
821
822 static int
823 mlx5e_get_sw_stats64(const struct net_device *dev,
824                      struct rtnl_link_stats64 *stats)
825 {
826         struct mlx5e_priv *priv = netdev_priv(dev);
827         struct mlx5e_sw_stats *sstats = &priv->stats.sw;
828
829         stats->rx_packets = sstats->rx_packets;
830         stats->rx_bytes   = sstats->rx_bytes;
831         stats->tx_packets = sstats->tx_packets;
832         stats->tx_bytes   = sstats->tx_bytes;
833
834         stats->tx_dropped = sstats->tx_queue_dropped;
835
836         return 0;
837 }
838
839 int mlx5e_get_offload_stats(int attr_id, const struct net_device *dev,
840                             void *sp)
841 {
842         switch (attr_id) {
843         case IFLA_OFFLOAD_XSTATS_CPU_HIT:
844                 return mlx5e_get_sw_stats64(dev, sp);
845         }
846
847         return -EINVAL;
848 }
849
850 static void
851 mlx5e_rep_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
852 {
853         struct mlx5e_priv *priv = netdev_priv(dev);
854
855         memcpy(stats, &priv->stats.vf_vport, sizeof(*stats));
856 }
857
858 static const struct switchdev_ops mlx5e_rep_switchdev_ops = {
859         .switchdev_port_attr_get        = mlx5e_attr_get,
860 };
861
862 static const struct net_device_ops mlx5e_netdev_ops_rep = {
863         .ndo_open                = mlx5e_rep_open,
864         .ndo_stop                = mlx5e_rep_close,
865         .ndo_start_xmit          = mlx5e_xmit,
866         .ndo_get_phys_port_name  = mlx5e_rep_get_phys_port_name,
867         .ndo_setup_tc            = mlx5e_rep_setup_tc,
868         .ndo_get_stats64         = mlx5e_rep_get_stats,
869         .ndo_has_offload_stats   = mlx5e_has_offload_stats,
870         .ndo_get_offload_stats   = mlx5e_get_offload_stats,
871 };
872
873 static void mlx5e_build_rep_params(struct mlx5_core_dev *mdev,
874                                    struct mlx5e_params *params)
875 {
876         u8 cq_period_mode = MLX5_CAP_GEN(mdev, cq_period_start_from_cqe) ?
877                                          MLX5_CQ_PERIOD_MODE_START_FROM_CQE :
878                                          MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
879
880         params->log_sq_size = MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE;
881         params->rq_wq_type  = MLX5_WQ_TYPE_LINKED_LIST;
882         params->log_rq_size = MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE;
883
884         params->rx_dim_enabled = MLX5_CAP_GEN(mdev, cq_moderation);
885         mlx5e_set_rx_cq_mode_params(params, cq_period_mode);
886
887         params->tx_max_inline         = mlx5e_get_max_inline_cap(mdev);
888         params->num_tc                = 1;
889         params->lro_wqe_sz            = MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ;
890
891         mlx5_query_min_inline(mdev, &params->tx_min_inline_mode);
892 }
893
894 static void mlx5e_build_rep_netdev(struct net_device *netdev)
895 {
896         netdev->netdev_ops = &mlx5e_netdev_ops_rep;
897
898         netdev->watchdog_timeo    = 15 * HZ;
899
900         netdev->ethtool_ops       = &mlx5e_rep_ethtool_ops;
901
902 #ifdef CONFIG_NET_SWITCHDEV
903         netdev->switchdev_ops = &mlx5e_rep_switchdev_ops;
904 #endif
905
906         netdev->features         |= NETIF_F_VLAN_CHALLENGED | NETIF_F_HW_TC | NETIF_F_NETNS_LOCAL;
907         netdev->hw_features      |= NETIF_F_HW_TC;
908
909         eth_hw_addr_random(netdev);
910 }
911
912 static void mlx5e_init_rep(struct mlx5_core_dev *mdev,
913                            struct net_device *netdev,
914                            const struct mlx5e_profile *profile,
915                            void *ppriv)
916 {
917         struct mlx5e_priv *priv = netdev_priv(netdev);
918
919         priv->mdev                         = mdev;
920         priv->netdev                       = netdev;
921         priv->profile                      = profile;
922         priv->ppriv                        = ppriv;
923
924         mutex_init(&priv->state_lock);
925
926         INIT_DELAYED_WORK(&priv->update_stats_work, mlx5e_update_stats_work);
927
928         priv->channels.params.num_channels = profile->max_nch(mdev);
929
930         priv->hard_mtu = MLX5E_ETH_HARD_MTU;
931
932         mlx5e_build_rep_params(mdev, &priv->channels.params);
933         mlx5e_build_rep_netdev(netdev);
934
935         mlx5e_timestamp_init(priv);
936 }
937
938 static int mlx5e_init_rep_rx(struct mlx5e_priv *priv)
939 {
940         struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
941         struct mlx5e_rep_priv *rpriv = priv->ppriv;
942         struct mlx5_eswitch_rep *rep = rpriv->rep;
943         struct mlx5_flow_handle *flow_rule;
944         int err;
945
946         mlx5e_init_l2_addr(priv);
947
948         err = mlx5e_create_direct_rqts(priv);
949         if (err)
950                 return err;
951
952         err = mlx5e_create_direct_tirs(priv);
953         if (err)
954                 goto err_destroy_direct_rqts;
955
956         flow_rule = mlx5_eswitch_create_vport_rx_rule(esw,
957                                                       rep->vport,
958                                                       priv->direct_tir[0].tirn);
959         if (IS_ERR(flow_rule)) {
960                 err = PTR_ERR(flow_rule);
961                 goto err_destroy_direct_tirs;
962         }
963         rpriv->vport_rx_rule = flow_rule;
964
965         err = mlx5e_tc_init(priv);
966         if (err)
967                 goto err_del_flow_rule;
968
969         return 0;
970
971 err_del_flow_rule:
972         mlx5_del_flow_rules(rpriv->vport_rx_rule);
973 err_destroy_direct_tirs:
974         mlx5e_destroy_direct_tirs(priv);
975 err_destroy_direct_rqts:
976         mlx5e_destroy_direct_rqts(priv);
977         return err;
978 }
979
980 static void mlx5e_cleanup_rep_rx(struct mlx5e_priv *priv)
981 {
982         struct mlx5e_rep_priv *rpriv = priv->ppriv;
983
984         mlx5e_tc_cleanup(priv);
985         mlx5_del_flow_rules(rpriv->vport_rx_rule);
986         mlx5e_destroy_direct_tirs(priv);
987         mlx5e_destroy_direct_rqts(priv);
988 }
989
990 static int mlx5e_init_rep_tx(struct mlx5e_priv *priv)
991 {
992         int err;
993
994         err = mlx5e_create_tises(priv);
995         if (err) {
996                 mlx5_core_warn(priv->mdev, "create tises failed, %d\n", err);
997                 return err;
998         }
999         return 0;
1000 }
1001
1002 static int mlx5e_get_rep_max_num_channels(struct mlx5_core_dev *mdev)
1003 {
1004 #define MLX5E_PORT_REPRESENTOR_NCH 1
1005         return MLX5E_PORT_REPRESENTOR_NCH;
1006 }
1007
1008 static const struct mlx5e_profile mlx5e_rep_profile = {
1009         .init                   = mlx5e_init_rep,
1010         .init_rx                = mlx5e_init_rep_rx,
1011         .cleanup_rx             = mlx5e_cleanup_rep_rx,
1012         .init_tx                = mlx5e_init_rep_tx,
1013         .cleanup_tx             = mlx5e_cleanup_nic_tx,
1014         .update_stats           = mlx5e_rep_update_stats,
1015         .max_nch                = mlx5e_get_rep_max_num_channels,
1016         .update_carrier         = NULL,
1017         .rx_handlers.handle_rx_cqe       = mlx5e_handle_rx_cqe_rep,
1018         .rx_handlers.handle_rx_cqe_mpwqe = NULL /* Not supported */,
1019         .max_tc                 = 1,
1020 };
1021
1022 /* e-Switch vport representors */
1023
1024 static int
1025 mlx5e_nic_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
1026 {
1027         struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
1028         struct mlx5e_priv *priv = netdev_priv(rpriv->netdev);
1029
1030         int err;
1031
1032         if (test_bit(MLX5E_STATE_OPENED, &priv->state)) {
1033                 err = mlx5e_add_sqs_fwd_rules(priv);
1034                 if (err)
1035                         return err;
1036         }
1037
1038         err = mlx5e_rep_neigh_init(rpriv);
1039         if (err)
1040                 goto err_remove_sqs;
1041
1042         return 0;
1043
1044 err_remove_sqs:
1045         mlx5e_remove_sqs_fwd_rules(priv);
1046         return err;
1047 }
1048
1049 static void
1050 mlx5e_nic_rep_unload(struct mlx5_eswitch_rep *rep)
1051 {
1052         struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
1053         struct mlx5e_priv *priv = netdev_priv(rpriv->netdev);
1054
1055         if (test_bit(MLX5E_STATE_OPENED, &priv->state))
1056                 mlx5e_remove_sqs_fwd_rules(priv);
1057
1058         /* clean (and re-init) existing uplink offloaded TC rules */
1059         mlx5e_tc_cleanup(priv);
1060         mlx5e_tc_init(priv);
1061
1062         mlx5e_rep_neigh_cleanup(rpriv);
1063 }
1064
1065 static int
1066 mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
1067 {
1068         struct mlx5e_rep_priv *uplink_rpriv;
1069         struct mlx5e_rep_priv *rpriv;
1070         struct net_device *netdev;
1071         struct mlx5e_priv *upriv;
1072         int err;
1073
1074         rpriv = kzalloc(sizeof(*rpriv), GFP_KERNEL);
1075         if (!rpriv)
1076                 return -ENOMEM;
1077
1078         netdev = mlx5e_create_netdev(dev, &mlx5e_rep_profile, rpriv);
1079         if (!netdev) {
1080                 pr_warn("Failed to create representor netdev for vport %d\n",
1081                         rep->vport);
1082                 kfree(rpriv);
1083                 return -EINVAL;
1084         }
1085
1086         rpriv->netdev = netdev;
1087         rpriv->rep = rep;
1088         rep->rep_if[REP_ETH].priv = rpriv;
1089         INIT_LIST_HEAD(&rpriv->vport_sqs_list);
1090
1091         err = mlx5e_attach_netdev(netdev_priv(netdev));
1092         if (err) {
1093                 pr_warn("Failed to attach representor netdev for vport %d\n",
1094                         rep->vport);
1095                 goto err_destroy_netdev;
1096         }
1097
1098         err = mlx5e_rep_neigh_init(rpriv);
1099         if (err) {
1100                 pr_warn("Failed to initialized neighbours handling for vport %d\n",
1101                         rep->vport);
1102                 goto err_detach_netdev;
1103         }
1104
1105         uplink_rpriv = mlx5_eswitch_get_uplink_priv(dev->priv.eswitch, REP_ETH);
1106         upriv = netdev_priv(uplink_rpriv->netdev);
1107         err = tc_setup_cb_egdev_register(netdev, mlx5e_setup_tc_block_cb,
1108                                          upriv);
1109         if (err)
1110                 goto err_neigh_cleanup;
1111
1112         err = register_netdev(netdev);
1113         if (err) {
1114                 pr_warn("Failed to register representor netdev for vport %d\n",
1115                         rep->vport);
1116                 goto err_egdev_cleanup;
1117         }
1118
1119         return 0;
1120
1121 err_egdev_cleanup:
1122         tc_setup_cb_egdev_unregister(netdev, mlx5e_setup_tc_block_cb,
1123                                      upriv);
1124
1125 err_neigh_cleanup:
1126         mlx5e_rep_neigh_cleanup(rpriv);
1127
1128 err_detach_netdev:
1129         mlx5e_detach_netdev(netdev_priv(netdev));
1130
1131 err_destroy_netdev:
1132         mlx5e_destroy_netdev(netdev_priv(netdev));
1133         kfree(rpriv);
1134         return err;
1135 }
1136
1137 static void
1138 mlx5e_vport_rep_unload(struct mlx5_eswitch_rep *rep)
1139 {
1140         struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
1141         struct net_device *netdev = rpriv->netdev;
1142         struct mlx5e_priv *priv = netdev_priv(netdev);
1143         struct mlx5e_rep_priv *uplink_rpriv;
1144         void *ppriv = priv->ppriv;
1145         struct mlx5e_priv *upriv;
1146
1147         unregister_netdev(netdev);
1148         uplink_rpriv = mlx5_eswitch_get_uplink_priv(priv->mdev->priv.eswitch,
1149                                                     REP_ETH);
1150         upriv = netdev_priv(uplink_rpriv->netdev);
1151         tc_setup_cb_egdev_unregister(netdev, mlx5e_setup_tc_block_cb,
1152                                      upriv);
1153         mlx5e_rep_neigh_cleanup(rpriv);
1154         mlx5e_detach_netdev(priv);
1155         mlx5e_destroy_netdev(priv);
1156         kfree(ppriv); /* mlx5e_rep_priv */
1157 }
1158
1159 static void mlx5e_rep_register_vf_vports(struct mlx5e_priv *priv)
1160 {
1161         struct mlx5_core_dev *mdev = priv->mdev;
1162         struct mlx5_eswitch *esw   = mdev->priv.eswitch;
1163         int total_vfs = MLX5_TOTAL_VPORTS(mdev);
1164         int vport;
1165
1166         for (vport = 1; vport < total_vfs; vport++) {
1167                 struct mlx5_eswitch_rep_if rep_if = {};
1168
1169                 rep_if.load = mlx5e_vport_rep_load;
1170                 rep_if.unload = mlx5e_vport_rep_unload;
1171                 mlx5_eswitch_register_vport_rep(esw, vport, &rep_if, REP_ETH);
1172         }
1173 }
1174
1175 static void mlx5e_rep_unregister_vf_vports(struct mlx5e_priv *priv)
1176 {
1177         struct mlx5_core_dev *mdev = priv->mdev;
1178         struct mlx5_eswitch *esw = mdev->priv.eswitch;
1179         int total_vfs = MLX5_TOTAL_VPORTS(mdev);
1180         int vport;
1181
1182         for (vport = 1; vport < total_vfs; vport++)
1183                 mlx5_eswitch_unregister_vport_rep(esw, vport, REP_ETH);
1184 }
1185
1186 void mlx5e_register_vport_reps(struct mlx5e_priv *priv)
1187 {
1188         struct mlx5_core_dev *mdev = priv->mdev;
1189         struct mlx5_eswitch *esw   = mdev->priv.eswitch;
1190         struct mlx5_eswitch_rep_if rep_if;
1191         struct mlx5e_rep_priv *rpriv;
1192
1193         rpriv = priv->ppriv;
1194         rpriv->netdev = priv->netdev;
1195
1196         rep_if.load = mlx5e_nic_rep_load;
1197         rep_if.unload = mlx5e_nic_rep_unload;
1198         rep_if.priv = rpriv;
1199         INIT_LIST_HEAD(&rpriv->vport_sqs_list);
1200         mlx5_eswitch_register_vport_rep(esw, 0, &rep_if, REP_ETH); /* UPLINK PF vport*/
1201
1202         mlx5e_rep_register_vf_vports(priv); /* VFs vports */
1203 }
1204
1205 void mlx5e_unregister_vport_reps(struct mlx5e_priv *priv)
1206 {
1207         struct mlx5_core_dev *mdev = priv->mdev;
1208         struct mlx5_eswitch *esw   = mdev->priv.eswitch;
1209
1210         mlx5e_rep_unregister_vf_vports(priv); /* VFs vports */
1211         mlx5_eswitch_unregister_vport_rep(esw, 0, REP_ETH); /* UPLINK PF*/
1212 }
1213
1214 void *mlx5e_alloc_nic_rep_priv(struct mlx5_core_dev *mdev)
1215 {
1216         struct mlx5_eswitch *esw = mdev->priv.eswitch;
1217         struct mlx5e_rep_priv *rpriv;
1218
1219         rpriv = kzalloc(sizeof(*rpriv), GFP_KERNEL);
1220         if (!rpriv)
1221                 return NULL;
1222
1223         rpriv->rep = &esw->offloads.vport_reps[0];
1224         return rpriv;
1225 }