@@ -236,21 +236,23 @@ static const char *sdebug_version_date = "20200421";
236
236
#define SDEBUG_CANQUEUE (SDEBUG_CANQUEUE_WORDS * BITS_PER_LONG)
237
237
#define DEF_CMD_PER_LUN 255
238
238
239
- #define F_D_IN 1
240
- #define F_D_OUT 2
239
+ /* UA - Unit Attention; SA - Service Action; SSU - Start Stop Unit */
240
+ #define F_D_IN 1 /* Data-in command (e.g. READ) */
241
+ #define F_D_OUT 2 /* Data-out command (e.g. WRITE) */
241
242
#define F_D_OUT_MAYBE 4 /* WRITE SAME, NDOB bit */
242
243
#define F_D_UNKN 8
243
- #define F_RL_WLUN_OK 0x10
244
- #define F_SKIP_UA 0x20
245
- #define F_DELAY_OVERR 0x40
246
- #define F_SA_LOW 0x80 /* cdb byte 1, bits 4 to 0 */
247
- #define F_SA_HIGH 0x100 /* as used by variable length cdbs */
248
- #define F_INV_OP 0x200
249
- #define F_FAKE_RW 0x400
250
- #define F_M_ACCESS 0x800 /* media access */
251
- #define F_SSU_DELAY 0x1000
252
- #define F_SYNC_DELAY 0x2000
253
-
244
+ #define F_RL_WLUN_OK 0x10 /* allowed with REPORT LUNS W-LUN */
245
+ #define F_SKIP_UA 0x20 /* bypass UAs (e.g. INQUIRY command) */
246
+ #define F_DELAY_OVERR 0x40 /* for commands like INQUIRY */
247
+ #define F_SA_LOW 0x80 /* SA is in cdb byte 1, bits 4 to 0 */
248
+ #define F_SA_HIGH 0x100 /* SA is in cdb bytes 8 and 9 */
249
+ #define F_INV_OP 0x200 /* invalid opcode (not supported) */
250
+ #define F_FAKE_RW 0x400 /* bypass resp_*() when fake_rw set */
251
+ #define F_M_ACCESS 0x800 /* media access, reacts to SSU state */
252
+ #define F_SSU_DELAY 0x1000 /* SSU command delay (long-ish) */
253
+ #define F_SYNC_DELAY 0x2000 /* SYNCHRONIZE CACHE delay */
254
+
255
+ /* Useful combinations of the above flags */
254
256
#define FF_RESPOND (F_RL_WLUN_OK | F_SKIP_UA | F_DELAY_OVERR)
255
257
#define FF_MEDIA_IO (F_M_ACCESS | F_FAKE_RW)
256
258
#define FF_SA (F_SA_HIGH | F_SA_LOW)
@@ -607,25 +609,25 @@ static const struct opcode_info_t sync_cache_iarr[] = {
607
609
};
608
610
609
611
static const struct opcode_info_t pre_fetch_iarr [] = {
610
- {0 , 0x90 , 0 , F_SYNC_DELAY | F_M_ACCESS , resp_pre_fetch , NULL ,
612
+ {0 , 0x90 , 0 , F_SYNC_DELAY | FF_MEDIA_IO , resp_pre_fetch , NULL ,
611
613
{16 , 0x2 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
612
614
0xff , 0xff , 0xff , 0xff , 0x3f , 0xc7 } }, /* PRE-FETCH (16) */
613
615
};
614
616
615
617
static const struct opcode_info_t zone_out_iarr [] = { /* ZONE OUT(16) */
616
- {0 , 0x94 , 0x1 , F_SA_LOW , resp_close_zone , NULL ,
618
+ {0 , 0x94 , 0x1 , F_SA_LOW | F_M_ACCESS , resp_close_zone , NULL ,
617
619
{16 , 0x1 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
618
620
0xff , 0 , 0 , 0xff , 0xff , 0x1 , 0xc7 } }, /* CLOSE ZONE */
619
- {0 , 0x94 , 0x2 , F_SA_LOW , resp_finish_zone , NULL ,
621
+ {0 , 0x94 , 0x2 , F_SA_LOW | F_M_ACCESS , resp_finish_zone , NULL ,
620
622
{16 , 0x2 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
621
623
0xff , 0 , 0 , 0xff , 0xff , 0x1 , 0xc7 } }, /* FINISH ZONE */
622
- {0 , 0x94 , 0x4 , F_SA_LOW , resp_rwp_zone , NULL ,
624
+ {0 , 0x94 , 0x4 , F_SA_LOW | F_M_ACCESS , resp_rwp_zone , NULL ,
623
625
{16 , 0x4 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
624
626
0xff , 0 , 0 , 0xff , 0xff , 0x1 , 0xc7 } }, /* RESET WRITE POINTER */
625
627
};
626
628
627
629
static const struct opcode_info_t zone_in_iarr [] = { /* ZONE IN(16) */
628
- {0 , 0x95 , 0x6 , F_SA_LOW | F_D_IN , NULL , NULL ,
630
+ {0 , 0x95 , 0x6 , F_SA_LOW | F_D_IN | F_M_ACCESS , NULL , NULL ,
629
631
{16 , 0x6 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
630
632
0xff , 0xff , 0xff , 0xff , 0x3f , 0xc7 } }, /* REPORT ZONES */
631
633
};
@@ -726,17 +728,17 @@ static const struct opcode_info_t opcode_info_arr[SDEB_I_LAST_ELEM_P1 + 1] = {
726
728
{0 , 0x89 , 0 , F_D_OUT | FF_MEDIA_IO , resp_comp_write , NULL ,
727
729
{16 , 0xf8 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0 , 0 ,
728
730
0 , 0xff , 0x3f , 0xc7 } }, /* COMPARE AND WRITE */
729
- {ARRAY_SIZE (pre_fetch_iarr ), 0x34 , 0 , F_SYNC_DELAY | F_M_ACCESS ,
731
+ {ARRAY_SIZE (pre_fetch_iarr ), 0x34 , 0 , F_SYNC_DELAY | FF_MEDIA_IO ,
730
732
resp_pre_fetch , pre_fetch_iarr ,
731
733
{10 , 0x2 , 0xff , 0xff , 0xff , 0xff , 0x3f , 0xff , 0xff , 0xc7 , 0 , 0 ,
732
734
0 , 0 , 0 , 0 } }, /* PRE-FETCH (10) */
733
735
734
736
/* 30 */
735
- {ARRAY_SIZE (zone_out_iarr ), 0x94 , 0x3 , F_SA_LOW ,
737
+ {ARRAY_SIZE (zone_out_iarr ), 0x94 , 0x3 , F_SA_LOW | F_M_ACCESS ,
736
738
resp_open_zone , zone_out_iarr , /* ZONE_OUT(16), OPEN ZONE) */
737
739
{16 , 0x3 /* SA */ , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
738
740
0xff , 0xff , 0x0 , 0x0 , 0xff , 0xff , 0x1 , 0xc7 } },
739
- {ARRAY_SIZE (zone_in_iarr ), 0x95 , 0x0 , F_SA_LOW | F_D_IN ,
741
+ {ARRAY_SIZE (zone_in_iarr ), 0x95 , 0x0 , F_SA_LOW | F_M_ACCESS ,
740
742
resp_report_zones , zone_in_iarr , /* ZONE_IN(16), REPORT ZONES) */
741
743
{16 , 0x0 /* SA */ , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
742
744
0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xbf , 0xc7 } },
@@ -2875,10 +2877,20 @@ static inline int check_device_access_params
2875
2877
return 0 ;
2876
2878
}
2877
2879
2878
- static inline struct sdeb_store_info * devip2sip (struct sdebug_dev_info * devip )
2880
+ /*
2881
+ * Note: if BUG_ON() fires it usually indicates a problem with the parser
2882
+ * tables. Perhaps a missing F_FAKE_RW or FF_MEDIA_IO flag. Response functions
2883
+ * that access any of the "stores" in struct sdeb_store_info should call this
2884
+ * function with bug_if_fake_rw set to true.
2885
+ */
2886
+ static inline struct sdeb_store_info * devip2sip (struct sdebug_dev_info * devip ,
2887
+ bool bug_if_fake_rw )
2879
2888
{
2880
- return sdebug_fake_rw ?
2881
- NULL : xa_load (per_store_ap , devip -> sdbg_host -> si_idx );
2889
+ if (sdebug_fake_rw ) {
2890
+ BUG_ON (bug_if_fake_rw ); /* See note above */
2891
+ return NULL ;
2892
+ }
2893
+ return xa_load (per_store_ap , devip -> sdbg_host -> si_idx );
2882
2894
}
2883
2895
2884
2896
/* Returns number of bytes copied or -1 if error. */
@@ -3015,7 +3027,7 @@ static void dif_copy_prot(struct scsi_cmnd *scp, sector_t sector,
3015
3027
size_t resid ;
3016
3028
void * paddr ;
3017
3029
struct sdeb_store_info * sip = devip2sip ((struct sdebug_dev_info * )
3018
- scp -> device -> hostdata );
3030
+ scp -> device -> hostdata , true );
3019
3031
struct t10_pi_tuple * dif_storep = sip -> dif_storep ;
3020
3032
const void * dif_store_end = dif_storep + sdebug_store_sectors ;
3021
3033
struct sg_mapping_iter miter ;
@@ -3061,7 +3073,7 @@ static int prot_verify_read(struct scsi_cmnd *scp, sector_t start_sec,
3061
3073
unsigned int i ;
3062
3074
sector_t sector ;
3063
3075
struct sdeb_store_info * sip = devip2sip ((struct sdebug_dev_info * )
3064
- scp -> device -> hostdata );
3076
+ scp -> device -> hostdata , true );
3065
3077
struct t10_pi_tuple * sdt ;
3066
3078
3067
3079
for (i = 0 ; i < sectors ; i ++ , ei_lba ++ ) {
@@ -3094,7 +3106,7 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3094
3106
u32 ei_lba ;
3095
3107
int ret ;
3096
3108
u64 lba ;
3097
- struct sdeb_store_info * sip = devip2sip (devip );
3109
+ struct sdeb_store_info * sip = devip2sip (devip , true );
3098
3110
rwlock_t * macc_lckp = sip ? & sip -> macc_lck : & sdeb_fake_rw_lck ;
3099
3111
u8 * cmd = scp -> cmnd ;
3100
3112
struct sdebug_queued_cmd * sqcp ;
@@ -3403,8 +3415,8 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3403
3415
u32 ei_lba ;
3404
3416
int ret ;
3405
3417
u64 lba ;
3406
- struct sdeb_store_info * sip = devip2sip (devip );
3407
- rwlock_t * macc_lckp = sip ? & sip -> macc_lck : & sdeb_fake_rw_lck ;
3418
+ struct sdeb_store_info * sip = devip2sip (devip , true );
3419
+ rwlock_t * macc_lckp = & sip -> macc_lck ;
3408
3420
u8 * cmd = scp -> cmnd ;
3409
3421
3410
3422
switch (cmd [0 ]) {
@@ -3524,8 +3536,8 @@ static int resp_write_scat(struct scsi_cmnd *scp,
3524
3536
u8 * cmd = scp -> cmnd ;
3525
3537
u8 * lrdp = NULL ;
3526
3538
u8 * up ;
3527
- struct sdeb_store_info * sip = devip2sip (devip );
3528
- rwlock_t * macc_lckp = sip ? & sip -> macc_lck : & sdeb_fake_rw_lck ;
3539
+ struct sdeb_store_info * sip = devip2sip (devip , true );
3540
+ rwlock_t * macc_lckp = & sip -> macc_lck ;
3529
3541
u8 wrprotect ;
3530
3542
u16 lbdof , num_lrd , k ;
3531
3543
u32 num , num_by , bt_len , lbdof_blen , sg_off , cum_lb ;
@@ -3695,8 +3707,8 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num,
3695
3707
u32 lb_size = sdebug_sector_size ;
3696
3708
int ret ;
3697
3709
struct sdeb_store_info * sip = devip2sip ((struct sdebug_dev_info * )
3698
- scp -> device -> hostdata );
3699
- rwlock_t * macc_lckp = sip ? & sip -> macc_lck : & sdeb_fake_rw_lck ;
3710
+ scp -> device -> hostdata , true );
3711
+ rwlock_t * macc_lckp = & sip -> macc_lck ;
3700
3712
u8 * fs1p ;
3701
3713
u8 * fsp ;
3702
3714
@@ -3855,8 +3867,8 @@ static int resp_comp_write(struct scsi_cmnd *scp,
3855
3867
{
3856
3868
u8 * cmd = scp -> cmnd ;
3857
3869
u8 * arr ;
3858
- struct sdeb_store_info * sip = devip2sip (devip );
3859
- rwlock_t * macc_lckp = sip ? & sip -> macc_lck : & sdeb_fake_rw_lck ;
3870
+ struct sdeb_store_info * sip = devip2sip (devip , true );
3871
+ rwlock_t * macc_lckp = & sip -> macc_lck ;
3860
3872
u64 lba ;
3861
3873
u32 dnum ;
3862
3874
u32 lb_size = sdebug_sector_size ;
@@ -3922,8 +3934,8 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3922
3934
{
3923
3935
unsigned char * buf ;
3924
3936
struct unmap_block_desc * desc ;
3925
- struct sdeb_store_info * sip = devip2sip (devip );
3926
- rwlock_t * macc_lckp = sip ? & sip -> macc_lck : & sdeb_fake_rw_lck ;
3937
+ struct sdeb_store_info * sip = devip2sip (devip , true );
3938
+ rwlock_t * macc_lckp = & sip -> macc_lck ;
3927
3939
unsigned int i , payload_len , descriptors ;
3928
3940
int ret ;
3929
3941
@@ -3980,7 +3992,6 @@ static int resp_get_lba_status(struct scsi_cmnd *scp,
3980
3992
struct sdebug_dev_info * devip )
3981
3993
{
3982
3994
u8 * cmd = scp -> cmnd ;
3983
- struct sdeb_store_info * sip = devip2sip (devip );
3984
3995
u64 lba ;
3985
3996
u32 alloc_len , mapped , num ;
3986
3997
int ret ;
@@ -3996,9 +4007,11 @@ static int resp_get_lba_status(struct scsi_cmnd *scp,
3996
4007
if (ret )
3997
4008
return ret ;
3998
4009
3999
- if (scsi_debug_lbp ())
4010
+ if (scsi_debug_lbp ()) {
4011
+ struct sdeb_store_info * sip = devip2sip (devip , true);
4012
+
4000
4013
mapped = map_state (sip , lba , & num );
4001
- else {
4014
+ } else {
4002
4015
mapped = 1 ;
4003
4016
/* following just in case virtual_gb changed */
4004
4017
sdebug_capacity = get_sdebug_capacity ();
@@ -4058,9 +4071,9 @@ static int resp_pre_fetch(struct scsi_cmnd *scp,
4058
4071
u64 block , rest = 0 ;
4059
4072
u32 nblks ;
4060
4073
u8 * cmd = scp -> cmnd ;
4061
- struct sdeb_store_info * sip = devip2sip (devip );
4062
- rwlock_t * macc_lckp = sip ? & sip -> macc_lck : & sdeb_fake_rw_lck ;
4063
- u8 * fsp = sip ? sip -> storep : NULL ;
4074
+ struct sdeb_store_info * sip = devip2sip (devip , true );
4075
+ rwlock_t * macc_lckp = & sip -> macc_lck ;
4076
+ u8 * fsp = sip -> storep ;
4064
4077
4065
4078
if (cmd [0 ] == PRE_FETCH ) { /* 10 byte cdb */
4066
4079
lba = get_unaligned_be32 (cmd + 2 );
@@ -4204,8 +4217,8 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
4204
4217
u64 lba ;
4205
4218
u8 * arr ;
4206
4219
u8 * cmd = scp -> cmnd ;
4207
- struct sdeb_store_info * sip = devip2sip (devip );
4208
- rwlock_t * macc_lckp = sip ? & sip -> macc_lck : & sdeb_fake_rw_lck ;
4220
+ struct sdeb_store_info * sip = devip2sip (devip , true );
4221
+ rwlock_t * macc_lckp = & sip -> macc_lck ;
4209
4222
4210
4223
bytchk = (cmd [1 ] >> 1 ) & 0x3 ;
4211
4224
if (bytchk == 0 ) {
@@ -4283,7 +4296,7 @@ static int resp_report_zones(struct scsi_cmnd *scp,
4283
4296
u8 * arr = NULL , * desc ;
4284
4297
u8 * cmd = scp -> cmnd ;
4285
4298
struct sdeb_zone_state * zsp ;
4286
- struct sdeb_store_info * sip = devip2sip (devip );
4299
+ struct sdeb_store_info * sip = devip2sip (devip , false );
4287
4300
rwlock_t * macc_lckp = sip ? & sip -> macc_lck : & sdeb_fake_rw_lck ;
4288
4301
4289
4302
if (!sdebug_dev_is_zoned (devip )) {
@@ -4424,7 +4437,7 @@ static int resp_open_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
4424
4437
u8 * cmd = scp -> cmnd ;
4425
4438
struct sdeb_zone_state * zsp ;
4426
4439
bool all = cmd [14 ] & 0x01 ;
4427
- struct sdeb_store_info * sip = devip2sip (devip );
4440
+ struct sdeb_store_info * sip = devip2sip (devip , false );
4428
4441
rwlock_t * macc_lckp = sip ? & sip -> macc_lck : & sdeb_fake_rw_lck ;
4429
4442
4430
4443
if (!sdebug_dev_is_zoned (devip )) {
@@ -4503,7 +4516,7 @@ static int resp_close_zone(struct scsi_cmnd *scp,
4503
4516
u8 * cmd = scp -> cmnd ;
4504
4517
struct sdeb_zone_state * zsp ;
4505
4518
bool all = cmd [14 ] & 0x01 ;
4506
- struct sdeb_store_info * sip = devip2sip (devip );
4519
+ struct sdeb_store_info * sip = devip2sip (devip , false );
4507
4520
rwlock_t * macc_lckp = sip ? & sip -> macc_lck : & sdeb_fake_rw_lck ;
4508
4521
4509
4522
if (!sdebug_dev_is_zoned (devip )) {
@@ -4576,7 +4589,7 @@ static int resp_finish_zone(struct scsi_cmnd *scp,
4576
4589
u64 z_id ;
4577
4590
u8 * cmd = scp -> cmnd ;
4578
4591
bool all = cmd [14 ] & 0x01 ;
4579
- struct sdeb_store_info * sip = devip2sip (devip );
4592
+ struct sdeb_store_info * sip = devip2sip (devip , false );
4580
4593
rwlock_t * macc_lckp = sip ? & sip -> macc_lck : & sdeb_fake_rw_lck ;
4581
4594
4582
4595
if (!sdebug_dev_is_zoned (devip )) {
@@ -4652,7 +4665,7 @@ static int resp_rwp_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
4652
4665
u64 z_id ;
4653
4666
u8 * cmd = scp -> cmnd ;
4654
4667
bool all = cmd [14 ] & 0x01 ;
4655
- struct sdeb_store_info * sip = devip2sip (devip );
4668
+ struct sdeb_store_info * sip = devip2sip (devip , false );
4656
4669
rwlock_t * macc_lckp = sip ? & sip -> macc_lck : & sdeb_fake_rw_lck ;
4657
4670
4658
4671
if (!sdebug_dev_is_zoned (devip )) {
0 commit comments