Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 859783a1 authored by Ghanim Fodi's avatar Ghanim Fodi
Browse files

msm: ipa: Add snapshot of IPA driver



This is a snapshot of the IPA and GSI drivers
from msm-4.14 to 4.19 kernel as of
'commit <cec0da843f57> ("clk: qcom: npucc: Add CRC div
source for npu_cc_cal_dp_clk_src")'.

CRs-Fixed: 2341003
Change-Id: I498b2edb878e7d75311824dd217e75893efcfc73
Signed-off-by: default avatarGhanim Fodi <gfodi@codeaurora.org>
parent 3c07308b
Loading
Loading
Loading
Loading
+100 −0
Original line number Diff line number Diff line
@@ -52,4 +52,104 @@ config SPS_SUPPORT_NDP_BAM
	  to do the actual data transfer themselves, instead of the
	  BAM.

config GSI
	bool "GSI support"
	help
	  This driver provides the transport needed to talk to the
	  IPA core. It replaces the BAM transport used previously.

	  The GSI connects to a peripheral component via uniform TLV
	  interface, and allows it to interface with other peripherals
	  and CPUs over various types of interfaces such as MHI, xDCI,
	  xHCI, GPI, WDI, Ethernet, etc.

config GSI_REGISTER_VERSION_2
	bool "GSI core Version 2 Registers SWI Support"
	depends on GSI
	help
	  GSI core registers Software interface version 2 has updated
	  registers interface to communicate with GSI. This includes
	  new registers offsets, new registers fields structure and
	  new registers.

config IPA3
	tristate "IPA3 support"
	select GSI
	depends on NET
	help
	  This driver supports the Internet Packet Accelerator (IPA3) core.
	  IPA is a programmable protocol processor HW block.
	  It is designed to support generic HW processing of UL/DL IP packets
	  for various use cases independent of radio technology.
	  The driver support client connection and configuration
	  for the IPA core.
	  Kernel and user-space processes can call the IPA driver
	  to configure IPA core.

config IPA_WDI_UNIFIED_API
	bool "IPA WDI unified API support"
	depends on IPA3
	help
	  This driver supports IPA WDI unified API.
	  WDI is the interface between IPA micro controller and WLAN chipset.
	  It is designed to support IPA HW accelerating path for WLAN use case.
	  The IPA WDI unified API supports all WDI versions through a unified
	  interface.

config RMNET_IPA3
	tristate "IPA3 RMNET WWAN Network Device"
	depends on IPA3 && QCOM_QMI_HELPERS
	help
	  This WWAN Network Driver implements network stack class device.
	  It supports Embedded data transfer from A7 to Q6. Configures IPA HW
	  for RmNet Data Driver and also exchange of QMI messages between
	  A7 and Q6 IPA-driver.

config ECM_IPA
	tristate "STD ECM LAN Driver support"
	depends on IPA3
	help
	  Enables LAN between applications processor and a tethered
	  host using the STD ECM protocol.
	  This Network interface is aimed to allow data path go through
	  IPA core while using STD ECM protocol.

config RNDIS_IPA
	tristate "RNDIS_IPA Network Interface Driver support"
	depends on IPA3
	help
	  Enables LAN between applications processor and a tethered
	  host using the RNDIS protocol.
	  This Network interface is aimed to allow data path go through
	  IPA core while using RNDIS protocol.

config IPA3_MHI_PROXY
	tristate "IPA3 MHI proxy driver"
	depends on RMNET_IPA3
	help
	  This driver is used as a proxy between modem and MHI host driver.
	  Its main functionality is to setup MHI Satellite channels on behalf of
	  modem and provide the ability of modem to MHI device communication.
	  Once the configuration is done modem will communicate directly with
	  the MHI device without AP involvement, with the exception of
	  power management.

config IPA_UT
	tristate "IPA Unit-Test Framework and Test Suites"
	depends on IPA3 && DEBUG_FS
	help
	  This Module implements IPA in-kernel test framework.
	  The framework supports defining and running tests, grouped
	  into suites according to the sub-unit of the IPA being tested.
	  The user interface to run and control the tests is debugfs file
	  system.

