aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2016-04-25 12:16:33 -0400
committerMartin K. Petersen <martin.petersen@oracle.com>2016-04-29 19:41:12 -0400
commitfd32119b0deac1af90ca3bed145f17d5ad68d5a7 (patch)
treea942b808e9bb5380a6aff0b6e559d12ce801c8bd /drivers/scsi
parenta10bc12af6347d2aa3a2ffbd5f8b7be260c12b85 (diff)
scsi_debug: re-order file scope declarations
Group most defines together first; followed by struct definitions and then table and variable definitions. Normalize all function headers. [mkp: Corrected hex value in WP/DPOFUA MODE SENSE comment] Signed-off-by: Douglas Gilbert <dgilbert@interlog.com> Reviewed-by: Hannes Reinicke <hare@suse.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/scsi_debug.c314
1 files changed, 151 insertions, 163 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 40de305de1d5..f952803ea966 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -95,7 +95,6 @@ static const char *sdebug_version_date = "20160422";
95/* Additional Sense Code Qualifier (ASCQ) */ 95/* Additional Sense Code Qualifier (ASCQ) */
96#define ACK_NAK_TO 0x3 96#define ACK_NAK_TO 0x3
97 97
98
99/* Default values for driver parameters */ 98/* Default values for driver parameters */
100#define DEF_NUM_HOST 1 99#define DEF_NUM_HOST 1
101#define DEF_NUM_TGTS 1 100#define DEF_NUM_TGTS 1
@@ -161,14 +160,14 @@ static const char *sdebug_version_date = "20160422";
161 SDEBUG_OPT_DIF_ERR | SDEBUG_OPT_DIX_ERR | \ 160 SDEBUG_OPT_DIF_ERR | SDEBUG_OPT_DIX_ERR | \
162 SDEBUG_OPT_SHORT_TRANSFER) 161 SDEBUG_OPT_SHORT_TRANSFER)
163/* When "every_nth" > 0 then modulo "every_nth" commands: 162/* When "every_nth" > 0 then modulo "every_nth" commands:
164 * - a no response is simulated if SDEBUG_OPT_TIMEOUT is set 163 * - a missing response is simulated if SDEBUG_OPT_TIMEOUT is set
165 * - a RECOVERED_ERROR is simulated on successful read and write 164 * - a RECOVERED_ERROR is simulated on successful read and write
166 * commands if SDEBUG_OPT_RECOVERED_ERR is set. 165 * commands if SDEBUG_OPT_RECOVERED_ERR is set.
167 * - a TRANSPORT_ERROR is simulated on successful read and write 166 * - a TRANSPORT_ERROR is simulated on successful read and write
168 * commands if SDEBUG_OPT_TRANSPORT_ERR is set. 167 * commands if SDEBUG_OPT_TRANSPORT_ERR is set.
169 * 168 *
170 * When "every_nth" < 0 then after "- every_nth" commands: 169 * When "every_nth" < 0 then after "- every_nth" commands:
171 * - a no response is simulated if SDEBUG_OPT_TIMEOUT is set 170 * - a missing response is simulated if SDEBUG_OPT_TIMEOUT is set
172 * - a RECOVERED_ERROR is simulated on successful read and write 171 * - a RECOVERED_ERROR is simulated on successful read and write
173 * commands if SDEBUG_OPT_RECOVERED_ERR is set. 172 * commands if SDEBUG_OPT_RECOVERED_ERR is set.
174 * - a TRANSPORT_ERROR is simulated on successful read and write 173 * - a TRANSPORT_ERROR is simulated on successful read and write
@@ -178,7 +177,7 @@ static const char *sdebug_version_date = "20160422";
178 * every_nth via sysfs). 177 * every_nth via sysfs).
179 */ 178 */
180 179
181/* As indicated in SAM-5 and SPC-4 Unit Attentions (UAs)are returned in 180/* As indicated in SAM-5 and SPC-4 Unit Attentions (UAs) are returned in
182 * priority order. In the subset implemented here lower numbers have higher 181 * priority order. In the subset implemented here lower numbers have higher
183 * priority. The UA numbers should be a sequence starting from 0 with 182 * priority. The UA numbers should be a sequence starting from 0 with
184 * SDEBUG_NUM_UAS being 1 higher than the highest numbered UA. */ 183 * SDEBUG_NUM_UAS being 1 higher than the highest numbered UA. */
@@ -218,7 +217,83 @@ static const char *sdebug_version_date = "20160422";
218#warning "Expect DEF_CMD_PER_LUN <= SCSI_DEBUG_CANQUEUE" 217#warning "Expect DEF_CMD_PER_LUN <= SCSI_DEBUG_CANQUEUE"
219#endif 218#endif
220 219
221/* SCSI opcodes (first byte of cdb) mapped onto these indexes */ 220#define F_D_IN 1
221#define F_D_OUT 2
222#define F_D_OUT_MAYBE 4 /* WRITE SAME, NDOB bit */
223#define F_D_UNKN 8
224#define F_RL_WLUN_OK 0x10
225#define F_SKIP_UA 0x20
226#define F_DELAY_OVERR 0x40
227#define F_SA_LOW 0x80 /* cdb byte 1, bits 4 to 0 */
228#define F_SA_HIGH 0x100 /* as used by variable length cdbs */
229#define F_INV_OP 0x200
230#define F_FAKE_RW 0x400
231#define F_M_ACCESS 0x800 /* media access */
232
233#define FF_RESPOND (F_RL_WLUN_OK | F_SKIP_UA | F_DELAY_OVERR)
234#define FF_DIRECT_IO (F_M_ACCESS | F_FAKE_RW)
235#define FF_SA (F_SA_HIGH | F_SA_LOW)
236
237#define SDEBUG_MAX_PARTS 4
238
239#define SCSI_DEBUG_MAX_CMD_LEN 32
240
241
242struct sdebug_dev_info {
243 struct list_head dev_list;
244 unsigned int channel;
245 unsigned int target;
246 u64 lun;
247 struct sdebug_host_info *sdbg_host;
248 unsigned long uas_bm[1];
249 atomic_t num_in_q;
250 char stopped; /* TODO: should be atomic */
251 bool used;
252};
253
254struct sdebug_host_info {
255 struct list_head host_list;
256 struct Scsi_Host *shost;
257 struct device dev;
258 struct list_head dev_info_list;
259};
260
261#define to_sdebug_host(d) \
262 container_of(d, struct sdebug_host_info, dev)
263
264struct sdebug_defer {
265 struct hrtimer hrt;
266 struct execute_work ew;
267 int qa_indx;
268};
269
270struct sdebug_queued_cmd {
271 /* in_use flagged by a bit in queued_in_use_bm[] */
272 struct sdebug_defer *sd_dp;
273 struct scsi_cmnd *a_cmnd;
274};
275
276struct sdebug_scmd_extra_t {
277 bool inj_recovered;
278 bool inj_transport;
279 bool inj_dif;
280 bool inj_dix;
281 bool inj_short;
282};
283
284struct opcode_info_t {
285 u8 num_attached; /* 0 if this is it (i.e. a leaf); use 0xff
286 * for terminating element */
287 u8 opcode; /* if num_attached > 0, preferred */
288 u16 sa; /* service action */
289 u32 flags; /* OR-ed set of SDEB_F_* */
290 int (*pfp)(struct scsi_cmnd *, struct sdebug_dev_info *);
291 const struct opcode_info_t *arrp; /* num_attached elements or NULL */
292 u8 len_mask[16]; /* len=len_mask[0], then mask for cdb[1]... */
293 /* ignore cdb bytes after position 15 */
294};
295
296/* SCSI opcodes (first byte of cdb) of interest mapped onto these indexes */
222enum sdeb_opcode_index { 297enum sdeb_opcode_index {
223 SDEB_I_INVALID_OPCODE = 0, 298 SDEB_I_INVALID_OPCODE = 0,
224 SDEB_I_INQUIRY = 1, 299 SDEB_I_INQUIRY = 1,
@@ -273,7 +348,7 @@ static const unsigned char opcode_ind_arr[256] = {
273 0, 0, 0, SDEB_I_XDWRITEREAD, 0, SDEB_I_MODE_SELECT, SDEB_I_RESERVE, 348 0, 0, 0, SDEB_I_XDWRITEREAD, 0, SDEB_I_MODE_SELECT, SDEB_I_RESERVE,
274 SDEB_I_RELEASE, 349 SDEB_I_RELEASE,
275 0, 0, SDEB_I_MODE_SENSE, 0, 0, 0, 0, 0, 350 0, 0, SDEB_I_MODE_SENSE, 0, 0, 0, 0, 0,
276/* 0x60; 0x60->0x7d are reserved */ 351/* 0x60; 0x60->0x7d are reserved, 0x7e is "extended cdb" */
277 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 352 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
278 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 353 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
279 0, SDEB_I_VARIABLE_LEN, 354 0, SDEB_I_VARIABLE_LEN,
@@ -296,24 +371,6 @@ static const unsigned char opcode_ind_arr[256] = {
296 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 371 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
297}; 372};
298 373
299#define F_D_IN 1
300#define F_D_OUT 2
301#define F_D_OUT_MAYBE 4 /* WRITE SAME, NDOB bit */
302#define F_D_UNKN 8
303#define F_RL_WLUN_OK 0x10
304#define F_SKIP_UA 0x20
305#define F_DELAY_OVERR 0x40
306#define F_SA_LOW 0x80 /* cdb byte 1, bits 4 to 0 */
307#define F_SA_HIGH 0x100 /* as used by variable length cdbs */
308#define F_INV_OP 0x200
309#define F_FAKE_RW 0x400
310#define F_M_ACCESS 0x800 /* media access */
311
312#define FF_RESPOND (F_RL_WLUN_OK | F_SKIP_UA | F_DELAY_OVERR)
313#define FF_DIRECT_IO (F_M_ACCESS | F_FAKE_RW)
314#define FF_SA (F_SA_HIGH | F_SA_LOW)
315
316struct sdebug_dev_info;
317static int resp_inquiry(struct scsi_cmnd *, struct sdebug_dev_info *); 374static int resp_inquiry(struct scsi_cmnd *, struct sdebug_dev_info *);
318static int resp_report_luns(struct scsi_cmnd *, struct sdebug_dev_info *); 375static int resp_report_luns(struct scsi_cmnd *, struct sdebug_dev_info *);
319static int resp_requests(struct scsi_cmnd *, struct sdebug_dev_info *); 376static int resp_requests(struct scsi_cmnd *, struct sdebug_dev_info *);
@@ -336,18 +393,6 @@ static int resp_xdwriteread_10(struct scsi_cmnd *, struct sdebug_dev_info *);
336static int resp_comp_write(struct scsi_cmnd *, struct sdebug_dev_info *); 393static int resp_comp_write(struct scsi_cmnd *, struct sdebug_dev_info *);
337static int resp_write_buffer(struct scsi_cmnd *, struct sdebug_dev_info *); 394static int resp_write_buffer(struct scsi_cmnd *, struct sdebug_dev_info *);
338 395
339struct opcode_info_t {
340 u8 num_attached; /* 0 if this is it (i.e. a leaf); use 0xff
341 * for terminating element */
342 u8 opcode; /* if num_attached > 0, preferred */
343 u16 sa; /* service action */
344 u32 flags; /* OR-ed set of SDEB_F_* */
345 int (*pfp)(struct scsi_cmnd *, struct sdebug_dev_info *);
346 const struct opcode_info_t *arrp; /* num_attached elements or NULL */
347 u8 len_mask[16]; /* len=len_mask[0], then mask for cdb[1]... */
348 /* ignore cdb bytes after position 15 */
349};
350
351static const struct opcode_info_t msense_iarr[1] = { 396static const struct opcode_info_t msense_iarr[1] = {
352 {0, 0x1a, 0, F_D_IN, NULL, NULL, 397 {0, 0x1a, 0, F_D_IN, NULL, NULL,
353 {6, 0xe8, 0xff, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, 398 {6, 0xe8, 0xff, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
@@ -508,14 +553,6 @@ static const struct opcode_info_t opcode_info_arr[SDEB_I_LAST_ELEMENT + 1] = {
508 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, 553 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
509}; 554};
510 555
511struct sdebug_scmd_extra_t {
512 bool inj_recovered;
513 bool inj_transport;
514 bool inj_dif;
515 bool inj_dix;
516 bool inj_short;
517};
518
519static int sdebug_add_host = DEF_NUM_HOST; 556static int sdebug_add_host = DEF_NUM_HOST;
520static int sdebug_ato = DEF_ATO; 557static int sdebug_ato = DEF_ATO;
521static int sdebug_jdelay = DEF_JDELAY; /* if > 0 then unit is jiffies */ 558static int sdebug_jdelay = DEF_JDELAY; /* if > 0 then unit is jiffies */
@@ -563,8 +600,6 @@ static atomic_t sdebug_cmnd_count;
563static atomic_t sdebug_completions; 600static atomic_t sdebug_completions;
564static atomic_t sdebug_a_tsf; /* counter of 'almost' TSFs */ 601static atomic_t sdebug_a_tsf; /* counter of 'almost' TSFs */
565 602
566#define DEV_READONLY(TGT) (0)
567
568static unsigned int sdebug_store_sectors; 603static unsigned int sdebug_store_sectors;
569static sector_t sdebug_capacity; /* in sectors */ 604static sector_t sdebug_capacity; /* in sectors */
570 605
@@ -574,58 +609,10 @@ static int sdebug_heads; /* heads per disk */
574static int sdebug_cylinders_per; /* cylinders per surface */ 609static int sdebug_cylinders_per; /* cylinders per surface */
575static int sdebug_sectors_per; /* sectors per cylinder */ 610static int sdebug_sectors_per; /* sectors per cylinder */
576 611
577#define SDEBUG_MAX_PARTS 4
578
579#define SCSI_DEBUG_MAX_CMD_LEN 32
580
581static unsigned int scsi_debug_lbp(void)
582{
583 return 0 == sdebug_fake_rw &&
584 (sdebug_lbpu || sdebug_lbpws || sdebug_lbpws10);
585}
586
587struct sdebug_dev_info {
588 struct list_head dev_list;
589 unsigned int channel;
590 unsigned int target;
591 u64 lun;
592 struct sdebug_host_info *sdbg_host;
593 unsigned long uas_bm[1];
594 atomic_t num_in_q;
595 char stopped; /* TODO: should be atomic */
596 bool used;
597};
598
599struct sdebug_host_info {
600 struct list_head host_list;
601 struct Scsi_Host *shost;
602 struct device dev;
603 struct list_head dev_info_list;
604};
605
606#define to_sdebug_host(d) \
607 container_of(d, struct sdebug_host_info, dev)
608
609static LIST_HEAD(sdebug_host_list); 612static LIST_HEAD(sdebug_host_list);
610static DEFINE_SPINLOCK(sdebug_host_list_lock); 613static DEFINE_SPINLOCK(sdebug_host_list_lock);
611 614
612 615static unsigned char *fake_storep; /* ramdisk storage */
613struct sdebug_defer {
614 struct hrtimer hrt;
615 struct execute_work ew;
616 int qa_indx;
617};
618
619struct sdebug_queued_cmd {
620 /* in_use flagged by a bit in queued_in_use_bm[] */
621 struct sdebug_defer *sd_dp;
622 struct scsi_cmnd * a_cmnd;
623};
624static struct sdebug_queued_cmd queued_arr[SCSI_DEBUG_CANQUEUE];
625static unsigned long queued_in_use_bm[SCSI_DEBUG_CANQUEUE_WORDS];
626
627
628static unsigned char * fake_storep; /* ramdisk storage */
629static struct sd_dif_tuple *dif_storep; /* protection info */ 616static struct sd_dif_tuple *dif_storep; /* protection info */
630static void *map_storep; /* provisioning map */ 617static void *map_storep; /* provisioning map */
631 618
@@ -639,6 +626,9 @@ static int dix_writes;
639static int dix_reads; 626static int dix_reads;
640static int dif_errors; 627static int dif_errors;
641 628
629static struct sdebug_queued_cmd queued_arr[SCSI_DEBUG_CANQUEUE];
630static unsigned long queued_in_use_bm[SCSI_DEBUG_CANQUEUE_WORDS];
631
642static DEFINE_SPINLOCK(queued_arr_lock); 632static DEFINE_SPINLOCK(queued_arr_lock);
643static DEFINE_RWLOCK(atomic_rw); 633static DEFINE_RWLOCK(atomic_rw);
644 634
@@ -661,13 +651,12 @@ static const int illegal_condition_result =
661static const int device_qfull_result = 651static const int device_qfull_result =
662 (DID_OK << 16) | (COMMAND_COMPLETE << 8) | SAM_STAT_TASK_SET_FULL; 652 (DID_OK << 16) | (COMMAND_COMPLETE << 8) | SAM_STAT_TASK_SET_FULL;
663 653
664static unsigned char caching_pg[] = {0x8, 18, 0x14, 0, 0xff, 0xff, 0, 0, 654
665 0xff, 0xff, 0xff, 0xff, 0x80, 0x14, 0, 0, 655static unsigned int scsi_debug_lbp(void)
666 0, 0, 0, 0}; 656{
667static unsigned char ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0, 657 return 0 == sdebug_fake_rw &&
668 0, 0, 0x2, 0x4b}; 658 (sdebug_lbpu || sdebug_lbpws || sdebug_lbpws10);
669static unsigned char iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0, 659}
670 0, 0, 0x0, 0x0};
671 660
672static void *fake_store(unsigned long long lba) 661static void *fake_store(unsigned long long lba)
673{ 662{
@@ -683,9 +672,6 @@ static struct sd_dif_tuple *dif_store(sector_t sector)
683 return dif_storep + sector; 672 return dif_storep + sector;
684} 673}
685 674
686static int sdebug_add_adapter(void);
687static void sdebug_remove_adapter(void);
688
689static void sdebug_max_tgts_luns(void) 675static void sdebug_max_tgts_luns(void)
690{ 676{
691 struct sdebug_host_info *sdbg_host; 677 struct sdebug_host_info *sdbg_host;
@@ -708,9 +694,9 @@ static void sdebug_max_tgts_luns(void)
708enum sdeb_cmd_data {SDEB_IN_DATA = 0, SDEB_IN_CDB = 1}; 694enum sdeb_cmd_data {SDEB_IN_DATA = 0, SDEB_IN_CDB = 1};
709 695
710/* Set in_bit to -1 to indicate no bit position of invalid field */ 696/* Set in_bit to -1 to indicate no bit position of invalid field */
711static void 697static void mk_sense_invalid_fld(struct scsi_cmnd *scp,
712mk_sense_invalid_fld(struct scsi_cmnd *scp, enum sdeb_cmd_data c_d, 698 enum sdeb_cmd_data c_d,
713 int in_byte, int in_bit) 699 int in_byte, int in_bit)
714{ 700{
715 unsigned char *sbuff; 701 unsigned char *sbuff;
716 u8 sks[4]; 702 u8 sks[4];
@@ -768,8 +754,7 @@ static void mk_sense_buffer(struct scsi_cmnd *scp, int key, int asc, int asq)
768 my_name, key, asc, asq); 754 my_name, key, asc, asq);
769} 755}
770 756
771static void 757static void mk_sense_invalid_opcode(struct scsi_cmnd *scp)
772mk_sense_invalid_opcode(struct scsi_cmnd *scp)
773{ 758{
774 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_OPCODE, 0); 759 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_OPCODE, 0);
775} 760}
@@ -1385,6 +1370,9 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1385 return ret; 1370 return ret;
1386} 1371}
1387 1372
1373static unsigned char iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0,
1374 0, 0, 0x0, 0x0};
1375
1388static int resp_requests(struct scsi_cmnd * scp, 1376static int resp_requests(struct scsi_cmnd * scp,
1389 struct sdebug_dev_info * devip) 1377 struct sdebug_dev_info * devip)
1390{ 1378{
@@ -1605,8 +1593,8 @@ static int resp_report_tgtpgs(struct scsi_cmnd * scp,
1605 return ret; 1593 return ret;
1606} 1594}
1607 1595
1608static int 1596static int resp_rsup_opcodes(struct scsi_cmnd *scp,
1609resp_rsup_opcodes(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) 1597 struct sdebug_dev_info *devip)
1610{ 1598{
1611 bool rctd; 1599 bool rctd;
1612 u8 reporting_opts, req_opcode, sdeb_i, supp; 1600 u8 reporting_opts, req_opcode, sdeb_i, supp;
@@ -1756,8 +1744,8 @@ resp_rsup_opcodes(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1756 return errsts; 1744 return errsts;
1757} 1745}
1758 1746
1759static int 1747static int resp_rsup_tmfs(struct scsi_cmnd *scp,
1760resp_rsup_tmfs(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) 1748 struct sdebug_dev_info *devip)
1761{ 1749{
1762 bool repd; 1750 bool repd;
1763 u32 alloc_len, len; 1751 u32 alloc_len, len;
@@ -1823,6 +1811,10 @@ static int resp_format_pg(unsigned char * p, int pcontrol, int target)
1823 return sizeof(format_pg); 1811 return sizeof(format_pg);
1824} 1812}
1825 1813
1814static unsigned char caching_pg[] = {0x8, 18, 0x14, 0, 0xff, 0xff, 0, 0,
1815 0xff, 0xff, 0xff, 0xff, 0x80, 0x14, 0, 0,
1816 0, 0, 0, 0};
1817
1826static int resp_caching_pg(unsigned char * p, int pcontrol, int target) 1818static int resp_caching_pg(unsigned char * p, int pcontrol, int target)
1827{ /* Caching page for mode_sense */ 1819{ /* Caching page for mode_sense */
1828 unsigned char ch_caching_pg[] = {/* 0x8, 18, */ 0x4, 0, 0, 0, 0, 0, 1820 unsigned char ch_caching_pg[] = {/* 0x8, 18, */ 0x4, 0, 0, 0, 0, 0,
@@ -1840,6 +1832,9 @@ static int resp_caching_pg(unsigned char * p, int pcontrol, int target)
1840 return sizeof(caching_pg); 1832 return sizeof(caching_pg);
1841} 1833}
1842 1834
1835static unsigned char ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0,
1836 0, 0, 0x2, 0x4b};
1837
1843static int resp_ctrl_m_pg(unsigned char * p, int pcontrol, int target) 1838static int resp_ctrl_m_pg(unsigned char * p, int pcontrol, int target)
1844{ /* Control mode page for mode_sense */ 1839{ /* Control mode page for mode_sense */
1845 unsigned char ch_ctrl_m_pg[] = {/* 0xa, 10, */ 0x6, 0, 0, 0, 0, 0, 1840 unsigned char ch_ctrl_m_pg[] = {/* 0xa, 10, */ 0x6, 0, 0, 0, 0, 0,
@@ -1938,8 +1933,8 @@ static int resp_sas_sha_m_spg(unsigned char * p, int pcontrol)
1938 1933
1939#define SDEBUG_MAX_MSENSE_SZ 256 1934#define SDEBUG_MAX_MSENSE_SZ 256
1940 1935
1941static int 1936static int resp_mode_sense(struct scsi_cmnd *scp,
1942resp_mode_sense(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) 1937 struct sdebug_dev_info *devip)
1943{ 1938{
1944 unsigned char dbd, llbaa; 1939 unsigned char dbd, llbaa;
1945 int pcontrol, pcode, subpcode, bd_len; 1940 int pcontrol, pcode, subpcode, bd_len;
@@ -1970,7 +1965,7 @@ resp_mode_sense(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1970 (devip->target * 1000) - 3; 1965 (devip->target * 1000) - 3;
1971 /* set DPOFUA bit for disks */ 1966 /* set DPOFUA bit for disks */
1972 if (0 == sdebug_ptype) 1967 if (0 == sdebug_ptype)
1973 dev_spec = (DEV_READONLY(target) ? 0x80 : 0x0) | 0x10; 1968 dev_spec = 0x10; /* would be 0x90 if read-only */
1974 else 1969 else
1975 dev_spec = 0x0; 1970 dev_spec = 0x0;
1976 if (msense_6) { 1971 if (msense_6) {
@@ -2081,8 +2076,8 @@ resp_mode_sense(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2081 2076
2082#define SDEBUG_MAX_MSELECT_SZ 512 2077#define SDEBUG_MAX_MSELECT_SZ 512
2083 2078
2084static int 2079static int resp_mode_select(struct scsi_cmnd *scp,
2085resp_mode_select(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) 2080 struct sdebug_dev_info *devip)
2086{ 2081{
2087 int pf, sp, ps, md_len, bd_len, off, spf, pg_len; 2082 int pf, sp, ps, md_len, bd_len, off, spf, pg_len;
2088 int param_len, res, mpage; 2083 int param_len, res, mpage;
@@ -2280,8 +2275,8 @@ static int check_device_access_params(struct scsi_cmnd *scp,
2280} 2275}
2281 2276
2282/* Returns number of bytes copied or -1 if error. */ 2277/* Returns number of bytes copied or -1 if error. */
2283static int 2278static int do_device_access(struct scsi_cmnd *scmd, u64 lba, u32 num,
2284do_device_access(struct scsi_cmnd *scmd, u64 lba, u32 num, bool do_write) 2279 bool do_write)
2285{ 2280{
2286 int ret; 2281 int ret;
2287 u64 block, rest = 0; 2282 u64 block, rest = 0;
@@ -2323,8 +2318,7 @@ do_device_access(struct scsi_cmnd *scmd, u64 lba, u32 num, bool do_write)
2323/* If fake_store(lba,num) compares equal to arr(num), then copy top half of 2318/* If fake_store(lba,num) compares equal to arr(num), then copy top half of
2324 * arr into fake_store(lba,num) and return true. If comparison fails then 2319 * arr into fake_store(lba,num) and return true. If comparison fails then
2325 * return false. */ 2320 * return false. */
2326static bool 2321static bool comp_write_worker(u64 lba, u32 num, const u8 *arr)
2327comp_write_worker(u64 lba, u32 num, const u8 *arr)
2328{ 2322{
2329 bool res; 2323 bool res;
2330 u64 block, rest = 0; 2324 u64 block, rest = 0;
@@ -2463,8 +2457,7 @@ static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec,
2463 return 0; 2457 return 0;
2464} 2458}
2465 2459
2466static int 2460static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2467resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2468{ 2461{
2469 u8 *cmd = scp->cmnd; 2462 u8 *cmd = scp->cmnd;
2470 u64 lba; 2463 u64 lba;
@@ -2775,8 +2768,7 @@ static void unmap_region(sector_t lba, unsigned int len)
2775 } 2768 }
2776} 2769}
2777 2770
2778static int 2771static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2779resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2780{ 2772{
2781 u8 *cmd = scp->cmnd; 2773 u8 *cmd = scp->cmnd;
2782 u64 lba; 2774 u64 lba;
@@ -2893,9 +2885,8 @@ resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2893 return 0; 2885 return 0;
2894} 2886}
2895 2887
2896static int 2888static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num,
2897resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, u32 ei_lba, 2889 u32 ei_lba, bool unmap, bool ndob)
2898 bool unmap, bool ndob)
2899{ 2890{
2900 unsigned long iflags; 2891 unsigned long iflags;
2901 unsigned long long i; 2892 unsigned long long i;
@@ -2945,8 +2936,8 @@ out:
2945 return 0; 2936 return 0;
2946} 2937}
2947 2938
2948static int 2939static int resp_write_same_10(struct scsi_cmnd *scp,
2949resp_write_same_10(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) 2940 struct sdebug_dev_info *devip)
2950{ 2941{
2951 u8 *cmd = scp->cmnd; 2942 u8 *cmd = scp->cmnd;
2952 u32 lba; 2943 u32 lba;
@@ -2970,8 +2961,8 @@ resp_write_same_10(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2970 return resp_write_same(scp, lba, num, ei_lba, unmap, false); 2961 return resp_write_same(scp, lba, num, ei_lba, unmap, false);
2971} 2962}
2972 2963
2973static int 2964static int resp_write_same_16(struct scsi_cmnd *scp,
2974resp_write_same_16(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) 2965 struct sdebug_dev_info *devip)
2975{ 2966{
2976 u8 *cmd = scp->cmnd; 2967 u8 *cmd = scp->cmnd;
2977 u64 lba; 2968 u64 lba;
@@ -3001,8 +2992,8 @@ resp_write_same_16(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3001/* Note the mode field is in the same position as the (lower) service action 2992/* Note the mode field is in the same position as the (lower) service action
3002 * field. For the Report supported operation codes command, SPC-4 suggests 2993 * field. For the Report supported operation codes command, SPC-4 suggests
3003 * each mode of this command should be reported separately; for future. */ 2994 * each mode of this command should be reported separately; for future. */
3004static int 2995static int resp_write_buffer(struct scsi_cmnd *scp,
3005resp_write_buffer(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) 2996 struct sdebug_dev_info *devip)
3006{ 2997{
3007 u8 *cmd = scp->cmnd; 2998 u8 *cmd = scp->cmnd;
3008 struct scsi_device *sdp = scp->device; 2999 struct scsi_device *sdp = scp->device;
@@ -3047,8 +3038,8 @@ resp_write_buffer(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3047 return 0; 3038 return 0;
3048} 3039}
3049 3040
3050static int 3041static int resp_comp_write(struct scsi_cmnd *scp,
3051resp_comp_write(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) 3042 struct sdebug_dev_info *devip)
3052{ 3043{
3053 u8 *cmd = scp->cmnd; 3044 u8 *cmd = scp->cmnd;
3054 u8 *arr; 3045 u8 *arr;
@@ -3129,8 +3120,7 @@ struct unmap_block_desc {
3129 __be32 __reserved; 3120 __be32 __reserved;
3130}; 3121};
3131 3122
3132static int 3123static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3133resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3134{ 3124{
3135 unsigned char *buf; 3125 unsigned char *buf;
3136 struct unmap_block_desc *desc; 3126 struct unmap_block_desc *desc;
@@ -3188,8 +3178,8 @@ out:
3188 3178
3189#define SDEBUG_GET_LBA_STATUS_LEN 32 3179#define SDEBUG_GET_LBA_STATUS_LEN 32
3190 3180
3191static int 3181static int resp_get_lba_status(struct scsi_cmnd *scp,
3192resp_get_lba_status(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) 3182 struct sdebug_dev_info *devip)
3193{ 3183{
3194 u8 *cmd = scp->cmnd; 3184 u8 *cmd = scp->cmnd;
3195 u64 lba; 3185 u64 lba;
@@ -3323,8 +3313,8 @@ static int resp_xdwriteread(struct scsi_cmnd *scp, unsigned long long lba,
3323 return 0; 3313 return 0;
3324} 3314}
3325 3315
3326static int 3316static int resp_xdwriteread_10(struct scsi_cmnd *scp,
3327resp_xdwriteread_10(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) 3317 struct sdebug_dev_info *devip)
3328{ 3318{
3329 u8 *cmd = scp->cmnd; 3319 u8 *cmd = scp->cmnd;
3330 u64 lba; 3320 u64 lba;
@@ -3350,8 +3340,7 @@ resp_xdwriteread_10(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3350} 3340}
3351 3341
3352/* Queued command completions converge here. */ 3342/* Queued command completions converge here. */
3353static void 3343static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp)
3354sdebug_q_cmd_complete(struct sdebug_defer *sd_dp)
3355{ 3344{
3356 int qa_indx; 3345 int qa_indx;
3357 int retiring = 0; 3346 int retiring = 0;
@@ -3409,8 +3398,7 @@ sdebug_q_cmd_complete(struct sdebug_defer *sd_dp)
3409} 3398}
3410 3399
3411/* When high resolution timer goes off this function is called. */ 3400/* When high resolution timer goes off this function is called. */
3412static enum hrtimer_restart 3401static enum hrtimer_restart sdebug_q_cmd_hrt_complete(struct hrtimer *timer)
3413sdebug_q_cmd_hrt_complete(struct hrtimer *timer)
3414{ 3402{
3415 struct sdebug_defer *sd_dp = container_of(timer, struct sdebug_defer, 3403 struct sdebug_defer *sd_dp = container_of(timer, struct sdebug_defer,
3416 hrt); 3404 hrt);
@@ -3419,16 +3407,15 @@ sdebug_q_cmd_hrt_complete(struct hrtimer *timer)
3419} 3407}
3420 3408
3421/* When work queue schedules work, it calls this function. */ 3409/* When work queue schedules work, it calls this function. */
3422static void 3410static void sdebug_q_cmd_wq_complete(struct work_struct *work)
3423sdebug_q_cmd_wq_complete(struct work_struct *work)
3424{ 3411{
3425 struct sdebug_defer *sd_dp = container_of(work, struct sdebug_defer, 3412 struct sdebug_defer *sd_dp = container_of(work, struct sdebug_defer,
3426 ew.work); 3413 ew.work);
3427 sdebug_q_cmd_complete(sd_dp); 3414 sdebug_q_cmd_complete(sd_dp);
3428} 3415}
3429 3416
3430static struct sdebug_dev_info * 3417static struct sdebug_dev_info *sdebug_device_create(
3431sdebug_device_create(struct sdebug_host_info *sdbg_host, gfp_t flags) 3418 struct sdebug_host_info *sdbg_host, gfp_t flags)
3432{ 3419{
3433 struct sdebug_dev_info *devip; 3420 struct sdebug_dev_info *devip;
3434 3421
@@ -3794,9 +3781,8 @@ static void __init sdebug_build_parts(unsigned char *ramp,
3794 } 3781 }
3795} 3782}
3796 3783
3797static int 3784static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip,
3798schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, 3785 int scsi_result, int delta_jiff)
3799 int scsi_result, int delta_jiff)
3800{ 3786{
3801 unsigned long iflags; 3787 unsigned long iflags;
3802 int k, num_in_q, qdepth, inject; 3788 int k, num_in_q, qdepth, inject;
@@ -4020,7 +4006,8 @@ static const char * scsi_debug_info(struct Scsi_Host * shp)
4020} 4006}
4021 4007
4022/* 'echo <val> > /proc/scsi/scsi_debug/<host_id>' writes to opts */ 4008/* 'echo <val> > /proc/scsi/scsi_debug/<host_id>' writes to opts */
4023static int scsi_debug_write_info(struct Scsi_Host *host, char *buffer, int length) 4009static int scsi_debug_write_info(struct Scsi_Host *host, char *buffer,
4010 int length)
4024{ 4011{
4025 char arr[16]; 4012 char arr[16];
4026 int opts; 4013 int opts;
@@ -4124,7 +4111,7 @@ static ssize_t ndelay_show(struct device_driver *ddp, char *buf)
4124/* Returns -EBUSY if ndelay is being changed and commands are queued */ 4111/* Returns -EBUSY if ndelay is being changed and commands are queued */
4125/* If > 0 and accepted then sdebug_jdelay is set to JDELAY_OVERRIDDEN */ 4112/* If > 0 and accepted then sdebug_jdelay is set to JDELAY_OVERRIDDEN */
4126static ssize_t ndelay_store(struct device_driver *ddp, const char *buf, 4113static ssize_t ndelay_store(struct device_driver *ddp, const char *buf,
4127 size_t count) 4114 size_t count)
4128{ 4115{
4129 unsigned long iflags; 4116 unsigned long iflags;
4130 int ndelay, res, k; 4117 int ndelay, res, k;
@@ -4433,6 +4420,9 @@ static ssize_t add_host_show(struct device_driver *ddp, char *buf)
4433 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_add_host); 4420 return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_add_host);
4434} 4421}
4435 4422
4423static int sdebug_add_adapter(void);
4424static void sdebug_remove_adapter(void);
4425
4436static ssize_t add_host_store(struct device_driver *ddp, const char *buf, 4426static ssize_t add_host_store(struct device_driver *ddp, const char *buf,
4437 size_t count) 4427 size_t count)
4438{ 4428{
@@ -4902,8 +4892,7 @@ static void sdebug_remove_adapter(void)
4902 --sdebug_add_host; 4892 --sdebug_add_host;
4903} 4893}
4904 4894
4905static int 4895static int sdebug_change_qdepth(struct scsi_device *sdev, int qdepth)
4906sdebug_change_qdepth(struct scsi_device *sdev, int qdepth)
4907{ 4896{
4908 int num_in_q = 0; 4897 int num_in_q = 0;
4909 unsigned long iflags; 4898 unsigned long iflags;
@@ -4933,8 +4922,7 @@ sdebug_change_qdepth(struct scsi_device *sdev, int qdepth)
4933 return sdev->queue_depth; 4922 return sdev->queue_depth;
4934} 4923}
4935 4924
4936static int 4925static int check_inject(struct scsi_cmnd *scp)
4937check_inject(struct scsi_cmnd *scp)
4938{ 4926{
4939 struct sdebug_scmd_extra_t *ep = scsi_cmd_priv(scp); 4927 struct sdebug_scmd_extra_t *ep = scsi_cmd_priv(scp);
4940 4928
@@ -4965,8 +4953,8 @@ check_inject(struct scsi_cmnd *scp)
4965 return 0; 4953 return 0;
4966} 4954}
4967 4955
4968static int 4956static int scsi_debug_queuecommand(struct Scsi_Host *shost,
4969scsi_debug_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scp) 4957 struct scsi_cmnd *scp)
4970{ 4958{
4971 u8 sdeb_i; 4959 u8 sdeb_i;
4972 struct scsi_device *sdp = scp->device; 4960 struct scsi_device *sdp = scp->device;