1
2
3
4
5
6
7
8
9#ifndef _TB_CFG
10#define _TB_CFG
11
12#include <linux/kref.h>
13#include <linux/thunderbolt.h>
14
15#include "nhi.h"
16#include "tb_msgs.h"
17
18
19struct tb_ctl;
20
21typedef bool (*event_cb)(void *data, enum tb_cfg_pkg_type type,
22 const void *buf, size_t size);
23
24struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, int timeout_msec, event_cb cb,
25 void *cb_data);
26void tb_ctl_start(struct tb_ctl *ctl);
27void tb_ctl_stop(struct tb_ctl *ctl);
28void tb_ctl_free(struct tb_ctl *ctl);
29
30
31
32struct tb_cfg_result {
33 u64 response_route;
34 u32 response_port;
35
36
37
38
39
40
41
42 int err;
43 enum tb_cfg_error tb_error;
44};
45
46struct ctl_pkg {
47 struct tb_ctl *ctl;
48 void *buffer;
49 struct ring_frame frame;
50};
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76struct tb_cfg_request {
77 struct kref kref;
78 struct tb_ctl *ctl;
79 const void *request;
80 size_t request_size;
81 enum tb_cfg_pkg_type request_type;
82 void *response;
83 size_t response_size;
84 enum tb_cfg_pkg_type response_type;
85 size_t npackets;
86 bool (*match)(const struct tb_cfg_request *req,
87 const struct ctl_pkg *pkg);
88 bool (*copy)(struct tb_cfg_request *req, const struct ctl_pkg *pkg);
89 void (*callback)(void *callback_data);
90 void *callback_data;
91 unsigned long flags;
92 struct work_struct work;
93 struct tb_cfg_result result;
94 struct list_head list;
95};
96
97#define TB_CFG_REQUEST_ACTIVE 0
98#define TB_CFG_REQUEST_CANCELED 1
99
100struct tb_cfg_request *tb_cfg_request_alloc(void);
101void tb_cfg_request_get(struct tb_cfg_request *req);
102void tb_cfg_request_put(struct tb_cfg_request *req);
103int tb_cfg_request(struct tb_ctl *ctl, struct tb_cfg_request *req,
104 void (*callback)(void *), void *callback_data);
105void tb_cfg_request_cancel(struct tb_cfg_request *req, int err);
106struct tb_cfg_result tb_cfg_request_sync(struct tb_ctl *ctl,
107 struct tb_cfg_request *req, int timeout_msec);
108
109static inline u64 tb_cfg_get_route(const struct tb_cfg_header *header)
110{
111 return (u64) header->route_hi << 32 | header->route_lo;
112}
113
114static inline struct tb_cfg_header tb_cfg_make_header(u64 route)
115{
116 struct tb_cfg_header header = {
117 .route_hi = route >> 32,
118 .route_lo = route,
119 };
120
121 WARN_ON(tb_cfg_get_route(&header) != route);
122 return header;
123}
124
125int tb_cfg_ack_plug(struct tb_ctl *ctl, u64 route, u32 port, bool unplug);
126struct tb_cfg_result tb_cfg_reset(struct tb_ctl *ctl, u64 route);
127struct tb_cfg_result tb_cfg_read_raw(struct tb_ctl *ctl, void *buffer,
128 u64 route, u32 port,
129 enum tb_cfg_space space, u32 offset,
130 u32 length, int timeout_msec);
131struct tb_cfg_result tb_cfg_write_raw(struct tb_ctl *ctl, const void *buffer,
132 u64 route, u32 port,
133 enum tb_cfg_space space, u32 offset,
134 u32 length, int timeout_msec);
135int tb_cfg_read(struct tb_ctl *ctl, void *buffer, u64 route, u32 port,
136 enum tb_cfg_space space, u32 offset, u32 length);
137int tb_cfg_write(struct tb_ctl *ctl, const void *buffer, u64 route, u32 port,
138 enum tb_cfg_space space, u32 offset, u32 length);
139int tb_cfg_get_upstream_port(struct tb_ctl *ctl, u64 route);
140
141
142#endif
143