Lines Matching defs:vhost
149 struct ibmvfc_host *vhost = evt->vhost;
154 entry = &vhost->trace[vhost->trace_index++];
183 struct ibmvfc_host *vhost = evt->vhost;
186 struct ibmvfc_trace_entry *entry = &vhost->trace[vhost->trace_index++];
475 * @vhost: ibmvfc host struct
481 static int ibmvfc_set_host_state(struct ibmvfc_host *vhost,
486 switch (vhost->state) {
491 vhost->state = state;
500 * @vhost: ibmvfc host struct
504 static void ibmvfc_set_host_action(struct ibmvfc_host *vhost,
509 if (vhost->action == IBMVFC_HOST_ACTION_INIT_WAIT)
510 vhost->action = action;
513 if (vhost->action == IBMVFC_HOST_ACTION_LOGO)
514 vhost->action = action;
517 if (vhost->action == IBMVFC_HOST_ACTION_INIT)
518 vhost->action = action;
521 switch (vhost->action) {
525 vhost->action = action;
532 if (vhost->action == IBMVFC_HOST_ACTION_ALLOC_TGTS)
533 vhost->action = action;
537 vhost->action = action;
546 switch (vhost->action) {
551 vhost->action = action;
560 * @vhost: ibmvfc host struct
565 static void ibmvfc_reinit_host(struct ibmvfc_host *vhost)
567 if (vhost->action == IBMVFC_HOST_ACTION_NONE &&
568 vhost->state == IBMVFC_ACTIVE) {
569 if (!ibmvfc_set_host_state(vhost, IBMVFC_INITIALIZING)) {
570 scsi_block_requests(vhost->host);
571 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY);
574 vhost->reinit = 1;
576 wake_up(&vhost->work_wait_q);
589 wake_up(&tgt->vhost->work_wait_q);
594 * @vhost: ibmvfc host struct
598 static void ibmvfc_link_down(struct ibmvfc_host *vhost,
604 scsi_block_requests(vhost->host);
605 list_for_each_entry(tgt, &vhost->targets, queue)
607 ibmvfc_set_host_state(vhost, state);
608 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_DEL);
609 vhost->events_to_log |= IBMVFC_AE_LINKDOWN;
610 wake_up(&vhost->work_wait_q);
616 * @vhost: ibmvfc host struct
621 static void ibmvfc_init_host(struct ibmvfc_host *vhost)
625 if (vhost->action == IBMVFC_HOST_ACTION_INIT_WAIT) {
626 if (++vhost->init_retries > IBMVFC_MAX_HOST_INIT_RETRIES) {
627 dev_err(vhost->dev,
629 ibmvfc_link_down(vhost, IBMVFC_HOST_OFFLINE);
634 if (!ibmvfc_set_host_state(vhost, IBMVFC_INITIALIZING)) {
635 memset(vhost->async_crq.msgs, 0, PAGE_SIZE);
636 vhost->async_crq.cur = 0;
638 list_for_each_entry(tgt, &vhost->targets, queue) {
639 if (vhost->client_migrated)
645 scsi_block_requests(vhost->host);
646 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT);
647 vhost->job_step = ibmvfc_npiv_login;
648 wake_up(&vhost->work_wait_q);
654 * @vhost: ibmvfc host struct
661 static int ibmvfc_send_crq(struct ibmvfc_host *vhost, u64 word1, u64 word2)
663 struct vio_dev *vdev = to_vio_dev(vhost->dev);
669 * @vhost: ibmvfc host struct
674 static int ibmvfc_send_crq_init(struct ibmvfc_host *vhost)
676 ibmvfc_dbg(vhost, "Sending CRQ init\n");
677 return ibmvfc_send_crq(vhost, 0xC001000000000000LL, 0);
682 * @vhost: ibmvfc host struct
687 static int ibmvfc_send_crq_init_complete(struct ibmvfc_host *vhost)
689 ibmvfc_dbg(vhost, "Sending CRQ init complete\n");
690 return ibmvfc_send_crq(vhost, 0xC002000000000000LL, 0);
695 * @vhost: ibmvfc host struct
700 static void ibmvfc_release_crq_queue(struct ibmvfc_host *vhost)
703 struct vio_dev *vdev = to_vio_dev(vhost->dev);
704 struct ibmvfc_crq_queue *crq = &vhost->crq;
706 ibmvfc_dbg(vhost, "Releasing CRQ\n");
707 free_irq(vdev->irq, vhost);
708 tasklet_kill(&vhost->tasklet);
715 vhost->state = IBMVFC_NO_CRQ;
716 vhost->logged_in = 0;
717 dma_unmap_single(vhost->dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL);
723 * @vhost: ibmvfc host struct
728 static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost)
731 struct vio_dev *vdev = to_vio_dev(vhost->dev);
741 dev_err(vhost->dev, "Error enabling adapter (rc=%d)\n", rc);
748 * @vhost: ibmvfc host struct
753 static int ibmvfc_reset_crq(struct ibmvfc_host *vhost)
757 struct vio_dev *vdev = to_vio_dev(vhost->dev);
758 struct ibmvfc_crq_queue *crq = &vhost->crq;
767 spin_lock_irqsave(vhost->host->host_lock, flags);
768 vhost->state = IBMVFC_NO_CRQ;
769 vhost->logged_in = 0;
781 dev_warn(vhost->dev, "Partner adapter not ready\n");
783 dev_warn(vhost->dev, "Couldn't register crq (rc=%d)\n", rc);
784 spin_unlock_irqrestore(vhost->host->host_lock, flags);
815 struct ibmvfc_host *vhost = evt->vhost;
816 struct ibmvfc_event_pool *pool = &vhost->pool;
820 list_add_tail(&evt->queue, &vhost->free);
869 * @vhost: ibmvfc host struct
875 static void ibmvfc_purge_requests(struct ibmvfc_host *vhost, int error_code)
879 ibmvfc_dbg(vhost, "Purging all requests\n");
880 list_for_each_entry_safe(evt, pos, &vhost->sent, queue)
886 * @vhost: struct ibmvfc host to reset
888 static void ibmvfc_hard_reset_host(struct ibmvfc_host *vhost)
890 ibmvfc_purge_requests(vhost, DID_ERROR);
891 ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN);
892 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_RESET);
897 * @vhost: struct ibmvfc host to reset
899 static void __ibmvfc_reset_host(struct ibmvfc_host *vhost)
901 if (vhost->logged_in && vhost->action != IBMVFC_HOST_ACTION_LOGO_WAIT &&
902 !ibmvfc_set_host_state(vhost, IBMVFC_INITIALIZING)) {
903 scsi_block_requests(vhost->host);
904 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_LOGO);
905 vhost->job_step = ibmvfc_npiv_logout;
906 wake_up(&vhost->work_wait_q);
908 ibmvfc_hard_reset_host(vhost);
913 * @vhost: ibmvfc host struct
915 static void ibmvfc_reset_host(struct ibmvfc_host *vhost)
919 spin_lock_irqsave(vhost->host->host_lock, flags);
920 __ibmvfc_reset_host(vhost);
921 spin_unlock_irqrestore(vhost->host->host_lock, flags);
926 * @vhost: ibmvfc host struct
931 static int ibmvfc_retry_host_init(struct ibmvfc_host *vhost)
935 if (vhost->action == IBMVFC_HOST_ACTION_INIT_WAIT) {
936 vhost->delay_init = 1;
937 if (++vhost->init_retries > IBMVFC_MAX_HOST_INIT_RETRIES) {
938 dev_err(vhost->dev,
940 ibmvfc_link_down(vhost, IBMVFC_HOST_OFFLINE);
941 } else if (vhost->init_retries == IBMVFC_MAX_HOST_INIT_RETRIES)
942 __ibmvfc_reset_host(vhost);
944 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT);
949 wake_up(&vhost->work_wait_q);
963 struct ibmvfc_host *vhost = shost_priv(shost);
966 list_for_each_entry(tgt, &vhost->targets, queue)
1002 struct ibmvfc_host *vhost = shost_priv(shost);
1006 if (vhost->state == IBMVFC_ACTIVE) {
1007 switch (be64_to_cpu(vhost->login_buf->resp.link_speed) / 100) {
1027 ibmvfc_log(vhost, 3, "Unknown port speed: %lld Gbit\n",
1028 be64_to_cpu(vhost->login_buf->resp.link_speed) / 100);
1046 struct ibmvfc_host *vhost = shost_priv(shost);
1050 switch (vhost->state) {
1069 ibmvfc_log(vhost, 3, "Unknown port state: %d\n", vhost->state);
1150 * @vhost: ibmvfc host struct
1155 static int ibmvfc_wait_while_resetting(struct ibmvfc_host *vhost)
1157 long timeout = wait_event_timeout(vhost->init_wait_q,
1158 ((vhost->state == IBMVFC_ACTIVE ||
1159 vhost->state == IBMVFC_HOST_OFFLINE ||
1160 vhost->state == IBMVFC_LINK_DEAD) &&
1161 vhost->action == IBMVFC_HOST_ACTION_NONE),
1176 struct ibmvfc_host *vhost = shost_priv(shost);
1178 dev_err(vhost->dev, "Initiating host LIP. Resetting connection\n");
1179 ibmvfc_reset_host(vhost);
1180 return ibmvfc_wait_while_resetting(vhost);
1189 static void ibmvfc_gather_partition_info(struct ibmvfc_host *vhost)
1201 strncpy(vhost->partition_name, name, sizeof(vhost->partition_name));
1204 vhost->partition_number = *num;
1210 * @vhost: ibmvfc host struct
1215 static void ibmvfc_set_login_info(struct ibmvfc_host *vhost)
1217 struct ibmvfc_npiv_login *login_info = &vhost->login_info;
1218 struct device_node *of_node = vhost->dev->of_node;
1227 login_info->partition_num = cpu_to_be32(vhost->partition_number);
1231 if (vhost->client_migrated)
1236 login_info->async.va = cpu_to_be64(vhost->async_crq.msg_token);
1237 login_info->async.len = cpu_to_be32(vhost->async_crq.size * sizeof(*vhost->async_crq.msgs));
1238 strncpy(login_info->partition_name, vhost->partition_name, IBMVFC_MAX_NAME);
1240 dev_name(&vhost->host->shost_gendev), IBMVFC_MAX_NAME);
1243 location = location ? location : dev_name(vhost->dev);
1249 * @vhost: ibmvfc host who owns the event pool
1253 static int ibmvfc_init_event_pool(struct ibmvfc_host *vhost)
1256 struct ibmvfc_event_pool *pool = &vhost->pool;
1264 pool->iu_storage = dma_alloc_coherent(vhost->dev,
1279 evt->vhost = vhost;
1281 list_add_tail(&evt->queue, &vhost->free);
1290 * @vhost: ibmvfc host who owns the event pool
1293 static void ibmvfc_free_event_pool(struct ibmvfc_host *vhost)
1296 struct ibmvfc_event_pool *pool = &vhost->pool;
1303 dma_pool_free(vhost->sg_pool,
1309 dma_free_coherent(vhost->dev,
1317 * @vhost: ibmvfc host struct
1321 static struct ibmvfc_event *ibmvfc_get_event(struct ibmvfc_host *vhost)
1325 BUG_ON(list_empty(&vhost->free));
1326 evt = list_entry(vhost->free.next, struct ibmvfc_event, queue);
1385 struct ibmvfc_host *vhost = dev_get_drvdata(dev);
1395 if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
1416 evt->ext_list = dma_pool_alloc(vhost->sg_pool, GFP_ATOMIC,
1421 if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
1444 struct ibmvfc_host *vhost = evt->vhost;
1445 dev_err(vhost->dev, "Command timed out (%p). Resetting connection\n", evt);
1446 ibmvfc_reset_host(vhost);
1452 * @vhost: ibmvfc host struct
1458 struct ibmvfc_host *vhost, unsigned long timeout)
1472 list_add_tail(&evt->queue, &vhost->sent);
1482 if ((rc = ibmvfc_send_crq(vhost, be64_to_cpu(crq_as_u64[0]),
1494 dev_warn(vhost->dev, "Send warning. Receive queue closed, will retry.\n");
1501 dev_err(vhost->dev, "Send error (rc=%d)\n", rc);
1523 struct ibmvfc_host *vhost = evt->vhost;
1536 if (!logerr && (vhost->log_level <= (IBMVFC_DEFAULT_LOG_LEVEL + 1)))
1555 struct ibmvfc_host *vhost = shost_priv(sdev->host);
1559 list_for_each_entry(tgt, &vhost->targets, queue) {
1566 ibmvfc_reinit_host(vhost);
1626 * @vhost: struct ibmvfc host
1631 static inline int ibmvfc_host_chkready(struct ibmvfc_host *vhost)
1635 switch (vhost->state) {
1665 struct ibmvfc_host *vhost = shost_priv(cmnd->device->host);
1672 unlikely((rc = ibmvfc_host_chkready(vhost)))) {
1679 evt = ibmvfc_get_event(vhost);
1701 if (likely(!(rc = ibmvfc_map_sg_data(cmnd, evt, vfc_cmd, vhost->dev))))
1702 return ibmvfc_send_event(evt, vhost, 0);
1708 if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
1740 struct ibmvfc_host *vhost = evt->vhost;
1743 vhost->aborting_passthru = 0;
1744 dev_info(vhost->dev, "Passthru command cancelled\n");
1756 struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
1764 spin_lock_irqsave(vhost->host->host_lock, flags);
1765 if (vhost->aborting_passthru || vhost->state != IBMVFC_ACTIVE) {
1766 __ibmvfc_reset_host(vhost);
1767 spin_unlock_irqrestore(vhost->host->host_lock, flags);
1771 vhost->aborting_passthru = 1;
1772 evt = ibmvfc_get_event(vhost);
1783 rc = ibmvfc_send_event(evt, vhost, default_timeout);
1786 vhost->aborting_passthru = 0;
1787 dev_err(vhost->dev, "Failed to send cancel event. rc=%d\n", rc);
1790 dev_info(vhost->dev, "Cancelling passthru command to port id 0x%lx\n",
1793 spin_unlock_irqrestore(vhost->host->host_lock, flags);
1801 * @vhost: struct ibmvfc_host to send command
1807 static int ibmvfc_bsg_plogi(struct ibmvfc_host *vhost, unsigned int port_id)
1817 spin_lock_irqsave(vhost->host->host_lock, flags);
1818 list_for_each_entry(tgt, &vhost->targets, queue) {
1827 if (unlikely((rc = ibmvfc_host_chkready(vhost))))
1830 evt = ibmvfc_get_event(vhost);
1841 rc = ibmvfc_send_event(evt, vhost, default_timeout);
1842 spin_unlock_irqrestore(vhost->host->host_lock, flags);
1852 spin_lock_irqsave(vhost->host->host_lock, flags);
1855 spin_unlock_irqrestore(vhost->host->host_lock, flags);
1869 struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
1910 if (!mutex_trylock(&vhost->passthru_mutex))
1914 req_seg = dma_map_sg(vhost->dev, job->request_payload.sg_list,
1918 mutex_unlock(&vhost->passthru_mutex);
1922 rsp_seg = dma_map_sg(vhost->dev, job->reply_payload.sg_list,
1926 dma_unmap_sg(vhost->dev, job->request_payload.sg_list,
1928 mutex_unlock(&vhost->passthru_mutex);
1938 rc = ibmvfc_bsg_plogi(vhost, port_id);
1940 spin_lock_irqsave(vhost->host->host_lock, flags);
1943 unlikely((rc = ibmvfc_host_chkready(vhost)))) {
1944 spin_unlock_irqrestore(vhost->host->host_lock, flags);
1948 evt = ibmvfc_get_event(vhost);
1976 rc = ibmvfc_send_event(evt, vhost, 0);
1977 spin_unlock_irqrestore(vhost->host->host_lock, flags);
1991 spin_lock_irqsave(vhost->host->host_lock, flags);
1993 spin_unlock_irqrestore(vhost->host->host_lock, flags);
1999 dma_unmap_sg(vhost->dev, job->request_payload.sg_list,
2001 dma_unmap_sg(vhost->dev, job->reply_payload.sg_list,
2003 mutex_unlock(&vhost->passthru_mutex);
2019 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2029 spin_lock_irqsave(vhost->host->host_lock, flags);
2030 if (vhost->state == IBMVFC_ACTIVE) {
2031 evt = ibmvfc_get_event(vhost);
2049 rsp_rc = ibmvfc_send_event(evt, vhost, default_timeout);
2051 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2078 spin_lock_irqsave(vhost->host->host_lock, flags);
2080 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2136 * @vhost: ibmvfc host struct
2143 static int ibmvfc_wait_for_ops(struct ibmvfc_host *vhost, void *device,
2155 spin_lock_irqsave(vhost->host->host_lock, flags);
2156 list_for_each_entry(evt, &vhost->sent, queue) {
2162 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2169 spin_lock_irqsave(vhost->host->host_lock, flags);
2170 list_for_each_entry(evt, &vhost->sent, queue) {
2176 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2178 dev_err(vhost->dev, "Timed out waiting for aborted commands\n");
2202 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2213 spin_lock_irqsave(vhost->host->host_lock, flags);
2215 list_for_each_entry(evt, &vhost->sent, queue) {
2223 if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
2225 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2229 if (vhost->logged_in) {
2230 evt = ibmvfc_get_event(vhost);
2240 if (!(be64_to_cpu(vhost->login_buf->resp.capabilities) & IBMVFC_CAN_SUPPRESS_ABTS))
2242 if (vhost->state == IBMVFC_ACTIVE)
2251 rsp_rc = ibmvfc_send_event(evt, vhost, default_timeout);
2254 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2268 spin_lock_irqsave(vhost->host->host_lock, flags);
2270 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2334 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2344 spin_lock_irqsave(vhost->host->host_lock, flags);
2346 list_for_each_entry(evt, &vhost->sent, queue) {
2354 if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
2356 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2360 if (vhost->state == IBMVFC_ACTIVE) {
2361 evt = ibmvfc_get_event(vhost);
2379 rsp_rc = ibmvfc_send_event(evt, vhost, default_timeout);
2382 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2395 rc = ibmvfc_wait_for_ops(vhost, sdev->hostdata, ibmvfc_match_key);
2402 ibmvfc_reset_host(vhost);
2404 rc = ibmvfc_wait_for_ops(vhost, sdev->hostdata, ibmvfc_match_key);
2409 rc = ibmvfc_wait_for_ops(vhost, evt, ibmvfc_match_evt);
2411 spin_lock_irqsave(vhost->host->host_lock, flags);
2412 ibmvfc_hard_reset_host(vhost);
2413 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2438 spin_lock_irqsave(vhost->host->host_lock, flags);
2440 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2454 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2460 ibmvfc_wait_while_resetting(vhost);
2468 rc = ibmvfc_wait_for_ops(vhost, sdev, ibmvfc_match_lun);
2487 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2493 ibmvfc_wait_while_resetting(vhost);
2501 rc = ibmvfc_wait_for_ops(vhost, sdev, ibmvfc_match_lun);
2544 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2553 ibmvfc_wait_while_resetting(vhost);
2561 rc = ibmvfc_wait_for_ops(vhost, starget, ibmvfc_match_target);
2578 struct ibmvfc_host *vhost = shost_priv(cmd->device->host);
2580 dev_err(vhost->dev, "Resetting connection due to error recovery\n");
2581 rc = ibmvfc_issue_fc_host_lip(vhost->host);
2596 struct ibmvfc_host *vhost = shost_priv(shost);
2611 rc = ibmvfc_wait_for_ops(vhost, rport, ibmvfc_match_rport);
2618 list_for_each_entry(tgt, &vhost->targets, queue) {
2632 ibmvfc_reinit_host(vhost);
2704 * @vhost: ibmvfc host struct
2708 struct ibmvfc_host *vhost)
2713 ibmvfc_log(vhost, desc->log_level, "%s event received. scsi_id: %llx, wwpn: %llx,"
2722 ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN);
2725 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
2730 vhost->events_to_log |= IBMVFC_AE_LINKUP;
2731 vhost->delay_init = 1;
2732 __ibmvfc_reset_host(vhost);
2738 vhost->events_to_log |= IBMVFC_AE_LINKUP;
2739 vhost->delay_init = 1;
2740 __ibmvfc_reset_host(vhost);
2744 vhost->events_to_log |= IBMVFC_AE_RSCN;
2745 if (vhost->state < IBMVFC_HALTED) {
2746 vhost->delay_init = 1;
2747 __ibmvfc_reset_host(vhost);
2752 vhost->events_to_log |= IBMVFC_AE_RSCN;
2753 ibmvfc_reinit_host(vhost);
2758 list_for_each_entry(tgt, &vhost->targets, queue) {
2771 ibmvfc_reinit_host(vhost);
2777 ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN);
2780 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
2783 ibmvfc_link_down(vhost, IBMVFC_HALTED);
2786 dev_err(vhost->dev, "Unknown async event received: %lld\n", crq->event);
2794 * @vhost: ibmvfc host struct
2797 static void ibmvfc_handle_crq(struct ibmvfc_crq *crq, struct ibmvfc_host *vhost)
2806 dev_info(vhost->dev, "Partner initialized\n");
2808 rc = ibmvfc_send_crq_init_complete(vhost);
2810 ibmvfc_init_host(vhost);
2812 dev_err(vhost->dev, "Unable to send init rsp. rc=%ld\n", rc);
2815 dev_info(vhost->dev, "Partner initialization complete\n");
2816 ibmvfc_init_host(vhost);
2819 dev_err(vhost->dev, "Unknown crq message type: %d\n", crq->format);
2823 vhost->state = IBMVFC_NO_CRQ;
2824 vhost->logged_in = 0;
2825 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_NONE);
2828 dev_info(vhost->dev, "Partition migrated, Re-enabling adapter\n");
2829 vhost->client_migrated = 1;
2831 scsi_block_requests(vhost->host);
2832 ibmvfc_purge_requests(vhost, DID_REQUEUE);
2833 ibmvfc_set_host_state(vhost, IBMVFC_LINK_DOWN);
2834 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_REENABLE);
2835 wake_up(&vhost->work_wait_q);
2837 dev_err(vhost->dev, "Host partner adapter deregistered or failed (rc=%d)\n", crq->format);
2838 ibmvfc_purge_requests(vhost, DID_ERROR);
2839 ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN);
2840 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_RESET);
2842 dev_err(vhost->dev, "Received unknown transport event from partner (rc=%d)\n", crq->format);
2848 dev_err(vhost->dev, "Got an invalid message type 0x%02x\n", crq->valid);
2859 if (unlikely(!ibmvfc_valid_event(&vhost->pool, evt))) {
2860 dev_err(vhost->dev, "Returned correlation_token 0x%08llx is invalid!\n",
2866 dev_err(vhost->dev, "Received duplicate correlation_token 0x%08llx!\n",
2888 struct ibmvfc_host *vhost = shost_priv(shost);
2893 dev_info(vhost->dev, "Scan taking longer than %d seconds, "
2898 if (vhost->scan_complete)
2918 struct ibmvfc_host *vhost = shost_priv(shost);
2925 sdev->hostdata = (void *)(unsigned long)vhost->task_set++;
2943 struct ibmvfc_host *vhost = shost_priv(shost);
2947 starget->hostdata = (void *)(unsigned long)vhost->task_set++;
2997 struct ibmvfc_host *vhost = shost_priv(shost);
3000 vhost->login_buf->resp.partition_name);
3007 struct ibmvfc_host *vhost = shost_priv(shost);
3010 vhost->login_buf->resp.device_name);
3017 struct ibmvfc_host *vhost = shost_priv(shost);
3020 vhost->login_buf->resp.port_loc_code);
3027 struct ibmvfc_host *vhost = shost_priv(shost);
3030 vhost->login_buf->resp.drc_name);
3037 struct ibmvfc_host *vhost = shost_priv(shost);
3038 return snprintf(buf, PAGE_SIZE, "%d\n", vhost->login_buf->resp.version);
3045 struct ibmvfc_host *vhost = shost_priv(shost);
3046 return snprintf(buf, PAGE_SIZE, "%llx\n", vhost->login_buf->resp.capabilities);
3061 struct ibmvfc_host *vhost = shost_priv(shost);
3066 len = snprintf(buf, PAGE_SIZE, "%d\n", vhost->log_level);
3084 struct ibmvfc_host *vhost = shost_priv(shost);
3088 vhost->log_level = simple_strtoul(buf, NULL, 10);
3121 struct ibmvfc_host *vhost = shost_priv(shost);
3124 char *src = (char *)vhost->trace;
3186 * @vhost: ibmvfc host struct
3191 static struct ibmvfc_async_crq *ibmvfc_next_async_crq(struct ibmvfc_host *vhost)
3193 struct ibmvfc_async_crq_queue *async_crq = &vhost->async_crq;
3209 * @vhost: ibmvfc host struct
3214 static struct ibmvfc_crq *ibmvfc_next_crq(struct ibmvfc_host *vhost)
3216 struct ibmvfc_crq_queue *queue = &vhost->crq;
3240 struct ibmvfc_host *vhost = (struct ibmvfc_host *)dev_instance;
3243 spin_lock_irqsave(vhost->host->host_lock, flags);
3244 vio_disable_interrupts(to_vio_dev(vhost->dev));
3245 tasklet_schedule(&vhost->tasklet);
3246 spin_unlock_irqrestore(vhost->host->host_lock, flags);
3259 struct ibmvfc_host *vhost = data;
3260 struct vio_dev *vdev = to_vio_dev(vhost->dev);
3266 spin_lock_irqsave(vhost->host->host_lock, flags);
3269 while ((async = ibmvfc_next_async_crq(vhost)) != NULL) {
3270 ibmvfc_handle_async(async, vhost);
3276 while ((crq = ibmvfc_next_crq(vhost)) != NULL) {
3277 ibmvfc_handle_crq(crq, vhost);
3283 if ((async = ibmvfc_next_async_crq(vhost)) != NULL) {
3285 ibmvfc_handle_async(async, vhost);
3288 } else if ((crq = ibmvfc_next_crq(vhost)) != NULL) {
3290 ibmvfc_handle_crq(crq, vhost);
3297 spin_unlock_irqrestore(vhost->host->host_lock, flags);
3311 wake_up(&tgt->vhost->work_wait_q);
3327 wake_up(&tgt->vhost->work_wait_q);
3376 struct ibmvfc_host *vhost = evt->vhost;
3382 vhost->discovery_threads--;
3434 wake_up(&vhost->work_wait_q);
3445 struct ibmvfc_host *vhost = tgt->vhost;
3448 if (vhost->discovery_threads >= disc_threads)
3452 evt = ibmvfc_get_event(vhost);
3453 vhost->discovery_threads++;
3472 if (ibmvfc_send_event(evt, vhost, default_timeout)) {
3473 vhost->discovery_threads--;
3488 struct ibmvfc_host *vhost = evt->vhost;
3493 vhost->discovery_threads--;
3500 vhost->reinit = 1;
3535 wake_up(&vhost->work_wait_q);
3546 struct ibmvfc_host *vhost = tgt->vhost;
3549 if (vhost->discovery_threads >= disc_threads)
3554 evt = ibmvfc_get_event(vhost);
3555 vhost->discovery_threads++;
3566 if (ibmvfc_send_event(evt, vhost, default_timeout)) {
3567 vhost->discovery_threads--;
3582 struct ibmvfc_host *vhost = evt->vhost;
3586 vhost->discovery_threads--;
3596 wake_up(&vhost->work_wait_q);
3606 wake_up(&vhost->work_wait_q);
3620 struct ibmvfc_host *vhost = tgt->vhost;
3624 evt = ibmvfc_get_event(vhost);
3643 struct ibmvfc_host *vhost = tgt->vhost;
3646 if (vhost->discovery_threads >= disc_threads)
3649 vhost->discovery_threads++;
3654 if (ibmvfc_send_event(evt, vhost, default_timeout)) {
3655 vhost->discovery_threads--;
3670 struct ibmvfc_host *vhost = evt->vhost;
3674 vhost->discovery_threads--;
3684 if (status == IBMVFC_MAD_SUCCESS || vhost->state == IBMVFC_HOST_OFFLINE)
3691 wake_up(&vhost->work_wait_q);
3701 struct ibmvfc_host *vhost = tgt->vhost;
3704 if (!vhost->logged_in) {
3709 if (vhost->discovery_threads >= disc_threads)
3712 vhost->discovery_threads++;
3717 if (ibmvfc_send_event(evt, vhost, default_timeout)) {
3718 vhost->discovery_threads--;
3733 struct ibmvfc_host *vhost = evt->vhost;
3738 vhost->discovery_threads--;
3770 wake_up(&vhost->work_wait_q);
3781 struct ibmvfc_host *vhost = tgt->vhost;
3785 if (vhost->discovery_threads >= disc_threads)
3789 evt = ibmvfc_get_event(vhost);
3790 vhost->discovery_threads++;
3805 if (ibmvfc_send_event(evt, vhost, default_timeout)) {
3806 vhost->discovery_threads--;
3841 struct ibmvfc_host *vhost = evt->vhost;
3846 vhost->discovery_threads--;
3873 wake_up(&vhost->work_wait_q);
3916 struct ibmvfc_host *vhost = evt->vhost;
3920 vhost->abort_threads--;
3923 wake_up(&vhost->work_wait_q);
3937 struct ibmvfc_host *vhost = tgt->vhost;
3944 spin_lock_irqsave(vhost->host->host_lock, flags);
3945 if (vhost->abort_threads >= disc_threads ||
3947 vhost->state != IBMVFC_INITIALIZING ||
3948 vhost->action != IBMVFC_HOST_ACTION_QUERY_TGTS) {
3949 spin_unlock_irqrestore(vhost->host->host_lock, flags);
3953 vhost->abort_threads++;
3955 evt = ibmvfc_get_event(vhost);
3967 rc = ibmvfc_send_event(evt, vhost, default_timeout);
3971 vhost->abort_threads--;
3973 __ibmvfc_reset_host(vhost);
3976 spin_unlock_irqrestore(vhost->host->host_lock, flags);
3993 struct ibmvfc_host *vhost = tgt->vhost;
3996 if (vhost->discovery_threads >= disc_threads)
4000 evt = ibmvfc_get_event(vhost);
4001 vhost->discovery_threads++;
4012 memcpy(&mad->fc_iu.payload[2], &vhost->login_buf->resp.port_name,
4013 sizeof(vhost->login_buf->resp.port_name));
4014 memcpy(&mad->fc_iu.payload[4], &vhost->login_buf->resp.node_name,
4015 sizeof(vhost->login_buf->resp.node_name));
4016 mad->fc_iu.payload[6] = cpu_to_be32(be64_to_cpu(vhost->login_buf->resp.scsi_id) & 0x00ffffff);
4026 if (ibmvfc_send_event(evt, vhost, IBMVFC_ADISC_PLUS_CANCEL_TIMEOUT)) {
4027 vhost->discovery_threads--;
4043 struct ibmvfc_host *vhost = evt->vhost;
4048 vhost->discovery_threads--;
4085 wake_up(&vhost->work_wait_q);
4096 struct ibmvfc_host *vhost = tgt->vhost;
4099 if (vhost->discovery_threads >= disc_threads)
4103 evt = ibmvfc_get_event(vhost);
4104 vhost->discovery_threads++;
4115 if (ibmvfc_send_event(evt, vhost, default_timeout)) {
4116 vhost->discovery_threads--;
4125 * @vhost: ibmvfc host struct
4131 static int ibmvfc_alloc_target(struct ibmvfc_host *vhost,
4142 spin_lock_irqsave(vhost->host->host_lock, flags);
4143 list_for_each_entry(tgt, &vhost->targets, queue) {
4150 list_for_each_entry(tgt, &vhost->targets, queue) {
4189 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4191 tgt = mempool_alloc(vhost->tgt_pool, GFP_NOIO);
4195 tgt->vhost = vhost;
4200 spin_lock_irqsave(vhost->host->host_lock, flags);
4201 tgt->cancel_key = vhost->task_set++;
4202 list_add_tail(&tgt->queue, &vhost->targets);
4205 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4211 * @vhost: ibmvfc host struct
4216 static int ibmvfc_alloc_targets(struct ibmvfc_host *vhost)
4220 for (i = 0, rc = 0; !rc && i < vhost->num_targets; i++)
4221 rc = ibmvfc_alloc_target(vhost, &vhost->disc_buf[i]);
4233 struct ibmvfc_host *vhost = evt->vhost;
4240 ibmvfc_dbg(vhost, "Discover Targets succeeded\n");
4241 vhost->num_targets = be32_to_cpu(rsp->num_written);
4242 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_ALLOC_TGTS);
4245 level += ibmvfc_retry_host_init(vhost);
4246 ibmvfc_log(vhost, level, "Discover Targets failed: %s (%x:%x)\n",
4253 dev_err(vhost->dev, "Invalid Discover Targets response: 0x%x\n", mad_status);
4254 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
4259 wake_up(&vhost->work_wait_q);
4264 * @vhost: ibmvfc host struct
4267 static void ibmvfc_discover_targets(struct ibmvfc_host *vhost)
4270 struct ibmvfc_event *evt = ibmvfc_get_event(vhost);
4278 mad->bufflen = cpu_to_be32(vhost->disc_buf_sz);
4279 mad->buffer.va = cpu_to_be64(vhost->disc_buf_dma);
4280 mad->buffer.len = cpu_to_be32(vhost->disc_buf_sz);
4282 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT_WAIT);
4284 if (!ibmvfc_send_event(evt, vhost, default_timeout))
4285 ibmvfc_dbg(vhost, "Sent discover targets\n");
4287 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
4297 struct ibmvfc_host *vhost = evt->vhost;
4299 struct ibmvfc_npiv_login_resp *rsp = &vhost->login_buf->resp;
4309 level += ibmvfc_retry_host_init(vhost);
4311 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
4312 ibmvfc_log(vhost, level, "NPIV Login failed: %s (%x:%x)\n",
4318 ibmvfc_retry_host_init(vhost);
4324 dev_err(vhost->dev, "Invalid NPIV Login response: 0x%x\n", mad_status);
4325 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
4330 vhost->client_migrated = 0;
4333 dev_err(vhost->dev, "Virtual adapter does not support FC. %x\n",
4335 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
4336 wake_up(&vhost->work_wait_q);
4341 dev_err(vhost->dev, "Virtual adapter supported queue depth too small: %d\n",
4343 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
4344 wake_up(&vhost->work_wait_q);
4348 vhost->logged_in = 1;
4350 dev_info(vhost->dev, "Host partition: %s, device: %s %s %s max sectors %u\n",
4354 fc_host_fabric_name(vhost->host) = be64_to_cpu(rsp->node_name);
4355 fc_host_node_name(vhost->host) = be64_to_cpu(rsp->node_name);
4356 fc_host_port_name(vhost->host) = be64_to_cpu(rsp->port_name);
4357 fc_host_port_id(vhost->host) = be64_to_cpu(rsp->scsi_id);
4358 fc_host_port_type(vhost->host) = FC_PORTTYPE_NPIV;
4359 fc_host_supported_classes(vhost->host) = 0;
4361 fc_host_supported_classes(vhost->host) |= FC_COS_CLASS1;
4363 fc_host_supported_classes(vhost->host) |= FC_COS_CLASS2;
4365 fc_host_supported_classes(vhost->host) |= FC_COS_CLASS3;
4366 fc_host_maxframe_size(vhost->host) =
4369 vhost->host->can_queue = be32_to_cpu(rsp->max_cmds) - IBMVFC_NUM_INTERNAL_REQ;
4370 vhost->host->max_sectors = npiv_max_sectors;
4371 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY);
4372 wake_up(&vhost->work_wait_q);
4377 * @vhost: ibmvfc host struct
4380 static void ibmvfc_npiv_login(struct ibmvfc_host *vhost)
4383 struct ibmvfc_event *evt = ibmvfc_get_event(vhost);
4385 ibmvfc_gather_partition_info(vhost);
4386 ibmvfc_set_login_info(vhost);
4389 memcpy(vhost->login_buf, &vhost->login_info, sizeof(vhost->login_info));
4395 mad->buffer.va = cpu_to_be64(vhost->login_buf_dma);
4396 mad->buffer.len = cpu_to_be32(sizeof(*vhost->login_buf));
4398 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT_WAIT);
4400 if (!ibmvfc_send_event(evt, vhost, default_timeout))
4401 ibmvfc_dbg(vhost, "Sent NPIV login\n");
4403 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
4408 * @vhost: ibmvfc host struct
4413 struct ibmvfc_host *vhost = evt->vhost;
4420 if (list_empty(&vhost->sent) &&
4421 vhost->action == IBMVFC_HOST_ACTION_LOGO_WAIT) {
4422 ibmvfc_init_host(vhost);
4431 ibmvfc_dbg(vhost, "NPIV Logout failed. 0x%X\n", mad_status);
4435 ibmvfc_hard_reset_host(vhost);
4440 * @vhost: ibmvfc host struct
4443 static void ibmvfc_npiv_logout(struct ibmvfc_host *vhost)
4448 evt = ibmvfc_get_event(vhost);
4457 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_LOGO_WAIT);
4459 if (!ibmvfc_send_event(evt, vhost, default_timeout))
4460 ibmvfc_dbg(vhost, "Sent NPIV logout\n");
4462 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
4467 * @vhost: ibmvfc host struct
4472 static int ibmvfc_dev_init_to_do(struct ibmvfc_host *vhost)
4476 list_for_each_entry(tgt, &vhost->targets, queue) {
4487 * @vhost: ibmvfc host struct
4492 static int ibmvfc_dev_logo_to_do(struct ibmvfc_host *vhost)
4496 list_for_each_entry(tgt, &vhost->targets, queue) {
4506 * @vhost: ibmvfc host struct
4511 static int __ibmvfc_work_to_do(struct ibmvfc_host *vhost)
4517 switch (vhost->action) {
4524 if (vhost->discovery_threads == disc_threads)
4526 list_for_each_entry(tgt, &vhost->targets, queue)
4529 list_for_each_entry(tgt, &vhost->targets, queue)
4535 if (vhost->discovery_threads == disc_threads)
4537 list_for_each_entry(tgt, &vhost->targets, queue)
4540 list_for_each_entry(tgt, &vhost->targets, queue)
4559 * @vhost: ibmvfc host struct
4564 static int ibmvfc_work_to_do(struct ibmvfc_host *vhost)
4569 spin_lock_irqsave(vhost->host->host_lock, flags);
4570 rc = __ibmvfc_work_to_do(vhost);
4571 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4577 * @vhost: ibmvfc host struct
4581 static void ibmvfc_log_ae(struct ibmvfc_host *vhost, int events)
4584 fc_host_post_event(vhost->host, fc_get_event_number(), FCH_EVT_RSCN, 0);
4586 vhost->state >= IBMVFC_HALTED)
4587 fc_host_post_event(vhost->host, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
4589 vhost->state == IBMVFC_INITIALIZING)
4590 fc_host_post_event(vhost->host, fc_get_event_number(), FCH_EVT_LINKUP, 0);
4600 struct ibmvfc_host *vhost = tgt->vhost;
4605 rport = fc_remote_port_add(vhost->host, 0, &tgt->ids);
4606 spin_lock_irqsave(vhost->host->host_lock, flags);
4612 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4621 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4625 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4645 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4650 * @vhost: ibmvfc host struct
4653 static void ibmvfc_do_work(struct ibmvfc_host *vhost)
4660 ibmvfc_log_ae(vhost, vhost->events_to_log);
4661 spin_lock_irqsave(vhost->host->host_lock, flags);
4662 vhost->events_to_log = 0;
4663 switch (vhost->action) {
4669 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4670 rc = ibmvfc_reset_crq(vhost);
4672 spin_lock_irqsave(vhost->host->host_lock, flags);
4674 vio_enable_interrupts(to_vio_dev(vhost->dev));
4675 if (vhost->action == IBMVFC_HOST_ACTION_RESET) {
4682 vhost->action = IBMVFC_HOST_ACTION_TGT_DEL;
4684 if (rc || (rc = ibmvfc_send_crq_init(vhost)) ||
4685 (rc = vio_enable_interrupts(to_vio_dev(vhost->dev)))) {
4686 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
4687 dev_err(vhost->dev, "Error after reset (rc=%d)\n", rc);
4692 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4693 rc = ibmvfc_reenable_crq_queue(vhost);
4695 spin_lock_irqsave(vhost->host->host_lock, flags);
4696 if (vhost->action == IBMVFC_HOST_ACTION_REENABLE) {
4703 vhost->action = IBMVFC_HOST_ACTION_TGT_DEL;
4704 if (rc || (rc = ibmvfc_send_crq_init(vhost))) {
4705 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
4706 dev_err(vhost->dev, "Error after enable (rc=%d)\n", rc);
4711 vhost->job_step(vhost);
4714 BUG_ON(vhost->state != IBMVFC_INITIALIZING);
4715 if (vhost->delay_init) {
4716 vhost->delay_init = 0;
4717 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4721 vhost->job_step(vhost);
4724 list_for_each_entry(tgt, &vhost->targets, queue)
4726 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY_TGTS);
4729 list_for_each_entry(tgt, &vhost->targets, queue) {
4736 if (!ibmvfc_dev_init_to_do(vhost))
4737 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_DEL);
4741 list_for_each_entry(tgt, &vhost->targets, queue) {
4748 if (ibmvfc_dev_logo_to_do(vhost)) {
4749 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4753 list_for_each_entry(tgt, &vhost->targets, queue) {
4760 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4771 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4778 if (vhost->state == IBMVFC_INITIALIZING) {
4779 if (vhost->action == IBMVFC_HOST_ACTION_TGT_DEL_FAILED) {
4780 if (vhost->reinit) {
4781 vhost->reinit = 0;
4782 scsi_block_requests(vhost->host);
4783 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY);
4784 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4786 ibmvfc_set_host_state(vhost, IBMVFC_ACTIVE);
4787 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_NONE);
4788 wake_up(&vhost->init_wait_q);
4789 schedule_work(&vhost->rport_add_work_q);
4790 vhost->init_retries = 0;
4791 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4792 scsi_unblock_requests(vhost->host);
4797 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT);
4798 vhost->job_step = ibmvfc_discover_targets;
4801 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_NONE);
4802 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4803 scsi_unblock_requests(vhost->host);
4804 wake_up(&vhost->init_wait_q);
4809 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_INIT);
4810 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4811 ibmvfc_alloc_targets(vhost);
4812 spin_lock_irqsave(vhost->host->host_lock, flags);
4815 list_for_each_entry(tgt, &vhost->targets, queue) {
4822 if (!ibmvfc_dev_init_to_do(vhost))
4823 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_DEL_FAILED);
4829 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4841 struct ibmvfc_host *vhost = data;
4847 rc = wait_event_interruptible(vhost->work_wait_q,
4848 ibmvfc_work_to_do(vhost));
4855 ibmvfc_do_work(vhost);
4858 ibmvfc_dbg(vhost, "ibmvfc kthread exiting...\n");
4864 * @vhost: ibmvfc host struct
4872 static int ibmvfc_init_crq(struct ibmvfc_host *vhost)
4875 struct device *dev = vhost->dev;
4877 struct ibmvfc_crq_queue *crq = &vhost->crq;
4897 retrc = rc = ibmvfc_reset_crq(vhost);
4908 tasklet_init(&vhost->tasklet, (void *)ibmvfc_tasklet, (unsigned long)vhost);
4910 if ((rc = request_irq(vdev->irq, ibmvfc_interrupt, 0, IBMVFC_NAME, vhost))) {
4925 tasklet_kill(&vhost->tasklet);
4937 * ibmvfc_free_mem - Free memory for vhost
4938 * @vhost: ibmvfc host struct
4943 static void ibmvfc_free_mem(struct ibmvfc_host *vhost)
4945 struct ibmvfc_async_crq_queue *async_q = &vhost->async_crq;
4948 mempool_destroy(vhost->tgt_pool);
4949 kfree(vhost->trace);
4950 dma_free_coherent(vhost->dev, vhost->disc_buf_sz, vhost->disc_buf,
4951 vhost->disc_buf_dma);
4952 dma_free_coherent(vhost->dev, sizeof(*vhost->login_buf),
4953 vhost->login_buf, vhost->login_buf_dma);
4954 dma_pool_destroy(vhost->sg_pool);
4955 dma_unmap_single(vhost->dev, async_q->msg_token,
4962 * ibmvfc_alloc_mem - Allocate memory for vhost
4963 * @vhost: ibmvfc host struct
4968 static int ibmvfc_alloc_mem(struct ibmvfc_host *vhost)
4970 struct ibmvfc_async_crq_queue *async_q = &vhost->async_crq;
4971 struct device *dev = vhost->dev;
4990 vhost->sg_pool = dma_pool_create(IBMVFC_NAME, dev,
4994 if (!vhost->sg_pool) {
4999 vhost->login_buf = dma_alloc_coherent(dev, sizeof(*vhost->login_buf),
5000 &vhost->login_buf_dma, GFP_KERNEL);
5002 if (!vhost->login_buf) {
5007 vhost->disc_buf_sz = sizeof(*vhost->disc_buf) * max_targets;
5008 vhost->disc_buf = dma_alloc_coherent(dev, vhost->disc_buf_sz,
5009 &vhost->disc_buf_dma, GFP_KERNEL);
5011 if (!vhost->disc_buf) {
5016 vhost->trace = kcalloc(IBMVFC_NUM_TRACE_ENTRIES,
5019 if (!vhost->trace)
5022 vhost->tgt_pool = mempool_create_kmalloc_pool(IBMVFC_TGT_MEMPOOL_SZ,
5025 if (!vhost->tgt_pool) {
5034 kfree(vhost->trace);
5036 dma_free_coherent(dev, vhost->disc_buf_sz, vhost->disc_buf,
5037 vhost->disc_buf_dma);
5039 dma_free_coherent(dev, sizeof(*vhost->login_buf),
5040 vhost->login_buf, vhost->login_buf_dma);
5042 dma_pool_destroy(vhost->sg_pool);
5060 struct ibmvfc_host *vhost = container_of(work, struct ibmvfc_host,
5068 spin_lock_irqsave(vhost->host->host_lock, flags);
5071 if (vhost->state != IBMVFC_ACTIVE)
5074 list_for_each_entry(tgt, &vhost->targets, queue) {
5081 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5084 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5089 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5093 spin_lock_irqsave(vhost->host->host_lock, flags);
5099 if (vhost->state == IBMVFC_ACTIVE)
5100 vhost->scan_complete = 1;
5101 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5115 struct ibmvfc_host *vhost;
5121 shost = scsi_host_alloc(&driver_template, sizeof(*vhost));
5135 vhost = shost_priv(shost);
5136 INIT_LIST_HEAD(&vhost->sent);
5137 INIT_LIST_HEAD(&vhost->free);
5138 INIT_LIST_HEAD(&vhost->targets);
5139 sprintf(vhost->name, IBMVFC_NAME);
5140 vhost->host = shost;
5141 vhost->dev = dev;
5142 vhost->partition_number = -1;
5143 vhost->log_level = log_level;
5144 vhost->task_set = 1;
5145 strcpy(vhost->partition_name, "UNKNOWN");
5146 init_waitqueue_head(&vhost->work_wait_q);
5147 init_waitqueue_head(&vhost->init_wait_q);
5148 INIT_WORK(&vhost->rport_add_work_q, ibmvfc_rport_add_thread);
5149 mutex_init(&vhost->passthru_mutex);
5151 if ((rc = ibmvfc_alloc_mem(vhost)))
5154 vhost->work_thread = kthread_run(ibmvfc_work, vhost, "%s_%d", IBMVFC_NAME,
5157 if (IS_ERR(vhost->work_thread)) {
5159 PTR_ERR(vhost->work_thread));
5160 rc = PTR_ERR(vhost->work_thread);
5164 if ((rc = ibmvfc_init_crq(vhost))) {
5169 if ((rc = ibmvfc_init_event_pool(vhost))) {
5187 dev_set_drvdata(dev, vhost);
5189 list_add_tail(&vhost->queue, &ibmvfc_head);
5192 ibmvfc_send_crq_init(vhost);
5199 ibmvfc_free_event_pool(vhost);
5201 ibmvfc_release_crq_queue(vhost);
5203 kthread_stop(vhost->work_thread);
5205 ibmvfc_free_mem(vhost);
5222 struct ibmvfc_host *vhost = dev_get_drvdata(&vdev->dev);
5226 ibmvfc_remove_trace_file(&vhost->host->shost_dev.kobj, &ibmvfc_trace_attr);
5228 spin_lock_irqsave(vhost->host->host_lock, flags);
5229 ibmvfc_link_down(vhost, IBMVFC_HOST_OFFLINE);
5230 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5232 ibmvfc_wait_while_resetting(vhost);
5233 ibmvfc_release_crq_queue(vhost);
5234 kthread_stop(vhost->work_thread);
5235 fc_remove_host(vhost->host);
5236 scsi_remove_host(vhost->host);
5238 spin_lock_irqsave(vhost->host->host_lock, flags);
5239 ibmvfc_purge_requests(vhost, DID_ERROR);
5240 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5241 ibmvfc_free_event_pool(vhost);
5243 ibmvfc_free_mem(vhost);
5245 list_del(&vhost->queue);
5247 scsi_host_put(vhost->host);
5263 struct ibmvfc_host *vhost = dev_get_drvdata(dev);
5266 spin_lock_irqsave(vhost->host->host_lock, flags);
5268 tasklet_schedule(&vhost->tasklet);
5269 spin_unlock_irqrestore(vhost->host->host_lock, flags);