trace.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. static u8 __get_ib_hdr_len(struct ib_header *hdr)
  50. {
  51. struct ib_other_headers *ohdr;
  52. u8 opcode;
  53. if (ib_get_lnh(hdr) == HFI1_LRH_BTH)
  54. ohdr = &hdr->u.oth;
  55. else
  56. ohdr = &hdr->u.l.oth;
  57. opcode = ib_bth_get_opcode(ohdr);
  58. return hdr_len_by_opcode[opcode] == 0 ?
  59. 0 : hdr_len_by_opcode[opcode] - (12 + 8);
  60. }
  61. static u8 __get_16b_hdr_len(struct hfi1_16b_header *hdr)
  62. {
  63. struct ib_other_headers *ohdr = NULL;
  64. u8 opcode;
  65. u8 l4 = hfi1_16B_get_l4(hdr);
  66. if (l4 == OPA_16B_L4_FM) {
  67. opcode = IB_OPCODE_UD_SEND_ONLY;
  68. return (8 + 8); /* No BTH */
  69. }
  70. if (l4 == OPA_16B_L4_IB_LOCAL)
  71. ohdr = &hdr->u.oth;
  72. else
  73. ohdr = &hdr->u.l.oth;
  74. opcode = ib_bth_get_opcode(ohdr);
  75. return hdr_len_by_opcode[opcode] == 0 ?
  76. 0 : hdr_len_by_opcode[opcode] - (12 + 8 + 8);
  77. }
  78. u8 hfi1_trace_packet_hdr_len(struct hfi1_packet *packet)
  79. {
  80. if (packet->etype != RHF_RCV_TYPE_BYPASS)
  81. return __get_ib_hdr_len(packet->hdr);
  82. else
  83. return __get_16b_hdr_len(packet->hdr);
  84. }
  85. u8 hfi1_trace_opa_hdr_len(struct hfi1_opa_header *opa_hdr)
  86. {
  87. if (!opa_hdr->hdr_type)
  88. return __get_ib_hdr_len(&opa_hdr->ibh);
  89. else
  90. return __get_16b_hdr_len(&opa_hdr->opah);
  91. }
  92. const char *hfi1_trace_get_packet_l4_str(u8 l4)
  93. {
  94. if (l4)
  95. return "16B";
  96. else
  97. return "9B";
  98. }
  99. const char *hfi1_trace_get_packet_l2_str(u8 l2)
  100. {
  101. switch (l2) {
  102. case 0:
  103. return "0";
  104. case 1:
  105. return "1";
  106. case 2:
  107. return "16B";
  108. case 3:
  109. return "9B";
  110. }
  111. return "";
  112. }
  113. #define IMM_PRN "imm:%d"
  114. #define RETH_PRN "reth vaddr:0x%.16llx rkey:0x%.8x dlen:0x%.8x"
  115. #define AETH_PRN "aeth syn:0x%.2x %s msn:0x%.8x"
  116. #define DETH_PRN "deth qkey:0x%.8x sqpn:0x%.6x"
  117. #define IETH_PRN "ieth rkey:0x%.8x"
  118. #define ATOMICACKETH_PRN "origdata:%llx"
  119. #define ATOMICETH_PRN "vaddr:0x%llx rkey:0x%.8x sdata:%llx cdata:%llx"
  120. #define OP(transport, op) IB_OPCODE_## transport ## _ ## op
  121. static const char *parse_syndrome(u8 syndrome)
  122. {
  123. switch (syndrome >> 5) {
  124. case 0:
  125. return "ACK";
  126. case 1:
  127. return "RNRNAK";
  128. case 3:
  129. return "NAK";
  130. }
  131. return "";
  132. }
  133. void hfi1_trace_parse_9b_bth(struct ib_other_headers *ohdr,
  134. u8 *ack, bool *becn, bool *fecn, u8 *mig,
  135. u8 *se, u8 *pad, u8 *opcode, u8 *tver,
  136. u16 *pkey, u32 *psn, u32 *qpn)
  137. {
  138. *ack = ib_bth_get_ackreq(ohdr);
  139. *becn = ib_bth_get_becn(ohdr);
  140. *fecn = ib_bth_get_fecn(ohdr);
  141. *mig = ib_bth_get_migreq(ohdr);
  142. *se = ib_bth_get_se(ohdr);
  143. *pad = ib_bth_get_pad(ohdr);
  144. *opcode = ib_bth_get_opcode(ohdr);
  145. *tver = ib_bth_get_tver(ohdr);
  146. *pkey = ib_bth_get_pkey(ohdr);
  147. *psn = mask_psn(ib_bth_get_psn(ohdr));
  148. *qpn = ib_bth_get_qpn(ohdr);
  149. }
  150. void hfi1_trace_parse_16b_bth(struct ib_other_headers *ohdr,
  151. u8 *ack, u8 *mig, u8 *opcode,
  152. u8 *pad, u8 *se, u8 *tver,
  153. u32 *psn, u32 *qpn)
  154. {
  155. *ack = ib_bth_get_ackreq(ohdr);
  156. *mig = ib_bth_get_migreq(ohdr);
  157. *opcode = ib_bth_get_opcode(ohdr);
  158. *pad = ib_bth_get_pad(ohdr);
  159. *se = ib_bth_get_se(ohdr);
  160. *tver = ib_bth_get_tver(ohdr);
  161. *psn = mask_psn(ib_bth_get_psn(ohdr));
  162. *qpn = ib_bth_get_qpn(ohdr);
  163. }
  164. void hfi1_trace_parse_9b_hdr(struct ib_header *hdr, bool sc5,
  165. u8 *lnh, u8 *lver, u8 *sl, u8 *sc,
  166. u16 *len, u32 *dlid, u32 *slid)
  167. {
  168. *lnh = ib_get_lnh(hdr);
  169. *lver = ib_get_lver(hdr);
  170. *sl = ib_get_sl(hdr);
  171. *sc = ib_get_sc(hdr) | (sc5 << 4);
  172. *len = ib_get_len(hdr);
  173. *dlid = ib_get_dlid(hdr);
  174. *slid = ib_get_slid(hdr);
  175. }
  176. void hfi1_trace_parse_16b_hdr(struct hfi1_16b_header *hdr,
  177. u8 *age, bool *becn, bool *fecn,
  178. u8 *l4, u8 *rc, u8 *sc,
  179. u16 *entropy, u16 *len, u16 *pkey,
  180. u32 *dlid, u32 *slid)
  181. {
  182. *age = hfi1_16B_get_age(hdr);
  183. *becn = hfi1_16B_get_becn(hdr);
  184. *fecn = hfi1_16B_get_fecn(hdr);
  185. *l4 = hfi1_16B_get_l4(hdr);
  186. *rc = hfi1_16B_get_rc(hdr);
  187. *sc = hfi1_16B_get_sc(hdr);
  188. *entropy = hfi1_16B_get_entropy(hdr);
  189. *len = hfi1_16B_get_len(hdr);
  190. *pkey = hfi1_16B_get_pkey(hdr);
  191. *dlid = hfi1_16B_get_dlid(hdr);
  192. *slid = hfi1_16B_get_slid(hdr);
  193. }
  194. #define LRH_PRN "len:%d sc:%d dlid:0x%.4x slid:0x%.4x "
  195. #define LRH_9B_PRN "lnh:%d,%s lver:%d sl:%d"
  196. #define LRH_16B_PRN "age:%d becn:%d fecn:%d l4:%d " \
  197. "rc:%d sc:%d pkey:0x%.4x entropy:0x%.4x"
  198. const char *hfi1_trace_fmt_lrh(struct trace_seq *p, bool bypass,
  199. u8 age, bool becn, bool fecn, u8 l4,
  200. u8 lnh, const char *lnh_name, u8 lver,
  201. u8 rc, u8 sc, u8 sl, u16 entropy,
  202. u16 len, u16 pkey, u32 dlid, u32 slid)
  203. {
  204. const char *ret = trace_seq_buffer_ptr(p);
  205. trace_seq_printf(p, LRH_PRN, len, sc, dlid, slid);
  206. if (bypass)
  207. trace_seq_printf(p, LRH_16B_PRN,
  208. age, becn, fecn, l4, rc, sc, pkey, entropy);
  209. else
  210. trace_seq_printf(p, LRH_9B_PRN,
  211. lnh, lnh_name, lver, sl);
  212. trace_seq_putc(p, 0);
  213. return ret;
  214. }
  215. #define BTH_9B_PRN \
  216. "op:0x%.2x,%s se:%d m:%d pad:%d tver:%d pkey:0x%.4x " \
  217. "f:%d b:%d qpn:0x%.6x a:%d psn:0x%.8x"
  218. #define BTH_16B_PRN \
  219. "op:0x%.2x,%s se:%d m:%d pad:%d tver:%d " \
  220. "qpn:0x%.6x a:%d psn:0x%.8x"
  221. #define L4_FM_16B_PRN \
  222. "op:0x%.2x,%s dest_qpn:0x%.6x src_qpn:0x%.6x"
  223. const char *hfi1_trace_fmt_rest(struct trace_seq *p, bool bypass, u8 l4,
  224. u8 ack, bool becn, bool fecn, u8 mig,
  225. u8 se, u8 pad, u8 opcode, const char *opname,
  226. u8 tver, u16 pkey, u32 psn, u32 qpn,
  227. u32 dest_qpn, u32 src_qpn)
  228. {
  229. const char *ret = trace_seq_buffer_ptr(p);
  230. if (bypass)
  231. if (l4 == OPA_16B_L4_FM)
  232. trace_seq_printf(p, L4_FM_16B_PRN,
  233. opcode, opname, dest_qpn, src_qpn);
  234. else
  235. trace_seq_printf(p, BTH_16B_PRN,
  236. opcode, opname,
  237. se, mig, pad, tver, qpn, ack, psn);
  238. else
  239. trace_seq_printf(p, BTH_9B_PRN,
  240. opcode, opname,
  241. se, mig, pad, tver, pkey, fecn, becn,
  242. qpn, ack, psn);
  243. trace_seq_putc(p, 0);
  244. return ret;
  245. }
  246. const char *parse_everbs_hdrs(
  247. struct trace_seq *p,
  248. u8 opcode, u8 l4, u32 dest_qpn, u32 src_qpn,
  249. void *ehdrs)
  250. {
  251. union ib_ehdrs *eh = ehdrs;
  252. const char *ret = trace_seq_buffer_ptr(p);
  253. if (l4 == OPA_16B_L4_FM) {
  254. trace_seq_printf(p, "mgmt pkt");
  255. goto out;
  256. }
  257. switch (opcode) {
  258. /* imm */
  259. case OP(RC, SEND_LAST_WITH_IMMEDIATE):
  260. case OP(UC, SEND_LAST_WITH_IMMEDIATE):
  261. case OP(RC, SEND_ONLY_WITH_IMMEDIATE):
  262. case OP(UC, SEND_ONLY_WITH_IMMEDIATE):
  263. case OP(RC, RDMA_WRITE_LAST_WITH_IMMEDIATE):
  264. case OP(UC, RDMA_WRITE_LAST_WITH_IMMEDIATE):
  265. trace_seq_printf(p, IMM_PRN,
  266. be32_to_cpu(eh->imm_data));
  267. break;
  268. /* reth + imm */
  269. case OP(RC, RDMA_WRITE_ONLY_WITH_IMMEDIATE):
  270. case OP(UC, RDMA_WRITE_ONLY_WITH_IMMEDIATE):
  271. trace_seq_printf(p, RETH_PRN " " IMM_PRN,
  272. get_ib_reth_vaddr(&eh->rc.reth),
  273. be32_to_cpu(eh->rc.reth.rkey),
  274. be32_to_cpu(eh->rc.reth.length),
  275. be32_to_cpu(eh->rc.imm_data));
  276. break;
  277. /* reth */
  278. case OP(RC, RDMA_READ_REQUEST):
  279. case OP(RC, RDMA_WRITE_FIRST):
  280. case OP(UC, RDMA_WRITE_FIRST):
  281. case OP(RC, RDMA_WRITE_ONLY):
  282. case OP(UC, RDMA_WRITE_ONLY):
  283. trace_seq_printf(p, RETH_PRN,
  284. get_ib_reth_vaddr(&eh->rc.reth),
  285. be32_to_cpu(eh->rc.reth.rkey),
  286. be32_to_cpu(eh->rc.reth.length));
  287. break;
  288. case OP(RC, RDMA_READ_RESPONSE_FIRST):
  289. case OP(RC, RDMA_READ_RESPONSE_LAST):
  290. case OP(RC, RDMA_READ_RESPONSE_ONLY):
  291. case OP(RC, ACKNOWLEDGE):
  292. trace_seq_printf(p, AETH_PRN, be32_to_cpu(eh->aeth) >> 24,
  293. parse_syndrome(be32_to_cpu(eh->aeth) >> 24),
  294. be32_to_cpu(eh->aeth) & IB_MSN_MASK);
  295. break;
  296. /* aeth + atomicacketh */
  297. case OP(RC, ATOMIC_ACKNOWLEDGE):
  298. trace_seq_printf(p, AETH_PRN " " ATOMICACKETH_PRN,
  299. be32_to_cpu(eh->at.aeth) >> 24,
  300. parse_syndrome(be32_to_cpu(eh->at.aeth) >> 24),
  301. be32_to_cpu(eh->at.aeth) & IB_MSN_MASK,
  302. ib_u64_get(&eh->at.atomic_ack_eth));
  303. break;
  304. /* atomiceth */
  305. case OP(RC, COMPARE_SWAP):
  306. case OP(RC, FETCH_ADD):
  307. trace_seq_printf(p, ATOMICETH_PRN,
  308. get_ib_ateth_vaddr(&eh->atomic_eth),
  309. eh->atomic_eth.rkey,
  310. get_ib_ateth_swap(&eh->atomic_eth),
  311. get_ib_ateth_compare(&eh->atomic_eth));
  312. break;
  313. /* deth */
  314. case OP(UD, SEND_ONLY):
  315. case OP(UD, SEND_ONLY_WITH_IMMEDIATE):
  316. trace_seq_printf(p, DETH_PRN,
  317. be32_to_cpu(eh->ud.deth[0]),
  318. be32_to_cpu(eh->ud.deth[1]) & RVT_QPN_MASK);
  319. break;
  320. /* ieth */
  321. case OP(RC, SEND_LAST_WITH_INVALIDATE):
  322. case OP(RC, SEND_ONLY_WITH_INVALIDATE):
  323. trace_seq_printf(p, IETH_PRN,
  324. be32_to_cpu(eh->ieth));
  325. break;
  326. }
  327. out:
  328. trace_seq_putc(p, 0);
  329. return ret;
  330. }
  331. const char *parse_sdma_flags(
  332. struct trace_seq *p,
  333. u64 desc0, u64 desc1)
  334. {
  335. const char *ret = trace_seq_buffer_ptr(p);
  336. char flags[5] = { 'x', 'x', 'x', 'x', 0 };
  337. flags[0] = (desc1 & SDMA_DESC1_INT_REQ_FLAG) ? 'I' : '-';
  338. flags[1] = (desc1 & SDMA_DESC1_HEAD_TO_HOST_FLAG) ? 'H' : '-';
  339. flags[2] = (desc0 & SDMA_DESC0_FIRST_DESC_FLAG) ? 'F' : '-';
  340. flags[3] = (desc0 & SDMA_DESC0_LAST_DESC_FLAG) ? 'L' : '-';
  341. trace_seq_printf(p, "%s", flags);
  342. if (desc0 & SDMA_DESC0_FIRST_DESC_FLAG)
  343. trace_seq_printf(p, " amode:%u aidx:%u alen:%u",
  344. (u8)((desc1 >> SDMA_DESC1_HEADER_MODE_SHIFT) &
  345. SDMA_DESC1_HEADER_MODE_MASK),
  346. (u8)((desc1 >> SDMA_DESC1_HEADER_INDEX_SHIFT) &
  347. SDMA_DESC1_HEADER_INDEX_MASK),
  348. (u8)((desc1 >> SDMA_DESC1_HEADER_DWS_SHIFT) &
  349. SDMA_DESC1_HEADER_DWS_MASK));
  350. return ret;
  351. }
  352. const char *print_u32_array(
  353. struct trace_seq *p,
  354. u32 *arr, int len)
  355. {
  356. int i;
  357. const char *ret = trace_seq_buffer_ptr(p);
  358. for (i = 0; i < len ; i++)
  359. trace_seq_printf(p, "%s%#x", i == 0 ? "" : " ", arr[i]);
  360. trace_seq_putc(p, 0);
  361. return ret;
  362. }
  363. __hfi1_trace_fn(AFFINITY);
  364. __hfi1_trace_fn(PKT);
  365. __hfi1_trace_fn(PROC);
  366. __hfi1_trace_fn(SDMA);
  367. __hfi1_trace_fn(LINKVERB);
  368. __hfi1_trace_fn(DEBUG);
  369. __hfi1_trace_fn(SNOOP);
  370. __hfi1_trace_fn(CNTR);
  371. __hfi1_trace_fn(PIO);
  372. __hfi1_trace_fn(DC8051);
  373. __hfi1_trace_fn(FIRMWARE);
  374. __hfi1_trace_fn(RCVCTRL);
  375. __hfi1_trace_fn(TID);
  376. __hfi1_trace_fn(MMU);
  377. __hfi1_trace_fn(IOCTL);