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