1 1.1 riastrad /* $NetBSD: qmgr.h,v 1.2 2021/12/18 23:45:38 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* SPDX-License-Identifier: MIT */ 4 1.1 riastrad #ifndef __NVKM_FALCON_QMGR_H__ 5 1.1 riastrad #define __NVKM_FALCON_QMGR_H__ 6 1.1 riastrad #include <core/falcon.h> 7 1.1 riastrad 8 1.1 riastrad #define HDR_SIZE sizeof(struct nv_falcon_msg) 9 1.1 riastrad #define QUEUE_ALIGNMENT 4 10 1.1 riastrad /* max size of the messages we can receive */ 11 1.1 riastrad #define MSG_BUF_SIZE 128 12 1.1 riastrad 13 1.1 riastrad /** 14 1.1 riastrad * struct nvkm_falcon_qmgr_seq - keep track of ongoing commands 15 1.1 riastrad * 16 1.1 riastrad * Every time a command is sent, a sequence is assigned to it so the 17 1.1 riastrad * corresponding message can be matched. Upon receiving the message, a callback 18 1.1 riastrad * can be called and/or a completion signaled. 19 1.1 riastrad * 20 1.1 riastrad * @id: sequence ID 21 1.1 riastrad * @state: current state 22 1.1 riastrad * @callback: callback to call upon receiving matching message 23 1.1 riastrad * @completion: completion to signal after callback is called 24 1.1 riastrad */ 25 1.1 riastrad struct nvkm_falcon_qmgr_seq { 26 1.1 riastrad u16 id; 27 1.1 riastrad enum { 28 1.1 riastrad SEQ_STATE_FREE = 0, 29 1.1 riastrad SEQ_STATE_PENDING, 30 1.1 riastrad SEQ_STATE_USED, 31 1.1 riastrad SEQ_STATE_CANCELLED 32 1.1 riastrad } state; 33 1.1 riastrad bool async; 34 1.1 riastrad nvkm_falcon_qmgr_callback callback; 35 1.1 riastrad void *priv; 36 1.1 riastrad struct completion done; 37 1.1 riastrad int result; 38 1.1 riastrad }; 39 1.1 riastrad 40 1.1 riastrad /* 41 1.1 riastrad * We can have an arbitrary number of sequences, but realistically we will 42 1.1 riastrad * probably not use that much simultaneously. 43 1.1 riastrad */ 44 1.1 riastrad #define NVKM_FALCON_QMGR_SEQ_NUM 16 45 1.1 riastrad 46 1.1 riastrad struct nvkm_falcon_qmgr { 47 1.1 riastrad struct nvkm_falcon *falcon; 48 1.1 riastrad 49 1.1 riastrad struct { 50 1.1 riastrad struct mutex mutex; 51 1.1 riastrad struct nvkm_falcon_qmgr_seq id[NVKM_FALCON_QMGR_SEQ_NUM]; 52 1.1 riastrad unsigned long tbl[BITS_TO_LONGS(NVKM_FALCON_QMGR_SEQ_NUM)]; 53 1.1 riastrad } seq; 54 1.1 riastrad }; 55 1.1 riastrad 56 1.1 riastrad struct nvkm_falcon_qmgr_seq * 57 1.1 riastrad nvkm_falcon_qmgr_seq_acquire(struct nvkm_falcon_qmgr *); 58 1.1 riastrad void nvkm_falcon_qmgr_seq_release(struct nvkm_falcon_qmgr *, 59 1.1 riastrad struct nvkm_falcon_qmgr_seq *); 60 1.1 riastrad 61 1.1 riastrad struct nvkm_falcon_cmdq { 62 1.1 riastrad struct nvkm_falcon_qmgr *qmgr; 63 1.1 riastrad const char *name; 64 1.1 riastrad struct mutex mutex; 65 1.1 riastrad struct completion ready; 66 1.1 riastrad 67 1.1 riastrad u32 head_reg; 68 1.1 riastrad u32 tail_reg; 69 1.1 riastrad u32 offset; 70 1.1 riastrad u32 size; 71 1.1 riastrad 72 1.1 riastrad u32 position; 73 1.1 riastrad }; 74 1.1 riastrad 75 1.1 riastrad struct nvkm_falcon_msgq { 76 1.1 riastrad struct nvkm_falcon_qmgr *qmgr; 77 1.1 riastrad const char *name; 78 1.1 riastrad struct mutex mutex; 79 1.1 riastrad 80 1.1 riastrad u32 head_reg; 81 1.1 riastrad u32 tail_reg; 82 1.1 riastrad u32 offset; 83 1.1 riastrad 84 1.1 riastrad u32 position; 85 1.1 riastrad }; 86 1.1 riastrad 87 1.1 riastrad #define FLCNQ_PRINTK(t,q,f,a...) \ 88 1.1 riastrad FLCN_PRINTK(t, (q)->qmgr->falcon, "%s: "f, (q)->name, ##a) 89 1.1 riastrad #define FLCNQ_DBG(q,f,a...) FLCNQ_PRINTK(debug, (q), f, ##a) 90 1.1 riastrad #define FLCNQ_ERR(q,f,a...) FLCNQ_PRINTK(error, (q), f, ##a) 91 1.1 riastrad #endif 92