ishtp-dev.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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_driver_data - Driver-specific data for ISHTP devices
  111. *
  112. * This structure holds driver-specific data that can be associated with each
  113. * ISHTP device instance. It allows for the storage of data that is unique to
  114. * a particular driver or hardware variant.
  115. *
  116. * @fw_generation: The generation name associated with a specific hardware
  117. * variant of the Intel Integrated Sensor Hub (ISH). This allows
  118. * the driver to load the correct firmware based on the device's
  119. * hardware variant. For example, "lnlm" for the Lunar Lake-M
  120. * platform. The generation name must not exceed 8 characters
  121. * in length.
  122. */
  123. struct ishtp_driver_data {
  124. char *fw_generation;
  125. };
  126. /**
  127. * struct ishtp_device - ISHTP private device struct
  128. */
  129. struct ishtp_device {
  130. struct device *devc; /* pointer to lowest device */
  131. struct pci_dev *pdev; /* PCI device to get device ids */
  132. struct ishtp_driver_data *driver_data; /* pointer to driver-specific data */
  133. /* waitq for waiting for suspend response */
  134. wait_queue_head_t suspend_wait;
  135. bool suspend_flag; /* Suspend is active */
  136. /* waitq for waiting for resume response */
  137. wait_queue_head_t resume_wait;
  138. bool resume_flag; /*Resume is active */
  139. /*
  140. * lock for the device, for everything that doesn't have
  141. * a dedicated spinlock
  142. */
  143. spinlock_t device_lock;
  144. bool recvd_hw_ready;
  145. struct hbm_version version;
  146. int transfer_path; /* Choice of transfer path: IPC or DMA */
  147. /* work structure for scheduling firmware loading tasks */
  148. struct work_struct work_fw_loader;
  149. /* waitq for waiting for command response from the firmware loader */
  150. wait_queue_head_t wait_loader_recvd_msg;
  151. /* indicating whether a message from the firmware loader has been received */
  152. bool fw_loader_received;
  153. /* pointer to a buffer for receiving messages from the firmware loader */
  154. void *fw_loader_rx_buf;
  155. /* size of the buffer pointed to by fw_loader_rx_buf */
  156. int fw_loader_rx_size;
  157. /* ishtp device states */
  158. enum ishtp_dev_state dev_state;
  159. enum ishtp_hbm_state hbm_state;
  160. /* driver read queue */
  161. struct ishtp_cl_rb read_list;
  162. spinlock_t read_list_spinlock;
  163. /* list of ishtp_cl's */
  164. struct list_head cl_list;
  165. spinlock_t cl_list_lock;
  166. long open_handle_count;
  167. /* List of bus devices */
  168. struct list_head device_list;
  169. spinlock_t device_list_lock;
  170. /* waiting queues for receive message from FW */
  171. wait_queue_head_t wait_hw_ready;
  172. wait_queue_head_t wait_hbm_recvd_msg;
  173. /* FIFO for input messages for BH processing */
  174. unsigned char rd_msg_fifo[RD_INT_FIFO_SIZE * IPC_PAYLOAD_SIZE];
  175. unsigned int rd_msg_fifo_head, rd_msg_fifo_tail;
  176. spinlock_t rd_msg_spinlock;
  177. struct work_struct bh_hbm_work;
  178. /* IPC write queue */
  179. struct list_head wr_processing_list, wr_free_list;
  180. /* For both processing list and free list */
  181. spinlock_t wr_processing_spinlock;
  182. struct ishtp_fw_client *fw_clients; /*Note:memory has to be allocated*/
  183. DECLARE_BITMAP(fw_clients_map, ISHTP_CLIENTS_MAX);
  184. DECLARE_BITMAP(host_clients_map, ISHTP_CLIENTS_MAX);
  185. uint8_t fw_clients_num;
  186. uint8_t fw_client_presentation_num;
  187. uint8_t fw_client_index;
  188. spinlock_t fw_clients_lock;
  189. /* TX DMA buffers and slots */
  190. int ishtp_host_dma_enabled;
  191. void *ishtp_host_dma_tx_buf;
  192. unsigned int ishtp_host_dma_tx_buf_size;
  193. uint64_t ishtp_host_dma_tx_buf_phys;
  194. int ishtp_dma_num_slots;
  195. /* map of 4k blocks in Tx dma buf: 0-free, 1-used */
  196. uint8_t *ishtp_dma_tx_map;
  197. spinlock_t ishtp_dma_tx_lock;
  198. /* RX DMA buffers and slots */
  199. void *ishtp_host_dma_rx_buf;
  200. unsigned int ishtp_host_dma_rx_buf_size;
  201. uint64_t ishtp_host_dma_rx_buf_phys;
  202. /* Dump to trace buffers if enabled*/
  203. ishtp_print_log print_log;
  204. /* Debug stats */
  205. unsigned int ipc_rx_cnt;
  206. unsigned long long ipc_rx_bytes_cnt;
  207. unsigned int ipc_tx_cnt;
  208. unsigned long long ipc_tx_bytes_cnt;
  209. /* Time of the last clock sync */
  210. unsigned long prev_sync;
  211. const struct ishtp_hw_ops *ops;
  212. size_t mtu;
  213. uint32_t ishtp_msg_hdr;
  214. char hw[] __aligned(sizeof(void *));
  215. };
  216. static inline unsigned long ishtp_secs_to_jiffies(unsigned long sec)
  217. {
  218. return msecs_to_jiffies(sec * MSEC_PER_SEC);
  219. }
  220. /*
  221. * Register Access Function
  222. */
  223. static inline int ish_ipc_reset(struct ishtp_device *dev)
  224. {
  225. return dev->ops->ipc_reset(dev);
  226. }
  227. /* Exported function */
  228. void ishtp_device_init(struct ishtp_device *dev);
  229. int ishtp_start(struct ishtp_device *dev);
  230. #endif /*_ISHTP_DEV_H_*/