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 (%d)\n",
113 memcpy(buffer, resp.read_mem.payload, rxlen);
122 int ath10k_bmi_write_memory(struct ath10k *ar,
123 u32 address, const void *buffer, u32 length)
126 u32 hdrlen = sizeof(cmd.id) + sizeof(cmd.write_mem);
130 if (ar->bmi.done_sent) {
131 ath10k_warn("command disallowed\n");
135 ath10k_dbg(ATH10K_DBG_CORE,
136 "%s: (device: 0x%p, address: 0x%x, length: %d)\n",
137 __func__, ar, address, length);
140 txlen = min(length, BMI_MAX_DATA_SIZE - hdrlen);
142 /* copy before roundup to avoid reading beyond buffer*/
143 memcpy(cmd.write_mem.payload, buffer, txlen);
144 txlen = roundup(txlen, 4);
146 cmd.id = __cpu_to_le32(BMI_WRITE_MEMORY);
147 cmd.write_mem.addr = __cpu_to_le32(address);
148 cmd.write_mem.len = __cpu_to_le32(txlen);
150 ret = ath10k_hif_exchange_bmi_msg(ar, &cmd, hdrlen + txlen,
153 ath10k_warn("unable to write to the device (%d)\n",
158 /* fixup roundup() so `length` zeroes out for last chunk */
159 txlen = min(txlen, length);
169 int ath10k_bmi_execute(struct ath10k *ar, u32 address, u32 *param)
173 u32 cmdlen = sizeof(cmd.id) + sizeof(cmd.execute);
174 u32 resplen = sizeof(resp.execute);
177 if (ar->bmi.done_sent) {
178 ath10k_warn("command disallowed\n");
182 ath10k_dbg(ATH10K_DBG_CORE,
183 "%s: (device: 0x%p, address: 0x%x, param: %d)\n",
184 __func__, ar, address, *param);
186 cmd.id = __cpu_to_le32(BMI_EXECUTE);
187 cmd.execute.addr = __cpu_to_le32(address);
188 cmd.execute.param = __cpu_to_le32(*param);
190 ret = ath10k_hif_exchange_bmi_msg(ar, &cmd, cmdlen, &resp, &resplen);
192 ath10k_warn("unable to read from the device\n");
196 if (resplen < sizeof(resp.execute)) {
197 ath10k_warn("invalid execute response length (%d)\n",
202 *param = __le32_to_cpu(resp.execute.result);
206 int ath10k_bmi_lz_data(struct ath10k *ar, const void *buffer, u32 length)
209 u32 hdrlen = sizeof(cmd.id) + sizeof(cmd.lz_data);
213 if (ar->bmi.done_sent) {
214 ath10k_warn("command disallowed\n");
219 txlen = min(length, BMI_MAX_DATA_SIZE - hdrlen);
221 WARN_ON_ONCE(txlen & 3);
223 cmd.id = __cpu_to_le32(BMI_LZ_DATA);
224 cmd.lz_data.len = __cpu_to_le32(txlen);
225 memcpy(cmd.lz_data.payload, buffer, txlen);
227 ret = ath10k_hif_exchange_bmi_msg(ar, &cmd, hdrlen + txlen,
230 ath10k_warn("unable to write to the device\n");
241 int ath10k_bmi_lz_stream_start(struct ath10k *ar, u32 address)
244 u32 cmdlen = sizeof(cmd.id) + sizeof(cmd.lz_start);
247 if (ar->bmi.done_sent) {
248 ath10k_warn("command disallowed\n");
252 cmd.id = __cpu_to_le32(BMI_LZ_STREAM_START);
253 cmd.lz_start.addr = __cpu_to_le32(address);
255 ret = ath10k_hif_exchange_bmi_msg(ar, &cmd, cmdlen, NULL, NULL);
257 ath10k_warn("unable to Start LZ Stream to the device\n");
264 int ath10k_bmi_fast_download(struct ath10k *ar,
265 u32 address, const void *buffer, u32 length)
268 u32 head_len = rounddown(length, 4);
269 u32 trailer_len = length - head_len;
272 ret = ath10k_bmi_lz_stream_start(ar, address);
276 /* copy the last word into a zero padded buffer */
278 memcpy(trailer, buffer + head_len, trailer_len);
280 ret = ath10k_bmi_lz_data(ar, buffer, head_len);
285 ret = ath10k_bmi_lz_data(ar, trailer, 4);
291 * Close compressed stream and open a new (fake) one.
292 * This serves mainly to flush Target caches.
294 ret = ath10k_bmi_lz_stream_start(ar, 0x00);