mei_dev.h 19 KB

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