rtw_recv.h 21 KB

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