2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 int ath10k_bmi_done(struct ath10k
*ar
)
26 u32 cmdlen
= sizeof(cmd
.id
) + sizeof(cmd
.done
);
29 if (ar
->bmi
.done_sent
) {
30 ath10k_dbg(ATH10K_DBG_CORE
, "%s skipped\n", __func__
);
34 ar
->bmi
.done_sent
= true;
35 cmd
.id
= __cpu_to_le32(BMI_DONE
);
37 ret
= ath10k_hif_exchange_bmi_msg(ar
, &cmd
, cmdlen
, NULL
, NULL
);
39 ath10k_warn("unable to write to the device: %d\n", ret
);
43 ath10k_dbg(ATH10K_DBG_CORE
, "BMI done\n");
47 int ath10k_bmi_get_target_info(struct ath10k
*ar
,
48 struct bmi_target_info
*target_info
)
52 u32 cmdlen
= sizeof(cmd
.id
) + sizeof(cmd
.get_target_info
);
53 u32 resplen
= sizeof(resp
.get_target_info
);
56 if (ar
->bmi
.done_sent
) {
57 ath10k_warn("BMI Get Target Info Command disallowed\n");
61 cmd
.id
= __cpu_to_le32(BMI_GET_TARGET_INFO
);
63 ret
= ath10k_hif_exchange_bmi_msg(ar
, &cmd
, cmdlen
, &resp
, &resplen
);
65 ath10k_warn("unable to get target info from device\n");
69 if (resplen
< sizeof(resp
.get_target_info
)) {
70 ath10k_warn("invalid get_target_info response length (%d)\n",
75 target_info
->version
= __le32_to_cpu(resp
.get_target_info
.version
);
76 target_info
->type
= __le32_to_cpu(resp
.get_target_info
.type
);
80 int ath10k_bmi_read_memory(struct ath10k
*ar
,
81 u32 address
, void *buffer
, u32 length
)
85 u32 cmdlen
= sizeof(cmd
.id
) + sizeof(cmd
.read_mem
);
89 if (ar
->bmi
.done_sent
) {
90 ath10k_warn("command disallowed\n");
94 ath10k_dbg(ATH10K_DBG_CORE
,
95 "%s: (device: 0x%p, address: 0x%x, length: %d)\n",
96 __func__
, ar
, address
, length
);
99 rxlen
= min_t(u32
, length
, BMI_MAX_DATA_SIZE
);
101 cmd
.id
= __cpu_to_le32(BMI_READ_MEMORY
);
102 cmd
.read_mem
.addr
= __cpu_to_le32(address
);
103 cmd
.read_mem
.len
= __cpu_to_le32(rxlen
);
105 ret
= ath10k_hif_exchange_bmi_msg(ar
, &cmd
, cmdlen
,
108 ath10k_warn("unable to read from the device\n");
112 memcpy(buffer
, resp
.read_mem
.payload
, rxlen
);
121 int ath10k_bmi_write_memory(struct ath10k
*ar
,
122 u32 address
, const void *buffer
, u32 length
)
125 u32 hdrlen
= sizeof(cmd
.id
) + sizeof(cmd
.write_mem
);
129 if (ar
->bmi
.done_sent
) {
130 ath10k_warn("command disallowed\n");
134 ath10k_dbg(ATH10K_DBG_CORE
,
135 "%s: (device: 0x%p, address: 0x%x, length: %d)\n",
136 __func__
, ar
, address
, length
);
139 txlen
= min(length
, BMI_MAX_DATA_SIZE
- hdrlen
);
141 /* copy before roundup to avoid reading beyond buffer*/
142 memcpy(cmd
.write_mem
.payload
, buffer
, txlen
);
143 txlen
= roundup(txlen
, 4);
145 cmd
.id
= __cpu_to_le32(BMI_WRITE_MEMORY
);
146 cmd
.write_mem
.addr
= __cpu_to_le32(address
);
147 cmd
.write_mem
.len
= __cpu_to_le32(txlen
);
149 ret
= ath10k_hif_exchange_bmi_msg(ar
, &cmd
, hdrlen
+ txlen
,
152 ath10k_warn("unable to write to the device\n");
156 /* fixup roundup() so `length` zeroes out for last chunk */
157 txlen
= min(txlen
, length
);
167 int ath10k_bmi_execute(struct ath10k
*ar
, u32 address
, u32
*param
)
171 u32 cmdlen
= sizeof(cmd
.id
) + sizeof(cmd
.execute
);
172 u32 resplen
= sizeof(resp
.execute
);
175 if (ar
->bmi
.done_sent
) {
176 ath10k_warn("command disallowed\n");
180 ath10k_dbg(ATH10K_DBG_CORE
,
181 "%s: (device: 0x%p, address: 0x%x, param: %d)\n",
182 __func__
, ar
, address
, *param
);
184 cmd
.id
= __cpu_to_le32(BMI_EXECUTE
);
185 cmd
.execute
.addr
= __cpu_to_le32(address
);
186 cmd
.execute
.param
= __cpu_to_le32(*param
);
188 ret
= ath10k_hif_exchange_bmi_msg(ar
, &cmd
, cmdlen
, &resp
, &resplen
);
190 ath10k_warn("unable to read from the device\n");
194 if (resplen
< sizeof(resp
.execute
)) {
195 ath10k_warn("invalid execute response length (%d)\n",
200 *param
= __le32_to_cpu(resp
.execute
.result
);
204 int ath10k_bmi_lz_data(struct ath10k
*ar
, const void *buffer
, u32 length
)
207 u32 hdrlen
= sizeof(cmd
.id
) + sizeof(cmd
.lz_data
);
211 if (ar
->bmi
.done_sent
) {
212 ath10k_warn("command disallowed\n");
217 txlen
= min(length
, BMI_MAX_DATA_SIZE
- hdrlen
);
219 WARN_ON_ONCE(txlen
& 3);
221 cmd
.id
= __cpu_to_le32(BMI_LZ_DATA
);
222 cmd
.lz_data
.len
= __cpu_to_le32(txlen
);
223 memcpy(cmd
.lz_data
.payload
, buffer
, txlen
);
225 ret
= ath10k_hif_exchange_bmi_msg(ar
, &cmd
, hdrlen
+ txlen
,
228 ath10k_warn("unable to write to the device\n");
239 int ath10k_bmi_lz_stream_start(struct ath10k
*ar
, u32 address
)
242 u32 cmdlen
= sizeof(cmd
.id
) + sizeof(cmd
.lz_start
);
245 if (ar
->bmi
.done_sent
) {
246 ath10k_warn("command disallowed\n");
250 cmd
.id
= __cpu_to_le32(BMI_LZ_STREAM_START
);
251 cmd
.lz_start
.addr
= __cpu_to_le32(address
);
253 ret
= ath10k_hif_exchange_bmi_msg(ar
, &cmd
, cmdlen
, NULL
, NULL
);
255 ath10k_warn("unable to Start LZ Stream to the device\n");
262 int ath10k_bmi_fast_download(struct ath10k
*ar
,
263 u32 address
, const void *buffer
, u32 length
)
266 u32 head_len
= rounddown(length
, 4);
267 u32 trailer_len
= length
- head_len
;
270 ret
= ath10k_bmi_lz_stream_start(ar
, address
);
274 /* copy the last word into a zero padded buffer */
276 memcpy(trailer
, buffer
+ head_len
, trailer_len
);
278 ret
= ath10k_bmi_lz_data(ar
, buffer
, head_len
);
283 ret
= ath10k_bmi_lz_data(ar
, trailer
, 4);
289 * Close compressed stream and open a new (fake) one.
290 * This serves mainly to flush Target caches.
292 ret
= ath10k_bmi_lz_stream_start(ar
, 0x00);