state_dump.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright 2021 HabanaLabs, Ltd.
  4. * All Rights Reserved.
  5. */
  6. #include <linux/vmalloc.h>
  7. #include <uapi/misc/habanalabs.h>
  8. #include "habanalabs.h"
  9. /**
  10. * hl_format_as_binary - helper function, format an integer as binary
  11. * using supplied scratch buffer
  12. * @buf: the buffer to use
  13. * @buf_len: buffer capacity
  14. * @n: number to format
  15. *
  16. * Returns pointer to buffer
  17. */
  18. char *hl_format_as_binary(char *buf, size_t buf_len, u32 n)
  19. {
  20. int i;
  21. u32 bit;
  22. bool leading0 = true;
  23. char *wrptr = buf;
  24. if (buf_len > 0 && buf_len < 3) {
  25. *wrptr = '\0';
  26. return buf;
  27. }
  28. wrptr[0] = '0';
  29. wrptr[1] = 'b';
  30. wrptr += 2;
  31. /* Remove 3 characters from length for '0b' and '\0' termination */
  32. buf_len -= 3;
  33. for (i = 0; i < sizeof(n) * BITS_PER_BYTE && buf_len; ++i, n <<= 1) {
  34. /* Writing bit calculation in one line would cause a false
  35. * positive static code analysis error, so splitting.
  36. */
  37. bit = n & (1 << (sizeof(n) * BITS_PER_BYTE - 1));
  38. bit = !!bit;
  39. leading0 &= !bit;
  40. if (!leading0) {
  41. *wrptr = '0' + bit;
  42. ++wrptr;
  43. }
  44. }
  45. *wrptr = '\0';
  46. return buf;
  47. }
  48. /**
  49. * resize_to_fit - helper function, resize buffer to fit given amount of data
  50. * @buf: destination buffer double pointer
  51. * @size: pointer to the size container
  52. * @desired_size: size the buffer must contain
  53. *
  54. * Returns 0 on success or error code on failure.
  55. * On success, the size of buffer is at least desired_size. Buffer is allocated
  56. * via vmalloc and must be freed with vfree.
  57. */
  58. static int resize_to_fit(char **buf, size_t *size, size_t desired_size)
  59. {
  60. char *resized_buf;
  61. size_t new_size;
  62. if (*size >= desired_size)
  63. return 0;
  64. /* Not enough space to print all, have to resize */
  65. new_size = max_t(size_t, PAGE_SIZE, round_up(desired_size, PAGE_SIZE));
  66. resized_buf = vmalloc(new_size);
  67. if (!resized_buf)
  68. return -ENOMEM;
  69. memcpy(resized_buf, *buf, *size);
  70. vfree(*buf);
  71. *buf = resized_buf;
  72. *size = new_size;
  73. return 1;
  74. }
  75. /**
  76. * hl_snprintf_resize() - print formatted data to buffer, resize as needed
  77. * @buf: buffer double pointer, to be written to and resized, must be either
  78. * NULL or allocated with vmalloc.
  79. * @size: current size of the buffer
  80. * @offset: current offset to write to
  81. * @format: format of the data
  82. *
  83. * This function will write formatted data into the buffer. If buffer is not
  84. * large enough, it will be resized using vmalloc. Size may be modified if the
  85. * buffer was resized, offset will be advanced by the number of bytes written
  86. * not including the terminating character
  87. *
  88. * Returns 0 on success or error code on failure
  89. *
  90. * Note that the buffer has to be manually released using vfree.
  91. */
  92. int hl_snprintf_resize(char **buf, size_t *size, size_t *offset,
  93. const char *format, ...)
  94. {
  95. va_list args;
  96. size_t length;
  97. int rc;
  98. if (*buf == NULL && (*size != 0 || *offset != 0))
  99. return -EINVAL;
  100. va_start(args, format);
  101. length = vsnprintf(*buf + *offset, *size - *offset, format, args);
  102. va_end(args);
  103. rc = resize_to_fit(buf, size, *offset + length + 1);
  104. if (rc < 0)
  105. return rc;
  106. else if (rc > 0) {
  107. /* Resize was needed, write again */
  108. va_start(args, format);
  109. length = vsnprintf(*buf + *offset, *size - *offset, format,
  110. args);
  111. va_end(args);
  112. }
  113. *offset += length;
  114. return 0;
  115. }
  116. /**
  117. * hl_sync_engine_to_string - convert engine type enum to string literal
  118. * @engine_type: engine type (TPC/MME/DMA)
  119. *
  120. * Return the resolved string literal
  121. */
  122. const char *hl_sync_engine_to_string(enum hl_sync_engine_type engine_type)
  123. {
  124. switch (engine_type) {
  125. case ENGINE_DMA:
  126. return "DMA";
  127. case ENGINE_MME:
  128. return "MME";
  129. case ENGINE_TPC:
  130. return "TPC";
  131. }
  132. return "Invalid Engine Type";
  133. }
  134. /**
  135. * hl_print_resize_sync_engine - helper function, format engine name and ID
  136. * using hl_snprintf_resize
  137. * @buf: destination buffer double pointer to be used with hl_snprintf_resize
  138. * @size: pointer to the size container
  139. * @offset: pointer to the offset container
  140. * @engine_type: engine type (TPC/MME/DMA)
  141. * @engine_id: engine numerical id
  142. *
  143. * Returns 0 on success or error code on failure
  144. */
  145. static int hl_print_resize_sync_engine(char **buf, size_t *size, size_t *offset,
  146. enum hl_sync_engine_type engine_type,
  147. u32 engine_id)
  148. {
  149. return hl_snprintf_resize(buf, size, offset, "%s%u",
  150. hl_sync_engine_to_string(engine_type), engine_id);
  151. }
  152. /**
  153. * hl_state_dump_get_sync_name - transform sync object id to name if available
  154. * @hdev: pointer to the device
  155. * @sync_id: sync object id
  156. *
  157. * Returns a name literal or NULL if not resolved.
  158. * Note: returning NULL shall not be considered as a failure, as not all
  159. * sync objects are named.
  160. */
  161. const char *hl_state_dump_get_sync_name(struct hl_device *hdev, u32 sync_id)
  162. {
  163. struct hl_state_dump_specs *sds = &hdev->state_dump_specs;
  164. struct hl_hw_obj_name_entry *entry;
  165. hash_for_each_possible(sds->so_id_to_str_tb, entry,
  166. node, sync_id)
  167. if (sync_id == entry->id)
  168. return entry->name;
  169. return NULL;
  170. }
  171. /**
  172. * hl_state_dump_get_monitor_name - transform monitor object dump to monitor
  173. * name if available
  174. * @hdev: pointer to the device
  175. * @mon: monitor state dump
  176. *
  177. * Returns a name literal or NULL if not resolved.
  178. * Note: returning NULL shall not be considered as a failure, as not all
  179. * monitors are named.
  180. */
  181. const char *hl_state_dump_get_monitor_name(struct hl_device *hdev,
  182. struct hl_mon_state_dump *mon)
  183. {
  184. struct hl_state_dump_specs *sds = &hdev->state_dump_specs;
  185. struct hl_hw_obj_name_entry *entry;
  186. hash_for_each_possible(sds->monitor_id_to_str_tb,
  187. entry, node, mon->id)
  188. if (mon->id == entry->id)
  189. return entry->name;
  190. return NULL;
  191. }
  192. /**
  193. * hl_state_dump_free_sync_to_engine_map - free sync object to engine map
  194. * @map: sync object to engine map
  195. *
  196. * Note: generic free implementation, the allocation is implemented per ASIC.
  197. */
  198. void hl_state_dump_free_sync_to_engine_map(struct hl_sync_to_engine_map *map)
  199. {
  200. struct hl_sync_to_engine_map_entry *entry;
  201. struct hlist_node *tmp_node;
  202. int i;
  203. hash_for_each_safe(map->tb, i, tmp_node, entry, node) {
  204. hash_del(&entry->node);
  205. kfree(entry);
  206. }
  207. }
  208. /**
  209. * hl_state_dump_get_sync_to_engine - transform sync_id to
  210. * hl_sync_to_engine_map_entry if available for current id
  211. * @map: sync object to engine map
  212. * @sync_id: sync object id
  213. *
  214. * Returns the translation entry if found or NULL if not.
  215. * Note, returned NULL shall not be considered as a failure as the map
  216. * does not cover all possible, it is a best effort sync ids.
  217. */
  218. static struct hl_sync_to_engine_map_entry *
  219. hl_state_dump_get_sync_to_engine(struct hl_sync_to_engine_map *map, u32 sync_id)
  220. {
  221. struct hl_sync_to_engine_map_entry *entry;
  222. hash_for_each_possible(map->tb, entry, node, sync_id)
  223. if (entry->sync_id == sync_id)
  224. return entry;
  225. return NULL;
  226. }
  227. /**
  228. * hl_state_dump_read_sync_objects - read sync objects array
  229. * @hdev: pointer to the device
  230. * @index: sync manager block index starting with E_N
  231. *
  232. * Returns array of size SP_SYNC_OBJ_AMOUNT on success or NULL on failure
  233. */
  234. static u32 *hl_state_dump_read_sync_objects(struct hl_device *hdev, u32 index)
  235. {
  236. struct hl_state_dump_specs *sds = &hdev->state_dump_specs;
  237. u32 *sync_objects;
  238. s64 base_addr; /* Base addr can be negative */
  239. int i;
  240. base_addr = sds->props[SP_SYNC_OBJ_BASE_ADDR] +
  241. sds->props[SP_NEXT_SYNC_OBJ_ADDR] * index;
  242. sync_objects = vmalloc(sds->props[SP_SYNC_OBJ_AMOUNT] * sizeof(u32));
  243. if (!sync_objects)
  244. return NULL;
  245. for (i = 0; i < sds->props[SP_SYNC_OBJ_AMOUNT]; ++i)
  246. sync_objects[i] = RREG32(base_addr + i * sizeof(u32));
  247. return sync_objects;
  248. }
  249. /**
  250. * hl_state_dump_free_sync_objects - free sync objects array allocated by
  251. * hl_state_dump_read_sync_objects
  252. * @sync_objects: sync objects array
  253. */
  254. static void hl_state_dump_free_sync_objects(u32 *sync_objects)
  255. {
  256. vfree(sync_objects);
  257. }
  258. /**
  259. * hl_state_dump_print_syncs_single_block - print active sync objects on a
  260. * single block
  261. * @hdev: pointer to the device
  262. * @index: sync manager block index starting with E_N
  263. * @buf: destination buffer double pointer to be used with hl_snprintf_resize
  264. * @size: pointer to the size container
  265. * @offset: pointer to the offset container
  266. * @map: sync engines names map
  267. *
  268. * Returns 0 on success or error code on failure
  269. */
  270. static int
  271. hl_state_dump_print_syncs_single_block(struct hl_device *hdev, u32 index,
  272. char **buf, size_t *size, size_t *offset,
  273. struct hl_sync_to_engine_map *map)
  274. {
  275. struct hl_state_dump_specs *sds = &hdev->state_dump_specs;
  276. const char *sync_name;
  277. u32 *sync_objects = NULL;
  278. int rc = 0, i;
  279. if (sds->sync_namager_names) {
  280. rc = hl_snprintf_resize(
  281. buf, size, offset, "%s\n",
  282. sds->sync_namager_names[index]);
  283. if (rc)
  284. goto out;
  285. }
  286. sync_objects = hl_state_dump_read_sync_objects(hdev, index);
  287. if (!sync_objects) {
  288. rc = -ENOMEM;
  289. goto out;
  290. }
  291. for (i = 0; i < sds->props[SP_SYNC_OBJ_AMOUNT]; ++i) {
  292. struct hl_sync_to_engine_map_entry *entry;
  293. u64 sync_object_addr;
  294. if (!sync_objects[i])
  295. continue;
  296. sync_object_addr = sds->props[SP_SYNC_OBJ_BASE_ADDR] +
  297. sds->props[SP_NEXT_SYNC_OBJ_ADDR] * index +
  298. i * sizeof(u32);
  299. rc = hl_snprintf_resize(buf, size, offset, "sync id: %u", i);
  300. if (rc)
  301. goto free_sync_objects;
  302. sync_name = hl_state_dump_get_sync_name(hdev, i);
  303. if (sync_name) {
  304. rc = hl_snprintf_resize(buf, size, offset, " %s",
  305. sync_name);
  306. if (rc)
  307. goto free_sync_objects;
  308. }
  309. rc = hl_snprintf_resize(buf, size, offset, ", value: %u",
  310. sync_objects[i]);
  311. if (rc)
  312. goto free_sync_objects;
  313. /* Append engine string */
  314. entry = hl_state_dump_get_sync_to_engine(map,
  315. (u32)sync_object_addr);
  316. if (entry) {
  317. rc = hl_snprintf_resize(buf, size, offset,
  318. ", Engine: ");
  319. if (rc)
  320. goto free_sync_objects;
  321. rc = hl_print_resize_sync_engine(buf, size, offset,
  322. entry->engine_type,
  323. entry->engine_id);
  324. if (rc)
  325. goto free_sync_objects;
  326. }
  327. rc = hl_snprintf_resize(buf, size, offset, "\n");
  328. if (rc)
  329. goto free_sync_objects;
  330. }
  331. free_sync_objects:
  332. hl_state_dump_free_sync_objects(sync_objects);
  333. out:
  334. return rc;
  335. }
  336. /**
  337. * hl_state_dump_print_syncs - print active sync objects
  338. * @hdev: pointer to the device
  339. * @buf: destination buffer double pointer to be used with hl_snprintf_resize
  340. * @size: pointer to the size container
  341. * @offset: pointer to the offset container
  342. *
  343. * Returns 0 on success or error code on failure
  344. */
  345. static int hl_state_dump_print_syncs(struct hl_device *hdev,
  346. char **buf, size_t *size,
  347. size_t *offset)
  348. {
  349. struct hl_state_dump_specs *sds = &hdev->state_dump_specs;
  350. struct hl_sync_to_engine_map *map;
  351. u32 index;
  352. int rc = 0;
  353. map = kzalloc(sizeof(*map), GFP_KERNEL);
  354. if (!map)
  355. return -ENOMEM;
  356. rc = sds->funcs.gen_sync_to_engine_map(hdev, map);
  357. if (rc)
  358. goto free_map_mem;
  359. rc = hl_snprintf_resize(buf, size, offset, "Non zero sync objects:\n");
  360. if (rc)
  361. goto out;
  362. if (sds->sync_namager_names) {
  363. for (index = 0; sds->sync_namager_names[index]; ++index) {
  364. rc = hl_state_dump_print_syncs_single_block(
  365. hdev, index, buf, size, offset, map);
  366. if (rc)
  367. goto out;
  368. }
  369. } else {
  370. for (index = 0; index < sds->props[SP_NUM_CORES]; ++index) {
  371. rc = hl_state_dump_print_syncs_single_block(
  372. hdev, index, buf, size, offset, map);
  373. if (rc)
  374. goto out;
  375. }
  376. }
  377. out:
  378. hl_state_dump_free_sync_to_engine_map(map);
  379. free_map_mem:
  380. kfree(map);
  381. return rc;
  382. }
  383. /**
  384. * hl_state_dump_alloc_read_sm_block_monitors - read monitors for a specific
  385. * block
  386. * @hdev: pointer to the device
  387. * @index: sync manager block index starting with E_N
  388. *
  389. * Returns an array of monitor data of size SP_MONITORS_AMOUNT or NULL
  390. * on error
  391. */
  392. static struct hl_mon_state_dump *
  393. hl_state_dump_alloc_read_sm_block_monitors(struct hl_device *hdev, u32 index)
  394. {
  395. struct hl_state_dump_specs *sds = &hdev->state_dump_specs;
  396. struct hl_mon_state_dump *monitors;
  397. s64 base_addr; /* Base addr can be negative */
  398. int i;
  399. monitors = vmalloc(sds->props[SP_MONITORS_AMOUNT] *
  400. sizeof(struct hl_mon_state_dump));
  401. if (!monitors)
  402. return NULL;
  403. base_addr = sds->props[SP_NEXT_SYNC_OBJ_ADDR] * index;
  404. for (i = 0; i < sds->props[SP_MONITORS_AMOUNT]; ++i) {
  405. monitors[i].id = i;
  406. monitors[i].wr_addr_low =
  407. RREG32(base_addr + sds->props[SP_MON_OBJ_WR_ADDR_LOW] +
  408. i * sizeof(u32));
  409. monitors[i].wr_addr_high =
  410. RREG32(base_addr + sds->props[SP_MON_OBJ_WR_ADDR_HIGH] +
  411. i * sizeof(u32));
  412. monitors[i].wr_data =
  413. RREG32(base_addr + sds->props[SP_MON_OBJ_WR_DATA] +
  414. i * sizeof(u32));
  415. monitors[i].arm_data =
  416. RREG32(base_addr + sds->props[SP_MON_OBJ_ARM_DATA] +
  417. i * sizeof(u32));
  418. monitors[i].status =
  419. RREG32(base_addr + sds->props[SP_MON_OBJ_STATUS] +
  420. i * sizeof(u32));
  421. }
  422. return monitors;
  423. }
  424. /**
  425. * hl_state_dump_free_monitors - free the monitors structure
  426. * @monitors: monitors array created with
  427. * hl_state_dump_alloc_read_sm_block_monitors
  428. */
  429. static void hl_state_dump_free_monitors(struct hl_mon_state_dump *monitors)
  430. {
  431. vfree(monitors);
  432. }
  433. /**
  434. * hl_state_dump_print_monitors_single_block - print active monitors on a
  435. * single block
  436. * @hdev: pointer to the device
  437. * @index: sync manager block index starting with E_N
  438. * @buf: destination buffer double pointer to be used with hl_snprintf_resize
  439. * @size: pointer to the size container
  440. * @offset: pointer to the offset container
  441. *
  442. * Returns 0 on success or error code on failure
  443. */
  444. static int hl_state_dump_print_monitors_single_block(struct hl_device *hdev,
  445. u32 index,
  446. char **buf, size_t *size,
  447. size_t *offset)
  448. {
  449. struct hl_state_dump_specs *sds = &hdev->state_dump_specs;
  450. struct hl_mon_state_dump *monitors = NULL;
  451. int rc = 0, i;
  452. if (sds->sync_namager_names) {
  453. rc = hl_snprintf_resize(
  454. buf, size, offset, "%s\n",
  455. sds->sync_namager_names[index]);
  456. if (rc)
  457. goto out;
  458. }
  459. monitors = hl_state_dump_alloc_read_sm_block_monitors(hdev, index);
  460. if (!monitors) {
  461. rc = -ENOMEM;
  462. goto out;
  463. }
  464. for (i = 0; i < sds->props[SP_MONITORS_AMOUNT]; ++i) {
  465. if (!(sds->funcs.monitor_valid(&monitors[i])))
  466. continue;
  467. /* Monitor is valid, dump it */
  468. rc = sds->funcs.print_single_monitor(buf, size, offset, hdev,
  469. &monitors[i]);
  470. if (rc)
  471. goto free_monitors;
  472. hl_snprintf_resize(buf, size, offset, "\n");
  473. }
  474. free_monitors:
  475. hl_state_dump_free_monitors(monitors);
  476. out:
  477. return rc;
  478. }
  479. /**
  480. * hl_state_dump_print_monitors - print active monitors
  481. * @hdev: pointer to the device
  482. * @buf: destination buffer double pointer to be used with hl_snprintf_resize
  483. * @size: pointer to the size container
  484. * @offset: pointer to the offset container
  485. *
  486. * Returns 0 on success or error code on failure
  487. */
  488. static int hl_state_dump_print_monitors(struct hl_device *hdev,
  489. char **buf, size_t *size,
  490. size_t *offset)
  491. {
  492. struct hl_state_dump_specs *sds = &hdev->state_dump_specs;
  493. u32 index;
  494. int rc = 0;
  495. rc = hl_snprintf_resize(buf, size, offset,
  496. "Valid (armed) monitor objects:\n");
  497. if (rc)
  498. goto out;
  499. if (sds->sync_namager_names) {
  500. for (index = 0; sds->sync_namager_names[index]; ++index) {
  501. rc = hl_state_dump_print_monitors_single_block(
  502. hdev, index, buf, size, offset);
  503. if (rc)
  504. goto out;
  505. }
  506. } else {
  507. for (index = 0; index < sds->props[SP_NUM_CORES]; ++index) {
  508. rc = hl_state_dump_print_monitors_single_block(
  509. hdev, index, buf, size, offset);
  510. if (rc)
  511. goto out;
  512. }
  513. }
  514. out:
  515. return rc;
  516. }
  517. /**
  518. * hl_state_dump_print_engine_fences - print active fences for a specific
  519. * engine
  520. * @hdev: pointer to the device
  521. * @engine_type: engine type to use
  522. * @buf: destination buffer double pointer to be used with hl_snprintf_resize
  523. * @size: pointer to the size container
  524. * @offset: pointer to the offset container
  525. */
  526. static int
  527. hl_state_dump_print_engine_fences(struct hl_device *hdev,
  528. enum hl_sync_engine_type engine_type,
  529. char **buf, size_t *size, size_t *offset)
  530. {
  531. struct hl_state_dump_specs *sds = &hdev->state_dump_specs;
  532. int rc = 0, i, n_fences;
  533. u64 base_addr, next_fence;
  534. switch (engine_type) {
  535. case ENGINE_TPC:
  536. n_fences = sds->props[SP_NUM_OF_TPC_ENGINES];
  537. base_addr = sds->props[SP_TPC0_CMDQ];
  538. next_fence = sds->props[SP_NEXT_TPC];
  539. break;
  540. case ENGINE_MME:
  541. n_fences = sds->props[SP_NUM_OF_MME_ENGINES];
  542. base_addr = sds->props[SP_MME_CMDQ];
  543. next_fence = sds->props[SP_NEXT_MME];
  544. break;
  545. case ENGINE_DMA:
  546. n_fences = sds->props[SP_NUM_OF_DMA_ENGINES];
  547. base_addr = sds->props[SP_DMA_CMDQ];
  548. next_fence = sds->props[SP_DMA_QUEUES_OFFSET];
  549. break;
  550. default:
  551. return -EINVAL;
  552. }
  553. for (i = 0; i < n_fences; ++i) {
  554. rc = sds->funcs.print_fences_single_engine(
  555. hdev,
  556. base_addr + next_fence * i +
  557. sds->props[SP_FENCE0_CNT_OFFSET],
  558. base_addr + next_fence * i +
  559. sds->props[SP_CP_STS_OFFSET],
  560. engine_type, i, buf, size, offset);
  561. if (rc)
  562. goto out;
  563. }
  564. out:
  565. return rc;
  566. }
  567. /**
  568. * hl_state_dump_print_fences - print active fences
  569. * @hdev: pointer to the device
  570. * @buf: destination buffer double pointer to be used with hl_snprintf_resize
  571. * @size: pointer to the size container
  572. * @offset: pointer to the offset container
  573. */
  574. static int hl_state_dump_print_fences(struct hl_device *hdev, char **buf,
  575. size_t *size, size_t *offset)
  576. {
  577. int rc = 0;
  578. rc = hl_snprintf_resize(buf, size, offset, "Valid (armed) fences:\n");
  579. if (rc)
  580. goto out;
  581. rc = hl_state_dump_print_engine_fences(hdev, ENGINE_TPC, buf, size, offset);
  582. if (rc)
  583. goto out;
  584. rc = hl_state_dump_print_engine_fences(hdev, ENGINE_MME, buf, size, offset);
  585. if (rc)
  586. goto out;
  587. rc = hl_state_dump_print_engine_fences(hdev, ENGINE_DMA, buf, size, offset);
  588. if (rc)
  589. goto out;
  590. out:
  591. return rc;
  592. }
  593. /**
  594. * hl_state_dump() - dump system state
  595. * @hdev: pointer to device structure
  596. */
  597. int hl_state_dump(struct hl_device *hdev)
  598. {
  599. char *buf = NULL;
  600. size_t offset = 0, size = 0;
  601. int rc;
  602. rc = hl_snprintf_resize(&buf, &size, &offset,
  603. "Timestamp taken on: %llu\n\n",
  604. ktime_to_ns(ktime_get()));
  605. if (rc)
  606. goto err;
  607. rc = hl_state_dump_print_syncs(hdev, &buf, &size, &offset);
  608. if (rc)
  609. goto err;
  610. hl_snprintf_resize(&buf, &size, &offset, "\n");
  611. rc = hl_state_dump_print_monitors(hdev, &buf, &size, &offset);
  612. if (rc)
  613. goto err;
  614. hl_snprintf_resize(&buf, &size, &offset, "\n");
  615. rc = hl_state_dump_print_fences(hdev, &buf, &size, &offset);
  616. if (rc)
  617. goto err;
  618. hl_snprintf_resize(&buf, &size, &offset, "\n");
  619. hl_debugfs_set_state_dump(hdev, buf, size);
  620. return 0;
  621. err:
  622. vfree(buf);
  623. return rc;
  624. }