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