Merge commit 'origin/citrix'
[sliver-openvswitch.git] / datapath / datapath.h
1 /*
2  * Copyright (c) 2009 Nicira Networks.
3  * Distributed under the terms of the GNU GPL version 2.
4  *
5  * Significant portions of this file may be copied from parts of the Linux
6  * kernel, by Linus Torvalds and others.
7  */
8
9 /* Interface exported by openvswitch_mod. */
10
11 #ifndef DATAPATH_H
12 #define DATAPATH_H 1
13
14 #include <asm/page.h>
15 #include <linux/kernel.h>
16 #include <linux/mutex.h>
17 #include <linux/netlink.h>
18 #include <linux/netdevice.h>
19 #include <linux/workqueue.h>
20 #include <linux/skbuff.h>
21 #include <linux/version.h>
22 #include "flow.h"
23 #include "dp_sysfs.h"
24
25 /* Mask for the priority bits in a vlan header.  If we ever merge upstream
26  * then this should go into include/linux/if_vlan.h. */
27 #define VLAN_PCP_MASK 0xe000
28
29 #define DP_MAX_PORTS 256
30 #define DP_MAX_GROUPS 16
31
32 #define DP_L2_BITS (PAGE_SHIFT - ilog2(sizeof(struct sw_flow*)))
33 #define DP_L2_SIZE (1 << DP_L2_BITS)
34 #define DP_L2_SHIFT 0
35
36 #define DP_L1_BITS (PAGE_SHIFT - ilog2(sizeof(struct sw_flow**)))
37 #define DP_L1_SIZE (1 << DP_L1_BITS)
38 #define DP_L1_SHIFT DP_L2_BITS
39
40 #define DP_MAX_BUCKETS (DP_L1_SIZE * DP_L2_SIZE)
41
42 struct dp_table {
43         unsigned int n_buckets;
44         struct sw_flow ***flows[2];
45         struct rcu_head rcu;
46 };
47
48 #define DP_N_QUEUES 2
49 #define DP_MAX_QUEUE_LEN 100
50
51 struct dp_stats_percpu {
52         u64 n_frags;
53         u64 n_hit;
54         u64 n_missed;
55         u64 n_lost;
56 };
57
58 struct dp_port_group {
59         struct rcu_head rcu;
60         int n_ports;
61         u16 ports[];
62 };
63
64 struct datapath {
65         struct mutex mutex;
66         int dp_idx;
67
68         struct kobject ifobj;
69
70         int drop_frags;
71
72         /* Queued data. */
73         struct sk_buff_head queues[DP_N_QUEUES];
74         wait_queue_head_t waitqueue;
75
76         /* Flow table. */
77         unsigned int n_flows;
78         struct dp_table *table;
79
80         /* Port groups. */
81         struct dp_port_group *groups[DP_MAX_GROUPS];
82
83         /* Switch ports. */
84         unsigned int n_ports;
85         struct net_bridge_port *ports[DP_MAX_PORTS];
86         struct list_head port_list; /* All ports, including local_port. */
87
88         /* Stats. */
89         struct dp_stats_percpu *stats_percpu;
90 };
91
92 struct net_bridge_port {
93         u16 port_no;
94         struct datapath *dp;
95         struct net_device *dev;
96         struct kobject kobj;
97         char linkname[IFNAMSIZ];
98         struct list_head node;   /* Element in datapath.ports. */
99 };
100
101 extern struct notifier_block dp_device_notifier;
102 extern int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd);
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 *);
118 int dp_output_control(struct datapath *, struct sk_buff *, int, u32 arg);
119 int dp_min_mtu(const struct datapath *dp);
120
121 struct datapath *get_dp(int dp_idx);
122
123 static inline const char *dp_name(const struct datapath *dp)
124 {
125         return dp->ports[ODPP_LOCAL]->dev->name;
126 }
127
128 #ifdef CONFIG_XEN
129 int skb_checksum_setup(struct sk_buff *skb);
130 #else
131 static inline int skb_checksum_setup(struct sk_buff *skb)
132 {
133         return 0;
134 }
135 #endif
136
137 int vswitch_skb_checksum_setup(struct sk_buff *skb);
138
139 #endif /* datapath.h */