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