2 * Thunderbolt Cactus Ridge driver - control channel and configuration commands
4 * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
16 typedef void (*event_cb)(void *data, enum tb_cfg_pkg_type type,
17 const void *buf, size_t size);
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);
24 /* configuration commands */
26 #define TB_CFG_DEFAULT_TIMEOUT 5000 /* msec */
28 struct tb_cfg_result {
31 * If err = 1 then this is the port that send the
33 * If err = 0 and if this was a cfg_read/write then
34 * this is the the upstream port of the responding
36 * Otherwise the field is set to zero.
38 int err; /* negative errors, 0 for success, 1 for tb errors */
39 enum tb_cfg_error tb_error; /* valid if err == 1 */
42 static inline u64 tb_cfg_get_route(const struct tb_cfg_header *header)
44 return (u64) header->route_hi << 32 | header->route_lo;
47 static inline struct tb_cfg_header tb_cfg_make_header(u64 route)
49 struct tb_cfg_header header = {
50 .route_hi = route >> 32,
53 /* check for overflow, route_hi is not 32 bits! */
54 WARN_ON(tb_cfg_get_route(&header) != route);
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,
62 struct tb_cfg_result tb_cfg_read_raw(struct tb_ctl *ctl, void *buffer,
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,
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);