config IPA_EMULATION
	bool "IPA on X86 Linux (IPA emulation support)"
	depends on X86 && IPA3
	help
	  This options is used only when building the X86 version of
	  the IPA/GSI driver. On this mode, IPA driver will be probed
	  as PCIE device (and not platform device) where IPA emulation
	  shall be connected via PCIE to X86 machine.
endmenu
+2 −0
Original line number Diff line number Diff line
@@ -7,3 +7,5 @@
obj-$(CONFIG_MSM_EXT_DISPLAY) += msm_ext_display.o
obj-$(CONFIG_QPNP_REVID) += qpnp-revid.o
obj-$(CONFIG_SPS) += sps/
obj-$(CONFIG_GSI) += gsi/
obj-$(CONFIG_IPA3) += ipa/
+6 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0

gsidbg-$(CONFIG_DEBUG_FS) += gsi_dbg.o
obj-$(CONFIG_GSI) += gsi.o gsidbg.o

obj-$(CONFIG_IPA_EMULATION) += gsi_emulation.o
+3913 −0

File added.

Preview size limit exceeded, changes collapsed.

+314 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
 */

#ifndef GSI_H
#define GSI_H

#include <linux/device.h>
#include <linux/types.h>
#include <linux/completion.h>
#include <linux/mutex.h>
#include <linux/spinlock.h>
#include <linux/msm_gsi.h>
#include <linux/errno.h>
#include <linux/ipc_logging.h>

/*
 * The following for adding code (ie. for EMULATION) not found on x86.
 */
#if defined(CONFIG_IPA_EMULATION)
# include "gsi_emulation_stubs.h"
#endif

#define GSI_ASSERT() \
	BUG()

#define GSI_CHAN_MAX      31
#define GSI_EVT_RING_MAX  24
#define GSI_NO_EVT_ERINDEX 31

#define gsi_readl(c)	({ u32 __v = readl_relaxed(c); __iormb(); __v; })
#define gsi_writel(v, c)	({ __iowmb(); writel_relaxed((v), (c)); })

