tc_encap_actions.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /****************************************************************************
  3. * Driver for Solarflare network controllers and boards
  4. * Copyright 2023, Advanced Micro Devices, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation, incorporated herein by reference.
  9. */
  10. #ifndef EFX_TC_ENCAP_ACTIONS_H
  11. #define EFX_TC_ENCAP_ACTIONS_H
  12. #include "net_driver.h"
  13. #if IS_ENABLED(CONFIG_SFC_SRIOV)
  14. #include <linux/refcount.h>
  15. #include <net/tc_act/tc_tunnel_key.h>
  16. /**
  17. * struct efx_neigh_binder - driver state for a neighbour entry
  18. * @net: the network namespace in which this neigh resides
  19. * @dst_ip: the IPv4 destination address resolved by this neigh
  20. * @dst_ip6: the IPv6 destination address resolved by this neigh
  21. * @ha: the hardware (Ethernet) address of the neighbour
  22. * @n_valid: true if the neighbour is in NUD_VALID state
  23. * @lock: protects @ha and @n_valid
  24. * @ttl: Time To Live associated with the route used
  25. * @dying: set when egdev is going away, to skip further updates
  26. * @egdev: egress device from the route lookup. Holds a reference
  27. * @dev_tracker: reference tracker entry for @egdev
  28. * @ns_tracker: reference tracker entry for @ns
  29. * @ref: counts encap actions referencing this entry
  30. * @used: jiffies of last time traffic hit any encap action using this.
  31. * When counter reads update this, a new neighbour event is sent to
  32. * indicate that the neighbour entry is still in use.
  33. * @users: list of &struct efx_tc_encap_action
  34. * @linkage: entry in efx->neigh_ht (keys are @net, @dst_ip, @dst_ip6).
  35. * @work: processes neighbour state changes, updates the encap actions
  36. * @efx: owning NIC instance.
  37. *
  38. * Associates a neighbour entry with the encap actions that are
  39. * interested in it, allowing the latter to be updated when the
  40. * neighbour details change.
  41. * Whichever of @dst_ip and @dst_ip6 is not in use will be all-zeroes,
  42. * this distinguishes IPv4 from IPv6 entries.
  43. */
  44. struct efx_neigh_binder {
  45. struct net *net;
  46. __be32 dst_ip;
  47. struct in6_addr dst_ip6;
  48. char ha[ETH_ALEN];
  49. bool n_valid;
  50. rwlock_t lock;
  51. u8 ttl;
  52. bool dying;
  53. struct net_device *egdev;
  54. netdevice_tracker dev_tracker;
  55. netns_tracker ns_tracker;
  56. refcount_t ref;
  57. unsigned long used;
  58. struct list_head users;
  59. struct rhash_head linkage;
  60. struct work_struct work;
  61. struct efx_nic *efx;
  62. };
  63. /* This limit is arbitrary; current hardware (SN1022) handles encap headers
  64. * of up to 126 bytes, but that limit is not enshrined in the MCDI protocol.
  65. */
  66. #define EFX_TC_MAX_ENCAP_HDR 126
  67. struct efx_tc_encap_action {
  68. enum efx_encap_type type;
  69. struct ip_tunnel_key key; /* 52 bytes */
  70. u32 dest_mport; /* is copied into struct efx_tc_action_set */
  71. u8 encap_hdr_len;
  72. bool n_valid;
  73. u8 encap_hdr[EFX_TC_MAX_ENCAP_HDR];
  74. struct efx_neigh_binder *neigh;
  75. struct list_head list; /* entry on neigh->users list */
  76. struct list_head users; /* action sets using this encap_md */
  77. struct rhash_head linkage; /* efx->tc_encap_ht */
  78. refcount_t ref;
  79. u32 fw_id; /* index of this entry in firmware encap table */
  80. };
  81. /* create/uncreate/teardown hashtables */
  82. int efx_tc_init_encap_actions(struct efx_nic *efx);
  83. void efx_tc_destroy_encap_actions(struct efx_nic *efx);
  84. void efx_tc_fini_encap_actions(struct efx_nic *efx);
  85. struct efx_tc_flow_rule;
  86. bool efx_tc_check_ready(struct efx_nic *efx, struct efx_tc_flow_rule *rule);
  87. struct efx_tc_encap_action *efx_tc_flower_create_encap_md(
  88. struct efx_nic *efx, const struct ip_tunnel_info *info,
  89. struct net_device *egdev, struct netlink_ext_ack *extack);
  90. void efx_tc_flower_release_encap_md(struct efx_nic *efx,
  91. struct efx_tc_encap_action *encap);
  92. void efx_tc_unregister_egdev(struct efx_nic *efx, struct net_device *net_dev);
  93. int efx_tc_netevent_event(struct efx_nic *efx, unsigned long event,
  94. void *ptr);
  95. #else /* CONFIG_SFC_SRIOV */
  96. static inline int efx_tc_netevent_event(struct efx_nic *efx,
  97. unsigned long event, void *ptr)
  98. {
  99. return NOTIFY_DONE;
  100. }
  101. #endif /* CONFIG_SFC_SRIOV */
  102. #endif /* EFX_TC_ENCAP_ACTIONS_H */