Lines Matching defs:vhost
181 static int ibmvfc_check_caps(struct ibmvfc_host *vhost, unsigned long cap_flags)
183 u64 host_caps = be64_to_cpu(vhost->login_buf->resp.capabilities);
188 static struct ibmvfc_fcp_cmd_iu *ibmvfc_get_fcp_iu(struct ibmvfc_host *vhost,
191 if (ibmvfc_check_caps(vhost, IBMVFC_HANDLE_VF_WWPN))
197 static struct ibmvfc_fcp_rsp *ibmvfc_get_fcp_rsp(struct ibmvfc_host *vhost,
200 if (ibmvfc_check_caps(vhost, IBMVFC_HANDLE_VF_WWPN))
214 struct ibmvfc_host *vhost = evt->vhost;
217 struct ibmvfc_fcp_cmd_iu *iu = ibmvfc_get_fcp_iu(vhost, vfc_cmd);
219 int index = atomic_inc_return(&vhost->trace_index) & IBMVFC_TRACE_INDEX_MASK;
221 entry = &vhost->trace[index];
250 struct ibmvfc_host *vhost = evt->vhost;
253 struct ibmvfc_fcp_cmd_iu *iu = ibmvfc_get_fcp_iu(vhost, vfc_cmd);
254 struct ibmvfc_fcp_rsp *rsp = ibmvfc_get_fcp_rsp(vhost, vfc_cmd);
256 int index = atomic_inc_return(&vhost->trace_index) & IBMVFC_TRACE_INDEX_MASK;
258 entry = &vhost->trace[index];
329 * @vhost: ibmvfc host struct
335 static int ibmvfc_get_err_result(struct ibmvfc_host *vhost, struct ibmvfc_cmd *vfc_cmd)
338 struct ibmvfc_fcp_rsp *rsp = ibmvfc_get_fcp_rsp(vhost, vfc_cmd);
547 * @vhost: ibmvfc host struct
553 static int ibmvfc_set_host_state(struct ibmvfc_host *vhost,
558 switch (vhost->state) {
563 vhost->state = state;
572 * @vhost: ibmvfc host struct
576 static void ibmvfc_set_host_action(struct ibmvfc_host *vhost,
581 if (vhost->action == IBMVFC_HOST_ACTION_INIT_WAIT)
582 vhost->action = action;
585 if (vhost->action == IBMVFC_HOST_ACTION_LOGO)
586 vhost->action = action;
589 if (vhost->action == IBMVFC_HOST_ACTION_INIT)
590 vhost->action = action;
593 switch (vhost->action) {
597 vhost->action = action;
604 if (vhost->action == IBMVFC_HOST_ACTION_ALLOC_TGTS)
605 vhost->action = action;
609 vhost->action = action;
618 switch (vhost->action) {
623 vhost->action = action;
632 * @vhost: ibmvfc host struct
637 static void ibmvfc_reinit_host(struct ibmvfc_host *vhost)
639 if (vhost->action == IBMVFC_HOST_ACTION_NONE &&
640 vhost->state == IBMVFC_ACTIVE) {
641 if (!ibmvfc_set_host_state(vhost, IBMVFC_INITIALIZING)) {
642 scsi_block_requests(vhost->host);
643 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY);
646 vhost->reinit = 1;
648 wake_up(&vhost->work_wait_q);
661 wake_up(&tgt->vhost->work_wait_q);
666 * @vhost: ibmvfc host struct
670 static void ibmvfc_link_down(struct ibmvfc_host *vhost,
676 scsi_block_requests(vhost->host);
677 list_for_each_entry(tgt, &vhost->targets, queue)
679 ibmvfc_set_host_state(vhost, state);
680 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_DEL);
681 vhost->events_to_log |= IBMVFC_AE_LINKDOWN;
682 wake_up(&vhost->work_wait_q);
688 * @vhost: ibmvfc host struct
693 static void ibmvfc_init_host(struct ibmvfc_host *vhost)
697 if (vhost->action == IBMVFC_HOST_ACTION_INIT_WAIT) {
698 if (++vhost->init_retries > IBMVFC_MAX_HOST_INIT_RETRIES) {
699 dev_err(vhost->dev,
701 ibmvfc_link_down(vhost, IBMVFC_HOST_OFFLINE);
706 if (!ibmvfc_set_host_state(vhost, IBMVFC_INITIALIZING)) {
707 memset(vhost->async_crq.msgs.async, 0, PAGE_SIZE);
708 vhost->async_crq.cur = 0;
710 list_for_each_entry(tgt, &vhost->targets, queue) {
711 if (vhost->client_migrated)
717 scsi_block_requests(vhost->host);
718 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT);
719 vhost->job_step = ibmvfc_npiv_login;
720 wake_up(&vhost->work_wait_q);
726 * @vhost: ibmvfc host struct
733 static int ibmvfc_send_crq(struct ibmvfc_host *vhost, u64 word1, u64 word2)
735 struct vio_dev *vdev = to_vio_dev(vhost->dev);
739 static int ibmvfc_send_sub_crq(struct ibmvfc_host *vhost, u64 cookie, u64 word1,
742 struct vio_dev *vdev = to_vio_dev(vhost->dev);
750 * @vhost: ibmvfc host struct
755 static int ibmvfc_send_crq_init(struct ibmvfc_host *vhost)
757 ibmvfc_dbg(vhost, "Sending CRQ init\n");
758 return ibmvfc_send_crq(vhost, 0xC001000000000000LL, 0);
763 * @vhost: ibmvfc host struct
768 static int ibmvfc_send_crq_init_complete(struct ibmvfc_host *vhost)
770 ibmvfc_dbg(vhost, "Sending CRQ init complete\n");
771 return ibmvfc_send_crq(vhost, 0xC002000000000000LL, 0);
776 * @vhost: ibmvfc host who owns the event pool
782 static int ibmvfc_init_event_pool(struct ibmvfc_host *vhost,
798 pool->iu_storage = dma_alloc_coherent(vhost->dev,
825 evt->vhost = vhost;
837 * @vhost: ibmvfc host who owns the event pool
841 static void ibmvfc_free_event_pool(struct ibmvfc_host *vhost,
852 dma_pool_free(vhost->sg_pool,
858 dma_free_coherent(vhost->dev,
866 * @vhost: ibmvfc host struct
871 static void ibmvfc_free_queue(struct ibmvfc_host *vhost,
874 struct device *dev = vhost->dev;
880 ibmvfc_free_event_pool(vhost, queue);
885 * @vhost: ibmvfc host struct
890 static void ibmvfc_release_crq_queue(struct ibmvfc_host *vhost)
893 struct vio_dev *vdev = to_vio_dev(vhost->dev);
894 struct ibmvfc_queue *crq = &vhost->crq;
896 ibmvfc_dbg(vhost, "Releasing CRQ\n");
897 free_irq(vdev->irq, vhost);
898 tasklet_kill(&vhost->tasklet);
905 vhost->state = IBMVFC_NO_CRQ;
906 vhost->logged_in = 0;
908 ibmvfc_free_queue(vhost, crq);
913 * @vhost: ibmvfc host struct
918 static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost)
921 struct vio_dev *vdev = to_vio_dev(vhost->dev);
924 ibmvfc_dereg_sub_crqs(vhost);
934 dev_err(vhost->dev, "Error enabling adapter (rc=%d)\n", rc);
936 spin_lock_irqsave(vhost->host->host_lock, flags);
937 spin_lock(vhost->crq.q_lock);
938 vhost->do_enquiry = 1;
939 vhost->using_channels = 0;
940 spin_unlock(vhost->crq.q_lock);
941 spin_unlock_irqrestore(vhost->host->host_lock, flags);
943 ibmvfc_reg_sub_crqs(vhost);
950 * @vhost: ibmvfc host struct
955 static int ibmvfc_reset_crq(struct ibmvfc_host *vhost)
959 struct vio_dev *vdev = to_vio_dev(vhost->dev);
960 struct ibmvfc_queue *crq = &vhost->crq;
962 ibmvfc_dereg_sub_crqs(vhost);
971 spin_lock_irqsave(vhost->host->host_lock, flags);
972 spin_lock(vhost->crq.q_lock);
973 vhost->state = IBMVFC_NO_CRQ;
974 vhost->logged_in = 0;
975 vhost->do_enquiry = 1;
976 vhost->using_channels = 0;
988 dev_warn(vhost->dev, "Partner adapter not ready\n");
990 dev_warn(vhost->dev, "Couldn't register crq (rc=%d)\n", rc);
992 spin_unlock(vhost->crq.q_lock);
993 spin_unlock_irqrestore(vhost->host->host_lock, flags);
995 ibmvfc_reg_sub_crqs(vhost);
1104 * @vhost: ibmvfc host struct
1110 static void ibmvfc_purge_requests(struct ibmvfc_host *vhost, int error_code)
1113 struct ibmvfc_queue *queues = vhost->scsi_scrqs.scrqs;
1118 if (vhost->using_channels)
1119 hwqs = vhost->scsi_scrqs.active_queues;
1121 ibmvfc_dbg(vhost, "Purging all requests\n");
1122 spin_lock_irqsave(&vhost->crq.l_lock, flags);
1123 list_for_each_entry_safe(evt, pos, &vhost->crq.sent, queue_list)
1125 list_splice_init(&vhost->crq.sent, &vhost->purge);
1126 spin_unlock_irqrestore(&vhost->crq.l_lock, flags);
1133 list_splice_init(&queues[i].sent, &vhost->purge);
1141 * @vhost: struct ibmvfc host to reset
1143 static void ibmvfc_hard_reset_host(struct ibmvfc_host *vhost)
1145 ibmvfc_purge_requests(vhost, DID_ERROR);
1146 ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN);
1147 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_RESET);
1152 * @vhost: struct ibmvfc host to reset
1154 static void __ibmvfc_reset_host(struct ibmvfc_host *vhost)
1156 if (vhost->logged_in && vhost->action != IBMVFC_HOST_ACTION_LOGO_WAIT &&
1157 !ibmvfc_set_host_state(vhost, IBMVFC_INITIALIZING)) {
1158 scsi_block_requests(vhost->host);
1159 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_LOGO);
1160 vhost->job_step = ibmvfc_npiv_logout;
1161 wake_up(&vhost->work_wait_q);
1163 ibmvfc_hard_reset_host(vhost);
1168 * @vhost: ibmvfc host struct
1170 static void ibmvfc_reset_host(struct ibmvfc_host *vhost)
1174 spin_lock_irqsave(vhost->host->host_lock, flags);
1175 __ibmvfc_reset_host(vhost);
1176 spin_unlock_irqrestore(vhost->host->host_lock, flags);
1181 * @vhost: ibmvfc host struct
1186 static int ibmvfc_retry_host_init(struct ibmvfc_host *vhost)
1190 if (vhost->action == IBMVFC_HOST_ACTION_INIT_WAIT) {
1191 vhost->delay_init = 1;
1192 if (++vhost->init_retries > IBMVFC_MAX_HOST_INIT_RETRIES) {
1193 dev_err(vhost->dev,
1195 ibmvfc_link_down(vhost, IBMVFC_HOST_OFFLINE);
1196 } else if (vhost->init_retries == IBMVFC_MAX_HOST_INIT_RETRIES)
1197 __ibmvfc_reset_host(vhost);
1199 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT);
1204 wake_up(&vhost->work_wait_q);
1218 struct ibmvfc_host *vhost = shost_priv(shost);
1221 list_for_each_entry(tgt, &vhost->targets, queue)
1257 struct ibmvfc_host *vhost = shost_priv(shost);
1261 if (vhost->state == IBMVFC_ACTIVE) {
1262 switch (be64_to_cpu(vhost->login_buf->resp.link_speed) / 100) {
1282 ibmvfc_log(vhost, 3, "Unknown port speed: %lld Gbit\n",
1283 be64_to_cpu(vhost->login_buf->resp.link_speed) / 100);
1301 struct ibmvfc_host *vhost = shost_priv(shost);
1305 switch (vhost->state) {
1324 ibmvfc_log(vhost, 3, "Unknown port state: %d\n", vhost->state);
1405 * @vhost: ibmvfc host struct
1410 static int ibmvfc_wait_while_resetting(struct ibmvfc_host *vhost)
1412 long timeout = wait_event_timeout(vhost->init_wait_q,
1413 ((vhost->state == IBMVFC_ACTIVE ||
1414 vhost->state == IBMVFC_HOST_OFFLINE ||
1415 vhost->state == IBMVFC_LINK_DEAD) &&
1416 vhost->action == IBMVFC_HOST_ACTION_NONE),
1431 struct ibmvfc_host *vhost = shost_priv(shost);
1433 dev_err(vhost->dev, "Initiating host LIP. Resetting connection\n");
1434 ibmvfc_reset_host(vhost);
1435 return ibmvfc_wait_while_resetting(vhost);
1440 * @vhost: ibmvfc host struct
1445 static void ibmvfc_gather_partition_info(struct ibmvfc_host *vhost)
1457 strncpy(vhost->partition_name, name, sizeof(vhost->partition_name));
1460 vhost->partition_number = *num;
1466 * @vhost: ibmvfc host struct
1471 static void ibmvfc_set_login_info(struct ibmvfc_host *vhost)
1473 struct ibmvfc_npiv_login *login_info = &vhost->login_info;
1474 struct ibmvfc_queue *async_crq = &vhost->async_crq;
1475 struct device_node *of_node = vhost->dev->of_node;
1484 login_info->partition_num = cpu_to_be32(vhost->partition_number);
1488 if (vhost->client_migrated)
1494 if (vhost->mq_enabled || vhost->using_channels)
1497 login_info->async.va = cpu_to_be64(vhost->async_crq.msg_token);
1500 strncpy(login_info->partition_name, vhost->partition_name, IBMVFC_MAX_NAME);
1502 dev_name(&vhost->host->shost_gendev), IBMVFC_MAX_NAME);
1505 location = location ? location : dev_name(vhost->dev);
1522 ibmvfc_log(queue->vhost, 4, "empty event pool on queue:%ld\n", queue->hwq_id);
1545 spin_lock_irqsave(evt->vhost->host->host_lock, flags);
1547 spin_unlock_irqrestore(evt->vhost->host->host_lock, flags);
1609 struct ibmvfc_host *vhost = dev_get_drvdata(dev);
1610 struct ibmvfc_fcp_cmd_iu *iu = ibmvfc_get_fcp_iu(evt->vhost, vfc_cmd);
1620 if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
1641 evt->ext_list = dma_pool_alloc(vhost->sg_pool, GFP_ATOMIC,
1646 if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
1669 struct ibmvfc_host *vhost = evt->vhost;
1670 dev_err(vhost->dev, "Command timed out (%p). Resetting connection\n", evt);
1671 ibmvfc_reset_host(vhost);
1677 * @vhost: ibmvfc host struct
1683 struct ibmvfc_host *vhost, unsigned long timeout)
1712 rc = ibmvfc_send_sub_crq(vhost,
1718 rc = ibmvfc_send_crq(vhost, be64_to_cpu(crq_as_u64[0]),
1734 dev_warn(vhost->dev, "Send warning. Receive queue closed, will retry.\n");
1741 dev_err(vhost->dev, "Send error (rc=%d)\n", rc);
1765 struct ibmvfc_host *vhost = evt->vhost;
1766 struct ibmvfc_fcp_rsp *rsp = ibmvfc_get_fcp_rsp(vhost, vfc_cmd);
1778 if (!logerr && (vhost->log_level <= (IBMVFC_DEFAULT_LOG_LEVEL + 1)))
1797 struct ibmvfc_host *vhost = shost_priv(sdev->host);
1802 spin_lock_irqsave(vhost->host->host_lock, flags);
1803 list_for_each_entry(tgt, &vhost->targets, queue) {
1810 ibmvfc_reinit_host(vhost);
1811 spin_unlock_irqrestore(vhost->host->host_lock, flags);
1823 struct ibmvfc_fcp_rsp *rsp = ibmvfc_get_fcp_rsp(evt->vhost, vfc_cmd);
1837 cmnd->result = ibmvfc_get_err_result(evt->vhost, vfc_cmd);
1868 * @vhost: struct ibmvfc host
1873 static inline int ibmvfc_host_chkready(struct ibmvfc_host *vhost)
1877 switch (vhost->state) {
1899 struct ibmvfc_host *vhost = evt->vhost;
1901 struct ibmvfc_fcp_cmd_iu *iu = ibmvfc_get_fcp_iu(vhost, vfc_cmd);
1902 struct ibmvfc_fcp_rsp *rsp = ibmvfc_get_fcp_rsp(vhost, vfc_cmd);
1906 if (ibmvfc_check_caps(vhost, IBMVFC_HANDLE_VF_WWPN)) {
1933 struct ibmvfc_host *vhost = shost_priv(shost);
1944 unlikely((rc = ibmvfc_host_chkready(vhost)))) {
1951 if (vhost->using_channels) {
1952 scsi_channel = hwq % vhost->scsi_scrqs.active_queues;
1953 evt = ibmvfc_get_event(&vhost->scsi_scrqs.scrqs[scsi_channel]);
1957 evt->hwq = hwq % vhost->scsi_scrqs.active_queues;
1959 evt = ibmvfc_get_event(&vhost->crq);
1968 iu = ibmvfc_get_fcp_iu(vhost, vfc_cmd);
1980 if (likely(!(rc = ibmvfc_map_sg_data(cmnd, evt, vfc_cmd, vhost->dev))))
1981 return ibmvfc_send_event(evt, vhost, 0);
1987 if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
2017 struct ibmvfc_host *vhost = evt->vhost;
2020 vhost->aborting_passthru = 0;
2021 dev_info(vhost->dev, "Passthru command cancelled\n");
2033 struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
2041 spin_lock_irqsave(vhost->host->host_lock, flags);
2042 if (vhost->aborting_passthru || vhost->state != IBMVFC_ACTIVE) {
2043 __ibmvfc_reset_host(vhost);
2044 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2048 vhost->aborting_passthru = 1;
2049 evt = ibmvfc_get_event(&vhost->crq);
2051 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2065 rc = ibmvfc_send_event(evt, vhost, default_timeout);
2068 vhost->aborting_passthru = 0;
2069 dev_err(vhost->dev, "Failed to send cancel event. rc=%d\n", rc);
2072 dev_info(vhost->dev, "Cancelling passthru command to port id 0x%lx\n",
2075 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2083 * @vhost: struct ibmvfc_host to send command
2089 static int ibmvfc_bsg_plogi(struct ibmvfc_host *vhost, unsigned int port_id)
2099 spin_lock_irqsave(vhost->host->host_lock, flags);
2100 list_for_each_entry(tgt, &vhost->targets, queue) {
2109 if (unlikely((rc = ibmvfc_host_chkready(vhost))))
2112 evt = ibmvfc_get_event(&vhost->crq);
2127 rc = ibmvfc_send_event(evt, vhost, default_timeout);
2128 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2138 spin_lock_irqsave(vhost->host->host_lock, flags);
2141 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2155 struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
2196 if (!mutex_trylock(&vhost->passthru_mutex))
2200 req_seg = dma_map_sg(vhost->dev, job->request_payload.sg_list,
2204 mutex_unlock(&vhost->passthru_mutex);
2208 rsp_seg = dma_map_sg(vhost->dev, job->reply_payload.sg_list,
2212 dma_unmap_sg(vhost->dev, job->request_payload.sg_list,
2214 mutex_unlock(&vhost->passthru_mutex);
2224 rc = ibmvfc_bsg_plogi(vhost, port_id);
2226 spin_lock_irqsave(vhost->host->host_lock, flags);
2229 unlikely((rc = ibmvfc_host_chkready(vhost)))) {
2230 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2234 evt = ibmvfc_get_event(&vhost->crq);
2236 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2267 rc = ibmvfc_send_event(evt, vhost, 0);
2268 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2282 spin_lock_irqsave(vhost->host->host_lock, flags);
2284 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2290 dma_unmap_sg(vhost->dev, job->request_payload.sg_list,
2292 dma_unmap_sg(vhost->dev, job->reply_payload.sg_list,
2294 mutex_unlock(&vhost->passthru_mutex);
2310 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2316 struct ibmvfc_fcp_rsp *fc_rsp = ibmvfc_get_fcp_rsp(vhost, &rsp_iu.cmd);
2321 spin_lock_irqsave(vhost->host->host_lock, flags);
2322 if (vhost->state == IBMVFC_ACTIVE) {
2323 if (vhost->using_channels)
2324 evt = ibmvfc_get_event(&vhost->scsi_scrqs.scrqs[0]);
2326 evt = ibmvfc_get_event(&vhost->crq);
2329 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2335 iu = ibmvfc_get_fcp_iu(vhost, tmf);
2338 if (ibmvfc_check_caps(vhost, IBMVFC_HANDLE_VF_WWPN))
2344 rsp_rc = ibmvfc_send_event(evt, vhost, default_timeout);
2346 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2358 rsp_code = ibmvfc_get_err_result(vhost, &rsp_iu.cmd);
2373 spin_lock_irqsave(vhost->host->host_lock, flags);
2375 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2449 * @vhost: ibmvfc host struct
2456 static int ibmvfc_wait_for_ops(struct ibmvfc_host *vhost, void *device,
2467 if (vhost->mq_enabled && vhost->using_channels) {
2468 queues = vhost->scsi_scrqs.scrqs;
2469 q_size = vhost->scsi_scrqs.active_queues;
2471 queues = &vhost->crq;
2477 spin_lock_irqsave(vhost->host->host_lock, flags);
2491 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2498 spin_lock_irqsave(vhost->host->host_lock, flags);
2512 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2514 dev_err(vhost->dev, "Timed out waiting for aborted commands\n");
2529 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2542 if (ibmvfc_check_caps(vhost, IBMVFC_HANDLE_VF_WWPN)) {
2552 if (!ibmvfc_check_caps(vhost, IBMVFC_CAN_SUPPRESS_ABTS))
2554 if (vhost->state == IBMVFC_ACTIVE)
2568 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2570 struct ibmvfc_queue *queues = vhost->scsi_scrqs.scrqs;
2578 spin_lock_irqsave(vhost->host->host_lock, flags);
2579 num_hwq = vhost->scsi_scrqs.active_queues;
2592 if (found_evt && vhost->logged_in) {
2596 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2600 ibmvfc_send_event(evt, vhost, default_timeout);
2606 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2609 if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
2648 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2657 spin_lock_irqsave(vhost->host->host_lock, flags);
2658 spin_lock(&vhost->crq.l_lock);
2659 list_for_each_entry(evt, &vhost->crq.sent, queue_list) {
2665 spin_unlock(&vhost->crq.l_lock);
2668 if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
2670 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2674 if (vhost->logged_in) {
2675 evt = ibmvfc_init_tmf(&vhost->crq, sdev, type);
2677 rsp_rc = ibmvfc_send_event(evt, vhost, default_timeout);
2680 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2694 spin_lock_irqsave(vhost->host->host_lock, flags);
2696 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2728 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2730 if (vhost->mq_enabled && vhost->using_channels)
2781 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2787 struct ibmvfc_fcp_rsp *fc_rsp = ibmvfc_get_fcp_rsp(vhost, &rsp_iu.cmd);
2793 spin_lock_irqsave(vhost->host->host_lock, flags);
2794 spin_lock(&vhost->crq.l_lock);
2795 list_for_each_entry(evt, &vhost->crq.sent, queue_list) {
2801 spin_unlock(&vhost->crq.l_lock);
2804 if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
2806 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2810 if (vhost->state == IBMVFC_ACTIVE) {
2811 evt = ibmvfc_get_event(&vhost->crq);
2813 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2818 iu = ibmvfc_get_fcp_iu(vhost, tmf);
2820 if (ibmvfc_check_caps(vhost, IBMVFC_HANDLE_VF_WWPN))
2829 rsp_rc = ibmvfc_send_event(evt, vhost, default_timeout);
2832 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2845 rc = ibmvfc_wait_for_ops(vhost, sdev->hostdata, ibmvfc_match_key);
2852 ibmvfc_reset_host(vhost);
2854 rc = ibmvfc_wait_for_ops(vhost, sdev->hostdata, ibmvfc_match_key);
2859 rc = ibmvfc_wait_for_ops(vhost, evt, ibmvfc_match_evt);
2861 spin_lock_irqsave(vhost->host->host_lock, flags);
2862 ibmvfc_hard_reset_host(vhost);
2863 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2872 rsp_code = ibmvfc_get_err_result(vhost, &rsp_iu.cmd);
2888 spin_lock_irqsave(vhost->host->host_lock, flags);
2890 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2904 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2910 ibmvfc_wait_while_resetting(vhost);
2918 rc = ibmvfc_wait_for_ops(vhost, sdev, ibmvfc_match_lun);
2937 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2943 ibmvfc_wait_while_resetting(vhost);
2951 rc = ibmvfc_wait_for_ops(vhost, sdev, ibmvfc_match_lun);
2994 struct ibmvfc_host *vhost = shost_priv(sdev->host);
3003 ibmvfc_wait_while_resetting(vhost);
3011 rc = ibmvfc_wait_for_ops(vhost, starget, ibmvfc_match_target);
3028 struct ibmvfc_host *vhost = shost_priv(cmd->device->host);
3030 dev_err(vhost->dev, "Resetting connection due to error recovery\n");
3031 rc = ibmvfc_issue_fc_host_lip(vhost->host);
3046 struct ibmvfc_host *vhost = shost_priv(shost);
3061 rc = ibmvfc_wait_for_ops(vhost, rport, ibmvfc_match_rport);
3068 list_for_each_entry(tgt, &vhost->targets, queue) {
3082 ibmvfc_reinit_host(vhost);
3154 * @vhost: ibmvfc host struct
3158 struct ibmvfc_host *vhost)
3163 ibmvfc_log(vhost, desc->log_level, "%s event received. scsi_id: %llx, wwpn: %llx,"
3172 ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN);
3175 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
3180 vhost->events_to_log |= IBMVFC_AE_LINKUP;
3181 vhost->delay_init = 1;
3182 __ibmvfc_reset_host(vhost);
3188 vhost->events_to_log |= IBMVFC_AE_LINKUP;
3189 vhost->delay_init = 1;
3190 __ibmvfc_reset_host(vhost);
3194 vhost->events_to_log |= IBMVFC_AE_RSCN;
3195 if (vhost->state < IBMVFC_HALTED) {
3196 vhost->delay_init = 1;
3197 __ibmvfc_reset_host(vhost);
3202 vhost->events_to_log |= IBMVFC_AE_RSCN;
3203 ibmvfc_reinit_host(vhost);
3208 list_for_each_entry(tgt, &vhost->targets, queue) {
3221 ibmvfc_reinit_host(vhost);
3227 ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN);
3230 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
3233 ibmvfc_link_down(vhost, IBMVFC_HALTED);
3236 dev_err(vhost->dev, "Unknown async event received: %lld\n", crq->event);
3244 * @vhost: ibmvfc host struct
3248 static void ibmvfc_handle_crq(struct ibmvfc_crq *crq, struct ibmvfc_host *vhost,
3258 dev_info(vhost->dev, "Partner initialized\n");
3260 rc = ibmvfc_send_crq_init_complete(vhost);
3262 ibmvfc_init_host(vhost);
3264 dev_err(vhost->dev, "Unable to send init rsp. rc=%ld\n", rc);
3267 dev_info(vhost->dev, "Partner initialization complete\n");
3268 ibmvfc_init_host(vhost);
3271 dev_err(vhost->dev, "Unknown crq message type: %d\n", crq->format);
3275 vhost->state = IBMVFC_NO_CRQ;
3276 vhost->logged_in = 0;
3277 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_NONE);
3280 dev_info(vhost->dev, "Partition migrated, Re-enabling adapter\n");
3281 vhost->client_migrated = 1;
3283 scsi_block_requests(vhost->host);
3284 ibmvfc_purge_requests(vhost, DID_REQUEUE);
3285 ibmvfc_set_host_state(vhost, IBMVFC_LINK_DOWN);
3286 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_REENABLE);
3287 wake_up(&vhost->work_wait_q);
3289 dev_err(vhost->dev, "Host partner adapter deregistered or failed (rc=%d)\n", crq->format);
3290 ibmvfc_purge_requests(vhost, DID_ERROR);
3291 ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN);
3292 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_RESET);
3294 dev_err(vhost->dev, "Received unknown transport event from partner (rc=%d)\n", crq->format);
3300 dev_err(vhost->dev, "Got an invalid message type 0x%02x\n", crq->valid);
3311 if (unlikely(!ibmvfc_valid_event(&vhost->crq.evt_pool, evt))) {
3312 dev_err(vhost->dev, "Returned correlation_token 0x%08llx is invalid!\n",
3318 dev_err(vhost->dev, "Received duplicate correlation_token 0x%08llx!\n",
3339 struct ibmvfc_host *vhost = shost_priv(shost);
3343 if (!vhost->scan_timeout)
3345 else if (time >= (vhost->scan_timeout * HZ)) {
3346 dev_info(vhost->dev, "Scan taking longer than %d seconds, "
3347 "continuing initialization\n", vhost->scan_timeout);
3351 if (vhost->scan_complete) {
3352 vhost->scan_timeout = init_timeout;
3373 struct ibmvfc_host *vhost = shost_priv(shost);
3380 sdev->hostdata = (void *)(unsigned long)vhost->task_set++;
3398 struct ibmvfc_host *vhost = shost_priv(shost);
3402 starget->hostdata = (void *)(unsigned long)vhost->task_set++;
3451 struct ibmvfc_host *vhost = shost_priv(shost);
3454 vhost->login_buf->resp.partition_name);
3461 struct ibmvfc_host *vhost = shost_priv(shost);
3464 vhost->login_buf->resp.device_name);
3471 struct ibmvfc_host *vhost = shost_priv(shost);
3474 vhost->login_buf->resp.port_loc_code);
3481 struct ibmvfc_host *vhost = shost_priv(shost);
3484 vhost->login_buf->resp.drc_name);
3491 struct ibmvfc_host *vhost = shost_priv(shost);
3492 return snprintf(buf, PAGE_SIZE, "%d\n", be32_to_cpu(vhost->login_buf->resp.version));
3499 struct ibmvfc_host *vhost = shost_priv(shost);
3500 return snprintf(buf, PAGE_SIZE, "%llx\n", be64_to_cpu(vhost->login_buf->resp.capabilities));
3516 struct ibmvfc_host *vhost = shost_priv(shost);
3521 len = snprintf(buf, PAGE_SIZE, "%d\n", vhost->log_level);
3541 struct ibmvfc_host *vhost = shost_priv(shost);
3545 vhost->log_level = simple_strtoul(buf, NULL, 10);
3554 struct ibmvfc_host *vhost = shost_priv(shost);
3559 len = snprintf(buf, PAGE_SIZE, "%d\n", vhost->client_scsi_channels);
3569 struct ibmvfc_host *vhost = shost_priv(shost);
3575 vhost->client_scsi_channels = min(channels, nr_scsi_hw_queues);
3576 ibmvfc_hard_reset_host(vhost);
3611 struct ibmvfc_host *vhost = shost_priv(shost);
3614 char *src = (char *)vhost->trace;
3680 * @vhost: ibmvfc host struct
3685 static struct ibmvfc_async_crq *ibmvfc_next_async_crq(struct ibmvfc_host *vhost)
3687 struct ibmvfc_queue *async_crq = &vhost->async_crq;
3703 * @vhost: ibmvfc host struct
3708 static struct ibmvfc_crq *ibmvfc_next_crq(struct ibmvfc_host *vhost)
3710 struct ibmvfc_queue *queue = &vhost->crq;
3734 struct ibmvfc_host *vhost = (struct ibmvfc_host *)dev_instance;
3737 spin_lock_irqsave(vhost->host->host_lock, flags);
3738 vio_disable_interrupts(to_vio_dev(vhost->dev));
3739 tasklet_schedule(&vhost->tasklet);
3740 spin_unlock_irqrestore(vhost->host->host_lock, flags);
3753 struct ibmvfc_host *vhost = data;
3754 struct vio_dev *vdev = to_vio_dev(vhost->dev);
3762 spin_lock_irqsave(vhost->host->host_lock, flags);
3763 spin_lock(vhost->crq.q_lock);
3766 while ((async = ibmvfc_next_async_crq(vhost)) != NULL) {
3767 ibmvfc_handle_async(async, vhost);
3773 while ((crq = ibmvfc_next_crq(vhost)) != NULL) {
3774 ibmvfc_handle_crq(crq, vhost, &evt_doneq);
3780 if ((async = ibmvfc_next_async_crq(vhost)) != NULL) {
3782 ibmvfc_handle_async(async, vhost);
3785 } else if ((crq = ibmvfc_next_crq(vhost)) != NULL) {
3787 ibmvfc_handle_crq(crq, vhost, &evt_doneq);
3794 spin_unlock(vhost->crq.q_lock);
3795 spin_unlock_irqrestore(vhost->host->host_lock, flags);
3807 struct device *dev = scrq->vhost->dev;
3825 static void ibmvfc_handle_scrq(struct ibmvfc_crq *crq, struct ibmvfc_host *vhost,
3836 dev_err(vhost->dev, "Got and invalid message type 0x%02x\n", crq->valid);
3845 dev_err(vhost->dev, "Returned correlation_token 0x%08llx is invalid!\n",
3851 dev_err(vhost->dev, "Received duplicate correlation_token 0x%08llx!\n",
3887 ibmvfc_handle_scrq(crq, scrq->vhost, &evt_doneq);
3895 ibmvfc_handle_scrq(crq, scrq->vhost, &evt_doneq);
3932 wake_up(&tgt->vhost->work_wait_q);
3948 wake_up(&tgt->vhost->work_wait_q);
3997 struct ibmvfc_host *vhost = evt->vhost;
4003 vhost->discovery_threads--;
4055 wake_up(&vhost->work_wait_q);
4066 struct ibmvfc_host *vhost = tgt->vhost;
4069 if (vhost->discovery_threads >= disc_threads)
4073 evt = ibmvfc_get_event(&vhost->crq);
4077 __ibmvfc_reset_host(vhost);
4080 vhost->discovery_threads++;
4085 if (ibmvfc_check_caps(vhost, IBMVFC_HANDLE_VF_WWPN)) {
4104 if (ibmvfc_send_event(evt, vhost, default_timeout)) {
4105 vhost->discovery_threads--;
4120 struct ibmvfc_host *vhost = evt->vhost;
4125 vhost->discovery_threads--;
4132 vhost->reinit = 1;
4167 wake_up(&vhost->work_wait_q);
4178 struct ibmvfc_host *vhost = tgt->vhost;
4181 if (vhost->discovery_threads >= disc_threads)
4186 evt = ibmvfc_get_event(&vhost->crq);
4190 __ibmvfc_reset_host(vhost);
4193 vhost->discovery_threads++;
4199 if (ibmvfc_check_caps(vhost, IBMVFC_HANDLE_VF_WWPN)) {
4209 if (ibmvfc_send_event(evt, vhost, default_timeout)) {
4210 vhost->discovery_threads--;
4225 struct ibmvfc_host *vhost = evt->vhost;
4229 vhost->discovery_threads--;
4239 wake_up(&vhost->work_wait_q);
4249 wake_up(&vhost->work_wait_q);
4264 struct ibmvfc_host *vhost = tgt->vhost;
4268 evt = ibmvfc_get_event(&vhost->crq);
4289 struct ibmvfc_host *vhost = tgt->vhost;
4292 if (vhost->discovery_threads >= disc_threads)
4295 vhost->discovery_threads++;
4299 vhost->discovery_threads--;
4302 __ibmvfc_reset_host(vhost);
4307 if (ibmvfc_send_event(evt, vhost, default_timeout)) {
4308 vhost->discovery_threads--;
4323 struct ibmvfc_host *vhost = evt->vhost;
4327 vhost->discovery_threads--;
4337 if (status == IBMVFC_MAD_SUCCESS || vhost->state == IBMVFC_HOST_OFFLINE)
4344 wake_up(&vhost->work_wait_q);
4354 struct ibmvfc_host *vhost = tgt->vhost;
4357 if (!vhost->logged_in) {
4362 if (vhost->discovery_threads >= disc_threads)
4365 vhost->discovery_threads++;
4370 if (ibmvfc_send_event(evt, vhost, default_timeout)) {
4371 vhost->discovery_threads--;
4386 struct ibmvfc_host *vhost = evt->vhost;
4391 vhost->discovery_threads--;
4424 wake_up(&vhost->work_wait_q);
4435 struct ibmvfc_host *vhost = tgt->vhost;
4439 if (vhost->discovery_threads >= disc_threads)
4443 evt = ibmvfc_get_event(&vhost->crq);
4447 __ibmvfc_reset_host(vhost);
4450 vhost->discovery_threads++;
4465 if (ibmvfc_send_event(evt, vhost, default_timeout)) {
4466 vhost->discovery_threads--;
4501 struct ibmvfc_host *vhost = evt->vhost;
4506 vhost->discovery_threads--;
4533 wake_up(&vhost->work_wait_q);
4576 struct ibmvfc_host *vhost = evt->vhost;
4580 vhost->abort_threads--;
4583 wake_up(&vhost->work_wait_q);
4597 struct ibmvfc_host *vhost = tgt->vhost;
4604 spin_lock_irqsave(vhost->host->host_lock, flags);
4605 if (vhost->abort_threads >= disc_threads ||
4607 vhost->state != IBMVFC_INITIALIZING ||
4608 vhost->action != IBMVFC_HOST_ACTION_QUERY_TGTS) {
4609 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4613 vhost->abort_threads++;
4615 evt = ibmvfc_get_event(&vhost->crq);
4618 vhost->abort_threads--;
4620 __ibmvfc_reset_host(vhost);
4621 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4629 if (ibmvfc_check_caps(vhost, IBMVFC_HANDLE_VF_WWPN)) {
4640 rc = ibmvfc_send_event(evt, vhost, default_timeout);
4644 vhost->abort_threads--;
4646 __ibmvfc_reset_host(vhost);
4649 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4666 struct ibmvfc_host *vhost = tgt->vhost;
4669 if (vhost->discovery_threads >= disc_threads)
4673 evt = ibmvfc_get_event(&vhost->crq);
4677 __ibmvfc_reset_host(vhost);
4680 vhost->discovery_threads++;
4691 memcpy(&mad->fc_iu.payload[2], &vhost->login_buf->resp.port_name,
4692 sizeof(vhost->login_buf->resp.port_name));
4693 memcpy(&mad->fc_iu.payload[4], &vhost->login_buf->resp.node_name,
4694 sizeof(vhost->login_buf->resp.node_name));
4695 mad->fc_iu.payload[6] = cpu_to_be32(be64_to_cpu(vhost->login_buf->resp.scsi_id) & 0x00ffffff);
4705 if (ibmvfc_send_event(evt, vhost, IBMVFC_ADISC_PLUS_CANCEL_TIMEOUT)) {
4706 vhost->discovery_threads--;
4722 struct ibmvfc_host *vhost = evt->vhost;
4727 vhost->discovery_threads--;
4764 wake_up(&vhost->work_wait_q);
4775 struct ibmvfc_host *vhost = tgt->vhost;
4778 if (vhost->discovery_threads >= disc_threads)
4782 evt = ibmvfc_get_event(&vhost->crq);
4786 __ibmvfc_reset_host(vhost);
4789 vhost->discovery_threads++;
4800 if (ibmvfc_send_event(evt, vhost, default_timeout)) {
4801 vhost->discovery_threads--;
4810 * @vhost: ibmvfc host struct
4816 static int ibmvfc_alloc_target(struct ibmvfc_host *vhost,
4827 spin_lock_irqsave(vhost->host->host_lock, flags);
4828 list_for_each_entry(tgt, &vhost->targets, queue) {
4835 list_for_each_entry(tgt, &vhost->targets, queue) {
4879 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4881 tgt = mempool_alloc(vhost->tgt_pool, GFP_NOIO);
4885 tgt->vhost = vhost;
4890 spin_lock_irqsave(vhost->host->host_lock, flags);
4891 tgt->cancel_key = vhost->task_set++;
4892 list_add_tail(&tgt->queue, &vhost->targets);
4895 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4901 * @vhost: ibmvfc host struct
4906 static int ibmvfc_alloc_targets(struct ibmvfc_host *vhost)
4910 for (i = 0, rc = 0; !rc && i < vhost->num_targets; i++)
4911 rc = ibmvfc_alloc_target(vhost, &vhost->disc_buf[i]);
4923 struct ibmvfc_host *vhost = evt->vhost;
4930 ibmvfc_dbg(vhost, "Discover Targets succeeded\n");
4931 vhost->num_targets = be32_to_cpu(rsp->num_written);
4932 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_ALLOC_TGTS);
4935 level += ibmvfc_retry_host_init(vhost);
4936 ibmvfc_log(vhost, level, "Discover Targets failed: %s (%x:%x)\n",
4943 dev_err(vhost->dev, "Invalid Discover Targets response: 0x%x\n", mad_status);
4944 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
4949 wake_up(&vhost->work_wait_q);
4954 * @vhost: ibmvfc host struct
4957 static void ibmvfc_discover_targets(struct ibmvfc_host *vhost)
4960 struct ibmvfc_event *evt = ibmvfc_get_event(&vhost->crq);
4964 ibmvfc_log(vhost, level, "Discover Targets failed: no available events\n");
4965 ibmvfc_hard_reset_host(vhost);
4975 mad->bufflen = cpu_to_be32(vhost->disc_buf_sz);
4976 mad->buffer.va = cpu_to_be64(vhost->disc_buf_dma);
4977 mad->buffer.len = cpu_to_be32(vhost->disc_buf_sz);
4979 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT_WAIT);
4981 if (!ibmvfc_send_event(evt, vhost, default_timeout))
4982 ibmvfc_dbg(vhost, "Sent discover targets\n");
4984 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
4989 struct ibmvfc_host *vhost = evt->vhost;
4990 struct ibmvfc_channel_setup *setup = vhost->channel_setup_buf;
4991 struct ibmvfc_scsi_channels *scrqs = &vhost->scsi_scrqs;
5000 ibmvfc_dbg(vhost, "Channel Setup succeeded\n");
5002 vhost->do_enquiry = 0;
5007 ibmvfc_dbg(vhost, "Channels Canceled\n");
5008 vhost->using_channels = 0;
5011 vhost->using_channels = 1;
5016 ibmvfc_dbg(vhost, "Using %u channels\n",
5017 vhost->scsi_scrqs.active_queues);
5021 level += ibmvfc_retry_host_init(vhost);
5022 ibmvfc_log(vhost, level, "Channel Setup failed\n");
5027 dev_err(vhost->dev, "Invalid Channel Setup response: 0x%x\n",
5029 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
5033 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY);
5034 wake_up(&vhost->work_wait_q);
5037 static void ibmvfc_channel_setup(struct ibmvfc_host *vhost)
5040 struct ibmvfc_channel_setup *setup_buf = vhost->channel_setup_buf;
5041 struct ibmvfc_event *evt = ibmvfc_get_event(&vhost->crq);
5042 struct ibmvfc_scsi_channels *scrqs = &vhost->scsi_scrqs;
5044 min(vhost->client_scsi_channels, vhost->max_vios_scsi_channels);
5049 ibmvfc_log(vhost, level, "Channel Setup failed: no available events\n");
5050 ibmvfc_hard_reset_host(vhost);
5069 mad->buffer.va = cpu_to_be64(vhost->channel_setup_dma);
5070 mad->buffer.len = cpu_to_be32(sizeof(*vhost->channel_setup_buf));
5072 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT_WAIT);
5074 if (!ibmvfc_send_event(evt, vhost, default_timeout))
5075 ibmvfc_dbg(vhost, "Sent channel setup\n");
5077 ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN);
5082 struct ibmvfc_host *vhost = evt->vhost;
5089 ibmvfc_dbg(vhost, "Channel Enquiry succeeded\n");
5090 vhost->max_vios_scsi_channels = be32_to_cpu(rsp->num_scsi_subq_channels);
5094 level += ibmvfc_retry_host_init(vhost);
5095 ibmvfc_log(vhost, level, "Channel Enquiry failed\n");
5101 dev_err(vhost->dev, "Invalid Channel Enquiry response: 0x%x\n",
5103 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
5108 ibmvfc_channel_setup(vhost);
5111 static void ibmvfc_channel_enquiry(struct ibmvfc_host *vhost)
5114 struct ibmvfc_event *evt = ibmvfc_get_event(&vhost->crq);
5118 ibmvfc_log(vhost, level, "Channel Enquiry failed: no available events\n");
5119 ibmvfc_hard_reset_host(vhost);
5135 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT_WAIT);
5137 if (!ibmvfc_send_event(evt, vhost, default_timeout))
5138 ibmvfc_dbg(vhost, "Send channel enquiry\n");
5140 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
5150 struct ibmvfc_host *vhost = evt->vhost;
5152 struct ibmvfc_npiv_login_resp *rsp = &vhost->login_buf->resp;
5162 level += ibmvfc_retry_host_init(vhost);
5164 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
5165 ibmvfc_log(vhost, level, "NPIV Login failed: %s (%x:%x)\n",
5171 ibmvfc_retry_host_init(vhost);
5177 dev_err(vhost->dev, "Invalid NPIV Login response: 0x%x\n", mad_status);
5178 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
5183 vhost->client_migrated = 0;
5186 dev_err(vhost->dev, "Virtual adapter does not support FC. %x\n",
5188 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
5189 wake_up(&vhost->work_wait_q);
5194 dev_err(vhost->dev, "Virtual adapter supported queue depth too small: %d\n",
5196 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
5197 wake_up(&vhost->work_wait_q);
5201 vhost->logged_in = 1;
5203 dev_info(vhost->dev, "Host partition: %s, device: %s %s %s max sectors %u\n",
5207 fc_host_fabric_name(vhost->host) = be64_to_cpu(rsp->node_name);
5208 fc_host_node_name(vhost->host) = be64_to_cpu(rsp->node_name);
5209 fc_host_port_name(vhost->host) = be64_to_cpu(rsp->port_name);
5210 fc_host_port_id(vhost->host) = be64_to_cpu(rsp->scsi_id);
5211 fc_host_port_type(vhost->host) = FC_PORTTYPE_NPIV;
5212 fc_host_supported_classes(vhost->host) = 0;
5214 fc_host_supported_classes(vhost->host) |= FC_COS_CLASS1;
5216 fc_host_supported_classes(vhost->host) |= FC_COS_CLASS2;
5218 fc_host_supported_classes(vhost->host) |= FC_COS_CLASS3;
5219 fc_host_maxframe_size(vhost->host) =
5222 vhost->host->can_queue = be32_to_cpu(rsp->max_cmds) - IBMVFC_NUM_INTERNAL_REQ;
5223 vhost->host->max_sectors = npiv_max_sectors;
5225 if (ibmvfc_check_caps(vhost, IBMVFC_CAN_SUPPORT_CHANNELS) && vhost->do_enquiry) {
5226 ibmvfc_channel_enquiry(vhost);
5228 vhost->do_enquiry = 0;
5229 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY);
5230 wake_up(&vhost->work_wait_q);
5236 * @vhost: ibmvfc host struct
5239 static void ibmvfc_npiv_login(struct ibmvfc_host *vhost)
5242 struct ibmvfc_event *evt = ibmvfc_get_event(&vhost->crq);
5245 ibmvfc_dbg(vhost, "NPIV Login failed: no available events\n");
5246 ibmvfc_hard_reset_host(vhost);
5250 ibmvfc_gather_partition_info(vhost);
5251 ibmvfc_set_login_info(vhost);
5254 memcpy(vhost->login_buf, &vhost->login_info, sizeof(vhost->login_info));
5260 mad->buffer.va = cpu_to_be64(vhost->login_buf_dma);
5261 mad->buffer.len = cpu_to_be32(sizeof(*vhost->login_buf));
5263 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT_WAIT);
5265 if (!ibmvfc_send_event(evt, vhost, default_timeout))
5266 ibmvfc_dbg(vhost, "Sent NPIV login\n");
5268 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
5278 struct ibmvfc_host *vhost = evt->vhost;
5285 if (list_empty(&vhost->crq.sent) &&
5286 vhost->action == IBMVFC_HOST_ACTION_LOGO_WAIT) {
5287 ibmvfc_init_host(vhost);
5296 ibmvfc_dbg(vhost, "NPIV Logout failed. 0x%X\n", mad_status);
5300 ibmvfc_hard_reset_host(vhost);
5305 * @vhost: ibmvfc host struct
5308 static void ibmvfc_npiv_logout(struct ibmvfc_host *vhost)
5313 evt = ibmvfc_get_event(&vhost->crq);
5315 ibmvfc_dbg(vhost, "NPIV Logout failed: no available events\n");
5316 ibmvfc_hard_reset_host(vhost);
5328 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_LOGO_WAIT);
5330 if (!ibmvfc_send_event(evt, vhost, default_timeout))
5331 ibmvfc_dbg(vhost, "Sent NPIV logout\n");
5333 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
5338 * @vhost: ibmvfc host struct
5343 static int ibmvfc_dev_init_to_do(struct ibmvfc_host *vhost)
5347 list_for_each_entry(tgt, &vhost->targets, queue) {
5358 * @vhost: ibmvfc host struct
5363 static int ibmvfc_dev_logo_to_do(struct ibmvfc_host *vhost)
5367 list_for_each_entry(tgt, &vhost->targets, queue) {
5377 * @vhost: ibmvfc host struct
5382 static int __ibmvfc_work_to_do(struct ibmvfc_host *vhost)
5388 switch (vhost->action) {
5395 if (vhost->discovery_threads == disc_threads)
5397 list_for_each_entry(tgt, &vhost->targets, queue)
5400 list_for_each_entry(tgt, &vhost->targets, queue)
5406 if (vhost->discovery_threads == disc_threads)
5408 list_for_each_entry(tgt, &vhost->targets, queue)
5411 list_for_each_entry(tgt, &vhost->targets, queue)
5430 * @vhost: ibmvfc host struct
5435 static int ibmvfc_work_to_do(struct ibmvfc_host *vhost)
5440 spin_lock_irqsave(vhost->host->host_lock, flags);
5441 rc = __ibmvfc_work_to_do(vhost);
5442 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5448 * @vhost: ibmvfc host struct
5452 static void ibmvfc_log_ae(struct ibmvfc_host *vhost, int events)
5455 fc_host_post_event(vhost->host, fc_get_event_number(), FCH_EVT_RSCN, 0);
5457 vhost->state >= IBMVFC_HALTED)
5458 fc_host_post_event(vhost->host, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
5460 vhost->state == IBMVFC_INITIALIZING)
5461 fc_host_post_event(vhost->host, fc_get_event_number(), FCH_EVT_LINKUP, 0);
5471 struct ibmvfc_host *vhost = tgt->vhost;
5476 rport = fc_remote_port_add(vhost->host, 0, &tgt->ids);
5477 spin_lock_irqsave(vhost->host->host_lock, flags);
5483 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5493 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5497 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5517 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5522 * @vhost: ibmvfc host struct
5525 static void ibmvfc_do_work(struct ibmvfc_host *vhost)
5533 ibmvfc_log_ae(vhost, vhost->events_to_log);
5534 spin_lock_irqsave(vhost->host->host_lock, flags);
5535 vhost->events_to_log = 0;
5536 switch (vhost->action) {
5542 list_splice_init(&vhost->purge, &purge);
5543 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5545 rc = ibmvfc_reset_crq(vhost);
5547 spin_lock_irqsave(vhost->host->host_lock, flags);
5549 vio_enable_interrupts(to_vio_dev(vhost->dev));
5550 if (vhost->action == IBMVFC_HOST_ACTION_RESET) {
5557 vhost->action = IBMVFC_HOST_ACTION_TGT_DEL;
5559 if (rc || (rc = ibmvfc_send_crq_init(vhost)) ||
5560 (rc = vio_enable_interrupts(to_vio_dev(vhost->dev)))) {
5561 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
5562 dev_err(vhost->dev, "Error after reset (rc=%d)\n", rc);
5567 list_splice_init(&vhost->purge, &purge);
5568 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5570 rc = ibmvfc_reenable_crq_queue(vhost);
5572 spin_lock_irqsave(vhost->host->host_lock, flags);
5573 if (vhost->action == IBMVFC_HOST_ACTION_REENABLE) {
5580 vhost->action = IBMVFC_HOST_ACTION_TGT_DEL;
5581 if (rc || (rc = ibmvfc_send_crq_init(vhost))) {
5582 ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
5583 dev_err(vhost->dev, "Error after enable (rc=%d)\n", rc);
5588 vhost->job_step(vhost);
5591 BUG_ON(vhost->state != IBMVFC_INITIALIZING);
5592 if (vhost->delay_init) {
5593 vhost->delay_init = 0;
5594 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5598 vhost->job_step(vhost);
5601 list_for_each_entry(tgt, &vhost->targets, queue)
5603 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY_TGTS);
5606 list_for_each_entry(tgt, &vhost->targets, queue) {
5613 if (!ibmvfc_dev_init_to_do(vhost))
5614 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_DEL);
5618 list_for_each_entry(tgt, &vhost->targets, queue) {
5625 if (ibmvfc_dev_logo_to_do(vhost)) {
5626 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5630 list_for_each_entry(tgt, &vhost->targets, queue) {
5637 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5661 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5668 if (vhost->state == IBMVFC_INITIALIZING) {
5669 if (vhost->action == IBMVFC_HOST_ACTION_TGT_DEL_FAILED) {
5670 if (vhost->reinit) {
5671 vhost->reinit = 0;
5672 scsi_block_requests(vhost->host);
5673 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY);
5674 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5676 ibmvfc_set_host_state(vhost, IBMVFC_ACTIVE);
5677 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_NONE);
5678 wake_up(&vhost->init_wait_q);
5679 schedule_work(&vhost->rport_add_work_q);
5680 vhost->init_retries = 0;
5681 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5682 scsi_unblock_requests(vhost->host);
5687 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT);
5688 vhost->job_step = ibmvfc_discover_targets;
5691 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_NONE);
5692 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5693 scsi_unblock_requests(vhost->host);
5694 wake_up(&vhost->init_wait_q);
5699 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_INIT);
5700 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5701 ibmvfc_alloc_targets(vhost);
5702 spin_lock_irqsave(vhost->host->host_lock, flags);
5705 list_for_each_entry(tgt, &vhost->targets, queue) {
5712 if (!ibmvfc_dev_init_to_do(vhost))
5713 ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_DEL_FAILED);
5719 spin_unlock_irqrestore(vhost->host->host_lock, flags);
5731 struct ibmvfc_host *vhost = data;
5737 rc = wait_event_interruptible(vhost->work_wait_q,
5738 ibmvfc_work_to_do(vhost));
5745 ibmvfc_do_work(vhost);
5748 ibmvfc_dbg(vhost, "ibmvfc kthread exiting...\n");
5754 * @vhost: ibmvfc host struct
5761 static int ibmvfc_alloc_queue(struct ibmvfc_host *vhost,
5765 struct device *dev = vhost->dev;
5791 if (ibmvfc_init_event_pool(vhost, queue, pool_size)) {
5813 queue->vhost = vhost;
5819 * @vhost: ibmvfc host struct
5827 static int ibmvfc_init_crq(struct ibmvfc_host *vhost)
5830 struct device *dev = vhost->dev;
5832 struct ibmvfc_queue *crq = &vhost->crq;
5835 if (ibmvfc_alloc_queue(vhost, crq, IBMVFC_CRQ_FMT))
5843 retrc = rc = ibmvfc_reset_crq(vhost);
5854 tasklet_init(&vhost->tasklet, (void *)ibmvfc_tasklet, (unsigned long)vhost);
5856 if ((rc = request_irq(vdev->irq, ibmvfc_interrupt, 0, IBMVFC_NAME, vhost))) {
5870 tasklet_kill(&vhost->tasklet);
5875 ibmvfc_free_queue(vhost, crq);
5879 static int ibmvfc_register_scsi_channel(struct ibmvfc_host *vhost,
5882 struct device *dev = vhost->dev;
5884 struct ibmvfc_queue *scrq = &vhost->scsi_scrqs.scrqs[index];
5932 static void ibmvfc_deregister_scsi_channel(struct ibmvfc_host *vhost, int index)
5934 struct device *dev = vhost->dev;
5936 struct ibmvfc_queue *scrq = &vhost->scsi_scrqs.scrqs[index];
5960 static void ibmvfc_reg_sub_crqs(struct ibmvfc_host *vhost)
5965 if (!vhost->mq_enabled || !vhost->scsi_scrqs.scrqs)
5969 if (ibmvfc_register_scsi_channel(vhost, i)) {
5971 ibmvfc_deregister_scsi_channel(vhost, j - 1);
5972 vhost->do_enquiry = 0;
5980 static void ibmvfc_dereg_sub_crqs(struct ibmvfc_host *vhost)
5985 if (!vhost->mq_enabled || !vhost->scsi_scrqs.scrqs)
5989 ibmvfc_deregister_scsi_channel(vhost, i);
5994 static void ibmvfc_init_sub_crqs(struct ibmvfc_host *vhost)
6000 if (!vhost->mq_enabled)
6003 vhost->scsi_scrqs.scrqs = kcalloc(nr_scsi_hw_queues,
6004 sizeof(*vhost->scsi_scrqs.scrqs),
6006 if (!vhost->scsi_scrqs.scrqs) {
6007 vhost->do_enquiry = 0;
6012 scrq = &vhost->scsi_scrqs.scrqs[i];
6013 if (ibmvfc_alloc_queue(vhost, scrq, IBMVFC_SUB_CRQ_FMT)) {
6015 scrq = &vhost->scsi_scrqs.scrqs[j - 1];
6016 ibmvfc_free_queue(vhost, scrq);
6018 kfree(vhost->scsi_scrqs.scrqs);
6019 vhost->scsi_scrqs.scrqs = NULL;
6020 vhost->scsi_scrqs.active_queues = 0;
6021 vhost->do_enquiry = 0;
6022 vhost->mq_enabled = 0;
6027 ibmvfc_reg_sub_crqs(vhost);
6032 static void ibmvfc_release_sub_crqs(struct ibmvfc_host *vhost)
6038 if (!vhost->scsi_scrqs.scrqs)
6041 ibmvfc_dereg_sub_crqs(vhost);
6044 scrq = &vhost->scsi_scrqs.scrqs[i];
6045 ibmvfc_free_queue(vhost, scrq);
6048 kfree(vhost->scsi_scrqs.scrqs);
6049 vhost->scsi_scrqs.scrqs = NULL;
6050 vhost->scsi_scrqs.active_queues = 0;
6055 * ibmvfc_free_mem - Free memory for vhost
6056 * @vhost: ibmvfc host struct
6061 static void ibmvfc_free_mem(struct ibmvfc_host *vhost)
6063 struct ibmvfc_queue *async_q = &vhost->async_crq;
6066 mempool_destroy(vhost->tgt_pool);
6067 kfree(vhost->trace);
6068 dma_free_coherent(vhost->dev, vhost->disc_buf_sz, vhost->disc_buf,
6069 vhost->disc_buf_dma);
6070 dma_free_coherent(vhost->dev, sizeof(*vhost->login_buf),
6071 vhost->login_buf, vhost->login_buf_dma);
6072 dma_free_coherent(vhost->dev, sizeof(*vhost->channel_setup_buf),
6073 vhost->channel_setup_buf, vhost->channel_setup_dma);
6074 dma_pool_destroy(vhost->sg_pool);
6075 ibmvfc_free_queue(vhost, async_q);
6080 * ibmvfc_alloc_mem - Allocate memory for vhost
6081 * @vhost: ibmvfc host struct
6086 static int ibmvfc_alloc_mem(struct ibmvfc_host *vhost)
6088 struct ibmvfc_queue *async_q = &vhost->async_crq;
6089 struct device *dev = vhost->dev;
6092 if (ibmvfc_alloc_queue(vhost, async_q, IBMVFC_ASYNC_FMT)) {
6097 vhost->sg_pool = dma_pool_create(IBMVFC_NAME, dev,
6101 if (!vhost->sg_pool) {
6106 vhost->login_buf = dma_alloc_coherent(dev, sizeof(*vhost->login_buf),
6107 &vhost->login_buf_dma, GFP_KERNEL);
6109 if (!vhost->login_buf) {
6114 vhost->disc_buf_sz = sizeof(*vhost->disc_buf) * max_targets;
6115 vhost->disc_buf = dma_alloc_coherent(dev, vhost->disc_buf_sz,
6116 &vhost->disc_buf_dma, GFP_KERNEL);
6118 if (!vhost->disc_buf) {
6123 vhost->trace = kcalloc(IBMVFC_NUM_TRACE_ENTRIES,
6125 atomic_set(&vhost->trace_index, -1);
6127 if (!vhost->trace)
6130 vhost->tgt_pool = mempool_create_kmalloc_pool(IBMVFC_TGT_MEMPOOL_SZ,
6133 if (!vhost->tgt_pool) {
6138 vhost->channel_setup_buf = dma_alloc_coherent(dev, sizeof(*vhost->channel_setup_buf),
6139 &vhost->channel_setup_dma,
6142 if (!vhost->channel_setup_buf) {
6151 mempool_destroy(vhost->tgt_pool);
6153 kfree(vhost->trace);
6155 dma_free_coherent(dev, vhost->disc_buf_sz, vhost->disc_buf,
6156 vhost->disc_buf_dma);
6158 dma_free_coherent(dev, sizeof(*vhost->login_buf),
6159 vhost->login_buf, vhost->login_buf_dma);
6161 dma_pool_destroy(vhost->sg_pool);
6163 ibmvfc_free_queue(vhost, async_q);
6176 struct ibmvfc_host *vhost = container_of(work, struct ibmvfc_host,
6184 spin_lock_irqsave(vhost->host->host_lock, flags);
6187 if (vhost->state != IBMVFC_ACTIVE)
6190 list_for_each_entry(tgt, &vhost->targets, queue) {
6197 spin_unlock_irqrestore(vhost->host->host_lock, flags);
6200 spin_unlock_irqrestore(vhost->host->host_lock, flags);
6205 spin_unlock_irqrestore(vhost->host->host_lock, flags);
6209 spin_lock_irqsave(vhost->host->host_lock, flags);
6215 if (vhost->state == IBMVFC_ACTIVE)
6216 vhost->scan_complete = 1;
6217 spin_unlock_irqrestore(vhost->host->host_lock, flags);
6231 struct ibmvfc_host *vhost;
6238 shost = scsi_host_alloc(&driver_template, sizeof(*vhost));
6253 vhost = shost_priv(shost);
6254 INIT_LIST_HEAD(&vhost->targets);
6255 INIT_LIST_HEAD(&vhost->purge);
6256 sprintf(vhost->name, IBMVFC_NAME);
6257 vhost->host = shost;
6258 vhost->dev = dev;
6259 vhost->partition_number = -1;
6260 vhost->log_level = log_level;
6261 vhost->task_set = 1;
6263 vhost->mq_enabled = mq_enabled;
6264 vhost->client_scsi_channels = min(shost->nr_hw_queues, nr_scsi_channels);
6265 vhost->using_channels = 0;
6266 vhost->do_enquiry = 1;
6267 vhost->scan_timeout = 0;
6269 strcpy(vhost->partition_name, "UNKNOWN");
6270 init_waitqueue_head(&vhost->work_wait_q);
6271 init_waitqueue_head(&vhost->init_wait_q);
6272 INIT_WORK(&vhost->rport_add_work_q, ibmvfc_rport_add_thread);
6273 mutex_init(&vhost->passthru_mutex);
6275 if ((rc = ibmvfc_alloc_mem(vhost)))
6278 vhost->work_thread = kthread_run(ibmvfc_work, vhost, "%s_%d", IBMVFC_NAME,
6281 if (IS_ERR(vhost->work_thread)) {
6283 PTR_ERR(vhost->work_thread));
6284 rc = PTR_ERR(vhost->work_thread);
6288 if ((rc = ibmvfc_init_crq(vhost))) {
6304 ibmvfc_init_sub_crqs(vhost);
6308 dev_set_drvdata(dev, vhost);
6310 list_add_tail(&vhost->queue, &ibmvfc_head);
6313 ibmvfc_send_crq_init(vhost);
6320 ibmvfc_release_crq_queue(vhost);
6322 kthread_stop(vhost->work_thread);
6324 ibmvfc_free_mem(vhost);
6341 struct ibmvfc_host *vhost = dev_get_drvdata(&vdev->dev);
6346 ibmvfc_remove_trace_file(&vhost->host->shost_dev.kobj, &ibmvfc_trace_attr);
6348 spin_lock_irqsave(vhost->host->host_lock, flags);
6349 ibmvfc_link_down(vhost, IBMVFC_HOST_OFFLINE);
6350 spin_unlock_irqrestore(vhost->host->host_lock, flags);
6352 ibmvfc_wait_while_resetting(vhost);
6353 kthread_stop(vhost->work_thread);
6354 fc_remove_host(vhost->host);
6355 scsi_remove_host(vhost->host);
6357 spin_lock_irqsave(vhost->host->host_lock, flags);
6358 ibmvfc_purge_requests(vhost, DID_ERROR);
6359 list_splice_init(&vhost->purge, &purge);
6360 spin_unlock_irqrestore(vhost->host->host_lock, flags);
6362 ibmvfc_release_sub_crqs(vhost);
6363 ibmvfc_release_crq_queue(vhost);
6365 ibmvfc_free_mem(vhost);
6367 list_del(&vhost->queue);
6369 scsi_host_put(vhost->host);
6384 struct ibmvfc_host *vhost = dev_get_drvdata(dev);
6387 spin_lock_irqsave(vhost->host->host_lock, flags);
6389 tasklet_schedule(&vhost->tasklet);
6390 spin_unlock_irqrestore(vhost->host->host_lock, flags);