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