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 #define NUM_IOREQ 8 12 13 #define MAX_PROT_SZ (64-16) 14 15 #define _IOREADY 0 16 #define _IO_WAIT_COMPLETE 1 17 #define _IO_WAIT_RSP 2 18 19 /* IO COMMAND TYPE */ 20 #define _IOSZ_MASK_ (0x7F) 21 #define _IO_WRITE_ BIT(7) 22 #define _IO_FIXED_ BIT(8) 23 #define _IO_BURST_ BIT(9) 24 #define _IO_BYTE_ BIT(10) 25 #define _IO_HW_ BIT(11) 26 #define _IO_WORD_ BIT(12) 27 #define _IO_SYNC_ BIT(13) 28 #define _IO_CMDMASK_ (0x1F80) 29 30 31 /* 32 For prompt mode accessing, caller shall free io_req 33 Otherwise, io_handler will free io_req 34 */ 35 36 37 38 /* IO STATUS TYPE */ 39 #define _IO_ERR_ BIT(2) 40 #define _IO_SUCCESS_ BIT(1) 41 #define _IO_DONE_ BIT(0) 42 43 44 #define IO_RD32 (_IO_SYNC_ | _IO_WORD_) 45 #define IO_RD16 (_IO_SYNC_ | _IO_HW_) 46 #define IO_RD8 (_IO_SYNC_ | _IO_BYTE_) 47 48 #define IO_RD32_ASYNC (_IO_WORD_) 49 #define IO_RD16_ASYNC (_IO_HW_) 50 #define IO_RD8_ASYNC (_IO_BYTE_) 51 52 #define IO_WR32 (_IO_WRITE_ | _IO_SYNC_ | _IO_WORD_) 53 #define IO_WR16 (_IO_WRITE_ | _IO_SYNC_ | _IO_HW_) 54 #define IO_WR8 (_IO_WRITE_ | _IO_SYNC_ | _IO_BYTE_) 55 56 #define IO_WR32_ASYNC (_IO_WRITE_ | _IO_WORD_) 57 #define IO_WR16_ASYNC (_IO_WRITE_ | _IO_HW_) 58 #define IO_WR8_ASYNC (_IO_WRITE_ | _IO_BYTE_) 59 60 /* 61 62 Only Sync. burst accessing is provided. 63 64 */ 65 66 #define IO_WR_BURST(x) (_IO_WRITE_ | _IO_SYNC_ | _IO_BURST_ | ((x) & _IOSZ_MASK_)) 67 #define IO_RD_BURST(x) (_IO_SYNC_ | _IO_BURST_ | ((x) & _IOSZ_MASK_)) 68 69 70 71 /* below is for the intf_option bit defition... */ 72 73 #define _INTF_ASYNC_ BIT(0) /* support async io */ 74 75 struct intf_priv; 76 struct intf_hdl; 77 struct io_queue; 78 79 struct _io_ops { 80 u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr); 81 u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr); 82 u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr); 83 84 int (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val); 85 int (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val); 86 int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val); 87 int (*_writeN)(struct intf_hdl *pintfhdl, u32 addr, u32 length, u8 *pdata); 88 89 int (*_write8_async)(struct intf_hdl *pintfhdl, u32 addr, u8 val); 90 int (*_write16_async)(struct intf_hdl *pintfhdl, u32 addr, u16 val); 91 int (*_write32_async)(struct intf_hdl *pintfhdl, u32 addr, u32 val); 92 93 void (*_read_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem); 94 void (*_write_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem); 95 96 void (*_sync_irp_protocol_rw)(struct io_queue *pio_q); 97 98 u32 (*_read_interrupt)(struct intf_hdl *pintfhdl, u32 addr); 99 100 u32 (*_read_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem); 101 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem); 102 103 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem); 104 105 void (*_read_port_cancel)(struct intf_hdl *pintfhdl); 106 void (*_write_port_cancel)(struct intf_hdl *pintfhdl); 107 108 u8 (*_sd_f0_read8)(struct intf_hdl *pintfhdl, u32 addr); 109 }; 110 111 struct io_req { 112 struct list_head list; 113 u32 addr; 114 volatile u32 val; 115 u32 command; 116 u32 status; 117 u8 *pbuf; 118 119 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt); 120 u8 *cnxt; 121 }; 122 123 struct intf_hdl { 124 struct adapter *padapter; 125 struct dvobj_priv *pintf_dev;/* pointer to &(padapter->dvobjpriv); */ 126 127 struct _io_ops io_ops; 128 }; 129 130 struct reg_protocol_rd { 131 132 #ifdef __LITTLE_ENDIAN 133 134 /* DW1 */ 135 u32 NumOfTrans:4; 136 u32 Reserved1:4; 137 u32 Reserved2:24; 138 /* DW2 */ 139 u32 ByteCount:7; 140 u32 WriteEnable:1; /* 0:read, 1:write */ 141 u32 FixOrContinuous:1; /* 0:continuous, 1: Fix */ 142 u32 BurstMode:1; 143 u32 Byte1Access:1; 144 u32 Byte2Access:1; 145 u32 Byte4Access:1; 146 u32 Reserved3:3; 147 u32 Reserved4:16; 148 /* DW3 */ 149 u32 BusAddress; 150 /* DW4 */ 151 /* u32 Value; */ 152 #else 153 154 155 /* DW1 */ 156 u32 Reserved1 :4; 157 u32 NumOfTrans :4; 158 159 u32 Reserved2 :24; 160 161 /* DW2 */ 162 u32 WriteEnable : 1; 163 u32 ByteCount :7; 164 165 166 u32 Reserved3 : 3; 167 u32 Byte4Access : 1; 168 169 u32 Byte2Access : 1; 170 u32 Byte1Access : 1; 171 u32 BurstMode :1; 172 u32 FixOrContinuous : 1; 173 174 u32 Reserved4 : 16; 175 176 /* DW3 */ 177 u32 BusAddress; 178 179 /* DW4 */ 180 /* u32 Value; */ 181 182 #endif 183 184 }; 185 186 187 struct reg_protocol_wt { 188 189 190 #ifdef __LITTLE_ENDIAN 191 192 /* DW1 */ 193 u32 NumOfTrans:4; 194 u32 Reserved1:4; 195 u32 Reserved2:24; 196 /* DW2 */ 197 u32 ByteCount:7; 198 u32 WriteEnable:1; /* 0:read, 1:write */ 199 u32 FixOrContinuous:1; /* 0:continuous, 1: Fix */ 200 u32 BurstMode:1; 201 u32 Byte1Access:1; 202 u32 Byte2Access:1; 203 u32 Byte4Access:1; 204 u32 Reserved3:3; 205 u32 Reserved4:16; 206 /* DW3 */ 207 u32 BusAddress; 208 /* DW4 */ 209 u32 Value; 210 211 #else 212 /* DW1 */ 213 u32 Reserved1 :4; 214 u32 NumOfTrans :4; 215 216 u32 Reserved2 :24; 217 218 /* DW2 */ 219 u32 WriteEnable : 1; 220 u32 ByteCount :7; 221 222 u32 Reserved3 : 3; 223 u32 Byte4Access : 1; 224 225 u32 Byte2Access : 1; 226 u32 Byte1Access : 1; 227 u32 BurstMode :1; 228 u32 FixOrContinuous : 1; 229 230 u32 Reserved4 : 16; 231 232 /* DW3 */ 233 u32 BusAddress; 234 235 /* DW4 */ 236 u32 Value; 237 238 #endif 239 240 }; 241 #define SD_IO_TRY_CNT (8) 242 #define MAX_CONTINUAL_IO_ERR SD_IO_TRY_CNT 243 244 int rtw_inc_and_chk_continual_io_error(struct dvobj_priv *dvobj); 245 void rtw_reset_continual_io_error(struct dvobj_priv *dvobj); 246 247 /* 248 Below is the data structure used by _io_handler 249 250 */ 251 252 struct io_queue { 253 _lock lock; 254 struct list_head free_ioreqs; 255 struct list_head pending; /* The io_req list that will be served in the single protocol read/write. */ 256 struct list_head processing; 257 u8 *free_ioreqs_buf; /* 4-byte aligned */ 258 u8 *pallocated_free_ioreqs_buf; 259 struct intf_hdl intf; 260 }; 261 262 struct io_priv { 263 264 struct adapter *padapter; 265 266 struct intf_hdl intf; 267 268 }; 269 270 extern uint ioreq_flush(struct adapter *adapter, struct io_queue *ioqueue); 271 extern void sync_ioreq_enqueue(struct io_req *preq, struct io_queue *ioqueue); 272 extern uint sync_ioreq_flush(struct adapter *adapter, struct io_queue *ioqueue); 273 274 275 extern uint free_ioreq(struct io_req *preq, struct io_queue *pio_queue); 276 extern struct io_req *alloc_ioreq(struct io_queue *pio_q); 277 278 extern uint register_intf_hdl(u8 *dev, struct intf_hdl *pintfhdl); 279 extern void unregister_intf_hdl(struct intf_hdl *pintfhdl); 280 281 extern void _rtw_attrib_read(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem); 282 extern void _rtw_attrib_write(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem); 283 284 extern u8 _rtw_read8(struct adapter *adapter, u32 addr); 285 extern u16 _rtw_read16(struct adapter *adapter, u32 addr); 286 extern u32 _rtw_read32(struct adapter *adapter, u32 addr); 287 288 extern int _rtw_write8(struct adapter *adapter, u32 addr, u8 val); 289 extern int _rtw_write16(struct adapter *adapter, u32 addr, u16 val); 290 extern int _rtw_write32(struct adapter *adapter, u32 addr, u32 val); 291 292 extern u8 _rtw_sd_f0_read8(struct adapter *adapter, u32 addr); 293 294 extern u32 _rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem); 295 296 #define rtw_read8(adapter, addr) _rtw_read8((adapter), (addr)) 297 #define rtw_read16(adapter, addr) _rtw_read16((adapter), (addr)) 298 #define rtw_read32(adapter, addr) _rtw_read32((adapter), (addr)) 299 300 #define rtw_write8(adapter, addr, val) _rtw_write8((adapter), (addr), (val)) 301 #define rtw_write16(adapter, addr, val) _rtw_write16((adapter), (addr), (val)) 302 #define rtw_write32(adapter, addr, val) _rtw_write32((adapter), (addr), (val)) 303 304 #define rtw_write_port(adapter, addr, cnt, mem) _rtw_write_port((adapter), (addr), (cnt), (mem)) 305 306 #define rtw_sd_f0_read8(adapter, addr) _rtw_sd_f0_read8((adapter), (addr)) 307 308 extern void rtw_write_scsi(struct adapter *adapter, u32 cnt, u8 *pmem); 309 310 /* ioreq */ 311 extern void ioreq_read8(struct adapter *adapter, u32 addr, u8 *pval); 312 extern void ioreq_read16(struct adapter *adapter, u32 addr, u16 *pval); 313 extern void ioreq_read32(struct adapter *adapter, u32 addr, u32 *pval); 314 extern void ioreq_write8(struct adapter *adapter, u32 addr, u8 val); 315 extern void ioreq_write16(struct adapter *adapter, u32 addr, u16 val); 316 extern void ioreq_write32(struct adapter *adapter, u32 addr, u32 val); 317 318 319 extern uint async_read8(struct adapter *adapter, u32 addr, u8 *pbuff, 320 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt); 321 extern uint async_read16(struct adapter *adapter, u32 addr, u8 *pbuff, 322 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt); 323 extern uint async_read32(struct adapter *adapter, u32 addr, u8 *pbuff, 324 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt); 325 326 extern void async_read_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem); 327 extern void async_read_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem); 328 329 extern void async_write8(struct adapter *adapter, u32 addr, u8 val, 330 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt); 331 extern void async_write16(struct adapter *adapter, u32 addr, u16 val, 332 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt); 333 extern void async_write32(struct adapter *adapter, u32 addr, u32 val, 334 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt); 335 336 extern void async_write_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem); 337 extern void async_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem); 338 339 340 int rtw_init_io_priv(struct adapter *padapter, void (*set_intf_ops)(struct adapter *padapter, struct _io_ops *pops)); 341 342 343 extern uint alloc_io_queue(struct adapter *adapter); 344 extern void free_io_queue(struct adapter *adapter); 345 extern void async_bus_io(struct io_queue *pio_q); 346 extern void bus_sync_io(struct io_queue *pio_q); 347 extern u32 _ioreq2rwmem(struct io_queue *pio_q); 348 extern void dev_power_down(struct adapter * Adapter, u8 bpwrup); 349 350 #define PlatformEFIOWrite1Byte(_a, _b, _c) \ 351 rtw_write8(_a, _b, _c) 352 #define PlatformEFIOWrite2Byte(_a, _b, _c) \ 353 rtw_write16(_a, _b, _c) 354 #define PlatformEFIOWrite4Byte(_a, _b, _c) \ 355 rtw_write32(_a, _b, _c) 356 357 #define PlatformEFIORead1Byte(_a, _b) \ 358 rtw_read8(_a, _b) 359 #define PlatformEFIORead2Byte(_a, _b) \ 360 rtw_read16(_a, _b) 361 #define PlatformEFIORead4Byte(_a, _b) \ 362 rtw_read32(_a, _b) 363 364 #endif /* _RTL8711_IO_H_ */ 365