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>
33 #include "fwil_types.h"
37 #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
109 static const char *brcmf_fws_get_tlv_name(enum brcmf_fws_tlv_type id
)
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
;
120 static const char *brcmf_fws_get_tlv_name(enum brcmf_fws_tlv_type id
)
127 * The PKTTAG tlv has additional bytes when firmware-signalling
128 * mode has REUSESEQ flag set.
130 #define BRCMF_FWS_TYPE_SEQ_LEN 2
133 * flags used to enable tlv signalling from firmware.
135 #define BRCMF_FWS_FLAGS_RSSI_SIGNALS 0x0001
136 #define BRCMF_FWS_FLAGS_XONXOFF_SIGNALS 0x0002
137 #define BRCMF_FWS_FLAGS_CREDIT_STATUS_SIGNALS 0x0004
138 #define BRCMF_FWS_FLAGS_HOST_PROPTXSTATUS_ACTIVE 0x0008
139 #define BRCMF_FWS_FLAGS_PSQ_GENERATIONFSM_ENABLE 0x0010
140 #define BRCMF_FWS_FLAGS_PSQ_ZERO_BUFFER_ENABLE 0x0020
141 #define BRCMF_FWS_FLAGS_HOST_RXREORDER_ACTIVE 0x0040
143 #define BRCMF_FWS_MAC_DESC_TABLE_SIZE 32
144 #define BRCMF_FWS_MAC_DESC_ID_INVALID 0xff
146 #define BRCMF_FWS_HOSTIF_FLOWSTATE_OFF 0
147 #define BRCMF_FWS_HOSTIF_FLOWSTATE_ON 1
148 #define BRCMF_FWS_FLOWCONTROL_HIWATER 128
149 #define BRCMF_FWS_FLOWCONTROL_LOWATER 64
151 #define BRCMF_FWS_PSQ_PREC_COUNT ((BRCMF_FWS_FIFO_COUNT + 1) * 2)
152 #define BRCMF_FWS_PSQ_LEN 256
154 #define BRCMF_FWS_HTOD_FLAG_PKTFROMHOST 0x01
155 #define BRCMF_FWS_HTOD_FLAG_PKT_REQUESTED 0x02
157 #define BRCMF_FWS_RET_OK_NOSCHEDULE 0
158 #define BRCMF_FWS_RET_OK_SCHEDULE 1
160 #define BRCMF_FWS_MODE_REUSESEQ_SHIFT 3 /* seq reuse */
161 #define BRCMF_FWS_MODE_SET_REUSESEQ(x, val) ((x) = \
162 ((x) & ~(1 << BRCMF_FWS_MODE_REUSESEQ_SHIFT)) | \
163 (((val) & 1) << BRCMF_FWS_MODE_REUSESEQ_SHIFT))
164 #define BRCMF_FWS_MODE_GET_REUSESEQ(x) \
165 (((x) >> BRCMF_FWS_MODE_REUSESEQ_SHIFT) & 1)
168 * enum brcmf_fws_skb_state - indicates processing state of skb.
170 * @BRCMF_FWS_SKBSTATE_NEW: sk_buff is newly arrived in the driver.
171 * @BRCMF_FWS_SKBSTATE_DELAYED: sk_buff had to wait on queue.
172 * @BRCMF_FWS_SKBSTATE_SUPPRESSED: sk_buff has been suppressed by firmware.
173 * @BRCMF_FWS_SKBSTATE_TIM: allocated for TIM update info.
175 enum brcmf_fws_skb_state
{
176 BRCMF_FWS_SKBSTATE_NEW
,
177 BRCMF_FWS_SKBSTATE_DELAYED
,
178 BRCMF_FWS_SKBSTATE_SUPPRESSED
,
179 BRCMF_FWS_SKBSTATE_TIM
183 * struct brcmf_skbuff_cb - control buffer associated with skbuff.
185 * @bus_flags: 2 bytes reserved for bus specific parameters
186 * @if_flags: holds interface index and packet related flags.
187 * @htod: host to device packet identifier (used in PKTTAG tlv).
188 * @htod_seq: this 16-bit is original seq number for every suppress packet.
189 * @state: transmit state of the packet.
190 * @mac: descriptor related to destination for this packet.
192 * This information is stored in control buffer struct sk_buff::cb, which
193 * provides 48 bytes of storage so this structure should not exceed that.
195 struct brcmf_skbuff_cb
{
200 enum brcmf_fws_skb_state state
;
201 struct brcmf_fws_mac_descriptor
*mac
;
205 * macro casting skbuff control buffer to struct brcmf_skbuff_cb.
207 #define brcmf_skbcb(skb) ((struct brcmf_skbuff_cb *)((skb)->cb))
210 * sk_buff control if flags
212 * b[11] - packet sent upon firmware request.
213 * b[10] - packet only contains signalling data.
214 * b[9] - packet is a tx packet.
215 * b[8] - packet used requested credit
216 * b[7] - interface in AP mode.
217 * b[3:0] - interface index.
219 #define BRCMF_SKB_IF_FLAGS_REQUESTED_MASK 0x0800
220 #define BRCMF_SKB_IF_FLAGS_REQUESTED_SHIFT 11
221 #define BRCMF_SKB_IF_FLAGS_SIGNAL_ONLY_MASK 0x0400
222 #define BRCMF_SKB_IF_FLAGS_SIGNAL_ONLY_SHIFT 10
223 #define BRCMF_SKB_IF_FLAGS_TRANSMIT_MASK 0x0200
224 #define BRCMF_SKB_IF_FLAGS_TRANSMIT_SHIFT 9
225 #define BRCMF_SKB_IF_FLAGS_REQ_CREDIT_MASK 0x0100
226 #define BRCMF_SKB_IF_FLAGS_REQ_CREDIT_SHIFT 8
227 #define BRCMF_SKB_IF_FLAGS_IF_AP_MASK 0x0080
228 #define BRCMF_SKB_IF_FLAGS_IF_AP_SHIFT 7
229 #define BRCMF_SKB_IF_FLAGS_INDEX_MASK 0x000f
230 #define BRCMF_SKB_IF_FLAGS_INDEX_SHIFT 0
232 #define brcmf_skb_if_flags_set_field(skb, field, value) \
233 brcmu_maskset16(&(brcmf_skbcb(skb)->if_flags), \
234 BRCMF_SKB_IF_FLAGS_ ## field ## _MASK, \
235 BRCMF_SKB_IF_FLAGS_ ## field ## _SHIFT, (value))
236 #define brcmf_skb_if_flags_get_field(skb, field) \
237 brcmu_maskget16(brcmf_skbcb(skb)->if_flags, \
238 BRCMF_SKB_IF_FLAGS_ ## field ## _MASK, \
239 BRCMF_SKB_IF_FLAGS_ ## field ## _SHIFT)
242 * sk_buff control packet identifier
244 * 32-bit packet identifier used in PKTTAG tlv from host to dongle.
246 * - Generated at the host (e.g. dhd)
247 * - Seen as a generic sequence number by firmware except for the flags field.
249 * Generation : b[31] => generation number for this packet [host->fw]
250 * OR, current generation number [fw->host]
251 * Flags : b[30:27] => command, status flags
252 * FIFO-AC : b[26:24] => AC-FIFO id
253 * h-slot : b[23:8] => hanger-slot
254 * freerun : b[7:0] => A free running counter
256 #define BRCMF_SKB_HTOD_TAG_GENERATION_MASK 0x80000000
257 #define BRCMF_SKB_HTOD_TAG_GENERATION_SHIFT 31
258 #define BRCMF_SKB_HTOD_TAG_FLAGS_MASK 0x78000000
259 #define BRCMF_SKB_HTOD_TAG_FLAGS_SHIFT 27
260 #define BRCMF_SKB_HTOD_TAG_FIFO_MASK 0x07000000
261 #define BRCMF_SKB_HTOD_TAG_FIFO_SHIFT 24
262 #define BRCMF_SKB_HTOD_TAG_HSLOT_MASK 0x00ffff00
263 #define BRCMF_SKB_HTOD_TAG_HSLOT_SHIFT 8
264 #define BRCMF_SKB_HTOD_TAG_FREERUN_MASK 0x000000ff
265 #define BRCMF_SKB_HTOD_TAG_FREERUN_SHIFT 0
267 #define brcmf_skb_htod_tag_set_field(skb, field, value) \
268 brcmu_maskset32(&(brcmf_skbcb(skb)->htod), \
269 BRCMF_SKB_HTOD_TAG_ ## field ## _MASK, \
270 BRCMF_SKB_HTOD_TAG_ ## field ## _SHIFT, (value))
271 #define brcmf_skb_htod_tag_get_field(skb, field) \
272 brcmu_maskget32(brcmf_skbcb(skb)->htod, \
273 BRCMF_SKB_HTOD_TAG_ ## field ## _MASK, \
274 BRCMF_SKB_HTOD_TAG_ ## field ## _SHIFT)
276 #define BRCMF_SKB_HTOD_SEQ_FROMFW_MASK 0x2000
277 #define BRCMF_SKB_HTOD_SEQ_FROMFW_SHIFT 13
278 #define BRCMF_SKB_HTOD_SEQ_FROMDRV_MASK 0x1000
279 #define BRCMF_SKB_HTOD_SEQ_FROMDRV_SHIFT 12
280 #define BRCMF_SKB_HTOD_SEQ_NR_MASK 0x0fff
281 #define BRCMF_SKB_HTOD_SEQ_NR_SHIFT 0
283 #define brcmf_skb_htod_seq_set_field(skb, field, value) \
284 brcmu_maskset16(&(brcmf_skbcb(skb)->htod_seq), \
285 BRCMF_SKB_HTOD_SEQ_ ## field ## _MASK, \
286 BRCMF_SKB_HTOD_SEQ_ ## field ## _SHIFT, (value))
287 #define brcmf_skb_htod_seq_get_field(skb, field) \
288 brcmu_maskget16(brcmf_skbcb(skb)->htod_seq, \
289 BRCMF_SKB_HTOD_SEQ_ ## field ## _MASK, \
290 BRCMF_SKB_HTOD_SEQ_ ## field ## _SHIFT)
292 #define BRCMF_FWS_TXSTAT_GENERATION_MASK 0x80000000
293 #define BRCMF_FWS_TXSTAT_GENERATION_SHIFT 31
294 #define BRCMF_FWS_TXSTAT_FLAGS_MASK 0x78000000
295 #define BRCMF_FWS_TXSTAT_FLAGS_SHIFT 27
296 #define BRCMF_FWS_TXSTAT_FIFO_MASK 0x07000000
297 #define BRCMF_FWS_TXSTAT_FIFO_SHIFT 24
298 #define BRCMF_FWS_TXSTAT_HSLOT_MASK 0x00FFFF00
299 #define BRCMF_FWS_TXSTAT_HSLOT_SHIFT 8
300 #define BRCMF_FWS_TXSTAT_FREERUN_MASK 0x000000FF
301 #define BRCMF_FWS_TXSTAT_FREERUN_SHIFT 0
303 #define brcmf_txstatus_get_field(txs, field) \
304 brcmu_maskget32(txs, BRCMF_FWS_TXSTAT_ ## field ## _MASK, \
305 BRCMF_FWS_TXSTAT_ ## field ## _SHIFT)
307 /* How long to defer borrowing in jiffies */
308 #define BRCMF_FWS_BORROW_DEFER_PERIOD (HZ / 10)
311 * enum brcmf_fws_fifo - fifo indices used by dongle firmware.
313 * @BRCMF_FWS_FIFO_FIRST: first fifo, ie. background.
314 * @BRCMF_FWS_FIFO_AC_BK: fifo for background traffic.
315 * @BRCMF_FWS_FIFO_AC_BE: fifo for best-effort traffic.
316 * @BRCMF_FWS_FIFO_AC_VI: fifo for video traffic.
317 * @BRCMF_FWS_FIFO_AC_VO: fifo for voice traffic.
318 * @BRCMF_FWS_FIFO_BCMC: fifo for broadcast/multicast (AP only).
319 * @BRCMF_FWS_FIFO_ATIM: fifo for ATIM (AP only).
320 * @BRCMF_FWS_FIFO_COUNT: number of fifos.
322 enum brcmf_fws_fifo
{
323 BRCMF_FWS_FIFO_FIRST
,
324 BRCMF_FWS_FIFO_AC_BK
= BRCMF_FWS_FIFO_FIRST
,
325 BRCMF_FWS_FIFO_AC_BE
,
326 BRCMF_FWS_FIFO_AC_VI
,
327 BRCMF_FWS_FIFO_AC_VO
,
334 * enum brcmf_fws_txstatus - txstatus flag values.
336 * @BRCMF_FWS_TXSTATUS_DISCARD:
337 * host is free to discard the packet.
338 * @BRCMF_FWS_TXSTATUS_CORE_SUPPRESS:
339 * 802.11 core suppressed the packet.
340 * @BRCMF_FWS_TXSTATUS_FW_PS_SUPPRESS:
341 * firmware suppress the packet as device is already in PS mode.
342 * @BRCMF_FWS_TXSTATUS_FW_TOSSED:
343 * firmware tossed the packet.
344 * @BRCMF_FWS_TXSTATUS_HOST_TOSSED:
345 * host tossed the packet.
347 enum brcmf_fws_txstatus
{
348 BRCMF_FWS_TXSTATUS_DISCARD
,
349 BRCMF_FWS_TXSTATUS_CORE_SUPPRESS
,
350 BRCMF_FWS_TXSTATUS_FW_PS_SUPPRESS
,
351 BRCMF_FWS_TXSTATUS_FW_TOSSED
,
352 BRCMF_FWS_TXSTATUS_HOST_TOSSED
355 enum brcmf_fws_fcmode
{
356 BRCMF_FWS_FCMODE_NONE
,
357 BRCMF_FWS_FCMODE_IMPLIED_CREDIT
,
358 BRCMF_FWS_FCMODE_EXPLICIT_CREDIT
361 enum brcmf_fws_mac_desc_state
{
362 BRCMF_FWS_STATE_OPEN
= 1,
363 BRCMF_FWS_STATE_CLOSE
367 * struct brcmf_fws_mac_descriptor - firmware signalling data per node/interface
369 * @occupied: slot is in use.
370 * @mac_handle: handle for mac entry determined by firmware.
371 * @interface_id: interface index.
372 * @state: current state.
373 * @suppressed: mac entry is suppressed.
374 * @generation: generation bit.
375 * @ac_bitmap: ac queue bitmap.
376 * @requested_credit: credits requested by firmware.
377 * @ea: ethernet address.
378 * @seq: per-node free-running sequence.
379 * @psq: power-save queue.
380 * @transit_count: packet in transit to firmware.
382 struct brcmf_fws_mac_descriptor
{
394 u8 seq
[BRCMF_FWS_FIFO_COUNT
];
397 int suppr_transit_count
;
398 bool send_tim_signal
;
399 u8 traffic_pending_bmp
;
400 u8 traffic_lastreported_bmp
;
403 #define BRCMF_FWS_HANGER_MAXITEMS 1024
406 * enum brcmf_fws_hanger_item_state - state of hanger item.
408 * @BRCMF_FWS_HANGER_ITEM_STATE_FREE: item is free for use.
409 * @BRCMF_FWS_HANGER_ITEM_STATE_INUSE: item is in use.
410 * @BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED: item was suppressed.
412 enum brcmf_fws_hanger_item_state
{
413 BRCMF_FWS_HANGER_ITEM_STATE_FREE
= 1,
414 BRCMF_FWS_HANGER_ITEM_STATE_INUSE
,
415 BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED
420 * struct brcmf_fws_hanger_item - single entry for tx pending packet.
422 * @state: entry is either free or occupied.
423 * @pkt: packet itself.
425 struct brcmf_fws_hanger_item
{
426 enum brcmf_fws_hanger_item_state state
;
431 * struct brcmf_fws_hanger - holds packets awaiting firmware txstatus.
433 * @pushed: packets pushed to await txstatus.
434 * @popped: packets popped upon handling txstatus.
435 * @failed_to_push: packets that could not be pushed.
436 * @failed_to_pop: packets that could not be popped.
437 * @failed_slotfind: packets for which failed to find an entry.
438 * @slot_pos: last returned item index for a free entry.
439 * @items: array of hanger items.
441 struct brcmf_fws_hanger
{
448 struct brcmf_fws_hanger_item items
[BRCMF_FWS_HANGER_MAXITEMS
];
451 struct brcmf_fws_macdesc_table
{
452 struct brcmf_fws_mac_descriptor nodes
[BRCMF_FWS_MAC_DESC_TABLE_SIZE
];
453 struct brcmf_fws_mac_descriptor iface
[BRCMF_MAX_IFS
];
454 struct brcmf_fws_mac_descriptor other
;
457 struct brcmf_fws_info
{
458 struct brcmf_pub
*drvr
;
461 struct brcmf_fws_stats stats
;
462 struct brcmf_fws_hanger hanger
;
463 enum brcmf_fws_fcmode fcmode
;
465 bool bcmc_credit_check
;
466 struct brcmf_fws_macdesc_table desc
;
467 struct workqueue_struct
*fws_wq
;
468 struct work_struct fws_dequeue_work
;
469 u32 fifo_enqpkt
[BRCMF_FWS_FIFO_COUNT
];
470 int fifo_credit
[BRCMF_FWS_FIFO_COUNT
];
471 int credits_borrowed
[BRCMF_FWS_FIFO_AC_VO
+ 1];
472 int deq_node_pos
[BRCMF_FWS_FIFO_COUNT
];
475 unsigned long borrow_defer_timestamp
;
476 bool bus_flow_blocked
;
477 bool creditmap_received
;
482 * brcmf_fws_prio2fifo - mapping from 802.1d priority to firmware fifo index.
484 static const int brcmf_fws_prio2fifo
[] = {
485 BRCMF_FWS_FIFO_AC_BE
,
486 BRCMF_FWS_FIFO_AC_BK
,
487 BRCMF_FWS_FIFO_AC_BK
,
488 BRCMF_FWS_FIFO_AC_BE
,
489 BRCMF_FWS_FIFO_AC_VI
,
490 BRCMF_FWS_FIFO_AC_VI
,
491 BRCMF_FWS_FIFO_AC_VO
,
496 module_param(fcmode
, int, S_IRUSR
);
497 MODULE_PARM_DESC(fcmode
, "mode of firmware signalled flow control");
499 #define BRCMF_FWS_TLV_DEF(name, id, len) \
500 case BRCMF_FWS_TYPE_ ## name: \
504 * brcmf_fws_get_tlv_len() - returns defined length for given tlv id.
506 * @fws: firmware-signalling information.
507 * @id: identifier of the TLV.
509 * Return: the specified length for the given TLV; Otherwise -EINVAL.
511 static int brcmf_fws_get_tlv_len(struct brcmf_fws_info
*fws
,
512 enum brcmf_fws_tlv_type id
)
515 BRCMF_FWS_TLV_DEFLIST
517 fws
->stats
.tlv_invalid_type
++;
522 #undef BRCMF_FWS_TLV_DEF
524 static void brcmf_fws_lock(struct brcmf_fws_info
*fws
)
525 __acquires(&fws
->spinlock
)
527 spin_lock_irqsave(&fws
->spinlock
, fws
->flags
);
530 static void brcmf_fws_unlock(struct brcmf_fws_info
*fws
)
531 __releases(&fws
->spinlock
)
533 spin_unlock_irqrestore(&fws
->spinlock
, fws
->flags
);
536 static bool brcmf_fws_ifidx_match(struct sk_buff
*skb
, void *arg
)
538 u32 ifidx
= brcmf_skb_if_flags_get_field(skb
, INDEX
);
539 return ifidx
== *(int *)arg
;
542 static void brcmf_fws_psq_flush(struct brcmf_fws_info
*fws
, struct pktq
*q
,
545 bool (*matchfn
)(struct sk_buff
*, void *) = NULL
;
550 matchfn
= brcmf_fws_ifidx_match
;
551 for (prec
= 0; prec
< q
->num_prec
; prec
++) {
552 skb
= brcmu_pktq_pdeq_match(q
, prec
, matchfn
, &ifidx
);
554 brcmu_pkt_buf_free_skb(skb
);
555 skb
= brcmu_pktq_pdeq_match(q
, prec
, matchfn
, &ifidx
);
560 static void brcmf_fws_hanger_init(struct brcmf_fws_hanger
*hanger
)
564 memset(hanger
, 0, sizeof(*hanger
));
565 for (i
= 0; i
< ARRAY_SIZE(hanger
->items
); i
++)
566 hanger
->items
[i
].state
= BRCMF_FWS_HANGER_ITEM_STATE_FREE
;
569 static u32
brcmf_fws_hanger_get_free_slot(struct brcmf_fws_hanger
*h
)
573 i
= (h
->slot_pos
+ 1) % BRCMF_FWS_HANGER_MAXITEMS
;
575 while (i
!= h
->slot_pos
) {
576 if (h
->items
[i
].state
== BRCMF_FWS_HANGER_ITEM_STATE_FREE
) {
581 if (i
== BRCMF_FWS_HANGER_MAXITEMS
)
584 brcmf_err("all slots occupied\n");
585 h
->failed_slotfind
++;
586 i
= BRCMF_FWS_HANGER_MAXITEMS
;
591 static int brcmf_fws_hanger_pushpkt(struct brcmf_fws_hanger
*h
,
592 struct sk_buff
*pkt
, u32 slot_id
)
594 if (slot_id
>= BRCMF_FWS_HANGER_MAXITEMS
)
597 if (h
->items
[slot_id
].state
!= BRCMF_FWS_HANGER_ITEM_STATE_FREE
) {
598 brcmf_err("slot is not free\n");
603 h
->items
[slot_id
].state
= BRCMF_FWS_HANGER_ITEM_STATE_INUSE
;
604 h
->items
[slot_id
].pkt
= pkt
;
609 static int brcmf_fws_hanger_poppkt(struct brcmf_fws_hanger
*h
,
610 u32 slot_id
, struct sk_buff
**pktout
,
613 if (slot_id
>= BRCMF_FWS_HANGER_MAXITEMS
)
616 if (h
->items
[slot_id
].state
== BRCMF_FWS_HANGER_ITEM_STATE_FREE
) {
617 brcmf_err("entry not in use\n");
622 *pktout
= h
->items
[slot_id
].pkt
;
624 h
->items
[slot_id
].state
= BRCMF_FWS_HANGER_ITEM_STATE_FREE
;
625 h
->items
[slot_id
].pkt
= NULL
;
631 static int brcmf_fws_hanger_mark_suppressed(struct brcmf_fws_hanger
*h
,
634 if (slot_id
>= BRCMF_FWS_HANGER_MAXITEMS
)
637 if (h
->items
[slot_id
].state
== BRCMF_FWS_HANGER_ITEM_STATE_FREE
) {
638 brcmf_err("entry not in use\n");
642 h
->items
[slot_id
].state
= BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED
;
646 static void brcmf_fws_hanger_cleanup(struct brcmf_fws_info
*fws
,
647 bool (*fn
)(struct sk_buff
*, void *),
650 struct brcmf_fws_hanger
*h
= &fws
->hanger
;
653 enum brcmf_fws_hanger_item_state s
;
655 for (i
= 0; i
< ARRAY_SIZE(h
->items
); i
++) {
656 s
= h
->items
[i
].state
;
657 if (s
== BRCMF_FWS_HANGER_ITEM_STATE_INUSE
||
658 s
== BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED
) {
659 skb
= h
->items
[i
].pkt
;
660 if (fn
== NULL
|| fn(skb
, &ifidx
)) {
661 /* suppress packets freed from psq */
662 if (s
== BRCMF_FWS_HANGER_ITEM_STATE_INUSE
)
663 brcmu_pkt_buf_free_skb(skb
);
665 BRCMF_FWS_HANGER_ITEM_STATE_FREE
;
671 static void brcmf_fws_macdesc_set_name(struct brcmf_fws_info
*fws
,
672 struct brcmf_fws_mac_descriptor
*desc
)
674 if (desc
== &fws
->desc
.other
)
675 strlcpy(desc
->name
, "MAC-OTHER", sizeof(desc
->name
));
676 else if (desc
->mac_handle
)
677 scnprintf(desc
->name
, sizeof(desc
->name
), "MAC-%d:%d",
678 desc
->mac_handle
, desc
->interface_id
);
680 scnprintf(desc
->name
, sizeof(desc
->name
), "MACIF:%d",
684 static void brcmf_fws_macdesc_init(struct brcmf_fws_mac_descriptor
*desc
,
688 "enter: desc %p ea=%pM, ifidx=%u\n", desc
, addr
, ifidx
);
690 desc
->state
= BRCMF_FWS_STATE_OPEN
;
691 desc
->requested_credit
= 0;
692 desc
->requested_packet
= 0;
693 /* depending on use may need ifp->bssidx instead */
694 desc
->interface_id
= ifidx
;
695 desc
->ac_bitmap
= 0xff; /* update this when handling APSD */
697 memcpy(&desc
->ea
[0], addr
, ETH_ALEN
);
701 void brcmf_fws_macdesc_deinit(struct brcmf_fws_mac_descriptor
*desc
)
704 "enter: ea=%pM, ifidx=%u\n", desc
->ea
, desc
->interface_id
);
706 desc
->state
= BRCMF_FWS_STATE_CLOSE
;
707 desc
->requested_credit
= 0;
708 desc
->requested_packet
= 0;
711 static struct brcmf_fws_mac_descriptor
*
712 brcmf_fws_macdesc_lookup(struct brcmf_fws_info
*fws
, u8
*ea
)
714 struct brcmf_fws_mac_descriptor
*entry
;
718 return ERR_PTR(-EINVAL
);
720 entry
= &fws
->desc
.nodes
[0];
721 for (i
= 0; i
< ARRAY_SIZE(fws
->desc
.nodes
); i
++) {
722 if (entry
->occupied
&& !memcmp(entry
->ea
, ea
, ETH_ALEN
))
727 return ERR_PTR(-ENOENT
);
730 static struct brcmf_fws_mac_descriptor
*
731 brcmf_fws_macdesc_find(struct brcmf_fws_info
*fws
, struct brcmf_if
*ifp
, u8
*da
)
733 struct brcmf_fws_mac_descriptor
*entry
= &fws
->desc
.other
;
736 multicast
= is_multicast_ether_addr(da
);
738 /* Multicast destination, STA and P2P clients get the interface entry.
739 * STA/GC gets the Mac Entry for TDLS destinations, TDLS destinations
740 * have their own entry.
742 if (multicast
&& ifp
->fws_desc
) {
743 entry
= ifp
->fws_desc
;
747 entry
= brcmf_fws_macdesc_lookup(fws
, da
);
749 entry
= ifp
->fws_desc
;
755 static bool brcmf_fws_macdesc_closed(struct brcmf_fws_info
*fws
,
756 struct brcmf_fws_mac_descriptor
*entry
,
759 struct brcmf_fws_mac_descriptor
*if_entry
;
762 /* for unique destination entries the related interface
765 if (entry
->mac_handle
) {
766 if_entry
= &fws
->desc
.iface
[entry
->interface_id
];
767 if (if_entry
->state
== BRCMF_FWS_STATE_CLOSE
)
770 /* an entry is closed when the state is closed and
771 * the firmware did not request anything.
773 closed
= entry
->state
== BRCMF_FWS_STATE_CLOSE
&&
774 !entry
->requested_credit
&& !entry
->requested_packet
;
776 /* Or firmware does not allow traffic for given fifo */
777 return closed
|| !(entry
->ac_bitmap
& BIT(fifo
));
780 static void brcmf_fws_macdesc_cleanup(struct brcmf_fws_info
*fws
,
781 struct brcmf_fws_mac_descriptor
*entry
,
784 if (entry
->occupied
&& (ifidx
== -1 || ifidx
== entry
->interface_id
)) {
785 brcmf_fws_psq_flush(fws
, &entry
->psq
, ifidx
);
786 entry
->occupied
= !!(entry
->psq
.len
);
790 static void brcmf_fws_bus_txq_cleanup(struct brcmf_fws_info
*fws
,
791 bool (*fn
)(struct sk_buff
*, void *),
794 struct brcmf_fws_hanger_item
*hi
;
800 txq
= brcmf_bus_gettxq(fws
->drvr
->bus_if
);
802 brcmf_dbg(TRACE
, "no txq to clean up\n");
806 for (prec
= 0; prec
< txq
->num_prec
; prec
++) {
807 skb
= brcmu_pktq_pdeq_match(txq
, prec
, fn
, &ifidx
);
809 hslot
= brcmf_skb_htod_tag_get_field(skb
, HSLOT
);
810 hi
= &fws
->hanger
.items
[hslot
];
811 WARN_ON(skb
!= hi
->pkt
);
812 hi
->state
= BRCMF_FWS_HANGER_ITEM_STATE_FREE
;
813 brcmu_pkt_buf_free_skb(skb
);
814 skb
= brcmu_pktq_pdeq_match(txq
, prec
, fn
, &ifidx
);
819 static void brcmf_fws_cleanup(struct brcmf_fws_info
*fws
, int ifidx
)
822 struct brcmf_fws_mac_descriptor
*table
;
823 bool (*matchfn
)(struct sk_buff
*, void *) = NULL
;
829 matchfn
= brcmf_fws_ifidx_match
;
831 /* cleanup individual nodes */
832 table
= &fws
->desc
.nodes
[0];
833 for (i
= 0; i
< ARRAY_SIZE(fws
->desc
.nodes
); i
++)
834 brcmf_fws_macdesc_cleanup(fws
, &table
[i
], ifidx
);
836 brcmf_fws_macdesc_cleanup(fws
, &fws
->desc
.other
, ifidx
);
837 brcmf_fws_bus_txq_cleanup(fws
, matchfn
, ifidx
);
838 brcmf_fws_hanger_cleanup(fws
, matchfn
, ifidx
);
841 static u8
brcmf_fws_hdrpush(struct brcmf_fws_info
*fws
, struct sk_buff
*skb
)
843 struct brcmf_fws_mac_descriptor
*entry
= brcmf_skbcb(skb
)->mac
;
847 __le32 pkttag
= cpu_to_le32(brcmf_skbcb(skb
)->htod
);
848 __le16 pktseq
= cpu_to_le16(brcmf_skbcb(skb
)->htod_seq
);
850 brcmf_dbg(TRACE
, "enter: %s, idx=%d hslot=%d htod %X seq %X\n",
851 entry
->name
, brcmf_skb_if_flags_get_field(skb
, INDEX
),
852 (le32_to_cpu(pkttag
) >> 8) & 0xffff,
853 brcmf_skbcb(skb
)->htod
, brcmf_skbcb(skb
)->htod_seq
);
854 if (entry
->send_tim_signal
)
855 data_offset
+= 2 + BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN
;
856 if (BRCMF_FWS_MODE_GET_REUSESEQ(fws
->mode
))
857 data_offset
+= BRCMF_FWS_TYPE_SEQ_LEN
;
858 /* +2 is for Type[1] and Len[1] in TLV, plus TIM signal */
859 data_offset
+= 2 + BRCMF_FWS_TYPE_PKTTAG_LEN
;
860 fillers
= round_up(data_offset
, 4) - data_offset
;
861 data_offset
+= fillers
;
863 skb_push(skb
, data_offset
);
866 wlh
[0] = BRCMF_FWS_TYPE_PKTTAG
;
867 wlh
[1] = BRCMF_FWS_TYPE_PKTTAG_LEN
;
868 memcpy(&wlh
[2], &pkttag
, sizeof(pkttag
));
869 if (BRCMF_FWS_MODE_GET_REUSESEQ(fws
->mode
)) {
870 wlh
[1] += BRCMF_FWS_TYPE_SEQ_LEN
;
871 memcpy(&wlh
[2 + BRCMF_FWS_TYPE_PKTTAG_LEN
], &pktseq
,
876 if (entry
->send_tim_signal
) {
877 entry
->send_tim_signal
= 0;
878 wlh
[0] = BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP
;
879 wlh
[1] = BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN
;
880 wlh
[2] = entry
->mac_handle
;
881 wlh
[3] = entry
->traffic_pending_bmp
;
882 brcmf_dbg(TRACE
, "adding TIM info: handle %d bmp 0x%X\n",
883 entry
->mac_handle
, entry
->traffic_pending_bmp
);
884 wlh
+= BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN
+ 2;
885 entry
->traffic_lastreported_bmp
= entry
->traffic_pending_bmp
;
888 memset(wlh
, BRCMF_FWS_TYPE_FILLER
, fillers
);
890 return (u8
)(data_offset
>> 2);
893 static bool brcmf_fws_tim_update(struct brcmf_fws_info
*fws
,
894 struct brcmf_fws_mac_descriptor
*entry
,
895 int fifo
, bool send_immediately
)
898 struct brcmf_skbuff_cb
*skcb
;
904 /* check delayedQ and suppressQ in one call using bitmap */
905 if (brcmu_pktq_mlen(&entry
->psq
, 3 << (fifo
* 2)) == 0)
906 entry
->traffic_pending_bmp
&= ~NBITVAL(fifo
);
908 entry
->traffic_pending_bmp
|= NBITVAL(fifo
);
910 entry
->send_tim_signal
= false;
911 if (entry
->traffic_lastreported_bmp
!= entry
->traffic_pending_bmp
)
912 entry
->send_tim_signal
= true;
913 if (send_immediately
&& entry
->send_tim_signal
&&
914 entry
->state
== BRCMF_FWS_STATE_CLOSE
) {
915 /* create a dummy packet and sent that. The traffic */
916 /* bitmap info will automatically be attached to that packet */
917 len
= BRCMF_FWS_TYPE_PKTTAG_LEN
+ 2 +
918 BRCMF_FWS_TYPE_SEQ_LEN
+
919 BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN
+ 2 +
920 4 + fws
->drvr
->hdrlen
;
921 skb
= brcmu_pkt_buf_get_skb(len
);
925 skcb
= brcmf_skbcb(skb
);
927 skcb
->state
= BRCMF_FWS_SKBSTATE_TIM
;
930 data_offset
= brcmf_fws_hdrpush(fws
, skb
);
931 ifidx
= brcmf_skb_if_flags_get_field(skb
, INDEX
);
932 brcmf_fws_unlock(fws
);
933 err
= brcmf_proto_txdata(fws
->drvr
, ifidx
, data_offset
, skb
);
936 brcmu_pkt_buf_free_skb(skb
);
943 brcmf_fws_flow_control_check(struct brcmf_fws_info
*fws
, struct pktq
*pq
,
946 struct brcmf_if
*ifp
= fws
->drvr
->iflist
[!if_id
? 0 : if_id
+ 1];
951 if ((ifp
->netif_stop
& BRCMF_NETIF_STOP_REASON_FWS_FC
) &&
952 pq
->len
<= BRCMF_FWS_FLOWCONTROL_LOWATER
)
953 brcmf_txflowblock_if(ifp
,
954 BRCMF_NETIF_STOP_REASON_FWS_FC
, false);
955 if (!(ifp
->netif_stop
& BRCMF_NETIF_STOP_REASON_FWS_FC
) &&
956 pq
->len
>= BRCMF_FWS_FLOWCONTROL_HIWATER
) {
957 fws
->stats
.fws_flow_block
++;
958 brcmf_txflowblock_if(ifp
, BRCMF_NETIF_STOP_REASON_FWS_FC
, true);
963 static int brcmf_fws_rssi_indicate(struct brcmf_fws_info
*fws
, s8 rssi
)
965 brcmf_dbg(CTL
, "rssi %d\n", rssi
);
970 int brcmf_fws_macdesc_indicate(struct brcmf_fws_info
*fws
, u8 type
, u8
*data
)
972 struct brcmf_fws_mac_descriptor
*entry
, *existing
;
977 mac_handle
= *data
++;
981 entry
= &fws
->desc
.nodes
[mac_handle
& 0x1F];
982 if (type
== BRCMF_FWS_TYPE_MACDESC_DEL
) {
983 if (entry
->occupied
) {
984 brcmf_dbg(TRACE
, "deleting %s mac %pM\n",
987 brcmf_fws_macdesc_cleanup(fws
, entry
, -1);
988 brcmf_fws_macdesc_deinit(entry
);
989 brcmf_fws_unlock(fws
);
991 fws
->stats
.mac_update_failed
++;
995 existing
= brcmf_fws_macdesc_lookup(fws
, addr
);
996 if (IS_ERR(existing
)) {
997 if (!entry
->occupied
) {
999 entry
->mac_handle
= mac_handle
;
1000 brcmf_fws_macdesc_init(entry
, addr
, ifidx
);
1001 brcmf_fws_macdesc_set_name(fws
, entry
);
1002 brcmu_pktq_init(&entry
->psq
, BRCMF_FWS_PSQ_PREC_COUNT
,
1004 brcmf_fws_unlock(fws
);
1005 brcmf_dbg(TRACE
, "add %s mac %pM\n", entry
->name
, addr
);
1007 fws
->stats
.mac_update_failed
++;
1010 if (entry
!= existing
) {
1011 brcmf_dbg(TRACE
, "copy mac %s\n", existing
->name
);
1012 brcmf_fws_lock(fws
);
1013 memcpy(entry
, existing
,
1014 offsetof(struct brcmf_fws_mac_descriptor
, psq
));
1015 entry
->mac_handle
= mac_handle
;
1016 brcmf_fws_macdesc_deinit(existing
);
1017 brcmf_fws_macdesc_set_name(fws
, entry
);
1018 brcmf_fws_unlock(fws
);
1019 brcmf_dbg(TRACE
, "relocate %s mac %pM\n", entry
->name
,
1022 brcmf_dbg(TRACE
, "use existing\n");
1023 WARN_ON(entry
->mac_handle
!= mac_handle
);
1024 /* TODO: what should we do here: continue, reinit, .. */
1030 static int brcmf_fws_macdesc_state_indicate(struct brcmf_fws_info
*fws
,
1033 struct brcmf_fws_mac_descriptor
*entry
;
1037 mac_handle
= data
[0];
1038 entry
= &fws
->desc
.nodes
[mac_handle
& 0x1F];
1039 if (!entry
->occupied
) {
1040 fws
->stats
.mac_ps_update_failed
++;
1043 brcmf_fws_lock(fws
);
1044 /* a state update should wipe old credits */
1045 entry
->requested_credit
= 0;
1046 entry
->requested_packet
= 0;
1047 if (type
== BRCMF_FWS_TYPE_MAC_OPEN
) {
1048 entry
->state
= BRCMF_FWS_STATE_OPEN
;
1049 ret
= BRCMF_FWS_RET_OK_SCHEDULE
;
1051 entry
->state
= BRCMF_FWS_STATE_CLOSE
;
1052 brcmf_fws_tim_update(fws
, entry
, BRCMF_FWS_FIFO_AC_BK
, false);
1053 brcmf_fws_tim_update(fws
, entry
, BRCMF_FWS_FIFO_AC_BE
, false);
1054 brcmf_fws_tim_update(fws
, entry
, BRCMF_FWS_FIFO_AC_VI
, false);
1055 brcmf_fws_tim_update(fws
, entry
, BRCMF_FWS_FIFO_AC_VO
, true);
1056 ret
= BRCMF_FWS_RET_OK_NOSCHEDULE
;
1058 brcmf_fws_unlock(fws
);
1062 static int brcmf_fws_interface_state_indicate(struct brcmf_fws_info
*fws
,
1065 struct brcmf_fws_mac_descriptor
*entry
;
1071 if (ifidx
>= BRCMF_MAX_IFS
) {
1076 entry
= &fws
->desc
.iface
[ifidx
];
1077 if (!entry
->occupied
) {
1082 brcmf_dbg(TRACE
, "%s (%d): %s\n", brcmf_fws_get_tlv_name(type
), type
,
1084 brcmf_fws_lock(fws
);
1086 case BRCMF_FWS_TYPE_INTERFACE_OPEN
:
1087 entry
->state
= BRCMF_FWS_STATE_OPEN
;
1088 ret
= BRCMF_FWS_RET_OK_SCHEDULE
;
1090 case BRCMF_FWS_TYPE_INTERFACE_CLOSE
:
1091 entry
->state
= BRCMF_FWS_STATE_CLOSE
;
1092 ret
= BRCMF_FWS_RET_OK_NOSCHEDULE
;
1096 brcmf_fws_unlock(fws
);
1099 brcmf_fws_unlock(fws
);
1103 fws
->stats
.if_update_failed
++;
1107 static int brcmf_fws_request_indicate(struct brcmf_fws_info
*fws
, u8 type
,
1110 struct brcmf_fws_mac_descriptor
*entry
;
1112 entry
= &fws
->desc
.nodes
[data
[1] & 0x1F];
1113 if (!entry
->occupied
) {
1114 if (type
== BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT
)
1115 fws
->stats
.credit_request_failed
++;
1117 fws
->stats
.packet_request_failed
++;
1121 brcmf_dbg(TRACE
, "%s (%d): %s cnt %d bmp %d\n",
1122 brcmf_fws_get_tlv_name(type
), type
, entry
->name
,
1124 brcmf_fws_lock(fws
);
1125 if (type
== BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT
)
1126 entry
->requested_credit
= data
[0];
1128 entry
->requested_packet
= data
[0];
1130 entry
->ac_bitmap
= data
[2];
1131 brcmf_fws_unlock(fws
);
1132 return BRCMF_FWS_RET_OK_SCHEDULE
;
1136 brcmf_fws_macdesc_use_req_credit(struct brcmf_fws_mac_descriptor
*entry
,
1137 struct sk_buff
*skb
)
1139 if (entry
->requested_credit
> 0) {
1140 entry
->requested_credit
--;
1141 brcmf_skb_if_flags_set_field(skb
, REQUESTED
, 1);
1142 brcmf_skb_if_flags_set_field(skb
, REQ_CREDIT
, 1);
1143 if (entry
->state
!= BRCMF_FWS_STATE_CLOSE
)
1144 brcmf_err("requested credit set while mac not closed!\n");
1145 } else if (entry
->requested_packet
> 0) {
1146 entry
->requested_packet
--;
1147 brcmf_skb_if_flags_set_field(skb
, REQUESTED
, 1);
1148 brcmf_skb_if_flags_set_field(skb
, REQ_CREDIT
, 0);
1149 if (entry
->state
!= BRCMF_FWS_STATE_CLOSE
)
1150 brcmf_err("requested packet set while mac not closed!\n");
1152 brcmf_skb_if_flags_set_field(skb
, REQUESTED
, 0);
1153 brcmf_skb_if_flags_set_field(skb
, REQ_CREDIT
, 0);
1157 static void brcmf_fws_macdesc_return_req_credit(struct sk_buff
*skb
)
1159 struct brcmf_fws_mac_descriptor
*entry
= brcmf_skbcb(skb
)->mac
;
1161 if ((brcmf_skb_if_flags_get_field(skb
, REQ_CREDIT
)) &&
1162 (entry
->state
== BRCMF_FWS_STATE_CLOSE
))
1163 entry
->requested_credit
++;
1166 static void brcmf_fws_return_credits(struct brcmf_fws_info
*fws
,
1167 u8 fifo
, u8 credits
)
1176 fws
->fifo_credit_map
|= 1 << fifo
;
1178 if ((fifo
== BRCMF_FWS_FIFO_AC_BE
) &&
1179 (fws
->credits_borrowed
[0])) {
1180 for (lender_ac
= BRCMF_FWS_FIFO_AC_VO
; lender_ac
>= 0;
1182 borrowed
= &fws
->credits_borrowed
[lender_ac
];
1184 fws
->fifo_credit_map
|= (1 << lender_ac
);
1185 fifo_credit
= &fws
->fifo_credit
[lender_ac
];
1186 if (*borrowed
>= credits
) {
1187 *borrowed
-= credits
;
1188 *fifo_credit
+= credits
;
1191 credits
-= *borrowed
;
1192 *fifo_credit
+= *borrowed
;
1199 fws
->fifo_credit
[fifo
] += credits
;
1202 static void brcmf_fws_schedule_deq(struct brcmf_fws_info
*fws
)
1204 /* only schedule dequeue when there are credits for delayed traffic */
1205 if ((fws
->fifo_credit_map
& fws
->fifo_delay_map
) ||
1206 (!brcmf_fws_fc_active(fws
) && fws
->fifo_delay_map
))
1207 queue_work(fws
->fws_wq
, &fws
->fws_dequeue_work
);
1210 static int brcmf_fws_enq(struct brcmf_fws_info
*fws
,
1211 enum brcmf_fws_skb_state state
, int fifo
,
1214 int prec
= 2 * fifo
;
1215 u32
*qfull_stat
= &fws
->stats
.delayq_full_error
;
1216 struct brcmf_fws_mac_descriptor
*entry
;
1218 struct sk_buff_head
*queue
;
1219 struct sk_buff
*p_head
;
1220 struct sk_buff
*p_tail
;
1224 entry
= brcmf_skbcb(p
)->mac
;
1225 if (entry
== NULL
) {
1226 brcmf_err("no mac descriptor found for skb %p\n", p
);
1230 brcmf_dbg(DATA
, "enter: fifo %d skb %p\n", fifo
, p
);
1231 if (state
== BRCMF_FWS_SKBSTATE_SUPPRESSED
) {
1233 qfull_stat
= &fws
->stats
.supprq_full_error
;
1235 /* Fix out of order delivery of frames. Dont assume frame */
1236 /* can be inserted at the end, but look for correct position */
1238 if (pktq_full(pq
) || pktq_pfull(pq
, prec
)) {
1242 queue
= &pq
->q
[prec
].skblist
;
1244 p_head
= skb_peek(queue
);
1245 p_tail
= skb_peek_tail(queue
);
1246 fr_new
= brcmf_skb_htod_tag_get_field(p
, FREERUN
);
1248 while (p_head
!= p_tail
) {
1249 fr_compare
= brcmf_skb_htod_tag_get_field(p_tail
,
1251 /* be sure to handle wrap of 256 */
1252 if (((fr_new
> fr_compare
) &&
1253 ((fr_new
- fr_compare
) < 128)) ||
1254 ((fr_new
< fr_compare
) &&
1255 ((fr_compare
- fr_new
) > 128)))
1257 p_tail
= skb_queue_prev(queue
, p_tail
);
1259 /* Position found. Determine what to do */
1260 if (p_tail
== NULL
) {
1262 __skb_queue_tail(queue
, p
);
1264 fr_compare
= brcmf_skb_htod_tag_get_field(p_tail
,
1266 if (((fr_new
> fr_compare
) &&
1267 ((fr_new
- fr_compare
) < 128)) ||
1268 ((fr_new
< fr_compare
) &&
1269 ((fr_compare
- fr_new
) > 128))) {
1271 __skb_queue_after(queue
, p_tail
, p
);
1274 __skb_insert(p
, p_tail
->prev
, p_tail
, queue
);
1278 /* Complete the counters and statistics */
1280 if (pq
->hi_prec
< prec
)
1281 pq
->hi_prec
= (u8
) prec
;
1282 } else if (brcmu_pktq_penq(&entry
->psq
, prec
, p
) == NULL
) {
1287 /* increment total enqueued packet count */
1288 fws
->fifo_delay_map
|= 1 << fifo
;
1289 fws
->fifo_enqpkt
[fifo
]++;
1291 /* update the sk_buff state */
1292 brcmf_skbcb(p
)->state
= state
;
1295 * A packet has been pushed so update traffic
1296 * availability bitmap, if applicable
1298 brcmf_fws_tim_update(fws
, entry
, fifo
, true);
1299 brcmf_fws_flow_control_check(fws
, &entry
->psq
,
1300 brcmf_skb_if_flags_get_field(p
, INDEX
));
1304 static struct sk_buff
*brcmf_fws_deq(struct brcmf_fws_info
*fws
, int fifo
)
1306 struct brcmf_fws_mac_descriptor
*table
;
1307 struct brcmf_fws_mac_descriptor
*entry
;
1315 table
= (struct brcmf_fws_mac_descriptor
*)&fws
->desc
;
1316 num_nodes
= sizeof(fws
->desc
) / sizeof(struct brcmf_fws_mac_descriptor
);
1317 node_pos
= fws
->deq_node_pos
[fifo
];
1319 for (i
= 0; i
< num_nodes
; i
++) {
1320 entry
= &table
[(node_pos
+ i
) % num_nodes
];
1321 if (!entry
->occupied
||
1322 brcmf_fws_macdesc_closed(fws
, entry
, fifo
))
1325 if (entry
->suppressed
)
1329 p
= brcmu_pktq_mdeq(&entry
->psq
, pmsk
<< (fifo
* 2), &prec_out
);
1331 if (entry
->suppressed
) {
1332 if (entry
->suppr_transit_count
)
1334 entry
->suppressed
= false;
1335 p
= brcmu_pktq_mdeq(&entry
->psq
,
1336 1 << (fifo
* 2), &prec_out
);
1342 brcmf_fws_macdesc_use_req_credit(entry
, p
);
1344 /* move dequeue position to ensure fair round-robin */
1345 fws
->deq_node_pos
[fifo
] = (node_pos
+ i
+ 1) % num_nodes
;
1346 brcmf_fws_flow_control_check(fws
, &entry
->psq
,
1347 brcmf_skb_if_flags_get_field(p
,
1351 * A packet has been picked up, update traffic
1352 * availability bitmap, if applicable
1354 brcmf_fws_tim_update(fws
, entry
, fifo
, false);
1357 * decrement total enqueued fifo packets and
1358 * clear delay bitmap if done.
1360 fws
->fifo_enqpkt
[fifo
]--;
1361 if (fws
->fifo_enqpkt
[fifo
] == 0)
1362 fws
->fifo_delay_map
&= ~(1 << fifo
);
1367 brcmf_dbg(DATA
, "exit: fifo %d skb %p\n", fifo
, p
);
1371 static int brcmf_fws_txstatus_suppressed(struct brcmf_fws_info
*fws
, int fifo
,
1372 struct sk_buff
*skb
, u32 genbit
,
1375 struct brcmf_fws_mac_descriptor
*entry
= brcmf_skbcb(skb
)->mac
;
1380 hslot
= brcmf_skb_htod_tag_get_field(skb
, HSLOT
);
1382 /* this packet was suppressed */
1383 if (!entry
->suppressed
) {
1384 entry
->suppressed
= true;
1385 entry
->suppr_transit_count
= entry
->transit_count
;
1386 brcmf_dbg(DATA
, "suppress %s: transit %d\n",
1387 entry
->name
, entry
->transit_count
);
1390 entry
->generation
= genbit
;
1392 ret
= brcmf_proto_hdrpull(fws
->drvr
, false, &ifidx
, skb
);
1394 brcmf_skb_htod_tag_set_field(skb
, GENERATION
, genbit
);
1395 brcmf_skbcb(skb
)->htod_seq
= seq
;
1396 if (brcmf_skb_htod_seq_get_field(skb
, FROMFW
)) {
1397 brcmf_skb_htod_seq_set_field(skb
, FROMDRV
, 1);
1398 brcmf_skb_htod_seq_set_field(skb
, FROMFW
, 0);
1400 brcmf_skb_htod_seq_set_field(skb
, FROMDRV
, 0);
1402 ret
= brcmf_fws_enq(fws
, BRCMF_FWS_SKBSTATE_SUPPRESSED
, fifo
,
1407 /* suppress q is full or hdrpull failed, drop this packet */
1408 brcmf_fws_hanger_poppkt(&fws
->hanger
, hslot
, &skb
,
1412 * Mark suppressed to avoid a double free during
1415 brcmf_fws_hanger_mark_suppressed(&fws
->hanger
, hslot
);
1422 brcmf_fws_txs_process(struct brcmf_fws_info
*fws
, u8 flags
, u32 hslot
,
1423 u32 genbit
, u16 seq
)
1427 bool remove_from_hanger
= true;
1428 struct sk_buff
*skb
;
1429 struct brcmf_skbuff_cb
*skcb
;
1430 struct brcmf_fws_mac_descriptor
*entry
= NULL
;
1432 brcmf_dbg(DATA
, "flags %d\n", flags
);
1434 if (flags
== BRCMF_FWS_TXSTATUS_DISCARD
)
1435 fws
->stats
.txs_discard
++;
1436 else if (flags
== BRCMF_FWS_TXSTATUS_CORE_SUPPRESS
) {
1437 fws
->stats
.txs_supp_core
++;
1438 remove_from_hanger
= false;
1439 } else if (flags
== BRCMF_FWS_TXSTATUS_FW_PS_SUPPRESS
) {
1440 fws
->stats
.txs_supp_ps
++;
1441 remove_from_hanger
= false;
1442 } else if (flags
== BRCMF_FWS_TXSTATUS_FW_TOSSED
)
1443 fws
->stats
.txs_tossed
++;
1444 else if (flags
== BRCMF_FWS_TXSTATUS_HOST_TOSSED
)
1445 fws
->stats
.txs_host_tossed
++;
1447 brcmf_err("unexpected txstatus\n");
1449 ret
= brcmf_fws_hanger_poppkt(&fws
->hanger
, hslot
, &skb
,
1450 remove_from_hanger
);
1452 brcmf_err("no packet in hanger slot: hslot=%d\n", hslot
);
1456 skcb
= brcmf_skbcb(skb
);
1458 if (WARN_ON(!entry
)) {
1459 brcmu_pkt_buf_free_skb(skb
);
1462 entry
->transit_count
--;
1463 if (entry
->suppressed
&& entry
->suppr_transit_count
)
1464 entry
->suppr_transit_count
--;
1466 brcmf_dbg(DATA
, "%s flags %d htod %X seq %X\n", entry
->name
, flags
,
1469 /* pick up the implicit credit from this packet */
1470 fifo
= brcmf_skb_htod_tag_get_field(skb
, FIFO
);
1471 if ((fws
->fcmode
== BRCMF_FWS_FCMODE_IMPLIED_CREDIT
) ||
1472 (brcmf_skb_if_flags_get_field(skb
, REQ_CREDIT
)) ||
1473 (flags
== BRCMF_FWS_TXSTATUS_HOST_TOSSED
)) {
1474 brcmf_fws_return_credits(fws
, fifo
, 1);
1475 brcmf_fws_schedule_deq(fws
);
1477 brcmf_fws_macdesc_return_req_credit(skb
);
1479 if (!remove_from_hanger
)
1480 ret
= brcmf_fws_txstatus_suppressed(fws
, fifo
, skb
, genbit
,
1483 if (remove_from_hanger
|| ret
)
1484 brcmf_txfinalize(fws
->drvr
, skb
, true);
1489 static int brcmf_fws_fifocreditback_indicate(struct brcmf_fws_info
*fws
,
1494 if (fws
->fcmode
!= BRCMF_FWS_FCMODE_EXPLICIT_CREDIT
) {
1495 brcmf_dbg(INFO
, "ignored\n");
1496 return BRCMF_FWS_RET_OK_NOSCHEDULE
;
1499 brcmf_dbg(DATA
, "enter: data %pM\n", data
);
1500 brcmf_fws_lock(fws
);
1501 for (i
= 0; i
< BRCMF_FWS_FIFO_COUNT
; i
++)
1502 brcmf_fws_return_credits(fws
, i
, data
[i
]);
1504 brcmf_dbg(DATA
, "map: credit %x delay %x\n", fws
->fifo_credit_map
,
1505 fws
->fifo_delay_map
);
1506 brcmf_fws_unlock(fws
);
1507 return BRCMF_FWS_RET_OK_SCHEDULE
;
1510 static int brcmf_fws_txstatus_indicate(struct brcmf_fws_info
*fws
, u8
*data
)
1520 fws
->stats
.txs_indicate
++;
1521 memcpy(&status_le
, data
, sizeof(status_le
));
1522 status
= le32_to_cpu(status_le
);
1523 flags
= brcmf_txstatus_get_field(status
, FLAGS
);
1524 hslot
= brcmf_txstatus_get_field(status
, HSLOT
);
1525 genbit
= brcmf_txstatus_get_field(status
, GENERATION
);
1526 if (BRCMF_FWS_MODE_GET_REUSESEQ(fws
->mode
)) {
1527 memcpy(&seq_le
, &data
[BRCMF_FWS_TYPE_PKTTAG_LEN
],
1529 seq
= le16_to_cpu(seq_le
);
1534 brcmf_fws_lock(fws
);
1535 brcmf_fws_txs_process(fws
, flags
, hslot
, genbit
, seq
);
1536 brcmf_fws_unlock(fws
);
1537 return BRCMF_FWS_RET_OK_NOSCHEDULE
;
1540 static int brcmf_fws_dbg_seqnum_check(struct brcmf_fws_info
*fws
, u8
*data
)
1544 memcpy(×tamp
, &data
[2], sizeof(timestamp
));
1545 brcmf_dbg(CTL
, "received: seq %d, timestamp %d\n", data
[1],
1546 le32_to_cpu(timestamp
));
1550 static int brcmf_fws_notify_credit_map(struct brcmf_if
*ifp
,
1551 const struct brcmf_event_msg
*e
,
1554 struct brcmf_fws_info
*fws
= ifp
->drvr
->fws
;
1558 if (e
->datalen
< BRCMF_FWS_FIFO_COUNT
) {
1559 brcmf_err("event payload too small (%d)\n", e
->datalen
);
1562 if (fws
->creditmap_received
)
1565 fws
->creditmap_received
= true;
1567 brcmf_dbg(TRACE
, "enter: credits %pM\n", credits
);
1568 brcmf_fws_lock(fws
);
1569 for (i
= 0; i
< ARRAY_SIZE(fws
->fifo_credit
); i
++) {
1571 fws
->fifo_credit_map
|= 1 << i
;
1573 fws
->fifo_credit_map
&= ~(1 << i
);
1574 fws
->fifo_credit
[i
] = *credits
++;
1576 brcmf_fws_schedule_deq(fws
);
1577 brcmf_fws_unlock(fws
);
1581 static int brcmf_fws_notify_bcmc_credit_support(struct brcmf_if
*ifp
,
1582 const struct brcmf_event_msg
*e
,
1585 struct brcmf_fws_info
*fws
= ifp
->drvr
->fws
;
1587 brcmf_fws_lock(fws
);
1589 fws
->bcmc_credit_check
= true;
1590 brcmf_fws_unlock(fws
);
1594 int brcmf_fws_hdrpull(struct brcmf_pub
*drvr
, int ifidx
, s16 signal_len
,
1595 struct sk_buff
*skb
)
1597 struct brcmf_skb_reorder_data
*rd
;
1598 struct brcmf_fws_info
*fws
= drvr
->fws
;
1607 brcmf_dbg(HDRS
, "enter: ifidx %d, skblen %u, sig %d\n",
1608 ifidx
, skb
->len
, signal_len
);
1610 WARN_ON(signal_len
> skb
->len
);
1614 /* if flow control disabled, skip to packet data and leave */
1615 if (!fws
->fw_signals
) {
1616 skb_pull(skb
, signal_len
);
1620 fws
->stats
.header_pulls
++;
1621 data_len
= signal_len
;
1622 signal_data
= skb
->data
;
1624 status
= BRCMF_FWS_RET_OK_NOSCHEDULE
;
1625 while (data_len
> 0) {
1626 /* extract tlv info */
1627 type
= signal_data
[0];
1629 /* FILLER type is actually not a TLV, but
1630 * a single byte that can be skipped.
1632 if (type
== BRCMF_FWS_TYPE_FILLER
) {
1637 len
= signal_data
[1];
1638 data
= signal_data
+ 2;
1640 brcmf_dbg(HDRS
, "tlv type=%s (%d), len=%d (%d)\n",
1641 brcmf_fws_get_tlv_name(type
), type
, len
,
1642 brcmf_fws_get_tlv_len(fws
, type
));
1644 /* abort parsing when length invalid */
1645 if (data_len
< len
+ 2)
1648 if (len
< brcmf_fws_get_tlv_len(fws
, type
))
1651 err
= BRCMF_FWS_RET_OK_NOSCHEDULE
;
1653 case BRCMF_FWS_TYPE_COMP_TXSTATUS
:
1655 case BRCMF_FWS_TYPE_HOST_REORDER_RXPKTS
:
1656 rd
= (struct brcmf_skb_reorder_data
*)skb
->cb
;
1659 case BRCMF_FWS_TYPE_MACDESC_ADD
:
1660 case BRCMF_FWS_TYPE_MACDESC_DEL
:
1661 brcmf_fws_macdesc_indicate(fws
, type
, data
);
1663 case BRCMF_FWS_TYPE_MAC_OPEN
:
1664 case BRCMF_FWS_TYPE_MAC_CLOSE
:
1665 err
= brcmf_fws_macdesc_state_indicate(fws
, type
, data
);
1667 case BRCMF_FWS_TYPE_INTERFACE_OPEN
:
1668 case BRCMF_FWS_TYPE_INTERFACE_CLOSE
:
1669 err
= brcmf_fws_interface_state_indicate(fws
, type
,
1672 case BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT
:
1673 case BRCMF_FWS_TYPE_MAC_REQUEST_PACKET
:
1674 err
= brcmf_fws_request_indicate(fws
, type
, data
);
1676 case BRCMF_FWS_TYPE_TXSTATUS
:
1677 brcmf_fws_txstatus_indicate(fws
, data
);
1679 case BRCMF_FWS_TYPE_FIFO_CREDITBACK
:
1680 err
= brcmf_fws_fifocreditback_indicate(fws
, data
);
1682 case BRCMF_FWS_TYPE_RSSI
:
1683 brcmf_fws_rssi_indicate(fws
, *data
);
1685 case BRCMF_FWS_TYPE_TRANS_ID
:
1686 brcmf_fws_dbg_seqnum_check(fws
, data
);
1688 case BRCMF_FWS_TYPE_PKTTAG
:
1689 case BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP
:
1691 fws
->stats
.tlv_invalid_type
++;
1694 if (err
== BRCMF_FWS_RET_OK_SCHEDULE
)
1695 status
= BRCMF_FWS_RET_OK_SCHEDULE
;
1696 signal_data
+= len
+ 2;
1697 data_len
-= len
+ 2;
1701 fws
->stats
.tlv_parse_failed
++;
1703 if (status
== BRCMF_FWS_RET_OK_SCHEDULE
)
1704 brcmf_fws_schedule_deq(fws
);
1706 /* signalling processing result does
1707 * not affect the actual ethernet packet.
1709 skb_pull(skb
, signal_len
);
1711 /* this may be a signal-only packet
1714 fws
->stats
.header_only_pkt
++;
1719 static u8
brcmf_fws_precommit_skb(struct brcmf_fws_info
*fws
, int fifo
,
1722 struct brcmf_skbuff_cb
*skcb
= brcmf_skbcb(p
);
1723 struct brcmf_fws_mac_descriptor
*entry
= skcb
->mac
;
1726 if (skcb
->state
!= BRCMF_FWS_SKBSTATE_SUPPRESSED
)
1727 brcmf_skb_htod_tag_set_field(p
, GENERATION
, entry
->generation
);
1728 flags
= BRCMF_FWS_HTOD_FLAG_PKTFROMHOST
;
1729 if (brcmf_skb_if_flags_get_field(p
, REQUESTED
)) {
1731 * Indicate that this packet is being sent in response to an
1732 * explicit request from the firmware side.
1734 flags
|= BRCMF_FWS_HTOD_FLAG_PKT_REQUESTED
;
1736 brcmf_skb_htod_tag_set_field(p
, FLAGS
, flags
);
1737 return brcmf_fws_hdrpush(fws
, p
);
1740 static void brcmf_fws_rollback_toq(struct brcmf_fws_info
*fws
,
1741 struct sk_buff
*skb
, int fifo
)
1743 struct brcmf_fws_mac_descriptor
*entry
;
1744 struct sk_buff
*pktout
;
1748 entry
= brcmf_skbcb(skb
)->mac
;
1749 if (entry
->occupied
) {
1751 if (brcmf_skbcb(skb
)->state
== BRCMF_FWS_SKBSTATE_SUPPRESSED
)
1754 pktout
= brcmu_pktq_penq_head(&entry
->psq
, qidx
, skb
);
1755 if (pktout
== NULL
) {
1756 brcmf_err("%s queue %d full\n", entry
->name
, qidx
);
1760 brcmf_err("%s entry removed\n", entry
->name
);
1765 fws
->stats
.rollback_failed
++;
1766 hslot
= brcmf_skb_htod_tag_get_field(skb
, HSLOT
);
1767 brcmf_fws_txs_process(fws
, BRCMF_FWS_TXSTATUS_HOST_TOSSED
,
1770 fws
->stats
.rollback_success
++;
1771 brcmf_fws_return_credits(fws
, fifo
, 1);
1772 brcmf_fws_macdesc_return_req_credit(skb
);
1776 static int brcmf_fws_borrow_credit(struct brcmf_fws_info
*fws
)
1780 if (time_after(fws
->borrow_defer_timestamp
, jiffies
)) {
1781 fws
->fifo_credit_map
&= ~(1 << BRCMF_FWS_FIFO_AC_BE
);
1785 for (lender_ac
= 0; lender_ac
<= BRCMF_FWS_FIFO_AC_VO
; lender_ac
++) {
1786 if (fws
->fifo_credit
[lender_ac
]) {
1787 fws
->credits_borrowed
[lender_ac
]++;
1788 fws
->fifo_credit
[lender_ac
]--;
1789 if (fws
->fifo_credit
[lender_ac
] == 0)
1790 fws
->fifo_credit_map
&= ~(1 << lender_ac
);
1791 fws
->fifo_credit_map
|= (1 << BRCMF_FWS_FIFO_AC_BE
);
1792 brcmf_dbg(DATA
, "borrow credit from: %d\n", lender_ac
);
1796 fws
->fifo_credit_map
&= ~(1 << BRCMF_FWS_FIFO_AC_BE
);
1800 static int brcmf_fws_commit_skb(struct brcmf_fws_info
*fws
, int fifo
,
1801 struct sk_buff
*skb
)
1803 struct brcmf_skbuff_cb
*skcb
= brcmf_skbcb(skb
);
1804 struct brcmf_fws_mac_descriptor
*entry
;
1811 return PTR_ERR(entry
);
1813 data_offset
= brcmf_fws_precommit_skb(fws
, fifo
, skb
);
1814 entry
->transit_count
++;
1815 if (entry
->suppressed
)
1816 entry
->suppr_transit_count
++;
1817 ifidx
= brcmf_skb_if_flags_get_field(skb
, INDEX
);
1818 brcmf_fws_unlock(fws
);
1819 rc
= brcmf_proto_txdata(fws
->drvr
, ifidx
, data_offset
, skb
);
1820 brcmf_fws_lock(fws
);
1821 brcmf_dbg(DATA
, "%s flags %X htod %X bus_tx %d\n", entry
->name
,
1822 skcb
->if_flags
, skcb
->htod
, rc
);
1824 entry
->transit_count
--;
1825 if (entry
->suppressed
)
1826 entry
->suppr_transit_count
--;
1827 brcmf_proto_hdrpull(fws
->drvr
, false, &ifidx
, skb
);
1831 fws
->stats
.pkt2bus
++;
1832 fws
->stats
.send_pkts
[fifo
]++;
1833 if (brcmf_skb_if_flags_get_field(skb
, REQUESTED
))
1834 fws
->stats
.requested_sent
[fifo
]++;
1839 brcmf_fws_rollback_toq(fws
, skb
, fifo
);
1843 static int brcmf_fws_assign_htod(struct brcmf_fws_info
*fws
, struct sk_buff
*p
,
1846 struct brcmf_skbuff_cb
*skcb
= brcmf_skbcb(p
);
1851 hslot
= brcmf_fws_hanger_get_free_slot(&fws
->hanger
);
1852 brcmf_skb_htod_tag_set_field(p
, HSLOT
, hslot
);
1853 brcmf_skb_htod_tag_set_field(p
, FREERUN
, skcb
->mac
->seq
[fifo
]);
1854 brcmf_skb_htod_tag_set_field(p
, FIFO
, fifo
);
1855 rc
= brcmf_fws_hanger_pushpkt(&fws
->hanger
, p
, hslot
);
1857 skcb
->mac
->seq
[fifo
]++;
1859 fws
->stats
.generic_error
++;
1863 int brcmf_fws_process_skb(struct brcmf_if
*ifp
, struct sk_buff
*skb
)
1865 struct brcmf_pub
*drvr
= ifp
->drvr
;
1866 struct brcmf_fws_info
*fws
= drvr
->fws
;
1867 struct brcmf_skbuff_cb
*skcb
= brcmf_skbcb(skb
);
1868 struct ethhdr
*eh
= (struct ethhdr
*)(skb
->data
);
1869 int fifo
= BRCMF_FWS_FIFO_BCMC
;
1870 bool multicast
= is_multicast_ether_addr(eh
->h_dest
);
1871 bool pae
= eh
->h_proto
== htons(ETH_P_PAE
);
1873 brcmf_dbg(DATA
, "tx proto=0x%X\n", ntohs(eh
->h_proto
));
1874 /* determine the priority */
1876 skb
->priority
= cfg80211_classify8021d(skb
, NULL
);
1878 drvr
->tx_multicast
+= !!multicast
;
1880 atomic_inc(&ifp
->pend_8021x_cnt
);
1882 /* set control buffer information */
1884 skcb
->state
= BRCMF_FWS_SKBSTATE_NEW
;
1885 brcmf_skb_if_flags_set_field(skb
, INDEX
, ifp
->ifidx
);
1887 fifo
= brcmf_fws_prio2fifo
[skb
->priority
];
1889 brcmf_fws_lock(fws
);
1890 if (fifo
!= BRCMF_FWS_FIFO_AC_BE
&& fifo
< BRCMF_FWS_FIFO_BCMC
)
1891 fws
->borrow_defer_timestamp
= jiffies
+
1892 BRCMF_FWS_BORROW_DEFER_PERIOD
;
1894 skcb
->mac
= brcmf_fws_macdesc_find(fws
, ifp
, eh
->h_dest
);
1895 brcmf_dbg(DATA
, "%s mac %pM multi %d fifo %d\n", skcb
->mac
->name
,
1896 eh
->h_dest
, multicast
, fifo
);
1897 if (!brcmf_fws_assign_htod(fws
, skb
, fifo
)) {
1898 brcmf_fws_enq(fws
, BRCMF_FWS_SKBSTATE_DELAYED
, fifo
, skb
);
1899 brcmf_fws_schedule_deq(fws
);
1901 brcmf_err("drop skb: no hanger slot\n");
1903 atomic_dec(&ifp
->pend_8021x_cnt
);
1904 if (waitqueue_active(&ifp
->pend_8021x_wait
))
1905 wake_up(&ifp
->pend_8021x_wait
);
1907 brcmu_pkt_buf_free_skb(skb
);
1909 brcmf_fws_unlock(fws
);
1913 void brcmf_fws_reset_interface(struct brcmf_if
*ifp
)
1915 struct brcmf_fws_mac_descriptor
*entry
= ifp
->fws_desc
;
1917 brcmf_dbg(TRACE
, "enter: idx=%d\n", ifp
->bssidx
);
1921 brcmf_fws_macdesc_init(entry
, ifp
->mac_addr
, ifp
->ifidx
);
1924 void brcmf_fws_add_interface(struct brcmf_if
*ifp
)
1926 struct brcmf_fws_info
*fws
= ifp
->drvr
->fws
;
1927 struct brcmf_fws_mac_descriptor
*entry
;
1932 entry
= &fws
->desc
.iface
[ifp
->ifidx
];
1933 ifp
->fws_desc
= entry
;
1934 brcmf_fws_macdesc_init(entry
, ifp
->mac_addr
, ifp
->ifidx
);
1935 brcmf_fws_macdesc_set_name(fws
, entry
);
1936 brcmu_pktq_init(&entry
->psq
, BRCMF_FWS_PSQ_PREC_COUNT
,
1938 brcmf_dbg(TRACE
, "added %s\n", entry
->name
);
1941 void brcmf_fws_del_interface(struct brcmf_if
*ifp
)
1943 struct brcmf_fws_mac_descriptor
*entry
= ifp
->fws_desc
;
1948 brcmf_fws_lock(ifp
->drvr
->fws
);
1949 ifp
->fws_desc
= NULL
;
1950 brcmf_dbg(TRACE
, "deleting %s\n", entry
->name
);
1951 brcmf_fws_macdesc_deinit(entry
);
1952 brcmf_fws_cleanup(ifp
->drvr
->fws
, ifp
->ifidx
);
1953 brcmf_fws_unlock(ifp
->drvr
->fws
);
1956 static void brcmf_fws_dequeue_worker(struct work_struct
*worker
)
1958 struct brcmf_fws_info
*fws
;
1959 struct brcmf_pub
*drvr
;
1960 struct sk_buff
*skb
;
1966 fws
= container_of(worker
, struct brcmf_fws_info
, fws_dequeue_work
);
1969 brcmf_fws_lock(fws
);
1970 for (fifo
= BRCMF_FWS_FIFO_BCMC
; fifo
>= 0 && !fws
->bus_flow_blocked
;
1972 if (!brcmf_fws_fc_active(fws
)) {
1973 while ((skb
= brcmf_fws_deq(fws
, fifo
)) != NULL
) {
1974 hslot
= brcmf_skb_htod_tag_get_field(skb
,
1976 brcmf_fws_hanger_poppkt(&fws
->hanger
, hslot
,
1978 ifidx
= brcmf_skb_if_flags_get_field(skb
,
1980 /* Use proto layer to send data frame */
1981 brcmf_fws_unlock(fws
);
1982 ret
= brcmf_proto_txdata(drvr
, ifidx
, 0, skb
);
1983 brcmf_fws_lock(fws
);
1985 brcmf_txfinalize(drvr
, skb
, false);
1986 if (fws
->bus_flow_blocked
)
1991 while ((fws
->fifo_credit
[fifo
]) || ((!fws
->bcmc_credit_check
) &&
1992 (fifo
== BRCMF_FWS_FIFO_BCMC
))) {
1993 skb
= brcmf_fws_deq(fws
, fifo
);
1996 fws
->fifo_credit
[fifo
]--;
1997 if (brcmf_fws_commit_skb(fws
, fifo
, skb
))
1999 if (fws
->bus_flow_blocked
)
2002 if ((fifo
== BRCMF_FWS_FIFO_AC_BE
) &&
2003 (fws
->fifo_credit
[fifo
] == 0) &&
2004 (!fws
->bus_flow_blocked
)) {
2005 while (brcmf_fws_borrow_credit(fws
) == 0) {
2006 skb
= brcmf_fws_deq(fws
, fifo
);
2008 brcmf_fws_return_credits(fws
, fifo
, 1);
2011 if (brcmf_fws_commit_skb(fws
, fifo
, skb
))
2013 if (fws
->bus_flow_blocked
)
2018 brcmf_fws_unlock(fws
);
2021 int brcmf_fws_init(struct brcmf_pub
*drvr
)
2023 struct brcmf_fws_info
*fws
;
2024 u32 tlv
= BRCMF_FWS_FLAGS_RSSI_SIGNALS
;
2028 drvr
->fws
= kzalloc(sizeof(*(drvr
->fws
)), GFP_KERNEL
);
2036 spin_lock_init(&fws
->spinlock
);
2038 /* set linkage back */
2040 fws
->fcmode
= fcmode
;
2042 fws
->fws_wq
= create_singlethread_workqueue("brcmf_fws_wq");
2043 if (fws
->fws_wq
== NULL
) {
2044 brcmf_err("workqueue creation failed\n");
2048 INIT_WORK(&fws
->fws_dequeue_work
, brcmf_fws_dequeue_worker
);
2050 /* enable firmware signalling if fcmode active */
2051 if (fws
->fcmode
!= BRCMF_FWS_FCMODE_NONE
)
2052 tlv
|= BRCMF_FWS_FLAGS_XONXOFF_SIGNALS
|
2053 BRCMF_FWS_FLAGS_CREDIT_STATUS_SIGNALS
|
2054 BRCMF_FWS_FLAGS_HOST_PROPTXSTATUS_ACTIVE
|
2055 BRCMF_FWS_FLAGS_HOST_RXREORDER_ACTIVE
;
2057 rc
= brcmf_fweh_register(drvr
, BRCMF_E_FIFO_CREDIT_MAP
,
2058 brcmf_fws_notify_credit_map
);
2060 brcmf_err("register credit map handler failed\n");
2063 rc
= brcmf_fweh_register(drvr
, BRCMF_E_BCMC_CREDIT_SUPPORT
,
2064 brcmf_fws_notify_bcmc_credit_support
);
2066 brcmf_err("register bcmc credit handler failed\n");
2067 brcmf_fweh_unregister(drvr
, BRCMF_E_FIFO_CREDIT_MAP
);
2071 /* Setting the iovar may fail if feature is unsupported
2072 * so leave the rc as is so driver initialization can
2073 * continue. Set mode back to none indicating not enabled.
2075 fws
->fw_signals
= true;
2076 if (brcmf_fil_iovar_int_set(drvr
->iflist
[0], "tlv", tlv
)) {
2077 brcmf_err("failed to set bdcv2 tlv signaling\n");
2078 fws
->fcmode
= BRCMF_FWS_FCMODE_NONE
;
2079 fws
->fw_signals
= false;
2082 if (brcmf_fil_iovar_int_set(drvr
->iflist
[0], "ampdu_hostreorder", 1))
2083 brcmf_dbg(INFO
, "enabling AMPDU host-reorder failed\n");
2085 /* Enable seq number reuse, if supported */
2086 if (brcmf_fil_iovar_int_get(drvr
->iflist
[0], "wlfc_mode", &mode
) == 0) {
2087 if (BRCMF_FWS_MODE_GET_REUSESEQ(mode
)) {
2089 BRCMF_FWS_MODE_SET_REUSESEQ(mode
, 1);
2090 if (brcmf_fil_iovar_int_set(drvr
->iflist
[0],
2091 "wlfc_mode", mode
) == 0) {
2092 BRCMF_FWS_MODE_SET_REUSESEQ(fws
->mode
, 1);
2097 brcmf_fws_hanger_init(&fws
->hanger
);
2098 brcmf_fws_macdesc_init(&fws
->desc
.other
, NULL
, 0);
2099 brcmf_fws_macdesc_set_name(fws
, &fws
->desc
.other
);
2100 brcmu_pktq_init(&fws
->desc
.other
.psq
, BRCMF_FWS_PSQ_PREC_COUNT
,
2103 /* create debugfs file for statistics */
2104 brcmf_debugfs_create_fws_stats(drvr
, &fws
->stats
);
2106 brcmf_dbg(INFO
, "%s bdcv2 tlv signaling [%x]\n",
2107 fws
->fw_signals
? "enabled" : "disabled", tlv
);
2111 brcmf_fws_deinit(drvr
);
2115 void brcmf_fws_deinit(struct brcmf_pub
*drvr
)
2117 struct brcmf_fws_info
*fws
= drvr
->fws
;
2122 if (drvr
->fws
->fws_wq
)
2123 destroy_workqueue(drvr
->fws
->fws_wq
);
2126 brcmf_fws_lock(fws
);
2127 brcmf_fws_cleanup(fws
, -1);
2129 brcmf_fws_unlock(fws
);
2131 /* free top structure */
2135 bool brcmf_fws_fc_active(struct brcmf_fws_info
*fws
)
2137 if (!fws
->creditmap_received
)
2140 return fws
->fcmode
!= BRCMF_FWS_FCMODE_NONE
;
2143 void brcmf_fws_bustxfail(struct brcmf_fws_info
*fws
, struct sk_buff
*skb
)
2147 if (brcmf_skbcb(skb
)->state
== BRCMF_FWS_SKBSTATE_TIM
) {
2148 brcmu_pkt_buf_free_skb(skb
);
2151 brcmf_fws_lock(fws
);
2152 hslot
= brcmf_skb_htod_tag_get_field(skb
, HSLOT
);
2153 brcmf_fws_txs_process(fws
, BRCMF_FWS_TXSTATUS_HOST_TOSSED
, hslot
, 0, 0);
2154 brcmf_fws_unlock(fws
);
2157 void brcmf_fws_bus_blocked(struct brcmf_pub
*drvr
, bool flow_blocked
)
2159 struct brcmf_fws_info
*fws
= drvr
->fws
;
2161 fws
->bus_flow_blocked
= flow_blocked
;
2163 brcmf_fws_schedule_deq(fws
);
2165 fws
->stats
.bus_flow_block
++;