xref: /openbmc/linux/drivers/net/wireless/ath/ath6kl/bmi.h (revision 3a9a231d)
1 /*
2  * Copyright (c) 2004-2011 Atheros Communications Inc.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef BMI_H
18 #define BMI_H
19 
20 /*
21  * Bootloader Messaging Interface (BMI)
22  *
23  * BMI is a very simple messaging interface used during initialization
24  * to read memory, write memory, execute code, and to define an
25  * application entry PC.
26  *
27  * It is used to download an application to ATH6KL, to provide
28  * patches to code that is already resident on ATH6KL, and generally
29  * to examine and modify state.  The Host has an opportunity to use
30  * BMI only once during bootup.  Once the Host issues a BMI_DONE
31  * command, this opportunity ends.
32  *
33  * The Host writes BMI requests to mailbox0, and reads BMI responses
34  * from mailbox0.   BMI requests all begin with a command
35  * (see below for specific commands), and are followed by
36  * command-specific data.
37  *
38  * Flow control:
39  * The Host can only issue a command once the Target gives it a
40  * "BMI Command Credit", using ATH6KL Counter #4.  As soon as the
41  * Target has completed a command, it issues another BMI Command
42  * Credit (so the Host can issue the next command).
43  *
44  * BMI handles all required Target-side cache flushing.
45  */
46 
47 #define MAX_BMI_CMDBUF_SZ (BMI_DATASZ_MAX + \
48 			   (sizeof(u32) * 3 /* cmd + addr + len */))
49 
50 /* Maximum data size used for BMI transfers */
51 #define BMI_DATASZ_MAX                      256
52 
53 /* BMI Commands */
54 
55 #define BMI_NO_COMMAND                      0
56 
57 #define BMI_DONE                            1
58 /*
59  * Semantics: Host is done using BMI
60  * Request format:
61  *    u32 command (BMI_DONE)
62  * Response format: none
63  */
64 
65 #define BMI_READ_MEMORY                     2
66 /*
67  * Semantics: Host reads ATH6KL memory
68  * Request format:
69  *    u32 command (BMI_READ_MEMORY)
70  *    u32 address
71  *    u32 length, at most BMI_DATASZ_MAX
72  * Response format:
73  *    u8 data[length]
74  */
75 
76 #define BMI_WRITE_MEMORY                    3
77 /*
78  * Semantics: Host writes ATH6KL memory
79  * Request format:
80  *    u32 command (BMI_WRITE_MEMORY)
81  *    u32 address
82  *    u32 length, at most BMI_DATASZ_MAX
83  *    u8 data[length]
84  * Response format: none
85  */
86 
87 #define BMI_EXECUTE                         4
88 /*
89  * Semantics: Causes ATH6KL to execute code
90  * Request format:
91  *    u32 command (BMI_EXECUTE)
92  *    u32 address
93  *    u32 parameter
94  * Response format:
95  *    u32 return value
96  */
97 
98 #define BMI_SET_APP_START                   5
99 /*
100  * Semantics: Set Target application starting address
101  * Request format:
102  *    u32 command (BMI_SET_APP_START)
103  *    u32 address
104  * Response format: none
105  */
106 
107 #define BMI_READ_SOC_REGISTER               6
108 /*
109  * Semantics: Read a 32-bit Target SOC register.
110  * Request format:
111  *    u32 command (BMI_READ_REGISTER)
112  *    u32 address
113  * Response format:
114  *    u32 value
115  */
116 
117 #define BMI_WRITE_SOC_REGISTER              7
118 /*
119  * Semantics: Write a 32-bit Target SOC register.
120  * Request format:
121  *    u32 command (BMI_WRITE_REGISTER)
122  *    u32 address
123  *    u32 value
124  *
125  * Response format: none
126  */
127 
128 #define BMI_GET_TARGET_ID                  8
129 #define BMI_GET_TARGET_INFO                8
130 /*
131  * Semantics: Fetch the 4-byte Target information
132  * Request format:
133  *    u32 command (BMI_GET_TARGET_ID/INFO)
134  * Response format1 (old firmware):
135  *    u32 TargetVersionID
136  * Response format2 (newer firmware):
137  *    u32 TARGET_VERSION_SENTINAL
138  *    struct bmi_target_info;
139  */
140 
141 #define TARGET_VERSION_SENTINAL 0xffffffff
142 #define TARGET_TYPE_AR6003      3
143 #define TARGET_TYPE_AR6004      5
144 #define BMI_ROMPATCH_INSTALL               9
145 /*
146  * Semantics: Install a ROM Patch.
147  * Request format:
148  *    u32 command (BMI_ROMPATCH_INSTALL)
149  *    u32 Target ROM Address
150  *    u32 Target RAM Address or Value (depending on Target Type)
151  *    u32 Size, in bytes
152  *    u32 Activate? 1-->activate;
153  *                            0-->install but do not activate
154  * Response format:
155  *    u32 PatchID
156  */
157 
158 #define BMI_ROMPATCH_UNINSTALL             10
159 /*
160  * Semantics: Uninstall a previously-installed ROM Patch,
161  * automatically deactivating, if necessary.
162  * Request format:
163  *    u32 command (BMI_ROMPATCH_UNINSTALL)
164  *    u32 PatchID
165  *
166  * Response format: none
167  */
168 
169 #define BMI_ROMPATCH_ACTIVATE              11
170 /*
171  * Semantics: Activate a list of previously-installed ROM Patches.
172  * Request format:
173  *    u32 command (BMI_ROMPATCH_ACTIVATE)
174  *    u32 rompatch_count
175  *    u32 PatchID[rompatch_count]
176  *
177  * Response format: none
178  */
179 
180 #define BMI_ROMPATCH_DEACTIVATE            12
181 /*
182  * Semantics: Deactivate a list of active ROM Patches.
183  * Request format:
184  *    u32 command (BMI_ROMPATCH_DEACTIVATE)
185  *    u32 rompatch_count
186  *    u32 PatchID[rompatch_count]
187  *
188  * Response format: none
189  */
190 
191 
192 #define BMI_LZ_STREAM_START                13
193 /*
194  * Semantics: Begin an LZ-compressed stream of input
195  * which is to be uncompressed by the Target to an
196  * output buffer at address.  The output buffer must
197  * be sufficiently large to hold the uncompressed
198  * output from the compressed input stream.  This BMI
199  * command should be followed by a series of 1 or more
200  * BMI_LZ_DATA commands.
201  *    u32 command (BMI_LZ_STREAM_START)
202  *    u32 address
203  * Note: Not supported on all versions of ROM firmware.
204  */
205 
206 #define BMI_LZ_DATA                        14
207 /*
208  * Semantics: Host writes ATH6KL memory with LZ-compressed
209  * data which is uncompressed by the Target.  This command
210  * must be preceded by a BMI_LZ_STREAM_START command. A series
211  * of BMI_LZ_DATA commands are considered part of a single
212  * input stream until another BMI_LZ_STREAM_START is issued.
213  * Request format:
214  *    u32 command (BMI_LZ_DATA)
215  *    u32 length (of compressed data),
216  *                  at most BMI_DATASZ_MAX
217  *    u8 CompressedData[length]
218  * Response format: none
219  * Note: Not supported on all versions of ROM firmware.
220  */
221 
222 #define BMI_COMMUNICATION_TIMEOUT       1000 /* in msec */
223 
224 struct ath6kl;
225 struct ath6kl_bmi_target_info {
226 	__le32 byte_count;   /* size of this structure */
227 	__le32 version;      /* target version id */
228 	__le32 type;         /* target type */
229 } __packed;
230 
231 int ath6kl_bmi_init(struct ath6kl *ar);
232 void ath6kl_bmi_cleanup(struct ath6kl *ar);
233 int ath6kl_bmi_done(struct ath6kl *ar);
234 int ath6kl_bmi_get_target_info(struct ath6kl *ar,
235 			       struct ath6kl_bmi_target_info *targ_info);
236 int ath6kl_bmi_read(struct ath6kl *ar, u32 addr, u8 *buf, u32 len);
237 int ath6kl_bmi_write(struct ath6kl *ar, u32 addr, u8 *buf, u32 len);
238 int ath6kl_bmi_execute(struct ath6kl *ar,
239 		       u32 addr, u32 *param);
240 int ath6kl_bmi_set_app_start(struct ath6kl *ar,
241 			     u32 addr);
242 int ath6kl_bmi_reg_read(struct ath6kl *ar, u32 addr, u32 *param);
243 int ath6kl_bmi_reg_write(struct ath6kl *ar, u32 addr, u32 param);
244 int ath6kl_bmi_lz_data(struct ath6kl *ar,
245 		       u8 *buf, u32 len);
246 int ath6kl_bmi_lz_stream_start(struct ath6kl *ar,
247 			       u32 addr);
248 int ath6kl_bmi_fast_download(struct ath6kl *ar,
249 			     u32 addr, u8 *buf, u32 len);
250 #endif
251