carl9170 toolchain: update binutils, gcc
[carl9170fw.git] / 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 /*
73  * This platform - being an odd 32-bit architecture - prefers to
74  * have 32-Bit variables.
75  */
76
77 struct firmware_context_struct {
78         /* timer / clocks */
79         unsigned int ticks_per_msec;
80         unsigned int counter;                   /* main() cycles */
81
82         /* misc */
83         unsigned int watchdog_enable;
84         unsigned int reboot;
85         unsigned int suspend_mode;
86
87         struct {
88                 /* Host Interface DMA queues */
89                 struct dma_queue up_queue;      /* used to send frames to the host */
90                 struct dma_queue down_queue;    /* stores incoming frames from the host */
91         } pta;
92
93         struct {
94                 /* Hardware DMA queues */
95                 struct dma_queue tx_queue[__AR9170_NUM_TX_QUEUES];      /* wlan tx queue */
96                 struct dma_queue tx_retry;
97                 struct dma_queue rx_queue;                              /* wlan rx queue */
98
99                 /* tx aggregate scheduling */
100                 struct carl9170_tx_superframe *ampdu_prev[__AR9170_NUM_TX_QUEUES];
101
102                 /* Hardware DMA queue unstuck/fix detection */
103                 unsigned int last_tx_desc_num[__AR9170_NUM_TX_QUEUES];
104                 struct dma_desc *last_tx_desc[__AR9170_NUM_TX_QUEUES];
105                 unsigned int mac_reset;
106                 unsigned int soft_int;
107
108                 /* rx filter */
109                 unsigned int rx_filter;
110
111                 /* rx statistics */
112                 unsigned int rx_total;
113                 unsigned int rx_overruns;
114
115                 /* tx sequence control counters */
116                 unsigned int sequence[CARL9170_INTF_NUM];
117
118 #ifdef CONFIG_CARL9170FW_CAB_QUEUE
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 #endif /* CONFIG_CARL9170FW_CAB_QUEUE */
125
126                 /* tx status */
127                 unsigned int tx_status_pending,
128                              tx_status_head_idx,
129                              tx_status_tail_idx;
130                 struct carl9170_tx_status tx_status_cache[CARL9170_TX_STATUS_NUM];
131
132 #ifdef CONFIG_CARL9170FW_HANDLE_BACK_REQ
133                 /* BA(R) Request Handler */
134                 struct dma_desc *ba_desc;
135                 struct carl9170_bar_ctx ba_cache[CONFIG_CARL9170FW_BACK_REQS_NUM];
136                 unsigned int ba_desc_available,
137                              ba_tail_idx,
138                              ba_head_idx;
139 #endif /* CONFIG_CARL9170FW_HANDLE_BACK_REQ */
140         } wlan;
141
142         struct {
143                 unsigned int config,
144                              interface_setting,
145                              alternate_interface_setting,
146                              device_feature;
147                 enum carl9170_ep0_action ep0_action;
148
149                 void *ep0_txrx_buffer;
150                 unsigned int ep0_txrx_len,
151                              ep0_txrx_pos;
152
153                 struct ar9170_usb_config *cfg_desc;
154                 struct ar9170_usb_config *os_cfg_desc;
155
156                 /*
157                  * special buffers for command & response handling
158                  *
159                  * the firmware uses a sort of ring-buffer to communicate
160                  * to the host.
161                  */
162                 unsigned int int_pending,
163                              int_desc_available,
164                              int_head_index,
165                              int_tail_index;
166                 struct dma_desc *int_desc;
167                 struct carl9170_rsp int_buf[CARL9170_INT_RQ_CACHES];
168
169 #ifdef CONFIG_CARL9170FW_DEBUG_USB
170                 /* USB printf */
171                 unsigned int put_index;
172                 uint8_t put_buffer[CARL9170_MAX_CMD_PAYLOAD_LEN];
173 #endif /* CONFIG_CARL9170FW_DEBUG_USB */
174
175         } usb;
176
177         struct {
178 #ifdef CONFIG_CARL9170FW_RADIO_FUNCTIONS
179                 /* (cached) ar9170_rf_init */
180
181                 /* PHY/RF state */
182                 unsigned int frequency;
183                 unsigned int ht_settings;
184
185                 struct carl9170_psm psm;
186 #endif /* CONFIG_CARL9170FW_RADIO_FUNCTIONS */
187         } phy;
188
189 #ifdef CONFIG_CARL9170FW_GPIO_INTERRUPT
190         struct carl9170_gpio cached_gpio_state;
191 #endif /*CONFIG_CARL9170FW_GPIO_INTERRUPT */
192 };
193
194 /*
195  * global firmware context struct.
196  *
197  * NOTE: This struct will zeroed out in start()
198  */
199 extern struct firmware_context_struct fw;
200 #endif /* __CARL9170FW_CARL9170_H */