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