Lines Matching +full:vp +full:- +full:p

1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (c) 2003-2014 QLogic Corporation
22 if (vha->vp_idx && vha->timer_active) { in qla2x00_vp_stop_timer()
23 del_timer_sync(&vha->timer); in qla2x00_vp_stop_timer()
24 vha->timer_active = 0; in qla2x00_vp_stop_timer()
32 struct qla_hw_data *ha = vha->hw; in qla24xx_allocate_vp_id()
36 mutex_lock(&ha->vport_lock); in qla24xx_allocate_vp_id()
37 vp_id = find_first_zero_bit(ha->vp_idx_map, ha->max_npiv_vports + 1); in qla24xx_allocate_vp_id()
38 if (vp_id > ha->max_npiv_vports) { in qla24xx_allocate_vp_id()
40 "vp_id %d is bigger than max-supported %d.\n", in qla24xx_allocate_vp_id()
41 vp_id, ha->max_npiv_vports); in qla24xx_allocate_vp_id()
42 mutex_unlock(&ha->vport_lock); in qla24xx_allocate_vp_id()
46 set_bit(vp_id, ha->vp_idx_map); in qla24xx_allocate_vp_id()
47 ha->num_vhosts++; in qla24xx_allocate_vp_id()
48 vha->vp_idx = vp_id; in qla24xx_allocate_vp_id()
50 spin_lock_irqsave(&ha->vport_slock, flags); in qla24xx_allocate_vp_id()
51 list_add_tail(&vha->list, &ha->vp_list); in qla24xx_allocate_vp_id()
52 spin_unlock_irqrestore(&ha->vport_slock, flags); in qla24xx_allocate_vp_id()
54 spin_lock_irqsave(&ha->hardware_lock, flags); in qla24xx_allocate_vp_id()
56 spin_unlock_irqrestore(&ha->hardware_lock, flags); in qla24xx_allocate_vp_id()
58 mutex_unlock(&ha->vport_lock); in qla24xx_allocate_vp_id()
66 struct qla_hw_data *ha = vha->hw; in qla24xx_deallocate_vp_id()
70 mutex_lock(&ha->vport_lock); in qla24xx_deallocate_vp_id()
80 spin_lock_irqsave(&ha->vport_slock, flags); in qla24xx_deallocate_vp_id()
81 if (atomic_read(&vha->vref_count) == 0) { in qla24xx_deallocate_vp_id()
82 list_del(&vha->list); in qla24xx_deallocate_vp_id()
86 spin_unlock_irqrestore(&ha->vport_slock, flags); in qla24xx_deallocate_vp_id()
95 "vha->vref_count=%u timeout\n", vha->vref_count.counter); in qla24xx_deallocate_vp_id()
96 spin_lock_irqsave(&ha->vport_slock, flags); in qla24xx_deallocate_vp_id()
97 list_del(&vha->list); in qla24xx_deallocate_vp_id()
99 spin_unlock_irqrestore(&ha->vport_slock, flags); in qla24xx_deallocate_vp_id()
102 vp_id = vha->vp_idx; in qla24xx_deallocate_vp_id()
103 ha->num_vhosts--; in qla24xx_deallocate_vp_id()
104 clear_bit(vp_id, ha->vp_idx_map); in qla24xx_deallocate_vp_id()
106 mutex_unlock(&ha->vport_lock); in qla24xx_deallocate_vp_id()
116 spin_lock_irqsave(&ha->vport_slock, flags); in qla24xx_find_vhost_by_name()
118 list_for_each_entry_safe(vha, tvha, &ha->vp_list, list) { in qla24xx_find_vhost_by_name()
119 if (!memcmp(port_name, vha->port_name, WWN_SIZE)) { in qla24xx_find_vhost_by_name()
120 spin_unlock_irqrestore(&ha->vport_slock, flags); in qla24xx_find_vhost_by_name()
124 spin_unlock_irqrestore(&ha->vport_slock, flags); in qla24xx_find_vhost_by_name()
146 * This function, if called in contexts other than vp create, disable in qla2x00_mark_vp_devices_dead()
152 list_for_each_entry(fcport, &vha->vp_fcports, list) { in qla2x00_mark_vp_devices_dead()
155 fcport->loop_id, fcport->vha->vp_idx); in qla2x00_mark_vp_devices_dead()
169 if (vha->hw->flags.edif_enabled) { in qla24xx_disable_vp()
177 if (vha->hw->flags.fw_started) in qla24xx_disable_vp()
180 atomic_set(&vha->loop_state, LOOP_DOWN); in qla24xx_disable_vp()
181 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); in qla24xx_disable_vp()
182 list_for_each_entry(fcport, &vha->vp_fcports, list) in qla24xx_disable_vp()
183 fcport->logout_on_delete = 1; in qla24xx_disable_vp()
185 if (!vha->hw->flags.edif_enabled) in qla24xx_disable_vp()
188 /* Remove port id from vp target map */ in qla24xx_disable_vp()
189 spin_lock_irqsave(&vha->hw->hardware_lock, flags); in qla24xx_disable_vp()
191 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); in qla24xx_disable_vp()
194 atomic_set(&vha->vp_state, VP_FAILED); in qla24xx_disable_vp()
195 vha->flags.management_server_logged_in = 0; in qla24xx_disable_vp()
197 fc_vport_set_state(vha->fc_vport, FC_VPORT_DISABLED); in qla24xx_disable_vp()
199 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); in qla24xx_disable_vp()
200 return -1; in qla24xx_disable_vp()
209 struct qla_hw_data *ha = vha->hw; in qla24xx_enable_vp()
210 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); in qla24xx_enable_vp()
213 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN || in qla24xx_enable_vp()
214 atomic_read(&base_vha->loop_state) == LOOP_DEAD || in qla24xx_enable_vp()
215 !(ha->current_topology & ISP_CFG_F)) { in qla24xx_enable_vp()
216 vha->vp_err_state = VP_ERR_PORTDWN; in qla24xx_enable_vp()
217 fc_vport_set_state(vha->fc_vport, FC_VPORT_LINKDOWN); in qla24xx_enable_vp()
220 __func__, base_vha->loop_state.counter, in qla24xx_enable_vp()
221 ha->current_topology); in qla24xx_enable_vp()
227 mutex_lock(&ha->vport_lock); in qla24xx_enable_vp()
229 mutex_unlock(&ha->vport_lock); in qla24xx_enable_vp()
232 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); in qla24xx_enable_vp()
237 "Virtual port with id: %d - Enabled.\n", vha->vp_idx); in qla24xx_enable_vp()
242 "Virtual port with id: %d - Disabled.\n", vha->vp_idx); in qla24xx_enable_vp()
252 fc_vport = vha->fc_vport; in qla24xx_configure_vp()
256 ret = qla2x00_send_change_request(vha, 0x3, vha->vp_idx); in qla24xx_configure_vp()
263 clear_bit(VP_SCR_NEEDED, &vha->vp_flags); in qla24xx_configure_vp()
266 vha->flags.online = 1; in qla24xx_configure_vp()
270 atomic_set(&vha->vp_state, VP_ACTIVE); in qla24xx_configure_vp()
278 struct qla_hw_data *ha = rsp->hw; in qla2x00_alert_all_vps()
282 spin_lock_irqsave(&ha->vport_slock, flags); in qla2x00_alert_all_vps()
283 list_for_each_entry_safe(vha, tvp, &ha->vp_list, list) { in qla2x00_alert_all_vps()
284 if (vha->vp_idx) { in qla2x00_alert_all_vps()
285 if (test_bit(VPORT_DELETE, &vha->dpc_flags)) in qla2x00_alert_all_vps()
288 atomic_inc(&vha->vref_count); in qla2x00_alert_all_vps()
289 spin_unlock_irqrestore(&ha->vport_slock, flags); in qla2x00_alert_all_vps()
299 "Async_event for VP[%d], mb=0x%x vha=%p.\n", in qla2x00_alert_all_vps()
305 if ((mb[3] & 0xff) == vha->vp_idx) { in qla2x00_alert_all_vps()
307 "Async_event for VP[%d], mb=0x%x vha=%p\n", in qla2x00_alert_all_vps()
314 spin_lock_irqsave(&ha->vport_slock, flags); in qla2x00_alert_all_vps()
315 atomic_dec(&vha->vref_count); in qla2x00_alert_all_vps()
316 wake_up(&vha->vref_waitq); in qla2x00_alert_all_vps()
320 spin_unlock_irqrestore(&ha->vport_slock, flags); in qla2x00_alert_all_vps()
331 * issued, this is expected, as the vp would be already in qla2x00_vp_abort_isp()
334 if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) { in qla2x00_vp_abort_isp()
336 list_for_each_entry(fcport, &vha->vp_fcports, list) in qla2x00_vp_abort_isp()
337 fcport->logout_on_delete = 0; in qla2x00_vp_abort_isp()
344 if (atomic_read(&vha->loop_state) != LOOP_DOWN) { in qla2x00_vp_abort_isp()
345 atomic_set(&vha->loop_state, LOOP_DOWN); in qla2x00_vp_abort_isp()
348 if (!atomic_read(&vha->loop_down_timer)) in qla2x00_vp_abort_isp()
349 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); in qla2x00_vp_abort_isp()
353 "Scheduling enable of Vport %d.\n", vha->vp_idx); in qla2x00_vp_abort_isp()
361 struct qla_hw_data *ha = vha->hw; in qla2x00_do_dpc_vp()
362 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); in qla2x00_do_dpc_vp()
365 "Entering %s vp_flags: 0x%lx.\n", __func__, vha->vp_flags); in qla2x00_do_dpc_vp()
367 /* Check if Fw is ready to configure VP first */ in qla2x00_do_dpc_vp()
368 if (test_bit(VP_CONFIG_OK, &base_vha->vp_flags)) { in qla2x00_do_dpc_vp()
369 if (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) { in qla2x00_do_dpc_vp()
370 /* VP acquired. complete port configuration */ in qla2x00_do_dpc_vp()
372 "Configure VP scheduled.\n"); in qla2x00_do_dpc_vp()
375 "Configure VP end.\n"); in qla2x00_do_dpc_vp()
380 if (test_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags)) { in qla2x00_do_dpc_vp()
381 if (atomic_read(&vha->loop_state) == LOOP_READY) { in qla2x00_do_dpc_vp()
382 qla24xx_process_purex_list(&vha->purex_list); in qla2x00_do_dpc_vp()
383 clear_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags); in qla2x00_do_dpc_vp()
387 if (test_bit(RELOGIN_NEEDED, &vha->dpc_flags) && in qla2x00_do_dpc_vp()
388 !test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) && in qla2x00_do_dpc_vp()
389 atomic_read(&vha->loop_state) != LOOP_DOWN) { in qla2x00_do_dpc_vp()
391 if (!vha->relogin_jif || in qla2x00_do_dpc_vp()
392 time_after_eq(jiffies, vha->relogin_jif)) { in qla2x00_do_dpc_vp()
393 vha->relogin_jif = jiffies + HZ; in qla2x00_do_dpc_vp()
394 clear_bit(RELOGIN_NEEDED, &vha->dpc_flags); in qla2x00_do_dpc_vp()
402 if (test_and_clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) && in qla2x00_do_dpc_vp()
403 (!(test_and_set_bit(RESET_ACTIVE, &vha->dpc_flags)))) { in qla2x00_do_dpc_vp()
404 clear_bit(RESET_ACTIVE, &vha->dpc_flags); in qla2x00_do_dpc_vp()
407 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { in qla2x00_do_dpc_vp()
408 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))) { in qla2x00_do_dpc_vp()
412 clear_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags); in qla2x00_do_dpc_vp()
426 struct qla_hw_data *ha = vha->hw; in qla2x00_do_dpc_all_vps()
427 scsi_qla_host_t *vp, *tvp; in qla2x00_do_dpc_all_vps() local
430 if (vha->vp_idx) in qla2x00_do_dpc_all_vps()
432 if (list_empty(&ha->vp_list)) in qla2x00_do_dpc_all_vps()
435 clear_bit(VP_DPC_NEEDED, &vha->dpc_flags); in qla2x00_do_dpc_all_vps()
437 if (!(ha->current_topology & ISP_CFG_F)) in qla2x00_do_dpc_all_vps()
440 spin_lock_irqsave(&ha->vport_slock, flags); in qla2x00_do_dpc_all_vps()
441 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { in qla2x00_do_dpc_all_vps()
442 if (vp->vp_idx) { in qla2x00_do_dpc_all_vps()
443 atomic_inc(&vp->vref_count); in qla2x00_do_dpc_all_vps()
444 spin_unlock_irqrestore(&ha->vport_slock, flags); in qla2x00_do_dpc_all_vps()
446 qla2x00_do_dpc_vp(vp); in qla2x00_do_dpc_all_vps()
448 spin_lock_irqsave(&ha->vport_slock, flags); in qla2x00_do_dpc_all_vps()
449 atomic_dec(&vp->vref_count); in qla2x00_do_dpc_all_vps()
452 spin_unlock_irqrestore(&ha->vport_slock, flags); in qla2x00_do_dpc_all_vps()
458 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost); in qla24xx_vport_create_req_sanity_check()
459 struct qla_hw_data *ha = base_vha->hw; in qla24xx_vport_create_req_sanity_check()
463 if (fc_vport->roles != FC_PORT_ROLE_FCP_INITIATOR) in qla24xx_vport_create_req_sanity_check()
467 if (!ha->flags.npiv_supported) in qla24xx_vport_create_req_sanity_check()
471 if (!(ha->switch_cap & FLOGI_MID_SUPPORT)) in qla24xx_vport_create_req_sanity_check()
475 u64_to_wwn(fc_vport->port_name, port_name); in qla24xx_vport_create_req_sanity_check()
476 if (!memcmp(port_name, base_vha->port_name, WWN_SIZE)) in qla24xx_vport_create_req_sanity_check()
482 /* Check up max-npiv-supports */ in qla24xx_vport_create_req_sanity_check()
483 if (ha->num_vhosts > ha->max_npiv_vports) { in qla24xx_vport_create_req_sanity_check()
487 ha->num_vhosts, ha->max_npiv_vports); in qla24xx_vport_create_req_sanity_check()
496 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost); in qla24xx_create_vhost()
497 struct qla_hw_data *ha = base_vha->hw; in qla24xx_create_vhost()
509 vha->irq_offset = QLA_BASE_VECTORS; in qla24xx_create_vhost()
510 host = vha->host; in qla24xx_create_vhost()
511 fc_vport->dd_data = vha; in qla24xx_create_vhost()
513 u64_to_wwn(fc_vport->node_name, vha->node_name); in qla24xx_create_vhost()
514 u64_to_wwn(fc_vport->port_name, vha->port_name); in qla24xx_create_vhost()
516 vha->fc_vport = fc_vport; in qla24xx_create_vhost()
517 vha->device_flags = 0; in qla24xx_create_vhost()
518 vha->vp_idx = qla24xx_allocate_vp_id(vha); in qla24xx_create_vhost()
519 if (vha->vp_idx > ha->max_npiv_vports) { in qla24xx_create_vhost()
524 vha->mgmt_svr_loop_id = qla2x00_reserve_mgmt_server_loop_id(vha); in qla24xx_create_vhost()
526 vha->dpc_flags = 0L; in qla24xx_create_vhost()
527 ha->dpc_active = 0; in qla24xx_create_vhost()
528 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags); in qla24xx_create_vhost()
529 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags); in qla24xx_create_vhost()
535 set_bit(VP_SCR_NEEDED, &vha->vp_flags); in qla24xx_create_vhost()
536 atomic_set(&vha->loop_state, LOOP_DOWN); in qla24xx_create_vhost()
537 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); in qla24xx_create_vhost()
541 vha->req = base_vha->req; in qla24xx_create_vhost()
542 vha->flags.nvme_enabled = base_vha->flags.nvme_enabled; in qla24xx_create_vhost()
543 host->can_queue = base_vha->req->length + 128; in qla24xx_create_vhost()
544 host->cmd_per_lun = 3; in qla24xx_create_vhost()
546 host->max_cmd_len = 32; in qla24xx_create_vhost()
548 host->max_cmd_len = MAX_CMDSZ; in qla24xx_create_vhost()
549 host->max_channel = MAX_BUSES - 1; in qla24xx_create_vhost()
550 host->max_lun = ql2xmaxlun; in qla24xx_create_vhost()
551 host->unique_id = host->host_no; in qla24xx_create_vhost()
552 host->max_id = ha->max_fibre_devices; in qla24xx_create_vhost()
553 host->transportt = qla2xxx_transport_vport_template; in qla24xx_create_vhost()
556 "Detect vport hba %ld at address = %p.\n", in qla24xx_create_vhost()
557 vha->host_no, vha); in qla24xx_create_vhost()
559 vha->flags.init_done = 1; in qla24xx_create_vhost()
561 mutex_lock(&ha->vport_lock); in qla24xx_create_vhost()
562 set_bit(vha->vp_idx, ha->vp_idx_map); in qla24xx_create_vhost()
563 ha->cur_vport_count++; in qla24xx_create_vhost()
564 mutex_unlock(&ha->vport_lock); in qla24xx_create_vhost()
575 struct qla_hw_data *ha = vha->hw; in qla25xx_free_req_que()
576 uint16_t que_id = req->id; in qla25xx_free_req_que()
578 dma_free_coherent(&ha->pdev->dev, (req->length + 1) * in qla25xx_free_req_que()
579 sizeof(request_t), req->ring, req->dma); in qla25xx_free_req_que()
580 req->ring = NULL; in qla25xx_free_req_que()
581 req->dma = 0; in qla25xx_free_req_que()
583 ha->req_q_map[que_id] = NULL; in qla25xx_free_req_que()
584 mutex_lock(&ha->vport_lock); in qla25xx_free_req_que()
585 clear_bit(que_id, ha->req_qid_map); in qla25xx_free_req_que()
586 mutex_unlock(&ha->vport_lock); in qla25xx_free_req_que()
588 kfree(req->outstanding_cmds); in qla25xx_free_req_que()
595 struct qla_hw_data *ha = vha->hw; in qla25xx_free_rsp_que()
596 uint16_t que_id = rsp->id; in qla25xx_free_rsp_que()
598 if (rsp->msix && rsp->msix->have_irq) { in qla25xx_free_rsp_que()
599 free_irq(rsp->msix->vector, rsp->msix->handle); in qla25xx_free_rsp_que()
600 rsp->msix->have_irq = 0; in qla25xx_free_rsp_que()
601 rsp->msix->in_use = 0; in qla25xx_free_rsp_que()
602 rsp->msix->handle = NULL; in qla25xx_free_rsp_que()
604 dma_free_coherent(&ha->pdev->dev, (rsp->length + 1) * in qla25xx_free_rsp_que()
605 sizeof(response_t), rsp->ring, rsp->dma); in qla25xx_free_rsp_que()
606 rsp->ring = NULL; in qla25xx_free_rsp_que()
607 rsp->dma = 0; in qla25xx_free_rsp_que()
609 ha->rsp_q_map[que_id] = NULL; in qla25xx_free_rsp_que()
610 mutex_lock(&ha->vport_lock); in qla25xx_free_rsp_que()
611 clear_bit(que_id, ha->rsp_qid_map); in qla25xx_free_rsp_que()
612 mutex_unlock(&ha->vport_lock); in qla25xx_free_rsp_que()
622 if (req && vha->flags.qpairs_req_created) { in qla25xx_delete_req_que()
623 req->options |= BIT_0; in qla25xx_delete_req_que()
639 if (rsp && vha->flags.qpairs_rsp_created) { in qla25xx_delete_rsp_que()
640 rsp->options |= BIT_0; in qla25xx_delete_rsp_que()
658 struct qla_hw_data *ha = vha->hw; in qla25xx_delete_queues()
662 list_for_each_entry_safe(qpair, tqpair, &vha->qp_list, in qla25xx_delete_queues()
667 for (cnt = 1; cnt < ha->max_req_queues; cnt++) { in qla25xx_delete_queues()
668 req = ha->req_q_map[cnt]; in qla25xx_delete_queues()
669 if (req && test_bit(cnt, ha->req_qid_map)) { in qla25xx_delete_queues()
674 req->id); in qla25xx_delete_queues()
681 for (cnt = 1; cnt < ha->max_rsp_queues; cnt++) { in qla25xx_delete_queues()
682 rsp = ha->rsp_q_map[cnt]; in qla25xx_delete_queues()
683 if (rsp && test_bit(cnt, ha->rsp_qid_map)) { in qla25xx_delete_queues()
688 rsp->id); in qla25xx_delete_queues()
704 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); in qla25xx_create_req_que()
705 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev); in qla25xx_create_req_que()
717 req->length = REQUEST_ENTRY_CNT_24XX; in qla25xx_create_req_que()
718 req->ring = dma_alloc_coherent(&ha->pdev->dev, in qla25xx_create_req_que()
719 (req->length + 1) * sizeof(request_t), in qla25xx_create_req_que()
720 &req->dma, GFP_KERNEL); in qla25xx_create_req_que()
721 if (req->ring == NULL) { in qla25xx_create_req_que()
731 mutex_lock(&ha->mq_lock); in qla25xx_create_req_que()
732 que_id = find_first_zero_bit(ha->req_qid_map, ha->max_req_queues); in qla25xx_create_req_que()
733 if (que_id >= ha->max_req_queues) { in qla25xx_create_req_que()
734 mutex_unlock(&ha->mq_lock); in qla25xx_create_req_que()
739 set_bit(que_id, ha->req_qid_map); in qla25xx_create_req_que()
740 ha->req_q_map[que_id] = req; in qla25xx_create_req_que()
741 req->rid = rid; in qla25xx_create_req_que()
742 req->vp_idx = vp_idx; in qla25xx_create_req_que()
743 req->qos = qos; in qla25xx_create_req_que()
747 que_id, req->rid, req->vp_idx, req->qos); in qla25xx_create_req_que()
750 que_id, req->rid, req->vp_idx, req->qos); in qla25xx_create_req_que()
752 req->rsp = NULL; in qla25xx_create_req_que()
754 req->rsp = ha->rsp_q_map[rsp_que]; in qla25xx_create_req_que()
756 if (MSB(req->rid)) in qla25xx_create_req_que()
759 if (LSB(req->rid)) in qla25xx_create_req_que()
761 req->options = options; in qla25xx_create_req_que()
764 "options=0x%x.\n", req->options); in qla25xx_create_req_que()
766 "options=0x%x.\n", req->options); in qla25xx_create_req_que()
767 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) in qla25xx_create_req_que()
768 req->outstanding_cmds[cnt] = NULL; in qla25xx_create_req_que()
769 req->current_outstanding_cmd = 1; in qla25xx_create_req_que()
771 req->ring_ptr = req->ring; in qla25xx_create_req_que()
772 req->ring_index = 0; in qla25xx_create_req_que()
773 req->cnt = req->length; in qla25xx_create_req_que()
774 req->id = que_id; in qla25xx_create_req_que()
776 req->req_q_in = &reg->isp25mq.req_q_in; in qla25xx_create_req_que()
777 req->req_q_out = &reg->isp25mq.req_q_out; in qla25xx_create_req_que()
778 req->max_q_depth = ha->req_q_map[0]->max_q_depth; in qla25xx_create_req_que()
779 req->out_ptr = (uint16_t *)(req->ring + req->length); in qla25xx_create_req_que()
780 mutex_unlock(&ha->mq_lock); in qla25xx_create_req_que()
782 "ring_ptr=%p ring_index=%d, " in qla25xx_create_req_que()
784 req->ring_ptr, req->ring_index, in qla25xx_create_req_que()
785 req->cnt, req->id, req->max_q_depth); in qla25xx_create_req_que()
787 "ring_ptr=%p ring_index=%d, " in qla25xx_create_req_que()
789 req->ring_ptr, req->ring_index, req->cnt, in qla25xx_create_req_que()
790 req->id, req->max_q_depth); in qla25xx_create_req_que()
797 mutex_lock(&ha->mq_lock); in qla25xx_create_req_que()
798 clear_bit(que_id, ha->req_qid_map); in qla25xx_create_req_que()
799 mutex_unlock(&ha->mq_lock); in qla25xx_create_req_que()
802 vha->flags.qpairs_req_created = 1; in qla25xx_create_req_que()
805 return req->id; in qla25xx_create_req_que()
817 struct scsi_qla_host *vha = qpair->vha; in qla_do_work()
819 spin_lock_irqsave(&qpair->qp_lock, flags); in qla_do_work()
820 qla24xx_process_response_queue(vha, qpair->rsp); in qla_do_work()
821 spin_unlock_irqrestore(&qpair->qp_lock, flags); in qla_do_work()
832 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); in qla25xx_create_rsp_que()
833 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev); in qla25xx_create_rsp_que()
844 rsp->length = RESPONSE_ENTRY_CNT_MQ; in qla25xx_create_rsp_que()
845 rsp->ring = dma_alloc_coherent(&ha->pdev->dev, in qla25xx_create_rsp_que()
846 (rsp->length + 1) * sizeof(response_t), in qla25xx_create_rsp_que()
847 &rsp->dma, GFP_KERNEL); in qla25xx_create_rsp_que()
848 if (rsp->ring == NULL) { in qla25xx_create_rsp_que()
854 mutex_lock(&ha->mq_lock); in qla25xx_create_rsp_que()
855 que_id = find_first_zero_bit(ha->rsp_qid_map, ha->max_rsp_queues); in qla25xx_create_rsp_que()
856 if (que_id >= ha->max_rsp_queues) { in qla25xx_create_rsp_que()
857 mutex_unlock(&ha->mq_lock); in qla25xx_create_rsp_que()
862 set_bit(que_id, ha->rsp_qid_map); in qla25xx_create_rsp_que()
864 rsp->msix = qpair->msix; in qla25xx_create_rsp_que()
866 ha->rsp_q_map[que_id] = rsp; in qla25xx_create_rsp_que()
867 rsp->rid = rid; in qla25xx_create_rsp_que()
868 rsp->vp_idx = vp_idx; in qla25xx_create_rsp_que()
869 rsp->hw = ha; in qla25xx_create_rsp_que()
871 "rsp queue_id=%d rid=%d vp_idx=%d hw=%p.\n", in qla25xx_create_rsp_que()
872 que_id, rsp->rid, rsp->vp_idx, rsp->hw); in qla25xx_create_rsp_que()
874 if (MSB(rsp->rid)) in qla25xx_create_rsp_que()
877 if (LSB(rsp->rid)) in qla25xx_create_rsp_que()
886 rsp->options = options; in qla25xx_create_rsp_que()
887 rsp->id = que_id; in qla25xx_create_rsp_que()
889 rsp->rsp_q_in = &reg->isp25mq.rsp_q_in; in qla25xx_create_rsp_que()
890 rsp->rsp_q_out = &reg->isp25mq.rsp_q_out; in qla25xx_create_rsp_que()
891 rsp->in_ptr = (uint16_t *)(rsp->ring + rsp->length); in qla25xx_create_rsp_que()
892 mutex_unlock(&ha->mq_lock); in qla25xx_create_rsp_que()
894 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p\n", in qla25xx_create_rsp_que()
895 rsp->options, rsp->id, rsp->rsp_q_in, in qla25xx_create_rsp_que()
896 rsp->rsp_q_out); in qla25xx_create_rsp_que()
898 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p\n", in qla25xx_create_rsp_que()
899 rsp->options, rsp->id, rsp->rsp_q_in, in qla25xx_create_rsp_que()
900 rsp->rsp_q_out); in qla25xx_create_rsp_que()
902 ret = qla25xx_request_irq(ha, qpair, qpair->msix, in qla25xx_create_rsp_que()
903 ha->flags.disable_msix_handshake ? in qla25xx_create_rsp_que()
913 mutex_lock(&ha->mq_lock); in qla25xx_create_rsp_que()
914 clear_bit(que_id, ha->rsp_qid_map); in qla25xx_create_rsp_que()
915 mutex_unlock(&ha->mq_lock); in qla25xx_create_rsp_que()
918 vha->flags.qpairs_rsp_created = 1; in qla25xx_create_rsp_que()
920 rsp->req = NULL; in qla25xx_create_rsp_que()
923 if (qpair->hw->wq) in qla25xx_create_rsp_que()
924 INIT_WORK(&qpair->q_work, qla_do_work); in qla25xx_create_rsp_que()
925 return rsp->id; in qla25xx_create_rsp_que()
935 if (sp->comp) in qla_ctrlvp_sp_done()
936 complete(sp->comp); in qla_ctrlvp_sp_done()
941 * qla24xx_control_vp() - Enable a virtual port for given host
950 struct qla_hw_data *ha = vha->hw; in qla24xx_control_vp()
951 int vp_index = vha->vp_idx; in qla24xx_control_vp()
952 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); in qla24xx_control_vp()
959 if (vp_index == 0 || vp_index >= ha->max_npiv_vports) in qla24xx_control_vp()
967 sp->type = SRB_CTRL_VP; in qla24xx_control_vp()
968 sp->name = "ctrl_vp"; in qla24xx_control_vp()
969 sp->comp = &comp; in qla24xx_control_vp()
972 sp->u.iocb_cmd.u.ctrlvp.cmd = cmd; in qla24xx_control_vp()
973 sp->u.iocb_cmd.u.ctrlvp.vp_index = vp_index; in qla24xx_control_vp()
979 __func__, sp->name, rval); in qla24xx_control_vp()
984 sp->name, sp->handle); in qla24xx_control_vp()
987 sp->comp = NULL; in qla24xx_control_vp()
989 rval = sp->rc; in qla24xx_control_vp()
993 __func__, sp->name, rval); in qla24xx_control_vp()
997 __func__, sp->name); in qla24xx_control_vp()
1001 __func__, sp->name, rval); in qla24xx_control_vp()
1006 kref_put(&sp->cmd_kref, qla2x00_sp_release); in qla24xx_control_vp()
1012 struct qla_hw_data *ha = vha->hw; in qla_find_host_by_vp_idx()
1014 if (vha->vp_idx == vp_idx) in qla_find_host_by_vp_idx()
1017 BUG_ON(ha->vp_map == NULL); in qla_find_host_by_vp_idx()
1018 if (likely(test_bit(vp_idx, ha->vp_idx_map))) in qla_find_host_by_vp_idx()
1019 return ha->vp_map[vp_idx].vha; in qla_find_host_by_vp_idx()
1032 if (!vha->hw->vp_map) in qla_update_vp_map()
1035 key = vha->d_id.b24; in qla_update_vp_map()
1039 vha->hw->vp_map[vha->vp_idx].vha = vha; in qla_update_vp_map()
1042 slot = btree_lookup32(&vha->hw->host_map, key); in qla_update_vp_map()
1045 "Save vha in host_map %p %06x\n", vha, key); in qla_update_vp_map()
1046 rc = btree_insert32(&vha->hw->host_map, in qla_update_vp_map()
1055 "replace existing vha in host_map %p %06x\n", vha, key); in qla_update_vp_map()
1056 btree_update32(&vha->hw->host_map, key, vha); in qla_update_vp_map()
1059 vha->hw->vp_map[vha->vp_idx].vha = NULL; in qla_update_vp_map()
1063 "clear vha in host_map %p %06x\n", vha, key); in qla_update_vp_map()
1064 slot = btree_lookup32(&vha->hw->host_map, key); in qla_update_vp_map()
1066 btree_remove32(&vha->hw->host_map, key); in qla_update_vp_map()
1067 vha->d_id.b24 = 0; in qla_update_vp_map()
1075 if (!vha->d_id.b24) { in qla_update_host_map()
1076 vha->d_id = id; in qla_update_host_map()
1078 } else if (vha->d_id.b24 != id.b24) { in qla_update_host_map()
1080 vha->d_id = id; in qla_update_host_map()
1089 qp->buf_pool.num_bufs = qp->req->length; in qla_create_buf_pool()
1091 sz = BITS_TO_LONGS(qp->req->length); in qla_create_buf_pool()
1092 qp->buf_pool.buf_map = kcalloc(sz, sizeof(long), GFP_KERNEL); in qla_create_buf_pool()
1093 if (!qp->buf_pool.buf_map) { in qla_create_buf_pool()
1096 return -ENOMEM; in qla_create_buf_pool()
1098 sz = qp->req->length * sizeof(void *); in qla_create_buf_pool()
1099 qp->buf_pool.buf_array = kcalloc(qp->req->length, sizeof(void *), GFP_KERNEL); in qla_create_buf_pool()
1100 if (!qp->buf_pool.buf_array) { in qla_create_buf_pool()
1103 kfree(qp->buf_pool.buf_map); in qla_create_buf_pool()
1104 return -ENOMEM; in qla_create_buf_pool()
1106 sz = qp->req->length * sizeof(dma_addr_t); in qla_create_buf_pool()
1107 qp->buf_pool.dma_array = kcalloc(qp->req->length, sizeof(dma_addr_t), GFP_KERNEL); in qla_create_buf_pool()
1108 if (!qp->buf_pool.dma_array) { in qla_create_buf_pool()
1111 kfree(qp->buf_pool.buf_map); in qla_create_buf_pool()
1112 kfree(qp->buf_pool.buf_array); in qla_create_buf_pool()
1113 return -ENOMEM; in qla_create_buf_pool()
1115 set_bit(0, qp->buf_pool.buf_map); in qla_create_buf_pool()
1122 struct qla_hw_data *ha = qp->vha->hw; in qla_free_buf_pool()
1124 for (i = 0; i < qp->buf_pool.num_bufs; i++) { in qla_free_buf_pool()
1125 if (qp->buf_pool.buf_array[i] && qp->buf_pool.dma_array[i]) in qla_free_buf_pool()
1126 dma_pool_free(ha->fcp_cmnd_dma_pool, qp->buf_pool.buf_array[i], in qla_free_buf_pool()
1127 qp->buf_pool.dma_array[i]); in qla_free_buf_pool()
1128 qp->buf_pool.buf_array[i] = NULL; in qla_free_buf_pool()
1129 qp->buf_pool.dma_array[i] = 0; in qla_free_buf_pool()
1132 kfree(qp->buf_pool.dma_array); in qla_free_buf_pool()
1133 kfree(qp->buf_pool.buf_array); in qla_free_buf_pool()
1134 kfree(qp->buf_pool.buf_map); in qla_free_buf_pool()
1137 /* it is assume qp->qp_lock is held at this point */
1143 struct qla_hw_data *ha = vha->hw; in qla_get_buf()
1145 dsc->tag = TAG_FREED; in qla_get_buf()
1147 tag = find_first_zero_bit(qp->buf_pool.buf_map, qp->buf_pool.num_bufs); in qla_get_buf()
1148 if (tag >= qp->buf_pool.num_bufs) { in qla_get_buf()
1150 "qp(%d) ran out of buf resource.\n", qp->id); in qla_get_buf()
1151 return -EIO; in qla_get_buf()
1154 set_bit(0, qp->buf_pool.buf_map); in qla_get_buf()
1158 "qp(%d) unable to get tag.\n", qp->id); in qla_get_buf()
1159 return -EIO; in qla_get_buf()
1164 if (!qp->buf_pool.buf_array[tag]) { in qla_get_buf()
1165 buf = dma_pool_zalloc(ha->fcp_cmnd_dma_pool, GFP_ATOMIC, &buf_dma); in qla_get_buf()
1169 return -ENOMEM; in qla_get_buf()
1172 dsc->buf = qp->buf_pool.buf_array[tag] = buf; in qla_get_buf()
1173 dsc->buf_dma = qp->buf_pool.dma_array[tag] = buf_dma; in qla_get_buf()
1174 qp->buf_pool.num_alloc++; in qla_get_buf()
1176 dsc->buf = qp->buf_pool.buf_array[tag]; in qla_get_buf()
1177 dsc->buf_dma = qp->buf_pool.dma_array[tag]; in qla_get_buf()
1178 memset(dsc->buf, 0, FCP_CMND_DMA_POOL_SIZE); in qla_get_buf()
1181 qp->buf_pool.num_active++; in qla_get_buf()
1182 if (qp->buf_pool.num_active > qp->buf_pool.max_used) in qla_get_buf()
1183 qp->buf_pool.max_used = qp->buf_pool.num_active; in qla_get_buf()
1185 dsc->tag = tag; in qla_get_buf()
1186 set_bit(tag, qp->buf_pool.buf_map); in qla_get_buf()
1193 struct qla_hw_data *ha = qp->vha->hw; in qla_trim_buf()
1199 j = qp->buf_pool.num_alloc - 1; in qla_trim_buf()
1200 if (test_bit(j, qp->buf_pool.buf_map)) { in qla_trim_buf()
1201 ql_dbg(ql_dbg_io + ql_dbg_verbose, qp->vha, 0x300b, in qla_trim_buf()
1203 qp->id, j, qp->buf_pool.num_alloc); in qla_trim_buf()
1207 if (qp->buf_pool.buf_array[j]) { in qla_trim_buf()
1208 dma_pool_free(ha->fcp_cmnd_dma_pool, qp->buf_pool.buf_array[j], in qla_trim_buf()
1209 qp->buf_pool.dma_array[j]); in qla_trim_buf()
1210 qp->buf_pool.buf_array[j] = NULL; in qla_trim_buf()
1211 qp->buf_pool.dma_array[j] = 0; in qla_trim_buf()
1213 qp->buf_pool.num_alloc--; in qla_trim_buf()
1214 if (!qp->buf_pool.num_alloc) in qla_trim_buf()
1217 ql_dbg(ql_dbg_io + ql_dbg_verbose, qp->vha, 0x3010, in qla_trim_buf()
1219 qp->id, trim, qp->buf_pool.num_alloc); in qla_trim_buf()
1226 qp->buf_pool.take_snapshot = 0; in __qla_adjust_buf()
1227 qp->buf_pool.prev_max = qp->buf_pool.max_used; in __qla_adjust_buf()
1228 qp->buf_pool.max_used = qp->buf_pool.num_active; in __qla_adjust_buf()
1230 if (qp->buf_pool.prev_max > qp->buf_pool.max_used && in __qla_adjust_buf()
1231 qp->buf_pool.num_alloc > qp->buf_pool.max_used) { in __qla_adjust_buf()
1233 trim = qp->buf_pool.num_alloc - qp->buf_pool.max_used; in __qla_adjust_buf()
1237 } else if (!qp->buf_pool.prev_max && !qp->buf_pool.max_used) { in __qla_adjust_buf()
1239 qla_trim_buf(qp, qp->buf_pool.num_alloc); in __qla_adjust_buf()
1243 /* it is assume qp->qp_lock is held at this point */
1246 if (dsc->tag == TAG_FREED) in qla_put_buf()
1248 lockdep_assert_held(qp->qp_lock_ptr); in qla_put_buf()
1250 clear_bit(dsc->tag, qp->buf_pool.buf_map); in qla_put_buf()
1251 qp->buf_pool.num_active--; in qla_put_buf()
1252 dsc->tag = TAG_FREED; in qla_put_buf()
1254 if (qp->buf_pool.take_snapshot) in qla_put_buf()
1265 if (vha->vp_idx) in qla_adjust_buf()
1268 if (!vha->buf_expired) { in qla_adjust_buf()
1269 vha->buf_expired = jiffies + EXPIRE; in qla_adjust_buf()
1272 if (time_before(jiffies, vha->buf_expired)) in qla_adjust_buf()
1275 vha->buf_expired = jiffies + EXPIRE; in qla_adjust_buf()
1277 for (i = 0; i < vha->hw->num_qpairs; i++) { in qla_adjust_buf()
1278 qp = vha->hw->queue_pair_map[i]; in qla_adjust_buf()
1281 if (!qp->buf_pool.num_alloc) in qla_adjust_buf()
1284 if (qp->buf_pool.take_snapshot) { in qla_adjust_buf()
1286 spin_lock_irqsave(qp->qp_lock_ptr, flags); in qla_adjust_buf()
1288 spin_unlock_irqrestore(qp->qp_lock_ptr, flags); in qla_adjust_buf()
1290 qp->buf_pool.take_snapshot = 1; in qla_adjust_buf()