0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _ASM_S390_CPU_MF_H
0010 #define _ASM_S390_CPU_MF_H
0011
0012 #include <linux/errno.h>
0013 #include <asm/asm-extable.h>
0014 #include <asm/facility.h>
0015
0016 asm(".include \"asm/cpu_mf-insn.h\"\n");
0017
0018 #define CPU_MF_INT_SF_IAE (1 << 31)
0019 #define CPU_MF_INT_SF_ISE (1 << 30)
0020 #define CPU_MF_INT_SF_PRA (1 << 29)
0021 #define CPU_MF_INT_SF_SACA (1 << 23)
0022 #define CPU_MF_INT_SF_LSDA (1 << 22)
0023 #define CPU_MF_INT_CF_MTDA (1 << 15)
0024 #define CPU_MF_INT_CF_CACA (1 << 7)
0025 #define CPU_MF_INT_CF_LCDA (1 << 6)
0026 #define CPU_MF_INT_CF_MASK (CPU_MF_INT_CF_MTDA|CPU_MF_INT_CF_CACA| \
0027 CPU_MF_INT_CF_LCDA)
0028 #define CPU_MF_INT_SF_MASK (CPU_MF_INT_SF_IAE|CPU_MF_INT_SF_ISE| \
0029 CPU_MF_INT_SF_PRA|CPU_MF_INT_SF_SACA| \
0030 CPU_MF_INT_SF_LSDA)
0031
0032 #define CPU_MF_SF_RIBM_NOTAV 0x1
0033
0034
0035 static inline int cpum_cf_avail(void)
0036 {
0037 return test_facility(40) && test_facility(67);
0038 }
0039
0040 static inline int cpum_sf_avail(void)
0041 {
0042 return test_facility(40) && test_facility(68);
0043 }
0044
0045
0046 struct cpumf_ctr_info {
0047 u16 cfvn;
0048 u16 auth_ctl;
0049 u16 enable_ctl;
0050 u16 act_ctl;
0051 u16 max_cpu;
0052 u16 csvn;
0053 u16 max_cg;
0054 u16 reserved1;
0055 u32 reserved2[12];
0056 } __packed;
0057
0058
0059 struct hws_qsi_info_block {
0060 unsigned int b0_13:14;
0061 unsigned int as:1;
0062 unsigned int ad:1;
0063 unsigned int b16_21:6;
0064 unsigned int es:1;
0065 unsigned int ed:1;
0066 unsigned int b24_29:6;
0067 unsigned int cs:1;
0068 unsigned int cd:1;
0069 unsigned int bsdes:16;
0070 unsigned int dsdes:16;
0071 unsigned long min_sampl_rate;
0072 unsigned long max_sampl_rate;
0073 unsigned long tear;
0074 unsigned long dear;
0075 unsigned int rsvrd0:24;
0076 unsigned int ribm:8;
0077 unsigned int cpu_speed;
0078 unsigned long long rsvrd1;
0079 unsigned long long rsvrd2;
0080 } __packed;
0081
0082
0083 struct hws_lsctl_request_block {
0084 unsigned int s:1;
0085 unsigned int h:1;
0086 unsigned long long b2_53:52;
0087 unsigned int es:1;
0088 unsigned int ed:1;
0089 unsigned int b56_61:6;
0090 unsigned int cs:1;
0091 unsigned int cd:1;
0092 unsigned long interval;
0093 unsigned long tear;
0094 unsigned long dear;
0095
0096 unsigned long rsvrd1;
0097 unsigned long rsvrd2;
0098 unsigned long rsvrd3;
0099 unsigned long rsvrd4;
0100 } __packed;
0101
0102 struct hws_basic_entry {
0103 unsigned int def:16;
0104 unsigned int R:4;
0105 unsigned int U:4;
0106 unsigned int z:2;
0107 unsigned int T:1;
0108 unsigned int W:1;
0109 unsigned int P:1;
0110 unsigned int AS:2;
0111 unsigned int I:1;
0112 unsigned int CL:2;
0113 unsigned int H:1;
0114 unsigned int LS:1;
0115 unsigned int:12;
0116 unsigned int prim_asn:16;
0117 unsigned long long ia;
0118 unsigned long long gpp;
0119 unsigned long long hpp;
0120 } __packed;
0121
0122 struct hws_diag_entry {
0123 unsigned int def:16;
0124 unsigned int R:15;
0125 unsigned int I:1;
0126 u8 data[];
0127 } __packed;
0128
0129 struct hws_combined_entry {
0130 struct hws_basic_entry basic;
0131 struct hws_diag_entry diag;
0132 } __packed;
0133
0134 struct hws_trailer_entry {
0135 union {
0136 struct {
0137 unsigned int f:1;
0138 unsigned int a:1;
0139 unsigned int t:1;
0140 unsigned int :29;
0141 unsigned int bsdes:16;
0142 unsigned int dsdes:16;
0143 };
0144 unsigned long long flags;
0145 };
0146 unsigned long long overflow;
0147 unsigned char timestamp[16];
0148 unsigned long long reserved1;
0149 unsigned long long reserved2;
0150 union {
0151 struct {
0152 unsigned int clock_base:1;
0153 unsigned long long progusage1:63;
0154 unsigned long long progusage2;
0155 };
0156 unsigned long long progusage[2];
0157 };
0158 } __packed;
0159
0160
0161 static inline void lpp(void *pp)
0162 {
0163 asm volatile("lpp 0(%0)\n" :: "a" (pp) : "memory");
0164 }
0165
0166
0167 static inline int qctri(struct cpumf_ctr_info *info)
0168 {
0169 int rc = -EINVAL;
0170
0171 asm volatile (
0172 "0: qctri %1\n"
0173 "1: lhi %0,0\n"
0174 "2:\n"
0175 EX_TABLE(1b, 2b)
0176 : "+d" (rc), "=Q" (*info));
0177 return rc;
0178 }
0179
0180
0181 static inline int lcctl(u64 ctl)
0182 {
0183 int cc;
0184
0185 asm volatile (
0186 " lcctl %1\n"
0187 " ipm %0\n"
0188 " srl %0,28\n"
0189 : "=d" (cc) : "Q" (ctl) : "cc");
0190 return cc;
0191 }
0192
0193
0194 static inline int __ecctr(u64 ctr, u64 *content)
0195 {
0196 u64 _content;
0197 int cc;
0198
0199 asm volatile (
0200 " ecctr %0,%2\n"
0201 " ipm %1\n"
0202 " srl %1,28\n"
0203 : "=d" (_content), "=d" (cc) : "d" (ctr) : "cc");
0204 *content = _content;
0205 return cc;
0206 }
0207
0208
0209 static inline int ecctr(u64 ctr, u64 *val)
0210 {
0211 u64 content;
0212 int cc;
0213
0214 cc = __ecctr(ctr, &content);
0215 if (!cc)
0216 *val = content;
0217 return cc;
0218 }
0219
0220
0221 enum stcctm_ctr_set {
0222 EXTENDED = 0,
0223 BASIC = 1,
0224 PROBLEM_STATE = 2,
0225 CRYPTO_ACTIVITY = 3,
0226 MT_DIAG = 5,
0227 MT_DIAG_CLEARING = 9,
0228 };
0229
0230 static __always_inline int stcctm(enum stcctm_ctr_set set, u64 range, u64 *dest)
0231 {
0232 int cc;
0233
0234 asm volatile (
0235 " STCCTM %2,%3,%1\n"
0236 " ipm %0\n"
0237 " srl %0,28\n"
0238 : "=d" (cc)
0239 : "Q" (*dest), "d" (range), "i" (set)
0240 : "cc", "memory");
0241 return cc;
0242 }
0243
0244
0245 static inline int qsi(struct hws_qsi_info_block *info)
0246 {
0247 int cc = 1;
0248
0249 asm volatile(
0250 "0: qsi %1\n"
0251 "1: lhi %0,0\n"
0252 "2:\n"
0253 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
0254 : "+d" (cc), "+Q" (*info));
0255 return cc ? -EINVAL : 0;
0256 }
0257
0258
0259 static inline int lsctl(struct hws_lsctl_request_block *req)
0260 {
0261 int cc;
0262
0263 cc = 1;
0264 asm volatile(
0265 "0: lsctl 0(%1)\n"
0266 "1: ipm %0\n"
0267 " srl %0,28\n"
0268 "2:\n"
0269 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
0270 : "+d" (cc), "+a" (req)
0271 : "m" (*req)
0272 : "cc", "memory");
0273
0274 return cc ? -EINVAL : 0;
0275 }
0276
0277
0278
0279 #include <linux/time.h>
0280
0281 static inline unsigned long freq_to_sample_rate(struct hws_qsi_info_block *qsi,
0282 unsigned long freq)
0283 {
0284 return (USEC_PER_SEC / freq) * qsi->cpu_speed;
0285 }
0286
0287 static inline unsigned long sample_rate_to_freq(struct hws_qsi_info_block *qsi,
0288 unsigned long rate)
0289 {
0290 return USEC_PER_SEC * qsi->cpu_speed / rate;
0291 }
0292
0293 #define SDB_TE_ALERT_REQ_MASK 0x4000000000000000UL
0294 #define SDB_TE_BUFFER_FULL_MASK 0x8000000000000000UL
0295
0296
0297 static inline unsigned long long trailer_timestamp(struct hws_trailer_entry *te)
0298 {
0299
0300 if (te->t)
0301 return *((unsigned long long *) &te->timestamp[1]);
0302
0303
0304 return *((unsigned long long *) &te->timestamp[0]);
0305 }
0306
0307
0308 static inline unsigned long *trailer_entry_ptr(unsigned long v)
0309 {
0310 void *ret;
0311
0312 ret = (void *) v;
0313 ret += PAGE_SIZE;
0314 ret -= sizeof(struct hws_trailer_entry);
0315
0316 return (unsigned long *) ret;
0317 }
0318
0319
0320
0321 static inline int is_link_entry(unsigned long *s)
0322 {
0323 return *s & 0x1ul ? 1 : 0;
0324 }
0325
0326
0327 static inline unsigned long *get_next_sdbt(unsigned long *s)
0328 {
0329 return (unsigned long *) (*s & ~0x1ul);
0330 }
0331 #endif