upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / net / wireless / bcm4330 / src / dhd / sys / dhd_wlfc.h
1 /*
2 * Copyright (C) 1999-2011, Broadcom Corporation
3
4 *         Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2 (the "GPL"),
7 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
8 * following added to such license:
9
10 *      As a special exception, the copyright holders of this software give you
11 * permission to link this software with independent modules, and to copy and
12 * distribute the resulting executable under terms of your choice, provided that
13 * you also meet, for each linked independent module, the terms and conditions of
14 * the license of that module.  An independent module is a module which is not
15 * derived from this software.  The special exception does not apply to any
16 * modifications of the software.
17
18 *      Notwithstanding the above, under no circumstances may you combine this
19 * software in any way with any other Broadcom software provided under a license
20 * other than the GPL, without Broadcom's express prior written consent.
21 * $Id: dhd_wlfc.h,v 1.1.8.1 2010-09-09 22:41:08 $
22 *
23 */
24 #ifndef __wlfc_host_driver_definitions_h__
25 #define __wlfc_host_driver_definitions_h__
26
27 /* 16 bits will provide an absolute max of 65536 slots */
28 #define WLFC_HANGER_MAXITEMS 1024
29
30 #define WLFC_HANGER_ITEM_STATE_FREE             1
31 #define WLFC_HANGER_ITEM_STATE_INUSE    2
32
33 #define WLFC_PKTID_HSLOT_MASK                   0xffff /* allow 16 bits only */
34 #define WLFC_PKTID_HSLOT_SHIFT                  8
35
36 /* x -> TXSTATUS TAG to/from firmware */
37 #define WLFC_PKTID_HSLOT_GET(x)                 \
38         (((x) >> WLFC_PKTID_HSLOT_SHIFT) & WLFC_PKTID_HSLOT_MASK)
39 #define WLFC_PKTID_HSLOT_SET(var, slot) \
40         ((var) = ((var) & ~(WLFC_PKTID_HSLOT_MASK << WLFC_PKTID_HSLOT_SHIFT)) | \
41         (((slot) & WLFC_PKTID_HSLOT_MASK) << WLFC_PKTID_HSLOT_SHIFT))
42
43 #define WLFC_PKTID_FREERUNCTR_MASK      0xff
44
45 #define WLFC_PKTID_FREERUNCTR_GET(x)    ((x) & WLFC_PKTID_FREERUNCTR_MASK)
46 #define WLFC_PKTID_FREERUNCTR_SET(var, ctr)     \
47         ((var) = (((var) & ~WLFC_PKTID_FREERUNCTR_MASK) | \
48         (((ctr) & WLFC_PKTID_FREERUNCTR_MASK))))
49
50 #define WLFC_PKTQ_PENQ(pq, prec, p) ((pktq_full((pq)) || pktq_pfull((pq), (prec)))? \
51         NULL : pktq_penq((pq), (prec), (p)))
52 #define WLFC_PKTQ_PENQ_HEAD(pq, prec, p) ((pktq_full((pq)) || pktq_pfull((pq), (prec))) ? \
53         NULL : pktq_penq_head((pq), (prec), (p)))
54
55 typedef enum ewlfc_packet_state {
56         eWLFC_PKTTYPE_NEW,
57         eWLFC_PKTTYPE_DELAYED,
58         eWLFC_PKTTYPE_SUPPRESSED,
59         eWLFC_PKTTYPE_MAX
60 } ewlfc_packet_state_t;
61
62 typedef enum ewlfc_mac_entry_action {
63         eWLFC_MAC_ENTRY_ACTION_ADD,
64         eWLFC_MAC_ENTRY_ACTION_DEL,
65         eWLFC_MAC_ENTRY_ACTION_MAX
66 } ewlfc_mac_entry_action_t;
67
68 typedef struct wlfc_hanger_item {
69         uint8   state;
70         uint8   pad[3];
71         uint32  identifier;
72         void*   pkt;
73 } wlfc_hanger_item_t;
74
75 typedef struct wlfc_hanger {
76         int max_items;
77         uint32 pushed;
78         uint32 popped;
79         uint32 failed_to_push;
80         uint32 failed_to_pop;
81         uint32 failed_slotfind;
82         wlfc_hanger_item_t items[1];
83 } wlfc_hanger_t;
84
85 #define WLFC_HANGER_SIZE(n)     ((sizeof(wlfc_hanger_t) - \
86         sizeof(wlfc_hanger_item_t)) + ((n)*sizeof(wlfc_hanger_item_t)))
87
88 #define WLFC_STATE_OPEN         1
89 #define WLFC_STATE_CLOSE        2
90
91 #define WLFC_PSQ_PREC_COUNT             ((AC_COUNT + 1) * 2) /* 2 for each AC traffic and bc/mc */
92 #define WLFC_PSQ_LEN                    64
93 #define WLFC_SENDQ_LEN                  256
94
95 #define WLFC_FLOWCONTROL_DELTA          8
96 #define WLFC_FLOWCONTROL_HIWATER        (WLFC_PSQ_LEN - WLFC_FLOWCONTROL_DELTA)
97 #define WLFC_FLOWCONTROL_LOWATER        (WLFC_FLOWCONTROL_HIWATER - WLFC_FLOWCONTROL_DELTA)
98
99 typedef struct wlfc_mac_descriptor {
100         uint8 occupied;
101         uint8 interface_id;
102         uint8 iftype;
103         uint8 state;
104         uint8 ac_bitmap; /* for APSD */
105         uint8 requested_credit;
106         uint8 requested_packet;
107         uint8 ea[ETHER_ADDR_LEN];
108         /*
109         maintain (MAC,AC) based seq count for
110         packets going to the device. As well as bc/mc.
111         */
112         uint8 seq[AC_COUNT + 1];
113         uint8 generation;
114         struct pktq     psq;
115         /* The AC pending bitmap that was reported to the fw at last change */
116         uint8 traffic_lastreported_bmp;
117         /* The new AC pending bitmap */
118         uint8 traffic_pending_bmp;
119         /* 1= send on next opportunity */
120         uint8 send_tim_signal;
121         uint8 mac_handle;
122 } wlfc_mac_descriptor_t;
123
124 #define WLFC_DECR_SEQCOUNT(entry, prec) do { if (entry->seq[(prec)] == 0) {\
125         entry->seq[prec] = 0xff; } else entry->seq[prec]--;} while (0)
126
127 #define WLFC_INCR_SEQCOUNT(entry, prec) entry->seq[(prec)]++
128 #define WLFC_SEQCOUNT(entry, prec) entry->seq[(prec)]
129
130 typedef struct athost_wl_stat_counters {
131         uint32  pktin;
132         uint32  pkt2bus;
133         uint32  pktdropped;
134         uint32  tlv_parse_failed;
135         uint32  rollback;
136         uint32  rollback_failed;
137         uint32  sendq_full_error;
138         uint32  delayq_full_error;
139         uint32  credit_request_failed;
140         uint32  packet_request_failed;
141         uint32  mac_update_failed;
142         uint32  psmode_update_failed;
143         uint32  interface_update_failed;
144         uint32  wlfc_header_only_pkt;
145         uint32  txstatus_in;
146         uint32  d11_suppress;
147         uint32  wl_suppress;
148         uint32  bad_suppress;
149         uint32  pkt_freed;
150         uint32  pkt_free_err;
151         uint32  psq_wlsup_retx;
152         uint32  psq_wlsup_enq;
153         uint32  psq_d11sup_retx;
154         uint32  psq_d11sup_enq;
155         uint32  psq_hostq_retx;
156         uint32  psq_hostq_enq;
157         uint32  mac_handle_notfound;
158         uint32  wlc_tossed_pkts;
159         uint32  dhd_hdrpulls;
160         uint32  generic_error;
161         /* an extra one for bc/mc traffic */
162         uint32  sendq_pkts[AC_COUNT + 1];
163 } athost_wl_stat_counters_t;
164
165 #define WLFC_HOST_FIFO_CREDIT_INC_SENTCTRS(ctx, ac) do {} while (0)
166 #define WLFC_HOST_FIFO_CREDIT_INC_BACKCTRS(ctx, ac) do {} while (0)
167 #define WLFC_HOST_FIFO_DROPPEDCTR_INC(ctx, ac) do {} while (0)
168
169 #define WLFC_FCMODE_NONE                                0
170 #define WLFC_FCMODE_IMPLIED_CREDIT              1
171 #define WLFC_FCMODE_EXPLICIT_CREDIT             2
172
173 typedef struct athost_wl_status_info {
174         uint8   last_seqid_to_wlc;
175
176         /* OSL handle */
177         osl_t*  osh;
178         /* dhd pub */
179         void*   dhdp;
180
181         /* stats */
182         athost_wl_stat_counters_t stats;
183
184         /* the additional ones are for bc/mc and ATIM FIFO */
185         int     FIFO_credit[AC_COUNT + 2];
186         struct  pktq SENDQ;
187
188         /* packet hanger and MAC->handle lookup table */
189         void*   hanger;
190         struct {
191                 /* table for individual nodes */
192                 wlfc_mac_descriptor_t   nodes[WLFC_MAC_DESC_TABLE_SIZE];
193                 /* table for interfaces */
194                 wlfc_mac_descriptor_t   interfaces[WLFC_MAX_IFNUM];
195                 /* OS may send packets to unknown (unassociated) destinations */
196                 /* A place holder for bc/mc and packets to unknown destinations */
197                 wlfc_mac_descriptor_t   other;
198         } destination_entries;
199         /* token position for different priority packets */
200         uint8   token_pos[AC_COUNT];
201         /* ON/OFF state for flow control to the host network interface */
202         uint8   hostif_flow_state[WLFC_MAX_IFNUM];
203         uint8   host_ifidx;
204         /* to flow control an OS interface */
205         uint8   toggle_host_if;
206
207         /*
208         Mode in which the dhd flow control shall operate. Must be set before
209         traffic starts to the device.
210         0 - Do not do any proptxtstatus flow control
211         1 - Use implied credit from a packet status
212         2 - Use explicit credit
213         */
214         uint8   proptxstatus_mode;
215 } athost_wl_status_info_t;
216
217 #endif /* __wlfc_host_driver_definitions_h__ */