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