1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2 /* Copyright (C) 2017-2018 Netronome Systems, Inc. */
4 #include <linux/etherdevice.h>
5 #include <linux/inetdevice.h>
6 #include <net/netevent.h>
8 #include <net/dst_metadata.h>
13 #include "../nfp_net_repr.h"
14 #include "../nfp_net.h"
16 #define NFP_FL_MAX_ROUTES 32
19 * struct nfp_tun_active_tuns - periodic message of active tunnels
20 * @seq: sequence number of the message
21 * @count: number of tunnels report in message
22 * @flags: options part of the request
23 * @tun_info.ipv4: dest IPv4 address of active route
24 * @tun_info.egress_port: port the encapsulated packet egressed
25 * @tun_info.extra: reserved for future use
26 * @tun_info: tunnels that have sent traffic in reported period
28 struct nfp_tun_active_tuns {
32 struct route_ip_info {
40 * struct nfp_tun_neigh - neighbour/route entry on the NFP
41 * @dst_ipv4: destination IPv4 address
42 * @src_ipv4: source IPv4 address
43 * @dst_addr: destination MAC address
44 * @src_addr: source MAC address
45 * @port_id: NFP port to output packet on - associated with source IPv4
47 struct nfp_tun_neigh {
50 u8 dst_addr[ETH_ALEN];
51 u8 src_addr[ETH_ALEN];
56 * struct nfp_tun_req_route_ipv4 - NFP requests a route/neighbour lookup
57 * @ingress_port: ingress port of packet that signalled request
58 * @ipv4_addr: destination ipv4 address for route
59 * @reserved: reserved for future use
61 struct nfp_tun_req_route_ipv4 {
68 * struct nfp_ipv4_route_entry - routes that are offloaded to the NFP
69 * @ipv4_addr: destination of route
72 struct nfp_ipv4_route_entry {
74 struct list_head list;
77 #define NFP_FL_IPV4_ADDRS_MAX 32
80 * struct nfp_tun_ipv4_addr - set the IP address list on the NFP
81 * @count: number of IPs populated in the array
82 * @ipv4_addr: array of IPV4_ADDRS_MAX 32 bit IPv4 addresses
84 struct nfp_tun_ipv4_addr {
86 __be32 ipv4_addr[NFP_FL_IPV4_ADDRS_MAX];
90 * struct nfp_ipv4_addr_entry - cached IPv4 addresses
91 * @ipv4_addr: IP address
92 * @ref_count: number of rules currently using this IP
95 struct nfp_ipv4_addr_entry {
98 struct list_head list;
101 #define NFP_TUN_MAC_OFFLOAD_DEL_FLAG 0x2
104 * struct nfp_tun_mac_addr_offload - configure MAC address of tunnel EP on NFP
105 * @flags: MAC address offload options
106 * @count: number of MAC addresses in the message (should be 1)
107 * @index: index of MAC address in the lookup table
108 * @addr: interface MAC address
110 struct nfp_tun_mac_addr_offload {
117 enum nfp_flower_mac_offload_cmd {
118 NFP_TUNNEL_MAC_OFFLOAD_ADD = 0,
119 NFP_TUNNEL_MAC_OFFLOAD_DEL = 1,
120 NFP_TUNNEL_MAC_OFFLOAD_MOD = 2,
123 #define NFP_MAX_MAC_INDEX 0xff
126 * struct nfp_tun_offloaded_mac - hashtable entry for an offloaded MAC
127 * @ht_node: Hashtable entry
128 * @addr: Offloaded MAC address
129 * @index: Offloaded index for given MAC address
130 * @ref_count: Number of devs using this MAC address
131 * @repr_list: List of reprs sharing this MAC address
133 struct nfp_tun_offloaded_mac {
134 struct rhash_head ht_node;
138 struct list_head repr_list;
141 static const struct rhashtable_params offloaded_macs_params = {
142 .key_offset = offsetof(struct nfp_tun_offloaded_mac, addr),
143 .head_offset = offsetof(struct nfp_tun_offloaded_mac, ht_node),
145 .automatic_shrinking = true,
148 void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb)
150 struct nfp_tun_active_tuns *payload;
151 struct net_device *netdev;
152 int count, i, pay_len;
157 payload = nfp_flower_cmsg_get_data(skb);
158 count = be32_to_cpu(payload->count);
159 if (count > NFP_FL_MAX_ROUTES) {
160 nfp_flower_cmsg_warn(app, "Tunnel keep-alive request exceeds max routes.\n");
164 pay_len = nfp_flower_cmsg_get_data_len(skb);
165 if (pay_len != struct_size(payload, tun_info, count)) {
166 nfp_flower_cmsg_warn(app, "Corruption in tunnel keep-alive message.\n");
171 for (i = 0; i < count; i++) {
172 ipv4_addr = payload->tun_info[i].ipv4;
173 port = be32_to_cpu(payload->tun_info[i].egress_port);
174 netdev = nfp_app_dev_get(app, port, NULL);
178 n = neigh_lookup(&arp_tbl, &ipv4_addr, netdev);
182 /* Update the used timestamp of neighbour */
183 neigh_event_send(n, NULL);
190 nfp_flower_xmit_tun_conf(struct nfp_app *app, u8 mtype, u16 plen, void *pdata,
196 skb = nfp_flower_cmsg_alloc(app, plen, mtype, flag);
200 msg = nfp_flower_cmsg_get_data(skb);
201 memcpy(msg, pdata, nfp_flower_cmsg_get_data_len(skb));
203 nfp_ctrl_tx(app->ctrl, skb);
207 static bool nfp_tun_has_route(struct nfp_app *app, __be32 ipv4_addr)
209 struct nfp_flower_priv *priv = app->priv;
210 struct nfp_ipv4_route_entry *entry;
211 struct list_head *ptr, *storage;
213 spin_lock_bh(&priv->tun.neigh_off_lock);
214 list_for_each_safe(ptr, storage, &priv->tun.neigh_off_list) {
215 entry = list_entry(ptr, struct nfp_ipv4_route_entry, list);
216 if (entry->ipv4_addr == ipv4_addr) {
217 spin_unlock_bh(&priv->tun.neigh_off_lock);
221 spin_unlock_bh(&priv->tun.neigh_off_lock);
225 static void nfp_tun_add_route_to_cache(struct nfp_app *app, __be32 ipv4_addr)
227 struct nfp_flower_priv *priv = app->priv;
228 struct nfp_ipv4_route_entry *entry;
229 struct list_head *ptr, *storage;
231 spin_lock_bh(&priv->tun.neigh_off_lock);
232 list_for_each_safe(ptr, storage, &priv->tun.neigh_off_list) {
233 entry = list_entry(ptr, struct nfp_ipv4_route_entry, list);
234 if (entry->ipv4_addr == ipv4_addr) {
235 spin_unlock_bh(&priv->tun.neigh_off_lock);
239 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
241 spin_unlock_bh(&priv->tun.neigh_off_lock);
242 nfp_flower_cmsg_warn(app, "Mem error when storing new route.\n");
246 entry->ipv4_addr = ipv4_addr;
247 list_add_tail(&entry->list, &priv->tun.neigh_off_list);
248 spin_unlock_bh(&priv->tun.neigh_off_lock);
251 static void nfp_tun_del_route_from_cache(struct nfp_app *app, __be32 ipv4_addr)
253 struct nfp_flower_priv *priv = app->priv;
254 struct nfp_ipv4_route_entry *entry;
255 struct list_head *ptr, *storage;
257 spin_lock_bh(&priv->tun.neigh_off_lock);
258 list_for_each_safe(ptr, storage, &priv->tun.neigh_off_list) {
259 entry = list_entry(ptr, struct nfp_ipv4_route_entry, list);
260 if (entry->ipv4_addr == ipv4_addr) {
261 list_del(&entry->list);
266 spin_unlock_bh(&priv->tun.neigh_off_lock);
270 nfp_tun_write_neigh(struct net_device *netdev, struct nfp_app *app,
271 struct flowi4 *flow, struct neighbour *neigh, gfp_t flag)
273 struct nfp_tun_neigh payload;
276 port_id = nfp_flower_get_port_id_from_netdev(app, netdev);
280 memset(&payload, 0, sizeof(struct nfp_tun_neigh));
281 payload.dst_ipv4 = flow->daddr;
283 /* If entry has expired send dst IP with all other fields 0. */
284 if (!(neigh->nud_state & NUD_VALID) || neigh->dead) {
285 nfp_tun_del_route_from_cache(app, payload.dst_ipv4);
286 /* Trigger ARP to verify invalid neighbour state. */
287 neigh_event_send(neigh, NULL);
291 /* Have a valid neighbour so populate rest of entry. */
292 payload.src_ipv4 = flow->saddr;
293 ether_addr_copy(payload.src_addr, netdev->dev_addr);
294 neigh_ha_snapshot(payload.dst_addr, neigh, netdev);
295 payload.port_id = cpu_to_be32(port_id);
296 /* Add destination of new route to NFP cache. */
297 nfp_tun_add_route_to_cache(app, payload.dst_ipv4);
300 nfp_flower_xmit_tun_conf(app, NFP_FLOWER_CMSG_TYPE_TUN_NEIGH,
301 sizeof(struct nfp_tun_neigh),
302 (unsigned char *)&payload, flag);
306 nfp_tun_neigh_event_handler(struct notifier_block *nb, unsigned long event,
309 struct nfp_flower_priv *app_priv;
310 struct netevent_redirect *redir;
311 struct flowi4 flow = {};
318 case NETEVENT_REDIRECT:
319 redir = (struct netevent_redirect *)ptr;
322 case NETEVENT_NEIGH_UPDATE:
323 n = (struct neighbour *)ptr;
329 flow.daddr = *(__be32 *)n->primary_key;
331 /* Only concerned with route changes for representors. */
332 if (!nfp_netdev_is_nfp_repr(n->dev))
335 app_priv = container_of(nb, struct nfp_flower_priv, tun.neigh_nb);
338 /* Only concerned with changes to routes already added to NFP. */
339 if (!nfp_tun_has_route(app, flow.daddr))
342 #if IS_ENABLED(CONFIG_INET)
343 /* Do a route lookup to populate flow data. */
344 rt = ip_route_output_key(dev_net(n->dev), &flow);
345 err = PTR_ERR_OR_ZERO(rt);
354 flow.flowi4_proto = IPPROTO_UDP;
355 nfp_tun_write_neigh(n->dev, app, &flow, n, GFP_ATOMIC);
360 void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb)
362 struct nfp_tun_req_route_ipv4 *payload;
363 struct net_device *netdev;
364 struct flowi4 flow = {};
369 payload = nfp_flower_cmsg_get_data(skb);
372 netdev = nfp_app_dev_get(app, be32_to_cpu(payload->ingress_port), NULL);
374 goto fail_rcu_unlock;
376 flow.daddr = payload->ipv4_addr;
377 flow.flowi4_proto = IPPROTO_UDP;
379 #if IS_ENABLED(CONFIG_INET)
380 /* Do a route lookup on same namespace as ingress port. */
381 rt = ip_route_output_key(dev_net(netdev), &flow);
382 err = PTR_ERR_OR_ZERO(rt);
384 goto fail_rcu_unlock;
386 goto fail_rcu_unlock;
389 /* Get the neighbour entry for the lookup */
390 n = dst_neigh_lookup(&rt->dst, &flow.daddr);
393 goto fail_rcu_unlock;
394 nfp_tun_write_neigh(n->dev, app, &flow, n, GFP_ATOMIC);
401 nfp_flower_cmsg_warn(app, "Requested route not found.\n");
404 static void nfp_tun_write_ipv4_list(struct nfp_app *app)
406 struct nfp_flower_priv *priv = app->priv;
407 struct nfp_ipv4_addr_entry *entry;
408 struct nfp_tun_ipv4_addr payload;
409 struct list_head *ptr, *storage;
412 memset(&payload, 0, sizeof(struct nfp_tun_ipv4_addr));
413 mutex_lock(&priv->tun.ipv4_off_lock);
415 list_for_each_safe(ptr, storage, &priv->tun.ipv4_off_list) {
416 if (count >= NFP_FL_IPV4_ADDRS_MAX) {
417 mutex_unlock(&priv->tun.ipv4_off_lock);
418 nfp_flower_cmsg_warn(app, "IPv4 offload exceeds limit.\n");
421 entry = list_entry(ptr, struct nfp_ipv4_addr_entry, list);
422 payload.ipv4_addr[count++] = entry->ipv4_addr;
424 payload.count = cpu_to_be32(count);
425 mutex_unlock(&priv->tun.ipv4_off_lock);
427 nfp_flower_xmit_tun_conf(app, NFP_FLOWER_CMSG_TYPE_TUN_IPS,
428 sizeof(struct nfp_tun_ipv4_addr),
429 &payload, GFP_KERNEL);
432 void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4)
434 struct nfp_flower_priv *priv = app->priv;
435 struct nfp_ipv4_addr_entry *entry;
436 struct list_head *ptr, *storage;
438 mutex_lock(&priv->tun.ipv4_off_lock);
439 list_for_each_safe(ptr, storage, &priv->tun.ipv4_off_list) {
440 entry = list_entry(ptr, struct nfp_ipv4_addr_entry, list);
441 if (entry->ipv4_addr == ipv4) {
443 mutex_unlock(&priv->tun.ipv4_off_lock);
448 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
450 mutex_unlock(&priv->tun.ipv4_off_lock);
451 nfp_flower_cmsg_warn(app, "Mem error when offloading IP address.\n");
454 entry->ipv4_addr = ipv4;
455 entry->ref_count = 1;
456 list_add_tail(&entry->list, &priv->tun.ipv4_off_list);
457 mutex_unlock(&priv->tun.ipv4_off_lock);
459 nfp_tun_write_ipv4_list(app);
462 void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4)
464 struct nfp_flower_priv *priv = app->priv;
465 struct nfp_ipv4_addr_entry *entry;
466 struct list_head *ptr, *storage;
468 mutex_lock(&priv->tun.ipv4_off_lock);
469 list_for_each_safe(ptr, storage, &priv->tun.ipv4_off_list) {
470 entry = list_entry(ptr, struct nfp_ipv4_addr_entry, list);
471 if (entry->ipv4_addr == ipv4) {
473 if (!entry->ref_count) {
474 list_del(&entry->list);
480 mutex_unlock(&priv->tun.ipv4_off_lock);
482 nfp_tun_write_ipv4_list(app);
486 __nfp_tunnel_offload_mac(struct nfp_app *app, u8 *mac, u16 idx, bool del)
488 struct nfp_tun_mac_addr_offload payload;
490 memset(&payload, 0, sizeof(payload));
493 payload.flags = cpu_to_be16(NFP_TUN_MAC_OFFLOAD_DEL_FLAG);
495 /* FW supports multiple MACs per cmsg but restrict to single. */
496 payload.count = cpu_to_be16(1);
497 payload.index = cpu_to_be16(idx);
498 ether_addr_copy(payload.addr, mac);
500 return nfp_flower_xmit_tun_conf(app, NFP_FLOWER_CMSG_TYPE_TUN_MAC,
501 sizeof(struct nfp_tun_mac_addr_offload),
502 &payload, GFP_KERNEL);
505 static bool nfp_tunnel_port_is_phy_repr(int port)
507 if (FIELD_GET(NFP_FLOWER_CMSG_PORT_TYPE, port) ==
508 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT)
514 static u16 nfp_tunnel_get_mac_idx_from_phy_port_id(int port)
516 return port << 8 | NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT;
519 static u16 nfp_tunnel_get_global_mac_idx_from_ida(int id)
521 return id << 8 | NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT;
524 static int nfp_tunnel_get_ida_from_global_mac_idx(u16 nfp_mac_idx)
526 return nfp_mac_idx >> 8;
529 static bool nfp_tunnel_is_mac_idx_global(u16 nfp_mac_idx)
531 return (nfp_mac_idx & 0xff) == NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT;
534 static struct nfp_tun_offloaded_mac *
535 nfp_tunnel_lookup_offloaded_macs(struct nfp_app *app, u8 *mac)
537 struct nfp_flower_priv *priv = app->priv;
539 return rhashtable_lookup_fast(&priv->tun.offloaded_macs, mac,
540 offloaded_macs_params);
544 nfp_tunnel_offloaded_macs_inc_ref_and_link(struct nfp_tun_offloaded_mac *entry,
545 struct net_device *netdev, bool mod)
547 if (nfp_netdev_is_nfp_repr(netdev)) {
548 struct nfp_flower_repr_priv *repr_priv;
549 struct nfp_repr *repr;
551 repr = netdev_priv(netdev);
552 repr_priv = repr->app_priv;
554 /* If modifing MAC, remove repr from old list first. */
556 list_del(&repr_priv->mac_list);
558 list_add_tail(&repr_priv->mac_list, &entry->repr_list);
565 nfp_tunnel_add_shared_mac(struct nfp_app *app, struct net_device *netdev,
568 struct nfp_flower_priv *priv = app->priv;
569 int ida_idx = NFP_MAX_MAC_INDEX, err;
570 struct nfp_tun_offloaded_mac *entry;
573 entry = nfp_tunnel_lookup_offloaded_macs(app, netdev->dev_addr);
574 if (entry && nfp_tunnel_is_mac_idx_global(entry->index)) {
575 nfp_tunnel_offloaded_macs_inc_ref_and_link(entry, netdev, mod);
579 /* Assign a global index if non-repr or MAC address is now shared. */
580 if (entry || !port) {
581 ida_idx = ida_simple_get(&priv->tun.mac_off_ids, 0,
582 NFP_MAX_MAC_INDEX, GFP_KERNEL);
586 nfp_mac_idx = nfp_tunnel_get_global_mac_idx_from_ida(ida_idx);
588 nfp_mac_idx = nfp_tunnel_get_mac_idx_from_phy_port_id(port);
592 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
598 ether_addr_copy(entry->addr, netdev->dev_addr);
599 INIT_LIST_HEAD(&entry->repr_list);
601 if (rhashtable_insert_fast(&priv->tun.offloaded_macs,
603 offloaded_macs_params)) {
609 err = __nfp_tunnel_offload_mac(app, netdev->dev_addr,
612 /* If not shared then free. */
613 if (!entry->ref_count)
614 goto err_remove_hash;
618 entry->index = nfp_mac_idx;
619 nfp_tunnel_offloaded_macs_inc_ref_and_link(entry, netdev, mod);
624 rhashtable_remove_fast(&priv->tun.offloaded_macs, &entry->ht_node,
625 offloaded_macs_params);
629 if (ida_idx != NFP_MAX_MAC_INDEX)
630 ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
636 nfp_tunnel_del_shared_mac(struct nfp_app *app, struct net_device *netdev,
639 struct nfp_flower_priv *priv = app->priv;
640 struct nfp_flower_repr_priv *repr_priv;
641 struct nfp_tun_offloaded_mac *entry;
642 struct nfp_repr *repr;
645 entry = nfp_tunnel_lookup_offloaded_macs(app, mac);
650 /* If del is part of a mod then mac_list is still in use elsewheree. */
651 if (nfp_netdev_is_nfp_repr(netdev) && !mod) {
652 repr = netdev_priv(netdev);
653 repr_priv = repr->app_priv;
654 list_del(&repr_priv->mac_list);
657 /* If MAC is now used by 1 repr set the offloaded MAC index to port. */
658 if (entry->ref_count == 1 && list_is_singular(&entry->repr_list)) {
662 repr_priv = list_first_entry(&entry->repr_list,
663 struct nfp_flower_repr_priv,
665 repr = repr_priv->nfp_repr;
666 port = nfp_repr_get_port_id(repr->netdev);
667 nfp_mac_idx = nfp_tunnel_get_mac_idx_from_phy_port_id(port);
668 err = __nfp_tunnel_offload_mac(app, mac, nfp_mac_idx, false);
670 nfp_flower_cmsg_warn(app, "MAC offload index revert failed on %s.\n",
671 netdev_name(netdev));
675 ida_idx = nfp_tunnel_get_ida_from_global_mac_idx(entry->index);
676 ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
677 entry->index = nfp_mac_idx;
681 if (entry->ref_count)
684 WARN_ON_ONCE(rhashtable_remove_fast(&priv->tun.offloaded_macs,
686 offloaded_macs_params));
687 /* If MAC has global ID then extract and free the ida entry. */
688 if (nfp_tunnel_is_mac_idx_global(entry->index)) {
689 ida_idx = nfp_tunnel_get_ida_from_global_mac_idx(entry->index);
690 ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
695 return __nfp_tunnel_offload_mac(app, mac, 0, true);
699 nfp_tunnel_offload_mac(struct nfp_app *app, struct net_device *netdev,
700 enum nfp_flower_mac_offload_cmd cmd)
702 struct nfp_flower_non_repr_priv *nr_priv = NULL;
703 bool non_repr = false, *mac_offloaded;
707 if (nfp_netdev_is_nfp_repr(netdev)) {
708 struct nfp_flower_repr_priv *repr_priv;
709 struct nfp_repr *repr;
711 repr = netdev_priv(netdev);
712 if (repr->app != app)
715 repr_priv = repr->app_priv;
716 mac_offloaded = &repr_priv->mac_offloaded;
717 off_mac = &repr_priv->offloaded_mac_addr[0];
718 port = nfp_repr_get_port_id(netdev);
719 if (!nfp_tunnel_port_is_phy_repr(port))
721 } else if (nfp_fl_is_netdev_to_offload(netdev)) {
722 nr_priv = nfp_flower_non_repr_priv_get(app, netdev);
726 mac_offloaded = &nr_priv->mac_offloaded;
727 off_mac = &nr_priv->offloaded_mac_addr[0];
733 if (!is_valid_ether_addr(netdev->dev_addr)) {
735 goto err_put_non_repr_priv;
738 if (cmd == NFP_TUNNEL_MAC_OFFLOAD_MOD && !*mac_offloaded)
739 cmd = NFP_TUNNEL_MAC_OFFLOAD_ADD;
742 case NFP_TUNNEL_MAC_OFFLOAD_ADD:
743 err = nfp_tunnel_add_shared_mac(app, netdev, port, false);
745 goto err_put_non_repr_priv;
748 __nfp_flower_non_repr_priv_get(nr_priv);
750 *mac_offloaded = true;
751 ether_addr_copy(off_mac, netdev->dev_addr);
753 case NFP_TUNNEL_MAC_OFFLOAD_DEL:
754 /* Only attempt delete if add was successful. */
759 __nfp_flower_non_repr_priv_put(nr_priv);
761 *mac_offloaded = false;
763 err = nfp_tunnel_del_shared_mac(app, netdev, netdev->dev_addr,
766 goto err_put_non_repr_priv;
769 case NFP_TUNNEL_MAC_OFFLOAD_MOD:
770 /* Ignore if changing to the same address. */
771 if (ether_addr_equal(netdev->dev_addr, off_mac))
774 err = nfp_tunnel_add_shared_mac(app, netdev, port, true);
776 goto err_put_non_repr_priv;
778 /* Delete the previous MAC address. */
779 err = nfp_tunnel_del_shared_mac(app, netdev, off_mac, true);
781 nfp_flower_cmsg_warn(app, "Failed to remove offload of replaced MAC addr on %s.\n",
782 netdev_name(netdev));
784 ether_addr_copy(off_mac, netdev->dev_addr);
788 goto err_put_non_repr_priv;
792 __nfp_flower_non_repr_priv_put(nr_priv);
796 err_put_non_repr_priv:
798 __nfp_flower_non_repr_priv_put(nr_priv);
803 int nfp_tunnel_mac_event_handler(struct nfp_app *app,
804 struct net_device *netdev,
805 unsigned long event, void *ptr)
809 if (event == NETDEV_DOWN) {
810 err = nfp_tunnel_offload_mac(app, netdev,
811 NFP_TUNNEL_MAC_OFFLOAD_DEL);
813 nfp_flower_cmsg_warn(app, "Failed to delete offload MAC on %s.\n",
814 netdev_name(netdev));
815 } else if (event == NETDEV_UP) {
816 err = nfp_tunnel_offload_mac(app, netdev,
817 NFP_TUNNEL_MAC_OFFLOAD_ADD);
819 nfp_flower_cmsg_warn(app, "Failed to offload MAC on %s.\n",
820 netdev_name(netdev));
821 } else if (event == NETDEV_CHANGEADDR) {
822 /* Only offload addr change if netdev is already up. */
823 if (!(netdev->flags & IFF_UP))
826 err = nfp_tunnel_offload_mac(app, netdev,
827 NFP_TUNNEL_MAC_OFFLOAD_MOD);
829 nfp_flower_cmsg_warn(app, "Failed to offload MAC change on %s.\n",
830 netdev_name(netdev));
835 int nfp_tunnel_config_start(struct nfp_app *app)
837 struct nfp_flower_priv *priv = app->priv;
840 /* Initialise rhash for MAC offload tracking. */
841 err = rhashtable_init(&priv->tun.offloaded_macs,
842 &offloaded_macs_params);
846 ida_init(&priv->tun.mac_off_ids);
848 /* Initialise priv data for IPv4 offloading. */
849 mutex_init(&priv->tun.ipv4_off_lock);
850 INIT_LIST_HEAD(&priv->tun.ipv4_off_list);
852 /* Initialise priv data for neighbour offloading. */
853 spin_lock_init(&priv->tun.neigh_off_lock);
854 INIT_LIST_HEAD(&priv->tun.neigh_off_list);
855 priv->tun.neigh_nb.notifier_call = nfp_tun_neigh_event_handler;
857 err = register_netevent_notifier(&priv->tun.neigh_nb);
859 rhashtable_free_and_destroy(&priv->tun.offloaded_macs,
860 nfp_check_rhashtable_empty, NULL);
867 void nfp_tunnel_config_stop(struct nfp_app *app)
869 struct nfp_flower_priv *priv = app->priv;
870 struct nfp_ipv4_route_entry *route_entry;
871 struct nfp_ipv4_addr_entry *ip_entry;
872 struct list_head *ptr, *storage;
874 unregister_netevent_notifier(&priv->tun.neigh_nb);
876 ida_destroy(&priv->tun.mac_off_ids);
878 /* Free any memory that may be occupied by ipv4 list. */
879 list_for_each_safe(ptr, storage, &priv->tun.ipv4_off_list) {
880 ip_entry = list_entry(ptr, struct nfp_ipv4_addr_entry, list);
881 list_del(&ip_entry->list);
885 /* Free any memory that may be occupied by the route list. */
886 list_for_each_safe(ptr, storage, &priv->tun.neigh_off_list) {
887 route_entry = list_entry(ptr, struct nfp_ipv4_route_entry,
889 list_del(&route_entry->list);
893 /* Destroy rhash. Entries should be cleaned on netdev notifier unreg. */
894 rhashtable_free_and_destroy(&priv->tun.offloaded_macs,
895 nfp_check_rhashtable_empty, NULL);