1 /* SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2020-21 Intel Corporation.
6 #ifndef IOSM_IPC_PCIE_H
7 #define IOSM_IPC_PCIE_H
9 #include <linux/device.h>
10 #include <linux/pci.h>
11 #include <linux/skbuff.h>
13 #include "iosm_ipc_irq.h"
16 #define INTEL_CP_DEVICE_7560_ID 0x7560
18 /* Define for BAR area usage */
19 #define IPC_DOORBELL_BAR0 0
20 #define IPC_SCRATCHPAD_BAR2 2
22 /* Defines for DOORBELL registers information */
23 #define IPC_DOORBELL_CH_OFFSET BIT(5)
24 #define IPC_WRITE_PTR_REG_0 BIT(4)
25 #define IPC_CAPTURE_PTR_REG_0 BIT(3)
27 /* Number of MSI used for IPC */
28 #define IPC_MSI_VECTORS 1
30 /* Total number of Maximum IPC IRQ vectors used for IPC */
31 #define IPC_IRQ_VECTORS IPC_MSI_VECTORS
34 * enum ipc_pcie_sleep_state - Enum type to different sleep state transitions
35 * @IPC_PCIE_D0L12: Put the sleep state in D0L12
36 * @IPC_PCIE_D3L2: Put the sleep state in D3L2
38 enum ipc_pcie_sleep_state {
44 * struct iosm_pcie - IPC_PCIE struct.
45 * @pci: Address of the device description
46 * @dev: Pointer to generic device structure
47 * @ipc_regs: Remapped CP doorbell address of the irq register
48 * set, to fire the doorbell irq.
49 * @scratchpad: Remapped CP scratchpad address, to send the
50 * configuration. tuple and the IPC descriptors
51 * to CP in the ROM phase. The config tuple
52 * information are saved on the MSI scratchpad.
53 * @imem: Pointer to imem data struct
54 * @ipc_regs_bar_nr: BAR number to be used for IPC doorbell
55 * @scratchpad_bar_nr: BAR number to be used for Scratchpad
56 * @nvec: number of requested irq vectors
57 * @doorbell_reg_offset: doorbell_reg_offset
58 * @doorbell_write: doorbell write register
59 * @doorbell_capture: doorbell capture resgister
60 * @suspend: S2IDLE sleep/active
61 * @d3l2_support: Read WWAN RTD3 BIOS setting for D3L2 support
66 void __iomem *ipc_regs;
67 void __iomem *scratchpad;
68 struct iosm_imem *imem;
70 int scratchpad_bar_nr;
72 u32 doorbell_reg_offset;
75 unsigned long suspend;
76 enum ipc_pcie_sleep_state d3l2_support;
80 * struct ipc_skb_cb - Struct definition of the socket buffer which is mapped to
82 * @mapping: Store physical or IOVA mapped address of skb virtual add.
83 * @direction: DMA direction
84 * @len: Length of the DMA mapped region
85 * @op_type: Expected values are defined about enum ipc_ul_usr_op.
95 * enum ipc_ul_usr_op - Control operation to execute the right action on
97 * @UL_USR_OP_BLOCKED: The uplink app was blocked until CP confirms that the
98 * uplink buffer was consumed triggered by the IRQ.
99 * @UL_MUX_OP_ADB: In MUX mode the UL ADB shall be addedd to the free list.
100 * @UL_DEFAULT: SKB in non muxing mode
109 * ipc_pcie_addr_map - Maps the kernel's virtual address to either IOVA
110 * address space or Physical address space, the mapping is
111 * stored in the skb's cb.
112 * @ipc_pcie: Pointer to struct iosm_pcie
113 * @data: Skb mem containing data
115 * @mapping: Dma mapping address
116 * @direction: Data direction
118 * Returns: 0 on success and failure value on error
120 int ipc_pcie_addr_map(struct iosm_pcie *ipc_pcie, unsigned char *data,
121 size_t size, dma_addr_t *mapping, int direction);
124 * ipc_pcie_addr_unmap - Unmaps the skb memory region from IOVA address space
125 * @ipc_pcie: Pointer to struct iosm_pcie
127 * @mapping: Dma mapping address
128 * @direction: Data direction
130 void ipc_pcie_addr_unmap(struct iosm_pcie *ipc_pcie, size_t size,
131 dma_addr_t mapping, int direction);
134 * ipc_pcie_alloc_skb - Allocate an uplink SKB for the given size.
135 * @ipc_pcie: Pointer to struct iosm_pcie
136 * @size: Size of the SKB required.
137 * @flags: Allocation flags
138 * @mapping: Copies either mapped IOVA add. or converted Phy address
139 * @direction: DMA data direction
140 * @headroom: Header data offset
142 * Returns: Pointer to ipc_skb on Success, NULL on failure.
144 struct sk_buff *ipc_pcie_alloc_skb(struct iosm_pcie *ipc_pcie, size_t size,
145 gfp_t flags, dma_addr_t *mapping,
146 int direction, size_t headroom);
149 * ipc_pcie_alloc_local_skb - Allocate a local SKB for the given size.
150 * @ipc_pcie: Pointer to struct iosm_pcie
151 * @flags: Allocation flags
152 * @size: Size of the SKB required.
154 * Returns: Pointer to ipc_skb on Success, NULL on failure.
156 struct sk_buff *ipc_pcie_alloc_local_skb(struct iosm_pcie *ipc_pcie,
157 gfp_t flags, size_t size);
160 * ipc_pcie_kfree_skb - Free skb allocated by ipc_pcie_alloc_*_skb().
161 * @ipc_pcie: Pointer to struct iosm_pcie
162 * @skb: Pointer to the skb
164 void ipc_pcie_kfree_skb(struct iosm_pcie *ipc_pcie, struct sk_buff *skb);
167 * ipc_pcie_check_data_link_active - Check Data Link Layer Active
168 * @ipc_pcie: Pointer to struct iosm_pcie
170 * Returns: true if active, otherwise false
172 bool ipc_pcie_check_data_link_active(struct iosm_pcie *ipc_pcie);
175 * ipc_pcie_suspend - Callback invoked by pm_runtime_suspend. It decrements
176 * the device's usage count then, carry out a suspend,
177 * either synchronous or asynchronous.
178 * @ipc_pcie: Pointer to struct iosm_pcie
180 * Returns: 0 on success and failure value on error
182 int ipc_pcie_suspend(struct iosm_pcie *ipc_pcie);
185 * ipc_pcie_resume - Callback invoked by pm_runtime_resume. It increments
186 * the device's usage count then, carry out a resume,
187 * either synchronous or asynchronous.
188 * @ipc_pcie: Pointer to struct iosm_pcie
190 * Returns: 0 on success and failure value on error
192 int ipc_pcie_resume(struct iosm_pcie *ipc_pcie);
195 * ipc_pcie_check_aspm_enabled - Check if ASPM L1 is already enabled
196 * @ipc_pcie: Pointer to struct iosm_pcie
197 * @parent: True if checking ASPM L1 for parent else false
199 * Returns: true if ASPM is already enabled else false
201 bool ipc_pcie_check_aspm_enabled(struct iosm_pcie *ipc_pcie,
204 * ipc_pcie_config_aspm - Configure ASPM L1
205 * @ipc_pcie: Pointer to struct iosm_pcie
207 void ipc_pcie_config_aspm(struct iosm_pcie *ipc_pcie);