xref: /OK3568_Linux_fs/external/rkwifibt/drivers/infineon/include/bcmcdc.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * CDC network driver ioctl/indication encoding
3*4882a593Smuzhiyun  * Broadcom 802.11abg Networking Device Driver
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Definitions subject to change without notice.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Portions of this code are copyright (c) 2021 Cypress Semiconductor Corporation
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * Copyright (C) 1999-2017, Broadcom Corporation
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  *      Unless you and Broadcom execute a separate written software license
12*4882a593Smuzhiyun  * agreement governing use of this software, this software is licensed to you
13*4882a593Smuzhiyun  * under the terms of the GNU General Public License version 2 (the "GPL"),
14*4882a593Smuzhiyun  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
15*4882a593Smuzhiyun  * following added to such license:
16*4882a593Smuzhiyun  *
17*4882a593Smuzhiyun  *      As a special exception, the copyright holders of this software give you
18*4882a593Smuzhiyun  * permission to link this software with independent modules, and to copy and
19*4882a593Smuzhiyun  * distribute the resulting executable under terms of your choice, provided that
20*4882a593Smuzhiyun  * you also meet, for each linked independent module, the terms and conditions of
21*4882a593Smuzhiyun  * the license of that module.  An independent module is a module which is not
22*4882a593Smuzhiyun  * derived from this software.  The special exception does not apply to any
23*4882a593Smuzhiyun  * modifications of the software.
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  *      Notwithstanding the above, under no circumstances may you combine this
26*4882a593Smuzhiyun  * software in any way with any other Broadcom software provided under a license
27*4882a593Smuzhiyun  * other than the GPL, without Broadcom's express prior written consent.
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  * <<Broadcom-WL-IPTag/Open:>>
31*4882a593Smuzhiyun  *
32*4882a593Smuzhiyun  * $Id$
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun #ifndef _bcmcdc_h_
35*4882a593Smuzhiyun #define	_bcmcdc_h_
36*4882a593Smuzhiyun #include <ethernet.h>
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun typedef struct cdc_ioctl {
39*4882a593Smuzhiyun 	uint32 cmd;      /* ioctl command value */
40*4882a593Smuzhiyun 	uint32 len;      /* lower 16: output buflen; upper 16: input buflen (excludes header) */
41*4882a593Smuzhiyun 	uint32 flags;    /* flag defns given below */
42*4882a593Smuzhiyun 	uint32 status;   /* status code returned from the device */
43*4882a593Smuzhiyun } cdc_ioctl_t;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /* Max valid buffer size that can be sent to the dongle */
46*4882a593Smuzhiyun #define CDC_MAX_MSG_SIZE   ETHER_MAX_LEN
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun /* len field is divided into input and output buffer lengths */
49*4882a593Smuzhiyun #define CDCL_IOC_OUTLEN_MASK   0x0000FFFF  /* maximum or expected response length, */
50*4882a593Smuzhiyun 					   /* excluding IOCTL header */
51*4882a593Smuzhiyun #define CDCL_IOC_OUTLEN_SHIFT  0
52*4882a593Smuzhiyun #define CDCL_IOC_INLEN_MASK    0xFFFF0000   /* input buffer length, excluding IOCTL header */
53*4882a593Smuzhiyun #define CDCL_IOC_INLEN_SHIFT   16
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun /* CDC flag definitions */
56*4882a593Smuzhiyun #define CDCF_IOC_ERROR		0x01	/* 0=success, 1=ioctl cmd failed */
57*4882a593Smuzhiyun #define CDCF_IOC_SET		0x02	/* 0=get, 1=set cmd */
58*4882a593Smuzhiyun #define CDCF_IOC_OVL_IDX_MASK	0x3c	/* overlay region index mask */
59*4882a593Smuzhiyun #define CDCF_IOC_OVL_RSV	0x40	/* 1=reserve this overlay region */
60*4882a593Smuzhiyun #define CDCF_IOC_OVL		0x80	/* 1=this ioctl corresponds to an overlay */
61*4882a593Smuzhiyun #define CDCF_IOC_ACTION_MASK	0xfe	/* SET/GET, OVL_IDX, OVL_RSV, OVL mask */
62*4882a593Smuzhiyun #define CDCF_IOC_ACTION_SHIFT	1	/* SET/GET, OVL_IDX, OVL_RSV, OVL shift */
63*4882a593Smuzhiyun #define CDCF_IOC_IF_MASK	0xF000	/* I/F index */
64*4882a593Smuzhiyun #define CDCF_IOC_IF_SHIFT	12
65*4882a593Smuzhiyun #define CDCF_IOC_ID_MASK	0xFFFF0000	/* used to uniquely id an ioctl req/resp pairing */
66*4882a593Smuzhiyun #define CDCF_IOC_ID_SHIFT	16		/* # of bits of shift for ID Mask */
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun #define CDC_IOC_IF_IDX(flags)	(((flags) & CDCF_IOC_IF_MASK) >> CDCF_IOC_IF_SHIFT)
69*4882a593Smuzhiyun #define CDC_IOC_ID(flags)	(((flags) & CDCF_IOC_ID_MASK) >> CDCF_IOC_ID_SHIFT)
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun #define CDC_GET_IF_IDX(hdr) \
72*4882a593Smuzhiyun 	((int)((((hdr)->flags) & CDCF_IOC_IF_MASK) >> CDCF_IOC_IF_SHIFT))
73*4882a593Smuzhiyun #define CDC_SET_IF_IDX(hdr, idx) \
74*4882a593Smuzhiyun 	((hdr)->flags = (((hdr)->flags & ~CDCF_IOC_IF_MASK) | ((idx) << CDCF_IOC_IF_SHIFT)))
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun /*
77*4882a593Smuzhiyun  * BDC header
78*4882a593Smuzhiyun  *
79*4882a593Smuzhiyun  *   The BDC header is used on data packets to convey priority across USB.
80*4882a593Smuzhiyun  */
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun struct bdc_header {
83*4882a593Smuzhiyun 	uint8	flags;			/* Flags */
84*4882a593Smuzhiyun 	uint8	priority;		/* 802.1d Priority 0:2 bits, 4:7 USB flow control info */
85*4882a593Smuzhiyun 	uint8	flags2;
86*4882a593Smuzhiyun 	uint8	dataOffset;		/* Offset from end of BDC header to packet data, in
87*4882a593Smuzhiyun 					 * 4-byte words.  Leaves room for optional headers.
88*4882a593Smuzhiyun 					 */
89*4882a593Smuzhiyun };
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun #define	BDC_HEADER_LEN		4
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun /* flags field bitmap */
94*4882a593Smuzhiyun #define BDC_FLAG_EXEMPT		0x03	/* EXT_STA: encryption exemption (host -> dongle?) */
95*4882a593Smuzhiyun #define BDC_FLAG_80211_PKT	0x01	/* Packet is in 802.11 format (dongle -> host) */
96*4882a593Smuzhiyun #define BDC_FLAG_SUM_GOOD	0x04	/* Dongle has verified good RX checksums */
97*4882a593Smuzhiyun #define BDC_FLAG_SUM_NEEDED	0x08	/* Dongle needs to do TX checksums: host->device */
98*4882a593Smuzhiyun #define BDC_FLAG_EVENT_MSG	0x08	/* Payload contains an event msg: device->host */
99*4882a593Smuzhiyun #define BDC_FLAG_VER_MASK	0xf0	/* Protocol version mask */
100*4882a593Smuzhiyun #define BDC_FLAG_VER_SHIFT	4	/* Protocol version shift */
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun /* priority field bitmap */
103*4882a593Smuzhiyun #define BDC_PRIORITY_MASK	0x07
104*4882a593Smuzhiyun #define BDC_PRIORITY_FC_MASK	0xf0	/* flow control info mask */
105*4882a593Smuzhiyun #define BDC_PRIORITY_FC_SHIFT	4	/* flow control info shift */
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun /* flags2 field bitmap */
108*4882a593Smuzhiyun #define BDC_FLAG2_IF_MASK	0x0f	/* interface index (host <-> dongle) */
109*4882a593Smuzhiyun #define BDC_FLAG2_IF_SHIFT	0
110*4882a593Smuzhiyun #define BDC_FLAG2_FC_FLAG	0x10	/* flag to indicate if pkt contains */
111*4882a593Smuzhiyun 					/* FLOW CONTROL info only */
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun /* version numbers */
114*4882a593Smuzhiyun #define BDC_PROTO_VER_1		1	/* Old Protocol version */
115*4882a593Smuzhiyun #define BDC_PROTO_VER		2	/* Protocol version */
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun /* flags2.if field access macros */
118*4882a593Smuzhiyun #define BDC_GET_IF_IDX(hdr) \
119*4882a593Smuzhiyun 	((int)((((hdr)->flags2) & BDC_FLAG2_IF_MASK) >> BDC_FLAG2_IF_SHIFT))
120*4882a593Smuzhiyun #define BDC_SET_IF_IDX(hdr, idx) \
121*4882a593Smuzhiyun 	((hdr)->flags2 = (((hdr)->flags2 & ~BDC_FLAG2_IF_MASK) | ((idx) << BDC_FLAG2_IF_SHIFT)))
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun #endif /* _bcmcdc_h_ */
124