Linux 5.1.15
[linux/fpc-iii.git] / drivers / hid / intel-ish-hid / ishtp / client.h
blobe0df3eb611e6fc37acd9f986b79c883090d88f04
1 /*
2 * ISHTP client logic
4 * Copyright (c) 2003-2016, Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
16 #ifndef _ISHTP_CLIENT_H_
17 #define _ISHTP_CLIENT_H_
19 #include <linux/types.h>
20 #include "ishtp-dev.h"
22 /* Client state */
23 enum cl_state {
24 ISHTP_CL_INITIALIZING = 0,
25 ISHTP_CL_CONNECTING,
26 ISHTP_CL_CONNECTED,
27 ISHTP_CL_DISCONNECTING,
28 ISHTP_CL_DISCONNECTED
31 /* Tx and Rx ring size */
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
37 #define DMA_SLOT_SIZE 4096
38 /* Number of IPC fragments after which it's worth sending via DMA */
39 #define DMA_WORTH_THRESHOLD 3
41 /* DMA/IPC Tx paths. Other the default means enforcement */
42 #define CL_TX_PATH_DEFAULT 0
43 #define CL_TX_PATH_IPC 1
44 #define CL_TX_PATH_DMA 2
46 /* Client Tx buffer list entry */
47 struct ishtp_cl_tx_ring {
48 struct list_head list;
49 struct ishtp_msg_data send_buf;
52 /* ISHTP client instance */
53 struct ishtp_cl {
54 struct list_head link;
55 struct ishtp_device *dev;
56 enum cl_state state;
57 int status;
59 /* Link to ISHTP bus device */
60 struct ishtp_cl_device *device;
62 /* ID of client connected */
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;
68 /* dma */
69 int last_tx_path;
70 /* 0: ack wasn't received,1:ack was received */
71 int last_dma_acked;
72 unsigned char *last_dma_addr;
73 /* 0: ack wasn't received,1:ack was received */
74 int last_ipc_acked;
76 /* Rx ring buffer pool */
77 unsigned int rx_ring_size;
78 struct ishtp_cl_rb free_rb_list;
79 spinlock_t free_list_spinlock;
80 /* Rx in-process list */
81 struct ishtp_cl_rb in_process_list;
82 spinlock_t in_process_spinlock;
84 /* Client Tx buffers list */
85 unsigned int tx_ring_size;
86 struct ishtp_cl_tx_ring tx_list, tx_free_list;
87 int tx_ring_free_size;
88 spinlock_t tx_list_spinlock;
89 spinlock_t tx_free_list_spinlock;
90 size_t tx_offs; /* Offset in buffer at head of 'tx_list' */
92 /**
93 * if we get a FC, and the list is not empty, we must know whether we
94 * are at the middle of sending.
95 * if so -need to increase FC counter, otherwise, need to start sending
96 * the first msg in list
97 * (!)This is for counting-FC implementation only. Within single-FC the
98 * other party may NOT send FC until it receives complete message
100 int sending;
102 /* Send FC spinlock */
103 spinlock_t fc_spinlock;
105 /* wait queue for connect and disconnect response from FW */
106 wait_queue_head_t wait_ctrl_res;
108 /* Error stats */
109 unsigned int err_send_msg;
110 unsigned int err_send_fc;
112 /* Send/recv stats */
113 unsigned int send_msg_cnt_ipc;
114 unsigned int send_msg_cnt_dma;
115 unsigned int recv_msg_cnt_ipc;
116 unsigned int recv_msg_cnt_dma;
117 unsigned int recv_msg_num_frags;
118 unsigned int ishtp_flow_ctrl_cnt;
119 unsigned int out_flow_ctrl_cnt;
121 /* Rx msg ... out FC timing */
122 ktime_t ts_rx;
123 ktime_t ts_out_fc;
124 ktime_t ts_max_fc_delay;
125 void *client_data;
128 /* Client connection managenment internal functions */
129 int ishtp_can_client_connect(struct ishtp_device *ishtp_dev, guid_t *uuid);
130 int ishtp_fw_cl_by_id(struct ishtp_device *dev, uint8_t client_id);
131 void ishtp_cl_send_msg(struct ishtp_device *dev, struct ishtp_cl *cl);
132 void recv_ishtp_cl_msg(struct ishtp_device *dev,
133 struct ishtp_msg_hdr *ishtp_hdr);
134 int ishtp_cl_read_start(struct ishtp_cl *cl);
136 /* Ring Buffer I/F */
137 int ishtp_cl_alloc_rx_ring(struct ishtp_cl *cl);
138 int ishtp_cl_alloc_tx_ring(struct ishtp_cl *cl);
139 void ishtp_cl_free_rx_ring(struct ishtp_cl *cl);
140 void ishtp_cl_free_tx_ring(struct ishtp_cl *cl);
141 int ishtp_cl_get_tx_free_buffer_size(struct ishtp_cl *cl);
142 int ishtp_cl_get_tx_free_rings(struct ishtp_cl *cl);
144 /* DMA I/F functions */
145 void recv_ishtp_cl_msg_dma(struct ishtp_device *dev, void *msg,
146 struct dma_xfer_hbm *hbm);
147 void ishtp_cl_alloc_dma_buf(struct ishtp_device *dev);
148 void ishtp_cl_free_dma_buf(struct ishtp_device *dev);
149 void *ishtp_cl_get_dma_send_buf(struct ishtp_device *dev,
150 uint32_t size);
151 void ishtp_cl_release_dma_acked_mem(struct ishtp_device *dev,
152 void *msg_addr,
153 uint8_t size);
155 /* Request blocks alloc/free I/F */
156 struct ishtp_cl_rb *ishtp_io_rb_init(struct ishtp_cl *cl);
157 void ishtp_io_rb_free(struct ishtp_cl_rb *priv_rb);
158 int ishtp_io_rb_alloc_buf(struct ishtp_cl_rb *rb, size_t length);
161 * ishtp_cl_cmp_id - tells if file private data have same id
162 * returns true - if ids are the same and not NULL
164 static inline bool ishtp_cl_cmp_id(const struct ishtp_cl *cl1,
165 const struct ishtp_cl *cl2)
167 return cl1 && cl2 &&
168 (cl1->host_client_id == cl2->host_client_id) &&
169 (cl1->fw_client_id == cl2->fw_client_id);
172 /* exported functions from ISHTP under client management scope */
173 struct ishtp_cl *ishtp_cl_allocate(struct ishtp_device *dev);
174 void ishtp_cl_free(struct ishtp_cl *cl);
175 int ishtp_cl_link(struct ishtp_cl *cl, int id);
176 void ishtp_cl_unlink(struct ishtp_cl *cl);
177 int ishtp_cl_disconnect(struct ishtp_cl *cl);
178 int ishtp_cl_connect(struct ishtp_cl *cl);
179 int ishtp_cl_send(struct ishtp_cl *cl, uint8_t *buf, size_t length);
180 int ishtp_cl_flush_queues(struct ishtp_cl *cl);
182 /* exported functions from ISHTP client buffer management scope */
183 int ishtp_cl_io_rb_recycle(struct ishtp_cl_rb *rb);
184 bool ishtp_cl_tx_empty(struct ishtp_cl *cl);
185 struct ishtp_cl_rb *ishtp_cl_rx_get_rb(struct ishtp_cl *cl);
187 #endif /* _ISHTP_CLIENT_H_ */