Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 
0003 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
0004  * Copyright (C) 2018-2021 Linaro Ltd.
0005  */
0006 #ifndef _GSI_H_
0007 #define _GSI_H_
0008 
0009 #include <linux/types.h>
0010 #include <linux/spinlock.h>
0011 #include <linux/mutex.h>
0012 #include <linux/completion.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/netdevice.h>
0015 
0016 #include "ipa_version.h"
0017 
0018 /* Maximum number of channels and event rings supported by the driver */
0019 #define GSI_CHANNEL_COUNT_MAX   23
0020 #define GSI_EVT_RING_COUNT_MAX  24
0021 
0022 /* Maximum TLV FIFO size for a channel; 64 here is arbitrary (and high) */
0023 #define GSI_TLV_MAX     64
0024 
0025 struct device;
0026 struct scatterlist;
0027 struct platform_device;
0028 
0029 struct gsi;
0030 struct gsi_trans;
0031 struct gsi_channel_data;
0032 struct ipa_gsi_endpoint_data;
0033 
0034 /* Execution environment IDs */
0035 enum gsi_ee_id {
0036     GSI_EE_AP               = 0x0,
0037     GSI_EE_MODEM                = 0x1,
0038     GSI_EE_UC               = 0x2,
0039     GSI_EE_TZ               = 0x3,
0040 };
0041 
0042 struct gsi_ring {
0043     void *virt;         /* ring array base address */
0044     dma_addr_t addr;        /* primarily low 32 bits used */
0045     u32 count;          /* number of elements in ring */
0046 
0047     /* The ring index value indicates the next "open" entry in the ring.
0048      *
0049      * A channel ring consists of TRE entries filled by the AP and passed
0050      * to the hardware for processing.  For a channel ring, the ring index
0051      * identifies the next unused entry to be filled by the AP.  In this
0052      * case the initial value is assumed by hardware to be 0.
0053      *
0054      * An event ring consists of event structures filled by the hardware
0055      * and passed to the AP.  For event rings, the ring index identifies
0056      * the next ring entry that is not known to have been filled by the
0057      * hardware.  The initial value used is arbitrary (so we use 0).
0058      */
0059     u32 index;
0060 };
0061 
0062 /* Transactions use several resources that can be allocated dynamically
0063  * but taken from a fixed-size pool.  The number of elements required for
0064  * the pool is limited by the total number of TREs that can be outstanding.
0065  *
0066  * If sufficient TREs are available to reserve for a transaction,
0067  * allocation from these pools is guaranteed to succeed.  Furthermore,
0068  * these resources are implicitly freed whenever the TREs in the
0069  * transaction they're associated with are released.
0070  *
0071  * The result of a pool allocation of multiple elements is always
0072  * contiguous.
0073  */
0074 struct gsi_trans_pool {
0075     void *base;         /* base address of element pool */
0076     u32 count;          /* # elements in the pool */
0077     u32 free;           /* next free element in pool (modulo) */
0078     u32 size;           /* size (bytes) of an element */
0079     u32 max_alloc;          /* max allocation request */
0080     dma_addr_t addr;        /* DMA address if DMA pool (or 0) */
0081 };
0082 
0083 struct gsi_trans_info {
0084     atomic_t tre_avail;     /* TREs available for allocation */
0085     struct gsi_trans_pool pool; /* transaction pool */
0086     struct gsi_trans **map;     /* TRE -> transaction map */
0087 
0088     struct gsi_trans_pool sg_pool;  /* scatterlist pool */
0089     struct gsi_trans_pool cmd_pool; /* command payload DMA pool */
0090 
0091     spinlock_t spinlock;        /* protects updates to the lists */
0092     struct list_head alloc;     /* allocated, not committed */
0093     struct list_head committed; /* committed, awaiting doorbell */
0094     struct list_head pending;   /* pending, awaiting completion */
0095     struct list_head complete;  /* completed, awaiting poll */
0096     struct list_head polled;    /* returned by gsi_channel_poll_one() */
0097 };
0098 
0099 /* Hardware values signifying the state of a channel */
0100 enum gsi_channel_state {
0101     GSI_CHANNEL_STATE_NOT_ALLOCATED     = 0x0,
0102     GSI_CHANNEL_STATE_ALLOCATED     = 0x1,
0103     GSI_CHANNEL_STATE_STARTED       = 0x2,
0104     GSI_CHANNEL_STATE_STOPPED       = 0x3,
0105     GSI_CHANNEL_STATE_STOP_IN_PROC      = 0x4,
0106     GSI_CHANNEL_STATE_FLOW_CONTROLLED   = 0x5,  /* IPA v4.2-v4.9 */
0107     GSI_CHANNEL_STATE_ERROR         = 0xf,
0108 };
0109 
0110 /* We only care about channels between IPA and AP */
0111 struct gsi_channel {
0112     struct gsi *gsi;
0113     bool toward_ipa;
0114     bool command;           /* AP command TX channel or not */
0115 
0116     u8 trans_tre_max;       /* max TREs in a transaction */
0117     u16 tre_count;
0118     u16 event_count;
0119 
0120     struct gsi_ring tre_ring;
0121     u32 evt_ring_id;
0122 
0123     /* The following counts are used only for TX endpoints */
0124     u64 byte_count;         /* total # bytes transferred */
0125     u64 trans_count;        /* total # transactions */
0126     u64 queued_byte_count;      /* last reported queued byte count */
0127     u64 queued_trans_count;     /* ...and queued trans count */
0128     u64 compl_byte_count;       /* last reported completed byte count */
0129     u64 compl_trans_count;      /* ...and completed trans count */
0130 
0131     struct gsi_trans_info trans_info;
0132 
0133     struct napi_struct napi;
0134 };
0135 
0136 /* Hardware values signifying the state of an event ring */
0137 enum gsi_evt_ring_state {
0138     GSI_EVT_RING_STATE_NOT_ALLOCATED    = 0x0,
0139     GSI_EVT_RING_STATE_ALLOCATED        = 0x1,
0140     GSI_EVT_RING_STATE_ERROR        = 0xf,
0141 };
0142 
0143 struct gsi_evt_ring {
0144     struct gsi_channel *channel;
0145     struct gsi_ring ring;
0146 };
0147 
0148 struct gsi {
0149     struct device *dev;     /* Same as IPA device */
0150     enum ipa_version version;
0151     void __iomem *virt_raw;     /* I/O mapped address range */
0152     void __iomem *virt;     /* Adjusted for most registers */
0153     u32 irq;
0154     u32 channel_count;
0155     u32 evt_ring_count;
0156     u32 event_bitmap;       /* allocated event rings */
0157     u32 modem_channel_bitmap;   /* modem channels to allocate */
0158     u32 type_enabled_bitmap;    /* GSI IRQ types enabled */
0159     u32 ieob_enabled_bitmap;    /* IEOB IRQ enabled (event rings) */
0160     int result;         /* Negative errno (generic commands) */
0161     struct completion completion;   /* Signals GSI command completion */
0162     struct mutex mutex;     /* protects commands, programming */
0163     struct gsi_channel channel[GSI_CHANNEL_COUNT_MAX];
0164     struct gsi_evt_ring evt_ring[GSI_EVT_RING_COUNT_MAX];
0165     struct net_device dummy_dev;    /* needed for NAPI */
0166 };
0167 
0168 /**
0169  * gsi_setup() - Set up the GSI subsystem
0170  * @gsi:    Address of GSI structure embedded in an IPA structure
0171  *
0172  * Return:  0 if successful, or a negative error code
0173  *
0174  * Performs initialization that must wait until the GSI hardware is
0175  * ready (including firmware loaded).
0176  */
0177 int gsi_setup(struct gsi *gsi);
0178 
0179 /**
0180  * gsi_teardown() - Tear down GSI subsystem
0181  * @gsi:    GSI address previously passed to a successful gsi_setup() call
0182  */
0183 void gsi_teardown(struct gsi *gsi);
0184 
0185 /**
0186  * gsi_channel_tre_max() - Channel maximum number of in-flight TREs
0187  * @gsi:    GSI pointer
0188  * @channel_id: Channel whose limit is to be returned
0189  *
0190  * Return:   The maximum number of TREs outstanding on the channel
0191  */
0192 u32 gsi_channel_tre_max(struct gsi *gsi, u32 channel_id);
0193 
0194 /**
0195  * gsi_channel_start() - Start an allocated GSI channel
0196  * @gsi:    GSI pointer
0197  * @channel_id: Channel to start
0198  *
0199  * Return:  0 if successful, or a negative error code
0200  */
0201 int gsi_channel_start(struct gsi *gsi, u32 channel_id);
0202 
0203 /**
0204  * gsi_channel_stop() - Stop a started GSI channel
0205  * @gsi:    GSI pointer returned by gsi_setup()
0206  * @channel_id: Channel to stop
0207  *
0208  * Return:  0 if successful, or a negative error code
0209  */
0210 int gsi_channel_stop(struct gsi *gsi, u32 channel_id);
0211 
0212 /**
0213  * gsi_modem_channel_flow_control() - Set channel flow control state (IPA v4.2+)
0214  * @gsi:    GSI pointer returned by gsi_setup()
0215  * @channel_id: Modem TX channel to control
0216  * @enable: Whether to enable flow control (i.e., prevent flow)
0217  */
0218 void gsi_modem_channel_flow_control(struct gsi *gsi, u32 channel_id,
0219                     bool enable);
0220 
0221 /**
0222  * gsi_channel_reset() - Reset an allocated GSI channel
0223  * @gsi:    GSI pointer
0224  * @channel_id: Channel to be reset
0225  * @doorbell:   Whether to (possibly) enable the doorbell engine
0226  *
0227  * Reset a channel and reconfigure it.  The @doorbell flag indicates
0228  * that the doorbell engine should be enabled if needed.
0229  *
0230  * GSI hardware relinquishes ownership of all pending receive buffer
0231  * transactions and they will complete with their cancelled flag set.
0232  */
0233 void gsi_channel_reset(struct gsi *gsi, u32 channel_id, bool doorbell);
0234 
0235 /**
0236  * gsi_suspend() - Prepare the GSI subsystem for suspend
0237  * @gsi:    GSI pointer
0238  */
0239 void gsi_suspend(struct gsi *gsi);
0240 
0241 /**
0242  * gsi_resume() - Resume the GSI subsystem following suspend
0243  * @gsi:    GSI pointer
0244  */
0245 void gsi_resume(struct gsi *gsi);
0246 
0247 /**
0248  * gsi_channel_suspend() - Suspend a GSI channel
0249  * @gsi:    GSI pointer
0250  * @channel_id: Channel to suspend
0251  *
0252  * For IPA v4.0+, suspend is implemented by stopping the channel.
0253  */
0254 int gsi_channel_suspend(struct gsi *gsi, u32 channel_id);
0255 
0256 /**
0257  * gsi_channel_resume() - Resume a suspended GSI channel
0258  * @gsi:    GSI pointer
0259  * @channel_id: Channel to resume
0260  *
0261  * For IPA v4.0+, the stopped channel is started again.
0262  */
0263 int gsi_channel_resume(struct gsi *gsi, u32 channel_id);
0264 
0265 /**
0266  * gsi_init() - Initialize the GSI subsystem
0267  * @gsi:    Address of GSI structure embedded in an IPA structure
0268  * @pdev:   IPA platform device
0269  * @version:    IPA hardware version (implies GSI version)
0270  * @count:  Number of entries in the configuration data array
0271  * @data:   Endpoint and channel configuration data
0272  *
0273  * Return:  0 if successful, or a negative error code
0274  *
0275  * Early stage initialization of the GSI subsystem, performing tasks
0276  * that can be done before the GSI hardware is ready to use.
0277  */
0278 int gsi_init(struct gsi *gsi, struct platform_device *pdev,
0279          enum ipa_version version, u32 count,
0280          const struct ipa_gsi_endpoint_data *data);
0281 
0282 /**
0283  * gsi_exit() - Exit the GSI subsystem
0284  * @gsi:    GSI address previously passed to a successful gsi_init() call
0285  */
0286 void gsi_exit(struct gsi *gsi);
0287 
0288 #endif /* _GSI_H_ */