/****************************************************************************** * * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA * * ******************************************************************************/ #ifndef _RTW_RECV_H_ #define _RTW_RECV_H_ #include #if defined(PLATFORM_ECOS) #define NR_RECVFRAME 16 //Decrease recv frame due to memory limitation - Alex Fang #elif defined(PLATFORM_FREERTOS) || defined (PLATFORM_CMSIS_RTOS) #ifdef CONFIG_RECV_REORDERING_CTRL #define NR_RECVFRAME 16 //Increase recv frame due to rx reorder - Andy Sun #else #if WIFI_LOGO_CERTIFICATION #define NR_RECVFRAME 8 //Decrease recv frame due to memory limitation - Alex Fang #else #ifndef CONFIG_HIGH_TP #define NR_RECVFRAME 2 //Decrease recv frame due to memory limitation - YangJue #else #define NR_RECVFRAME 256 #endif #endif #endif #else #define NR_RECVFRAME 256 #endif #ifdef PLATFORM_OS_XP #define NR_RECVBUFF (16) #elif defined(PLATFORM_OS_CE) #define NR_RECVBUFF (4) #elif defined(PLATFORM_FREERTOS) || defined (PLATFORM_CMSIS_RTOS) #ifndef CONFIG_HIGH_TP // #define NR_RECVBUFF (8) //Decrease recv buffer due to memory limitation - Alex Fang #define NR_RECVBUFF (1) //Decrease recv buffer due to memory limitation - YangJue #else #define NR_RECVBUFF (32) #endif #else #if (defined CONFIG_GSPI_HCI || defined CONFIG_SDIO_HCI) #define NR_RECVBUFF (32) #else #define NR_RECVBUFF (4) #endif #define NR_PREALLOC_RECV_SKB (8) #endif #define RECV_BULK_IN_ADDR 0x80 #define RECV_INT_IN_ADDR 0x81 #define PHY_RSSI_SLID_WIN_MAX 100 #define PHY_LINKQUALITY_SLID_WIN_MAX 20 // Rx smooth factor #define Rx_Smooth_Factor (20) #define RXFRAME_ALIGN 8 #define RXFRAME_ALIGN_SZ (1<signal_stat_timer, (recvpriv)->signal_stat_sampling_interval) #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS struct sta_recv_priv { _lock lock; sint option; //_queue blk_strms[MAX_RX_NUMBLKS]; _queue defrag_q; //keeping the fragment frame until defrag struct stainfo_rxcache rxcache; //uint sta_rx_bytes; //uint sta_rx_pkts; //uint sta_rx_fail; }; struct recv_buf { _list list; // _lock recvbuf_lock; // u32 ref_cnt; PADAPTER adapter; // u8 *pbuf; // u8 *pallocated_buf; u32 len; u8 *phead; u8 *pdata; u8 *ptail; u8 *pend; #ifdef CONFIG_USB_HCI #if defined(PLATFORM_OS_XP)||defined(PLATFORM_LINUX)||defined(PLATFORM_FREEBSD) PURB purb; dma_addr_t dma_transfer_addr; /* (in) dma addr for transfer_buffer */ u32 alloc_sz; #endif #ifdef PLATFORM_OS_XP PIRP pirp; #endif #ifdef PLATFORM_OS_CE USB_TRANSFER usb_transfer_read_port; #endif u8 irp_pending; int transfer_len; #endif #if defined(PLATFORM_LINUX) || defined(PLATFORM_ECOS) || defined(PLATFORM_FREERTOS) || defined (PLATFORM_CMSIS_RTOS) _pkt *pskb; // u8 reuse; #endif #ifdef PLATFORM_FREEBSD //skb solution struct sk_buff *pskb; u8 reuse; #endif //PLATFORM_FREEBSD //skb solution }; /* head -----> data -----> payload tail -----> end -----> len = (unsigned int )(tail - data); */ struct recv_frame_hdr { _list list; #ifndef CONFIG_BSD_RX_USE_MBUF struct sk_buff *pkt; struct sk_buff *pkt_newalloc; #else // CONFIG_BSD_RX_USE_MBUF _pkt *pkt; _pkt *pkt_newalloc; #endif // CONFIG_BSD_RX_USE_MBUF _adapter *adapter; u8 fragcnt; int frame_tag; struct rx_pkt_attrib attrib; uint len; u8 *rx_head; u8 *rx_data; u8 *rx_tail; u8 *rx_end; void *precvbuf; // struct sta_info *psta; #ifdef CONFIG_RECV_REORDERING_CTRL //for A-MPDU Rx reordering buffer control struct recv_reorder_ctrl *preorder_ctrl; #endif #ifdef CONFIG_WAPI_SUPPORT u8 UserPriority; u8 WapiTempPN[16]; u8 WapiSrcAddr[6]; u8 bWapiCheckPNInDecrypt; u8 bIsWaiPacket; #endif }; union recv_frame{ union{ _list list; struct recv_frame_hdr hdr; uint mem[RECVFRAME_HDR_ALIGN>>2]; }u; //uint mem[MAX_RXSZ>>2]; }; typedef enum _RX_PACKET_TYPE{ NORMAL_RX,//Normal rx packet TX_REPORT1,//CCX TX_REPORT2,//TX RPT HIS_REPORT,// USB HISR RPT C2H_PACKET }RX_PACKET_TYPE, *PRX_PACKET_TYPE; extern union recv_frame *_rtw_alloc_recvframe (_queue *pfree_recv_queue); //get a free recv_frame from pfree_recv_queue extern void rtw_init_recvframe(union recv_frame *precvframe ,struct recv_priv *precvpriv); extern int rtw_free_recvframe(union recv_frame *precvframe, _queue *pfree_recv_queue); #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue) extern int _rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue); #ifdef CONFIG_TRACE_SKB int __rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue); union recv_frame *__rtw_alloc_recvframe (_queue *pfree_recv_queue); //get a free recv_frame from pfree_recv_queue #define rtw_enqueue_recvframe(precvframe, queue, Q) \ do{\ set_skb_list_flag(precvframe->u.hdr.pkt, SKBLIST_RECVFRAME_##Q);\ __rtw_enqueue_recvframe(precvframe, queue);\ }while (0) #define rtw_alloc_recvframe(queue, precvframe, Q) \ (\ precvframe = __rtw_alloc_recvframe(queue),\ precvframe ? clear_skb_list_flag(precvframe->u.hdr.pkt, SKBLIST_RECVFRAME_##Q):0,\ precvframe\ ) #else extern int rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue); extern union recv_frame *rtw_alloc_recvframe (_queue *pfree_recv_queue); //get a free recv_frame from pfree_recv_queue #endif extern void rtw_free_recvframe_queue(_queue *pframequeue, _queue *pfree_recv_queue); u32 rtw_free_uc_swdec_pending_queue(_adapter *adapter); #ifdef CONFIG_TRACE_SKB sint _rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, _queue *queue); sint _rtw_enqueue_recvbuf(struct recv_buf *precvbuf, _queue *queue); struct recv_buf *_rtw_dequeue_recvbuf (_queue *queue); #define rtw_enqueue_recvbuf_to_head(precvbuf, queue, Q) \ do{\ set_skb_list_flag(precvbuf->pskb, SKBLIST_RECVBUF_##Q);\ _rtw_enqueue_recvbuf_to_head(precvbuf, queue);\ }while (0) #define rtw_enqueue_recvbuf(precvbuf, queue, Q) \ do{\ set_skb_list_flag(precvbuf->pskb, SKBLIST_RECVBUF_##Q);\ _rtw_enqueue_recvbuf(precvbuf, queue);\ }while (0) #define rtw_dequeue_recvbuf(queue, precvbuf, Q) \ (\ precvbuf = _rtw_dequeue_recvbuf(queue),\ precvbuf ? clear_skb_list_flag(precvbuf->pskb, SKBLIST_RECVBUF_##Q):0,\ precvbuf\ ) #else sint rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, _queue *queue); sint rtw_enqueue_recvbuf(struct recv_buf *precvbuf, _queue *queue); struct recv_buf *rtw_dequeue_recvbuf (_queue *queue); #endif void rtw_reordering_ctrl_timeout_handler(void *pcontext); __inline static u8 *get_rxmem(union recv_frame *precvframe) { //always return rx_head... if(precvframe==NULL) return NULL; return precvframe->u.hdr.rx_head; } __inline static u8 *get_rx_status(union recv_frame *precvframe) { return get_rxmem(precvframe); } __inline static u8 *get_recvframe_data(union recv_frame *precvframe) { //alwasy return rx_data if(precvframe==NULL) return NULL; return precvframe->u.hdr.rx_data; } //TODO #if 0 __inline static u8 *recvframe_push(union recv_frame *precvframe, sint sz) { // append data before rx_data /* add data to the start of recv_frame * * This function extends the used data area of the recv_frame at the buffer * start. rx_data must be still larger than rx_head, after pushing. */ if(precvframe==NULL) return NULL; precvframe->u.hdr.rx_data -= sz ; if( precvframe->u.hdr.rx_data < precvframe->u.hdr.rx_head ) { precvframe->u.hdr.rx_data += sz ; return NULL; } precvframe->u.hdr.len +=sz; return precvframe->u.hdr.rx_data; } #endif //#if 0 __inline static u8 *recvframe_pull(union recv_frame *precvframe, sint sz) { // rx_data += sz; move rx_data sz bytes hereafter //used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller if(precvframe==NULL) return NULL; precvframe->u.hdr.rx_data += sz; if(precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail) { precvframe->u.hdr.rx_data -= sz; return NULL; } precvframe->u.hdr.len -=sz; return precvframe->u.hdr.rx_data; } __inline static u8 *recvframe_put(union recv_frame *precvframe, sint sz) { // rx_tai += sz; move rx_tail sz bytes hereafter //used for append sz bytes from ptr to rx_tail, update rx_tail and return the updated rx_tail to the caller //after putting, rx_tail must be still larger than rx_end. if(precvframe==NULL) return NULL; precvframe->u.hdr.rx_tail += sz; if(precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end) { precvframe->u.hdr.rx_tail -= sz; return NULL; } precvframe->u.hdr.len +=sz; return precvframe->u.hdr.rx_tail; } __inline static u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz) { // rmv data from rx_tail (by yitsen) //used for extract sz bytes from rx_end, update rx_end and return the updated rx_end to the caller //after pulling, rx_end must be still larger than rx_data. if(precvframe==NULL) return NULL; precvframe->u.hdr.rx_tail -= sz; if(precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data) { precvframe->u.hdr.rx_tail += sz; return NULL; } precvframe->u.hdr.len -=sz; return precvframe->u.hdr.rx_tail; } __inline static _buffer * get_rxbuf_desc(union recv_frame *precvframe) { _buffer * buf_desc = NULL; if(precvframe==NULL) return NULL; #ifdef PLATFORM_WINDOWS NdisQueryPacket(precvframe->u.hdr.pkt, NULL, NULL, &buf_desc, NULL); #endif return buf_desc; } __inline static union recv_frame *rxmem_to_recvframe(u8 *rxmem) { //due to the design of 2048 bytes alignment of recv_frame, we can reference the union recv_frame //from any given member of recv_frame. // rxmem indicates the any member/address in recv_frame return (union recv_frame*)(((SIZE_PTR)rxmem >> RXFRAME_ALIGN) << RXFRAME_ALIGN); } __inline static union recv_frame *pkt_to_recvframe(_pkt *pkt) { u8 * buf_star = NULL; union recv_frame * precv_frame = NULL; #ifdef PLATFORM_WINDOWS _buffer * buf_desc; uint len; NdisQueryPacket(pkt, NULL, NULL, &buf_desc, &len); NdisQueryBufferSafe(buf_desc, &buf_star, &len, HighPagePriority); #endif precv_frame = rxmem_to_recvframe((unsigned char*)buf_star); return precv_frame; } __inline static u8 *pkt_to_recvmem(_pkt *pkt) { // return the rx_head union recv_frame * precv_frame = pkt_to_recvframe(pkt); return precv_frame->u.hdr.rx_head; } __inline static u8 *pkt_to_recvdata(_pkt *pkt) { // return the rx_data union recv_frame * precv_frame =pkt_to_recvframe(pkt); return precv_frame->u.hdr.rx_data; } __inline static sint get_recvframe_len(union recv_frame *precvframe) { return precvframe->u.hdr.len; } __inline static s32 translate_percentage_to_dbm(u32 SignalStrengthIndex) { s32 SignalPower; // in dBm. #ifndef CONFIG_SKIP_SIGNAL_SCALE_MAPPING // Translate to dBm (x=0.9y-95). SignalPower = (s32)((SignalStrengthIndex *18) /20); SignalPower -= 95; #else /* Translate to dBm (x=y-100) */ SignalPower = SignalStrengthIndex - 100; #endif return SignalPower; } struct sta_info; extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv); extern void mgt_dispatcher(_adapter *padapter, union recv_frame *precv_frame); int process_recv_indicatepkts(_adapter *padapter, union recv_frame *prframe); void rtw_rxhandler(_adapter * padapter, struct recv_buf *precvbuf); u32 rtw_free_buf_pending_queue(_adapter *adapter); #endif