2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
16 #include <linux/types.h>
17 #include <linux/module.h>
18 #include <linux/if_ether.h>
19 #include <linux/spinlock.h>
20 #include <linux/skbuff.h>
21 #include <linux/netdevice.h>
22 #include <linux/etherdevice.h>
23 #include <linux/err.h>
24 #include <linux/jiffies.h>
25 #include <net/cfg80211.h>
27 #include <brcmu_utils.h>
28 #include <brcmu_wifi.h>
30 #include "dhd_proto.h"
34 #include "fwil_types.h"
38 #include "wl_cfg80211.h"
41 * DOC: Firmware Signalling
43 * Firmware can send signals to host and vice versa, which are passed in the
44 * data packets using TLV based header. This signalling layer is on top of the
45 * BDC bus protocol layer.
49 * single definition for firmware-driver flow control tlv's.
51 * each tlv is specified by BRCMF_FWS_TLV_DEF(name, ID, length).
52 * A length value 0 indicates variable length tlv.
54 #define BRCMF_FWS_TLV_DEFLIST \
55 BRCMF_FWS_TLV_DEF(MAC_OPEN, 1, 1) \
56 BRCMF_FWS_TLV_DEF(MAC_CLOSE, 2, 1) \
57 BRCMF_FWS_TLV_DEF(MAC_REQUEST_CREDIT, 3, 2) \
58 BRCMF_FWS_TLV_DEF(TXSTATUS, 4, 4) \
59 BRCMF_FWS_TLV_DEF(PKTTAG, 5, 4) \
60 BRCMF_FWS_TLV_DEF(MACDESC_ADD, 6, 8) \
61 BRCMF_FWS_TLV_DEF(MACDESC_DEL, 7, 8) \
62 BRCMF_FWS_TLV_DEF(RSSI, 8, 1) \
63 BRCMF_FWS_TLV_DEF(INTERFACE_OPEN, 9, 1) \
64 BRCMF_FWS_TLV_DEF(INTERFACE_CLOSE, 10, 1) \
65 BRCMF_FWS_TLV_DEF(FIFO_CREDITBACK, 11, 6) \
66 BRCMF_FWS_TLV_DEF(PENDING_TRAFFIC_BMP, 12, 2) \
67 BRCMF_FWS_TLV_DEF(MAC_REQUEST_PACKET, 13, 3) \
68 BRCMF_FWS_TLV_DEF(HOST_REORDER_RXPKTS, 14, 10) \
69 BRCMF_FWS_TLV_DEF(TRANS_ID, 18, 6) \
70 BRCMF_FWS_TLV_DEF(COMP_TXSTATUS, 19, 1) \
71 BRCMF_FWS_TLV_DEF(FILLER, 255, 0)
74 * enum brcmf_fws_tlv_type - definition of tlv identifiers.
76 #define BRCMF_FWS_TLV_DEF(name, id, len) \
77 BRCMF_FWS_TYPE_ ## name = id,
78 enum brcmf_fws_tlv_type
{
80 BRCMF_FWS_TYPE_INVALID
82 #undef BRCMF_FWS_TLV_DEF
85 * enum brcmf_fws_tlv_len - definition of tlv lengths.
87 #define BRCMF_FWS_TLV_DEF(name, id, len) \
88 BRCMF_FWS_TYPE_ ## name ## _LEN = (len),
89 enum brcmf_fws_tlv_len
{
92 #undef BRCMF_FWS_TLV_DEF
96 * brcmf_fws_tlv_names - array of tlv names.
98 #define BRCMF_FWS_TLV_DEF(name, id, len) \
101 enum brcmf_fws_tlv_type id
;
103 } brcmf_fws_tlv_names
[] = {
104 BRCMF_FWS_TLV_DEFLIST
106 #undef BRCMF_FWS_TLV_DEF
108 static const char *brcmf_fws_get_tlv_name(enum brcmf_fws_tlv_type id
)
112 for (i
= 0; i
< ARRAY_SIZE(brcmf_fws_tlv_names
); i
++)
113 if (brcmf_fws_tlv_names
[i
].id
== id
)
114 return brcmf_fws_tlv_names
[i
].name
;
119 static const char *brcmf_fws_get_tlv_name(enum brcmf_fws_tlv_type id
)
126 * flags used to enable tlv signalling from firmware.
128 #define BRCMF_FWS_FLAGS_RSSI_SIGNALS 0x0001
129 #define BRCMF_FWS_FLAGS_XONXOFF_SIGNALS 0x0002
130 #define BRCMF_FWS_FLAGS_CREDIT_STATUS_SIGNALS 0x0004
131 #define BRCMF_FWS_FLAGS_HOST_PROPTXSTATUS_ACTIVE 0x0008
132 #define BRCMF_FWS_FLAGS_PSQ_GENERATIONFSM_ENABLE 0x0010
133 #define BRCMF_FWS_FLAGS_PSQ_ZERO_BUFFER_ENABLE 0x0020
134 #define BRCMF_FWS_FLAGS_HOST_RXREORDER_ACTIVE 0x0040
136 #define BRCMF_FWS_MAC_DESC_TABLE_SIZE 32
137 #define BRCMF_FWS_MAC_DESC_ID_INVALID 0xff
139 #define BRCMF_FWS_HOSTIF_FLOWSTATE_OFF 0
140 #define BRCMF_FWS_HOSTIF_FLOWSTATE_ON 1
141 #define BRCMF_FWS_FLOWCONTROL_HIWATER 128
142 #define BRCMF_FWS_FLOWCONTROL_LOWATER 64
144 #define BRCMF_FWS_PSQ_PREC_COUNT ((BRCMF_FWS_FIFO_COUNT + 1) * 2)
145 #define BRCMF_FWS_PSQ_LEN 256
147 #define BRCMF_FWS_HTOD_FLAG_PKTFROMHOST 0x01
148 #define BRCMF_FWS_HTOD_FLAG_PKT_REQUESTED 0x02
150 #define BRCMF_FWS_RET_OK_NOSCHEDULE 0
151 #define BRCMF_FWS_RET_OK_SCHEDULE 1
154 * enum brcmf_fws_skb_state - indicates processing state of skb.
156 * @BRCMF_FWS_SKBSTATE_NEW: sk_buff is newly arrived in the driver.
157 * @BRCMF_FWS_SKBSTATE_DELAYED: sk_buff had to wait on queue.
158 * @BRCMF_FWS_SKBSTATE_SUPPRESSED: sk_buff has been suppressed by firmware.
159 * @BRCMF_FWS_SKBSTATE_TIM: allocated for TIM update info.
161 enum brcmf_fws_skb_state
{
162 BRCMF_FWS_SKBSTATE_NEW
,
163 BRCMF_FWS_SKBSTATE_DELAYED
,
164 BRCMF_FWS_SKBSTATE_SUPPRESSED
,
165 BRCMF_FWS_SKBSTATE_TIM
169 * struct brcmf_skbuff_cb - control buffer associated with skbuff.
171 * @if_flags: holds interface index and packet related flags.
172 * @htod: host to device packet identifier (used in PKTTAG tlv).
173 * @state: transmit state of the packet.
174 * @mac: descriptor related to destination for this packet.
176 * This information is stored in control buffer struct sk_buff::cb, which
177 * provides 48 bytes of storage so this structure should not exceed that.
179 struct brcmf_skbuff_cb
{
182 enum brcmf_fws_skb_state state
;
183 struct brcmf_fws_mac_descriptor
*mac
;
187 * macro casting skbuff control buffer to struct brcmf_skbuff_cb.
189 #define brcmf_skbcb(skb) ((struct brcmf_skbuff_cb *)((skb)->cb))
192 * sk_buff control if flags
194 * b[11] - packet sent upon firmware request.
195 * b[10] - packet only contains signalling data.
196 * b[9] - packet is a tx packet.
197 * b[8] - packet used requested credit
198 * b[7] - interface in AP mode.
199 * b[3:0] - interface index.
201 #define BRCMF_SKB_IF_FLAGS_REQUESTED_MASK 0x0800
202 #define BRCMF_SKB_IF_FLAGS_REQUESTED_SHIFT 11
203 #define BRCMF_SKB_IF_FLAGS_SIGNAL_ONLY_MASK 0x0400
204 #define BRCMF_SKB_IF_FLAGS_SIGNAL_ONLY_SHIFT 10
205 #define BRCMF_SKB_IF_FLAGS_TRANSMIT_MASK 0x0200
206 #define BRCMF_SKB_IF_FLAGS_TRANSMIT_SHIFT 9
207 #define BRCMF_SKB_IF_FLAGS_REQ_CREDIT_MASK 0x0100
208 #define BRCMF_SKB_IF_FLAGS_REQ_CREDIT_SHIFT 8
209 #define BRCMF_SKB_IF_FLAGS_IF_AP_MASK 0x0080
210 #define BRCMF_SKB_IF_FLAGS_IF_AP_SHIFT 7
211 #define BRCMF_SKB_IF_FLAGS_INDEX_MASK 0x000f
212 #define BRCMF_SKB_IF_FLAGS_INDEX_SHIFT 0
214 #define brcmf_skb_if_flags_set_field(skb, field, value) \
215 brcmu_maskset16(&(brcmf_skbcb(skb)->if_flags), \
216 BRCMF_SKB_IF_FLAGS_ ## field ## _MASK, \
217 BRCMF_SKB_IF_FLAGS_ ## field ## _SHIFT, (value))
218 #define brcmf_skb_if_flags_get_field(skb, field) \
219 brcmu_maskget16(brcmf_skbcb(skb)->if_flags, \
220 BRCMF_SKB_IF_FLAGS_ ## field ## _MASK, \
221 BRCMF_SKB_IF_FLAGS_ ## field ## _SHIFT)
224 * sk_buff control packet identifier
226 * 32-bit packet identifier used in PKTTAG tlv from host to dongle.
228 * - Generated at the host (e.g. dhd)
229 * - Seen as a generic sequence number by firmware except for the flags field.
231 * Generation : b[31] => generation number for this packet [host->fw]
232 * OR, current generation number [fw->host]
233 * Flags : b[30:27] => command, status flags
234 * FIFO-AC : b[26:24] => AC-FIFO id
235 * h-slot : b[23:8] => hanger-slot
236 * freerun : b[7:0] => A free running counter
238 #define BRCMF_SKB_HTOD_TAG_GENERATION_MASK 0x80000000
239 #define BRCMF_SKB_HTOD_TAG_GENERATION_SHIFT 31
240 #define BRCMF_SKB_HTOD_TAG_FLAGS_MASK 0x78000000
241 #define BRCMF_SKB_HTOD_TAG_FLAGS_SHIFT 27
242 #define BRCMF_SKB_HTOD_TAG_FIFO_MASK 0x07000000
243 #define BRCMF_SKB_HTOD_TAG_FIFO_SHIFT 24
244 #define BRCMF_SKB_HTOD_TAG_HSLOT_MASK 0x00ffff00
245 #define BRCMF_SKB_HTOD_TAG_HSLOT_SHIFT 8
246 #define BRCMF_SKB_HTOD_TAG_FREERUN_MASK 0x000000ff
247 #define BRCMF_SKB_HTOD_TAG_FREERUN_SHIFT 0
249 #define brcmf_skb_htod_tag_set_field(skb, field, value) \
250 brcmu_maskset32(&(brcmf_skbcb(skb)->htod), \
251 BRCMF_SKB_HTOD_TAG_ ## field ## _MASK, \
252 BRCMF_SKB_HTOD_TAG_ ## field ## _SHIFT, (value))
253 #define brcmf_skb_htod_tag_get_field(skb, field) \
254 brcmu_maskget32(brcmf_skbcb(skb)->htod, \
255 BRCMF_SKB_HTOD_TAG_ ## field ## _MASK, \
256 BRCMF_SKB_HTOD_TAG_ ## field ## _SHIFT)
258 #define BRCMF_FWS_TXSTAT_GENERATION_MASK 0x80000000
259 #define BRCMF_FWS_TXSTAT_GENERATION_SHIFT 31
260 #define BRCMF_FWS_TXSTAT_FLAGS_MASK 0x78000000
261 #define BRCMF_FWS_TXSTAT_FLAGS_SHIFT 27
262 #define BRCMF_FWS_TXSTAT_FIFO_MASK 0x07000000
263 #define BRCMF_FWS_TXSTAT_FIFO_SHIFT 24
264 #define BRCMF_FWS_TXSTAT_HSLOT_MASK 0x00FFFF00
265 #define BRCMF_FWS_TXSTAT_HSLOT_SHIFT 8
266 #define BRCMF_FWS_TXSTAT_PKTID_MASK 0x00FFFFFF
267 #define BRCMF_FWS_TXSTAT_PKTID_SHIFT 0
269 #define brcmf_txstatus_get_field(txs, field) \
270 brcmu_maskget32(txs, BRCMF_FWS_TXSTAT_ ## field ## _MASK, \
271 BRCMF_FWS_TXSTAT_ ## field ## _SHIFT)
273 /* How long to defer borrowing in jiffies */
274 #define BRCMF_FWS_BORROW_DEFER_PERIOD (HZ / 10)
277 * enum brcmf_fws_fifo - fifo indices used by dongle firmware.
279 * @BRCMF_FWS_FIFO_FIRST: first fifo, ie. background.
280 * @BRCMF_FWS_FIFO_AC_BK: fifo for background traffic.
281 * @BRCMF_FWS_FIFO_AC_BE: fifo for best-effort traffic.
282 * @BRCMF_FWS_FIFO_AC_VI: fifo for video traffic.
283 * @BRCMF_FWS_FIFO_AC_VO: fifo for voice traffic.
284 * @BRCMF_FWS_FIFO_BCMC: fifo for broadcast/multicast (AP only).
285 * @BRCMF_FWS_FIFO_ATIM: fifo for ATIM (AP only).
286 * @BRCMF_FWS_FIFO_COUNT: number of fifos.
288 enum brcmf_fws_fifo
{
289 BRCMF_FWS_FIFO_FIRST
,
290 BRCMF_FWS_FIFO_AC_BK
= BRCMF_FWS_FIFO_FIRST
,
291 BRCMF_FWS_FIFO_AC_BE
,
292 BRCMF_FWS_FIFO_AC_VI
,
293 BRCMF_FWS_FIFO_AC_VO
,
300 * enum brcmf_fws_txstatus - txstatus flag values.
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 * @BRCMF_FWS_TXSTATUS_HOST_TOSSED:
311 * host tossed the packet.
313 enum brcmf_fws_txstatus
{
314 BRCMF_FWS_TXSTATUS_DISCARD
,
315 BRCMF_FWS_TXSTATUS_CORE_SUPPRESS
,
316 BRCMF_FWS_TXSTATUS_FW_PS_SUPPRESS
,
317 BRCMF_FWS_TXSTATUS_FW_TOSSED
,
318 BRCMF_FWS_TXSTATUS_HOST_TOSSED
321 enum brcmf_fws_fcmode
{
322 BRCMF_FWS_FCMODE_NONE
,
323 BRCMF_FWS_FCMODE_IMPLIED_CREDIT
,
324 BRCMF_FWS_FCMODE_EXPLICIT_CREDIT
327 enum brcmf_fws_mac_desc_state
{
328 BRCMF_FWS_STATE_OPEN
= 1,
329 BRCMF_FWS_STATE_CLOSE
333 * struct brcmf_fws_mac_descriptor - firmware signalling data per node/interface
335 * @occupied: slot is in use.
336 * @mac_handle: handle for mac entry determined by firmware.
337 * @interface_id: interface index.
338 * @state: current state.
339 * @suppressed: mac entry is suppressed.
340 * @generation: generation bit.
341 * @ac_bitmap: ac queue bitmap.
342 * @requested_credit: credits requested by firmware.
343 * @ea: ethernet address.
344 * @seq: per-node free-running sequence.
345 * @psq: power-save queue.
346 * @transit_count: packet in transit to firmware.
348 struct brcmf_fws_mac_descriptor
{
360 u8 seq
[BRCMF_FWS_FIFO_COUNT
];
363 int suppr_transit_count
;
364 bool send_tim_signal
;
365 u8 traffic_pending_bmp
;
366 u8 traffic_lastreported_bmp
;
369 #define BRCMF_FWS_HANGER_MAXITEMS 1024
372 * enum brcmf_fws_hanger_item_state - state of hanger item.
374 * @BRCMF_FWS_HANGER_ITEM_STATE_FREE: item is free for use.
375 * @BRCMF_FWS_HANGER_ITEM_STATE_INUSE: item is in use.
376 * @BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED: item was suppressed.
378 enum brcmf_fws_hanger_item_state
{
379 BRCMF_FWS_HANGER_ITEM_STATE_FREE
= 1,
380 BRCMF_FWS_HANGER_ITEM_STATE_INUSE
,
381 BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED
386 * struct brcmf_fws_hanger_item - single entry for tx pending packet.
388 * @state: entry is either free or occupied.
389 * @pkt: packet itself.
391 struct brcmf_fws_hanger_item
{
392 enum brcmf_fws_hanger_item_state state
;
397 * struct brcmf_fws_hanger - holds packets awaiting firmware txstatus.
399 * @pushed: packets pushed to await txstatus.
400 * @popped: packets popped upon handling txstatus.
401 * @failed_to_push: packets that could not be pushed.
402 * @failed_to_pop: packets that could not be popped.
403 * @failed_slotfind: packets for which failed to find an entry.
404 * @slot_pos: last returned item index for a free entry.
405 * @items: array of hanger items.
407 struct brcmf_fws_hanger
{
414 struct brcmf_fws_hanger_item items
[BRCMF_FWS_HANGER_MAXITEMS
];
417 struct brcmf_fws_macdesc_table
{
418 struct brcmf_fws_mac_descriptor nodes
[BRCMF_FWS_MAC_DESC_TABLE_SIZE
];
419 struct brcmf_fws_mac_descriptor iface
[BRCMF_MAX_IFS
];
420 struct brcmf_fws_mac_descriptor other
;
423 struct brcmf_fws_info
{
424 struct brcmf_pub
*drvr
;
427 struct brcmf_fws_stats stats
;
428 struct brcmf_fws_hanger hanger
;
429 enum brcmf_fws_fcmode fcmode
;
431 bool bcmc_credit_check
;
432 struct brcmf_fws_macdesc_table desc
;
433 struct workqueue_struct
*fws_wq
;
434 struct work_struct fws_dequeue_work
;
435 u32 fifo_enqpkt
[BRCMF_FWS_FIFO_COUNT
];
436 int fifo_credit
[BRCMF_FWS_FIFO_COUNT
];
437 int credits_borrowed
[BRCMF_FWS_FIFO_AC_VO
+ 1];
438 int deq_node_pos
[BRCMF_FWS_FIFO_COUNT
];
441 unsigned long borrow_defer_timestamp
;
442 bool bus_flow_blocked
;
443 bool creditmap_received
;
447 * brcmf_fws_prio2fifo - mapping from 802.1d priority to firmware fifo index.
449 static const int brcmf_fws_prio2fifo
[] = {
450 BRCMF_FWS_FIFO_AC_BE
,
451 BRCMF_FWS_FIFO_AC_BK
,
452 BRCMF_FWS_FIFO_AC_BK
,
453 BRCMF_FWS_FIFO_AC_BE
,
454 BRCMF_FWS_FIFO_AC_VI
,
455 BRCMF_FWS_FIFO_AC_VI
,
456 BRCMF_FWS_FIFO_AC_VO
,
461 module_param(fcmode
, int, S_IRUSR
);
462 MODULE_PARM_DESC(fcmode
, "mode of firmware signalled flow control");
464 #define BRCMF_FWS_TLV_DEF(name, id, len) \
465 case BRCMF_FWS_TYPE_ ## name: \
469 * brcmf_fws_get_tlv_len() - returns defined length for given tlv id.
471 * @fws: firmware-signalling information.
472 * @id: identifier of the TLV.
474 * Return: the specified length for the given TLV; Otherwise -EINVAL.
476 static int brcmf_fws_get_tlv_len(struct brcmf_fws_info
*fws
,
477 enum brcmf_fws_tlv_type id
)
480 BRCMF_FWS_TLV_DEFLIST
482 fws
->stats
.tlv_invalid_type
++;
487 #undef BRCMF_FWS_TLV_DEF
489 static void brcmf_fws_lock(struct brcmf_fws_info
*fws
)
490 __acquires(&fws
->spinlock
)
492 spin_lock_irqsave(&fws
->spinlock
, fws
->flags
);
495 static void brcmf_fws_unlock(struct brcmf_fws_info
*fws
)
496 __releases(&fws
->spinlock
)
498 spin_unlock_irqrestore(&fws
->spinlock
, fws
->flags
);
501 static bool brcmf_fws_ifidx_match(struct sk_buff
*skb
, void *arg
)
503 u32 ifidx
= brcmf_skb_if_flags_get_field(skb
, INDEX
);
504 return ifidx
== *(int *)arg
;
507 static void brcmf_fws_psq_flush(struct brcmf_fws_info
*fws
, struct pktq
*q
,
510 bool (*matchfn
)(struct sk_buff
*, void *) = NULL
;
515 matchfn
= brcmf_fws_ifidx_match
;
516 for (prec
= 0; prec
< q
->num_prec
; prec
++) {
517 skb
= brcmu_pktq_pdeq_match(q
, prec
, matchfn
, &ifidx
);
519 brcmu_pkt_buf_free_skb(skb
);
520 skb
= brcmu_pktq_pdeq_match(q
, prec
, matchfn
, &ifidx
);
525 static void brcmf_fws_hanger_init(struct brcmf_fws_hanger
*hanger
)
529 memset(hanger
, 0, sizeof(*hanger
));
530 for (i
= 0; i
< ARRAY_SIZE(hanger
->items
); i
++)
531 hanger
->items
[i
].state
= BRCMF_FWS_HANGER_ITEM_STATE_FREE
;
534 static u32
brcmf_fws_hanger_get_free_slot(struct brcmf_fws_hanger
*h
)
538 i
= (h
->slot_pos
+ 1) % BRCMF_FWS_HANGER_MAXITEMS
;
540 while (i
!= h
->slot_pos
) {
541 if (h
->items
[i
].state
== BRCMF_FWS_HANGER_ITEM_STATE_FREE
) {
546 if (i
== BRCMF_FWS_HANGER_MAXITEMS
)
549 brcmf_err("all slots occupied\n");
550 h
->failed_slotfind
++;
551 i
= BRCMF_FWS_HANGER_MAXITEMS
;
556 static int brcmf_fws_hanger_pushpkt(struct brcmf_fws_hanger
*h
,
557 struct sk_buff
*pkt
, u32 slot_id
)
559 if (slot_id
>= BRCMF_FWS_HANGER_MAXITEMS
)
562 if (h
->items
[slot_id
].state
!= BRCMF_FWS_HANGER_ITEM_STATE_FREE
) {
563 brcmf_err("slot is not free\n");
568 h
->items
[slot_id
].state
= BRCMF_FWS_HANGER_ITEM_STATE_INUSE
;
569 h
->items
[slot_id
].pkt
= pkt
;
574 static int brcmf_fws_hanger_poppkt(struct brcmf_fws_hanger
*h
,
575 u32 slot_id
, struct sk_buff
**pktout
,
578 if (slot_id
>= BRCMF_FWS_HANGER_MAXITEMS
)
581 if (h
->items
[slot_id
].state
== BRCMF_FWS_HANGER_ITEM_STATE_FREE
) {
582 brcmf_err("entry not in use\n");
587 *pktout
= h
->items
[slot_id
].pkt
;
589 h
->items
[slot_id
].state
= BRCMF_FWS_HANGER_ITEM_STATE_FREE
;
590 h
->items
[slot_id
].pkt
= NULL
;
596 static int brcmf_fws_hanger_mark_suppressed(struct brcmf_fws_hanger
*h
,
599 if (slot_id
>= BRCMF_FWS_HANGER_MAXITEMS
)
602 if (h
->items
[slot_id
].state
== BRCMF_FWS_HANGER_ITEM_STATE_FREE
) {
603 brcmf_err("entry not in use\n");
607 h
->items
[slot_id
].state
= BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED
;
611 static void brcmf_fws_hanger_cleanup(struct brcmf_fws_info
*fws
,
612 bool (*fn
)(struct sk_buff
*, void *),
615 struct brcmf_fws_hanger
*h
= &fws
->hanger
;
618 enum brcmf_fws_hanger_item_state s
;
620 for (i
= 0; i
< ARRAY_SIZE(h
->items
); i
++) {
621 s
= h
->items
[i
].state
;
622 if (s
== BRCMF_FWS_HANGER_ITEM_STATE_INUSE
||
623 s
== BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED
) {
624 skb
= h
->items
[i
].pkt
;
625 if (fn
== NULL
|| fn(skb
, &ifidx
)) {
626 /* suppress packets freed from psq */
627 if (s
== BRCMF_FWS_HANGER_ITEM_STATE_INUSE
)
628 brcmu_pkt_buf_free_skb(skb
);
630 BRCMF_FWS_HANGER_ITEM_STATE_FREE
;
636 static void brcmf_fws_macdesc_set_name(struct brcmf_fws_info
*fws
,
637 struct brcmf_fws_mac_descriptor
*desc
)
639 if (desc
== &fws
->desc
.other
)
640 strlcpy(desc
->name
, "MAC-OTHER", sizeof(desc
->name
));
641 else if (desc
->mac_handle
)
642 scnprintf(desc
->name
, sizeof(desc
->name
), "MAC-%d:%d",
643 desc
->mac_handle
, desc
->interface_id
);
645 scnprintf(desc
->name
, sizeof(desc
->name
), "MACIF:%d",
649 static void brcmf_fws_macdesc_init(struct brcmf_fws_mac_descriptor
*desc
,
653 "enter: desc %p ea=%pM, ifidx=%u\n", desc
, addr
, ifidx
);
655 desc
->state
= BRCMF_FWS_STATE_OPEN
;
656 desc
->requested_credit
= 0;
657 desc
->requested_packet
= 0;
658 /* depending on use may need ifp->bssidx instead */
659 desc
->interface_id
= ifidx
;
660 desc
->ac_bitmap
= 0xff; /* update this when handling APSD */
662 memcpy(&desc
->ea
[0], addr
, ETH_ALEN
);
666 void brcmf_fws_macdesc_deinit(struct brcmf_fws_mac_descriptor
*desc
)
669 "enter: ea=%pM, ifidx=%u\n", desc
->ea
, desc
->interface_id
);
671 desc
->state
= BRCMF_FWS_STATE_CLOSE
;
672 desc
->requested_credit
= 0;
673 desc
->requested_packet
= 0;
676 static struct brcmf_fws_mac_descriptor
*
677 brcmf_fws_macdesc_lookup(struct brcmf_fws_info
*fws
, u8
*ea
)
679 struct brcmf_fws_mac_descriptor
*entry
;
683 return ERR_PTR(-EINVAL
);
685 entry
= &fws
->desc
.nodes
[0];
686 for (i
= 0; i
< ARRAY_SIZE(fws
->desc
.nodes
); i
++) {
687 if (entry
->occupied
&& !memcmp(entry
->ea
, ea
, ETH_ALEN
))
692 return ERR_PTR(-ENOENT
);
695 static struct brcmf_fws_mac_descriptor
*
696 brcmf_fws_macdesc_find(struct brcmf_fws_info
*fws
, struct brcmf_if
*ifp
, u8
*da
)
698 struct brcmf_fws_mac_descriptor
*entry
= &fws
->desc
.other
;
701 multicast
= is_multicast_ether_addr(da
);
703 /* Multicast destination, STA and P2P clients get the interface entry.
704 * STA/GC gets the Mac Entry for TDLS destinations, TDLS destinations
705 * have their own entry.
707 if (multicast
&& ifp
->fws_desc
) {
708 entry
= ifp
->fws_desc
;
712 entry
= brcmf_fws_macdesc_lookup(fws
, da
);
714 entry
= ifp
->fws_desc
;
720 static bool brcmf_fws_macdesc_closed(struct brcmf_fws_info
*fws
,
721 struct brcmf_fws_mac_descriptor
*entry
,
724 struct brcmf_fws_mac_descriptor
*if_entry
;
727 /* for unique destination entries the related interface
730 if (entry
->mac_handle
) {
731 if_entry
= &fws
->desc
.iface
[entry
->interface_id
];
732 if (if_entry
->state
== BRCMF_FWS_STATE_CLOSE
)
735 /* an entry is closed when the state is closed and
736 * the firmware did not request anything.
738 closed
= entry
->state
== BRCMF_FWS_STATE_CLOSE
&&
739 !entry
->requested_credit
&& !entry
->requested_packet
;
741 /* Or firmware does not allow traffic for given fifo */
742 return closed
|| !(entry
->ac_bitmap
& BIT(fifo
));
745 static void brcmf_fws_macdesc_cleanup(struct brcmf_fws_info
*fws
,
746 struct brcmf_fws_mac_descriptor
*entry
,
749 if (entry
->occupied
&& (ifidx
== -1 || ifidx
== entry
->interface_id
)) {
750 brcmf_fws_psq_flush(fws
, &entry
->psq
, ifidx
);
751 entry
->occupied
= !!(entry
->psq
.len
);
755 static void brcmf_fws_bus_txq_cleanup(struct brcmf_fws_info
*fws
,
756 bool (*fn
)(struct sk_buff
*, void *),
759 struct brcmf_fws_hanger_item
*hi
;
765 txq
= brcmf_bus_gettxq(fws
->drvr
->bus_if
);
767 brcmf_dbg(TRACE
, "no txq to clean up\n");
771 for (prec
= 0; prec
< txq
->num_prec
; prec
++) {
772 skb
= brcmu_pktq_pdeq_match(txq
, prec
, fn
, &ifidx
);
774 hslot
= brcmf_skb_htod_tag_get_field(skb
, HSLOT
);
775 hi
= &fws
->hanger
.items
[hslot
];
776 WARN_ON(skb
!= hi
->pkt
);
777 hi
->state
= BRCMF_FWS_HANGER_ITEM_STATE_FREE
;
778 brcmu_pkt_buf_free_skb(skb
);
779 skb
= brcmu_pktq_pdeq_match(txq
, prec
, fn
, &ifidx
);
784 static void brcmf_fws_cleanup(struct brcmf_fws_info
*fws
, int ifidx
)
787 struct brcmf_fws_mac_descriptor
*table
;
788 bool (*matchfn
)(struct sk_buff
*, void *) = NULL
;
794 matchfn
= brcmf_fws_ifidx_match
;
796 /* cleanup individual nodes */
797 table
= &fws
->desc
.nodes
[0];
798 for (i
= 0; i
< ARRAY_SIZE(fws
->desc
.nodes
); i
++)
799 brcmf_fws_macdesc_cleanup(fws
, &table
[i
], ifidx
);
801 brcmf_fws_macdesc_cleanup(fws
, &fws
->desc
.other
, ifidx
);
802 brcmf_fws_bus_txq_cleanup(fws
, matchfn
, ifidx
);
803 brcmf_fws_hanger_cleanup(fws
, matchfn
, ifidx
);
806 static int brcmf_fws_hdrpush(struct brcmf_fws_info
*fws
, struct sk_buff
*skb
)
808 struct brcmf_fws_mac_descriptor
*entry
= brcmf_skbcb(skb
)->mac
;
812 __le32 pkttag
= cpu_to_le32(brcmf_skbcb(skb
)->htod
);
814 brcmf_dbg(TRACE
, "enter: %s, idx=%d pkttag=0x%08X, hslot=%d\n",
815 entry
->name
, brcmf_skb_if_flags_get_field(skb
, INDEX
),
816 le32_to_cpu(pkttag
), (le32_to_cpu(pkttag
) >> 8) & 0xffff);
817 if (entry
->send_tim_signal
)
818 data_offset
+= 2 + BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN
;
820 /* +2 is for Type[1] and Len[1] in TLV, plus TIM signal */
821 data_offset
+= 2 + BRCMF_FWS_TYPE_PKTTAG_LEN
;
822 fillers
= round_up(data_offset
, 4) - data_offset
;
823 data_offset
+= fillers
;
825 skb_push(skb
, data_offset
);
828 wlh
[0] = BRCMF_FWS_TYPE_PKTTAG
;
829 wlh
[1] = BRCMF_FWS_TYPE_PKTTAG_LEN
;
830 memcpy(&wlh
[2], &pkttag
, sizeof(pkttag
));
831 wlh
+= BRCMF_FWS_TYPE_PKTTAG_LEN
+ 2;
833 if (entry
->send_tim_signal
) {
834 entry
->send_tim_signal
= 0;
835 wlh
[0] = BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP
;
836 wlh
[1] = BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN
;
837 wlh
[2] = entry
->mac_handle
;
838 wlh
[3] = entry
->traffic_pending_bmp
;
839 brcmf_dbg(TRACE
, "adding TIM info: handle %d bmp 0x%X\n",
840 entry
->mac_handle
, entry
->traffic_pending_bmp
);
841 wlh
+= BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN
+ 2;
842 entry
->traffic_lastreported_bmp
= entry
->traffic_pending_bmp
;
845 memset(wlh
, BRCMF_FWS_TYPE_FILLER
, fillers
);
847 brcmf_proto_hdrpush(fws
->drvr
, brcmf_skb_if_flags_get_field(skb
, INDEX
),
848 data_offset
>> 2, skb
);
852 static bool brcmf_fws_tim_update(struct brcmf_fws_info
*fws
,
853 struct brcmf_fws_mac_descriptor
*entry
,
854 int fifo
, bool send_immediately
)
857 struct brcmf_bus
*bus
;
858 struct brcmf_skbuff_cb
*skcb
;
862 /* check delayedQ and suppressQ in one call using bitmap */
863 if (brcmu_pktq_mlen(&entry
->psq
, 3 << (fifo
* 2)) == 0)
864 entry
->traffic_pending_bmp
&= ~NBITVAL(fifo
);
866 entry
->traffic_pending_bmp
|= NBITVAL(fifo
);
868 entry
->send_tim_signal
= false;
869 if (entry
->traffic_lastreported_bmp
!= entry
->traffic_pending_bmp
)
870 entry
->send_tim_signal
= true;
871 if (send_immediately
&& entry
->send_tim_signal
&&
872 entry
->state
== BRCMF_FWS_STATE_CLOSE
) {
873 /* create a dummy packet and sent that. The traffic */
874 /* bitmap info will automatically be attached to that packet */
875 len
= BRCMF_FWS_TYPE_PKTTAG_LEN
+ 2 +
876 BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN
+ 2 +
877 4 + fws
->drvr
->hdrlen
;
878 skb
= brcmu_pkt_buf_get_skb(len
);
882 skcb
= brcmf_skbcb(skb
);
884 skcb
->state
= BRCMF_FWS_SKBSTATE_TIM
;
885 bus
= fws
->drvr
->bus_if
;
886 err
= brcmf_fws_hdrpush(fws
, skb
);
888 brcmf_fws_unlock(fws
);
889 err
= brcmf_bus_txdata(bus
, skb
);
893 brcmu_pkt_buf_free_skb(skb
);
900 brcmf_fws_flow_control_check(struct brcmf_fws_info
*fws
, struct pktq
*pq
,
903 struct brcmf_if
*ifp
= fws
->drvr
->iflist
[!if_id
? 0 : if_id
+ 1];
908 if ((ifp
->netif_stop
& BRCMF_NETIF_STOP_REASON_FWS_FC
) &&
909 pq
->len
<= BRCMF_FWS_FLOWCONTROL_LOWATER
)
910 brcmf_txflowblock_if(ifp
,
911 BRCMF_NETIF_STOP_REASON_FWS_FC
, false);
912 if (!(ifp
->netif_stop
& BRCMF_NETIF_STOP_REASON_FWS_FC
) &&
913 pq
->len
>= BRCMF_FWS_FLOWCONTROL_HIWATER
) {
914 fws
->stats
.fws_flow_block
++;
915 brcmf_txflowblock_if(ifp
, BRCMF_NETIF_STOP_REASON_FWS_FC
, true);
920 static int brcmf_fws_rssi_indicate(struct brcmf_fws_info
*fws
, s8 rssi
)
922 brcmf_dbg(CTL
, "rssi %d\n", rssi
);
927 int brcmf_fws_macdesc_indicate(struct brcmf_fws_info
*fws
, u8 type
, u8
*data
)
929 struct brcmf_fws_mac_descriptor
*entry
, *existing
;
934 mac_handle
= *data
++;
938 entry
= &fws
->desc
.nodes
[mac_handle
& 0x1F];
939 if (type
== BRCMF_FWS_TYPE_MACDESC_DEL
) {
940 if (entry
->occupied
) {
941 brcmf_dbg(TRACE
, "deleting %s mac %pM\n",
944 brcmf_fws_macdesc_cleanup(fws
, entry
, -1);
945 brcmf_fws_macdesc_deinit(entry
);
946 brcmf_fws_unlock(fws
);
948 fws
->stats
.mac_update_failed
++;
952 existing
= brcmf_fws_macdesc_lookup(fws
, addr
);
953 if (IS_ERR(existing
)) {
954 if (!entry
->occupied
) {
956 entry
->mac_handle
= mac_handle
;
957 brcmf_fws_macdesc_init(entry
, addr
, ifidx
);
958 brcmf_fws_macdesc_set_name(fws
, entry
);
959 brcmu_pktq_init(&entry
->psq
, BRCMF_FWS_PSQ_PREC_COUNT
,
961 brcmf_fws_unlock(fws
);
962 brcmf_dbg(TRACE
, "add %s mac %pM\n", entry
->name
, addr
);
964 fws
->stats
.mac_update_failed
++;
967 if (entry
!= existing
) {
968 brcmf_dbg(TRACE
, "copy mac %s\n", existing
->name
);
970 memcpy(entry
, existing
,
971 offsetof(struct brcmf_fws_mac_descriptor
, psq
));
972 entry
->mac_handle
= mac_handle
;
973 brcmf_fws_macdesc_deinit(existing
);
974 brcmf_fws_macdesc_set_name(fws
, entry
);
975 brcmf_fws_unlock(fws
);
976 brcmf_dbg(TRACE
, "relocate %s mac %pM\n", entry
->name
,
979 brcmf_dbg(TRACE
, "use existing\n");
980 WARN_ON(entry
->mac_handle
!= mac_handle
);
981 /* TODO: what should we do here: continue, reinit, .. */
987 static int brcmf_fws_macdesc_state_indicate(struct brcmf_fws_info
*fws
,
990 struct brcmf_fws_mac_descriptor
*entry
;
994 mac_handle
= data
[0];
995 entry
= &fws
->desc
.nodes
[mac_handle
& 0x1F];
996 if (!entry
->occupied
) {
997 fws
->stats
.mac_ps_update_failed
++;
1000 brcmf_fws_lock(fws
);
1001 /* a state update should wipe old credits */
1002 entry
->requested_credit
= 0;
1003 entry
->requested_packet
= 0;
1004 if (type
== BRCMF_FWS_TYPE_MAC_OPEN
) {
1005 entry
->state
= BRCMF_FWS_STATE_OPEN
;
1006 ret
= BRCMF_FWS_RET_OK_SCHEDULE
;
1008 entry
->state
= BRCMF_FWS_STATE_CLOSE
;
1009 brcmf_fws_tim_update(fws
, entry
, BRCMF_FWS_FIFO_AC_BK
, false);
1010 brcmf_fws_tim_update(fws
, entry
, BRCMF_FWS_FIFO_AC_BE
, false);
1011 brcmf_fws_tim_update(fws
, entry
, BRCMF_FWS_FIFO_AC_VI
, false);
1012 brcmf_fws_tim_update(fws
, entry
, BRCMF_FWS_FIFO_AC_VO
, true);
1013 ret
= BRCMF_FWS_RET_OK_NOSCHEDULE
;
1015 brcmf_fws_unlock(fws
);
1019 static int brcmf_fws_interface_state_indicate(struct brcmf_fws_info
*fws
,
1022 struct brcmf_fws_mac_descriptor
*entry
;
1028 if (ifidx
>= BRCMF_MAX_IFS
) {
1033 entry
= &fws
->desc
.iface
[ifidx
];
1034 if (!entry
->occupied
) {
1039 brcmf_dbg(TRACE
, "%s (%d): %s\n", brcmf_fws_get_tlv_name(type
), type
,
1041 brcmf_fws_lock(fws
);
1043 case BRCMF_FWS_TYPE_INTERFACE_OPEN
:
1044 entry
->state
= BRCMF_FWS_STATE_OPEN
;
1045 ret
= BRCMF_FWS_RET_OK_SCHEDULE
;
1047 case BRCMF_FWS_TYPE_INTERFACE_CLOSE
:
1048 entry
->state
= BRCMF_FWS_STATE_CLOSE
;
1049 ret
= BRCMF_FWS_RET_OK_NOSCHEDULE
;
1053 brcmf_fws_unlock(fws
);
1056 brcmf_fws_unlock(fws
);
1060 fws
->stats
.if_update_failed
++;
1064 static int brcmf_fws_request_indicate(struct brcmf_fws_info
*fws
, u8 type
,
1067 struct brcmf_fws_mac_descriptor
*entry
;
1069 entry
= &fws
->desc
.nodes
[data
[1] & 0x1F];
1070 if (!entry
->occupied
) {
1071 if (type
== BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT
)
1072 fws
->stats
.credit_request_failed
++;
1074 fws
->stats
.packet_request_failed
++;
1078 brcmf_dbg(TRACE
, "%s (%d): %s cnt %d bmp %d\n",
1079 brcmf_fws_get_tlv_name(type
), type
, entry
->name
,
1081 brcmf_fws_lock(fws
);
1082 if (type
== BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT
)
1083 entry
->requested_credit
= data
[0];
1085 entry
->requested_packet
= data
[0];
1087 entry
->ac_bitmap
= data
[2];
1088 brcmf_fws_unlock(fws
);
1089 return BRCMF_FWS_RET_OK_SCHEDULE
;
1093 brcmf_fws_macdesc_use_req_credit(struct brcmf_fws_mac_descriptor
*entry
,
1094 struct sk_buff
*skb
)
1096 if (entry
->requested_credit
> 0) {
1097 entry
->requested_credit
--;
1098 brcmf_skb_if_flags_set_field(skb
, REQUESTED
, 1);
1099 brcmf_skb_if_flags_set_field(skb
, REQ_CREDIT
, 1);
1100 if (entry
->state
!= BRCMF_FWS_STATE_CLOSE
)
1101 brcmf_err("requested credit set while mac not closed!\n");
1102 } else if (entry
->requested_packet
> 0) {
1103 entry
->requested_packet
--;
1104 brcmf_skb_if_flags_set_field(skb
, REQUESTED
, 1);
1105 brcmf_skb_if_flags_set_field(skb
, REQ_CREDIT
, 0);
1106 if (entry
->state
!= BRCMF_FWS_STATE_CLOSE
)
1107 brcmf_err("requested packet set while mac not closed!\n");
1109 brcmf_skb_if_flags_set_field(skb
, REQUESTED
, 0);
1110 brcmf_skb_if_flags_set_field(skb
, REQ_CREDIT
, 0);
1114 static void brcmf_fws_macdesc_return_req_credit(struct sk_buff
*skb
)
1116 struct brcmf_fws_mac_descriptor
*entry
= brcmf_skbcb(skb
)->mac
;
1118 if ((brcmf_skb_if_flags_get_field(skb
, REQ_CREDIT
)) &&
1119 (entry
->state
== BRCMF_FWS_STATE_CLOSE
))
1120 entry
->requested_credit
++;
1123 static void brcmf_fws_return_credits(struct brcmf_fws_info
*fws
,
1124 u8 fifo
, u8 credits
)
1133 fws
->fifo_credit_map
|= 1 << fifo
;
1135 if ((fifo
== BRCMF_FWS_FIFO_AC_BE
) &&
1136 (fws
->credits_borrowed
[0])) {
1137 for (lender_ac
= BRCMF_FWS_FIFO_AC_VO
; lender_ac
>= 0;
1139 borrowed
= &fws
->credits_borrowed
[lender_ac
];
1141 fws
->fifo_credit_map
|= (1 << lender_ac
);
1142 fifo_credit
= &fws
->fifo_credit
[lender_ac
];
1143 if (*borrowed
>= credits
) {
1144 *borrowed
-= credits
;
1145 *fifo_credit
+= credits
;
1148 credits
-= *borrowed
;
1149 *fifo_credit
+= *borrowed
;
1156 fws
->fifo_credit
[fifo
] += credits
;
1159 static void brcmf_fws_schedule_deq(struct brcmf_fws_info
*fws
)
1161 /* only schedule dequeue when there are credits for delayed traffic */
1162 if ((fws
->fifo_credit_map
& fws
->fifo_delay_map
) ||
1163 (!brcmf_fws_fc_active(fws
) && fws
->fifo_delay_map
))
1164 queue_work(fws
->fws_wq
, &fws
->fws_dequeue_work
);
1167 static int brcmf_fws_enq(struct brcmf_fws_info
*fws
,
1168 enum brcmf_fws_skb_state state
, int fifo
,
1171 int prec
= 2 * fifo
;
1172 u32
*qfull_stat
= &fws
->stats
.delayq_full_error
;
1174 struct brcmf_fws_mac_descriptor
*entry
;
1176 entry
= brcmf_skbcb(p
)->mac
;
1177 if (entry
== NULL
) {
1178 brcmf_err("no mac descriptor found for skb %p\n", p
);
1182 brcmf_dbg(DATA
, "enter: fifo %d skb %p\n", fifo
, p
);
1183 if (state
== BRCMF_FWS_SKBSTATE_SUPPRESSED
) {
1185 qfull_stat
= &fws
->stats
.supprq_full_error
;
1188 if (brcmu_pktq_penq(&entry
->psq
, prec
, p
) == NULL
) {
1193 /* increment total enqueued packet count */
1194 fws
->fifo_delay_map
|= 1 << fifo
;
1195 fws
->fifo_enqpkt
[fifo
]++;
1197 /* update the sk_buff state */
1198 brcmf_skbcb(p
)->state
= state
;
1201 * A packet has been pushed so update traffic
1202 * availability bitmap, if applicable
1204 brcmf_fws_tim_update(fws
, entry
, fifo
, true);
1205 brcmf_fws_flow_control_check(fws
, &entry
->psq
,
1206 brcmf_skb_if_flags_get_field(p
, INDEX
));
1210 static struct sk_buff
*brcmf_fws_deq(struct brcmf_fws_info
*fws
, int fifo
)
1212 struct brcmf_fws_mac_descriptor
*table
;
1213 struct brcmf_fws_mac_descriptor
*entry
;
1221 table
= (struct brcmf_fws_mac_descriptor
*)&fws
->desc
;
1222 num_nodes
= sizeof(fws
->desc
) / sizeof(struct brcmf_fws_mac_descriptor
);
1223 node_pos
= fws
->deq_node_pos
[fifo
];
1225 for (i
= 0; i
< num_nodes
; i
++) {
1226 entry
= &table
[(node_pos
+ i
) % num_nodes
];
1227 if (!entry
->occupied
||
1228 brcmf_fws_macdesc_closed(fws
, entry
, fifo
))
1231 if (entry
->suppressed
)
1235 p
= brcmu_pktq_mdeq(&entry
->psq
, pmsk
<< (fifo
* 2), &prec_out
);
1237 if (entry
->suppressed
) {
1238 if (entry
->suppr_transit_count
)
1240 entry
->suppressed
= false;
1241 p
= brcmu_pktq_mdeq(&entry
->psq
,
1242 1 << (fifo
* 2), &prec_out
);
1248 brcmf_fws_macdesc_use_req_credit(entry
, p
);
1250 /* move dequeue position to ensure fair round-robin */
1251 fws
->deq_node_pos
[fifo
] = (node_pos
+ i
+ 1) % num_nodes
;
1252 brcmf_fws_flow_control_check(fws
, &entry
->psq
,
1253 brcmf_skb_if_flags_get_field(p
,
1257 * A packet has been picked up, update traffic
1258 * availability bitmap, if applicable
1260 brcmf_fws_tim_update(fws
, entry
, fifo
, false);
1263 * decrement total enqueued fifo packets and
1264 * clear delay bitmap if done.
1266 fws
->fifo_enqpkt
[fifo
]--;
1267 if (fws
->fifo_enqpkt
[fifo
] == 0)
1268 fws
->fifo_delay_map
&= ~(1 << fifo
);
1273 brcmf_dbg(DATA
, "exit: fifo %d skb %p\n", fifo
, p
);
1277 static int brcmf_fws_txstatus_suppressed(struct brcmf_fws_info
*fws
, int fifo
,
1278 struct sk_buff
*skb
, u32 genbit
)
1280 struct brcmf_fws_mac_descriptor
*entry
= brcmf_skbcb(skb
)->mac
;
1285 hslot
= brcmf_skb_htod_tag_get_field(skb
, HSLOT
);
1287 /* this packet was suppressed */
1288 if (!entry
->suppressed
) {
1289 entry
->suppressed
= true;
1290 entry
->suppr_transit_count
= entry
->transit_count
;
1291 brcmf_dbg(DATA
, "suppress %s: transit %d\n",
1292 entry
->name
, entry
->transit_count
);
1295 entry
->generation
= genbit
;
1297 ret
= brcmf_proto_hdrpull(fws
->drvr
, false, &ifidx
, skb
);
1299 ret
= brcmf_fws_enq(fws
, BRCMF_FWS_SKBSTATE_SUPPRESSED
, fifo
,
1302 /* suppress q is full or hdrpull failed, drop this packet */
1303 brcmf_fws_hanger_poppkt(&fws
->hanger
, hslot
, &skb
,
1307 * Mark suppressed to avoid a double free during
1310 brcmf_fws_hanger_mark_suppressed(&fws
->hanger
, hslot
);
1317 brcmf_fws_txs_process(struct brcmf_fws_info
*fws
, u8 flags
, u32 hslot
,
1322 bool remove_from_hanger
= true;
1323 struct sk_buff
*skb
;
1324 struct brcmf_skbuff_cb
*skcb
;
1325 struct brcmf_fws_mac_descriptor
*entry
= NULL
;
1327 brcmf_dbg(DATA
, "flags %d\n", flags
);
1329 if (flags
== BRCMF_FWS_TXSTATUS_DISCARD
)
1330 fws
->stats
.txs_discard
++;
1331 else if (flags
== BRCMF_FWS_TXSTATUS_CORE_SUPPRESS
) {
1332 fws
->stats
.txs_supp_core
++;
1333 remove_from_hanger
= false;
1334 } else if (flags
== BRCMF_FWS_TXSTATUS_FW_PS_SUPPRESS
) {
1335 fws
->stats
.txs_supp_ps
++;
1336 remove_from_hanger
= false;
1337 } else if (flags
== BRCMF_FWS_TXSTATUS_FW_TOSSED
)
1338 fws
->stats
.txs_tossed
++;
1339 else if (flags
== BRCMF_FWS_TXSTATUS_HOST_TOSSED
)
1340 fws
->stats
.txs_host_tossed
++;
1342 brcmf_err("unexpected txstatus\n");
1344 ret
= brcmf_fws_hanger_poppkt(&fws
->hanger
, hslot
, &skb
,
1345 remove_from_hanger
);
1347 brcmf_err("no packet in hanger slot: hslot=%d\n", hslot
);
1351 skcb
= brcmf_skbcb(skb
);
1353 if (WARN_ON(!entry
)) {
1354 brcmu_pkt_buf_free_skb(skb
);
1357 entry
->transit_count
--;
1358 if (entry
->suppressed
&& entry
->suppr_transit_count
)
1359 entry
->suppr_transit_count
--;
1361 brcmf_dbg(DATA
, "%s flags %X htod %X\n", entry
->name
, skcb
->if_flags
,
1364 /* pick up the implicit credit from this packet */
1365 fifo
= brcmf_skb_htod_tag_get_field(skb
, FIFO
);
1366 if ((fws
->fcmode
== BRCMF_FWS_FCMODE_IMPLIED_CREDIT
) ||
1367 (brcmf_skb_if_flags_get_field(skb
, REQ_CREDIT
)) ||
1368 (flags
== BRCMF_FWS_TXSTATUS_HOST_TOSSED
)) {
1369 brcmf_fws_return_credits(fws
, fifo
, 1);
1370 brcmf_fws_schedule_deq(fws
);
1372 brcmf_fws_macdesc_return_req_credit(skb
);
1374 if (!remove_from_hanger
)
1375 ret
= brcmf_fws_txstatus_suppressed(fws
, fifo
, skb
, genbit
);
1377 if (remove_from_hanger
|| ret
)
1378 brcmf_txfinalize(fws
->drvr
, skb
, true);
1383 static int brcmf_fws_fifocreditback_indicate(struct brcmf_fws_info
*fws
,
1388 if (fws
->fcmode
!= BRCMF_FWS_FCMODE_EXPLICIT_CREDIT
) {
1389 brcmf_dbg(INFO
, "ignored\n");
1390 return BRCMF_FWS_RET_OK_NOSCHEDULE
;
1393 brcmf_dbg(DATA
, "enter: data %pM\n", data
);
1394 brcmf_fws_lock(fws
);
1395 for (i
= 0; i
< BRCMF_FWS_FIFO_COUNT
; i
++)
1396 brcmf_fws_return_credits(fws
, i
, data
[i
]);
1398 brcmf_dbg(DATA
, "map: credit %x delay %x\n", fws
->fifo_credit_map
,
1399 fws
->fifo_delay_map
);
1400 brcmf_fws_unlock(fws
);
1401 return BRCMF_FWS_RET_OK_SCHEDULE
;
1404 static int brcmf_fws_txstatus_indicate(struct brcmf_fws_info
*fws
, u8
*data
)
1412 fws
->stats
.txs_indicate
++;
1413 memcpy(&status_le
, data
, sizeof(status_le
));
1414 status
= le32_to_cpu(status_le
);
1415 flags
= brcmf_txstatus_get_field(status
, FLAGS
);
1416 hslot
= brcmf_txstatus_get_field(status
, HSLOT
);
1417 genbit
= brcmf_txstatus_get_field(status
, GENERATION
);
1419 brcmf_fws_lock(fws
);
1420 brcmf_fws_txs_process(fws
, flags
, hslot
, genbit
);
1421 brcmf_fws_unlock(fws
);
1422 return BRCMF_FWS_RET_OK_NOSCHEDULE
;
1425 static int brcmf_fws_dbg_seqnum_check(struct brcmf_fws_info
*fws
, u8
*data
)
1429 memcpy(×tamp
, &data
[2], sizeof(timestamp
));
1430 brcmf_dbg(CTL
, "received: seq %d, timestamp %d\n", data
[1],
1431 le32_to_cpu(timestamp
));
1435 static int brcmf_fws_notify_credit_map(struct brcmf_if
*ifp
,
1436 const struct brcmf_event_msg
*e
,
1439 struct brcmf_fws_info
*fws
= ifp
->drvr
->fws
;
1443 if (e
->datalen
< BRCMF_FWS_FIFO_COUNT
) {
1444 brcmf_err("event payload too small (%d)\n", e
->datalen
);
1447 if (fws
->creditmap_received
)
1450 fws
->creditmap_received
= true;
1452 brcmf_dbg(TRACE
, "enter: credits %pM\n", credits
);
1453 brcmf_fws_lock(fws
);
1454 for (i
= 0; i
< ARRAY_SIZE(fws
->fifo_credit
); i
++) {
1456 fws
->fifo_credit_map
|= 1 << i
;
1458 fws
->fifo_credit_map
&= ~(1 << i
);
1459 fws
->fifo_credit
[i
] = *credits
++;
1461 brcmf_fws_schedule_deq(fws
);
1462 brcmf_fws_unlock(fws
);
1466 static int brcmf_fws_notify_bcmc_credit_support(struct brcmf_if
*ifp
,
1467 const struct brcmf_event_msg
*e
,
1470 struct brcmf_fws_info
*fws
= ifp
->drvr
->fws
;
1472 brcmf_fws_lock(fws
);
1474 fws
->bcmc_credit_check
= true;
1475 brcmf_fws_unlock(fws
);
1479 int brcmf_fws_hdrpull(struct brcmf_pub
*drvr
, int ifidx
, s16 signal_len
,
1480 struct sk_buff
*skb
)
1482 struct brcmf_skb_reorder_data
*rd
;
1483 struct brcmf_fws_info
*fws
= drvr
->fws
;
1492 brcmf_dbg(HDRS
, "enter: ifidx %d, skblen %u, sig %d\n",
1493 ifidx
, skb
->len
, signal_len
);
1495 WARN_ON(signal_len
> skb
->len
);
1499 /* if flow control disabled, skip to packet data and leave */
1500 if (!fws
->fw_signals
) {
1501 skb_pull(skb
, signal_len
);
1505 fws
->stats
.header_pulls
++;
1506 data_len
= signal_len
;
1507 signal_data
= skb
->data
;
1509 status
= BRCMF_FWS_RET_OK_NOSCHEDULE
;
1510 while (data_len
> 0) {
1511 /* extract tlv info */
1512 type
= signal_data
[0];
1514 /* FILLER type is actually not a TLV, but
1515 * a single byte that can be skipped.
1517 if (type
== BRCMF_FWS_TYPE_FILLER
) {
1522 len
= signal_data
[1];
1523 data
= signal_data
+ 2;
1525 brcmf_dbg(HDRS
, "tlv type=%s (%d), len=%d (%d)\n",
1526 brcmf_fws_get_tlv_name(type
), type
, len
,
1527 brcmf_fws_get_tlv_len(fws
, type
));
1529 /* abort parsing when length invalid */
1530 if (data_len
< len
+ 2)
1533 if (len
< brcmf_fws_get_tlv_len(fws
, type
))
1536 err
= BRCMF_FWS_RET_OK_NOSCHEDULE
;
1538 case BRCMF_FWS_TYPE_COMP_TXSTATUS
:
1540 case BRCMF_FWS_TYPE_HOST_REORDER_RXPKTS
:
1541 rd
= (struct brcmf_skb_reorder_data
*)skb
->cb
;
1544 case BRCMF_FWS_TYPE_MACDESC_ADD
:
1545 case BRCMF_FWS_TYPE_MACDESC_DEL
:
1546 brcmf_fws_macdesc_indicate(fws
, type
, data
);
1548 case BRCMF_FWS_TYPE_MAC_OPEN
:
1549 case BRCMF_FWS_TYPE_MAC_CLOSE
:
1550 err
= brcmf_fws_macdesc_state_indicate(fws
, type
, data
);
1552 case BRCMF_FWS_TYPE_INTERFACE_OPEN
:
1553 case BRCMF_FWS_TYPE_INTERFACE_CLOSE
:
1554 err
= brcmf_fws_interface_state_indicate(fws
, type
,
1557 case BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT
:
1558 case BRCMF_FWS_TYPE_MAC_REQUEST_PACKET
:
1559 err
= brcmf_fws_request_indicate(fws
, type
, data
);
1561 case BRCMF_FWS_TYPE_TXSTATUS
:
1562 brcmf_fws_txstatus_indicate(fws
, data
);
1564 case BRCMF_FWS_TYPE_FIFO_CREDITBACK
:
1565 err
= brcmf_fws_fifocreditback_indicate(fws
, data
);
1567 case BRCMF_FWS_TYPE_RSSI
:
1568 brcmf_fws_rssi_indicate(fws
, *data
);
1570 case BRCMF_FWS_TYPE_TRANS_ID
:
1571 brcmf_fws_dbg_seqnum_check(fws
, data
);
1573 case BRCMF_FWS_TYPE_PKTTAG
:
1574 case BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP
:
1576 fws
->stats
.tlv_invalid_type
++;
1579 if (err
== BRCMF_FWS_RET_OK_SCHEDULE
)
1580 status
= BRCMF_FWS_RET_OK_SCHEDULE
;
1581 signal_data
+= len
+ 2;
1582 data_len
-= len
+ 2;
1586 fws
->stats
.tlv_parse_failed
++;
1588 if (status
== BRCMF_FWS_RET_OK_SCHEDULE
)
1589 brcmf_fws_schedule_deq(fws
);
1591 /* signalling processing result does
1592 * not affect the actual ethernet packet.
1594 skb_pull(skb
, signal_len
);
1596 /* this may be a signal-only packet
1599 fws
->stats
.header_only_pkt
++;
1604 static void brcmf_fws_precommit_skb(struct brcmf_fws_info
*fws
, int fifo
,
1607 struct brcmf_skbuff_cb
*skcb
= brcmf_skbcb(p
);
1608 struct brcmf_fws_mac_descriptor
*entry
= skcb
->mac
;
1611 brcmf_skb_if_flags_set_field(p
, TRANSMIT
, 1);
1612 brcmf_skb_htod_tag_set_field(p
, GENERATION
, entry
->generation
);
1613 flags
= BRCMF_FWS_HTOD_FLAG_PKTFROMHOST
;
1614 if (brcmf_skb_if_flags_get_field(p
, REQUESTED
)) {
1616 * Indicate that this packet is being sent in response to an
1617 * explicit request from the firmware side.
1619 flags
|= BRCMF_FWS_HTOD_FLAG_PKT_REQUESTED
;
1621 brcmf_skb_htod_tag_set_field(p
, FLAGS
, flags
);
1622 brcmf_fws_hdrpush(fws
, p
);
1625 static void brcmf_fws_rollback_toq(struct brcmf_fws_info
*fws
,
1626 struct sk_buff
*skb
, int fifo
)
1628 struct brcmf_fws_mac_descriptor
*entry
;
1629 struct sk_buff
*pktout
;
1633 entry
= brcmf_skbcb(skb
)->mac
;
1634 if (entry
->occupied
) {
1636 if (brcmf_skbcb(skb
)->state
== BRCMF_FWS_SKBSTATE_SUPPRESSED
)
1639 pktout
= brcmu_pktq_penq_head(&entry
->psq
, qidx
, skb
);
1640 if (pktout
== NULL
) {
1641 brcmf_err("%s queue %d full\n", entry
->name
, qidx
);
1645 brcmf_err("%s entry removed\n", entry
->name
);
1650 fws
->stats
.rollback_failed
++;
1651 hslot
= brcmf_skb_htod_tag_get_field(skb
, HSLOT
);
1652 brcmf_fws_txs_process(fws
, BRCMF_FWS_TXSTATUS_HOST_TOSSED
,
1655 fws
->stats
.rollback_success
++;
1656 brcmf_fws_return_credits(fws
, fifo
, 1);
1657 brcmf_fws_macdesc_return_req_credit(skb
);
1661 static int brcmf_fws_borrow_credit(struct brcmf_fws_info
*fws
)
1665 if (time_after(fws
->borrow_defer_timestamp
, jiffies
)) {
1666 fws
->fifo_credit_map
&= ~(1 << BRCMF_FWS_FIFO_AC_BE
);
1670 for (lender_ac
= 0; lender_ac
<= BRCMF_FWS_FIFO_AC_VO
; lender_ac
++) {
1671 if (fws
->fifo_credit
[lender_ac
]) {
1672 fws
->credits_borrowed
[lender_ac
]++;
1673 fws
->fifo_credit
[lender_ac
]--;
1674 if (fws
->fifo_credit
[lender_ac
] == 0)
1675 fws
->fifo_credit_map
&= ~(1 << lender_ac
);
1676 fws
->fifo_credit_map
|= (1 << BRCMF_FWS_FIFO_AC_BE
);
1677 brcmf_dbg(DATA
, "borrow credit from: %d\n", lender_ac
);
1681 fws
->fifo_credit_map
&= ~(1 << BRCMF_FWS_FIFO_AC_BE
);
1685 static int brcmf_fws_commit_skb(struct brcmf_fws_info
*fws
, int fifo
,
1686 struct sk_buff
*skb
)
1688 struct brcmf_skbuff_cb
*skcb
= brcmf_skbcb(skb
);
1689 struct brcmf_fws_mac_descriptor
*entry
;
1690 struct brcmf_bus
*bus
= fws
->drvr
->bus_if
;
1696 return PTR_ERR(entry
);
1698 brcmf_fws_precommit_skb(fws
, fifo
, skb
);
1699 entry
->transit_count
++;
1700 if (entry
->suppressed
)
1701 entry
->suppr_transit_count
++;
1702 brcmf_fws_unlock(fws
);
1703 rc
= brcmf_bus_txdata(bus
, skb
);
1704 brcmf_fws_lock(fws
);
1705 brcmf_dbg(DATA
, "%s flags %X htod %X bus_tx %d\n", entry
->name
,
1706 skcb
->if_flags
, skcb
->htod
, rc
);
1708 entry
->transit_count
--;
1709 if (entry
->suppressed
)
1710 entry
->suppr_transit_count
--;
1711 brcmf_proto_hdrpull(fws
->drvr
, false, &ifidx
, skb
);
1715 fws
->stats
.pkt2bus
++;
1716 fws
->stats
.send_pkts
[fifo
]++;
1717 if (brcmf_skb_if_flags_get_field(skb
, REQUESTED
))
1718 fws
->stats
.requested_sent
[fifo
]++;
1723 brcmf_fws_rollback_toq(fws
, skb
, fifo
);
1727 static int brcmf_fws_assign_htod(struct brcmf_fws_info
*fws
, struct sk_buff
*p
,
1730 struct brcmf_skbuff_cb
*skcb
= brcmf_skbcb(p
);
1733 hslot
= brcmf_fws_hanger_get_free_slot(&fws
->hanger
);
1734 brcmf_skb_htod_tag_set_field(p
, HSLOT
, hslot
);
1735 brcmf_skb_htod_tag_set_field(p
, FREERUN
, skcb
->mac
->seq
[fifo
]);
1736 brcmf_skb_htod_tag_set_field(p
, FIFO
, fifo
);
1737 rc
= brcmf_fws_hanger_pushpkt(&fws
->hanger
, p
, hslot
);
1739 skcb
->mac
->seq
[fifo
]++;
1741 fws
->stats
.generic_error
++;
1745 int brcmf_fws_process_skb(struct brcmf_if
*ifp
, struct sk_buff
*skb
)
1747 struct brcmf_pub
*drvr
= ifp
->drvr
;
1748 struct brcmf_fws_info
*fws
= drvr
->fws
;
1749 struct brcmf_skbuff_cb
*skcb
= brcmf_skbcb(skb
);
1750 struct ethhdr
*eh
= (struct ethhdr
*)(skb
->data
);
1751 int fifo
= BRCMF_FWS_FIFO_BCMC
;
1752 bool multicast
= is_multicast_ether_addr(eh
->h_dest
);
1753 bool pae
= eh
->h_proto
== htons(ETH_P_PAE
);
1755 brcmf_dbg(DATA
, "tx proto=0x%X\n", ntohs(eh
->h_proto
));
1756 /* determine the priority */
1758 skb
->priority
= cfg80211_classify8021d(skb
);
1760 drvr
->tx_multicast
+= !!multicast
;
1762 atomic_inc(&ifp
->pend_8021x_cnt
);
1764 /* set control buffer information */
1766 skcb
->state
= BRCMF_FWS_SKBSTATE_NEW
;
1767 brcmf_skb_if_flags_set_field(skb
, INDEX
, ifp
->ifidx
);
1769 fifo
= brcmf_fws_prio2fifo
[skb
->priority
];
1771 brcmf_fws_lock(fws
);
1772 if (fifo
!= BRCMF_FWS_FIFO_AC_BE
&& fifo
< BRCMF_FWS_FIFO_BCMC
)
1773 fws
->borrow_defer_timestamp
= jiffies
+
1774 BRCMF_FWS_BORROW_DEFER_PERIOD
;
1776 skcb
->mac
= brcmf_fws_macdesc_find(fws
, ifp
, eh
->h_dest
);
1777 brcmf_dbg(DATA
, "%s mac %pM multi %d fifo %d\n", skcb
->mac
->name
,
1778 eh
->h_dest
, multicast
, fifo
);
1779 if (!brcmf_fws_assign_htod(fws
, skb
, fifo
)) {
1780 brcmf_fws_enq(fws
, BRCMF_FWS_SKBSTATE_DELAYED
, fifo
, skb
);
1781 brcmf_fws_schedule_deq(fws
);
1783 brcmf_err("drop skb: no hanger slot\n");
1785 atomic_dec(&ifp
->pend_8021x_cnt
);
1786 if (waitqueue_active(&ifp
->pend_8021x_wait
))
1787 wake_up(&ifp
->pend_8021x_wait
);
1789 brcmu_pkt_buf_free_skb(skb
);
1791 brcmf_fws_unlock(fws
);
1795 void brcmf_fws_reset_interface(struct brcmf_if
*ifp
)
1797 struct brcmf_fws_mac_descriptor
*entry
= ifp
->fws_desc
;
1799 brcmf_dbg(TRACE
, "enter: idx=%d\n", ifp
->bssidx
);
1803 brcmf_fws_macdesc_init(entry
, ifp
->mac_addr
, ifp
->ifidx
);
1806 void brcmf_fws_add_interface(struct brcmf_if
*ifp
)
1808 struct brcmf_fws_info
*fws
= ifp
->drvr
->fws
;
1809 struct brcmf_fws_mac_descriptor
*entry
;
1814 entry
= &fws
->desc
.iface
[ifp
->ifidx
];
1815 ifp
->fws_desc
= entry
;
1816 brcmf_fws_macdesc_init(entry
, ifp
->mac_addr
, ifp
->ifidx
);
1817 brcmf_fws_macdesc_set_name(fws
, entry
);
1818 brcmu_pktq_init(&entry
->psq
, BRCMF_FWS_PSQ_PREC_COUNT
,
1820 brcmf_dbg(TRACE
, "added %s\n", entry
->name
);
1823 void brcmf_fws_del_interface(struct brcmf_if
*ifp
)
1825 struct brcmf_fws_mac_descriptor
*entry
= ifp
->fws_desc
;
1830 brcmf_fws_lock(ifp
->drvr
->fws
);
1831 ifp
->fws_desc
= NULL
;
1832 brcmf_dbg(TRACE
, "deleting %s\n", entry
->name
);
1833 brcmf_fws_macdesc_deinit(entry
);
1834 brcmf_fws_cleanup(ifp
->drvr
->fws
, ifp
->ifidx
);
1835 brcmf_fws_unlock(ifp
->drvr
->fws
);
1838 static void brcmf_fws_dequeue_worker(struct work_struct
*worker
)
1840 struct brcmf_fws_info
*fws
;
1841 struct brcmf_pub
*drvr
;
1842 struct sk_buff
*skb
;
1848 fws
= container_of(worker
, struct brcmf_fws_info
, fws_dequeue_work
);
1851 brcmf_fws_lock(fws
);
1852 for (fifo
= BRCMF_FWS_FIFO_BCMC
; fifo
>= 0 && !fws
->bus_flow_blocked
;
1854 if (!brcmf_fws_fc_active(fws
)) {
1855 while ((skb
= brcmf_fws_deq(fws
, fifo
)) != NULL
) {
1856 hslot
= brcmf_skb_htod_tag_get_field(skb
,
1858 brcmf_fws_hanger_poppkt(&fws
->hanger
, hslot
,
1860 ifidx
= brcmf_skb_if_flags_get_field(skb
,
1862 brcmf_proto_hdrpush(drvr
, ifidx
, 0, skb
);
1863 /* Use bus module to send data frame */
1864 brcmf_fws_unlock(fws
);
1865 ret
= brcmf_bus_txdata(drvr
->bus_if
, skb
);
1866 brcmf_fws_lock(fws
);
1868 brcmf_txfinalize(drvr
, skb
, false);
1869 if (fws
->bus_flow_blocked
)
1874 while ((fws
->fifo_credit
[fifo
]) || ((!fws
->bcmc_credit_check
) &&
1875 (fifo
== BRCMF_FWS_FIFO_BCMC
))) {
1876 skb
= brcmf_fws_deq(fws
, fifo
);
1879 fws
->fifo_credit
[fifo
]--;
1880 if (brcmf_fws_commit_skb(fws
, fifo
, skb
))
1882 if (fws
->bus_flow_blocked
)
1885 if ((fifo
== BRCMF_FWS_FIFO_AC_BE
) &&
1886 (fws
->fifo_credit
[fifo
] == 0) &&
1887 (!fws
->bus_flow_blocked
)) {
1888 while (brcmf_fws_borrow_credit(fws
) == 0) {
1889 skb
= brcmf_fws_deq(fws
, fifo
);
1891 brcmf_fws_return_credits(fws
, fifo
, 1);
1894 if (brcmf_fws_commit_skb(fws
, fifo
, skb
))
1896 if (fws
->bus_flow_blocked
)
1901 brcmf_fws_unlock(fws
);
1904 int brcmf_fws_init(struct brcmf_pub
*drvr
)
1906 struct brcmf_fws_info
*fws
;
1907 u32 tlv
= BRCMF_FWS_FLAGS_RSSI_SIGNALS
;
1910 drvr
->fws
= kzalloc(sizeof(*(drvr
->fws
)), GFP_KERNEL
);
1918 spin_lock_init(&fws
->spinlock
);
1920 /* set linkage back */
1922 fws
->fcmode
= fcmode
;
1924 fws
->fws_wq
= create_singlethread_workqueue("brcmf_fws_wq");
1925 if (fws
->fws_wq
== NULL
) {
1926 brcmf_err("workqueue creation failed\n");
1930 INIT_WORK(&fws
->fws_dequeue_work
, brcmf_fws_dequeue_worker
);
1932 /* enable firmware signalling if fcmode active */
1933 if (fws
->fcmode
!= BRCMF_FWS_FCMODE_NONE
)
1934 tlv
|= BRCMF_FWS_FLAGS_XONXOFF_SIGNALS
|
1935 BRCMF_FWS_FLAGS_CREDIT_STATUS_SIGNALS
|
1936 BRCMF_FWS_FLAGS_HOST_PROPTXSTATUS_ACTIVE
|
1937 BRCMF_FWS_FLAGS_HOST_RXREORDER_ACTIVE
;
1939 rc
= brcmf_fweh_register(drvr
, BRCMF_E_FIFO_CREDIT_MAP
,
1940 brcmf_fws_notify_credit_map
);
1942 brcmf_err("register credit map handler failed\n");
1945 rc
= brcmf_fweh_register(drvr
, BRCMF_E_BCMC_CREDIT_SUPPORT
,
1946 brcmf_fws_notify_bcmc_credit_support
);
1948 brcmf_err("register bcmc credit handler failed\n");
1949 brcmf_fweh_unregister(drvr
, BRCMF_E_FIFO_CREDIT_MAP
);
1953 /* Setting the iovar may fail if feature is unsupported
1954 * so leave the rc as is so driver initialization can
1955 * continue. Set mode back to none indicating not enabled.
1957 fws
->fw_signals
= true;
1958 if (brcmf_fil_iovar_int_set(drvr
->iflist
[0], "tlv", tlv
)) {
1959 brcmf_err("failed to set bdcv2 tlv signaling\n");
1960 fws
->fcmode
= BRCMF_FWS_FCMODE_NONE
;
1961 fws
->fw_signals
= false;
1964 if (brcmf_fil_iovar_int_set(drvr
->iflist
[0], "ampdu_hostreorder", 1))
1965 brcmf_dbg(INFO
, "enabling AMPDU host-reorder failed\n");
1967 brcmf_fws_hanger_init(&fws
->hanger
);
1968 brcmf_fws_macdesc_init(&fws
->desc
.other
, NULL
, 0);
1969 brcmf_fws_macdesc_set_name(fws
, &fws
->desc
.other
);
1970 brcmu_pktq_init(&fws
->desc
.other
.psq
, BRCMF_FWS_PSQ_PREC_COUNT
,
1973 /* create debugfs file for statistics */
1974 brcmf_debugfs_create_fws_stats(drvr
, &fws
->stats
);
1976 brcmf_dbg(INFO
, "%s bdcv2 tlv signaling [%x]\n",
1977 fws
->fw_signals
? "enabled" : "disabled", tlv
);
1981 brcmf_fws_deinit(drvr
);
1985 void brcmf_fws_deinit(struct brcmf_pub
*drvr
)
1987 struct brcmf_fws_info
*fws
= drvr
->fws
;
1992 if (drvr
->fws
->fws_wq
)
1993 destroy_workqueue(drvr
->fws
->fws_wq
);
1996 brcmf_fws_lock(fws
);
1997 brcmf_fws_cleanup(fws
, -1);
1999 brcmf_fws_unlock(fws
);
2001 /* free top structure */
2005 bool brcmf_fws_fc_active(struct brcmf_fws_info
*fws
)
2007 if (!fws
->creditmap_received
)
2010 return fws
->fcmode
!= BRCMF_FWS_FCMODE_NONE
;
2013 void brcmf_fws_bustxfail(struct brcmf_fws_info
*fws
, struct sk_buff
*skb
)
2017 if (brcmf_skbcb(skb
)->state
== BRCMF_FWS_SKBSTATE_TIM
) {
2018 brcmu_pkt_buf_free_skb(skb
);
2021 brcmf_fws_lock(fws
);
2022 hslot
= brcmf_skb_htod_tag_get_field(skb
, HSLOT
);
2023 brcmf_fws_txs_process(fws
, BRCMF_FWS_TXSTATUS_HOST_TOSSED
, hslot
, 0);
2024 brcmf_fws_unlock(fws
);
2027 void brcmf_fws_bus_blocked(struct brcmf_pub
*drvr
, bool flow_blocked
)
2029 struct brcmf_fws_info
*fws
= drvr
->fws
;
2031 fws
->bus_flow_blocked
= flow_blocked
;
2033 brcmf_fws_schedule_deq(fws
);
2035 fws
->stats
.bus_flow_block
++;