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