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_STATS_ELEM_RS FIELD_SIZEOF(struct nfp_fl_stats_id, \ 24 init_unalloc) 25 #define NFP_FLOWER_MASK_ENTRY_RS 256 26 #define NFP_FLOWER_MASK_ELEMENT_RS 1 27 #define NFP_FLOWER_MASK_HASH_BITS 10 28 29 #define NFP_FL_META_FLAG_MANAGE_MASK BIT(7) 30 31 #define NFP_FL_MASK_REUSE_TIME_NS 40000 32 #define NFP_FL_MASK_ID_LOCATION 1 33 34 #define NFP_FL_VXLAN_PORT 4789 35 #define NFP_FL_GENEVE_PORT 6081 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_mtu_conf - manage MTU setting 58 * @portnum: NFP port number of repr with requested MTU change 59 * @requested_val: MTU value requested for repr 60 * @ack: Received ack that MTU has been correctly set 61 * @wait_q: Wait queue for MTU acknowledgements 62 * @lock: Lock for setting/reading MTU variables 63 */ 64 struct nfp_mtu_conf { 65 u32 portnum; 66 unsigned int requested_val; 67 bool ack; 68 wait_queue_head_t wait_q; 69 spinlock_t lock; 70 }; 71 72 /** 73 * struct nfp_fl_lag - Flower APP priv data for link aggregation 74 * @work: Work queue for writing configs to the HW 75 * @lock: Lock to protect lag_group_list 76 * @group_list: List of all master/slave groups offloaded 77 * @ida_handle: IDA to handle group ids 78 * @pkt_num: Incremented for each config packet sent 79 * @batch_ver: Incremented for each batch of config packets 80 * @global_inst: Instance allocator for groups 81 * @rst_cfg: Marker to reset HW LAG config 82 * @retrans_skbs: Cmsgs that could not be processed by HW and require 83 * retransmission 84 */ 85 struct nfp_fl_lag { 86 struct delayed_work work; 87 struct mutex lock; 88 struct list_head group_list; 89 struct ida ida_handle; 90 unsigned int pkt_num; 91 unsigned int batch_ver; 92 u8 global_inst; 93 bool rst_cfg; 94 struct sk_buff_head retrans_skbs; 95 }; 96 97 /** 98 * struct nfp_flower_priv - Flower APP per-vNIC priv data 99 * @app: Back pointer to app 100 * @nn: Pointer to vNIC 101 * @mask_id_seed: Seed used for mask hash table 102 * @flower_version: HW version of flower 103 * @flower_ext_feats: Bitmap of extra features the HW supports 104 * @stats_ids: List of free stats ids 105 * @mask_ids: List of free mask ids 106 * @mask_table: Hash table used to store masks 107 * @stats_ring_size: Maximum number of allowed stats ids 108 * @flow_table: Hash table used to store flower rules 109 * @stats: Stored stats updates for flower rules 110 * @stats_lock: Lock for flower rule stats updates 111 * @cmsg_work: Workqueue for control messages processing 112 * @cmsg_skbs_high: List of higher priority skbs for control message 113 * processing 114 * @cmsg_skbs_low: List of lower priority skbs for control message 115 * processing 116 * @nfp_mac_off_list: List of MAC addresses to offload 117 * @nfp_mac_index_list: List of unique 8-bit indexes for non NFP netdevs 118 * @nfp_ipv4_off_list: List of IPv4 addresses to offload 119 * @nfp_neigh_off_list: List of neighbour offloads 120 * @nfp_mac_off_lock: Lock for the MAC address list 121 * @nfp_mac_index_lock: Lock for the MAC index list 122 * @nfp_ipv4_off_lock: Lock for the IPv4 address list 123 * @nfp_neigh_off_lock: Lock for the neighbour address list 124 * @nfp_mac_off_ids: IDA to manage id assignment for offloaded macs 125 * @nfp_mac_off_count: Number of MACs in address list 126 * @nfp_tun_neigh_nb: Notifier to monitor neighbour state 127 * @reify_replies: atomically stores the number of replies received 128 * from firmware for repr reify 129 * @reify_wait_queue: wait queue for repr reify response counting 130 * @mtu_conf: Configuration of repr MTU value 131 * @nfp_lag: Link aggregation data block 132 * @indr_block_cb_priv: List of priv data passed to indirect block cbs 133 */ 134 struct nfp_flower_priv { 135 struct nfp_app *app; 136 struct nfp_net *nn; 137 u32 mask_id_seed; 138 u64 flower_version; 139 u64 flower_ext_feats; 140 struct nfp_fl_stats_id stats_ids; 141 struct nfp_fl_mask_id mask_ids; 142 DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS); 143 u32 stats_ring_size; 144 struct rhashtable flow_table; 145 struct nfp_fl_stats *stats; 146 spinlock_t stats_lock; /* lock stats */ 147 struct work_struct cmsg_work; 148 struct sk_buff_head cmsg_skbs_high; 149 struct sk_buff_head cmsg_skbs_low; 150 struct list_head nfp_mac_off_list; 151 struct list_head nfp_mac_index_list; 152 struct list_head nfp_ipv4_off_list; 153 struct list_head nfp_neigh_off_list; 154 struct mutex nfp_mac_off_lock; 155 struct mutex nfp_mac_index_lock; 156 struct mutex nfp_ipv4_off_lock; 157 spinlock_t nfp_neigh_off_lock; 158 struct ida nfp_mac_off_ids; 159 int nfp_mac_off_count; 160 struct notifier_block nfp_tun_neigh_nb; 161 atomic_t reify_replies; 162 wait_queue_head_t reify_wait_queue; 163 struct nfp_mtu_conf mtu_conf; 164 struct nfp_fl_lag nfp_lag; 165 struct list_head indr_block_cb_priv; 166 }; 167 168 /** 169 * struct nfp_flower_repr_priv - Flower APP per-repr priv data 170 * @lag_port_flags: Extended port flags to record lag state of repr 171 */ 172 struct nfp_flower_repr_priv { 173 unsigned long lag_port_flags; 174 }; 175 176 struct nfp_fl_key_ls { 177 u32 key_layer_two; 178 u8 key_layer; 179 int key_size; 180 }; 181 182 struct nfp_fl_rule_metadata { 183 u8 key_len; 184 u8 mask_len; 185 u8 act_len; 186 u8 flags; 187 __be32 host_ctx_id; 188 __be64 host_cookie __packed; 189 __be64 flow_version __packed; 190 __be32 shortcut; 191 }; 192 193 struct nfp_fl_stats { 194 u64 pkts; 195 u64 bytes; 196 u64 used; 197 }; 198 199 struct nfp_fl_payload { 200 struct nfp_fl_rule_metadata meta; 201 unsigned long tc_flower_cookie; 202 struct rhash_head fl_node; 203 struct rcu_head rcu; 204 __be32 nfp_tun_ipv4_addr; 205 struct net_device *ingress_dev; 206 char *unmasked_data; 207 char *mask_data; 208 char *action_data; 209 }; 210 211 extern const struct rhashtable_params nfp_flower_table_params; 212 213 struct nfp_fl_stats_frame { 214 __be32 stats_con_id; 215 __be32 pkt_count; 216 __be64 byte_count; 217 __be64 stats_cookie; 218 }; 219 220 int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count); 221 void nfp_flower_metadata_cleanup(struct nfp_app *app); 222 223 int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev, 224 enum tc_setup_type type, void *type_data); 225 int nfp_flower_compile_flow_match(struct nfp_app *app, 226 struct tc_cls_flower_offload *flow, 227 struct nfp_fl_key_ls *key_ls, 228 struct net_device *netdev, 229 struct nfp_fl_payload *nfp_flow, 230 enum nfp_flower_tun_type tun_type); 231 int nfp_flower_compile_action(struct nfp_app *app, 232 struct tc_cls_flower_offload *flow, 233 struct net_device *netdev, 234 struct nfp_fl_payload *nfp_flow); 235 int nfp_compile_flow_metadata(struct nfp_app *app, 236 struct tc_cls_flower_offload *flow, 237 struct nfp_fl_payload *nfp_flow, 238 struct net_device *netdev); 239 int nfp_modify_flow_metadata(struct nfp_app *app, 240 struct nfp_fl_payload *nfp_flow); 241 242 struct nfp_fl_payload * 243 nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie, 244 struct net_device *netdev); 245 struct nfp_fl_payload * 246 nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie); 247 248 void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb); 249 250 int nfp_tunnel_config_start(struct nfp_app *app); 251 void nfp_tunnel_config_stop(struct nfp_app *app); 252 int nfp_tunnel_mac_event_handler(struct nfp_app *app, 253 struct net_device *netdev, 254 unsigned long event, void *ptr); 255 void nfp_tunnel_write_macs(struct nfp_app *app); 256 void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4); 257 void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4); 258 void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb); 259 void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb); 260 void nfp_flower_lag_init(struct nfp_fl_lag *lag); 261 void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag); 262 int nfp_flower_lag_reset(struct nfp_fl_lag *lag); 263 int nfp_flower_lag_netdev_event(struct nfp_flower_priv *priv, 264 struct net_device *netdev, 265 unsigned long event, void *ptr); 266 bool nfp_flower_lag_unprocessed_msg(struct nfp_app *app, struct sk_buff *skb); 267 int nfp_flower_lag_populate_pre_action(struct nfp_app *app, 268 struct net_device *master, 269 struct nfp_fl_pre_lag *pre_act); 270 int nfp_flower_lag_get_output_id(struct nfp_app *app, 271 struct net_device *master); 272 int nfp_flower_reg_indir_block_handler(struct nfp_app *app, 273 struct net_device *netdev, 274 unsigned long event); 275 276 #endif 277