mei_dev.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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_WATCHDOG_DATA_SIZE 16
  26. #define MEI_START_WD_DATA_SIZE 20
  27. #define MEI_WD_PARAMS_SIZE 4
  28. #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0)
  29. #define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32))
  30. /*
  31. * MEI PCI Device object
  32. */
  33. extern struct pci_dev *mei_device;
  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 File descriptors/handles
  48. * that can be opened to the driver.
  49. *
  50. * Limit to 253: 255 Total Clients
  51. * minus internal client for AMTHI
  52. * minus internal client for Watchdog
  53. */
  54. #define MEI_MAX_OPEN_HANDLE_COUNT 253
  55. /*
  56. * Number of Maximum MEI Clients
  57. */
  58. #define MEI_CLIENTS_MAX 255
  59. /* File state */
  60. enum file_state {
  61. MEI_FILE_INITIALIZING = 0,
  62. MEI_FILE_CONNECTING,
  63. MEI_FILE_CONNECTED,
  64. MEI_FILE_DISCONNECTING,
  65. MEI_FILE_DISCONNECTED
  66. };
  67. /* MEI device states */
  68. enum mei_states {
  69. MEI_INITIALIZING = 0,
  70. MEI_INIT_CLIENTS,
  71. MEI_ENABLED,
  72. MEI_RESETING,
  73. MEI_DISABLED,
  74. MEI_RECOVERING_FROM_RESET,
  75. MEI_POWER_DOWN,
  76. MEI_POWER_UP
  77. };
  78. /* init clients states*/
  79. enum mei_init_clients_states {
  80. MEI_START_MESSAGE = 0,
  81. MEI_ENUM_CLIENTS_MESSAGE,
  82. MEI_CLIENT_PROPERTIES_MESSAGE
  83. };
  84. enum iamthif_states {
  85. MEI_IAMTHIF_IDLE,
  86. MEI_IAMTHIF_WRITING,
  87. MEI_IAMTHIF_FLOW_CONTROL,
  88. MEI_IAMTHIF_READING,
  89. MEI_IAMTHIF_READ_COMPLETE
  90. };
  91. enum mei_file_transaction_states {
  92. MEI_IDLE,
  93. MEI_WRITING,
  94. MEI_WRITE_COMPLETE,
  95. MEI_FLOW_CONTROL,
  96. MEI_READING,
  97. MEI_READ_COMPLETE
  98. };
  99. /* MEI CB */
  100. enum mei_cb_major_types {
  101. MEI_READ = 0,
  102. MEI_WRITE,
  103. MEI_IOCTL,
  104. MEI_OPEN,
  105. MEI_CLOSE
  106. };
  107. /*
  108. * Intel MEI message data struct
  109. */
  110. struct mei_message_data {
  111. u32 size;
  112. unsigned char *data;
  113. } __packed;
  114. struct mei_cl_cb {
  115. struct list_head cb_list;
  116. enum mei_cb_major_types major_file_operations;
  117. void *file_private;
  118. struct mei_message_data request_buffer;
  119. struct mei_message_data response_buffer;
  120. unsigned long information;
  121. unsigned long read_time;
  122. struct file *file_object;
  123. };
  124. /* MEI client instance carried as file->pirvate_data*/
  125. struct mei_cl {
  126. struct list_head link;
  127. struct mei_device *dev;
  128. enum file_state state;
  129. wait_queue_head_t tx_wait;
  130. wait_queue_head_t rx_wait;
  131. wait_queue_head_t wait;
  132. int read_pending;
  133. int status;
  134. /* ID of client connected */
  135. u8 host_client_id;
  136. u8 me_client_id;
  137. u8 mei_flow_ctrl_creds;
  138. u8 timer_count;
  139. enum mei_file_transaction_states reading_state;
  140. enum mei_file_transaction_states writing_state;
  141. int sm_state;
  142. struct mei_cl_cb *read_cb;
  143. };
  144. struct mei_io_list {
  145. struct mei_cl_cb mei_cb;
  146. };
  147. /* MEI private device struct */
  148. struct mei_device {
  149. struct pci_dev *pdev; /* pointer to pci device struct */
  150. /*
  151. * lists of queues
  152. */
  153. /* array of pointers to aio lists */
  154. struct mei_io_list read_list; /* driver read queue */
  155. struct mei_io_list write_list; /* driver write queue */
  156. struct mei_io_list write_waiting_list; /* write waiting queue */
  157. struct mei_io_list ctrl_wr_list; /* managed write IOCTL list */
  158. struct mei_io_list ctrl_rd_list; /* managed read IOCTL list */
  159. struct mei_io_list amthi_cmd_list; /* amthi list for cmd waiting */
  160. /* driver managed amthi list for reading completed amthi cmd data */
  161. struct mei_io_list amthi_read_complete_list;
  162. /*
  163. * list of files
  164. */
  165. struct list_head file_list;
  166. long open_handle_count;
  167. /*
  168. * memory of device
  169. */
  170. unsigned int mem_base;
  171. unsigned int mem_length;
  172. void __iomem *mem_addr;
  173. /*
  174. * lock for the device
  175. */
  176. struct mutex device_lock; /* device lock */
  177. struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */
  178. bool recvd_msg;
  179. /*
  180. * hw states of host and fw(ME)
  181. */
  182. u32 host_hw_state;
  183. u32 me_hw_state;
  184. /*
  185. * waiting queue for receive message from FW
  186. */
  187. wait_queue_head_t wait_recvd_msg;
  188. wait_queue_head_t wait_stop_wd;
  189. /*
  190. * mei device states
  191. */
  192. enum mei_states mei_state;
  193. enum mei_init_clients_states init_clients_state;
  194. u16 init_clients_timer;
  195. bool stop;
  196. bool need_reset;
  197. u32 extra_write_index;
  198. unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */
  199. u32 wr_msg_buf[128]; /* used for control messages */
  200. u32 ext_msg_buf[8]; /* for control responses */
  201. u32 rd_msg_hdr;
  202. struct hbm_version version;
  203. struct mei_me_client *me_clients; /* Note: memory has to be allocated */
  204. DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
  205. DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
  206. u8 me_clients_num;
  207. u8 me_client_presentation_num;
  208. u8 me_client_index;
  209. bool mei_host_buffer_is_empty;
  210. struct mei_cl wd_cl;
  211. bool wd_pending;
  212. bool wd_stopped;
  213. bool wd_bypass; /* if false, don't refresh watchdog ME client */
  214. u16 wd_timeout; /* seconds ((wd_data[1] << 8) + wd_data[0]) */
  215. u16 wd_due_counter;
  216. unsigned char wd_data[MEI_START_WD_DATA_SIZE];
  217. struct file *iamthif_file_object;
  218. struct mei_cl iamthif_cl;
  219. struct mei_cl_cb *iamthif_current_cb;
  220. int iamthif_mtu;
  221. unsigned long iamthif_timer;
  222. u32 iamthif_stall_timer;
  223. unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
  224. u32 iamthif_msg_buf_size;
  225. u32 iamthif_msg_buf_index;
  226. enum iamthif_states iamthif_state;
  227. bool iamthif_flow_control_pending;
  228. bool iamthif_ioctl;
  229. bool iamthif_canceled;
  230. bool wd_interface_reg;
  231. };
  232. /*
  233. * mei init function prototypes
  234. */
  235. struct mei_device *mei_device_init(struct pci_dev *pdev);
  236. void mei_reset(struct mei_device *dev, int interrupts);
  237. int mei_hw_init(struct mei_device *dev);
  238. int mei_task_initialize_clients(void *data);
  239. int mei_initialize_clients(struct mei_device *dev);
  240. int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
  241. void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
  242. void mei_host_init_iamthif(struct mei_device *dev);
  243. void mei_allocate_me_clients_storage(struct mei_device *dev);
  244. u8 mei_find_me_client_update_filext(struct mei_device *dev,
  245. struct mei_cl *priv,
  246. const uuid_le *cguid, u8 client_id);
  247. /*
  248. * MEI IO List Functions
  249. */
  250. void mei_io_list_init(struct mei_io_list *list);
  251. void mei_io_list_flush(struct mei_io_list *list, struct mei_cl *cl);
  252. /*
  253. * MEI ME Client Functions
  254. */
  255. struct mei_cl *mei_cl_allocate(struct mei_device *dev);
  256. void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
  257. int mei_cl_flush_queues(struct mei_cl *cl);
  258. /**
  259. * mei_cl_cmp_id - tells if file private data have same id
  260. *
  261. * @fe1: private data of 1. file object
  262. * @fe2: private data of 2. file object
  263. *
  264. * returns true - if ids are the same and not NULL
  265. */
  266. static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
  267. const struct mei_cl *cl2)
  268. {
  269. return cl1 && cl2 &&
  270. (cl1->host_client_id == cl2->host_client_id) &&
  271. (cl1->me_client_id == cl2->me_client_id);
  272. }
  273. /*
  274. * MEI Host Client Functions
  275. */
  276. void mei_host_start_message(struct mei_device *dev);
  277. void mei_host_enum_clients_message(struct mei_device *dev);
  278. int mei_host_client_properties(struct mei_device *dev);
  279. /*
  280. * MEI interrupt functions prototype
  281. */
  282. irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
  283. irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
  284. void mei_timer(struct work_struct *work);
  285. /*
  286. * MEI input output function prototype
  287. */
  288. int mei_ioctl_connect_client(struct file *file,
  289. struct mei_connect_client_data *data);
  290. int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
  291. int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
  292. int amthi_read(struct mei_device *dev, struct file *file,
  293. char __user *ubuf, size_t length, loff_t *offset);
  294. struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev,
  295. struct file *file);
  296. void mei_run_next_iamthif_cmd(struct mei_device *dev);
  297. void mei_free_cb_private(struct mei_cl_cb *priv_cb);
  298. int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid);
  299. /*
  300. * Register Access Function
  301. */
  302. /**
  303. * mei_reg_read - Reads 32bit data from the mei device
  304. *
  305. * @dev: the device structure
  306. * @offset: offset from which to read the data
  307. *
  308. * returns register value (u32)
  309. */
  310. static inline u32 mei_reg_read(struct mei_device *dev, unsigned long offset)
  311. {
  312. return ioread32(dev->mem_addr + offset);
  313. }
  314. /**
  315. * mei_reg_write - Writes 32bit data to the mei device
  316. *
  317. * @dev: the device structure
  318. * @offset: offset from which to write the data
  319. * @value: register value to write (u32)
  320. */
  321. static inline void mei_reg_write(struct mei_device *dev,
  322. unsigned long offset, u32 value)
  323. {
  324. iowrite32(value, dev->mem_addr + offset);
  325. }
  326. /**
  327. * mei_hcsr_read - Reads 32bit data from the host CSR
  328. *
  329. * @dev: the device structure
  330. *
  331. * returns the byte read.
  332. */
  333. static inline u32 mei_hcsr_read(struct mei_device *dev)
  334. {
  335. return mei_reg_read(dev, H_CSR);
  336. }
  337. /**
  338. * mei_mecsr_read - Reads 32bit data from the ME CSR
  339. *
  340. * @dev: the device structure
  341. *
  342. * returns ME_CSR_HA register value (u32)
  343. */
  344. static inline u32 mei_mecsr_read(struct mei_device *dev)
  345. {
  346. return mei_reg_read(dev, ME_CSR_HA);
  347. }
  348. /**
  349. * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register
  350. *
  351. * @dev: the device structure
  352. *
  353. * returns ME_CB_RW register value (u32)
  354. */
  355. static inline u32 mei_mecbrw_read(struct mei_device *dev)
  356. {
  357. return mei_reg_read(dev, ME_CB_RW);
  358. }
  359. /*
  360. * mei interface function prototypes
  361. */
  362. void mei_hcsr_set(struct mei_device *dev);
  363. void mei_csr_clear_his(struct mei_device *dev);
  364. void mei_enable_interrupts(struct mei_device *dev);
  365. void mei_disable_interrupts(struct mei_device *dev);
  366. #endif