Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 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> |
| 17 | #include <linux/if_ether.h> |
| 18 | #include <linux/spinlock.h> |
| 19 | #include <linux/skbuff.h> |
| 20 | #include <linux/netdevice.h> |
| 21 | #include <linux/err.h> |
| 22 | #include <uapi/linux/nl80211.h> |
| 23 | |
| 24 | #include <brcmu_utils.h> |
| 25 | #include <brcmu_wifi.h> |
| 26 | #include "dhd.h" |
| 27 | #include "dhd_dbg.h" |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame^] | 28 | #include "dhd_bus.h" |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 29 | #include "fwil.h" |
| 30 | #include "fweh.h" |
| 31 | #include "fwsignal.h" |
| 32 | |
| 33 | /** |
| 34 | * DOC: Firmware Signalling |
| 35 | * |
| 36 | * Firmware can send signals to host and vice versa, which are passed in the |
| 37 | * data packets using TLV based header. This signalling layer is on top of the |
| 38 | * BDC bus protocol layer. |
| 39 | */ |
| 40 | |
| 41 | /* |
| 42 | * single definition for firmware-driver flow control tlv's. |
| 43 | * |
| 44 | * each tlv is specified by BRCMF_FWS_TLV_DEF(name, ID, length). |
| 45 | * A length value 0 indicates variable length tlv. |
| 46 | */ |
| 47 | #define BRCMF_FWS_TLV_DEFLIST \ |
| 48 | BRCMF_FWS_TLV_DEF(MAC_OPEN, 1, 1) \ |
| 49 | BRCMF_FWS_TLV_DEF(MAC_CLOSE, 2, 1) \ |
| 50 | BRCMF_FWS_TLV_DEF(MAC_REQUEST_CREDIT, 3, 2) \ |
| 51 | BRCMF_FWS_TLV_DEF(TXSTATUS, 4, 4) \ |
| 52 | BRCMF_FWS_TLV_DEF(PKTTAG, 5, 4) \ |
| 53 | BRCMF_FWS_TLV_DEF(MACDESC_ADD, 6, 8) \ |
| 54 | BRCMF_FWS_TLV_DEF(MACDESC_DEL, 7, 8) \ |
| 55 | BRCMF_FWS_TLV_DEF(RSSI, 8, 1) \ |
| 56 | BRCMF_FWS_TLV_DEF(INTERFACE_OPEN, 9, 1) \ |
| 57 | BRCMF_FWS_TLV_DEF(INTERFACE_CLOSE, 10, 1) \ |
| 58 | BRCMF_FWS_TLV_DEF(FIFO_CREDITBACK, 11, 8) \ |
| 59 | BRCMF_FWS_TLV_DEF(PENDING_TRAFFIC_BMP, 12, 2) \ |
| 60 | BRCMF_FWS_TLV_DEF(MAC_REQUEST_PACKET, 13, 3) \ |
| 61 | BRCMF_FWS_TLV_DEF(HOST_REORDER_RXPKTS, 14, 10) \ |
| 62 | BRCMF_FWS_TLV_DEF(TRANS_ID, 18, 6) \ |
| 63 | BRCMF_FWS_TLV_DEF(COMP_TXSTATUS, 19, 1) \ |
| 64 | BRCMF_FWS_TLV_DEF(FILLER, 255, 0) |
| 65 | |
| 66 | /** |
| 67 | * enum brcmf_fws_tlv_type - definition of tlv identifiers. |
| 68 | */ |
| 69 | #define BRCMF_FWS_TLV_DEF(name, id, len) \ |
| 70 | BRCMF_FWS_TYPE_ ## name = id, |
| 71 | enum brcmf_fws_tlv_type { |
| 72 | BRCMF_FWS_TLV_DEFLIST |
| 73 | BRCMF_FWS_TYPE_INVALID |
| 74 | }; |
| 75 | #undef BRCMF_FWS_TLV_DEF |
| 76 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 77 | #ifdef DEBUG |
| 78 | /** |
| 79 | * brcmf_fws_tlv_names - array of tlv names. |
| 80 | */ |
| 81 | #define BRCMF_FWS_TLV_DEF(name, id, len) \ |
| 82 | { id, #name }, |
| 83 | static struct { |
| 84 | enum brcmf_fws_tlv_type id; |
| 85 | const char *name; |
| 86 | } brcmf_fws_tlv_names[] = { |
| 87 | BRCMF_FWS_TLV_DEFLIST |
| 88 | }; |
| 89 | #undef BRCMF_FWS_TLV_DEF |
| 90 | |
| 91 | static const char *brcmf_fws_get_tlv_name(enum brcmf_fws_tlv_type id) |
| 92 | { |
| 93 | int i; |
| 94 | |
| 95 | for (i = 0; i < ARRAY_SIZE(brcmf_fws_tlv_names); i++) |
| 96 | if (brcmf_fws_tlv_names[i].id == id) |
| 97 | return brcmf_fws_tlv_names[i].name; |
| 98 | |
| 99 | return "INVALID"; |
| 100 | } |
| 101 | #else |
| 102 | static const char *brcmf_fws_get_tlv_name(enum brcmf_fws_tlv_type id) |
| 103 | { |
| 104 | return "NODEBUG"; |
| 105 | } |
| 106 | #endif /* DEBUG */ |
| 107 | |
| 108 | /** |
| 109 | * flags used to enable tlv signalling from firmware. |
| 110 | */ |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 111 | #define BRCMF_FWS_FLAGS_RSSI_SIGNALS 0x0001 |
| 112 | #define BRCMF_FWS_FLAGS_XONXOFF_SIGNALS 0x0002 |
| 113 | #define BRCMF_FWS_FLAGS_CREDIT_STATUS_SIGNALS 0x0004 |
| 114 | #define BRCMF_FWS_FLAGS_HOST_PROPTXSTATUS_ACTIVE 0x0008 |
| 115 | #define BRCMF_FWS_FLAGS_PSQ_GENERATIONFSM_ENABLE 0x0010 |
| 116 | #define BRCMF_FWS_FLAGS_PSQ_ZERO_BUFFER_ENABLE 0x0020 |
| 117 | #define BRCMF_FWS_FLAGS_HOST_RXREORDER_ACTIVE 0x0040 |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 118 | |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 119 | #define BRCMF_FWS_HANGER_MAXITEMS 1024 |
| 120 | #define BRCMF_FWS_HANGER_ITEM_STATE_FREE 1 |
| 121 | #define BRCMF_FWS_HANGER_ITEM_STATE_INUSE 2 |
| 122 | #define BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED 3 |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 123 | |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 124 | #define BRCMF_FWS_STATE_OPEN 1 |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 125 | #define BRCMF_FWS_STATE_CLOSE 2 |
| 126 | |
| 127 | #define BRCMF_FWS_FCMODE_NONE 0 |
| 128 | #define BRCMF_FWS_FCMODE_IMPLIED_CREDIT 1 |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 129 | #define BRCMF_FWS_FCMODE_EXPLICIT_CREDIT 2 |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 130 | |
| 131 | #define BRCMF_FWS_MAC_DESC_TABLE_SIZE 32 |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 132 | #define BRCMF_FWS_MAX_IFNUM 16 |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 133 | #define BRCMF_FWS_MAC_DESC_ID_INVALID 0xff |
| 134 | |
| 135 | #define BRCMF_FWS_HOSTIF_FLOWSTATE_OFF 0 |
| 136 | #define BRCMF_FWS_HOSTIF_FLOWSTATE_ON 1 |
| 137 | |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 138 | #define BRCMF_FWS_PSQ_PREC_COUNT ((NL80211_NUM_ACS + 1) * 2) |
| 139 | #define BRCMF_FWS_PSQ_LEN 256 |
| 140 | |
| 141 | /** |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 142 | * enum brcmf_fws_skb_state - indicates processing state of skb. |
| 143 | */ |
| 144 | enum brcmf_fws_skb_state { |
| 145 | WLFC_PKTTYPE_NEW, |
| 146 | WLFC_PKTTYPE_DELAYED, |
| 147 | WLFC_PKTTYPE_SUPPRESSED, |
| 148 | WLFC_PKTTYPE_MAX |
| 149 | }; |
| 150 | |
| 151 | /** |
| 152 | * struct brcmf_skbuff_cb - control buffer associated with skbuff. |
| 153 | * |
| 154 | * @if_flags: holds interface index and packet related flags. |
| 155 | * @da: destination MAC address extracted from skbuff once. |
| 156 | * @htod: host to device packet identifier (used in PKTTAG tlv). |
| 157 | * @needs_hdr: the packet does not yet have a BDC header. |
| 158 | * @state: transmit state of the packet. |
| 159 | * @mac: descriptor related to destination for this packet. |
| 160 | * |
| 161 | * This information is stored in control buffer struct sk_buff::cb, which |
| 162 | * provides 48 bytes of storage so this structure should not exceed that. |
| 163 | */ |
| 164 | struct brcmf_skbuff_cb { |
| 165 | u16 if_flags; |
| 166 | u8 da[ETH_ALEN]; |
| 167 | u32 htod; |
| 168 | u8 needs_hdr; |
| 169 | enum brcmf_fws_skb_state state; |
| 170 | struct brcmf_fws_mac_descriptor *mac; |
| 171 | }; |
| 172 | |
| 173 | /** |
| 174 | * macro casting skbuff control buffer to struct brcmf_skbuff_cb. |
| 175 | */ |
| 176 | #define brcmf_skbcb(skb) ((struct brcmf_skbuff_cb *)((skb)->cb)) |
| 177 | |
| 178 | /** |
| 179 | * sk_buff control if flags |
| 180 | * |
| 181 | * b[11] - packet sent upon firmware request. |
| 182 | * b[10] - packet only contains signalling data. |
| 183 | * b[9] - packet is a tx packet. |
| 184 | * b[8] - packet uses FIFO credit (non-pspoll). |
| 185 | * b[7] - interface in AP mode. |
| 186 | * b[6:4] - AC FIFO number. |
| 187 | * b[3:0] - interface index. |
| 188 | */ |
| 189 | #define BRCMF_SKB_IF_FLAGS_REQUESTED_MASK 0x0800 |
| 190 | #define BRCMF_SKB_IF_FLAGS_REQUESTED_SHIFT 11 |
| 191 | #define BRCMF_SKB_IF_FLAGS_SIGNAL_ONLY_MASK 0x0400 |
| 192 | #define BRCMF_SKB_IF_FLAGS_SIGNAL_ONLY_SHIFT 10 |
| 193 | #define BRCMF_SKB_IF_FLAGS_TRANSMIT_MASK 0x0200 |
| 194 | #define BRCMF_SKB_IF_FLAGS_TRANSMIT_SHIFT 9 |
| 195 | #define BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK 0x0100 |
| 196 | #define BRCMF_SKB_IF_FLAGS_CREDITCHECK_SHIFT 8 |
| 197 | #define BRCMF_SKB_IF_FLAGS_IF_AP_MASK 0x0080 |
| 198 | #define BRCMF_SKB_IF_FLAGS_IF_AP_SHIFT 7 |
| 199 | #define BRCMF_SKB_IF_FLAGS_FIFO_MASK 0x0070 |
| 200 | #define BRCMF_SKB_IF_FLAGS_FIFO_SHIFT 4 |
| 201 | #define BRCMF_SKB_IF_FLAGS_INDEX_MASK 0x000f |
| 202 | #define BRCMF_SKB_IF_FLAGS_INDEX_SHIFT 0 |
| 203 | |
| 204 | #define brcmf_skb_if_flags_set_field(skb, field, value) \ |
| 205 | brcmu_maskset16(&(brcmf_skbcb(skb)->if_flags), \ |
| 206 | BRCMF_SKB_IF_FLAGS_ ## field ## _MASK, \ |
| 207 | BRCMF_SKB_IF_FLAGS_ ## field ## _SHIFT, (value)) |
| 208 | #define brcmf_skb_if_flags_get_field(skb, field) \ |
| 209 | brcmu_maskget16(brcmf_skbcb(skb)->if_flags, \ |
| 210 | BRCMF_SKB_IF_FLAGS_ ## field ## _MASK, \ |
| 211 | BRCMF_SKB_IF_FLAGS_ ## field ## _SHIFT) |
| 212 | |
| 213 | /** |
| 214 | * sk_buff control packet identifier |
| 215 | * |
| 216 | * 32-bit packet identifier used in PKTTAG tlv from host to dongle. |
| 217 | * |
| 218 | * - Generated at the host (e.g. dhd) |
| 219 | * - Seen as a generic sequence number by firmware except for the flags field. |
| 220 | * |
| 221 | * Generation : b[31] => generation number for this packet [host->fw] |
| 222 | * OR, current generation number [fw->host] |
| 223 | * Flags : b[30:27] => command, status flags |
| 224 | * FIFO-AC : b[26:24] => AC-FIFO id |
| 225 | * h-slot : b[23:8] => hanger-slot |
| 226 | * freerun : b[7:0] => A free running counter |
| 227 | */ |
| 228 | #define BRCMF_SKB_HTOD_TAG_GENERATION_MASK 0x80000000 |
| 229 | #define BRCMF_SKB_HTOD_TAG_GENERATION_SHIFT 31 |
| 230 | #define BRCMF_SKB_HTOD_TAG_FLAGS_MASK 0x78000000 |
| 231 | #define BRCMF_SKB_HTOD_TAG_FLAGS_SHIFT 27 |
| 232 | #define BRCMF_SKB_HTOD_TAG_FIFO_MASK 0x07000000 |
| 233 | #define BRCMF_SKB_HTOD_TAG_FIFO_SHIFT 24 |
| 234 | #define BRCMF_SKB_HTOD_TAG_HSLOT_MASK 0x00ffff00 |
| 235 | #define BRCMF_SKB_HTOD_TAG_HSLOT_SHIFT 8 |
| 236 | #define BRCMF_SKB_HTOD_TAG_FREERUN_MASK 0x000000ff |
| 237 | #define BRCMF_SKB_HTOD_TAG_FREERUN_SHIFT 0 |
| 238 | |
| 239 | #define brcmf_skb_htod_tag_set_field(skb, field, value) \ |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame^] | 240 | brcmu_maskset32(&(brcmf_skbcb(skb)->htod), \ |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 241 | BRCMF_SKB_HTOD_TAG_ ## field ## _MASK, \ |
| 242 | BRCMF_SKB_HTOD_TAG_ ## field ## _SHIFT, (value)) |
| 243 | #define brcmf_skb_htod_tag_get_field(skb, field) \ |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame^] | 244 | brcmu_maskget32(brcmf_skbcb(skb)->htod, \ |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 245 | BRCMF_SKB_HTOD_TAG_ ## field ## _MASK, \ |
| 246 | BRCMF_SKB_HTOD_TAG_ ## field ## _SHIFT) |
| 247 | |
| 248 | /** |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 249 | * struct brcmf_fws_mac_descriptor - firmware signalling data per node/interface |
| 250 | * |
| 251 | * @occupied: slot is in use. |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 252 | * @mac_handle: handle for mac entry determined by firmware. |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 253 | * @interface_id: interface index. |
| 254 | * @state: current state. |
| 255 | * @ac_bitmap: ac queue bitmap. |
| 256 | * @requested_credit: credits requested by firmware. |
| 257 | * @ea: ethernet address. |
| 258 | * @psq: power-save queue. |
| 259 | */ |
| 260 | struct brcmf_fws_mac_descriptor { |
| 261 | u8 occupied; |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 262 | u8 mac_handle; |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 263 | u8 interface_id; |
| 264 | u8 state; |
| 265 | u8 ac_bitmap; |
| 266 | u8 requested_credit; |
| 267 | u8 ea[ETH_ALEN]; |
| 268 | struct pktq psq; |
| 269 | }; |
| 270 | |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 271 | #define BRCMF_FWS_HANGER_MAXITEMS 1024 |
| 272 | |
| 273 | /** |
| 274 | * enum brcmf_fws_hanger_item_state - state of hanger item. |
| 275 | * |
| 276 | * @WLFC_HANGER_ITEM_STATE_FREE: item is free for use. |
| 277 | * @WLFC_HANGER_ITEM_STATE_INUSE: item is in use. |
| 278 | * @WLFC_HANGER_ITEM_STATE_INUSE_SUPPRESSED: item was suppressed. |
| 279 | */ |
| 280 | enum brcmf_fws_hanger_item_state { |
| 281 | WLFC_HANGER_ITEM_STATE_FREE = 1, |
| 282 | WLFC_HANGER_ITEM_STATE_INUSE, |
| 283 | WLFC_HANGER_ITEM_STATE_INUSE_SUPPRESSED |
| 284 | }; |
| 285 | |
| 286 | |
| 287 | /** |
| 288 | * struct brcmf_fws_hanger_item - single entry for tx pending packet. |
| 289 | * |
| 290 | * @state: entry is either free or occupied. |
| 291 | * @gen: generation. |
| 292 | * @identifier: packet identifier. |
| 293 | * @pkt: packet itself. |
| 294 | */ |
| 295 | struct brcmf_fws_hanger_item { |
| 296 | enum brcmf_fws_hanger_item_state state; |
| 297 | u8 gen; |
| 298 | u8 pad[2]; |
| 299 | u32 identifier; |
| 300 | struct sk_buff *pkt; |
| 301 | }; |
| 302 | |
| 303 | /** |
| 304 | * struct brcmf_fws_hanger - holds packets awaiting firmware txstatus. |
| 305 | * |
| 306 | * @max_items: number of packets it can hold. |
| 307 | * @pushed: packets pushed to await txstatus. |
| 308 | * @popped: packets popped upon handling txstatus. |
| 309 | * @failed_to_push: packets that could not be pushed. |
| 310 | * @failed_to_pop: packets that could not be popped. |
| 311 | * @failed_slotfind: packets for which failed to find an entry. |
| 312 | * @slot_pos: last returned item index for a free entry. |
| 313 | * @items: array of hanger items. |
| 314 | */ |
| 315 | struct brcmf_fws_hanger { |
| 316 | u32 pushed; |
| 317 | u32 popped; |
| 318 | u32 failed_to_push; |
| 319 | u32 failed_to_pop; |
| 320 | u32 failed_slotfind; |
| 321 | u32 slot_pos; |
| 322 | struct brcmf_fws_hanger_item items[BRCMF_FWS_HANGER_MAXITEMS]; |
| 323 | }; |
| 324 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 325 | struct brcmf_fws_info { |
| 326 | struct brcmf_pub *drvr; |
| 327 | struct brcmf_fws_stats stats; |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 328 | struct brcmf_fws_hanger hanger; |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 329 | struct brcmf_fws_mac_descriptor nodes[BRCMF_FWS_MAC_DESC_TABLE_SIZE]; |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 330 | struct brcmf_fws_mac_descriptor other; |
Arend van Spriel | 43fa635 | 2013-04-03 12:40:32 +0200 | [diff] [blame] | 331 | int fifo_credit[NL80211_NUM_ACS+1+1]; |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 332 | }; |
| 333 | |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 334 | /** |
| 335 | * brcmf_fws_get_tlv_len() - returns defined length for given tlv id. |
| 336 | */ |
| 337 | #define BRCMF_FWS_TLV_DEF(name, id, len) \ |
| 338 | case BRCMF_FWS_TYPE_ ## name: \ |
| 339 | return len; |
| 340 | |
| 341 | static int brcmf_fws_get_tlv_len(struct brcmf_fws_info *fws, |
| 342 | enum brcmf_fws_tlv_type id) |
| 343 | { |
| 344 | switch (id) { |
| 345 | BRCMF_FWS_TLV_DEFLIST |
| 346 | default: |
| 347 | brcmf_err("invalid tlv id: %d\n", id); |
| 348 | fws->stats.tlv_invalid_type++; |
| 349 | break; |
| 350 | } |
| 351 | return -EINVAL; |
| 352 | } |
| 353 | #undef BRCMF_FWS_TLV_DEF |
| 354 | |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 355 | static void brcmf_fws_hanger_init(struct brcmf_fws_hanger *hanger) |
| 356 | { |
| 357 | int i; |
| 358 | |
| 359 | brcmf_dbg(TRACE, "enter\n"); |
| 360 | memset(hanger, 0, sizeof(*hanger)); |
| 361 | for (i = 0; i < ARRAY_SIZE(hanger->items); i++) |
| 362 | hanger->items[i].state = WLFC_HANGER_ITEM_STATE_FREE; |
| 363 | } |
| 364 | |
| 365 | static __used u32 brcmf_fws_hanger_get_free_slot(struct brcmf_fws_hanger *h) |
| 366 | { |
| 367 | u32 i; |
| 368 | |
| 369 | brcmf_dbg(TRACE, "enter\n"); |
| 370 | i = (h->slot_pos + 1) % BRCMF_FWS_HANGER_MAXITEMS; |
| 371 | |
| 372 | while (i != h->slot_pos) { |
| 373 | if (h->items[i].state == WLFC_HANGER_ITEM_STATE_FREE) { |
| 374 | h->slot_pos = i; |
| 375 | return i; |
| 376 | } |
| 377 | i++; |
| 378 | if (i == BRCMF_FWS_HANGER_MAXITEMS) |
| 379 | i = 0; |
| 380 | } |
| 381 | brcmf_err("all slots occupied\n"); |
| 382 | h->failed_slotfind++; |
| 383 | return BRCMF_FWS_HANGER_MAXITEMS; |
| 384 | } |
| 385 | |
| 386 | static __used int brcmf_fws_hanger_pushpkt(struct brcmf_fws_hanger *h, |
| 387 | struct sk_buff *pkt, u32 slot_id) |
| 388 | { |
| 389 | brcmf_dbg(TRACE, "enter\n"); |
| 390 | if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS) |
| 391 | return -ENOENT; |
| 392 | |
| 393 | if (h->items[slot_id].state != BRCMF_FWS_HANGER_ITEM_STATE_FREE) { |
| 394 | brcmf_err("slot is not free\n"); |
| 395 | h->failed_to_push++; |
| 396 | return -EINVAL; |
| 397 | } |
| 398 | |
| 399 | h->items[slot_id].state = BRCMF_FWS_HANGER_ITEM_STATE_INUSE; |
| 400 | h->items[slot_id].pkt = pkt; |
| 401 | h->items[slot_id].identifier = slot_id; |
| 402 | h->pushed++; |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | static __used int brcmf_fws_hanger_poppkt(struct brcmf_fws_hanger *h, |
| 407 | u32 slot_id, struct sk_buff **pktout, |
| 408 | bool remove_item) |
| 409 | { |
| 410 | brcmf_dbg(TRACE, "enter\n"); |
| 411 | if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS) |
| 412 | return -ENOENT; |
| 413 | |
| 414 | if (h->items[slot_id].state == BRCMF_FWS_HANGER_ITEM_STATE_FREE) { |
| 415 | brcmf_err("entry not in use\n"); |
| 416 | h->failed_to_pop++; |
| 417 | return -EINVAL; |
| 418 | } |
| 419 | |
| 420 | *pktout = h->items[slot_id].pkt; |
| 421 | if (remove_item) { |
| 422 | h->items[slot_id].state = BRCMF_FWS_HANGER_ITEM_STATE_FREE; |
| 423 | h->items[slot_id].pkt = NULL; |
| 424 | h->items[slot_id].identifier = 0; |
| 425 | h->items[slot_id].gen = 0xff; |
| 426 | h->popped++; |
| 427 | } |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | static __used int brcmf_fws_hanger_mark_suppressed(struct brcmf_fws_hanger *h, |
| 432 | u32 slot_id, u8 gen) |
| 433 | { |
| 434 | brcmf_dbg(TRACE, "enter\n"); |
| 435 | |
| 436 | if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS) |
| 437 | return -ENOENT; |
| 438 | |
| 439 | h->items[slot_id].gen = gen; |
| 440 | |
| 441 | if (h->items[slot_id].state != WLFC_HANGER_ITEM_STATE_INUSE) { |
| 442 | brcmf_err("entry not in use\n"); |
| 443 | return -EINVAL; |
| 444 | } |
| 445 | |
| 446 | h->items[slot_id].state = WLFC_HANGER_ITEM_STATE_INUSE_SUPPRESSED; |
| 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | static __used int brcmf_fws_hanger_get_genbit(struct brcmf_fws_hanger *hanger, |
| 451 | struct sk_buff *pkt, u32 slot_id, |
| 452 | int *gen) |
| 453 | { |
| 454 | brcmf_dbg(TRACE, "enter\n"); |
| 455 | *gen = 0xff; |
| 456 | |
| 457 | if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS) |
| 458 | return -ENOENT; |
| 459 | |
| 460 | if (hanger->items[slot_id].state == BRCMF_FWS_HANGER_ITEM_STATE_FREE) { |
| 461 | brcmf_err("slot not in use\n"); |
| 462 | return -EINVAL; |
| 463 | } |
| 464 | |
| 465 | *gen = hanger->items[slot_id].gen; |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static void brcmf_fws_hanger_cleanup(struct brcmf_fws_hanger *h, |
| 470 | bool (*fn)(struct sk_buff *, void *), |
| 471 | int ifidx) |
| 472 | { |
| 473 | struct sk_buff *skb; |
| 474 | int i; |
| 475 | enum brcmf_fws_hanger_item_state s; |
| 476 | |
| 477 | brcmf_dbg(TRACE, "enter: ifidx=%d\n", ifidx); |
| 478 | for (i = 0; i < ARRAY_SIZE(h->items); i++) { |
| 479 | s = h->items[i].state; |
| 480 | if (s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE || |
| 481 | s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED) { |
| 482 | skb = h->items[i].pkt; |
| 483 | if (fn == NULL || fn(skb, &ifidx)) { |
| 484 | /* suppress packets freed from psq */ |
| 485 | if (s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE) |
| 486 | brcmu_pkt_buf_free_skb(skb); |
| 487 | h->items[i].state = |
| 488 | BRCMF_FWS_HANGER_ITEM_STATE_FREE; |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 494 | static void brcmf_fws_init_mac_descriptor(struct brcmf_fws_mac_descriptor *desc, |
| 495 | u8 *addr, u8 ifidx) |
| 496 | { |
| 497 | brcmf_dbg(TRACE, "enter: ea=%pM, ifidx=%u\n", addr, ifidx); |
| 498 | desc->occupied = 1; |
| 499 | desc->state = BRCMF_FWS_STATE_OPEN; |
| 500 | desc->requested_credit = 0; |
| 501 | /* depending on use may need ifp->bssidx instead */ |
| 502 | desc->interface_id = ifidx; |
| 503 | desc->ac_bitmap = 0xff; /* update this when handling APSD */ |
| 504 | memcpy(&desc->ea[0], addr, ETH_ALEN); |
| 505 | } |
| 506 | |
| 507 | static |
| 508 | void brcmf_fws_clear_mac_descriptor(struct brcmf_fws_mac_descriptor *desc) |
| 509 | { |
| 510 | brcmf_dbg(TRACE, |
| 511 | "enter: ea=%pM, ifidx=%u\n", desc->ea, desc->interface_id); |
| 512 | desc->occupied = 0; |
| 513 | desc->state = BRCMF_FWS_STATE_CLOSE; |
| 514 | desc->requested_credit = 0; |
| 515 | } |
| 516 | |
| 517 | static struct brcmf_fws_mac_descriptor * |
| 518 | brcmf_fws_mac_descriptor_lookup(struct brcmf_fws_info *fws, u8 *ea) |
| 519 | { |
| 520 | struct brcmf_fws_mac_descriptor *entry; |
| 521 | int i; |
| 522 | |
| 523 | brcmf_dbg(TRACE, "enter: ea=%pM\n", ea); |
| 524 | if (ea == NULL) |
| 525 | return ERR_PTR(-EINVAL); |
| 526 | |
| 527 | entry = &fws->nodes[0]; |
| 528 | for (i = 0; i < ARRAY_SIZE(fws->nodes); i++) { |
| 529 | if (entry->occupied && !memcmp(entry->ea, ea, ETH_ALEN)) |
| 530 | return entry; |
| 531 | entry++; |
| 532 | } |
| 533 | |
| 534 | return ERR_PTR(-ENOENT); |
| 535 | } |
| 536 | |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 537 | static void brcmf_fws_mac_desc_cleanup(struct brcmf_fws_mac_descriptor *entry, |
| 538 | bool (*fn)(struct sk_buff *, void *), |
| 539 | int ifidx) |
| 540 | { |
| 541 | brcmf_dbg(TRACE, "enter: entry=(ea=%pM,ifid=%d), ifidx=%d\n", |
| 542 | entry->ea, entry->interface_id, ifidx); |
| 543 | if (entry->occupied && (fn == NULL || (ifidx == entry->interface_id))) { |
| 544 | brcmf_dbg(TRACE, "flush delayQ: ifidx=%d, qlen=%d\n", |
| 545 | ifidx, entry->psq.len); |
| 546 | /* release packets held in DELAYQ */ |
| 547 | brcmu_pktq_flush(&entry->psq, true, fn, &ifidx); |
| 548 | entry->occupied = !!(entry->psq.len); |
| 549 | } |
| 550 | } |
| 551 | |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame^] | 552 | static void brcmf_fws_bus_txq_cleanup(struct brcmf_fws_info *fws, |
| 553 | bool (*fn)(struct sk_buff *, void *), |
| 554 | int ifidx) |
| 555 | { |
| 556 | struct brcmf_fws_hanger_item *hi; |
| 557 | struct pktq *txq; |
| 558 | struct sk_buff *skb; |
| 559 | int prec; |
| 560 | u32 hslot; |
| 561 | |
| 562 | brcmf_dbg(TRACE, "enter: ifidx=%d\n", ifidx); |
| 563 | txq = brcmf_bus_gettxq(fws->drvr->bus_if); |
| 564 | if (IS_ERR(txq)) { |
| 565 | brcmf_dbg(TRACE, "no txq to clean up\n"); |
| 566 | return; |
| 567 | } |
| 568 | |
| 569 | for (prec = 0; prec < txq->num_prec; prec++) { |
| 570 | skb = brcmu_pktq_pdeq_match(txq, prec, fn, &ifidx); |
| 571 | while (skb) { |
| 572 | hslot = brcmf_skb_htod_tag_get_field(skb, HSLOT); |
| 573 | hi = &fws->hanger.items[hslot]; |
| 574 | WARN_ON(skb != hi->pkt); |
| 575 | hi->state = BRCMF_FWS_HANGER_ITEM_STATE_FREE; |
| 576 | brcmu_pkt_buf_free_skb(skb); |
| 577 | skb = brcmu_pktq_pdeq_match(txq, prec, fn, &ifidx); |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 | |
Arend van Spriel | a3e993c | 2013-04-03 12:40:36 +0200 | [diff] [blame] | 582 | static bool brcmf_fws_ifidx_match(struct sk_buff *skb, void *arg) |
| 583 | { |
| 584 | u32 ifidx = brcmf_skb_if_flags_get_field(skb, INDEX); |
| 585 | return ifidx == *(int *)arg; |
| 586 | } |
| 587 | |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 588 | static void brcmf_fws_cleanup(struct brcmf_fws_info *fws, int ifidx) |
| 589 | { |
| 590 | int i; |
| 591 | struct brcmf_fws_mac_descriptor *table; |
Arend van Spriel | a3e993c | 2013-04-03 12:40:36 +0200 | [diff] [blame] | 592 | bool (*matchfn)(struct sk_buff *, void *) = NULL; |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 593 | |
| 594 | brcmf_dbg(TRACE, "enter: ifidx=%d\n", ifidx); |
| 595 | if (fws == NULL) |
| 596 | return; |
| 597 | |
Arend van Spriel | a3e993c | 2013-04-03 12:40:36 +0200 | [diff] [blame] | 598 | if (ifidx != -1) |
| 599 | matchfn = brcmf_fws_ifidx_match; |
| 600 | |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 601 | /* cleanup individual nodes */ |
| 602 | table = &fws->nodes[0]; |
| 603 | for (i = 0; i < ARRAY_SIZE(fws->nodes); i++) |
Arend van Spriel | a3e993c | 2013-04-03 12:40:36 +0200 | [diff] [blame] | 604 | brcmf_fws_mac_desc_cleanup(&table[i], matchfn, ifidx); |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 605 | |
Arend van Spriel | a3e993c | 2013-04-03 12:40:36 +0200 | [diff] [blame] | 606 | brcmf_fws_mac_desc_cleanup(&fws->other, matchfn, ifidx); |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame^] | 607 | brcmf_fws_bus_txq_cleanup(fws, matchfn, ifidx); |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 608 | brcmf_fws_hanger_cleanup(&fws->hanger, matchfn, ifidx); |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 609 | } |
| 610 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 611 | static int brcmf_fws_rssi_indicate(struct brcmf_fws_info *fws, s8 rssi) |
| 612 | { |
| 613 | brcmf_dbg(CTL, "rssi %d\n", rssi); |
| 614 | return 0; |
| 615 | } |
| 616 | |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 617 | static |
| 618 | int brcmf_fws_macdesc_indicate(struct brcmf_fws_info *fws, u8 type, u8 *data) |
| 619 | { |
| 620 | struct brcmf_fws_mac_descriptor *entry, *existing; |
| 621 | u8 mac_handle; |
| 622 | u8 ifidx; |
| 623 | u8 *addr; |
| 624 | |
| 625 | mac_handle = *data++; |
| 626 | ifidx = *data++; |
| 627 | addr = data; |
| 628 | |
| 629 | entry = &fws->nodes[mac_handle & 0x1F]; |
| 630 | if (type == BRCMF_FWS_TYPE_MACDESC_DEL) { |
| 631 | brcmf_dbg(TRACE, "deleting mac %pM idx %d\n", addr, ifidx); |
| 632 | if (entry->occupied) { |
| 633 | entry->occupied = 0; |
| 634 | entry->state = BRCMF_FWS_STATE_CLOSE; |
| 635 | entry->requested_credit = 0; |
| 636 | } else { |
| 637 | fws->stats.mac_update_failed++; |
| 638 | } |
| 639 | return 0; |
| 640 | } |
| 641 | |
| 642 | brcmf_dbg(TRACE, "add mac %pM idx %d\n", addr, ifidx); |
| 643 | existing = brcmf_fws_mac_descriptor_lookup(fws, addr); |
| 644 | if (IS_ERR(existing)) { |
| 645 | if (!entry->occupied) { |
| 646 | entry->mac_handle = mac_handle; |
| 647 | brcmf_fws_init_mac_descriptor(entry, addr, ifidx); |
| 648 | brcmu_pktq_init(&entry->psq, BRCMF_FWS_PSQ_PREC_COUNT, |
| 649 | BRCMF_FWS_PSQ_LEN); |
| 650 | } else { |
| 651 | fws->stats.mac_update_failed++; |
| 652 | } |
| 653 | } else { |
| 654 | if (entry != existing) { |
| 655 | brcmf_dbg(TRACE, "relocate mac\n"); |
| 656 | memcpy(entry, existing, |
| 657 | offsetof(struct brcmf_fws_mac_descriptor, psq)); |
| 658 | entry->mac_handle = mac_handle; |
| 659 | brcmf_fws_clear_mac_descriptor(existing); |
| 660 | } else { |
| 661 | brcmf_dbg(TRACE, "use existing\n"); |
| 662 | WARN_ON(entry->mac_handle != mac_handle); |
| 663 | /* TODO: what should we do here: continue, reinit, .. */ |
| 664 | } |
| 665 | } |
| 666 | return 0; |
| 667 | } |
| 668 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 669 | static int brcmf_fws_dbg_seqnum_check(struct brcmf_fws_info *fws, u8 *data) |
| 670 | { |
| 671 | __le32 timestamp; |
| 672 | |
| 673 | memcpy(×tamp, &data[2], sizeof(timestamp)); |
| 674 | brcmf_dbg(INFO, "received: seq %d, timestamp %d\n", data[1], |
| 675 | le32_to_cpu(timestamp)); |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | /* using macro so sparse checking does not complain |
| 680 | * about locking imbalance. |
| 681 | */ |
| 682 | #define brcmf_fws_lock(drvr, flags) \ |
| 683 | do { \ |
| 684 | flags = 0; \ |
| 685 | spin_lock_irqsave(&((drvr)->fws_spinlock), (flags)); \ |
| 686 | } while (0) |
| 687 | |
| 688 | /* using macro so sparse checking does not complain |
| 689 | * about locking imbalance. |
| 690 | */ |
| 691 | #define brcmf_fws_unlock(drvr, flags) \ |
| 692 | spin_unlock_irqrestore(&((drvr)->fws_spinlock), (flags)) |
| 693 | |
Arend van Spriel | 43fa635 | 2013-04-03 12:40:32 +0200 | [diff] [blame] | 694 | static int brcmf_fws_notify_credit_map(struct brcmf_if *ifp, |
| 695 | const struct brcmf_event_msg *e, |
| 696 | void *data) |
| 697 | { |
| 698 | struct brcmf_fws_info *fws = ifp->drvr->fws; |
| 699 | int i; |
| 700 | ulong flags; |
| 701 | u8 *credits = data; |
| 702 | |
| 703 | brcmf_fws_lock(ifp->drvr, flags); |
| 704 | for (i = 0; i < ARRAY_SIZE(fws->fifo_credit); i++) |
| 705 | fws->fifo_credit[i] = *credits++; |
| 706 | brcmf_fws_unlock(ifp->drvr, flags); |
| 707 | return 0; |
| 708 | } |
| 709 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 710 | int brcmf_fws_init(struct brcmf_pub *drvr) |
| 711 | { |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 712 | u32 tlv = 0; |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 713 | int rc; |
| 714 | |
| 715 | /* enable rssi signals */ |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 716 | if (drvr->fw_signals) |
| 717 | tlv = BRCMF_FWS_FLAGS_RSSI_SIGNALS | |
| 718 | BRCMF_FWS_FLAGS_XONXOFF_SIGNALS; |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 719 | |
| 720 | spin_lock_init(&drvr->fws_spinlock); |
| 721 | |
| 722 | drvr->fws = kzalloc(sizeof(*(drvr->fws)), GFP_KERNEL); |
| 723 | if (!drvr->fws) { |
| 724 | rc = -ENOMEM; |
| 725 | goto fail; |
| 726 | } |
| 727 | |
| 728 | /* enable proptxtstatus signaling by default */ |
| 729 | rc = brcmf_fil_iovar_int_set(drvr->iflist[0], "tlv", tlv); |
| 730 | if (rc < 0) { |
| 731 | brcmf_err("failed to set bdcv2 tlv signaling\n"); |
| 732 | goto fail; |
| 733 | } |
Arend van Spriel | 43fa635 | 2013-04-03 12:40:32 +0200 | [diff] [blame] | 734 | |
| 735 | if (brcmf_fweh_register(drvr, BRCMF_E_FIFO_CREDIT_MAP, |
| 736 | brcmf_fws_notify_credit_map)) { |
| 737 | brcmf_err("register credit map handler failed\n"); |
| 738 | goto fail; |
| 739 | } |
| 740 | |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 741 | brcmf_fws_hanger_init(&drvr->fws->hanger); |
| 742 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 743 | /* create debugfs file for statistics */ |
| 744 | brcmf_debugfs_create_fws_stats(drvr, &drvr->fws->stats); |
| 745 | |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 746 | /* set linkage back */ |
| 747 | drvr->fws->drvr = drvr; |
| 748 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 749 | /* TODO: remove upon feature delivery */ |
| 750 | brcmf_err("%s bdcv2 tlv signaling [%x]\n", |
| 751 | drvr->fw_signals ? "enabled" : "disabled", tlv); |
| 752 | return 0; |
| 753 | |
| 754 | fail: |
| 755 | /* disable flow control entirely */ |
| 756 | drvr->fw_signals = false; |
| 757 | brcmf_fws_deinit(drvr); |
| 758 | return rc; |
| 759 | } |
| 760 | |
| 761 | void brcmf_fws_deinit(struct brcmf_pub *drvr) |
| 762 | { |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 763 | struct brcmf_fws_info *fws = drvr->fws; |
| 764 | ulong flags; |
| 765 | |
| 766 | /* cleanup */ |
| 767 | brcmf_fws_lock(drvr, flags); |
| 768 | brcmf_fws_cleanup(fws, -1); |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 769 | drvr->fws = NULL; |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 770 | brcmf_fws_unlock(drvr, flags); |
| 771 | |
| 772 | /* free top structure */ |
| 773 | kfree(fws); |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | int brcmf_fws_hdrpull(struct brcmf_pub *drvr, int ifidx, s16 signal_len, |
| 777 | struct sk_buff *skb) |
| 778 | { |
| 779 | struct brcmf_fws_info *fws = drvr->fws; |
| 780 | ulong flags; |
| 781 | u8 *signal_data; |
| 782 | s16 data_len; |
| 783 | u8 type; |
| 784 | u8 len; |
| 785 | u8 *data; |
| 786 | |
| 787 | brcmf_dbg(TRACE, "enter: ifidx %d, skblen %u, sig %d\n", |
| 788 | ifidx, skb->len, signal_len); |
| 789 | |
| 790 | WARN_ON(signal_len > skb->len); |
| 791 | |
| 792 | /* if flow control disabled, skip to packet data and leave */ |
| 793 | if (!signal_len || !drvr->fw_signals) { |
| 794 | skb_pull(skb, signal_len); |
| 795 | return 0; |
| 796 | } |
| 797 | |
| 798 | /* lock during tlv parsing */ |
| 799 | brcmf_fws_lock(drvr, flags); |
| 800 | |
| 801 | fws->stats.header_pulls++; |
| 802 | data_len = signal_len; |
| 803 | signal_data = skb->data; |
| 804 | |
| 805 | while (data_len > 0) { |
| 806 | /* extract tlv info */ |
| 807 | type = signal_data[0]; |
| 808 | |
| 809 | /* FILLER type is actually not a TLV, but |
| 810 | * a single byte that can be skipped. |
| 811 | */ |
| 812 | if (type == BRCMF_FWS_TYPE_FILLER) { |
| 813 | signal_data += 1; |
| 814 | data_len -= 1; |
| 815 | continue; |
| 816 | } |
| 817 | len = signal_data[1]; |
| 818 | data = signal_data + 2; |
| 819 | |
| 820 | /* abort parsing when length invalid */ |
| 821 | if (data_len < len + 2) |
| 822 | break; |
| 823 | |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 824 | if (len != brcmf_fws_get_tlv_len(fws, type)) |
| 825 | break; |
| 826 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 827 | brcmf_dbg(INFO, "tlv type=%d (%s), len=%d\n", type, |
| 828 | brcmf_fws_get_tlv_name(type), len); |
| 829 | switch (type) { |
| 830 | case BRCMF_FWS_TYPE_MAC_OPEN: |
| 831 | case BRCMF_FWS_TYPE_MAC_CLOSE: |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 832 | case BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT: |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 833 | case BRCMF_FWS_TYPE_TXSTATUS: |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 834 | case BRCMF_FWS_TYPE_PKTTAG: |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 835 | case BRCMF_FWS_TYPE_INTERFACE_OPEN: |
| 836 | case BRCMF_FWS_TYPE_INTERFACE_CLOSE: |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 837 | case BRCMF_FWS_TYPE_FIFO_CREDITBACK: |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 838 | case BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP: |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 839 | case BRCMF_FWS_TYPE_MAC_REQUEST_PACKET: |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 840 | case BRCMF_FWS_TYPE_HOST_REORDER_RXPKTS: |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 841 | case BRCMF_FWS_TYPE_COMP_TXSTATUS: |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 842 | break; |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 843 | case BRCMF_FWS_TYPE_MACDESC_ADD: |
| 844 | case BRCMF_FWS_TYPE_MACDESC_DEL: |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 845 | brcmf_fws_macdesc_indicate(fws, type, data); |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 846 | break; |
| 847 | case BRCMF_FWS_TYPE_RSSI: |
| 848 | brcmf_fws_rssi_indicate(fws, *data); |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 849 | break; |
| 850 | case BRCMF_FWS_TYPE_TRANS_ID: |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 851 | brcmf_fws_dbg_seqnum_check(fws, data); |
| 852 | break; |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 853 | default: |
| 854 | fws->stats.tlv_invalid_type++; |
| 855 | break; |
| 856 | } |
| 857 | |
| 858 | signal_data += len + 2; |
| 859 | data_len -= len + 2; |
| 860 | } |
| 861 | |
| 862 | if (data_len != 0) |
| 863 | fws->stats.tlv_parse_failed++; |
| 864 | |
| 865 | /* signalling processing result does |
| 866 | * not affect the actual ethernet packet. |
| 867 | */ |
| 868 | skb_pull(skb, signal_len); |
| 869 | |
| 870 | /* this may be a signal-only packet |
| 871 | */ |
| 872 | if (skb->len == 0) |
| 873 | fws->stats.header_only_pkt++; |
| 874 | |
| 875 | brcmf_fws_unlock(drvr, flags); |
| 876 | return 0; |
| 877 | } |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 878 | |
| 879 | void brcmf_fws_reset_interface(struct brcmf_if *ifp) |
| 880 | { |
| 881 | struct brcmf_fws_mac_descriptor *entry = ifp->fws_desc; |
| 882 | |
| 883 | brcmf_dbg(TRACE, "enter: idx=%d\n", ifp->bssidx); |
| 884 | if (!entry) |
| 885 | return; |
| 886 | |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 887 | brcmf_fws_init_mac_descriptor(entry, ifp->mac_addr, ifp->ifidx); |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | void brcmf_fws_add_interface(struct brcmf_if *ifp) |
| 891 | { |
| 892 | struct brcmf_fws_mac_descriptor *entry; |
| 893 | |
| 894 | brcmf_dbg(TRACE, "enter: idx=%d, mac=%pM\n", |
| 895 | ifp->bssidx, ifp->mac_addr); |
| 896 | if (!ifp->drvr->fw_signals) |
| 897 | return; |
| 898 | |
| 899 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 900 | if (entry) { |
| 901 | ifp->fws_desc = entry; |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 902 | brcmf_fws_init_mac_descriptor(entry, ifp->mac_addr, ifp->ifidx); |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 903 | brcmu_pktq_init(&entry->psq, BRCMF_FWS_PSQ_PREC_COUNT, |
| 904 | BRCMF_FWS_PSQ_LEN); |
| 905 | } else { |
| 906 | brcmf_err("no firmware signalling\n"); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | void brcmf_fws_del_interface(struct brcmf_if *ifp) |
| 911 | { |
| 912 | struct brcmf_fws_mac_descriptor *entry = ifp->fws_desc; |
| 913 | |
| 914 | brcmf_dbg(TRACE, "enter: idx=%d\n", ifp->bssidx); |
| 915 | if (!entry) |
| 916 | return; |
| 917 | |
| 918 | ifp->fws_desc = NULL; |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 919 | brcmf_fws_clear_mac_descriptor(entry); |
Arend van Spriel | a3e993c | 2013-04-03 12:40:36 +0200 | [diff] [blame] | 920 | brcmf_fws_cleanup(ifp->drvr->fws, ifp->ifidx); |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 921 | kfree(entry); |
| 922 | } |