49fdb2f71a731ec25c0561e6ffe333b4b4be9898
[carl9170fw.git] / include / shared / fwcmd.h
1 /*
2  * Atheros AR9170 driver
3  *
4  * firmware command interface definitions
5  *
6  * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7  * Copyright 2009, 2010, Christian Lamparter <chunkeey@googlemail.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License.
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
19  * along with this program; see the file COPYING.  If not, see
20  * http://www.gnu.org/licenses/.
21  *
22  * This file incorporates work covered by the following copyright and
23  * permission notice:
24  *    Copyright (c) 2007-2008 Atheros Communications, Inc.
25  *
26  *    Permission to use, copy, modify, and/or distribute this software for any
27  *    purpose with or without fee is hereby granted, provided that the above
28  *    copyright notice and this permission notice appear in all copies.
29  *
30  *    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
31  *    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
32  *    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
33  *    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
34  *    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
35  *    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
36  *    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
37  */
38
39 #ifndef __CARL9170_SHARED_FWCMD_H
40 #define __CARL9170_SHARED_FWCMD_H
41
42 #define CARL9170_MAX_CMD_LEN            64
43 #define CARL9170_MAX_CMD_PAYLOAD_LEN    60
44
45 #define CARL9170FW_API_MIN_VER          1
46 #define CARL9170FW_API_MAX_VER          1
47
48 enum carl9170_cmd_oids {
49         CARL9170_CMD_RREG               = 0x00,
50         CARL9170_CMD_WREG               = 0x01,
51         CARL9170_CMD_ECHO               = 0x02,
52         CARL9170_CMD_SWRST              = 0x03,
53         CARL9170_CMD_REBOOT             = 0x04,
54         CARL9170_CMD_FLUSH_CAB          = 0x05,
55         CARL9170_CMD_READ_TSF           = 0x06,
56         CARL9170_CMD_USB_WD             = 0x07,
57
58         /* CAM */
59         CARL9170_CMD_EKEY               = 0x10,
60         CARL9170_CMD_DKEY               = 0x11,
61
62         /* RF / PHY */
63         CARL9170_CMD_FREQUENCY          = 0x20,
64         CARL9170_CMD_RF_INIT            = 0x21,
65         CARL9170_CMD_SYNTH              = 0x22,
66         CARL9170_CMD_FREQ_START         = 0x23,
67         CARL9170_CMD_PSM                = 0x24,
68
69         /* responses and traps */
70         CARL9170_RSP_PRETBTT            = 0xc0,
71         CARL9170_RSP_TXCOMP             = 0xc1,
72         CARL9170_RSP_BEACON_CONFIG      = 0xc2,
73         CARL9170_RSP_ATIM               = 0xc3,
74         CARL9170_RSP_WATCHDOG           = 0xc6,
75         CARL9170_RSP_TEXT               = 0xca,
76         CARL9170_RSP_HEXDUMP            = 0xcc,
77         CARL9170_RSP_RADAR              = 0xcd,
78         CARL9170_RSP_GPIO               = 0xce,
79         CARL9170_RSP_USB_WD             = 0xcf
80 };
81
82 struct carl9170_set_key_cmd {
83         __le16          user;
84         __le16          keyId;
85         __le16          type;
86         u8              macAddr[6];
87         u32             key[4];
88 } __packed;
89 #define CARL9170_SET_KEY_CMD_SIZE               28
90
91 struct carl9170_disable_key_cmd {
92         __le16          user;
93         __le16          padding;
94 } __packed;
95 #define CARL9170_DISABLE_KEY_CMD_SIZE           4
96
97 struct carl9170_u32_list {
98         u32     vals[0];
99 } __packed;
100
101 struct carl9170_reg_list {
102         __le32          regs[0];
103 } __packed;
104
105 struct carl9170_write_reg {
106         struct {
107                 __le32          addr;
108                 __le32          val;
109         } regs[0] __packed;
110 } __packed;
111
112 #define CARL9170FW_PHY_HT_ENABLE                0x4
113 #define CARL9170FW_PHY_HT_DYN2040               0x8
114 #define CARL9170FW_PHY_HT_EXT_CHAN_OFF          0x3
115 #define CARL9170FW_PHY_HT_EXT_CHAN_OFF_S        2
116
117 struct carl9170_rf_init {
118         __le32          freq;
119         u8              ht_settings;
120         u8              padding2[3];
121         __le32          delta_slope_coeff_exp;
122         __le32          delta_slope_coeff_man;
123         __le32          delta_slope_coeff_exp_shgi;
124         __le32          delta_slope_coeff_man_shgi;
125         __le32          finiteLoopCount;
126 } __packed;
127 #define CARL9170_RF_INIT_SIZE           28
128
129 struct carl9170_rf_init_result {
130         __le32          ret;            /* AR9170_PHY_REG_AGC_CONTROL */
131         __le32          regs[6];
132 } __packed;
133 #define CARL9170_RF_INIT_RESULT_SIZE    28
134
135 #define CARL9170_USB_WATCHDOG_INACTIVE  0
136 #define CARL9170_USB_WATCHDOG_ON_DUTY   1
137
138 struct carl9170_watchdog_cmd {
139         __le32          state;
140 } __packed;
141 #define CARL9170_WATCHDOG_CMD_SIZE      4
142
143 #define CARL9170_PSM_SLEEP              0x1000
144 #define CARL9170_PSM_SOFTWARE           0
145 #define CARL9170_PSM_WAKE               0 /* internally used. */
146 #define CARL9170_PSM_COUNTER            0xfff
147 #define CARL9170_PSM_COUNTER_S          0
148
149 struct carl9170_psm {
150         __le32          state;
151 } __packed;
152 #define CARL9170_PSM_SIZE               4
153
154 struct carl9170_cab_flush_cmd {
155         __le32          vif_id;         /* currently unused */
156 } __packed;
157 #define CARL9170_CAB_FLUSH_CMD_SIZE     4
158
159 struct carl9170_cmd_head {
160         union {
161                 struct {
162                         u8      len;
163                         u8      cmd;
164                         u8      seq;
165                         u8      ext;
166                 } __packed;
167
168                 u32 hdr_data;
169         } __packed;
170 } __packed;
171
172 struct carl9170_cmd {
173         struct carl9170_cmd_head hdr;
174         union {
175                 struct carl9170_set_key_cmd     setkey;
176                 struct carl9170_disable_key_cmd disablekey;
177                 struct carl9170_u32_list        echo;
178                 struct carl9170_watchdog_cmd    watchdog;
179                 struct carl9170_reg_list        rreg;
180                 struct carl9170_write_reg       wreg;
181                 struct carl9170_rf_init         rf_init;
182                 struct carl9170_psm             psm;
183                 struct carl9170_cab_flush_cmd   cab_flush;
184                 u8 data[CARL9170_MAX_CMD_PAYLOAD_LEN];
185         } __packed;
186 } __packed;
187
188 #define CARL9170_TX_STATUS_QUEUE_MASK   3
189 #define CARL9170_TX_STATUS_RIX_SHIFT    2
190 #define CARL9170_TX_STATUS_RIX_MASK     (3 << CARL9170_TX_STATUS_RIX_SHIFT)
191 #define CARL9170_TX_STATUS_TRIES_SHIFT  4
192 #define CARL9170_TX_STATUS_TRIES_MASK   (7 << CARL9170_TX_STATUS_TRIES_SHIFT)
193 #define CARL9170_TX_STATUS_SUCCESS      0x80
194
195 /*
196  * NOTE:
197  * Both structs [carl9170_tx_status and _carl9170_tx_status]
198  * need to be "bit for bit" in sync.
199  */
200 struct carl9170_tx_status {
201         /*
202          * Beware of compiler bugs in all gcc pre 4.4!
203          */
204
205         u8 cookie;
206         u8 queue:2;
207         u8 rix:2;
208         u8 tries:3;
209         u8 success:1;
210 } __packed;
211 struct _carl9170_tx_status {
212         /*
213          * This version should be immune to all alignment bugs.
214          */
215
216         u8 cookie;
217         u8 info;
218 } __packed;
219 #define CARL9170_TX_STATUS_SIZE         2
220
221 #define CARL9170_RSP_TX_STATUS_NUM      (CARL9170_MAX_CMD_PAYLOAD_LEN / \
222                                          sizeof(struct _carl9170_tx_status))
223
224 #define CARL9170_TX_MAX_RATE_TRIES      7
225
226 #define CARL9170_TX_MAX_RATES           4
227 #define CARL9170_TX_MAX_RETRY_RATES     (CARL9170_TX_MAX_RATES - 1)
228 #define CARL9170_ERR_MAGIC              "ERR:"
229 #define CARL9170_BUG_MAGIC              "BUG:"
230
231 struct carl9170_gpio {
232         __le32 gpio;
233 } __packed;
234 #define CARL9170_GPIO_SIZE              4
235
236 struct carl9170_tsf_rsp {
237         union {
238                 __le32 tsf[2];
239                 __le64 tsf_64;
240         } __packed;
241 } __packed;
242 #define CARL9170_TSF_RSP_SIZE           8
243
244 struct carl9170_rsp {
245         struct carl9170_cmd_head hdr;
246
247         union {
248                 struct carl9170_rf_init_result  rf_init_res;
249                 struct carl9170_u32_list        rreg_res;
250                 struct carl9170_u32_list        echo;
251                 struct carl9170_watchdog_cmd    watchdog;
252                 struct carl9170_tx_status       tx_status[0];
253                 struct _carl9170_tx_status      _tx_status[0];
254                 struct carl9170_gpio            gpio;
255                 struct carl9170_tsf_rsp         tsf;
256                 struct carl9170_psm             psm;
257                 u8 data[CARL9170_MAX_CMD_PAYLOAD_LEN];
258         } __packed;
259 } __packed;
260
261 #endif /* __CARL9170_SHARED_FWCMD_H */