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> |
Arend van Spriel | c7f34a6 | 2013-04-03 12:40:39 +0200 | [diff] [blame] | 17 | #include <linux/module.h> |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 18 | #include <linux/if_ether.h> |
| 19 | #include <linux/spinlock.h> |
| 20 | #include <linux/skbuff.h> |
| 21 | #include <linux/netdevice.h> |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 22 | #include <linux/etherdevice.h> |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 23 | #include <linux/err.h> |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 24 | #include <linux/jiffies.h> |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 25 | #include <uapi/linux/nl80211.h> |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 26 | #include <net/cfg80211.h> |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 27 | |
| 28 | #include <brcmu_utils.h> |
| 29 | #include <brcmu_wifi.h> |
| 30 | #include "dhd.h" |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 31 | #include "dhd_proto.h" |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 32 | #include "dhd_dbg.h" |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame] | 33 | #include "dhd_bus.h" |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 34 | #include "fwil.h" |
Arend van Spriel | a7965fb | 2013-04-11 17:08:37 +0200 | [diff] [blame] | 35 | #include "fwil_types.h" |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 36 | #include "fweh.h" |
| 37 | #include "fwsignal.h" |
Arend van Spriel | a7965fb | 2013-04-11 17:08:37 +0200 | [diff] [blame] | 38 | #include "p2p.h" |
| 39 | #include "wl_cfg80211.h" |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 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) \ |
Arend van Spriel | 9460723 | 2013-04-03 12:40:46 +0200 | [diff] [blame] | 66 | BRCMF_FWS_TLV_DEF(FIFO_CREDITBACK, 11, 6) \ |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 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 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 74 | /* |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 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 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 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 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 95 | #ifdef DEBUG |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 96 | /* |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 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 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 126 | /* |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 127 | * flags used to enable tlv signalling from firmware. |
| 128 | */ |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 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 |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 136 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 137 | #define BRCMF_FWS_MAC_DESC_TABLE_SIZE 32 |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 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 |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 142 | #define BRCMF_FWS_FLOWCONTROL_HIWATER 128 |
| 143 | #define BRCMF_FWS_FLOWCONTROL_LOWATER 64 |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 144 | |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 145 | #define BRCMF_FWS_PSQ_PREC_COUNT ((NL80211_NUM_ACS + 1) * 2) |
| 146 | #define BRCMF_FWS_PSQ_LEN 256 |
| 147 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 148 | #define BRCMF_FWS_HTOD_FLAG_PKTFROMHOST 0x01 |
| 149 | #define BRCMF_FWS_HTOD_FLAG_PKT_REQUESTED 0x02 |
| 150 | |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 151 | #define BRCMF_FWS_RET_OK_NOSCHEDULE 0 |
| 152 | #define BRCMF_FWS_RET_OK_SCHEDULE 1 |
| 153 | |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 154 | /** |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 155 | * enum brcmf_fws_skb_state - indicates processing state of skb. |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 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. |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 160 | */ |
| 161 | enum brcmf_fws_skb_state { |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 162 | BRCMF_FWS_SKBSTATE_NEW, |
| 163 | BRCMF_FWS_SKBSTATE_DELAYED, |
| 164 | BRCMF_FWS_SKBSTATE_SUPPRESSED |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | /** |
| 168 | * struct brcmf_skbuff_cb - control buffer associated with skbuff. |
| 169 | * |
| 170 | * @if_flags: holds interface index and packet related flags. |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 171 | * @htod: host to device packet identifier (used in PKTTAG tlv). |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 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; |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 180 | u32 htod; |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 181 | enum brcmf_fws_skb_state state; |
| 182 | struct brcmf_fws_mac_descriptor *mac; |
| 183 | }; |
| 184 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 185 | /* |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 186 | * macro casting skbuff control buffer to struct brcmf_skbuff_cb. |
| 187 | */ |
| 188 | #define brcmf_skbcb(skb) ((struct brcmf_skbuff_cb *)((skb)->cb)) |
| 189 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 190 | /* |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 191 | * sk_buff control if flags |
| 192 | * |
| 193 | * b[11] - packet sent upon firmware request. |
| 194 | * b[10] - packet only contains signalling data. |
| 195 | * b[9] - packet is a tx packet. |
| 196 | * b[8] - packet uses FIFO credit (non-pspoll). |
| 197 | * b[7] - interface in AP mode. |
| 198 | * b[6:4] - AC FIFO number. |
| 199 | * b[3:0] - interface index. |
| 200 | */ |
| 201 | #define BRCMF_SKB_IF_FLAGS_REQUESTED_MASK 0x0800 |
| 202 | #define BRCMF_SKB_IF_FLAGS_REQUESTED_SHIFT 11 |
| 203 | #define BRCMF_SKB_IF_FLAGS_SIGNAL_ONLY_MASK 0x0400 |
| 204 | #define BRCMF_SKB_IF_FLAGS_SIGNAL_ONLY_SHIFT 10 |
| 205 | #define BRCMF_SKB_IF_FLAGS_TRANSMIT_MASK 0x0200 |
| 206 | #define BRCMF_SKB_IF_FLAGS_TRANSMIT_SHIFT 9 |
| 207 | #define BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK 0x0100 |
| 208 | #define BRCMF_SKB_IF_FLAGS_CREDITCHECK_SHIFT 8 |
| 209 | #define BRCMF_SKB_IF_FLAGS_IF_AP_MASK 0x0080 |
| 210 | #define BRCMF_SKB_IF_FLAGS_IF_AP_SHIFT 7 |
| 211 | #define BRCMF_SKB_IF_FLAGS_FIFO_MASK 0x0070 |
| 212 | #define BRCMF_SKB_IF_FLAGS_FIFO_SHIFT 4 |
| 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 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 225 | /* |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 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 |
| 249 | #define BRCMF_SKB_HTOD_TAG_FREERUN_SHIFT 0 |
| 250 | |
| 251 | #define brcmf_skb_htod_tag_set_field(skb, field, value) \ |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame] | 252 | brcmu_maskset32(&(brcmf_skbcb(skb)->htod), \ |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 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) \ |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame] | 256 | brcmu_maskget32(brcmf_skbcb(skb)->htod, \ |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 257 | BRCMF_SKB_HTOD_TAG_ ## field ## _MASK, \ |
| 258 | BRCMF_SKB_HTOD_TAG_ ## field ## _SHIFT) |
| 259 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 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 | |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 275 | /* How long to defer borrowing in jiffies */ |
| 276 | #define BRCMF_FWS_BORROW_DEFER_PERIOD (HZ / 10) |
| 277 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 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 | |
Arend van Spriel | c7f34a6 | 2013-04-03 12:40:39 +0200 | [diff] [blame] | 318 | enum brcmf_fws_fcmode { |
| 319 | BRCMF_FWS_FCMODE_NONE, |
| 320 | BRCMF_FWS_FCMODE_IMPLIED_CREDIT, |
| 321 | BRCMF_FWS_FCMODE_EXPLICIT_CREDIT |
| 322 | }; |
| 323 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 324 | enum brcmf_fws_mac_desc_state { |
| 325 | BRCMF_FWS_STATE_OPEN = 1, |
| 326 | BRCMF_FWS_STATE_CLOSE |
| 327 | }; |
| 328 | |
Arend van Spriel | ebb9388 | 2013-04-03 12:40:35 +0200 | [diff] [blame] | 329 | /** |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 330 | * struct brcmf_fws_mac_descriptor - firmware signalling data per node/interface |
| 331 | * |
| 332 | * @occupied: slot is in use. |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 333 | * @mac_handle: handle for mac entry determined by firmware. |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 334 | * @interface_id: interface index. |
| 335 | * @state: current state. |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 336 | * @suppressed: mac entry is suppressed. |
| 337 | * @generation: generation bit. |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 338 | * @ac_bitmap: ac queue bitmap. |
| 339 | * @requested_credit: credits requested by firmware. |
| 340 | * @ea: ethernet address. |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 341 | * @seq: per-node free-running sequence. |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 342 | * @psq: power-save queue. |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 343 | * @transit_count: packet in transit to firmware. |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 344 | */ |
| 345 | struct brcmf_fws_mac_descriptor { |
| 346 | u8 occupied; |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 347 | u8 mac_handle; |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 348 | u8 interface_id; |
| 349 | u8 state; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 350 | bool suppressed; |
| 351 | u8 generation; |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 352 | u8 ac_bitmap; |
| 353 | u8 requested_credit; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 354 | u8 requested_packet; |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 355 | u8 ea[ETH_ALEN]; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 356 | u8 seq[BRCMF_FWS_FIFO_COUNT]; |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 357 | struct pktq psq; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 358 | int transit_count; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 359 | int suppress_count; |
| 360 | int suppr_transit_count; |
| 361 | bool send_tim_signal; |
| 362 | u8 traffic_pending_bmp; |
| 363 | u8 traffic_lastreported_bmp; |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 364 | }; |
| 365 | |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 366 | #define BRCMF_FWS_HANGER_MAXITEMS 1024 |
| 367 | |
| 368 | /** |
| 369 | * enum brcmf_fws_hanger_item_state - state of hanger item. |
| 370 | * |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 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. |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 374 | */ |
| 375 | enum brcmf_fws_hanger_item_state { |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 376 | BRCMF_FWS_HANGER_ITEM_STATE_FREE = 1, |
| 377 | BRCMF_FWS_HANGER_ITEM_STATE_INUSE, |
| 378 | BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 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. |
| 386 | * @gen: generation. |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 387 | * @pkt: packet itself. |
| 388 | */ |
| 389 | struct brcmf_fws_hanger_item { |
| 390 | enum brcmf_fws_hanger_item_state state; |
| 391 | u8 gen; |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 392 | struct sk_buff *pkt; |
| 393 | }; |
| 394 | |
| 395 | /** |
| 396 | * struct brcmf_fws_hanger - holds packets awaiting firmware txstatus. |
| 397 | * |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 398 | * @pushed: packets pushed to await txstatus. |
| 399 | * @popped: packets popped upon handling txstatus. |
| 400 | * @failed_to_push: packets that could not be pushed. |
| 401 | * @failed_to_pop: packets that could not be popped. |
| 402 | * @failed_slotfind: packets for which failed to find an entry. |
| 403 | * @slot_pos: last returned item index for a free entry. |
| 404 | * @items: array of hanger items. |
| 405 | */ |
| 406 | struct brcmf_fws_hanger { |
| 407 | u32 pushed; |
| 408 | u32 popped; |
| 409 | u32 failed_to_push; |
| 410 | u32 failed_to_pop; |
| 411 | u32 failed_slotfind; |
| 412 | u32 slot_pos; |
| 413 | struct brcmf_fws_hanger_item items[BRCMF_FWS_HANGER_MAXITEMS]; |
| 414 | }; |
| 415 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 416 | struct brcmf_fws_macdesc_table { |
| 417 | struct brcmf_fws_mac_descriptor nodes[BRCMF_FWS_MAC_DESC_TABLE_SIZE]; |
| 418 | struct brcmf_fws_mac_descriptor iface[BRCMF_MAX_IFS]; |
| 419 | struct brcmf_fws_mac_descriptor other; |
| 420 | }; |
| 421 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 422 | struct brcmf_fws_info { |
| 423 | struct brcmf_pub *drvr; |
| 424 | struct brcmf_fws_stats stats; |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 425 | struct brcmf_fws_hanger hanger; |
Arend van Spriel | c7f34a6 | 2013-04-03 12:40:39 +0200 | [diff] [blame] | 426 | enum brcmf_fws_fcmode fcmode; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 427 | struct brcmf_fws_macdesc_table desc; |
| 428 | struct workqueue_struct *fws_wq; |
| 429 | struct work_struct fws_dequeue_work; |
| 430 | u32 fifo_enqpkt[BRCMF_FWS_FIFO_COUNT]; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 431 | int fifo_credit[BRCMF_FWS_FIFO_COUNT]; |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 432 | int credits_borrowed[BRCMF_FWS_FIFO_AC_VO + 1]; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 433 | int deq_node_pos[BRCMF_FWS_FIFO_COUNT]; |
| 434 | u32 fifo_credit_map; |
| 435 | u32 fifo_delay_map; |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 436 | unsigned long borrow_defer_timestamp; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 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 |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 451 | }; |
| 452 | |
Arend van Spriel | c7f34a6 | 2013-04-03 12:40:39 +0200 | [diff] [blame] | 453 | static int fcmode; |
| 454 | module_param(fcmode, int, S_IRUSR); |
| 455 | MODULE_PARM_DESC(fcmode, "mode of firmware signalled flow control"); |
| 456 | |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 457 | #define BRCMF_FWS_TLV_DEF(name, id, len) \ |
| 458 | case BRCMF_FWS_TYPE_ ## name: \ |
| 459 | return len; |
| 460 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 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 | */ |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 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: |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 475 | fws->stats.tlv_invalid_type++; |
| 476 | break; |
| 477 | } |
| 478 | return -EINVAL; |
| 479 | } |
| 480 | #undef BRCMF_FWS_TLV_DEF |
| 481 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 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) { |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 500 | brcmu_pkt_buf_free_skb(skb); |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 501 | skb = brcmu_pktq_pdeq_match(q, prec, matchfn, &ifidx); |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 506 | static void brcmf_fws_hanger_init(struct brcmf_fws_hanger *hanger) |
| 507 | { |
| 508 | int i; |
| 509 | |
| 510 | brcmf_dbg(TRACE, "enter\n"); |
| 511 | memset(hanger, 0, sizeof(*hanger)); |
| 512 | for (i = 0; i < ARRAY_SIZE(hanger->items); i++) |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 513 | hanger->items[i].state = BRCMF_FWS_HANGER_ITEM_STATE_FREE; |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 514 | } |
| 515 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 516 | static u32 brcmf_fws_hanger_get_free_slot(struct brcmf_fws_hanger *h) |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 517 | { |
| 518 | u32 i; |
| 519 | |
| 520 | brcmf_dbg(TRACE, "enter\n"); |
| 521 | i = (h->slot_pos + 1) % BRCMF_FWS_HANGER_MAXITEMS; |
| 522 | |
| 523 | while (i != h->slot_pos) { |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 524 | if (h->items[i].state == BRCMF_FWS_HANGER_ITEM_STATE_FREE) { |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 525 | h->slot_pos = i; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 526 | goto done; |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 527 | } |
| 528 | i++; |
| 529 | if (i == BRCMF_FWS_HANGER_MAXITEMS) |
| 530 | i = 0; |
| 531 | } |
| 532 | brcmf_err("all slots occupied\n"); |
| 533 | h->failed_slotfind++; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 534 | i = BRCMF_FWS_HANGER_MAXITEMS; |
| 535 | done: |
| 536 | brcmf_dbg(TRACE, "exit: %d\n", i); |
| 537 | return i; |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 538 | } |
| 539 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 540 | static int brcmf_fws_hanger_pushpkt(struct brcmf_fws_hanger *h, |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 541 | struct sk_buff *pkt, u32 slot_id) |
| 542 | { |
| 543 | brcmf_dbg(TRACE, "enter\n"); |
| 544 | if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS) |
| 545 | return -ENOENT; |
| 546 | |
| 547 | if (h->items[slot_id].state != BRCMF_FWS_HANGER_ITEM_STATE_FREE) { |
| 548 | brcmf_err("slot is not free\n"); |
| 549 | h->failed_to_push++; |
| 550 | return -EINVAL; |
| 551 | } |
| 552 | |
| 553 | h->items[slot_id].state = BRCMF_FWS_HANGER_ITEM_STATE_INUSE; |
| 554 | h->items[slot_id].pkt = pkt; |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 555 | h->pushed++; |
| 556 | return 0; |
| 557 | } |
| 558 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 559 | static int brcmf_fws_hanger_poppkt(struct brcmf_fws_hanger *h, |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 560 | u32 slot_id, struct sk_buff **pktout, |
| 561 | bool remove_item) |
| 562 | { |
| 563 | brcmf_dbg(TRACE, "enter\n"); |
| 564 | if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS) |
| 565 | return -ENOENT; |
| 566 | |
| 567 | if (h->items[slot_id].state == BRCMF_FWS_HANGER_ITEM_STATE_FREE) { |
| 568 | brcmf_err("entry not in use\n"); |
| 569 | h->failed_to_pop++; |
| 570 | return -EINVAL; |
| 571 | } |
| 572 | |
| 573 | *pktout = h->items[slot_id].pkt; |
| 574 | if (remove_item) { |
| 575 | h->items[slot_id].state = BRCMF_FWS_HANGER_ITEM_STATE_FREE; |
| 576 | h->items[slot_id].pkt = NULL; |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 577 | h->items[slot_id].gen = 0xff; |
| 578 | h->popped++; |
| 579 | } |
| 580 | return 0; |
| 581 | } |
| 582 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 583 | static int brcmf_fws_hanger_mark_suppressed(struct brcmf_fws_hanger *h, |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 584 | u32 slot_id, u8 gen) |
| 585 | { |
| 586 | brcmf_dbg(TRACE, "enter\n"); |
| 587 | |
| 588 | if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS) |
| 589 | return -ENOENT; |
| 590 | |
| 591 | h->items[slot_id].gen = gen; |
| 592 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 593 | if (h->items[slot_id].state != BRCMF_FWS_HANGER_ITEM_STATE_INUSE) { |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 594 | brcmf_err("entry not in use\n"); |
| 595 | return -EINVAL; |
| 596 | } |
| 597 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 598 | h->items[slot_id].state = BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED; |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 599 | return 0; |
| 600 | } |
| 601 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 602 | static int brcmf_fws_hanger_get_genbit(struct brcmf_fws_hanger *hanger, |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 603 | struct sk_buff *pkt, u32 slot_id, |
| 604 | int *gen) |
| 605 | { |
| 606 | brcmf_dbg(TRACE, "enter\n"); |
| 607 | *gen = 0xff; |
| 608 | |
| 609 | if (slot_id >= BRCMF_FWS_HANGER_MAXITEMS) |
| 610 | return -ENOENT; |
| 611 | |
| 612 | if (hanger->items[slot_id].state == BRCMF_FWS_HANGER_ITEM_STATE_FREE) { |
| 613 | brcmf_err("slot not in use\n"); |
| 614 | return -EINVAL; |
| 615 | } |
| 616 | |
| 617 | *gen = hanger->items[slot_id].gen; |
| 618 | return 0; |
| 619 | } |
| 620 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 621 | static void brcmf_fws_hanger_cleanup(struct brcmf_fws_info *fws, |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 622 | bool (*fn)(struct sk_buff *, void *), |
| 623 | int ifidx) |
| 624 | { |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 625 | struct brcmf_fws_hanger *h = &fws->hanger; |
Arend van Spriel | 6971280 | 2013-04-03 12:40:37 +0200 | [diff] [blame] | 626 | struct sk_buff *skb; |
| 627 | int i; |
| 628 | enum brcmf_fws_hanger_item_state s; |
| 629 | |
| 630 | brcmf_dbg(TRACE, "enter: ifidx=%d\n", ifidx); |
| 631 | for (i = 0; i < ARRAY_SIZE(h->items); i++) { |
| 632 | s = h->items[i].state; |
| 633 | if (s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE || |
| 634 | s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE_SUPPRESSED) { |
| 635 | skb = h->items[i].pkt; |
| 636 | if (fn == NULL || fn(skb, &ifidx)) { |
| 637 | /* suppress packets freed from psq */ |
| 638 | if (s == BRCMF_FWS_HANGER_ITEM_STATE_INUSE) |
| 639 | brcmu_pkt_buf_free_skb(skb); |
| 640 | h->items[i].state = |
| 641 | BRCMF_FWS_HANGER_ITEM_STATE_FREE; |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | } |
| 646 | |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 647 | static void brcmf_fws_init_mac_descriptor(struct brcmf_fws_mac_descriptor *desc, |
| 648 | u8 *addr, u8 ifidx) |
| 649 | { |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 650 | brcmf_dbg(TRACE, |
| 651 | "enter: desc %p ea=%pM, ifidx=%u\n", desc, addr, ifidx); |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 652 | desc->occupied = 1; |
| 653 | desc->state = BRCMF_FWS_STATE_OPEN; |
| 654 | desc->requested_credit = 0; |
| 655 | /* depending on use may need ifp->bssidx instead */ |
| 656 | desc->interface_id = ifidx; |
| 657 | desc->ac_bitmap = 0xff; /* update this when handling APSD */ |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 658 | if (addr) |
| 659 | memcpy(&desc->ea[0], addr, ETH_ALEN); |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static |
| 663 | void brcmf_fws_clear_mac_descriptor(struct brcmf_fws_mac_descriptor *desc) |
| 664 | { |
| 665 | brcmf_dbg(TRACE, |
| 666 | "enter: ea=%pM, ifidx=%u\n", desc->ea, desc->interface_id); |
| 667 | desc->occupied = 0; |
| 668 | desc->state = BRCMF_FWS_STATE_CLOSE; |
| 669 | desc->requested_credit = 0; |
| 670 | } |
| 671 | |
| 672 | static struct brcmf_fws_mac_descriptor * |
| 673 | brcmf_fws_mac_descriptor_lookup(struct brcmf_fws_info *fws, u8 *ea) |
| 674 | { |
| 675 | struct brcmf_fws_mac_descriptor *entry; |
| 676 | int i; |
| 677 | |
| 678 | brcmf_dbg(TRACE, "enter: ea=%pM\n", ea); |
| 679 | if (ea == NULL) |
| 680 | return ERR_PTR(-EINVAL); |
| 681 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 682 | entry = &fws->desc.nodes[0]; |
| 683 | for (i = 0; i < ARRAY_SIZE(fws->desc.nodes); i++) { |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 684 | if (entry->occupied && !memcmp(entry->ea, ea, ETH_ALEN)) |
| 685 | return entry; |
| 686 | entry++; |
| 687 | } |
| 688 | |
| 689 | return ERR_PTR(-ENOENT); |
| 690 | } |
| 691 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 692 | static struct brcmf_fws_mac_descriptor* |
Arend van Spriel | f97a7f0 | 2013-04-11 13:28:58 +0200 | [diff] [blame] | 693 | brcmf_fws_find_mac_desc(struct brcmf_fws_info *fws, struct brcmf_if *ifp, |
| 694 | u8 *da) |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 695 | { |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 696 | struct brcmf_fws_mac_descriptor *entry = &fws->desc.other; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 697 | bool multicast; |
Arend van Spriel | a7965fb | 2013-04-11 17:08:37 +0200 | [diff] [blame] | 698 | enum nl80211_iftype iftype; |
Arend van Spriel | f97a7f0 | 2013-04-11 13:28:58 +0200 | [diff] [blame] | 699 | |
| 700 | brcmf_dbg(TRACE, "enter: idx=%d\n", ifp->bssidx); |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 701 | |
| 702 | multicast = is_multicast_ether_addr(da); |
Arend van Spriel | a7965fb | 2013-04-11 17:08:37 +0200 | [diff] [blame] | 703 | iftype = brcmf_cfg80211_get_iftype(ifp); |
| 704 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 705 | /* Multicast destination and P2P clients get the interface entry. |
| 706 | * STA gets the interface entry if there is no exact match. For |
| 707 | * example, TDLS destinations have their own entry. |
| 708 | */ |
| 709 | entry = NULL; |
Arend van Spriel | a7965fb | 2013-04-11 17:08:37 +0200 | [diff] [blame] | 710 | if ((multicast || iftype == NL80211_IFTYPE_STATION || |
| 711 | iftype == NL80211_IFTYPE_P2P_CLIENT) && ifp->fws_desc) |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 712 | entry = ifp->fws_desc; |
| 713 | |
Arend van Spriel | a7965fb | 2013-04-11 17:08:37 +0200 | [diff] [blame] | 714 | if (entry != NULL && iftype != NL80211_IFTYPE_STATION) |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 715 | goto done; |
| 716 | |
| 717 | entry = brcmf_fws_mac_descriptor_lookup(fws, da); |
| 718 | if (IS_ERR(entry)) |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 719 | entry = &fws->desc.other; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 720 | |
| 721 | done: |
| 722 | brcmf_dbg(TRACE, "exit: entry=%p\n", entry); |
| 723 | return entry; |
| 724 | } |
| 725 | |
Arend van Spriel | b75c1a3 | 2013-04-17 21:25:53 +0200 | [diff] [blame] | 726 | static bool brcmf_fws_mac_desc_closed(struct brcmf_fws_info *fws, |
| 727 | struct brcmf_fws_mac_descriptor *entry, |
Arend van Spriel | 9fc6022 | 2013-04-11 17:12:04 +0200 | [diff] [blame] | 728 | int fifo) |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 729 | { |
Arend van Spriel | b75c1a3 | 2013-04-17 21:25:53 +0200 | [diff] [blame] | 730 | struct brcmf_fws_mac_descriptor *if_entry; |
Arend van Spriel | 9fc6022 | 2013-04-11 17:12:04 +0200 | [diff] [blame] | 731 | bool closed; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 732 | |
Arend van Spriel | b75c1a3 | 2013-04-17 21:25:53 +0200 | [diff] [blame] | 733 | /* for unique destination entries the related interface |
| 734 | * may be closed. |
| 735 | */ |
| 736 | if (entry->mac_handle) { |
| 737 | if_entry = &fws->desc.iface[entry->interface_id]; |
| 738 | if (if_entry->state == BRCMF_FWS_STATE_CLOSE) |
| 739 | return true; |
| 740 | } |
Arend van Spriel | 9fc6022 | 2013-04-11 17:12:04 +0200 | [diff] [blame] | 741 | /* an entry is closed when the state is closed and |
| 742 | * the firmware did not request anything. |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 743 | */ |
Arend van Spriel | 9fc6022 | 2013-04-11 17:12:04 +0200 | [diff] [blame] | 744 | closed = entry->state == BRCMF_FWS_STATE_CLOSE && |
| 745 | !entry->requested_credit && !entry->requested_packet; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 746 | |
Arend van Spriel | 9fc6022 | 2013-04-11 17:12:04 +0200 | [diff] [blame] | 747 | /* Or firmware does not allow traffic for given fifo */ |
| 748 | return closed || !(entry->ac_bitmap & BIT(fifo)); |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 749 | } |
| 750 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 751 | static void brcmf_fws_mac_desc_cleanup(struct brcmf_fws_info *fws, |
| 752 | struct brcmf_fws_mac_descriptor *entry, |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 753 | int ifidx) |
| 754 | { |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 755 | brcmf_dbg(TRACE, "enter: entry=(ea=%pM, ifid=%d), ifidx=%d\n", |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 756 | entry->ea, entry->interface_id, ifidx); |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 757 | if (entry->occupied && (ifidx == -1 || ifidx == entry->interface_id)) { |
| 758 | brcmf_dbg(TRACE, "flush psq: ifidx=%d, qlen=%d\n", |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 759 | ifidx, entry->psq.len); |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 760 | brcmf_fws_psq_flush(fws, &entry->psq, ifidx); |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 761 | entry->occupied = !!(entry->psq.len); |
| 762 | } |
| 763 | } |
| 764 | |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame] | 765 | static void brcmf_fws_bus_txq_cleanup(struct brcmf_fws_info *fws, |
| 766 | bool (*fn)(struct sk_buff *, void *), |
| 767 | int ifidx) |
| 768 | { |
| 769 | struct brcmf_fws_hanger_item *hi; |
| 770 | struct pktq *txq; |
| 771 | struct sk_buff *skb; |
| 772 | int prec; |
| 773 | u32 hslot; |
| 774 | |
| 775 | brcmf_dbg(TRACE, "enter: ifidx=%d\n", ifidx); |
| 776 | txq = brcmf_bus_gettxq(fws->drvr->bus_if); |
| 777 | if (IS_ERR(txq)) { |
| 778 | brcmf_dbg(TRACE, "no txq to clean up\n"); |
| 779 | return; |
| 780 | } |
| 781 | |
| 782 | for (prec = 0; prec < txq->num_prec; prec++) { |
| 783 | skb = brcmu_pktq_pdeq_match(txq, prec, fn, &ifidx); |
| 784 | while (skb) { |
| 785 | hslot = brcmf_skb_htod_tag_get_field(skb, HSLOT); |
| 786 | hi = &fws->hanger.items[hslot]; |
| 787 | WARN_ON(skb != hi->pkt); |
| 788 | hi->state = BRCMF_FWS_HANGER_ITEM_STATE_FREE; |
| 789 | brcmu_pkt_buf_free_skb(skb); |
| 790 | skb = brcmu_pktq_pdeq_match(txq, prec, fn, &ifidx); |
| 791 | } |
| 792 | } |
| 793 | } |
| 794 | |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 795 | static void brcmf_fws_cleanup(struct brcmf_fws_info *fws, int ifidx) |
| 796 | { |
| 797 | int i; |
| 798 | struct brcmf_fws_mac_descriptor *table; |
Arend van Spriel | a3e993c | 2013-04-03 12:40:36 +0200 | [diff] [blame] | 799 | bool (*matchfn)(struct sk_buff *, void *) = NULL; |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 800 | |
| 801 | brcmf_dbg(TRACE, "enter: ifidx=%d\n", ifidx); |
| 802 | if (fws == NULL) |
| 803 | return; |
| 804 | |
Arend van Spriel | a3e993c | 2013-04-03 12:40:36 +0200 | [diff] [blame] | 805 | if (ifidx != -1) |
| 806 | matchfn = brcmf_fws_ifidx_match; |
| 807 | |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 808 | /* cleanup individual nodes */ |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 809 | table = &fws->desc.nodes[0]; |
| 810 | for (i = 0; i < ARRAY_SIZE(fws->desc.nodes); i++) |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 811 | brcmf_fws_mac_desc_cleanup(fws, &table[i], ifidx); |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 812 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 813 | brcmf_fws_mac_desc_cleanup(fws, &fws->desc.other, ifidx); |
Arend van Spriel | e2432b6 | 2013-04-03 12:40:38 +0200 | [diff] [blame] | 814 | brcmf_fws_bus_txq_cleanup(fws, matchfn, ifidx); |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 815 | brcmf_fws_hanger_cleanup(fws, matchfn, ifidx); |
| 816 | } |
| 817 | |
| 818 | static void brcmf_fws_tim_update(struct brcmf_fws_info *ctx, |
| 819 | struct brcmf_fws_mac_descriptor *entry, |
| 820 | int prec) |
| 821 | { |
| 822 | brcmf_dbg(TRACE, "enter: ea=%pM\n", entry->ea); |
| 823 | if (entry->state == BRCMF_FWS_STATE_CLOSE) { |
| 824 | /* check delayedQ and suppressQ in one call using bitmap */ |
| 825 | if (brcmu_pktq_mlen(&entry->psq, 3 << (prec * 2)) == 0) |
| 826 | entry->traffic_pending_bmp = |
| 827 | entry->traffic_pending_bmp & ~NBITVAL(prec); |
| 828 | else |
| 829 | entry->traffic_pending_bmp = |
| 830 | entry->traffic_pending_bmp | NBITVAL(prec); |
| 831 | } |
| 832 | /* request a TIM update to firmware at the next piggyback opportunity */ |
| 833 | if (entry->traffic_lastreported_bmp != entry->traffic_pending_bmp) |
| 834 | entry->send_tim_signal = true; |
| 835 | } |
| 836 | |
| 837 | static void |
| 838 | brcmf_fws_flow_control_check(struct brcmf_fws_info *fws, struct pktq *pq, |
| 839 | u8 if_id) |
| 840 | { |
| 841 | struct brcmf_if *ifp = fws->drvr->iflist[if_id]; |
| 842 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 843 | if (WARN_ON(!ifp)) |
| 844 | return; |
| 845 | |
Wei Yongjun | 16a1f73 | 2013-04-19 10:14:31 +0800 | [diff] [blame] | 846 | brcmf_dbg(TRACE, |
| 847 | "enter: bssidx=%d, ifidx=%d\n", ifp->bssidx, ifp->ifidx); |
| 848 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 849 | if ((ifp->netif_stop & BRCMF_NETIF_STOP_REASON_FWS_FC) && |
| 850 | pq->len <= BRCMF_FWS_FLOWCONTROL_LOWATER) |
| 851 | brcmf_txflowblock_if(ifp, |
| 852 | BRCMF_NETIF_STOP_REASON_FWS_FC, false); |
| 853 | if (!(ifp->netif_stop & BRCMF_NETIF_STOP_REASON_FWS_FC) && |
| 854 | pq->len >= BRCMF_FWS_FLOWCONTROL_HIWATER) |
| 855 | brcmf_txflowblock_if(ifp, BRCMF_NETIF_STOP_REASON_FWS_FC, true); |
| 856 | return; |
Arend van Spriel | fba1400 | 2013-04-03 12:40:33 +0200 | [diff] [blame] | 857 | } |
| 858 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 859 | static int brcmf_fws_rssi_indicate(struct brcmf_fws_info *fws, s8 rssi) |
| 860 | { |
| 861 | brcmf_dbg(CTL, "rssi %d\n", rssi); |
| 862 | return 0; |
| 863 | } |
| 864 | |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 865 | static |
| 866 | int brcmf_fws_macdesc_indicate(struct brcmf_fws_info *fws, u8 type, u8 *data) |
| 867 | { |
| 868 | struct brcmf_fws_mac_descriptor *entry, *existing; |
| 869 | u8 mac_handle; |
| 870 | u8 ifidx; |
| 871 | u8 *addr; |
| 872 | |
| 873 | mac_handle = *data++; |
| 874 | ifidx = *data++; |
| 875 | addr = data; |
| 876 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 877 | entry = &fws->desc.nodes[mac_handle & 0x1F]; |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 878 | if (type == BRCMF_FWS_TYPE_MACDESC_DEL) { |
| 879 | brcmf_dbg(TRACE, "deleting mac %pM idx %d\n", addr, ifidx); |
Arend van Spriel | 9a83f1e | 2013-04-23 12:53:13 +0200 | [diff] [blame] | 880 | if (entry->occupied) { |
| 881 | brcmf_fws_mac_desc_cleanup(fws, entry, -1); |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 882 | brcmf_fws_clear_mac_descriptor(entry); |
Arend van Spriel | 9a83f1e | 2013-04-23 12:53:13 +0200 | [diff] [blame] | 883 | } else |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 884 | fws->stats.mac_update_failed++; |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 885 | return 0; |
| 886 | } |
| 887 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 888 | brcmf_dbg(TRACE, |
| 889 | "add mac %pM handle %u idx %d\n", addr, mac_handle, ifidx); |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 890 | existing = brcmf_fws_mac_descriptor_lookup(fws, addr); |
| 891 | if (IS_ERR(existing)) { |
| 892 | if (!entry->occupied) { |
| 893 | entry->mac_handle = mac_handle; |
| 894 | brcmf_fws_init_mac_descriptor(entry, addr, ifidx); |
| 895 | brcmu_pktq_init(&entry->psq, BRCMF_FWS_PSQ_PREC_COUNT, |
| 896 | BRCMF_FWS_PSQ_LEN); |
| 897 | } else { |
| 898 | fws->stats.mac_update_failed++; |
| 899 | } |
| 900 | } else { |
| 901 | if (entry != existing) { |
| 902 | brcmf_dbg(TRACE, "relocate mac\n"); |
| 903 | memcpy(entry, existing, |
| 904 | offsetof(struct brcmf_fws_mac_descriptor, psq)); |
| 905 | entry->mac_handle = mac_handle; |
| 906 | brcmf_fws_clear_mac_descriptor(existing); |
| 907 | } else { |
| 908 | brcmf_dbg(TRACE, "use existing\n"); |
| 909 | WARN_ON(entry->mac_handle != mac_handle); |
| 910 | /* TODO: what should we do here: continue, reinit, .. */ |
| 911 | } |
| 912 | } |
| 913 | return 0; |
| 914 | } |
| 915 | |
Arend van Spriel | 33753d4 | 2013-04-05 10:57:40 +0200 | [diff] [blame] | 916 | static int brcmf_fws_macdesc_state_indicate(struct brcmf_fws_info *fws, |
| 917 | u8 type, u8 *data) |
| 918 | { |
| 919 | struct brcmf_fws_mac_descriptor *entry; |
| 920 | u8 mac_handle; |
| 921 | int i; |
| 922 | |
| 923 | mac_handle = data[0]; |
| 924 | entry = &fws->desc.nodes[mac_handle & 0x1F]; |
| 925 | if (!entry->occupied) { |
| 926 | fws->stats.mac_ps_update_failed++; |
| 927 | return -ESRCH; |
| 928 | } |
| 929 | |
| 930 | /* a state update should wipe old credits? */ |
| 931 | entry->requested_credit = 0; |
| 932 | if (type == BRCMF_FWS_TYPE_MAC_OPEN) { |
| 933 | entry->state = BRCMF_FWS_STATE_OPEN; |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 934 | return BRCMF_FWS_RET_OK_SCHEDULE; |
Arend van Spriel | 33753d4 | 2013-04-05 10:57:40 +0200 | [diff] [blame] | 935 | } else { |
| 936 | entry->state = BRCMF_FWS_STATE_CLOSE; |
| 937 | for (i = BRCMF_FWS_FIFO_AC_BE; i < NL80211_NUM_ACS; i++) |
| 938 | brcmf_fws_tim_update(fws, entry, i); |
| 939 | } |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 940 | return BRCMF_FWS_RET_OK_NOSCHEDULE; |
Arend van Spriel | 33753d4 | 2013-04-05 10:57:40 +0200 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | static int brcmf_fws_interface_state_indicate(struct brcmf_fws_info *fws, |
| 944 | u8 type, u8 *data) |
| 945 | { |
| 946 | struct brcmf_fws_mac_descriptor *entry; |
| 947 | u8 ifidx; |
| 948 | int ret; |
| 949 | |
| 950 | ifidx = data[0]; |
| 951 | |
| 952 | brcmf_dbg(TRACE, "enter: ifidx=%d\n", ifidx); |
| 953 | if (ifidx >= BRCMF_MAX_IFS) { |
| 954 | ret = -ERANGE; |
| 955 | goto fail; |
| 956 | } |
| 957 | |
| 958 | entry = &fws->desc.iface[ifidx]; |
| 959 | if (!entry->occupied) { |
| 960 | ret = -ESRCH; |
| 961 | goto fail; |
| 962 | } |
| 963 | |
| 964 | switch (type) { |
| 965 | case BRCMF_FWS_TYPE_INTERFACE_OPEN: |
| 966 | entry->state = BRCMF_FWS_STATE_OPEN; |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 967 | return BRCMF_FWS_RET_OK_SCHEDULE; |
Arend van Spriel | 33753d4 | 2013-04-05 10:57:40 +0200 | [diff] [blame] | 968 | case BRCMF_FWS_TYPE_INTERFACE_CLOSE: |
| 969 | entry->state = BRCMF_FWS_STATE_CLOSE; |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 970 | return BRCMF_FWS_RET_OK_NOSCHEDULE; |
Arend van Spriel | 33753d4 | 2013-04-05 10:57:40 +0200 | [diff] [blame] | 971 | default: |
| 972 | ret = -EINVAL; |
| 973 | break; |
| 974 | } |
| 975 | fail: |
| 976 | fws->stats.if_update_failed++; |
| 977 | return ret; |
| 978 | } |
| 979 | |
Arend van Spriel | 5f38b68 | 2013-04-05 10:57:41 +0200 | [diff] [blame] | 980 | static int brcmf_fws_request_indicate(struct brcmf_fws_info *fws, u8 type, |
| 981 | u8 *data) |
| 982 | { |
| 983 | struct brcmf_fws_mac_descriptor *entry; |
| 984 | |
| 985 | entry = &fws->desc.nodes[data[1] & 0x1F]; |
| 986 | if (!entry->occupied) { |
| 987 | if (type == BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT) |
| 988 | fws->stats.credit_request_failed++; |
| 989 | else |
| 990 | fws->stats.packet_request_failed++; |
| 991 | return -ESRCH; |
| 992 | } |
| 993 | |
| 994 | if (type == BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT) |
| 995 | entry->requested_credit = data[0]; |
| 996 | else |
| 997 | entry->requested_packet = data[0]; |
| 998 | |
| 999 | entry->ac_bitmap = data[2]; |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 1000 | return BRCMF_FWS_RET_OK_SCHEDULE; |
Arend van Spriel | 5f38b68 | 2013-04-05 10:57:41 +0200 | [diff] [blame] | 1001 | } |
| 1002 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1003 | static void brcmf_fws_return_credits(struct brcmf_fws_info *fws, |
| 1004 | u8 fifo, u8 credits) |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1005 | { |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 1006 | int lender_ac; |
| 1007 | int *borrowed; |
| 1008 | int *fifo_credit; |
| 1009 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1010 | if (!credits) |
| 1011 | return; |
| 1012 | |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 1013 | if ((fifo == BRCMF_FWS_FIFO_AC_BE) && |
| 1014 | (fws->credits_borrowed[0])) { |
| 1015 | for (lender_ac = BRCMF_FWS_FIFO_AC_VO; lender_ac >= 0; |
| 1016 | lender_ac--) { |
| 1017 | borrowed = &fws->credits_borrowed[lender_ac]; |
| 1018 | if (*borrowed) { |
| 1019 | fws->fifo_credit_map |= (1 << lender_ac); |
| 1020 | fifo_credit = &fws->fifo_credit[lender_ac]; |
| 1021 | if (*borrowed >= credits) { |
| 1022 | *borrowed -= credits; |
| 1023 | *fifo_credit += credits; |
| 1024 | return; |
| 1025 | } else { |
| 1026 | credits -= *borrowed; |
| 1027 | *fifo_credit += *borrowed; |
| 1028 | *borrowed = 0; |
| 1029 | } |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1034 | fws->fifo_credit_map |= 1 << fifo; |
| 1035 | fws->fifo_credit[fifo] += credits; |
| 1036 | } |
| 1037 | |
| 1038 | static void brcmf_fws_schedule_deq(struct brcmf_fws_info *fws) |
| 1039 | { |
| 1040 | /* only schedule dequeue when there are credits for delayed traffic */ |
| 1041 | if (fws->fifo_credit_map & fws->fifo_delay_map) |
| 1042 | queue_work(fws->fws_wq, &fws->fws_dequeue_work); |
| 1043 | } |
| 1044 | |
| 1045 | static void brcmf_skb_pick_up_credit(struct brcmf_fws_info *fws, int fifo, |
| 1046 | struct sk_buff *p) |
| 1047 | { |
| 1048 | struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(p)->mac; |
| 1049 | |
| 1050 | if (brcmf_skbcb(p)->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK) { |
| 1051 | if (fws->fcmode != BRCMF_FWS_FCMODE_IMPLIED_CREDIT) |
| 1052 | return; |
| 1053 | brcmf_fws_return_credits(fws, fifo, 1); |
| 1054 | } else { |
| 1055 | /* |
| 1056 | * if this packet did not count against FIFO credit, it |
| 1057 | * must have taken a requested_credit from the destination |
| 1058 | * entry (for pspoll etc.) |
| 1059 | */ |
| 1060 | if (!brcmf_skb_if_flags_get_field(p, REQUESTED)) |
| 1061 | entry->requested_credit++; |
| 1062 | } |
| 1063 | brcmf_fws_schedule_deq(fws); |
| 1064 | } |
| 1065 | |
| 1066 | static int brcmf_fws_enq(struct brcmf_fws_info *fws, |
| 1067 | enum brcmf_fws_skb_state state, int fifo, |
| 1068 | struct sk_buff *p) |
| 1069 | { |
| 1070 | int prec = 2 * fifo; |
| 1071 | u32 *qfull_stat = &fws->stats.delayq_full_error; |
| 1072 | |
| 1073 | struct brcmf_fws_mac_descriptor *entry; |
| 1074 | |
| 1075 | entry = brcmf_skbcb(p)->mac; |
| 1076 | if (entry == NULL) { |
| 1077 | brcmf_err("no mac descriptor found for skb %p\n", p); |
| 1078 | return -ENOENT; |
| 1079 | } |
| 1080 | |
| 1081 | brcmf_dbg(TRACE, "enter: ea=%pM, qlen=%d\n", entry->ea, entry->psq.len); |
| 1082 | if (state == BRCMF_FWS_SKBSTATE_SUPPRESSED) { |
| 1083 | prec += 1; |
| 1084 | qfull_stat = &fws->stats.supprq_full_error; |
| 1085 | } |
| 1086 | |
| 1087 | if (brcmu_pktq_penq(&entry->psq, prec, p) == NULL) { |
| 1088 | *qfull_stat += 1; |
| 1089 | return -ENFILE; |
| 1090 | } |
| 1091 | |
| 1092 | /* increment total enqueued packet count */ |
| 1093 | fws->fifo_delay_map |= 1 << fifo; |
| 1094 | fws->fifo_enqpkt[fifo]++; |
| 1095 | |
| 1096 | /* update the sk_buff state */ |
| 1097 | brcmf_skbcb(p)->state = state; |
| 1098 | if (state == BRCMF_FWS_SKBSTATE_SUPPRESSED) |
| 1099 | entry->suppress_count++; |
| 1100 | |
| 1101 | /* |
| 1102 | * A packet has been pushed so update traffic |
| 1103 | * availability bitmap, if applicable |
| 1104 | */ |
| 1105 | brcmf_fws_tim_update(fws, entry, fifo); |
| 1106 | brcmf_fws_flow_control_check(fws, &entry->psq, |
| 1107 | brcmf_skb_if_flags_get_field(p, INDEX)); |
| 1108 | return 0; |
| 1109 | } |
| 1110 | |
| 1111 | static struct sk_buff *brcmf_fws_deq(struct brcmf_fws_info *fws, int fifo) |
| 1112 | { |
| 1113 | struct brcmf_fws_mac_descriptor *table; |
| 1114 | struct brcmf_fws_mac_descriptor *entry; |
| 1115 | struct sk_buff *p; |
| 1116 | int use_credit = 1; |
| 1117 | int num_nodes; |
| 1118 | int node_pos; |
| 1119 | int prec_out; |
Arend van Spriel | 07529d2 | 2013-04-17 21:25:49 +0200 | [diff] [blame] | 1120 | int pmsk; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1121 | int i; |
| 1122 | |
| 1123 | table = (struct brcmf_fws_mac_descriptor *)&fws->desc; |
| 1124 | num_nodes = sizeof(fws->desc) / sizeof(struct brcmf_fws_mac_descriptor); |
| 1125 | node_pos = fws->deq_node_pos[fifo]; |
| 1126 | |
| 1127 | for (i = 0; i < num_nodes; i++) { |
| 1128 | entry = &table[(node_pos + i) % num_nodes]; |
Arend van Spriel | b75c1a3 | 2013-04-17 21:25:53 +0200 | [diff] [blame] | 1129 | if (!entry->occupied || |
| 1130 | brcmf_fws_mac_desc_closed(fws, entry, fifo)) |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1131 | continue; |
| 1132 | |
| 1133 | if (entry->suppressed) |
| 1134 | pmsk = 2; |
Arend van Spriel | 07529d2 | 2013-04-17 21:25:49 +0200 | [diff] [blame] | 1135 | else |
| 1136 | pmsk = 3; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1137 | p = brcmu_pktq_mdeq(&entry->psq, pmsk << (fifo * 2), &prec_out); |
| 1138 | if (p == NULL) { |
| 1139 | if (entry->suppressed) { |
| 1140 | if (entry->suppr_transit_count > |
| 1141 | entry->suppress_count) |
| 1142 | return NULL; |
| 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 | |
| 1151 | /* did the packet come from suppress sub-queue? */ |
| 1152 | if (entry->requested_credit > 0) { |
| 1153 | entry->requested_credit--; |
| 1154 | /* |
| 1155 | * if the packet was pulled out while destination is in |
| 1156 | * closed state but had a non-zero packets requested, |
| 1157 | * then this should not count against the FIFO credit. |
| 1158 | * That is due to the fact that the firmware will |
| 1159 | * most likely hold onto this packet until a suitable |
| 1160 | * time later to push it to the appropriate AC FIFO. |
| 1161 | */ |
| 1162 | if (entry->state == BRCMF_FWS_STATE_CLOSE) |
| 1163 | use_credit = 0; |
| 1164 | } else if (entry->requested_packet > 0) { |
| 1165 | entry->requested_packet--; |
| 1166 | brcmf_skb_if_flags_set_field(p, REQUESTED, 1); |
| 1167 | if (entry->state == BRCMF_FWS_STATE_CLOSE) |
| 1168 | use_credit = 0; |
| 1169 | } |
| 1170 | brcmf_skb_if_flags_set_field(p, CREDITCHECK, use_credit); |
| 1171 | |
| 1172 | /* move dequeue position to ensure fair round-robin */ |
| 1173 | fws->deq_node_pos[fifo] = (node_pos + i + 1) % num_nodes; |
| 1174 | brcmf_fws_flow_control_check(fws, &entry->psq, |
| 1175 | brcmf_skb_if_flags_get_field(p, |
| 1176 | INDEX) |
| 1177 | ); |
| 1178 | /* |
| 1179 | * A packet has been picked up, update traffic |
| 1180 | * availability bitmap, if applicable |
| 1181 | */ |
| 1182 | brcmf_fws_tim_update(fws, entry, fifo); |
| 1183 | |
| 1184 | /* |
| 1185 | * decrement total enqueued fifo packets and |
| 1186 | * clear delay bitmap if done. |
| 1187 | */ |
| 1188 | fws->fifo_enqpkt[fifo]--; |
| 1189 | if (fws->fifo_enqpkt[fifo] == 0) |
| 1190 | fws->fifo_delay_map &= ~(1 << fifo); |
| 1191 | goto done; |
| 1192 | } |
| 1193 | p = NULL; |
| 1194 | done: |
| 1195 | brcmf_dbg(TRACE, "exit: fifo %d skb %p\n", fifo, p); |
| 1196 | return p; |
| 1197 | } |
| 1198 | |
| 1199 | static int brcmf_fws_txstatus_suppressed(struct brcmf_fws_info *fws, int fifo, |
| 1200 | struct sk_buff *skb, u32 genbit) |
| 1201 | { |
| 1202 | struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(skb)->mac; |
| 1203 | u32 hslot; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1204 | int ret; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1205 | |
| 1206 | hslot = brcmf_skb_htod_tag_get_field(skb, HSLOT); |
| 1207 | |
| 1208 | /* this packet was suppressed */ |
| 1209 | if (!entry->suppressed || entry->generation != genbit) { |
| 1210 | entry->suppressed = true; |
| 1211 | entry->suppress_count = brcmu_pktq_mlen(&entry->psq, |
| 1212 | 1 << (fifo * 2 + 1)); |
| 1213 | entry->suppr_transit_count = entry->transit_count; |
| 1214 | } |
| 1215 | |
| 1216 | entry->generation = genbit; |
| 1217 | |
| 1218 | ret = brcmf_fws_enq(fws, BRCMF_FWS_SKBSTATE_SUPPRESSED, fifo, skb); |
| 1219 | if (ret != 0) { |
| 1220 | /* suppress q is full, drop this packet */ |
| 1221 | brcmf_fws_hanger_poppkt(&fws->hanger, hslot, &skb, |
| 1222 | true); |
| 1223 | } else { |
| 1224 | /* |
| 1225 | * Mark suppressed to avoid a double free during |
| 1226 | * wlfc cleanup |
| 1227 | */ |
| 1228 | brcmf_fws_hanger_mark_suppressed(&fws->hanger, hslot, |
| 1229 | genbit); |
| 1230 | entry->suppress_count++; |
| 1231 | } |
| 1232 | |
| 1233 | return ret; |
| 1234 | } |
| 1235 | |
| 1236 | static int |
| 1237 | brcmf_fws_txstatus_process(struct brcmf_fws_info *fws, u8 flags, u32 hslot, |
| 1238 | u32 genbit) |
| 1239 | { |
| 1240 | u32 fifo; |
| 1241 | int ret; |
| 1242 | bool remove_from_hanger = true; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1243 | struct sk_buff *skb; |
| 1244 | struct brcmf_fws_mac_descriptor *entry = NULL; |
| 1245 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1246 | brcmf_dbg(TRACE, "status: flags=0x%X, hslot=%d\n", |
| 1247 | flags, hslot); |
| 1248 | |
| 1249 | if (flags == BRCMF_FWS_TXSTATUS_DISCARD) |
| 1250 | fws->stats.txs_discard++; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1251 | else if (flags == BRCMF_FWS_TXSTATUS_CORE_SUPPRESS) { |
| 1252 | fws->stats.txs_supp_core++; |
| 1253 | remove_from_hanger = false; |
| 1254 | } else if (flags == BRCMF_FWS_TXSTATUS_FW_PS_SUPPRESS) { |
| 1255 | fws->stats.txs_supp_ps++; |
| 1256 | remove_from_hanger = false; |
| 1257 | } else if (flags == BRCMF_FWS_TXSTATUS_FW_TOSSED) |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1258 | fws->stats.txs_tossed++; |
| 1259 | else |
| 1260 | brcmf_err("unexpected txstatus\n"); |
| 1261 | |
| 1262 | ret = brcmf_fws_hanger_poppkt(&fws->hanger, hslot, &skb, |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1263 | remove_from_hanger); |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1264 | if (ret != 0) { |
| 1265 | brcmf_err("no packet in hanger slot: hslot=%d\n", hslot); |
| 1266 | return ret; |
| 1267 | } |
| 1268 | |
| 1269 | entry = brcmf_skbcb(skb)->mac; |
| 1270 | if (WARN_ON(!entry)) { |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1271 | brcmu_pkt_buf_free_skb(skb); |
| 1272 | return -EINVAL; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1273 | } |
| 1274 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1275 | /* pick up the implicit credit from this packet */ |
| 1276 | fifo = brcmf_skb_htod_tag_get_field(skb, FIFO); |
| 1277 | brcmf_skb_pick_up_credit(fws, fifo, skb); |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1278 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1279 | if (!remove_from_hanger) |
| 1280 | ret = brcmf_fws_txstatus_suppressed(fws, fifo, skb, genbit); |
| 1281 | |
| 1282 | if (remove_from_hanger || ret) { |
| 1283 | entry->transit_count--; |
| 1284 | if (entry->suppressed) |
| 1285 | entry->suppr_transit_count--; |
| 1286 | |
| 1287 | brcmf_txfinalize(fws->drvr, skb, true); |
| 1288 | } |
| 1289 | return 0; |
| 1290 | } |
| 1291 | |
| 1292 | static int brcmf_fws_fifocreditback_indicate(struct brcmf_fws_info *fws, |
| 1293 | u8 *data) |
| 1294 | { |
| 1295 | int i; |
| 1296 | |
| 1297 | if (fws->fcmode != BRCMF_FWS_FCMODE_EXPLICIT_CREDIT) { |
| 1298 | brcmf_dbg(INFO, "ignored\n"); |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 1299 | return BRCMF_FWS_RET_OK_NOSCHEDULE; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | brcmf_dbg(TRACE, "enter: data %pM\n", data); |
| 1303 | for (i = 0; i < BRCMF_FWS_FIFO_COUNT; i++) |
| 1304 | brcmf_fws_return_credits(fws, i, data[i]); |
| 1305 | |
| 1306 | brcmf_dbg(INFO, "map: credit %x delay %x\n", fws->fifo_credit_map, |
| 1307 | fws->fifo_delay_map); |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 1308 | return BRCMF_FWS_RET_OK_SCHEDULE; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1309 | } |
| 1310 | |
Arend van Spriel | 0f8b5cc | 2013-04-03 12:40:41 +0200 | [diff] [blame] | 1311 | static int brcmf_fws_txstatus_indicate(struct brcmf_fws_info *fws, u8 *data) |
| 1312 | { |
Arend van Spriel | a2ffc56 | 2013-04-05 10:57:39 +0200 | [diff] [blame] | 1313 | __le32 status_le; |
Arend van Spriel | 0f8b5cc | 2013-04-03 12:40:41 +0200 | [diff] [blame] | 1314 | u32 status; |
| 1315 | u32 hslot; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1316 | u32 genbit; |
Arend van Spriel | 0f8b5cc | 2013-04-03 12:40:41 +0200 | [diff] [blame] | 1317 | u8 flags; |
| 1318 | |
| 1319 | fws->stats.txs_indicate++; |
Arend van Spriel | a2ffc56 | 2013-04-05 10:57:39 +0200 | [diff] [blame] | 1320 | memcpy(&status_le, data, sizeof(status_le)); |
| 1321 | status = le32_to_cpu(status_le); |
Arend van Spriel | 0f8b5cc | 2013-04-03 12:40:41 +0200 | [diff] [blame] | 1322 | flags = brcmf_txstatus_get_field(status, FLAGS); |
| 1323 | hslot = brcmf_txstatus_get_field(status, HSLOT); |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1324 | genbit = brcmf_txstatus_get_field(status, GENERATION); |
Arend van Spriel | 0f8b5cc | 2013-04-03 12:40:41 +0200 | [diff] [blame] | 1325 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1326 | return brcmf_fws_txstatus_process(fws, flags, hslot, genbit); |
Arend van Spriel | 0f8b5cc | 2013-04-03 12:40:41 +0200 | [diff] [blame] | 1327 | } |
| 1328 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1329 | static int brcmf_fws_dbg_seqnum_check(struct brcmf_fws_info *fws, u8 *data) |
| 1330 | { |
| 1331 | __le32 timestamp; |
| 1332 | |
| 1333 | memcpy(×tamp, &data[2], sizeof(timestamp)); |
| 1334 | brcmf_dbg(INFO, "received: seq %d, timestamp %d\n", data[1], |
| 1335 | le32_to_cpu(timestamp)); |
| 1336 | return 0; |
| 1337 | } |
| 1338 | |
| 1339 | /* using macro so sparse checking does not complain |
| 1340 | * about locking imbalance. |
| 1341 | */ |
| 1342 | #define brcmf_fws_lock(drvr, flags) \ |
| 1343 | do { \ |
| 1344 | flags = 0; \ |
| 1345 | spin_lock_irqsave(&((drvr)->fws_spinlock), (flags)); \ |
| 1346 | } while (0) |
| 1347 | |
| 1348 | /* using macro so sparse checking does not complain |
| 1349 | * about locking imbalance. |
| 1350 | */ |
| 1351 | #define brcmf_fws_unlock(drvr, flags) \ |
| 1352 | spin_unlock_irqrestore(&((drvr)->fws_spinlock), (flags)) |
| 1353 | |
Arend van Spriel | 43fa635 | 2013-04-03 12:40:32 +0200 | [diff] [blame] | 1354 | static int brcmf_fws_notify_credit_map(struct brcmf_if *ifp, |
| 1355 | const struct brcmf_event_msg *e, |
| 1356 | void *data) |
| 1357 | { |
| 1358 | struct brcmf_fws_info *fws = ifp->drvr->fws; |
| 1359 | int i; |
| 1360 | ulong flags; |
| 1361 | u8 *credits = data; |
| 1362 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1363 | if (e->datalen < BRCMF_FWS_FIFO_COUNT) { |
| 1364 | brcmf_err("event payload too small (%d)\n", e->datalen); |
| 1365 | return -EINVAL; |
| 1366 | } |
| 1367 | |
| 1368 | brcmf_dbg(TRACE, "enter: credits %pM\n", credits); |
Arend van Spriel | 43fa635 | 2013-04-03 12:40:32 +0200 | [diff] [blame] | 1369 | brcmf_fws_lock(ifp->drvr, flags); |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1370 | for (i = 0; i < ARRAY_SIZE(fws->fifo_credit); i++) { |
| 1371 | if (*credits) |
| 1372 | fws->fifo_credit_map |= 1 << i; |
| 1373 | else |
| 1374 | fws->fifo_credit_map &= ~(1 << i); |
Arend van Spriel | 43fa635 | 2013-04-03 12:40:32 +0200 | [diff] [blame] | 1375 | fws->fifo_credit[i] = *credits++; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1376 | } |
| 1377 | brcmf_fws_schedule_deq(fws); |
Arend van Spriel | 43fa635 | 2013-04-03 12:40:32 +0200 | [diff] [blame] | 1378 | brcmf_fws_unlock(ifp->drvr, flags); |
| 1379 | return 0; |
| 1380 | } |
| 1381 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1382 | int brcmf_fws_hdrpull(struct brcmf_pub *drvr, int ifidx, s16 signal_len, |
| 1383 | struct sk_buff *skb) |
| 1384 | { |
| 1385 | struct brcmf_fws_info *fws = drvr->fws; |
| 1386 | ulong flags; |
| 1387 | u8 *signal_data; |
| 1388 | s16 data_len; |
| 1389 | u8 type; |
| 1390 | u8 len; |
| 1391 | u8 *data; |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 1392 | s32 status; |
| 1393 | s32 err; |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1394 | |
| 1395 | brcmf_dbg(TRACE, "enter: ifidx %d, skblen %u, sig %d\n", |
| 1396 | ifidx, skb->len, signal_len); |
| 1397 | |
| 1398 | WARN_ON(signal_len > skb->len); |
| 1399 | |
| 1400 | /* if flow control disabled, skip to packet data and leave */ |
| 1401 | if (!signal_len || !drvr->fw_signals) { |
| 1402 | skb_pull(skb, signal_len); |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
| 1406 | /* lock during tlv parsing */ |
| 1407 | brcmf_fws_lock(drvr, flags); |
| 1408 | |
| 1409 | fws->stats.header_pulls++; |
| 1410 | data_len = signal_len; |
| 1411 | signal_data = skb->data; |
| 1412 | |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 1413 | status = BRCMF_FWS_RET_OK_NOSCHEDULE; |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1414 | while (data_len > 0) { |
| 1415 | /* extract tlv info */ |
| 1416 | type = signal_data[0]; |
| 1417 | |
| 1418 | /* FILLER type is actually not a TLV, but |
| 1419 | * a single byte that can be skipped. |
| 1420 | */ |
| 1421 | if (type == BRCMF_FWS_TYPE_FILLER) { |
| 1422 | signal_data += 1; |
| 1423 | data_len -= 1; |
| 1424 | continue; |
| 1425 | } |
| 1426 | len = signal_data[1]; |
| 1427 | data = signal_data + 2; |
| 1428 | |
Arend van Spriel | 2af1558 | 2013-04-03 12:40:42 +0200 | [diff] [blame] | 1429 | brcmf_dbg(INFO, "tlv type=%d (%s), len=%d, data[0]=%d\n", type, |
| 1430 | brcmf_fws_get_tlv_name(type), len, *data); |
| 1431 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1432 | /* abort parsing when length invalid */ |
| 1433 | if (data_len < len + 2) |
| 1434 | break; |
| 1435 | |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 1436 | if (len != brcmf_fws_get_tlv_len(fws, type)) |
| 1437 | break; |
| 1438 | |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 1439 | err = BRCMF_FWS_RET_OK_NOSCHEDULE; |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1440 | switch (type) { |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1441 | case BRCMF_FWS_TYPE_HOST_REORDER_RXPKTS: |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 1442 | case BRCMF_FWS_TYPE_COMP_TXSTATUS: |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 1443 | break; |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 1444 | case BRCMF_FWS_TYPE_MACDESC_ADD: |
| 1445 | case BRCMF_FWS_TYPE_MACDESC_DEL: |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 1446 | brcmf_fws_macdesc_indicate(fws, type, data); |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 1447 | break; |
Arend van Spriel | 33753d4 | 2013-04-05 10:57:40 +0200 | [diff] [blame] | 1448 | case BRCMF_FWS_TYPE_MAC_OPEN: |
| 1449 | case BRCMF_FWS_TYPE_MAC_CLOSE: |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 1450 | err = brcmf_fws_macdesc_state_indicate(fws, type, data); |
Arend van Spriel | 33753d4 | 2013-04-05 10:57:40 +0200 | [diff] [blame] | 1451 | break; |
| 1452 | case BRCMF_FWS_TYPE_INTERFACE_OPEN: |
| 1453 | case BRCMF_FWS_TYPE_INTERFACE_CLOSE: |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 1454 | err = brcmf_fws_interface_state_indicate(fws, type, |
| 1455 | data); |
Arend van Spriel | 33753d4 | 2013-04-05 10:57:40 +0200 | [diff] [blame] | 1456 | break; |
Arend van Spriel | 5f38b68 | 2013-04-05 10:57:41 +0200 | [diff] [blame] | 1457 | case BRCMF_FWS_TYPE_MAC_REQUEST_CREDIT: |
| 1458 | case BRCMF_FWS_TYPE_MAC_REQUEST_PACKET: |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 1459 | err = brcmf_fws_request_indicate(fws, type, data); |
Arend van Spriel | 5f38b68 | 2013-04-05 10:57:41 +0200 | [diff] [blame] | 1460 | break; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1461 | case BRCMF_FWS_TYPE_TXSTATUS: |
| 1462 | brcmf_fws_txstatus_indicate(fws, data); |
| 1463 | break; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1464 | case BRCMF_FWS_TYPE_FIFO_CREDITBACK: |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 1465 | err = brcmf_fws_fifocreditback_indicate(fws, data); |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1466 | break; |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 1467 | case BRCMF_FWS_TYPE_RSSI: |
| 1468 | brcmf_fws_rssi_indicate(fws, *data); |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1469 | break; |
| 1470 | case BRCMF_FWS_TYPE_TRANS_ID: |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1471 | brcmf_fws_dbg_seqnum_check(fws, data); |
| 1472 | break; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1473 | case BRCMF_FWS_TYPE_PKTTAG: |
| 1474 | case BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP: |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1475 | default: |
| 1476 | fws->stats.tlv_invalid_type++; |
| 1477 | break; |
| 1478 | } |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 1479 | if (err == BRCMF_FWS_RET_OK_SCHEDULE) |
| 1480 | status = BRCMF_FWS_RET_OK_SCHEDULE; |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1481 | signal_data += len + 2; |
| 1482 | data_len -= len + 2; |
| 1483 | } |
| 1484 | |
| 1485 | if (data_len != 0) |
| 1486 | fws->stats.tlv_parse_failed++; |
| 1487 | |
Arend van Spriel | a5e9d80 | 2013-04-17 21:25:54 +0200 | [diff] [blame] | 1488 | if (status == BRCMF_FWS_RET_OK_SCHEDULE) |
| 1489 | brcmf_fws_schedule_deq(fws); |
| 1490 | |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 1491 | /* signalling processing result does |
| 1492 | * not affect the actual ethernet packet. |
| 1493 | */ |
| 1494 | skb_pull(skb, signal_len); |
| 1495 | |
| 1496 | /* this may be a signal-only packet |
| 1497 | */ |
| 1498 | if (skb->len == 0) |
| 1499 | fws->stats.header_only_pkt++; |
| 1500 | |
| 1501 | brcmf_fws_unlock(drvr, flags); |
| 1502 | return 0; |
| 1503 | } |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 1504 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1505 | static int brcmf_fws_hdrpush(struct brcmf_fws_info *fws, struct sk_buff *skb) |
| 1506 | { |
| 1507 | struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(skb)->mac; |
| 1508 | u8 *wlh; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1509 | u16 data_offset = 0; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1510 | u8 fillers; |
| 1511 | __le32 pkttag = cpu_to_le32(brcmf_skbcb(skb)->htod); |
| 1512 | |
| 1513 | brcmf_dbg(TRACE, "enter: ea=%pM, ifidx=%u, pkttag=0x%08X\n", |
| 1514 | entry->ea, entry->interface_id, le32_to_cpu(pkttag)); |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1515 | if (entry->send_tim_signal) |
| 1516 | data_offset += 2 + BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN; |
| 1517 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1518 | /* +2 is for Type[1] and Len[1] in TLV, plus TIM signal */ |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1519 | data_offset += 2 + BRCMF_FWS_TYPE_PKTTAG_LEN; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1520 | fillers = round_up(data_offset, 4) - data_offset; |
| 1521 | data_offset += fillers; |
| 1522 | |
| 1523 | skb_push(skb, data_offset); |
| 1524 | wlh = skb->data; |
| 1525 | |
| 1526 | wlh[0] = BRCMF_FWS_TYPE_PKTTAG; |
| 1527 | wlh[1] = BRCMF_FWS_TYPE_PKTTAG_LEN; |
| 1528 | memcpy(&wlh[2], &pkttag, sizeof(pkttag)); |
| 1529 | wlh += BRCMF_FWS_TYPE_PKTTAG_LEN + 2; |
| 1530 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1531 | if (entry->send_tim_signal) { |
| 1532 | entry->send_tim_signal = 0; |
| 1533 | wlh[0] = BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP; |
| 1534 | wlh[1] = BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN; |
| 1535 | wlh[2] = entry->mac_handle; |
| 1536 | wlh[3] = entry->traffic_pending_bmp; |
| 1537 | wlh += BRCMF_FWS_TYPE_PENDING_TRAFFIC_BMP_LEN + 2; |
| 1538 | entry->traffic_lastreported_bmp = entry->traffic_pending_bmp; |
| 1539 | } |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1540 | if (fillers) |
| 1541 | memset(wlh, BRCMF_FWS_TYPE_FILLER, fillers); |
| 1542 | |
| 1543 | brcmf_proto_hdrpush(fws->drvr, brcmf_skb_if_flags_get_field(skb, INDEX), |
| 1544 | data_offset >> 2, skb); |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | static int brcmf_fws_precommit_skb(struct brcmf_fws_info *fws, int fifo, |
| 1549 | struct sk_buff *p) |
| 1550 | { |
| 1551 | struct brcmf_skbuff_cb *skcb = brcmf_skbcb(p); |
| 1552 | struct brcmf_fws_mac_descriptor *entry = skcb->mac; |
| 1553 | int rc = 0; |
| 1554 | bool header_needed; |
| 1555 | int hslot = BRCMF_FWS_HANGER_MAXITEMS; |
| 1556 | u8 free_ctr; |
| 1557 | u8 ifidx; |
| 1558 | u8 flags; |
| 1559 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1560 | header_needed = skcb->state != BRCMF_FWS_SKBSTATE_SUPPRESSED; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1561 | |
| 1562 | if (header_needed) { |
| 1563 | /* obtaining free slot may fail, but that will be caught |
| 1564 | * by the hanger push. This assures the packet has a BDC |
| 1565 | * header upon return. |
| 1566 | */ |
| 1567 | hslot = brcmf_fws_hanger_get_free_slot(&fws->hanger); |
| 1568 | free_ctr = entry->seq[fifo]; |
| 1569 | brcmf_skb_htod_tag_set_field(p, HSLOT, hslot); |
| 1570 | brcmf_skb_htod_tag_set_field(p, FREERUN, free_ctr); |
| 1571 | brcmf_skb_htod_tag_set_field(p, GENERATION, 1); |
| 1572 | entry->transit_count++; |
| 1573 | } |
| 1574 | brcmf_skb_if_flags_set_field(p, TRANSMIT, 1); |
| 1575 | brcmf_skb_htod_tag_set_field(p, FIFO, fifo); |
| 1576 | |
| 1577 | flags = BRCMF_FWS_HTOD_FLAG_PKTFROMHOST; |
| 1578 | if (!(skcb->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK)) { |
| 1579 | /* |
| 1580 | Indicate that this packet is being sent in response to an |
| 1581 | explicit request from the firmware side. |
| 1582 | */ |
| 1583 | flags |= BRCMF_FWS_HTOD_FLAG_PKT_REQUESTED; |
| 1584 | } |
| 1585 | brcmf_skb_htod_tag_set_field(p, FLAGS, flags); |
| 1586 | if (header_needed) { |
| 1587 | brcmf_fws_hdrpush(fws, p); |
| 1588 | rc = brcmf_fws_hanger_pushpkt(&fws->hanger, p, hslot); |
| 1589 | if (rc) |
| 1590 | brcmf_err("hanger push failed: rc=%d\n", rc); |
| 1591 | } else { |
| 1592 | int gen; |
| 1593 | |
| 1594 | /* remove old header */ |
| 1595 | rc = brcmf_proto_hdrpull(fws->drvr, false, &ifidx, p); |
| 1596 | if (rc == 0) { |
| 1597 | hslot = brcmf_skb_htod_tag_get_field(p, HSLOT); |
| 1598 | brcmf_fws_hanger_get_genbit(&fws->hanger, p, |
| 1599 | hslot, &gen); |
| 1600 | brcmf_skb_htod_tag_set_field(p, GENERATION, gen); |
| 1601 | |
| 1602 | /* push new header */ |
| 1603 | brcmf_fws_hdrpush(fws, p); |
| 1604 | } |
| 1605 | } |
| 1606 | |
| 1607 | return rc; |
| 1608 | } |
| 1609 | |
Arend van Spriel | 88f656f | 2013-04-17 21:25:57 +0200 | [diff] [blame] | 1610 | static void |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1611 | brcmf_fws_rollback_toq(struct brcmf_fws_info *fws, struct sk_buff *skb) |
| 1612 | { |
| 1613 | /* |
| 1614 | put the packet back to the head of queue |
| 1615 | |
| 1616 | - suppressed packet goes back to suppress sub-queue |
| 1617 | - pull out the header, if new or delayed packet |
| 1618 | |
| 1619 | Note: hslot is used only when header removal is done. |
| 1620 | */ |
| 1621 | struct brcmf_fws_mac_descriptor *entry; |
| 1622 | enum brcmf_fws_skb_state state; |
| 1623 | struct sk_buff *pktout; |
| 1624 | int rc = 0; |
| 1625 | int fifo; |
| 1626 | int hslot; |
| 1627 | u8 ifidx; |
| 1628 | |
| 1629 | fifo = brcmf_skb_if_flags_get_field(skb, FIFO); |
| 1630 | state = brcmf_skbcb(skb)->state; |
| 1631 | entry = brcmf_skbcb(skb)->mac; |
| 1632 | |
| 1633 | if (entry != NULL) { |
| 1634 | if (state == BRCMF_FWS_SKBSTATE_SUPPRESSED) { |
| 1635 | /* wl-header is saved for suppressed packets */ |
| 1636 | pktout = brcmu_pktq_penq_head(&entry->psq, 2 * fifo + 1, |
| 1637 | skb); |
| 1638 | if (pktout == NULL) { |
| 1639 | brcmf_err("suppress queue full\n"); |
| 1640 | rc = -ENOSPC; |
| 1641 | } |
| 1642 | } else { |
| 1643 | hslot = brcmf_skb_htod_tag_get_field(skb, HSLOT); |
| 1644 | |
| 1645 | /* remove header first */ |
| 1646 | rc = brcmf_proto_hdrpull(fws->drvr, false, &ifidx, skb); |
| 1647 | if (rc) { |
| 1648 | brcmf_err("header removal failed\n"); |
| 1649 | /* free the hanger slot */ |
| 1650 | brcmf_fws_hanger_poppkt(&fws->hanger, hslot, |
| 1651 | &pktout, true); |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1652 | rc = -EINVAL; |
| 1653 | goto fail; |
| 1654 | } |
| 1655 | |
| 1656 | /* delay-q packets are going to delay-q */ |
| 1657 | pktout = brcmu_pktq_penq_head(&entry->psq, |
| 1658 | 2 * fifo, skb); |
| 1659 | if (pktout == NULL) { |
| 1660 | brcmf_err("delay queue full\n"); |
| 1661 | rc = -ENOSPC; |
| 1662 | } |
| 1663 | |
| 1664 | /* free the hanger slot */ |
| 1665 | brcmf_fws_hanger_poppkt(&fws->hanger, hslot, &pktout, |
| 1666 | true); |
| 1667 | |
| 1668 | /* decrement sequence count */ |
| 1669 | entry->seq[fifo]--; |
| 1670 | } |
| 1671 | /* |
| 1672 | if this packet did not count against FIFO credit, it must have |
| 1673 | taken a requested_credit from the firmware (for pspoll etc.) |
| 1674 | */ |
| 1675 | if (!(brcmf_skbcb(skb)->if_flags & |
| 1676 | BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK)) |
| 1677 | entry->requested_credit++; |
| 1678 | } else { |
| 1679 | brcmf_err("no mac entry linked\n"); |
| 1680 | rc = -ENOENT; |
| 1681 | } |
| 1682 | |
| 1683 | |
| 1684 | fail: |
Arend van Spriel | 67994fa | 2013-04-17 21:25:56 +0200 | [diff] [blame] | 1685 | if (rc) { |
| 1686 | brcmf_txfinalize(fws->drvr, skb, false); |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1687 | fws->stats.rollback_failed++; |
Arend van Spriel | 67994fa | 2013-04-17 21:25:56 +0200 | [diff] [blame] | 1688 | } else |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1689 | fws->stats.rollback_success++; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1690 | } |
| 1691 | |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 1692 | static int brcmf_fws_borrow_credit(struct brcmf_fws_info *fws) |
| 1693 | { |
| 1694 | int lender_ac; |
| 1695 | |
| 1696 | if (time_after(fws->borrow_defer_timestamp, jiffies)) |
| 1697 | return -ENAVAIL; |
| 1698 | |
| 1699 | for (lender_ac = 0; lender_ac <= BRCMF_FWS_FIFO_AC_VO; lender_ac++) { |
| 1700 | if (fws->fifo_credit[lender_ac]) { |
| 1701 | fws->credits_borrowed[lender_ac]++; |
| 1702 | fws->fifo_credit[lender_ac]--; |
| 1703 | if (fws->fifo_credit[lender_ac] == 0) |
| 1704 | fws->fifo_credit_map &= ~(1 << lender_ac); |
| 1705 | brcmf_dbg(TRACE, "borrow credit from: %d\n", lender_ac); |
| 1706 | return 0; |
| 1707 | } |
| 1708 | } |
| 1709 | return -ENAVAIL; |
| 1710 | } |
| 1711 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1712 | static int brcmf_fws_consume_credit(struct brcmf_fws_info *fws, int fifo, |
| 1713 | struct sk_buff *skb) |
| 1714 | { |
| 1715 | struct brcmf_fws_mac_descriptor *entry = brcmf_skbcb(skb)->mac; |
| 1716 | int *credit = &fws->fifo_credit[fifo]; |
| 1717 | int use_credit = 1; |
| 1718 | |
| 1719 | brcmf_dbg(TRACE, "enter: ac=%d, credits=%d\n", fifo, *credit); |
| 1720 | |
| 1721 | if (entry->requested_credit > 0) { |
| 1722 | /* |
| 1723 | * if the packet was pulled out while destination is in |
| 1724 | * closed state but had a non-zero packets requested, |
| 1725 | * then this should not count against the FIFO credit. |
| 1726 | * That is due to the fact that the firmware will |
| 1727 | * most likely hold onto this packet until a suitable |
| 1728 | * time later to push it to the appropriate AC FIFO. |
| 1729 | */ |
| 1730 | entry->requested_credit--; |
| 1731 | if (entry->state == BRCMF_FWS_STATE_CLOSE) |
| 1732 | use_credit = 0; |
| 1733 | } else if (entry->requested_packet > 0) { |
| 1734 | entry->requested_packet--; |
| 1735 | brcmf_skb_if_flags_set_field(skb, REQUESTED, 1); |
| 1736 | if (entry->state == BRCMF_FWS_STATE_CLOSE) |
| 1737 | use_credit = 0; |
| 1738 | } |
| 1739 | brcmf_skb_if_flags_set_field(skb, CREDITCHECK, use_credit); |
| 1740 | if (!use_credit) { |
| 1741 | brcmf_dbg(TRACE, "exit: no creditcheck set\n"); |
| 1742 | return 0; |
| 1743 | } |
| 1744 | |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 1745 | if (fifo != BRCMF_FWS_FIFO_AC_BE) |
| 1746 | fws->borrow_defer_timestamp = jiffies + |
| 1747 | BRCMF_FWS_BORROW_DEFER_PERIOD; |
| 1748 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1749 | if (!(*credit)) { |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 1750 | /* Try to borrow a credit from other queue */ |
| 1751 | if (fifo == BRCMF_FWS_FIFO_AC_BE && |
| 1752 | brcmf_fws_borrow_credit(fws) == 0) |
| 1753 | return 0; |
| 1754 | |
| 1755 | brcmf_dbg(TRACE, "exit: ac=%d, credits depleted\n", fifo); |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1756 | return -ENAVAIL; |
| 1757 | } |
| 1758 | (*credit)--; |
| 1759 | if (!(*credit)) |
| 1760 | fws->fifo_credit_map &= ~(1 << fifo); |
| 1761 | brcmf_dbg(TRACE, "exit: ac=%d, credits=%d\n", fifo, *credit); |
| 1762 | return 0; |
| 1763 | } |
| 1764 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1765 | static int brcmf_fws_commit_skb(struct brcmf_fws_info *fws, int fifo, |
| 1766 | struct sk_buff *skb) |
| 1767 | { |
| 1768 | struct brcmf_skbuff_cb *skcb = brcmf_skbcb(skb); |
| 1769 | struct brcmf_fws_mac_descriptor *entry; |
| 1770 | struct brcmf_bus *bus = fws->drvr->bus_if; |
| 1771 | int rc; |
| 1772 | |
| 1773 | entry = skcb->mac; |
| 1774 | if (IS_ERR(entry)) |
| 1775 | return PTR_ERR(entry); |
| 1776 | |
| 1777 | rc = brcmf_fws_precommit_skb(fws, fifo, skb); |
| 1778 | if (rc < 0) { |
| 1779 | fws->stats.generic_error++; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1780 | goto rollback; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | rc = brcmf_bus_txdata(bus, skb); |
| 1784 | if (rc < 0) |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1785 | goto rollback; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1786 | |
| 1787 | entry->seq[fifo]++; |
| 1788 | fws->stats.pkt2bus++; |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1789 | if (brcmf_skbcb(skb)->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK) { |
| 1790 | fws->stats.send_pkts[fifo]++; |
| 1791 | fws->stats.fifo_credits_sent[fifo]++; |
| 1792 | } |
| 1793 | |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1794 | return rc; |
| 1795 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1796 | rollback: |
Arend van Spriel | 88f656f | 2013-04-17 21:25:57 +0200 | [diff] [blame] | 1797 | brcmf_fws_rollback_toq(fws, skb); |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1798 | return rc; |
| 1799 | } |
| 1800 | |
| 1801 | int brcmf_fws_process_skb(struct brcmf_if *ifp, struct sk_buff *skb) |
| 1802 | { |
| 1803 | struct brcmf_pub *drvr = ifp->drvr; |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 1804 | struct brcmf_fws_info *fws = drvr->fws; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1805 | struct brcmf_skbuff_cb *skcb = brcmf_skbcb(skb); |
| 1806 | struct ethhdr *eh = (struct ethhdr *)(skb->data); |
| 1807 | ulong flags; |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1808 | int fifo = BRCMF_FWS_FIFO_BCMC; |
| 1809 | bool multicast = is_multicast_ether_addr(eh->h_dest); |
| 1810 | |
| 1811 | /* determine the priority */ |
| 1812 | if (!skb->priority) |
| 1813 | skb->priority = cfg80211_classify8021d(skb); |
| 1814 | |
| 1815 | drvr->tx_multicast += !!multicast; |
| 1816 | if (ntohs(eh->h_proto) == ETH_P_PAE) |
| 1817 | atomic_inc(&ifp->pend_8021x_cnt); |
| 1818 | |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 1819 | if (!brcmf_fws_fc_active(fws)) { |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1820 | /* If the protocol uses a data header, apply it */ |
Arend van Spriel | 31ed07d | 2013-04-11 13:29:00 +0200 | [diff] [blame] | 1821 | brcmf_proto_hdrpush(drvr, ifp->ifidx, 0, skb); |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1822 | |
| 1823 | /* Use bus module to send data frame */ |
| 1824 | return brcmf_bus_txdata(drvr->bus_if, skb); |
| 1825 | } |
| 1826 | |
| 1827 | /* set control buffer information */ |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1828 | skcb->if_flags = 0; |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 1829 | skcb->mac = brcmf_fws_find_mac_desc(fws, ifp, eh->h_dest); |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1830 | skcb->state = BRCMF_FWS_SKBSTATE_NEW; |
Arend van Spriel | 31ed07d | 2013-04-11 13:29:00 +0200 | [diff] [blame] | 1831 | brcmf_skb_if_flags_set_field(skb, INDEX, ifp->ifidx); |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1832 | if (!multicast) |
| 1833 | fifo = brcmf_fws_prio2fifo[skb->priority]; |
| 1834 | brcmf_skb_if_flags_set_field(skb, FIFO, fifo); |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1835 | |
| 1836 | brcmf_dbg(TRACE, "ea=%pM, multi=%d, fifo=%d\n", eh->h_dest, |
| 1837 | multicast, fifo); |
| 1838 | |
| 1839 | brcmf_fws_lock(drvr, flags); |
Arend van Spriel | 9fc6022 | 2013-04-11 17:12:04 +0200 | [diff] [blame] | 1840 | if (skcb->mac->suppressed || |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 1841 | brcmf_fws_mac_desc_closed(fws, skcb->mac, fifo) || |
Arend van Spriel | 9fc6022 | 2013-04-11 17:12:04 +0200 | [diff] [blame] | 1842 | brcmu_pktq_mlen(&skcb->mac->psq, 3 << (fifo * 2)) || |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1843 | (!multicast && |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 1844 | brcmf_fws_consume_credit(fws, fifo, skb) < 0)) { |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1845 | /* enqueue the packet in delayQ */ |
| 1846 | drvr->fws->fifo_delay_map |= 1 << fifo; |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 1847 | brcmf_fws_enq(fws, BRCMF_FWS_SKBSTATE_DELAYED, fifo, skb); |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1848 | } else { |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 1849 | if (brcmf_fws_commit_skb(fws, fifo, skb)) |
| 1850 | if (!multicast) |
| 1851 | brcmf_skb_pick_up_credit(fws, fifo, skb); |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1852 | } |
Arend van Spriel | 3edc1cf | 2013-04-03 12:40:40 +0200 | [diff] [blame] | 1853 | brcmf_fws_unlock(drvr, flags); |
| 1854 | return 0; |
| 1855 | } |
| 1856 | |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 1857 | void brcmf_fws_reset_interface(struct brcmf_if *ifp) |
| 1858 | { |
| 1859 | struct brcmf_fws_mac_descriptor *entry = ifp->fws_desc; |
| 1860 | |
| 1861 | brcmf_dbg(TRACE, "enter: idx=%d\n", ifp->bssidx); |
| 1862 | if (!entry) |
| 1863 | return; |
| 1864 | |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 1865 | brcmf_fws_init_mac_descriptor(entry, ifp->mac_addr, ifp->ifidx); |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | void brcmf_fws_add_interface(struct brcmf_if *ifp) |
| 1869 | { |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1870 | struct brcmf_fws_info *fws = ifp->drvr->fws; |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 1871 | struct brcmf_fws_mac_descriptor *entry; |
| 1872 | |
| 1873 | brcmf_dbg(TRACE, "enter: idx=%d, mac=%pM\n", |
| 1874 | ifp->bssidx, ifp->mac_addr); |
Arend van Spriel | 01b8e7d | 2013-04-05 10:57:51 +0200 | [diff] [blame] | 1875 | if (!ifp->ndev || !ifp->drvr->fw_signals) |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 1876 | return; |
| 1877 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1878 | entry = &fws->desc.iface[ifp->ifidx]; |
| 1879 | ifp->fws_desc = entry; |
| 1880 | brcmf_fws_init_mac_descriptor(entry, ifp->mac_addr, ifp->ifidx); |
| 1881 | brcmu_pktq_init(&entry->psq, BRCMF_FWS_PSQ_PREC_COUNT, |
| 1882 | BRCMF_FWS_PSQ_LEN); |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | void brcmf_fws_del_interface(struct brcmf_if *ifp) |
| 1886 | { |
| 1887 | struct brcmf_fws_mac_descriptor *entry = ifp->fws_desc; |
Arend van Spriel | 6d421e5 | 2013-04-17 21:25:55 +0200 | [diff] [blame] | 1888 | ulong flags; |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 1889 | |
| 1890 | brcmf_dbg(TRACE, "enter: idx=%d\n", ifp->bssidx); |
| 1891 | if (!entry) |
| 1892 | return; |
| 1893 | |
Arend van Spriel | 6d421e5 | 2013-04-17 21:25:55 +0200 | [diff] [blame] | 1894 | brcmf_fws_lock(ifp->drvr, flags); |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 1895 | ifp->fws_desc = NULL; |
Arend van Spriel | ce814c1 | 2013-04-03 12:40:31 +0200 | [diff] [blame] | 1896 | brcmf_fws_clear_mac_descriptor(entry); |
Arend van Spriel | a3e993c | 2013-04-03 12:40:36 +0200 | [diff] [blame] | 1897 | brcmf_fws_cleanup(ifp->drvr->fws, ifp->ifidx); |
Arend van Spriel | 6d421e5 | 2013-04-17 21:25:55 +0200 | [diff] [blame] | 1898 | brcmf_fws_unlock(ifp->drvr, flags); |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | static void brcmf_fws_dequeue_worker(struct work_struct *worker) |
| 1902 | { |
| 1903 | struct brcmf_fws_info *fws; |
| 1904 | struct sk_buff *skb; |
| 1905 | ulong flags; |
| 1906 | int fifo; |
| 1907 | int credit; |
| 1908 | |
| 1909 | fws = container_of(worker, struct brcmf_fws_info, fws_dequeue_work); |
| 1910 | |
| 1911 | brcmf_dbg(TRACE, "enter: fws=%p\n", fws); |
| 1912 | brcmf_fws_lock(fws->drvr, flags); |
| 1913 | for (fifo = NL80211_NUM_ACS; fifo >= 0; fifo--) { |
| 1914 | brcmf_dbg(TRACE, "fifo %d credit %d\n", fifo, |
| 1915 | fws->fifo_credit[fifo]); |
| 1916 | for (credit = 0; credit < fws->fifo_credit[fifo]; /* nop */) { |
| 1917 | skb = brcmf_fws_deq(fws, fifo); |
Arend van Spriel | 047445c | 2013-04-17 21:25:58 +0200 | [diff] [blame] | 1918 | if (!skb || brcmf_fws_commit_skb(fws, fifo, skb)) |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1919 | break; |
Arend van Spriel | 047445c | 2013-04-17 21:25:58 +0200 | [diff] [blame] | 1920 | if (brcmf_skbcb(skb)->if_flags & |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1921 | BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK) |
| 1922 | credit++; |
| 1923 | } |
Arend van Spriel | 1aac1e9 | 2013-04-23 12:53:15 +0200 | [diff] [blame^] | 1924 | if ((fifo == BRCMF_FWS_FIFO_AC_BE) && |
| 1925 | (credit == fws->fifo_credit[fifo])) { |
| 1926 | fws->fifo_credit[fifo] -= credit; |
| 1927 | while (brcmf_fws_borrow_credit(fws) == 0) { |
| 1928 | skb = brcmf_fws_deq(fws, fifo); |
| 1929 | if (!skb) { |
| 1930 | brcmf_fws_return_credits(fws, fifo, 1); |
| 1931 | break; |
| 1932 | } |
| 1933 | if (brcmf_fws_commit_skb(fws, fifo, skb)) { |
| 1934 | brcmf_fws_return_credits(fws, fifo, 1); |
| 1935 | break; |
| 1936 | } |
| 1937 | } |
| 1938 | } else { |
| 1939 | fws->fifo_credit[fifo] -= credit; |
| 1940 | } |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1941 | } |
| 1942 | brcmf_fws_unlock(fws->drvr, flags); |
Arend van Spriel | bb8c806 | 2013-04-03 12:40:30 +0200 | [diff] [blame] | 1943 | } |
Arend van Spriel | c7f34a6 | 2013-04-03 12:40:39 +0200 | [diff] [blame] | 1944 | |
Arend van Spriel | d933741 | 2013-04-03 12:40:47 +0200 | [diff] [blame] | 1945 | int brcmf_fws_init(struct brcmf_pub *drvr) |
| 1946 | { |
Arend van Spriel | 290fb76 | 2013-04-03 12:40:49 +0200 | [diff] [blame] | 1947 | u32 tlv = BRCMF_FWS_FLAGS_RSSI_SIGNALS; |
Arend van Spriel | d933741 | 2013-04-03 12:40:47 +0200 | [diff] [blame] | 1948 | int rc; |
| 1949 | |
Arend van Spriel | 47829f4 | 2013-04-03 12:40:48 +0200 | [diff] [blame] | 1950 | if (!drvr->fw_signals) |
| 1951 | return 0; |
| 1952 | |
Arend van Spriel | d933741 | 2013-04-03 12:40:47 +0200 | [diff] [blame] | 1953 | spin_lock_init(&drvr->fws_spinlock); |
| 1954 | |
| 1955 | drvr->fws = kzalloc(sizeof(*(drvr->fws)), GFP_KERNEL); |
| 1956 | if (!drvr->fws) { |
| 1957 | rc = -ENOMEM; |
| 1958 | goto fail; |
| 1959 | } |
| 1960 | |
| 1961 | /* set linkage back */ |
| 1962 | drvr->fws->drvr = drvr; |
| 1963 | drvr->fws->fcmode = fcmode; |
| 1964 | |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1965 | drvr->fws->fws_wq = create_singlethread_workqueue("brcmf_fws_wq"); |
| 1966 | if (drvr->fws->fws_wq == NULL) { |
| 1967 | brcmf_err("workqueue creation failed\n"); |
| 1968 | rc = -EBADF; |
| 1969 | goto fail; |
| 1970 | } |
| 1971 | INIT_WORK(&drvr->fws->fws_dequeue_work, brcmf_fws_dequeue_worker); |
| 1972 | |
Arend van Spriel | 290fb76 | 2013-04-03 12:40:49 +0200 | [diff] [blame] | 1973 | /* enable firmware signalling if fcmode active */ |
| 1974 | if (drvr->fws->fcmode != BRCMF_FWS_FCMODE_NONE) |
| 1975 | tlv |= BRCMF_FWS_FLAGS_XONXOFF_SIGNALS | |
Arend van Spriel | 33753d4 | 2013-04-05 10:57:40 +0200 | [diff] [blame] | 1976 | BRCMF_FWS_FLAGS_CREDIT_STATUS_SIGNALS | |
| 1977 | BRCMF_FWS_FLAGS_HOST_PROPTXSTATUS_ACTIVE; |
Arend van Spriel | 290fb76 | 2013-04-03 12:40:49 +0200 | [diff] [blame] | 1978 | |
Arend van Spriel | a786b38 | 2013-04-23 12:53:14 +0200 | [diff] [blame] | 1979 | rc = brcmf_fweh_register(drvr, BRCMF_E_FIFO_CREDIT_MAP, |
| 1980 | brcmf_fws_notify_credit_map); |
Arend van Spriel | d933741 | 2013-04-03 12:40:47 +0200 | [diff] [blame] | 1981 | if (rc < 0) { |
Arend van Spriel | a786b38 | 2013-04-23 12:53:14 +0200 | [diff] [blame] | 1982 | brcmf_err("register credit map handler failed\n"); |
Arend van Spriel | d933741 | 2013-04-03 12:40:47 +0200 | [diff] [blame] | 1983 | goto fail; |
| 1984 | } |
| 1985 | |
Arend van Spriel | a786b38 | 2013-04-23 12:53:14 +0200 | [diff] [blame] | 1986 | /* setting the iovar may fail if feature is unsupported |
| 1987 | * so leave the rc as is so driver initialization can |
| 1988 | * continue. |
| 1989 | */ |
| 1990 | if (brcmf_fil_iovar_int_set(drvr->iflist[0], "tlv", tlv)) { |
| 1991 | brcmf_err("failed to set bdcv2 tlv signaling\n"); |
| 1992 | goto fail_event; |
Arend van Spriel | d933741 | 2013-04-03 12:40:47 +0200 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | brcmf_fws_hanger_init(&drvr->fws->hanger); |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 1996 | brcmf_fws_init_mac_descriptor(&drvr->fws->desc.other, NULL, 0); |
| 1997 | brcmu_pktq_init(&drvr->fws->desc.other.psq, BRCMF_FWS_PSQ_PREC_COUNT, |
| 1998 | BRCMF_FWS_PSQ_LEN); |
Arend van Spriel | d933741 | 2013-04-03 12:40:47 +0200 | [diff] [blame] | 1999 | |
| 2000 | /* create debugfs file for statistics */ |
| 2001 | brcmf_debugfs_create_fws_stats(drvr, &drvr->fws->stats); |
| 2002 | |
| 2003 | /* TODO: remove upon feature delivery */ |
| 2004 | brcmf_err("%s bdcv2 tlv signaling [%x]\n", |
| 2005 | drvr->fw_signals ? "enabled" : "disabled", tlv); |
| 2006 | return 0; |
| 2007 | |
Arend van Spriel | a786b38 | 2013-04-23 12:53:14 +0200 | [diff] [blame] | 2008 | fail_event: |
| 2009 | brcmf_fweh_unregister(drvr, BRCMF_E_FIFO_CREDIT_MAP); |
Arend van Spriel | d933741 | 2013-04-03 12:40:47 +0200 | [diff] [blame] | 2010 | fail: |
Arend van Spriel | d933741 | 2013-04-03 12:40:47 +0200 | [diff] [blame] | 2011 | brcmf_fws_deinit(drvr); |
| 2012 | return rc; |
| 2013 | } |
| 2014 | |
| 2015 | void brcmf_fws_deinit(struct brcmf_pub *drvr) |
| 2016 | { |
| 2017 | struct brcmf_fws_info *fws = drvr->fws; |
| 2018 | ulong flags; |
| 2019 | |
Arend van Spriel | 47829f4 | 2013-04-03 12:40:48 +0200 | [diff] [blame] | 2020 | if (!fws) |
| 2021 | return; |
| 2022 | |
Arend van Spriel | a786b38 | 2013-04-23 12:53:14 +0200 | [diff] [blame] | 2023 | /* disable firmware signalling entirely |
| 2024 | * to avoid using the workqueue. |
| 2025 | */ |
| 2026 | drvr->fw_signals = false; |
| 2027 | |
| 2028 | if (drvr->fws->fws_wq) |
| 2029 | destroy_workqueue(drvr->fws->fws_wq); |
| 2030 | |
Arend van Spriel | d933741 | 2013-04-03 12:40:47 +0200 | [diff] [blame] | 2031 | /* cleanup */ |
| 2032 | brcmf_fws_lock(drvr, flags); |
| 2033 | brcmf_fws_cleanup(fws, -1); |
| 2034 | drvr->fws = NULL; |
| 2035 | brcmf_fws_unlock(drvr, flags); |
| 2036 | |
| 2037 | /* free top structure */ |
| 2038 | kfree(fws); |
| 2039 | } |
| 2040 | |
Arend van Spriel | c7f34a6 | 2013-04-03 12:40:39 +0200 | [diff] [blame] | 2041 | bool brcmf_fws_fc_active(struct brcmf_fws_info *fws) |
| 2042 | { |
| 2043 | if (!fws) |
| 2044 | return false; |
| 2045 | |
| 2046 | brcmf_dbg(TRACE, "enter: mode=%d\n", fws->fcmode); |
| 2047 | return fws->fcmode != BRCMF_FWS_FCMODE_NONE; |
| 2048 | } |
Arend van Spriel | 0f8b5cc | 2013-04-03 12:40:41 +0200 | [diff] [blame] | 2049 | |
| 2050 | void brcmf_fws_bustxfail(struct brcmf_fws_info *fws, struct sk_buff *skb) |
| 2051 | { |
| 2052 | ulong flags; |
| 2053 | |
| 2054 | brcmf_fws_lock(fws->drvr, flags); |
| 2055 | brcmf_fws_txstatus_process(fws, BRCMF_FWS_TXSTATUS_FW_TOSSED, |
Arend van Spriel | 84bcc0c | 2013-04-03 12:40:50 +0200 | [diff] [blame] | 2056 | brcmf_skb_htod_tag_get_field(skb, HSLOT), 0); |
| 2057 | /* the packet never reached firmware so reclaim credit */ |
| 2058 | if (fws->fcmode == BRCMF_FWS_FCMODE_EXPLICIT_CREDIT && |
| 2059 | brcmf_skbcb(skb)->if_flags & BRCMF_SKB_IF_FLAGS_CREDITCHECK_MASK) { |
| 2060 | brcmf_fws_return_credits(fws, |
| 2061 | brcmf_skb_htod_tag_get_field(skb, |
| 2062 | FIFO), |
| 2063 | 1); |
| 2064 | brcmf_fws_schedule_deq(fws); |
| 2065 | } |
Arend van Spriel | 0f8b5cc | 2013-04-03 12:40:41 +0200 | [diff] [blame] | 2066 | brcmf_fws_unlock(fws->drvr, flags); |
| 2067 | } |