1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5  *
6  ******************************************************************************/
7 
8 #ifndef _RTW_IO_H_
9 #define _RTW_IO_H_
10 
11 /*
12 	For prompt mode accessing, caller shall free io_req
13 	Otherwise, io_handler will free io_req
14 */
15 
16 /* below is for the intf_option bit definition... */
17 
18 struct intf_priv;
19 struct intf_hdl;
20 struct io_queue;
21 
22 struct _io_ops {
23 		u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr);
24 		u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr);
25 		u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr);
26 
27 		int (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
28 		int (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
29 		int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
30 		int (*_writeN)(struct intf_hdl *pintfhdl, u32 addr, u32 length, u8 *pdata);
31 
32 		int (*_write8_async)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
33 		int (*_write16_async)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
34 		int (*_write32_async)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
35 
36 		void (*_read_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
37 		void (*_write_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
38 
39 		void (*_sync_irp_protocol_rw)(struct io_queue *pio_q);
40 
41 		u32 (*_read_interrupt)(struct intf_hdl *pintfhdl, u32 addr);
42 
43 		u32 (*_read_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
44 		u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
45 
46 		u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
47 
48 		void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
49 		void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50 };
51 
52 struct io_req {
53 	struct list_head	list;
54 	u32 addr;
55 	volatile u32 val;
56 	u32 command;
57 	u32 status;
58 	u8 *pbuf;
59 
60 	void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt);
61 	u8 *cnxt;
62 };
63 
64 struct	intf_hdl {
65 	struct adapter *padapter;
66 	struct dvobj_priv *pintf_dev;/* 	pointer to &(padapter->dvobjpriv); */
67 
68 	struct _io_ops	io_ops;
69 };
70 
71 #define SD_IO_TRY_CNT (8)
72 #define MAX_CONTINUAL_IO_ERR SD_IO_TRY_CNT
73 
74 int rtw_inc_and_chk_continual_io_error(struct dvobj_priv *dvobj);
75 void rtw_reset_continual_io_error(struct dvobj_priv *dvobj);
76 
77 /*
78 Below is the data structure used by _io_handler
79 
80 */
81 
82 struct io_queue {
83 	spinlock_t	lock;
84 	struct list_head	free_ioreqs;
85 	struct list_head		pending;		/* The io_req list that will be served in the single protocol read/write. */
86 	struct list_head		processing;
87 	u8 *free_ioreqs_buf; /*  4-byte aligned */
88 	u8 *pallocated_free_ioreqs_buf;
89 	struct	intf_hdl	intf;
90 };
91 
92 struct io_priv {
93 
94 	struct adapter *padapter;
95 
96 	struct intf_hdl intf;
97 
98 };
99 
100 extern uint ioreq_flush(struct adapter *adapter, struct io_queue *ioqueue);
101 extern void sync_ioreq_enqueue(struct io_req *preq, struct io_queue *ioqueue);
102 extern uint sync_ioreq_flush(struct adapter *adapter, struct io_queue *ioqueue);
103 
104 
105 extern uint free_ioreq(struct io_req *preq, struct io_queue *pio_queue);
106 extern struct io_req *alloc_ioreq(struct io_queue *pio_q);
107 
108 extern uint register_intf_hdl(u8 *dev, struct intf_hdl *pintfhdl);
109 extern void unregister_intf_hdl(struct intf_hdl *pintfhdl);
110 
111 extern void _rtw_attrib_read(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
112 extern void _rtw_attrib_write(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
113 
114 extern u8 rtw_read8(struct adapter *adapter, u32 addr);
115 extern u16 rtw_read16(struct adapter *adapter, u32 addr);
116 extern u32 rtw_read32(struct adapter *adapter, u32 addr);
117 
118 extern int rtw_write8(struct adapter *adapter, u32 addr, u8 val);
119 extern int rtw_write16(struct adapter *adapter, u32 addr, u16 val);
120 extern int rtw_write32(struct adapter *adapter, u32 addr, u32 val);
121 
122 extern u32 rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
123 
124 extern void rtw_write_scsi(struct adapter *adapter, u32 cnt, u8 *pmem);
125 
126 /* ioreq */
127 extern void ioreq_read8(struct adapter *adapter, u32 addr, u8 *pval);
128 extern void ioreq_read16(struct adapter *adapter, u32 addr, u16 *pval);
129 extern void ioreq_read32(struct adapter *adapter, u32 addr, u32 *pval);
130 extern void ioreq_write8(struct adapter *adapter, u32 addr, u8 val);
131 extern void ioreq_write16(struct adapter *adapter, u32 addr, u16 val);
132 extern void ioreq_write32(struct adapter *adapter, u32 addr, u32 val);
133 
134 
135 extern uint async_read8(struct adapter *adapter, u32 addr, u8 *pbuff,
136 	void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
137 extern uint async_read16(struct adapter *adapter, u32 addr,  u8 *pbuff,
138 	void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
139 extern uint async_read32(struct adapter *adapter, u32 addr,  u8 *pbuff,
140 	void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
141 
142 extern void async_read_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
143 extern void async_read_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
144 
145 extern void async_write8(struct adapter *adapter, u32 addr, u8 val,
146 	void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
147 extern void async_write16(struct adapter *adapter, u32 addr, u16 val,
148 	void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
149 extern void async_write32(struct adapter *adapter, u32 addr, u32 val,
150 	void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
151 
152 extern void async_write_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
153 extern void async_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
154 
155 
156 int rtw_init_io_priv(struct adapter *padapter, void (*set_intf_ops)(struct adapter *padapter, struct _io_ops *pops));
157 
158 
159 extern uint alloc_io_queue(struct adapter *adapter);
160 extern void free_io_queue(struct adapter *adapter);
161 extern void async_bus_io(struct io_queue *pio_q);
162 extern void bus_sync_io(struct io_queue *pio_q);
163 extern u32 _ioreq2rwmem(struct io_queue *pio_q);
164 extern void dev_power_down(struct adapter *Adapter, u8 bpwrup);
165 
166 #endif	/* _RTL8711_IO_H_ */
167