Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * ISHTP bus layer messages handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2003-2016, Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "ishtp-dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "hbm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "client.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * ishtp_hbm_fw_cl_allocate() - Allocate FW clients
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * Allocates storage for fw clients
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static void ishtp_hbm_fw_cl_allocate(struct ishtp_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct ishtp_fw_client *clients;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	int b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	/* count how many ISH clients we have */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	for_each_set_bit(b, dev->fw_clients_map, ISHTP_CLIENTS_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		dev->fw_clients_num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	if (dev->fw_clients_num <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	/* allocate storage for fw clients representation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	clients = kcalloc(dev->fw_clients_num, sizeof(struct ishtp_fw_client),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			  GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (!clients) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		dev->dev_state = ISHTP_DEV_RESETTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		ish_hw_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	dev->fw_clients = clients;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * ishtp_hbm_cl_hdr() - construct client hbm header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * @cl: client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * @hbm_cmd: host bus message command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * @buf: buffer for cl header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * @len: buffer length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * Initialize HBM buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static inline void ishtp_hbm_cl_hdr(struct ishtp_cl *cl, uint8_t hbm_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	void *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct ishtp_hbm_cl_cmd *cmd = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	memset(cmd, 0, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	cmd->hbm_cmd = hbm_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	cmd->host_addr = cl->host_client_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	cmd->fw_addr = cl->fw_client_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * ishtp_hbm_cl_addr_equal() - Compare client address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * @cl: client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * @buf: Client command buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * Compare client address with the address in command buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * Return: True if they have the same address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static inline bool ishtp_hbm_cl_addr_equal(struct ishtp_cl *cl, void *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct ishtp_hbm_cl_cmd *cmd = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return cl->host_client_id == cmd->host_addr &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		cl->fw_client_id == cmd->fw_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * ishtp_hbm_start_wait() - Wait for HBM start message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * Wait for HBM start message from firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  * Return: 0 if HBM start is/was received else timeout error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) int ishtp_hbm_start_wait(struct ishtp_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (dev->hbm_state > ISHTP_HBM_START)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	dev_dbg(dev->devc, "Going to wait for ishtp start. hbm_state=%08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		dev->hbm_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	ret = wait_event_interruptible_timeout(dev->wait_hbm_recvd_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 					dev->hbm_state >= ISHTP_HBM_STARTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 					(ISHTP_INTEROP_TIMEOUT * HZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	dev_dbg(dev->devc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		"Woke up from waiting for ishtp start. hbm_state=%08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		dev->hbm_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (ret <= 0 && (dev->hbm_state <= ISHTP_HBM_START)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		dev->hbm_state = ISHTP_HBM_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		dev_err(dev->devc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		"waiting for ishtp start failed. ret=%d hbm_state=%08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			ret, dev->hbm_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * ishtp_hbm_start_req() - Send HBM start message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * Send HBM start message to firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * Return: 0 if success else error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int ishtp_hbm_start_req(struct ishtp_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct ishtp_msg_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct hbm_host_version_request start_req = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	ishtp_hbm_hdr(&hdr, sizeof(start_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	/* host start message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	start_req.hbm_cmd = HOST_START_REQ_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	start_req.host_version.major_version = HBM_MAJOR_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	start_req.host_version.minor_version = HBM_MINOR_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	 * (!) Response to HBM start may be so quick that this thread would get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	 * preempted BEFORE managing to set hbm_state = ISHTP_HBM_START.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	 * So set it at first, change back to ISHTP_HBM_IDLE upon failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	dev->hbm_state = ISHTP_HBM_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (ishtp_write_message(dev, &hdr, &start_req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		dev_err(dev->devc, "version message send failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		dev->dev_state = ISHTP_DEV_RESETTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		dev->hbm_state = ISHTP_HBM_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		ish_hw_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * ishtp_hbm_enum_clients_req() - Send client enum req
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * Send enumeration client request message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  * Return: 0 if success else error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) void ishtp_hbm_enum_clients_req(struct ishtp_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct ishtp_msg_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct hbm_host_enum_request enum_req = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	/* enumerate clients */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	ishtp_hbm_hdr(&hdr, sizeof(enum_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	enum_req.hbm_cmd = HOST_ENUM_REQ_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (ishtp_write_message(dev, &hdr, &enum_req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		dev->dev_state = ISHTP_DEV_RESETTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		dev_err(dev->devc, "enumeration request send failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		ish_hw_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	dev->hbm_state = ISHTP_HBM_ENUM_CLIENTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * ishtp_hbm_prop_req() - Request property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * Request property for a single client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * Return: 0 if success else error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static int ishtp_hbm_prop_req(struct ishtp_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct ishtp_msg_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct hbm_props_request prop_req = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	unsigned long next_client_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	uint8_t client_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	client_num = dev->fw_client_presentation_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	next_client_index = find_next_bit(dev->fw_clients_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		ISHTP_CLIENTS_MAX, dev->fw_client_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	/* We got all client properties */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (next_client_index == ISHTP_CLIENTS_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		dev->hbm_state = ISHTP_HBM_WORKING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		dev->dev_state = ISHTP_DEV_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		for (dev->fw_client_presentation_num = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			dev->fw_client_presentation_num < client_num + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 				++dev->fw_client_presentation_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			/* Add new client device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			ishtp_bus_new_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	dev->fw_clients[client_num].client_id = next_client_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	ishtp_hbm_hdr(&hdr, sizeof(prop_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	prop_req.hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	prop_req.address = next_client_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (ishtp_write_message(dev, &hdr, &prop_req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		dev->dev_state = ISHTP_DEV_RESETTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		dev_err(dev->devc, "properties request send failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		ish_hw_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	dev->fw_client_index = next_client_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * ishtp_hbm_stop_req() - Send HBM stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * Send stop request message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static void ishtp_hbm_stop_req(struct ishtp_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	struct ishtp_msg_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct hbm_host_stop_request stop_req = { 0 } ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	ishtp_hbm_hdr(&hdr, sizeof(stop_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	stop_req.hbm_cmd = HOST_STOP_REQ_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	stop_req.reason = DRIVER_STOP_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	ishtp_write_message(dev, &hdr, &stop_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  * ishtp_hbm_cl_flow_control_req() - Send flow control request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  * @cl: ISHTP client instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  * Send flow control request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  * Return: 0 if success else error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 				  struct ishtp_cl *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	struct ishtp_msg_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	struct hbm_flow_control flow_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	const size_t len = sizeof(flow_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	int	rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	unsigned long	flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	spin_lock_irqsave(&cl->fc_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	ishtp_hbm_hdr(&hdr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	ishtp_hbm_cl_hdr(cl, ISHTP_FLOW_CONTROL_CMD, &flow_ctrl, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	 * Sync possible race when RB recycle and packet receive paths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	 * both try to send an out FC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	if (cl->out_flow_ctrl_creds) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		spin_unlock_irqrestore(&cl->fc_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		return	0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	cl->recv_msg_num_frags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	rv = ishtp_write_message(dev, &hdr, &flow_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (!rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		++cl->out_flow_ctrl_creds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		++cl->out_flow_ctrl_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		cl->ts_out_fc = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		if (cl->ts_rx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			ktime_t ts_diff = ktime_sub(cl->ts_out_fc, cl->ts_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			if (ktime_after(ts_diff, cl->ts_max_fc_delay))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 				cl->ts_max_fc_delay = ts_diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		++cl->err_send_fc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	spin_unlock_irqrestore(&cl->fc_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	return	rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  * ishtp_hbm_cl_disconnect_req() - Send disconnect request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  * @cl: ISHTP client instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  * Send disconnect message to fw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  * Return: 0 if success else error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int ishtp_hbm_cl_disconnect_req(struct ishtp_device *dev, struct ishtp_cl *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	struct ishtp_msg_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	struct hbm_client_connect_request disconn_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	const size_t len = sizeof(disconn_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	ishtp_hbm_hdr(&hdr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	ishtp_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, &disconn_req, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	return ishtp_write_message(dev, &hdr, &disconn_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * ishtp_hbm_cl_disconnect_res() - Get disconnect response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)  * @rs: Response message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)  * Received disconnect response from fw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static void ishtp_hbm_cl_disconnect_res(struct ishtp_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	struct hbm_client_connect_response *rs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	struct ishtp_cl *cl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	unsigned long	flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	spin_lock_irqsave(&dev->cl_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	list_for_each_entry(cl, &dev->cl_list, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		if (!rs->status && ishtp_hbm_cl_addr_equal(cl, rs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			cl->state = ISHTP_CL_DISCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			wake_up_interruptible(&cl->wait_ctrl_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	spin_unlock_irqrestore(&dev->cl_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)  * ishtp_hbm_cl_connect_req() - Send connect request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)  * @cl: client device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  * Send connection request to specific fw client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  * Return: 0 if success else error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) int ishtp_hbm_cl_connect_req(struct ishtp_device *dev, struct ishtp_cl *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	struct ishtp_msg_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	struct hbm_client_connect_request conn_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	const size_t len = sizeof(conn_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	ishtp_hbm_hdr(&hdr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	ishtp_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, &conn_req, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	return ishtp_write_message(dev, &hdr, &conn_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)  * ishtp_hbm_cl_connect_res() - Get connect response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)  * @rs: Response message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  * Received connect response from fw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) static void ishtp_hbm_cl_connect_res(struct ishtp_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	struct hbm_client_connect_response *rs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	struct ishtp_cl *cl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	unsigned long	flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	spin_lock_irqsave(&dev->cl_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	list_for_each_entry(cl, &dev->cl_list, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		if (ishtp_hbm_cl_addr_equal(cl, rs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 			if (!rs->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 				cl->state = ISHTP_CL_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 				cl->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 				cl->state = ISHTP_CL_DISCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 				cl->status = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 			wake_up_interruptible(&cl->wait_ctrl_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	spin_unlock_irqrestore(&dev->cl_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  * ishtp_client_disconnect_request() - Receive disconnect request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  * @disconnect_req: disconnect request structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  * Disconnect request bus message from the fw. Send disconnect response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static void ishtp_hbm_fw_disconnect_req(struct ishtp_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	struct hbm_client_connect_request *disconnect_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	struct ishtp_cl *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	const size_t len = sizeof(struct hbm_client_connect_response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	unsigned long	flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	struct ishtp_msg_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	unsigned char data[4];	/* All HBM messages are 4 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	spin_lock_irqsave(&dev->cl_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	list_for_each_entry(cl, &dev->cl_list, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		if (ishtp_hbm_cl_addr_equal(cl, disconnect_req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 			cl->state = ISHTP_CL_DISCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 			/* send disconnect response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 			ishtp_hbm_hdr(&hdr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 			ishtp_hbm_cl_hdr(cl, CLIENT_DISCONNECT_RES_CMD, data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 				len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			ishtp_write_message(dev, &hdr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	spin_unlock_irqrestore(&dev->cl_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)  * ishtp_hbm_dma_xfer_ack(() - Receive transfer ACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)  * @dma_xfer: HBM transfer message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)  * Receive ack for ISHTP-over-DMA client message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) static void ishtp_hbm_dma_xfer_ack(struct ishtp_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 				   struct dma_xfer_hbm *dma_xfer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	void	*msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	uint64_t	offs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	struct ishtp_msg_hdr	*ishtp_hdr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		(struct ishtp_msg_hdr *)&dev->ishtp_msg_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	unsigned int	msg_offs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	struct ishtp_cl *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	for (msg_offs = 0; msg_offs < ishtp_hdr->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		msg_offs += sizeof(struct dma_xfer_hbm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		offs = dma_xfer->msg_addr - dev->ishtp_host_dma_tx_buf_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		if (offs > dev->ishtp_host_dma_tx_buf_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 			dev_err(dev->devc, "Bad DMA Tx ack message address\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		if (dma_xfer->msg_length >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 				dev->ishtp_host_dma_tx_buf_size - offs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 			dev_err(dev->devc, "Bad DMA Tx ack message size\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		/* logical address of the acked mem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		msg = (unsigned char *)dev->ishtp_host_dma_tx_buf + offs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		ishtp_cl_release_dma_acked_mem(dev, msg, dma_xfer->msg_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		list_for_each_entry(cl, &dev->cl_list, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 			if (cl->fw_client_id == dma_xfer->fw_client_id &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 			    cl->host_client_id == dma_xfer->host_client_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 				 * in case that a single ack may be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 				 * over several dma transfers, and the last msg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 				 * addr was inside the acked memory, but not in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 				 * its start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 				if (cl->last_dma_addr >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 							(unsigned char *)msg &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 						cl->last_dma_addr <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 						(unsigned char *)msg +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 						dma_xfer->msg_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 					cl->last_dma_acked = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 					if (!list_empty(&cl->tx_list.list) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 						cl->ishtp_flow_ctrl_creds) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 						/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 						 * start sending the first msg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 						 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 						ishtp_cl_send_msg(dev, cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		++dma_xfer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)  * ishtp_hbm_dma_xfer() - Receive DMA transfer message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)  * @dma_xfer: HBM transfer message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)  * Receive ISHTP-over-DMA client message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) static void ishtp_hbm_dma_xfer(struct ishtp_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 			       struct dma_xfer_hbm *dma_xfer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	void	*msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	uint64_t	offs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	struct ishtp_msg_hdr	hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	struct ishtp_msg_hdr	*ishtp_hdr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		(struct ishtp_msg_hdr *) &dev->ishtp_msg_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	struct dma_xfer_hbm	*prm = dma_xfer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	unsigned int	msg_offs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	for (msg_offs = 0; msg_offs < ishtp_hdr->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		msg_offs += sizeof(struct dma_xfer_hbm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		offs = dma_xfer->msg_addr - dev->ishtp_host_dma_rx_buf_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		if (offs > dev->ishtp_host_dma_rx_buf_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 			dev_err(dev->devc, "Bad DMA Rx message address\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		if (dma_xfer->msg_length >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 				dev->ishtp_host_dma_rx_buf_size - offs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 			dev_err(dev->devc, "Bad DMA Rx message size\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		msg = dev->ishtp_host_dma_rx_buf + offs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		recv_ishtp_cl_msg_dma(dev, msg, dma_xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		dma_xfer->hbm = DMA_XFER_ACK;	/* Prepare for response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		++dma_xfer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	/* Send DMA_XFER_ACK [...] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	ishtp_hbm_hdr(&hdr, ishtp_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	ishtp_write_message(dev, &hdr, (unsigned char *)prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)  * ishtp_hbm_dispatch() - HBM dispatch function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)  * @hdr: bus message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)  * Bottom half read routine after ISR to handle the read bus message cmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)  * processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) void ishtp_hbm_dispatch(struct ishtp_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 			struct ishtp_bus_message *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	struct ishtp_bus_message *ishtp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	struct ishtp_fw_client *fw_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	struct hbm_host_version_response *version_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	struct hbm_client_connect_response *connect_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	struct hbm_client_connect_response *disconnect_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	struct hbm_client_connect_request *disconnect_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	struct hbm_props_response *props_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	struct hbm_host_enum_response *enum_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	struct ishtp_msg_hdr ishtp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	struct dma_alloc_notify	dma_alloc_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	struct dma_xfer_hbm	*dma_xfer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	ishtp_msg = hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	switch (ishtp_msg->hbm_cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	case HOST_START_RES_CMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		version_res = (struct hbm_host_version_response *)ishtp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		if (!version_res->host_version_supported) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 			dev->version = version_res->fw_max_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 			dev->hbm_state = ISHTP_HBM_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 			ishtp_hbm_stop_req(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		dev->version.major_version = HBM_MAJOR_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 		dev->version.minor_version = HBM_MINOR_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 		if (dev->dev_state == ISHTP_DEV_INIT_CLIENTS &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 				dev->hbm_state == ISHTP_HBM_START) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 			dev->hbm_state = ISHTP_HBM_STARTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 			ishtp_hbm_enum_clients_req(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 			dev_err(dev->devc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 				"reset: wrong host start response\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 			/* BUG: why do we arrive here? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 			ish_hw_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		wake_up_interruptible(&dev->wait_hbm_recvd_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	case CLIENT_CONNECT_RES_CMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		connect_res = (struct hbm_client_connect_response *)ishtp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 		ishtp_hbm_cl_connect_res(dev, connect_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	case CLIENT_DISCONNECT_RES_CMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 		disconnect_res =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 			(struct hbm_client_connect_response *)ishtp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 		ishtp_hbm_cl_disconnect_res(dev, disconnect_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	case HOST_CLIENT_PROPERTIES_RES_CMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		props_res = (struct hbm_props_response *)ishtp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 		fw_client = &dev->fw_clients[dev->fw_client_presentation_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		if (props_res->status || !dev->fw_clients) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 			dev_err(dev->devc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 			"reset: properties response hbm wrong status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 			ish_hw_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 		if (fw_client->client_id != props_res->address) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 			dev_err(dev->devc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 				"reset: host properties response address mismatch [%02X %02X]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 				fw_client->client_id, props_res->address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 			ish_hw_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 		if (dev->dev_state != ISHTP_DEV_INIT_CLIENTS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 			dev->hbm_state != ISHTP_HBM_CLIENT_PROPERTIES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 			dev_err(dev->devc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 				"reset: unexpected properties response\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 			ish_hw_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 		fw_client->props = props_res->client_properties;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		dev->fw_client_index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 		dev->fw_client_presentation_num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		/* request property for the next client */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		ishtp_hbm_prop_req(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 		if (dev->dev_state != ISHTP_DEV_ENABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		if (!ishtp_use_dma_transfer())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		dev_dbg(dev->devc, "Requesting to use DMA\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 		ishtp_cl_alloc_dma_buf(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		if (dev->ishtp_host_dma_rx_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 			const size_t len = sizeof(dma_alloc_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 			memset(&dma_alloc_notify, 0, sizeof(dma_alloc_notify));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 			dma_alloc_notify.hbm = DMA_BUFFER_ALLOC_NOTIFY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 			dma_alloc_notify.buf_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 					dev->ishtp_host_dma_rx_buf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 			dma_alloc_notify.buf_address =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 					dev->ishtp_host_dma_rx_buf_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 			ishtp_hbm_hdr(&ishtp_hdr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 			ishtp_write_message(dev, &ishtp_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 				(unsigned char *)&dma_alloc_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	case HOST_ENUM_RES_CMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 		enum_res = (struct hbm_host_enum_response *) ishtp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		memcpy(dev->fw_clients_map, enum_res->valid_addresses, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 		if (dev->dev_state == ISHTP_DEV_INIT_CLIENTS &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 			dev->hbm_state == ISHTP_HBM_ENUM_CLIENTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 			dev->fw_client_presentation_num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 			dev->fw_client_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 			ishtp_hbm_fw_cl_allocate(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 			dev->hbm_state = ISHTP_HBM_CLIENT_PROPERTIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 			/* first property request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 			ishtp_hbm_prop_req(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 			dev_err(dev->devc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 			      "reset: unexpected enumeration response hbm\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 			ish_hw_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	case HOST_STOP_RES_CMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 		if (dev->hbm_state != ISHTP_HBM_STOPPED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 			dev_err(dev->devc, "unexpected stop response\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 		dev->dev_state = ISHTP_DEV_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 		dev_info(dev->devc, "reset: FW stop response\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 		ish_hw_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	case CLIENT_DISCONNECT_REQ_CMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 		/* search for client */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		disconnect_req =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 			(struct hbm_client_connect_request *)ishtp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 		ishtp_hbm_fw_disconnect_req(dev, disconnect_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	case FW_STOP_REQ_CMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 		dev->hbm_state = ISHTP_HBM_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	case DMA_BUFFER_ALLOC_RESPONSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 		dev->ishtp_host_dma_enabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	case DMA_XFER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 		dma_xfer = (struct dma_xfer_hbm *)ishtp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 		if (!dev->ishtp_host_dma_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 			dev_err(dev->devc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 				"DMA XFER requested but DMA is not enabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 		ishtp_hbm_dma_xfer(dev, dma_xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	case DMA_XFER_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 		dma_xfer = (struct dma_xfer_hbm *)ishtp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 		if (!dev->ishtp_host_dma_enabled ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 		    !dev->ishtp_host_dma_tx_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 			dev_err(dev->devc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 				"DMA XFER acked but DMA Tx is not enabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 		ishtp_hbm_dma_xfer_ack(dev, dma_xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 		dev_err(dev->devc, "unknown HBM: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 			(unsigned int)ishtp_msg->hbm_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)  * bh_hbm_work_fn() - HBM work function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)  * @work: work struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)  * Bottom half processing work function (instead of thread handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)  * for processing hbm messages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) void	bh_hbm_work_fn(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	unsigned long	flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	struct ishtp_device	*dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	unsigned char	hbm[IPC_PAYLOAD_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	dev = container_of(work, struct ishtp_device, bh_hbm_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	spin_lock_irqsave(&dev->rd_msg_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	if (dev->rd_msg_fifo_head != dev->rd_msg_fifo_tail) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 		memcpy(hbm, dev->rd_msg_fifo + dev->rd_msg_fifo_head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 			IPC_PAYLOAD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 		dev->rd_msg_fifo_head =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 			(dev->rd_msg_fifo_head + IPC_PAYLOAD_SIZE) %
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 			(RD_INT_FIFO_SIZE * IPC_PAYLOAD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 		spin_unlock_irqrestore(&dev->rd_msg_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 		ishtp_hbm_dispatch(dev, (struct ishtp_bus_message *)hbm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 		spin_unlock_irqrestore(&dev->rd_msg_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)  * recv_hbm() - Receive HBM message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)  * @ishtp_hdr: received bus message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)  * Receive and process ISHTP bus messages in ISR context. This will schedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)  * work function to process message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) void	recv_hbm(struct ishtp_device *dev, struct ishtp_msg_hdr *ishtp_hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 	uint8_t	rd_msg_buf[ISHTP_RD_MSG_BUF_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	struct ishtp_bus_message	*ishtp_msg =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 		(struct ishtp_bus_message *)rd_msg_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 	unsigned long	flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 	dev->ops->ishtp_read(dev, rd_msg_buf, ishtp_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 	/* Flow control - handle in place */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	if (ishtp_msg->hbm_cmd == ISHTP_FLOW_CONTROL_CMD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 		struct hbm_flow_control *flow_control =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 			(struct hbm_flow_control *)ishtp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 		struct ishtp_cl *cl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 		unsigned long	flags, tx_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 		spin_lock_irqsave(&dev->cl_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 		list_for_each_entry(cl, &dev->cl_list, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 			if (cl->host_client_id == flow_control->host_addr &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 					cl->fw_client_id ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 					flow_control->fw_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 				 * NOTE: It's valid only for counting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 				 * flow-control implementation to receive a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 				 * FC in the middle of sending. Meanwhile not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 				 * supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 				if (cl->ishtp_flow_ctrl_creds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 					dev_err(dev->devc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 					 "recv extra FC from FW client %u (host client %u) (FC count was %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 					 (unsigned int)cl->fw_client_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 					 (unsigned int)cl->host_client_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 					 cl->ishtp_flow_ctrl_creds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 				else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 					++cl->ishtp_flow_ctrl_creds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 					++cl->ishtp_flow_ctrl_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 					cl->last_ipc_acked = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 					spin_lock_irqsave(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 							&cl->tx_list_spinlock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 							tx_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 					if (!list_empty(&cl->tx_list.list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 						/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 						 * start sending the first msg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 						 *	= the callback function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 						 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 						spin_unlock_irqrestore(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 							&cl->tx_list_spinlock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 							tx_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 						ishtp_cl_send_msg(dev, cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 					} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 						spin_unlock_irqrestore(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 							&cl->tx_list_spinlock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 							tx_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 		spin_unlock_irqrestore(&dev->cl_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 		goto	eoi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 	 * Some messages that are safe for ISR processing and important
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	 * to be done "quickly" and in-order, go here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 	if (ishtp_msg->hbm_cmd == CLIENT_CONNECT_RES_CMD ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 			ishtp_msg->hbm_cmd == CLIENT_DISCONNECT_RES_CMD ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 			ishtp_msg->hbm_cmd == CLIENT_DISCONNECT_REQ_CMD ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 			ishtp_msg->hbm_cmd == DMA_XFER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 		ishtp_hbm_dispatch(dev, ishtp_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 		goto	eoi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 	 * All other HBMs go here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 	 * We schedule HBMs for processing serially by using system wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 	 * possibly there will be multiple HBMs scheduled at the same time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	spin_lock_irqsave(&dev->rd_msg_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 	if ((dev->rd_msg_fifo_tail + IPC_PAYLOAD_SIZE) %
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 			(RD_INT_FIFO_SIZE * IPC_PAYLOAD_SIZE) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 			dev->rd_msg_fifo_head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 		spin_unlock_irqrestore(&dev->rd_msg_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 		dev_err(dev->devc, "BH buffer overflow, dropping HBM %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 			(unsigned int)ishtp_msg->hbm_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 		goto	eoi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 	memcpy(dev->rd_msg_fifo + dev->rd_msg_fifo_tail, ishtp_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 		ishtp_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 	dev->rd_msg_fifo_tail = (dev->rd_msg_fifo_tail + IPC_PAYLOAD_SIZE) %
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 		(RD_INT_FIFO_SIZE * IPC_PAYLOAD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 	spin_unlock_irqrestore(&dev->rd_msg_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 	schedule_work(&dev->bh_hbm_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) eoi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)  * recv_fixed_cl_msg() - Receive fixed client message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)  * @ishtp_hdr: received bus message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)  * Receive and process ISHTP fixed client messages (address == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)  * in ISR context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) void recv_fixed_cl_msg(struct ishtp_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 	struct ishtp_msg_hdr *ishtp_hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 	uint8_t rd_msg_buf[ISHTP_RD_MSG_BUF_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 	dev->print_log(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 		"%s() got fixed client msg from client #%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 		__func__, ishtp_hdr->fw_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 	dev->ops->ishtp_read(dev, rd_msg_buf, ishtp_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 	if (ishtp_hdr->fw_addr == ISHTP_SYSTEM_STATE_CLIENT_ADDR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 		struct ish_system_states_header *msg_hdr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 			(struct ish_system_states_header *)rd_msg_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 		if (msg_hdr->cmd == SYSTEM_STATE_SUBSCRIBE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 			ishtp_send_resume(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 		/* if FW request arrived here, the system is not suspended */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 			dev_err(dev->devc, "unknown fixed client msg [%02X]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 				msg_hdr->cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)  * fix_cl_hdr() - Initialize fixed client header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)  * @hdr: message header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)  * @length: length of message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900)  * @cl_addr: Client address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)  * Initialize message header for fixed client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) static inline void fix_cl_hdr(struct ishtp_msg_hdr *hdr, size_t length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) 	uint8_t cl_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) 	hdr->host_addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) 	hdr->fw_addr = cl_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) 	hdr->length = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) 	hdr->msg_complete = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) 	hdr->reserved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) /*** Suspend and resume notification ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) static uint32_t current_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) static uint32_t supported_states = 0 | SUSPEND_STATE_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)  * ishtp_send_suspend() - Send suspend message to FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)  * Send suspend message to FW. This is useful for system freeze (non S3) case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) void ishtp_send_suspend(struct ishtp_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) 	struct ishtp_msg_hdr	ishtp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) 	struct ish_system_states_status state_status_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) 	const size_t len = sizeof(struct ish_system_states_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) 	fix_cl_hdr(&ishtp_hdr, len, ISHTP_SYSTEM_STATE_CLIENT_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) 	memset(&state_status_msg, 0, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) 	state_status_msg.hdr.cmd = SYSTEM_STATE_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) 	state_status_msg.supported_states = supported_states;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) 	current_state |= SUSPEND_STATE_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) 	dev->print_log(dev, "%s() sends SUSPEND notification\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) 	state_status_msg.states_status = current_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) 	ishtp_write_message(dev, &ishtp_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) 		(unsigned char *)&state_status_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) EXPORT_SYMBOL(ishtp_send_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)  * ishtp_send_resume() - Send resume message to FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)  * Send resume message to FW. This is useful for system freeze (non S3) case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) void ishtp_send_resume(struct ishtp_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) 	struct ishtp_msg_hdr	ishtp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) 	struct ish_system_states_status state_status_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) 	const size_t len = sizeof(struct ish_system_states_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) 	fix_cl_hdr(&ishtp_hdr, len, ISHTP_SYSTEM_STATE_CLIENT_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) 	memset(&state_status_msg, 0, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) 	state_status_msg.hdr.cmd = SYSTEM_STATE_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) 	state_status_msg.supported_states = supported_states;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) 	current_state &= ~SUSPEND_STATE_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) 	dev->print_log(dev, "%s() sends RESUME notification\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) 	state_status_msg.states_status = current_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) 	ishtp_write_message(dev, &ishtp_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) 		(unsigned char *)&state_status_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) EXPORT_SYMBOL(ishtp_send_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)  * ishtp_query_subscribers() - Send query subscribers message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)  * @dev: ISHTP device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)  * Send message to query subscribers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) void ishtp_query_subscribers(struct ishtp_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) 	struct ishtp_msg_hdr	ishtp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) 	struct ish_system_states_query_subscribers query_subscribers_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) 	const size_t len = sizeof(struct ish_system_states_query_subscribers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) 	fix_cl_hdr(&ishtp_hdr, len, ISHTP_SYSTEM_STATE_CLIENT_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) 	memset(&query_subscribers_msg, 0, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) 	query_subscribers_msg.hdr.cmd = SYSTEM_STATE_QUERY_SUBSCRIBERS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) 	ishtp_write_message(dev, &ishtp_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) 		(unsigned char *)&query_subscribers_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) }