xref: /openbmc/linux/drivers/net/wireless/ath/ath10k/hif.h (revision 96c64857)
1f0553ca9SKalle Valo /* SPDX-License-Identifier: ISC */
25e3dd157SKalle Valo /*
35e3dd157SKalle Valo  * Copyright (c) 2005-2011 Atheros Communications Inc.
48b1083d6SKalle Valo  * Copyright (c) 2011-2015,2017 Qualcomm Atheros, Inc.
55e3dd157SKalle Valo  */
65e3dd157SKalle Valo 
75e3dd157SKalle Valo #ifndef _HIF_H_
85e3dd157SKalle Valo #define _HIF_H_
95e3dd157SKalle Valo 
105e3dd157SKalle Valo #include <linux/kernel.h>
115e3dd157SKalle Valo #include "core.h"
12140d1214SRakesh Pillai #include "bmi.h"
13077a3804SYanbo Li #include "debug.h"
145e3dd157SKalle Valo 
15d9e47698SGovind Singh /* Types of fw logging mode */
16d9e47698SGovind Singh enum ath_dbg_mode {
17d9e47698SGovind Singh 	ATH10K_ENABLE_FW_LOG_DIAG,
18d9e47698SGovind Singh 	ATH10K_ENABLE_FW_LOG_CE,
19d9e47698SGovind Singh };
20d9e47698SGovind Singh 
21726346fcSMichal Kazior struct ath10k_hif_sg_item {
22726346fcSMichal Kazior 	u16 transfer_id;
23726346fcSMichal Kazior 	void *transfer_context; /* NULL = tx completion callback not called */
24726346fcSMichal Kazior 	void *vaddr; /* for debugging mostly */
25546d407cSGovind Singh 	dma_addr_t paddr;
26726346fcSMichal Kazior 	u16 len;
27726346fcSMichal Kazior };
28726346fcSMichal Kazior 
295e3dd157SKalle Valo struct ath10k_hif_ops {
30726346fcSMichal Kazior 	/* send a scatter-gather list to the target */
31726346fcSMichal Kazior 	int (*tx_sg)(struct ath10k *ar, u8 pipe_id,
32726346fcSMichal Kazior 		     struct ath10k_hif_sg_item *items, int n_items);
335e3dd157SKalle Valo 
34eef25405SKalle Valo 	/* read firmware memory through the diagnose interface */
35eef25405SKalle Valo 	int (*diag_read)(struct ath10k *ar, u32 address, void *buf,
36eef25405SKalle Valo 			 size_t buf_len);
37eef25405SKalle Valo 
389f65ad25SYanbo Li 	int (*diag_write)(struct ath10k *ar, u32 address, const void *data,
399f65ad25SYanbo Li 			  int nbytes);
405e3dd157SKalle Valo 	/*
415e3dd157SKalle Valo 	 * API to handle HIF-specific BMI message exchanges, this API is
425e3dd157SKalle Valo 	 * synchronous and only allowed to be called from a context that
435e3dd157SKalle Valo 	 * can block (sleep)
445e3dd157SKalle Valo 	 */
455e3dd157SKalle Valo 	int (*exchange_bmi_msg)(struct ath10k *ar,
465e3dd157SKalle Valo 				void *request, u32 request_len,
475e3dd157SKalle Valo 				void *response, u32 *response_len);
485e3dd157SKalle Valo 
498c5c5368SMichal Kazior 	/* Post BMI phase, after FW is loaded. Starts regular operation */
505e3dd157SKalle Valo 	int (*start)(struct ath10k *ar);
515e3dd157SKalle Valo 
528c5c5368SMichal Kazior 	/* Clean up what start() did. This does not revert to BMI phase. If
5337ff1b0dSMarcin Rokicki 	 * desired so, call power_down() and power_up()
5437ff1b0dSMarcin Rokicki 	 */
555e3dd157SKalle Valo 	void (*stop)(struct ath10k *ar);
565e3dd157SKalle Valo 
57557e1714SKalle Valo 	int (*start_post)(struct ath10k *ar);
5840194e3bSWen Gong 
59d81686d3SWen Gong 	int (*get_htt_tx_complete)(struct ath10k *ar);
60d81686d3SWen Gong 
615e3dd157SKalle Valo 	int (*map_service_to_pipe)(struct ath10k *ar, u16 service_id,
62400143e4SRajkumar Manoharan 				   u8 *ul_pipe, u8 *dl_pipe);
635e3dd157SKalle Valo 
645e3dd157SKalle Valo 	void (*get_default_pipe)(struct ath10k *ar, u8 *ul_pipe, u8 *dl_pipe);
655e3dd157SKalle Valo 
665e3dd157SKalle Valo 	/*
675e3dd157SKalle Valo 	 * Check if prior sends have completed.
685e3dd157SKalle Valo 	 *
695e3dd157SKalle Valo 	 * Check whether the pipe in question has any completed
705e3dd157SKalle Valo 	 * sends that have not yet been processed.
715e3dd157SKalle Valo 	 * This function is only relevant for HIF pipes that are configured
725e3dd157SKalle Valo 	 * to be polled rather than interrupt-driven.
735e3dd157SKalle Valo 	 */
745e3dd157SKalle Valo 	void (*send_complete_check)(struct ath10k *ar, u8 pipe_id, int force);
755e3dd157SKalle Valo 
765e3dd157SKalle Valo 	u16 (*get_free_queue_number)(struct ath10k *ar, u8 pipe_id);
778c5c5368SMichal Kazior 
78077a3804SYanbo Li 	u32 (*read32)(struct ath10k *ar, u32 address);
79077a3804SYanbo Li 
80077a3804SYanbo Li 	void (*write32)(struct ath10k *ar, u32 address, u32 value);
81077a3804SYanbo Li 
828c5c5368SMichal Kazior 	/* Power up the device and enter BMI transfer mode for FW download */
833c545a25SRakesh Pillai 	int (*power_up)(struct ath10k *ar, enum ath10k_firmware_mode fw_mode);
848c5c5368SMichal Kazior 
858c5c5368SMichal Kazior 	/* Power down the device and free up resources. stop() must be called
8637ff1b0dSMarcin Rokicki 	 * before this if start() was called earlier
8737ff1b0dSMarcin Rokicki 	 */
888c5c5368SMichal Kazior 	void (*power_down)(struct ath10k *ar);
898cd13cadSMichal Kazior 
908cd13cadSMichal Kazior 	int (*suspend)(struct ath10k *ar);
918cd13cadSMichal Kazior 	int (*resume)(struct ath10k *ar);
926847f967SSven Eckelmann 
936847f967SSven Eckelmann 	/* fetch calibration data from target eeprom */
946847f967SSven Eckelmann 	int (*fetch_cal_eeprom)(struct ath10k *ar, void **data,
956847f967SSven Eckelmann 				size_t *data_len);
96140d1214SRakesh Pillai 
97140d1214SRakesh Pillai 	int (*get_target_info)(struct ath10k *ar,
98140d1214SRakesh Pillai 			       struct bmi_target_info *target_info);
99d9e47698SGovind Singh 	int (*set_target_log_mode)(struct ath10k *ar, u8 fw_log_mode);
1005e3dd157SKalle Valo };
1015e3dd157SKalle Valo 
ath10k_hif_tx_sg(struct ath10k * ar,u8 pipe_id,struct ath10k_hif_sg_item * items,int n_items)102726346fcSMichal Kazior static inline int ath10k_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
103726346fcSMichal Kazior 				   struct ath10k_hif_sg_item *items,
104726346fcSMichal Kazior 				   int n_items)
1055e3dd157SKalle Valo {
106726346fcSMichal Kazior 	return ar->hif.ops->tx_sg(ar, pipe_id, items, n_items);
1075e3dd157SKalle Valo }
1085e3dd157SKalle Valo 
ath10k_hif_diag_read(struct ath10k * ar,u32 address,void * buf,size_t buf_len)109eef25405SKalle Valo static inline int ath10k_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
110eef25405SKalle Valo 				       size_t buf_len)
111eef25405SKalle Valo {
112eef25405SKalle Valo 	return ar->hif.ops->diag_read(ar, address, buf, buf_len);
113eef25405SKalle Valo }
114eef25405SKalle Valo 
ath10k_hif_diag_write(struct ath10k * ar,u32 address,const void * data,int nbytes)1159f65ad25SYanbo Li static inline int ath10k_hif_diag_write(struct ath10k *ar, u32 address,
1169f65ad25SYanbo Li 					const void *data, int nbytes)
1179f65ad25SYanbo Li {
1189f65ad25SYanbo Li 	if (!ar->hif.ops->diag_write)
1199f65ad25SYanbo Li 		return -EOPNOTSUPP;
1209f65ad25SYanbo Li 
1219f65ad25SYanbo Li 	return ar->hif.ops->diag_write(ar, address, data, nbytes);
1229f65ad25SYanbo Li }
1239f65ad25SYanbo Li 
ath10k_hif_exchange_bmi_msg(struct ath10k * ar,void * request,u32 request_len,void * response,u32 * response_len)1245e3dd157SKalle Valo static inline int ath10k_hif_exchange_bmi_msg(struct ath10k *ar,
1255e3dd157SKalle Valo 					      void *request, u32 request_len,
1265e3dd157SKalle Valo 					      void *response, u32 *response_len)
1275e3dd157SKalle Valo {
1285e3dd157SKalle Valo 	return ar->hif.ops->exchange_bmi_msg(ar, request, request_len,
1295e3dd157SKalle Valo 					     response, response_len);
1305e3dd157SKalle Valo }
1315e3dd157SKalle Valo 
ath10k_hif_start(struct ath10k * ar)1325e3dd157SKalle Valo static inline int ath10k_hif_start(struct ath10k *ar)
1335e3dd157SKalle Valo {
1345e3dd157SKalle Valo 	return ar->hif.ops->start(ar);
1355e3dd157SKalle Valo }
1365e3dd157SKalle Valo 
ath10k_hif_stop(struct ath10k * ar)1375e3dd157SKalle Valo static inline void ath10k_hif_stop(struct ath10k *ar)
1385e3dd157SKalle Valo {
1395e3dd157SKalle Valo 	return ar->hif.ops->stop(ar);
1405e3dd157SKalle Valo }
1415e3dd157SKalle Valo 
ath10k_hif_start_post(struct ath10k * ar)142557e1714SKalle Valo static inline int ath10k_hif_start_post(struct ath10k *ar)
14340194e3bSWen Gong {
144557e1714SKalle Valo 	if (ar->hif.ops->start_post)
145557e1714SKalle Valo 		return ar->hif.ops->start_post(ar);
14640194e3bSWen Gong 	return 0;
14740194e3bSWen Gong }
14840194e3bSWen Gong 
ath10k_hif_get_htt_tx_complete(struct ath10k * ar)149d81686d3SWen Gong static inline int ath10k_hif_get_htt_tx_complete(struct ath10k *ar)
150d81686d3SWen Gong {
151d81686d3SWen Gong 	if (ar->hif.ops->get_htt_tx_complete)
152d81686d3SWen Gong 		return ar->hif.ops->get_htt_tx_complete(ar);
153d81686d3SWen Gong 	return 0;
154d81686d3SWen Gong }
155d81686d3SWen Gong 
ath10k_hif_map_service_to_pipe(struct ath10k * ar,u16 service_id,u8 * ul_pipe,u8 * dl_pipe)1565e3dd157SKalle Valo static inline int ath10k_hif_map_service_to_pipe(struct ath10k *ar,
1575e3dd157SKalle Valo 						 u16 service_id,
158400143e4SRajkumar Manoharan 						 u8 *ul_pipe, u8 *dl_pipe)
1595e3dd157SKalle Valo {
1605e3dd157SKalle Valo 	return ar->hif.ops->map_service_to_pipe(ar, service_id,
161400143e4SRajkumar Manoharan 						ul_pipe, dl_pipe);
1625e3dd157SKalle Valo }
1635e3dd157SKalle Valo 
ath10k_hif_get_default_pipe(struct ath10k * ar,u8 * ul_pipe,u8 * dl_pipe)1645e3dd157SKalle Valo static inline void ath10k_hif_get_default_pipe(struct ath10k *ar,
1655e3dd157SKalle Valo 					       u8 *ul_pipe, u8 *dl_pipe)
1665e3dd157SKalle Valo {
1675e3dd157SKalle Valo 	ar->hif.ops->get_default_pipe(ar, ul_pipe, dl_pipe);
1685e3dd157SKalle Valo }
1695e3dd157SKalle Valo 
ath10k_hif_send_complete_check(struct ath10k * ar,u8 pipe_id,int force)1705e3dd157SKalle Valo static inline void ath10k_hif_send_complete_check(struct ath10k *ar,
1715e3dd157SKalle Valo 						  u8 pipe_id, int force)
1725e3dd157SKalle Valo {
17396c64857SKalle Valo 	if (ar->hif.ops->send_complete_check)
1745e3dd157SKalle Valo 		ar->hif.ops->send_complete_check(ar, pipe_id, force);
1755e3dd157SKalle Valo }
1765e3dd157SKalle Valo 
ath10k_hif_get_free_queue_number(struct ath10k * ar,u8 pipe_id)1775e3dd157SKalle Valo static inline u16 ath10k_hif_get_free_queue_number(struct ath10k *ar,
1785e3dd157SKalle Valo 						   u8 pipe_id)
1795e3dd157SKalle Valo {
1805e3dd157SKalle Valo 	return ar->hif.ops->get_free_queue_number(ar, pipe_id);
1815e3dd157SKalle Valo }
1825e3dd157SKalle Valo 
ath10k_hif_power_up(struct ath10k * ar,enum ath10k_firmware_mode fw_mode)1833c545a25SRakesh Pillai static inline int ath10k_hif_power_up(struct ath10k *ar,
1843c545a25SRakesh Pillai 				      enum ath10k_firmware_mode fw_mode)
1858c5c5368SMichal Kazior {
1863c545a25SRakesh Pillai 	return ar->hif.ops->power_up(ar, fw_mode);
1878c5c5368SMichal Kazior }
1888c5c5368SMichal Kazior 
ath10k_hif_power_down(struct ath10k * ar)1898c5c5368SMichal Kazior static inline void ath10k_hif_power_down(struct ath10k *ar)
1908c5c5368SMichal Kazior {
1918c5c5368SMichal Kazior 	ar->hif.ops->power_down(ar);
1928c5c5368SMichal Kazior }
1938c5c5368SMichal Kazior 
ath10k_hif_suspend(struct ath10k * ar)1948cd13cadSMichal Kazior static inline int ath10k_hif_suspend(struct ath10k *ar)
1958cd13cadSMichal Kazior {
1968cd13cadSMichal Kazior 	if (!ar->hif.ops->suspend)
1978cd13cadSMichal Kazior 		return -EOPNOTSUPP;
1988cd13cadSMichal Kazior 
1998cd13cadSMichal Kazior 	return ar->hif.ops->suspend(ar);
2008cd13cadSMichal Kazior }
2018cd13cadSMichal Kazior 
ath10k_hif_resume(struct ath10k * ar)2028cd13cadSMichal Kazior static inline int ath10k_hif_resume(struct ath10k *ar)
2038cd13cadSMichal Kazior {
2048cd13cadSMichal Kazior 	if (!ar->hif.ops->resume)
2058cd13cadSMichal Kazior 		return -EOPNOTSUPP;
2068cd13cadSMichal Kazior 
2078cd13cadSMichal Kazior 	return ar->hif.ops->resume(ar);
2088cd13cadSMichal Kazior }
2098cd13cadSMichal Kazior 
ath10k_hif_read32(struct ath10k * ar,u32 address)210077a3804SYanbo Li static inline u32 ath10k_hif_read32(struct ath10k *ar, u32 address)
211077a3804SYanbo Li {
212077a3804SYanbo Li 	if (!ar->hif.ops->read32) {
213077a3804SYanbo Li 		ath10k_warn(ar, "hif read32 not supported\n");
214077a3804SYanbo Li 		return 0xdeaddead;
215077a3804SYanbo Li 	}
216077a3804SYanbo Li 
217077a3804SYanbo Li 	return ar->hif.ops->read32(ar, address);
218077a3804SYanbo Li }
219077a3804SYanbo Li 
ath10k_hif_write32(struct ath10k * ar,u32 address,u32 data)220077a3804SYanbo Li static inline void ath10k_hif_write32(struct ath10k *ar,
221077a3804SYanbo Li 				      u32 address, u32 data)
222077a3804SYanbo Li {
223077a3804SYanbo Li 	if (!ar->hif.ops->write32) {
224077a3804SYanbo Li 		ath10k_warn(ar, "hif write32 not supported\n");
225077a3804SYanbo Li 		return;
226077a3804SYanbo Li 	}
227077a3804SYanbo Li 
228077a3804SYanbo Li 	ar->hif.ops->write32(ar, address, data);
229077a3804SYanbo Li }
230077a3804SYanbo Li 
ath10k_hif_fetch_cal_eeprom(struct ath10k * ar,void ** data,size_t * data_len)2316847f967SSven Eckelmann static inline int ath10k_hif_fetch_cal_eeprom(struct ath10k *ar,
2326847f967SSven Eckelmann 					      void **data,
2336847f967SSven Eckelmann 					      size_t *data_len)
2346847f967SSven Eckelmann {
2356847f967SSven Eckelmann 	if (!ar->hif.ops->fetch_cal_eeprom)
2366847f967SSven Eckelmann 		return -EOPNOTSUPP;
2376847f967SSven Eckelmann 
2386847f967SSven Eckelmann 	return ar->hif.ops->fetch_cal_eeprom(ar, data, data_len);
2396847f967SSven Eckelmann }
2406847f967SSven Eckelmann 
ath10k_hif_get_target_info(struct ath10k * ar,struct bmi_target_info * tgt_info)241140d1214SRakesh Pillai static inline int ath10k_hif_get_target_info(struct ath10k *ar,
242140d1214SRakesh Pillai 					     struct bmi_target_info *tgt_info)
243140d1214SRakesh Pillai {
244140d1214SRakesh Pillai 	if (!ar->hif.ops->get_target_info)
245140d1214SRakesh Pillai 		return -EOPNOTSUPP;
246140d1214SRakesh Pillai 
247140d1214SRakesh Pillai 	return ar->hif.ops->get_target_info(ar, tgt_info);
248140d1214SRakesh Pillai }
249140d1214SRakesh Pillai 
ath10k_hif_set_target_log_mode(struct ath10k * ar,u8 fw_log_mode)250d9e47698SGovind Singh static inline int ath10k_hif_set_target_log_mode(struct ath10k *ar,
251d9e47698SGovind Singh 						 u8 fw_log_mode)
252d9e47698SGovind Singh {
253d9e47698SGovind Singh 	if (!ar->hif.ops->set_target_log_mode)
254d9e47698SGovind Singh 		return -EOPNOTSUPP;
255d9e47698SGovind Singh 
256d9e47698SGovind Singh 	return ar->hif.ops->set_target_log_mode(ar, fw_log_mode);
257d9e47698SGovind Singh }
2585e3dd157SKalle Valo #endif /* _HIF_H_ */
259