blob: bba4ff04ee1976cad7ac04b53afda62df6add5d0 [file] [log] [blame]
Arend van Spriel349e7102013-03-03 12:45:28 +01001/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16#include <linux/types.h>
Arend van Sprielc7f34a62013-04-03 12:40:39 +020017#include <linux/module.h>
Arend van Spriel349e7102013-03-03 12:45:28 +010018#include <linux/if_ether.h>
19#include <linux/spinlock.h>
20#include <linux/skbuff.h>
21#include <linux/netdevice.h>
Arend van Spriel3edc1cf2013-04-03 12:40:40 +020022#include <linux/etherdevice.h>
Arend van Spriel349e7102013-03-03 12:45:28 +010023#include <linux/err.h>
Arend van Spriel1aac1e92013-04-23 12:53:15 +020024#include <linux/jiffies.h>
Arend van Spriel349e7102013-03-03 12:45:28 +010025#include <uapi/linux/nl80211.h>
Arend van Spriel3edc1cf2013-04-03 12:40:40 +020026#include <net/cfg80211.h>
Arend van Spriel349e7102013-03-03 12:45:28 +010027
28#include <brcmu_utils.h>
29#include <brcmu_wifi.h>
30#include "dhd.h"
Arend van Spriel3edc1cf2013-04-03 12:40:40 +020031#include "dhd_proto.h"
Arend van Spriel349e7102013-03-03 12:45:28 +010032#include "dhd_dbg.h"
Arend van Spriele2432b62013-04-03 12:40:38 +020033#include "dhd_bus.h"
Arend van Spriel349e7102013-03-03 12:45:28 +010034#include "fwil.h"
Arend van Spriela7965fb2013-04-11 17:08:37 +020035#include "fwil_types.h"
Arend van Spriel349e7102013-03-03 12:45:28 +010036#include "fweh.h"
37#include "fwsignal.h"
Arend van Spriela7965fb2013-04-11 17:08:37 +020038#include "p2p.h"
39#include "wl_cfg80211.h"
Arend van Spriel349e7102013-03-03 12:45:28 +010040
41/**
42 * DOC: Firmware Signalling
43 *
44 * Firmware can send signals to host and vice versa, which are passed in the
45 * data packets using TLV based header. This signalling layer is on top of the
46 * BDC bus protocol layer.
47 */
48
49/*
50 * single definition for firmware-driver flow control tlv's.
51 *
52 * each tlv is specified by BRCMF_FWS_TLV_DEF(name, ID, length).
53 * A length value 0 indicates variable length tlv.
54 */
55#define BRCMF_FWS_TLV_DEFLIST \
56 BRCMF_FWS_TLV_DEF(MAC_OPEN, 1, 1) \
57 BRCMF_FWS_TLV_DEF(MAC_CLOSE, 2, 1) \
58 BRCMF_FWS_TLV_DEF(MAC_REQUEST_CREDIT, 3, 2) \
59 BRCMF_FWS_TLV_DEF(TXSTATUS, 4, 4) \
60 BRCMF_FWS_TLV_DEF(PKTTAG, 5, 4) \
61 BRCMF_FWS_TLV_DEF(MACDESC_ADD, 6, 8) \
62 BRCMF_FWS_TLV_DEF(MACDESC_DEL, 7, 8) \
63 BRCMF_FWS_TLV_DEF(RSSI, 8, 1) \
64 BRCMF_FWS_TLV_DEF(INTERFACE_OPEN, 9, 1) \
65 BRCMF_FWS_TLV_DEF(INTERFACE_CLOSE, 10, 1) \
Arend van Spriel94607232013-04-03 12:40:46 +020066 BRCMF_FWS_TLV_DEF(FIFO_CREDITBACK, 11, 6) \
Arend van Spriel349e7102013-03-03 12:45:28 +010067 BRCMF_FWS_TLV_DEF(PENDING_TRAFFIC_BMP, 12, 2) \
68 BRCMF_FWS_TLV_DEF(MAC_REQUEST_PACKET, 13, 3) \
69 BRCMF_FWS_TLV_DEF(HOST_REORDER_RXPKTS, 14, 10) \
70 BRCMF_FWS_TLV_DEF(TRANS_ID, 18, 6) \
71 BRCMF_FWS_TLV_DEF(COMP_TXSTATUS, 19, 1) \
72 BRCMF_FWS_TLV_DEF(FILLER, 255, 0)
73
Arend van Spriel3edc1cf2013-04-03 12:40:40 +020074/*
Arend van Spriel349e7102013-03-03 12:45:28 +010075 * enum brcmf_fws_tlv_type - definition of tlv identifiers.
76 */
77#define BRCMF_FWS_TLV_DEF(name, id, len) \
78 BRCMF_FWS_TYPE_ ## name = id,
79enum brcmf_fws_tlv_type {
80 BRCMF_FWS_TLV_DEFLIST
81 BRCMF_FWS_TYPE_INVALID
82};
83#undef BRCMF_FWS_TLV_DEF
84
Arend van Spriel3edc1cf2013-04-03 12:40:40 +020085/*
86 * enum brcmf_fws_tlv_len - definition of tlv lengths.
87 */
88#define BRCMF_FWS_TLV_DEF(name, id, len) \
89 BRCMF_FWS_TYPE_ ## name ## _LEN = (len),
90enum brcmf_fws_tlv_len {
91 BRCMF_FWS_TLV_DEFLIST
92};
93#undef BRCMF_FWS_TLV_DEF
94
Arend van Spriel349e7102013-03-03 12:45:28 +010095#ifdef DEBUG
Arend van Spriel3edc1cf2013-04-03 12:40:40 +020096/*
Arend van Spriel349e7102013-03-03 12:45:28 +010097 * brcmf_fws_tlv_names - array of tlv names.
98 */
99#define BRCMF_FWS_TLV_DEF(name, id, len) \
100 { id, #name },
101static struct {
102 enum brcmf_fws_tlv_type id;
103 const char *name;
104} brcmf_fws_tlv_names[] = {
105 BRCMF_FWS_TLV_DEFLIST
106};
107#undef BRCMF_FWS_TLV_DEF
108
109static const char *brcmf_fws_get_tlv_name(enum brcmf_fws_tlv_type id)
110{
111 int i;
112
113 for (i = 0; i < ARRAY_SIZE(brcmf_fws_tlv_names); i++)
114 if (brcmf_fws_tlv_names[i].id == id)
115 return brcmf_fws_tlv_names[i].name;
116
117 return "INVALID";
118}
119#else
120static const char *brcmf_fws_get_tlv_name(enum brcmf_fws_tlv_type id)
121{
122 return "NODEBUG";
123}
124#endif /* DEBUG */
125
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200126/*
Arend van Spriel349e7102013-03-03 12:45:28 +0100127 * flags used to enable tlv signalling from firmware.
128 */
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200129#define BRCMF_FWS_FLAGS_RSSI_SIGNALS 0x0001
130#define BRCMF_FWS_FLAGS_XONXOFF_SIGNALS 0x0002
131#define BRCMF_FWS_FLAGS_CREDIT_STATUS_SIGNALS 0x0004
132#define BRCMF_FWS_FLAGS_HOST_PROPTXSTATUS_ACTIVE 0x0008
133#define BRCMF_FWS_FLAGS_PSQ_GENERATIONFSM_ENABLE 0x0010
134#define BRCMF_FWS_FLAGS_PSQ_ZERO_BUFFER_ENABLE 0x0020
135#define BRCMF_FWS_FLAGS_HOST_RXREORDER_ACTIVE 0x0040
Arend van Spriel349e7102013-03-03 12:45:28 +0100136
Arend van Spriel349e7102013-03-03 12:45:28 +0100137#define BRCMF_FWS_MAC_DESC_TABLE_SIZE 32
Arend van Spriel349e7102013-03-03 12:45:28 +0100138#define BRCMF_FWS_MAC_DESC_ID_INVALID 0xff
139
140#define BRCMF_FWS_HOSTIF_FLOWSTATE_OFF 0
141#define BRCMF_FWS_HOSTIF_FLOWSTATE_ON 1
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200142#define BRCMF_FWS_FLOWCONTROL_HIWATER 128
143#define BRCMF_FWS_FLOWCONTROL_LOWATER 64
Arend van Spriel349e7102013-03-03 12:45:28 +0100144
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200145#define BRCMF_FWS_PSQ_PREC_COUNT ((NL80211_NUM_ACS + 1) * 2)
146#define BRCMF_FWS_PSQ_LEN 256
147
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200148#define BRCMF_FWS_HTOD_FLAG_PKTFROMHOST 0x01
149#define BRCMF_FWS_HTOD_FLAG_PKT_REQUESTED 0x02
150
Arend van Spriela5e9d802013-04-17 21:25:54 +0200151#define BRCMF_FWS_RET_OK_NOSCHEDULE 0
152#define BRCMF_FWS_RET_OK_SCHEDULE 1
153
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200154/**
Arend van Sprielebb93882013-04-03 12:40:35 +0200155 * enum brcmf_fws_skb_state - indicates processing state of skb.
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200156 *
157 * @BRCMF_FWS_SKBSTATE_NEW: sk_buff is newly arrived in the driver.
158 * @BRCMF_FWS_SKBSTATE_DELAYED: sk_buff had to wait on queue.
159 * @BRCMF_FWS_SKBSTATE_SUPPRESSED: sk_buff has been suppressed by firmware.
Arend van Sprielebb93882013-04-03 12:40:35 +0200160 */
161enum brcmf_fws_skb_state {
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200162 BRCMF_FWS_SKBSTATE_NEW,
163 BRCMF_FWS_SKBSTATE_DELAYED,
164 BRCMF_FWS_SKBSTATE_SUPPRESSED
Arend van Sprielebb93882013-04-03 12:40:35 +0200165};
166
167/**
168 * struct brcmf_skbuff_cb - control buffer associated with skbuff.
169 *
170 * @if_flags: holds interface index and packet related flags.
Arend van Sprielebb93882013-04-03 12:40:35 +0200171 * @htod: host to device packet identifier (used in PKTTAG tlv).
Arend van Sprielebb93882013-04-03 12:40:35 +0200172 * @state: transmit state of the packet.
173 * @mac: descriptor related to destination for this packet.
174 *
175 * This information is stored in control buffer struct sk_buff::cb, which
176 * provides 48 bytes of storage so this structure should not exceed that.
177 */
178struct brcmf_skbuff_cb {
179 u16 if_flags;
Arend van Sprielebb93882013-04-03 12:40:35 +0200180 u32 htod;
Arend van Sprielebb93882013-04-03 12:40:35 +0200181 enum brcmf_fws_skb_state state;
182 struct brcmf_fws_mac_descriptor *mac;
183};
184
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200185/*
Arend van Sprielebb93882013-04-03 12:40:35 +0200186 * macro casting skbuff control buffer to struct brcmf_skbuff_cb.
187 */
188#define brcmf_skbcb(skb) ((struct brcmf_skbuff_cb *)((skb)->cb))
189
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200190/*
Arend van Sprielebb93882013-04-03 12:40:35 +0200191 * sk_buff control if flags
192 *
Arend van Spriel289ec1c2013-06-06 13:17:50 +0200193 * b[12] - packet sent upon credit request.
194 * b[11] - packet sent upon packet request.
Arend van Sprielebb93882013-04-03 12:40:35 +0200195 * b[10] - packet only contains signalling data.
196 * b[9] - packet is a tx packet.
197 * b[8] - packet uses FIFO credit (non-pspoll).
198 * b[7] - interface in AP mode.
Arend van Sprielebb93882013-04-03 12:40:35 +0200199 * b[3:0] - interface index.
200 */
Arend van Spriel289ec1c2013-06-06 13:17:50 +0200201#define BRCMF_SKB_IF_FLAGS_REQ_CREDIT_MASK 0x1000
202#define BRCMF_SKB_IF_FLAGS_REQ_CREDIT_SHIFT 12
Arend van Sprielebb93882013-04-03 12:40:35 +0200203#define BRCMF_SKB_IF_FLAGS_REQUESTED_MASK 0x0800
204#define BRCMF_SKB_IF_FLAGS_REQUESTED_SHIFT 11
205#define BRCMF_SKB_IF_FLAGS_SIGNAL_ONLY_MASK 0x0400
206#define BRCMF_SKB_IF_FLAGS_SIGNAL_ONLY_SHIFT 10
207#define BRCMF_SKB_IF_FLAGS_TRANSMIT_MASK 0x0200
208#define BRCMF_SKB_IF_FLAGS_TRANSMIT_SHIFT 9
209#define BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK 0x0100
210#define BRCMF_SKB_IF_FLAGS_CREDITCHECK_SHIFT 8
211#define BRCMF_SKB_IF_FLAGS_IF_AP_MASK 0x0080
212#define BRCMF_SKB_IF_FLAGS_IF_AP_SHIFT 7
Arend van Sprielebb93882013-04-03 12:40:35 +0200213#define BRCMF_SKB_IF_FLAGS_INDEX_MASK 0x000f
214#define BRCMF_SKB_IF_FLAGS_INDEX_SHIFT 0
215
216#define brcmf_skb_if_flags_set_field(skb, field, value) \
217 brcmu_maskset16(&(brcmf_skbcb(skb)->if_flags), \
218 BRCMF_SKB_IF_FLAGS_ ## field ## _MASK, \
219 BRCMF_SKB_IF_FLAGS_ ## field ## _SHIFT, (value))
220#define brcmf_skb_if_flags_get_field(skb, field) \
221 brcmu_maskget16(brcmf_skbcb(skb)->if_flags, \
222 BRCMF_SKB_IF_FLAGS_ ## field ## _MASK, \
223 BRCMF_SKB_IF_FLAGS_ ## field ## _SHIFT)
224
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200225/*
Arend van Sprielebb93882013-04-03 12:40:35 +0200226 * sk_buff control packet identifier
227 *
228 * 32-bit packet identifier used in PKTTAG tlv from host to dongle.
229 *
230 * - Generated at the host (e.g. dhd)
231 * - Seen as a generic sequence number by firmware except for the flags field.
232 *
233 * Generation : b[31] => generation number for this packet [host->fw]
234 * OR, current generation number [fw->host]
235 * Flags : b[30:27] => command, status flags
236 * FIFO-AC : b[26:24] => AC-FIFO id
237 * h-slot : b[23:8] => hanger-slot
238 * freerun : b[7:0] => A free running counter
239 */
240#define BRCMF_SKB_HTOD_TAG_GENERATION_MASK 0x80000000
241#define BRCMF_SKB_HTOD_TAG_GENERATION_SHIFT 31
242#define BRCMF_SKB_HTOD_TAG_FLAGS_MASK 0x78000000
243#define BRCMF_SKB_HTOD_TAG_FLAGS_SHIFT 27
244#define BRCMF_SKB_HTOD_TAG_FIFO_MASK 0x07000000
245#define BRCMF_SKB_HTOD_TAG_FIFO_SHIFT 24
246#define BRCMF_SKB_HTOD_TAG_HSLOT_MASK 0x00ffff00
247#define BRCMF_SKB_HTOD_TAG_HSLOT_SHIFT 8
248#define BRCMF_SKB_HTOD_TAG_FREERUN_MASK 0x000000ff
Hante Meulemanbe4910a2013-06-06 13:17:53 +0200249#define BRCMF_SKB_HTOD_TAG_FREERUN_SHIFT 0
Arend van Sprielebb93882013-04-03 12:40:35 +0200250
251#define brcmf_skb_htod_tag_set_field(skb, field, value) \
Arend van Spriele2432b62013-04-03 12:40:38 +0200252 brcmu_maskset32(&(brcmf_skbcb(skb)->htod), \
Arend van Sprielebb93882013-04-03 12:40:35 +0200253 BRCMF_SKB_HTOD_TAG_ ## field ## _MASK, \
254 BRCMF_SKB_HTOD_TAG_ ## field ## _SHIFT, (value))
255#define brcmf_skb_htod_tag_get_field(skb, field) \
Arend van Spriele2432b62013-04-03 12:40:38 +0200256 brcmu_maskget32(brcmf_skbcb(skb)->htod, \
Arend van Sprielebb93882013-04-03 12:40:35 +0200257 BRCMF_SKB_HTOD_TAG_ ## field ## _MASK, \
258 BRCMF_SKB_HTOD_TAG_ ## field ## _SHIFT)
259
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200260#define BRCMF_FWS_TXSTAT_GENERATION_MASK 0x80000000
261#define BRCMF_FWS_TXSTAT_GENERATION_SHIFT 31
262#define BRCMF_FWS_TXSTAT_FLAGS_MASK 0x78000000
263#define BRCMF_FWS_TXSTAT_FLAGS_SHIFT 27
264#define BRCMF_FWS_TXSTAT_FIFO_MASK 0x07000000
265#define BRCMF_FWS_TXSTAT_FIFO_SHIFT 24
266#define BRCMF_FWS_TXSTAT_HSLOT_MASK 0x00FFFF00
267#define BRCMF_FWS_TXSTAT_HSLOT_SHIFT 8
268#define BRCMF_FWS_TXSTAT_PKTID_MASK 0x00FFFFFF
269#define BRCMF_FWS_TXSTAT_PKTID_SHIFT 0
270
271#define brcmf_txstatus_get_field(txs, field) \
272 brcmu_maskget32(txs, BRCMF_FWS_TXSTAT_ ## field ## _MASK, \
273 BRCMF_FWS_TXSTAT_ ## field ## _SHIFT)
274
Arend van Spriel1aac1e92013-04-23 12:53:15 +0200275/* How long to defer borrowing in jiffies */
276#define BRCMF_FWS_BORROW_DEFER_PERIOD (HZ / 10)
277
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200278/**
279 * enum brcmf_fws_fifo - fifo indices used by dongle firmware.
280 *
281 * @BRCMF_FWS_FIFO_AC_BK: fifo for background traffic.
282 * @BRCMF_FWS_FIFO_AC_BE: fifo for best-effort traffic.
283 * @BRCMF_FWS_FIFO_AC_VI: fifo for video traffic.
284 * @BRCMF_FWS_FIFO_AC_VO: fifo for voice traffic.
285 * @BRCMF_FWS_FIFO_BCMC: fifo for broadcast/multicast (AP only).
286 * @BRCMF_FWS_FIFO_ATIM: fifo for ATIM (AP only).
287 * @BRCMF_FWS_FIFO_COUNT: number of fifos.
288 */
289enum brcmf_fws_fifo {
290 BRCMF_FWS_FIFO_AC_BK,
291 BRCMF_FWS_FIFO_AC_BE,
292 BRCMF_FWS_FIFO_AC_VI,
293 BRCMF_FWS_FIFO_AC_VO,
294 BRCMF_FWS_FIFO_BCMC,
295 BRCMF_FWS_FIFO_ATIM,
296 BRCMF_FWS_FIFO_COUNT
297};
298
299/**
300 * enum brcmf_fws_txstatus - txstatus flag values.
301 *
302 * @BRCMF_FWS_TXSTATUS_DISCARD:
303 * host is free to discard the packet.
304 * @BRCMF_FWS_TXSTATUS_CORE_SUPPRESS:
305 * 802.11 core suppressed the packet.
306 * @BRCMF_FWS_TXSTATUS_FW_PS_SUPPRESS:
307 * firmware suppress the packet as device is already in PS mode.
308 * @BRCMF_FWS_TXSTATUS_FW_TOSSED:
309 * firmware tossed the packet.
310 */
311enum brcmf_fws_txstatus {
312 BRCMF_FWS_TXSTATUS_DISCARD,
313 BRCMF_FWS_TXSTATUS_CORE_SUPPRESS,
314 BRCMF_FWS_TXSTATUS_FW_PS_SUPPRESS,
315 BRCMF_FWS_TXSTATUS_FW_TOSSED
316};
317
Arend van Sprielc7f34a62013-04-03 12:40:39 +0200318enum brcmf_fws_fcmode {
319 BRCMF_FWS_FCMODE_NONE,
320 BRCMF_FWS_FCMODE_IMPLIED_CREDIT,
321 BRCMF_FWS_FCMODE_EXPLICIT_CREDIT
322};
323
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200324enum brcmf_fws_mac_desc_state {
325 BRCMF_FWS_STATE_OPEN = 1,
326 BRCMF_FWS_STATE_CLOSE
327};
328
Arend van Sprielebb93882013-04-03 12:40:35 +0200329/**
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200330 * struct brcmf_fws_mac_descriptor - firmware signalling data per node/interface
331 *
332 * @occupied: slot is in use.
Arend van Sprielce814c12013-04-03 12:40:31 +0200333 * @mac_handle: handle for mac entry determined by firmware.
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200334 * @interface_id: interface index.
335 * @state: current state.
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200336 * @suppressed: mac entry is suppressed.
337 * @generation: generation bit.
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200338 * @ac_bitmap: ac queue bitmap.
339 * @requested_credit: credits requested by firmware.
340 * @ea: ethernet address.
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200341 * @seq: per-node free-running sequence.
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200342 * @psq: power-save queue.
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200343 * @transit_count: packet in transit to firmware.
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200344 */
345struct brcmf_fws_mac_descriptor {
Arend van Spriel8071fd62013-06-06 13:17:51 +0200346 char name[16];
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200347 u8 occupied;
Arend van Sprielce814c12013-04-03 12:40:31 +0200348 u8 mac_handle;
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200349 u8 interface_id;
350 u8 state;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200351 bool suppressed;
352 u8 generation;
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200353 u8 ac_bitmap;
354 u8 requested_credit;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200355 u8 requested_packet;
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200356 u8 ea[ETH_ALEN];
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200357 u8 seq[BRCMF_FWS_FIFO_COUNT];
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200358 struct pktq psq;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200359 int transit_count;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200360 int suppress_count;
361 int suppr_transit_count;
362 bool send_tim_signal;
363 u8 traffic_pending_bmp;
364 u8 traffic_lastreported_bmp;
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200365};
366
Arend van Spriel69712802013-04-03 12:40:37 +0200367#define BRCMF_FWS_HANGER_MAXITEMS 1024
368
369/**
370 * enum brcmf_fws_hanger_item_state - state of hanger item.
371 *
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200372 * @BRCMF_FWS_HANGER_ITEM_STATE_FREE: item is free for use.
373 * @BRCMF_FWS_HANGER_ITEM_STATE_INUSE: item is in use.
374 * @BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED: item was suppressed.
Arend van Spriel69712802013-04-03 12:40:37 +0200375 */
376enum brcmf_fws_hanger_item_state {
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200377 BRCMF_FWS_HANGER_ITEM_STATE_FREE = 1,
378 BRCMF_FWS_HANGER_ITEM_STATE_INUSE,
379 BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED
Arend van Spriel69712802013-04-03 12:40:37 +0200380};
381
382
383/**
384 * struct brcmf_fws_hanger_item - single entry for tx pending packet.
385 *
386 * @state: entry is either free or occupied.
Arend van Spriel69712802013-04-03 12:40:37 +0200387 * @pkt: packet itself.
388 */
389struct brcmf_fws_hanger_item {
390 enum brcmf_fws_hanger_item_state state;
Arend van Spriel69712802013-04-03 12:40:37 +0200391 struct sk_buff *pkt;
392};
393
394/**
395 * struct brcmf_fws_hanger - holds packets awaiting firmware txstatus.
396 *
Arend van Spriel69712802013-04-03 12:40:37 +0200397 * @pushed: packets pushed to await txstatus.
398 * @popped: packets popped upon handling txstatus.
399 * @failed_to_push: packets that could not be pushed.
400 * @failed_to_pop: packets that could not be popped.
401 * @failed_slotfind: packets for which failed to find an entry.
402 * @slot_pos: last returned item index for a free entry.
403 * @items: array of hanger items.
404 */
405struct brcmf_fws_hanger {
406 u32 pushed;
407 u32 popped;
408 u32 failed_to_push;
409 u32 failed_to_pop;
410 u32 failed_slotfind;
411 u32 slot_pos;
412 struct brcmf_fws_hanger_item items[BRCMF_FWS_HANGER_MAXITEMS];
413};
414
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200415struct brcmf_fws_macdesc_table {
416 struct brcmf_fws_mac_descriptor nodes[BRCMF_FWS_MAC_DESC_TABLE_SIZE];
417 struct brcmf_fws_mac_descriptor iface[BRCMF_MAX_IFS];
418 struct brcmf_fws_mac_descriptor other;
419};
420
Arend van Spriel349e7102013-03-03 12:45:28 +0100421struct brcmf_fws_info {
422 struct brcmf_pub *drvr;
423 struct brcmf_fws_stats stats;
Arend van Spriel69712802013-04-03 12:40:37 +0200424 struct brcmf_fws_hanger hanger;
Arend van Sprielc7f34a62013-04-03 12:40:39 +0200425 enum brcmf_fws_fcmode fcmode;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200426 struct brcmf_fws_macdesc_table desc;
427 struct workqueue_struct *fws_wq;
428 struct work_struct fws_dequeue_work;
429 u32 fifo_enqpkt[BRCMF_FWS_FIFO_COUNT];
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200430 int fifo_credit[BRCMF_FWS_FIFO_COUNT];
Arend van Spriel1aac1e92013-04-23 12:53:15 +0200431 int credits_borrowed[BRCMF_FWS_FIFO_AC_VO + 1];
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200432 int deq_node_pos[BRCMF_FWS_FIFO_COUNT];
433 u32 fifo_credit_map;
434 u32 fifo_delay_map;
Arend van Spriel1aac1e92013-04-23 12:53:15 +0200435 unsigned long borrow_defer_timestamp;
Hante Meulemandf50f752013-06-06 13:17:48 +0200436 bool bus_flow_blocked;
Hante Meuleman0d24b0e2013-06-06 13:17:58 +0200437 bool creditmap_received;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200438};
439
440/*
441 * brcmf_fws_prio2fifo - mapping from 802.1d priority to firmware fifo index.
442 */
443static const int brcmf_fws_prio2fifo[] = {
444 BRCMF_FWS_FIFO_AC_BE,
445 BRCMF_FWS_FIFO_AC_BK,
446 BRCMF_FWS_FIFO_AC_BK,
447 BRCMF_FWS_FIFO_AC_BE,
448 BRCMF_FWS_FIFO_AC_VI,
449 BRCMF_FWS_FIFO_AC_VI,
450 BRCMF_FWS_FIFO_AC_VO,
451 BRCMF_FWS_FIFO_AC_VO
Arend van Spriel349e7102013-03-03 12:45:28 +0100452};
453
Arend van Sprielc7f34a62013-04-03 12:40:39 +0200454static int fcmode;
455module_param(fcmode, int, S_IRUSR);
456MODULE_PARM_DESC(fcmode, "mode of firmware signalled flow control");
457
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200458#define BRCMF_FWS_TLV_DEF(name, id, len) \
459 case BRCMF_FWS_TYPE_ ## name: \
460 return len;
461
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200462/**
463 * brcmf_fws_get_tlv_len() - returns defined length for given tlv id.
464 *
465 * @fws: firmware-signalling information.
466 * @id: identifier of the TLV.
467 *
468 * Return: the specified length for the given TLV; Otherwise -EINVAL.
469 */
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200470static int brcmf_fws_get_tlv_len(struct brcmf_fws_info *fws,
471 enum brcmf_fws_tlv_type id)
472{
473 switch (id) {
474 BRCMF_FWS_TLV_DEFLIST
475 default:
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200476 fws->stats.tlv_invalid_type++;
477 break;
478 }
479 return -EINVAL;
480}
481#undef BRCMF_FWS_TLV_DEF
482
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200483static bool brcmf_fws_ifidx_match(struct sk_buff *skb, void *arg)
484{
485 u32 ifidx = brcmf_skb_if_flags_get_field(skb, INDEX);
486 return ifidx == *(int *)arg;
487}
488
489static void brcmf_fws_psq_flush(struct brcmf_fws_info *fws, struct pktq *q,
490 int ifidx)
491{
492 bool (*matchfn)(struct sk_buff *, void *) = NULL;
493 struct sk_buff *skb;
494 int prec;
495
496 if (ifidx != -1)
497 matchfn = brcmf_fws_ifidx_match;
498 for (prec = 0; prec < q->num_prec; prec++) {
499 skb = brcmu_pktq_pdeq_match(q, prec, matchfn, &ifidx);
500 while (skb) {
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200501 brcmu_pkt_buf_free_skb(skb);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200502 skb = brcmu_pktq_pdeq_match(q, prec, matchfn, &ifidx);
503 }
504 }
505}
506
Arend van Spriel69712802013-04-03 12:40:37 +0200507static void brcmf_fws_hanger_init(struct brcmf_fws_hanger *hanger)
508{
509 int i;
510
Arend van Spriel69712802013-04-03 12:40:37 +0200511 memset(hanger, 0, sizeof(*hanger));
512 for (i = 0; i < ARRAY_SIZE(hanger->items); i++)
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200513 hanger->items[i].state = BRCMF_FWS_HANGER_ITEM_STATE_FREE;
Arend van Spriel69712802013-04-03 12:40:37 +0200514}
515
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200516static u32 brcmf_fws_hanger_get_free_slot(struct brcmf_fws_hanger *h)
Arend van Spriel69712802013-04-03 12:40:37 +0200517{
518 u32 i;
519
Arend van Spriel69712802013-04-03 12:40:37 +0200520 i = (h->slot_pos + 1) % BRCMF_FWS_HANGER_MAXITEMS;
521
522 while (i != h->slot_pos) {
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200523 if (h->items[i].state == BRCMF_FWS_HANGER_ITEM_STATE_FREE) {
Arend van Spriel69712802013-04-03 12:40:37 +0200524 h->slot_pos = i;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200525 goto done;
Arend van Spriel69712802013-04-03 12:40:37 +0200526 }
527 i++;
528 if (i == BRCMF_FWS_HANGER_MAXITEMS)
529 i = 0;
530 }
531 brcmf_err("all slots occupied\n");
532 h->failed_slotfind++;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200533 i = BRCMF_FWS_HANGER_MAXITEMS;
534done:
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200535 return i;
Arend van Spriel69712802013-04-03 12:40:37 +0200536}
537
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200538static int brcmf_fws_hanger_pushpkt(struct brcmf_fws_hanger *h,
Hante Meulemanbe4910a2013-06-06 13:17:53 +0200539 struct sk_buff *pkt, u32 slot_id)
Arend van Spriel69712802013-04-03 12:40:37 +0200540{
Arend van Spriel69712802013-04-03 12:40:37 +0200541 if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS)
542 return -ENOENT;
543
544 if (h->items[slot_id].state != BRCMF_FWS_HANGER_ITEM_STATE_FREE) {
545 brcmf_err("slot is not free\n");
546 h->failed_to_push++;
547 return -EINVAL;
548 }
549
550 h->items[slot_id].state = BRCMF_FWS_HANGER_ITEM_STATE_INUSE;
551 h->items[slot_id].pkt = pkt;
Arend van Spriel69712802013-04-03 12:40:37 +0200552 h->pushed++;
553 return 0;
554}
555
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200556static int brcmf_fws_hanger_poppkt(struct brcmf_fws_hanger *h,
Arend van Spriel69712802013-04-03 12:40:37 +0200557 u32 slot_id, struct sk_buff **pktout,
558 bool remove_item)
559{
Arend van Spriel69712802013-04-03 12:40:37 +0200560 if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS)
561 return -ENOENT;
562
563 if (h->items[slot_id].state == BRCMF_FWS_HANGER_ITEM_STATE_FREE) {
564 brcmf_err("entry not in use\n");
565 h->failed_to_pop++;
566 return -EINVAL;
567 }
568
569 *pktout = h->items[slot_id].pkt;
570 if (remove_item) {
571 h->items[slot_id].state = BRCMF_FWS_HANGER_ITEM_STATE_FREE;
572 h->items[slot_id].pkt = NULL;
Arend van Spriel69712802013-04-03 12:40:37 +0200573 h->popped++;
574 }
575 return 0;
576}
577
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200578static int brcmf_fws_hanger_mark_suppressed(struct brcmf_fws_hanger *h,
Hante Meulemanbe4910a2013-06-06 13:17:53 +0200579 u32 slot_id)
Arend van Spriel69712802013-04-03 12:40:37 +0200580{
Arend van Spriel69712802013-04-03 12:40:37 +0200581 if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS)
582 return -ENOENT;
583
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200584 if (h->items[slot_id].state != BRCMF_FWS_HANGER_ITEM_STATE_INUSE) {
Arend van Spriel69712802013-04-03 12:40:37 +0200585 brcmf_err("entry not in use\n");
586 return -EINVAL;
587 }
588
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200589 h->items[slot_id].state = BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED;
Arend van Spriel69712802013-04-03 12:40:37 +0200590 return 0;
591}
592
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200593static void brcmf_fws_hanger_cleanup(struct brcmf_fws_info *fws,
Arend van Spriel69712802013-04-03 12:40:37 +0200594 bool (*fn)(struct sk_buff *, void *),
595 int ifidx)
596{
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200597 struct brcmf_fws_hanger *h = &fws->hanger;
Arend van Spriel69712802013-04-03 12:40:37 +0200598 struct sk_buff *skb;
599 int i;
600 enum brcmf_fws_hanger_item_state s;
601
Arend van Spriel69712802013-04-03 12:40:37 +0200602 for (i = 0; i < ARRAY_SIZE(h->items); i++) {
603 s = h->items[i].state;
604 if (s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE ||
605 s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED) {
606 skb = h->items[i].pkt;
607 if (fn == NULL || fn(skb, &ifidx)) {
608 /* suppress packets freed from psq */
609 if (s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE)
610 brcmu_pkt_buf_free_skb(skb);
611 h->items[i].state =
612 BRCMF_FWS_HANGER_ITEM_STATE_FREE;
613 }
614 }
615 }
616}
617
Arend van Spriel8071fd62013-06-06 13:17:51 +0200618static void brcmf_fws_macdesc_set_name(struct brcmf_fws_info *fws,
619 struct brcmf_fws_mac_descriptor *desc)
620{
621 if (desc == &fws->desc.other)
622 strlcpy(desc->name, "MAC-OTHER", sizeof(desc->name));
623 else if (desc->mac_handle)
624 scnprintf(desc->name, sizeof(desc->name), "MAC-%d:%d",
625 desc->mac_handle, desc->interface_id);
626 else
627 scnprintf(desc->name, sizeof(desc->name), "MACIF:%d",
628 desc->interface_id);
629}
630
Arend van Sprielce814c12013-04-03 12:40:31 +0200631static void brcmf_fws_init_mac_descriptor(struct brcmf_fws_mac_descriptor *desc,
632 u8 *addr, u8 ifidx)
633{
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200634 brcmf_dbg(TRACE,
635 "enter: desc %p ea=%pM, ifidx=%u\n", desc, addr, ifidx);
Arend van Sprielce814c12013-04-03 12:40:31 +0200636 desc->occupied = 1;
637 desc->state = BRCMF_FWS_STATE_OPEN;
638 desc->requested_credit = 0;
639 /* depending on use may need ifp->bssidx instead */
640 desc->interface_id = ifidx;
641 desc->ac_bitmap = 0xff; /* update this when handling APSD */
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200642 if (addr)
643 memcpy(&desc->ea[0], addr, ETH_ALEN);
Arend van Sprielce814c12013-04-03 12:40:31 +0200644}
645
646static
647void brcmf_fws_clear_mac_descriptor(struct brcmf_fws_mac_descriptor *desc)
648{
649 brcmf_dbg(TRACE,
650 "enter: ea=%pM, ifidx=%u\n", desc->ea, desc->interface_id);
651 desc->occupied = 0;
652 desc->state = BRCMF_FWS_STATE_CLOSE;
653 desc->requested_credit = 0;
654}
655
656static struct brcmf_fws_mac_descriptor *
657brcmf_fws_mac_descriptor_lookup(struct brcmf_fws_info *fws, u8 *ea)
658{
659 struct brcmf_fws_mac_descriptor *entry;
660 int i;
661
Arend van Sprielce814c12013-04-03 12:40:31 +0200662 if (ea == NULL)
663 return ERR_PTR(-EINVAL);
664
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200665 entry = &fws->desc.nodes[0];
666 for (i = 0; i < ARRAY_SIZE(fws->desc.nodes); i++) {
Arend van Sprielce814c12013-04-03 12:40:31 +0200667 if (entry->occupied && !memcmp(entry->ea, ea, ETH_ALEN))
668 return entry;
669 entry++;
670 }
671
672 return ERR_PTR(-ENOENT);
673}
674
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200675static struct brcmf_fws_mac_descriptor*
Arend van Sprielf97a7f02013-04-11 13:28:58 +0200676brcmf_fws_find_mac_desc(struct brcmf_fws_info *fws, struct brcmf_if *ifp,
677 u8 *da)
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200678{
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200679 struct brcmf_fws_mac_descriptor *entry = &fws->desc.other;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200680 bool multicast;
Arend van Sprielf97a7f02013-04-11 13:28:58 +0200681
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200682 multicast = is_multicast_ether_addr(da);
Arend van Spriela7965fb2013-04-11 17:08:37 +0200683
Hante Meuleman5cd51c22013-06-06 13:17:56 +0200684 /* Multicast destination, STA and P2P clients get the interface entry.
685 * STA/GC gets the Mac Entry for TDLS destinations, TDLS destinations
686 * have their own entry.
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200687 */
Hante Meuleman5cd51c22013-06-06 13:17:56 +0200688 if (multicast && ifp->fws_desc) {
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200689 entry = ifp->fws_desc;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200690 goto done;
Hante Meuleman5cd51c22013-06-06 13:17:56 +0200691 }
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200692
693 entry = brcmf_fws_mac_descriptor_lookup(fws, da);
694 if (IS_ERR(entry))
Hante Meuleman5cd51c22013-06-06 13:17:56 +0200695 entry = ifp->fws_desc;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200696
697done:
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200698 return entry;
699}
700
Arend van Sprielb75c1a32013-04-17 21:25:53 +0200701static bool brcmf_fws_mac_desc_closed(struct brcmf_fws_info *fws,
702 struct brcmf_fws_mac_descriptor *entry,
Arend van Spriel9fc60222013-04-11 17:12:04 +0200703 int fifo)
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200704{
Arend van Sprielb75c1a32013-04-17 21:25:53 +0200705 struct brcmf_fws_mac_descriptor *if_entry;
Arend van Spriel9fc60222013-04-11 17:12:04 +0200706 bool closed;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200707
Arend van Sprielb75c1a32013-04-17 21:25:53 +0200708 /* for unique destination entries the related interface
709 * may be closed.
710 */
711 if (entry->mac_handle) {
712 if_entry = &fws->desc.iface[entry->interface_id];
713 if (if_entry->state == BRCMF_FWS_STATE_CLOSE)
714 return true;
715 }
Arend van Spriel9fc60222013-04-11 17:12:04 +0200716 /* an entry is closed when the state is closed and
717 * the firmware did not request anything.
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200718 */
Arend van Spriel9fc60222013-04-11 17:12:04 +0200719 closed = entry->state == BRCMF_FWS_STATE_CLOSE &&
720 !entry->requested_credit && !entry->requested_packet;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200721
Arend van Spriel9fc60222013-04-11 17:12:04 +0200722 /* Or firmware does not allow traffic for given fifo */
723 return closed || !(entry->ac_bitmap & BIT(fifo));
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200724}
725
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200726static void brcmf_fws_mac_desc_cleanup(struct brcmf_fws_info *fws,
727 struct brcmf_fws_mac_descriptor *entry,
Arend van Sprielfba14002013-04-03 12:40:33 +0200728 int ifidx)
729{
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200730 if (entry->occupied && (ifidx == -1 || ifidx == entry->interface_id)) {
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200731 brcmf_fws_psq_flush(fws, &entry->psq, ifidx);
Arend van Sprielfba14002013-04-03 12:40:33 +0200732 entry->occupied = !!(entry->psq.len);
733 }
734}
735
Arend van Spriele2432b62013-04-03 12:40:38 +0200736static void brcmf_fws_bus_txq_cleanup(struct brcmf_fws_info *fws,
737 bool (*fn)(struct sk_buff *, void *),
738 int ifidx)
739{
740 struct brcmf_fws_hanger_item *hi;
741 struct pktq *txq;
742 struct sk_buff *skb;
743 int prec;
744 u32 hslot;
745
Arend van Spriele2432b62013-04-03 12:40:38 +0200746 txq = brcmf_bus_gettxq(fws->drvr->bus_if);
747 if (IS_ERR(txq)) {
748 brcmf_dbg(TRACE, "no txq to clean up\n");
749 return;
750 }
751
752 for (prec = 0; prec < txq->num_prec; prec++) {
753 skb = brcmu_pktq_pdeq_match(txq, prec, fn, &ifidx);
754 while (skb) {
755 hslot = brcmf_skb_htod_tag_get_field(skb, HSLOT);
756 hi = &fws->hanger.items[hslot];
757 WARN_ON(skb != hi->pkt);
758 hi->state = BRCMF_FWS_HANGER_ITEM_STATE_FREE;
759 brcmu_pkt_buf_free_skb(skb);
760 skb = brcmu_pktq_pdeq_match(txq, prec, fn, &ifidx);
761 }
762 }
763}
764
Arend van Sprielfba14002013-04-03 12:40:33 +0200765static void brcmf_fws_cleanup(struct brcmf_fws_info *fws, int ifidx)
766{
767 int i;
768 struct brcmf_fws_mac_descriptor *table;
Arend van Spriela3e993c2013-04-03 12:40:36 +0200769 bool (*matchfn)(struct sk_buff *, void *) = NULL;
Arend van Sprielfba14002013-04-03 12:40:33 +0200770
Arend van Sprielfba14002013-04-03 12:40:33 +0200771 if (fws == NULL)
772 return;
773
Arend van Spriela3e993c2013-04-03 12:40:36 +0200774 if (ifidx != -1)
775 matchfn = brcmf_fws_ifidx_match;
776
Arend van Sprielfba14002013-04-03 12:40:33 +0200777 /* cleanup individual nodes */
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200778 table = &fws->desc.nodes[0];
779 for (i = 0; i < ARRAY_SIZE(fws->desc.nodes); i++)
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200780 brcmf_fws_mac_desc_cleanup(fws, &table[i], ifidx);
Arend van Sprielfba14002013-04-03 12:40:33 +0200781
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200782 brcmf_fws_mac_desc_cleanup(fws, &fws->desc.other, ifidx);
Arend van Spriele2432b62013-04-03 12:40:38 +0200783 brcmf_fws_bus_txq_cleanup(fws, matchfn, ifidx);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200784 brcmf_fws_hanger_cleanup(fws, matchfn, ifidx);
785}
786
787static void brcmf_fws_tim_update(struct brcmf_fws_info *ctx,
788 struct brcmf_fws_mac_descriptor *entry,
789 int prec)
790{
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200791 if (entry->state == BRCMF_FWS_STATE_CLOSE) {
792 /* check delayedQ and suppressQ in one call using bitmap */
793 if (brcmu_pktq_mlen(&entry->psq, 3 << (prec * 2)) == 0)
794 entry->traffic_pending_bmp =
795 entry->traffic_pending_bmp & ~NBITVAL(prec);
796 else
797 entry->traffic_pending_bmp =
798 entry->traffic_pending_bmp | NBITVAL(prec);
799 }
800 /* request a TIM update to firmware at the next piggyback opportunity */
801 if (entry->traffic_lastreported_bmp != entry->traffic_pending_bmp)
802 entry->send_tim_signal = true;
803}
804
805static void
806brcmf_fws_flow_control_check(struct brcmf_fws_info *fws, struct pktq *pq,
807 u8 if_id)
808{
Hante Meuleman402e3ba2013-06-06 13:17:57 +0200809 struct brcmf_if *ifp = fws->drvr->iflist[!if_id ? 0 : if_id + 1];
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200810
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200811 if (WARN_ON(!ifp))
812 return;
813
814 if ((ifp->netif_stop & BRCMF_NETIF_STOP_REASON_FWS_FC) &&
815 pq->len <= BRCMF_FWS_FLOWCONTROL_LOWATER)
816 brcmf_txflowblock_if(ifp,
817 BRCMF_NETIF_STOP_REASON_FWS_FC, false);
818 if (!(ifp->netif_stop & BRCMF_NETIF_STOP_REASON_FWS_FC) &&
819 pq->len >= BRCMF_FWS_FLOWCONTROL_HIWATER)
820 brcmf_txflowblock_if(ifp, BRCMF_NETIF_STOP_REASON_FWS_FC, true);
821 return;
Arend van Sprielfba14002013-04-03 12:40:33 +0200822}
823
Arend van Spriel349e7102013-03-03 12:45:28 +0100824static int brcmf_fws_rssi_indicate(struct brcmf_fws_info *fws, s8 rssi)
825{
826 brcmf_dbg(CTL, "rssi %d\n", rssi);
827 return 0;
828}
829
Arend van Sprielce814c12013-04-03 12:40:31 +0200830static
831int brcmf_fws_macdesc_indicate(struct brcmf_fws_info *fws, u8 type, u8 *data)
832{
833 struct brcmf_fws_mac_descriptor *entry, *existing;
834 u8 mac_handle;
835 u8 ifidx;
836 u8 *addr;
837
838 mac_handle = *data++;
839 ifidx = *data++;
840 addr = data;
841
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200842 entry = &fws->desc.nodes[mac_handle & 0x1F];
Arend van Sprielce814c12013-04-03 12:40:31 +0200843 if (type == BRCMF_FWS_TYPE_MACDESC_DEL) {
Arend van Spriel9a83f1e2013-04-23 12:53:13 +0200844 if (entry->occupied) {
Arend van Spriel8071fd62013-06-06 13:17:51 +0200845 brcmf_dbg(TRACE, "deleting %s mac %pM\n",
846 entry->name, addr);
Arend van Spriel9a83f1e2013-04-23 12:53:13 +0200847 brcmf_fws_mac_desc_cleanup(fws, entry, -1);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200848 brcmf_fws_clear_mac_descriptor(entry);
Arend van Spriel9a83f1e2013-04-23 12:53:13 +0200849 } else
Arend van Sprielce814c12013-04-03 12:40:31 +0200850 fws->stats.mac_update_failed++;
Arend van Sprielce814c12013-04-03 12:40:31 +0200851 return 0;
852 }
853
Arend van Sprielce814c12013-04-03 12:40:31 +0200854 existing = brcmf_fws_mac_descriptor_lookup(fws, addr);
855 if (IS_ERR(existing)) {
856 if (!entry->occupied) {
857 entry->mac_handle = mac_handle;
858 brcmf_fws_init_mac_descriptor(entry, addr, ifidx);
Arend van Spriel8071fd62013-06-06 13:17:51 +0200859 brcmf_fws_macdesc_set_name(fws, entry);
Arend van Sprielce814c12013-04-03 12:40:31 +0200860 brcmu_pktq_init(&entry->psq, BRCMF_FWS_PSQ_PREC_COUNT,
861 BRCMF_FWS_PSQ_LEN);
Arend van Spriel8071fd62013-06-06 13:17:51 +0200862 brcmf_dbg(TRACE, "add %s mac %pM\n", entry->name, addr);
Arend van Sprielce814c12013-04-03 12:40:31 +0200863 } else {
864 fws->stats.mac_update_failed++;
865 }
866 } else {
867 if (entry != existing) {
Arend van Spriel8071fd62013-06-06 13:17:51 +0200868 brcmf_dbg(TRACE, "copy mac %s\n", existing->name);
Arend van Sprielce814c12013-04-03 12:40:31 +0200869 memcpy(entry, existing,
870 offsetof(struct brcmf_fws_mac_descriptor, psq));
871 entry->mac_handle = mac_handle;
872 brcmf_fws_clear_mac_descriptor(existing);
Arend van Spriel8071fd62013-06-06 13:17:51 +0200873 brcmf_fws_macdesc_set_name(fws, entry);
874 brcmf_dbg(TRACE, "relocate %s mac %pM\n", entry->name,
875 addr);
Arend van Sprielce814c12013-04-03 12:40:31 +0200876 } else {
877 brcmf_dbg(TRACE, "use existing\n");
878 WARN_ON(entry->mac_handle != mac_handle);
879 /* TODO: what should we do here: continue, reinit, .. */
880 }
881 }
882 return 0;
883}
884
Arend van Spriel33753d42013-04-05 10:57:40 +0200885static int brcmf_fws_macdesc_state_indicate(struct brcmf_fws_info *fws,
886 u8 type, u8 *data)
887{
888 struct brcmf_fws_mac_descriptor *entry;
889 u8 mac_handle;
890 int i;
891
892 mac_handle = data[0];
893 entry = &fws->desc.nodes[mac_handle & 0x1F];
894 if (!entry->occupied) {
895 fws->stats.mac_ps_update_failed++;
896 return -ESRCH;
897 }
898
Arend van Spriel8071fd62013-06-06 13:17:51 +0200899 brcmf_dbg(TRACE, "%s (%d): %s\n", brcmf_fws_get_tlv_name(type), type,
900 entry->name);
Arend van Spriel33753d42013-04-05 10:57:40 +0200901 /* a state update should wipe old credits? */
902 entry->requested_credit = 0;
903 if (type == BRCMF_FWS_TYPE_MAC_OPEN) {
904 entry->state = BRCMF_FWS_STATE_OPEN;
Arend van Spriela5e9d802013-04-17 21:25:54 +0200905 return BRCMF_FWS_RET_OK_SCHEDULE;
Arend van Spriel33753d42013-04-05 10:57:40 +0200906 } else {
907 entry->state = BRCMF_FWS_STATE_CLOSE;
908 for (i = BRCMF_FWS_FIFO_AC_BE; i < NL80211_NUM_ACS; i++)
909 brcmf_fws_tim_update(fws, entry, i);
910 }
Arend van Spriela5e9d802013-04-17 21:25:54 +0200911 return BRCMF_FWS_RET_OK_NOSCHEDULE;
Arend van Spriel33753d42013-04-05 10:57:40 +0200912}
913
914static int brcmf_fws_interface_state_indicate(struct brcmf_fws_info *fws,
915 u8 type, u8 *data)
916{
917 struct brcmf_fws_mac_descriptor *entry;
918 u8 ifidx;
919 int ret;
920
921 ifidx = data[0];
922
Arend van Spriel33753d42013-04-05 10:57:40 +0200923 if (ifidx >= BRCMF_MAX_IFS) {
924 ret = -ERANGE;
925 goto fail;
926 }
927
928 entry = &fws->desc.iface[ifidx];
929 if (!entry->occupied) {
930 ret = -ESRCH;
931 goto fail;
932 }
933
Arend van Spriel8071fd62013-06-06 13:17:51 +0200934 brcmf_dbg(TRACE, "%s (%d): %s\n", brcmf_fws_get_tlv_name(type), type,
935 entry->name);
Arend van Spriel33753d42013-04-05 10:57:40 +0200936 switch (type) {
937 case BRCMF_FWS_TYPE_INTERFACE_OPEN:
938 entry->state = BRCMF_FWS_STATE_OPEN;
Arend van Spriela5e9d802013-04-17 21:25:54 +0200939 return BRCMF_FWS_RET_OK_SCHEDULE;
Arend van Spriel33753d42013-04-05 10:57:40 +0200940 case BRCMF_FWS_TYPE_INTERFACE_CLOSE:
941 entry->state = BRCMF_FWS_STATE_CLOSE;
Arend van Spriela5e9d802013-04-17 21:25:54 +0200942 return BRCMF_FWS_RET_OK_NOSCHEDULE;
Arend van Spriel33753d42013-04-05 10:57:40 +0200943 default:
944 ret = -EINVAL;
945 break;
946 }
947fail:
948 fws->stats.if_update_failed++;
949 return ret;
950}
951
Arend van Spriel5f38b682013-04-05 10:57:41 +0200952static int brcmf_fws_request_indicate(struct brcmf_fws_info *fws, u8 type,
953 u8 *data)
954{
955 struct brcmf_fws_mac_descriptor *entry;
956
957 entry = &fws->desc.nodes[data[1] & 0x1F];
958 if (!entry->occupied) {
959 if (type == BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT)
960 fws->stats.credit_request_failed++;
961 else
962 fws->stats.packet_request_failed++;
963 return -ESRCH;
964 }
965
Arend van Spriel8071fd62013-06-06 13:17:51 +0200966 brcmf_dbg(TRACE, "%s (%d): %s cnt %d bmp %d\n",
967 brcmf_fws_get_tlv_name(type), type, entry->name,
968 data[0], data[2]);
Arend van Spriel5f38b682013-04-05 10:57:41 +0200969 if (type == BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT)
970 entry->requested_credit = data[0];
971 else
972 entry->requested_packet = data[0];
973
974 entry->ac_bitmap = data[2];
Arend van Spriela5e9d802013-04-17 21:25:54 +0200975 return BRCMF_FWS_RET_OK_SCHEDULE;
Arend van Spriel5f38b682013-04-05 10:57:41 +0200976}
977
Arend van Spriel289ec1c2013-06-06 13:17:50 +0200978static int brcmf_fws_macdesc_use_credit(struct brcmf_fws_mac_descriptor *entry,
979 struct sk_buff *skb)
980{
981 int use_credit = 1;
982
983 if (entry->state == BRCMF_FWS_STATE_CLOSE) {
984 if (entry->requested_credit > 0) {
985 /*
986 * if the packet was pulled out while destination is in
987 * closed state but had a non-zero packets requested,
988 * then this should not count against the FIFO credit.
989 * That is due to the fact that the firmware will
990 * most likely hold onto this packet until a suitable
991 * time later to push it to the appropriate AC FIFO.
992 */
993 entry->requested_credit--;
994 brcmf_skb_if_flags_set_field(skb, REQ_CREDIT, 1);
995 use_credit = 0;
996 } else if (entry->requested_packet > 0) {
997 entry->requested_packet--;
998 brcmf_skb_if_flags_set_field(skb, REQUESTED, 1);
999 use_credit = 0;
1000 }
1001 } else {
1002 WARN_ON(entry->requested_credit);
1003 WARN_ON(entry->requested_packet);
1004 }
1005 brcmf_skb_if_flags_set_field(skb, CREDITCHECK, use_credit);
1006 return use_credit;
1007}
1008
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001009static void brcmf_fws_return_credits(struct brcmf_fws_info *fws,
1010 u8 fifo, u8 credits)
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001011{
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001012 int lender_ac;
1013 int *borrowed;
1014 int *fifo_credit;
1015
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001016 if (!credits)
1017 return;
1018
Hante Meulemanafc3bbf2013-06-06 13:17:54 +02001019 fws->fifo_credit_map |= 1 << fifo;
1020
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001021 if ((fifo == BRCMF_FWS_FIFO_AC_BE) &&
1022 (fws->credits_borrowed[0])) {
1023 for (lender_ac = BRCMF_FWS_FIFO_AC_VO; lender_ac >= 0;
1024 lender_ac--) {
1025 borrowed = &fws->credits_borrowed[lender_ac];
1026 if (*borrowed) {
1027 fws->fifo_credit_map |= (1 << lender_ac);
1028 fifo_credit = &fws->fifo_credit[lender_ac];
1029 if (*borrowed >= credits) {
1030 *borrowed -= credits;
1031 *fifo_credit += credits;
1032 return;
1033 } else {
1034 credits -= *borrowed;
1035 *fifo_credit += *borrowed;
1036 *borrowed = 0;
1037 }
1038 }
1039 }
1040 }
1041
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001042 fws->fifo_credit[fifo] += credits;
1043}
1044
1045static void brcmf_fws_schedule_deq(struct brcmf_fws_info *fws)
1046{
1047 /* only schedule dequeue when there are credits for delayed traffic */
1048 if (fws->fifo_credit_map & fws->fifo_delay_map)
1049 queue_work(fws->fws_wq, &fws->fws_dequeue_work);
1050}
1051
Arend van Sprielfe353b22013-06-06 13:17:49 +02001052static void brcmf_fws_skb_pickup_credit(struct brcmf_fws_info *fws, int fifo,
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001053 struct sk_buff *p)
1054{
1055 struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(p)->mac;
1056
Arend van Sprielfe353b22013-06-06 13:17:49 +02001057 if (brcmf_skbcb(p)->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK)
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001058 brcmf_fws_return_credits(fws, fifo, 1);
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001059 else if (brcmf_skb_if_flags_get_field(p, REQ_CREDIT) &&
1060 entry->state == BRCMF_FWS_STATE_CLOSE)
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001061 /*
1062 * if this packet did not count against FIFO credit, it
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001063 * could have taken a requested_credit from the destination
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001064 * entry (for pspoll etc.)
1065 */
Arend van Sprielfe353b22013-06-06 13:17:49 +02001066 entry->requested_credit++;
1067
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001068 brcmf_fws_schedule_deq(fws);
1069}
1070
1071static int brcmf_fws_enq(struct brcmf_fws_info *fws,
1072 enum brcmf_fws_skb_state state, int fifo,
1073 struct sk_buff *p)
1074{
1075 int prec = 2 * fifo;
1076 u32 *qfull_stat = &fws->stats.delayq_full_error;
1077
1078 struct brcmf_fws_mac_descriptor *entry;
1079
1080 entry = brcmf_skbcb(p)->mac;
1081 if (entry == NULL) {
1082 brcmf_err("no mac descriptor found for skb %p\n", p);
1083 return -ENOENT;
1084 }
1085
Arend van Spriel8071fd62013-06-06 13:17:51 +02001086 brcmf_dbg(DATA, "enter: fifo %d skb %p\n", fifo, p);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001087 if (state == BRCMF_FWS_SKBSTATE_SUPPRESSED) {
1088 prec += 1;
1089 qfull_stat = &fws->stats.supprq_full_error;
1090 }
1091
1092 if (brcmu_pktq_penq(&entry->psq, prec, p) == NULL) {
1093 *qfull_stat += 1;
1094 return -ENFILE;
1095 }
1096
1097 /* increment total enqueued packet count */
1098 fws->fifo_delay_map |= 1 << fifo;
1099 fws->fifo_enqpkt[fifo]++;
1100
1101 /* update the sk_buff state */
1102 brcmf_skbcb(p)->state = state;
1103 if (state == BRCMF_FWS_SKBSTATE_SUPPRESSED)
1104 entry->suppress_count++;
1105
1106 /*
1107 * A packet has been pushed so update traffic
1108 * availability bitmap, if applicable
1109 */
1110 brcmf_fws_tim_update(fws, entry, fifo);
1111 brcmf_fws_flow_control_check(fws, &entry->psq,
1112 brcmf_skb_if_flags_get_field(p, INDEX));
1113 return 0;
1114}
1115
1116static struct sk_buff *brcmf_fws_deq(struct brcmf_fws_info *fws, int fifo)
1117{
1118 struct brcmf_fws_mac_descriptor *table;
1119 struct brcmf_fws_mac_descriptor *entry;
1120 struct sk_buff *p;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001121 int num_nodes;
1122 int node_pos;
1123 int prec_out;
Arend van Spriel07529d22013-04-17 21:25:49 +02001124 int pmsk;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001125 int i;
1126
1127 table = (struct brcmf_fws_mac_descriptor *)&fws->desc;
1128 num_nodes = sizeof(fws->desc) / sizeof(struct brcmf_fws_mac_descriptor);
1129 node_pos = fws->deq_node_pos[fifo];
1130
1131 for (i = 0; i < num_nodes; i++) {
1132 entry = &table[(node_pos + i) % num_nodes];
Arend van Sprielb75c1a32013-04-17 21:25:53 +02001133 if (!entry->occupied ||
1134 brcmf_fws_mac_desc_closed(fws, entry, fifo))
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001135 continue;
1136
1137 if (entry->suppressed)
1138 pmsk = 2;
Arend van Spriel07529d22013-04-17 21:25:49 +02001139 else
1140 pmsk = 3;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001141 p = brcmu_pktq_mdeq(&entry->psq, pmsk << (fifo * 2), &prec_out);
1142 if (p == NULL) {
1143 if (entry->suppressed) {
1144 if (entry->suppr_transit_count >
1145 entry->suppress_count)
1146 return NULL;
1147 entry->suppressed = false;
1148 p = brcmu_pktq_mdeq(&entry->psq,
1149 1 << (fifo * 2), &prec_out);
1150 }
1151 }
1152 if (p == NULL)
1153 continue;
1154
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001155 brcmf_fws_macdesc_use_credit(entry, p);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001156
1157 /* move dequeue position to ensure fair round-robin */
1158 fws->deq_node_pos[fifo] = (node_pos + i + 1) % num_nodes;
1159 brcmf_fws_flow_control_check(fws, &entry->psq,
1160 brcmf_skb_if_flags_get_field(p,
1161 INDEX)
1162 );
1163 /*
1164 * A packet has been picked up, update traffic
1165 * availability bitmap, if applicable
1166 */
1167 brcmf_fws_tim_update(fws, entry, fifo);
1168
1169 /*
1170 * decrement total enqueued fifo packets and
1171 * clear delay bitmap if done.
1172 */
1173 fws->fifo_enqpkt[fifo]--;
1174 if (fws->fifo_enqpkt[fifo] == 0)
1175 fws->fifo_delay_map &= ~(1 << fifo);
1176 goto done;
1177 }
1178 p = NULL;
1179done:
Arend van Spriel8071fd62013-06-06 13:17:51 +02001180 brcmf_dbg(DATA, "exit: fifo %d skb %p\n", fifo, p);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001181 return p;
1182}
1183
1184static int brcmf_fws_txstatus_suppressed(struct brcmf_fws_info *fws, int fifo,
1185 struct sk_buff *skb, u32 genbit)
1186{
1187 struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(skb)->mac;
1188 u32 hslot;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001189 int ret;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001190
1191 hslot = brcmf_skb_htod_tag_get_field(skb, HSLOT);
1192
1193 /* this packet was suppressed */
Hante Meulemanbe4910a2013-06-06 13:17:53 +02001194 if (!entry->suppressed) {
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001195 entry->suppressed = true;
1196 entry->suppress_count = brcmu_pktq_mlen(&entry->psq,
1197 1 << (fifo * 2 + 1));
1198 entry->suppr_transit_count = entry->transit_count;
Arend van Spriel8071fd62013-06-06 13:17:51 +02001199 brcmf_dbg(DATA, "suppress %s: supp_cnt %d transit %d\n",
1200 entry->name, entry->suppress_count,
1201 entry->transit_count);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001202 }
1203
1204 entry->generation = genbit;
1205
1206 ret = brcmf_fws_enq(fws, BRCMF_FWS_SKBSTATE_SUPPRESSED, fifo, skb);
1207 if (ret != 0) {
1208 /* suppress q is full, drop this packet */
1209 brcmf_fws_hanger_poppkt(&fws->hanger, hslot, &skb,
1210 true);
1211 } else {
1212 /*
1213 * Mark suppressed to avoid a double free during
1214 * wlfc cleanup
1215 */
Hante Meulemanbe4910a2013-06-06 13:17:53 +02001216 brcmf_fws_hanger_mark_suppressed(&fws->hanger, hslot);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001217 entry->suppress_count++;
1218 }
1219
1220 return ret;
1221}
1222
1223static int
Arend van Spriel8071fd62013-06-06 13:17:51 +02001224brcmf_fws_txs_process(struct brcmf_fws_info *fws, u8 flags, u32 hslot,
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001225 u32 genbit)
1226{
1227 u32 fifo;
1228 int ret;
1229 bool remove_from_hanger = true;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001230 struct sk_buff *skb;
Arend van Spriel8071fd62013-06-06 13:17:51 +02001231 struct brcmf_skbuff_cb *skcb;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001232 struct brcmf_fws_mac_descriptor *entry = NULL;
1233
Arend van Spriel8071fd62013-06-06 13:17:51 +02001234 brcmf_dbg(DATA, "flags %d\n", flags);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001235
1236 if (flags == BRCMF_FWS_TXSTATUS_DISCARD)
1237 fws->stats.txs_discard++;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001238 else if (flags == BRCMF_FWS_TXSTATUS_CORE_SUPPRESS) {
1239 fws->stats.txs_supp_core++;
1240 remove_from_hanger = false;
1241 } else if (flags == BRCMF_FWS_TXSTATUS_FW_PS_SUPPRESS) {
1242 fws->stats.txs_supp_ps++;
1243 remove_from_hanger = false;
1244 } else if (flags == BRCMF_FWS_TXSTATUS_FW_TOSSED)
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001245 fws->stats.txs_tossed++;
1246 else
1247 brcmf_err("unexpected txstatus\n");
1248
1249 ret = brcmf_fws_hanger_poppkt(&fws->hanger, hslot, &skb,
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001250 remove_from_hanger);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001251 if (ret != 0) {
1252 brcmf_err("no packet in hanger slot: hslot=%d\n", hslot);
1253 return ret;
1254 }
1255
Arend van Spriel8071fd62013-06-06 13:17:51 +02001256 skcb = brcmf_skbcb(skb);
1257 entry = skcb->mac;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001258 if (WARN_ON(!entry)) {
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001259 brcmu_pkt_buf_free_skb(skb);
1260 return -EINVAL;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001261 }
1262
Arend van Spriel8071fd62013-06-06 13:17:51 +02001263 brcmf_dbg(DATA, "%s flags %X htod %X\n", entry->name, skcb->if_flags,
1264 skcb->htod);
1265
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001266 /* pick up the implicit credit from this packet */
1267 fifo = brcmf_skb_htod_tag_get_field(skb, FIFO);
Arend van Sprielfe353b22013-06-06 13:17:49 +02001268 if (fws->fcmode == BRCMF_FWS_FCMODE_IMPLIED_CREDIT ||
1269 !(brcmf_skbcb(skb)->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK))
1270 brcmf_fws_skb_pickup_credit(fws, fifo, skb);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001271
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001272 if (!remove_from_hanger)
1273 ret = brcmf_fws_txstatus_suppressed(fws, fifo, skb, genbit);
1274
1275 if (remove_from_hanger || ret) {
1276 entry->transit_count--;
1277 if (entry->suppressed)
1278 entry->suppr_transit_count--;
1279
1280 brcmf_txfinalize(fws->drvr, skb, true);
1281 }
1282 return 0;
1283}
1284
1285static int brcmf_fws_fifocreditback_indicate(struct brcmf_fws_info *fws,
1286 u8 *data)
1287{
1288 int i;
1289
1290 if (fws->fcmode != BRCMF_FWS_FCMODE_EXPLICIT_CREDIT) {
1291 brcmf_dbg(INFO, "ignored\n");
Arend van Spriela5e9d802013-04-17 21:25:54 +02001292 return BRCMF_FWS_RET_OK_NOSCHEDULE;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001293 }
1294
Arend van Spriel8071fd62013-06-06 13:17:51 +02001295 brcmf_dbg(DATA, "enter: data %pM\n", data);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001296 for (i = 0; i < BRCMF_FWS_FIFO_COUNT; i++)
1297 brcmf_fws_return_credits(fws, i, data[i]);
1298
Arend van Spriel8071fd62013-06-06 13:17:51 +02001299 brcmf_dbg(DATA, "map: credit %x delay %x\n", fws->fifo_credit_map,
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001300 fws->fifo_delay_map);
Arend van Spriela5e9d802013-04-17 21:25:54 +02001301 return BRCMF_FWS_RET_OK_SCHEDULE;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001302}
1303
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02001304static int brcmf_fws_txstatus_indicate(struct brcmf_fws_info *fws, u8 *data)
1305{
Arend van Spriela2ffc562013-04-05 10:57:39 +02001306 __le32 status_le;
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02001307 u32 status;
1308 u32 hslot;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001309 u32 genbit;
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02001310 u8 flags;
1311
1312 fws->stats.txs_indicate++;
Arend van Spriela2ffc562013-04-05 10:57:39 +02001313 memcpy(&status_le, data, sizeof(status_le));
1314 status = le32_to_cpu(status_le);
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02001315 flags = brcmf_txstatus_get_field(status, FLAGS);
1316 hslot = brcmf_txstatus_get_field(status, HSLOT);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001317 genbit = brcmf_txstatus_get_field(status, GENERATION);
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02001318
Arend van Spriel8071fd62013-06-06 13:17:51 +02001319 return brcmf_fws_txs_process(fws, flags, hslot, genbit);
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02001320}
1321
Arend van Spriel349e7102013-03-03 12:45:28 +01001322static int brcmf_fws_dbg_seqnum_check(struct brcmf_fws_info *fws, u8 *data)
1323{
1324 __le32 timestamp;
1325
1326 memcpy(&timestamp, &data[2], sizeof(timestamp));
Arend van Spriel8071fd62013-06-06 13:17:51 +02001327 brcmf_dbg(CTL, "received: seq %d, timestamp %d\n", data[1],
Arend van Spriel349e7102013-03-03 12:45:28 +01001328 le32_to_cpu(timestamp));
1329 return 0;
1330}
1331
1332/* using macro so sparse checking does not complain
1333 * about locking imbalance.
1334 */
1335#define brcmf_fws_lock(drvr, flags) \
1336do { \
1337 flags = 0; \
1338 spin_lock_irqsave(&((drvr)->fws_spinlock), (flags)); \
1339} while (0)
1340
1341/* using macro so sparse checking does not complain
1342 * about locking imbalance.
1343 */
1344#define brcmf_fws_unlock(drvr, flags) \
1345 spin_unlock_irqrestore(&((drvr)->fws_spinlock), (flags))
1346
Arend van Spriel43fa6352013-04-03 12:40:32 +02001347static int brcmf_fws_notify_credit_map(struct brcmf_if *ifp,
1348 const struct brcmf_event_msg *e,
1349 void *data)
1350{
1351 struct brcmf_fws_info *fws = ifp->drvr->fws;
1352 int i;
1353 ulong flags;
1354 u8 *credits = data;
1355
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001356 if (e->datalen < BRCMF_FWS_FIFO_COUNT) {
1357 brcmf_err("event payload too small (%d)\n", e->datalen);
1358 return -EINVAL;
1359 }
Hante Meuleman0d24b0e2013-06-06 13:17:58 +02001360 if (fws->creditmap_received)
1361 return 0;
1362
1363 fws->creditmap_received = true;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001364
1365 brcmf_dbg(TRACE, "enter: credits %pM\n", credits);
Arend van Spriel43fa6352013-04-03 12:40:32 +02001366 brcmf_fws_lock(ifp->drvr, flags);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001367 for (i = 0; i < ARRAY_SIZE(fws->fifo_credit); i++) {
1368 if (*credits)
1369 fws->fifo_credit_map |= 1 << i;
1370 else
1371 fws->fifo_credit_map &= ~(1 << i);
Arend van Spriel43fa6352013-04-03 12:40:32 +02001372 fws->fifo_credit[i] = *credits++;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001373 }
1374 brcmf_fws_schedule_deq(fws);
Arend van Spriel43fa6352013-04-03 12:40:32 +02001375 brcmf_fws_unlock(ifp->drvr, flags);
1376 return 0;
1377}
1378
Arend van Spriel349e7102013-03-03 12:45:28 +01001379int brcmf_fws_hdrpull(struct brcmf_pub *drvr, int ifidx, s16 signal_len,
1380 struct sk_buff *skb)
1381{
1382 struct brcmf_fws_info *fws = drvr->fws;
1383 ulong flags;
1384 u8 *signal_data;
1385 s16 data_len;
1386 u8 type;
1387 u8 len;
1388 u8 *data;
Arend van Spriela5e9d802013-04-17 21:25:54 +02001389 s32 status;
1390 s32 err;
Arend van Spriel349e7102013-03-03 12:45:28 +01001391
Arend van Spriel8071fd62013-06-06 13:17:51 +02001392 brcmf_dbg(HDRS, "enter: ifidx %d, skblen %u, sig %d\n",
Arend van Spriel349e7102013-03-03 12:45:28 +01001393 ifidx, skb->len, signal_len);
1394
1395 WARN_ON(signal_len > skb->len);
1396
1397 /* if flow control disabled, skip to packet data and leave */
1398 if (!signal_len || !drvr->fw_signals) {
1399 skb_pull(skb, signal_len);
1400 return 0;
1401 }
1402
1403 /* lock during tlv parsing */
1404 brcmf_fws_lock(drvr, flags);
1405
1406 fws->stats.header_pulls++;
1407 data_len = signal_len;
1408 signal_data = skb->data;
1409
Arend van Spriela5e9d802013-04-17 21:25:54 +02001410 status = BRCMF_FWS_RET_OK_NOSCHEDULE;
Arend van Spriel349e7102013-03-03 12:45:28 +01001411 while (data_len > 0) {
1412 /* extract tlv info */
1413 type = signal_data[0];
1414
1415 /* FILLER type is actually not a TLV, but
1416 * a single byte that can be skipped.
1417 */
1418 if (type == BRCMF_FWS_TYPE_FILLER) {
1419 signal_data += 1;
1420 data_len -= 1;
1421 continue;
1422 }
1423 len = signal_data[1];
1424 data = signal_data + 2;
1425
Arend van Spriel8071fd62013-06-06 13:17:51 +02001426 brcmf_dbg(HDRS, "tlv type=%s (%d), len=%d (%d)\n",
1427 brcmf_fws_get_tlv_name(type), type, len,
1428 brcmf_fws_get_tlv_len(fws, type));
Arend van Spriel2af15582013-04-03 12:40:42 +02001429
Arend van Spriel349e7102013-03-03 12:45:28 +01001430 /* abort parsing when length invalid */
1431 if (data_len < len + 2)
1432 break;
1433
Arend van Sprielf55d94a2013-06-06 13:17:46 +02001434 if (len < brcmf_fws_get_tlv_len(fws, type))
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001435 break;
1436
Arend van Spriela5e9d802013-04-17 21:25:54 +02001437 err = BRCMF_FWS_RET_OK_NOSCHEDULE;
Arend van Spriel349e7102013-03-03 12:45:28 +01001438 switch (type) {
Arend van Spriel349e7102013-03-03 12:45:28 +01001439 case BRCMF_FWS_TYPE_HOST_REORDER_RXPKTS:
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001440 case BRCMF_FWS_TYPE_COMP_TXSTATUS:
Arend van Sprielce814c12013-04-03 12:40:31 +02001441 break;
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001442 case BRCMF_FWS_TYPE_MACDESC_ADD:
1443 case BRCMF_FWS_TYPE_MACDESC_DEL:
Arend van Sprielce814c12013-04-03 12:40:31 +02001444 brcmf_fws_macdesc_indicate(fws, type, data);
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001445 break;
Arend van Spriel33753d42013-04-05 10:57:40 +02001446 case BRCMF_FWS_TYPE_MAC_OPEN:
1447 case BRCMF_FWS_TYPE_MAC_CLOSE:
Arend van Spriela5e9d802013-04-17 21:25:54 +02001448 err = brcmf_fws_macdesc_state_indicate(fws, type, data);
Arend van Spriel33753d42013-04-05 10:57:40 +02001449 break;
1450 case BRCMF_FWS_TYPE_INTERFACE_OPEN:
1451 case BRCMF_FWS_TYPE_INTERFACE_CLOSE:
Arend van Spriela5e9d802013-04-17 21:25:54 +02001452 err = brcmf_fws_interface_state_indicate(fws, type,
1453 data);
Arend van Spriel33753d42013-04-05 10:57:40 +02001454 break;
Arend van Spriel5f38b682013-04-05 10:57:41 +02001455 case BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT:
1456 case BRCMF_FWS_TYPE_MAC_REQUEST_PACKET:
Arend van Spriela5e9d802013-04-17 21:25:54 +02001457 err = brcmf_fws_request_indicate(fws, type, data);
Arend van Spriel5f38b682013-04-05 10:57:41 +02001458 break;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001459 case BRCMF_FWS_TYPE_TXSTATUS:
1460 brcmf_fws_txstatus_indicate(fws, data);
1461 break;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001462 case BRCMF_FWS_TYPE_FIFO_CREDITBACK:
Arend van Spriela5e9d802013-04-17 21:25:54 +02001463 err = brcmf_fws_fifocreditback_indicate(fws, data);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001464 break;
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001465 case BRCMF_FWS_TYPE_RSSI:
1466 brcmf_fws_rssi_indicate(fws, *data);
Arend van Spriel349e7102013-03-03 12:45:28 +01001467 break;
1468 case BRCMF_FWS_TYPE_TRANS_ID:
Arend van Spriel349e7102013-03-03 12:45:28 +01001469 brcmf_fws_dbg_seqnum_check(fws, data);
1470 break;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001471 case BRCMF_FWS_TYPE_PKTTAG:
1472 case BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP:
Arend van Spriel349e7102013-03-03 12:45:28 +01001473 default:
1474 fws->stats.tlv_invalid_type++;
1475 break;
1476 }
Arend van Spriela5e9d802013-04-17 21:25:54 +02001477 if (err == BRCMF_FWS_RET_OK_SCHEDULE)
1478 status = BRCMF_FWS_RET_OK_SCHEDULE;
Arend van Spriel349e7102013-03-03 12:45:28 +01001479 signal_data += len + 2;
1480 data_len -= len + 2;
1481 }
1482
1483 if (data_len != 0)
1484 fws->stats.tlv_parse_failed++;
1485
Arend van Spriela5e9d802013-04-17 21:25:54 +02001486 if (status == BRCMF_FWS_RET_OK_SCHEDULE)
1487 brcmf_fws_schedule_deq(fws);
1488
Arend van Spriel349e7102013-03-03 12:45:28 +01001489 /* signalling processing result does
1490 * not affect the actual ethernet packet.
1491 */
1492 skb_pull(skb, signal_len);
1493
1494 /* this may be a signal-only packet
1495 */
1496 if (skb->len == 0)
1497 fws->stats.header_only_pkt++;
1498
1499 brcmf_fws_unlock(drvr, flags);
1500 return 0;
1501}
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001502
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001503static int brcmf_fws_hdrpush(struct brcmf_fws_info *fws, struct sk_buff *skb)
1504{
1505 struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(skb)->mac;
1506 u8 *wlh;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001507 u16 data_offset = 0;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001508 u8 fillers;
1509 __le32 pkttag = cpu_to_le32(brcmf_skbcb(skb)->htod);
1510
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001511 if (entry->send_tim_signal)
1512 data_offset += 2 + BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN;
1513
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001514 /* +2 is for Type[1] and Len[1] in TLV, plus TIM signal */
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001515 data_offset += 2 + BRCMF_FWS_TYPE_PKTTAG_LEN;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001516 fillers = round_up(data_offset, 4) - data_offset;
1517 data_offset += fillers;
1518
1519 skb_push(skb, data_offset);
1520 wlh = skb->data;
1521
1522 wlh[0] = BRCMF_FWS_TYPE_PKTTAG;
1523 wlh[1] = BRCMF_FWS_TYPE_PKTTAG_LEN;
1524 memcpy(&wlh[2], &pkttag, sizeof(pkttag));
1525 wlh += BRCMF_FWS_TYPE_PKTTAG_LEN + 2;
1526
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001527 if (entry->send_tim_signal) {
1528 entry->send_tim_signal = 0;
1529 wlh[0] = BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP;
1530 wlh[1] = BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN;
1531 wlh[2] = entry->mac_handle;
1532 wlh[3] = entry->traffic_pending_bmp;
1533 wlh += BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN + 2;
1534 entry->traffic_lastreported_bmp = entry->traffic_pending_bmp;
1535 }
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001536 if (fillers)
1537 memset(wlh, BRCMF_FWS_TYPE_FILLER, fillers);
1538
1539 brcmf_proto_hdrpush(fws->drvr, brcmf_skb_if_flags_get_field(skb, INDEX),
1540 data_offset >> 2, skb);
1541 return 0;
1542}
1543
1544static int brcmf_fws_precommit_skb(struct brcmf_fws_info *fws, int fifo,
1545 struct sk_buff *p)
1546{
1547 struct brcmf_skbuff_cb *skcb = brcmf_skbcb(p);
1548 struct brcmf_fws_mac_descriptor *entry = skcb->mac;
1549 int rc = 0;
Hante Meulemanbe4910a2013-06-06 13:17:53 +02001550 bool first_time;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001551 int hslot = BRCMF_FWS_HANGER_MAXITEMS;
1552 u8 free_ctr;
1553 u8 ifidx;
1554 u8 flags;
1555
Hante Meulemanbe4910a2013-06-06 13:17:53 +02001556 first_time = skcb->state != BRCMF_FWS_SKBSTATE_SUPPRESSED;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001557
Hante Meulemanbe4910a2013-06-06 13:17:53 +02001558 if (!first_time) {
1559 rc = brcmf_proto_hdrpull(fws->drvr, false, &ifidx, p);
1560 if (rc) {
1561 brcmf_err("hdrpull failed\n");
1562 return rc;
1563 }
1564 }
1565 brcmf_skb_if_flags_set_field(p, TRANSMIT, 1);
1566 brcmf_skb_htod_tag_set_field(p, FIFO, fifo);
1567 brcmf_skb_htod_tag_set_field(p, GENERATION, entry->generation);
1568 flags = BRCMF_FWS_HTOD_FLAG_PKTFROMHOST;
1569 if (!(skcb->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK)) {
1570 /*
1571 * Indicate that this packet is being sent in response to an
1572 * explicit request from the firmware side.
1573 */
1574 flags |= BRCMF_FWS_HTOD_FLAG_PKT_REQUESTED;
1575 }
1576 brcmf_skb_htod_tag_set_field(p, FLAGS, flags);
1577 if (first_time) {
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001578 /* obtaining free slot may fail, but that will be caught
1579 * by the hanger push. This assures the packet has a BDC
1580 * header upon return.
1581 */
1582 hslot = brcmf_fws_hanger_get_free_slot(&fws->hanger);
1583 free_ctr = entry->seq[fifo];
1584 brcmf_skb_htod_tag_set_field(p, HSLOT, hslot);
1585 brcmf_skb_htod_tag_set_field(p, FREERUN, free_ctr);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001586 entry->transit_count++;
1587 }
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001588
Hante Meulemanbe4910a2013-06-06 13:17:53 +02001589 brcmf_fws_hdrpush(fws, p);
1590 if (first_time) {
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001591 rc = brcmf_fws_hanger_pushpkt(&fws->hanger, p, hslot);
1592 if (rc)
1593 brcmf_err("hanger push failed: rc=%d\n", rc);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001594 }
1595
1596 return rc;
1597}
1598
Arend van Spriel88f656f2013-04-17 21:25:57 +02001599static void
Arend van Spriel51f6dd92013-06-06 13:17:47 +02001600brcmf_fws_rollback_toq(struct brcmf_fws_info *fws,
1601 struct sk_buff *skb, int fifo)
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001602{
1603 /*
1604 put the packet back to the head of queue
1605
1606 - suppressed packet goes back to suppress sub-queue
1607 - pull out the header, if new or delayed packet
1608
1609 Note: hslot is used only when header removal is done.
1610 */
1611 struct brcmf_fws_mac_descriptor *entry;
1612 enum brcmf_fws_skb_state state;
1613 struct sk_buff *pktout;
1614 int rc = 0;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001615 int hslot;
1616 u8 ifidx;
1617
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001618 state = brcmf_skbcb(skb)->state;
1619 entry = brcmf_skbcb(skb)->mac;
1620
1621 if (entry != NULL) {
1622 if (state == BRCMF_FWS_SKBSTATE_SUPPRESSED) {
1623 /* wl-header is saved for suppressed packets */
1624 pktout = brcmu_pktq_penq_head(&entry->psq, 2 * fifo + 1,
1625 skb);
1626 if (pktout == NULL) {
1627 brcmf_err("suppress queue full\n");
1628 rc = -ENOSPC;
1629 }
1630 } else {
1631 hslot = brcmf_skb_htod_tag_get_field(skb, HSLOT);
1632
1633 /* remove header first */
1634 rc = brcmf_proto_hdrpull(fws->drvr, false, &ifidx, skb);
1635 if (rc) {
1636 brcmf_err("header removal failed\n");
1637 /* free the hanger slot */
1638 brcmf_fws_hanger_poppkt(&fws->hanger, hslot,
1639 &pktout, true);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001640 rc = -EINVAL;
1641 goto fail;
1642 }
1643
1644 /* delay-q packets are going to delay-q */
1645 pktout = brcmu_pktq_penq_head(&entry->psq,
1646 2 * fifo, skb);
1647 if (pktout == NULL) {
1648 brcmf_err("delay queue full\n");
1649 rc = -ENOSPC;
1650 }
1651
1652 /* free the hanger slot */
1653 brcmf_fws_hanger_poppkt(&fws->hanger, hslot, &pktout,
1654 true);
1655
1656 /* decrement sequence count */
1657 entry->seq[fifo]--;
1658 }
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001659 } else {
1660 brcmf_err("no mac entry linked\n");
1661 rc = -ENOENT;
1662 }
1663
1664
1665fail:
Arend van Spriel67994fa2013-04-17 21:25:56 +02001666 if (rc) {
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001667 brcmf_fws_bustxfail(fws, skb);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001668 fws->stats.rollback_failed++;
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001669 } else {
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001670 fws->stats.rollback_success++;
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001671 brcmf_fws_skb_pickup_credit(fws, fifo, skb);
1672 }
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001673}
1674
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001675static int brcmf_fws_borrow_credit(struct brcmf_fws_info *fws)
1676{
1677 int lender_ac;
1678
Hante Meulemanafc3bbf2013-06-06 13:17:54 +02001679 if (time_after(fws->borrow_defer_timestamp, jiffies)) {
1680 fws->fifo_credit_map &= ~(1 << BRCMF_FWS_FIFO_AC_BE);
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001681 return -ENAVAIL;
Hante Meulemanafc3bbf2013-06-06 13:17:54 +02001682 }
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001683
1684 for (lender_ac = 0; lender_ac <= BRCMF_FWS_FIFO_AC_VO; lender_ac++) {
1685 if (fws->fifo_credit[lender_ac]) {
1686 fws->credits_borrowed[lender_ac]++;
1687 fws->fifo_credit[lender_ac]--;
1688 if (fws->fifo_credit[lender_ac] == 0)
1689 fws->fifo_credit_map &= ~(1 << lender_ac);
Hante Meulemanafc3bbf2013-06-06 13:17:54 +02001690 fws->fifo_credit_map |= (1 << BRCMF_FWS_FIFO_AC_BE);
Arend van Spriel8071fd62013-06-06 13:17:51 +02001691 brcmf_dbg(DATA, "borrow credit from: %d\n", lender_ac);
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001692 return 0;
1693 }
1694 }
Hante Meulemanafc3bbf2013-06-06 13:17:54 +02001695 fws->fifo_credit_map &= ~(1 << BRCMF_FWS_FIFO_AC_BE);
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001696 return -ENAVAIL;
1697}
1698
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001699static int brcmf_fws_consume_credit(struct brcmf_fws_info *fws, int fifo,
1700 struct sk_buff *skb)
1701{
1702 struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(skb)->mac;
1703 int *credit = &fws->fifo_credit[fifo];
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001704
Arend van Spriel8071fd62013-06-06 13:17:51 +02001705 if (!brcmf_fws_macdesc_use_credit(entry, skb))
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001706 return 0;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001707
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001708 if (fifo != BRCMF_FWS_FIFO_AC_BE)
1709 fws->borrow_defer_timestamp = jiffies +
1710 BRCMF_FWS_BORROW_DEFER_PERIOD;
1711
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001712 if (!(*credit)) {
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001713 /* Try to borrow a credit from other queue */
1714 if (fifo == BRCMF_FWS_FIFO_AC_BE &&
1715 brcmf_fws_borrow_credit(fws) == 0)
1716 return 0;
1717
Arend van Spriel8071fd62013-06-06 13:17:51 +02001718 brcmf_dbg(DATA, "exit: ac=%d, credits depleted\n", fifo);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001719 return -ENAVAIL;
1720 }
1721 (*credit)--;
1722 if (!(*credit))
1723 fws->fifo_credit_map &= ~(1 << fifo);
Arend van Spriel8071fd62013-06-06 13:17:51 +02001724 brcmf_dbg(DATA, "exit: ac=%d, credits=%d\n", fifo, *credit);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001725 return 0;
1726}
1727
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001728static int brcmf_fws_commit_skb(struct brcmf_fws_info *fws, int fifo,
1729 struct sk_buff *skb)
1730{
1731 struct brcmf_skbuff_cb *skcb = brcmf_skbcb(skb);
1732 struct brcmf_fws_mac_descriptor *entry;
1733 struct brcmf_bus *bus = fws->drvr->bus_if;
1734 int rc;
1735
1736 entry = skcb->mac;
1737 if (IS_ERR(entry))
1738 return PTR_ERR(entry);
1739
1740 rc = brcmf_fws_precommit_skb(fws, fifo, skb);
1741 if (rc < 0) {
1742 fws->stats.generic_error++;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001743 goto rollback;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001744 }
1745
Arend van Spriel8071fd62013-06-06 13:17:51 +02001746 brcmf_dbg(DATA, "%s flags %X htod %X\n", entry->name, skcb->if_flags,
1747 skcb->htod);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001748 rc = brcmf_bus_txdata(bus, skb);
1749 if (rc < 0)
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001750 goto rollback;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001751
1752 entry->seq[fifo]++;
1753 fws->stats.pkt2bus++;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001754 if (brcmf_skbcb(skb)->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK) {
1755 fws->stats.send_pkts[fifo]++;
1756 fws->stats.fifo_credits_sent[fifo]++;
1757 }
1758
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001759 return rc;
1760
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001761rollback:
Arend van Spriel51f6dd92013-06-06 13:17:47 +02001762 brcmf_fws_rollback_toq(fws, skb, fifo);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001763 return rc;
1764}
1765
1766int brcmf_fws_process_skb(struct brcmf_if *ifp, struct sk_buff *skb)
1767{
1768 struct brcmf_pub *drvr = ifp->drvr;
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001769 struct brcmf_fws_info *fws = drvr->fws;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001770 struct brcmf_skbuff_cb *skcb = brcmf_skbcb(skb);
1771 struct ethhdr *eh = (struct ethhdr *)(skb->data);
1772 ulong flags;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001773 int fifo = BRCMF_FWS_FIFO_BCMC;
1774 bool multicast = is_multicast_ether_addr(eh->h_dest);
1775
1776 /* determine the priority */
1777 if (!skb->priority)
1778 skb->priority = cfg80211_classify8021d(skb);
1779
1780 drvr->tx_multicast += !!multicast;
1781 if (ntohs(eh->h_proto) == ETH_P_PAE)
1782 atomic_inc(&ifp->pend_8021x_cnt);
1783
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001784 if (!brcmf_fws_fc_active(fws)) {
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001785 /* If the protocol uses a data header, apply it */
Arend van Spriel31ed07d2013-04-11 13:29:00 +02001786 brcmf_proto_hdrpush(drvr, ifp->ifidx, 0, skb);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001787
1788 /* Use bus module to send data frame */
1789 return brcmf_bus_txdata(drvr->bus_if, skb);
1790 }
1791
1792 /* set control buffer information */
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001793 skcb->if_flags = 0;
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001794 skcb->mac = brcmf_fws_find_mac_desc(fws, ifp, eh->h_dest);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001795 skcb->state = BRCMF_FWS_SKBSTATE_NEW;
Arend van Spriel31ed07d2013-04-11 13:29:00 +02001796 brcmf_skb_if_flags_set_field(skb, INDEX, ifp->ifidx);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001797 if (!multicast)
1798 fifo = brcmf_fws_prio2fifo[skb->priority];
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001799
Arend van Spriel8071fd62013-06-06 13:17:51 +02001800 brcmf_dbg(DATA, "%s mac %pM multi %d fifo %d\n", skcb->mac->name,
1801 eh->h_dest, multicast, fifo);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001802
1803 brcmf_fws_lock(drvr, flags);
Arend van Spriel9fc60222013-04-11 17:12:04 +02001804 if (skcb->mac->suppressed ||
Hante Meulemandf50f752013-06-06 13:17:48 +02001805 fws->bus_flow_blocked ||
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001806 brcmf_fws_mac_desc_closed(fws, skcb->mac, fifo) ||
Arend van Spriel9fc60222013-04-11 17:12:04 +02001807 brcmu_pktq_mlen(&skcb->mac->psq, 3 << (fifo * 2)) ||
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001808 (!multicast &&
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001809 brcmf_fws_consume_credit(fws, fifo, skb) < 0)) {
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001810 /* enqueue the packet in delayQ */
1811 drvr->fws->fifo_delay_map |= 1 << fifo;
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001812 brcmf_fws_enq(fws, BRCMF_FWS_SKBSTATE_DELAYED, fifo, skb);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001813 } else {
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001814 brcmf_fws_commit_skb(fws, fifo, skb);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001815 }
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001816 brcmf_fws_unlock(drvr, flags);
1817 return 0;
1818}
1819
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001820void brcmf_fws_reset_interface(struct brcmf_if *ifp)
1821{
1822 struct brcmf_fws_mac_descriptor *entry = ifp->fws_desc;
1823
1824 brcmf_dbg(TRACE, "enter: idx=%d\n", ifp->bssidx);
1825 if (!entry)
1826 return;
1827
Arend van Sprielce814c12013-04-03 12:40:31 +02001828 brcmf_fws_init_mac_descriptor(entry, ifp->mac_addr, ifp->ifidx);
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001829}
1830
1831void brcmf_fws_add_interface(struct brcmf_if *ifp)
1832{
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001833 struct brcmf_fws_info *fws = ifp->drvr->fws;
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001834 struct brcmf_fws_mac_descriptor *entry;
1835
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02001836 if (!ifp->ndev || !ifp->drvr->fw_signals)
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001837 return;
1838
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001839 entry = &fws->desc.iface[ifp->ifidx];
1840 ifp->fws_desc = entry;
1841 brcmf_fws_init_mac_descriptor(entry, ifp->mac_addr, ifp->ifidx);
Arend van Spriel8071fd62013-06-06 13:17:51 +02001842 brcmf_fws_macdesc_set_name(fws, entry);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001843 brcmu_pktq_init(&entry->psq, BRCMF_FWS_PSQ_PREC_COUNT,
1844 BRCMF_FWS_PSQ_LEN);
Arend van Spriel8071fd62013-06-06 13:17:51 +02001845 brcmf_dbg(TRACE, "added %s\n", entry->name);
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001846}
1847
1848void brcmf_fws_del_interface(struct brcmf_if *ifp)
1849{
1850 struct brcmf_fws_mac_descriptor *entry = ifp->fws_desc;
Arend van Spriel6d421e52013-04-17 21:25:55 +02001851 ulong flags;
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001852
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001853 if (!entry)
1854 return;
1855
Arend van Spriel6d421e52013-04-17 21:25:55 +02001856 brcmf_fws_lock(ifp->drvr, flags);
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001857 ifp->fws_desc = NULL;
Arend van Spriel8071fd62013-06-06 13:17:51 +02001858 brcmf_dbg(TRACE, "deleting %s\n", entry->name);
Arend van Sprielce814c12013-04-03 12:40:31 +02001859 brcmf_fws_clear_mac_descriptor(entry);
Arend van Spriela3e993c2013-04-03 12:40:36 +02001860 brcmf_fws_cleanup(ifp->drvr->fws, ifp->ifidx);
Arend van Spriel6d421e52013-04-17 21:25:55 +02001861 brcmf_fws_unlock(ifp->drvr, flags);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001862}
1863
1864static void brcmf_fws_dequeue_worker(struct work_struct *worker)
1865{
1866 struct brcmf_fws_info *fws;
1867 struct sk_buff *skb;
1868 ulong flags;
1869 int fifo;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001870
1871 fws = container_of(worker, struct brcmf_fws_info, fws_dequeue_work);
1872
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001873 brcmf_fws_lock(fws->drvr, flags);
Hante Meulemandf50f752013-06-06 13:17:48 +02001874 for (fifo = NL80211_NUM_ACS; fifo >= 0 && !fws->bus_flow_blocked;
1875 fifo--) {
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001876 while (fws->fifo_credit[fifo]) {
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001877 skb = brcmf_fws_deq(fws, fifo);
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001878 if (!skb)
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001879 break;
Arend van Spriel047445c2013-04-17 21:25:58 +02001880 if (brcmf_skbcb(skb)->if_flags &
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001881 BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK)
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001882 fws->fifo_credit[fifo]--;
1883
1884 if (brcmf_fws_commit_skb(fws, fifo, skb))
1885 break;
Hante Meulemandf50f752013-06-06 13:17:48 +02001886 if (fws->bus_flow_blocked)
1887 break;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001888 }
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001889 if ((fifo == BRCMF_FWS_FIFO_AC_BE) &&
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001890 (fws->fifo_credit[fifo] == 0) &&
Hante Meulemandf50f752013-06-06 13:17:48 +02001891 (!fws->bus_flow_blocked)) {
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001892 while (brcmf_fws_borrow_credit(fws) == 0) {
1893 skb = brcmf_fws_deq(fws, fifo);
1894 if (!skb) {
1895 brcmf_fws_return_credits(fws, fifo, 1);
1896 break;
1897 }
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001898 brcmf_fws_commit_skb(fws, fifo, skb);
Hante Meulemandf50f752013-06-06 13:17:48 +02001899 if (fws->bus_flow_blocked)
1900 break;
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001901 }
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001902 }
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001903 }
1904 brcmf_fws_unlock(fws->drvr, flags);
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001905}
Arend van Sprielc7f34a62013-04-03 12:40:39 +02001906
Arend van Sprield9337412013-04-03 12:40:47 +02001907int brcmf_fws_init(struct brcmf_pub *drvr)
1908{
Arend van Spriel290fb762013-04-03 12:40:49 +02001909 u32 tlv = BRCMF_FWS_FLAGS_RSSI_SIGNALS;
Arend van Sprield9337412013-04-03 12:40:47 +02001910 int rc;
1911
Arend van Spriel47829f42013-04-03 12:40:48 +02001912 if (!drvr->fw_signals)
1913 return 0;
1914
Arend van Sprield9337412013-04-03 12:40:47 +02001915 spin_lock_init(&drvr->fws_spinlock);
1916
1917 drvr->fws = kzalloc(sizeof(*(drvr->fws)), GFP_KERNEL);
1918 if (!drvr->fws) {
1919 rc = -ENOMEM;
1920 goto fail;
1921 }
1922
1923 /* set linkage back */
1924 drvr->fws->drvr = drvr;
1925 drvr->fws->fcmode = fcmode;
1926
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001927 drvr->fws->fws_wq = create_singlethread_workqueue("brcmf_fws_wq");
1928 if (drvr->fws->fws_wq == NULL) {
1929 brcmf_err("workqueue creation failed\n");
1930 rc = -EBADF;
1931 goto fail;
1932 }
1933 INIT_WORK(&drvr->fws->fws_dequeue_work, brcmf_fws_dequeue_worker);
1934
Arend van Spriel290fb762013-04-03 12:40:49 +02001935 /* enable firmware signalling if fcmode active */
1936 if (drvr->fws->fcmode != BRCMF_FWS_FCMODE_NONE)
1937 tlv |= BRCMF_FWS_FLAGS_XONXOFF_SIGNALS |
Arend van Spriel33753d42013-04-05 10:57:40 +02001938 BRCMF_FWS_FLAGS_CREDIT_STATUS_SIGNALS |
1939 BRCMF_FWS_FLAGS_HOST_PROPTXSTATUS_ACTIVE;
Arend van Spriel290fb762013-04-03 12:40:49 +02001940
Arend van Spriela786b382013-04-23 12:53:14 +02001941 rc = brcmf_fweh_register(drvr, BRCMF_E_FIFO_CREDIT_MAP,
1942 brcmf_fws_notify_credit_map);
Arend van Sprield9337412013-04-03 12:40:47 +02001943 if (rc < 0) {
Arend van Spriela786b382013-04-23 12:53:14 +02001944 brcmf_err("register credit map handler failed\n");
Arend van Sprield9337412013-04-03 12:40:47 +02001945 goto fail;
1946 }
1947
Arend van Spriela786b382013-04-23 12:53:14 +02001948 /* setting the iovar may fail if feature is unsupported
1949 * so leave the rc as is so driver initialization can
1950 * continue.
1951 */
1952 if (brcmf_fil_iovar_int_set(drvr->iflist[0], "tlv", tlv)) {
1953 brcmf_err("failed to set bdcv2 tlv signaling\n");
1954 goto fail_event;
Arend van Sprield9337412013-04-03 12:40:47 +02001955 }
1956
1957 brcmf_fws_hanger_init(&drvr->fws->hanger);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001958 brcmf_fws_init_mac_descriptor(&drvr->fws->desc.other, NULL, 0);
Arend van Spriel8071fd62013-06-06 13:17:51 +02001959 brcmf_fws_macdesc_set_name(drvr->fws, &drvr->fws->desc.other);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001960 brcmu_pktq_init(&drvr->fws->desc.other.psq, BRCMF_FWS_PSQ_PREC_COUNT,
1961 BRCMF_FWS_PSQ_LEN);
Arend van Sprield9337412013-04-03 12:40:47 +02001962
1963 /* create debugfs file for statistics */
1964 brcmf_debugfs_create_fws_stats(drvr, &drvr->fws->stats);
1965
Arend van Spriel8071fd62013-06-06 13:17:51 +02001966 brcmf_dbg(INFO, "%s bdcv2 tlv signaling [%x]\n",
Arend van Sprield9337412013-04-03 12:40:47 +02001967 drvr->fw_signals ? "enabled" : "disabled", tlv);
1968 return 0;
1969
Arend van Spriela786b382013-04-23 12:53:14 +02001970fail_event:
1971 brcmf_fweh_unregister(drvr, BRCMF_E_FIFO_CREDIT_MAP);
Arend van Sprield9337412013-04-03 12:40:47 +02001972fail:
Arend van Sprield9337412013-04-03 12:40:47 +02001973 brcmf_fws_deinit(drvr);
1974 return rc;
1975}
1976
1977void brcmf_fws_deinit(struct brcmf_pub *drvr)
1978{
1979 struct brcmf_fws_info *fws = drvr->fws;
1980 ulong flags;
1981
Arend van Spriel47829f42013-04-03 12:40:48 +02001982 if (!fws)
1983 return;
1984
Arend van Spriela786b382013-04-23 12:53:14 +02001985 /* disable firmware signalling entirely
1986 * to avoid using the workqueue.
1987 */
1988 drvr->fw_signals = false;
1989
1990 if (drvr->fws->fws_wq)
1991 destroy_workqueue(drvr->fws->fws_wq);
1992
Arend van Sprield9337412013-04-03 12:40:47 +02001993 /* cleanup */
1994 brcmf_fws_lock(drvr, flags);
1995 brcmf_fws_cleanup(fws, -1);
1996 drvr->fws = NULL;
1997 brcmf_fws_unlock(drvr, flags);
1998
1999 /* free top structure */
2000 kfree(fws);
2001}
2002
Arend van Sprielc7f34a62013-04-03 12:40:39 +02002003bool brcmf_fws_fc_active(struct brcmf_fws_info *fws)
2004{
2005 if (!fws)
2006 return false;
2007
Arend van Sprielc7f34a62013-04-03 12:40:39 +02002008 return fws->fcmode != BRCMF_FWS_FCMODE_NONE;
2009}
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02002010
2011void brcmf_fws_bustxfail(struct brcmf_fws_info *fws, struct sk_buff *skb)
2012{
2013 ulong flags;
Arend van Sprielfe353b22013-06-06 13:17:49 +02002014 int fifo;
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02002015
2016 brcmf_fws_lock(fws->drvr, flags);
Arend van Spriel8071fd62013-06-06 13:17:51 +02002017 brcmf_fws_txs_process(fws, BRCMF_FWS_TXSTATUS_FW_TOSSED,
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02002018 brcmf_skb_htod_tag_get_field(skb, HSLOT), 0);
2019 /* the packet never reached firmware so reclaim credit */
Arend van Sprielfe353b22013-06-06 13:17:49 +02002020 if (fws->fcmode == BRCMF_FWS_FCMODE_EXPLICIT_CREDIT) {
2021 fifo = brcmf_skb_htod_tag_get_field(skb, FIFO);
2022 brcmf_fws_skb_pickup_credit(fws, fifo, skb);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02002023 }
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02002024 brcmf_fws_unlock(fws->drvr, flags);
2025}
Hante Meulemandf50f752013-06-06 13:17:48 +02002026
2027void brcmf_fws_bus_blocked(struct brcmf_pub *drvr, bool flow_blocked)
2028{
2029 struct brcmf_fws_info *fws = drvr->fws;
2030
2031 fws->bus_flow_blocked = flow_blocked;
2032 if (!flow_blocked)
2033 brcmf_fws_schedule_deq(fws);
2034}