ishtp-dev.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Most ISHTP provider device and ISHTP logic declarations
  4. *
  5. * Copyright (c) 2003-2016, Intel Corporation.
  6. */
  7. #ifndef _ISHTP_DEV_H_
  8. #define _ISHTP_DEV_H_
  9. #include <linux/types.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/intel-ish-client-if.h>
  12. #include "bus.h"
  13. #include "hbm.h"
  14. #define IPC_PAYLOAD_SIZE 128
  15. #define ISHTP_RD_MSG_BUF_SIZE IPC_PAYLOAD_SIZE
  16. #define IPC_FULL_MSG_SIZE 132
  17. /* Number of messages to be held in ISR->BH FIFO */
  18. #define RD_INT_FIFO_SIZE 64
  19. /*
  20. * Number of IPC messages to be held in Tx FIFO, to be sent by ISR -
  21. * Tx complete interrupt or RX_COMPLETE handler
  22. */
  23. #define IPC_TX_FIFO_SIZE 512
  24. /*
  25. * Number of Maximum ISHTP Clients
  26. */
  27. #define ISHTP_CLIENTS_MAX 256
  28. /*
  29. * Number of File descriptors/handles
  30. * that can be opened to the driver.
  31. *
  32. * Limit to 255: 256 Total Clients
  33. * minus internal client for ISHTP Bus Messages
  34. */
  35. #define ISHTP_MAX_OPEN_HANDLE_COUNT (ISHTP_CLIENTS_MAX - 1)
  36. /* Internal Clients Number */
  37. #define ISHTP_HOST_CLIENT_ID_ANY (-1)
  38. #define ISHTP_HBM_HOST_CLIENT_ID 0
  39. #define MAX_DMA_DELAY 20
  40. /* ISHTP device states */
  41. enum ishtp_dev_state {
  42. ISHTP_DEV_INITIALIZING = 0,
  43. ISHTP_DEV_INIT_CLIENTS,
  44. ISHTP_DEV_ENABLED,
  45. ISHTP_DEV_RESETTING,
  46. ISHTP_DEV_DISABLED,
  47. ISHTP_DEV_POWER_DOWN,
  48. ISHTP_DEV_POWER_UP
  49. };
  50. const char *ishtp_dev_state_str(int state);
  51. struct ishtp_cl;
  52. /**
  53. * struct ishtp_fw_client - representation of fw client
  54. *
  55. * @props - client properties
  56. * @client_id - fw client id
  57. */
  58. struct ishtp_fw_client {
  59. struct ishtp_client_properties props;
  60. uint8_t client_id;
  61. };
  62. /*
  63. * Control info for IPC messages ISHTP/IPC sending FIFO -
  64. * list with inline data buffer
  65. * This structure will be filled with parameters submitted
  66. * by the caller glue layer
  67. * 'buf' may be pointing to the external buffer or to 'inline_data'
  68. * 'offset' will be initialized to 0 by submitting
  69. *
  70. * 'ipc_send_compl' is intended for use by clients that send fragmented
  71. * messages. When a fragment is sent down to IPC msg regs,
  72. * it will be called.
  73. * If it has more fragments to send, it will do it. With last fragment
  74. * it will send appropriate ISHTP "message-complete" flag.
  75. * It will remove the outstanding message
  76. * (mark outstanding buffer as available).
  77. * If counting flow control is in work and there are more flow control
  78. * credits, it can put the next client message queued in cl.
  79. * structure for IPC processing.
  80. *
  81. */
  82. struct wr_msg_ctl_info {
  83. /* Will be called with 'ipc_send_compl_prm' as parameter */
  84. void (*ipc_send_compl)(void *);
  85. void *ipc_send_compl_prm;
  86. size_t length;
  87. struct list_head link;
  88. unsigned char inline_data[IPC_FULL_MSG_SIZE];
  89. };
  90. /*
  91. * The ISHTP layer talks to hardware IPC message using the following
  92. * callbacks
  93. */
  94. struct ishtp_hw_ops {
  95. int (*hw_reset)(struct ishtp_device *dev);
  96. int (*ipc_reset)(struct ishtp_device *dev);
  97. uint32_t (*ipc_get_header)(struct ishtp_device *dev, int length,
  98. int busy);
  99. int (*write)(struct ishtp_device *dev,
  100. void (*ipc_send_compl)(void *), void *ipc_send_compl_prm,
  101. unsigned char *msg, int length);
  102. uint32_t (*ishtp_read_hdr)(const struct ishtp_device *dev);
  103. int (*ishtp_read)(struct ishtp_device *dev, unsigned char *buffer,
  104. unsigned long buffer_length);
  105. uint32_t (*get_fw_status)(struct ishtp_device *dev);
  106. void (*sync_fw_clock)(struct ishtp_device *dev);
  107. bool (*dma_no_cache_snooping)(struct ishtp_device *dev);
  108. };
  109. /**
  110. * struct ishtp_device - ISHTP private device struct
  111. */
  112. struct ishtp_device {
  113. struct device *devc; /* pointer to lowest device */
  114. struct pci_dev *pdev; /* PCI device to get device ids */
  115. /* waitq for waiting for suspend response */
  116. wait_queue_head_t suspend_wait;
  117. bool suspend_flag; /* Suspend is active */
  118. /* waitq for waiting for resume response */
  119. wait_queue_head_t resume_wait;
  120. bool resume_flag; /*Resume is active */
  121. /*
  122. * lock for the device, for everything that doesn't have
  123. * a dedicated spinlock
  124. */
  125. spinlock_t device_lock;
  126. bool recvd_hw_ready;
  127. struct hbm_version version;
  128. int transfer_path; /* Choice of transfer path: IPC or DMA */
  129. /* ishtp device states */
  130. enum ishtp_dev_state dev_state;
  131. enum ishtp_hbm_state hbm_state;
  132. /* driver read queue */
  133. struct ishtp_cl_rb read_list;
  134. spinlock_t read_list_spinlock;
  135. /* list of ishtp_cl's */
  136. struct list_head cl_list;
  137. spinlock_t cl_list_lock;
  138. long open_handle_count;
  139. /* List of bus devices */
  140. struct list_head device_list;
  141. spinlock_t device_list_lock;
  142. /* waiting queues for receive message from FW */
  143. wait_queue_head_t wait_hw_ready;
  144. wait_queue_head_t wait_hbm_recvd_msg;
  145. /* FIFO for input messages for BH processing */
  146. unsigned char rd_msg_fifo[RD_INT_FIFO_SIZE * IPC_PAYLOAD_SIZE];
  147. unsigned int rd_msg_fifo_head, rd_msg_fifo_tail;
  148. spinlock_t rd_msg_spinlock;
  149. struct work_struct bh_hbm_work;
  150. /* IPC write queue */
  151. struct list_head wr_processing_list, wr_free_list;
  152. /* For both processing list and free list */
  153. spinlock_t wr_processing_spinlock;
  154. struct ishtp_fw_client *fw_clients; /*Note:memory has to be allocated*/
  155. DECLARE_BITMAP(fw_clients_map, ISHTP_CLIENTS_MAX);
  156. DECLARE_BITMAP(host_clients_map, ISHTP_CLIENTS_MAX);
  157. uint8_t fw_clients_num;
  158. uint8_t fw_client_presentation_num;
  159. uint8_t fw_client_index;
  160. spinlock_t fw_clients_lock;
  161. /* TX DMA buffers and slots */
  162. int ishtp_host_dma_enabled;
  163. void *ishtp_host_dma_tx_buf;
  164. unsigned int ishtp_host_dma_tx_buf_size;
  165. uint64_t ishtp_host_dma_tx_buf_phys;
  166. int ishtp_dma_num_slots;
  167. /* map of 4k blocks in Tx dma buf: 0-free, 1-used */
  168. uint8_t *ishtp_dma_tx_map;
  169. spinlock_t ishtp_dma_tx_lock;
  170. /* RX DMA buffers and slots */
  171. void *ishtp_host_dma_rx_buf;
  172. unsigned int ishtp_host_dma_rx_buf_size;
  173. uint64_t ishtp_host_dma_rx_buf_phys;
  174. /* Dump to trace buffers if enabled*/
  175. ishtp_print_log print_log;
  176. /* Debug stats */
  177. unsigned int ipc_rx_cnt;
  178. unsigned long long ipc_rx_bytes_cnt;
  179. unsigned int ipc_tx_cnt;
  180. unsigned long long ipc_tx_bytes_cnt;
  181. const struct ishtp_hw_ops *ops;
  182. size_t mtu;
  183. uint32_t ishtp_msg_hdr;
  184. char hw[] __aligned(sizeof(void *));
  185. };
  186. static inline unsigned long ishtp_secs_to_jiffies(unsigned long sec)
  187. {
  188. return msecs_to_jiffies(sec * MSEC_PER_SEC);
  189. }
  190. /*
  191. * Register Access Function
  192. */
  193. static inline int ish_ipc_reset(struct ishtp_device *dev)
  194. {
  195. return dev->ops->ipc_reset(dev);
  196. }
  197. /* Exported function */
  198. void ishtp_device_init(struct ishtp_device *dev);
  199. int ishtp_start(struct ishtp_device *dev);
  200. #endif /*_ISHTP_DEV_H_*/