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 10 #ifndef BNXT_TC_H 11 #define BNXT_TC_H 12 13 #ifdef CONFIG_BNXT_FLOWER_OFFLOAD 14 15 /* Structs used for storing the filter/actions of the TC cmd. 16 */ 17 struct bnxt_tc_l2_key { 18 u8 dmac[ETH_ALEN]; 19 u8 smac[ETH_ALEN]; 20 __be16 inner_vlan_tpid; 21 __be16 inner_vlan_tci; 22 __be16 ether_type; 23 u8 num_vlans; 24 }; 25 26 struct bnxt_tc_l3_key { 27 union { 28 struct { 29 struct in_addr daddr; 30 struct in_addr saddr; 31 } ipv4; 32 struct { 33 struct in6_addr daddr; 34 struct in6_addr saddr; 35 } ipv6; 36 }; 37 }; 38 39 struct bnxt_tc_l4_key { 40 u8 ip_proto; 41 union { 42 struct { 43 __be16 sport; 44 __be16 dport; 45 } ports; 46 struct { 47 u8 type; 48 u8 code; 49 } icmp; 50 }; 51 }; 52 53 struct bnxt_tc_actions { 54 u32 flags; 55 #define BNXT_TC_ACTION_FLAG_FWD BIT(0) 56 #define BNXT_TC_ACTION_FLAG_FWD_VXLAN BIT(1) 57 #define BNXT_TC_ACTION_FLAG_PUSH_VLAN BIT(3) 58 #define BNXT_TC_ACTION_FLAG_POP_VLAN BIT(4) 59 #define BNXT_TC_ACTION_FLAG_DROP BIT(5) 60 61 u16 dst_fid; 62 struct net_device *dst_dev; 63 __be16 push_vlan_tpid; 64 __be16 push_vlan_tci; 65 }; 66 67 struct bnxt_tc_flow_stats { 68 u64 packets; 69 u64 bytes; 70 }; 71 72 struct bnxt_tc_flow { 73 u32 flags; 74 #define BNXT_TC_FLOW_FLAGS_ETH_ADDRS BIT(1) 75 #define BNXT_TC_FLOW_FLAGS_IPV4_ADDRS BIT(2) 76 #define BNXT_TC_FLOW_FLAGS_IPV6_ADDRS BIT(3) 77 #define BNXT_TC_FLOW_FLAGS_PORTS BIT(4) 78 #define BNXT_TC_FLOW_FLAGS_ICMP BIT(5) 79 80 /* flow applicable to pkts ingressing on this fid */ 81 u16 src_fid; 82 struct bnxt_tc_l2_key l2_key; 83 struct bnxt_tc_l2_key l2_mask; 84 struct bnxt_tc_l3_key l3_key; 85 struct bnxt_tc_l3_key l3_mask; 86 struct bnxt_tc_l4_key l4_key; 87 struct bnxt_tc_l4_key l4_mask; 88 89 struct bnxt_tc_actions actions; 90 91 /* updated stats accounting for hw-counter wrap-around */ 92 struct bnxt_tc_flow_stats stats; 93 /* previous snap-shot of stats */ 94 struct bnxt_tc_flow_stats prev_stats; 95 unsigned long lastused; /* jiffies */ 96 }; 97 98 /* L2 hash table 99 * This data-struct is used for L2-flow table. 100 * The L2 part of a flow is stored in a hash table. 101 * A flow that shares the same L2 key/mask with an 102 * already existing flow must refer to it's flow handle. 103 */ 104 struct bnxt_tc_l2_node { 105 /* hash key: first 16b of key */ 106 #define BNXT_TC_L2_KEY_LEN 16 107 struct bnxt_tc_l2_key key; 108 struct rhash_head node; 109 110 /* a linked list of flows that share the same l2 key */ 111 struct list_head common_l2_flows; 112 113 /* number of flows sharing the l2 key */ 114 u16 refcount; 115 116 struct rcu_head rcu; 117 }; 118 119 struct bnxt_tc_flow_node { 120 /* hash key: provided by TC */ 121 unsigned long cookie; 122 struct rhash_head node; 123 124 struct bnxt_tc_flow flow; 125 126 __le16 flow_handle; 127 128 /* L2 node in l2 hashtable that shares flow's l2 key */ 129 struct bnxt_tc_l2_node *l2_node; 130 /* for the shared_flows list maintained in l2_node */ 131 struct list_head l2_list_node; 132 133 struct rcu_head rcu; 134 }; 135 136 int bnxt_tc_setup_flower(struct bnxt *bp, u16 src_fid, 137 struct tc_cls_flower_offload *cls_flower); 138 int bnxt_init_tc(struct bnxt *bp); 139 void bnxt_shutdown_tc(struct bnxt *bp); 140 141 #else /* CONFIG_BNXT_FLOWER_OFFLOAD */ 142 143 static inline int bnxt_tc_setup_flower(struct bnxt *bp, u16 src_fid, 144 struct tc_cls_flower_offload *cls_flower) 145 { 146 return -EOPNOTSUPP; 147 } 148 149 static inline int bnxt_init_tc(struct bnxt *bp) 150 { 151 return 0; 152 } 153 154 static inline void bnxt_shutdown_tc(struct bnxt *bp) 155 { 156 } 157 #endif /* CONFIG_BNXT_FLOWER_OFFLOAD */ 158 #endif /* BNXT_TC_H */ 159