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 #ifndef _RTW_XMIT_H_ 16 #define _RTW_XMIT_H_ 17 18 #include <osdep_service.h> 19 #include <drv_types.h> 20 21 #define MAX_XMITBUF_SZ 2048 22 #define NR_XMITBUFF 4 23 24 #define XMITBUF_ALIGN_SZ 512 25 26 /* xmit extension buff defination */ 27 #define MAX_XMIT_EXTBUF_SZ 1536 28 #define NR_XMIT_EXTBUFF 32 29 30 #define MAX_NUMBLKS 1 31 32 #define XMIT_VO_QUEUE 0 33 #define XMIT_VI_QUEUE 1 34 #define XMIT_BE_QUEUE 2 35 #define XMIT_BK_QUEUE 3 36 37 #define VO_QUEUE_INX 0 38 #define VI_QUEUE_INX 1 39 #define BE_QUEUE_INX 2 40 #define BK_QUEUE_INX 3 41 #define BCN_QUEUE_INX 4 42 #define MGT_QUEUE_INX 5 43 #define HIGH_QUEUE_INX 6 44 #define TXCMD_QUEUE_INX 7 45 46 #define HW_QUEUE_ENTRY 8 47 48 #define WEP_IV(pattrib_iv, dot11txpn, keyidx) \ 49 do { \ 50 pattrib_iv[0] = dot11txpn._byte_.TSC0; \ 51 pattrib_iv[1] = dot11txpn._byte_.TSC1; \ 52 pattrib_iv[2] = dot11txpn._byte_.TSC2; \ 53 pattrib_iv[3] = ((keyidx & 0x3) << 6); \ 54 dot11txpn.val = (dot11txpn.val == 0xffffff) ? 0 : \ 55 (dot11txpn.val+1); \ 56 } while (0) 57 58 #define TKIP_IV(pattrib_iv, dot11txpn, keyidx) \ 59 do { \ 60 pattrib_iv[0] = dot11txpn._byte_.TSC1; \ 61 pattrib_iv[1] = (dot11txpn._byte_.TSC1 | 0x20) & 0x7f; \ 62 pattrib_iv[2] = dot11txpn._byte_.TSC0; \ 63 pattrib_iv[3] = BIT(5) | ((keyidx & 0x3)<<6); \ 64 pattrib_iv[4] = dot11txpn._byte_.TSC2; \ 65 pattrib_iv[5] = dot11txpn._byte_.TSC3; \ 66 pattrib_iv[6] = dot11txpn._byte_.TSC4; \ 67 pattrib_iv[7] = dot11txpn._byte_.TSC5; \ 68 dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0 : \ 69 (dot11txpn.val+1); \ 70 } while (0) 71 72 #define AES_IV(pattrib_iv, dot11txpn, keyidx)\ 73 do { \ 74 pattrib_iv[0] = dot11txpn._byte_.TSC0; \ 75 pattrib_iv[1] = dot11txpn._byte_.TSC1; \ 76 pattrib_iv[2] = 0; \ 77 pattrib_iv[3] = BIT(5) | ((keyidx & 0x3) << 6); \ 78 pattrib_iv[4] = dot11txpn._byte_.TSC2; \ 79 pattrib_iv[5] = dot11txpn._byte_.TSC3; \ 80 pattrib_iv[6] = dot11txpn._byte_.TSC4; \ 81 pattrib_iv[7] = dot11txpn._byte_.TSC5; \ 82 dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0 : \ 83 (dot11txpn.val+1); \ 84 } while (0) 85 86 #define HWXMIT_ENTRY 4 87 88 #define TXDESC_SIZE 32 89 90 #define PACKET_OFFSET_SZ 8 91 #define TXDESC_OFFSET (TXDESC_SIZE + PACKET_OFFSET_SZ) 92 93 struct tx_desc { 94 /* DWORD 0 */ 95 __le32 txdw0; 96 __le32 txdw1; 97 __le32 txdw2; 98 __le32 txdw3; 99 __le32 txdw4; 100 __le32 txdw5; 101 __le32 txdw6; 102 __le32 txdw7; 103 }; 104 105 union txdesc { 106 struct tx_desc txdesc; 107 unsigned int value[TXDESC_SIZE>>2]; 108 }; 109 110 struct hw_xmit { 111 struct rtw_queue *sta_queue; 112 int accnt; 113 }; 114 115 /* reduce size */ 116 struct pkt_attrib { 117 u16 type; 118 u8 bswenc; 119 u8 dhcp_pkt; 120 u16 ether_type; 121 u16 seqnum; 122 u16 pkt_hdrlen; /* the original 802.3 pkt header len */ 123 u16 hdrlen; /* the WLAN Header Len */ 124 u32 pktlen; /* the original 802.3 pkt raw_data len */ 125 u32 last_txcmdsz; 126 u32 encrypt; /* when 0 indicate no encrypt. */ 127 u8 nr_frags; 128 u8 iv_len; 129 u8 icv_len; 130 u8 iv[18]; 131 u8 icv[16]; 132 u8 priority; 133 u8 ack_policy; 134 u8 mac_id; 135 u8 vcs_mode; /* virtual carrier sense method */ 136 u8 dst[ETH_ALEN]; 137 u8 src[ETH_ALEN]; 138 u8 ta[ETH_ALEN]; 139 u8 ra[ETH_ALEN]; 140 u8 key_idx; 141 u8 qos_en; 142 u8 ht_en; 143 u8 raid;/* rate adpative id */ 144 u8 bwmode; 145 u8 ch_offset;/* PRIME_CHNL_OFFSET */ 146 u8 sgi;/* short GI */ 147 u8 ampdu_en;/* tx ampdu enable */ 148 u8 mdata;/* more data bit */ 149 u8 pctrl;/* per packet txdesc control enable */ 150 u8 triggered;/* for ap mode handling Power Saving sta */ 151 u8 qsel; 152 u8 eosp; 153 u8 rate; 154 u8 retry_ctrl; 155 struct sta_info *psta; 156 }; 157 158 #define WLANHDR_OFFSET 64 159 160 #define NULL_FRAMETAG 0x0 161 #define DATA_FRAMETAG 0x01 162 #define L2_FRAMETAG 0x02 163 #define MGNT_FRAMETAG 0x03 164 #define AMSDU_FRAMETAG 0x04 165 166 #define EII_FRAMETAG 0x05 167 #define IEEE8023_FRAMETAG 0x06 168 169 #define MP_FRAMETAG 0x07 170 171 #define TXAGG_FRAMETAG 0x08 172 173 struct submit_ctx { 174 u32 timeout_ms; /* <0: not synchronous, 0: wait forever, 175 * >0: up to ms waiting 176 */ 177 int status; /* status for operation */ 178 struct completion done; 179 }; 180 181 enum { 182 RTW_SCTX_SUBMITTED = -1, 183 RTW_SCTX_DONE_SUCCESS = 0, 184 RTW_SCTX_DONE_UNKNOWN, 185 RTW_SCTX_DONE_TIMEOUT, 186 RTW_SCTX_DONE_BUF_ALLOC, 187 RTW_SCTX_DONE_BUF_FREE, 188 RTW_SCTX_DONE_WRITE_PORT_ERR, 189 RTW_SCTX_DONE_TX_DESC_NA, 190 RTW_SCTX_DONE_TX_DENY, 191 RTW_SCTX_DONE_CCX_PKT_FAIL, 192 RTW_SCTX_DONE_DRV_STOP, 193 RTW_SCTX_DONE_DEV_REMOVE, 194 }; 195 196 void rtw_sctx_init23a(struct submit_ctx *sctx, int timeout_ms); 197 int rtw_sctx_wait23a(struct submit_ctx *sctx); 198 void rtw23a_sctx_done_err(struct submit_ctx **sctx, int status); 199 void rtw_sctx_done23a(struct submit_ctx **sctx); 200 201 struct xmit_buf { 202 struct list_head list, list2; 203 struct rtw_adapter *padapter; 204 205 u8 *pallocated_buf; 206 u8 *pbuf; 207 void *priv_data; 208 209 u16 ext_tag; /* 0: Normal xmitbuf, 1: extension xmitbuf. */ 210 u16 flags; 211 u32 alloc_sz; 212 u32 len; 213 struct submit_ctx *sctx; 214 u32 ff_hwaddr; 215 struct urb *pxmit_urb[8]; 216 u8 bpending[8]; 217 int last[8]; 218 #if defined(DBG_XMIT_BUF) || defined(DBG_XMIT_BUF_EXT) 219 u8 no; 220 #endif 221 }; 222 223 struct xmit_frame { 224 struct list_head list; 225 struct pkt_attrib attrib; 226 struct sk_buff *pkt; 227 int frame_tag; 228 struct rtw_adapter *padapter; 229 u8 *buf_addr; 230 struct xmit_buf *pxmitbuf; 231 232 s8 pkt_offset; 233 234 u8 ack_report; 235 236 u8 ext_tag; /* 0:data, 1:mgmt */ 237 }; 238 239 struct tx_servq { 240 struct list_head tx_pending; 241 struct rtw_queue sta_pending; 242 int qcnt; 243 }; 244 245 struct sta_xmit_priv { 246 spinlock_t lock; 247 int option; 248 int apsd_setting; /* When bit mask is on, the associated edca 249 * queue supports APSD. 250 */ 251 struct tx_servq be_q; /* priority == 0,3 */ 252 struct tx_servq bk_q; /* priority == 1,2 */ 253 struct tx_servq vi_q; /* priority == 4,5 */ 254 struct tx_servq vo_q; /* priority == 6,7 */ 255 struct list_head legacy_dz; 256 struct list_head apsd; 257 u16 txseq_tid[16]; 258 }; 259 260 struct hw_txqueue { 261 volatile int head; 262 volatile int tail; 263 volatile int free_sz; /* in units of 64 bytes */ 264 volatile int free_cmdsz; 265 volatile int txsz[8]; 266 uint ff_hwaddr; 267 uint cmd_hwaddr; 268 int ac_tag; 269 }; 270 271 struct agg_pkt_info { 272 u16 offset; 273 u16 pkt_len; 274 }; 275 276 struct xmit_priv { 277 spinlock_t lock; 278 279 struct semaphore xmit_sema; 280 struct semaphore terminate_xmitthread_sema; 281 282 struct rtw_queue be_pending; 283 struct rtw_queue bk_pending; 284 struct rtw_queue vi_pending; 285 struct rtw_queue vo_pending; 286 struct rtw_queue bm_pending; 287 288 int free_xmitframe_cnt; 289 struct rtw_queue free_xmit_queue; 290 291 int free_xframe_ext_cnt; 292 struct rtw_queue free_xframe_ext_queue; 293 294 uint frag_len; 295 296 struct rtw_adapter *adapter; 297 298 u8 vcs_setting; 299 u8 vcs; 300 u8 vcs_type; 301 302 u64 tx_bytes; 303 u64 tx_pkts; 304 u64 tx_drop; 305 u64 last_tx_bytes; 306 u64 last_tx_pkts; 307 308 struct hw_xmit *hwxmits; 309 u8 hwxmit_entry; 310 311 u8 wmm_para_seq[4];/* sequence for wmm ac parameter strength from 312 * large to small. it's value is 0->vo, 1->vi, 313 * 2->be, 3->bk. 314 */ 315 316 struct semaphore tx_retevt;/* all tx return event; */ 317 u8 txirp_cnt;/* */ 318 319 struct tasklet_struct xmit_tasklet; 320 /* per AC pending irp */ 321 int beq_cnt; 322 int bkq_cnt; 323 int viq_cnt; 324 int voq_cnt; 325 326 struct rtw_queue free_xmitbuf_queue; 327 struct list_head xmitbuf_list; /* track buffers for cleanup */ 328 struct rtw_queue pending_xmitbuf_queue; 329 uint free_xmitbuf_cnt; 330 331 struct rtw_queue free_xmit_extbuf_queue; 332 struct list_head xmitextbuf_list; /* track buffers for cleanup */ 333 uint free_xmit_extbuf_cnt; 334 335 u16 nqos_ssn; 336 int ack_tx; 337 struct mutex ack_tx_mutex; 338 struct submit_ctx ack_tx_ops; 339 spinlock_t lock_sctx; 340 }; 341 342 struct xmit_buf *rtw_alloc_xmitbuf23a_ext(struct xmit_priv *pxmitpriv); 343 s32 rtw_free_xmitbuf_ext23a(struct xmit_priv *pxmitpriv, 344 struct xmit_buf *pxmitbuf); 345 346 struct xmit_buf *rtw_alloc_xmitbuf23a(struct xmit_priv *pxmitpriv); 347 s32 rtw_free_xmitbuf23a(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf); 348 349 void rtw_count_tx_stats23a(struct rtw_adapter *padapter, 350 struct xmit_frame *pxmitframe, int sz); 351 void rtw_update_protection23a(struct rtw_adapter *padapter, u8 *ie, uint ie_len); 352 s32 rtw_put_snap23a(u8 *data, u16 h_proto); 353 struct xmit_frame *rtw_alloc_xmitframe23a_ext(struct xmit_priv *pxmitpriv); 354 struct xmit_frame *rtw_alloc_xmitframe23a_once(struct xmit_priv *pxmitpriv); 355 s32 rtw_free_xmitframe23a(struct xmit_priv *pxmitpriv, 356 struct xmit_frame *pxmitframe); 357 void rtw_free_xmitframe_queue23a(struct xmit_priv *pxmitpriv, struct rtw_queue *pframequeue); 358 struct tx_servq *rtw_get_sta_pending23a(struct rtw_adapter *padapter, 359 struct sta_info *psta, int up, u8 *ac); 360 s32 rtw_xmitframe_enqueue23a(struct rtw_adapter *padapter, 361 struct xmit_frame *pxmitframe); 362 struct xmit_frame *rtw_dequeue_xframe23a(struct xmit_priv *pxmitpriv, 363 struct hw_xmit *phwxmit_i, int entry); 364 s32 rtw_xmit23a_classifier(struct rtw_adapter *padapter, 365 struct xmit_frame *pxmitframe); 366 u32 rtw_calculate_wlan_pkt_size_by_attribue23a(struct pkt_attrib *pattrib); 367 #define rtw_wlan_pkt_size(f) rtw_calculate_wlan_pkt_size_by_attribue23a(&f->attrib) 368 s32 rtw_xmitframe_coalesce23a(struct rtw_adapter *padapter, struct sk_buff *pkt, 369 struct xmit_frame *pxmitframe); 370 s32 _rtw_init_hw_txqueue(struct hw_txqueue *phw_txqueue, u8 ac_tag); 371 void _rtw_init_sta_xmit_priv23a(struct sta_xmit_priv *psta_xmitpriv); 372 373 s32 rtw_txframes_pending23a(struct rtw_adapter *padapter); 374 s32 rtw_txframes_sta_ac_pending23a(struct rtw_adapter *padapter, 375 struct pkt_attrib *pattrib); 376 void rtw_init_hwxmits23a(struct hw_xmit *phwxmit, int entry); 377 int _rtw_init_xmit_priv23a(struct xmit_priv *pxmitpriv, 378 struct rtw_adapter *padapter); 379 void _rtw_free_xmit_priv23a(struct xmit_priv *pxmitpriv); 380 void rtw_alloc_hwxmits23a(struct rtw_adapter *padapter); 381 void rtw_free_hwxmits23a(struct rtw_adapter *padapter); 382 int rtw_xmit23a(struct rtw_adapter *padapter, struct sk_buff *pkt); 383 #if defined(CONFIG_8723AU_AP_MODE) 384 int xmitframe_enqueue_for_sleeping_sta23a(struct rtw_adapter *padapter, 385 struct xmit_frame *pxmitframe); 386 void stop_sta_xmit23a(struct rtw_adapter *padapter, struct sta_info *psta); 387 void wakeup_sta_to_xmit23a(struct rtw_adapter *padapter, struct sta_info *psta); 388 void xmit_delivery_enabled_frames23a(struct rtw_adapter *padapter, 389 struct sta_info *psta); 390 #endif 391 u8 qos_acm23a(u8 acm_mask, u8 priority); 392 u32 rtw_get_ff_hwaddr23a(struct xmit_frame *pxmitframe); 393 int rtw_ack_tx_wait23a(struct xmit_priv *pxmitpriv, u32 timeout_ms); 394 void rtw_ack_tx_done23a(struct xmit_priv *pxmitpriv, int status); 395 396 /* include after declaring struct xmit_buf, in order to avoid warning */ 397 #include <xmit_osdep.h> 398 399 #endif /* _RTL871X_XMIT_H_ */ 400