xref: /linux/drivers/staging/rtl8723bs/hal/hal_sdio.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5  *
6  ******************************************************************************/
7 
8 #include <drv_types.h>
9 #include <hal_data.h>
10 
rtw_hal_sdio_max_txoqt_free_space(struct adapter * padapter)11 u8 rtw_hal_sdio_max_txoqt_free_space(struct adapter *padapter)
12 {
13 	struct hal_com_data	*pHalData = GET_HAL_DATA(padapter);
14 
15 	if (pHalData->SdioTxOQTMaxFreeSpace < 8)
16 		pHalData->SdioTxOQTMaxFreeSpace = 8;
17 
18 	return pHalData->SdioTxOQTMaxFreeSpace;
19 }
20 
rtw_hal_sdio_query_tx_freepage(struct adapter * padapter,u8 PageIdx,u8 RequiredPageNum)21 u8 rtw_hal_sdio_query_tx_freepage(
22 	struct adapter *padapter, u8 PageIdx, u8 RequiredPageNum
23 )
24 {
25 	struct hal_com_data	*pHalData = GET_HAL_DATA(padapter);
26 
27 	if ((pHalData->SdioTxFIFOFreePage[PageIdx]+pHalData->SdioTxFIFOFreePage[PUBLIC_QUEUE_IDX]) >= (RequiredPageNum))
28 		return true;
29 	else
30 		return false;
31 }
32 
rtw_hal_sdio_update_tx_freepage(struct adapter * padapter,u8 PageIdx,u8 RequiredPageNum)33 void rtw_hal_sdio_update_tx_freepage(
34 	struct adapter *padapter, u8 PageIdx, u8 RequiredPageNum
35 )
36 {
37 	struct hal_com_data	*pHalData = GET_HAL_DATA(padapter);
38 	u8 DedicatedPgNum = 0;
39 	u8 RequiredPublicFreePgNum = 0;
40 	/* _irqL irql; */
41 
42 	/* spin_lock_bh(&pHalData->SdioTxFIFOFreePageLock); */
43 
44 	DedicatedPgNum = pHalData->SdioTxFIFOFreePage[PageIdx];
45 	if (RequiredPageNum <= DedicatedPgNum) {
46 		pHalData->SdioTxFIFOFreePage[PageIdx] -= RequiredPageNum;
47 	} else {
48 		pHalData->SdioTxFIFOFreePage[PageIdx] = 0;
49 		RequiredPublicFreePgNum = RequiredPageNum - DedicatedPgNum;
50 		pHalData->SdioTxFIFOFreePage[PUBLIC_QUEUE_IDX] -= RequiredPublicFreePgNum;
51 	}
52 
53 	/* spin_unlock_bh(&pHalData->SdioTxFIFOFreePageLock); */
54 }
55 
rtw_hal_set_sdio_tx_max_length(struct adapter * padapter,u8 numHQ,u8 numNQ,u8 numLQ,u8 numPubQ)56 void rtw_hal_set_sdio_tx_max_length(
57 	struct adapter *padapter, u8 numHQ, u8 numNQ, u8 numLQ, u8 numPubQ
58 )
59 {
60 	struct hal_com_data	*pHalData = GET_HAL_DATA(padapter);
61 	u32 page_size;
62 	u32 lenHQ, lenNQ, lenLQ;
63 
64 	rtw_hal_get_def_var(padapter, HAL_DEF_TX_PAGE_SIZE, &page_size);
65 
66 	lenHQ = ((numHQ + numPubQ) >> 1) * page_size;
67 	lenNQ = ((numNQ + numPubQ) >> 1) * page_size;
68 	lenLQ = ((numLQ + numPubQ) >> 1) * page_size;
69 
70 	pHalData->sdio_tx_max_len[HI_QUEUE_IDX] =
71 		(lenHQ > MAX_XMITBUF_SZ) ? MAX_XMITBUF_SZ : lenHQ;
72 	pHalData->sdio_tx_max_len[MID_QUEUE_IDX] =
73 		(lenNQ > MAX_XMITBUF_SZ) ? MAX_XMITBUF_SZ : lenNQ;
74 	pHalData->sdio_tx_max_len[LOW_QUEUE_IDX] =
75 		(lenLQ > MAX_XMITBUF_SZ) ? MAX_XMITBUF_SZ : lenLQ;
76 }
77 
rtw_hal_get_sdio_tx_max_length(struct adapter * padapter,u8 queue_idx)78 u32 rtw_hal_get_sdio_tx_max_length(struct adapter *padapter, u8 queue_idx)
79 {
80 	struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
81 	struct hal_com_data	*pHalData = GET_HAL_DATA(padapter);
82 	u32 deviceId, max_len;
83 
84 
85 	deviceId = ffaddr2deviceId(pdvobjpriv, queue_idx);
86 	switch (deviceId) {
87 	case WLAN_TX_HIQ_DEVICE_ID:
88 		max_len = pHalData->sdio_tx_max_len[HI_QUEUE_IDX];
89 		break;
90 
91 	case WLAN_TX_MIQ_DEVICE_ID:
92 		max_len = pHalData->sdio_tx_max_len[MID_QUEUE_IDX];
93 		break;
94 
95 	case WLAN_TX_LOQ_DEVICE_ID:
96 		max_len = pHalData->sdio_tx_max_len[LOW_QUEUE_IDX];
97 		break;
98 
99 	default:
100 		max_len = pHalData->sdio_tx_max_len[MID_QUEUE_IDX];
101 		break;
102 	}
103 
104 	return max_len;
105 }
106