xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/phl/hal_g6/hal_chan_info.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 _HAL_CHAN_INFO_C_
16 #include "hal_headers.h"
17 
18 #ifdef CONFIG_PHL_CHANNEL_INFO
19 
20 enum rtw_hal_status
rtw_hal_cfg_chinfo(void * hal,struct rtw_phl_stainfo_t * sta,u8 enable)21 rtw_hal_cfg_chinfo(void *hal, struct rtw_phl_stainfo_t *sta, u8 enable)
22 {
23 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
24 	struct chinfo_bbcr_cfg bbcr = {0};
25 	u8 mode = 0, filter = 0, sg_size = 0;
26 	enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
27 	u8 macid = (u8)sta->macid;
28 	/*
29 	 *TODO: Discuss how to config accroding to different mode.
30 	 *	Currently, macid, mode, filter, sg_size use default value,
31 	 *	which is hard code in rtw_hal_mac_chan_info_cfg.
32 	 */
33 	hal_status = rtw_hal_mac_chan_info_cfg(hal_info, enable, macid, mode, filter, sg_size);
34 	if (hal_status == RTW_HAL_STATUS_SUCCESS) {
35 		if (enable) {
36 			/*
37 			 *Below is Example code for BBCR set to Legacy channel 80MHz
38 			 *TODO 1: need to calculate channel raw data size to see if
39 			 *	it is acceptable.
40 			 *TODO 2: there should be 10 sets of pre-defined configuration for BBCR.
41 			 *	need to decide which CR to use.
42 			 */
43 			bbcr.ch_i_phy0_en =1;
44 			bbcr.ch_i_phy1_en = 0;
45 			bbcr.ch_i_grp_num_he = 1;
46 			bbcr.ch_i_grp_num_non_he = 1;
47 			bbcr.ch_i_data_src = 0; /*LS, channel estimation*/
48 			bbcr.ch_i_cmprs = 0; /*8 bits*/
49 			bbcr.ch_i_ele_bitmap = 0x101;
50 			bbcr.ch_i_blk_start_idx = 1;
51 			bbcr.ch_i_blk_end_idx = 10;
52 			bbcr.ch_i_type = 0; /* legacy channel*/
53 			bbcr.ch_i_seg_len = 0; /*12*/
54 			rtw_hal_bb_chan_info_cfg(hal_info, &bbcr);
55 		}
56 	}
57 
58 	return hal_status;
59 }
60 
61 void
_hal_fill_csi_header_remain(void * hal,struct csi_header_t * csi_header,struct rtw_r_meta_data * mdata)62 _hal_fill_csi_header_remain(void* hal, struct csi_header_t *csi_header
63 	, struct rtw_r_meta_data *mdata)
64 {
65 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
66 	struct rtw_hal_com_t *h = hal_info->hal_com;
67 
68 	/* from mdata */
69 	csi_header->hw_assigned_timestamp = mdata->freerun_cnt;
70 	csi_header->rx_data_rate = mdata->rx_rate;
71 	csi_header->bandwidth = mdata->bw;
72 	csi_header->ch_matrix_report = mdata->get_ch_info;
73 	/* TODO: from drv define, get value from other side.*/
74 	csi_header->channel = 0;
75 	csi_header->num_sub_carrier = 0;
76 	csi_header->num_bit_per_tone = 0;
77 	/* Others: mac addres not from TA ? */
78 	/* hal_mem_cpy(h, &(csi_header->mac_addr[0]), &(mdata->ta[0]), MAC_ALEN); */
79 }
80 
81 void
_hal_fill_csi_header_phy_info(void * hal,struct csi_header_t * csi_header,struct ch_rpt_hdr_info * ch_hdr_rpt,struct phy_info_rpt * phy_info)82 _hal_fill_csi_header_phy_info(void* hal, struct csi_header_t *csi_header
83 	, struct ch_rpt_hdr_info *ch_hdr_rpt, struct phy_info_rpt *phy_info)
84 {
85 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
86 	struct rtw_hal_com_t *h = hal_info->hal_com;
87 
88 	/* Initialize csi header */
89 	hal_mem_set(h, csi_header, 0, sizeof(struct csi_header_t));
90 	/* from phy_info_rpt */
91 	hal_mem_cpy(h, &(csi_header->rssi[0]), &(phy_info->rssi[0]), 2);
92 	csi_header->rxsc = phy_info->rxsc;
93 	/* from ch_rpt_hdr_info */
94 	csi_header->nc = ch_hdr_rpt->n_rx;
95 	csi_header->nr = ch_hdr_rpt->n_sts;
96 	csi_header->avg_idle_noise_pwr = ch_hdr_rpt->avg_noise_pow;
97 	csi_header->csi_data_length = (ch_hdr_rpt->total_len_l <<16 | ch_hdr_rpt->total_len_m)
98 		- 16; /* header(8byte) + Phy_info_in_seg_0(8byte) */
99 	csi_header->csi_valid = ch_hdr_rpt->set_valid;
100 	hal_mem_cpy(h, &(csi_header->evm[0]), &(ch_hdr_rpt->evm[0]), 2);
101 }
102 
103 #endif /* CONFIG_PHL_CHANNEL_INFO */