0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _TB_CFG
0010 #define _TB_CFG
0011
0012 #include <linux/kref.h>
0013 #include <linux/thunderbolt.h>
0014
0015 #include "nhi.h"
0016 #include "tb_msgs.h"
0017
0018
0019 struct tb_ctl;
0020
0021 typedef bool (*event_cb)(void *data, enum tb_cfg_pkg_type type,
0022 const void *buf, size_t size);
0023
0024 struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, int timeout_msec, event_cb cb,
0025 void *cb_data);
0026 void tb_ctl_start(struct tb_ctl *ctl);
0027 void tb_ctl_stop(struct tb_ctl *ctl);
0028 void tb_ctl_free(struct tb_ctl *ctl);
0029
0030
0031
0032 struct tb_cfg_result {
0033 u64 response_route;
0034 u32 response_port;
0035
0036
0037
0038
0039
0040
0041
0042 int err;
0043 enum tb_cfg_error tb_error;
0044 };
0045
0046 struct ctl_pkg {
0047 struct tb_ctl *ctl;
0048 void *buffer;
0049 struct ring_frame frame;
0050 };
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 struct tb_cfg_request {
0077 struct kref kref;
0078 struct tb_ctl *ctl;
0079 const void *request;
0080 size_t request_size;
0081 enum tb_cfg_pkg_type request_type;
0082 void *response;
0083 size_t response_size;
0084 enum tb_cfg_pkg_type response_type;
0085 size_t npackets;
0086 bool (*match)(const struct tb_cfg_request *req,
0087 const struct ctl_pkg *pkg);
0088 bool (*copy)(struct tb_cfg_request *req, const struct ctl_pkg *pkg);
0089 void (*callback)(void *callback_data);
0090 void *callback_data;
0091 unsigned long flags;
0092 struct work_struct work;
0093 struct tb_cfg_result result;
0094 struct list_head list;
0095 };
0096
0097 #define TB_CFG_REQUEST_ACTIVE 0
0098 #define TB_CFG_REQUEST_CANCELED 1
0099
0100 struct tb_cfg_request *tb_cfg_request_alloc(void);
0101 void tb_cfg_request_get(struct tb_cfg_request *req);
0102 void tb_cfg_request_put(struct tb_cfg_request *req);
0103 int tb_cfg_request(struct tb_ctl *ctl, struct tb_cfg_request *req,
0104 void (*callback)(void *), void *callback_data);
0105 void tb_cfg_request_cancel(struct tb_cfg_request *req, int err);
0106 struct tb_cfg_result tb_cfg_request_sync(struct tb_ctl *ctl,
0107 struct tb_cfg_request *req, int timeout_msec);
0108
0109 static inline u64 tb_cfg_get_route(const struct tb_cfg_header *header)
0110 {
0111 return (u64) header->route_hi << 32 | header->route_lo;
0112 }
0113
0114 static inline struct tb_cfg_header tb_cfg_make_header(u64 route)
0115 {
0116 struct tb_cfg_header header = {
0117 .route_hi = route >> 32,
0118 .route_lo = route,
0119 };
0120
0121 WARN_ON(tb_cfg_get_route(&header) != route);
0122 return header;
0123 }
0124
0125 int tb_cfg_ack_plug(struct tb_ctl *ctl, u64 route, u32 port, bool unplug);
0126 struct tb_cfg_result tb_cfg_reset(struct tb_ctl *ctl, u64 route);
0127 struct tb_cfg_result tb_cfg_read_raw(struct tb_ctl *ctl, void *buffer,
0128 u64 route, u32 port,
0129 enum tb_cfg_space space, u32 offset,
0130 u32 length, int timeout_msec);
0131 struct tb_cfg_result tb_cfg_write_raw(struct tb_ctl *ctl, const void *buffer,
0132 u64 route, u32 port,
0133 enum tb_cfg_space space, u32 offset,
0134 u32 length, int timeout_msec);
0135 int tb_cfg_read(struct tb_ctl *ctl, void *buffer, u64 route, u32 port,
0136 enum tb_cfg_space space, u32 offset, u32 length);
0137 int tb_cfg_write(struct tb_ctl *ctl, const void *buffer, u64 route, u32 port,
0138 enum tb_cfg_space space, u32 offset, u32 length);
0139 int tb_cfg_get_upstream_port(struct tb_ctl *ctl, u64 route);
0140
0141
0142 #endif