mei_dev.h 12 KB

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