client.h 4.4 KB

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