2018-10-11 08:57:42 -07:00
|
|
|
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
|
|
|
|
|
/* Copyright (C) 2017-2018 Netronome Systems, Inc. */
|
2017-06-29 22:08:13 +02:00
|
|
|
|
|
|
|
|
#ifndef __NFP_FLOWER_H__
|
|
|
|
|
#define __NFP_FLOWER_H__ 1
|
|
|
|
|
|
2017-12-19 17:58:28 +01:00
|
|
|
#include "cmsg.h"
|
|
|
|
|
|
2017-06-29 22:08:17 +02:00
|
|
|
#include <linux/circ_buf.h>
|
|
|
|
|
#include <linux/hashtable.h>
|
2018-10-08 18:57:34 -07:00
|
|
|
#include <linux/rhashtable.h>
|
2017-06-29 22:08:17 +02:00
|
|
|
#include <linux/time64.h>
|
2017-06-29 22:08:13 +02:00
|
|
|
#include <linux/types.h>
|
2017-08-07 10:15:32 +02:00
|
|
|
#include <net/pkt_cls.h>
|
2018-02-15 20:19:09 -08:00
|
|
|
#include <net/tcp.h>
|
2017-08-16 09:37:43 +02:00
|
|
|
#include <linux/workqueue.h>
|
2018-05-23 19:22:53 -07:00
|
|
|
#include <linux/idr.h>
|
2017-06-29 22:08:13 +02:00
|
|
|
|
2018-05-23 19:22:55 -07:00
|
|
|
struct nfp_fl_pre_lag;
|
2017-06-29 22:08:13 +02:00
|
|
|
struct net_device;
|
|
|
|
|
struct nfp_app;
|
|
|
|
|
|
2019-01-15 19:06:52 -08:00
|
|
|
#define NFP_FL_STAT_ID_MU_NUM GENMASK(31, 22)
|
|
|
|
|
#define NFP_FL_STAT_ID_STAT GENMASK(21, 0)
|
|
|
|
|
|
2018-10-08 18:57:36 -07:00
|
|
|
#define NFP_FL_STATS_ELEM_RS FIELD_SIZEOF(struct nfp_fl_stats_id, \
|
|
|
|
|
init_unalloc)
|
2017-06-29 22:08:17 +02:00
|
|
|
#define NFP_FLOWER_MASK_ENTRY_RS 256
|
|
|
|
|
#define NFP_FLOWER_MASK_ELEMENT_RS 1
|
|
|
|
|
#define NFP_FLOWER_MASK_HASH_BITS 10
|
|
|
|
|
|
2017-11-16 17:06:39 -08:00
|
|
|
#define NFP_FL_META_FLAG_MANAGE_MASK BIT(7)
|
2017-06-29 22:08:17 +02:00
|
|
|
|
|
|
|
|
#define NFP_FL_MASK_REUSE_TIME_NS 40000
|
|
|
|
|
#define NFP_FL_MASK_ID_LOCATION 1
|
|
|
|
|
|
2017-09-25 12:23:36 +02:00
|
|
|
#define NFP_FL_VXLAN_PORT 4789
|
2017-12-19 17:58:28 +01:00
|
|
|
#define NFP_FL_GENEVE_PORT 6081
|
|
|
|
|
|
|
|
|
|
/* Extra features bitmap. */
|
|
|
|
|
#define NFP_FL_FEATS_GENEVE BIT(0)
|
2018-03-28 18:50:07 -07:00
|
|
|
#define NFP_FL_NBI_MTU_SETTING BIT(1)
|
2018-08-07 17:36:02 +02:00
|
|
|
#define NFP_FL_FEATS_GENEVE_OPT BIT(2)
|
2018-09-11 06:38:44 -07:00
|
|
|
#define NFP_FL_FEATS_VLAN_PCP BIT(3)
|
2018-05-23 19:22:50 -07:00
|
|
|
#define NFP_FL_FEATS_LAG BIT(31)
|
2017-09-25 12:23:36 +02:00
|
|
|
|
2017-06-29 22:08:17 +02:00
|
|
|
struct nfp_fl_mask_id {
|
|
|
|
|
struct circ_buf mask_id_free_list;
|
2018-07-11 14:29:53 +02:00
|
|
|
ktime_t *last_used;
|
2017-06-29 22:08:17 +02:00
|
|
|
u8 init_unallocated;
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-29 22:08:18 +02:00
|
|
|
struct nfp_fl_stats_id {
|
|
|
|
|
struct circ_buf free_list;
|
|
|
|
|
u32 init_unalloc;
|
|
|
|
|
u8 repeated_em_count;
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-15 19:06:53 -08:00
|
|
|
/**
|
|
|
|
|
* struct nfp_fl_tunnel_offloads - priv data for tunnel offloads
|
|
|
|
|
* @mac_index_list: List of unique 8-bit indexes for non NFP netdevs
|
|
|
|
|
* @ipv4_off_list: List of IPv4 addresses to offload
|
|
|
|
|
* @neigh_off_list: List of neighbour offloads
|
|
|
|
|
* @mac_index_lock: Lock for the MAC index list
|
|
|
|
|
* @ipv4_off_lock: Lock for the IPv4 address list
|
|
|
|
|
* @neigh_off_lock: Lock for the neighbour address list
|
|
|
|
|
* @mac_off_ids: IDA to manage id assignment for offloaded MACs
|
|
|
|
|
* @neigh_nb: Notifier to monitor neighbour state
|
|
|
|
|
*/
|
|
|
|
|
struct nfp_fl_tunnel_offloads {
|
|
|
|
|
struct list_head mac_index_list;
|
|
|
|
|
struct list_head ipv4_off_list;
|
|
|
|
|
struct list_head neigh_off_list;
|
|
|
|
|
struct mutex mac_index_lock;
|
|
|
|
|
struct mutex ipv4_off_lock;
|
|
|
|
|
spinlock_t neigh_off_lock;
|
|
|
|
|
struct ida mac_off_ids;
|
|
|
|
|
struct notifier_block neigh_nb;
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-28 18:50:07 -07:00
|
|
|
/**
|
|
|
|
|
* struct nfp_mtu_conf - manage MTU setting
|
|
|
|
|
* @portnum: NFP port number of repr with requested MTU change
|
|
|
|
|
* @requested_val: MTU value requested for repr
|
|
|
|
|
* @ack: Received ack that MTU has been correctly set
|
|
|
|
|
* @wait_q: Wait queue for MTU acknowledgements
|
|
|
|
|
* @lock: Lock for setting/reading MTU variables
|
|
|
|
|
*/
|
|
|
|
|
struct nfp_mtu_conf {
|
|
|
|
|
u32 portnum;
|
|
|
|
|
unsigned int requested_val;
|
|
|
|
|
bool ack;
|
|
|
|
|
wait_queue_head_t wait_q;
|
|
|
|
|
spinlock_t lock;
|
|
|
|
|
};
|
|
|
|
|
|
2018-05-23 19:22:53 -07:00
|
|
|
/**
|
|
|
|
|
* struct nfp_fl_lag - Flower APP priv data for link aggregation
|
|
|
|
|
* @work: Work queue for writing configs to the HW
|
|
|
|
|
* @lock: Lock to protect lag_group_list
|
|
|
|
|
* @group_list: List of all master/slave groups offloaded
|
|
|
|
|
* @ida_handle: IDA to handle group ids
|
|
|
|
|
* @pkt_num: Incremented for each config packet sent
|
|
|
|
|
* @batch_ver: Incremented for each batch of config packets
|
|
|
|
|
* @global_inst: Instance allocator for groups
|
|
|
|
|
* @rst_cfg: Marker to reset HW LAG config
|
2018-05-23 19:22:54 -07:00
|
|
|
* @retrans_skbs: Cmsgs that could not be processed by HW and require
|
|
|
|
|
* retransmission
|
2018-05-23 19:22:53 -07:00
|
|
|
*/
|
|
|
|
|
struct nfp_fl_lag {
|
|
|
|
|
struct delayed_work work;
|
|
|
|
|
struct mutex lock;
|
|
|
|
|
struct list_head group_list;
|
|
|
|
|
struct ida ida_handle;
|
|
|
|
|
unsigned int pkt_num;
|
|
|
|
|
unsigned int batch_ver;
|
|
|
|
|
u8 global_inst;
|
|
|
|
|
bool rst_cfg;
|
2018-05-23 19:22:54 -07:00
|
|
|
struct sk_buff_head retrans_skbs;
|
2018-05-23 19:22:53 -07:00
|
|
|
};
|
|
|
|
|
|
2017-06-29 22:08:17 +02:00
|
|
|
/**
|
|
|
|
|
* struct nfp_flower_priv - Flower APP per-vNIC priv data
|
2017-09-02 18:26:00 -07:00
|
|
|
* @app: Back pointer to app
|
2017-06-29 22:08:17 +02:00
|
|
|
* @nn: Pointer to vNIC
|
|
|
|
|
* @mask_id_seed: Seed used for mask hash table
|
|
|
|
|
* @flower_version: HW version of flower
|
2017-12-19 17:58:27 +01:00
|
|
|
* @flower_ext_feats: Bitmap of extra features the HW supports
|
2017-06-29 22:08:18 +02:00
|
|
|
* @stats_ids: List of free stats ids
|
2017-06-29 22:08:17 +02:00
|
|
|
* @mask_ids: List of free mask ids
|
|
|
|
|
* @mask_table: Hash table used to store masks
|
2018-10-08 18:57:36 -07:00
|
|
|
* @stats_ring_size: Maximum number of allowed stats ids
|
2017-06-29 22:08:17 +02:00
|
|
|
* @flow_table: Hash table used to store flower rules
|
2018-10-08 18:57:35 -07:00
|
|
|
* @stats: Stored stats updates for flower rules
|
|
|
|
|
* @stats_lock: Lock for flower rule stats updates
|
2017-08-16 09:37:43 +02:00
|
|
|
* @cmsg_work: Workqueue for control messages processing
|
2018-04-11 16:47:38 -07:00
|
|
|
* @cmsg_skbs_high: List of higher priority skbs for control message
|
|
|
|
|
* processing
|
|
|
|
|
* @cmsg_skbs_low: List of lower priority skbs for control message
|
|
|
|
|
* processing
|
2019-01-15 19:06:53 -08:00
|
|
|
* @tun: Tunnel offload data
|
2018-01-02 19:19:01 -08:00
|
|
|
* @reify_replies: atomically stores the number of replies received
|
|
|
|
|
* from firmware for repr reify
|
|
|
|
|
* @reify_wait_queue: wait queue for repr reify response counting
|
2018-03-28 18:50:07 -07:00
|
|
|
* @mtu_conf: Configuration of repr MTU value
|
2018-05-23 19:22:53 -07:00
|
|
|
* @nfp_lag: Link aggregation data block
|
2018-11-09 21:21:29 -08:00
|
|
|
* @indr_block_cb_priv: List of priv data passed to indirect block cbs
|
2019-01-15 19:06:52 -08:00
|
|
|
* @active_mem_unit: Current active memory unit for flower rules
|
|
|
|
|
* @total_mem_units: Total number of available memory units for flower rules
|
2017-06-29 22:08:17 +02:00
|
|
|
*/
|
|
|
|
|
struct nfp_flower_priv {
|
2017-09-02 18:26:00 -07:00
|
|
|
struct nfp_app *app;
|
2017-06-29 22:08:17 +02:00
|
|
|
struct nfp_net *nn;
|
|
|
|
|
u32 mask_id_seed;
|
|
|
|
|
u64 flower_version;
|
2017-12-19 17:58:27 +01:00
|
|
|
u64 flower_ext_feats;
|
2017-06-29 22:08:18 +02:00
|
|
|
struct nfp_fl_stats_id stats_ids;
|
2017-06-29 22:08:17 +02:00
|
|
|
struct nfp_fl_mask_id mask_ids;
|
|
|
|
|
DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS);
|
2018-10-08 18:57:36 -07:00
|
|
|
u32 stats_ring_size;
|
2018-10-08 18:57:34 -07:00
|
|
|
struct rhashtable flow_table;
|
2018-10-08 18:57:35 -07:00
|
|
|
struct nfp_fl_stats *stats;
|
|
|
|
|
spinlock_t stats_lock; /* lock stats */
|
2017-08-16 09:37:43 +02:00
|
|
|
struct work_struct cmsg_work;
|
2018-04-11 16:47:38 -07:00
|
|
|
struct sk_buff_head cmsg_skbs_high;
|
|
|
|
|
struct sk_buff_head cmsg_skbs_low;
|
2019-01-15 19:06:53 -08:00
|
|
|
struct nfp_fl_tunnel_offloads tun;
|
2018-01-02 19:19:01 -08:00
|
|
|
atomic_t reify_replies;
|
|
|
|
|
wait_queue_head_t reify_wait_queue;
|
2018-03-28 18:50:07 -07:00
|
|
|
struct nfp_mtu_conf mtu_conf;
|
2018-05-23 19:22:53 -07:00
|
|
|
struct nfp_fl_lag nfp_lag;
|
2018-11-09 21:21:29 -08:00
|
|
|
struct list_head indr_block_cb_priv;
|
2019-01-15 19:06:52 -08:00
|
|
|
unsigned int active_mem_unit;
|
|
|
|
|
unsigned int total_mem_units;
|
2017-06-29 22:08:17 +02:00
|
|
|
};
|
|
|
|
|
|
2018-05-23 19:22:51 -07:00
|
|
|
/**
|
|
|
|
|
* struct nfp_flower_repr_priv - Flower APP per-repr priv data
|
|
|
|
|
* @lag_port_flags: Extended port flags to record lag state of repr
|
|
|
|
|
*/
|
|
|
|
|
struct nfp_flower_repr_priv {
|
|
|
|
|
unsigned long lag_port_flags;
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-29 22:08:14 +02:00
|
|
|
struct nfp_fl_key_ls {
|
|
|
|
|
u32 key_layer_two;
|
|
|
|
|
u8 key_layer;
|
|
|
|
|
int key_size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct nfp_fl_rule_metadata {
|
|
|
|
|
u8 key_len;
|
|
|
|
|
u8 mask_len;
|
|
|
|
|
u8 act_len;
|
|
|
|
|
u8 flags;
|
|
|
|
|
__be32 host_ctx_id;
|
|
|
|
|
__be64 host_cookie __packed;
|
|
|
|
|
__be64 flow_version __packed;
|
|
|
|
|
__be32 shortcut;
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-29 22:08:18 +02:00
|
|
|
struct nfp_fl_stats {
|
|
|
|
|
u64 pkts;
|
|
|
|
|
u64 bytes;
|
|
|
|
|
u64 used;
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-29 22:08:14 +02:00
|
|
|
struct nfp_fl_payload {
|
|
|
|
|
struct nfp_fl_rule_metadata meta;
|
2017-06-29 22:08:17 +02:00
|
|
|
unsigned long tc_flower_cookie;
|
2018-10-08 18:57:34 -07:00
|
|
|
struct rhash_head fl_node;
|
2017-06-29 22:08:17 +02:00
|
|
|
struct rcu_head rcu;
|
2017-09-25 12:23:39 +02:00
|
|
|
__be32 nfp_tun_ipv4_addr;
|
2018-04-24 21:17:03 -07:00
|
|
|
struct net_device *ingress_dev;
|
2017-06-29 22:08:14 +02:00
|
|
|
char *unmasked_data;
|
|
|
|
|
char *mask_data;
|
|
|
|
|
char *action_data;
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-08 18:57:34 -07:00
|
|
|
extern const struct rhashtable_params nfp_flower_table_params;
|
|
|
|
|
|
2017-06-29 22:08:18 +02:00
|
|
|
struct nfp_fl_stats_frame {
|
|
|
|
|
__be32 stats_con_id;
|
|
|
|
|
__be32 pkt_count;
|
|
|
|
|
__be64 byte_count;
|
|
|
|
|
__be64 stats_cookie;
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-15 19:06:52 -08:00
|
|
|
int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count,
|
|
|
|
|
unsigned int host_ctx_split);
|
2017-06-29 22:08:17 +02:00
|
|
|
void nfp_flower_metadata_cleanup(struct nfp_app *app);
|
|
|
|
|
|
2017-06-29 22:08:13 +02:00
|
|
|
int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
|
2017-08-07 10:15:32 +02:00
|
|
|
enum tc_setup_type type, void *type_data);
|
2018-11-09 21:21:27 -08:00
|
|
|
int nfp_flower_compile_flow_match(struct nfp_app *app,
|
|
|
|
|
struct tc_cls_flower_offload *flow,
|
2017-06-29 22:08:15 +02:00
|
|
|
struct nfp_fl_key_ls *key_ls,
|
|
|
|
|
struct net_device *netdev,
|
2017-12-19 17:58:28 +01:00
|
|
|
struct nfp_fl_payload *nfp_flow,
|
|
|
|
|
enum nfp_flower_tun_type tun_type);
|
2018-05-23 19:22:55 -07:00
|
|
|
int nfp_flower_compile_action(struct nfp_app *app,
|
|
|
|
|
struct tc_cls_flower_offload *flow,
|
2017-06-29 22:08:16 +02:00
|
|
|
struct net_device *netdev,
|
|
|
|
|
struct nfp_fl_payload *nfp_flow);
|
2017-06-29 22:08:17 +02:00
|
|
|
int nfp_compile_flow_metadata(struct nfp_app *app,
|
|
|
|
|
struct tc_cls_flower_offload *flow,
|
2018-04-24 21:17:03 -07:00
|
|
|
struct nfp_fl_payload *nfp_flow,
|
|
|
|
|
struct net_device *netdev);
|
2017-06-29 22:08:17 +02:00
|
|
|
int nfp_modify_flow_metadata(struct nfp_app *app,
|
|
|
|
|
struct nfp_fl_payload *nfp_flow);
|
|
|
|
|
|
|
|
|
|
struct nfp_fl_payload *
|
2018-04-24 21:17:03 -07:00
|
|
|
nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie,
|
2018-11-09 21:21:31 -08:00
|
|
|
struct net_device *netdev);
|
2017-06-29 22:08:17 +02:00
|
|
|
struct nfp_fl_payload *
|
|
|
|
|
nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
|
2017-06-29 22:08:15 +02:00
|
|
|
|
2017-06-29 22:08:18 +02:00
|
|
|
void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb);
|
|
|
|
|
|
2017-09-25 12:23:38 +02:00
|
|
|
int nfp_tunnel_config_start(struct nfp_app *app);
|
|
|
|
|
void nfp_tunnel_config_stop(struct nfp_app *app);
|
2018-11-06 17:07:34 -08:00
|
|
|
int nfp_tunnel_mac_event_handler(struct nfp_app *app,
|
|
|
|
|
struct net_device *netdev,
|
|
|
|
|
unsigned long event, void *ptr);
|
2017-09-25 12:23:39 +02:00
|
|
|
void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4);
|
|
|
|
|
void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4);
|
2017-09-25 12:23:40 +02:00
|
|
|
void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb);
|
2017-09-25 12:23:41 +02:00
|
|
|
void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb);
|
2018-05-23 19:22:53 -07:00
|
|
|
void nfp_flower_lag_init(struct nfp_fl_lag *lag);
|
|
|
|
|
void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag);
|
|
|
|
|
int nfp_flower_lag_reset(struct nfp_fl_lag *lag);
|
2018-11-06 17:07:34 -08:00
|
|
|
int nfp_flower_lag_netdev_event(struct nfp_flower_priv *priv,
|
|
|
|
|
struct net_device *netdev,
|
|
|
|
|
unsigned long event, void *ptr);
|
2018-05-23 19:22:54 -07:00
|
|
|
bool nfp_flower_lag_unprocessed_msg(struct nfp_app *app, struct sk_buff *skb);
|
2018-05-23 19:22:55 -07:00
|
|
|
int nfp_flower_lag_populate_pre_action(struct nfp_app *app,
|
|
|
|
|
struct net_device *master,
|
|
|
|
|
struct nfp_fl_pre_lag *pre_act);
|
|
|
|
|
int nfp_flower_lag_get_output_id(struct nfp_app *app,
|
|
|
|
|
struct net_device *master);
|
2018-11-09 21:21:29 -08:00
|
|
|
int nfp_flower_reg_indir_block_handler(struct nfp_app *app,
|
|
|
|
|
struct net_device *netdev,
|
|
|
|
|
unsigned long event);
|
2017-09-25 12:23:38 +02:00
|
|
|
|
2017-06-29 22:08:13 +02:00
|
|
|
#endif
|