mei_dev.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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_FLOW_CONTROL,
  71. MEI_IAMTHIF_READING,
  72. MEI_IAMTHIF_READ_COMPLETE
  73. };
  74. enum mei_file_transaction_states {
  75. MEI_IDLE,
  76. MEI_WRITING,
  77. MEI_WRITE_COMPLETE,
  78. MEI_FLOW_CONTROL,
  79. MEI_READING,
  80. MEI_READ_COMPLETE
  81. };
  82. /**
  83. * enum mei_cb_file_ops - file operation associated with the callback
  84. * @MEI_FOP_READ: read
  85. * @MEI_FOP_WRITE: write
  86. * @MEI_FOP_CONNECT: connect
  87. * @MEI_FOP_DISCONNECT: disconnect
  88. * @MEI_FOP_DISCONNECT_RSP: disconnect response
  89. * @MEI_FOP_NOTIFY_START: start notification
  90. * @MEI_FOP_NOTIFY_STOP: stop notification
  91. */
  92. enum mei_cb_file_ops {
  93. MEI_FOP_READ = 0,
  94. MEI_FOP_WRITE,
  95. MEI_FOP_CONNECT,
  96. MEI_FOP_DISCONNECT,
  97. MEI_FOP_DISCONNECT_RSP,
  98. MEI_FOP_NOTIFY_START,
  99. MEI_FOP_NOTIFY_STOP,
  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. * @mei_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 mei_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. * @completed: the transfer or reception has completed
  155. */
  156. struct mei_cl_cb {
  157. struct list_head list;
  158. struct mei_cl *cl;
  159. enum mei_cb_file_ops fop_type;
  160. struct mei_msg_data buf;
  161. size_t buf_idx;
  162. const struct file *fp;
  163. int status;
  164. u32 internal:1;
  165. u32 completed:1;
  166. };
  167. /**
  168. * struct mei_cl - me client host representation
  169. * carried in file->private_data
  170. *
  171. * @link: link in the clients list
  172. * @dev: mei parent device
  173. * @state: file operation state
  174. * @tx_wait: wait queue for tx completion
  175. * @rx_wait: wait queue for rx completion
  176. * @wait: wait queue for management operation
  177. * @ev_wait: notification wait queue
  178. * @ev_async: event async notification
  179. * @status: connection status
  180. * @me_cl: fw client connected
  181. * @host_client_id: host id
  182. * @mei_flow_ctrl_creds: transmit flow credentials
  183. * @timer_count: watchdog timer for operation completion
  184. * @reserved: reserved for alignment
  185. * @notify_en: notification - enabled/disabled
  186. * @notify_ev: pending notification event
  187. * @writing_state: state of the tx
  188. * @rd_pending: pending read credits
  189. * @rd_completed: completed read
  190. *
  191. * @cldev: device on the mei client bus
  192. */
  193. struct mei_cl {
  194. struct list_head link;
  195. struct mei_device *dev;
  196. enum file_state state;
  197. wait_queue_head_t tx_wait;
  198. wait_queue_head_t rx_wait;
  199. wait_queue_head_t wait;
  200. wait_queue_head_t ev_wait;
  201. struct fasync_struct *ev_async;
  202. int status;
  203. struct mei_me_client *me_cl;
  204. u8 host_client_id;
  205. u8 mei_flow_ctrl_creds;
  206. u8 timer_count;
  207. u8 reserved;
  208. u8 notify_en;
  209. u8 notify_ev;
  210. enum mei_file_transaction_states writing_state;
  211. struct list_head rd_pending;
  212. struct list_head rd_completed;
  213. struct mei_cl_device *cldev;
  214. };
  215. /**
  216. * struct mei_hw_ops - hw specific ops
  217. *
  218. * @host_is_ready : query for host readiness
  219. *
  220. * @hw_is_ready : query if hw is ready
  221. * @hw_reset : reset hw
  222. * @hw_start : start hw after reset
  223. * @hw_config : configure hw
  224. *
  225. * @fw_status : get fw status registers
  226. * @pg_state : power gating state of the device
  227. * @pg_in_transition : is device now in pg transition
  228. * @pg_is_enabled : is power gating enabled
  229. *
  230. * @intr_clear : clear pending interrupts
  231. * @intr_enable : enable interrupts
  232. * @intr_disable : disable interrupts
  233. *
  234. * @hbuf_free_slots : query for write buffer empty slots
  235. * @hbuf_is_ready : query if write buffer is empty
  236. * @hbuf_max_len : query for write buffer max len
  237. *
  238. * @write : write a message to FW
  239. *
  240. * @rdbuf_full_slots : query how many slots are filled
  241. *
  242. * @read_hdr : get first 4 bytes (header)
  243. * @read : read a buffer from the FW
  244. */
  245. struct mei_hw_ops {
  246. bool (*host_is_ready)(struct mei_device *dev);
  247. bool (*hw_is_ready)(struct mei_device *dev);
  248. int (*hw_reset)(struct mei_device *dev, bool enable);
  249. int (*hw_start)(struct mei_device *dev);
  250. void (*hw_config)(struct mei_device *dev);
  251. int (*fw_status)(struct mei_device *dev, struct mei_fw_status *fw_sts);
  252. enum mei_pg_state (*pg_state)(struct mei_device *dev);
  253. bool (*pg_in_transition)(struct mei_device *dev);
  254. bool (*pg_is_enabled)(struct mei_device *dev);
  255. void (*intr_clear)(struct mei_device *dev);
  256. void (*intr_enable)(struct mei_device *dev);
  257. void (*intr_disable)(struct mei_device *dev);
  258. int (*hbuf_free_slots)(struct mei_device *dev);
  259. bool (*hbuf_is_ready)(struct mei_device *dev);
  260. size_t (*hbuf_max_len)(const struct mei_device *dev);
  261. int (*write)(struct mei_device *dev,
  262. struct mei_msg_hdr *hdr,
  263. unsigned char *buf);
  264. int (*rdbuf_full_slots)(struct mei_device *dev);
  265. u32 (*read_hdr)(const struct mei_device *dev);
  266. int (*read)(struct mei_device *dev,
  267. unsigned char *buf, unsigned long len);
  268. };
  269. /* MEI bus API*/
  270. void mei_cl_bus_rescan(struct mei_device *bus);
  271. void mei_cl_bus_rescan_work(struct work_struct *work);
  272. void mei_cl_bus_dev_fixup(struct mei_cl_device *dev);
  273. ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
  274. bool blocking);
  275. ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length);
  276. bool mei_cl_bus_rx_event(struct mei_cl *cl);
  277. bool mei_cl_bus_notify_event(struct mei_cl *cl);
  278. void mei_cl_bus_remove_devices(struct mei_device *bus);
  279. int mei_cl_bus_init(void);
  280. void mei_cl_bus_exit(void);
  281. /**
  282. * enum mei_pg_event - power gating transition events
  283. *
  284. * @MEI_PG_EVENT_IDLE: the driver is not in power gating transition
  285. * @MEI_PG_EVENT_WAIT: the driver is waiting for a pg event to complete
  286. * @MEI_PG_EVENT_RECEIVED: the driver received pg event
  287. * @MEI_PG_EVENT_INTR_WAIT: the driver is waiting for a pg event interrupt
  288. * @MEI_PG_EVENT_INTR_RECEIVED: the driver received pg event interrupt
  289. */
  290. enum mei_pg_event {
  291. MEI_PG_EVENT_IDLE,
  292. MEI_PG_EVENT_WAIT,
  293. MEI_PG_EVENT_RECEIVED,
  294. MEI_PG_EVENT_INTR_WAIT,
  295. MEI_PG_EVENT_INTR_RECEIVED,
  296. };
  297. /**
  298. * enum mei_pg_state - device internal power gating state
  299. *
  300. * @MEI_PG_OFF: device is not power gated - it is active
  301. * @MEI_PG_ON: device is power gated - it is in lower power state
  302. */
  303. enum mei_pg_state {
  304. MEI_PG_OFF = 0,
  305. MEI_PG_ON = 1,
  306. };
  307. const char *mei_pg_state_str(enum mei_pg_state state);
  308. /**
  309. * struct mei_device - MEI private device struct
  310. *
  311. * @dev : device on a bus
  312. * @cdev : character device
  313. * @minor : minor number allocated for device
  314. *
  315. * @write_list : write pending list
  316. * @write_waiting_list : write completion list
  317. * @ctrl_wr_list : pending control write list
  318. * @ctrl_rd_list : pending control read list
  319. *
  320. * @file_list : list of opened handles
  321. * @open_handle_count: number of opened handles
  322. *
  323. * @device_lock : big device lock
  324. * @timer_work : MEI timer delayed work (timeouts)
  325. *
  326. * @recvd_hw_ready : hw ready message received flag
  327. *
  328. * @wait_hw_ready : wait queue for receive HW ready message form FW
  329. * @wait_pg : wait queue for receive PG message from FW
  330. * @wait_hbm_start : wait queue for receive HBM start message from FW
  331. *
  332. * @reset_count : number of consecutive resets
  333. * @dev_state : device state
  334. * @hbm_state : state of host bus message protocol
  335. * @init_clients_timer : HBM init handshake timeout
  336. *
  337. * @pg_event : power gating event
  338. * @pg_domain : runtime PM domain
  339. *
  340. * @rd_msg_buf : control messages buffer
  341. * @rd_msg_hdr : read message header storage
  342. *
  343. * @hbuf_depth : depth of hardware host/write buffer is slots
  344. * @hbuf_is_ready : query if the host host/write buffer is ready
  345. * @wr_msg : the buffer for hbm control messages
  346. *
  347. * @version : HBM protocol version in use
  348. * @hbm_f_pg_supported : hbm feature pgi protocol
  349. * @hbm_f_dc_supported : hbm feature dynamic clients
  350. * @hbm_f_dot_supported : hbm feature disconnect on timeout
  351. * @hbm_f_ev_supported : hbm feature event notification
  352. * @hbm_f_fa_supported : hbm feature fixed address client
  353. * @hbm_f_ie_supported : hbm feature immediate reply to enum request
  354. *
  355. * @me_clients_rwsem: rw lock over me_clients list
  356. * @me_clients : list of FW clients
  357. * @me_clients_map : FW clients bit map
  358. * @host_clients_map : host clients id pool
  359. * @me_client_index : last FW client index in enumeration
  360. *
  361. * @allow_fixed_address: allow user space to connect a fixed client
  362. * @override_fixed_address: force allow fixed address behavior
  363. *
  364. * @amthif_cmd_list : amthif list for cmd waiting
  365. * @iamthif_fp : file for current amthif operation
  366. * @iamthif_cl : amthif host client
  367. * @iamthif_current_cb : amthif current operation callback
  368. * @iamthif_open_count : number of opened amthif connections
  369. * @iamthif_stall_timer : timer to detect amthif hang
  370. * @iamthif_state : amthif processor state
  371. * @iamthif_canceled : current amthif command is canceled
  372. *
  373. * @reset_work : work item for the device reset
  374. * @bus_rescan_work : work item for the bus rescan
  375. *
  376. * @device_list : mei client bus list
  377. * @cl_bus_lock : client bus list lock
  378. *
  379. * @dbgfs_dir : debugfs mei root directory
  380. *
  381. * @ops: : hw specific operations
  382. * @hw : hw specific data
  383. */
  384. struct mei_device {
  385. struct device *dev;
  386. struct cdev cdev;
  387. int minor;
  388. struct mei_cl_cb write_list;
  389. struct mei_cl_cb write_waiting_list;
  390. struct mei_cl_cb ctrl_wr_list;
  391. struct mei_cl_cb ctrl_rd_list;
  392. struct list_head file_list;
  393. long open_handle_count;
  394. struct mutex device_lock;
  395. struct delayed_work timer_work;
  396. bool recvd_hw_ready;
  397. /*
  398. * waiting queue for receive message from FW
  399. */
  400. wait_queue_head_t wait_hw_ready;
  401. wait_queue_head_t wait_pg;
  402. wait_queue_head_t wait_hbm_start;
  403. /*
  404. * mei device states
  405. */
  406. unsigned long reset_count;
  407. enum mei_dev_state dev_state;
  408. enum mei_hbm_state hbm_state;
  409. u16 init_clients_timer;
  410. /*
  411. * Power Gating support
  412. */
  413. enum mei_pg_event pg_event;
  414. #ifdef CONFIG_PM
  415. struct dev_pm_domain pg_domain;
  416. #endif /* CONFIG_PM */
  417. unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE];
  418. u32 rd_msg_hdr;
  419. /* write buffer */
  420. u8 hbuf_depth;
  421. bool hbuf_is_ready;
  422. /* used for control messages */
  423. struct {
  424. struct mei_msg_hdr hdr;
  425. unsigned char data[128];
  426. } wr_msg;
  427. struct hbm_version version;
  428. unsigned int hbm_f_pg_supported:1;
  429. unsigned int hbm_f_dc_supported:1;
  430. unsigned int hbm_f_dot_supported:1;
  431. unsigned int hbm_f_ev_supported:1;
  432. unsigned int hbm_f_fa_supported:1;
  433. unsigned int hbm_f_ie_supported:1;
  434. struct rw_semaphore me_clients_rwsem;
  435. struct list_head me_clients;
  436. DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
  437. DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
  438. unsigned long me_client_index;
  439. bool allow_fixed_address;
  440. bool override_fixed_address;
  441. /* amthif list for cmd waiting */
  442. struct mei_cl_cb amthif_cmd_list;
  443. /* driver managed amthif list for reading completed amthif cmd data */
  444. const struct file *iamthif_fp;
  445. struct mei_cl iamthif_cl;
  446. struct mei_cl_cb *iamthif_current_cb;
  447. long iamthif_open_count;
  448. u32 iamthif_stall_timer;
  449. enum iamthif_states iamthif_state;
  450. bool iamthif_canceled;
  451. struct work_struct reset_work;
  452. struct work_struct bus_rescan_work;
  453. /* List of bus devices */
  454. struct list_head device_list;
  455. struct mutex cl_bus_lock;
  456. #if IS_ENABLED(CONFIG_DEBUG_FS)
  457. struct dentry *dbgfs_dir;
  458. #endif /* CONFIG_DEBUG_FS */
  459. const struct mei_hw_ops *ops;
  460. char hw[0] __aligned(sizeof(void *));
  461. };
  462. static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
  463. {
  464. return msecs_to_jiffies(sec * MSEC_PER_SEC);
  465. }
  466. /**
  467. * mei_data2slots - get slots - number of (dwords) from a message length
  468. * + size of the mei header
  469. *
  470. * @length: size of the messages in bytes
  471. *
  472. * Return: number of slots
  473. */
  474. static inline u32 mei_data2slots(size_t length)
  475. {
  476. return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4);
  477. }
  478. /**
  479. * mei_slots2data - get data in slots - bytes from slots
  480. *
  481. * @slots: number of available slots
  482. *
  483. * Return: number of bytes in slots
  484. */
  485. static inline u32 mei_slots2data(int slots)
  486. {
  487. return slots * 4;
  488. }
  489. /*
  490. * mei init function prototypes
  491. */
  492. void mei_device_init(struct mei_device *dev,
  493. struct device *device,
  494. const struct mei_hw_ops *hw_ops);
  495. int mei_reset(struct mei_device *dev);
  496. int mei_start(struct mei_device *dev);
  497. int mei_restart(struct mei_device *dev);
  498. void mei_stop(struct mei_device *dev);
  499. void mei_cancel_work(struct mei_device *dev);
  500. /*
  501. * MEI interrupt functions prototype
  502. */
  503. void mei_timer(struct work_struct *work);
  504. int mei_irq_read_handler(struct mei_device *dev,
  505. struct mei_cl_cb *cmpl_list, s32 *slots);
  506. int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list);
  507. void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list);
  508. /*
  509. * AMTHIF - AMT Host Interface Functions
  510. */
  511. void mei_amthif_reset_params(struct mei_device *dev);
  512. int mei_amthif_host_init(struct mei_device *dev, struct mei_me_client *me_cl);
  513. int mei_amthif_read(struct mei_device *dev, struct file *file,
  514. char __user *ubuf, size_t length, loff_t *offset);
  515. unsigned int mei_amthif_poll(struct mei_device *dev,
  516. struct file *file, poll_table *wait);
  517. int mei_amthif_release(struct mei_device *dev, struct file *file);
  518. int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb);
  519. int mei_amthif_run_next_cmd(struct mei_device *dev);
  520. int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb,
  521. struct mei_cl_cb *cmpl_list);
  522. void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb);
  523. int mei_amthif_irq_read_msg(struct mei_cl *cl,
  524. struct mei_msg_hdr *mei_hdr,
  525. struct mei_cl_cb *complete_list);
  526. int mei_amthif_irq_read(struct mei_device *dev, s32 *slots);
  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 bool mei_host_is_ready(struct mei_device *dev)
  567. {
  568. return dev->ops->host_is_ready(dev);
  569. }
  570. static inline bool mei_hw_is_ready(struct mei_device *dev)
  571. {
  572. return dev->ops->hw_is_ready(dev);
  573. }
  574. static inline bool mei_hbuf_is_ready(struct mei_device *dev)
  575. {
  576. return dev->ops->hbuf_is_ready(dev);
  577. }
  578. static inline int mei_hbuf_empty_slots(struct mei_device *dev)
  579. {
  580. return dev->ops->hbuf_free_slots(dev);
  581. }
  582. static inline size_t mei_hbuf_max_len(const struct mei_device *dev)
  583. {
  584. return dev->ops->hbuf_max_len(dev);
  585. }
  586. static inline int mei_write_message(struct mei_device *dev,
  587. struct mei_msg_hdr *hdr,
  588. unsigned char *buf)
  589. {
  590. return dev->ops->write(dev, hdr, buf);
  591. }
  592. static inline u32 mei_read_hdr(const struct mei_device *dev)
  593. {
  594. return dev->ops->read_hdr(dev);
  595. }
  596. static inline void mei_read_slots(struct mei_device *dev,
  597. unsigned char *buf, unsigned long len)
  598. {
  599. dev->ops->read(dev, buf, len);
  600. }
  601. static inline int mei_count_full_read_slots(struct mei_device *dev)
  602. {
  603. return dev->ops->rdbuf_full_slots(dev);
  604. }
  605. static inline int mei_fw_status(struct mei_device *dev,
  606. struct mei_fw_status *fw_status)
  607. {
  608. return dev->ops->fw_status(dev, fw_status);
  609. }
  610. bool mei_hbuf_acquire(struct mei_device *dev);
  611. bool mei_write_is_idle(struct mei_device *dev);
  612. #if IS_ENABLED(CONFIG_DEBUG_FS)
  613. int mei_dbgfs_register(struct mei_device *dev, const char *name);
  614. void mei_dbgfs_deregister(struct mei_device *dev);
  615. #else
  616. static inline int mei_dbgfs_register(struct mei_device *dev, const char *name)
  617. {
  618. return 0;
  619. }
  620. static inline void mei_dbgfs_deregister(struct mei_device *dev) {}
  621. #endif /* CONFIG_DEBUG_FS */
  622. int mei_register(struct mei_device *dev, struct device *parent);
  623. void mei_deregister(struct mei_device *dev);
  624. #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d internal=%1d comp=%1d"
  625. #define MEI_HDR_PRM(hdr) \
  626. (hdr)->host_addr, (hdr)->me_addr, \
  627. (hdr)->length, (hdr)->internal, (hdr)->msg_complete
  628. ssize_t mei_fw_status2str(struct mei_fw_status *fw_sts, char *buf, size_t len);
  629. /**
  630. * mei_fw_status_str - fetch and convert fw status registers to printable string
  631. *
  632. * @dev: the device structure
  633. * @buf: string buffer at minimal size MEI_FW_STATUS_STR_SZ
  634. * @len: buffer len must be >= MEI_FW_STATUS_STR_SZ
  635. *
  636. * Return: number of bytes written or < 0 on failure
  637. */
  638. static inline ssize_t mei_fw_status_str(struct mei_device *dev,
  639. char *buf, size_t len)
  640. {
  641. struct mei_fw_status fw_status;
  642. int ret;
  643. buf[0] = '\0';
  644. ret = mei_fw_status(dev, &fw_status);
  645. if (ret)
  646. return ret;
  647. ret = mei_fw_status2str(&fw_status, buf, MEI_FW_STATUS_STR_SZ);
  648. return ret;
  649. }
  650. #endif