315 lines · c
1/* SPDX-License-Identifier: GPL-2.0-only */2/*3 * ISHTP bus layer messages handling4 *5 * Copyright (c) 2003-2016, Intel Corporation.6 */7 8#ifndef _ISHTP_HBM_H_9#define _ISHTP_HBM_H_10 11#include <linux/uuid.h>12 13struct ishtp_device;14struct ishtp_msg_hdr;15struct ishtp_cl;16 17/*18 * Timeouts in Seconds19 */20#define ISHTP_INTEROP_TIMEOUT 7 /* Timeout on ready message */21 22#define ISHTP_CL_CONNECT_TIMEOUT 15 /* HPS: Client Connect Timeout */23 24/*25 * ISHTP Version26 */27#define HBM_MINOR_VERSION 028#define HBM_MAJOR_VERSION 129 30/* Host bus message command opcode */31#define ISHTP_HBM_CMD_OP_MSK 0x7f32/* Host bus message command RESPONSE */33#define ISHTP_HBM_CMD_RES_MSK 0x8034 35/*36 * ISHTP Bus Message Command IDs37 */38#define HOST_START_REQ_CMD 0x0139#define HOST_START_RES_CMD 0x8140 41#define HOST_STOP_REQ_CMD 0x0242#define HOST_STOP_RES_CMD 0x8243 44#define FW_STOP_REQ_CMD 0x0345 46#define HOST_ENUM_REQ_CMD 0x0447#define HOST_ENUM_RES_CMD 0x8448 49#define HOST_CLIENT_PROPERTIES_REQ_CMD 0x0550#define HOST_CLIENT_PROPERTIES_RES_CMD 0x8551 52#define CLIENT_CONNECT_REQ_CMD 0x0653#define CLIENT_CONNECT_RES_CMD 0x8654 55#define CLIENT_DISCONNECT_REQ_CMD 0x0756#define CLIENT_DISCONNECT_RES_CMD 0x8757 58#define ISHTP_FLOW_CONTROL_CMD 0x0859 60#define DMA_BUFFER_ALLOC_NOTIFY 0x1161#define DMA_BUFFER_ALLOC_RESPONSE 0x9162 63#define DMA_XFER 0x1264#define DMA_XFER_ACK 0x9265 66/*67 * ISHTP Stop Reason68 * used by hbm_host_stop_request.reason69 */70#define DRIVER_STOP_REQUEST 0x0071 72/*73 * ISHTP BUS Interface Section74 */75struct ishtp_msg_hdr {76 uint32_t fw_addr:8;77 uint32_t host_addr:8;78 uint32_t length:9;79 uint32_t reserved:6;80 uint32_t msg_complete:1;81} __packed;82 83struct ishtp_bus_message {84 uint8_t hbm_cmd;85 uint8_t data[];86} __packed;87 88/**89 * struct hbm_cl_cmd - client specific host bus command90 * CONNECT, DISCONNECT, and FlOW CONTROL91 *92 * @hbm_cmd - bus message command header93 * @fw_addr - address of the fw client94 * @host_addr - address of the client in the driver95 * @data96 */97struct ishtp_hbm_cl_cmd {98 uint8_t hbm_cmd;99 uint8_t fw_addr;100 uint8_t host_addr;101 uint8_t data;102};103 104struct hbm_version {105 uint8_t minor_version;106 uint8_t major_version;107} __packed;108 109struct hbm_host_version_request {110 uint8_t hbm_cmd;111 uint8_t reserved;112 struct hbm_version host_version;113} __packed;114 115struct hbm_host_version_response {116 uint8_t hbm_cmd;117 uint8_t host_version_supported;118 struct hbm_version fw_max_version;119} __packed;120 121struct hbm_host_stop_request {122 uint8_t hbm_cmd;123 uint8_t reason;124 uint8_t reserved[2];125} __packed;126 127struct hbm_host_stop_response {128 uint8_t hbm_cmd;129 uint8_t reserved[3];130} __packed;131 132struct hbm_host_enum_request {133 uint8_t hbm_cmd;134 uint8_t reserved[3];135} __packed;136 137struct hbm_host_enum_response {138 uint8_t hbm_cmd;139 uint8_t reserved[3];140 uint8_t valid_addresses[32];141} __packed;142 143struct ishtp_client_properties {144 guid_t protocol_name;145 uint8_t protocol_version;146 uint8_t max_number_of_connections;147 uint8_t fixed_address;148 uint8_t single_recv_buf;149 uint32_t max_msg_length;150 uint8_t dma_hdr_len;151#define ISHTP_CLIENT_DMA_ENABLED 0x80152 uint8_t reserved4;153 uint8_t reserved5;154 uint8_t reserved6;155} __packed;156 157struct hbm_props_request {158 uint8_t hbm_cmd;159 uint8_t address;160 uint8_t reserved[2];161} __packed;162 163struct hbm_props_response {164 uint8_t hbm_cmd;165 uint8_t address;166 uint8_t status;167 uint8_t reserved[1];168 struct ishtp_client_properties client_properties;169} __packed;170 171/**172 * struct hbm_client_connect_request - connect/disconnect request173 *174 * @hbm_cmd - bus message command header175 * @fw_addr - address of the fw client176 * @host_addr - address of the client in the driver177 * @reserved178 */179struct hbm_client_connect_request {180 uint8_t hbm_cmd;181 uint8_t fw_addr;182 uint8_t host_addr;183 uint8_t reserved;184} __packed;185 186/**187 * struct hbm_client_connect_response - connect/disconnect response188 *189 * @hbm_cmd - bus message command header190 * @fw_addr - address of the fw client191 * @host_addr - address of the client in the driver192 * @status - status of the request193 */194struct hbm_client_connect_response {195 uint8_t hbm_cmd;196 uint8_t fw_addr;197 uint8_t host_addr;198 uint8_t status;199} __packed;200 201 202#define ISHTP_FC_MESSAGE_RESERVED_LENGTH 5203 204struct hbm_flow_control {205 uint8_t hbm_cmd;206 uint8_t fw_addr;207 uint8_t host_addr;208 uint8_t reserved[ISHTP_FC_MESSAGE_RESERVED_LENGTH];209} __packed;210 211struct dma_alloc_notify {212 uint8_t hbm;213 uint8_t status;214 uint8_t reserved[2];215 uint32_t buf_size;216 uint64_t buf_address;217 /* [...] May come more size/address pairs */218} __packed;219 220struct dma_xfer_hbm {221 uint8_t hbm;222 uint8_t fw_client_id;223 uint8_t host_client_id;224 uint8_t reserved;225 uint64_t msg_addr;226 uint32_t msg_length;227 uint32_t reserved2;228} __packed;229 230/* System state */231#define ISHTP_SYSTEM_STATE_CLIENT_ADDR 13232 233#define SYSTEM_STATE_SUBSCRIBE 0x1234#define SYSTEM_STATE_STATUS 0x2235#define SYSTEM_STATE_QUERY_SUBSCRIBERS 0x3236#define SYSTEM_STATE_STATE_CHANGE_REQ 0x4237/*indicates suspend and resume states*/238#define CONNECTED_STANDBY_STATE_BIT (1<<0)239#define SUSPEND_STATE_BIT (1<<1)240 241struct ish_system_states_header {242 uint32_t cmd;243 uint32_t cmd_status; /*responses will have this set*/244} __packed;245 246struct ish_system_states_subscribe {247 struct ish_system_states_header hdr;248 uint32_t states;249} __packed;250 251struct ish_system_states_status {252 struct ish_system_states_header hdr;253 uint32_t supported_states;254 uint32_t states_status;255} __packed;256 257struct ish_system_states_query_subscribers {258 struct ish_system_states_header hdr;259} __packed;260 261struct ish_system_states_state_change_req {262 struct ish_system_states_header hdr;263 uint32_t requested_states;264 uint32_t states_status;265} __packed;266 267/**268 * enum ishtp_hbm_state - host bus message protocol state269 *270 * @ISHTP_HBM_IDLE : protocol not started271 * @ISHTP_HBM_START : start request message was sent272 * @ISHTP_HBM_ENUM_CLIENTS : enumeration request was sent273 * @ISHTP_HBM_CLIENT_PROPERTIES : acquiring clients properties274 */275enum ishtp_hbm_state {276 ISHTP_HBM_IDLE = 0,277 ISHTP_HBM_START,278 ISHTP_HBM_STARTED,279 ISHTP_HBM_ENUM_CLIENTS,280 ISHTP_HBM_CLIENT_PROPERTIES,281 ISHTP_HBM_WORKING,282 ISHTP_HBM_STOPPED,283};284 285static inline void ishtp_hbm_hdr(struct ishtp_msg_hdr *hdr, size_t length)286{287 hdr->host_addr = 0;288 hdr->fw_addr = 0;289 hdr->length = length;290 hdr->msg_complete = 1;291 hdr->reserved = 0;292}293 294int ishtp_hbm_start_req(struct ishtp_device *dev);295int ishtp_hbm_start_wait(struct ishtp_device *dev);296int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev,297 struct ishtp_cl *cl);298int ishtp_hbm_cl_disconnect_req(struct ishtp_device *dev, struct ishtp_cl *cl);299int ishtp_hbm_cl_connect_req(struct ishtp_device *dev, struct ishtp_cl *cl);300void ishtp_hbm_enum_clients_req(struct ishtp_device *dev);301void bh_hbm_work_fn(struct work_struct *work);302void recv_hbm(struct ishtp_device *dev, struct ishtp_msg_hdr *ishtp_hdr);303void recv_fixed_cl_msg(struct ishtp_device *dev,304 struct ishtp_msg_hdr *ishtp_hdr);305void ishtp_hbm_dispatch(struct ishtp_device *dev,306 struct ishtp_bus_message *hdr);307 308void ishtp_query_subscribers(struct ishtp_device *dev);309 310/* Exported I/F */311void ishtp_send_suspend(struct ishtp_device *dev);312void ishtp_send_resume(struct ishtp_device *dev);313 314#endif /* _ISHTP_HBM_H_ */315