mei_dev.h 22 KB

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