ishtp-dev.h 7.3 KB

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