mei_dev.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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/watchdog.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. * watch dog definition
  27. */
  28. #define MEI_WD_HDR_SIZE 4
  29. #define MEI_WD_STOP_MSG_SIZE MEI_WD_HDR_SIZE
  30. #define MEI_WD_START_MSG_SIZE (MEI_WD_HDR_SIZE + 16)
  31. #define MEI_WD_DEFAULT_TIMEOUT 120 /* seconds */
  32. #define MEI_WD_MIN_TIMEOUT 120 /* seconds */
  33. #define MEI_WD_MAX_TIMEOUT 65535 /* seconds */
  34. #define MEI_WD_STOP_TIMEOUT 10 /* msecs */
  35. #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0)
  36. #define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32))
  37. /*
  38. * AMTHI Client UUID
  39. */
  40. extern const uuid_le mei_amthif_guid;
  41. /*
  42. * Watchdog Client UUID
  43. */
  44. extern const uuid_le mei_wd_guid;
  45. /*
  46. * Number of Maximum MEI Clients
  47. */
  48. #define MEI_CLIENTS_MAX 256
  49. /*
  50. * maximum number of consecutive resets
  51. */
  52. #define MEI_MAX_CONSEC_RESET 3
  53. /*
  54. * Number of File descriptors/handles
  55. * that can be opened to the driver.
  56. *
  57. * Limit to 255: 256 Total Clients
  58. * minus internal client for MEI Bus Messages
  59. */
  60. #define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 1)
  61. /*
  62. * Internal Clients Number
  63. */
  64. #define MEI_HOST_CLIENT_ID_ANY (-1)
  65. #define MEI_HBM_HOST_CLIENT_ID 0 /* not used, just for documentation */
  66. #define MEI_WD_HOST_CLIENT_ID 1
  67. #define MEI_IAMTHIF_HOST_CLIENT_ID 2
  68. /* File state */
  69. enum file_state {
  70. MEI_FILE_INITIALIZING = 0,
  71. MEI_FILE_CONNECTING,
  72. MEI_FILE_CONNECTED,
  73. MEI_FILE_DISCONNECTING,
  74. MEI_FILE_DISCONNECTED
  75. };
  76. /* MEI device states */
  77. enum mei_dev_state {
  78. MEI_DEV_INITIALIZING = 0,
  79. MEI_DEV_INIT_CLIENTS,
  80. MEI_DEV_ENABLED,
  81. MEI_DEV_RESETTING,
  82. MEI_DEV_DISABLED,
  83. MEI_DEV_POWER_DOWN,
  84. MEI_DEV_POWER_UP
  85. };
  86. const char *mei_dev_state_str(int state);
  87. enum iamthif_states {
  88. MEI_IAMTHIF_IDLE,
  89. MEI_IAMTHIF_WRITING,
  90. MEI_IAMTHIF_FLOW_CONTROL,
  91. MEI_IAMTHIF_READING,
  92. MEI_IAMTHIF_READ_COMPLETE
  93. };
  94. enum mei_file_transaction_states {
  95. MEI_IDLE,
  96. MEI_WRITING,
  97. MEI_WRITE_COMPLETE,
  98. MEI_FLOW_CONTROL,
  99. MEI_READING,
  100. MEI_READ_COMPLETE
  101. };
  102. enum mei_wd_states {
  103. MEI_WD_IDLE,
  104. MEI_WD_RUNNING,
  105. MEI_WD_STOPPING,
  106. };
  107. /**
  108. * enum mei_cb_file_ops - file operation associated with the callback
  109. * @MEI_FOP_READ - read
  110. * @MEI_FOP_WRITE - write
  111. * @MEI_FOP_CONNECT - connect
  112. * @MEI_FOP_DISCONNECT_RSP - disconnect response
  113. * @MEI_FOP_OPEN - open
  114. * @MEI_FOP_CLOSE - close
  115. */
  116. enum mei_cb_file_ops {
  117. MEI_FOP_READ = 0,
  118. MEI_FOP_WRITE,
  119. MEI_FOP_CONNECT,
  120. MEI_FOP_DISCONNECT_RSP,
  121. MEI_FOP_OPEN,
  122. MEI_FOP_CLOSE
  123. };
  124. /*
  125. * Intel MEI message data struct
  126. */
  127. struct mei_msg_data {
  128. u32 size;
  129. unsigned char *data;
  130. };
  131. /* Maximum number of processed FW status registers */
  132. #define MEI_FW_STATUS_MAX 2
  133. /*
  134. * struct mei_fw_status - storage of FW status data
  135. *
  136. * @count - number of actually available elements in array
  137. * @status - FW status registers
  138. */
  139. struct mei_fw_status {
  140. int count;
  141. u32 status[MEI_FW_STATUS_MAX];
  142. };
  143. /**
  144. * struct mei_me_client - representation of me (fw) client
  145. *
  146. * @props - client properties
  147. * @client_id - me client id
  148. * @mei_flow_ctrl_creds - flow control credits
  149. */
  150. struct mei_me_client {
  151. struct mei_client_properties props;
  152. u8 client_id;
  153. u8 mei_flow_ctrl_creds;
  154. };
  155. struct mei_cl;
  156. /**
  157. * struct mei_cl_cb - file operation callback structure
  158. *
  159. * @cl - file client who is running this operation
  160. * @fop_type - file operation type
  161. */
  162. struct mei_cl_cb {
  163. struct list_head list;
  164. struct mei_cl *cl;
  165. enum mei_cb_file_ops fop_type;
  166. struct mei_msg_data request_buffer;
  167. struct mei_msg_data response_buffer;
  168. unsigned long buf_idx;
  169. unsigned long read_time;
  170. struct file *file_object;
  171. u32 internal:1;
  172. };
  173. /* MEI client instance carried as file->private_data*/
  174. struct mei_cl {
  175. struct list_head link;
  176. struct mei_device *dev;
  177. enum file_state state;
  178. wait_queue_head_t tx_wait;
  179. wait_queue_head_t rx_wait;
  180. wait_queue_head_t wait;
  181. int status;
  182. /* ID of client connected */
  183. u8 host_client_id;
  184. u8 me_client_id;
  185. u8 mei_flow_ctrl_creds;
  186. u8 timer_count;
  187. enum mei_file_transaction_states reading_state;
  188. enum mei_file_transaction_states writing_state;
  189. struct mei_cl_cb *read_cb;
  190. /* MEI CL bus data */
  191. struct mei_cl_device *device;
  192. struct list_head device_link;
  193. uuid_le device_uuid;
  194. };
  195. /** struct mei_hw_ops
  196. *
  197. * @fw_status - read FW status from PCI config space
  198. * @host_is_ready - query for host readiness
  199. * @hw_is_ready - query if hw is ready
  200. * @hw_reset - reset hw
  201. * @hw_start - start hw after reset
  202. * @hw_config - configure hw
  203. * @pg_state - power gating state of the device
  204. * @pg_is_enabled - is power gating enabled
  205. * @intr_clear - clear pending interrupts
  206. * @intr_enable - enable interrupts
  207. * @intr_disable - disable interrupts
  208. * @hbuf_free_slots - query for write buffer empty slots
  209. * @hbuf_is_ready - query if write buffer is empty
  210. * @hbuf_max_len - query for write buffer max len
  211. * @write - write a message to FW
  212. * @rdbuf_full_slots - query how many slots are filled
  213. * @read_hdr - get first 4 bytes (header)
  214. * @read - read a buffer from the FW
  215. */
  216. struct mei_hw_ops {
  217. int (*fw_status)(struct mei_device *dev,
  218. struct mei_fw_status *fw_status);
  219. bool (*host_is_ready)(struct mei_device *dev);
  220. bool (*hw_is_ready)(struct mei_device *dev);
  221. int (*hw_reset)(struct mei_device *dev, bool enable);
  222. int (*hw_start)(struct mei_device *dev);
  223. void (*hw_config)(struct mei_device *dev);
  224. enum mei_pg_state (*pg_state)(struct mei_device *dev);
  225. bool (*pg_is_enabled)(struct mei_device *dev);
  226. void (*intr_clear)(struct mei_device *dev);
  227. void (*intr_enable)(struct mei_device *dev);
  228. void (*intr_disable)(struct mei_device *dev);
  229. int (*hbuf_free_slots)(struct mei_device *dev);
  230. bool (*hbuf_is_ready)(struct mei_device *dev);
  231. size_t (*hbuf_max_len)(const struct mei_device *dev);
  232. int (*write)(struct mei_device *dev,
  233. struct mei_msg_hdr *hdr,
  234. unsigned char *buf);
  235. int (*rdbuf_full_slots)(struct mei_device *dev);
  236. u32 (*read_hdr)(const struct mei_device *dev);
  237. int (*read)(struct mei_device *dev,
  238. unsigned char *buf, unsigned long len);
  239. };
  240. /* MEI bus API*/
  241. /**
  242. * struct mei_cl_ops - MEI CL device ops
  243. * This structure allows ME host clients to implement technology
  244. * specific operations.
  245. *
  246. * @enable: Enable an MEI CL device. Some devices require specific
  247. * HECI commands to initialize completely.
  248. * @disable: Disable an MEI CL device.
  249. * @send: Tx hook for the device. This allows ME host clients to trap
  250. * the device driver buffers before actually physically
  251. * pushing it to the ME.
  252. * @recv: Rx hook for the device. This allows ME host clients to trap the
  253. * ME buffers before forwarding them to the device driver.
  254. */
  255. struct mei_cl_ops {
  256. int (*enable)(struct mei_cl_device *device);
  257. int (*disable)(struct mei_cl_device *device);
  258. int (*send)(struct mei_cl_device *device, u8 *buf, size_t length);
  259. int (*recv)(struct mei_cl_device *device, u8 *buf, size_t length);
  260. };
  261. struct mei_cl_device *mei_cl_add_device(struct mei_device *dev,
  262. uuid_le uuid, char *name,
  263. struct mei_cl_ops *ops);
  264. void mei_cl_remove_device(struct mei_cl_device *device);
  265. int __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length);
  266. int __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length);
  267. int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length);
  268. void mei_cl_bus_rx_event(struct mei_cl *cl);
  269. void mei_cl_bus_remove_devices(struct mei_device *dev);
  270. int mei_cl_bus_init(void);
  271. void mei_cl_bus_exit(void);
  272. /**
  273. * struct mei_cl_device - MEI device handle
  274. * An mei_cl_device pointer is returned from mei_add_device()
  275. * and links MEI bus clients to their actual ME host client pointer.
  276. * Drivers for MEI devices will get an mei_cl_device pointer
  277. * when being probed and shall use it for doing ME bus I/O.
  278. *
  279. * @dev: linux driver model device pointer
  280. * @uuid: me client uuid
  281. * @cl: mei client
  282. * @ops: ME transport ops
  283. * @event_cb: Drivers register this callback to get asynchronous ME
  284. * events (e.g. Rx buffer pending) notifications.
  285. * @events: Events bitmask sent to the driver.
  286. * @priv_data: client private data
  287. */
  288. struct mei_cl_device {
  289. struct device dev;
  290. struct mei_cl *cl;
  291. const struct mei_cl_ops *ops;
  292. struct work_struct event_work;
  293. mei_cl_event_cb_t event_cb;
  294. void *event_context;
  295. unsigned long events;
  296. void *priv_data;
  297. };
  298. /**
  299. * enum mei_pg_event - power gating transition events
  300. *
  301. * @MEI_PG_EVENT_IDLE: the driver is not in power gating transition
  302. * @MEI_PG_EVENT_WAIT: the driver is waiting for a pg event to complete
  303. * @MEI_PG_EVENT_RECEIVED: the driver received pg event
  304. */
  305. enum mei_pg_event {
  306. MEI_PG_EVENT_IDLE,
  307. MEI_PG_EVENT_WAIT,
  308. MEI_PG_EVENT_RECEIVED,
  309. };
  310. /**
  311. * enum mei_pg_state - device internal power gating state
  312. *
  313. * @MEI_PG_OFF: device is not power gated - it is active
  314. * @MEI_PG_ON: device is power gated - it is in lower power state
  315. */
  316. enum mei_pg_state {
  317. MEI_PG_OFF = 0,
  318. MEI_PG_ON = 1,
  319. };
  320. /*
  321. * mei_cfg
  322. *
  323. * @fw_status - FW status
  324. * @quirk_probe - device exclusion quirk
  325. */
  326. struct mei_cfg {
  327. const struct mei_fw_status fw_status;
  328. bool (*quirk_probe)(struct pci_dev *pdev);
  329. };
  330. #define MEI_PCI_DEVICE(dev, cfg) \
  331. .vendor = PCI_VENDOR_ID_INTEL, .device = (dev), \
  332. .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, \
  333. .driver_data = (kernel_ulong_t)&(cfg)
  334. /**
  335. * struct mei_device - MEI private device struct
  336. * @reset_count - limits the number of consecutive resets
  337. * @hbm_state - state of host bus message protocol
  338. * @pg_event - power gating event
  339. * @mem_addr - mem mapped base register address
  340. * @hbuf_depth - depth of hardware host/write buffer is slots
  341. * @hbuf_is_ready - query if the host host/write buffer is ready
  342. * @wr_msg - the buffer for hbm control messages
  343. * @cfg - per device generation config and ops
  344. */
  345. struct mei_device {
  346. struct pci_dev *pdev; /* pointer to pci device struct */
  347. /*
  348. * lists of queues
  349. */
  350. /* array of pointers to aio lists */
  351. struct mei_cl_cb read_list; /* driver read queue */
  352. struct mei_cl_cb write_list; /* driver write queue */
  353. struct mei_cl_cb write_waiting_list; /* write waiting queue */
  354. struct mei_cl_cb ctrl_wr_list; /* managed write IOCTL list */
  355. struct mei_cl_cb ctrl_rd_list; /* managed read IOCTL list */
  356. /*
  357. * list of files
  358. */
  359. struct list_head file_list;
  360. long open_handle_count;
  361. /*
  362. * lock for the device
  363. */
  364. struct mutex device_lock; /* device lock */
  365. struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */
  366. bool recvd_hw_ready;
  367. /*
  368. * waiting queue for receive message from FW
  369. */
  370. wait_queue_head_t wait_hw_ready;
  371. wait_queue_head_t wait_pg;
  372. wait_queue_head_t wait_recvd_msg;
  373. wait_queue_head_t wait_stop_wd;
  374. /*
  375. * mei device states
  376. */
  377. unsigned long reset_count;
  378. enum mei_dev_state dev_state;
  379. enum mei_hbm_state hbm_state;
  380. u16 init_clients_timer;
  381. /*
  382. * Power Gating support
  383. */
  384. enum mei_pg_event pg_event;
  385. #ifdef CONFIG_PM_RUNTIME
  386. struct dev_pm_domain pg_domain;
  387. #endif /* CONFIG_PM_RUNTIME */
  388. unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */
  389. u32 rd_msg_hdr;
  390. /* write buffer */
  391. u8 hbuf_depth;
  392. bool hbuf_is_ready;
  393. /* used for control messages */
  394. struct {
  395. struct mei_msg_hdr hdr;
  396. unsigned char data[128];
  397. } wr_msg;
  398. struct hbm_version version;
  399. struct mei_me_client *me_clients; /* Note: memory has to be allocated */
  400. DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
  401. DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
  402. unsigned long me_clients_num;
  403. unsigned long me_client_presentation_num;
  404. unsigned long me_client_index;
  405. struct mei_cl wd_cl;
  406. enum mei_wd_states wd_state;
  407. bool wd_pending;
  408. u16 wd_timeout;
  409. unsigned char wd_data[MEI_WD_START_MSG_SIZE];
  410. /* amthif list for cmd waiting */
  411. struct mei_cl_cb amthif_cmd_list;
  412. /* driver managed amthif list for reading completed amthif cmd data */
  413. struct mei_cl_cb amthif_rd_complete_list;
  414. struct file *iamthif_file_object;
  415. struct mei_cl iamthif_cl;
  416. struct mei_cl_cb *iamthif_current_cb;
  417. long iamthif_open_count;
  418. int iamthif_mtu;
  419. unsigned long iamthif_timer;
  420. u32 iamthif_stall_timer;
  421. unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
  422. u32 iamthif_msg_buf_size;
  423. u32 iamthif_msg_buf_index;
  424. enum iamthif_states iamthif_state;
  425. bool iamthif_flow_control_pending;
  426. bool iamthif_ioctl;
  427. bool iamthif_canceled;
  428. struct work_struct init_work;
  429. struct work_struct reset_work;
  430. /* List of bus devices */
  431. struct list_head device_list;
  432. #if IS_ENABLED(CONFIG_DEBUG_FS)
  433. struct dentry *dbgfs_dir;
  434. #endif /* CONFIG_DEBUG_FS */
  435. const struct mei_hw_ops *ops;
  436. const struct mei_cfg *cfg;
  437. char hw[0] __aligned(sizeof(void *));
  438. };
  439. static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
  440. {
  441. return msecs_to_jiffies(sec * MSEC_PER_SEC);
  442. }
  443. /**
  444. * mei_data2slots - get slots - number of (dwords) from a message length
  445. * + size of the mei header
  446. * @length - size of the messages in bytes
  447. * returns - number of slots
  448. */
  449. static inline u32 mei_data2slots(size_t length)
  450. {
  451. return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4);
  452. }
  453. /**
  454. * mei_slots2data- get data in slots - bytes from slots
  455. * @slots - number of available slots
  456. * returns - number of bytes in slots
  457. */
  458. static inline u32 mei_slots2data(int slots)
  459. {
  460. return slots * 4;
  461. }
  462. /*
  463. * mei init function prototypes
  464. */
  465. void mei_device_init(struct mei_device *dev, const struct mei_cfg *cfg);
  466. int mei_reset(struct mei_device *dev);
  467. int mei_start(struct mei_device *dev);
  468. int mei_restart(struct mei_device *dev);
  469. void mei_stop(struct mei_device *dev);
  470. void mei_cancel_work(struct mei_device *dev);
  471. /*
  472. * MEI interrupt functions prototype
  473. */
  474. void mei_timer(struct work_struct *work);
  475. int mei_irq_read_handler(struct mei_device *dev,
  476. struct mei_cl_cb *cmpl_list, s32 *slots);
  477. int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list);
  478. void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list);
  479. /*
  480. * AMTHIF - AMT Host Interface Functions
  481. */
  482. void mei_amthif_reset_params(struct mei_device *dev);
  483. int mei_amthif_host_init(struct mei_device *dev);
  484. int mei_amthif_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
  485. int mei_amthif_read(struct mei_device *dev, struct file *file,
  486. char __user *ubuf, size_t length, loff_t *offset);
  487. unsigned int mei_amthif_poll(struct mei_device *dev,
  488. struct file *file, poll_table *wait);
  489. int mei_amthif_release(struct mei_device *dev, struct file *file);
  490. struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev,
  491. struct file *file);
  492. void mei_amthif_run_next_cmd(struct mei_device *dev);
  493. int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb,
  494. struct mei_cl_cb *cmpl_list);
  495. void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb);
  496. int mei_amthif_irq_read_msg(struct mei_device *dev,
  497. struct mei_msg_hdr *mei_hdr,
  498. struct mei_cl_cb *complete_list);
  499. int mei_amthif_irq_read(struct mei_device *dev, s32 *slots);
  500. /*
  501. * NFC functions
  502. */
  503. int mei_nfc_host_init(struct mei_device *dev);
  504. void mei_nfc_host_exit(struct mei_device *dev);
  505. /*
  506. * NFC Client UUID
  507. */
  508. extern const uuid_le mei_nfc_guid;
  509. int mei_wd_send(struct mei_device *dev);
  510. int mei_wd_stop(struct mei_device *dev);
  511. int mei_wd_host_init(struct mei_device *dev);
  512. /*
  513. * mei_watchdog_register - Registering watchdog interface
  514. * once we got connection to the WD Client
  515. * @dev - mei device
  516. */
  517. int mei_watchdog_register(struct mei_device *dev);
  518. /*
  519. * mei_watchdog_unregister - Unregistering watchdog interface
  520. * @dev - mei device
  521. */
  522. void mei_watchdog_unregister(struct mei_device *dev);
  523. /*
  524. * Register Access Function
  525. */
  526. static inline void mei_hw_config(struct mei_device *dev)
  527. {
  528. dev->ops->hw_config(dev);
  529. }
  530. static inline enum mei_pg_state mei_pg_state(struct mei_device *dev)
  531. {
  532. return dev->ops->pg_state(dev);
  533. }
  534. static inline bool mei_pg_is_enabled(struct mei_device *dev)
  535. {
  536. return dev->ops->pg_is_enabled(dev);
  537. }
  538. static inline int mei_hw_reset(struct mei_device *dev, bool enable)
  539. {
  540. return dev->ops->hw_reset(dev, enable);
  541. }
  542. static inline int mei_hw_start(struct mei_device *dev)
  543. {
  544. return dev->ops->hw_start(dev);
  545. }
  546. static inline void mei_clear_interrupts(struct mei_device *dev)
  547. {
  548. dev->ops->intr_clear(dev);
  549. }
  550. static inline void mei_enable_interrupts(struct mei_device *dev)
  551. {
  552. dev->ops->intr_enable(dev);
  553. }
  554. static inline void mei_disable_interrupts(struct mei_device *dev)
  555. {
  556. dev->ops->intr_disable(dev);
  557. }
  558. static inline bool mei_host_is_ready(struct mei_device *dev)
  559. {
  560. return dev->ops->host_is_ready(dev);
  561. }
  562. static inline bool mei_hw_is_ready(struct mei_device *dev)
  563. {
  564. return dev->ops->hw_is_ready(dev);
  565. }
  566. static inline bool mei_hbuf_is_ready(struct mei_device *dev)
  567. {
  568. return dev->ops->hbuf_is_ready(dev);
  569. }
  570. static inline int mei_hbuf_empty_slots(struct mei_device *dev)
  571. {
  572. return dev->ops->hbuf_free_slots(dev);
  573. }
  574. static inline size_t mei_hbuf_max_len(const struct mei_device *dev)
  575. {
  576. return dev->ops->hbuf_max_len(dev);
  577. }
  578. static inline int mei_write_message(struct mei_device *dev,
  579. struct mei_msg_hdr *hdr,
  580. unsigned char *buf)
  581. {
  582. return dev->ops->write(dev, hdr, buf);
  583. }
  584. static inline u32 mei_read_hdr(const struct mei_device *dev)
  585. {
  586. return dev->ops->read_hdr(dev);
  587. }
  588. static inline void mei_read_slots(struct mei_device *dev,
  589. unsigned char *buf, unsigned long len)
  590. {
  591. dev->ops->read(dev, buf, len);
  592. }
  593. static inline int mei_count_full_read_slots(struct mei_device *dev)
  594. {
  595. return dev->ops->rdbuf_full_slots(dev);
  596. }
  597. int mei_fw_status(struct mei_device *dev, struct mei_fw_status *fw_status);
  598. #define FW_STS_FMT "%08X %08X"
  599. #define FW_STS_PRM(fw_status) \
  600. (fw_status).count > 0 ? (fw_status).status[0] : 0xDEADBEEF, \
  601. (fw_status).count > 1 ? (fw_status).status[1] : 0xDEADBEEF
  602. bool mei_hbuf_acquire(struct mei_device *dev);
  603. bool mei_write_is_idle(struct mei_device *dev);
  604. #if IS_ENABLED(CONFIG_DEBUG_FS)
  605. int mei_dbgfs_register(struct mei_device *dev, const char *name);
  606. void mei_dbgfs_deregister(struct mei_device *dev);
  607. #else
  608. static inline int mei_dbgfs_register(struct mei_device *dev, const char *name)
  609. {
  610. return 0;
  611. }
  612. static inline void mei_dbgfs_deregister(struct mei_device *dev) {}
  613. #endif /* CONFIG_DEBUG_FS */
  614. int mei_register(struct mei_device *dev);
  615. void mei_deregister(struct mei_device *dev);
  616. #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d internal=%1d comp=%1d"
  617. #define MEI_HDR_PRM(hdr) \
  618. (hdr)->host_addr, (hdr)->me_addr, \
  619. (hdr)->length, (hdr)->internal, (hdr)->msg_complete
  620. #endif