Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright 2018-2020 Broadcom.
0004  */
0005 
0006 #ifndef BCM_VK_MSG_H
0007 #define BCM_VK_MSG_H
0008 
0009 #include <uapi/linux/misc/bcm_vk.h>
0010 #include "bcm_vk_sg.h"
0011 
0012 /* Single message queue control structure */
0013 struct bcm_vk_msgq {
0014     u16 type;   /* queue type */
0015     u16 num;    /* queue number */
0016     u32 start;  /* offset in BAR1 where the queue memory starts */
0017 
0018     u32 rd_idx; /* read idx */
0019     u32 wr_idx; /* write idx */
0020 
0021     u32 size;   /*
0022              * size, which is in number of 16byte blocks,
0023              * to align with the message data structure.
0024              */
0025     u32 nxt;    /*
0026              * nxt offset to the next msg queue struct.
0027              * This is to provide flexibity for alignment purposes.
0028              */
0029 
0030 /* Least significant 16 bits in below field hold doorbell register offset */
0031 #define DB_SHIFT 16
0032 
0033     u32 db_offset; /* queue doorbell register offset in BAR0 */
0034 
0035     u32 rsvd;
0036 };
0037 
0038 /*
0039  * Structure to record static info from the msgq sync.  We keep local copy
0040  * for some of these variables for both performance + checking purpose.
0041  */
0042 struct bcm_vk_sync_qinfo {
0043     void __iomem *q_start;
0044     u32 q_size;
0045     u32 q_mask;
0046     u32 q_low;
0047     u32 q_db_offset;
0048 };
0049 
0050 #define VK_MSGQ_MAX_NR 4 /* Maximum number of message queues */
0051 
0052 /*
0053  * message block - basic unit in the message where a message's size is always
0054  *         N x sizeof(basic_block)
0055  */
0056 struct vk_msg_blk {
0057     u8 function_id;
0058 #define VK_FID_TRANS_BUF    5
0059 #define VK_FID_SHUTDOWN     8
0060 #define VK_FID_INIT     9
0061     u8 size; /* size of the message in number of vk_msg_blk's */
0062     u16 trans_id; /* transport id, queue & msg_id */
0063     u32 context_id;
0064 #define VK_NEW_CTX      0
0065     u32 cmd;
0066 #define VK_CMD_PLANES_MASK  0x000f /* number of planes to up/download */
0067 #define VK_CMD_UPLOAD       0x0400 /* memory transfer to vk */
0068 #define VK_CMD_DOWNLOAD     0x0500 /* memory transfer from vk */
0069 #define VK_CMD_MASK     0x0f00 /* command mask */
0070     u32 arg;
0071 };
0072 
0073 /* vk_msg_blk is 16 bytes fixed */
0074 #define VK_MSGQ_BLK_SIZE   (sizeof(struct vk_msg_blk))
0075 /* shift for fast division of basic msg blk size */
0076 #define VK_MSGQ_BLK_SZ_SHIFT 4
0077 
0078 /* use msg_id 0 for any simplex host2vk communication */
0079 #define VK_SIMPLEX_MSG_ID 0
0080 
0081 /* context per session opening of sysfs */
0082 struct bcm_vk_ctx {
0083     struct list_head node; /* use for linkage in Hash Table */
0084     unsigned int idx;
0085     bool in_use;
0086     pid_t pid;
0087     u32 hash_idx;
0088     u32 q_num; /* queue number used by the stream */
0089     struct miscdevice *miscdev;
0090     atomic_t pend_cnt; /* number of items pending to be read from host */
0091     atomic_t dma_cnt; /* any dma transaction outstanding */
0092     wait_queue_head_t rd_wq;
0093 };
0094 
0095 /* pid hash table entry */
0096 struct bcm_vk_ht_entry {
0097     struct list_head head;
0098 };
0099 
0100 #define VK_DMA_MAX_ADDRS 4 /* Max 4 DMA Addresses */
0101 /* structure for house keeping a single work entry */
0102 struct bcm_vk_wkent {
0103     struct list_head node; /* for linking purpose */
0104     struct bcm_vk_ctx *ctx;
0105 
0106     /* Store up to 4 dma pointers */
0107     struct bcm_vk_dma dma[VK_DMA_MAX_ADDRS];
0108 
0109     u32 to_h_blks; /* response */
0110     struct vk_msg_blk *to_h_msg;
0111 
0112     /*
0113      * put the to_v_msg at the end so that we could simply append to_v msg
0114      * to the end of the allocated block
0115      */
0116     u32 usr_msg_id;
0117     u32 to_v_blks;
0118     u32 seq_num;
0119     struct vk_msg_blk to_v_msg[];
0120 };
0121 
0122 /* queue stats counters */
0123 struct bcm_vk_qs_cnts {
0124     u32 cnt; /* general counter, used to limit output */
0125     u32 acc_sum;
0126     u32 max_occ; /* max during a sampling period */
0127     u32 max_abs; /* the abs max since reset */
0128 };
0129 
0130 /* control channel structure for either to_v or to_h communication */
0131 struct bcm_vk_msg_chan {
0132     u32 q_nr;
0133     /* Mutex to access msgq */
0134     struct mutex msgq_mutex;
0135     /* pointing to BAR locations */
0136     struct bcm_vk_msgq __iomem *msgq[VK_MSGQ_MAX_NR];
0137     /* Spinlock to access pending queue */
0138     spinlock_t pendq_lock;
0139     /* for temporary storing pending items, one for each queue */
0140     struct list_head pendq[VK_MSGQ_MAX_NR];
0141     /* static queue info from the sync */
0142     struct bcm_vk_sync_qinfo sync_qinfo[VK_MSGQ_MAX_NR];
0143 };
0144 
0145 /* totol number of message q allowed by the driver */
0146 #define VK_MSGQ_PER_CHAN_MAX    3
0147 #define VK_MSGQ_NUM_DEFAULT (VK_MSGQ_PER_CHAN_MAX - 1)
0148 
0149 /* total number of supported ctx, 32 ctx each for 5 components */
0150 #define VK_CMPT_CTX_MAX     (32 * 5)
0151 
0152 /* hash table defines to store the opened FDs */
0153 #define VK_PID_HT_SHIFT_BIT 7 /* 128 */
0154 #define VK_PID_HT_SZ        BIT(VK_PID_HT_SHIFT_BIT)
0155 
0156 /* The following are offsets of DDR info provided by the vk card */
0157 #define VK_BAR0_SEG_SIZE    (4 * SZ_1K) /* segment size for BAR0 */
0158 
0159 /* shutdown types supported */
0160 #define VK_SHUTDOWN_PID     1
0161 #define VK_SHUTDOWN_GRACEFUL    2
0162 
0163 #endif