mei_dev.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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/mei.h>
  21. #include "hw.h"
  22. /*
  23. * watch dog definition
  24. */
  25. #define MEI_WD_HDR_SIZE 4
  26. #define MEI_WD_STOP_MSG_SIZE MEI_WD_HDR_SIZE
  27. #define MEI_WD_START_MSG_SIZE (MEI_WD_HDR_SIZE + 16)
  28. #define MEI_WD_DEFAULT_TIMEOUT 120 /* seconds */
  29. #define MEI_WD_MIN_TIMEOUT 120 /* seconds */
  30. #define MEI_WD_MAX_TIMEOUT 65535 /* seconds */
  31. #define MEI_WD_STOP_TIMEOUT 10 /* msecs */
  32. #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0)
  33. #define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32))
  34. /*
  35. * AMTHI Client UUID
  36. */
  37. extern const uuid_le mei_amthi_guid;
  38. /*
  39. * Watchdog Client UUID
  40. */
  41. extern const uuid_le mei_wd_guid;
  42. /*
  43. * Watchdog independence state message
  44. */
  45. extern const u8 mei_wd_state_independence_msg[3][4];
  46. /*
  47. * Number of Maximum MEI Clients
  48. */
  49. #define MEI_CLIENTS_MAX 256
  50. /*
  51. * Number of File descriptors/handles
  52. * that can be opened to the driver.
  53. *
  54. * Limit to 253: 256 Total Clients
  55. * minus internal client for MEI Bus Messags
  56. * minus internal client for AMTHI
  57. * minus internal client for Watchdog
  58. */
  59. #define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 3)
  60. /* File state */
  61. enum file_state {
  62. MEI_FILE_INITIALIZING = 0,
  63. MEI_FILE_CONNECTING,
  64. MEI_FILE_CONNECTED,
  65. MEI_FILE_DISCONNECTING,
  66. MEI_FILE_DISCONNECTED
  67. };
  68. /* MEI device states */
  69. enum mei_dev_state {
  70. MEI_DEV_INITIALIZING = 0,
  71. MEI_DEV_INIT_CLIENTS,
  72. MEI_DEV_ENABLED,
  73. MEI_DEV_RESETING,
  74. MEI_DEV_DISABLED,
  75. MEI_DEV_RECOVERING_FROM_RESET,
  76. MEI_DEV_POWER_DOWN,
  77. MEI_DEV_POWER_UP
  78. };
  79. const char *mei_dev_state_str(int state);
  80. /* init clients states*/
  81. enum mei_init_clients_states {
  82. MEI_START_MESSAGE = 0,
  83. MEI_ENUM_CLIENTS_MESSAGE,
  84. MEI_CLIENT_PROPERTIES_MESSAGE
  85. };
  86. enum iamthif_states {
  87. MEI_IAMTHIF_IDLE,
  88. MEI_IAMTHIF_WRITING,
  89. MEI_IAMTHIF_FLOW_CONTROL,
  90. MEI_IAMTHIF_READING,
  91. MEI_IAMTHIF_READ_COMPLETE
  92. };
  93. enum mei_file_transaction_states {
  94. MEI_IDLE,
  95. MEI_WRITING,
  96. MEI_WRITE_COMPLETE,
  97. MEI_FLOW_CONTROL,
  98. MEI_READING,
  99. MEI_READ_COMPLETE
  100. };
  101. enum mei_wd_states {
  102. MEI_WD_IDLE,
  103. MEI_WD_RUNNING,
  104. MEI_WD_STOPPING,
  105. };
  106. /* MEI CB */
  107. enum mei_cb_major_types {
  108. MEI_READ = 0,
  109. MEI_WRITE,
  110. MEI_IOCTL,
  111. MEI_OPEN,
  112. MEI_CLOSE
  113. };
  114. /*
  115. * Intel MEI message data struct
  116. */
  117. struct mei_message_data {
  118. u32 size;
  119. unsigned char *data;
  120. };
  121. struct mei_cl;
  122. /*
  123. * struct mei_cl_cb - file operation callback structure
  124. *
  125. * @cl - file client who is running this operation
  126. */
  127. struct mei_cl_cb {
  128. struct list_head list;
  129. struct mei_cl *cl;
  130. enum mei_cb_major_types major_file_operations;
  131. struct mei_message_data request_buffer;
  132. struct mei_message_data response_buffer;
  133. unsigned long buf_idx;
  134. unsigned long read_time;
  135. struct file *file_object;
  136. };
  137. /* MEI client instance carried as file->pirvate_data*/
  138. struct mei_cl {
  139. struct list_head link;
  140. struct mei_device *dev;
  141. enum file_state state;
  142. wait_queue_head_t tx_wait;
  143. wait_queue_head_t rx_wait;
  144. wait_queue_head_t wait;
  145. int read_pending;
  146. int status;
  147. /* ID of client connected */
  148. u8 host_client_id;
  149. u8 me_client_id;
  150. u8 mei_flow_ctrl_creds;
  151. u8 timer_count;
  152. enum mei_file_transaction_states reading_state;
  153. enum mei_file_transaction_states writing_state;
  154. int sm_state;
  155. struct mei_cl_cb *read_cb;
  156. };
  157. /**
  158. * struct mei_deive - MEI private device struct
  159. * @hbuf_depth - depth of host(write) buffer
  160. */
  161. struct mei_device {
  162. struct pci_dev *pdev; /* pointer to pci device struct */
  163. /*
  164. * lists of queues
  165. */
  166. /* array of pointers to aio lists */
  167. struct mei_cl_cb read_list; /* driver read queue */
  168. struct mei_cl_cb write_list; /* driver write queue */
  169. struct mei_cl_cb write_waiting_list; /* write waiting queue */
  170. struct mei_cl_cb ctrl_wr_list; /* managed write IOCTL list */
  171. struct mei_cl_cb ctrl_rd_list; /* managed read IOCTL list */
  172. /*
  173. * list of files
  174. */
  175. struct list_head file_list;
  176. long open_handle_count;
  177. /*
  178. * memory of device
  179. */
  180. unsigned int mem_base;
  181. unsigned int mem_length;
  182. void __iomem *mem_addr;
  183. /*
  184. * lock for the device
  185. */
  186. struct mutex device_lock; /* device lock */
  187. struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */
  188. bool recvd_msg;
  189. /*
  190. * hw states of host and fw(ME)
  191. */
  192. u32 host_hw_state;
  193. u32 me_hw_state;
  194. u8 hbuf_depth;
  195. /*
  196. * waiting queue for receive message from FW
  197. */
  198. wait_queue_head_t wait_recvd_msg;
  199. wait_queue_head_t wait_stop_wd;
  200. /*
  201. * mei device states
  202. */
  203. enum mei_dev_state dev_state;
  204. enum mei_init_clients_states init_clients_state;
  205. u16 init_clients_timer;
  206. bool need_reset;
  207. u32 extra_write_index;
  208. unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */
  209. u32 wr_msg_buf[128]; /* used for control messages */
  210. u32 ext_msg_buf[8]; /* for control responses */
  211. u32 rd_msg_hdr;
  212. struct hbm_version version;
  213. struct mei_me_client *me_clients; /* Note: memory has to be allocated */
  214. DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
  215. DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
  216. u8 me_clients_num;
  217. u8 me_client_presentation_num;
  218. u8 me_client_index;
  219. bool mei_host_buffer_is_empty;
  220. struct mei_cl wd_cl;
  221. enum mei_wd_states wd_state;
  222. bool wd_pending;
  223. u16 wd_timeout;
  224. unsigned char wd_data[MEI_WD_START_MSG_SIZE];
  225. /* amthif list for cmd waiting */
  226. struct mei_cl_cb amthif_cmd_list;
  227. /* driver managed amthif list for reading completed amthif cmd data */
  228. struct mei_cl_cb amthif_rd_complete_list;
  229. struct file *iamthif_file_object;
  230. struct mei_cl iamthif_cl;
  231. struct mei_cl_cb *iamthif_current_cb;
  232. int iamthif_mtu;
  233. unsigned long iamthif_timer;
  234. u32 iamthif_stall_timer;
  235. unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
  236. u32 iamthif_msg_buf_size;
  237. u32 iamthif_msg_buf_index;
  238. enum iamthif_states iamthif_state;
  239. bool iamthif_flow_control_pending;
  240. bool iamthif_ioctl;
  241. bool iamthif_canceled;
  242. };
  243. static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
  244. {
  245. return msecs_to_jiffies(sec * MSEC_PER_SEC);
  246. }
  247. /*
  248. * mei init function prototypes
  249. */
  250. struct mei_device *mei_device_init(struct pci_dev *pdev);
  251. void mei_reset(struct mei_device *dev, int interrupts);
  252. int mei_hw_init(struct mei_device *dev);
  253. int mei_task_initialize_clients(void *data);
  254. int mei_initialize_clients(struct mei_device *dev);
  255. int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
  256. void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
  257. void mei_allocate_me_clients_storage(struct mei_device *dev);
  258. int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl,
  259. const uuid_le *cguid, u8 host_client_id);
  260. int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid);
  261. int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
  262. /*
  263. * MEI IO Functions
  264. */
  265. struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp);
  266. void mei_io_cb_free(struct mei_cl_cb *priv_cb);
  267. int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length);
  268. int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length);
  269. /**
  270. * mei_io_list_init - Sets up a queue list.
  271. *
  272. * @list: An instance cl callback structure
  273. */
  274. static inline void mei_io_list_init(struct mei_cl_cb *list)
  275. {
  276. INIT_LIST_HEAD(&list->list);
  277. }
  278. void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl);
  279. /*
  280. * MEI ME Client Functions
  281. */
  282. struct mei_cl *mei_cl_allocate(struct mei_device *dev);
  283. void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
  284. int mei_cl_flush_queues(struct mei_cl *cl);
  285. /**
  286. * mei_cl_cmp_id - tells if file private data have same id
  287. *
  288. * @fe1: private data of 1. file object
  289. * @fe2: private data of 2. file object
  290. *
  291. * returns true - if ids are the same and not NULL
  292. */
  293. static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
  294. const struct mei_cl *cl2)
  295. {
  296. return cl1 && cl2 &&
  297. (cl1->host_client_id == cl2->host_client_id) &&
  298. (cl1->me_client_id == cl2->me_client_id);
  299. }
  300. /*
  301. * MEI Host Client Functions
  302. */
  303. void mei_host_start_message(struct mei_device *dev);
  304. void mei_host_enum_clients_message(struct mei_device *dev);
  305. int mei_host_client_properties(struct mei_device *dev);
  306. /*
  307. * MEI interrupt functions prototype
  308. */
  309. irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
  310. irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
  311. void mei_timer(struct work_struct *work);
  312. /*
  313. * MEI input output function prototype
  314. */
  315. int mei_ioctl_connect_client(struct file *file,
  316. struct mei_connect_client_data *data);
  317. int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
  318. /*
  319. * AMTHIF - AMT Host Interface Functions
  320. */
  321. void mei_amthif_reset_params(struct mei_device *dev);
  322. void mei_amthif_host_init(struct mei_device *dev);
  323. int mei_amthif_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
  324. int mei_amthif_read(struct mei_device *dev, struct file *file,
  325. char __user *ubuf, size_t length, loff_t *offset);
  326. struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev,
  327. struct file *file);
  328. void mei_amthif_run_next_cmd(struct mei_device *dev);
  329. int mei_amthif_read_message(struct mei_cl_cb *complete_list,
  330. struct mei_device *dev, struct mei_msg_hdr *mei_hdr);
  331. int mei_amthif_irq_process_completed(struct mei_device *dev, s32 *slots,
  332. struct mei_cl_cb *cb_pos,
  333. struct mei_cl *cl,
  334. struct mei_cl_cb *cmpl_list);
  335. void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb);
  336. int mei_amthif_irq_read_message(struct mei_cl_cb *complete_list,
  337. struct mei_device *dev, struct mei_msg_hdr *mei_hdr);
  338. int mei_amthif_irq_read(struct mei_device *dev, s32 *slots);
  339. /*
  340. * Register Access Function
  341. */
  342. /**
  343. * mei_reg_read - Reads 32bit data from the mei device
  344. *
  345. * @dev: the device structure
  346. * @offset: offset from which to read the data
  347. *
  348. * returns register value (u32)
  349. */
  350. static inline u32 mei_reg_read(const struct mei_device *dev,
  351. unsigned long offset)
  352. {
  353. return ioread32(dev->mem_addr + offset);
  354. }
  355. /**
  356. * mei_reg_write - Writes 32bit data to the mei device
  357. *
  358. * @dev: the device structure
  359. * @offset: offset from which to write the data
  360. * @value: register value to write (u32)
  361. */
  362. static inline void mei_reg_write(const struct mei_device *dev,
  363. unsigned long offset, u32 value)
  364. {
  365. iowrite32(value, dev->mem_addr + offset);
  366. }
  367. /**
  368. * mei_hcsr_read - Reads 32bit data from the host CSR
  369. *
  370. * @dev: the device structure
  371. *
  372. * returns the byte read.
  373. */
  374. static inline u32 mei_hcsr_read(const struct mei_device *dev)
  375. {
  376. return mei_reg_read(dev, H_CSR);
  377. }
  378. /**
  379. * mei_mecsr_read - Reads 32bit data from the ME CSR
  380. *
  381. * @dev: the device structure
  382. *
  383. * returns ME_CSR_HA register value (u32)
  384. */
  385. static inline u32 mei_mecsr_read(const struct mei_device *dev)
  386. {
  387. return mei_reg_read(dev, ME_CSR_HA);
  388. }
  389. /**
  390. * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register
  391. *
  392. * @dev: the device structure
  393. *
  394. * returns ME_CB_RW register value (u32)
  395. */
  396. static inline u32 mei_mecbrw_read(const struct mei_device *dev)
  397. {
  398. return mei_reg_read(dev, ME_CB_RW);
  399. }
  400. /*
  401. * mei interface function prototypes
  402. */
  403. void mei_hcsr_set(struct mei_device *dev);
  404. void mei_csr_clear_his(struct mei_device *dev);
  405. void mei_enable_interrupts(struct mei_device *dev);
  406. void mei_disable_interrupts(struct mei_device *dev);
  407. #endif