hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/hid/intel-ish-hid/ishtp/client-buffers.c
....@@ -1,17 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * ISHTP Ring Buffers
34 *
45 * Copyright (c) 2003-2016, Intel Corporation.
5
- *
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.
9
- *
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.
14
- *
156 */
167
178 #include <linux/slab.h>
....@@ -69,6 +60,8 @@
6960 int j;
7061 unsigned long flags;
7162
63
+ cl->tx_ring_free_size = 0;
64
+
7265 /* Allocate pool to free Tx bufs */
7366 for (j = 0; j < cl->tx_ring_size; ++j) {
7467 struct ishtp_cl_tx_ring *tx_buf;
....@@ -85,6 +78,7 @@
8578
8679 spin_lock_irqsave(&cl->tx_free_list_spinlock, flags);
8780 list_add_tail(&tx_buf->list, &cl->tx_free_list.list);
81
+ ++cl->tx_ring_free_size;
8882 spin_unlock_irqrestore(&cl->tx_free_list_spinlock, flags);
8983 }
9084 return 0;
....@@ -144,6 +138,7 @@
144138 tx_buf = list_entry(cl->tx_free_list.list.next,
145139 struct ishtp_cl_tx_ring, list);
146140 list_del(&tx_buf->list);
141
+ --cl->tx_ring_free_size;
147142 kfree(tx_buf->send_buf.data);
148143 kfree(tx_buf);
149144 }
....@@ -255,3 +250,48 @@
255250 return rets;
256251 }
257252 EXPORT_SYMBOL(ishtp_cl_io_rb_recycle);
253
+
254
+/**
255
+ * ishtp_cl_tx_empty() -test whether client device tx buffer is empty
256
+ * @cl: Pointer to client device instance
257
+ *
258
+ * Look client device tx buffer list, and check whether this list is empty
259
+ *
260
+ * Return: true if client tx buffer list is empty else false
261
+ */
262
+bool ishtp_cl_tx_empty(struct ishtp_cl *cl)
263
+{
264
+ int tx_list_empty;
265
+ unsigned long tx_flags;
266
+
267
+ spin_lock_irqsave(&cl->tx_list_spinlock, tx_flags);
268
+ tx_list_empty = list_empty(&cl->tx_list.list);
269
+ spin_unlock_irqrestore(&cl->tx_list_spinlock, tx_flags);
270
+
271
+ return !!tx_list_empty;
272
+}
273
+EXPORT_SYMBOL(ishtp_cl_tx_empty);
274
+
275
+/**
276
+ * ishtp_cl_rx_get_rb() -Get a rb from client device rx buffer list
277
+ * @cl: Pointer to client device instance
278
+ *
279
+ * Check client device in-processing buffer list and get a rb from it.
280
+ *
281
+ * Return: rb pointer if buffer list isn't empty else NULL
282
+ */
283
+struct ishtp_cl_rb *ishtp_cl_rx_get_rb(struct ishtp_cl *cl)
284
+{
285
+ unsigned long rx_flags;
286
+ struct ishtp_cl_rb *rb;
287
+
288
+ spin_lock_irqsave(&cl->in_process_spinlock, rx_flags);
289
+ rb = list_first_entry_or_null(&cl->in_process_list.list,
290
+ struct ishtp_cl_rb, list);
291
+ if (rb)
292
+ list_del_init(&rb->list);
293
+ spin_unlock_irqrestore(&cl->in_process_spinlock, rx_flags);
294
+
295
+ return rb;
296
+}
297
+EXPORT_SYMBOL(ishtp_cl_rx_get_rb);