datapath: Move sysfs support from brcompat_mod into openvswitch_mod.
[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 "flow.h"
22 #include "brc_sysfs.h"
23
24 /* Mask for the priority bits in a vlan header.  If we ever merge upstream
25  * then this should go into include/linux/if_vlan.h. */
26 #define VLAN_PCP_MASK 0xe000
27
28 #define DP_MAX_PORTS 256
29 #define DP_MAX_GROUPS 16
30
31 #define DP_L2_BITS (PAGE_SHIFT - ilog2(sizeof(struct sw_flow*)))
32 #define DP_L2_SIZE (1 << DP_L2_BITS)
33 #define DP_L2_SHIFT 0
34
35 #define DP_L1_BITS (PAGE_SHIFT - ilog2(sizeof(struct sw_flow**)))
36 #define DP_L1_SIZE (1 << DP_L1_BITS)
37 #define DP_L1_SHIFT DP_L2_BITS
38
39 #define DP_MAX_BUCKETS (DP_L1_SIZE * DP_L2_SIZE)
40
41 struct dp_table {
42         unsigned int n_buckets;
43         struct sw_flow ***flows[2];
44         struct rcu_head rcu;
45 };
46
47 #define DP_N_QUEUES 2
48 #define DP_MAX_QUEUE_LEN 100
49
50 struct dp_stats_percpu {
51         u64 n_frags;
52         u64 n_hit;
53         u64 n_missed;
54         u64 n_lost;
55 };
56
57 struct dp_port_group {
58         struct rcu_head rcu;
59         int n_ports;
60         u16 ports[];
61 };
62
63 struct datapath {
64         struct mutex mutex;
65         int dp_idx;
66
67 #ifdef SUPPORT_SYSFS
68         struct kobject ifobj;
69 #endif
70
71         int drop_frags;
72
73         /* Queued data. */
74         struct sk_buff_head queues[DP_N_QUEUES];
75         wait_queue_head_t waitqueue;
76
77         /* Flow table. */
78         unsigned int n_flows;
79         struct dp_table *table;
80
81         /* Port groups. */
82         struct dp_port_group *groups[DP_MAX_GROUPS];
83
84         /* Switch ports. */
85         unsigned int n_ports;
86         struct net_bridge_port *ports[DP_MAX_PORTS];
87         struct list_head port_list; /* All ports, including local_port. */
88
89         /* Stats. */
90         struct dp_stats_percpu *stats_percpu;
91 };
92
93 struct net_bridge_port {
94         u16 port_no;
95         struct datapath *dp;
96         struct net_device *dev;
97 #ifdef SUPPORT_SYSFS
98         struct kobject kobj;
99 #endif
100         struct list_head node;   /* Element in datapath.ports. */
101 };
102
103 extern struct notifier_block dp_device_notifier;
104 extern int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd);
105
106 /* Flow table. */
107 struct dp_table *dp_table_create(unsigned int n_buckets);
108 void dp_table_destroy(struct dp_table *, int free_flows);
109 struct sw_flow *dp_table_lookup(struct dp_table *, const struct odp_flow_key *);
110 struct sw_flow **dp_table_lookup_for_insert(struct dp_table *, const struct odp_flow_key *);
111 int dp_table_delete(struct dp_table *, struct sw_flow *);
112 int dp_table_expand(struct datapath *);
113 int dp_table_flush(struct datapath *);
114 int dp_table_foreach(struct dp_table *table,
115                      int (*callback)(struct sw_flow *flow, void *aux),
116                      void *aux);
117
118 void dp_process_received_packet(struct sk_buff *, struct net_bridge_port *);
119 int dp_del_port(struct net_bridge_port *);
120 int dp_output_control(struct datapath *, struct sk_buff *, int, u32 arg);
121 int dp_min_mtu(const struct datapath *dp);
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 */