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()
353 result -= SCSI_VPD_HEADER_SIZE; in scsi_get_vpd_size()
368 dev_warn_once(&sdev->sdev_gendev, in scsi_get_vpd_size()
378 * scsi_get_vpd_page - Get Vital Product Data from a SCSI device
388 * supported or its content cannot be retrieved, -EINVAL is returned.
396 return -EINVAL; in scsi_get_vpd_page()
400 return -EINVAL; in scsi_get_vpd_page()
411 return -EINVAL; in scsi_get_vpd_page()
413 dev_warn_once(&sdev->sdev_gendev, in scsi_get_vpd_page()
422 * scsi_get_vpd_buf - Get Vital Product Data from a SCSI device
446 result = scsi_vpd_inquiry(sdev, vpd_buf->data, page, vpd_len); in scsi_get_vpd_buf()
452 dev_warn_once(&sdev->sdev_gendev, in scsi_get_vpd_buf()
460 vpd_buf->len = result; in scsi_get_vpd_buf()
474 mutex_lock(&sdev->inquiry_mutex); in scsi_update_vpd_page()
476 lockdep_is_held(&sdev->inquiry_mutex)); in scsi_update_vpd_page()
477 mutex_unlock(&sdev->inquiry_mutex); in scsi_update_vpd_page()
484 * scsi_attach_vpd - Attach Vital Product Data to a SCSI device structure
505 for (i = 4; i < vpd_buf->len; i++) { in scsi_attach_vpd()
506 if (vpd_buf->data[i] == 0x0) in scsi_attach_vpd()
507 scsi_update_vpd_page(sdev, 0x0, &sdev->vpd_pg0); in scsi_attach_vpd()
508 if (vpd_buf->data[i] == 0x80) in scsi_attach_vpd()
509 scsi_update_vpd_page(sdev, 0x80, &sdev->vpd_pg80); in scsi_attach_vpd()
510 if (vpd_buf->data[i] == 0x83) in scsi_attach_vpd()
511 scsi_update_vpd_page(sdev, 0x83, &sdev->vpd_pg83); in scsi_attach_vpd()
512 if (vpd_buf->data[i] == 0x89) in scsi_attach_vpd()
513 scsi_update_vpd_page(sdev, 0x89, &sdev->vpd_pg89); in scsi_attach_vpd()
514 if (vpd_buf->data[i] == 0xb0) in scsi_attach_vpd()
515 scsi_update_vpd_page(sdev, 0xb0, &sdev->vpd_pgb0); in scsi_attach_vpd()
516 if (vpd_buf->data[i] == 0xb1) in scsi_attach_vpd()
517 scsi_update_vpd_page(sdev, 0xb1, &sdev->vpd_pgb1); in scsi_attach_vpd()
518 if (vpd_buf->data[i] == 0xb2) in scsi_attach_vpd()
519 scsi_update_vpd_page(sdev, 0xb2, &sdev->vpd_pgb2); in scsi_attach_vpd()
525 * scsi_report_opcode - Find out if a given command is supported
534 * have a service action, @sa must be 0. Returns -EINVAL if RSOC fails,
549 if (sdev->no_report_opcodes || sdev->scsi_level < SCSI_SPC_3) in scsi_report_opcode()
550 return -EINVAL; in scsi_report_opcode()
555 dev_warn_once(&sdev->sdev_gendev, in scsi_report_opcode()
558 return -EINVAL; in scsi_report_opcode()
582 return -EINVAL; in scsi_report_opcode()
608 * See SPC-6, One_command parameter data format for in scsi_cdl_check_cmd()
611 * - rwcdlp == 0: then cdlp indicates support for the A mode page when in scsi_cdl_check_cmd()
614 * - rwcdlp == 1: then cdlp indicates support for the T2A mode page in scsi_cdl_check_cmd()
626 * scsi_cdl_check - Check if a SCSI device supports Command Duration Limits
635 * Support for CDL was defined in SPC-5. Ignore devices reporting an in scsi_cdl_check()
640 if (sdev->scsi_level < SCSI_SPC_5) { in scsi_cdl_check()
641 sdev->cdl_supported = 0; in scsi_cdl_check()
647 sdev->cdl_supported = 0; in scsi_cdl_check()
663 sdev->use_16_for_rw = 1; in scsi_cdl_check()
664 sdev->use_10_for_rw = 0; in scsi_cdl_check()
666 sdev->cdl_supported = 1; in scsi_cdl_check()
668 sdev->cdl_supported = 0; in scsi_cdl_check()
675 * scsi_cdl_enable - Enable or disable a SCSI device supports for Command
689 if (!sdev->cdl_supported) in scsi_cdl_enable()
690 return -EOPNOTSUPP; in scsi_cdl_enable()
693 vpd = rcu_dereference(sdev->vpd_pg89); in scsi_cdl_enable()
708 return -EINVAL; in scsi_cdl_enable()
712 data.length - data.header_length - in scsi_cdl_enable()
726 dev_name(&sdev->sdev_gendev), &sshdr); in scsi_cdl_enable()
731 sdev->cdl_enable = enable; in scsi_cdl_enable()
737 * scsi_device_get - get an additional reference to a scsi_device
749 if (sdev->sdev_state == SDEV_DEL || sdev->sdev_state == SDEV_CANCEL) in scsi_device_get()
751 if (!try_module_get(sdev->host->hostt->module)) in scsi_device_get()
753 if (!get_device(&sdev->sdev_gendev)) in scsi_device_get()
758 module_put(sdev->host->hostt->module); in scsi_device_get()
760 return -ENXIO; in scsi_device_get()
765 * scsi_device_put - release a reference to a scsi_device
774 struct module *mod = sdev->host->hostt->module; in scsi_device_put()
776 put_device(&sdev->sdev_gendev); in scsi_device_put()
785 struct list_head *list = (prev ? &prev->siblings : &shost->__devices); in __scsi_iterate_devices()
789 spin_lock_irqsave(shost->host_lock, flags); in __scsi_iterate_devices()
790 while (list->next != &shost->__devices) { in __scsi_iterate_devices()
791 next = list_entry(list->next, struct scsi_device, siblings); in __scsi_iterate_devices()
796 list = list->next; in __scsi_iterate_devices()
798 spin_unlock_irqrestore(shost->host_lock, flags); in __scsi_iterate_devices()
807 * starget_for_each_device - helper to walk all devices of a target
819 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); in starget_for_each_device()
823 if ((sdev->channel == starget->channel) && in starget_for_each_device()
824 (sdev->id == starget->id)) in starget_for_each_device()
831 * __starget_for_each_device - helper to walk all devices of a target (UNLOCKED)
838 * protected by shost->host_lock.
847 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); in __starget_for_each_device()
851 if ((sdev->channel == starget->channel) && in __starget_for_each_device()
852 (sdev->id == starget->id)) in __starget_for_each_device()
859 * __scsi_device_lookup_by_target - find a device given the target (UNLOCKED)
878 list_for_each_entry(sdev, &starget->devices, same_target_siblings) { in __scsi_device_lookup_by_target()
879 if (sdev->sdev_state == SDEV_DEL) in __scsi_device_lookup_by_target()
881 if (sdev->lun ==lun) in __scsi_device_lookup_by_target()
890 * scsi_device_lookup_by_target - find a device given the target
902 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); in scsi_device_lookup_by_target()
905 spin_lock_irqsave(shost->host_lock, flags); in scsi_device_lookup_by_target()
909 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_device_lookup_by_target()
916 * __scsi_device_lookup - find a device given the host (UNLOCKED)
936 list_for_each_entry(sdev, &shost->__devices, siblings) { in __scsi_device_lookup()
937 if (sdev->sdev_state == SDEV_DEL) in __scsi_device_lookup()
939 if (sdev->channel == channel && sdev->id == id && in __scsi_device_lookup()
940 sdev->lun ==lun) in __scsi_device_lookup()
949 * scsi_device_lookup - find a device given the host
965 spin_lock_irqsave(shost->host_lock, flags); in scsi_device_lookup()
969 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_device_lookup()
1017 -error); in init_scsi()