Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / drivers / net / ath / ath.h
1 /*
2  * Copyright (c) 2008-2009 Atheros Communications Inc.
3  *
4  * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
5  * Original from Linux kernel 3.0.1
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19
20 #ifndef ATH_H
21 #define ATH_H
22
23 FILE_LICENCE ( BSD2 );
24
25 #include <unistd.h>
26 #include <ipxe/net80211.h>
27
28 /* This block of functions are from kernel.h v3.0.1 */
29 #define ARRAY_SIZE(arr)         (sizeof(arr) / sizeof((arr)[0]))
30 #define DIV_ROUND_UP(n,d)       (((n) + (d) - 1) / (d))
31 #define BITS_PER_BYTE           8
32 #define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
33 #define BIT(nr)                 (1UL << (nr))
34
35 #define min(x, y) ({                                    \
36         typeof(x) _min1 = (x);                          \
37         typeof(y) _min2 = (y);                          \
38         (void) (&_min1 == &_min2);                      \
39         _min1 < _min2 ? _min1 : _min2; })
40 #define max(x, y) ({                                    \
41         typeof(x) _max1 = (x);                          \
42         typeof(y) _max2 = (y);                          \
43         (void) (&_max1 == &_max2);                      \
44         _max1 > _max2 ? _max1 : _max2; })
45 #define abs(x) ({                                       \
46                 long ret;                               \
47                 if (sizeof(x) == sizeof(long)) {        \
48                         long __x = (x);                 \
49                         ret = (__x < 0) ? -__x : __x;   \
50                 } else {                                \
51                         int __x = (x);                  \
52                         ret = (__x < 0) ? -__x : __x;   \
53                 }                                       \
54                 ret;                                    \
55         })
56
57 #define ___constant_swab16(x) ((uint16_t)(                      \
58         (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) |            \
59         (((uint16_t)(x) & (uint16_t)0xff00U) >> 8)))
60 #define ___constant_swab32(x) ((uint32_t)(                      \
61         (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) |      \
62         (((uint32_t)(x) & (uint32_t)0x0000ff00UL) <<  8) |      \
63         (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >>  8) |      \
64         (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24)))
65 #define __swab16(x) ___constant_swab16(x)
66 #define __swab32(x) ___constant_swab32(x)
67 #define swab16 __swab16
68 #define swab32 __swab32
69
70 static inline int32_t sign_extend32(uint32_t value, int index)
71 {
72         uint8_t shift = 31 - index;
73         return (int32_t)(value << shift) >> shift;
74 }
75
76 static inline u16 __get_unaligned_le16(const u8 *p)
77 {
78         return p[0] | p[1] << 8;
79 }
80 static inline u32 __get_unaligned_le32(const u8 *p)
81 {
82         return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
83 }
84 static inline u16 get_unaligned_le16(const void *p)
85 {
86         return __get_unaligned_le16((const u8 *)p);
87 }
88 static inline u32 get_unaligned_le32(const void *p)
89 {
90         return __get_unaligned_le32((const u8 *)p);
91 }
92 /* End Kernel Block */
93
94 /*
95  * The key cache is used for h/w cipher state and also for
96  * tracking station state such as the current tx antenna.
97  * We also setup a mapping table between key cache slot indices
98  * and station state to short-circuit node lookups on rx.
99  * Different parts have different size key caches.  We handle
100  * up to ATH_KEYMAX entries (could dynamically allocate state).
101  */
102 #define ATH_KEYMAX              128     /* max key cache size we handle */
103
104 static const u8 ath_bcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
105
106 struct ath_ani {
107         int caldone;
108         unsigned int longcal_timer;
109         unsigned int shortcal_timer;
110         unsigned int resetcal_timer;
111         unsigned int checkani_timer;
112         int timer;
113 };
114
115 struct ath_cycle_counters {
116         u32 cycles;
117         u32 rx_busy;
118         u32 rx_frame;
119         u32 tx_frame;
120 };
121
122 enum ath_device_state {
123         ATH_HW_UNAVAILABLE,
124         ATH_HW_INITIALIZED,
125 };
126
127 enum ath_bus_type {
128         ATH_PCI,
129         ATH_AHB,
130         ATH_USB,
131 };
132
133 struct reg_dmn_pair_mapping {
134         u16 regDmnEnum;
135         u16 reg_5ghz_ctl;
136         u16 reg_2ghz_ctl;
137 };
138
139 struct ath_regulatory {
140         char alpha2[2];
141         u16 country_code;
142         u16 max_power_level;
143         u32 tp_scale;
144         u16 current_rd;
145         u16 current_rd_ext;
146         int16_t power_limit;
147         struct reg_dmn_pair_mapping *regpair;
148 };
149
150 enum ath_crypt_caps {
151         ATH_CRYPT_CAP_CIPHER_AESCCM             = BIT(0),
152         ATH_CRYPT_CAP_MIC_COMBINED              = BIT(1),
153 };
154
155 struct ath_keyval {
156         u8 kv_type;
157         u8 kv_pad;
158         u16 kv_len;
159         u8 kv_val[16]; /* TK */
160         u8 kv_mic[8]; /* Michael MIC key */
161         u8 kv_txmic[8]; /* Michael MIC TX key (used only if the hardware
162                          * supports both MIC keys in the same key cache entry;
163                          * in that case, kv_mic is the RX key) */
164 };
165
166 enum ath_cipher {
167         ATH_CIPHER_WEP = 0,
168         ATH_CIPHER_AES_OCB = 1,
169         ATH_CIPHER_AES_CCM = 2,
170         ATH_CIPHER_CKIP = 3,
171         ATH_CIPHER_TKIP = 4,
172         ATH_CIPHER_CLR = 5,
173         ATH_CIPHER_MIC = 127
174 };
175
176 /**
177  * struct ath_ops - Register read/write operations
178  *
179  * @read: Register read
180  * @multi_read: Multiple register read
181  * @write: Register write
182  * @enable_write_buffer: Enable multiple register writes
183  * @write_flush: flush buffered register writes and disable buffering
184  */
185 struct ath_ops {
186         unsigned int (*read)(void *, u32 reg_offset);
187         void (*multi_read)(void *, u32 *addr, u32 *val, u16 count);
188         void (*write)(void *, u32 val, u32 reg_offset);
189         void (*enable_write_buffer)(void *);
190         void (*write_flush) (void *);
191         u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
192 };
193
194 struct ath_common;
195 struct ath_bus_ops;
196
197 struct ath_common {
198         void *ah;
199         void *priv;
200         struct net80211_device *dev;
201         int debug_mask;
202         enum ath_device_state state;
203
204         struct ath_ani ani;
205
206         u16 cachelsz;
207         u16 curaid;
208         u8 macaddr[ETH_ALEN];
209         u8 curbssid[ETH_ALEN];
210         u8 bssidmask[ETH_ALEN];
211
212         u8 tx_chainmask;
213         u8 rx_chainmask;
214
215         u32 rx_bufsize;
216
217         u32 keymax;
218         enum ath_crypt_caps crypt_caps;
219
220         unsigned int clockrate;
221
222         struct ath_cycle_counters cc_ani;
223         struct ath_cycle_counters cc_survey;
224
225         struct ath_regulatory regulatory;
226         const struct ath_ops *ops;
227         const struct ath_bus_ops *bus_ops;
228
229         int btcoex_enabled;
230 };
231
232 struct io_buffer *ath_rxbuf_alloc(struct ath_common *common,
233                                 u32 len,
234                                 u32 *iob_addr);
235
236 void ath_hw_setbssidmask(struct ath_common *common);
237 int ath_hw_keyreset(struct ath_common *common, u16 entry);
238 void ath_hw_cycle_counters_update(struct ath_common *common);
239 int32_t ath_hw_get_listen_time(struct ath_common *common);
240
241 #endif /* ATH_H */