Lines Matching defs:shost
69 * @shost: scsi host to change the state of.
75 int scsi_host_set_state(struct Scsi_Host *shost, enum scsi_host_state state)
77 enum scsi_host_state oldstate = shost->shost_state;
148 shost->shost_state = state;
153 shost_printk(KERN_ERR, shost,
163 * @shost: a pointer to a scsi host to remove
165 void scsi_remove_host(struct Scsi_Host *shost)
169 mutex_lock(&shost->scan_mutex);
170 spin_lock_irqsave(shost->host_lock, flags);
171 if (scsi_host_set_state(shost, SHOST_CANCEL))
172 if (scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY)) {
173 spin_unlock_irqrestore(shost->host_lock, flags);
174 mutex_unlock(&shost->scan_mutex);
177 spin_unlock_irqrestore(shost->host_lock, flags);
179 scsi_autopm_get_host(shost);
180 flush_workqueue(shost->tmf_work_q);
181 scsi_forget_host(shost);
182 mutex_unlock(&shost->scan_mutex);
183 scsi_proc_host_rm(shost);
184 scsi_proc_hostdir_rm(shost->hostt);
192 kref_put(&shost->tagset_refcnt, scsi_mq_free_tags);
193 wait_for_completion(&shost->tagset_freed);
195 spin_lock_irqsave(shost->host_lock, flags);
196 if (scsi_host_set_state(shost, SHOST_DEL))
197 BUG_ON(scsi_host_set_state(shost, SHOST_DEL_RECOVERY));
198 spin_unlock_irqrestore(shost->host_lock, flags);
200 transport_unregister_device(&shost->shost_gendev);
201 device_unregister(&shost->shost_dev);
202 device_del(&shost->shost_gendev);
208 * @shost: scsi host pointer to add
219 int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
222 const struct scsi_host_template *sht = shost->hostt;
225 shost_printk(KERN_INFO, shost, "%s\n",
226 sht->info ? sht->info(shost) : sht->name);
228 if (!shost->can_queue) {
229 shost_printk(KERN_ERR, shost,
234 /* Use min_t(int, ...) in case shost->can_queue exceeds SHRT_MAX */
235 shost->cmd_per_lun = min_t(int, shost->cmd_per_lun,
236 shost->can_queue);
238 error = scsi_init_sense_cache(shost);
242 if (!shost->shost_gendev.parent)
243 shost->shost_gendev.parent = dev ? dev : &platform_bus;
245 dma_dev = shost->shost_gendev.parent;
247 shost->dma_dev = dma_dev;
250 shost->max_sectors = min_t(unsigned int, shost->max_sectors,
254 error = scsi_mq_setup_tags(shost);
258 kref_init(&shost->tagset_refcnt);
259 init_completion(&shost->tagset_freed);
266 pm_runtime_get_noresume(&shost->shost_gendev);
267 pm_runtime_set_active(&shost->shost_gendev);
268 pm_runtime_enable(&shost->shost_gendev);
269 device_enable_async_suspend(&shost->shost_gendev);
271 error = device_add(&shost->shost_gendev);
275 scsi_host_set_state(shost, SHOST_RUNNING);
276 get_device(shost->shost_gendev.parent);
278 device_enable_async_suspend(&shost->shost_dev);
280 get_device(&shost->shost_gendev);
281 error = device_add(&shost->shost_dev);
285 if (shost->transportt->host_size) {
286 shost->shost_data = kzalloc(shost->transportt->host_size,
288 if (shost->shost_data == NULL) {
294 if (shost->transportt->create_work_queue) {
295 snprintf(shost->work_q_name, sizeof(shost->work_q_name),
296 "scsi_wq_%d", shost->host_no);
297 shost->work_q = alloc_workqueue("%s",
299 1, shost->work_q_name);
301 if (!shost->work_q) {
307 error = scsi_sysfs_add_host(shost);
311 scsi_proc_host_add(shost);
312 scsi_autopm_put_host(shost);
320 device_del(&shost->shost_dev);
326 put_device(&shost->shost_dev);
327 device_del(&shost->shost_gendev);
329 device_disable_async_suspend(&shost->shost_gendev);
330 pm_runtime_disable(&shost->shost_gendev);
331 pm_runtime_set_suspended(&shost->shost_gendev);
332 pm_runtime_put_noidle(&shost->shost_gendev);
333 kref_put(&shost->tagset_refcnt, scsi_mq_free_tags);
341 struct Scsi_Host *shost = dev_to_shost(dev);
347 if (shost->tmf_work_q)
348 destroy_workqueue(shost->tmf_work_q);
349 if (shost->ehandler)
350 kthread_stop(shost->ehandler);
351 if (shost->work_q)
352 destroy_workqueue(shost->work_q);
354 if (shost->shost_state == SHOST_CREATED) {
362 kfree(dev_name(&shost->shost_dev));
365 kfree(shost->shost_data);
367 ida_free(&host_index_ida, shost->host_no);
369 if (shost->shost_state != SHOST_CREATED)
371 kfree(shost);
394 struct Scsi_Host *shost;
397 shost = kzalloc(sizeof(struct Scsi_Host) + privsize, GFP_KERNEL);
398 if (!shost)
401 shost->host_lock = &shost->default_lock;
402 spin_lock_init(shost->host_lock);
403 shost->shost_state = SHOST_CREATED;
404 INIT_LIST_HEAD(&shost->__devices);
405 INIT_LIST_HEAD(&shost->__targets);
406 INIT_LIST_HEAD(&shost->eh_abort_list);
407 INIT_LIST_HEAD(&shost->eh_cmd_q);
408 INIT_LIST_HEAD(&shost->starved_list);
409 init_waitqueue_head(&shost->host_wait);
410 mutex_init(&shost->scan_mutex);
414 kfree(shost);
417 shost->host_no = index;
419 shost->dma_channel = 0xff;
422 shost->max_channel = 0;
423 shost->max_id = 8;
424 shost->max_lun = 8;
426 /* Give each shost a default transportt */
427 shost->transportt = &blank_transport_template;
435 shost->max_cmd_len = 12;
436 shost->hostt = sht;
437 shost->this_id = sht->this_id;
438 shost->can_queue = sht->can_queue;
439 shost->sg_tablesize = sht->sg_tablesize;
440 shost->sg_prot_tablesize = sht->sg_prot_tablesize;
441 shost->cmd_per_lun = sht->cmd_per_lun;
442 shost->no_write_same = sht->no_write_same;
443 shost->host_tagset = sht->host_tagset;
444 shost->queuecommand_may_block = sht->queuecommand_may_block;
447 shost->eh_deadline = -1;
449 shost_printk(KERN_WARNING, shost,
452 shost->eh_deadline = INT_MAX;
454 shost->eh_deadline = shost_eh_deadline * HZ;
458 shost->active_mode = MODE_INITIATOR;
460 shost->active_mode = sht->supported_mode;
463 shost->max_host_blocked = sht->max_host_blocked;
465 shost->max_host_blocked = SCSI_DEFAULT_HOST_BLOCKED;
472 shost->max_sectors = sht->max_sectors;
474 shost->max_sectors = SCSI_DEFAULT_MAX_SECTORS;
477 shost->max_segment_size = sht->max_segment_size;
479 shost->max_segment_size = BLK_MAX_SEGMENT_SIZE;
485 shost->dma_boundary = sht->dma_boundary;
487 shost->dma_boundary = 0xffffffff;
490 shost->virt_boundary_mask = sht->virt_boundary_mask;
492 device_initialize(&shost->shost_gendev);
493 dev_set_name(&shost->shost_gendev, "host%d", shost->host_no);
494 shost->shost_gendev.bus = &scsi_bus_type;
495 shost->shost_gendev.type = &scsi_host_type;
496 scsi_enable_async_suspend(&shost->shost_gendev);
498 device_initialize(&shost->shost_dev);
499 shost->shost_dev.parent = &shost->shost_gendev;
500 shost->shost_dev.class = &shost_class;
501 dev_set_name(&shost->shost_dev, "host%d", shost->host_no);
502 shost->shost_dev.groups = sht->shost_groups;
504 shost->ehandler = kthread_run(scsi_error_handler, shost,
505 "scsi_eh_%d", shost->host_no);
506 if (IS_ERR(shost->ehandler)) {
507 shost_printk(KERN_WARNING, shost,
509 PTR_ERR(shost->ehandler));
510 shost->ehandler = NULL;
514 shost->tmf_work_q = alloc_workqueue("scsi_tmf_%d",
516 1, shost->host_no);
517 if (!shost->tmf_work_q) {
518 shost_printk(KERN_WARNING, shost,
522 if (scsi_proc_hostdir_add(shost->hostt) < 0)
524 return shost;
529 * dev_name(&shost->shost_dev).
531 put_device(&shost->shost_gendev);
560 struct Scsi_Host *shost = NULL;
565 shost = scsi_host_get(class_to_shost(cdev));
568 return shost;
574 * @shost: Pointer to Scsi_Host to inc.
576 struct Scsi_Host *scsi_host_get(struct Scsi_Host *shost)
578 if ((shost->shost_state == SHOST_DEL) ||
579 !get_device(&shost->shost_gendev))
581 return shost;
598 * @shost: Pointer to Scsi_Host to inc.
600 int scsi_host_busy(struct Scsi_Host *shost)
604 blk_mq_tagset_busy_iter(&shost->tag_set,
612 * @shost: Pointer to Scsi_Host to dec.
614 void scsi_host_put(struct Scsi_Host *shost)
616 put_device(&shost->shost_gendev);
639 * @shost: Pointer to Scsi_Host.
647 int scsi_queue_work(struct Scsi_Host *shost, struct work_struct *work)
649 if (unlikely(!shost->work_q)) {
650 shost_printk(KERN_ERR, shost,
652 "when no workqueue created.\n", shost->hostt->name);
658 return queue_work(shost->work_q, work);
664 * @shost: Pointer to Scsi_Host.
666 void scsi_flush_work(struct Scsi_Host *shost)
668 if (!shost->work_q) {
669 shost_printk(KERN_ERR, shost,
671 "when no workqueue created.\n", shost->hostt->name);
676 flush_workqueue(shost->work_q);
694 * @shost: Scsi Host on which commands should be terminated
702 void scsi_host_complete_all_commands(struct Scsi_Host *shost,
705 blk_mq_tagset_busy_iter(&shost->tag_set, complete_all_cmds_iter,
725 * @shost: Pointer to Scsi_Host.
732 void scsi_host_busy_iter(struct Scsi_Host *shost,
741 blk_mq_tagset_busy_iter(&shost->tag_set, __scsi_host_busy_iter_fn,