blob: 9812b1c86d4f64f0825bfb6becbd1c5f4b86aa38 [file] [log] [blame]
Andreas Noeverf25bf6f2014-06-03 22:03:59 +02001/*
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"
Mika Westerberg32af9432017-06-06 15:25:06 +030011#include "tb_msgs.h"
Andreas Noeverf25bf6f2014-06-03 22:03:59 +020012
13/* control channel */
14struct tb_ctl;
15
16typedef void (*hotplug_cb)(void *data, u64 route, u8 port, bool unplug);
17
18struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, hotplug_cb cb, void *cb_data);
19void tb_ctl_start(struct tb_ctl *ctl);
20void tb_ctl_stop(struct tb_ctl *ctl);
21void tb_ctl_free(struct tb_ctl *ctl);
22
23/* configuration commands */
24
25#define TB_CFG_DEFAULT_TIMEOUT 5000 /* msec */
26
Andreas Noeverf25bf6f2014-06-03 22:03:59 +020027struct tb_cfg_result {
28 u64 response_route;
29 u32 response_port; /*
30 * If err = 1 then this is the port that send the
31 * error.
32 * If err = 0 and if this was a cfg_read/write then
33 * this is the the upstream port of the responding
34 * switch.
35 * Otherwise the field is set to zero.
36 */
37 int err; /* negative errors, 0 for success, 1 for tb errors */
38 enum tb_cfg_error tb_error; /* valid if err == 1 */
39};
40
Mika Westerbergac6c44d2017-06-06 15:25:07 +030041static inline u64 tb_cfg_get_route(const struct tb_cfg_header *header)
42{
43 return (u64) header->route_hi << 32 | header->route_lo;
44}
Andreas Noeverf25bf6f2014-06-03 22:03:59 +020045
46int tb_cfg_error(struct tb_ctl *ctl, u64 route, u32 port,
47 enum tb_cfg_error error);
48struct tb_cfg_result tb_cfg_reset(struct tb_ctl *ctl, u64 route,
49 int timeout_msec);
50struct tb_cfg_result tb_cfg_read_raw(struct tb_ctl *ctl, void *buffer,
51 u64 route, u32 port,
52 enum tb_cfg_space space, u32 offset,
53 u32 length, int timeout_msec);
Mika Westerberg16a12582017-06-06 15:24:53 +030054struct tb_cfg_result tb_cfg_write_raw(struct tb_ctl *ctl, const void *buffer,
Andreas Noeverf25bf6f2014-06-03 22:03:59 +020055 u64 route, u32 port,
56 enum tb_cfg_space space, u32 offset,
57 u32 length, int timeout_msec);
58int tb_cfg_read(struct tb_ctl *ctl, void *buffer, u64 route, u32 port,
59 enum tb_cfg_space space, u32 offset, u32 length);
Mika Westerberg16a12582017-06-06 15:24:53 +030060int tb_cfg_write(struct tb_ctl *ctl, const void *buffer, u64 route, u32 port,
Andreas Noeverf25bf6f2014-06-03 22:03:59 +020061 enum tb_cfg_space space, u32 offset, u32 length);
62int tb_cfg_get_upstream_port(struct tb_ctl *ctl, u64 route);
63
64
65#endif