1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ 2 /* Copyright (C) 2017-2018 Netronome Systems, Inc. */ 3 4 #ifndef __NFP_FLOWER_H__ 5 #define __NFP_FLOWER_H__ 1 6 7 #include "cmsg.h" 8 9 #include <linux/circ_buf.h> 10 #include <linux/hashtable.h> 11 #include <linux/rhashtable.h> 12 #include <linux/time64.h> 13 #include <linux/types.h> 14 #include <net/pkt_cls.h> 15 #include <net/tcp.h> 16 #include <linux/workqueue.h> 17 #include <linux/idr.h> 18 19 struct nfp_fl_pre_lag; 20 struct net_device; 21 struct nfp_app; 22 23 #define NFP_FL_STAT_ID_MU_NUM GENMASK(31, 22) 24 #define NFP_FL_STAT_ID_STAT GENMASK(21, 0) 25 26 #define NFP_FL_STATS_ELEM_RS FIELD_SIZEOF(struct nfp_fl_stats_id, \ 27 init_unalloc) 28 #define NFP_FLOWER_MASK_ENTRY_RS 256 29 #define NFP_FLOWER_MASK_ELEMENT_RS 1 30 #define NFP_FLOWER_MASK_HASH_BITS 10 31 32 #define NFP_FL_META_FLAG_MANAGE_MASK BIT(7) 33 34 #define NFP_FL_MASK_REUSE_TIME_NS 40000 35 #define NFP_FL_MASK_ID_LOCATION 1 36 37 /* Extra features bitmap. */ 38 #define NFP_FL_FEATS_GENEVE BIT(0) 39 #define NFP_FL_NBI_MTU_SETTING BIT(1) 40 #define NFP_FL_FEATS_GENEVE_OPT BIT(2) 41 #define NFP_FL_FEATS_VLAN_PCP BIT(3) 42 #define NFP_FL_FEATS_LAG BIT(31) 43 44 struct nfp_fl_mask_id { 45 struct circ_buf mask_id_free_list; 46 ktime_t *last_used; 47 u8 init_unallocated; 48 }; 49 50 struct nfp_fl_stats_id { 51 struct circ_buf free_list; 52 u32 init_unalloc; 53 u8 repeated_em_count; 54 }; 55 56 /** 57 * struct nfp_fl_tunnel_offloads - priv data for tunnel offloads 58 * @offloaded_macs: Hashtable of the offloaded MAC addresses 59 * @ipv4_off_list: List of IPv4 addresses to offload 60 * @neigh_off_list: List of neighbour offloads 61 * @ipv4_off_lock: Lock for the IPv4 address list 62 * @neigh_off_lock: Lock for the neighbour address list 63 * @mac_off_ids: IDA to manage id assignment for offloaded MACs 64 * @neigh_nb: Notifier to monitor neighbour state 65 */ 66 struct nfp_fl_tunnel_offloads { 67 struct rhashtable offloaded_macs; 68 struct list_head ipv4_off_list; 69 struct list_head neigh_off_list; 70 struct mutex ipv4_off_lock; 71 spinlock_t neigh_off_lock; 72 struct ida mac_off_ids; 73 struct notifier_block neigh_nb; 74 }; 75 76 /** 77 * struct nfp_mtu_conf - manage MTU setting 78 * @portnum: NFP port number of repr with requested MTU change 79 * @requested_val: MTU value requested for repr 80 * @ack: Received ack that MTU has been correctly set 81 * @wait_q: Wait queue for MTU acknowledgements 82 * @lock: Lock for setting/reading MTU variables 83 */ 84 struct nfp_mtu_conf { 85 u32 portnum; 86 unsigned int requested_val; 87 bool ack; 88 wait_queue_head_t wait_q; 89 spinlock_t lock; 90 }; 91 92 /** 93 * struct nfp_fl_lag - Flower APP priv data for link aggregation 94 * @work: Work queue for writing configs to the HW 95 * @lock: Lock to protect lag_group_list 96 * @group_list: List of all master/slave groups offloaded 97 * @ida_handle: IDA to handle group ids 98 * @pkt_num: Incremented for each config packet sent 99 * @batch_ver: Incremented for each batch of config packets 100 * @global_inst: Instance allocator for groups 101 * @rst_cfg: Marker to reset HW LAG config 102 * @retrans_skbs: Cmsgs that could not be processed by HW and require 103 * retransmission 104 */ 105 struct nfp_fl_lag { 106 struct delayed_work work; 107 struct mutex lock; 108 struct list_head group_list; 109 struct ida ida_handle; 110 unsigned int pkt_num; 111 unsigned int batch_ver; 112 u8 global_inst; 113 bool rst_cfg; 114 struct sk_buff_head retrans_skbs; 115 }; 116 117 /** 118 * struct nfp_flower_priv - Flower APP per-vNIC priv data 119 * @app: Back pointer to app 120 * @nn: Pointer to vNIC 121 * @mask_id_seed: Seed used for mask hash table 122 * @flower_version: HW version of flower 123 * @flower_ext_feats: Bitmap of extra features the HW supports 124 * @stats_ids: List of free stats ids 125 * @mask_ids: List of free mask ids 126 * @mask_table: Hash table used to store masks 127 * @stats_ring_size: Maximum number of allowed stats ids 128 * @flow_table: Hash table used to store flower rules 129 * @stats: Stored stats updates for flower rules 130 * @stats_lock: Lock for flower rule stats updates 131 * @cmsg_work: Workqueue for control messages processing 132 * @cmsg_skbs_high: List of higher priority skbs for control message 133 * processing 134 * @cmsg_skbs_low: List of lower priority skbs for control message 135 * processing 136 * @tun: Tunnel offload data 137 * @reify_replies: atomically stores the number of replies received 138 * from firmware for repr reify 139 * @reify_wait_queue: wait queue for repr reify response counting 140 * @mtu_conf: Configuration of repr MTU value 141 * @nfp_lag: Link aggregation data block 142 * @indr_block_cb_priv: List of priv data passed to indirect block cbs 143 * @non_repr_priv: List of offloaded non-repr ports and their priv data 144 * @active_mem_unit: Current active memory unit for flower rules 145 * @total_mem_units: Total number of available memory units for flower rules 146 */ 147 struct nfp_flower_priv { 148 struct nfp_app *app; 149 struct nfp_net *nn; 150 u32 mask_id_seed; 151 u64 flower_version; 152 u64 flower_ext_feats; 153 struct nfp_fl_stats_id stats_ids; 154 struct nfp_fl_mask_id mask_ids; 155 DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS); 156 u32 stats_ring_size; 157 struct rhashtable flow_table; 158 struct nfp_fl_stats *stats; 159 spinlock_t stats_lock; /* lock stats */ 160 struct work_struct cmsg_work; 161 struct sk_buff_head cmsg_skbs_high; 162 struct sk_buff_head cmsg_skbs_low; 163 struct nfp_fl_tunnel_offloads tun; 164 atomic_t reify_replies; 165 wait_queue_head_t reify_wait_queue; 166 struct nfp_mtu_conf mtu_conf; 167 struct nfp_fl_lag nfp_lag; 168 struct list_head indr_block_cb_priv; 169 struct list_head non_repr_priv; 170 unsigned int active_mem_unit; 171 unsigned int total_mem_units; 172 }; 173 174 /** 175 * struct nfp_flower_repr_priv - Flower APP per-repr priv data 176 * @nfp_repr: Back pointer to nfp_repr 177 * @lag_port_flags: Extended port flags to record lag state of repr 178 * @mac_offloaded: Flag indicating a MAC address is offloaded for repr 179 * @offloaded_mac_addr: MAC address that has been offloaded for repr 180 * @mac_list: List entry of reprs that share the same offloaded MAC 181 */ 182 struct nfp_flower_repr_priv { 183 struct nfp_repr *nfp_repr; 184 unsigned long lag_port_flags; 185 bool mac_offloaded; 186 u8 offloaded_mac_addr[ETH_ALEN]; 187 struct list_head mac_list; 188 }; 189 190 /** 191 * struct nfp_flower_non_repr_priv - Priv data for non-repr offloaded ports 192 * @list: List entry of offloaded reprs 193 * @netdev: Pointer to non-repr net_device 194 * @ref_count: Number of references held for this priv data 195 * @mac_offloaded: Flag indicating a MAC address is offloaded for device 196 * @offloaded_mac_addr: MAC address that has been offloaded for dev 197 */ 198 struct nfp_flower_non_repr_priv { 199 struct list_head list; 200 struct net_device *netdev; 201 int ref_count; 202 bool mac_offloaded; 203 u8 offloaded_mac_addr[ETH_ALEN]; 204 }; 205 206 struct nfp_fl_key_ls { 207 u32 key_layer_two; 208 u8 key_layer; 209 int key_size; 210 }; 211 212 struct nfp_fl_rule_metadata { 213 u8 key_len; 214 u8 mask_len; 215 u8 act_len; 216 u8 flags; 217 __be32 host_ctx_id; 218 __be64 host_cookie __packed; 219 __be64 flow_version __packed; 220 __be32 shortcut; 221 }; 222 223 struct nfp_fl_stats { 224 u64 pkts; 225 u64 bytes; 226 u64 used; 227 }; 228 229 struct nfp_fl_payload { 230 struct nfp_fl_rule_metadata meta; 231 unsigned long tc_flower_cookie; 232 struct rhash_head fl_node; 233 struct rcu_head rcu; 234 __be32 nfp_tun_ipv4_addr; 235 struct net_device *ingress_dev; 236 char *unmasked_data; 237 char *mask_data; 238 char *action_data; 239 }; 240 241 extern const struct rhashtable_params nfp_flower_table_params; 242 243 struct nfp_fl_stats_frame { 244 __be32 stats_con_id; 245 __be32 pkt_count; 246 __be64 byte_count; 247 __be64 stats_cookie; 248 }; 249 250 int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count, 251 unsigned int host_ctx_split); 252 void nfp_flower_metadata_cleanup(struct nfp_app *app); 253 254 int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev, 255 enum tc_setup_type type, void *type_data); 256 int nfp_flower_compile_flow_match(struct nfp_app *app, 257 struct tc_cls_flower_offload *flow, 258 struct nfp_fl_key_ls *key_ls, 259 struct net_device *netdev, 260 struct nfp_fl_payload *nfp_flow, 261 enum nfp_flower_tun_type tun_type); 262 int nfp_flower_compile_action(struct nfp_app *app, 263 struct tc_cls_flower_offload *flow, 264 struct net_device *netdev, 265 struct nfp_fl_payload *nfp_flow); 266 int nfp_compile_flow_metadata(struct nfp_app *app, 267 struct tc_cls_flower_offload *flow, 268 struct nfp_fl_payload *nfp_flow, 269 struct net_device *netdev); 270 int nfp_modify_flow_metadata(struct nfp_app *app, 271 struct nfp_fl_payload *nfp_flow); 272 273 struct nfp_fl_payload * 274 nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie, 275 struct net_device *netdev); 276 struct nfp_fl_payload * 277 nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie); 278 279 void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb); 280 281 int nfp_tunnel_config_start(struct nfp_app *app); 282 void nfp_tunnel_config_stop(struct nfp_app *app); 283 int nfp_tunnel_mac_event_handler(struct nfp_app *app, 284 struct net_device *netdev, 285 unsigned long event, void *ptr); 286 void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4); 287 void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4); 288 void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb); 289 void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb); 290 void nfp_flower_lag_init(struct nfp_fl_lag *lag); 291 void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag); 292 int nfp_flower_lag_reset(struct nfp_fl_lag *lag); 293 int nfp_flower_lag_netdev_event(struct nfp_flower_priv *priv, 294 struct net_device *netdev, 295 unsigned long event, void *ptr); 296 bool nfp_flower_lag_unprocessed_msg(struct nfp_app *app, struct sk_buff *skb); 297 int nfp_flower_lag_populate_pre_action(struct nfp_app *app, 298 struct net_device *master, 299 struct nfp_fl_pre_lag *pre_act); 300 int nfp_flower_lag_get_output_id(struct nfp_app *app, 301 struct net_device *master); 302 int nfp_flower_reg_indir_block_handler(struct nfp_app *app, 303 struct net_device *netdev, 304 unsigned long event); 305 306 void 307 __nfp_flower_non_repr_priv_get(struct nfp_flower_non_repr_priv *non_repr_priv); 308 struct nfp_flower_non_repr_priv * 309 nfp_flower_non_repr_priv_get(struct nfp_app *app, struct net_device *netdev); 310 void 311 __nfp_flower_non_repr_priv_put(struct nfp_flower_non_repr_priv *non_repr_priv); 312 void 313 nfp_flower_non_repr_priv_put(struct nfp_app *app, struct net_device *netdev); 314 #endif 315