Lines Matching +full:layer +full:- +full:depth
1 // SPDX-License-Identifier: GPL-2.0-only
7 * generic mid-level SCSI driver
16 * Thomas Wuensche <tw@fgb1.fgb.mw.tu-muenchen.de>
19 * add scatter-gather, multiple outstanding request, and other
23 * support added by Michael Neuffer <mike@i-connect.net>
36 * Jiffies wrap fixes (host->resetting), 3 Dec 1998 Andrea Arcangeli
80 * Note - the initial logging level can be set here to log events at boot time.
134 if (((level > 0) && (cmd->result || disposition != SUCCESS)) || in scsi_log_completion()
138 if (scsi_status_is_check_condition(cmd->result)) in scsi_log_completion()
143 scsi_host_busy(cmd->device->host), in scsi_log_completion()
144 cmd->device->host->host_failed); in scsi_log_completion()
151 * scsi_finish_command - cleanup and pass command back to upper layer
154 * Description: Pass command off to upper layer for finishing of I/O
160 struct scsi_device *sdev = cmd->device; in scsi_finish_command()
162 struct Scsi_Host *shost = sdev->host; in scsi_finish_command()
172 if (atomic_read(&shost->host_blocked)) in scsi_finish_command()
173 atomic_set(&shost->host_blocked, 0); in scsi_finish_command()
174 if (atomic_read(&starget->target_blocked)) in scsi_finish_command()
175 atomic_set(&starget->target_blocked, 0); in scsi_finish_command()
176 if (atomic_read(&sdev->device_blocked)) in scsi_finish_command()
177 atomic_set(&sdev->device_blocked, 0); in scsi_finish_command()
181 "(result %x)\n", cmd->result)); in scsi_finish_command()
187 if (drv->done) in scsi_finish_command()
188 good_bytes = drv->done(cmd); in scsi_finish_command()
192 * residue if drv->done() error processing indicates no in scsi_finish_command()
196 good_bytes -= scsi_get_resid(cmd); in scsi_finish_command()
207 return min_t(int, sdev->host->can_queue, 4096); in scsi_device_max_queue_depth()
211 * scsi_change_queue_depth - change a device's queue depth
213 * @depth: number of commands allowed to be queued to the driver
215 * Sets the device queue depth and returns the new value.
217 int scsi_change_queue_depth(struct scsi_device *sdev, int depth) in scsi_change_queue_depth() argument
219 depth = min_t(int, depth, scsi_device_max_queue_depth(sdev)); in scsi_change_queue_depth()
221 if (depth > 0) { in scsi_change_queue_depth()
222 sdev->queue_depth = depth; in scsi_change_queue_depth()
226 if (sdev->request_queue) in scsi_change_queue_depth()
227 blk_set_queue_depth(sdev->request_queue, depth); in scsi_change_queue_depth()
229 sbitmap_resize(&sdev->budget_map, sdev->queue_depth); in scsi_change_queue_depth()
231 return sdev->queue_depth; in scsi_change_queue_depth()
236 * scsi_track_queue_full - track QUEUE_FULL events to adjust queue depth
238 * @depth: Current number of outstanding SCSI commands on this device,
243 * need to adjust the queue depth on the device.
245 * Returns: 0 - No change needed, >0 - Adjust queue depth to this new depth,
246 * -1 - Drop back to untagged operation using host->cmd_per_lun
247 * as the untagged command depth
254 int scsi_track_queue_full(struct scsi_device *sdev, int depth) in scsi_track_queue_full() argument
262 if ((jiffies >> 4) == (sdev->last_queue_full_time >> 4)) in scsi_track_queue_full()
265 sdev->last_queue_full_time = jiffies; in scsi_track_queue_full()
266 if (sdev->last_queue_full_depth != depth) { in scsi_track_queue_full()
267 sdev->last_queue_full_count = 1; in scsi_track_queue_full()
268 sdev->last_queue_full_depth = depth; in scsi_track_queue_full()
270 sdev->last_queue_full_count++; in scsi_track_queue_full()
273 if (sdev->last_queue_full_count <= 10) in scsi_track_queue_full()
276 return scsi_change_queue_depth(sdev, depth); in scsi_track_queue_full()
281 * scsi_vpd_inquiry - Request a device provide us with a VPD page
299 return -EINVAL; in scsi_vpd_inquiry()
315 return -EIO; in scsi_vpd_inquiry()
322 return -EIO; in scsi_vpd_inquiry()
326 return -EIO; in scsi_vpd_inquiry()
341 if (sdev->no_vpd_size) in scsi_get_vpd_size()
354 dev_warn_once(&sdev->sdev_gendev, in scsi_get_vpd_size()
360 result -= SCSI_VPD_HEADER_SIZE; in scsi_get_vpd_size()
375 dev_warn_once(&sdev->sdev_gendev, in scsi_get_vpd_size()
385 * scsi_get_vpd_page - Get Vital Product Data from a SCSI device
395 * supported or its content cannot be retrieved, -EINVAL is returned.
403 return -EINVAL; in scsi_get_vpd_page()
407 return -EINVAL; in scsi_get_vpd_page()
418 return -EINVAL; in scsi_get_vpd_page()
420 dev_warn_once(&sdev->sdev_gendev, in scsi_get_vpd_page()
429 * scsi_get_vpd_buf - Get Vital Product Data from a SCSI device
453 result = scsi_vpd_inquiry(sdev, vpd_buf->data, page, vpd_len); in scsi_get_vpd_buf()
459 dev_warn_once(&sdev->sdev_gendev, in scsi_get_vpd_buf()
467 vpd_buf->len = result; in scsi_get_vpd_buf()
481 mutex_lock(&sdev->inquiry_mutex); in scsi_update_vpd_page()
483 lockdep_is_held(&sdev->inquiry_mutex)); in scsi_update_vpd_page()
484 mutex_unlock(&sdev->inquiry_mutex); in scsi_update_vpd_page()
491 * scsi_attach_vpd - Attach Vital Product Data to a SCSI device structure
512 for (i = 4; i < vpd_buf->len; i++) { in scsi_attach_vpd()
513 switch (vpd_buf->data[i]) { in scsi_attach_vpd()
515 scsi_update_vpd_page(sdev, 0x0, &sdev->vpd_pg0); in scsi_attach_vpd()
518 scsi_update_vpd_page(sdev, 0x80, &sdev->vpd_pg80); in scsi_attach_vpd()
521 scsi_update_vpd_page(sdev, 0x83, &sdev->vpd_pg83); in scsi_attach_vpd()
524 scsi_update_vpd_page(sdev, 0x89, &sdev->vpd_pg89); in scsi_attach_vpd()
527 scsi_update_vpd_page(sdev, 0xb0, &sdev->vpd_pgb0); in scsi_attach_vpd()
530 scsi_update_vpd_page(sdev, 0xb1, &sdev->vpd_pgb1); in scsi_attach_vpd()
533 scsi_update_vpd_page(sdev, 0xb2, &sdev->vpd_pgb2); in scsi_attach_vpd()
536 scsi_update_vpd_page(sdev, 0xb7, &sdev->vpd_pgb7); in scsi_attach_vpd()
546 * scsi_report_opcode - Find out if a given command is supported
555 * have a service action, @sa must be 0. Returns -EINVAL if RSOC fails,
570 if (sdev->no_report_opcodes || sdev->scsi_level < SCSI_SPC_3) in scsi_report_opcode()
571 return -EINVAL; in scsi_report_opcode()
576 dev_warn_once(&sdev->sdev_gendev, in scsi_report_opcode()
579 return -EINVAL; in scsi_report_opcode()
603 return -EINVAL; in scsi_report_opcode()
629 * See SPC-6, One_command parameter data format for in scsi_cdl_check_cmd()
632 * - rwcdlp == 0: then cdlp indicates support for the A mode page when in scsi_cdl_check_cmd()
635 * - rwcdlp == 1: then cdlp indicates support for the T2A mode page in scsi_cdl_check_cmd()
647 * scsi_cdl_check - Check if a SCSI device supports Command Duration Limits
656 * Support for CDL was defined in SPC-5. Ignore devices reporting an in scsi_cdl_check()
661 if (sdev->scsi_level < SCSI_SPC_5) { in scsi_cdl_check()
662 sdev->cdl_supported = 0; in scsi_cdl_check()
668 sdev->cdl_supported = 0; in scsi_cdl_check()
684 sdev->use_16_for_rw = 1; in scsi_cdl_check()
685 sdev->use_10_for_rw = 0; in scsi_cdl_check()
687 sdev->cdl_supported = 1; in scsi_cdl_check()
694 scsi_cdl_enable(sdev, sdev->cdl_enable); in scsi_cdl_check()
696 sdev->cdl_supported = 0; in scsi_cdl_check()
703 * scsi_cdl_enable - Enable or disable a SCSI device supports for Command
714 if (!sdev->cdl_supported) in scsi_cdl_enable()
715 return -EOPNOTSUPP; in scsi_cdl_enable()
718 is_ata = rcu_dereference(sdev->vpd_pg89); in scsi_cdl_enable()
733 return -EINVAL; in scsi_cdl_enable()
737 data.length - data.header_length - in scsi_cdl_enable()
765 dev_name(&sdev->sdev_gendev), &sshdr); in scsi_cdl_enable()
771 sdev->cdl_enable = enable; in scsi_cdl_enable()
777 * scsi_device_get - get an additional reference to a scsi_device
789 if (sdev->sdev_state == SDEV_DEL || sdev->sdev_state == SDEV_CANCEL) in scsi_device_get()
791 if (!try_module_get(sdev->host->hostt->module)) in scsi_device_get()
793 if (!get_device(&sdev->sdev_gendev)) in scsi_device_get()
798 module_put(sdev->host->hostt->module); in scsi_device_get()
800 return -ENXIO; in scsi_device_get()
805 * scsi_device_put - release a reference to a scsi_device
814 struct module *mod = sdev->host->hostt->module; in scsi_device_put()
816 put_device(&sdev->sdev_gendev); in scsi_device_put()
825 struct list_head *list = (prev ? &prev->siblings : &shost->__devices); in __scsi_iterate_devices()
829 spin_lock_irqsave(shost->host_lock, flags); in __scsi_iterate_devices()
830 while (list->next != &shost->__devices) { in __scsi_iterate_devices()
831 next = list_entry(list->next, struct scsi_device, siblings); in __scsi_iterate_devices()
836 list = list->next; in __scsi_iterate_devices()
838 spin_unlock_irqrestore(shost->host_lock, flags); in __scsi_iterate_devices()
847 * starget_for_each_device - helper to walk all devices of a target
859 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); in starget_for_each_device()
863 if ((sdev->channel == starget->channel) && in starget_for_each_device()
864 (sdev->id == starget->id)) in starget_for_each_device()
871 * __starget_for_each_device - helper to walk all devices of a target (UNLOCKED)
878 * protected by shost->host_lock.
887 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); in __starget_for_each_device()
891 if ((sdev->channel == starget->channel) && in __starget_for_each_device()
892 (sdev->id == starget->id)) in __starget_for_each_device()
899 * __scsi_device_lookup_by_target - find a device given the target (UNLOCKED)
918 list_for_each_entry(sdev, &starget->devices, same_target_siblings) { in __scsi_device_lookup_by_target()
919 if (sdev->sdev_state == SDEV_DEL) in __scsi_device_lookup_by_target()
921 if (sdev->lun ==lun) in __scsi_device_lookup_by_target()
930 * scsi_device_lookup_by_target - find a device given the target
942 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); in scsi_device_lookup_by_target()
945 spin_lock_irqsave(shost->host_lock, flags); in scsi_device_lookup_by_target()
949 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_device_lookup_by_target()
956 * __scsi_device_lookup - find a device given the host (UNLOCKED)
976 list_for_each_entry(sdev, &shost->__devices, siblings) { in __scsi_device_lookup()
977 if (sdev->sdev_state == SDEV_DEL) in __scsi_device_lookup()
979 if (sdev->channel == channel && sdev->id == id && in __scsi_device_lookup()
980 sdev->lun ==lun) in __scsi_device_lookup()
989 * scsi_device_lookup - find a device given the host
1005 spin_lock_irqsave(shost->host_lock, flags); in scsi_device_lookup()
1009 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_device_lookup()
1057 -error); in init_scsi()