xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8821cs/hal/rtl8821c/sdio/rtl8821cs_halmac.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2016 - 2018 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 _RTL8821CS_HALMAC_C_
16 
17 #include <drv_types.h>		/* struct dvobj_priv and etc. */
18 #include <rtw_sdio.h>		/* rtw_sdio_write_cmd53() */
19 #include "../../hal_halmac.h"
20 #include "rtl8821cs_io.h"
21 
22 
sdio_write_data_rsvd_page(void * d,u8 * pBuf,u32 size)23 static u8 sdio_write_data_rsvd_page(void *d, u8 *pBuf, u32 size)
24 {
25 	struct halmac_adapter *halmac;
26 	struct halmac_api *api;
27 	u32 desclen, len;
28 	u8 *buf;
29 	u8 ret;
30 
31 
32 	halmac = dvobj_to_halmac((struct dvobj_priv *)d);
33 	api = HALMAC_GET_API(halmac);
34 
35 	rtw_halmac_get_tx_desc_size((struct dvobj_priv *)d, &desclen);
36 	len = desclen + size;
37 	buf = rtw_zmalloc(len);
38 	if (!buf)
39 		return 0;
40 	_rtw_memcpy(buf + desclen, pBuf, size);
41 
42 	SET_TX_DESC_TXPKTSIZE_8821C(buf, size);
43 	SET_TX_DESC_OFFSET_8821C(buf, desclen);
44 	SET_TX_DESC_QSEL_8821C(buf, HALMAC_TXDESC_QSEL_BEACON);
45 	api->halmac_fill_txdesc_checksum(halmac, buf);
46 
47 	ret = rtl8821cs_write_port(d, len, buf);
48 	if (_SUCCESS == ret)
49 		ret = 1;
50 	else
51 		ret = 0;
52 
53 	rtw_mfree(buf, len);
54 
55 	return ret;
56 }
57 
sdio_write_data_h2c(void * d,u8 * pBuf,u32 size)58 static u8 sdio_write_data_h2c(void *d, u8 *pBuf, u32 size)
59 {
60 	struct halmac_adapter *halmac;
61 	struct halmac_api *api;
62 	u32 addr, desclen, len;
63 	u8 *buf;
64 	u8 ret;
65 
66 
67 	halmac = dvobj_to_halmac((struct dvobj_priv *)d);
68 	api = HALMAC_GET_API(halmac);
69 
70 	rtw_halmac_get_tx_desc_size((struct dvobj_priv *)d, &desclen);
71 	len = desclen + size;
72 	buf = rtw_zmalloc(len);
73 	if (!buf)
74 		return 0;
75 	_rtw_memcpy(buf + desclen, pBuf, size);
76 
77 	SET_TX_DESC_TXPKTSIZE_8821C(buf, size);
78 	SET_TX_DESC_QSEL_8821C(buf, HALMAC_TXDESC_QSEL_H2C_CMD);
79 	api->halmac_fill_txdesc_checksum(halmac, buf);
80 
81 	ret = rtl8821cs_write_port(d, len, buf);
82 	if (_SUCCESS == ret)
83 		ret = 1;
84 	else
85 		ret = 0;
86 
87 	rtw_mfree(buf, len);
88 
89 	return ret;
90 }
91 
rtl8821cs_halmac_init_adapter(PADAPTER adapter)92 int rtl8821cs_halmac_init_adapter(PADAPTER adapter)
93 {
94 	struct dvobj_priv *d;
95 	struct halmac_platform_api *api;
96 	int err;
97 
98 
99 	d = adapter_to_dvobj(adapter);
100 	api = &rtw_halmac_platform_api;
101 	api->SEND_RSVD_PAGE = sdio_write_data_rsvd_page;
102 	api->SEND_H2C_PKT = sdio_write_data_h2c;
103 
104 	err = rtw_halmac_init_adapter(d, api);
105 
106 	return err;
107 }
108