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