]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcdc.c
drivers: add explicit interrupt.h includes
[mirror_ubuntu-artful-kernel.git] / drivers / net / wireless / broadcom / brcm80211 / brcmfmac / bcdc.c
CommitLineData
5b435de0
AS
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>
5b435de0
AS
24
25#include <brcmu_utils.h>
26#include <brcmu_wifi.h>
27
122d3d04 28#include "core.h"
d14f78b9 29#include "bus.h"
349e7104 30#include "fwsignal.h"
a8e8ed34 31#include "debug.h"
ea0737d6 32#include "tracepoint.h"
85b84133
HM
33#include "proto.h"
34#include "bcdc.h"
5b435de0 35
aec87ce2 36struct brcmf_proto_bcdc_dcmd {
5b435de0
AS
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
aec87ce2
HM
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)
5b435de0
AS
53
54/*
aec87ce2 55 * BCDC header - Broadcom specific extension of CDC.
5b435de0
AS
56 * Used on data packets to convey priority across USB.
57 */
aec87ce2
HM
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
67
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)))
5b435de0 73
bee1b848 74/**
aec87ce2 75 * struct brcmf_proto_bcdc_header - BCDC header format
bee1b848
AS
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 */
aec87ce2 82struct brcmf_proto_bcdc_header {
5b435de0 83 u8 flags;
bee1b848 84 u8 priority;
5b435de0 85 u8 flags2;
e40aed06 86 u8 data_offset;
5b435de0
AS
87};
88
bee1b848
AS
89/*
90 * maximum length of firmware signal data between
aec87ce2 91 * the BCDC header and packet data in the tx path.
bee1b848
AS
92 */
93#define BRCMF_PROT_FW_SIGNAL_MAX_TXBYTES 12
5b435de0
AS
94
95#define RETRIES 2 /* # of retries to retrieve matching dcmd response */
6e3c7128 96#define BUS_HEADER_LEN (16+64) /* Must be atleast SDPCM_RESERVE
5b435de0
AS
97 * (amount of header tha might be added)
98 * plus any space that might be needed
6e3c7128 99 * for bus alignment padding.
5b435de0 100 */
85b84133 101struct brcmf_bcdc {
5b435de0 102 u16 reqid;
5b435de0 103 u8 bus_header[BUS_HEADER_LEN];
aec87ce2 104 struct brcmf_proto_bcdc_dcmd msg;
8141083c 105 unsigned char buf[BRCMF_DCMD_MAXLEN];
5b435de0
AS
106};
107
8141083c
HM
108
109static int
110brcmf_proto_bcdc_msg(struct brcmf_pub *drvr, int ifidx, uint cmd, void *buf,
111 uint len, bool set)
5b435de0 112{
85b84133 113 struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd;
8141083c
HM
114 struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg;
115 u32 flags;
5b435de0 116
aec87ce2 117 brcmf_dbg(BCDC, "Enter\n");
5b435de0 118
8141083c
HM
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);
5b435de0 132
d4533992
HM
133 len += sizeof(*msg);
134 if (len > BRCMF_TX_IOCTL_MAX_MSG_SIZE)
135 len = BRCMF_TX_IOCTL_MAX_MSG_SIZE;
136
5b435de0 137 /* Send request */
d4533992 138 return brcmf_bus_txctl(drvr->bus_if, (unsigned char *)&bcdc->msg, len);
5b435de0
AS
139}
140
aec87ce2 141static int brcmf_proto_bcdc_cmplt(struct brcmf_pub *drvr, u32 id, u32 len)
5b435de0
AS
142{
143 int ret;
85b84133 144 struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd;
5b435de0 145
aec87ce2
HM
146 brcmf_dbg(BCDC, "Enter\n");
147 len += sizeof(struct brcmf_proto_bcdc_dcmd);
5b435de0 148 do {
85b84133 149 ret = brcmf_bus_rxctl(drvr->bus_if, (unsigned char *)&bcdc->msg,
d9cb2596 150 len);
5b435de0
AS
151 if (ret < 0)
152 break;
aec87ce2 153 } while (BCDC_DCMD_ID(le32_to_cpu(bcdc->msg.flags)) != id);
5b435de0
AS
154
155 return ret;
156}
157
85b84133
HM
158static int
159brcmf_proto_bcdc_query_dcmd(struct brcmf_pub *drvr, int ifidx, uint cmd,
160 void *buf, uint len)
5b435de0 161{
85b84133 162 struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd;
aec87ce2 163 struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg;
5b435de0
AS
164 void *info;
165 int ret = 0, retries = 0;
166 u32 id, flags;
167
aec87ce2 168 brcmf_dbg(BCDC, "Enter, cmd %d len %d\n", cmd, len);
5b435de0 169
8141083c 170 ret = brcmf_proto_bcdc_msg(drvr, ifidx, cmd, buf, len, false);
5b435de0 171 if (ret < 0) {
aec87ce2 172 brcmf_err("brcmf_proto_bcdc_msg failed w/status %d\n",
5b435de0
AS
173 ret);
174 goto done;
175 }
176
177retry:
178 /* wait for interrupt and get first fragment */
aec87ce2 179 ret = brcmf_proto_bcdc_cmplt(drvr, bcdc->reqid, len);
5b435de0
AS
180 if (ret < 0)
181 goto done;
182
183 flags = le32_to_cpu(msg->flags);
aec87ce2 184 id = (flags & BCDC_DCMD_ID_MASK) >> BCDC_DCMD_ID_SHIFT;
5b435de0 185
85b84133 186 if ((id < bcdc->reqid) && (++retries < RETRIES))
5b435de0 187 goto retry;
85b84133 188 if (id != bcdc->reqid) {
5e8149f5 189 brcmf_err("%s: unexpected request id %d (expected %d)\n",
c9c00438
HM
190 brcmf_ifname(brcmf_get_ifp(drvr, ifidx)), id,
191 bcdc->reqid);
5b435de0
AS
192 ret = -EINVAL;
193 goto done;
194 }
195
196 /* Check info buffer */
704d1c6b 197 info = (void *)&bcdc->buf[0];
5b435de0
AS
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 */
aec87ce2 207 if (flags & BCDC_DCMD_ERROR)
5b435de0 208 ret = le32_to_cpu(msg->status);
5b435de0
AS
209
210done:
211 return ret;
212}
213
85b84133
HM
214static int
215brcmf_proto_bcdc_set_dcmd(struct brcmf_pub *drvr, int ifidx, uint cmd,
216 void *buf, uint len)
5b435de0 217{
85b84133 218 struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd;
aec87ce2 219 struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg;
5b435de0
AS
220 int ret = 0;
221 u32 flags, id;
222
aec87ce2 223 brcmf_dbg(BCDC, "Enter, cmd %d len %d\n", cmd, len);
5b435de0 224
8141083c 225 ret = brcmf_proto_bcdc_msg(drvr, ifidx, cmd, buf, len, true);
5b435de0
AS
226 if (ret < 0)
227 goto done;
228
aec87ce2 229 ret = brcmf_proto_bcdc_cmplt(drvr, bcdc->reqid, len);
5b435de0
AS
230 if (ret < 0)
231 goto done;
232
233 flags = le32_to_cpu(msg->flags);
aec87ce2 234 id = (flags & BCDC_DCMD_ID_MASK) >> BCDC_DCMD_ID_SHIFT;
5b435de0 235
85b84133 236 if (id != bcdc->reqid) {
5e8149f5 237 brcmf_err("%s: unexpected request id %d (expected %d)\n",
c9c00438
HM
238 brcmf_ifname(brcmf_get_ifp(drvr, ifidx)), id,
239 bcdc->reqid);
5b435de0
AS
240 ret = -EINVAL;
241 goto done;
242 }
243
244 /* Check the ERROR flag */
aec87ce2 245 if (flags & BCDC_DCMD_ERROR)
5b435de0 246 ret = le32_to_cpu(msg->status);
5b435de0
AS
247
248done:
249 return ret;
250}
251
85b84133
HM
252static void
253brcmf_proto_bcdc_hdrpush(struct brcmf_pub *drvr, int ifidx, u8 offset,
5b435de0
AS
254 struct sk_buff *pktbuf)
255{
aec87ce2 256 struct brcmf_proto_bcdc_header *h;
5b435de0 257
aec87ce2 258 brcmf_dbg(BCDC, "Enter\n");
5b435de0
AS
259
260 /* Push BDC header used to convey priority for buses that don't */
aec87ce2 261 skb_push(pktbuf, BCDC_HEADER_LEN);
5b435de0 262
aec87ce2 263 h = (struct brcmf_proto_bcdc_header *)(pktbuf->data);
5b435de0 264
aec87ce2
HM
265 h->flags = (BCDC_PROTO_VER << BCDC_FLAG_VER_SHIFT);
266 if (pktbuf->ip_summed == CHECKSUM_PARTIAL)
267 h->flags |= BCDC_FLAG_SUM_NEEDED;
5b435de0 268
aec87ce2 269 h->priority = (pktbuf->priority & BCDC_PRIORITY_MASK);
5b435de0 270 h->flags2 = 0;
8f0c3b6d 271 h->data_offset = offset;
aec87ce2
HM
272 BCDC_SET_IF_IDX(h, ifidx);
273 trace_brcmf_bcdchdr(pktbuf->data);
5b435de0
AS
274}
275
85b84133 276static int
796cfb65
AS
277brcmf_proto_bcdc_hdrpull(struct brcmf_pub *drvr, bool do_fws,
278 struct sk_buff *pktbuf, struct brcmf_if **ifp)
5b435de0 279{
aec87ce2 280 struct brcmf_proto_bcdc_header *h;
796cfb65 281 struct brcmf_if *tmp_if;
5b435de0 282
aec87ce2 283 brcmf_dbg(BCDC, "Enter\n");
5b435de0 284
aec87ce2
HM
285 /* Pop BCDC header used to convey priority for buses that don't */
286 if (pktbuf->len <= BCDC_HEADER_LEN) {
5cd02c77 287 brcmf_dbg(INFO, "rx data too short (%d <= %d)\n",
aec87ce2 288 pktbuf->len, BCDC_HEADER_LEN);
5b435de0
AS
289 return -EBADE;
290 }
291
aec87ce2
HM
292 trace_brcmf_bcdchdr(pktbuf->data);
293 h = (struct brcmf_proto_bcdc_header *)(pktbuf->data);
5b435de0 294
796cfb65
AS
295 tmp_if = brcmf_get_ifp(drvr, BCDC_GET_IF_IDX(h));
296 if (!tmp_if) {
75effb03 297 brcmf_dbg(INFO, "no matching ifp found\n");
5b435de0
AS
298 return -EBADE;
299 }
aec87ce2
HM
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",
c9c00438 303 brcmf_ifname(tmp_if), h->flags);
5b435de0
AS
304 return -EBADE;
305 }
306
aec87ce2
HM
307 if (h->flags & BCDC_FLAG_SUM_GOOD) {
308 brcmf_dbg(BCDC, "%s: BDC rcv, good checksum, flags 0x%x\n",
c9c00438 309 brcmf_ifname(tmp_if), h->flags);
aec87ce2 310 pktbuf->ip_summed = CHECKSUM_UNNECESSARY;
5b435de0
AS
311 }
312
aec87ce2 313 pktbuf->priority = h->priority & BCDC_PRIORITY_MASK;
5b435de0 314
aec87ce2 315 skb_pull(pktbuf, BCDC_HEADER_LEN);
349e7104 316 if (do_fws)
c67d41ba 317 brcmf_fws_hdrpull(tmp_if, h->data_offset << 2, pktbuf);
349e7104
AS
318 else
319 skb_pull(pktbuf, h->data_offset << 2);
5b435de0 320
a43af515
AS
321 if (pktbuf->len == 0)
322 return -ENODATA;
75effb03 323
53985dcc
PF
324 if (ifp != NULL)
325 *ifp = tmp_if;
5b435de0
AS
326 return 0;
327}
328
b073ac1f
RM
329static int brcmf_proto_bcdc_tx_queue_data(struct brcmf_pub *drvr, int ifidx,
330 struct sk_buff *skb)
331{
332 struct brcmf_if *ifp = brcmf_get_ifp(drvr, ifidx);
333
334 if (!brcmf_fws_queue_skbs(drvr->fws))
335 return brcmf_proto_txdata(drvr, ifidx, 0, skb);
336
337 return brcmf_fws_process_skb(ifp, skb);
338}
339
7b8a466e
HM
340static int
341brcmf_proto_bcdc_txdata(struct brcmf_pub *drvr, int ifidx, u8 offset,
342 struct sk_buff *pktbuf)
343{
344 brcmf_proto_bcdc_hdrpush(drvr, ifidx, offset, pktbuf);
345 return brcmf_bus_txdata(drvr->bus_if, pktbuf);
346}
347
8851cce0
HM
348static void
349brcmf_proto_bcdc_configure_addr_mode(struct brcmf_pub *drvr, int ifidx,
350 enum proto_addr_mode addr_mode)
351{
352}
353
354static void
355brcmf_proto_bcdc_delete_peer(struct brcmf_pub *drvr, int ifidx,
356 u8 peer[ETH_ALEN])
357{
358}
7b8a466e 359
70b7d94b
HM
360static void
361brcmf_proto_bcdc_add_tdls_peer(struct brcmf_pub *drvr, int ifidx,
362 u8 peer[ETH_ALEN])
363{
364}
365
bbd1f932
AS
366static void brcmf_proto_bcdc_rxreorder(struct brcmf_if *ifp,
367 struct sk_buff *skb)
368{
369 brcmf_fws_rxreorder(ifp, skb);
370}
371
85b84133 372int brcmf_proto_bcdc_attach(struct brcmf_pub *drvr)
5b435de0 373{
85b84133 374 struct brcmf_bcdc *bcdc;
5b435de0 375
85b84133
HM
376 bcdc = kzalloc(sizeof(*bcdc), GFP_ATOMIC);
377 if (!bcdc)
5b435de0
AS
378 goto fail;
379
380 /* ensure that the msg buf directly follows the cdc msg struct */
85b84133
HM
381 if ((unsigned long)(&bcdc->msg + 1) != (unsigned long)bcdc->buf) {
382 brcmf_err("struct brcmf_proto_bcdc is not correctly defined\n");
5b435de0
AS
383 goto fail;
384 }
385
85b84133
HM
386 drvr->proto->hdrpull = brcmf_proto_bcdc_hdrpull;
387 drvr->proto->query_dcmd = brcmf_proto_bcdc_query_dcmd;
388 drvr->proto->set_dcmd = brcmf_proto_bcdc_set_dcmd;
b073ac1f 389 drvr->proto->tx_queue_data = brcmf_proto_bcdc_tx_queue_data;
7b8a466e 390 drvr->proto->txdata = brcmf_proto_bcdc_txdata;
8851cce0
HM
391 drvr->proto->configure_addr_mode = brcmf_proto_bcdc_configure_addr_mode;
392 drvr->proto->delete_peer = brcmf_proto_bcdc_delete_peer;
70b7d94b 393 drvr->proto->add_tdls_peer = brcmf_proto_bcdc_add_tdls_peer;
bbd1f932 394 drvr->proto->rxreorder = brcmf_proto_bcdc_rxreorder;
85b84133
HM
395 drvr->proto->pd = bcdc;
396
aec87ce2 397 drvr->hdrlen += BCDC_HEADER_LEN + BRCMF_PROT_FW_SIGNAL_MAX_TXBYTES;
b01a6b3c 398 drvr->bus_if->maxctl = BRCMF_DCMD_MAXLEN +
8141083c 399 sizeof(struct brcmf_proto_bcdc_dcmd);
5b435de0
AS
400 return 0;
401
402fail:
85b84133 403 kfree(bcdc);
5b435de0
AS
404 return -ENOMEM;
405}
406
85b84133 407void brcmf_proto_bcdc_detach(struct brcmf_pub *drvr)
5b435de0 408{
85b84133
HM
409 kfree(drvr->proto->pd);
410 drvr->proto->pd = NULL;
5b435de0 411}