client.h 5.4 KB

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