Merge branch 'intel_idle+snb' into idle-release
[pandora-kernel.git] / drivers / staging / batman-adv / main.h
1 /*
2  * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3  *
4  * Marek Lindner, Simon Wunderlich
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of version 2 of the GNU General Public
8  * License as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA
19  *
20  */
21
22 #ifndef _NET_BATMAN_ADV_MAIN_H_
23 #define _NET_BATMAN_ADV_MAIN_H_
24
25 /* Kernel Programming */
26 #define LINUX
27
28 #define DRIVER_AUTHOR "Marek Lindner <lindner_marek@yahoo.de>, " \
29                       "Simon Wunderlich <siwu@hrz.tu-chemnitz.de>"
30 #define DRIVER_DESC   "B.A.T.M.A.N. advanced"
31 #define DRIVER_DEVICE "batman-adv"
32
33 #define SOURCE_VERSION "maint"
34
35
36 /* B.A.T.M.A.N. parameters */
37
38 #define TQ_MAX_VALUE 255
39 #define JITTER 20
40 #define TTL 50                    /* Time To Live of broadcast messages */
41
42 #define PURGE_TIMEOUT 200       /* purge originators after time in seconds if no
43                                    * valid packet comes in -> TODO: check
44                                    * influence on TQ_LOCAL_WINDOW_SIZE */
45 #define LOCAL_HNA_TIMEOUT 3600 /* in seconds */
46
47 #define TQ_LOCAL_WINDOW_SIZE 64   /* sliding packet range of received originator
48                                    * messages in squence numbers (should be a
49                                    * multiple of our word size) */
50 #define TQ_GLOBAL_WINDOW_SIZE 5
51 #define TQ_LOCAL_BIDRECT_SEND_MINIMUM 1
52 #define TQ_LOCAL_BIDRECT_RECV_MINIMUM 1
53 #define TQ_TOTAL_BIDRECT_LIMIT 1
54
55 #define TQ_HOP_PENALTY 10
56
57 #define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE)
58
59 #define PACKBUFF_SIZE 2000
60 #define LOG_BUF_LEN 8192          /* has to be a power of 2 */
61 #define ETH_STR_LEN 20
62
63 #define VIS_INTERVAL 5000       /* 5 seconds */
64
65 /* how much worse secondary interfaces may be to
66  * to be considered as bonding candidates */
67
68 #define BONDING_TQ_THRESHOLD    50
69
70 #define MAX_AGGREGATION_BYTES 512 /* should not be bigger than 512 bytes or
71                                    * change the size of
72                                    * forw_packet->direct_link_flags */
73 #define MAX_AGGREGATION_MS 100
74
75 #define RESET_PROTECTION_MS 30000
76 #define EXPECTED_SEQNO_RANGE    65536
77 /* don't reset again within 30 seconds */
78
79 #define MODULE_INACTIVE 0
80 #define MODULE_ACTIVE 1
81 #define MODULE_DEACTIVATING 2
82
83 #define BCAST_QUEUE_LEN         256
84 #define BATMAN_QUEUE_LEN        256
85
86 /*
87  * Debug Messages
88  */
89 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt /* Append 'batman-adv: ' before
90                                              * kernel messages */
91
92 #define DBG_BATMAN 1    /* all messages related to routing / flooding /
93                          * broadcasting / etc */
94 #define DBG_ROUTES 2    /* route or hna added / changed / deleted */
95 #define DBG_ALL 3
96
97 #define LOG_BUF_LEN 8192          /* has to be a power of 2 */
98
99
100 /*
101  *  Vis
102  */
103
104 /* #define VIS_SUBCLUSTERS_DISABLED */
105
106 /*
107  * Kernel headers
108  */
109
110 #include <linux/mutex.h>        /* mutex */
111 #include <linux/module.h>       /* needed by all modules */
112 #include <linux/netdevice.h>    /* netdevice */
113 #include <linux/if_ether.h>     /* ethernet header */
114 #include <linux/poll.h>         /* poll_table */
115 #include <linux/kthread.h>      /* kernel threads */
116 #include <linux/pkt_sched.h>    /* schedule types */
117 #include <linux/workqueue.h>    /* workqueue */
118 #include <linux/slab.h>
119 #include <net/sock.h>           /* struct sock */
120 #include <linux/jiffies.h>
121 #include <linux/seq_file.h>
122 #include "types.h"
123
124 #ifndef REVISION_VERSION
125 #define REVISION_VERSION_STR ""
126 #else
127 #define REVISION_VERSION_STR " "REVISION_VERSION
128 #endif
129
130 extern struct list_head if_list;
131 extern struct hlist_head forw_bat_list;
132 extern struct hlist_head forw_bcast_list;
133 extern struct hashtable_t *orig_hash;
134
135 extern spinlock_t orig_hash_lock;
136 extern spinlock_t forw_bat_list_lock;
137 extern spinlock_t forw_bcast_list_lock;
138
139 extern atomic_t bcast_queue_left;
140 extern atomic_t batman_queue_left;
141 extern int16_t num_hna;
142
143 extern struct net_device *soft_device;
144
145 extern unsigned char broadcast_addr[];
146 extern atomic_t module_state;
147 extern struct workqueue_struct *bat_event_workqueue;
148
149 void activate_module(void);
150 void deactivate_module(void);
151 void inc_module_count(void);
152 void dec_module_count(void);
153 int addr_to_string(char *buff, uint8_t *addr);
154 int compare_orig(void *data1, void *data2);
155 int choose_orig(void *data, int32_t size);
156 int is_my_mac(uint8_t *addr);
157 int is_bcast(uint8_t *addr);
158 int is_mcast(uint8_t *addr);
159
160 #ifdef CONFIG_BATMAN_ADV_DEBUG
161 extern int debug_log(struct bat_priv *bat_priv, char *fmt, ...);
162
163 #define bat_dbg(type, bat_priv, fmt, arg...)                    \
164         do {                                                    \
165                 if (atomic_read(&bat_priv->log_level) & type)   \
166                         debug_log(bat_priv, fmt, ## arg);       \
167         }                                                       \
168         while (0)
169 #else /* !CONFIG_BATMAN_ADV_DEBUG */
170 static inline void bat_dbg(char type __attribute__((unused)),
171                            struct bat_priv *bat_priv __attribute__((unused)),
172                            char *fmt __attribute__((unused)), ...)
173 {
174 }
175 #endif
176
177 #define bat_warning(net_dev, fmt, arg...)                               \
178         do {                                                            \
179                 struct net_device *_netdev = (net_dev);                 \
180                 struct bat_priv *_batpriv = netdev_priv(_netdev);       \
181                 bat_dbg(DBG_ALL, _batpriv, fmt, ## arg);                \
182                 pr_warning("%s: " fmt, _netdev->name, ## arg);          \
183         } while (0)
184 #define bat_info(net_dev, fmt, arg...)                                  \
185         do {                                                            \
186                 struct net_device *_netdev = (net_dev);                 \
187                 struct bat_priv *_batpriv = netdev_priv(_netdev);       \
188                 bat_dbg(DBG_ALL, _batpriv, fmt, ## arg);                \
189                 pr_info("%s: " fmt, _netdev->name, ## arg);             \
190         } while (0)
191 #define bat_err(net_dev, fmt, arg...)                                   \
192         do {                                                            \
193                 struct net_device *_netdev = (net_dev);                 \
194                 struct bat_priv *_batpriv = netdev_priv(_netdev);       \
195                 bat_dbg(DBG_ALL, _batpriv, fmt, ## arg);                \
196                 pr_err("%s: " fmt, _netdev->name, ## arg);              \
197         } while (0)
198
199 #endif /* _NET_BATMAN_ADV_MAIN_H_ */