scm_blk.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #ifndef SCM_BLK_H
  2. #define SCM_BLK_H
  3. #include <linux/interrupt.h>
  4. #include <linux/spinlock.h>
  5. #include <linux/blkdev.h>
  6. #include <linux/genhd.h>
  7. #include <linux/list.h>
  8. #include <asm/debug.h>
  9. #include <asm/eadm.h>
  10. #define SCM_NR_PARTS 8
  11. #define SCM_QUEUE_DELAY 5
  12. struct scm_blk_dev {
  13. struct tasklet_struct tasklet;
  14. struct request_queue *rq;
  15. struct gendisk *gendisk;
  16. struct scm_device *scmdev;
  17. spinlock_t rq_lock; /* guard the request queue */
  18. spinlock_t lock; /* guard the rest of the blockdev */
  19. atomic_t queued_reqs;
  20. enum {SCM_OPER, SCM_WR_PROHIBIT} state;
  21. struct list_head finished_requests;
  22. #ifdef CONFIG_SCM_BLOCK_CLUSTER_WRITE
  23. struct list_head cluster_list;
  24. #endif
  25. };
  26. struct scm_request {
  27. struct scm_blk_dev *bdev;
  28. struct aidaw *next_aidaw;
  29. struct request **request;
  30. struct aob *aob;
  31. struct list_head list;
  32. u8 retries;
  33. int error;
  34. #ifdef CONFIG_SCM_BLOCK_CLUSTER_WRITE
  35. struct {
  36. enum {CLUSTER_NONE, CLUSTER_READ, CLUSTER_WRITE} state;
  37. struct list_head list;
  38. void **buf;
  39. } cluster;
  40. #endif
  41. };
  42. #define to_aobrq(rq) container_of((void *) rq, struct aob_rq_header, data)
  43. int scm_blk_dev_setup(struct scm_blk_dev *, struct scm_device *);
  44. void scm_blk_dev_cleanup(struct scm_blk_dev *);
  45. void scm_blk_set_available(struct scm_blk_dev *);
  46. void scm_blk_irq(struct scm_device *, void *, int);
  47. void scm_request_finish(struct scm_request *);
  48. void scm_request_requeue(struct scm_request *);
  49. struct aidaw *scm_aidaw_fetch(struct scm_request *scmrq, unsigned int bytes);
  50. int scm_drv_init(void);
  51. void scm_drv_cleanup(void);
  52. #ifdef CONFIG_SCM_BLOCK_CLUSTER_WRITE
  53. void __scm_free_rq_cluster(struct scm_request *);
  54. int __scm_alloc_rq_cluster(struct scm_request *);
  55. void scm_request_cluster_init(struct scm_request *);
  56. bool scm_reserve_cluster(struct scm_request *);
  57. void scm_release_cluster(struct scm_request *);
  58. void scm_blk_dev_cluster_setup(struct scm_blk_dev *);
  59. bool scm_need_cluster_request(struct scm_request *);
  60. void scm_initiate_cluster_request(struct scm_request *);
  61. void scm_cluster_request_irq(struct scm_request *);
  62. bool scm_test_cluster_request(struct scm_request *);
  63. bool scm_cluster_size_valid(void);
  64. #else /* CONFIG_SCM_BLOCK_CLUSTER_WRITE */
  65. static inline void __scm_free_rq_cluster(struct scm_request *scmrq) {}
  66. static inline int __scm_alloc_rq_cluster(struct scm_request *scmrq)
  67. {
  68. return 0;
  69. }
  70. static inline void scm_request_cluster_init(struct scm_request *scmrq) {}
  71. static inline bool scm_reserve_cluster(struct scm_request *scmrq)
  72. {
  73. return true;
  74. }
  75. static inline void scm_release_cluster(struct scm_request *scmrq) {}
  76. static inline void scm_blk_dev_cluster_setup(struct scm_blk_dev *bdev) {}
  77. static inline bool scm_need_cluster_request(struct scm_request *scmrq)
  78. {
  79. return false;
  80. }
  81. static inline void scm_initiate_cluster_request(struct scm_request *scmrq) {}
  82. static inline void scm_cluster_request_irq(struct scm_request *scmrq) {}
  83. static inline bool scm_test_cluster_request(struct scm_request *scmrq)
  84. {
  85. return false;
  86. }
  87. static inline bool scm_cluster_size_valid(void)
  88. {
  89. return true;
  90. }
  91. #endif /* CONFIG_SCM_BLOCK_CLUSTER_WRITE */
  92. extern debug_info_t *scm_debug;
  93. #define SCM_LOG(imp, txt) do { \
  94. debug_text_event(scm_debug, imp, txt); \
  95. } while (0)
  96. static inline void SCM_LOG_HEX(int level, void *data, int length)
  97. {
  98. if (!debug_level_enabled(scm_debug, level))
  99. return;
  100. while (length > 0) {
  101. debug_event(scm_debug, level, data, length);
  102. length -= scm_debug->buf_size;
  103. data += scm_debug->buf_size;
  104. }
  105. }
  106. static inline void SCM_LOG_STATE(int level, struct scm_device *scmdev)
  107. {
  108. struct {
  109. u64 address;
  110. u8 oper_state;
  111. u8 rank;
  112. } __packed data = {
  113. .address = scmdev->address,
  114. .oper_state = scmdev->attrs.oper_state,
  115. .rank = scmdev->attrs.rank,
  116. };
  117. SCM_LOG_HEX(level, &data, sizeof(data));
  118. }
  119. #endif /* SCM_BLK_H */