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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2018-2020 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/bitfield.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/remoteproc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/qcom_scm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/soc/qcom/mdt_loader.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "ipa.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "ipa_clock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "ipa_data.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "ipa_endpoint.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include "ipa_cmd.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "ipa_reg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "ipa_mem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include "ipa_table.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "ipa_modem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include "ipa_uc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include "ipa_interrupt.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include "gsi_trans.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * DOC: The IP Accelerator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * This driver supports the Qualcomm IP Accelerator (IPA), which is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * networking component found in many Qualcomm SoCs.  The IPA is connected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * to the application processor (AP), but is also connected (and partially
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * controlled by) other "execution environments" (EEs), such as a modem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * The IPA is the conduit between the AP and the modem that carries network
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * traffic.  This driver presents a network interface representing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * connection of the modem to external (e.g. LTE) networks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * The IPA provides protocol checksum calculation, offloading this work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * from the AP.  The IPA offers additional functionality, including routing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * filtering, and NAT support, but that more advanced functionality is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * currently supported.  Despite that, some resources--including routing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * tables and filter tables--are defined in this driver because they must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * be initialized even when the advanced hardware features are not used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * There are two distinct layers that implement the IPA hardware, and this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * is reflected in the organization of the driver.  The generic software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * interface (GSI) is an integral component of the IPA, providing a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * well-defined communication layer between the AP subsystem and the IPA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * core.  The GSI implements a set of "channels" used for communication
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * between the AP and the IPA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * The IPA layer uses GSI channels to implement its "endpoints".  And while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * a GSI channel carries data between the AP and the IPA, a pair of IPA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * endpoints is used to carry traffic between two EEs.  Specifically, the main
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * modem network interface is implemented by two pairs of endpoints:  a TX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * endpoint on the AP coupled with an RX endpoint on the modem; and another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * RX endpoint on the AP receiving data from a TX endpoint on the modem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) /* The name of the GSI firmware file relative to /lib/firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #define IPA_FWS_PATH		"ipa_fws.mdt"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #define IPA_PAS_ID		15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * ipa_suspend_handler() - Handle the suspend IPA interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * @ipa:	IPA pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * @irq_id:	IPA interrupt type (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * If an RX endpoint is in suspend state, and the IPA has a packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * destined for that endpoint, the IPA generates a SUSPEND interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * to inform the AP that it should resume the endpoint.  If we get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * one of these interrupts we just resume everything.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static void ipa_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	/* Just report the event, and let system resume handle the rest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	 * More than one endpoint could signal this; if so, ignore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	 * all but the first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (!test_and_set_bit(IPA_FLAG_RESUMED, ipa->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		pm_wakeup_dev_event(&ipa->pdev->dev, 0, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	/* Acknowledge/clear the suspend interrupt on all endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	ipa_interrupt_suspend_clear_all(ipa->interrupt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * ipa_setup() - Set up IPA hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * @ipa:	IPA pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * Perform initialization that requires issuing immediate commands on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * the command TX endpoint.  If the modem is doing GSI firmware load
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * and initialization, this function will be called when an SMP2P
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * interrupt has been signaled by the modem.  Otherwise it will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * called from ipa_probe() after GSI firmware has been successfully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * loaded, authenticated, and started by Trust Zone.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int ipa_setup(struct ipa *ipa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct ipa_endpoint *exception_endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct ipa_endpoint *command_endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct device *dev = &ipa->pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	/* Setup for IPA v3.5.1 has some slight differences */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	ret = gsi_setup(&ipa->gsi, ipa->version == IPA_VERSION_3_5_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	ipa->interrupt = ipa_interrupt_setup(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (IS_ERR(ipa->interrupt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		ret = PTR_ERR(ipa->interrupt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		goto err_gsi_teardown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	ipa_interrupt_add(ipa->interrupt, IPA_IRQ_TX_SUSPEND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			  ipa_suspend_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	ipa_uc_setup(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	ret = device_init_wakeup(dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		goto err_uc_teardown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	ipa_endpoint_setup(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/* We need to use the AP command TX endpoint to perform other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	 * initialization, so we enable first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	command_endpoint = ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	ret = ipa_endpoint_enable_one(command_endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		goto err_endpoint_teardown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	ret = ipa_mem_setup(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		goto err_command_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	ret = ipa_table_setup(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		goto err_mem_teardown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	/* Enable the exception handling endpoint, and tell the hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	 * to use it by default.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	exception_endpoint = ipa->name_map[IPA_ENDPOINT_AP_LAN_RX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	ret = ipa_endpoint_enable_one(exception_endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		goto err_table_teardown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	ipa_endpoint_default_route_set(ipa, exception_endpoint->endpoint_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	/* We're all set.  Now prepare for communication with the modem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	ret = ipa_modem_setup(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		goto err_default_route_clear;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	ipa->setup_complete = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	dev_info(dev, "IPA driver setup completed successfully\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) err_default_route_clear:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	ipa_endpoint_default_route_clear(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	ipa_endpoint_disable_one(exception_endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) err_table_teardown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	ipa_table_teardown(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) err_mem_teardown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	ipa_mem_teardown(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) err_command_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	ipa_endpoint_disable_one(command_endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) err_endpoint_teardown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	ipa_endpoint_teardown(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	(void)device_init_wakeup(dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) err_uc_teardown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	ipa_uc_teardown(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	ipa_interrupt_remove(ipa->interrupt, IPA_IRQ_TX_SUSPEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	ipa_interrupt_teardown(ipa->interrupt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) err_gsi_teardown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	gsi_teardown(&ipa->gsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * ipa_teardown() - Inverse of ipa_setup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * @ipa:	IPA pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static void ipa_teardown(struct ipa *ipa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct ipa_endpoint *exception_endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	struct ipa_endpoint *command_endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	ipa_modem_teardown(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	ipa_endpoint_default_route_clear(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	exception_endpoint = ipa->name_map[IPA_ENDPOINT_AP_LAN_RX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	ipa_endpoint_disable_one(exception_endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	ipa_table_teardown(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	ipa_mem_teardown(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	command_endpoint = ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	ipa_endpoint_disable_one(command_endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	ipa_endpoint_teardown(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	(void)device_init_wakeup(&ipa->pdev->dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	ipa_uc_teardown(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	ipa_interrupt_remove(ipa->interrupt, IPA_IRQ_TX_SUSPEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	ipa_interrupt_teardown(ipa->interrupt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	gsi_teardown(&ipa->gsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* Configure QMB Core Master Port selection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static void ipa_hardware_config_comp(struct ipa *ipa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	/* Nothing to configure for IPA v3.5.1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (ipa->version == IPA_VERSION_3_5_1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	val = ioread32(ipa->reg_virt + IPA_REG_COMP_CFG_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (ipa->version == IPA_VERSION_4_0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		val &= ~IPA_QMB_SELECT_CONS_EN_FMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		val &= ~IPA_QMB_SELECT_PROD_EN_FMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		val &= ~IPA_QMB_SELECT_GLOBAL_EN_FMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	} else  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		val |= GSI_MULTI_AXI_MASTERS_DIS_FMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	val |= GSI_MULTI_INORDER_RD_DIS_FMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	val |= GSI_MULTI_INORDER_WR_DIS_FMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	iowrite32(val, ipa->reg_virt + IPA_REG_COMP_CFG_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* Configure DDR and PCIe max read/write QSB values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static void ipa_hardware_config_qsb(struct ipa *ipa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	/* QMB_0 represents DDR; QMB_1 represents PCIe (not present in 4.2) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	val = u32_encode_bits(8, GEN_QMB_0_MAX_WRITES_FMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (ipa->version == IPA_VERSION_4_2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		val |= u32_encode_bits(0, GEN_QMB_1_MAX_WRITES_FMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		val |= u32_encode_bits(4, GEN_QMB_1_MAX_WRITES_FMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	iowrite32(val, ipa->reg_virt + IPA_REG_QSB_MAX_WRITES_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (ipa->version == IPA_VERSION_3_5_1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		val = u32_encode_bits(8, GEN_QMB_0_MAX_READS_FMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		val |= u32_encode_bits(12, GEN_QMB_1_MAX_READS_FMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		val = u32_encode_bits(12, GEN_QMB_0_MAX_READS_FMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		if (ipa->version == IPA_VERSION_4_2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			val |= u32_encode_bits(0, GEN_QMB_1_MAX_READS_FMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			val |= u32_encode_bits(12, GEN_QMB_1_MAX_READS_FMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		/* GEN_QMB_0_MAX_READS_BEATS is 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		/* GEN_QMB_1_MAX_READS_BEATS is 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	iowrite32(val, ipa->reg_virt + IPA_REG_QSB_MAX_READS_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static void ipa_idle_indication_cfg(struct ipa *ipa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				    u32 enter_idle_debounce_thresh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				    bool const_non_idle_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	u32 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	val = u32_encode_bits(enter_idle_debounce_thresh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			      ENTER_IDLE_DEBOUNCE_THRESH_FMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (const_non_idle_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		val |= CONST_NON_IDLE_ENABLE_FMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	offset = ipa_reg_idle_indication_cfg_offset(ipa->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	iowrite32(val, ipa->reg_virt + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)  * ipa_hardware_dcd_config() - Enable dynamic clock division on IPA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)  * @ipa:	IPA pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  * Configures when the IPA signals it is idle to the global clock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  * controller, which can respond by scalling down the clock to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)  * save power.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static void ipa_hardware_dcd_config(struct ipa *ipa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	/* Recommended values for IPA 3.5 according to IPA HPG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	ipa_idle_indication_cfg(ipa, 256, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static void ipa_hardware_dcd_deconfig(struct ipa *ipa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	/* Power-on reset values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	ipa_idle_indication_cfg(ipa, 0, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  * ipa_hardware_config() - Primitive hardware initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * @ipa:	IPA pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static void ipa_hardware_config(struct ipa *ipa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	u32 granularity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	/* Fill in backward-compatibility register, based on version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	val = ipa_reg_bcr_val(ipa->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	iowrite32(val, ipa->reg_virt + IPA_REG_BCR_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (ipa->version != IPA_VERSION_3_5_1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		/* Enable open global clocks (hardware workaround) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		val = GLOBAL_FMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		val |= GLOBAL_2X_CLK_FMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		iowrite32(val, ipa->reg_virt + IPA_REG_CLKON_CFG_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		/* Disable PA mask to allow HOLB drop (hardware workaround) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		val = ioread32(ipa->reg_virt + IPA_REG_TX_CFG_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		val &= ~PA_MASK_EN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		iowrite32(val, ipa->reg_virt + IPA_REG_TX_CFG_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	ipa_hardware_config_comp(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	/* Configure system bus limits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	ipa_hardware_config_qsb(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	/* Configure aggregation granularity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	val = ioread32(ipa->reg_virt + IPA_REG_COUNTER_CFG_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	granularity = ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	val = u32_encode_bits(granularity, AGGR_GRANULARITY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	iowrite32(val, ipa->reg_virt + IPA_REG_COUNTER_CFG_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	/* Disable hashed IPv4 and IPv6 routing and filtering for IPA v4.2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	if (ipa->version == IPA_VERSION_4_2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		iowrite32(0, ipa->reg_virt + IPA_REG_FILT_ROUT_HASH_EN_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	/* Enable dynamic clock division */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	ipa_hardware_dcd_config(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  * ipa_hardware_deconfig() - Inverse of ipa_hardware_config()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  * @ipa:	IPA pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  * This restores the power-on reset values (even if they aren't different)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) static void ipa_hardware_deconfig(struct ipa *ipa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	/* Mostly we just leave things as we set them. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	ipa_hardware_dcd_deconfig(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) #ifdef IPA_VALIDATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /* # IPA resources used based on version (see IPA_RESOURCE_GROUP_COUNT) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static int ipa_resource_group_count(struct ipa *ipa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	switch (ipa->version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	case IPA_VERSION_3_5_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		return 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	case IPA_VERSION_4_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	case IPA_VERSION_4_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		return 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	case IPA_VERSION_4_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) static bool ipa_resource_limits_valid(struct ipa *ipa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 				      const struct ipa_resource_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	u32 group_count = ipa_resource_group_count(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	u32 j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	if (!group_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	/* Return an error if a non-zero resource group limit is specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	 * for a resource not supported by hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	for (i = 0; i < data->resource_src_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		const struct ipa_resource_src *resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		resource = &data->resource_src[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		for (j = group_count; j < IPA_RESOURCE_GROUP_COUNT; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			if (resource->limits[j].min || resource->limits[j].max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 				return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	for (i = 0; i < data->resource_dst_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		const struct ipa_resource_dst *resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		resource = &data->resource_dst[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		for (j = group_count; j < IPA_RESOURCE_GROUP_COUNT; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			if (resource->limits[j].min || resource->limits[j].max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 				return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) #else /* !IPA_VALIDATION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static bool ipa_resource_limits_valid(struct ipa *ipa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 				      const struct ipa_resource_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) #endif /* !IPA_VALIDATION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) ipa_resource_config_common(struct ipa *ipa, u32 offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 			   const struct ipa_resource_limits *xlimits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			   const struct ipa_resource_limits *ylimits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	val = u32_encode_bits(xlimits->min, X_MIN_LIM_FMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	val |= u32_encode_bits(xlimits->max, X_MAX_LIM_FMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	val |= u32_encode_bits(ylimits->min, Y_MIN_LIM_FMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	val |= u32_encode_bits(ylimits->max, Y_MAX_LIM_FMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	iowrite32(val, ipa->reg_virt + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static void ipa_resource_config_src_01(struct ipa *ipa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 				       const struct ipa_resource_src *resource)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	u32 offset = IPA_REG_SRC_RSRC_GRP_01_RSRC_TYPE_N_OFFSET(resource->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	ipa_resource_config_common(ipa, offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 				   &resource->limits[0], &resource->limits[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) static void ipa_resource_config_src_23(struct ipa *ipa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 				       const struct ipa_resource_src *resource)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	u32 offset = IPA_REG_SRC_RSRC_GRP_23_RSRC_TYPE_N_OFFSET(resource->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	ipa_resource_config_common(ipa, offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 				   &resource->limits[2], &resource->limits[3]);
^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) static void ipa_resource_config_dst_01(struct ipa *ipa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 				       const struct ipa_resource_dst *resource)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	u32 offset = IPA_REG_DST_RSRC_GRP_01_RSRC_TYPE_N_OFFSET(resource->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	ipa_resource_config_common(ipa, offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 				   &resource->limits[0], &resource->limits[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static void ipa_resource_config_dst_23(struct ipa *ipa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 				       const struct ipa_resource_dst *resource)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	u32 offset = IPA_REG_DST_RSRC_GRP_23_RSRC_TYPE_N_OFFSET(resource->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	ipa_resource_config_common(ipa, offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 				   &resource->limits[2], &resource->limits[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) ipa_resource_config(struct ipa *ipa, const struct ipa_resource_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	if (!ipa_resource_limits_valid(ipa, data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	for (i = 0; i < data->resource_src_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		ipa_resource_config_src_01(ipa, &data->resource_src[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		ipa_resource_config_src_23(ipa, &data->resource_src[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	for (i = 0; i < data->resource_dst_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		ipa_resource_config_dst_01(ipa, &data->resource_dst[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		ipa_resource_config_dst_23(ipa, &data->resource_dst[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) static void ipa_resource_deconfig(struct ipa *ipa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	/* Nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)  * ipa_config() - Configure IPA hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)  * @ipa:	IPA pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)  * @data:	IPA configuration data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)  * Perform initialization requiring IPA clock to be enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) static int ipa_config(struct ipa *ipa, const struct ipa_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	/* Get a clock reference to allow initialization.  This reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	 * is held after initialization completes, and won't get dropped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	 * unless/until a system suspend request arrives.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	ipa_clock_get(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	ipa_hardware_config(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	ret = ipa_endpoint_config(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		goto err_hardware_deconfig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	ret = ipa_mem_config(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		goto err_endpoint_deconfig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	ipa_table_config(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	/* Assign resource limitation to each group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	ret = ipa_resource_config(ipa, data->resource_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		goto err_table_deconfig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	ret = ipa_modem_config(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		goto err_resource_deconfig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) err_resource_deconfig:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	ipa_resource_deconfig(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) err_table_deconfig:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	ipa_table_deconfig(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	ipa_mem_deconfig(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) err_endpoint_deconfig:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	ipa_endpoint_deconfig(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) err_hardware_deconfig:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	ipa_hardware_deconfig(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	ipa_clock_put(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)  * ipa_deconfig() - Inverse of ipa_config()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)  * @ipa:	IPA pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) static void ipa_deconfig(struct ipa *ipa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	ipa_modem_deconfig(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	ipa_resource_deconfig(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	ipa_table_deconfig(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	ipa_mem_deconfig(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	ipa_endpoint_deconfig(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	ipa_hardware_deconfig(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	ipa_clock_put(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static int ipa_firmware_load(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	const struct firmware *fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	struct device_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	struct resource res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	phys_addr_t phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	ssize_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	void *virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	node = of_parse_phandle(dev->of_node, "memory-region", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	if (!node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		dev_err(dev, "DT error getting \"memory-region\" property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	ret = of_address_to_resource(node, 0, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	of_node_put(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 		dev_err(dev, "error %d getting \"memory-region\" resource\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	ret = request_firmware(&fw, IPA_FWS_PATH, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		dev_err(dev, "error %d requesting \"%s\"\n", ret, IPA_FWS_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	phys = res.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	size = (size_t)resource_size(&res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	virt = memremap(phys, size, MEMREMAP_WC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	if (!virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 		dev_err(dev, "unable to remap firmware memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 		goto out_release_firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	ret = qcom_mdt_load(dev, fw, IPA_FWS_PATH, IPA_PAS_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 			    virt, phys, size, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		dev_err(dev, "error %d loading \"%s\"\n", ret, IPA_FWS_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	else if ((ret = qcom_scm_pas_auth_and_reset(IPA_PAS_ID)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		dev_err(dev, "error %d authenticating \"%s\"\n", ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 			IPA_FWS_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	memunmap(virt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) out_release_firmware:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) static const struct of_device_id ipa_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		.compatible	= "qcom,sdm845-ipa",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		.data		= &ipa_data_sdm845,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 		.compatible	= "qcom,sc7180-ipa",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 		.data		= &ipa_data_sc7180,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) MODULE_DEVICE_TABLE(of, ipa_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) static phandle of_property_read_phandle(const struct device_node *np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 					const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)         struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)         int len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)         prop = of_find_property(np, name, &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)         if (!prop || len != sizeof(__be32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)                 return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)         return be32_to_cpup(prop->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) /* Check things that can be validated at build time.  This just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)  * groups these things BUILD_BUG_ON() calls don't clutter the rest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)  * of the code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)  * */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) static void ipa_validate_build(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) #ifdef IPA_VALIDATE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	/* We assume we're working on 64-bit hardware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	BUILD_BUG_ON(!IS_ENABLED(CONFIG_64BIT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	/* Code assumes the EE ID for the AP is 0 (zeroed structure field) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	BUILD_BUG_ON(GSI_EE_AP != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	/* There's no point if we have no channels or event rings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	BUILD_BUG_ON(!GSI_CHANNEL_COUNT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	BUILD_BUG_ON(!GSI_EVT_RING_COUNT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	/* GSI hardware design limits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	BUILD_BUG_ON(GSI_CHANNEL_COUNT_MAX > 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	BUILD_BUG_ON(GSI_EVT_RING_COUNT_MAX > 31);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	/* The number of TREs in a transaction is limited by the channel's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	 * TLV FIFO size.  A transaction structure uses 8-bit fields
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	 * to represents the number of TREs it has allocated and used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	BUILD_BUG_ON(GSI_TLV_MAX > U8_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	/* Exceeding 128 bytes makes the transaction pool *much* larger */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	BUILD_BUG_ON(sizeof(struct gsi_trans) > 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	/* This is used as a divisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	BUILD_BUG_ON(!IPA_AGGR_GRANULARITY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	/* Aggregation granularity value can't be 0, and must fit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	BUILD_BUG_ON(!ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	BUILD_BUG_ON(ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 			field_max(AGGR_GRANULARITY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) #endif /* IPA_VALIDATE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)  * ipa_probe() - IPA platform driver probe function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)  * @pdev:	Platform device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)  * Return:	0 if successful, or a negative error code (possibly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)  *		EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)  * This is the main entry point for the IPA driver.  Initialization proceeds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)  * in several stages:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)  *   - The "init" stage involves activities that can be initialized without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)  *     access to the IPA hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)  *   - The "config" stage requires the IPA clock to be active so IPA registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)  *     can be accessed, but does not require the use of IPA immediate commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)  *   - The "setup" stage uses IPA immediate commands, and so requires the GSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)  *     layer to be initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)  * A Boolean Device Tree "modem-init" property determines whether GSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)  * initialization will be performed by the AP (Trust Zone) or the modem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)  * If the AP does GSI initialization, the setup phase is entered after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)  * this has completed successfully.  Otherwise the modem initializes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)  * the GSI layer and signals it has finished by sending an SMP2P interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)  * to the AP; this triggers the start if IPA setup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) static int ipa_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	const struct ipa_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	struct ipa_clock *clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	struct rproc *rproc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	bool modem_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	bool modem_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	struct ipa *ipa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	bool prefetch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	phandle ph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	ipa_validate_build();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	/* If we need Trust Zone, make sure it's available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	modem_init = of_property_read_bool(dev->of_node, "modem-init");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	if (!modem_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 		if (!qcom_scm_is_available())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 			return -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	/* We rely on remoteproc to tell us about modem state changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	ph = of_property_read_phandle(dev->of_node, "modem-remoteproc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	if (!ph) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 		dev_err(dev, "DT missing \"modem-remoteproc\" property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	rproc = rproc_get_by_phandle(ph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	if (!rproc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 		return -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	/* The clock and interconnects might not be ready when we're
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	 * probed, so might return -EPROBE_DEFER.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	clock = ipa_clock_init(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	if (IS_ERR(clock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 		ret = PTR_ERR(clock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 		goto err_rproc_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 	/* No more EPROBE_DEFER.  Get our configuration data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 	data = of_device_get_match_data(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 	if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 		/* This is really IPA_VALIDATE (should never happen) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 		dev_err(dev, "matched hardware not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 		ret = -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 		goto err_clock_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	/* Allocate and initialize the IPA structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 	ipa = kzalloc(sizeof(*ipa), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	if (!ipa) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 		goto err_clock_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	ipa->pdev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 	dev_set_drvdata(dev, ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	ipa->modem_rproc = rproc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 	ipa->clock = clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	ipa->version = data->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 	ret = ipa_reg_init(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 		goto err_kfree_ipa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	ret = ipa_mem_init(ipa, data->mem_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 		goto err_reg_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	/* GSI v2.0+ (IPA v4.0+) uses prefetch for the command channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	prefetch = ipa->version != IPA_VERSION_3_5_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	/* IPA v4.2 requires the AP to allocate channels for the modem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 	modem_alloc = ipa->version == IPA_VERSION_4_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 	ret = gsi_init(&ipa->gsi, pdev, prefetch, data->endpoint_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 		       data->endpoint_data, modem_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 		goto err_mem_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 	/* Result is a non-zero mask endpoints that support filtering */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 	ipa->filter_map = ipa_endpoint_init(ipa, data->endpoint_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 					    data->endpoint_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	if (!ipa->filter_map) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 		goto err_gsi_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 	ret = ipa_table_init(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 		goto err_endpoint_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 	ret = ipa_modem_init(ipa, modem_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 		goto err_table_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 	ret = ipa_config(ipa, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 		goto err_modem_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 	dev_info(dev, "IPA driver initialized");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 	/* If the modem is doing early initialization, it will trigger a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 	 * call to ipa_setup() call when it has finished.  In that case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 	 * we're done here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 	if (modem_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 	/* Otherwise we need to load the firmware and have Trust Zone validate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 	 * and install it.  If that succeeds we can proceed with setup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 	ret = ipa_firmware_load(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 		goto err_deconfig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 	ret = ipa_setup(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 		goto err_deconfig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) err_deconfig:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 	ipa_deconfig(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) err_modem_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 	ipa_modem_exit(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) err_table_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 	ipa_table_exit(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) err_endpoint_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	ipa_endpoint_exit(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) err_gsi_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 	gsi_exit(&ipa->gsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) err_mem_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 	ipa_mem_exit(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) err_reg_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 	ipa_reg_exit(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) err_kfree_ipa:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 	kfree(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) err_clock_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 	ipa_clock_exit(clock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) err_rproc_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 	rproc_put(rproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) static int ipa_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 	struct ipa *ipa = dev_get_drvdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 	struct rproc *rproc = ipa->modem_rproc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 	struct ipa_clock *clock = ipa->clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 	if (ipa->setup_complete) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 		ret = ipa_modem_stop(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 		ipa_teardown(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 	ipa_deconfig(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 	ipa_modem_exit(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 	ipa_table_exit(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 	ipa_endpoint_exit(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 	gsi_exit(&ipa->gsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 	ipa_mem_exit(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 	ipa_reg_exit(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 	kfree(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 	ipa_clock_exit(clock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 	rproc_put(rproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) }
^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)  * ipa_suspend() - Power management system suspend callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)  * @dev:	IPA device structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)  * Return:	Always returns zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900)  * Called by the PM framework when a system suspend operation is invoked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)  * Suspends endpoints and releases the clock reference held to keep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)  * the IPA clock running until this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) static int ipa_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) 	struct ipa *ipa = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) 	/* When a suspended RX endpoint has a packet ready to receive, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) 	 * get an IPA SUSPEND interrupt.  We trigger a system resume in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) 	 * that case, but only on the first such interrupt since suspend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) 	__clear_bit(IPA_FLAG_RESUMED, ipa->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) 	ipa_endpoint_suspend(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) 	ipa_clock_put(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)  * ipa_resume() - Power management system resume callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)  * @dev:	IPA device structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)  * Return:	Always returns 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)  * Called by the PM framework when a system resume operation is invoked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)  * Takes an IPA clock reference to keep the clock running until suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)  * and resumes endpoints.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) static int ipa_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) 	struct ipa *ipa = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) 	/* This clock reference will keep the IPA out of suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) 	 * until we get a power management suspend request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) 	ipa_clock_get(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) 	ipa_endpoint_resume(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) static const struct dev_pm_ops ipa_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) 	.suspend	= ipa_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) 	.resume		= ipa_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) static struct platform_driver ipa_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) 	.probe	= ipa_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) 	.remove	= ipa_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) 	.driver	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) 		.name		= "ipa",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) 		.pm		= &ipa_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) 		.of_match_table	= ipa_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) module_platform_driver(ipa_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) MODULE_DESCRIPTION("Qualcomm IP Accelerator device driver");