Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * ISHTP client logic
0004  *
0005  * Copyright (c) 2003-2016, Intel Corporation.
0006  */
0007 
0008 #ifndef _ISHTP_CLIENT_H_
0009 #define _ISHTP_CLIENT_H_
0010 
0011 #include <linux/types.h>
0012 #include "ishtp-dev.h"
0013 
0014 /* Tx and Rx ring size */
0015 #define CL_DEF_RX_RING_SIZE 2
0016 #define CL_DEF_TX_RING_SIZE 2
0017 #define CL_MAX_RX_RING_SIZE 32
0018 #define CL_MAX_TX_RING_SIZE 32
0019 
0020 #define DMA_SLOT_SIZE       4096
0021 /* Number of IPC fragments after which it's worth sending via DMA */
0022 #define DMA_WORTH_THRESHOLD 3
0023 
0024 /* DMA/IPC Tx paths. Other the default means enforcement */
0025 #define CL_TX_PATH_DEFAULT  0
0026 #define CL_TX_PATH_IPC      1
0027 #define CL_TX_PATH_DMA      2
0028 
0029 /* Client Tx buffer list entry */
0030 struct ishtp_cl_tx_ring {
0031     struct list_head    list;
0032     struct ishtp_msg_data   send_buf;
0033 };
0034 
0035 /* ISHTP client instance */
0036 struct ishtp_cl {
0037     struct list_head    link;
0038     struct ishtp_device *dev;
0039     enum cl_state       state;
0040     int         status;
0041 
0042     /* Link to ISHTP bus device */
0043     struct ishtp_cl_device  *device;
0044 
0045     /* ID of client connected */
0046     uint8_t host_client_id;
0047     uint8_t fw_client_id;
0048     uint8_t ishtp_flow_ctrl_creds;
0049     uint8_t out_flow_ctrl_creds;
0050 
0051     /* dma */
0052     int last_tx_path;
0053     /* 0: ack wasn't received,1:ack was received */
0054     int last_dma_acked;
0055     unsigned char   *last_dma_addr;
0056     /* 0: ack wasn't received,1:ack was received */
0057     int last_ipc_acked;
0058 
0059     /* Rx ring buffer pool */
0060     unsigned int    rx_ring_size;
0061     struct ishtp_cl_rb  free_rb_list;
0062     spinlock_t  free_list_spinlock;
0063     /* Rx in-process list */
0064     struct ishtp_cl_rb  in_process_list;
0065     spinlock_t  in_process_spinlock;
0066 
0067     /* Client Tx buffers list */
0068     unsigned int    tx_ring_size;
0069     struct ishtp_cl_tx_ring tx_list, tx_free_list;
0070     int     tx_ring_free_size;
0071     spinlock_t  tx_list_spinlock;
0072     spinlock_t  tx_free_list_spinlock;
0073     size_t  tx_offs;    /* Offset in buffer at head of 'tx_list' */
0074 
0075     /**
0076      * if we get a FC, and the list is not empty, we must know whether we
0077      * are at the middle of sending.
0078      * if so -need to increase FC counter, otherwise, need to start sending
0079      * the first msg in list
0080      * (!)This is for counting-FC implementation only. Within single-FC the
0081      * other party may NOT send FC until it receives complete message
0082      */
0083     int sending;
0084 
0085     /* Send FC spinlock */
0086     spinlock_t  fc_spinlock;
0087 
0088     /* wait queue for connect and disconnect response from FW */
0089     wait_queue_head_t   wait_ctrl_res;
0090 
0091     /* Error stats */
0092     unsigned int    err_send_msg;
0093     unsigned int    err_send_fc;
0094 
0095     /* Send/recv stats */
0096     unsigned int    send_msg_cnt_ipc;
0097     unsigned int    send_msg_cnt_dma;
0098     unsigned int    recv_msg_cnt_ipc;
0099     unsigned int    recv_msg_cnt_dma;
0100     unsigned int    recv_msg_num_frags;
0101     unsigned int    ishtp_flow_ctrl_cnt;
0102     unsigned int    out_flow_ctrl_cnt;
0103 
0104     /* Rx msg ... out FC timing */
0105     ktime_t ts_rx;
0106     ktime_t ts_out_fc;
0107     ktime_t ts_max_fc_delay;
0108     void *client_data;
0109 };
0110 
0111 /* Client connection managenment internal functions */
0112 int ishtp_can_client_connect(struct ishtp_device *ishtp_dev, guid_t *uuid);
0113 int ishtp_fw_cl_by_id(struct ishtp_device *dev, uint8_t client_id);
0114 void ishtp_cl_send_msg(struct ishtp_device *dev, struct ishtp_cl *cl);
0115 void recv_ishtp_cl_msg(struct ishtp_device *dev,
0116                struct ishtp_msg_hdr *ishtp_hdr);
0117 int ishtp_cl_read_start(struct ishtp_cl *cl);
0118 
0119 /* Ring Buffer I/F */
0120 int ishtp_cl_alloc_rx_ring(struct ishtp_cl *cl);
0121 int ishtp_cl_alloc_tx_ring(struct ishtp_cl *cl);
0122 void ishtp_cl_free_rx_ring(struct ishtp_cl *cl);
0123 void ishtp_cl_free_tx_ring(struct ishtp_cl *cl);
0124 int ishtp_cl_get_tx_free_buffer_size(struct ishtp_cl *cl);
0125 int ishtp_cl_get_tx_free_rings(struct ishtp_cl *cl);
0126 
0127 /* DMA I/F functions */
0128 void recv_ishtp_cl_msg_dma(struct ishtp_device *dev, void *msg,
0129                struct dma_xfer_hbm *hbm);
0130 void ishtp_cl_alloc_dma_buf(struct ishtp_device *dev);
0131 void ishtp_cl_free_dma_buf(struct ishtp_device *dev);
0132 void *ishtp_cl_get_dma_send_buf(struct ishtp_device *dev,
0133                 uint32_t size);
0134 void ishtp_cl_release_dma_acked_mem(struct ishtp_device *dev,
0135                     void *msg_addr,
0136                     uint8_t size);
0137 
0138 /* Request blocks alloc/free I/F */
0139 struct ishtp_cl_rb *ishtp_io_rb_init(struct ishtp_cl *cl);
0140 void ishtp_io_rb_free(struct ishtp_cl_rb *priv_rb);
0141 int ishtp_io_rb_alloc_buf(struct ishtp_cl_rb *rb, size_t length);
0142 
0143 /**
0144  * ishtp_cl_cmp_id - tells if file private data have same id
0145  * returns true  - if ids are the same and not NULL
0146  */
0147 static inline bool ishtp_cl_cmp_id(const struct ishtp_cl *cl1,
0148                    const struct ishtp_cl *cl2)
0149 {
0150     return cl1 && cl2 &&
0151         (cl1->host_client_id == cl2->host_client_id) &&
0152         (cl1->fw_client_id == cl2->fw_client_id);
0153 }
0154 
0155 #endif /* _ISHTP_CLIENT_H_ */