6dfdf3e56df000087a3e7acdde93ebb49182be64
[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
37 struct carl9170_bar_ctx {
38         uint8_t ta[6];
39         uint8_t ra[6];
40         __le16 start_seq_num;
41         __le16 control;
42         __le32 phy;
43 };
44
45 #ifdef CONFIG_CARL9170FW_CAB_QUEUE
46 enum carl9170_cab_trigger {
47         CARL9170_CAB_TRIGGER_EMPTY      = 0,
48         CARL9170_CAB_TRIGGER_ARMED      = BIT(0),
49         CARL9170_CAB_TRIGGER_DEFER      = BIT(1),
50 };
51 #endif /* CONFIG_CARL9170FW_CAB_QUEUE */
52
53 enum carl9170_ep0_action {
54         CARL9170_EP0_NO_ACTION          = 0,
55         CARL9170_EP0_STALL              = BIT(0),
56         CARL9170_EP0_TRIGGER            = BIT(1),
57 };
58
59 enum carl9170_mac_reset_state {
60         CARL9170_MAC_RESET_OFF          = 0,
61         CARL9170_MAC_RESET_ARMED,
62         CARL9170_MAC_RESET_RESET,
63         CARL9170_MAC_RESET_FORCE,
64 };
65
66 enum carl9170_suspend_mode {
67         CARL9170_HOST_AWAKE                     = 0,
68         CARL9170_HOST_SUSPENDED,
69         CARL9170_AWAKE_HOST,
70 };
71
72 enum carl9170_phy_state {
73         CARL9170_PHY_OFF                = 0,
74         CARL9170_PHY_ON
75 };
76
77 typedef void (*fw_desc_callback_t)(void *, const bool);
78
79 /*
80  * This platform - being an odd 32-bit architecture - prefers to
81  * have 32-Bit variables.
82  */
83
84 struct firmware_context_struct {
85         /* timer / clocks */
86         unsigned int ticks_per_usec;
87         unsigned int counter;                   /* main() cycles */
88
89         /* misc */
90         unsigned int watchdog_enable;
91         unsigned int reboot;
92         unsigned int suspend_mode;
93
94         struct {
95                 /* Host Interface DMA queues */
96                 struct dma_queue up_queue;      /* used to send frames to the host */
97                 struct dma_queue down_queue;    /* stores incoming frames from the host */
98         } pta;
99
100         struct {
101                 /* Hardware DMA queues */
102                 struct dma_queue tx_queue[__AR9170_NUM_TX_QUEUES];      /* wlan tx queue */
103                 struct dma_queue tx_retry;
104                 struct dma_queue rx_queue;                              /* wlan rx queue */
105
106                 /* tx aggregate scheduling */
107                 struct carl9170_tx_superframe *ampdu_prev[__AR9170_NUM_TX_QUEUES];
108
109                 /* Hardware DMA queue unstuck/fix detection */
110                 unsigned int last_super_num[__AR9170_NUM_TX_QUEUES];
111                 struct carl9170_tx_superframe *last_super[__AR9170_NUM_TX_QUEUES];
112                 unsigned int mac_reset;
113                 unsigned int soft_int;
114
115                 /* rx filter */
116                 unsigned int rx_filter;
117
118                 /* tx sequence control counters */
119                 unsigned int sequence[CARL9170_INTF_NUM];
120
121 #ifdef CONFIG_CARL9170FW_CAB_QUEUE
122                 /* CAB */
123                 struct dma_queue cab_queue[CARL9170_INTF_NUM];
124                 unsigned int cab_queue_len[CARL9170_INTF_NUM];
125                 unsigned int cab_flush_time;
126                 enum carl9170_cab_trigger cab_flush_trigger[CARL9170_INTF_NUM];
127 #endif /* CONFIG_CARL9170FW_CAB_QUEUE */
128
129                 /* tx status */
130                 unsigned int tx_status_pending,
131                              tx_status_head_idx,
132                              tx_status_tail_idx;
133                 struct carl9170_tx_status tx_status_cache[CARL9170_TX_STATUS_NUM];
134
135                 /* internal descriptor for use within the service routines */
136                 struct dma_desc *fw_desc;
137                 unsigned int fw_desc_available;
138                 void *fw_desc_data;
139                 fw_desc_callback_t fw_desc_callback;
140
141                 /* BA(R) Request Handler */
142                 struct carl9170_bar_ctx ba_cache[CONFIG_CARL9170FW_BACK_REQS_NUM];
143                 unsigned int ba_tail_idx,
144                              ba_head_idx,
145                              queued_ba;
146         } wlan;
147
148         struct {
149                 unsigned int config,
150                              interface_setting,
151                              alternate_interface_setting,
152                              device_feature;
153                 enum carl9170_ep0_action ep0_action;
154
155                 void *ep0_txrx_buffer;
156                 unsigned int ep0_txrx_len,
157                              ep0_txrx_pos;
158
159                 struct ar9170_usb_config *cfg_desc;
160                 struct ar9170_usb_config *os_cfg_desc;
161
162                 /*
163                  * special buffers for command & response handling
164                  *
165                  * the firmware uses a sort of ring-buffer to communicate
166                  * to the host.
167                  */
168                 unsigned int int_pending,
169                              int_desc_available,
170                              int_head_index,
171                              int_tail_index;
172                 struct dma_desc *int_desc;
173                 struct carl9170_rsp int_buf[CARL9170_INT_RQ_CACHES];
174
175 #ifdef CONFIG_CARL9170FW_DEBUG_USB
176                 /* USB printf */
177                 unsigned int put_index;
178                 uint8_t put_buffer[CARL9170_MAX_CMD_PAYLOAD_LEN];
179 #endif /* CONFIG_CARL9170FW_DEBUG_USB */
180
181         } usb;
182
183         struct {
184 #ifdef CONFIG_CARL9170FW_RADIO_FUNCTIONS
185                 /* (cached) ar9170_rf_init */
186
187                 /* PHY/RF state */
188                 unsigned int frequency;
189                 unsigned int ht_settings;
190
191                 enum carl9170_phy_state state;
192                 struct carl9170_psm psm;
193 #endif /* CONFIG_CARL9170FW_RADIO_FUNCTIONS */
194         } phy;
195
196         unsigned int tally_clock;
197         struct carl9170_tally_rsp tally;
198         unsigned int tx_time;
199
200 #ifdef CONFIG_CARL9170FW_WOL
201         struct {
202                 struct carl9170_wol_cmd cmd;
203                 unsigned int last_beacon;
204                 unsigned int lost_null;
205                 unsigned int last_null;
206                 bool wake_up;
207         } wol;
208 #endif /* CONFIG_CARL9170FW_WOL */
209
210 #ifdef CONFIG_CARL9170FW_GPIO_INTERRUPT
211         struct carl9170_gpio cached_gpio_state;
212 #endif /*CONFIG_CARL9170FW_GPIO_INTERRUPT */
213 };
214
215 /*
216  * global firmware context struct.
217  *
218  * NOTE: This struct will zeroed out in start()
219  */
220 extern struct firmware_context_struct fw;
221 #endif /* __CARL9170FW_CARL9170_H */