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 void ath10k_bmi_start(struct ath10k *ar)
25 ath10k_dbg(ar, ATH10K_DBG_BMI, "bmi start\n");
27 ar->bmi.done_sent = false;
30 int ath10k_bmi_done(struct ath10k *ar)
33 u32 cmdlen = sizeof(cmd.id) + sizeof(cmd.done);
36 ath10k_dbg(ar, ATH10K_DBG_BMI, "bmi done\n");
38 if (ar->bmi.done_sent) {
39 ath10k_dbg(ar, ATH10K_DBG_BMI, "bmi skipped\n");
43 ar->bmi.done_sent = true;
44 cmd.id = __cpu_to_le32(BMI_DONE);
46 ret = ath10k_hif_exchange_bmi_msg(ar, &cmd, cmdlen, NULL, NULL);
48 ath10k_warn(ar, "unable to write to the device: %d\n", ret);
55 int ath10k_bmi_get_target_info(struct ath10k *ar,
56 struct bmi_target_info *target_info)
60 u32 cmdlen = sizeof(cmd.id) + sizeof(cmd.get_target_info);
61 u32 resplen = sizeof(resp.get_target_info);
64 ath10k_dbg(ar, ATH10K_DBG_BMI, "bmi get target info\n");
66 if (ar->bmi.done_sent) {
67 ath10k_warn(ar, "BMI Get Target Info Command disallowed\n");
71 cmd.id = __cpu_to_le32(BMI_GET_TARGET_INFO);
73 ret = ath10k_hif_exchange_bmi_msg(ar, &cmd, cmdlen, &resp, &resplen);
75 ath10k_warn(ar, "unable to get target info from device\n");
79 if (resplen < sizeof(resp.get_target_info)) {
80 ath10k_warn(ar, "invalid get_target_info response length (%d)\n",
85 target_info->version = __le32_to_cpu(resp.get_target_info.version);
86 target_info->type = __le32_to_cpu(resp.get_target_info.type);
91 int ath10k_bmi_read_memory(struct ath10k *ar,
92 u32 address, void *buffer, u32 length)
96 u32 cmdlen = sizeof(cmd.id) + sizeof(cmd.read_mem);
100 ath10k_dbg(ar, ATH10K_DBG_BMI, "bmi read address 0x%x length %d\n",
103 if (ar->bmi.done_sent) {
104 ath10k_warn(ar, "command disallowed\n");
109 rxlen = min_t(u32, length, BMI_MAX_DATA_SIZE);
111 cmd.id = __cpu_to_le32(BMI_READ_MEMORY);
112 cmd.read_mem.addr = __cpu_to_le32(address);
113 cmd.read_mem.len = __cpu_to_le32(rxlen);
115 ret = ath10k_hif_exchange_bmi_msg(ar, &cmd, cmdlen,
118 ath10k_warn(ar, "unable to read from the device (%d)\n",
123 memcpy(buffer, resp.read_mem.payload, rxlen);
132 int ath10k_bmi_write_memory(struct ath10k *ar,
133 u32 address, const void *buffer, u32 length)
136 u32 hdrlen = sizeof(cmd.id) + sizeof(cmd.write_mem);
140 ath10k_dbg(ar, ATH10K_DBG_BMI, "bmi write address 0x%x length %d\n",
143 if (ar->bmi.done_sent) {
144 ath10k_warn(ar, "command disallowed\n");
149 txlen = min(length, BMI_MAX_DATA_SIZE - hdrlen);
151 /* copy before roundup to avoid reading beyond buffer*/
152 memcpy(cmd.write_mem.payload, buffer, txlen);
153 txlen = roundup(txlen, 4);
155 cmd.id = __cpu_to_le32(BMI_WRITE_MEMORY);
156 cmd.write_mem.addr = __cpu_to_le32(address);
157 cmd.write_mem.len = __cpu_to_le32(txlen);
159 ret = ath10k_hif_exchange_bmi_msg(ar, &cmd, hdrlen + txlen,
162 ath10k_warn(ar, "unable to write to the device (%d)\n",
167 /* fixup roundup() so `length` zeroes out for last chunk */
168 txlen = min(txlen, length);
178 int ath10k_bmi_execute(struct ath10k *ar, u32 address, u32 param, u32 *result)
182 u32 cmdlen = sizeof(cmd.id) + sizeof(cmd.execute);
183 u32 resplen = sizeof(resp.execute);
186 ath10k_dbg(ar, ATH10K_DBG_BMI, "bmi execute address 0x%x param 0x%x\n",
189 if (ar->bmi.done_sent) {
190 ath10k_warn(ar, "command disallowed\n");
194 cmd.id = __cpu_to_le32(BMI_EXECUTE);
195 cmd.execute.addr = __cpu_to_le32(address);
196 cmd.execute.param = __cpu_to_le32(param);
198 ret = ath10k_hif_exchange_bmi_msg(ar, &cmd, cmdlen, &resp, &resplen);
200 ath10k_warn(ar, "unable to read from the device\n");
204 if (resplen < sizeof(resp.execute)) {
205 ath10k_warn(ar, "invalid execute response length (%d)\n",
210 *result = __le32_to_cpu(resp.execute.result);
212 ath10k_dbg(ar, ATH10K_DBG_BMI, "bmi execute result 0x%x\n", *result);
217 int ath10k_bmi_lz_data(struct ath10k *ar, const void *buffer, u32 length)
220 u32 hdrlen = sizeof(cmd.id) + sizeof(cmd.lz_data);
224 ath10k_dbg(ar, ATH10K_DBG_BMI, "bmi lz data buffer 0x%p length %d\n",
227 if (ar->bmi.done_sent) {
228 ath10k_warn(ar, "command disallowed\n");
233 txlen = min(length, BMI_MAX_DATA_SIZE - hdrlen);
235 WARN_ON_ONCE(txlen & 3);
237 cmd.id = __cpu_to_le32(BMI_LZ_DATA);
238 cmd.lz_data.len = __cpu_to_le32(txlen);
239 memcpy(cmd.lz_data.payload, buffer, txlen);
241 ret = ath10k_hif_exchange_bmi_msg(ar, &cmd, hdrlen + txlen,
244 ath10k_warn(ar, "unable to write to the device\n");
255 int ath10k_bmi_lz_stream_start(struct ath10k *ar, u32 address)
258 u32 cmdlen = sizeof(cmd.id) + sizeof(cmd.lz_start);
261 ath10k_dbg(ar, ATH10K_DBG_BMI, "bmi lz stream start address 0x%x\n",
264 if (ar->bmi.done_sent) {
265 ath10k_warn(ar, "command disallowed\n");
269 cmd.id = __cpu_to_le32(BMI_LZ_STREAM_START);
270 cmd.lz_start.addr = __cpu_to_le32(address);
272 ret = ath10k_hif_exchange_bmi_msg(ar, &cmd, cmdlen, NULL, NULL);
274 ath10k_warn(ar, "unable to Start LZ Stream to the device\n");
281 int ath10k_bmi_fast_download(struct ath10k *ar,
282 u32 address, const void *buffer, u32 length)
285 u32 head_len = rounddown(length, 4);
286 u32 trailer_len = length - head_len;
289 ath10k_dbg(ar, ATH10K_DBG_BMI,
290 "bmi fast download address 0x%x buffer 0x%p length %d\n",
291 address, buffer, length);
293 ret = ath10k_bmi_lz_stream_start(ar, address);
297 /* copy the last word into a zero padded buffer */
299 memcpy(trailer, buffer + head_len, trailer_len);
301 ret = ath10k_bmi_lz_data(ar, buffer, head_len);
306 ret = ath10k_bmi_lz_data(ar, trailer, 4);
312 * Close compressed stream and open a new (fake) one.
313 * This serves mainly to flush Target caches.
315 ret = ath10k_bmi_lz_stream_start(ar, 0x00);