Merge branch 'master' into radar
[carl9170fw.git] / carlfw / include / carl9170.h
1 /*
2  * carl9170 firmware - used by the ar9170 wireless device
3  *
4  * Firmware context definition
5  *
6  * Copyright 2009-2011 Christian Lamparter <chunkeey@googlemail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #ifndef __CARL9170FW_CARL9170_H
24 #define __CARL9170FW_CARL9170_H
25
26 #include "generated/autoconf.h"
27 #include "version.h"
28 #include "config.h"
29 #include "types.h"
30 #include "compiler.h"
31 #include "fwcmd.h"
32 #include "hw.h"
33 #include "dma.h"
34 #include "usb.h"
35 #include "cmd.h"
36 #include "radar.h"
37
38 struct carl9170_bar_ctx {
39         uint8_t ta[6];
40         uint8_t ra[6];
41         __le16 start_seq_num;
42         __le16 control;
43 };
44
45 enum carl9170_cab_trigger {
46         CARL9170_CAB_TRIGGER_EMPTY      = 0,
47         CARL9170_CAB_TRIGGER_ARMED      = BIT(0),
48         CARL9170_CAB_TRIGGER_DEFER      = BIT(1),
49 };
50
51 enum carl9170_ep0_action {
52         CARL9170_EP0_NO_ACTION          = 0,
53         CARL9170_EP0_STALL              = BIT(0),
54         CARL9170_EP0_TRIGGER            = BIT(1),
55 };
56
57 enum carl9170_mac_reset_state {
58         CARL9170_MAC_RESET_OFF          = 0,
59         CARL9170_MAC_RESET_ARMED,
60         CARL9170_MAC_RESET_RESET,
61         CARL9170_MAC_RESET_FORCE,
62 };
63
64 enum carl9170_suspend_mode {
65         CARL9170_HOST_AWAKE                     = 0,
66         CARL9170_HOST_SUSPENDED,
67         CARL9170_AWAKE_HOST,
68 };
69
70 enum carl9170_phy_state {
71         CARL9170_PHY_OFF                = 0,
72         CARL9170_PHY_ON
73 };
74
75 typedef void (*fw_desc_callback_t)(void *, const bool);
76
77 /*
78  * This platform - being an odd 32-bit architecture - prefers to
79  * have 32-Bit variables.
80  */
81
82 struct firmware_context_struct {
83         /* timer / clocks */
84         unsigned int ticks_per_usec;
85         unsigned int counter;                   /* main() cycles */
86
87         /* misc */
88         unsigned int watchdog_enable;
89         unsigned int reboot;
90         unsigned int suspend_mode;
91
92         struct {
93                 /* Host Interface DMA queues */
94                 struct dma_queue up_queue;      /* used to send frames to the host */
95                 struct dma_queue down_queue;    /* stores incoming frames from the host */
96         } pta;
97
98         struct {
99                 /* Hardware DMA queues */
100                 struct dma_queue tx_queue[__AR9170_NUM_TX_QUEUES];      /* wlan tx queue */
101                 struct dma_queue tx_retry;
102                 struct dma_queue rx_queue;                              /* wlan rx queue */
103
104                 /* tx aggregate scheduling */
105                 struct carl9170_tx_superframe *ampdu_prev[__AR9170_NUM_TX_QUEUES];
106
107                 /* Hardware DMA queue unstuck/fix detection */
108                 unsigned int last_super_num[__AR9170_NUM_TX_QUEUES];
109                 struct carl9170_tx_superframe *last_super[__AR9170_NUM_TX_QUEUES];
110                 unsigned int mac_reset;
111                 unsigned int soft_int;
112
113                 /* rx filter */
114                 unsigned int rx_filter;
115
116                 /* tx sequence control counters */
117                 unsigned int sequence[CARL9170_INTF_NUM];
118
119                 /* CAB */
120                 struct dma_queue cab_queue[CARL9170_INTF_NUM];
121                 unsigned int cab_queue_len[CARL9170_INTF_NUM];
122                 unsigned int cab_flush_time;
123                 enum carl9170_cab_trigger cab_flush_trigger[CARL9170_INTF_NUM];
124
125                 /* tx status */
126                 unsigned int tx_status_pending,
127                              tx_status_head_idx,
128                              tx_status_tail_idx;
129                 struct carl9170_tx_status tx_status_cache[CARL9170_TX_STATUS_NUM];
130
131                 /* internal descriptor for use within the service routines */
132                 struct dma_desc *fw_desc;
133                 unsigned int fw_desc_available;
134                 void *fw_desc_data;
135                 fw_desc_callback_t fw_desc_callback;
136
137                 /* BA(R) Request Handler */
138                 struct carl9170_bar_ctx ba_cache[CONFIG_CARL9170FW_BACK_REQS_NUM];
139                 unsigned int ba_tail_idx,
140                              ba_head_idx,
141                              queued_ba;
142
143                 unsigned int queued_bar;
144
145 #ifdef CONFIG_CARL9170FW_RADAR
146                 unsigned int soft_radar,
147                              radar_last,
148                              pattern_index;
149 #endif /* CONFIG_CARL9170FW_RADAR */
150         } wlan;
151
152         struct {
153                 unsigned int config,
154                              interface_setting,
155                              alternate_interface_setting,
156                              device_feature;
157                 enum carl9170_ep0_action ep0_action;
158
159                 void *ep0_txrx_buffer;
160                 unsigned int ep0_txrx_len,
161                              ep0_txrx_pos;
162
163                 struct ar9170_usb_config *cfg_desc;
164                 struct ar9170_usb_config *os_cfg_desc;
165
166                 /*
167                  * special buffers for command & response handling
168                  *
169                  * the firmware uses a sort of ring-buffer to communicate
170                  * to the host.
171                  */
172                 unsigned int int_pending,
173                              int_desc_available,
174                              int_head_index,
175                              int_tail_index;
176                 struct dma_desc *int_desc;
177                 struct carl9170_rsp int_buf[CARL9170_INT_RQ_CACHES];
178
179 #ifdef CONFIG_CARL9170FW_DEBUG_USB
180                 /* USB printf */
181                 unsigned int put_index;
182                 uint8_t put_buffer[CARL9170_MAX_CMD_PAYLOAD_LEN];
183 #endif /* CONFIG_CARL9170FW_DEBUG_USB */
184
185         } usb;
186
187         struct {
188 #ifdef CONFIG_CARL9170FW_RADIO_FUNCTIONS
189                 /* (cached) ar9170_rf_init */
190
191                 /* PHY/RF state */
192                 unsigned int frequency;
193                 unsigned int ht_settings;
194
195                 enum carl9170_phy_state state;
196                 struct carl9170_psm psm;
197 #endif /* CONFIG_CARL9170FW_RADIO_FUNCTIONS */
198         } phy;
199
200         unsigned int tally_clock;
201         struct carl9170_tally_rsp tally;
202         unsigned int tx_time;
203
204 #ifdef CONFIG_CARL9170FW_WOL
205         struct {
206                 struct carl9170_wol_cmd cmd;
207                 unsigned int last_beacon;
208                 unsigned int lost_null;
209                 unsigned int last_null;
210                 bool wake_up;
211         } wol;
212 #endif /* CONFIG_CARL9170FW_WOL */
213
214 #ifdef CONFIG_CARL9170FW_GPIO_INTERRUPT
215         struct carl9170_gpio cached_gpio_state;
216 #endif /*CONFIG_CARL9170FW_GPIO_INTERRUPT */
217 };
218
219 /*
220  * global firmware context struct.
221  *
222  * NOTE: This struct will zeroed out in start()
223  */
224 extern struct firmware_context_struct fw;
225 #endif /* __CARL9170FW_CARL9170_H */