// SPDX-License-Identifier: GPL-2.0-only
/*
* ISHTP client logic
*
* Copyright (c) 2003-2016, Intel Corporation.
*/
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/wait.h>
#include <linux/delay.h>
#include <linux/dma-mapping.h>
#include <asm/cacheflush.h>
#include "hbm.h"
#include "client.h"
int ishtp_cl_get_tx_free_buffer_size(struct ishtp_cl *cl)
{
unsigned long tx_free_flags;
int size;
spin_lock_irqsave(&cl->tx_free_list_spinlock, tx_free_flags);
size = cl->tx_ring_free_size * cl->device->fw_client->props.max_msg_length;
spin_unlock_irqrestore(&cl->tx_free_list_spinlock, tx_free_flags);
return size;
}
EXPORT_SYMBOL(ishtp_cl_get_tx_free_buffer_size);
int ishtp_cl_get_tx_free_rings(struct ishtp_cl *cl)
{
return cl->tx_ring_free_size;
}
EXPORT_SYMBOL(ishtp_cl_get_tx_free_rings);
/**
* ishtp_read_list_flush() - Flush read queue
* @cl: ishtp client instance
*
* Used to remove all entries from read queue for a client
*/
static void ishtp_read_list_flush(struct ishtp_cl *cl)
{
struct ishtp_cl_rb *rb;
struct ishtp_cl_rb *next;
unsigned long flags;
spin_lock_irqsave(&cl->dev->read_list_spinlock, flags);
list_for_each_entry_safe(rb, next, &cl->dev->read_list.list, list)
if (rb->cl && ishtp_cl_cmp_id(cl, rb->cl)) {
list_del(&rb->list);
spin_lock(&cl->free_list_spinlock);
list_add_tail(&rb->list, &cl->free_rb_list.list);
spin_unlock(&cl->free_list_spinlock);
}
spin_unlock_irqrestore(&cl->dev->read_list_spinlock, flags);
}
/**
* ishtp_cl_flush_queues() - Flush all queues for a client
* @cl: ishtp client instance
*
* Used to remove all queues for a client. This is called when a client device
* needs reset due to error, S3 resume or during module removal
*
* Return: 0 on success else -EINVAL if device is NULL
*/
int ishtp_cl_flush_queues(struct ishtp_cl *cl)
{
if (WARN_ON(!cl || !cl->dev))
return -EINVAL;
ishtp_read_list_flush(cl);
return 0;
}
EXPORT_SYMBOL(ishtp_cl_flush_queues);
/**
* ishtp_cl_init() - Initialize all fields of a client device
* @cl: ishtp client instance
* @dev: ishtp device
*
* Initializes a client device fields: Init spinlocks, init queues etc.
* This function is called during new client creation
*/
static void ishtp_cl_init(struct ishtp_cl *cl, struct ishtp_device *dev)
{
memset(cl, 0, sizeof(struct ishtp_cl));
init_waitqueue_head(&cl->wait_ctrl_res);
spin_lock_init(&cl->free_list_spinlock);
spin_lock_init(&cl->in_process_spinlock);
spin_lock_init(&cl->tx_list_spinlock);
spin_lock_init(&cl->tx_free_list_spinlock);
spin_lock_init(&cl->fc_spinlock);
INIT_LIST_HEAD(&cl->link);
cl->dev = dev;
INIT_LIST_HEAD(&cl->free_rb_list.list);
INIT_LIST_HEAD(&cl->tx_list.list);
INIT_LIST_HEAD(&cl->tx_free_list.list);
INIT_LIST_HEAD(&cl->in_process_list.list);
cl->rx_ring_size = CL_DEF_RX_RING_SIZE;
cl<