mei_dev.h 20 KB

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