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