mei_dev.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  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 <linux/mei_cl_bus.h>
  23. #include "hw.h"
  24. #include "hbm.h"
  25. /*
  26. * watch dog definition
  27. */
  28. #define MEI_WD_HDR_SIZE 4
  29. #define MEI_WD_STOP_MSG_SIZE MEI_WD_HDR_SIZE
  30. #define MEI_WD_START_MSG_SIZE (MEI_WD_HDR_SIZE + 16)
  31. #define MEI_WD_DEFAULT_TIMEOUT 120 /* seconds */
  32. #define MEI_WD_MIN_TIMEOUT 120 /* seconds */
  33. #define MEI_WD_MAX_TIMEOUT 65535 /* seconds */
  34. #define MEI_WD_STOP_TIMEOUT 10 /* msecs */
  35. #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0)
  36. #define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32))
  37. /*
  38. * AMTHI Client UUID
  39. */
  40. extern const uuid_le mei_amthif_guid;
  41. /*
  42. * Watchdog Client UUID
  43. */
  44. extern const uuid_le mei_wd_guid;
  45. /*
  46. * Number of Maximum MEI Clients
  47. */
  48. #define MEI_CLIENTS_MAX 256
  49. /*
  50. * maximum number of consecutive resets
  51. */
  52. #define MEI_MAX_CONSEC_RESET 3
  53. /*
  54. * Number of File descriptors/handles
  55. * that can be opened to the driver.
  56. *
  57. * Limit to 255: 256 Total Clients
  58. * minus internal client for MEI Bus Messages
  59. */
  60. #define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 1)
  61. /*
  62. * Internal Clients Number
  63. */
  64. #define MEI_HOST_CLIENT_ID_ANY (-1)
  65. #define MEI_HBM_HOST_CLIENT_ID 0 /* not used, just for documentation */
  66. #define MEI_WD_HOST_CLIENT_ID 1
  67. #define MEI_IAMTHIF_HOST_CLIENT_ID 2
  68. /* File state */
  69. enum file_state {
  70. MEI_FILE_INITIALIZING = 0,
  71. MEI_FILE_CONNECTING,
  72. MEI_FILE_CONNECTED,
  73. MEI_FILE_DISCONNECTING,
  74. MEI_FILE_DISCONNECTED
  75. };
  76. /* MEI device states */
  77. enum mei_dev_state {
  78. MEI_DEV_INITIALIZING = 0,
  79. MEI_DEV_INIT_CLIENTS,
  80. MEI_DEV_ENABLED,
  81. MEI_DEV_RESETTING,
  82. MEI_DEV_DISABLED,
  83. MEI_DEV_POWER_DOWN,
  84. MEI_DEV_POWER_UP
  85. };
  86. const char *mei_dev_state_str(int state);
  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_CONNECT: connect
  112. * @MEI_FOP_DISCONNECT: disconnect
  113. * @MEI_FOP_DISCONNECT_RSP: disconnect response
  114. */
  115. enum mei_cb_file_ops {
  116. MEI_FOP_READ = 0,
  117. MEI_FOP_WRITE,
  118. MEI_FOP_CONNECT,
  119. MEI_FOP_DISCONNECT,
  120. MEI_FOP_DISCONNECT_RSP,
  121. };
  122. /*
  123. * Intel MEI message data struct
  124. */
  125. struct mei_msg_data {
  126. u32 size;
  127. unsigned char *data;
  128. };
  129. /* Maximum number of processed FW status registers */
  130. #define MEI_FW_STATUS_MAX 2
  131. /*
  132. * struct mei_fw_status - storage of FW status data
  133. *
  134. * @count: number of actually available elements in array
  135. * @status: FW status registers
  136. */
  137. struct mei_fw_status {
  138. int count;
  139. u32 status[MEI_FW_STATUS_MAX];
  140. };
  141. /**
  142. * struct mei_me_client - representation of me (fw) client
  143. *
  144. * @list: link in me client list
  145. * @props: client properties
  146. * @client_id: me client id
  147. * @mei_flow_ctrl_creds: flow control credits
  148. */
  149. struct mei_me_client {
  150. struct list_head list;
  151. struct mei_client_properties props;
  152. u8 client_id;
  153. u8 mei_flow_ctrl_creds;
  154. };
  155. struct mei_cl;
  156. /**
  157. * struct mei_cl_cb - file operation callback structure
  158. *
  159. * @list: link in callback queue
  160. * @cl: file client who is running this operation
  161. * @fop_type: file operation type
  162. * @request_buffer: buffer to store request data
  163. * @response_buffer: buffer to store response data
  164. * @buf_idx: last read index
  165. * @read_time: last read operation time stamp (iamthif)
  166. * @file_object: pointer to file structure
  167. * @internal: communication between driver and FW flag
  168. */
  169. struct mei_cl_cb {
  170. struct list_head list;
  171. struct mei_cl *cl;
  172. enum mei_cb_file_ops fop_type;
  173. struct mei_msg_data request_buffer;
  174. struct mei_msg_data response_buffer;
  175. unsigned long buf_idx;
  176. unsigned long read_time;
  177. struct file *file_object;
  178. u32 internal:1;
  179. };
  180. /**
  181. * struct mei_cl - me client host representation
  182. * carried in file->private_data
  183. *
  184. * @link: link in the clients list
  185. * @dev: mei parent device
  186. * @state: file operation state
  187. * @tx_wait: wait queue for tx completion
  188. * @rx_wait: wait queue for rx completion
  189. * @wait: wait queue for management operation
  190. * @status: connection status
  191. * @cl_uuid: client uuid name
  192. * @host_client_id: host id
  193. * @me_client_id: me/fw id
  194. * @mei_flow_ctrl_creds: transmit flow credentials
  195. * @timer_count: watchdog timer for operation completion
  196. * @reading_state: state of the rx
  197. * @writing_state: state of the tx
  198. * @read_cb: current pending reading callback
  199. *
  200. * @device: device on the mei client bus
  201. * @device_link: link to bus clients
  202. */
  203. struct mei_cl {
  204. struct list_head link;
  205. struct mei_device *dev;
  206. enum file_state state;
  207. wait_queue_head_t tx_wait;
  208. wait_queue_head_t rx_wait;
  209. wait_queue_head_t wait;
  210. int status;
  211. uuid_le cl_uuid;
  212. u8 host_client_id;
  213. u8 me_client_id;
  214. u8 mei_flow_ctrl_creds;
  215. u8 timer_count;
  216. enum mei_file_transaction_states reading_state;
  217. enum mei_file_transaction_states writing_state;
  218. struct mei_cl_cb *read_cb;
  219. /* MEI CL bus data */
  220. struct mei_cl_device *device;
  221. struct list_head device_link;
  222. };
  223. /** struct mei_hw_ops
  224. *
  225. * @host_is_ready : query for host readiness
  226. * @hw_is_ready : query if hw is ready
  227. * @hw_reset : reset hw
  228. * @hw_start : start hw after reset
  229. * @hw_config : configure hw
  230. * @fw_status : get fw status registers
  231. * @pg_state : power gating state of the device
  232. * @pg_is_enabled : is power gating enabled
  233. * @intr_clear : clear pending interrupts
  234. * @intr_enable : enable interrupts
  235. * @intr_disable : disable interrupts
  236. * @hbuf_free_slots : query for write buffer empty slots
  237. * @hbuf_is_ready : query if write buffer is empty
  238. * @hbuf_max_len : query for write buffer max len
  239. * @write : write a message to FW
  240. * @rdbuf_full_slots : query how many slots are filled
  241. * @read_hdr : get first 4 bytes (header)
  242. * @read : read a buffer from the FW
  243. */
  244. struct mei_hw_ops {
  245. bool (*host_is_ready)(struct mei_device *dev);
  246. bool (*hw_is_ready)(struct mei_device *dev);
  247. int (*hw_reset)(struct mei_device *dev, bool enable);
  248. int (*hw_start)(struct mei_device *dev);
  249. void (*hw_config)(struct mei_device *dev);
  250. int (*fw_status)(struct mei_device *dev, struct mei_fw_status *fw_sts);
  251. enum mei_pg_state (*pg_state)(struct mei_device *dev);
  252. bool (*pg_is_enabled)(struct mei_device *dev);
  253. void (*intr_clear)(struct mei_device *dev);
  254. void (*intr_enable)(struct mei_device *dev);
  255. void (*intr_disable)(struct mei_device *dev);
  256. int (*hbuf_free_slots)(struct mei_device *dev);
  257. bool (*hbuf_is_ready)(struct mei_device *dev);
  258. size_t (*hbuf_max_len)(const struct mei_device *dev);
  259. int (*write)(struct mei_device *dev,
  260. struct mei_msg_hdr *hdr,
  261. unsigned char *buf);
  262. int (*rdbuf_full_slots)(struct mei_device *dev);
  263. u32 (*read_hdr)(const struct mei_device *dev);
  264. int (*read)(struct mei_device *dev,
  265. unsigned char *buf, unsigned long len);
  266. };
  267. /* MEI bus API*/
  268. /**
  269. * struct mei_cl_ops - MEI CL device ops
  270. * This structure allows ME host clients to implement technology
  271. * specific operations.
  272. *
  273. * @enable: Enable an MEI CL device. Some devices require specific
  274. * HECI commands to initialize completely.
  275. * @disable: Disable an MEI CL device.
  276. * @send: Tx hook for the device. This allows ME host clients to trap
  277. * the device driver buffers before actually physically
  278. * pushing it to the ME.
  279. * @recv: Rx hook for the device. This allows ME host clients to trap the
  280. * ME buffers before forwarding them to the device driver.
  281. */
  282. struct mei_cl_ops {
  283. int (*enable)(struct mei_cl_device *device);
  284. int (*disable)(struct mei_cl_device *device);
  285. int (*send)(struct mei_cl_device *device, u8 *buf, size_t length);
  286. int (*recv)(struct mei_cl_device *device, u8 *buf, size_t length);
  287. };
  288. struct mei_cl_device *mei_cl_add_device(struct mei_device *dev,
  289. uuid_le uuid, char *name,
  290. struct mei_cl_ops *ops);
  291. void mei_cl_remove_device(struct mei_cl_device *device);
  292. int __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length);
  293. int __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length);
  294. int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length);
  295. void mei_cl_bus_rx_event(struct mei_cl *cl);
  296. void mei_cl_bus_remove_devices(struct mei_device *dev);
  297. int mei_cl_bus_init(void);
  298. void mei_cl_bus_exit(void);
  299. /**
  300. * struct mei_cl_device - MEI device handle
  301. * An mei_cl_device pointer is returned from mei_add_device()
  302. * and links MEI bus clients to their actual ME host client pointer.
  303. * Drivers for MEI devices will get an mei_cl_device pointer
  304. * when being probed and shall use it for doing ME bus I/O.
  305. *
  306. * @dev: linux driver model device pointer
  307. * @cl: mei client
  308. * @ops: ME transport ops
  309. * @event_work: async work to execute event callback
  310. * @event_cb: Drivers register this callback to get asynchronous ME
  311. * events (e.g. Rx buffer pending) notifications.
  312. * @event_context: event callback run context
  313. * @events: Events bitmask sent to the driver.
  314. * @priv_data: client private data
  315. */
  316. struct mei_cl_device {
  317. struct device dev;
  318. struct mei_cl *cl;
  319. const struct mei_cl_ops *ops;
  320. struct work_struct event_work;
  321. mei_cl_event_cb_t event_cb;
  322. void *event_context;
  323. unsigned long events;
  324. void *priv_data;
  325. };
  326. /**
  327. * enum mei_pg_event - power gating transition events
  328. *
  329. * @MEI_PG_EVENT_IDLE: the driver is not in power gating transition
  330. * @MEI_PG_EVENT_WAIT: the driver is waiting for a pg event to complete
  331. * @MEI_PG_EVENT_RECEIVED: the driver received pg event
  332. */
  333. enum mei_pg_event {
  334. MEI_PG_EVENT_IDLE,
  335. MEI_PG_EVENT_WAIT,
  336. MEI_PG_EVENT_RECEIVED,
  337. };
  338. /**
  339. * enum mei_pg_state - device internal power gating state
  340. *
  341. * @MEI_PG_OFF: device is not power gated - it is active
  342. * @MEI_PG_ON: device is power gated - it is in lower power state
  343. */
  344. enum mei_pg_state {
  345. MEI_PG_OFF = 0,
  346. MEI_PG_ON = 1,
  347. };
  348. const char *mei_pg_state_str(enum mei_pg_state state);
  349. /**
  350. * struct mei_device - MEI private device struct
  351. *
  352. * @dev : device on a bus
  353. * @cdev : character device
  354. * @minor : minor number allocated for device
  355. *
  356. * @read_list : read completion list
  357. * @write_list : write pending list
  358. * @write_waiting_list : write completion list
  359. * @ctrl_wr_list : pending control write list
  360. * @ctrl_rd_list : pending control read list
  361. *
  362. * @file_list : list of opened handles
  363. * @open_handle_count: number of opened handles
  364. *
  365. * @device_lock : big device lock
  366. * @timer_work : MEI timer delayed work (timeouts)
  367. *
  368. * @recvd_hw_ready : hw ready message received flag
  369. *
  370. * @wait_hw_ready : wait queue for receive HW ready message form FW
  371. * @wait_pg : wait queue for receive PG message from FW
  372. * @wait_hbm_start : wait queue for receive HBM start message from FW
  373. * @wait_stop_wd : wait queue for receive WD stop message from FW
  374. *
  375. * @reset_count : number of consecutive resets
  376. * @dev_state : device state
  377. * @hbm_state : state of host bus message protocol
  378. * @init_clients_timer : HBM init handshake timeout
  379. *
  380. * @pg_event : power gating event
  381. * @pg_domain : runtime PM domain
  382. *
  383. * @rd_msg_buf : control messages buffer
  384. * @rd_msg_hdr : read message header storage
  385. *
  386. * @hbuf_depth : depth of hardware host/write buffer is slots
  387. * @hbuf_is_ready : query if the host host/write buffer is ready
  388. * @wr_msg : the buffer for hbm control messages
  389. *
  390. * @version : HBM protocol version in use
  391. * @hbm_f_pg_supported : hbm feature pgi protocol
  392. *
  393. * @me_clients : list of FW clients
  394. * @me_clients_map : FW clients bit map
  395. * @host_clients_map : host clients id pool
  396. * @me_client_index : last FW client index in enumeration
  397. *
  398. * @wd_cl : watchdog client
  399. * @wd_state : watchdog client state
  400. * @wd_pending : watchdog command is pending
  401. * @wd_timeout : watchdog expiration timeout
  402. * @wd_data : watchdog message buffer
  403. *
  404. * @amthif_cmd_list : amthif list for cmd waiting
  405. * @amthif_rd_complete_list : amthif list for reading completed cmd data
  406. * @iamthif_file_object : file for current amthif operation
  407. * @iamthif_cl : amthif host client
  408. * @iamthif_current_cb : amthif current operation callback
  409. * @iamthif_open_count : number of opened amthif connections
  410. * @iamthif_mtu : amthif client max message length
  411. * @iamthif_timer : time stamp of current amthif command completion
  412. * @iamthif_stall_timer : timer to detect amthif hang
  413. * @iamthif_msg_buf : amthif current message buffer
  414. * @iamthif_msg_buf_size : size of current amthif message request buffer
  415. * @iamthif_msg_buf_index : current index in amthif message request buffer
  416. * @iamthif_state : amthif processor state
  417. * @iamthif_flow_control_pending: amthif waits for flow control
  418. * @iamthif_ioctl : wait for completion if amthif control message
  419. * @iamthif_canceled : current amthif command is canceled
  420. *
  421. * @init_work : work item for the device init
  422. * @reset_work : work item for the device reset
  423. *
  424. * @device_list : mei client bus list
  425. *
  426. * @dbgfs_dir : debugfs mei root directory
  427. *
  428. * @ops: : hw specific operations
  429. * @hw : hw specific data
  430. */
  431. struct mei_device {
  432. struct device *dev;
  433. struct cdev cdev;
  434. int minor;
  435. struct mei_cl_cb read_list;
  436. struct mei_cl_cb write_list;
  437. struct mei_cl_cb write_waiting_list;
  438. struct mei_cl_cb ctrl_wr_list;
  439. struct mei_cl_cb ctrl_rd_list;
  440. struct list_head file_list;
  441. long open_handle_count;
  442. struct mutex device_lock;
  443. struct delayed_work timer_work;
  444. bool recvd_hw_ready;
  445. /*
  446. * waiting queue for receive message from FW
  447. */
  448. wait_queue_head_t wait_hw_ready;
  449. wait_queue_head_t wait_pg;
  450. wait_queue_head_t wait_hbm_start;
  451. wait_queue_head_t wait_stop_wd;
  452. /*
  453. * mei device states
  454. */
  455. unsigned long reset_count;
  456. enum mei_dev_state dev_state;
  457. enum mei_hbm_state hbm_state;
  458. u16 init_clients_timer;
  459. /*
  460. * Power Gating support
  461. */
  462. enum mei_pg_event pg_event;
  463. #ifdef CONFIG_PM_RUNTIME
  464. struct dev_pm_domain pg_domain;
  465. #endif /* CONFIG_PM_RUNTIME */
  466. unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE];
  467. u32 rd_msg_hdr;
  468. /* write buffer */
  469. u8 hbuf_depth;
  470. bool hbuf_is_ready;
  471. /* used for control messages */
  472. struct {
  473. struct mei_msg_hdr hdr;
  474. unsigned char data[128];
  475. } wr_msg;
  476. struct hbm_version version;
  477. unsigned int hbm_f_pg_supported:1;
  478. struct list_head me_clients;
  479. DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
  480. DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
  481. unsigned long me_client_index;
  482. struct mei_cl wd_cl;
  483. enum mei_wd_states wd_state;
  484. bool wd_pending;
  485. u16 wd_timeout;
  486. unsigned char wd_data[MEI_WD_START_MSG_SIZE];
  487. /* amthif list for cmd waiting */
  488. struct mei_cl_cb amthif_cmd_list;
  489. /* driver managed amthif list for reading completed amthif cmd data */
  490. struct mei_cl_cb amthif_rd_complete_list;
  491. struct file *iamthif_file_object;
  492. struct mei_cl iamthif_cl;
  493. struct mei_cl_cb *iamthif_current_cb;
  494. long iamthif_open_count;
  495. int iamthif_mtu;
  496. unsigned long iamthif_timer;
  497. u32 iamthif_stall_timer;
  498. unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
  499. u32 iamthif_msg_buf_size;
  500. u32 iamthif_msg_buf_index;
  501. enum iamthif_states iamthif_state;
  502. bool iamthif_flow_control_pending;
  503. bool iamthif_ioctl;
  504. bool iamthif_canceled;
  505. struct work_struct init_work;
  506. struct work_struct reset_work;
  507. /* List of bus devices */
  508. struct list_head device_list;
  509. #if IS_ENABLED(CONFIG_DEBUG_FS)
  510. struct dentry *dbgfs_dir;
  511. #endif /* CONFIG_DEBUG_FS */
  512. const struct mei_hw_ops *ops;
  513. char hw[0] __aligned(sizeof(void *));
  514. };
  515. static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
  516. {
  517. return msecs_to_jiffies(sec * MSEC_PER_SEC);
  518. }
  519. /**
  520. * mei_data2slots - get slots - number of (dwords) from a message length
  521. * + size of the mei header
  522. *
  523. * @length: size of the messages in bytes
  524. *
  525. * Return: number of slots
  526. */
  527. static inline u32 mei_data2slots(size_t length)
  528. {
  529. return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4);
  530. }
  531. /**
  532. * mei_slots2data - get data in slots - bytes from slots
  533. *
  534. * @slots: number of available slots
  535. *
  536. * Return: number of bytes in slots
  537. */
  538. static inline u32 mei_slots2data(int slots)
  539. {
  540. return slots * 4;
  541. }
  542. /*
  543. * mei init function prototypes
  544. */
  545. void mei_device_init(struct mei_device *dev,
  546. struct device *device,
  547. const struct mei_hw_ops *hw_ops);
  548. int mei_reset(struct mei_device *dev);
  549. int mei_start(struct mei_device *dev);
  550. int mei_restart(struct mei_device *dev);
  551. void mei_stop(struct mei_device *dev);
  552. void mei_cancel_work(struct mei_device *dev);
  553. /*
  554. * MEI interrupt functions prototype
  555. */
  556. void mei_timer(struct work_struct *work);
  557. int mei_irq_read_handler(struct mei_device *dev,
  558. struct mei_cl_cb *cmpl_list, s32 *slots);
  559. int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list);
  560. void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list);
  561. /*
  562. * AMTHIF - AMT Host Interface Functions
  563. */
  564. void mei_amthif_reset_params(struct mei_device *dev);
  565. int mei_amthif_host_init(struct mei_device *dev);
  566. int mei_amthif_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
  567. int mei_amthif_read(struct mei_device *dev, struct file *file,
  568. char __user *ubuf, size_t length, loff_t *offset);
  569. unsigned int mei_amthif_poll(struct mei_device *dev,
  570. struct file *file, poll_table *wait);
  571. int mei_amthif_release(struct mei_device *dev, struct file *file);
  572. struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev,
  573. struct file *file);
  574. void mei_amthif_run_next_cmd(struct mei_device *dev);
  575. int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb,
  576. struct mei_cl_cb *cmpl_list);
  577. void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb);
  578. int mei_amthif_irq_read_msg(struct mei_device *dev,
  579. struct mei_msg_hdr *mei_hdr,
  580. struct mei_cl_cb *complete_list);
  581. int mei_amthif_irq_read(struct mei_device *dev, s32 *slots);
  582. /*
  583. * NFC functions
  584. */
  585. int mei_nfc_host_init(struct mei_device *dev);
  586. void mei_nfc_host_exit(struct mei_device *dev);
  587. /*
  588. * NFC Client UUID
  589. */
  590. extern const uuid_le mei_nfc_guid;
  591. int mei_wd_send(struct mei_device *dev);
  592. int mei_wd_stop(struct mei_device *dev);
  593. int mei_wd_host_init(struct mei_device *dev);
  594. /*
  595. * mei_watchdog_register - Registering watchdog interface
  596. * once we got connection to the WD Client
  597. * @dev: mei device
  598. */
  599. int mei_watchdog_register(struct mei_device *dev);
  600. /*
  601. * mei_watchdog_unregister - Unregistering watchdog interface
  602. * @dev: mei device
  603. */
  604. void mei_watchdog_unregister(struct mei_device *dev);
  605. /*
  606. * Register Access Function
  607. */
  608. static inline void mei_hw_config(struct mei_device *dev)
  609. {
  610. dev->ops->hw_config(dev);
  611. }
  612. static inline enum mei_pg_state mei_pg_state(struct mei_device *dev)
  613. {
  614. return dev->ops->pg_state(dev);
  615. }
  616. static inline bool mei_pg_is_enabled(struct mei_device *dev)
  617. {
  618. return dev->ops->pg_is_enabled(dev);
  619. }
  620. static inline int mei_hw_reset(struct mei_device *dev, bool enable)
  621. {
  622. return dev->ops->hw_reset(dev, enable);
  623. }
  624. static inline int mei_hw_start(struct mei_device *dev)
  625. {
  626. return dev->ops->hw_start(dev);
  627. }
  628. static inline void mei_clear_interrupts(struct mei_device *dev)
  629. {
  630. dev->ops->intr_clear(dev);
  631. }
  632. static inline void mei_enable_interrupts(struct mei_device *dev)
  633. {
  634. dev->ops->intr_enable(dev);
  635. }
  636. static inline void mei_disable_interrupts(struct mei_device *dev)
  637. {
  638. dev->ops->intr_disable(dev);
  639. }
  640. static inline bool mei_host_is_ready(struct mei_device *dev)
  641. {
  642. return dev->ops->host_is_ready(dev);
  643. }
  644. static inline bool mei_hw_is_ready(struct mei_device *dev)
  645. {
  646. return dev->ops->hw_is_ready(dev);
  647. }
  648. static inline bool mei_hbuf_is_ready(struct mei_device *dev)
  649. {
  650. return dev->ops->hbuf_is_ready(dev);
  651. }
  652. static inline int mei_hbuf_empty_slots(struct mei_device *dev)
  653. {
  654. return dev->ops->hbuf_free_slots(dev);
  655. }
  656. static inline size_t mei_hbuf_max_len(const struct mei_device *dev)
  657. {
  658. return dev->ops->hbuf_max_len(dev);
  659. }
  660. static inline int mei_write_message(struct mei_device *dev,
  661. struct mei_msg_hdr *hdr,
  662. unsigned char *buf)
  663. {
  664. return dev->ops->write(dev, hdr, buf);
  665. }
  666. static inline u32 mei_read_hdr(const struct mei_device *dev)
  667. {
  668. return dev->ops->read_hdr(dev);
  669. }
  670. static inline void mei_read_slots(struct mei_device *dev,
  671. unsigned char *buf, unsigned long len)
  672. {
  673. dev->ops->read(dev, buf, len);
  674. }
  675. static inline int mei_count_full_read_slots(struct mei_device *dev)
  676. {
  677. return dev->ops->rdbuf_full_slots(dev);
  678. }
  679. static inline int mei_fw_status(struct mei_device *dev,
  680. struct mei_fw_status *fw_status)
  681. {
  682. return dev->ops->fw_status(dev, fw_status);
  683. }
  684. #define FW_STS_FMT "%08X %08X"
  685. #define FW_STS_PRM(fw_status) \
  686. (fw_status).count > 0 ? (fw_status).status[0] : 0xDEADBEEF, \
  687. (fw_status).count > 1 ? (fw_status).status[1] : 0xDEADBEEF
  688. bool mei_hbuf_acquire(struct mei_device *dev);
  689. bool mei_write_is_idle(struct mei_device *dev);
  690. #if IS_ENABLED(CONFIG_DEBUG_FS)
  691. int mei_dbgfs_register(struct mei_device *dev, const char *name);
  692. void mei_dbgfs_deregister(struct mei_device *dev);
  693. #else
  694. static inline int mei_dbgfs_register(struct mei_device *dev, const char *name)
  695. {
  696. return 0;
  697. }
  698. static inline void mei_dbgfs_deregister(struct mei_device *dev) {}
  699. #endif /* CONFIG_DEBUG_FS */
  700. int mei_register(struct mei_device *dev, struct device *parent);
  701. void mei_deregister(struct mei_device *dev);
  702. #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d internal=%1d comp=%1d"
  703. #define MEI_HDR_PRM(hdr) \
  704. (hdr)->host_addr, (hdr)->me_addr, \
  705. (hdr)->length, (hdr)->internal, (hdr)->msg_complete
  706. #endif