aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/sd.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/sd.h')
-rw-r--r--drivers/scsi/sd.h66
1 files changed, 64 insertions, 2 deletions
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
index 4c3ab8377fd3..467377884b63 100644
--- a/drivers/scsi/sd.h
+++ b/drivers/scsi/sd.h
@@ -167,6 +167,68 @@ enum sd_dif_target_protection_types {
167}; 167};
168 168
169/* 169/*
170 * Look up the DIX operation based on whether the command is read or
171 * write and whether dix and dif are enabled.
172 */
173static inline unsigned int sd_prot_op(bool write, bool dix, bool dif)
174{
175 /* Lookup table: bit 2 (write), bit 1 (dix), bit 0 (dif) */
176 const unsigned int ops[] = { /* wrt dix dif */
177 SCSI_PROT_NORMAL, /* 0 0 0 */
178 SCSI_PROT_READ_STRIP, /* 0 0 1 */
179 SCSI_PROT_READ_INSERT, /* 0 1 0 */
180 SCSI_PROT_READ_PASS, /* 0 1 1 */
181 SCSI_PROT_NORMAL, /* 1 0 0 */
182 SCSI_PROT_WRITE_INSERT, /* 1 0 1 */
183 SCSI_PROT_WRITE_STRIP, /* 1 1 0 */
184 SCSI_PROT_WRITE_PASS, /* 1 1 1 */
185 };
186
187 return ops[write << 2 | dix << 1 | dif];
188}
189
190/*
191 * Returns a mask of the protection flags that are valid for a given DIX
192 * operation.
193 */
194static inline unsigned int sd_prot_flag_mask(unsigned int prot_op)
195{
196 const unsigned int flag_mask[] = {
197 [SCSI_PROT_NORMAL] = 0,
198
199 [SCSI_PROT_READ_STRIP] = SCSI_PROT_TRANSFER_PI |
200 SCSI_PROT_GUARD_CHECK |
201 SCSI_PROT_REF_CHECK |
202 SCSI_PROT_REF_INCREMENT,
203
204 [SCSI_PROT_READ_INSERT] = SCSI_PROT_REF_INCREMENT |
205 SCSI_PROT_IP_CHECKSUM,
206
207 [SCSI_PROT_READ_PASS] = SCSI_PROT_TRANSFER_PI |
208 SCSI_PROT_GUARD_CHECK |
209 SCSI_PROT_REF_CHECK |
210 SCSI_PROT_REF_INCREMENT |
211 SCSI_PROT_IP_CHECKSUM,
212
213 [SCSI_PROT_WRITE_INSERT] = SCSI_PROT_TRANSFER_PI |
214 SCSI_PROT_REF_INCREMENT,
215
216 [SCSI_PROT_WRITE_STRIP] = SCSI_PROT_GUARD_CHECK |
217 SCSI_PROT_REF_CHECK |
218 SCSI_PROT_REF_INCREMENT |
219 SCSI_PROT_IP_CHECKSUM,
220
221 [SCSI_PROT_WRITE_PASS] = SCSI_PROT_TRANSFER_PI |
222 SCSI_PROT_GUARD_CHECK |
223 SCSI_PROT_REF_CHECK |
224 SCSI_PROT_REF_INCREMENT |
225 SCSI_PROT_IP_CHECKSUM,
226 };
227
228 return flag_mask[prot_op];
229}
230
231/*
170 * Data Integrity Field tuple. 232 * Data Integrity Field tuple.
171 */ 233 */
172struct sd_dif_tuple { 234struct sd_dif_tuple {
@@ -178,7 +240,7 @@ struct sd_dif_tuple {
178#ifdef CONFIG_BLK_DEV_INTEGRITY 240#ifdef CONFIG_BLK_DEV_INTEGRITY
179 241
180extern void sd_dif_config_host(struct scsi_disk *); 242extern void sd_dif_config_host(struct scsi_disk *);
181extern void sd_dif_prepare(struct request *rq, sector_t, unsigned int); 243extern void sd_dif_prepare(struct scsi_cmnd *scmd);
182extern void sd_dif_complete(struct scsi_cmnd *, unsigned int); 244extern void sd_dif_complete(struct scsi_cmnd *, unsigned int);
183 245
184#else /* CONFIG_BLK_DEV_INTEGRITY */ 246#else /* CONFIG_BLK_DEV_INTEGRITY */
@@ -186,7 +248,7 @@ extern void sd_dif_complete(struct scsi_cmnd *, unsigned int);
186static inline void sd_dif_config_host(struct scsi_disk *disk) 248static inline void sd_dif_config_host(struct scsi_disk *disk)
187{ 249{
188} 250}
189static inline int sd_dif_prepare(struct request *rq, sector_t s, unsigned int a) 251static inline int sd_dif_prepare(struct scsi_cmnd *scmd)
190{ 252{
191 return 0; 253 return 0;
192} 254}