Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Intel Wireless Multicomm 3200 WiFi driver |
| 3 | * |
| 4 | * Copyright (C) 2009 Intel Corporation. All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in |
| 14 | * the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Intel Corporation nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived |
| 18 | * from this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | * |
| 33 | * Intel Corporation <ilw@linux.intel.com> |
| 34 | * Samuel Ortiz <samuel.ortiz@intel.com> |
| 35 | * Zhu Yi <yi.zhu@intel.com> |
| 36 | * |
| 37 | */ |
| 38 | |
| 39 | #ifndef __IWM_H__ |
| 40 | #define __IWM_H__ |
| 41 | |
| 42 | #include <linux/netdevice.h> |
| 43 | #include <linux/wireless.h> |
| 44 | #include <net/cfg80211.h> |
| 45 | |
| 46 | #include "debug.h" |
| 47 | #include "hal.h" |
| 48 | #include "umac.h" |
| 49 | #include "lmac.h" |
| 50 | #include "eeprom.h" |
| 51 | |
| 52 | #define IWM_COPYRIGHT "Copyright(c) 2009 Intel Corporation" |
| 53 | #define IWM_AUTHOR "<ilw@linux.intel.com>" |
| 54 | |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 55 | #define IWM_SRC_LMAC UMAC_HDI_IN_SOURCE_FHRX |
| 56 | #define IWM_SRC_UDMA UMAC_HDI_IN_SOURCE_UDMA |
| 57 | #define IWM_SRC_UMAC UMAC_HDI_IN_SOURCE_FW |
| 58 | #define IWM_SRC_NUM 3 |
| 59 | |
| 60 | #define IWM_POWER_INDEX_MIN 0 |
| 61 | #define IWM_POWER_INDEX_MAX 5 |
| 62 | #define IWM_POWER_INDEX_DEFAULT 3 |
| 63 | |
| 64 | struct iwm_conf { |
| 65 | u32 sdio_ior_timeout; |
Zhu Yi | fd2c7fe | 2009-06-25 18:28:31 +0800 | [diff] [blame] | 66 | unsigned long calib_map; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 67 | bool reset_on_fatal_err; |
| 68 | bool auto_connect; |
| 69 | bool wimax_not_present; |
| 70 | bool enable_qos; |
| 71 | u32 mode; |
| 72 | |
| 73 | u32 power_index; |
| 74 | u32 frag_threshold; |
| 75 | u32 rts_threshold; |
| 76 | bool cts_to_self; |
| 77 | |
| 78 | u32 assoc_timeout; |
| 79 | u32 roam_timeout; |
| 80 | u32 wireless_mode; |
| 81 | u32 coexist_mode; |
| 82 | |
| 83 | u8 ibss_band; |
| 84 | u8 ibss_channel; |
| 85 | |
| 86 | u8 mac_addr[ETH_ALEN]; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | enum { |
| 90 | COEX_MODE_SA = 1, |
| 91 | COEX_MODE_XOR, |
| 92 | COEX_MODE_CM, |
| 93 | COEX_MODE_MAX, |
| 94 | }; |
| 95 | |
| 96 | struct iwm_if_ops; |
| 97 | struct iwm_wifi_cmd; |
| 98 | |
| 99 | struct pool_entry { |
| 100 | int id; /* group id */ |
| 101 | int sid; /* super group id */ |
| 102 | int min_pages; /* min capacity in pages */ |
| 103 | int max_pages; /* max capacity in pages */ |
| 104 | int alloc_pages; /* allocated # of pages. incresed by driver */ |
| 105 | int total_freed_pages; /* total freed # of pages. incresed by UMAC */ |
| 106 | }; |
| 107 | |
| 108 | struct spool_entry { |
| 109 | int id; |
| 110 | int max_pages; |
| 111 | int alloc_pages; |
| 112 | }; |
| 113 | |
| 114 | struct iwm_tx_credit { |
| 115 | spinlock_t lock; |
| 116 | int pool_nr; |
| 117 | unsigned long full_pools_map; /* bitmap for # of filled tx pools */ |
| 118 | struct pool_entry pools[IWM_MACS_OUT_GROUPS]; |
| 119 | struct spool_entry spools[IWM_MACS_OUT_SGROUPS]; |
| 120 | }; |
| 121 | |
| 122 | struct iwm_notif { |
| 123 | struct list_head pending; |
| 124 | u32 cmd_id; |
| 125 | void *cmd; |
| 126 | u8 src; |
| 127 | void *buf; |
| 128 | unsigned long buf_size; |
| 129 | }; |
| 130 | |
| 131 | struct iwm_sta_info { |
| 132 | u8 addr[ETH_ALEN]; |
| 133 | bool valid; |
| 134 | bool qos; |
| 135 | u8 color; |
| 136 | }; |
| 137 | |
| 138 | struct iwm_tx_info { |
| 139 | u8 sta; |
| 140 | u8 color; |
| 141 | u8 tid; |
| 142 | }; |
| 143 | |
| 144 | struct iwm_rx_info { |
| 145 | unsigned long rx_size; |
| 146 | unsigned long rx_buf_size; |
| 147 | }; |
| 148 | |
| 149 | #define IWM_NUM_KEYS 4 |
| 150 | |
| 151 | struct iwm_umac_key_hdr { |
| 152 | u8 mac[ETH_ALEN]; |
| 153 | u8 key_idx; |
| 154 | u8 multicast; /* BCast encrypt & BCast decrypt of frames FROM mac */ |
| 155 | } __attribute__ ((packed)); |
| 156 | |
| 157 | struct iwm_key { |
| 158 | struct iwm_umac_key_hdr hdr; |
Samuel Ortiz | 13e0fe70 | 2009-06-15 21:59:52 +0200 | [diff] [blame] | 159 | u32 cipher; |
| 160 | u8 key[WLAN_MAX_KEY_LEN]; |
| 161 | u8 seq[IW_ENCODE_SEQ_MAX_SIZE]; |
| 162 | int key_len; |
| 163 | int seq_len; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 164 | }; |
| 165 | |
| 166 | #define IWM_RX_ID_HASH 0xff |
| 167 | #define IWM_RX_ID_GET_HASH(id) ((id) % IWM_RX_ID_HASH) |
| 168 | |
| 169 | #define IWM_STA_TABLE_NUM 16 |
| 170 | #define IWM_TX_LIST_SIZE 64 |
| 171 | #define IWM_RX_LIST_SIZE 256 |
| 172 | |
| 173 | #define IWM_SCAN_ID_MAX 0xff |
| 174 | |
| 175 | #define IWM_STATUS_READY 0 |
| 176 | #define IWM_STATUS_SCANNING 1 |
| 177 | #define IWM_STATUS_SCAN_ABORTING 2 |
Zhu Yi | de15fd3 | 2009-09-01 15:14:01 +0200 | [diff] [blame] | 178 | #define IWM_STATUS_SME_CONNECTING 3 |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 179 | #define IWM_STATUS_ASSOCIATED 4 |
| 180 | |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 181 | struct iwm_tx_queue { |
| 182 | int id; |
| 183 | struct sk_buff_head queue; |
| 184 | struct workqueue_struct *wq; |
| 185 | struct work_struct worker; |
| 186 | u8 concat_buf[IWM_HAL_CONCATENATE_BUF_SIZE]; |
| 187 | int concat_count; |
| 188 | u8 *concat_ptr; |
| 189 | }; |
| 190 | |
| 191 | /* Queues 0 ~ 3 for AC data, 5 for iPAN */ |
| 192 | #define IWM_TX_QUEUES 5 |
| 193 | #define IWM_TX_DATA_QUEUES 4 |
| 194 | #define IWM_TX_CMD_QUEUE 4 |
| 195 | |
| 196 | struct iwm_bss_info { |
| 197 | struct list_head node; |
| 198 | struct cfg80211_bss *cfg_bss; |
| 199 | struct iwm_umac_notif_bss_info *bss; |
| 200 | }; |
| 201 | |
| 202 | typedef int (*iwm_handler)(struct iwm_priv *priv, u8 *buf, |
| 203 | unsigned long buf_size, struct iwm_wifi_cmd *cmd); |
| 204 | |
| 205 | #define IWM_WATCHDOG_PERIOD (6 * HZ) |
| 206 | |
| 207 | struct iwm_priv { |
| 208 | struct wireless_dev *wdev; |
| 209 | struct iwm_if_ops *bus_ops; |
| 210 | |
| 211 | struct iwm_conf conf; |
| 212 | |
| 213 | unsigned long status; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 214 | |
| 215 | struct list_head pending_notif; |
| 216 | wait_queue_head_t notif_queue; |
| 217 | |
| 218 | wait_queue_head_t nonwifi_queue; |
| 219 | |
| 220 | unsigned long calib_done_map; |
| 221 | struct { |
| 222 | u8 *buf; |
| 223 | u32 size; |
| 224 | } calib_res[CALIBRATION_CMD_NUM]; |
| 225 | |
| 226 | struct iwm_umac_profile *umac_profile; |
| 227 | bool umac_profile_active; |
| 228 | |
| 229 | u8 bssid[ETH_ALEN]; |
| 230 | u8 channel; |
| 231 | u16 rate; |
Zhu Yi | 257862f | 2009-06-15 21:59:56 +0200 | [diff] [blame] | 232 | u32 txpower; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 233 | |
| 234 | struct iwm_sta_info sta_table[IWM_STA_TABLE_NUM]; |
| 235 | struct list_head bss_list; |
| 236 | |
| 237 | void (*nonwifi_rx_handlers[UMAC_HDI_IN_OPCODE_NONWIFI_MAX]) |
| 238 | (struct iwm_priv *priv, u8 *buf, unsigned long buf_size); |
| 239 | |
| 240 | const iwm_handler *umac_handlers; |
| 241 | const iwm_handler *lmac_handlers; |
| 242 | DECLARE_BITMAP(lmac_handler_map, LMAC_COMMAND_ID_NUM); |
| 243 | DECLARE_BITMAP(umac_handler_map, LMAC_COMMAND_ID_NUM); |
| 244 | DECLARE_BITMAP(udma_handler_map, LMAC_COMMAND_ID_NUM); |
| 245 | |
| 246 | struct list_head wifi_pending_cmd; |
| 247 | struct list_head nonwifi_pending_cmd; |
| 248 | u16 wifi_seq_num; |
| 249 | u8 nonwifi_seq_num; |
| 250 | spinlock_t cmd_lock; |
| 251 | |
| 252 | u32 core_enabled; |
| 253 | |
| 254 | u8 scan_id; |
| 255 | struct cfg80211_scan_request *scan_request; |
| 256 | |
| 257 | struct sk_buff_head rx_list; |
| 258 | struct list_head rx_tickets; |
| 259 | struct list_head rx_packets[IWM_RX_ID_HASH]; |
| 260 | struct workqueue_struct *rx_wq; |
| 261 | struct work_struct rx_worker; |
| 262 | |
| 263 | struct iwm_tx_credit tx_credit; |
| 264 | struct iwm_tx_queue txq[IWM_TX_QUEUES]; |
| 265 | |
| 266 | struct iwm_key keys[IWM_NUM_KEYS]; |
Samuel Ortiz | 13e0fe70 | 2009-06-15 21:59:52 +0200 | [diff] [blame] | 267 | s8 default_key; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 268 | |
Samuel Ortiz | a70742f | 2009-06-15 21:59:51 +0200 | [diff] [blame] | 269 | DECLARE_BITMAP(wifi_ntfy, WIFI_IF_NTFY_MAX); |
| 270 | wait_queue_head_t wifi_ntfy_queue; |
| 271 | |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 272 | wait_queue_head_t mlme_queue; |
| 273 | |
| 274 | struct iw_statistics wstats; |
| 275 | struct delayed_work stats_request; |
Zhu Yi | c743627 | 2009-09-01 15:14:02 +0200 | [diff] [blame^] | 276 | struct delayed_work disconnect; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 277 | |
| 278 | struct iwm_debugfs dbg; |
| 279 | |
| 280 | u8 *eeprom; |
| 281 | struct timer_list watchdog; |
| 282 | struct work_struct reset_worker; |
Zhu Yi | 68810c5 | 2009-06-15 21:59:49 +0200 | [diff] [blame] | 283 | struct mutex mutex; |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 284 | |
Zhu Yi | b68518f | 2009-07-20 11:47:45 +0800 | [diff] [blame] | 285 | u8 *req_ie; |
| 286 | int req_ie_len; |
| 287 | u8 *resp_ie; |
| 288 | int resp_ie_len; |
| 289 | |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 290 | char private[0] __attribute__((__aligned__(NETDEV_ALIGN))); |
| 291 | }; |
| 292 | |
| 293 | static inline void *iwm_private(struct iwm_priv *iwm) |
| 294 | { |
| 295 | BUG_ON(!iwm); |
| 296 | return &iwm->private; |
| 297 | } |
| 298 | |
| 299 | #define hw_to_iwm(h) (h->iwm) |
| 300 | #define iwm_to_dev(i) (wiphy_dev(i->wdev->wiphy)) |
| 301 | #define iwm_to_wiphy(i) (i->wdev->wiphy) |
| 302 | #define wiphy_to_iwm(w) (struct iwm_priv *)(wiphy_priv(w)) |
| 303 | #define iwm_to_wdev(i) (i->wdev) |
| 304 | #define wdev_to_iwm(w) (struct iwm_priv *)(wdev_priv(w)) |
| 305 | #define iwm_to_ndev(i) (i->wdev->netdev) |
| 306 | #define ndev_to_iwm(n) (wdev_to_iwm(n->ieee80211_ptr)) |
| 307 | #define skb_to_rx_info(s) ((struct iwm_rx_info *)(s->cb)) |
| 308 | #define skb_to_tx_info(s) ((struct iwm_tx_info *)s->cb) |
| 309 | |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 310 | void *iwm_if_alloc(int sizeof_bus, struct device *dev, |
| 311 | struct iwm_if_ops *if_ops); |
| 312 | void iwm_if_free(struct iwm_priv *iwm); |
Zhu Yi | d7e057d | 2009-06-15 21:36:14 +0200 | [diff] [blame] | 313 | int iwm_if_add(struct iwm_priv *iwm); |
| 314 | void iwm_if_remove(struct iwm_priv *iwm); |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 315 | int iwm_mode_to_nl80211_iftype(int mode); |
| 316 | int iwm_priv_init(struct iwm_priv *iwm); |
Zhu Yi | 8d96e79 | 2009-06-15 21:36:13 +0200 | [diff] [blame] | 317 | void iwm_priv_deinit(struct iwm_priv *iwm); |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 318 | void iwm_reset(struct iwm_priv *iwm); |
| 319 | void iwm_tx_credit_init_pools(struct iwm_priv *iwm, |
| 320 | struct iwm_umac_notif_alive *alive); |
| 321 | int iwm_tx_credit_alloc(struct iwm_priv *iwm, int id, int nb); |
| 322 | int iwm_notif_send(struct iwm_priv *iwm, struct iwm_wifi_cmd *cmd, |
| 323 | u8 cmd_id, u8 source, u8 *buf, unsigned long buf_size); |
| 324 | int iwm_notif_handle(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout); |
| 325 | void iwm_init_default_profile(struct iwm_priv *iwm, |
| 326 | struct iwm_umac_profile *profile); |
| 327 | void iwm_link_on(struct iwm_priv *iwm); |
| 328 | void iwm_link_off(struct iwm_priv *iwm); |
| 329 | int iwm_up(struct iwm_priv *iwm); |
| 330 | int iwm_down(struct iwm_priv *iwm); |
| 331 | |
| 332 | /* TX API */ |
| 333 | void iwm_tx_credit_inc(struct iwm_priv *iwm, int id, int total_freed_pages); |
| 334 | void iwm_tx_worker(struct work_struct *work); |
| 335 | int iwm_xmit_frame(struct sk_buff *skb, struct net_device *netdev); |
| 336 | |
| 337 | /* RX API */ |
| 338 | void iwm_rx_setup_handlers(struct iwm_priv *iwm); |
| 339 | int iwm_rx_handle(struct iwm_priv *iwm, u8 *buf, unsigned long buf_size); |
| 340 | int iwm_rx_handle_resp(struct iwm_priv *iwm, u8 *buf, unsigned long buf_size, |
| 341 | struct iwm_wifi_cmd *cmd); |
| 342 | void iwm_rx_free(struct iwm_priv *iwm); |
| 343 | |
Zhu Yi | bb9f869 | 2009-05-21 21:20:45 +0800 | [diff] [blame] | 344 | #endif |