Commit 530f9216 authored by Alex Elder's avatar Alex Elder Committed by David S. Miller

soc: qcom: ipa: AP/modem communications

This patch implements two forms of out-of-band communication between
the AP and modem.

  - QMI is a mechanism that allows clients running on the AP
    interact with services running on the modem (and vice-versa).
    The AP IPA driver uses QMI to communicate with the corresponding
    IPA driver resident on the modem, to agree on parameters used
    with the IPA hardware and to ensure both sides are ready before
    entering operational mode.

  - SMP2P is a more primitive mechanism available for the modem and
    AP to communicate with each other.  It provides a means for either
    the AP or modem to interrupt the other, and furthermore, to provide
    32 bits worth of information.  The IPA driver uses SMP2P to tell
    the modem what the state of the IPA clock was in the event of a
    crash.  This allows the modem to safely access the IPA hardware
    (or avoid doing so) when a crash occurs, for example, to access
    information within the IPA hardware.
Signed-off-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a646d6ec
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (c) 2018, The Linux Foundation. All rights reserved.
* Copyright (C) 2018-2020 Linaro Ltd.
*/
#ifndef _IPA_QMI_H_
#define _IPA_QMI_H_
#include <linux/types.h>
#include <linux/soc/qcom/qmi.h>
struct ipa;
/**
* struct ipa_qmi - QMI state associated with an IPA
* @client_handle - used to send an QMI requests to the modem
* @server_handle - used to handle QMI requests from the modem
* @initialized - whether QMI initialization has completed
* @indication_register_received - tracks modem request receipt
* @init_driver_response_received - tracks modem response receipt
*/
struct ipa_qmi {
struct qmi_handle client_handle;
struct qmi_handle server_handle;
/* Information used for the client handle */
struct sockaddr_qrtr modem_sq;
struct work_struct init_driver_work;
/* Flags used in negotiating readiness */
bool initial_boot;
bool uc_ready;
bool modem_ready;
bool indication_requested;
bool indication_sent;
};
int ipa_qmi_setup(struct ipa *ipa);
void ipa_qmi_teardown(struct ipa *ipa);
#endif /* !_IPA_QMI_H_ */
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (c) 2018, The Linux Foundation. All rights reserved.
* Copyright (C) 2018-2020 Linaro Ltd.
*/
#ifndef _IPA_QMI_MSG_H_
#define _IPA_QMI_MSG_H_
/* === Only "ipa_qmi" and "ipa_qmi_msg.c" should include this file === */
#include <linux/types.h>
#include <linux/soc/qcom/qmi.h>
/* Request/response/indication QMI message ids used for IPA. Receiving
* end issues a response for requests; indications require no response.
*/
#define IPA_QMI_INDICATION_REGISTER 0x20 /* modem -> AP request */
#define IPA_QMI_INIT_DRIVER 0x21 /* AP -> modem request */
#define IPA_QMI_INIT_COMPLETE 0x22 /* AP -> modem indication */
#define IPA_QMI_DRIVER_INIT_COMPLETE 0x35 /* modem -> AP request */
/* The maximum size required for message types. These sizes include
* the message data, along with type (1 byte) and length (2 byte)
* information for each field. The qmi_send_*() interfaces require
* the message size to be provided.
*/
#define IPA_QMI_INDICATION_REGISTER_REQ_SZ 12 /* -> server handle */
#define IPA_QMI_INDICATION_REGISTER_RSP_SZ 7 /* <- server handle */
#define IPA_QMI_INIT_DRIVER_REQ_SZ 162 /* client handle -> */
#define IPA_QMI_INIT_DRIVER_RSP_SZ 25 /* client handle <- */
#define IPA_QMI_INIT_COMPLETE_IND_SZ 7 /* <- server handle */
#define IPA_QMI_DRIVER_INIT_COMPLETE_REQ_SZ 4 /* -> server handle */
#define IPA_QMI_DRIVER_INIT_COMPLETE_RSP_SZ 7 /* <- server handle */
/* Maximum size of messages we expect the AP to receive (max of above) */
#define IPA_QMI_SERVER_MAX_RCV_SZ 8
#define IPA_QMI_CLIENT_MAX_RCV_SZ 25
/* Request message for the IPA_QMI_INDICATION_REGISTER request */
struct ipa_indication_register_req {
u8 master_driver_init_complete_valid;
u8 master_driver_init_complete;
u8 data_usage_quota_reached_valid;
u8 data_usage_quota_reached;
u8 ipa_mhi_ready_ind_valid;
u8 ipa_mhi_ready_ind;
};
/* The response to a IPA_QMI_INDICATION_REGISTER request consists only of
* a standard QMI response.
*/
struct ipa_indication_register_rsp {
struct qmi_response_type_v01 rsp;
};
/* Request message for the IPA_QMI_DRIVER_INIT_COMPLETE request */
struct ipa_driver_init_complete_req {
u8 status;
};
/* The response to a IPA_QMI_DRIVER_INIT_COMPLETE request consists only
* of a standard QMI response.
*/
struct ipa_driver_init_complete_rsp {
struct qmi_response_type_v01 rsp;
};
/* The message for the IPA_QMI_INIT_COMPLETE_IND indication consists
* only of a standard QMI response.
*/
struct ipa_init_complete_ind {
struct qmi_response_type_v01 status;
};
/* The AP tells the modem its platform type. We assume Android. */
enum ipa_platform_type {
IPA_QMI_PLATFORM_TYPE_INVALID = 0, /* Invalid */
IPA_QMI_PLATFORM_TYPE_TN = 1, /* Data card */
IPA_QMI_PLATFORM_TYPE_LE = 2, /* Data router */
IPA_QMI_PLATFORM_TYPE_MSM_ANDROID = 3, /* Android MSM */
IPA_QMI_PLATFORM_TYPE_MSM_WINDOWS = 4, /* Windows MSM */
IPA_QMI_PLATFORM_TYPE_MSM_QNX_V01 = 5, /* QNX MSM */
};
/* This defines the start and end offset of a range of memory. Both
* fields are offsets relative to the start of IPA shared memory.
* The end value is the last addressable byte *within* the range.
*/
struct ipa_mem_bounds {
u32 start;
u32 end;
};
/* This defines the location and size of an array. The start value
* is an offset relative to the start of IPA shared memory. The
* size of the array is implied by the number of entries (the entry
* size is assumed to be known).
*/
struct ipa_mem_array {
u32 start;
u32 count;
};
/* This defines the location and size of a range of memory. The
* start is an offset relative to the start of IPA shared memory.
* This differs from the ipa_mem_bounds structure in that the size
* (in bytes) of the memory region is specified rather than the
* offset of its last byte.
*/
struct ipa_mem_range {
u32 start;
u32 size;
};
/* The message for the IPA_QMI_INIT_DRIVER request contains information
* from the AP that affects modem initialization.
*/
struct ipa_init_modem_driver_req {
u8 platform_type_valid;
u32 platform_type; /* enum ipa_platform_type */
/* Modem header table information. This defines the IPA shared
* memory in which the modem may insert header table entries.
*/
u8 hdr_tbl_info_valid;
struct ipa_mem_bounds hdr_tbl_info;
/* Routing table information. These define the location and size of
* non-hashable IPv4 and IPv6 filter tables. The start values are
* offsets relative to the start of IPA shared memory.
*/
u8 v4_route_tbl_info_valid;
struct ipa_mem_array v4_route_tbl_info;
u8 v6_route_tbl_info_valid;
struct ipa_mem_array v6_route_tbl_info;
/* Filter table information. These define the location of the
* non-hashable IPv4 and IPv6 filter tables. The start values are
* offsets relative to the start of IPA shared memory.
*/
u8 v4_filter_tbl_start_valid;
u32 v4_filter_tbl_start;
u8 v6_filter_tbl_start_valid;
u32 v6_filter_tbl_start;
/* Modem memory information. This defines the location and
* size of memory available for the modem to use.
*/
u8 modem_mem_info_valid;
struct ipa_mem_range modem_mem_info;
/* This defines the destination endpoint on the AP to which
* the modem driver can send control commands. Must be less
* than ipa_endpoint_max().
*/
u8 ctrl_comm_dest_end_pt_valid;
u32 ctrl_comm_dest_end_pt;
/* This defines whether the modem should load the microcontroller
* or not. It is unnecessary to reload it if the modem is being
* restarted.
*
* NOTE: this field is named "is_ssr_bootup" elsewhere.
*/
u8 skip_uc_load_valid;
u8 skip_uc_load;
/* Processing context memory information. This defines the memory in
* which the modem may insert header processing context table entries.
*/
u8 hdr_proc_ctx_tbl_info_valid;
struct ipa_mem_bounds hdr_proc_ctx_tbl_info;
/* Compression command memory information. This defines the memory
* in which the modem may insert compression/decompression commands.
*/
u8 zip_tbl_info_valid;
struct ipa_mem_bounds zip_tbl_info;
/* Routing table information. These define the location and size
* of hashable IPv4 and IPv6 filter tables. The start values are
* offsets relative to the start of IPA shared memory.
*/
u8 v4_hash_route_tbl_info_valid;
struct ipa_mem_array v4_hash_route_tbl_info;
u8 v6_hash_route_tbl_info_valid;
struct ipa_mem_array v6_hash_route_tbl_info;
/* Filter table information. These define the location and size
* of hashable IPv4 and IPv6 filter tables. The start values are
* offsets relative to the start of IPA shared memory.
*/
u8 v4_hash_filter_tbl_start_valid;
u32 v4_hash_filter_tbl_start;
u8 v6_hash_filter_tbl_start_valid;
u32 v6_hash_filter_tbl_start;
/* Statistics information. These define the locations of the
* first and last statistics sub-regions. (IPA v4.0 and above)
*/
u8 hw_stats_quota_base_addr_valid;
u32 hw_stats_quota_base_addr;
u8 hw_stats_quota_size_valid;
u32 hw_stats_quota_size;
u8 hw_stats_drop_base_addr_valid;
u32 hw_stats_drop_base_addr;
u8 hw_stats_drop_size_valid;
u32 hw_stats_drop_size;
};
/* The response to a IPA_QMI_INIT_DRIVER request begins with a standard
* QMI response, but contains other information as well. Currently we
* simply wait for the the INIT_DRIVER transaction to complete and
* ignore any other data that might be returned.
*/
struct ipa_init_modem_driver_rsp {
struct qmi_response_type_v01 rsp;
/* This defines the destination endpoint on the modem to which
* the AP driver can send control commands. Must be less than
* ipa_endpoint_max().
*/
u8 ctrl_comm_dest_end_pt_valid;
u32 ctrl_comm_dest_end_pt;
/* This defines the default endpoint. The AP driver is not
* required to configure the hardware with this value. Must
* be less than ipa_endpoint_max().
*/
u8 default_end_pt_valid;
u32 default_end_pt;
/* This defines whether a second handshake is required to complete
* initialization.
*/
u8 modem_driver_init_pending_valid;
u8 modem_driver_init_pending;
};
/* Message structure definitions defined in "ipa_qmi_msg.c" */
extern struct qmi_elem_info ipa_indication_register_req_ei[];
extern struct qmi_elem_info ipa_indication_register_rsp_ei[];
extern struct qmi_elem_info ipa_driver_init_complete_req_ei[];
extern struct qmi_elem_info ipa_driver_init_complete_rsp_ei[];
extern struct qmi_elem_info ipa_init_complete_ind_ei[];
extern struct qmi_elem_info ipa_mem_bounds_ei[];
extern struct qmi_elem_info ipa_mem_array_ei[];
extern struct qmi_elem_info ipa_mem_range_ei[];
extern struct qmi_elem_info ipa_init_modem_driver_req_ei[];
extern struct qmi_elem_info ipa_init_modem_driver_rsp_ei[];
#endif /* !_IPA_QMI_MSG_H_ */
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
* Copyright (C) 2019-2020 Linaro Ltd.
*/
#include <linux/types.h>
#include <linux/device.h>
#include <linux/interrupt.h>
#include <linux/notifier.h>
#include <linux/soc/qcom/smem.h>
#include <linux/soc/qcom/smem_state.h>
#include "ipa_smp2p.h"
#include "ipa.h"
#include "ipa_uc.h"
#include "ipa_clock.h"
/**
* DOC: IPA SMP2P communication with the modem
*
* SMP2P is a primitive communication mechanism available between the AP and
* the modem. The IPA driver uses this for two purposes: to enable the modem
* to state that the GSI hardware is ready to use; and to communicate the
* state of the IPA clock in the event of a crash.
*
* GSI needs to have early initialization completed before it can be used.
* This initialization is done either by Trust Zone or by the modem. In the
* latter case, the modem uses an SMP2P interrupt to tell the AP IPA driver
* when the GSI is ready to use.
*
* The modem is also able to inquire about the current state of the IPA
* clock by trigging another SMP2P interrupt to the AP. We communicate
* whether the clock is enabled using two SMP2P state bits--one to
* indicate the clock state (on or off), and a second to indicate the
* clock state bit is valid. The modem will poll the valid bit until it
* is set, and at that time records whether the AP has the IPA clock enabled.
*
* Finally, if the AP kernel panics, we update the SMP2P state bits even if
* we never receive an interrupt from the modem requesting this.
*/
/**
* struct ipa_smp2p - IPA SMP2P information
* @ipa: IPA pointer
* @valid_state: SMEM state indicating enabled state is valid
* @enabled_state: SMEM state to indicate clock is enabled
* @valid_bit: Valid bit in 32-bit SMEM state mask
* @enabled_bit: Enabled bit in 32-bit SMEM state mask
* @enabled_bit: Enabled bit in 32-bit SMEM state mask
* @clock_query_irq: IPA interrupt triggered by modem for clock query
* @setup_ready_irq: IPA interrupt triggered by modem to signal GSI ready
* @clock_on: Whether IPA clock is on
* @notified: Whether modem has been notified of clock state
* @disabled: Whether setup ready interrupt handling is disabled
* @mutex mutex: Motex protecting ready interrupt/shutdown interlock
* @panic_notifier: Panic notifier structure
*/
struct ipa_smp2p {
struct ipa *ipa;
struct qcom_smem_state *valid_state;
struct qcom_smem_state *enabled_state;
u32 valid_bit;
u32 enabled_bit;
u32 clock_query_irq;
u32 setup_ready_irq;
bool clock_on;
bool notified;
bool disabled;
struct mutex mutex;
struct notifier_block panic_notifier;
};
/**
* ipa_smp2p_notify() - use SMP2P to tell modem about IPA clock state
* @smp2p: SMP2P information
*
* This is called either when the modem has requested it (by triggering
* the modem clock query IPA interrupt) or whenever the AP is shutting down
* (via a panic notifier). It sets the two SMP2P state bits--one saying
* whether the IPA clock is running, and the other indicating the first bit
* is valid.
*/
static void ipa_smp2p_notify(struct ipa_smp2p *smp2p)
{
u32 value;
u32 mask;
if (smp2p->notified)
return;
smp2p->clock_on = ipa_clock_get_additional(smp2p->ipa);
/* Signal whether the clock is enabled */
mask = BIT(smp2p->enabled_bit);
value = smp2p->clock_on ? mask : 0;
qcom_smem_state_update_bits(smp2p->enabled_state, mask, value);
/* Now indicate that the enabled flag is valid */
mask = BIT(smp2p->valid_bit);
value = mask;
qcom_smem_state_update_bits(smp2p->valid_state, mask, value);
smp2p->notified = true;
}
/* Threaded IRQ handler for modem "ipa-clock-query" SMP2P interrupt */
static irqreturn_t ipa_smp2p_modem_clk_query_isr(int irq, void *dev_id)
{
struct ipa_smp2p *smp2p = dev_id;
ipa_smp2p_notify(smp2p);
return IRQ_HANDLED;
}
static int ipa_smp2p_panic_notifier(struct notifier_block *nb,
unsigned long action, void *data)
{
struct ipa_smp2p *smp2p;
smp2p = container_of(nb, struct ipa_smp2p, panic_notifier);
ipa_smp2p_notify(smp2p);
if (smp2p->clock_on)
ipa_uc_panic_notifier(smp2p->ipa);
return NOTIFY_DONE;
}
static int ipa_smp2p_panic_notifier_register(struct ipa_smp2p *smp2p)
{
/* IPA panic handler needs to run before modem shuts down */
smp2p->panic_notifier.notifier_call = ipa_smp2p_panic_notifier;
smp2p->panic_notifier.priority = INT_MAX; /* Do it early */
return atomic_notifier_chain_register(&panic_notifier_list,
&smp2p->panic_notifier);
}
static void ipa_smp2p_panic_notifier_unregister(struct ipa_smp2p *smp2p)
{
atomic_notifier_chain_unregister(&panic_notifier_list,
&smp2p->panic_notifier);
}
/* Threaded IRQ handler for modem "ipa-setup-ready" SMP2P interrupt */
static irqreturn_t ipa_smp2p_modem_setup_ready_isr(int irq, void *dev_id)
{
struct ipa_smp2p *smp2p = dev_id;
mutex_lock(&smp2p->mutex);
if (!smp2p->disabled) {
int ret;
ret = ipa_setup(smp2p->ipa);
if (ret)
dev_err(&smp2p->ipa->pdev->dev,
"error %d from ipa_setup()\n", ret);
smp2p->disabled = true;
}
mutex_unlock(&smp2p->mutex);
return IRQ_HANDLED;
}
/* Initialize SMP2P interrupts */
static int ipa_smp2p_irq_init(struct ipa_smp2p *smp2p, const char *name,
irq_handler_t handler)
{
struct device *dev = &smp2p->ipa->pdev->dev;
unsigned int irq;
int ret;
ret = platform_get_irq_byname(smp2p->ipa->pdev, name);
if (ret <= 0) {
dev_err(dev, "DT error %d getting \"%s\" IRQ property\n",
ret, name);
return ret ? : -EINVAL;
}
irq = ret;
ret = request_threaded_irq(irq, NULL, handler, 0, name, smp2p);
if (ret) {
dev_err(dev, "error %d requesting \"%s\" IRQ\n", ret, name);
return ret;
}
return irq;
}
static void ipa_smp2p_irq_exit(struct ipa_smp2p *smp2p, u32 irq)
{
free_irq(irq, smp2p);
}
/* Drop the clock reference if it was taken in ipa_smp2p_notify() */
static void ipa_smp2p_clock_release(struct ipa *ipa)
{
if (!ipa->smp2p->clock_on)
return;
ipa_clock_put(ipa);
ipa->smp2p->clock_on = false;
}
/* Initialize the IPA SMP2P subsystem */
int ipa_smp2p_init(struct ipa *ipa, bool modem_init)
{
struct qcom_smem_state *enabled_state;
struct device *dev = &ipa->pdev->dev;
struct qcom_smem_state *valid_state;
struct ipa_smp2p *smp2p;
u32 enabled_bit;
u32 valid_bit;
int ret;
valid_state = qcom_smem_state_get(dev, "ipa-clock-enabled-valid",
&valid_bit);
if (IS_ERR(valid_state))
return PTR_ERR(valid_state);
if (valid_bit >= 32) /* BITS_PER_U32 */
return -EINVAL;
enabled_state = qcom_smem_state_get(dev, "ipa-clock-enabled",
&enabled_bit);
if (IS_ERR(enabled_state))
return PTR_ERR(enabled_state);
if (enabled_bit >= 32) /* BITS_PER_U32 */
return -EINVAL;
smp2p = kzalloc(sizeof(*smp2p), GFP_KERNEL);
if (!smp2p)
return -ENOMEM;
smp2p->ipa = ipa;
/* These fields are needed by the clock query interrupt
* handler, so initialize them now.
*/
mutex_init(&smp2p->mutex);
smp2p->valid_state = valid_state;
smp2p->valid_bit = valid_bit;
smp2p->enabled_state = enabled_state;
smp2p->enabled_bit = enabled_bit;
/* We have enough information saved to handle notifications */
ipa->smp2p = smp2p;
ret = ipa_smp2p_irq_init(smp2p, "ipa-clock-query",
ipa_smp2p_modem_clk_query_isr);
if (ret < 0)
goto err_null_smp2p;
smp2p->clock_query_irq = ret;
ret = ipa_smp2p_panic_notifier_register(smp2p);
if (ret)
goto err_irq_exit;
if (modem_init) {
/* Result will be non-zero (negative for error) */
ret = ipa_smp2p_irq_init(smp2p, "ipa-setup-ready",
ipa_smp2p_modem_setup_ready_isr);
if (ret < 0)
goto err_notifier_unregister;
smp2p->setup_ready_irq = ret;
}
return 0;
err_notifier_unregister:
ipa_smp2p_panic_notifier_unregister(smp2p);
err_irq_exit:
ipa_smp2p_irq_exit(smp2p, smp2p->clock_query_irq);
err_null_smp2p:
ipa->smp2p = NULL;
mutex_destroy(&smp2p->mutex);
kfree(smp2p);
return ret;
}
void ipa_smp2p_exit(struct ipa *ipa)
{
struct ipa_smp2p *smp2p = ipa->smp2p;
if (smp2p->setup_ready_irq)
ipa_smp2p_irq_exit(smp2p, smp2p->setup_ready_irq);
ipa_smp2p_panic_notifier_unregister(smp2p);
ipa_smp2p_irq_exit(smp2p, smp2p->clock_query_irq);
/* We won't get notified any more; drop clock reference (if any) */
ipa_smp2p_clock_release(ipa);
ipa->smp2p = NULL;
mutex_destroy(&smp2p->mutex);
kfree(smp2p);
}
void ipa_smp2p_disable(struct ipa *ipa)
{
struct ipa_smp2p *smp2p = ipa->smp2p;
if (!smp2p->setup_ready_irq)
return;
mutex_lock(&smp2p->mutex);
smp2p->disabled = true;
mutex_unlock(&smp2p->mutex);
}
/* Reset state tracking whether we have notified the modem */
void ipa_smp2p_notify_reset(struct ipa *ipa)
{
struct ipa_smp2p *smp2p = ipa->smp2p;
u32 mask;
if (!smp2p->notified)
return;
ipa_smp2p_clock_release(ipa);
/* Reset the clock enabled valid flag */
mask = BIT(smp2p->valid_bit);
qcom_smem_state_update_bits(smp2p->valid_state, mask, 0);
/* Mark the clock disabled for good measure... */
mask = BIT(smp2p->enabled_bit);
qcom_smem_state_update_bits(smp2p->enabled_state, mask, 0);
smp2p->notified = false;
}
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
* Copyright (C) 2019-2020 Linaro Ltd.
*/
#ifndef _IPA_SMP2P_H_
#define _IPA_SMP2P_H_
#include <linux/types.h>
struct ipa;
/**
* ipa_smp2p_init() - Initialize the IPA SMP2P subsystem
* @ipa: IPA pointer
* @modem_init: Whether the modem is responsible for GSI initialization
*
* @Return: 0 if successful, or a negative error code
*
*/
int ipa_smp2p_init(struct ipa *ipa, bool modem_init);
/**
* ipa_smp2p_exit() - Inverse of ipa_smp2p_init()
* @ipa: IPA pointer
*/
void ipa_smp2p_exit(struct ipa *ipa);
/**
* ipa_smp2p_disable() - Prevent "ipa-setup-ready" interrupt handling
* @IPA: IPA pointer
*
* Prevent handling of the "setup ready" interrupt from the modem.
* This is used before initiating shutdown of the driver.
*/
void ipa_smp2p_disable(struct ipa *ipa);
/**
* ipa_smp2p_notify_reset() - Reset modem notification state
* @ipa: IPA pointer
*
* If the modem crashes it queries the IPA clock state. In cleaning
* up after such a crash this is used to reset some state maintained
* for managing this notification.
*/
void ipa_smp2p_notify_reset(struct ipa *ipa);
#endif /* _IPA_SMP2P_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment