bnxt_tc.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /* Broadcom NetXtreme-C/E network driver.
  2. *
  3. * Copyright (c) 2017 Broadcom Limited
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. */
  9. #ifndef BNXT_TC_H
  10. #define BNXT_TC_H
  11. #ifdef CONFIG_BNXT_FLOWER_OFFLOAD
  12. #include <net/ip_tunnels.h>
  13. /* Structs used for storing the filter/actions of the TC cmd.
  14. */
  15. struct bnxt_tc_l2_key {
  16. u8 dmac[ETH_ALEN];
  17. u8 smac[ETH_ALEN];
  18. __be16 inner_vlan_tpid;
  19. __be16 inner_vlan_tci;
  20. __be16 ether_type;
  21. u8 num_vlans;
  22. };
  23. struct bnxt_tc_l3_key {
  24. union {
  25. struct {
  26. struct in_addr daddr;
  27. struct in_addr saddr;
  28. } ipv4;
  29. struct {
  30. struct in6_addr daddr;
  31. struct in6_addr saddr;
  32. } ipv6;
  33. };
  34. };
  35. struct bnxt_tc_l4_key {
  36. u8 ip_proto;
  37. union {
  38. struct {
  39. __be16 sport;
  40. __be16 dport;
  41. } ports;
  42. struct {
  43. u8 type;
  44. u8 code;
  45. } icmp;
  46. };
  47. };
  48. struct bnxt_tc_tunnel_key {
  49. struct bnxt_tc_l2_key l2;
  50. struct bnxt_tc_l3_key l3;
  51. struct bnxt_tc_l4_key l4;
  52. __be32 id;
  53. };
  54. struct bnxt_tc_actions {
  55. u32 flags;
  56. #define BNXT_TC_ACTION_FLAG_FWD BIT(0)
  57. #define BNXT_TC_ACTION_FLAG_FWD_VXLAN BIT(1)
  58. #define BNXT_TC_ACTION_FLAG_PUSH_VLAN BIT(3)
  59. #define BNXT_TC_ACTION_FLAG_POP_VLAN BIT(4)
  60. #define BNXT_TC_ACTION_FLAG_DROP BIT(5)
  61. #define BNXT_TC_ACTION_FLAG_TUNNEL_ENCAP BIT(6)
  62. #define BNXT_TC_ACTION_FLAG_TUNNEL_DECAP BIT(7)
  63. u16 dst_fid;
  64. struct net_device *dst_dev;
  65. __be16 push_vlan_tpid;
  66. __be16 push_vlan_tci;
  67. /* tunnel encap */
  68. struct ip_tunnel_key tun_encap_key;
  69. };
  70. struct bnxt_tc_flow {
  71. u32 flags;
  72. #define BNXT_TC_FLOW_FLAGS_ETH_ADDRS BIT(1)
  73. #define BNXT_TC_FLOW_FLAGS_IPV4_ADDRS BIT(2)
  74. #define BNXT_TC_FLOW_FLAGS_IPV6_ADDRS BIT(3)
  75. #define BNXT_TC_FLOW_FLAGS_PORTS BIT(4)
  76. #define BNXT_TC_FLOW_FLAGS_ICMP BIT(5)
  77. #define BNXT_TC_FLOW_FLAGS_TUNL_ETH_ADDRS BIT(6)
  78. #define BNXT_TC_FLOW_FLAGS_TUNL_IPV4_ADDRS BIT(7)
  79. #define BNXT_TC_FLOW_FLAGS_TUNL_IPV6_ADDRS BIT(8)
  80. #define BNXT_TC_FLOW_FLAGS_TUNL_PORTS BIT(9)
  81. #define BNXT_TC_FLOW_FLAGS_TUNL_ID BIT(10)
  82. #define BNXT_TC_FLOW_FLAGS_TUNNEL (BNXT_TC_FLOW_FLAGS_TUNL_ETH_ADDRS | \
  83. BNXT_TC_FLOW_FLAGS_TUNL_IPV4_ADDRS | \
  84. BNXT_TC_FLOW_FLAGS_TUNL_IPV6_ADDRS |\
  85. BNXT_TC_FLOW_FLAGS_TUNL_PORTS |\
  86. BNXT_TC_FLOW_FLAGS_TUNL_ID)
  87. /* flow applicable to pkts ingressing on this fid */
  88. u16 src_fid;
  89. struct bnxt_tc_l2_key l2_key;
  90. struct bnxt_tc_l2_key l2_mask;
  91. struct bnxt_tc_l3_key l3_key;
  92. struct bnxt_tc_l3_key l3_mask;
  93. struct bnxt_tc_l4_key l4_key;
  94. struct bnxt_tc_l4_key l4_mask;
  95. struct ip_tunnel_key tun_key;
  96. struct ip_tunnel_key tun_mask;
  97. struct bnxt_tc_actions actions;
  98. /* updated stats accounting for hw-counter wrap-around */
  99. struct bnxt_tc_flow_stats stats;
  100. /* previous snap-shot of stats */
  101. struct bnxt_tc_flow_stats prev_stats;
  102. unsigned long lastused; /* jiffies */
  103. /* for calculating delta from prev_stats and
  104. * updating prev_stats atomically.
  105. */
  106. spinlock_t stats_lock;
  107. };
  108. /* Tunnel encap/decap hash table
  109. * This table is used to maintain a list of flows that use
  110. * the same tunnel encap/decap params (ip_daddrs, vni, udp_dport)
  111. * and the FW returned handle.
  112. * A separate table is maintained for encap and decap
  113. */
  114. struct bnxt_tc_tunnel_node {
  115. struct ip_tunnel_key key;
  116. struct rhash_head node;
  117. /* tunnel l2 info */
  118. struct bnxt_tc_l2_key l2_info;
  119. #define INVALID_TUNNEL_HANDLE cpu_to_le32(0xffffffff)
  120. /* tunnel handle returned by FW */
  121. __le32 tunnel_handle;
  122. u32 refcount;
  123. struct rcu_head rcu;
  124. };
  125. /* L2 hash table
  126. * The same data-struct is used for L2-flow table and L2-tunnel table.
  127. * The L2 part of a flow or tunnel is stored in a hash table.
  128. * A flow that shares the same L2 key/mask with an
  129. * already existing flow/tunnel must refer to it's flow handle or
  130. * decap_filter_id respectively.
  131. */
  132. struct bnxt_tc_l2_node {
  133. /* hash key: first 16b of key */
  134. #define BNXT_TC_L2_KEY_LEN 16
  135. struct bnxt_tc_l2_key key;
  136. struct rhash_head node;
  137. /* a linked list of flows that share the same l2 key */
  138. struct list_head common_l2_flows;
  139. /* number of flows/tunnels sharing the l2 key */
  140. u16 refcount;
  141. struct rcu_head rcu;
  142. };
  143. struct bnxt_tc_flow_node {
  144. /* hash key: provided by TC */
  145. unsigned long cookie;
  146. struct rhash_head node;
  147. struct bnxt_tc_flow flow;
  148. __le16 flow_handle;
  149. /* L2 node in l2 hashtable that shares flow's l2 key */
  150. struct bnxt_tc_l2_node *l2_node;
  151. /* for the shared_flows list maintained in l2_node */
  152. struct list_head l2_list_node;
  153. /* tunnel encap related */
  154. struct bnxt_tc_tunnel_node *encap_node;
  155. /* tunnel decap related */
  156. struct bnxt_tc_tunnel_node *decap_node;
  157. /* L2 node in tunnel-l2 hashtable that shares flow's tunnel l2 key */
  158. struct bnxt_tc_l2_node *decap_l2_node;
  159. /* for the shared_flows list maintained in tunnel decap l2_node */
  160. struct list_head decap_l2_list_node;
  161. struct rcu_head rcu;
  162. };
  163. int bnxt_tc_setup_flower(struct bnxt *bp, u16 src_fid,
  164. struct tc_cls_flower_offload *cls_flower);
  165. int bnxt_init_tc(struct bnxt *bp);
  166. void bnxt_shutdown_tc(struct bnxt *bp);
  167. void bnxt_tc_flow_stats_work(struct bnxt *bp);
  168. static inline bool bnxt_tc_flower_enabled(struct bnxt *bp)
  169. {
  170. return bp->tc_info && bp->tc_info->enabled;
  171. }
  172. #else /* CONFIG_BNXT_FLOWER_OFFLOAD */
  173. static inline int bnxt_tc_setup_flower(struct bnxt *bp, u16 src_fid,
  174. struct tc_cls_flower_offload *cls_flower)
  175. {
  176. return -EOPNOTSUPP;
  177. }
  178. static inline int bnxt_init_tc(struct bnxt *bp)
  179. {
  180. return 0;
  181. }
  182. static inline void bnxt_shutdown_tc(struct bnxt *bp)
  183. {
  184. }
  185. static inline void bnxt_tc_flow_stats_work(struct bnxt *bp)
  186. {
  187. }
  188. static inline bool bnxt_tc_flower_enabled(struct bnxt *bp)
  189. {
  190. return false;
  191. }
  192. #endif /* CONFIG_BNXT_FLOWER_OFFLOAD */
  193. #endif /* BNXT_TC_H */