scsi_logging.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _SCSI_LOGGING_H
  3. #define _SCSI_LOGGING_H
  4. /*
  5. * This defines the scsi logging feature. It is a means by which the user can
  6. * select how much information they get about various goings on, and it can be
  7. * really useful for fault tracing. The logging word is divided into 10 3-bit
  8. * bitfields, each of which describes a loglevel. The division of things is
  9. * somewhat arbitrary, and the division of the word could be changed if it
  10. * were really needed for any reason. The numbers below are the only place
  11. * where these are specified. For a first go-around, 3 bits is more than
  12. * enough, since this gives 8 levels of logging (really 7, since 0 is always
  13. * off). Cutting to 2 bits might be wise at some point.
  14. */
  15. #define SCSI_LOG_ERROR_SHIFT 0
  16. #define SCSI_LOG_TIMEOUT_SHIFT 3
  17. #define SCSI_LOG_SCAN_SHIFT 6
  18. #define SCSI_LOG_MLQUEUE_SHIFT 9
  19. #define SCSI_LOG_MLCOMPLETE_SHIFT 12
  20. #define SCSI_LOG_LLQUEUE_SHIFT 15
  21. #define SCSI_LOG_LLCOMPLETE_SHIFT 18
  22. #define SCSI_LOG_HLQUEUE_SHIFT 21
  23. #define SCSI_LOG_HLCOMPLETE_SHIFT 24
  24. #define SCSI_LOG_IOCTL_SHIFT 27
  25. #define SCSI_LOG_ERROR_BITS 3
  26. #define SCSI_LOG_TIMEOUT_BITS 3
  27. #define SCSI_LOG_SCAN_BITS 3
  28. #define SCSI_LOG_MLQUEUE_BITS 3
  29. #define SCSI_LOG_MLCOMPLETE_BITS 3
  30. #define SCSI_LOG_LLQUEUE_BITS 3
  31. #define SCSI_LOG_LLCOMPLETE_BITS 3
  32. #define SCSI_LOG_HLQUEUE_BITS 3
  33. #define SCSI_LOG_HLCOMPLETE_BITS 3
  34. #define SCSI_LOG_IOCTL_BITS 3
  35. extern unsigned int scsi_logging_level;
  36. #ifdef CONFIG_SCSI_LOGGING
  37. #define SCSI_LOG_LEVEL(SHIFT, BITS) \
  38. ((scsi_logging_level >> (SHIFT)) & ((1 << (BITS)) - 1))
  39. #define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) \
  40. do { \
  41. if (unlikely((SCSI_LOG_LEVEL(SHIFT, BITS)) > (LEVEL))) \
  42. do { \
  43. CMD; \
  44. } while (0); \
  45. } while (0)
  46. #else
  47. #define SCSI_LOG_LEVEL(SHIFT, BITS) 0
  48. #define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) do { } while (0)
  49. #endif /* CONFIG_SCSI_LOGGING */
  50. /*
  51. * These are the macros that are actually used throughout the code to
  52. * log events. If logging isn't enabled, they are no-ops and will be
  53. * completely absent from the user's code.
  54. */
  55. #define SCSI_LOG_ERROR_RECOVERY(LEVEL,CMD) \
  56. SCSI_CHECK_LOGGING(SCSI_LOG_ERROR_SHIFT, SCSI_LOG_ERROR_BITS, LEVEL,CMD);
  57. #define SCSI_LOG_TIMEOUT(LEVEL,CMD) \
  58. SCSI_CHECK_LOGGING(SCSI_LOG_TIMEOUT_SHIFT, SCSI_LOG_TIMEOUT_BITS, LEVEL,CMD);
  59. #define SCSI_LOG_SCAN_BUS(LEVEL,CMD) \
  60. SCSI_CHECK_LOGGING(SCSI_LOG_SCAN_SHIFT, SCSI_LOG_SCAN_BITS, LEVEL,CMD);
  61. #define SCSI_LOG_MLQUEUE(LEVEL,CMD) \
  62. SCSI_CHECK_LOGGING(SCSI_LOG_MLQUEUE_SHIFT, SCSI_LOG_MLQUEUE_BITS, LEVEL,CMD);
  63. #define SCSI_LOG_MLCOMPLETE(LEVEL,CMD) \
  64. SCSI_CHECK_LOGGING(SCSI_LOG_MLCOMPLETE_SHIFT, SCSI_LOG_MLCOMPLETE_BITS, LEVEL,CMD);
  65. #define SCSI_LOG_LLQUEUE(LEVEL,CMD) \
  66. SCSI_CHECK_LOGGING(SCSI_LOG_LLQUEUE_SHIFT, SCSI_LOG_LLQUEUE_BITS, LEVEL,CMD);
  67. #define SCSI_LOG_LLCOMPLETE(LEVEL,CMD) \
  68. SCSI_CHECK_LOGGING(SCSI_LOG_LLCOMPLETE_SHIFT, SCSI_LOG_LLCOMPLETE_BITS, LEVEL,CMD);
  69. #define SCSI_LOG_HLQUEUE(LEVEL,CMD) \
  70. SCSI_CHECK_LOGGING(SCSI_LOG_HLQUEUE_SHIFT, SCSI_LOG_HLQUEUE_BITS, LEVEL,CMD);
  71. #define SCSI_LOG_HLCOMPLETE(LEVEL,CMD) \
  72. SCSI_CHECK_LOGGING(SCSI_LOG_HLCOMPLETE_SHIFT, SCSI_LOG_HLCOMPLETE_BITS, LEVEL,CMD);
  73. #define SCSI_LOG_IOCTL(LEVEL,CMD) \
  74. SCSI_CHECK_LOGGING(SCSI_LOG_IOCTL_SHIFT, SCSI_LOG_IOCTL_BITS, LEVEL,CMD);
  75. #endif /* _SCSI_LOGGING_H */