xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852bs/phl/phl_api_drv.c (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 #define _PHL_API_DRV_C_
16 #include "phl_headers.h"
17 
rtw_phl_get_txbd_buf(struct rtw_phl_com_t * phl_com)18 void *rtw_phl_get_txbd_buf(struct rtw_phl_com_t *phl_com)
19 {
20 	struct phl_info_t *phl_info = (struct phl_info_t *)phl_com->phl_priv;
21 
22 	return phl_info->hci_trx_ops->get_txbd_buf(phl_info);
23 }
24 
rtw_phl_get_rxbd_buf(struct rtw_phl_com_t * phl_com)25 void *rtw_phl_get_rxbd_buf(struct rtw_phl_com_t *phl_com)
26 {
27 	struct phl_info_t *phl_info = (struct phl_info_t *)phl_com->phl_priv;
28 
29 	return phl_info->hci_trx_ops->get_rxbd_buf(phl_info);
30 }
31 
rtw_phl_query_h2c_pkt(struct rtw_phl_com_t * phl_com,enum rtw_h2c_pkt_type type)32 struct rtw_h2c_pkt *rtw_phl_query_h2c_pkt(struct rtw_phl_com_t *phl_com,
33 											enum rtw_h2c_pkt_type type)
34 {
35 	struct rtw_h2c_pkt *h2c_pkt = NULL;
36 	struct phl_info_t *phl_info = (struct phl_info_t *)phl_com->phl_priv;
37 
38 	h2c_pkt = (struct rtw_h2c_pkt *)phl_query_idle_h2c_pkt(phl_info, type);
39 
40 	if (!h2c_pkt)
41 		phl_dump_h2c_pool_stats(phl_info->h2c_pool);
42 
43 	return h2c_pkt;
44 }
45 
rtw_phl_pltfm_tx(struct rtw_phl_com_t * phl_com,struct rtw_h2c_pkt * pkt)46 enum rtw_phl_status rtw_phl_pltfm_tx(struct rtw_phl_com_t *phl_com,
47 										struct rtw_h2c_pkt *pkt)
48 {
49 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
50 	struct phl_info_t *phl_info = (struct phl_info_t *)phl_com->phl_priv;
51 
52 	#ifdef CONFIG_PCI_HCI
53 	struct phl_hci_trx_ops *hci_trx_ops = phl_info->hci_trx_ops;
54 	hci_trx_ops->recycle_busy_h2c(phl_info);
55 	#endif
56 
57 	pstatus = phl_info->hci_trx_ops->pltfm_tx(phl_info, pkt);
58 
59 	return pstatus;
60 }
61 
rtw_phl_proc_cmd(void * phl,char proc_cmd,struct rtw_proc_cmd * incmd,char * output,u32 out_len)62 void rtw_phl_proc_cmd(void *phl, char proc_cmd,
63 		      struct rtw_proc_cmd *incmd,
64 		      char *output, u32 out_len)
65 {
66 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
67 	struct hal_info_t *hal_info = (struct hal_info_t *)phl_info->hal;
68 
69 	if (RTW_PROC_CMD_PHL == proc_cmd)
70 		rtw_phl_dbg_proc_cmd(phl_info, incmd, output, out_len);
71 	else if (RTW_PROC_CMD_CORE == proc_cmd)
72 		rtw_phl_dbg_core_cmd(phl_info, incmd, output, out_len);
73 	else
74 		rtw_hal_proc_cmd(hal_info, proc_cmd, incmd, output, out_len);
75 }
76 
rtw_phl_get_fw_ver(void * phl,char * ver_str,u16 len)77 void rtw_phl_get_fw_ver(void *phl, char *ver_str, u16 len)
78 {
79 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
80 
81 	rtw_hal_get_fw_ver(phl_info->hal, ver_str, len);
82 }
83 
rtw_phl_get_fw_status(void * phl)84 enum rtw_fw_status rtw_phl_get_fw_status(void *phl)
85 {
86 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
87 
88 	return rtw_hal_get_fw_status(phl_info->hal);
89 }
90 
rtw_phl_msg_hub_hal_send(struct rtw_phl_com_t * phl_com,struct phl_msg_attribute * attr,struct phl_msg * msg)91 enum rtw_phl_status rtw_phl_msg_hub_hal_send(struct rtw_phl_com_t *phl_com,
92 							struct phl_msg_attribute* attr, struct phl_msg* msg)
93 {
94 	return phl_msg_hub_send((struct phl_info_t*)phl_com->phl_priv, attr, msg);
95 }
rtw_phl_test_txtb_cfg(struct rtw_phl_com_t * phl_com,void * buf,u32 buf_len,u8 * cfg_bssid,u16 cfg_aid,u8 cfg_bsscolor)96 void rtw_phl_test_txtb_cfg(struct rtw_phl_com_t* phl_com,
97 	void *buf, u32 buf_len, u8 *cfg_bssid, u16 cfg_aid, u8 cfg_bsscolor)
98 {
99 	/* Get parameters from MP UL */
100 	u8 ui_bssid[6]={0x00, 0x09, 0x08, 0x07, 0x06, 0x05};
101 	u16 ui_aid = 2;
102 	u8 ui_bsscolor = 1;
103 	u8 cfg;
104 	struct phl_info_t *phl_info = (struct phl_info_t *)phl_com->phl_priv;
105 	struct rtw_wifi_role_t *role = &phl_com->wifi_roles[0];
106 	struct rtw_phl_stainfo_t *sta = rtw_phl_get_stainfo_self(
107 		phl_com->phl_priv, role);
108 
109 	cfg = (u8)*((u8 *)buf);
110 	switch (cfg) {
111 		case 0:
112 			/* disable */
113 			role->mstate = MLME_NO_LINK;
114 			_os_mem_cpy(phlcom_to_drvpriv(phl_com), sta->mac_addr,
115 				role->mac_addr, MAC_ALEN);
116 			rtw_hal_update_sta_entry(phl_info->hal, sta, false);
117 			rtw_hal_role_cfg(phl_info->hal, role);
118 		break;
119 
120 		case 1:
121 			role->mstate = MLME_LINKED;
122 			_os_mem_cpy(phlcom_to_drvpriv(phl_com), sta->mac_addr,
123 				cfg_bssid, MAC_ALEN);
124 			sta->wmode = WLAN_MD_MAX;
125 			sta->aid = cfg_aid;
126 			sta->asoc_cap.bsscolor = cfg_bsscolor;
127 			sta->asoc_cap.pkt_padding = 2;
128 			rtw_hal_update_sta_entry(phl_info->hal, sta, false);
129 			rtw_hal_role_cfg(phl_info->hal, role);
130 		break;
131 
132 		case 2:
133 			role->mstate = MLME_LINKED;
134 			_os_mem_cpy(phlcom_to_drvpriv(phl_com), sta->mac_addr,
135 				ui_bssid, MAC_ALEN);
136 			sta->wmode = WLAN_MD_MAX;
137 			sta->aid = ui_aid;
138 			sta->asoc_cap.bsscolor = ui_bsscolor;
139 			sta->asoc_cap.pkt_padding = 2;
140 			rtw_hal_update_sta_entry(phl_info->hal, sta, false);
141 			rtw_hal_role_cfg(phl_info->hal, role);
142 		break;		default:
143 		break;
144 	}
145 }
146 
rtw_phl_pkt_ofld_reset_all_entry(struct rtw_phl_com_t * phl_com)147 void rtw_phl_pkt_ofld_reset_all_entry(struct rtw_phl_com_t* phl_com)
148 {
149 	struct phl_info_t *phl_info = (struct phl_info_t *)phl_com->phl_priv;
150 
151 	phl_pkt_ofld_reset_all_entry(phl_info);
152 }
153 
rtw_phl_dbg_dump_rx(void * phl,struct rtw_wifi_role_t * wrole)154 void rtw_phl_dbg_dump_rx(void *phl, struct rtw_wifi_role_t *wrole)
155 {
156 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
157 
158 	phl_rx_dbg_dump(phl_info, wrole->hw_band);
159 }
160 
rtw_phl_get_phy_stat_info(void * phl,enum phl_band_idx hw_band,enum phl_stat_info_query phy_stat)161 u32 rtw_phl_get_phy_stat_info(void *phl, enum phl_band_idx hw_band,
162 			      enum phl_stat_info_query phy_stat)
163 {
164 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
165 
166 	return rtw_hal_get_phy_stat_info(phl_info->hal, hw_band, phy_stat);
167 }