1 /* 2 * Copyright(c) 2015 - 2018 Intel Corporation. 3 * 4 * This file is provided under a dual BSD/GPLv2 license. When using or 5 * redistributing this file, you may do so under either license. 6 * 7 * GPL LICENSE SUMMARY 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of version 2 of the GNU General Public License as 11 * published by the Free Software Foundation. 12 * 13 * This program is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * BSD LICENSE 19 * 20 * Redistribution and use in source and binary forms, with or without 21 * modification, are permitted provided that the following conditions 22 * are met: 23 * 24 * - Redistributions of source code must retain the above copyright 25 * notice, this list of conditions and the following disclaimer. 26 * - Redistributions in binary form must reproduce the above copyright 27 * notice, this list of conditions and the following disclaimer in 28 * the documentation and/or other materials provided with the 29 * distribution. 30 * - Neither the name of Intel Corporation nor the names of its 31 * contributors may be used to endorse or promote products derived 32 * from this software without specific prior written permission. 33 * 34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 * 46 */ 47 #define CREATE_TRACE_POINTS 48 #include "trace.h" 49 #include "exp_rcv.h" 50 51 static u8 __get_ib_hdr_len(struct ib_header *hdr) 52 { 53 struct ib_other_headers *ohdr; 54 u8 opcode; 55 56 if (ib_get_lnh(hdr) == HFI1_LRH_BTH) 57 ohdr = &hdr->u.oth; 58 else 59 ohdr = &hdr->u.l.oth; 60 opcode = ib_bth_get_opcode(ohdr); 61 return hdr_len_by_opcode[opcode] == 0 ? 62 0 : hdr_len_by_opcode[opcode] - (12 + 8); 63 } 64 65 static u8 __get_16b_hdr_len(struct hfi1_16b_header *hdr) 66 { 67 struct ib_other_headers *ohdr = NULL; 68 u8 opcode; 69 u8 l4 = hfi1_16B_get_l4(hdr); 70 71 if (l4 == OPA_16B_L4_FM) { 72 opcode = IB_OPCODE_UD_SEND_ONLY; 73 return (8 + 8); /* No BTH */ 74 } 75 76 if (l4 == OPA_16B_L4_IB_LOCAL) 77 ohdr = &hdr->u.oth; 78 else 79 ohdr = &hdr->u.l.oth; 80 81 opcode = ib_bth_get_opcode(ohdr); 82 return hdr_len_by_opcode[opcode] == 0 ? 83 0 : hdr_len_by_opcode[opcode] - (12 + 8 + 8); 84 } 85 86 u8 hfi1_trace_packet_hdr_len(struct hfi1_packet *packet) 87 { 88 if (packet->etype != RHF_RCV_TYPE_BYPASS) 89 return __get_ib_hdr_len(packet->hdr); 90 else 91 return __get_16b_hdr_len(packet->hdr); 92 } 93 94 u8 hfi1_trace_opa_hdr_len(struct hfi1_opa_header *opa_hdr) 95 { 96 if (!opa_hdr->hdr_type) 97 return __get_ib_hdr_len(&opa_hdr->ibh); 98 else 99 return __get_16b_hdr_len(&opa_hdr->opah); 100 } 101 102 const char *hfi1_trace_get_packet_l4_str(u8 l4) 103 { 104 if (l4) 105 return "16B"; 106 else 107 return "9B"; 108 } 109 110 const char *hfi1_trace_get_packet_l2_str(u8 l2) 111 { 112 switch (l2) { 113 case 0: 114 return "0"; 115 case 1: 116 return "1"; 117 case 2: 118 return "16B"; 119 case 3: 120 return "9B"; 121 } 122 return ""; 123 } 124 125 #define IMM_PRN "imm:%d" 126 #define RETH_PRN "reth vaddr:0x%.16llx rkey:0x%.8x dlen:0x%.8x" 127 #define AETH_PRN "aeth syn:0x%.2x %s msn:0x%.8x" 128 #define DETH_PRN "deth qkey:0x%.8x sqpn:0x%.6x" 129 #define IETH_PRN "ieth rkey:0x%.8x" 130 #define ATOMICACKETH_PRN "origdata:%llx" 131 #define ATOMICETH_PRN "vaddr:0x%llx rkey:0x%.8x sdata:%llx cdata:%llx" 132 133 #define OP(transport, op) IB_OPCODE_## transport ## _ ## op 134 135 static const char *parse_syndrome(u8 syndrome) 136 { 137 switch (syndrome >> 5) { 138 case 0: 139 return "ACK"; 140 case 1: 141 return "RNRNAK"; 142 case 3: 143 return "NAK"; 144 } 145 return ""; 146 } 147 148 void hfi1_trace_parse_9b_bth(struct ib_other_headers *ohdr, 149 u8 *ack, bool *becn, bool *fecn, u8 *mig, 150 u8 *se, u8 *pad, u8 *opcode, u8 *tver, 151 u16 *pkey, u32 *psn, u32 *qpn) 152 { 153 *ack = ib_bth_get_ackreq(ohdr); 154 *becn = ib_bth_get_becn(ohdr); 155 *fecn = ib_bth_get_fecn(ohdr); 156 *mig = ib_bth_get_migreq(ohdr); 157 *se = ib_bth_get_se(ohdr); 158 *pad = ib_bth_get_pad(ohdr); 159 *opcode = ib_bth_get_opcode(ohdr); 160 *tver = ib_bth_get_tver(ohdr); 161 *pkey = ib_bth_get_pkey(ohdr); 162 *psn = mask_psn(ib_bth_get_psn(ohdr)); 163 *qpn = ib_bth_get_qpn(ohdr); 164 } 165 166 void hfi1_trace_parse_16b_bth(struct ib_other_headers *ohdr, 167 u8 *ack, u8 *mig, u8 *opcode, 168 u8 *pad, u8 *se, u8 *tver, 169 u32 *psn, u32 *qpn) 170 { 171 *ack = ib_bth_get_ackreq(ohdr); 172 *mig = ib_bth_get_migreq(ohdr); 173 *opcode = ib_bth_get_opcode(ohdr); 174 *pad = ib_bth_get_pad(ohdr); 175 *se = ib_bth_get_se(ohdr); 176 *tver = ib_bth_get_tver(ohdr); 177 *psn = mask_psn(ib_bth_get_psn(ohdr)); 178 *qpn = ib_bth_get_qpn(ohdr); 179 } 180 181 void hfi1_trace_parse_9b_hdr(struct ib_header *hdr, bool sc5, 182 u8 *lnh, u8 *lver, u8 *sl, u8 *sc, 183 u16 *len, u32 *dlid, u32 *slid) 184 { 185 *lnh = ib_get_lnh(hdr); 186 *lver = ib_get_lver(hdr); 187 *sl = ib_get_sl(hdr); 188 *sc = ib_get_sc(hdr) | (sc5 << 4); 189 *len = ib_get_len(hdr); 190 *dlid = ib_get_dlid(hdr); 191 *slid = ib_get_slid(hdr); 192 } 193 194 void hfi1_trace_parse_16b_hdr(struct hfi1_16b_header *hdr, 195 u8 *age, bool *becn, bool *fecn, 196 u8 *l4, u8 *rc, u8 *sc, 197 u16 *entropy, u16 *len, u16 *pkey, 198 u32 *dlid, u32 *slid) 199 { 200 *age = hfi1_16B_get_age(hdr); 201 *becn = hfi1_16B_get_becn(hdr); 202 *fecn = hfi1_16B_get_fecn(hdr); 203 *l4 = hfi1_16B_get_l4(hdr); 204 *rc = hfi1_16B_get_rc(hdr); 205 *sc = hfi1_16B_get_sc(hdr); 206 *entropy = hfi1_16B_get_entropy(hdr); 207 *len = hfi1_16B_get_len(hdr); 208 *pkey = hfi1_16B_get_pkey(hdr); 209 *dlid = hfi1_16B_get_dlid(hdr); 210 *slid = hfi1_16B_get_slid(hdr); 211 } 212 213 #define LRH_PRN "len:%d sc:%d dlid:0x%.4x slid:0x%.4x " 214 #define LRH_9B_PRN "lnh:%d,%s lver:%d sl:%d" 215 #define LRH_16B_PRN "age:%d becn:%d fecn:%d l4:%d " \ 216 "rc:%d sc:%d pkey:0x%.4x entropy:0x%.4x" 217 const char *hfi1_trace_fmt_lrh(struct trace_seq *p, bool bypass, 218 u8 age, bool becn, bool fecn, u8 l4, 219 u8 lnh, const char *lnh_name, u8 lver, 220 u8 rc, u8 sc, u8 sl, u16 entropy, 221 u16 len, u16 pkey, u32 dlid, u32 slid) 222 { 223 const char *ret = trace_seq_buffer_ptr(p); 224 225 trace_seq_printf(p, LRH_PRN, len, sc, dlid, slid); 226 227 if (bypass) 228 trace_seq_printf(p, LRH_16B_PRN, 229 age, becn, fecn, l4, rc, sc, pkey, entropy); 230 231 else 232 trace_seq_printf(p, LRH_9B_PRN, 233 lnh, lnh_name, lver, sl); 234 trace_seq_putc(p, 0); 235 236 return ret; 237 } 238 239 #define BTH_9B_PRN \ 240 "op:0x%.2x,%s se:%d m:%d pad:%d tver:%d pkey:0x%.4x " \ 241 "f:%d b:%d qpn:0x%.6x a:%d psn:0x%.8x" 242 #define BTH_16B_PRN \ 243 "op:0x%.2x,%s se:%d m:%d pad:%d tver:%d " \ 244 "qpn:0x%.6x a:%d psn:0x%.8x" 245 #define L4_FM_16B_PRN \ 246 "op:0x%.2x,%s dest_qpn:0x%.6x src_qpn:0x%.6x" 247 const char *hfi1_trace_fmt_rest(struct trace_seq *p, bool bypass, u8 l4, 248 u8 ack, bool becn, bool fecn, u8 mig, 249 u8 se, u8 pad, u8 opcode, const char *opname, 250 u8 tver, u16 pkey, u32 psn, u32 qpn, 251 u32 dest_qpn, u32 src_qpn) 252 { 253 const char *ret = trace_seq_buffer_ptr(p); 254 255 if (bypass) 256 if (l4 == OPA_16B_L4_FM) 257 trace_seq_printf(p, L4_FM_16B_PRN, 258 opcode, opname, dest_qpn, src_qpn); 259 else 260 trace_seq_printf(p, BTH_16B_PRN, 261 opcode, opname, 262 se, mig, pad, tver, qpn, ack, psn); 263 264 else 265 trace_seq_printf(p, BTH_9B_PRN, 266 opcode, opname, 267 se, mig, pad, tver, pkey, fecn, becn, 268 qpn, ack, psn); 269 trace_seq_putc(p, 0); 270 271 return ret; 272 } 273 274 const char *parse_everbs_hdrs( 275 struct trace_seq *p, 276 u8 opcode, u8 l4, u32 dest_qpn, u32 src_qpn, 277 void *ehdrs) 278 { 279 union ib_ehdrs *eh = ehdrs; 280 const char *ret = trace_seq_buffer_ptr(p); 281 282 if (l4 == OPA_16B_L4_FM) { 283 trace_seq_printf(p, "mgmt pkt"); 284 goto out; 285 } 286 287 switch (opcode) { 288 /* imm */ 289 case OP(RC, SEND_LAST_WITH_IMMEDIATE): 290 case OP(UC, SEND_LAST_WITH_IMMEDIATE): 291 case OP(RC, SEND_ONLY_WITH_IMMEDIATE): 292 case OP(UC, SEND_ONLY_WITH_IMMEDIATE): 293 case OP(RC, RDMA_WRITE_LAST_WITH_IMMEDIATE): 294 case OP(UC, RDMA_WRITE_LAST_WITH_IMMEDIATE): 295 trace_seq_printf(p, IMM_PRN, 296 be32_to_cpu(eh->imm_data)); 297 break; 298 /* reth + imm */ 299 case OP(RC, RDMA_WRITE_ONLY_WITH_IMMEDIATE): 300 case OP(UC, RDMA_WRITE_ONLY_WITH_IMMEDIATE): 301 trace_seq_printf(p, RETH_PRN " " IMM_PRN, 302 get_ib_reth_vaddr(&eh->rc.reth), 303 be32_to_cpu(eh->rc.reth.rkey), 304 be32_to_cpu(eh->rc.reth.length), 305 be32_to_cpu(eh->rc.imm_data)); 306 break; 307 /* reth */ 308 case OP(RC, RDMA_READ_REQUEST): 309 case OP(RC, RDMA_WRITE_FIRST): 310 case OP(UC, RDMA_WRITE_FIRST): 311 case OP(RC, RDMA_WRITE_ONLY): 312 case OP(UC, RDMA_WRITE_ONLY): 313 trace_seq_printf(p, RETH_PRN, 314 get_ib_reth_vaddr(&eh->rc.reth), 315 be32_to_cpu(eh->rc.reth.rkey), 316 be32_to_cpu(eh->rc.reth.length)); 317 break; 318 case OP(RC, RDMA_READ_RESPONSE_FIRST): 319 case OP(RC, RDMA_READ_RESPONSE_LAST): 320 case OP(RC, RDMA_READ_RESPONSE_ONLY): 321 case OP(RC, ACKNOWLEDGE): 322 trace_seq_printf(p, AETH_PRN, be32_to_cpu(eh->aeth) >> 24, 323 parse_syndrome(be32_to_cpu(eh->aeth) >> 24), 324 be32_to_cpu(eh->aeth) & IB_MSN_MASK); 325 break; 326 /* aeth + atomicacketh */ 327 case OP(RC, ATOMIC_ACKNOWLEDGE): 328 trace_seq_printf(p, AETH_PRN " " ATOMICACKETH_PRN, 329 be32_to_cpu(eh->at.aeth) >> 24, 330 parse_syndrome(be32_to_cpu(eh->at.aeth) >> 24), 331 be32_to_cpu(eh->at.aeth) & IB_MSN_MASK, 332 ib_u64_get(&eh->at.atomic_ack_eth)); 333 break; 334 /* atomiceth */ 335 case OP(RC, COMPARE_SWAP): 336 case OP(RC, FETCH_ADD): 337 trace_seq_printf(p, ATOMICETH_PRN, 338 get_ib_ateth_vaddr(&eh->atomic_eth), 339 eh->atomic_eth.rkey, 340 get_ib_ateth_swap(&eh->atomic_eth), 341 get_ib_ateth_compare(&eh->atomic_eth)); 342 break; 343 /* deth */ 344 case OP(UD, SEND_ONLY): 345 case OP(UD, SEND_ONLY_WITH_IMMEDIATE): 346 trace_seq_printf(p, DETH_PRN, 347 be32_to_cpu(eh->ud.deth[0]), 348 be32_to_cpu(eh->ud.deth[1]) & RVT_QPN_MASK); 349 break; 350 /* ieth */ 351 case OP(RC, SEND_LAST_WITH_INVALIDATE): 352 case OP(RC, SEND_ONLY_WITH_INVALIDATE): 353 trace_seq_printf(p, IETH_PRN, 354 be32_to_cpu(eh->ieth)); 355 break; 356 } 357 out: 358 trace_seq_putc(p, 0); 359 return ret; 360 } 361 362 const char *parse_sdma_flags( 363 struct trace_seq *p, 364 u64 desc0, u64 desc1) 365 { 366 const char *ret = trace_seq_buffer_ptr(p); 367 char flags[5] = { 'x', 'x', 'x', 'x', 0 }; 368 369 flags[0] = (desc1 & SDMA_DESC1_INT_REQ_FLAG) ? 'I' : '-'; 370 flags[1] = (desc1 & SDMA_DESC1_HEAD_TO_HOST_FLAG) ? 'H' : '-'; 371 flags[2] = (desc0 & SDMA_DESC0_FIRST_DESC_FLAG) ? 'F' : '-'; 372 flags[3] = (desc0 & SDMA_DESC0_LAST_DESC_FLAG) ? 'L' : '-'; 373 trace_seq_printf(p, "%s", flags); 374 if (desc0 & SDMA_DESC0_FIRST_DESC_FLAG) 375 trace_seq_printf(p, " amode:%u aidx:%u alen:%u", 376 (u8)((desc1 >> SDMA_DESC1_HEADER_MODE_SHIFT) & 377 SDMA_DESC1_HEADER_MODE_MASK), 378 (u8)((desc1 >> SDMA_DESC1_HEADER_INDEX_SHIFT) & 379 SDMA_DESC1_HEADER_INDEX_MASK), 380 (u8)((desc1 >> SDMA_DESC1_HEADER_DWS_SHIFT) & 381 SDMA_DESC1_HEADER_DWS_MASK)); 382 return ret; 383 } 384 385 const char *print_u32_array( 386 struct trace_seq *p, 387 u32 *arr, int len) 388 { 389 int i; 390 const char *ret = trace_seq_buffer_ptr(p); 391 392 for (i = 0; i < len ; i++) 393 trace_seq_printf(p, "%s%#x", i == 0 ? "" : " ", arr[i]); 394 trace_seq_putc(p, 0); 395 return ret; 396 } 397 398 u8 hfi1_trace_get_tid_ctrl(u32 ent) 399 { 400 return EXP_TID_GET(ent, CTRL); 401 } 402 403 u16 hfi1_trace_get_tid_len(u32 ent) 404 { 405 return EXP_TID_GET(ent, LEN); 406 } 407 408 u16 hfi1_trace_get_tid_idx(u32 ent) 409 { 410 return EXP_TID_GET(ent, IDX); 411 } 412 413 __hfi1_trace_fn(AFFINITY); 414 __hfi1_trace_fn(PKT); 415 __hfi1_trace_fn(PROC); 416 __hfi1_trace_fn(SDMA); 417 __hfi1_trace_fn(LINKVERB); 418 __hfi1_trace_fn(DEBUG); 419 __hfi1_trace_fn(SNOOP); 420 __hfi1_trace_fn(CNTR); 421 __hfi1_trace_fn(PIO); 422 __hfi1_trace_fn(DC8051); 423 __hfi1_trace_fn(FIRMWARE); 424 __hfi1_trace_fn(RCVCTRL); 425 __hfi1_trace_fn(TID); 426 __hfi1_trace_fn(MMU); 427 __hfi1_trace_fn(IOCTL); 428