^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * ISHTP client logic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2003-2016, Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef _ISHTP_CLIENT_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define _ISHTP_CLIENT_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "ishtp-dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /* Tx and Rx ring size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define CL_DEF_RX_RING_SIZE 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define CL_DEF_TX_RING_SIZE 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define CL_MAX_RX_RING_SIZE 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define CL_MAX_TX_RING_SIZE 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define DMA_SLOT_SIZE 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /* Number of IPC fragments after which it's worth sending via DMA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define DMA_WORTH_THRESHOLD 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* DMA/IPC Tx paths. Other the default means enforcement */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define CL_TX_PATH_DEFAULT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define CL_TX_PATH_IPC 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define CL_TX_PATH_DMA 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* Client Tx buffer list entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct ishtp_cl_tx_ring {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct ishtp_msg_data send_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* ISHTP client instance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct ishtp_cl {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct list_head link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct ishtp_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) enum cl_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* Link to ISHTP bus device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct ishtp_cl_device *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* ID of client connected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) uint8_t host_client_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) uint8_t fw_client_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) uint8_t ishtp_flow_ctrl_creds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) uint8_t out_flow_ctrl_creds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* dma */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int last_tx_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /* 0: ack wasn't received,1:ack was received */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int last_dma_acked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) unsigned char *last_dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* 0: ack wasn't received,1:ack was received */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int last_ipc_acked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* Rx ring buffer pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) unsigned int rx_ring_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct ishtp_cl_rb free_rb_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) spinlock_t free_list_spinlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* Rx in-process list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct ishtp_cl_rb in_process_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) spinlock_t in_process_spinlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* Client Tx buffers list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) unsigned int tx_ring_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct ishtp_cl_tx_ring tx_list, tx_free_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int tx_ring_free_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) spinlock_t tx_list_spinlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) spinlock_t tx_free_list_spinlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) size_t tx_offs; /* Offset in buffer at head of 'tx_list' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * if we get a FC, and the list is not empty, we must know whether we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * are at the middle of sending.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * if so -need to increase FC counter, otherwise, need to start sending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * the first msg in list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * (!)This is for counting-FC implementation only. Within single-FC the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * other party may NOT send FC until it receives complete message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) int sending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* Send FC spinlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) spinlock_t fc_spinlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* wait queue for connect and disconnect response from FW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) wait_queue_head_t wait_ctrl_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* Error stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) unsigned int err_send_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) unsigned int err_send_fc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /* Send/recv stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) unsigned int send_msg_cnt_ipc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unsigned int send_msg_cnt_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) unsigned int recv_msg_cnt_ipc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) unsigned int recv_msg_cnt_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) unsigned int recv_msg_num_frags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) unsigned int ishtp_flow_ctrl_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) unsigned int out_flow_ctrl_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* Rx msg ... out FC timing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ktime_t ts_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ktime_t ts_out_fc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ktime_t ts_max_fc_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) void *client_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* Client connection managenment internal functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int ishtp_can_client_connect(struct ishtp_device *ishtp_dev, guid_t *uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) int ishtp_fw_cl_by_id(struct ishtp_device *dev, uint8_t client_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) void ishtp_cl_send_msg(struct ishtp_device *dev, struct ishtp_cl *cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) void recv_ishtp_cl_msg(struct ishtp_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct ishtp_msg_hdr *ishtp_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int ishtp_cl_read_start(struct ishtp_cl *cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* Ring Buffer I/F */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int ishtp_cl_alloc_rx_ring(struct ishtp_cl *cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int ishtp_cl_alloc_tx_ring(struct ishtp_cl *cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) void ishtp_cl_free_rx_ring(struct ishtp_cl *cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) void ishtp_cl_free_tx_ring(struct ishtp_cl *cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int ishtp_cl_get_tx_free_buffer_size(struct ishtp_cl *cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int ishtp_cl_get_tx_free_rings(struct ishtp_cl *cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* DMA I/F functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) void recv_ishtp_cl_msg_dma(struct ishtp_device *dev, void *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct dma_xfer_hbm *hbm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void ishtp_cl_alloc_dma_buf(struct ishtp_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) void ishtp_cl_free_dma_buf(struct ishtp_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) void *ishtp_cl_get_dma_send_buf(struct ishtp_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) uint32_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) void ishtp_cl_release_dma_acked_mem(struct ishtp_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) void *msg_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) uint8_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /* Request blocks alloc/free I/F */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct ishtp_cl_rb *ishtp_io_rb_init(struct ishtp_cl *cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) void ishtp_io_rb_free(struct ishtp_cl_rb *priv_rb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int ishtp_io_rb_alloc_buf(struct ishtp_cl_rb *rb, size_t length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * ishtp_cl_cmp_id - tells if file private data have same id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * returns true - if ids are the same and not NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static inline bool ishtp_cl_cmp_id(const struct ishtp_cl *cl1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) const struct ishtp_cl *cl2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return cl1 && cl2 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) (cl1->host_client_id == cl2->host_client_id) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) (cl1->fw_client_id == cl2->fw_client_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #endif /* _ISHTP_CLIENT_H_ */