Lines Matching +full:u +full:- +full:blox

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>
27 * Bjorn Ekwall <bj0rn@blox.se>
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
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
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
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
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()
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 if (vpd_buf->data[i] == 0x0) in scsi_attach_vpd()
514 scsi_update_vpd_page(sdev, 0x0, &sdev->vpd_pg0); in scsi_attach_vpd()
515 if (vpd_buf->data[i] == 0x80) in scsi_attach_vpd()
516 scsi_update_vpd_page(sdev, 0x80, &sdev->vpd_pg80); in scsi_attach_vpd()
517 if (vpd_buf->data[i] == 0x83) in scsi_attach_vpd()
518 scsi_update_vpd_page(sdev, 0x83, &sdev->vpd_pg83); in scsi_attach_vpd()
519 if (vpd_buf->data[i] == 0x89) in scsi_attach_vpd()
520 scsi_update_vpd_page(sdev, 0x89, &sdev->vpd_pg89); in scsi_attach_vpd()
521 if (vpd_buf->data[i] == 0xb0) in scsi_attach_vpd()
522 scsi_update_vpd_page(sdev, 0xb0, &sdev->vpd_pgb0); in scsi_attach_vpd()
523 if (vpd_buf->data[i] == 0xb1) in scsi_attach_vpd()
524 scsi_update_vpd_page(sdev, 0xb1, &sdev->vpd_pgb1); in scsi_attach_vpd()
525 if (vpd_buf->data[i] == 0xb2) in scsi_attach_vpd()
526 scsi_update_vpd_page(sdev, 0xb2, &sdev->vpd_pgb2); in scsi_attach_vpd()
527 if (vpd_buf->data[i] == 0xb7) in scsi_attach_vpd()
528 scsi_update_vpd_page(sdev, 0xb7, &sdev->vpd_pgb7); in scsi_attach_vpd()
534 * scsi_report_opcode - Find out if a given command is supported
543 * have a service action, @sa must be 0. Returns -EINVAL if RSOC fails,
558 if (sdev->no_report_opcodes || sdev->scsi_level < SCSI_SPC_3) in scsi_report_opcode()
559 return -EINVAL; in scsi_report_opcode()
564 dev_warn_once(&sdev->sdev_gendev, in scsi_report_opcode()
565 "%s: len %u bytes, opcode 0x%02x needs %u\n", in scsi_report_opcode()
567 return -EINVAL; in scsi_report_opcode()
591 return -EINVAL; in scsi_report_opcode()
617 * See SPC-6, One_command parameter data format for in scsi_cdl_check_cmd()
620 * - rwcdlp == 0: then cdlp indicates support for the A mode page when in scsi_cdl_check_cmd()
623 * - rwcdlp == 1: then cdlp indicates support for the T2A mode page in scsi_cdl_check_cmd()
635 * scsi_cdl_check - Check if a SCSI device supports Command Duration Limits
644 * Support for CDL was defined in SPC-5. Ignore devices reporting an in scsi_cdl_check()
649 if (sdev->scsi_level < SCSI_SPC_5) { in scsi_cdl_check()
650 sdev->cdl_supported = 0; in scsi_cdl_check()
656 sdev->cdl_supported = 0; in scsi_cdl_check()
672 sdev->use_16_for_rw = 1; in scsi_cdl_check()
673 sdev->use_10_for_rw = 0; in scsi_cdl_check()
675 sdev->cdl_supported = 1; in scsi_cdl_check()
682 scsi_cdl_enable(sdev, sdev->cdl_enable); in scsi_cdl_check()
684 sdev->cdl_supported = 0; in scsi_cdl_check()
691 * scsi_cdl_enable - Enable or disable a SCSI device supports for Command
705 if (!sdev->cdl_supported) in scsi_cdl_enable()
706 return -EOPNOTSUPP; in scsi_cdl_enable()
709 vpd = rcu_dereference(sdev->vpd_pg89); in scsi_cdl_enable()
724 return -EINVAL; in scsi_cdl_enable()
728 data.length - data.header_length - in scsi_cdl_enable()
742 dev_name(&sdev->sdev_gendev), &sshdr); in scsi_cdl_enable()
747 sdev->cdl_enable = enable; in scsi_cdl_enable()
753 * scsi_device_get - get an additional reference to a scsi_device
765 if (sdev->sdev_state == SDEV_DEL || sdev->sdev_state == SDEV_CANCEL) in scsi_device_get()
767 if (!try_module_get(sdev->host->hostt->module)) in scsi_device_get()
769 if (!get_device(&sdev->sdev_gendev)) in scsi_device_get()
774 module_put(sdev->host->hostt->module); in scsi_device_get()
776 return -ENXIO; in scsi_device_get()
781 * scsi_device_put - release a reference to a scsi_device
790 struct module *mod = sdev->host->hostt->module; in scsi_device_put()
792 put_device(&sdev->sdev_gendev); in scsi_device_put()
801 struct list_head *list = (prev ? &prev->siblings : &shost->__devices); in __scsi_iterate_devices()
805 spin_lock_irqsave(shost->host_lock, flags); in __scsi_iterate_devices()
806 while (list->next != &shost->__devices) { in __scsi_iterate_devices()
807 next = list_entry(list->next, struct scsi_device, siblings); in __scsi_iterate_devices()
812 list = list->next; in __scsi_iterate_devices()
814 spin_unlock_irqrestore(shost->host_lock, flags); in __scsi_iterate_devices()
823 * starget_for_each_device - helper to walk all devices of a target
835 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); in starget_for_each_device()
839 if ((sdev->channel == starget->channel) && in starget_for_each_device()
840 (sdev->id == starget->id)) in starget_for_each_device()
847 * __starget_for_each_device - helper to walk all devices of a target (UNLOCKED)
854 * protected by shost->host_lock.
863 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); in __starget_for_each_device()
867 if ((sdev->channel == starget->channel) && in __starget_for_each_device()
868 (sdev->id == starget->id)) in __starget_for_each_device()
875 * __scsi_device_lookup_by_target - find a device given the target (UNLOCKED)
894 list_for_each_entry(sdev, &starget->devices, same_target_siblings) { in __scsi_device_lookup_by_target()
895 if (sdev->sdev_state == SDEV_DEL) in __scsi_device_lookup_by_target()
897 if (sdev->lun ==lun) in __scsi_device_lookup_by_target()
906 * scsi_device_lookup_by_target - find a device given the target
918 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); in scsi_device_lookup_by_target()
921 spin_lock_irqsave(shost->host_lock, flags); in scsi_device_lookup_by_target()
925 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_device_lookup_by_target()
932 * __scsi_device_lookup - find a device given the host (UNLOCKED)
952 list_for_each_entry(sdev, &shost->__devices, siblings) { in __scsi_device_lookup()
953 if (sdev->sdev_state == SDEV_DEL) in __scsi_device_lookup()
955 if (sdev->channel == channel && sdev->id == id && in __scsi_device_lookup()
956 sdev->lun ==lun) in __scsi_device_lookup()
965 * scsi_device_lookup - find a device given the host
981 spin_lock_irqsave(shost->host_lock, flags); in scsi_device_lookup()
985 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_device_lookup()
1033 -error); in init_scsi()