mei_dev.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  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_DISCONNECT_REPLY,
  75. MEI_FILE_DISCONNECTED,
  76. };
  77. /* MEI device states */
  78. enum mei_dev_state {
  79. MEI_DEV_INITIALIZING = 0,
  80. MEI_DEV_INIT_CLIENTS,
  81. MEI_DEV_ENABLED,
  82. MEI_DEV_RESETTING,
  83. MEI_DEV_DISABLED,
  84. MEI_DEV_POWER_DOWN,
  85. MEI_DEV_POWER_UP
  86. };
  87. const char *mei_dev_state_str(int state);
  88. enum iamthif_states {
  89. MEI_IAMTHIF_IDLE,
  90. MEI_IAMTHIF_WRITING,
  91. MEI_IAMTHIF_FLOW_CONTROL,
  92. MEI_IAMTHIF_READING,
  93. MEI_IAMTHIF_READ_COMPLETE
  94. };
  95. enum mei_file_transaction_states {
  96. MEI_IDLE,
  97. MEI_WRITING,
  98. MEI_WRITE_COMPLETE,
  99. MEI_FLOW_CONTROL,
  100. MEI_READING,
  101. MEI_READ_COMPLETE
  102. };
  103. enum mei_wd_states {
  104. MEI_WD_IDLE,
  105. MEI_WD_RUNNING,
  106. MEI_WD_STOPPING,
  107. };
  108. /**
  109. * enum mei_cb_file_ops - file operation associated with the callback
  110. * @MEI_FOP_READ: read
  111. * @MEI_FOP_WRITE: write
  112. * @MEI_FOP_CONNECT: connect
  113. * @MEI_FOP_DISCONNECT: disconnect
  114. * @MEI_FOP_DISCONNECT_RSP: disconnect response
  115. */
  116. enum mei_cb_file_ops {
  117. MEI_FOP_READ = 0,
  118. MEI_FOP_WRITE,
  119. MEI_FOP_CONNECT,
  120. MEI_FOP_DISCONNECT,
  121. MEI_FOP_DISCONNECT_RSP,
  122. };
  123. /*
  124. * Intel MEI message data struct
  125. */
  126. struct mei_msg_data {
  127. u32 size;
  128. unsigned char *data;
  129. };
  130. /* Maximum number of processed FW status registers */
  131. #define MEI_FW_STATUS_MAX 6
  132. /* Minimal buffer for FW status string (8 bytes in dw + space or '\0') */
  133. #define MEI_FW_STATUS_STR_SZ (MEI_FW_STATUS_MAX * (8 + 1))
  134. /*
  135. * struct mei_fw_status - storage of FW status data
  136. *
  137. * @count: number of actually available elements in array
  138. * @status: FW status registers
  139. */
  140. struct mei_fw_status {
  141. int count;
  142. u32 status[MEI_FW_STATUS_MAX];
  143. };
  144. /**
  145. * struct mei_me_client - representation of me (fw) client
  146. *
  147. * @list: link in me client list
  148. * @refcnt: struct reference count
  149. * @props: client properties
  150. * @client_id: me client id
  151. * @mei_flow_ctrl_creds: flow control credits
  152. * @connect_count: number connections to this client
  153. * @reserved: reserved
  154. */
  155. struct mei_me_client {
  156. struct list_head list;
  157. struct kref refcnt;
  158. struct mei_client_properties props;
  159. u8 client_id;
  160. u8 mei_flow_ctrl_creds;
  161. u8 connect_count;
  162. u8 reserved;
  163. };
  164. struct mei_cl;
  165. /**
  166. * struct mei_cl_cb - file operation callback structure
  167. *
  168. * @list: link in callback queue
  169. * @cl: file client who is running this operation
  170. * @fop_type: file operation type
  171. * @buf: buffer for data associated with the callback
  172. * @buf_idx: last read index
  173. * @read_time: last read operation time stamp (iamthif)
  174. * @file_object: pointer to file structure
  175. * @status: io status of the cb
  176. * @internal: communication between driver and FW flag
  177. * @completed: the transfer or reception has completed
  178. */
  179. struct mei_cl_cb {
  180. struct list_head list;
  181. struct mei_cl *cl;
  182. enum mei_cb_file_ops fop_type;
  183. struct mei_msg_data buf;
  184. unsigned long buf_idx;
  185. unsigned long read_time;
  186. struct file *file_object;
  187. int status;
  188. u32 internal:1;
  189. u32 completed:1;
  190. };
  191. /**
  192. * struct mei_cl - me client host representation
  193. * carried in file->private_data
  194. *
  195. * @link: link in the clients list
  196. * @dev: mei parent device
  197. * @state: file operation state
  198. * @tx_wait: wait queue for tx completion
  199. * @rx_wait: wait queue for rx completion
  200. * @wait: wait queue for management operation
  201. * @status: connection status
  202. * @me_cl: fw client connected
  203. * @host_client_id: host id
  204. * @mei_flow_ctrl_creds: transmit flow credentials
  205. * @timer_count: watchdog timer for operation completion
  206. * @reserved: reserved for alignment
  207. * @writing_state: state of the tx
  208. * @rd_pending: pending read credits
  209. * @rd_completed: completed read
  210. *
  211. * @device: device on the mei client bus
  212. * @device_link: link to bus clients
  213. */
  214. struct mei_cl {
  215. struct list_head link;
  216. struct mei_device *dev;
  217. enum file_state state;
  218. wait_queue_head_t tx_wait;
  219. wait_queue_head_t rx_wait;
  220. wait_queue_head_t wait;
  221. int status;
  222. struct mei_me_client *me_cl;
  223. u8 host_client_id;
  224. u8 mei_flow_ctrl_creds;
  225. u8 timer_count;
  226. u8 reserved;
  227. enum mei_file_transaction_states writing_state;
  228. struct list_head rd_pending;
  229. struct list_head rd_completed;
  230. /* MEI CL bus data */
  231. struct mei_cl_device *device;
  232. struct list_head device_link;
  233. };
  234. /** struct mei_hw_ops
  235. *
  236. * @host_is_ready : query for host readiness
  237. * @hw_is_ready : query if hw is ready
  238. * @hw_reset : reset hw
  239. * @hw_start : start hw after reset
  240. * @hw_config : configure hw
  241. * @fw_status : get fw status registers
  242. * @pg_state : power gating state of the device
  243. * @pg_in_transition : is device now in pg transition
  244. * @pg_is_enabled : is power gating enabled
  245. * @intr_clear : clear pending interrupts
  246. * @intr_enable : enable interrupts
  247. * @intr_disable : disable interrupts
  248. * @hbuf_free_slots : query for write buffer empty slots
  249. * @hbuf_is_ready : query if write buffer is empty
  250. * @hbuf_max_len : query for write buffer max len
  251. * @write : write a message to FW
  252. * @rdbuf_full_slots : query how many slots are filled
  253. * @read_hdr : get first 4 bytes (header)
  254. * @read : read a buffer from the FW
  255. */
  256. struct mei_hw_ops {
  257. bool (*host_is_ready)(struct mei_device *dev);
  258. bool (*hw_is_ready)(struct mei_device *dev);
  259. int (*hw_reset)(struct mei_device *dev, bool enable);
  260. int (*hw_start)(struct mei_device *dev);
  261. void (*hw_config)(struct mei_device *dev);
  262. int (*fw_status)(struct mei_device *dev, struct mei_fw_status *fw_sts);
  263. enum mei_pg_state (*pg_state)(struct mei_device *dev);
  264. bool (*pg_in_transition)(struct mei_device *dev);
  265. bool (*pg_is_enabled)(struct mei_device *dev);
  266. void (*intr_clear)(struct mei_device *dev);
  267. void (*intr_enable)(struct mei_device *dev);
  268. void (*intr_disable)(struct mei_device *dev);
  269. int (*hbuf_free_slots)(struct mei_device *dev);
  270. bool (*hbuf_is_ready)(struct mei_device *dev);
  271. size_t (*hbuf_max_len)(const struct mei_device *dev);
  272. int (*write)(struct mei_device *dev,
  273. struct mei_msg_hdr *hdr,
  274. unsigned char *buf);
  275. int (*rdbuf_full_slots)(struct mei_device *dev);
  276. u32 (*read_hdr)(const struct mei_device *dev);
  277. int (*read)(struct mei_device *dev,
  278. unsigned char *buf, unsigned long len);
  279. };
  280. /* MEI bus API*/
  281. struct mei_cl_device *mei_cl_add_device(struct mei_device *dev,
  282. struct mei_me_client *me_cl,
  283. struct mei_cl *cl,
  284. char *name);
  285. void mei_cl_remove_device(struct mei_cl_device *device);
  286. ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
  287. bool blocking);
  288. ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length);
  289. void mei_cl_bus_rx_event(struct mei_cl *cl);
  290. void mei_cl_bus_remove_devices(struct mei_device *dev);
  291. int mei_cl_bus_init(void);
  292. void mei_cl_bus_exit(void);
  293. struct mei_cl *mei_cl_bus_find_cl_by_uuid(struct mei_device *dev, uuid_le uuid);
  294. /**
  295. * enum mei_pg_event - power gating transition events
  296. *
  297. * @MEI_PG_EVENT_IDLE: the driver is not in power gating transition
  298. * @MEI_PG_EVENT_WAIT: the driver is waiting for a pg event to complete
  299. * @MEI_PG_EVENT_RECEIVED: the driver received pg event
  300. * @MEI_PG_EVENT_INTR_WAIT: the driver is waiting for a pg event interrupt
  301. * @MEI_PG_EVENT_INTR_RECEIVED: the driver received pg event interrupt
  302. */
  303. enum mei_pg_event {
  304. MEI_PG_EVENT_IDLE,
  305. MEI_PG_EVENT_WAIT,
  306. MEI_PG_EVENT_RECEIVED,
  307. MEI_PG_EVENT_INTR_WAIT,
  308. MEI_PG_EVENT_INTR_RECEIVED,
  309. };
  310. /**
  311. * enum mei_pg_state - device internal power gating state
  312. *
  313. * @MEI_PG_OFF: device is not power gated - it is active
  314. * @MEI_PG_ON: device is power gated - it is in lower power state
  315. */
  316. enum mei_pg_state {
  317. MEI_PG_OFF = 0,
  318. MEI_PG_ON = 1,
  319. };
  320. const char *mei_pg_state_str(enum mei_pg_state state);
  321. /**
  322. * struct mei_device - MEI private device struct
  323. *
  324. * @dev : device on a bus
  325. * @cdev : character device
  326. * @minor : minor number allocated for device
  327. *
  328. * @write_list : write pending list
  329. * @write_waiting_list : write completion list
  330. * @ctrl_wr_list : pending control write list
  331. * @ctrl_rd_list : pending control read list
  332. *
  333. * @file_list : list of opened handles
  334. * @open_handle_count: number of opened handles
  335. *
  336. * @device_lock : big device lock
  337. * @timer_work : MEI timer delayed work (timeouts)
  338. *
  339. * @recvd_hw_ready : hw ready message received flag
  340. *
  341. * @wait_hw_ready : wait queue for receive HW ready message form FW
  342. * @wait_pg : wait queue for receive PG message from FW
  343. * @wait_hbm_start : wait queue for receive HBM start message from FW
  344. * @wait_stop_wd : wait queue for receive WD stop message from FW
  345. *
  346. * @reset_count : number of consecutive resets
  347. * @dev_state : device state
  348. * @hbm_state : state of host bus message protocol
  349. * @init_clients_timer : HBM init handshake timeout
  350. *
  351. * @pg_event : power gating event
  352. * @pg_domain : runtime PM domain
  353. *
  354. * @rd_msg_buf : control messages buffer
  355. * @rd_msg_hdr : read message header storage
  356. *
  357. * @hbuf_depth : depth of hardware host/write buffer is slots
  358. * @hbuf_is_ready : query if the host host/write buffer is ready
  359. * @wr_msg : the buffer for hbm control messages
  360. *
  361. * @version : HBM protocol version in use
  362. * @hbm_f_pg_supported : hbm feature pgi protocol
  363. *
  364. * @me_clients_rwsem: rw lock over me_clients list
  365. * @me_clients : list of FW clients
  366. * @me_clients_map : FW clients bit map
  367. * @host_clients_map : host clients id pool
  368. * @me_client_index : last FW client index in enumeration
  369. *
  370. * @allow_fixed_address: allow user space to connect a fixed client
  371. *
  372. * @wd_cl : watchdog client
  373. * @wd_state : watchdog client state
  374. * @wd_pending : watchdog command is pending
  375. * @wd_timeout : watchdog expiration timeout
  376. * @wd_data : watchdog message buffer
  377. *
  378. * @amthif_cmd_list : amthif list for cmd waiting
  379. * @amthif_rd_complete_list : amthif list for reading completed cmd data
  380. * @iamthif_file_object : file for current amthif operation
  381. * @iamthif_cl : amthif host client
  382. * @iamthif_current_cb : amthif current operation callback
  383. * @iamthif_open_count : number of opened amthif connections
  384. * @iamthif_timer : time stamp of current amthif command completion
  385. * @iamthif_stall_timer : timer to detect amthif hang
  386. * @iamthif_state : amthif processor state
  387. * @iamthif_canceled : current amthif command is canceled
  388. *
  389. * @init_work : work item for the device init
  390. * @reset_work : work item for the device reset
  391. *
  392. * @device_list : mei client bus list
  393. *
  394. * @dbgfs_dir : debugfs mei root directory
  395. *
  396. * @ops: : hw specific operations
  397. * @hw : hw specific data
  398. */
  399. struct mei_device {
  400. struct device *dev;
  401. struct cdev cdev;
  402. int minor;
  403. struct mei_cl_cb write_list;
  404. struct mei_cl_cb write_waiting_list;
  405. struct mei_cl_cb ctrl_wr_list;
  406. struct mei_cl_cb ctrl_rd_list;
  407. struct list_head file_list;
  408. long open_handle_count;
  409. struct mutex device_lock;
  410. struct delayed_work timer_work;
  411. bool recvd_hw_ready;
  412. /*
  413. * waiting queue for receive message from FW
  414. */
  415. wait_queue_head_t wait_hw_ready;
  416. wait_queue_head_t wait_pg;
  417. wait_queue_head_t wait_hbm_start;
  418. wait_queue_head_t wait_stop_wd;
  419. /*
  420. * mei device states
  421. */
  422. unsigned long reset_count;
  423. enum mei_dev_state dev_state;
  424. enum mei_hbm_state hbm_state;
  425. u16 init_clients_timer;
  426. /*
  427. * Power Gating support
  428. */
  429. enum mei_pg_event pg_event;
  430. #ifdef CONFIG_PM
  431. struct dev_pm_domain pg_domain;
  432. #endif /* CONFIG_PM */
  433. unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE];
  434. u32 rd_msg_hdr;
  435. /* write buffer */
  436. u8 hbuf_depth;
  437. bool hbuf_is_ready;
  438. /* used for control messages */
  439. struct {
  440. struct mei_msg_hdr hdr;
  441. unsigned char data[128];
  442. } wr_msg;
  443. struct hbm_version version;
  444. unsigned int hbm_f_pg_supported:1;
  445. struct rw_semaphore me_clients_rwsem;
  446. struct list_head me_clients;
  447. DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
  448. DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
  449. unsigned long me_client_index;
  450. u32 allow_fixed_address;
  451. struct mei_cl wd_cl;
  452. enum mei_wd_states wd_state;
  453. bool wd_pending;
  454. u16 wd_timeout;
  455. unsigned char wd_data[MEI_WD_START_MSG_SIZE];
  456. /* amthif list for cmd waiting */
  457. struct mei_cl_cb amthif_cmd_list;
  458. /* driver managed amthif list for reading completed amthif cmd data */
  459. struct mei_cl_cb amthif_rd_complete_list;
  460. struct file *iamthif_file_object;
  461. struct mei_cl iamthif_cl;
  462. struct mei_cl_cb *iamthif_current_cb;
  463. long iamthif_open_count;
  464. unsigned long iamthif_timer;
  465. u32 iamthif_stall_timer;
  466. enum iamthif_states iamthif_state;
  467. bool iamthif_canceled;
  468. struct work_struct init_work;
  469. struct work_struct reset_work;
  470. /* List of bus devices */
  471. struct list_head device_list;
  472. #if IS_ENABLED(CONFIG_DEBUG_FS)
  473. struct dentry *dbgfs_dir;
  474. #endif /* CONFIG_DEBUG_FS */
  475. const struct mei_hw_ops *ops;
  476. char hw[0] __aligned(sizeof(void *));
  477. };
  478. static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
  479. {
  480. return msecs_to_jiffies(sec * MSEC_PER_SEC);
  481. }
  482. /**
  483. * mei_data2slots - get slots - number of (dwords) from a message length
  484. * + size of the mei header
  485. *
  486. * @length: size of the messages in bytes
  487. *
  488. * Return: number of slots
  489. */
  490. static inline u32 mei_data2slots(size_t length)
  491. {
  492. return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4);
  493. }
  494. /**
  495. * mei_slots2data - get data in slots - bytes from slots
  496. *
  497. * @slots: number of available slots
  498. *
  499. * Return: number of bytes in slots
  500. */
  501. static inline u32 mei_slots2data(int slots)
  502. {
  503. return slots * 4;
  504. }
  505. /*
  506. * mei init function prototypes
  507. */
  508. void mei_device_init(struct mei_device *dev,
  509. struct device *device,
  510. const struct mei_hw_ops *hw_ops);
  511. int mei_reset(struct mei_device *dev);
  512. int mei_start(struct mei_device *dev);
  513. int mei_restart(struct mei_device *dev);
  514. void mei_stop(struct mei_device *dev);
  515. void mei_cancel_work(struct mei_device *dev);
  516. /*
  517. * MEI interrupt functions prototype
  518. */
  519. void mei_timer(struct work_struct *work);
  520. int mei_irq_read_handler(struct mei_device *dev,
  521. struct mei_cl_cb *cmpl_list, s32 *slots);
  522. int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list);
  523. void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list);
  524. /*
  525. * AMTHIF - AMT Host Interface Functions
  526. */
  527. void mei_amthif_reset_params(struct mei_device *dev);
  528. int mei_amthif_host_init(struct mei_device *dev, struct mei_me_client *me_cl);
  529. int mei_amthif_read(struct mei_device *dev, struct file *file,
  530. char __user *ubuf, size_t length, loff_t *offset);
  531. unsigned int mei_amthif_poll(struct mei_device *dev,
  532. struct file *file, poll_table *wait);
  533. int mei_amthif_release(struct mei_device *dev, struct file *file);
  534. struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev,
  535. struct file *file);
  536. int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb);
  537. int mei_amthif_run_next_cmd(struct mei_device *dev);
  538. int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb,
  539. struct mei_cl_cb *cmpl_list);
  540. void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb);
  541. int mei_amthif_irq_read_msg(struct mei_cl *cl,
  542. struct mei_msg_hdr *mei_hdr,
  543. struct mei_cl_cb *complete_list);
  544. int mei_amthif_irq_read(struct mei_device *dev, s32 *slots);
  545. /*
  546. * NFC functions
  547. */
  548. int mei_nfc_host_init(struct mei_device *dev, struct mei_me_client *me_cl);
  549. void mei_nfc_host_exit(struct mei_device *dev);
  550. /*
  551. * NFC Client UUID
  552. */
  553. extern const uuid_le mei_nfc_guid;
  554. int mei_wd_send(struct mei_device *dev);
  555. int mei_wd_stop(struct mei_device *dev);
  556. int mei_wd_host_init(struct mei_device *dev, struct mei_me_client *me_cl);
  557. /*
  558. * mei_watchdog_register - Registering watchdog interface
  559. * once we got connection to the WD Client
  560. * @dev: mei device
  561. */
  562. int mei_watchdog_register(struct mei_device *dev);
  563. /*
  564. * mei_watchdog_unregister - Unregistering watchdog interface
  565. * @dev: mei device
  566. */
  567. void mei_watchdog_unregister(struct mei_device *dev);
  568. /*
  569. * Register Access Function
  570. */
  571. static inline void mei_hw_config(struct mei_device *dev)
  572. {
  573. dev->ops->hw_config(dev);
  574. }
  575. static inline enum mei_pg_state mei_pg_state(struct mei_device *dev)
  576. {
  577. return dev->ops->pg_state(dev);
  578. }
  579. static inline bool mei_pg_in_transition(struct mei_device *dev)
  580. {
  581. return dev->ops->pg_in_transition(dev);
  582. }
  583. static inline bool mei_pg_is_enabled(struct mei_device *dev)
  584. {
  585. return dev->ops->pg_is_enabled(dev);
  586. }
  587. static inline int mei_hw_reset(struct mei_device *dev, bool enable)
  588. {
  589. return dev->ops->hw_reset(dev, enable);
  590. }
  591. static inline int mei_hw_start(struct mei_device *dev)
  592. {
  593. return dev->ops->hw_start(dev);
  594. }
  595. static inline void mei_clear_interrupts(struct mei_device *dev)
  596. {
  597. dev->ops->intr_clear(dev);
  598. }
  599. static inline void mei_enable_interrupts(struct mei_device *dev)
  600. {
  601. dev->ops->intr_enable(dev);
  602. }
  603. static inline void mei_disable_interrupts(struct mei_device *dev)
  604. {
  605. dev->ops->intr_disable(dev);
  606. }
  607. static inline bool mei_host_is_ready(struct mei_device *dev)
  608. {
  609. return dev->ops->host_is_ready(dev);
  610. }
  611. static inline bool mei_hw_is_ready(struct mei_device *dev)
  612. {
  613. return dev->ops->hw_is_ready(dev);
  614. }
  615. static inline bool mei_hbuf_is_ready(struct mei_device *dev)
  616. {
  617. return dev->ops->hbuf_is_ready(dev);
  618. }
  619. static inline int mei_hbuf_empty_slots(struct mei_device *dev)
  620. {
  621. return dev->ops->hbuf_free_slots(dev);
  622. }
  623. static inline size_t mei_hbuf_max_len(const struct mei_device *dev)
  624. {
  625. return dev->ops->hbuf_max_len(dev);
  626. }
  627. static inline int mei_write_message(struct mei_device *dev,
  628. struct mei_msg_hdr *hdr,
  629. unsigned char *buf)
  630. {
  631. return dev->ops->write(dev, hdr, buf);
  632. }
  633. static inline u32 mei_read_hdr(const struct mei_device *dev)
  634. {
  635. return dev->ops->read_hdr(dev);
  636. }
  637. static inline void mei_read_slots(struct mei_device *dev,
  638. unsigned char *buf, unsigned long len)
  639. {
  640. dev->ops->read(dev, buf, len);
  641. }
  642. static inline int mei_count_full_read_slots(struct mei_device *dev)
  643. {
  644. return dev->ops->rdbuf_full_slots(dev);
  645. }
  646. static inline int mei_fw_status(struct mei_device *dev,
  647. struct mei_fw_status *fw_status)
  648. {
  649. return dev->ops->fw_status(dev, fw_status);
  650. }
  651. bool mei_hbuf_acquire(struct mei_device *dev);
  652. bool mei_write_is_idle(struct mei_device *dev);
  653. #if IS_ENABLED(CONFIG_DEBUG_FS)
  654. int mei_dbgfs_register(struct mei_device *dev, const char *name);
  655. void mei_dbgfs_deregister(struct mei_device *dev);
  656. #else
  657. static inline int mei_dbgfs_register(struct mei_device *dev, const char *name)
  658. {
  659. return 0;
  660. }
  661. static inline void mei_dbgfs_deregister(struct mei_device *dev) {}
  662. #endif /* CONFIG_DEBUG_FS */
  663. int mei_register(struct mei_device *dev, struct device *parent);
  664. void mei_deregister(struct mei_device *dev);
  665. #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d internal=%1d comp=%1d"
  666. #define MEI_HDR_PRM(hdr) \
  667. (hdr)->host_addr, (hdr)->me_addr, \
  668. (hdr)->length, (hdr)->internal, (hdr)->msg_complete
  669. ssize_t mei_fw_status2str(struct mei_fw_status *fw_sts, char *buf, size_t len);
  670. /**
  671. * mei_fw_status_str - fetch and convert fw status registers to printable string
  672. *
  673. * @dev: the device structure
  674. * @buf: string buffer at minimal size MEI_FW_STATUS_STR_SZ
  675. * @len: buffer len must be >= MEI_FW_STATUS_STR_SZ
  676. *
  677. * Return: number of bytes written or < 0 on failure
  678. */
  679. static inline ssize_t mei_fw_status_str(struct mei_device *dev,
  680. char *buf, size_t len)
  681. {
  682. struct mei_fw_status fw_status;
  683. int ret;
  684. buf[0] = '\0';
  685. ret = mei_fw_status(dev, &fw_status);
  686. if (ret)
  687. return ret;
  688. ret = mei_fw_status2str(&fw_status, buf, MEI_FW_STATUS_STR_SZ);
  689. return ret;
  690. }
  691. #endif