| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2010 Broadcom Corporation | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Permission to use, copy, modify, and/or distribute this software for any | 
					
						
							|  |  |  |  * purpose with or without fee is hereby granted, provided that the above | 
					
						
							|  |  |  |  * copyright notice and this permission notice appear in all copies. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 
					
						
							|  |  |  |  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 
					
						
							|  |  |  |  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | 
					
						
							|  |  |  |  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 
					
						
							|  |  |  |  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | 
					
						
							|  |  |  |  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | 
					
						
							|  |  |  |  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*******************************************************************************
 | 
					
						
							|  |  |  |  * Communicates with the dongle by using dcmd codes. | 
					
						
							|  |  |  |  * For certain dcmd codes, the dongle interprets string data from the host. | 
					
						
							|  |  |  |  ******************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/types.h>
 | 
					
						
							|  |  |  | #include <linux/netdevice.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <brcmu_utils.h>
 | 
					
						
							|  |  |  | #include <brcmu_wifi.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "dhd.h"
 | 
					
						
							|  |  |  | #include "dhd_bus.h"
 | 
					
						
							| 
									
										
										
										
											2013-03-03 12:45:28 +01:00
										 |  |  | #include "fwsignal.h"
 | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | #include "dhd_dbg.h"
 | 
					
						
							| 
									
										
										
										
											2013-06-06 13:18:05 +02:00
										 |  |  | #include "tracepoint.h"
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | #include "proto.h"
 | 
					
						
							|  |  |  | #include "bcdc.h"
 | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | struct brcmf_proto_bcdc_dcmd { | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	__le32 cmd;	/* dongle command value */ | 
					
						
							|  |  |  | 	__le32 len;	/* lower 16: output buflen;
 | 
					
						
							|  |  |  | 			 * upper 16: input buflen (excludes header) */ | 
					
						
							|  |  |  | 	__le32 flags;	/* flag defns given below */ | 
					
						
							|  |  |  | 	__le32 status;	/* status code returned from the device */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | /* BCDC flag definitions */ | 
					
						
							|  |  |  | #define BCDC_DCMD_ERROR		0x01		/* 1=cmd failed */
 | 
					
						
							|  |  |  | #define BCDC_DCMD_SET		0x02		/* 0=get, 1=set cmd */
 | 
					
						
							|  |  |  | #define BCDC_DCMD_IF_MASK	0xF000		/* I/F index */
 | 
					
						
							|  |  |  | #define BCDC_DCMD_IF_SHIFT	12
 | 
					
						
							|  |  |  | #define BCDC_DCMD_ID_MASK	0xFFFF0000	/* id an cmd pairing */
 | 
					
						
							|  |  |  | #define BCDC_DCMD_ID_SHIFT	16		/* ID Mask shift bits */
 | 
					
						
							|  |  |  | #define BCDC_DCMD_ID(flags)	\
 | 
					
						
							|  |  |  | 	(((flags) & BCDC_DCMD_ID_MASK) >> BCDC_DCMD_ID_SHIFT) | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  |  * BCDC header - Broadcom specific extension of CDC. | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  |  * Used on data packets to convey priority across USB. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | #define	BCDC_HEADER_LEN		4
 | 
					
						
							|  |  |  | #define BCDC_PROTO_VER		2	/* Protocol version */
 | 
					
						
							|  |  |  | #define BCDC_FLAG_VER_MASK	0xf0	/* Protocol version mask */
 | 
					
						
							|  |  |  | #define BCDC_FLAG_VER_SHIFT	4	/* Protocol version shift */
 | 
					
						
							|  |  |  | #define BCDC_FLAG_SUM_GOOD	0x04	/* Good RX checksums */
 | 
					
						
							|  |  |  | #define BCDC_FLAG_SUM_NEEDED	0x08	/* Dongle needs to do TX checksums */
 | 
					
						
							|  |  |  | #define BCDC_PRIORITY_MASK	0x7
 | 
					
						
							|  |  |  | #define BCDC_FLAG2_IF_MASK	0x0f	/* packet rx interface in APSTA */
 | 
					
						
							|  |  |  | #define BCDC_FLAG2_IF_SHIFT	0
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define BCDC_GET_IF_IDX(hdr) \
 | 
					
						
							|  |  |  | 	((int)((((hdr)->flags2) & BCDC_FLAG2_IF_MASK) >> BCDC_FLAG2_IF_SHIFT)) | 
					
						
							|  |  |  | #define BCDC_SET_IF_IDX(hdr, idx) \
 | 
					
						
							|  |  |  | 	((hdr)->flags2 = (((hdr)->flags2 & ~BCDC_FLAG2_IF_MASK) | \ | 
					
						
							|  |  |  | 	((idx) << BCDC_FLAG2_IF_SHIFT))) | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-03 12:45:26 +01:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  |  * struct brcmf_proto_bcdc_header - BCDC header format | 
					
						
							| 
									
										
										
										
											2013-03-03 12:45:26 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @flags: flags contain protocol and checksum info. | 
					
						
							|  |  |  |  * @priority: 802.1d priority and USB flow control info (bit 4:7). | 
					
						
							|  |  |  |  * @flags2: additional flags containing dongle interface index. | 
					
						
							|  |  |  |  * @data_offset: start of packet data. header is following by firmware signals. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | struct brcmf_proto_bcdc_header { | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	u8 flags; | 
					
						
							| 
									
										
										
										
											2013-03-03 12:45:26 +01:00
										 |  |  | 	u8 priority; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	u8 flags2; | 
					
						
							| 
									
										
										
										
											2011-12-08 15:06:38 -08:00
										 |  |  | 	u8 data_offset; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-03 12:45:26 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * maximum length of firmware signal data between | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  |  * the BCDC header and packet data in the tx path. | 
					
						
							| 
									
										
										
										
											2013-03-03 12:45:26 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | #define BRCMF_PROT_FW_SIGNAL_MAX_TXBYTES	12
 | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define RETRIES 2 /* # of retries to retrieve matching dcmd response */
 | 
					
						
							| 
									
										
										
										
											2011-12-16 18:37:11 -08:00
										 |  |  | #define BUS_HEADER_LEN	(16+64)		/* Must be atleast SDPCM_RESERVE
 | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 					 * (amount of header tha might be added) | 
					
						
							|  |  |  | 					 * plus any space that might be needed | 
					
						
							| 
									
										
										
										
											2011-12-16 18:37:11 -08:00
										 |  |  | 					 * for bus alignment padding. | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 					 */ | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | struct brcmf_bcdc { | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	u16 reqid; | 
					
						
							|  |  |  | 	u8 bus_header[BUS_HEADER_LEN]; | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	struct brcmf_proto_bcdc_dcmd msg; | 
					
						
							| 
									
										
										
										
											2013-12-12 11:59:00 +01:00
										 |  |  | 	unsigned char buf[BRCMF_DCMD_MAXLEN]; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-12 11:59:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | brcmf_proto_bcdc_msg(struct brcmf_pub *drvr, int ifidx, uint cmd, void *buf, | 
					
						
							|  |  |  | 		     uint len, bool set) | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 	struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd; | 
					
						
							| 
									
										
										
										
											2013-12-12 11:59:00 +01:00
										 |  |  | 	struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg; | 
					
						
							|  |  |  | 	u32 flags; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	brcmf_dbg(BCDC, "Enter\n"); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-12 11:59:00 +01:00
										 |  |  | 	memset(msg, 0, sizeof(struct brcmf_proto_bcdc_dcmd)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	msg->cmd = cpu_to_le32(cmd); | 
					
						
							|  |  |  | 	msg->len = cpu_to_le32(len); | 
					
						
							|  |  |  | 	flags = (++bcdc->reqid << BCDC_DCMD_ID_SHIFT); | 
					
						
							|  |  |  | 	if (set) | 
					
						
							|  |  |  | 		flags |= BCDC_DCMD_SET; | 
					
						
							|  |  |  | 	flags = (flags & ~BCDC_DCMD_IF_MASK) | | 
					
						
							|  |  |  | 		(ifidx << BCDC_DCMD_IF_SHIFT); | 
					
						
							|  |  |  | 	msg->flags = cpu_to_le32(flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (buf) | 
					
						
							|  |  |  | 		memcpy(bcdc->buf, buf, len); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-06 12:40:38 +01:00
										 |  |  | 	len += sizeof(*msg); | 
					
						
							|  |  |  | 	if (len > BRCMF_TX_IOCTL_MAX_MSG_SIZE) | 
					
						
							|  |  |  | 		len = BRCMF_TX_IOCTL_MAX_MSG_SIZE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	/* Send request */ | 
					
						
							| 
									
										
										
										
											2014-01-06 12:40:38 +01:00
										 |  |  | 	return brcmf_bus_txctl(drvr->bus_if, (unsigned char *)&bcdc->msg, len); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | static int brcmf_proto_bcdc_cmplt(struct brcmf_pub *drvr, u32 id, u32 len) | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	int ret; | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 	struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	brcmf_dbg(BCDC, "Enter\n"); | 
					
						
							|  |  |  | 	len += sizeof(struct brcmf_proto_bcdc_dcmd); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	do { | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 		ret = brcmf_bus_rxctl(drvr->bus_if, (unsigned char *)&bcdc->msg, | 
					
						
							| 
									
										
										
										
											2012-12-05 15:25:54 +01:00
										 |  |  | 				      len); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 		if (ret < 0) | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	} while (BCDC_DCMD_ID(le32_to_cpu(bcdc->msg.flags)) != id); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | static int | 
					
						
							|  |  |  | brcmf_proto_bcdc_query_dcmd(struct brcmf_pub *drvr, int ifidx, uint cmd, | 
					
						
							|  |  |  | 			    void *buf, uint len) | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 	struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd; | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	void *info; | 
					
						
							|  |  |  | 	int ret = 0, retries = 0; | 
					
						
							|  |  |  | 	u32 id, flags; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	brcmf_dbg(BCDC, "Enter, cmd %d len %d\n", cmd, len); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-12 11:59:00 +01:00
										 |  |  | 	ret = brcmf_proto_bcdc_msg(drvr, ifidx, cmd, buf, len, false); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	if (ret < 0) { | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 		brcmf_err("brcmf_proto_bcdc_msg failed w/status %d\n", | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 			  ret); | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | retry: | 
					
						
							|  |  |  | 	/* wait for interrupt and get first fragment */ | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	ret = brcmf_proto_bcdc_cmplt(drvr, bcdc->reqid, len); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	if (ret < 0) | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	flags = le32_to_cpu(msg->flags); | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	id = (flags & BCDC_DCMD_ID_MASK) >> BCDC_DCMD_ID_SHIFT; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 	if ((id < bcdc->reqid) && (++retries < RETRIES)) | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 		goto retry; | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 	if (id != bcdc->reqid) { | 
					
						
							| 
									
										
										
										
											2012-12-07 10:49:57 +01:00
										 |  |  | 		brcmf_err("%s: unexpected request id %d (expected %d)\n", | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 			  brcmf_ifname(drvr, ifidx), id, bcdc->reqid); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 		ret = -EINVAL; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Check info buffer */ | 
					
						
							|  |  |  | 	info = (void *)&msg[1]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Copy info buffer */ | 
					
						
							|  |  |  | 	if (buf) { | 
					
						
							|  |  |  | 		if (ret < (int)len) | 
					
						
							|  |  |  | 			len = ret; | 
					
						
							|  |  |  | 		memcpy(buf, info, len); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Check the ERROR flag */ | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	if (flags & BCDC_DCMD_ERROR) | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 		ret = le32_to_cpu(msg->status); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | done: | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | static int | 
					
						
							|  |  |  | brcmf_proto_bcdc_set_dcmd(struct brcmf_pub *drvr, int ifidx, uint cmd, | 
					
						
							|  |  |  | 			  void *buf, uint len) | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 	struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd; | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	int ret = 0; | 
					
						
							|  |  |  | 	u32 flags, id; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	brcmf_dbg(BCDC, "Enter, cmd %d len %d\n", cmd, len); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-12 11:59:00 +01:00
										 |  |  | 	ret = brcmf_proto_bcdc_msg(drvr, ifidx, cmd, buf, len, true); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	if (ret < 0) | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	ret = brcmf_proto_bcdc_cmplt(drvr, bcdc->reqid, len); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	if (ret < 0) | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	flags = le32_to_cpu(msg->flags); | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	id = (flags & BCDC_DCMD_ID_MASK) >> BCDC_DCMD_ID_SHIFT; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 	if (id != bcdc->reqid) { | 
					
						
							| 
									
										
										
										
											2012-12-07 10:49:57 +01:00
										 |  |  | 		brcmf_err("%s: unexpected request id %d (expected %d)\n", | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 			  brcmf_ifname(drvr, ifidx), id, bcdc->reqid); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 		ret = -EINVAL; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Check the ERROR flag */ | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	if (flags & BCDC_DCMD_ERROR) | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 		ret = le32_to_cpu(msg->status); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | done: | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | static void | 
					
						
							|  |  |  | brcmf_proto_bcdc_hdrpush(struct brcmf_pub *drvr, int ifidx, u8 offset, | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 			 struct sk_buff *pktbuf) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	struct brcmf_proto_bcdc_header *h; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	brcmf_dbg(BCDC, "Enter\n"); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Push BDC header used to convey priority for buses that don't */ | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	skb_push(pktbuf, BCDC_HEADER_LEN); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	h = (struct brcmf_proto_bcdc_header *)(pktbuf->data); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	h->flags = (BCDC_PROTO_VER << BCDC_FLAG_VER_SHIFT); | 
					
						
							|  |  |  | 	if (pktbuf->ip_summed == CHECKSUM_PARTIAL) | 
					
						
							|  |  |  | 		h->flags |= BCDC_FLAG_SUM_NEEDED; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	h->priority = (pktbuf->priority & BCDC_PRIORITY_MASK); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	h->flags2 = 0; | 
					
						
							| 
									
										
										
										
											2013-03-03 12:45:32 +01:00
										 |  |  | 	h->data_offset = offset; | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	BCDC_SET_IF_IDX(h, ifidx); | 
					
						
							|  |  |  | 	trace_brcmf_bcdchdr(pktbuf->data); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | static int | 
					
						
							|  |  |  | brcmf_proto_bcdc_hdrpull(struct brcmf_pub *drvr, bool do_fws, u8 *ifidx, | 
					
						
							|  |  |  | 			 struct sk_buff *pktbuf) | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	struct brcmf_proto_bcdc_header *h; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	brcmf_dbg(BCDC, "Enter\n"); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	/* Pop BCDC header used to convey priority for buses that don't */ | 
					
						
							|  |  |  | 	if (pktbuf->len <= BCDC_HEADER_LEN) { | 
					
						
							| 
									
										
										
										
											2013-04-03 12:40:43 +02:00
										 |  |  | 		brcmf_dbg(INFO, "rx data too short (%d <= %d)\n", | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 			  pktbuf->len, BCDC_HEADER_LEN); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 		return -EBADE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	trace_brcmf_bcdchdr(pktbuf->data); | 
					
						
							|  |  |  | 	h = (struct brcmf_proto_bcdc_header *)(pktbuf->data); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	*ifidx = BCDC_GET_IF_IDX(h); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	if (*ifidx >= BRCMF_MAX_IFS) { | 
					
						
							| 
									
										
										
										
											2012-12-07 10:49:57 +01:00
										 |  |  | 		brcmf_err("rx data ifnum out of range (%d)\n", *ifidx); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 		return -EBADE; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-02-08 12:06:31 +01:00
										 |  |  | 	/* The ifidx is the idx to map to matching netdev/ifp. When receiving
 | 
					
						
							|  |  |  | 	 * events this is easy because it contains the bssidx which maps | 
					
						
							|  |  |  | 	 * 1-on-1 to the netdev/ifp. But for data frames the ifidx is rcvd. | 
					
						
							|  |  |  | 	 * bssidx 1 is used for p2p0 and no data can be received or | 
					
						
							|  |  |  | 	 * transmitted on it. Therefor bssidx is ifidx + 1 if ifidx > 0 | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (*ifidx) | 
					
						
							|  |  |  | 		(*ifidx)++; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	if (((h->flags & BCDC_FLAG_VER_MASK) >> BCDC_FLAG_VER_SHIFT) != | 
					
						
							|  |  |  | 	    BCDC_PROTO_VER) { | 
					
						
							|  |  |  | 		brcmf_err("%s: non-BCDC packet received, flags 0x%x\n", | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 			  brcmf_ifname(drvr, *ifidx), h->flags); | 
					
						
							|  |  |  | 		return -EBADE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	if (h->flags & BCDC_FLAG_SUM_GOOD) { | 
					
						
							|  |  |  | 		brcmf_dbg(BCDC, "%s: BDC rcv, good checksum, flags 0x%x\n", | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 			  brcmf_ifname(drvr, *ifidx), h->flags); | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 		pktbuf->ip_summed = CHECKSUM_UNNECESSARY; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	pktbuf->priority = h->priority & BCDC_PRIORITY_MASK; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	skb_pull(pktbuf, BCDC_HEADER_LEN); | 
					
						
							| 
									
										
										
										
											2013-03-03 12:45:28 +01:00
										 |  |  | 	if (do_fws) | 
					
						
							|  |  |  | 		brcmf_fws_hdrpull(drvr, *ifidx, h->data_offset << 2, pktbuf); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		skb_pull(pktbuf, h->data_offset << 2); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-02 15:22:43 +01:00
										 |  |  | 	if (pktbuf->len == 0) | 
					
						
							|  |  |  | 		return -ENODATA; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-12 11:59:03 +01:00
										 |  |  | static int | 
					
						
							|  |  |  | brcmf_proto_bcdc_txdata(struct brcmf_pub *drvr, int ifidx, u8 offset, | 
					
						
							|  |  |  | 			struct sk_buff *pktbuf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	brcmf_proto_bcdc_hdrpush(drvr, ifidx, offset, pktbuf); | 
					
						
							|  |  |  | 	return brcmf_bus_txdata(drvr->bus_if, pktbuf); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | int brcmf_proto_bcdc_attach(struct brcmf_pub *drvr) | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 	struct brcmf_bcdc *bcdc; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 	bcdc = kzalloc(sizeof(*bcdc), GFP_ATOMIC); | 
					
						
							|  |  |  | 	if (!bcdc) | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 		goto fail; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ensure that the msg buf directly follows the cdc msg struct */ | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 	if ((unsigned long)(&bcdc->msg + 1) != (unsigned long)bcdc->buf) { | 
					
						
							|  |  |  | 		brcmf_err("struct brcmf_proto_bcdc is not correctly defined\n"); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 		goto fail; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 	drvr->proto->hdrpull = brcmf_proto_bcdc_hdrpull; | 
					
						
							|  |  |  | 	drvr->proto->query_dcmd = brcmf_proto_bcdc_query_dcmd; | 
					
						
							|  |  |  | 	drvr->proto->set_dcmd = brcmf_proto_bcdc_set_dcmd; | 
					
						
							| 
									
										
										
										
											2013-12-12 11:59:03 +01:00
										 |  |  | 	drvr->proto->txdata = brcmf_proto_bcdc_txdata; | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 	drvr->proto->pd = bcdc; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:21 +01:00
										 |  |  | 	drvr->hdrlen += BCDC_HEADER_LEN + BRCMF_PROT_FW_SIGNAL_MAX_TXBYTES; | 
					
						
							| 
									
										
										
										
											2011-12-16 18:37:03 -08:00
										 |  |  | 	drvr->bus_if->maxctl = BRCMF_DCMD_MAXLEN + | 
					
						
							| 
									
										
										
										
											2013-12-12 11:59:00 +01:00
										 |  |  | 			sizeof(struct brcmf_proto_bcdc_dcmd); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | fail: | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 	kfree(bcdc); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	return -ENOMEM; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | void brcmf_proto_bcdc_detach(struct brcmf_pub *drvr) | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:16 +01:00
										 |  |  | 	kfree(drvr->proto->pd); | 
					
						
							|  |  |  | 	drvr->proto->pd = NULL; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | } |