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