datapath: Add sysfs support for all (otherwise supported) Linux versions.
[openvswitch] / 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 <linux/version.h>
14 #include "flow.h"
15 #include "brc_sysfs.h"
16
17 struct sk_buff;
18
19 /* Mask for the priority bits in a vlan header.  If we ever merge upstream
20  * then this should go into include/linux/if_vlan.h. */
21 #define VLAN_PCP_MASK 0xe000
22
23 #define DP_MAX_PORTS 256
24 #define DP_MAX_GROUPS 16
25
26 #define DP_L2_BITS (PAGE_SHIFT - ilog2(sizeof(struct sw_flow*)))
27 #define DP_L2_SIZE (1 << DP_L2_BITS)
28 #define DP_L2_SHIFT 0
29
30 #define DP_L1_BITS (PAGE_SHIFT - ilog2(sizeof(struct sw_flow**)))
31 #define DP_L1_SIZE (1 << DP_L1_BITS)
32 #define DP_L1_SHIFT DP_L2_BITS
33
34 #define DP_MAX_BUCKETS (DP_L1_SIZE * DP_L2_SIZE)
35
36 struct dp_table {
37         unsigned int n_buckets;
38         struct sw_flow ***flows[2];
39         struct rcu_head rcu;
40 };
41
42 #define DP_N_QUEUES 2
43 #define DP_MAX_QUEUE_LEN 100
44
45 struct dp_stats_percpu {
46         u64 n_frags;
47         u64 n_hit;
48         u64 n_missed;
49         u64 n_lost;
50 };
51
52 struct dp_port_group {
53         struct rcu_head rcu;
54         int n_ports;
55         u16 ports[];
56 };
57
58 struct datapath {
59         struct mutex mutex;
60         int dp_idx;
61
62 #ifdef CONFIG_SYSFS
63 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
64         struct kobject ifobj;
65 #else
66         struct kobject *ifobj;
67 #endif
68 #endif
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 #ifdef CONFIG_SYSFS
97         struct kobject kobj;
98 #endif
99         struct list_head node;   /* Element in datapath.ports. */
100 };
101
102 extern struct notifier_block dp_device_notifier;
103 extern int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd);
104 extern int (*dp_add_dp_hook)(struct datapath *dp);
105 extern int (*dp_del_dp_hook)(struct datapath *dp);
106 extern int (*dp_add_if_hook)(struct net_bridge_port *p);
107 extern int (*dp_del_if_hook)(struct net_bridge_port *p);
108
109 /* Flow table. */
110 struct dp_table *dp_table_create(unsigned int n_buckets);
111 void dp_table_destroy(struct dp_table *, int free_flows);
112 struct sw_flow *dp_table_lookup(struct dp_table *, const struct odp_flow_key *);
113 struct sw_flow **dp_table_lookup_for_insert(struct dp_table *, const struct odp_flow_key *);
114 int dp_table_delete(struct dp_table *, struct sw_flow *);
115 int dp_table_expand(struct datapath *);
116 int dp_table_flush(struct datapath *);
117 int dp_table_foreach(struct dp_table *table,
118                      int (*callback)(struct sw_flow *flow, void *aux),
119                      void *aux);
120
121 void dp_process_received_packet(struct sk_buff *, struct net_bridge_port *);
122 int dp_del_port(struct net_bridge_port *, struct list_head *);
123 int dp_output_port(struct datapath *, struct sk_buff *, int out_port,
124                    int ignore_no_fwd);
125 int dp_output_control(struct datapath *, struct sk_buff *, int, u32 arg);
126 void dp_set_origin(struct datapath *, u16, struct sk_buff *);
127
128 struct datapath *get_dp(int dp_idx);
129
130 static inline const char *dp_name(const struct datapath *dp)
131 {
132         return dp->ports[ODPP_LOCAL]->dev->name;
133 }
134
135 #ifdef CONFIG_XEN
136 int skb_checksum_setup(struct sk_buff *skb);
137 #else
138 static inline int skb_checksum_setup(struct sk_buff *skb)
139 {
140         return 0;
141 }
142 #endif
143
144 #endif /* datapath.h */