rtw_xmit.h 11 KB

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