mei_dev.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. /*
  2. *
  3. * Intel Management Engine Interface (Intel MEI) Linux driver
  4. * Copyright (c) 2003-2012, 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. */
  16. #ifndef _MEI_DEV_H_
  17. #define _MEI_DEV_H_
  18. #include <linux/types.h>
  19. #include <linux/watchdog.h>
  20. #include <linux/poll.h>
  21. #include <linux/mei.h>
  22. #include "hw.h"
  23. #include "hw-me-regs.h"
  24. /*
  25. * watch dog definition
  26. */
  27. #define MEI_WD_HDR_SIZE 4
  28. #define MEI_WD_STOP_MSG_SIZE MEI_WD_HDR_SIZE
  29. #define MEI_WD_START_MSG_SIZE (MEI_WD_HDR_SIZE + 16)
  30. #define MEI_WD_DEFAULT_TIMEOUT 120 /* seconds */
  31. #define MEI_WD_MIN_TIMEOUT 120 /* seconds */
  32. #define MEI_WD_MAX_TIMEOUT 65535 /* seconds */
  33. #define MEI_WD_STOP_TIMEOUT 10 /* msecs */
  34. #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0)
  35. #define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32))
  36. /*
  37. * AMTHI Client UUID
  38. */
  39. extern const uuid_le mei_amthif_guid;
  40. /*
  41. * Watchdog Client UUID
  42. */
  43. extern const uuid_le mei_wd_guid;
  44. /*
  45. * Watchdog independence state message
  46. */
  47. extern const u8 mei_wd_state_independence_msg[3][4];
  48. /*
  49. * Number of Maximum MEI Clients
  50. */
  51. #define MEI_CLIENTS_MAX 256
  52. /*
  53. * Number of File descriptors/handles
  54. * that can be opened to the driver.
  55. *
  56. * Limit to 255: 256 Total Clients
  57. * minus internal client for MEI Bus Messags
  58. */
  59. #define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 1)
  60. /*
  61. * Internal Clients Number
  62. */
  63. #define MEI_HOST_CLIENT_ID_ANY (-1)
  64. #define MEI_HBM_HOST_CLIENT_ID 0 /* not used, just for documentation */
  65. #define MEI_WD_HOST_CLIENT_ID 1
  66. #define MEI_IAMTHIF_HOST_CLIENT_ID 2
  67. /* File state */
  68. enum file_state {
  69. MEI_FILE_INITIALIZING = 0,
  70. MEI_FILE_CONNECTING,
  71. MEI_FILE_CONNECTED,
  72. MEI_FILE_DISCONNECTING,
  73. MEI_FILE_DISCONNECTED
  74. };
  75. /* MEI device states */
  76. enum mei_dev_state {
  77. MEI_DEV_INITIALIZING = 0,
  78. MEI_DEV_INIT_CLIENTS,
  79. MEI_DEV_ENABLED,
  80. MEI_DEV_RESETING,
  81. MEI_DEV_DISABLED,
  82. MEI_DEV_RECOVERING_FROM_RESET,
  83. MEI_DEV_POWER_DOWN,
  84. MEI_DEV_POWER_UP
  85. };
  86. const char *mei_dev_state_str(int state);
  87. /* init clients states*/
  88. enum mei_init_clients_states {
  89. MEI_START_MESSAGE = 0,
  90. MEI_ENUM_CLIENTS_MESSAGE,
  91. MEI_CLIENT_PROPERTIES_MESSAGE
  92. };
  93. enum iamthif_states {
  94. MEI_IAMTHIF_IDLE,
  95. MEI_IAMTHIF_WRITING,
  96. MEI_IAMTHIF_FLOW_CONTROL,
  97. MEI_IAMTHIF_READING,
  98. MEI_IAMTHIF_READ_COMPLETE
  99. };
  100. enum mei_file_transaction_states {
  101. MEI_IDLE,
  102. MEI_WRITING,
  103. MEI_WRITE_COMPLETE,
  104. MEI_FLOW_CONTROL,
  105. MEI_READING,
  106. MEI_READ_COMPLETE
  107. };
  108. enum mei_wd_states {
  109. MEI_WD_IDLE,
  110. MEI_WD_RUNNING,
  111. MEI_WD_STOPPING,
  112. };
  113. /**
  114. * enum mei_cb_file_ops - file operation associated with the callback
  115. * @MEI_FOP_READ - read
  116. * @MEI_FOP_WRITE - write
  117. * @MEI_FOP_IOCTL - ioctl
  118. * @MEI_FOP_OPEN - open
  119. * @MEI_FOP_CLOSE - close
  120. */
  121. enum mei_cb_file_ops {
  122. MEI_FOP_READ = 0,
  123. MEI_FOP_WRITE,
  124. MEI_FOP_IOCTL,
  125. MEI_FOP_OPEN,
  126. MEI_FOP_CLOSE
  127. };
  128. /*
  129. * Intel MEI message data struct
  130. */
  131. struct mei_message_data {
  132. u32 size;
  133. unsigned char *data;
  134. };
  135. /**
  136. * struct mei_me_client - representation of me (fw) client
  137. *
  138. * @props - client properties
  139. * @client_id - me client id
  140. * @mei_flow_ctrl_creds - flow control credits
  141. */
  142. struct mei_me_client {
  143. struct mei_client_properties props;
  144. u8 client_id;
  145. u8 mei_flow_ctrl_creds;
  146. };
  147. struct mei_cl;
  148. /**
  149. * struct mei_cl_cb - file operation callback structure
  150. *
  151. * @cl - file client who is running this operation
  152. * @fop_type - file operation type
  153. */
  154. struct mei_cl_cb {
  155. struct list_head list;
  156. struct mei_cl *cl;
  157. enum mei_cb_file_ops fop_type;
  158. struct mei_message_data request_buffer;
  159. struct mei_message_data response_buffer;
  160. unsigned long buf_idx;
  161. unsigned long read_time;
  162. struct file *file_object;
  163. };
  164. /* MEI client instance carried as file->pirvate_data*/
  165. struct mei_cl {
  166. struct list_head link;
  167. struct mei_device *dev;
  168. enum file_state state;
  169. wait_queue_head_t tx_wait;
  170. wait_queue_head_t rx_wait;
  171. wait_queue_head_t wait;
  172. int status;
  173. /* ID of client connected */
  174. u8 host_client_id;
  175. u8 me_client_id;
  176. u8 mei_flow_ctrl_creds;
  177. u8 timer_count;
  178. enum mei_file_transaction_states reading_state;
  179. enum mei_file_transaction_states writing_state;
  180. int sm_state;
  181. struct mei_cl_cb *read_cb;
  182. };
  183. /**
  184. * struct mei_device - MEI private device struct
  185. * @mem_addr - mem mapped base register address
  186. * @hbuf_depth - depth of host(write) buffer
  187. * @wr_ext_msg - buffer for hbm control responses (set in read cycle)
  188. */
  189. struct mei_device {
  190. struct pci_dev *pdev; /* pointer to pci device struct */
  191. /*
  192. * lists of queues
  193. */
  194. /* array of pointers to aio lists */
  195. struct mei_cl_cb read_list; /* driver read queue */
  196. struct mei_cl_cb write_list; /* driver write queue */
  197. struct mei_cl_cb write_waiting_list; /* write waiting queue */
  198. struct mei_cl_cb ctrl_wr_list; /* managed write IOCTL list */
  199. struct mei_cl_cb ctrl_rd_list; /* managed read IOCTL list */
  200. /*
  201. * list of files
  202. */
  203. struct list_head file_list;
  204. long open_handle_count;
  205. void __iomem *mem_addr;
  206. /*
  207. * lock for the device
  208. */
  209. struct mutex device_lock; /* device lock */
  210. struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */
  211. bool recvd_msg;
  212. /*
  213. * hw states of host and fw(ME)
  214. */
  215. u32 host_hw_state;
  216. u32 me_hw_state;
  217. u8 hbuf_depth;
  218. /*
  219. * waiting queue for receive message from FW
  220. */
  221. wait_queue_head_t wait_recvd_msg;
  222. wait_queue_head_t wait_stop_wd;
  223. /*
  224. * mei device states
  225. */
  226. enum mei_dev_state dev_state;
  227. enum mei_init_clients_states init_clients_state;
  228. u16 init_clients_timer;
  229. unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */
  230. u32 rd_msg_hdr;
  231. /* used for control messages */
  232. struct {
  233. struct mei_msg_hdr hdr;
  234. unsigned char data[128];
  235. } wr_msg;
  236. struct {
  237. struct mei_msg_hdr hdr;
  238. unsigned char data[4]; /* All HBM messages are 4 bytes */
  239. } wr_ext_msg; /* for control responses */
  240. struct hbm_version version;
  241. struct mei_me_client *me_clients; /* Note: memory has to be allocated */
  242. DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
  243. DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
  244. u8 me_clients_num;
  245. u8 me_client_presentation_num;
  246. u8 me_client_index;
  247. bool mei_host_buffer_is_empty;
  248. struct mei_cl wd_cl;
  249. enum mei_wd_states wd_state;
  250. bool wd_pending;
  251. u16 wd_timeout;
  252. unsigned char wd_data[MEI_WD_START_MSG_SIZE];
  253. /* amthif list for cmd waiting */
  254. struct mei_cl_cb amthif_cmd_list;
  255. /* driver managed amthif list for reading completed amthif cmd data */
  256. struct mei_cl_cb amthif_rd_complete_list;
  257. struct file *iamthif_file_object;
  258. struct mei_cl iamthif_cl;
  259. struct mei_cl_cb *iamthif_current_cb;
  260. int iamthif_mtu;
  261. unsigned long iamthif_timer;
  262. u32 iamthif_stall_timer;
  263. unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
  264. u32 iamthif_msg_buf_size;
  265. u32 iamthif_msg_buf_index;
  266. enum iamthif_states iamthif_state;
  267. bool iamthif_flow_control_pending;
  268. bool iamthif_ioctl;
  269. bool iamthif_canceled;
  270. struct work_struct init_work;
  271. };
  272. static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
  273. {
  274. return msecs_to_jiffies(sec * MSEC_PER_SEC);
  275. }
  276. /*
  277. * mei init function prototypes
  278. */
  279. struct mei_device *mei_device_init(struct pci_dev *pdev);
  280. void mei_reset(struct mei_device *dev, int interrupts);
  281. int mei_hw_init(struct mei_device *dev);
  282. /*
  283. * MEI interrupt functions prototype
  284. */
  285. irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
  286. irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
  287. void mei_timer(struct work_struct *work);
  288. /*
  289. * AMTHIF - AMT Host Interface Functions
  290. */
  291. void mei_amthif_reset_params(struct mei_device *dev);
  292. int mei_amthif_host_init(struct mei_device *dev);
  293. int mei_amthif_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
  294. int mei_amthif_read(struct mei_device *dev, struct file *file,
  295. char __user *ubuf, size_t length, loff_t *offset);
  296. unsigned int mei_amthif_poll(struct mei_device *dev,
  297. struct file *file, poll_table *wait);
  298. int mei_amthif_release(struct mei_device *dev, struct file *file);
  299. struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev,
  300. struct file *file);
  301. void mei_amthif_run_next_cmd(struct mei_device *dev);
  302. int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots,
  303. struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list);
  304. void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb);
  305. int mei_amthif_irq_read_message(struct mei_cl_cb *complete_list,
  306. struct mei_device *dev, struct mei_msg_hdr *mei_hdr);
  307. int mei_amthif_irq_read(struct mei_device *dev, s32 *slots);
  308. int mei_wd_send(struct mei_device *dev);
  309. int mei_wd_stop(struct mei_device *dev);
  310. int mei_wd_host_init(struct mei_device *dev);
  311. /*
  312. * mei_watchdog_register - Registering watchdog interface
  313. * once we got connection to the WD Client
  314. * @dev - mei device
  315. */
  316. void mei_watchdog_register(struct mei_device *dev);
  317. /*
  318. * mei_watchdog_unregister - Unregistering watchdog interface
  319. * @dev - mei device
  320. */
  321. void mei_watchdog_unregister(struct mei_device *dev);
  322. /*
  323. * Register Access Function
  324. */
  325. void mei_hw_config(struct mei_device *dev);
  326. void mei_hw_reset(struct mei_device *dev, bool intr_enable);
  327. u32 mei_mecbrw_read(const struct mei_device *dev);
  328. void mei_clear_interrupts(struct mei_device *dev);
  329. void mei_enable_interrupts(struct mei_device *dev);
  330. void mei_disable_interrupts(struct mei_device *dev);
  331. void mei_host_set_ready(struct mei_device *dev);
  332. bool mei_host_is_ready(struct mei_device *dev);
  333. bool mei_me_is_ready(struct mei_device *dev);
  334. #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d comp=%1d"
  335. #define MEI_HDR_PRM(hdr) \
  336. (hdr)->host_addr, (hdr)->me_addr, \
  337. (hdr)->length, (hdr)->msg_complete
  338. #endif