iPXE
ath.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008-2009 Atheros Communications Inc.
00003  *
00004  * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
00005  * Original from Linux kernel 3.0.1
00006  *
00007  * Permission to use, copy, modify, and/or distribute this software for any
00008  * purpose with or without fee is hereby granted, provided that the above
00009  * copyright notice and this permission notice appear in all copies.
00010  *
00011  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00012  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00013  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00014  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00015  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00016  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00017  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00018  */
00019 
00020 #ifndef ATH_H
00021 #define ATH_H
00022 
00023 FILE_LICENCE ( BSD2 );
00024 
00025 #include <unistd.h>
00026 #include <ipxe/net80211.h>
00027 
00028 /* This block of functions are from kernel.h v3.0.1 */
00029 #define DIV_ROUND_UP(n,d)       (((n) + (d) - 1) / (d))
00030 #define BITS_PER_BYTE           8
00031 #define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
00032 #define BIT(nr)                 (1UL << (nr))
00033 
00034 #define min(x, y) ({                                    \
00035         typeof(x) _min1 = (x);                          \
00036         typeof(y) _min2 = (y);                          \
00037         (void) (&_min1 == &_min2);                      \
00038         _min1 < _min2 ? _min1 : _min2; })
00039 #define max(x, y) ({                                    \
00040         typeof(x) _max1 = (x);                          \
00041         typeof(y) _max2 = (y);                          \
00042         (void) (&_max1 == &_max2);                      \
00043         _max1 > _max2 ? _max1 : _max2; })
00044 #define abs(x) ({                                       \
00045                 long ret;                               \
00046                 if (sizeof(x) == sizeof(long)) {        \
00047                         long __x = (x);                 \
00048                         ret = (__x < 0) ? -__x : __x;   \
00049                 } else {                                \
00050                         int __x = (x);                  \
00051                         ret = (__x < 0) ? -__x : __x;   \
00052                 }                                       \
00053                 ret;                                    \
00054         })
00055 
00056 #define ___constant_swab16(x) ((uint16_t)(                      \
00057         (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) |            \
00058         (((uint16_t)(x) & (uint16_t)0xff00U) >> 8)))
00059 #define ___constant_swab32(x) ((uint32_t)(                      \
00060         (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) |      \
00061         (((uint32_t)(x) & (uint32_t)0x0000ff00UL) <<  8) |      \
00062         (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >>  8) |      \
00063         (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24)))
00064 #define __swab16(x) ___constant_swab16(x)
00065 #define __swab32(x) ___constant_swab32(x)
00066 #define swab16 __swab16
00067 #define swab32 __swab32
00068 
00069 static inline int32_t sign_extend32(uint32_t value, int index)
00070 {
00071         uint8_t shift = 31 - index;
00072         return (int32_t)(value << shift) >> shift;
00073 }
00074 
00075 static inline u16 __get_unaligned_le16(const u8 *p)
00076 {
00077         return p[0] | p[1] << 8;
00078 }
00079 static inline u32 __get_unaligned_le32(const u8 *p)
00080 {
00081         return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
00082 }
00083 static inline u16 get_unaligned_le16(const void *p)
00084 {
00085         return __get_unaligned_le16((const u8 *)p);
00086 }
00087 static inline u32 get_unaligned_le32(const void *p)
00088 {
00089         return __get_unaligned_le32((const u8 *)p);
00090 }
00091 /* End Kernel Block */
00092 
00093 /*
00094  * The key cache is used for h/w cipher state and also for
00095  * tracking station state such as the current tx antenna.
00096  * We also setup a mapping table between key cache slot indices
00097  * and station state to short-circuit node lookups on rx.
00098  * Different parts have different size key caches.  We handle
00099  * up to ATH_KEYMAX entries (could dynamically allocate state).
00100  */
00101 #define ATH_KEYMAX              128     /* max key cache size we handle */
00102 
00103 struct ath_ani {
00104         int caldone;
00105         unsigned int longcal_timer;
00106         unsigned int shortcal_timer;
00107         unsigned int resetcal_timer;
00108         unsigned int checkani_timer;
00109         int timer;
00110 };
00111 
00112 struct ath_cycle_counters {
00113         u32 cycles;
00114         u32 rx_busy;
00115         u32 rx_frame;
00116         u32 tx_frame;
00117 };
00118 
00119 enum ath_device_state {
00120         ATH_HW_UNAVAILABLE,
00121         ATH_HW_INITIALIZED,
00122 };
00123 
00124 enum ath_bus_type {
00125         ATH_PCI,
00126         ATH_AHB,
00127         ATH_USB,
00128 };
00129 
00130 struct reg_dmn_pair_mapping {
00131         u16 regDmnEnum;
00132         u16 reg_5ghz_ctl;
00133         u16 reg_2ghz_ctl;
00134 };
00135 
00136 struct ath_regulatory {
00137         char alpha2[2];
00138         u16 country_code;
00139         u16 max_power_level;
00140         u32 tp_scale;
00141         u16 current_rd;
00142         u16 current_rd_ext;
00143         int16_t power_limit;
00144         struct reg_dmn_pair_mapping *regpair;
00145 };
00146 
00147 enum ath_crypt_caps {
00148         ATH_CRYPT_CAP_CIPHER_AESCCM             = BIT(0),
00149         ATH_CRYPT_CAP_MIC_COMBINED              = BIT(1),
00150 };
00151 
00152 struct ath_keyval {
00153         u8 kv_type;
00154         u8 kv_pad;
00155         u16 kv_len;
00156         u8 kv_val[16]; /* TK */
00157         u8 kv_mic[8]; /* Michael MIC key */
00158         u8 kv_txmic[8]; /* Michael MIC TX key (used only if the hardware
00159                          * supports both MIC keys in the same key cache entry;
00160                          * in that case, kv_mic is the RX key) */
00161 };
00162 
00163 enum ath_cipher {
00164         ATH_CIPHER_WEP = 0,
00165         ATH_CIPHER_AES_OCB = 1,
00166         ATH_CIPHER_AES_CCM = 2,
00167         ATH_CIPHER_CKIP = 3,
00168         ATH_CIPHER_TKIP = 4,
00169         ATH_CIPHER_CLR = 5,
00170         ATH_CIPHER_MIC = 127
00171 };
00172 
00173 /**
00174  * struct ath_ops - Register read/write operations
00175  *
00176  * @read: Register read
00177  * @multi_read: Multiple register read
00178  * @write: Register write
00179  * @enable_write_buffer: Enable multiple register writes
00180  * @write_flush: flush buffered register writes and disable buffering
00181  */
00182 struct ath_ops {
00183         unsigned int (*read)(void *, u32 reg_offset);
00184         void (*multi_read)(void *, u32 *addr, u32 *val, u16 count);
00185         void (*write)(void *, u32 val, u32 reg_offset);
00186         void (*enable_write_buffer)(void *);
00187         void (*write_flush) (void *);
00188         u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
00189 };
00190 
00191 struct ath_common;
00192 struct ath_bus_ops;
00193 
00194 struct ath_common {
00195         void *ah;
00196         void *priv;
00197         struct net80211_device *dev;
00198         int debug_mask;
00199         enum ath_device_state state;
00200 
00201         struct ath_ani ani;
00202 
00203         u16 cachelsz;
00204         u16 curaid;
00205         u8 macaddr[ETH_ALEN];
00206         u8 curbssid[ETH_ALEN];
00207         u8 bssidmask[ETH_ALEN];
00208 
00209         u8 tx_chainmask;
00210         u8 rx_chainmask;
00211 
00212         u32 rx_bufsize;
00213 
00214         u32 keymax;
00215         enum ath_crypt_caps crypt_caps;
00216 
00217         unsigned int clockrate;
00218 
00219         struct ath_cycle_counters cc_ani;
00220         struct ath_cycle_counters cc_survey;
00221 
00222         struct ath_regulatory regulatory;
00223         const struct ath_ops *ops;
00224         const struct ath_bus_ops *bus_ops;
00225 
00226         int btcoex_enabled;
00227 };
00228 
00229 void ath_hw_setbssidmask(struct ath_common *common);
00230 int ath_hw_keyreset(struct ath_common *common, u16 entry);
00231 void ath_hw_cycle_counters_update(struct ath_common *common);
00232 int32_t ath_hw_get_listen_time(struct ath_common *common);
00233 
00234 #endif /* ATH_H */