| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * ISHTP Ring Buffers |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * 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 | | - * |
|---|
| 15 | 6 | */ |
|---|
| 16 | 7 | |
|---|
| 17 | 8 | #include <linux/slab.h> |
|---|
| .. | .. |
|---|
| 69 | 60 | int j; |
|---|
| 70 | 61 | unsigned long flags; |
|---|
| 71 | 62 | |
|---|
| 63 | + cl->tx_ring_free_size = 0; |
|---|
| 64 | + |
|---|
| 72 | 65 | /* Allocate pool to free Tx bufs */ |
|---|
| 73 | 66 | for (j = 0; j < cl->tx_ring_size; ++j) { |
|---|
| 74 | 67 | struct ishtp_cl_tx_ring *tx_buf; |
|---|
| .. | .. |
|---|
| 85 | 78 | |
|---|
| 86 | 79 | spin_lock_irqsave(&cl->tx_free_list_spinlock, flags); |
|---|
| 87 | 80 | list_add_tail(&tx_buf->list, &cl->tx_free_list.list); |
|---|
| 81 | + ++cl->tx_ring_free_size; |
|---|
| 88 | 82 | spin_unlock_irqrestore(&cl->tx_free_list_spinlock, flags); |
|---|
| 89 | 83 | } |
|---|
| 90 | 84 | return 0; |
|---|
| .. | .. |
|---|
| 144 | 138 | tx_buf = list_entry(cl->tx_free_list.list.next, |
|---|
| 145 | 139 | struct ishtp_cl_tx_ring, list); |
|---|
| 146 | 140 | list_del(&tx_buf->list); |
|---|
| 141 | + --cl->tx_ring_free_size; |
|---|
| 147 | 142 | kfree(tx_buf->send_buf.data); |
|---|
| 148 | 143 | kfree(tx_buf); |
|---|
| 149 | 144 | } |
|---|
| .. | .. |
|---|
| 255 | 250 | return rets; |
|---|
| 256 | 251 | } |
|---|
| 257 | 252 | 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); |
|---|