1c9422999SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2e6445719SPravin B Shelar /* 3e6445719SPravin B Shelar * Copyright (c) 2007-2013 Nicira, Inc. 4e6445719SPravin B Shelar */ 5e6445719SPravin B Shelar 6e6445719SPravin B Shelar #ifndef FLOW_TABLE_H 7e6445719SPravin B Shelar #define FLOW_TABLE_H 1 8e6445719SPravin B Shelar 9e6445719SPravin B Shelar #include <linux/kernel.h> 10e6445719SPravin B Shelar #include <linux/netlink.h> 11e6445719SPravin B Shelar #include <linux/openvswitch.h> 12e6445719SPravin B Shelar #include <linux/spinlock.h> 13e6445719SPravin B Shelar #include <linux/types.h> 14e6445719SPravin B Shelar #include <linux/rcupdate.h> 15e6445719SPravin B Shelar #include <linux/if_ether.h> 16e6445719SPravin B Shelar #include <linux/in6.h> 17e6445719SPravin B Shelar #include <linux/jiffies.h> 18e6445719SPravin B Shelar #include <linux/time.h> 19e6445719SPravin B Shelar 20e6445719SPravin B Shelar #include <net/inet_ecn.h> 21e6445719SPravin B Shelar #include <net/ip_tunnels.h> 22e6445719SPravin B Shelar 23e6445719SPravin B Shelar #include "flow.h" 24e6445719SPravin B Shelar 2504b7d136STonghao Zhang struct mask_cache_entry { 2604b7d136STonghao Zhang u32 skb_hash; 2704b7d136STonghao Zhang u32 mask_index; 2804b7d136STonghao Zhang }; 2904b7d136STonghao Zhang 309bf24f59SEelco Chaudron struct mask_cache { 319bf24f59SEelco Chaudron struct rcu_head rcu; 329bf24f59SEelco Chaudron u32 cache_size; /* Must be ^2 value. */ 339bf24f59SEelco Chaudron struct mask_cache_entry __percpu *mask_cache; 349bf24f59SEelco Chaudron }; 359bf24f59SEelco Chaudron 36eac87c41SEelco Chaudron struct mask_count { 37eac87c41SEelco Chaudron int index; 38eac87c41SEelco Chaudron u64 counter; 39eac87c41SEelco Chaudron }; 40eac87c41SEelco Chaudron 41f981fc3dSEelco Chaudron struct mask_array_stats { 42f981fc3dSEelco Chaudron struct u64_stats_sync syncp; 43f981fc3dSEelco Chaudron u64 usage_cntrs[]; 44f981fc3dSEelco Chaudron }; 45f981fc3dSEelco Chaudron 464bc63b1bSTonghao Zhang struct mask_array { 474bc63b1bSTonghao Zhang struct rcu_head rcu; 484bc63b1bSTonghao Zhang int count, max; 49f981fc3dSEelco Chaudron struct mask_array_stats __percpu *masks_usage_stats; 50eac87c41SEelco Chaudron u64 *masks_usage_zero_cntr; 514bc63b1bSTonghao Zhang struct sw_flow_mask __rcu *masks[]; 524bc63b1bSTonghao Zhang }; 534bc63b1bSTonghao Zhang 54b637e498SPravin B Shelar struct table_instance { 55ee9c5e67SKent Overstreet struct hlist_head *buckets; 56b637e498SPravin B Shelar unsigned int n_buckets; 57e6445719SPravin B Shelar struct rcu_head rcu; 58e6445719SPravin B Shelar int node_ver; 59e6445719SPravin B Shelar u32 hash_seed; 60e6445719SPravin B Shelar }; 61e6445719SPravin B Shelar 62b637e498SPravin B Shelar struct flow_table { 63b637e498SPravin B Shelar struct table_instance __rcu *ti; 6474ed7ab9SJoe Stringer struct table_instance __rcu *ufid_ti; 659bf24f59SEelco Chaudron struct mask_cache __rcu *mask_cache; 664bc63b1bSTonghao Zhang struct mask_array __rcu *mask_array; 67b637e498SPravin B Shelar unsigned long last_rehash; 68b637e498SPravin B Shelar unsigned int count; 6974ed7ab9SJoe Stringer unsigned int ufid_count; 70b637e498SPravin B Shelar }; 71b637e498SPravin B Shelar 7263e7959cSJarno Rajahalme extern struct kmem_cache *flow_stats_cache; 7363e7959cSJarno Rajahalme 74e6445719SPravin B Shelar int ovs_flow_init(void); 75e6445719SPravin B Shelar void ovs_flow_exit(void); 76e6445719SPravin B Shelar 7723dabf88SJarno Rajahalme struct sw_flow *ovs_flow_alloc(void); 78e6445719SPravin B Shelar void ovs_flow_free(struct sw_flow *, bool deferred); 79e6445719SPravin B Shelar 80b637e498SPravin B Shelar int ovs_flow_tbl_init(struct flow_table *); 8112eb18f7SThomas Graf int ovs_flow_tbl_count(const struct flow_table *table); 829b996e54SPravin B Shelar void ovs_flow_tbl_destroy(struct flow_table *table); 83b637e498SPravin B Shelar int ovs_flow_tbl_flush(struct flow_table *flow_table); 84e6445719SPravin B Shelar 85618ed0c8SPravin B Shelar int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow, 8612eb18f7SThomas Graf const struct sw_flow_mask *mask); 87e6445719SPravin B Shelar void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow); 881bd7116fSAndy Zhou int ovs_flow_tbl_num_masks(const struct flow_table *table); 899bf24f59SEelco Chaudron u32 ovs_flow_tbl_masks_cache_size(const struct flow_table *table); 909bf24f59SEelco Chaudron int ovs_flow_tbl_masks_cache_resize(struct flow_table *table, u32 size); 91b637e498SPravin B Shelar struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table, 92e6445719SPravin B Shelar u32 *bucket, u32 *idx); 935bb50632SAndy Zhou struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *, 941bd7116fSAndy Zhou const struct sw_flow_key *, 9504b7d136STonghao Zhang u32 skb_hash, 969d2f627bSEelco Chaudron u32 *n_mask_hit, 979d2f627bSEelco Chaudron u32 *n_cache_hit); 985bb50632SAndy Zhou struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *, 995bb50632SAndy Zhou const struct sw_flow_key *); 1004a46b24eSAlex Wang struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl, 10112eb18f7SThomas Graf const struct sw_flow_match *match); 10274ed7ab9SJoe Stringer struct sw_flow *ovs_flow_tbl_lookup_ufid(struct flow_table *, 10374ed7ab9SJoe Stringer const struct sw_flow_id *); 10474ed7ab9SJoe Stringer 10574ed7ab9SJoe Stringer bool ovs_flow_cmp(const struct sw_flow *, const struct sw_flow_match *); 106e6445719SPravin B Shelar 107e6445719SPravin B Shelar void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src, 108ae5f2fb1SJesse Gross bool full, const struct sw_flow_mask *mask); 109eac87c41SEelco Chaudron 110eac87c41SEelco Chaudron void ovs_flow_masks_rebalance(struct flow_table *table); 1111f3a090bSTonghao Zhang void table_instance_flow_flush(struct flow_table *table, 1121f3a090bSTonghao Zhang struct table_instance *ti, 1131f3a090bSTonghao Zhang struct table_instance *ufid_ti); 114eac87c41SEelco Chaudron 115e6445719SPravin B Shelar #endif /* flow_table.h */ 116