1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5 
6 #ifndef _XE_GUC_CT_TYPES_H_
7 #define _XE_GUC_CT_TYPES_H_
8 
9 #include <linux/interrupt.h>
10 #include <linux/iosys-map.h>
11 #include <linux/spinlock_types.h>
12 #include <linux/wait.h>
13 #include <linux/xarray.h>
14 
15 #include "abi/guc_communication_ctb_abi.h"
16 
17 struct xe_bo;
18 
19 /**
20  * struct guc_ctb_info - GuC command transport buffer (CTB) info
21  */
22 struct guc_ctb_info {
23 	/** @size: size of CTB commands (DW) */
24 	u32 size;
25 	/** @resv_space: reserved space of CTB commands (DW) */
26 	u32 resv_space;
27 	/** @head: head of CTB commands (DW) */
28 	u32 head;
29 	/** @tail: tail of CTB commands (DW) */
30 	u32 tail;
31 	/** @space: space in CTB commands (DW) */
32 	u32 space;
33 	/** @broken: channel broken */
34 	bool broken;
35 };
36 
37 /**
38  * struct guc_ctb - GuC command transport buffer (CTB)
39  */
40 struct guc_ctb {
41 	/** @desc: dma buffer map for CTB descriptor */
42 	struct iosys_map desc;
43 	/** @cmds: dma buffer map for CTB commands */
44 	struct iosys_map cmds;
45 	/** @info: CTB info */
46 	struct guc_ctb_info info;
47 };
48 
49 /**
50  * struct guc_ctb_snapshot - GuC command transport buffer (CTB) snapshot
51  */
52 struct guc_ctb_snapshot {
53 	/** @desc: snapshot of the CTB descriptor */
54 	struct guc_ct_buffer_desc desc;
55 	/** @cmds: snapshot of the CTB commands */
56 	u32 *cmds;
57 	/** @info: snapshot of the CTB info */
58 	struct guc_ctb_info info;
59 };
60 
61 /**
62  * struct xe_guc_ct_snapshot - GuC command transport (CT) snapshot
63  */
64 struct xe_guc_ct_snapshot {
65 	/** @ct_enabled: CT enabled info at capture time. */
66 	bool ct_enabled;
67 	/** @g2h_outstanding: G2H outstanding info at the capture time */
68 	u32 g2h_outstanding;
69 	/** @g2h: G2H CTB snapshot */
70 	struct guc_ctb_snapshot g2h;
71 	/** @h2g: H2G CTB snapshot */
72 	struct guc_ctb_snapshot h2g;
73 };
74 
75 /**
76  * enum xe_guc_ct_state - CT state
77  * @XE_GUC_CT_STATE_NOT_INITIALIZED: CT not initialized, messages not expected in this state
78  * @XE_GUC_CT_STATE_DISABLED: CT disabled, messages not expected in this state
79  * @XE_GUC_CT_STATE_STOPPED: CT stopped, drop messages without errors
80  * @XE_GUC_CT_STATE_ENABLED: CT enabled, messages sent / received in this state
81  */
82 enum xe_guc_ct_state {
83 	XE_GUC_CT_STATE_NOT_INITIALIZED = 0,
84 	XE_GUC_CT_STATE_DISABLED,
85 	XE_GUC_CT_STATE_STOPPED,
86 	XE_GUC_CT_STATE_ENABLED,
87 };
88 
89 /**
90  * struct xe_guc_ct - GuC command transport (CT) layer
91  *
92  * Includes a pair of CT buffers for bi-directional communication and tracking
93  * for the H2G and G2H requests sent and received through the buffers.
94  */
95 struct xe_guc_ct {
96 	/** @bo: XE BO for CT */
97 	struct xe_bo *bo;
98 	/** @lock: protects everything in CT layer */
99 	struct mutex lock;
100 	/** @fast_lock: protects G2H channel and credits */
101 	spinlock_t fast_lock;
102 	/** @ctbs: buffers for sending and receiving commands */
103 	struct {
104 		/** @ctbs.send: Host to GuC (H2G, send) channel */
105 		struct guc_ctb h2g;
106 		/** @ctbs.recv: GuC to Host (G2H, receive) channel */
107 		struct guc_ctb g2h;
108 	} ctbs;
109 	/** @g2h_outstanding: number of outstanding G2H */
110 	u32 g2h_outstanding;
111 	/** @g2h_worker: worker to process G2H messages */
112 	struct work_struct g2h_worker;
113 	/** @safe_mode_worker: worker to check G2H messages with IRQ disabled */
114 	struct delayed_work safe_mode_worker;
115 	/** @state: CT state */
116 	enum xe_guc_ct_state state;
117 	/** @fence_seqno: G2H fence seqno - 16 bits used by CT */
118 	u32 fence_seqno;
119 	/** @fence_lookup: G2H fence lookup */
120 	struct xarray fence_lookup;
121 	/** @wq: wait queue used for reliable CT sends and freeing G2H credits */
122 	wait_queue_head_t wq;
123 	/** @g2h_fence_wq: wait queue used for G2H fencing */
124 	wait_queue_head_t g2h_fence_wq;
125 	/** @g2h_wq: used to process G2H */
126 	struct workqueue_struct *g2h_wq;
127 	/** @msg: Message buffer */
128 	u32 msg[GUC_CTB_MSG_MAX_LEN];
129 	/** @fast_msg: Message buffer */
130 	u32 fast_msg[GUC_CTB_MSG_MAX_LEN];
131 };
132 
133 #endif
134