1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/dma-mapping.h>
6 #include <linux/interrupt.h>
10 #define VERSION_LEN 32
13 * struct nitrox_cmdq - NITROX command queue
14 * @cmd_qlock: command queue lock
15 * @resp_qlock: response queue lock
16 * @backlog_qlock: backlog queue lock
17 * @ndev: NITROX device
18 * @response_head: submitted request list
19 * @backlog_head: backlog queue
20 * @dbell_csr_addr: doorbell register address for this queue
21 * @compl_cnt_csr_addr: completion count register address of the slc port
22 * @base: command queue base address
23 * @dma: dma address of the base
24 * @pending_count: request pending at device
25 * @backlog_count: backlog request count
26 * @write_idx: next write index for the command
27 * @instr_size: command size
28 * @qno: command queue number
29 * @qsize: command queue size
30 * @unalign_base: unaligned base address
31 * @unalign_dma: unaligned dma address
35 spinlock_t resp_qlock;
36 spinlock_t backlog_qlock;
38 struct nitrox_device *ndev;
39 struct list_head response_head;
40 struct list_head backlog_head;
42 u8 __iomem *dbell_csr_addr;
43 u8 __iomem *compl_cnt_csr_addr;
47 struct work_struct backlog_qflush;
49 atomic_t pending_count;
50 atomic_t backlog_count;
58 dma_addr_t unalign_dma;
62 * struct nitrox_hw - NITROX hardware information
63 * @partname: partname ex: CNN55xxx-xxx
64 * @fw_name: firmware version
65 * @freq: NITROX frequency
66 * @vendor_id: vendor ID
67 * @device_id: device ID
68 * @revision_id: revision ID
69 * @se_cores: number of symmetric cores
70 * @ae_cores: number of asymmetric cores
71 * @zip_cores: number of zip cores
74 char partname[IFNAMSIZ * 2];
75 char fw_name[VERSION_LEN];
95 struct nitrox_q_vector {
96 char name[IRQ_NAMESZ];
99 struct tasklet_struct resp_tasklet;
101 struct nitrox_cmdq *cmdq;
102 struct nitrox_device *ndev;
107 * struct nitrox_iov - SR-IOV information
108 * @num_vfs: number of VF(s) enabled
109 * @msix: MSI-X for PF in SR-IOV case
113 struct msix_entry msix;
117 * NITROX Device states
125 /* NITROX support modes for VF(s) */
134 #define __NDEV_SRIOV_BIT 0
136 /* command queue size */
137 #define DEFAULT_CMD_QLEN 2048
138 /* command timeout in milliseconds */
139 #define CMD_TIMEOUT 2000
141 #define DEV(ndev) ((struct device *)(&(ndev)->pdev->dev))
143 #define NITROX_CSR_ADDR(ndev, offset) \
144 ((ndev)->bar_addr + (offset))
147 * struct nitrox_device - NITROX Device Information.
148 * @list: pointer to linked list of devices
149 * @bar_addr: iomap address
150 * @pdev: PCI device information
151 * @state: NITROX device state
152 * @flags: flags to indicate device the features
153 * @timeout: Request timeout in jiffies
154 * @refcnt: Device usage count
155 * @idx: device index (0..N)
156 * @node: NUMA node id attached
157 * @qlen: Command queue length
158 * @nr_queues: Number of command queues
159 * @mode: Device mode PF/VF
160 * @ctx_pool: DMA pool for crypto context
161 * @pkt_inq: Packet input rings
162 * @qvec: MSI-X queue vectors information
163 * @iov: SR-IOV informatin
164 * @num_vecs: number of MSI-X vectors
165 * @stats: request statistics
166 * @hw: hardware information
167 * @debugfs_dir: debugfs directory
169 struct nitrox_device {
170 struct list_head list;
172 u8 __iomem *bar_addr;
173 struct pci_dev *pdev;
177 unsigned long timeout;
186 struct dma_pool *ctx_pool;
187 struct nitrox_cmdq *pkt_inq;
189 struct nitrox_q_vector *qvec;
190 struct nitrox_iov iov;
193 struct nitrox_stats stats;
195 #if IS_ENABLED(CONFIG_DEBUG_FS)
196 struct dentry *debugfs_dir;
201 * nitrox_read_csr - Read from device register
202 * @ndev: NITROX device
203 * @offset: offset of the register to read
205 * Returns: value read
207 static inline u64 nitrox_read_csr(struct nitrox_device *ndev, u64 offset)
209 return readq(ndev->bar_addr + offset);
213 * nitrox_write_csr - Write to device register
214 * @ndev: NITROX device
215 * @offset: offset of the register to write
216 * @value: value to write
218 static inline void nitrox_write_csr(struct nitrox_device *ndev, u64 offset,
221 writeq(value, (ndev->bar_addr + offset));
224 static inline bool nitrox_ready(struct nitrox_device *ndev)
226 return atomic_read(&ndev->state) == __NDEV_READY;
229 #ifdef CONFIG_DEBUG_FS
230 int nitrox_debugfs_init(struct nitrox_device *ndev);
231 void nitrox_debugfs_exit(struct nitrox_device *ndev);
233 static inline int nitrox_debugfs_init(struct nitrox_device *ndev)
238 static inline void nitrox_debugfs_exit(struct nitrox_device *ndev)
242 #endif /* __NITROX_DEV_H */