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