4 * Copyright (C) 2004 - 2009 Vladislav Bolkhovitin <vst@vlnb.net>
5 * Copyright (C) 2004 - 2005 Leonid Stoljar
6 * Copyright (C) 2007 - 2009 ID7 Ltd.
8 * Main SCSI target mid-level include file.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation, version 2
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
24 #include <linux/types.h>
25 #include <linux/version.h>
26 #include <linux/blkdev.h>
27 #include <linux/interrupt.h>
28 #include <linux/proc_fs.h>
29 #include <linux/wait.h>
31 #include <scsi/scsi_cmnd.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_eh.h>
34 #include <scsi/scsi.h>
36 #include <scst_const.h>
38 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
39 #ifndef RHEL_RELEASE_CODE
49 * Version numbers, the same as for the kernel.
51 * Changing it don't forget to change SCST_FIO_REV in scst_vdisk.c
52 * and FIO_REV in usr/fileio/common.h as well.
54 #define SCST_VERSION(a, b, c, d) (((a) << 24) + ((b) << 16) + ((c) << 8) + d)
55 #define SCST_VERSION_CODE SCST_VERSION(1, 0, 2, 0)
56 #define SCST_VERSION_STRING "1.0.2"
57 #define SCST_INTERFACE_VERSION \
58 SCST_VERSION_STRING "$Revision$" SCST_CONST_VERSION
61 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18))
62 #define COMPLETION_INITIALIZER_ONSTACK(work) \
63 ({ init_completion(&work); work; })
66 * Lockdep needs to run a non-constant initializer for on-stack
67 * completions - so we use the _ONSTACK() variant for those that
68 * are on the kernel stack:
71 # define DECLARE_COMPLETION_ONSTACK(work) \
72 struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
74 # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
79 #define SCST_LOCAL_NAME "scst_lcl_drvr"
81 /*************************************************************
82 ** States of command processing state machine. At first,
83 ** "active" states, then - "passive" ones. This is to have
84 ** more efficient generated code of the corresponding
85 ** "switch" statements.
86 *************************************************************/
88 /* Internal parsing */
89 #define SCST_CMD_STATE_PRE_PARSE 0
91 /* Dev handler's parse() is going to be called */
92 #define SCST_CMD_STATE_DEV_PARSE 1
94 /* Allocation of the cmd's data buffer */
95 #define SCST_CMD_STATE_PREPARE_SPACE 2
97 /* Target driver's rdy_to_xfer() is going to be called */
98 #define SCST_CMD_STATE_RDY_TO_XFER 3
100 /* Target driver's pre_exec() is going to be called */
101 #define SCST_CMD_STATE_TGT_PRE_EXEC 4
103 /* Cmd is going to be sent for execution */
104 #define SCST_CMD_STATE_SEND_FOR_EXEC 5
106 /* Cmd is being checked if it should be executed locally */
107 #define SCST_CMD_STATE_LOCAL_EXEC 6
109 /* Cmd is ready for execution */
110 #define SCST_CMD_STATE_REAL_EXEC 7
112 /* Internal post-exec checks */
113 #define SCST_CMD_STATE_PRE_DEV_DONE 8
115 /* Internal MODE SELECT pages related checks */
116 #define SCST_CMD_STATE_MODE_SELECT_CHECKS 9
118 /* Dev handler's dev_done() is going to be called */
119 #define SCST_CMD_STATE_DEV_DONE 10
121 /* Target driver's xmit_response() is going to be called */
122 #define SCST_CMD_STATE_PRE_XMIT_RESP 11
124 /* Target driver's xmit_response() is going to be called */
125 #define SCST_CMD_STATE_XMIT_RESP 12
128 #define SCST_CMD_STATE_FINISHED 13
130 /* Internal cmd finished */
131 #define SCST_CMD_STATE_FINISHED_INTERNAL 14
133 #define SCST_CMD_STATE_LAST_ACTIVE (SCST_CMD_STATE_FINISHED_INTERNAL+100)
135 /* A cmd is created, but scst_cmd_init_done() not called */
136 #define SCST_CMD_STATE_INIT_WAIT (SCST_CMD_STATE_LAST_ACTIVE+1)
138 /* LUN translation (cmd->tgt_dev assignment) */
139 #define SCST_CMD_STATE_INIT (SCST_CMD_STATE_LAST_ACTIVE+2)
141 /* Allocation of the cmd's data buffer */
142 #define SCST_CMD_STATE_PREPROCESS_DONE (SCST_CMD_STATE_LAST_ACTIVE+3)
144 /* Waiting for data from the initiator (until scst_rx_data() called) */
145 #define SCST_CMD_STATE_DATA_WAIT (SCST_CMD_STATE_LAST_ACTIVE+4)
147 /* Waiting for CDB's execution finish */
148 #define SCST_CMD_STATE_REAL_EXECUTING (SCST_CMD_STATE_LAST_ACTIVE+5)
150 /* Waiting for response's transmission finish */
151 #define SCST_CMD_STATE_XMIT_WAIT (SCST_CMD_STATE_LAST_ACTIVE+6)
153 /*************************************************************
154 * Can be retuned instead of cmd's state by dev handlers'
155 * functions, if the command's state should be set by default
156 *************************************************************/
157 #define SCST_CMD_STATE_DEFAULT 500
159 /*************************************************************
160 * Can be retuned instead of cmd's state by dev handlers'
161 * functions, if it is impossible to complete requested
162 * task in atomic context. The cmd will be restarted in thread
164 *************************************************************/
165 #define SCST_CMD_STATE_NEED_THREAD_CTX 1000
167 /*************************************************************
168 * Can be retuned instead of cmd's state by dev handlers'
169 * parse function, if the cmd processing should be stopped
170 * for now. The cmd will be restarted by dev handlers itself.
171 *************************************************************/
172 #define SCST_CMD_STATE_STOP 1001
174 /*************************************************************
175 ** States of mgmt command processing state machine
176 *************************************************************/
178 /* LUN translation (mcmd->tgt_dev assignment) */
179 #define SCST_MCMD_STATE_INIT 0
181 /* Mgmt cmd is ready for processing */
182 #define SCST_MCMD_STATE_READY 1
184 /* Mgmt cmd is being executing */
185 #define SCST_MCMD_STATE_EXECUTING 2
187 /* Post check when affected commands done */
188 #define SCST_MCMD_STATE_POST_AFFECTED_CMDS_DONE 3
190 /* Target driver's task_mgmt_fn_done() is going to be called */
191 #define SCST_MCMD_STATE_DONE 4
193 /* The mcmd finished */
194 #define SCST_MCMD_STATE_FINISHED 5
196 /*************************************************************
197 ** Constants for "atomic" parameter of SCST's functions
198 *************************************************************/
199 #define SCST_NON_ATOMIC 0
200 #define SCST_ATOMIC 1
202 /*************************************************************
203 ** Values for pref_context parameter of scst_cmd_init_done(),
204 ** scst_rx_data(), scst_restart_cmd(), scst_tgt_cmd_done()
205 ** and scst_cmd_done()
206 *************************************************************/
208 enum scst_exec_context {
210 * Direct cmd's processing (i.e. regular function calls in the current
211 * context) sleeping is not allowed
213 SCST_CONTEXT_DIRECT_ATOMIC,
216 * Direct cmd's processing (i.e. regular function calls in the current
217 * context), sleeping is allowed, no restrictions
221 /* Tasklet or thread context required for cmd's processing */
222 SCST_CONTEXT_TASKLET,
224 /* Thread context required for cmd's processing */
228 * Context is the same as it was in previous call of the corresponding
229 * callback. For example, if dev handler's exec() does sync. data
230 * reading this value should be used for scst_cmd_done(). The same is
231 * true if scst_tgt_cmd_done() called directly from target driver's
232 * xmit_response(). Not allowed in scst_cmd_init_done() and
233 * scst_cmd_init_stage1_done().
238 /*************************************************************
239 ** Values for status parameter of scst_rx_data()
240 *************************************************************/
243 #define SCST_RX_STATUS_SUCCESS 0
246 * Data receiving finished with error, so set the sense and
247 * finish the command, including xmit_response() call
249 #define SCST_RX_STATUS_ERROR 1
252 * Data receiving finished with error and the sense is set,
253 * so finish the command, including xmit_response() call
255 #define SCST_RX_STATUS_ERROR_SENSE_SET 2
258 * Data receiving finished with fatal error, so finish the command,
259 * but don't call xmit_response()
261 #define SCST_RX_STATUS_ERROR_FATAL 3
263 /*************************************************************
264 ** Values for status parameter of scst_restart_cmd()
265 *************************************************************/
268 #define SCST_PREPROCESS_STATUS_SUCCESS 0
271 * Command's processing finished with error, so set the sense and
272 * finish the command, including xmit_response() call
274 #define SCST_PREPROCESS_STATUS_ERROR 1
277 * Command's processing finished with error and the sense is set,
278 * so finish the command, including xmit_response() call
280 #define SCST_PREPROCESS_STATUS_ERROR_SENSE_SET 2
283 * Command's processing finished with fatal error, so finish the command,
284 * but don't call xmit_response()
286 #define SCST_PREPROCESS_STATUS_ERROR_FATAL 3
288 /* Thread context requested */
289 #define SCST_PREPROCESS_STATUS_NEED_THREAD 4
291 /*************************************************************
292 ** Values for AEN functions
293 *************************************************************/
296 * SCSI Asynchronous Event. Parameter contains SCSI sense
297 * (Unit Attention). AENs generated only for 2 the following UAs:
298 * CAPACITY DATA HAS CHANGED and REPORTED LUNS DATA HAS CHANGED.
299 * Other UAs reported regularly as CHECK CONDITION status,
300 * because it doesn't look safe to report them using AENs, since
301 * reporting using AENs opens delivery race windows even in case of
304 #define SCST_AEN_SCSI 0
306 /*************************************************************
307 ** Allowed return/status codes for report_aen() callback and
308 ** scst_set_aen_delivery_status() function
309 *************************************************************/
312 #define SCST_AEN_RES_SUCCESS 0
315 #define SCST_AEN_RES_NOT_SUPPORTED -1
318 #define SCST_AEN_RES_FAILED -2
320 /*************************************************************
321 ** Allowed return codes for xmit_response(), rdy_to_xfer()
322 *************************************************************/
325 #define SCST_TGT_RES_SUCCESS 0
327 /* Internal device queue is full, retry again later */
328 #define SCST_TGT_RES_QUEUE_FULL -1
331 * It is impossible to complete requested task in atomic context.
332 * The cmd will be restarted in thread context.
334 #define SCST_TGT_RES_NEED_THREAD_CTX -2
337 * Fatal error, if returned by xmit_response() the cmd will
338 * be destroyed, if by any other function, xmit_response()
339 * will be called with HARDWARE ERROR sense data
341 #define SCST_TGT_RES_FATAL_ERROR -3
343 /*************************************************************
344 ** Allowed return codes for dev handler's exec()
345 *************************************************************/
347 /* The cmd is done, go to other ones */
348 #define SCST_EXEC_COMPLETED 0
350 /* The cmd should be sent to SCSI mid-level */
351 #define SCST_EXEC_NOT_COMPLETED 1
354 * Thread context is required to execute the command.
355 * Exec() will be called again in the thread context.
357 #define SCST_EXEC_NEED_THREAD 2
360 * Set if cmd is finished and there is status/sense to be sent.
361 * The status should be not sent (i.e. the flag not set) if the
362 * possibility to perform a command in "chunks" (i.e. with multiple
363 * xmit_response()/rdy_to_xfer()) is used (not implemented yet).
364 * Obsolete, use scst_cmd_get_is_send_status() instead.
366 #define SCST_TSC_FLAG_STATUS 0x2
368 /*************************************************************
369 ** Additional return code for dev handler's task_mgmt_fn()
370 *************************************************************/
372 /* Regular standard actions for the command should be done */
373 #define SCST_DEV_TM_NOT_COMPLETED 1
375 /*************************************************************
376 ** Session initialization phases
377 *************************************************************/
379 /* Set if session is being initialized */
380 #define SCST_SESS_IPH_INITING 0
382 /* Set if the session is successfully initialized */
383 #define SCST_SESS_IPH_SUCCESS 1
385 /* Set if the session initialization failed */
386 #define SCST_SESS_IPH_FAILED 2
388 /* Set if session is initialized and ready */
389 #define SCST_SESS_IPH_READY 3
391 /*************************************************************
392 ** Session shutdown phases
393 *************************************************************/
395 /* Set if session is initialized and ready */
396 #define SCST_SESS_SPH_READY 0
398 /* Set if session is shutting down */
399 #define SCST_SESS_SPH_SHUTDOWN 1
401 /*************************************************************
402 ** Session's async (atomic) flags
403 *************************************************************/
405 /* Set if the sess's hw pending work is scheduled */
406 #define SCST_SESS_HW_PENDING_WORK_SCHEDULED 0
408 /*************************************************************
409 ** Cmd's async (atomic) flags
410 *************************************************************/
412 /* Set if the cmd is aborted and ABORTED sense will be sent as the result */
413 #define SCST_CMD_ABORTED 0
415 /* Set if the cmd is aborted by other initiator */
416 #define SCST_CMD_ABORTED_OTHER 1
418 /* Set if the cmd is aborted and counted in cmd_done_wait_count */
419 #define SCST_CMD_DONE_COUNTED 2
421 /* Set if no response should be sent to the target about this cmd */
422 #define SCST_CMD_NO_RESP 3
424 /* Set if the cmd is dead and can be destroyed at any time */
425 #define SCST_CMD_CAN_BE_DESTROYED 4
427 /*************************************************************
428 ** Tgt_dev's async. flags (tgt_dev_flags)
429 *************************************************************/
431 /* Set if tgt_dev has Unit Attention sense */
432 #define SCST_TGT_DEV_UA_PENDING 0
434 /* Set if tgt_dev is RESERVED by another session */
435 #define SCST_TGT_DEV_RESERVED 1
437 /* Set if the corresponding context is atomic */
438 #define SCST_TGT_DEV_AFTER_INIT_WR_ATOMIC 5
439 #define SCST_TGT_DEV_AFTER_INIT_OTH_ATOMIC 6
440 #define SCST_TGT_DEV_AFTER_RESTART_WR_ATOMIC 7
441 #define SCST_TGT_DEV_AFTER_RESTART_OTH_ATOMIC 8
442 #define SCST_TGT_DEV_AFTER_RX_DATA_ATOMIC 9
443 #define SCST_TGT_DEV_AFTER_EXEC_ATOMIC 10
445 #define SCST_TGT_DEV_CLUST_POOL 11
447 /*************************************************************
448 ** Name of the entry in /proc
449 *************************************************************/
450 #define SCST_PROC_ENTRY_NAME "scsi_tgt"
452 /*************************************************************
453 ** Activities suspending timeout
454 *************************************************************/
455 #define SCST_SUSPENDING_TIMEOUT (90 * HZ)
457 /*************************************************************
458 ** Kernel cache creation helper
459 *************************************************************/
461 #define KMEM_CACHE(__struct, __flags) kmem_cache_create(#__struct,\
462 sizeof(struct __struct), __alignof__(struct __struct),\
463 (__flags), NULL, NULL)
466 /*************************************************************
467 ** Vlaid_mask constants for scst_analyze_sense()
468 *************************************************************/
470 #define SCST_SENSE_KEY_VALID 1
471 #define SCST_SENSE_ASC_VALID 2
472 #define SCST_SENSE_ASCQ_VALID 4
474 #define SCST_SENSE_ASCx_VALID (SCST_SENSE_ASC_VALID | \
475 SCST_SENSE_ASCQ_VALID)
477 #define SCST_SENSE_ALL_VALID (SCST_SENSE_KEY_VALID | \
478 SCST_SENSE_ASC_VALID | \
479 SCST_SENSE_ASCQ_VALID)
481 /*************************************************************
483 *************************************************************/
488 struct scst_mgmt_cmd;
491 struct scst_dev_type;
498 * SCST uses 64-bit numbers to represent LUN's internally. The value
499 * NO_SUCH_LUN is guaranteed to be different of every valid LUN.
501 #define NO_SUCH_LUN ((uint64_t)-1)
503 typedef enum dma_data_direction scst_data_direction;
505 enum scst_cdb_flags {
506 /* SCST_TRANSFER_LEN_TYPE_FIXED must be equiv 1 (FIXED_BIT in cdb) */
507 SCST_TRANSFER_LEN_TYPE_FIXED = 0x001,
508 SCST_SMALL_TIMEOUT = 0x002,
509 SCST_LONG_TIMEOUT = 0x004,
510 SCST_UNKNOWN_LENGTH = 0x008,
511 SCST_INFO_NOT_FOUND = 0x010, /* must be single bit */
512 SCST_VERIFY_BYTCHK_MISMATCH_ALLOWED = 0x020,
513 SCST_IMPLICIT_HQ = 0x040,
514 SCST_SKIP_UA = 0x080,
515 SCST_WRITE_MEDIUM = 0x100,
516 SCST_LOCAL_CMD = 0x200,
517 SCST_LOCAL_EXEC_NEEDED = 0x400,
521 * Scsi_Target_Template: defines what functions a target driver will
522 * have to provide in order to work with the target mid-level.
523 * MUST HAVEs define functions that are expected to be in order to work.
524 * OPTIONAL says that there is a choice.
526 * Also, pay attention to the fact that a command is BLOCKING or NON-BLOCKING.
527 * NON-BLOCKING means that a function returns immediately and will not wait
528 * for actual data transfer to finish. Blocking in such command could have
529 * negative impact on overall system performance. If blocking is necessary,
530 * it is worth to consider creating dedicated thread(s) in target driver, to
531 * which the commands would be passed and which would perform blocking
532 * operations instead of SCST.
534 * If the function allowed to sleep or not is determined by its last
535 * argument, which is true, if sleeping is not allowed. In this case,
536 * if the function requires sleeping, it can return
537 * SCST_TGT_RES_NEED_THREAD_CTX, and it will be recalled in the thread context,
538 * where sleeping is allowed.
540 struct scst_tgt_template {
544 * SG tablesize allows to check whether scatter/gather can be used
550 * True, if this target adapter uses unchecked DMA onto an ISA bus.
552 unsigned unchecked_isa_dma:1;
555 * True, if this target adapter can benefit from using SG-vector
556 * clustering (i.e. smaller number of segments).
558 unsigned use_clustering:1;
561 * True, if this target adapter doesn't support SG-vector clustering
563 unsigned no_clustering:1;
566 * True, if corresponding function supports execution in
567 * the atomic (non-sleeping) context
569 unsigned xmit_response_atomic:1;
570 unsigned rdy_to_xfer_atomic:1;
572 /* True, if the template doesn't need the entry in /proc */
573 unsigned no_proc_entry:1;
576 * The maximum time in seconds cmd can stay inside the target
577 * hardware, i.e. after rdy_to_xfer() and xmit_response(), before
578 * on_hw_pending_cmd_timeout() will be called, if defined.
580 * In the current implementation a cmd will be aborted in time t
581 * max_hw_pending_time <= t < 2*max_hw_pending_time.
583 int max_hw_pending_time;
586 * This function is equivalent to the SCSI
587 * queuecommand. The target should transmit the response
588 * buffer and the status in the scst_cmd struct.
589 * The expectation is that this executing this command is NON-BLOCKING.
591 * After the response is actually transmitted, the target
592 * should call the scst_tgt_cmd_done() function of the
593 * mid-level, which will allow it to free up the command.
594 * Returns one of the SCST_TGT_RES_* constants.
596 * Pay attention to "atomic" attribute of the cmd, which can be get
597 * by scst_cmd_atomic(): it is true if the function called in the
598 * atomic (non-sleeping) context.
602 int (*xmit_response) (struct scst_cmd *cmd);
605 * This function informs the driver that data
606 * buffer corresponding to the said command have now been
607 * allocated and it is OK to receive data for this command.
608 * This function is necessary because a SCSI target does not
609 * have any control over the commands it receives. Most lower
610 * level protocols have a corresponding function which informs
611 * the initiator that buffers have been allocated e.g., XFER_
612 * RDY in Fibre Channel. After the data is actually received
613 * the low-level driver needs to call scst_rx_data() in order to
614 * continue processing this command.
615 * Returns one of the SCST_TGT_RES_* constants.
616 * This command is expected to be NON-BLOCKING.
618 * Pay attention to "atomic" attribute of the cmd, which can be get
619 * by scst_cmd_atomic(): it is true if the function called in the
620 * atomic (non-sleeping) context.
624 int (*rdy_to_xfer) (struct scst_cmd *cmd);
627 * Called if cmd stays inside the target hardware, i.e. after
628 * rdy_to_xfer() and xmit_response(), more than max_hw_pending_time
629 * time. The target driver supposed to cleanup this command and
630 * resume cmd's processing.
634 void (*on_hw_pending_cmd_timeout) (struct scst_cmd *cmd);
637 * Called to notify the driver that the command is about to be freed.
638 * Necessary, because for aborted commands xmit_response() could not
639 * be called. Could be called on IRQ context.
643 void (*on_free_cmd) (struct scst_cmd *cmd);
646 * This function allows target driver to handle data buffer
647 * allocations on its own.
649 * Target driver doesn't have to always allocate buffer in this
650 * function, but if it decide to do it, it must check that
651 * scst_cmd_get_data_buff_alloced() returns 0, otherwise to avoid
652 * double buffer allocation and memory leaks alloc_data_buf() shall
655 * Shall return 0 in case of success or < 0 (preferrably -ENOMEM)
656 * in case of error, or > 0 if the regular SCST allocation should be
657 * done. In case of returning successfully,
658 * scst_cmd->tgt_data_buf_alloced will be set by SCST.
660 * It is possible that both target driver and dev handler request own
661 * memory allocation. In this case, data will be memcpy() between
662 * buffers, where necessary.
664 * If allocation in atomic context - cf. scst_cmd_atomic() - is not
665 * desired or fails and consequently < 0 is returned, this function
666 * will be re-called in thread context.
668 * Please note that the driver will have to handle itself all relevant
669 * details such as scatterlist setup, highmem, freeing the allocated
674 int (*alloc_data_buf) (struct scst_cmd *cmd);
677 * This function informs the driver that data
678 * buffer corresponding to the said command have now been
679 * allocated and other preprocessing tasks have been done.
680 * A target driver could need to do some actions at this stage.
681 * After the target driver done the needed actions, it shall call
682 * scst_restart_cmd() in order to continue processing this command.
684 * Called only if the cmd is queued using scst_cmd_init_stage1_done()
685 * instead of scst_cmd_init_done().
687 * Returns void, the result is expected to be returned using
688 * scst_restart_cmd().
690 * This command is expected to be NON-BLOCKING.
692 * Pay attention to "atomic" attribute of the cmd, which can be get
693 * by scst_cmd_atomic(): it is true if the function called in the
694 * atomic (non-sleeping) context.
698 void (*preprocessing_done) (struct scst_cmd *cmd);
701 * This function informs the driver that the said command is about
704 * Returns one of the SCST_PREPROCESS_* constants.
706 * This command is expected to be NON-BLOCKING.
708 * Pay attention to "atomic" attribute of the cmd, which can be get
709 * by scst_cmd_atomic(): it is true if the function called in the
710 * atomic (non-sleeping) context.
714 int (*pre_exec) (struct scst_cmd *cmd);
717 * This function informs the driver that all affected by the
718 * corresponding task management function commands have beed completed.
719 * No return value expected.
721 * This function is expected to be NON-BLOCKING.
723 * Called without any locks held from a thread context.
727 void (*task_mgmt_affected_cmds_done) (struct scst_mgmt_cmd *mgmt_cmd);
730 * This function informs the driver that the corresponding task
731 * management function has been completed, i.e. all the corresponding
732 * commands completed and freed. No return value expected.
734 * This function is expected to be NON-BLOCKING.
736 * Called without any locks held from a thread context.
738 * MUST HAVE if the target supports task management.
740 void (*task_mgmt_fn_done) (struct scst_mgmt_cmd *mgmt_cmd);
743 * This function should detect the target adapters that
744 * are present in the system. The function should return a value
745 * >= 0 to signify the number of detected target adapters.
746 * A negative value should be returned whenever there is
751 int (*detect) (struct scst_tgt_template *tgt_template);
754 * This function should free up the resources allocated to the device.
755 * The function should return 0 to indicate successful release
756 * or a negative value if there are some issues with the release.
757 * In the current version the return value is ignored.
761 int (*release) (struct scst_tgt *tgt);
764 * This function is used for Asynchronous Event Notifications.
766 * Returns one of the SCST_AEN_RES_* constants.
767 * After AEN is sent, target driver must call scst_aen_done() and,
768 * optionally, scst_set_aen_delivery_status().
770 * This command is expected to be NON-BLOCKING, but can sleep.
772 * MUST HAVE, if low-level protocol supports AENs.
774 int (*report_aen) (struct scst_aen *aen);
777 * Those functions can be used to export the driver's statistics and
778 * other infos to the world outside the kernel as well as to get some
779 * management commands from it.
783 int (*read_proc) (struct seq_file *seq, struct scst_tgt *tgt);
784 int (*write_proc) (char *buffer, char **start, off_t offset,
785 int length, int *eof, struct scst_tgt *tgt);
788 * Name of the template. Must be unique to identify
789 * the template. MUST HAVE
791 const char name[SCST_MAX_NAME];
794 * Number of additional threads to the pool of dedicated threads.
795 * Used if xmit_response() or rdy_to_xfer() is blocking.
796 * It is the target driver's duty to ensure that not more, than that
797 * number of threads, are blocked in those functions at any time.
801 /* Private, must be inited to 0 by memset() */
803 /* List of targets per template, protected by scst_mutex */
804 struct list_head tgt_list;
806 /* List entry of global templates list */
807 struct list_head scst_template_list_entry;
809 /* The pointer to the /proc directory entry */
810 struct proc_dir_entry *proc_tgt_root;
812 /* Device number in /proc */
816 struct scst_dev_type {
817 /* SCSI type of the supported device. MUST HAVE */
821 * True, if corresponding function supports execution in
822 * the atomic (non-sleeping) context
824 unsigned parse_atomic:1;
825 unsigned exec_atomic:1;
826 unsigned dev_done_atomic:1;
828 /* Set, if no /proc files should be automatically created by SCST */
832 * Should be set, if exec() is synchronous. This is a hint to SCST core
833 * to optimize commands order management.
835 unsigned exec_sync:1;
838 * Called to parse CDB from the cmd and initialize
839 * cmd->bufflen and cmd->data_direction (both - REQUIRED).
840 * Returns the command's next state or SCST_CMD_STATE_DEFAULT,
841 * if the next default state should be used, or
842 * SCST_CMD_STATE_NEED_THREAD_CTX if the function called in atomic
843 * context, but requires sleeping, or SCST_CMD_STATE_STOP if the
844 * command should not be further processed for now. In the
845 * SCST_CMD_STATE_NEED_THREAD_CTX case the function
846 * will be recalled in the thread context, where sleeping is allowed.
848 * Pay attention to "atomic" attribute of the cmd, which can be get
849 * by scst_cmd_atomic(): it is true if the function called in the
850 * atomic (non-sleeping) context.
854 int (*parse) (struct scst_cmd *cmd);
857 * Called to execute CDB. Useful, for instance, to implement
858 * data caching. The result of CDB execution is reported via
859 * cmd->scst_cmd_done() callback.
861 * - SCST_EXEC_COMPLETED - the cmd is done, go to other ones
862 * - SCST_EXEC_NEED_THREAD - thread context is required to execute
863 * the command. Exec() will be called again in the thread context.
864 * - SCST_EXEC_NOT_COMPLETED - the cmd should be sent to SCSI
867 * Pay attention to "atomic" attribute of the cmd, which can be get
868 * by scst_cmd_atomic(): it is true if the function called in the
869 * atomic (non-sleeping) context.
871 * If this function provides sync execution, you should set
872 * exec_sync flag and consider to setup dedicated threads by
873 * setting threads_num > 0.
875 * !! If this function is implemented, scst_check_local_events() !!
876 * !! shall be called inside it just before the actual command's !!
879 * OPTIONAL, if not set, the commands will be sent directly to SCSI
882 int (*exec) (struct scst_cmd *cmd);
885 * Called to notify dev handler about the result of cmd execution
886 * and perform some post processing. Cmd's fields is_send_status and
887 * resp_data_len should be set by this function, but SCST offers good
889 * Returns the command's next state or SCST_CMD_STATE_DEFAULT,
890 * if the next default state should be used, or
891 * SCST_CMD_STATE_NEED_THREAD_CTX if the function called in atomic
892 * context, but requires sleeping. In the last case, the function
893 * will be recalled in the thread context, where sleeping is allowed.
895 * Pay attention to "atomic" attribute of the cmd, which can be get
896 * by scst_cmd_atomic(): it is true if the function called in the
897 * atomic (non-sleeping) context.
899 int (*dev_done) (struct scst_cmd *cmd);
902 * Called to notify dev hander that the command is about to be freed.
903 * Could be called on IRQ context.
905 void (*on_free_cmd) (struct scst_cmd *cmd);
908 * Called to execute a task management command.
910 * - SCST_MGMT_STATUS_SUCCESS - the command is done with success,
911 * no firther actions required
912 * - The SCST_MGMT_STATUS_* error code if the command is failed and
913 * no further actions required
914 * - SCST_DEV_TM_NOT_COMPLETED - regular standard actions for the
915 * command should be done
917 * Called without any locks held from a thread context.
919 int (*task_mgmt_fn) (struct scst_mgmt_cmd *mgmt_cmd,
920 struct scst_tgt_dev *tgt_dev);
923 * Called when new device is attaching to the dev handler
924 * Returns 0 on success, error code otherwise.
926 int (*attach) (struct scst_device *dev);
928 /* Called when new device is detaching from the dev handler */
929 void (*detach) (struct scst_device *dev);
932 * Called when new tgt_dev (session) is attaching to the dev handler.
933 * Returns 0 on success, error code otherwise.
935 int (*attach_tgt) (struct scst_tgt_dev *tgt_dev);
937 /* Called when tgt_dev (session) is detaching from the dev handler */
938 void (*detach_tgt) (struct scst_tgt_dev *tgt_dev);
941 * Those functions can be used to export the handler's statistics and
942 * other infos to the world outside the kernel as well as to get some
943 * management commands from it.
947 int (*read_proc) (struct seq_file *seq, struct scst_dev_type *dev_type);
948 int (*write_proc) (char *buffer, char **start, off_t offset,
949 int length, int *eof, struct scst_dev_type *dev_type);
952 * Name of the dev handler. Must be unique. MUST HAVE.
954 * It's SCST_MAX_NAME + few more bytes to match scst_user expectations.
956 char name[SCST_MAX_NAME + 10];
959 * Number of dedicated threads. If 0 - no dedicated threads will
960 * be created, if <0 - creation of dedicated threads is prohibited.
964 struct module *module;
968 /* list entry in scst_dev_type_list */
969 struct list_head dev_type_list_entry;
971 /* The pointer to the /proc directory entry */
972 struct proc_dir_entry *proc_dev_type_root;
976 /* List of remote sessions per target, protected by scst_mutex */
977 struct list_head sess_list;
979 /* List entry of targets per template (tgts_list) */
980 struct list_head tgt_list_entry;
982 struct scst_tgt_template *tgtt; /* corresponding target template */
985 * Maximum SG table size. Needed here, since different cards on the
986 * same target template can have different SG table limitations.
990 /* Used for storage of target driver private stuff */
994 * The following fields used to store and retry cmds if target's
995 * internal queue is full, so the target is unable to accept
996 * the cmd returning QUEUE FULL.
997 * They protected by tgt_lock, where necessary.
999 bool retry_timer_active;
1000 struct timer_list retry_timer;
1001 atomic_t finished_cmds;
1003 spinlock_t tgt_lock;
1004 struct list_head retry_cmd_list;
1006 /* Used to wait until session finished to unregister */
1007 wait_queue_head_t unreg_waitQ;
1009 /* Device number in /proc */
1012 /* Name on the default security group ("Default_target_name") */
1013 char *default_group_name;
1016 /* Hash size and hash fn for hash based lun translation */
1017 #define TGT_DEV_HASH_SHIFT 5
1018 #define TGT_DEV_HASH_SIZE (1 << TGT_DEV_HASH_SHIFT)
1019 #define HASH_VAL(_val) (_val & (TGT_DEV_HASH_SIZE - 1))
1021 struct scst_session {
1023 * Initialization phase, one of SCST_SESS_IPH_* constants, protected by
1028 struct scst_tgt *tgt; /* corresponding target */
1030 /* Used for storage of target driver private stuff */
1033 unsigned long sess_aflags; /* session's async flags */
1036 * Hash list of tgt_dev's for this session, protected by scst_mutex
1037 * and suspended activity
1039 struct list_head sess_tgt_dev_list_hash[TGT_DEV_HASH_SIZE];
1042 * List of cmds in this session. Used to find a cmd in the
1043 * session. Protected by sess_list_lock.
1045 struct list_head search_cmd_list;
1047 spinlock_t sess_list_lock; /* protects search_cmd_list, etc */
1050 * List of cmds in this in the state after PRE_XMIT_RESP. All the cmds
1051 * moved here from search_cmd_list. Needed for hw_pending_work.
1052 * Protected by sess_list_lock.
1054 struct list_head after_pre_xmit_cmd_list;
1056 atomic_t refcnt; /* get/put counter */
1059 * Alive commands for this session. ToDo: make it part of the common
1062 atomic_t sess_cmd_count;
1064 /* Access control for this session and list entry there */
1065 struct scst_acg *acg;
1067 /* List entry for the sessions list inside ACG */
1068 struct list_head acg_sess_list_entry;
1070 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20))
1071 struct delayed_work hw_pending_work;
1073 struct work_struct hw_pending_work;
1076 /* Name of attached initiator */
1077 const char *initiator_name;
1079 /* List entry of sessions per target */
1080 struct list_head sess_list_entry;
1082 /* List entry for the list that keeps session, waiting for the init */
1083 struct list_head sess_init_list_entry;
1086 * List entry for the list that keeps session, waiting for the shutdown
1088 struct list_head sess_shut_list_entry;
1091 * Lists of deferred during session initialization commands.
1092 * Protected by sess_list_lock.
1094 struct list_head init_deferred_cmd_list;
1095 struct list_head init_deferred_mcmd_list;
1098 * Shutdown phase, one of SCST_SESS_SPH_* constants, unprotected.
1099 * Async. relating to init_phase, must be a separate variable, because
1100 * session could be unregistered before async. registration is finished.
1102 unsigned long shut_phase;
1104 /* Used if scst_unregister_session() called in wait mode */
1105 struct completion *shutdown_compl;
1108 * Functions and data for user callbacks from scst_register_session()
1109 * and scst_unregister_session()
1111 void *reg_sess_data;
1112 void (*init_result_fn) (struct scst_session *sess, void *data,
1114 void (*unreg_done_fn) (struct scst_session *sess);
1116 #ifdef CONFIG_SCST_MEASURE_LATENCY /* must be last */
1117 spinlock_t meas_lock;
1118 uint64_t scst_time, processing_time;
1119 unsigned int processed_cmds;
1123 struct scst_cmd_lists {
1124 spinlock_t cmd_list_lock;
1125 struct list_head active_cmd_list;
1126 wait_queue_head_t cmd_list_waitQ;
1127 struct list_head lists_list_entry;
1131 /* List entry for below *_cmd_lists */
1132 struct list_head cmd_list_entry;
1134 /* Pointer to lists of commands with the lock */
1135 struct scst_cmd_lists *cmd_lists;
1139 struct scst_session *sess; /* corresponding session */
1141 /* Cmd state, one of SCST_CMD_STATE_* constants */
1144 /*************************************************************
1146 *************************************************************/
1149 * Set if expected_sn should be incremented, i.e. cmd was sent
1152 unsigned int sent_for_exec:1;
1154 /* Set if the cmd's action is completed */
1155 unsigned int completed:1;
1157 /* Set if we should ignore Unit Attention in scst_check_sense() */
1158 unsigned int ua_ignore:1;
1160 /* Set if cmd is being processed in atomic context */
1161 unsigned int atomic:1;
1163 /* Set if this command was sent in double UA possible state */
1164 unsigned int double_ua_possible:1;
1166 /* Set if this command contains status */
1167 unsigned int is_send_status:1;
1169 /* Set if cmd is being retried */
1170 unsigned int retry:1;
1172 /* Set if cmd is internally generated */
1173 unsigned int internal:1;
1175 /* Set if the device was blocked by scst_inc_on_dev_cmd() (for debug) */
1176 unsigned int inc_blocking:1;
1178 /* Set if the device should be unblocked after cmd's finish */
1179 unsigned int needs_unblocking:1;
1181 /* Set if scst_dec_on_dev_cmd() call is needed on the cmd's finish */
1182 unsigned int dec_on_dev_needed:1;
1184 /* Set if cmd is queued as hw pending */
1185 unsigned int cmd_hw_pending:1;
1188 * Set if the target driver wants to alloc data buffers on its own.
1189 * In this case alloc_data_buf() must be provided in the target driver
1192 unsigned int tgt_need_alloc_data_buf:1;
1195 * Set by SCST if the custom data buffer allocation by the target driver
1198 unsigned int tgt_data_buf_alloced:1;
1200 /* Set if custom data buffer allocated by dev handler */
1201 unsigned int dh_data_buf_alloced:1;
1203 /* Set if the target driver called scst_set_expected() */
1204 unsigned int expected_values_set:1;
1207 * Set if the SG buffer was modified by scst_set_resp_data_len()
1209 unsigned int sg_buff_modified:1;
1212 * Set if scst_cmd_init_stage1_done() called and the target
1213 * want that preprocessing_done() will be called
1215 unsigned int preprocessing_only:1;
1217 /* Set if cmd's SN was set */
1218 unsigned int sn_set:1;
1220 /* Set if hq_cmd_count was incremented */
1221 unsigned int hq_cmd_inced:1;
1224 * Set if scst_cmd_init_stage1_done() called and the target wants
1225 * that the SN for the cmd won't be assigned until scst_restart_cmd()
1227 unsigned int set_sn_on_restart_cmd:1;
1229 /* Set if the cmd's must not use sgv cache for data buffer */
1230 unsigned int no_sgv:1;
1233 * Set if target driver may need to call dma_sync_sg() or similar
1234 * function before transferring cmd' data to the target device
1237 unsigned int may_need_dma_sync:1;
1239 /* Set if the cmd was done or aborted out of its SN */
1240 unsigned int out_of_sn:1;
1242 /* Set if increment expected_sn in cmd->scst_cmd_done() */
1243 unsigned int inc_expected_sn_on_done:1;
1245 /* Set if tgt_sn field is valid */
1246 unsigned int tgt_sn_set:1;
1248 /* Set if cmd is done */
1249 unsigned int done:1;
1251 /* Set if cmd is finished */
1252 unsigned int finished:1;
1255 * Set if the cmd was delayed by task management debugging code.
1256 * Used only if CONFIG_SCST_DEBUG_TM is on.
1258 unsigned int tm_dbg_delayed:1;
1261 * Set if the cmd must be ignored by task management debugging code.
1262 * Used only if CONFIG_SCST_DEBUG_TM is on.
1264 unsigned int tm_dbg_immut:1;
1266 /**************************************************************/
1268 unsigned long cmd_flags; /* cmd's async flags */
1270 /* Keeps status of cmd's status/data delivery to remote initiator */
1271 int delivery_status;
1273 struct scst_tgt_template *tgtt; /* to save extra dereferences */
1274 struct scst_tgt *tgt; /* to save extra dereferences */
1275 struct scst_device *dev; /* to save extra dereferences */
1277 struct scst_tgt_dev *tgt_dev; /* corresponding device for this cmd */
1279 uint64_t lun; /* LUN for this cmd */
1281 unsigned long start_time;
1283 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
1284 struct scsi_request *scsi_req; /* SCSI request */
1287 /* List entry for tgt_dev's SN related lists */
1288 struct list_head sn_cmd_list_entry;
1290 /* Cmd's serial number, used to execute cmd's in order of arrival */
1293 /* The corresponding sn_slot in tgt_dev->sn_slots */
1296 /* List entry for sess's search_cmd_list and after_pre_xmit_cmd_list */
1297 struct list_head sess_cmd_list_entry;
1300 * Used to found the cmd by scst_find_cmd_by_tag(). Set by the
1301 * target driver on the cmd's initialization time
1305 uint32_t tgt_sn; /* SN set by target driver (for TM purposes) */
1307 /* CDB and its len */
1308 uint8_t cdb[SCST_MAX_CDB_SIZE];
1309 short cdb_len; /* it might be -1 */
1310 unsigned short ext_cdb_len;
1313 enum scst_cdb_flags op_flags;
1314 const char *op_name;
1316 enum scst_cmd_queue_type queue_type;
1318 int timeout; /* CDB execution timeout in seconds */
1319 int retries; /* Amount of retries that will be done by SCSI mid-level */
1321 /* SCSI data direction, one of SCST_DATA_* constants */
1322 scst_data_direction data_direction;
1324 /* Remote initiator supplied values, if any */
1325 scst_data_direction expected_data_direction;
1326 int expected_transfer_len;
1327 int expected_in_transfer_len; /* for bidi writes */
1330 * Cmd data length. Could be different from bufflen for commands like
1331 * VERIFY, which transfer different amount of data (if any), than
1336 /* Completition routine */
1337 void (*scst_cmd_done) (struct scst_cmd *cmd, int next_state,
1338 enum scst_exec_context pref_context);
1340 struct sgv_pool_obj *sgv; /* sgv object */
1341 int bufflen; /* cmd buffer length */
1342 struct scatterlist *sg; /* cmd data buffer SG vector */
1343 int sg_cnt; /* SG segments count */
1346 * Response data length in data buffer. This field must not be set
1347 * directly, use scst_set_resp_data_len() for that
1351 /* scst_get_sg_buf_[first,next]() support */
1352 int get_sg_buf_entry_num;
1354 /* Bidirectional transfers support */
1355 int in_bufflen; /* WRITE buffer length */
1356 struct sgv_pool_obj *in_sgv; /* WRITE sgv object */
1357 struct scatterlist *in_sg; /* WRITE data buffer SG vector */
1358 int in_sg_cnt; /* WRITE SG segments count */
1361 * Used if both target driver and dev handler request own memory
1362 * allocation. In other cases, both are equal to sg and sg_cnt
1365 * If target driver requests own memory allocations, it MUST use
1366 * functions scst_cmd_get_tgt_sg*() to get sg and sg_cnt! Otherwise,
1367 * it may use functions scst_cmd_get_sg*().
1369 struct scatterlist *tgt_sg;
1371 struct scatterlist *tgt_in_sg; /* bidirectional */
1372 int tgt_in_sg_cnt; /* bidirectional */
1375 * The status fields in case of errors must be set using
1376 * scst_set_cmd_error_status()!
1378 uint8_t status; /* status byte from target device */
1379 uint8_t msg_status; /* return status from host adapter itself */
1380 uint8_t host_status; /* set by low-level driver to indicate status */
1381 uint8_t driver_status; /* set by mid-level */
1383 uint8_t *sense; /* pointer to sense buffer */
1384 unsigned short sense_bufflen; /* length of the sense buffer, if any */
1386 /* Start time when cmd was sent to rdy_to_xfer() or xmit_response() */
1387 unsigned long hw_pending_start;
1389 /* Used for storage of target driver private stuff */
1392 /* Used for storage of dev handler private stuff */
1396 * Used to restore the SG vector if it was modified by
1397 * scst_set_resp_data_len()
1399 int orig_sg_cnt, orig_sg_entry, orig_entry_len;
1401 /* Used to retry commands in case of double UA */
1402 int dbl_ua_orig_resp_data_len, dbl_ua_orig_data_direction;
1404 /* List corresponding mgmt cmd, if any, protected by sess_list_lock */
1405 struct list_head mgmt_cmd_list;
1407 /* List entry for dev's blocked_cmd_list */
1408 struct list_head blocked_cmd_list_entry;
1410 struct scst_cmd *orig_cmd; /* Used to issue REQUEST SENSE */
1412 #ifdef CONFIG_SCST_MEASURE_LATENCY /* must be last */
1413 uint64_t start, pre_exec_finish, post_exec_start;
1417 struct scst_rx_mgmt_params {
1425 unsigned char tag_set;
1426 unsigned char lun_set;
1427 unsigned char cmd_sn_set;
1430 struct scst_mgmt_cmd_stub {
1431 struct scst_mgmt_cmd *mcmd;
1433 /* List entry in cmd->mgmt_cmd_list */
1434 struct list_head cmd_mgmt_cmd_list_entry;
1437 struct scst_mgmt_cmd {
1438 /* List entry for *_mgmt_cmd_list */
1439 struct list_head mgmt_cmd_list_entry;
1441 struct scst_session *sess;
1443 /* Mgmt cmd state, one of SCST_MCMD_STATE_* constants */
1448 unsigned int completed:1; /* set, if the mcmd is completed */
1449 /* Set if device(s) should be unblocked after mcmd's finish */
1450 unsigned int needs_unblocking:1;
1451 unsigned int lun_set:1; /* set, if lun field is valid */
1452 unsigned int cmd_sn_set:1; /* set, if cmd_sn field is valid */
1453 /* set, if scst_mgmt_affected_cmds_done was called */
1454 unsigned int affected_cmds_done_called:1;
1457 * Number of commands to finish before sending response,
1458 * protected by scst_mcmd_lock
1460 int cmd_finish_wait_count;
1463 * Number of commands to complete (done) before resetting reservation,
1464 * protected by scst_mcmd_lock
1466 int cmd_done_wait_count;
1468 /* Number of completed commands, protected by scst_mcmd_lock */
1469 int completed_cmd_count;
1471 uint64_t lun; /* LUN for this mgmt cmd */
1472 /* or (and for iSCSI) */
1473 uint64_t tag; /* tag of the corresponding cmd */
1475 uint32_t cmd_sn; /* affected command's highest SN */
1477 /* corresponding cmd (to be aborted, found by tag) */
1478 struct scst_cmd *cmd_to_abort;
1480 /* corresponding device for this mgmt cmd (found by lun) */
1481 struct scst_tgt_dev *mcmd_tgt_dev;
1483 /* completition status, one of the SCST_MGMT_STATUS_* constants */
1486 /* Used for storage of target driver private stuff */
1490 struct scst_device {
1491 struct scst_dev_type *handler; /* corresponding dev handler */
1493 struct scst_mem_lim dev_mem_lim;
1495 unsigned short type; /* SCSI type of the device */
1497 /*************************************************************
1498 ** Dev's flags. Updates serialized by dev_lock or suspended
1500 *************************************************************/
1502 /* Set if dev is RESERVED */
1503 unsigned short dev_reserved:1;
1505 /* Set if double reset UA is possible */
1506 unsigned short dev_double_ua_possible:1;
1508 /* If set, dev is read only */
1509 unsigned int rd_only:1;
1511 /**************************************************************/
1513 /*************************************************************
1514 ** Dev's control mode page related values. Updates serialized
1515 ** by scst_block_dev(). It's long to not interfere with the
1517 *************************************************************/
1519 unsigned long queue_alg:4;
1520 unsigned long tst:3;
1521 unsigned long tas:1;
1522 unsigned long swp:1;
1523 unsigned long d_sense:1;
1526 * Set if device implements own ordered commands management. If not set
1527 * and queue_alg is SCST_CONTR_MODE_QUEUE_ALG_RESTRICTED_REORDER,
1528 * expected_sn will be incremented only after commands finished.
1530 unsigned long has_own_order_mgmt:1;
1532 /**************************************************************/
1534 /* Used for storage of dev handler private stuff */
1537 /* Used to translate SCSI's cmd to SCST's cmd */
1538 struct gendisk *rq_disk;
1540 /* Corresponding real SCSI device, could be NULL for virtual devices */
1541 struct scsi_device *scsi_dev;
1543 /* Pointer to lists of commands with the lock */
1544 struct scst_cmd_lists *p_cmd_lists;
1546 /* Lists of commands with lock, if dedicated threads are used */
1547 struct scst_cmd_lists cmd_lists;
1549 /* Per-device dedicated IO context */
1550 struct io_context *dev_io_ctx;
1552 /* How many cmds alive on this dev */
1553 atomic_t dev_cmd_count;
1555 /* How many write cmds alive on this dev. Temporary, ToDo */
1556 atomic_t write_cmd_count;
1558 spinlock_t dev_lock; /* device lock */
1561 * How many times device was blocked for new cmds execution.
1562 * Protected by dev_lock
1567 * How many there are "on_dev" commands, i.e. ones those are being
1568 * executed by the underlying SCSI/virtual device.
1570 atomic_t on_dev_count;
1572 struct list_head blocked_cmd_list; /* protected by dev_lock */
1574 /* Used to wait for requested amount of "on_dev" commands */
1575 wait_queue_head_t on_dev_waitQ;
1577 /* A list entry used during TM, protected by scst_mutex */
1578 struct list_head tm_dev_list_entry;
1580 /* Virtual device internal ID */
1583 /* Pointer to virtual device name, for convenience only */
1584 const char *virt_name;
1586 /* List entry in global devices list */
1587 struct list_head dev_list_entry;
1590 * List of tgt_dev's, one per session, protected by scst_mutex or
1591 * dev_lock for reads and both for writes
1593 struct list_head dev_tgt_dev_list;
1595 /* List of acg_dev's, one per acg, protected by scst_mutex */
1596 struct list_head dev_acg_dev_list;
1598 /* List of dedicated threads, protected by scst_mutex */
1599 struct list_head threads_list;
1606 * Used to store threads local tgt_dev specific data
1608 struct scst_thr_data_hdr {
1609 /* List entry in tgt_dev->thr_data_list */
1610 struct list_head thr_data_list_entry;
1611 struct task_struct *owner_thr; /* the owner thread */
1613 /* Function that will be called on the tgt_dev destruction */
1614 void (*free_fn) (struct scst_thr_data_hdr *data);
1618 * Used to store per-session specific device information
1620 struct scst_tgt_dev {
1621 /* List entry in sess->sess_tgt_dev_list_hash */
1622 struct list_head sess_tgt_dev_list_entry;
1624 struct scst_device *dev; /* to save extra dereferences */
1625 uint64_t lun; /* to save extra dereferences */
1628 struct sgv_pool *pool;
1631 unsigned long tgt_dev_flags; /* tgt_dev's async flags */
1633 /* Used for storage of dev handler private stuff */
1636 /* How many cmds alive on this dev in this session */
1637 atomic_t tgt_dev_cmd_count;
1640 * Used to execute cmd's in order of arrival, honoring SCSI task
1643 * Protected by sn_lock, except expected_sn, which is protected by
1644 * itself. Curr_sn must have the same size as expected_sn to
1645 * overflow simultaneously.
1649 unsigned long expected_sn;
1650 unsigned long curr_sn;
1652 struct list_head deferred_cmd_list;
1653 struct list_head skipped_sn_list;
1656 * Set if the prev cmd was ORDERED. Size must allow unprotected
1657 * modifications independant to the neighbour fields.
1659 unsigned long prev_cmd_ordered;
1661 int num_free_sn_slots; /* if it's <0, then all slots are busy */
1662 atomic_t *cur_sn_slot;
1663 atomic_t sn_slots[15];
1665 /* List of scst_thr_data_hdr and lock */
1666 spinlock_t thr_data_lock;
1667 struct list_head thr_data_list;
1669 /* Per-(device, session) dedicated IO context */
1670 struct io_context *tgt_dev_io_ctx;
1672 spinlock_t tgt_dev_lock; /* per-session device lock */
1674 /* List of UA's for this device, protected by tgt_dev_lock */
1675 struct list_head UA_list;
1677 struct scst_session *sess; /* corresponding session */
1678 struct scst_acg_dev *acg_dev; /* corresponding acg_dev */
1680 /* list entry in dev->dev_tgt_dev_list */
1681 struct list_head dev_tgt_dev_list_entry;
1683 /* internal tmp list entry */
1684 struct list_head extra_tgt_dev_list_entry;
1687 * Stored Unit Attention sense and its length for possible
1688 * subsequent REQUEST SENSE. Both protected by tgt_dev_lock.
1690 unsigned short tgt_dev_valid_sense_len;
1691 uint8_t tgt_dev_sense[SCST_SENSE_BUFFERSIZE];
1695 * Used to store ACG-specific device information, like LUN
1697 struct scst_acg_dev {
1698 struct scst_device *dev; /* corresponding device */
1699 uint64_t lun; /* device's LUN in this acg */
1700 unsigned int rd_only:1; /* if != 0, then read only */
1701 struct scst_acg *acg; /* parent acg */
1703 /* list entry in dev->dev_acg_dev_list */
1704 struct list_head dev_acg_dev_list_entry;
1706 /* list entry in acg->acg_dev_list */
1707 struct list_head acg_dev_list_entry;
1711 * ACG - access control group. Used to store group related
1712 * control information.
1715 /* List of acg_dev's in this acg, protected by scst_mutex */
1716 struct list_head acg_dev_list;
1718 /* List of attached sessions, protected by scst_mutex */
1719 struct list_head acg_sess_list;
1721 /* List of attached acn's, protected by scst_mutex */
1722 struct list_head acn_list;
1724 /* List entry in scst_acg_list */
1725 struct list_head scst_acg_list_entry;
1727 /* Name of this acg */
1728 const char *acg_name;
1730 /* The pointer to the /proc directory entry */
1731 struct proc_dir_entry *acg_proc_root;
1735 * ACN - access control name. Used to store names, by which
1736 * incoming sessions will be assigned to appropriate ACG.
1739 /* Initiator's name */
1741 /* List entry in acg->acn_list */
1742 struct list_head acn_list_entry;
1746 * Used to store per-session UNIT ATTENTIONs
1748 struct scst_tgt_dev_UA {
1749 /* List entry in tgt_dev->UA_list */
1750 struct list_head UA_list_entry;
1752 /* Set if UA is global for session */
1753 unsigned int global_UA:1;
1755 /* Unit Attention sense */
1756 uint8_t UA_sense_buffer[SCST_SENSE_BUFFERSIZE];
1759 /* Used to deliver AENs */
1761 int event_fn; /* AEN fn */
1763 struct scst_session *sess; /* corresponding session */
1764 uint64_t lun; /* corresponding LUN in SCSI form */
1770 uint8_t aen_sense[SCST_STANDARD_SENSE_LEN];
1774 /* Keeps status of AEN's delivery to remote initiator */
1775 int delivery_status;
1778 #ifndef smp_mb__after_set_bit
1779 /* There is no smp_mb__after_set_bit() in the kernel */
1780 #define smp_mb__after_set_bit() smp_mb()
1784 * Registers target template
1785 * Returns 0 on success or appropriate error code otherwise
1787 int __scst_register_target_template(struct scst_tgt_template *vtt,
1788 const char *version);
1789 static inline int scst_register_target_template(struct scst_tgt_template *vtt)
1791 return __scst_register_target_template(vtt, SCST_INTERFACE_VERSION);
1795 * Unregisters target template
1797 void scst_unregister_target_template(struct scst_tgt_template *vtt);
1800 * Registers and returns target adapter
1801 * Returns new target structure on success or NULL otherwise.
1803 * If parameter "target_name" isn't NULL, then security group with name
1804 * "Default_##target_name", if created, will be used as the default
1805 * instead of "Default" one for all initiators not assigned to any other group.
1807 struct scst_tgt *scst_register(struct scst_tgt_template *vtt,
1808 const char *target_name);
1811 * Unregisters target adapter
1813 void scst_unregister(struct scst_tgt *tgt);
1816 * Registers and returns a session
1818 * Returns new session on success or NULL otherwise
1822 * atomic - true, if the function called in the atomic context. If false,
1823 * this function will block until the session registration is completed.
1824 * initiator_name - remote initiator's name, any NULL-terminated string,
1825 * e.g. iSCSI name, which used as the key to found appropriate access
1826 * control group. Could be NULL, then "default" group is used.
1827 * The groups are set up via /proc interface.
1828 * data - any target driver supplied data
1829 * result_fn - pointer to the function that will be
1830 * asynchronously called when session initialization finishes.
1831 * Can be NULL. Parameters:
1833 * - data - target driver supplied to scst_register_session() data
1834 * - result - session initialization result, 0 on success or
1835 * appropriate error code otherwise
1837 * Note: A session creation and initialization is a complex task,
1838 * which requires sleeping state, so it can't be fully done
1839 * in interrupt context. Therefore the "bottom half" of it, if
1840 * scst_register_session() is called from atomic context, will be
1841 * done in SCST thread context. In this case scst_register_session()
1842 * will return not completely initialized session, but the target
1843 * driver can supply commands to this session via scst_rx_cmd().
1844 * Those commands processing will be delayed inside SCST until
1845 * the session initialization is finished, then their processing
1846 * will be restarted. The target driver will be notified about
1847 * finish of the session initialization by function result_fn().
1848 * On success the target driver could do nothing, but if the
1849 * initialization fails, the target driver must ensure that
1850 * no more new commands being sent or will be sent to SCST after
1851 * result_fn() returns. All already sent to SCST commands for
1852 * failed session will be returned in xmit_response() with BUSY status.
1853 * In case of failure the driver shall call scst_unregister_session()
1854 * inside result_fn(), it will NOT be called automatically.
1856 struct scst_session *scst_register_session(struct scst_tgt *tgt, int atomic,
1857 const char *initiator_name, void *data,
1858 void (*result_fn) (struct scst_session *sess, void *data, int result));
1861 * Unregisters a session.
1863 * sess - session to be unregistered
1864 * wait - if true, instructs to wait until all commands, which
1865 * currently is being executed and belonged to the session, finished.
1866 * Otherwise, target driver should be prepared to receive
1867 * xmit_response() for the session's command after
1868 * scst_unregister_session() returns.
1869 * unreg_done_fn - pointer to the function that will be
1870 * asynchronously called when the last session's command finishes and
1871 * the session is about to be completely freed. Can be NULL.
1877 * - All outstanding commands will be finished regularly. After
1878 * scst_unregister_session() returned no new commands must be sent to
1879 * SCST via scst_rx_cmd().
1881 * - The caller must ensure that no scst_rx_cmd() or scst_rx_mgmt_fn_*() is
1882 * called in paralell with scst_unregister_session().
1884 * - Can be called before result_fn() of scst_register_session() called,
1885 * i.e. during the session registration/initialization.
1887 * - It is highly recommended to call scst_unregister_session() as soon as it
1888 * gets clear that session will be unregistered and not to wait until all
1889 * related commands finished. This function provides the wait functionality,
1890 * but it also starts recovering stuck commands, if there are any.
1891 * Otherwise, your target driver could wait for those commands forever.
1893 void scst_unregister_session(struct scst_session *sess, int wait,
1894 void (*unreg_done_fn) (struct scst_session *sess));
1897 * Registers dev handler driver
1898 * Returns 0 on success or appropriate error code otherwise
1900 int __scst_register_dev_driver(struct scst_dev_type *dev_type,
1901 const char *version);
1902 static inline int scst_register_dev_driver(struct scst_dev_type *dev_type)
1904 return __scst_register_dev_driver(dev_type, SCST_INTERFACE_VERSION);
1908 * Unregisters dev handler driver
1910 void scst_unregister_dev_driver(struct scst_dev_type *dev_type);
1913 * Registers dev handler driver for virtual devices (eg VDISK)
1914 * Returns 0 on success or appropriate error code otherwise
1916 int __scst_register_virtual_dev_driver(struct scst_dev_type *dev_type,
1917 const char *version);
1918 static inline int scst_register_virtual_dev_driver(
1919 struct scst_dev_type *dev_type)
1921 return __scst_register_virtual_dev_driver(dev_type,
1922 SCST_INTERFACE_VERSION);
1926 * Unregisters dev handler driver for virtual devices
1928 void scst_unregister_virtual_dev_driver(struct scst_dev_type *dev_type);
1931 * Creates and sends new command to SCST.
1932 * Must not be called in parallel with scst_unregister_session() for the
1933 * same sess. Returns the command on success or NULL otherwise
1935 struct scst_cmd *scst_rx_cmd(struct scst_session *sess,
1936 const uint8_t *lun, int lun_len, const uint8_t *cdb,
1937 int cdb_len, int atomic);
1940 * Notifies SCST that the driver finished its part of the command
1941 * initialization, and the command is ready for execution.
1942 * The second argument sets preferred command execition context.
1943 * See SCST_CONTEXT_* constants for details.
1947 * If cmd->set_sn_on_restart_cmd not set, this function, as well as
1948 * scst_cmd_init_stage1_done() and scst_restart_cmd(), must not be
1949 * called simultaneously for the same session (more precisely,
1950 * for the same session/LUN, i.e. tgt_dev), i.e. they must be
1951 * somehow externally serialized. This is needed to have lock free fast path in
1952 * scst_cmd_set_sn(). For majority of targets those functions are naturally
1953 * serialized by the single source of commands. Only iSCSI immediate commands
1954 * with multiple connections per session seems to be an exception. For it, some
1955 * mutex/lock shall be used for the serialization.
1957 void scst_cmd_init_done(struct scst_cmd *cmd,
1958 enum scst_exec_context pref_context);
1961 * Notifies SCST that the driver finished the first stage of the command
1962 * initialization, and the command is ready for execution, but after
1963 * SCST done the command's preprocessing preprocessing_done() function
1964 * should be called. The second argument sets preferred command execition
1965 * context. See SCST_CONTEXT_* constants for details.
1967 * See also scst_cmd_init_done() comment for the serialization requirements.
1969 static inline void scst_cmd_init_stage1_done(struct scst_cmd *cmd,
1970 enum scst_exec_context pref_context, int set_sn)
1972 cmd->preprocessing_only = 1;
1973 cmd->set_sn_on_restart_cmd = !set_sn;
1974 scst_cmd_init_done(cmd, pref_context);
1978 * Notifies SCST that the driver finished its part of the command's
1979 * preprocessing and it is ready for further processing.
1980 * The second argument sets data receiving completion status
1981 * (see SCST_PREPROCESS_STATUS_* constants for details)
1982 * The third argument sets preferred command execition context
1983 * (see SCST_CONTEXT_* constants for details).
1985 * See also scst_cmd_init_done() comment for the serialization requirements.
1987 void scst_restart_cmd(struct scst_cmd *cmd, int status,
1988 enum scst_exec_context pref_context);
1991 * Notifies SCST that the driver received all the necessary data
1992 * and the command is ready for further processing.
1993 * The second argument sets data receiving completion status
1994 * (see SCST_RX_STATUS_* constants for details)
1995 * The third argument sets preferred command execition context
1996 * (see SCST_CONTEXT_* constants for details)
1998 void scst_rx_data(struct scst_cmd *cmd, int status,
1999 enum scst_exec_context pref_context);
2002 * Notifies SCST that the driver sent the response and the command
2003 * can be freed now. Don't forget to set the delivery status, if it
2004 * isn't success, using scst_set_delivery_status() before calling
2005 * this function. The third argument sets preferred command execition
2006 * context (see SCST_CONTEXT_* constants for details)
2008 void scst_tgt_cmd_done(struct scst_cmd *cmd,
2009 enum scst_exec_context pref_context);
2012 * Creates new management command sends it for execution.
2013 * Must not be called in parallel with scst_unregister_session() for the
2014 * same sess. Returns 0 for success, error code otherwise.
2016 int scst_rx_mgmt_fn(struct scst_session *sess,
2017 const struct scst_rx_mgmt_params *params);
2020 * Creates new management command using tag and sends it for execution.
2021 * Can be used for SCST_ABORT_TASK only.
2022 * Must not be called in parallel with scst_unregister_session() for the
2023 * same sess. Returns 0 for success, error code otherwise.
2025 * Obsolete in favor of scst_rx_mgmt_fn()
2027 static inline int scst_rx_mgmt_fn_tag(struct scst_session *sess, int fn,
2028 uint64_t tag, int atomic, void *tgt_priv)
2030 struct scst_rx_mgmt_params params;
2032 BUG_ON(fn != SCST_ABORT_TASK);
2034 memset(¶ms, 0, sizeof(params));
2038 params.atomic = atomic;
2039 params.tgt_priv = tgt_priv;
2040 return scst_rx_mgmt_fn(sess, ¶ms);
2044 * Creates new management command using LUN and sends it for execution.
2045 * Currently can be used for any fn, except SCST_ABORT_TASK.
2046 * Must not be called in parallel with scst_unregister_session() for the
2047 * same sess. Returns 0 for success, error code otherwise.
2049 * Obsolete in favor of scst_rx_mgmt_fn()
2051 static inline int scst_rx_mgmt_fn_lun(struct scst_session *sess, int fn,
2052 const uint8_t *lun, int lun_len, int atomic, void *tgt_priv)
2054 struct scst_rx_mgmt_params params;
2056 BUG_ON(fn == SCST_ABORT_TASK);
2058 memset(¶ms, 0, sizeof(params));
2061 params.lun_len = lun_len;
2063 params.atomic = atomic;
2064 params.tgt_priv = tgt_priv;
2065 return scst_rx_mgmt_fn(sess, ¶ms);
2069 * Provides various info about command's CDB.
2071 * Returns: 0 on success, <0 if command is unknown, >0 if command is invalid.
2073 int scst_get_cdb_info(struct scst_cmd *cmd);
2076 * Set error SCSI status in the command and prepares it for returning it
2078 void scst_set_cmd_error_status(struct scst_cmd *cmd, int status);
2081 * Set error in the command and fill the sense buffer
2083 void scst_set_cmd_error(struct scst_cmd *cmd, int key, int asc, int ascq);
2086 * Sets BUSY or TASK QUEUE FULL status
2088 void scst_set_busy(struct scst_cmd *cmd);
2091 * Check if sense in the sense buffer, if any, in the correct format. If not,
2092 * convert it to the correct format.
2094 void scst_check_convert_sense(struct scst_cmd *cmd);
2097 * Sets initial Unit Attention for sess, replacing default scst_sense_reset_UA
2099 void scst_set_initial_UA(struct scst_session *sess, int key, int asc, int ascq);
2102 * Notifies SCST core that dev changed its capacity
2104 void scst_capacity_data_changed(struct scst_device *dev);
2107 * Finds a command based on the supplied tag comparing it with one
2108 * that previously set by scst_cmd_set_tag().
2109 * Returns the command on success or NULL otherwise
2111 struct scst_cmd *scst_find_cmd_by_tag(struct scst_session *sess, uint64_t tag);
2114 * Finds a command based on user supplied data and comparision
2115 * callback function, that should return true, if the command is found.
2116 * Returns the command on success or NULL otherwise
2118 struct scst_cmd *scst_find_cmd(struct scst_session *sess, void *data,
2119 int (*cmp_fn) (struct scst_cmd *cmd,
2123 * Translates SCST's data direction to DMA one from backend storage
2126 enum dma_data_direction scst_to_dma_dir(int scst_dir);
2129 * Translates SCST data direction to DMA data direction from the perspective
2130 * of the target device.
2132 enum dma_data_direction scst_to_tgt_dma_dir(int scst_dir);
2135 * Returns 1, if cmd's CDB is locally handled by SCST and 0 otherwise.
2136 * Dev handlers parse() and dev_done() not called for such commands.
2138 static inline bool scst_is_cmd_local(struct scst_cmd *cmd)
2140 return (cmd->op_flags & SCST_LOCAL_CMD) != 0;
2144 * Registers a virtual device.
2146 * dev_type - the device's device handler
2147 * dev_name - the new device name, NULL-terminated string. Must be uniq
2148 * among all virtual devices in the system. The value isn't
2149 * copied, only the reference is stored, so the value must
2150 * remain valid during the device lifetime.
2151 * Returns assinged to the device ID on success, or negative value otherwise
2153 int scst_register_virtual_device(struct scst_dev_type *dev_handler,
2154 const char *dev_name);
2157 * Unegisters a virtual device.
2159 * id - the device's ID, returned by the registration function
2161 void scst_unregister_virtual_device(int id);
2164 * Get/Set functions for tgt's sg_tablesize
2166 static inline int scst_tgt_get_sg_tablesize(struct scst_tgt *tgt)
2168 return tgt->sg_tablesize;
2171 static inline void scst_tgt_set_sg_tablesize(struct scst_tgt *tgt, int val)
2173 tgt->sg_tablesize = val;
2177 * Get/Set functions for tgt's target private data
2179 static inline void *scst_tgt_get_tgt_priv(struct scst_tgt *tgt)
2181 return tgt->tgt_priv;
2184 static inline void scst_tgt_set_tgt_priv(struct scst_tgt *tgt, void *val)
2186 tgt->tgt_priv = val;
2190 * Get/Set functions for session's target private data
2192 static inline void *scst_sess_get_tgt_priv(struct scst_session *sess)
2194 return sess->tgt_priv;
2197 static inline void scst_sess_set_tgt_priv(struct scst_session *sess,
2200 sess->tgt_priv = val;
2204 * Returns TRUE if cmd is being executed in atomic context.
2206 * Note: checkpatch will complain on the use of in_atomic() below. You can
2207 * safely ignore this warning since in_atomic() is used here only for debugging
2210 static inline int scst_cmd_atomic(struct scst_cmd *cmd)
2212 int res = cmd->atomic;
2213 #ifdef CONFIG_SCST_EXTRACHECKS
2214 if (unlikely((in_atomic() || in_interrupt() || irqs_disabled()) &&
2216 printk(KERN_ERR "ERROR: atomic context and non-atomic cmd\n");
2225 static inline enum scst_exec_context __scst_estimate_context(bool direct)
2228 return SCST_CONTEXT_TASKLET;
2229 else if (irqs_disabled())
2230 return SCST_CONTEXT_THREAD;
2232 return direct ? SCST_CONTEXT_DIRECT :
2233 SCST_CONTEXT_DIRECT_ATOMIC;
2236 static inline enum scst_exec_context scst_estimate_context(void)
2238 return __scst_estimate_context(0);
2241 static inline enum scst_exec_context scst_estimate_context_direct(void)
2243 return __scst_estimate_context(1);
2246 /* Returns cmd's CDB */
2247 static inline const uint8_t *scst_cmd_get_cdb(struct scst_cmd *cmd)
2252 /* Returns cmd's CDB length */
2253 static inline int scst_cmd_get_cdb_len(struct scst_cmd *cmd)
2255 return cmd->cdb_len;
2258 /* Returns cmd's extended CDB */
2259 static inline const uint8_t *scst_cmd_get_ext_cdb(struct scst_cmd *cmd)
2261 return cmd->ext_cdb;
2264 /* Returns cmd's extended CDB length */
2265 static inline int scst_cmd_get_ext_cdb_len(struct scst_cmd *cmd)
2267 return cmd->ext_cdb_len;
2270 /* Sets cmd's extended CDB and its length */
2271 static inline void scst_cmd_set_ext_cdb(struct scst_cmd *cmd,
2272 uint8_t *ext_cdb, unsigned int ext_cdb_len)
2274 cmd->ext_cdb = ext_cdb;
2275 cmd->ext_cdb_len = ext_cdb_len;
2278 /* Returns cmd's session */
2279 static inline struct scst_session *scst_cmd_get_session(struct scst_cmd *cmd)
2284 /* Returns cmd's response data length */
2285 static inline int scst_cmd_get_resp_data_len(struct scst_cmd *cmd)
2287 return cmd->resp_data_len;
2290 /* Returns if status should be sent for cmd */
2291 static inline int scst_cmd_get_is_send_status(struct scst_cmd *cmd)
2293 return cmd->is_send_status;
2297 * Returns pointer to cmd's SG data buffer.
2299 * Usage of this function is not recommended, use scst_get_buf_*()
2300 * family of functions instead.
2302 static inline struct scatterlist *scst_cmd_get_sg(struct scst_cmd *cmd)
2308 * Returns cmd's sg_cnt.
2310 * Usage of this function is not recommended, use scst_get_buf_*()
2311 * family of functions instead.
2313 static inline int scst_cmd_get_sg_cnt(struct scst_cmd *cmd)
2319 * Returns cmd's data buffer length.
2321 * In case if you need to iterate over data in the buffer, usage of
2322 * this function is not recommended, use scst_get_buf_*()
2323 * family of functions instead.
2325 static inline unsigned int scst_cmd_get_bufflen(struct scst_cmd *cmd)
2327 return cmd->bufflen;
2331 * Returns pointer to cmd's bidirectional in (WRITE) SG data buffer.
2333 * Usage of this function is not recommended, use scst_get_in_buf_*()
2334 * family of functions instead.
2336 static inline struct scatterlist *scst_cmd_get_in_sg(struct scst_cmd *cmd)
2342 * Returns cmd's bidirectional in (WRITE) sg_cnt.
2344 * Usage of this function is not recommended, use scst_get_in_buf_*()
2345 * family of functions instead.
2347 static inline int scst_cmd_get_in_sg_cnt(struct scst_cmd *cmd)
2349 return cmd->in_sg_cnt;
2353 * Returns cmd's bidirectional in (WRITE) data buffer length.
2355 * In case if you need to iterate over data in the buffer, usage of
2356 * this function is not recommended, use scst_get_in_buf_*()
2357 * family of functions instead.
2359 static inline unsigned int scst_cmd_get_in_bufflen(struct scst_cmd *cmd)
2361 return cmd->in_bufflen;
2364 /* Returns pointer to cmd's target's SG data buffer */
2365 static inline struct scatterlist *scst_cmd_get_tgt_sg(struct scst_cmd *cmd)
2370 /* Returns cmd's target's sg_cnt */
2371 static inline int scst_cmd_get_tgt_sg_cnt(struct scst_cmd *cmd)
2373 return cmd->tgt_sg_cnt;
2376 /* Sets cmd's target's SG data buffer */
2377 static inline void scst_cmd_set_tgt_sg(struct scst_cmd *cmd,
2378 struct scatterlist *sg, int sg_cnt)
2381 cmd->tgt_sg_cnt = sg_cnt;
2382 cmd->tgt_data_buf_alloced = 1;
2385 /* Returns pointer to cmd's target's IN SG data buffer */
2386 static inline struct scatterlist *scst_cmd_get_in_tgt_sg(struct scst_cmd *cmd)
2388 return cmd->tgt_in_sg;
2391 /* Returns cmd's target's IN sg_cnt */
2392 static inline int scst_cmd_get_tgt_in_sg_cnt(struct scst_cmd *cmd)
2394 return cmd->tgt_in_sg_cnt;
2397 /* Sets cmd's target's IN SG data buffer */
2398 static inline void scst_cmd_set_tgt_in_sg(struct scst_cmd *cmd,
2399 struct scatterlist *sg, int sg_cnt)
2401 WARN_ON(!cmd->tgt_data_buf_alloced);
2403 cmd->tgt_in_sg = sg;
2404 cmd->tgt_in_sg_cnt = sg_cnt;
2407 /* Returns cmd's data direction */
2408 static inline scst_data_direction scst_cmd_get_data_direction(
2409 struct scst_cmd *cmd)
2411 return cmd->data_direction;
2414 /* Returns cmd's status byte from host device */
2415 static inline uint8_t scst_cmd_get_status(struct scst_cmd *cmd)
2420 /* Returns cmd's status from host adapter itself */
2421 static inline uint8_t scst_cmd_get_msg_status(struct scst_cmd *cmd)
2423 return cmd->msg_status;
2426 /* Returns cmd's status set by low-level driver to indicate its status */
2427 static inline uint8_t scst_cmd_get_host_status(struct scst_cmd *cmd)
2429 return cmd->host_status;
2432 /* Returns cmd's status set by SCSI mid-level */
2433 static inline uint8_t scst_cmd_get_driver_status(struct scst_cmd *cmd)
2435 return cmd->driver_status;
2438 /* Returns pointer to cmd's sense buffer */
2439 static inline uint8_t *scst_cmd_get_sense_buffer(struct scst_cmd *cmd)
2444 /* Returns cmd's sense buffer length */
2445 static inline int scst_cmd_get_sense_buffer_len(struct scst_cmd *cmd)
2447 return cmd->sense_bufflen;
2451 * Get/Set functions for cmd's target SN
2453 static inline uint64_t scst_cmd_get_tag(struct scst_cmd *cmd)
2458 static inline void scst_cmd_set_tag(struct scst_cmd *cmd, uint64_t tag)
2464 * Get/Set functions for cmd's target private data.
2465 * Variant with *_lock must be used if target driver uses
2466 * scst_find_cmd() to avoid race with it, except inside scst_find_cmd()'s
2467 * callback, where lock is already taken.
2469 static inline void *scst_cmd_get_tgt_priv(struct scst_cmd *cmd)
2471 return cmd->tgt_priv;
2474 static inline void scst_cmd_set_tgt_priv(struct scst_cmd *cmd, void *val)
2476 cmd->tgt_priv = val;
2479 void *scst_cmd_get_tgt_priv_lock(struct scst_cmd *cmd);
2480 void scst_cmd_set_tgt_priv_lock(struct scst_cmd *cmd, void *val);
2483 * Get/Set functions for tgt_need_alloc_data_buf flag
2485 static inline int scst_cmd_get_tgt_need_alloc_data_buf(struct scst_cmd *cmd)
2487 return cmd->tgt_need_alloc_data_buf;
2490 static inline void scst_cmd_set_tgt_need_alloc_data_buf(struct scst_cmd *cmd)
2492 cmd->tgt_need_alloc_data_buf = 1;
2496 * Get/Set functions for tgt_data_buf_alloced flag
2498 static inline int scst_cmd_get_tgt_data_buff_alloced(struct scst_cmd *cmd)
2500 return cmd->tgt_data_buf_alloced;
2503 static inline void scst_cmd_set_tgt_data_buff_alloced(struct scst_cmd *cmd)
2505 cmd->tgt_data_buf_alloced = 1;
2509 * Get/Set functions for dh_data_buf_alloced flag
2511 static inline int scst_cmd_get_dh_data_buff_alloced(struct scst_cmd *cmd)
2513 return cmd->dh_data_buf_alloced;
2516 static inline void scst_cmd_set_dh_data_buff_alloced(struct scst_cmd *cmd)
2518 cmd->dh_data_buf_alloced = 1;
2522 * Get/Set functions for no_sgv flag
2524 static inline int scst_cmd_get_no_sgv(struct scst_cmd *cmd)
2529 static inline void scst_cmd_set_no_sgv(struct scst_cmd *cmd)
2535 * Get/Set functions for tgt_sn
2537 static inline int scst_cmd_get_tgt_sn(struct scst_cmd *cmd)
2539 BUG_ON(!cmd->tgt_sn_set);
2543 static inline void scst_cmd_set_tgt_sn(struct scst_cmd *cmd, uint32_t tgt_sn)
2545 cmd->tgt_sn_set = 1;
2546 cmd->tgt_sn = tgt_sn;
2550 * Returns 1 if the cmd was aborted, so its status is invalid and no
2551 * reply shall be sent to the remote initiator. A target driver should
2552 * only clear internal resources, associated with cmd.
2554 static inline int scst_cmd_aborted(struct scst_cmd *cmd)
2556 return test_bit(SCST_CMD_ABORTED, &cmd->cmd_flags) &&
2557 !test_bit(SCST_CMD_ABORTED_OTHER, &cmd->cmd_flags);
2560 /* Returns sense data format for cmd's dev */
2561 static inline bool scst_get_cmd_dev_d_sense(struct scst_cmd *cmd)
2563 return (cmd->dev != NULL) ? cmd->dev->d_sense : 0;
2567 * Get/Set functions for expected data direction, transfer length
2568 * and its validity flag
2570 static inline int scst_cmd_is_expected_set(struct scst_cmd *cmd)
2572 return cmd->expected_values_set;
2575 static inline scst_data_direction scst_cmd_get_expected_data_direction(
2576 struct scst_cmd *cmd)
2578 return cmd->expected_data_direction;
2581 static inline int scst_cmd_get_expected_transfer_len(
2582 struct scst_cmd *cmd)
2584 return cmd->expected_transfer_len;
2587 static inline int scst_cmd_get_expected_in_transfer_len(
2588 struct scst_cmd *cmd)
2590 return cmd->expected_in_transfer_len;
2593 static inline void scst_cmd_set_expected(struct scst_cmd *cmd,
2594 scst_data_direction expected_data_direction,
2595 int expected_transfer_len)
2597 cmd->expected_data_direction = expected_data_direction;
2598 cmd->expected_transfer_len = expected_transfer_len;
2599 cmd->expected_values_set = 1;
2602 static inline void scst_cmd_set_expected_in_transfer_len(struct scst_cmd *cmd,
2603 int expected_in_transfer_len)
2605 WARN_ON(!cmd->expected_values_set);
2606 cmd->expected_in_transfer_len = expected_in_transfer_len;
2610 * Get/clear functions for cmd's may_need_dma_sync
2612 static inline int scst_get_may_need_dma_sync(struct scst_cmd *cmd)
2614 return cmd->may_need_dma_sync;
2617 static inline void scst_clear_may_need_dma_sync(struct scst_cmd *cmd)
2619 cmd->may_need_dma_sync = 0;
2623 * Get/set functions for cmd's delivery_status. It is one of
2624 * SCST_CMD_DELIVERY_* constants. It specifies the status of the
2625 * command's delivery to initiator.
2627 static inline int scst_get_delivery_status(struct scst_cmd *cmd)
2629 return cmd->delivery_status;
2632 static inline void scst_set_delivery_status(struct scst_cmd *cmd,
2633 int delivery_status)
2635 cmd->delivery_status = delivery_status;
2639 * Get/Set function for mgmt cmd's target private data
2641 static inline void *scst_mgmt_cmd_get_tgt_priv(struct scst_mgmt_cmd *mcmd)
2643 return mcmd->tgt_priv;
2646 static inline void scst_mgmt_cmd_set_tgt_priv(struct scst_mgmt_cmd *mcmd,
2649 mcmd->tgt_priv = val;
2652 /* Returns mgmt cmd's completition status (SCST_MGMT_STATUS_* constants) */
2653 static inline int scst_mgmt_cmd_get_status(struct scst_mgmt_cmd *mcmd)
2655 return mcmd->status;
2658 /* Returns mgmt cmd's TM fn */
2659 static inline int scst_mgmt_cmd_get_fn(struct scst_mgmt_cmd *mcmd)
2665 * Called by dev handler's task_mgmt_fn() to notify SCST core that mcmd
2666 * is going to complete asynchronously.
2668 void scst_prepare_async_mcmd(struct scst_mgmt_cmd *mcmd);
2671 * Called by dev handler to notify SCST core that async. mcmd is completed
2672 * with status "status".
2674 void scst_async_mcmd_completed(struct scst_mgmt_cmd *mcmd, int status);
2676 /* Returns AEN's fn */
2677 static inline int scst_aen_get_event_fn(struct scst_aen *aen)
2679 return aen->event_fn;
2682 /* Returns AEN's session */
2683 static inline struct scst_session *scst_aen_get_sess(struct scst_aen *aen)
2688 /* Returns AEN's LUN */
2689 static inline uint64_t scst_aen_get_lun(struct scst_aen *aen)
2694 /* Returns SCSI AEN's sense */
2695 static inline const uint8_t *scst_aen_get_sense(struct scst_aen *aen)
2697 return aen->aen_sense;
2700 /* Returns SCSI AEN's sense length */
2701 static inline int scst_aen_get_sense_len(struct scst_aen *aen)
2703 return aen->aen_sense_len;
2707 * Get/set functions for AEN's delivery_status. It is one of
2708 * SCST_AEN_RES_* constants. It specifies the status of the
2709 * command's delivery to initiator.
2711 static inline int scst_get_aen_delivery_status(struct scst_aen *aen)
2713 return aen->delivery_status;
2716 static inline void scst_set_aen_delivery_status(struct scst_aen *aen,
2719 aen->delivery_status = status;
2723 * Notifies SCST that the driver has sent the AEN and it
2724 * can be freed now. Don't forget to set the delivery status, if it
2725 * isn't success, using scst_set_aen_delivery_status() before calling
2728 void scst_aen_done(struct scst_aen *aen);
2730 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
2733 * The macro's sg_page(), sg_virt(), sg_init_table(), sg_assign_page() and
2734 * sg_set_page() have been introduced in the 2.6.24 kernel. The definitions
2735 * below are backports of the 2.6.24 macro's for older kernels. There is one
2736 * exception however: when compiling SCST on a system with a pre-2.6.24 kernel
2737 * (e.g. RHEL 5.x) where the OFED kernel headers have been installed, do not
2738 * define the backported macro's because OFED has already defined these.
2741 #ifndef __BACKPORT_LINUX_SCATTERLIST_H_TO_2_6_23__
2743 static inline struct page *sg_page(struct scatterlist *sg)
2748 static inline void *sg_virt(struct scatterlist *sg)
2750 return page_address(sg_page(sg)) + sg->offset;
2753 static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents)
2755 memset(sgl, 0, sizeof(*sgl) * nents);
2758 static inline void sg_assign_page(struct scatterlist *sg, struct page *page)
2763 static inline void sg_set_page(struct scatterlist *sg, struct page *page,
2764 unsigned int len, unsigned int offset)
2766 sg_assign_page(sg, page);
2767 sg->offset = offset;
2771 static inline struct scatterlist *sg_next(struct scatterlist *sg)
2779 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) */
2781 static inline void sg_clear(struct scatterlist *sg)
2783 memset(sg, 0, sizeof(*sg));
2784 #ifdef CONFIG_DEBUG_SG
2785 sg->sg_magic = SG_MAGIC;
2790 * Functions for access to the commands data (SG) buffer,
2791 * including HIGHMEM environment. Should be used instead of direct
2792 * access. Returns the mapped buffer length for success, 0 for EOD,
2793 * negative error code otherwise.
2795 * "Buf" argument returns the mapped buffer
2797 * The "put" function unmaps the buffer.
2799 static inline int __scst_get_buf(struct scst_cmd *cmd, struct scatterlist *sg,
2800 int sg_cnt, uint8_t **buf)
2803 int i = cmd->get_sg_buf_entry_num;
2807 if ((i >= sg_cnt) || unlikely(sg == NULL))
2810 *buf = page_address(sg_page(&sg[i]));
2811 *buf += sg[i].offset;
2814 cmd->get_sg_buf_entry_num++;
2820 static inline int scst_get_buf_first(struct scst_cmd *cmd, uint8_t **buf)
2822 cmd->get_sg_buf_entry_num = 0;
2823 cmd->may_need_dma_sync = 1;
2824 return __scst_get_buf(cmd, cmd->sg, cmd->sg_cnt, buf);
2827 static inline int scst_get_buf_next(struct scst_cmd *cmd, uint8_t **buf)
2829 return __scst_get_buf(cmd, cmd->sg, cmd->sg_cnt, buf);
2832 static inline void scst_put_buf(struct scst_cmd *cmd, void *buf)
2837 static inline int scst_get_in_buf_first(struct scst_cmd *cmd, uint8_t **buf)
2839 cmd->get_sg_buf_entry_num = 0;
2840 cmd->may_need_dma_sync = 1;
2841 return __scst_get_buf(cmd, cmd->in_sg, cmd->in_sg_cnt, buf);
2844 static inline int scst_get_in_buf_next(struct scst_cmd *cmd, uint8_t **buf)
2846 return __scst_get_buf(cmd, cmd->in_sg, cmd->in_sg_cnt, buf);
2849 static inline void scst_put_in_buf(struct scst_cmd *cmd, void *buf)
2855 * Returns approximate higher rounded buffers count that
2856 * scst_get_buf_[first|next]() return.
2858 static inline int scst_get_buf_count(struct scst_cmd *cmd)
2860 return (cmd->sg_cnt == 0) ? 1 : cmd->sg_cnt;
2864 * Returns approximate higher rounded buffers count that
2865 * scst_get_in_buf_[first|next]() return.
2867 static inline int scst_get_in_buf_count(struct scst_cmd *cmd)
2869 return (cmd->in_sg_cnt == 0) ? 1 : cmd->in_sg_cnt;
2872 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23) && !defined(BACKPORT_LINUX_WORKQUEUE_TO_2_6_19)
2873 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20))
2874 static inline int cancel_delayed_work_sync(struct delayed_work *work)
2876 static inline int cancel_delayed_work_sync(struct work_struct *work)
2881 res = cancel_delayed_work(work);
2882 flush_scheduled_work();
2888 * Suspends and resumes any activity.
2889 * Function scst_suspend_activity() doesn't return 0, until there are any
2890 * active commands (state after SCST_CMD_STATE_INIT). If "interruptible"
2891 * is true, it returns after SCST_SUSPENDING_TIMEOUT or if it was interrupted
2892 * by a signal with the coresponding error status < 0. If "interruptible"
2893 * is false, it will wait virtually forever.
2895 * New arriving commands stay in that state until scst_resume_activity()
2898 int scst_suspend_activity(bool interruptible);
2899 void scst_resume_activity(void);
2902 * Main SCST commands processing routing. Must be used only by dev handlers.
2903 * Argument atomic is true if function called in atomic context.
2905 void scst_process_active_cmd(struct scst_cmd *cmd, bool atomic);
2908 * Checks if command can be executed (reservations, etc.) or there are local
2909 * events, like pending UAs. Returns < 0 if command must be aborted, > 0 if
2910 * there is an event and command should be immediately completed, or 0
2913 * !! Dev handlers implementing exec() callback must call this function there !!
2914 * !! just before the actual command's execution !!
2916 int scst_check_local_events(struct scst_cmd *cmd);
2919 * Returns the next state of the SCSI target state machine in case if command's
2920 * completed abnormally.
2922 int scst_get_cmd_abnormal_done_state(const struct scst_cmd *cmd);
2925 * Sets state of the SCSI target state machine in case if command's completed
2928 void scst_set_cmd_abnormal_done_state(struct scst_cmd *cmd);
2931 * Returns target driver's root entry in SCST's /proc hierarchy.
2932 * The driver can create own files/directories here, which should
2933 * be deleted in the driver's release().
2935 static inline struct proc_dir_entry *scst_proc_get_tgt_root(
2936 struct scst_tgt_template *vtt)
2938 return vtt->proc_tgt_root;
2942 * Returns device handler's root entry in SCST's /proc hierarchy.
2943 * The driver can create own files/directories here, which should
2944 * be deleted in the driver's detach()/release().
2946 static inline struct proc_dir_entry *scst_proc_get_dev_type_root(
2947 struct scst_dev_type *dtt)
2949 return dtt->proc_dev_type_root;
2953 ** Two library functions and the structure to help the drivers
2954 ** that use scst_debug.* facilities manage "trace_level" /proc entry.
2955 ** The functions service "standard" log levels and allow to work
2956 ** with driver specific levels, which should be passed inside as
2957 ** NULL-terminated array of struct scst_proc_log's, where:
2958 ** - val - the level's numeric value
2959 ** - token - its string representation
2962 struct scst_proc_log {
2967 int scst_proc_log_entry_read(struct seq_file *seq, unsigned long log_level,
2968 const struct scst_proc_log *tbl);
2970 int scst_proc_log_entry_write(struct file *file, const char __user *buf,
2971 unsigned long length, unsigned long *log_level,
2972 unsigned long default_level, const struct scst_proc_log *tbl);
2975 * helper data structure and function to create proc entry.
2977 struct scst_proc_data {
2978 const struct file_operations seq_op;
2979 int (*show)(struct seq_file *, void *);
2983 int scst_single_seq_open(struct inode *inode, struct file *file);
2985 struct proc_dir_entry *scst_create_proc_entry(struct proc_dir_entry *root,
2986 const char *name, struct scst_proc_data *pdata);
2988 #define SCST_DEF_RW_SEQ_OP(x) \
2990 .owner = THIS_MODULE, \
2991 .open = scst_single_seq_open,\
2994 .llseek = seq_lseek, \
2995 .release = single_release, \
2999 * Adds and deletes (stops) num of global SCST's threads. Returns 0 on
3000 * success, error code otherwise.
3002 int scst_add_global_threads(int num);
3003 void scst_del_global_threads(int num);
3005 int scst_alloc_sense(struct scst_cmd *cmd, int atomic);
3006 int scst_alloc_set_sense(struct scst_cmd *cmd, int atomic,
3007 const uint8_t *sense, unsigned int len);
3009 void scst_set_sense(uint8_t *buffer, int len, bool d_sense,
3010 int key, int asc, int ascq);
3013 * Returnes true if sense matches to (key, asc, ascq) and false otherwise.
3014 * Valid_mask is one or several SCST_SENSE_*_VALID constants setting valid
3015 * (key, asc, ascq) values.
3017 bool scst_analyze_sense(const uint8_t *sense, int len,
3018 unsigned int valid_mask, int key, int asc, int ascq);
3021 * Returnes a pseudo-random number for debugging purposes. Available only in
3024 unsigned long scst_random(void);
3027 * Sets response data length for cmd and truncates its SG vector accordingly.
3028 * The cmd->resp_data_len must not be set directly, it must be set only
3029 * using this function. Value of resp_data_len must be <= cmd->bufflen.
3031 void scst_set_resp_data_len(struct scst_cmd *cmd, int resp_data_len);
3034 * Get/put global ref counter that prevents from entering into suspended
3035 * activities stage, so protects from any global management operations.
3037 void scst_get(void);
3038 void scst_put(void);
3043 void scst_cmd_get(struct scst_cmd *cmd);
3044 void scst_cmd_put(struct scst_cmd *cmd);
3047 * Allocates and returns pointer to SG vector with data size "size".
3048 * In *count returned the count of entries in the vector.
3049 * Returns NULL for failure.
3051 struct scatterlist *scst_alloc(int size, gfp_t gfp_mask, int *count);
3053 /* Frees SG vector returned by scst_alloc() */
3054 void scst_free(struct scatterlist *sg, int count);
3057 * Adds local to the current thread data to tgt_dev
3058 * (they will be local for the tgt_dev and current thread).
3060 void scst_add_thr_data(struct scst_tgt_dev *tgt_dev,
3061 struct scst_thr_data_hdr *data,
3062 void (*free_fn) (struct scst_thr_data_hdr *data));
3064 /* Deletes all local to threads data from tgt_dev */
3065 void scst_del_all_thr_data(struct scst_tgt_dev *tgt_dev);
3067 /* Deletes all local to threads data from all tgt_dev's of the dev */
3068 void scst_dev_del_all_thr_data(struct scst_device *dev);
3070 /* Finds local to the thread data. Returns NULL, if they not found. */
3071 struct scst_thr_data_hdr *__scst_find_thr_data(struct scst_tgt_dev *tgt_dev,
3072 struct task_struct *tsk);
3074 /* Finds local to the current thread data. Returns NULL, if they not found. */
3075 static inline struct scst_thr_data_hdr *scst_find_thr_data(
3076 struct scst_tgt_dev *tgt_dev)
3078 return __scst_find_thr_data(tgt_dev, current);
3081 static inline void scst_thr_data_get(struct scst_thr_data_hdr *data)
3083 atomic_inc(&data->ref);
3086 static inline void scst_thr_data_put(struct scst_thr_data_hdr *data)
3088 if (atomic_dec_and_test(&data->ref))
3089 data->free_fn(data);
3093 ** Generic parse() support routines.
3094 ** Done via pointer on functions to avoid unneeded dereferences on
3098 /* Calculates and returns block shift for the given sector size */
3099 int scst_calc_block_shift(int sector_size);
3101 /* Generic parse() for SBC (disk) devices */
3102 int scst_sbc_generic_parse(struct scst_cmd *cmd,
3103 int (*get_block_shift)(struct scst_cmd *cmd));
3105 /* Generic parse() for MMC (cdrom) devices */
3106 int scst_cdrom_generic_parse(struct scst_cmd *cmd,
3107 int (*get_block_shift)(struct scst_cmd *cmd));
3109 /* Generic parse() for MO disk devices */
3110 int scst_modisk_generic_parse(struct scst_cmd *cmd,
3111 int (*get_block_shift)(struct scst_cmd *cmd));
3113 /* Generic parse() for tape devices */
3114 int scst_tape_generic_parse(struct scst_cmd *cmd,
3115 int (*get_block_size)(struct scst_cmd *cmd));
3117 /* Generic parse() for changer devices */
3118 int scst_changer_generic_parse(struct scst_cmd *cmd,
3119 int (*nothing)(struct scst_cmd *cmd));
3121 /* Generic parse() for "processor" devices */
3122 int scst_processor_generic_parse(struct scst_cmd *cmd,
3123 int (*nothing)(struct scst_cmd *cmd));
3125 /* Generic parse() for RAID devices */
3126 int scst_raid_generic_parse(struct scst_cmd *cmd,
3127 int (*nothing)(struct scst_cmd *cmd));
3130 ** Generic dev_done() support routines.
3131 ** Done via pointer on functions to avoid unneeded dereferences on
3135 /* Generic dev_done() for block devices */
3136 int scst_block_generic_dev_done(struct scst_cmd *cmd,
3137 void (*set_block_shift)(struct scst_cmd *cmd, int block_shift));
3139 /* Generic dev_done() for tape devices */
3140 int scst_tape_generic_dev_done(struct scst_cmd *cmd,
3141 void (*set_block_size)(struct scst_cmd *cmd, int block_size));
3144 * Issues a MODE SENSE for control mode page data and sets the corresponding
3145 * dev's parameter from it. Returns 0 on success and not 0 otherwise.
3147 int scst_obtain_device_parameters(struct scst_device *dev);
3150 * Has to be put here open coded, because Linux doesn't have equivalent, which
3151 * allows exclusive wake ups of threads in LIFO order. We need it to let (yet)
3152 * unneeded threads sleep and not pollute CPU cache by their stacks.
3154 static inline void add_wait_queue_exclusive_head(wait_queue_head_t *q,
3157 unsigned long flags;
3159 wait->flags |= WQ_FLAG_EXCLUSIVE;
3160 spin_lock_irqsave(&q->lock, flags);
3161 __add_wait_queue(q, wait);
3162 spin_unlock_irqrestore(&q->lock, flags);
3165 #endif /* __SCST_H */