ctl.h 2.2 KB

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