mei_dev.h 19 KB

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