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