Lines Matching refs:shost

72 int scsi_host_set_state(struct Scsi_Host *shost, enum scsi_host_state state)  in scsi_host_set_state()  argument
74 enum scsi_host_state oldstate = shost->shost_state; in scsi_host_set_state()
145 shost->shost_state = state; in scsi_host_set_state()
150 shost_printk(KERN_ERR, shost, in scsi_host_set_state()
162 void scsi_remove_host(struct Scsi_Host *shost) in scsi_remove_host() argument
166 mutex_lock(&shost->scan_mutex); in scsi_remove_host()
167 spin_lock_irqsave(shost->host_lock, flags); in scsi_remove_host()
168 if (scsi_host_set_state(shost, SHOST_CANCEL)) in scsi_remove_host()
169 if (scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY)) { in scsi_remove_host()
170 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_remove_host()
171 mutex_unlock(&shost->scan_mutex); in scsi_remove_host()
174 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_remove_host()
176 scsi_autopm_get_host(shost); in scsi_remove_host()
177 flush_workqueue(shost->tmf_work_q); in scsi_remove_host()
178 scsi_forget_host(shost); in scsi_remove_host()
179 mutex_unlock(&shost->scan_mutex); in scsi_remove_host()
180 scsi_proc_host_rm(shost); in scsi_remove_host()
182 spin_lock_irqsave(shost->host_lock, flags); in scsi_remove_host()
183 if (scsi_host_set_state(shost, SHOST_DEL)) in scsi_remove_host()
184 BUG_ON(scsi_host_set_state(shost, SHOST_DEL_RECOVERY)); in scsi_remove_host()
185 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_remove_host()
187 transport_unregister_device(&shost->shost_gendev); in scsi_remove_host()
188 device_unregister(&shost->shost_dev); in scsi_remove_host()
189 device_del(&shost->shost_gendev); in scsi_remove_host()
206 int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, in scsi_add_host_with_dma() argument
209 struct scsi_host_template *sht = shost->hostt; in scsi_add_host_with_dma()
212 shost_printk(KERN_INFO, shost, "%s\n", in scsi_add_host_with_dma()
213 sht->info ? sht->info(shost) : sht->name); in scsi_add_host_with_dma()
215 if (!shost->can_queue) { in scsi_add_host_with_dma()
216 shost_printk(KERN_ERR, shost, in scsi_add_host_with_dma()
221 error = scsi_init_sense_cache(shost); in scsi_add_host_with_dma()
225 if (shost_use_blk_mq(shost)) { in scsi_add_host_with_dma()
226 error = scsi_mq_setup_tags(shost); in scsi_add_host_with_dma()
230 shost->bqt = blk_init_tags(shost->can_queue, in scsi_add_host_with_dma()
231 shost->hostt->tag_alloc_policy); in scsi_add_host_with_dma()
232 if (!shost->bqt) { in scsi_add_host_with_dma()
238 if (!shost->shost_gendev.parent) in scsi_add_host_with_dma()
239 shost->shost_gendev.parent = dev ? dev : &platform_bus; in scsi_add_host_with_dma()
241 dma_dev = shost->shost_gendev.parent; in scsi_add_host_with_dma()
243 shost->dma_dev = dma_dev; in scsi_add_host_with_dma()
250 pm_runtime_get_noresume(&shost->shost_gendev); in scsi_add_host_with_dma()
251 pm_runtime_set_active(&shost->shost_gendev); in scsi_add_host_with_dma()
252 pm_runtime_enable(&shost->shost_gendev); in scsi_add_host_with_dma()
253 device_enable_async_suspend(&shost->shost_gendev); in scsi_add_host_with_dma()
255 error = device_add(&shost->shost_gendev); in scsi_add_host_with_dma()
259 scsi_host_set_state(shost, SHOST_RUNNING); in scsi_add_host_with_dma()
260 get_device(shost->shost_gendev.parent); in scsi_add_host_with_dma()
262 device_enable_async_suspend(&shost->shost_dev); in scsi_add_host_with_dma()
264 error = device_add(&shost->shost_dev); in scsi_add_host_with_dma()
268 get_device(&shost->shost_gendev); in scsi_add_host_with_dma()
270 if (shost->transportt->host_size) { in scsi_add_host_with_dma()
271 shost->shost_data = kzalloc(shost->transportt->host_size, in scsi_add_host_with_dma()
273 if (shost->shost_data == NULL) { in scsi_add_host_with_dma()
279 if (shost->transportt->create_work_queue) { in scsi_add_host_with_dma()
280 snprintf(shost->work_q_name, sizeof(shost->work_q_name), in scsi_add_host_with_dma()
281 "scsi_wq_%d", shost->host_no); in scsi_add_host_with_dma()
282 shost->work_q = create_singlethread_workqueue( in scsi_add_host_with_dma()
283 shost->work_q_name); in scsi_add_host_with_dma()
284 if (!shost->work_q) { in scsi_add_host_with_dma()
290 error = scsi_sysfs_add_host(shost); in scsi_add_host_with_dma()
294 scsi_proc_host_add(shost); in scsi_add_host_with_dma()
295 scsi_autopm_put_host(shost); in scsi_add_host_with_dma()
299 if (shost->work_q) in scsi_add_host_with_dma()
300 destroy_workqueue(shost->work_q); in scsi_add_host_with_dma()
302 kfree(shost->shost_data); in scsi_add_host_with_dma()
304 device_del(&shost->shost_dev); in scsi_add_host_with_dma()
306 device_del(&shost->shost_gendev); in scsi_add_host_with_dma()
308 device_disable_async_suspend(&shost->shost_gendev); in scsi_add_host_with_dma()
309 pm_runtime_disable(&shost->shost_gendev); in scsi_add_host_with_dma()
310 pm_runtime_set_suspended(&shost->shost_gendev); in scsi_add_host_with_dma()
311 pm_runtime_put_noidle(&shost->shost_gendev); in scsi_add_host_with_dma()
312 if (shost_use_blk_mq(shost)) in scsi_add_host_with_dma()
313 scsi_mq_destroy_tags(shost); 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_use_blk_mq(shost)) { in scsi_host_dev_release()
348 if (shost->tag_set.tags) in scsi_host_dev_release()
349 scsi_mq_destroy_tags(shost); in scsi_host_dev_release()
351 if (shost->bqt) in scsi_host_dev_release()
352 blk_free_tags(shost->bqt); in scsi_host_dev_release()
355 kfree(shost->shost_data); in scsi_host_dev_release()
357 ida_simple_remove(&host_index_ida, shost->host_no); in scsi_host_dev_release()
361 kfree(shost); in scsi_host_dev_release()
384 struct Scsi_Host *shost; in scsi_host_alloc() local
391 shost = kzalloc(sizeof(struct Scsi_Host) + privsize, gfp_mask); in scsi_host_alloc()
392 if (!shost) in scsi_host_alloc()
395 shost->host_lock = &shost->default_lock; in scsi_host_alloc()
396 spin_lock_init(shost->host_lock); in scsi_host_alloc()
397 shost->shost_state = SHOST_CREATED; in scsi_host_alloc()
398 INIT_LIST_HEAD(&shost->__devices); in scsi_host_alloc()
399 INIT_LIST_HEAD(&shost->__targets); in scsi_host_alloc()
400 INIT_LIST_HEAD(&shost->eh_cmd_q); in scsi_host_alloc()
401 INIT_LIST_HEAD(&shost->starved_list); in scsi_host_alloc()
402 init_waitqueue_head(&shost->host_wait); in scsi_host_alloc()
403 mutex_init(&shost->scan_mutex); in scsi_host_alloc()
408 shost->host_no = index; in scsi_host_alloc()
410 shost->dma_channel = 0xff; in scsi_host_alloc()
413 shost->max_channel = 0; in scsi_host_alloc()
414 shost->max_id = 8; in scsi_host_alloc()
415 shost->max_lun = 8; in scsi_host_alloc()
418 shost->transportt = &blank_transport_template; in scsi_host_alloc()
426 shost->max_cmd_len = 12; in scsi_host_alloc()
427 shost->hostt = sht; in scsi_host_alloc()
428 shost->this_id = sht->this_id; in scsi_host_alloc()
429 shost->can_queue = sht->can_queue; in scsi_host_alloc()
430 shost->sg_tablesize = sht->sg_tablesize; in scsi_host_alloc()
431 shost->sg_prot_tablesize = sht->sg_prot_tablesize; in scsi_host_alloc()
432 shost->cmd_per_lun = sht->cmd_per_lun; in scsi_host_alloc()
433 shost->unchecked_isa_dma = sht->unchecked_isa_dma; in scsi_host_alloc()
434 shost->use_clustering = sht->use_clustering; in scsi_host_alloc()
435 shost->no_write_same = sht->no_write_same; in scsi_host_alloc()
438 shost->eh_deadline = -1; in scsi_host_alloc()
440 shost_printk(KERN_WARNING, shost, in scsi_host_alloc()
443 shost->eh_deadline = INT_MAX; in scsi_host_alloc()
445 shost->eh_deadline = shost_eh_deadline * HZ; in scsi_host_alloc()
449 shost->active_mode = MODE_INITIATOR; in scsi_host_alloc()
451 shost->active_mode = sht->supported_mode; in scsi_host_alloc()
454 shost->max_host_blocked = sht->max_host_blocked; in scsi_host_alloc()
456 shost->max_host_blocked = SCSI_DEFAULT_HOST_BLOCKED; in scsi_host_alloc()
463 shost->max_sectors = sht->max_sectors; in scsi_host_alloc()
465 shost->max_sectors = SCSI_DEFAULT_MAX_SECTORS; in scsi_host_alloc()
471 shost->dma_boundary = sht->dma_boundary; in scsi_host_alloc()
473 shost->dma_boundary = 0xffffffff; in scsi_host_alloc()
475 shost->use_blk_mq = scsi_use_blk_mq || shost->hostt->force_blk_mq; in scsi_host_alloc()
477 device_initialize(&shost->shost_gendev); in scsi_host_alloc()
478 dev_set_name(&shost->shost_gendev, "host%d", shost->host_no); in scsi_host_alloc()
479 shost->shost_gendev.bus = &scsi_bus_type; in scsi_host_alloc()
480 shost->shost_gendev.type = &scsi_host_type; in scsi_host_alloc()
482 device_initialize(&shost->shost_dev); in scsi_host_alloc()
483 shost->shost_dev.parent = &shost->shost_gendev; in scsi_host_alloc()
484 shost->shost_dev.class = &shost_class; in scsi_host_alloc()
485 dev_set_name(&shost->shost_dev, "host%d", shost->host_no); in scsi_host_alloc()
486 shost->shost_dev.groups = scsi_sysfs_shost_attr_groups; in scsi_host_alloc()
488 shost->ehandler = kthread_run(scsi_error_handler, shost, in scsi_host_alloc()
489 "scsi_eh_%d", shost->host_no); in scsi_host_alloc()
490 if (IS_ERR(shost->ehandler)) { in scsi_host_alloc()
491 shost_printk(KERN_WARNING, shost, in scsi_host_alloc()
493 PTR_ERR(shost->ehandler)); in scsi_host_alloc()
497 shost->tmf_work_q = alloc_workqueue("scsi_tmf_%d", in scsi_host_alloc()
499 1, shost->host_no); in scsi_host_alloc()
500 if (!shost->tmf_work_q) { in scsi_host_alloc()
501 shost_printk(KERN_WARNING, shost, in scsi_host_alloc()
505 scsi_proc_hostdir_add(shost->hostt); in scsi_host_alloc()
506 return shost; in scsi_host_alloc()
509 kthread_stop(shost->ehandler); in scsi_host_alloc()
511 ida_simple_remove(&host_index_ida, shost->host_no); in scsi_host_alloc()
513 kfree(shost); in scsi_host_alloc()
541 struct Scsi_Host *shost = NULL; in scsi_host_lookup() local
546 shost = scsi_host_get(class_to_shost(cdev)); in scsi_host_lookup()
549 return shost; in scsi_host_lookup()
557 struct Scsi_Host *scsi_host_get(struct Scsi_Host *shost) in scsi_host_get() argument
559 if ((shost->shost_state == SHOST_DEL) || in scsi_host_get()
560 !get_device(&shost->shost_gendev)) in scsi_host_get()
562 return shost; in scsi_host_get()
570 int scsi_host_busy(struct Scsi_Host *shost) in scsi_host_busy() argument
572 return atomic_read(&shost->host_busy); in scsi_host_busy()
580 void scsi_host_put(struct Scsi_Host *shost) in scsi_host_put() argument
582 put_device(&shost->shost_gendev); in scsi_host_put()
613 int scsi_queue_work(struct Scsi_Host *shost, struct work_struct *work) in scsi_queue_work() argument
615 if (unlikely(!shost->work_q)) { in scsi_queue_work()
616 shost_printk(KERN_ERR, shost, in scsi_queue_work()
618 "when no workqueue created.\n", shost->hostt->name); in scsi_queue_work()
624 return queue_work(shost->work_q, work); in scsi_queue_work()
632 void scsi_flush_work(struct Scsi_Host *shost) in scsi_flush_work() argument
634 if (!shost->work_q) { in scsi_flush_work()
635 shost_printk(KERN_ERR, shost, in scsi_flush_work()
637 "when no workqueue created.\n", shost->hostt->name); in scsi_flush_work()
642 flush_workqueue(shost->work_q); in scsi_flush_work()