Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6
[pandora-kernel.git] / drivers / staging / ath6kl / reorder / aggr_rx_internal.h
1 /*
2  *
3  * Copyright (c) 2004-2010 Atheros Communications Inc.
4  * All rights reserved.
5  *
6  * 
7 //
8 // Permission to use, copy, modify, and/or distribute this software for any
9 // purpose with or without fee is hereby granted, provided that the above
10 // copyright notice and this permission notice appear in all copies.
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 //
20 //
21  *
22  */
23
24 #ifndef __AGGR_RX_INTERNAL_H__
25 #define __AGGR_RX_INTERNAL_H__
26
27 #include "a_osapi.h"
28 #include "aggr_recv_api.h"
29
30 #define AGGR_WIN_IDX(x, y)          ((x) % (y))
31 #define AGGR_INCR_IDX(x, y)         AGGR_WIN_IDX(((x)+1), (y))
32 #define AGGR_DCRM_IDX(x, y)         AGGR_WIN_IDX(((x)-1), (y))
33 #define IEEE80211_MAX_SEQ_NO        0xFFF
34 #define IEEE80211_NEXT_SEQ_NO(x)    (((x) + 1) & IEEE80211_MAX_SEQ_NO)
35
36
37 #define NUM_OF_TIDS         8
38 #define AGGR_SZ_DEFAULT     8
39
40 #define AGGR_WIN_SZ_MIN     2
41 #define AGGR_WIN_SZ_MAX     8
42 /* TID Window sz is double of what is negotiated. Derive TID_WINDOW_SZ from win_sz, per tid */
43 #define TID_WINDOW_SZ(_x)   ((_x) << 1)
44
45 #define AGGR_NUM_OF_FREE_NETBUFS    16
46
47 #define AGGR_GET_RXTID_STATS(_p, _x)    (&(_p->stat[(_x)]))
48 #define AGGR_GET_RXTID(_p, _x)    (&(_p->RxTid[(_x)]))
49
50 /* Hold q is a function of win_sz, which is negotiated per tid */
51 #define HOLD_Q_SZ(_x)   (TID_WINDOW_SZ((_x))*sizeof(OSBUF_HOLD_Q))
52 /* AGGR_RX_TIMEOUT value is important as a (too) small value can cause frames to be 
53  * delivered out of order and a (too) large value can cause undesirable latency in
54  * certain situations. */
55 #define AGGR_RX_TIMEOUT     400  /* Timeout(in ms) for delivery of frames, if they are stuck */
56
57 typedef enum {
58     ALL_SEQNO = 0,
59     CONTIGUOUS_SEQNO = 1,
60 }DELIVERY_ORDER;
61
62 typedef struct {
63     void        *osbuf;
64     A_BOOL      is_amsdu;
65     A_UINT16    seq_no;
66 }OSBUF_HOLD_Q;
67
68
69 #if 0
70 typedef struct {
71     A_UINT16    seqno_st;
72     A_UINT16    seqno_end;
73 }WINDOW_SNAPSHOT;
74 #endif
75
76 typedef struct {
77     A_BOOL              aggr;       /* is it ON or OFF */
78     A_BOOL              progress;   /* TRUE when frames have arrived after a timer start */
79     A_BOOL              timerMon;   /* TRUE if the timer started for the sake of this TID */
80     A_UINT16            win_sz;     /* negotiated window size */
81     A_UINT16            seq_next;   /* Next seq no, in current window */
82     A_UINT32            hold_q_sz;  /* Num of frames that can be held in hold q */
83     OSBUF_HOLD_Q        *hold_q;    /* Hold q for re-order */
84 #if 0    
85     WINDOW_SNAPSHOT     old_win;    /* Sliding window snapshot - for timeout */
86 #endif    
87     A_NETBUF_QUEUE_T    q;          /* q head for enqueuing frames for dispatch */
88     A_MUTEX_T           lock;
89 }RXTID;
90
91 typedef struct {
92     A_UINT32    num_into_aggr;      /* hitting at the input of this module */
93     A_UINT32    num_dups;           /* duplicate */
94     A_UINT32    num_oow;            /* out of window */
95     A_UINT32    num_mpdu;           /* single payload 802.3/802.11 frame */
96     A_UINT32    num_amsdu;          /* AMSDU */
97     A_UINT32    num_delivered;      /* frames delivered to IP stack */
98     A_UINT32    num_timeouts;       /* num of timeouts, during which frames delivered */
99     A_UINT32    num_hole;           /* frame not present, when window moved over */
100     A_UINT32    num_bar;            /* num of resets of seq_num, via BAR */
101 }RXTID_STATS;
102
103 typedef struct {
104     A_UINT8             aggr_sz;            /* config value of aggregation size */    
105     A_UINT8             timerScheduled;
106     A_TIMER             timer;              /* timer for returning held up pkts in re-order que */    
107     void                *dev;               /* dev handle */
108     RX_CALLBACK         rx_fn;              /* callback function to return frames; to upper layer */
109     RXTID               RxTid[NUM_OF_TIDS]; /* Per tid window */
110     ALLOC_NETBUFS       netbuf_allocator;   /* OS netbuf alloc fn */
111     A_NETBUF_QUEUE_T    freeQ;              /* pre-allocated buffers - for A_MSDU slicing */
112     RXTID_STATS         stat[NUM_OF_TIDS];  /* Tid based statistics */
113     PACKET_LOG          pkt_log;            /* Log info of the packets */
114 }AGGR_INFO;
115
116 #endif /* __AGGR_RX_INTERNAL_H__ */