wl1271.h 13 KB

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