coredump.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2022 Google Corporation
  4. */
  5. #ifndef __COREDUMP_H
  6. #define __COREDUMP_H
  7. #define DEVCOREDUMP_TIMEOUT msecs_to_jiffies(10000) /* 10 sec */
  8. typedef void (*coredump_t)(struct hci_dev *hdev);
  9. typedef void (*dmp_hdr_t)(struct hci_dev *hdev, struct sk_buff *skb);
  10. typedef void (*notify_change_t)(struct hci_dev *hdev, int state);
  11. /* struct hci_devcoredump - Devcoredump state
  12. *
  13. * @supported: Indicates if FW dump collection is supported by driver
  14. * @state: Current state of dump collection
  15. * @timeout: Indicates a timeout for collecting the devcoredump
  16. *
  17. * @alloc_size: Total size of the dump
  18. * @head: Start of the dump
  19. * @tail: Pointer to current end of dump
  20. * @end: head + alloc_size for easy comparisons
  21. *
  22. * @dump_q: Dump queue for state machine to process
  23. * @dump_rx: Devcoredump state machine work
  24. * @dump_timeout: Devcoredump timeout work
  25. *
  26. * @coredump: Called from the driver's .coredump() function.
  27. * @dmp_hdr: Create a dump header to identify controller/fw/driver info
  28. * @notify_change: Notify driver when devcoredump state has changed
  29. */
  30. struct hci_devcoredump {
  31. bool supported;
  32. enum devcoredump_state {
  33. HCI_DEVCOREDUMP_IDLE,
  34. HCI_DEVCOREDUMP_ACTIVE,
  35. HCI_DEVCOREDUMP_DONE,
  36. HCI_DEVCOREDUMP_ABORT,
  37. HCI_DEVCOREDUMP_TIMEOUT,
  38. } state;
  39. unsigned long timeout;
  40. size_t alloc_size;
  41. char *head;
  42. char *tail;
  43. char *end;
  44. struct sk_buff_head dump_q;
  45. struct work_struct dump_rx;
  46. struct delayed_work dump_timeout;
  47. coredump_t coredump;
  48. dmp_hdr_t dmp_hdr;
  49. notify_change_t notify_change;
  50. };
  51. #ifdef CONFIG_DEV_COREDUMP
  52. void hci_devcd_reset(struct hci_dev *hdev);
  53. void hci_devcd_rx(struct work_struct *work);
  54. void hci_devcd_timeout(struct work_struct *work);
  55. int hci_devcd_register(struct hci_dev *hdev, coredump_t coredump,
  56. dmp_hdr_t dmp_hdr, notify_change_t notify_change);
  57. int hci_devcd_init(struct hci_dev *hdev, u32 dump_size);
  58. int hci_devcd_append(struct hci_dev *hdev, struct sk_buff *skb);
  59. int hci_devcd_append_pattern(struct hci_dev *hdev, u8 pattern, u32 len);
  60. int hci_devcd_complete(struct hci_dev *hdev);
  61. int hci_devcd_abort(struct hci_dev *hdev);
  62. #else
  63. static inline void hci_devcd_reset(struct hci_dev *hdev) {}
  64. static inline void hci_devcd_rx(struct work_struct *work) {}
  65. static inline void hci_devcd_timeout(struct work_struct *work) {}
  66. static inline int hci_devcd_register(struct hci_dev *hdev, coredump_t coredump,
  67. dmp_hdr_t dmp_hdr,
  68. notify_change_t notify_change)
  69. {
  70. return -EOPNOTSUPP;
  71. }
  72. static inline int hci_devcd_init(struct hci_dev *hdev, u32 dump_size)
  73. {
  74. return -EOPNOTSUPP;
  75. }
  76. static inline int hci_devcd_append(struct hci_dev *hdev, struct sk_buff *skb)
  77. {
  78. return -EOPNOTSUPP;
  79. }
  80. static inline int hci_devcd_append_pattern(struct hci_dev *hdev,
  81. u8 pattern, u32 len)
  82. {
  83. return -EOPNOTSUPP;
  84. }
  85. static inline int hci_devcd_complete(struct hci_dev *hdev)
  86. {
  87. return -EOPNOTSUPP;
  88. }
  89. static inline int hci_devcd_abort(struct hci_dev *hdev)
  90. {
  91. return -EOPNOTSUPP;
  92. }
  93. #endif /* CONFIG_DEV_COREDUMP */
  94. #endif /* __COREDUMP_H */