xref: /openbmc/linux/drivers/net/wireless/ath/ath10k/bmi.h (revision 37ff1b0d)
15e3dd157SKalle Valo /*
25e3dd157SKalle Valo  * Copyright (c) 2005-2011 Atheros Communications Inc.
35e3dd157SKalle Valo  * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
45e3dd157SKalle Valo  *
55e3dd157SKalle Valo  * Permission to use, copy, modify, and/or distribute this software for any
65e3dd157SKalle Valo  * purpose with or without fee is hereby granted, provided that the above
75e3dd157SKalle Valo  * copyright notice and this permission notice appear in all copies.
85e3dd157SKalle Valo  *
95e3dd157SKalle Valo  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
105e3dd157SKalle Valo  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
115e3dd157SKalle Valo  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
125e3dd157SKalle Valo  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
135e3dd157SKalle Valo  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
145e3dd157SKalle Valo  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
155e3dd157SKalle Valo  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
165e3dd157SKalle Valo  */
175e3dd157SKalle Valo 
185e3dd157SKalle Valo #ifndef _BMI_H_
195e3dd157SKalle Valo #define _BMI_H_
205e3dd157SKalle Valo 
215e3dd157SKalle Valo #include "core.h"
225e3dd157SKalle Valo 
235e3dd157SKalle Valo /*
245e3dd157SKalle Valo  * Bootloader Messaging Interface (BMI)
255e3dd157SKalle Valo  *
265e3dd157SKalle Valo  * BMI is a very simple messaging interface used during initialization
275e3dd157SKalle Valo  * to read memory, write memory, execute code, and to define an
285e3dd157SKalle Valo  * application entry PC.
295e3dd157SKalle Valo  *
305e3dd157SKalle Valo  * It is used to download an application to QCA988x, to provide
315e3dd157SKalle Valo  * patches to code that is already resident on QCA988x, and generally
325e3dd157SKalle Valo  * to examine and modify state.  The Host has an opportunity to use
335e3dd157SKalle Valo  * BMI only once during bootup.  Once the Host issues a BMI_DONE
345e3dd157SKalle Valo  * command, this opportunity ends.
355e3dd157SKalle Valo  *
365e3dd157SKalle Valo  * The Host writes BMI requests to mailbox0, and reads BMI responses
375e3dd157SKalle Valo  * from mailbox0.   BMI requests all begin with a command
385e3dd157SKalle Valo  * (see below for specific commands), and are followed by
395e3dd157SKalle Valo  * command-specific data.
405e3dd157SKalle Valo  *
415e3dd157SKalle Valo  * Flow control:
425e3dd157SKalle Valo  * The Host can only issue a command once the Target gives it a
435e3dd157SKalle Valo  * "BMI Command Credit", using AR8K Counter #4.  As soon as the
445e3dd157SKalle Valo  * Target has completed a command, it issues another BMI Command
455e3dd157SKalle Valo  * Credit (so the Host can issue the next command).
465e3dd157SKalle Valo  *
475e3dd157SKalle Valo  * BMI handles all required Target-side cache flushing.
485e3dd157SKalle Valo  */
495e3dd157SKalle Valo 
505e3dd157SKalle Valo /* Maximum data size used for BMI transfers */
515e3dd157SKalle Valo #define BMI_MAX_DATA_SIZE	256
525e3dd157SKalle Valo 
535e3dd157SKalle Valo /* len = cmd + addr + length */
545e3dd157SKalle Valo #define BMI_MAX_CMDBUF_SIZE (BMI_MAX_DATA_SIZE + \
555e3dd157SKalle Valo 			sizeof(u32) + \
565e3dd157SKalle Valo 			sizeof(u32) + \
575e3dd157SKalle Valo 			sizeof(u32))
585e3dd157SKalle Valo 
595e3dd157SKalle Valo /* BMI Commands */
605e3dd157SKalle Valo 
615e3dd157SKalle Valo enum bmi_cmd_id {
625e3dd157SKalle Valo 	BMI_NO_COMMAND          = 0,
635e3dd157SKalle Valo 	BMI_DONE                = 1,
645e3dd157SKalle Valo 	BMI_READ_MEMORY         = 2,
655e3dd157SKalle Valo 	BMI_WRITE_MEMORY        = 3,
665e3dd157SKalle Valo 	BMI_EXECUTE             = 4,
675e3dd157SKalle Valo 	BMI_SET_APP_START       = 5,
685e3dd157SKalle Valo 	BMI_READ_SOC_REGISTER   = 6,
695e3dd157SKalle Valo 	BMI_READ_SOC_WORD       = 6,
705e3dd157SKalle Valo 	BMI_WRITE_SOC_REGISTER  = 7,
715e3dd157SKalle Valo 	BMI_WRITE_SOC_WORD      = 7,
725e3dd157SKalle Valo 	BMI_GET_TARGET_ID       = 8,
735e3dd157SKalle Valo 	BMI_GET_TARGET_INFO     = 8,
745e3dd157SKalle Valo 	BMI_ROMPATCH_INSTALL    = 9,
755e3dd157SKalle Valo 	BMI_ROMPATCH_UNINSTALL  = 10,
765e3dd157SKalle Valo 	BMI_ROMPATCH_ACTIVATE   = 11,
775e3dd157SKalle Valo 	BMI_ROMPATCH_DEACTIVATE = 12,
785e3dd157SKalle Valo 	BMI_LZ_STREAM_START     = 13, /* should be followed by LZ_DATA */
795e3dd157SKalle Valo 	BMI_LZ_DATA             = 14,
805e3dd157SKalle Valo 	BMI_NVRAM_PROCESS       = 15,
815e3dd157SKalle Valo };
825e3dd157SKalle Valo 
835e3dd157SKalle Valo #define BMI_NVRAM_SEG_NAME_SZ 16
845e3dd157SKalle Valo 
85db0984e5SManikanta Pubbisetty #define BMI_PARAM_GET_EEPROM_BOARD_ID 0x10
86db0984e5SManikanta Pubbisetty 
87db0984e5SManikanta Pubbisetty #define ATH10K_BMI_BOARD_ID_FROM_OTP_MASK   0x7c00
88db0984e5SManikanta Pubbisetty #define ATH10K_BMI_BOARD_ID_FROM_OTP_LSB    10
89db0984e5SManikanta Pubbisetty 
90db0984e5SManikanta Pubbisetty #define ATH10K_BMI_CHIP_ID_FROM_OTP_MASK    0x18000
91db0984e5SManikanta Pubbisetty #define ATH10K_BMI_CHIP_ID_FROM_OTP_LSB     15
92db0984e5SManikanta Pubbisetty 
93db0984e5SManikanta Pubbisetty #define ATH10K_BMI_BOARD_ID_STATUS_MASK 0xff
94db0984e5SManikanta Pubbisetty 
955e3dd157SKalle Valo struct bmi_cmd {
965e3dd157SKalle Valo 	__le32 id; /* enum bmi_cmd_id */
975e3dd157SKalle Valo 	union {
985e3dd157SKalle Valo 		struct {
995e3dd157SKalle Valo 		} done;
1005e3dd157SKalle Valo 		struct {
1015e3dd157SKalle Valo 			__le32 addr;
1025e3dd157SKalle Valo 			__le32 len;
1035e3dd157SKalle Valo 		} read_mem;
1045e3dd157SKalle Valo 		struct {
1055e3dd157SKalle Valo 			__le32 addr;
1065e3dd157SKalle Valo 			__le32 len;
1075e3dd157SKalle Valo 			u8 payload[0];
1085e3dd157SKalle Valo 		} write_mem;
1095e3dd157SKalle Valo 		struct {
1105e3dd157SKalle Valo 			__le32 addr;
1115e3dd157SKalle Valo 			__le32 param;
1125e3dd157SKalle Valo 		} execute;
1135e3dd157SKalle Valo 		struct {
1145e3dd157SKalle Valo 			__le32 addr;
1155e3dd157SKalle Valo 		} set_app_start;
1165e3dd157SKalle Valo 		struct {
1175e3dd157SKalle Valo 			__le32 addr;
1185e3dd157SKalle Valo 		} read_soc_reg;
1195e3dd157SKalle Valo 		struct {
1205e3dd157SKalle Valo 			__le32 addr;
1215e3dd157SKalle Valo 			__le32 value;
1225e3dd157SKalle Valo 		} write_soc_reg;
1235e3dd157SKalle Valo 		struct {
1245e3dd157SKalle Valo 		} get_target_info;
1255e3dd157SKalle Valo 		struct {
1265e3dd157SKalle Valo 			__le32 rom_addr;
1275e3dd157SKalle Valo 			__le32 ram_addr; /* or value */
1285e3dd157SKalle Valo 			__le32 size;
1295e3dd157SKalle Valo 			__le32 activate; /* 0=install, but dont activate */
1305e3dd157SKalle Valo 		} rompatch_install;
1315e3dd157SKalle Valo 		struct {
1325e3dd157SKalle Valo 			__le32 patch_id;
1335e3dd157SKalle Valo 		} rompatch_uninstall;
1345e3dd157SKalle Valo 		struct {
1355e3dd157SKalle Valo 			__le32 count;
1365e3dd157SKalle Valo 			__le32 patch_ids[0]; /* length of @count */
1375e3dd157SKalle Valo 		} rompatch_activate;
1385e3dd157SKalle Valo 		struct {
1395e3dd157SKalle Valo 			__le32 count;
1405e3dd157SKalle Valo 			__le32 patch_ids[0]; /* length of @count */
1415e3dd157SKalle Valo 		} rompatch_deactivate;
1425e3dd157SKalle Valo 		struct {
1435e3dd157SKalle Valo 			__le32 addr;
1445e3dd157SKalle Valo 		} lz_start;
1455e3dd157SKalle Valo 		struct {
1465e3dd157SKalle Valo 			__le32 len; /* max BMI_MAX_DATA_SIZE */
1475e3dd157SKalle Valo 			u8 payload[0]; /* length of @len */
1485e3dd157SKalle Valo 		} lz_data;
1495e3dd157SKalle Valo 		struct {
1505e3dd157SKalle Valo 			u8 name[BMI_NVRAM_SEG_NAME_SZ];
1515e3dd157SKalle Valo 		} nvram_process;
1525e3dd157SKalle Valo 		u8 payload[BMI_MAX_CMDBUF_SIZE];
1535e3dd157SKalle Valo 	};
1545e3dd157SKalle Valo } __packed;
1555e3dd157SKalle Valo 
1565e3dd157SKalle Valo union bmi_resp {
1575e3dd157SKalle Valo 	struct {
1585e3dd157SKalle Valo 		u8 payload[0];
1595e3dd157SKalle Valo 	} read_mem;
1605e3dd157SKalle Valo 	struct {
1615e3dd157SKalle Valo 		__le32 result;
1625e3dd157SKalle Valo 	} execute;
1635e3dd157SKalle Valo 	struct {
1645e3dd157SKalle Valo 		__le32 value;
1655e3dd157SKalle Valo 	} read_soc_reg;
1665e3dd157SKalle Valo 	struct {
1675e3dd157SKalle Valo 		__le32 len;
1685e3dd157SKalle Valo 		__le32 version;
1695e3dd157SKalle Valo 		__le32 type;
1705e3dd157SKalle Valo 	} get_target_info;
1715e3dd157SKalle Valo 	struct {
1725e3dd157SKalle Valo 		__le32 patch_id;
1735e3dd157SKalle Valo 	} rompatch_install;
1745e3dd157SKalle Valo 	struct {
1755e3dd157SKalle Valo 		__le32 patch_id;
1765e3dd157SKalle Valo 	} rompatch_uninstall;
1775e3dd157SKalle Valo 	struct {
1785e3dd157SKalle Valo 		/* 0 = nothing executed
17937ff1b0dSMarcin Rokicki 		 * otherwise = NVRAM segment return value
18037ff1b0dSMarcin Rokicki 		 */
1815e3dd157SKalle Valo 		__le32 result;
1825e3dd157SKalle Valo 	} nvram_process;
1835e3dd157SKalle Valo 	u8 payload[BMI_MAX_CMDBUF_SIZE];
1845e3dd157SKalle Valo } __packed;
1855e3dd157SKalle Valo 
1865e3dd157SKalle Valo struct bmi_target_info {
1875e3dd157SKalle Valo 	u32 version;
1885e3dd157SKalle Valo 	u32 type;
1895e3dd157SKalle Valo };
1905e3dd157SKalle Valo 
1915e3dd157SKalle Valo /* in msec */
192fd3d6ffbSVasanthakumar Thiagarajan #define BMI_COMMUNICATION_TIMEOUT_HZ (2 * HZ)
1935e3dd157SKalle Valo 
1945e3dd157SKalle Valo #define BMI_CE_NUM_TO_TARG 0
1955e3dd157SKalle Valo #define BMI_CE_NUM_TO_HOST 1
1965e3dd157SKalle Valo 
19764d151d4SMichal Kazior void ath10k_bmi_start(struct ath10k *ar);
1985e3dd157SKalle Valo int ath10k_bmi_done(struct ath10k *ar);
1995e3dd157SKalle Valo int ath10k_bmi_get_target_info(struct ath10k *ar,
2005e3dd157SKalle Valo 			       struct bmi_target_info *target_info);
2015e3dd157SKalle Valo int ath10k_bmi_read_memory(struct ath10k *ar, u32 address,
2025e3dd157SKalle Valo 			   void *buffer, u32 length);
2035e3dd157SKalle Valo int ath10k_bmi_write_memory(struct ath10k *ar, u32 address,
2045e3dd157SKalle Valo 			    const void *buffer, u32 length);
2055e3dd157SKalle Valo 
2065e3dd157SKalle Valo #define ath10k_bmi_read32(ar, item, val)				\
2075e3dd157SKalle Valo 	({								\
2085e3dd157SKalle Valo 		int ret;						\
2095e3dd157SKalle Valo 		u32 addr;						\
2105e3dd157SKalle Valo 		__le32 tmp;						\
2115e3dd157SKalle Valo 									\
2125e3dd157SKalle Valo 		addr = host_interest_item_address(HI_ITEM(item));	\
2135e3dd157SKalle Valo 		ret = ath10k_bmi_read_memory(ar, addr, (u8 *)&tmp, 4); \
214afe5b7b4SFrederic Danis 		if (!ret)						\
2155e3dd157SKalle Valo 			*val = __le32_to_cpu(tmp);			\
2165e3dd157SKalle Valo 		ret;							\
2175e3dd157SKalle Valo 	 })
2185e3dd157SKalle Valo 
2195e3dd157SKalle Valo #define ath10k_bmi_write32(ar, item, val)				\
2205e3dd157SKalle Valo 	({								\
2215e3dd157SKalle Valo 		int ret;						\
2225e3dd157SKalle Valo 		u32 address;						\
2235e3dd157SKalle Valo 		__le32 v = __cpu_to_le32(val);				\
2245e3dd157SKalle Valo 									\
2255e3dd157SKalle Valo 		address = host_interest_item_address(HI_ITEM(item));	\
2265e3dd157SKalle Valo 		ret = ath10k_bmi_write_memory(ar, address,		\
2275e3dd157SKalle Valo 					      (u8 *)&v, sizeof(v));	\
2285e3dd157SKalle Valo 		ret;							\
2295e3dd157SKalle Valo 	})
2305e3dd157SKalle Valo 
231d6d4a58dSKalle Valo int ath10k_bmi_execute(struct ath10k *ar, u32 address, u32 param, u32 *result);
2325e3dd157SKalle Valo int ath10k_bmi_lz_stream_start(struct ath10k *ar, u32 address);
2335e3dd157SKalle Valo int ath10k_bmi_lz_data(struct ath10k *ar, const void *buffer, u32 length);
2345e3dd157SKalle Valo int ath10k_bmi_fast_download(struct ath10k *ar, u32 address,
2355e3dd157SKalle Valo 			     const void *buffer, u32 length);
236583a6629SRyan Hsu int ath10k_bmi_read_soc_reg(struct ath10k *ar, u32 address, u32 *reg_val);
237583a6629SRyan Hsu int ath10k_bmi_write_soc_reg(struct ath10k *ar, u32 address, u32 reg_val);
2385e3dd157SKalle Valo #endif /* _BMI_H_ */
239