net/fealnx: switch from 'pci_' to 'dma_' API
[linux-2.6-microblaze.git] / net / openvswitch / flow_table.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2007-2013 Nicira, Inc.
4  */
5
6 #ifndef FLOW_TABLE_H
7 #define FLOW_TABLE_H 1
8
9 #include <linux/kernel.h>
10 #include <linux/netlink.h>
11 #include <linux/openvswitch.h>
12 #include <linux/spinlock.h>
13 #include <linux/types.h>
14 #include <linux/rcupdate.h>
15 #include <linux/if_ether.h>
16 #include <linux/in6.h>
17 #include <linux/jiffies.h>
18 #include <linux/time.h>
19
20 #include <net/inet_ecn.h>
21 #include <net/ip_tunnels.h>
22
23 #include "flow.h"
24
25 struct mask_cache_entry {
26         u32 skb_hash;
27         u32 mask_index;
28 };
29
30 struct mask_count {
31         int index;
32         u64 counter;
33 };
34
35 struct mask_array {
36         struct rcu_head rcu;
37         int count, max;
38         u64 __percpu *masks_usage_cntr;
39         u64 *masks_usage_zero_cntr;
40         struct u64_stats_sync syncp;
41         struct sw_flow_mask __rcu *masks[];
42 };
43
44 struct table_instance {
45         struct hlist_head *buckets;
46         unsigned int n_buckets;
47         struct rcu_head rcu;
48         int node_ver;
49         u32 hash_seed;
50         bool keep_flows;
51 };
52
53 struct flow_table {
54         struct table_instance __rcu *ti;
55         struct table_instance __rcu *ufid_ti;
56         struct mask_cache_entry __percpu *mask_cache;
57         struct mask_array __rcu *mask_array;
58         unsigned long last_rehash;
59         unsigned int count;
60         unsigned int ufid_count;
61 };
62
63 extern struct kmem_cache *flow_stats_cache;
64
65 int ovs_flow_init(void);
66 void ovs_flow_exit(void);
67
68 struct sw_flow *ovs_flow_alloc(void);
69 void ovs_flow_free(struct sw_flow *, bool deferred);
70
71 int ovs_flow_tbl_init(struct flow_table *);
72 int ovs_flow_tbl_count(const struct flow_table *table);
73 void ovs_flow_tbl_destroy(struct flow_table *table);
74 int ovs_flow_tbl_flush(struct flow_table *flow_table);
75
76 int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
77                         const struct sw_flow_mask *mask);
78 void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow);
79 int  ovs_flow_tbl_num_masks(const struct flow_table *table);
80 struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table,
81                                        u32 *bucket, u32 *idx);
82 struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *,
83                                           const struct sw_flow_key *,
84                                           u32 skb_hash,
85                                           u32 *n_mask_hit);
86 struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
87                                     const struct sw_flow_key *);
88 struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
89                                           const struct sw_flow_match *match);
90 struct sw_flow *ovs_flow_tbl_lookup_ufid(struct flow_table *,
91                                          const struct sw_flow_id *);
92
93 bool ovs_flow_cmp(const struct sw_flow *, const struct sw_flow_match *);
94
95 void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
96                        bool full, const struct sw_flow_mask *mask);
97
98 void ovs_flow_masks_rebalance(struct flow_table *table);
99
100 #endif /* flow_table.h */