trace.c 11 KB

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