mei_dev.h 24 KB

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