1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
9 The purpose of rtw_io.c
13 b. provides the protocol engine
15 c. provides the software interface between caller and the hardware interface
21 a. USE_SYNC_IRP: Only sync operations are provided.
22 b. USE_ASYNC_IRP:Both sync/async operations are provided.
24 jackson@realtek.com.tw
28 #include <drv_types.h>
29 #include <rtw_debug.h>
31 #define rtw_le16_to_cpu(val) val
32 #define rtw_le32_to_cpu(val) val
33 #define rtw_cpu_to_le16(val) val
34 #define rtw_cpu_to_le32(val) val
36 u8 rtw_read8(struct adapter *adapter, u32 addr)
38 /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
39 struct io_priv *pio_priv = &adapter->iopriv;
40 struct intf_hdl *pintfhdl = &(pio_priv->intf);
41 u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr);
43 _read8 = pintfhdl->io_ops._read8;
45 return _read8(pintfhdl, addr);
48 u16 rtw_read16(struct adapter *adapter, u32 addr)
51 /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
52 struct io_priv *pio_priv = &adapter->iopriv;
53 struct intf_hdl *pintfhdl = &(pio_priv->intf);
54 u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr);
56 _read16 = pintfhdl->io_ops._read16;
58 r_val = _read16(pintfhdl, addr);
59 return rtw_le16_to_cpu(r_val);
62 u32 rtw_read32(struct adapter *adapter, u32 addr)
65 /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
66 struct io_priv *pio_priv = &adapter->iopriv;
67 struct intf_hdl *pintfhdl = &(pio_priv->intf);
68 u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr);
70 _read32 = pintfhdl->io_ops._read32;
72 r_val = _read32(pintfhdl, addr);
73 return rtw_le32_to_cpu(r_val);
77 int rtw_write8(struct adapter *adapter, u32 addr, u8 val)
79 /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
80 struct io_priv *pio_priv = &adapter->iopriv;
81 struct intf_hdl *pintfhdl = &(pio_priv->intf);
82 int (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
85 _write8 = pintfhdl->io_ops._write8;
87 ret = _write8(pintfhdl, addr, val);
89 return RTW_STATUS_CODE(ret);
91 int rtw_write16(struct adapter *adapter, u32 addr, u16 val)
93 /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
94 struct io_priv *pio_priv = &adapter->iopriv;
95 struct intf_hdl *pintfhdl = &(pio_priv->intf);
96 int (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
99 _write16 = pintfhdl->io_ops._write16;
101 ret = _write16(pintfhdl, addr, val);
102 return RTW_STATUS_CODE(ret);
104 int rtw_write32(struct adapter *adapter, u32 addr, u32 val)
106 /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
107 struct io_priv *pio_priv = &adapter->iopriv;
108 struct intf_hdl *pintfhdl = &(pio_priv->intf);
109 int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
112 _write32 = pintfhdl->io_ops._write32;
114 ret = _write32(pintfhdl, addr, val);
116 return RTW_STATUS_CODE(ret);
119 u32 rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
121 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
122 struct io_priv *pio_priv = &adapter->iopriv;
123 struct intf_hdl *pintfhdl = &(pio_priv->intf);
125 _write_port = pintfhdl->io_ops._write_port;
127 return _write_port(pintfhdl, addr, cnt, pmem);
130 int rtw_init_io_priv(struct adapter *padapter, void (*set_intf_ops)(struct adapter *padapter, struct _io_ops *pops))
132 struct io_priv *piopriv = &padapter->iopriv;
133 struct intf_hdl *pintf = &piopriv->intf;
138 piopriv->padapter = padapter;
139 pintf->padapter = padapter;
140 pintf->pintf_dev = adapter_to_dvobj(padapter);
142 set_intf_ops(padapter, &pintf->io_ops);
148 * Increase and check if the continual_io_error of this @param dvobjprive is larger than MAX_CONTINUAL_IO_ERR
152 int rtw_inc_and_chk_continual_io_error(struct dvobj_priv *dvobj)
155 int value = atomic_inc_return(&dvobj->continual_io_error);
156 if (value > MAX_CONTINUAL_IO_ERR)
163 * Set the continual_io_error of this @param dvobjprive to 0
165 void rtw_reset_continual_io_error(struct dvobj_priv *dvobj)
167 atomic_set(&dvobj->continual_io_error, 0);