18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2004-2011 Atheros Communications Inc. 38c2ecf20Sopenharmony_ci * Copyright (c) 2011 Qualcomm Atheros, Inc. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 68c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 78c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 108c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 118c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 128c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 138c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 148c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 158c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 168c2ecf20Sopenharmony_ci */ 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#ifndef BMI_H 198c2ecf20Sopenharmony_ci#define BMI_H 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/* 228c2ecf20Sopenharmony_ci * Bootloader Messaging Interface (BMI) 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * BMI is a very simple messaging interface used during initialization 258c2ecf20Sopenharmony_ci * to read memory, write memory, execute code, and to define an 268c2ecf20Sopenharmony_ci * application entry PC. 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * It is used to download an application to ATH6KL, to provide 298c2ecf20Sopenharmony_ci * patches to code that is already resident on ATH6KL, and generally 308c2ecf20Sopenharmony_ci * to examine and modify state. The Host has an opportunity to use 318c2ecf20Sopenharmony_ci * BMI only once during bootup. Once the Host issues a BMI_DONE 328c2ecf20Sopenharmony_ci * command, this opportunity ends. 338c2ecf20Sopenharmony_ci * 348c2ecf20Sopenharmony_ci * The Host writes BMI requests to mailbox0, and reads BMI responses 358c2ecf20Sopenharmony_ci * from mailbox0. BMI requests all begin with a command 368c2ecf20Sopenharmony_ci * (see below for specific commands), and are followed by 378c2ecf20Sopenharmony_ci * command-specific data. 388c2ecf20Sopenharmony_ci * 398c2ecf20Sopenharmony_ci * Flow control: 408c2ecf20Sopenharmony_ci * The Host can only issue a command once the Target gives it a 418c2ecf20Sopenharmony_ci * "BMI Command Credit", using ATH6KL Counter #4. As soon as the 428c2ecf20Sopenharmony_ci * Target has completed a command, it issues another BMI Command 438c2ecf20Sopenharmony_ci * Credit (so the Host can issue the next command). 448c2ecf20Sopenharmony_ci * 458c2ecf20Sopenharmony_ci * BMI handles all required Target-side cache flushing. 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* BMI Commands */ 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define BMI_NO_COMMAND 0 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#define BMI_DONE 1 538c2ecf20Sopenharmony_ci/* 548c2ecf20Sopenharmony_ci * Semantics: Host is done using BMI 558c2ecf20Sopenharmony_ci * Request format: 568c2ecf20Sopenharmony_ci * u32 command (BMI_DONE) 578c2ecf20Sopenharmony_ci * Response format: none 588c2ecf20Sopenharmony_ci */ 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#define BMI_READ_MEMORY 2 618c2ecf20Sopenharmony_ci/* 628c2ecf20Sopenharmony_ci * Semantics: Host reads ATH6KL memory 638c2ecf20Sopenharmony_ci * Request format: 648c2ecf20Sopenharmony_ci * u32 command (BMI_READ_MEMORY) 658c2ecf20Sopenharmony_ci * u32 address 668c2ecf20Sopenharmony_ci * u32 length, at most BMI_DATASZ_MAX 678c2ecf20Sopenharmony_ci * Response format: 688c2ecf20Sopenharmony_ci * u8 data[length] 698c2ecf20Sopenharmony_ci */ 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#define BMI_WRITE_MEMORY 3 728c2ecf20Sopenharmony_ci/* 738c2ecf20Sopenharmony_ci * Semantics: Host writes ATH6KL memory 748c2ecf20Sopenharmony_ci * Request format: 758c2ecf20Sopenharmony_ci * u32 command (BMI_WRITE_MEMORY) 768c2ecf20Sopenharmony_ci * u32 address 778c2ecf20Sopenharmony_ci * u32 length, at most BMI_DATASZ_MAX 788c2ecf20Sopenharmony_ci * u8 data[length] 798c2ecf20Sopenharmony_ci * Response format: none 808c2ecf20Sopenharmony_ci */ 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci#define BMI_EXECUTE 4 838c2ecf20Sopenharmony_ci/* 848c2ecf20Sopenharmony_ci * Semantics: Causes ATH6KL to execute code 858c2ecf20Sopenharmony_ci * Request format: 868c2ecf20Sopenharmony_ci * u32 command (BMI_EXECUTE) 878c2ecf20Sopenharmony_ci * u32 address 888c2ecf20Sopenharmony_ci * u32 parameter 898c2ecf20Sopenharmony_ci * Response format: 908c2ecf20Sopenharmony_ci * u32 return value 918c2ecf20Sopenharmony_ci */ 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci#define BMI_SET_APP_START 5 948c2ecf20Sopenharmony_ci/* 958c2ecf20Sopenharmony_ci * Semantics: Set Target application starting address 968c2ecf20Sopenharmony_ci * Request format: 978c2ecf20Sopenharmony_ci * u32 command (BMI_SET_APP_START) 988c2ecf20Sopenharmony_ci * u32 address 998c2ecf20Sopenharmony_ci * Response format: none 1008c2ecf20Sopenharmony_ci */ 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci#define BMI_READ_SOC_REGISTER 6 1038c2ecf20Sopenharmony_ci/* 1048c2ecf20Sopenharmony_ci * Semantics: Read a 32-bit Target SOC register. 1058c2ecf20Sopenharmony_ci * Request format: 1068c2ecf20Sopenharmony_ci * u32 command (BMI_READ_REGISTER) 1078c2ecf20Sopenharmony_ci * u32 address 1088c2ecf20Sopenharmony_ci * Response format: 1098c2ecf20Sopenharmony_ci * u32 value 1108c2ecf20Sopenharmony_ci */ 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci#define BMI_WRITE_SOC_REGISTER 7 1138c2ecf20Sopenharmony_ci/* 1148c2ecf20Sopenharmony_ci * Semantics: Write a 32-bit Target SOC register. 1158c2ecf20Sopenharmony_ci * Request format: 1168c2ecf20Sopenharmony_ci * u32 command (BMI_WRITE_REGISTER) 1178c2ecf20Sopenharmony_ci * u32 address 1188c2ecf20Sopenharmony_ci * u32 value 1198c2ecf20Sopenharmony_ci * 1208c2ecf20Sopenharmony_ci * Response format: none 1218c2ecf20Sopenharmony_ci */ 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci#define BMI_GET_TARGET_ID 8 1248c2ecf20Sopenharmony_ci#define BMI_GET_TARGET_INFO 8 1258c2ecf20Sopenharmony_ci/* 1268c2ecf20Sopenharmony_ci * Semantics: Fetch the 4-byte Target information 1278c2ecf20Sopenharmony_ci * Request format: 1288c2ecf20Sopenharmony_ci * u32 command (BMI_GET_TARGET_ID/INFO) 1298c2ecf20Sopenharmony_ci * Response format1 (old firmware): 1308c2ecf20Sopenharmony_ci * u32 TargetVersionID 1318c2ecf20Sopenharmony_ci * Response format2 (newer firmware): 1328c2ecf20Sopenharmony_ci * u32 TARGET_VERSION_SENTINAL 1338c2ecf20Sopenharmony_ci * struct bmi_target_info; 1348c2ecf20Sopenharmony_ci */ 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#define TARGET_VERSION_SENTINAL 0xffffffff 1378c2ecf20Sopenharmony_ci#define TARGET_TYPE_AR6003 3 1388c2ecf20Sopenharmony_ci#define TARGET_TYPE_AR6004 5 1398c2ecf20Sopenharmony_ci#define BMI_ROMPATCH_INSTALL 9 1408c2ecf20Sopenharmony_ci/* 1418c2ecf20Sopenharmony_ci * Semantics: Install a ROM Patch. 1428c2ecf20Sopenharmony_ci * Request format: 1438c2ecf20Sopenharmony_ci * u32 command (BMI_ROMPATCH_INSTALL) 1448c2ecf20Sopenharmony_ci * u32 Target ROM Address 1458c2ecf20Sopenharmony_ci * u32 Target RAM Address or Value (depending on Target Type) 1468c2ecf20Sopenharmony_ci * u32 Size, in bytes 1478c2ecf20Sopenharmony_ci * u32 Activate? 1-->activate; 1488c2ecf20Sopenharmony_ci * 0-->install but do not activate 1498c2ecf20Sopenharmony_ci * Response format: 1508c2ecf20Sopenharmony_ci * u32 PatchID 1518c2ecf20Sopenharmony_ci */ 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci#define BMI_ROMPATCH_UNINSTALL 10 1548c2ecf20Sopenharmony_ci/* 1558c2ecf20Sopenharmony_ci * Semantics: Uninstall a previously-installed ROM Patch, 1568c2ecf20Sopenharmony_ci * automatically deactivating, if necessary. 1578c2ecf20Sopenharmony_ci * Request format: 1588c2ecf20Sopenharmony_ci * u32 command (BMI_ROMPATCH_UNINSTALL) 1598c2ecf20Sopenharmony_ci * u32 PatchID 1608c2ecf20Sopenharmony_ci * 1618c2ecf20Sopenharmony_ci * Response format: none 1628c2ecf20Sopenharmony_ci */ 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci#define BMI_ROMPATCH_ACTIVATE 11 1658c2ecf20Sopenharmony_ci/* 1668c2ecf20Sopenharmony_ci * Semantics: Activate a list of previously-installed ROM Patches. 1678c2ecf20Sopenharmony_ci * Request format: 1688c2ecf20Sopenharmony_ci * u32 command (BMI_ROMPATCH_ACTIVATE) 1698c2ecf20Sopenharmony_ci * u32 rompatch_count 1708c2ecf20Sopenharmony_ci * u32 PatchID[rompatch_count] 1718c2ecf20Sopenharmony_ci * 1728c2ecf20Sopenharmony_ci * Response format: none 1738c2ecf20Sopenharmony_ci */ 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci#define BMI_ROMPATCH_DEACTIVATE 12 1768c2ecf20Sopenharmony_ci/* 1778c2ecf20Sopenharmony_ci * Semantics: Deactivate a list of active ROM Patches. 1788c2ecf20Sopenharmony_ci * Request format: 1798c2ecf20Sopenharmony_ci * u32 command (BMI_ROMPATCH_DEACTIVATE) 1808c2ecf20Sopenharmony_ci * u32 rompatch_count 1818c2ecf20Sopenharmony_ci * u32 PatchID[rompatch_count] 1828c2ecf20Sopenharmony_ci * 1838c2ecf20Sopenharmony_ci * Response format: none 1848c2ecf20Sopenharmony_ci */ 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci#define BMI_LZ_STREAM_START 13 1888c2ecf20Sopenharmony_ci/* 1898c2ecf20Sopenharmony_ci * Semantics: Begin an LZ-compressed stream of input 1908c2ecf20Sopenharmony_ci * which is to be uncompressed by the Target to an 1918c2ecf20Sopenharmony_ci * output buffer at address. The output buffer must 1928c2ecf20Sopenharmony_ci * be sufficiently large to hold the uncompressed 1938c2ecf20Sopenharmony_ci * output from the compressed input stream. This BMI 1948c2ecf20Sopenharmony_ci * command should be followed by a series of 1 or more 1958c2ecf20Sopenharmony_ci * BMI_LZ_DATA commands. 1968c2ecf20Sopenharmony_ci * u32 command (BMI_LZ_STREAM_START) 1978c2ecf20Sopenharmony_ci * u32 address 1988c2ecf20Sopenharmony_ci * Note: Not supported on all versions of ROM firmware. 1998c2ecf20Sopenharmony_ci */ 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci#define BMI_LZ_DATA 14 2028c2ecf20Sopenharmony_ci/* 2038c2ecf20Sopenharmony_ci * Semantics: Host writes ATH6KL memory with LZ-compressed 2048c2ecf20Sopenharmony_ci * data which is uncompressed by the Target. This command 2058c2ecf20Sopenharmony_ci * must be preceded by a BMI_LZ_STREAM_START command. A series 2068c2ecf20Sopenharmony_ci * of BMI_LZ_DATA commands are considered part of a single 2078c2ecf20Sopenharmony_ci * input stream until another BMI_LZ_STREAM_START is issued. 2088c2ecf20Sopenharmony_ci * Request format: 2098c2ecf20Sopenharmony_ci * u32 command (BMI_LZ_DATA) 2108c2ecf20Sopenharmony_ci * u32 length (of compressed data), 2118c2ecf20Sopenharmony_ci * at most BMI_DATASZ_MAX 2128c2ecf20Sopenharmony_ci * u8 CompressedData[length] 2138c2ecf20Sopenharmony_ci * Response format: none 2148c2ecf20Sopenharmony_ci * Note: Not supported on all versions of ROM firmware. 2158c2ecf20Sopenharmony_ci */ 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci#define BMI_COMMUNICATION_TIMEOUT 1000 /* in msec */ 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_cistruct ath6kl; 2208c2ecf20Sopenharmony_cistruct ath6kl_bmi_target_info { 2218c2ecf20Sopenharmony_ci __le32 byte_count; /* size of this structure */ 2228c2ecf20Sopenharmony_ci __le32 version; /* target version id */ 2238c2ecf20Sopenharmony_ci __le32 type; /* target type */ 2248c2ecf20Sopenharmony_ci} __packed; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci#define ath6kl_bmi_write_hi32(ar, item, val) \ 2278c2ecf20Sopenharmony_ci ({ \ 2288c2ecf20Sopenharmony_ci u32 addr; \ 2298c2ecf20Sopenharmony_ci __le32 v; \ 2308c2ecf20Sopenharmony_ci \ 2318c2ecf20Sopenharmony_ci addr = ath6kl_get_hi_item_addr(ar, HI_ITEM(item)); \ 2328c2ecf20Sopenharmony_ci v = cpu_to_le32(val); \ 2338c2ecf20Sopenharmony_ci ath6kl_bmi_write(ar, addr, (u8 *) &v, sizeof(v)); \ 2348c2ecf20Sopenharmony_ci }) 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci#define ath6kl_bmi_read_hi32(ar, item, val) \ 2378c2ecf20Sopenharmony_ci ({ \ 2388c2ecf20Sopenharmony_ci u32 addr, *check_type = val; \ 2398c2ecf20Sopenharmony_ci __le32 tmp; \ 2408c2ecf20Sopenharmony_ci int ret; \ 2418c2ecf20Sopenharmony_ci \ 2428c2ecf20Sopenharmony_ci (void) (check_type == val); \ 2438c2ecf20Sopenharmony_ci addr = ath6kl_get_hi_item_addr(ar, HI_ITEM(item)); \ 2448c2ecf20Sopenharmony_ci ret = ath6kl_bmi_read(ar, addr, (u8 *) &tmp, 4); \ 2458c2ecf20Sopenharmony_ci if (!ret) \ 2468c2ecf20Sopenharmony_ci *val = le32_to_cpu(tmp); \ 2478c2ecf20Sopenharmony_ci ret; \ 2488c2ecf20Sopenharmony_ci }) 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ciint ath6kl_bmi_init(struct ath6kl *ar); 2518c2ecf20Sopenharmony_civoid ath6kl_bmi_cleanup(struct ath6kl *ar); 2528c2ecf20Sopenharmony_civoid ath6kl_bmi_reset(struct ath6kl *ar); 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ciint ath6kl_bmi_done(struct ath6kl *ar); 2558c2ecf20Sopenharmony_ciint ath6kl_bmi_get_target_info(struct ath6kl *ar, 2568c2ecf20Sopenharmony_ci struct ath6kl_bmi_target_info *targ_info); 2578c2ecf20Sopenharmony_ciint ath6kl_bmi_read(struct ath6kl *ar, u32 addr, u8 *buf, u32 len); 2588c2ecf20Sopenharmony_ciint ath6kl_bmi_write(struct ath6kl *ar, u32 addr, u8 *buf, u32 len); 2598c2ecf20Sopenharmony_ciint ath6kl_bmi_execute(struct ath6kl *ar, 2608c2ecf20Sopenharmony_ci u32 addr, u32 *param); 2618c2ecf20Sopenharmony_ciint ath6kl_bmi_set_app_start(struct ath6kl *ar, 2628c2ecf20Sopenharmony_ci u32 addr); 2638c2ecf20Sopenharmony_ciint ath6kl_bmi_reg_read(struct ath6kl *ar, u32 addr, u32 *param); 2648c2ecf20Sopenharmony_ciint ath6kl_bmi_reg_write(struct ath6kl *ar, u32 addr, u32 param); 2658c2ecf20Sopenharmony_ciint ath6kl_bmi_lz_data(struct ath6kl *ar, 2668c2ecf20Sopenharmony_ci u8 *buf, u32 len); 2678c2ecf20Sopenharmony_ciint ath6kl_bmi_lz_stream_start(struct ath6kl *ar, 2688c2ecf20Sopenharmony_ci u32 addr); 2698c2ecf20Sopenharmony_ciint ath6kl_bmi_fast_download(struct ath6kl *ar, 2708c2ecf20Sopenharmony_ci u32 addr, u8 *buf, u32 len); 2718c2ecf20Sopenharmony_ci#endif 272