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 != sizeof(struct nfp_tun_active_tuns) +
166 sizeof(struct route_ip_info) * count) {
167 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_repr_get(app, port);
178 n = neigh_lookup(&arp_tbl, &ipv4_addr, netdev);
182 /* Update the used timestamp of neighbour */
183 neigh_event_send(n, NULL);
189 nfp_flower_xmit_tun_conf(struct nfp_app *app, u8 mtype, u16 plen, void *pdata,
195 skb = nfp_flower_cmsg_alloc(app, plen, mtype, flag);
199 msg = nfp_flower_cmsg_get_data(skb);
200 memcpy(msg, pdata, nfp_flower_cmsg_get_data_len(skb));
202 nfp_ctrl_tx(app->ctrl, skb);
206 static bool nfp_tun_has_route(struct nfp_app *app, __be32 ipv4_addr)
208 struct nfp_flower_priv *priv = app->priv;
209 struct nfp_ipv4_route_entry *entry;
210 struct list_head *ptr, *storage;
212 spin_lock_bh(&priv->tun.neigh_off_lock);
213 list_for_each_safe(ptr, storage, &priv->tun.neigh_off_list) {
214 entry = list_entry(ptr, struct nfp_ipv4_route_entry, list);
215 if (entry->ipv4_addr == ipv4_addr) {
216 spin_unlock_bh(&priv->tun.neigh_off_lock);
220 spin_unlock_bh(&priv->tun.neigh_off_lock);
224 static void nfp_tun_add_route_to_cache(struct nfp_app *app, __be32 ipv4_addr)
226 struct nfp_flower_priv *priv = app->priv;
227 struct nfp_ipv4_route_entry *entry;
228 struct list_head *ptr, *storage;
230 spin_lock_bh(&priv->tun.neigh_off_lock);
231 list_for_each_safe(ptr, storage, &priv->tun.neigh_off_list) {
232 entry = list_entry(ptr, struct nfp_ipv4_route_entry, list);
233 if (entry->ipv4_addr == ipv4_addr) {
234 spin_unlock_bh(&priv->tun.neigh_off_lock);
238 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
240 spin_unlock_bh(&priv->tun.neigh_off_lock);
241 nfp_flower_cmsg_warn(app, "Mem error when storing new route.\n");
245 entry->ipv4_addr = ipv4_addr;
246 list_add_tail(&entry->list, &priv->tun.neigh_off_list);
247 spin_unlock_bh(&priv->tun.neigh_off_lock);
250 static void nfp_tun_del_route_from_cache(struct nfp_app *app, __be32 ipv4_addr)
252 struct nfp_flower_priv *priv = app->priv;
253 struct nfp_ipv4_route_entry *entry;
254 struct list_head *ptr, *storage;
256 spin_lock_bh(&priv->tun.neigh_off_lock);
257 list_for_each_safe(ptr, storage, &priv->tun.neigh_off_list) {
258 entry = list_entry(ptr, struct nfp_ipv4_route_entry, list);
259 if (entry->ipv4_addr == ipv4_addr) {
260 list_del(&entry->list);
265 spin_unlock_bh(&priv->tun.neigh_off_lock);
269 nfp_tun_write_neigh(struct net_device *netdev, struct nfp_app *app,
270 struct flowi4 *flow, struct neighbour *neigh, gfp_t flag)
272 struct nfp_tun_neigh payload;
274 /* Only offload representor IPv4s for now. */
275 if (!nfp_netdev_is_nfp_repr(netdev))
278 memset(&payload, 0, sizeof(struct nfp_tun_neigh));
279 payload.dst_ipv4 = flow->daddr;
281 /* If entry has expired send dst IP with all other fields 0. */
282 if (!(neigh->nud_state & NUD_VALID) || neigh->dead) {
283 nfp_tun_del_route_from_cache(app, payload.dst_ipv4);
284 /* Trigger ARP to verify invalid neighbour state. */
285 neigh_event_send(neigh, NULL);
289 /* Have a valid neighbour so populate rest of entry. */
290 payload.src_ipv4 = flow->saddr;
291 ether_addr_copy(payload.src_addr, netdev->dev_addr);
292 neigh_ha_snapshot(payload.dst_addr, neigh, netdev);
293 payload.port_id = cpu_to_be32(nfp_repr_get_port_id(netdev));
294 /* Add destination of new route to NFP cache. */
295 nfp_tun_add_route_to_cache(app, payload.dst_ipv4);
298 nfp_flower_xmit_tun_conf(app, NFP_FLOWER_CMSG_TYPE_TUN_NEIGH,
299 sizeof(struct nfp_tun_neigh),
300 (unsigned char *)&payload, flag);
304 nfp_tun_neigh_event_handler(struct notifier_block *nb, unsigned long event,
307 struct nfp_flower_priv *app_priv;
308 struct netevent_redirect *redir;
309 struct flowi4 flow = {};
316 case NETEVENT_REDIRECT:
317 redir = (struct netevent_redirect *)ptr;
320 case NETEVENT_NEIGH_UPDATE:
321 n = (struct neighbour *)ptr;
327 flow.daddr = *(__be32 *)n->primary_key;
329 /* Only concerned with route changes for representors. */
330 if (!nfp_netdev_is_nfp_repr(n->dev))
333 app_priv = container_of(nb, struct nfp_flower_priv, tun.neigh_nb);
336 /* Only concerned with changes to routes already added to NFP. */
337 if (!nfp_tun_has_route(app, flow.daddr))
340 #if IS_ENABLED(CONFIG_INET)
341 /* Do a route lookup to populate flow data. */
342 rt = ip_route_output_key(dev_net(n->dev), &flow);
343 err = PTR_ERR_OR_ZERO(rt);
352 flow.flowi4_proto = IPPROTO_UDP;
353 nfp_tun_write_neigh(n->dev, app, &flow, n, GFP_ATOMIC);
358 void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb)
360 struct nfp_tun_req_route_ipv4 *payload;
361 struct net_device *netdev;
362 struct flowi4 flow = {};
367 payload = nfp_flower_cmsg_get_data(skb);
369 netdev = nfp_app_repr_get(app, be32_to_cpu(payload->ingress_port));
371 goto route_fail_warning;
373 flow.daddr = payload->ipv4_addr;
374 flow.flowi4_proto = IPPROTO_UDP;
376 #if IS_ENABLED(CONFIG_INET)
377 /* Do a route lookup on same namespace as ingress port. */
378 rt = ip_route_output_key(dev_net(netdev), &flow);
379 err = PTR_ERR_OR_ZERO(rt);
381 goto route_fail_warning;
383 goto route_fail_warning;
386 /* Get the neighbour entry for the lookup */
387 n = dst_neigh_lookup(&rt->dst, &flow.daddr);
390 goto route_fail_warning;
391 nfp_tun_write_neigh(n->dev, app, &flow, n, GFP_KERNEL);
396 nfp_flower_cmsg_warn(app, "Requested route not found.\n");
399 static void nfp_tun_write_ipv4_list(struct nfp_app *app)
401 struct nfp_flower_priv *priv = app->priv;
402 struct nfp_ipv4_addr_entry *entry;
403 struct nfp_tun_ipv4_addr payload;
404 struct list_head *ptr, *storage;
407 memset(&payload, 0, sizeof(struct nfp_tun_ipv4_addr));
408 mutex_lock(&priv->tun.ipv4_off_lock);
410 list_for_each_safe(ptr, storage, &priv->tun.ipv4_off_list) {
411 if (count >= NFP_FL_IPV4_ADDRS_MAX) {
412 mutex_unlock(&priv->tun.ipv4_off_lock);
413 nfp_flower_cmsg_warn(app, "IPv4 offload exceeds limit.\n");
416 entry = list_entry(ptr, struct nfp_ipv4_addr_entry, list);
417 payload.ipv4_addr[count++] = entry->ipv4_addr;
419 payload.count = cpu_to_be32(count);
420 mutex_unlock(&priv->tun.ipv4_off_lock);
422 nfp_flower_xmit_tun_conf(app, NFP_FLOWER_CMSG_TYPE_TUN_IPS,
423 sizeof(struct nfp_tun_ipv4_addr),
424 &payload, GFP_KERNEL);
427 void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4)
429 struct nfp_flower_priv *priv = app->priv;
430 struct nfp_ipv4_addr_entry *entry;
431 struct list_head *ptr, *storage;
433 mutex_lock(&priv->tun.ipv4_off_lock);
434 list_for_each_safe(ptr, storage, &priv->tun.ipv4_off_list) {
435 entry = list_entry(ptr, struct nfp_ipv4_addr_entry, list);
436 if (entry->ipv4_addr == ipv4) {
438 mutex_unlock(&priv->tun.ipv4_off_lock);
443 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
445 mutex_unlock(&priv->tun.ipv4_off_lock);
446 nfp_flower_cmsg_warn(app, "Mem error when offloading IP address.\n");
449 entry->ipv4_addr = ipv4;
450 entry->ref_count = 1;
451 list_add_tail(&entry->list, &priv->tun.ipv4_off_list);
452 mutex_unlock(&priv->tun.ipv4_off_lock);
454 nfp_tun_write_ipv4_list(app);
457 void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4)
459 struct nfp_flower_priv *priv = app->priv;
460 struct nfp_ipv4_addr_entry *entry;
461 struct list_head *ptr, *storage;
463 mutex_lock(&priv->tun.ipv4_off_lock);
464 list_for_each_safe(ptr, storage, &priv->tun.ipv4_off_list) {
465 entry = list_entry(ptr, struct nfp_ipv4_addr_entry, list);
466 if (entry->ipv4_addr == ipv4) {
468 if (!entry->ref_count) {
469 list_del(&entry->list);
475 mutex_unlock(&priv->tun.ipv4_off_lock);
477 nfp_tun_write_ipv4_list(app);
481 __nfp_tunnel_offload_mac(struct nfp_app *app, u8 *mac, u16 idx, bool del)
483 struct nfp_tun_mac_addr_offload payload;
485 memset(&payload, 0, sizeof(payload));
488 payload.flags = cpu_to_be16(NFP_TUN_MAC_OFFLOAD_DEL_FLAG);
490 /* FW supports multiple MACs per cmsg but restrict to single. */
491 payload.count = cpu_to_be16(1);
492 payload.index = cpu_to_be16(idx);
493 ether_addr_copy(payload.addr, mac);
495 return nfp_flower_xmit_tun_conf(app, NFP_FLOWER_CMSG_TYPE_TUN_MAC,
496 sizeof(struct nfp_tun_mac_addr_offload),
497 &payload, GFP_KERNEL);
500 static bool nfp_tunnel_port_is_phy_repr(int port)
502 if (FIELD_GET(NFP_FLOWER_CMSG_PORT_TYPE, port) ==
503 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT)
509 static u16 nfp_tunnel_get_mac_idx_from_phy_port_id(int port)
511 return port << 8 | NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT;
514 static u16 nfp_tunnel_get_global_mac_idx_from_ida(int id)
516 return id << 8 | NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT;
519 static int nfp_tunnel_get_ida_from_global_mac_idx(u16 nfp_mac_idx)
521 return nfp_mac_idx >> 8;
524 static bool nfp_tunnel_is_mac_idx_global(u16 nfp_mac_idx)
526 return (nfp_mac_idx & 0xff) == NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT;
529 static struct nfp_tun_offloaded_mac *
530 nfp_tunnel_lookup_offloaded_macs(struct nfp_app *app, u8 *mac)
532 struct nfp_flower_priv *priv = app->priv;
534 return rhashtable_lookup_fast(&priv->tun.offloaded_macs, mac,
535 offloaded_macs_params);
539 nfp_tunnel_offloaded_macs_inc_ref_and_link(struct nfp_tun_offloaded_mac *entry,
540 struct net_device *netdev, bool mod)
542 if (nfp_netdev_is_nfp_repr(netdev)) {
543 struct nfp_flower_repr_priv *repr_priv;
544 struct nfp_repr *repr;
546 repr = netdev_priv(netdev);
547 repr_priv = repr->app_priv;
549 /* If modifing MAC, remove repr from old list first. */
551 list_del(&repr_priv->mac_list);
553 list_add_tail(&repr_priv->mac_list, &entry->repr_list);
560 nfp_tunnel_add_shared_mac(struct nfp_app *app, struct net_device *netdev,
563 struct nfp_flower_priv *priv = app->priv;
564 int ida_idx = NFP_MAX_MAC_INDEX, err;
565 struct nfp_tun_offloaded_mac *entry;
568 entry = nfp_tunnel_lookup_offloaded_macs(app, netdev->dev_addr);
569 if (entry && nfp_tunnel_is_mac_idx_global(entry->index)) {
570 nfp_tunnel_offloaded_macs_inc_ref_and_link(entry, netdev, mod);
574 /* Assign a global index if non-repr or MAC address is now shared. */
575 if (entry || !port) {
576 ida_idx = ida_simple_get(&priv->tun.mac_off_ids, 0,
577 NFP_MAX_MAC_INDEX, GFP_KERNEL);
581 nfp_mac_idx = nfp_tunnel_get_global_mac_idx_from_ida(ida_idx);
583 nfp_mac_idx = nfp_tunnel_get_mac_idx_from_phy_port_id(port);
587 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
593 ether_addr_copy(entry->addr, netdev->dev_addr);
594 INIT_LIST_HEAD(&entry->repr_list);
596 if (rhashtable_insert_fast(&priv->tun.offloaded_macs,
598 offloaded_macs_params)) {
604 err = __nfp_tunnel_offload_mac(app, netdev->dev_addr,
607 /* If not shared then free. */
608 if (!entry->ref_count)
609 goto err_remove_hash;
613 entry->index = nfp_mac_idx;
614 nfp_tunnel_offloaded_macs_inc_ref_and_link(entry, netdev, mod);
619 rhashtable_remove_fast(&priv->tun.offloaded_macs, &entry->ht_node,
620 offloaded_macs_params);
624 if (ida_idx != NFP_MAX_MAC_INDEX)
625 ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
631 nfp_tunnel_del_shared_mac(struct nfp_app *app, struct net_device *netdev,
634 struct nfp_flower_priv *priv = app->priv;
635 struct nfp_flower_repr_priv *repr_priv;
636 struct nfp_tun_offloaded_mac *entry;
637 struct nfp_repr *repr;
640 entry = nfp_tunnel_lookup_offloaded_macs(app, mac);
645 /* If del is part of a mod then mac_list is still in use elsewheree. */
646 if (nfp_netdev_is_nfp_repr(netdev) && !mod) {
647 repr = netdev_priv(netdev);
648 repr_priv = repr->app_priv;
649 list_del(&repr_priv->mac_list);
652 /* If MAC is now used by 1 repr set the offloaded MAC index to port. */
653 if (entry->ref_count == 1 && list_is_singular(&entry->repr_list)) {
657 repr_priv = list_first_entry(&entry->repr_list,
658 struct nfp_flower_repr_priv,
660 repr = repr_priv->nfp_repr;
661 port = nfp_repr_get_port_id(repr->netdev);
662 nfp_mac_idx = nfp_tunnel_get_mac_idx_from_phy_port_id(port);
663 err = __nfp_tunnel_offload_mac(app, mac, nfp_mac_idx, false);
665 nfp_flower_cmsg_warn(app, "MAC offload index revert failed on %s.\n",
666 netdev_name(netdev));
670 ida_idx = nfp_tunnel_get_ida_from_global_mac_idx(entry->index);
671 ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
672 entry->index = nfp_mac_idx;
676 if (entry->ref_count)
679 WARN_ON_ONCE(rhashtable_remove_fast(&priv->tun.offloaded_macs,
681 offloaded_macs_params));
682 /* If MAC has global ID then extract and free the ida entry. */
683 if (nfp_tunnel_is_mac_idx_global(entry->index)) {
684 ida_idx = nfp_tunnel_get_ida_from_global_mac_idx(entry->index);
685 ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
690 return __nfp_tunnel_offload_mac(app, mac, 0, true);
694 nfp_tunnel_offload_mac(struct nfp_app *app, struct net_device *netdev,
695 enum nfp_flower_mac_offload_cmd cmd)
697 struct nfp_flower_non_repr_priv *nr_priv = NULL;
698 bool non_repr = false, *mac_offloaded;
702 if (nfp_netdev_is_nfp_repr(netdev)) {
703 struct nfp_flower_repr_priv *repr_priv;
704 struct nfp_repr *repr;
706 repr = netdev_priv(netdev);
707 if (repr->app != app)
710 repr_priv = repr->app_priv;
711 mac_offloaded = &repr_priv->mac_offloaded;
712 off_mac = &repr_priv->offloaded_mac_addr[0];
713 port = nfp_repr_get_port_id(netdev);
714 if (!nfp_tunnel_port_is_phy_repr(port))
716 } else if (nfp_fl_is_netdev_to_offload(netdev)) {
717 nr_priv = nfp_flower_non_repr_priv_get(app, netdev);
721 mac_offloaded = &nr_priv->mac_offloaded;
722 off_mac = &nr_priv->offloaded_mac_addr[0];
728 if (!is_valid_ether_addr(netdev->dev_addr)) {
730 goto err_put_non_repr_priv;
733 if (cmd == NFP_TUNNEL_MAC_OFFLOAD_MOD && !*mac_offloaded)
734 cmd = NFP_TUNNEL_MAC_OFFLOAD_ADD;
737 case NFP_TUNNEL_MAC_OFFLOAD_ADD:
738 err = nfp_tunnel_add_shared_mac(app, netdev, port, false);
740 goto err_put_non_repr_priv;
743 __nfp_flower_non_repr_priv_get(nr_priv);
745 *mac_offloaded = true;
746 ether_addr_copy(off_mac, netdev->dev_addr);
748 case NFP_TUNNEL_MAC_OFFLOAD_DEL:
749 /* Only attempt delete if add was successful. */
754 __nfp_flower_non_repr_priv_put(nr_priv);
756 *mac_offloaded = false;
758 err = nfp_tunnel_del_shared_mac(app, netdev, netdev->dev_addr,
761 goto err_put_non_repr_priv;
764 case NFP_TUNNEL_MAC_OFFLOAD_MOD:
765 /* Ignore if changing to the same address. */
766 if (ether_addr_equal(netdev->dev_addr, off_mac))
769 err = nfp_tunnel_add_shared_mac(app, netdev, port, true);
771 goto err_put_non_repr_priv;
773 /* Delete the previous MAC address. */
774 err = nfp_tunnel_del_shared_mac(app, netdev, off_mac, true);
776 nfp_flower_cmsg_warn(app, "Failed to remove offload of replaced MAC addr on %s.\n",
777 netdev_name(netdev));
779 ether_addr_copy(off_mac, netdev->dev_addr);
783 goto err_put_non_repr_priv;
787 __nfp_flower_non_repr_priv_put(nr_priv);
791 err_put_non_repr_priv:
793 __nfp_flower_non_repr_priv_put(nr_priv);
798 int nfp_tunnel_mac_event_handler(struct nfp_app *app,
799 struct net_device *netdev,
800 unsigned long event, void *ptr)
804 if (event == NETDEV_DOWN) {
805 err = nfp_tunnel_offload_mac(app, netdev,
806 NFP_TUNNEL_MAC_OFFLOAD_DEL);
808 nfp_flower_cmsg_warn(app, "Failed to delete offload MAC on %s.\n",
809 netdev_name(netdev));
810 } else if (event == NETDEV_UP) {
811 err = nfp_tunnel_offload_mac(app, netdev,
812 NFP_TUNNEL_MAC_OFFLOAD_ADD);
814 nfp_flower_cmsg_warn(app, "Failed to offload MAC on %s.\n",
815 netdev_name(netdev));
816 } else if (event == NETDEV_CHANGEADDR) {
817 /* Only offload addr change if netdev is already up. */
818 if (!(netdev->flags & IFF_UP))
821 err = nfp_tunnel_offload_mac(app, netdev,
822 NFP_TUNNEL_MAC_OFFLOAD_MOD);
824 nfp_flower_cmsg_warn(app, "Failed to offload MAC change on %s.\n",
825 netdev_name(netdev));
830 int nfp_tunnel_config_start(struct nfp_app *app)
832 struct nfp_flower_priv *priv = app->priv;
835 /* Initialise rhash for MAC offload tracking. */
836 err = rhashtable_init(&priv->tun.offloaded_macs,
837 &offloaded_macs_params);
841 ida_init(&priv->tun.mac_off_ids);
843 /* Initialise priv data for IPv4 offloading. */
844 mutex_init(&priv->tun.ipv4_off_lock);
845 INIT_LIST_HEAD(&priv->tun.ipv4_off_list);
847 /* Initialise priv data for neighbour offloading. */
848 spin_lock_init(&priv->tun.neigh_off_lock);
849 INIT_LIST_HEAD(&priv->tun.neigh_off_list);
850 priv->tun.neigh_nb.notifier_call = nfp_tun_neigh_event_handler;
852 err = register_netevent_notifier(&priv->tun.neigh_nb);
854 rhashtable_free_and_destroy(&priv->tun.offloaded_macs,
855 nfp_check_rhashtable_empty, NULL);
862 void nfp_tunnel_config_stop(struct nfp_app *app)
864 struct nfp_flower_priv *priv = app->priv;
865 struct nfp_ipv4_route_entry *route_entry;
866 struct nfp_ipv4_addr_entry *ip_entry;
867 struct list_head *ptr, *storage;
869 unregister_netevent_notifier(&priv->tun.neigh_nb);
871 ida_destroy(&priv->tun.mac_off_ids);
873 /* Free any memory that may be occupied by ipv4 list. */
874 list_for_each_safe(ptr, storage, &priv->tun.ipv4_off_list) {
875 ip_entry = list_entry(ptr, struct nfp_ipv4_addr_entry, list);
876 list_del(&ip_entry->list);
880 /* Free any memory that may be occupied by the route list. */
881 list_for_each_safe(ptr, storage, &priv->tun.neigh_off_list) {
882 route_entry = list_entry(ptr, struct nfp_ipv4_route_entry,
884 list_del(&route_entry->list);
888 /* Destroy rhash. Entries should be cleaned on netdev notifier unreg. */
889 rhashtable_free_and_destroy(&priv->tun.offloaded_macs,
890 nfp_check_rhashtable_empty, NULL);