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