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_UNINITIALIZED = 0,
  51. MEI_DEV_INITIALIZING,
  52. MEI_DEV_INIT_CLIENTS,
  53. MEI_DEV_ENABLED,
  54. MEI_DEV_RESETTING,
  55. MEI_DEV_DISABLED,
  56. MEI_DEV_POWERING_DOWN,
  57. MEI_DEV_POWER_DOWN,
  58. MEI_DEV_POWER_UP
  59. };
  60. /**
  61. * enum mei_dev_pxp_mode - MEI PXP mode state
  62. *
  63. * @MEI_DEV_PXP_DEFAULT: PCH based device, no initialization required
  64. * @MEI_DEV_PXP_INIT: device requires initialization, send setup message to firmware
  65. * @MEI_DEV_PXP_SETUP: device is in setup stage, waiting for firmware response
  66. * @MEI_DEV_PXP_READY: device initialized
  67. */
  68. enum mei_dev_pxp_mode {
  69. MEI_DEV_PXP_DEFAULT = 0,
  70. MEI_DEV_PXP_INIT = 1,
  71. MEI_DEV_PXP_SETUP = 2,
  72. MEI_DEV_PXP_READY = 3,
  73. };
  74. /**
  75. * enum mei_dev_reset_to_pxp - reset to PXP mode performed
  76. *
  77. * @MEI_DEV_RESET_TO_PXP_DEFAULT: before reset
  78. * @MEI_DEV_RESET_TO_PXP_PERFORMED: reset performed
  79. * @MEI_DEV_RESET_TO_PXP_DONE: reset processed
  80. */
  81. enum mei_dev_reset_to_pxp {
  82. MEI_DEV_RESET_TO_PXP_DEFAULT = 0,
  83. MEI_DEV_RESET_TO_PXP_PERFORMED = 1,
  84. MEI_DEV_RESET_TO_PXP_DONE = 2,
  85. };
  86. const char *mei_dev_state_str(int state);
  87. enum mei_file_transaction_states {
  88. MEI_IDLE,
  89. MEI_WRITING,
  90. MEI_WRITE_COMPLETE,
  91. };
  92. /**
  93. * enum mei_cb_file_ops - file operation associated with the callback
  94. * @MEI_FOP_READ: read
  95. * @MEI_FOP_WRITE: write
  96. * @MEI_FOP_CONNECT: connect
  97. * @MEI_FOP_DISCONNECT: disconnect
  98. * @MEI_FOP_DISCONNECT_RSP: disconnect response
  99. * @MEI_FOP_NOTIFY_START: start notification
  100. * @MEI_FOP_NOTIFY_STOP: stop notification
  101. * @MEI_FOP_DMA_MAP: request client dma map
  102. * @MEI_FOP_DMA_UNMAP: request client dma unmap
  103. */
  104. enum mei_cb_file_ops {
  105. MEI_FOP_READ = 0,
  106. MEI_FOP_WRITE,
  107. MEI_FOP_CONNECT,
  108. MEI_FOP_DISCONNECT,
  109. MEI_FOP_DISCONNECT_RSP,
  110. MEI_FOP_NOTIFY_START,
  111. MEI_FOP_NOTIFY_STOP,
  112. MEI_FOP_DMA_MAP,
  113. MEI_FOP_DMA_UNMAP,
  114. };
  115. /**
  116. * enum mei_cl_io_mode - io mode between driver and fw
  117. *
  118. * @MEI_CL_IO_TX_BLOCKING: send is blocking
  119. * @MEI_CL_IO_TX_INTERNAL: internal communication between driver and FW
  120. *
  121. * @MEI_CL_IO_RX_NONBLOCK: recv is non-blocking
  122. *
  123. * @MEI_CL_IO_SGL: send command with sgl list.
  124. */
  125. enum mei_cl_io_mode {
  126. MEI_CL_IO_TX_BLOCKING = BIT(0),
  127. MEI_CL_IO_TX_INTERNAL = BIT(1),
  128. MEI_CL_IO_RX_NONBLOCK = BIT(2),
  129. MEI_CL_IO_SGL = BIT(3),
  130. };
  131. /*
  132. * Intel MEI message data struct
  133. */
  134. struct mei_msg_data {
  135. size_t size;
  136. unsigned char *data;
  137. };
  138. struct mei_dma_data {
  139. u8 buffer_id;
  140. void *vaddr;
  141. dma_addr_t daddr;
  142. size_t size;
  143. };
  144. /**
  145. * struct mei_dma_dscr - dma address descriptor
  146. *
  147. * @vaddr: dma buffer virtual address
  148. * @daddr: dma buffer physical address
  149. * @size : dma buffer size
  150. */
  151. struct mei_dma_dscr {
  152. void *vaddr;
  153. dma_addr_t daddr;
  154. size_t size;
  155. };
  156. /* Maximum number of processed FW status registers */
  157. #define MEI_FW_STATUS_MAX 6
  158. /* Minimal buffer for FW status string (8 bytes in dw + space or '\0') */
  159. #define MEI_FW_STATUS_STR_SZ (MEI_FW_STATUS_MAX * (8 + 1))
  160. /*
  161. * struct mei_fw_status - storage of FW status data
  162. *
  163. * @count: number of actually available elements in array
  164. * @status: FW status registers
  165. */
  166. struct mei_fw_status {
  167. int count;
  168. u32 status[MEI_FW_STATUS_MAX];
  169. };
  170. /**
  171. * struct mei_me_client - representation of me (fw) client
  172. *
  173. * @list: link in me client list
  174. * @refcnt: struct reference count
  175. * @props: client properties
  176. * @client_id: me client id
  177. * @tx_flow_ctrl_creds: flow control credits
  178. * @connect_count: number connections to this client
  179. * @bus_added: added to bus
  180. */
  181. struct mei_me_client {
  182. struct list_head list;
  183. struct kref refcnt;
  184. struct mei_client_properties props;
  185. u8 client_id;
  186. u8 tx_flow_ctrl_creds;
  187. u8 connect_count;
  188. u8 bus_added;
  189. };
  190. struct mei_cl;
  191. /**
  192. * struct mei_cl_cb - file operation callback structure
  193. *
  194. * @list: link in callback queue
  195. * @cl: file client who is running this operation
  196. * @fop_type: file operation type
  197. * @buf: buffer for data associated with the callback
  198. * @buf_idx: last read index
  199. * @vtag: virtual tag
  200. * @fp: pointer to file structure
  201. * @status: io status of the cb
  202. * @internal: communication between driver and FW flag
  203. * @blocking: transmission blocking mode
  204. * @ext_hdr: extended header
  205. */
  206. struct mei_cl_cb {
  207. struct list_head list;
  208. struct mei_cl *cl;
  209. enum mei_cb_file_ops fop_type;
  210. struct mei_msg_data buf;
  211. size_t buf_idx;
  212. u8 vtag;
  213. const struct file *fp;
  214. int status;
  215. u32 internal:1;
  216. u32 blocking:1;
  217. struct mei_ext_hdr *ext_hdr;
  218. };
  219. /**
  220. * struct mei_cl_vtag - file pointer to vtag mapping structure
  221. *
  222. * @list: link in map queue
  223. * @fp: file pointer
  224. * @vtag: corresponding vtag
  225. * @pending_read: the read is pending on this file
  226. */
  227. struct mei_cl_vtag {
  228. struct list_head list;
  229. const struct file *fp;
  230. u8 vtag;
  231. u8 pending_read:1;
  232. };
  233. /**
  234. * struct mei_cl - me client host representation
  235. * carried in file->private_data
  236. *
  237. * @link: link in the clients list
  238. * @dev: mei parent device
  239. * @state: file operation state
  240. * @tx_wait: wait queue for tx completion
  241. * @rx_wait: wait queue for rx completion
  242. * @wait: wait queue for management operation
  243. * @ev_wait: notification wait queue
  244. * @ev_async: event async notification
  245. * @status: connection status
  246. * @me_cl: fw client connected
  247. * @fp: file associated with client
  248. * @host_client_id: host id
  249. * @vtag_map: vtag map
  250. * @tx_flow_ctrl_creds: transmit flow credentials
  251. * @rx_flow_ctrl_creds: receive flow credentials
  252. * @timer_count: watchdog timer for operation completion
  253. * @notify_en: notification - enabled/disabled
  254. * @notify_ev: pending notification event
  255. * @tx_cb_queued: number of tx callbacks in queue
  256. * @writing_state: state of the tx
  257. * @rd_pending: pending read credits
  258. * @rd_completed_lock: protects rd_completed queue
  259. * @rd_completed: completed read
  260. * @dma: dma settings
  261. * @dma_mapped: dma buffer is currently mapped.
  262. *
  263. * @cldev: device on the mei client bus
  264. */
  265. struct mei_cl {
  266. struct list_head link;
  267. struct mei_device *dev;
  268. enum file_state state;
  269. wait_queue_head_t tx_wait;
  270. wait_queue_head_t rx_wait;
  271. wait_queue_head_t wait;
  272. wait_queue_head_t ev_wait;
  273. struct fasync_struct *ev_async;
  274. int status;
  275. struct mei_me_client *me_cl;
  276. const struct file *fp;
  277. u8 host_client_id;
  278. struct list_head vtag_map;
  279. u8 tx_flow_ctrl_creds;
  280. u8 rx_flow_ctrl_creds;
  281. u8 timer_count;
  282. u8 notify_en;
  283. u8 notify_ev;
  284. u8 tx_cb_queued;
  285. enum mei_file_transaction_states writing_state;
  286. struct list_head rd_pending;
  287. spinlock_t rd_completed_lock; /* protects rd_completed queue */
  288. struct list_head rd_completed;
  289. struct mei_dma_data dma;
  290. u8 dma_mapped;
  291. struct mei_cl_device *cldev;
  292. };
  293. #define MEI_TX_QUEUE_LIMIT_DEFAULT 50
  294. #define MEI_TX_QUEUE_LIMIT_MAX 255
  295. #define MEI_TX_QUEUE_LIMIT_MIN 30
  296. /**
  297. * struct mei_hw_ops - hw specific ops
  298. *
  299. * @host_is_ready : query for host readiness
  300. *
  301. * @hw_is_ready : query if hw is ready
  302. * @hw_reset : reset hw
  303. * @hw_start : start hw after reset
  304. * @hw_config : configure hw
  305. *
  306. * @fw_status : get fw status registers
  307. * @trc_status : get trc status register
  308. * @pg_state : power gating state of the device
  309. * @pg_in_transition : is device now in pg transition
  310. * @pg_is_enabled : is power gating enabled
  311. *
  312. * @intr_clear : clear pending interrupts
  313. * @intr_enable : enable interrupts
  314. * @intr_disable : disable interrupts
  315. * @synchronize_irq : synchronize irqs
  316. *
  317. * @hbuf_free_slots : query for write buffer empty slots
  318. * @hbuf_is_ready : query if write buffer is empty
  319. * @hbuf_depth : query for write buffer depth
  320. *
  321. * @write : write a message to FW
  322. *
  323. * @rdbuf_full_slots : query how many slots are filled
  324. *
  325. * @read_hdr : get first 4 bytes (header)
  326. * @read : read a buffer from the FW
  327. */
  328. struct mei_hw_ops {
  329. bool (*host_is_ready)(struct mei_device *dev);
  330. bool (*hw_is_ready)(struct mei_device *dev);
  331. int (*hw_reset)(struct mei_device *dev, bool enable);
  332. int (*hw_start)(struct mei_device *dev);
  333. int (*hw_config)(struct mei_device *dev);
  334. int (*fw_status)(struct mei_device *dev, struct mei_fw_status *fw_sts);
  335. int (*trc_status)(struct mei_device *dev, u32 *trc);
  336. enum mei_pg_state (*pg_state)(struct mei_device *dev);
  337. bool (*pg_in_transition)(struct mei_device *dev);
  338. bool (*pg_is_enabled)(struct mei_device *dev);
  339. void (*intr_clear)(struct mei_device *dev);
  340. void (*intr_enable)(struct mei_device *dev);
  341. void (*intr_disable)(struct mei_device *dev);
  342. void (*synchronize_irq)(struct mei_device *dev);
  343. int (*hbuf_free_slots)(struct mei_device *dev);
  344. bool (*hbuf_is_ready)(struct mei_device *dev);
  345. u32 (*hbuf_depth)(const struct mei_device *dev);
  346. int (*write)(struct mei_device *dev,
  347. const void *hdr, size_t hdr_len,
  348. const void *data, size_t data_len);
  349. int (*rdbuf_full_slots)(struct mei_device *dev);
  350. u32 (*read_hdr)(const struct mei_device *dev);
  351. int (*read)(struct mei_device *dev,
  352. unsigned char *buf, unsigned long len);
  353. };
  354. /* MEI bus API*/
  355. void mei_cl_bus_rescan_work(struct work_struct *work);
  356. void mei_cl_bus_dev_fixup(struct mei_cl_device *dev);
  357. ssize_t __mei_cl_send(struct mei_cl *cl, const u8 *buf, size_t length, u8 vtag,
  358. unsigned int mode);
  359. ssize_t __mei_cl_send_timeout(struct mei_cl *cl, const u8 *buf, size_t length, u8 vtag,
  360. unsigned int mode, unsigned long timeout);
  361. ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length, u8 *vtag,
  362. unsigned int mode, unsigned long timeout);
  363. bool mei_cl_bus_rx_event(struct mei_cl *cl);
  364. bool mei_cl_bus_notify_event(struct mei_cl *cl);
  365. void mei_cl_bus_remove_devices(struct mei_device *bus);
  366. int mei_cl_bus_init(void);
  367. void mei_cl_bus_exit(void);
  368. /**
  369. * enum mei_pg_event - power gating transition events
  370. *
  371. * @MEI_PG_EVENT_IDLE: the driver is not in power gating transition
  372. * @MEI_PG_EVENT_WAIT: the driver is waiting for a pg event to complete
  373. * @MEI_PG_EVENT_RECEIVED: the driver received pg event
  374. * @MEI_PG_EVENT_INTR_WAIT: the driver is waiting for a pg event interrupt
  375. * @MEI_PG_EVENT_INTR_RECEIVED: the driver received pg event interrupt
  376. */
  377. enum mei_pg_event {
  378. MEI_PG_EVENT_IDLE,
  379. MEI_PG_EVENT_WAIT,
  380. MEI_PG_EVENT_RECEIVED,
  381. MEI_PG_EVENT_INTR_WAIT,
  382. MEI_PG_EVENT_INTR_RECEIVED,
  383. };
  384. /**
  385. * enum mei_pg_state - device internal power gating state
  386. *
  387. * @MEI_PG_OFF: device is not power gated - it is active
  388. * @MEI_PG_ON: device is power gated - it is in lower power state
  389. */
  390. enum mei_pg_state {
  391. MEI_PG_OFF = 0,
  392. MEI_PG_ON = 1,
  393. };
  394. const char *mei_pg_state_str(enum mei_pg_state state);
  395. /**
  396. * struct mei_fw_version - MEI FW version struct
  397. *
  398. * @platform: platform identifier
  399. * @major: major version field
  400. * @minor: minor version field
  401. * @buildno: build number version field
  402. * @hotfix: hotfix number version field
  403. */
  404. struct mei_fw_version {
  405. u8 platform;
  406. u8 major;
  407. u16 minor;
  408. u16 buildno;
  409. u16 hotfix;
  410. };
  411. #define MEI_MAX_FW_VER_BLOCKS 3
  412. struct mei_dev_timeouts {
  413. unsigned long hw_ready; /* Timeout on ready message, in jiffies */
  414. int connect; /* HPS: at least 2 seconds, in seconds */
  415. unsigned long cl_connect; /* HPS: Client Connect Timeout, in jiffies */
  416. int client_init; /* HPS: Clients Enumeration Timeout, in seconds */
  417. unsigned long pgi; /* PG Isolation time response, in jiffies */
  418. unsigned int d0i3; /* D0i3 set/unset max response time, in jiffies */
  419. unsigned long hbm; /* HBM operation timeout, in jiffies */
  420. unsigned long mkhi_recv; /* receive timeout, in jiffies */
  421. unsigned long link_reset_wait; /* link reset wait timeout, in jiffies */
  422. };
  423. /**
  424. * struct mei_device - MEI private device struct
  425. *
  426. * @parent : device on a bus
  427. * @dev : device object
  428. * @cdev : character device pointer
  429. * @minor : minor number allocated for device
  430. *
  431. * @write_list : write pending list
  432. * @write_waiting_list : write completion list
  433. * @ctrl_wr_list : pending control write list
  434. * @ctrl_rd_list : pending control read list
  435. * @tx_queue_limit: tx queues per client linit
  436. *
  437. * @file_list : list of opened handles
  438. * @open_handle_count: number of opened handles
  439. *
  440. * @device_lock : big device lock
  441. * @timer_work : MEI timer delayed work (timeouts)
  442. *
  443. * @recvd_hw_ready : hw ready message received flag
  444. *
  445. * @wait_hw_ready : wait queue for receive HW ready message form FW
  446. * @wait_pg : wait queue for receive PG message from FW
  447. * @wait_hbm_start : wait queue for receive HBM start message from FW
  448. *
  449. * @reset_count : number of consecutive resets
  450. * @dev_state : device state
  451. * @wait_dev_state: wait queue for device state change
  452. * @hbm_state : state of host bus message protocol
  453. * @pxp_mode : PXP device mode
  454. * @init_clients_timer : HBM init handshake timeout
  455. *
  456. * @pg_event : power gating event
  457. * @pg_domain : runtime PM domain
  458. *
  459. * @rd_msg_buf : control messages buffer
  460. * @rd_msg_hdr : read message header storage
  461. * @rd_msg_hdr_count : how many dwords were already read from header
  462. *
  463. * @hbuf_is_ready : query if the host host/write buffer is ready
  464. * @dr_dscr: DMA ring descriptors: TX, RX, and CTRL
  465. *
  466. * @version : HBM protocol version in use
  467. * @hbm_f_pg_supported : hbm feature pgi protocol
  468. * @hbm_f_dc_supported : hbm feature dynamic clients
  469. * @hbm_f_dot_supported : hbm feature disconnect on timeout
  470. * @hbm_f_ev_supported : hbm feature event notification
  471. * @hbm_f_fa_supported : hbm feature fixed address client
  472. * @hbm_f_ie_supported : hbm feature immediate reply to enum request
  473. * @hbm_f_os_supported : hbm feature support OS ver message
  474. * @hbm_f_dr_supported : hbm feature dma ring supported
  475. * @hbm_f_vt_supported : hbm feature vtag supported
  476. * @hbm_f_cap_supported : hbm feature capabilities message supported
  477. * @hbm_f_cd_supported : hbm feature client dma supported
  478. * @hbm_f_gsc_supported : hbm feature gsc supported
  479. *
  480. * @fw_ver : FW versions
  481. *
  482. * @fw_f_fw_ver_supported : fw feature: fw version supported
  483. * @fw_ver_received : fw version received
  484. *
  485. * @me_clients_rwsem: rw lock over me_clients list
  486. * @me_clients : list of FW clients
  487. * @me_clients_map : FW clients bit map
  488. * @host_clients_map : host clients id pool
  489. *
  490. * @allow_fixed_address: allow user space to connect a fixed client
  491. * @override_fixed_address: force allow fixed address behavior
  492. *
  493. * @timeouts: actual timeout values
  494. *
  495. * @reset_work : work item for the device reset
  496. * @bus_rescan_work : work item for the bus rescan
  497. *
  498. * @device_list : mei client bus list
  499. * @cl_bus_lock : client bus list lock
  500. *
  501. * @kind : kind of mei device
  502. *
  503. * @dbgfs_dir : debugfs mei root directory
  504. *
  505. * @gsc_reset_to_pxp : state of reset to the PXP mode
  506. *
  507. * @ops: : hw specific operations
  508. * @hw : hw specific data
  509. */
  510. struct mei_device {
  511. struct device *parent;
  512. struct device dev;
  513. struct cdev *cdev;
  514. int minor;
  515. struct list_head write_list;
  516. struct list_head write_waiting_list;
  517. struct list_head ctrl_wr_list;
  518. struct list_head ctrl_rd_list;
  519. u8 tx_queue_limit;
  520. struct list_head file_list;
  521. long open_handle_count;
  522. struct mutex device_lock;
  523. struct delayed_work timer_work;
  524. bool recvd_hw_ready;
  525. /*
  526. * waiting queue for receive message from FW
  527. */
  528. wait_queue_head_t wait_hw_ready;
  529. wait_queue_head_t wait_pg;
  530. wait_queue_head_t wait_hbm_start;
  531. /*
  532. * mei device states
  533. */
  534. unsigned long reset_count;
  535. enum mei_dev_state dev_state;
  536. wait_queue_head_t wait_dev_state;
  537. enum mei_hbm_state hbm_state;
  538. enum mei_dev_pxp_mode pxp_mode;
  539. u16 init_clients_timer;
  540. /*
  541. * Power Gating support
  542. */
  543. enum mei_pg_event pg_event;
  544. #ifdef CONFIG_PM
  545. struct dev_pm_domain pg_domain;
  546. #endif /* CONFIG_PM */
  547. unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE];
  548. u32 rd_msg_hdr[MEI_RD_MSG_BUF_SIZE];
  549. int rd_msg_hdr_count;
  550. /* write buffer */
  551. bool hbuf_is_ready;
  552. struct mei_dma_dscr dr_dscr[DMA_DSCR_NUM];
  553. struct hbm_version version;
  554. unsigned int hbm_f_pg_supported:1;
  555. unsigned int hbm_f_dc_supported:1;
  556. unsigned int hbm_f_dot_supported:1;
  557. unsigned int hbm_f_ev_supported:1;
  558. unsigned int hbm_f_fa_supported:1;
  559. unsigned int hbm_f_ie_supported:1;
  560. unsigned int hbm_f_os_supported:1;
  561. unsigned int hbm_f_dr_supported:1;
  562. unsigned int hbm_f_vt_supported:1;
  563. unsigned int hbm_f_cap_supported:1;
  564. unsigned int hbm_f_cd_supported:1;
  565. unsigned int hbm_f_gsc_supported:1;
  566. struct mei_fw_version fw_ver[MEI_MAX_FW_VER_BLOCKS];
  567. unsigned int fw_f_fw_ver_supported:1;
  568. unsigned int fw_ver_received:1;
  569. struct rw_semaphore me_clients_rwsem;
  570. struct list_head me_clients;
  571. DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
  572. DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
  573. bool allow_fixed_address;
  574. bool override_fixed_address;
  575. struct mei_dev_timeouts timeouts;
  576. struct work_struct reset_work;
  577. struct work_struct bus_rescan_work;
  578. /* List of bus devices */
  579. struct list_head device_list;
  580. struct mutex cl_bus_lock;
  581. const char *kind;
  582. #if IS_ENABLED(CONFIG_DEBUG_FS)
  583. struct dentry *dbgfs_dir;
  584. #endif /* CONFIG_DEBUG_FS */
  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 *parent,
  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