Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [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 | |
| 17 | /******************************************************************************* |
| 18 | * Communicates with the dongle by using dcmd codes. |
| 19 | * For certain dcmd codes, the dongle interprets string data from the host. |
| 20 | ******************************************************************************/ |
| 21 | |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/netdevice.h> |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 24 | |
| 25 | #include <brcmu_utils.h> |
| 26 | #include <brcmu_wifi.h> |
| 27 | |
Hante Meuleman | 122d3d0 | 2014-10-28 14:56:18 +0100 | [diff] [blame] | 28 | #include "core.h" |
Hante Meuleman | d14f78b | 2014-10-28 14:56:14 +0100 | [diff] [blame] | 29 | #include "bus.h" |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 30 | #include "fwsignal.h" |
Hante Meuleman | a8e8ed3 | 2014-10-28 14:56:13 +0100 | [diff] [blame] | 31 | #include "debug.h" |
Arend van Spriel | ea0737d | 2013-06-06 13:18:05 +0200 | [diff] [blame] | 32 | #include "tracepoint.h" |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 33 | #include "proto.h" |
| 34 | #include "bcdc.h" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 35 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 36 | struct brcmf_proto_bcdc_dcmd { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 37 | __le32 cmd; /* dongle command value */ |
| 38 | __le32 len; /* lower 16: output buflen; |
| 39 | * upper 16: input buflen (excludes header) */ |
| 40 | __le32 flags; /* flag defns given below */ |
| 41 | __le32 status; /* status code returned from the device */ |
| 42 | }; |
| 43 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 44 | /* BCDC flag definitions */ |
| 45 | #define BCDC_DCMD_ERROR 0x01 /* 1=cmd failed */ |
| 46 | #define BCDC_DCMD_SET 0x02 /* 0=get, 1=set cmd */ |
| 47 | #define BCDC_DCMD_IF_MASK 0xF000 /* I/F index */ |
| 48 | #define BCDC_DCMD_IF_SHIFT 12 |
| 49 | #define BCDC_DCMD_ID_MASK 0xFFFF0000 /* id an cmd pairing */ |
| 50 | #define BCDC_DCMD_ID_SHIFT 16 /* ID Mask shift bits */ |
| 51 | #define BCDC_DCMD_ID(flags) \ |
| 52 | (((flags) & BCDC_DCMD_ID_MASK) >> BCDC_DCMD_ID_SHIFT) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 53 | |
| 54 | /* |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 55 | * BCDC header - Broadcom specific extension of CDC. |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 56 | * Used on data packets to convey priority across USB. |
| 57 | */ |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 58 | #define BCDC_HEADER_LEN 4 |
| 59 | #define BCDC_PROTO_VER 2 /* Protocol version */ |
| 60 | #define BCDC_FLAG_VER_MASK 0xf0 /* Protocol version mask */ |
| 61 | #define BCDC_FLAG_VER_SHIFT 4 /* Protocol version shift */ |
| 62 | #define BCDC_FLAG_SUM_GOOD 0x04 /* Good RX checksums */ |
| 63 | #define BCDC_FLAG_SUM_NEEDED 0x08 /* Dongle needs to do TX checksums */ |
| 64 | #define BCDC_PRIORITY_MASK 0x7 |
| 65 | #define BCDC_FLAG2_IF_MASK 0x0f /* packet rx interface in APSTA */ |
| 66 | #define BCDC_FLAG2_IF_SHIFT 0 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 67 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 68 | #define BCDC_GET_IF_IDX(hdr) \ |
| 69 | ((int)((((hdr)->flags2) & BCDC_FLAG2_IF_MASK) >> BCDC_FLAG2_IF_SHIFT)) |
| 70 | #define BCDC_SET_IF_IDX(hdr, idx) \ |
| 71 | ((hdr)->flags2 = (((hdr)->flags2 & ~BCDC_FLAG2_IF_MASK) | \ |
| 72 | ((idx) << BCDC_FLAG2_IF_SHIFT))) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 73 | |
Arend van Spriel | bee1b84 | 2013-03-03 12:45:26 +0100 | [diff] [blame] | 74 | /** |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 75 | * struct brcmf_proto_bcdc_header - BCDC header format |
Arend van Spriel | bee1b84 | 2013-03-03 12:45:26 +0100 | [diff] [blame] | 76 | * |
| 77 | * @flags: flags contain protocol and checksum info. |
| 78 | * @priority: 802.1d priority and USB flow control info (bit 4:7). |
| 79 | * @flags2: additional flags containing dongle interface index. |
| 80 | * @data_offset: start of packet data. header is following by firmware signals. |
| 81 | */ |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 82 | struct brcmf_proto_bcdc_header { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 83 | u8 flags; |
Arend van Spriel | bee1b84 | 2013-03-03 12:45:26 +0100 | [diff] [blame] | 84 | u8 priority; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 85 | u8 flags2; |
Franky Lin | e40aed0 | 2011-12-08 15:06:38 -0800 | [diff] [blame] | 86 | u8 data_offset; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 87 | }; |
| 88 | |
Arend van Spriel | bee1b84 | 2013-03-03 12:45:26 +0100 | [diff] [blame] | 89 | /* |
| 90 | * maximum length of firmware signal data between |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 91 | * the BCDC header and packet data in the tx path. |
Arend van Spriel | bee1b84 | 2013-03-03 12:45:26 +0100 | [diff] [blame] | 92 | */ |
| 93 | #define BRCMF_PROT_FW_SIGNAL_MAX_TXBYTES 12 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 94 | |
| 95 | #define RETRIES 2 /* # of retries to retrieve matching dcmd response */ |
Franky Lin | 6e3c712 | 2011-12-16 18:37:11 -0800 | [diff] [blame] | 96 | #define BUS_HEADER_LEN (16+64) /* Must be atleast SDPCM_RESERVE |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 97 | * (amount of header tha might be added) |
| 98 | * plus any space that might be needed |
Franky Lin | 6e3c712 | 2011-12-16 18:37:11 -0800 | [diff] [blame] | 99 | * for bus alignment padding. |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 100 | */ |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 101 | struct brcmf_bcdc { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 102 | u16 reqid; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 103 | u8 bus_header[BUS_HEADER_LEN]; |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 104 | struct brcmf_proto_bcdc_dcmd msg; |
Hante Meuleman | 8141083 | 2013-12-12 11:59:00 +0100 | [diff] [blame] | 105 | unsigned char buf[BRCMF_DCMD_MAXLEN]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 106 | }; |
| 107 | |
Hante Meuleman | 8141083 | 2013-12-12 11:59:00 +0100 | [diff] [blame] | 108 | |
| 109 | static int |
| 110 | brcmf_proto_bcdc_msg(struct brcmf_pub *drvr, int ifidx, uint cmd, void *buf, |
| 111 | uint len, bool set) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 112 | { |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 113 | struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd; |
Hante Meuleman | 8141083 | 2013-12-12 11:59:00 +0100 | [diff] [blame] | 114 | struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg; |
| 115 | u32 flags; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 116 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 117 | brcmf_dbg(BCDC, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 118 | |
Hante Meuleman | 8141083 | 2013-12-12 11:59:00 +0100 | [diff] [blame] | 119 | memset(msg, 0, sizeof(struct brcmf_proto_bcdc_dcmd)); |
| 120 | |
| 121 | msg->cmd = cpu_to_le32(cmd); |
| 122 | msg->len = cpu_to_le32(len); |
| 123 | flags = (++bcdc->reqid << BCDC_DCMD_ID_SHIFT); |
| 124 | if (set) |
| 125 | flags |= BCDC_DCMD_SET; |
| 126 | flags = (flags & ~BCDC_DCMD_IF_MASK) | |
| 127 | (ifidx << BCDC_DCMD_IF_SHIFT); |
| 128 | msg->flags = cpu_to_le32(flags); |
| 129 | |
| 130 | if (buf) |
| 131 | memcpy(bcdc->buf, buf, len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 132 | |
Hante Meuleman | d453399 | 2014-01-06 12:40:38 +0100 | [diff] [blame] | 133 | len += sizeof(*msg); |
| 134 | if (len > BRCMF_TX_IOCTL_MAX_MSG_SIZE) |
| 135 | len = BRCMF_TX_IOCTL_MAX_MSG_SIZE; |
| 136 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 137 | /* Send request */ |
Hante Meuleman | d453399 | 2014-01-06 12:40:38 +0100 | [diff] [blame] | 138 | return brcmf_bus_txctl(drvr->bus_if, (unsigned char *)&bcdc->msg, len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 139 | } |
| 140 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 141 | static int brcmf_proto_bcdc_cmplt(struct brcmf_pub *drvr, u32 id, u32 len) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 142 | { |
| 143 | int ret; |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 144 | struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 145 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 146 | brcmf_dbg(BCDC, "Enter\n"); |
| 147 | len += sizeof(struct brcmf_proto_bcdc_dcmd); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 148 | do { |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 149 | ret = brcmf_bus_rxctl(drvr->bus_if, (unsigned char *)&bcdc->msg, |
Arend van Spriel | d9cb259 | 2012-12-05 15:25:54 +0100 | [diff] [blame] | 150 | len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 151 | if (ret < 0) |
| 152 | break; |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 153 | } while (BCDC_DCMD_ID(le32_to_cpu(bcdc->msg.flags)) != id); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 154 | |
| 155 | return ret; |
| 156 | } |
| 157 | |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 158 | static int |
| 159 | brcmf_proto_bcdc_query_dcmd(struct brcmf_pub *drvr, int ifidx, uint cmd, |
| 160 | void *buf, uint len) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 161 | { |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 162 | struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd; |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 163 | struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 164 | void *info; |
| 165 | int ret = 0, retries = 0; |
| 166 | u32 id, flags; |
| 167 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 168 | brcmf_dbg(BCDC, "Enter, cmd %d len %d\n", cmd, len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 169 | |
Hante Meuleman | 8141083 | 2013-12-12 11:59:00 +0100 | [diff] [blame] | 170 | ret = brcmf_proto_bcdc_msg(drvr, ifidx, cmd, buf, len, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 171 | if (ret < 0) { |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 172 | brcmf_err("brcmf_proto_bcdc_msg failed w/status %d\n", |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 173 | ret); |
| 174 | goto done; |
| 175 | } |
| 176 | |
| 177 | retry: |
| 178 | /* wait for interrupt and get first fragment */ |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 179 | ret = brcmf_proto_bcdc_cmplt(drvr, bcdc->reqid, len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 180 | if (ret < 0) |
| 181 | goto done; |
| 182 | |
| 183 | flags = le32_to_cpu(msg->flags); |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 184 | id = (flags & BCDC_DCMD_ID_MASK) >> BCDC_DCMD_ID_SHIFT; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 185 | |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 186 | if ((id < bcdc->reqid) && (++retries < RETRIES)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 187 | goto retry; |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 188 | if (id != bcdc->reqid) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 189 | brcmf_err("%s: unexpected request id %d (expected %d)\n", |
Hante Meuleman | c9c0043 | 2015-10-29 20:33:12 +0100 | [diff] [blame] | 190 | brcmf_ifname(brcmf_get_ifp(drvr, ifidx)), id, |
| 191 | bcdc->reqid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 192 | ret = -EINVAL; |
| 193 | goto done; |
| 194 | } |
| 195 | |
| 196 | /* Check info buffer */ |
| 197 | info = (void *)&msg[1]; |
| 198 | |
| 199 | /* Copy info buffer */ |
| 200 | if (buf) { |
| 201 | if (ret < (int)len) |
| 202 | len = ret; |
| 203 | memcpy(buf, info, len); |
| 204 | } |
| 205 | |
| 206 | /* Check the ERROR flag */ |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 207 | if (flags & BCDC_DCMD_ERROR) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 208 | ret = le32_to_cpu(msg->status); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 209 | |
| 210 | done: |
| 211 | return ret; |
| 212 | } |
| 213 | |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 214 | static int |
| 215 | brcmf_proto_bcdc_set_dcmd(struct brcmf_pub *drvr, int ifidx, uint cmd, |
| 216 | void *buf, uint len) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 217 | { |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 218 | struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd; |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 219 | struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 220 | int ret = 0; |
| 221 | u32 flags, id; |
| 222 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 223 | brcmf_dbg(BCDC, "Enter, cmd %d len %d\n", cmd, len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 224 | |
Hante Meuleman | 8141083 | 2013-12-12 11:59:00 +0100 | [diff] [blame] | 225 | ret = brcmf_proto_bcdc_msg(drvr, ifidx, cmd, buf, len, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 226 | if (ret < 0) |
| 227 | goto done; |
| 228 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 229 | ret = brcmf_proto_bcdc_cmplt(drvr, bcdc->reqid, len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 230 | if (ret < 0) |
| 231 | goto done; |
| 232 | |
| 233 | flags = le32_to_cpu(msg->flags); |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 234 | id = (flags & BCDC_DCMD_ID_MASK) >> BCDC_DCMD_ID_SHIFT; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 235 | |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 236 | if (id != bcdc->reqid) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 237 | brcmf_err("%s: unexpected request id %d (expected %d)\n", |
Hante Meuleman | c9c0043 | 2015-10-29 20:33:12 +0100 | [diff] [blame] | 238 | brcmf_ifname(brcmf_get_ifp(drvr, ifidx)), id, |
| 239 | bcdc->reqid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 240 | ret = -EINVAL; |
| 241 | goto done; |
| 242 | } |
| 243 | |
| 244 | /* Check the ERROR flag */ |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 245 | if (flags & BCDC_DCMD_ERROR) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 246 | ret = le32_to_cpu(msg->status); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 247 | |
| 248 | done: |
| 249 | return ret; |
| 250 | } |
| 251 | |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 252 | static void |
| 253 | brcmf_proto_bcdc_hdrpush(struct brcmf_pub *drvr, int ifidx, u8 offset, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 254 | struct sk_buff *pktbuf) |
| 255 | { |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 256 | struct brcmf_proto_bcdc_header *h; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 257 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 258 | brcmf_dbg(BCDC, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 259 | |
| 260 | /* Push BDC header used to convey priority for buses that don't */ |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 261 | skb_push(pktbuf, BCDC_HEADER_LEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 262 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 263 | h = (struct brcmf_proto_bcdc_header *)(pktbuf->data); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 264 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 265 | h->flags = (BCDC_PROTO_VER << BCDC_FLAG_VER_SHIFT); |
| 266 | if (pktbuf->ip_summed == CHECKSUM_PARTIAL) |
| 267 | h->flags |= BCDC_FLAG_SUM_NEEDED; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 268 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 269 | h->priority = (pktbuf->priority & BCDC_PRIORITY_MASK); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 270 | h->flags2 = 0; |
Arend van Spriel | 8f0c3b6 | 2013-03-03 12:45:32 +0100 | [diff] [blame] | 271 | h->data_offset = offset; |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 272 | BCDC_SET_IF_IDX(h, ifidx); |
| 273 | trace_brcmf_bcdchdr(pktbuf->data); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 274 | } |
| 275 | |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 276 | static int |
Arend van Spriel | 796cfb6 | 2015-08-26 22:14:54 +0200 | [diff] [blame] | 277 | brcmf_proto_bcdc_hdrpull(struct brcmf_pub *drvr, bool do_fws, |
| 278 | struct sk_buff *pktbuf, struct brcmf_if **ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 279 | { |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 280 | struct brcmf_proto_bcdc_header *h; |
Arend van Spriel | 796cfb6 | 2015-08-26 22:14:54 +0200 | [diff] [blame] | 281 | struct brcmf_if *tmp_if; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 282 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 283 | brcmf_dbg(BCDC, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 284 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 285 | /* Pop BCDC header used to convey priority for buses that don't */ |
| 286 | if (pktbuf->len <= BCDC_HEADER_LEN) { |
Piotr Haber | 5cd02c7 | 2013-04-03 12:40:43 +0200 | [diff] [blame] | 287 | brcmf_dbg(INFO, "rx data too short (%d <= %d)\n", |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 288 | pktbuf->len, BCDC_HEADER_LEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 289 | return -EBADE; |
| 290 | } |
| 291 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 292 | trace_brcmf_bcdchdr(pktbuf->data); |
| 293 | h = (struct brcmf_proto_bcdc_header *)(pktbuf->data); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 294 | |
Arend van Spriel | 796cfb6 | 2015-08-26 22:14:54 +0200 | [diff] [blame] | 295 | tmp_if = brcmf_get_ifp(drvr, BCDC_GET_IF_IDX(h)); |
| 296 | if (!tmp_if) { |
Arend van Spriel | 75effb03e | 2015-08-26 22:14:53 +0200 | [diff] [blame] | 297 | brcmf_dbg(INFO, "no matching ifp found\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 298 | return -EBADE; |
| 299 | } |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 300 | if (((h->flags & BCDC_FLAG_VER_MASK) >> BCDC_FLAG_VER_SHIFT) != |
| 301 | BCDC_PROTO_VER) { |
| 302 | brcmf_err("%s: non-BCDC packet received, flags 0x%x\n", |
Hante Meuleman | c9c0043 | 2015-10-29 20:33:12 +0100 | [diff] [blame] | 303 | brcmf_ifname(tmp_if), h->flags); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 304 | return -EBADE; |
| 305 | } |
| 306 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 307 | if (h->flags & BCDC_FLAG_SUM_GOOD) { |
| 308 | brcmf_dbg(BCDC, "%s: BDC rcv, good checksum, flags 0x%x\n", |
Hante Meuleman | c9c0043 | 2015-10-29 20:33:12 +0100 | [diff] [blame] | 309 | brcmf_ifname(tmp_if), h->flags); |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 310 | pktbuf->ip_summed = CHECKSUM_UNNECESSARY; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 311 | } |
| 312 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 313 | pktbuf->priority = h->priority & BCDC_PRIORITY_MASK; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 314 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 315 | skb_pull(pktbuf, BCDC_HEADER_LEN); |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 316 | if (do_fws) |
Arend van Spriel | c67d41b | 2015-08-26 22:15:03 +0200 | [diff] [blame] | 317 | brcmf_fws_hdrpull(tmp_if, h->data_offset << 2, pktbuf); |
Arend van Spriel | 349e710 | 2013-03-03 12:45:28 +0100 | [diff] [blame] | 318 | else |
| 319 | skb_pull(pktbuf, h->data_offset << 2); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 320 | |
Arend van Spriel | a43af51 | 2013-01-02 15:22:43 +0100 | [diff] [blame] | 321 | if (pktbuf->len == 0) |
| 322 | return -ENODATA; |
Arend van Spriel | 75effb03e | 2015-08-26 22:14:53 +0200 | [diff] [blame] | 323 | |
Arend van Spriel | 796cfb6 | 2015-08-26 22:14:54 +0200 | [diff] [blame] | 324 | *ifp = tmp_if; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 325 | return 0; |
| 326 | } |
| 327 | |
Hante Meuleman | 7b8a466 | 2013-12-12 11:59:03 +0100 | [diff] [blame] | 328 | static int |
| 329 | brcmf_proto_bcdc_txdata(struct brcmf_pub *drvr, int ifidx, u8 offset, |
| 330 | struct sk_buff *pktbuf) |
| 331 | { |
| 332 | brcmf_proto_bcdc_hdrpush(drvr, ifidx, offset, pktbuf); |
| 333 | return brcmf_bus_txdata(drvr->bus_if, pktbuf); |
| 334 | } |
| 335 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 336 | static void |
| 337 | brcmf_proto_bcdc_configure_addr_mode(struct brcmf_pub *drvr, int ifidx, |
| 338 | enum proto_addr_mode addr_mode) |
| 339 | { |
| 340 | } |
| 341 | |
| 342 | static void |
| 343 | brcmf_proto_bcdc_delete_peer(struct brcmf_pub *drvr, int ifidx, |
| 344 | u8 peer[ETH_ALEN]) |
| 345 | { |
| 346 | } |
Hante Meuleman | 7b8a466 | 2013-12-12 11:59:03 +0100 | [diff] [blame] | 347 | |
Hante Meuleman | 70b7d94 | 2014-07-30 13:20:07 +0200 | [diff] [blame] | 348 | static void |
| 349 | brcmf_proto_bcdc_add_tdls_peer(struct brcmf_pub *drvr, int ifidx, |
| 350 | u8 peer[ETH_ALEN]) |
| 351 | { |
| 352 | } |
| 353 | |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 354 | int brcmf_proto_bcdc_attach(struct brcmf_pub *drvr) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 355 | { |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 356 | struct brcmf_bcdc *bcdc; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 357 | |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 358 | bcdc = kzalloc(sizeof(*bcdc), GFP_ATOMIC); |
| 359 | if (!bcdc) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 360 | goto fail; |
| 361 | |
| 362 | /* ensure that the msg buf directly follows the cdc msg struct */ |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 363 | if ((unsigned long)(&bcdc->msg + 1) != (unsigned long)bcdc->buf) { |
| 364 | brcmf_err("struct brcmf_proto_bcdc is not correctly defined\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 365 | goto fail; |
| 366 | } |
| 367 | |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 368 | drvr->proto->hdrpull = brcmf_proto_bcdc_hdrpull; |
| 369 | drvr->proto->query_dcmd = brcmf_proto_bcdc_query_dcmd; |
| 370 | drvr->proto->set_dcmd = brcmf_proto_bcdc_set_dcmd; |
Hante Meuleman | 7b8a466 | 2013-12-12 11:59:03 +0100 | [diff] [blame] | 371 | drvr->proto->txdata = brcmf_proto_bcdc_txdata; |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 372 | drvr->proto->configure_addr_mode = brcmf_proto_bcdc_configure_addr_mode; |
| 373 | drvr->proto->delete_peer = brcmf_proto_bcdc_delete_peer; |
Hante Meuleman | 70b7d94 | 2014-07-30 13:20:07 +0200 | [diff] [blame] | 374 | drvr->proto->add_tdls_peer = brcmf_proto_bcdc_add_tdls_peer; |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 375 | drvr->proto->pd = bcdc; |
| 376 | |
Hante Meuleman | aec87ce | 2013-11-29 12:25:21 +0100 | [diff] [blame] | 377 | drvr->hdrlen += BCDC_HEADER_LEN + BRCMF_PROT_FW_SIGNAL_MAX_TXBYTES; |
Franky Lin | b01a6b3 | 2011-12-16 18:37:03 -0800 | [diff] [blame] | 378 | drvr->bus_if->maxctl = BRCMF_DCMD_MAXLEN + |
Hante Meuleman | 8141083 | 2013-12-12 11:59:00 +0100 | [diff] [blame] | 379 | sizeof(struct brcmf_proto_bcdc_dcmd); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 380 | return 0; |
| 381 | |
| 382 | fail: |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 383 | kfree(bcdc); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 384 | return -ENOMEM; |
| 385 | } |
| 386 | |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 387 | void brcmf_proto_bcdc_detach(struct brcmf_pub *drvr) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 388 | { |
Hante Meuleman | 85b8413 | 2013-11-29 12:25:16 +0100 | [diff] [blame] | 389 | kfree(drvr->proto->pd); |
| 390 | drvr->proto->pd = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 391 | } |