1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5  *
6  ******************************************************************************/
7 /*
8 
9 The purpose of rtw_io.c
10 
11 a. provides the API
12 
13 b. provides the protocol engine
14 
15 c. provides the software interface between caller and the hardware interface
16 
17 
18 Compiler Flag Option:
19 
20 1. CONFIG_SDIO_HCI:
21     a. USE_SYNC_IRP:  Only sync operations are provided.
22     b. USE_ASYNC_IRP:Both sync/async operations are provided.
23 
24 jackson@realtek.com.tw
25 
26 */
27 
28 #include <drv_types.h>
29 
rtw_read8(struct adapter * adapter,u32 addr)30 u8 rtw_read8(struct adapter *adapter, u32 addr)
31 {
32 	/* struct	io_queue	*pio_queue = (struct io_queue *)adapter->pio_queue; */
33 	struct io_priv *pio_priv = &adapter->iopriv;
34 	struct	intf_hdl		*pintfhdl = &(pio_priv->intf);
35 	u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr);
36 
37 	_read8 = pintfhdl->io_ops._read8;
38 
39 	return _read8(pintfhdl, addr);
40 }
41 
rtw_read16(struct adapter * adapter,u32 addr)42 u16 rtw_read16(struct adapter *adapter, u32 addr)
43 {
44 	/* struct	io_queue	*pio_queue = (struct io_queue *)adapter->pio_queue; */
45 	struct io_priv *pio_priv = &adapter->iopriv;
46 	struct	intf_hdl		*pintfhdl = &(pio_priv->intf);
47 	u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr);
48 
49 	_read16 = pintfhdl->io_ops._read16;
50 
51 	return _read16(pintfhdl, addr);
52 }
53 
rtw_read32(struct adapter * adapter,u32 addr)54 u32 rtw_read32(struct adapter *adapter, u32 addr)
55 {
56 	/* struct	io_queue	*pio_queue = (struct io_queue *)adapter->pio_queue; */
57 	struct io_priv *pio_priv = &adapter->iopriv;
58 	struct	intf_hdl		*pintfhdl = &(pio_priv->intf);
59 	u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr);
60 
61 	_read32 = pintfhdl->io_ops._read32;
62 
63 	return _read32(pintfhdl, addr);
64 
65 }
66 
rtw_write8(struct adapter * adapter,u32 addr,u8 val)67 int rtw_write8(struct adapter *adapter, u32 addr, u8 val)
68 {
69 	/* struct	io_queue	*pio_queue = (struct io_queue *)adapter->pio_queue; */
70 	struct io_priv *pio_priv = &adapter->iopriv;
71 	struct	intf_hdl		*pintfhdl = &(pio_priv->intf);
72 	int (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
73 	int ret;
74 
75 	_write8 = pintfhdl->io_ops._write8;
76 
77 	ret = _write8(pintfhdl, addr, val);
78 
79 	return RTW_STATUS_CODE(ret);
80 }
rtw_write16(struct adapter * adapter,u32 addr,u16 val)81 int rtw_write16(struct adapter *adapter, u32 addr, u16 val)
82 {
83 	/* struct	io_queue	*pio_queue = (struct io_queue *)adapter->pio_queue; */
84 	struct io_priv *pio_priv = &adapter->iopriv;
85 	struct	intf_hdl		*pintfhdl = &(pio_priv->intf);
86 	int (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
87 	int ret;
88 
89 	_write16 = pintfhdl->io_ops._write16;
90 
91 	ret = _write16(pintfhdl, addr, val);
92 	return RTW_STATUS_CODE(ret);
93 }
rtw_write32(struct adapter * adapter,u32 addr,u32 val)94 int rtw_write32(struct adapter *adapter, u32 addr, u32 val)
95 {
96 	/* struct	io_queue	*pio_queue = (struct io_queue *)adapter->pio_queue; */
97 	struct io_priv *pio_priv = &adapter->iopriv;
98 	struct	intf_hdl		*pintfhdl = &(pio_priv->intf);
99 	int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
100 	int ret;
101 
102 	_write32 = pintfhdl->io_ops._write32;
103 
104 	ret = _write32(pintfhdl, addr, val);
105 
106 	return RTW_STATUS_CODE(ret);
107 }
108 
rtw_write_port(struct adapter * adapter,u32 addr,u32 cnt,u8 * pmem)109 u32 rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
110 {
111 	u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
112 	struct io_priv *pio_priv = &adapter->iopriv;
113 	struct	intf_hdl		*pintfhdl = &(pio_priv->intf);
114 
115 	_write_port = pintfhdl->io_ops._write_port;
116 
117 	return _write_port(pintfhdl, addr, cnt, pmem);
118 }
119 
rtw_init_io_priv(struct adapter * padapter,void (* set_intf_ops)(struct adapter * padapter,struct _io_ops * pops))120 int rtw_init_io_priv(struct adapter *padapter, void (*set_intf_ops)(struct adapter *padapter, struct _io_ops *pops))
121 {
122 	struct io_priv *piopriv = &padapter->iopriv;
123 	struct intf_hdl *pintf = &piopriv->intf;
124 
125 	if (!set_intf_ops)
126 		return _FAIL;
127 
128 	piopriv->padapter = padapter;
129 	pintf->padapter = padapter;
130 	pintf->pintf_dev = adapter_to_dvobj(padapter);
131 
132 	set_intf_ops(padapter, &pintf->io_ops);
133 
134 	return _SUCCESS;
135 }
136 
137 /*
138 * Increase and check if the continual_io_error of this @param dvobjprive is larger than MAX_CONTINUAL_IO_ERR
139 * @return true:
140 * @return false:
141 */
rtw_inc_and_chk_continual_io_error(struct dvobj_priv * dvobj)142 int rtw_inc_and_chk_continual_io_error(struct dvobj_priv *dvobj)
143 {
144 	int ret = false;
145 	int value = atomic_inc_return(&dvobj->continual_io_error);
146 	if (value > MAX_CONTINUAL_IO_ERR)
147 		ret = true;
148 
149 	return ret;
150 }
151 
152 /*
153 * Set the continual_io_error of this @param dvobjprive to 0
154 */
rtw_reset_continual_io_error(struct dvobj_priv * dvobj)155 void rtw_reset_continual_io_error(struct dvobj_priv *dvobj)
156 {
157 	atomic_set(&dvobj->continual_io_error, 0);
158 }
159