blob: dc40eec8a5ccba3bac2d88cb2ac3072aee98ffd9 [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 suppr_transit_count;
361 bool send_tim_signal;
362 u8 traffic_pending_bmp;
363 u8 traffic_lastreported_bmp;
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200364};
365
Arend van Spriel69712802013-04-03 12:40:37 +0200366#define BRCMF_FWS_HANGER_MAXITEMS 1024
367
368/**
369 * enum brcmf_fws_hanger_item_state - state of hanger item.
370 *
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200371 * @BRCMF_FWS_HANGER_ITEM_STATE_FREE: item is free for use.
372 * @BRCMF_FWS_HANGER_ITEM_STATE_INUSE: item is in use.
373 * @BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED: item was suppressed.
Arend van Spriel69712802013-04-03 12:40:37 +0200374 */
375enum brcmf_fws_hanger_item_state {
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200376 BRCMF_FWS_HANGER_ITEM_STATE_FREE = 1,
377 BRCMF_FWS_HANGER_ITEM_STATE_INUSE,
378 BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED
Arend van Spriel69712802013-04-03 12:40:37 +0200379};
380
381
382/**
383 * struct brcmf_fws_hanger_item - single entry for tx pending packet.
384 *
385 * @state: entry is either free or occupied.
Arend van Spriel69712802013-04-03 12:40:37 +0200386 * @pkt: packet itself.
387 */
388struct brcmf_fws_hanger_item {
389 enum brcmf_fws_hanger_item_state state;
Arend van Spriel69712802013-04-03 12:40:37 +0200390 struct sk_buff *pkt;
391};
392
393/**
394 * struct brcmf_fws_hanger - holds packets awaiting firmware txstatus.
395 *
Arend van Spriel69712802013-04-03 12:40:37 +0200396 * @pushed: packets pushed to await txstatus.
397 * @popped: packets popped upon handling txstatus.
398 * @failed_to_push: packets that could not be pushed.
399 * @failed_to_pop: packets that could not be popped.
400 * @failed_slotfind: packets for which failed to find an entry.
401 * @slot_pos: last returned item index for a free entry.
402 * @items: array of hanger items.
403 */
404struct brcmf_fws_hanger {
405 u32 pushed;
406 u32 popped;
407 u32 failed_to_push;
408 u32 failed_to_pop;
409 u32 failed_slotfind;
410 u32 slot_pos;
411 struct brcmf_fws_hanger_item items[BRCMF_FWS_HANGER_MAXITEMS];
412};
413
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200414struct brcmf_fws_macdesc_table {
415 struct brcmf_fws_mac_descriptor nodes[BRCMF_FWS_MAC_DESC_TABLE_SIZE];
416 struct brcmf_fws_mac_descriptor iface[BRCMF_MAX_IFS];
417 struct brcmf_fws_mac_descriptor other;
418};
419
Arend van Spriel349e7102013-03-03 12:45:28 +0100420struct brcmf_fws_info {
421 struct brcmf_pub *drvr;
422 struct brcmf_fws_stats stats;
Arend van Spriel69712802013-04-03 12:40:37 +0200423 struct brcmf_fws_hanger hanger;
Arend van Sprielc7f34a62013-04-03 12:40:39 +0200424 enum brcmf_fws_fcmode fcmode;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200425 struct brcmf_fws_macdesc_table desc;
426 struct workqueue_struct *fws_wq;
427 struct work_struct fws_dequeue_work;
428 u32 fifo_enqpkt[BRCMF_FWS_FIFO_COUNT];
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200429 int fifo_credit[BRCMF_FWS_FIFO_COUNT];
Arend van Spriel1aac1e92013-04-23 12:53:15 +0200430 int credits_borrowed[BRCMF_FWS_FIFO_AC_VO + 1];
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200431 int deq_node_pos[BRCMF_FWS_FIFO_COUNT];
432 u32 fifo_credit_map;
433 u32 fifo_delay_map;
Arend van Spriel1aac1e92013-04-23 12:53:15 +0200434 unsigned long borrow_defer_timestamp;
Hante Meulemandf50f752013-06-06 13:17:48 +0200435 bool bus_flow_blocked;
Hante Meuleman0d24b0e2013-06-06 13:17:58 +0200436 bool creditmap_received;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200437};
438
439/*
440 * brcmf_fws_prio2fifo - mapping from 802.1d priority to firmware fifo index.
441 */
442static const int brcmf_fws_prio2fifo[] = {
443 BRCMF_FWS_FIFO_AC_BE,
444 BRCMF_FWS_FIFO_AC_BK,
445 BRCMF_FWS_FIFO_AC_BK,
446 BRCMF_FWS_FIFO_AC_BE,
447 BRCMF_FWS_FIFO_AC_VI,
448 BRCMF_FWS_FIFO_AC_VI,
449 BRCMF_FWS_FIFO_AC_VO,
450 BRCMF_FWS_FIFO_AC_VO
Arend van Spriel349e7102013-03-03 12:45:28 +0100451};
452
Arend van Sprielc7f34a62013-04-03 12:40:39 +0200453static int fcmode;
454module_param(fcmode, int, S_IRUSR);
455MODULE_PARM_DESC(fcmode, "mode of firmware signalled flow control");
456
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200457#define BRCMF_FWS_TLV_DEF(name, id, len) \
458 case BRCMF_FWS_TYPE_ ## name: \
459 return len;
460
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200461/**
462 * brcmf_fws_get_tlv_len() - returns defined length for given tlv id.
463 *
464 * @fws: firmware-signalling information.
465 * @id: identifier of the TLV.
466 *
467 * Return: the specified length for the given TLV; Otherwise -EINVAL.
468 */
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200469static int brcmf_fws_get_tlv_len(struct brcmf_fws_info *fws,
470 enum brcmf_fws_tlv_type id)
471{
472 switch (id) {
473 BRCMF_FWS_TLV_DEFLIST
474 default:
Arend van Sprielbb8c8062013-04-03 12:40:30 +0200475 fws->stats.tlv_invalid_type++;
476 break;
477 }
478 return -EINVAL;
479}
480#undef BRCMF_FWS_TLV_DEF
481
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200482static bool brcmf_fws_ifidx_match(struct sk_buff *skb, void *arg)
483{
484 u32 ifidx = brcmf_skb_if_flags_get_field(skb, INDEX);
485 return ifidx == *(int *)arg;
486}
487
488static void brcmf_fws_psq_flush(struct brcmf_fws_info *fws, struct pktq *q,
489 int ifidx)
490{
491 bool (*matchfn)(struct sk_buff *, void *) = NULL;
492 struct sk_buff *skb;
493 int prec;
494
495 if (ifidx != -1)
496 matchfn = brcmf_fws_ifidx_match;
497 for (prec = 0; prec < q->num_prec; prec++) {
498 skb = brcmu_pktq_pdeq_match(q, prec, matchfn, &ifidx);
499 while (skb) {
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200500 brcmu_pkt_buf_free_skb(skb);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200501 skb = brcmu_pktq_pdeq_match(q, prec, matchfn, &ifidx);
502 }
503 }
504}
505
Arend van Spriel69712802013-04-03 12:40:37 +0200506static void brcmf_fws_hanger_init(struct brcmf_fws_hanger *hanger)
507{
508 int i;
509
Arend van Spriel69712802013-04-03 12:40:37 +0200510 memset(hanger, 0, sizeof(*hanger));
511 for (i = 0; i < ARRAY_SIZE(hanger->items); i++)
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200512 hanger->items[i].state = BRCMF_FWS_HANGER_ITEM_STATE_FREE;
Arend van Spriel69712802013-04-03 12:40:37 +0200513}
514
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200515static u32 brcmf_fws_hanger_get_free_slot(struct brcmf_fws_hanger *h)
Arend van Spriel69712802013-04-03 12:40:37 +0200516{
517 u32 i;
518
Arend van Spriel69712802013-04-03 12:40:37 +0200519 i = (h->slot_pos + 1) % BRCMF_FWS_HANGER_MAXITEMS;
520
521 while (i != h->slot_pos) {
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200522 if (h->items[i].state == BRCMF_FWS_HANGER_ITEM_STATE_FREE) {
Arend van Spriel69712802013-04-03 12:40:37 +0200523 h->slot_pos = i;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200524 goto done;
Arend van Spriel69712802013-04-03 12:40:37 +0200525 }
526 i++;
527 if (i == BRCMF_FWS_HANGER_MAXITEMS)
528 i = 0;
529 }
530 brcmf_err("all slots occupied\n");
531 h->failed_slotfind++;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200532 i = BRCMF_FWS_HANGER_MAXITEMS;
533done:
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200534 return i;
Arend van Spriel69712802013-04-03 12:40:37 +0200535}
536
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200537static int brcmf_fws_hanger_pushpkt(struct brcmf_fws_hanger *h,
Hante Meulemanbe4910a2013-06-06 13:17:53 +0200538 struct sk_buff *pkt, u32 slot_id)
Arend van Spriel69712802013-04-03 12:40:37 +0200539{
Arend van Spriel69712802013-04-03 12:40:37 +0200540 if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS)
541 return -ENOENT;
542
543 if (h->items[slot_id].state != BRCMF_FWS_HANGER_ITEM_STATE_FREE) {
544 brcmf_err("slot is not free\n");
545 h->failed_to_push++;
546 return -EINVAL;
547 }
548
549 h->items[slot_id].state = BRCMF_FWS_HANGER_ITEM_STATE_INUSE;
550 h->items[slot_id].pkt = pkt;
Arend van Spriel69712802013-04-03 12:40:37 +0200551 h->pushed++;
552 return 0;
553}
554
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200555static int brcmf_fws_hanger_poppkt(struct brcmf_fws_hanger *h,
Arend van Spriel69712802013-04-03 12:40:37 +0200556 u32 slot_id, struct sk_buff **pktout,
557 bool remove_item)
558{
Arend van Spriel69712802013-04-03 12:40:37 +0200559 if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS)
560 return -ENOENT;
561
562 if (h->items[slot_id].state == BRCMF_FWS_HANGER_ITEM_STATE_FREE) {
563 brcmf_err("entry not in use\n");
564 h->failed_to_pop++;
565 return -EINVAL;
566 }
567
568 *pktout = h->items[slot_id].pkt;
569 if (remove_item) {
570 h->items[slot_id].state = BRCMF_FWS_HANGER_ITEM_STATE_FREE;
571 h->items[slot_id].pkt = NULL;
Arend van Spriel69712802013-04-03 12:40:37 +0200572 h->popped++;
573 }
574 return 0;
575}
576
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200577static int brcmf_fws_hanger_mark_suppressed(struct brcmf_fws_hanger *h,
Hante Meulemanbe4910a2013-06-06 13:17:53 +0200578 u32 slot_id)
Arend van Spriel69712802013-04-03 12:40:37 +0200579{
Arend van Spriel69712802013-04-03 12:40:37 +0200580 if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS)
581 return -ENOENT;
582
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200583 if (h->items[slot_id].state != BRCMF_FWS_HANGER_ITEM_STATE_INUSE) {
Arend van Spriel69712802013-04-03 12:40:37 +0200584 brcmf_err("entry not in use\n");
585 return -EINVAL;
586 }
587
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200588 h->items[slot_id].state = BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED;
Arend van Spriel69712802013-04-03 12:40:37 +0200589 return 0;
590}
591
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200592static void brcmf_fws_hanger_cleanup(struct brcmf_fws_info *fws,
Arend van Spriel69712802013-04-03 12:40:37 +0200593 bool (*fn)(struct sk_buff *, void *),
594 int ifidx)
595{
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200596 struct brcmf_fws_hanger *h = &fws->hanger;
Arend van Spriel69712802013-04-03 12:40:37 +0200597 struct sk_buff *skb;
598 int i;
599 enum brcmf_fws_hanger_item_state s;
600
Arend van Spriel69712802013-04-03 12:40:37 +0200601 for (i = 0; i < ARRAY_SIZE(h->items); i++) {
602 s = h->items[i].state;
603 if (s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE ||
604 s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED) {
605 skb = h->items[i].pkt;
606 if (fn == NULL || fn(skb, &ifidx)) {
607 /* suppress packets freed from psq */
608 if (s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE)
609 brcmu_pkt_buf_free_skb(skb);
610 h->items[i].state =
611 BRCMF_FWS_HANGER_ITEM_STATE_FREE;
612 }
613 }
614 }
615}
616
Arend van Spriel8071fd62013-06-06 13:17:51 +0200617static void brcmf_fws_macdesc_set_name(struct brcmf_fws_info *fws,
618 struct brcmf_fws_mac_descriptor *desc)
619{
620 if (desc == &fws->desc.other)
621 strlcpy(desc->name, "MAC-OTHER", sizeof(desc->name));
622 else if (desc->mac_handle)
623 scnprintf(desc->name, sizeof(desc->name), "MAC-%d:%d",
624 desc->mac_handle, desc->interface_id);
625 else
626 scnprintf(desc->name, sizeof(desc->name), "MACIF:%d",
627 desc->interface_id);
628}
629
Arend van Sprielce814c12013-04-03 12:40:31 +0200630static void brcmf_fws_init_mac_descriptor(struct brcmf_fws_mac_descriptor *desc,
631 u8 *addr, u8 ifidx)
632{
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200633 brcmf_dbg(TRACE,
634 "enter: desc %p ea=%pM, ifidx=%u\n", desc, addr, ifidx);
Arend van Sprielce814c12013-04-03 12:40:31 +0200635 desc->occupied = 1;
636 desc->state = BRCMF_FWS_STATE_OPEN;
637 desc->requested_credit = 0;
638 /* depending on use may need ifp->bssidx instead */
639 desc->interface_id = ifidx;
640 desc->ac_bitmap = 0xff; /* update this when handling APSD */
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200641 if (addr)
642 memcpy(&desc->ea[0], addr, ETH_ALEN);
Arend van Sprielce814c12013-04-03 12:40:31 +0200643}
644
645static
646void brcmf_fws_clear_mac_descriptor(struct brcmf_fws_mac_descriptor *desc)
647{
648 brcmf_dbg(TRACE,
649 "enter: ea=%pM, ifidx=%u\n", desc->ea, desc->interface_id);
650 desc->occupied = 0;
651 desc->state = BRCMF_FWS_STATE_CLOSE;
652 desc->requested_credit = 0;
653}
654
655static struct brcmf_fws_mac_descriptor *
656brcmf_fws_mac_descriptor_lookup(struct brcmf_fws_info *fws, u8 *ea)
657{
658 struct brcmf_fws_mac_descriptor *entry;
659 int i;
660
Arend van Sprielce814c12013-04-03 12:40:31 +0200661 if (ea == NULL)
662 return ERR_PTR(-EINVAL);
663
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200664 entry = &fws->desc.nodes[0];
665 for (i = 0; i < ARRAY_SIZE(fws->desc.nodes); i++) {
Arend van Sprielce814c12013-04-03 12:40:31 +0200666 if (entry->occupied && !memcmp(entry->ea, ea, ETH_ALEN))
667 return entry;
668 entry++;
669 }
670
671 return ERR_PTR(-ENOENT);
672}
673
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200674static struct brcmf_fws_mac_descriptor*
Arend van Sprielf97a7f02013-04-11 13:28:58 +0200675brcmf_fws_find_mac_desc(struct brcmf_fws_info *fws, struct brcmf_if *ifp,
676 u8 *da)
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200677{
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200678 struct brcmf_fws_mac_descriptor *entry = &fws->desc.other;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200679 bool multicast;
Arend van Sprielf97a7f02013-04-11 13:28:58 +0200680
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200681 multicast = is_multicast_ether_addr(da);
Arend van Spriela7965fb2013-04-11 17:08:37 +0200682
Hante Meuleman5cd51c22013-06-06 13:17:56 +0200683 /* Multicast destination, STA and P2P clients get the interface entry.
684 * STA/GC gets the Mac Entry for TDLS destinations, TDLS destinations
685 * have their own entry.
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200686 */
Hante Meuleman5cd51c22013-06-06 13:17:56 +0200687 if (multicast && ifp->fws_desc) {
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200688 entry = ifp->fws_desc;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200689 goto done;
Hante Meuleman5cd51c22013-06-06 13:17:56 +0200690 }
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200691
692 entry = brcmf_fws_mac_descriptor_lookup(fws, da);
693 if (IS_ERR(entry))
Hante Meuleman5cd51c22013-06-06 13:17:56 +0200694 entry = ifp->fws_desc;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200695
696done:
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200697 return entry;
698}
699
Arend van Sprielb75c1a32013-04-17 21:25:53 +0200700static bool brcmf_fws_mac_desc_closed(struct brcmf_fws_info *fws,
701 struct brcmf_fws_mac_descriptor *entry,
Arend van Spriel9fc60222013-04-11 17:12:04 +0200702 int fifo)
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200703{
Arend van Sprielb75c1a32013-04-17 21:25:53 +0200704 struct brcmf_fws_mac_descriptor *if_entry;
Arend van Spriel9fc60222013-04-11 17:12:04 +0200705 bool closed;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200706
Arend van Sprielb75c1a32013-04-17 21:25:53 +0200707 /* for unique destination entries the related interface
708 * may be closed.
709 */
710 if (entry->mac_handle) {
711 if_entry = &fws->desc.iface[entry->interface_id];
712 if (if_entry->state == BRCMF_FWS_STATE_CLOSE)
713 return true;
714 }
Arend van Spriel9fc60222013-04-11 17:12:04 +0200715 /* an entry is closed when the state is closed and
716 * the firmware did not request anything.
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200717 */
Arend van Spriel9fc60222013-04-11 17:12:04 +0200718 closed = entry->state == BRCMF_FWS_STATE_CLOSE &&
719 !entry->requested_credit && !entry->requested_packet;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200720
Arend van Spriel9fc60222013-04-11 17:12:04 +0200721 /* Or firmware does not allow traffic for given fifo */
722 return closed || !(entry->ac_bitmap & BIT(fifo));
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200723}
724
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200725static void brcmf_fws_mac_desc_cleanup(struct brcmf_fws_info *fws,
726 struct brcmf_fws_mac_descriptor *entry,
Arend van Sprielfba14002013-04-03 12:40:33 +0200727 int ifidx)
728{
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200729 if (entry->occupied && (ifidx == -1 || ifidx == entry->interface_id)) {
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200730 brcmf_fws_psq_flush(fws, &entry->psq, ifidx);
Arend van Sprielfba14002013-04-03 12:40:33 +0200731 entry->occupied = !!(entry->psq.len);
732 }
733}
734
Arend van Spriele2432b62013-04-03 12:40:38 +0200735static void brcmf_fws_bus_txq_cleanup(struct brcmf_fws_info *fws,
736 bool (*fn)(struct sk_buff *, void *),
737 int ifidx)
738{
739 struct brcmf_fws_hanger_item *hi;
740 struct pktq *txq;
741 struct sk_buff *skb;
742 int prec;
743 u32 hslot;
744
Arend van Spriele2432b62013-04-03 12:40:38 +0200745 txq = brcmf_bus_gettxq(fws->drvr->bus_if);
746 if (IS_ERR(txq)) {
747 brcmf_dbg(TRACE, "no txq to clean up\n");
748 return;
749 }
750
751 for (prec = 0; prec < txq->num_prec; prec++) {
752 skb = brcmu_pktq_pdeq_match(txq, prec, fn, &ifidx);
753 while (skb) {
754 hslot = brcmf_skb_htod_tag_get_field(skb, HSLOT);
755 hi = &fws->hanger.items[hslot];
756 WARN_ON(skb != hi->pkt);
757 hi->state = BRCMF_FWS_HANGER_ITEM_STATE_FREE;
758 brcmu_pkt_buf_free_skb(skb);
759 skb = brcmu_pktq_pdeq_match(txq, prec, fn, &ifidx);
760 }
761 }
762}
763
Arend van Sprielfba14002013-04-03 12:40:33 +0200764static void brcmf_fws_cleanup(struct brcmf_fws_info *fws, int ifidx)
765{
766 int i;
767 struct brcmf_fws_mac_descriptor *table;
Arend van Spriela3e993c2013-04-03 12:40:36 +0200768 bool (*matchfn)(struct sk_buff *, void *) = NULL;
Arend van Sprielfba14002013-04-03 12:40:33 +0200769
Arend van Sprielfba14002013-04-03 12:40:33 +0200770 if (fws == NULL)
771 return;
772
Arend van Spriela3e993c2013-04-03 12:40:36 +0200773 if (ifidx != -1)
774 matchfn = brcmf_fws_ifidx_match;
775
Arend van Sprielfba14002013-04-03 12:40:33 +0200776 /* cleanup individual nodes */
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200777 table = &fws->desc.nodes[0];
778 for (i = 0; i < ARRAY_SIZE(fws->desc.nodes); i++)
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200779 brcmf_fws_mac_desc_cleanup(fws, &table[i], ifidx);
Arend van Sprielfba14002013-04-03 12:40:33 +0200780
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200781 brcmf_fws_mac_desc_cleanup(fws, &fws->desc.other, ifidx);
Arend van Spriele2432b62013-04-03 12:40:38 +0200782 brcmf_fws_bus_txq_cleanup(fws, matchfn, ifidx);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200783 brcmf_fws_hanger_cleanup(fws, matchfn, ifidx);
784}
785
786static void brcmf_fws_tim_update(struct brcmf_fws_info *ctx,
787 struct brcmf_fws_mac_descriptor *entry,
788 int prec)
789{
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200790 if (entry->state == BRCMF_FWS_STATE_CLOSE) {
791 /* check delayedQ and suppressQ in one call using bitmap */
792 if (brcmu_pktq_mlen(&entry->psq, 3 << (prec * 2)) == 0)
793 entry->traffic_pending_bmp =
794 entry->traffic_pending_bmp & ~NBITVAL(prec);
795 else
796 entry->traffic_pending_bmp =
797 entry->traffic_pending_bmp | NBITVAL(prec);
798 }
799 /* request a TIM update to firmware at the next piggyback opportunity */
800 if (entry->traffic_lastreported_bmp != entry->traffic_pending_bmp)
801 entry->send_tim_signal = true;
802}
803
804static void
805brcmf_fws_flow_control_check(struct brcmf_fws_info *fws, struct pktq *pq,
806 u8 if_id)
807{
Hante Meuleman402e3ba2013-06-06 13:17:57 +0200808 struct brcmf_if *ifp = fws->drvr->iflist[!if_id ? 0 : if_id + 1];
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200809
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200810 if (WARN_ON(!ifp))
811 return;
812
813 if ((ifp->netif_stop & BRCMF_NETIF_STOP_REASON_FWS_FC) &&
814 pq->len <= BRCMF_FWS_FLOWCONTROL_LOWATER)
815 brcmf_txflowblock_if(ifp,
816 BRCMF_NETIF_STOP_REASON_FWS_FC, false);
817 if (!(ifp->netif_stop & BRCMF_NETIF_STOP_REASON_FWS_FC) &&
818 pq->len >= BRCMF_FWS_FLOWCONTROL_HIWATER)
819 brcmf_txflowblock_if(ifp, BRCMF_NETIF_STOP_REASON_FWS_FC, true);
820 return;
Arend van Sprielfba14002013-04-03 12:40:33 +0200821}
822
Arend van Spriel349e7102013-03-03 12:45:28 +0100823static int brcmf_fws_rssi_indicate(struct brcmf_fws_info *fws, s8 rssi)
824{
825 brcmf_dbg(CTL, "rssi %d\n", rssi);
826 return 0;
827}
828
Arend van Sprielce814c12013-04-03 12:40:31 +0200829static
830int brcmf_fws_macdesc_indicate(struct brcmf_fws_info *fws, u8 type, u8 *data)
831{
832 struct brcmf_fws_mac_descriptor *entry, *existing;
833 u8 mac_handle;
834 u8 ifidx;
835 u8 *addr;
836
837 mac_handle = *data++;
838 ifidx = *data++;
839 addr = data;
840
Arend van Spriel84bcc0c2013-04-03 12:40:50 +0200841 entry = &fws->desc.nodes[mac_handle & 0x1F];
Arend van Sprielce814c12013-04-03 12:40:31 +0200842 if (type == BRCMF_FWS_TYPE_MACDESC_DEL) {
Arend van Spriel9a83f1e2013-04-23 12:53:13 +0200843 if (entry->occupied) {
Arend van Spriel8071fd62013-06-06 13:17:51 +0200844 brcmf_dbg(TRACE, "deleting %s mac %pM\n",
845 entry->name, addr);
Arend van Spriel9a83f1e2013-04-23 12:53:13 +0200846 brcmf_fws_mac_desc_cleanup(fws, entry, -1);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +0200847 brcmf_fws_clear_mac_descriptor(entry);
Arend van Spriel9a83f1e2013-04-23 12:53:13 +0200848 } else
Arend van Sprielce814c12013-04-03 12:40:31 +0200849 fws->stats.mac_update_failed++;
Arend van Sprielce814c12013-04-03 12:40:31 +0200850 return 0;
851 }
852
Arend van Sprielce814c12013-04-03 12:40:31 +0200853 existing = brcmf_fws_mac_descriptor_lookup(fws, addr);
854 if (IS_ERR(existing)) {
855 if (!entry->occupied) {
856 entry->mac_handle = mac_handle;
857 brcmf_fws_init_mac_descriptor(entry, addr, ifidx);
Arend van Spriel8071fd62013-06-06 13:17:51 +0200858 brcmf_fws_macdesc_set_name(fws, entry);
Arend van Sprielce814c12013-04-03 12:40:31 +0200859 brcmu_pktq_init(&entry->psq, BRCMF_FWS_PSQ_PREC_COUNT,
860 BRCMF_FWS_PSQ_LEN);
Arend van Spriel8071fd62013-06-06 13:17:51 +0200861 brcmf_dbg(TRACE, "add %s mac %pM\n", entry->name, addr);
Arend van Sprielce814c12013-04-03 12:40:31 +0200862 } else {
863 fws->stats.mac_update_failed++;
864 }
865 } else {
866 if (entry != existing) {
Arend van Spriel8071fd62013-06-06 13:17:51 +0200867 brcmf_dbg(TRACE, "copy mac %s\n", existing->name);
Arend van Sprielce814c12013-04-03 12:40:31 +0200868 memcpy(entry, existing,
869 offsetof(struct brcmf_fws_mac_descriptor, psq));
870 entry->mac_handle = mac_handle;
871 brcmf_fws_clear_mac_descriptor(existing);
Arend van Spriel8071fd62013-06-06 13:17:51 +0200872 brcmf_fws_macdesc_set_name(fws, entry);
873 brcmf_dbg(TRACE, "relocate %s mac %pM\n", entry->name,
874 addr);
Arend van Sprielce814c12013-04-03 12:40:31 +0200875 } else {
876 brcmf_dbg(TRACE, "use existing\n");
877 WARN_ON(entry->mac_handle != mac_handle);
878 /* TODO: what should we do here: continue, reinit, .. */
879 }
880 }
881 return 0;
882}
883
Arend van Spriel33753d42013-04-05 10:57:40 +0200884static int brcmf_fws_macdesc_state_indicate(struct brcmf_fws_info *fws,
885 u8 type, u8 *data)
886{
887 struct brcmf_fws_mac_descriptor *entry;
888 u8 mac_handle;
889 int i;
890
891 mac_handle = data[0];
892 entry = &fws->desc.nodes[mac_handle & 0x1F];
893 if (!entry->occupied) {
894 fws->stats.mac_ps_update_failed++;
895 return -ESRCH;
896 }
897
Arend van Spriel8071fd62013-06-06 13:17:51 +0200898 brcmf_dbg(TRACE, "%s (%d): %s\n", brcmf_fws_get_tlv_name(type), type,
899 entry->name);
Arend van Spriel33753d42013-04-05 10:57:40 +0200900 /* a state update should wipe old credits? */
901 entry->requested_credit = 0;
902 if (type == BRCMF_FWS_TYPE_MAC_OPEN) {
903 entry->state = BRCMF_FWS_STATE_OPEN;
Arend van Spriela5e9d802013-04-17 21:25:54 +0200904 return BRCMF_FWS_RET_OK_SCHEDULE;
Arend van Spriel33753d42013-04-05 10:57:40 +0200905 } else {
906 entry->state = BRCMF_FWS_STATE_CLOSE;
907 for (i = BRCMF_FWS_FIFO_AC_BE; i < NL80211_NUM_ACS; i++)
908 brcmf_fws_tim_update(fws, entry, i);
909 }
Arend van Spriela5e9d802013-04-17 21:25:54 +0200910 return BRCMF_FWS_RET_OK_NOSCHEDULE;
Arend van Spriel33753d42013-04-05 10:57:40 +0200911}
912
913static int brcmf_fws_interface_state_indicate(struct brcmf_fws_info *fws,
914 u8 type, u8 *data)
915{
916 struct brcmf_fws_mac_descriptor *entry;
917 u8 ifidx;
918 int ret;
919
920 ifidx = data[0];
921
Arend van Spriel33753d42013-04-05 10:57:40 +0200922 if (ifidx >= BRCMF_MAX_IFS) {
923 ret = -ERANGE;
924 goto fail;
925 }
926
927 entry = &fws->desc.iface[ifidx];
928 if (!entry->occupied) {
929 ret = -ESRCH;
930 goto fail;
931 }
932
Arend van Spriel8071fd62013-06-06 13:17:51 +0200933 brcmf_dbg(TRACE, "%s (%d): %s\n", brcmf_fws_get_tlv_name(type), type,
934 entry->name);
Arend van Spriel33753d42013-04-05 10:57:40 +0200935 switch (type) {
936 case BRCMF_FWS_TYPE_INTERFACE_OPEN:
937 entry->state = BRCMF_FWS_STATE_OPEN;
Arend van Spriela5e9d802013-04-17 21:25:54 +0200938 return BRCMF_FWS_RET_OK_SCHEDULE;
Arend van Spriel33753d42013-04-05 10:57:40 +0200939 case BRCMF_FWS_TYPE_INTERFACE_CLOSE:
940 entry->state = BRCMF_FWS_STATE_CLOSE;
Arend van Spriela5e9d802013-04-17 21:25:54 +0200941 return BRCMF_FWS_RET_OK_NOSCHEDULE;
Arend van Spriel33753d42013-04-05 10:57:40 +0200942 default:
943 ret = -EINVAL;
944 break;
945 }
946fail:
947 fws->stats.if_update_failed++;
948 return ret;
949}
950
Arend van Spriel5f38b682013-04-05 10:57:41 +0200951static int brcmf_fws_request_indicate(struct brcmf_fws_info *fws, u8 type,
952 u8 *data)
953{
954 struct brcmf_fws_mac_descriptor *entry;
955
956 entry = &fws->desc.nodes[data[1] & 0x1F];
957 if (!entry->occupied) {
958 if (type == BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT)
959 fws->stats.credit_request_failed++;
960 else
961 fws->stats.packet_request_failed++;
962 return -ESRCH;
963 }
964
Arend van Spriel8071fd62013-06-06 13:17:51 +0200965 brcmf_dbg(TRACE, "%s (%d): %s cnt %d bmp %d\n",
966 brcmf_fws_get_tlv_name(type), type, entry->name,
967 data[0], data[2]);
Arend van Spriel5f38b682013-04-05 10:57:41 +0200968 if (type == BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT)
969 entry->requested_credit = data[0];
970 else
971 entry->requested_packet = data[0];
972
973 entry->ac_bitmap = data[2];
Arend van Spriela5e9d802013-04-17 21:25:54 +0200974 return BRCMF_FWS_RET_OK_SCHEDULE;
Arend van Spriel5f38b682013-04-05 10:57:41 +0200975}
976
Arend van Spriel289ec1c2013-06-06 13:17:50 +0200977static int brcmf_fws_macdesc_use_credit(struct brcmf_fws_mac_descriptor *entry,
978 struct sk_buff *skb)
979{
980 int use_credit = 1;
981
982 if (entry->state == BRCMF_FWS_STATE_CLOSE) {
983 if (entry->requested_credit > 0) {
984 /*
985 * if the packet was pulled out while destination is in
986 * closed state but had a non-zero packets requested,
987 * then this should not count against the FIFO credit.
988 * That is due to the fact that the firmware will
989 * most likely hold onto this packet until a suitable
990 * time later to push it to the appropriate AC FIFO.
991 */
992 entry->requested_credit--;
993 brcmf_skb_if_flags_set_field(skb, REQ_CREDIT, 1);
994 use_credit = 0;
995 } else if (entry->requested_packet > 0) {
996 entry->requested_packet--;
997 brcmf_skb_if_flags_set_field(skb, REQUESTED, 1);
998 use_credit = 0;
999 }
1000 } else {
1001 WARN_ON(entry->requested_credit);
1002 WARN_ON(entry->requested_packet);
1003 }
1004 brcmf_skb_if_flags_set_field(skb, CREDITCHECK, use_credit);
1005 return use_credit;
1006}
1007
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001008static void brcmf_fws_return_credits(struct brcmf_fws_info *fws,
1009 u8 fifo, u8 credits)
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001010{
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001011 int lender_ac;
1012 int *borrowed;
1013 int *fifo_credit;
1014
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001015 if (!credits)
1016 return;
1017
Hante Meulemanafc3bbf2013-06-06 13:17:54 +02001018 fws->fifo_credit_map |= 1 << fifo;
1019
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001020 if ((fifo == BRCMF_FWS_FIFO_AC_BE) &&
1021 (fws->credits_borrowed[0])) {
1022 for (lender_ac = BRCMF_FWS_FIFO_AC_VO; lender_ac >= 0;
1023 lender_ac--) {
1024 borrowed = &fws->credits_borrowed[lender_ac];
1025 if (*borrowed) {
1026 fws->fifo_credit_map |= (1 << lender_ac);
1027 fifo_credit = &fws->fifo_credit[lender_ac];
1028 if (*borrowed >= credits) {
1029 *borrowed -= credits;
1030 *fifo_credit += credits;
1031 return;
1032 } else {
1033 credits -= *borrowed;
1034 *fifo_credit += *borrowed;
1035 *borrowed = 0;
1036 }
1037 }
1038 }
1039 }
1040
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001041 fws->fifo_credit[fifo] += credits;
1042}
1043
1044static void brcmf_fws_schedule_deq(struct brcmf_fws_info *fws)
1045{
1046 /* only schedule dequeue when there are credits for delayed traffic */
1047 if (fws->fifo_credit_map & fws->fifo_delay_map)
1048 queue_work(fws->fws_wq, &fws->fws_dequeue_work);
1049}
1050
Arend van Sprielfe353b22013-06-06 13:17:49 +02001051static void brcmf_fws_skb_pickup_credit(struct brcmf_fws_info *fws, int fifo,
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001052 struct sk_buff *p)
1053{
1054 struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(p)->mac;
1055
Arend van Sprielfe353b22013-06-06 13:17:49 +02001056 if (brcmf_skbcb(p)->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK)
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001057 brcmf_fws_return_credits(fws, fifo, 1);
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001058 else if (brcmf_skb_if_flags_get_field(p, REQ_CREDIT) &&
1059 entry->state == BRCMF_FWS_STATE_CLOSE)
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001060 /*
1061 * if this packet did not count against FIFO credit, it
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001062 * could have taken a requested_credit from the destination
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001063 * entry (for pspoll etc.)
1064 */
Arend van Sprielfe353b22013-06-06 13:17:49 +02001065 entry->requested_credit++;
1066
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001067 brcmf_fws_schedule_deq(fws);
1068}
1069
1070static int brcmf_fws_enq(struct brcmf_fws_info *fws,
1071 enum brcmf_fws_skb_state state, int fifo,
1072 struct sk_buff *p)
1073{
1074 int prec = 2 * fifo;
1075 u32 *qfull_stat = &fws->stats.delayq_full_error;
1076
1077 struct brcmf_fws_mac_descriptor *entry;
1078
1079 entry = brcmf_skbcb(p)->mac;
1080 if (entry == NULL) {
1081 brcmf_err("no mac descriptor found for skb %p\n", p);
1082 return -ENOENT;
1083 }
1084
Arend van Spriel8071fd62013-06-06 13:17:51 +02001085 brcmf_dbg(DATA, "enter: fifo %d skb %p\n", fifo, p);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001086 if (state == BRCMF_FWS_SKBSTATE_SUPPRESSED) {
1087 prec += 1;
1088 qfull_stat = &fws->stats.supprq_full_error;
1089 }
1090
1091 if (brcmu_pktq_penq(&entry->psq, prec, p) == NULL) {
1092 *qfull_stat += 1;
1093 return -ENFILE;
1094 }
1095
1096 /* increment total enqueued packet count */
1097 fws->fifo_delay_map |= 1 << fifo;
1098 fws->fifo_enqpkt[fifo]++;
1099
1100 /* update the sk_buff state */
1101 brcmf_skbcb(p)->state = state;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001102
1103 /*
1104 * A packet has been pushed so update traffic
1105 * availability bitmap, if applicable
1106 */
1107 brcmf_fws_tim_update(fws, entry, fifo);
1108 brcmf_fws_flow_control_check(fws, &entry->psq,
1109 brcmf_skb_if_flags_get_field(p, INDEX));
1110 return 0;
1111}
1112
1113static struct sk_buff *brcmf_fws_deq(struct brcmf_fws_info *fws, int fifo)
1114{
1115 struct brcmf_fws_mac_descriptor *table;
1116 struct brcmf_fws_mac_descriptor *entry;
1117 struct sk_buff *p;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001118 int num_nodes;
1119 int node_pos;
1120 int prec_out;
Arend van Spriel07529d22013-04-17 21:25:49 +02001121 int pmsk;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001122 int i;
1123
1124 table = (struct brcmf_fws_mac_descriptor *)&fws->desc;
1125 num_nodes = sizeof(fws->desc) / sizeof(struct brcmf_fws_mac_descriptor);
1126 node_pos = fws->deq_node_pos[fifo];
1127
1128 for (i = 0; i < num_nodes; i++) {
1129 entry = &table[(node_pos + i) % num_nodes];
Arend van Sprielb75c1a32013-04-17 21:25:53 +02001130 if (!entry->occupied ||
1131 brcmf_fws_mac_desc_closed(fws, entry, fifo))
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001132 continue;
1133
1134 if (entry->suppressed)
1135 pmsk = 2;
Arend van Spriel07529d22013-04-17 21:25:49 +02001136 else
1137 pmsk = 3;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001138 p = brcmu_pktq_mdeq(&entry->psq, pmsk << (fifo * 2), &prec_out);
1139 if (p == NULL) {
1140 if (entry->suppressed) {
Hante Meuleman8c5140f2013-06-06 13:18:01 +02001141 if (entry->suppr_transit_count)
1142 continue;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001143 entry->suppressed = false;
1144 p = brcmu_pktq_mdeq(&entry->psq,
1145 1 << (fifo * 2), &prec_out);
1146 }
1147 }
1148 if (p == NULL)
1149 continue;
1150
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001151 brcmf_fws_macdesc_use_credit(entry, p);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001152
1153 /* move dequeue position to ensure fair round-robin */
1154 fws->deq_node_pos[fifo] = (node_pos + i + 1) % num_nodes;
1155 brcmf_fws_flow_control_check(fws, &entry->psq,
1156 brcmf_skb_if_flags_get_field(p,
1157 INDEX)
1158 );
1159 /*
1160 * A packet has been picked up, update traffic
1161 * availability bitmap, if applicable
1162 */
1163 brcmf_fws_tim_update(fws, entry, fifo);
1164
1165 /*
1166 * decrement total enqueued fifo packets and
1167 * clear delay bitmap if done.
1168 */
1169 fws->fifo_enqpkt[fifo]--;
1170 if (fws->fifo_enqpkt[fifo] == 0)
1171 fws->fifo_delay_map &= ~(1 << fifo);
1172 goto done;
1173 }
1174 p = NULL;
1175done:
Arend van Spriel8071fd62013-06-06 13:17:51 +02001176 brcmf_dbg(DATA, "exit: fifo %d skb %p\n", fifo, p);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001177 return p;
1178}
1179
1180static int brcmf_fws_txstatus_suppressed(struct brcmf_fws_info *fws, int fifo,
1181 struct sk_buff *skb, u32 genbit)
1182{
1183 struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(skb)->mac;
1184 u32 hslot;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001185 int ret;
Hante Meuleman2747e5f2013-06-06 13:17:59 +02001186 u8 ifidx;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001187
1188 hslot = brcmf_skb_htod_tag_get_field(skb, HSLOT);
1189
1190 /* this packet was suppressed */
Hante Meulemanbe4910a2013-06-06 13:17:53 +02001191 if (!entry->suppressed) {
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001192 entry->suppressed = true;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001193 entry->suppr_transit_count = entry->transit_count;
Hante Meuleman8c5140f2013-06-06 13:18:01 +02001194 brcmf_dbg(DATA, "suppress %s: transit %d\n",
1195 entry->name, entry->transit_count);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001196 }
1197
1198 entry->generation = genbit;
1199
Hante Meuleman2747e5f2013-06-06 13:17:59 +02001200 ret = brcmf_proto_hdrpull(fws->drvr, false, &ifidx, skb);
1201 if (ret == 0)
1202 ret = brcmf_fws_enq(fws, BRCMF_FWS_SKBSTATE_SUPPRESSED, fifo,
1203 skb);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001204 if (ret != 0) {
Hante Meuleman2747e5f2013-06-06 13:17:59 +02001205 /* suppress q is full or hdrpull failed, drop this packet */
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001206 brcmf_fws_hanger_poppkt(&fws->hanger, hslot, &skb,
1207 true);
1208 } else {
1209 /*
1210 * Mark suppressed to avoid a double free during
1211 * wlfc cleanup
1212 */
Hante Meulemanbe4910a2013-06-06 13:17:53 +02001213 brcmf_fws_hanger_mark_suppressed(&fws->hanger, hslot);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001214 }
1215
1216 return ret;
1217}
1218
1219static int
Arend van Spriel8071fd62013-06-06 13:17:51 +02001220brcmf_fws_txs_process(struct brcmf_fws_info *fws, u8 flags, u32 hslot,
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001221 u32 genbit)
1222{
1223 u32 fifo;
1224 int ret;
1225 bool remove_from_hanger = true;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001226 struct sk_buff *skb;
Arend van Spriel8071fd62013-06-06 13:17:51 +02001227 struct brcmf_skbuff_cb *skcb;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001228 struct brcmf_fws_mac_descriptor *entry = NULL;
1229
Arend van Spriel8071fd62013-06-06 13:17:51 +02001230 brcmf_dbg(DATA, "flags %d\n", flags);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001231
1232 if (flags == BRCMF_FWS_TXSTATUS_DISCARD)
1233 fws->stats.txs_discard++;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001234 else if (flags == BRCMF_FWS_TXSTATUS_CORE_SUPPRESS) {
1235 fws->stats.txs_supp_core++;
1236 remove_from_hanger = false;
1237 } else if (flags == BRCMF_FWS_TXSTATUS_FW_PS_SUPPRESS) {
1238 fws->stats.txs_supp_ps++;
1239 remove_from_hanger = false;
1240 } else if (flags == BRCMF_FWS_TXSTATUS_FW_TOSSED)
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001241 fws->stats.txs_tossed++;
1242 else
1243 brcmf_err("unexpected txstatus\n");
1244
1245 ret = brcmf_fws_hanger_poppkt(&fws->hanger, hslot, &skb,
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001246 remove_from_hanger);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001247 if (ret != 0) {
1248 brcmf_err("no packet in hanger slot: hslot=%d\n", hslot);
1249 return ret;
1250 }
1251
Arend van Spriel8071fd62013-06-06 13:17:51 +02001252 skcb = brcmf_skbcb(skb);
1253 entry = skcb->mac;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001254 if (WARN_ON(!entry)) {
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001255 brcmu_pkt_buf_free_skb(skb);
1256 return -EINVAL;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001257 }
Hante Meuleman8c5140f2013-06-06 13:18:01 +02001258 entry->transit_count--;
1259 if (entry->suppressed && entry->suppr_transit_count)
1260 entry->suppr_transit_count--;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001261
Arend van Spriel8071fd62013-06-06 13:17:51 +02001262 brcmf_dbg(DATA, "%s flags %X htod %X\n", entry->name, skcb->if_flags,
1263 skcb->htod);
1264
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001265 /* pick up the implicit credit from this packet */
1266 fifo = brcmf_skb_htod_tag_get_field(skb, FIFO);
Arend van Sprielfe353b22013-06-06 13:17:49 +02001267 if (fws->fcmode == BRCMF_FWS_FCMODE_IMPLIED_CREDIT ||
1268 !(brcmf_skbcb(skb)->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK))
1269 brcmf_fws_skb_pickup_credit(fws, fifo, skb);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001270
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001271 if (!remove_from_hanger)
1272 ret = brcmf_fws_txstatus_suppressed(fws, fifo, skb, genbit);
1273
Hante Meuleman8c5140f2013-06-06 13:18:01 +02001274 if (remove_from_hanger || ret)
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001275 brcmf_txfinalize(fws->drvr, skb, true);
Hante Meuleman8c5140f2013-06-06 13:18:01 +02001276
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001277 return 0;
1278}
1279
1280static int brcmf_fws_fifocreditback_indicate(struct brcmf_fws_info *fws,
1281 u8 *data)
1282{
1283 int i;
1284
1285 if (fws->fcmode != BRCMF_FWS_FCMODE_EXPLICIT_CREDIT) {
1286 brcmf_dbg(INFO, "ignored\n");
Arend van Spriela5e9d802013-04-17 21:25:54 +02001287 return BRCMF_FWS_RET_OK_NOSCHEDULE;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001288 }
1289
Arend van Spriel8071fd62013-06-06 13:17:51 +02001290 brcmf_dbg(DATA, "enter: data %pM\n", data);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001291 for (i = 0; i < BRCMF_FWS_FIFO_COUNT; i++)
1292 brcmf_fws_return_credits(fws, i, data[i]);
1293
Arend van Spriel8071fd62013-06-06 13:17:51 +02001294 brcmf_dbg(DATA, "map: credit %x delay %x\n", fws->fifo_credit_map,
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001295 fws->fifo_delay_map);
Arend van Spriela5e9d802013-04-17 21:25:54 +02001296 return BRCMF_FWS_RET_OK_SCHEDULE;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001297}
1298
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02001299static int brcmf_fws_txstatus_indicate(struct brcmf_fws_info *fws, u8 *data)
1300{
Arend van Spriela2ffc562013-04-05 10:57:39 +02001301 __le32 status_le;
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02001302 u32 status;
1303 u32 hslot;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001304 u32 genbit;
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02001305 u8 flags;
1306
1307 fws->stats.txs_indicate++;
Arend van Spriela2ffc562013-04-05 10:57:39 +02001308 memcpy(&status_le, data, sizeof(status_le));
1309 status = le32_to_cpu(status_le);
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02001310 flags = brcmf_txstatus_get_field(status, FLAGS);
1311 hslot = brcmf_txstatus_get_field(status, HSLOT);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001312 genbit = brcmf_txstatus_get_field(status, GENERATION);
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02001313
Arend van Spriel8071fd62013-06-06 13:17:51 +02001314 return brcmf_fws_txs_process(fws, flags, hslot, genbit);
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02001315}
1316
Arend van Spriel349e7102013-03-03 12:45:28 +01001317static int brcmf_fws_dbg_seqnum_check(struct brcmf_fws_info *fws, u8 *data)
1318{
1319 __le32 timestamp;
1320
1321 memcpy(&timestamp, &data[2], sizeof(timestamp));
Arend van Spriel8071fd62013-06-06 13:17:51 +02001322 brcmf_dbg(CTL, "received: seq %d, timestamp %d\n", data[1],
Arend van Spriel349e7102013-03-03 12:45:28 +01001323 le32_to_cpu(timestamp));
1324 return 0;
1325}
1326
1327/* using macro so sparse checking does not complain
1328 * about locking imbalance.
1329 */
1330#define brcmf_fws_lock(drvr, flags) \
1331do { \
1332 flags = 0; \
1333 spin_lock_irqsave(&((drvr)->fws_spinlock), (flags)); \
1334} while (0)
1335
1336/* using macro so sparse checking does not complain
1337 * about locking imbalance.
1338 */
1339#define brcmf_fws_unlock(drvr, flags) \
1340 spin_unlock_irqrestore(&((drvr)->fws_spinlock), (flags))
1341
Arend van Spriel43fa6352013-04-03 12:40:32 +02001342static int brcmf_fws_notify_credit_map(struct brcmf_if *ifp,
1343 const struct brcmf_event_msg *e,
1344 void *data)
1345{
1346 struct brcmf_fws_info *fws = ifp->drvr->fws;
1347 int i;
1348 ulong flags;
1349 u8 *credits = data;
1350
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001351 if (e->datalen < BRCMF_FWS_FIFO_COUNT) {
1352 brcmf_err("event payload too small (%d)\n", e->datalen);
1353 return -EINVAL;
1354 }
Hante Meuleman0d24b0e2013-06-06 13:17:58 +02001355 if (fws->creditmap_received)
1356 return 0;
1357
1358 fws->creditmap_received = true;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001359
1360 brcmf_dbg(TRACE, "enter: credits %pM\n", credits);
Arend van Spriel43fa6352013-04-03 12:40:32 +02001361 brcmf_fws_lock(ifp->drvr, flags);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001362 for (i = 0; i < ARRAY_SIZE(fws->fifo_credit); i++) {
1363 if (*credits)
1364 fws->fifo_credit_map |= 1 << i;
1365 else
1366 fws->fifo_credit_map &= ~(1 << i);
Arend van Spriel43fa6352013-04-03 12:40:32 +02001367 fws->fifo_credit[i] = *credits++;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001368 }
1369 brcmf_fws_schedule_deq(fws);
Arend van Spriel43fa6352013-04-03 12:40:32 +02001370 brcmf_fws_unlock(ifp->drvr, flags);
1371 return 0;
1372}
1373
Arend van Spriel349e7102013-03-03 12:45:28 +01001374int brcmf_fws_hdrpull(struct brcmf_pub *drvr, int ifidx, s16 signal_len,
1375 struct sk_buff *skb)
1376{
1377 struct brcmf_fws_info *fws = drvr->fws;
1378 ulong flags;
1379 u8 *signal_data;
1380 s16 data_len;
1381 u8 type;
1382 u8 len;
1383 u8 *data;
Arend van Spriela5e9d802013-04-17 21:25:54 +02001384 s32 status;
1385 s32 err;
Arend van Spriel349e7102013-03-03 12:45:28 +01001386
Arend van Spriel8071fd62013-06-06 13:17:51 +02001387 brcmf_dbg(HDRS, "enter: ifidx %d, skblen %u, sig %d\n",
Arend van Spriel349e7102013-03-03 12:45:28 +01001388 ifidx, skb->len, signal_len);
1389
1390 WARN_ON(signal_len > skb->len);
1391
1392 /* if flow control disabled, skip to packet data and leave */
1393 if (!signal_len || !drvr->fw_signals) {
1394 skb_pull(skb, signal_len);
1395 return 0;
1396 }
1397
1398 /* lock during tlv parsing */
1399 brcmf_fws_lock(drvr, flags);
1400
1401 fws->stats.header_pulls++;
1402 data_len = signal_len;
1403 signal_data = skb->data;
1404
Arend van Spriela5e9d802013-04-17 21:25:54 +02001405 status = BRCMF_FWS_RET_OK_NOSCHEDULE;
Arend van Spriel349e7102013-03-03 12:45:28 +01001406 while (data_len > 0) {
1407 /* extract tlv info */
1408 type = signal_data[0];
1409
1410 /* FILLER type is actually not a TLV, but
1411 * a single byte that can be skipped.
1412 */
1413 if (type == BRCMF_FWS_TYPE_FILLER) {
1414 signal_data += 1;
1415 data_len -= 1;
1416 continue;
1417 }
1418 len = signal_data[1];
1419 data = signal_data + 2;
1420
Arend van Spriel8071fd62013-06-06 13:17:51 +02001421 brcmf_dbg(HDRS, "tlv type=%s (%d), len=%d (%d)\n",
1422 brcmf_fws_get_tlv_name(type), type, len,
1423 brcmf_fws_get_tlv_len(fws, type));
Arend van Spriel2af15582013-04-03 12:40:42 +02001424
Arend van Spriel349e7102013-03-03 12:45:28 +01001425 /* abort parsing when length invalid */
1426 if (data_len < len + 2)
1427 break;
1428
Arend van Sprielf55d94a2013-06-06 13:17:46 +02001429 if (len < brcmf_fws_get_tlv_len(fws, type))
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001430 break;
1431
Arend van Spriela5e9d802013-04-17 21:25:54 +02001432 err = BRCMF_FWS_RET_OK_NOSCHEDULE;
Arend van Spriel349e7102013-03-03 12:45:28 +01001433 switch (type) {
Arend van Spriel349e7102013-03-03 12:45:28 +01001434 case BRCMF_FWS_TYPE_HOST_REORDER_RXPKTS:
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001435 case BRCMF_FWS_TYPE_COMP_TXSTATUS:
Arend van Sprielce814c12013-04-03 12:40:31 +02001436 break;
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001437 case BRCMF_FWS_TYPE_MACDESC_ADD:
1438 case BRCMF_FWS_TYPE_MACDESC_DEL:
Arend van Sprielce814c12013-04-03 12:40:31 +02001439 brcmf_fws_macdesc_indicate(fws, type, data);
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001440 break;
Arend van Spriel33753d42013-04-05 10:57:40 +02001441 case BRCMF_FWS_TYPE_MAC_OPEN:
1442 case BRCMF_FWS_TYPE_MAC_CLOSE:
Arend van Spriela5e9d802013-04-17 21:25:54 +02001443 err = brcmf_fws_macdesc_state_indicate(fws, type, data);
Arend van Spriel33753d42013-04-05 10:57:40 +02001444 break;
1445 case BRCMF_FWS_TYPE_INTERFACE_OPEN:
1446 case BRCMF_FWS_TYPE_INTERFACE_CLOSE:
Arend van Spriela5e9d802013-04-17 21:25:54 +02001447 err = brcmf_fws_interface_state_indicate(fws, type,
1448 data);
Arend van Spriel33753d42013-04-05 10:57:40 +02001449 break;
Arend van Spriel5f38b682013-04-05 10:57:41 +02001450 case BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT:
1451 case BRCMF_FWS_TYPE_MAC_REQUEST_PACKET:
Arend van Spriela5e9d802013-04-17 21:25:54 +02001452 err = brcmf_fws_request_indicate(fws, type, data);
Arend van Spriel5f38b682013-04-05 10:57:41 +02001453 break;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001454 case BRCMF_FWS_TYPE_TXSTATUS:
1455 brcmf_fws_txstatus_indicate(fws, data);
1456 break;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001457 case BRCMF_FWS_TYPE_FIFO_CREDITBACK:
Arend van Spriela5e9d802013-04-17 21:25:54 +02001458 err = brcmf_fws_fifocreditback_indicate(fws, data);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001459 break;
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001460 case BRCMF_FWS_TYPE_RSSI:
1461 brcmf_fws_rssi_indicate(fws, *data);
Arend van Spriel349e7102013-03-03 12:45:28 +01001462 break;
1463 case BRCMF_FWS_TYPE_TRANS_ID:
Arend van Spriel349e7102013-03-03 12:45:28 +01001464 brcmf_fws_dbg_seqnum_check(fws, data);
1465 break;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001466 case BRCMF_FWS_TYPE_PKTTAG:
1467 case BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP:
Arend van Spriel349e7102013-03-03 12:45:28 +01001468 default:
1469 fws->stats.tlv_invalid_type++;
1470 break;
1471 }
Arend van Spriela5e9d802013-04-17 21:25:54 +02001472 if (err == BRCMF_FWS_RET_OK_SCHEDULE)
1473 status = BRCMF_FWS_RET_OK_SCHEDULE;
Arend van Spriel349e7102013-03-03 12:45:28 +01001474 signal_data += len + 2;
1475 data_len -= len + 2;
1476 }
1477
1478 if (data_len != 0)
1479 fws->stats.tlv_parse_failed++;
1480
Arend van Spriela5e9d802013-04-17 21:25:54 +02001481 if (status == BRCMF_FWS_RET_OK_SCHEDULE)
1482 brcmf_fws_schedule_deq(fws);
1483
Arend van Spriel349e7102013-03-03 12:45:28 +01001484 /* signalling processing result does
1485 * not affect the actual ethernet packet.
1486 */
1487 skb_pull(skb, signal_len);
1488
1489 /* this may be a signal-only packet
1490 */
1491 if (skb->len == 0)
1492 fws->stats.header_only_pkt++;
1493
1494 brcmf_fws_unlock(drvr, flags);
1495 return 0;
1496}
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001497
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001498static int brcmf_fws_hdrpush(struct brcmf_fws_info *fws, struct sk_buff *skb)
1499{
1500 struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(skb)->mac;
1501 u8 *wlh;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001502 u16 data_offset = 0;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001503 u8 fillers;
1504 __le32 pkttag = cpu_to_le32(brcmf_skbcb(skb)->htod);
1505
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001506 if (entry->send_tim_signal)
1507 data_offset += 2 + BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN;
1508
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001509 /* +2 is for Type[1] and Len[1] in TLV, plus TIM signal */
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001510 data_offset += 2 + BRCMF_FWS_TYPE_PKTTAG_LEN;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001511 fillers = round_up(data_offset, 4) - data_offset;
1512 data_offset += fillers;
1513
1514 skb_push(skb, data_offset);
1515 wlh = skb->data;
1516
1517 wlh[0] = BRCMF_FWS_TYPE_PKTTAG;
1518 wlh[1] = BRCMF_FWS_TYPE_PKTTAG_LEN;
1519 memcpy(&wlh[2], &pkttag, sizeof(pkttag));
1520 wlh += BRCMF_FWS_TYPE_PKTTAG_LEN + 2;
1521
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001522 if (entry->send_tim_signal) {
1523 entry->send_tim_signal = 0;
1524 wlh[0] = BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP;
1525 wlh[1] = BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN;
1526 wlh[2] = entry->mac_handle;
1527 wlh[3] = entry->traffic_pending_bmp;
1528 wlh += BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN + 2;
1529 entry->traffic_lastreported_bmp = entry->traffic_pending_bmp;
1530 }
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001531 if (fillers)
1532 memset(wlh, BRCMF_FWS_TYPE_FILLER, fillers);
1533
1534 brcmf_proto_hdrpush(fws->drvr, brcmf_skb_if_flags_get_field(skb, INDEX),
1535 data_offset >> 2, skb);
1536 return 0;
1537}
1538
1539static int brcmf_fws_precommit_skb(struct brcmf_fws_info *fws, int fifo,
1540 struct sk_buff *p)
1541{
1542 struct brcmf_skbuff_cb *skcb = brcmf_skbcb(p);
1543 struct brcmf_fws_mac_descriptor *entry = skcb->mac;
1544 int rc = 0;
Hante Meulemanbe4910a2013-06-06 13:17:53 +02001545 bool first_time;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001546 int hslot = BRCMF_FWS_HANGER_MAXITEMS;
1547 u8 free_ctr;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001548 u8 flags;
1549
Hante Meulemanbe4910a2013-06-06 13:17:53 +02001550 first_time = skcb->state != BRCMF_FWS_SKBSTATE_SUPPRESSED;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001551
Hante Meulemanbe4910a2013-06-06 13:17:53 +02001552 brcmf_skb_if_flags_set_field(p, TRANSMIT, 1);
1553 brcmf_skb_htod_tag_set_field(p, FIFO, fifo);
1554 brcmf_skb_htod_tag_set_field(p, GENERATION, entry->generation);
1555 flags = BRCMF_FWS_HTOD_FLAG_PKTFROMHOST;
1556 if (!(skcb->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK)) {
1557 /*
1558 * Indicate that this packet is being sent in response to an
1559 * explicit request from the firmware side.
1560 */
1561 flags |= BRCMF_FWS_HTOD_FLAG_PKT_REQUESTED;
1562 }
1563 brcmf_skb_htod_tag_set_field(p, FLAGS, flags);
1564 if (first_time) {
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001565 /* obtaining free slot may fail, but that will be caught
1566 * by the hanger push. This assures the packet has a BDC
1567 * header upon return.
1568 */
1569 hslot = brcmf_fws_hanger_get_free_slot(&fws->hanger);
1570 free_ctr = entry->seq[fifo];
1571 brcmf_skb_htod_tag_set_field(p, HSLOT, hslot);
1572 brcmf_skb_htod_tag_set_field(p, FREERUN, free_ctr);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001573 rc = brcmf_fws_hanger_pushpkt(&fws->hanger, p, hslot);
1574 if (rc)
1575 brcmf_err("hanger push failed: rc=%d\n", rc);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001576 }
1577
Hante Meuleman2747e5f2013-06-06 13:17:59 +02001578 if (rc == 0)
1579 brcmf_fws_hdrpush(fws, p);
1580
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001581 return rc;
1582}
1583
Arend van Spriel88f656f2013-04-17 21:25:57 +02001584static void
Arend van Spriel51f6dd92013-06-06 13:17:47 +02001585brcmf_fws_rollback_toq(struct brcmf_fws_info *fws,
1586 struct sk_buff *skb, int fifo)
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001587{
1588 /*
1589 put the packet back to the head of queue
1590
1591 - suppressed packet goes back to suppress sub-queue
1592 - pull out the header, if new or delayed packet
1593
1594 Note: hslot is used only when header removal is done.
1595 */
1596 struct brcmf_fws_mac_descriptor *entry;
1597 enum brcmf_fws_skb_state state;
1598 struct sk_buff *pktout;
1599 int rc = 0;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001600 int hslot;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001601
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001602 state = brcmf_skbcb(skb)->state;
1603 entry = brcmf_skbcb(skb)->mac;
1604
1605 if (entry != NULL) {
1606 if (state == BRCMF_FWS_SKBSTATE_SUPPRESSED) {
1607 /* wl-header is saved for suppressed packets */
1608 pktout = brcmu_pktq_penq_head(&entry->psq, 2 * fifo + 1,
1609 skb);
1610 if (pktout == NULL) {
1611 brcmf_err("suppress queue full\n");
1612 rc = -ENOSPC;
1613 }
1614 } else {
1615 hslot = brcmf_skb_htod_tag_get_field(skb, HSLOT);
1616
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001617 /* delay-q packets are going to delay-q */
1618 pktout = brcmu_pktq_penq_head(&entry->psq,
1619 2 * fifo, skb);
1620 if (pktout == NULL) {
1621 brcmf_err("delay queue full\n");
1622 rc = -ENOSPC;
1623 }
1624
1625 /* free the hanger slot */
1626 brcmf_fws_hanger_poppkt(&fws->hanger, hslot, &pktout,
1627 true);
1628
1629 /* decrement sequence count */
1630 entry->seq[fifo]--;
1631 }
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001632 } else {
1633 brcmf_err("no mac entry linked\n");
1634 rc = -ENOENT;
1635 }
1636
Arend van Spriel67994fa2013-04-17 21:25:56 +02001637 if (rc) {
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001638 brcmf_fws_bustxfail(fws, skb);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001639 fws->stats.rollback_failed++;
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001640 } else {
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001641 fws->stats.rollback_success++;
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001642 brcmf_fws_skb_pickup_credit(fws, fifo, skb);
1643 }
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001644}
1645
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001646static int brcmf_fws_borrow_credit(struct brcmf_fws_info *fws)
1647{
1648 int lender_ac;
1649
Hante Meulemanafc3bbf2013-06-06 13:17:54 +02001650 if (time_after(fws->borrow_defer_timestamp, jiffies)) {
1651 fws->fifo_credit_map &= ~(1 << BRCMF_FWS_FIFO_AC_BE);
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001652 return -ENAVAIL;
Hante Meulemanafc3bbf2013-06-06 13:17:54 +02001653 }
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001654
1655 for (lender_ac = 0; lender_ac <= BRCMF_FWS_FIFO_AC_VO; lender_ac++) {
1656 if (fws->fifo_credit[lender_ac]) {
1657 fws->credits_borrowed[lender_ac]++;
1658 fws->fifo_credit[lender_ac]--;
1659 if (fws->fifo_credit[lender_ac] == 0)
1660 fws->fifo_credit_map &= ~(1 << lender_ac);
Hante Meulemanafc3bbf2013-06-06 13:17:54 +02001661 fws->fifo_credit_map |= (1 << BRCMF_FWS_FIFO_AC_BE);
Arend van Spriel8071fd62013-06-06 13:17:51 +02001662 brcmf_dbg(DATA, "borrow credit from: %d\n", lender_ac);
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001663 return 0;
1664 }
1665 }
Hante Meulemanafc3bbf2013-06-06 13:17:54 +02001666 fws->fifo_credit_map &= ~(1 << BRCMF_FWS_FIFO_AC_BE);
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001667 return -ENAVAIL;
1668}
1669
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001670static int brcmf_fws_consume_credit(struct brcmf_fws_info *fws, int fifo,
1671 struct sk_buff *skb)
1672{
1673 struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(skb)->mac;
1674 int *credit = &fws->fifo_credit[fifo];
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001675
Arend van Spriel8071fd62013-06-06 13:17:51 +02001676 if (!brcmf_fws_macdesc_use_credit(entry, skb))
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001677 return 0;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001678
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001679 if (fifo != BRCMF_FWS_FIFO_AC_BE)
1680 fws->borrow_defer_timestamp = jiffies +
1681 BRCMF_FWS_BORROW_DEFER_PERIOD;
1682
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001683 if (!(*credit)) {
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001684 /* Try to borrow a credit from other queue */
1685 if (fifo == BRCMF_FWS_FIFO_AC_BE &&
1686 brcmf_fws_borrow_credit(fws) == 0)
1687 return 0;
1688
Arend van Spriel8071fd62013-06-06 13:17:51 +02001689 brcmf_dbg(DATA, "exit: ac=%d, credits depleted\n", fifo);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001690 return -ENAVAIL;
1691 }
1692 (*credit)--;
1693 if (!(*credit))
1694 fws->fifo_credit_map &= ~(1 << fifo);
Arend van Spriel8071fd62013-06-06 13:17:51 +02001695 brcmf_dbg(DATA, "exit: ac=%d, credits=%d\n", fifo, *credit);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001696 return 0;
1697}
1698
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001699static int brcmf_fws_commit_skb(struct brcmf_fws_info *fws, int fifo,
1700 struct sk_buff *skb)
1701{
1702 struct brcmf_skbuff_cb *skcb = brcmf_skbcb(skb);
1703 struct brcmf_fws_mac_descriptor *entry;
1704 struct brcmf_bus *bus = fws->drvr->bus_if;
1705 int rc;
Hante Meuleman2747e5f2013-06-06 13:17:59 +02001706 u8 ifidx;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001707
1708 entry = skcb->mac;
1709 if (IS_ERR(entry))
1710 return PTR_ERR(entry);
1711
1712 rc = brcmf_fws_precommit_skb(fws, fifo, skb);
1713 if (rc < 0) {
1714 fws->stats.generic_error++;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001715 goto rollback;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001716 }
1717
Arend van Spriel8071fd62013-06-06 13:17:51 +02001718 brcmf_dbg(DATA, "%s flags %X htod %X\n", entry->name, skcb->if_flags,
1719 skcb->htod);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001720 rc = brcmf_bus_txdata(bus, skb);
Hante Meuleman2747e5f2013-06-06 13:17:59 +02001721 if (rc < 0) {
1722 brcmf_proto_hdrpull(fws->drvr, false, &ifidx, skb);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001723 goto rollback;
Hante Meuleman2747e5f2013-06-06 13:17:59 +02001724 }
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001725
Hante Meuleman8c5140f2013-06-06 13:18:01 +02001726 entry->transit_count++;
1727 if (entry->suppressed)
1728 entry->suppr_transit_count++;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001729 entry->seq[fifo]++;
1730 fws->stats.pkt2bus++;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001731 if (brcmf_skbcb(skb)->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK) {
1732 fws->stats.send_pkts[fifo]++;
1733 fws->stats.fifo_credits_sent[fifo]++;
1734 }
1735
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001736 return rc;
1737
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001738rollback:
Arend van Spriel51f6dd92013-06-06 13:17:47 +02001739 brcmf_fws_rollback_toq(fws, skb, fifo);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001740 return rc;
1741}
1742
1743int brcmf_fws_process_skb(struct brcmf_if *ifp, struct sk_buff *skb)
1744{
1745 struct brcmf_pub *drvr = ifp->drvr;
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001746 struct brcmf_fws_info *fws = drvr->fws;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001747 struct brcmf_skbuff_cb *skcb = brcmf_skbcb(skb);
1748 struct ethhdr *eh = (struct ethhdr *)(skb->data);
1749 ulong flags;
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001750 int fifo = BRCMF_FWS_FIFO_BCMC;
1751 bool multicast = is_multicast_ether_addr(eh->h_dest);
1752
1753 /* determine the priority */
1754 if (!skb->priority)
1755 skb->priority = cfg80211_classify8021d(skb);
1756
1757 drvr->tx_multicast += !!multicast;
1758 if (ntohs(eh->h_proto) == ETH_P_PAE)
1759 atomic_inc(&ifp->pend_8021x_cnt);
1760
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001761 if (!brcmf_fws_fc_active(fws)) {
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001762 /* If the protocol uses a data header, apply it */
Arend van Spriel31ed07d2013-04-11 13:29:00 +02001763 brcmf_proto_hdrpush(drvr, ifp->ifidx, 0, skb);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001764
1765 /* Use bus module to send data frame */
1766 return brcmf_bus_txdata(drvr->bus_if, skb);
1767 }
1768
1769 /* set control buffer information */
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001770 skcb->if_flags = 0;
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001771 skcb->mac = brcmf_fws_find_mac_desc(fws, ifp, eh->h_dest);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001772 skcb->state = BRCMF_FWS_SKBSTATE_NEW;
Arend van Spriel31ed07d2013-04-11 13:29:00 +02001773 brcmf_skb_if_flags_set_field(skb, INDEX, ifp->ifidx);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001774 if (!multicast)
1775 fifo = brcmf_fws_prio2fifo[skb->priority];
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001776
Arend van Spriel8071fd62013-06-06 13:17:51 +02001777 brcmf_dbg(DATA, "%s mac %pM multi %d fifo %d\n", skcb->mac->name,
1778 eh->h_dest, multicast, fifo);
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001779
1780 brcmf_fws_lock(drvr, flags);
Arend van Spriel9fc60222013-04-11 17:12:04 +02001781 if (skcb->mac->suppressed ||
Hante Meulemandf50f752013-06-06 13:17:48 +02001782 fws->bus_flow_blocked ||
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001783 brcmf_fws_mac_desc_closed(fws, skcb->mac, fifo) ||
Arend van Spriel9fc60222013-04-11 17:12:04 +02001784 brcmu_pktq_mlen(&skcb->mac->psq, 3 << (fifo * 2)) ||
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001785 (!multicast &&
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001786 brcmf_fws_consume_credit(fws, fifo, skb) < 0)) {
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001787 /* enqueue the packet in delayQ */
1788 drvr->fws->fifo_delay_map |= 1 << fifo;
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001789 brcmf_fws_enq(fws, BRCMF_FWS_SKBSTATE_DELAYED, fifo, skb);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001790 } else {
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001791 brcmf_fws_commit_skb(fws, fifo, skb);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001792 }
Arend van Spriel3edc1cf2013-04-03 12:40:40 +02001793 brcmf_fws_unlock(drvr, flags);
1794 return 0;
1795}
1796
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001797void brcmf_fws_reset_interface(struct brcmf_if *ifp)
1798{
1799 struct brcmf_fws_mac_descriptor *entry = ifp->fws_desc;
1800
1801 brcmf_dbg(TRACE, "enter: idx=%d\n", ifp->bssidx);
1802 if (!entry)
1803 return;
1804
Arend van Sprielce814c12013-04-03 12:40:31 +02001805 brcmf_fws_init_mac_descriptor(entry, ifp->mac_addr, ifp->ifidx);
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001806}
1807
1808void brcmf_fws_add_interface(struct brcmf_if *ifp)
1809{
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001810 struct brcmf_fws_info *fws = ifp->drvr->fws;
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001811 struct brcmf_fws_mac_descriptor *entry;
1812
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02001813 if (!ifp->ndev || !ifp->drvr->fw_signals)
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001814 return;
1815
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001816 entry = &fws->desc.iface[ifp->ifidx];
1817 ifp->fws_desc = entry;
1818 brcmf_fws_init_mac_descriptor(entry, ifp->mac_addr, ifp->ifidx);
Arend van Spriel8071fd62013-06-06 13:17:51 +02001819 brcmf_fws_macdesc_set_name(fws, entry);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001820 brcmu_pktq_init(&entry->psq, BRCMF_FWS_PSQ_PREC_COUNT,
1821 BRCMF_FWS_PSQ_LEN);
Arend van Spriel8071fd62013-06-06 13:17:51 +02001822 brcmf_dbg(TRACE, "added %s\n", entry->name);
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001823}
1824
1825void brcmf_fws_del_interface(struct brcmf_if *ifp)
1826{
1827 struct brcmf_fws_mac_descriptor *entry = ifp->fws_desc;
Arend van Spriel6d421e52013-04-17 21:25:55 +02001828 ulong flags;
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001829
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001830 if (!entry)
1831 return;
1832
Arend van Spriel6d421e52013-04-17 21:25:55 +02001833 brcmf_fws_lock(ifp->drvr, flags);
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001834 ifp->fws_desc = NULL;
Arend van Spriel8071fd62013-06-06 13:17:51 +02001835 brcmf_dbg(TRACE, "deleting %s\n", entry->name);
Arend van Sprielce814c12013-04-03 12:40:31 +02001836 brcmf_fws_clear_mac_descriptor(entry);
Arend van Spriela3e993c2013-04-03 12:40:36 +02001837 brcmf_fws_cleanup(ifp->drvr->fws, ifp->ifidx);
Arend van Spriel6d421e52013-04-17 21:25:55 +02001838 brcmf_fws_unlock(ifp->drvr, flags);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001839}
1840
1841static void brcmf_fws_dequeue_worker(struct work_struct *worker)
1842{
1843 struct brcmf_fws_info *fws;
1844 struct sk_buff *skb;
1845 ulong flags;
1846 int fifo;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001847
1848 fws = container_of(worker, struct brcmf_fws_info, fws_dequeue_work);
1849
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001850 brcmf_fws_lock(fws->drvr, flags);
Hante Meulemandf50f752013-06-06 13:17:48 +02001851 for (fifo = NL80211_NUM_ACS; fifo >= 0 && !fws->bus_flow_blocked;
1852 fifo--) {
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001853 while (fws->fifo_credit[fifo]) {
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001854 skb = brcmf_fws_deq(fws, fifo);
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001855 if (!skb)
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001856 break;
Arend van Spriel047445c2013-04-17 21:25:58 +02001857 if (brcmf_skbcb(skb)->if_flags &
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001858 BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK)
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001859 fws->fifo_credit[fifo]--;
1860
1861 if (brcmf_fws_commit_skb(fws, fifo, skb))
1862 break;
Hante Meulemandf50f752013-06-06 13:17:48 +02001863 if (fws->bus_flow_blocked)
1864 break;
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001865 }
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001866 if ((fifo == BRCMF_FWS_FIFO_AC_BE) &&
Arend van Spriel289ec1c2013-06-06 13:17:50 +02001867 (fws->fifo_credit[fifo] == 0) &&
Hante Meulemandf50f752013-06-06 13:17:48 +02001868 (!fws->bus_flow_blocked)) {
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001869 while (brcmf_fws_borrow_credit(fws) == 0) {
1870 skb = brcmf_fws_deq(fws, fifo);
1871 if (!skb) {
1872 brcmf_fws_return_credits(fws, fifo, 1);
1873 break;
1874 }
Hante Meulemaneb2410c2013-06-06 13:18:00 +02001875 if (brcmf_fws_commit_skb(fws, fifo, skb))
1876 break;
Hante Meulemandf50f752013-06-06 13:17:48 +02001877 if (fws->bus_flow_blocked)
1878 break;
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001879 }
Arend van Spriel1aac1e92013-04-23 12:53:15 +02001880 }
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001881 }
1882 brcmf_fws_unlock(fws->drvr, flags);
Arend van Sprielbb8c8062013-04-03 12:40:30 +02001883}
Arend van Sprielc7f34a62013-04-03 12:40:39 +02001884
Arend van Sprield9337412013-04-03 12:40:47 +02001885int brcmf_fws_init(struct brcmf_pub *drvr)
1886{
Arend van Spriel290fb762013-04-03 12:40:49 +02001887 u32 tlv = BRCMF_FWS_FLAGS_RSSI_SIGNALS;
Arend van Sprield9337412013-04-03 12:40:47 +02001888 int rc;
1889
Arend van Spriel47829f42013-04-03 12:40:48 +02001890 if (!drvr->fw_signals)
1891 return 0;
1892
Arend van Sprield9337412013-04-03 12:40:47 +02001893 spin_lock_init(&drvr->fws_spinlock);
1894
1895 drvr->fws = kzalloc(sizeof(*(drvr->fws)), GFP_KERNEL);
1896 if (!drvr->fws) {
1897 rc = -ENOMEM;
1898 goto fail;
1899 }
1900
1901 /* set linkage back */
1902 drvr->fws->drvr = drvr;
1903 drvr->fws->fcmode = fcmode;
1904
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001905 drvr->fws->fws_wq = create_singlethread_workqueue("brcmf_fws_wq");
1906 if (drvr->fws->fws_wq == NULL) {
1907 brcmf_err("workqueue creation failed\n");
1908 rc = -EBADF;
1909 goto fail;
1910 }
1911 INIT_WORK(&drvr->fws->fws_dequeue_work, brcmf_fws_dequeue_worker);
1912
Arend van Spriel290fb762013-04-03 12:40:49 +02001913 /* enable firmware signalling if fcmode active */
1914 if (drvr->fws->fcmode != BRCMF_FWS_FCMODE_NONE)
1915 tlv |= BRCMF_FWS_FLAGS_XONXOFF_SIGNALS |
Arend van Spriel33753d42013-04-05 10:57:40 +02001916 BRCMF_FWS_FLAGS_CREDIT_STATUS_SIGNALS |
1917 BRCMF_FWS_FLAGS_HOST_PROPTXSTATUS_ACTIVE;
Arend van Spriel290fb762013-04-03 12:40:49 +02001918
Arend van Spriela786b382013-04-23 12:53:14 +02001919 rc = brcmf_fweh_register(drvr, BRCMF_E_FIFO_CREDIT_MAP,
1920 brcmf_fws_notify_credit_map);
Arend van Sprield9337412013-04-03 12:40:47 +02001921 if (rc < 0) {
Arend van Spriela786b382013-04-23 12:53:14 +02001922 brcmf_err("register credit map handler failed\n");
Arend van Sprield9337412013-04-03 12:40:47 +02001923 goto fail;
1924 }
1925
Arend van Spriela786b382013-04-23 12:53:14 +02001926 /* setting the iovar may fail if feature is unsupported
1927 * so leave the rc as is so driver initialization can
1928 * continue.
1929 */
1930 if (brcmf_fil_iovar_int_set(drvr->iflist[0], "tlv", tlv)) {
1931 brcmf_err("failed to set bdcv2 tlv signaling\n");
1932 goto fail_event;
Arend van Sprield9337412013-04-03 12:40:47 +02001933 }
1934
1935 brcmf_fws_hanger_init(&drvr->fws->hanger);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001936 brcmf_fws_init_mac_descriptor(&drvr->fws->desc.other, NULL, 0);
Arend van Spriel8071fd62013-06-06 13:17:51 +02001937 brcmf_fws_macdesc_set_name(drvr->fws, &drvr->fws->desc.other);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001938 brcmu_pktq_init(&drvr->fws->desc.other.psq, BRCMF_FWS_PSQ_PREC_COUNT,
1939 BRCMF_FWS_PSQ_LEN);
Arend van Sprield9337412013-04-03 12:40:47 +02001940
1941 /* create debugfs file for statistics */
1942 brcmf_debugfs_create_fws_stats(drvr, &drvr->fws->stats);
1943
Arend van Spriel8071fd62013-06-06 13:17:51 +02001944 brcmf_dbg(INFO, "%s bdcv2 tlv signaling [%x]\n",
Arend van Sprield9337412013-04-03 12:40:47 +02001945 drvr->fw_signals ? "enabled" : "disabled", tlv);
1946 return 0;
1947
Arend van Spriela786b382013-04-23 12:53:14 +02001948fail_event:
1949 brcmf_fweh_unregister(drvr, BRCMF_E_FIFO_CREDIT_MAP);
Arend van Sprield9337412013-04-03 12:40:47 +02001950fail:
Arend van Sprield9337412013-04-03 12:40:47 +02001951 brcmf_fws_deinit(drvr);
1952 return rc;
1953}
1954
1955void brcmf_fws_deinit(struct brcmf_pub *drvr)
1956{
1957 struct brcmf_fws_info *fws = drvr->fws;
1958 ulong flags;
1959
Arend van Spriel47829f42013-04-03 12:40:48 +02001960 if (!fws)
1961 return;
1962
Arend van Spriela786b382013-04-23 12:53:14 +02001963 /* disable firmware signalling entirely
1964 * to avoid using the workqueue.
1965 */
1966 drvr->fw_signals = false;
1967
1968 if (drvr->fws->fws_wq)
1969 destroy_workqueue(drvr->fws->fws_wq);
1970
Arend van Sprield9337412013-04-03 12:40:47 +02001971 /* cleanup */
1972 brcmf_fws_lock(drvr, flags);
1973 brcmf_fws_cleanup(fws, -1);
1974 drvr->fws = NULL;
1975 brcmf_fws_unlock(drvr, flags);
1976
1977 /* free top structure */
1978 kfree(fws);
1979}
1980
Arend van Sprielc7f34a62013-04-03 12:40:39 +02001981bool brcmf_fws_fc_active(struct brcmf_fws_info *fws)
1982{
1983 if (!fws)
1984 return false;
1985
Arend van Sprielc7f34a62013-04-03 12:40:39 +02001986 return fws->fcmode != BRCMF_FWS_FCMODE_NONE;
1987}
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02001988
1989void brcmf_fws_bustxfail(struct brcmf_fws_info *fws, struct sk_buff *skb)
1990{
1991 ulong flags;
Arend van Sprielfe353b22013-06-06 13:17:49 +02001992 int fifo;
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02001993
1994 brcmf_fws_lock(fws->drvr, flags);
Arend van Spriel8071fd62013-06-06 13:17:51 +02001995 brcmf_fws_txs_process(fws, BRCMF_FWS_TXSTATUS_FW_TOSSED,
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02001996 brcmf_skb_htod_tag_get_field(skb, HSLOT), 0);
1997 /* the packet never reached firmware so reclaim credit */
Arend van Sprielfe353b22013-06-06 13:17:49 +02001998 if (fws->fcmode == BRCMF_FWS_FCMODE_EXPLICIT_CREDIT) {
1999 fifo = brcmf_skb_htod_tag_get_field(skb, FIFO);
2000 brcmf_fws_skb_pickup_credit(fws, fifo, skb);
Arend van Spriel84bcc0c2013-04-03 12:40:50 +02002001 }
Arend van Spriel0f8b5cc2013-04-03 12:40:41 +02002002 brcmf_fws_unlock(fws->drvr, flags);
2003}
Hante Meulemandf50f752013-06-06 13:17:48 +02002004
2005void brcmf_fws_bus_blocked(struct brcmf_pub *drvr, bool flow_blocked)
2006{
2007 struct brcmf_fws_info *fws = drvr->fws;
2008
2009 fws->bus_flow_blocked = flow_blocked;
2010 if (!flow_blocked)
2011 brcmf_fws_schedule_deq(fws);
2012}