1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright 2016-17 IBM Corp.
6 #ifndef _ASM_POWERPC_VAS_H
7 #define _ASM_POWERPC_VAS_H
12 * Min and max FIFO sizes are based on Version 1.05 Section 3.1.4.25
13 * (Local FIFO Size Register) of the VAS workbook.
15 #define VAS_RX_FIFO_SIZE_MIN (1 << 10) /* 1KB */
16 #define VAS_RX_FIFO_SIZE_MAX (8 << 20) /* 8MB */
19 * Threshold Control Mode: Have paste operation fail if the number of
20 * requests in receive FIFO exceeds a threshold.
22 * NOTE: No special error code yet if paste is rejected because of these
23 * limits. So users can't distinguish between this and other errors.
25 #define VAS_THRESH_DISABLED 0
26 #define VAS_THRESH_FIFO_GT_HALF_FULL 1
27 #define VAS_THRESH_FIFO_GT_QTR_FULL 2
28 #define VAS_THRESH_FIFO_GT_EIGHTH_FULL 3
33 #define GET_FIELD(m, v) (((v) & (m)) >> MASK_LSH(m))
34 #define MASK_LSH(m) (__builtin_ffsl(m) - 1)
35 #define SET_FIELD(m, v, val) \
36 (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_LSH(m)) & (m)))
39 * Co-processor Engine type.
44 VAS_COP_TYPE_842_HIPRI
,
46 VAS_COP_TYPE_GZIP_HIPRI
,
52 * Receive window attributes specified by the (in-kernel) owner of window.
54 struct vas_rx_win_attr
{
82 * Window attributes specified by the in-kernel owner of a send window.
84 struct vas_tx_win_attr
{
85 enum vas_cop_type cop
;
88 int pidr
; /* hardware PID (from SPRN_PID) */
96 bool rsvd_txbuf_enable
;
100 bool rx_win_ord_mode
;
104 * Helper to map a chip id to VAS id.
105 * For POWER9, this is a 1:1 mapping. In the future this maybe a 1:N
106 * mapping in which case, we will need to update this helper.
108 * Return the VAS id or -1 if no matching vasid is found.
110 int chip_to_vas_id(int chipid
);
113 * Helper to initialize receive window attributes to defaults for an
116 void vas_init_rx_win_attr(struct vas_rx_win_attr
*rxattr
, enum vas_cop_type cop
);
119 * Open a VAS receive window for the instance of VAS identified by @vasid
120 * Use @attr to initialize the attributes of the window.
122 * Return a handle to the window or ERR_PTR() on error.
124 struct vas_window
*vas_rx_win_open(int vasid
, enum vas_cop_type cop
,
125 struct vas_rx_win_attr
*attr
);
128 * Helper to initialize send window attributes to defaults for an NX window.
130 extern void vas_init_tx_win_attr(struct vas_tx_win_attr
*txattr
,
131 enum vas_cop_type cop
);
134 * Open a VAS send window for the instance of VAS identified by @vasid
135 * and the co-processor type @cop. Use @attr to initialize attributes
138 * Note: The instance of VAS must already have an open receive window for
139 * the coprocessor type @cop.
141 * Return a handle to the send window or ERR_PTR() on error.
143 struct vas_window
*vas_tx_win_open(int vasid
, enum vas_cop_type cop
,
144 struct vas_tx_win_attr
*attr
);
147 * Close the send or receive window identified by @win. For receive windows
148 * return -EAGAIN if there are active send windows attached to this receive
151 int vas_win_close(struct vas_window
*win
);
154 * Copy the co-processor request block (CRB) @crb into the local L2 cache.
156 int vas_copy_crb(void *crb
, int offset
);
159 * Paste a previously copied CRB (see vas_copy_crb()) from the L2 cache to
160 * the hardware address associated with the window @win. @re is expected/
161 * assumed to be true for NX windows.
163 int vas_paste_crb(struct vas_window
*win
, int offset
, bool re
);
166 * Register / unregister coprocessor type to VAS API which will be exported
167 * to user space. Applications can use this API to open / close window
168 * which can be used to send / receive requests directly to cooprcessor.
170 * Only NX GZIP coprocessor type is supported now, but this API can be
171 * used for others in future.
173 int vas_register_coproc_api(struct module
*mod
, enum vas_cop_type cop_type
,
175 void vas_unregister_coproc_api(void);
177 #endif /* __ASM_POWERPC_VAS_H */