rtw_recv.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  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_RECV_H_
  16. #define _RTW_RECV_H_
  17. #define RTW_RX_MSDU_ACT_NONE 0
  18. #define RTW_RX_MSDU_ACT_INDICATE BIT0
  19. #define RTW_RX_MSDU_ACT_FORWARD BIT1
  20. #ifdef PLATFORM_OS_XP
  21. #ifdef CONFIG_SDIO_HCI
  22. #define NR_RECVBUFF 1024/* 512 */ /* 128 */
  23. #else
  24. #define NR_RECVBUFF (16)
  25. #endif
  26. #elif defined(PLATFORM_OS_CE)
  27. #ifdef CONFIG_SDIO_HCI
  28. #define NR_RECVBUFF (128)
  29. #else
  30. #define NR_RECVBUFF (4)
  31. #endif
  32. #else /* PLATFORM_LINUX /PLATFORM_BSD */
  33. #ifdef CONFIG_SINGLE_RECV_BUF
  34. #define NR_RECVBUFF (1)
  35. #else
  36. #if defined(CONFIG_GSPI_HCI)
  37. #define NR_RECVBUFF (32)
  38. #elif defined(CONFIG_SDIO_HCI)
  39. #define NR_RECVBUFF (8)
  40. #else
  41. #define NR_RECVBUFF (8)
  42. #endif
  43. #endif /* CONFIG_SINGLE_RECV_BUF */
  44. #ifdef CONFIG_PREALLOC_RX_SKB_BUFFER
  45. #define NR_PREALLOC_RECV_SKB (rtw_rtkm_get_nr_recv_skb()>>1)
  46. #else /*!CONFIG_PREALLOC_RX_SKB_BUFFER */
  47. #define NR_PREALLOC_RECV_SKB 8
  48. #endif /* CONFIG_PREALLOC_RX_SKB_BUFFER */
  49. #ifdef CONFIG_RTW_NAPI
  50. #define RTL_NAPI_WEIGHT (32)
  51. #endif
  52. #endif
  53. #if defined(CONFIG_RTL8821C) && defined(CONFIG_SDIO_HCI) && defined(CONFIG_RECV_THREAD_MODE)
  54. #ifdef NR_RECVBUFF
  55. #undef NR_RECVBUFF
  56. #define NR_RECVBUFF (32)
  57. #endif
  58. #endif
  59. #define NR_RECVFRAME 256
  60. #define RXFRAME_ALIGN 8
  61. #define RXFRAME_ALIGN_SZ (1<<RXFRAME_ALIGN)
  62. #define DRVINFO_SZ 4 /* unit is 8bytes */
  63. #define MAX_RXFRAME_CNT 512
  64. #define MAX_RX_NUMBLKS (32)
  65. #define RECVFRAME_HDR_ALIGN 128
  66. #define MAX_CONTINUAL_NORXPACKET_COUNT 4 /* In MAX_CONTINUAL_NORXPACKET_COUNT*2 sec , no rx traffict would issue DELBA*/
  67. #define PHY_RSSI_SLID_WIN_MAX 100
  68. #define PHY_LINKQUALITY_SLID_WIN_MAX 20
  69. #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
  70. #define RX_MPDU_QUEUE 0
  71. #define RX_CMD_QUEUE 1
  72. #define RX_MAX_QUEUE 2
  73. #define MAX_SUBFRAME_COUNT 64
  74. /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
  75. extern u8 rtw_bridge_tunnel_header[];
  76. extern u8 rtw_rfc1042_header[];
  77. /* for Rx reordering buffer control */
  78. struct recv_reorder_ctrl {
  79. _adapter *padapter;
  80. u8 tid;
  81. u8 enable;
  82. u16 indicate_seq;/* =wstart_b, init_value=0xffff */
  83. u16 wend_b;
  84. u8 wsize_b;
  85. u8 ampdu_size;
  86. _queue pending_recvframe_queue;
  87. _timer reordering_ctrl_timer;
  88. u8 bReorderWaiting;
  89. };
  90. struct stainfo_rxcache {
  91. u16 tid_rxseq[16];
  92. u8 iv[16][8];
  93. u8 last_tid;
  94. #if 0
  95. unsigned short tid0_rxseq;
  96. unsigned short tid1_rxseq;
  97. unsigned short tid2_rxseq;
  98. unsigned short tid3_rxseq;
  99. unsigned short tid4_rxseq;
  100. unsigned short tid5_rxseq;
  101. unsigned short tid6_rxseq;
  102. unsigned short tid7_rxseq;
  103. unsigned short tid8_rxseq;
  104. unsigned short tid9_rxseq;
  105. unsigned short tid10_rxseq;
  106. unsigned short tid11_rxseq;
  107. unsigned short tid12_rxseq;
  108. unsigned short tid13_rxseq;
  109. unsigned short tid14_rxseq;
  110. unsigned short tid15_rxseq;
  111. #endif
  112. };
  113. struct smooth_rssi_data {
  114. u32 elements[100]; /* array to store values */
  115. u32 index; /* index to current array to store */
  116. u32 total_num; /* num of valid elements */
  117. u32 total_val; /* sum of valid elements */
  118. };
  119. struct signal_stat {
  120. u8 update_req; /* used to indicate */
  121. u8 avg_val; /* avg of valid elements */
  122. u32 total_num; /* num of valid elements */
  123. u32 total_val; /* sum of valid elements */
  124. };
  125. struct rx_raw_rssi {
  126. u8 data_rate;
  127. u8 pwdball;
  128. s8 pwr_all;
  129. u8 mimo_signal_strength[4];/* in 0~100 index */
  130. u8 mimo_signal_quality[4];
  131. s8 ofdm_pwr[4];
  132. u8 ofdm_snr[4];
  133. };
  134. #include "cmn_info/rtw_sta_info.h"
  135. struct rx_pkt_attrib {
  136. u16 pkt_len;
  137. u8 physt;
  138. u8 drvinfo_sz;
  139. u8 shift_sz;
  140. u8 hdrlen; /* the WLAN Header Len */
  141. u8 to_fr_ds;
  142. u8 amsdu;
  143. u8 qos;
  144. u8 priority;
  145. u8 pw_save;
  146. u8 mdata;
  147. u16 seq_num;
  148. u8 frag_num;
  149. u8 mfrag;
  150. u8 order;
  151. u8 privacy; /* in frame_ctrl field */
  152. u8 bdecrypted;
  153. u8 encrypt; /* when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith */
  154. u8 iv_len;
  155. u8 icv_len;
  156. u8 crc_err;
  157. u8 icv_err;
  158. u16 eth_type;
  159. u8 dst[ETH_ALEN];
  160. u8 src[ETH_ALEN];
  161. u8 ta[ETH_ALEN];
  162. u8 ra[ETH_ALEN];
  163. u8 bssid[ETH_ALEN];
  164. #ifdef CONFIG_RTW_MESH
  165. u8 msa[ETH_ALEN]; /* mesh sa */
  166. u8 mda[ETH_ALEN]; /* mesh da */
  167. u8 mesh_ctrl_present;
  168. u8 mesh_ctrl_len; /* length of mesh control field */
  169. #endif
  170. u8 ack_policy;
  171. u8 key_index;
  172. u8 data_rate;
  173. u8 ch; /* RX channel */
  174. u8 bw;
  175. u8 stbc;
  176. u8 ldpc;
  177. u8 sgi;
  178. u8 pkt_rpt_type;
  179. u32 tsfl;
  180. u32 MacIDValidEntry[2]; /* 64 bits present 64 entry. */
  181. u8 ppdu_cnt;
  182. u32 free_cnt; /* free run counter */
  183. struct phydm_phyinfo_struct phy_info;
  184. };
  185. #ifdef CONFIG_RTW_MESH
  186. #define RATTRIB_GET_MCTRL_LEN(rattrib) ((rattrib)->mesh_ctrl_len)
  187. #else
  188. #define RATTRIB_GET_MCTRL_LEN(rattrib) 0
  189. #endif
  190. /* These definition is used for Rx packet reordering. */
  191. #define SN_LESS(a, b) (((a-b) & 0x800) != 0)
  192. #define SN_EQUAL(a, b) (a == b)
  193. /* #define REORDER_WIN_SIZE 128 */
  194. /* #define REORDER_ENTRY_NUM 128 */
  195. #define REORDER_WAIT_TIME (50) /* (ms) */
  196. #if defined(CONFIG_PLATFORM_RTK390X) && defined(CONFIG_USB_HCI)
  197. #define RECVBUFF_ALIGN_SZ 32
  198. #else
  199. #define RECVBUFF_ALIGN_SZ 8
  200. #endif
  201. #ifdef CONFIG_TRX_BD_ARCH
  202. #define RX_WIFI_INFO_SIZE 24
  203. #elif (defined(CONFIG_RTL8192E) || defined(CONFIG_RTL8814A) || defined(CONFIG_RTL8822B)) && defined(CONFIG_PCI_HCI)
  204. #define RXBD_SIZE sizeof(struct recv_stat)
  205. #endif
  206. #define RXDESC_SIZE 24
  207. #define RXDESC_OFFSET RXDESC_SIZE
  208. #ifdef CONFIG_TRX_BD_ARCH
  209. struct rx_buf_desc {
  210. /* RX has exactly one segment */
  211. #ifdef CONFIG_64BIT_DMA
  212. unsigned int dword[4];
  213. #else
  214. unsigned int dword[2];
  215. #endif
  216. };
  217. struct recv_stat {
  218. unsigned int rxdw[8];
  219. };
  220. #else
  221. struct recv_stat {
  222. unsigned int rxdw0;
  223. unsigned int rxdw1;
  224. #if !((defined(CONFIG_RTL8192E) || defined(CONFIG_RTL8814A) || defined(CONFIG_RTL8822B) || defined(CONFIG_RTL8821C)) && defined(CONFIG_PCI_HCI)) /* exclude 8192ee, 8814ae, 8822be, 8821ce */
  225. unsigned int rxdw2;
  226. unsigned int rxdw3;
  227. #endif
  228. #ifndef BUF_DESC_ARCH
  229. unsigned int rxdw4;
  230. unsigned int rxdw5;
  231. #ifdef CONFIG_PCI_HCI
  232. unsigned int rxdw6;
  233. unsigned int rxdw7;
  234. #endif
  235. #endif /* if BUF_DESC_ARCH is defined, rx_buf_desc occupy 4 double words */
  236. };
  237. #endif
  238. #define EOR BIT(30)
  239. #ifdef CONFIG_PCI_HCI
  240. #define PCI_MAX_RX_QUEUE 1/* MSDU packet queue, Rx Command Queue */
  241. #define PCI_MAX_RX_COUNT 128
  242. #ifdef CONFIG_TRX_BD_ARCH
  243. #define RX_BD_NUM PCI_MAX_RX_COUNT /* alias */
  244. #endif
  245. struct rtw_rx_ring {
  246. #ifdef CONFIG_TRX_BD_ARCH
  247. struct rx_buf_desc *buf_desc;
  248. #else
  249. struct recv_stat *desc;
  250. #endif
  251. dma_addr_t dma;
  252. unsigned int idx;
  253. struct sk_buff *rx_buf[PCI_MAX_RX_COUNT];
  254. };
  255. #endif
  256. /*
  257. accesser of recv_priv: rtw_recv_entry(dispatch / passive level); recv_thread(passive) ; returnpkt(dispatch)
  258. ; halt(passive) ;
  259. using enter_critical section to protect
  260. */
  261. #ifndef DBG_RX_BH_TRACKING
  262. #define DBG_RX_BH_TRACKING 0
  263. #endif
  264. struct recv_priv {
  265. _lock lock;
  266. #ifdef CONFIG_RECV_THREAD_MODE
  267. _sema recv_sema;
  268. #endif
  269. /* _queue blk_strms[MAX_RX_NUMBLKS]; */ /* keeping the block ack frame until return ack */
  270. _queue free_recv_queue;
  271. _queue recv_pending_queue;
  272. _queue uc_swdec_pending_queue;
  273. u8 *pallocated_frame_buf;
  274. u8 *precv_frame_buf;
  275. uint free_recvframe_cnt;
  276. #if DBG_RX_BH_TRACKING
  277. u32 rx_bh_stage;
  278. u32 rx_bh_buf_dq_cnt;
  279. void *rx_bh_lbuf;
  280. void *rx_bh_cbuf;
  281. void *rx_bh_cbuf_data;
  282. u32 rx_bh_cbuf_dlen;
  283. u32 rx_bh_cbuf_pos;
  284. void *rx_bh_cframe;
  285. #endif
  286. _adapter *adapter;
  287. #ifdef PLATFORM_WINDOWS
  288. _nic_hdl RxPktPoolHdl;
  289. _nic_hdl RxBufPoolHdl;
  290. #ifdef PLATFORM_OS_XP
  291. PMDL pbytecnt_mdl;
  292. #endif
  293. uint counter; /* record the number that up-layer will return to drv; only when counter==0 can we release recv_priv */
  294. NDIS_EVENT recv_resource_evt ;
  295. #endif
  296. u32 is_any_non_be_pkts;
  297. u64 rx_bytes;
  298. u64 rx_pkts;
  299. u64 rx_drop;
  300. u64 dbg_rx_drop_count;
  301. u64 dbg_rx_ampdu_drop_count;
  302. u64 dbg_rx_ampdu_forced_indicate_count;
  303. u64 dbg_rx_ampdu_loss_count;
  304. u64 dbg_rx_dup_mgt_frame_drop_count;
  305. u64 dbg_rx_ampdu_window_shift_cnt;
  306. u64 dbg_rx_conflic_mac_addr_cnt;
  307. uint rx_icv_err;
  308. uint rx_largepacket_crcerr;
  309. uint rx_smallpacket_crcerr;
  310. uint rx_middlepacket_crcerr;
  311. #ifdef CONFIG_USB_HCI
  312. /* u8 *pallocated_urb_buf; */
  313. _sema allrxreturnevt;
  314. uint ff_hwaddr;
  315. ATOMIC_T rx_pending_cnt;
  316. #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
  317. #ifdef PLATFORM_LINUX
  318. PURB int_in_urb;
  319. #endif
  320. u8 *int_in_buf;
  321. #endif /* CONFIG_USB_INTERRUPT_IN_PIPE */
  322. #endif
  323. #if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD)
  324. #ifdef PLATFORM_FREEBSD
  325. struct task irq_prepare_beacon_tasklet;
  326. struct task recv_tasklet;
  327. #else /* PLATFORM_FREEBSD */
  328. struct tasklet_struct irq_prepare_beacon_tasklet;
  329. struct tasklet_struct recv_tasklet;
  330. #endif /* PLATFORM_FREEBSD */
  331. struct sk_buff_head free_recv_skb_queue;
  332. struct sk_buff_head rx_skb_queue;
  333. #ifdef CONFIG_RTW_NAPI
  334. struct sk_buff_head rx_napi_skb_queue;
  335. #endif
  336. #ifdef CONFIG_RX_INDICATE_QUEUE
  337. struct task rx_indicate_tasklet;
  338. struct ifqueue rx_indicate_queue;
  339. #endif /* CONFIG_RX_INDICATE_QUEUE */
  340. #endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD) */
  341. u8 *pallocated_recv_buf;
  342. u8 *precv_buf; /* 4 alignment */
  343. _queue free_recv_buf_queue;
  344. u32 free_recv_buf_queue_cnt;
  345. #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI) || defined(CONFIG_USB_HCI)
  346. _queue recv_buf_pending_queue;
  347. #endif
  348. #ifdef CONFIG_PCI_HCI
  349. /* Rx */
  350. struct rtw_rx_ring rx_ring[PCI_MAX_RX_QUEUE];
  351. int rxringcount; /* size should be PCI_MAX_RX_QUEUE */
  352. u16 rxbuffersize;
  353. #endif
  354. /* For display the phy informatiom */
  355. u8 is_signal_dbg; /* for debug */
  356. u8 signal_strength_dbg; /* for debug */
  357. u8 signal_strength;
  358. u8 signal_qual;
  359. s8 rssi; /* translate_percentage_to_dbm(ptarget_wlan->network.PhyInfo.SignalStrength); */
  360. struct rx_raw_rssi raw_rssi_info;
  361. /* s8 rxpwdb; */
  362. /* int RxSNRdB[2]; */
  363. /* s8 RxRssi[2]; */
  364. /* int FalseAlmCnt_all; */
  365. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  366. _timer signal_stat_timer;
  367. u32 signal_stat_sampling_interval;
  368. /* u32 signal_stat_converging_constant; */
  369. struct signal_stat signal_qual_data;
  370. struct signal_stat signal_strength_data;
  371. #else /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
  372. struct smooth_rssi_data signal_qual_data;
  373. struct smooth_rssi_data signal_strength_data;
  374. #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
  375. u16 sink_udpport, pre_rtp_rxseq, cur_rtp_rxseq;
  376. BOOLEAN store_law_data_flag;
  377. };
  378. #define RX_BH_STG_UNKNOWN 0
  379. #define RX_BH_STG_HDL_ENTER 1
  380. #define RX_BH_STG_HDL_EXIT 2
  381. #define RX_BH_STG_NEW_BUF 3
  382. #define RX_BH_STG_NEW_FRAME 4
  383. #define RX_BH_STG_NORMAL_RX 5
  384. #define RX_BH_STG_NORMAL_RX_END 6
  385. #define RX_BH_STG_C2H 7
  386. #define RX_BH_STG_C2H_END 8
  387. #if DBG_RX_BH_TRACKING
  388. void rx_bh_tk_set_stage(struct recv_priv *recv, u32 s);
  389. void rx_bh_tk_set_buf(struct recv_priv *recv, void *buf, void *data, u32 dlen);
  390. void rx_bh_tk_set_buf_pos(struct recv_priv *recv, void *pos);
  391. void rx_bh_tk_set_frame(struct recv_priv *recv, void *frame);
  392. void dump_rx_bh_tk(void *sel, struct recv_priv *recv);
  393. #else
  394. #define rx_bh_tk_set_stage(recv, s) do {} while (0)
  395. #define rx_bh_tk_set_buf(recv, buf, data, dlen) do {} while (0)
  396. #define rx_bh_tk_set_buf_pos(recv, pos) do {} while (0)
  397. #define rx_bh_tk_set_frame(recv, frame) do {} while (0)
  398. #define dump_rx_bh_tk(sel, recv) do {} while (0)
  399. #endif
  400. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  401. #define rtw_set_signal_stat_timer(recvpriv) _set_timer(&(recvpriv)->signal_stat_timer, (recvpriv)->signal_stat_sampling_interval)
  402. #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
  403. struct sta_recv_priv {
  404. _lock lock;
  405. sint option;
  406. /* _queue blk_strms[MAX_RX_NUMBLKS]; */
  407. _queue defrag_q; /* keeping the fragment frame until defrag */
  408. struct stainfo_rxcache rxcache;
  409. u16 bmc_tid_rxseq[16];
  410. u16 nonqos_rxseq;
  411. u16 nonqos_bmc_rxseq;
  412. /* uint sta_rx_bytes; */
  413. /* uint sta_rx_pkts; */
  414. /* uint sta_rx_fail; */
  415. };
  416. struct recv_buf {
  417. _list list;
  418. _lock recvbuf_lock;
  419. u32 ref_cnt;
  420. PADAPTER adapter;
  421. u8 *pbuf;
  422. u8 *pallocated_buf;
  423. u32 len;
  424. u8 *phead;
  425. u8 *pdata;
  426. u8 *ptail;
  427. u8 *pend;
  428. #ifdef CONFIG_USB_HCI
  429. #if defined(PLATFORM_OS_XP) || defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD)
  430. PURB purb;
  431. dma_addr_t dma_transfer_addr; /* (in) dma addr for transfer_buffer */
  432. u32 alloc_sz;
  433. #endif
  434. #ifdef PLATFORM_OS_XP
  435. PIRP pirp;
  436. #endif
  437. #ifdef PLATFORM_OS_CE
  438. USB_TRANSFER usb_transfer_read_port;
  439. #endif
  440. u8 irp_pending;
  441. int transfer_len;
  442. #endif
  443. #if defined(PLATFORM_LINUX)
  444. _pkt *pskb;
  445. #elif defined(PLATFORM_FREEBSD) /* skb solution */
  446. struct sk_buff *pskb;
  447. #endif
  448. };
  449. /*
  450. head ----->
  451. data ----->
  452. payload
  453. tail ----->
  454. end ----->
  455. len = (unsigned int )(tail - data);
  456. */
  457. struct recv_frame_hdr {
  458. _list list;
  459. _pkt *pkt;
  460. _adapter *adapter;
  461. u8 fragcnt;
  462. int frame_tag;
  463. struct rx_pkt_attrib attrib;
  464. uint len;
  465. u8 *rx_head;
  466. u8 *rx_data;
  467. u8 *rx_tail;
  468. u8 *rx_end;
  469. void *precvbuf;
  470. /* */
  471. struct sta_info *psta;
  472. /* for A-MPDU Rx reordering buffer control */
  473. struct recv_reorder_ctrl *preorder_ctrl;
  474. #ifdef CONFIG_WAPI_SUPPORT
  475. u8 UserPriority;
  476. u8 WapiTempPN[16];
  477. u8 WapiSrcAddr[6];
  478. u8 bWapiCheckPNInDecrypt;
  479. u8 bIsWaiPacket;
  480. #endif
  481. };
  482. union recv_frame {
  483. union {
  484. _list list;
  485. struct recv_frame_hdr hdr;
  486. uint mem[RECVFRAME_HDR_ALIGN >> 2];
  487. } u;
  488. /* uint mem[MAX_RXSZ>>2]; */
  489. };
  490. bool rtw_rframe_del_wfd_ie(union recv_frame *rframe, u8 ies_offset);
  491. typedef enum _RX_PACKET_TYPE {
  492. NORMAL_RX,/* Normal rx packet */
  493. TX_REPORT1,/* CCX */
  494. TX_REPORT2,/* TX RPT */
  495. HIS_REPORT,/* USB HISR RPT */
  496. C2H_PACKET
  497. } RX_PACKET_TYPE, *PRX_PACKET_TYPE;
  498. extern union recv_frame *_rtw_alloc_recvframe(_queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */
  499. extern union recv_frame *rtw_alloc_recvframe(_queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */
  500. extern void rtw_init_recvframe(union recv_frame *precvframe , struct recv_priv *precvpriv);
  501. extern int rtw_free_recvframe(union recv_frame *precvframe, _queue *pfree_recv_queue);
  502. #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
  503. extern int _rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue);
  504. extern int rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue);
  505. extern void rtw_free_recvframe_queue(_queue *pframequeue, _queue *pfree_recv_queue);
  506. u32 rtw_free_uc_swdec_pending_queue(_adapter *adapter);
  507. sint rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, _queue *queue);
  508. sint rtw_enqueue_recvbuf(struct recv_buf *precvbuf, _queue *queue);
  509. struct recv_buf *rtw_dequeue_recvbuf(_queue *queue);
  510. #if defined(CONFIG_80211N_HT) && defined(CONFIG_RECV_REORDERING_CTRL)
  511. void rtw_reordering_ctrl_timeout_handler(void *pcontext);
  512. #endif
  513. void rx_query_phy_status(union recv_frame *rframe, u8 *phy_stat);
  514. int rtw_inc_and_chk_continual_no_rx_packet(struct sta_info *sta, int tid_index);
  515. void rtw_reset_continual_no_rx_packet(struct sta_info *sta, int tid_index);
  516. #ifdef CONFIG_RECV_THREAD_MODE
  517. thread_return rtw_recv_thread(thread_context context);
  518. #endif
  519. __inline static u8 *get_rxmem(union recv_frame *precvframe)
  520. {
  521. /* always return rx_head... */
  522. if (precvframe == NULL)
  523. return NULL;
  524. return precvframe->u.hdr.rx_head;
  525. }
  526. __inline static u8 *get_rx_status(union recv_frame *precvframe)
  527. {
  528. return get_rxmem(precvframe);
  529. }
  530. __inline static u8 *get_recvframe_data(union recv_frame *precvframe)
  531. {
  532. /* alwasy return rx_data */
  533. if (precvframe == NULL)
  534. return NULL;
  535. return precvframe->u.hdr.rx_data;
  536. }
  537. __inline static u8 *recvframe_push(union recv_frame *precvframe, sint sz)
  538. {
  539. /* append data before rx_data */
  540. /* add data to the start of recv_frame
  541. *
  542. * This function extends the used data area of the recv_frame at the buffer
  543. * start. rx_data must be still larger than rx_head, after pushing.
  544. */
  545. if (precvframe == NULL)
  546. return NULL;
  547. precvframe->u.hdr.rx_data -= sz ;
  548. if (precvframe->u.hdr.rx_data < precvframe->u.hdr.rx_head) {
  549. precvframe->u.hdr.rx_data += sz ;
  550. return NULL;
  551. }
  552. precvframe->u.hdr.len += sz;
  553. return precvframe->u.hdr.rx_data;
  554. }
  555. __inline static u8 *recvframe_pull(union recv_frame *precvframe, sint sz)
  556. {
  557. /* rx_data += sz; move rx_data sz bytes hereafter */
  558. /* used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller */
  559. if (precvframe == NULL)
  560. return NULL;
  561. precvframe->u.hdr.rx_data += sz;
  562. if (precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail) {
  563. precvframe->u.hdr.rx_data -= sz;
  564. return NULL;
  565. }
  566. precvframe->u.hdr.len -= sz;
  567. return precvframe->u.hdr.rx_data;
  568. }
  569. __inline static u8 *recvframe_put(union recv_frame *precvframe, sint sz)
  570. {
  571. /* rx_tai += sz; move rx_tail sz bytes hereafter */
  572. /* used for append sz bytes from ptr to rx_tail, update rx_tail and return the updated rx_tail to the caller */
  573. /* after putting, rx_tail must be still larger than rx_end. */
  574. unsigned char *prev_rx_tail;
  575. /* RTW_INFO("recvframe_put: len=%d\n", sz); */
  576. if (precvframe == NULL)
  577. return NULL;
  578. prev_rx_tail = precvframe->u.hdr.rx_tail;
  579. precvframe->u.hdr.rx_tail += sz;
  580. if (precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end) {
  581. precvframe->u.hdr.rx_tail -= sz;
  582. return NULL;
  583. }
  584. precvframe->u.hdr.len += sz;
  585. return precvframe->u.hdr.rx_tail;
  586. }
  587. __inline static u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz)
  588. {
  589. /* rmv data from rx_tail (by yitsen) */
  590. /* used for extract sz bytes from rx_end, update rx_end and return the updated rx_end to the caller */
  591. /* after pulling, rx_end must be still larger than rx_data. */
  592. if (precvframe == NULL)
  593. return NULL;
  594. precvframe->u.hdr.rx_tail -= sz;
  595. if (precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data) {
  596. precvframe->u.hdr.rx_tail += sz;
  597. return NULL;
  598. }
  599. precvframe->u.hdr.len -= sz;
  600. return precvframe->u.hdr.rx_tail;
  601. }
  602. __inline static _buffer *get_rxbuf_desc(union recv_frame *precvframe)
  603. {
  604. _buffer *buf_desc;
  605. if (precvframe == NULL)
  606. return NULL;
  607. #ifdef PLATFORM_WINDOWS
  608. NdisQueryPacket(precvframe->u.hdr.pkt, NULL, NULL, &buf_desc, NULL);
  609. #endif
  610. return buf_desc;
  611. }
  612. __inline static union recv_frame *rxmem_to_recvframe(u8 *rxmem)
  613. {
  614. /* due to the design of 2048 bytes alignment of recv_frame, we can reference the union recv_frame */
  615. /* from any given member of recv_frame. */
  616. /* rxmem indicates the any member/address in recv_frame */
  617. return (union recv_frame *)(((SIZE_PTR)rxmem >> RXFRAME_ALIGN) << RXFRAME_ALIGN);
  618. }
  619. __inline static union recv_frame *pkt_to_recvframe(_pkt *pkt)
  620. {
  621. u8 *buf_star;
  622. union recv_frame *precv_frame;
  623. #ifdef PLATFORM_WINDOWS
  624. _buffer *buf_desc;
  625. uint len;
  626. NdisQueryPacket(pkt, NULL, NULL, &buf_desc, &len);
  627. NdisQueryBufferSafe(buf_desc, &buf_star, &len, HighPagePriority);
  628. #endif
  629. precv_frame = rxmem_to_recvframe((unsigned char *)buf_star);
  630. return precv_frame;
  631. }
  632. __inline static u8 *pkt_to_recvmem(_pkt *pkt)
  633. {
  634. /* return the rx_head */
  635. union recv_frame *precv_frame = pkt_to_recvframe(pkt);
  636. return precv_frame->u.hdr.rx_head;
  637. }
  638. __inline static u8 *pkt_to_recvdata(_pkt *pkt)
  639. {
  640. /* return the rx_data */
  641. union recv_frame *precv_frame = pkt_to_recvframe(pkt);
  642. return precv_frame->u.hdr.rx_data;
  643. }
  644. __inline static sint get_recvframe_len(union recv_frame *precvframe)
  645. {
  646. return precvframe->u.hdr.len;
  647. }
  648. __inline static s32 translate_percentage_to_dbm(u32 SignalStrengthIndex)
  649. {
  650. s32 SignalPower; /* in dBm. */
  651. /* Translate to dBm (x=y-100) */
  652. SignalPower = SignalStrengthIndex - 100;
  653. return SignalPower;
  654. }
  655. struct sta_info;
  656. extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
  657. extern void mgt_dispatcher(_adapter *padapter, union recv_frame *precv_frame);
  658. u8 adapter_allow_bmc_data_rx(_adapter *adapter);
  659. s32 pre_recv_entry(union recv_frame *precvframe, u8 *pphy_status);
  660. void count_rx_stats(_adapter *padapter, union recv_frame *prframe, struct sta_info *sta);
  661. #endif