Import from old repository commit 61ef2b42a9c4ba8e1600f15bb0236765edc2ad45.
[cascardo/ovs.git] / datapath / datapath.h
1 /* Interface exported by openvswitch_mod. */
2
3 #ifndef DATAPATH_H
4 #define DATAPATH_H 1
5
6 #include <asm/page.h>
7 #include <linux/kernel.h>
8 #include <linux/mutex.h>
9 #include <linux/netlink.h>
10 #include <linux/netdevice.h>
11 #include <linux/workqueue.h>
12 #include <linux/skbuff.h>
13 #include "flow.h"
14 #include "brc_sysfs.h"
15
16 struct sk_buff;
17
18 /* Mask for the priority bits in a vlan header.  If we ever merge upstream
19  * then this should go into include/linux/if_vlan.h. */
20 #define VLAN_PCP_MASK 0xe000
21
22 #define DP_MAX_PORTS 256
23 #define DP_MAX_GROUPS 16
24
25 #define DP_L2_BITS (PAGE_SHIFT - ilog2(sizeof(struct sw_flow*)))
26 #define DP_L2_SIZE (1 << DP_L2_BITS)
27 #define DP_L2_SHIFT 0
28
29 #define DP_L1_BITS (PAGE_SHIFT - ilog2(sizeof(struct sw_flow**)))
30 #define DP_L1_SIZE (1 << DP_L1_BITS)
31 #define DP_L1_SHIFT DP_L2_BITS
32
33 #define DP_MAX_BUCKETS (DP_L1_SIZE * DP_L2_SIZE)
34
35 struct dp_table {
36         unsigned int n_buckets;
37         struct sw_flow ***flows[2];
38         struct rcu_head rcu;
39 };
40
41 #define DP_N_QUEUES 2
42 #define DP_MAX_QUEUE_LEN 100
43
44 struct dp_stats_percpu {
45         u64 n_frags;
46         u64 n_hit;
47         u64 n_missed;
48         u64 n_lost;
49 };
50
51 struct dp_port_group {
52         struct rcu_head rcu;
53         int n_ports;
54         u16 ports[];
55 };
56
57 struct datapath {
58         struct mutex mutex;
59         int dp_idx;
60
61 #ifdef SUPPORT_SYSFS
62         struct kobject ifobj;
63 #endif
64
65         int drop_frags;
66
67         /* Queued data. */
68         struct sk_buff_head queues[DP_N_QUEUES];
69         wait_queue_head_t waitqueue;
70
71         /* Flow table. */
72         unsigned int n_flows;
73         struct dp_table *table;
74
75         /* Port groups. */
76         struct dp_port_group *groups[DP_MAX_GROUPS];
77
78         /* Switch ports. */
79         unsigned int n_ports;
80         struct net_bridge_port *ports[DP_MAX_PORTS];
81         struct list_head port_list; /* All ports, including local_port. */
82
83         /* Stats. */
84         struct dp_stats_percpu *stats_percpu;
85 };
86
87 struct net_bridge_port {
88         u16 port_no;
89         struct datapath *dp;
90         struct net_device *dev;
91 #ifdef SUPPORT_SYSFS
92         struct kobject kobj;
93 #endif
94         struct list_head node;   /* Element in datapath.ports. */
95 };
96
97 extern struct notifier_block dp_device_notifier;
98 extern int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd);
99 extern int (*dp_add_dp_hook)(struct datapath *dp);
100 extern int (*dp_del_dp_hook)(struct datapath *dp);
101 extern int (*dp_add_if_hook)(struct net_bridge_port *p);
102 extern int (*dp_del_if_hook)(struct net_bridge_port *p);
103
104 /* Flow table. */
105 struct dp_table *dp_table_create(unsigned int n_buckets);
106 void dp_table_destroy(struct dp_table *, int free_flows);
107 struct sw_flow *dp_table_lookup(struct dp_table *, const struct odp_flow_key *);
108 struct sw_flow **dp_table_lookup_for_insert(struct dp_table *, const struct odp_flow_key *);
109 int dp_table_delete(struct dp_table *, struct sw_flow *);
110 int dp_table_expand(struct datapath *);
111 int dp_table_flush(struct datapath *);
112 int dp_table_foreach(struct dp_table *table,
113                      int (*callback)(struct sw_flow *flow, void *aux),
114                      void *aux);
115
116 void dp_process_received_packet(struct sk_buff *, struct net_bridge_port *);
117 int dp_del_port(struct net_bridge_port *, struct list_head *);
118 int dp_output_port(struct datapath *, struct sk_buff *, int out_port,
119                    int ignore_no_fwd);
120 int dp_output_control(struct datapath *, struct sk_buff *, int, u32 arg);
121 void dp_set_origin(struct datapath *, u16, struct sk_buff *);
122
123 struct datapath *get_dp(int dp_idx);
124
125 static inline const char *dp_name(const struct datapath *dp)
126 {
127         return dp->ports[ODPP_LOCAL]->dev->name;
128 }
129
130 #ifdef CONFIG_XEN
131 int skb_checksum_setup(struct sk_buff *skb);
132 #else
133 static inline int skb_checksum_setup(struct sk_buff *skb)
134 {
135         return 0;
136 }
137 #endif
138
139 #endif /* datapath.h */