2020-03-06 12:28:20 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
|
|
|
|
/* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
|
2021-02-12 22:33:58 +08:00
|
|
|
* Copyright (C) 2018-2021 Linaro Ltd.
|
2020-03-06 12:28:20 +08:00
|
|
|
*/
|
|
|
|
#ifndef _GSI_H_
|
|
|
|
#define _GSI_H_
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
|
2020-11-03 01:53:56 +08:00
|
|
|
#include "ipa_version.h"
|
|
|
|
|
2020-03-06 12:28:20 +08:00
|
|
|
/* Maximum number of channels and event rings supported by the driver */
|
2021-03-24 21:15:28 +08:00
|
|
|
#define GSI_CHANNEL_COUNT_MAX 23
|
2021-06-22 01:56:26 +08:00
|
|
|
#define GSI_EVT_RING_COUNT_MAX 24
|
2020-03-06 12:28:20 +08:00
|
|
|
|
|
|
|
/* Maximum TLV FIFO size for a channel; 64 here is arbitrary (and high) */
|
|
|
|
#define GSI_TLV_MAX 64
|
|
|
|
|
|
|
|
struct device;
|
|
|
|
struct scatterlist;
|
|
|
|
struct platform_device;
|
|
|
|
|
|
|
|
struct gsi;
|
|
|
|
struct gsi_trans;
|
|
|
|
struct gsi_channel_data;
|
|
|
|
struct ipa_gsi_endpoint_data;
|
|
|
|
|
|
|
|
/* Execution environment IDs */
|
|
|
|
enum gsi_ee_id {
|
2020-11-17 07:38:01 +08:00
|
|
|
GSI_EE_AP = 0x0,
|
|
|
|
GSI_EE_MODEM = 0x1,
|
|
|
|
GSI_EE_UC = 0x2,
|
|
|
|
GSI_EE_TZ = 0x3,
|
2020-03-06 12:28:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct gsi_ring {
|
|
|
|
void *virt; /* ring array base address */
|
|
|
|
dma_addr_t addr; /* primarily low 32 bits used */
|
|
|
|
u32 count; /* number of elements in ring */
|
|
|
|
|
|
|
|
/* The ring index value indicates the next "open" entry in the ring.
|
|
|
|
*
|
|
|
|
* A channel ring consists of TRE entries filled by the AP and passed
|
|
|
|
* to the hardware for processing. For a channel ring, the ring index
|
|
|
|
* identifies the next unused entry to be filled by the AP.
|
|
|
|
*
|
|
|
|
* An event ring consists of event structures filled by the hardware
|
|
|
|
* and passed to the AP. For event rings, the ring index identifies
|
|
|
|
* the next ring entry that is not known to have been filled by the
|
|
|
|
* hardware.
|
|
|
|
*/
|
|
|
|
u32 index;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Transactions use several resources that can be allocated dynamically
|
|
|
|
* but taken from a fixed-size pool. The number of elements required for
|
|
|
|
* the pool is limited by the total number of TREs that can be outstanding.
|
|
|
|
*
|
|
|
|
* If sufficient TREs are available to reserve for a transaction,
|
|
|
|
* allocation from these pools is guaranteed to succeed. Furthermore,
|
|
|
|
* these resources are implicitly freed whenever the TREs in the
|
|
|
|
* transaction they're associated with are released.
|
|
|
|
*
|
|
|
|
* The result of a pool allocation of multiple elements is always
|
|
|
|
* contiguous.
|
|
|
|
*/
|
|
|
|
struct gsi_trans_pool {
|
|
|
|
void *base; /* base address of element pool */
|
|
|
|
u32 count; /* # elements in the pool */
|
|
|
|
u32 free; /* next free element in pool (modulo) */
|
|
|
|
u32 size; /* size (bytes) of an element */
|
|
|
|
u32 max_alloc; /* max allocation request */
|
|
|
|
dma_addr_t addr; /* DMA address if DMA pool (or 0) */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gsi_trans_info {
|
|
|
|
atomic_t tre_avail; /* TREs available for allocation */
|
|
|
|
struct gsi_trans_pool pool; /* transaction pool */
|
|
|
|
struct gsi_trans_pool sg_pool; /* scatterlist pool */
|
|
|
|
struct gsi_trans_pool cmd_pool; /* command payload DMA pool */
|
|
|
|
struct gsi_trans_pool info_pool;/* command information pool */
|
|
|
|
struct gsi_trans **map; /* TRE -> transaction map */
|
|
|
|
|
|
|
|
spinlock_t spinlock; /* protects updates to the lists */
|
|
|
|
struct list_head alloc; /* allocated, not committed */
|
|
|
|
struct list_head pending; /* committed, awaiting completion */
|
|
|
|
struct list_head complete; /* completed, awaiting poll */
|
|
|
|
struct list_head polled; /* returned by gsi_channel_poll_one() */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Hardware values signifying the state of a channel */
|
|
|
|
enum gsi_channel_state {
|
2020-11-17 07:38:01 +08:00
|
|
|
GSI_CHANNEL_STATE_NOT_ALLOCATED = 0x0,
|
|
|
|
GSI_CHANNEL_STATE_ALLOCATED = 0x1,
|
|
|
|
GSI_CHANNEL_STATE_STARTED = 0x2,
|
|
|
|
GSI_CHANNEL_STATE_STOPPED = 0x3,
|
|
|
|
GSI_CHANNEL_STATE_STOP_IN_PROC = 0x4,
|
|
|
|
GSI_CHANNEL_STATE_ERROR = 0xf,
|
2020-03-06 12:28:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* We only care about channels between IPA and AP */
|
|
|
|
struct gsi_channel {
|
|
|
|
struct gsi *gsi;
|
|
|
|
bool toward_ipa;
|
|
|
|
bool command; /* AP command TX channel or not */
|
|
|
|
|
|
|
|
u8 tlv_count; /* # entries in TLV FIFO */
|
|
|
|
u16 tre_count;
|
|
|
|
u16 event_count;
|
|
|
|
|
2020-05-01 06:13:23 +08:00
|
|
|
struct completion completion; /* signals channel command completion */
|
2020-03-06 12:28:20 +08:00
|
|
|
|
|
|
|
struct gsi_ring tre_ring;
|
|
|
|
u32 evt_ring_id;
|
|
|
|
|
|
|
|
u64 byte_count; /* total # bytes transferred */
|
|
|
|
u64 trans_count; /* total # transactions */
|
|
|
|
/* The following counts are used only for TX endpoints */
|
|
|
|
u64 queued_byte_count; /* last reported queued byte count */
|
|
|
|
u64 queued_trans_count; /* ...and queued trans count */
|
|
|
|
u64 compl_byte_count; /* last reported completed byte count */
|
|
|
|
u64 compl_trans_count; /* ...and completed trans count */
|
|
|
|
|
|
|
|
struct gsi_trans_info trans_info;
|
|
|
|
|
|
|
|
struct napi_struct napi;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Hardware values signifying the state of an event ring */
|
|
|
|
enum gsi_evt_ring_state {
|
|
|
|
GSI_EVT_RING_STATE_NOT_ALLOCATED = 0x0,
|
|
|
|
GSI_EVT_RING_STATE_ALLOCATED = 0x1,
|
|
|
|
GSI_EVT_RING_STATE_ERROR = 0xf,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gsi_evt_ring {
|
|
|
|
struct gsi_channel *channel;
|
|
|
|
struct completion completion; /* signals event ring state changes */
|
|
|
|
struct gsi_ring ring;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gsi {
|
|
|
|
struct device *dev; /* Same as IPA device */
|
2020-11-03 01:53:56 +08:00
|
|
|
enum ipa_version version;
|
2020-03-06 12:28:20 +08:00
|
|
|
struct net_device dummy_dev; /* needed for NAPI */
|
2021-02-12 22:33:58 +08:00
|
|
|
void __iomem *virt_raw; /* I/O mapped address range */
|
|
|
|
void __iomem *virt; /* Adjusted for most registers */
|
2020-03-06 12:28:20 +08:00
|
|
|
u32 irq;
|
|
|
|
u32 channel_count;
|
|
|
|
u32 evt_ring_count;
|
|
|
|
struct gsi_channel channel[GSI_CHANNEL_COUNT_MAX];
|
|
|
|
struct gsi_evt_ring evt_ring[GSI_EVT_RING_COUNT_MAX];
|
2020-11-06 02:13:57 +08:00
|
|
|
u32 event_bitmap; /* allocated event rings */
|
|
|
|
u32 modem_channel_bitmap; /* modem channels to allocate */
|
2020-11-06 02:14:00 +08:00
|
|
|
u32 type_enabled_bitmap; /* GSI IRQ types enabled */
|
2020-11-06 02:13:57 +08:00
|
|
|
u32 ieob_enabled_bitmap; /* IEOB IRQ enabled (event rings) */
|
2020-03-06 12:28:20 +08:00
|
|
|
struct completion completion; /* for global EE commands */
|
2020-11-20 06:49:27 +08:00
|
|
|
int result; /* Negative errno (generic commands) */
|
2020-03-06 12:28:20 +08:00
|
|
|
struct mutex mutex; /* protects commands, programming */
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsi_setup() - Set up the GSI subsystem
|
|
|
|
* @gsi: Address of GSI structure embedded in an IPA structure
|
|
|
|
*
|
2020-07-13 20:24:18 +08:00
|
|
|
* Return: 0 if successful, or a negative error code
|
2020-03-06 12:28:20 +08:00
|
|
|
*
|
|
|
|
* Performs initialization that must wait until the GSI hardware is
|
|
|
|
* ready (including firmware loaded).
|
|
|
|
*/
|
2020-11-03 01:54:00 +08:00
|
|
|
int gsi_setup(struct gsi *gsi);
|
2020-03-06 12:28:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gsi_teardown() - Tear down GSI subsystem
|
|
|
|
* @gsi: GSI address previously passed to a successful gsi_setup() call
|
|
|
|
*/
|
|
|
|
void gsi_teardown(struct gsi *gsi);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsi_channel_tre_max() - Channel maximum number of in-flight TREs
|
|
|
|
* @gsi: GSI pointer
|
|
|
|
* @channel_id: Channel whose limit is to be returned
|
|
|
|
*
|
2020-07-13 20:24:18 +08:00
|
|
|
* Return: The maximum number of TREs oustanding on the channel
|
2020-03-06 12:28:20 +08:00
|
|
|
*/
|
|
|
|
u32 gsi_channel_tre_max(struct gsi *gsi, u32 channel_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsi_channel_trans_tre_max() - Maximum TREs in a single transaction
|
|
|
|
* @gsi: GSI pointer
|
|
|
|
* @channel_id: Channel whose limit is to be returned
|
|
|
|
*
|
2020-07-13 20:24:18 +08:00
|
|
|
* Return: The maximum TRE count per transaction on the channel
|
2020-03-06 12:28:20 +08:00
|
|
|
*/
|
|
|
|
u32 gsi_channel_trans_tre_max(struct gsi *gsi, u32 channel_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsi_channel_start() - Start an allocated GSI channel
|
|
|
|
* @gsi: GSI pointer
|
|
|
|
* @channel_id: Channel to start
|
|
|
|
*
|
2020-07-13 20:24:18 +08:00
|
|
|
* Return: 0 if successful, or a negative error code
|
2020-03-06 12:28:20 +08:00
|
|
|
*/
|
|
|
|
int gsi_channel_start(struct gsi *gsi, u32 channel_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsi_channel_stop() - Stop a started GSI channel
|
|
|
|
* @gsi: GSI pointer returned by gsi_setup()
|
|
|
|
* @channel_id: Channel to stop
|
|
|
|
*
|
2020-07-13 20:24:18 +08:00
|
|
|
* Return: 0 if successful, or a negative error code
|
2020-03-06 12:28:20 +08:00
|
|
|
*/
|
|
|
|
int gsi_channel_stop(struct gsi *gsi, u32 channel_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsi_channel_reset() - Reset an allocated GSI channel
|
|
|
|
* @gsi: GSI pointer
|
|
|
|
* @channel_id: Channel to be reset
|
2020-11-03 01:53:59 +08:00
|
|
|
* @doorbell: Whether to (possibly) enable the doorbell engine
|
2020-03-06 12:28:20 +08:00
|
|
|
*
|
2020-11-03 01:53:59 +08:00
|
|
|
* Reset a channel and reconfigure it. The @doorbell flag indicates
|
|
|
|
* that the doorbell engine should be enabled if needed.
|
2020-03-06 12:28:20 +08:00
|
|
|
*
|
|
|
|
* GSI hardware relinquishes ownership of all pending receive buffer
|
|
|
|
* transactions and they will complete with their cancelled flag set.
|
|
|
|
*/
|
2020-11-03 01:53:59 +08:00
|
|
|
void gsi_channel_reset(struct gsi *gsi, u32 channel_id, bool doorbell);
|
2020-03-06 12:28:20 +08:00
|
|
|
|
2021-08-03 22:01:03 +08:00
|
|
|
/**
|
|
|
|
* gsi_suspend() - Prepare the GSI subsystem for suspend
|
|
|
|
* @gsi: GSI pointer
|
|
|
|
*/
|
|
|
|
void gsi_suspend(struct gsi *gsi);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsi_resume() - Resume the GSI subsystem following suspend
|
|
|
|
* @gsi: GSI pointer
|
|
|
|
*/
|
|
|
|
void gsi_resume(struct gsi *gsi);
|
|
|
|
|
2021-08-03 22:00:58 +08:00
|
|
|
/**
|
|
|
|
* gsi_channel_suspend() - Suspend a GSI channel
|
|
|
|
* @gsi: GSI pointer
|
|
|
|
* @channel_id: Channel to suspend
|
|
|
|
*
|
|
|
|
* For IPA v4.0+, suspend is implemented by stopping the channel.
|
|
|
|
*/
|
|
|
|
int gsi_channel_suspend(struct gsi *gsi, u32 channel_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gsi_channel_resume() - Resume a suspended GSI channel
|
|
|
|
* @gsi: GSI pointer
|
|
|
|
* @channel_id: Channel to resume
|
|
|
|
*
|
|
|
|
* For IPA v4.0+, the stopped channel is started again.
|
|
|
|
*/
|
|
|
|
int gsi_channel_resume(struct gsi *gsi, u32 channel_id);
|
2020-03-06 12:28:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gsi_init() - Initialize the GSI subsystem
|
|
|
|
* @gsi: Address of GSI structure embedded in an IPA structure
|
|
|
|
* @pdev: IPA platform device
|
net: ipa: expose IPA version to the GSI layer
Although GSI is integral to IPA, it is a separate hardware component
and the IPA code supporting it has been structured to avoid explicit
dependence on IPA details. An example of this is that gsi_init() is
passed a number of Boolean flags to indicate special behaviors,
whose values are dependent on the IPA hardware version. Looking
ahead, newer hardware versions would require even more such special
behaviors.
For any given version of IPA hardware (like 3.5.1 or 4.2), the GSI
hardware version is fixed (in this case, 1.3 and 2.2, respectively).
So the IPA version *implies* the GSI version, and the IPA version
can be used as effectively the equivalent of the GSI hardware version.
Rather than proliferating new special behavior flags, just provide
the IPA version to the GSI layer when it is initialized. The GSI
code can then use that directly to determine whether special
behaviors are required. The IPA version enumerated type is already
isolated to its own header file, so the exposure of this IPA detail
is very limited.
For now, just change gsi_init() to pass the version rather than the
Boolean flags, and set the flag values internal to that function.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2020-11-03 01:53:55 +08:00
|
|
|
* @version: IPA hardware version (implies GSI version)
|
|
|
|
* @count: Number of entries in the configuration data array
|
|
|
|
* @data: Endpoint and channel configuration data
|
2020-03-06 12:28:20 +08:00
|
|
|
*
|
2020-07-13 20:24:18 +08:00
|
|
|
* Return: 0 if successful, or a negative error code
|
2020-03-06 12:28:20 +08:00
|
|
|
*
|
|
|
|
* Early stage initialization of the GSI subsystem, performing tasks
|
|
|
|
* that can be done before the GSI hardware is ready to use.
|
|
|
|
*/
|
net: ipa: expose IPA version to the GSI layer
Although GSI is integral to IPA, it is a separate hardware component
and the IPA code supporting it has been structured to avoid explicit
dependence on IPA details. An example of this is that gsi_init() is
passed a number of Boolean flags to indicate special behaviors,
whose values are dependent on the IPA hardware version. Looking
ahead, newer hardware versions would require even more such special
behaviors.
For any given version of IPA hardware (like 3.5.1 or 4.2), the GSI
hardware version is fixed (in this case, 1.3 and 2.2, respectively).
So the IPA version *implies* the GSI version, and the IPA version
can be used as effectively the equivalent of the GSI hardware version.
Rather than proliferating new special behavior flags, just provide
the IPA version to the GSI layer when it is initialized. The GSI
code can then use that directly to determine whether special
behaviors are required. The IPA version enumerated type is already
isolated to its own header file, so the exposure of this IPA detail
is very limited.
For now, just change gsi_init() to pass the version rather than the
Boolean flags, and set the flag values internal to that function.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2020-11-03 01:53:55 +08:00
|
|
|
int gsi_init(struct gsi *gsi, struct platform_device *pdev,
|
|
|
|
enum ipa_version version, u32 count,
|
|
|
|
const struct ipa_gsi_endpoint_data *data);
|
2020-03-06 12:28:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gsi_exit() - Exit the GSI subsystem
|
|
|
|
* @gsi: GSI address previously passed to a successful gsi_init() call
|
|
|
|
*/
|
|
|
|
void gsi_exit(struct gsi *gsi);
|
|
|
|
|
|
|
|
#endif /* _GSI_H_ */
|