net: introduce Qualcomm IPA driver
Subsystems (6)
cover net: introduce Qualcomm IPA driver
This series presents the driver for the Qualcomm IP Accelerator (IPA). The IPA is a hardware component present in some Qualcomm SoCs that allows network functions--such as routing, filtering, network address translation and aggregation--to be performed without active involvement of the main application processor (AP).
Initially, these advanced features are not supported; the IPA driver simply provides a network interface that makes the modem's LTE network available to the AP. In addition, support is only provided for the IPA found in the Qualcomm SDM845 SoC.
This code is derived from a driver developed internally by Qualcomm. A version of the original source can be seen here:
https://source.codeaurora.org/quic/la/kernel/msm-4.9/tree
in the "drivers/platform/msm/ipa" directory. Many were involved in developing this, but the following individuals deserve explicit acknowledgement for their substantial contributions:
Abhishek Choubey
Ady Abraham
Chaitanya Pratapa
David Arinzon
Ghanim Fodi
Gidon Studinski
Ravi Gummadidala
Shihuan Liu
Skylar Chang
The code has undergone considerable rework to prepare it for incorporation into upstream Linux. Parts of it bear little resemblance to the original driver. Still, some work remains to be done. The current code and its design had a preliminary review, and some changes to the data path implementation were
recommended. These have not yet been addressed:
- Use NAPI for all interfaces, not just RX (and WAN data) endpoints.
- Do more work in the NAPI poll function, including collecting completed TX requests and posting buffers for RX.
- Do not use periodic NOP requests as a way to avoid TX interrupts.
- The NAPI context should be associated with the hardware interrupt (it is now associated with something abstracted from the hardware).
- Use threaded interrupts, to avoid the need for using spinlocks and atomic variables for synchronizing between workqueue and interrupt context.
- Have runtime power management enable and disable IPA clock and interconnects.
Many thanks to Arnd Bergmann, Ilias Apalodimas, and Bjorn Andersson for their early feedback.
While there clearly remains work to do on this, we felt that things are far enough along that it would be helpful to solicit broader input on the code. Major issues are best addressed as soon as possible, and even minor issues when identified help in setting priorities.
This code is dependent on the following two sets of code, which have been posted for review but are not yet accepted upstream:
- Interconnect framework: https://lkml.org/lkml/2018/8/31/444
- SDM845 interconnect provider driver: https://lkml.org/lkml/2018/8/24/25
In addition, it depends on four more bits of code that have not yet been posted for upstream review, but are expected to be available soon:
- clk-rpmh support for IPA from David Dai <[email protected]>
- SDM845 reserved memory from Bjorn Andersson <[email protected]>
- list_cut_end() from Alex Elder <[email protected]>
- FIELD_MAX() in "bitfield.h" from Alex Elder <[email protected]>
This code (including its dependencies) is available in buildable form here, based on kernel v4.19:
remote: ssh://git at git.linaro.org/people/alex.elder/linux.git
branch: qualcomm_ipa-v1
59562facd61a arm64: dts: sdm845: add IPA information
-Alex
Alex Elder (12):
dt-bindings: soc: qcom: add IPA bindings
soc: qcom: ipa: DMA helpers
soc: qcom: ipa: generic software interface
soc: qcom: ipa: immediate commands
soc: qcom: ipa: IPA interrupts and the microcontroller
soc: qcom: ipa: QMI modem communication
soc: qcom: ipa: IPA register abstraction
soc: qcom: ipa: utility functions
soc: qcom: ipa: main IPA source file
soc: qcom: ipa: data path
soc: qcom: ipa: IPA rmnet interface
soc: qcom: ipa: build and "ipa_i.h"
.../devicetree/bindings/soc/qcom/qcom,ipa.txt | 136 ++ .../bindings/soc/qcom/qcom,rmnet-ipa.txt | 15 + drivers/net/ipa/Kconfig | 30 + drivers/net/ipa/Makefile | 7 + drivers/net/ipa/gsi.c | 1685 ++++++++++++++ drivers/net/ipa/gsi.h | 195 ++ drivers/net/ipa/gsi_reg.h | 563 +++++ drivers/net/ipa/ipa_dma.c | 61 + drivers/net/ipa/ipa_dma.h | 61 + drivers/net/ipa/ipa_dp.c | 1994 +++++++++++++++++ drivers/net/ipa/ipa_i.h | 573 +++++ drivers/net/ipa/ipa_interrupts.c | 307 +++ drivers/net/ipa/ipa_main.c | 1400 ++++++++++++ drivers/net/ipa/ipa_qmi.c | 406 ++++ drivers/net/ipa/ipa_qmi.h | 12 + drivers/net/ipa/ipa_qmi_msg.c | 587 +++++ drivers/net/ipa/ipa_qmi_msg.h | 233 ++ drivers/net/ipa/ipa_reg.c | 972 ++++++++ drivers/net/ipa/ipa_reg.h | 614 +++++ drivers/net/ipa/ipa_uc.c | 336 +++ drivers/net/ipa/ipa_utils.c | 1035 +++++++++ drivers/net/ipa/ipahal.c | 541 +++++ drivers/net/ipa/ipahal.h | 253 +++ drivers/net/ipa/msm_rmnet.h | 120 + drivers/net/ipa/rmnet_config.h | 31 + drivers/net/ipa/rmnet_ipa.c | 805 +++++++ 26 files changed, 12972 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt create mode 100644 drivers/net/ipa/Kconfig create mode 100644 drivers/net/ipa/Makefile create mode 100644 drivers/net/ipa/gsi.c create mode 100644 drivers/net/ipa/gsi.h create mode 100644 drivers/net/ipa/gsi_reg.h create mode 100644 drivers/net/ipa/ipa_dma.c create mode 100644 drivers/net/ipa/ipa_dma.h create mode 100644 drivers/net/ipa/ipa_dp.c create mode 100644 drivers/net/ipa/ipa_i.h create mode 100644 drivers/net/ipa/ipa_interrupts.c create mode 100644 drivers/net/ipa/ipa_main.c create mode 100644 drivers/net/ipa/ipa_qmi.c create mode 100644 drivers/net/ipa/ipa_qmi.h create mode 100644 drivers/net/ipa/ipa_qmi_msg.c create mode 100644 drivers/net/ipa/ipa_qmi_msg.h create mode 100644 drivers/net/ipa/ipa_reg.c create mode 100644 drivers/net/ipa/ipa_reg.h create mode 100644 drivers/net/ipa/ipa_uc.c create mode 100644 drivers/net/ipa/ipa_utils.c create mode 100644 drivers/net/ipa/ipahal.c create mode 100644 drivers/net/ipa/ipahal.h create mode 100644 drivers/net/ipa/msm_rmnet.h create mode 100644 drivers/net/ipa/rmnet_config.h create mode 100644 drivers/net/ipa/rmnet_ipa.c
Signature · 1 line
2.17.1
RFC PATCH 1/12 dt-bindings: soc: qcom: add IPA bindings
Add the binding definitions for the "qcom,ipa" and "qcom,rmnet-ipa" device tree nodes.
--- .../devicetree/bindings/soc/qcom/qcom,ipa.txt | 136 ++++++++++++++++++ .../bindings/soc/qcom/qcom,rmnet-ipa.txt | 15 ++ 2 files changed, 151 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +136 -0
@@ -0,0 +1,136 @@ +Qualcomm IPA (IP Accelerator) Driver + +This binding describes the Qualcomm IPA. The IPA is capable of offloading +certain network processing tasks (e.g. filtering, routing, and NAT) from +the main processor. The IPA currently serves only as a network interface, +providing access to an LTE network available via a modem. + +The IPA sits between multiple independent "execution environments," +including the AP subsystem (APSS) and the modem. The IPA presents +a Generic Software Interface (GSI) to each execution environment. +The GSI is an integral part of the IPA, but it is logically isolated +and has a distinct interrupt and a separately-defined address space. + + ---------- ------------- --------- + | | |G| |G| | | + | APSS |===|S| IPA |S|===| Modem | + | | |I| |I| | | + ---------- ------------- --------- + +See also: + bindings/interrupt-controller/interrupts.txt + bindings/interconnect/interconnect.txt + bindings/soc/qcom/qcom,smp2p.txt + bindings/reserved-memory/reserved-memory.txt + bindings/clock/clock-bindings.txt + +All properties defined below are required. + +- compatible: + Must be one of the following compatible strings: + "qcom,ipa-sdm845-modem_init" + "qcom,ipa-sdm845-tz_init" + +-reg: + Resources specyfing the physical address spaces of the IPA and GSI. + +-reg-names: + The names of the address space ranges defined by the "reg" property. + Must be "ipa" and "gsi". + +- interrupts-extended: + Specifies the IRQs used by the IPA. Four cells are required, + specifying: the IPA IRQ; the GSI IRQ; the clock query interrupt + from the modem; and the "ready for stage 2 initialization" + interrupt from the modem. The first two are hardware IRQs; the + third and fourth are SMP2P input interrupts. + +- interrupt-names: + The names of the interrupts defined by the "interrupts-extended" + property. Must be "ipa", "gsi", "ipa-clock-query", and + "ipa-post-init". + +- clocks: + Resource that defines the IPA core clock. + +- clock-names: + The name used for the IPA core clock. Must be "core". + +- interconnects: + Specifies the interconnects used by the IPA. Three cells are + required, specifying: the path from the IPA to memory; from + IPA to internal (SoC resident) memory; and between the AP + subsystem and IPA for register access. + +- interconnect-names: + The names of the interconnects defined by the "interconnects" + property. Must be "memory", "imem", and "config". + +- qcom,smem-states + The state bits used for SMP2P output. Two cells must be specified. + The first indicates whether the value in the second bit is valid + (1 means valid). The second, if valid, defines whether the IPA + clock is enabled (1 means enabled). + +- qcom,smem-state-names + The names of the state bits used for SMP2P output. These must be + "ipa-clock-enabled-valid" and "ipa-clock-enabled". + +- memory-region + A phandle for a reserved memory area that holds the firmware passed + to Trust Zone for authentication. (Note, this is required + only for "qcom,ipa-sdm845-tz_init".) + += EXAMPLE + +The following example represents the IPA present in the SDM845 SoC. It +shows portions of the "modem-smp2p" node to indicate its relationship +with the interrupts and SMEM states used by the IPA. + + modem-smp2p { + compatible = "qcom,smp2p"; + . . . + ipa_smp2p_out: ipa-ap-to-modem { + qcom,entry-name = "ipa"; + #qcom,smem-state-cells = <1>; + }; + + ipa_smp2p_in: ipa-modem-to-ap { + qcom,entry-name = "ipa"; + interrupt-controller; + #interrupt-cells = <2>; + }; + }; + + ipa at 1e00000 { + compatible = "qcom,ipa-sdm845-modem_init"; + + reg = <0x1e40000 0x34000>, + <0x1e04000 0x2c000>; + reg-names = "ipa", + "gsi"; + + interrupts-extended = <&intc 0 311 IRQ_TYPE_LEVEL_HIGH>, + <&intc 0 432 IRQ_TYPE_LEVEL_HIGH>, + <&ipa_smp2p_in 0 IRQ_TYPE_EDGE_RISING>, + <&ipa_smp2p_in 1 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "ipa", + "gsi", + "ipa-clock-query", + "ipa-post-init"; + + clocks = <&rpmhcc RPMH_IPA_CLK>; + clock-names = "core"; + + interconnects = <&qnoc MASTER_IPA &qnoc SLAVE_EBI1>, + <&qnoc MASTER_IPA &qnoc SLAVE_IMEM>, + <&qnoc MASTER_APPSS_PROC &qnoc SLAVE_IPA_CFG>; + interconnect-names = "memory", + "imem", + "config"; + + qcom,smem-states = <&ipa_smp2p_out 0>, + <&ipa_smp2p_out 1>; + qcom,smem-state-names = "ipa-clock-enabled-valid", + "ipa-clock-enabled"; + };
Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt new file +15 -0
@@ -0,0 +1,15 @@ +Qualcomm IPA RMNet Driver + +This binding describes the IPA RMNet driver, which is used to +represent virtual interfaces available on the modem accessed via +the IPA. Other than the compatible string there are no properties +associated with this device. + +- compatible: + Must be "qcom,rmnet-ipa". + += EXAMPLE + + qcom,rmnet-ipa { + compatible = "qcom,rmnet-ipa"; + };
Signature · 1 line
2.17.1
RFC PATCH 2/12 soc: qcom: ipa: DMA helpers
In reply to Alex ElderThis patch includes code implementing the IPA DMA module, which defines a structure to represent a DMA allocation for the IPA device. It's used throughout the IPA code.
--- drivers/net/ipa/ipa_dma.c | 61 +++++++++++++++++++++++++++++++++++++++ drivers/net/ipa/ipa_dma.h | 61 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 drivers/net/ipa/ipa_dma.c create mode 100644 drivers/net/ipa/ipa_dma.h
drivers/net/ipa/ipa_dma.c new file +61 -0
@@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd. +*/ + +#include <linux/types.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/string.h> + +#include "ipa_dma.h" + +static struct device *ipa_dma_dev; + +int ipa_dma_init (struct device *dev,u32 align) +{ +int ret; + +/* Ensure DMA addresses will have the alignment we require */ +if (dma_get_cache_alignment () % align) +return -ENOTSUPP ; + + ret =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (64 )); +if (!ret) + ipa_dma_dev = dev; + +return ret; +} + +void ipa_dma_exit (void ) +{ + ipa_dma_dev =NULL ; +} + +int ipa_dma_alloc (struct ipa_dma_mem *mem,size_t size,gfp_t gfp) +{ +dma_addr_t phys; +void *virt; + + virt =dma_zalloc_coherent (ipa_dma_dev, size, &phys, gfp); +if (!virt) +return -ENOMEM ; + + mem->virt = virt; + mem->phys = phys; + mem->size = size; + +return 0 ; +} + +void ipa_dma_free (struct ipa_dma_mem *mem) +{ +dma_free_coherent (ipa_dma_dev, mem->size, mem->virt, mem->phys); +memset (mem,0 ,sizeof (*mem)); +} + +void *ipa_dma_phys_to_virt (struct ipa_dma_mem *mem,dma_addr_t phys) +{ +return mem->virt + (phys - mem->phys); +}
drivers/net/ipa/ipa_dma.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH 3/12 soc: qcom: ipa: generic software interface
In reply to Alex ElderThis patch contains the code supporting the Generic Software Interface (GSI) used by the IPA. Although the GSI is an integral part of the IPA, it provides a well-defined layer between the AP subsystem (or, for that matter, the modem) and the IPA core.
The GSI code presents an abstract interface through which commands and data transfers can be queued to be implemented on a channel. A hardware independent gsi_xfer_elem structure describes a single transfer, and an array of these can be queued on a channel. The information in the gsi_xfer_elem is converted by the GSI layer into the specific layout required by the hardware.
A channel has an associated event ring, through which completion of channel commands can be signaled. GSI channel commands are completed in order, and may optionally generate an interrupt on completion.
--- drivers/net/ipa/gsi.c | 1685 +++++++++++++++++++++++++++++++++++++ drivers/net/ipa/gsi.h | 195 +++++ drivers/net/ipa/gsi_reg.h | 563 +++++++++++++ 3 files changed, 2443 insertions(+) create mode 100644 drivers/net/ipa/gsi.c create mode 100644 drivers/net/ipa/gsi.h create mode 100644 drivers/net/ipa/gsi_reg.h
drivers/net/ipa/gsi.c new file +1685 -0
@@ -0,0 +1,1685 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd. +*/ + +#include <linux/types.h> +#include <linux/bitops.h> +#include <linux/log2.h> +#include <linux/bitfield.h> +#include <linux/atomic.h> +#include <linux/spinlock.h> +#include <linux/mutex.h> +#include <linux/slab.h> +#include <linux/completion.h> +#include <linux/jiffies.h> +#include <linux/string.h> +#include <linux/device.h> +#include <linux/io.h> +#include <linux/bug.h> +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/platform_device.h> + +#include "gsi.h" +#include "gsi_reg.h" +#include "ipa_dma.h" +#include "ipa_i.h" /* ipa_err() */ + +/** +* DOC: The Role of GSI in IPA Operation +* +* The generic software interface (GSI) is an integral component of +* the IPA, providing a well-defined layer between the AP subsystem +* (or, for that matter, the modem) and the IPA core:: +* +* ---------- ------------- --------- +* | | |G| |G| | | +* | APSS |===|S| IPA |S|===| Modem | +* | | |I| |I| | | +* ---------- ------------- --------- +* +* In the above diagram, the APSS and Modem represent "execution +* environments" (EEs), which are independent operating environments +* that use the IPA for data transfer. +* +* Each EE uses a set of unidirectional GSI "channels," which allow +* transfer of data to or from the IPA. A channel is implemented as a +* ring buffer, with a DRAM-resident array of "transfer elements" (TREs) +* available to describe transfers to or from other EEs through the IPA. +* A transfer element can also contain an immediate command, requesting +* the IPA perform actions other than data transfer. +* +* Each transfer element refers to a block of data--also located DRAM. +* After writing one or more TREs to a channel, the writer (either the +* IPA or an EE) writes a doorbell register to inform the receiving side +* how many elements have been written. Writing to a doorbell register +* triggers an interrupt on the receiver. +* +* Each channel has a GSI "event ring" associated with it. An event +* ring is implemented very much like a channel ring, but is always +* directed from the IPA to an EE. The IPA notifies an EE (such as +* the AP) about channel events by adding an entry to the event ring +* associated with the channel; when it writes the event ring's +* doorbell register the EE will be interrupted. +* +* A transfer element has a set of flags. One flag indicates whether +* the completion of the transfer operation generates a channel event. +* Another flag allows transfer elements to be chained together, +* forming a single logical transaction. These flags are used to +* control whether and when interrupts are generated to signal +* completion of a channel transfer. +* +* Elements in channel and event rings are completed (or consumed) +* strictly in order. Completion of one entry implies the completion +* of all preceding entries. A single completion interrupt can +* therefore be used to communicate the completion of many transfers. +*/ + +#define GSI_RING_ELEMENT_SIZE 16/* bytes (channel or event ring) */ + +#define GSI_CHAN_MAX 14 +#define GSI_EVT_RING_MAX 10 + +/* Delay period if interrupt moderation is in effect */ +#define IPA_GSI_EVT_RING_INT_MODT (32 * 1)/* 1ms under 32KHz clock */ + +#define GSI_CMD_TIMEOUT msecs_to_jiffies(5 * MSEC_PER_SEC) + +#define GSI_MHI_ER_START 10/* First reserved event number */ +#define GSI_MHI_ER_END 16/* Last reserved event number */ + +#define GSI_RESET_WA_MIN_SLEEP 1000/* microseconds */ +#define GSI_RESET_WA_MAX_SLEEP 2000/* microseconds */ + +#define GSI_MAX_PREFETCH 0/* 0 means 1 segment; 1 means 2 */ + +#define GSI_ISR_MAX_ITER 50 + +/* Hardware values from the error log register code field */ +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 , +}; + +/* Hardware values used when programming an event ring context */ +enum gsi_evt_chtype { +GSI_EVT_CHTYPE_MHI_EV =0x0 , +GSI_EVT_CHTYPE_XHCI_EV =0x1 , +GSI_EVT_CHTYPE_GPI_EV =0x2 , +GSI_EVT_CHTYPE_XDCI_EV =0x3 , +}; + +/* Hardware values used when programming a channel context */ +enum gsi_channel_protocol { +GSI_CHANNEL_PROTOCOL_MHI =0x0 , +GSI_CHANNEL_PROTOCOL_XHCI =0x1 , +GSI_CHANNEL_PROTOCOL_GPI =0x2 , +GSI_CHANNEL_PROTOCOL_XDCI =0x3 , +}; + +/* Hardware values returned in a transfer completion event structure */ +enum gsi_channel_evt { +GSI_CHANNEL_EVT_INVALID =0x0 , +GSI_CHANNEL_EVT_SUCCESS =0x1 , +GSI_CHANNEL_EVT_EOT =0x2 , +GSI_CHANNEL_EVT_OVERFLOW =0x3 , +GSI_CHANNEL_EVT_EOB =0x4 , +GSI_CHANNEL_EVT_OOB =0x5 , +GSI_CHANNEL_EVT_DB_MODE =0x6 , +GSI_CHANNEL_EVT_UNDEFINED =0x10 , +GSI_CHANNEL_EVT_RE_ERROR =0x11 , +}; + +/* 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 , +}; + +/* Hardware values signifying the state of a channel */ +enum gsi_channel_state { +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 , +}; + +struct gsi_ring { +spinlock_t slock;/* protects wp, rp updates */ +struct ipa_dma_mem mem; +u64 wp; +u64 rp; +u64 wp_local; +u64 rp_local; +u64 end;/* physical addr past last element */ +}; + +struct gsi_channel { +bool from_ipa;/* true: IPA->AP; false: AP->IPA */ +bool priority;/* Does hardware give this channel priority? */ +enum gsi_channel_state state; +struct gsi_ring ring; +void *notify_data; +void **user_data; +struct gsi_evt_ring *evt_ring; +struct mutex mutex;/* protects channel_scratch updates */ +struct completion compl; +atomic_t poll_mode; +u32 tlv_count;/* # slots in TLV */ +}; + +struct gsi_evt_ring { +bool moderation; +enum gsi_evt_ring_state state; +struct gsi_ring ring; +struct completion compl; +struct gsi_channel *channel; +}; + +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 { +void __iomem *base; +struct device *dev; +u32 phys; +unsigned int irq; +bool irq_wake_enabled; +spinlock_t slock;/* protects global register updates */ +struct mutex mutex;/* protects 1-at-a-time commands, evt_bmap */ +atomic_t channel_count; +atomic_t evt_ring_count; +struct gsi_channel channel[GSI_CHAN_MAX ]; +struct ch_debug_stats ch_dbg[GSI_CHAN_MAX ]; +struct gsi_evt_ring evt_ring[GSI_EVT_RING_MAX ]; +unsigned long evt_bmap; +u32 channel_max; +u32 evt_ring_max; +}; + +/* Hardware values representing a transfer element type */ +enum gsi_re_type { +GSI_RE_XFER =0x2 , +GSI_RE_IMMD_CMD =0x3 , +GSI_RE_NOP =0x4 , +}; + +struct gsi_tre { +u64 buffer_ptr; +u16 buf_len; +u16 rsvd1; +u8 chain :1 , + rsvd4 :7 ; +u8 ieob :1 , + ieot :1 , + bei :1 , + rsvd3 :5 ; +u8 re_type; +u8 rsvd2; +} __packed; + +struct gsi_xfer_compl_evt { +u64 xfer_ptr; +u16 len; +u8 rsvd1; +u8 code;/* see gsi_channel_evt */ +u16 rsvd; +u8 type; +u8 chid; +} __packed; + +/* Hardware values from the error log register error type field */ +enum gsi_err_type { +GSI_ERR_TYPE_GLOB =0x1 , +GSI_ERR_TYPE_CHAN =0x2 , +GSI_ERR_TYPE_EVT =0x3 , +}; + +struct gsi_log_err { +u8 arg3 :4 , + arg2 :4 ; +u8 arg1 :4 , + code :4 ; +u8 rsvd :3 , + virt_idx :5 ; +u8 err_type :4 , + ee :4 ; +} __packed; + +/* Hardware values repreasenting a channel immediate command opcode */ +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 , +}; + +/* Hardware values repreasenting an event ring immediate command opcode */ +enum gsi_evt_ch_cmd_opcode { +GSI_EVT_ALLOCATE =0x0 , +GSI_EVT_RESET =0x9 , +GSI_EVT_DE_ALLOC =0xa , +}; + +/** gsi_gpi_channel_scratch - GPI protocol SW config area of channel scratch +* +* @max_outstanding_tre: Used for the prefetch management sequence by the +* sequencer. Defines the maximum number of allowed +* outstanding TREs in IPA/GSI (in Bytes). RE engine +* prefetch will be limited by this configuration. It +* is suggested to configure this value to IPA_IF +* channel TLV queue size times element size. To disable +* the feature in doorbell mode (DB Mode=1). Maximum +* outstanding TREs should be set to 64KB +* (or any value larger or equal to ring length . RLEN) +* @outstanding_threshold: Used for the prefetch management sequence by the +* sequencer. Defines the threshold (in Bytes) as to when +* to update the channel doorbell. Should be smaller than +* Maximum outstanding TREs. value. It is suggested to +* configure this value to 2 * element size. +*/ +struct gsi_gpi_channel_scratch { +u64 rsvd1; +u16 rsvd2; +u16 max_outstanding_tre; +u16 rsvd3; +u16 outstanding_threshold; +} __packed; + +/** gsi_channel_scratch - channel scratch SW config area */ +union gsi_channel_scratch { +struct gsi_gpi_channel_scratch gpi; +struct { +u32 word1; +u32 word2; +u32 word3; +u32 word4; + } data; +} __packed; + +/* Read a value from the given offset into the I/O space defined in +* the GSI context. +*/ +static u32 gsi_readl (struct gsi *gsi,u32 offset) +{ +return readl (gsi->base + offset); +} + +/* Write the provided value to the given offset into the I/O space +* defined in the GSI context. +*/ +static void gsi_writel (struct gsi *gsi,u32 v,u32 offset) +{ +writel (v, gsi->base + offset); +} + +static void +_gsi_irq_control_event (struct gsi *gsi,u32 evt_ring_id,bool enable) +{ +u32 mask =BIT (evt_ring_id); +u32 val; + + val =gsi_readl (gsi,GSI_CNTXT_SRC_IEOB_IRQ_MSK_OFFS ); +if (enable) + val |= mask; +else + val &= ~mask; +gsi_writel (gsi, val,GSI_CNTXT_SRC_IEOB_IRQ_MSK_OFFS ); +} + +static void gsi_irq_disable_event (struct gsi *gsi,u32 evt_ring_id) +{ +_gsi_irq_control_event (gsi, evt_ring_id, false); +} + +static void gsi_irq_enable_event (struct gsi *gsi,u32 evt_ring_id) +{ +_gsi_irq_control_event (gsi, evt_ring_id, true); +} + +static void _gsi_irq_control_all (struct gsi *gsi,bool enable) +{ +u32 val = enable ? ~0 :0 ; + +/* Inter EE commands / interrupt are no supported. */ +gsi_writel (gsi, val,GSI_CNTXT_TYPE_IRQ_MSK_OFFS ); +gsi_writel (gsi, val,GSI_CNTXT_SRC_CH_IRQ_MSK_OFFS ); +gsi_writel (gsi, val,GSI_CNTXT_SRC_EV_CH_IRQ_MSK_OFFS ); +gsi_writel (gsi, val,GSI_CNTXT_SRC_IEOB_IRQ_MSK_OFFS ); +gsi_writel (gsi, val,GSI_CNTXT_GLOB_IRQ_EN_OFFS ); +/* Never enable GSI_BREAK_POINT */ + val &= ~FIELD_PREP (EN_BREAK_POINT_FMASK ,1 ); +gsi_writel (gsi, val,GSI_CNTXT_GSI_IRQ_EN_OFFS ); +} + +static void gsi_irq_disable_all (struct gsi *gsi) +{ +_gsi_irq_control_all (gsi, false); +} + +static void gsi_irq_enable_all (struct gsi *gsi) +{ +_gsi_irq_control_all (gsi, true); +} + +static u32 gsi_channel_id (struct gsi *gsi,struct gsi_channel *channel) +{ +return (u32)(channel - &gsi->channel[0 ]); +} + +static u32 gsi_evt_ring_id (struct gsi *gsi,struct gsi_evt_ring *evt_ring) +{ +return (u32)(evt_ring - &gsi->evt_ring[0 ]); +} + +static enum gsi_channel_state gsi_channel_state (struct gsi *gsi,u32 channel_id) +{ +u32 val =gsi_readl (gsi,GSI_CH_C_CNTXT_0_OFFS (channel_id)); + +return (enum gsi_channel_state )FIELD_GET (CHSTATE_FMASK , val); +} + +static enum gsi_evt_ring_state +gsi_evt_ring_state (struct gsi *gsi,u32 evt_ring_id) +{ +u32 val =gsi_readl (gsi,GSI_EV_CH_E_CNTXT_0_OFFS (evt_ring_id)); + +return (enum gsi_evt_ring_state )FIELD_GET (EV_CHSTATE_FMASK , val); +} + +static void gsi_isr_chan_ctrl (struct gsi *gsi) +{ +u32 channel_mask; + + channel_mask =gsi_readl (gsi,GSI_CNTXT_SRC_CH_IRQ_OFFS ); +gsi_writel (gsi, channel_mask,GSI_CNTXT_SRC_CH_IRQ_CLR_OFFS ); + +ipa_assert (!(channel_mask & ~GENMASK (gsi->channel_max -1 ,0 ))); + +while (channel_mask) { +struct gsi_channel *channel; +int i =__ffs (channel_mask); + + channel = &gsi->channel[i]; + channel->state =gsi_channel_state (gsi, i); + +complete (&channel->compl); + + channel_mask ^=BIT (i); + } +} + +static void gsi_isr_evt_ctrl (struct gsi *gsi) +{ +u32 evt_mask; + + evt_mask =gsi_readl (gsi,GSI_CNTXT_SRC_EV_CH_IRQ_OFFS ); +gsi_writel (gsi, evt_mask,GSI_CNTXT_SRC_EV_CH_IRQ_CLR_OFFS ); + +ipa_assert (!(evt_mask & ~GENMASK (gsi->evt_ring_max -1 ,0 ))); + +while (evt_mask) { +struct gsi_evt_ring *evt_ring; +int i =__ffs (evt_mask); + + evt_ring = &gsi->evt_ring[i]; + evt_ring->state =gsi_evt_ring_state (gsi, i); + +complete (&evt_ring->compl); + + evt_mask ^=BIT (i); + } +} + +static void +gsi_isr_glob_chan_err (struct gsi *gsi,u32 err_ee,u32 channel_id,u32 code) +{ +struct gsi_channel *channel = &gsi->channel[channel_id]; + +if (err_ee !=IPA_EE_AP ) +ipa_bug_on (code !=GSI_UNSUPPORTED_INTER_EE_OP_ERR ); + +if (WARN_ON (channel_id >= gsi->channel_max)) { +ipa_err ("unexpected channel_id %u\n" , channel_id); +return ; + } + +switch (code) { +case GSI_INVALID_TRE_ERR : +ipa_err ("got INVALID_TRE_ERR\n" ); + channel->state =gsi_channel_state (gsi, channel_id); +ipa_bug_on (channel->state !=GSI_CHANNEL_STATE_ERROR ); +break ; +case GSI_OUT_OF_BUFFERS_ERR : +ipa_err ("got OUT_OF_BUFFERS_ERR\n" ); +break ; +case GSI_OUT_OF_RESOURCES_ERR : +ipa_err ("got OUT_OF_RESOURCES_ERR\n" ); +complete (&channel->compl); +break ; +case GSI_UNSUPPORTED_INTER_EE_OP_ERR : +ipa_err ("got UNSUPPORTED_INTER_EE_OP_ERR\n" ); +break ; +case GSI_NON_ALLOCATED_EVT_ACCESS_ERR : +ipa_err ("got NON_ALLOCATED_EVT_ACCESS_ERR\n" ); +break ; +case GSI_HWO_1_ERR : +ipa_err ("got HWO_1_ERR\n" ); +break ; +default : +ipa_err ("unexpected channel error code %u\n" , code); +ipa_bug (); + } +} + +static void +gsi_isr_glob_evt_err (struct gsi *gsi,u32 err_ee,u32 evt_ring_id,u32 code) +{ +struct gsi_evt_ring *evt_ring = &gsi->evt_ring[evt_ring_id]; + +if (err_ee !=IPA_EE_AP ) +ipa_bug_on (code !=GSI_UNSUPPORTED_INTER_EE_OP_ERR ); + +if (WARN_ON (evt_ring_id >= gsi->evt_ring_max)) { +ipa_err ("unexpected evt_ring_id %u\n" , evt_ring_id); +return ; + } + +switch (code) { +case GSI_OUT_OF_BUFFERS_ERR : +ipa_err ("got OUT_OF_BUFFERS_ERR\n" ); +break ; +case GSI_OUT_OF_RESOURCES_ERR : +ipa_err ("got OUT_OF_RESOURCES_ERR\n" ); +complete (&evt_ring->compl); +break ; +case GSI_UNSUPPORTED_INTER_EE_OP_ERR : +ipa_err ("got UNSUPPORTED_INTER_EE_OP_ERR\n" ); +break ; +case GSI_EVT_RING_EMPTY_ERR : +ipa_err ("got EVT_RING_EMPTY_ERR\n" ); +break ; +default : +ipa_err ("unexpected event error code %u\n" , code); +ipa_bug (); + } +} + +static void gsi_isr_glob_err (struct gsi *gsi,u32 err) +{ +struct gsi_log_err *log = (struct gsi_log_err *)&err; + +ipa_err ("log err_type %u ee %u idx %u\n" , log->err_type, log->ee, + log->virt_idx); +ipa_err ("log code 0x%1x arg1 0x%1x arg2 0x%1x arg3 0x%1x\n" , log->code, + log->arg1, log->arg2, log->arg3); + +ipa_bug_on (log->err_type ==GSI_ERR_TYPE_GLOB ); + +switch (log->err_type) { +case GSI_ERR_TYPE_CHAN : +gsi_isr_glob_chan_err (gsi, log->ee, log->virt_idx, log->code); +break ; +case GSI_ERR_TYPE_EVT : +gsi_isr_glob_evt_err (gsi, log->ee, log->virt_idx, log->code); +break ; +default : +WARN_ON (1 ); + } +} + +static void gsi_isr_glob_ee (struct gsi *gsi) +{ +u32 val; + + val =gsi_readl (gsi,GSI_CNTXT_GLOB_IRQ_STTS_OFFS ); + +if (val &ERROR_INT_FMASK ) { +u32 err =gsi_readl (gsi,GSI_ERROR_LOG_OFFS ); + +gsi_writel (gsi,0 ,GSI_ERROR_LOG_OFFS ); +gsi_writel (gsi, ~0 ,GSI_ERROR_LOG_CLR_OFFS ); + +gsi_isr_glob_err (gsi, err); + } + +if (val &EN_GP_INT1_FMASK ) +ipa_err ("unexpected GP INT1 received\n" ); + +ipa_bug_on (val &EN_GP_INT2_FMASK ); +ipa_bug_on (val &EN_GP_INT3_FMASK ); + +gsi_writel (gsi, val,GSI_CNTXT_GLOB_IRQ_CLR_OFFS ); +} + +static void ring_wp_local_inc (struct gsi_ring *ring) +{ + ring->wp_local +=GSI_RING_ELEMENT_SIZE ; +if (ring->wp_local == ring->end) + ring->wp_local = ring->mem.phys; +} + +static void ring_rp_local_inc (struct gsi_ring *ring) +{ + ring->rp_local +=GSI_RING_ELEMENT_SIZE ; +if (ring->rp_local == ring->end) + ring->rp_local = ring->mem.phys; +} + +static u16 ring_rp_local_index (struct gsi_ring *ring) +{ +return (u16)(ring->rp_local - ring->mem.phys) /GSI_RING_ELEMENT_SIZE ; +} + +static u16 ring_wp_local_index (struct gsi_ring *ring) +{ +return (u16)(ring->wp_local - ring->mem.phys) /GSI_RING_ELEMENT_SIZE ; +} + +static void channel_xfer_cb (struct gsi_channel *channel,u16 count) +{ +void *xfer_data; + +if (!channel->from_ipa) { +u16 ring_rp_local =ring_rp_local_index (&channel->ring); + + xfer_data = channel->user_data[ring_rp_local];; +ipa_gsi_irq_tx_notify_cb (xfer_data); + }else { +ipa_gsi_irq_rx_notify_cb (channel->notify_data, count); + } +} + +static u16 gsi_channel_process (struct gsi *gsi,struct gsi_xfer_compl_evt *evt, +bool callback) +{ +struct gsi_channel *channel; +u32 channel_id = (u32 )evt->chid; + +ipa_assert (channel_id < gsi->channel_max); + +/* Event tells us the last completed channel ring element */ + channel = &gsi->channel[channel_id]; + channel->ring.rp_local = evt->xfer_ptr; + +if (callback) { +if (evt->code ==GSI_CHANNEL_EVT_EOT ) +channel_xfer_cb (channel, evt->len); +else +ipa_err ("ch %u unexpected %sX event id %hhu\n" , + channel_id, channel->from_ipa ?"R" :"T" , + evt->code); + } + +/* Record that we've processed this channel ring element. */ +ring_rp_local_inc (&channel->ring); + channel->ring.rp = channel->ring.rp_local; + +return evt->len; +} + +static void +gsi_evt_ring_doorbell (struct gsi *gsi,struct gsi_evt_ring *evt_ring) +{ +u32 evt_ring_id =gsi_evt_ring_id (gsi, evt_ring); +u32 val; + +/* The doorbell 0 and 1 registers store the low-order and +* high-order 32 bits of the event ring doorbell register, +* respectively. LSB (doorbell 0) must be written last. +*/ + val = evt_ring->ring.wp_local >>32 ; +gsi_writel (gsi, val,GSI_EV_CH_E_DOORBELL_1_OFFS (evt_ring_id)); + + val = evt_ring->ring.wp_local &GENMASK (31 ,0 ); +gsi_writel (gsi, val,GSI_EV_CH_E_DOORBELL_0_OFFS (evt_ring_id)); +} + +static void gsi_channel_doorbell (struct gsi *gsi,struct gsi_channel *channel) +{ +u32 channel_id =gsi_channel_id (gsi, channel); +u32 val; + +/* allocate new events for this channel first +* before submitting the new TREs. +* for TO_GSI channels the event ring doorbell is rang as part of +* interrupt handling. +*/ +if (channel->from_ipa) +gsi_evt_ring_doorbell (gsi, channel->evt_ring); + channel->ring.wp = channel->ring.wp_local; + +/* The doorbell 0 and 1 registers store the low-order and +* high-order 32 bits of the channel ring doorbell register, +* respectively. LSB (doorbell 0) must be written last. +*/ + val = channel->ring.wp_local >>32 ; +gsi_writel (gsi, val,GSI_CH_C_DOORBELL_1_OFFS (channel_id)); + val = channel->ring.wp_local &GENMASK (31 ,0 ); +gsi_writel (gsi, val,GSI_CH_C_DOORBELL_0_OFFS (channel_id)); +} + +static void gsi_event_handle (struct gsi *gsi,u32 evt_ring_id) +{ +struct gsi_evt_ring *evt_ring = &gsi->evt_ring[evt_ring_id]; +unsigned long flags; +bool check_again; + +spin_lock_irqsave (&evt_ring->ring.slock, flags); + +do { +u32 val =gsi_readl (gsi,GSI_EV_CH_E_CNTXT_4_OFFS (evt_ring_id)); + + evt_ring->ring.rp = evt_ring->ring.rp &GENMASK_ULL (63 ,32 ); + evt_ring->ring.rp |= val; + + check_again = false; +while (evt_ring->ring.rp_local != evt_ring->ring.rp) { +struct gsi_xfer_compl_evt *evt; + +if (atomic_read (&evt_ring->channel->poll_mode)) { + check_again = false; +break ; + } + check_again = true; + + evt =ipa_dma_phys_to_virt (&evt_ring->ring.mem, + evt_ring->ring.rp_local); + (void )gsi_channel_process (gsi, evt, true); + +ring_rp_local_inc (&evt_ring->ring); +ring_wp_local_inc (&evt_ring->ring);/* recycle */ + } + +gsi_evt_ring_doorbell (gsi, evt_ring); + }while (check_again); + +spin_unlock_irqrestore (&evt_ring->ring.slock, flags); +} + +static void gsi_isr_ioeb (struct gsi *gsi) +{ +u32 evt_mask; + + evt_mask =gsi_readl (gsi,GSI_CNTXT_SRC_IEOB_IRQ_OFFS ); + evt_mask &=gsi_readl (gsi,GSI_CNTXT_SRC_IEOB_IRQ_MSK_OFFS ); +gsi_writel (gsi, evt_mask,GSI_CNTXT_SRC_IEOB_IRQ_CLR_OFFS ); + +ipa_assert (!(evt_mask & ~GENMASK (gsi->evt_ring_max -1 ,0 ))); + +while (evt_mask) { +u32 i = (u32 )__ffs (evt_mask); + +gsi_event_handle (gsi, i); + + evt_mask ^=BIT (i); + } +} + +static void gsi_isr_inter_ee_chan_ctrl (struct gsi *gsi) +{ +u32 channel_mask; + + channel_mask =gsi_readl (gsi,GSI_INTER_EE_SRC_CH_IRQ_OFFS ); +gsi_writel (gsi, channel_mask,GSI_INTER_EE_SRC_CH_IRQ_CLR_OFFS ); + +ipa_assert (!(channel_mask & ~GENMASK (gsi->channel_max -1 ,0 ))); + +while (channel_mask) { +int i =__ffs (channel_mask); + +/* not currently expected */ +ipa_err ("ch %d was inter-EE changed\n" , i); + channel_mask ^=BIT (i); + } +} + +static void gsi_isr_inter_ee_evt_ctrl (struct gsi *gsi) +{ +u32 evt_mask; + + evt_mask =gsi_readl (gsi,GSI_INTER_EE_SRC_EV_CH_IRQ_OFFS ); +gsi_writel (gsi, evt_mask,GSI_INTER_EE_SRC_EV_CH_IRQ_CLR_OFFS ); + +ipa_assert (!(evt_mask & ~GENMASK (gsi->evt_ring_max -1 ,0 ))); + +while (evt_mask) { +u32 i = (u32 )__ffs (evt_mask); + +/* not currently expected */ +ipa_err ("evt %d was inter-EE changed\n" , i); + evt_mask ^=BIT (i); + } +} + +static void gsi_isr_general (struct gsi *gsi) +{ +u32 val; + + val =gsi_readl (gsi,GSI_CNTXT_GSI_IRQ_STTS_OFFS ); + +ipa_bug_on (val &CLR_MCS_STACK_OVRFLOW_FMASK ); +ipa_bug_on (val &CLR_CMD_FIFO_OVRFLOW_FMASK ); +ipa_bug_on (val &CLR_BUS_ERROR_FMASK ); + +if (val &CLR_BREAK_POINT_FMASK ) +ipa_err ("got breakpoint\n" ); + +gsi_writel (gsi, val,GSI_CNTXT_GSI_IRQ_CLR_OFFS ); +} + +/* Returns a bitmask of pending GSI interrupts */ +static u32 gsi_isr_type (struct gsi *gsi) +{ +return gsi_readl (gsi,GSI_CNTXT_TYPE_IRQ_OFFS ); +} + +static irqreturn_t gsi_isr (int irq,void *dev_id) +{ +struct gsi *gsi = dev_id; +u32 type; +u32 cnt; + + cnt =0 ; +while ((type =gsi_isr_type (gsi))) { +do { +u32 single =BIT (__ffs (type)); + +switch (single) { +case CH_CTRL_FMASK : +gsi_isr_chan_ctrl (gsi); +break ; +case EV_CTRL_FMASK : +gsi_isr_evt_ctrl (gsi); +break ; +case GLOB_EE_FMASK : +gsi_isr_glob_ee (gsi); +break ; +case IEOB_FMASK : +gsi_isr_ioeb (gsi); +break ; +case INTER_EE_CH_CTRL_FMASK : +gsi_isr_inter_ee_chan_ctrl (gsi); +break ; +case INTER_EE_EV_CTRL_FMASK : +gsi_isr_inter_ee_evt_ctrl (gsi); +break ; +case GENERAL_FMASK : +gsi_isr_general (gsi); +break ; +default : +WARN (true,"%s: unrecognized type 0x%08x\n" , + __func__, single); +break ; + } + type ^= single; + }while (type); + +ipa_bug_on (++cnt >GSI_ISR_MAX_ITER ); + } + +return IRQ_HANDLED ; +} + +static u32 gsi_channel_max (struct gsi *gsi) +{ +u32 val =gsi_readl (gsi,GSI_GSI_HW_PARAM_2_OFFS ); + +return FIELD_GET (NUM_CH_PER_EE_FMASK , val); +} + +static u32 gsi_evt_ring_max (struct gsi *gsi) +{ +u32 val =gsi_readl (gsi,GSI_GSI_HW_PARAM_2_OFFS ); + +return FIELD_GET (NUM_EV_PER_EE_FMASK , val); +} + +/* Zero bits in an event bitmap represent event numbers available +* for allocation. Initialize the map so all events supported by +* the hardware are available; then preclude any reserved events +* from allocation. +*/ +static u32 gsi_evt_bmap_init (u32 evt_ring_max) +{ +u32 evt_bmap =GENMASK (BITS_PER_LONG -1 , evt_ring_max); + +return evt_bmap |GENMASK (GSI_MHI_ER_END ,GSI_MHI_ER_START ); +} + +int gsi_device_init (struct gsi *gsi) +{ +u32 evt_ring_max; +u32 channel_max; +u32 val; +int ret; + + val =gsi_readl (gsi,GSI_GSI_STATUS_OFFS ); +if (!(val &ENABLED_FMASK )) { +ipa_err ("manager EE has not enabled GSI, GSI un-usable\n" ); +return -EIO ; + } + + channel_max =gsi_channel_max (gsi); +ipa_debug ("channel_max %u\n" , channel_max); +ipa_assert (channel_max <=GSI_CHAN_MAX ); + + evt_ring_max =gsi_evt_ring_max (gsi); +ipa_debug ("evt_ring_max %u\n" , evt_ring_max); +ipa_assert (evt_ring_max <=GSI_EVT_RING_MAX ); + + ret =request_irq (gsi->irq, gsi_isr,IRQF_TRIGGER_HIGH ,"gsi" , gsi); +if (ret) { +ipa_err ("failed to register isr for %u\n" , gsi->irq); +return -EIO ; + } + + ret =enable_irq_wake (gsi->irq); +if (ret) +ipa_err ("error %d enabling gsi wake irq\n" , ret); + gsi->irq_wake_enabled = !ret; + gsi->channel_max = channel_max; + gsi->evt_ring_max = evt_ring_max; + gsi->evt_bmap =gsi_evt_bmap_init (evt_ring_max); + +/* Enable all IPA interrupts */ +gsi_irq_enable_all (gsi); + +/* Writing 1 indicates IRQ interrupts; 0 would be MSI */ +gsi_writel (gsi,1 ,GSI_CNTXT_INTSET_OFFS ); + +/* Initialize the error log */ +gsi_writel (gsi,0 ,GSI_ERROR_LOG_OFFS ); + +return 0 ; +} + +void gsi_device_exit (struct gsi *gsi) +{ +ipa_assert (!atomic_read (&gsi->channel_count)); +ipa_assert (!atomic_read (&gsi->evt_ring_count)); + +/* Don't bother clearing the error log again (ERROR_LOG) or +* setting the interrupt type again (INTSET). +*/ +gsi_irq_disable_all (gsi); + +/* Clean up everything else set up by gsi_device_init() */ + gsi->evt_bmap =0 ; + gsi->evt_ring_max =0 ; + gsi->channel_max =0 ; +if (gsi->irq_wake_enabled) { + (void )disable_irq_wake (gsi->irq); + gsi->irq_wake_enabled = false; + } +free_irq (gsi->irq, gsi); + gsi->irq =0 ; +} + +static void gsi_evt_ring_program (struct gsi *gsi,u32 evt_ring_id) +{ +struct gsi_evt_ring *evt_ring = &gsi->evt_ring[evt_ring_id]; +u32 int_modt; +u32 int_modc; +u64 phys; +u32 val; + + phys = evt_ring->ring.mem.phys; + int_modt = evt_ring->moderation ?IPA_GSI_EVT_RING_INT_MODT :0 ; + int_modc =1 ;/* moderation always comes from channel*/ + + val =FIELD_PREP (EV_CHTYPE_FMASK ,GSI_EVT_CHTYPE_GPI_EV ); + val |=FIELD_PREP (EV_INTYPE_FMASK ,1 ); + val |=FIELD_PREP (EV_ELEMENT_SIZE_FMASK ,GSI_RING_ELEMENT_SIZE ); +gsi_writel (gsi, val,GSI_EV_CH_E_CNTXT_0_OFFS (evt_ring_id)); + + val =FIELD_PREP (EV_R_LENGTH_FMASK , (u32 )evt_ring->ring.mem.size); +gsi_writel (gsi, val,GSI_EV_CH_E_CNTXT_1_OFFS (evt_ring_id)); + +/* The context 2 and 3 registers store the low-order and +* high-order 32 bits of the address of the event ring, +* respectively. +*/ + val = phys &GENMASK (31 ,0 ); +gsi_writel (gsi, val,GSI_EV_CH_E_CNTXT_2_OFFS (evt_ring_id)); + + val = phys >>32 ; +gsi_writel (gsi, val,GSI_EV_CH_E_CNTXT_3_OFFS (evt_ring_id)); + + val =FIELD_PREP (MODT_FMASK , int_modt); + val |=FIELD_PREP (MODC_FMASK , int_modc); +gsi_writel (gsi, val,GSI_EV_CH_E_CNTXT_8_OFFS (evt_ring_id)); + +/* No MSI write data, and MSI address high and low address is 0 */ +gsi_writel (gsi,0 ,GSI_EV_CH_E_CNTXT_9_OFFS (evt_ring_id)); +gsi_writel (gsi,0 ,GSI_EV_CH_E_CNTXT_10_OFFS (evt_ring_id)); +gsi_writel (gsi,0 ,GSI_EV_CH_E_CNTXT_11_OFFS (evt_ring_id)); + +/* We don't need to get event read pointer updates */ +gsi_writel (gsi,0 ,GSI_EV_CH_E_CNTXT_12_OFFS (evt_ring_id)); +gsi_writel (gsi,0 ,GSI_EV_CH_E_CNTXT_13_OFFS (evt_ring_id)); +} + +static void gsi_ring_init (struct gsi_ring *ring) +{ + ring->wp_local = ring->wp = ring->mem.phys; + ring->rp_local = ring->rp = ring->mem.phys; +} + +static int gsi_ring_alloc (struct gsi_ring *ring,u32 count) +{ +size_t size =roundup_pow_of_two (count *GSI_RING_ELEMENT_SIZE ); + +/* Hardware requires a power-of-2 ring size (and alignment) */ +if (ipa_dma_alloc (&ring->mem, size,GFP_KERNEL )) +return -ENOMEM ; +ipa_assert (!(ring->mem.phys % size)); + + ring->end = ring->mem.phys + size; +spin_lock_init (&ring->slock); + +return 0 ; +} + +static void gsi_ring_free (struct gsi_ring *ring) +{ +ipa_dma_free (&ring->mem); +memset (ring,0 ,sizeof (*ring)); +} + +static void gsi_evt_ring_prime (struct gsi *gsi,struct gsi_evt_ring *evt_ring) +{ +unsigned long flags; + +spin_lock_irqsave (&evt_ring->ring.slock, flags); +memset (evt_ring->ring.mem.virt,0 , evt_ring->ring.mem.size); + evt_ring->ring.wp_local = evt_ring->ring.end -GSI_RING_ELEMENT_SIZE ; +gsi_evt_ring_doorbell (gsi, evt_ring); +spin_unlock_irqrestore (&evt_ring->ring.slock, flags); +} + +/* Issue a GSI command by writing a value to a register, then wait +* for completion to be signaled. Returns true if successful or +* false if a timeout occurred. Note that the register offset is +* first, value to write is second (reverse of writel() order). +*/ +static bool command (struct gsi *gsi,u32 reg,u32 val,struct completion *compl) +{ +bool ret; + +gsi_writel (gsi, val, reg); + ret = !!wait_for_completion_timeout (compl,GSI_CMD_TIMEOUT ); +if (!ret) +ipa_err ("command timeout\n" ); + +return ret; +} + +/* Issue an event ring command and wait for it to complete */ +static bool evt_ring_command (struct gsi *gsi,u32 evt_ring_id, +enum gsi_evt_ch_cmd_opcode op) +{ +struct completion *compl = &gsi->evt_ring[evt_ring_id].compl; +u32 val; + +reinit_completion (compl); + + val =FIELD_PREP (EV_CHID_FMASK , evt_ring_id); + val |=FIELD_PREP (EV_OPCODE_FMASK , (u32 )op); + +return command (gsi,GSI_EV_CH_CMD_OFFS , val, compl); +} + +/* Issue a channel command and wait for it to complete */ +static bool +channel_command (struct gsi *gsi,u32 channel_id,enum gsi_ch_cmd_opcode op) +{ +struct completion *compl = &gsi->channel[channel_id].compl; +u32 val; + +reinit_completion (compl); + + val =FIELD_PREP (CH_CHID_FMASK , channel_id); + val |=FIELD_PREP (CH_OPCODE_FMASK , (u32 )op); + +return command (gsi,GSI_CH_CMD_OFFS , val, compl); +} + +/* Note: only GPI interfaces, IRQ interrupts are currently supported */ +static int gsi_evt_ring_alloc (struct gsi *gsi,u32 ring_count,bool moderation) +{ +struct gsi_evt_ring *evt_ring; +unsigned long flags; +u32 evt_ring_id; +u32 val; +int ret; + +/* Get the mutex to allocate from the bitmap and issue a command */ +mutex_lock (&gsi->mutex); + +/* Start by allocating the event id to use */ +ipa_assert (gsi->evt_bmap != ~0UL ); + evt_ring_id = (u32 )ffz (gsi->evt_bmap); + gsi->evt_bmap |=BIT (evt_ring_id); + + evt_ring = &gsi->evt_ring[evt_ring_id]; + + ret =gsi_ring_alloc (&evt_ring->ring, ring_count); +if (ret) + goto err_free_bmap; + +init_completion (&evt_ring->compl); + +if (!evt_ring_command (gsi, evt_ring_id,GSI_EVT_ALLOCATE )) { + ret = -ETIMEDOUT ; + goto err_free_ring; + } + +if (evt_ring->state !=GSI_EVT_RING_STATE_ALLOCATED ) { +ipa_err ("evt_ring_id %u allocation failed state %u\n" , + evt_ring_id, evt_ring->state); + ret = -ENOMEM ; + goto err_free_ring; + } +atomic_inc (&gsi->evt_ring_count); + + evt_ring->moderation = moderation; + +gsi_evt_ring_program (gsi, evt_ring_id); +gsi_ring_init (&evt_ring->ring); +gsi_evt_ring_prime (gsi, evt_ring); + +mutex_unlock (&gsi->mutex); + +spin_lock_irqsave (&gsi->slock, flags); + +/* Enable the event interrupt (clear it first in case pending) */ + val =BIT (evt_ring_id); +gsi_writel (gsi, val,GSI_CNTXT_SRC_IEOB_IRQ_CLR_OFFS ); +gsi_irq_enable_event (gsi, evt_ring_id); + +spin_unlock_irqrestore (&gsi->slock, flags); + +return evt_ring_id; + +err_free_ring: +gsi_ring_free (&evt_ring->ring); +memset (evt_ring,0 ,sizeof (*evt_ring)); +err_free_bmap: +ipa_assert (gsi->evt_bmap &BIT (evt_ring_id)); + gsi->evt_bmap &= ~BIT (evt_ring_id); + +mutex_unlock (&gsi->mutex); + +return ret; +} + +static void gsi_evt_ring_scratch_zero (struct gsi *gsi,u32 evt_ring_id) +{ +gsi_writel (gsi,0 ,GSI_EV_CH_E_SCRATCH_0_OFFS (evt_ring_id)); +gsi_writel (gsi,0 ,GSI_EV_CH_E_SCRATCH_1_OFFS (evt_ring_id)); +} + +static void gsi_evt_ring_dealloc (struct gsi *gsi,u32 evt_ring_id) +{ +struct gsi_evt_ring *evt_ring = &gsi->evt_ring[evt_ring_id]; +bool completed; + +ipa_bug_on (evt_ring->state !=GSI_EVT_RING_STATE_ALLOCATED ); + +mutex_lock (&gsi->mutex); + + completed =evt_ring_command (gsi, evt_ring_id,GSI_EVT_RESET ); +ipa_bug_on (!completed); +ipa_bug_on (evt_ring->state !=GSI_EVT_RING_STATE_ALLOCATED ); + +gsi_evt_ring_program (gsi, evt_ring_id); +gsi_ring_init (&evt_ring->ring); +gsi_evt_ring_scratch_zero (gsi, evt_ring_id); +gsi_evt_ring_prime (gsi, evt_ring); + + completed =evt_ring_command (gsi, evt_ring_id,GSI_EVT_DE_ALLOC ); +ipa_bug_on (!completed); + +ipa_bug_on (evt_ring->state !=GSI_EVT_RING_STATE_NOT_ALLOCATED ); + +ipa_assert (gsi->evt_bmap &BIT (evt_ring_id)); + gsi->evt_bmap &= ~BIT (evt_ring_id); + +mutex_unlock (&gsi->mutex); + + evt_ring->moderation = false; +gsi_ring_free (&evt_ring->ring); +memset (evt_ring,0 ,sizeof (*evt_ring)); + +atomic_dec (&gsi->evt_ring_count); +} + +static void gsi_channel_program (struct gsi *gsi,u32 channel_id, +u32 evt_ring_id,bool doorbell_enable) +{ +struct gsi_channel *channel = &gsi->channel[channel_id]; +u32 low_weight; +u32 val; + + val =FIELD_PREP (CHTYPE_PROTOCOL_FMASK ,GSI_CHANNEL_PROTOCOL_GPI ); + val |=FIELD_PREP (CHTYPE_DIR_FMASK , channel->from_ipa ?0 :1 ); + val |=FIELD_PREP (ERINDEX_FMASK , evt_ring_id); + val |=FIELD_PREP (ELEMENT_SIZE_FMASK ,GSI_RING_ELEMENT_SIZE ); +gsi_writel (gsi, val,GSI_CH_C_CNTXT_0_OFFS (channel_id)); + + val =FIELD_PREP (R_LENGTH_FMASK , channel->ring.mem.size); +gsi_writel (gsi, val,GSI_CH_C_CNTXT_1_OFFS (channel_id)); + +/* The context 2 and 3 registers store the low-order and +* high-order 32 bits of the address of the channel ring, +* respectively. +*/ + val = channel->ring.mem.phys &GENMASK (31 ,0 ); +gsi_writel (gsi, val,GSI_CH_C_CNTXT_2_OFFS (channel_id)); + + val = channel->ring.mem.phys >>32 ; +gsi_writel (gsi, val,GSI_CH_C_CNTXT_3_OFFS (channel_id)); + + low_weight = channel->priority ?FIELD_MAX (WRR_WEIGHT_FMASK ) :0 ; + val =FIELD_PREP (WRR_WEIGHT_FMASK , low_weight); + val |=FIELD_PREP (MAX_PREFETCH_FMASK ,GSI_MAX_PREFETCH ); + val |=FIELD_PREP (USE_DB_ENG_FMASK , doorbell_enable ?1 :0 ); +gsi_writel (gsi, val,GSI_CH_C_QOS_OFFS (channel_id)); +} + +int gsi_channel_alloc (struct gsi *gsi,u32 channel_id,u32 channel_count, +bool from_ipa,bool priority,u32 evt_ring_mult, +bool moderation,void *notify_data) +{ +struct gsi_channel *channel = &gsi->channel[channel_id]; +u32 evt_ring_count; +u32 evt_ring_id; +void **user_data; +int ret; + + evt_ring_count = channel_count * evt_ring_mult; + ret =gsi_evt_ring_alloc (gsi, evt_ring_count, moderation); +if (ret <0 ) +return ret; + evt_ring_id = (u32 )ret; + + ret =gsi_ring_alloc (&channel->ring, channel_count); +if (ret) + goto err_evt_ring_free; + + user_data =kcalloc (channel_count,sizeof (void *),GFP_KERNEL ); +if (!user_data) { + ret = -ENOMEM ; + goto err_ring_free; + } + +mutex_init (&channel->mutex); +init_completion (&channel->compl); +atomic_set (&channel->poll_mode,0 );/* Initially in callback mode */ + channel->from_ipa = from_ipa; + channel->notify_data = notify_data; + +mutex_lock (&gsi->mutex); + +if (!channel_command (gsi, channel_id,GSI_CH_ALLOCATE )) { + ret = -ETIMEDOUT ; + goto err_mutex_unlock; + } +if (channel->state !=GSI_CHANNEL_STATE_ALLOCATED ) { + ret = -EIO ; + goto err_mutex_unlock; + } + + gsi->ch_dbg[channel_id].ch_allocate++; + +mutex_unlock (&gsi->mutex); + + channel->evt_ring = &gsi->evt_ring[evt_ring_id]; + channel->evt_ring->channel = channel; + channel->priority = priority; + +gsi_channel_program (gsi, channel_id, evt_ring_id, true); +gsi_ring_init (&channel->ring); + + channel->user_data = user_data; +atomic_inc (&gsi->channel_count); + +return 0 ; + +err_mutex_unlock: +mutex_unlock (&gsi->mutex); +kfree (user_data); +err_ring_free: +gsi_ring_free (&channel->ring); +err_evt_ring_free: +gsi_evt_ring_dealloc (gsi, evt_ring_id); + +return ret; +} + +static void __gsi_channel_scratch_write (struct gsi *gsi,u32 channel_id) +{ +struct gsi_channel *channel = &gsi->channel[channel_id]; +struct gsi_gpi_channel_scratch *gpi; +union gsi_channel_scratch scr = { }; +u32 val; + + gpi = &scr.gpi; +/* See comments above definition of gsi_gpi_channel_scratch */ + gpi->max_outstanding_tre = channel->tlv_count *GSI_RING_ELEMENT_SIZE ; + gpi->outstanding_threshold =2 *GSI_RING_ELEMENT_SIZE ; + + val = scr.data.word1; +gsi_writel (gsi, val,GSI_CH_C_SCRATCH_0_OFFS (channel_id)); + + val = scr.data.word2; +gsi_writel (gsi, val,GSI_CH_C_SCRATCH_1_OFFS (channel_id)); + + val = scr.data.word3; +gsi_writel (gsi, val,GSI_CH_C_SCRATCH_2_OFFS (channel_id)); + +/* We must preserve the upper 16 bits of the last scratch +* register. The next sequence assumes those bits remain +* unchanged between the read and the write. +*/ + val =gsi_readl (gsi,GSI_CH_C_SCRATCH_3_OFFS (channel_id)); + val = (scr.data.word4 &GENMASK (31 ,16 )) | (val &GENMASK (15 ,0 )); +gsi_writel (gsi, val,GSI_CH_C_SCRATCH_3_OFFS (channel_id)); +} + +void gsi_channel_scratch_write (struct gsi *gsi,u32 channel_id,u32 tlv_count) +{ +struct gsi_channel *channel = &gsi->channel[channel_id]; + + channel->tlv_count = tlv_count; + +mutex_lock (&channel->mutex); + +__gsi_channel_scratch_write (gsi, channel_id); + +mutex_unlock (&channel->mutex); +} + +int gsi_channel_start (struct gsi *gsi,u32 channel_id) +{ +struct gsi_channel *channel = &gsi->channel[channel_id]; + +if (channel->state !=GSI_CHANNEL_STATE_ALLOCATED && + channel->state !=GSI_CHANNEL_STATE_STOP_IN_PROC && + channel->state !=GSI_CHANNEL_STATE_STOPPED ) { +ipa_err ("bad state %d\n" , channel->state); +return -ENOTSUPP ; + } + +mutex_lock (&gsi->mutex); + + gsi->ch_dbg[channel_id].ch_start++; + +if (!channel_command (gsi, channel_id,GSI_CH_START )) { +mutex_unlock (&gsi->mutex); +return -ETIMEDOUT ; + } +if (channel->state !=GSI_CHANNEL_STATE_STARTED ) { +ipa_err ("channel %u unexpected state %u\n" , channel_id, + channel->state); +ipa_bug (); + } + +mutex_unlock (&gsi->mutex); + +return 0 ; +} + +int gsi_channel_stop (struct gsi *gsi,u32 channel_id) +{ +struct gsi_channel *channel = &gsi->channel[channel_id]; +int ret; + +if (channel->state ==GSI_CHANNEL_STATE_STOPPED ) +return 0 ; + +if (channel->state !=GSI_CHANNEL_STATE_STARTED && + channel->state !=GSI_CHANNEL_STATE_STOP_IN_PROC && + channel->state !=GSI_CHANNEL_STATE_ERROR ) { +ipa_err ("bad state %d\n" , channel->state); +return -ENOTSUPP ; + } + +mutex_lock (&gsi->mutex); + + gsi->ch_dbg[channel_id].ch_stop++; + +if (!channel_command (gsi, channel_id,GSI_CH_STOP )) { +/* check channel state here in case the channel is stopped but +* the interrupt was not handled yet. +*/ + channel->state =gsi_channel_state (gsi, channel_id); +if (channel->state ==GSI_CHANNEL_STATE_STOPPED ) { + ret =0 ; + goto free_lock; + } + ret = -ETIMEDOUT ; + goto free_lock; + } + +if (channel->state !=GSI_CHANNEL_STATE_STOPPED && + channel->state !=GSI_CHANNEL_STATE_STOP_IN_PROC ) { +ipa_err ("channel %u unexpected state %u\n" , channel_id, + channel->state); + ret = -EBUSY ; + goto free_lock; + } + +if (channel->state ==GSI_CHANNEL_STATE_STOP_IN_PROC ) { +ipa_err ("channel %u busy try again\n" , channel_id); + ret = -EAGAIN ; + goto free_lock; + } + + ret =0 ; + +free_lock: +mutex_unlock (&gsi->mutex); + +return ret; +} + +int gsi_channel_reset (struct gsi *gsi,u32 channel_id) +{ +struct gsi_channel *channel = &gsi->channel[channel_id]; +u32 evt_ring_id; +bool reset_done; + +if (channel->state !=GSI_CHANNEL_STATE_STOPPED ) { +ipa_err ("bad state %d\n" , channel->state); +return -ENOTSUPP ; + } + + evt_ring_id =gsi_evt_ring_id (gsi, channel->evt_ring); + reset_done = false; +mutex_lock (&gsi->mutex); +reset: + + gsi->ch_dbg[channel_id].ch_reset++; + +if (!channel_command (gsi, channel_id,GSI_CH_RESET )) { +mutex_unlock (&gsi->mutex); +return -ETIMEDOUT ; + } + +if (channel->state !=GSI_CHANNEL_STATE_ALLOCATED ) { +ipa_err ("channel_id %u unexpected state %u\n" , channel_id, + channel->state); +ipa_bug (); + } + +/* workaround: reset GSI producers again */ +if (channel->from_ipa && !reset_done) { +usleep_range (GSI_RESET_WA_MIN_SLEEP ,GSI_RESET_WA_MAX_SLEEP ); + reset_done = true; + goto reset; + } + +gsi_channel_program (gsi, channel_id, evt_ring_id, true); +gsi_ring_init (&channel->ring); + +/* restore scratch */ +__gsi_channel_scratch_write (gsi, channel_id); + +mutex_unlock (&gsi->mutex); + +return 0 ; +} + +void gsi_channel_free (struct gsi *gsi,u32 channel_id) +{ +struct gsi_channel *channel = &gsi->channel[channel_id]; +u32 evt_ring_id; +bool completed; + +ipa_bug_on (channel->state !=GSI_CHANNEL_STATE_ALLOCATED ); + + evt_ring_id =gsi_evt_ring_id (gsi, channel->evt_ring); +mutex_lock (&gsi->mutex); + + gsi->ch_dbg[channel_id].ch_de_alloc++; + + completed =channel_command (gsi, channel_id,GSI_CH_DE_ALLOC ); +ipa_bug_on (!completed); + +ipa_bug_on (channel->state !=GSI_CHANNEL_STATE_NOT_ALLOCATED ); + +mutex_unlock (&gsi->mutex); + +kfree (channel->user_data); +gsi_ring_free (&channel->ring); + +gsi_evt_ring_dealloc (gsi, evt_ring_id); + +memset (channel,0 ,sizeof (*channel)); + +atomic_dec (&gsi->channel_count); +} + +static u16 __gsi_query_ring_free_re (struct gsi_ring *ring) +{ +u64 delta; + +if (ring->wp_local < ring->rp_local) + delta = ring->rp_local - ring->wp_local; +else + delta = ring->end - ring->wp_local + ring->rp_local; + +return (u16)(delta /GSI_RING_ELEMENT_SIZE -1 ); +} + +int gsi_channel_queue (struct gsi *gsi,u32 channel_id,u16 num_xfers, +struct gsi_xfer_elem *xfer,bool ring_db) +{ +struct gsi_channel *channel = &gsi->channel[channel_id]; +unsigned long flags; +u32 i; + +spin_lock_irqsave (&channel->evt_ring->ring.slock, flags); + +if (num_xfers >__gsi_query_ring_free_re (&channel->ring)) { +spin_unlock_irqrestore (&channel->evt_ring->ring.slock, flags); +ipa_err ("no space for %u-element transfer on ch %u\n" , + num_xfers, channel_id); + +return -ENOSPC ; + } + +for (i =0 ; i < num_xfers; i++) { +struct gsi_tre *tre_ptr; +u16 idx =ring_wp_local_index (&channel->ring); + + channel->user_data[idx] = xfer[i].user_data; + + tre_ptr =ipa_dma_phys_to_virt (&channel->ring.mem, + channel->ring.wp_local); + + tre_ptr->buffer_ptr = xfer[i].addr; + tre_ptr->buf_len = xfer[i].len_opcode; + tre_ptr->bei = xfer[i].flags &GSI_XFER_FLAG_BEI ?1 :0 ; + tre_ptr->ieot = xfer[i].flags &GSI_XFER_FLAG_EOT ?1 :0 ; + tre_ptr->ieob = xfer[i].flags &GSI_XFER_FLAG_EOB ?1 :0 ; + tre_ptr->chain = xfer[i].flags &GSI_XFER_FLAG_CHAIN ?1 :0 ; + +if (xfer[i].type ==GSI_XFER_ELEM_DATA ) + tre_ptr->re_type =GSI_RE_XFER ; +else if (xfer[i].type ==GSI_XFER_ELEM_IMME_CMD ) + tre_ptr->re_type =GSI_RE_IMMD_CMD ; +else if (xfer[i].type ==GSI_XFER_ELEM_NOP ) + tre_ptr->re_type =GSI_RE_NOP ; +else +ipa_bug_on ("invalid xfer type" ); + +ring_wp_local_inc (&channel->ring); + } + +wmb ();/* Ensure TRE is set before ringing doorbell */ + +if (ring_db) +gsi_channel_doorbell (gsi, channel); + +spin_unlock_irqrestore (&channel->evt_ring->ring.slock, flags); + +return 0 ; +} + +int gsi_channel_poll (struct gsi *gsi,u32 channel_id) +{ +struct gsi_channel *channel = &gsi->channel[channel_id]; +struct gsi_evt_ring *evt_ring; +unsigned long flags; +u32 evt_ring_id; +int size; + + evt_ring = channel->evt_ring; + evt_ring_id =gsi_evt_ring_id (gsi, evt_ring); + +spin_lock_irqsave (&evt_ring->ring.slock, flags); + +/* update rp to see of we have anything new to process */ +if (evt_ring->ring.rp == evt_ring->ring.rp_local) { +u32 val; + + val =gsi_readl (gsi,GSI_EV_CH_E_CNTXT_4_OFFS (evt_ring_id)); + evt_ring->ring.rp = channel->ring.rp &GENMASK_ULL (63 ,32 ); + evt_ring->ring.rp |= val; + } + +if (evt_ring->ring.rp != evt_ring->ring.rp_local) { +struct gsi_xfer_compl_evt *evt; + + evt =ipa_dma_phys_to_virt (&evt_ring->ring.mem, + evt_ring->ring.rp_local); + size =gsi_channel_process (gsi, evt, false); + +ring_rp_local_inc (&evt_ring->ring); +ring_wp_local_inc (&evt_ring->ring);/* recycle element */ + }else { + size = -ENOENT ; + } + +spin_unlock_irqrestore (&evt_ring->ring.slock, flags); + +return size; +} + +static void gsi_channel_mode_set (struct gsi *gsi,u32 channel_id,bool polling) +{ +struct gsi_channel *channel = &gsi->channel[channel_id]; +unsigned long flags; +u32 evt_ring_id; + + evt_ring_id =gsi_evt_ring_id (gsi, channel->evt_ring); + +spin_lock_irqsave (&gsi->slock, flags); + +if (polling) +gsi_irq_disable_event (gsi, evt_ring_id); +else +gsi_irq_enable_event (gsi, evt_ring_id); +atomic_set (&channel->poll_mode, polling ?1 :0 ); + +spin_unlock_irqrestore (&gsi->slock, flags); +} + +void gsi_channel_intr_enable (struct gsi *gsi,u32 channel_id) +{ +gsi_channel_mode_set (gsi, channel_id, false); +} + +void gsi_channel_intr_disable (struct gsi *gsi,u32 channel_id) +{ +gsi_channel_mode_set (gsi, channel_id, true); +} + +void gsi_channel_config (struct gsi *gsi,u32 channel_id,bool doorbell_enable) +{ +struct gsi_channel *channel = &gsi->channel[channel_id]; +u32 evt_ring_id; + + evt_ring_id =gsi_evt_ring_id (gsi, channel->evt_ring); + +mutex_lock (&channel->mutex); + +gsi_channel_program (gsi, channel_id, evt_ring_id, doorbell_enable); +gsi_ring_init (&channel->ring); + +/* restore scratch */ +__gsi_channel_scratch_write (gsi, channel_id); +mutex_unlock (&channel->mutex); +} + +/* Initialize GSI driver */ +struct gsi *gsi_init (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct resource *res; +resource_size_t size; +struct gsi *gsi; +int irq; + +/* Get GSI memory range and map it */ + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"gsi" ); +if (!res) { +ipa_err ("missing \"gsi\" property in DTB\n" ); +return ERR_PTR (-EINVAL ); + } + + size =resource_size (res); +if (res->start >U32_MAX || size >U32_MAX ) { +ipa_err ("\"gsi\" values out of range\n" ); +return ERR_PTR (-EINVAL ); + } + +/* Get IPA GSI IRQ number */ + irq =platform_get_irq_byname (pdev,"gsi" ); +if (irq <0 ) { +ipa_err ("failed to get gsi IRQ!\n" ); +return ERR_PTR (irq); + } + + gsi =kzalloc (sizeof (*gsi),GFP_KERNEL ); +if (!gsi) +return ERR_PTR (-ENOMEM ); + + gsi->base =devm_ioremap_nocache (dev, res->start, size); +if (!gsi->base) { +kfree (gsi); + +return ERR_PTR (-ENOMEM ); + } + gsi->dev = dev; + gsi->phys = (u32 )res->start; + gsi->irq = irq; +spin_lock_init (&gsi->slock); +mutex_init (&gsi->mutex); +atomic_set (&gsi->channel_count,0 ); +atomic_set (&gsi->evt_ring_count,0 ); + +return gsi; +}
drivers/net/ipa/gsi.h new file +195 -0
195 lines not on this page · raw message
drivers/net/ipa/gsi_reg.h new file +563 -0
563 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH 4/12 soc: qcom: ipa: immediate commands
In reply to Alex ElderThis patch contains (mostly) code implementing "immediate commands." (The source files are still named "ipahal" for historical reasons.)
One channel (APPS CMD_PROD) is used for sending commands *to* the IPA itself, rather than passing data through it. These immediate commands are issued to the IPA using the normal GSI queueing mechanism. And each command's completion is handled using the normal GSI transfer completion mechanisms.
In addition to immediate commands, the "IPA HAL" includes code for interpreting status packets that are supplied to the IPA on consumer channels.
--- drivers/net/ipa/ipahal.c | 541 +++++++++++++++++++++++++++++++++++++++ drivers/net/ipa/ipahal.h | 253 ++++++++++++++++++ 2 files changed, 794 insertions(+) create mode 100644 drivers/net/ipa/ipahal.c create mode 100644 drivers/net/ipa/ipahal.h
drivers/net/ipa/ipahal.c new file +541 -0
@@ -0,0 +1,541 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd. +*/ + +#include <linux/types.h> +#include <linux/slab.h> +#include <asm/unaligned.h> + +#include "ipahal.h" +#include "ipa_i.h" /* ipa_err() */ +#include "ipa_dma.h" + +/** +* DOC: IPA Immediate Commands +* +* The APPS_CMD_PROD channel is used to issue immediate commands to +* the IPA. An immediate command is generally used to request the +* IPA do something other than data transfer. +* +* An immediate command is represented by a GSI transfer element. +* Each immediate command has a well-defined format, with a known +* length. The transfer element's length field can therefore be +* used to hold a command's opcode. The "payload" of an immediate +* command contains additional information required for the command. +* It resides in DRAM and is referred to using the DMA memory data +* pointer (the same one used to refer to the data in a "normal" +* transfer). +* +* Immediate commands are issued to the IPA through the APPS_CMD_PROD +* channel using the normal GSI queueing mechanism. And each command's +* completion is handled using the normal GSI transfer completion +* mechanisms. +*/ + +/** +* struct ipahal_context - HAL global context data +* @empty_fltrt_tbl: Empty table to be used for table initialization +*/ +static struct ipahal_context { +struct ipa_dma_mem empty_fltrt_tbl; +} ipahal_ctx_struct; +static struct ipahal_context *ipahal_ctx = &ipahal_ctx_struct; + +/* enum ipa_pipeline_clear_option - Values for pipeline clear waiting options +* @IPAHAL_HPS_CLEAR: Wait for HPS clear. All queues except high priority queue +* shall not be serviced until HPS is clear of packets or immediate commands. +* The high priority Rx queue / Q6ZIP group shall still be serviced normally. +* +* @IPAHAL_SRC_GRP_CLEAR: Wait for originating source group to be clear +* (for no packet contexts allocated to the originating source group). +* The source group / Rx queue shall not be serviced until all previously +* allocated packet contexts are released. All other source groups/queues shall +* be serviced normally. +* +* @IPAHAL_FULL_PIPELINE_CLEAR: Wait for full pipeline to be clear. +* All groups / Rx queues shall not be serviced until IPA pipeline is fully +* clear. This should be used for debug only. +* +* The values assigned to these are assumed by the REGISTER_WRITE +* (struct ipa_imm_cmd_hw_register_write) and the DMA_SHARED_MEM +* (struct ipa_imm_cmd_hw_dma_shared_mem) immediate commands for +* IPA version 3 hardware. They are also used to modify the opcode +* used to implement these commands for IPA version 4 hardware. +*/ +enum ipahal_pipeline_clear_option { +IPAHAL_HPS_CLEAR =0 , +IPAHAL_SRC_GRP_CLEAR =1 , +IPAHAL_FULL_PIPELINE_CLEAR =2 , +}; + +/* Immediate commands H/W structures */ + +/* struct ipa_imm_cmd_hw_ip_fltrt_init - IP_V*_FILTER_INIT/IP_V*_ROUTING_INIT +* command payload in H/W format. +* Inits IPv4/v6 routing or filter block. +* @hash_rules_addr: Addr in system mem where hashable flt/rt rules starts +* @hash_rules_size: Size in bytes of the hashable tbl to cpy to local mem +* @hash_local_addr: Addr in shared mem where hashable flt/rt tbl should +* be copied to +* @nhash_rules_size: Size in bytes of the non-hashable tbl to cpy to local mem +* @nhash_local_addr: Addr in shared mem where non-hashable flt/rt tbl should +* be copied to +* @rsvd: reserved +* @nhash_rules_addr: Addr in sys mem where non-hashable flt/rt tbl starts +*/ +struct ipa_imm_cmd_hw_ip_fltrt_init { +u64 hash_rules_addr; +u64 hash_rules_size :12 , + hash_local_addr :16 , + nhash_rules_size :12 , + nhash_local_addr :16 , + rsvd :8 ; +u64 nhash_rules_addr; +}; + +/* struct ipa_imm_cmd_hw_hdr_init_local - HDR_INIT_LOCAL command payload +* in H/W format. +* Inits hdr table within local mem with the hdrs and their length. +* @hdr_table_addr: Word address in sys mem where the table starts (SRC) +* @size_hdr_table: Size of the above (in bytes) +* @hdr_addr: header address in IPA sram (used as DST for memory copy) +* @rsvd: reserved +*/ +struct ipa_imm_cmd_hw_hdr_init_local { +u64 hdr_table_addr; +u32 size_hdr_table :12 , + hdr_addr :16 , + rsvd :4 ; +}; + +/* struct ipa_imm_cmd_hw_dma_shared_mem - DMA_SHARED_MEM command payload +* in H/W format. +* Perform mem copy into or out of the SW area of IPA local mem +* @sw_rsvd: Ignored by H/W. My be used by S/W +* @size: Size in bytes of data to copy. Expected size is up to 2K bytes +* @local_addr: Address in IPA local memory +* @direction: Read or write? +* 0: IPA write, Write to local address from system address +* 1: IPA read, Read from local address to system address +* @skip_pipeline_clear: 0 to wait until IPA pipeline is clear. 1 don't wait +* @pipeline_clear_options: options for pipeline to clear +* 0: HPS - no pkt inside HPS (not grp specific) +* 1: source group - The immediate cmd src grp does npt use any pkt ctxs +* 2: Wait until no pkt reside inside IPA pipeline +* 3: reserved +* @rsvd: reserved - should be set to zero +* @system_addr: Address in system memory +*/ +struct ipa_imm_cmd_hw_dma_shared_mem { +u16 sw_rsvd; +u16 size; +u16 local_addr; +u16 direction :1 , + skip_pipeline_clear :1 , + pipeline_clear_options :2 , + rsvd :12 ; +u64 system_addr; +}; + +/* struct ipa_imm_cmd_hw_dma_task_32b_addr - +* IPA_DMA_TASK_32B_ADDR command payload in H/W format. +* Used by clients using 32bit addresses. Used to perform DMA operation on +* multiple descriptors. +* The Opcode is dynamic, where it holds the number of buffer to process +* @sw_rsvd: Ignored by H/W. My be used by S/W +* @cmplt: Complete flag: When asserted IPA will interrupt SW when the entire +* DMA related data was completely xfered to its destination. +* @eof: Enf Of Frame flag: When asserted IPA will assert the EOT to the +* dest client. This is used used for aggr sequence +* @flsh: Flush flag: When asserted, pkt will go through the IPA blocks but +* will not be xfered to dest client but rather will be discarded +* @lock: Lock endpoint flag: When asserted, IPA will stop processing +* descriptors from other EPs in the same src grp (RX queue) +* @unlock: Unlock endpoint flag: When asserted, IPA will stop exclusively +* servicing current EP out of the src EPs of the grp (RX queue) +* @size1: Size of buffer1 data +* @addr1: Pointer to buffer1 data +* @packet_size: Total packet size. If a pkt send using multiple DMA_TASKs, +* only the first one needs to have this field set. It will be ignored +* in subsequent DMA_TASKs until the packet ends (EOT). First DMA_TASK +* must contain this field (2 or more buffers) or EOT. +*/ +struct ipa_imm_cmd_hw_dma_task_32b_addr { +u16 sw_rsvd :11 , + cmplt :1 , + eof :1 , + flsh :1 , + lock :1 , + unlock :1 ; +u16 size1; +u32 addr1; +u16 packet_size; +u16 rsvd1; +u32 rsvd2; +}; + +/* IPA Status packet H/W structures and info */ + +/* struct ipa_status_pkt_hw - IPA status packet payload in H/W format. +* This structure describes the status packet H/W structure for the +* following statuses: IPA_STATUS_PACKET, IPA_STATUS_DROPPED_PACKET, +* IPA_STATUS_SUSPENDED_PACKET. +* Other statuses types has different status packet structure. +* @status_opcode: The Type of the status (Opcode). +* @exception: (not bitmask) - the first exception that took place. +* In case of exception, src endp and pkt len are always valid. +* @status_mask: Bit mask specifying on which H/W blocks the pkt was processed. +* @pkt_len: Pkt payload len including hdr, include retained hdr if used. Does +* not include padding or checksum trailer len. +* @endp_src_idx: Source end point index. +* @rsvd1: reserved +* @endp_dest_idx: Destination end point index. +* Not valid in case of exception +* @rsvd2: reserved +* @metadata: meta data value used by packet +* @flt_local: Filter table location flag: Does matching flt rule belongs to +* flt tbl that resides in lcl memory? (if not, then system mem) +* @flt_hash: Filter hash hit flag: Does matching flt rule was in hash tbl? +* @flt_global: Global filter rule flag: Does matching flt rule belongs to +* the global flt tbl? (if not, then the per endp tables) +* @flt_ret_hdr: Retain header in filter rule flag: Does matching flt rule +* specifies to retain header? +* @flt_rule_id: The ID of the matching filter rule. This info can be combined +* with endp_src_idx to locate the exact rule. ID=0x3ff reserved to specify +* flt miss. In case of miss, all flt info to be ignored +* @rt_local: Route table location flag: Does matching rt rule belongs to +* rt tbl that resides in lcl memory? (if not, then system mem) +* @rt_hash: Route hash hit flag: Does matching rt rule was in hash tbl? +* @ucp: UC Processing flag. +* @rt_tbl_idx: Index of rt tbl that contains the rule on which was a match +* @rt_rule_id: The ID of the matching rt rule. This info can be combined +* with rt_tbl_idx to locate the exact rule. ID=0x3ff reserved to specify +* rt miss. In case of miss, all rt info to be ignored +* @nat_hit: NAT hit flag: Was their NAT hit? +* @nat_entry_idx: Index of the NAT entry used of NAT processing +* @nat_type: Defines the type of the NAT operation (ignored for now) +* @tag_info: S/W defined value provided via immediate command +* @seq_num: Per source endp unique packet sequence number +* @time_of_day_ctr: running counter from IPA clock +* @hdr_local: Header table location flag: In header insertion, was the header +* taken from the table resides in local memory? (If no, then system mem) +* @hdr_offset: Offset of used header in the header table +* @frag_hit: Frag hit flag: Was their frag rule hit in H/W frag table? +* @frag_rule: Frag rule index in H/W frag table in case of frag hit +* @hw_specific: H/W specific reserved value +*/ +#define IPA_RULE_ID_BITS 10/* See ipahal_is_rule_miss_id() */ +struct ipa_pkt_status_hw { +u8 status_opcode; +u8 exception; +u16 status_mask; +u16 pkt_len; +u8 endp_src_idx :5 , + rsvd1 :3 ; +u8 endp_dest_idx :5 , + rsvd2 :3 ; +u32 metadata; +u16 flt_local :1 , + flt_hash :1 , + flt_global :1 , + flt_ret_hdr :1 , + flt_rule_id :IPA_RULE_ID_BITS , + rt_local :1 , + rt_hash :1 ; +u16 ucp :1 , + rt_tbl_idx :5 , + rt_rule_id :IPA_RULE_ID_BITS ; +u64 nat_hit :1 , + nat_entry_idx :13 , + nat_type :2 , + tag_info :48 ; +u32 seq_num :8 , + time_of_day_ctr :24 ; +u16 hdr_local :1 , + hdr_offset :10 , + frag_hit :1 , + frag_rule :4 ; +u16 hw_specific; +}; + +void *ipahal_dma_shared_mem_write_pyld (struct ipa_dma_mem *mem,u32 offset) +{ +struct ipa_imm_cmd_hw_dma_shared_mem *data; + +ipa_assert (mem->size <1 <<16 );/* size is 16 bits wide */ +ipa_assert (offset <1 <<16 );/* local_addr is 16 bits wide */ + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (!data) +return NULL ; + + data->size = mem->size; + data->local_addr = offset; + data->direction =0 ;/* 0 = write to IPA; 1 = read from IPA */ + data->skip_pipeline_clear =0 ; + data->pipeline_clear_options =IPAHAL_HPS_CLEAR ; + data->system_addr = mem->phys; + +return data; +} + +void *ipahal_hdr_init_local_pyld (struct ipa_dma_mem *mem,u32 offset) +{ +struct ipa_imm_cmd_hw_hdr_init_local *data; + +ipa_assert (mem->size <1 <<12 );/* size_hdr_table is 12 bits wide */ +ipa_assert (offset <1 <<16 );/* hdr_addr is 16 bits wide */ + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (!data) +return NULL ; + + data->hdr_table_addr = mem->phys; + data->size_hdr_table = mem->size; + data->hdr_addr = offset; + +return data; +} + +static void *fltrt_init_common (struct ipa_dma_mem *mem,u32 hash_offset, +u32 nhash_offset) +{ +struct ipa_imm_cmd_hw_ip_fltrt_init *data; + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (!data) +return NULL ; + + data->hash_rules_addr = (u64 )mem->phys; + data->hash_rules_size = (u32 )mem->size; + data->hash_local_addr = hash_offset; + data->nhash_rules_addr = (u64 )mem->phys; + data->nhash_rules_size = (u32 )mem->size; + data->nhash_local_addr = nhash_offset; + +return data; +} + +void *ipahal_ip_v4_routing_init_pyld (struct ipa_dma_mem *mem,u32 hash_offset, +u32 nhash_offset) +{ +return fltrt_init_common (mem, hash_offset, nhash_offset); +} + +void *ipahal_ip_v6_routing_init_pyld (struct ipa_dma_mem *mem,u32 hash_offset, +u32 nhash_offset) +{ +return fltrt_init_common (mem, hash_offset, nhash_offset); +} + +void *ipahal_ip_v4_filter_init_pyld (struct ipa_dma_mem *mem,u32 hash_offset, +u32 nhash_offset) +{ +return fltrt_init_common (mem, hash_offset, nhash_offset); +} + +void *ipahal_ip_v6_filter_init_pyld (struct ipa_dma_mem *mem,u32 hash_offset, +u32 nhash_offset) +{ +return fltrt_init_common (mem, hash_offset, nhash_offset); +} + +void *ipahal_dma_task_32b_addr_pyld (struct ipa_dma_mem *mem) +{ +struct ipa_imm_cmd_hw_dma_task_32b_addr *data; + +/* size1 and packet_size are both 16 bits wide */ +ipa_assert (mem->size <1 <<16 ); + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (!data) +return NULL ; + + data->cmplt =0 ; + data->eof =0 ; + data->flsh =1 ; + data->lock =0 ; + data->unlock =0 ; + data->size1 = mem->size; + data->addr1 = mem->phys; + data->packet_size = mem->size; + +return data; +} + +void ipahal_payload_free (void *payload) +{ +kfree (payload); +} + +/* IPA Packet Status Logic */ + +/* Maps an exception type returned in a ipa_pkt_status_hw structure +* to the ipahal_pkt_status_exception value that represents it in +* the exception field of a ipahal_pkt_status structure. Returns +* IPAHAL_PKT_STATUS_EXCEPTION_MAX for an unrecognized value. +*/ +static enum ipahal_pkt_status_exception +exception_map (u8 exception,bool is_ipv6) +{ +switch (exception) { +case 0x00 :return IPAHAL_PKT_STATUS_EXCEPTION_NONE ; +case 0x01 :return IPAHAL_PKT_STATUS_EXCEPTION_DEAGGR ; +case 0x04 :return IPAHAL_PKT_STATUS_EXCEPTION_IPTYPE ; +case 0x08 :return IPAHAL_PKT_STATUS_EXCEPTION_PACKET_LENGTH ; +case 0x10 :return IPAHAL_PKT_STATUS_EXCEPTION_FRAG_RULE_MISS ; +case 0x20 :return IPAHAL_PKT_STATUS_EXCEPTION_SW_FILT ; +case 0x40 :return is_ipv6 ?IPAHAL_PKT_STATUS_EXCEPTION_IPV6CT + :IPAHAL_PKT_STATUS_EXCEPTION_NAT ; +default :return IPAHAL_PKT_STATUS_EXCEPTION_MAX ; + } +} + +/* ipahal_pkt_status_get_size() - Get H/W size of packet status */ +u32 ipahal_pkt_status_get_size (void ) +{ +return sizeof (struct ipa_pkt_status_hw ); +} + +/* ipahal_pkt_status_parse() - Parse Packet Status payload to abstracted form +* @unparsed_status: Pointer to H/W format of the packet status as read from H/W +* @status: Pointer to pre-allocated buffer where the parsed info will be stored +*/ +void ipahal_pkt_status_parse (const void *unparsed_status, +struct ipahal_pkt_status *status) +{ +const struct ipa_pkt_status_hw *hw_status = unparsed_status; +bool is_ipv6; + + status->status_opcode = + (enum ipahal_pkt_status_opcode )hw_status->status_opcode; + is_ipv6 = hw_status->status_mask &BIT (7 ) ? false : true; +/* If hardware status values change we may have to re-map this */ + status->status_mask = + (enum ipahal_pkt_status_mask )hw_status->status_mask; + status->exception =exception_map (hw_status->exception, is_ipv6); + status->pkt_len = hw_status->pkt_len; + status->endp_src_idx = hw_status->endp_src_idx; + status->endp_dest_idx = hw_status->endp_dest_idx; + status->metadata = hw_status->metadata; + status->rt_miss =ipahal_is_rule_miss_id (hw_status->rt_rule_id); +} + +int ipahal_init (void ) +{ +struct ipa_dma_mem *mem = &ipahal_ctx->empty_fltrt_tbl; + +/* Set up an empty filter/route table entry in system +* memory. This will be used, for example, to delete a +* route safely. +*/ +if (ipa_dma_alloc (mem,IPA_HW_TBL_WIDTH ,GFP_KERNEL )) { +ipa_err ("error allocating empty filter/route table\n" ); +return -ENOMEM ; + } + +return 0 ; +} + +void ipahal_exit (void ) +{ +ipa_dma_free (&ipahal_ctx->empty_fltrt_tbl); +} + +/* Does the given rule ID represent a routing or filter rule miss? +* A rule miss is indicated as an all-1's value in the rt_rule_id +* or flt_rule_id field of the ipahal_pkt_status structure. +*/ +bool ipahal_is_rule_miss_id (u32 id) +{ +BUILD_BUG_ON (IPA_RULE_ID_BITS <2 ); + +return id == (1U <<IPA_RULE_ID_BITS ) -1 ; +} + +/** +* ipahal_rt_generate_empty_img() - Generate empty route table header +* @route_count: Number of table entries +* @mem: DMA memory object representing the header structure +* +* Allocates and fills an "empty" route table header having the given +* number of entries. Each entry in the table contains the DMA address +* of a routing entry. +* +* This function initializes all entries to point@the preallocated +* empty routing entry in system RAM. +* +* Return: 0 if successful, or a negative error code otherwise +*/ +int ipahal_rt_generate_empty_img (u32 route_count,struct ipa_dma_mem *mem) +{ +u64 addr; +int i; + +BUILD_BUG_ON (!IPA_HW_TBL_HDR_WIDTH ); + +if (ipa_dma_alloc (mem, route_count *IPA_HW_TBL_HDR_WIDTH ,GFP_KERNEL )) +return -ENOMEM ; + + addr = (u64 )ipahal_ctx->empty_fltrt_tbl.phys; +for (i =0 ; i < route_count; i++) +put_unaligned (addr, mem->virt + i *IPA_HW_TBL_HDR_WIDTH ); + +return 0 ; +} + +/** +* ipahal_flt_generate_empty_img() - Generate empty filter table header +* @filter_bitmap: Bitmap representing which endpoints support filtering +* @mem: DMA memory object representing the header structure +* +* Allocates and fills an "empty" filter table header based on the +* given filter bitmap. +* +* The first slot in a filter table header is a 64-bit bitmap whose +* set bits define which endpoints support filtering. Following +* this, each set bit in the mask has the DMA address of the filter +* used for the corresponding endpoint. +* +* This function initializes all endpoints that support filtering to +* point at the preallocated empty filter in system RAM. +* +* Note: the (software) bitmap here uses bit 0 to represent +* endpoint 0, bit 1 for endpoint 1, and so on. This is different +* from the hardware (which uses bit 1 to represent filter 0, etc.). +* +* Return: 0 if successful, or a negative error code +*/ +int ipahal_flt_generate_empty_img (u64 filter_bitmap,struct ipa_dma_mem *mem) +{ +u32 filter_count =hweight32 (filter_bitmap) +1 ; +u64 addr; +int i; + +ipa_assert (filter_bitmap); + +if (ipa_dma_alloc (mem, filter_count *IPA_HW_TBL_HDR_WIDTH ,GFP_KERNEL )) +return -ENOMEM ; + +/* Save the endpoint bitmap in the first slot of the table. +* Convert it from software to hardware representation by +* shifting it left one position. +* XXX Does bit position 0 represent global? At IPA3, global +* XXX configuration is possible but not used. +*/ +put_unaligned (filter_bitmap <<1 , mem->virt); + +/* Point every entry in the table at the empty filter */ + addr = (u64 )ipahal_ctx->empty_fltrt_tbl.phys; +for (i =1 ; i < filter_count; i++) +put_unaligned (addr, mem->virt + i *IPA_HW_TBL_HDR_WIDTH ); + +return 0 ; +} + +void ipahal_free_empty_img (struct ipa_dma_mem *mem) +{ +ipa_dma_free (mem); +}
drivers/net/ipa/ipahal.h new file +253 -0
253 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH 5/12 soc: qcom: ipa: IPA interrupts and the microcontroller
In reply to Alex ElderThe IPA has an interrupt line distinct from the interrupt used by the GSI code. Whereas GSI interrupts are generally related to channel events (like transfer completions), IPA interrupts are related to other events related to the IPA. When the IPA IRQ fires, an IPA interrupt status register indicates which IPA interrupt events are being signaled. IPA interrupts can be masked independently, and can also be endependently enabled or disabled.
The IPA has an embedded microcontroller that can be used for additional processing of messages passing through the IPA. This feature is generally not used by the current code.
Currently only three IPA interrupts are used: one to trigger a resume when in a suspended state; and two that allow the embedded microcontroller to signal events.
--- drivers/net/ipa/ipa_interrupts.c | 307 ++++++++++++++++++++++++++++ drivers/net/ipa/ipa_uc.c | 336 +++++++++++++++++++++++++++++++ 2 files changed, 643 insertions(+) create mode 100644 drivers/net/ipa/ipa_interrupts.c create mode 100644 drivers/net/ipa/ipa_uc.c
drivers/net/ipa/ipa_interrupts.c new file +307 -0
@@ -0,0 +1,307 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2014-2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd. +*/ + +/* +* DOC: IPA Interrupts +* +* The IPA has an interrupt line distinct from the interrupt used +* by the GSI code. Whereas GSI interrupts are generally related +* to channel events (like transfer completions), IPA interrupts are +* related to other events related to the IPA. Some of the IPA +* interrupts come from a microcontroller embedded in the IPA. +* Each IPA interrupt type can be both masked and acknowledged +* independent of the others, +* +* So two of the IPA interrupts are initiated by the microcontroller. +* A third can be generated to signal the need for a wakeup/resume +* when the IPA has been suspended. The modem can cause this event +* to occur (for example, for an incoming call). There are other IPA +* events defined, but at this time only these three are supported. +*/ + +#include <linux/types.h> +#include <linux/interrupt.h> +#include <linux/workqueue.h> + +#include "ipa_i.h" +#include "ipa_reg.h" + +struct ipa_interrupt_info { +ipa_irq_handler_t handler; +enum ipa_irq_type interrupt; +}; + +#define IPA_IRQ_NUM_MAX 32/* Number of IRQ bits in IPA interrupt mask */ +static struct ipa_interrupt_info ipa_interrupt_info[IPA_IRQ_NUM_MAX ]; + +static struct workqueue_struct *ipa_interrupt_wq; + +static void enable_tx_suspend_work_func (struct work_struct *work); +static DECLARE_DELAYED_WORK(tx_suspend_work, enable_tx_suspend_work_func); + +static const int ipa_irq_mapping[] = { + [IPA_INVALID_IRQ ] =-1 , + [IPA_UC_IRQ_0 ] =2 , + [IPA_UC_IRQ_1 ] =3 , + [IPA_TX_SUSPEND_IRQ ] =14 , +}; + +/* IPA interrupt handlers are called in contexts that can block */ +static void ipa_interrupt_work_func (struct work_struct *work); +static DECLARE_WORK(ipa_interrupt_work, ipa_interrupt_work_func); + +/* Workaround disables TX_SUSPEND interrupt for this long */ +#define DISABLE_TX_SUSPEND_INTR_DELAY msecs_to_jiffies(5) + +/* Disable the IPA TX_SUSPEND interrupt, and arrange for it to be +* re-enabled again in 5 milliseconds. +* +* This is part of a hardware bug workaround. +*/ +static void ipa_tx_suspend_interrupt_wa (void ) +{ +u32 val; + + val =ipa_read_reg_n (IPA_IRQ_EN_EE_N ,IPA_EE_AP ); + val &= ~BIT (ipa_irq_mapping[IPA_TX_SUSPEND_IRQ ]); +ipa_write_reg_n (IPA_IRQ_EN_EE_N ,IPA_EE_AP , val); + +queue_delayed_work (ipa_interrupt_wq, &tx_suspend_work, +DISABLE_TX_SUSPEND_INTR_DELAY ); +} + +static void ipa_handle_interrupt (int irq_num) +{ +struct ipa_interrupt_info *intr_info = &ipa_interrupt_info[irq_num]; +u32 endpoints =0 ;/* Only TX_SUSPEND uses its interrupt_data */ + +if (!intr_info->handler) +return ; + +if (intr_info->interrupt ==IPA_TX_SUSPEND_IRQ ) { +/* Disable the suspend interrupt temporarily */ +ipa_tx_suspend_interrupt_wa (); + +/* Get and clear mask of endpoints signaling TX_SUSPEND */ + endpoints =ipa_read_reg_n (IPA_IRQ_SUSPEND_INFO_EE_N , +IPA_EE_AP ); +ipa_write_reg_n (IPA_SUSPEND_IRQ_CLR_EE_N ,IPA_EE_AP , endpoints); + } + + intr_info->handler (intr_info->interrupt, endpoints); +} + +static inline bool is_uc_irq (int irq_num) +{ +enum ipa_irq_type interrupt = ipa_interrupt_info[irq_num].interrupt; + +return interrupt !=IPA_UC_IRQ_0 && interrupt !=IPA_UC_IRQ_1 ; +} + +static void ipa_process_interrupts (void ) +{ +while (true) { +u32 ipa_intr_mask; +u32 imask;/* one set bit */ + +/* Determine which interrupts have fired, then examine only +* those that are enabled. Note that a suspend interrupt +* bug forces us to re-read the enabled mask every time to +* avoid an endless loop. +*/ + ipa_intr_mask =ipa_read_reg_n (IPA_IRQ_STTS_EE_N ,IPA_EE_AP ); + ipa_intr_mask &=ipa_read_reg_n (IPA_IRQ_EN_EE_N ,IPA_EE_AP ); + +if (!ipa_intr_mask) +break ; + +do { +int i =__ffs (ipa_intr_mask); +bool uc_irq =is_uc_irq (i); + + imask =BIT (i); + +/* Clear uC interrupt before processing to avoid +* clearing unhandled interrupts +*/ +if (uc_irq) +ipa_write_reg_n (IPA_IRQ_CLR_EE_N ,IPA_EE_AP , + imask); + +ipa_handle_interrupt (i); + +/* Clear non-uC interrupt after processing +* to avoid clearing interrupt data +*/ +if (!uc_irq) +ipa_write_reg_n (IPA_IRQ_CLR_EE_N ,IPA_EE_AP , + imask); + }while ((ipa_intr_mask ^= imask)); + } +} + +static void ipa_interrupt_work_func (struct work_struct *work) +{ +ipa_client_add (); + +ipa_process_interrupts (); + +ipa_client_remove (); +} + +static irqreturn_t ipa_isr (int irq,void *ctxt) +{ +/* Schedule handling (if not already scheduled) */ +queue_work (ipa_interrupt_wq, &ipa_interrupt_work); + +return IRQ_HANDLED ; +} + +/* Re-enable the IPA TX_SUSPEND interrupt after having been disabled +* for a moment by ipa_tx_suspend_interrupt_wa(). This is part of a +* workaround for a hardware bug. +*/ +static void enable_tx_suspend_work_func (struct work_struct *work) +{ +u32 val; + +ipa_client_add (); + + val =ipa_read_reg_n (IPA_IRQ_EN_EE_N ,IPA_EE_AP ); + val |=BIT (ipa_irq_mapping[IPA_TX_SUSPEND_IRQ ]); +ipa_write_reg_n (IPA_IRQ_EN_EE_N ,IPA_EE_AP , val); + +ipa_process_interrupts (); + +ipa_client_remove (); +} + +/* Register SUSPEND_IRQ_EN_EE_N_ADDR for L2 interrupt. */ +static void tx_suspend_enable (void ) +{ +enum ipa_client_type client; +u32 val = ~0 ; + +/* Compute the mask to use (bits set for all non-modem endpoints) */ +for (client =0 ; client <IPA_CLIENT_MAX ; client++) +if (ipa_modem_consumer (client) ||ipa_modem_producer (client)) + val &= ~BIT (ipa_client_ep_id (client)); + +ipa_write_reg_n (IPA_SUSPEND_IRQ_EN_EE_N ,IPA_EE_AP , val); +} + +/* Unregister SUSPEND_IRQ_EN_EE_N_ADDR for L2 interrupt. */ +static void tx_suspend_disable (void ) +{ +ipa_write_reg_n (IPA_SUSPEND_IRQ_EN_EE_N ,IPA_EE_AP ,0 ); +} + +/** +* ipa_add_interrupt_handler() - Adds handler for an IPA interrupt +* @interrupt: IPA interrupt type +* @handler: The handler for that interrupt +* +* Adds handler to an IPA interrupt type and enable it. IPA interrupt +* handlers are allowed to block (they aren't run in interrupt context). +*/ +void ipa_add_interrupt_handler (enum ipa_irq_type interrupt, +ipa_irq_handler_t handler) +{ +int irq_num = ipa_irq_mapping[interrupt]; +struct ipa_interrupt_info *intr_info; +u32 val; + + intr_info = &ipa_interrupt_info[irq_num]; + intr_info->handler = handler; + intr_info->interrupt = interrupt; + +/* Enable the IPA interrupt */ + val =ipa_read_reg_n (IPA_IRQ_EN_EE_N ,IPA_EE_AP ); + val |=BIT (irq_num); +ipa_write_reg_n (IPA_IRQ_EN_EE_N ,IPA_EE_AP , val); + +if (interrupt ==IPA_TX_SUSPEND_IRQ ) +tx_suspend_enable (); +} + +/** +* ipa_remove_interrupt_handler() - Removes handler for an IPA interrupt type +* @interrupt: IPA interrupt type +* +* Remove an IPA interrupt handler and disable it. +*/ +void ipa_remove_interrupt_handler (enum ipa_irq_type interrupt) +{ +int irq_num = ipa_irq_mapping[interrupt]; +struct ipa_interrupt_info *intr_info; +u32 val; + + intr_info = &ipa_interrupt_info[irq_num]; + intr_info->handler =NULL ; + intr_info->interrupt =IPA_INVALID_IRQ ; + +if (interrupt ==IPA_TX_SUSPEND_IRQ ) +tx_suspend_disable (); + +/* Disable the interrupt */ + val =ipa_read_reg_n (IPA_IRQ_EN_EE_N ,IPA_EE_AP ); + val &= ~BIT (irq_num); +ipa_write_reg_n (IPA_IRQ_EN_EE_N ,IPA_EE_AP , val); +} + +/** +* ipa_interrupts_init() - Initialize the IPA interrupts framework +*/ +int ipa_interrupts_init (void ) +{ +int ret; + + ret =request_irq (ipa_ctx->ipa_irq, ipa_isr,IRQF_TRIGGER_RISING , +"ipa" , ipa_ctx->dev); +if (ret) +return ret; + + ipa_interrupt_wq =alloc_ordered_workqueue ("ipa_interrupt_wq" ,0 ); +if (ipa_interrupt_wq) +return 0 ; + +free_irq (ipa_ctx->ipa_irq, ipa_ctx->dev); + +return -ENOMEM ; +} + +/** +* ipa_suspend_active_aggr_wa() - Emulate suspend interrupt +* @ep_id: Endpoint on which to emulate a suspend +* +* Emulate suspend IRQ to unsuspend a client suspended with an open +* aggregation frame. This is to work around a hardware issue +* where an IRQ is not generated as it should be when this occurs. +*/ +void ipa_suspend_active_aggr_wa (u32 ep_id) +{ +struct ipa_reg_aggr_force_close force_close; +struct ipa_interrupt_info *intr_info; +u32 clnt_mask; +int irq_num; + + irq_num = ipa_irq_mapping[IPA_TX_SUSPEND_IRQ ]; + intr_info = &ipa_interrupt_info[irq_num]; + clnt_mask =BIT (ep_id); + +/* Nothing to do if the endpoint doesn't have aggregation open */ +if (!(ipa_read_reg (IPA_STATE_AGGR_ACTIVE ) & clnt_mask)) +return ; + +/* Force close aggregation */ +ipa_reg_aggr_force_close (&force_close, clnt_mask); +ipa_write_reg_fields (IPA_AGGR_FORCE_CLOSE , &force_close); + +/* Simulate suspend IRQ */ +ipa_assert (!in_interrupt ()); +if (intr_info->handler) + intr_info->handler (intr_info->interrupt, clnt_mask); +}
drivers/net/ipa/ipa_uc.c new file +336 -0
336 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH 6/12 soc: qcom: ipa: QMI modem communication
In reply to Alex ElderQMI is a mechanism that allows entities on the AP to communicate and coordinate with peer entities on a modem. Each peer can create an endpoint for communicating with the other. QMI defines a way for the format of messages sent between endpoints to be described, and uses a service to route and deliver these messages.
For IPA, QMI is used to synchronize the startup sequence of the IPA drivers resident on the AP and modem. The documentation in "ipa_qmi.c" below provides more detail about the message interchange involved. The IPA QMI code is divided into the "main" code that implements message handling and synchronization, and the message code that defines the structure and layout of the messages used.
--- drivers/net/ipa/ipa_qmi.c | 406 +++++++++++++++++++++++ drivers/net/ipa/ipa_qmi.h | 12 + drivers/net/ipa/ipa_qmi_msg.c | 587 ++++++++++++++++++++++++++++++++++ drivers/net/ipa/ipa_qmi_msg.h | 233 ++++++++++++++ 4 files changed, 1238 insertions(+) create mode 100644 drivers/net/ipa/ipa_qmi.c create mode 100644 drivers/net/ipa/ipa_qmi.h create mode 100644 drivers/net/ipa/ipa_qmi_msg.c create mode 100644 drivers/net/ipa/ipa_qmi_msg.h
drivers/net/ipa/ipa_qmi.c new file +406 -0
@@ -0,0 +1,406 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2013-2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd. +*/ + +#include <linux/types.h> +#include <linux/string.h> +#include <linux/slab.h> +#include <linux/qrtr.h> +#include <linux/soc/qcom/qmi.h> + +#include "ipa_qmi_msg.h" + +#include "ipa_i.h" /* ipa_err() */ + +#define QMI_INIT_DRIVER_TIMEOUT 60000/* A minute in milliseconds */ + +static bool ipa_qmi_initialized; + +/* The AP and modem perform a "handshake" at initialization time to +* ensure each side knows the other side is ready. Two pairs of QMI +* handles (endpoints) are used for this; one provides service on +* the modem for AP requests, and the other is on the AP to service +* modem requests (and to supply an indication from the AP). +* +* The QMI service on the modem expects to receive an INIT_DRIVER +* request from the AP, which contains parameters used by the +* modem during initialization. The AP sends this request as soon +* as it is knows the service is available. The modem responds to +* this request immediately. +* +* When the modem learns the AP service is available, it is able +* to communicate its status to the AP. The modem uses this to +* tell the AP when it is ready to receive an indication, sending +* an INDICATION_REGISTER request to the handle served by the AP. +* This is separate from the modem driver initialization. +* +* When the modem has completed the driver initialization requested +* by the AP, it sends a DRIVER_INIT_COMPLETE request to the AP. +* This request could arrive at the AP either before or after the +* INDICATION_REGISTER request. +* +* The final step in the handshake occurs after the AP has received +* both requests from the modem. The AP completes the handshake by +* sending an INIT_COMPLETE_IND indication message to the modem. +*/ + +#define IPA_HOST_SERVICE_SVC_ID 0x31 +#define IPA_HOST_SVC_VERS 1 +#define IPA_HOST_SERVICE_INS_ID 1 + +#define IPA_MODEM_SERVICE_SVC_ID 0x31 +#define IPA_MODEM_SERVICE_INS_ID 2 +#define IPA_MODEM_SVC_VERS 1 + +/* Used to send an INIT_DRIVER request to the modem */ +static struct qmi_handle client_handle; + +/* Requests from the modem arrive on the server handle to tell us +* when it is prepared to receive an INIT_COMPLETE indication, and +* when its driver initialization is complete. The AP sends the +* indication after it has received and responded to both requests. +*/ +static struct qmi_handle server_handle; + +/* These track state during the handshake */ +static bool indication_register_received; +static bool init_driver_response_received; + +/* Send an INIT_COMPLETE_IND indication message to the modem */ +static int ipa_send_master_driver_init_complete_ind (struct qmi_handle *qmi, +struct sockaddr_qrtr *sq) +{ +struct ipa_init_complete_ind ind = { }; + + ind.status.result =QMI_RESULT_SUCCESS_V01 ; + ind.status.error =QMI_ERR_NONE_V01 ; + +return qmi_send_indication (qmi, sq,IPA_QMI_INIT_COMPLETE_IND , +IPA_QMI_INIT_COMPLETE_IND_SZ , + ipa_init_complete_ind_ei, &ind); +} + +/* This function is called to determine whether to complete the +* handshake by sending an INIT_COMPLETE_IND indication message to +* the modem. The "init_driver" parameter is false when we've +* received an INDICATION_REGISTER request message from the modem, +* or true when we've received the response from the INIT_DRIVER +* request message we send. If this function decides the message +* should be sent, it calls ipa_send_master_driver_init_complete_ind() +* to send it. +*/ +static void ipa_handshake_complete (struct qmi_handle *qmi, +struct sockaddr_qrtr *sq,bool init_driver) +{ +bool send_it; +int ret; + +if (init_driver) { + init_driver_response_received = true; + send_it = indication_register_received; + }else { + indication_register_received = true; + send_it = init_driver_response_received; + } +if (!send_it) +return ; + + ret =ipa_send_master_driver_init_complete_ind (qmi, sq); +if (ret) +ipa_err ("error %d sending init complete indication\n" , ret); +} + +/* Callback function to handle an INDICATION_REGISTER request message +* from the modem. This informs the AP that the modem is now ready to +* receive the INIT_COMPLETE_IND indication message. +*/ +static void ipa_indication_register_fn (struct qmi_handle *qmi, +struct sockaddr_qrtr *sq, +struct qmi_txn *txn, +const void *decoded) +{ +struct ipa_indication_register_rsp rsp = { }; +int ret; + + rsp.rsp.result =QMI_RESULT_SUCCESS_V01 ; + rsp.rsp.error =QMI_ERR_NONE_V01 ; + + ret =qmi_send_response (qmi, sq, txn,IPA_QMI_INDICATION_REGISTER , +IPA_QMI_INDICATION_REGISTER_RSP_SZ , + ipa_indication_register_rsp_ei, &rsp); +if (ret) +ipa_err ("error %d sending response\n" , ret); +else +ipa_handshake_complete (qmi, sq, false); +} + +/* Callback function to handle a DRIVER_INIT_COMPLETE request message +* from the modem. This informs the AP that the modem has completed +* the initializion of its driver. +*/ +static void ipa_driver_init_complete_fn (struct qmi_handle *qmi, +struct sockaddr_qrtr *sq, +struct qmi_txn *txn, +const void *decoded) +{ +struct ipa_driver_init_complete_rsp rsp = { }; +int ret; + + rsp.rsp.result =QMI_RESULT_SUCCESS_V01 ; + rsp.rsp.error =QMI_ERR_NONE_V01 ; + + ret =qmi_send_response (qmi, sq, txn,IPA_QMI_DRIVER_INIT_COMPLETE , +IPA_QMI_DRIVER_INIT_COMPLETE_RSP_SZ , + ipa_driver_init_complete_rsp_ei, &rsp); +if (ret) +ipa_err ("error %d sending response\n" , ret); +} + +/* The server handles two request message types sent by the modem. */ +static struct qmi_msg_handler ipa_server_msg_handlers[] = { + { + .type =QMI_REQUEST , + .msg_id =IPA_QMI_INDICATION_REGISTER , + .ei = ipa_indication_register_req_ei, + .decoded_size =IPA_QMI_INDICATION_REGISTER_REQ_SZ , + .fn = ipa_indication_register_fn, + }, + { + .type =QMI_REQUEST , + .msg_id =IPA_QMI_DRIVER_INIT_COMPLETE , + .ei = ipa_driver_init_complete_req_ei, + .decoded_size =IPA_QMI_DRIVER_INIT_COMPLETE_REQ_SZ , + .fn = ipa_driver_init_complete_fn, + }, +}; + +/* Callback function to handle an IPA_QMI_INIT_DRIVER response message +* from the modem. This only acknowledges that the modem received the +* request. The modem will eventually report that it has completed its +* modem initialization by sending a IPA_QMI_DRIVER_INIT_COMPLETE request. +*/ +static void ipa_init_driver_rsp_fn (struct qmi_handle *qmi, +struct sockaddr_qrtr *sq, +struct qmi_txn *txn, +const void *decoded) +{ + txn->result =0 ;/* IPA_QMI_INIT_DRIVER request was successful */ +complete (&txn->completion); + +ipa_handshake_complete (qmi, sq, true); +} + +/* The client handles one response message type sent by the modem. */ +static struct qmi_msg_handler ipa_client_msg_handlers[] = { + { + .type =QMI_RESPONSE , + .msg_id =IPA_QMI_INIT_DRIVER , + .ei = ipa_init_modem_driver_rsp_ei, + .decoded_size =IPA_QMI_INIT_DRIVER_RSP_SZ , + .fn = ipa_init_driver_rsp_fn, + }, +}; + +/* Return a pointer to an init modem driver request structure, which +* contains configuration parameters for the modem. The modem may +* be started multiple times, but generally these parameters don't +* change so we can reuse the request structure once it's initialized. +* The only exception is the skip_uc_load field, which will be set +* only after the microcontroller has reported it has completed its +* initialization. +*/ +static const struct ipa_init_modem_driver_req *init_modem_driver_req (void ) +{ +static struct ipa_init_modem_driver_req req; +u32 base; + +/* This is not the first boot if the microcontroller is loaded */ + req.skip_uc_load =ipa_uc_loaded () ?1 :0 ; + req.skip_uc_load_valid = true; + +/* We only have to initialize most of it once */ +if (req.platform_type_valid) +return &req; + +/* All offsets are relative to the start of IPA shared memory */ + base = (u32 )ipa_ctx->smem_offset; + + req.platform_type_valid = true; + req.platform_type =IPA_QMI_PLATFORM_TYPE_MSM_ANDROID ; + + req.hdr_tbl_info_valid =IPA_MEM_MODEM_HDR_SIZE ?1 :0 ; + req.hdr_tbl_info.start = base +IPA_MEM_MODEM_HDR_OFST ; + req.hdr_tbl_info.end = req.hdr_tbl_info.start + +IPA_MEM_MODEM_HDR_SIZE -1 ; + + req.v4_route_tbl_info_valid = true; + req.v4_route_tbl_info.start = base +IPA_MEM_V4_RT_NHASH_OFST ; + req.v4_route_tbl_info.count =IPA_MEM_MODEM_RT_COUNT ; + + req.v6_route_tbl_info_valid = true; + req.v6_route_tbl_info.start = base +IPA_MEM_V6_RT_NHASH_OFST ; + req.v6_route_tbl_info.count =IPA_MEM_MODEM_RT_COUNT ; + + req.v4_filter_tbl_start_valid = true; + req.v4_filter_tbl_start = base +IPA_MEM_V4_FLT_NHASH_OFST ; + + req.v6_filter_tbl_start_valid = true; + req.v6_filter_tbl_start = base +IPA_MEM_V6_FLT_NHASH_OFST ; + + req.modem_mem_info_valid =IPA_MEM_MODEM_SIZE ?1 :0 ; + req.modem_mem_info.start = base +IPA_MEM_MODEM_OFST ; + req.modem_mem_info.size =IPA_MEM_MODEM_SIZE ; + + req.ctrl_comm_dest_end_pt_valid = true; + req.ctrl_comm_dest_end_pt =ipa_client_ep_id (IPA_CLIENT_APPS_WAN_CONS ); + + req.hdr_proc_ctx_tbl_info_valid = +IPA_MEM_MODEM_HDR_PROC_CTX_SIZE ?1 :0 ; + req.hdr_proc_ctx_tbl_info.start = + base +IPA_MEM_MODEM_HDR_PROC_CTX_OFST ; + req.hdr_proc_ctx_tbl_info.end = req.hdr_proc_ctx_tbl_info.start + +IPA_MEM_MODEM_HDR_PROC_CTX_SIZE -1 ; + + req.v4_hash_route_tbl_info_valid = true; + req.v4_hash_route_tbl_info.start = base +IPA_MEM_V4_RT_HASH_OFST ; + req.v4_hash_route_tbl_info.count =IPA_MEM_MODEM_RT_COUNT ; + + req.v6_hash_route_tbl_info_valid = true; + req.v6_hash_route_tbl_info.start = base +IPA_MEM_V6_RT_HASH_OFST ; + req.v6_hash_route_tbl_info.count =IPA_MEM_MODEM_RT_COUNT ; + + req.v4_hash_filter_tbl_start_valid = true; + req.v4_hash_filter_tbl_start = base +IPA_MEM_V4_FLT_HASH_OFST ; + + req.v6_hash_filter_tbl_start_valid = true; + req.v6_hash_filter_tbl_start = base +IPA_MEM_V6_FLT_HASH_OFST ; + +return &req; +} + +/* The modem service we requested is now available via the client +* handle. Send an INIT_DRIVER request to the modem. +*/ +static int +ipa_client_new_server (struct qmi_handle *qmi,struct qmi_service *svc) +{ +const struct ipa_init_modem_driver_req *req =init_modem_driver_req (); +struct sockaddr_qrtr sq; +struct qmi_txn *txn; +int ret; + + txn =kzalloc (sizeof (*txn),GFP_KERNEL ); +if (!txn) +return -ENOMEM ; + + ret =qmi_txn_init (qmi, txn,NULL ,NULL ); +if (ret) { +kfree (txn); +return ret; + } + + sq.sq_family =AF_QIPCRTR ; + sq.sq_node = svc->node; + sq.sq_port = svc->port; + + ret =qmi_send_request (qmi, &sq, txn,IPA_QMI_INIT_DRIVER , +IPA_QMI_INIT_DRIVER_REQ_SZ , + ipa_init_modem_driver_req_ei, req); +if (!ret) + ret =qmi_txn_wait (txn,MAX_SCHEDULE_TIMEOUT ); +if (ret) +qmi_txn_cancel (txn); +kfree (txn); + +return ret; +} + +/* The only callback we supply for the client handle is notification +* that the service on the modem has become available. +*/ +static struct qmi_ops ipa_client_ops = { + .new_server = ipa_client_new_server, +}; + +static int ipa_qmi_initialize (void ) +{ +int ret; + +/* The only handle operation that might be interesting for the +* server would be del_client, to find out when the modem side +* client has disappeared. But other than reporting the event, +* we wouldn't do anything about that. So we just pass a null +* pointer for its handle operations. All the real work is +* done by the message handlers. +*/ + ret =qmi_handle_init (&server_handle,IPA_QMI_SERVER_MAX_RCV_SZ , +NULL , ipa_server_msg_handlers); +if (ret <0 ) +return ret; + + ret =qmi_add_server (&server_handle,IPA_HOST_SERVICE_SVC_ID , +IPA_HOST_SVC_VERS ,IPA_HOST_SERVICE_INS_ID ); +if (ret <0 ) + goto err_release_server_handle; + +/* The client handle is only used for sending an INIT_DRIVER +* request to the modem, and receiving its response message. +*/ + ret =qmi_handle_init (&client_handle,IPA_QMI_CLIENT_MAX_RCV_SZ , + &ipa_client_ops, ipa_client_msg_handlers); +if (ret <0 ) + goto err_release_server_handle; + + ret =qmi_add_lookup (&client_handle,IPA_MODEM_SERVICE_SVC_ID , +IPA_MODEM_SVC_VERS ,IPA_MODEM_SERVICE_INS_ID ); +if (ret <0 ) + goto err_release_client_handle; + + ipa_qmi_initialized = true; + +return 0 ; + +err_release_client_handle: +/* Releasing the handle also removes registered lookups */ +qmi_handle_release (&client_handle); +memset (&client_handle,0 ,sizeof (client_handle)); +err_release_server_handle: +/* Releasing the handle also removes registered services */ +qmi_handle_release (&server_handle); +memset (&server_handle,0 ,sizeof (server_handle)); + +return ret; +} + +/* This is called by the rmnet probe routine. The rmnet driver can +* be unregistered after it has been initialized as a result of a +* subsystem shutdown; it can later be registered again if a +* subsystem restart occurs. This function can therefore be called +* more than once. +*/ +int ipa_qmi_init (void ) +{ + init_driver_response_received = false; + indication_register_received = false; + +if (!ipa_qmi_initialized) +return ipa_qmi_initialize (); + +return 0 ; +} + +void ipa_qmi_exit (void ) +{ +if (!ipa_qmi_initialized) +return ; + +qmi_handle_release (&client_handle); +memset (&client_handle,0 ,sizeof (client_handle)); + +qmi_handle_release (&server_handle); +memset (&server_handle,0 ,sizeof (server_handle)); + + ipa_qmi_initialized = false; +}
drivers/net/ipa/ipa_qmi.h new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd. +*/ +#ifndef _IPA_QMI_H_ +#define _IPA_QMI_H_ + +int ipa_qmi_init (void ); +void ipa_qmi_exit (void ); + +#endif /* !_IPA_QMI_H_ */
drivers/net/ipa/ipa_qmi_msg.c new file +587 -0
587 lines not on this page · raw message
drivers/net/ipa/ipa_qmi_msg.h new file +233 -0
233 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH 7/12 soc: qcom: ipa: IPA register abstraction
In reply to Alex Elder(Much of the following is copied from text in "ipa_reg.c". Please see that for the more complete explanation.)
The IPA code abstracts the details of its 32-bit registers, allowing access to them to be done generically. The original motivation for this was that the field width and/or position for values stored in some registers differed for different versions of IPA hardware. Abstracting access this way allows code that uses such registers to be simpler, describing how register fields are used without proliferating special-case code that is dependent on hardware version.
Each IPA register has a name, which is one of the values in the "ipa_reg" enumerated type (e.g., IPA_ENABLED_PIPES). The offset (memory address) of the register having a given name is maintained internal to the "ipa_reg" module.
Some registers hold one or more fields that are less than 32 bits wide. Each of these registers has a data structure that breaks out those fields into individual (32-bit) values. These field structures allow the register contents to be defined in a hardware independent way. Such registers have a pair of functions associated with them to "construct" (when writing) and "parse" (when reading) the fields found within them, using the register's fields structure. This allows the content of these registers to be read in a generic way.
--- drivers/net/ipa/ipa_reg.c | 972 ++++++++++++++++++++++++++++++++++++++ drivers/net/ipa/ipa_reg.h | 614 ++++++++++++++++++++++++ 2 files changed, 1586 insertions(+) create mode 100644 drivers/net/ipa/ipa_reg.c create mode 100644 drivers/net/ipa/ipa_reg.h
drivers/net/ipa/ipa_reg.c new file +972 -0
@@ -0,0 +1,972 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd. +*/ + +#include <linux/types.h> +#include <linux/io.h> +#include <linux/bitfield.h> + +#include "ipa_reg.h" + +/* I/O remapped base address of IPA register space */ +static void __iomem *ipa_reg_virt; + +/* struct ipa_reg_desc - descriptor for an abstracted hardware register +* +* @construct - fn to construct the register value from its field structure +* @parse - function to parse register field values into its field structure +* @offset - register offset relative to base address +* @n_ofst - size multiplier for "N-parameterized" registers +*/ +struct ipa_reg_desc { +u32 (*construct)(enum ipa_reg reg,const void *fields); +void (*parse)(enum ipa_reg reg,void *fields,u32 val); +u32 offset; +u16 n_ofst; +}; + +/* IPA_ROUTE register */ + +void ipa_reg_route (struct ipa_reg_route *route,u32 ep_id) +{ + route->route_dis =0 ; + route->route_def_pipe = ep_id; + route->route_def_hdr_table =1 ; + route->route_def_hdr_ofst =0 ; + route->route_frag_def_pipe = ep_id; + route->route_def_retain_hdr =1 ; +} + +#define ROUTE_DIS_FMASK 0x00000001 +#define ROUTE_DEF_PIPE_FMASK 0x0000003e +#define ROUTE_DEF_HDR_TABLE_FMASK 0x00000040 +#define ROUTE_DEF_HDR_OFST_FMASK 0x0001ff80 +#define ROUTE_FRAG_DEF_PIPE_FMASK 0x003e0000 +#define ROUTE_DEF_RETAIN_HDR_FMASK 0x01000000 + +static u32 ipa_reg_construct_route (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_route *route = fields; +u32 val; + + val =FIELD_PREP (ROUTE_DIS_FMASK , route->route_dis); + val |=FIELD_PREP (ROUTE_DEF_PIPE_FMASK , route->route_def_pipe); + val |=FIELD_PREP (ROUTE_DEF_HDR_TABLE_FMASK , + route->route_def_hdr_table); + val |=FIELD_PREP (ROUTE_DEF_HDR_OFST_FMASK , route->route_def_hdr_ofst); + val |=FIELD_PREP (ROUTE_FRAG_DEF_PIPE_FMASK , + route->route_frag_def_pipe); + val |=FIELD_PREP (ROUTE_DEF_RETAIN_HDR_FMASK , + route->route_def_retain_hdr); + +return val; +} + +/* IPA_ENDP_INIT_HDR_N register */ + +static void +ipa_reg_endp_init_hdr_common (struct ipa_reg_endp_init_hdr *init_hdr) +{ + init_hdr->hdr_additional_const_len =0 ;/* XXX description? */ + init_hdr->hdr_a5_mux =0 ;/* XXX description? */ + init_hdr->hdr_len_inc_deagg_hdr =0 ;/* XXX description? */ + init_hdr->hdr_metadata_reg_valid =0 ;/* XXX description? */ +} + +void ipa_reg_endp_init_hdr_cons (struct ipa_reg_endp_init_hdr *init_hdr, +u32 header_size,u32 metadata_offset, +u32 length_offset) +{ + init_hdr->hdr_len = header_size; + init_hdr->hdr_ofst_metadata_valid =1 ; + init_hdr->hdr_ofst_metadata = metadata_offset;/* XXX ignored */ + init_hdr->hdr_ofst_pkt_size_valid =1 ; + init_hdr->hdr_ofst_pkt_size = length_offset; + +ipa_reg_endp_init_hdr_common (init_hdr); +} + +void ipa_reg_endp_init_hdr_prod (struct ipa_reg_endp_init_hdr *init_hdr, +u32 header_size,u32 metadata_offset, +u32 length_offset) +{ + init_hdr->hdr_len = header_size; + init_hdr->hdr_ofst_metadata_valid =1 ; + init_hdr->hdr_ofst_metadata = metadata_offset; + init_hdr->hdr_ofst_pkt_size_valid =1 ; + init_hdr->hdr_ofst_pkt_size = length_offset;/* XXX ignored */ + +ipa_reg_endp_init_hdr_common (init_hdr); +} + +#define HDR_LEN_FMASK 0x0000003f +#define HDR_OFST_METADATA_VALID_FMASK 0x00000040 +#define HDR_OFST_METADATA_FMASK 0x00001f80 +#define HDR_ADDITIONAL_CONST_LEN_FMASK 0x0007e000 +#define HDR_OFST_PKT_SIZE_VALID_FMASK 0x00080000 +#define HDR_OFST_PKT_SIZE_FMASK 0x03f00000 +#define HDR_A5_MUX_FMASK 0x04000000 +#define HDR_LEN_INC_DEAGG_HDR_FMASK 0x08000000 +#define HDR_METADATA_REG_VALID_FMASK 0x10000000 + +static u32 +ipa_reg_construct_endp_init_hdr_n (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_endp_init_hdr *init_hdr = fields; +u32 val; + + val =FIELD_PREP (HDR_LEN_FMASK , init_hdr->hdr_len); + val |=FIELD_PREP (HDR_OFST_METADATA_VALID_FMASK , + init_hdr->hdr_ofst_metadata_valid); + val |=FIELD_PREP (HDR_OFST_METADATA_FMASK , init_hdr->hdr_ofst_metadata); + val |=FIELD_PREP (HDR_ADDITIONAL_CONST_LEN_FMASK , + init_hdr->hdr_additional_const_len); + val |=FIELD_PREP (HDR_OFST_PKT_SIZE_VALID_FMASK , + init_hdr->hdr_ofst_pkt_size_valid); + val |=FIELD_PREP (HDR_OFST_PKT_SIZE_FMASK , + init_hdr->hdr_ofst_pkt_size); + val |=FIELD_PREP (HDR_A5_MUX_FMASK , init_hdr->hdr_a5_mux); + val |=FIELD_PREP (HDR_LEN_INC_DEAGG_HDR_FMASK , + init_hdr->hdr_len_inc_deagg_hdr); + val |=FIELD_PREP (HDR_METADATA_REG_VALID_FMASK , + init_hdr->hdr_metadata_reg_valid); + +return val; +} + +/* IPA_ENDP_INIT_HDR_EXT_N register */ + +void ipa_reg_endp_init_hdr_ext_common (struct ipa_reg_endp_init_hdr_ext *hdr_ext) +{ + hdr_ext->hdr_endianness =1 ;/* big endian */ + hdr_ext->hdr_total_len_or_pad_valid =1 ; + hdr_ext->hdr_total_len_or_pad =0 ;/* pad */ + hdr_ext->hdr_total_len_or_pad_offset =0 ;/* XXX description? */ +} + +void ipa_reg_endp_init_hdr_ext_cons (struct ipa_reg_endp_init_hdr_ext *hdr_ext, +u32 pad_align,bool pad_included) +{ + hdr_ext->hdr_payload_len_inc_padding = pad_included ?1 :0 ; + hdr_ext->hdr_pad_to_alignment = pad_align; + +ipa_reg_endp_init_hdr_ext_common (hdr_ext); +} + +void ipa_reg_endp_init_hdr_ext_prod (struct ipa_reg_endp_init_hdr_ext *hdr_ext, +u32 pad_align) +{ + hdr_ext->hdr_payload_len_inc_padding =0 ; + hdr_ext->hdr_pad_to_alignment = pad_align;/* XXX ignored */ + +ipa_reg_endp_init_hdr_ext_common (hdr_ext); +} + +#define HDR_ENDIANNESS_FMASK 0x00000001 +#define HDR_TOTAL_LEN_OR_PAD_VALID_FMASK 0x00000002 +#define HDR_TOTAL_LEN_OR_PAD_FMASK 0x00000004 +#define HDR_PAYLOAD_LEN_INC_PADDING_FMASK 0x00000008 +#define HDR_TOTAL_LEN_OR_PAD_OFFSET_FMASK 0x000003f0 +#define HDR_PAD_TO_ALIGNMENT_FMASK 0x00003c00 + +static u32 +ipa_reg_construct_endp_init_hdr_ext_n (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_endp_init_hdr_ext *init_hdr_ext = fields; +u32 val; + +/* 0 = little endian; 1 = big endian */ + val =FIELD_PREP (HDR_ENDIANNESS_FMASK ,1 ); + val |=FIELD_PREP (HDR_TOTAL_LEN_OR_PAD_VALID_FMASK , + init_hdr_ext->hdr_total_len_or_pad_valid); + val |=FIELD_PREP (HDR_TOTAL_LEN_OR_PAD_FMASK , + init_hdr_ext->hdr_total_len_or_pad); + val |=FIELD_PREP (HDR_PAYLOAD_LEN_INC_PADDING_FMASK , + init_hdr_ext->hdr_payload_len_inc_padding); + val |=FIELD_PREP (HDR_TOTAL_LEN_OR_PAD_OFFSET_FMASK ,0 ); + val |=FIELD_PREP (HDR_PAD_TO_ALIGNMENT_FMASK , + init_hdr_ext->hdr_pad_to_alignment); + +return val; +} + +/* IPA_ENDP_INIT_AGGR_N register */ + +static void +ipa_reg_endp_init_aggr_common (struct ipa_reg_endp_init_aggr *init_aggr) +{ + init_aggr->aggr_force_close =0 ;/* XXX description? */ + init_aggr->aggr_hard_byte_limit_en =0 ;/* XXX ignored for PROD? */ +} + +void ipa_reg_endp_init_aggr_cons (struct ipa_reg_endp_init_aggr *init_aggr, +u32 byte_limit,u32 packet_limit, +bool close_on_eof) +{ + init_aggr->aggr_en =IPA_ENABLE_AGGR ; + init_aggr->aggr_type =IPA_GENERIC ; + init_aggr->aggr_byte_limit = byte_limit; + init_aggr->aggr_time_limit =IPA_AGGR_TIME_LIMIT_DEFAULT ; + init_aggr->aggr_pkt_limit = packet_limit; + init_aggr->aggr_sw_eof_active = close_on_eof ?1 :0 ; + +ipa_reg_endp_init_aggr_common (init_aggr); +} + +void ipa_reg_endp_init_aggr_prod (struct ipa_reg_endp_init_aggr *init_aggr, +enum ipa_aggr_en aggr_en, +enum ipa_aggr_type aggr_type) +{ + init_aggr->aggr_en = (u32 )aggr_en; + init_aggr->aggr_type = aggr_en ==IPA_BYPASS_AGGR ?0 : (u32 )aggr_type; + init_aggr->aggr_byte_limit =0 ;/* ignored */ + init_aggr->aggr_time_limit =0 ;/* ignored */ + init_aggr->aggr_pkt_limit =0 ;/* ignored */ + init_aggr->aggr_sw_eof_active =0 ;/* ignored */ + +ipa_reg_endp_init_aggr_common (init_aggr); +} + +#define AGGR_EN_FMASK 0x00000003 +#define AGGR_TYPE_FMASK 0x0000001c +#define AGGR_BYTE_LIMIT_FMASK 0x000003e0 +#define AGGR_TIME_LIMIT_FMASK 0x00007c00 +#define AGGR_PKT_LIMIT_FMASK 0x001f8000 +#define AGGR_SW_EOF_ACTIVE_FMASK 0x00200000 +#define AGGR_FORCE_CLOSE_FMASK 0x00400000 +#define AGGR_HARD_BYTE_LIMIT_ENABLE_FMASK 0x01000000 + +static u32 +ipa_reg_construct_endp_init_aggr_n (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_endp_init_aggr *init_aggr = fields; +u32 val; + + val =FIELD_PREP (AGGR_EN_FMASK , init_aggr->aggr_en); + val |=FIELD_PREP (AGGR_TYPE_FMASK , init_aggr->aggr_type); + val |=FIELD_PREP (AGGR_BYTE_LIMIT_FMASK , init_aggr->aggr_byte_limit); + val |=FIELD_PREP (AGGR_TIME_LIMIT_FMASK , init_aggr->aggr_time_limit); + val |=FIELD_PREP (AGGR_PKT_LIMIT_FMASK , init_aggr->aggr_pkt_limit); + val |=FIELD_PREP (AGGR_SW_EOF_ACTIVE_FMASK , + init_aggr->aggr_sw_eof_active); + val |=FIELD_PREP (AGGR_FORCE_CLOSE_FMASK , init_aggr->aggr_force_close); + val |=FIELD_PREP (AGGR_HARD_BYTE_LIMIT_ENABLE_FMASK , + init_aggr->aggr_hard_byte_limit_en); + +return val; +} + +static void +ipa_reg_parse_endp_init_aggr_n (enum ipa_reg reg,void *fields,u32 val) +{ +struct ipa_reg_endp_init_aggr *init_aggr = fields; + +memset (init_aggr,0 ,sizeof (*init_aggr)); + + init_aggr->aggr_en =FIELD_GET (AGGR_EN_FMASK , val); + init_aggr->aggr_type =FIELD_GET (AGGR_TYPE_FMASK , val); + init_aggr->aggr_byte_limit =FIELD_GET (AGGR_BYTE_LIMIT_FMASK , val); + init_aggr->aggr_time_limit =FIELD_GET (AGGR_TIME_LIMIT_FMASK , val); + init_aggr->aggr_pkt_limit =FIELD_GET (AGGR_PKT_LIMIT_FMASK , val); + init_aggr->aggr_sw_eof_active = +FIELD_GET (AGGR_SW_EOF_ACTIVE_FMASK , val); + init_aggr->aggr_force_close =FIELD_GET (AGGR_SW_EOF_ACTIVE_FMASK , val); + init_aggr->aggr_hard_byte_limit_en = +FIELD_GET (AGGR_HARD_BYTE_LIMIT_ENABLE_FMASK , val); +} + +/* IPA_AGGR_FORCE_CLOSE register */ + +void ipa_reg_aggr_force_close (struct ipa_reg_aggr_force_close *force_close, +u32 pipe_bitmap) +{ + force_close->pipe_bitmap = pipe_bitmap; +} + +#define PIPE_BITMAP_FMASK 0x000fffff + +static u32 +ipa_reg_construct_aggr_force_close (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_aggr_force_close *force_close = fields; + +return FIELD_PREP (PIPE_BITMAP_FMASK , force_close->pipe_bitmap); +} + +/* IPA_ENDP_INIT_MODE_N register */ + +static void +ipa_reg_endp_init_mode_common (struct ipa_reg_endp_init_mode *init_mode) +{ + init_mode->byte_threshold =0 ;/* XXX description? */ + init_mode->pipe_replication_en =0 ;/* XXX description? */ + init_mode->pad_en =0 ;/* XXX description? */ + init_mode->hdr_ftch_disable =0 ;/* XXX description? */ +} + +/* IPA_ENDP_INIT_MODE is not valid for consumer pipes */ +void ipa_reg_endp_init_mode_cons (struct ipa_reg_endp_init_mode *init_mode) +{ + init_mode->mode =0 ;/* ignored */ + init_mode->dest_pipe_index =0 ;/* ignored */ + +ipa_reg_endp_init_mode_common (init_mode); +} + +void ipa_reg_endp_init_mode_prod (struct ipa_reg_endp_init_mode *init_mode, +enum ipa_mode mode,u32 dest_endp) +{ + init_mode->mode = mode; + init_mode->dest_pipe_index = mode ==IPA_DMA ? dest_endp :0 ; + +ipa_reg_endp_init_mode_common (init_mode); +} + +#define MODE_FMASK 0x00000007 +#define DEST_PIPE_INDEX_FMASK 0x000001f0 +#define BYTE_THRESHOLD_FMASK 0x0ffff000 +#define PIPE_REPLICATION_EN_FMASK 0x10000000 +#define PAD_EN_FMASK 0x20000000 +#define HDR_FTCH_DISABLE_FMASK 0x40000000 + +static u32 +ipa_reg_construct_endp_init_mode_n (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_endp_init_mode *init_mode = fields; +u32 val; + + val =FIELD_PREP (MODE_FMASK , init_mode->mode); + val |=FIELD_PREP (DEST_PIPE_INDEX_FMASK , init_mode->dest_pipe_index); + val |=FIELD_PREP (BYTE_THRESHOLD_FMASK , init_mode->byte_threshold); + val |=FIELD_PREP (PIPE_REPLICATION_EN_FMASK , + init_mode->pipe_replication_en); + val |=FIELD_PREP (PAD_EN_FMASK , init_mode->pad_en); + val |=FIELD_PREP (HDR_FTCH_DISABLE_FMASK , init_mode->hdr_ftch_disable); + +return val; +} + +/* IPA_ENDP_INIT_CTRL_N register */ + +void +ipa_reg_endp_init_ctrl (struct ipa_reg_endp_init_ctrl *init_ctrl,bool suspend) +{ + init_ctrl->endp_suspend = suspend ?1 :0 ; + init_ctrl->endp_delay =0 ; +} + +#define ENDP_SUSPEND_FMASK 0x00000001 +#define ENDP_DELAY_FMASK 0x00000002 + +static u32 +ipa_reg_construct_endp_init_ctrl_n (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_endp_init_ctrl *init_ctrl = fields; +u32 val; + + val =FIELD_PREP (ENDP_SUSPEND_FMASK , init_ctrl->endp_suspend); + val |=FIELD_PREP (ENDP_DELAY_FMASK , init_ctrl->endp_delay); + +return val; +} + +static void +ipa_reg_parse_endp_init_ctrl_n (enum ipa_reg reg,void *fields,u32 val) +{ +struct ipa_reg_endp_init_ctrl *init_ctrl = fields; + +memset (init_ctrl,0 ,sizeof (*init_ctrl)); + + init_ctrl->endp_suspend =FIELD_GET (ENDP_SUSPEND_FMASK , val); + init_ctrl->endp_delay =FIELD_GET (ENDP_DELAY_FMASK , val); +} + +/* IPA_ENDP_INIT_DEAGGR_N register */ + +static void +ipa_reg_endp_init_deaggr_common (struct ipa_reg_endp_init_deaggr *init_deaggr) +{ + init_deaggr->deaggr_hdr_len =0 ;/* XXX description? */ + init_deaggr->packet_offset_valid =0 ;/* XXX description? */ + init_deaggr->packet_offset_location =0 ;/* XXX description? */ + init_deaggr->max_packet_len =0 ;/* XXX description? */ +} + +/* XXX The deaggr setting seems not to be valid for consumer endpoints */ +void +ipa_reg_endp_init_deaggr_cons (struct ipa_reg_endp_init_deaggr *init_deaggr) +{ +ipa_reg_endp_init_deaggr_common (init_deaggr); +} + +void +ipa_reg_endp_init_deaggr_prod (struct ipa_reg_endp_init_deaggr *init_deaggr) +{ +ipa_reg_endp_init_deaggr_common (init_deaggr); +} + +#define DEAGGR_HDR_LEN_FMASK 0x0000003f +#define PACKET_OFFSET_VALID_FMASK 0x00000080 +#define PACKET_OFFSET_LOCATION_FMASK 0x00003f00 +#define MAX_PACKET_LEN_FMASK 0xffff0000 + +static u32 +ipa_reg_construct_endp_init_deaggr_n (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_endp_init_deaggr *init_deaggr = fields; +u32 val; + +/* fields value is completely ignored (can be NULL) */ + val =FIELD_PREP (DEAGGR_HDR_LEN_FMASK , init_deaggr->deaggr_hdr_len); + val |=FIELD_PREP (PACKET_OFFSET_VALID_FMASK , + init_deaggr->packet_offset_valid); + val |=FIELD_PREP (PACKET_OFFSET_LOCATION_FMASK , + init_deaggr->packet_offset_location); + val |=FIELD_PREP (MAX_PACKET_LEN_FMASK , + init_deaggr->max_packet_len); + +return val; +} + +/* IPA_ENDP_INIT_SEQ_N register */ + +static void +ipa_reg_endp_init_seq_common (struct ipa_reg_endp_init_seq *init_seq) +{ + init_seq->dps_seq_type =0 ;/* XXX description? */ + init_seq->hps_rep_seq_type =0 ;/* XXX description? */ + init_seq->dps_rep_seq_type =0 ;/* XXX description? */ +} + +void ipa_reg_endp_init_seq_cons (struct ipa_reg_endp_init_seq *init_seq) +{ + init_seq->hps_seq_type =0 ;/* ignored */ + +ipa_reg_endp_init_seq_common (init_seq); +} + +void ipa_reg_endp_init_seq_prod (struct ipa_reg_endp_init_seq *init_seq, +enum ipa_seq_type seq_type) +{ + init_seq->hps_seq_type = (u32 )seq_type; + +ipa_reg_endp_init_seq_common (init_seq); +} + +#define HPS_SEQ_TYPE_FMASK 0x0000000f +#define DPS_SEQ_TYPE_FMASK 0x000000f0 +#define HPS_REP_SEQ_TYPE_FMASK 0x00000f00 +#define DPS_REP_SEQ_TYPE_FMASK 0x0000f000 + +static u32 +ipa_reg_construct_endp_init_seq_n (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_endp_init_seq *init_seq = fields; +u32 val; + + val =FIELD_PREP (HPS_SEQ_TYPE_FMASK , init_seq->hps_seq_type); + val |=FIELD_PREP (DPS_SEQ_TYPE_FMASK , init_seq->dps_seq_type); + val |=FIELD_PREP (HPS_REP_SEQ_TYPE_FMASK , init_seq->hps_rep_seq_type); + val |=FIELD_PREP (DPS_REP_SEQ_TYPE_FMASK , init_seq->dps_rep_seq_type); + +return val; +} + +/* IPA_ENDP_INIT_CFG_N register */ + +static void +ipa_reg_endp_init_cfg_common (struct ipa_reg_endp_init_cfg *init_cfg) +{ + init_cfg->frag_offload_en =0 ;/* XXX description? */ + init_cfg->cs_gen_qmb_master_sel =0 ;/* XXX description? */ +} + +void ipa_reg_endp_init_cfg_cons (struct ipa_reg_endp_init_cfg *init_cfg, +enum ipa_cs_offload_en offload_type) +{ + init_cfg->cs_offload_en = offload_type; + init_cfg->cs_metadata_hdr_offset =0 ;/* ignored */ + +ipa_reg_endp_init_cfg_common (init_cfg); +} + +void ipa_reg_endp_init_cfg_prod (struct ipa_reg_endp_init_cfg *init_cfg, +enum ipa_cs_offload_en offload_type, +u32 metadata_offset) +{ + init_cfg->cs_offload_en = offload_type; + init_cfg->cs_metadata_hdr_offset = metadata_offset; + +ipa_reg_endp_init_cfg_common (init_cfg); +} + +#define FRAG_OFFLOAD_EN_FMASK 0x00000001 +#define CS_OFFLOAD_EN_FMASK 0x00000006 +#define CS_METADATA_HDR_OFFSET_FMASK 0x00000078 +#define CS_GEN_QMB_MASTER_SEL_FMASK 0x00000100 + +static u32 +ipa_reg_construct_endp_init_cfg_n (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_endp_init_cfg *init_cfg = fields; +u32 val; + + val =FIELD_PREP (FRAG_OFFLOAD_EN_FMASK , init_cfg->frag_offload_en); + val |=FIELD_PREP (CS_OFFLOAD_EN_FMASK , init_cfg->cs_offload_en); + val |=FIELD_PREP (CS_METADATA_HDR_OFFSET_FMASK , + init_cfg->cs_metadata_hdr_offset); + val |=FIELD_PREP (CS_GEN_QMB_MASTER_SEL_FMASK , + init_cfg->cs_gen_qmb_master_sel); + +return val; +} + +/* IPA_ENDP_INIT_HDR_METADATA_MASK_N register */ + +void ipa_reg_endp_init_hdr_metadata_mask_cons ( +struct ipa_reg_endp_init_hdr_metadata_mask *metadata_mask, +u32 mask) +{ + metadata_mask->metadata_mask = mask; +} + +/* IPA_ENDP_INIT_HDR_METADATA_MASK is not valid for producer pipes */ +void ipa_reg_endp_init_hdr_metadata_mask_prod ( +struct ipa_reg_endp_init_hdr_metadata_mask *metadata_mask) +{ + metadata_mask->metadata_mask =0 ;/* ignored */ +} + + +#define METADATA_MASK_FMASK 0xffffffff + +static u32 ipa_reg_construct_endp_init_hdr_metadata_mask_n (enum ipa_reg reg, +const void *fields) +{ +const struct ipa_reg_endp_init_hdr_metadata_mask *metadata_mask; + + metadata_mask = fields; + +return FIELD_PREP (METADATA_MASK_FMASK , metadata_mask->metadata_mask); +} + +/* IPA_SHARED_MEM_SIZE register (read-only) */ + +#define SHARED_MEM_SIZE_FMASK 0x0000ffff +#define SHARED_MEM_BADDR_FMASK 0xffff0000 + +static void +ipa_reg_parse_shared_mem_size (enum ipa_reg reg,void *fields,u32 val) +{ +struct ipa_reg_shared_mem_size *mem_size = fields; + +memset (mem_size,0 ,sizeof (*mem_size)); + + mem_size->shared_mem_size =FIELD_GET (SHARED_MEM_SIZE_FMASK , val); + mem_size->shared_mem_baddr =FIELD_GET (SHARED_MEM_BADDR_FMASK , val); +} + +/* IPA_ENDP_STATUS_N register */ + +static void ipa_reg_endp_status_common (struct ipa_reg_endp_status *endp_status) +{ + endp_status->status_pkt_suppress =0 ;/* XXX description? */ +} + +void ipa_reg_endp_status_cons (struct ipa_reg_endp_status *endp_status, +bool enable) +{ + endp_status->status_en = enable ?1 :0 ; + endp_status->status_endp =0 ;/* ignored */ + endp_status->status_location =0 ;/* before packet data */ + +ipa_reg_endp_status_common (endp_status); +} + +void ipa_reg_endp_status_prod (struct ipa_reg_endp_status *endp_status, +bool enable,u32 endp) +{ + endp_status->status_en = enable ?1 :0 ; + endp_status->status_endp = endp; + endp_status->status_location =0 ;/* ignored */ + +ipa_reg_endp_status_common (endp_status); +} + +#define STATUS_EN_FMASK 0x00000001 +#define STATUS_ENDP_FMASK 0x0000003e +#define STATUS_LOCATION_FMASK 0x00000100 +#define STATUS_PKT_SUPPRESS_FMASK 0x00000200 + +static u32 ipa_reg_construct_endp_status_n (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_endp_status *endp_status = fields; +u32 val; + + val =FIELD_PREP (STATUS_EN_FMASK , endp_status->status_en); + val |=FIELD_PREP (STATUS_ENDP_FMASK , endp_status->status_endp); + val |=FIELD_PREP (STATUS_LOCATION_FMASK , endp_status->status_location); + val |=FIELD_PREP (STATUS_PKT_SUPPRESS_FMASK ,0 ); + +return val; +} + +/* IPA_ENDP_FILTER_ROUTER_HSH_CFG_N register */ + +void ipa_reg_hash_tuple (struct ipa_reg_hash_tuple *tuple) +{ + tuple->src_id =0 ;/* pipe number in flt, table index in rt */ + tuple->src_ip =0 ; + tuple->dst_ip =0 ; + tuple->src_port =0 ; + tuple->dst_port =0 ; + tuple->protocol =0 ; + tuple->metadata =0 ; + tuple->undefined =0 ; +} + +#define FILTER_HASH_MSK_SRC_ID_FMASK 0x00000001 +#define FILTER_HASH_MSK_SRC_IP_FMASK 0x00000002 +#define FILTER_HASH_MSK_DST_IP_FMASK 0x00000004 +#define FILTER_HASH_MSK_SRC_PORT_FMASK 0x00000008 +#define FILTER_HASH_MSK_DST_PORT_FMASK 0x00000010 +#define FILTER_HASH_MSK_PROTOCOL_FMASK 0x00000020 +#define FILTER_HASH_MSK_METADATA_FMASK 0x00000040 +#define FILTER_HASH_UNDEFINED1_FMASK 0x0000ff80 + +#define ROUTER_HASH_MSK_SRC_ID_FMASK 0x00010000 +#define ROUTER_HASH_MSK_SRC_IP_FMASK 0x00020000 +#define ROUTER_HASH_MSK_DST_IP_FMASK 0x00040000 +#define ROUTER_HASH_MSK_SRC_PORT_FMASK 0x00080000 +#define ROUTER_HASH_MSK_DST_PORT_FMASK 0x00100000 +#define ROUTER_HASH_MSK_PROTOCOL_FMASK 0x00200000 +#define ROUTER_HASH_MSK_METADATA_FMASK 0x00400000 +#define ROUTER_HASH_UNDEFINED2_FMASK 0xff800000 + +static u32 ipa_reg_construct_hash_cfg_n (enum ipa_reg reg,const void *fields) +{ +const struct ipa_ep_filter_router_hsh_cfg *hsh_cfg = fields; +u32 val; + + val =FIELD_PREP (FILTER_HASH_MSK_SRC_ID_FMASK , hsh_cfg->flt.src_id); + val |=FIELD_PREP (FILTER_HASH_MSK_SRC_IP_FMASK , hsh_cfg->flt.src_ip); + val |=FIELD_PREP (FILTER_HASH_MSK_DST_IP_FMASK , hsh_cfg->flt.dst_ip); + val |=FIELD_PREP (FILTER_HASH_MSK_SRC_PORT_FMASK , + hsh_cfg->flt.src_port); + val |=FIELD_PREP (FILTER_HASH_MSK_DST_PORT_FMASK , + hsh_cfg->flt.dst_port); + val |=FIELD_PREP (FILTER_HASH_MSK_PROTOCOL_FMASK , + hsh_cfg->flt.protocol); + val |=FIELD_PREP (FILTER_HASH_MSK_METADATA_FMASK , + hsh_cfg->flt.metadata); + val |=FIELD_PREP (FILTER_HASH_UNDEFINED1_FMASK , hsh_cfg->flt.undefined); + + val |=FIELD_PREP (ROUTER_HASH_MSK_SRC_ID_FMASK , hsh_cfg->rt.src_id); + val |=FIELD_PREP (ROUTER_HASH_MSK_SRC_IP_FMASK , hsh_cfg->rt.src_ip); + val |=FIELD_PREP (ROUTER_HASH_MSK_DST_IP_FMASK , hsh_cfg->rt.dst_ip); + val |=FIELD_PREP (ROUTER_HASH_MSK_SRC_PORT_FMASK , hsh_cfg->rt.src_port); + val |=FIELD_PREP (ROUTER_HASH_MSK_DST_PORT_FMASK , hsh_cfg->rt.dst_port); + val |=FIELD_PREP (ROUTER_HASH_MSK_PROTOCOL_FMASK , hsh_cfg->rt.protocol); + val |=FIELD_PREP (ROUTER_HASH_MSK_METADATA_FMASK , hsh_cfg->rt.metadata); + val |=FIELD_PREP (FILTER_HASH_UNDEFINED1_FMASK , hsh_cfg->rt.undefined); + +return val; +} + +static void ipa_reg_parse_hash_cfg_n (enum ipa_reg reg,void *fields,u32 val) +{ +struct ipa_ep_filter_router_hsh_cfg *hsh_cfg = fields; + +memset (hsh_cfg,0 ,sizeof (*hsh_cfg)); + + hsh_cfg->flt.src_id =FIELD_GET (FILTER_HASH_MSK_SRC_ID_FMASK , val); + hsh_cfg->flt.src_ip =FIELD_GET (FILTER_HASH_MSK_SRC_IP_FMASK , val); + hsh_cfg->flt.dst_ip =FIELD_GET (FILTER_HASH_MSK_DST_IP_FMASK , val); + hsh_cfg->flt.src_port =FIELD_GET (FILTER_HASH_MSK_SRC_PORT_FMASK , val); + hsh_cfg->flt.dst_port =FIELD_GET (FILTER_HASH_MSK_DST_PORT_FMASK , val); + hsh_cfg->flt.protocol =FIELD_GET (FILTER_HASH_MSK_PROTOCOL_FMASK , val); + hsh_cfg->flt.metadata =FIELD_GET (FILTER_HASH_MSK_METADATA_FMASK , val); + hsh_cfg->flt.undefined =FIELD_GET (FILTER_HASH_UNDEFINED1_FMASK , val); + + hsh_cfg->rt.src_id =FIELD_GET (ROUTER_HASH_MSK_SRC_ID_FMASK , val); + hsh_cfg->rt.src_ip =FIELD_GET (ROUTER_HASH_MSK_SRC_IP_FMASK , val); + hsh_cfg->rt.dst_ip =FIELD_GET (ROUTER_HASH_MSK_DST_IP_FMASK , val); + hsh_cfg->rt.src_port =FIELD_GET (ROUTER_HASH_MSK_SRC_PORT_FMASK , val); + hsh_cfg->rt.dst_port =FIELD_GET (ROUTER_HASH_MSK_DST_PORT_FMASK , val); + hsh_cfg->rt.protocol =FIELD_GET (ROUTER_HASH_MSK_PROTOCOL_FMASK , val); + hsh_cfg->rt.metadata =FIELD_GET (ROUTER_HASH_MSK_METADATA_FMASK , val); + hsh_cfg->rt.undefined =FIELD_GET (ROUTER_HASH_UNDEFINED2_FMASK , val); +} + +/* IPA_RSRC_GRP_XY_RSRC_TYPE_N register(s) */ + +void +ipa_reg_rsrc_grp_xy_rsrc_type_n (struct ipa_reg_rsrc_grp_xy_rsrc_type_n *limits, +u32 x_min,u32 x_max,u32 y_min,u32 y_max) +{ + limits->x_min = x_min; + limits->x_max = x_max; + limits->y_min = y_min; + limits->y_max = y_max; +} + +#define X_MIN_LIM_FMASK 0x0000003f +#define X_MAX_LIM_FMASK 0x00003f00 +#define Y_MIN_LIM_FMASK 0x003f0000 +#define Y_MAX_LIM_FMASK 0x3f000000 + +static u32 +ipa_reg_construct_rsrg_grp_xy_rsrc_type_n (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_rsrc_grp_xy_rsrc_type_n *limits = fields; +u32 val; + + val =FIELD_PREP (X_MIN_LIM_FMASK , limits->x_min); + val |=FIELD_PREP (X_MAX_LIM_FMASK , limits->x_max); + +/* DST_23 register has only X fields at ipa V3_5 */ +if (reg ==IPA_DST_RSRC_GRP_23_RSRC_TYPE_N ) +return val; + + val |=FIELD_PREP (Y_MIN_LIM_FMASK , limits->y_min); + val |=FIELD_PREP (Y_MAX_LIM_FMASK , limits->y_max); + +return val; +} + +/* IPA_QSB_MAX_WRITES register */ + +void ipa_reg_qsb_max_writes (struct ipa_reg_qsb_max_writes *max_writes, +u32 qmb_0_max_writes,u32 qmb_1_max_writes) +{ + max_writes->qmb_0_max_writes = qmb_0_max_writes; + max_writes->qmb_1_max_writes = qmb_1_max_writes; +} + +#define GEN_QMB_0_MAX_WRITES_FMASK 0x0000000f +#define GEN_QMB_1_MAX_WRITES_FMASK 0x000000f0 + +static u32 +ipa_reg_construct_qsb_max_writes (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_qsb_max_writes *max_writes = fields; +u32 val; + + val =FIELD_PREP (GEN_QMB_0_MAX_WRITES_FMASK , + max_writes->qmb_0_max_writes); + val |=FIELD_PREP (GEN_QMB_1_MAX_WRITES_FMASK , + max_writes->qmb_1_max_writes); + +return val; +} + +/* IPA_QSB_MAX_READS register */ + +void ipa_reg_qsb_max_reads (struct ipa_reg_qsb_max_reads *max_reads, +u32 qmb_0_max_reads,u32 qmb_1_max_reads) +{ + max_reads->qmb_0_max_reads = qmb_0_max_reads; + max_reads->qmb_1_max_reads = qmb_1_max_reads; +} + +#define GEN_QMB_0_MAX_READS_FMASK 0x0000000f +#define GEN_QMB_1_MAX_READS_FMASK 0x000000f0 + +static u32 ipa_reg_construct_qsb_max_reads (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_qsb_max_reads *max_reads = fields; +u32 val; + + val =FIELD_PREP (GEN_QMB_0_MAX_READS_FMASK , max_reads->qmb_0_max_reads); + val |=FIELD_PREP (GEN_QMB_1_MAX_READS_FMASK , + max_reads->qmb_1_max_reads); + +return val; +} + +/* IPA_IDLE_INDICATION_CFG register */ + +void ipa_reg_idle_indication_cfg (struct ipa_reg_idle_indication_cfg *indication, +u32 debounce_thresh,bool non_idle_enable) +{ + indication->enter_idle_debounce_thresh = debounce_thresh; + indication->const_non_idle_enable = non_idle_enable; +} + +#define ENTER_IDLE_DEBOUNCE_THRESH_FMASK 0x0000ffff +#define CONST_NON_IDLE_ENABLE_FMASK 0x00010000 + +static u32 +ipa_reg_construct_idle_indication_cfg (enum ipa_reg reg,const void *fields) +{ +const struct ipa_reg_idle_indication_cfg *indication_cfg; +u32 val; + + indication_cfg = fields; + + val =FIELD_PREP (ENTER_IDLE_DEBOUNCE_THRESH_FMASK , + indication_cfg->enter_idle_debounce_thresh); + val |=FIELD_PREP (CONST_NON_IDLE_ENABLE_FMASK , + indication_cfg->const_non_idle_enable); + +return val; +} + +/* The entries in the following table have the following constraints: +* - 0 is not a valid offset (it represents an unused entry). It is +* a bug for code to attempt to access a register which has an +* undefined (zero) offset value. +* - If a construct function is supplied, the register must be +* written using ipa_write_reg_n_fields() (or its wrapper +* function ipa_write_reg_fields()). +* - Generally, if a parse function is supplied, the register should +* read using ipa_read_reg_n_fields() (or ipa_read_reg_fields()). +* (Currently some debug code reads some registers directly, without +* parsing.) +*/ +#define cfunc (f) ipa_reg_construct_ ## f +#define pfunc (f) ipa_reg_parse_ ## f +#define reg_obj_common (id, cf, pf, o, n) \ + [id] = { \ + .construct = cf, \ + .parse = pf, \ + .offset = o, \ + .n_ofst = n, \ + } +#define reg_obj_cfunc (id, f, o, n) \ + reg_obj_common(id, cfunc(f), NULL, o, n) +#define reg_obj_pfunc (id, f, o, n) \ + reg_obj_common(id, NULL, pfunc(f), o, n) +#define reg_obj_both (id, f, o, n) \ + reg_obj_common(id, cfunc(f), pfunc(f), o, n) +#define reg_obj_nofunc (id, o, n) \ + reg_obj_common(id, NULL, NULL, o, n) + +/* IPAv3.5.1 */ +static const struct ipa_reg_desc ipa_reg[] = { +reg_obj_cfunc (IPA_ROUTE , route,0x00000048 ,0x0000 ), +reg_obj_nofunc (IPA_IRQ_STTS_EE_N ,0x00003008 ,0x1000 ), +reg_obj_nofunc (IPA_IRQ_EN_EE_N ,0x0000300c ,0x1000 ), +reg_obj_nofunc (IPA_IRQ_CLR_EE_N ,0x00003010 ,0x1000 ), +reg_obj_nofunc (IPA_IRQ_SUSPEND_INFO_EE_N ,0x00003030 ,0x1000 ), +reg_obj_nofunc (IPA_SUSPEND_IRQ_EN_EE_N ,0x00003034 ,0x1000 ), +reg_obj_nofunc (IPA_SUSPEND_IRQ_CLR_EE_N ,0x00003038 ,0x1000 ), +reg_obj_nofunc (IPA_BCR ,0x000001d0 ,0x0000 ), +reg_obj_nofunc (IPA_ENABLED_PIPES ,0x00000038 ,0x0000 ), +reg_obj_nofunc (IPA_TAG_TIMER ,0x00000060 ,0x0000 ), +reg_obj_nofunc (IPA_STATE_AGGR_ACTIVE ,0x0000010c ,0x0000 ), +reg_obj_cfunc (IPA_ENDP_INIT_HDR_N , + endp_init_hdr_n,0x00000810 ,0x0070 ), +reg_obj_cfunc (IPA_ENDP_INIT_HDR_EXT_N , + endp_init_hdr_ext_n,0x00000814 ,0x0070 ), +reg_obj_both (IPA_ENDP_INIT_AGGR_N , + endp_init_aggr_n,0x00000824 ,0x0070 ), +reg_obj_cfunc (IPA_AGGR_FORCE_CLOSE , + aggr_force_close,0x000001ec ,0x0000 ), +reg_obj_cfunc (IPA_ENDP_INIT_MODE_N , + endp_init_mode_n,0x00000820 ,0x0070 ), +reg_obj_both (IPA_ENDP_INIT_CTRL_N , + endp_init_ctrl_n,0x00000800 ,0x0070 ), +reg_obj_cfunc (IPA_ENDP_INIT_DEAGGR_N , + endp_init_deaggr_n,0x00000834 ,0x0070 ), +reg_obj_cfunc (IPA_ENDP_INIT_SEQ_N , + endp_init_seq_n,0x0000083c ,0x0070 ), +reg_obj_cfunc (IPA_ENDP_INIT_CFG_N , + endp_init_cfg_n,0x00000808 ,0x0070 ), +reg_obj_nofunc (IPA_IRQ_EE_UC_N ,0x0000301c ,0x1000 ), +reg_obj_cfunc (IPA_ENDP_INIT_HDR_METADATA_MASK_N , + endp_init_hdr_metadata_mask_n,0x00000818 ,0x0070 ), +reg_obj_pfunc (IPA_SHARED_MEM_SIZE , + shared_mem_size,0x00000054 ,0x0000 ), +reg_obj_nofunc (IPA_SRAM_DIRECT_ACCESS_N ,0x00007000 ,0x0004 ), +reg_obj_nofunc (IPA_LOCAL_PKT_PROC_CNTXT_BASE ,0x000001e8 ,0x0000 ), +reg_obj_cfunc (IPA_ENDP_STATUS_N , + endp_status_n,0x00000840 ,0x0070 ), +reg_obj_both (IPA_ENDP_FILTER_ROUTER_HSH_CFG_N , + hash_cfg_n,0x0000085c ,0x0070 ), +reg_obj_cfunc (IPA_SRC_RSRC_GRP_01_RSRC_TYPE_N , + rsrg_grp_xy_rsrc_type_n,0x00000400 ,0x0020 ), +reg_obj_cfunc (IPA_SRC_RSRC_GRP_23_RSRC_TYPE_N , + rsrg_grp_xy_rsrc_type_n,0x00000404 ,0x0020 ), +reg_obj_cfunc (IPA_DST_RSRC_GRP_01_RSRC_TYPE_N , + rsrg_grp_xy_rsrc_type_n,0x00000500 ,0x0020 ), +reg_obj_cfunc (IPA_DST_RSRC_GRP_23_RSRC_TYPE_N , + rsrg_grp_xy_rsrc_type_n,0x00000504 ,0x0020 ), +reg_obj_cfunc (IPA_QSB_MAX_WRITES , + qsb_max_writes,0x00000074 ,0x0000 ), +reg_obj_cfunc (IPA_QSB_MAX_READS , + qsb_max_reads,0x00000078 ,0x0000 ), +reg_obj_cfunc (IPA_IDLE_INDICATION_CFG , + idle_indication_cfg,0x00000220 ,0x0000 ), +}; + +#undef reg_obj_nofunc +#undef reg_obj_both +#undef reg_obj_pfunc +#undef reg_obj_cfunc +#undef reg_obj_common +#undef pfunc +#undef cfunc + +int ipa_reg_init (phys_addr_t phys_addr,size_t size) +{ + ipa_reg_virt =ioremap (phys_addr, size); + +return ipa_reg_virt ?0 : -ENOMEM ; +} + +void ipa_reg_exit (void ) +{ +iounmap (ipa_reg_virt); + ipa_reg_virt =NULL ; +} + +/* Get the offset of an "n parameterized" register */ +u32 ipa_reg_n_offset (enum ipa_reg reg,u32 n) +{ +return ipa_reg[reg].offset + n * ipa_reg[reg].n_ofst; +} + +/* ipa_read_reg_n() - Get an "n parameterized" register's value */ +u32 ipa_read_reg_n (enum ipa_reg reg,u32 n) +{ +return ioread32 (ipa_reg_virt +ipa_reg_n_offset (reg, n)); +} + +/* ipa_write_reg_n() - Write a raw value to an "n parameterized" register */ +void ipa_write_reg_n (enum ipa_reg reg,u32 n,u32 val) +{ +iowrite32 (val, ipa_reg_virt +ipa_reg_n_offset (reg, n)); +} + +/* ipa_read_reg_n_fields() - Parse value of an "n parameterized" register */ +void ipa_read_reg_n_fields (enum ipa_reg reg,u32 n,void *fields) +{ +u32 val =ipa_read_reg_n (reg, n); + + ipa_reg[reg].parse (reg, fields, val); +} + +/* ipa_write_reg_n_fields() - Construct a vlaue to write to an "n +* parameterized" register +*/ +void ipa_write_reg_n_fields (enum ipa_reg reg,u32 n,const void *fields) +{ +u32 val = ipa_reg[reg].construct (reg, fields); + +ipa_write_reg_n (reg, n, val); +} + +/* Maximum representable aggregation byte limit value (in bytes) */ +u32 ipa_reg_aggr_max_byte_limit (void ) +{ +return FIELD_MAX (AGGR_BYTE_LIMIT_FMASK ) *SZ_1K ; +} + +/* Maximum representable aggregation packet limit value */ +u32 ipa_reg_aggr_max_packet_limit (void ) +{ +return FIELD_MAX (AGGR_PKT_LIMIT_FMASK ); +}
drivers/net/ipa/ipa_reg.h new file +614 -0
614 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH 8/12 soc: qcom: ipa: utility functions
In reply to Alex ElderThis patch contains "ipa_utils.c", which provides some miscellaneous supporting code. Included are:
- Endpoint configuration. The IPA hardware has a fixed number of endpoints (pipes) available. In some cases the AP and modem must agree on aspects of these. A key example is that they need to agree what particular endpoints are used for (the modem can't send messages to the AP command endpoint, for example). There is a static array that defines these parameters, and this is found in "ipa_utils.c".
- Resource group configuration. The IPA has a number of internal resources it uses for its operation. These are configurable, and it is up to the AP to set these configuration values at initialization time. There are some static arrays that define these configuration values. Functions are also defined here to send those values to hardware.
- Shared memory. The IPA uses a region of shared memory to hold various data structures. A function ipa_sram_settings_read() fetches the location and size of this shared memory. (The individual regions are currently initialized in "ipa_main.c".)
- Endpoint configuration. Each endpoint (or channel) has a number of configurable properties. Functions found in this file are used to configure these properties.
- Interconnect handling. The IPA driver depends on the interconnect framework to request that buses it uses be enabled when needed.
This is not a complete list, but it covers much of the functionality found in "ipa_utils.c".
--- drivers/net/ipa/ipa_utils.c | 1035 +++++++++++++++++++++++++++++++++++ 1 file changed, 1035 insertions(+) create mode 100644 drivers/net/ipa/ipa_utils.c
drivers/net/ipa/ipa_utils.c new file +1035 -0
@@ -0,0 +1,1035 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd. +*/ + +#include <linux/types.h> +#include <linux/device.h> +#include <linux/interconnect.h> +#include <linux/module.h> +#include <linux/delay.h> + +#include "ipa_dma.h" +#include "ipa_i.h" +#include "ipahal.h" + +/* Interconnect path bandwidths (each times 1000 bytes per second) */ +#define IPA_MEMORY_AVG 80000 +#define IPA_MEMORY_PEAK 600000 + +#define IPA_IMEM_AVG 80000 +#define IPA_IMEM_PEAK 350000 + +#define IPA_CONFIG_AVG 40000 +#define IPA_CONFIG_PEAK 40000 + +#define IPA_BCR_REG_VAL 0x0000003b + +#define IPA_GSI_DMA_TASK_TIMEOUT 15/* milliseconds */ + +#define IPA_GSI_CHANNEL_STOP_SLEEP_MIN 1000/* microseconds */ +#define IPA_GSI_CHANNEL_STOP_SLEEP_MAX 2000/* microseconds */ + +#define QMB_MASTER_SELECT_DDR 0 + +enum ipa_rsrc_group { +IPA_RSRC_GROUP_LWA_DL ,/* currently not used */ +IPA_RSRC_GROUP_UL_DL , +IPA_RSRC_GROUP_MAX , +}; + +enum ipa_rsrc_grp_type_src { +IPA_RSRC_GRP_TYPE_SRC_PKT_CONTEXTS , +IPA_RSRC_GRP_TYPE_SRS_DESCRIPTOR_LISTS , +IPA_RSRC_GRP_TYPE_SRC_DESCRIPTOR_BUFF , +IPA_RSRC_GRP_TYPE_SRC_HPS_DMARS , +IPA_RSRC_GRP_TYPE_SRC_ACK_ENTRIES , +}; + +enum ipa_rsrc_grp_type_dst { +IPA_RSRC_GRP_TYPE_DST_DATA_SECTORS , +IPA_RSRC_GRP_TYPE_DST_DPS_DMARS , +}; + +enum ipa_rsrc_grp_type_rx { +IPA_RSRC_GRP_TYPE_RX_HPS_CMDQ , +IPA_RSRC_GRP_TYPE_RX_MAX +}; + +struct rsrc_min_max { +u32 min; +u32 max; +}; + +/* IPA_HW_v3_5_1 */ +static const struct rsrc_min_max ipa_src_rsrc_grp[][IPA_RSRC_GROUP_MAX ] = { + [IPA_RSRC_GRP_TYPE_SRC_PKT_CONTEXTS ] = { + [IPA_RSRC_GROUP_LWA_DL ] = { .min =1 , .max =63 , }, + [IPA_RSRC_GROUP_UL_DL ] = { .min =1 , .max =63 , }, + }, + [IPA_RSRC_GRP_TYPE_SRS_DESCRIPTOR_LISTS ] = { + [IPA_RSRC_GROUP_LWA_DL ] = { .min =10 , .max =10 , }, + [IPA_RSRC_GROUP_UL_DL ] = { .min =10 , .max =10 , }, + }, + [IPA_RSRC_GRP_TYPE_SRC_DESCRIPTOR_BUFF ] = { + [IPA_RSRC_GROUP_LWA_DL ] = { .min =12 , .max =12 , }, + [IPA_RSRC_GROUP_UL_DL ] = { .min =14 , .max =14 , }, + }, + [IPA_RSRC_GRP_TYPE_SRC_HPS_DMARS ] = { + [IPA_RSRC_GROUP_LWA_DL ] = { .min =0 , .max =63 , }, + [IPA_RSRC_GROUP_UL_DL ] = { .min =0 , .max =63 , }, + }, + [IPA_RSRC_GRP_TYPE_SRC_ACK_ENTRIES ] = { + [IPA_RSRC_GROUP_LWA_DL ] = { .min =14 , .max =14 , }, + [IPA_RSRC_GROUP_UL_DL ] = { .min =20 , .max =20 , }, + }, +}; + +/* IPA_HW_v3_5_1 */ +static const struct rsrc_min_max ipa_dst_rsrc_grp[][IPA_RSRC_GROUP_MAX ] = { + [IPA_RSRC_GRP_TYPE_DST_DATA_SECTORS ] = { + [IPA_RSRC_GROUP_LWA_DL ] = { .min =4 , .max =4 , }, + [IPA_RSRC_GROUP_UL_DL ] = { .min =4 , .max =4 , }, + }, + [IPA_RSRC_GRP_TYPE_DST_DPS_DMARS ] = { + [IPA_RSRC_GROUP_LWA_DL ] = { .min =2 , .max =63 , }, + [IPA_RSRC_GROUP_UL_DL ] = { .min =1 , .max =63 , }, + }, +}; + +/** +* struct ipa_gsi_ep_config - GSI endpoint configuration. +* @ep_id: IPA endpoint identifier. +* @channel_id: GSI channel number used for this endpoint. +* @tlv_count: The number of TLV (type-length-value) entries for the channel. +* @ee: Execution environment endpoint is associated with. +* +* Each GSI endpoint has a set of configuration parameters defined within +* entries in the ipa_ep_configuration[] array. Its @ep_id field uniquely +* defines the endpoint, and @channel_id defines which data channel (ring +* buffer) is used for the endpoint. +* XXX TLV +* XXX ee is never used in the code +*/ +struct ipa_gsi_ep_config { +u32 ep_id; +u32 channel_id; +u32 tlv_count; +u32 ee; +}; + +struct ipa_ep_configuration { +bool support_flt; +enum ipa_seq_type seq_type; +struct ipa_gsi_ep_config ipa_gsi_ep_info; +}; + +/* IPA_HW_v3_5_1 */ +/* clients not included in the list below are considered as invalid */ +static const struct ipa_ep_configuration ipa_ep_configuration[] = { + [IPA_CLIENT_WLAN1_PROD ] = { + .support_flt = true, + .seq_type =IPA_SEQ_2ND_PKT_PROCESS_PASS_NO_DEC_UCP , + .ipa_gsi_ep_info = { + .ep_id =7 , + .channel_id =1 , + .tlv_count =8 , + .ee =IPA_EE_UC , + }, + }, + [IPA_CLIENT_USB_PROD ] = { + .support_flt = true, + .seq_type =IPA_SEQ_2ND_PKT_PROCESS_PASS_NO_DEC_UCP , + .ipa_gsi_ep_info = { + .ep_id =0 , + .channel_id =0 , + .tlv_count =8 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_APPS_LAN_PROD ] = { + .support_flt = false, + .seq_type =IPA_SEQ_PKT_PROCESS_NO_DEC_UCP , + .ipa_gsi_ep_info = { + .ep_id =8 , + .channel_id =7 , + .tlv_count =8 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_APPS_WAN_PROD ] = { + .support_flt = true, + .seq_type =IPA_SEQ_2ND_PKT_PROCESS_PASS_NO_DEC_UCP , + .ipa_gsi_ep_info = { + .ep_id =2 , + .channel_id =3 , + .tlv_count =16 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_APPS_CMD_PROD ] = { + .support_flt = false, + .seq_type =IPA_SEQ_DMA_ONLY , + .ipa_gsi_ep_info = { + .ep_id =5 , + .channel_id =4 , + .tlv_count =20 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_Q6_LAN_PROD ] = { + .support_flt = true, + .seq_type =IPA_SEQ_PKT_PROCESS_NO_DEC_UCP , + .ipa_gsi_ep_info = { + .ep_id =3 , + .channel_id =0 , + .tlv_count =16 , + .ee =IPA_EE_Q6 , + }, + }, + [IPA_CLIENT_Q6_WAN_PROD ] = { + .support_flt = true, + .seq_type =IPA_SEQ_PKT_PROCESS_NO_DEC_UCP , + .ipa_gsi_ep_info = { + .ep_id =6 , + .channel_id =4 , + .tlv_count =12 , + .ee =IPA_EE_Q6 , + }, + }, + [IPA_CLIENT_Q6_CMD_PROD ] = { + .support_flt = false, + .seq_type =IPA_SEQ_PKT_PROCESS_NO_DEC_UCP , + .ipa_gsi_ep_info = { + .ep_id =4 , + .channel_id =1 , + .tlv_count =20 , + .ee =IPA_EE_Q6 , + }, + }, + [IPA_CLIENT_TEST_CONS ] = { + .support_flt = true, + .seq_type =IPA_SEQ_2ND_PKT_PROCESS_PASS_NO_DEC_UCP , + .ipa_gsi_ep_info = { + .ep_id =14 , + .channel_id =5 , + .tlv_count =8 , + .ee =IPA_EE_Q6 , + }, + }, + [IPA_CLIENT_TEST1_CONS ] = { + .support_flt = true, + .seq_type =IPA_SEQ_2ND_PKT_PROCESS_PASS_NO_DEC_UCP , + .ipa_gsi_ep_info = { + .ep_id =15 , + .channel_id =2 , + .tlv_count =8 , + .ee =IPA_EE_UC , + }, + }, +/* Only for testing */ + [IPA_CLIENT_TEST_PROD ] = { + .support_flt = true, + .seq_type =IPA_SEQ_2ND_PKT_PROCESS_PASS_NO_DEC_UCP , + .ipa_gsi_ep_info = { + .ep_id =0 , + .channel_id =0 , + .tlv_count =8 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_TEST1_PROD ] = { + .support_flt = true, + .seq_type =IPA_SEQ_2ND_PKT_PROCESS_PASS_NO_DEC_UCP , + .ipa_gsi_ep_info = { + .ep_id =0 , + .channel_id =0 , + .tlv_count =8 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_TEST2_PROD ] = { + .support_flt = true, + .seq_type =IPA_SEQ_2ND_PKT_PROCESS_PASS_NO_DEC_UCP , + .ipa_gsi_ep_info = { + .ep_id =2 , + .channel_id =3 , + .tlv_count =16 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_TEST3_PROD ] = { + .support_flt = true, + .seq_type =IPA_SEQ_2ND_PKT_PROCESS_PASS_NO_DEC_UCP , + .ipa_gsi_ep_info = { + .ep_id =4 , + .channel_id =1 , + .tlv_count =20 , + .ee =IPA_EE_Q6 , + }, + }, + [IPA_CLIENT_TEST4_PROD ] = { + .support_flt = true, + .seq_type =IPA_SEQ_2ND_PKT_PROCESS_PASS_NO_DEC_UCP , + .ipa_gsi_ep_info = { + .ep_id =1 , + .channel_id =0 , + .tlv_count =8 , + .ee =IPA_EE_UC , + }, + }, + [IPA_CLIENT_WLAN1_CONS ] = { + .support_flt = false, + .seq_type =IPA_SEQ_INVALID , + .ipa_gsi_ep_info = { + .ep_id =16 , + .channel_id =3 , + .tlv_count =8 , + .ee =IPA_EE_UC , + }, + }, + [IPA_CLIENT_WLAN2_CONS ] = { + .support_flt = false, + .seq_type =IPA_SEQ_INVALID , + .ipa_gsi_ep_info = { + .ep_id =18 , + .channel_id =9 , + .tlv_count =8 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_WLAN3_CONS ] = { + .support_flt = false, + .seq_type =IPA_SEQ_INVALID , + .ipa_gsi_ep_info = { + .ep_id =19 , + .channel_id =10 , + .tlv_count =8 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_USB_CONS ] = { + .support_flt = false, + .seq_type =IPA_SEQ_INVALID , + .ipa_gsi_ep_info = { + .ep_id =17 , + .channel_id =8 , + .tlv_count =8 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_USB_DPL_CONS ] = { + .support_flt = false, + .seq_type =IPA_SEQ_INVALID , + .ipa_gsi_ep_info = { + .ep_id =11 , + .channel_id =2 , + .tlv_count =4 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_APPS_LAN_CONS ] = { + .support_flt = false, + .seq_type =IPA_SEQ_INVALID , + .ipa_gsi_ep_info = { + .ep_id =9 , + .channel_id =5 , + .tlv_count =8 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_APPS_WAN_CONS ] = { + .support_flt = false, + .seq_type =IPA_SEQ_INVALID , + .ipa_gsi_ep_info = { + .ep_id =10 , + .channel_id =6 , + .tlv_count =8 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_Q6_LAN_CONS ] = { + .support_flt = false, + .seq_type =IPA_SEQ_INVALID , + .ipa_gsi_ep_info = { + .ep_id =13 , + .channel_id =3 , + .tlv_count =8 , + .ee =IPA_EE_Q6 , + }, + }, + [IPA_CLIENT_Q6_WAN_CONS ] = { + .support_flt = false, + .seq_type =IPA_SEQ_INVALID , + .ipa_gsi_ep_info = { + .ep_id =12 , + .channel_id =2 , + .tlv_count =8 , + .ee =IPA_EE_Q6 , + }, + }, +/* Only for testing */ + [IPA_CLIENT_TEST2_CONS ] = { + .support_flt = false, + .seq_type =IPA_SEQ_INVALID , + .ipa_gsi_ep_info = { + .ep_id =18 , + .channel_id =9 , + .tlv_count =8 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_TEST3_CONS ] = { + .support_flt = false, + .seq_type =IPA_SEQ_INVALID , + .ipa_gsi_ep_info = { + .ep_id =19 , + .channel_id =10 , + .tlv_count =8 , + .ee =IPA_EE_AP , + }, + }, + [IPA_CLIENT_TEST4_CONS ] = { + .support_flt = false, + .seq_type =IPA_SEQ_INVALID , + .ipa_gsi_ep_info = { + .ep_id =11 , + .channel_id =2 , + .tlv_count =4 , + .ee =IPA_EE_AP , + }, + }, +/* Dummy consumer (endpoint 31) is used in L2TP rt rule */ + [IPA_CLIENT_DUMMY_CONS ] = { + .support_flt = false, + .seq_type =IPA_SEQ_INVALID , + .ipa_gsi_ep_info = { + .ep_id =31 , + .channel_id =31 , + .tlv_count =8 , + .ee =IPA_EE_AP , + }, + }, +}; + +/** ipa_client_ep_id() - provide endpoint mapping +* @client: client type +* +* Return value: endpoint mapping +*/ +u32 ipa_client_ep_id (enum ipa_client_type client) +{ +return ipa_ep_configuration[client].ipa_gsi_ep_info.ep_id; +} + +u32 ipa_client_channel_id (enum ipa_client_type client) +{ +return ipa_ep_configuration[client].ipa_gsi_ep_info.channel_id; +} + +u32 ipa_client_tlv_count (enum ipa_client_type client) +{ +return ipa_ep_configuration[client].ipa_gsi_ep_info.tlv_count; +} + +enum ipa_seq_type ipa_endp_seq_type (u32 ep_id) +{ +return ipa_ep_configuration[ipa_ctx->ep[ep_id].client].seq_type; +} + +/** ipa_sram_settings_read() - Read SRAM settings from HW +* +* Returns: None +*/ +void ipa_sram_settings_read (void ) +{ +struct ipa_reg_shared_mem_size mem_size; + +ipa_read_reg_fields (IPA_SHARED_MEM_SIZE , &mem_size); + +/* reg fields are in 8B units */ + ipa_ctx->smem_offset = mem_size.shared_mem_baddr *8 ; + ipa_ctx->smem_size = mem_size.shared_mem_size *8 ; + +ipa_debug ("sram size 0x%x offset 0x%x\n" , ipa_ctx->smem_size, + ipa_ctx->smem_offset); +} + +/** ipa_init_hw() - initialize HW */ +void ipa_init_hw (void ) +{ +struct ipa_reg_qsb_max_writes max_writes; +struct ipa_reg_qsb_max_reads max_reads; + +/* SDM845 has IPA version 3.5.1 */ +ipa_write_reg (IPA_BCR ,IPA_BCR_REG_VAL ); + +ipa_reg_qsb_max_writes (&max_writes,8 ,4 ); +ipa_write_reg_fields (IPA_QSB_MAX_WRITES , &max_writes); + +ipa_reg_qsb_max_reads (&max_reads,8 ,12 ); +ipa_write_reg_fields (IPA_QSB_MAX_READS , &max_reads); +} + +/** ipa_filter_bitmap_init() - Initialize the bitmap +* that represents the End-points that supports filtering +*/ +u32 ipa_filter_bitmap_init (void ) +{ +enum ipa_client_type client; +u32 filter_bitmap =0 ; +u32 count =0 ; + +for (client =0 ; client <IPA_CLIENT_MAX ; client++) { +const struct ipa_ep_configuration *ep_config; + + ep_config = &ipa_ep_configuration[client]; +if (!ep_config->support_flt) +continue ; +if (++count >IPA_MEM_FLT_COUNT ) +return 0 ;/* Too many filtering endpoints */ + + filter_bitmap |=BIT (ep_config->ipa_gsi_ep_info.ep_id); + } + +return filter_bitmap; +} + +/* In IPAv3 only endpoints 0-3 can be configured to deaggregation */ +bool ipa_endp_aggr_support (u32 ep_id) +{ +return ep_id <4 ; +} + +/** ipa_endp_init_hdr_write() +* +* @ep_id: endpoint whose header config register should be written +*/ +static void ipa_endp_init_hdr_write (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_write_reg_n_fields (IPA_ENDP_INIT_HDR_N , ep_id, &ep->init_hdr); +} + +/** ipa_endp_init_hdr_ext_write() - write endpoint extended header register +* +* @ep_id: endpoint whose register should be written +*/ +static void +ipa_endp_init_hdr_ext_write (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_write_reg_n_fields (IPA_ENDP_INIT_HDR_EXT_N , ep_id, + &ep->hdr_ext); +} + +/** ipa_endp_init_aggr_write() write endpoint aggregation register +* +* @ep_id: endpoint whose aggregation config register should be written +*/ +static void ipa_endp_init_aggr_write (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_write_reg_n_fields (IPA_ENDP_INIT_AGGR_N , ep_id, &ep->init_aggr); +} + +/** ipa_endp_init_cfg_write() - write endpoint configuration register +* +* @ep_id: endpoint whose configuration register should be written +*/ +static void ipa_endp_init_cfg_write (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_write_reg_n_fields (IPA_ENDP_INIT_CFG_N , ep_id, &ep->init_cfg); +} + +/** ipa_endp_init_mode_write() - write endpoint mode register +* +* @ep_id: endpoint whose register should be written +*/ +static void ipa_endp_init_mode_write (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_write_reg_n_fields (IPA_ENDP_INIT_MODE_N , ep_id, + &ep->init_mode); +} + +/** ipa_endp_init_seq_write() - write endpoint sequencer register +* +* @ep_id: endpoint whose register should be written +*/ +static void ipa_endp_init_seq_write (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_write_reg_n_fields (IPA_ENDP_INIT_SEQ_N , ep_id, &ep->init_seq); +} + +/** ipa_endp_init_deaggr_write() - write endpoint deaggregation register +* +* @ep_id: endpoint whose register should be written +*/ +void ipa_endp_init_deaggr_write (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_write_reg_n_fields (IPA_ENDP_INIT_DEAGGR_N , ep_id, + &ep->init_deaggr); +} + +/** ipa_endp_init_hdr_metadata_mask_write() - endpoint metadata mask register +* +* @ep_id: endpoint whose register should be written +*/ +static void ipa_endp_init_hdr_metadata_mask_write (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_write_reg_n_fields (IPA_ENDP_INIT_HDR_METADATA_MASK_N , ep_id, + &ep->metadata_mask); +} + +/** ipa_endp_init_hdr_metadata_mask_write() - endpoint metadata mask register +* +* @ep_id: endpoint whose register should be written +*/ +static void ipa_endp_status_write (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_write_reg_n_fields (IPA_ENDP_STATUS_N , ep_id, &ep->status); +} + +/** ipa_cfg_ep - IPA end-point configuration +* @ep_id: [in] endpoint id assigned by IPA to client +* @dst: [in] destination client handle (ignored for consumer clients) +* +* This includes nat, IPv6CT, header, mode, aggregation and route settings and +* is a one shot API to configure the IPA end-point fully +* +* Returns: 0 on success, negative on failure +* +* Note: Should not be called from atomic context +*/ +void ipa_cfg_ep (u32 ep_id) +{ +ipa_endp_init_hdr_write (ep_id); +ipa_endp_init_hdr_ext_write (ep_id); + +ipa_endp_init_aggr_write (ep_id); +ipa_endp_init_cfg_write (ep_id); + +if (ipa_producer (ipa_ctx->ep[ep_id].client)) { +ipa_endp_init_mode_write (ep_id); +ipa_endp_init_seq_write (ep_id); +ipa_endp_init_deaggr_write (ep_id); + }else { +ipa_endp_init_hdr_metadata_mask_write (ep_id); + } + +ipa_endp_status_write (ep_id); +} + +int ipa_interconnect_init (struct device *dev) +{ +struct icc_path *path; + + path =of_icc_get (dev,"memory" ); +if (IS_ERR (path)) + goto err_return; + ipa_ctx->memory_path = path; + + path =of_icc_get (dev,"imem" ); +if (IS_ERR (path)) + goto err_memory_path_put; + ipa_ctx->imem_path = path; + + path =of_icc_get (dev,"config" ); +if (IS_ERR (path)) + goto err_imem_path_put; + ipa_ctx->config_path = path; + +return 0 ; + +err_imem_path_put: +icc_put (ipa_ctx->imem_path); + ipa_ctx->imem_path =NULL ; +err_memory_path_put: +icc_put (ipa_ctx->memory_path); + ipa_ctx->memory_path =NULL ; +err_return: + +return PTR_ERR (path); +} + +void ipa_interconnect_exit (void ) +{ +icc_put (ipa_ctx->config_path); + ipa_ctx->config_path =NULL ; + +icc_put (ipa_ctx->imem_path); + ipa_ctx->imem_path =NULL ; + +icc_put (ipa_ctx->memory_path); + ipa_ctx->memory_path =NULL ; +} + +/* Currently we only use bandwidth level, so just "enable" interconnects */ +int ipa_interconnect_enable (void ) +{ +int ret; + + ret =icc_set (ipa_ctx->memory_path,IPA_MEMORY_AVG ,IPA_MEMORY_PEAK ); +if (ret) +return ret; + + ret =icc_set (ipa_ctx->imem_path,IPA_IMEM_AVG ,IPA_IMEM_PEAK ); +if (ret) + goto err_disable_memory_path; + + ret =icc_set (ipa_ctx->config_path,IPA_CONFIG_AVG ,IPA_CONFIG_PEAK ); +if (!ret) +return 0 ;/* Success */ + + (void )icc_set (ipa_ctx->imem_path,0 ,0 ); +err_disable_memory_path: + (void )icc_set (ipa_ctx->memory_path,0 ,0 ); + +return ret; +} + +/* To disable an interconnect, we just its bandwidth to 0 */ +int ipa_interconnect_disable (void ) +{ +int ret; + + ret =icc_set (ipa_ctx->memory_path,0 ,0 ); +if (ret) +return ret; + + ret =icc_set (ipa_ctx->imem_path,0 ,0 ); +if (ret) + goto err_reenable_memory_path; + + ret =icc_set (ipa_ctx->config_path,0 ,0 ); +if (!ret) +return 0 ;/* Success */ + +/* Re-enable things in the event of an error */ + (void )icc_set (ipa_ctx->imem_path,IPA_IMEM_AVG ,IPA_IMEM_PEAK ); +err_reenable_memory_path: + (void )icc_set (ipa_ctx->memory_path,IPA_MEMORY_AVG ,IPA_MEMORY_PEAK ); + +return ret; +} + +/** ipa_proxy_clk_unvote() - called to remove IPA clock proxy vote +* +* Return value: none +*/ +void ipa_proxy_clk_unvote (void ) +{ +if (ipa_ctx->modem_clk_vote_valid) { +ipa_client_remove (); + ipa_ctx->modem_clk_vote_valid = false; + } +} + +/** ipa_proxy_clk_vote() - called to add IPA clock proxy vote +* +* Return value: none +*/ +void ipa_proxy_clk_vote (void ) +{ +if (!ipa_ctx->modem_clk_vote_valid) { +ipa_client_add (); + ipa_ctx->modem_clk_vote_valid = true; + } +} + +u32 ipa_get_ep_count (void ) +{ +return ipa_read_reg (IPA_ENABLED_PIPES ); +} + +/** ipa_is_modem_ep()- Checks if endpoint is owned by the modem +* +* @ep_id: endpoint identifier +* Return value: true if owned by modem, false otherwize +*/ +bool ipa_is_modem_ep (u32 ep_id) +{ +int client_idx; + +for (client_idx =0 ; client_idx <IPA_CLIENT_MAX ; client_idx++) { +if (!ipa_modem_consumer (client_idx) && + !ipa_modem_producer (client_idx)) +continue ; +if (ipa_client_ep_id (client_idx) == ep_id) +return true; + } + +return false; +} + +static void ipa_src_rsrc_grp_init (enum ipa_rsrc_grp_type_src n) +{ +struct ipa_reg_rsrc_grp_xy_rsrc_type_n limits; +const struct rsrc_min_max *x_limits; +const struct rsrc_min_max *y_limits; + + x_limits = &ipa_src_rsrc_grp[n][IPA_RSRC_GROUP_LWA_DL ]; + y_limits = &ipa_src_rsrc_grp[n][IPA_RSRC_GROUP_UL_DL ]; +ipa_reg_rsrc_grp_xy_rsrc_type_n (&limits, x_limits->min, x_limits->max, + y_limits->min, y_limits->max); + +ipa_write_reg_n_fields (IPA_SRC_RSRC_GRP_01_RSRC_TYPE_N , n, &limits); +} + +static void ipa_dst_rsrc_grp_init (enum ipa_rsrc_grp_type_dst n) +{ +struct ipa_reg_rsrc_grp_xy_rsrc_type_n limits; +const struct rsrc_min_max *x_limits; +const struct rsrc_min_max *y_limits; + + x_limits = &ipa_dst_rsrc_grp[n][IPA_RSRC_GROUP_LWA_DL ]; + y_limits = &ipa_dst_rsrc_grp[n][IPA_RSRC_GROUP_UL_DL ]; +ipa_reg_rsrc_grp_xy_rsrc_type_n (&limits, x_limits->min, x_limits->max, + y_limits->min, y_limits->max); + +ipa_write_reg_n_fields (IPA_DST_RSRC_GRP_01_RSRC_TYPE_N , n, &limits); +} + +void ipa_set_resource_groups_min_max_limits (void ) +{ +ipa_src_rsrc_grp_init (IPA_RSRC_GRP_TYPE_SRC_PKT_CONTEXTS ); +ipa_src_rsrc_grp_init (IPA_RSRC_GRP_TYPE_SRS_DESCRIPTOR_LISTS ); +ipa_src_rsrc_grp_init (IPA_RSRC_GRP_TYPE_SRC_DESCRIPTOR_BUFF ); +ipa_src_rsrc_grp_init (IPA_RSRC_GRP_TYPE_SRC_HPS_DMARS ); +ipa_src_rsrc_grp_init (IPA_RSRC_GRP_TYPE_SRC_ACK_ENTRIES ); + +ipa_dst_rsrc_grp_init (IPA_RSRC_GRP_TYPE_DST_DATA_SECTORS ); +ipa_dst_rsrc_grp_init (IPA_RSRC_GRP_TYPE_DST_DPS_DMARS ); +} + +static void ipa_gsi_poll_after_suspend (struct ipa_ep_context *ep) +{ +ipa_rx_switch_to_poll_mode (ep->sys); +} + +/* Suspend a consumer endpoint */ +static void ipa_ep_cons_suspend (enum ipa_client_type client) +{ +struct ipa_reg_endp_init_ctrl init_ctrl; +u32 ep_id =ipa_client_ep_id (client); + +ipa_reg_endp_init_ctrl (&init_ctrl, true); +ipa_write_reg_n_fields (IPA_ENDP_INIT_CTRL_N , ep_id, &init_ctrl); + +/* Due to a hardware bug, a client suspended with an open +* aggregation frame will not generate a SUSPEND IPA interrupt. +* We work around this by force-closing the aggregation frame, +* then simulating the arrival of such an interrupt. +*/ +ipa_suspend_active_aggr_wa (ep_id); + +ipa_gsi_poll_after_suspend (&ipa_ctx->ep[ep_id]); +} + +void ipa_ep_suspend_all (void ) +{ +ipa_ep_cons_suspend (IPA_CLIENT_APPS_WAN_CONS ); +ipa_ep_cons_suspend (IPA_CLIENT_APPS_LAN_CONS ); +} + +/* Resume a suspended consumer endpoint */ +static void ipa_ep_cons_resume (enum ipa_client_type client) +{ +struct ipa_reg_endp_init_ctrl init_ctrl; +struct ipa_ep_context *ep; +u32 ep_id; + + ep_id =ipa_client_ep_id (client); + ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_ctrl (&init_ctrl, false); +ipa_write_reg_n_fields (IPA_ENDP_INIT_CTRL_N , ep_id, &init_ctrl); + +if (!ipa_ep_polling (ep)) +gsi_channel_intr_enable (ipa_ctx->gsi, ep->channel_id); +} + +void ipa_ep_resume_all (void ) +{ +ipa_ep_cons_resume (IPA_CLIENT_APPS_LAN_CONS ); +ipa_ep_cons_resume (IPA_CLIENT_APPS_WAN_CONS ); +} + +/** ipa_cfg_route() - configure IPA route +* @route: IPA route +* +* Return codes: +* 0: success +*/ +void ipa_cfg_default_route (enum ipa_client_type client) +{ +struct ipa_reg_route route; + +ipa_reg_route (&route,ipa_client_ep_id (client)); +ipa_write_reg_fields (IPA_ROUTE , &route); +} + +/* In certain cases we need to issue a command to reliably clear the +* IPA pipeline. Sending a 1-byte DMA task is sufficient, and this +* function preallocates a command to do just that. There are +* conditions (process context in KILL state) where DMA allocations +* can fail, and we need to be able to issue this command to put the +* hardware in a known state. By preallocating the command here we +* guarantee it can't fail for that reason. +*/ +int ipa_gsi_dma_task_alloc (void ) +{ +struct ipa_dma_mem *mem = &ipa_ctx->dma_task_info.mem; + +if (ipa_dma_alloc (mem,IPA_GSI_CHANNEL_STOP_PKT_SIZE ,GFP_KERNEL )) +return -ENOMEM ; + +/* IPA_IMM_CMD_DMA_TASK_32B_ADDR */ + ipa_ctx->dma_task_info.payload =ipahal_dma_task_32b_addr_pyld (mem); +if (!ipa_ctx->dma_task_info.payload) { +ipa_dma_free (mem); + +return -ENOMEM ; + } + +return 0 ; +} + +void ipa_gsi_dma_task_free (void ) +{ +struct ipa_dma_mem *mem = &ipa_ctx->dma_task_info.mem; + +ipahal_payload_free (ipa_ctx->dma_task_info.payload); + ipa_ctx->dma_task_info.payload =NULL ; +ipa_dma_free (mem); +} + +/** ipa_gsi_dma_task_inject()- Send DMA_TASK to IPA for GSI stop channel +* +* Send a DMA_TASK of 1B to IPA to unblock GSI channel in STOP_IN_PROG. +* Return value: 0 on success, negative otherwise +*/ +static int ipa_gsi_dma_task_inject (void ) +{ +struct ipa_desc desc = { }; + + desc.type =IPA_IMM_CMD_DESC ; + desc.len_opcode =IPA_IMM_CMD_DMA_TASK_32B_ADDR ; + desc.payload = ipa_ctx->dma_task_info.payload; + +return ipa_send_cmd_timeout (&desc,IPA_GSI_DMA_TASK_TIMEOUT ); +} + +/** ipa_stop_gsi_channel()- Stops a GSI channel in IPA +* @chan_hdl: GSI channel handle +* +* This function implements the sequence to stop a GSI channel +* in IPA. This function returns when the channel is is STOP state. +* +* Return value: 0 on success, negative otherwise +*/ +int ipa_stop_gsi_channel (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; +int ret; +int i; + +if (ipa_producer (ep->client)) +return gsi_channel_stop (ipa_ctx->gsi, ep->channel_id); + +for (i =0 ; i <IPA_GSI_CHANNEL_STOP_MAX_RETRY ; i++) { + ret =gsi_channel_stop (ipa_ctx->gsi, ep->channel_id); +if (ret != -EAGAIN && ret != -ETIMEDOUT ) +return ret; + +/* Send a 1B packet DMA_TASK to IPA and try again */ + ret =ipa_gsi_dma_task_inject (); +if (ret) +return ret; + +/* sleep for short period to flush IPA */ +usleep_range (IPA_GSI_CHANNEL_STOP_SLEEP_MIN , +IPA_GSI_CHANNEL_STOP_SLEEP_MAX ); + } + +ipa_err ("Failed to stop GSI channel with retries\n" ); + +return -EFAULT ; +} + +/** ipa_enable_dcd() - enable dynamic clock division on IPA +* +* Return value: Non applicable +* +*/ +void ipa_enable_dcd (void ) +{ +struct ipa_reg_idle_indication_cfg indication; + +/* recommended values for IPA 3.5 according to IPA HPG */ +ipa_reg_idle_indication_cfg (&indication,256 ,0 ); +ipa_write_reg_fields (IPA_IDLE_INDICATION_CFG , &indication); +} + +/** ipa_set_flt_tuple_mask() - Sets the flt tuple masking for the given +* endpoint. Endpoint must be for AP (not modem) and support filtering. +* Updates the the filtering masking values without changing the rt ones. +* +* @ep_id: filter endpoint to configure the tuple masking +* @tuple: the tuple members masking +* Returns: 0 on success, negative on failure +* +*/ +void ipa_set_flt_tuple_mask (u32 ep_id) +{ +struct ipa_ep_filter_router_hsh_cfg hsh_cfg; + +ipa_read_reg_n_fields (IPA_ENDP_FILTER_ROUTER_HSH_CFG_N , ep_id, + &hsh_cfg); + +ipa_reg_hash_tuple (&hsh_cfg.flt); + +ipa_write_reg_n_fields (IPA_ENDP_FILTER_ROUTER_HSH_CFG_N , ep_id, + &hsh_cfg); +} + +/** ipa_set_rt_tuple_mask() - Sets the rt tuple masking for the given tbl +* table index must be for AP EP (not modem) +* updates the the routing masking values without changing the flt ones. +* +* @tbl_idx: routing table index to configure the tuple masking +* @tuple: the tuple members masking +* Returns: 0 on success, negative on failure +* +*/ +void ipa_set_rt_tuple_mask (int tbl_idx) +{ +struct ipa_ep_filter_router_hsh_cfg hsh_cfg; + +ipa_read_reg_n_fields (IPA_ENDP_FILTER_ROUTER_HSH_CFG_N , tbl_idx, + &hsh_cfg); + +ipa_reg_hash_tuple (&hsh_cfg.rt); + +ipa_write_reg_n_fields (IPA_ENDP_FILTER_ROUTER_HSH_CFG_N , tbl_idx, + &hsh_cfg); +} + +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("IPA HW device driver" );
Signature · 1 line
2.17.1
RFC PATCH 9/12 soc: qcom: ipa: main IPA source file
In reply to Alex ElderThis patch includes "ipa_main.c", which consists mostly of the initialization code.
The IPA is a hardware resource shared by multiple independent execution environments (currently, the AP and the modem). In some cases, initialization must be performed by only one of these. As an example, the AP must initialize some filter table data structures that are only used by the modem. (And in general, some initialization of IPA hardware is required regardless of whether it will be used.)
There are two phases of IPA initialization. The first phase is triggered by the probe of the driver. It involves setting up operating system resources, and doing some basic initialization of IPA memory resources using register and DMA access.
The second phase involves configuration of enpoints used, and this phase requires access to the GSI layer. However the GSI layer is requires some firmware to be loaded before it can be used. So the second stage (in ipa_post_init()) only occurs after it is known firmware is loaded.
The GSI firmware can be loaded in two ways: the modem can load it; or Trust Zone code running on the AP can load it. If the modem loads the firmware, it will send an SMP2P interrupt to the AP to signal that GSI firmware is loaded and the AP can proceed with its second stage IPA initialization. If Trust Zone is responsible for loading the firmware, the IPA driver requests the firmware blob from the file system and passes the result via an SMC to Trust Zone to load and activate the GSI firmware. When that has completed successfully, the second stage of initialization can proceed.
--- drivers/net/ipa/ipa_main.c | 1400 ++++++++++++++++++++++++++++++++++++ 1 file changed, 1400 insertions(+) create mode 100644 drivers/net/ipa/ipa_main.c
drivers/net/ipa/ipa_main.c new file +1400 -0
@@ -0,0 +1,1400 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd. +*/ + +#include <linux/types.h> +#include <linux/atomic.h> +#include <linux/spinlock.h> +#include <linux/mutex.h> +#include <linux/device.h> +#include <linux/firmware.h> +#include <linux/workqueue.h> +#include <linux/bug.h> +#include <linux/io.h> +#include <linux/clk.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> +#include <linux/of_platform.h> +#include <linux/interrupt.h> +#include <linux/notifier.h> +#include <linux/remoteproc.h> +#include <linux/pm_wakeup.h> +#include <linux/kconfig.h> +#include <linux/qcom_scm.h> +#include <linux/soc/qcom/mdt_loader.h> +#include <linux/soc/qcom/smem.h> +#include <linux/soc/qcom/smem_state.h> +#include <linux/module.h> + +#include "ipa_i.h" +#include "ipa_dma.h" +#include "ipahal.h" + +#define IPA_CORE_CLOCK_RATE (75UL * 1000 * 1000) + +/* The name of the main firmware file relative to /lib/firmware */ +#define IPA_FWS_PATH "ipa_fws.mdt" +#define IPA_PAS_ID 15 + +#define IPA_APPS_CMD_PROD_RING_COUNT 256 +#define IPA_APPS_LAN_CONS_RING_COUNT 256 + +/* Details of the initialization sequence are determined by who is +* responsible for doing some early IPA hardware initialization. +* The Device Tree compatible string defines what to expect. +*/ +enum ipa_init_type { + ipa_undefined_init =0 , + ipa_tz_init, + ipa_modem_init, +}; + +struct ipa_match_data { +enum ipa_init_type init_type; +}; + +static void ipa_client_remove_deferred (struct work_struct *work); +static DECLARE_WORK(ipa_client_remove_work, ipa_client_remove_deferred); + +static struct ipa_context ipa_ctx_struct; +struct ipa_context *ipa_ctx = &ipa_ctx_struct; + +static int hdr_init_local_cmd (u32 offset,u32 size) +{ +struct ipa_desc desc = { }; +struct ipa_dma_mem mem; +void *payload; +int ret; + +if (ipa_dma_alloc (&mem, size,GFP_KERNEL )) +return -ENOMEM ; + + offset += ipa_ctx->smem_offset; + + payload =ipahal_hdr_init_local_pyld (&mem, offset); +if (!payload) { + ret = -ENOMEM ; + goto err_dma_free; + } + + desc.type =IPA_IMM_CMD_DESC ; + desc.len_opcode =IPA_IMM_CMD_HDR_INIT_LOCAL ; + desc.payload = payload; + + ret =ipa_send_cmd (&desc); + +ipahal_payload_free (payload); +err_dma_free: +ipa_dma_free (&mem); + +return ret; +} + +static int dma_shared_mem_zero_cmd (u32 offset,u32 size) +{ +struct ipa_desc desc = { }; +struct ipa_dma_mem mem; +void *payload; +int ret; + +ipa_assert (size >0 ); + +if (ipa_dma_alloc (&mem, size,GFP_KERNEL )) +return -ENOMEM ; + + offset += ipa_ctx->smem_offset; + + payload =ipahal_dma_shared_mem_write_pyld (&mem, offset); +if (!payload) { + ret = -ENOMEM ; + goto err_dma_free; + } + + desc.type =IPA_IMM_CMD_DESC ; + desc.len_opcode =IPA_IMM_CMD_DMA_SHARED_MEM ; + desc.payload = payload; + + ret =ipa_send_cmd (&desc); + +ipahal_payload_free (payload); +err_dma_free: +ipa_dma_free (&mem); + +return ret; +} + +/** +* ipa_modem_smem_init() - Initialize modem general memory and header memory +*/ +int ipa_modem_smem_init (void ) +{ +int ret; + + ret =dma_shared_mem_zero_cmd (IPA_MEM_MODEM_OFST ,IPA_MEM_MODEM_SIZE ); +if (ret) +return ret; + + ret =dma_shared_mem_zero_cmd (IPA_MEM_MODEM_HDR_OFST , +IPA_MEM_MODEM_HDR_SIZE ); +if (ret) +return ret; + +return dma_shared_mem_zero_cmd (IPA_MEM_MODEM_HDR_PROC_CTX_OFST , +IPA_MEM_MODEM_HDR_PROC_CTX_SIZE ); +} + +static int ipa_ep_apps_cmd_prod_setup (void ) +{ +enum ipa_client_type dst_client; +enum ipa_client_type client; +u32 channel_count; +u32 ep_id; +int ret; + +if (ipa_ctx->cmd_prod_ep_id !=IPA_EP_ID_BAD ) + ret = -EBUSY ; + + client =IPA_CLIENT_APPS_CMD_PROD ; + dst_client =IPA_CLIENT_APPS_LAN_CONS ; + channel_count =IPA_APPS_CMD_PROD_RING_COUNT ; + + ret =ipa_ep_alloc (client); +if (ret <0 ) +return ret; + ep_id = ret; + + +ipa_endp_init_mode_prod (ep_id,IPA_DMA , dst_client); +ipa_endp_init_seq_prod (ep_id); +ipa_endp_init_deaggr_prod (ep_id); + + ret =ipa_ep_setup (ep_id, channel_count,2 ,0 ,NULL ,NULL ); +if (ret) +ipa_ep_free (ep_id); +else + ipa_ctx->cmd_prod_ep_id = ep_id; + +return ret; +} + +/* Only used for IPA_MEM_UC_EVENT_RING_OFST, which must be 1KB aligned */ +static __always_inline void sram_set_canary(u32 *sram_mmio, u32 offset) +{ +BUILD_BUG_ON (offset <sizeof (*sram_mmio)); +BUILD_BUG_ON (offset %1024 ); + + sram_mmio += offset /sizeof (*sram_mmio); + *--sram_mmio =IPA_MEM_CANARY_VAL ; +} + +static __always_inline void sram_set_canaries(u32 *sram_mmio, u32 offset) +{ +BUILD_BUG_ON (offset <2 *sizeof (*sram_mmio)); +BUILD_BUG_ON (offset %8 ); + + sram_mmio += offset /sizeof (*sram_mmio); + *--sram_mmio =IPA_MEM_CANARY_VAL ; + *--sram_mmio =IPA_MEM_CANARY_VAL ; +} + +/** +* ipa_init_sram() - Initialize IPA local SRAM. +* +* Return: 0 if successful, or a negative error code +*/ +static int ipa_init_sram (void ) +{ +phys_addr_t phys_addr; +u32 *ipa_sram_mmio; + + phys_addr = ipa_ctx->ipa_phys; + phys_addr +=ipa_reg_n_offset (IPA_SRAM_DIRECT_ACCESS_N ,0 ); + phys_addr += ipa_ctx->smem_offset; + + ipa_sram_mmio =ioremap (phys_addr, ipa_ctx->smem_size); +if (!ipa_sram_mmio) { +ipa_err ("fail to ioremap IPA SRAM\n" ); +return -ENOMEM ; + } + +sram_set_canaries (ipa_sram_mmio,IPA_MEM_V4_FLT_HASH_OFST ); +sram_set_canaries (ipa_sram_mmio,IPA_MEM_V4_FLT_NHASH_OFST ); +sram_set_canaries (ipa_sram_mmio,IPA_MEM_V6_FLT_HASH_OFST ); +sram_set_canaries (ipa_sram_mmio,IPA_MEM_V6_FLT_NHASH_OFST ); +sram_set_canaries (ipa_sram_mmio,IPA_MEM_V4_RT_HASH_OFST ); +sram_set_canaries (ipa_sram_mmio,IPA_MEM_V4_RT_NHASH_OFST ); +sram_set_canaries (ipa_sram_mmio,IPA_MEM_V6_RT_HASH_OFST ); +sram_set_canaries (ipa_sram_mmio,IPA_MEM_V6_RT_NHASH_OFST ); +sram_set_canaries (ipa_sram_mmio,IPA_MEM_MODEM_HDR_OFST ); +sram_set_canaries (ipa_sram_mmio,IPA_MEM_MODEM_HDR_PROC_CTX_OFST ); +sram_set_canaries (ipa_sram_mmio,IPA_MEM_MODEM_OFST ); + +/* Only one canary precedes the microcontroller ring */ +sram_set_canary (ipa_sram_mmio,IPA_MEM_UC_EVENT_RING_OFST ); + +iounmap (ipa_sram_mmio); + +return 0 ; +} + +/** +* ipa_init_hdr() - Initialize IPA header block. +* +* Return: 0 if successful, or a negative error code +*/ +static int ipa_init_hdr (void ) +{ +int ret; + +if (IPA_MEM_MODEM_HDR_SIZE ) { + ret =hdr_init_local_cmd (IPA_MEM_MODEM_HDR_OFST , +IPA_MEM_MODEM_HDR_SIZE ); +if (ret) +return ret; + } + +if (IPA_MEM_APPS_HDR_SIZE ) { +BUILD_BUG_ON (IPA_MEM_APPS_HDR_OFST %8 ); + ret =hdr_init_local_cmd (IPA_MEM_APPS_HDR_OFST , +IPA_MEM_APPS_HDR_SIZE ); +if (ret) +return ret; + } + +if (IPA_MEM_MODEM_HDR_PROC_CTX_SIZE ) { + ret =dma_shared_mem_zero_cmd (IPA_MEM_MODEM_HDR_PROC_CTX_OFST , +IPA_MEM_MODEM_HDR_PROC_CTX_SIZE ); +if (ret) +return ret; + } + +if (IPA_MEM_APPS_HDR_PROC_CTX_SIZE ) { +BUILD_BUG_ON (IPA_MEM_APPS_HDR_PROC_CTX_OFST %8 ); + ret =dma_shared_mem_zero_cmd (IPA_MEM_APPS_HDR_PROC_CTX_OFST , +IPA_MEM_APPS_HDR_PROC_CTX_SIZE ); +if (ret) +return ret; + } + +ipa_write_reg (IPA_LOCAL_PKT_PROC_CNTXT_BASE , + ipa_ctx->smem_offset +IPA_MEM_MODEM_HDR_PROC_CTX_OFST ); + +return 0 ; +} + +/** +* ipa_init_rt4() - Initialize IPA routing block for IPv4. +* +* Return: 0 if successful, or a negative error code +*/ +static int ipa_init_rt4 (struct ipa_dma_mem *mem) +{ +struct ipa_desc desc = { }; +u32 nhash_offset; +u32 hash_offset; +void *payload; +int ret; + + hash_offset = ipa_ctx->smem_offset +IPA_MEM_V4_RT_HASH_OFST ; + nhash_offset = ipa_ctx->smem_offset +IPA_MEM_V4_RT_NHASH_OFST ; + payload =ipahal_ip_v4_routing_init_pyld (mem, hash_offset, + nhash_offset); +if (!payload) +return -ENOMEM ; + + desc.type =IPA_IMM_CMD_DESC ; + desc.len_opcode =IPA_IMM_CMD_IP_V4_ROUTING_INIT ; + desc.payload = payload; + + ret =ipa_send_cmd (&desc); + +ipahal_payload_free (payload); + +return ret; +} + +/** +* ipa_init_rt6() - Initialize IPA routing block for IPv6. +* +* Return: 0 if successful, or a negative error code +*/ +static int ipa_init_rt6 (struct ipa_dma_mem *mem) +{ +struct ipa_desc desc = { }; +u32 nhash_offset; +u32 hash_offset; +void *payload; +int ret; + + hash_offset = ipa_ctx->smem_offset +IPA_MEM_V6_RT_HASH_OFST ; + nhash_offset = ipa_ctx->smem_offset +IPA_MEM_V6_RT_NHASH_OFST ; + payload =ipahal_ip_v6_routing_init_pyld (mem, hash_offset, + nhash_offset); +if (!payload) +return -ENOMEM ; + + desc.type =IPA_IMM_CMD_DESC ; + desc.len_opcode =IPA_IMM_CMD_IP_V6_ROUTING_INIT ; + desc.payload = payload; + + ret =ipa_send_cmd (&desc); + +ipahal_payload_free (payload); + +return ret; +} + +/** +* ipa_init_flt4() - Initialize IPA filtering block for IPv4. +* +* Return: 0 if successful, or a negative error code +*/ +static int ipa_init_flt4 (struct ipa_dma_mem *mem) +{ +struct ipa_desc desc = { }; +u32 nhash_offset; +u32 hash_offset; +void *payload; +int ret; + + hash_offset = ipa_ctx->smem_offset +IPA_MEM_V4_FLT_HASH_OFST ; + nhash_offset = ipa_ctx->smem_offset +IPA_MEM_V4_FLT_NHASH_OFST ; + payload =ipahal_ip_v4_filter_init_pyld (mem, hash_offset, + nhash_offset); +if (!payload) +return -ENOMEM ; + + desc.type =IPA_IMM_CMD_DESC ; + desc.len_opcode =IPA_IMM_CMD_IP_V4_FILTER_INIT ; + desc.payload = payload; + + ret =ipa_send_cmd (&desc); + +ipahal_payload_free (payload); + +return ret; +} + +/** +* ipa_init_flt6() - Initialize IPA filtering block for IPv6. +* +* Return: 0 if successful, or a negative error code +*/ +static int ipa_init_flt6 (struct ipa_dma_mem *mem) +{ +struct ipa_desc desc = { }; +u32 nhash_offset; +u32 hash_offset; +void *payload; +int ret; + + hash_offset = ipa_ctx->smem_offset +IPA_MEM_V6_FLT_HASH_OFST ; + nhash_offset = ipa_ctx->smem_offset +IPA_MEM_V6_FLT_NHASH_OFST ; + payload =ipahal_ip_v6_filter_init_pyld (mem, hash_offset, + nhash_offset); +if (!payload) +return -ENOMEM ; + + desc.type =IPA_IMM_CMD_DESC ; + desc.len_opcode =IPA_IMM_CMD_IP_V6_FILTER_INIT ; + desc.payload = payload; + + ret =ipa_send_cmd (&desc); + +ipahal_payload_free (payload); + +return ret; +} + +static void ipa_setup_flt_hash_tuple (void ) +{ +u32 ep_mask = ipa_ctx->filter_bitmap; + +while (ep_mask) { +u32 i =__ffs (ep_mask); + + ep_mask ^=BIT (i); +if (!ipa_is_modem_ep (i)) +ipa_set_flt_tuple_mask (i); + } +} + +static void ipa_setup_rt_hash_tuple (void ) +{ +u32 route_mask; +u32 modem_mask; + +BUILD_BUG_ON (!IPA_MEM_MODEM_RT_COUNT ); +BUILD_BUG_ON (IPA_MEM_RT_COUNT <IPA_MEM_MODEM_RT_COUNT ); + +/* Compute a mask representing non-modem route table entries */ + route_mask =GENMASK (IPA_MEM_RT_COUNT -1 ,0 ); + modem_mask =GENMASK (IPA_MEM_MODEM_RT_INDEX_MAX , +IPA_MEM_MODEM_RT_INDEX_MIN ); + route_mask &= ~modem_mask; + +while (route_mask) { +u32 i =__ffs (route_mask); + + route_mask ^=BIT (i); +ipa_set_rt_tuple_mask (i); + } +} + +static int ipa_ep_apps_lan_cons_setup (void ) +{ +enum ipa_client_type client; +u32 rx_buffer_size; +u32 channel_count; +u32 aggr_count; +u32 aggr_bytes; +u32 aggr_size; +u32 ep_id; +int ret; + + client =IPA_CLIENT_APPS_LAN_CONS ; + channel_count =IPA_APPS_LAN_CONS_RING_COUNT ; + aggr_count =IPA_GENERIC_AGGR_PKT_LIMIT ; + aggr_bytes =IPA_GENERIC_AGGR_BYTE_LIMIT ; + +if (aggr_bytes >ipa_reg_aggr_max_byte_limit ()) +return -EINVAL ; + +if (aggr_count >ipa_reg_aggr_max_packet_limit ()) +return -EINVAL ; + +if (ipa_ctx->lan_cons_ep_id !=IPA_EP_ID_BAD ) +return -EBUSY ; + +/* Compute the buffer size required to handle the requested +* aggregation byte limit. The aggr_byte_limit value is +* expressed as a number of KB, but we derive that value +* after computing the buffer size to use (in bytes). The +* buffer must be sufficient to hold one IPA_MTU-sized +* packet *after* the limit is reached. +* +* (Note that the rx_buffer_size value reflects only the +* space for data, not any standard metadata or headers.) +*/ + rx_buffer_size =ipa_aggr_byte_limit_buf_size (aggr_bytes); + +/* Account for the extra IPA_MTU past the limit in the +* buffer, and convert the result to the KB units the +* aggr_byte_limit uses. +*/ + aggr_size = (rx_buffer_size -IPA_MTU ) /SZ_1K ; + + ret =ipa_ep_alloc (client); +if (ret <0 ) +return ret; + ep_id = ret; + +ipa_endp_init_hdr_cons (ep_id,IPA_LAN_RX_HEADER_LENGTH ,0 ,0 ); +ipa_endp_init_hdr_ext_cons (ep_id,ilog2 (sizeof (u32)), false); +ipa_endp_init_aggr_cons (ep_id, aggr_size, aggr_count, false); +ipa_endp_init_cfg_cons (ep_id,IPA_CS_OFFLOAD_DL ); +ipa_endp_init_hdr_metadata_mask_cons (ep_id,0x0 ); +ipa_endp_status_cons (ep_id, true); + + ret =ipa_ep_setup (ep_id, channel_count,1 , rx_buffer_size, + ipa_lan_rx_cb,NULL ); +if (ret) +ipa_ep_free (ep_id); +else + ipa_ctx->lan_cons_ep_id = ep_id; + +return ret; +} + +static int ipa_ep_apps_setup (void ) +{ +struct ipa_dma_mem mem;/* Empty table */ +int ret; + +/* CMD OUT (AP->IPA) */ + ret =ipa_ep_apps_cmd_prod_setup (); +if (ret <0 ) +return ret; + +ipa_init_sram (); +ipa_init_hdr (); + + ret =ipahal_rt_generate_empty_img (IPA_MEM_RT_COUNT , &mem); +ipa_assert (!ret); +ipa_init_rt4 (&mem); +ipa_init_rt6 (&mem); +ipahal_free_empty_img (&mem); + + ret =ipahal_flt_generate_empty_img (ipa_ctx->filter_bitmap, &mem); +ipa_assert (!ret); +ipa_init_flt4 (&mem); +ipa_init_flt6 (&mem); +ipahal_free_empty_img (&mem); + +ipa_setup_flt_hash_tuple (); +ipa_setup_rt_hash_tuple (); + +/* LAN IN (IPA->AP) +* +* Even without supporting LAN traffic, we use the LAN consumer +* endpoint for receiving some information from the IPA. If we issue +* a tagged command, we arrange to be notified of its completion +* through this endpoint. In addition, we arrange for this endpoint +* to be used as the IPA's default route; the IPA will notify the AP +* of exceptions (unroutable packets, but other events as well) +* through this endpoint. +*/ + ret =ipa_ep_apps_lan_cons_setup (); +if (ret <0 ) + goto fail_flt_hash_tuple; + +ipa_cfg_default_route (IPA_CLIENT_APPS_LAN_CONS ); + +return 0 ; + +fail_flt_hash_tuple: +ipa_ep_teardown (ipa_ctx->cmd_prod_ep_id); + ipa_ctx->cmd_prod_ep_id =IPA_EP_ID_BAD ; + +return ret; +} + +static int ipa_clock_init (struct device *dev) +{ +struct clk *clk; +int ret; + + clk =clk_get (dev,"core" ); +if (IS_ERR (clk)) +return PTR_ERR (clk); + + ret =clk_set_rate (clk,IPA_CORE_CLOCK_RATE ); +if (ret) { +clk_put (clk); +return ret; + } + + ipa_ctx->core_clock = clk; + +return 0 ; +} + +static void ipa_clock_exit (void ) +{ +clk_put (ipa_ctx->core_clock); + ipa_ctx->core_clock =NULL ; +} + +/** +* ipa_enable_clks() - Turn on IPA clocks +*/ +static void ipa_enable_clks (void ) +{ +if (WARN_ON (ipa_interconnect_enable ())) +return ; + +if (WARN_ON (clk_prepare_enable (ipa_ctx->core_clock))) +ipa_interconnect_disable (); +} + +/** +* ipa_disable_clks() - Turn off IPA clocks +*/ +static void ipa_disable_clks (void ) +{ +clk_disable_unprepare (ipa_ctx->core_clock); +WARN_ON (ipa_interconnect_disable ()); +} + +/* Add an IPA client under protection of the mutex. This is called +* for the first client, but a race could mean another caller gets +* the first reference. When the first reference is taken, IPA +* clocks are enabled endpoints are resumed. A positive reference count +* means the endpoints are active; this doesn't set the first reference +* until after this is complete (and the mutex, not the atomic +* count, is what protects this). +*/ +static void ipa_client_add_first (void ) +{ +mutex_lock (&ipa_ctx->active_clients_mutex); + +/* A reference might have been added while awaiting the mutex. */ +if (!atomic_inc_not_zero (&ipa_ctx->active_clients_count)) { +ipa_enable_clks (); +ipa_ep_resume_all (); +atomic_inc (&ipa_ctx->active_clients_count); + }else { +ipa_assert (atomic_read (&ipa_ctx->active_clients_count) >1 ); + } + +mutex_unlock (&ipa_ctx->active_clients_mutex); +} + +/* Attempt to add an IPA client reference, but only if this does not +* represent the initiaal reference. Returns true if the reference +* was taken, false otherwise. +*/ +static bool ipa_client_add_not_first (void ) +{ +return !!atomic_inc_not_zero (&ipa_ctx->active_clients_count); +} + +/* Add an IPA client, but only if the reference count is already +* non-zero. (This is used to avoid blocking.) Returns true if the +* additional reference was added successfully, or false otherwise. +*/ +bool ipa_client_add_additional (void ) +{ +return ipa_client_add_not_first (); +} + +/* Add an IPA client. If this is not the first client, the +* reference count is updated and return is immediate. Otherwise +* ipa_client_add_first() will safely add the first client, enabling +* clocks and setting up (resuming) endpoints before returning. +*/ +void ipa_client_add (void ) +{ +/* There's nothing more to do if this isn't the first reference */ +if (!ipa_client_add_not_first ()) +ipa_client_add_first (); +} + +/* Remove an IPA client under protection of the mutex. This is +* called for the last remaining client, but a race could mean +* another caller gets an additional reference before the mutex +* is acquired. When the final reference is dropped, endpoints are +* suspended and IPA clocks disabled. +*/ +static void ipa_client_remove_final (void ) +{ +mutex_lock (&ipa_ctx->active_clients_mutex); + +/* A reference might have been removed while awaiting the mutex. */ +if (!atomic_dec_return (&ipa_ctx->active_clients_count)) { +ipa_ep_suspend_all (); +ipa_disable_clks (); + } + +mutex_unlock (&ipa_ctx->active_clients_mutex); +} + +/* Decrement the active clients reference count, and if the result +* is 0, suspend the endpoints and disable clocks. +* +* This function runs in work queue context, scheduled to run whenever +* the last reference would be dropped in ipa_client_remove(). +*/ +static void ipa_client_remove_deferred (struct work_struct *work) +{ +ipa_client_remove_final (); +} + +/* Attempt to remove a client reference, but only if this is not the +* only reference remaining. Returns true if the reference was +* removed, or false if doing so would produce a zero reference +* count. +*/ +static bool ipa_client_remove_not_final (void ) +{ +return !!atomic_add_unless (&ipa_ctx->active_clients_count,-1 ,1 ); +} + +/* Attempt to remove an IPA client reference. If this represents +* the last reference arrange for ipa_client_remove_final() to be +* called in workqueue context, dropping the last reference under +* protection of the mutex. +*/ +void ipa_client_remove (void ) +{ +if (!ipa_client_remove_not_final ()) +queue_work (ipa_ctx->power_mgmt_wq, &ipa_client_remove_work); +} + +/** ipa_inc_acquire_wakelock() - Increase active clients counter, and +* acquire wakelock if necessary +*/ +void ipa_inc_acquire_wakelock (void ) +{ +unsigned long flags; + +spin_lock_irqsave (&ipa_ctx->wakeup_lock, flags); + + ipa_ctx->wakeup_count++; +if (ipa_ctx->wakeup_count ==1 ) +__pm_stay_awake (&ipa_ctx->wakeup); + +spin_unlock_irqrestore (&ipa_ctx->wakeup_lock, flags); +} + +/** ipa_dec_release_wakelock() - Decrease active clients counter +* +* In case if the ref count is 0, release the wakelock. +*/ +void ipa_dec_release_wakelock (void ) +{ +unsigned long flags; + +spin_lock_irqsave (&ipa_ctx->wakeup_lock, flags); + + ipa_ctx->wakeup_count--; +if (ipa_ctx->wakeup_count ==0 ) +__pm_relax (&ipa_ctx->wakeup); + +spin_unlock_irqrestore (&ipa_ctx->wakeup_lock, flags); +} + +/** ipa_suspend_handler() - Handle the suspend interrupt +* @interrupt: Interrupt type +* @endpoints: Interrupt specific information data +*/ +static void ipa_suspend_handler (enum ipa_irq_type interrupt,u32 interrupt_data) +{ +u32 endpoints = interrupt_data; + +while (endpoints) { +enum ipa_client_type client; +u32 i =__ffs (endpoints); + + endpoints ^=BIT (i); + +if (!ipa_ctx->ep[i].allocated) +continue ; + + client = ipa_ctx->ep[i].client; +if (!ipa_ap_consumer (client)) +continue ; + +/* endpoint will be unsuspended by enabling IPA clocks */ +mutex_lock (&ipa_ctx->transport_pm.transport_pm_mutex); +if (!atomic_read (&ipa_ctx->transport_pm.dec_clients)) { +ipa_client_add (); + +atomic_set (&ipa_ctx->transport_pm.dec_clients,1 ); + } +mutex_unlock (&ipa_ctx->transport_pm.transport_pm_mutex); + } +} + +/** +* ipa_init_interrupts() - Initialize IPA interrupts +*/ +static int ipa_init_interrupts (void ) +{ +int ret; + + ret =ipa_interrupts_init (); +if (!ret) +return ret; + +ipa_add_interrupt_handler (IPA_TX_SUSPEND_IRQ , ipa_suspend_handler); + +return 0 ; +} + +static void ipa_freeze_clock_vote_and_notify_modem (void ) +{ +u32 value; +u32 mask; + +if (ipa_ctx->smp2p_info.res_sent) +return ; + +if (!ipa_ctx->smp2p_info.enabled_state) { +ipa_err ("smp2p out gpio not assigned\n" ); +return ; + } + + ipa_ctx->smp2p_info.ipa_clk_on =ipa_client_add_additional (); + +/* Signal whether the clock is enabled */ + mask =BIT (ipa_ctx->smp2p_info.enabled_bit); + value = ipa_ctx->smp2p_info.ipa_clk_on ? mask :0 ; +qcom_smem_state_update_bits (ipa_ctx->smp2p_info.enabled_state, mask, + value); + +/* Now indicate that the enabled flag is valid */ + mask =BIT (ipa_ctx->smp2p_info.valid_bit); + value = mask; +qcom_smem_state_update_bits (ipa_ctx->smp2p_info.valid_state, mask, + value); + + ipa_ctx->smp2p_info.res_sent = true; +} + +void ipa_reset_freeze_vote (void ) +{ +u32 mask; + +if (!ipa_ctx->smp2p_info.res_sent) +return ; + +if (ipa_ctx->smp2p_info.ipa_clk_on) +ipa_client_remove (); + +/* Reset the clock enabled valid flag */ + mask =BIT (ipa_ctx->smp2p_info.valid_bit); +qcom_smem_state_update_bits (ipa_ctx->smp2p_info.valid_state, mask,0 ); + +/* Mark the clock disabled for good measure... */ + mask =BIT (ipa_ctx->smp2p_info.enabled_bit); +qcom_smem_state_update_bits (ipa_ctx->smp2p_info.enabled_state, mask,0 ); + + ipa_ctx->smp2p_info.res_sent = false; + ipa_ctx->smp2p_info.ipa_clk_on = false; +} + +static int +ipa_panic_notifier (struct notifier_block *this,unsigned long event,void *ptr) +{ +ipa_freeze_clock_vote_and_notify_modem (); +ipa_uc_panic_notifier (); + +return NOTIFY_DONE ; +} + +static struct notifier_block ipa_panic_blk = { + .notifier_call = ipa_panic_notifier, +/* IPA panic handler needs to run before modem shuts down */ + .priority =INT_MAX , +}; + +static void ipa_register_panic_hdlr (void ) +{ +atomic_notifier_chain_register (&panic_notifier_list, &ipa_panic_blk); +} + +/* Remoteproc callbacks for SSR events: prepare, start, stop, unprepare */ +int ipa_ssr_prepare (struct rproc_subdev *subdev) +{ +printk ("======== SSR prepare received ========\n" ); +return 0 ; +} +EXPORT_SYMBOL_GPL (ipa_ssr_prepare); + +int ipa_ssr_start (struct rproc_subdev *subdev) +{ +printk ("======== SSR start received ========\n" ); +return 0 ; +} +EXPORT_SYMBOL_GPL (ipa_ssr_start); + +void ipa_ssr_stop (struct rproc_subdev *subdev,bool crashed) +{ +printk ("======== SSR stop received ========\n" ); +} +EXPORT_SYMBOL_GPL (ipa_ssr_stop); + +void ipa_ssr_unprepare (struct rproc_subdev *subdev) +{ +printk ("======== SSR unprepare received ========\n" ); +} +EXPORT_SYMBOL_GPL (ipa_ssr_unprepare); + +/** +* ipa_post_init() - Initialize the IPA Driver (Part II). +* +* Perform initialization that requires interaction with IPA hardware. +*/ +static void ipa_post_init (void ) +{ +int ret; + +ipa_debug ("ipa_post_init() started\n" ); + + ret =gsi_device_init (ipa_ctx->gsi); +if (ret) { +ipa_err (":gsi register error - %d\n" , ret); +return ; + } + +/* setup the AP-IPA endpoints */ +if (ipa_ep_apps_setup ()) { +ipa_err (":failed to setup IPA-Apps endpoints\n" ); +gsi_device_exit (ipa_ctx->gsi); + +return ; + } + + ipa_ctx->uc_ctx =ipa_uc_init (ipa_ctx->ipa_phys); +if (!ipa_ctx->uc_ctx) +ipa_err ("microcontroller init failed\n" ); + +ipa_register_panic_hdlr (); + + ipa_ctx->modem_clk_vote_valid = true; + +if (ipa_wwan_init ()) +ipa_err ("WWAN init failed (ignoring)\n" ); + +dev_info (ipa_ctx->dev,"IPA driver initialization was successful.\n" ); +} + +/** ipa_pre_init() - Initialize the IPA Driver. +* +* Perform initialization which doesn't require access to IPA hardware. +*/ +static int ipa_pre_init (void ) +{ +int ret =0 ; + +/* enable IPA clocks explicitly to allow the initialization */ +ipa_enable_clks (); + +ipa_init_hw (); + + ipa_ctx->ep_count =ipa_get_ep_count (); +ipa_debug ("ep_count %u\n" ,ipa_get_ep_count ()); +ipa_assert (ipa_ctx->ep_count <=IPA_EP_COUNT_MAX ); + +ipa_sram_settings_read (); +if (ipa_ctx->smem_size <IPA_MEM_END_OFST ) { +ipa_err ("insufficient memory: %hu bytes available, need %u\n" , + ipa_ctx->smem_size,IPA_MEM_END_OFST ); + ret = -ENOMEM ; + goto err_disable_clks; + } + +mutex_init (&ipa_ctx->active_clients_mutex); +atomic_set (&ipa_ctx->active_clients_count,1 ); + +/* Create workqueues for power management */ + ipa_ctx->power_mgmt_wq = +create_singlethread_workqueue ("ipa_power_mgmt" ); +if (!ipa_ctx->power_mgmt_wq) { +ipa_err ("failed to create power mgmt wq\n" ); + ret = -ENOMEM ; + goto err_disable_clks; + } + +mutex_init (&ipa_ctx->transport_pm.transport_pm_mutex); + +/* init the lookaside cache */ + + ipa_ctx->dp =ipa_dp_init (); +if (!ipa_ctx->dp) + goto err_destroy_pm_wq; + +/* allocate memory for DMA_TASK workaround */ + ret =ipa_gsi_dma_task_alloc (); +if (ret) + goto err_dp_exit; + +/* Create a wakeup source. */ +wakeup_source_init (&ipa_ctx->wakeup,"IPA_WS" ); +spin_lock_init (&ipa_ctx->wakeup_lock); + +/* Note enabling dynamic clock division must not be +* attempted for IPA hardware versions prior to 3.5. +*/ +ipa_enable_dcd (); + +/* Assign resource limitation to each group */ +ipa_set_resource_groups_min_max_limits (); + + ret =ipa_init_interrupts (); +if (!ret) +return 0 ;/* Success! */ + +ipa_err ("ipa initialization of interrupts failed\n" ); +err_dp_exit: +ipa_dp_exit (ipa_ctx->dp); + ipa_ctx->dp =NULL ; +err_destroy_pm_wq: +destroy_workqueue (ipa_ctx->power_mgmt_wq); +err_disable_clks: +ipa_disable_clks (); + +return ret; +} + +static int ipa_firmware_load (struct device *dev) +{ +const struct firmware *fw; +struct device_node *node; +struct resource res; +phys_addr_t phys; +ssize_t size; +void *virt; +int ret; + + ret =request_firmware (&fw,IPA_FWS_PATH , dev); +if (ret) +return ret; + + node =of_parse_phandle (dev->of_node,"memory-region" ,0 ); +if (!node) { +dev_err (dev,"memory-region not specified\n" ); + ret = -EINVAL ; + goto out_release_firmware; + } + + ret =of_address_to_resource (node,0 , &res); +if (ret) + goto out_release_firmware; + + phys = res.start, + size = (size_t )resource_size (&res); + virt =memremap (phys, size,MEMREMAP_WC ); +if (!virt) { + ret = -ENOMEM ; + goto out_release_firmware; + } + + ret =qcom_mdt_load (dev, fw,IPA_FWS_PATH ,IPA_PAS_ID , + virt, phys, size,NULL ); +if (!ret) + ret =qcom_scm_pas_auth_and_reset (IPA_PAS_ID ); + +memunmap (virt); +out_release_firmware: +release_firmware (fw); + +return ret; +} + +/* Threaded IRQ handler for modem "ipa-clock-query" SMP2P interrupt */ +static irqreturn_t ipa_smp2p_modem_clk_query_isr (int irq,void *ctxt) +{ +ipa_freeze_clock_vote_and_notify_modem (); + +return IRQ_HANDLED ; +} + +/* Threaded IRQ handler for modem "ipa-post-init" SMP2P interrupt */ +static irqreturn_t ipa_smp2p_modem_post_init_isr (int irq,void *ctxt) +{ +ipa_post_init (); + +return IRQ_HANDLED ; +} + +static int +ipa_smp2p_irq_init (struct device *dev,const char *name,irq_handler_t handler) +{ +struct device_node *node = dev->of_node; +unsigned int irq; +int ret; + + ret =of_irq_get_byname (node, name); +if (ret <0 ) +return ret; +if (!ret) +return -EINVAL ;/* IRQ mapping failure */ + irq = ret; + + ret =devm_request_threaded_irq (dev, irq,NULL , handler,0 , name, dev); +if (ret) +return ret; + +return irq; +} + +static void +ipa_smp2p_irq_exit (struct device *dev,unsigned int irq) +{ +devm_free_irq (dev, irq, dev); +} + +static int ipa_smp2p_init (struct device *dev,bool modem_init) +{ +struct qcom_smem_state *enabled_state; +struct qcom_smem_state *valid_state; +struct device_node *node; +unsigned int enabled_bit; +unsigned int valid_bit; +unsigned int clock_irq; +int ret; + + node = dev->of_node; + + valid_state =qcom_smem_state_get (dev,"ipa-clock-enabled-valid" , + &valid_bit); +if (IS_ERR (valid_state)) +return PTR_ERR (valid_state); + + enabled_state =qcom_smem_state_get (dev,"ipa-clock-enabled" , + &enabled_bit); +if (IS_ERR (enabled_state)) { + ret =PTR_ERR (enabled_state); +ipa_err ("error %d getting ipa-clock-enabled state\n" , ret); + +return ret; + } + + ret =ipa_smp2p_irq_init (dev,"ipa-clock-query" , + ipa_smp2p_modem_clk_query_isr); +if (ret <0 ) +return ret; + clock_irq = ret; + +if (modem_init) { +/* Result will be non-zero (negative for error) */ + ret =ipa_smp2p_irq_init (dev,"ipa-post-init" , + ipa_smp2p_modem_post_init_isr); +if (ret <0 ) { +ipa_smp2p_irq_exit (dev, clock_irq); + +return ret; + } + } + +/* Success. Record our smp2p information */ + ipa_ctx->smp2p_info.valid_state = valid_state; + ipa_ctx->smp2p_info.valid_bit = valid_bit; + ipa_ctx->smp2p_info.enabled_state = enabled_state; + ipa_ctx->smp2p_info.enabled_bit = enabled_bit; + ipa_ctx->smp2p_info.clock_query_irq = clock_irq; + ipa_ctx->smp2p_info.post_init_irq = modem_init ? ret :0 ; + +return 0 ; +} + +static void ipa_smp2p_exit (struct device *dev) +{ +if (ipa_ctx->smp2p_info.post_init_irq) +ipa_smp2p_irq_exit (dev, ipa_ctx->smp2p_info.post_init_irq); +ipa_smp2p_irq_exit (dev, ipa_ctx->smp2p_info.clock_query_irq); + +memset (&ipa_ctx->smp2p_info,0 ,sizeof (ipa_ctx->smp2p_info)); +} + +static const struct ipa_match_data tz_init = { + .init_type = ipa_tz_init, +}; + +static const struct ipa_match_data modem_init = { + .init_type = ipa_modem_init, +}; + +static const struct of_device_id ipa_plat_drv_match[] = { + { + .compatible ="qcom,ipa-sdm845-tz_init" , + .data = &tz_init, + }, + { + .compatible ="qcom,ipa-sdm845-modem_init" , + .data = &modem_init, + }, + {} +}; + +static int ipa_plat_drv_probe (struct platform_device *pdev) +{ +const struct ipa_match_data *match_data; +struct resource *res; +struct device *dev; +bool modem_init; +int ret; + +/* We assume we're working on 64-bit hardware */ +BUILD_BUG_ON (!IS_ENABLED (CONFIG_64BIT )); + + dev = &pdev->dev; + + match_data =of_device_get_match_data (dev); + modem_init = match_data->init_type == ipa_modem_init; + +/* If we need Trust Zone, make sure it's ready */ +if (!modem_init) +if (!qcom_scm_is_available ()) +return -EPROBE_DEFER ; + +/* Initialize the smp2p driver early. It might not be ready +* when we're probed, so it might return -EPROBE_DEFER. +*/ + ret =ipa_smp2p_init (dev, modem_init); +if (ret) +return ret; + +/* Initialize the interconnect driver early too. It might +* also return -EPROBE_DEFER. +*/ + ret =ipa_interconnect_init (dev); +if (ret) + goto out_smp2p_exit; + + ret =ipa_clock_init (dev); +if (ret) + goto err_interconnect_exit; + + ipa_ctx->dev = dev;/* Set early for ipa_err()/ipa_debug() */ + +/* Compute a bitmask representing which endpoints support filtering */ + ipa_ctx->filter_bitmap =ipa_filter_bitmap_init (); +ipa_debug ("filter_bitmap 0x%08x\n" , ipa_ctx->filter_bitmap); +if (!ipa_ctx->filter_bitmap) + goto err_clock_exit; + + ret =platform_get_irq_byname (pdev,"ipa" ); +if (ret <0 ) + goto err_clear_filter_bitmap; + ipa_ctx->ipa_irq = ret; + +/* Get IPA memory range */ + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"ipa" ); +if (!res) { + ret = -ENODEV ; + goto err_clear_ipa_irq; + } + +/* Setup IPA register access */ + ret =ipa_reg_init (res->start, (size_t )resource_size (res)); +if (ret) + goto err_clear_ipa_irq; + ipa_ctx->ipa_phys = res->start; + + ipa_ctx->gsi =gsi_init (pdev); +if (IS_ERR (ipa_ctx->gsi)) { + ret =PTR_ERR (ipa_ctx->gsi); + goto err_clear_gsi; + } + + ret =ipa_dma_init (dev,IPA_HW_TBL_SYSADDR_ALIGN ); +if (ret) + goto err_clear_gsi; + + ret =ipahal_init (); +if (ret) + goto err_dma_exit; + + ipa_ctx->cmd_prod_ep_id =IPA_EP_ID_BAD ; + ipa_ctx->lan_cons_ep_id =IPA_EP_ID_BAD ; + +/* Proceed to real initialization */ + ret =ipa_pre_init (); +if (ret) + goto err_clear_dev; + +/* If the modem is not verifying and loading firmware we need to +* get it loaded ourselves. Only then can we proceed with the +* second stage of IPA initialization. If the modem is doing it, +* it will send an SMP2P interrupt to signal this has been done, +* and that will trigger the "post init". +*/ +if (!modem_init) { + ret =ipa_firmware_load (dev); +if (ret) + goto err_clear_dev; + +/* Now we can proceed to stage two initialization */ +ipa_post_init (); + } + +return 0 ;/* Success */ + +err_clear_dev: + ipa_ctx->lan_cons_ep_id =0 ; + ipa_ctx->cmd_prod_ep_id =0 ; +ipahal_exit (); +err_dma_exit: +ipa_dma_exit (); +err_clear_gsi: + ipa_ctx->gsi =NULL ; + ipa_ctx->ipa_phys =0 ; +ipa_reg_exit (); +err_clear_ipa_irq: + ipa_ctx->ipa_irq =0 ; +err_clear_filter_bitmap: + ipa_ctx->filter_bitmap =0 ; +err_interconnect_exit: +ipa_interconnect_exit (); +err_clock_exit: +ipa_clock_exit (); + ipa_ctx->dev =NULL ; +out_smp2p_exit: +ipa_smp2p_exit (dev); + +return ret; +} + +static int ipa_plat_drv_remove (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; + + ipa_ctx->dev =NULL ; +ipahal_exit (); +ipa_dma_exit (); + ipa_ctx->gsi =NULL ;/* XXX ipa_gsi_exit() */ +ipa_reg_exit (); + + ipa_ctx->ipa_phys =0 ; + +if (ipa_ctx->lan_cons_ep_id !=IPA_EP_ID_BAD ) { +ipa_ep_free (ipa_ctx->lan_cons_ep_id); + ipa_ctx->lan_cons_ep_id =IPA_EP_ID_BAD ; + } +if (ipa_ctx->cmd_prod_ep_id !=IPA_EP_ID_BAD ) { +ipa_ep_free (ipa_ctx->cmd_prod_ep_id); + ipa_ctx->cmd_prod_ep_id =IPA_EP_ID_BAD ; + } + ipa_ctx->ipa_irq =0 ;/* XXX Need to de-initialize? */ + ipa_ctx->filter_bitmap =0 ; +ipa_interconnect_exit (); +ipa_smp2p_exit (dev); + +return 0 ; +} + +/** +* ipa_ap_suspend() - suspend callback for runtime_pm +* @dev: IPA device structure +* +* This callback will be invoked by the runtime_pm framework when an AP suspend +* operation is invoked, usually by pressing a suspend button. +* +* Return: 0 if successful, -EAGAIN if IPA is in use +*/ +int ipa_ap_suspend (struct device *dev) +{ +u32 i; + +/* In case there is a tx/rx handler in polling mode fail to suspend */ +for (i =0 ; i < ipa_ctx->ep_count; i++) { +if (ipa_ctx->ep[i].sys &&ipa_ep_polling (&ipa_ctx->ep[i])) { +ipa_err ("EP %d is in polling state, do not suspend\n" , + i); +return -EAGAIN ; + } + } + +return 0 ; +} + +/** +* ipa_ap_resume() - resume callback for runtime_pm +* @dev: IPA device structure +* +* This callback will be invoked by the runtime_pm framework when an AP resume +* operation is invoked. +* +* Return: Zero +*/ +int ipa_ap_resume (struct device *dev) +{ +return 0 ; +} + +static const struct dev_pm_ops ipa_pm_ops = { + .suspend_noirq = ipa_ap_suspend, + .resume_noirq = ipa_ap_resume, +}; + +static struct platform_driver ipa_plat_drv = { + .probe = ipa_plat_drv_probe, + .remove = ipa_plat_drv_remove, + .driver = { + .name ="ipa" , + .owner =THIS_MODULE , + .pm = &ipa_pm_ops, + .of_match_table = ipa_plat_drv_match, + }, +}; + +builtin_platform_driver (ipa_plat_drv); + +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("IPA HW device driver" );
Signature · 1 line
2.17.1
RFC PATCH 10/12 soc: qcom: ipa: data path
In reply to Alex ElderThis patch contains "ipa_dp.c", which includes the bulk of the data path code. There is an overview in the code of how things operate, but there are already plans to rework this portion of the driver.
In particular:
- Interrupt handling will be replaced with a threaded interrupt handler. Currently handling occurs in a combination of interrupt and workqueue context, and this requires locking and atomic operations for proper synchronization.
- Currently, only receive endpoints use NAPI. Transmit completion interrupts are disabled, and are handled in batches by periodically scheduling an interrupting no-op request. The plan is to arrange for transmit requests to generate interrupts, and their completion will be processed with other completions in the NAPI poll function. This will also allow accurate feedback about packet sojourn time to be provided to queue limiting mechanisms.
- Not all receive endpoints use NAPI. The plan is for *all* endpoints to use NAPI. And because all endpoints share a common GSI interrupt, a single NAPI structure will used to managing the processing for all completions on all endpoints.
- Receive buffers are posted to the hardware by a workqueue function. Instead, the plan is to have this done by the NAPI poll routine.
--- drivers/net/ipa/ipa_dp.c | 1994 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 1994 insertions(+) create mode 100644 drivers/net/ipa/ipa_dp.c
drivers/net/ipa/ipa_dp.c new file +1994 -0
@@ -0,0 +1,1994 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd. +*/ + +#include <linux/types.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/list.h> +#include <linux/slab.h> +#include <linux/netdevice.h> + +#include "ipa_i.h" /* ipa_err() */ +#include "ipahal.h" +#include "ipa_dma.h" + +/** +* DOC: The IPA Data Path +* +* The IPA is used to transmit data between execution environments. +* The data path code uses functions and structures supplied by the +* GSI to interact with the IPA hardware. A packet to be transmitted +* or received is held in a socket buffer. Each has a "wrapper" +* structure associated with it. A GSI transfer request refers to +* the packet wrapper, and when queued to the hardware the packet +* wrapper is added to a list of outstanding requests for an endpoint +* (maintained in the head_desc_list in the endpoint's system context). +* When the GSI transfer completes, a callback function is provided +* the packet wrapper pointer, allowing it to be released after the +* received socket buffer has been passed up the stack, or a buffer +* whose data has been transmitted has been freed. +* +* Producer (PROD) endpoints are used to send data from the AP toward +* the IPA. The common function for sending data on producer endpoints +* is ipa_send(). It takes a system context and an array of IPA +* descriptors as arguments. Each descriptor is given a TX packet +* wrapper, and its content is translated into an equivalent GSI +* transfer element structure after its memory address is mapped for +* DMA. The GSI transfer element array is finally passed to the GSI +* layer using gsi_channel_queue(). +* +* The code provides a "no_intr" feature, allowing endpoints to have +* their transmit completions not produce an interrupt. (This +* behavior is used only for the modem producer.) In this case, a +* no-op request is generated every 200 milliseconds while transmit +* requests are outstanding. The no-op will generate an interrupt +* when it's complete, and its completion implies the completion of +* all transmit requests issued before it. The GSI will call +* ipa_gsi_irq_tx_notify_cb() in response to interrupts on a producer +* endpoint. +* +* Receive buffers are passed to consumer (CONS) channels to be +* available to hold incoming data. Arriving data is placed +* in these buffers, leading to events being generated on the event +* ring assciated with a channel. When an interrupt occurs on a +* consumer endpoint, the GSI layer calls ipa_gsi_irq_rx_notify_cb(). +* This causes the endpoint to switch to polling mode. The +* completion of a receive also leads to ipa_replenish_rx_cache() +* being called, to replace the consumed buffer. +* +* Consumer enpoints optionally use NAPI (only the modem consumer, +* WWAN_CONS, does currently). An atomic variable records whether +* the endpoint is in polling mode or not. This is needed because +* switching to polling mode is currently done in a workqueue. Once +* NAPI polling completes, and endpoint switches back to interrupt +* mode. +*/ + +/** +* struct ipa_tx_pkt_wrapper - IPA transmit packet wrapper +* @type: type of descriptor +* @sys: Corresponding IPA sys context +* @mem: Memory buffer used by this packet +* @callback: IPA client provided callback +* @user1: Cookie1 for above callback +* @user2: Cookie2 for above callback +* @link: Links for the endpoint's sys->head_desc_list +* @cnt: Number of descriptors in request +* @done_work: Work structure used when complete +*/ +struct ipa_tx_pkt_wrapper { +enum ipa_desc_type type; +struct ipa_sys_context *sys; +struct ipa_dma_mem mem; +void (*callback)(void *user1,int user2); +void *user1; +int user2; +struct list_head link; +u32 cnt; +struct work_struct done_work; +}; + +/** struct ipa_rx_pkt_wrapper - IPA Rx packet wrapper +* @link: Links for the endpoint's sys->head_desc_list +* @skb: Socket buffer containing the received packet +* @len: How many bytes are copied into skb's buffer +*/ +struct ipa_rx_pkt_wrapper { +struct list_head link; +struct sk_buff *skb; +dma_addr_t dma_addr; +}; + +/** struct ipa_sys_context - IPA GPI endpoint context +* @len: The number of entries in @head_desc_list +* @tx: Details related to AP->IPA endpoints +* @rx: Details related to IPA->AP endpoints +* @ep: Associated endpoint +* @head_desc_list: List of packets +* @spinlock: Lock protecting the descriptor list +* @workqueue: Workqueue used for this endpoint +*/ +struct ipa_sys_context { +u32 len; +union { +struct {/* Consumer endpoints only */ +u32 len_pending_xfer; +atomic_t curr_polling_state; +struct delayed_work switch_to_intr_work;/* sys->wq */ +void (*pyld_hdlr)(struct sk_buff *, +struct ipa_sys_context *); +u32 buff_sz; +u32 pool_sz; +struct sk_buff *prev_skb; +unsigned int len_rem; +unsigned int len_pad;/* APPS_LAN only */ +unsigned int len_partial;/* APPS_LAN only */ +bool drop_packet;/* APPS_LAN only */ + +struct work_struct work;/* sys->wq */ +struct delayed_work replenish_work;/* sys->wq */ + } rx; +struct {/* Producer endpoints only */ +/* no_intr/nop is APPS_WAN_PROD only */ +bool no_intr; +atomic_t nop_pending; +struct hrtimer nop_timer; +struct work_struct nop_work;/* sys->wq */ + } tx; + }; + +/* ordering is important - mutable fields go above */ +struct ipa_ep_context *ep; +struct list_head head_desc_list;/* contains len entries */ +spinlock_t spinlock;/* protects head_desc list */ +struct workqueue_struct *wq; +/* ordering is important - other immutable fields go below */ +}; + +/** +* struct ipa_dp - IPA data path information +* @tx_pkt_wrapper_cache: Tx packets cache +* @rx_pkt_wrapper_cache: Rx packets cache +*/ +struct ipa_dp { +struct kmem_cache *tx_pkt_wrapper_cache; +struct kmem_cache *rx_pkt_wrapper_cache; +}; + +/** +* struct ipa_tag_completion - Reference counted completion object +* @comp: Completion when last reference is dropped +* @cnt: Reference count +*/ +struct ipa_tag_completion { +struct completion comp; +atomic_t cnt; +}; + +#define CHANNEL_RESET_AGGR_RETRY_COUNT 3 +#define CHANNEL_RESET_DELAY 1/* milliseconds */ + +#define IPA_QMAP_HEADER_LENGTH 4 + +#define IPA_WAN_AGGR_PKT_CNT 5 +#define POLLING_INACTIVITY_RX 40 +#define POLLING_MIN_SLEEP_RX 1010/* microseconds */ +#define POLLING_MAX_SLEEP_RX 1050/* microseconds */ + +#define IPA_RX_BUFFER_ORDER 1/* Default RX buffer is 2^1 pages */ +#define IPA_RX_BUFFER_SIZE (1 << (IPA_RX_BUFFER_ORDER + PAGE_SHIFT)) + +/* The amount of RX buffer space consumed by standard skb overhead */ +#define IPA_RX_BUFFER_RESERVED \ + (IPA_RX_BUFFER_SIZE - SKB_MAX_ORDER(NET_SKB_PAD, IPA_RX_BUFFER_ORDER)) + +/* RX buffer space remaining after standard overhead is consumed */ +#define IPA_RX_BUFFER_AVAILABLE (X ) ((X) - IPA_RX_BUFFER_RESERVED) + +#define IPA_RX_BUFF_CLIENT_HEADROOM 256 + +#define IPA_SIZE_DL_CSUM_META_TRAILER 8 + +#define IPA_REPL_XFER_THRESH 10 + +/* How long before sending an interrupting no-op to handle TX completions */ +#define IPA_TX_NOP_DELAY_NS (2 * 1000 * 1000)/* 2 msec */ + +static void ipa_rx_switch_to_intr_mode (struct ipa_sys_context *sys); + +static void ipa_replenish_rx_cache (struct ipa_sys_context *sys); +static void ipa_replenish_rx_work_func (struct work_struct *work); +static void ipa_wq_handle_rx (struct work_struct *work); +static void ipa_rx_common (struct ipa_sys_context *sys,u32 size); +static void ipa_cleanup_rx (struct ipa_sys_context *sys); +static int ipa_poll_gsi_pkt (struct ipa_sys_context *sys); + +static void ipa_tx_complete (struct ipa_tx_pkt_wrapper *tx_pkt) +{ +struct device *dev = ipa_ctx->dev; + +/* If DMA memory was mapped, unmap it */ +if (tx_pkt->mem.virt) { +if (tx_pkt->type ==IPA_DATA_DESC_SKB_PAGED ) +dma_unmap_page (dev, tx_pkt->mem.phys, + tx_pkt->mem.size,DMA_TO_DEVICE ); +else +dma_unmap_single (dev, tx_pkt->mem.phys, + tx_pkt->mem.size,DMA_TO_DEVICE ); + } + +if (tx_pkt->callback) + tx_pkt->callback (tx_pkt->user1, tx_pkt->user2); + +kmem_cache_free (ipa_ctx->dp->tx_pkt_wrapper_cache, tx_pkt); +} + +static void +ipa_wq_write_done_common (struct ipa_sys_context *sys, +struct ipa_tx_pkt_wrapper *tx_pkt) +{ +struct ipa_tx_pkt_wrapper *next_pkt; +int cnt; +int i; + + cnt = tx_pkt->cnt; +for (i =0 ; i < cnt; i++) { +ipa_assert (!list_empty (&sys->head_desc_list)); + +spin_lock_bh (&sys->spinlock); + + next_pkt =list_next_entry (tx_pkt, link); +list_del (&tx_pkt->link); + sys->len--; + +spin_unlock_bh (&sys->spinlock); + +ipa_tx_complete (tx_pkt); + + tx_pkt = next_pkt; + } +} + +/** +* ipa_wq_write_done() - Work function executed when TX completes +* * @done_work: work_struct used by the work queue +*/ +static void ipa_wq_write_done (struct work_struct *done_work) +{ +struct ipa_tx_pkt_wrapper *this_pkt; +struct ipa_tx_pkt_wrapper *tx_pkt; +struct ipa_sys_context *sys; + + tx_pkt = container_of(done_work, struct ipa_tx_pkt_wrapper, done_work); + sys = tx_pkt->sys; +spin_lock_bh (&sys->spinlock); + this_pkt =list_first_entry (&sys->head_desc_list, + struct ipa_tx_pkt_wrapper, link); +while (tx_pkt != this_pkt) { +spin_unlock_bh (&sys->spinlock); +ipa_wq_write_done_common (sys, this_pkt); +spin_lock_bh (&sys->spinlock); + this_pkt =list_first_entry (&sys->head_desc_list, + struct ipa_tx_pkt_wrapper, link); + } +spin_unlock_bh (&sys->spinlock); +ipa_wq_write_done_common (sys, tx_pkt); +} + +/** +* ipa_rx_poll() - Poll the rx packets from IPA hardware +* @ep_id: Endpoint to poll +* @weight: NAPI poll weight +* +* Return: The number of received packets. +*/ +int ipa_rx_poll (u32 ep_id,int weight) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; +static int total_cnt; +int cnt =0 ; + +while (cnt < weight &&ipa_ep_polling (ep)) { +int ret; + + ret =ipa_poll_gsi_pkt (ep->sys); +if (ret <0 ) +break ; + +ipa_rx_common (ep->sys, (u32 )ret); + cnt +=IPA_WAN_AGGR_PKT_CNT ; + total_cnt++; + +/* Force switch back to interrupt mode if no more packets */ +if (!ep->sys->len || total_cnt >= ep->sys->rx.pool_sz) { + total_cnt =0 ; + cnt--; +break ; + } + } + +if (cnt < weight) { + ep->client_notify (ep->priv,IPA_CLIENT_COMP_NAPI ,0 ); +ipa_rx_switch_to_intr_mode (ep->sys); + +/* Matching enable is in ipa_gsi_irq_rx_notify_cb() */ +ipa_client_remove (); + } + +return cnt; +} + +/** +* ipa_send_nop() - Send an interrupting no-op request to a producer endpoint. +* @sys: System context for the endpoint +* +* Normally an interrupt is generated upon completion of every transfer +* performed by an endpoint, but a producer endpoint can be configured +* to avoid getting these interrupts. Instead, once a transfer has been +* initiated, a no-op is scheduled to be sent after a short delay. This +* no-op request will interrupt when it is complete, and in handling that +* interrupt, previously-completed transfers will be handled as well. If +* a no-op is already scheduled, another is not initiated (there's only +* one pending at a time). +*/ +static bool ipa_send_nop (struct ipa_sys_context *sys) +{ +struct gsi_xfer_elem nop_xfer = { }; +struct ipa_tx_pkt_wrapper *nop_pkt; +u32 channel_id; + + nop_pkt =kmem_cache_zalloc (ipa_ctx->dp->tx_pkt_wrapper_cache, +GFP_KERNEL ); +if (!nop_pkt) +return false; + + nop_pkt->type =IPA_DATA_DESC ; +/* No-op packet uses no memory for data */ +INIT_WORK (&nop_pkt->done_work, ipa_wq_write_done); + nop_pkt->sys = sys; + nop_pkt->cnt =1 ; + + nop_xfer.type =GSI_XFER_ELEM_NOP ; + nop_xfer.flags =GSI_XFER_FLAG_EOT ; + nop_xfer.user_data = nop_pkt; + +spin_lock_bh (&sys->spinlock); +list_add_tail (&nop_pkt->link, &sys->head_desc_list); +spin_unlock_bh (&sys->spinlock); + + channel_id = sys->ep->channel_id; +if (!gsi_channel_queue (ipa_ctx->gsi, channel_id,1 , &nop_xfer, true)) +return true;/* Success */ + +spin_lock_bh (&sys->spinlock); +list_del (&nop_pkt->link); +spin_unlock_bh (&sys->spinlock); + +kmem_cache_free (ipa_ctx->dp->tx_pkt_wrapper_cache, nop_pkt); + +return false; +} + +/** +* ipa_send_nop_work() - Work function for sending a no-op request +* nop_work: Work structure for the request +* +* Try to send the no-op request. If it fails, arrange to try again. +*/ +static void ipa_send_nop_work (struct work_struct *nop_work) +{ +struct ipa_sys_context *sys; + + sys = container_of(nop_work, struct ipa_sys_context, tx.nop_work); + +/* If sending a no-op request fails, schedule another try */ +if (!ipa_send_nop (sys)) +queue_work (sys->wq, nop_work); +} + +/** +* ipa_nop_timer_expiry() - Timer function to schedule a no-op request +* @timer: High-resolution timer structure +* +* The delay before sending the no-op request is implemented by a +* high resolution timer, which will call this in interrupt context. +* Arrange to send the no-op in workqueue context when it expires. +*/ +static enum hrtimer_restart ipa_nop_timer_expiry (struct hrtimer *timer) +{ +struct ipa_sys_context *sys; + + sys = container_of(timer, struct ipa_sys_context, tx.nop_timer); +atomic_set (&sys->tx.nop_pending,0 ); +queue_work (sys->wq, &sys->tx.nop_work); + +return HRTIMER_NORESTART ; +} + +static void ipa_nop_timer_schedule (struct ipa_sys_context *sys) +{ +ktime_t time; + +if (atomic_xchg (&sys->tx.nop_pending,1 )) +return ; + + time =ktime_set (0 ,IPA_TX_NOP_DELAY_NS ); +hrtimer_start (&sys->tx.nop_timer, time,HRTIMER_MODE_REL ); +} + +/** +* ipa_no_intr_init() - Configure endpoint point for no-op requests +* @prod_ep_id: Endpoint that will use interrupting no-ops +* +* For some producer endpoints we don't interrupt on completions. +* Instead we schedule an interrupting NOP command to be issued on +* the endpoint after a short delay (if one is not already scheduled). +* When the NOP completes it signals all preceding transfers have +* completed also. +*/ +void ipa_no_intr_init (u32 prod_ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[prod_ep_id]; + +INIT_WORK (&ep->sys->tx.nop_work, ipa_send_nop_work); +atomic_set (&ep->sys->tx.nop_pending,0 ); +hrtimer_init (&ep->sys->tx.nop_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); + ep->sys->tx.nop_timer.function = ipa_nop_timer_expiry; + ep->sys->tx.no_intr = true; +} + +/** +* ipa_send() - Send descriptors to hardware as a single transaction +* @sys: System context for endpoint +* @num_desc: Number of descriptors +* @desc: Transfer descriptors to send +* +* Return: 0 iff successful, or a negative error code. +*/ +static int +ipa_send (struct ipa_sys_context *sys,u32 num_desc,struct ipa_desc *desc) +{ +struct ipa_tx_pkt_wrapper *tx_pkt; +struct ipa_tx_pkt_wrapper *first; +struct ipa_tx_pkt_wrapper *next; +struct gsi_xfer_elem *xfer_elem; +LIST_HEAD (pkt_list); +int ret; +int i; + +ipa_assert (num_desc); +ipa_assert (num_desc <=ipa_client_tlv_count (sys->ep->client)); + + xfer_elem =kcalloc (num_desc,sizeof (*xfer_elem),GFP_ATOMIC ); +if (!xfer_elem) +return -ENOMEM ; + +/* Within loop, all errors are allocation or DMA mapping */ + ret = -ENOMEM ; + first =NULL ; +for (i =0 ; i < num_desc; i++) { +dma_addr_t phys; + + tx_pkt =kmem_cache_zalloc (ipa_ctx->dp->tx_pkt_wrapper_cache, +GFP_ATOMIC ); +if (!tx_pkt) + goto err_unwind; + +if (!first) + first = tx_pkt; + +if (desc[i].type ==IPA_DATA_DESC_SKB_PAGED ) + phys =skb_frag_dma_map (ipa_ctx->dev, desc[i].payload, +0 , desc[i].len_opcode, +DMA_TO_DEVICE ); +else + phys =dma_map_single (ipa_ctx->dev, desc[i].payload, + desc[i].len_opcode, +DMA_TO_DEVICE ); +if (dma_mapping_error (ipa_ctx->dev, phys)) { +ipa_err ("dma mapping error on descriptor\n" ); +kmem_cache_free (ipa_ctx->dp->tx_pkt_wrapper_cache, + tx_pkt); + goto err_unwind; + } + + tx_pkt->type = desc[i].type; + tx_pkt->sys = sys; + tx_pkt->mem.virt = desc[i].payload; + tx_pkt->mem.phys = phys; + tx_pkt->mem.size = desc[i].len_opcode; + tx_pkt->callback = desc[i].callback; + tx_pkt->user1 = desc[i].user1; + tx_pkt->user2 = desc[i].user2; +list_add_tail (&tx_pkt->link, &pkt_list); + + xfer_elem[i].addr = tx_pkt->mem.phys; +if (desc[i].type ==IPA_IMM_CMD_DESC ) + xfer_elem[i].type =GSI_XFER_ELEM_IMME_CMD ; +else + xfer_elem[i].type =GSI_XFER_ELEM_DATA ; + xfer_elem[i].len_opcode = desc[i].len_opcode; +if (i < num_desc -1 ) + xfer_elem[i].flags =GSI_XFER_FLAG_CHAIN ; + } + +/* Fill in extra fields in the first TX packet */ + first->cnt = num_desc; +INIT_WORK (&first->done_work, ipa_wq_write_done); + +/* Fill in extra fields in the last transfer element */ +if (!sys->tx.no_intr) { + xfer_elem[num_desc -1 ].flags =GSI_XFER_FLAG_EOT ; + xfer_elem[num_desc -1 ].flags |=GSI_XFER_FLAG_BEI ; + } + xfer_elem[num_desc -1 ].user_data = first; + +spin_lock_bh (&sys->spinlock); + +list_splice_tail_init (&pkt_list, &sys->head_desc_list); + ret =gsi_channel_queue (ipa_ctx->gsi, sys->ep->channel_id, num_desc, + xfer_elem, true); +if (ret) +list_cut_end (&pkt_list, &sys->head_desc_list, &first->link); + +spin_unlock_bh (&sys->spinlock); + +kfree (xfer_elem); + +if (!ret) { +if (sys->tx.no_intr) +ipa_nop_timer_schedule (sys); +return 0 ; + } +err_unwind: +list_for_each_entry_safe (tx_pkt, next, &pkt_list, link) { +list_del (&tx_pkt->link); + tx_pkt->callback =NULL ;/* Avoid doing the callback */ +ipa_tx_complete (tx_pkt); + } + +return ret; +} + +/** +* ipa_send_cmd_timeout_complete() - Command completion callback +* @user1: Opaque value carried by the command +* @ignored: Second opaque value (ignored) +* +* Schedule a completion to signal that a command is done. Free the +* tag_completion structure if its reference count reaches zero. +*/ +static void ipa_send_cmd_timeout_complete (void *user1,int ignored) +{ +struct ipa_tag_completion *comp = user1; + +complete (&comp->comp); +if (!atomic_dec_return (&comp->cnt)) +kfree (comp); +} + +/** +* ipa_send_cmd_timeout() - Send an immediate command with timeout +* @desc: descriptor structure +* @timeout: milliseconds to wait (or 0 to wait indefinitely) +* +* Send an immediate command, and wait for it to complete. If +* timeout is non-zero it indicates the number of milliseconds to +* wait to receive the acknowledgment from the hardware before +* timing out. If 0 is supplied, wait will not time out. +* +* Return: 0 if successful, or a negative error code +*/ +int ipa_send_cmd_timeout (struct ipa_desc *desc,u32 timeout) +{ +struct ipa_tag_completion *comp; +unsigned long timeout_jiffies; +struct ipa_ep_context *ep; +int ret; + + comp =kzalloc (sizeof (*comp),GFP_KERNEL ); +if (!comp) +return -ENOMEM ; + +/* The reference count is decremented both here and in ack +* callback. Whichever reaches 0 frees the structure. +*/ +atomic_set (&comp->cnt,2 ); +init_completion (&comp->comp); + +/* Fill in the callback info (the sole descriptor is the last) */ + desc->callback = ipa_send_cmd_timeout_complete; + desc->user1 = comp; + + ep = &ipa_ctx->ep[ipa_client_ep_id (IPA_CLIENT_APPS_CMD_PROD )]; + ret =ipa_send (ep->sys,1 , desc); +if (ret) { +/* Callback won't run; drop reference on its behalf */ +atomic_dec (&comp->cnt); + goto out; + } + + timeout_jiffies =msecs_to_jiffies (timeout); +if (!timeout_jiffies) { +wait_for_completion (&comp->comp); + }else if (!wait_for_completion_timeout (&comp->comp, timeout_jiffies)) { + ret = -ETIMEDOUT ; +ipa_err ("command timed out\n" ); + } +out: +if (!atomic_dec_return (&comp->cnt)) +kfree (comp); + +return ret; +} + +/** +* ipa_handle_rx_core() - Core packet reception handling +* @sys: System context for endpoint receiving packets +* +* Return: The number of packets processed, or a negative error code +*/ +static int ipa_handle_rx_core (struct ipa_sys_context *sys) +{ +int cnt; + +/* Stop if the endpoint leaves polling state */ + cnt =0 ; +while (ipa_ep_polling (sys->ep)) { +int ret =ipa_poll_gsi_pkt (sys); + +if (ret <0 ) +break ; + +ipa_rx_common (sys, (u32 )ret); + + cnt++; + } + +return cnt; +} + +/** +* ipa_rx_switch_to_intr_mode() - Switch from polling to interrupt mode +* @sys: System context for endpoint switching mode +*/ +static void ipa_rx_switch_to_intr_mode (struct ipa_sys_context *sys) +{ +if (!atomic_xchg (&sys->rx.curr_polling_state,0 )) { +ipa_err ("already in intr mode\n" ); +queue_delayed_work (sys->wq, &sys->rx.switch_to_intr_work, +msecs_to_jiffies (1 )); +return ; + } +ipa_dec_release_wakelock (); +gsi_channel_intr_enable (ipa_ctx->gsi, sys->ep->channel_id); +} + +void ipa_rx_switch_to_poll_mode (struct ipa_sys_context *sys) +{ +if (atomic_xchg (&sys->rx.curr_polling_state,1 )) +return ; +gsi_channel_intr_disable (ipa_ctx->gsi, sys->ep->channel_id); +ipa_inc_acquire_wakelock (); +queue_work (sys->wq, &sys->rx.work); +} + +/** +* ipa_handle_rx() - Handle packet reception. +* @sys: System context for endpoint receiving packets +*/ +static void ipa_handle_rx (struct ipa_sys_context *sys) +{ +int inactive_cycles =0 ; +int cnt; + +ipa_client_add (); +do { + cnt =ipa_handle_rx_core (sys); +if (cnt ==0 ) + inactive_cycles++; +else + inactive_cycles =0 ; + +usleep_range (POLLING_MIN_SLEEP_RX ,POLLING_MAX_SLEEP_RX ); + +/* if endpoint is out of buffers there is no point polling for +* completed descs; release the worker so delayed work can +* run in a timely manner +*/ +if (sys->len - sys->rx.len_pending_xfer ==0 ) +break ; + + }while (inactive_cycles <=POLLING_INACTIVITY_RX ); + +ipa_rx_switch_to_intr_mode (sys); +ipa_client_remove (); +} + +static void ipa_switch_to_intr_rx_work_func (struct work_struct *work) +{ +struct delayed_work *dwork =to_delayed_work (work); +struct ipa_sys_context *sys; + + sys = container_of(dwork, struct ipa_sys_context, + rx.switch_to_intr_work); + +/* For NAPI, interrupt mode is done in ipa_rx_poll context */ +ipa_assert (!sys->ep->napi_enabled); + +ipa_handle_rx (sys); +} + +static struct ipa_sys_context *ipa_ep_sys_create (enum ipa_client_type client) +{ +const unsigned int wq_flags =WQ_MEM_RECLAIM |WQ_UNBOUND ; +struct ipa_sys_context *sys; + +/* Caller will zero all "mutable" fields; we fill in the rest */ + sys =kmalloc (sizeof (*sys),GFP_KERNEL ); +if (!sys) +return NULL ; + + sys->wq =alloc_workqueue ("ipawq%u" , wq_flags,1 , (u32 )client); +if (!sys->wq) { +kfree (sys); +return NULL ; + } + +/* Caller assigns sys->ep = ep */ +INIT_LIST_HEAD (&sys->head_desc_list); +spin_lock_init (&sys->spinlock); + +return sys; +} + +/** +* ipa_tx_dp_complete() - Transmit complete callback +* @user1: Caller-supplied pointer value +* @user2: Caller-supplied integer value +* +* Calls the endpoint's client_notify function if it exists; +* otherwise just frees the socket buffer (supplied in user1). +*/ +static void ipa_tx_dp_complete (void *user1,int user2) +{ +struct sk_buff *skb = user1; +int ep_id = user2; + +if (ipa_ctx->ep[ep_id].client_notify) { +unsigned long data; +void *priv; + + priv = ipa_ctx->ep[ep_id].priv; + data = (unsigned long )skb; + ipa_ctx->ep[ep_id].client_notify (priv,IPA_WRITE_DONE , data); + }else { +dev_kfree_skb_any (skb); + } +} + +/** +* ipa_tx_dp() - Transmit a socket buffer for APPS_WAN_PROD +* @client: IPA client that is sending packets (WAN producer) +* @skb: The socket buffer to send +* +* Returns: 0 if successful, or a negative error code +*/ +int ipa_tx_dp (enum ipa_client_type client,struct sk_buff *skb) +{ +struct ipa_desc _desc = { };/* Used for common case */ +struct ipa_desc *desc; +u32 tlv_count; +int data_idx; +u32 nr_frags; +u32 ep_id; +int ret; +u32 f; + +if (!skb->len) +return -EINVAL ; + + ep_id =ipa_client_ep_id (client); + +/* Make sure source endpoint's TLV FIFO has enough entries to +* hold the linear portion of the skb and all its frags. +* If not, see if we can linearize it before giving up. +*/ + nr_frags =skb_shinfo (skb)->nr_frags; + tlv_count =ipa_client_tlv_count (client); +if (1 + nr_frags > tlv_count) { +if (skb_linearize (skb)) +return -ENOMEM ; + nr_frags =0 ; + } +if (nr_frags) { + desc =kcalloc (1 + nr_frags,sizeof (*desc),GFP_ATOMIC ); +if (!desc) +return -ENOMEM ; + }else { + desc = &_desc;/* Default, linear case */ + } + +/* Fill in the IPA request descriptors--one for the linear +* data in the skb, one each for each of its fragments. +*/ + data_idx =0 ; + desc[data_idx].payload = skb->data; + desc[data_idx].len_opcode =skb_headlen (skb); + desc[data_idx].type =IPA_DATA_DESC_SKB ; +for (f =0 ; f < nr_frags; f++) { + data_idx++; + desc[data_idx].payload = &skb_shinfo (skb)->frags[f]; + desc[data_idx].type =IPA_DATA_DESC_SKB_PAGED ; + desc[data_idx].len_opcode = +skb_frag_size (desc[data_idx].payload); + } + +/* Have the skb be freed after the last descriptor completes. */ + desc[data_idx].callback = ipa_tx_dp_complete; + desc[data_idx].user1 = skb; + desc[data_idx].user2 = ep_id; + + ret =ipa_send (ipa_ctx->ep[ep_id].sys, data_idx +1 , desc); + +if (nr_frags) +kfree (desc); + +return ret; +} + +static void ipa_wq_handle_rx (struct work_struct *work) +{ +struct ipa_sys_context *sys; + + sys = container_of(work, struct ipa_sys_context, rx.work); + +if (sys->ep->napi_enabled) { +ipa_client_add (); + sys->ep->client_notify (sys->ep->priv,IPA_CLIENT_START_POLL ,0 ); + }else { +ipa_handle_rx (sys); + } +} + +static int +queue_rx_cache (struct ipa_sys_context *sys,struct ipa_rx_pkt_wrapper *rx_pkt) +{ +struct gsi_xfer_elem gsi_xfer_elem; +bool ring_doorbell; +int ret; + +/* Don't bother zeroing this; we fill all fields */ + gsi_xfer_elem.addr = rx_pkt->dma_addr; + gsi_xfer_elem.len_opcode = sys->rx.buff_sz; + gsi_xfer_elem.flags =GSI_XFER_FLAG_EOT ; + gsi_xfer_elem.flags |=GSI_XFER_FLAG_EOB ; + gsi_xfer_elem.type =GSI_XFER_ELEM_DATA ; + gsi_xfer_elem.user_data = rx_pkt; + +/* Doorbell is expensive; only ring it when a batch is queued */ + ring_doorbell = sys->rx.len_pending_xfer++ >=IPA_REPL_XFER_THRESH ; + + ret =gsi_channel_queue (ipa_ctx->gsi, sys->ep->channel_id, +1 , &gsi_xfer_elem, ring_doorbell); +if (ret) +return ret; + +if (ring_doorbell) + sys->rx.len_pending_xfer =0 ; + +return 0 ; +} + +/** +* ipa_replenish_rx_cache() - Replenish the Rx packets cache. +* @sys: System context for IPA->AP endpoint +* +* Allocate RX packet wrapper structures with maximal socket buffers +* for an endpoint. These are supplied to the hardware, which fills +* them with incoming data. +*/ +static void ipa_replenish_rx_cache (struct ipa_sys_context *sys) +{ +struct ipa_rx_pkt_wrapper *rx_pkt; +struct device *dev = ipa_ctx->dev; +u32 rx_len_cached = sys->len; + +while (rx_len_cached < sys->rx.pool_sz) { +gfp_t flag =GFP_NOWAIT | __GFP_NOWARN; +void *ptr; +int ret; + + rx_pkt =kmem_cache_zalloc (ipa_ctx->dp->rx_pkt_wrapper_cache, + flag); +if (!rx_pkt) + goto fail_kmem_cache_alloc; + +INIT_LIST_HEAD (&rx_pkt->link); + + rx_pkt->skb =__dev_alloc_skb (sys->rx.buff_sz, flag); +if (!rx_pkt->skb) { +ipa_err ("failed to alloc skb\n" ); + goto fail_skb_alloc; + } + ptr =skb_put (rx_pkt->skb, sys->rx.buff_sz); + rx_pkt->dma_addr =dma_map_single (dev, ptr, sys->rx.buff_sz, +DMA_FROM_DEVICE ); +if (dma_mapping_error (dev, rx_pkt->dma_addr)) { +ipa_err ("dma_map_single failure %p for %p\n" , + (void *)rx_pkt->dma_addr, ptr); + goto fail_dma_mapping; + } + +list_add_tail (&rx_pkt->link, &sys->head_desc_list); + rx_len_cached = ++sys->len; + + ret =queue_rx_cache (sys, rx_pkt); +if (ret) + goto fail_provide_rx_buffer; + } + +return ; + +fail_provide_rx_buffer: +list_del (&rx_pkt->link); + rx_len_cached = --sys->len; +dma_unmap_single (dev, rx_pkt->dma_addr, sys->rx.buff_sz, +DMA_FROM_DEVICE ); +fail_dma_mapping: +dev_kfree_skb_any (rx_pkt->skb); +fail_skb_alloc: +kmem_cache_free (ipa_ctx->dp->rx_pkt_wrapper_cache, rx_pkt); +fail_kmem_cache_alloc: +if (rx_len_cached - sys->rx.len_pending_xfer ==0 ) +queue_delayed_work (sys->wq, &sys->rx.replenish_work, +msecs_to_jiffies (1 )); +} + +static void ipa_replenish_rx_work_func (struct work_struct *work) +{ +struct delayed_work *dwork =to_delayed_work (work); +struct ipa_sys_context *sys; + + sys = container_of(dwork, struct ipa_sys_context, rx.replenish_work); +ipa_client_add (); +ipa_replenish_rx_cache (sys); +ipa_client_remove (); +} + +/** ipa_cleanup_rx() - release RX queue resources */ +static void ipa_cleanup_rx (struct ipa_sys_context *sys) +{ +struct ipa_rx_pkt_wrapper *rx_pkt; +struct ipa_rx_pkt_wrapper *r; + +list_for_each_entry_safe (rx_pkt, r, &sys->head_desc_list, link) { +list_del (&rx_pkt->link); +dma_unmap_single (ipa_ctx->dev, rx_pkt->dma_addr, + sys->rx.buff_sz,DMA_FROM_DEVICE ); +dev_kfree_skb_any (rx_pkt->skb); +kmem_cache_free (ipa_ctx->dp->rx_pkt_wrapper_cache, rx_pkt); + } +} + +static struct sk_buff *ipa_skb_copy_for_client (struct sk_buff *skb,int len) +{ +struct sk_buff *skb2; + + skb2 =__dev_alloc_skb (len +IPA_RX_BUFF_CLIENT_HEADROOM ,GFP_KERNEL ); +if (likely (skb2)) { +/* Set the data pointer */ +skb_reserve (skb2,IPA_RX_BUFF_CLIENT_HEADROOM ); +memcpy (skb2->data, skb->data, len); + skb2->len = len; +skb_set_tail_pointer (skb2, len); + } + +return skb2; +} + +static struct sk_buff *ipa_join_prev_skb (struct sk_buff *prev_skb, +struct sk_buff *skb,unsigned int len) +{ +struct sk_buff *skb2; + + skb2 =skb_copy_expand (prev_skb,0 , len,GFP_KERNEL ); +if (likely (skb2)) +memcpy (skb_put (skb2, len), skb->data, len); +else +ipa_err ("copy expand failed\n" ); +dev_kfree_skb_any (prev_skb); + +return skb2; +} + +static bool ipa_status_opcode_supported (enum ipahal_pkt_status_opcode opcode) +{ +return opcode ==IPAHAL_PKT_STATUS_OPCODE_PACKET || + opcode ==IPAHAL_PKT_STATUS_OPCODE_DROPPED_PACKET || + opcode ==IPAHAL_PKT_STATUS_OPCODE_SUSPENDED_PACKET || + opcode ==IPAHAL_PKT_STATUS_OPCODE_PACKET_2ND_PASS ; +} + +static void +ipa_lan_rx_pyld_hdlr (struct sk_buff *skb,struct ipa_sys_context *sys) +{ +struct ipahal_pkt_status status; +struct sk_buff *skb2; +unsigned long unused; +unsigned int align; +unsigned int used; +unsigned char *buf; +u32 pkt_status_sz; +int pad_len_byte; +u32 ep_id; +int len; +int len2; + + pkt_status_sz =ipahal_pkt_status_get_size (); + used = *(unsigned int *)skb->cb; + align =ALIGN (used,32 ); + unused =IPA_RX_BUFFER_SIZE - used; + +ipa_assert (skb->len); + +if (sys->rx.len_partial) { + buf =skb_push (skb, sys->rx.len_partial); +memcpy (buf, sys->rx.prev_skb->data, sys->rx.len_partial); + sys->rx.len_partial =0 ; +dev_kfree_skb_any (sys->rx.prev_skb); + sys->rx.prev_skb =NULL ; + goto begin; + } + +/* this endpoint has TX comp (status only) + mux-ed LAN RX data +* (status+data) +*/ +if (sys->rx.len_rem) { +if (sys->rx.len_rem <= skb->len) { +if (sys->rx.prev_skb) { + skb2 =skb_copy_expand (sys->rx.prev_skb,0 , + sys->rx.len_rem, +GFP_KERNEL ); +if (likely (skb2)) { +memcpy (skb_put (skb2, sys->rx.len_rem), + skb->data, sys->rx.len_rem); +skb_trim (skb2, + skb2->len - sys->rx.len_pad); + skb2->truesize = skb2->len + +sizeof (struct sk_buff ); +if (sys->rx.drop_packet) +dev_kfree_skb_any (skb2); +else + sys->ep->client_notify ( + sys->ep->priv, +IPA_RECEIVE , + (unsigned long )(skb2)); + }else { +ipa_err ("copy expand failed\n" ); + } +dev_kfree_skb_any (sys->rx.prev_skb); + } +skb_pull (skb, sys->rx.len_rem); + sys->rx.prev_skb =NULL ; + sys->rx.len_rem =0 ; + sys->rx.len_pad =0 ; + }else { +if (sys->rx.prev_skb) { + skb2 =ipa_join_prev_skb (sys->rx.prev_skb, skb, + skb->len); +dev_kfree_skb_any (sys->rx.prev_skb); + sys->rx.prev_skb = skb2; + } + sys->rx.len_rem -= skb->len; +return ; + } + } + +begin: +while (skb->len) { + sys->rx.drop_packet = false; + +if (skb->len < pkt_status_sz) { +WARN_ON (sys->rx.prev_skb); + sys->rx.prev_skb =skb_copy (skb,GFP_KERNEL ); + sys->rx.len_partial = skb->len; +return ; + } + +ipahal_pkt_status_parse (skb->data, &status); + +if (!ipa_status_opcode_supported (status.status_opcode)) { +ipa_err ("unsupported opcode(%d)\n" , + status.status_opcode); +skb_pull (skb, pkt_status_sz); +continue ; + } + +if (status.pkt_len ==0 ) { +skb_pull (skb, pkt_status_sz); +continue ; + } + +if (status.endp_dest_idx == (sys->ep - ipa_ctx->ep)) { +/* RX data */ + ep_id = status.endp_src_idx; + +/* A packet which is received back to the AP after +* there was no route match. +*/ + +if (status.exception == +IPAHAL_PKT_STATUS_EXCEPTION_NONE && + status.rt_miss) + sys->rx.drop_packet = true; +if (skb->len == pkt_status_sz && + status.exception == +IPAHAL_PKT_STATUS_EXCEPTION_NONE ) { +WARN_ON (sys->rx.prev_skb); + sys->rx.prev_skb =skb_copy (skb,GFP_KERNEL ); + sys->rx.len_partial = skb->len; +return ; + } + + pad_len_byte = ((status.pkt_len +3 ) & ~3 ) - + status.pkt_len; + + len = status.pkt_len + pad_len_byte + +IPA_SIZE_DL_CSUM_META_TRAILER ; + +if (status.exception == +IPAHAL_PKT_STATUS_EXCEPTION_DEAGGR ) { + sys->rx.drop_packet = true; + } + + len2 =min (status.pkt_len + pkt_status_sz, skb->len); + skb2 =ipa_skb_copy_for_client (skb, len2); +if (likely (skb2)) { +if (skb->len < len + pkt_status_sz) { + sys->rx.prev_skb = skb2; + sys->rx.len_rem = len - skb->len + + pkt_status_sz; + sys->rx.len_pad = pad_len_byte; +skb_pull (skb, skb->len); + }else { +skb_trim (skb2, status.pkt_len + + pkt_status_sz); +if (sys->rx.drop_packet) { +dev_kfree_skb_any (skb2); + }else { + skb2->truesize = + skb2->len + +sizeof (struct sk_buff ) + + (ALIGN (len + + pkt_status_sz,32 ) * + unused / align); + sys->ep->client_notify ( + sys->ep->priv, +IPA_RECEIVE , + (unsigned long )(skb2)); + } +skb_pull (skb, len + pkt_status_sz); + } + }else { +ipa_err ("fail to alloc skb\n" ); +if (skb->len < len) { + sys->rx.prev_skb =NULL ; + sys->rx.len_rem = len - skb->len + + pkt_status_sz; + sys->rx.len_pad = pad_len_byte; +skb_pull (skb, skb->len); + }else { +skb_pull (skb, len + pkt_status_sz); + } + } + }else { +skb_pull (skb, pkt_status_sz); + } + } +} + +static void +ipa_wan_rx_handle_splt_pyld (struct sk_buff *skb,struct ipa_sys_context *sys) +{ +struct sk_buff *skb2; + +if (sys->rx.len_rem <= skb->len) { +if (sys->rx.prev_skb) { + skb2 =ipa_join_prev_skb (sys->rx.prev_skb, skb, + sys->rx.len_rem); +if (likely (skb2)) { +skb_pull (skb2,ipahal_pkt_status_get_size ()); + skb2->truesize = skb2->len + +sizeof (struct sk_buff ); + sys->ep->client_notify (sys->ep->priv, +IPA_RECEIVE , + (unsigned long )skb2); + } + } +skb_pull (skb, sys->rx.len_rem); + sys->rx.prev_skb =NULL ; + sys->rx.len_rem =0 ; + }else { +if (sys->rx.prev_skb) { + skb2 =ipa_join_prev_skb (sys->rx.prev_skb, skb, + skb->len); + sys->rx.prev_skb = skb2; + } + sys->rx.len_rem -= skb->len; +skb_pull (skb, skb->len); + } +} + +static void +ipa_wan_rx_pyld_hdlr (struct sk_buff *skb,struct ipa_sys_context *sys) +{ +struct ipahal_pkt_status status; +unsigned char *skb_data; +struct sk_buff *skb2; +u16 pkt_len_with_pad; +unsigned long unused; +unsigned int align; +unsigned int used; +u32 pkt_status_sz; +int frame_len; +u32 qmap_hdr; +int checksum; +int ep_id; + + used = *(unsigned int *)skb->cb; + align =ALIGN (used,32 ); + unused =IPA_RX_BUFFER_SIZE - used; + +ipa_assert (skb->len); + +if (ipa_ctx->ipa_client_apps_wan_cons_agg_gro) { + sys->ep->client_notify (sys->ep->priv,IPA_RECEIVE , + (unsigned long )(skb)); +return ; + } + +/* payload splits across 2 buff or more, +* take the start of the payload from rx.prev_skb +*/ +if (sys->rx.len_rem) +ipa_wan_rx_handle_splt_pyld (skb, sys); + + pkt_status_sz =ipahal_pkt_status_get_size (); +while (skb->len) { +u32 status_mask; + +if (skb->len < pkt_status_sz) { +ipa_err ("status straddles buffer\n" ); +WARN_ON (1 ); + goto bail; + } +ipahal_pkt_status_parse (skb->data, &status); + skb_data = skb->data; + +if (!ipa_status_opcode_supported (status.status_opcode) || + status.status_opcode == +IPAHAL_PKT_STATUS_OPCODE_SUSPENDED_PACKET ) { +ipa_err ("unsupported opcode(%d)\n" , + status.status_opcode); +skb_pull (skb, pkt_status_sz); +continue ; + } + +if (status.endp_dest_idx >= ipa_ctx->ep_count || + status.endp_src_idx >= ipa_ctx->ep_count || + status.pkt_len >IPA_GENERIC_AGGR_BYTE_LIMIT ) { +ipa_err ("status fields invalid\n" ); +WARN_ON (1 ); + goto bail; + } +if (status.pkt_len ==0 ) { +skb_pull (skb, pkt_status_sz); +continue ; + } + ep_id =ipa_client_ep_id (IPA_CLIENT_APPS_WAN_CONS ); +if (status.endp_dest_idx != ep_id) { +ipa_err ("expected endp_dest_idx %d received %d\n" , + ep_id, status.endp_dest_idx); +WARN_ON (1 ); + goto bail; + } +/* RX data */ +if (skb->len == pkt_status_sz) { +ipa_err ("Ins header in next buffer\n" ); +WARN_ON (1 ); + goto bail; + } + qmap_hdr = *(u32 *)(skb_data + pkt_status_sz); + +/* Take the pkt_len_with_pad from the last 2 bytes of the QMAP +* header +*/ +/*QMAP is BE: convert the pkt_len field from BE to LE*/ + pkt_len_with_pad =ntohs ((qmap_hdr >>16 ) &0xffff ); +/*get the CHECKSUM_PROCESS bit*/ + status_mask = status.status_mask; + checksum = status_mask &IPAHAL_PKT_STATUS_MASK_CKSUM_PROCESS ; + + frame_len = pkt_status_sz +IPA_QMAP_HEADER_LENGTH + + pkt_len_with_pad; +if (checksum) + frame_len +=IPA_DL_CHECKSUM_LENGTH ; + + skb2 =skb_clone (skb,GFP_ATOMIC ); +if (likely (skb2)) { +/* the len of actual data is smaller than expected +* payload split across 2 buff +*/ +if (skb->len < frame_len) { + sys->rx.prev_skb = skb2; + sys->rx.len_rem = frame_len - skb->len; +skb_pull (skb, skb->len); + }else { +skb_trim (skb2, frame_len); +skb_pull (skb2, pkt_status_sz); + skb2->truesize = skb2->len + +sizeof (struct sk_buff ) + + (ALIGN (frame_len,32 ) * + unused / align); + sys->ep->client_notify (sys->ep->priv, +IPA_RECEIVE , + (unsigned long )(skb2)); +skb_pull (skb, frame_len); + } + }else { +ipa_err ("fail to clone\n" ); +if (skb->len < frame_len) { + sys->rx.prev_skb =NULL ; + sys->rx.len_rem = frame_len - skb->len; +skb_pull (skb, skb->len); + }else { +skb_pull (skb, frame_len); + } + } + } +bail: +dev_kfree_skb_any (skb); +} + +void ipa_lan_rx_cb (void *priv,enum ipa_dp_evt_type evt,unsigned long data) +{ +struct sk_buff *rx_skb = (struct sk_buff *)data; +struct ipahal_pkt_status status; +struct ipa_ep_context *ep; +u32 pkt_status_size; +u32 metadata; +u32 ep_id; + + pkt_status_size =ipahal_pkt_status_get_size (); + +ipa_assert (rx_skb->len >= pkt_status_size); + +ipahal_pkt_status_parse (rx_skb->data, &status); + ep_id = status.endp_src_idx; + metadata = status.metadata; + ep = &ipa_ctx->ep[ep_id]; +if (ep_id >= ipa_ctx->ep_count || !ep->allocated || + !ep->client_notify) { +ipa_err ("drop endpoint=%u allocated=%s client_notify=%p\n" , + ep_id, ep->allocated ?"true" :"false" , + ep->client_notify); +dev_kfree_skb_any (rx_skb); +return ; + } + +/* Consume the status packet, and if no exception, the header */ +skb_pull (rx_skb, pkt_status_size); +if (status.exception ==IPAHAL_PKT_STATUS_EXCEPTION_NONE ) +skb_pull (rx_skb,IPA_LAN_RX_HEADER_LENGTH ); + +/* Metadata Info +* ------------------------------------------ +* | 3 | 2 | 1 | 0 | +* | fw_desc | vdev_id | qmap mux id | Resv | +* ------------------------------------------ +*/ + *(u16 *)rx_skb->cb = ((metadata >>16 ) &0xffff ); + + ep->client_notify (ep->priv,IPA_RECEIVE , (unsigned long )rx_skb); +} + +static void ipa_rx_common (struct ipa_sys_context *sys,u32 size) +{ +struct ipa_rx_pkt_wrapper *rx_pkt; +struct sk_buff *rx_skb; + +ipa_assert (!list_empty (&sys->head_desc_list)); + +spin_lock_bh (&sys->spinlock); + + rx_pkt =list_first_entry (&sys->head_desc_list, + struct ipa_rx_pkt_wrapper, link); +list_del (&rx_pkt->link); + sys->len--; + +spin_unlock_bh (&sys->spinlock); + + rx_skb = rx_pkt->skb; +dma_unmap_single (ipa_ctx->dev, rx_pkt->dma_addr, sys->rx.buff_sz, +DMA_FROM_DEVICE ); + +skb_trim (rx_skb, size); + + *(unsigned int *)rx_skb->cb = rx_skb->len; + rx_skb->truesize = size +sizeof (struct sk_buff ); + + sys->rx.pyld_hdlr (rx_skb, sys); +kmem_cache_free (ipa_ctx->dp->rx_pkt_wrapper_cache, rx_pkt); +ipa_replenish_rx_cache (sys); +} + +/** +* ipa_aggr_byte_limit_buf_size() +* @byte_limit: Desired limit (in bytes) for aggregation +* +* Compute the buffer size required to support a requested aggregation +* byte limit. Aggregration will close when *more* than the configured +* number of bytes have been added to an aggregation frame. Our +* buffers therefore need to to be big enough to receive one complete +* packet once the configured byte limit has been consumed. +* +* An incoming packet can have as much as IPA_MTU of data in it, but +* the buffer also needs to be large enough to accomodate the standard +* socket buffer overhead (NET_SKB_PAD of headroom, plus an implied +* skb_shared_info structure at the end). +* +* So we compute the required buffer size by adding the standard +* socket buffer overhead and MTU to the requested size. We round +* that down to a power of 2 in an effort to avoid fragmentation due +* to unaligned buffer sizes. +* +* After accounting for all of this, we return the number of bytes +* of buffer space the IPA hardware will know is available to hold +* received data (without any overhead). +* +* Return: The computes size of buffer space available +*/ +u32 ipa_aggr_byte_limit_buf_size (u32 byte_limit) +{ +/* Account for one additional packet, including overhead */ + byte_limit +=IPA_RX_BUFFER_RESERVED ; + byte_limit +=IPA_MTU ; + +/* Convert this size to a nearby power-of-2. We choose one +* that's *less than* the limit we seek--so we start by +* subracting 1. The highest set bit in that is used to +* compute the power of 2. +* +* XXX Why is this *less than* and not possibly equal? +*/ + byte_limit =1 <<__fls (byte_limit -1 ); + +/* Given that size, figure out how much buffer space that +* leaves us for received data. +*/ +return IPA_RX_BUFFER_AVAILABLE (byte_limit); +} + +void ipa_gsi_irq_tx_notify_cb (void *xfer_data) +{ +struct ipa_tx_pkt_wrapper *tx_pkt = xfer_data; + +queue_work (tx_pkt->sys->wq, &tx_pkt->done_work); +} + +void ipa_gsi_irq_rx_notify_cb (void *chan_data,u16 count) +{ +struct ipa_sys_context *sys = chan_data; + + sys->ep->bytes_xfered_valid = true; + sys->ep->bytes_xfered = count; + +ipa_rx_switch_to_poll_mode (sys); +} + +static int ipa_gsi_setup_channel (struct ipa_ep_context *ep,u32 channel_count, +u32 evt_ring_mult) +{ +u32 channel_id =ipa_client_channel_id (ep->client); +u32 tlv_count =ipa_client_tlv_count (ep->client); +bool from_ipa =ipa_consumer (ep->client); +bool moderation; +bool priority; +int ret; + + priority = ep->client ==IPA_CLIENT_APPS_CMD_PROD ; + moderation = !ep->sys->tx.no_intr; + + ret =gsi_channel_alloc (ipa_ctx->gsi, channel_id, channel_count, + from_ipa, priority, evt_ring_mult, moderation, + ep->sys); +if (ret) +return ret; + ep->channel_id = channel_id; + +gsi_channel_scratch_write (ipa_ctx->gsi, ep->channel_id, tlv_count); + + ret =gsi_channel_start (ipa_ctx->gsi, ep->channel_id); +if (ret) +gsi_channel_free (ipa_ctx->gsi, ep->channel_id); + +return ret; +} + +void ipa_endp_init_hdr_cons (u32 ep_id,u32 header_size, +u32 metadata_offset,u32 length_offset) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_hdr_cons (&ep->init_hdr, header_size, metadata_offset, + length_offset); +} + +void ipa_endp_init_hdr_prod (u32 ep_id,u32 header_size, +u32 metadata_offset,u32 length_offset) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_hdr_prod (&ep->init_hdr, header_size, metadata_offset, + length_offset); +} + +void +ipa_endp_init_hdr_ext_cons (u32 ep_id,u32 pad_align,bool pad_included) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_hdr_ext_cons (&ep->hdr_ext, pad_align, pad_included); +} + +void ipa_endp_init_hdr_ext_prod (u32 ep_id,u32 pad_align) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_hdr_ext_prod (&ep->hdr_ext, pad_align); +} + +void +ipa_endp_init_aggr_cons (u32 ep_id,u32 size,u32 count,bool close_on_eof) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_aggr_cons (&ep->init_aggr, size, count, close_on_eof); +} + +void ipa_endp_init_aggr_prod (u32 ep_id,enum ipa_aggr_en aggr_en, +enum ipa_aggr_type aggr_type) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_aggr_prod (&ep->init_aggr, aggr_en, aggr_type); +} + +void ipa_endp_init_cfg_cons (u32 ep_id,enum ipa_cs_offload_en offload_type) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_cfg_cons (&ep->init_cfg, offload_type); +} + +void ipa_endp_init_cfg_prod (u32 ep_id,enum ipa_cs_offload_en offload_type, +u32 metadata_offset) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_cfg_prod (&ep->init_cfg, offload_type, + metadata_offset); +} + +void ipa_endp_init_hdr_metadata_mask_cons (u32 ep_id,u32 mask) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_hdr_metadata_mask_cons (&ep->metadata_mask, mask); +} + +void ipa_endp_init_hdr_metadata_mask_prod (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_hdr_metadata_mask_prod (&ep->metadata_mask); +} + +void ipa_endp_status_cons (u32 ep_id,bool enable) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_status_cons (&ep->status, enable); +} + +void ipa_endp_status_prod (u32 ep_id,bool enable, +enum ipa_client_type status_client) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; +u32 status_ep_id; + + status_ep_id =ipa_client_ep_id (status_client); + +ipa_reg_endp_status_prod (&ep->status, enable, status_ep_id); +} + + +/* Note that the mode setting is not valid for consumer endpoints */ +void ipa_endp_init_mode_cons (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_mode_cons (&ep->init_mode); +} + +void ipa_endp_init_mode_prod (u32 ep_id,enum ipa_mode mode, +enum ipa_client_type dst_client) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; +u32 dst_ep_id; + + dst_ep_id =ipa_client_ep_id (dst_client); + +ipa_reg_endp_init_mode_prod (&ep->init_mode, mode, dst_ep_id); +} + +/* XXX The sequencer setting seems not to be valid for consumer endpoints */ +void ipa_endp_init_seq_cons (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_seq_cons (&ep->init_seq); +} + +void ipa_endp_init_seq_prod (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; +u32 seq_type; + + seq_type = (u32 )ipa_endp_seq_type (ep_id); + +ipa_reg_endp_init_seq_prod (&ep->init_seq, seq_type); +} + +/* XXX The deaggr setting seems not to be valid for consumer endpoints */ +void ipa_endp_init_deaggr_cons (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_deaggr_cons (&ep->init_deaggr); +} + +void ipa_endp_init_deaggr_prod (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_reg_endp_init_deaggr_prod (&ep->init_deaggr); +} + +int ipa_ep_alloc (enum ipa_client_type client) +{ +u32 ep_id =ipa_client_ep_id (client); +struct ipa_sys_context *sys; +struct ipa_ep_context *ep; + + ep = &ipa_ctx->ep[ep_id]; + +ipa_assert (!ep->allocated); + +/* Reuse the endpoint's sys pointer if it is initialized */ + sys = ep->sys; +if (!sys) { + sys =ipa_ep_sys_create (client); +if (!sys) +return -ENOMEM ; + sys->ep = ep; + } + +/* Zero the "mutable" part of the system context */ +memset (sys,0 , offsetof(struct ipa_sys_context , ep)); + +/* Initialize the endpoint context */ +memset (ep,0 ,sizeof (*ep)); + ep->sys = sys; + ep->client = client; + ep->allocated = true; + +return ep_id; +} + +void ipa_ep_free (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; + +ipa_assert (ep->allocated); + + ep->allocated = false; +} + +/** +* ipa_ep_setup() - Set up an IPA endpoint +* @ep_id: Endpoint to set up +* @channel_count: Number of transfer elements in the channel +* @evt_ring_mult: Used to determine number of elements in event ring +* @rx_buffer_size: Receive buffer size to use (or 0 for TX endpoitns) +* @client_notify: Notify function to call on completion +* @priv: Value supplied to the notify function +* +* Returns: 0 if successful, or a negative error code +*/ +int ipa_ep_setup (u32 ep_id,u32 channel_count,u32 evt_ring_mult, +u32 rx_buffer_size, +void (*client_notify)(void *priv,enum ipa_dp_evt_type type, +unsigned long data), +void *priv) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; +int ret; + +if (ipa_consumer (ep->client)) { +atomic_set (&ep->sys->rx.curr_polling_state,0 ); +INIT_DELAYED_WORK (&ep->sys->rx.switch_to_intr_work, + ipa_switch_to_intr_rx_work_func); +if (ep->client ==IPA_CLIENT_APPS_LAN_CONS ) + ep->sys->rx.pyld_hdlr = ipa_lan_rx_pyld_hdlr; +else + ep->sys->rx.pyld_hdlr = ipa_wan_rx_pyld_hdlr; + ep->sys->rx.buff_sz = rx_buffer_size; + ep->sys->rx.pool_sz =IPA_GENERIC_RX_POOL_SZ ; +INIT_WORK (&ep->sys->rx.work, ipa_wq_handle_rx); +INIT_DELAYED_WORK (&ep->sys->rx.replenish_work, + ipa_replenish_rx_work_func); + } + + ep->client_notify = client_notify; + ep->priv = priv; + ep->napi_enabled = ep->client ==IPA_CLIENT_APPS_WAN_CONS ; + +ipa_client_add (); + +ipa_cfg_ep (ep_id); + + ret =ipa_gsi_setup_channel (ep, channel_count, evt_ring_mult); +if (ret) + goto err_client_remove; + +if (ipa_consumer (ep->client)) +ipa_replenish_rx_cache (ep->sys); +err_client_remove: +ipa_client_remove (); + +return ret; +} + +/** +* ipa_channel_reset_aggr() - Reset with aggregation active +* @ep_id: Endpoint on which reset is performed +* +* If aggregation is active on a channel when a reset is performed, +* a special sequence of actions must be taken. This is a workaround +* for a hardware limitation. +* +* Return: 0 if successful, or a negative error code. +*/ +static int ipa_channel_reset_aggr (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; +struct ipa_reg_aggr_force_close force_close; +struct ipa_reg_endp_init_ctrl init_ctrl; +struct gsi_xfer_elem xfer_elem = { }; +struct ipa_dma_mem dma_byte; +int aggr_active_bitmap =0 ; +bool ep_suspended = false; +int ret; +int i; + +ipa_reg_aggr_force_close (&force_close,BIT (ep_id)); +ipa_write_reg_fields (IPA_AGGR_FORCE_CLOSE , &force_close); + +/* Reset channel */ + ret =gsi_channel_reset (ipa_ctx->gsi, ep->channel_id); +if (ret) +return ret; + +/* Turn off the doorbell engine. We're going to poll until +* we know aggregation isn't active. +*/ +gsi_channel_config (ipa_ctx->gsi, ep->channel_id, false); + +ipa_read_reg_n_fields (IPA_ENDP_INIT_CTRL_N , ep_id, &init_ctrl); +if (init_ctrl.endp_suspend) { + ep_suspended = true; +ipa_reg_endp_init_ctrl (&init_ctrl, false); +ipa_write_reg_n_fields (IPA_ENDP_INIT_CTRL_N , ep_id, &init_ctrl); + } + +/* Start channel and put 1 Byte descriptor on it */ + ret =gsi_channel_start (ipa_ctx->gsi, ep->channel_id); +if (ret) + goto out_suspend_again; + +if (ipa_dma_alloc (&dma_byte,1 ,GFP_KERNEL )) { + ret = -ENOMEM ; + goto err_stop_channel; + } + + xfer_elem.addr = dma_byte.phys; + xfer_elem.len_opcode =1 ;/* = dma_byte.size; */ + xfer_elem.flags =GSI_XFER_FLAG_EOT ; + xfer_elem.type =GSI_XFER_ELEM_DATA ; + + ret =gsi_channel_queue (ipa_ctx->gsi, ep->channel_id,1 , &xfer_elem, + true); +if (ret) + goto err_dma_free; + +/* Wait for aggregation frame to be closed */ +for (i =0 ; i <CHANNEL_RESET_AGGR_RETRY_COUNT ; i++) { + aggr_active_bitmap =ipa_read_reg (IPA_STATE_AGGR_ACTIVE ); +if (!(aggr_active_bitmap &BIT (ep_id))) +break ; +msleep (CHANNEL_RESET_DELAY ); + } +ipa_bug_on (aggr_active_bitmap &BIT (ep_id)); + +ipa_dma_free (&dma_byte); + + ret =ipa_stop_gsi_channel (ep_id); +if (ret) + goto out_suspend_again; + +/* Reset the channel. If successful we need to sleep for 1 +* msec to complete the GSI channel reset sequence. Either +* way we finish by suspending the channel again (if necessary) +* and re-enabling its doorbell engine. +*/ + ret =gsi_channel_reset (ipa_ctx->gsi, ep->channel_id); +if (!ret) +msleep (CHANNEL_RESET_DELAY ); + goto out_suspend_again; + +err_dma_free: +ipa_dma_free (&dma_byte); +err_stop_channel: +ipa_stop_gsi_channel (ep_id); +out_suspend_again: +if (ep_suspended) { +ipa_reg_endp_init_ctrl (&init_ctrl, true); +ipa_write_reg_n_fields (IPA_ENDP_INIT_CTRL_N , ep_id, &init_ctrl); + } +/* Turn on the doorbell engine again */ +gsi_channel_config (ipa_ctx->gsi, ep->channel_id, true); + +return ret; +} + +static void ipa_reset_gsi_channel (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; +u32 aggr_active_bitmap =0 ; + +/* For consumer endpoints, a hardware limitation prevents us +* from issuing a channel reset if aggregation is active. +* Check for this case, and if detected, perform a special +* reset sequence. Otherwise just do a "normal" reset. +*/ +if (ipa_consumer (ep->client)) + aggr_active_bitmap =ipa_read_reg (IPA_STATE_AGGR_ACTIVE ); + +if (aggr_active_bitmap &BIT (ep_id)) { +ipa_bug_on (ipa_channel_reset_aggr (ep_id)); + }else { +/* In case the reset follows stop, need to wait 1 msec */ +msleep (CHANNEL_RESET_DELAY ); +ipa_bug_on (gsi_channel_reset (ipa_ctx->gsi, ep->channel_id)); + } +} + +/** +* ipa_ep_teardown() - Tear down an endpoint +* @ep_id: The endpoint to tear down +*/ +void ipa_ep_teardown (u32 ep_id) +{ +struct ipa_ep_context *ep = &ipa_ctx->ep[ep_id]; +int empty; +int ret; +int i; + +if (ep->napi_enabled) { +do { +usleep_range (95 ,105 ); + }while (ipa_ep_polling (ep)); + } + +if (ipa_producer (ep->client)) { +do { +spin_lock_bh (&ep->sys->spinlock); + empty =list_empty (&ep->sys->head_desc_list); +spin_unlock_bh (&ep->sys->spinlock); +if (!empty) +usleep_range (95 ,105 ); +else +break ; + }while (1 ); + } + +if (ipa_consumer (ep->client)) +cancel_delayed_work_sync (&ep->sys->rx.replenish_work); +flush_workqueue (ep->sys->wq); +/* channel stop might fail on timeout if IPA is busy */ +for (i =0 ; i <IPA_GSI_CHANNEL_STOP_MAX_RETRY ; i++) { + ret =ipa_stop_gsi_channel (ep_id); +if (!ret) +break ; +ipa_bug_on (ret != -EAGAIN && ret != -ETIMEDOUT ); + } + +ipa_reset_gsi_channel (ep_id); +gsi_channel_free (ipa_ctx->gsi, ep->channel_id); + +if (ipa_consumer (ep->client)) +ipa_cleanup_rx (ep->sys); + +ipa_ep_free (ep_id); +} + +static int ipa_poll_gsi_pkt (struct ipa_sys_context *sys) +{ +if (sys->ep->bytes_xfered_valid) { + sys->ep->bytes_xfered_valid = false; + +return (int )sys->ep->bytes_xfered; + } + +return gsi_channel_poll (ipa_ctx->gsi, sys->ep->channel_id); +} + +bool ipa_ep_polling (struct ipa_ep_context *ep) +{ +ipa_assert (ipa_consumer (ep->client)); + +return !!atomic_read (&ep->sys->rx.curr_polling_state); +} + +struct ipa_dp *ipa_dp_init (void ) +{ +struct kmem_cache *cache; +struct ipa_dp *dp; + + dp =kzalloc (sizeof (*dp),GFP_KERNEL ); +if (!dp) +return NULL ; + + cache =kmem_cache_create ("IPA_TX_PKT_WRAPPER" , +sizeof (struct ipa_tx_pkt_wrapper ), +0 ,0 ,NULL ); +if (!cache) { +kfree (dp); +return NULL ; + } + dp->tx_pkt_wrapper_cache = cache; + + cache =kmem_cache_create ("IPA_RX_PKT_WRAPPER" , +sizeof (struct ipa_rx_pkt_wrapper ), +0 ,0 ,NULL ); +if (!cache) { +kmem_cache_destroy (dp->tx_pkt_wrapper_cache); +kfree (dp); +return NULL ; + } + dp->rx_pkt_wrapper_cache = cache; + +return dp; +} + +void ipa_dp_exit (struct ipa_dp *dp) +{ +kmem_cache_destroy (dp->rx_pkt_wrapper_cache); +kmem_cache_destroy (dp->tx_pkt_wrapper_cache); +kfree (dp); +}
Signature · 1 line
2.17.1
RFC PATCH 11/12 soc: qcom: ipa: IPA rmnet interface
In reply to Alex ElderThe IPA uses "rmnet" as a way to present remote network resources as if they were local to the AP. IPA interfaces representing networks accessible via the modem are represented as rmnet interfaces, implemented by the "rmnet data driver" found here:
drivers/net/ethernet/qualcomm/rmnet/
The IPA is able to perform aggregation of packets, as well as checksum offload. These options (plus others, such as configuring MTU size) are configurable using an ioctl interface. In addition, rmnet devices support multiplexing.
TX packets are handed to the data path layer, and when their transmission is complete the notification callback will be called. The data path code posts RX packets to the hardware, and when they are filled they are supplied here by a receive notification callback.
The IPA driver currently does not support the modem shutting down (or crashing). But the rmnet_ipa device roughly represents the availability of networks reachable by the modem. If the modem is operational, an ipa_rmnet network device will be available. Modem operation is managed by the remoteproc subsystem.
Note: This portion of the driver will be heavily affected by planned rework on the data path code.
--- drivers/net/ipa/msm_rmnet.h | 120 +++++ drivers/net/ipa/rmnet_config.h | 31 ++ drivers/net/ipa/rmnet_ipa.c | 805 +++++++++++++++++++++++++++++++++ 3 files changed, 956 insertions(+) create mode 100644 drivers/net/ipa/msm_rmnet.h create mode 100644 drivers/net/ipa/rmnet_config.h create mode 100644 drivers/net/ipa/rmnet_ipa.c
drivers/net/ipa/msm_rmnet.h new file +120 -0
@@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd. +*/ +#ifndef _MSM_RMNET_H_ +#define _MSM_RMNET_H_ + +/* Bitmap macros for RmNET driver operation mode. */ +#define RMNET_MODE_NONE 0x00 +#define RMNET_MODE_LLP_ETH 0x01 +#define RMNET_MODE_LLP_IP 0x02 +#define RMNET_MODE_QOS 0x04 + +/* IOCTL commands +* Values chosen to not conflict with other drivers in the ecosystem +*/ + +#define RMNET_IOCTL_SET_LLP_ETHERNET 0x000089f1/* Set Ethernet protocol */ +#define RMNET_IOCTL_SET_LLP_IP 0x000089f2/* Set RAWIP protocol */ +#define RMNET_IOCTL_GET_LLP 0x000089f3/* Get link protocol */ +#define RMNET_IOCTL_SET_QOS_ENABLE 0x000089f4/* Set QoS header enabled */ +#define RMNET_IOCTL_SET_QOS_DISABLE 0x000089f5/* Set QoS header disabled*/ +#define RMNET_IOCTL_GET_QOS 0x000089f6/* Get QoS header state */ +#define RMNET_IOCTL_GET_OPMODE 0x000089f7/* Get operation mode */ +#define RMNET_IOCTL_OPEN 0x000089f8/* Open transport port */ +#define RMNET_IOCTL_CLOSE 0x000089f9/* Close transport port */ +#define RMNET_IOCTL_FLOW_ENABLE 0x000089fa/* Flow enable */ +#define RMNET_IOCTL_FLOW_DISABLE 0x000089fb/* Flow disable */ +#define RMNET_IOCTL_FLOW_SET_HNDL 0x000089fc/* Set flow handle */ +#define RMNET_IOCTL_EXTENDED 0x000089fd/* Extended IOCTLs */ + +/* RmNet Data Required IOCTLs */ +#define RMNET_IOCTL_GET_SUPPORTED_FEATURES 0x0000/* Get features */ +#define RMNET_IOCTL_SET_MRU 0x0001/* Set MRU */ +#define RMNET_IOCTL_GET_MRU 0x0002/* Get MRU */ +#define RMNET_IOCTL_GET_EPID 0x0003/* Get endpoint ID */ +#define RMNET_IOCTL_GET_DRIVER_NAME 0x0004/* Get driver name */ +#define RMNET_IOCTL_ADD_MUX_CHANNEL 0x0005/* Add MUX ID */ +#define RMNET_IOCTL_SET_EGRESS_DATA_FORMAT 0x0006/* Set EDF */ +#define RMNET_IOCTL_SET_INGRESS_DATA_FORMAT 0x0007/* Set IDF */ +#define RMNET_IOCTL_SET_AGGREGATION_COUNT 0x0008/* Set agg count */ +#define RMNET_IOCTL_GET_AGGREGATION_COUNT 0x0009/* Get agg count */ +#define RMNET_IOCTL_SET_AGGREGATION_SIZE 0x000a/* Set agg size */ +#define RMNET_IOCTL_GET_AGGREGATION_SIZE 0x000b/* Get agg size */ +#define RMNET_IOCTL_FLOW_CONTROL 0x000c/* Do flow control */ +#define RMNET_IOCTL_GET_DFLT_CONTROL_CHANNEL 0x000d/* For legacy use */ +#define RMNET_IOCTL_GET_HWSW_MAP 0x000e/* Get HW/SW map */ +#define RMNET_IOCTL_SET_RX_HEADROOM 0x000f/* RX Headroom */ +#define RMNET_IOCTL_GET_EP_PAIR 0x0010/* Endpoint pair */ +#define RMNET_IOCTL_SET_QOS_VERSION 0x0011/* 8/6 byte QoS hdr*/ +#define RMNET_IOCTL_GET_QOS_VERSION 0x0012/* 8/6 byte QoS hdr*/ +#define RMNET_IOCTL_GET_SUPPORTED_QOS_MODES 0x0013/* Get QoS modes */ +#define RMNET_IOCTL_SET_SLEEP_STATE 0x0014/* Set sleep state */ +#define RMNET_IOCTL_SET_XLAT_DEV_INFO 0x0015/* xlat dev name */ +#define RMNET_IOCTL_DEREGISTER_DEV 0x0016/* Dereg a net dev */ +#define RMNET_IOCTL_GET_SG_SUPPORT 0x0017/* Query sg support*/ + +/* Return values for the RMNET_IOCTL_GET_SUPPORTED_FEATURES IOCTL */ +#define RMNET_IOCTL_FEAT_NOTIFY_MUX_CHANNEL BIT(0) +#define RMNET_IOCTL_FEAT_SET_EGRESS_DATA_FORMAT BIT(1) +#define RMNET_IOCTL_FEAT_SET_INGRESS_DATA_FORMAT BIT(2) + +/* Input values for the RMNET_IOCTL_SET_EGRESS_DATA_FORMAT IOCTL */ +#define RMNET_IOCTL_EGRESS_FORMAT_AGGREGATION BIT(2) +#define RMNET_IOCTL_EGRESS_FORMAT_CHECKSUM BIT(4) + +/* Input values for the RMNET_IOCTL_SET_INGRESS_DATA_FORMAT IOCTL */ +#define RMNET_IOCTL_INGRESS_FORMAT_CHECKSUM BIT(4) +#define RMNET_IOCTL_INGRESS_FORMAT_AGG_DATA BIT(5) + +/* User space may not have this defined. */ +#ifndef IFNAMSIZ +#define IFNAMSIZ 16 +#endif + +struct rmnet_ioctl_extended_s { +u32 extended_ioctl; +union { +u32 data;/* Generic data field for most extended IOCTLs */ + +/* Return values for +* RMNET_IOCTL_GET_DRIVER_NAME +* RMNET_IOCTL_GET_DFLT_CONTROL_CHANNEL +*/ +char if_name[IFNAMSIZ ]; + +/* Input values for the RMNET_IOCTL_ADD_MUX_CHANNEL IOCTL */ +struct { +u32 mux_id; +char vchannel_name[IFNAMSIZ ]; + } rmnet_mux_val; + +/* Input values for the RMNET_IOCTL_FLOW_CONTROL IOCTL */ +struct { +u8 flow_mode; +u8 mux_id; + } flow_control_prop; + +/* Return values for RMNET_IOCTL_GET_EP_PAIR */ +struct { +u32 consumer_pipe_num; +u32 producer_pipe_num; + } ipa_ep_pair; + +struct { +u32 __data;/* Placeholder for legacy data*/ +u32 agg_size; +u32 agg_count; + } ingress_format; + } u; +}; + +struct rmnet_ioctl_data_s { +union { +u32 operation_mode; +u32 tcm_handle; + } u; +}; +#endif /* _MSM_RMNET_H_ */
drivers/net/ipa/rmnet_config.h new file +31 -0
@@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd. +*/ +#ifndef _RMNET_CONFIG_H_ +#define _RMNET_CONFIG_H_ + +#include <linux/types.h> + +/* XXX We want to use struct rmnet_map_header, but that's currently defined in +* XXX drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h +* XXX We also want to use RMNET_MAP_GET_CD_BIT(Y), defined in the same file. +*/ +struct rmnet_map_header_s { +#ifndef RMNET_USE_BIG_ENDIAN_STRUCTS +u8 pad_len :6 , + reserved_bit :1 , + cd_bit :1 ; +#else +u8 cd_bit :1 , + reserved_bit :1 , + pad_len :6 ; +#endif /* RMNET_USE_BIG_ENDIAN_STRUCTS */ +u8 mux_id; +u16 pkt_len; +}__aligned(1) ; + +#define RMNET_MAP_GET_CD_BIT (Y ) (((struct rmnet_map_header_s *)Y->data)->cd_bit) + +#endif /* _RMNET_CONFIG_H_ */
drivers/net/ipa/rmnet_ipa.c new file +805 -0
805 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH 12/12 soc: qcom: ipa: build and "ipa_i.h"
In reply to Alex ElderThis last IPA code patch includes "Kconfig" for kernel configuration and a "Makefile" to build the code. The main configuration option enabling the code to be built is "CONFIG_IPA". A second one, "CONFIG_IPA_ASSERT", is on by default if CONFIG_IPA is selected, but can be disabled to cause ipa_assert() calls to not be included.
Finally, "ipa_i.h" is a sort of dumping ground header file, declaring things used and needed throughout the code. (I expect much of this can be doled out into separate headers.)
--- drivers/net/ipa/Kconfig | 30 ++ drivers/net/ipa/Makefile | 7 + drivers/net/ipa/ipa_i.h | 573 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 610 insertions(+) create mode 100644 drivers/net/ipa/Kconfig create mode 100644 drivers/net/ipa/Makefile create mode 100644 drivers/net/ipa/ipa_i.h
drivers/net/ipa/Kconfig new file +30 -0
@@ -0,0 +1,30 @@ +config IPA + tristate "Qualcomm IPA support" + depends on NET + select QCOM_QMI_HELPERS + select QCOM_MDT_LOADER + default n + help + Choose Y here to include support for the Qualcomm IP + Accelerator (IPA), a hardware block present in some + Qualcomm SoCs. The IPA is a programmable protocol + processor that is capable of generic hardware handling + of IP packets, including routing, filtering, and NAT. + Currently the IPA driver supports only basic transport + of network traffic between the AP and modem, on the + Qualcomm SDM845 SoC. + + If unsure, say N. + +config IPA_ASSERT + bool "Enable IPA assertions" + depends on IPA + default y + help + Incorporate IPA assertion verification in the build. This + cause various design assumptions to be checked at runtime, + generating a report (and a crash) if any assumed condition + does not hold. You may wish to disable this to avoid the + overhead of checking. + + If unsure doubt, say "Y" here.
drivers/net/ipa/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +obj-$(CONFIG_IPA) += ipa.o + +ipa-y := ipa_main.o ipa_dp.o \ + ipa_utils.o ipa_interrupts.o \ + ipa_uc.o gsi.o rmnet_ipa.o \ + ipa_qmi.o ipa_qmi_msg.o \ + ipahal.o ipa_reg.o ipa_dma.o
drivers/net/ipa/ipa_i.h new file +573 -0
573 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [RFC PATCH 12/12] soc: qcom: ipa: build and "ipa_i.h"
Hi-
Quoted 21 lines · Alex Elder
drivers/net/ipa/Kconfig new file +15
-0@@ -0,0 +1,30 @@ +config IPA + tristate "Qualcomm IPA support" + depends on NET + select QCOM_QMI_HELPERS + select QCOM_MDT_LOADER + default n + help + Choose Y here to include support for the Qualcomm IP + Accelerator (IPA), a hardware block present in some + Qualcomm SoCs. The IPA is a programmable protocol + processor that is capable of generic hardware handling + of IP packets, including routing, filtering, and NAT. + Currently the IPA driver supports only basic transport + of network traffic between the AP and modem, on the + Qualcomm SDM845 SoC.
drivers/net/ipa/Kconfig line 25
Quoted 10 lines
drivers/net/ipa/Kconfig new file +10
-0+ + If unsure, say N. + +config IPA_ASSERT + bool "Enable IPA assertions" + depends on IPA + default y + help + Incorporate IPA assertion verification in the build. This + cause various design assumptions to be checked at runtime,
causes
Quoted 5 lines
drivers/net/ipa/Kconfig new file +5
-0+ generating a report (and a crash) if any assumed condition + does not hold. You may wish to disable this to avoid the + overhead of checking. + + If unsure doubt, say "Y" here.
Signature · 1 line
~Randy
Re: [RFC PATCH 01/12] dt-bindings: soc: qcom: add IPA bindings
In reply to Alex ElderQuoted 11 lines · Alex Elder
Add the binding definitions for the "qcom,ipa" and "qcom,rmnet-ipa" device tree nodes.
Signed-off-by Alex Elder <[email protected]>--- .../devicetree/bindings/soc/qcom/qcom,ipa.txt | 136 ++++++++++++++++++ .../bindings/soc/qcom/qcom,rmnet-ipa.txt | 15 ++ 2 files changed, 151 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt
I think this should go into bindings/net instead of bindings/soc, since it's mostly about networking rather than a specific detail of managing the SoC itself.
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 6
Quoted 12 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +6
-0@@ -0,0 +1,136 @@ +Qualcomm IPA (IP Accelerator) Driver + +This binding describes the Qualcomm IPA. The IPA is capable of offloading +certain network processing tasks (e.g. filtering, routing, and NAT) from +the main processor. The IPA currently serves only as a network interface, +providing access to an LTE network available via a modem.
That doesn't belong into the binding. Say what the hardware can do here, not what a specific implementation of the driver does at this moment. The binding should be written in an OS independent way after all.
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 46
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +6
-0+- interrupts-extended: + Specifies the IRQs used by the IPA. Four cells are required, + specifying: the IPA IRQ; the GSI IRQ; the clock query interrupt + from the modem; and the "ready for stage 2 initialization" + interrupt from the modem. The first two are hardware IRQs; the + third and fourth are SMP2P input interrupts.
You mean 'four interrupts', not 'four cells' -- each interrupt specifier already consists of at least two cells (one for the phandle to the irqchip, plus one or more cells to describe that interrupt).
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 63
Quoted 5 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +5
-0+- interconnects: + Specifies the interconnects used by the IPA. Three cells are + required, specifying: the path from the IPA to memory; from + IPA to internal (SoC resident) memory; and between the AP + subsystem and IPA for register access.
Same here and in the rest.
Arnd
Re: [RFC PATCH 02/12] soc: qcom: ipa: DMA helpers
In reply to Alex ElderQuoted 6 lines · Alex Elder
This patch includes code implementing the IPA DMA module, which defines a structure to represent a DMA allocation for the IPA device. It's used throughout the IPA code.
Signed-off-by Alex Elder <[email protected]>
I looked through all the users of this and couldn't fine one that actually benefits from it. I'd say better drop this patch entirely and open-code the contents in the callers. That will help readability since the dma API is well understood by many people.
Generally speaking, try not to wrap Linux interfaces into driver specific helper functions.
Arnd
Re: [RFC PATCH 12/12] soc: qcom: ipa: build and "ipa_i.h"
In reply to Alex Elderdrivers/net/ipa/Kconfig line 28
Quoted 10 lines · Alex Elder
drivers/net/ipa/Kconfig new file +10
-0+config IPA_ASSERT + bool "Enable IPA assertions" + depends on IPA + default y + help + Incorporate IPA assertion verification in the build. This + cause various design assumptions to be checked at runtime, + generating a report (and a crash) if any assumed condition + does not hold. You may wish to disable this to avoid the + overhead of checking.
Maybe remove this from the submission.
drivers/net/ipa/ipa_i.h line 91
Quoted 2 lines
drivers/net/ipa/ipa_i.h new file +2
-0+#define ipa_debug(fmt, args...) dev_dbg(ipa_ctx->dev, fmt, ## args) +#define ipa_err(fmt, args...) dev_err(ipa_ctx->dev, fmt, ## args)
These macros refer to variables in the caller that are not passed as arguments, which is generally a bad idea. They also trivially wrap a standard kernel interface, so better just that directly.
drivers/net/ipa/ipa_i.h line 105
Quoted 13 lines
drivers/net/ipa/ipa_i.h new file +13
-0+#define ipa_bug () \ + do { \ + ipa_err("an unrecoverable error has occurred\n"); \ + BUG(); \ + } while (0) + +#define ipa_bug_on (condition) \ + do { \ + if (condition) { \ + ipa_err("ipa_bug_on(%s) failed!\n", #condition); \ + ipa_bug(); \ + } \ + } while (0)
According to a discussion at the kernel summit, we should generally try to avoid BUG() as it rarely does anything useful: it crashes the current task, but in a network driver that usually means killing the entire kernel since you are not in process context.
Try questioning each one to see if it can possibly happen, or if the code can be rewritten in a way to guarantee that it cannot.
If continuing after the bug was detected does not cause a security hole or permanent data corruption, you can also use WARN_ON() or WARN_ONCE() (without a wrapper).
Quoted 6 lines
drivers/net/ipa/ipa_i.h new file +6
-0+int ipa_wwan_init (void ); +void ipa_wwan_cleanup (void ); + +int ipa_stop_gsi_channel (u32 ep_id); + +void ipa_cfg_ep (u32 ep_id);
drivers/net/ipa/ipa_i.h line 457
Quoted 10 lines
drivers/net/ipa/ipa_i.h new file +10
-0+ +int ipa_tx_dp (enum ipa_client_type dst,struct sk_buff *skb); + +bool ipa_endp_aggr_support (u32 ep_id); +enum ipa_seq_type ipa_endp_seq_type (u32 ep_id); + +void ipa_endp_init_hdr_cons (u32 ep_id,u32 header_size, +u32 metadata_offset,u32 length_offset); +void ipa_endp_init_hdr_prod (u32 ep_id,u32 header_size, +u32 metadata_offset,u32 length_offset);
I'm surprised to see many functions that don't take a pointer to an instance as the first argument, which often indicates that you have global state variables and the driver won't work with multiple hardware instances.
Arnd
Re: [RFC PATCH 11/12] soc: qcom: ipa: IPA rmnet interface
In reply to Alex ElderQuoted 2 lines · Alex Elder
Note: This portion of the driver will be heavily affected by planned rework on the data path code.
Ok. I don't think the ioctl interface has a real chance of getting merged into the kernel. You should generally not require any custom user space tools for a driver like this.
drivers/net/ipa/msm_rmnet.h
Quoted 5 lines
drivers/net/ipa/msm_rmnet.h new file +0
-0
Just for the record: if we really wanted to define ioctls, this would go into 'include/linux/uapi/msm_rmnet.h' and get installed into the /usr/include hierarchy on all machines.
drivers/net/ipa/msm_rmnet.h line 25
Quoted 8 lines
drivers/net/ipa/msm_rmnet.h new file +8
-0+ +#define RMNET_IOCTL_SET_LLP_ETHERNET 0x000089f1/* Set Ethernet protocol */ +#define RMNET_IOCTL_SET_LLP_IP 0x000089f2/* Set RAWIP protocol */ +#define RMNET_IOCTL_GET_LLP 0x000089f3/* Get link protocol */ +#define RMNET_IOCTL_SET_QOS_ENABLE 0x000089f4/* Set QoS header enabled */ +#define RMNET_IOCTL_SET_QOS_DISABLE 0x000089f5/* Set QoS header disabled*/ +#define RMNET_IOCTL_GET_QOS 0x000089f6/* Get QoS header state */ +#define RMNET_IOCTL_GET_OPMODE 0x000089f7/* Get operation mode */
And the commands would be defined using _IOC/_IOR/_IOW macros that document which arguments they take
drivers/net/ipa/msm_rmnet.h line 31
Quoted 6 lines
drivers/net/ipa/msm_rmnet.h new file +6
-0+#define RMNET_IOCTL_OPEN 0x000089f8/* Open transport port */ +#define RMNET_IOCTL_CLOSE 0x000089f9/* Close transport port */ +#define RMNET_IOCTL_FLOW_ENABLE 0x000089fa/* Flow enable */ +#define RMNET_IOCTL_FLOW_DISABLE 0x000089fb/* Flow disable */ +#define RMNET_IOCTL_FLOW_SET_HNDL 0x000089fc/* Set flow handle */ +#define RMNET_IOCTL_EXTENDED 0x000089fd/* Extended IOCTLs */
'extended' interfaces are obviously out of the question entirely, those would all need to be separate commands.
drivers/net/ipa/msm_rmnet.h line 75
Quoted 4 lines
drivers/net/ipa/msm_rmnet.h new file +4
-0+/* User space may not have this defined. */ +#ifndef IFNAMSIZ +#define IFNAMSIZ 16 +#endif
This is in <linux/if.h>
drivers/net/ipa/msm_rmnet.h line 79
Quoted 3 lines
drivers/net/ipa/msm_rmnet.h new file +3
-0+struct rmnet_ioctl_extended_s { +u32 extended_ioctl; +union {
And unions in the ioctl interfaces also wouldn't work.
drivers/net/ipa/msm_rmnet.h
Quoted 4 lines
drivers/net/ipa/msm_rmnet.h new file +4
-0+static bool initialized;/* Avoid duplicate initialization */ + +static struct rmnet_ipa_context rmnet_ipa_ctx_struct; +static struct rmnet_ipa_context *rmnet_ipa_ctx = &rmnet_ipa_ctx_struct;
Global variables like these should be removed.
Quoted 23 lines
drivers/net/ipa/msm_rmnet.h new file +23
-0+/** ipa_wwan_xmit() - Transmits an skb. +* +* @skb: skb to be transmitted +* @dev: network device +* +* Return codes: +* NETDEV_TX_OK: Success +* NETDEV_TX_BUSY: Error while transmitting the skb. Try again later +*/ +static int ipa_wwan_xmit (struct sk_buff *skb,struct net_device *dev) +{ +struct ipa_wwan_private *wwan_ptr =netdev_priv (dev); +unsigned int skb_len; +int outstanding; + +if (skb->protocol !=htons (ETH_P_MAP )) { +dev_kfree_skb_any (skb); + dev->stats.tx_dropped++; +return NETDEV_TX_OK ; + } + +/* Control packets are sent even if queue is stopped. We +* always honor the data and control high-water marks.
drivers/net/ipa/msm_rmnet.h
Quoted 10 lines
drivers/net/ipa/msm_rmnet.h new file +10
-0+*/ + outstanding =atomic_read (&wwan_ptr->outstanding_pkts); +if (!RMNET_MAP_GET_CD_BIT (skb)) {/* Data packet? */ +if (netif_queue_stopped (dev)) +return NETDEV_TX_BUSY ; +if (outstanding >= wwan_ptr->outstanding_high) +return NETDEV_TX_BUSY ; + }else if (outstanding >= wwan_ptr->outstanding_high_ctl) { +return NETDEV_TX_BUSY ; + }
This seems to be a poor reimplementation of BQL. Better use netdev_sent_queue() and netdev_completed_queue() to do the same thing better.
Quoted 28 lines
drivers/net/ipa/msm_rmnet.h new file +28
-0+/** apps_ipa_packet_receive_notify() - Rx notify +* +* @priv: driver context +* @evt: event type +* @data: data provided with event +* +* IPA will pass a packet to the Linux network stack with skb->data +*/ +static void apps_ipa_packet_receive_notify (void *priv,enum ipa_dp_evt_type evt, +unsigned long data) +{ +struct ipa_wwan_private *wwan_ptr; +struct net_device *dev = priv; + + wwan_ptr =netdev_priv (dev); +if (evt ==IPA_RECEIVE ) { +struct sk_buff *skb = (struct sk_buff *)data; +int ret; +unsigned int packet_len = skb->len; + + skb->dev = rmnet_ipa_ctx->dev; + skb->protocol =htons (ETH_P_MAP ); + + ret =netif_receive_skb (skb); +if (ret) { +pr_err_ratelimited ("fail on netif_receive_skb\n" ); + dev->stats.rx_dropped++; + }
drivers/net/ipa/msm_rmnet.h
Quoted 10 lines
drivers/net/ipa/msm_rmnet.h new file +10
-0+ dev->stats.rx_packets++; + dev->stats.rx_bytes += packet_len; + }else if (evt ==IPA_CLIENT_START_POLL ) { +napi_schedule (&wwan_ptr->napi); + }else if (evt ==IPA_CLIENT_COMP_NAPI ) { +napi_complete (&wwan_ptr->napi); + }else { +ipa_err ("Invalid evt %d received in wan_ipa_receive\n" , evt); + } +}
I don't understand the logic here. Why is this a callback function? You normally want the data path to be as fast as possible, and the indirection seems like it would get in the way of that.
Since the function doesn't do much interesting work, could it be moved into the caller?
drivers/net/ipa/msm_rmnet.h
Quoted 4 lines
drivers/net/ipa/msm_rmnet.h new file +4
-0+/** handle_ingress_format() - Ingress data format configuration */ +static int handle_ingress_format (struct net_device *dev, +struct rmnet_ioctl_extended_s *in) +{
Can you describe how this would be called from user space? I.e. what is the reason we have to configure anything here?
Quoted 61 lines
drivers/net/ipa/msm_rmnet.h new file +61
-0+ +/* Unsupported requests */ +case RMNET_IOCTL_SET_MRU :/* Set MRU */ +case RMNET_IOCTL_GET_MRU :/* Get MRU */ +case RMNET_IOCTL_GET_AGGREGATION_COUNT :/* Get agg count */ +case RMNET_IOCTL_SET_AGGREGATION_COUNT :/* Set agg count */ +case RMNET_IOCTL_GET_AGGREGATION_SIZE :/* Get agg size */ +case RMNET_IOCTL_SET_AGGREGATION_SIZE :/* Set agg size */ +case RMNET_IOCTL_FLOW_CONTROL :/* Do flow control */ +case RMNET_IOCTL_GET_DFLT_CONTROL_CHANNEL :/* For legacy use */ +case RMNET_IOCTL_GET_HWSW_MAP :/* Get HW/SW map */ +case RMNET_IOCTL_SET_RX_HEADROOM :/* Set RX Headroom */ +case RMNET_IOCTL_SET_QOS_VERSION :/* Set 8/6 byte QoS */ +case RMNET_IOCTL_GET_QOS_VERSION :/* Get 8/6 byte QoS */ +case RMNET_IOCTL_GET_SUPPORTED_QOS_MODES :/* Get QoS modes */ +case RMNET_IOCTL_SET_SLEEP_STATE :/* Set sleep state */ +case RMNET_IOCTL_SET_XLAT_DEV_INFO :/* xlat dev name */ +case RMNET_IOCTL_DEREGISTER_DEV :/* Deregister netdev */ +return -ENOTSUPP ;/* Defined, but unsupported command */ + +default : +return -EINVAL ;/* Invalid (unrecognized) command */ + } + +copy_out: +return copy_to_user (data, &edata, size) ? -EFAULT :0 ; +} + +/** ipa_wwan_ioctl() - I/O control for wwan network driver */ +static int ipa_wwan_ioctl (struct net_device *dev,struct ifreq *ifr,int cmd) +{ +struct rmnet_ioctl_data_s ioctl_data = { }; +void __user *data; +size_t size; + + data = ifr->ifr_ifru.ifru_data; + size =sizeof (ioctl_data); + +switch (cmd) { +/* These features are implied; alternatives are not supported */ +case RMNET_IOCTL_SET_LLP_IP :/* RAW IP protocol */ +case RMNET_IOCTL_SET_QOS_DISABLE :/* QoS header disabled */ +return 0 ; + +/* These features are not supported; use alternatives */ +case RMNET_IOCTL_SET_LLP_ETHERNET :/* Ethernet protocol */ +case RMNET_IOCTL_SET_QOS_ENABLE :/* QoS header enabled */ +case RMNET_IOCTL_GET_OPMODE :/* Get operation mode */ +case RMNET_IOCTL_FLOW_ENABLE :/* Flow enable */ +case RMNET_IOCTL_FLOW_DISABLE :/* Flow disable */ +case RMNET_IOCTL_FLOW_SET_HNDL :/* Set flow handle */ +return -ENOTSUPP ; + +case RMNET_IOCTL_GET_LLP :/* Get link protocol */ + ioctl_data.u.operation_mode =RMNET_MODE_LLP_IP ; + goto copy_out; + +case RMNET_IOCTL_GET_QOS :/* Get QoS header state */ + ioctl_data.u.operation_mode =RMNET_MODE_NONE ; + goto copy_out; +
drivers/net/ipa/msm_rmnet.h
Quoted 10 lines
drivers/net/ipa/msm_rmnet.h new file +10
-0+case RMNET_IOCTL_OPEN :/* Open transport port */ +case RMNET_IOCTL_CLOSE :/* Close transport port */ +return 0 ; + +case RMNET_IOCTL_EXTENDED :/* Extended IOCTLs */ +return ipa_wwan_ioctl_extended (dev, data); + +default : +return -EINVAL ; + }
It would help to remove everything that is a nop or not implemented or that returns a constant value here, those are clearly not relevant for the submission here.
drivers/net/ipa/msm_rmnet.h
Quoted 5 lines
drivers/net/ipa/msm_rmnet.h new file +5
-0+ +static const struct of_device_id rmnet_ipa_dt_match[] = { + {.compatible ="qcom,rmnet-ipa" }, + {}, +};
The match string looks overly generic, surely there must be plans to have future versions of this that might require identification.
Arnd
Re: [RFC PATCH 09/12] soc: qcom: ipa: main IPA source file
In reply to Alex ElderQuoted 1 line · Alex Elder
+static void
ipa_client_remove_deferred(struct work_struct *work);
Try to avoid forward declarations by reordering the code in call order, it will also make it easier to read.
drivers/net/ipa/ipa_main.c line 63
Quoted 4 lines
drivers/net/ipa/ipa_main.c new file +4
-0+static DECLARE_WORK(ipa_client_remove_work, ipa_client_remove_deferred); + +static struct ipa_context ipa_ctx_struct; +struct ipa_context *ipa_ctx = &ipa_ctx_struct;
Global state variables should generally be removed as well, and passed around as function arguments.
Quoted 13 lines
drivers/net/ipa/ipa_main.c new file +13
-0+static int hdr_init_local_cmd (u32 offset,u32 size) +{ +struct ipa_desc desc = { }; +struct ipa_dma_mem mem; +void *payload; +int ret; + +if (ipa_dma_alloc (&mem, size,GFP_KERNEL )) +return -ENOMEM ; + + offset += ipa_ctx->smem_offset; + + payload =ipahal_hdr_init_local_pyld (&mem, offset);
drivers/net/ipa/ipa_main.c line 87
Quoted 10 lines
drivers/net/ipa/ipa_main.c new file +10
-0+if (!payload) { + ret = -ENOMEM ; + goto err_dma_free; + } + + desc.type =IPA_IMM_CMD_DESC ; + desc.len_opcode =IPA_IMM_CMD_HDR_INIT_LOCAL ; + desc.payload = payload; + + ret =ipa_send_cmd (&desc);
You have a bunch of dynamic allocations in here, which you then immediately tear down again after the command is complete. I can't see at all what you do with the DMA address, since you seem to not use the virtual address at all but only store the physical address in some kind of descriptor without ever writing to it.
Am I missing something here?
drivers/net/ipa/ipa_main.c line 873
Quoted 4 lines
drivers/net/ipa/ipa_main.c new file +4
-0+/* Remoteproc callbacks for SSR events: prepare, start, stop, unprepare */ +int ipa_ssr_prepare (struct rproc_subdev *subdev) +{ +printk ("======== SSR prepare received ========\n" );
I think you mean dev_dbg() here. A plain printk() without a level is not correct and we probably don't want those messages to arrive on the console for normal users.
Quoted 14 lines
drivers/net/ipa/ipa_main.c new file +14
-0+static int ipa_firmware_load (struct de + +err_clear_dev: + ipa_ctx->lan_cons_ep_id = 0; + ipa_ctx->cmd_prod_ep_id =0 ; +ipahal_exit (); +err_dma_exit: +ipa_dma_exit (); +err_clear_gsi: + ipa_ctx->gsi =NULL ; + ipa_ctx->ipa_phys =0 ; +ipa_reg_exit (); +err_clear_ipa_irq: + ipa_ctx->ipa_irq =0 ;
drivers/net/ipa/ipa_main.c line 1310
Quoted 10 lines
drivers/net/ipa/ipa_main.c new file +10
-0+err_clear_filter_bitmap: + ipa_ctx->filter_bitmap =0 ; +err_interconnect_exit: +ipa_interconnect_exit (); +err_clock_exit: +ipa_clock_exit (); + ipa_ctx->dev =NULL ; +out_smp2p_exit: +ipa_smp2p_exit (dev); +
No need to initialize members to zero when you are about to free the structure.
drivers/net/ipa/ipa_main.c line 1397
Quoted 12 lines
drivers/net/ipa/ipa_main.c new file +12
-0+static struct platform_driver ipa_plat_drv = { + .probe = ipa_plat_drv_probe, + .remove = ipa_plat_drv_remove, + .driver = { + .name ="ipa" , + .owner =THIS_MODULE , + .pm = &ipa_pm_ops, + .of_match_table = ipa_plat_drv_match, + }, +}; + +builtin_platform_driver (ipa_plat_drv);
This should be module_platform_driver(), and allow unloading the driver.
Arnd
Re: [RFC PATCH 04/12] soc: qcom: ipa: immediate commands
In reply to Alex Elderdrivers/net/ipa/ipahal.c line 44
Quoted 9 lines · Alex Elder
drivers/net/ipa/ipahal.c new file +8
-0+/** +* struct ipahal_context - HAL global context data +* @empty_fltrt_tbl: Empty table to be used for table initialization +*/ +static struct ipahal_context { +struct ipa_dma_mem empty_fltrt_tbl; +} ipahal_ctx_struct; +static struct ipahal_context *ipahal_ctx = &ipahal_ctx_struct;
Remove the global variables here
Quoted 14 lines
drivers/net/ipa/ipahal.c new file +14
-0+/* Immediate commands H/W structures */ + +/* struct ipa_imm_cmd_hw_ip_fltrt_init - IP_V*_FILTER_INIT/IP_V*_ROUTING_INIT +* command payload in H/W format. +* Inits IPv4/v6 routing or filter block. +* @hash_rules_addr: Addr in system mem where hashable flt/rt rules starts +* @hash_rules_size: Size in bytes of the hashable tbl to cpy to local mem +* @hash_local_addr: Addr in shared mem where hashable flt/rt tbl should +* be copied to +* @nhash_rules_size: Size in bytes of the non-hashable tbl to cpy to local mem +* @nhash_local_addr: Addr in shared mem where non-hashable flt/rt tbl should +* be copied to +* @rsvd: reserved +* @nhash_rules_addr: Addr in sys mem where non-hashable flt/rt tbl starts
drivers/net/ipa/ipahal.c line 96
Quoted 10 lines
drivers/net/ipa/ipahal.c new file +10
-0+*/ +struct ipa_imm_cmd_hw_ip_fltrt_init { +u64 hash_rules_addr; +u64 hash_rules_size :12 , + hash_local_addr :16 , + nhash_rules_size :12 , + nhash_local_addr :16 , + rsvd :8 ; +u64 nhash_rules_addr; +};
In hardware structures, you should not use bit fields, as the ordering of the bits is not well-defined in C. The only portable way to do this is to use shifts and masks unfortunately.
drivers/net/ipa/ipahal.c line 111
Quoted 6 lines
drivers/net/ipa/ipahal.c new file +6
-0+struct ipa_imm_cmd_hw_hdr_init_local { +u64 hdr_table_addr; +u32 size_hdr_table :12 , + hdr_addr :16 , + rsvd :4 ; +};
I would also add a 'u32 pad' member at the end to make the padding explicit here, or mark the first member as '__aligned(4) __packed' if you want to avoid the padding.
Quoted 10 lines
drivers/net/ipa/ipahal.c new file +10
-0+void *ipahal_dma_shared_mem_write_pyld (struct ipa_dma_mem *mem,u32 offset) +{ +struct ipa_imm_cmd_hw_dma_shared_mem *data; + +ipa_assert (mem->size <1 <<16 );/* size is 16 bits wide */ +ipa_assert (offset <1 <<16 );/* local_addr is 16 bits wide */ + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (!data) +return NULL ;
drivers/net/ipa/ipahal.c line 282
Quoted 10 lines
drivers/net/ipa/ipahal.c new file +10
-0+ + data->size = mem->size; + data->local_addr = offset; + data->direction =0 ;/* 0 = write to IPA; 1 = read from IPA */ + data->skip_pipeline_clear =0 ; + data->pipeline_clear_options =IPAHAL_HPS_CLEAR ; + data->system_addr = mem->phys; + +return data; +}
The 'void *' return looks odd here, and also the dynamic allocation. It looks to me like all these functions could be better done the other way round, basically putting the ipa_imm_cmd_hw_dma_shared_mem etc structures on the stack of the caller. At least for this one, the dynamic allocation doesn't help at all because the caller is the same that frees it again after the command. I suspect the same is true for a lot of those commands.
Arnd
Re: [RFC PATCH 10/12] soc: qcom: ipa: data path
In reply to Alex ElderQuoted 10 lines · Alex Elder
This patch contains "
ipa_dp.c", which includes the bulk of the data path code. There is an overview in the code of how things operate, but there are already plans to rework this portion of the driver.In particular:
- Interrupt handling will be replaced with a threaded interrupt handler. Currently handling occurs in a combination of interrupt and workqueue context, and this requires locking and atomic operations for proper synchronization.
You probably don't want to use just a threaded IRQ handler to start the poll function, that would still require an extra indirection.
However, you can probably use the top half of the threaded handler to request the poll function if necessary but use the bottom half for anything that does not go through poll.
Quoted 8 lines
- Currently, only receive endpoints use NAPI. Transmit completion interrupts are disabled, and are handled in batches by periodically scheduling an interrupting no-op request. The plan is to arrange for transmit requests to generate interrupts, and their completion will be processed with other completions in the NAPI poll function. This will also allow accurate feedback about packet sojourn time to be provided to queue limiting mechanisms.
Right, that is definitely required here. I also had a look at the gsi_channel_queue() function, which sits in the middle of the transmit function and is rather unoptimized. I'd suggest moving that into the caller so we can see what is going on, and then optimizing it from there.
Quoted 7 lines
- Not all receive endpoints use NAPI. The plan is for *all* endpoints to use NAPI. And because all endpoints share a common GSI interrupt, a single NAPI structure will used to managing the processing for all completions on all endpoints.
- Receive buffers are posted to the hardware by a workqueue function. Instead, the plan is to have this done by the NAPI poll routine.
Makes sense, yes.
Arnd
Rob Herring
maintainerRe: [RFC PATCH 01/12] dt-bindings: soc: qcom: add IPA bindings
In reply to Alex ElderQuoted 18 lines · Alex Elder
Add the binding definitions for the "qcom,ipa" and "qcom,rmnet-ipa" device tree nodes.
Signed-off-by Alex Elder <[email protected]>--- .../devicetree/bindings/soc/qcom/qcom,ipa.txt | 136 ++++++++++++++++++ .../bindings/soc/qcom/qcom,rmnet-ipa.txt | 15 ++ 2 files changed, 151 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txtDocumentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +0
-0
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 1
Quoted 1 line
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +1
-0@@ -0,0 +1,136 @@ +Qualcomm IPA (IP Accelerator) Driver
Bindings are for h/w not drivers.
Quoted 21 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +21
-0+ +This binding describes the Qualcomm IPA. The IPA is capable of offloading +certain network processing tasks (e.g. filtering, routing, and NAT) from +the main processor. The IPA currently serves only as a network interface, +providing access to an LTE network available via a modem. + +The IPA sits between multiple independent "execution environments," +including the AP subsystem (APSS) and the modem. The IPA presents +a Generic Software Interface (GSI) to each execution environment. +The GSI is an integral part of the IPA, but it is logically isolated +and has a distinct interrupt and a separately-defined address space. + + ---------- ------------- --------- + | | |G| |G| | | + | APSS |===|S| IPA |S|===| Modem | + | | |I| |I| | | + ---------- ------------- --------- + +See also: + bindings/interrupt-controller/interrupts.txt + bindings/interconnect/interconnect.txt
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 32
Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +10
-0+ bindings/soc/qcom/qcom,smp2p.txt + bindings/reserved-memory/reserved-memory.txt + bindings/clock/clock-bindings.txt + +All properties defined below are required. + +- compatible: + Must be one of the following compatible strings: + "qcom,ipa-sdm845-modem_init" + "qcom,ipa-sdm845-tz_init"
Normal order is <vendor>,<soc>-<ipblock>.
Don't use '_'.
What's the difference between these 2? It can't be detected somehow? This might be better expressed as a property. Then if Trustzone initializes things, it can just add a property.
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 35
Quoted 3 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +3
-0+ +-reg: + Resources specyfing the physical address spaces of the IPA and GSI.
typo
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 41
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +6
-0+ +-reg-names: + The names of the address space ranges defined by the "reg" property. + Must be "ipa" and "gsi". + +- interrupts-extended:
Use 'interrupts' here and describe what they are and the order. What they are connected to (and the need for interrupts-extended) is outside the scope of this binding.
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 51
Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +10
-0+ Specifies the IRQs used by the IPA. Four cells are required, + specifying: the IPA IRQ; the GSI IRQ; the clock query interrupt + from the modem; and the "ready for stage 2 initialization" + interrupt from the modem. The first two are hardware IRQs; the + third and fourth are SMP2P input interrupts. + +- interrupt-names: + The names of the interrupts defined by the "interrupts-extended" + property. Must be "ipa", "gsi", "ipa-clock-query", and + "ipa-post-init".
Format as one per line.
Quoted 44 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +44
-0+ +- clocks: + Resource that defines the IPA core clock. + +- clock-names: + The name used for the IPA core clock. Must be "core". + +- interconnects: + Specifies the interconnects used by the IPA. Three cells are + required, specifying: the path from the IPA to memory; from + IPA to internal (SoC resident) memory; and between the AP + subsystem and IPA for register access. + +- interconnect-names: + The names of the interconnects defined by the "interconnects" + property. Must be "memory", "imem", and "config". + +- qcom,smem-states + The state bits used for SMP2P output. Two cells must be specified. + The first indicates whether the value in the second bit is valid + (1 means valid). The second, if valid, defines whether the IPA + clock is enabled (1 means enabled). + +- qcom,smem-state-names + The names of the state bits used for SMP2P output. These must be + "ipa-clock-enabled-valid" and "ipa-clock-enabled". + +- memory-region + A phandle for a reserved memory area that holds the firmware passed + to Trust Zone for authentication. (Note, this is required + only for "qcom,ipa-sdm845-tz_init".) + += EXAMPLE + +The following example represents the IPA present in the SDM845 SoC. It +shows portions of the "modem-smp2p" node to indicate its relationship +with the interrupts and SMEM states used by the IPA. + + modem-smp2p { + compatible = "qcom,smp2p"; + . . . + ipa_smp2p_out: ipa-ap-to-modem { + qcom,entry-name = "ipa"; + #qcom,smem-state-cells = <1>;
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 105
Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +10
-0+ }; + + ipa_smp2p_in: ipa-modem-to-ap { + qcom,entry-name = "ipa"; + interrupt-controller; + #interrupt-cells = <2>; + }; + }; + + ipa at 1e00000 {
ipa at 1e40000
Quoted 37 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +31
-0+ compatible = "qcom,ipa-sdm845-modem_init"; + + reg = <0x1e40000 0x34000>, + <0x1e04000 0x2c000>; + reg-names = "ipa", + "gsi"; + + interrupts-extended = <&intc 0 311 IRQ_TYPE_LEVEL_HIGH>, + <&intc 0 432 IRQ_TYPE_LEVEL_HIGH>, + <&ipa_smp2p_in 0 IRQ_TYPE_EDGE_RISING>, + <&ipa_smp2p_in 1 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "ipa", + "gsi", + "ipa-clock-query", + "ipa-post-init"; + + clocks = <&rpmhcc RPMH_IPA_CLK>; + clock-names = "core"; + + interconnects = <&qnoc MASTER_IPA &qnoc SLAVE_EBI1>, + <&qnoc MASTER_IPA &qnoc SLAVE_IMEM>, + <&qnoc MASTER_APPSS_PROC &qnoc SLAVE_IPA_CFG>; + interconnect-names = "memory", + "imem", + "config"; + + qcom,smem-states = <&ipa_smp2p_out 0>, + <&ipa_smp2p_out 1>; + qcom,smem-state-names = "ipa-clock-enabled-valid", + "ipa-clock-enabled"; + };Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt new file +0
-0
Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt line 6
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt new file +6
-0@@ -0,0 +1,15 @@ +Qualcomm IPA RMNet Driver + +This binding describes the IPA RMNet driver, which is used to +represent virtual interfaces available on the modem accessed via +the IPA. Other than the compatible string there are no properties +associated with this device.
Only a compatible string is a sure sign this is not a h/w device and you are just abusing DT to instantiate drivers. Make the IPA driver instantiate any sub drivers it needs.
Rob
Re: [RFC PATCH 07/12] soc: qcom: ipa: IPA register abstraction
In reply to Alex ElderQuoted 10 lines · Alex Elder
drivers/net/ipa/ipa_reg.c new file +4
-0@@ -0,0 +1,972 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd.
drivers/net/ipa/ipa_reg.c line 14
Quoted 10 lines
drivers/net/ipa/ipa_reg.c new file +10
-0+*/ + +#include <linux/types.h> +#include <linux/io.h> +#include <linux/bitfield.h> + +#include "ipa_reg.h" + +/* I/O remapped base address of IPA register space */ +static void __iomem *ipa_reg_virt;
This should of course be part of the device structure.
drivers/net/ipa/ipa_reg.c line 28
Quoted 13 lines
drivers/net/ipa/ipa_reg.c new file +13
-0+/* struct ipa_reg_desc - descriptor for an abstracted hardware register +* +* @construct - fn to construct the register value from its field structure +* @parse - function to parse register field values into its field structure +* @offset - register offset relative to base address +* @n_ofst - size multiplier for "N-parameterized" registers +*/ +struct ipa_reg_desc { +u32 (*construct)(enum ipa_reg reg,const void *fields); +void (*parse)(enum ipa_reg reg,void *fields,u32 val); +u32 offset; +u16 n_ofst; +};
Indirect function pointers can be a bit expensive in the post-spectre days. It's probably not overly important if these are always part of an MMIO access function, but you should be careful about using these in the data path.
How many different versions do we have to support in practice?
Arnd
Re: [RFC PATCH 11/12] soc: qcom: ipa: IPA rmnet interface
In reply to Alex ElderQuoted 5 lines · Alex Elder
The IPA uses "rmnet" as a way to present remote network resources as if they were local to the AP. IPA interfaces representing networks accessible via the modem are represented as rmnet interfaces, implemented by the "rmnet data driver" found here:
drivers/net/ethernet/qualcomm/rmnet/
It looks like there's a lot of overlap between this driver and that one. Ideally they would be a single driver which could automatically select the IPA mode for appropriate hardware, or the IPA mode would be a "subdriver" that bases itself heavily on the existing rmnet driver even if it doesn't use the same packet movement functions. Or something like that.
But as Arnd stated, the ioctls won't fly. They were also proposed for the rmnet driver but they are better done as netlink, or via sysfs as the existing qmi_wwan driver does for some of the same values.
Half the non-extended ioctls aren't even supported/used and should simply be removed.
The extended ioctls should be evaluated as to whether they are really needed (eg RMNET_IOCTL_GET_DRIVER_NAME). I think most of the rest have either been handled already via the 'rmnet' driver itself (like the MUX channels using the vlan netlink attributes) or should be added via netlink-type mechansims if they are really required.
In general, it would be good to get to a single 'rmnet' driver that has a single API and supports as much hardware as possible. There's too much duplication currently.
Dan
Quoted 1,142 lines
The IPA is able to perform aggregation of packets, as well as checksum offload. These options (plus others, such as configuring MTU size) are configurable using an ioctl interface. In addition, rmnet devices support multiplexing.
TX packets are handed to the data path layer, and when their transmission is complete the notification callback will be called. The data path code posts RX packets to the hardware, and when they are filled they are supplied here by a receive notification callback.
The IPA driver currently does not support the modem shutting down (or crashing). But the
rmnet_ipadevice roughly represents the availability of networks reachable by the modem. If the modem is operational, anipa_rmnetnetwork device will be available. Modem operation is managed by the remoteproc subsystem.Note: This portion of the driver will be heavily affected by planned rework on the data path code.
Signed-off-by Alex Elder <[email protected]>--- drivers/net/ipa/msm_rmnet.h | 120 +++++ drivers/net/ipa/rmnet_config.h | 31 ++ drivers/net/ipa/rmnet_ipa.c | 805 +++++++++++++++++++++++++++++++++ 3 files changed, 956 insertions(+) create mode 100644 drivers/net/ipa/msm_rmnet.h create mode 100644 drivers/net/ipa/rmnet_config.h create mode 100644 drivers/net/ipa/rmnet_ipa.cdrivers/net/ipa/msm_rmnet.h new file +19
-0@@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd. +*/ +#ifndef _MSM_RMNET_H_ +#define _MSM_RMNET_H_ + +/* Bitmap macros for RmNET driver operation mode. */ +#define RMNET_MODE_NONE 0x00 +#define RMNET_MODE_LLP_ETH 0x01 +#define RMNET_MODE_LLP_IP 0x02 +#define RMNET_MODE_QOS 0x04 + +/* IOCTL commands +* Values chosen to not conflict with other drivers in the ecosystem +*/ + +#define RMNET_IOCTL_SET_LLP_ETHERNET 0x000089f1/* Set Ethernet protocol */
+#defineRMNET_IOCTL_SET_LLP_IP0x000089f2/* Set RAWIP
protocol */
+#defineRMNET_IOCTL_GET_LLP0x000089f3/* Get link
protocol */
+#defineRMNET_IOCTL_SET_QOS_ENABLE0x000089f4/* Set QoS header
enabled */
+#defineRMNET_IOCTL_SET_QOS_DISABLE0x000089f5/* Set QoS header disabled*/
+#defineRMNET_IOCTL_GET_QOS0x000089f6/* Get QoS header
state */
+#defineRMNET_IOCTL_GET_OPMODE0x000089f7/* Get
operation mode */
+#defineRMNET_IOCTL_OPEN0x000089f8/* Open transport
port */
+#defineRMNET_IOCTL_CLOSE0x000089f9/* Close transport
port */
+#defineRMNET_IOCTL_FLOW_ENABLE0x000089fa/* Flow
enable */
+#defineRMNET_IOCTL_FLOW_DISABLE0x000089fb/* Flow disable*/drivers/net/ipa/msm_rmnet.h new file +2
-0+#define RMNET_IOCTL_FLOW_SET_HNDL 0x000089fc/* Set flow handle */ +#define RMNET_IOCTL_EXTENDED 0x000089fd/* Extended IOCTLs */
drivers/net/ipa/msm_rmnet.h new file +3
-0+ +/* RmNet Data Required IOCTLs */ +#define RMNET_IOCTL_GET_SUPPORTED_FEATURES 0x0000/* Get features */
+#defineRMNET_IOCTL_SET_MRU0x0001/*
Set MRU */
+#defineRMNET_IOCTL_GET_MRU0x0002/*
Get MRU */
+#defineRMNET_IOCTL_GET_EPID0x0003/*
Get endpoint ID */
+#defineRMNET_IOCTL_GET_DRIVER_NAME0x0004/*
Get driver name */
+#defineRMNET_IOCTL_ADD_MUX_CHANNEL0x0005/*
Add MUX ID */
+#defineRMNET_IOCTL_SET_EGRESS_DATA_FORMAT0x0006/* Set
EDF */
+#defineRMNET_IOCTL_SET_INGRESS_DATA_FORMAT0x0007/* Set
IDF */
+#defineRMNET_IOCTL_SET_AGGREGATION_COUNT0x0008/* Set
agg count */
+#defineRMNET_IOCTL_GET_AGGREGATION_COUNT0x0009/* Get
agg count */
+#defineRMNET_IOCTL_SET_AGGREGATION_SIZE0x000a/* Set
agg size */
+#defineRMNET_IOCTL_GET_AGGREGATION_SIZE0x000b/* Get
agg size */
+#defineRMNET_IOCTL_FLOW_CONTROL0x000c/* Do
flow control */
+#defineRMNET_IOCTL_GET_DFLT_CONTROL_CHANNEL0x000d/* For
legacy use */
+#defineRMNET_IOCTL_GET_HWSW_MAP0x000e/* Get
HW/SW map */
+#defineRMNET_IOCTL_SET_RX_HEADROOM0x000f/*
RX Headroom */
+#defineRMNET_IOCTL_GET_EP_PAIR0x0010
/* Endpoint pair */
+#defineRMNET_IOCTL_SET_QOS_VERSION0x0011/*
8/6 byte QoS hdr*/
+#defineRMNET_IOCTL_GET_QOS_VERSION0x0012/*
8/6 byte QoS hdr*/
+#defineRMNET_IOCTL_GET_SUPPORTED_QOS_MODES0x0013/* Get
QoS modes */
+#defineRMNET_IOCTL_SET_SLEEP_STATE0x0014/*
Set sleep state */
+#defineRMNET_IOCTL_SET_XLAT_DEV_INFO0x0015/*
xlat dev name */
+#defineRMNET_IOCTL_DEREGISTER_DEV0x0016/*
Dereg a net dev */
+#defineRMNET_IOCTL_GET_SG_SUPPORT0x0017/*
Query sg support*/drivers/net/ipa/msm_rmnet.h new file +4
-0+ +/* Return values for the RMNET_IOCTL_GET_SUPPORTED_FEATURES IOCTL */ +#define RMNET_IOCTL_FEAT_NOTIFY_MUX_CHANNEL BIT(0) +#define RMNET_IOCTL_FEAT_SET_EGRESS_DATA_FORMAT BIT(1)
drivers/net/ipa/msm_rmnet.h new file +19
-0+#define RMNET_IOCTL_FEAT_SET_INGRESS_DATA_FORMAT BIT(2) + +/* Input values for the RMNET_IOCTL_SET_EGRESS_DATA_FORMAT IOCTL */ +#define RMNET_IOCTL_EGRESS_FORMAT_AGGREGATION BIT(2) +#define RMNET_IOCTL_EGRESS_FORMAT_CHECKSUM BIT(4) + +/* Input values for the RMNET_IOCTL_SET_INGRESS_DATA_FORMAT IOCTL */ +#define RMNET_IOCTL_INGRESS_FORMAT_CHECKSUM BIT(4) +#define RMNET_IOCTL_INGRESS_FORMAT_AGG_DATA BIT(5) + +/* User space may not have this defined. */ +#ifndef IFNAMSIZ +#define IFNAMSIZ 16 +#endif + +struct rmnet_ioctl_extended_s { +u32 extended_ioctl; +union { +u32 data;/* Generic data field for most extended IOCTLs */
drivers/net/ipa/msm_rmnet.h new file +8
-0+ +/* Return values for +* RMNET_IOCTL_GET_DRIVER_NAME +* RMNET_IOCTL_GET_DFLT_CONTROL_CHANNEL +*/ +char if_name[IFNAMSIZ ]; + +/* Input values for the RMNET_IOCTL_ADD_MUX_CHANNEL IOCTL */
drivers/net/ipa/msm_rmnet.h new file +6
-0+struct { +u32 mux_id; +char vchannel_name[IFNAMSIZ ]; + } rmnet_mux_val; + +/* Input values for the RMNET_IOCTL_FLOW_CONTROL IOCTL */
drivers/net/ipa/msm_rmnet.h new file +13
-0+struct { +u8 flow_mode; +u8 mux_id; + } flow_control_prop; + +/* Return values for RMNET_IOCTL_GET_EP_PAIR */ +struct { +u32 consumer_pipe_num; +u32 producer_pipe_num; + } ipa_ep_pair; + +struct { +u32 __data;/* Placeholder for legacy data*/
drivers/net/ipa/msm_rmnet.h new file +13
-0+u32 agg_size; + u32 agg_count; + } ingress_format; + } u; +}; + +struct rmnet_ioctl_data_s { +union { +u32 operation_mode; +u32 tcm_handle; + } u; +}; +#endif /* _MSM_RMNET_H_ */ drivers/net/ipa/rmnet_config.h new file +3
-0@@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ * Copyright (C) 2018 Linaro Ltd.
+ */drivers/net/ipa/rmnet_config.h new file +6
-0+#ifndef _RMNET_CONFIG_H_ +#define _RMNET_CONFIG_H_ + +#include <linux/types.h> + +/* XXX We want to use struct rmnet_map_header, but that's currently defined in
+ * XXXdrivers/net/ethernet/qualcomm/rmnet/rmnet_map.h
+ * XXX We also want to useRMNET_MAP_GET_CD_BIT(Y), defined in the same file.
+ */drivers/net/ipa/rmnet_config.h new file +15
-0+struct rmnet_map_header_s { +#ifndef RMNET_USE_BIG_ENDIAN_STRUCTS +u8 pad_len :6 , + reserved_bit :1 , + cd_bit :1 ; +#else +u8 cd_bit :1 , + reserved_bit :1 , + pad_len :6 ; +#endif /* RMNET_USE_BIG_ENDIAN_STRUCTS */ +u8 mux_id; +u16 pkt_len; +}__aligned(1) ; + +#define RMNET_MAP_GET_CD_BIT (Y ) (((struct rmnet_map_header_s *)Y-Quoted 1 line
data)->cd_bit)
drivers/net/ipa/rmnet_config.h new file +2
-0+ +#endif /* _RMNET_CONFIG_H_ */ drivers/net/ipa/rmnet_ipa.c new file +3
-0@@ -0,0 +1,805 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
+ * Copyright (C) 2018 Linaro Ltd.
+ */drivers/net/ipa/rmnet_ipa.c new file +27
-0+ +/* WWAN Transport Network Driver. */ + +#include <linux/completion.h> +#include <linux/errno.h> +#include <linux/if_arp.h> +#include <linux/interrupt.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/netdevice.h> +#include <linux/of_device.h> +#include <linux/string.h> +#include <linux/skbuff.h> +#include <linux/version.h> +#include <linux/workqueue.h> +#include <net/pkt_sched.h> + +#include "msm_rmnet.h" +#include "rmnet_config.h" +#include "ipa_qmi.h" +#include "ipa_i.h" + +#define DRIVER_NAME "wwan_ioctl" +#define IPA_WWAN_DEV_NAME "rmnet_ipa%d" + +#define MUX_CHANNEL_MAX 10/* max mux channels */
drivers/net/ipa/rmnet_ipa.c new file +6
-0+ +#define NAPI_WEIGHT 60 + +#define WWAN_DATA_LEN 2000 +#define HEADROOM_FOR_QMAP 8/* for mux header */ +#define TAILROOM 0/* for padding by mux layer */
drivers/net/ipa/rmnet_ipa.c new file +3
-0+ +#define DEFAULT_OUTSTANDING_HIGH 128 +#define DEFAULT_OUTSTANDING_HIGH_CTL (DEFAULT_OUTSTANDING_HIGH + 32)
drivers/net/ipa/rmnet_ipa.c new file +27
-0+#define DEFAULT_OUTSTANDING_LOW 64 + +#define IPA_APPS_WWAN_CONS_RING_COUNT 256 +#define IPA_APPS_WWAN_PROD_RING_COUNT 512 + +static int ipa_rmnet_poll (struct napi_struct *napi,int budget); + +/** struct ipa_wwan_private - WWAN private data +* @net: network interface struct implemented by this driver +* @stats: iface statistics +* @outstanding_high: number of outstanding packets allowed +* @outstanding_low: number of outstanding packets which shall cause +* +* WWAN private - holds all relevant info about WWAN driver +*/ +struct ipa_wwan_private { +struct net_device_stats stats; +atomic_t outstanding_pkts; +int outstanding_high_ctl; +int outstanding_high; +int outstanding_low; +struct napi_struct napi; +}; + +struct rmnet_ipa_context { +struct net_device *dev; +struct mutex mux_id_mutex;/* protects mux_id[] */
drivers/net/ipa/rmnet_ipa.c new file +5
-0+u32 mux_id_count; +u32 mux_id[MUX_CHANNEL_MAX ]; +u32 wan_prod_ep_id; +u32 wan_cons_ep_id; +struct mutex ep_setup_mutex;/* endpoint setup/teardown */
drivers/net/ipa/rmnet_ipa.c new file +6
-0+}; + +static bool initialized;/* Avoid duplicate initialization */ + +static struct rmnet_ipa_context rmnet_ipa_ctx_struct; +static struct rmnet_ipa_context *rmnet_ipa_ctx =
&rmnet_ipa_ctx_struct;drivers/net/ipa/rmnet_ipa.c new file +30
-0+ +/** wwan_open() - Opens the wwan network interface */ +static int ipa_wwan_open (struct net_device *dev) +{ +struct ipa_wwan_private *wwan_ptr =netdev_priv (dev); + +napi_enable (&wwan_ptr->napi); +netif_start_queue (dev); + +return 0 ; +} + +/** ipa_wwan_stop() - Stops the wwan network interface. */ +static int ipa_wwan_stop (struct net_device *dev) +{ +netif_stop_queue (dev); + +return 0 ; +} + +/** ipa_wwan_xmit() - Transmits an skb. +* +* @skb: skb to be transmitted +* @dev: network device +* +* Return codes: +* NETDEV_TX_OK: Success +* NETDEV_TX_BUSY: Error while transmitting the skb. Try again later +*/ +static int ipa_wwan_xmit(struct sk_buff *skb, struct net_device*dev)
drivers/net/ipa/rmnet_ipa.c new file +48
-0+{ +struct ipa_wwan_private *wwan_ptr =netdev_priv (dev); +unsigned int skb_len; +int outstanding; + +if (skb->protocol !=htons (ETH_P_MAP )) { +dev_kfree_skb_any (skb); + dev->stats.tx_dropped++; +return NETDEV_TX_OK ; + } + +/* Control packets are sent even if queue is stopped. We +* always honor the data and control high-water marks. +*/ + outstanding =atomic_read (&wwan_ptr->outstanding_pkts); +if (!RMNET_MAP_GET_CD_BIT (skb)) {/* Data packet? */ +if (netif_queue_stopped (dev)) +return NETDEV_TX_BUSY ; +if (outstanding >= wwan_ptr->outstanding_high) +return NETDEV_TX_BUSY ; + }else if (outstanding >= wwan_ptr->outstanding_high_ctl) { +return NETDEV_TX_BUSY ; + } + +/* both data packets and commands will be routed to +* IPA_CLIENT_Q6_WAN_CONS based on status configuration. +*/ + skb_len = skb->len; +if (ipa_tx_dp (IPA_CLIENT_APPS_WAN_PROD , skb)) +return NETDEV_TX_BUSY ; + +atomic_inc (&wwan_ptr->outstanding_pkts); + dev->stats.tx_packets++; + dev->stats.tx_bytes += skb_len; + +return NETDEV_TX_OK ; +} + +/** apps_ipa_tx_complete_notify() - Rx notify +* +* @priv: driver context +* @evt: event type +* @data: data provided with event +* +* Check that the packet is the one we sent and release it +* This function will be called in defered context in IPA wq. +*/ +static void apps_ipa_tx_complete_notify(void *priv, enum
ipa_dp_evt_typeevt,drivers/net/ipa/rmnet_ipa.c new file +15
-0+ unsigned long data) +{ +struct ipa_wwan_private *wwan_ptr; +struct net_device *dev = priv; +struct sk_buff *skb; + + skb = (struct sk_buff *)data; + +if (dev != rmnet_ipa_ctx->dev) { +dev_kfree_skb_any (skb); +return ; + } + +if (evt !=IPA_WRITE_DONE ) { + ipa_err("unsupported evt on Tx callback, Drop thepacket\n");
drivers/net/ipa/rmnet_ipa.c new file +27
-0+dev_kfree_skb_any (skb); + dev->stats.tx_dropped++; +return ; + } + + wwan_ptr =netdev_priv (dev); +atomic_dec (&wwan_ptr->outstanding_pkts); +__netif_tx_lock_bh (netdev_get_tx_queue (dev,0 )); +if (netif_queue_stopped (dev) && +atomic_read (&wwan_ptr->outstanding_pkts) < + wwan_ptr->outstanding_low) { +netif_wake_queue (dev); + } + +__netif_tx_unlock_bh (netdev_get_tx_queue (dev,0 )); +dev_kfree_skb_any (skb); +} + +/** apps_ipa_packet_receive_notify() - Rx notify +* +* @priv: driver context +* @evt: event type +* @data: data provided with event +* +* IPA will pass a packet to the Linux network stack with skb->data +*/ +static void apps_ipa_packet_receive_notify(void *priv, enum
ipa_dp_evt_typeevt,drivers/net/ipa/rmnet_ipa.c new file +17
-0+ unsigned long data) +{ +struct ipa_wwan_private *wwan_ptr; +struct net_device *dev = priv; + + wwan_ptr =netdev_priv (dev); +if (evt ==IPA_RECEIVE ) { +struct sk_buff *skb = (struct sk_buff *)data; +int ret; +unsigned int packet_len = skb->len; + + skb->dev = rmnet_ipa_ctx->dev; + skb->protocol =htons (ETH_P_MAP ); + + ret =netif_receive_skb (skb); +if (ret) { + pr_err_ratelimited("fail onnetif_receive_skb\n");
drivers/net/ipa/rmnet_ipa.c new file +10
-0+ dev->stats.rx_dropped++; + } + dev->stats.rx_packets++; + dev->stats.rx_bytes += packet_len; + }else if (evt ==IPA_CLIENT_START_POLL ) { +napi_schedule (&wwan_ptr->napi); + }else if (evt ==IPA_CLIENT_COMP_NAPI ) { +napi_complete (&wwan_ptr->napi); + }else { + ipa_err("Invalid evt %d received inwan_ipa_receive\n", evt);
drivers/net/ipa/rmnet_ipa.c new file +25
-0+ } +} + +/** handle_ingress_format() - Ingress data format configuration */ +static int handle_ingress_format (struct net_device *dev, +struct rmnet_ioctl_extended_s *in) +{ +enum ipa_cs_offload_en offload_type; +enum ipa_client_type client; +u32 metadata_offset; +u32 rx_buffer_size; +u32 channel_count; +u32 length_offset; +u32 header_size; +bool aggr_active; +u32 aggr_bytes; +u32 aggr_count; +u32 aggr_size;/* in KB */ +u32 ep_id; +int ret; + + client =IPA_CLIENT_APPS_WAN_CONS ; + channel_count =IPA_APPS_WWAN_CONS_RING_COUNT ; + header_size =sizeof (struct rmnet_map_header_s ); + metadata_offset = offsetof(struct rmnet_map_header_s,
mux_id);drivers/net/ipa/rmnet_ipa.c new file +1
-0+ length_offset = offsetof(struct rmnet_map_header_s,
pkt_len);drivers/net/ipa/rmnet_ipa.c new file +104
-0+ offload_type =IPA_CS_OFFLOAD_NONE ; + aggr_bytes =IPA_GENERIC_AGGR_BYTE_LIMIT ; + aggr_count =IPA_GENERIC_AGGR_PKT_LIMIT ; + aggr_active = false; + +if (in->u.data &RMNET_IOCTL_INGRESS_FORMAT_CHECKSUM ) + offload_type =IPA_CS_OFFLOAD_DL ; + +if (in->u.data &RMNET_IOCTL_INGRESS_FORMAT_AGG_DATA ) { + aggr_bytes = in->u.ingress_format.agg_size; + aggr_count = in->u.ingress_format.agg_count; + aggr_active = true; + } + +if (aggr_bytes >ipa_reg_aggr_max_byte_limit ()) +return -EINVAL ; + +if (aggr_count >ipa_reg_aggr_max_packet_limit ()) +return -EINVAL ; + +/* Compute the buffer size required to handle the requested +* aggregation byte limit. The aggr_byte_limit value is +* expressed as a number of KB, but we derive that value +* after computing the buffer size to use (in bytes). The +* buffer must be sufficient to hold one IPA_MTU-sized +* packet *after* the limit is reached. +* +* (Note that the rx_buffer_size value reflects only the +* space for data, not any standard metadata or headers.) +*/ + rx_buffer_size =ipa_aggr_byte_limit_buf_size (aggr_bytes); + +/* Account for the extra IPA_MTU past the limit in the +* buffer, and convert the result to the KB units the +* aggr_byte_limit uses. +*/ + aggr_size = (rx_buffer_size -IPA_MTU ) /SZ_1K ; + +mutex_lock (&rmnet_ipa_ctx->ep_setup_mutex); + +if (rmnet_ipa_ctx->wan_cons_ep_id !=IPA_EP_ID_BAD ) { + ret = -EBUSY ; + goto out_unlock; + } + + ret =ipa_ep_alloc (client); +if (ret <0 ) + goto out_unlock; + ep_id = ret; + +/* Record our endpoint configuration parameters */ +ipa_endp_init_hdr_cons (ep_id, header_size, metadata_offset, + length_offset); +ipa_endp_init_hdr_ext_cons (ep_id,0 , true); +ipa_endp_init_aggr_cons (ep_id, aggr_size, aggr_count, true); +ipa_endp_init_cfg_cons (ep_id, offload_type); +ipa_endp_init_hdr_metadata_mask_cons (ep_id,0xff000000 ); +ipa_endp_status_cons (ep_id, !aggr_active); + + ipa_ctx->ipa_client_apps_wan_cons_agg_gro = aggr_active; + + ret =ipa_ep_setup (ep_id, channel_count,1 , rx_buffer_size, + apps_ipa_packet_receive_notify, dev); +if (ret) +ipa_ep_free (ep_id); +else + rmnet_ipa_ctx->wan_cons_ep_id = ep_id; +out_unlock: +mutex_unlock (&rmnet_ipa_ctx->ep_setup_mutex); + +return ret; +} + +/** handle_egress_format() - Egress data format configuration */ +static int handle_egress_format (struct net_device *dev, +struct rmnet_ioctl_extended_s *e) +{ +enum ipa_cs_offload_en offload_type; +enum ipa_client_type dst_client; +enum ipa_client_type client; +enum ipa_aggr_type aggr_type; +enum ipa_aggr_en aggr_en; +u32 channel_count; +u32 length_offset; +u32 header_align; +u32 header_offset; +u32 header_size; +u32 ep_id; +int ret; + + client =IPA_CLIENT_APPS_WAN_PROD ; + dst_client =IPA_CLIENT_APPS_LAN_CONS ; + channel_count =IPA_APPS_WWAN_PROD_RING_COUNT ; + header_size =sizeof (struct rmnet_map_header_s ); + offload_type =IPA_CS_OFFLOAD_NONE ; + aggr_en =IPA_BYPASS_AGGR ; + aggr_type =0 ;/* ignored if BYPASS */ + header_offset =0 ; + length_offset =0 ; + header_align =0 ; + +if (e->u.data &RMNET_IOCTL_EGRESS_FORMAT_CHECKSUM ) { + offload_type =IPA_CS_OFFLOAD_UL ; + header_offset = sizeof(struct rmnet_map_header_s) /4;
drivers/net/ipa/rmnet_ipa.c new file +7
-0+ header_size +=sizeof (u32); + } + +if (e->u.data &RMNET_IOCTL_EGRESS_FORMAT_AGGREGATION ) { + aggr_en =IPA_ENABLE_DEAGGR ; + aggr_type =IPA_QCMAP ; + length_offset = offsetof(struct rmnet_map_header_s,
pkt_len);drivers/net/ipa/rmnet_ipa.c new file +16
-0+ header_align =ilog2 (sizeof (u32)); + } + +mutex_lock (&rmnet_ipa_ctx->ep_setup_mutex); + +if (rmnet_ipa_ctx->wan_prod_ep_id !=IPA_EP_ID_BAD ) { + ret = -EBUSY ; + goto out_unlock; + } + + ret =ipa_ep_alloc (client); +if (ret <0 ) + goto out_unlock; + ep_id = ret; + + if (aggr_en == IPA_ENABLE_DEAGGR &&!ipa_endp_aggr_support(ep_id)) {
drivers/net/ipa/rmnet_ipa.c new file +6
-0+ ret = -ENOTSUPP ; + goto out_unlock; + } + +/* We really do want 0 metadata offset */ + ipa_endp_init_hdr_prod(ep_id, header_size, 0,
length_offset);drivers/net/ipa/rmnet_ipa.c new file +12
-0+ipa_endp_init_hdr_ext_prod (ep_id, header_align); +ipa_endp_init_mode_prod (ep_id,IPA_BASIC , dst_client); +ipa_endp_init_aggr_prod (ep_id, aggr_en, aggr_type); +ipa_endp_init_cfg_prod (ep_id, offload_type, header_offset); +ipa_endp_init_seq_prod (ep_id); +ipa_endp_init_deaggr_prod (ep_id); +/* Enable source notification status for exception packets +* (i.e. QMAP commands) to be routed to modem. +*/ +ipa_endp_status_prod (ep_id, true,IPA_CLIENT_Q6_WAN_CONS ); + +/* Use a deferred interrupting no-op to reduce completion interrupts */
drivers/net/ipa/rmnet_ipa.c new file +35
-0+ipa_no_intr_init (ep_id); + + ret =ipa_ep_setup (ep_id, channel_count,1 ,0 , + apps_ipa_tx_complete_notify, dev); +if (ret) +ipa_ep_free (ep_id); +else + rmnet_ipa_ctx->wan_prod_ep_id = ep_id; + +out_unlock: +mutex_unlock (&rmnet_ipa_ctx->ep_setup_mutex); + +return ret; +} + +/** ipa_wwan_add_mux_channel() - add a mux_id */ +static int ipa_wwan_add_mux_channel (u32 mux_id) +{ +int ret; +u32 i; + +mutex_lock (&rmnet_ipa_ctx->mux_id_mutex); + +if (rmnet_ipa_ctx->mux_id_count >=MUX_CHANNEL_MAX ) { + ret = -EFAULT ; + goto out; + } + +for (i =0 ; i < rmnet_ipa_ctx->mux_id_count; i++) +if (mux_id == rmnet_ipa_ctx->mux_id[i]) +break ; + +/* Record the mux_id if it hasn't already been seen */ +if (i == rmnet_ipa_ctx->mux_id_count) + rmnet_ipa_ctx->mux_id[rmnet_ipa_ctx->mux_id_count++]=
mux_id;drivers/net/ipa/rmnet_ipa.c new file +9
-0+ ret =0 ; +out: +mutex_unlock (&rmnet_ipa_ctx->mux_id_mutex); + +return ret; +} + +/** ipa_wwan_ioctl_extended() - rmnet extended I/O control */ +static int ipa_wwan_ioctl_extended(struct net_device *dev, void
__user*data)drivers/net/ipa/rmnet_ipa.c new file +9
-0+{ +struct rmnet_ioctl_extended_s edata = { }; +size_t size =sizeof (edata); + +if (copy_from_user (&edata, data, size)) +return -EFAULT ; + +switch (edata.extended_ioctl) { +case RMNET_IOCTL_GET_SUPPORTED_FEATURES :/* Get features */
drivers/net/ipa/rmnet_ipa.c new file +2
-0+ edata.u.data =RMNET_IOCTL_FEAT_NOTIFY_MUX_CHANNEL ; + edata.u.data |=
RMNET_IOCTL_FEAT_SET_EGRESS_DATA_FORMAT;drivers/net/ipa/rmnet_ipa.c new file +1
-0+ edata.u.data |=
RMNET_IOCTL_FEAT_SET_INGRESS_DATA_FORMAT;drivers/net/ipa/rmnet_ipa.c new file +3
-0+ goto copy_out; + +case RMNET_IOCTL_GET_EPID :/* Get endpoint ID */
drivers/net/ipa/rmnet_ipa.c new file +4
-0+ edata.u.data =1 ; + goto copy_out; + +case RMNET_IOCTL_GET_DRIVER_NAME :/* Get driver name */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+ memcpy(&edata.u.if_name, rmnet_ipa_ctx->dev->name,IFNAMSIZ);
drivers/net/ipa/rmnet_ipa.c new file +3
-0+ goto copy_out; + +case RMNET_IOCTL_ADD_MUX_CHANNEL :/* Add MUX ID */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+return
ipa_wwan_add_mux_channel(edata.u.rmnet_mux_val.mux_id);drivers/net/ipa/rmnet_ipa.c new file +2
-0+ +case RMNET_IOCTL_SET_EGRESS_DATA_FORMAT :/* Egress data format */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+ return handle_egress_format(dev, &edata) ? -EFAULT :0;
drivers/net/ipa/rmnet_ipa.c new file +2
-0+ +case RMNET_IOCTL_SET_INGRESS_DATA_FORMAT :/* Ingress format */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+ return handle_ingress_format(dev, &edata) ? -EFAULT: 0;
drivers/net/ipa/rmnet_ipa.c new file +2
-0+ +case RMNET_IOCTL_GET_EP_PAIR :/* Get endpoint pair */
drivers/net/ipa/rmnet_ipa.c new file +2
-0+ edata.u.ipa_ep_pair.consumer_pipe_num = + ipa_client_ep_id(IPA_CLIENT_APPS_WAN
_PROD);drivers/net/ipa/rmnet_ipa.c new file +2
-0+ edata.u.ipa_ep_pair.producer_pipe_num = + ipa_client_ep_id(IPA_CLIENT_APPS_WAN
_CONS);drivers/net/ipa/rmnet_ipa.c new file +3
-0+ goto copy_out; + +case RMNET_IOCTL_GET_SG_SUPPORT :/* Get SG support */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+ edata.u.data =1 ;/* Scatter/gather is always supported */
drivers/net/ipa/rmnet_ipa.c new file +4
-0+ goto copy_out; + +/* Unsupported requests */ +case RMNET_IOCTL_SET_MRU :/* Set MRU */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_GET_MRU :/* Get MRU */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_GET_AGGREGATION_COUNT :/* Get agg count */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_SET_AGGREGATION_COUNT :/* Set agg count */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_GET_AGGREGATION_SIZE :/* Get agg size */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_SET_AGGREGATION_SIZE :/* Set agg size */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_FLOW_CONTROL :/* Do flow control */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_GET_DFLT_CONTROL_CHANNEL :/* For legacy use */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_GET_HWSW_MAP :/* Get HW/SW map */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_SET_RX_HEADROOM :/* Set RX Headroom */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_SET_QOS_VERSION :/* Set 8/6 byte QoS */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_GET_QOS_VERSION :/* Get 8/6 byte QoS */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_GET_SUPPORTED_QOS_MODES :/* Get QoS modes */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_SET_SLEEP_STATE :/* Set sleep state */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_SET_XLAT_DEV_INFO :/* xlat dev name */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_DEREGISTER_DEV :/* Deregister netdev */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+return -ENOTSUPP ;/* Defined, but unsupported command */
drivers/net/ipa/rmnet_ipa.c new file +3
-0+ +default : +return -EINVAL ;/* Invalid (unrecognized) command */
drivers/net/ipa/rmnet_ipa.c new file +8
-0+ } + +copy_out: +return copy_to_user (data, &edata, size) ? -EFAULT :0 ; +} + +/** ipa_wwan_ioctl() - I/O control for wwan network driver */ +static int ipa_wwan_ioctl(struct net_device *dev, struct ifreq *ifr,int cmd)
drivers/net/ipa/rmnet_ipa.c new file +10
-0+{ +struct rmnet_ioctl_data_s ioctl_data = { }; +void __user *data; +size_t size; + + data = ifr->ifr_ifru.ifru_data; + size =sizeof (ioctl_data); + +switch (cmd) { +/* These features are implied; alternatives are not supported */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_SET_LLP_IP :/* RAW IP protocol */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_SET_QOS_DISABLE :/* QoS header disabled */
drivers/net/ipa/rmnet_ipa.c new file +4
-0+return 0 ; + +/* These features are not supported; use alternatives */ +case RMNET_IOCTL_SET_LLP_ETHERNET :/* Ethernet protocol */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_SET_QOS_ENABLE :/* QoS header enabled */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_GET_OPMODE :/* Get operation mode */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_FLOW_ENABLE :/* Flow enable */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_FLOW_DISABLE :/* Flow disable */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_FLOW_SET_HNDL :/* Set flow handle */
drivers/net/ipa/rmnet_ipa.c new file +3
-0+return -ENOTSUPP ; + +case RMNET_IOCTL_GET_LLP :/* Get link protocol */
drivers/net/ipa/rmnet_ipa.c new file +4
-0+ ioctl_data.u.operation_mode =RMNET_MODE_LLP_IP ; + goto copy_out; + +case RMNET_IOCTL_GET_QOS :/* Get QoS header state */
drivers/net/ipa/rmnet_ipa.c new file +4
-0+ ioctl_data.u.operation_mode =RMNET_MODE_NONE ; + goto copy_out; + +case RMNET_IOCTL_OPEN :/* Open transport port */
drivers/net/ipa/rmnet_ipa.c new file +1
-0+case RMNET_IOCTL_CLOSE :/* Close transport port */
drivers/net/ipa/rmnet_ipa.c new file +3
-0+return 0 ; + +case RMNET_IOCTL_EXTENDED :/* Extended IOCTLs */
drivers/net/ipa/rmnet_ipa.c new file +23
-0+return ipa_wwan_ioctl_extended (dev, data); + +default : +return -EINVAL ; + } + +copy_out: +return copy_to_user (data, &ioctl_data, size) ? -EFAULT :0 ; +} + +static const struct net_device_ops ipa_wwan_ops_ip = { + .ndo_open = ipa_wwan_open, + .ndo_stop = ipa_wwan_stop, + .ndo_start_xmit = ipa_wwan_xmit, + .ndo_do_ioctl = ipa_wwan_ioctl, +}; + +/** wwan_setup() - Setup the wwan network driver */ +static void ipa_wwan_setup (struct net_device *dev) +{ + dev->netdev_ops = &ipa_wwan_ops_ip; +ether_setup (dev); + dev->header_ops =NULL ;/* No header (override
ether_setup()value) */drivers/net/ipa/rmnet_ipa.c new file +45
-0+ dev->type =ARPHRD_RAWIP ; + dev->hard_header_len =0 ; + dev->max_mtu =WWAN_DATA_LEN ; + dev->mtu = dev->max_mtu; + dev->addr_len =0 ; + dev->flags &= ~(IFF_BROADCAST |IFF_MULTICAST ); + dev->needed_headroom =HEADROOM_FOR_QMAP ; + dev->needed_tailroom =TAILROOM ; + dev->watchdog_timeo =msecs_to_jiffies (10 *MSEC_PER_SEC ); +} + +/** ipa_wwan_probe() - Network probe function */ +static int ipa_wwan_probe (struct platform_device *pdev) +{ +struct ipa_wwan_private *wwan_ptr; +struct net_device *dev; +int ret; + +mutex_init (&rmnet_ipa_ctx->ep_setup_mutex); +mutex_init (&rmnet_ipa_ctx->mux_id_mutex); + +/* Mark client handles bad until we initialize them */ + rmnet_ipa_ctx->wan_prod_ep_id =IPA_EP_ID_BAD ; + rmnet_ipa_ctx->wan_cons_ep_id =IPA_EP_ID_BAD ; + + ret =ipa_modem_smem_init (); +if (ret) + goto err_clear_ctx; + +/* start A7 QMI service/client */ +ipa_qmi_init (); + +/* initialize wan-driver netdev */ + dev =alloc_netdev (sizeof (struct ipa_wwan_private ), +IPA_WWAN_DEV_NAME , +NET_NAME_UNKNOWN , + ipa_wwan_setup); +if (!dev) { +ipa_err ("no memory for netdev\n" ); + ret = -ENOMEM ; + goto err_clear_ctx; + } + rmnet_ipa_ctx->dev = dev; + wwan_ptr =netdev_priv (dev); + wwan_ptr->outstanding_high_ctl =
DEFAULT_OUTSTANDING_HIGH_CTL;drivers/net/ipa/rmnet_ipa.c new file +8
-0+ wwan_ptr->outstanding_high =DEFAULT_OUTSTANDING_HIGH ; + wwan_ptr->outstanding_low =DEFAULT_OUTSTANDING_LOW ; +atomic_set (&wwan_ptr->outstanding_pkts,0 ); + +/* Enable SG support in netdevice. */ + dev->hw_features |=NETIF_F_SG ; + + netif_napi_add(dev, &wwan_ptr->napi, ipa_rmnet_poll,
NAPI_WEIGHT);drivers/net/ipa/rmnet_ipa.c new file +3
-0+ ret =register_netdev (dev); +if (ret) { + ipa_err("unable to register ipa_netdev %d rc=%d\n",0, ret);
drivers/net/ipa/rmnet_ipa.c new file +18
-0+ goto err_napi_del; + } + +/* offline charging mode */ +ipa_proxy_clk_unvote (); + +/* Till the system is suspended, we keep the clock open */ +ipa_client_add (); + + initialized = true; + +return 0 ; + +err_napi_del: +netif_napi_del (&wwan_ptr->napi); +free_netdev (dev); +err_clear_ctx: + memset(&rmnet_ipa_ctx_struct, 0,
sizeof(rmnet_ipa_ctx_struct));drivers/net/ipa/rmnet_ipa.c new file +7
-0+ +return ret; +} + +static int ipa_wwan_remove (struct platform_device *pdev) +{ + struct ipa_wwan_private *wwan_ptr =
netdev_priv(rmnet_ipa_ctx->dev);drivers/net/ipa/rmnet_ipa.c new file +2
-0+ + dev_info(&pdev->dev, "rmnet_ipa starteddeinitialization\n");
drivers/net/ipa/rmnet_ipa.c new file +31
-0+ +mutex_lock (&rmnet_ipa_ctx->ep_setup_mutex); + +ipa_client_add (); + +if (rmnet_ipa_ctx->wan_cons_ep_id !=IPA_EP_ID_BAD ) { +ipa_ep_teardown (rmnet_ipa_ctx->wan_cons_ep_id); + rmnet_ipa_ctx->wan_cons_ep_id =IPA_EP_ID_BAD ; + } + +if (rmnet_ipa_ctx->wan_prod_ep_id !=IPA_EP_ID_BAD ) { +ipa_ep_teardown (rmnet_ipa_ctx->wan_prod_ep_id); + rmnet_ipa_ctx->wan_prod_ep_id =IPA_EP_ID_BAD ; + } + +ipa_client_remove (); + +netif_napi_del (&wwan_ptr->napi); +mutex_unlock (&rmnet_ipa_ctx->ep_setup_mutex); +unregister_netdev (rmnet_ipa_ctx->dev); + +if (rmnet_ipa_ctx->dev) +free_netdev (rmnet_ipa_ctx->dev); + rmnet_ipa_ctx->dev =NULL ; + +mutex_destroy (&rmnet_ipa_ctx->mux_id_mutex); +mutex_destroy (&rmnet_ipa_ctx->ep_setup_mutex); + + initialized = false; + + dev_info(&pdev->dev, "rmnet_ipa completeddeinitialization\n");
drivers/net/ipa/rmnet_ipa.c new file +8
-0+ +return 0 ; +} + +/** rmnet_ipa_ap_suspend() - suspend callback for runtime_pm +* @dev: pointer to device +* +* This callback will be invoked by the runtime_pm framework when an AP suspend
+ * operation is invoked, usually by pressing a suspend button.
+ *
+ * Returns-EAGAINtoruntime_pmframework in case there are pending packets
+ * in the Tx queue. This will postpone the suspend operation until all the
+ * pending packets will be transmitted.
+ *
+ * In case there are no packets to send, releases theWWAN0_PRODentity.
+ * As an outcome, the number of IPA active clients should be decremented
+ * until IPA clocks can be gated.
+ */drivers/net/ipa/rmnet_ipa.c new file +21
-0+static int rmnet_ipa_ap_suspend (struct device *dev) +{ +struct net_device *netdev = rmnet_ipa_ctx->dev; +struct ipa_wwan_private *wwan_ptr; +int ret; + +if (!netdev) { +ipa_err ("netdev is NULL.\n" ); + ret =0 ; + goto bail; + } + +netif_tx_lock_bh (netdev); + wwan_ptr =netdev_priv (netdev); +if (!wwan_ptr) { +ipa_err ("wwan_ptr is NULL.\n" ); + ret =0 ; + goto unlock_and_bail; + } + +/* Do not allow A7 to suspend in case there are outstanding packets */
drivers/net/ipa/rmnet_ipa.c new file +22
-0+if (atomic_read (&wwan_ptr->outstanding_pkts) !=0 ) { + ret = -EAGAIN ; + goto unlock_and_bail; + } + +/* Make sure that there is no Tx operation ongoing */ +netif_stop_queue (netdev); + + ret =0 ; +ipa_client_remove (); + +unlock_and_bail: +netif_tx_unlock_bh (netdev); +bail: + +return ret; +} + +/** rmnet_ipa_ap_resume() - resume callback for runtime_pm +* @dev: pointer to device +* +* This callback will be invoked by the runtime_pm framework when an AP resume
+ * operation is invoked.
+ *
+ * Enables the network interface queue and returns success to the
+ *runtime_pmframework.
+ */drivers/net/ipa/rmnet_ipa.c new file +45
-0+static int rmnet_ipa_ap_resume (struct device *dev) +{ +struct net_device *netdev = rmnet_ipa_ctx->dev; + +ipa_client_add (); +if (netdev) +netif_wake_queue (netdev); + +return 0 ; +} + +static const struct of_device_id rmnet_ipa_dt_match[] = { + {.compatible ="qcom,rmnet-ipa" }, + {}, +}; +MODULE_DEVICE_TABLE (of, rmnet_ipa_dt_match); + +static const struct dev_pm_ops rmnet_ipa_pm_ops = { + .suspend_noirq = rmnet_ipa_ap_suspend, + .resume_noirq = rmnet_ipa_ap_resume, +}; + +static struct platform_driver rmnet_ipa_driver = { + .driver = { + .name ="rmnet_ipa" , + .owner =THIS_MODULE , + .pm = &rmnet_ipa_pm_ops, + .of_match_table = rmnet_ipa_dt_match, + }, + .probe = ipa_wwan_probe, + .remove = ipa_wwan_remove, +}; + +int ipa_wwan_init (void ) +{ +if (initialized) +return 0 ; + +return platform_driver_register (&rmnet_ipa_driver); +} + +void ipa_wwan_cleanup (void ) +{ +platform_driver_unregister (&rmnet_ipa_driver); + memset(&rmnet_ipa_ctx_struct, 0,
sizeof(rmnet_ipa_ctx_struct));drivers/net/ipa/rmnet_ipa.c new file +9
-0+} + +static int ipa_rmnet_poll (struct napi_struct *napi,int budget) +{ +return ipa_rx_poll (rmnet_ipa_ctx->wan_cons_ep_id, budget); +} + +MODULE_DESCRIPTION ("WWAN Network Interface" ); +MODULE_LICENSE ("GPL v2" );
Quoted 11 lines · Alex Elder
The code has undergone considerable rework to prepare it for incorporation into upstream Linux. Parts of it bear little resemblance to the original driver. Still, some work remains to be done. The current code and its design had a preliminary review, and some changes to the data path implementation were
recommended. These have not yet been addressed:
- Use NAPI for all interfaces, not just RX (and WAN data) endpoints.
- Do more work in the NAPI poll function, including collecting completed TX requests and posting buffers for RX.
- Do not use periodic NOP requests as a way to avoid TX interrupts.
- The NAPI context should be associated with the hardware interrupt
Quoted 8 lines
(it is now associated with something abstracted from the hardware).
- Use threaded interrupts, to avoid the need for using spinlocks and atomic variables for synchronizing between workqueue and interrupt context.
- Have runtime power management enable and disable IPA clock and interconnects.
Many thanks to Arnd Bergmann, Ilias Apalodimas, and Bjorn Andersson for their early feedback.
Thanks for getting the current version out even with the long TODO list. I've had my first deeper look at some of the patches and found a few more things that likely require substantial rework. I also think there is still significant room for simplifying it further, and getting better performance out of it in the process.
Also, despite the criticism in my patch review, I have to say you've done a great job at cutting out a lot of the things that were present in the past, it's good to see that you have come this far with the cleanup!
Arnd
Re: [RFC PATCH 12/12] soc: qcom: ipa: build and "ipa_i.h"
In reply to Randy DunlapQuoted 1 line · Randy Dunlap
Hi-
Thanks Randy, I've fixed this in my own tree. -Alex
Quoted 43 lines · Alex Elder
Quoted 21 lines
drivers/net/ipa/Kconfig new file +15
-0@@ -0,0 +1,30 @@ +config IPA + tristate "Qualcomm IPA support" + depends on NET + select QCOM_QMI_HELPERS + select QCOM_MDT_LOADER + default n + help + Choose Y here to include support for the Qualcomm IP + Accelerator (IPA), a hardware block present in some + Qualcomm SoCs. The IPA is a programmable protocol + processor that is capable of generic hardware handling + of IP packets, including routing, filtering, and NAT. + Currently the IPA driver supports only basic transport + of network traffic between the AP and modem, on the + Qualcomm SDM845 SoC.drivers/net/ipa/Kconfig line 25
Quoted 10 lines
drivers/net/ipa/Kconfig new file +10
-0+ + If unsure, say N. + +config IPA_ASSERT + bool "Enable IPA assertions" + depends on IPA + default y + help + Incorporate IPA assertion verification in the build. This + cause various design assumptions to be checked at runtime,causes
Quoted 5 lines
drivers/net/ipa/Kconfig new file +5
-0+ generating a report (and a crash) if any assumed condition + does not hold. You may wish to disable this to avoid the + overhead of checking. + + If unsure doubt, say "Y" here.
Re: [RFC PATCH 01/12] dt-bindings: soc: qcom: add IPA bindings
In reply to Arnd BergmannQuoted 13 lines · Arnd Bergmann
Quoted 11 lines · Alex Elder
Add the binding definitions for the "qcom,ipa" and "qcom,rmnet-ipa" device tree nodes.
Signed-off-by Alex Elder <[email protected]>--- .../devicetree/bindings/soc/qcom/qcom,ipa.txt | 136 ++++++++++++++++++ .../bindings/soc/qcom/qcom,rmnet-ipa.txt | 15 ++ 2 files changed, 151 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt
Quoted 3 lines
I think this should go into bindings/net instead of bindings/soc, since it's mostly about networking rather than a specific detail of managing the SoC itself.
Done (in my tree--and will be reflected next time I send something out).
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +2
-0@@ -0,0 +1,136 @@ +Qualcomm IPA (IP Accelerator) Driver +
Quoted 8 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 6
Quoted 4 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +4
-0+This binding describes the Qualcomm IPA. The IPA is capable of offloading +certain network processing tasks (e.g. filtering, routing, and NAT) from +the main processor. The IPA currently serves only as a network interface, +providing access to an LTE network available via a modem.That doesn't belong into the binding. Say what the hardware can do here, not what a specific implementation of the driver does at this moment. The binding should be written in an OS independent way after all.
OK.
Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 46
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +6
-0+- interrupts-extended: + Specifies the IRQs used by the IPA. Four cells are required, + specifying: the IPA IRQ; the GSI IRQ; the clock query interrupt + from the modem; and the "ready for stage 2 initialization" + interrupt from the modem. The first two are hardware IRQs; the + third and fourth are SMP2P input interrupts.You mean 'four interrupts', not 'four cells' -- each interrupt specifier already consists of at least two cells (one for the phandle to the irqchip, plus one or more cells to describe that interrupt).
OK.
Quoted 7 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 63
Quoted 5 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +5
-0+- interconnects: + Specifies the interconnects used by the IPA. Three cells are + required, specifying: the path from the IPA to memory; from + IPA to internal (SoC resident) memory; and between the AP + subsystem and IPA for register access.Same here and in the rest.
OK, I've fixed all of these. Thank you.
-Alex
Quoted 3 lines
Arnd
Re: [RFC PATCH 01/12] dt-bindings: soc: qcom: add IPA bindings
In reply to Rob HerringQuoted 13 lines · Rob Herring
Quoted 12 lines · Alex Elder
Add the binding definitions for the "qcom,ipa" and "qcom,rmnet-ipa" device tree nodes.
Signed-off-by Alex Elder <[email protected]>--- .../devicetree/bindings/soc/qcom/qcom,ipa.txt | 136 ++++++++++++++++++ .../bindings/soc/qcom/qcom,rmnet-ipa.txt | 15 ++ 2 files changed, 151 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt
Quoted 9 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 1
Quoted 7 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +1
-0@@ -0,0 +1,136 @@ +Qualcomm IPA (IP Accelerator) DriverBindings are for h/w not drivers.
OK. I'll drop " Driver".
Quoted 25 lines
Quoted 25 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +25
-0+ +This binding describes the Qualcomm IPA. The IPA is capable of offloading +certain network processing tasks (e.g. filtering, routing, and NAT) from +the main processor. The IPA currently serves only as a network interface, +providing access to an LTE network available via a modem. + +The IPA sits between multiple independent "execution environments," +including the AP subsystem (APSS) and the modem. The IPA presents +a Generic Software Interface (GSI) to each execution environment. +The GSI is an integral part of the IPA, but it is logically isolated +and has a distinct interrupt and a separately-defined address space. + + ---------- ------------- --------- + | | |G| |G| | | + | APSS |===|S| IPA |S|===| Modem | + | | |I| |I| | | + ---------- ------------- --------- + +See also: + bindings/interrupt-controller/interrupts.txt + bindings/interconnect/interconnect.txt + bindings/soc/qcom/qcom,smp2p.txt + bindings/reserved-memory/reserved-memory.txt + bindings/clock/clock-bindings.txt +
Quoted 8 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 32
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +6
-0+All properties defined below are required. + +- compatible: + Must be one of the following compatible strings: + "qcom,ipa-sdm845-modem_init" + "qcom,ipa-sdm845-tz_init"Normal order is <vendor>,<soc>-<ipblock>."
I'll use "qcom,sdm845-ipa-modem-init" and "qcom,sdm845-ipa-tz-init". (Or just "qcom,sdm845-ipa", depending on the outcome of the discussion below.)
Quoted 1 line
Don't use '_'.
OK.
Quoted 1 line
What's the difference between these 2? It can't be detected somehow?
There is some early initialization, including loading some firmware, that must be done by trusted code. That can be done by either Trust Zone or the modem. If it's done by the modem, there is an additional step required during initialization so the modem can tell the AP that it has done its part, and the AP can finish IPA initialization.
There is no way of detecting (e.g. by probing hardware) which is in effect so we use DT. I discussed this with Bjorn, who said that this was a situation seen elsewhere and that using compatible strings was the way he suggested to address it.
Quoted 2 lines
This might be better expressed as a property. Then if Trustzone initializes things, it can just add a property.
A Boolean property to distinguish them would be fine as well, but I would like to address this "common" problem consistently.
Bjorn, would you please weigh in?
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 35
Quoted 3 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +3
-0+ +-reg: + Resources specyfing the physical address spaces of the IPA and GSI.typo
Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 41
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +6
-0+ +-reg-names: + The names of the address space ranges defined by the "reg" property. + Must be "ipa" and "gsi". + +- interrupts-extended:Use 'interrupts' here and describe what they are and the order. What they are connected to (and the need for interrupts-extended) is outside the scope of this binding.
I used interrupts-extended because there were two interrupt parents (a "normal" interrupt controller and the interrupt controller implemented for SMP2P input). A paragraph here:
bindings/interrupt-controller/interrupts.txt
recommends "interrupts-extended" in that case.
I have no objection to using just "interrupts" but can you tell me what I misunderstood? It seems like I need to do "interrupts-extended".
Quoted 11 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 51
Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +10
-0+ Specifies the IRQs used by the IPA. Four cells are required, + specifying: the IPA IRQ; the GSI IRQ; the clock query interrupt + from the modem; and the "ready for stage 2 initialization" + interrupt from the modem. The first two are hardware IRQs; the + third and fourth are SMP2P input interrupts. + +- interrupt-names: + The names of the interrupts defined by the "interrupts-extended" + property. Must be "ipa", "gsi", "ipa-clock-query", and + "ipa-post-init".
Quoted 1 line
Format as one per line.
Done. And I did this throughout the file where there was more than one name. One per line, no comma, no "and".
Quoted 48 lines
Quoted 48 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +48
-0+ +- clocks: + Resource that defines the IPA core clock. + +- clock-names: + The name used for the IPA core clock. Must be "core". + +- interconnects: + Specifies the interconnects used by the IPA. Three cells are + required, specifying: the path from the IPA to memory; from + IPA to internal (SoC resident) memory; and between the AP + subsystem and IPA for register access. + +- interconnect-names: + The names of the interconnects defined by the "interconnects" + property. Must be "memory", "imem", and "config". + +- qcom,smem-states + The state bits used for SMP2P output. Two cells must be specified. + The first indicates whether the value in the second bit is valid + (1 means valid). The second, if valid, defines whether the IPA + clock is enabled (1 means enabled). + +- qcom,smem-state-names + The names of the state bits used for SMP2P output. These must be + "ipa-clock-enabled-valid" and "ipa-clock-enabled". + +- memory-region + A phandle for a reserved memory area that holds the firmware passed + to Trust Zone for authentication. (Note, this is required + only for "qcom,ipa-sdm845-tz_init".) + += EXAMPLE + +The following example represents the IPA present in the SDM845 SoC. It +shows portions of the "modem-smp2p" node to indicate its relationship +with the interrupts and SMEM states used by the IPA. + + modem-smp2p { + compatible = "qcom,smp2p"; + . . . + ipa_smp2p_out: ipa-ap-to-modem { + qcom,entry-name = "ipa"; + #qcom,smem-state-cells = <1>; + }; + + ipa_smp2p_in: ipa-modem-to-ap { + qcom,entry-name = "ipa";
Quoted 8 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 105
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +6
-0+ interrupt-controller; + #interrupt-cells = <2>; + }; + }; + + ipa at 1e00000 {ipa at 1e40000
Oops. Fixed.
Quoted 39 lines
Quoted 39 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +31
-0+ compatible = "qcom,ipa-sdm845-modem_init"; + + reg = <0x1e40000 0x34000>, + <0x1e04000 0x2c000>; + reg-names = "ipa", + "gsi"; + + interrupts-extended = <&intc 0 311 IRQ_TYPE_LEVEL_HIGH>, + <&intc 0 432 IRQ_TYPE_LEVEL_HIGH>, + <&ipa_smp2p_in 0 IRQ_TYPE_EDGE_RISING>, + <&ipa_smp2p_in 1 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "ipa", + "gsi", + "ipa-clock-query", + "ipa-post-init"; + + clocks = <&rpmhcc RPMH_IPA_CLK>; + clock-names = "core"; + + interconnects = <&qnoc MASTER_IPA &qnoc SLAVE_EBI1>, + <&qnoc MASTER_IPA &qnoc SLAVE_IMEM>, + <&qnoc MASTER_APPSS_PROC &qnoc SLAVE_IPA_CFG>; + interconnect-names = "memory", + "imem", + "config"; + + qcom,smem-states = <&ipa_smp2p_out 0>, + <&ipa_smp2p_out 1>; + qcom,smem-state-names = "ipa-clock-enabled-valid", + "ipa-clock-enabled"; + };Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt new file +2
-0@@ -0,0 +1,15 @@ +Qualcomm IPA RMNet Driver +
Quoted 8 lines
Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt line 6
Quoted 4 lines
Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt new file +4
-0+This binding describes the IPA RMNet driver, which is used to +represent virtual interfaces available on the modem accessed via +the IPA. Other than the compatible string there are no properties +associated with this device.Only a compatible string is a sure sign this is not a h/w device and you are just abusing DT to instantiate drivers. Make the IPA driver instantiate any sub drivers it needs.
Yeah I have been thinking this but hadn't followed through on doing anything about it yet. I'll remove this node entirely. It's possible it had other properties at one time, but in the end this represents a soft interface and can be implemented within the IPA driver.
Thanks a lot for the review.
-Alex
Quoted 3 lines
Rob
Rob Herring
maintainerRe: [RFC PATCH 01/12] dt-bindings: soc: qcom: add IPA bindings
Quoted 77 lines · Alex Elder
Quoted 13 lines · Rob Herring
Quoted 12 lines · Alex Elder
Add the binding definitions for the "qcom,ipa" and "qcom,rmnet-ipa" device tree nodes.
Signed-off-by Alex Elder <[email protected]>--- .../devicetree/bindings/soc/qcom/qcom,ipa.txt | 136 ++++++++++++++++++ .../bindings/soc/qcom/qcom,rmnet-ipa.txt | 15 ++ 2 files changed, 151 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txtQuoted 9 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 1
Quoted 7 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +1
-0@@ -0,0 +1,136 @@ +Qualcomm IPA (IP Accelerator) DriverBindings are for h/w not drivers.
OK. I'll drop " Driver".
Quoted 25 lines
Quoted 25 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +25
-0+ +This binding describes the Qualcomm IPA. The IPA is capable of offloading +certain network processing tasks (e.g. filtering, routing, and NAT) from +the main processor. The IPA currently serves only as a network interface, +providing access to an LTE network available via a modem. + +The IPA sits between multiple independent "execution environments," +including the AP subsystem (APSS) and the modem. The IPA presents +a Generic Software Interface (GSI) to each execution environment. +The GSI is an integral part of the IPA, but it is logically isolated +and has a distinct interrupt and a separately-defined address space. + + ---------- ------------- --------- + | | |G| |G| | | + | APSS |===|S| IPA |S|===| Modem | + | | |I| |I| | | + ---------- ------------- --------- + +See also: + bindings/interrupt-controller/interrupts.txt + bindings/interconnect/interconnect.txt + bindings/soc/qcom/qcom,smp2p.txt + bindings/reserved-memory/reserved-memory.txt + bindings/clock/clock-bindings.txt +Quoted 8 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 32
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +6
-0+All properties defined below are required. + +- compatible: + Must be one of the following compatible strings: + "qcom,ipa-sdm845-modem_init" + "qcom,ipa-sdm845-tz_init"Normal order is <vendor>,<soc>-<ipblock>."
I'll use "qcom,sdm845-ipa-modem-init" and "qcom,sdm845-ipa-tz-init". (Or just "qcom,sdm845-ipa", depending on the outcome of the discussion below.)
Quoted 1 line
Don't use '_'.
OK.
Quoted 1 line
What's the difference between these 2? It can't be detected somehow?
There is some early initialization, including loading some firmware, that must be done by trusted code. That can be done by either Trust Zone or the modem. If it's done by the modem, there is an additional step required during initialization so the modem can tell the AP that it has done its part, and the AP can finish IPA initialization.
Quoted 4 lines
There is no way of detecting (e.g. by probing hardware) which is in effect so we use DT. I discussed this with Bjorn, who said that this was a situation seen elsewhere and that using compatible strings was the way he suggested to address it.
Okay. However, if this is common for QCom blocks maybe we should reconsider. I think compatible makes sense if the programming model changes.
Quoted 25 lines
Quoted 2 lines
This might be better expressed as a property. Then if Trustzone initializes things, it can just add a property.
A Boolean property to distinguish them would be fine as well, but I would like to address this "common" problem consistently.
Bjorn, would you please weigh in?
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 35
Quoted 3 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +3
-0+ +-reg: + Resources specyfing the physical address spaces of the IPA and GSI.typo
Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 41
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +6
-0+ +-reg-names: + The names of the address space ranges defined by the "reg" property. + Must be "ipa" and "gsi". + +- interrupts-extended:Use 'interrupts' here and describe what they are and the order. What they are connected to (and the need for interrupts-extended) is outside the scope of this binding.
Quoted 8 lines
I used interrupts-extended because there were two interrupt parents (a "normal" interrupt controller and the interrupt controller implemented for SMP2P input). A paragraph here:
bindings/interrupt-controller/interrupts.txt
recommends "interrupts-extended" in that case.I have no objection to using just "interrupts" but can you tell me what I misunderstood? It seems like I need to do "interrupts-extended".
Yes, in the dts you should use interrupts-extended. However, for documentation purposes that aspect is not important. So we just use interrupts most everywhere.
Rob
Re: [RFC PATCH 01/12] dt-bindings: soc: qcom: add IPA bindings
In reply to Rob HerringQuoted 6 lines · Rob Herring
Quoted 5 lines · Alex Elder
Add the binding definitions for the "qcom,ipa" and "qcom,rmnet-ipa" device tree nodes.
Signed-off-by Alex Elder <[email protected]>
Rob, I'm just following up to let you know that I have now addressed all of your suggestions in my current code.
This includes the removal of the "qcom,rmnet-ipa" DT node. The driver that was set up to match that node is now gone from the code, and this entity is no longer represented by a "real" device. It implements a network device that represents the modem, and that is now set up and torn down as needed by the "main" IPA code.
The one thing that might need to be addressed is whether a Boolean flag should be used rather than a different compatible string to select whether the modem or TZ is responsible for GSI firmware load and launch. If you and Bjorn agree it should be done with a flag instead I'll fix the binding and code accordingly.
-Alex
Quoted 194 lines
Quoted 13 lines
--- .../devicetree/bindings/soc/qcom/qcom,ipa.txt | 136 ++++++++++++++++++ .../bindings/soc/qcom/qcom,rmnet-ipa.txt | 15 ++ 2 files changed, 151 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txtDocumentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +0
-0Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 1
Quoted 1 line
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +1
-0@@ -0,0 +1,136 @@ +Qualcomm IPA (IP Accelerator) DriverBindings are for h/w not drivers.
Quoted 21 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +21
-0+ +This binding describes the Qualcomm IPA. The IPA is capable of offloading +certain network processing tasks (e.g. filtering, routing, and NAT) from +the main processor. The IPA currently serves only as a network interface, +providing access to an LTE network available via a modem. + +The IPA sits between multiple independent "execution environments," +including the AP subsystem (APSS) and the modem. The IPA presents +a Generic Software Interface (GSI) to each execution environment. +The GSI is an integral part of the IPA, but it is logically isolated +and has a distinct interrupt and a separately-defined address space. + + ---------- ------------- --------- + | | |G| |G| | | + | APSS |===|S| IPA |S|===| Modem | + | | |I| |I| | | + ---------- ------------- --------- + +See also: + bindings/interrupt-controller/interrupts.txt + bindings/interconnect/interconnect.txtDocumentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 32
Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +10
-0+ bindings/soc/qcom/qcom,smp2p.txt + bindings/reserved-memory/reserved-memory.txt + bindings/clock/clock-bindings.txt + +All properties defined below are required. + +- compatible: + Must be one of the following compatible strings: + "qcom,ipa-sdm845-modem_init" + "qcom,ipa-sdm845-tz_init"Normal order is <vendor>,<soc>-<ipblock>.
Don't use '_'.
What's the difference between these 2? It can't be detected somehow? This might be better expressed as a property. Then if Trustzone initializes things, it can just add a property.
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 35
Quoted 3 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +3
-0+ +-reg: + Resources specyfing the physical address spaces of the IPA and GSI.typo
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 41
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +6
-0+ +-reg-names: + The names of the address space ranges defined by the "reg" property. + Must be "ipa" and "gsi". + +- interrupts-extended:Use 'interrupts' here and describe what they are and the order. What they are connected to (and the need for interrupts-extended) is outside the scope of this binding.
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 51
Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +10
-0+ Specifies the IRQs used by the IPA. Four cells are required, + specifying: the IPA IRQ; the GSI IRQ; the clock query interrupt + from the modem; and the "ready for stage 2 initialization" + interrupt from the modem. The first two are hardware IRQs; the + third and fourth are SMP2P input interrupts. + +- interrupt-names: + The names of the interrupts defined by the "interrupts-extended" + property. Must be "ipa", "gsi", "ipa-clock-query", and + "ipa-post-init".Format as one per line.
Quoted 44 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +44
-0+ +- clocks: + Resource that defines the IPA core clock. + +- clock-names: + The name used for the IPA core clock. Must be "core". + +- interconnects: + Specifies the interconnects used by the IPA. Three cells are + required, specifying: the path from the IPA to memory; from + IPA to internal (SoC resident) memory; and between the AP + subsystem and IPA for register access. + +- interconnect-names: + The names of the interconnects defined by the "interconnects" + property. Must be "memory", "imem", and "config". + +- qcom,smem-states + The state bits used for SMP2P output. Two cells must be specified. + The first indicates whether the value in the second bit is valid + (1 means valid). The second, if valid, defines whether the IPA + clock is enabled (1 means enabled). + +- qcom,smem-state-names + The names of the state bits used for SMP2P output. These must be + "ipa-clock-enabled-valid" and "ipa-clock-enabled". + +- memory-region + A phandle for a reserved memory area that holds the firmware passed + to Trust Zone for authentication. (Note, this is required + only for "qcom,ipa-sdm845-tz_init".) + += EXAMPLE + +The following example represents the IPA present in the SDM845 SoC. It +shows portions of the "modem-smp2p" node to indicate its relationship +with the interrupts and SMEM states used by the IPA. + + modem-smp2p { + compatible = "qcom,smp2p"; + . . . + ipa_smp2p_out: ipa-ap-to-modem { + qcom,entry-name = "ipa"; + #qcom,smem-state-cells = <1>;Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt line 105
Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +10
-0+ }; + + ipa_smp2p_in: ipa-modem-to-ap { + qcom,entry-name = "ipa"; + interrupt-controller; + #interrupt-cells = <2>; + }; + }; + + ipa at 1e00000 {ipa at 1e40000
Quoted 37 lines
Documentation/devicetree/bindings/soc/qcom/qcom,ipa.txt new file +31
-0+ compatible = "qcom,ipa-sdm845-modem_init"; + + reg = <0x1e40000 0x34000>, + <0x1e04000 0x2c000>; + reg-names = "ipa", + "gsi"; + + interrupts-extended = <&intc 0 311 IRQ_TYPE_LEVEL_HIGH>, + <&intc 0 432 IRQ_TYPE_LEVEL_HIGH>, + <&ipa_smp2p_in 0 IRQ_TYPE_EDGE_RISING>, + <&ipa_smp2p_in 1 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "ipa", + "gsi", + "ipa-clock-query", + "ipa-post-init"; + + clocks = <&rpmhcc RPMH_IPA_CLK>; + clock-names = "core"; + + interconnects = <&qnoc MASTER_IPA &qnoc SLAVE_EBI1>, + <&qnoc MASTER_IPA &qnoc SLAVE_IMEM>, + <&qnoc MASTER_APPSS_PROC &qnoc SLAVE_IPA_CFG>; + interconnect-names = "memory", + "imem", + "config"; + + qcom,smem-states = <&ipa_smp2p_out 0>, + <&ipa_smp2p_out 1>; + qcom,smem-state-names = "ipa-clock-enabled-valid", + "ipa-clock-enabled"; + };Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt new file +0
-0Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt line 6
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,rmnet-ipa.txt new file +6
-0@@ -0,0 +1,15 @@ +Qualcomm IPA RMNet Driver + +This binding describes the IPA RMNet driver, which is used to +represent virtual interfaces available on the modem accessed via +the IPA. Other than the compatible string there are no properties +associated with this device.Only a compatible string is a sure sign this is not a h/w device and you are just abusing DT to instantiate drivers. Make the IPA driver instantiate any sub drivers it needs.
Rob
Re: [RFC PATCH 02/12] soc: qcom: ipa: DMA helpers
In reply to Arnd BergmannQuoted 6 lines · Arnd Bergmann
Quoted 5 lines · Alex Elder
This patch includes code implementing the IPA DMA module, which defines a structure to represent a DMA allocation for the IPA device. It's used throughout the IPA code.
Quoted 6 lines
Quoted 1 line
Signed-off-by Alex Elder <[email protected]>I looked through all the users of this and couldn't fine one that actually benefits from it. I'd say better drop this patch entirely and open-code the contents in the callers. That will help readability since the dma API is well understood by many people.
Originally this was done to make it more obvious that all DMA allocations were done with the same device pointer. Previously there were several separate devices, and it wasn't very obvious that only one was used (and required). Now that we're past that it's not difficult to do as you suggest.
I have now done that, and in the process identified a few more ways to improve/simplify the code. The net result is that more lines of code were removed than were present in "ipa_dma.[ch]". I see that as a win (aside from your point below).
Quoted 2 lines
Generally speaking, try not to wrap Linux interfaces into driver specific helper functions.
Agreed. Thanks a lot for your review.
-Alex
Quoted 3 lines
Arnd
Re: [RFC PATCH 04/12] soc: qcom: ipa: immediate commands
In reply to Arnd BergmannQuoted 12 lines · Arnd Bergmann
drivers/net/ipa/ipahal.c line 44
Quoted 9 lines · Alex Elder
drivers/net/ipa/ipahal.c new file +8
-0+/** +* struct ipahal_context - HAL global context data +* @empty_fltrt_tbl: Empty table to be used for table initialization +*/ +static struct ipahal_context { +struct ipa_dma_mem empty_fltrt_tbl; +} ipahal_ctx_struct; +static struct ipahal_context *ipahal_ctx = &ipahal_ctx_struct;Remove the global variables here
Not done yet, but I will do this. I've been working on eliminating the top-level "ipa_ctx" global (which is *very* pervasive) and in the process I'm eliminating all the others as well. I'll get to this soon.
Quoted 20 lines
Quoted 20 lines
drivers/net/ipa/ipahal.c new file +20
-0+/* Immediate commands H/W structures */ + +/* struct ipa_imm_cmd_hw_ip_fltrt_init - IP_V*_FILTER_INIT/IP_V*_ROUTING_INIT +* command payload in H/W format. +* Inits IPv4/v6 routing or filter block. +* @hash_rules_addr: Addr in system mem where hashable flt/rt rules starts +* @hash_rules_size: Size in bytes of the hashable tbl to cpy to local mem +* @hash_local_addr: Addr in shared mem where hashable flt/rt tbl should +* be copied to +* @nhash_rules_size: Size in bytes of the non-hashable tbl to cpy to local mem +* @nhash_local_addr: Addr in shared mem where non-hashable flt/rt tbl should +* be copied to +* @rsvd: reserved +* @nhash_rules_addr: Addr in sys mem where non-hashable flt/rt tbl starts +*/ +struct ipa_imm_cmd_hw_ip_fltrt_init { +u64 hash_rules_addr; +u64 hash_rules_size :12 , + hash_local_addr :16 , + nhash_rules_size : 12,
Quoted 8 lines
drivers/net/ipa/ipahal.c line 96
Quoted 4 lines
drivers/net/ipa/ipahal.c new file +4
-0+ nhash_local_addr :16 , + rsvd : 8; +u64 nhash_rules_addr; +};In hardware structures, you should not use bit fields, as the ordering of the bits is not well-defined in C. The only portable way to do this is to use shifts and masks unfortunately.
This is something I held off fixing because I have seen other use of bit fields in the kernel. I wasn't sure whether my instinct about it (which matches what you say) was wrong, and didn't want to do the work to change things over to masks without knowing. Based on your suggestion, I will proceed with this conversion.
Quoted 10 lines
drivers/net/ipa/ipahal.c line 111
Quoted 6 lines
drivers/net/ipa/ipahal.c new file +6
-0+struct ipa_imm_cmd_hw_hdr_init_local { +u64 hdr_table_addr; +u32 size_hdr_table :12 , + hdr_addr :16 , + rsvd :4 ; +};I would also add a 'u32 pad' member at the end to make the padding explicit here, or mark the first member as '
__aligned(4)__packed' if you want to avoid the padding.
Yes, this is a good suggestion, and I will implement it.
You're right that the actual size of this structure includes the extra 4 byte pad. But I'm not actually sure whether the hardware touches it because the size of immediate commands is implied by the opcode. To be safe, I'll make the pad explicit; but if I learn it's not needed I'll define it to be packed.
Quoted 14 lines
Quoted 14 lines
drivers/net/ipa/ipahal.c new file +14
-0+void *ipahal_dma_shared_mem_write_pyld (struct ipa_dma_mem *mem,u32 offset) +{ +struct ipa_imm_cmd_hw_dma_shared_mem *data; + +ipa_assert (mem->size <1 <<16 );/* size is 16 bits wide */ +ipa_assert (offset <1 <<16 );/* local_addr is 16 bits wide */ + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (!data) +return NULL ; + + data->size = mem->size; + data->local_addr = offset; + data->direction =0 ;/* 0 = write to IPA; 1 = read from IPA */
Quoted 8 lines
drivers/net/ipa/ipahal.c line 282
Quoted 6 lines
drivers/net/ipa/ipahal.c new file +6
-0+ data->skip_pipeline_clear =0 ; + data->pipeline_clear_options =IPAHAL_HPS_CLEAR ; + data->system_addr = mem->phys; + +return data; +}The 'void *' return looks odd here, and also the dynamic allocation.
It was done because it allows the definition of the data structure to be hidden within this file.
Quoted 7 lines
It looks to me like all these functions could be better done the other way round, basically putting the
ipa_imm_cmd_hw_dma_shared_memetc structures on the stack of the caller. At least for this one, the dynamic allocation doesn't help at all because the caller is the same that frees it again after the command. I suspect the same is true for a lot of those commands.
Yes, I see what you're saying. In fact, now that I look, all of these payload allocating functions except for one are used just the way you describe (freed in the same function that uses it). And the one is saved with the intention of avoiding an allocation failure... But I'll mention that this code was structured very differently originally.
So I agree, putting them on the stack (given they're relatively small--most 16 bytes one 24 bytes) is better. And it seems I can reduce some complexity by getting rid of that preallocated command, which is a great outcome.
If I run into trouble implementing any of the above suggestions I will circle back and explain.
Thanks a lot.
-Alex
Quoted 3 lines
Arnd
Re: [RFC PATCH 07/12] soc: qcom: ipa: IPA register abstraction
In reply to Arnd BergmannQuoted 15 lines · Arnd Bergmann
Quoted 14 lines · Alex Elder
drivers/net/ipa/ipa_reg.c new file +8
-0@@ -0,0 +1,972 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. +* Copyright (C) 2018 Linaro Ltd. +*/ + +#include <linux/types.h> +#include <linux/io.h>
Quoted 8 lines
drivers/net/ipa/ipa_reg.c line 14
Quoted 6 lines
drivers/net/ipa/ipa_reg.c new file +6
-0+#include <linux/bitfield.h> + +#include "ipa_reg.h" + +/* I/O remapped base address of IPA register space */ +static void __iomem *ipa_reg_virt;This should of course be part of the device structure.
Yes, this should have been be in that structure to begin with.
I'm working through doing a comprehensive replacement of global variables like this with values passed around as arguments. I've intended to do it all along but your nudge pushed it to the top of my list. It's a *lot* of work, much more than I realized. But I'm making rapid progress.
Quoted 10 lines
Quoted 10 lines
drivers/net/ipa/ipa_reg.c new file +10
-0+/* struct ipa_reg_desc - descriptor for an abstracted hardware register +* +* @construct - fn to construct the register value from its field structure +* @parse - function to parse register field values into its field structure +* @offset - register offset relative to base address +* @n_ofst - size multiplier for "N-parameterized" registers +*/ +struct ipa_reg_desc { +u32 (*construct)(enum ipa_reg reg,const void *fields); +void (*parse)(enum ipa_reg reg,void *fields,u32 val);
Quoted 8 lines
drivers/net/ipa/ipa_reg.c line 28
Quoted 3 lines
drivers/net/ipa/ipa_reg.c new file +3
-0+u32 offset; +u16 n_ofst; +};Indirect function pointers can be a bit expensive in the post-spectre days. It's probably not overly important if these are always part of an MMIO access function, but you should be careful about using these in the data path.
OK.
There used to be a more elaborate scheme for supporting lots of versions, and I have tried to preserve at least part of the underlying mechanism (the parse and construct functions). Not all of these registers use the indirect functions, and it looks to me like none of them are in the data path.
The most important registers for the fast path are found in the GSI code. And that doesn't use this construct--it only reads and writes 32-bit registers. (I think it differs because it was originally developed by a different team.)
Quoted 1 line
How many different versions do we have to support in practice
I don't know for sure how many versions really were used, but the original code had about 10 distinct version values, many of which shared most (but not all) register definitions (offset and bit field widths) with older versions.
With the upstream code the decision was made to ignore anything older than IPA version 3 (and 3.5.1 in particular, which is found in the SDM845 SoC).
It may be that this parse/construct mechanism isn't justified at this point. I thought the way it presented a generic interface was useful, but with just one (initial) hardware target we don't (yet) realize its potential benefit. It could be added back later, as support for new versions is added.
As of now I don't plan to change this, but if you or someone else feels it would be better without it I can do that.
-Alex
Quoted 2 lines
Arnd
Re: [RFC PATCH 09/12] soc: qcom: ipa: main IPA source file
In reply to Arnd BergmannQuoted 8 lines · Arnd Bergmann
Quoted 1 line · Alex Elder
+static void
ipa_client_remove_deferred(struct work_struct *work);Try to avoid forward declarations by reordering the code in call order, it will also make it easier to read.
Quoted 1 line
+static
DECLARE_WORK(ipa_client_remove_work, ipa_client_remove_deferred);
Done. I've actually reworked this a lot, and pulled all the clock (and interconnect) related code into a separate source file. No more forward declarations (there anyway), and the work structure is now embedded in the top-level IPA structure so I can derive it again in the work function (rather than using the global).
Quoted 5 lines
drivers/net/ipa/ipa_main.c line 63
Quoted 2 lines
drivers/net/ipa/ipa_main.c new file +2
-0+static struct ipa_context ipa_ctx_struct; +struct ipa_context *ipa_ctx = &ipa_ctx_struct;Global state variables should generally be removed as well, and passed around as function arguments.
Working on this.
Quoted 22 lines
Quoted 22 lines
drivers/net/ipa/ipa_main.c new file +22
-0+static int hdr_init_local_cmd (u32 offset,u32 size) +{ +struct ipa_desc desc = { }; +struct ipa_dma_mem mem; +void *payload; +int ret; + +if (ipa_dma_alloc (&mem, size,GFP_KERNEL )) +return -ENOMEM ; + + offset += ipa_ctx->smem_offset; + + payload =ipahal_hdr_init_local_pyld (&mem, offset); +if (!payload) { + ret = -ENOMEM ; + goto err_dma_free; + } + + desc.type =IPA_IMM_CMD_DESC ; + desc.len_opcode =IPA_IMM_CMD_HDR_INIT_LOCAL ; + desc.payload = payload; +
Quoted 8 lines
Quoted 1 line
+ ret =
ipa_send_cmd(&desc);You have a bunch of dynamic allocations in here, which you then immediately tear down again after the command is complete. I can't see at all what you do with the DMA address, since you seem to not use the virtual address at all but only store the physical address in some kind of descriptor without ever writing to it.
I should probably have added at least a comment here. The DMA memory was zeroed at the time of allocation. That zero buffer is then referred to in the payload to the HDR_INIT_LOCAL immediate command. So that command, when executing in the IPA hardware, uses the contents of the buffer whose physical address it's supplied, which in this case is full of zeroes. We don't use the virtual address because the buffer came pre-zeroed.
Based on your comment elsewhere I will be putting the command payload in a structure on the stack rather than allocating it dynamically.
Quoted 10 lines
Am I missing something here?
drivers/net/ipa/ipa_main.c line 873
Quoted 4 lines
drivers/net/ipa/ipa_main.c new file +4
-0+/* Remoteproc callbacks for SSR events: prepare, start, stop, unprepare */ +int ipa_ssr_prepare (struct rproc_subdev *subdev) +{ +printk ("======== SSR prepare received ========\n" );I think you mean
dev_dbg()here. A plainprintk()without a level is not correct and we probably don't want those messages to arrive on the console for normal users.
Yes, this was obviously a debug message in some code I should have removed before sending...
Quoted 19 lines
Quoted 19 lines
drivers/net/ipa/ipa_main.c new file +19
-0+static int ipa_firmware_load (struct de + +err_clear_dev: + ipa_ctx->lan_cons_ep_id = 0; + ipa_ctx->cmd_prod_ep_id =0 ; +ipahal_exit (); +err_dma_exit: +ipa_dma_exit (); +err_clear_gsi: + ipa_ctx->gsi =NULL ; + ipa_ctx->ipa_phys =0 ; +ipa_reg_exit (); +err_clear_ipa_irq: + ipa_ctx->ipa_irq =0 ; +err_clear_filter_bitmap: + ipa_ctx->filter_bitmap =0 ; +err_interconnect_exit: +ipa_interconnect_exit (); +err_clock_exit:
Quoted 8 lines
drivers/net/ipa/ipa_main.c line 1310
Quoted 5 lines
drivers/net/ipa/ipa_main.c new file +5
-0+ipa_clock_exit (); + ipa_ctx->dev =NULL ; +out_smp2p_exit: +ipa_smp2p_exit (dev); +No need to initialize members to zero when you are about to free the structure.
The IPA context is in fact a global, static structure at the moment. All of this bookkeeping (zeroing out things) is a habitual practice, basically. Regardless your point is good and I'll remove these kinds of things as part of converting to not using globals.
Quoted 7 lines
Quoted 7 lines
drivers/net/ipa/ipa_main.c new file +7
-0+static struct platform_driver ipa_plat_drv = { + .probe = ipa_plat_drv_probe, + .remove = ipa_plat_drv_remove, + .driver = { + .name ="ipa" , + .owner =THIS_MODULE , + .pm = &ipa_pm_ops,
Quoted 8 lines
drivers/net/ipa/ipa_main.c line 1397
Quoted 5 lines
drivers/net/ipa/ipa_main.c new file +5
-0+ .of_match_table = ipa_plat_drv_match, + }, +}; + +builtin_platform_driver (ipa_plat_drv);This should be
module_platform_driver(), and allow unloading the driver.
Yes. I've done this for my own use, but the code is not currently able to shut down cleanly. I've been fixing a *lot* of the things that don't clean up after themselves today but there's more work before I can say this can be safely built as a module. But it's a requirement.
-Alex
Quoted 3 lines
Arnd
Re: [RFC PATCH 10/12] soc: qcom: ipa: data path
In reply to Arnd BergmannQuoted 6 lines · Arnd Bergmann
Quoted 5 lines · Alex Elder
This patch contains "
ipa_dp.c", which includes the bulk of the data path code. There is an overview in the code of how things operate, but there are already plans to rework this portion of the driver.
Quoted 8 lines
Quoted 5 lines
In particular:
- Interrupt handling will be replaced with a threaded interrupt handler. Currently handling occurs in a combination of interrupt and workqueue context, and this requires locking and atomic operations for proper synchronization.You probably don't want to use just a threaded IRQ handler to start the poll function, that would still require an extra indirection.
That's a really good point. However I think that the path I'll take to *getting* to scheduling the poll in interrupt context will use a threaded interrupt handler. I'm hoping that will allow me to simplify the code in steps.
The main reason for this split between working in interrupt context when possible, but pushing to a workqueue when not, is to allow IPA clock(s) to be turned off. Enabling the clocks is a blocking operation, so can't' be done in the top half interrupt handler. The thought was it would be best to work in interrupt context--if the clock was already active--but to defer to a workqueue to turn the clock on if necessary.
The result requires locking and duplication of code that I find to be pretty confusing--and hard to reason about. I have been planning to re-do things to be better suited to NAPI, and knowing that, I haven't given the data path as much attention as some of the rest.
Quoted 13 lines
However, you can probably use the top half of the threaded handler to request the poll function if necessary but use the bottom half for anything that does not go through poll.
Quoted 8 lines
- Currently, only receive endpoints use NAPI. Transmit completion interrupts are disabled, and are handled in batches by periodically scheduling an interrupting no-op request. The plan is to arrange for transmit requests to generate interrupts, and their completion will be processed with other completions in the NAPI poll function. This will also allow accurate feedback about packet sojourn time to be provided to queue limiting mechanisms.
Quoted 5 lines
Right, that is definitely required here. I also had a look at the
gsi_channel_queue()function, which sits in the middle of the transmit function and is rather unoptimized. I'd suggest moving that into the caller so we can see what is going on, and then optimizing it from there.
Yes, I agree with that. There are multiple levels of abstraction in play and they aren't helpful. We have ipa_desc structures that are translated by ipa_send() into gsi_xfer_elem structures, which are ultimately recorded by gsi_channel_queue() as 16 byte gsi_tre structures. At least one of those translations can go away.
Quoted 9 lines
Quoted 7 lines
- Not all receive endpoints use NAPI. The plan is for *all* endpoints to use NAPI. And because all endpoints share a common GSI interrupt, a single NAPI structure will used to managing the processing for all completions on all endpoints.
- Receive buffers are posted to the hardware by a workqueue function. Instead, the plan is to have this done by the NAPI poll routine.Makes sense, yes.
Thanks.
-Alex
Quoted 3 lines
Arnd
Re: [RFC PATCH 07/12] soc: qcom: ipa: IPA register abstraction
In reply to Alex ElderQuoted 16 lines · Alex Elder
Quoted 7 lines · Arnd Bergmann
drivers/net/ipa/ipa_reg.c
Quoted 6 lines · Alex Elder
drivers/net/ipa/ipa_reg.c new file +0
-0@@ -0,0 +1,972 @@It may be that this parse/construct mechanism isn't justified at this point. I thought the way it presented a generic interface was useful, but with just one (initial) hardware target we don't (yet) realize its potential benefit. It could be added back later, as support for new versions is added.
Quoted 2 lines
As of now I don't plan to change this, but if you or someone else feels it would be better without it I can do that.
Fair enough. I do think that it would be better to avoid this, but it's much less important than the other issues I mentioned, so please put this on the bottom of your priorities list, we can talk about it again when we get closer to merging the driver.
Arnd
Re: [RFC PATCH 10/12] soc: qcom: ipa: data path
In reply to Alex ElderQuoted 30 lines · Alex Elder
Quoted 6 lines · Arnd Bergmann
Quoted 5 lines · Alex Elder
This patch contains "
ipa_dp.c", which includes the bulk of the data path code. There is an overview in the code of how things operate, but there are already plans to rework this portion of the driver.Quoted 8 lines
Quoted 5 lines
In particular:
- Interrupt handling will be replaced with a threaded interrupt handler. Currently handling occurs in a combination of interrupt and workqueue context, and this requires locking and atomic operations for proper synchronization.You probably don't want to use just a threaded IRQ handler to start the poll function, that would still require an extra indirection.
That's a really good point. However I think that the path I'll take to *getting* to scheduling the poll in interrupt context will use a threaded interrupt handler. I'm hoping that will allow me to simplify the code in steps.
The main reason for this split between working in interrupt context when possible, but pushing to a workqueue when not, is to allow IPA clock(s) to be turned off. Enabling the clocks is a blocking operation, so can't' be done in the top half interrupt handler. The thought was it would be best to work in interrupt context--if the clock was already active--but to defer to a workqueue to turn the clock on if necessary.
Quoted 5 lines
The result requires locking and duplication of code that I find to be pretty confusing--and hard to reason about. I have been planning to re-do things to be better suited to NAPI, and knowing that, I haven't given the data path as much attention as some of the rest.
Right, that sounds like a good plan: start making it use a threaded IRQ handler first to clean up the code, and then think about optimizing the NAPI wakeup once that works reliably.
I think what you can do here eventually is to have a combined threaded/non-threaded IRQ handler, where the threaded handler can do everything it needs to do, and the non-threaded handler does only one thing:
if all conditions are met for entering the NAPI handler (waiting for rx/tx IRQ, clocks enabled, ...) we call napi_schedule(), otherwise defer to the threaded handler.
Arnd