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