xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/phl/hal_g6/hal_trx_mit.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_TRX_MIT_C_
16 #include "hal_headers.h"
17 
18 static void
_hal_trx_mit_timer_convert(u32 timer,u8 * mul_ptr,enum mac_ax_trx_mitigation_timer_unit * unit_ptr)19 _hal_trx_mit_timer_convert(u32 timer, u8 *mul_ptr,
20 			   enum mac_ax_trx_mitigation_timer_unit *unit_ptr)
21 {
22 	/* timer = mul * unit */
23 
24 	const enum mac_ax_trx_mitigation_timer_unit UNIT_ARR[] = {
25 	    MAC_AX_MIT_64US, MAC_AX_MIT_128US, MAC_AX_MIT_256US,
26 	    MAC_AX_MIT_512US};
27 	const u8 UNIT_EXP_ARR[] = {6, 7, 8, 9}; /* 2^exp = unit */
28 	const u8 UNIT_ARR_LEN = 4;
29 
30 	const u8 MUL_MAX = 0xff; /* 8 bits for mul */
31 
32 	u32 timer_ = 0;
33 	u8 idx;
34 
35 	for (idx = 0; idx < UNIT_ARR_LEN; idx++) {
36 
37 		timer_ = timer >> UNIT_EXP_ARR[idx];
38 
39 		if (timer_ <= MUL_MAX)
40 			break;
41 	}
42 
43 	if (timer_ > MUL_MAX)
44 		*mul_ptr = MUL_MAX;
45 	else
46 		*mul_ptr = (u8)timer_;
47 
48 	if (idx < UNIT_ARR_LEN)
49 		*unit_ptr = UNIT_ARR[idx];
50 	else
51 		*unit_ptr = UNIT_ARR[UNIT_ARR_LEN - 1];
52 }
53 
rtw_hal_pcie_trx_mit(void * hal,u32 tx_timer,u8 tx_counter,u32 rx_timer,u8 rx_counter)54 enum rtw_hal_status rtw_hal_pcie_trx_mit(void *hal, u32 tx_timer, u8 tx_counter,
55 					 u32 rx_timer, u8 rx_counter)
56 {
57 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
58 
59 	struct mac_ax_pcie_trx_mitigation mit_info;
60 	struct mac_ax_txdma_ch_map txch_map;
61 	struct mac_ax_rxdma_ch_map rxch_map;
62 
63 	/* tx */
64 
65 	txch_map.ch0 = MAC_AX_PCIE_DISABLE;
66 	txch_map.ch1 = MAC_AX_PCIE_DISABLE;
67 	txch_map.ch2 = MAC_AX_PCIE_DISABLE;
68 	txch_map.ch3 = MAC_AX_PCIE_DISABLE;
69 	txch_map.ch4 = MAC_AX_PCIE_DISABLE;
70 	txch_map.ch5 = MAC_AX_PCIE_DISABLE;
71 	txch_map.ch6 = MAC_AX_PCIE_DISABLE;
72 	txch_map.ch7 = MAC_AX_PCIE_DISABLE;
73 	txch_map.ch8 = MAC_AX_PCIE_DISABLE;
74 	txch_map.ch9 = MAC_AX_PCIE_DISABLE;
75 	txch_map.ch10 = MAC_AX_PCIE_DISABLE;
76 	txch_map.ch11 = MAC_AX_PCIE_DISABLE;
77 	txch_map.ch12 = MAC_AX_PCIE_DISABLE;
78 
79 	mit_info.txch_map = &txch_map;
80 	mit_info.tx_counter = tx_counter;
81 
82 	_hal_trx_mit_timer_convert(tx_timer, &(mit_info.tx_timer),
83 				   &(mit_info.tx_timer_unit));
84 
85 	PHL_INFO(
86 	    "%s :: mit_info.tx_timer == %d, mit_info.tx_timer_unit == %d\n",
87 	    __func__, mit_info.tx_timer, mit_info.tx_timer_unit);
88 
89 	/* tx - END */
90 
91 	/* rx */
92 
93 	rxch_map.rxq = MAC_AX_PCIE_ENABLE;
94 	rxch_map.rpq = MAC_AX_PCIE_ENABLE;
95 
96 	mit_info.rxch_map = &rxch_map;
97 	mit_info.rx_counter = rx_counter;
98 
99 	_hal_trx_mit_timer_convert(rx_timer, &(mit_info.rx_timer),
100 				   &(mit_info.rx_timer_unit));
101 
102 	PHL_INFO(
103 	    "%s :: mit_info.rx_timer == %d, mit_info.rx_timer_unit == %d\n",
104 	    __func__, mit_info.rx_timer, mit_info.rx_timer_unit);
105 
106 	/* rx - END */
107 
108 	if (rtw_hal_mac_pcie_trx_mit(hal_info, &mit_info) !=
109 	    RTW_HAL_STATUS_SUCCESS) {
110 
111 		PHL_INFO(
112 		    "%s :: failed to config pcie trx interrupt mitigation\n",
113 		    __func__);
114 		return RTW_HAL_STATUS_FAILURE;
115 	}
116 
117 	return RTW_HAL_STATUS_SUCCESS;
118 }
119