// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2003-2022, Intel Corporation. All rights reserved. * Intel Management Engine Interface (Intel MEI) Linux driver */ #include <linux/export.h> #include <linux/sched.h> #include <linux/wait.h> #include <linux/pm_runtime.h> #include <linux/slab.h> #include <linux/mei.h> #include "mei_dev.h" #include "hbm.h" #include "client.h" static const char *mei_hbm_status_str(enum mei_hbm_status status) { #define MEI_HBM_STATUS(status) case MEI_HBMS_##status: return #status switch (status) { MEI_HBM_STATUS(SUCCESS); MEI_HBM_STATUS(CLIENT_NOT_FOUND); MEI_HBM_STATUS(ALREADY_EXISTS); MEI_HBM_STATUS(REJECTED); MEI_HBM_STATUS(INVALID_PARAMETER); MEI_HBM_STATUS(NOT_ALLOWED); MEI_HBM_STATUS(ALREADY_STARTED); MEI_HBM_STATUS(NOT_STARTED); default: return "unknown"; } #undef MEI_HBM_STATUS }; static const char *mei_cl_conn_status_str(enum mei_cl_connect_status status) { … } const char *mei_hbm_state_str(enum mei_hbm_state state) { … } /** * mei_cl_conn_status_to_errno - convert client connect response * status to error code * * @status: client connect response status * * Return: corresponding error code */ static int mei_cl_conn_status_to_errno(enum mei_cl_connect_status status) { … } /** * mei_hbm_write_message - wrapper for sending hbm messages. * * @dev: mei device * @hdr: mei header * @data: payload * * Return: >=0 on success, <0 on error */ static inline int mei_hbm_write_message(struct mei_device *dev, struct mei_msg_hdr *hdr, const void *data) { … } /** * mei_hbm_idle - set hbm to idle state * * @dev: the device structure */ void mei_hbm_idle(struct mei_device *dev) { … } /** * mei_hbm_reset - reset hbm counters and book keeping data structures * * @dev: the device structure */ void mei_hbm_reset(struct mei_device *dev) { … } /** * mei_hbm_hdr - construct hbm header * * @mei_hdr: hbm header * @length: payload length */ static inline void mei_hbm_hdr(struct mei_msg_hdr *mei_hdr, size_t length) { … } /** * mei_hbm_cl_hdr - construct client hbm header * * @cl: client * @hbm_cmd: host bus message command * @buf: buffer for cl header * @len: buffer length */ static inline void mei_hbm_cl_hdr(struct mei_cl *cl, u8 hbm_cmd, void *buf, size_t len) { … } /** * mei_hbm_cl_write - write simple hbm client message * * @dev: the device structure * @cl: client * @hbm_cmd: host bus message command * @buf: message buffer * @len: buffer length * * Return: 0 on success, <0 on failure. */ static inline int mei_hbm_cl_write(struct mei_device *dev, struct mei_cl *cl, u8 hbm_cmd, void *buf, size_t len) { … } /** * mei_hbm_cl_addr_equal - check if the client's and * the message address match * * @cl: client * @cmd: hbm client message * * Return: true if addresses are the same */ static inline bool mei_hbm_cl_addr_equal(struct mei_cl *cl, struct mei_hbm_cl_cmd *cmd) { … } /** * mei_hbm_cl_find_by_cmd - find recipient client * * @dev: the device structure * @buf: a buffer with hbm cl command * * Return: the recipient client or NULL if not found */ static inline struct mei_cl *mei_hbm_cl_find_by_cmd(struct mei_device *dev, void *buf) { … } /** * mei_hbm_start_wait - wait for start response message. * * @dev: the device structure * * Return: 0 on success and < 0 on failure */ int mei_hbm_start_wait(struct mei_device *dev) { … } /** * mei_hbm_start_req - sends start request message. * * @dev: the device structure * * Return: 0 on success and < 0 on failure */ int mei_hbm_start_req(struct mei_device *dev) { … } /** * mei_hbm_dma_setup_req() - setup DMA request * @dev: the device structure * * Return: 0 on success and < 0 on failure */ static int mei_hbm_dma_setup_req(struct mei_device *dev) { … } /** * mei_hbm_capabilities_req - request capabilities * * @dev: the device structure * * Return: 0 on success and < 0 on failure */ static int mei_hbm_capabilities_req(struct mei_device *dev) { … } /** * mei_hbm_enum_clients_req - sends enumeration client request message. * * @dev: the device structure * * Return: 0 on success and < 0 on failure */ static int mei_hbm_enum_clients_req(struct mei_device *dev) { … } /** * mei_hbm_me_cl_add - add new me client to the list * * @dev: the device structure * @res: hbm property response * * Return: 0 on success and -ENOMEM on allocation failure */ static int mei_hbm_me_cl_add(struct mei_device *dev, struct hbm_props_response *res) { … } /** * mei_hbm_add_cl_resp - send response to fw on client add request * * @dev: the device structure * @addr: me address * @status: response status * * Return: 0 on success and < 0 on failure */ static int mei_hbm_add_cl_resp(struct mei_device *dev, u8 addr, u8 status) { … } /** * mei_hbm_fw_add_cl_req - request from the fw to add a client * * @dev: the device structure * @req: add client request * * Return: 0 on success and < 0 on failure */ static int mei_hbm_fw_add_cl_req(struct mei_device *dev, struct hbm_add_client_request *req) { … } /** * mei_hbm_cl_notify_req - send notification request * * @dev: the device structure * @cl: a client to disconnect from * @start: true for start false for stop * * Return: 0 on success and -EIO on write failure */ int mei_hbm_cl_notify_req(struct mei_device *dev, struct mei_cl *cl, u8 start) { … } /** * notify_res_to_fop - convert notification response to the proper * notification FOP * * @cmd: client notification start response command * * Return: MEI_FOP_NOTIFY_START or MEI_FOP_NOTIFY_STOP; */ static inline enum mei_cb_file_ops notify_res_to_fop(struct mei_hbm_cl_cmd *cmd) { … } /** * mei_hbm_cl_notify_start_res - update the client state according * notify start response * * @dev: the device structure * @cl: mei host client * @cmd: client notification start response command */ static void mei_hbm_cl_notify_start_res(struct mei_device *dev, struct mei_cl *cl, struct mei_hbm_cl_cmd *cmd) { … } /** * mei_hbm_cl_notify_stop_res - update the client state according * notify stop response * * @dev: the device structure * @cl: mei host client * @cmd: client notification stop response command */ static void mei_hbm_cl_notify_stop_res(struct mei_device *dev, struct mei_cl *cl, struct mei_hbm_cl_cmd *cmd) { … } /** * mei_hbm_cl_notify - signal notification event * * @dev: the device structure * @cmd: notification client message */ static void mei_hbm_cl_notify(struct mei_device *dev, struct mei_hbm_cl_cmd *cmd) { … } /** * mei_hbm_cl_dma_map_req - send client dma map request * * @dev: the device structure * @cl: mei host client * * Return: 0 on success and -EIO on write failure */ int mei_hbm_cl_dma_map_req(struct mei_device *dev, struct mei_cl *cl) { … } /** * mei_hbm_cl_dma_unmap_req - send client dma unmap request * * @dev: the device structure * @cl: mei host client * * Return: 0 on success and -EIO on write failure */ int mei_hbm_cl_dma_unmap_req(struct mei_device *dev, struct mei_cl *cl) { … } static void mei_hbm_cl_dma_map_res(struct mei_device *dev, struct hbm_client_dma_response *res) { … } static void mei_hbm_cl_dma_unmap_res(struct mei_device *dev, struct hbm_client_dma_response *res) { … } /** * mei_hbm_prop_req - request property for a single client * * @dev: the device structure * @start_idx: client index to start search * * Return: 0 on success and < 0 on failure */ static int mei_hbm_prop_req(struct mei_device *dev, unsigned long start_idx) { … } /** * mei_hbm_pg - sends pg command * * @dev: the device structure * @pg_cmd: the pg command code * * Return: -EIO on write failure * -EOPNOTSUPP if the operation is not supported by the protocol */ int mei_hbm_pg(struct mei_device *dev, u8 pg_cmd) { … } EXPORT_SYMBOL_GPL(…); /** * mei_hbm_stop_req - send stop request message * * @dev: mei device * * Return: -EIO on write failure */ static int mei_hbm_stop_req(struct mei_device *dev) { … } /** * mei_hbm_cl_flow_control_req - sends flow control request. * * @dev: the device structure * @cl: client info * * Return: -EIO on write failure */ int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl) { … } /** * mei_hbm_add_single_tx_flow_ctrl_creds - adds single buffer credentials. * * @dev: the device structure * @fctrl: flow control response bus message * * Return: 0 on success, < 0 otherwise */ static int mei_hbm_add_single_tx_flow_ctrl_creds(struct mei_device *dev, struct hbm_flow_control *fctrl) { … } /** * mei_hbm_cl_tx_flow_ctrl_creds_res - flow control response from me * * @dev: the device structure * @fctrl: flow control response bus message */ static void mei_hbm_cl_tx_flow_ctrl_creds_res(struct mei_device *dev, struct hbm_flow_control *fctrl) { … } /** * mei_hbm_cl_disconnect_req - sends disconnect message to fw. * * @dev: the device structure * @cl: a client to disconnect from * * Return: -EIO on write failure */ int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl) { … } /** * mei_hbm_cl_disconnect_rsp - sends disconnect response to the FW * * @dev: the device structure * @cl: a client to disconnect from * * Return: -EIO on write failure */ int mei_hbm_cl_disconnect_rsp(struct mei_device *dev, struct mei_cl *cl) { … } /** * mei_hbm_cl_disconnect_res - update the client state according * disconnect response * * @dev: the device structure * @cl: mei host client * @cmd: disconnect client response host bus message */ static void mei_hbm_cl_disconnect_res(struct mei_device *dev, struct mei_cl *cl, struct mei_hbm_cl_cmd *cmd) { … } /** * mei_hbm_cl_connect_req - send connection request to specific me client * * @dev: the device structure * @cl: a client to connect to * * Return: -EIO on write failure */ int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl) { … } /** * mei_hbm_cl_connect_res - update the client state according * connection response * * @dev: the device structure * @cl: mei host client * @cmd: connect client response host bus message */ static void mei_hbm_cl_connect_res(struct mei_device *dev, struct mei_cl *cl, struct mei_hbm_cl_cmd *cmd) { … } /** * mei_hbm_cl_res - process hbm response received on behalf * an client * * @dev: the device structure * @rs: hbm client message * @fop_type: file operation type */ static void mei_hbm_cl_res(struct mei_device *dev, struct mei_hbm_cl_cmd *rs, enum mei_cb_file_ops fop_type) { … } /** * mei_hbm_fw_disconnect_req - disconnect request initiated by ME firmware * host sends disconnect response * * @dev: the device structure. * @disconnect_req: disconnect request bus message from the me * * Return: -ENOMEM on allocation failure */ static int mei_hbm_fw_disconnect_req(struct mei_device *dev, struct hbm_client_connect_request *disconnect_req) { … } /** * mei_hbm_pg_enter_res - PG enter response received * * @dev: the device structure. * * Return: 0 on success, -EPROTO on state mismatch */ static int mei_hbm_pg_enter_res(struct mei_device *dev) { … } /** * mei_hbm_pg_resume - process with PG resume * * @dev: the device structure. */ void mei_hbm_pg_resume(struct mei_device *dev) { … } EXPORT_SYMBOL_GPL(…); /** * mei_hbm_pg_exit_res - PG exit response received * * @dev: the device structure. * * Return: 0 on success, -EPROTO on state mismatch */ static int mei_hbm_pg_exit_res(struct mei_device *dev) { … } /** * mei_hbm_config_features - check what hbm features and commands * are supported by the fw * * @dev: the device structure */ static void mei_hbm_config_features(struct mei_device *dev) { … } /** * mei_hbm_version_is_supported - checks whether the driver can * support the hbm version of the device * * @dev: the device structure * Return: true if driver can support hbm version of the device */ bool mei_hbm_version_is_supported(struct mei_device *dev) { … } /** * mei_hbm_dispatch - bottom half read routine after ISR to * handle the read bus message cmd processing. * * @dev: the device structure * @hdr: header of bus message * * Return: 0 on success and < 0 on failure */ int mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr) { … }