Lines Matching refs:shost

66 int scsi_host_set_state(struct Scsi_Host *shost, enum scsi_host_state state)  in scsi_host_set_state()  argument
68 enum scsi_host_state oldstate = shost->shost_state; in scsi_host_set_state()
139 shost->shost_state = state; in scsi_host_set_state()
144 shost_printk(KERN_ERR, shost, in scsi_host_set_state()
157 void scsi_remove_host(struct Scsi_Host *shost) in scsi_remove_host() argument
161 mutex_lock(&shost->scan_mutex); in scsi_remove_host()
162 spin_lock_irqsave(shost->host_lock, flags); in scsi_remove_host()
163 if (scsi_host_set_state(shost, SHOST_CANCEL)) in scsi_remove_host()
164 if (scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY)) { in scsi_remove_host()
165 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_remove_host()
166 mutex_unlock(&shost->scan_mutex); in scsi_remove_host()
169 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_remove_host()
171 scsi_autopm_get_host(shost); in scsi_remove_host()
172 flush_workqueue(shost->tmf_work_q); in scsi_remove_host()
173 scsi_forget_host(shost); in scsi_remove_host()
174 mutex_unlock(&shost->scan_mutex); in scsi_remove_host()
175 scsi_proc_host_rm(shost); in scsi_remove_host()
177 spin_lock_irqsave(shost->host_lock, flags); in scsi_remove_host()
178 if (scsi_host_set_state(shost, SHOST_DEL)) in scsi_remove_host()
179 BUG_ON(scsi_host_set_state(shost, SHOST_DEL_RECOVERY)); in scsi_remove_host()
180 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_remove_host()
182 transport_unregister_device(&shost->shost_gendev); in scsi_remove_host()
183 device_unregister(&shost->shost_dev); in scsi_remove_host()
184 device_del(&shost->shost_gendev); in scsi_remove_host()
201 int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, in scsi_add_host_with_dma() argument
204 struct scsi_host_template *sht = shost->hostt; in scsi_add_host_with_dma()
207 shost_printk(KERN_INFO, shost, "%s\n", in scsi_add_host_with_dma()
208 sht->info ? sht->info(shost) : sht->name); in scsi_add_host_with_dma()
210 if (!shost->can_queue) { in scsi_add_host_with_dma()
211 shost_printk(KERN_ERR, shost, in scsi_add_host_with_dma()
216 if (shost_use_blk_mq(shost)) { in scsi_add_host_with_dma()
217 error = scsi_mq_setup_tags(shost); in scsi_add_host_with_dma()
221 shost->bqt = blk_init_tags(shost->can_queue, in scsi_add_host_with_dma()
222 shost->hostt->tag_alloc_policy); in scsi_add_host_with_dma()
223 if (!shost->bqt) { in scsi_add_host_with_dma()
237 error = scsi_setup_command_freelist(shost); in scsi_add_host_with_dma()
242 if (!shost->shost_gendev.parent) in scsi_add_host_with_dma()
243 shost->shost_gendev.parent = dev ? dev : &platform_bus; in scsi_add_host_with_dma()
245 dma_dev = shost->shost_gendev.parent; in scsi_add_host_with_dma()
247 shost->dma_dev = dma_dev; in scsi_add_host_with_dma()
249 error = device_add(&shost->shost_gendev); in scsi_add_host_with_dma()
253 pm_runtime_set_active(&shost->shost_gendev); in scsi_add_host_with_dma()
254 pm_runtime_enable(&shost->shost_gendev); in scsi_add_host_with_dma()
255 device_enable_async_suspend(&shost->shost_gendev); in scsi_add_host_with_dma()
257 scsi_host_set_state(shost, SHOST_RUNNING); in scsi_add_host_with_dma()
258 get_device(shost->shost_gendev.parent); in scsi_add_host_with_dma()
260 device_enable_async_suspend(&shost->shost_dev); in scsi_add_host_with_dma()
262 error = device_add(&shost->shost_dev); in scsi_add_host_with_dma()
266 get_device(&shost->shost_gendev); in scsi_add_host_with_dma()
268 if (shost->transportt->host_size) { in scsi_add_host_with_dma()
269 shost->shost_data = kzalloc(shost->transportt->host_size, in scsi_add_host_with_dma()
271 if (shost->shost_data == NULL) { in scsi_add_host_with_dma()
277 if (shost->transportt->create_work_queue) { in scsi_add_host_with_dma()
278 snprintf(shost->work_q_name, sizeof(shost->work_q_name), in scsi_add_host_with_dma()
279 "scsi_wq_%d", shost->host_no); in scsi_add_host_with_dma()
280 shost->work_q = create_singlethread_workqueue( in scsi_add_host_with_dma()
281 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()
296 if (shost->work_q) in scsi_add_host_with_dma()
297 destroy_workqueue(shost->work_q); in scsi_add_host_with_dma()
299 kfree(shost->shost_data); in scsi_add_host_with_dma()
301 device_del(&shost->shost_dev); in scsi_add_host_with_dma()
303 device_del(&shost->shost_gendev); in scsi_add_host_with_dma()
305 scsi_destroy_command_freelist(shost); in scsi_add_host_with_dma()
307 if (shost_use_blk_mq(shost)) in scsi_add_host_with_dma()
308 scsi_mq_destroy_tags(shost); in scsi_add_host_with_dma()
316 struct Scsi_Host *shost = dev_to_shost(dev); in scsi_host_dev_release() local
321 scsi_proc_hostdir_rm(shost->hostt); in scsi_host_dev_release()
323 if (shost->tmf_work_q) in scsi_host_dev_release()
324 destroy_workqueue(shost->tmf_work_q); in scsi_host_dev_release()
325 if (shost->ehandler) in scsi_host_dev_release()
326 kthread_stop(shost->ehandler); in scsi_host_dev_release()
327 if (shost->work_q) in scsi_host_dev_release()
328 destroy_workqueue(shost->work_q); in scsi_host_dev_release()
329 q = shost->uspace_req_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 scsi_destroy_command_freelist(shost); in scsi_host_dev_release()
348 if (shost_use_blk_mq(shost)) { in scsi_host_dev_release()
349 if (shost->tag_set.tags) in scsi_host_dev_release()
350 scsi_mq_destroy_tags(shost); in scsi_host_dev_release()
352 if (shost->bqt) in scsi_host_dev_release()
353 blk_free_tags(shost->bqt); in scsi_host_dev_release()
356 kfree(shost->shost_data); in scsi_host_dev_release()
360 kfree(shost); in scsi_host_dev_release()
389 struct Scsi_Host *shost; in scsi_host_alloc() local
395 shost = kzalloc(sizeof(struct Scsi_Host) + privsize, gfp_mask); in scsi_host_alloc()
396 if (!shost) in scsi_host_alloc()
399 shost->host_lock = &shost->default_lock; in scsi_host_alloc()
400 spin_lock_init(shost->host_lock); in scsi_host_alloc()
401 shost->shost_state = SHOST_CREATED; in scsi_host_alloc()
402 INIT_LIST_HEAD(&shost->__devices); in scsi_host_alloc()
403 INIT_LIST_HEAD(&shost->__targets); in scsi_host_alloc()
404 INIT_LIST_HEAD(&shost->eh_cmd_q); in scsi_host_alloc()
405 INIT_LIST_HEAD(&shost->starved_list); in scsi_host_alloc()
406 init_waitqueue_head(&shost->host_wait); in scsi_host_alloc()
407 mutex_init(&shost->scan_mutex); in scsi_host_alloc()
413 shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1; in scsi_host_alloc()
414 shost->dma_channel = 0xff; in scsi_host_alloc()
417 shost->max_channel = 0; in scsi_host_alloc()
418 shost->max_id = 8; in scsi_host_alloc()
419 shost->max_lun = 8; in scsi_host_alloc()
422 shost->transportt = &blank_transport_template; in scsi_host_alloc()
430 shost->max_cmd_len = 12; in scsi_host_alloc()
431 shost->hostt = sht; in scsi_host_alloc()
432 shost->this_id = sht->this_id; in scsi_host_alloc()
433 shost->can_queue = sht->can_queue; in scsi_host_alloc()
434 shost->sg_tablesize = sht->sg_tablesize; in scsi_host_alloc()
435 shost->sg_prot_tablesize = sht->sg_prot_tablesize; in scsi_host_alloc()
436 shost->cmd_per_lun = sht->cmd_per_lun; in scsi_host_alloc()
437 shost->unchecked_isa_dma = sht->unchecked_isa_dma; in scsi_host_alloc()
438 shost->use_clustering = sht->use_clustering; in scsi_host_alloc()
439 shost->no_write_same = sht->no_write_same; in scsi_host_alloc()
442 shost->eh_deadline = -1; in scsi_host_alloc()
444 shost_printk(KERN_WARNING, shost, in scsi_host_alloc()
447 shost->eh_deadline = INT_MAX; in scsi_host_alloc()
449 shost->eh_deadline = shost_eh_deadline * HZ; in scsi_host_alloc()
453 shost->active_mode = MODE_INITIATOR; in scsi_host_alloc()
455 shost->active_mode = sht->supported_mode; in scsi_host_alloc()
458 shost->max_host_blocked = sht->max_host_blocked; in scsi_host_alloc()
460 shost->max_host_blocked = SCSI_DEFAULT_HOST_BLOCKED; in scsi_host_alloc()
467 shost->max_sectors = sht->max_sectors; in scsi_host_alloc()
469 shost->max_sectors = SCSI_DEFAULT_MAX_SECTORS; in scsi_host_alloc()
475 shost->dma_boundary = sht->dma_boundary; in scsi_host_alloc()
477 shost->dma_boundary = 0xffffffff; in scsi_host_alloc()
479 shost->use_blk_mq = scsi_use_blk_mq && !shost->hostt->disable_blk_mq; in scsi_host_alloc()
481 device_initialize(&shost->shost_gendev); in scsi_host_alloc()
482 dev_set_name(&shost->shost_gendev, "host%d", shost->host_no); in scsi_host_alloc()
483 shost->shost_gendev.bus = &scsi_bus_type; in scsi_host_alloc()
484 shost->shost_gendev.type = &scsi_host_type; in scsi_host_alloc()
486 device_initialize(&shost->shost_dev); in scsi_host_alloc()
487 shost->shost_dev.parent = &shost->shost_gendev; in scsi_host_alloc()
488 shost->shost_dev.class = &shost_class; in scsi_host_alloc()
489 dev_set_name(&shost->shost_dev, "host%d", shost->host_no); in scsi_host_alloc()
490 shost->shost_dev.groups = scsi_sysfs_shost_attr_groups; in scsi_host_alloc()
492 shost->ehandler = kthread_run(scsi_error_handler, shost, in scsi_host_alloc()
493 "scsi_eh_%d", shost->host_no); in scsi_host_alloc()
494 if (IS_ERR(shost->ehandler)) { in scsi_host_alloc()
495 shost_printk(KERN_WARNING, shost, in scsi_host_alloc()
497 PTR_ERR(shost->ehandler)); 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()
513 kthread_stop(shost->ehandler); in scsi_host_alloc()
515 kfree(shost); in scsi_host_alloc()
522 struct Scsi_Host *shost = scsi_host_alloc(sht, privsize); in scsi_register() local
530 if (shost) in scsi_register()
531 list_add_tail(&shost->sht_legacy_list, &sht->legacy_hosts); in scsi_register()
532 return shost; in scsi_register()
536 void scsi_unregister(struct Scsi_Host *shost) in scsi_unregister() argument
538 list_del(&shost->sht_legacy_list); in scsi_unregister()
539 scsi_host_put(shost); in scsi_unregister()
566 struct Scsi_Host *shost = NULL; in scsi_host_lookup() local
571 shost = scsi_host_get(class_to_shost(cdev)); in scsi_host_lookup()
574 return shost; in scsi_host_lookup()
582 struct Scsi_Host *scsi_host_get(struct Scsi_Host *shost) in scsi_host_get() argument
584 if ((shost->shost_state == SHOST_DEL) || in scsi_host_get()
585 !get_device(&shost->shost_gendev)) in scsi_host_get()
587 return shost; in scsi_host_get()
595 void scsi_host_put(struct Scsi_Host *shost) in scsi_host_put() argument
597 put_device(&shost->shost_gendev); in scsi_host_put()
627 int scsi_queue_work(struct Scsi_Host *shost, struct work_struct *work) in scsi_queue_work() argument
629 if (unlikely(!shost->work_q)) { in scsi_queue_work()
630 shost_printk(KERN_ERR, shost, in scsi_queue_work()
632 "when no workqueue created.\n", shost->hostt->name); in scsi_queue_work()
638 return queue_work(shost->work_q, work); in scsi_queue_work()
646 void scsi_flush_work(struct Scsi_Host *shost) in scsi_flush_work() argument
648 if (!shost->work_q) { in scsi_flush_work()
649 shost_printk(KERN_ERR, shost, in scsi_flush_work()
651 "when no workqueue created.\n", shost->hostt->name); in scsi_flush_work()
656 flush_workqueue(shost->work_q); in scsi_flush_work()