Lines Matching refs:shost
74 int scsi_host_set_state(struct Scsi_Host *shost, enum scsi_host_state state) in scsi_host_set_state() argument
76 enum scsi_host_state oldstate = shost->shost_state; in scsi_host_set_state()
147 shost->shost_state = state; in scsi_host_set_state()
152 shost_printk(KERN_ERR, shost, in scsi_host_set_state()
164 void scsi_remove_host(struct Scsi_Host *shost) in scsi_remove_host() argument
168 mutex_lock(&shost->scan_mutex); in scsi_remove_host()
169 spin_lock_irqsave(shost->host_lock, flags); in scsi_remove_host()
170 if (scsi_host_set_state(shost, SHOST_CANCEL)) in scsi_remove_host()
171 if (scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY)) { in scsi_remove_host()
172 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_remove_host()
173 mutex_unlock(&shost->scan_mutex); in scsi_remove_host()
176 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_remove_host()
178 scsi_autopm_get_host(shost); in scsi_remove_host()
179 flush_workqueue(shost->tmf_work_q); in scsi_remove_host()
180 scsi_forget_host(shost); in scsi_remove_host()
181 mutex_unlock(&shost->scan_mutex); in scsi_remove_host()
182 scsi_proc_host_rm(shost); in scsi_remove_host()
184 spin_lock_irqsave(shost->host_lock, flags); in scsi_remove_host()
185 if (scsi_host_set_state(shost, SHOST_DEL)) in scsi_remove_host()
186 BUG_ON(scsi_host_set_state(shost, SHOST_DEL_RECOVERY)); in scsi_remove_host()
187 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_remove_host()
189 transport_unregister_device(&shost->shost_gendev); in scsi_remove_host()
190 device_unregister(&shost->shost_dev); in scsi_remove_host()
191 device_del(&shost->shost_gendev); in scsi_remove_host()
208 int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, in scsi_add_host_with_dma() argument
211 struct scsi_host_template *sht = shost->hostt; in scsi_add_host_with_dma()
214 shost_printk(KERN_INFO, shost, "%s\n", in scsi_add_host_with_dma()
215 sht->info ? sht->info(shost) : sht->name); in scsi_add_host_with_dma()
217 if (!shost->can_queue) { in scsi_add_host_with_dma()
218 shost_printk(KERN_ERR, shost, in scsi_add_host_with_dma()
224 shost->cmd_per_lun = min_t(int, shost->cmd_per_lun, in scsi_add_host_with_dma()
225 shost->can_queue); in scsi_add_host_with_dma()
227 error = scsi_init_sense_cache(shost); in scsi_add_host_with_dma()
231 error = scsi_mq_setup_tags(shost); in scsi_add_host_with_dma()
235 if (!shost->shost_gendev.parent) in scsi_add_host_with_dma()
236 shost->shost_gendev.parent = dev ? dev : &platform_bus; in scsi_add_host_with_dma()
238 dma_dev = shost->shost_gendev.parent; in scsi_add_host_with_dma()
240 shost->dma_dev = dma_dev; in scsi_add_host_with_dma()
247 pm_runtime_get_noresume(&shost->shost_gendev); in scsi_add_host_with_dma()
248 pm_runtime_set_active(&shost->shost_gendev); in scsi_add_host_with_dma()
249 pm_runtime_enable(&shost->shost_gendev); in scsi_add_host_with_dma()
250 device_enable_async_suspend(&shost->shost_gendev); in scsi_add_host_with_dma()
252 error = device_add(&shost->shost_gendev); in scsi_add_host_with_dma()
256 scsi_host_set_state(shost, SHOST_RUNNING); in scsi_add_host_with_dma()
257 get_device(shost->shost_gendev.parent); in scsi_add_host_with_dma()
259 device_enable_async_suspend(&shost->shost_dev); in scsi_add_host_with_dma()
261 get_device(&shost->shost_gendev); in scsi_add_host_with_dma()
262 error = device_add(&shost->shost_dev); in scsi_add_host_with_dma()
266 if (shost->transportt->host_size) { in scsi_add_host_with_dma()
267 shost->shost_data = kzalloc(shost->transportt->host_size, in scsi_add_host_with_dma()
269 if (shost->shost_data == NULL) { in scsi_add_host_with_dma()
275 if (shost->transportt->create_work_queue) { in scsi_add_host_with_dma()
276 snprintf(shost->work_q_name, sizeof(shost->work_q_name), in scsi_add_host_with_dma()
277 "scsi_wq_%d", shost->host_no); in scsi_add_host_with_dma()
278 shost->work_q = alloc_workqueue("%s", in scsi_add_host_with_dma()
280 1, shost->work_q_name); in scsi_add_host_with_dma()
282 if (!shost->work_q) { in scsi_add_host_with_dma()
288 error = scsi_sysfs_add_host(shost); in scsi_add_host_with_dma()
292 scsi_proc_host_add(shost); in scsi_add_host_with_dma()
293 scsi_autopm_put_host(shost); in scsi_add_host_with_dma()
301 device_del(&shost->shost_dev); in scsi_add_host_with_dma()
307 put_device(&shost->shost_dev); in scsi_add_host_with_dma()
308 device_del(&shost->shost_gendev); in scsi_add_host_with_dma()
310 device_disable_async_suspend(&shost->shost_gendev); in scsi_add_host_with_dma()
311 pm_runtime_disable(&shost->shost_gendev); in scsi_add_host_with_dma()
312 pm_runtime_set_suspended(&shost->shost_gendev); in scsi_add_host_with_dma()
313 pm_runtime_put_noidle(&shost->shost_gendev); in scsi_add_host_with_dma()
321 struct Scsi_Host *shost = dev_to_shost(dev); in scsi_host_dev_release() local
324 scsi_proc_hostdir_rm(shost->hostt); in scsi_host_dev_release()
329 if (shost->tmf_work_q) in scsi_host_dev_release()
330 destroy_workqueue(shost->tmf_work_q); in scsi_host_dev_release()
331 if (shost->ehandler) in scsi_host_dev_release()
332 kthread_stop(shost->ehandler); in scsi_host_dev_release()
333 if (shost->work_q) in scsi_host_dev_release()
334 destroy_workqueue(shost->work_q); in scsi_host_dev_release()
336 if (shost->shost_state == SHOST_CREATED) { in scsi_host_dev_release()
344 kfree(dev_name(&shost->shost_dev)); in scsi_host_dev_release()
347 if (shost->tag_set.tags) in scsi_host_dev_release()
348 scsi_mq_destroy_tags(shost); in scsi_host_dev_release()
350 kfree(shost->shost_data); in scsi_host_dev_release()
352 ida_simple_remove(&host_index_ida, shost->host_no); in scsi_host_dev_release()
354 if (shost->shost_state != SHOST_CREATED) in scsi_host_dev_release()
356 kfree(shost); in scsi_host_dev_release()
379 struct Scsi_Host *shost; in scsi_host_alloc() local
386 shost = kzalloc(sizeof(struct Scsi_Host) + privsize, gfp_mask); in scsi_host_alloc()
387 if (!shost) in scsi_host_alloc()
390 shost->host_lock = &shost->default_lock; in scsi_host_alloc()
391 spin_lock_init(shost->host_lock); in scsi_host_alloc()
392 shost->shost_state = SHOST_CREATED; in scsi_host_alloc()
393 INIT_LIST_HEAD(&shost->__devices); in scsi_host_alloc()
394 INIT_LIST_HEAD(&shost->__targets); in scsi_host_alloc()
395 INIT_LIST_HEAD(&shost->eh_cmd_q); in scsi_host_alloc()
396 INIT_LIST_HEAD(&shost->starved_list); in scsi_host_alloc()
397 init_waitqueue_head(&shost->host_wait); in scsi_host_alloc()
398 mutex_init(&shost->scan_mutex); in scsi_host_alloc()
402 kfree(shost); in scsi_host_alloc()
405 shost->host_no = index; in scsi_host_alloc()
407 shost->dma_channel = 0xff; in scsi_host_alloc()
410 shost->max_channel = 0; in scsi_host_alloc()
411 shost->max_id = 8; in scsi_host_alloc()
412 shost->max_lun = 8; in scsi_host_alloc()
415 shost->transportt = &blank_transport_template; in scsi_host_alloc()
423 shost->max_cmd_len = 12; in scsi_host_alloc()
424 shost->hostt = sht; in scsi_host_alloc()
425 shost->this_id = sht->this_id; in scsi_host_alloc()
426 shost->can_queue = sht->can_queue; in scsi_host_alloc()
427 shost->sg_tablesize = sht->sg_tablesize; in scsi_host_alloc()
428 shost->sg_prot_tablesize = sht->sg_prot_tablesize; in scsi_host_alloc()
429 shost->cmd_per_lun = sht->cmd_per_lun; in scsi_host_alloc()
430 shost->unchecked_isa_dma = sht->unchecked_isa_dma; in scsi_host_alloc()
431 shost->no_write_same = sht->no_write_same; in scsi_host_alloc()
432 shost->host_tagset = sht->host_tagset; in scsi_host_alloc()
435 shost->eh_deadline = -1; in scsi_host_alloc()
437 shost_printk(KERN_WARNING, shost, in scsi_host_alloc()
440 shost->eh_deadline = INT_MAX; in scsi_host_alloc()
442 shost->eh_deadline = shost_eh_deadline * HZ; in scsi_host_alloc()
446 shost->active_mode = MODE_INITIATOR; in scsi_host_alloc()
448 shost->active_mode = sht->supported_mode; in scsi_host_alloc()
451 shost->max_host_blocked = sht->max_host_blocked; in scsi_host_alloc()
453 shost->max_host_blocked = SCSI_DEFAULT_HOST_BLOCKED; in scsi_host_alloc()
460 shost->max_sectors = sht->max_sectors; in scsi_host_alloc()
462 shost->max_sectors = SCSI_DEFAULT_MAX_SECTORS; in scsi_host_alloc()
465 shost->max_segment_size = sht->max_segment_size; in scsi_host_alloc()
467 shost->max_segment_size = BLK_MAX_SEGMENT_SIZE; in scsi_host_alloc()
473 shost->dma_boundary = sht->dma_boundary; in scsi_host_alloc()
475 shost->dma_boundary = 0xffffffff; in scsi_host_alloc()
478 shost->virt_boundary_mask = sht->virt_boundary_mask; in scsi_host_alloc()
480 device_initialize(&shost->shost_gendev); in scsi_host_alloc()
481 dev_set_name(&shost->shost_gendev, "host%d", shost->host_no); in scsi_host_alloc()
482 shost->shost_gendev.bus = &scsi_bus_type; in scsi_host_alloc()
483 shost->shost_gendev.type = &scsi_host_type; in scsi_host_alloc()
485 device_initialize(&shost->shost_dev); in scsi_host_alloc()
486 shost->shost_dev.parent = &shost->shost_gendev; in scsi_host_alloc()
487 shost->shost_dev.class = &shost_class; in scsi_host_alloc()
488 dev_set_name(&shost->shost_dev, "host%d", shost->host_no); in scsi_host_alloc()
489 shost->shost_dev.groups = scsi_sysfs_shost_attr_groups; in scsi_host_alloc()
491 shost->ehandler = kthread_run(scsi_error_handler, shost, in scsi_host_alloc()
492 "scsi_eh_%d", shost->host_no); in scsi_host_alloc()
493 if (IS_ERR(shost->ehandler)) { in scsi_host_alloc()
494 shost_printk(KERN_WARNING, shost, in scsi_host_alloc()
496 PTR_ERR(shost->ehandler)); in scsi_host_alloc()
497 shost->ehandler = NULL; in scsi_host_alloc()
501 shost->tmf_work_q = alloc_workqueue("scsi_tmf_%d", in scsi_host_alloc()
503 1, shost->host_no); in scsi_host_alloc()
504 if (!shost->tmf_work_q) { in scsi_host_alloc()
505 shost_printk(KERN_WARNING, shost, in scsi_host_alloc()
509 scsi_proc_hostdir_add(shost->hostt); in scsi_host_alloc()
510 return shost; in scsi_host_alloc()
517 put_device(&shost->shost_gendev); in scsi_host_alloc()
546 struct Scsi_Host *shost = NULL; in scsi_host_lookup() local
551 shost = scsi_host_get(class_to_shost(cdev)); in scsi_host_lookup()
554 return shost; in scsi_host_lookup()
562 struct Scsi_Host *scsi_host_get(struct Scsi_Host *shost) in scsi_host_get() argument
564 if ((shost->shost_state == SHOST_DEL) || in scsi_host_get()
565 !get_device(&shost->shost_gendev)) in scsi_host_get()
567 return shost; in scsi_host_get()
587 int scsi_host_busy(struct Scsi_Host *shost) in scsi_host_busy() argument
591 blk_mq_tagset_busy_iter(&shost->tag_set, in scsi_host_busy()
601 void scsi_host_put(struct Scsi_Host *shost) in scsi_host_put() argument
603 put_device(&shost->shost_gendev); in scsi_host_put()
634 int scsi_queue_work(struct Scsi_Host *shost, struct work_struct *work) in scsi_queue_work() argument
636 if (unlikely(!shost->work_q)) { in scsi_queue_work()
637 shost_printk(KERN_ERR, shost, in scsi_queue_work()
639 "when no workqueue created.\n", shost->hostt->name); in scsi_queue_work()
645 return queue_work(shost->work_q, work); in scsi_queue_work()
653 void scsi_flush_work(struct Scsi_Host *shost) in scsi_flush_work() argument
655 if (!shost->work_q) { in scsi_flush_work()
656 shost_printk(KERN_ERR, shost, in scsi_flush_work()
658 "when no workqueue created.\n", shost->hostt->name); in scsi_flush_work()
663 flush_workqueue(shost->work_q); in scsi_flush_work()
688 void scsi_host_complete_all_commands(struct Scsi_Host *shost, int status) in scsi_host_complete_all_commands() argument
690 blk_mq_tagset_busy_iter(&shost->tag_set, complete_all_cmds_iter, in scsi_host_complete_all_commands()
718 void scsi_host_busy_iter(struct Scsi_Host *shost, in scsi_host_busy_iter() argument
727 blk_mq_tagset_busy_iter(&shost->tag_set, __scsi_host_busy_iter_fn, in scsi_host_busy_iter()