iwm.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. #ifndef __IWM_H__
  39. #define __IWM_H__
  40. #include <linux/netdevice.h>
  41. #include <linux/wireless.h>
  42. #include <net/cfg80211.h>
  43. #include "debug.h"
  44. #include "hal.h"
  45. #include "umac.h"
  46. #include "lmac.h"
  47. #include "eeprom.h"
  48. #include "trace.h"
  49. #define IWM_COPYRIGHT "Copyright(c) 2009 Intel Corporation"
  50. #define IWM_AUTHOR "<ilw@linux.intel.com>"
  51. #define IWM_SRC_LMAC UMAC_HDI_IN_SOURCE_FHRX
  52. #define IWM_SRC_UDMA UMAC_HDI_IN_SOURCE_UDMA
  53. #define IWM_SRC_UMAC UMAC_HDI_IN_SOURCE_FW
  54. #define IWM_SRC_NUM 3
  55. #define IWM_POWER_INDEX_MIN 0
  56. #define IWM_POWER_INDEX_MAX 5
  57. #define IWM_POWER_INDEX_DEFAULT 3
  58. struct iwm_conf {
  59. u32 sdio_ior_timeout;
  60. unsigned long calib_map;
  61. unsigned long expected_calib_map;
  62. u8 ct_kill_entry;
  63. u8 ct_kill_exit;
  64. bool reset_on_fatal_err;
  65. bool auto_connect;
  66. bool wimax_not_present;
  67. bool enable_qos;
  68. u32 mode;
  69. u32 power_index;
  70. u32 frag_threshold;
  71. u32 rts_threshold;
  72. bool cts_to_self;
  73. u32 assoc_timeout;
  74. u32 roam_timeout;
  75. u32 wireless_mode;
  76. u8 ibss_band;
  77. u8 ibss_channel;
  78. u8 mac_addr[ETH_ALEN];
  79. };
  80. enum {
  81. COEX_MODE_SA = 1,
  82. COEX_MODE_XOR,
  83. COEX_MODE_CM,
  84. COEX_MODE_MAX,
  85. };
  86. struct iwm_if_ops;
  87. struct iwm_wifi_cmd;
  88. struct pool_entry {
  89. int id; /* group id */
  90. int sid; /* super group id */
  91. int min_pages; /* min capacity in pages */
  92. int max_pages; /* max capacity in pages */
  93. int alloc_pages; /* allocated # of pages. incresed by driver */
  94. int total_freed_pages; /* total freed # of pages. incresed by UMAC */
  95. };
  96. struct spool_entry {
  97. int id;
  98. int max_pages;
  99. int alloc_pages;
  100. };
  101. struct iwm_tx_credit {
  102. spinlock_t lock;
  103. int pool_nr;
  104. unsigned long full_pools_map; /* bitmap for # of filled tx pools */
  105. struct pool_entry pools[IWM_MACS_OUT_GROUPS];
  106. struct spool_entry spools[IWM_MACS_OUT_SGROUPS];
  107. };
  108. struct iwm_notif {
  109. struct list_head pending;
  110. u32 cmd_id;
  111. void *cmd;
  112. u8 src;
  113. void *buf;
  114. unsigned long buf_size;
  115. };
  116. struct iwm_tid_info {
  117. __le16 last_seq_num;
  118. bool stopped;
  119. struct mutex mutex;
  120. };
  121. struct iwm_sta_info {
  122. u8 addr[ETH_ALEN];
  123. bool valid;
  124. bool qos;
  125. u8 color;
  126. struct iwm_tid_info tid_info[IWM_UMAC_TID_NR];
  127. };
  128. struct iwm_tx_info {
  129. u8 sta;
  130. u8 color;
  131. u8 tid;
  132. };
  133. struct iwm_rx_info {
  134. unsigned long rx_size;
  135. unsigned long rx_buf_size;
  136. };
  137. #define IWM_NUM_KEYS 4
  138. struct iwm_umac_key_hdr {
  139. u8 mac[ETH_ALEN];
  140. u8 key_idx;
  141. u8 multicast; /* BCast encrypt & BCast decrypt of frames FROM mac */
  142. } __packed;
  143. struct iwm_key {
  144. struct iwm_umac_key_hdr hdr;
  145. u32 cipher;
  146. u8 key[WLAN_MAX_KEY_LEN];
  147. u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
  148. int key_len;
  149. int seq_len;
  150. };
  151. #define IWM_RX_ID_HASH 0xff
  152. #define IWM_RX_ID_GET_HASH(id) ((id) % IWM_RX_ID_HASH)
  153. #define IWM_STA_TABLE_NUM 16
  154. #define IWM_TX_LIST_SIZE 64
  155. #define IWM_RX_LIST_SIZE 256
  156. #define IWM_SCAN_ID_MAX 0xff
  157. #define IWM_STATUS_READY 0
  158. #define IWM_STATUS_SCANNING 1
  159. #define IWM_STATUS_SCAN_ABORTING 2
  160. #define IWM_STATUS_SME_CONNECTING 3
  161. #define IWM_STATUS_ASSOCIATED 4
  162. #define IWM_STATUS_RESETTING 5
  163. struct iwm_tx_queue {
  164. int id;
  165. struct sk_buff_head queue;
  166. struct sk_buff_head stopped_queue;
  167. spinlock_t lock;
  168. struct workqueue_struct *wq;
  169. struct work_struct worker;
  170. u8 concat_buf[IWM_HAL_CONCATENATE_BUF_SIZE];
  171. int concat_count;
  172. u8 *concat_ptr;
  173. };
  174. /* Queues 0 ~ 3 for AC data, 5 for iPAN */
  175. #define IWM_TX_QUEUES 5
  176. #define IWM_TX_DATA_QUEUES 4
  177. #define IWM_TX_CMD_QUEUE 4
  178. struct iwm_bss_info {
  179. struct list_head node;
  180. struct cfg80211_bss *cfg_bss;
  181. struct iwm_umac_notif_bss_info *bss;
  182. };
  183. typedef int (*iwm_handler)(struct iwm_priv *priv, u8 *buf,
  184. unsigned long buf_size, struct iwm_wifi_cmd *cmd);
  185. #define IWM_WATCHDOG_PERIOD (6 * HZ)
  186. struct iwm_priv {
  187. struct wireless_dev *wdev;
  188. struct iwm_if_ops *bus_ops;
  189. struct iwm_conf conf;
  190. unsigned long status;
  191. struct list_head pending_notif;
  192. wait_queue_head_t notif_queue;
  193. wait_queue_head_t nonwifi_queue;
  194. unsigned long calib_done_map;
  195. struct {
  196. u8 *buf;
  197. u32 size;
  198. } calib_res[CALIBRATION_CMD_NUM];
  199. struct iwm_umac_profile *umac_profile;
  200. bool umac_profile_active;
  201. u8 bssid[ETH_ALEN];
  202. u8 channel;
  203. u16 rate;
  204. u32 txpower;
  205. struct iwm_sta_info sta_table[IWM_STA_TABLE_NUM];
  206. struct list_head bss_list;
  207. void (*nonwifi_rx_handlers[UMAC_HDI_IN_OPCODE_NONWIFI_MAX])
  208. (struct iwm_priv *priv, u8 *buf, unsigned long buf_size);
  209. const iwm_handler *umac_handlers;
  210. const iwm_handler *lmac_handlers;
  211. DECLARE_BITMAP(lmac_handler_map, LMAC_COMMAND_ID_NUM);
  212. DECLARE_BITMAP(umac_handler_map, LMAC_COMMAND_ID_NUM);
  213. DECLARE_BITMAP(udma_handler_map, LMAC_COMMAND_ID_NUM);
  214. struct list_head wifi_pending_cmd;
  215. struct list_head nonwifi_pending_cmd;
  216. u16 wifi_seq_num;
  217. u8 nonwifi_seq_num;
  218. spinlock_t cmd_lock;
  219. u32 core_enabled;
  220. u8 scan_id;
  221. struct cfg80211_scan_request *scan_request;
  222. struct sk_buff_head rx_list;
  223. struct list_head rx_tickets;
  224. spinlock_t ticket_lock;
  225. struct list_head rx_packets[IWM_RX_ID_HASH];
  226. spinlock_t packet_lock[IWM_RX_ID_HASH];
  227. struct workqueue_struct *rx_wq;
  228. struct work_struct rx_worker;
  229. struct iwm_tx_credit tx_credit;
  230. struct iwm_tx_queue txq[IWM_TX_QUEUES];
  231. struct iwm_key keys[IWM_NUM_KEYS];
  232. s8 default_key;
  233. DECLARE_BITMAP(wifi_ntfy, WIFI_IF_NTFY_MAX);
  234. wait_queue_head_t wifi_ntfy_queue;
  235. wait_queue_head_t mlme_queue;
  236. struct iw_statistics wstats;
  237. struct delayed_work stats_request;
  238. struct delayed_work disconnect;
  239. struct delayed_work ct_kill_delay;
  240. struct iwm_debugfs dbg;
  241. u8 *eeprom;
  242. struct timer_list watchdog;
  243. struct work_struct reset_worker;
  244. struct work_struct auth_retry_worker;
  245. struct mutex mutex;
  246. u8 *req_ie;
  247. int req_ie_len;
  248. u8 *resp_ie;
  249. int resp_ie_len;
  250. struct iwm_fw_error_hdr *last_fw_err;
  251. char umac_version[8];
  252. char lmac_version[8];
  253. char private[0] __attribute__((__aligned__(NETDEV_ALIGN)));
  254. };
  255. static inline void *iwm_private(struct iwm_priv *iwm)
  256. {
  257. BUG_ON(!iwm);
  258. return &iwm->private;
  259. }
  260. #define hw_to_iwm(h) (h->iwm)
  261. #define iwm_to_dev(i) (wiphy_dev(i->wdev->wiphy))
  262. #define iwm_to_wiphy(i) (i->wdev->wiphy)
  263. #define wiphy_to_iwm(w) (struct iwm_priv *)(wiphy_priv(w))
  264. #define iwm_to_wdev(i) (i->wdev)
  265. #define wdev_to_iwm(w) (struct iwm_priv *)(wdev_priv(w))
  266. #define iwm_to_ndev(i) (i->wdev->netdev)
  267. #define ndev_to_iwm(n) (wdev_to_iwm(n->ieee80211_ptr))
  268. #define skb_to_rx_info(s) ((struct iwm_rx_info *)(s->cb))
  269. #define skb_to_tx_info(s) ((struct iwm_tx_info *)s->cb)
  270. void *iwm_if_alloc(int sizeof_bus, struct device *dev,
  271. struct iwm_if_ops *if_ops);
  272. void iwm_if_free(struct iwm_priv *iwm);
  273. int iwm_if_add(struct iwm_priv *iwm);
  274. void iwm_if_remove(struct iwm_priv *iwm);
  275. int iwm_mode_to_nl80211_iftype(int mode);
  276. int iwm_priv_init(struct iwm_priv *iwm);
  277. void iwm_priv_deinit(struct iwm_priv *iwm);
  278. void iwm_reset(struct iwm_priv *iwm);
  279. void iwm_resetting(struct iwm_priv *iwm);
  280. void iwm_tx_credit_init_pools(struct iwm_priv *iwm,
  281. struct iwm_umac_notif_alive *alive);
  282. int iwm_tx_credit_alloc(struct iwm_priv *iwm, int id, int nb);
  283. int iwm_notif_send(struct iwm_priv *iwm, struct iwm_wifi_cmd *cmd,
  284. u8 cmd_id, u8 source, u8 *buf, unsigned long buf_size);
  285. int iwm_notif_handle(struct iwm_priv *iwm, u32 cmd, u8 source, long timeout);
  286. void iwm_init_default_profile(struct iwm_priv *iwm,
  287. struct iwm_umac_profile *profile);
  288. void iwm_link_on(struct iwm_priv *iwm);
  289. void iwm_link_off(struct iwm_priv *iwm);
  290. int iwm_up(struct iwm_priv *iwm);
  291. int iwm_down(struct iwm_priv *iwm);
  292. /* TX API */
  293. int iwm_tid_to_queue(u16 tid);
  294. void iwm_tx_credit_inc(struct iwm_priv *iwm, int id, int total_freed_pages);
  295. void iwm_tx_worker(struct work_struct *work);
  296. int iwm_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
  297. /* RX API */
  298. void iwm_rx_setup_handlers(struct iwm_priv *iwm);
  299. int iwm_rx_handle(struct iwm_priv *iwm, u8 *buf, unsigned long buf_size);
  300. int iwm_rx_handle_resp(struct iwm_priv *iwm, u8 *buf, unsigned long buf_size,
  301. struct iwm_wifi_cmd *cmd);
  302. void iwm_rx_free(struct iwm_priv *iwm);
  303. #endif