mei_dev.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2003-2022, Intel Corporation. All rights reserved.
  4. * Intel Management Engine Interface (Intel MEI) Linux driver
  5. */
  6. #ifndef _MEI_DEV_H_
  7. #define _MEI_DEV_H_
  8. #include <linux/types.h>
  9. #include <linux/cdev.h>
  10. #include <linux/poll.h>
  11. #include <linux/mei.h>
  12. #include <linux/mei_cl_bus.h>
  13. #include "hw.h"
  14. #include "hbm.h"
  15. #define MEI_SLOT_SIZE sizeof(u32)
  16. #define MEI_RD_MSG_BUF_SIZE (128 * MEI_SLOT_SIZE)
  17. /*
  18. * Number of Maximum MEI Clients
  19. */
  20. #define MEI_CLIENTS_MAX 256
  21. /*
  22. * maximum number of consecutive resets
  23. */
  24. #define MEI_MAX_CONSEC_RESET 3
  25. /*
  26. * Number of File descriptors/handles
  27. * that can be opened to the driver.
  28. *
  29. * Limit to 255: 256 Total Clients
  30. * minus internal client for MEI Bus Messages
  31. */
  32. #define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 1)
  33. /* File state */
  34. enum file_state {
  35. MEI_FILE_UNINITIALIZED = 0,
  36. MEI_FILE_INITIALIZING,
  37. MEI_FILE_CONNECTING,
  38. MEI_FILE_CONNECTED,
  39. MEI_FILE_DISCONNECTING,
  40. MEI_FILE_DISCONNECT_REPLY,
  41. MEI_FILE_DISCONNECT_REQUIRED,
  42. MEI_FILE_DISCONNECTED,
  43. };
  44. /* MEI device states */
  45. enum mei_dev_state {
  46. MEI_DEV_INITIALIZING = 0,
  47. MEI_DEV_INIT_CLIENTS,
  48. MEI_DEV_ENABLED,
  49. MEI_DEV_RESETTING,
  50. MEI_DEV_DISABLED,
  51. MEI_DEV_POWERING_DOWN,
  52. MEI_DEV_POWER_DOWN,
  53. MEI_DEV_POWER_UP
  54. };
  55. /**
  56. * enum mei_dev_pxp_mode - MEI PXP mode state
  57. *
  58. * @MEI_DEV_PXP_DEFAULT: PCH based device, no initailization required
  59. * @MEI_DEV_PXP_INIT: device requires initialization, send setup message to firmware
  60. * @MEI_DEV_PXP_SETUP: device is in setup stage, waiting for firmware repsonse
  61. * @MEI_DEV_PXP_READY: device initialized
  62. */
  63. enum mei_dev_pxp_mode {
  64. MEI_DEV_PXP_DEFAULT = 0,
  65. MEI_DEV_PXP_INIT = 1,
  66. MEI_DEV_PXP_SETUP = 2,
  67. MEI_DEV_PXP_READY = 3,
  68. };
  69. const char *mei_dev_state_str(int state);
  70. enum mei_file_transaction_states {
  71. MEI_IDLE,
  72. MEI_WRITING,
  73. MEI_WRITE_COMPLETE,
  74. };
  75. /**
  76. * enum mei_cb_file_ops - file operation associated with the callback
  77. * @MEI_FOP_READ: read
  78. * @MEI_FOP_WRITE: write
  79. * @MEI_FOP_CONNECT: connect
  80. * @MEI_FOP_DISCONNECT: disconnect
  81. * @MEI_FOP_DISCONNECT_RSP: disconnect response
  82. * @MEI_FOP_NOTIFY_START: start notification
  83. * @MEI_FOP_NOTIFY_STOP: stop notification
  84. * @MEI_FOP_DMA_MAP: request client dma map
  85. * @MEI_FOP_DMA_UNMAP: request client dma unmap
  86. */
  87. enum mei_cb_file_ops {
  88. MEI_FOP_READ = 0,
  89. MEI_FOP_WRITE,
  90. MEI_FOP_CONNECT,
  91. MEI_FOP_DISCONNECT,
  92. MEI_FOP_DISCONNECT_RSP,
  93. MEI_FOP_NOTIFY_START,
  94. MEI_FOP_NOTIFY_STOP,
  95. MEI_FOP_DMA_MAP,
  96. MEI_FOP_DMA_UNMAP,
  97. };
  98. /**
  99. * enum mei_cl_io_mode - io mode between driver and fw
  100. *
  101. * @MEI_CL_IO_TX_BLOCKING: send is blocking
  102. * @MEI_CL_IO_TX_INTERNAL: internal communication between driver and FW
  103. *
  104. * @MEI_CL_IO_RX_NONBLOCK: recv is non-blocking
  105. */
  106. enum mei_cl_io_mode {
  107. MEI_CL_IO_TX_BLOCKING = BIT(0),
  108. MEI_CL_IO_TX_INTERNAL = BIT(1),
  109. MEI_CL_IO_RX_NONBLOCK = BIT(2),
  110. };
  111. /*
  112. * Intel MEI message data struct
  113. */
  114. struct mei_msg_data {
  115. size_t size;
  116. unsigned char *data;
  117. };
  118. struct mei_dma_data {
  119. u8 buffer_id;
  120. void *vaddr;
  121. dma_addr_t daddr;
  122. size_t size;
  123. };
  124. /**
  125. * struct mei_dma_dscr - dma address descriptor
  126. *
  127. * @vaddr: dma buffer virtual address
  128. * @daddr: dma buffer physical address
  129. * @size : dma buffer size
  130. */
  131. struct mei_dma_dscr {
  132. void *vaddr;
  133. dma_addr_t daddr;
  134. size_t size;
  135. };
  136. /* Maximum number of processed FW status registers */
  137. #define MEI_FW_STATUS_MAX 6
  138. /* Minimal buffer for FW status string (8 bytes in dw + space or '\0') */
  139. #define MEI_FW_STATUS_STR_SZ (MEI_FW_STATUS_MAX * (8 + 1))
  140. /*
  141. * struct mei_fw_status - storage of FW status data
  142. *
  143. * @count: number of actually available elements in array
  144. * @status: FW status registers
  145. */
  146. struct mei_fw_status {
  147. int count;
  148. u32 status[MEI_FW_STATUS_MAX];
  149. };
  150. /**
  151. * struct mei_me_client - representation of me (fw) client
  152. *
  153. * @list: link in me client list
  154. * @refcnt: struct reference count
  155. * @props: client properties
  156. * @client_id: me client id
  157. * @tx_flow_ctrl_creds: flow control credits
  158. * @connect_count: number connections to this client
  159. * @bus_added: added to bus
  160. */
  161. struct mei_me_client {
  162. struct list_head list;
  163. struct kref refcnt;
  164. struct mei_client_properties props;
  165. u8 client_id;
  166. u8 tx_flow_ctrl_creds;
  167. u8 connect_count;
  168. u8 bus_added;
  169. };
  170. struct mei_cl;
  171. /**
  172. * struct mei_cl_cb - file operation callback structure
  173. *
  174. * @list: link in callback queue
  175. * @cl: file client who is running this operation
  176. * @fop_type: file operation type
  177. * @buf: buffer for data associated with the callback
  178. * @buf_idx: last read index
  179. * @vtag: virtual tag
  180. * @fp: pointer to file structure
  181. * @status: io status of the cb
  182. * @internal: communication between driver and FW flag
  183. * @blocking: transmission blocking mode
  184. */
  185. struct mei_cl_cb {
  186. struct list_head list;
  187. struct mei_cl *cl;
  188. enum mei_cb_file_ops fop_type;
  189. struct mei_msg_data buf;
  190. size_t buf_idx;
  191. u8 vtag;
  192. const struct file *fp;
  193. int status;
  194. u32 internal:1;
  195. u32 blocking:1;
  196. };
  197. /**
  198. * struct mei_cl_vtag - file pointer to vtag mapping structure
  199. *
  200. * @list: link in map queue
  201. * @fp: file pointer
  202. * @vtag: corresponding vtag
  203. * @pending_read: the read is pending on this file
  204. */
  205. struct mei_cl_vtag {
  206. struct list_head list;
  207. const struct file *fp;
  208. u8 vtag;
  209. u8 pending_read:1;
  210. };
  211. /**
  212. * struct mei_cl - me client host representation
  213. * carried in file->private_data
  214. *
  215. * @link: link in the clients list
  216. * @dev: mei parent device
  217. * @state: file operation state
  218. * @tx_wait: wait queue for tx completion
  219. * @rx_wait: wait queue for rx completion
  220. * @wait: wait queue for management operation
  221. * @ev_wait: notification wait queue
  222. * @ev_async: event async notification
  223. * @status: connection status
  224. * @me_cl: fw client connected
  225. * @fp: file associated with client
  226. * @host_client_id: host id
  227. * @vtag_map: vtag map
  228. * @tx_flow_ctrl_creds: transmit flow credentials
  229. * @rx_flow_ctrl_creds: receive flow credentials
  230. * @timer_count: watchdog timer for operation completion
  231. * @notify_en: notification - enabled/disabled
  232. * @notify_ev: pending notification event
  233. * @tx_cb_queued: number of tx callbacks in queue
  234. * @writing_state: state of the tx
  235. * @rd_pending: pending read credits
  236. * @rd_completed_lock: protects rd_completed queue
  237. * @rd_completed: completed read
  238. * @dma: dma settings
  239. * @dma_mapped: dma buffer is currently mapped.
  240. *
  241. * @cldev: device on the mei client bus
  242. */
  243. struct mei_cl {
  244. struct list_head link;
  245. struct mei_device *dev;
  246. enum file_state state;
  247. wait_queue_head_t tx_wait;
  248. wait_queue_head_t rx_wait;
  249. wait_queue_head_t wait;
  250. wait_queue_head_t ev_wait;
  251. struct fasync_struct *ev_async;
  252. int status;
  253. struct mei_me_client *me_cl;
  254. const struct file *fp;
  255. u8 host_client_id;
  256. struct list_head vtag_map;
  257. u8 tx_flow_ctrl_creds;
  258. u8 rx_flow_ctrl_creds;
  259. u8 timer_count;
  260. u8 notify_en;
  261. u8 notify_ev;
  262. u8 tx_cb_queued;
  263. enum mei_file_transaction_states writing_state;
  264. struct list_head rd_pending;
  265. spinlock_t rd_completed_lock; /* protects rd_completed queue */
  266. struct list_head rd_completed;
  267. struct mei_dma_data dma;
  268. u8 dma_mapped;
  269. struct mei_cl_device *cldev;
  270. };
  271. #define MEI_TX_QUEUE_LIMIT_DEFAULT 50
  272. #define MEI_TX_QUEUE_LIMIT_MAX 255
  273. #define MEI_TX_QUEUE_LIMIT_MIN 30
  274. /**
  275. * struct mei_hw_ops - hw specific ops
  276. *
  277. * @host_is_ready : query for host readiness
  278. *
  279. * @hw_is_ready : query if hw is ready
  280. * @hw_reset : reset hw
  281. * @hw_start : start hw after reset
  282. * @hw_config : configure hw
  283. *
  284. * @fw_status : get fw status registers
  285. * @trc_status : get trc status register
  286. * @pg_state : power gating state of the device
  287. * @pg_in_transition : is device now in pg transition
  288. * @pg_is_enabled : is power gating enabled
  289. *
  290. * @intr_clear : clear pending interrupts
  291. * @intr_enable : enable interrupts
  292. * @intr_disable : disable interrupts
  293. * @synchronize_irq : synchronize irqs
  294. *
  295. * @hbuf_free_slots : query for write buffer empty slots
  296. * @hbuf_is_ready : query if write buffer is empty
  297. * @hbuf_depth : query for write buffer depth
  298. *
  299. * @write : write a message to FW
  300. *
  301. * @rdbuf_full_slots : query how many slots are filled
  302. *
  303. * @read_hdr : get first 4 bytes (header)
  304. * @read : read a buffer from the FW
  305. */
  306. struct mei_hw_ops {
  307. bool (*host_is_ready)(struct mei_device *dev);
  308. bool (*hw_is_ready)(struct mei_device *dev);
  309. int (*hw_reset)(struct mei_device *dev, bool enable);
  310. int (*hw_start)(struct mei_device *dev);
  311. int (*hw_config)(struct mei_device *dev);
  312. int (*fw_status)(struct mei_device *dev, struct mei_fw_status *fw_sts);
  313. int (*trc_status)(struct mei_device *dev, u32 *trc);
  314. enum mei_pg_state (*pg_state)(struct mei_device *dev);
  315. bool (*pg_in_transition)(struct mei_device *dev);
  316. bool (*pg_is_enabled)(struct mei_device *dev);
  317. void (*intr_clear)(struct mei_device *dev);
  318. void (*intr_enable)(struct mei_device *dev);
  319. void (*intr_disable)(struct mei_device *dev);
  320. void (*synchronize_irq)(struct mei_device *dev);
  321. int (*hbuf_free_slots)(struct mei_device *dev);
  322. bool (*hbuf_is_ready)(struct mei_device *dev);
  323. u32 (*hbuf_depth)(const struct mei_device *dev);
  324. int (*write)(struct mei_device *dev,
  325. const void *hdr, size_t hdr_len,
  326. const void *data, size_t data_len);
  327. int (*rdbuf_full_slots)(struct mei_device *dev);
  328. u32 (*read_hdr)(const struct mei_device *dev);
  329. int (*read)(struct mei_device *dev,
  330. unsigned char *buf, unsigned long len);
  331. };
  332. /* MEI bus API*/
  333. void mei_cl_bus_rescan_work(struct work_struct *work);
  334. void mei_cl_bus_dev_fixup(struct mei_cl_device *dev);
  335. ssize_t __mei_cl_send(struct mei_cl *cl, const u8 *buf, size_t length, u8 vtag,
  336. unsigned int mode);
  337. ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length, u8 *vtag,
  338. unsigned int mode, unsigned long timeout);
  339. bool mei_cl_bus_rx_event(struct mei_cl *cl);
  340. bool mei_cl_bus_notify_event(struct mei_cl *cl);
  341. void mei_cl_bus_remove_devices(struct mei_device *bus);
  342. int mei_cl_bus_init(void);
  343. void mei_cl_bus_exit(void);
  344. /**
  345. * enum mei_pg_event - power gating transition events
  346. *
  347. * @MEI_PG_EVENT_IDLE: the driver is not in power gating transition
  348. * @MEI_PG_EVENT_WAIT: the driver is waiting for a pg event to complete
  349. * @MEI_PG_EVENT_RECEIVED: the driver received pg event
  350. * @MEI_PG_EVENT_INTR_WAIT: the driver is waiting for a pg event interrupt
  351. * @MEI_PG_EVENT_INTR_RECEIVED: the driver received pg event interrupt
  352. */
  353. enum mei_pg_event {
  354. MEI_PG_EVENT_IDLE,
  355. MEI_PG_EVENT_WAIT,
  356. MEI_PG_EVENT_RECEIVED,
  357. MEI_PG_EVENT_INTR_WAIT,
  358. MEI_PG_EVENT_INTR_RECEIVED,
  359. };
  360. /**
  361. * enum mei_pg_state - device internal power gating state
  362. *
  363. * @MEI_PG_OFF: device is not power gated - it is active
  364. * @MEI_PG_ON: device is power gated - it is in lower power state
  365. */
  366. enum mei_pg_state {
  367. MEI_PG_OFF = 0,
  368. MEI_PG_ON = 1,
  369. };
  370. const char *mei_pg_state_str(enum mei_pg_state state);
  371. /**
  372. * struct mei_fw_version - MEI FW version struct
  373. *
  374. * @platform: platform identifier
  375. * @major: major version field
  376. * @minor: minor version field
  377. * @buildno: build number version field
  378. * @hotfix: hotfix number version field
  379. */
  380. struct mei_fw_version {
  381. u8 platform;
  382. u8 major;
  383. u16 minor;
  384. u16 buildno;
  385. u16 hotfix;
  386. };
  387. #define MEI_MAX_FW_VER_BLOCKS 3
  388. struct mei_dev_timeouts {
  389. unsigned long hw_ready; /* Timeout on ready message, in jiffies */
  390. int connect; /* HPS: at least 2 seconds, in seconds */
  391. unsigned long cl_connect; /* HPS: Client Connect Timeout, in jiffies */
  392. int client_init; /* HPS: Clients Enumeration Timeout, in seconds */
  393. unsigned long pgi; /* PG Isolation time response, in jiffies */
  394. unsigned int d0i3; /* D0i3 set/unset max response time, in jiffies */
  395. unsigned long hbm; /* HBM operation timeout, in jiffies */
  396. unsigned long mkhi_recv; /* receive timeout, in jiffies */
  397. };
  398. /**
  399. * struct mei_device - MEI private device struct
  400. *
  401. * @dev : device on a bus
  402. * @cdev : character device
  403. * @minor : minor number allocated for device
  404. *
  405. * @write_list : write pending list
  406. * @write_waiting_list : write completion list
  407. * @ctrl_wr_list : pending control write list
  408. * @ctrl_rd_list : pending control read list
  409. * @tx_queue_limit: tx queues per client linit
  410. *
  411. * @file_list : list of opened handles
  412. * @open_handle_count: number of opened handles
  413. *
  414. * @device_lock : big device lock
  415. * @timer_work : MEI timer delayed work (timeouts)
  416. *
  417. * @recvd_hw_ready : hw ready message received flag
  418. *
  419. * @wait_hw_ready : wait queue for receive HW ready message form FW
  420. * @wait_pg : wait queue for receive PG message from FW
  421. * @wait_hbm_start : wait queue for receive HBM start message from FW
  422. *
  423. * @reset_count : number of consecutive resets
  424. * @dev_state : device state
  425. * @hbm_state : state of host bus message protocol
  426. * @pxp_mode : PXP device mode
  427. * @init_clients_timer : HBM init handshake timeout
  428. *
  429. * @pg_event : power gating event
  430. * @pg_domain : runtime PM domain
  431. *
  432. * @rd_msg_buf : control messages buffer
  433. * @rd_msg_hdr : read message header storage
  434. * @rd_msg_hdr_count : how many dwords were already read from header
  435. *
  436. * @hbuf_is_ready : query if the host host/write buffer is ready
  437. * @dr_dscr: DMA ring descriptors: TX, RX, and CTRL
  438. *
  439. * @version : HBM protocol version in use
  440. * @hbm_f_pg_supported : hbm feature pgi protocol
  441. * @hbm_f_dc_supported : hbm feature dynamic clients
  442. * @hbm_f_dot_supported : hbm feature disconnect on timeout
  443. * @hbm_f_ev_supported : hbm feature event notification
  444. * @hbm_f_fa_supported : hbm feature fixed address client
  445. * @hbm_f_ie_supported : hbm feature immediate reply to enum request
  446. * @hbm_f_os_supported : hbm feature support OS ver message
  447. * @hbm_f_dr_supported : hbm feature dma ring supported
  448. * @hbm_f_vt_supported : hbm feature vtag supported
  449. * @hbm_f_cap_supported : hbm feature capabilities message supported
  450. * @hbm_f_cd_supported : hbm feature client dma supported
  451. *
  452. * @fw_ver : FW versions
  453. *
  454. * @fw_f_fw_ver_supported : fw feature: fw version supported
  455. *
  456. * @me_clients_rwsem: rw lock over me_clients list
  457. * @me_clients : list of FW clients
  458. * @me_clients_map : FW clients bit map
  459. * @host_clients_map : host clients id pool
  460. *
  461. * @allow_fixed_address: allow user space to connect a fixed client
  462. * @override_fixed_address: force allow fixed address behavior
  463. *
  464. * @timeouts: actual timeout values
  465. *
  466. * @reset_work : work item for the device reset
  467. * @bus_rescan_work : work item for the bus rescan
  468. *
  469. * @device_list : mei client bus list
  470. * @cl_bus_lock : client bus list lock
  471. *
  472. * @kind : kind of mei device
  473. *
  474. * @dbgfs_dir : debugfs mei root directory
  475. *
  476. * @ops: : hw specific operations
  477. * @hw : hw specific data
  478. */
  479. struct mei_device {
  480. struct device *dev;
  481. struct cdev cdev;
  482. int minor;
  483. struct list_head write_list;
  484. struct list_head write_waiting_list;
  485. struct list_head ctrl_wr_list;
  486. struct list_head ctrl_rd_list;
  487. u8 tx_queue_limit;
  488. struct list_head file_list;
  489. long open_handle_count;
  490. struct mutex device_lock;
  491. struct delayed_work timer_work;
  492. bool recvd_hw_ready;
  493. /*
  494. * waiting queue for receive message from FW
  495. */
  496. wait_queue_head_t wait_hw_ready;
  497. wait_queue_head_t wait_pg;
  498. wait_queue_head_t wait_hbm_start;
  499. /*
  500. * mei device states
  501. */
  502. unsigned long reset_count;
  503. enum mei_dev_state dev_state;
  504. enum mei_hbm_state hbm_state;
  505. enum mei_dev_pxp_mode pxp_mode;
  506. u16 init_clients_timer;
  507. /*
  508. * Power Gating support
  509. */
  510. enum mei_pg_event pg_event;
  511. #ifdef CONFIG_PM
  512. struct dev_pm_domain pg_domain;
  513. #endif /* CONFIG_PM */
  514. unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE];
  515. u32 rd_msg_hdr[MEI_RD_MSG_BUF_SIZE];
  516. int rd_msg_hdr_count;
  517. /* write buffer */
  518. bool hbuf_is_ready;
  519. struct mei_dma_dscr dr_dscr[DMA_DSCR_NUM];
  520. struct hbm_version version;
  521. unsigned int hbm_f_pg_supported:1;
  522. unsigned int hbm_f_dc_supported:1;
  523. unsigned int hbm_f_dot_supported:1;
  524. unsigned int hbm_f_ev_supported:1;
  525. unsigned int hbm_f_fa_supported:1;
  526. unsigned int hbm_f_ie_supported:1;
  527. unsigned int hbm_f_os_supported:1;
  528. unsigned int hbm_f_dr_supported:1;
  529. unsigned int hbm_f_vt_supported:1;
  530. unsigned int hbm_f_cap_supported:1;
  531. unsigned int hbm_f_cd_supported:1;
  532. struct mei_fw_version fw_ver[MEI_MAX_FW_VER_BLOCKS];
  533. unsigned int fw_f_fw_ver_supported:1;
  534. struct rw_semaphore me_clients_rwsem;
  535. struct list_head me_clients;
  536. DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
  537. DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
  538. bool allow_fixed_address;
  539. bool override_fixed_address;
  540. struct mei_dev_timeouts timeouts;
  541. struct work_struct reset_work;
  542. struct work_struct bus_rescan_work;
  543. /* List of bus devices */
  544. struct list_head device_list;
  545. struct mutex cl_bus_lock;
  546. const char *kind;
  547. #if IS_ENABLED(CONFIG_DEBUG_FS)
  548. struct dentry *dbgfs_dir;
  549. #endif /* CONFIG_DEBUG_FS */
  550. const struct mei_hw_ops *ops;
  551. char hw[] __aligned(sizeof(void *));
  552. };
  553. static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
  554. {
  555. return msecs_to_jiffies(sec * MSEC_PER_SEC);
  556. }
  557. /**
  558. * mei_data2slots - get slots number from a message length
  559. *
  560. * @length: size of the messages in bytes
  561. *
  562. * Return: number of slots
  563. */
  564. static inline u32 mei_data2slots(size_t length)
  565. {
  566. return DIV_ROUND_UP(length, MEI_SLOT_SIZE);
  567. }
  568. /**
  569. * mei_hbm2slots - get slots number from a hbm message length
  570. * length + size of the mei message header
  571. *
  572. * @length: size of the messages in bytes
  573. *
  574. * Return: number of slots
  575. */
  576. static inline u32 mei_hbm2slots(size_t length)
  577. {
  578. return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, MEI_SLOT_SIZE);
  579. }
  580. /**
  581. * mei_slots2data - get data in slots - bytes from slots
  582. *
  583. * @slots: number of available slots
  584. *
  585. * Return: number of bytes in slots
  586. */
  587. static inline u32 mei_slots2data(int slots)
  588. {
  589. return slots * MEI_SLOT_SIZE;
  590. }
  591. /*
  592. * mei init function prototypes
  593. */
  594. void mei_device_init(struct mei_device *dev,
  595. struct device *device,
  596. bool slow_fw,
  597. const struct mei_hw_ops *hw_ops);
  598. int mei_reset(struct mei_device *dev);
  599. int mei_start(struct mei_device *dev);
  600. int mei_restart(struct mei_device *dev);
  601. void mei_stop(struct mei_device *dev);
  602. void mei_cancel_work(struct mei_device *dev);
  603. void mei_set_devstate(struct mei_device *dev, enum mei_dev_state state);
  604. int mei_dmam_ring_alloc(struct mei_device *dev);
  605. void mei_dmam_ring_free(struct mei_device *dev);
  606. bool mei_dma_ring_is_allocated(struct mei_device *dev);
  607. void mei_dma_ring_reset(struct mei_device *dev);
  608. void mei_dma_ring_read(struct mei_device *dev, unsigned char *buf, u32 len);
  609. void mei_dma_ring_write(struct mei_device *dev, unsigned char *buf, u32 len);
  610. u32 mei_dma_ring_empty_slots(struct mei_device *dev);
  611. /*
  612. * MEI interrupt functions prototype
  613. */
  614. void mei_timer(struct work_struct *work);
  615. void mei_schedule_stall_timer(struct mei_device *dev);
  616. int mei_irq_read_handler(struct mei_device *dev,
  617. struct list_head *cmpl_list, s32 *slots);
  618. int mei_irq_write_handler(struct mei_device *dev, struct list_head *cmpl_list);
  619. void mei_irq_compl_handler(struct mei_device *dev, struct list_head *cmpl_list);
  620. /*
  621. * Register Access Function
  622. */
  623. static inline int mei_hw_config(struct mei_device *dev)
  624. {
  625. return dev->ops->hw_config(dev);
  626. }
  627. static inline enum mei_pg_state mei_pg_state(struct mei_device *dev)
  628. {
  629. return dev->ops->pg_state(dev);
  630. }
  631. static inline bool mei_pg_in_transition(struct mei_device *dev)
  632. {
  633. return dev->ops->pg_in_transition(dev);
  634. }
  635. static inline bool mei_pg_is_enabled(struct mei_device *dev)
  636. {
  637. return dev->ops->pg_is_enabled(dev);
  638. }
  639. static inline int mei_hw_reset(struct mei_device *dev, bool enable)
  640. {
  641. return dev->ops->hw_reset(dev, enable);
  642. }
  643. static inline int mei_hw_start(struct mei_device *dev)
  644. {
  645. return dev->ops->hw_start(dev);
  646. }
  647. static inline void mei_clear_interrupts(struct mei_device *dev)
  648. {
  649. dev->ops->intr_clear(dev);
  650. }
  651. static inline void mei_enable_interrupts(struct mei_device *dev)
  652. {
  653. dev->ops->intr_enable(dev);
  654. }
  655. static inline void mei_disable_interrupts(struct mei_device *dev)
  656. {
  657. dev->ops->intr_disable(dev);
  658. }
  659. static inline void mei_synchronize_irq(struct mei_device *dev)
  660. {
  661. dev->ops->synchronize_irq(dev);
  662. }
  663. static inline bool mei_host_is_ready(struct mei_device *dev)
  664. {
  665. return dev->ops->host_is_ready(dev);
  666. }
  667. static inline bool mei_hw_is_ready(struct mei_device *dev)
  668. {
  669. return dev->ops->hw_is_ready(dev);
  670. }
  671. static inline bool mei_hbuf_is_ready(struct mei_device *dev)
  672. {
  673. return dev->ops->hbuf_is_ready(dev);
  674. }
  675. static inline int mei_hbuf_empty_slots(struct mei_device *dev)
  676. {
  677. return dev->ops->hbuf_free_slots(dev);
  678. }
  679. static inline u32 mei_hbuf_depth(const struct mei_device *dev)
  680. {
  681. return dev->ops->hbuf_depth(dev);
  682. }
  683. static inline int mei_write_message(struct mei_device *dev,
  684. const void *hdr, size_t hdr_len,
  685. const void *data, size_t data_len)
  686. {
  687. return dev->ops->write(dev, hdr, hdr_len, data, data_len);
  688. }
  689. static inline u32 mei_read_hdr(const struct mei_device *dev)
  690. {
  691. return dev->ops->read_hdr(dev);
  692. }
  693. static inline void mei_read_slots(struct mei_device *dev,
  694. unsigned char *buf, unsigned long len)
  695. {
  696. dev->ops->read(dev, buf, len);
  697. }
  698. static inline int mei_count_full_read_slots(struct mei_device *dev)
  699. {
  700. return dev->ops->rdbuf_full_slots(dev);
  701. }
  702. static inline int mei_trc_status(struct mei_device *dev, u32 *trc)
  703. {
  704. if (dev->ops->trc_status)
  705. return dev->ops->trc_status(dev, trc);
  706. return -EOPNOTSUPP;
  707. }
  708. static inline int mei_fw_status(struct mei_device *dev,
  709. struct mei_fw_status *fw_status)
  710. {
  711. return dev->ops->fw_status(dev, fw_status);
  712. }
  713. bool mei_hbuf_acquire(struct mei_device *dev);
  714. bool mei_write_is_idle(struct mei_device *dev);
  715. #if IS_ENABLED(CONFIG_DEBUG_FS)
  716. void mei_dbgfs_register(struct mei_device *dev, const char *name);
  717. void mei_dbgfs_deregister(struct mei_device *dev);
  718. #else
  719. static inline void mei_dbgfs_register(struct mei_device *dev, const char *name) {}
  720. static inline void mei_dbgfs_deregister(struct mei_device *dev) {}
  721. #endif /* CONFIG_DEBUG_FS */
  722. int mei_register(struct mei_device *dev, struct device *parent);
  723. void mei_deregister(struct mei_device *dev);
  724. #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d dma=%1d ext=%1d internal=%1d comp=%1d"
  725. #define MEI_HDR_PRM(hdr) \
  726. (hdr)->host_addr, (hdr)->me_addr, \
  727. (hdr)->length, (hdr)->dma_ring, (hdr)->extended, \
  728. (hdr)->internal, (hdr)->msg_complete
  729. ssize_t mei_fw_status2str(struct mei_fw_status *fw_sts, char *buf, size_t len);
  730. /**
  731. * mei_fw_status_str - fetch and convert fw status registers to printable string
  732. *
  733. * @dev: the device structure
  734. * @buf: string buffer at minimal size MEI_FW_STATUS_STR_SZ
  735. * @len: buffer len must be >= MEI_FW_STATUS_STR_SZ
  736. *
  737. * Return: number of bytes written or < 0 on failure
  738. */
  739. static inline ssize_t mei_fw_status_str(struct mei_device *dev,
  740. char *buf, size_t len)
  741. {
  742. struct mei_fw_status fw_status;
  743. int ret;
  744. buf[0] = '\0';
  745. ret = mei_fw_status(dev, &fw_status);
  746. if (ret)
  747. return ret;
  748. ret = mei_fw_status2str(&fw_status, buf, MEI_FW_STATUS_STR_SZ);
  749. return ret;
  750. }
  751. #endif