1*25763b3cSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2c694b233SGeorge Cherian /* 3c694b233SGeorge Cherian * Copyright (C) 2016 Cavium, Inc. 4c694b233SGeorge Cherian */ 5c694b233SGeorge Cherian 6c694b233SGeorge Cherian #ifndef __CPTVF_H 7c694b233SGeorge Cherian #define __CPTVF_H 8c694b233SGeorge Cherian 9c694b233SGeorge Cherian #include <linux/list.h> 10c694b233SGeorge Cherian #include "cpt_common.h" 11c694b233SGeorge Cherian 12c694b233SGeorge Cherian /* Default command queue length */ 13c694b233SGeorge Cherian #define CPT_CMD_QLEN 2046 14c694b233SGeorge Cherian #define CPT_CMD_QCHUNK_SIZE 1023 15c694b233SGeorge Cherian 16c694b233SGeorge Cherian /* Default command timeout in seconds */ 17c694b233SGeorge Cherian #define CPT_COMMAND_TIMEOUT 4 18c694b233SGeorge Cherian #define CPT_TIMER_THOLD 0xFFFF 19c694b233SGeorge Cherian #define CPT_NUM_QS_PER_VF 1 20c694b233SGeorge Cherian #define CPT_INST_SIZE 64 21c694b233SGeorge Cherian #define CPT_NEXT_CHUNK_PTR_SIZE 8 22c694b233SGeorge Cherian 23c694b233SGeorge Cherian #define CPT_VF_MSIX_VECTORS 2 24c694b233SGeorge Cherian #define CPT_VF_INTR_MBOX_MASK BIT(0) 25c694b233SGeorge Cherian #define CPT_VF_INTR_DOVF_MASK BIT(1) 26c694b233SGeorge Cherian #define CPT_VF_INTR_IRDE_MASK BIT(2) 27c694b233SGeorge Cherian #define CPT_VF_INTR_NWRP_MASK BIT(3) 28c694b233SGeorge Cherian #define CPT_VF_INTR_SERR_MASK BIT(4) 29c694b233SGeorge Cherian #define DMA_DIRECT_DIRECT 0 /* Input DIRECT, Output DIRECT */ 30c694b233SGeorge Cherian #define DMA_GATHER_SCATTER 1 31c694b233SGeorge Cherian #define FROM_DPTR 1 32c694b233SGeorge Cherian 33c694b233SGeorge Cherian /** 34c694b233SGeorge Cherian * Enumeration cpt_vf_int_vec_e 35c694b233SGeorge Cherian * 36c694b233SGeorge Cherian * CPT VF MSI-X Vector Enumeration 37c694b233SGeorge Cherian * Enumerates the MSI-X interrupt vectors. 38c694b233SGeorge Cherian */ 39c694b233SGeorge Cherian enum cpt_vf_int_vec_e { 40c694b233SGeorge Cherian CPT_VF_INT_VEC_E_MISC = 0x00, 41c694b233SGeorge Cherian CPT_VF_INT_VEC_E_DONE = 0x01 42c694b233SGeorge Cherian }; 43c694b233SGeorge Cherian 44c694b233SGeorge Cherian struct command_chunk { 45c694b233SGeorge Cherian u8 *head; 46c694b233SGeorge Cherian dma_addr_t dma_addr; 47c694b233SGeorge Cherian u32 size; /* Chunk size, max CPT_INST_CHUNK_MAX_SIZE */ 48c694b233SGeorge Cherian struct hlist_node nextchunk; 49c694b233SGeorge Cherian }; 50c694b233SGeorge Cherian 51c694b233SGeorge Cherian struct command_queue { 52c694b233SGeorge Cherian spinlock_t lock; /* command queue lock */ 53c694b233SGeorge Cherian u32 idx; /* Command queue host write idx */ 54c694b233SGeorge Cherian u32 nchunks; /* Number of command chunks */ 55c694b233SGeorge Cherian struct command_chunk *qhead; /* Command queue head, instructions 56c694b233SGeorge Cherian * are inserted here 57c694b233SGeorge Cherian */ 58c694b233SGeorge Cherian struct hlist_head chead; 59c694b233SGeorge Cherian }; 60c694b233SGeorge Cherian 61c694b233SGeorge Cherian struct command_qinfo { 62c694b233SGeorge Cherian u32 cmd_size; 63c694b233SGeorge Cherian u32 qchunksize; /* Command queue chunk size */ 64c694b233SGeorge Cherian struct command_queue queue[CPT_NUM_QS_PER_VF]; 65c694b233SGeorge Cherian }; 66c694b233SGeorge Cherian 67c694b233SGeorge Cherian struct pending_entry { 68c694b233SGeorge Cherian u8 busy; /* Entry status (free/busy) */ 69c694b233SGeorge Cherian 70c694b233SGeorge Cherian volatile u64 *completion_addr; /* Completion address */ 71c694b233SGeorge Cherian void *post_arg; 72c694b233SGeorge Cherian void (*callback)(int, void *); /* Kernel ASYNC request callabck */ 73c694b233SGeorge Cherian void *callback_arg; /* Kernel ASYNC request callabck arg */ 74c694b233SGeorge Cherian }; 75c694b233SGeorge Cherian 76c694b233SGeorge Cherian struct pending_queue { 77c694b233SGeorge Cherian struct pending_entry *head; /* head of the queue */ 78c694b233SGeorge Cherian u32 front; /* Process work from here */ 79c694b233SGeorge Cherian u32 rear; /* Append new work here */ 80c694b233SGeorge Cherian atomic64_t pending_count; 81c694b233SGeorge Cherian spinlock_t lock; /* Queue lock */ 82c694b233SGeorge Cherian }; 83c694b233SGeorge Cherian 84c694b233SGeorge Cherian struct pending_qinfo { 85c694b233SGeorge Cherian u32 nr_queues; /* Number of queues supported */ 86c694b233SGeorge Cherian u32 qlen; /* Queue length */ 87c694b233SGeorge Cherian struct pending_queue queue[CPT_NUM_QS_PER_VF]; 88c694b233SGeorge Cherian }; 89c694b233SGeorge Cherian 90c694b233SGeorge Cherian #define for_each_pending_queue(qinfo, q, i) \ 91c694b233SGeorge Cherian for (i = 0, q = &qinfo->queue[i]; i < qinfo->nr_queues; i++, \ 92c694b233SGeorge Cherian q = &qinfo->queue[i]) 93c694b233SGeorge Cherian 94c694b233SGeorge Cherian struct cpt_vf { 95c694b233SGeorge Cherian u16 flags; /* Flags to hold device status bits */ 96c694b233SGeorge Cherian u8 vfid; /* Device Index 0...CPT_MAX_VF_NUM */ 97c694b233SGeorge Cherian u8 vftype; /* VF type of SE_TYPE(1) or AE_TYPE(1) */ 98c694b233SGeorge Cherian u8 vfgrp; /* VF group (0 - 8) */ 99c694b233SGeorge Cherian u8 node; /* Operating node: Bits (46:44) in BAR0 address */ 100c694b233SGeorge Cherian u8 priority; /* VF priority ring: 1-High proirity round 101c694b233SGeorge Cherian * robin ring;0-Low priority round robin ring; 102c694b233SGeorge Cherian */ 103c694b233SGeorge Cherian struct pci_dev *pdev; /* pci device handle */ 104c694b233SGeorge Cherian void __iomem *reg_base; /* Register start address */ 105c694b233SGeorge Cherian void *wqe_info; /* BH worker info */ 106c694b233SGeorge Cherian /* MSI-X */ 107c694b233SGeorge Cherian cpumask_var_t affinity_mask[CPT_VF_MSIX_VECTORS]; 108c694b233SGeorge Cherian /* Command and Pending queues */ 109c694b233SGeorge Cherian u32 qsize; 110c694b233SGeorge Cherian u32 nr_queues; 111c694b233SGeorge Cherian struct command_qinfo cqinfo; /* Command queue information */ 112c694b233SGeorge Cherian struct pending_qinfo pqinfo; /* Pending queue information */ 113c694b233SGeorge Cherian /* VF-PF mailbox communication */ 114c694b233SGeorge Cherian bool pf_acked; 115c694b233SGeorge Cherian bool pf_nacked; 116c694b233SGeorge Cherian }; 117c694b233SGeorge Cherian 118c694b233SGeorge Cherian int cptvf_send_vf_up(struct cpt_vf *cptvf); 119c694b233SGeorge Cherian int cptvf_send_vf_down(struct cpt_vf *cptvf); 120c694b233SGeorge Cherian int cptvf_send_vf_to_grp_msg(struct cpt_vf *cptvf); 121c694b233SGeorge Cherian int cptvf_send_vf_priority_msg(struct cpt_vf *cptvf); 122c694b233SGeorge Cherian int cptvf_send_vq_size_msg(struct cpt_vf *cptvf); 123c694b233SGeorge Cherian int cptvf_check_pf_ready(struct cpt_vf *cptvf); 124c694b233SGeorge Cherian void cptvf_handle_mbox_intr(struct cpt_vf *cptvf); 125c694b233SGeorge Cherian void cvm_crypto_exit(void); 126c694b233SGeorge Cherian int cvm_crypto_init(struct cpt_vf *cptvf); 127c694b233SGeorge Cherian void vq_post_process(struct cpt_vf *cptvf, u32 qno); 128c694b233SGeorge Cherian void cptvf_write_vq_doorbell(struct cpt_vf *cptvf, u32 val); 129c694b233SGeorge Cherian #endif /* __CPTVF_H */ 130