1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
214fa93cdSSrikanth Jampala #ifndef __NITROX_DEV_H
314fa93cdSSrikanth Jampala #define __NITROX_DEV_H
414fa93cdSSrikanth Jampala
514fa93cdSSrikanth Jampala #include <linux/dma-mapping.h>
614fa93cdSSrikanth Jampala #include <linux/interrupt.h>
714fa93cdSSrikanth Jampala #include <linux/pci.h>
848e10548SSrikanth Jampala #include <linux/if.h>
914fa93cdSSrikanth Jampala
1014fa93cdSSrikanth Jampala #define VERSION_LEN 32
11cf718eaaSSrikanth, Jampala /* Maximum queues in PF mode */
12cf718eaaSSrikanth, Jampala #define MAX_PF_QUEUES 64
13b31c17c8SPhani Kiran Hemadri /* Maximum device queues */
14b31c17c8SPhani Kiran Hemadri #define MAX_DEV_QUEUES (MAX_PF_QUEUES)
15a7268c4dSPhani Kiran Hemadri /* Maximum UCD Blocks */
16a7268c4dSPhani Kiran Hemadri #define CNN55XX_MAX_UCD_BLOCKS 8
1714fa93cdSSrikanth Jampala
18e7892dd6SSrikanth Jampala /**
19e7892dd6SSrikanth Jampala * struct nitrox_cmdq - NITROX command queue
20e7892dd6SSrikanth Jampala * @cmd_qlock: command queue lock
21e7892dd6SSrikanth Jampala * @resp_qlock: response queue lock
22e7892dd6SSrikanth Jampala * @backlog_qlock: backlog queue lock
23e7892dd6SSrikanth Jampala * @ndev: NITROX device
24e7892dd6SSrikanth Jampala * @response_head: submitted request list
25e7892dd6SSrikanth Jampala * @backlog_head: backlog queue
26e7892dd6SSrikanth Jampala * @dbell_csr_addr: doorbell register address for this queue
275155e118SSrikanth Jampala * @compl_cnt_csr_addr: completion count register address of the slc port
28e7892dd6SSrikanth Jampala * @base: command queue base address
29e7892dd6SSrikanth Jampala * @dma: dma address of the base
30e7892dd6SSrikanth Jampala * @pending_count: request pending at device
31e7892dd6SSrikanth Jampala * @backlog_count: backlog request count
32e7892dd6SSrikanth Jampala * @write_idx: next write index for the command
33e7892dd6SSrikanth Jampala * @instr_size: command size
34e7892dd6SSrikanth Jampala * @qno: command queue number
35e7892dd6SSrikanth Jampala * @qsize: command queue size
36e7892dd6SSrikanth Jampala * @unalign_base: unaligned base address
37e7892dd6SSrikanth Jampala * @unalign_dma: unaligned dma address
38e7892dd6SSrikanth Jampala */
3914fa93cdSSrikanth Jampala struct nitrox_cmdq {
40e7892dd6SSrikanth Jampala spinlock_t cmd_qlock;
41e7892dd6SSrikanth Jampala spinlock_t resp_qlock;
42e7892dd6SSrikanth Jampala spinlock_t backlog_qlock;
4314fa93cdSSrikanth Jampala
4414fa93cdSSrikanth Jampala struct nitrox_device *ndev;
45e7892dd6SSrikanth Jampala struct list_head response_head;
46e7892dd6SSrikanth Jampala struct list_head backlog_head;
47e7892dd6SSrikanth Jampala
48e7892dd6SSrikanth Jampala u8 __iomem *dbell_csr_addr;
495155e118SSrikanth Jampala u8 __iomem *compl_cnt_csr_addr;
50e7892dd6SSrikanth Jampala u8 *base;
51e7892dd6SSrikanth Jampala dma_addr_t dma;
52e7892dd6SSrikanth Jampala
5314fa93cdSSrikanth Jampala struct work_struct backlog_qflush;
5414fa93cdSSrikanth Jampala
5514fa93cdSSrikanth Jampala atomic_t pending_count;
5614fa93cdSSrikanth Jampala atomic_t backlog_count;
5714fa93cdSSrikanth Jampala
583d7c8206SSrikanth Jampala int write_idx;
5914fa93cdSSrikanth Jampala u8 instr_size;
6014fa93cdSSrikanth Jampala u8 qno;
6114fa93cdSSrikanth Jampala u32 qsize;
6214fa93cdSSrikanth Jampala
63e7892dd6SSrikanth Jampala u8 *unalign_base;
64e7892dd6SSrikanth Jampala dma_addr_t unalign_dma;
6514fa93cdSSrikanth Jampala };
6614fa93cdSSrikanth Jampala
6748e10548SSrikanth Jampala /**
6848e10548SSrikanth Jampala * struct nitrox_hw - NITROX hardware information
6948e10548SSrikanth Jampala * @partname: partname ex: CNN55xxx-xxx
7048e10548SSrikanth Jampala * @fw_name: firmware version
7148e10548SSrikanth Jampala * @freq: NITROX frequency
7248e10548SSrikanth Jampala * @vendor_id: vendor ID
7348e10548SSrikanth Jampala * @device_id: device ID
7448e10548SSrikanth Jampala * @revision_id: revision ID
7548e10548SSrikanth Jampala * @se_cores: number of symmetric cores
7648e10548SSrikanth Jampala * @ae_cores: number of asymmetric cores
7748e10548SSrikanth Jampala * @zip_cores: number of zip cores
7848e10548SSrikanth Jampala */
7914fa93cdSSrikanth Jampala struct nitrox_hw {
8048e10548SSrikanth Jampala char partname[IFNAMSIZ * 2];
81a7268c4dSPhani Kiran Hemadri char fw_name[CNN55XX_MAX_UCD_BLOCKS][VERSION_LEN];
8214fa93cdSSrikanth Jampala
8348e10548SSrikanth Jampala int freq;
8414fa93cdSSrikanth Jampala u16 vendor_id;
8514fa93cdSSrikanth Jampala u16 device_id;
8614fa93cdSSrikanth Jampala u8 revision_id;
8714fa93cdSSrikanth Jampala
8814fa93cdSSrikanth Jampala u8 se_cores;
8914fa93cdSSrikanth Jampala u8 ae_cores;
9014fa93cdSSrikanth Jampala u8 zip_cores;
9114fa93cdSSrikanth Jampala };
9214fa93cdSSrikanth Jampala
93fec165c9SSrikanth Jampala struct nitrox_stats {
94fec165c9SSrikanth Jampala atomic64_t posted;
95fec165c9SSrikanth Jampala atomic64_t completed;
96fec165c9SSrikanth Jampala atomic64_t dropped;
97fec165c9SSrikanth Jampala };
98fec165c9SSrikanth Jampala
995155e118SSrikanth Jampala #define IRQ_NAMESZ 32
10014fa93cdSSrikanth Jampala
1015155e118SSrikanth Jampala struct nitrox_q_vector {
1025155e118SSrikanth Jampala char name[IRQ_NAMESZ];
1035155e118SSrikanth Jampala bool valid;
1045155e118SSrikanth Jampala int ring;
1055155e118SSrikanth Jampala struct tasklet_struct resp_tasklet;
1065155e118SSrikanth Jampala union {
10714fa93cdSSrikanth Jampala struct nitrox_cmdq *cmdq;
1085155e118SSrikanth Jampala struct nitrox_device *ndev;
10914fa93cdSSrikanth Jampala };
11014fa93cdSSrikanth Jampala };
11114fa93cdSSrikanth Jampala
112*9e5de3e0SNagadheeraj Rottela enum mcode_type {
113*9e5de3e0SNagadheeraj Rottela MCODE_TYPE_INVALID,
114*9e5de3e0SNagadheeraj Rottela MCODE_TYPE_AE,
115*9e5de3e0SNagadheeraj Rottela MCODE_TYPE_SE_SSL,
116*9e5de3e0SNagadheeraj Rottela MCODE_TYPE_SE_IPSEC,
117*9e5de3e0SNagadheeraj Rottela };
118*9e5de3e0SNagadheeraj Rottela
1197a027b57SSrikanth, Jampala /**
120cf718eaaSSrikanth, Jampala * mbox_msg - Mailbox message data
121cf718eaaSSrikanth, Jampala * @type: message type
122cf718eaaSSrikanth, Jampala * @opcode: message opcode
123cf718eaaSSrikanth, Jampala * @data: message data
124cf718eaaSSrikanth, Jampala */
125cf718eaaSSrikanth, Jampala union mbox_msg {
126cf718eaaSSrikanth, Jampala u64 value;
127cf718eaaSSrikanth, Jampala struct {
128cf718eaaSSrikanth, Jampala u64 type: 2;
129cf718eaaSSrikanth, Jampala u64 opcode: 6;
130cf718eaaSSrikanth, Jampala u64 data: 58;
131cf718eaaSSrikanth, Jampala };
132cf718eaaSSrikanth, Jampala struct {
133cf718eaaSSrikanth, Jampala u64 type: 2;
134cf718eaaSSrikanth, Jampala u64 opcode: 6;
135cf718eaaSSrikanth, Jampala u64 chipid: 8;
136cf718eaaSSrikanth, Jampala u64 vfid: 8;
137cf718eaaSSrikanth, Jampala } id;
138*9e5de3e0SNagadheeraj Rottela struct {
139*9e5de3e0SNagadheeraj Rottela u64 type: 2;
140*9e5de3e0SNagadheeraj Rottela u64 opcode: 6;
141*9e5de3e0SNagadheeraj Rottela u64 count: 4;
142*9e5de3e0SNagadheeraj Rottela u64 info: 40;
143*9e5de3e0SNagadheeraj Rottela u64 next_se_grp: 3;
144*9e5de3e0SNagadheeraj Rottela u64 next_ae_grp: 3;
145*9e5de3e0SNagadheeraj Rottela } mcode_info;
146cf718eaaSSrikanth, Jampala };
147cf718eaaSSrikanth, Jampala
148cf718eaaSSrikanth, Jampala /**
149cf718eaaSSrikanth, Jampala * nitrox_vfdev - NITROX VF device instance in PF
150cf718eaaSSrikanth, Jampala * @state: VF device state
151cf718eaaSSrikanth, Jampala * @vfno: VF number
152cf718eaaSSrikanth, Jampala * @nr_queues: number of queues enabled in VF
153cf718eaaSSrikanth, Jampala * @ring: ring to communicate with VF
154cf718eaaSSrikanth, Jampala * @msg: Mailbox message data from VF
155cf718eaaSSrikanth, Jampala * @mbx_resp: Mailbox counters
156cf718eaaSSrikanth, Jampala */
157cf718eaaSSrikanth, Jampala struct nitrox_vfdev {
158cf718eaaSSrikanth, Jampala atomic_t state;
159cf718eaaSSrikanth, Jampala int vfno;
160cf718eaaSSrikanth, Jampala int nr_queues;
161cf718eaaSSrikanth, Jampala int ring;
162cf718eaaSSrikanth, Jampala union mbox_msg msg;
163cf718eaaSSrikanth, Jampala atomic64_t mbx_resp;
164cf718eaaSSrikanth, Jampala };
165cf718eaaSSrikanth, Jampala
166cf718eaaSSrikanth, Jampala /**
1677a027b57SSrikanth, Jampala * struct nitrox_iov - SR-IOV information
1687a027b57SSrikanth, Jampala * @num_vfs: number of VF(s) enabled
169cf718eaaSSrikanth, Jampala * @max_vf_queues: Maximum number of queues allowed for VF
170cf718eaaSSrikanth, Jampala * @vfdev: VF(s) devices
171cf718eaaSSrikanth, Jampala * @pf2vf_wq: workqueue for PF2VF communication
172cf718eaaSSrikanth, Jampala * @msix: MSI-X entry for PF in SR-IOV case
1737a027b57SSrikanth, Jampala */
1747a027b57SSrikanth, Jampala struct nitrox_iov {
1757a027b57SSrikanth, Jampala int num_vfs;
176cf718eaaSSrikanth, Jampala int max_vf_queues;
177cf718eaaSSrikanth, Jampala struct nitrox_vfdev *vfdev;
178cf718eaaSSrikanth, Jampala struct workqueue_struct *pf2vf_wq;
1797a027b57SSrikanth, Jampala struct msix_entry msix;
1807a027b57SSrikanth, Jampala };
1817a027b57SSrikanth, Jampala
18241a9aca6SSrikanth Jampala /*
18341a9aca6SSrikanth Jampala * NITROX Device states
18441a9aca6SSrikanth Jampala */
18541a9aca6SSrikanth Jampala enum ndev_state {
18641a9aca6SSrikanth Jampala __NDEV_NOT_READY,
18741a9aca6SSrikanth Jampala __NDEV_READY,
18841a9aca6SSrikanth Jampala __NDEV_IN_RESET,
18941a9aca6SSrikanth Jampala };
19041a9aca6SSrikanth Jampala
19141a9aca6SSrikanth Jampala /* NITROX support modes for VF(s) */
19241a9aca6SSrikanth Jampala enum vf_mode {
19341a9aca6SSrikanth Jampala __NDEV_MODE_PF,
19441a9aca6SSrikanth Jampala __NDEV_MODE_VF16,
19541a9aca6SSrikanth Jampala __NDEV_MODE_VF32,
19641a9aca6SSrikanth Jampala __NDEV_MODE_VF64,
19741a9aca6SSrikanth Jampala __NDEV_MODE_VF128,
19841a9aca6SSrikanth Jampala };
19941a9aca6SSrikanth Jampala
20041a9aca6SSrikanth Jampala #define __NDEV_SRIOV_BIT 0
20114fa93cdSSrikanth Jampala
20214fa93cdSSrikanth Jampala /* command queue size */
20314fa93cdSSrikanth Jampala #define DEFAULT_CMD_QLEN 2048
20414fa93cdSSrikanth Jampala /* command timeout in milliseconds */
20514fa93cdSSrikanth Jampala #define CMD_TIMEOUT 2000
20614fa93cdSSrikanth Jampala
20714fa93cdSSrikanth Jampala #define DEV(ndev) ((struct device *)(&(ndev)->pdev->dev))
20814fa93cdSSrikanth Jampala
20914fa93cdSSrikanth Jampala #define NITROX_CSR_ADDR(ndev, offset) \
21014fa93cdSSrikanth Jampala ((ndev)->bar_addr + (offset))
21114fa93cdSSrikanth Jampala
21214fa93cdSSrikanth Jampala /**
21314fa93cdSSrikanth Jampala * struct nitrox_device - NITROX Device Information.
21414fa93cdSSrikanth Jampala * @list: pointer to linked list of devices
21514fa93cdSSrikanth Jampala * @bar_addr: iomap address
21614fa93cdSSrikanth Jampala * @pdev: PCI device information
21741a9aca6SSrikanth Jampala * @state: NITROX device state
21841a9aca6SSrikanth Jampala * @flags: flags to indicate device the features
21914fa93cdSSrikanth Jampala * @timeout: Request timeout in jiffies
22014fa93cdSSrikanth Jampala * @refcnt: Device usage count
22114fa93cdSSrikanth Jampala * @idx: device index (0..N)
22214fa93cdSSrikanth Jampala * @node: NUMA node id attached
22314fa93cdSSrikanth Jampala * @qlen: Command queue length
22414fa93cdSSrikanth Jampala * @nr_queues: Number of command queues
22541a9aca6SSrikanth Jampala * @mode: Device mode PF/VF
22614fa93cdSSrikanth Jampala * @ctx_pool: DMA pool for crypto context
227e7892dd6SSrikanth Jampala * @pkt_inq: Packet input rings
228b31c17c8SPhani Kiran Hemadri * @aqmq: AQM command queues
2295155e118SSrikanth Jampala * @qvec: MSI-X queue vectors information
2307a027b57SSrikanth, Jampala * @iov: SR-IOV informatin
2317a027b57SSrikanth, Jampala * @num_vecs: number of MSI-X vectors
2327a027b57SSrikanth, Jampala * @stats: request statistics
23314fa93cdSSrikanth Jampala * @hw: hardware information
234086eac9eSSrikanth Jampala * @debugfs_dir: debugfs directory
23514fa93cdSSrikanth Jampala */
23614fa93cdSSrikanth Jampala struct nitrox_device {
23714fa93cdSSrikanth Jampala struct list_head list;
23814fa93cdSSrikanth Jampala
23914fa93cdSSrikanth Jampala u8 __iomem *bar_addr;
24014fa93cdSSrikanth Jampala struct pci_dev *pdev;
24114fa93cdSSrikanth Jampala
24241a9aca6SSrikanth Jampala atomic_t state;
24341a9aca6SSrikanth Jampala unsigned long flags;
24414fa93cdSSrikanth Jampala unsigned long timeout;
24514fa93cdSSrikanth Jampala refcount_t refcnt;
24614fa93cdSSrikanth Jampala
24714fa93cdSSrikanth Jampala u8 idx;
24814fa93cdSSrikanth Jampala int node;
24914fa93cdSSrikanth Jampala u16 qlen;
25014fa93cdSSrikanth Jampala u16 nr_queues;
25141a9aca6SSrikanth Jampala enum vf_mode mode;
25214fa93cdSSrikanth Jampala
25314fa93cdSSrikanth Jampala struct dma_pool *ctx_pool;
254e7892dd6SSrikanth Jampala struct nitrox_cmdq *pkt_inq;
255b31c17c8SPhani Kiran Hemadri struct nitrox_cmdq *aqmq[MAX_DEV_QUEUES] ____cacheline_aligned_in_smp;
25614fa93cdSSrikanth Jampala
2575155e118SSrikanth Jampala struct nitrox_q_vector *qvec;
2587a027b57SSrikanth, Jampala struct nitrox_iov iov;
2595155e118SSrikanth Jampala int num_vecs;
26014fa93cdSSrikanth Jampala
261fec165c9SSrikanth Jampala struct nitrox_stats stats;
26214fa93cdSSrikanth Jampala struct nitrox_hw hw;
263086eac9eSSrikanth Jampala #if IS_ENABLED(CONFIG_DEBUG_FS)
264086eac9eSSrikanth Jampala struct dentry *debugfs_dir;
265086eac9eSSrikanth Jampala #endif
26614fa93cdSSrikanth Jampala };
26714fa93cdSSrikanth Jampala
26814fa93cdSSrikanth Jampala /**
26914fa93cdSSrikanth Jampala * nitrox_read_csr - Read from device register
27014fa93cdSSrikanth Jampala * @ndev: NITROX device
27114fa93cdSSrikanth Jampala * @offset: offset of the register to read
27214fa93cdSSrikanth Jampala *
27314fa93cdSSrikanth Jampala * Returns: value read
27414fa93cdSSrikanth Jampala */
nitrox_read_csr(struct nitrox_device * ndev,u64 offset)27514fa93cdSSrikanth Jampala static inline u64 nitrox_read_csr(struct nitrox_device *ndev, u64 offset)
27614fa93cdSSrikanth Jampala {
27714fa93cdSSrikanth Jampala return readq(ndev->bar_addr + offset);
27814fa93cdSSrikanth Jampala }
27914fa93cdSSrikanth Jampala
28014fa93cdSSrikanth Jampala /**
28114fa93cdSSrikanth Jampala * nitrox_write_csr - Write to device register
28214fa93cdSSrikanth Jampala * @ndev: NITROX device
28314fa93cdSSrikanth Jampala * @offset: offset of the register to write
28414fa93cdSSrikanth Jampala * @value: value to write
28514fa93cdSSrikanth Jampala */
nitrox_write_csr(struct nitrox_device * ndev,u64 offset,u64 value)28614fa93cdSSrikanth Jampala static inline void nitrox_write_csr(struct nitrox_device *ndev, u64 offset,
28714fa93cdSSrikanth Jampala u64 value)
28814fa93cdSSrikanth Jampala {
28914fa93cdSSrikanth Jampala writeq(value, (ndev->bar_addr + offset));
29014fa93cdSSrikanth Jampala }
29114fa93cdSSrikanth Jampala
nitrox_ready(struct nitrox_device * ndev)29241a9aca6SSrikanth Jampala static inline bool nitrox_ready(struct nitrox_device *ndev)
29314fa93cdSSrikanth Jampala {
29441a9aca6SSrikanth Jampala return atomic_read(&ndev->state) == __NDEV_READY;
29514fa93cdSSrikanth Jampala }
29614fa93cdSSrikanth Jampala
nitrox_vfdev_ready(struct nitrox_vfdev * vfdev)297cf718eaaSSrikanth, Jampala static inline bool nitrox_vfdev_ready(struct nitrox_vfdev *vfdev)
2982a8780beSSrikanth Jampala {
299cf718eaaSSrikanth, Jampala return atomic_read(&vfdev->state) == __NDEV_READY;
3002a8780beSSrikanth Jampala }
3012a8780beSSrikanth Jampala
30214fa93cdSSrikanth Jampala #endif /* __NITROX_DEV_H */
303