xref: /openbmc/u-boot/drivers/usb/gadget/rndis.h (revision fd0bc623)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * RNDIS	Definitions for Remote NDIS
4  *
5  * Authors:	Benedikt Spranger, Pengutronix
6  *		Robert Schwebel, Pengutronix
7  *
8  *		This software was originally developed in conformance with
9  *		Microsoft's Remote NDIS Specification License Agreement.
10  */
11 
12 #ifndef _USBGADGET_RNDIS_H
13 #define _USBGADGET_RNDIS_H
14 
15 #include "ndis.h"
16 
17 /*
18  * By default rndis_signal_disconnect does not send status message about
19  * RNDIS disconnection to USB host (indicated as cable disconnected).
20  * Define RNDIS_COMPLETE_SIGNAL_DISCONNECT to send it.
21  * However, this will cause 1 sec delay on Ethernet device halt.
22  * Usually you do not need to define it. Mostly usable for debugging.
23  */
24 
25 #define RNDIS_MAXIMUM_FRAME_SIZE	1518
26 #define RNDIS_MAX_TOTAL_SIZE		1558
27 
28 /* Remote NDIS Versions */
29 #define RNDIS_MAJOR_VERSION		1
30 #define RNDIS_MINOR_VERSION		0
31 
32 /* Status Values */
33 #define RNDIS_STATUS_SUCCESS		0x00000000U	/* Success           */
34 #define RNDIS_STATUS_FAILURE		0xC0000001U	/* Unspecified error */
35 #define RNDIS_STATUS_INVALID_DATA	0xC0010015U	/* Invalid data      */
36 #define RNDIS_STATUS_NOT_SUPPORTED	0xC00000BBU	/* Unsupported request */
37 #define RNDIS_STATUS_MEDIA_CONNECT	0x4001000BU	/* Device connected  */
38 #define RNDIS_STATUS_MEDIA_DISCONNECT	0x4001000CU	/* Device disconnected */
39 /*
40  * For all not specified status messages:
41  * RNDIS_STATUS_Xxx -> NDIS_STATUS_Xxx
42  */
43 
44 /* Message Set for Connectionless (802.3) Devices */
45 #define REMOTE_NDIS_PACKET_MSG		0x00000001U
46 #define REMOTE_NDIS_INITIALIZE_MSG	0x00000002U	/* Initialize device */
47 #define REMOTE_NDIS_HALT_MSG		0x00000003U
48 #define REMOTE_NDIS_QUERY_MSG		0x00000004U
49 #define REMOTE_NDIS_SET_MSG		0x00000005U
50 #define REMOTE_NDIS_RESET_MSG		0x00000006U
51 #define REMOTE_NDIS_INDICATE_STATUS_MSG	0x00000007U
52 #define REMOTE_NDIS_KEEPALIVE_MSG	0x00000008U
53 
54 /* Message completion */
55 #define REMOTE_NDIS_INITIALIZE_CMPLT	0x80000002U
56 #define REMOTE_NDIS_QUERY_CMPLT		0x80000004U
57 #define REMOTE_NDIS_SET_CMPLT		0x80000005U
58 #define REMOTE_NDIS_RESET_CMPLT		0x80000006U
59 #define REMOTE_NDIS_KEEPALIVE_CMPLT	0x80000008U
60 
61 /* Device Flags */
62 #define RNDIS_DF_CONNECTIONLESS		0x00000001U
63 #define RNDIS_DF_CONNECTION_ORIENTED	0x00000002U
64 
65 #define RNDIS_MEDIUM_802_3		0x00000000U
66 
67 /* from drivers/net/sk98lin/h/skgepnmi.h */
68 #define OID_PNP_CAPABILITIES			0xFD010100
69 #define OID_PNP_SET_POWER			0xFD010101
70 #define OID_PNP_QUERY_POWER			0xFD010102
71 #define OID_PNP_ADD_WAKE_UP_PATTERN		0xFD010103
72 #define OID_PNP_REMOVE_WAKE_UP_PATTERN		0xFD010104
73 #define OID_PNP_ENABLE_WAKE_UP			0xFD010106
74 
75 
76 typedef struct rndis_init_msg_type {
77 	__le32	MessageType;
78 	__le32	MessageLength;
79 	__le32	RequestID;
80 	__le32	MajorVersion;
81 	__le32	MinorVersion;
82 	__le32	MaxTransferSize;
83 } rndis_init_msg_type;
84 
85 typedef struct rndis_init_cmplt_type {
86 	__le32	MessageType;
87 	__le32	MessageLength;
88 	__le32	RequestID;
89 	__le32	Status;
90 	__le32	MajorVersion;
91 	__le32	MinorVersion;
92 	__le32	DeviceFlags;
93 	__le32	Medium;
94 	__le32	MaxPacketsPerTransfer;
95 	__le32	MaxTransferSize;
96 	__le32	PacketAlignmentFactor;
97 	__le32	AFListOffset;
98 	__le32	AFListSize;
99 } rndis_init_cmplt_type;
100 
101 typedef struct rndis_halt_msg_type {
102 	__le32	MessageType;
103 	__le32	MessageLength;
104 	__le32	RequestID;
105 } rndis_halt_msg_type;
106 
107 typedef struct rndis_query_msg_type {
108 	__le32	MessageType;
109 	__le32	MessageLength;
110 	__le32	RequestID;
111 	__le32	OID;
112 	__le32	InformationBufferLength;
113 	__le32	InformationBufferOffset;
114 	__le32	DeviceVcHandle;
115 } rndis_query_msg_type;
116 
117 typedef struct rndis_query_cmplt_type {
118 	__le32	MessageType;
119 	__le32	MessageLength;
120 	__le32	RequestID;
121 	__le32	Status;
122 	__le32	InformationBufferLength;
123 	__le32	InformationBufferOffset;
124 } rndis_query_cmplt_type;
125 
126 typedef struct rndis_set_msg_type {
127 	__le32	MessageType;
128 	__le32	MessageLength;
129 	__le32	RequestID;
130 	__le32	OID;
131 	__le32	InformationBufferLength;
132 	__le32	InformationBufferOffset;
133 	__le32	DeviceVcHandle;
134 } rndis_set_msg_type;
135 
136 typedef struct rndis_set_cmplt_type {
137 	__le32	MessageType;
138 	__le32	MessageLength;
139 	__le32	RequestID;
140 	__le32	Status;
141 } rndis_set_cmplt_type;
142 
143 typedef struct rndis_reset_msg_type {
144 	__le32	MessageType;
145 	__le32	MessageLength;
146 	__le32	Reserved;
147 } rndis_reset_msg_type;
148 
149 typedef struct rndis_reset_cmplt_type {
150 	__le32	MessageType;
151 	__le32	MessageLength;
152 	__le32	Status;
153 	__le32	AddressingReset;
154 } rndis_reset_cmplt_type;
155 
156 typedef struct rndis_indicate_status_msg_type {
157 	__le32	MessageType;
158 	__le32	MessageLength;
159 	__le32	Status;
160 	__le32	StatusBufferLength;
161 	__le32	StatusBufferOffset;
162 } rndis_indicate_status_msg_type;
163 
164 typedef struct rndis_keepalive_msg_type {
165 	__le32	MessageType;
166 	__le32	MessageLength;
167 	__le32	RequestID;
168 } rndis_keepalive_msg_type;
169 
170 typedef struct rndis_keepalive_cmplt_type {
171 	__le32	MessageType;
172 	__le32	MessageLength;
173 	__le32	RequestID;
174 	__le32	Status;
175 } rndis_keepalive_cmplt_type;
176 
177 struct rndis_packet_msg_type {
178 	__le32	MessageType;
179 	__le32	MessageLength;
180 	__le32	DataOffset;
181 	__le32	DataLength;
182 	__le32	OOBDataOffset;
183 	__le32	OOBDataLength;
184 	__le32	NumOOBDataElements;
185 	__le32	PerPacketInfoOffset;
186 	__le32	PerPacketInfoLength;
187 	__le32	VcHandle;
188 	__le32	Reserved;
189 } __attribute__ ((packed));
190 
191 struct rndis_config_parameter {
192 	__le32	ParameterNameOffset;
193 	__le32	ParameterNameLength;
194 	__le32	ParameterType;
195 	__le32	ParameterValueOffset;
196 	__le32	ParameterValueLength;
197 };
198 
199 /* implementation specific */
200 enum rndis_state {
201 	RNDIS_UNINITIALIZED,
202 	RNDIS_INITIALIZED,
203 	RNDIS_DATA_INITIALIZED,
204 };
205 
206 typedef struct rndis_resp_t {
207 	struct list_head	list;
208 	u8			*buf;
209 	u32			length;
210 	int			send;
211 } rndis_resp_t;
212 
213 typedef struct rndis_params {
214 	u8			confignr;
215 	u8			used;
216 	u16			saved_filter;
217 	enum rndis_state	state;
218 	u32			medium;
219 	u32			speed;
220 	u32			media_state;
221 
222 	const u8		*host_mac;
223 	u16			*filter;
224 	struct net_device_stats *stats;
225 	int			mtu;
226 
227 	u32			vendorID;
228 	const char		*vendorDescr;
229 #ifndef CONFIG_DM_ETH
230 	struct eth_device	*dev;
231 	int (*ack)(struct eth_device *);
232 #else
233 	struct udevice		*dev;
234 	int (*ack)(struct udevice *);
235 #endif
236 	struct list_head	resp_queue;
237 } rndis_params;
238 
239 /* RNDIS Message parser and other useless functions */
240 int  rndis_msg_parser(u8 configNr, u8 *buf);
241 enum rndis_state rndis_get_state(int configNr);
242 void rndis_deregister(int configNr);
243 #ifndef CONFIG_DM_ETH
244 int  rndis_register(int (*rndis_control_ack)(struct eth_device *));
245 int  rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu,
246 			 struct net_device_stats *stats, u16 *cdc_filter);
247 #else
248 int  rndis_register(int (*rndis_control_ack)(struct udevice *));
249 int  rndis_set_param_dev(u8 configNr, struct udevice *dev, int mtu,
250 			 struct net_device_stats *stats, u16 *cdc_filter);
251 #endif
252 int  rndis_set_param_vendor(u8 configNr, u32 vendorID,
253 			    const char *vendorDescr);
254 int  rndis_set_param_medium(u8 configNr, u32 medium, u32 speed);
255 void rndis_add_hdr(void *bug, int length);
256 int rndis_rm_hdr(void *bug, int length);
257 u8   *rndis_get_next_response(int configNr, u32 *length);
258 void rndis_free_response(int configNr, u8 *buf);
259 
260 void rndis_uninit(int configNr);
261 int  rndis_signal_connect(int configNr);
262 int  rndis_signal_disconnect(int configNr);
263 extern void rndis_set_host_mac(int configNr, const u8 *addr);
264 
265 int rndis_init(void);
266 void rndis_exit(void);
267 
268 #endif  /* _USBGADGET_RNDIS_H */
269