#define GSI_IPC_LOGGING(buf, fmt, args...) \
	do { \
		if (buf) \
			ipc_log_string((buf), fmt, __func__, __LINE__, \
				## args); \
	} while (0)

#define GSIDBG(fmt, args...) \
	do { \
		dev_dbg(gsi_ctx->dev, "%s:%d " fmt, __func__, __LINE__, \
		## args);\
		if (gsi_ctx) { \
			GSI_IPC_LOGGING(gsi_ctx->ipc_logbuf, \
				"%s:%d " fmt, ## args); \
			GSI_IPC_LOGGING(gsi_ctx->ipc_logbuf_low, \
				"%s:%d " fmt, ## args); \
		} \
	} while (0)

#define GSIDBG_LOW(fmt, args...) \
	do { \
		dev_dbg(gsi_ctx->dev, "%s:%d " fmt, __func__, __LINE__, \
		## args);\
		if (gsi_ctx) { \
			GSI_IPC_LOGGING(gsi_ctx->ipc_logbuf_low, \
				"%s:%d " fmt, ## args); \
		} \
	} while (0)

#define GSIERR(fmt, args...) \
	do { \
		dev_err(gsi_ctx->dev, "%s:%d " fmt, __func__, __LINE__, \
		## args);\
		if (gsi_ctx) { \
			GSI_IPC_LOGGING(gsi_ctx->ipc_logbuf, \
				"%s:%d " fmt, ## args); \
			GSI_IPC_LOGGING(gsi_ctx->ipc_logbuf_low, \
				"%s:%d " fmt, ## args); \
		} \
	} while (0)

#define GSI_IPC_LOG_PAGES 50

enum gsi_evt_ring_state {
	GSI_EVT_RING_STATE_NOT_ALLOCATED = 0x0,
	GSI_EVT_RING_STATE_ALLOCATED = 0x1,
	GSI_EVT_RING_STATE_ERROR = 0xf
};

enum gsi_chan_state {
	GSI_CHAN_STATE_NOT_ALLOCATED = 0x0,
	GSI_CHAN_STATE_ALLOCATED = 0x1,
	GSI_CHAN_STATE_STARTED = 0x2,
	GSI_CHAN_STATE_STOPPED = 0x3,
	GSI_CHAN_STATE_STOP_IN_PROC = 0x4,
	GSI_CHAN_STATE_ERROR = 0xf
};

struct gsi_ring_ctx {
	spinlock_t slock;
	unsigned long base_va;
	uint64_t base;
	uint64_t wp;
	uint64_t rp;
	uint64_t wp_local;
	uint64_t rp_local;
	uint16_t len;
	uint8_t elem_sz;
	uint16_t max_num_elem;
	uint64_t end;
};

struct gsi_chan_dp_stats {
	unsigned long ch_below_lo;
	unsigned long ch_below_hi;
	unsigned long ch_above_hi;
	unsigned long empty_time;
	unsigned long last_timestamp;
};

struct gsi_chan_stats {
	unsigned long queued;
	unsigned long completed;
	unsigned long callback_to_poll;
	unsigned long poll_to_callback;
	unsigned long poll_pending_irq;
	unsigned long invalid_tre_error;
	unsigned long poll_ok;
	unsigned long poll_empty;
	struct gsi_chan_dp_stats dp;
};

struct gsi_chan_ctx {
	struct gsi_chan_props props;
	enum gsi_chan_state state;
	struct gsi_ring_ctx ring;
	void **user_data;
	struct gsi_evt_ctx *evtr;
	struct mutex mlock;
	struct completion compl;
	bool allocated;
	atomic_t poll_mode;
	union __packed gsi_channel_scratch scratch;
	struct gsi_chan_stats stats;
	bool enable_dp_stats;
	bool print_dp_stats;
};

struct gsi_evt_stats {
	unsigned long completed;
};

struct gsi_evt_ctx {
	struct gsi_evt_ring_props props;
	enum gsi_evt_ring_state state;
	uint8_t id;
	struct gsi_ring_ctx ring;
	struct mutex mlock;
	struct completion compl;
	struct gsi_chan_ctx *chan;
	atomic_t chan_ref_cnt;
	union __packed gsi_evt_scratch scratch;
	struct gsi_evt_stats stats;
};

struct gsi_ee_scratch {
	union __packed {
		struct {
			uint32_t inter_ee_cmd_return_code:3;
			uint32_t resvd1:2;
			uint32_t generic_ee_cmd_return_code:3;
			uint32_t resvd2:7;
			uint32_t max_usb_pkt_size:1;
			uint32_t resvd3:8;
			uint32_t mhi_base_chan_idx:8;
		} s;
		uint32_t val;
	} word0;
	uint32_t word1;
};

struct ch_debug_stats {
	unsigned long ch_allocate;
	unsigned long ch_start;
	unsigned long ch_stop;
	unsigned long ch_reset;
	unsigned long ch_de_alloc;
	unsigned long ch_db_stop;
	unsigned long cmd_completed;
};

struct gsi_generic_ee_cmd_debug_stats {
	unsigned long halt_channel;
};

struct gsi_ctx {
	void __iomem *base;
	struct device *dev;
	struct gsi_per_props per;
	bool per_registered;
	struct gsi_chan_ctx chan[GSI_CHAN_MAX];
	struct ch_debug_stats ch_dbg[GSI_CHAN_MAX];
	struct gsi_evt_ctx evtr[GSI_EVT_RING_MAX];
	struct gsi_generic_ee_cmd_debug_stats gen_ee_cmd_dbg;
	struct mutex mlock;
	spinlock_t slock;
	unsigned long evt_bmap;
	bool enabled;
	atomic_t num_chan;
	atomic_t num_evt_ring;
	struct gsi_ee_scratch scratch;
	int num_ch_dp_stats;
	struct workqueue_struct *dp_stat_wq;
	u32 max_ch;
	u32 max_ev;
	struct completion gen_ee_cmd_compl;
	void *ipc_logbuf;
	void *ipc_logbuf_low;
	/*
	 * The following used only on emulation systems.
	 */
	void __iomem *intcntrlr_base;
	u32 intcntrlr_mem_size;
	irq_handler_t intcntrlr_gsi_isr;
	irq_handler_t intcntrlr_client_isr;
};

enum gsi_re_type {
	GSI_RE_XFER = 0x2,
	GSI_RE_IMMD_CMD = 0x3,
	GSI_RE_NOP = 0x4,
};

struct __packed gsi_tre {
	uint64_t buffer_ptr;
	uint16_t buf_len;
	uint16_t resvd1;
	uint16_t chain:1;
	uint16_t resvd4:7;
	uint16_t ieob:1;
	uint16_t ieot:1;
	uint16_t bei:1;
	uint16_t resvd3:5;
	uint8_t re_type;
	uint8_t resvd2;
};

struct __packed gsi_xfer_compl_evt {
	uint64_t xfer_ptr;
	uint16_t len;
	uint8_t resvd1;
	uint8_t code;  /* see gsi_chan_evt */
	uint16_t resvd;
	uint8_t type;
	uint8_t chid;
};

enum gsi_err_type {
	GSI_ERR_TYPE_GLOB = 0x1,
	GSI_ERR_TYPE_CHAN = 0x2,
	GSI_ERR_TYPE_EVT = 0x3,
};

enum gsi_err_code {
	GSI_INVALID_TRE_ERR = 0x1,
	GSI_OUT_OF_BUFFERS_ERR = 0x2,
	GSI_OUT_OF_RESOURCES_ERR = 0x3,
	GSI_UNSUPPORTED_INTER_EE_OP_ERR = 0x4,
	GSI_EVT_RING_EMPTY_ERR = 0x5,
	GSI_NON_ALLOCATED_EVT_ACCESS_ERR = 0x6,
	GSI_HWO_1_ERR = 0x8
};

struct __packed gsi_log_err {
	uint32_t arg3:4;
	uint32_t arg2:4;
	uint32_t arg1:4;
	uint32_t code:4;
	uint32_t resvd:3;
	uint32_t virt_idx:5;
	uint32_t err_type:4;
	uint32_t ee:4;
};

enum gsi_ch_cmd_opcode {
	GSI_CH_ALLOCATE = 0x0,
	GSI_CH_START = 0x1,
	GSI_CH_STOP = 0x2,
	GSI_CH_RESET = 0x9,
	GSI_CH_DE_ALLOC = 0xa,
	GSI_CH_DB_STOP = 0xb,
};

enum gsi_evt_ch_cmd_opcode {
	GSI_EVT_ALLOCATE = 0x0,
	GSI_EVT_RESET = 0x9,
	GSI_EVT_DE_ALLOC = 0xa,
};

enum gsi_generic_ee_cmd_opcode {
	GSI_GEN_EE_CMD_HALT_CHANNEL = 0x1,
	GSI_GEN_EE_CMD_ALLOC_CHANNEL = 0x2,
};

enum gsi_generic_ee_cmd_return_code {
	GSI_GEN_EE_CMD_RETURN_CODE_SUCCESS = 0x1,
	GSI_GEN_EE_CMD_RETURN_CODE_CHANNEL_NOT_RUNNING = 0x2,
	GSI_GEN_EE_CMD_RETURN_CODE_INCORRECT_DIRECTION = 0x3,
	GSI_GEN_EE_CMD_RETURN_CODE_INCORRECT_CHANNEL_TYPE = 0x4,
	GSI_GEN_EE_CMD_RETURN_CODE_INCORRECT_CHANNEL_INDEX = 0x5,
	GSI_GEN_EE_CMD_RETURN_CODE_RETRY = 0x6,
	GSI_GEN_EE_CMD_RETURN_CODE_OUT_OF_RESOURCES = 0x7,
};

extern struct gsi_ctx *gsi_ctx;
void gsi_debugfs_init(void);
uint16_t gsi_find_idx_from_addr(struct gsi_ring_ctx *ctx, uint64_t addr);
void gsi_update_ch_dp_stats(struct gsi_chan_ctx *ctx, uint16_t used);

#endif
Loading