1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __NITROX_DEV_H 3 #define __NITROX_DEV_H 4 5 #include <linux/dma-mapping.h> 6 #include <linux/interrupt.h> 7 #include <linux/pci.h> 8 #include <linux/if.h> 9 10 #define VERSION_LEN 32 11 12 /** 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 32 */ 33 struct nitrox_cmdq { 34 spinlock_t cmd_qlock; 35 spinlock_t resp_qlock; 36 spinlock_t backlog_qlock; 37 38 struct nitrox_device *ndev; 39 struct list_head response_head; 40 struct list_head backlog_head; 41 42 u8 __iomem *dbell_csr_addr; 43 u8 __iomem *compl_cnt_csr_addr; 44 u8 *base; 45 dma_addr_t dma; 46 47 struct work_struct backlog_qflush; 48 49 atomic_t pending_count; 50 atomic_t backlog_count; 51 52 int write_idx; 53 u8 instr_size; 54 u8 qno; 55 u32 qsize; 56 57 u8 *unalign_base; 58 dma_addr_t unalign_dma; 59 }; 60 61 /** 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 72 */ 73 struct nitrox_hw { 74 char partname[IFNAMSIZ * 2]; 75 char fw_name[VERSION_LEN]; 76 77 int freq; 78 u16 vendor_id; 79 u16 device_id; 80 u8 revision_id; 81 82 u8 se_cores; 83 u8 ae_cores; 84 u8 zip_cores; 85 }; 86 87 struct nitrox_stats { 88 atomic64_t posted; 89 atomic64_t completed; 90 atomic64_t dropped; 91 }; 92 93 #define IRQ_NAMESZ 32 94 95 struct nitrox_q_vector { 96 char name[IRQ_NAMESZ]; 97 bool valid; 98 int ring; 99 struct tasklet_struct resp_tasklet; 100 union { 101 struct nitrox_cmdq *cmdq; 102 struct nitrox_device *ndev; 103 }; 104 }; 105 106 /** 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 110 */ 111 struct nitrox_iov { 112 int num_vfs; 113 struct msix_entry msix; 114 }; 115 116 /* 117 * NITROX Device states 118 */ 119 enum ndev_state { 120 __NDEV_NOT_READY, 121 __NDEV_READY, 122 __NDEV_IN_RESET, 123 }; 124 125 /* NITROX support modes for VF(s) */ 126 enum vf_mode { 127 __NDEV_MODE_PF, 128 __NDEV_MODE_VF16, 129 __NDEV_MODE_VF32, 130 __NDEV_MODE_VF64, 131 __NDEV_MODE_VF128, 132 }; 133 134 #define __NDEV_SRIOV_BIT 0 135 136 /* command queue size */ 137 #define DEFAULT_CMD_QLEN 2048 138 /* command timeout in milliseconds */ 139 #define CMD_TIMEOUT 2000 140 141 #define DEV(ndev) ((struct device *)(&(ndev)->pdev->dev)) 142 143 #define NITROX_CSR_ADDR(ndev, offset) \ 144 ((ndev)->bar_addr + (offset)) 145 146 /** 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 168 */ 169 struct nitrox_device { 170 struct list_head list; 171 172 u8 __iomem *bar_addr; 173 struct pci_dev *pdev; 174 175 atomic_t state; 176 unsigned long flags; 177 unsigned long timeout; 178 refcount_t refcnt; 179 180 u8 idx; 181 int node; 182 u16 qlen; 183 u16 nr_queues; 184 enum vf_mode mode; 185 186 struct dma_pool *ctx_pool; 187 struct nitrox_cmdq *pkt_inq; 188 189 struct nitrox_q_vector *qvec; 190 struct nitrox_iov iov; 191 int num_vecs; 192 193 struct nitrox_stats stats; 194 struct nitrox_hw hw; 195 #if IS_ENABLED(CONFIG_DEBUG_FS) 196 struct dentry *debugfs_dir; 197 #endif 198 }; 199 200 /** 201 * nitrox_read_csr - Read from device register 202 * @ndev: NITROX device 203 * @offset: offset of the register to read 204 * 205 * Returns: value read 206 */ 207 static inline u64 nitrox_read_csr(struct nitrox_device *ndev, u64 offset) 208 { 209 return readq(ndev->bar_addr + offset); 210 } 211 212 /** 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 217 */ 218 static inline void nitrox_write_csr(struct nitrox_device *ndev, u64 offset, 219 u64 value) 220 { 221 writeq(value, (ndev->bar_addr + offset)); 222 } 223 224 static inline bool nitrox_ready(struct nitrox_device *ndev) 225 { 226 return atomic_read(&ndev->state) == __NDEV_READY; 227 } 228 229 #ifdef CONFIG_DEBUG_FS 230 int nitrox_debugfs_init(struct nitrox_device *ndev); 231 void nitrox_debugfs_exit(struct nitrox_device *ndev); 232 #else 233 static inline int nitrox_debugfs_init(struct nitrox_device *ndev) 234 { 235 return 0; 236 } 237 238 static inline void nitrox_debugfs_exit(struct nitrox_device *ndev) 239 { } 240 #endif 241 242 #endif /* __NITROX_DEV_H */ 243