1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX_BLK_INTEGRITY_H 3 #define _LINUX_BLK_INTEGRITY_H 4 5 #include <linux/blk-mq.h> 6 #include <linux/bio-integrity.h> 7 8 struct request; 9 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, 16 }; 17 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) 23 { 24 return queue_limits_stack_integrity(t, &bdev->bd_disk->queue->limits); 25 } 26 27 #ifdef CONFIG_BLK_DEV_INTEGRITY 28 int blk_rq_map_integrity_sg(struct request_queue *, struct bio *, 29 struct scatterlist *); 30 int blk_rq_count_integrity_sg(struct request_queue *, struct bio *); 31 32 static inline bool 33 blk_integrity_queue_supports_integrity(struct request_queue *q) 34 { 35 return q->limits.integrity.tuple_size; 36 } 37 38 static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) 39 { 40 if (!blk_integrity_queue_supports_integrity(disk->queue)) 41 return NULL; 42 return &disk->queue->limits.integrity; 43 } 44 45 static inline struct blk_integrity * 46 bdev_get_integrity(struct block_device *bdev) 47 { 48 return blk_get_integrity(bdev->bd_disk); 49 } 50 51 static inline unsigned short 52 queue_max_integrity_segments(const struct request_queue *q) 53 { 54 return q->limits.max_integrity_segments; 55 } 56 57 /** 58 * bio_integrity_intervals - Return number of integrity intervals for a bio 59 * @bi: blk_integrity profile for device 60 * @sectors: Size of the bio in 512-byte sectors 61 * 62 * Description: The block layer calculates everything in 512 byte 63 * sectors but integrity metadata is done in terms of the data integrity 64 * interval size of the storage device. Convert the block layer sectors 65 * to the appropriate number of integrity intervals. 66 */ 67 static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi, 68 unsigned int sectors) 69 { 70 return sectors >> (bi->interval_exp - 9); 71 } 72 73 static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi, 74 unsigned int sectors) 75 { 76 return bio_integrity_intervals(bi, sectors) * bi->tuple_size; 77 } 78 79 static inline bool blk_integrity_rq(struct request *rq) 80 { 81 return rq->cmd_flags & REQ_INTEGRITY; 82 } 83 84 /* 85 * Return the current bvec that contains the integrity data. bip_iter may be 86 * advanced to iterate over the integrity data. 87 */ 88 static inline struct bio_vec rq_integrity_vec(struct request *rq) 89 { 90 return mp_bvec_iter_bvec(rq->bio->bi_integrity->bip_vec, 91 rq->bio->bi_integrity->bip_iter); 92 } 93 #else /* CONFIG_BLK_DEV_INTEGRITY */ 94 static inline int blk_rq_count_integrity_sg(struct request_queue *q, 95 struct bio *b) 96 { 97 return 0; 98 } 99 static inline int blk_rq_map_integrity_sg(struct request_queue *q, 100 struct bio *b, 101 struct scatterlist *s) 102 { 103 return 0; 104 } 105 static inline struct blk_integrity *bdev_get_integrity(struct block_device *b) 106 { 107 return NULL; 108 } 109 static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) 110 { 111 return NULL; 112 } 113 static inline bool 114 blk_integrity_queue_supports_integrity(struct request_queue *q) 115 { 116 return false; 117 } 118 static inline unsigned short 119 queue_max_integrity_segments(const struct request_queue *q) 120 { 121 return 0; 122 } 123 124 static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi, 125 unsigned int sectors) 126 { 127 return 0; 128 } 129 130 static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi, 131 unsigned int sectors) 132 { 133 return 0; 134 } 135 static inline int blk_integrity_rq(struct request *rq) 136 { 137 return 0; 138 } 139 140 static inline struct bio_vec rq_integrity_vec(struct request *rq) 141 { 142 /* the optimizer will remove all calls to this function */ 143 return (struct bio_vec){ }; 144 } 145 #endif /* CONFIG_BLK_DEV_INTEGRITY */ 146 147 #endif /* _LINUX_BLK_INTEGRITY_H */ 148
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.