xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852bs/phl/phl_cmd_dispatch.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2019 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 #ifndef __PHL_CMD_DISP_ENG_H_
16 #define __PHL_CMD_DISP_ENG_H_
17 #define SHARE_THREAD_MODE (0x1)
18 #define SOLO_THREAD_MODE (0x2)
19 /**
20  * phl_cmd_dispatch_engine,
21  * @phl_info: for general reference usage.
22  * @dispatcher: array of cmd dispatcher,
23  *	each dispatch is design to address coexist issue for each PHY instance.
24  * @phy_num: current PHY instance number
25  * @token_mgnt_thread: token mgnt thread
26  * @token_chk: semaphore to wake up token mgnt thread
27  * @thread_mode: indicate current thread operation mode.
28  * 		 SHARE_THREAD_MODE means all dispatcher share an background thread
29  * 		 SOLO_THREAD_MODE means each disaptcher has a dedicated background thread
30  * @msg_q_sema: (opt) only used in SHARE_THREAD_MODE, used to wake up shared background thread
31  * @share_thread: (opt) only used in SHARE_THREAD_MODE, context of shared background thread
32  */
33 struct phl_cmd_dispatch_engine {
34 	struct phl_info_t *phl_info;
35 	void **dispatcher; //an array of struct cmd_dispatcher
36 	u8 phy_num;
37 	u8 thread_mode;
38 	_os_sema msg_q_sema;
39 	_os_thread share_thread;
40 #ifdef CONFIG_CMD_DISP_SOLO_MODE
41 	_os_sema dispr_ctrl_sema; /* keep msg from different dispr sequentially forward to ctrl*/
42 #endif
43 };
44 
45 
46 /* functions called in phl layer*/
47 enum rtw_phl_status phl_disp_eng_init(struct phl_info_t *phl, u8 phy_num);
48 enum rtw_phl_status phl_disp_eng_deinit(struct phl_info_t *phl);
49 enum rtw_phl_status phl_disp_eng_start(struct phl_info_t *phl);
50 enum rtw_phl_status phl_disp_eng_stop(struct phl_info_t *phl);
51 
52 /* bk module would be initialized in phl_disp_eng_register_module call
53  * as for de-initialization, user can use phl_disp_eng_deregister_module as pair-wise operation
54  * or phl_disp_eng_deinit would deinit all bk modules per dispatcher
55 */
56 enum rtw_phl_status phl_disp_eng_register_module(struct phl_info_t *phl,
57 						 u8 band_idx,
58 						 enum phl_module_id id,
59 						 struct phl_bk_module_ops *ops);
60 
61 enum rtw_phl_status phl_disp_eng_deregister_module(struct phl_info_t *phl,
62 						   u8 band_idx,
63 						   enum phl_module_id id);
64 enum rtw_phl_status phl_dispr_get_idx(void *dispr, u8 *idx);
65 u8 phl_disp_eng_is_dispr_busy(struct phl_info_t *phl, u8 band_idx);
66 u8 phl_disp_eng_is_fg_empty(struct phl_info_t *phl, u8 band_idx);
67 enum rtw_phl_status phl_disp_eng_set_cur_cmd_info(struct phl_info_t *phl, u8 band_idx,
68 					       struct phl_module_op_info *op_info);
69 enum rtw_phl_status phl_disp_eng_query_cur_cmd_info(struct phl_info_t *phl, u8 band_idx,
70 						 struct phl_module_op_info *op_info);
71 enum rtw_phl_status phl_disp_eng_set_bk_module_info(struct phl_info_t *phl, u8 band_idx,
72 						enum phl_module_id id, struct phl_module_op_info *op_info);
73 enum rtw_phl_status phl_disp_eng_query_bk_module_info(struct phl_info_t *phl, u8 band_idx,
74 							enum phl_module_id id, struct phl_module_op_info *op_info);
75 enum rtw_phl_status phl_disp_eng_set_src_info(struct phl_info_t *phl, struct phl_msg *msg,
76 						struct phl_module_op_info *op_info);
77 enum rtw_phl_status phl_disp_eng_query_src_info(struct phl_info_t *phl, struct phl_msg *msg,
78 						struct phl_module_op_info *op_info);
79 enum rtw_phl_status phl_disp_eng_send_msg(struct phl_info_t *phl, struct phl_msg *msg,
80 						struct phl_msg_attribute *attr, u32 *msg_hdl);
81 enum rtw_phl_status phl_disp_eng_cancel_msg(struct phl_info_t *phl, u8 band_idx, u32 *msg_hdl);
82 enum rtw_phl_status phl_disp_eng_clr_pending_msg(struct phl_info_t *phl, u8 band_idx);
83 
84 enum rtw_phl_status phl_disp_eng_add_token_req(struct phl_info_t *phl, u8 band_idx,
85 					    struct phl_cmd_token_req *req, u32 *req_hdl);
86 enum rtw_phl_status phl_disp_eng_cancel_token_req(struct phl_info_t *phl, u8 band_idx, u32 *req_hdl);
87 enum rtw_phl_status phl_disp_eng_free_token(struct phl_info_t *phl, u8 band_idx, u32 *req_hdl);
88 enum rtw_phl_status phl_disp_eng_notify_dev_io_status(struct phl_info_t *phl,
89                                                       u8 band_idx,
90                                                       enum phl_module_id mdl_id,
91                                                       bool allow_io);
92 void phl_disp_eng_notify_shall_stop(struct phl_info_t *phl);
93 
94 enum rtw_phl_status phl_disp_eng_set_msg_disp_seq(struct phl_info_t *phl,
95 							struct phl_msg_attribute *attr,
96 							struct msg_self_def_seq *seq);
97 u8 phl_disp_query_mdl_id(struct phl_info_t *phl, void *bk_mdl);
98 #ifdef CONFIG_CMD_DISP
99 /* following functions are only used inside phl_cmd_dispatch_eng.c */
100 enum rtw_phl_status dispr_init(struct phl_info_t *phl, void **dispr, u8 idx);
101 enum rtw_phl_status dispr_deinit(struct phl_info_t *phl, void *dispr);
102 enum rtw_phl_status dispr_start(void *dispr);
103 bool is_dispr_started(void *dispr);
104 enum rtw_phl_status dispr_stop(void *dispr);
105 enum rtw_phl_status dispr_register_module(void *dispr,
106 					  enum phl_module_id id,
107 					  struct phl_bk_module_ops *ops);
108 enum rtw_phl_status dispr_deregister_module(void *dispr,
109 					    enum phl_module_id id);
110 enum rtw_phl_status dispr_module_init(void *dispr);
111 enum rtw_phl_status dispr_module_deinit(void *dispr);
112 enum rtw_phl_status dispr_module_start(void *dispr);
113 enum rtw_phl_status dispr_module_stop(void *dispr);
114 enum rtw_phl_status dispr_get_cur_cmd_req(void *dispr, void **handle);
115 enum rtw_phl_status dispr_set_cur_cmd_info(void *dispr,
116 					       struct phl_module_op_info *op_info);
117 enum rtw_phl_status dispr_query_cur_cmd_info(void *dispr,
118 						 struct phl_module_op_info *op_info);
119 enum rtw_phl_status dispr_get_bk_module_handle(void *dispr,
120 						   enum phl_module_id id,
121 						   void **handle);
122 enum rtw_phl_status dispr_set_bk_module_info(void *dispr, void *handle,
123 						 struct phl_module_op_info *op_info);
124 enum rtw_phl_status dispr_query_bk_module_info(void *dispr, void *handle,
125 						   struct phl_module_op_info *op_info);
126 enum rtw_phl_status dispr_set_src_info(void *dispr, struct phl_msg *msg,
127 					   struct phl_module_op_info *op_info);
128 enum rtw_phl_status dispr_query_src_info(void *dispr, struct phl_msg *msg,
129 					     struct phl_module_op_info *op_info);
130 enum rtw_phl_status dispr_send_msg(void *dispr, struct phl_msg *msg,
131 				       struct phl_msg_attribute *attr, u32 *msg_hdl);
132 enum rtw_phl_status dispr_cancel_msg(void *dispr, u32 *msg_hdl);
133 enum rtw_phl_status dispr_clr_pending_msg(void *dispr);
134 
135 enum rtw_phl_status dispr_add_token_req(void *dispr,
136 					    struct phl_cmd_token_req *req, u32 *req_hdl);
137 enum rtw_phl_status dispr_cancel_token_req(void *dispr, u32 *req_hdl);
138 enum rtw_phl_status dispr_free_token(void *dispr, u32 *req_hdl);
139 enum rtw_phl_status dispr_notify_dev_io_status(void *dispr, enum phl_module_id mdl_id, bool allow_io);
140 void dispr_notify_shall_stop(void *dispr);
141 u8 dispr_is_fg_empty(void *dispr);
142 void dispr_share_thread_loop_hdl(void *dispr);
143 void dispr_share_thread_leave_hdl(void *dispr);
144 void dispr_share_thread_stop_prior_hdl(void *dispr);
145 void dispr_share_thread_stop_post_hdl(void *dispr);
146 
147 enum rtw_phl_status dispr_set_dispatch_seq(void *dispr, struct phl_msg_attribute *attr,
148 							struct msg_self_def_seq* seq);
149 
150 /*ollowing functions are called inside phl_cmd_dispatcher.c */
151 #define IS_DISPR_CTRL(_mdl_id) ((_mdl_id) < PHL_BK_MDL_ROLE_START)
152 #define disp_eng_is_solo_thread_mode(_phl) \
153 	((_phl)->disp_eng.thread_mode == SOLO_THREAD_MODE)
154 void disp_eng_notify_share_thread(struct phl_info_t *phl, void *dispr);
155 void dispr_ctrl_hook_ops(void *dispr, struct phl_bk_module_ops *ops);
156 u8 disp_query_mdl_id(struct phl_info_t *phl, void *bk_mdl);
157 #ifdef CONFIG_CMD_DISP_SOLO_MODE
158 void dispr_ctrl_sema_down(struct phl_info_t *phl);
159 void dispr_ctrl_sema_up(struct phl_info_t *phl);
160 #endif
161 #endif
162 #endif	/* __PHL_PHY_H_ */
163