]> Pileus Git - ~andy/linux/blob - drivers/net/wireless/ti/wlcore/wlcore.h
wlcore: Refactor probe
[~andy/linux] / drivers / net / wireless / ti / wlcore / wlcore.h
1 /*
2  * This file is part of wlcore
3  *
4  * Copyright (C) 2011 Texas Instruments Inc.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * version 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301 USA
19  *
20  */
21
22 #ifndef __WLCORE_H__
23 #define __WLCORE_H__
24
25 #include <linux/platform_device.h>
26
27 #include "wlcore_i.h"
28 #include "event.h"
29 #include "boot.h"
30
31 /* The maximum number of Tx descriptors in all chip families */
32 #define WLCORE_MAX_TX_DESCRIPTORS 32
33
34 /*
35  * We always allocate this number of mac addresses. If we don't
36  * have enough allocated addresses, the LAA bit is used
37  */
38 #define WLCORE_NUM_MAC_ADDRESSES 3
39
40 /* forward declaration */
41 struct wl1271_tx_hw_descr;
42 enum wl_rx_buf_align;
43 struct wl1271_rx_descriptor;
44
45 struct wlcore_ops {
46         int (*setup)(struct wl1271 *wl);
47         int (*identify_chip)(struct wl1271 *wl);
48         int (*identify_fw)(struct wl1271 *wl);
49         int (*boot)(struct wl1271 *wl);
50         int (*plt_init)(struct wl1271 *wl);
51         int (*trigger_cmd)(struct wl1271 *wl, int cmd_box_addr,
52                            void *buf, size_t len);
53         int (*ack_event)(struct wl1271 *wl);
54         u32 (*calc_tx_blocks)(struct wl1271 *wl, u32 len, u32 spare_blks);
55         void (*set_tx_desc_blocks)(struct wl1271 *wl,
56                                    struct wl1271_tx_hw_descr *desc,
57                                    u32 blks, u32 spare_blks);
58         void (*set_tx_desc_data_len)(struct wl1271 *wl,
59                                      struct wl1271_tx_hw_descr *desc,
60                                      struct sk_buff *skb);
61         enum wl_rx_buf_align (*get_rx_buf_align)(struct wl1271 *wl,
62                                                  u32 rx_desc);
63         int (*prepare_read)(struct wl1271 *wl, u32 rx_desc, u32 len);
64         u32 (*get_rx_packet_len)(struct wl1271 *wl, void *rx_data,
65                                  u32 data_len);
66         int (*tx_delayed_compl)(struct wl1271 *wl);
67         void (*tx_immediate_compl)(struct wl1271 *wl);
68         int (*hw_init)(struct wl1271 *wl);
69         int (*init_vif)(struct wl1271 *wl, struct wl12xx_vif *wlvif);
70         u32 (*sta_get_ap_rate_mask)(struct wl1271 *wl,
71                                     struct wl12xx_vif *wlvif);
72         int (*get_pg_ver)(struct wl1271 *wl, s8 *ver);
73         int (*get_mac)(struct wl1271 *wl);
74         void (*set_tx_desc_csum)(struct wl1271 *wl,
75                                  struct wl1271_tx_hw_descr *desc,
76                                  struct sk_buff *skb);
77         void (*set_rx_csum)(struct wl1271 *wl,
78                             struct wl1271_rx_descriptor *desc,
79                             struct sk_buff *skb);
80         u32 (*ap_get_mimo_wide_rate_mask)(struct wl1271 *wl,
81                                           struct wl12xx_vif *wlvif);
82         int (*debugfs_init)(struct wl1271 *wl, struct dentry *rootdir);
83         int (*handle_static_data)(struct wl1271 *wl,
84                                   struct wl1271_static_data *static_data);
85         int (*get_spare_blocks)(struct wl1271 *wl, bool is_gem);
86         int (*set_key)(struct wl1271 *wl, enum set_key_cmd cmd,
87                        struct ieee80211_vif *vif,
88                        struct ieee80211_sta *sta,
89                        struct ieee80211_key_conf *key_conf);
90         u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
91 };
92
93 enum wlcore_partitions {
94         PART_DOWN,
95         PART_WORK,
96         PART_BOOT,
97         PART_DRPW,
98         PART_TOP_PRCM_ELP_SOC,
99         PART_PHY_INIT,
100
101         PART_TABLE_LEN,
102 };
103
104 struct wlcore_partition {
105         u32 size;
106         u32 start;
107 };
108
109 struct wlcore_partition_set {
110         struct wlcore_partition mem;
111         struct wlcore_partition reg;
112         struct wlcore_partition mem2;
113         struct wlcore_partition mem3;
114 };
115
116 enum wlcore_registers {
117         /* register addresses, used with partition translation */
118         REG_ECPU_CONTROL,
119         REG_INTERRUPT_NO_CLEAR,
120         REG_INTERRUPT_ACK,
121         REG_COMMAND_MAILBOX_PTR,
122         REG_EVENT_MAILBOX_PTR,
123         REG_INTERRUPT_TRIG,
124         REG_INTERRUPT_MASK,
125         REG_PC_ON_RECOVERY,
126         REG_CHIP_ID_B,
127         REG_CMD_MBOX_ADDRESS,
128
129         /* data access memory addresses, used with partition translation */
130         REG_SLV_MEM_DATA,
131         REG_SLV_REG_DATA,
132
133         /* raw data access memory addresses */
134         REG_RAW_FW_STATUS_ADDR,
135
136         REG_TABLE_LEN,
137 };
138
139 struct wl1271_stats {
140         void *fw_stats;
141         unsigned long fw_stats_update;
142         size_t fw_stats_len;
143
144         unsigned int retry_count;
145         unsigned int excessive_retries;
146 };
147
148 struct wl1271 {
149         struct ieee80211_hw *hw;
150         bool mac80211_registered;
151
152         struct device *dev;
153         struct platform_device *pdev;
154
155         void *if_priv;
156
157         struct wl1271_if_operations *if_ops;
158
159         void (*set_power)(bool enable);
160         int irq;
161
162         spinlock_t wl_lock;
163
164         enum wlcore_state state;
165         enum wl12xx_fw_type fw_type;
166         bool plt;
167         enum plt_mode plt_mode;
168         u8 fem_manuf;
169         u8 last_vif_count;
170         struct mutex mutex;
171
172         unsigned long flags;
173
174         struct wlcore_partition_set curr_part;
175
176         struct wl1271_chip chip;
177
178         int cmd_box_addr;
179
180         u8 *fw;
181         size_t fw_len;
182         void *nvs;
183         size_t nvs_len;
184
185         s8 hw_pg_ver;
186
187         /* address read from the fuse ROM */
188         u32 fuse_oui_addr;
189         u32 fuse_nic_addr;
190
191         /* we have up to 2 MAC addresses */
192         struct mac_address addresses[WLCORE_NUM_MAC_ADDRESSES];
193         int channel;
194         u8 system_hlid;
195
196         unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
197         unsigned long roles_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
198         unsigned long roc_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
199         unsigned long rate_policies_map[
200                         BITS_TO_LONGS(WL12XX_MAX_RATE_POLICIES)];
201         unsigned long klv_templates_map[
202                         BITS_TO_LONGS(WLCORE_MAX_KLV_TEMPLATES)];
203
204         struct list_head wlvif_list;
205
206         u8 sta_count;
207         u8 ap_count;
208
209         struct wl1271_acx_mem_map *target_mem_map;
210
211         /* Accounting for allocated / available TX blocks on HW */
212         u32 tx_blocks_freed;
213         u32 tx_blocks_available;
214         u32 tx_allocated_blocks;
215         u32 tx_results_count;
216
217         /* Accounting for allocated / available Tx packets in HW */
218         u32 tx_pkts_freed[NUM_TX_QUEUES];
219         u32 tx_allocated_pkts[NUM_TX_QUEUES];
220
221         /* Transmitted TX packets counter for chipset interface */
222         u32 tx_packets_count;
223
224         /* Time-offset between host and chipset clocks */
225         s64 time_offset;
226
227         /* Frames scheduled for transmission, not handled yet */
228         int tx_queue_count[NUM_TX_QUEUES];
229         unsigned long queue_stop_reasons[NUM_TX_QUEUES];
230
231         /* Frames received, not handled yet by mac80211 */
232         struct sk_buff_head deferred_rx_queue;
233
234         /* Frames sent, not returned yet to mac80211 */
235         struct sk_buff_head deferred_tx_queue;
236
237         struct work_struct tx_work;
238         struct workqueue_struct *freezable_wq;
239
240         /* Pending TX frames */
241         unsigned long tx_frames_map[BITS_TO_LONGS(WLCORE_MAX_TX_DESCRIPTORS)];
242         struct sk_buff *tx_frames[WLCORE_MAX_TX_DESCRIPTORS];
243         int tx_frames_cnt;
244
245         /* FW Rx counter */
246         u32 rx_counter;
247
248         /* Intermediate buffer, used for packet aggregation */
249         u8 *aggr_buf;
250         u32 aggr_buf_size;
251
252         /* Reusable dummy packet template */
253         struct sk_buff *dummy_packet;
254
255         /* Network stack work  */
256         struct work_struct netstack_work;
257
258         /* FW log buffer */
259         u8 *fwlog;
260
261         /* Number of valid bytes in the FW log buffer */
262         ssize_t fwlog_size;
263
264         /* Sysfs FW log entry readers wait queue */
265         wait_queue_head_t fwlog_waitq;
266
267         /* Hardware recovery work */
268         struct work_struct recovery_work;
269         bool watchdog_recovery;
270
271         /* Pointer that holds DMA-friendly block for the mailbox */
272         struct event_mailbox *mbox;
273
274         /* The mbox event mask */
275         u32 event_mask;
276
277         /* Mailbox pointers */
278         u32 mbox_ptr[2];
279
280         /* Are we currently scanning */
281         struct ieee80211_vif *scan_vif;
282         struct wl1271_scan scan;
283         struct delayed_work scan_complete_work;
284
285         /* Connection loss work */
286         struct delayed_work connection_loss_work;
287
288         bool sched_scanning;
289
290         /* The current band */
291         enum ieee80211_band band;
292
293         struct completion *elp_compl;
294         struct delayed_work elp_work;
295
296         /* in dBm */
297         int power_level;
298
299         struct wl1271_stats stats;
300
301         __le32 buffer_32;
302         u32 buffer_cmd;
303         u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
304
305         struct wl_fw_status_1 *fw_status_1;
306         struct wl_fw_status_2 *fw_status_2;
307         struct wl1271_tx_hw_res_if *tx_res_if;
308
309         /* Current chipset configuration */
310         struct wlcore_conf conf;
311
312         bool sg_enabled;
313
314         bool enable_11a;
315
316         /* Most recently reported noise in dBm */
317         s8 noise;
318
319         /* bands supported by this instance of wl12xx */
320         struct ieee80211_supported_band bands[WLCORE_NUM_BANDS];
321
322         /*
323          * wowlan trigger was configured during suspend.
324          * (currently, only "ANY" trigger is supported)
325          */
326         bool wow_enabled;
327         bool irq_wake_enabled;
328
329         /*
330          * AP-mode - links indexed by HLID. The global and broadcast links
331          * are always active.
332          */
333         struct wl1271_link links[WL12XX_MAX_LINKS];
334
335         /* AP-mode - a bitmap of links currently in PS mode according to FW */
336         u32 ap_fw_ps_map;
337
338         /* AP-mode - a bitmap of links currently in PS mode in mac80211 */
339         unsigned long ap_ps_map;
340
341         /* Quirks of specific hardware revisions */
342         unsigned int quirks;
343
344         /* Platform limitations */
345         unsigned int platform_quirks;
346
347         /* number of currently active RX BA sessions */
348         int ba_rx_session_count;
349
350         /* AP-mode - number of currently connected stations */
351         int active_sta_count;
352
353         /* last wlvif we transmitted from */
354         struct wl12xx_vif *last_wlvif;
355
356         /* work to fire when Tx is stuck */
357         struct delayed_work tx_watchdog_work;
358
359         struct wlcore_ops *ops;
360         /* pointer to the lower driver partition table */
361         const struct wlcore_partition_set *ptable;
362         /* pointer to the lower driver register table */
363         const int *rtable;
364         /* name of the firmwares to load - for PLT, single role, multi-role */
365         const char *plt_fw_name;
366         const char *sr_fw_name;
367         const char *mr_fw_name;
368
369         /* per-chip-family private structure */
370         void *priv;
371
372         /* number of TX descriptors the HW supports. */
373         u32 num_tx_desc;
374         /* number of RX descriptors the HW supports. */
375         u32 num_rx_desc;
376
377         /* translate HW Tx rates to standard rate-indices */
378         const u8 **band_rate_to_idx;
379
380         /* size of table for HW rates that can be received from chip */
381         u8 hw_tx_rate_tbl_size;
382
383         /* this HW rate and below are considered HT rates for this chip */
384         u8 hw_min_ht_rate;
385
386         /* HW HT (11n) capabilities */
387         struct ieee80211_sta_ht_cap ht_cap[WLCORE_NUM_BANDS];
388
389         /* size of the private FW status data */
390         size_t fw_status_priv_len;
391
392         /* RX Data filter rule state - enabled/disabled */
393         bool rx_filter_enabled[WL1271_MAX_RX_FILTERS];
394
395         /* size of the private static data */
396         size_t static_data_priv_len;
397
398         /* the current channel type */
399         enum nl80211_channel_type channel_type;
400
401         /* mutex for protecting the tx_flush function */
402         struct mutex flush_mutex;
403
404         /* sleep auth value currently configured to FW */
405         int sleep_auth;
406
407         /* the number of allocated MAC addresses in this chip */
408         int num_mac_addr;
409
410         /* the minimum FW version required for the driver to work */
411         unsigned int min_fw_ver[NUM_FW_VER];
412 };
413
414 int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev);
415 int __devexit wlcore_remove(struct platform_device *pdev);
416 struct ieee80211_hw *wlcore_alloc_hw(size_t priv_size, u32 aggr_buf_size);
417 int wlcore_free_hw(struct wl1271 *wl);
418 int wlcore_set_key(struct wl1271 *wl, enum set_key_cmd cmd,
419                    struct ieee80211_vif *vif,
420                    struct ieee80211_sta *sta,
421                    struct ieee80211_key_conf *key_conf);
422
423 static inline void
424 wlcore_set_ht_cap(struct wl1271 *wl, enum ieee80211_band band,
425                   struct ieee80211_sta_ht_cap *ht_cap)
426 {
427         memcpy(&wl->ht_cap[band], ht_cap, sizeof(*ht_cap));
428 }
429
430 static inline void
431 wlcore_set_min_fw_ver(struct wl1271 *wl, unsigned int chip,
432                       unsigned int iftype, unsigned int major,
433                       unsigned int subtype, unsigned int minor)
434 {
435         wl->min_fw_ver[FW_VER_CHIP] = chip;
436         wl->min_fw_ver[FW_VER_IF_TYPE] = iftype;
437         wl->min_fw_ver[FW_VER_MAJOR] = major;
438         wl->min_fw_ver[FW_VER_SUBTYPE] = subtype;
439         wl->min_fw_ver[FW_VER_MINOR] = minor;
440 }
441
442 /* Firmware image load chunk size */
443 #define CHUNK_SIZE      16384
444
445 /* Quirks */
446
447 /* Each RX/TX transaction requires an end-of-transaction transfer */
448 #define WLCORE_QUIRK_END_OF_TRANSACTION         BIT(0)
449
450 /* wl127x and SPI don't support SDIO block size alignment */
451 #define WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN         BIT(2)
452
453 /* means aggregated Rx packets are aligned to a SDIO block */
454 #define WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN         BIT(3)
455
456 /* Older firmwares did not implement the FW logger over bus feature */
457 #define WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED      BIT(4)
458
459 /* Older firmwares use an old NVS format */
460 #define WLCORE_QUIRK_LEGACY_NVS                 BIT(5)
461
462 /* Some firmwares may not support ELP */
463 #define WLCORE_QUIRK_NO_ELP                     BIT(6)
464
465 /* pad only the last frame in the aggregate buffer */
466 #define WLCORE_QUIRK_TX_PAD_LAST_FRAME          BIT(7)
467
468 /* extra header space is required for TKIP */
469 #define WLCORE_QUIRK_TKIP_HEADER_SPACE          BIT(8)
470
471 /* Some firmwares not support sched scans while connected */
472 #define WLCORE_QUIRK_NO_SCHED_SCAN_WHILE_CONN   BIT(9)
473
474 /* separate probe response templates for one-shot and sched scans */
475 #define WLCORE_QUIRK_DUAL_PROBE_TMPL            BIT(10)
476
477 /* TODO: move to the lower drivers when all usages are abstracted */
478 #define CHIP_ID_1271_PG10              (0x4030101)
479 #define CHIP_ID_1271_PG20              (0x4030111)
480 #define CHIP_ID_1283_PG10              (0x05030101)
481 #define CHIP_ID_1283_PG20              (0x05030111)
482
483 /* TODO: move all these common registers and values elsewhere */
484 #define HW_ACCESS_ELP_CTRL_REG          0x1FFFC
485
486 /* ELP register commands */
487 #define ELPCTRL_WAKE_UP             0x1
488 #define ELPCTRL_WAKE_UP_WLAN_READY  0x5
489 #define ELPCTRL_SLEEP               0x0
490 /* ELP WLAN_READY bit */
491 #define ELPCTRL_WLAN_READY          0x2
492
493 /*************************************************************************
494
495     Interrupt Trigger Register (Host -> WiLink)
496
497 **************************************************************************/
498
499 /* Hardware to Embedded CPU Interrupts - first 32-bit register set */
500
501 /*
502  * The host sets this bit to inform the Wlan
503  * FW that a TX packet is in the XFER
504  * Buffer #0.
505  */
506 #define INTR_TRIG_TX_PROC0 BIT(2)
507
508 /*
509  * The host sets this bit to inform the FW
510  * that it read a packet from RX XFER
511  * Buffer #0.
512  */
513 #define INTR_TRIG_RX_PROC0 BIT(3)
514
515 #define INTR_TRIG_DEBUG_ACK BIT(4)
516
517 #define INTR_TRIG_STATE_CHANGED BIT(5)
518
519 /* Hardware to Embedded CPU Interrupts - second 32-bit register set */
520
521 /*
522  * The host sets this bit to inform the FW
523  * that it read a packet from RX XFER
524  * Buffer #1.
525  */
526 #define INTR_TRIG_RX_PROC1 BIT(17)
527
528 /*
529  * The host sets this bit to inform the Wlan
530  * hardware that a TX packet is in the XFER
531  * Buffer #1.
532  */
533 #define INTR_TRIG_TX_PROC1 BIT(18)
534
535 #define ACX_SLV_SOFT_RESET_BIT  BIT(1)
536 #define SOFT_RESET_MAX_TIME     1000000
537 #define SOFT_RESET_STALL_TIME   1000
538
539 #define ECPU_CONTROL_HALT       0x00000101
540
541 #define WELP_ARM_COMMAND_VAL    0x4
542
543 #endif /* __WLCORE_H__ */