0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/types.h>
0012 #include <linux/netdevice.h>
0013
0014 #include <brcmu_utils.h>
0015 #include <brcmu_wifi.h>
0016
0017 #include "core.h"
0018 #include "bus.h"
0019 #include "fwsignal.h"
0020 #include "debug.h"
0021 #include "tracepoint.h"
0022 #include "proto.h"
0023 #include "bcdc.h"
0024
0025 struct brcmf_proto_bcdc_dcmd {
0026 __le32 cmd;
0027 __le32 len;
0028
0029 __le32 flags;
0030 __le32 status;
0031 };
0032
0033
0034 #define BCDC_DCMD_ERROR 0x01
0035 #define BCDC_DCMD_SET 0x02
0036 #define BCDC_DCMD_IF_MASK 0xF000
0037 #define BCDC_DCMD_IF_SHIFT 12
0038 #define BCDC_DCMD_ID_MASK 0xFFFF0000
0039 #define BCDC_DCMD_ID_SHIFT 16
0040 #define BCDC_DCMD_ID(flags) \
0041 (((flags) & BCDC_DCMD_ID_MASK) >> BCDC_DCMD_ID_SHIFT)
0042
0043
0044
0045
0046
0047 #define BCDC_HEADER_LEN 4
0048 #define BCDC_PROTO_VER 2
0049 #define BCDC_FLAG_VER_MASK 0xf0
0050 #define BCDC_FLAG_VER_SHIFT 4
0051 #define BCDC_FLAG_SUM_GOOD 0x04
0052 #define BCDC_FLAG_SUM_NEEDED 0x08
0053 #define BCDC_PRIORITY_MASK 0x7
0054 #define BCDC_FLAG2_IF_MASK 0x0f
0055 #define BCDC_FLAG2_IF_SHIFT 0
0056
0057 #define BCDC_GET_IF_IDX(hdr) \
0058 ((int)((((hdr)->flags2) & BCDC_FLAG2_IF_MASK) >> BCDC_FLAG2_IF_SHIFT))
0059 #define BCDC_SET_IF_IDX(hdr, idx) \
0060 ((hdr)->flags2 = (((hdr)->flags2 & ~BCDC_FLAG2_IF_MASK) | \
0061 ((idx) << BCDC_FLAG2_IF_SHIFT)))
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 struct brcmf_proto_bcdc_header {
0072 u8 flags;
0073 u8 priority;
0074 u8 flags2;
0075 u8 data_offset;
0076 };
0077
0078
0079
0080
0081
0082 #define BRCMF_PROT_FW_SIGNAL_MAX_TXBYTES 12
0083
0084 #define RETRIES 2
0085 #define BUS_HEADER_LEN (16+64)
0086
0087
0088
0089
0090 struct brcmf_bcdc {
0091 u16 reqid;
0092 u8 bus_header[BUS_HEADER_LEN];
0093 struct brcmf_proto_bcdc_dcmd msg;
0094 unsigned char buf[BRCMF_DCMD_MAXLEN];
0095 struct brcmf_fws_info *fws;
0096 };
0097
0098
0099 struct brcmf_fws_info *drvr_to_fws(struct brcmf_pub *drvr)
0100 {
0101 struct brcmf_bcdc *bcdc = drvr->proto->pd;
0102
0103 return bcdc->fws;
0104 }
0105
0106 static int
0107 brcmf_proto_bcdc_msg(struct brcmf_pub *drvr, int ifidx, uint cmd, void *buf,
0108 uint len, bool set)
0109 {
0110 struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd;
0111 struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg;
0112 u32 flags;
0113
0114 brcmf_dbg(BCDC, "Enter\n");
0115
0116 memset(msg, 0, sizeof(struct brcmf_proto_bcdc_dcmd));
0117
0118 msg->cmd = cpu_to_le32(cmd);
0119 msg->len = cpu_to_le32(len);
0120 flags = (++bcdc->reqid << BCDC_DCMD_ID_SHIFT);
0121 if (set)
0122 flags |= BCDC_DCMD_SET;
0123 flags = (flags & ~BCDC_DCMD_IF_MASK) |
0124 (ifidx << BCDC_DCMD_IF_SHIFT);
0125 msg->flags = cpu_to_le32(flags);
0126
0127 if (buf)
0128 memcpy(bcdc->buf, buf, len);
0129
0130 len += sizeof(*msg);
0131 if (len > BRCMF_TX_IOCTL_MAX_MSG_SIZE)
0132 len = BRCMF_TX_IOCTL_MAX_MSG_SIZE;
0133
0134
0135 return brcmf_bus_txctl(drvr->bus_if, (unsigned char *)&bcdc->msg, len);
0136 }
0137
0138 static int brcmf_proto_bcdc_cmplt(struct brcmf_pub *drvr, u32 id, u32 len)
0139 {
0140 int ret;
0141 struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd;
0142
0143 brcmf_dbg(BCDC, "Enter\n");
0144 len += sizeof(struct brcmf_proto_bcdc_dcmd);
0145 do {
0146 ret = brcmf_bus_rxctl(drvr->bus_if, (unsigned char *)&bcdc->msg,
0147 len);
0148 if (ret < 0)
0149 break;
0150 } while (BCDC_DCMD_ID(le32_to_cpu(bcdc->msg.flags)) != id);
0151
0152 return ret;
0153 }
0154
0155 static int
0156 brcmf_proto_bcdc_query_dcmd(struct brcmf_pub *drvr, int ifidx, uint cmd,
0157 void *buf, uint len, int *fwerr)
0158 {
0159 struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd;
0160 struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg;
0161 void *info;
0162 int ret = 0, retries = 0;
0163 u32 id, flags;
0164
0165 brcmf_dbg(BCDC, "Enter, cmd %d len %d\n", cmd, len);
0166
0167 *fwerr = 0;
0168 ret = brcmf_proto_bcdc_msg(drvr, ifidx, cmd, buf, len, false);
0169 if (ret < 0) {
0170 bphy_err(drvr, "brcmf_proto_bcdc_msg failed w/status %d\n",
0171 ret);
0172 goto done;
0173 }
0174
0175 retry:
0176
0177 ret = brcmf_proto_bcdc_cmplt(drvr, bcdc->reqid, len);
0178 if (ret < 0)
0179 goto done;
0180
0181 flags = le32_to_cpu(msg->flags);
0182 id = (flags & BCDC_DCMD_ID_MASK) >> BCDC_DCMD_ID_SHIFT;
0183
0184 if ((id < bcdc->reqid) && (++retries < RETRIES))
0185 goto retry;
0186 if (id != bcdc->reqid) {
0187 bphy_err(drvr, "%s: unexpected request id %d (expected %d)\n",
0188 brcmf_ifname(brcmf_get_ifp(drvr, ifidx)), id,
0189 bcdc->reqid);
0190 ret = -EINVAL;
0191 goto done;
0192 }
0193
0194
0195 info = (void *)&bcdc->buf[0];
0196
0197
0198 if (buf) {
0199 if (ret < (int)len)
0200 len = ret;
0201 memcpy(buf, info, len);
0202 }
0203
0204 ret = 0;
0205
0206
0207 if (flags & BCDC_DCMD_ERROR)
0208 *fwerr = le32_to_cpu(msg->status);
0209 done:
0210 return ret;
0211 }
0212
0213 static int
0214 brcmf_proto_bcdc_set_dcmd(struct brcmf_pub *drvr, int ifidx, uint cmd,
0215 void *buf, uint len, int *fwerr)
0216 {
0217 struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd;
0218 struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg;
0219 int ret;
0220 u32 flags, id;
0221
0222 brcmf_dbg(BCDC, "Enter, cmd %d len %d\n", cmd, len);
0223
0224 *fwerr = 0;
0225 ret = brcmf_proto_bcdc_msg(drvr, ifidx, cmd, buf, len, true);
0226 if (ret < 0)
0227 goto done;
0228
0229 ret = brcmf_proto_bcdc_cmplt(drvr, bcdc->reqid, len);
0230 if (ret < 0)
0231 goto done;
0232
0233 flags = le32_to_cpu(msg->flags);
0234 id = (flags & BCDC_DCMD_ID_MASK) >> BCDC_DCMD_ID_SHIFT;
0235
0236 if (id != bcdc->reqid) {
0237 bphy_err(drvr, "%s: unexpected request id %d (expected %d)\n",
0238 brcmf_ifname(brcmf_get_ifp(drvr, ifidx)), id,
0239 bcdc->reqid);
0240 ret = -EINVAL;
0241 goto done;
0242 }
0243
0244 ret = 0;
0245
0246
0247 if (flags & BCDC_DCMD_ERROR)
0248 *fwerr = le32_to_cpu(msg->status);
0249
0250 done:
0251 return ret;
0252 }
0253
0254 static void
0255 brcmf_proto_bcdc_hdrpush(struct brcmf_pub *drvr, int ifidx, u8 offset,
0256 struct sk_buff *pktbuf)
0257 {
0258 struct brcmf_proto_bcdc_header *h;
0259
0260 brcmf_dbg(BCDC, "Enter\n");
0261
0262
0263 skb_push(pktbuf, BCDC_HEADER_LEN);
0264
0265 h = (struct brcmf_proto_bcdc_header *)(pktbuf->data);
0266
0267 h->flags = (BCDC_PROTO_VER << BCDC_FLAG_VER_SHIFT);
0268 if (pktbuf->ip_summed == CHECKSUM_PARTIAL)
0269 h->flags |= BCDC_FLAG_SUM_NEEDED;
0270
0271 h->priority = (pktbuf->priority & BCDC_PRIORITY_MASK);
0272 h->flags2 = 0;
0273 h->data_offset = offset;
0274 BCDC_SET_IF_IDX(h, ifidx);
0275 trace_brcmf_bcdchdr(pktbuf->data);
0276 }
0277
0278 static int
0279 brcmf_proto_bcdc_hdrpull(struct brcmf_pub *drvr, bool do_fws,
0280 struct sk_buff *pktbuf, struct brcmf_if **ifp)
0281 {
0282 struct brcmf_proto_bcdc_header *h;
0283 struct brcmf_if *tmp_if;
0284
0285 brcmf_dbg(BCDC, "Enter\n");
0286
0287
0288 if (pktbuf->len <= BCDC_HEADER_LEN) {
0289 brcmf_dbg(INFO, "rx data too short (%d <= %d)\n",
0290 pktbuf->len, BCDC_HEADER_LEN);
0291 return -EBADE;
0292 }
0293
0294 trace_brcmf_bcdchdr(pktbuf->data);
0295 h = (struct brcmf_proto_bcdc_header *)(pktbuf->data);
0296
0297 tmp_if = brcmf_get_ifp(drvr, BCDC_GET_IF_IDX(h));
0298 if (!tmp_if) {
0299 brcmf_dbg(INFO, "no matching ifp found\n");
0300 return -EBADE;
0301 }
0302 if (((h->flags & BCDC_FLAG_VER_MASK) >> BCDC_FLAG_VER_SHIFT) !=
0303 BCDC_PROTO_VER) {
0304 bphy_err(drvr, "%s: non-BCDC packet received, flags 0x%x\n",
0305 brcmf_ifname(tmp_if), h->flags);
0306 return -EBADE;
0307 }
0308
0309 if (h->flags & BCDC_FLAG_SUM_GOOD) {
0310 brcmf_dbg(BCDC, "%s: BDC rcv, good checksum, flags 0x%x\n",
0311 brcmf_ifname(tmp_if), h->flags);
0312 pktbuf->ip_summed = CHECKSUM_UNNECESSARY;
0313 }
0314
0315 pktbuf->priority = h->priority & BCDC_PRIORITY_MASK;
0316
0317 skb_pull(pktbuf, BCDC_HEADER_LEN);
0318 if (do_fws)
0319 brcmf_fws_hdrpull(tmp_if, h->data_offset << 2, pktbuf);
0320 else
0321 skb_pull(pktbuf, h->data_offset << 2);
0322
0323 if (pktbuf->len == 0)
0324 return -ENODATA;
0325
0326 if (ifp != NULL)
0327 *ifp = tmp_if;
0328 return 0;
0329 }
0330
0331 static int brcmf_proto_bcdc_tx_queue_data(struct brcmf_pub *drvr, int ifidx,
0332 struct sk_buff *skb)
0333 {
0334 struct brcmf_if *ifp = brcmf_get_ifp(drvr, ifidx);
0335 struct brcmf_bcdc *bcdc = drvr->proto->pd;
0336
0337 if (!brcmf_fws_queue_skbs(bcdc->fws))
0338 return brcmf_proto_txdata(drvr, ifidx, 0, skb);
0339
0340 return brcmf_fws_process_skb(ifp, skb);
0341 }
0342
0343 static int
0344 brcmf_proto_bcdc_txdata(struct brcmf_pub *drvr, int ifidx, u8 offset,
0345 struct sk_buff *pktbuf)
0346 {
0347 brcmf_proto_bcdc_hdrpush(drvr, ifidx, offset, pktbuf);
0348 return brcmf_bus_txdata(drvr->bus_if, pktbuf);
0349 }
0350
0351 void brcmf_proto_bcdc_txflowblock(struct device *dev, bool state)
0352 {
0353 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
0354 struct brcmf_pub *drvr = bus_if->drvr;
0355
0356 brcmf_dbg(TRACE, "Enter\n");
0357
0358 brcmf_fws_bus_blocked(drvr, state);
0359 }
0360
0361 void
0362 brcmf_proto_bcdc_txcomplete(struct device *dev, struct sk_buff *txp,
0363 bool success)
0364 {
0365 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
0366 struct brcmf_bcdc *bcdc = bus_if->drvr->proto->pd;
0367 struct brcmf_if *ifp;
0368
0369
0370 if (brcmf_fws_fc_active(bcdc->fws)) {
0371 if (!success)
0372 brcmf_fws_bustxfail(bcdc->fws, txp);
0373 } else {
0374 if (brcmf_proto_bcdc_hdrpull(bus_if->drvr, false, txp, &ifp))
0375 brcmu_pkt_buf_free_skb(txp);
0376 else
0377 brcmf_txfinalize(ifp, txp, success);
0378 }
0379 }
0380
0381 static void
0382 brcmf_proto_bcdc_configure_addr_mode(struct brcmf_pub *drvr, int ifidx,
0383 enum proto_addr_mode addr_mode)
0384 {
0385 }
0386
0387 static void
0388 brcmf_proto_bcdc_delete_peer(struct brcmf_pub *drvr, int ifidx,
0389 u8 peer[ETH_ALEN])
0390 {
0391 }
0392
0393 static void
0394 brcmf_proto_bcdc_add_tdls_peer(struct brcmf_pub *drvr, int ifidx,
0395 u8 peer[ETH_ALEN])
0396 {
0397 }
0398
0399 static void brcmf_proto_bcdc_rxreorder(struct brcmf_if *ifp,
0400 struct sk_buff *skb)
0401 {
0402 brcmf_fws_rxreorder(ifp, skb);
0403 }
0404
0405 static void
0406 brcmf_proto_bcdc_add_if(struct brcmf_if *ifp)
0407 {
0408 brcmf_fws_add_interface(ifp);
0409 }
0410
0411 static void
0412 brcmf_proto_bcdc_del_if(struct brcmf_if *ifp)
0413 {
0414 brcmf_fws_del_interface(ifp);
0415 }
0416
0417 static void
0418 brcmf_proto_bcdc_reset_if(struct brcmf_if *ifp)
0419 {
0420 brcmf_fws_reset_interface(ifp);
0421 }
0422
0423 static int
0424 brcmf_proto_bcdc_init_done(struct brcmf_pub *drvr)
0425 {
0426 struct brcmf_bcdc *bcdc = drvr->proto->pd;
0427 struct brcmf_fws_info *fws;
0428
0429 fws = brcmf_fws_attach(drvr);
0430 if (IS_ERR(fws))
0431 return PTR_ERR(fws);
0432
0433 bcdc->fws = fws;
0434 return 0;
0435 }
0436
0437 static void brcmf_proto_bcdc_debugfs_create(struct brcmf_pub *drvr)
0438 {
0439 brcmf_fws_debugfs_create(drvr);
0440 }
0441
0442 int brcmf_proto_bcdc_attach(struct brcmf_pub *drvr)
0443 {
0444 struct brcmf_bcdc *bcdc;
0445
0446 bcdc = kzalloc(sizeof(*bcdc), GFP_ATOMIC);
0447 if (!bcdc)
0448 goto fail;
0449
0450
0451 if ((unsigned long)(&bcdc->msg + 1) != (unsigned long)bcdc->buf) {
0452 bphy_err(drvr, "struct brcmf_proto_bcdc is not correctly defined\n");
0453 goto fail;
0454 }
0455
0456 drvr->proto->hdrpull = brcmf_proto_bcdc_hdrpull;
0457 drvr->proto->query_dcmd = brcmf_proto_bcdc_query_dcmd;
0458 drvr->proto->set_dcmd = brcmf_proto_bcdc_set_dcmd;
0459 drvr->proto->tx_queue_data = brcmf_proto_bcdc_tx_queue_data;
0460 drvr->proto->txdata = brcmf_proto_bcdc_txdata;
0461 drvr->proto->configure_addr_mode = brcmf_proto_bcdc_configure_addr_mode;
0462 drvr->proto->delete_peer = brcmf_proto_bcdc_delete_peer;
0463 drvr->proto->add_tdls_peer = brcmf_proto_bcdc_add_tdls_peer;
0464 drvr->proto->rxreorder = brcmf_proto_bcdc_rxreorder;
0465 drvr->proto->add_if = brcmf_proto_bcdc_add_if;
0466 drvr->proto->del_if = brcmf_proto_bcdc_del_if;
0467 drvr->proto->reset_if = brcmf_proto_bcdc_reset_if;
0468 drvr->proto->init_done = brcmf_proto_bcdc_init_done;
0469 drvr->proto->debugfs_create = brcmf_proto_bcdc_debugfs_create;
0470 drvr->proto->pd = bcdc;
0471
0472 drvr->hdrlen += BCDC_HEADER_LEN + BRCMF_PROT_FW_SIGNAL_MAX_TXBYTES;
0473 drvr->bus_if->maxctl = BRCMF_DCMD_MAXLEN +
0474 sizeof(struct brcmf_proto_bcdc_dcmd);
0475 return 0;
0476
0477 fail:
0478 kfree(bcdc);
0479 return -ENOMEM;
0480 }
0481
0482 void brcmf_proto_bcdc_detach(struct brcmf_pub *drvr)
0483 {
0484 struct brcmf_bcdc *bcdc = drvr->proto->pd;
0485
0486 drvr->proto->pd = NULL;
0487 brcmf_fws_detach(bcdc->fws);
0488 kfree(bcdc);
0489 }