]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/thunderbolt/ctl.h
2b23e030a85bdefc043fafd72286565c9fc32de4
[karo-tx-linux.git] / drivers / thunderbolt / ctl.h
1 /*
2  * Thunderbolt Cactus Ridge driver - control channel and configuration commands
3  *
4  * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
5  */
6
7 #ifndef _TB_CFG
8 #define _TB_CFG
9
10 #include "nhi.h"
11 #include "tb_msgs.h"
12
13 /* control channel */
14 struct tb_ctl;
15
16 typedef void (*event_cb)(void *data, enum tb_cfg_pkg_type type,
17                          const void *buf, size_t size);
18
19 struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, event_cb cb, void *cb_data);
20 void tb_ctl_start(struct tb_ctl *ctl);
21 void tb_ctl_stop(struct tb_ctl *ctl);
22 void tb_ctl_free(struct tb_ctl *ctl);
23
24 /* configuration commands */
25
26 #define TB_CFG_DEFAULT_TIMEOUT 5000 /* msec */
27
28 struct tb_cfg_result {
29         u64 response_route;
30         u32 response_port; /*
31                             * If err = 1 then this is the port that send the
32                             * error.
33                             * If err = 0 and if this was a cfg_read/write then
34                             * this is the the upstream port of the responding
35                             * switch.
36                             * Otherwise the field is set to zero.
37                             */
38         int err; /* negative errors, 0 for success, 1 for tb errors */
39         enum tb_cfg_error tb_error; /* valid if err == 1 */
40 };
41
42 static inline u64 tb_cfg_get_route(const struct tb_cfg_header *header)
43 {
44         return (u64) header->route_hi << 32 | header->route_lo;
45 }
46
47 static inline struct tb_cfg_header tb_cfg_make_header(u64 route)
48 {
49         struct tb_cfg_header header = {
50                 .route_hi = route >> 32,
51                 .route_lo = route,
52         };
53         /* check for overflow, route_hi is not 32 bits! */
54         WARN_ON(tb_cfg_get_route(&header) != route);
55         return header;
56 }
57
58 int tb_cfg_error(struct tb_ctl *ctl, u64 route, u32 port,
59                  enum tb_cfg_error error);
60 struct tb_cfg_result tb_cfg_reset(struct tb_ctl *ctl, u64 route,
61                                   int timeout_msec);
62 struct tb_cfg_result tb_cfg_read_raw(struct tb_ctl *ctl, void *buffer,
63                                      u64 route, u32 port,
64                                      enum tb_cfg_space space, u32 offset,
65                                      u32 length, int timeout_msec);
66 struct tb_cfg_result tb_cfg_write_raw(struct tb_ctl *ctl, const void *buffer,
67                                       u64 route, u32 port,
68                                       enum tb_cfg_space space, u32 offset,
69                                       u32 length, int timeout_msec);
70 int tb_cfg_read(struct tb_ctl *ctl, void *buffer, u64 route, u32 port,
71                 enum tb_cfg_space space, u32 offset, u32 length);
72 int tb_cfg_write(struct tb_ctl *ctl, const void *buffer, u64 route, u32 port,
73                  enum tb_cfg_space space, u32 offset, u32 length);
74 int tb_cfg_get_upstream_port(struct tb_ctl *ctl, u64 route);
75
76
77 #endif