1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef _ISHTP_CLIENT_H_
17#define _ISHTP_CLIENT_H_
18
19#include <linux/types.h>
20#include "ishtp-dev.h"
21
22
23enum cl_state {
24 ISHTP_CL_INITIALIZING = 0,
25 ISHTP_CL_CONNECTING,
26 ISHTP_CL_CONNECTED,
27 ISHTP_CL_DISCONNECTING,
28 ISHTP_CL_DISCONNECTED
29};
30
31
32#define CL_DEF_RX_RING_SIZE 2
33#define CL_DEF_TX_RING_SIZE 2
34#define CL_MAX_RX_RING_SIZE 32
35#define CL_MAX_TX_RING_SIZE 32
36
37#define DMA_SLOT_SIZE 4096
38
39#define DMA_WORTH_THRESHOLD 3
40
41
42#define CL_TX_PATH_DEFAULT 0
43#define CL_TX_PATH_IPC 1
44#define CL_TX_PATH_DMA 2
45
46
47struct ishtp_cl_tx_ring {
48 struct list_head list;
49 struct ishtp_msg_data send_buf;
50};
51
52
53struct ishtp_cl {
54 struct list_head link;
55 struct ishtp_device *dev;
56 enum cl_state state;
57 int status;
58
59
60 struct ishtp_cl_device *device;
61
62
63 uint8_t host_client_id;
64 uint8_t fw_client_id;
65 uint8_t ishtp_flow_ctrl_creds;
66 uint8_t out_flow_ctrl_creds;
67
68
69 int last_tx_path;
70
71 int last_dma_acked;
72 unsigned char *last_dma_addr;
73
74 int last_ipc_acked;
75
76
77 unsigned int rx_ring_size;
78 struct ishtp_cl_rb free_rb_list;
79 spinlock_t free_list_spinlock;
80
81 struct ishtp_cl_rb in_process_list;
82 spinlock_t in_process_spinlock;
83
84
85 unsigned int tx_ring_size;
86 struct ishtp_cl_tx_ring tx_list, tx_free_list;
87 spinlock_t tx_list_spinlock;
88 spinlock_t tx_free_list_spinlock;
89 size_t tx_offs;
90
91
92
93
94
95
96
97
98
99 int sending;
100
101
102 spinlock_t fc_spinlock;
103
104
105 wait_queue_head_t wait_ctrl_res;
106
107
108 unsigned int err_send_msg;
109 unsigned int err_send_fc;
110
111
112 unsigned int send_msg_cnt_ipc;
113 unsigned int send_msg_cnt_dma;
114 unsigned int recv_msg_cnt_ipc;
115 unsigned int recv_msg_cnt_dma;
116 unsigned int recv_msg_num_frags;
117 unsigned int ishtp_flow_ctrl_cnt;
118 unsigned int out_flow_ctrl_cnt;
119
120
121 struct timespec ts_rx;
122 struct timespec ts_out_fc;
123 struct timespec ts_max_fc_delay;
124 void *client_data;
125
126
127 RH_KABI_EXTEND(int tx_ring_free_size;)
128};
129
130
131int ishtp_can_client_connect(struct ishtp_device *ishtp_dev, uuid_le *uuid);
132int ishtp_fw_cl_by_id(struct ishtp_device *dev, uint8_t client_id);
133void ishtp_cl_send_msg(struct ishtp_device *dev, struct ishtp_cl *cl);
134void recv_ishtp_cl_msg(struct ishtp_device *dev,
135 struct ishtp_msg_hdr *ishtp_hdr);
136int ishtp_cl_read_start(struct ishtp_cl *cl);
137
138
139int ishtp_cl_alloc_rx_ring(struct ishtp_cl *cl);
140int ishtp_cl_alloc_tx_ring(struct ishtp_cl *cl);
141void ishtp_cl_free_rx_ring(struct ishtp_cl *cl);
142void ishtp_cl_free_tx_ring(struct ishtp_cl *cl);
143int ishtp_cl_get_tx_free_buffer_size(struct ishtp_cl *cl);
144int ishtp_cl_get_tx_free_rings(struct ishtp_cl *cl);
145
146
147void recv_ishtp_cl_msg_dma(struct ishtp_device *dev, void *msg,
148 struct dma_xfer_hbm *hbm);
149void ishtp_cl_alloc_dma_buf(struct ishtp_device *dev);
150void ishtp_cl_free_dma_buf(struct ishtp_device *dev);
151void *ishtp_cl_get_dma_send_buf(struct ishtp_device *dev,
152 uint32_t size);
153void ishtp_cl_release_dma_acked_mem(struct ishtp_device *dev,
154 void *msg_addr,
155 uint8_t size);
156
157
158struct ishtp_cl_rb *ishtp_io_rb_init(struct ishtp_cl *cl);
159void ishtp_io_rb_free(struct ishtp_cl_rb *priv_rb);
160int ishtp_io_rb_alloc_buf(struct ishtp_cl_rb *rb, size_t length);
161
162
163
164
165
166static inline bool ishtp_cl_cmp_id(const struct ishtp_cl *cl1,
167 const struct ishtp_cl *cl2)
168{
169 return cl1 && cl2 &&
170 (cl1->host_client_id == cl2->host_client_id) &&
171 (cl1->fw_client_id == cl2->fw_client_id);
172}
173
174
175struct ishtp_cl *ishtp_cl_allocate(struct ishtp_device *dev);
176void ishtp_cl_free(struct ishtp_cl *cl);
177int ishtp_cl_link(struct ishtp_cl *cl, int id);
178void ishtp_cl_unlink(struct ishtp_cl *cl);
179int ishtp_cl_disconnect(struct ishtp_cl *cl);
180int ishtp_cl_connect(struct ishtp_cl *cl);
181int ishtp_cl_send(struct ishtp_cl *cl, uint8_t *buf, size_t length);
182int ishtp_cl_flush_queues(struct ishtp_cl *cl);
183
184
185int ishtp_cl_io_rb_recycle(struct ishtp_cl_rb *rb);
186bool ishtp_cl_tx_empty(struct ishtp_cl *cl);
187struct ishtp_cl_rb *ishtp_cl_rx_get_rb(struct ishtp_cl *cl);
188
189#endif
190