1f25bf6fcSAndreas Noever /* 2f25bf6fcSAndreas Noever * Thunderbolt Cactus Ridge driver - control channel and configuration commands 3f25bf6fcSAndreas Noever * 4f25bf6fcSAndreas Noever * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com> 5f25bf6fcSAndreas Noever */ 6f25bf6fcSAndreas Noever 7f25bf6fcSAndreas Noever #ifndef _TB_CFG 8f25bf6fcSAndreas Noever #define _TB_CFG 9f25bf6fcSAndreas Noever 10f25bf6fcSAndreas Noever #include "nhi.h" 11*32af9434SMika Westerberg #include "tb_msgs.h" 12f25bf6fcSAndreas Noever 13f25bf6fcSAndreas Noever /* control channel */ 14f25bf6fcSAndreas Noever struct tb_ctl; 15f25bf6fcSAndreas Noever 16f25bf6fcSAndreas Noever typedef void (*hotplug_cb)(void *data, u64 route, u8 port, bool unplug); 17f25bf6fcSAndreas Noever 18f25bf6fcSAndreas Noever struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, hotplug_cb cb, void *cb_data); 19f25bf6fcSAndreas Noever void tb_ctl_start(struct tb_ctl *ctl); 20f25bf6fcSAndreas Noever void tb_ctl_stop(struct tb_ctl *ctl); 21f25bf6fcSAndreas Noever void tb_ctl_free(struct tb_ctl *ctl); 22f25bf6fcSAndreas Noever 23f25bf6fcSAndreas Noever /* configuration commands */ 24f25bf6fcSAndreas Noever 25f25bf6fcSAndreas Noever #define TB_CFG_DEFAULT_TIMEOUT 5000 /* msec */ 26f25bf6fcSAndreas Noever 27f25bf6fcSAndreas Noever struct tb_cfg_result { 28f25bf6fcSAndreas Noever u64 response_route; 29f25bf6fcSAndreas Noever u32 response_port; /* 30f25bf6fcSAndreas Noever * If err = 1 then this is the port that send the 31f25bf6fcSAndreas Noever * error. 32f25bf6fcSAndreas Noever * If err = 0 and if this was a cfg_read/write then 33f25bf6fcSAndreas Noever * this is the the upstream port of the responding 34f25bf6fcSAndreas Noever * switch. 35f25bf6fcSAndreas Noever * Otherwise the field is set to zero. 36f25bf6fcSAndreas Noever */ 37f25bf6fcSAndreas Noever int err; /* negative errors, 0 for success, 1 for tb errors */ 38f25bf6fcSAndreas Noever enum tb_cfg_error tb_error; /* valid if err == 1 */ 39f25bf6fcSAndreas Noever }; 40f25bf6fcSAndreas Noever 41f25bf6fcSAndreas Noever 42f25bf6fcSAndreas Noever int tb_cfg_error(struct tb_ctl *ctl, u64 route, u32 port, 43f25bf6fcSAndreas Noever enum tb_cfg_error error); 44f25bf6fcSAndreas Noever struct tb_cfg_result tb_cfg_reset(struct tb_ctl *ctl, u64 route, 45f25bf6fcSAndreas Noever int timeout_msec); 46f25bf6fcSAndreas Noever struct tb_cfg_result tb_cfg_read_raw(struct tb_ctl *ctl, void *buffer, 47f25bf6fcSAndreas Noever u64 route, u32 port, 48f25bf6fcSAndreas Noever enum tb_cfg_space space, u32 offset, 49f25bf6fcSAndreas Noever u32 length, int timeout_msec); 5016a1258aSMika Westerberg struct tb_cfg_result tb_cfg_write_raw(struct tb_ctl *ctl, const void *buffer, 51f25bf6fcSAndreas Noever u64 route, u32 port, 52f25bf6fcSAndreas Noever enum tb_cfg_space space, u32 offset, 53f25bf6fcSAndreas Noever u32 length, int timeout_msec); 54f25bf6fcSAndreas Noever int tb_cfg_read(struct tb_ctl *ctl, void *buffer, u64 route, u32 port, 55f25bf6fcSAndreas Noever enum tb_cfg_space space, u32 offset, u32 length); 5616a1258aSMika Westerberg int tb_cfg_write(struct tb_ctl *ctl, const void *buffer, u64 route, u32 port, 57f25bf6fcSAndreas Noever enum tb_cfg_space space, u32 offset, u32 length); 58f25bf6fcSAndreas Noever int tb_cfg_get_upstream_port(struct tb_ctl *ctl, u64 route); 59f25bf6fcSAndreas Noever 60f25bf6fcSAndreas Noever 61f25bf6fcSAndreas Noever #endif 62