1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic Fibre Channel HBA Driver
4 * Copyright (c) 2003-2014 QLogic Corporation
8 #include "qla_target.h"
10 #include <linux/moduleparam.h>
11 #include <linux/vmalloc.h>
12 #include <linux/slab.h>
13 #include <linux/list.h>
15 #include <scsi/scsi_tcq.h>
16 #include <scsi/scsicam.h>
17 #include <linux/delay.h>
20 qla2x00_vp_stop_timer(scsi_qla_host_t *vha)
22 if (vha->vp_idx && vha->timer_active) {
23 del_timer_sync(&vha->timer);
24 vha->timer_active = 0;
29 qla24xx_allocate_vp_id(scsi_qla_host_t *vha)
32 struct qla_hw_data *ha = vha->hw;
35 /* Find an empty slot and assign an vp_id */
36 mutex_lock(&ha->vport_lock);
37 vp_id = find_first_zero_bit(ha->vp_idx_map, ha->max_npiv_vports + 1);
38 if (vp_id > ha->max_npiv_vports) {
39 ql_dbg(ql_dbg_vport, vha, 0xa000,
40 "vp_id %d is bigger than max-supported %d.\n",
41 vp_id, ha->max_npiv_vports);
42 mutex_unlock(&ha->vport_lock);
46 set_bit(vp_id, ha->vp_idx_map);
50 spin_lock_irqsave(&ha->vport_slock, flags);
51 list_add_tail(&vha->list, &ha->vp_list);
52 spin_unlock_irqrestore(&ha->vport_slock, flags);
54 spin_lock_irqsave(&ha->hardware_lock, flags);
55 qlt_update_vp_map(vha, SET_VP_IDX);
56 spin_unlock_irqrestore(&ha->hardware_lock, flags);
58 mutex_unlock(&ha->vport_lock);
63 qla24xx_deallocate_vp_id(scsi_qla_host_t *vha)
66 struct qla_hw_data *ha = vha->hw;
67 unsigned long flags = 0;
70 mutex_lock(&ha->vport_lock);
72 * Wait for all pending activities to finish before removing vport from
74 * Lock needs to be held for safe removal from the list (it
75 * ensures no active vp_list traversal while the vport is removed
79 for (i = 0; i < 500; i++) {
80 spin_lock_irqsave(&ha->vport_slock, flags);
81 if (atomic_read(&vha->vref_count) == 0) {
83 qlt_update_vp_map(vha, RESET_VP_IDX);
86 spin_unlock_irqrestore(&ha->vport_slock, flags);
94 ql_log(ql_log_info, vha, 0xfffa,
95 "vha->vref_count=%u timeout\n", vha->vref_count.counter);
96 spin_lock_irqsave(&ha->vport_slock, flags);
98 qlt_update_vp_map(vha, RESET_VP_IDX);
99 spin_unlock_irqrestore(&ha->vport_slock, flags);
104 clear_bit(vp_id, ha->vp_idx_map);
106 mutex_unlock(&ha->vport_lock);
109 static scsi_qla_host_t *
110 qla24xx_find_vhost_by_name(struct qla_hw_data *ha, uint8_t *port_name)
112 scsi_qla_host_t *vha;
113 struct scsi_qla_host *tvha;
116 spin_lock_irqsave(&ha->vport_slock, flags);
117 /* Locate matching device in database. */
118 list_for_each_entry_safe(vha, tvha, &ha->vp_list, list) {
119 if (!memcmp(port_name, vha->port_name, WWN_SIZE)) {
120 spin_unlock_irqrestore(&ha->vport_slock, flags);
124 spin_unlock_irqrestore(&ha->vport_slock, flags);
129 * qla2x00_mark_vp_devices_dead
130 * Updates fcport state when device goes offline.
133 * ha = adapter block pointer.
134 * fcport = port structure pointer.
142 qla2x00_mark_vp_devices_dead(scsi_qla_host_t *vha)
146 * This function, if called in contexts other than vp create, disable
147 * or delete, please make sure this is synchronized with the
152 list_for_each_entry(fcport, &vha->vp_fcports, list) {
153 ql_dbg(ql_dbg_vport, vha, 0xa001,
154 "Marking port dead, loop_id=0x%04x : %x.\n",
155 fcport->loop_id, fcport->vha->vp_idx);
157 qla2x00_mark_device_lost(vha, fcport, 0);
158 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
163 qla24xx_disable_vp(scsi_qla_host_t *vha)
166 int ret = QLA_SUCCESS;
169 if (vha->hw->flags.edif_enabled)
170 /* delete sessions and flush sa_indexes */
171 qla2x00_wait_for_sess_deletion(vha);
173 if (vha->hw->flags.fw_started)
174 ret = qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
176 atomic_set(&vha->loop_state, LOOP_DOWN);
177 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
178 list_for_each_entry(fcport, &vha->vp_fcports, list)
179 fcport->logout_on_delete = 0;
181 if (!vha->hw->flags.edif_enabled)
182 qla2x00_wait_for_sess_deletion(vha);
184 /* Remove port id from vp target map */
185 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
186 qlt_update_vp_map(vha, RESET_AL_PA);
187 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
189 qla2x00_mark_vp_devices_dead(vha);
190 atomic_set(&vha->vp_state, VP_FAILED);
191 vha->flags.management_server_logged_in = 0;
192 if (ret == QLA_SUCCESS) {
193 fc_vport_set_state(vha->fc_vport, FC_VPORT_DISABLED);
195 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
202 qla24xx_enable_vp(scsi_qla_host_t *vha)
205 struct qla_hw_data *ha = vha->hw;
206 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
208 /* Check if physical ha port is Up */
209 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
210 atomic_read(&base_vha->loop_state) == LOOP_DEAD ||
211 !(ha->current_topology & ISP_CFG_F)) {
212 vha->vp_err_state = VP_ERR_PORTDWN;
213 fc_vport_set_state(vha->fc_vport, FC_VPORT_LINKDOWN);
214 ql_dbg(ql_dbg_taskm, vha, 0x800b,
215 "%s skip enable. loop_state %x topo %x\n",
216 __func__, base_vha->loop_state.counter,
217 ha->current_topology);
222 /* Initialize the new vport unless it is a persistent port */
223 mutex_lock(&ha->vport_lock);
224 ret = qla24xx_modify_vp_config(vha);
225 mutex_unlock(&ha->vport_lock);
227 if (ret != QLA_SUCCESS) {
228 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
232 ql_dbg(ql_dbg_taskm, vha, 0x801a,
233 "Virtual port with id: %d - Enabled.\n", vha->vp_idx);
237 ql_dbg(ql_dbg_taskm, vha, 0x801b,
238 "Virtual port with id: %d - Disabled.\n", vha->vp_idx);
243 qla24xx_configure_vp(scsi_qla_host_t *vha)
245 struct fc_vport *fc_vport;
248 fc_vport = vha->fc_vport;
250 ql_dbg(ql_dbg_vport, vha, 0xa002,
251 "%s: change request #3.\n", __func__);
252 ret = qla2x00_send_change_request(vha, 0x3, vha->vp_idx);
253 if (ret != QLA_SUCCESS) {
254 ql_dbg(ql_dbg_vport, vha, 0xa003, "Failed to enable "
255 "receiving of RSCN requests: 0x%x.\n", ret);
258 /* Corresponds to SCR enabled */
259 clear_bit(VP_SCR_NEEDED, &vha->vp_flags);
262 vha->flags.online = 1;
263 if (qla24xx_configure_vhba(vha))
266 atomic_set(&vha->vp_state, VP_ACTIVE);
267 fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
271 qla2x00_alert_all_vps(struct rsp_que *rsp, uint16_t *mb)
273 scsi_qla_host_t *vha, *tvp;
274 struct qla_hw_data *ha = rsp->hw;
278 spin_lock_irqsave(&ha->vport_slock, flags);
279 list_for_each_entry_safe(vha, tvp, &ha->vp_list, list) {
281 if (test_bit(VPORT_DELETE, &vha->dpc_flags))
284 atomic_inc(&vha->vref_count);
285 spin_unlock_irqrestore(&ha->vport_slock, flags);
288 case MBA_LIP_OCCURRED:
292 case MBA_POINT_TO_POINT:
293 case MBA_CHG_IN_CONNECTION:
294 ql_dbg(ql_dbg_async, vha, 0x5024,
295 "Async_event for VP[%d], mb=0x%x vha=%p.\n",
297 qla2x00_async_event(vha, rsp, mb);
299 case MBA_PORT_UPDATE:
300 case MBA_RSCN_UPDATE:
301 if ((mb[3] & 0xff) == vha->vp_idx) {
302 ql_dbg(ql_dbg_async, vha, 0x5024,
303 "Async_event for VP[%d], mb=0x%x vha=%p\n",
305 qla2x00_async_event(vha, rsp, mb);
310 spin_lock_irqsave(&ha->vport_slock, flags);
311 atomic_dec(&vha->vref_count);
312 wake_up(&vha->vref_waitq);
316 spin_unlock_irqrestore(&ha->vport_slock, flags);
320 qla2x00_vp_abort_isp(scsi_qla_host_t *vha)
325 * To exclusively reset vport, we need to log it out first.
326 * Note: This control_vp can fail if ISP reset is already
327 * issued, this is expected, as the vp would be already
328 * logged out due to ISP reset.
330 if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
331 qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
332 list_for_each_entry(fcport, &vha->vp_fcports, list)
333 fcport->logout_on_delete = 0;
337 * Physical port will do most of the abort and recovery work. We can
338 * just treat it as a loop down
340 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
341 atomic_set(&vha->loop_state, LOOP_DOWN);
342 qla2x00_mark_all_devices_lost(vha);
344 if (!atomic_read(&vha->loop_down_timer))
345 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
348 ql_dbg(ql_dbg_taskm, vha, 0x801d,
349 "Scheduling enable of Vport %d.\n", vha->vp_idx);
351 return qla24xx_enable_vp(vha);
355 qla2x00_do_dpc_vp(scsi_qla_host_t *vha)
357 struct qla_hw_data *ha = vha->hw;
358 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
360 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, vha, 0x4012,
361 "Entering %s vp_flags: 0x%lx.\n", __func__, vha->vp_flags);
363 /* Check if Fw is ready to configure VP first */
364 if (test_bit(VP_CONFIG_OK, &base_vha->vp_flags)) {
365 if (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) {
366 /* VP acquired. complete port configuration */
367 ql_dbg(ql_dbg_dpc, vha, 0x4014,
368 "Configure VP scheduled.\n");
369 qla24xx_configure_vp(vha);
370 ql_dbg(ql_dbg_dpc, vha, 0x4015,
371 "Configure VP end.\n");
376 if (test_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags)) {
377 if (atomic_read(&vha->loop_state) == LOOP_READY) {
378 qla24xx_process_purex_list(&vha->purex_list);
379 clear_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags);
383 if (test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) {
384 ql_dbg(ql_dbg_dpc, vha, 0x4016,
385 "FCPort update scheduled.\n");
386 qla2x00_update_fcports(vha);
387 clear_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
388 ql_dbg(ql_dbg_dpc, vha, 0x4017,
389 "FCPort update end.\n");
392 if (test_bit(RELOGIN_NEEDED, &vha->dpc_flags) &&
393 !test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) &&
394 atomic_read(&vha->loop_state) != LOOP_DOWN) {
396 if (!vha->relogin_jif ||
397 time_after_eq(jiffies, vha->relogin_jif)) {
398 vha->relogin_jif = jiffies + HZ;
399 clear_bit(RELOGIN_NEEDED, &vha->dpc_flags);
401 ql_dbg(ql_dbg_dpc, vha, 0x4018,
402 "Relogin needed scheduled.\n");
403 qla24xx_post_relogin_work(vha);
407 if (test_and_clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) &&
408 (!(test_and_set_bit(RESET_ACTIVE, &vha->dpc_flags)))) {
409 clear_bit(RESET_ACTIVE, &vha->dpc_flags);
412 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
413 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))) {
414 ql_dbg(ql_dbg_dpc, vha, 0x401a,
415 "Loop resync scheduled.\n");
416 qla2x00_loop_resync(vha);
417 clear_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags);
418 ql_dbg(ql_dbg_dpc, vha, 0x401b,
419 "Loop resync end.\n");
423 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, vha, 0x401c,
424 "Exiting %s.\n", __func__);
429 qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha)
431 struct qla_hw_data *ha = vha->hw;
432 scsi_qla_host_t *vp, *tvp;
433 unsigned long flags = 0;
437 if (list_empty(&ha->vp_list))
440 clear_bit(VP_DPC_NEEDED, &vha->dpc_flags);
442 if (!(ha->current_topology & ISP_CFG_F))
445 spin_lock_irqsave(&ha->vport_slock, flags);
446 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
448 atomic_inc(&vp->vref_count);
449 spin_unlock_irqrestore(&ha->vport_slock, flags);
451 qla2x00_do_dpc_vp(vp);
453 spin_lock_irqsave(&ha->vport_slock, flags);
454 atomic_dec(&vp->vref_count);
457 spin_unlock_irqrestore(&ha->vport_slock, flags);
461 qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport)
463 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
464 struct qla_hw_data *ha = base_vha->hw;
465 scsi_qla_host_t *vha;
466 uint8_t port_name[WWN_SIZE];
468 if (fc_vport->roles != FC_PORT_ROLE_FCP_INITIATOR)
469 return VPCERR_UNSUPPORTED;
471 /* Check up the F/W and H/W support NPIV */
472 if (!ha->flags.npiv_supported)
473 return VPCERR_UNSUPPORTED;
475 /* Check up whether npiv supported switch presented */
476 if (!(ha->switch_cap & FLOGI_MID_SUPPORT))
477 return VPCERR_NO_FABRIC_SUPP;
479 /* Check up unique WWPN */
480 u64_to_wwn(fc_vport->port_name, port_name);
481 if (!memcmp(port_name, base_vha->port_name, WWN_SIZE))
482 return VPCERR_BAD_WWN;
483 vha = qla24xx_find_vhost_by_name(ha, port_name);
485 return VPCERR_BAD_WWN;
487 /* Check up max-npiv-supports */
488 if (ha->num_vhosts > ha->max_npiv_vports) {
489 ql_dbg(ql_dbg_vport, vha, 0xa004,
490 "num_vhosts %ud is bigger "
491 "than max_npiv_vports %ud.\n",
492 ha->num_vhosts, ha->max_npiv_vports);
493 return VPCERR_UNSUPPORTED;
499 qla24xx_create_vhost(struct fc_vport *fc_vport)
501 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
502 struct qla_hw_data *ha = base_vha->hw;
503 scsi_qla_host_t *vha;
504 struct scsi_host_template *sht = &qla2xxx_driver_template;
505 struct Scsi_Host *host;
507 vha = qla2x00_create_host(sht, ha);
509 ql_log(ql_log_warn, vha, 0xa005,
510 "scsi_host_alloc() failed for vport.\n");
515 fc_vport->dd_data = vha;
517 u64_to_wwn(fc_vport->node_name, vha->node_name);
518 u64_to_wwn(fc_vport->port_name, vha->port_name);
520 vha->fc_vport = fc_vport;
521 vha->device_flags = 0;
522 vha->vp_idx = qla24xx_allocate_vp_id(vha);
523 if (vha->vp_idx > ha->max_npiv_vports) {
524 ql_dbg(ql_dbg_vport, vha, 0xa006,
525 "Couldn't allocate vp_id.\n");
526 goto create_vhost_failed;
528 vha->mgmt_svr_loop_id = qla2x00_reserve_mgmt_server_loop_id(vha);
532 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
533 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
536 * To fix the issue of processing a parent's RSCN for the vport before
537 * its SCR is complete.
539 set_bit(VP_SCR_NEEDED, &vha->vp_flags);
540 atomic_set(&vha->loop_state, LOOP_DOWN);
541 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
543 qla2x00_start_timer(vha, WATCH_INTERVAL);
545 vha->req = base_vha->req;
546 vha->flags.nvme_enabled = base_vha->flags.nvme_enabled;
547 host->can_queue = base_vha->req->length + 128;
548 host->cmd_per_lun = 3;
549 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
550 host->max_cmd_len = 32;
552 host->max_cmd_len = MAX_CMDSZ;
553 host->max_channel = MAX_BUSES - 1;
554 host->max_lun = ql2xmaxlun;
555 host->unique_id = host->host_no;
556 host->max_id = ha->max_fibre_devices;
557 host->transportt = qla2xxx_transport_vport_template;
559 ql_dbg(ql_dbg_vport, vha, 0xa007,
560 "Detect vport hba %ld at address = %p.\n",
563 vha->flags.init_done = 1;
565 mutex_lock(&ha->vport_lock);
566 set_bit(vha->vp_idx, ha->vp_idx_map);
567 ha->cur_vport_count++;
568 mutex_unlock(&ha->vport_lock);
577 qla25xx_free_req_que(struct scsi_qla_host *vha, struct req_que *req)
579 struct qla_hw_data *ha = vha->hw;
580 uint16_t que_id = req->id;
582 dma_free_coherent(&ha->pdev->dev, (req->length + 1) *
583 sizeof(request_t), req->ring, req->dma);
587 ha->req_q_map[que_id] = NULL;
588 mutex_lock(&ha->vport_lock);
589 clear_bit(que_id, ha->req_qid_map);
590 mutex_unlock(&ha->vport_lock);
592 kfree(req->outstanding_cmds);
597 qla25xx_free_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
599 struct qla_hw_data *ha = vha->hw;
600 uint16_t que_id = rsp->id;
602 if (rsp->msix && rsp->msix->have_irq) {
603 free_irq(rsp->msix->vector, rsp->msix->handle);
604 rsp->msix->have_irq = 0;
605 rsp->msix->in_use = 0;
606 rsp->msix->handle = NULL;
608 dma_free_coherent(&ha->pdev->dev, (rsp->length + 1) *
609 sizeof(response_t), rsp->ring, rsp->dma);
613 ha->rsp_q_map[que_id] = NULL;
614 mutex_lock(&ha->vport_lock);
615 clear_bit(que_id, ha->rsp_qid_map);
616 mutex_unlock(&ha->vport_lock);
622 qla25xx_delete_req_que(struct scsi_qla_host *vha, struct req_que *req)
624 int ret = QLA_SUCCESS;
626 if (req && vha->flags.qpairs_req_created) {
627 req->options |= BIT_0;
628 ret = qla25xx_init_req_que(vha, req);
629 if (ret != QLA_SUCCESS)
630 return QLA_FUNCTION_FAILED;
632 qla25xx_free_req_que(vha, req);
639 qla25xx_delete_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
641 int ret = QLA_SUCCESS;
643 if (rsp && vha->flags.qpairs_rsp_created) {
644 rsp->options |= BIT_0;
645 ret = qla25xx_init_rsp_que(vha, rsp);
646 if (ret != QLA_SUCCESS)
647 return QLA_FUNCTION_FAILED;
649 qla25xx_free_rsp_que(vha, rsp);
655 /* Delete all queues for a given vhost */
657 qla25xx_delete_queues(struct scsi_qla_host *vha)
660 struct req_que *req = NULL;
661 struct rsp_que *rsp = NULL;
662 struct qla_hw_data *ha = vha->hw;
663 struct qla_qpair *qpair, *tqpair;
665 if (ql2xmqsupport || ql2xnvmeenable) {
666 list_for_each_entry_safe(qpair, tqpair, &vha->qp_list,
668 qla2xxx_delete_qpair(vha, qpair);
670 /* Delete request queues */
671 for (cnt = 1; cnt < ha->max_req_queues; cnt++) {
672 req = ha->req_q_map[cnt];
673 if (req && test_bit(cnt, ha->req_qid_map)) {
674 ret = qla25xx_delete_req_que(vha, req);
675 if (ret != QLA_SUCCESS) {
676 ql_log(ql_log_warn, vha, 0x00ea,
677 "Couldn't delete req que %d.\n",
684 /* Delete response queues */
685 for (cnt = 1; cnt < ha->max_rsp_queues; cnt++) {
686 rsp = ha->rsp_q_map[cnt];
687 if (rsp && test_bit(cnt, ha->rsp_qid_map)) {
688 ret = qla25xx_delete_rsp_que(vha, rsp);
689 if (ret != QLA_SUCCESS) {
690 ql_log(ql_log_warn, vha, 0x00eb,
691 "Couldn't delete rsp que %d.\n",
703 qla25xx_create_req_que(struct qla_hw_data *ha, uint16_t options,
704 uint8_t vp_idx, uint16_t rid, int rsp_que, uint8_t qos, bool startqp)
707 struct req_que *req = NULL;
708 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
709 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
714 req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
716 ql_log(ql_log_fatal, base_vha, 0x00d9,
717 "Failed to allocate memory for request queue.\n");
721 req->length = REQUEST_ENTRY_CNT_24XX;
722 req->ring = dma_alloc_coherent(&ha->pdev->dev,
723 (req->length + 1) * sizeof(request_t),
724 &req->dma, GFP_KERNEL);
725 if (req->ring == NULL) {
726 ql_log(ql_log_fatal, base_vha, 0x00da,
727 "Failed to allocate memory for request_ring.\n");
731 ret = qla2x00_alloc_outstanding_cmds(ha, req);
732 if (ret != QLA_SUCCESS)
735 mutex_lock(&ha->mq_lock);
736 que_id = find_first_zero_bit(ha->req_qid_map, ha->max_req_queues);
737 if (que_id >= ha->max_req_queues) {
738 mutex_unlock(&ha->mq_lock);
739 ql_log(ql_log_warn, base_vha, 0x00db,
740 "No resources to create additional request queue.\n");
743 set_bit(que_id, ha->req_qid_map);
744 ha->req_q_map[que_id] = req;
746 req->vp_idx = vp_idx;
749 ql_dbg(ql_dbg_multiq, base_vha, 0xc002,
750 "queue_id=%d rid=%d vp_idx=%d qos=%d.\n",
751 que_id, req->rid, req->vp_idx, req->qos);
752 ql_dbg(ql_dbg_init, base_vha, 0x00dc,
753 "queue_id=%d rid=%d vp_idx=%d qos=%d.\n",
754 que_id, req->rid, req->vp_idx, req->qos);
758 req->rsp = ha->rsp_q_map[rsp_que];
759 /* Use alternate PCI bus number */
762 /* Use alternate PCI devfn */
765 req->options = options;
767 ql_dbg(ql_dbg_multiq, base_vha, 0xc003,
768 "options=0x%x.\n", req->options);
769 ql_dbg(ql_dbg_init, base_vha, 0x00dd,
770 "options=0x%x.\n", req->options);
771 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
772 req->outstanding_cmds[cnt] = NULL;
773 req->current_outstanding_cmd = 1;
775 req->ring_ptr = req->ring;
777 req->cnt = req->length;
779 reg = ISP_QUE_REG(ha, que_id);
780 req->req_q_in = ®->isp25mq.req_q_in;
781 req->req_q_out = ®->isp25mq.req_q_out;
782 req->max_q_depth = ha->req_q_map[0]->max_q_depth;
783 req->out_ptr = (uint16_t *)(req->ring + req->length);
784 mutex_unlock(&ha->mq_lock);
785 ql_dbg(ql_dbg_multiq, base_vha, 0xc004,
786 "ring_ptr=%p ring_index=%d, "
787 "cnt=%d id=%d max_q_depth=%d.\n",
788 req->ring_ptr, req->ring_index,
789 req->cnt, req->id, req->max_q_depth);
790 ql_dbg(ql_dbg_init, base_vha, 0x00de,
791 "ring_ptr=%p ring_index=%d, "
792 "cnt=%d id=%d max_q_depth=%d.\n",
793 req->ring_ptr, req->ring_index, req->cnt,
794 req->id, req->max_q_depth);
797 ret = qla25xx_init_req_que(base_vha, req);
798 if (ret != QLA_SUCCESS) {
799 ql_log(ql_log_fatal, base_vha, 0x00df,
800 "%s failed.\n", __func__);
801 mutex_lock(&ha->mq_lock);
802 clear_bit(que_id, ha->req_qid_map);
803 mutex_unlock(&ha->mq_lock);
806 vha->flags.qpairs_req_created = 1;
812 qla25xx_free_req_que(base_vha, req);
817 static void qla_do_work(struct work_struct *work)
820 struct qla_qpair *qpair = container_of(work, struct qla_qpair, q_work);
821 struct scsi_qla_host *vha = qpair->vha;
823 spin_lock_irqsave(&qpair->qp_lock, flags);
824 qla24xx_process_response_queue(vha, qpair->rsp);
825 spin_unlock_irqrestore(&qpair->qp_lock, flags);
829 /* create response queue */
831 qla25xx_create_rsp_que(struct qla_hw_data *ha, uint16_t options,
832 uint8_t vp_idx, uint16_t rid, struct qla_qpair *qpair, bool startqp)
835 struct rsp_que *rsp = NULL;
836 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
837 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
841 rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
843 ql_log(ql_log_warn, base_vha, 0x0066,
844 "Failed to allocate memory for response queue.\n");
848 rsp->length = RESPONSE_ENTRY_CNT_MQ;
849 rsp->ring = dma_alloc_coherent(&ha->pdev->dev,
850 (rsp->length + 1) * sizeof(response_t),
851 &rsp->dma, GFP_KERNEL);
852 if (rsp->ring == NULL) {
853 ql_log(ql_log_warn, base_vha, 0x00e1,
854 "Failed to allocate memory for response ring.\n");
858 mutex_lock(&ha->mq_lock);
859 que_id = find_first_zero_bit(ha->rsp_qid_map, ha->max_rsp_queues);
860 if (que_id >= ha->max_rsp_queues) {
861 mutex_unlock(&ha->mq_lock);
862 ql_log(ql_log_warn, base_vha, 0x00e2,
863 "No resources to create additional request queue.\n");
866 set_bit(que_id, ha->rsp_qid_map);
868 rsp->msix = qpair->msix;
870 ha->rsp_q_map[que_id] = rsp;
872 rsp->vp_idx = vp_idx;
874 ql_dbg(ql_dbg_init, base_vha, 0x00e4,
875 "rsp queue_id=%d rid=%d vp_idx=%d hw=%p.\n",
876 que_id, rsp->rid, rsp->vp_idx, rsp->hw);
877 /* Use alternate PCI bus number */
880 /* Use alternate PCI devfn */
883 /* Enable MSIX handshake mode on for uncapable adapters */
884 if (!IS_MSIX_NACK_CAPABLE(ha))
887 /* Set option to indicate response queue creation */
890 rsp->options = options;
892 reg = ISP_QUE_REG(ha, que_id);
893 rsp->rsp_q_in = ®->isp25mq.rsp_q_in;
894 rsp->rsp_q_out = ®->isp25mq.rsp_q_out;
895 rsp->in_ptr = (uint16_t *)(rsp->ring + rsp->length);
896 mutex_unlock(&ha->mq_lock);
897 ql_dbg(ql_dbg_multiq, base_vha, 0xc00b,
898 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p\n",
899 rsp->options, rsp->id, rsp->rsp_q_in,
901 ql_dbg(ql_dbg_init, base_vha, 0x00e5,
902 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p\n",
903 rsp->options, rsp->id, rsp->rsp_q_in,
906 ret = qla25xx_request_irq(ha, qpair, qpair->msix,
907 ha->flags.disable_msix_handshake ?
908 QLA_MSIX_QPAIR_MULTIQ_RSP_Q : QLA_MSIX_QPAIR_MULTIQ_RSP_Q_HS);
913 ret = qla25xx_init_rsp_que(base_vha, rsp);
914 if (ret != QLA_SUCCESS) {
915 ql_log(ql_log_fatal, base_vha, 0x00e7,
916 "%s failed.\n", __func__);
917 mutex_lock(&ha->mq_lock);
918 clear_bit(que_id, ha->rsp_qid_map);
919 mutex_unlock(&ha->mq_lock);
922 vha->flags.qpairs_rsp_created = 1;
926 qla2x00_init_response_q_entries(rsp);
928 INIT_WORK(&qpair->q_work, qla_do_work);
932 qla25xx_free_rsp_que(base_vha, rsp);
937 static void qla_ctrlvp_sp_done(srb_t *sp, int res)
941 /* don't free sp here. Let the caller do the free */
945 * qla24xx_control_vp() - Enable a virtual port for given host
946 * @vha: adapter block pointer
947 * @cmd: command type to be sent for enable virtual port
949 * Return: qla2xxx local function return status code.
951 int qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
953 int rval = QLA_MEMORY_ALLOC_FAILED;
954 struct qla_hw_data *ha = vha->hw;
955 int vp_index = vha->vp_idx;
956 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
957 DECLARE_COMPLETION_ONSTACK(comp);
960 ql_dbg(ql_dbg_vport, vha, 0x10c1,
961 "Entered %s cmd %x index %d.\n", __func__, cmd, vp_index);
963 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
964 return QLA_PARAMETER_ERROR;
967 sp = qla2x00_get_sp(base_vha, NULL, GFP_KERNEL);
971 sp->type = SRB_CTRL_VP;
972 sp->name = "ctrl_vp";
974 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
976 sp->u.iocb_cmd.u.ctrlvp.cmd = cmd;
977 sp->u.iocb_cmd.u.ctrlvp.vp_index = vp_index;
979 rval = qla2x00_start_sp(sp);
980 if (rval != QLA_SUCCESS) {
981 ql_dbg(ql_dbg_async, vha, 0xffff,
982 "%s: %s Failed submission. %x.\n",
983 __func__, sp->name, rval);
987 ql_dbg(ql_dbg_vport, vha, 0x113f, "%s hndl %x submitted\n",
988 sp->name, sp->handle);
990 wait_for_completion(&comp);
995 case QLA_FUNCTION_TIMEOUT:
996 ql_dbg(ql_dbg_vport, vha, 0xffff, "%s: %s Timeout. %x.\n",
997 __func__, sp->name, rval);
1000 ql_dbg(ql_dbg_vport, vha, 0xffff, "%s: %s done.\n",
1001 __func__, sp->name);
1004 ql_dbg(ql_dbg_vport, vha, 0xffff, "%s: %s Failed. %x.\n",
1005 __func__, sp->name, rval);
1010 kref_put(&sp->cmd_kref, qla2x00_sp_release);