]> Git Repo - linux.git/blob - drivers/thunderbolt/tb_msgs.h
Merge branch 'fixes' of git://git.armlinux.org.uk/~rmk/linux-arm
[linux.git] / drivers / thunderbolt / tb_msgs.h
1 /*
2  * Thunderbolt control channel messages
3  *
4  * Copyright (C) 2014 Andreas Noever <[email protected]>
5  * Copyright (C) 2017, Intel Corporation
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11
12 #ifndef _TB_MSGS
13 #define _TB_MSGS
14
15 #include <linux/types.h>
16 #include <linux/uuid.h>
17
18 enum tb_cfg_space {
19         TB_CFG_HOPS = 0,
20         TB_CFG_PORT = 1,
21         TB_CFG_SWITCH = 2,
22         TB_CFG_COUNTERS = 3,
23 };
24
25 enum tb_cfg_error {
26         TB_CFG_ERROR_PORT_NOT_CONNECTED = 0,
27         TB_CFG_ERROR_LINK_ERROR = 1,
28         TB_CFG_ERROR_INVALID_CONFIG_SPACE = 2,
29         TB_CFG_ERROR_NO_SUCH_PORT = 4,
30         TB_CFG_ERROR_ACK_PLUG_EVENT = 7, /* send as reply to TB_CFG_PKG_EVENT */
31         TB_CFG_ERROR_LOOP = 8,
32         TB_CFG_ERROR_HEC_ERROR_DETECTED = 12,
33         TB_CFG_ERROR_FLOW_CONTROL_ERROR = 13,
34 };
35
36 /* common header */
37 struct tb_cfg_header {
38         u32 route_hi:22;
39         u32 unknown:10; /* highest order bit is set on replies */
40         u32 route_lo;
41 } __packed;
42
43 /* additional header for read/write packets */
44 struct tb_cfg_address {
45         u32 offset:13; /* in dwords */
46         u32 length:6; /* in dwords */
47         u32 port:6;
48         enum tb_cfg_space space:2;
49         u32 seq:2; /* sequence number  */
50         u32 zero:3;
51 } __packed;
52
53 /* TB_CFG_PKG_READ, response for TB_CFG_PKG_WRITE */
54 struct cfg_read_pkg {
55         struct tb_cfg_header header;
56         struct tb_cfg_address addr;
57 } __packed;
58
59 /* TB_CFG_PKG_WRITE, response for TB_CFG_PKG_READ */
60 struct cfg_write_pkg {
61         struct tb_cfg_header header;
62         struct tb_cfg_address addr;
63         u32 data[64]; /* maximum size, tb_cfg_address.length has 6 bits */
64 } __packed;
65
66 /* TB_CFG_PKG_ERROR */
67 struct cfg_error_pkg {
68         struct tb_cfg_header header;
69         enum tb_cfg_error error:4;
70         u32 zero1:4;
71         u32 port:6;
72         u32 zero2:2; /* Both should be zero, still they are different fields. */
73         u32 zero3:16;
74 } __packed;
75
76 /* TB_CFG_PKG_EVENT */
77 struct cfg_event_pkg {
78         struct tb_cfg_header header;
79         u32 port:6;
80         u32 zero:25;
81         bool unplug:1;
82 } __packed;
83
84 /* TB_CFG_PKG_RESET */
85 struct cfg_reset_pkg {
86         struct tb_cfg_header header;
87 } __packed;
88
89 /* TB_CFG_PKG_PREPARE_TO_SLEEP */
90 struct cfg_pts_pkg {
91         struct tb_cfg_header header;
92         u32 data;
93 } __packed;
94
95 /* ICM messages */
96
97 enum icm_pkg_code {
98         ICM_GET_TOPOLOGY = 0x1,
99         ICM_DRIVER_READY = 0x3,
100         ICM_APPROVE_DEVICE = 0x4,
101         ICM_CHALLENGE_DEVICE = 0x5,
102         ICM_ADD_DEVICE_KEY = 0x6,
103         ICM_GET_ROUTE = 0xa,
104         ICM_APPROVE_XDOMAIN = 0x10,
105 };
106
107 enum icm_event_code {
108         ICM_EVENT_DEVICE_CONNECTED = 3,
109         ICM_EVENT_DEVICE_DISCONNECTED = 4,
110         ICM_EVENT_XDOMAIN_CONNECTED = 6,
111         ICM_EVENT_XDOMAIN_DISCONNECTED = 7,
112 };
113
114 struct icm_pkg_header {
115         u8 code;
116         u8 flags;
117         u8 packet_id;
118         u8 total_packets;
119 };
120
121 #define ICM_FLAGS_ERROR                 BIT(0)
122 #define ICM_FLAGS_NO_KEY                BIT(1)
123 #define ICM_FLAGS_SLEVEL_SHIFT          3
124 #define ICM_FLAGS_SLEVEL_MASK           GENMASK(4, 3)
125
126 struct icm_pkg_driver_ready {
127         struct icm_pkg_header hdr;
128 };
129
130 struct icm_pkg_driver_ready_response {
131         struct icm_pkg_header hdr;
132         u8 romver;
133         u8 ramver;
134         u16 security_level;
135 };
136
137 /* Falcon Ridge & Alpine Ridge common messages */
138
139 struct icm_fr_pkg_get_topology {
140         struct icm_pkg_header hdr;
141 };
142
143 #define ICM_GET_TOPOLOGY_PACKETS        14
144
145 struct icm_fr_pkg_get_topology_response {
146         struct icm_pkg_header hdr;
147         u32 route_lo;
148         u32 route_hi;
149         u8 first_data;
150         u8 second_data;
151         u8 drom_i2c_address_index;
152         u8 switch_index;
153         u32 reserved[2];
154         u32 ports[16];
155         u32 port_hop_info[16];
156 };
157
158 #define ICM_SWITCH_USED                 BIT(0)
159 #define ICM_SWITCH_UPSTREAM_PORT_MASK   GENMASK(7, 1)
160 #define ICM_SWITCH_UPSTREAM_PORT_SHIFT  1
161
162 #define ICM_PORT_TYPE_MASK              GENMASK(23, 0)
163 #define ICM_PORT_INDEX_SHIFT            24
164 #define ICM_PORT_INDEX_MASK             GENMASK(31, 24)
165
166 struct icm_fr_event_device_connected {
167         struct icm_pkg_header hdr;
168         uuid_t ep_uuid;
169         u8 connection_key;
170         u8 connection_id;
171         u16 link_info;
172         u32 ep_name[55];
173 };
174
175 #define ICM_LINK_INFO_LINK_MASK         0x7
176 #define ICM_LINK_INFO_DEPTH_SHIFT       4
177 #define ICM_LINK_INFO_DEPTH_MASK        GENMASK(7, 4)
178 #define ICM_LINK_INFO_APPROVED          BIT(8)
179
180 struct icm_fr_pkg_approve_device {
181         struct icm_pkg_header hdr;
182         uuid_t ep_uuid;
183         u8 connection_key;
184         u8 connection_id;
185         u16 reserved;
186 };
187
188 struct icm_fr_event_device_disconnected {
189         struct icm_pkg_header hdr;
190         u16 reserved;
191         u16 link_info;
192 };
193
194 struct icm_fr_event_xdomain_connected {
195         struct icm_pkg_header hdr;
196         u16 reserved;
197         u16 link_info;
198         uuid_t remote_uuid;
199         uuid_t local_uuid;
200         u32 local_route_hi;
201         u32 local_route_lo;
202         u32 remote_route_hi;
203         u32 remote_route_lo;
204 };
205
206 struct icm_fr_event_xdomain_disconnected {
207         struct icm_pkg_header hdr;
208         u16 reserved;
209         u16 link_info;
210         uuid_t remote_uuid;
211 };
212
213 struct icm_fr_pkg_add_device_key {
214         struct icm_pkg_header hdr;
215         uuid_t ep_uuid;
216         u8 connection_key;
217         u8 connection_id;
218         u16 reserved;
219         u32 key[8];
220 };
221
222 struct icm_fr_pkg_add_device_key_response {
223         struct icm_pkg_header hdr;
224         uuid_t ep_uuid;
225         u8 connection_key;
226         u8 connection_id;
227         u16 reserved;
228 };
229
230 struct icm_fr_pkg_challenge_device {
231         struct icm_pkg_header hdr;
232         uuid_t ep_uuid;
233         u8 connection_key;
234         u8 connection_id;
235         u16 reserved;
236         u32 challenge[8];
237 };
238
239 struct icm_fr_pkg_challenge_device_response {
240         struct icm_pkg_header hdr;
241         uuid_t ep_uuid;
242         u8 connection_key;
243         u8 connection_id;
244         u16 reserved;
245         u32 challenge[8];
246         u32 response[8];
247 };
248
249 struct icm_fr_pkg_approve_xdomain {
250         struct icm_pkg_header hdr;
251         u16 reserved;
252         u16 link_info;
253         uuid_t remote_uuid;
254         u16 transmit_path;
255         u16 transmit_ring;
256         u16 receive_path;
257         u16 receive_ring;
258 };
259
260 struct icm_fr_pkg_approve_xdomain_response {
261         struct icm_pkg_header hdr;
262         u16 reserved;
263         u16 link_info;
264         uuid_t remote_uuid;
265         u16 transmit_path;
266         u16 transmit_ring;
267         u16 receive_path;
268         u16 receive_ring;
269 };
270
271 /* Alpine Ridge only messages */
272
273 struct icm_ar_pkg_get_route {
274         struct icm_pkg_header hdr;
275         u16 reserved;
276         u16 link_info;
277 };
278
279 struct icm_ar_pkg_get_route_response {
280         struct icm_pkg_header hdr;
281         u16 reserved;
282         u16 link_info;
283         u32 route_hi;
284         u32 route_lo;
285 };
286
287 /* XDomain messages */
288
289 struct tb_xdomain_header {
290         u32 route_hi;
291         u32 route_lo;
292         u32 length_sn;
293 };
294
295 #define TB_XDOMAIN_LENGTH_MASK  GENMASK(5, 0)
296 #define TB_XDOMAIN_SN_MASK      GENMASK(28, 27)
297 #define TB_XDOMAIN_SN_SHIFT     27
298
299 enum tb_xdp_type {
300         UUID_REQUEST_OLD = 1,
301         UUID_RESPONSE = 2,
302         PROPERTIES_REQUEST,
303         PROPERTIES_RESPONSE,
304         PROPERTIES_CHANGED_REQUEST,
305         PROPERTIES_CHANGED_RESPONSE,
306         ERROR_RESPONSE,
307         UUID_REQUEST = 12,
308 };
309
310 struct tb_xdp_header {
311         struct tb_xdomain_header xd_hdr;
312         uuid_t uuid;
313         u32 type;
314 };
315
316 struct tb_xdp_properties {
317         struct tb_xdp_header hdr;
318         uuid_t src_uuid;
319         uuid_t dst_uuid;
320         u16 offset;
321         u16 reserved;
322 };
323
324 struct tb_xdp_properties_response {
325         struct tb_xdp_header hdr;
326         uuid_t src_uuid;
327         uuid_t dst_uuid;
328         u16 offset;
329         u16 data_length;
330         u32 generation;
331         u32 data[0];
332 };
333
334 /*
335  * Max length of data array single XDomain property response is allowed
336  * to carry.
337  */
338 #define TB_XDP_PROPERTIES_MAX_DATA_LENGTH       \
339         (((256 - 4 - sizeof(struct tb_xdp_properties_response))) / 4)
340
341 /* Maximum size of the total property block in dwords we allow */
342 #define TB_XDP_PROPERTIES_MAX_LENGTH            500
343
344 struct tb_xdp_properties_changed {
345         struct tb_xdp_header hdr;
346         uuid_t src_uuid;
347 };
348
349 struct tb_xdp_properties_changed_response {
350         struct tb_xdp_header hdr;
351 };
352
353 enum tb_xdp_error {
354         ERROR_SUCCESS,
355         ERROR_UNKNOWN_PACKET,
356         ERROR_UNKNOWN_DOMAIN,
357         ERROR_NOT_SUPPORTED,
358         ERROR_NOT_READY,
359 };
360
361 struct tb_xdp_error_response {
362         struct tb_xdp_header hdr;
363         u32 error;
364 };
365
366 #endif
This page took 0.054294 seconds and 4 git commands to generate.