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