OLD | NEW |
1 //------------------------------------------------------------------------------ | 1 //------------------------------------------------------------------------------ |
2 // <copyright file="bmi.c" company="Atheros"> | 2 // <copyright file="bmi.c" company="Atheros"> |
3 // Copyright (c) 2004-2008 Atheros Corporation. All rights reserved. | 3 // Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. |
4 // | 4 // |
5 // This program is free software; you can redistribute it and/or modify | |
6 // it under the terms of the GNU General Public License version 2 as | |
7 // published by the Free Software Foundation; | |
8 // | 5 // |
9 // Software distributed under the License is distributed on an "AS | 6 // Permission to use, copy, modify, and/or distribute this software for any |
10 // IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | 7 // purpose with or without fee is hereby granted, provided that the above |
11 // implied. See the License for the specific language governing | 8 // copyright notice and this permission notice appear in all copies. |
12 // rights and limitations under the License. | 9 // |
| 10 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 13 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 16 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
13 // | 17 // |
14 // | 18 // |
15 //------------------------------------------------------------------------------ | 19 //------------------------------------------------------------------------------ |
16 //============================================================================== | 20 //============================================================================== |
17 // | 21 // |
18 // Author(s): ="Atheros" | 22 // Author(s): ="Atheros" |
19 //============================================================================== | 23 //============================================================================== |
20 | 24 |
21 | 25 |
| 26 #ifdef THREAD_X |
| 27 #include <string.h> |
| 28 #endif |
| 29 |
22 #include "hif.h" | 30 #include "hif.h" |
23 #include "bmi.h" | 31 #include "bmi.h" |
24 #include "htc_api.h" | 32 #include "htc_api.h" |
25 #include "bmi_internal.h" | 33 #include "bmi_internal.h" |
26 | 34 |
27 #ifdef DEBUG | 35 #ifdef ATH_DEBUG_MODULE |
28 static ATH_DEBUG_MASK_DESCRIPTION bmi_debug_desc[] = { | 36 static ATH_DEBUG_MASK_DESCRIPTION bmi_debug_desc[] = { |
29 { ATH_DEBUG_BMI , "BMI Tracing"}, | 37 { ATH_DEBUG_BMI , "BMI Tracing"}, |
30 }; | 38 }; |
31 | 39 |
32 ATH_DEBUG_INSTANTIATE_MODULE_VAR(bmi, | 40 ATH_DEBUG_INSTANTIATE_MODULE_VAR(bmi, |
33 "bmi", | 41 "bmi", |
34 "Boot Manager Interface", | 42 "Boot Manager Interface", |
35 ATH_DEBUG_MASK_DEFAULTS, | 43 ATH_DEBUG_MASK_DEFAULTS, |
36 ATH_DEBUG_DESCRIPTION_COUNT(bmi_debug_desc), | 44 ATH_DEBUG_DESCRIPTION_COUNT(bmi_debug_desc), |
37 bmi_debug_desc); | 45 bmi_debug_desc); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 84 } |
77 | 85 |
78 if (!pBMICmdBuf) { | 86 if (!pBMICmdBuf) { |
79 pBMICmdBuf = (A_UCHAR *)A_MALLOC_NOWAIT(MAX_BMI_CMDBUF_SZ); | 87 pBMICmdBuf = (A_UCHAR *)A_MALLOC_NOWAIT(MAX_BMI_CMDBUF_SZ); |
80 A_ASSERT(pBMICmdBuf); | 88 A_ASSERT(pBMICmdBuf); |
81 } | 89 } |
82 | 90 |
83 A_REGISTER_MODULE_DEBUG_INFO(bmi); | 91 A_REGISTER_MODULE_DEBUG_INFO(bmi); |
84 } | 92 } |
85 | 93 |
| 94 void |
| 95 BMICleanup(void) |
| 96 { |
| 97 if (pBMICmdCredits) { |
| 98 A_FREE(pBMICmdCredits); |
| 99 pBMICmdCredits = NULL; |
| 100 } |
| 101 |
| 102 if (pBMICmdBuf) { |
| 103 A_FREE(pBMICmdBuf); |
| 104 pBMICmdBuf = NULL; |
| 105 } |
| 106 } |
| 107 |
86 A_STATUS | 108 A_STATUS |
87 BMIDone(HIF_DEVICE *device) | 109 BMIDone(HIF_DEVICE *device) |
88 { | 110 { |
89 A_STATUS status; | 111 A_STATUS status; |
90 A_UINT32 cid; | 112 A_UINT32 cid; |
91 | 113 |
92 if (bmiDone) { | 114 if (bmiDone) { |
93 AR_DEBUG_PRINTF (ATH_DEBUG_BMI, ("BMIDone skipped\n")); | 115 AR_DEBUG_PRINTF (ATH_DEBUG_BMI, ("BMIDone skipped\n")); |
94 return A_OK; | 116 return A_OK; |
95 } | 117 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 185 |
164 /* Read the remainder of the targ_info */ | 186 /* Read the remainder of the targ_info */ |
165 status = bmiBufferReceive(device, | 187 status = bmiBufferReceive(device, |
166 ((A_UCHAR *)targ_info)+sizeof(targ_info->target_info_byt
e_count), | 188 ((A_UCHAR *)targ_info)+sizeof(targ_info->target_info_byt
e_count), |
167 sizeof(*targ_info)-sizeof(targ_info->target_info_byte_co
unt), TRUE); | 189 sizeof(*targ_info)-sizeof(targ_info->target_info_byte_co
unt), TRUE); |
168 if (status != A_OK) { | 190 if (status != A_OK) { |
169 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read Target Info (%d byte
s) from the device\n", | 191 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read Target Info (%d byte
s) from the device\n", |
170 targ_info->targe
t_info_byte_count)); | 192 targ_info->targe
t_info_byte_count)); |
171 return A_ERROR; | 193 return A_ERROR; |
172 } | 194 } |
173 } else { | |
174 /* | |
175 * Target must be an AR6001 whose firmware does not | |
176 * support BMI_GET_TARGET_INFO. Construct the data | |
177 * that it would have sent. | |
178 */ | |
179 targ_info->target_info_byte_count=sizeof(*targ_info); | |
180 targ_info->target_type=TARGET_TYPE_AR6001; | |
181 } | 195 } |
182 | 196 |
183 AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Get Target Info: Exit (ver: 0x%x type:
0x%x)\n", | 197 AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Get Target Info: Exit (ver: 0x%x type:
0x%x)\n", |
184 targ_info->targe
t_ver, targ_info->target_type)); | 198 targ_info->targe
t_ver, targ_info->target_type)); |
185 | 199 |
186 return A_OK; | 200 return A_OK; |
187 } | 201 } |
188 | 202 |
189 A_STATUS | 203 A_STATUS |
190 BMIReadMemory(HIF_DEVICE *device, | 204 BMIReadMemory(HIF_DEVICE *device, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 BMIWriteMemory(HIF_DEVICE *device, | 260 BMIWriteMemory(HIF_DEVICE *device, |
247 A_UINT32 address, | 261 A_UINT32 address, |
248 A_UCHAR *buffer, | 262 A_UCHAR *buffer, |
249 A_UINT32 length) | 263 A_UINT32 length) |
250 { | 264 { |
251 A_UINT32 cid; | 265 A_UINT32 cid; |
252 A_STATUS status; | 266 A_STATUS status; |
253 A_UINT32 offset; | 267 A_UINT32 offset; |
254 A_UINT32 remaining, txlen; | 268 A_UINT32 remaining, txlen; |
255 const A_UINT32 header = sizeof(cid) + sizeof(address) + sizeof(length); | 269 const A_UINT32 header = sizeof(cid) + sizeof(address) + sizeof(length); |
256 | 270 A_UCHAR alignedBuffer[BMI_DATASZ_MAX]; |
| 271 A_UCHAR *src; |
| 272 |
257 A_ASSERT(BMI_COMMAND_FITS(BMI_DATASZ_MAX + header)); | 273 A_ASSERT(BMI_COMMAND_FITS(BMI_DATASZ_MAX + header)); |
258 memset (pBMICmdBuf, 0, BMI_DATASZ_MAX + header); | 274 memset (pBMICmdBuf, 0, BMI_DATASZ_MAX + header); |
259 | 275 |
260 if (bmiDone) { | 276 if (bmiDone) { |
261 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); | 277 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); |
262 return A_ERROR; | 278 return A_ERROR; |
263 } | 279 } |
264 | 280 |
265 AR_DEBUG_PRINTF(ATH_DEBUG_BMI, | 281 AR_DEBUG_PRINTF(ATH_DEBUG_BMI, |
266 ("BMI Write Memory: Enter (device: 0x%p, address: 0x%x, length: %d)\n", | 282 ("BMI Write Memory: Enter (device: 0x%p, address: 0x%x, length: %d)\n", |
267 device, address, length)); | 283 device, address, length)); |
268 | 284 |
269 cid = BMI_WRITE_MEMORY; | 285 cid = BMI_WRITE_MEMORY; |
270 | 286 |
271 remaining = length; | 287 remaining = length; |
272 while (remaining) | 288 while (remaining) |
273 { | 289 { |
274 txlen = (remaining < (BMI_DATASZ_MAX - header)) ? | 290 src = &buffer[length - remaining]; |
275 remaining : (BMI_DATASZ_MAX - header); | 291 if (remaining < (BMI_DATASZ_MAX - header)) { |
| 292 if (remaining & 3) { |
| 293 /* align it with 4 bytes */ |
| 294 remaining = remaining + (4 - (remaining & 3)); |
| 295 memcpy(alignedBuffer, src, remaining); |
| 296 src = alignedBuffer; |
| 297 } |
| 298 txlen = remaining; |
| 299 } else { |
| 300 txlen = (BMI_DATASZ_MAX - header); |
| 301 } |
276 offset = 0; | 302 offset = 0; |
277 A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); | 303 A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); |
278 offset += sizeof(cid); | 304 offset += sizeof(cid); |
279 A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); | 305 A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); |
280 offset += sizeof(address); | 306 offset += sizeof(address); |
281 A_MEMCPY(&(pBMICmdBuf[offset]), &txlen, sizeof(txlen)); | 307 A_MEMCPY(&(pBMICmdBuf[offset]), &txlen, sizeof(txlen)); |
282 offset += sizeof(txlen); | 308 offset += sizeof(txlen); |
283 A_MEMCPY(&(pBMICmdBuf[offset]), &buffer[length - remaining], txlen); | 309 A_MEMCPY(&(pBMICmdBuf[offset]), src, txlen); |
284 offset += txlen; | 310 offset += txlen; |
285 status = bmiBufferSend(device, pBMICmdBuf, offset); | 311 status = bmiBufferSend(device, pBMICmdBuf, offset); |
286 if (status != A_OK) { | 312 if (status != A_OK) { |
287 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); | 313 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); |
288 return A_ERROR; | 314 return A_ERROR; |
289 } | 315 } |
290 remaining -= txlen; address += txlen; | 316 remaining -= txlen; address += txlen; |
291 } | 317 } |
292 | 318 |
293 AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Write Memory: Exit\n")); | 319 AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Write Memory: Exit\n")); |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 BMIRawWrite(HIF_DEVICE *device, A_UCHAR *buffer, A_UINT32 length) | 1001 BMIRawWrite(HIF_DEVICE *device, A_UCHAR *buffer, A_UINT32 length) |
976 { | 1002 { |
977 return bmiBufferSend(device, buffer, length); | 1003 return bmiBufferSend(device, buffer, length); |
978 } | 1004 } |
979 | 1005 |
980 A_STATUS | 1006 A_STATUS |
981 BMIRawRead(HIF_DEVICE *device, A_UCHAR *buffer, A_UINT32 length, A_BOOL want_tim
eout) | 1007 BMIRawRead(HIF_DEVICE *device, A_UCHAR *buffer, A_UINT32 length, A_BOOL want_tim
eout) |
982 { | 1008 { |
983 return bmiBufferReceive(device, buffer, length, want_timeout); | 1009 return bmiBufferReceive(device, buffer, length, want_timeout); |
984 } | 1010 } |
OLD | NEW |