xref: /linux/drivers/net/wwan/iosm/iosm_ipc_pcie.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0-only
2  *
3  * Copyright (C) 2020-21 Intel Corporation.
4  */
5 
6 #ifndef IOSM_IPC_PCIE_H
7 #define IOSM_IPC_PCIE_H
8 
9 #include <linux/device.h>
10 #include <linux/pci.h>
11 #include <linux/skbuff.h>
12 
13 #include "iosm_ipc_irq.h"
14 
15 /* Device ID */
16 #define INTEL_CP_DEVICE_7560_ID 0x7560
17 #define INTEL_CP_DEVICE_7360_ID 0x7360
18 
19 /* Define for BAR area usage */
20 #define IPC_DOORBELL_BAR0 0
21 #define IPC_SCRATCHPAD_BAR2 2
22 
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)
27 
28 /* Number of MSI used for IPC */
29 #define IPC_MSI_VECTORS 1
30 
31 /* Total number of Maximum IPC IRQ vectors used for IPC */
32 #define IPC_IRQ_VECTORS IPC_MSI_VECTORS
33 
34 /**
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
38  */
39 enum ipc_pcie_sleep_state {
40 	IPC_PCIE_D0L12,
41 	IPC_PCIE_D3L2,
42 };
43 
44 /**
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
63  */
64 struct iosm_pcie {
65 	struct pci_dev *pci;
66 	struct device *dev;
67 	void __iomem *ipc_regs;
68 	void __iomem *scratchpad;
69 	struct iosm_imem *imem;
70 	int ipc_regs_bar_nr;
71 	int scratchpad_bar_nr;
72 	int nvec;
73 	u32 doorbell_reg_offset;
74 	u32 doorbell_write;
75 	u32 doorbell_capture;
76 	unsigned long suspend;
77 	enum ipc_pcie_sleep_state d3l2_support;
78 };
79 
80 /**
81  * struct ipc_skb_cb - Struct definition of the socket buffer which is mapped to
82  *		       the cb field of sbk
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.
87  */
88 struct ipc_skb_cb {
89 	dma_addr_t mapping;
90 	int direction;
91 	int len;
92 	u8 op_type;
93 };
94 
95 /**
96  * enum ipc_ul_usr_op - Control operation to execute the right action on
97  *			the user interface.
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
102  */
103 enum ipc_ul_usr_op {
104 	UL_USR_OP_BLOCKED,
105 	UL_MUX_OP_ADB,
106 	UL_DEFAULT,
107 };
108 
109 /**
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
115  * @size:	Data size
116  * @mapping:	Dma mapping address
117  * @direction:	Data direction
118  *
119  * Returns: 0 on success and failure value on error
120  */
121 int ipc_pcie_addr_map(struct iosm_pcie *ipc_pcie, unsigned char *data,
122 		      size_t size, dma_addr_t *mapping, int direction);
123 
124 /**
125  * ipc_pcie_addr_unmap - Unmaps the skb memory region from IOVA address space
126  * @ipc_pcie:	Pointer to struct iosm_pcie
127  * @size:	Data size
128  * @mapping:	Dma mapping address
129  * @direction:	Data direction
130  */
131 void ipc_pcie_addr_unmap(struct iosm_pcie *ipc_pcie, size_t size,
132 			 dma_addr_t mapping, int direction);
133 
134 /**
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
142  *
143  * Returns: Pointer to ipc_skb on Success, NULL on failure.
144  */
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);
148 
149 /**
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.
154  *
155  * Returns: Pointer to ipc_skb on Success, NULL on failure.
156  */
157 struct sk_buff *ipc_pcie_alloc_local_skb(struct iosm_pcie *ipc_pcie,
158 					 gfp_t flags, size_t size);
159 
160 /**
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
164  */
165 void ipc_pcie_kfree_skb(struct iosm_pcie *ipc_pcie, struct sk_buff *skb);
166 
167 /**
168  * ipc_pcie_check_data_link_active - Check Data Link Layer Active
169  * @ipc_pcie:	Pointer to struct iosm_pcie
170  *
171  * Returns: true if active, otherwise false
172  */
173 bool ipc_pcie_check_data_link_active(struct iosm_pcie *ipc_pcie);
174 
175 /**
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
180  *
181  * Returns: 0 on success and failure value on error
182  */
183 int ipc_pcie_suspend(struct iosm_pcie *ipc_pcie);
184 
185 /**
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
190  *
191  * Returns: 0 on success and failure value on error
192  */
193 int ipc_pcie_resume(struct iosm_pcie *ipc_pcie);
194 
195 /**
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
199  *
200  * Returns: true if ASPM is already enabled else false
201  */
202 bool ipc_pcie_check_aspm_enabled(struct iosm_pcie *ipc_pcie,
203 				 bool parent);
204 /**
205  * ipc_pcie_config_aspm - Configure ASPM L1
206  * @ipc_pcie:	Pointer to struct iosm_pcie
207  */
208 void ipc_pcie_config_aspm(struct iosm_pcie *ipc_pcie);
209 
210 #endif
211