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_CTX_DONT_CARE cpu_to_be32(0xffffffff) 24 #define NFP_FL_STATS_ELEM_RS FIELD_SIZEOF(struct nfp_fl_stats_id, \ 25 init_unalloc) 26 #define NFP_FLOWER_MASK_ENTRY_RS 256 27 #define NFP_FLOWER_MASK_ELEMENT_RS 1 28 #define NFP_FLOWER_MASK_HASH_BITS 10 29 30 #define NFP_FL_META_FLAG_MANAGE_MASK BIT(7) 31 32 #define NFP_FL_MASK_REUSE_TIME_NS 40000 33 #define NFP_FL_MASK_ID_LOCATION 1 34 35 #define NFP_FL_VXLAN_PORT 4789 36 #define NFP_FL_GENEVE_PORT 6081 37 38 /* Extra features bitmap. */ 39 #define NFP_FL_FEATS_GENEVE BIT(0) 40 #define NFP_FL_NBI_MTU_SETTING BIT(1) 41 #define NFP_FL_FEATS_GENEVE_OPT BIT(2) 42 #define NFP_FL_FEATS_VLAN_PCP BIT(3) 43 #define NFP_FL_FEATS_LAG BIT(31) 44 45 struct nfp_fl_mask_id { 46 struct circ_buf mask_id_free_list; 47 ktime_t *last_used; 48 u8 init_unallocated; 49 }; 50 51 struct nfp_fl_stats_id { 52 struct circ_buf free_list; 53 u32 init_unalloc; 54 u8 repeated_em_count; 55 }; 56 57 /** 58 * struct nfp_mtu_conf - manage MTU setting 59 * @portnum: NFP port number of repr with requested MTU change 60 * @requested_val: MTU value requested for repr 61 * @ack: Received ack that MTU has been correctly set 62 * @wait_q: Wait queue for MTU acknowledgements 63 * @lock: Lock for setting/reading MTU variables 64 */ 65 struct nfp_mtu_conf { 66 u32 portnum; 67 unsigned int requested_val; 68 bool ack; 69 wait_queue_head_t wait_q; 70 spinlock_t lock; 71 }; 72 73 /** 74 * struct nfp_fl_lag - Flower APP priv data for link aggregation 75 * @work: Work queue for writing configs to the HW 76 * @lock: Lock to protect lag_group_list 77 * @group_list: List of all master/slave groups offloaded 78 * @ida_handle: IDA to handle group ids 79 * @pkt_num: Incremented for each config packet sent 80 * @batch_ver: Incremented for each batch of config packets 81 * @global_inst: Instance allocator for groups 82 * @rst_cfg: Marker to reset HW LAG config 83 * @retrans_skbs: Cmsgs that could not be processed by HW and require 84 * retransmission 85 */ 86 struct nfp_fl_lag { 87 struct delayed_work work; 88 struct mutex lock; 89 struct list_head group_list; 90 struct ida ida_handle; 91 unsigned int pkt_num; 92 unsigned int batch_ver; 93 u8 global_inst; 94 bool rst_cfg; 95 struct sk_buff_head retrans_skbs; 96 }; 97 98 /** 99 * struct nfp_flower_priv - Flower APP per-vNIC priv data 100 * @app: Back pointer to app 101 * @nn: Pointer to vNIC 102 * @mask_id_seed: Seed used for mask hash table 103 * @flower_version: HW version of flower 104 * @flower_ext_feats: Bitmap of extra features the HW supports 105 * @stats_ids: List of free stats ids 106 * @mask_ids: List of free mask ids 107 * @mask_table: Hash table used to store masks 108 * @stats_ring_size: Maximum number of allowed stats ids 109 * @flow_table: Hash table used to store flower rules 110 * @stats: Stored stats updates for flower rules 111 * @stats_lock: Lock for flower rule stats updates 112 * @cmsg_work: Workqueue for control messages processing 113 * @cmsg_skbs_high: List of higher priority skbs for control message 114 * processing 115 * @cmsg_skbs_low: List of lower priority skbs for control message 116 * processing 117 * @nfp_mac_off_list: List of MAC addresses to offload 118 * @nfp_mac_index_list: List of unique 8-bit indexes for non NFP netdevs 119 * @nfp_ipv4_off_list: List of IPv4 addresses to offload 120 * @nfp_neigh_off_list: List of neighbour offloads 121 * @nfp_mac_off_lock: Lock for the MAC address list 122 * @nfp_mac_index_lock: Lock for the MAC index list 123 * @nfp_ipv4_off_lock: Lock for the IPv4 address list 124 * @nfp_neigh_off_lock: Lock for the neighbour address list 125 * @nfp_mac_off_ids: IDA to manage id assignment for offloaded macs 126 * @nfp_mac_off_count: Number of MACs in address list 127 * @nfp_tun_neigh_nb: Notifier to monitor neighbour state 128 * @reify_replies: atomically stores the number of replies received 129 * from firmware for repr reify 130 * @reify_wait_queue: wait queue for repr reify response counting 131 * @mtu_conf: Configuration of repr MTU value 132 * @nfp_lag: Link aggregation data block 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 }; 166 167 /** 168 * struct nfp_flower_repr_priv - Flower APP per-repr priv data 169 * @lag_port_flags: Extended port flags to record lag state of repr 170 */ 171 struct nfp_flower_repr_priv { 172 unsigned long lag_port_flags; 173 }; 174 175 struct nfp_fl_key_ls { 176 u32 key_layer_two; 177 u8 key_layer; 178 int key_size; 179 }; 180 181 struct nfp_fl_rule_metadata { 182 u8 key_len; 183 u8 mask_len; 184 u8 act_len; 185 u8 flags; 186 __be32 host_ctx_id; 187 __be64 host_cookie __packed; 188 __be64 flow_version __packed; 189 __be32 shortcut; 190 }; 191 192 struct nfp_fl_stats { 193 u64 pkts; 194 u64 bytes; 195 u64 used; 196 }; 197 198 struct nfp_fl_payload { 199 struct nfp_fl_rule_metadata meta; 200 unsigned long tc_flower_cookie; 201 struct rhash_head fl_node; 202 struct rcu_head rcu; 203 __be32 nfp_tun_ipv4_addr; 204 struct net_device *ingress_dev; 205 char *unmasked_data; 206 char *mask_data; 207 char *action_data; 208 bool ingress_offload; 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 tc_cls_flower_offload *flow, 226 struct nfp_fl_key_ls *key_ls, 227 struct net_device *netdev, 228 struct nfp_fl_payload *nfp_flow, 229 enum nfp_flower_tun_type tun_type); 230 int nfp_flower_compile_action(struct nfp_app *app, 231 struct tc_cls_flower_offload *flow, 232 struct net_device *netdev, 233 struct nfp_fl_payload *nfp_flow); 234 int nfp_compile_flow_metadata(struct nfp_app *app, 235 struct tc_cls_flower_offload *flow, 236 struct nfp_fl_payload *nfp_flow, 237 struct net_device *netdev); 238 int nfp_modify_flow_metadata(struct nfp_app *app, 239 struct nfp_fl_payload *nfp_flow); 240 241 struct nfp_fl_payload * 242 nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie, 243 struct net_device *netdev, __be32 host_ctx); 244 struct nfp_fl_payload * 245 nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie); 246 247 void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb); 248 249 int nfp_tunnel_config_start(struct nfp_app *app); 250 void nfp_tunnel_config_stop(struct nfp_app *app); 251 int nfp_tunnel_mac_event_handler(struct nfp_app *app, 252 struct net_device *netdev, 253 unsigned long event, void *ptr); 254 void nfp_tunnel_write_macs(struct nfp_app *app); 255 void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4); 256 void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4); 257 void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb); 258 void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb); 259 int nfp_flower_setup_tc_egress_cb(enum tc_setup_type type, void *type_data, 260 void *cb_priv); 261 void nfp_flower_lag_init(struct nfp_fl_lag *lag); 262 void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag); 263 int nfp_flower_lag_reset(struct nfp_fl_lag *lag); 264 int nfp_flower_lag_netdev_event(struct nfp_flower_priv *priv, 265 struct net_device *netdev, 266 unsigned long event, void *ptr); 267 bool nfp_flower_lag_unprocessed_msg(struct nfp_app *app, struct sk_buff *skb); 268 int nfp_flower_lag_populate_pre_action(struct nfp_app *app, 269 struct net_device *master, 270 struct nfp_fl_pre_lag *pre_act); 271 int nfp_flower_lag_get_output_id(struct nfp_app *app, 272 struct net_device *master); 273 274 #endif 275