1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /****************************************************************************** 3 * 4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. 5 * 6 ******************************************************************************/ 7 #ifndef _RTW_XMIT_H_ 8 #define _RTW_XMIT_H_ 9 10 11 #define MAX_XMITBUF_SZ (20480) /* 20k */ 12 13 #define NR_XMITBUFF (16) 14 15 #define XMITBUF_ALIGN_SZ 512 16 17 /* xmit extension buff defination */ 18 #define MAX_XMIT_EXTBUF_SZ (1536) 19 #define NR_XMIT_EXTBUFF (32) 20 21 #define MAX_CMDBUF_SZ (5120) /* 4096) */ 22 23 #define MAX_NUMBLKS (1) 24 25 #define XMIT_VO_QUEUE (0) 26 #define XMIT_VI_QUEUE (1) 27 #define XMIT_BE_QUEUE (2) 28 #define XMIT_BK_QUEUE (3) 29 30 #define VO_QUEUE_INX 0 31 #define VI_QUEUE_INX 1 32 #define BE_QUEUE_INX 2 33 #define BK_QUEUE_INX 3 34 #define BCN_QUEUE_INX 4 35 #define MGT_QUEUE_INX 5 36 #define HIGH_QUEUE_INX 6 37 #define TXCMD_QUEUE_INX 7 38 39 #define HW_QUEUE_ENTRY 8 40 41 #define WEP_IV(pattrib_iv, dot11txpn, keyidx)\ 42 do{\ 43 pattrib_iv[0] = dot11txpn._byte_.TSC0;\ 44 pattrib_iv[1] = dot11txpn._byte_.TSC1;\ 45 pattrib_iv[2] = dot11txpn._byte_.TSC2;\ 46 pattrib_iv[3] = ((keyidx & 0x3)<<6);\ 47 dot11txpn.val = (dot11txpn.val == 0xffffff) ? 0: (dot11txpn.val+1);\ 48 }while (0) 49 50 51 #define TKIP_IV(pattrib_iv, dot11txpn, keyidx)\ 52 do{\ 53 pattrib_iv[0] = dot11txpn._byte_.TSC1;\ 54 pattrib_iv[1] = (dot11txpn._byte_.TSC1 | 0x20) & 0x7f;\ 55 pattrib_iv[2] = dot11txpn._byte_.TSC0;\ 56 pattrib_iv[3] = BIT(5) | ((keyidx & 0x3)<<6);\ 57 pattrib_iv[4] = dot11txpn._byte_.TSC2;\ 58 pattrib_iv[5] = dot11txpn._byte_.TSC3;\ 59 pattrib_iv[6] = dot11txpn._byte_.TSC4;\ 60 pattrib_iv[7] = dot11txpn._byte_.TSC5;\ 61 dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0: (dot11txpn.val+1);\ 62 }while (0) 63 64 #define AES_IV(pattrib_iv, dot11txpn, keyidx)\ 65 do{\ 66 pattrib_iv[0] = dot11txpn._byte_.TSC0;\ 67 pattrib_iv[1] = dot11txpn._byte_.TSC1;\ 68 pattrib_iv[2] = 0;\ 69 pattrib_iv[3] = BIT(5) | ((keyidx & 0x3)<<6);\ 70 pattrib_iv[4] = dot11txpn._byte_.TSC2;\ 71 pattrib_iv[5] = dot11txpn._byte_.TSC3;\ 72 pattrib_iv[6] = dot11txpn._byte_.TSC4;\ 73 pattrib_iv[7] = dot11txpn._byte_.TSC5;\ 74 dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0: (dot11txpn.val+1);\ 75 }while (0) 76 77 78 #define HWXMIT_ENTRY 4 79 80 /* For Buffer Descriptor ring architecture */ 81 #define TXDESC_SIZE 40 82 83 #define TXDESC_OFFSET TXDESC_SIZE 84 85 enum TXDESC_SC{ 86 SC_DONT_CARE = 0x00, 87 SC_UPPER = 0x01, 88 SC_LOWER = 0x02, 89 SC_DUPLICATE = 0x03 90 }; 91 92 #define TXDESC_40_BYTES 93 94 struct tx_desc { 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 #if defined(TXDESC_40_BYTES) || defined(TXDESC_64_BYTES) 105 __le32 txdw8; 106 __le32 txdw9; 107 #endif /* TXDESC_40_BYTES */ 108 109 #ifdef TXDESC_64_BYTES 110 __le32 txdw10; 111 __le32 txdw11; 112 113 /* 2008/05/15 MH Because PCIE HW memory R/W 4K limit. And now, our descriptor */ 114 /* size is 40 bytes. If you use more than 102 descriptor(103*40>4096), HW will execute */ 115 /* memoryR/W CRC error. And then all DMA fetch will fail. We must decrease descriptor */ 116 /* number or enlarge descriptor size as 64 bytes. */ 117 __le32 txdw12; 118 __le32 txdw13; 119 __le32 txdw14; 120 __le32 txdw15; 121 #endif 122 }; 123 124 union txdesc { 125 struct tx_desc txdesc; 126 unsigned int value[TXDESC_SIZE>>2]; 127 }; 128 129 struct hw_xmit { 130 /* _lock xmit_lock; */ 131 /* struct list_head pending; */ 132 struct __queue *sta_queue; 133 /* struct hw_txqueue *phwtxqueue; */ 134 /* sint txcmdcnt; */ 135 int accnt; 136 }; 137 138 /* reduce size */ 139 struct pkt_attrib 140 { 141 u8 type; 142 u8 subtype; 143 u8 bswenc; 144 u8 dhcp_pkt; 145 u16 ether_type; 146 u16 seqnum; 147 u16 pkt_hdrlen; /* the original 802.3 pkt header len */ 148 u16 hdrlen; /* the WLAN Header Len */ 149 u32 pktlen; /* the original 802.3 pkt raw_data len (not include ether_hdr data) */ 150 u32 last_txcmdsz; 151 u8 nr_frags; 152 u8 encrypt; /* when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith */ 153 u8 iv_len; 154 u8 icv_len; 155 u8 iv[18]; 156 u8 icv[16]; 157 u8 priority; 158 u8 ack_policy; 159 u8 mac_id; 160 u8 vcs_mode; /* virtual carrier sense method */ 161 u8 dst[ETH_ALEN]; 162 u8 src[ETH_ALEN]; 163 u8 ta[ETH_ALEN]; 164 u8 ra[ETH_ALEN]; 165 u8 key_idx; 166 u8 qos_en; 167 u8 ht_en; 168 u8 raid;/* rate adpative id */ 169 u8 bwmode; 170 u8 ch_offset;/* PRIME_CHNL_OFFSET */ 171 u8 sgi;/* short GI */ 172 u8 ampdu_en;/* tx ampdu enable */ 173 u8 ampdu_spacing; /* ampdu_min_spacing for peer sta's rx */ 174 u8 mdata;/* more data bit */ 175 u8 pctrl;/* per packet txdesc control enable */ 176 u8 triggered;/* for ap mode handling Power Saving sta */ 177 u8 qsel; 178 u8 order;/* order bit */ 179 u8 eosp; 180 u8 rate; 181 u8 intel_proxim; 182 u8 retry_ctrl; 183 u8 mbssid; 184 u8 ldpc; 185 u8 stbc; 186 struct sta_info * psta; 187 188 u8 rtsen; 189 u8 cts2self; 190 union Keytype dot11tkiptxmickey; 191 /* union Keytype dot11tkiprxmickey; */ 192 union Keytype dot118021x_UncstKey; 193 194 u8 icmp_pkt; 195 196 }; 197 198 #define WLANHDR_OFFSET 64 199 200 #define NULL_FRAMETAG (0x0) 201 #define DATA_FRAMETAG 0x01 202 #define L2_FRAMETAG 0x02 203 #define MGNT_FRAMETAG 0x03 204 #define AMSDU_FRAMETAG 0x04 205 206 #define EII_FRAMETAG 0x05 207 #define IEEE8023_FRAMETAG 0x06 208 209 #define MP_FRAMETAG 0x07 210 211 #define TXAGG_FRAMETAG 0x08 212 213 enum { 214 XMITBUF_DATA = 0, 215 XMITBUF_MGNT = 1, 216 XMITBUF_CMD = 2, 217 }; 218 219 struct submit_ctx{ 220 unsigned long submit_time; /* */ 221 u32 timeout_ms; /* <0: not synchronous, 0: wait forever, >0: up to ms waiting */ 222 int status; /* status for operation */ 223 struct completion done; 224 }; 225 226 enum { 227 RTW_SCTX_SUBMITTED = -1, 228 RTW_SCTX_DONE_SUCCESS = 0, 229 RTW_SCTX_DONE_UNKNOWN, 230 RTW_SCTX_DONE_TIMEOUT, 231 RTW_SCTX_DONE_BUF_ALLOC, 232 RTW_SCTX_DONE_BUF_FREE, 233 RTW_SCTX_DONE_WRITE_PORT_ERR, 234 RTW_SCTX_DONE_TX_DESC_NA, 235 RTW_SCTX_DONE_TX_DENY, 236 RTW_SCTX_DONE_CCX_PKT_FAIL, 237 RTW_SCTX_DONE_DRV_STOP, 238 RTW_SCTX_DONE_DEV_REMOVE, 239 RTW_SCTX_DONE_CMD_ERROR, 240 }; 241 242 243 void rtw_sctx_init(struct submit_ctx *sctx, int timeout_ms); 244 int rtw_sctx_wait(struct submit_ctx *sctx, const char *msg); 245 void rtw_sctx_done_err(struct submit_ctx **sctx, int status); 246 void rtw_sctx_done(struct submit_ctx **sctx); 247 248 struct xmit_buf 249 { 250 struct list_head list; 251 252 struct adapter *padapter; 253 254 u8 *pallocated_buf; 255 256 u8 *pbuf; 257 258 void *priv_data; 259 260 u16 buf_tag; /* 0: Normal xmitbuf, 1: extension xmitbuf, 2:cmd xmitbuf */ 261 u16 flags; 262 u32 alloc_sz; 263 264 u32 len; 265 266 struct submit_ctx *sctx; 267 268 u8 *phead; 269 u8 *pdata; 270 u8 *ptail; 271 u8 *pend; 272 u32 ff_hwaddr; 273 u8 pg_num; 274 u8 agg_num; 275 276 #if defined(DBG_XMIT_BUF)|| defined(DBG_XMIT_BUF_EXT) 277 u8 no; 278 #endif 279 280 }; 281 282 283 struct xmit_frame 284 { 285 struct list_head list; 286 287 struct pkt_attrib attrib; 288 289 _pkt *pkt; 290 291 int frame_tag; 292 293 struct adapter *padapter; 294 295 u8 *buf_addr; 296 297 struct xmit_buf *pxmitbuf; 298 299 u8 pg_num; 300 u8 agg_num; 301 302 u8 ack_report; 303 304 u8 *alloc_addr; /* the actual address this xmitframe allocated */ 305 u8 ext_tag; /* 0:data, 1:mgmt */ 306 307 }; 308 309 struct tx_servq { 310 struct list_head tx_pending; 311 struct __queue sta_pending; 312 int qcnt; 313 }; 314 315 316 struct sta_xmit_priv 317 { 318 _lock lock; 319 sint option; 320 sint apsd_setting; /* When bit mask is on, the associated edca queue supports APSD. */ 321 322 323 /* struct tx_servq blk_q[MAX_NUMBLKS]; */ 324 struct tx_servq be_q; /* priority == 0, 3 */ 325 struct tx_servq bk_q; /* priority == 1, 2 */ 326 struct tx_servq vi_q; /* priority == 4, 5 */ 327 struct tx_servq vo_q; /* priority == 6, 7 */ 328 struct list_head legacy_dz; 329 struct list_head apsd; 330 331 u16 txseq_tid[16]; 332 333 /* uint sta_tx_bytes; */ 334 /* u64 sta_tx_pkts; */ 335 /* uint sta_tx_fail; */ 336 337 338 }; 339 340 341 struct hw_txqueue { 342 volatile sint head; 343 volatile sint tail; 344 volatile sint free_sz; /* in units of 64 bytes */ 345 volatile sint free_cmdsz; 346 volatile sint txsz[8]; 347 uint ff_hwaddr; 348 uint cmd_hwaddr; 349 sint ac_tag; 350 }; 351 352 struct agg_pkt_info{ 353 u16 offset; 354 u16 pkt_len; 355 }; 356 357 enum cmdbuf_type { 358 CMDBUF_BEACON = 0x00, 359 CMDBUF_RSVD, 360 CMDBUF_MAX 361 }; 362 363 struct xmit_priv { 364 365 _lock lock; 366 367 _sema xmit_sema; 368 _sema terminate_xmitthread_sema; 369 370 /* struct __queue blk_strms[MAX_NUMBLKS]; */ 371 struct __queue be_pending; 372 struct __queue bk_pending; 373 struct __queue vi_pending; 374 struct __queue vo_pending; 375 struct __queue bm_pending; 376 377 /* struct __queue legacy_dz_queue; */ 378 /* struct __queue apsd_queue; */ 379 380 u8 *pallocated_frame_buf; 381 u8 *pxmit_frame_buf; 382 uint free_xmitframe_cnt; 383 struct __queue free_xmit_queue; 384 385 /* uint mapping_addr; */ 386 /* uint pkt_sz; */ 387 388 u8 *xframe_ext_alloc_addr; 389 u8 *xframe_ext; 390 uint free_xframe_ext_cnt; 391 struct __queue free_xframe_ext_queue; 392 393 /* struct hw_txqueue be_txqueue; */ 394 /* struct hw_txqueue bk_txqueue; */ 395 /* struct hw_txqueue vi_txqueue; */ 396 /* struct hw_txqueue vo_txqueue; */ 397 /* struct hw_txqueue bmc_txqueue; */ 398 399 uint frag_len; 400 401 struct adapter *adapter; 402 403 u8 vcs_setting; 404 u8 vcs; 405 u8 vcs_type; 406 /* u16 rts_thresh; */ 407 408 u64 tx_bytes; 409 u64 tx_pkts; 410 u64 tx_drop; 411 u64 last_tx_pkts; 412 413 struct hw_xmit *hwxmits; 414 u8 hwxmit_entry; 415 416 u8 wmm_para_seq[4];/* sequence for wmm ac parameter strength from large to small. it's value is 0->vo, 1->vi, 2->be, 3->bk. */ 417 418 #ifdef CONFIG_SDIO_TX_TASKLET 419 struct tasklet_struct xmit_tasklet; 420 #else 421 void *SdioXmitThread; 422 _sema SdioXmitSema; 423 _sema SdioXmitTerminateSema; 424 #endif /* CONFIG_SDIO_TX_TASKLET */ 425 426 struct __queue free_xmitbuf_queue; 427 struct __queue pending_xmitbuf_queue; 428 u8 *pallocated_xmitbuf; 429 u8 *pxmitbuf; 430 uint free_xmitbuf_cnt; 431 432 struct __queue free_xmit_extbuf_queue; 433 u8 *pallocated_xmit_extbuf; 434 u8 *pxmit_extbuf; 435 uint free_xmit_extbuf_cnt; 436 437 struct xmit_buf pcmd_xmitbuf[CMDBUF_MAX]; 438 439 u16 nqos_ssn; 440 441 int ack_tx; 442 _mutex ack_tx_mutex; 443 struct submit_ctx ack_tx_ops; 444 u8 seq_no; 445 _lock lock_sctx; 446 }; 447 448 extern struct xmit_frame *__rtw_alloc_cmdxmitframe(struct xmit_priv *pxmitpriv, 449 enum cmdbuf_type buf_type); 450 #define rtw_alloc_cmdxmitframe(p) __rtw_alloc_cmdxmitframe(p, CMDBUF_RSVD) 451 #define rtw_alloc_bcnxmitframe(p) __rtw_alloc_cmdxmitframe(p, CMDBUF_BEACON) 452 453 extern struct xmit_buf *rtw_alloc_xmitbuf_ext(struct xmit_priv *pxmitpriv); 454 extern s32 rtw_free_xmitbuf_ext(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf); 455 456 extern struct xmit_buf *rtw_alloc_xmitbuf(struct xmit_priv *pxmitpriv); 457 extern s32 rtw_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf); 458 459 void rtw_count_tx_stats(struct adapter *padapter, struct xmit_frame *pxmitframe, int sz); 460 extern void rtw_update_protection(struct adapter *padapter, u8 *ie, uint ie_len); 461 extern s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattrib); 462 extern s32 rtw_put_snap(u8 *data, u16 h_proto); 463 464 extern struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv); 465 struct xmit_frame *rtw_alloc_xmitframe_ext(struct xmit_priv *pxmitpriv); 466 struct xmit_frame *rtw_alloc_xmitframe_once(struct xmit_priv *pxmitpriv); 467 extern s32 rtw_free_xmitframe(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitframe); 468 extern void rtw_free_xmitframe_queue(struct xmit_priv *pxmitpriv, struct __queue *pframequeue); 469 struct tx_servq *rtw_get_sta_pending(struct adapter *padapter, struct sta_info *psta, sint up, u8 *ac); 470 extern s32 rtw_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe); 471 472 extern s32 rtw_xmit_classifier(struct adapter *padapter, struct xmit_frame *pxmitframe); 473 extern u32 rtw_calculate_wlan_pkt_size_by_attribue(struct pkt_attrib *pattrib); 474 #define rtw_wlan_pkt_size(f) rtw_calculate_wlan_pkt_size_by_attribue(&f->attrib) 475 extern s32 rtw_xmitframe_coalesce(struct adapter *padapter, _pkt *pkt, struct xmit_frame *pxmitframe); 476 extern s32 rtw_mgmt_xmitframe_coalesce(struct adapter *padapter, _pkt *pkt, struct xmit_frame *pxmitframe); 477 s32 _rtw_init_hw_txqueue(struct hw_txqueue* phw_txqueue, u8 ac_tag); 478 void _rtw_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv); 479 480 481 s32 rtw_txframes_pending(struct adapter *padapter); 482 void rtw_init_hwxmits(struct hw_xmit *phwxmit, sint entry); 483 484 485 s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter); 486 void _rtw_free_xmit_priv (struct xmit_priv *pxmitpriv); 487 488 489 void rtw_alloc_hwxmits(struct adapter *padapter); 490 void rtw_free_hwxmits(struct adapter *padapter); 491 492 493 s32 rtw_xmit(struct adapter *padapter, _pkt **pkt); 494 bool xmitframe_hiq_filter(struct xmit_frame *xmitframe); 495 496 sint xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_frame *pxmitframe); 497 void stop_sta_xmit(struct adapter *padapter, struct sta_info *psta); 498 void wakeup_sta_to_xmit(struct adapter *padapter, struct sta_info *psta); 499 void xmit_delivery_enabled_frames(struct adapter *padapter, struct sta_info *psta); 500 501 u8 query_ra_short_GI(struct sta_info *psta); 502 503 u8 qos_acm(u8 acm_mask, u8 priority); 504 505 void enqueue_pending_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf); 506 void enqueue_pending_xmitbuf_to_head(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf); 507 struct xmit_buf*dequeue_pending_xmitbuf(struct xmit_priv *pxmitpriv); 508 struct xmit_buf*dequeue_pending_xmitbuf_under_survey(struct xmit_priv *pxmitpriv); 509 sint check_pending_xmitbuf(struct xmit_priv *pxmitpriv); 510 int rtw_xmit_thread(void *context); 511 512 u32 rtw_get_ff_hwaddr(struct xmit_frame *pxmitframe); 513 514 int rtw_ack_tx_wait(struct xmit_priv *pxmitpriv, u32 timeout_ms); 515 void rtw_ack_tx_done(struct xmit_priv *pxmitpriv, int status); 516 517 /* include after declaring struct xmit_buf, in order to avoid warning */ 518 #include <xmit_osdep.h> 519 520 #endif /* _RTL871X_XMIT_H_ */ 521