Commit | Line | Data |
---|---|---|
349e7104 AS |
1 | /* |
2 | * Copyright (c) 2010 Broadcom Corporation | |
3 | * | |
4 | * Permission to use, copy, modify, and/or distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | |
11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | |
13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |
14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | #include <linux/types.h> | |
c7f34a69 | 17 | #include <linux/module.h> |
349e7104 AS |
18 | #include <linux/if_ether.h> |
19 | #include <linux/spinlock.h> | |
20 | #include <linux/skbuff.h> | |
21 | #include <linux/netdevice.h> | |
3edc1cff | 22 | #include <linux/etherdevice.h> |
349e7104 | 23 | #include <linux/err.h> |
1aac1e91 | 24 | #include <linux/jiffies.h> |
349e7104 | 25 | #include <uapi/linux/nl80211.h> |
3edc1cff | 26 | #include <net/cfg80211.h> |
349e7104 AS |
27 | |
28 | #include <brcmu_utils.h> | |
29 | #include <brcmu_wifi.h> | |
30 | #include "dhd.h" | |
3edc1cff | 31 | #include "dhd_proto.h" |
349e7104 | 32 | #include "dhd_dbg.h" |
e2432b67 | 33 | #include "dhd_bus.h" |
349e7104 | 34 | #include "fwil.h" |
a7965fbb | 35 | #include "fwil_types.h" |
349e7104 AS |
36 | #include "fweh.h" |
37 | #include "fwsignal.h" | |
a7965fbb AS |
38 | #include "p2p.h" |
39 | #include "wl_cfg80211.h" | |
349e7104 AS |
40 | |
41 | /** | |
42 | * DOC: Firmware Signalling | |
43 | * | |
44 | * Firmware can send signals to host and vice versa, which are passed in the | |
45 | * data packets using TLV based header. This signalling layer is on top of the | |
46 | * BDC bus protocol layer. | |
47 | */ | |
48 | ||
49 | /* | |
50 | * single definition for firmware-driver flow control tlv's. | |
51 | * | |
52 | * each tlv is specified by BRCMF_FWS_TLV_DEF(name, ID, length). | |
53 | * A length value 0 indicates variable length tlv. | |
54 | */ | |
55 | #define BRCMF_FWS_TLV_DEFLIST \ | |
56 | BRCMF_FWS_TLV_DEF(MAC_OPEN, 1, 1) \ | |
57 | BRCMF_FWS_TLV_DEF(MAC_CLOSE, 2, 1) \ | |
58 | BRCMF_FWS_TLV_DEF(MAC_REQUEST_CREDIT, 3, 2) \ | |
59 | BRCMF_FWS_TLV_DEF(TXSTATUS, 4, 4) \ | |
60 | BRCMF_FWS_TLV_DEF(PKTTAG, 5, 4) \ | |
61 | BRCMF_FWS_TLV_DEF(MACDESC_ADD, 6, 8) \ | |
62 | BRCMF_FWS_TLV_DEF(MACDESC_DEL, 7, 8) \ | |
63 | BRCMF_FWS_TLV_DEF(RSSI, 8, 1) \ | |
64 | BRCMF_FWS_TLV_DEF(INTERFACE_OPEN, 9, 1) \ | |
65 | BRCMF_FWS_TLV_DEF(INTERFACE_CLOSE, 10, 1) \ | |
94607238 | 66 | BRCMF_FWS_TLV_DEF(FIFO_CREDITBACK, 11, 6) \ |
349e7104 AS |
67 | BRCMF_FWS_TLV_DEF(PENDING_TRAFFIC_BMP, 12, 2) \ |
68 | BRCMF_FWS_TLV_DEF(MAC_REQUEST_PACKET, 13, 3) \ | |
69 | BRCMF_FWS_TLV_DEF(HOST_REORDER_RXPKTS, 14, 10) \ | |
70 | BRCMF_FWS_TLV_DEF(TRANS_ID, 18, 6) \ | |
71 | BRCMF_FWS_TLV_DEF(COMP_TXSTATUS, 19, 1) \ | |
72 | BRCMF_FWS_TLV_DEF(FILLER, 255, 0) | |
73 | ||
3edc1cff | 74 | /* |
349e7104 AS |
75 | * enum brcmf_fws_tlv_type - definition of tlv identifiers. |
76 | */ | |
77 | #define BRCMF_FWS_TLV_DEF(name, id, len) \ | |
78 | BRCMF_FWS_TYPE_ ## name = id, | |
79 | enum brcmf_fws_tlv_type { | |
80 | BRCMF_FWS_TLV_DEFLIST | |
81 | BRCMF_FWS_TYPE_INVALID | |
82 | }; | |
83 | #undef BRCMF_FWS_TLV_DEF | |
84 | ||
3edc1cff AS |
85 | /* |
86 | * enum brcmf_fws_tlv_len - definition of tlv lengths. | |
87 | */ | |
88 | #define BRCMF_FWS_TLV_DEF(name, id, len) \ | |
89 | BRCMF_FWS_TYPE_ ## name ## _LEN = (len), | |
90 | enum brcmf_fws_tlv_len { | |
91 | BRCMF_FWS_TLV_DEFLIST | |
92 | }; | |
93 | #undef BRCMF_FWS_TLV_DEF | |
94 | ||
349e7104 | 95 | #ifdef DEBUG |
3edc1cff | 96 | /* |
349e7104 AS |
97 | * brcmf_fws_tlv_names - array of tlv names. |
98 | */ | |
99 | #define BRCMF_FWS_TLV_DEF(name, id, len) \ | |
100 | { id, #name }, | |
101 | static struct { | |
102 | enum brcmf_fws_tlv_type id; | |
103 | const char *name; | |
104 | } brcmf_fws_tlv_names[] = { | |
105 | BRCMF_FWS_TLV_DEFLIST | |
106 | }; | |
107 | #undef BRCMF_FWS_TLV_DEF | |
108 | ||
109 | static const char *brcmf_fws_get_tlv_name(enum brcmf_fws_tlv_type id) | |
110 | { | |
111 | int i; | |
112 | ||
113 | for (i = 0; i < ARRAY_SIZE(brcmf_fws_tlv_names); i++) | |
114 | if (brcmf_fws_tlv_names[i].id == id) | |
115 | return brcmf_fws_tlv_names[i].name; | |
116 | ||
117 | return "INVALID"; | |
118 | } | |
119 | #else | |
120 | static const char *brcmf_fws_get_tlv_name(enum brcmf_fws_tlv_type id) | |
121 | { | |
122 | return "NODEBUG"; | |
123 | } | |
124 | #endif /* DEBUG */ | |
125 | ||
3edc1cff | 126 | /* |
349e7104 AS |
127 | * flags used to enable tlv signalling from firmware. |
128 | */ | |
bb8c8063 AS |
129 | #define BRCMF_FWS_FLAGS_RSSI_SIGNALS 0x0001 |
130 | #define BRCMF_FWS_FLAGS_XONXOFF_SIGNALS 0x0002 | |
131 | #define BRCMF_FWS_FLAGS_CREDIT_STATUS_SIGNALS 0x0004 | |
132 | #define BRCMF_FWS_FLAGS_HOST_PROPTXSTATUS_ACTIVE 0x0008 | |
133 | #define BRCMF_FWS_FLAGS_PSQ_GENERATIONFSM_ENABLE 0x0010 | |
134 | #define BRCMF_FWS_FLAGS_PSQ_ZERO_BUFFER_ENABLE 0x0020 | |
135 | #define BRCMF_FWS_FLAGS_HOST_RXREORDER_ACTIVE 0x0040 | |
136 | ||
349e7104 | 137 | #define BRCMF_FWS_MAC_DESC_TABLE_SIZE 32 |
349e7104 AS |
138 | #define BRCMF_FWS_MAC_DESC_ID_INVALID 0xff |
139 | ||
140 | #define BRCMF_FWS_HOSTIF_FLOWSTATE_OFF 0 | |
141 | #define BRCMF_FWS_HOSTIF_FLOWSTATE_ON 1 | |
84bcc0c3 AS |
142 | #define BRCMF_FWS_FLOWCONTROL_HIWATER 128 |
143 | #define BRCMF_FWS_FLOWCONTROL_LOWATER 64 | |
349e7104 | 144 | |
bb8c8063 AS |
145 | #define BRCMF_FWS_PSQ_PREC_COUNT ((NL80211_NUM_ACS + 1) * 2) |
146 | #define BRCMF_FWS_PSQ_LEN 256 | |
147 | ||
3edc1cff AS |
148 | #define BRCMF_FWS_HTOD_FLAG_PKTFROMHOST 0x01 |
149 | #define BRCMF_FWS_HTOD_FLAG_PKT_REQUESTED 0x02 | |
150 | ||
a5e9d805 AS |
151 | #define BRCMF_FWS_RET_OK_NOSCHEDULE 0 |
152 | #define BRCMF_FWS_RET_OK_SCHEDULE 1 | |
153 | ||
ebb93883 AS |
154 | /** |
155 | * enum brcmf_fws_skb_state - indicates processing state of skb. | |
3edc1cff AS |
156 | * |
157 | * @BRCMF_FWS_SKBSTATE_NEW: sk_buff is newly arrived in the driver. | |
158 | * @BRCMF_FWS_SKBSTATE_DELAYED: sk_buff had to wait on queue. | |
159 | * @BRCMF_FWS_SKBSTATE_SUPPRESSED: sk_buff has been suppressed by firmware. | |
ebb93883 AS |
160 | */ |
161 | enum brcmf_fws_skb_state { | |
3edc1cff AS |
162 | BRCMF_FWS_SKBSTATE_NEW, |
163 | BRCMF_FWS_SKBSTATE_DELAYED, | |
164 | BRCMF_FWS_SKBSTATE_SUPPRESSED | |
ebb93883 AS |
165 | }; |
166 | ||
167 | /** | |
168 | * struct brcmf_skbuff_cb - control buffer associated with skbuff. | |
169 | * | |
170 | * @if_flags: holds interface index and packet related flags. | |
ebb93883 | 171 | * @htod: host to device packet identifier (used in PKTTAG tlv). |
ebb93883 AS |
172 | * @state: transmit state of the packet. |
173 | * @mac: descriptor related to destination for this packet. | |
174 | * | |
175 | * This information is stored in control buffer struct sk_buff::cb, which | |
176 | * provides 48 bytes of storage so this structure should not exceed that. | |
177 | */ | |
178 | struct brcmf_skbuff_cb { | |
179 | u16 if_flags; | |
ebb93883 | 180 | u32 htod; |
ebb93883 AS |
181 | enum brcmf_fws_skb_state state; |
182 | struct brcmf_fws_mac_descriptor *mac; | |
183 | }; | |
184 | ||
3edc1cff | 185 | /* |
ebb93883 AS |
186 | * macro casting skbuff control buffer to struct brcmf_skbuff_cb. |
187 | */ | |
188 | #define brcmf_skbcb(skb) ((struct brcmf_skbuff_cb *)((skb)->cb)) | |
189 | ||
3edc1cff | 190 | /* |
ebb93883 AS |
191 | * sk_buff control if flags |
192 | * | |
289ec1c7 AS |
193 | * b[12] - packet sent upon credit request. |
194 | * b[11] - packet sent upon packet request. | |
ebb93883 AS |
195 | * b[10] - packet only contains signalling data. |
196 | * b[9] - packet is a tx packet. | |
197 | * b[8] - packet uses FIFO credit (non-pspoll). | |
198 | * b[7] - interface in AP mode. | |
ebb93883 AS |
199 | * b[3:0] - interface index. |
200 | */ | |
289ec1c7 AS |
201 | #define BRCMF_SKB_IF_FLAGS_REQ_CREDIT_MASK 0x1000 |
202 | #define BRCMF_SKB_IF_FLAGS_REQ_CREDIT_SHIFT 12 | |
ebb93883 AS |
203 | #define BRCMF_SKB_IF_FLAGS_REQUESTED_MASK 0x0800 |
204 | #define BRCMF_SKB_IF_FLAGS_REQUESTED_SHIFT 11 | |
205 | #define BRCMF_SKB_IF_FLAGS_SIGNAL_ONLY_MASK 0x0400 | |
206 | #define BRCMF_SKB_IF_FLAGS_SIGNAL_ONLY_SHIFT 10 | |
207 | #define BRCMF_SKB_IF_FLAGS_TRANSMIT_MASK 0x0200 | |
208 | #define BRCMF_SKB_IF_FLAGS_TRANSMIT_SHIFT 9 | |
209 | #define BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK 0x0100 | |
210 | #define BRCMF_SKB_IF_FLAGS_CREDITCHECK_SHIFT 8 | |
211 | #define BRCMF_SKB_IF_FLAGS_IF_AP_MASK 0x0080 | |
212 | #define BRCMF_SKB_IF_FLAGS_IF_AP_SHIFT 7 | |
ebb93883 AS |
213 | #define BRCMF_SKB_IF_FLAGS_INDEX_MASK 0x000f |
214 | #define BRCMF_SKB_IF_FLAGS_INDEX_SHIFT 0 | |
215 | ||
216 | #define brcmf_skb_if_flags_set_field(skb, field, value) \ | |
217 | brcmu_maskset16(&(brcmf_skbcb(skb)->if_flags), \ | |
218 | BRCMF_SKB_IF_FLAGS_ ## field ## _MASK, \ | |
219 | BRCMF_SKB_IF_FLAGS_ ## field ## _SHIFT, (value)) | |
220 | #define brcmf_skb_if_flags_get_field(skb, field) \ | |
221 | brcmu_maskget16(brcmf_skbcb(skb)->if_flags, \ | |
222 | BRCMF_SKB_IF_FLAGS_ ## field ## _MASK, \ | |
223 | BRCMF_SKB_IF_FLAGS_ ## field ## _SHIFT) | |
224 | ||
3edc1cff | 225 | /* |
ebb93883 AS |
226 | * sk_buff control packet identifier |
227 | * | |
228 | * 32-bit packet identifier used in PKTTAG tlv from host to dongle. | |
229 | * | |
230 | * - Generated at the host (e.g. dhd) | |
231 | * - Seen as a generic sequence number by firmware except for the flags field. | |
232 | * | |
233 | * Generation : b[31] => generation number for this packet [host->fw] | |
234 | * OR, current generation number [fw->host] | |
235 | * Flags : b[30:27] => command, status flags | |
236 | * FIFO-AC : b[26:24] => AC-FIFO id | |
237 | * h-slot : b[23:8] => hanger-slot | |
238 | * freerun : b[7:0] => A free running counter | |
239 | */ | |
240 | #define BRCMF_SKB_HTOD_TAG_GENERATION_MASK 0x80000000 | |
241 | #define BRCMF_SKB_HTOD_TAG_GENERATION_SHIFT 31 | |
242 | #define BRCMF_SKB_HTOD_TAG_FLAGS_MASK 0x78000000 | |
243 | #define BRCMF_SKB_HTOD_TAG_FLAGS_SHIFT 27 | |
244 | #define BRCMF_SKB_HTOD_TAG_FIFO_MASK 0x07000000 | |
245 | #define BRCMF_SKB_HTOD_TAG_FIFO_SHIFT 24 | |
246 | #define BRCMF_SKB_HTOD_TAG_HSLOT_MASK 0x00ffff00 | |
247 | #define BRCMF_SKB_HTOD_TAG_HSLOT_SHIFT 8 | |
248 | #define BRCMF_SKB_HTOD_TAG_FREERUN_MASK 0x000000ff | |
be4910ad | 249 | #define BRCMF_SKB_HTOD_TAG_FREERUN_SHIFT 0 |
ebb93883 AS |
250 | |
251 | #define brcmf_skb_htod_tag_set_field(skb, field, value) \ | |
e2432b67 | 252 | brcmu_maskset32(&(brcmf_skbcb(skb)->htod), \ |
ebb93883 AS |
253 | BRCMF_SKB_HTOD_TAG_ ## field ## _MASK, \ |
254 | BRCMF_SKB_HTOD_TAG_ ## field ## _SHIFT, (value)) | |
255 | #define brcmf_skb_htod_tag_get_field(skb, field) \ | |
e2432b67 | 256 | brcmu_maskget32(brcmf_skbcb(skb)->htod, \ |
ebb93883 AS |
257 | BRCMF_SKB_HTOD_TAG_ ## field ## _MASK, \ |
258 | BRCMF_SKB_HTOD_TAG_ ## field ## _SHIFT) | |
259 | ||
3edc1cff AS |
260 | #define BRCMF_FWS_TXSTAT_GENERATION_MASK 0x80000000 |
261 | #define BRCMF_FWS_TXSTAT_GENERATION_SHIFT 31 | |
262 | #define BRCMF_FWS_TXSTAT_FLAGS_MASK 0x78000000 | |
263 | #define BRCMF_FWS_TXSTAT_FLAGS_SHIFT 27 | |
264 | #define BRCMF_FWS_TXSTAT_FIFO_MASK 0x07000000 | |
265 | #define BRCMF_FWS_TXSTAT_FIFO_SHIFT 24 | |
266 | #define BRCMF_FWS_TXSTAT_HSLOT_MASK 0x00FFFF00 | |
267 | #define BRCMF_FWS_TXSTAT_HSLOT_SHIFT 8 | |
268 | #define BRCMF_FWS_TXSTAT_PKTID_MASK 0x00FFFFFF | |
269 | #define BRCMF_FWS_TXSTAT_PKTID_SHIFT 0 | |
270 | ||
271 | #define brcmf_txstatus_get_field(txs, field) \ | |
272 | brcmu_maskget32(txs, BRCMF_FWS_TXSTAT_ ## field ## _MASK, \ | |
273 | BRCMF_FWS_TXSTAT_ ## field ## _SHIFT) | |
274 | ||
1aac1e91 AS |
275 | /* How long to defer borrowing in jiffies */ |
276 | #define BRCMF_FWS_BORROW_DEFER_PERIOD (HZ / 10) | |
277 | ||
3edc1cff AS |
278 | /** |
279 | * enum brcmf_fws_fifo - fifo indices used by dongle firmware. | |
280 | * | |
281 | * @BRCMF_FWS_FIFO_AC_BK: fifo for background traffic. | |
282 | * @BRCMF_FWS_FIFO_AC_BE: fifo for best-effort traffic. | |
283 | * @BRCMF_FWS_FIFO_AC_VI: fifo for video traffic. | |
284 | * @BRCMF_FWS_FIFO_AC_VO: fifo for voice traffic. | |
285 | * @BRCMF_FWS_FIFO_BCMC: fifo for broadcast/multicast (AP only). | |
286 | * @BRCMF_FWS_FIFO_ATIM: fifo for ATIM (AP only). | |
287 | * @BRCMF_FWS_FIFO_COUNT: number of fifos. | |
288 | */ | |
289 | enum brcmf_fws_fifo { | |
290 | BRCMF_FWS_FIFO_AC_BK, | |
291 | BRCMF_FWS_FIFO_AC_BE, | |
292 | BRCMF_FWS_FIFO_AC_VI, | |
293 | BRCMF_FWS_FIFO_AC_VO, | |
294 | BRCMF_FWS_FIFO_BCMC, | |
295 | BRCMF_FWS_FIFO_ATIM, | |
296 | BRCMF_FWS_FIFO_COUNT | |
297 | }; | |
298 | ||
299 | /** | |
300 | * enum brcmf_fws_txstatus - txstatus flag values. | |
301 | * | |
302 | * @BRCMF_FWS_TXSTATUS_DISCARD: | |
303 | * host is free to discard the packet. | |
304 | * @BRCMF_FWS_TXSTATUS_CORE_SUPPRESS: | |
305 | * 802.11 core suppressed the packet. | |
306 | * @BRCMF_FWS_TXSTATUS_FW_PS_SUPPRESS: | |
307 | * firmware suppress the packet as device is already in PS mode. | |
308 | * @BRCMF_FWS_TXSTATUS_FW_TOSSED: | |
309 | * firmware tossed the packet. | |
310 | */ | |
311 | enum brcmf_fws_txstatus { | |
312 | BRCMF_FWS_TXSTATUS_DISCARD, | |
313 | BRCMF_FWS_TXSTATUS_CORE_SUPPRESS, | |
314 | BRCMF_FWS_TXSTATUS_FW_PS_SUPPRESS, | |
315 | BRCMF_FWS_TXSTATUS_FW_TOSSED | |
316 | }; | |
317 | ||
c7f34a69 AS |
318 | enum brcmf_fws_fcmode { |
319 | BRCMF_FWS_FCMODE_NONE, | |
320 | BRCMF_FWS_FCMODE_IMPLIED_CREDIT, | |
321 | BRCMF_FWS_FCMODE_EXPLICIT_CREDIT | |
322 | }; | |
323 | ||
84bcc0c3 AS |
324 | enum brcmf_fws_mac_desc_state { |
325 | BRCMF_FWS_STATE_OPEN = 1, | |
326 | BRCMF_FWS_STATE_CLOSE | |
327 | }; | |
328 | ||
bb8c8063 AS |
329 | /** |
330 | * struct brcmf_fws_mac_descriptor - firmware signalling data per node/interface | |
331 | * | |
332 | * @occupied: slot is in use. | |
ce814c1b | 333 | * @mac_handle: handle for mac entry determined by firmware. |
bb8c8063 AS |
334 | * @interface_id: interface index. |
335 | * @state: current state. | |
3edc1cff AS |
336 | * @suppressed: mac entry is suppressed. |
337 | * @generation: generation bit. | |
bb8c8063 AS |
338 | * @ac_bitmap: ac queue bitmap. |
339 | * @requested_credit: credits requested by firmware. | |
340 | * @ea: ethernet address. | |
3edc1cff | 341 | * @seq: per-node free-running sequence. |
bb8c8063 | 342 | * @psq: power-save queue. |
3edc1cff | 343 | * @transit_count: packet in transit to firmware. |
bb8c8063 AS |
344 | */ |
345 | struct brcmf_fws_mac_descriptor { | |
8071fd61 | 346 | char name[16]; |
bb8c8063 | 347 | u8 occupied; |
ce814c1b | 348 | u8 mac_handle; |
bb8c8063 AS |
349 | u8 interface_id; |
350 | u8 state; | |
3edc1cff AS |
351 | bool suppressed; |
352 | u8 generation; | |
bb8c8063 AS |
353 | u8 ac_bitmap; |
354 | u8 requested_credit; | |
84bcc0c3 | 355 | u8 requested_packet; |
bb8c8063 | 356 | u8 ea[ETH_ALEN]; |
3edc1cff | 357 | u8 seq[BRCMF_FWS_FIFO_COUNT]; |
bb8c8063 | 358 | struct pktq psq; |
3edc1cff | 359 | int transit_count; |
84bcc0c3 AS |
360 | int suppr_transit_count; |
361 | bool send_tim_signal; | |
362 | u8 traffic_pending_bmp; | |
363 | u8 traffic_lastreported_bmp; | |
bb8c8063 AS |
364 | }; |
365 | ||
6971280a AS |
366 | #define BRCMF_FWS_HANGER_MAXITEMS 1024 |
367 | ||
368 | /** | |
369 | * enum brcmf_fws_hanger_item_state - state of hanger item. | |
370 | * | |
3edc1cff AS |
371 | * @BRCMF_FWS_HANGER_ITEM_STATE_FREE: item is free for use. |
372 | * @BRCMF_FWS_HANGER_ITEM_STATE_INUSE: item is in use. | |
373 | * @BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED: item was suppressed. | |
6971280a AS |
374 | */ |
375 | enum brcmf_fws_hanger_item_state { | |
3edc1cff AS |
376 | BRCMF_FWS_HANGER_ITEM_STATE_FREE = 1, |
377 | BRCMF_FWS_HANGER_ITEM_STATE_INUSE, | |
378 | BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED | |
6971280a AS |
379 | }; |
380 | ||
381 | ||
382 | /** | |
383 | * struct brcmf_fws_hanger_item - single entry for tx pending packet. | |
384 | * | |
385 | * @state: entry is either free or occupied. | |
6971280a AS |
386 | * @pkt: packet itself. |
387 | */ | |
388 | struct brcmf_fws_hanger_item { | |
389 | enum brcmf_fws_hanger_item_state state; | |
6971280a AS |
390 | struct sk_buff *pkt; |
391 | }; | |
392 | ||
393 | /** | |
394 | * struct brcmf_fws_hanger - holds packets awaiting firmware txstatus. | |
395 | * | |
6971280a AS |
396 | * @pushed: packets pushed to await txstatus. |
397 | * @popped: packets popped upon handling txstatus. | |
398 | * @failed_to_push: packets that could not be pushed. | |
399 | * @failed_to_pop: packets that could not be popped. | |
400 | * @failed_slotfind: packets for which failed to find an entry. | |
401 | * @slot_pos: last returned item index for a free entry. | |
402 | * @items: array of hanger items. | |
403 | */ | |
404 | struct brcmf_fws_hanger { | |
405 | u32 pushed; | |
406 | u32 popped; | |
407 | u32 failed_to_push; | |
408 | u32 failed_to_pop; | |
409 | u32 failed_slotfind; | |
410 | u32 slot_pos; | |
411 | struct brcmf_fws_hanger_item items[BRCMF_FWS_HANGER_MAXITEMS]; | |
412 | }; | |
413 | ||
84bcc0c3 AS |
414 | struct brcmf_fws_macdesc_table { |
415 | struct brcmf_fws_mac_descriptor nodes[BRCMF_FWS_MAC_DESC_TABLE_SIZE]; | |
416 | struct brcmf_fws_mac_descriptor iface[BRCMF_MAX_IFS]; | |
417 | struct brcmf_fws_mac_descriptor other; | |
418 | }; | |
419 | ||
349e7104 AS |
420 | struct brcmf_fws_info { |
421 | struct brcmf_pub *drvr; | |
422 | struct brcmf_fws_stats stats; | |
6971280a | 423 | struct brcmf_fws_hanger hanger; |
c7f34a69 | 424 | enum brcmf_fws_fcmode fcmode; |
84bcc0c3 AS |
425 | struct brcmf_fws_macdesc_table desc; |
426 | struct workqueue_struct *fws_wq; | |
427 | struct work_struct fws_dequeue_work; | |
428 | u32 fifo_enqpkt[BRCMF_FWS_FIFO_COUNT]; | |
3edc1cff | 429 | int fifo_credit[BRCMF_FWS_FIFO_COUNT]; |
1aac1e91 | 430 | int credits_borrowed[BRCMF_FWS_FIFO_AC_VO + 1]; |
84bcc0c3 AS |
431 | int deq_node_pos[BRCMF_FWS_FIFO_COUNT]; |
432 | u32 fifo_credit_map; | |
433 | u32 fifo_delay_map; | |
1aac1e91 | 434 | unsigned long borrow_defer_timestamp; |
df50f756 | 435 | bool bus_flow_blocked; |
0d24b0ea | 436 | bool creditmap_received; |
3edc1cff AS |
437 | }; |
438 | ||
439 | /* | |
440 | * brcmf_fws_prio2fifo - mapping from 802.1d priority to firmware fifo index. | |
441 | */ | |
442 | static const int brcmf_fws_prio2fifo[] = { | |
443 | BRCMF_FWS_FIFO_AC_BE, | |
444 | BRCMF_FWS_FIFO_AC_BK, | |
445 | BRCMF_FWS_FIFO_AC_BK, | |
446 | BRCMF_FWS_FIFO_AC_BE, | |
447 | BRCMF_FWS_FIFO_AC_VI, | |
448 | BRCMF_FWS_FIFO_AC_VI, | |
449 | BRCMF_FWS_FIFO_AC_VO, | |
450 | BRCMF_FWS_FIFO_AC_VO | |
349e7104 AS |
451 | }; |
452 | ||
c7f34a69 AS |
453 | static int fcmode; |
454 | module_param(fcmode, int, S_IRUSR); | |
455 | MODULE_PARM_DESC(fcmode, "mode of firmware signalled flow control"); | |
456 | ||
bb8c8063 AS |
457 | #define BRCMF_FWS_TLV_DEF(name, id, len) \ |
458 | case BRCMF_FWS_TYPE_ ## name: \ | |
459 | return len; | |
460 | ||
3edc1cff AS |
461 | /** |
462 | * brcmf_fws_get_tlv_len() - returns defined length for given tlv id. | |
463 | * | |
464 | * @fws: firmware-signalling information. | |
465 | * @id: identifier of the TLV. | |
466 | * | |
467 | * Return: the specified length for the given TLV; Otherwise -EINVAL. | |
468 | */ | |
bb8c8063 AS |
469 | static int brcmf_fws_get_tlv_len(struct brcmf_fws_info *fws, |
470 | enum brcmf_fws_tlv_type id) | |
471 | { | |
472 | switch (id) { | |
473 | BRCMF_FWS_TLV_DEFLIST | |
474 | default: | |
bb8c8063 AS |
475 | fws->stats.tlv_invalid_type++; |
476 | break; | |
477 | } | |
478 | return -EINVAL; | |
479 | } | |
480 | #undef BRCMF_FWS_TLV_DEF | |
481 | ||
3edc1cff AS |
482 | static bool brcmf_fws_ifidx_match(struct sk_buff *skb, void *arg) |
483 | { | |
484 | u32 ifidx = brcmf_skb_if_flags_get_field(skb, INDEX); | |
485 | return ifidx == *(int *)arg; | |
486 | } | |
487 | ||
488 | static void brcmf_fws_psq_flush(struct brcmf_fws_info *fws, struct pktq *q, | |
489 | int ifidx) | |
490 | { | |
491 | bool (*matchfn)(struct sk_buff *, void *) = NULL; | |
492 | struct sk_buff *skb; | |
493 | int prec; | |
494 | ||
495 | if (ifidx != -1) | |
496 | matchfn = brcmf_fws_ifidx_match; | |
497 | for (prec = 0; prec < q->num_prec; prec++) { | |
498 | skb = brcmu_pktq_pdeq_match(q, prec, matchfn, &ifidx); | |
499 | while (skb) { | |
84bcc0c3 | 500 | brcmu_pkt_buf_free_skb(skb); |
3edc1cff AS |
501 | skb = brcmu_pktq_pdeq_match(q, prec, matchfn, &ifidx); |
502 | } | |
503 | } | |
504 | } | |
505 | ||
6971280a AS |
506 | static void brcmf_fws_hanger_init(struct brcmf_fws_hanger *hanger) |
507 | { | |
508 | int i; | |
509 | ||
6971280a AS |
510 | memset(hanger, 0, sizeof(*hanger)); |
511 | for (i = 0; i < ARRAY_SIZE(hanger->items); i++) | |
3edc1cff | 512 | hanger->items[i].state = BRCMF_FWS_HANGER_ITEM_STATE_FREE; |
6971280a AS |
513 | } |
514 | ||
3edc1cff | 515 | static u32 brcmf_fws_hanger_get_free_slot(struct brcmf_fws_hanger *h) |
6971280a AS |
516 | { |
517 | u32 i; | |
518 | ||
6971280a AS |
519 | i = (h->slot_pos + 1) % BRCMF_FWS_HANGER_MAXITEMS; |
520 | ||
521 | while (i != h->slot_pos) { | |
3edc1cff | 522 | if (h->items[i].state == BRCMF_FWS_HANGER_ITEM_STATE_FREE) { |
6971280a | 523 | h->slot_pos = i; |
84bcc0c3 | 524 | goto done; |
6971280a AS |
525 | } |
526 | i++; | |
527 | if (i == BRCMF_FWS_HANGER_MAXITEMS) | |
528 | i = 0; | |
529 | } | |
530 | brcmf_err("all slots occupied\n"); | |
531 | h->failed_slotfind++; | |
84bcc0c3 AS |
532 | i = BRCMF_FWS_HANGER_MAXITEMS; |
533 | done: | |
84bcc0c3 | 534 | return i; |
6971280a AS |
535 | } |
536 | ||
3edc1cff | 537 | static int brcmf_fws_hanger_pushpkt(struct brcmf_fws_hanger *h, |
be4910ad | 538 | struct sk_buff *pkt, u32 slot_id) |
6971280a | 539 | { |
6971280a AS |
540 | if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS) |
541 | return -ENOENT; | |
542 | ||
543 | if (h->items[slot_id].state != BRCMF_FWS_HANGER_ITEM_STATE_FREE) { | |
544 | brcmf_err("slot is not free\n"); | |
545 | h->failed_to_push++; | |
546 | return -EINVAL; | |
547 | } | |
548 | ||
549 | h->items[slot_id].state = BRCMF_FWS_HANGER_ITEM_STATE_INUSE; | |
550 | h->items[slot_id].pkt = pkt; | |
6971280a AS |
551 | h->pushed++; |
552 | return 0; | |
553 | } | |
554 | ||
3edc1cff | 555 | static int brcmf_fws_hanger_poppkt(struct brcmf_fws_hanger *h, |
6971280a AS |
556 | u32 slot_id, struct sk_buff **pktout, |
557 | bool remove_item) | |
558 | { | |
6971280a AS |
559 | if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS) |
560 | return -ENOENT; | |
561 | ||
562 | if (h->items[slot_id].state == BRCMF_FWS_HANGER_ITEM_STATE_FREE) { | |
563 | brcmf_err("entry not in use\n"); | |
564 | h->failed_to_pop++; | |
565 | return -EINVAL; | |
566 | } | |
567 | ||
568 | *pktout = h->items[slot_id].pkt; | |
569 | if (remove_item) { | |
570 | h->items[slot_id].state = BRCMF_FWS_HANGER_ITEM_STATE_FREE; | |
571 | h->items[slot_id].pkt = NULL; | |
6971280a AS |
572 | h->popped++; |
573 | } | |
574 | return 0; | |
575 | } | |
576 | ||
84bcc0c3 | 577 | static int brcmf_fws_hanger_mark_suppressed(struct brcmf_fws_hanger *h, |
be4910ad | 578 | u32 slot_id) |
6971280a | 579 | { |
6971280a AS |
580 | if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS) |
581 | return -ENOENT; | |
582 | ||
3edc1cff | 583 | if (h->items[slot_id].state != BRCMF_FWS_HANGER_ITEM_STATE_INUSE) { |
6971280a AS |
584 | brcmf_err("entry not in use\n"); |
585 | return -EINVAL; | |
586 | } | |
587 | ||
3edc1cff | 588 | h->items[slot_id].state = BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED; |
6971280a AS |
589 | return 0; |
590 | } | |
591 | ||
84bcc0c3 | 592 | static void brcmf_fws_hanger_cleanup(struct brcmf_fws_info *fws, |
6971280a AS |
593 | bool (*fn)(struct sk_buff *, void *), |
594 | int ifidx) | |
595 | { | |
84bcc0c3 | 596 | struct brcmf_fws_hanger *h = &fws->hanger; |
6971280a AS |
597 | struct sk_buff *skb; |
598 | int i; | |
599 | enum brcmf_fws_hanger_item_state s; | |
600 | ||
6971280a AS |
601 | for (i = 0; i < ARRAY_SIZE(h->items); i++) { |
602 | s = h->items[i].state; | |
603 | if (s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE || | |
604 | s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED) { | |
605 | skb = h->items[i].pkt; | |
606 | if (fn == NULL || fn(skb, &ifidx)) { | |
607 | /* suppress packets freed from psq */ | |
608 | if (s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE) | |
609 | brcmu_pkt_buf_free_skb(skb); | |
610 | h->items[i].state = | |
611 | BRCMF_FWS_HANGER_ITEM_STATE_FREE; | |
612 | } | |
613 | } | |
614 | } | |
615 | } | |
616 | ||
8071fd61 AS |
617 | static void brcmf_fws_macdesc_set_name(struct brcmf_fws_info *fws, |
618 | struct brcmf_fws_mac_descriptor *desc) | |
619 | { | |
620 | if (desc == &fws->desc.other) | |
621 | strlcpy(desc->name, "MAC-OTHER", sizeof(desc->name)); | |
622 | else if (desc->mac_handle) | |
623 | scnprintf(desc->name, sizeof(desc->name), "MAC-%d:%d", | |
624 | desc->mac_handle, desc->interface_id); | |
625 | else | |
626 | scnprintf(desc->name, sizeof(desc->name), "MACIF:%d", | |
627 | desc->interface_id); | |
628 | } | |
629 | ||
ce814c1b AS |
630 | static void brcmf_fws_init_mac_descriptor(struct brcmf_fws_mac_descriptor *desc, |
631 | u8 *addr, u8 ifidx) | |
632 | { | |
84bcc0c3 AS |
633 | brcmf_dbg(TRACE, |
634 | "enter: desc %p ea=%pM, ifidx=%u\n", desc, addr, ifidx); | |
ce814c1b AS |
635 | desc->occupied = 1; |
636 | desc->state = BRCMF_FWS_STATE_OPEN; | |
637 | desc->requested_credit = 0; | |
638 | /* depending on use may need ifp->bssidx instead */ | |
639 | desc->interface_id = ifidx; | |
640 | desc->ac_bitmap = 0xff; /* update this when handling APSD */ | |
84bcc0c3 AS |
641 | if (addr) |
642 | memcpy(&desc->ea[0], addr, ETH_ALEN); | |
ce814c1b AS |
643 | } |
644 | ||
645 | static | |
646 | void brcmf_fws_clear_mac_descriptor(struct brcmf_fws_mac_descriptor *desc) | |
647 | { | |
648 | brcmf_dbg(TRACE, | |
649 | "enter: ea=%pM, ifidx=%u\n", desc->ea, desc->interface_id); | |
650 | desc->occupied = 0; | |
651 | desc->state = BRCMF_FWS_STATE_CLOSE; | |
652 | desc->requested_credit = 0; | |
653 | } | |
654 | ||
655 | static struct brcmf_fws_mac_descriptor * | |
656 | brcmf_fws_mac_descriptor_lookup(struct brcmf_fws_info *fws, u8 *ea) | |
657 | { | |
658 | struct brcmf_fws_mac_descriptor *entry; | |
659 | int i; | |
660 | ||
ce814c1b AS |
661 | if (ea == NULL) |
662 | return ERR_PTR(-EINVAL); | |
663 | ||
84bcc0c3 AS |
664 | entry = &fws->desc.nodes[0]; |
665 | for (i = 0; i < ARRAY_SIZE(fws->desc.nodes); i++) { | |
ce814c1b AS |
666 | if (entry->occupied && !memcmp(entry->ea, ea, ETH_ALEN)) |
667 | return entry; | |
668 | entry++; | |
669 | } | |
670 | ||
671 | return ERR_PTR(-ENOENT); | |
672 | } | |
673 | ||
3edc1cff | 674 | static struct brcmf_fws_mac_descriptor* |
f97a7f06 AS |
675 | brcmf_fws_find_mac_desc(struct brcmf_fws_info *fws, struct brcmf_if *ifp, |
676 | u8 *da) | |
3edc1cff | 677 | { |
84bcc0c3 | 678 | struct brcmf_fws_mac_descriptor *entry = &fws->desc.other; |
3edc1cff | 679 | bool multicast; |
3edc1cff | 680 | |
f97a7f06 | 681 | multicast = is_multicast_ether_addr(da); |
a7965fbb | 682 | |
5cd51c2b HM |
683 | /* Multicast destination, STA and P2P clients get the interface entry. |
684 | * STA/GC gets the Mac Entry for TDLS destinations, TDLS destinations | |
685 | * have their own entry. | |
3edc1cff | 686 | */ |
5cd51c2b | 687 | if (multicast && ifp->fws_desc) { |
3edc1cff | 688 | entry = ifp->fws_desc; |
3edc1cff | 689 | goto done; |
5cd51c2b | 690 | } |
3edc1cff AS |
691 | |
692 | entry = brcmf_fws_mac_descriptor_lookup(fws, da); | |
693 | if (IS_ERR(entry)) | |
5cd51c2b | 694 | entry = ifp->fws_desc; |
3edc1cff AS |
695 | |
696 | done: | |
3edc1cff AS |
697 | return entry; |
698 | } | |
699 | ||
b75c1a30 AS |
700 | static bool brcmf_fws_mac_desc_closed(struct brcmf_fws_info *fws, |
701 | struct brcmf_fws_mac_descriptor *entry, | |
9fc60224 | 702 | int fifo) |
84bcc0c3 | 703 | { |
b75c1a30 | 704 | struct brcmf_fws_mac_descriptor *if_entry; |
9fc60224 | 705 | bool closed; |
84bcc0c3 | 706 | |
b75c1a30 AS |
707 | /* for unique destination entries the related interface |
708 | * may be closed. | |
709 | */ | |
710 | if (entry->mac_handle) { | |
711 | if_entry = &fws->desc.iface[entry->interface_id]; | |
712 | if (if_entry->state == BRCMF_FWS_STATE_CLOSE) | |
713 | return true; | |
714 | } | |
9fc60224 AS |
715 | /* an entry is closed when the state is closed and |
716 | * the firmware did not request anything. | |
84bcc0c3 | 717 | */ |
9fc60224 AS |
718 | closed = entry->state == BRCMF_FWS_STATE_CLOSE && |
719 | !entry->requested_credit && !entry->requested_packet; | |
84bcc0c3 | 720 | |
9fc60224 AS |
721 | /* Or firmware does not allow traffic for given fifo */ |
722 | return closed || !(entry->ac_bitmap & BIT(fifo)); | |
84bcc0c3 AS |
723 | } |
724 | ||
3edc1cff AS |
725 | static void brcmf_fws_mac_desc_cleanup(struct brcmf_fws_info *fws, |
726 | struct brcmf_fws_mac_descriptor *entry, | |
fba1400a AS |
727 | int ifidx) |
728 | { | |
3edc1cff | 729 | if (entry->occupied && (ifidx == -1 || ifidx == entry->interface_id)) { |
3edc1cff | 730 | brcmf_fws_psq_flush(fws, &entry->psq, ifidx); |
fba1400a AS |
731 | entry->occupied = !!(entry->psq.len); |
732 | } | |
733 | } | |
734 | ||
e2432b67 AS |
735 | static void brcmf_fws_bus_txq_cleanup(struct brcmf_fws_info *fws, |
736 | bool (*fn)(struct sk_buff *, void *), | |
737 | int ifidx) | |
738 | { | |
739 | struct brcmf_fws_hanger_item *hi; | |
740 | struct pktq *txq; | |
741 | struct sk_buff *skb; | |
742 | int prec; | |
743 | u32 hslot; | |
744 | ||
e2432b67 AS |
745 | txq = brcmf_bus_gettxq(fws->drvr->bus_if); |
746 | if (IS_ERR(txq)) { | |
747 | brcmf_dbg(TRACE, "no txq to clean up\n"); | |
748 | return; | |
749 | } | |
750 | ||
751 | for (prec = 0; prec < txq->num_prec; prec++) { | |
752 | skb = brcmu_pktq_pdeq_match(txq, prec, fn, &ifidx); | |
753 | while (skb) { | |
754 | hslot = brcmf_skb_htod_tag_get_field(skb, HSLOT); | |
755 | hi = &fws->hanger.items[hslot]; | |
756 | WARN_ON(skb != hi->pkt); | |
757 | hi->state = BRCMF_FWS_HANGER_ITEM_STATE_FREE; | |
758 | brcmu_pkt_buf_free_skb(skb); | |
759 | skb = brcmu_pktq_pdeq_match(txq, prec, fn, &ifidx); | |
760 | } | |
761 | } | |
762 | } | |
763 | ||
fba1400a AS |
764 | static void brcmf_fws_cleanup(struct brcmf_fws_info *fws, int ifidx) |
765 | { | |
766 | int i; | |
767 | struct brcmf_fws_mac_descriptor *table; | |
a3e993c7 | 768 | bool (*matchfn)(struct sk_buff *, void *) = NULL; |
fba1400a | 769 | |
fba1400a AS |
770 | if (fws == NULL) |
771 | return; | |
772 | ||
a3e993c7 AS |
773 | if (ifidx != -1) |
774 | matchfn = brcmf_fws_ifidx_match; | |
775 | ||
fba1400a | 776 | /* cleanup individual nodes */ |
84bcc0c3 AS |
777 | table = &fws->desc.nodes[0]; |
778 | for (i = 0; i < ARRAY_SIZE(fws->desc.nodes); i++) | |
3edc1cff | 779 | brcmf_fws_mac_desc_cleanup(fws, &table[i], ifidx); |
fba1400a | 780 | |
84bcc0c3 | 781 | brcmf_fws_mac_desc_cleanup(fws, &fws->desc.other, ifidx); |
e2432b67 | 782 | brcmf_fws_bus_txq_cleanup(fws, matchfn, ifidx); |
84bcc0c3 AS |
783 | brcmf_fws_hanger_cleanup(fws, matchfn, ifidx); |
784 | } | |
785 | ||
786 | static void brcmf_fws_tim_update(struct brcmf_fws_info *ctx, | |
787 | struct brcmf_fws_mac_descriptor *entry, | |
788 | int prec) | |
789 | { | |
84bcc0c3 AS |
790 | if (entry->state == BRCMF_FWS_STATE_CLOSE) { |
791 | /* check delayedQ and suppressQ in one call using bitmap */ | |
792 | if (brcmu_pktq_mlen(&entry->psq, 3 << (prec * 2)) == 0) | |
793 | entry->traffic_pending_bmp = | |
794 | entry->traffic_pending_bmp & ~NBITVAL(prec); | |
795 | else | |
796 | entry->traffic_pending_bmp = | |
797 | entry->traffic_pending_bmp | NBITVAL(prec); | |
798 | } | |
799 | /* request a TIM update to firmware at the next piggyback opportunity */ | |
800 | if (entry->traffic_lastreported_bmp != entry->traffic_pending_bmp) | |
801 | entry->send_tim_signal = true; | |
802 | } | |
803 | ||
804 | static void | |
805 | brcmf_fws_flow_control_check(struct brcmf_fws_info *fws, struct pktq *pq, | |
806 | u8 if_id) | |
807 | { | |
402e3ba2 | 808 | struct brcmf_if *ifp = fws->drvr->iflist[!if_id ? 0 : if_id + 1]; |
84bcc0c3 | 809 | |
84bcc0c3 AS |
810 | if (WARN_ON(!ifp)) |
811 | return; | |
812 | ||
813 | if ((ifp->netif_stop & BRCMF_NETIF_STOP_REASON_FWS_FC) && | |
814 | pq->len <= BRCMF_FWS_FLOWCONTROL_LOWATER) | |
815 | brcmf_txflowblock_if(ifp, | |
816 | BRCMF_NETIF_STOP_REASON_FWS_FC, false); | |
817 | if (!(ifp->netif_stop & BRCMF_NETIF_STOP_REASON_FWS_FC) && | |
818 | pq->len >= BRCMF_FWS_FLOWCONTROL_HIWATER) | |
819 | brcmf_txflowblock_if(ifp, BRCMF_NETIF_STOP_REASON_FWS_FC, true); | |
820 | return; | |
fba1400a AS |
821 | } |
822 | ||
349e7104 AS |
823 | static int brcmf_fws_rssi_indicate(struct brcmf_fws_info *fws, s8 rssi) |
824 | { | |
825 | brcmf_dbg(CTL, "rssi %d\n", rssi); | |
826 | return 0; | |
827 | } | |
828 | ||
ce814c1b AS |
829 | static |
830 | int brcmf_fws_macdesc_indicate(struct brcmf_fws_info *fws, u8 type, u8 *data) | |
831 | { | |
832 | struct brcmf_fws_mac_descriptor *entry, *existing; | |
833 | u8 mac_handle; | |
834 | u8 ifidx; | |
835 | u8 *addr; | |
836 | ||
837 | mac_handle = *data++; | |
838 | ifidx = *data++; | |
839 | addr = data; | |
840 | ||
84bcc0c3 | 841 | entry = &fws->desc.nodes[mac_handle & 0x1F]; |
ce814c1b | 842 | if (type == BRCMF_FWS_TYPE_MACDESC_DEL) { |
9a83f1ec | 843 | if (entry->occupied) { |
8071fd61 AS |
844 | brcmf_dbg(TRACE, "deleting %s mac %pM\n", |
845 | entry->name, addr); | |
9a83f1ec | 846 | brcmf_fws_mac_desc_cleanup(fws, entry, -1); |
3edc1cff | 847 | brcmf_fws_clear_mac_descriptor(entry); |
9a83f1ec | 848 | } else |
ce814c1b | 849 | fws->stats.mac_update_failed++; |
ce814c1b AS |
850 | return 0; |
851 | } | |
852 | ||
ce814c1b AS |
853 | existing = brcmf_fws_mac_descriptor_lookup(fws, addr); |
854 | if (IS_ERR(existing)) { | |
855 | if (!entry->occupied) { | |
856 | entry->mac_handle = mac_handle; | |
857 | brcmf_fws_init_mac_descriptor(entry, addr, ifidx); | |
8071fd61 | 858 | brcmf_fws_macdesc_set_name(fws, entry); |
ce814c1b AS |
859 | brcmu_pktq_init(&entry->psq, BRCMF_FWS_PSQ_PREC_COUNT, |
860 | BRCMF_FWS_PSQ_LEN); | |
8071fd61 | 861 | brcmf_dbg(TRACE, "add %s mac %pM\n", entry->name, addr); |
ce814c1b AS |
862 | } else { |
863 | fws->stats.mac_update_failed++; | |
864 | } | |
865 | } else { | |
866 | if (entry != existing) { | |
8071fd61 | 867 | brcmf_dbg(TRACE, "copy mac %s\n", existing->name); |
ce814c1b AS |
868 | memcpy(entry, existing, |
869 | offsetof(struct brcmf_fws_mac_descriptor, psq)); | |
870 | entry->mac_handle = mac_handle; | |
871 | brcmf_fws_clear_mac_descriptor(existing); | |
8071fd61 AS |
872 | brcmf_fws_macdesc_set_name(fws, entry); |
873 | brcmf_dbg(TRACE, "relocate %s mac %pM\n", entry->name, | |
874 | addr); | |
ce814c1b AS |
875 | } else { |
876 | brcmf_dbg(TRACE, "use existing\n"); | |
877 | WARN_ON(entry->mac_handle != mac_handle); | |
878 | /* TODO: what should we do here: continue, reinit, .. */ | |
879 | } | |
880 | } | |
881 | return 0; | |
882 | } | |
883 | ||
33753d47 AS |
884 | static int brcmf_fws_macdesc_state_indicate(struct brcmf_fws_info *fws, |
885 | u8 type, u8 *data) | |
886 | { | |
887 | struct brcmf_fws_mac_descriptor *entry; | |
888 | u8 mac_handle; | |
889 | int i; | |
890 | ||
891 | mac_handle = data[0]; | |
892 | entry = &fws->desc.nodes[mac_handle & 0x1F]; | |
893 | if (!entry->occupied) { | |
894 | fws->stats.mac_ps_update_failed++; | |
895 | return -ESRCH; | |
896 | } | |
897 | ||
8071fd61 AS |
898 | brcmf_dbg(TRACE, "%s (%d): %s\n", brcmf_fws_get_tlv_name(type), type, |
899 | entry->name); | |
33753d47 AS |
900 | /* a state update should wipe old credits? */ |
901 | entry->requested_credit = 0; | |
902 | if (type == BRCMF_FWS_TYPE_MAC_OPEN) { | |
903 | entry->state = BRCMF_FWS_STATE_OPEN; | |
a5e9d805 | 904 | return BRCMF_FWS_RET_OK_SCHEDULE; |
33753d47 AS |
905 | } else { |
906 | entry->state = BRCMF_FWS_STATE_CLOSE; | |
907 | for (i = BRCMF_FWS_FIFO_AC_BE; i < NL80211_NUM_ACS; i++) | |
908 | brcmf_fws_tim_update(fws, entry, i); | |
909 | } | |
a5e9d805 | 910 | return BRCMF_FWS_RET_OK_NOSCHEDULE; |
33753d47 AS |
911 | } |
912 | ||
913 | static int brcmf_fws_interface_state_indicate(struct brcmf_fws_info *fws, | |
914 | u8 type, u8 *data) | |
915 | { | |
916 | struct brcmf_fws_mac_descriptor *entry; | |
917 | u8 ifidx; | |
918 | int ret; | |
919 | ||
920 | ifidx = data[0]; | |
921 | ||
33753d47 AS |
922 | if (ifidx >= BRCMF_MAX_IFS) { |
923 | ret = -ERANGE; | |
924 | goto fail; | |
925 | } | |
926 | ||
927 | entry = &fws->desc.iface[ifidx]; | |
928 | if (!entry->occupied) { | |
929 | ret = -ESRCH; | |
930 | goto fail; | |
931 | } | |
932 | ||
8071fd61 AS |
933 | brcmf_dbg(TRACE, "%s (%d): %s\n", brcmf_fws_get_tlv_name(type), type, |
934 | entry->name); | |
33753d47 AS |
935 | switch (type) { |
936 | case BRCMF_FWS_TYPE_INTERFACE_OPEN: | |
937 | entry->state = BRCMF_FWS_STATE_OPEN; | |
a5e9d805 | 938 | return BRCMF_FWS_RET_OK_SCHEDULE; |
33753d47 AS |
939 | case BRCMF_FWS_TYPE_INTERFACE_CLOSE: |
940 | entry->state = BRCMF_FWS_STATE_CLOSE; | |
a5e9d805 | 941 | return BRCMF_FWS_RET_OK_NOSCHEDULE; |
33753d47 AS |
942 | default: |
943 | ret = -EINVAL; | |
944 | break; | |
945 | } | |
946 | fail: | |
947 | fws->stats.if_update_failed++; | |
948 | return ret; | |
949 | } | |
950 | ||
5f38b683 AS |
951 | static int brcmf_fws_request_indicate(struct brcmf_fws_info *fws, u8 type, |
952 | u8 *data) | |
953 | { | |
954 | struct brcmf_fws_mac_descriptor *entry; | |
955 | ||
956 | entry = &fws->desc.nodes[data[1] & 0x1F]; | |
957 | if (!entry->occupied) { | |
958 | if (type == BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT) | |
959 | fws->stats.credit_request_failed++; | |
960 | else | |
961 | fws->stats.packet_request_failed++; | |
962 | return -ESRCH; | |
963 | } | |
964 | ||
8071fd61 AS |
965 | brcmf_dbg(TRACE, "%s (%d): %s cnt %d bmp %d\n", |
966 | brcmf_fws_get_tlv_name(type), type, entry->name, | |
967 | data[0], data[2]); | |
5f38b683 AS |
968 | if (type == BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT) |
969 | entry->requested_credit = data[0]; | |
970 | else | |
971 | entry->requested_packet = data[0]; | |
972 | ||
973 | entry->ac_bitmap = data[2]; | |
a5e9d805 | 974 | return BRCMF_FWS_RET_OK_SCHEDULE; |
5f38b683 AS |
975 | } |
976 | ||
289ec1c7 AS |
977 | static int brcmf_fws_macdesc_use_credit(struct brcmf_fws_mac_descriptor *entry, |
978 | struct sk_buff *skb) | |
979 | { | |
980 | int use_credit = 1; | |
981 | ||
982 | if (entry->state == BRCMF_FWS_STATE_CLOSE) { | |
983 | if (entry->requested_credit > 0) { | |
984 | /* | |
985 | * if the packet was pulled out while destination is in | |
986 | * closed state but had a non-zero packets requested, | |
987 | * then this should not count against the FIFO credit. | |
988 | * That is due to the fact that the firmware will | |
989 | * most likely hold onto this packet until a suitable | |
990 | * time later to push it to the appropriate AC FIFO. | |
991 | */ | |
992 | entry->requested_credit--; | |
993 | brcmf_skb_if_flags_set_field(skb, REQ_CREDIT, 1); | |
994 | use_credit = 0; | |
995 | } else if (entry->requested_packet > 0) { | |
996 | entry->requested_packet--; | |
997 | brcmf_skb_if_flags_set_field(skb, REQUESTED, 1); | |
998 | use_credit = 0; | |
999 | } | |
1000 | } else { | |
1001 | WARN_ON(entry->requested_credit); | |
1002 | WARN_ON(entry->requested_packet); | |
1003 | } | |
1004 | brcmf_skb_if_flags_set_field(skb, CREDITCHECK, use_credit); | |
1005 | return use_credit; | |
1006 | } | |
1007 | ||
84bcc0c3 AS |
1008 | static void brcmf_fws_return_credits(struct brcmf_fws_info *fws, |
1009 | u8 fifo, u8 credits) | |
1010 | { | |
1aac1e91 AS |
1011 | int lender_ac; |
1012 | int *borrowed; | |
1013 | int *fifo_credit; | |
1014 | ||
84bcc0c3 AS |
1015 | if (!credits) |
1016 | return; | |
1017 | ||
afc3bbfc HM |
1018 | fws->fifo_credit_map |= 1 << fifo; |
1019 | ||
1aac1e91 AS |
1020 | if ((fifo == BRCMF_FWS_FIFO_AC_BE) && |
1021 | (fws->credits_borrowed[0])) { | |
1022 | for (lender_ac = BRCMF_FWS_FIFO_AC_VO; lender_ac >= 0; | |
1023 | lender_ac--) { | |
1024 | borrowed = &fws->credits_borrowed[lender_ac]; | |
1025 | if (*borrowed) { | |
1026 | fws->fifo_credit_map |= (1 << lender_ac); | |
1027 | fifo_credit = &fws->fifo_credit[lender_ac]; | |
1028 | if (*borrowed >= credits) { | |
1029 | *borrowed -= credits; | |
1030 | *fifo_credit += credits; | |
1031 | return; | |
1032 | } else { | |
1033 | credits -= *borrowed; | |
1034 | *fifo_credit += *borrowed; | |
1035 | *borrowed = 0; | |
1036 | } | |
1037 | } | |
1038 | } | |
1039 | } | |
1040 | ||
84bcc0c3 AS |
1041 | fws->fifo_credit[fifo] += credits; |
1042 | } | |
1043 | ||
1044 | static void brcmf_fws_schedule_deq(struct brcmf_fws_info *fws) | |
1045 | { | |
1046 | /* only schedule dequeue when there are credits for delayed traffic */ | |
1047 | if (fws->fifo_credit_map & fws->fifo_delay_map) | |
1048 | queue_work(fws->fws_wq, &fws->fws_dequeue_work); | |
1049 | } | |
1050 | ||
fe353b24 | 1051 | static void brcmf_fws_skb_pickup_credit(struct brcmf_fws_info *fws, int fifo, |
84bcc0c3 AS |
1052 | struct sk_buff *p) |
1053 | { | |
1054 | struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(p)->mac; | |
1055 | ||
fe353b24 | 1056 | if (brcmf_skbcb(p)->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK) |
84bcc0c3 | 1057 | brcmf_fws_return_credits(fws, fifo, 1); |
289ec1c7 AS |
1058 | else if (brcmf_skb_if_flags_get_field(p, REQ_CREDIT) && |
1059 | entry->state == BRCMF_FWS_STATE_CLOSE) | |
84bcc0c3 AS |
1060 | /* |
1061 | * if this packet did not count against FIFO credit, it | |
289ec1c7 | 1062 | * could have taken a requested_credit from the destination |
84bcc0c3 AS |
1063 | * entry (for pspoll etc.) |
1064 | */ | |
fe353b24 AS |
1065 | entry->requested_credit++; |
1066 | ||
84bcc0c3 AS |
1067 | brcmf_fws_schedule_deq(fws); |
1068 | } | |
1069 | ||
1070 | static int brcmf_fws_enq(struct brcmf_fws_info *fws, | |
1071 | enum brcmf_fws_skb_state state, int fifo, | |
1072 | struct sk_buff *p) | |
1073 | { | |
1074 | int prec = 2 * fifo; | |
1075 | u32 *qfull_stat = &fws->stats.delayq_full_error; | |
1076 | ||
1077 | struct brcmf_fws_mac_descriptor *entry; | |
1078 | ||
1079 | entry = brcmf_skbcb(p)->mac; | |
1080 | if (entry == NULL) { | |
1081 | brcmf_err("no mac descriptor found for skb %p\n", p); | |
1082 | return -ENOENT; | |
1083 | } | |
1084 | ||
8071fd61 | 1085 | brcmf_dbg(DATA, "enter: fifo %d skb %p\n", fifo, p); |
84bcc0c3 AS |
1086 | if (state == BRCMF_FWS_SKBSTATE_SUPPRESSED) { |
1087 | prec += 1; | |
1088 | qfull_stat = &fws->stats.supprq_full_error; | |
1089 | } | |
1090 | ||
1091 | if (brcmu_pktq_penq(&entry->psq, prec, p) == NULL) { | |
1092 | *qfull_stat += 1; | |
1093 | return -ENFILE; | |
1094 | } | |
1095 | ||
1096 | /* increment total enqueued packet count */ | |
1097 | fws->fifo_delay_map |= 1 << fifo; | |
1098 | fws->fifo_enqpkt[fifo]++; | |
1099 | ||
1100 | /* update the sk_buff state */ | |
1101 | brcmf_skbcb(p)->state = state; | |
84bcc0c3 AS |
1102 | |
1103 | /* | |
1104 | * A packet has been pushed so update traffic | |
1105 | * availability bitmap, if applicable | |
1106 | */ | |
1107 | brcmf_fws_tim_update(fws, entry, fifo); | |
1108 | brcmf_fws_flow_control_check(fws, &entry->psq, | |
1109 | brcmf_skb_if_flags_get_field(p, INDEX)); | |
1110 | return 0; | |
1111 | } | |
1112 | ||
1113 | static struct sk_buff *brcmf_fws_deq(struct brcmf_fws_info *fws, int fifo) | |
1114 | { | |
1115 | struct brcmf_fws_mac_descriptor *table; | |
1116 | struct brcmf_fws_mac_descriptor *entry; | |
1117 | struct sk_buff *p; | |
84bcc0c3 AS |
1118 | int num_nodes; |
1119 | int node_pos; | |
1120 | int prec_out; | |
07529d20 | 1121 | int pmsk; |
84bcc0c3 AS |
1122 | int i; |
1123 | ||
1124 | table = (struct brcmf_fws_mac_descriptor *)&fws->desc; | |
1125 | num_nodes = sizeof(fws->desc) / sizeof(struct brcmf_fws_mac_descriptor); | |
1126 | node_pos = fws->deq_node_pos[fifo]; | |
1127 | ||
1128 | for (i = 0; i < num_nodes; i++) { | |
1129 | entry = &table[(node_pos + i) % num_nodes]; | |
b75c1a30 AS |
1130 | if (!entry->occupied || |
1131 | brcmf_fws_mac_desc_closed(fws, entry, fifo)) | |
84bcc0c3 AS |
1132 | continue; |
1133 | ||
1134 | if (entry->suppressed) | |
1135 | pmsk = 2; | |
07529d20 AS |
1136 | else |
1137 | pmsk = 3; | |
84bcc0c3 AS |
1138 | p = brcmu_pktq_mdeq(&entry->psq, pmsk << (fifo * 2), &prec_out); |
1139 | if (p == NULL) { | |
1140 | if (entry->suppressed) { | |
8c5140f6 HM |
1141 | if (entry->suppr_transit_count) |
1142 | continue; | |
84bcc0c3 AS |
1143 | entry->suppressed = false; |
1144 | p = brcmu_pktq_mdeq(&entry->psq, | |
1145 | 1 << (fifo * 2), &prec_out); | |
1146 | } | |
1147 | } | |
1148 | if (p == NULL) | |
1149 | continue; | |
1150 | ||
289ec1c7 | 1151 | brcmf_fws_macdesc_use_credit(entry, p); |
84bcc0c3 AS |
1152 | |
1153 | /* move dequeue position to ensure fair round-robin */ | |
1154 | fws->deq_node_pos[fifo] = (node_pos + i + 1) % num_nodes; | |
1155 | brcmf_fws_flow_control_check(fws, &entry->psq, | |
1156 | brcmf_skb_if_flags_get_field(p, | |
1157 | INDEX) | |
1158 | ); | |
1159 | /* | |
1160 | * A packet has been picked up, update traffic | |
1161 | * availability bitmap, if applicable | |
1162 | */ | |
1163 | brcmf_fws_tim_update(fws, entry, fifo); | |
1164 | ||
1165 | /* | |
1166 | * decrement total enqueued fifo packets and | |
1167 | * clear delay bitmap if done. | |
1168 | */ | |
1169 | fws->fifo_enqpkt[fifo]--; | |
1170 | if (fws->fifo_enqpkt[fifo] == 0) | |
1171 | fws->fifo_delay_map &= ~(1 << fifo); | |
1172 | goto done; | |
1173 | } | |
1174 | p = NULL; | |
1175 | done: | |
8071fd61 | 1176 | brcmf_dbg(DATA, "exit: fifo %d skb %p\n", fifo, p); |
84bcc0c3 AS |
1177 | return p; |
1178 | } | |
1179 | ||
1180 | static int brcmf_fws_txstatus_suppressed(struct brcmf_fws_info *fws, int fifo, | |
1181 | struct sk_buff *skb, u32 genbit) | |
1182 | { | |
1183 | struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(skb)->mac; | |
1184 | u32 hslot; | |
1185 | int ret; | |
2747e5f7 | 1186 | u8 ifidx; |
84bcc0c3 AS |
1187 | |
1188 | hslot = brcmf_skb_htod_tag_get_field(skb, HSLOT); | |
1189 | ||
1190 | /* this packet was suppressed */ | |
be4910ad | 1191 | if (!entry->suppressed) { |
84bcc0c3 | 1192 | entry->suppressed = true; |
84bcc0c3 | 1193 | entry->suppr_transit_count = entry->transit_count; |
8c5140f6 HM |
1194 | brcmf_dbg(DATA, "suppress %s: transit %d\n", |
1195 | entry->name, entry->transit_count); | |
84bcc0c3 AS |
1196 | } |
1197 | ||
1198 | entry->generation = genbit; | |
1199 | ||
2747e5f7 HM |
1200 | ret = brcmf_proto_hdrpull(fws->drvr, false, &ifidx, skb); |
1201 | if (ret == 0) | |
1202 | ret = brcmf_fws_enq(fws, BRCMF_FWS_SKBSTATE_SUPPRESSED, fifo, | |
1203 | skb); | |
84bcc0c3 | 1204 | if (ret != 0) { |
2747e5f7 | 1205 | /* suppress q is full or hdrpull failed, drop this packet */ |
84bcc0c3 AS |
1206 | brcmf_fws_hanger_poppkt(&fws->hanger, hslot, &skb, |
1207 | true); | |
1208 | } else { | |
1209 | /* | |
1210 | * Mark suppressed to avoid a double free during | |
1211 | * wlfc cleanup | |
1212 | */ | |
be4910ad | 1213 | brcmf_fws_hanger_mark_suppressed(&fws->hanger, hslot); |
84bcc0c3 AS |
1214 | } |
1215 | ||
1216 | return ret; | |
1217 | } | |
1218 | ||
3edc1cff | 1219 | static int |
8071fd61 | 1220 | brcmf_fws_txs_process(struct brcmf_fws_info *fws, u8 flags, u32 hslot, |
84bcc0c3 | 1221 | u32 genbit) |
3edc1cff | 1222 | { |
84bcc0c3 | 1223 | u32 fifo; |
3edc1cff | 1224 | int ret; |
84bcc0c3 | 1225 | bool remove_from_hanger = true; |
3edc1cff | 1226 | struct sk_buff *skb; |
8071fd61 | 1227 | struct brcmf_skbuff_cb *skcb; |
3edc1cff AS |
1228 | struct brcmf_fws_mac_descriptor *entry = NULL; |
1229 | ||
8071fd61 | 1230 | brcmf_dbg(DATA, "flags %d\n", flags); |
3edc1cff AS |
1231 | |
1232 | if (flags == BRCMF_FWS_TXSTATUS_DISCARD) | |
1233 | fws->stats.txs_discard++; | |
84bcc0c3 AS |
1234 | else if (flags == BRCMF_FWS_TXSTATUS_CORE_SUPPRESS) { |
1235 | fws->stats.txs_supp_core++; | |
1236 | remove_from_hanger = false; | |
1237 | } else if (flags == BRCMF_FWS_TXSTATUS_FW_PS_SUPPRESS) { | |
1238 | fws->stats.txs_supp_ps++; | |
1239 | remove_from_hanger = false; | |
1240 | } else if (flags == BRCMF_FWS_TXSTATUS_FW_TOSSED) | |
3edc1cff AS |
1241 | fws->stats.txs_tossed++; |
1242 | else | |
1243 | brcmf_err("unexpected txstatus\n"); | |
1244 | ||
1245 | ret = brcmf_fws_hanger_poppkt(&fws->hanger, hslot, &skb, | |
84bcc0c3 | 1246 | remove_from_hanger); |
3edc1cff AS |
1247 | if (ret != 0) { |
1248 | brcmf_err("no packet in hanger slot: hslot=%d\n", hslot); | |
1249 | return ret; | |
1250 | } | |
1251 | ||
8071fd61 AS |
1252 | skcb = brcmf_skbcb(skb); |
1253 | entry = skcb->mac; | |
3edc1cff | 1254 | if (WARN_ON(!entry)) { |
84bcc0c3 AS |
1255 | brcmu_pkt_buf_free_skb(skb); |
1256 | return -EINVAL; | |
3edc1cff | 1257 | } |
8c5140f6 HM |
1258 | entry->transit_count--; |
1259 | if (entry->suppressed && entry->suppr_transit_count) | |
1260 | entry->suppr_transit_count--; | |
3edc1cff | 1261 | |
8071fd61 AS |
1262 | brcmf_dbg(DATA, "%s flags %X htod %X\n", entry->name, skcb->if_flags, |
1263 | skcb->htod); | |
1264 | ||
84bcc0c3 AS |
1265 | /* pick up the implicit credit from this packet */ |
1266 | fifo = brcmf_skb_htod_tag_get_field(skb, FIFO); | |
fe353b24 AS |
1267 | if (fws->fcmode == BRCMF_FWS_FCMODE_IMPLIED_CREDIT || |
1268 | !(brcmf_skbcb(skb)->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK)) | |
1269 | brcmf_fws_skb_pickup_credit(fws, fifo, skb); | |
3edc1cff | 1270 | |
84bcc0c3 AS |
1271 | if (!remove_from_hanger) |
1272 | ret = brcmf_fws_txstatus_suppressed(fws, fifo, skb, genbit); | |
1273 | ||
8c5140f6 | 1274 | if (remove_from_hanger || ret) |
84bcc0c3 | 1275 | brcmf_txfinalize(fws->drvr, skb, true); |
8c5140f6 | 1276 | |
84bcc0c3 AS |
1277 | return 0; |
1278 | } | |
1279 | ||
1280 | static int brcmf_fws_fifocreditback_indicate(struct brcmf_fws_info *fws, | |
1281 | u8 *data) | |
1282 | { | |
1283 | int i; | |
1284 | ||
1285 | if (fws->fcmode != BRCMF_FWS_FCMODE_EXPLICIT_CREDIT) { | |
1286 | brcmf_dbg(INFO, "ignored\n"); | |
a5e9d805 | 1287 | return BRCMF_FWS_RET_OK_NOSCHEDULE; |
84bcc0c3 AS |
1288 | } |
1289 | ||
8071fd61 | 1290 | brcmf_dbg(DATA, "enter: data %pM\n", data); |
84bcc0c3 AS |
1291 | for (i = 0; i < BRCMF_FWS_FIFO_COUNT; i++) |
1292 | brcmf_fws_return_credits(fws, i, data[i]); | |
1293 | ||
8071fd61 | 1294 | brcmf_dbg(DATA, "map: credit %x delay %x\n", fws->fifo_credit_map, |
84bcc0c3 | 1295 | fws->fifo_delay_map); |
a5e9d805 | 1296 | return BRCMF_FWS_RET_OK_SCHEDULE; |
3edc1cff AS |
1297 | } |
1298 | ||
0f8b5cc5 AS |
1299 | static int brcmf_fws_txstatus_indicate(struct brcmf_fws_info *fws, u8 *data) |
1300 | { | |
a2ffc566 | 1301 | __le32 status_le; |
0f8b5cc5 AS |
1302 | u32 status; |
1303 | u32 hslot; | |
84bcc0c3 | 1304 | u32 genbit; |
0f8b5cc5 AS |
1305 | u8 flags; |
1306 | ||
1307 | fws->stats.txs_indicate++; | |
a2ffc566 AS |
1308 | memcpy(&status_le, data, sizeof(status_le)); |
1309 | status = le32_to_cpu(status_le); | |
0f8b5cc5 AS |
1310 | flags = brcmf_txstatus_get_field(status, FLAGS); |
1311 | hslot = brcmf_txstatus_get_field(status, HSLOT); | |
84bcc0c3 | 1312 | genbit = brcmf_txstatus_get_field(status, GENERATION); |
0f8b5cc5 | 1313 | |
8071fd61 | 1314 | return brcmf_fws_txs_process(fws, flags, hslot, genbit); |
0f8b5cc5 AS |
1315 | } |
1316 | ||
349e7104 AS |
1317 | static int brcmf_fws_dbg_seqnum_check(struct brcmf_fws_info *fws, u8 *data) |
1318 | { | |
1319 | __le32 timestamp; | |
1320 | ||
1321 | memcpy(×tamp, &data[2], sizeof(timestamp)); | |
8071fd61 | 1322 | brcmf_dbg(CTL, "received: seq %d, timestamp %d\n", data[1], |
349e7104 AS |
1323 | le32_to_cpu(timestamp)); |
1324 | return 0; | |
1325 | } | |
1326 | ||
1327 | /* using macro so sparse checking does not complain | |
1328 | * about locking imbalance. | |
1329 | */ | |
1330 | #define brcmf_fws_lock(drvr, flags) \ | |
1331 | do { \ | |
1332 | flags = 0; \ | |
1333 | spin_lock_irqsave(&((drvr)->fws_spinlock), (flags)); \ | |
1334 | } while (0) | |
1335 | ||
1336 | /* using macro so sparse checking does not complain | |
1337 | * about locking imbalance. | |
1338 | */ | |
1339 | #define brcmf_fws_unlock(drvr, flags) \ | |
1340 | spin_unlock_irqrestore(&((drvr)->fws_spinlock), (flags)) | |
1341 | ||
43fa635e AS |
1342 | static int brcmf_fws_notify_credit_map(struct brcmf_if *ifp, |
1343 | const struct brcmf_event_msg *e, | |
1344 | void *data) | |
1345 | { | |
1346 | struct brcmf_fws_info *fws = ifp->drvr->fws; | |
1347 | int i; | |
1348 | ulong flags; | |
1349 | u8 *credits = data; | |
1350 | ||
84bcc0c3 AS |
1351 | if (e->datalen < BRCMF_FWS_FIFO_COUNT) { |
1352 | brcmf_err("event payload too small (%d)\n", e->datalen); | |
1353 | return -EINVAL; | |
1354 | } | |
0d24b0ea HM |
1355 | if (fws->creditmap_received) |
1356 | return 0; | |
1357 | ||
1358 | fws->creditmap_received = true; | |
84bcc0c3 AS |
1359 | |
1360 | brcmf_dbg(TRACE, "enter: credits %pM\n", credits); | |
43fa635e | 1361 | brcmf_fws_lock(ifp->drvr, flags); |
84bcc0c3 AS |
1362 | for (i = 0; i < ARRAY_SIZE(fws->fifo_credit); i++) { |
1363 | if (*credits) | |
1364 | fws->fifo_credit_map |= 1 << i; | |
1365 | else | |
1366 | fws->fifo_credit_map &= ~(1 << i); | |
43fa635e | 1367 | fws->fifo_credit[i] = *credits++; |
84bcc0c3 AS |
1368 | } |
1369 | brcmf_fws_schedule_deq(fws); | |
43fa635e AS |
1370 | brcmf_fws_unlock(ifp->drvr, flags); |
1371 | return 0; | |
1372 | } | |
1373 | ||
349e7104 AS |
1374 | int brcmf_fws_hdrpull(struct brcmf_pub *drvr, int ifidx, s16 signal_len, |
1375 | struct sk_buff *skb) | |
1376 | { | |
1377 | struct brcmf_fws_info *fws = drvr->fws; | |
1378 | ulong flags; | |
1379 | u8 *signal_data; | |
1380 | s16 data_len; | |
1381 | u8 type; | |
1382 | u8 len; | |
1383 | u8 *data; | |
a5e9d805 AS |
1384 | s32 status; |
1385 | s32 err; | |
349e7104 | 1386 | |
8071fd61 | 1387 | brcmf_dbg(HDRS, "enter: ifidx %d, skblen %u, sig %d\n", |
349e7104 AS |
1388 | ifidx, skb->len, signal_len); |
1389 | ||
1390 | WARN_ON(signal_len > skb->len); | |
1391 | ||
1392 | /* if flow control disabled, skip to packet data and leave */ | |
1393 | if (!signal_len || !drvr->fw_signals) { | |
1394 | skb_pull(skb, signal_len); | |
1395 | return 0; | |
1396 | } | |
1397 | ||
1398 | /* lock during tlv parsing */ | |
1399 | brcmf_fws_lock(drvr, flags); | |
1400 | ||
1401 | fws->stats.header_pulls++; | |
1402 | data_len = signal_len; | |
1403 | signal_data = skb->data; | |
1404 | ||
a5e9d805 | 1405 | status = BRCMF_FWS_RET_OK_NOSCHEDULE; |
349e7104 AS |
1406 | while (data_len > 0) { |
1407 | /* extract tlv info */ | |
1408 | type = signal_data[0]; | |
1409 | ||
1410 | /* FILLER type is actually not a TLV, but | |
1411 | * a single byte that can be skipped. | |
1412 | */ | |
1413 | if (type == BRCMF_FWS_TYPE_FILLER) { | |
1414 | signal_data += 1; | |
1415 | data_len -= 1; | |
1416 | continue; | |
1417 | } | |
1418 | len = signal_data[1]; | |
1419 | data = signal_data + 2; | |
1420 | ||
8071fd61 AS |
1421 | brcmf_dbg(HDRS, "tlv type=%s (%d), len=%d (%d)\n", |
1422 | brcmf_fws_get_tlv_name(type), type, len, | |
1423 | brcmf_fws_get_tlv_len(fws, type)); | |
2af15580 | 1424 | |
349e7104 AS |
1425 | /* abort parsing when length invalid */ |
1426 | if (data_len < len + 2) | |
1427 | break; | |
1428 | ||
f55d94a6 | 1429 | if (len < brcmf_fws_get_tlv_len(fws, type)) |
bb8c8063 AS |
1430 | break; |
1431 | ||
a5e9d805 | 1432 | err = BRCMF_FWS_RET_OK_NOSCHEDULE; |
349e7104 | 1433 | switch (type) { |
349e7104 | 1434 | case BRCMF_FWS_TYPE_HOST_REORDER_RXPKTS: |
bb8c8063 | 1435 | case BRCMF_FWS_TYPE_COMP_TXSTATUS: |
ce814c1b | 1436 | break; |
bb8c8063 AS |
1437 | case BRCMF_FWS_TYPE_MACDESC_ADD: |
1438 | case BRCMF_FWS_TYPE_MACDESC_DEL: | |
ce814c1b | 1439 | brcmf_fws_macdesc_indicate(fws, type, data); |
bb8c8063 | 1440 | break; |
33753d47 AS |
1441 | case BRCMF_FWS_TYPE_MAC_OPEN: |
1442 | case BRCMF_FWS_TYPE_MAC_CLOSE: | |
a5e9d805 | 1443 | err = brcmf_fws_macdesc_state_indicate(fws, type, data); |
33753d47 AS |
1444 | break; |
1445 | case BRCMF_FWS_TYPE_INTERFACE_OPEN: | |
1446 | case BRCMF_FWS_TYPE_INTERFACE_CLOSE: | |
a5e9d805 AS |
1447 | err = brcmf_fws_interface_state_indicate(fws, type, |
1448 | data); | |
33753d47 | 1449 | break; |
5f38b683 AS |
1450 | case BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT: |
1451 | case BRCMF_FWS_TYPE_MAC_REQUEST_PACKET: | |
a5e9d805 | 1452 | err = brcmf_fws_request_indicate(fws, type, data); |
5f38b683 | 1453 | break; |
3edc1cff AS |
1454 | case BRCMF_FWS_TYPE_TXSTATUS: |
1455 | brcmf_fws_txstatus_indicate(fws, data); | |
1456 | break; | |
84bcc0c3 | 1457 | case BRCMF_FWS_TYPE_FIFO_CREDITBACK: |
a5e9d805 | 1458 | err = brcmf_fws_fifocreditback_indicate(fws, data); |
84bcc0c3 | 1459 | break; |
bb8c8063 AS |
1460 | case BRCMF_FWS_TYPE_RSSI: |
1461 | brcmf_fws_rssi_indicate(fws, *data); | |
349e7104 AS |
1462 | break; |
1463 | case BRCMF_FWS_TYPE_TRANS_ID: | |
349e7104 AS |
1464 | brcmf_fws_dbg_seqnum_check(fws, data); |
1465 | break; | |
84bcc0c3 AS |
1466 | case BRCMF_FWS_TYPE_PKTTAG: |
1467 | case BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP: | |
349e7104 AS |
1468 | default: |
1469 | fws->stats.tlv_invalid_type++; | |
1470 | break; | |
1471 | } | |
a5e9d805 AS |
1472 | if (err == BRCMF_FWS_RET_OK_SCHEDULE) |
1473 | status = BRCMF_FWS_RET_OK_SCHEDULE; | |
349e7104 AS |
1474 | signal_data += len + 2; |
1475 | data_len -= len + 2; | |
1476 | } | |
1477 | ||
1478 | if (data_len != 0) | |
1479 | fws->stats.tlv_parse_failed++; | |
1480 | ||
a5e9d805 AS |
1481 | if (status == BRCMF_FWS_RET_OK_SCHEDULE) |
1482 | brcmf_fws_schedule_deq(fws); | |
1483 | ||
349e7104 AS |
1484 | /* signalling processing result does |
1485 | * not affect the actual ethernet packet. | |
1486 | */ | |
1487 | skb_pull(skb, signal_len); | |
1488 | ||
1489 | /* this may be a signal-only packet | |
1490 | */ | |
1491 | if (skb->len == 0) | |
1492 | fws->stats.header_only_pkt++; | |
1493 | ||
1494 | brcmf_fws_unlock(drvr, flags); | |
1495 | return 0; | |
1496 | } | |
bb8c8063 | 1497 | |
3edc1cff AS |
1498 | static int brcmf_fws_hdrpush(struct brcmf_fws_info *fws, struct sk_buff *skb) |
1499 | { | |
1500 | struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(skb)->mac; | |
1501 | u8 *wlh; | |
84bcc0c3 | 1502 | u16 data_offset = 0; |
3edc1cff AS |
1503 | u8 fillers; |
1504 | __le32 pkttag = cpu_to_le32(brcmf_skbcb(skb)->htod); | |
1505 | ||
84bcc0c3 AS |
1506 | if (entry->send_tim_signal) |
1507 | data_offset += 2 + BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN; | |
1508 | ||
3edc1cff | 1509 | /* +2 is for Type[1] and Len[1] in TLV, plus TIM signal */ |
84bcc0c3 | 1510 | data_offset += 2 + BRCMF_FWS_TYPE_PKTTAG_LEN; |
3edc1cff AS |
1511 | fillers = round_up(data_offset, 4) - data_offset; |
1512 | data_offset += fillers; | |
1513 | ||
1514 | skb_push(skb, data_offset); | |
1515 | wlh = skb->data; | |
1516 | ||
1517 | wlh[0] = BRCMF_FWS_TYPE_PKTTAG; | |
1518 | wlh[1] = BRCMF_FWS_TYPE_PKTTAG_LEN; | |
1519 | memcpy(&wlh[2], &pkttag, sizeof(pkttag)); | |
1520 | wlh += BRCMF_FWS_TYPE_PKTTAG_LEN + 2; | |
1521 | ||
84bcc0c3 AS |
1522 | if (entry->send_tim_signal) { |
1523 | entry->send_tim_signal = 0; | |
1524 | wlh[0] = BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP; | |
1525 | wlh[1] = BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN; | |
1526 | wlh[2] = entry->mac_handle; | |
1527 | wlh[3] = entry->traffic_pending_bmp; | |
1528 | wlh += BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN + 2; | |
1529 | entry->traffic_lastreported_bmp = entry->traffic_pending_bmp; | |
1530 | } | |
3edc1cff AS |
1531 | if (fillers) |
1532 | memset(wlh, BRCMF_FWS_TYPE_FILLER, fillers); | |
1533 | ||
1534 | brcmf_proto_hdrpush(fws->drvr, brcmf_skb_if_flags_get_field(skb, INDEX), | |
1535 | data_offset >> 2, skb); | |
1536 | return 0; | |
1537 | } | |
1538 | ||
1539 | static int brcmf_fws_precommit_skb(struct brcmf_fws_info *fws, int fifo, | |
1540 | struct sk_buff *p) | |
1541 | { | |
1542 | struct brcmf_skbuff_cb *skcb = brcmf_skbcb(p); | |
1543 | struct brcmf_fws_mac_descriptor *entry = skcb->mac; | |
1544 | int rc = 0; | |
be4910ad | 1545 | bool first_time; |
3edc1cff AS |
1546 | int hslot = BRCMF_FWS_HANGER_MAXITEMS; |
1547 | u8 free_ctr; | |
3edc1cff AS |
1548 | u8 flags; |
1549 | ||
be4910ad | 1550 | first_time = skcb->state != BRCMF_FWS_SKBSTATE_SUPPRESSED; |
3edc1cff | 1551 | |
be4910ad HM |
1552 | brcmf_skb_if_flags_set_field(p, TRANSMIT, 1); |
1553 | brcmf_skb_htod_tag_set_field(p, FIFO, fifo); | |
1554 | brcmf_skb_htod_tag_set_field(p, GENERATION, entry->generation); | |
1555 | flags = BRCMF_FWS_HTOD_FLAG_PKTFROMHOST; | |
1556 | if (!(skcb->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK)) { | |
1557 | /* | |
1558 | * Indicate that this packet is being sent in response to an | |
1559 | * explicit request from the firmware side. | |
1560 | */ | |
1561 | flags |= BRCMF_FWS_HTOD_FLAG_PKT_REQUESTED; | |
1562 | } | |
1563 | brcmf_skb_htod_tag_set_field(p, FLAGS, flags); | |
1564 | if (first_time) { | |
3edc1cff AS |
1565 | /* obtaining free slot may fail, but that will be caught |
1566 | * by the hanger push. This assures the packet has a BDC | |
1567 | * header upon return. | |
1568 | */ | |
1569 | hslot = brcmf_fws_hanger_get_free_slot(&fws->hanger); | |
1570 | free_ctr = entry->seq[fifo]; | |
1571 | brcmf_skb_htod_tag_set_field(p, HSLOT, hslot); | |
1572 | brcmf_skb_htod_tag_set_field(p, FREERUN, free_ctr); | |
3edc1cff AS |
1573 | rc = brcmf_fws_hanger_pushpkt(&fws->hanger, p, hslot); |
1574 | if (rc) | |
1575 | brcmf_err("hanger push failed: rc=%d\n", rc); | |
3edc1cff AS |
1576 | } |
1577 | ||
2747e5f7 HM |
1578 | if (rc == 0) |
1579 | brcmf_fws_hdrpush(fws, p); | |
1580 | ||
3edc1cff AS |
1581 | return rc; |
1582 | } | |
1583 | ||
88f656fa | 1584 | static void |
51f6dd9d AS |
1585 | brcmf_fws_rollback_toq(struct brcmf_fws_info *fws, |
1586 | struct sk_buff *skb, int fifo) | |
84bcc0c3 AS |
1587 | { |
1588 | /* | |
1589 | put the packet back to the head of queue | |
1590 | ||
1591 | - suppressed packet goes back to suppress sub-queue | |
1592 | - pull out the header, if new or delayed packet | |
1593 | ||
1594 | Note: hslot is used only when header removal is done. | |
1595 | */ | |
1596 | struct brcmf_fws_mac_descriptor *entry; | |
1597 | enum brcmf_fws_skb_state state; | |
1598 | struct sk_buff *pktout; | |
1599 | int rc = 0; | |
84bcc0c3 | 1600 | int hslot; |
84bcc0c3 | 1601 | |
84bcc0c3 AS |
1602 | state = brcmf_skbcb(skb)->state; |
1603 | entry = brcmf_skbcb(skb)->mac; | |
1604 | ||
1605 | if (entry != NULL) { | |
1606 | if (state == BRCMF_FWS_SKBSTATE_SUPPRESSED) { | |
1607 | /* wl-header is saved for suppressed packets */ | |
1608 | pktout = brcmu_pktq_penq_head(&entry->psq, 2 * fifo + 1, | |
1609 | skb); | |
1610 | if (pktout == NULL) { | |
1611 | brcmf_err("suppress queue full\n"); | |
1612 | rc = -ENOSPC; | |
1613 | } | |
1614 | } else { | |
1615 | hslot = brcmf_skb_htod_tag_get_field(skb, HSLOT); | |
1616 | ||
84bcc0c3 AS |
1617 | /* delay-q packets are going to delay-q */ |
1618 | pktout = brcmu_pktq_penq_head(&entry->psq, | |
1619 | 2 * fifo, skb); | |
1620 | if (pktout == NULL) { | |
1621 | brcmf_err("delay queue full\n"); | |
1622 | rc = -ENOSPC; | |
1623 | } | |
1624 | ||
1625 | /* free the hanger slot */ | |
1626 | brcmf_fws_hanger_poppkt(&fws->hanger, hslot, &pktout, | |
1627 | true); | |
1628 | ||
1629 | /* decrement sequence count */ | |
1630 | entry->seq[fifo]--; | |
1631 | } | |
84bcc0c3 AS |
1632 | } else { |
1633 | brcmf_err("no mac entry linked\n"); | |
1634 | rc = -ENOENT; | |
1635 | } | |
1636 | ||
67994fa2 | 1637 | if (rc) { |
289ec1c7 | 1638 | brcmf_fws_bustxfail(fws, skb); |
84bcc0c3 | 1639 | fws->stats.rollback_failed++; |
289ec1c7 | 1640 | } else { |
84bcc0c3 | 1641 | fws->stats.rollback_success++; |
289ec1c7 AS |
1642 | brcmf_fws_skb_pickup_credit(fws, fifo, skb); |
1643 | } | |
84bcc0c3 AS |
1644 | } |
1645 | ||
1aac1e91 AS |
1646 | static int brcmf_fws_borrow_credit(struct brcmf_fws_info *fws) |
1647 | { | |
1648 | int lender_ac; | |
1649 | ||
afc3bbfc HM |
1650 | if (time_after(fws->borrow_defer_timestamp, jiffies)) { |
1651 | fws->fifo_credit_map &= ~(1 << BRCMF_FWS_FIFO_AC_BE); | |
1aac1e91 | 1652 | return -ENAVAIL; |
afc3bbfc | 1653 | } |
1aac1e91 AS |
1654 | |
1655 | for (lender_ac = 0; lender_ac <= BRCMF_FWS_FIFO_AC_VO; lender_ac++) { | |
1656 | if (fws->fifo_credit[lender_ac]) { | |
1657 | fws->credits_borrowed[lender_ac]++; | |
1658 | fws->fifo_credit[lender_ac]--; | |
1659 | if (fws->fifo_credit[lender_ac] == 0) | |
1660 | fws->fifo_credit_map &= ~(1 << lender_ac); | |
afc3bbfc | 1661 | fws->fifo_credit_map |= (1 << BRCMF_FWS_FIFO_AC_BE); |
8071fd61 | 1662 | brcmf_dbg(DATA, "borrow credit from: %d\n", lender_ac); |
1aac1e91 AS |
1663 | return 0; |
1664 | } | |
1665 | } | |
afc3bbfc | 1666 | fws->fifo_credit_map &= ~(1 << BRCMF_FWS_FIFO_AC_BE); |
1aac1e91 AS |
1667 | return -ENAVAIL; |
1668 | } | |
1669 | ||
84bcc0c3 AS |
1670 | static int brcmf_fws_consume_credit(struct brcmf_fws_info *fws, int fifo, |
1671 | struct sk_buff *skb) | |
1672 | { | |
1673 | struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(skb)->mac; | |
1674 | int *credit = &fws->fifo_credit[fifo]; | |
84bcc0c3 | 1675 | |
8071fd61 | 1676 | if (!brcmf_fws_macdesc_use_credit(entry, skb)) |
84bcc0c3 | 1677 | return 0; |
84bcc0c3 | 1678 | |
1aac1e91 AS |
1679 | if (fifo != BRCMF_FWS_FIFO_AC_BE) |
1680 | fws->borrow_defer_timestamp = jiffies + | |
1681 | BRCMF_FWS_BORROW_DEFER_PERIOD; | |
1682 | ||
84bcc0c3 | 1683 | if (!(*credit)) { |
1aac1e91 AS |
1684 | /* Try to borrow a credit from other queue */ |
1685 | if (fifo == BRCMF_FWS_FIFO_AC_BE && | |
1686 | brcmf_fws_borrow_credit(fws) == 0) | |
1687 | return 0; | |
1688 | ||
8071fd61 | 1689 | brcmf_dbg(DATA, "exit: ac=%d, credits depleted\n", fifo); |
84bcc0c3 AS |
1690 | return -ENAVAIL; |
1691 | } | |
1692 | (*credit)--; | |
1693 | if (!(*credit)) | |
1694 | fws->fifo_credit_map &= ~(1 << fifo); | |
8071fd61 | 1695 | brcmf_dbg(DATA, "exit: ac=%d, credits=%d\n", fifo, *credit); |
84bcc0c3 AS |
1696 | return 0; |
1697 | } | |
1698 | ||
3edc1cff AS |
1699 | static int brcmf_fws_commit_skb(struct brcmf_fws_info *fws, int fifo, |
1700 | struct sk_buff *skb) | |
1701 | { | |
1702 | struct brcmf_skbuff_cb *skcb = brcmf_skbcb(skb); | |
1703 | struct brcmf_fws_mac_descriptor *entry; | |
1704 | struct brcmf_bus *bus = fws->drvr->bus_if; | |
1705 | int rc; | |
2747e5f7 | 1706 | u8 ifidx; |
3edc1cff AS |
1707 | |
1708 | entry = skcb->mac; | |
1709 | if (IS_ERR(entry)) | |
1710 | return PTR_ERR(entry); | |
1711 | ||
1712 | rc = brcmf_fws_precommit_skb(fws, fifo, skb); | |
1713 | if (rc < 0) { | |
1714 | fws->stats.generic_error++; | |
84bcc0c3 | 1715 | goto rollback; |
3edc1cff AS |
1716 | } |
1717 | ||
8071fd61 AS |
1718 | brcmf_dbg(DATA, "%s flags %X htod %X\n", entry->name, skcb->if_flags, |
1719 | skcb->htod); | |
3edc1cff | 1720 | rc = brcmf_bus_txdata(bus, skb); |
2747e5f7 HM |
1721 | if (rc < 0) { |
1722 | brcmf_proto_hdrpull(fws->drvr, false, &ifidx, skb); | |
84bcc0c3 | 1723 | goto rollback; |
2747e5f7 | 1724 | } |
3edc1cff | 1725 | |
8c5140f6 HM |
1726 | entry->transit_count++; |
1727 | if (entry->suppressed) | |
1728 | entry->suppr_transit_count++; | |
3edc1cff AS |
1729 | entry->seq[fifo]++; |
1730 | fws->stats.pkt2bus++; | |
cf3a6872 AS |
1731 | fws->stats.send_pkts[fifo]++; |
1732 | if (brcmf_skbcb(skb)->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK) | |
84bcc0c3 | 1733 | fws->stats.fifo_credits_sent[fifo]++; |
84bcc0c3 | 1734 | |
3edc1cff AS |
1735 | return rc; |
1736 | ||
84bcc0c3 | 1737 | rollback: |
51f6dd9d | 1738 | brcmf_fws_rollback_toq(fws, skb, fifo); |
3edc1cff AS |
1739 | return rc; |
1740 | } | |
1741 | ||
1742 | int brcmf_fws_process_skb(struct brcmf_if *ifp, struct sk_buff *skb) | |
1743 | { | |
1744 | struct brcmf_pub *drvr = ifp->drvr; | |
1aac1e91 | 1745 | struct brcmf_fws_info *fws = drvr->fws; |
3edc1cff AS |
1746 | struct brcmf_skbuff_cb *skcb = brcmf_skbcb(skb); |
1747 | struct ethhdr *eh = (struct ethhdr *)(skb->data); | |
1748 | ulong flags; | |
3edc1cff AS |
1749 | int fifo = BRCMF_FWS_FIFO_BCMC; |
1750 | bool multicast = is_multicast_ether_addr(eh->h_dest); | |
1751 | ||
1752 | /* determine the priority */ | |
1753 | if (!skb->priority) | |
1754 | skb->priority = cfg80211_classify8021d(skb); | |
1755 | ||
1756 | drvr->tx_multicast += !!multicast; | |
1757 | if (ntohs(eh->h_proto) == ETH_P_PAE) | |
1758 | atomic_inc(&ifp->pend_8021x_cnt); | |
1759 | ||
1aac1e91 | 1760 | if (!brcmf_fws_fc_active(fws)) { |
3edc1cff | 1761 | /* If the protocol uses a data header, apply it */ |
31ed07dc | 1762 | brcmf_proto_hdrpush(drvr, ifp->ifidx, 0, skb); |
3edc1cff AS |
1763 | |
1764 | /* Use bus module to send data frame */ | |
1765 | return brcmf_bus_txdata(drvr->bus_if, skb); | |
1766 | } | |
1767 | ||
1768 | /* set control buffer information */ | |
84bcc0c3 | 1769 | skcb->if_flags = 0; |
1aac1e91 | 1770 | skcb->mac = brcmf_fws_find_mac_desc(fws, ifp, eh->h_dest); |
3edc1cff | 1771 | skcb->state = BRCMF_FWS_SKBSTATE_NEW; |
31ed07dc | 1772 | brcmf_skb_if_flags_set_field(skb, INDEX, ifp->ifidx); |
3edc1cff AS |
1773 | if (!multicast) |
1774 | fifo = brcmf_fws_prio2fifo[skb->priority]; | |
3edc1cff | 1775 | |
8071fd61 AS |
1776 | brcmf_dbg(DATA, "%s mac %pM multi %d fifo %d\n", skcb->mac->name, |
1777 | eh->h_dest, multicast, fifo); | |
3edc1cff AS |
1778 | |
1779 | brcmf_fws_lock(drvr, flags); | |
9fc60224 | 1780 | if (skcb->mac->suppressed || |
df50f756 | 1781 | fws->bus_flow_blocked || |
1aac1e91 | 1782 | brcmf_fws_mac_desc_closed(fws, skcb->mac, fifo) || |
9fc60224 | 1783 | brcmu_pktq_mlen(&skcb->mac->psq, 3 << (fifo * 2)) || |
84bcc0c3 | 1784 | (!multicast && |
1aac1e91 | 1785 | brcmf_fws_consume_credit(fws, fifo, skb) < 0)) { |
84bcc0c3 AS |
1786 | /* enqueue the packet in delayQ */ |
1787 | drvr->fws->fifo_delay_map |= 1 << fifo; | |
1aac1e91 | 1788 | brcmf_fws_enq(fws, BRCMF_FWS_SKBSTATE_DELAYED, fifo, skb); |
84bcc0c3 | 1789 | } else { |
289ec1c7 | 1790 | brcmf_fws_commit_skb(fws, fifo, skb); |
84bcc0c3 | 1791 | } |
3edc1cff AS |
1792 | brcmf_fws_unlock(drvr, flags); |
1793 | return 0; | |
1794 | } | |
1795 | ||
bb8c8063 AS |
1796 | void brcmf_fws_reset_interface(struct brcmf_if *ifp) |
1797 | { | |
1798 | struct brcmf_fws_mac_descriptor *entry = ifp->fws_desc; | |
1799 | ||
1800 | brcmf_dbg(TRACE, "enter: idx=%d\n", ifp->bssidx); | |
1801 | if (!entry) | |
1802 | return; | |
1803 | ||
ce814c1b | 1804 | brcmf_fws_init_mac_descriptor(entry, ifp->mac_addr, ifp->ifidx); |
bb8c8063 AS |
1805 | } |
1806 | ||
1807 | void brcmf_fws_add_interface(struct brcmf_if *ifp) | |
1808 | { | |
84bcc0c3 | 1809 | struct brcmf_fws_info *fws = ifp->drvr->fws; |
bb8c8063 AS |
1810 | struct brcmf_fws_mac_descriptor *entry; |
1811 | ||
01b8e7db | 1812 | if (!ifp->ndev || !ifp->drvr->fw_signals) |
bb8c8063 AS |
1813 | return; |
1814 | ||
84bcc0c3 AS |
1815 | entry = &fws->desc.iface[ifp->ifidx]; |
1816 | ifp->fws_desc = entry; | |
1817 | brcmf_fws_init_mac_descriptor(entry, ifp->mac_addr, ifp->ifidx); | |
8071fd61 | 1818 | brcmf_fws_macdesc_set_name(fws, entry); |
84bcc0c3 AS |
1819 | brcmu_pktq_init(&entry->psq, BRCMF_FWS_PSQ_PREC_COUNT, |
1820 | BRCMF_FWS_PSQ_LEN); | |
8071fd61 | 1821 | brcmf_dbg(TRACE, "added %s\n", entry->name); |
bb8c8063 AS |
1822 | } |
1823 | ||
1824 | void brcmf_fws_del_interface(struct brcmf_if *ifp) | |
1825 | { | |
1826 | struct brcmf_fws_mac_descriptor *entry = ifp->fws_desc; | |
6d421e54 | 1827 | ulong flags; |
bb8c8063 | 1828 | |
bb8c8063 AS |
1829 | if (!entry) |
1830 | return; | |
1831 | ||
6d421e54 | 1832 | brcmf_fws_lock(ifp->drvr, flags); |
bb8c8063 | 1833 | ifp->fws_desc = NULL; |
8071fd61 | 1834 | brcmf_dbg(TRACE, "deleting %s\n", entry->name); |
ce814c1b | 1835 | brcmf_fws_clear_mac_descriptor(entry); |
a3e993c7 | 1836 | brcmf_fws_cleanup(ifp->drvr->fws, ifp->ifidx); |
6d421e54 | 1837 | brcmf_fws_unlock(ifp->drvr, flags); |
84bcc0c3 AS |
1838 | } |
1839 | ||
1840 | static void brcmf_fws_dequeue_worker(struct work_struct *worker) | |
1841 | { | |
1842 | struct brcmf_fws_info *fws; | |
1843 | struct sk_buff *skb; | |
1844 | ulong flags; | |
1845 | int fifo; | |
84bcc0c3 AS |
1846 | |
1847 | fws = container_of(worker, struct brcmf_fws_info, fws_dequeue_work); | |
1848 | ||
84bcc0c3 | 1849 | brcmf_fws_lock(fws->drvr, flags); |
df50f756 HM |
1850 | for (fifo = NL80211_NUM_ACS; fifo >= 0 && !fws->bus_flow_blocked; |
1851 | fifo--) { | |
289ec1c7 | 1852 | while (fws->fifo_credit[fifo]) { |
84bcc0c3 | 1853 | skb = brcmf_fws_deq(fws, fifo); |
289ec1c7 | 1854 | if (!skb) |
84bcc0c3 | 1855 | break; |
047445c5 | 1856 | if (brcmf_skbcb(skb)->if_flags & |
84bcc0c3 | 1857 | BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK) |
289ec1c7 AS |
1858 | fws->fifo_credit[fifo]--; |
1859 | ||
1860 | if (brcmf_fws_commit_skb(fws, fifo, skb)) | |
1861 | break; | |
df50f756 HM |
1862 | if (fws->bus_flow_blocked) |
1863 | break; | |
84bcc0c3 | 1864 | } |
1aac1e91 | 1865 | if ((fifo == BRCMF_FWS_FIFO_AC_BE) && |
289ec1c7 | 1866 | (fws->fifo_credit[fifo] == 0) && |
df50f756 | 1867 | (!fws->bus_flow_blocked)) { |
1aac1e91 AS |
1868 | while (brcmf_fws_borrow_credit(fws) == 0) { |
1869 | skb = brcmf_fws_deq(fws, fifo); | |
1870 | if (!skb) { | |
1871 | brcmf_fws_return_credits(fws, fifo, 1); | |
1872 | break; | |
1873 | } | |
eb2410cd HM |
1874 | if (brcmf_fws_commit_skb(fws, fifo, skb)) |
1875 | break; | |
df50f756 HM |
1876 | if (fws->bus_flow_blocked) |
1877 | break; | |
1aac1e91 | 1878 | } |
1aac1e91 | 1879 | } |
84bcc0c3 AS |
1880 | } |
1881 | brcmf_fws_unlock(fws->drvr, flags); | |
bb8c8063 | 1882 | } |
c7f34a69 | 1883 | |
d9337414 AS |
1884 | int brcmf_fws_init(struct brcmf_pub *drvr) |
1885 | { | |
290fb763 | 1886 | u32 tlv = BRCMF_FWS_FLAGS_RSSI_SIGNALS; |
d9337414 AS |
1887 | int rc; |
1888 | ||
47829f4f AS |
1889 | if (!drvr->fw_signals) |
1890 | return 0; | |
1891 | ||
d9337414 AS |
1892 | spin_lock_init(&drvr->fws_spinlock); |
1893 | ||
1894 | drvr->fws = kzalloc(sizeof(*(drvr->fws)), GFP_KERNEL); | |
1895 | if (!drvr->fws) { | |
1896 | rc = -ENOMEM; | |
1897 | goto fail; | |
1898 | } | |
1899 | ||
1900 | /* set linkage back */ | |
1901 | drvr->fws->drvr = drvr; | |
1902 | drvr->fws->fcmode = fcmode; | |
1903 | ||
84bcc0c3 AS |
1904 | drvr->fws->fws_wq = create_singlethread_workqueue("brcmf_fws_wq"); |
1905 | if (drvr->fws->fws_wq == NULL) { | |
1906 | brcmf_err("workqueue creation failed\n"); | |
1907 | rc = -EBADF; | |
1908 | goto fail; | |
1909 | } | |
1910 | INIT_WORK(&drvr->fws->fws_dequeue_work, brcmf_fws_dequeue_worker); | |
1911 | ||
290fb763 AS |
1912 | /* enable firmware signalling if fcmode active */ |
1913 | if (drvr->fws->fcmode != BRCMF_FWS_FCMODE_NONE) | |
1914 | tlv |= BRCMF_FWS_FLAGS_XONXOFF_SIGNALS | | |
33753d47 AS |
1915 | BRCMF_FWS_FLAGS_CREDIT_STATUS_SIGNALS | |
1916 | BRCMF_FWS_FLAGS_HOST_PROPTXSTATUS_ACTIVE; | |
290fb763 | 1917 | |
a786b38d AS |
1918 | rc = brcmf_fweh_register(drvr, BRCMF_E_FIFO_CREDIT_MAP, |
1919 | brcmf_fws_notify_credit_map); | |
d9337414 | 1920 | if (rc < 0) { |
a786b38d | 1921 | brcmf_err("register credit map handler failed\n"); |
d9337414 AS |
1922 | goto fail; |
1923 | } | |
1924 | ||
a786b38d AS |
1925 | /* setting the iovar may fail if feature is unsupported |
1926 | * so leave the rc as is so driver initialization can | |
1927 | * continue. | |
1928 | */ | |
1929 | if (brcmf_fil_iovar_int_set(drvr->iflist[0], "tlv", tlv)) { | |
1930 | brcmf_err("failed to set bdcv2 tlv signaling\n"); | |
1931 | goto fail_event; | |
d9337414 AS |
1932 | } |
1933 | ||
1934 | brcmf_fws_hanger_init(&drvr->fws->hanger); | |
84bcc0c3 | 1935 | brcmf_fws_init_mac_descriptor(&drvr->fws->desc.other, NULL, 0); |
8071fd61 | 1936 | brcmf_fws_macdesc_set_name(drvr->fws, &drvr->fws->desc.other); |
84bcc0c3 AS |
1937 | brcmu_pktq_init(&drvr->fws->desc.other.psq, BRCMF_FWS_PSQ_PREC_COUNT, |
1938 | BRCMF_FWS_PSQ_LEN); | |
d9337414 AS |
1939 | |
1940 | /* create debugfs file for statistics */ | |
1941 | brcmf_debugfs_create_fws_stats(drvr, &drvr->fws->stats); | |
1942 | ||
8071fd61 | 1943 | brcmf_dbg(INFO, "%s bdcv2 tlv signaling [%x]\n", |
d9337414 AS |
1944 | drvr->fw_signals ? "enabled" : "disabled", tlv); |
1945 | return 0; | |
1946 | ||
a786b38d AS |
1947 | fail_event: |
1948 | brcmf_fweh_unregister(drvr, BRCMF_E_FIFO_CREDIT_MAP); | |
d9337414 | 1949 | fail: |
d9337414 AS |
1950 | brcmf_fws_deinit(drvr); |
1951 | return rc; | |
1952 | } | |
1953 | ||
1954 | void brcmf_fws_deinit(struct brcmf_pub *drvr) | |
1955 | { | |
1956 | struct brcmf_fws_info *fws = drvr->fws; | |
1957 | ulong flags; | |
1958 | ||
47829f4f AS |
1959 | if (!fws) |
1960 | return; | |
1961 | ||
a786b38d AS |
1962 | /* disable firmware signalling entirely |
1963 | * to avoid using the workqueue. | |
1964 | */ | |
1965 | drvr->fw_signals = false; | |
1966 | ||
1967 | if (drvr->fws->fws_wq) | |
1968 | destroy_workqueue(drvr->fws->fws_wq); | |
1969 | ||
d9337414 AS |
1970 | /* cleanup */ |
1971 | brcmf_fws_lock(drvr, flags); | |
1972 | brcmf_fws_cleanup(fws, -1); | |
1973 | drvr->fws = NULL; | |
1974 | brcmf_fws_unlock(drvr, flags); | |
1975 | ||
1976 | /* free top structure */ | |
1977 | kfree(fws); | |
1978 | } | |
1979 | ||
c7f34a69 AS |
1980 | bool brcmf_fws_fc_active(struct brcmf_fws_info *fws) |
1981 | { | |
1982 | if (!fws) | |
1983 | return false; | |
1984 | ||
c7f34a69 AS |
1985 | return fws->fcmode != BRCMF_FWS_FCMODE_NONE; |
1986 | } | |
0f8b5cc5 AS |
1987 | |
1988 | void brcmf_fws_bustxfail(struct brcmf_fws_info *fws, struct sk_buff *skb) | |
1989 | { | |
1990 | ulong flags; | |
fe353b24 | 1991 | int fifo; |
0f8b5cc5 AS |
1992 | |
1993 | brcmf_fws_lock(fws->drvr, flags); | |
8071fd61 | 1994 | brcmf_fws_txs_process(fws, BRCMF_FWS_TXSTATUS_FW_TOSSED, |
84bcc0c3 AS |
1995 | brcmf_skb_htod_tag_get_field(skb, HSLOT), 0); |
1996 | /* the packet never reached firmware so reclaim credit */ | |
fe353b24 AS |
1997 | if (fws->fcmode == BRCMF_FWS_FCMODE_EXPLICIT_CREDIT) { |
1998 | fifo = brcmf_skb_htod_tag_get_field(skb, FIFO); | |
1999 | brcmf_fws_skb_pickup_credit(fws, fifo, skb); | |
84bcc0c3 | 2000 | } |
0f8b5cc5 AS |
2001 | brcmf_fws_unlock(fws->drvr, flags); |
2002 | } | |
df50f756 HM |
2003 | |
2004 | void brcmf_fws_bus_blocked(struct brcmf_pub *drvr, bool flow_blocked) | |
2005 | { | |
2006 | struct brcmf_fws_info *fws = drvr->fws; | |
2007 | ||
2008 | fws->bus_flow_blocked = flow_blocked; | |
2009 | if (!flow_blocked) | |
2010 | brcmf_fws_schedule_deq(fws); | |
2011 | } |