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
17 #define INTEL_CP_DEVICE_7360_ID 0x7360
19 /* Define for BAR area usage */
20 #define IPC_DOORBELL_BAR0 0
21 #define IPC_SCRATCHPAD_BAR2 2
23 /* Defines for DOORBELL registers information */
24 #define IPC_DOORBELL_CH_OFFSET BIT(5)
25 #define IPC_WRITE_PTR_REG_0 BIT(4)
26 #define IPC_CAPTURE_PTR_REG_0 BIT(3)
28 /* Number of MSI used for IPC */
29 #define IPC_MSI_VECTORS 1
31 /* Total number of Maximum IPC IRQ vectors used for IPC */
32 #define IPC_IRQ_VECTORS IPC_MSI_VECTORS
35 * enum ipc_pcie_sleep_state - Enum type to different sleep state transitions
36 * @IPC_PCIE_D0L12: Put the sleep state in D0L12
37 * @IPC_PCIE_D3L2: Put the sleep state in D3L2
39 enum ipc_pcie_sleep_state {
45 * struct iosm_pcie - IPC_PCIE struct.
46 * @pci: Address of the device description
47 * @dev: Pointer to generic device structure
48 * @ipc_regs: Remapped CP doorbell address of the irq register
49 * set, to fire the doorbell irq.
50 * @scratchpad: Remapped CP scratchpad address, to send the
51 * configuration. tuple and the IPC descriptors
52 * to CP in the ROM phase. The config tuple
53 * information are saved on the MSI scratchpad.
54 * @imem: Pointer to imem data struct
55 * @ipc_regs_bar_nr: BAR number to be used for IPC doorbell
56 * @scratchpad_bar_nr: BAR number to be used for Scratchpad
57 * @nvec: number of requested irq vectors
58 * @doorbell_reg_offset: doorbell_reg_offset
59 * @doorbell_write: doorbell write register
60 * @doorbell_capture: doorbell capture resgister
61 * @suspend: S2IDLE sleep/active
62 * @d3l2_support: Read WWAN RTD3 BIOS setting for D3L2 support
67 void __iomem *ipc_regs;
68 void __iomem *scratchpad;
69 struct iosm_imem *imem;
71 int scratchpad_bar_nr;
73 u32 doorbell_reg_offset;
76 unsigned long suspend;
77 enum ipc_pcie_sleep_state d3l2_support;
81 * struct ipc_skb_cb - Struct definition of the socket buffer which is mapped to
83 * @mapping: Store physical or IOVA mapped address of skb virtual add.
84 * @direction: DMA direction
85 * @len: Length of the DMA mapped region
86 * @op_type: Expected values are defined about enum ipc_ul_usr_op.
96 * enum ipc_ul_usr_op - Control operation to execute the right action on
98 * @UL_USR_OP_BLOCKED: The uplink app was blocked until CP confirms that the
99 * uplink buffer was consumed triggered by the IRQ.
100 * @UL_MUX_OP_ADB: In MUX mode the UL ADB shall be addedd to the free list.
101 * @UL_DEFAULT: SKB in non muxing mode
110 * ipc_pcie_addr_map - Maps the kernel's virtual address to either IOVA
111 * address space or Physical address space, the mapping is
112 * stored in the skb's cb.
113 * @ipc_pcie: Pointer to struct iosm_pcie
114 * @data: Skb mem containing data
116 * @mapping: Dma mapping address
117 * @direction: Data direction
119 * Returns: 0 on success and failure value on error
121 int ipc_pcie_addr_map(struct iosm_pcie *ipc_pcie, unsigned char *data,
122 size_t size, dma_addr_t *mapping, int direction);
125 * ipc_pcie_addr_unmap - Unmaps the skb memory region from IOVA address space
126 * @ipc_pcie: Pointer to struct iosm_pcie
128 * @mapping: Dma mapping address
129 * @direction: Data direction
131 void ipc_pcie_addr_unmap(struct iosm_pcie *ipc_pcie, size_t size,
132 dma_addr_t mapping, int direction);
135 * ipc_pcie_alloc_skb - Allocate an uplink SKB for the given size.
136 * @ipc_pcie: Pointer to struct iosm_pcie
137 * @size: Size of the SKB required.
138 * @flags: Allocation flags
139 * @mapping: Copies either mapped IOVA add. or converted Phy address
140 * @direction: DMA data direction
141 * @headroom: Header data offset
143 * Returns: Pointer to ipc_skb on Success, NULL on failure.
145 struct sk_buff *ipc_pcie_alloc_skb(struct iosm_pcie *ipc_pcie, size_t size,
146 gfp_t flags, dma_addr_t *mapping,
147 int direction, size_t headroom);
150 * ipc_pcie_alloc_local_skb - Allocate a local SKB for the given size.
151 * @ipc_pcie: Pointer to struct iosm_pcie
152 * @flags: Allocation flags
153 * @size: Size of the SKB required.
155 * Returns: Pointer to ipc_skb on Success, NULL on failure.
157 struct sk_buff *ipc_pcie_alloc_local_skb(struct iosm_pcie *ipc_pcie,
158 gfp_t flags, size_t size);
161 * ipc_pcie_kfree_skb - Free skb allocated by ipc_pcie_alloc_*_skb().
162 * @ipc_pcie: Pointer to struct iosm_pcie
163 * @skb: Pointer to the skb
165 void ipc_pcie_kfree_skb(struct iosm_pcie *ipc_pcie, struct sk_buff *skb);
168 * ipc_pcie_check_data_link_active - Check Data Link Layer Active
169 * @ipc_pcie: Pointer to struct iosm_pcie
171 * Returns: true if active, otherwise false
173 bool ipc_pcie_check_data_link_active(struct iosm_pcie *ipc_pcie);
176 * ipc_pcie_suspend - Callback invoked by pm_runtime_suspend. It decrements
177 * the device's usage count then, carry out a suspend,
178 * either synchronous or asynchronous.
179 * @ipc_pcie: Pointer to struct iosm_pcie
181 * Returns: 0 on success and failure value on error
183 int ipc_pcie_suspend(struct iosm_pcie *ipc_pcie);
186 * ipc_pcie_resume - Callback invoked by pm_runtime_resume. It increments
187 * the device's usage count then, carry out a resume,
188 * either synchronous or asynchronous.
189 * @ipc_pcie: Pointer to struct iosm_pcie
191 * Returns: 0 on success and failure value on error
193 int ipc_pcie_resume(struct iosm_pcie *ipc_pcie);
196 * ipc_pcie_check_aspm_enabled - Check if ASPM L1 is already enabled
197 * @ipc_pcie: Pointer to struct iosm_pcie
198 * @parent: True if checking ASPM L1 for parent else false
200 * Returns: true if ASPM is already enabled else false
202 bool ipc_pcie_check_aspm_enabled(struct iosm_pcie *ipc_pcie,
205 * ipc_pcie_config_aspm - Configure ASPM L1
206 * @ipc_pcie: Pointer to struct iosm_pcie
208 void ipc_pcie_config_aspm(struct iosm_pcie *ipc_pcie);