1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/dma-mapping.h>
6 #include <linux/interrupt.h>
12 /* command queue lock */
14 /* response list lock */
15 spinlock_t response_lock
;
16 /* backlog list lock */
17 spinlock_t backlog_lock
;
19 /* request submitted to chip, in progress */
20 struct list_head response_head
;
21 /* hw queue full, hold in backlog list */
22 struct list_head backlog_head
;
24 /* doorbell address */
25 u8 __iomem
*dbell_csr_addr
;
26 /* base address of the queue */
29 struct nitrox_device
*ndev
;
30 /* flush pending backlog commands */
31 struct work_struct backlog_qflush
;
33 /* requests posted waiting for completion */
34 atomic_t pending_count
;
35 /* requests in backlog queues */
36 atomic_t backlog_count
;
38 /* command size 32B/64B */
43 /* unaligned addresses */
45 dma_addr_t dma_unaligned
;
46 /* dma address of the base */
51 /* firmware version */
52 char fw_name
[VERSION_LEN
];
64 #define MAX_MSIX_VECTOR_NAME 20
66 * vectors for queues (64 AE, 64 SE and 64 ZIP) and
67 * error condition/mailbox.
69 #define MAX_MSIX_VECTORS 192
72 struct msix_entry
*entries
;
74 DECLARE_BITMAP(irqs
, MAX_MSIX_VECTORS
);
79 /* slc port completion count address */
80 u8 __iomem
*completion_cnt_csr_addr
;
82 struct nitrox_cmdq
*cmdq
;
83 struct tasklet_struct resp_handler
;
90 /* NITROX-5 driver state */
91 #define NITROX_UCODE_LOADED 0
92 #define NITROX_READY 1
94 /* command queue size */
95 #define DEFAULT_CMD_QLEN 2048
96 /* command timeout in milliseconds */
97 #define CMD_TIMEOUT 2000
99 #define DEV(ndev) ((struct device *)(&(ndev)->pdev->dev))
102 #define NITROX_CSR_ADDR(ndev, offset) \
103 ((ndev)->bar_addr + (offset))
106 * struct nitrox_device - NITROX Device Information.
107 * @list: pointer to linked list of devices
108 * @bar_addr: iomap address
109 * @pdev: PCI device information
110 * @status: NITROX status
111 * @timeout: Request timeout in jiffies
112 * @refcnt: Device usage count
113 * @idx: device index (0..N)
114 * @node: NUMA node id attached
115 * @qlen: Command queue length
116 * @nr_queues: Number of command queues
117 * @ctx_pool: DMA pool for crypto context
118 * @pkt_cmdqs: SE Command queues
119 * @msix: MSI-X information
120 * @bh: post processing work
121 * @hw: hardware information
122 * @debugfs_dir: debugfs directory
124 struct nitrox_device
{
125 struct list_head list
;
127 u8 __iomem
*bar_addr
;
128 struct pci_dev
*pdev
;
130 unsigned long status
;
131 unsigned long timeout
;
139 struct dma_pool
*ctx_pool
;
140 struct nitrox_cmdq
*pkt_cmdqs
;
142 struct nitrox_msix msix
;
146 #if IS_ENABLED(CONFIG_DEBUG_FS)
147 struct dentry
*debugfs_dir
;
152 * nitrox_read_csr - Read from device register
153 * @ndev: NITROX device
154 * @offset: offset of the register to read
156 * Returns: value read
158 static inline u64
nitrox_read_csr(struct nitrox_device
*ndev
, u64 offset
)
160 return readq(ndev
->bar_addr
+ offset
);
164 * nitrox_write_csr - Write to device register
165 * @ndev: NITROX device
166 * @offset: offset of the register to write
167 * @value: value to write
169 static inline void nitrox_write_csr(struct nitrox_device
*ndev
, u64 offset
,
172 writeq(value
, (ndev
->bar_addr
+ offset
));
175 static inline int nitrox_ready(struct nitrox_device
*ndev
)
177 return test_bit(NITROX_READY
, &ndev
->status
);
180 #endif /* __NITROX_DEV_H */