18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 2016-17 IBM Corp.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_VAS_H
78c2ecf20Sopenharmony_ci#define _ASM_POWERPC_VAS_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_cistruct vas_window;
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/*
128c2ecf20Sopenharmony_ci * Min and max FIFO sizes are based on Version 1.05 Section 3.1.4.25
138c2ecf20Sopenharmony_ci * (Local FIFO Size Register) of the VAS workbook.
148c2ecf20Sopenharmony_ci */
158c2ecf20Sopenharmony_ci#define VAS_RX_FIFO_SIZE_MIN	(1 << 10)	/* 1KB */
168c2ecf20Sopenharmony_ci#define VAS_RX_FIFO_SIZE_MAX	(8 << 20)	/* 8MB */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/*
198c2ecf20Sopenharmony_ci * Threshold Control Mode: Have paste operation fail if the number of
208c2ecf20Sopenharmony_ci * requests in receive FIFO exceeds a threshold.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * NOTE: No special error code yet if paste is rejected because of these
238c2ecf20Sopenharmony_ci *	 limits. So users can't distinguish between this and other errors.
248c2ecf20Sopenharmony_ci */
258c2ecf20Sopenharmony_ci#define VAS_THRESH_DISABLED		0
268c2ecf20Sopenharmony_ci#define VAS_THRESH_FIFO_GT_HALF_FULL	1
278c2ecf20Sopenharmony_ci#define VAS_THRESH_FIFO_GT_QTR_FULL	2
288c2ecf20Sopenharmony_ci#define VAS_THRESH_FIFO_GT_EIGHTH_FULL	3
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/*
318c2ecf20Sopenharmony_ci * Get/Set bit fields
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci#define GET_FIELD(m, v)                (((v) & (m)) >> MASK_LSH(m))
348c2ecf20Sopenharmony_ci#define MASK_LSH(m)            (__builtin_ffsl(m) - 1)
358c2ecf20Sopenharmony_ci#define SET_FIELD(m, v, val)   \
368c2ecf20Sopenharmony_ci		(((v) & ~(m)) | ((((typeof(v))(val)) << MASK_LSH(m)) & (m)))
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/*
398c2ecf20Sopenharmony_ci * Co-processor Engine type.
408c2ecf20Sopenharmony_ci */
418c2ecf20Sopenharmony_cienum vas_cop_type {
428c2ecf20Sopenharmony_ci	VAS_COP_TYPE_FAULT,
438c2ecf20Sopenharmony_ci	VAS_COP_TYPE_842,
448c2ecf20Sopenharmony_ci	VAS_COP_TYPE_842_HIPRI,
458c2ecf20Sopenharmony_ci	VAS_COP_TYPE_GZIP,
468c2ecf20Sopenharmony_ci	VAS_COP_TYPE_GZIP_HIPRI,
478c2ecf20Sopenharmony_ci	VAS_COP_TYPE_FTW,
488c2ecf20Sopenharmony_ci	VAS_COP_TYPE_MAX,
498c2ecf20Sopenharmony_ci};
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/*
528c2ecf20Sopenharmony_ci * Receive window attributes specified by the (in-kernel) owner of window.
538c2ecf20Sopenharmony_ci */
548c2ecf20Sopenharmony_cistruct vas_rx_win_attr {
558c2ecf20Sopenharmony_ci	u64 rx_fifo;
568c2ecf20Sopenharmony_ci	int rx_fifo_size;
578c2ecf20Sopenharmony_ci	int wcreds_max;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	bool pin_win;
608c2ecf20Sopenharmony_ci	bool rej_no_credit;
618c2ecf20Sopenharmony_ci	bool tx_wcred_mode;
628c2ecf20Sopenharmony_ci	bool rx_wcred_mode;
638c2ecf20Sopenharmony_ci	bool tx_win_ord_mode;
648c2ecf20Sopenharmony_ci	bool rx_win_ord_mode;
658c2ecf20Sopenharmony_ci	bool data_stamp;
668c2ecf20Sopenharmony_ci	bool nx_win;
678c2ecf20Sopenharmony_ci	bool fault_win;
688c2ecf20Sopenharmony_ci	bool user_win;
698c2ecf20Sopenharmony_ci	bool notify_disable;
708c2ecf20Sopenharmony_ci	bool intr_disable;
718c2ecf20Sopenharmony_ci	bool notify_early;
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	int lnotify_lpid;
748c2ecf20Sopenharmony_ci	int lnotify_pid;
758c2ecf20Sopenharmony_ci	int lnotify_tid;
768c2ecf20Sopenharmony_ci	u32 pswid;
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	int tc_mode;
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/*
828c2ecf20Sopenharmony_ci * Window attributes specified by the in-kernel owner of a send window.
838c2ecf20Sopenharmony_ci */
848c2ecf20Sopenharmony_cistruct vas_tx_win_attr {
858c2ecf20Sopenharmony_ci	enum vas_cop_type cop;
868c2ecf20Sopenharmony_ci	int wcreds_max;
878c2ecf20Sopenharmony_ci	int lpid;
888c2ecf20Sopenharmony_ci	int pidr;		/* hardware PID (from SPRN_PID) */
898c2ecf20Sopenharmony_ci	int pswid;
908c2ecf20Sopenharmony_ci	int rsvd_txbuf_count;
918c2ecf20Sopenharmony_ci	int tc_mode;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	bool user_win;
948c2ecf20Sopenharmony_ci	bool pin_win;
958c2ecf20Sopenharmony_ci	bool rej_no_credit;
968c2ecf20Sopenharmony_ci	bool rsvd_txbuf_enable;
978c2ecf20Sopenharmony_ci	bool tx_wcred_mode;
988c2ecf20Sopenharmony_ci	bool rx_wcred_mode;
998c2ecf20Sopenharmony_ci	bool tx_win_ord_mode;
1008c2ecf20Sopenharmony_ci	bool rx_win_ord_mode;
1018c2ecf20Sopenharmony_ci};
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/*
1048c2ecf20Sopenharmony_ci * Helper to map a chip id to VAS id.
1058c2ecf20Sopenharmony_ci * For POWER9, this is a 1:1 mapping. In the future this maybe a 1:N
1068c2ecf20Sopenharmony_ci * mapping in which case, we will need to update this helper.
1078c2ecf20Sopenharmony_ci *
1088c2ecf20Sopenharmony_ci * Return the VAS id or -1 if no matching vasid is found.
1098c2ecf20Sopenharmony_ci */
1108c2ecf20Sopenharmony_ciint chip_to_vas_id(int chipid);
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/*
1138c2ecf20Sopenharmony_ci * Helper to initialize receive window attributes to defaults for an
1148c2ecf20Sopenharmony_ci * NX window.
1158c2ecf20Sopenharmony_ci */
1168c2ecf20Sopenharmony_civoid vas_init_rx_win_attr(struct vas_rx_win_attr *rxattr, enum vas_cop_type cop);
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci/*
1198c2ecf20Sopenharmony_ci * Open a VAS receive window for the instance of VAS identified by @vasid
1208c2ecf20Sopenharmony_ci * Use @attr to initialize the attributes of the window.
1218c2ecf20Sopenharmony_ci *
1228c2ecf20Sopenharmony_ci * Return a handle to the window or ERR_PTR() on error.
1238c2ecf20Sopenharmony_ci */
1248c2ecf20Sopenharmony_cistruct vas_window *vas_rx_win_open(int vasid, enum vas_cop_type cop,
1258c2ecf20Sopenharmony_ci				   struct vas_rx_win_attr *attr);
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/*
1288c2ecf20Sopenharmony_ci * Helper to initialize send window attributes to defaults for an NX window.
1298c2ecf20Sopenharmony_ci */
1308c2ecf20Sopenharmony_ciextern void vas_init_tx_win_attr(struct vas_tx_win_attr *txattr,
1318c2ecf20Sopenharmony_ci			enum vas_cop_type cop);
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci/*
1348c2ecf20Sopenharmony_ci * Open a VAS send window for the instance of VAS identified by @vasid
1358c2ecf20Sopenharmony_ci * and the co-processor type @cop. Use @attr to initialize attributes
1368c2ecf20Sopenharmony_ci * of the window.
1378c2ecf20Sopenharmony_ci *
1388c2ecf20Sopenharmony_ci * Note: The instance of VAS must already have an open receive window for
1398c2ecf20Sopenharmony_ci * the coprocessor type @cop.
1408c2ecf20Sopenharmony_ci *
1418c2ecf20Sopenharmony_ci * Return a handle to the send window or ERR_PTR() on error.
1428c2ecf20Sopenharmony_ci */
1438c2ecf20Sopenharmony_cistruct vas_window *vas_tx_win_open(int vasid, enum vas_cop_type cop,
1448c2ecf20Sopenharmony_ci			struct vas_tx_win_attr *attr);
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci/*
1478c2ecf20Sopenharmony_ci * Close the send or receive window identified by @win. For receive windows
1488c2ecf20Sopenharmony_ci * return -EAGAIN if there are active send windows attached to this receive
1498c2ecf20Sopenharmony_ci * window.
1508c2ecf20Sopenharmony_ci */
1518c2ecf20Sopenharmony_ciint vas_win_close(struct vas_window *win);
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci/*
1548c2ecf20Sopenharmony_ci * Copy the co-processor request block (CRB) @crb into the local L2 cache.
1558c2ecf20Sopenharmony_ci */
1568c2ecf20Sopenharmony_ciint vas_copy_crb(void *crb, int offset);
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci/*
1598c2ecf20Sopenharmony_ci * Paste a previously copied CRB (see vas_copy_crb()) from the L2 cache to
1608c2ecf20Sopenharmony_ci * the hardware address associated with the window @win. @re is expected/
1618c2ecf20Sopenharmony_ci * assumed to be true for NX windows.
1628c2ecf20Sopenharmony_ci */
1638c2ecf20Sopenharmony_ciint vas_paste_crb(struct vas_window *win, int offset, bool re);
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci/*
1668c2ecf20Sopenharmony_ci * Register / unregister coprocessor type to VAS API which will be exported
1678c2ecf20Sopenharmony_ci * to user space. Applications can use this API to open / close window
1688c2ecf20Sopenharmony_ci * which can be used to send / receive requests directly to cooprcessor.
1698c2ecf20Sopenharmony_ci *
1708c2ecf20Sopenharmony_ci * Only NX GZIP coprocessor type is supported now, but this API can be
1718c2ecf20Sopenharmony_ci * used for others in future.
1728c2ecf20Sopenharmony_ci */
1738c2ecf20Sopenharmony_ciint vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type,
1748c2ecf20Sopenharmony_ci				const char *name);
1758c2ecf20Sopenharmony_civoid vas_unregister_coproc_api(void);
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci#endif /* __ASM_POWERPC_VAS_H */
178