mei_dev.h 18 KB

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