1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_BLK_INTEGRITY_H
3 #define _LINUX_BLK_INTEGRITY_H
5 #include <linux/blk-mq.h>
6 #include <linux/bio-integrity.h>
10 enum blk_integrity_flags
{
11 BLK_INTEGRITY_NOVERIFY
= 1 << 0,
12 BLK_INTEGRITY_NOGENERATE
= 1 << 1,
13 BLK_INTEGRITY_DEVICE_CAPABLE
= 1 << 2,
14 BLK_INTEGRITY_REF_TAG
= 1 << 3,
15 BLK_INTEGRITY_STACKED
= 1 << 4,
18 const char *blk_integrity_profile_name(struct blk_integrity
*bi
);
19 bool queue_limits_stack_integrity(struct queue_limits
*t
,
20 struct queue_limits
*b
);
21 static inline bool queue_limits_stack_integrity_bdev(struct queue_limits
*t
,
22 struct block_device
*bdev
)
24 return queue_limits_stack_integrity(t
, &bdev
->bd_disk
->queue
->limits
);
27 #ifdef CONFIG_BLK_DEV_INTEGRITY
28 int blk_rq_map_integrity_sg(struct request
*, struct scatterlist
*);
29 int blk_rq_count_integrity_sg(struct request_queue
*, struct bio
*);
30 int blk_rq_integrity_map_user(struct request
*rq
, void __user
*ubuf
,
34 blk_integrity_queue_supports_integrity(struct request_queue
*q
)
36 return q
->limits
.integrity
.tuple_size
;
39 static inline struct blk_integrity
*blk_get_integrity(struct gendisk
*disk
)
41 if (!blk_integrity_queue_supports_integrity(disk
->queue
))
43 return &disk
->queue
->limits
.integrity
;
46 static inline struct blk_integrity
*
47 bdev_get_integrity(struct block_device
*bdev
)
49 return blk_get_integrity(bdev
->bd_disk
);
52 static inline unsigned short
53 queue_max_integrity_segments(const struct request_queue
*q
)
55 return q
->limits
.max_integrity_segments
;
59 * bio_integrity_intervals - Return number of integrity intervals for a bio
60 * @bi: blk_integrity profile for device
61 * @sectors: Size of the bio in 512-byte sectors
63 * Description: The block layer calculates everything in 512 byte
64 * sectors but integrity metadata is done in terms of the data integrity
65 * interval size of the storage device. Convert the block layer sectors
66 * to the appropriate number of integrity intervals.
68 static inline unsigned int bio_integrity_intervals(struct blk_integrity
*bi
,
71 return sectors
>> (bi
->interval_exp
- 9);
74 static inline unsigned int bio_integrity_bytes(struct blk_integrity
*bi
,
77 return bio_integrity_intervals(bi
, sectors
) * bi
->tuple_size
;
80 static inline bool blk_integrity_rq(struct request
*rq
)
82 return rq
->cmd_flags
& REQ_INTEGRITY
;
86 * Return the current bvec that contains the integrity data. bip_iter may be
87 * advanced to iterate over the integrity data.
89 static inline struct bio_vec
rq_integrity_vec(struct request
*rq
)
91 return mp_bvec_iter_bvec(rq
->bio
->bi_integrity
->bip_vec
,
92 rq
->bio
->bi_integrity
->bip_iter
);
94 #else /* CONFIG_BLK_DEV_INTEGRITY */
95 static inline int blk_rq_count_integrity_sg(struct request_queue
*q
,
100 static inline int blk_rq_map_integrity_sg(struct request
*q
,
101 struct scatterlist
*s
)
105 static inline int blk_rq_integrity_map_user(struct request
*rq
,
111 static inline struct blk_integrity
*bdev_get_integrity(struct block_device
*b
)
115 static inline struct blk_integrity
*blk_get_integrity(struct gendisk
*disk
)
120 blk_integrity_queue_supports_integrity(struct request_queue
*q
)
124 static inline unsigned short
125 queue_max_integrity_segments(const struct request_queue
*q
)
130 static inline unsigned int bio_integrity_intervals(struct blk_integrity
*bi
,
131 unsigned int sectors
)
136 static inline unsigned int bio_integrity_bytes(struct blk_integrity
*bi
,
137 unsigned int sectors
)
141 static inline int blk_integrity_rq(struct request
*rq
)
146 static inline struct bio_vec
rq_integrity_vec(struct request
*rq
)
148 /* the optimizer will remove all calls to this function */
149 return (struct bio_vec
){ };
151 #endif /* CONFIG_BLK_DEV_INTEGRITY */
153 #endif /* _LINUX_BLK_INTEGRITY_H */