xref: /openbmc/linux/arch/powerpc/include/asm/vas.h (revision e3d786a3)
1 /*
2  * Copyright 2016-17 IBM Corp.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version
7  * 2 of the License, or (at your option) any later version.
8  */
9 
10 #ifndef _ASM_POWERPC_VAS_H
11 #define _ASM_POWERPC_VAS_H
12 
13 struct vas_window;
14 
15 /*
16  * Min and max FIFO sizes are based on Version 1.05 Section 3.1.4.25
17  * (Local FIFO Size Register) of the VAS workbook.
18  */
19 #define VAS_RX_FIFO_SIZE_MIN	(1 << 10)	/* 1KB */
20 #define VAS_RX_FIFO_SIZE_MAX	(8 << 20)	/* 8MB */
21 
22 /*
23  * Threshold Control Mode: Have paste operation fail if the number of
24  * requests in receive FIFO exceeds a threshold.
25  *
26  * NOTE: No special error code yet if paste is rejected because of these
27  *	 limits. So users can't distinguish between this and other errors.
28  */
29 #define VAS_THRESH_DISABLED		0
30 #define VAS_THRESH_FIFO_GT_HALF_FULL	1
31 #define VAS_THRESH_FIFO_GT_QTR_FULL	2
32 #define VAS_THRESH_FIFO_GT_EIGHTH_FULL	3
33 
34 /*
35  * Get/Set bit fields
36  */
37 #define GET_FIELD(m, v)                (((v) & (m)) >> MASK_LSH(m))
38 #define MASK_LSH(m)            (__builtin_ffsl(m) - 1)
39 #define SET_FIELD(m, v, val)   \
40 		(((v) & ~(m)) | ((((typeof(v))(val)) << MASK_LSH(m)) & (m)))
41 
42 /*
43  * Co-processor Engine type.
44  */
45 enum vas_cop_type {
46 	VAS_COP_TYPE_FAULT,
47 	VAS_COP_TYPE_842,
48 	VAS_COP_TYPE_842_HIPRI,
49 	VAS_COP_TYPE_GZIP,
50 	VAS_COP_TYPE_GZIP_HIPRI,
51 	VAS_COP_TYPE_FTW,
52 	VAS_COP_TYPE_MAX,
53 };
54 
55 /*
56  * Receive window attributes specified by the (in-kernel) owner of window.
57  */
58 struct vas_rx_win_attr {
59 	void *rx_fifo;
60 	int rx_fifo_size;
61 	int wcreds_max;
62 
63 	bool pin_win;
64 	bool rej_no_credit;
65 	bool tx_wcred_mode;
66 	bool rx_wcred_mode;
67 	bool tx_win_ord_mode;
68 	bool rx_win_ord_mode;
69 	bool data_stamp;
70 	bool nx_win;
71 	bool fault_win;
72 	bool user_win;
73 	bool notify_disable;
74 	bool intr_disable;
75 	bool notify_early;
76 
77 	int lnotify_lpid;
78 	int lnotify_pid;
79 	int lnotify_tid;
80 	u32 pswid;
81 
82 	int tc_mode;
83 };
84 
85 /*
86  * Window attributes specified by the in-kernel owner of a send window.
87  */
88 struct vas_tx_win_attr {
89 	enum vas_cop_type cop;
90 	int wcreds_max;
91 	int lpid;
92 	int pidr;		/* hardware PID (from SPRN_PID) */
93 	int pid;		/* linux process id */
94 	int pswid;
95 	int rsvd_txbuf_count;
96 	int tc_mode;
97 
98 	bool user_win;
99 	bool pin_win;
100 	bool rej_no_credit;
101 	bool rsvd_txbuf_enable;
102 	bool tx_wcred_mode;
103 	bool rx_wcred_mode;
104 	bool tx_win_ord_mode;
105 	bool rx_win_ord_mode;
106 };
107 
108 /*
109  * Helper to map a chip id to VAS id.
110  * For POWER9, this is a 1:1 mapping. In the future this maybe a 1:N
111  * mapping in which case, we will need to update this helper.
112  *
113  * Return the VAS id or -1 if no matching vasid is found.
114  */
115 int chip_to_vas_id(int chipid);
116 
117 /*
118  * Helper to initialize receive window attributes to defaults for an
119  * NX window.
120  */
121 void vas_init_rx_win_attr(struct vas_rx_win_attr *rxattr, enum vas_cop_type cop);
122 
123 /*
124  * Open a VAS receive window for the instance of VAS identified by @vasid
125  * Use @attr to initialize the attributes of the window.
126  *
127  * Return a handle to the window or ERR_PTR() on error.
128  */
129 struct vas_window *vas_rx_win_open(int vasid, enum vas_cop_type cop,
130 				   struct vas_rx_win_attr *attr);
131 
132 /*
133  * Helper to initialize send window attributes to defaults for an NX window.
134  */
135 extern void vas_init_tx_win_attr(struct vas_tx_win_attr *txattr,
136 			enum vas_cop_type cop);
137 
138 /*
139  * Open a VAS send window for the instance of VAS identified by @vasid
140  * and the co-processor type @cop. Use @attr to initialize attributes
141  * of the window.
142  *
143  * Note: The instance of VAS must already have an open receive window for
144  * the coprocessor type @cop.
145  *
146  * Return a handle to the send window or ERR_PTR() on error.
147  */
148 struct vas_window *vas_tx_win_open(int vasid, enum vas_cop_type cop,
149 			struct vas_tx_win_attr *attr);
150 
151 /*
152  * Close the send or receive window identified by @win. For receive windows
153  * return -EAGAIN if there are active send windows attached to this receive
154  * window.
155  */
156 int vas_win_close(struct vas_window *win);
157 
158 /*
159  * Copy the co-processor request block (CRB) @crb into the local L2 cache.
160  */
161 int vas_copy_crb(void *crb, int offset);
162 
163 /*
164  * Paste a previously copied CRB (see vas_copy_crb()) from the L2 cache to
165  * the hardware address associated with the window @win. @re is expected/
166  * assumed to be true for NX windows.
167  */
168 int vas_paste_crb(struct vas_window *win, int offset, bool re);
169 
170 /*
171  * Return a system-wide unique id for the VAS window @win.
172  */
173 extern u32 vas_win_id(struct vas_window *win);
174 
175 /*
176  * Return the power bus paste address associated with @win so the caller
177  * can map that address into their address space.
178  */
179 extern u64 vas_win_paste_addr(struct vas_window *win);
180 #endif /* __ASM_POWERPC_VAS_H */
181