18f3a6c92SHaren Myneni /* SPDX-License-Identifier: GPL-2.0-or-later */ 28f3a6c92SHaren Myneni /* 38f3a6c92SHaren Myneni * Copyright 2020-21 IBM Corp. 48f3a6c92SHaren Myneni */ 58f3a6c92SHaren Myneni 68f3a6c92SHaren Myneni #ifndef _VAS_H 78f3a6c92SHaren Myneni #define _VAS_H 88f3a6c92SHaren Myneni #include <asm/vas.h> 98f3a6c92SHaren Myneni #include <linux/mutex.h> 108f3a6c92SHaren Myneni #include <linux/stringify.h> 118f3a6c92SHaren Myneni 128f3a6c92SHaren Myneni /* 138f3a6c92SHaren Myneni * VAS window modify flags 148f3a6c92SHaren Myneni */ 158f3a6c92SHaren Myneni #define VAS_MOD_WIN_CLOSE PPC_BIT(0) 168f3a6c92SHaren Myneni #define VAS_MOD_WIN_JOBS_KILL PPC_BIT(1) 178f3a6c92SHaren Myneni #define VAS_MOD_WIN_DR PPC_BIT(3) 188f3a6c92SHaren Myneni #define VAS_MOD_WIN_PR PPC_BIT(4) 198f3a6c92SHaren Myneni #define VAS_MOD_WIN_SF PPC_BIT(5) 208f3a6c92SHaren Myneni #define VAS_MOD_WIN_TA PPC_BIT(6) 218f3a6c92SHaren Myneni #define VAS_MOD_WIN_FLAGS (VAS_MOD_WIN_JOBS_KILL | VAS_MOD_WIN_DR | \ 228f3a6c92SHaren Myneni VAS_MOD_WIN_PR | VAS_MOD_WIN_SF) 238f3a6c92SHaren Myneni 248f3a6c92SHaren Myneni #define VAS_WIN_ACTIVE 0x0 258f3a6c92SHaren Myneni #define VAS_WIN_CLOSED 0x1 268f3a6c92SHaren Myneni #define VAS_WIN_INACTIVE 0x2 /* Inactive due to HW failure */ 278f3a6c92SHaren Myneni /* Process of being modified, deallocated, or quiesced */ 288f3a6c92SHaren Myneni #define VAS_WIN_MOD_IN_PROCESS 0x3 298f3a6c92SHaren Myneni 308f3a6c92SHaren Myneni #define VAS_COPY_PASTE_USER_MODE 0x00000001 318f3a6c92SHaren Myneni #define VAS_COP_OP_USER_MODE 0x00000010 328f3a6c92SHaren Myneni 33b903737bSHaren Myneni #define VAS_GZIP_QOS_CAPABILITIES 0x56516F73477A6970 34b903737bSHaren Myneni #define VAS_GZIP_DEFAULT_CAPABILITIES 0x56446566477A6970 35b903737bSHaren Myneni 3637e67648SHaren Myneni enum vas_migrate_action { 3737e67648SHaren Myneni VAS_SUSPEND, 3837e67648SHaren Myneni VAS_RESUME, 3937e67648SHaren Myneni }; 4037e67648SHaren Myneni 418f3a6c92SHaren Myneni /* 428f3a6c92SHaren Myneni * Co-processor feature - GZIP QoS windows or GZIP default windows 438f3a6c92SHaren Myneni */ 448f3a6c92SHaren Myneni enum vas_cop_feat_type { 458f3a6c92SHaren Myneni VAS_GZIP_QOS_FEAT_TYPE, 468f3a6c92SHaren Myneni VAS_GZIP_DEF_FEAT_TYPE, 478f3a6c92SHaren Myneni VAS_MAX_FEAT_TYPE, 488f3a6c92SHaren Myneni }; 498f3a6c92SHaren Myneni 508f3a6c92SHaren Myneni /* 518f3a6c92SHaren Myneni * Use to get feature specific capabilities from the 528f3a6c92SHaren Myneni * hypervisor. 538f3a6c92SHaren Myneni */ 548f3a6c92SHaren Myneni struct hv_vas_cop_feat_caps { 558f3a6c92SHaren Myneni __be64 descriptor; 568f3a6c92SHaren Myneni u8 win_type; /* Default or QoS type */ 578f3a6c92SHaren Myneni u8 user_mode; 588f3a6c92SHaren Myneni __be16 max_lpar_creds; 598f3a6c92SHaren Myneni __be16 max_win_creds; 608f3a6c92SHaren Myneni union { 618f3a6c92SHaren Myneni __be16 reserved; 628f3a6c92SHaren Myneni __be16 def_lpar_creds; /* Used for default capabilities */ 638f3a6c92SHaren Myneni }; 648f3a6c92SHaren Myneni __be16 target_lpar_creds; 658f3a6c92SHaren Myneni } __packed __aligned(0x1000); 668f3a6c92SHaren Myneni 678f3a6c92SHaren Myneni /* 688f3a6c92SHaren Myneni * Feature specific (QoS or default) capabilities. 698f3a6c92SHaren Myneni */ 708f3a6c92SHaren Myneni struct vas_cop_feat_caps { 718f3a6c92SHaren Myneni u64 descriptor; 728f3a6c92SHaren Myneni u8 win_type; /* Default or QoS type */ 738f3a6c92SHaren Myneni u8 user_mode; /* User mode copy/paste or COP HCALL */ 748f3a6c92SHaren Myneni u16 max_lpar_creds; /* Max credits available in LPAR */ 758f3a6c92SHaren Myneni /* Max credits can be assigned per window */ 768f3a6c92SHaren Myneni u16 max_win_creds; 778f3a6c92SHaren Myneni union { 788f3a6c92SHaren Myneni u16 reserved; /* Used for QoS credit type */ 798f3a6c92SHaren Myneni u16 def_lpar_creds; /* Used for default credit type */ 808f3a6c92SHaren Myneni }; 818f3a6c92SHaren Myneni /* Total LPAR available credits. Can be different from max LPAR */ 828f3a6c92SHaren Myneni /* credits due to DLPAR operation */ 8340562fe4SHaren Myneni atomic_t nr_total_credits; /* Total credits assigned to LPAR */ 8440562fe4SHaren Myneni atomic_t nr_used_credits; /* Used credits so far */ 858f3a6c92SHaren Myneni }; 868f3a6c92SHaren Myneni 878f3a6c92SHaren Myneni /* 888f3a6c92SHaren Myneni * Feature (QoS or Default) specific to store capabilities and 898f3a6c92SHaren Myneni * the list of open windows. 908f3a6c92SHaren Myneni */ 918f3a6c92SHaren Myneni struct vas_caps { 928f3a6c92SHaren Myneni struct vas_cop_feat_caps caps; 938f3a6c92SHaren Myneni struct list_head list; /* List of open windows */ 94*e1b45baaSHaren Myneni int nr_open_wins_progress; /* Number of open windows in */ 95*e1b45baaSHaren Myneni /* progress. Used in migration */ 968ef7b9e1SHaren Myneni int nr_close_wins; /* closed windows in the hypervisor for DLPAR */ 978ef7b9e1SHaren Myneni int nr_open_windows; /* Number of successful open windows */ 988ef7b9e1SHaren Myneni u8 feat; /* Feature type */ 998f3a6c92SHaren Myneni }; 1008f3a6c92SHaren Myneni 1018f3a6c92SHaren Myneni /* 1028f3a6c92SHaren Myneni * To get window information from the hypervisor. 1038f3a6c92SHaren Myneni */ 1048f3a6c92SHaren Myneni struct hv_vas_win_lpar { 1058f3a6c92SHaren Myneni __be16 version; 1068f3a6c92SHaren Myneni u8 win_type; 1078f3a6c92SHaren Myneni u8 status; 1088f3a6c92SHaren Myneni __be16 credits; /* No of credits assigned to this window */ 1098f3a6c92SHaren Myneni __be16 reserved; 1108f3a6c92SHaren Myneni __be32 pid; /* LPAR Process ID */ 1118f3a6c92SHaren Myneni __be32 tid; /* LPAR Thread ID */ 1128f3a6c92SHaren Myneni __be64 win_addr; /* Paste address */ 1138f3a6c92SHaren Myneni __be32 interrupt; /* Interrupt when NX request completes */ 1148f3a6c92SHaren Myneni __be32 fault; /* Interrupt when NX sees fault */ 1158f3a6c92SHaren Myneni /* Associativity Domain Identifiers as returned in */ 1168f3a6c92SHaren Myneni /* H_HOME_NODE_ASSOCIATIVITY */ 1178f3a6c92SHaren Myneni __be64 domain[6]; 1188f3a6c92SHaren Myneni __be64 win_util; /* Number of bytes processed */ 1198f3a6c92SHaren Myneni } __packed __aligned(0x1000); 1208f3a6c92SHaren Myneni 1218f3a6c92SHaren Myneni struct pseries_vas_window { 1228f3a6c92SHaren Myneni struct vas_window vas_win; 1238f3a6c92SHaren Myneni u64 win_addr; /* Physical paste address */ 1248f3a6c92SHaren Myneni u8 win_type; /* QoS or Default window */ 1258f3a6c92SHaren Myneni u32 complete_irq; /* Completion interrupt */ 1268f3a6c92SHaren Myneni u32 fault_irq; /* Fault interrupt */ 1278f3a6c92SHaren Myneni u64 domain[6]; /* Associativity domain Ids */ 1288f3a6c92SHaren Myneni /* this window is allocated */ 1298f3a6c92SHaren Myneni u64 util; 130976410cdSHaren Myneni u32 pid; /* PID associated with this window */ 1318f3a6c92SHaren Myneni 1328f3a6c92SHaren Myneni /* List of windows opened which is used for LPM */ 1338f3a6c92SHaren Myneni struct list_head win_list; 1348f3a6c92SHaren Myneni u64 flags; 1358f3a6c92SHaren Myneni char *name; 1368f3a6c92SHaren Myneni int fault_virq; 13789ed0b76SHaren Myneni atomic_t pending_faults; /* Number of pending faults */ 1388f3a6c92SHaren Myneni }; 139b903737bSHaren Myneni 140b903737bSHaren Myneni int sysfs_add_vas_caps(struct vas_cop_feat_caps *caps); 14157831bfbSHaren Myneni int vas_reconfig_capabilties(u8 type, int new_nr_creds); 142b903737bSHaren Myneni int __init sysfs_pseries_vas_init(struct vas_all_caps *vas_caps); 14337e67648SHaren Myneni 14437e67648SHaren Myneni #ifdef CONFIG_PPC_VAS 14537e67648SHaren Myneni int vas_migration_handler(int action); 1462147783dSHaren Myneni int pseries_vas_dlpar_cpu(void); 14737e67648SHaren Myneni #else vas_migration_handler(int action)14837e67648SHaren Mynenistatic inline int vas_migration_handler(int action) 14937e67648SHaren Myneni { 15037e67648SHaren Myneni return 0; 15137e67648SHaren Myneni } pseries_vas_dlpar_cpu(void)1522147783dSHaren Mynenistatic inline int pseries_vas_dlpar_cpu(void) 1532147783dSHaren Myneni { 1542147783dSHaren Myneni return 0; 1552147783dSHaren Myneni } 15637e67648SHaren Myneni #endif 1578f3a6c92SHaren Myneni #endif /* _VAS_H */ 158