util.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2016 Broadcom
  4. */
  5. #ifndef _UTIL_H
  6. #define _UTIL_H
  7. #include <linux/kernel.h>
  8. #include <linux/delay.h>
  9. #include "spu.h"
  10. extern int flow_debug_logging;
  11. extern int packet_debug_logging;
  12. extern int debug_logging_sleep;
  13. #ifdef DEBUG
  14. #define flow_log(...) \
  15. do { \
  16. if (flow_debug_logging) { \
  17. printk(__VA_ARGS__); \
  18. if (debug_logging_sleep) \
  19. msleep(debug_logging_sleep); \
  20. } \
  21. } while (0)
  22. #define flow_dump(msg, var, var_len) \
  23. do { \
  24. if (flow_debug_logging) { \
  25. print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE, \
  26. 16, 1, var, var_len, false); \
  27. if (debug_logging_sleep) \
  28. msleep(debug_logging_sleep); \
  29. } \
  30. } while (0)
  31. #define packet_log(...) \
  32. do { \
  33. if (packet_debug_logging) { \
  34. printk(__VA_ARGS__); \
  35. if (debug_logging_sleep) \
  36. msleep(debug_logging_sleep); \
  37. } \
  38. } while (0)
  39. #define packet_dump(msg, var, var_len) \
  40. do { \
  41. if (packet_debug_logging) { \
  42. print_hex_dump(KERN_ALERT, msg, DUMP_PREFIX_NONE, \
  43. 16, 1, var, var_len, false); \
  44. if (debug_logging_sleep) \
  45. msleep(debug_logging_sleep); \
  46. } \
  47. } while (0)
  48. void __dump_sg(struct scatterlist *sg, unsigned int skip, unsigned int len);
  49. #define dump_sg(sg, skip, len) __dump_sg(sg, skip, len)
  50. #else /* !DEBUG_ON */
  51. static inline void flow_log(const char *format, ...)
  52. {
  53. }
  54. static inline void flow_dump(const char *msg, const void *var, size_t var_len)
  55. {
  56. }
  57. static inline void packet_log(const char *format, ...)
  58. {
  59. }
  60. static inline void packet_dump(const char *msg, const void *var, size_t var_len)
  61. {
  62. }
  63. static inline void dump_sg(struct scatterlist *sg, unsigned int skip,
  64. unsigned int len)
  65. {
  66. }
  67. #endif /* DEBUG_ON */
  68. int spu_sg_at_offset(struct scatterlist *sg, unsigned int skip,
  69. struct scatterlist **sge, unsigned int *sge_offset);
  70. /* Copy sg data, from skip, length len, to dest */
  71. void sg_copy_part_to_buf(struct scatterlist *src, u8 *dest,
  72. unsigned int len, unsigned int skip);
  73. /* Copy src into scatterlist from offset, length len */
  74. void sg_copy_part_from_buf(struct scatterlist *dest, u8 *src,
  75. unsigned int len, unsigned int skip);
  76. int spu_sg_count(struct scatterlist *sg_list, unsigned int skip, int nbytes);
  77. u32 spu_msg_sg_add(struct scatterlist **to_sg,
  78. struct scatterlist **from_sg, u32 *skip,
  79. u8 from_nents, u32 tot_len);
  80. void add_to_ctr(u8 *ctr_pos, unsigned int increment);
  81. /* produce a message digest from data of length n bytes */
  82. int do_shash(unsigned char *name, unsigned char *result,
  83. const u8 *data1, unsigned int data1_len,
  84. const u8 *data2, unsigned int data2_len,
  85. const u8 *key, unsigned int key_len);
  86. char *spu_alg_name(enum spu_cipher_alg alg, enum spu_cipher_mode mode);
  87. void spu_setup_debugfs(void);
  88. void spu_free_debugfs(void);
  89. void format_value_ccm(unsigned int val, u8 *buf, u8 len);
  90. #endif