wl1271.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
  5. * Copyright (C) 2008-2009 Nokia Corporation
  6. *
  7. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. #ifndef __WL1271_H__
  25. #define __WL1271_H__
  26. #include <linux/mutex.h>
  27. #include <linux/completion.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/list.h>
  30. #include <linux/bitops.h>
  31. #include <net/mac80211.h>
  32. #include "wl1271_conf.h"
  33. #define DRIVER_NAME "wl1271"
  34. #define DRIVER_PREFIX DRIVER_NAME ": "
  35. enum {
  36. DEBUG_NONE = 0,
  37. DEBUG_IRQ = BIT(0),
  38. DEBUG_SPI = BIT(1),
  39. DEBUG_BOOT = BIT(2),
  40. DEBUG_MAILBOX = BIT(3),
  41. DEBUG_TESTMODE = BIT(4),
  42. DEBUG_EVENT = BIT(5),
  43. DEBUG_TX = BIT(6),
  44. DEBUG_RX = BIT(7),
  45. DEBUG_SCAN = BIT(8),
  46. DEBUG_CRYPT = BIT(9),
  47. DEBUG_PSM = BIT(10),
  48. DEBUG_MAC80211 = BIT(11),
  49. DEBUG_CMD = BIT(12),
  50. DEBUG_ACX = BIT(13),
  51. DEBUG_SDIO = BIT(14),
  52. DEBUG_FILTERS = BIT(15),
  53. DEBUG_ALL = ~0,
  54. };
  55. #define DEBUG_LEVEL (DEBUG_NONE)
  56. #define DEBUG_DUMP_LIMIT 1024
  57. #define wl1271_error(fmt, arg...) \
  58. printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
  59. #define wl1271_warning(fmt, arg...) \
  60. printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
  61. #define wl1271_notice(fmt, arg...) \
  62. printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
  63. #define wl1271_info(fmt, arg...) \
  64. printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
  65. #define wl1271_debug(level, fmt, arg...) \
  66. do { \
  67. if (level & DEBUG_LEVEL) \
  68. printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
  69. } while (0)
  70. #define wl1271_dump(level, prefix, buf, len) \
  71. do { \
  72. if (level & DEBUG_LEVEL) \
  73. print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
  74. DUMP_PREFIX_OFFSET, 16, 1, \
  75. buf, \
  76. min_t(size_t, len, DEBUG_DUMP_LIMIT), \
  77. 0); \
  78. } while (0)
  79. #define wl1271_dump_ascii(level, prefix, buf, len) \
  80. do { \
  81. if (level & DEBUG_LEVEL) \
  82. print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
  83. DUMP_PREFIX_OFFSET, 16, 1, \
  84. buf, \
  85. min_t(size_t, len, DEBUG_DUMP_LIMIT), \
  86. true); \
  87. } while (0)
  88. #define WL1271_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
  89. CFG_BSSID_FILTER_EN | \
  90. CFG_MC_FILTER_EN)
  91. #define WL1271_DEFAULT_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN | \
  92. CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \
  93. CFG_RX_CTL_EN | CFG_RX_BCN_EN | \
  94. CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
  95. #define WL1271_FW_NAME "wl1271-fw.bin"
  96. #define WL1271_NVS_NAME "wl1271-nvs.bin"
  97. #define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
  98. #define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
  99. /* NVS data structure */
  100. #define WL1271_NVS_SECTION_SIZE 468
  101. #define WL1271_NVS_GENERAL_PARAMS_SIZE 57
  102. #define WL1271_NVS_GENERAL_PARAMS_SIZE_PADDED \
  103. (WL1271_NVS_GENERAL_PARAMS_SIZE + 1)
  104. #define WL1271_NVS_STAT_RADIO_PARAMS_SIZE 17
  105. #define WL1271_NVS_STAT_RADIO_PARAMS_SIZE_PADDED \
  106. (WL1271_NVS_STAT_RADIO_PARAMS_SIZE + 1)
  107. #define WL1271_NVS_DYN_RADIO_PARAMS_SIZE 65
  108. #define WL1271_NVS_DYN_RADIO_PARAMS_SIZE_PADDED \
  109. (WL1271_NVS_DYN_RADIO_PARAMS_SIZE + 1)
  110. #define WL1271_NVS_FEM_COUNT 2
  111. #define WL1271_NVS_INI_SPARE_SIZE 124
  112. struct wl1271_nvs_file {
  113. /* NVS section */
  114. u8 nvs[WL1271_NVS_SECTION_SIZE];
  115. /* INI section */
  116. u8 general_params[WL1271_NVS_GENERAL_PARAMS_SIZE_PADDED];
  117. u8 stat_radio_params[WL1271_NVS_STAT_RADIO_PARAMS_SIZE_PADDED];
  118. u8 dyn_radio_params[WL1271_NVS_FEM_COUNT]
  119. [WL1271_NVS_DYN_RADIO_PARAMS_SIZE_PADDED];
  120. u8 ini_spare[WL1271_NVS_INI_SPARE_SIZE];
  121. } __attribute__ ((packed));
  122. /*
  123. * Enable/disable 802.11a support for WL1273
  124. */
  125. #undef WL1271_80211A_ENABLED
  126. #define WL1271_BUSY_WORD_CNT 1
  127. #define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
  128. #define WL1271_ELP_HW_STATE_ASLEEP 0
  129. #define WL1271_ELP_HW_STATE_IRQ 1
  130. #define WL1271_DEFAULT_BEACON_INT 100
  131. #define WL1271_DEFAULT_DTIM_PERIOD 1
  132. #define ACX_TX_DESCRIPTORS 32
  133. enum wl1271_state {
  134. WL1271_STATE_OFF,
  135. WL1271_STATE_ON,
  136. WL1271_STATE_PLT,
  137. };
  138. enum wl1271_partition_type {
  139. PART_DOWN,
  140. PART_WORK,
  141. PART_DRPW,
  142. PART_TABLE_LEN
  143. };
  144. struct wl1271_partition {
  145. u32 size;
  146. u32 start;
  147. };
  148. struct wl1271_partition_set {
  149. struct wl1271_partition mem;
  150. struct wl1271_partition reg;
  151. struct wl1271_partition mem2;
  152. struct wl1271_partition mem3;
  153. };
  154. struct wl1271;
  155. /* FIXME: I'm not sure about this structure name */
  156. struct wl1271_chip {
  157. u32 id;
  158. char fw_ver[21];
  159. };
  160. struct wl1271_stats {
  161. struct acx_statistics *fw_stats;
  162. unsigned long fw_stats_update;
  163. unsigned int retry_count;
  164. unsigned int excessive_retries;
  165. };
  166. struct wl1271_debugfs {
  167. struct dentry *rootdir;
  168. struct dentry *fw_statistics;
  169. struct dentry *tx_internal_desc_overflow;
  170. struct dentry *rx_out_of_mem;
  171. struct dentry *rx_hdr_overflow;
  172. struct dentry *rx_hw_stuck;
  173. struct dentry *rx_dropped;
  174. struct dentry *rx_fcs_err;
  175. struct dentry *rx_xfr_hint_trig;
  176. struct dentry *rx_path_reset;
  177. struct dentry *rx_reset_counter;
  178. struct dentry *dma_rx_requested;
  179. struct dentry *dma_rx_errors;
  180. struct dentry *dma_tx_requested;
  181. struct dentry *dma_tx_errors;
  182. struct dentry *isr_cmd_cmplt;
  183. struct dentry *isr_fiqs;
  184. struct dentry *isr_rx_headers;
  185. struct dentry *isr_rx_mem_overflow;
  186. struct dentry *isr_rx_rdys;
  187. struct dentry *isr_irqs;
  188. struct dentry *isr_tx_procs;
  189. struct dentry *isr_decrypt_done;
  190. struct dentry *isr_dma0_done;
  191. struct dentry *isr_dma1_done;
  192. struct dentry *isr_tx_exch_complete;
  193. struct dentry *isr_commands;
  194. struct dentry *isr_rx_procs;
  195. struct dentry *isr_hw_pm_mode_changes;
  196. struct dentry *isr_host_acknowledges;
  197. struct dentry *isr_pci_pm;
  198. struct dentry *isr_wakeups;
  199. struct dentry *isr_low_rssi;
  200. struct dentry *wep_addr_key_count;
  201. struct dentry *wep_default_key_count;
  202. /* skipping wep.reserved */
  203. struct dentry *wep_key_not_found;
  204. struct dentry *wep_decrypt_fail;
  205. struct dentry *wep_packets;
  206. struct dentry *wep_interrupt;
  207. struct dentry *pwr_ps_enter;
  208. struct dentry *pwr_elp_enter;
  209. struct dentry *pwr_missing_bcns;
  210. struct dentry *pwr_wake_on_host;
  211. struct dentry *pwr_wake_on_timer_exp;
  212. struct dentry *pwr_tx_with_ps;
  213. struct dentry *pwr_tx_without_ps;
  214. struct dentry *pwr_rcvd_beacons;
  215. struct dentry *pwr_power_save_off;
  216. struct dentry *pwr_enable_ps;
  217. struct dentry *pwr_disable_ps;
  218. struct dentry *pwr_fix_tsf_ps;
  219. /* skipping cont_miss_bcns_spread for now */
  220. struct dentry *pwr_rcvd_awake_beacons;
  221. struct dentry *mic_rx_pkts;
  222. struct dentry *mic_calc_failure;
  223. struct dentry *aes_encrypt_fail;
  224. struct dentry *aes_decrypt_fail;
  225. struct dentry *aes_encrypt_packets;
  226. struct dentry *aes_decrypt_packets;
  227. struct dentry *aes_encrypt_interrupt;
  228. struct dentry *aes_decrypt_interrupt;
  229. struct dentry *event_heart_beat;
  230. struct dentry *event_calibration;
  231. struct dentry *event_rx_mismatch;
  232. struct dentry *event_rx_mem_empty;
  233. struct dentry *event_rx_pool;
  234. struct dentry *event_oom_late;
  235. struct dentry *event_phy_transmit_error;
  236. struct dentry *event_tx_stuck;
  237. struct dentry *ps_pspoll_timeouts;
  238. struct dentry *ps_upsd_timeouts;
  239. struct dentry *ps_upsd_max_sptime;
  240. struct dentry *ps_upsd_max_apturn;
  241. struct dentry *ps_pspoll_max_apturn;
  242. struct dentry *ps_pspoll_utilization;
  243. struct dentry *ps_upsd_utilization;
  244. struct dentry *rxpipe_rx_prep_beacon_drop;
  245. struct dentry *rxpipe_descr_host_int_trig_rx_data;
  246. struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
  247. struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
  248. struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
  249. struct dentry *tx_queue_len;
  250. struct dentry *retry_count;
  251. struct dentry *excessive_retries;
  252. struct dentry *gpio_power;
  253. };
  254. #define NUM_TX_QUEUES 4
  255. #define NUM_RX_PKT_DESC 8
  256. /* FW status registers */
  257. struct wl1271_fw_status {
  258. __le32 intr;
  259. u8 fw_rx_counter;
  260. u8 drv_rx_counter;
  261. u8 reserved;
  262. u8 tx_results_counter;
  263. __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
  264. __le32 tx_released_blks[NUM_TX_QUEUES];
  265. __le32 fw_localtime;
  266. __le32 padding[2];
  267. } __attribute__ ((packed));
  268. struct wl1271_rx_mem_pool_addr {
  269. u32 addr;
  270. u32 addr_extra;
  271. };
  272. struct wl1271_scan {
  273. u8 state;
  274. u8 ssid[IW_ESSID_MAX_SIZE+1];
  275. size_t ssid_len;
  276. u8 active;
  277. u8 high_prio;
  278. u8 probe_requests;
  279. };
  280. struct wl1271_if_operations {
  281. void (*read)(struct wl1271 *wl, int addr, void *buf, size_t len,
  282. bool fixed);
  283. void (*write)(struct wl1271 *wl, int addr, void *buf, size_t len,
  284. bool fixed);
  285. void (*reset)(struct wl1271 *wl);
  286. void (*init)(struct wl1271 *wl);
  287. void (*power)(struct wl1271 *wl, bool enable);
  288. struct device* (*dev)(struct wl1271 *wl);
  289. void (*enable_irq)(struct wl1271 *wl);
  290. void (*disable_irq)(struct wl1271 *wl);
  291. };
  292. struct wl1271 {
  293. struct platform_device *plat_dev;
  294. struct ieee80211_hw *hw;
  295. bool mac80211_registered;
  296. void *if_priv;
  297. struct wl1271_if_operations *if_ops;
  298. void (*set_power)(bool enable);
  299. int irq;
  300. spinlock_t wl_lock;
  301. enum wl1271_state state;
  302. struct mutex mutex;
  303. #define WL1271_FLAG_STA_RATES_CHANGED (0)
  304. #define WL1271_FLAG_STA_ASSOCIATED (1)
  305. #define WL1271_FLAG_JOINED (2)
  306. #define WL1271_FLAG_GPIO_POWER (3)
  307. #define WL1271_FLAG_TX_QUEUE_STOPPED (4)
  308. #define WL1271_FLAG_SCANNING (5)
  309. #define WL1271_FLAG_IN_ELP (6)
  310. #define WL1271_FLAG_PSM (7)
  311. #define WL1271_FLAG_PSM_REQUESTED (8)
  312. #define WL1271_FLAG_IRQ_PENDING (9)
  313. #define WL1271_FLAG_IRQ_RUNNING (10)
  314. unsigned long flags;
  315. struct wl1271_partition_set part;
  316. struct wl1271_chip chip;
  317. int cmd_box_addr;
  318. int event_box_addr;
  319. u8 *fw;
  320. size_t fw_len;
  321. struct wl1271_nvs_file *nvs;
  322. u8 bssid[ETH_ALEN];
  323. u8 mac_addr[ETH_ALEN];
  324. u8 bss_type;
  325. u8 ssid[IW_ESSID_MAX_SIZE + 1];
  326. u8 ssid_len;
  327. int channel;
  328. struct wl1271_acx_mem_map *target_mem_map;
  329. /* Accounting for allocated / available TX blocks on HW */
  330. u32 tx_blocks_freed[NUM_TX_QUEUES];
  331. u32 tx_blocks_available;
  332. u32 tx_results_count;
  333. /* Transmitted TX packets counter for chipset interface */
  334. u32 tx_packets_count;
  335. /* Time-offset between host and chipset clocks */
  336. s64 time_offset;
  337. /* Session counter for the chipset */
  338. int session_counter;
  339. /* Frames scheduled for transmission, not handled yet */
  340. struct sk_buff_head tx_queue;
  341. struct work_struct tx_work;
  342. /* Pending TX frames */
  343. struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
  344. /* Security sequence number counters */
  345. u8 tx_security_last_seq;
  346. s64 tx_security_seq;
  347. /* FW Rx counter */
  348. u32 rx_counter;
  349. /* Rx memory pool address */
  350. struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
  351. /* The target interrupt mask */
  352. struct work_struct irq_work;
  353. /* The mbox event mask */
  354. u32 event_mask;
  355. /* Mailbox pointers */
  356. u32 mbox_ptr[2];
  357. /* Are we currently scanning */
  358. struct wl1271_scan scan;
  359. /* Our association ID */
  360. u16 aid;
  361. /* currently configured rate set */
  362. u32 sta_rate_set;
  363. u32 basic_rate_set;
  364. u32 rate_set;
  365. /* The current band */
  366. enum ieee80211_band band;
  367. /* Default key (for WEP) */
  368. u32 default_key;
  369. unsigned int filters;
  370. unsigned int rx_config;
  371. unsigned int rx_filter;
  372. struct completion *elp_compl;
  373. struct delayed_work elp_work;
  374. /* retry counter for PSM entries */
  375. u8 psm_entry_retry;
  376. /* in dBm */
  377. int power_level;
  378. struct wl1271_stats stats;
  379. struct wl1271_debugfs debugfs;
  380. u32 buffer_32;
  381. u32 buffer_cmd;
  382. u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
  383. struct wl1271_fw_status *fw_status;
  384. struct wl1271_tx_hw_res_if *tx_res_if;
  385. struct ieee80211_vif *vif;
  386. /* Current chipset configuration */
  387. struct conf_drv_settings conf;
  388. bool sg_enabled;
  389. struct list_head list;
  390. };
  391. int wl1271_plt_start(struct wl1271 *wl);
  392. int wl1271_plt_stop(struct wl1271 *wl);
  393. #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
  394. #define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */
  395. #define WL1271_DEFAULT_POWER_LEVEL 0
  396. #define WL1271_TX_QUEUE_LOW_WATERMARK 10
  397. #define WL1271_TX_QUEUE_HIGH_WATERMARK 25
  398. /* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
  399. on in case is has been shut down shortly before */
  400. #define WL1271_PRE_POWER_ON_SLEEP 20 /* in miliseconds */
  401. #define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */
  402. static inline bool wl1271_11a_enabled(void)
  403. {
  404. /* FIXME: this could be determined based on the NVS-INI file */
  405. #ifdef WL1271_80211A_ENABLED
  406. return true;
  407. #else
  408. return false;
  409. #endif
  410. }
  411. #endif