18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * ISHTP bus layer messages handling 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2003-2016, Intel Corporation. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef _ISHTP_HBM_H_ 98c2ecf20Sopenharmony_ci#define _ISHTP_HBM_H_ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/uuid.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistruct ishtp_device; 148c2ecf20Sopenharmony_cistruct ishtp_msg_hdr; 158c2ecf20Sopenharmony_cistruct ishtp_cl; 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* 188c2ecf20Sopenharmony_ci * Timeouts in Seconds 198c2ecf20Sopenharmony_ci */ 208c2ecf20Sopenharmony_ci#define ISHTP_INTEROP_TIMEOUT 7 /* Timeout on ready message */ 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define ISHTP_CL_CONNECT_TIMEOUT 15 /* HPS: Client Connect Timeout */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* 258c2ecf20Sopenharmony_ci * ISHTP Version 268c2ecf20Sopenharmony_ci */ 278c2ecf20Sopenharmony_ci#define HBM_MINOR_VERSION 0 288c2ecf20Sopenharmony_ci#define HBM_MAJOR_VERSION 1 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* Host bus message command opcode */ 318c2ecf20Sopenharmony_ci#define ISHTP_HBM_CMD_OP_MSK 0x7f 328c2ecf20Sopenharmony_ci/* Host bus message command RESPONSE */ 338c2ecf20Sopenharmony_ci#define ISHTP_HBM_CMD_RES_MSK 0x80 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* 368c2ecf20Sopenharmony_ci * ISHTP Bus Message Command IDs 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_ci#define HOST_START_REQ_CMD 0x01 398c2ecf20Sopenharmony_ci#define HOST_START_RES_CMD 0x81 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define HOST_STOP_REQ_CMD 0x02 428c2ecf20Sopenharmony_ci#define HOST_STOP_RES_CMD 0x82 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define FW_STOP_REQ_CMD 0x03 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define HOST_ENUM_REQ_CMD 0x04 478c2ecf20Sopenharmony_ci#define HOST_ENUM_RES_CMD 0x84 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#define HOST_CLIENT_PROPERTIES_REQ_CMD 0x05 508c2ecf20Sopenharmony_ci#define HOST_CLIENT_PROPERTIES_RES_CMD 0x85 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#define CLIENT_CONNECT_REQ_CMD 0x06 538c2ecf20Sopenharmony_ci#define CLIENT_CONNECT_RES_CMD 0x86 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#define CLIENT_DISCONNECT_REQ_CMD 0x07 568c2ecf20Sopenharmony_ci#define CLIENT_DISCONNECT_RES_CMD 0x87 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#define ISHTP_FLOW_CONTROL_CMD 0x08 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#define DMA_BUFFER_ALLOC_NOTIFY 0x11 618c2ecf20Sopenharmony_ci#define DMA_BUFFER_ALLOC_RESPONSE 0x91 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#define DMA_XFER 0x12 648c2ecf20Sopenharmony_ci#define DMA_XFER_ACK 0x92 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* 678c2ecf20Sopenharmony_ci * ISHTP Stop Reason 688c2ecf20Sopenharmony_ci * used by hbm_host_stop_request.reason 698c2ecf20Sopenharmony_ci */ 708c2ecf20Sopenharmony_ci#define DRIVER_STOP_REQUEST 0x00 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* 738c2ecf20Sopenharmony_ci * ISHTP BUS Interface Section 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_cistruct ishtp_msg_hdr { 768c2ecf20Sopenharmony_ci uint32_t fw_addr:8; 778c2ecf20Sopenharmony_ci uint32_t host_addr:8; 788c2ecf20Sopenharmony_ci uint32_t length:9; 798c2ecf20Sopenharmony_ci uint32_t reserved:6; 808c2ecf20Sopenharmony_ci uint32_t msg_complete:1; 818c2ecf20Sopenharmony_ci} __packed; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistruct ishtp_bus_message { 848c2ecf20Sopenharmony_ci uint8_t hbm_cmd; 858c2ecf20Sopenharmony_ci uint8_t data[]; 868c2ecf20Sopenharmony_ci} __packed; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/** 898c2ecf20Sopenharmony_ci * struct hbm_cl_cmd - client specific host bus command 908c2ecf20Sopenharmony_ci * CONNECT, DISCONNECT, and FlOW CONTROL 918c2ecf20Sopenharmony_ci * 928c2ecf20Sopenharmony_ci * @hbm_cmd - bus message command header 938c2ecf20Sopenharmony_ci * @fw_addr - address of the fw client 948c2ecf20Sopenharmony_ci * @host_addr - address of the client in the driver 958c2ecf20Sopenharmony_ci * @data 968c2ecf20Sopenharmony_ci */ 978c2ecf20Sopenharmony_cistruct ishtp_hbm_cl_cmd { 988c2ecf20Sopenharmony_ci uint8_t hbm_cmd; 998c2ecf20Sopenharmony_ci uint8_t fw_addr; 1008c2ecf20Sopenharmony_ci uint8_t host_addr; 1018c2ecf20Sopenharmony_ci uint8_t data; 1028c2ecf20Sopenharmony_ci}; 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cistruct hbm_version { 1058c2ecf20Sopenharmony_ci uint8_t minor_version; 1068c2ecf20Sopenharmony_ci uint8_t major_version; 1078c2ecf20Sopenharmony_ci} __packed; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistruct hbm_host_version_request { 1108c2ecf20Sopenharmony_ci uint8_t hbm_cmd; 1118c2ecf20Sopenharmony_ci uint8_t reserved; 1128c2ecf20Sopenharmony_ci struct hbm_version host_version; 1138c2ecf20Sopenharmony_ci} __packed; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistruct hbm_host_version_response { 1168c2ecf20Sopenharmony_ci uint8_t hbm_cmd; 1178c2ecf20Sopenharmony_ci uint8_t host_version_supported; 1188c2ecf20Sopenharmony_ci struct hbm_version fw_max_version; 1198c2ecf20Sopenharmony_ci} __packed; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_cistruct hbm_host_stop_request { 1228c2ecf20Sopenharmony_ci uint8_t hbm_cmd; 1238c2ecf20Sopenharmony_ci uint8_t reason; 1248c2ecf20Sopenharmony_ci uint8_t reserved[2]; 1258c2ecf20Sopenharmony_ci} __packed; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_cistruct hbm_host_stop_response { 1288c2ecf20Sopenharmony_ci uint8_t hbm_cmd; 1298c2ecf20Sopenharmony_ci uint8_t reserved[3]; 1308c2ecf20Sopenharmony_ci} __packed; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_cistruct hbm_host_enum_request { 1338c2ecf20Sopenharmony_ci uint8_t hbm_cmd; 1348c2ecf20Sopenharmony_ci uint8_t reserved[3]; 1358c2ecf20Sopenharmony_ci} __packed; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_cistruct hbm_host_enum_response { 1388c2ecf20Sopenharmony_ci uint8_t hbm_cmd; 1398c2ecf20Sopenharmony_ci uint8_t reserved[3]; 1408c2ecf20Sopenharmony_ci uint8_t valid_addresses[32]; 1418c2ecf20Sopenharmony_ci} __packed; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistruct ishtp_client_properties { 1448c2ecf20Sopenharmony_ci guid_t protocol_name; 1458c2ecf20Sopenharmony_ci uint8_t protocol_version; 1468c2ecf20Sopenharmony_ci uint8_t max_number_of_connections; 1478c2ecf20Sopenharmony_ci uint8_t fixed_address; 1488c2ecf20Sopenharmony_ci uint8_t single_recv_buf; 1498c2ecf20Sopenharmony_ci uint32_t max_msg_length; 1508c2ecf20Sopenharmony_ci uint8_t dma_hdr_len; 1518c2ecf20Sopenharmony_ci#define ISHTP_CLIENT_DMA_ENABLED 0x80 1528c2ecf20Sopenharmony_ci uint8_t reserved4; 1538c2ecf20Sopenharmony_ci uint8_t reserved5; 1548c2ecf20Sopenharmony_ci uint8_t reserved6; 1558c2ecf20Sopenharmony_ci} __packed; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_cistruct hbm_props_request { 1588c2ecf20Sopenharmony_ci uint8_t hbm_cmd; 1598c2ecf20Sopenharmony_ci uint8_t address; 1608c2ecf20Sopenharmony_ci uint8_t reserved[2]; 1618c2ecf20Sopenharmony_ci} __packed; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_cistruct hbm_props_response { 1648c2ecf20Sopenharmony_ci uint8_t hbm_cmd; 1658c2ecf20Sopenharmony_ci uint8_t address; 1668c2ecf20Sopenharmony_ci uint8_t status; 1678c2ecf20Sopenharmony_ci uint8_t reserved[1]; 1688c2ecf20Sopenharmony_ci struct ishtp_client_properties client_properties; 1698c2ecf20Sopenharmony_ci} __packed; 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci/** 1728c2ecf20Sopenharmony_ci * struct hbm_client_connect_request - connect/disconnect request 1738c2ecf20Sopenharmony_ci * 1748c2ecf20Sopenharmony_ci * @hbm_cmd - bus message command header 1758c2ecf20Sopenharmony_ci * @fw_addr - address of the fw client 1768c2ecf20Sopenharmony_ci * @host_addr - address of the client in the driver 1778c2ecf20Sopenharmony_ci * @reserved 1788c2ecf20Sopenharmony_ci */ 1798c2ecf20Sopenharmony_cistruct hbm_client_connect_request { 1808c2ecf20Sopenharmony_ci uint8_t hbm_cmd; 1818c2ecf20Sopenharmony_ci uint8_t fw_addr; 1828c2ecf20Sopenharmony_ci uint8_t host_addr; 1838c2ecf20Sopenharmony_ci uint8_t reserved; 1848c2ecf20Sopenharmony_ci} __packed; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci/** 1878c2ecf20Sopenharmony_ci * struct hbm_client_connect_response - connect/disconnect response 1888c2ecf20Sopenharmony_ci * 1898c2ecf20Sopenharmony_ci * @hbm_cmd - bus message command header 1908c2ecf20Sopenharmony_ci * @fw_addr - address of the fw client 1918c2ecf20Sopenharmony_ci * @host_addr - address of the client in the driver 1928c2ecf20Sopenharmony_ci * @status - status of the request 1938c2ecf20Sopenharmony_ci */ 1948c2ecf20Sopenharmony_cistruct hbm_client_connect_response { 1958c2ecf20Sopenharmony_ci uint8_t hbm_cmd; 1968c2ecf20Sopenharmony_ci uint8_t fw_addr; 1978c2ecf20Sopenharmony_ci uint8_t host_addr; 1988c2ecf20Sopenharmony_ci uint8_t status; 1998c2ecf20Sopenharmony_ci} __packed; 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci#define ISHTP_FC_MESSAGE_RESERVED_LENGTH 5 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_cistruct hbm_flow_control { 2058c2ecf20Sopenharmony_ci uint8_t hbm_cmd; 2068c2ecf20Sopenharmony_ci uint8_t fw_addr; 2078c2ecf20Sopenharmony_ci uint8_t host_addr; 2088c2ecf20Sopenharmony_ci uint8_t reserved[ISHTP_FC_MESSAGE_RESERVED_LENGTH]; 2098c2ecf20Sopenharmony_ci} __packed; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_cistruct dma_alloc_notify { 2128c2ecf20Sopenharmony_ci uint8_t hbm; 2138c2ecf20Sopenharmony_ci uint8_t status; 2148c2ecf20Sopenharmony_ci uint8_t reserved[2]; 2158c2ecf20Sopenharmony_ci uint32_t buf_size; 2168c2ecf20Sopenharmony_ci uint64_t buf_address; 2178c2ecf20Sopenharmony_ci /* [...] May come more size/address pairs */ 2188c2ecf20Sopenharmony_ci} __packed; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_cistruct dma_xfer_hbm { 2218c2ecf20Sopenharmony_ci uint8_t hbm; 2228c2ecf20Sopenharmony_ci uint8_t fw_client_id; 2238c2ecf20Sopenharmony_ci uint8_t host_client_id; 2248c2ecf20Sopenharmony_ci uint8_t reserved; 2258c2ecf20Sopenharmony_ci uint64_t msg_addr; 2268c2ecf20Sopenharmony_ci uint32_t msg_length; 2278c2ecf20Sopenharmony_ci uint32_t reserved2; 2288c2ecf20Sopenharmony_ci} __packed; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci/* System state */ 2318c2ecf20Sopenharmony_ci#define ISHTP_SYSTEM_STATE_CLIENT_ADDR 13 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci#define SYSTEM_STATE_SUBSCRIBE 0x1 2348c2ecf20Sopenharmony_ci#define SYSTEM_STATE_STATUS 0x2 2358c2ecf20Sopenharmony_ci#define SYSTEM_STATE_QUERY_SUBSCRIBERS 0x3 2368c2ecf20Sopenharmony_ci#define SYSTEM_STATE_STATE_CHANGE_REQ 0x4 2378c2ecf20Sopenharmony_ci/*indicates suspend and resume states*/ 2388c2ecf20Sopenharmony_ci#define SUSPEND_STATE_BIT (1<<1) 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_cistruct ish_system_states_header { 2418c2ecf20Sopenharmony_ci uint32_t cmd; 2428c2ecf20Sopenharmony_ci uint32_t cmd_status; /*responses will have this set*/ 2438c2ecf20Sopenharmony_ci} __packed; 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_cistruct ish_system_states_subscribe { 2468c2ecf20Sopenharmony_ci struct ish_system_states_header hdr; 2478c2ecf20Sopenharmony_ci uint32_t states; 2488c2ecf20Sopenharmony_ci} __packed; 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_cistruct ish_system_states_status { 2518c2ecf20Sopenharmony_ci struct ish_system_states_header hdr; 2528c2ecf20Sopenharmony_ci uint32_t supported_states; 2538c2ecf20Sopenharmony_ci uint32_t states_status; 2548c2ecf20Sopenharmony_ci} __packed; 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_cistruct ish_system_states_query_subscribers { 2578c2ecf20Sopenharmony_ci struct ish_system_states_header hdr; 2588c2ecf20Sopenharmony_ci} __packed; 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_cistruct ish_system_states_state_change_req { 2618c2ecf20Sopenharmony_ci struct ish_system_states_header hdr; 2628c2ecf20Sopenharmony_ci uint32_t requested_states; 2638c2ecf20Sopenharmony_ci uint32_t states_status; 2648c2ecf20Sopenharmony_ci} __packed; 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci/** 2678c2ecf20Sopenharmony_ci * enum ishtp_hbm_state - host bus message protocol state 2688c2ecf20Sopenharmony_ci * 2698c2ecf20Sopenharmony_ci * @ISHTP_HBM_IDLE : protocol not started 2708c2ecf20Sopenharmony_ci * @ISHTP_HBM_START : start request message was sent 2718c2ecf20Sopenharmony_ci * @ISHTP_HBM_ENUM_CLIENTS : enumeration request was sent 2728c2ecf20Sopenharmony_ci * @ISHTP_HBM_CLIENT_PROPERTIES : acquiring clients properties 2738c2ecf20Sopenharmony_ci */ 2748c2ecf20Sopenharmony_cienum ishtp_hbm_state { 2758c2ecf20Sopenharmony_ci ISHTP_HBM_IDLE = 0, 2768c2ecf20Sopenharmony_ci ISHTP_HBM_START, 2778c2ecf20Sopenharmony_ci ISHTP_HBM_STARTED, 2788c2ecf20Sopenharmony_ci ISHTP_HBM_ENUM_CLIENTS, 2798c2ecf20Sopenharmony_ci ISHTP_HBM_CLIENT_PROPERTIES, 2808c2ecf20Sopenharmony_ci ISHTP_HBM_WORKING, 2818c2ecf20Sopenharmony_ci ISHTP_HBM_STOPPED, 2828c2ecf20Sopenharmony_ci}; 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_cistatic inline void ishtp_hbm_hdr(struct ishtp_msg_hdr *hdr, size_t length) 2858c2ecf20Sopenharmony_ci{ 2868c2ecf20Sopenharmony_ci hdr->host_addr = 0; 2878c2ecf20Sopenharmony_ci hdr->fw_addr = 0; 2888c2ecf20Sopenharmony_ci hdr->length = length; 2898c2ecf20Sopenharmony_ci hdr->msg_complete = 1; 2908c2ecf20Sopenharmony_ci hdr->reserved = 0; 2918c2ecf20Sopenharmony_ci} 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ciint ishtp_hbm_start_req(struct ishtp_device *dev); 2948c2ecf20Sopenharmony_ciint ishtp_hbm_start_wait(struct ishtp_device *dev); 2958c2ecf20Sopenharmony_ciint ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev, 2968c2ecf20Sopenharmony_ci struct ishtp_cl *cl); 2978c2ecf20Sopenharmony_ciint ishtp_hbm_cl_disconnect_req(struct ishtp_device *dev, struct ishtp_cl *cl); 2988c2ecf20Sopenharmony_ciint ishtp_hbm_cl_connect_req(struct ishtp_device *dev, struct ishtp_cl *cl); 2998c2ecf20Sopenharmony_civoid ishtp_hbm_enum_clients_req(struct ishtp_device *dev); 3008c2ecf20Sopenharmony_civoid bh_hbm_work_fn(struct work_struct *work); 3018c2ecf20Sopenharmony_civoid recv_hbm(struct ishtp_device *dev, struct ishtp_msg_hdr *ishtp_hdr); 3028c2ecf20Sopenharmony_civoid recv_fixed_cl_msg(struct ishtp_device *dev, 3038c2ecf20Sopenharmony_ci struct ishtp_msg_hdr *ishtp_hdr); 3048c2ecf20Sopenharmony_civoid ishtp_hbm_dispatch(struct ishtp_device *dev, 3058c2ecf20Sopenharmony_ci struct ishtp_bus_message *hdr); 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_civoid ishtp_query_subscribers(struct ishtp_device *dev); 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci/* Exported I/F */ 3108c2ecf20Sopenharmony_civoid ishtp_send_suspend(struct ishtp_device *dev); 3118c2ecf20Sopenharmony_civoid ishtp_send_resume(struct ishtp_device *dev); 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci#endif /* _ISHTP_HBM_H_ */ 314