Path: blob/master/drivers/crypto/cavium/nitrox/nitrox_dev.h
26285 views
/* SPDX-License-Identifier: GPL-2.0 */1#ifndef __NITROX_DEV_H2#define __NITROX_DEV_H34#include <linux/dma-mapping.h>5#include <linux/interrupt.h>6#include <linux/pci.h>7#include <linux/if.h>89#define VERSION_LEN 3210/* Maximum queues in PF mode */11#define MAX_PF_QUEUES 6412/* Maximum device queues */13#define MAX_DEV_QUEUES (MAX_PF_QUEUES)14/* Maximum UCD Blocks */15#define CNN55XX_MAX_UCD_BLOCKS 81617/**18* struct nitrox_cmdq - NITROX command queue19* @cmd_qlock: command queue lock20* @resp_qlock: response queue lock21* @backlog_qlock: backlog queue lock22* @ndev: NITROX device23* @response_head: submitted request list24* @backlog_head: backlog queue25* @dbell_csr_addr: doorbell register address for this queue26* @compl_cnt_csr_addr: completion count register address of the slc port27* @base: command queue base address28* @dma: dma address of the base29* @pending_count: request pending at device30* @backlog_count: backlog request count31* @write_idx: next write index for the command32* @instr_size: command size33* @qno: command queue number34* @qsize: command queue size35* @unalign_base: unaligned base address36* @unalign_dma: unaligned dma address37*/38struct nitrox_cmdq {39spinlock_t cmd_qlock;40spinlock_t resp_qlock;41spinlock_t backlog_qlock;4243struct nitrox_device *ndev;44struct list_head response_head;45struct list_head backlog_head;4647u8 __iomem *dbell_csr_addr;48u8 __iomem *compl_cnt_csr_addr;49u8 *base;50dma_addr_t dma;5152struct work_struct backlog_qflush;5354atomic_t pending_count;55atomic_t backlog_count;5657int write_idx;58u8 instr_size;59u8 qno;60u32 qsize;6162u8 *unalign_base;63dma_addr_t unalign_dma;64};6566/**67* struct nitrox_hw - NITROX hardware information68* @partname: partname ex: CNN55xxx-xxx69* @fw_name: firmware version70* @freq: NITROX frequency71* @vendor_id: vendor ID72* @device_id: device ID73* @revision_id: revision ID74* @se_cores: number of symmetric cores75* @ae_cores: number of asymmetric cores76* @zip_cores: number of zip cores77*/78struct nitrox_hw {79char partname[IFNAMSIZ * 2];80char fw_name[CNN55XX_MAX_UCD_BLOCKS][VERSION_LEN];8182int freq;83u16 vendor_id;84u16 device_id;85u8 revision_id;8687u8 se_cores;88u8 ae_cores;89u8 zip_cores;90};9192struct nitrox_stats {93atomic64_t posted;94atomic64_t completed;95atomic64_t dropped;96};9798#define IRQ_NAMESZ 3299100struct nitrox_q_vector {101char name[IRQ_NAMESZ];102bool valid;103int ring;104struct tasklet_struct resp_tasklet;105union {106struct nitrox_cmdq *cmdq;107struct nitrox_device *ndev;108};109};110111enum mcode_type {112MCODE_TYPE_INVALID,113MCODE_TYPE_AE,114MCODE_TYPE_SE_SSL,115MCODE_TYPE_SE_IPSEC,116};117118/**119* mbox_msg - Mailbox message data120* @type: message type121* @opcode: message opcode122* @data: message data123*/124union mbox_msg {125u64 value;126struct {127u64 type: 2;128u64 opcode: 6;129u64 data: 58;130};131struct {132u64 type: 2;133u64 opcode: 6;134u64 chipid: 8;135u64 vfid: 8;136} id;137struct {138u64 type: 2;139u64 opcode: 6;140u64 count: 4;141u64 info: 40;142u64 next_se_grp: 3;143u64 next_ae_grp: 3;144} mcode_info;145};146147/**148* nitrox_vfdev - NITROX VF device instance in PF149* @state: VF device state150* @vfno: VF number151* @nr_queues: number of queues enabled in VF152* @ring: ring to communicate with VF153* @msg: Mailbox message data from VF154* @mbx_resp: Mailbox counters155*/156struct nitrox_vfdev {157atomic_t state;158int vfno;159int nr_queues;160int ring;161union mbox_msg msg;162atomic64_t mbx_resp;163};164165/**166* struct nitrox_iov - SR-IOV information167* @num_vfs: number of VF(s) enabled168* @max_vf_queues: Maximum number of queues allowed for VF169* @vfdev: VF(s) devices170* @pf2vf_wq: workqueue for PF2VF communication171* @msix: MSI-X entry for PF in SR-IOV case172*/173struct nitrox_iov {174int num_vfs;175int max_vf_queues;176struct nitrox_vfdev *vfdev;177struct workqueue_struct *pf2vf_wq;178struct msix_entry msix;179};180181/*182* NITROX Device states183*/184enum ndev_state {185__NDEV_NOT_READY,186__NDEV_READY,187__NDEV_IN_RESET,188};189190/* NITROX support modes for VF(s) */191enum vf_mode {192__NDEV_MODE_PF,193__NDEV_MODE_VF16,194__NDEV_MODE_VF32,195__NDEV_MODE_VF64,196__NDEV_MODE_VF128,197};198199#define __NDEV_SRIOV_BIT 0200201/* command queue size */202#define DEFAULT_CMD_QLEN 2048203/* command timeout in milliseconds */204#define CMD_TIMEOUT 2000205206#define DEV(ndev) ((struct device *)(&(ndev)->pdev->dev))207208#define NITROX_CSR_ADDR(ndev, offset) \209((ndev)->bar_addr + (offset))210211/**212* struct nitrox_device - NITROX Device Information.213* @list: pointer to linked list of devices214* @bar_addr: iomap address215* @pdev: PCI device information216* @state: NITROX device state217* @flags: flags to indicate device the features218* @timeout: Request timeout in jiffies219* @refcnt: Device usage count220* @idx: device index (0..N)221* @node: NUMA node id attached222* @qlen: Command queue length223* @nr_queues: Number of command queues224* @mode: Device mode PF/VF225* @ctx_pool: DMA pool for crypto context226* @pkt_inq: Packet input rings227* @aqmq: AQM command queues228* @qvec: MSI-X queue vectors information229* @iov: SR-IOV informatin230* @num_vecs: number of MSI-X vectors231* @stats: request statistics232* @hw: hardware information233* @debugfs_dir: debugfs directory234*/235struct nitrox_device {236struct list_head list;237238u8 __iomem *bar_addr;239struct pci_dev *pdev;240241atomic_t state;242unsigned long flags;243unsigned long timeout;244refcount_t refcnt;245246u8 idx;247int node;248u16 qlen;249u16 nr_queues;250enum vf_mode mode;251252struct dma_pool *ctx_pool;253struct nitrox_cmdq *pkt_inq;254struct nitrox_cmdq *aqmq[MAX_DEV_QUEUES] ____cacheline_aligned_in_smp;255256struct nitrox_q_vector *qvec;257struct nitrox_iov iov;258int num_vecs;259260struct nitrox_stats stats;261struct nitrox_hw hw;262#if IS_ENABLED(CONFIG_DEBUG_FS)263struct dentry *debugfs_dir;264#endif265};266267/**268* nitrox_read_csr - Read from device register269* @ndev: NITROX device270* @offset: offset of the register to read271*272* Returns: value read273*/274static inline u64 nitrox_read_csr(struct nitrox_device *ndev, u64 offset)275{276return readq(ndev->bar_addr + offset);277}278279/**280* nitrox_write_csr - Write to device register281* @ndev: NITROX device282* @offset: offset of the register to write283* @value: value to write284*/285static inline void nitrox_write_csr(struct nitrox_device *ndev, u64 offset,286u64 value)287{288writeq(value, (ndev->bar_addr + offset));289}290291static inline bool nitrox_ready(struct nitrox_device *ndev)292{293return atomic_read(&ndev->state) == __NDEV_READY;294}295296static inline bool nitrox_vfdev_ready(struct nitrox_vfdev *vfdev)297{298return atomic_read(&vfdev->state) == __NDEV_READY;299}300301#endif /* __NITROX_DEV_H */302303304