ice_tc_lib.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2019-2021, Intel Corporation. */
  3. #ifndef _ICE_TC_LIB_H_
  4. #define _ICE_TC_LIB_H_
  5. #include <linux/bits.h>
  6. #include <net/pfcp.h>
  7. #define ICE_TC_FLWR_FIELD_DST_MAC BIT(0)
  8. #define ICE_TC_FLWR_FIELD_SRC_MAC BIT(1)
  9. #define ICE_TC_FLWR_FIELD_VLAN BIT(2)
  10. #define ICE_TC_FLWR_FIELD_DEST_IPV4 BIT(3)
  11. #define ICE_TC_FLWR_FIELD_SRC_IPV4 BIT(4)
  12. #define ICE_TC_FLWR_FIELD_DEST_IPV6 BIT(5)
  13. #define ICE_TC_FLWR_FIELD_SRC_IPV6 BIT(6)
  14. #define ICE_TC_FLWR_FIELD_DEST_L4_PORT BIT(7)
  15. #define ICE_TC_FLWR_FIELD_SRC_L4_PORT BIT(8)
  16. #define ICE_TC_FLWR_FIELD_TENANT_ID BIT(9)
  17. #define ICE_TC_FLWR_FIELD_ENC_DEST_IPV4 BIT(10)
  18. #define ICE_TC_FLWR_FIELD_ENC_SRC_IPV4 BIT(11)
  19. #define ICE_TC_FLWR_FIELD_ENC_DEST_IPV6 BIT(12)
  20. #define ICE_TC_FLWR_FIELD_ENC_SRC_IPV6 BIT(13)
  21. #define ICE_TC_FLWR_FIELD_ENC_DEST_L4_PORT BIT(14)
  22. #define ICE_TC_FLWR_FIELD_ENC_SRC_L4_PORT BIT(15)
  23. #define ICE_TC_FLWR_FIELD_ENC_DST_MAC BIT(16)
  24. #define ICE_TC_FLWR_FIELD_ETH_TYPE_ID BIT(17)
  25. #define ICE_TC_FLWR_FIELD_GTP_OPTS BIT(18)
  26. #define ICE_TC_FLWR_FIELD_CVLAN BIT(19)
  27. #define ICE_TC_FLWR_FIELD_PPPOE_SESSID BIT(20)
  28. #define ICE_TC_FLWR_FIELD_PPP_PROTO BIT(21)
  29. #define ICE_TC_FLWR_FIELD_IP_TOS BIT(22)
  30. #define ICE_TC_FLWR_FIELD_IP_TTL BIT(23)
  31. #define ICE_TC_FLWR_FIELD_ENC_IP_TOS BIT(24)
  32. #define ICE_TC_FLWR_FIELD_ENC_IP_TTL BIT(25)
  33. #define ICE_TC_FLWR_FIELD_L2TPV3_SESSID BIT(26)
  34. #define ICE_TC_FLWR_FIELD_VLAN_PRIO BIT(27)
  35. #define ICE_TC_FLWR_FIELD_CVLAN_PRIO BIT(28)
  36. #define ICE_TC_FLWR_FIELD_VLAN_TPID BIT(29)
  37. #define ICE_TC_FLWR_FIELD_PFCP_OPTS BIT(30)
  38. #define ICE_TC_FLOWER_MASK_32 0xFFFFFFFF
  39. #define ICE_IPV6_HDR_TC_MASK 0xFF00000
  40. struct ice_indr_block_priv {
  41. struct net_device *netdev;
  42. struct ice_netdev_priv *np;
  43. struct list_head list;
  44. };
  45. struct ice_tc_flower_action {
  46. /* forward action specific params */
  47. union {
  48. struct {
  49. u32 tc_class; /* forward to hw_tc */
  50. u32 rsvd;
  51. } tc;
  52. struct {
  53. u16 queue; /* forward to queue */
  54. /* To add filter in HW, absolute queue number in global
  55. * space of queues (between 0...N) is needed
  56. */
  57. u16 hw_queue;
  58. } q;
  59. } fwd;
  60. enum ice_sw_fwd_act_type fltr_act;
  61. };
  62. struct ice_tc_vlan_hdr {
  63. __be16 vlan_id; /* Only last 12 bits valid */
  64. __be16 vlan_prio; /* Only last 3 bits valid (valid values: 0..7) */
  65. __be16 vlan_tpid;
  66. };
  67. struct ice_tc_pppoe_hdr {
  68. __be16 session_id;
  69. __be16 ppp_proto;
  70. };
  71. struct ice_tc_l2_hdr {
  72. u8 dst_mac[ETH_ALEN];
  73. u8 src_mac[ETH_ALEN];
  74. __be16 n_proto; /* Ethernet Protocol */
  75. };
  76. struct ice_tc_l3_hdr {
  77. u8 ip_proto; /* IPPROTO value */
  78. union {
  79. struct {
  80. struct in_addr dst_ip;
  81. struct in_addr src_ip;
  82. } v4;
  83. struct {
  84. struct in6_addr dst_ip6;
  85. struct in6_addr src_ip6;
  86. } v6;
  87. } ip;
  88. #define dst_ipv6 ip.v6.dst_ip6.s6_addr32
  89. #define dst_ipv6_addr ip.v6.dst_ip6.s6_addr
  90. #define src_ipv6 ip.v6.src_ip6.s6_addr32
  91. #define src_ipv6_addr ip.v6.src_ip6.s6_addr
  92. #define dst_ipv4 ip.v4.dst_ip.s_addr
  93. #define src_ipv4 ip.v4.src_ip.s_addr
  94. u8 tos;
  95. u8 ttl;
  96. };
  97. struct ice_tc_l2tpv3_hdr {
  98. __be32 session_id;
  99. };
  100. struct ice_tc_l4_hdr {
  101. __be16 dst_port;
  102. __be16 src_port;
  103. };
  104. struct ice_tc_flower_lyr_2_4_hdrs {
  105. /* L2 layer fields with their mask */
  106. struct ice_tc_l2_hdr l2_key;
  107. struct ice_tc_l2_hdr l2_mask;
  108. struct ice_tc_vlan_hdr vlan_hdr;
  109. struct ice_tc_vlan_hdr cvlan_hdr;
  110. struct ice_tc_pppoe_hdr pppoe_hdr;
  111. struct ice_tc_l2tpv3_hdr l2tpv3_hdr;
  112. /* L3 (IPv4[6]) layer fields with their mask */
  113. struct ice_tc_l3_hdr l3_key;
  114. struct ice_tc_l3_hdr l3_mask;
  115. /* L4 layer fields with their mask */
  116. struct ice_tc_l4_hdr l4_key;
  117. struct ice_tc_l4_hdr l4_mask;
  118. };
  119. enum ice_eswitch_fltr_direction {
  120. ICE_ESWITCH_FLTR_INGRESS,
  121. ICE_ESWITCH_FLTR_EGRESS,
  122. };
  123. struct ice_tc_flower_fltr {
  124. struct hlist_node tc_flower_node;
  125. /* cookie becomes filter_rule_id if rule is added successfully */
  126. unsigned long cookie;
  127. /* add_adv_rule returns information like recipe ID, rule_id. Store
  128. * those values since they are needed to remove advanced rule
  129. */
  130. u16 rid;
  131. u16 rule_id;
  132. /* VSI handle of the destination VSI (it could be main PF VSI, CHNL_VSI,
  133. * VF VSI)
  134. */
  135. u16 dest_vsi_handle;
  136. /* ptr to destination VSI */
  137. struct ice_vsi *dest_vsi;
  138. /* direction of fltr for eswitch use case */
  139. enum ice_eswitch_fltr_direction direction;
  140. /* Parsed TC flower configuration params */
  141. struct ice_tc_flower_lyr_2_4_hdrs outer_headers;
  142. struct ice_tc_flower_lyr_2_4_hdrs inner_headers;
  143. struct ice_vsi *src_vsi;
  144. __be32 tenant_id;
  145. struct gtp_pdu_session_info gtp_pdu_info_keys;
  146. struct gtp_pdu_session_info gtp_pdu_info_masks;
  147. struct pfcp_metadata pfcp_meta_keys;
  148. struct pfcp_metadata pfcp_meta_masks;
  149. u32 flags;
  150. u8 tunnel_type;
  151. struct ice_tc_flower_action action;
  152. /* cache ptr which is used wherever needed to communicate netlink
  153. * messages
  154. */
  155. struct netlink_ext_ack *extack;
  156. };
  157. /**
  158. * ice_is_chnl_fltr - is this a valid channel filter
  159. * @f: Pointer to tc-flower filter
  160. *
  161. * Criteria to determine of given filter is valid channel filter
  162. * or not is based on its destination.
  163. * For forward to VSI action, if destination is valid hw_tc (aka tc_class)
  164. * and in supported range of TCs for ADQ, then return true.
  165. * For forward to queue, as long as dest_vsi is valid and it is of type
  166. * VSI_CHNL (PF ADQ VSI is of type VSI_CHNL), return true.
  167. * NOTE: For forward to queue, correct dest_vsi is still set in tc_fltr based
  168. * on destination queue specified.
  169. */
  170. static inline bool ice_is_chnl_fltr(struct ice_tc_flower_fltr *f)
  171. {
  172. if (f->action.fltr_act == ICE_FWD_TO_VSI)
  173. return f->action.fwd.tc.tc_class >= ICE_CHNL_START_TC &&
  174. f->action.fwd.tc.tc_class < ICE_CHNL_MAX_TC;
  175. else if (f->action.fltr_act == ICE_FWD_TO_Q)
  176. return f->dest_vsi && f->dest_vsi->type == ICE_VSI_CHNL;
  177. return false;
  178. }
  179. /**
  180. * ice_chnl_dmac_fltr_cnt - DMAC based CHNL filter count
  181. * @pf: Pointer to PF
  182. */
  183. static inline int ice_chnl_dmac_fltr_cnt(struct ice_pf *pf)
  184. {
  185. return pf->num_dmac_chnl_fltrs;
  186. }
  187. struct ice_vsi *ice_locate_vsi_using_queue(struct ice_vsi *vsi, int queue);
  188. int
  189. ice_add_cls_flower(struct net_device *netdev, struct ice_vsi *vsi,
  190. struct flow_cls_offload *cls_flower);
  191. int
  192. ice_del_cls_flower(struct ice_vsi *vsi, struct flow_cls_offload *cls_flower);
  193. void ice_replay_tc_fltrs(struct ice_pf *pf);
  194. bool ice_is_tunnel_supported(struct net_device *dev);
  195. static inline bool ice_is_forward_action(enum ice_sw_fwd_act_type fltr_act)
  196. {
  197. switch (fltr_act) {
  198. case ICE_FWD_TO_VSI:
  199. case ICE_FWD_TO_Q:
  200. return true;
  201. default:
  202. return false;
  203. }
  204. }
  205. #endif /* _ICE_TC_LIB_H_ */