2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include "qla_target.h"
11 #include <linux/moduleparam.h>
12 #include <linux/vmalloc.h>
13 #include <linux/slab.h>
14 #include <linux/list.h>
16 #include <scsi/scsi_tcq.h>
17 #include <scsi/scsicam.h>
18 #include <linux/delay.h>
21 qla2x00_vp_stop_timer(scsi_qla_host_t
*vha
)
23 if (vha
->vp_idx
&& vha
->timer_active
) {
24 del_timer_sync(&vha
->timer
);
25 vha
->timer_active
= 0;
30 qla24xx_allocate_vp_id(scsi_qla_host_t
*vha
)
33 struct qla_hw_data
*ha
= vha
->hw
;
36 /* Find an empty slot and assign an vp_id */
37 mutex_lock(&ha
->vport_lock
);
38 vp_id
= find_first_zero_bit(ha
->vp_idx_map
, ha
->max_npiv_vports
+ 1);
39 if (vp_id
> ha
->max_npiv_vports
) {
40 ql_dbg(ql_dbg_vport
, vha
, 0xa000,
41 "vp_id %d is bigger than max-supported %d.\n",
42 vp_id
, ha
->max_npiv_vports
);
43 mutex_unlock(&ha
->vport_lock
);
47 set_bit(vp_id
, ha
->vp_idx_map
);
51 spin_lock_irqsave(&ha
->vport_slock
, flags
);
52 list_add_tail(&vha
->list
, &ha
->vp_list
);
53 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
55 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
56 qlt_update_vp_map(vha
, SET_VP_IDX
);
57 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
59 mutex_unlock(&ha
->vport_lock
);
64 qla24xx_deallocate_vp_id(scsi_qla_host_t
*vha
)
67 struct qla_hw_data
*ha
= vha
->hw
;
68 unsigned long flags
= 0;
71 mutex_lock(&ha
->vport_lock
);
73 * Wait for all pending activities to finish before removing vport from
75 * Lock needs to be held for safe removal from the list (it
76 * ensures no active vp_list traversal while the vport is removed
79 for (i
= 0; i
< 10; i
++) {
80 if (wait_event_timeout(vha
->vref_waitq
,
81 !atomic_read(&vha
->vref_count
), HZ
) > 0)
85 spin_lock_irqsave(&ha
->vport_slock
, flags
);
86 if (atomic_read(&vha
->vref_count
)) {
87 ql_dbg(ql_dbg_vport
, vha
, 0xfffa,
88 "vha->vref_count=%u timeout\n", vha
->vref_count
.counter
);
89 vha
->vref_count
= (atomic_t
)ATOMIC_INIT(0);
92 qlt_update_vp_map(vha
, RESET_VP_IDX
);
93 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
97 clear_bit(vp_id
, ha
->vp_idx_map
);
99 mutex_unlock(&ha
->vport_lock
);
102 static scsi_qla_host_t
*
103 qla24xx_find_vhost_by_name(struct qla_hw_data
*ha
, uint8_t *port_name
)
105 scsi_qla_host_t
*vha
;
106 struct scsi_qla_host
*tvha
;
109 spin_lock_irqsave(&ha
->vport_slock
, flags
);
110 /* Locate matching device in database. */
111 list_for_each_entry_safe(vha
, tvha
, &ha
->vp_list
, list
) {
112 if (!memcmp(port_name
, vha
->port_name
, WWN_SIZE
)) {
113 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
117 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
122 * qla2x00_mark_vp_devices_dead
123 * Updates fcport state when device goes offline.
126 * ha = adapter block pointer.
127 * fcport = port structure pointer.
135 qla2x00_mark_vp_devices_dead(scsi_qla_host_t
*vha
)
139 * This function, if called in contexts other than vp create, disable
140 * or delete, please make sure this is synchronized with the
145 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
146 ql_dbg(ql_dbg_vport
, vha
, 0xa001,
147 "Marking port dead, loop_id=0x%04x : %x.\n",
148 fcport
->loop_id
, fcport
->vha
->vp_idx
);
150 qla2x00_mark_device_lost(vha
, fcport
, 0);
151 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
156 qla24xx_disable_vp(scsi_qla_host_t
*vha
)
159 int ret
= QLA_SUCCESS
;
162 if (vha
->hw
->flags
.fw_started
)
163 ret
= qla24xx_control_vp(vha
, VCE_COMMAND_DISABLE_VPS_LOGO_ALL
);
165 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
166 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
167 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
168 fcport
->logout_on_delete
= 0;
170 qla2x00_mark_all_devices_lost(vha
);
172 /* Remove port id from vp target map */
173 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
174 qlt_update_vp_map(vha
, RESET_AL_PA
);
175 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
177 qla2x00_mark_vp_devices_dead(vha
);
178 atomic_set(&vha
->vp_state
, VP_FAILED
);
179 vha
->flags
.management_server_logged_in
= 0;
180 if (ret
== QLA_SUCCESS
) {
181 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_DISABLED
);
183 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
190 qla24xx_enable_vp(scsi_qla_host_t
*vha
)
193 struct qla_hw_data
*ha
= vha
->hw
;
194 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
196 /* Check if physical ha port is Up */
197 if (atomic_read(&base_vha
->loop_state
) == LOOP_DOWN
||
198 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
||
199 !(ha
->current_topology
& ISP_CFG_F
)) {
200 vha
->vp_err_state
= VP_ERR_PORTDWN
;
201 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_LINKDOWN
);
202 ql_dbg(ql_dbg_taskm
, vha
, 0x800b,
203 "%s skip enable. loop_state %x topo %x\n",
204 __func__
, base_vha
->loop_state
.counter
,
205 ha
->current_topology
);
210 /* Initialize the new vport unless it is a persistent port */
211 mutex_lock(&ha
->vport_lock
);
212 ret
= qla24xx_modify_vp_config(vha
);
213 mutex_unlock(&ha
->vport_lock
);
215 if (ret
!= QLA_SUCCESS
) {
216 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
220 ql_dbg(ql_dbg_taskm
, vha
, 0x801a,
221 "Virtual port with id: %d - Enabled.\n", vha
->vp_idx
);
225 ql_dbg(ql_dbg_taskm
, vha
, 0x801b,
226 "Virtual port with id: %d - Disabled.\n", vha
->vp_idx
);
231 qla24xx_configure_vp(scsi_qla_host_t
*vha
)
233 struct fc_vport
*fc_vport
;
236 fc_vport
= vha
->fc_vport
;
238 ql_dbg(ql_dbg_vport
, vha
, 0xa002,
239 "%s: change request #3.\n", __func__
);
240 ret
= qla2x00_send_change_request(vha
, 0x3, vha
->vp_idx
);
241 if (ret
!= QLA_SUCCESS
) {
242 ql_dbg(ql_dbg_vport
, vha
, 0xa003, "Failed to enable "
243 "receiving of RSCN requests: 0x%x.\n", ret
);
246 /* Corresponds to SCR enabled */
247 clear_bit(VP_SCR_NEEDED
, &vha
->vp_flags
);
250 vha
->flags
.online
= 1;
251 if (qla24xx_configure_vhba(vha
))
254 atomic_set(&vha
->vp_state
, VP_ACTIVE
);
255 fc_vport_set_state(fc_vport
, FC_VPORT_ACTIVE
);
259 qla2x00_alert_all_vps(struct rsp_que
*rsp
, uint16_t *mb
)
261 scsi_qla_host_t
*vha
;
262 struct qla_hw_data
*ha
= rsp
->hw
;
266 spin_lock_irqsave(&ha
->vport_slock
, flags
);
267 list_for_each_entry(vha
, &ha
->vp_list
, list
) {
269 if (test_bit(VPORT_DELETE
, &vha
->dpc_flags
))
272 atomic_inc(&vha
->vref_count
);
273 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
276 case MBA_LIP_OCCURRED
:
280 case MBA_POINT_TO_POINT
:
281 case MBA_CHG_IN_CONNECTION
:
282 ql_dbg(ql_dbg_async
, vha
, 0x5024,
283 "Async_event for VP[%d], mb=0x%x vha=%p.\n",
285 qla2x00_async_event(vha
, rsp
, mb
);
287 case MBA_PORT_UPDATE
:
288 case MBA_RSCN_UPDATE
:
289 if ((mb
[3] & 0xff) == vha
->vp_idx
) {
290 ql_dbg(ql_dbg_async
, vha
, 0x5024,
291 "Async_event for VP[%d], mb=0x%x vha=%p\n",
293 qla2x00_async_event(vha
, rsp
, mb
);
298 spin_lock_irqsave(&ha
->vport_slock
, flags
);
299 atomic_dec(&vha
->vref_count
);
300 wake_up(&vha
->vref_waitq
);
304 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
308 qla2x00_vp_abort_isp(scsi_qla_host_t
*vha
)
313 * To exclusively reset vport, we need to log it out first.
314 * Note: This control_vp can fail if ISP reset is already
315 * issued, this is expected, as the vp would be already
316 * logged out due to ISP reset.
318 if (!test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
)) {
319 qla24xx_control_vp(vha
, VCE_COMMAND_DISABLE_VPS_LOGO_ALL
);
320 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
321 fcport
->logout_on_delete
= 0;
325 * Physical port will do most of the abort and recovery work. We can
326 * just treat it as a loop down
328 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
329 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
330 qla2x00_mark_all_devices_lost(vha
);
332 if (!atomic_read(&vha
->loop_down_timer
))
333 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
336 ql_dbg(ql_dbg_taskm
, vha
, 0x801d,
337 "Scheduling enable of Vport %d.\n", vha
->vp_idx
);
339 return qla24xx_enable_vp(vha
);
343 qla2x00_do_dpc_vp(scsi_qla_host_t
*vha
)
345 struct qla_hw_data
*ha
= vha
->hw
;
346 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
348 ql_dbg(ql_dbg_dpc
+ ql_dbg_verbose
, vha
, 0x4012,
349 "Entering %s vp_flags: 0x%lx.\n", __func__
, vha
->vp_flags
);
351 /* Check if Fw is ready to configure VP first */
352 if (test_bit(VP_CONFIG_OK
, &base_vha
->vp_flags
)) {
353 if (test_and_clear_bit(VP_IDX_ACQUIRED
, &vha
->vp_flags
)) {
354 /* VP acquired. complete port configuration */
355 ql_dbg(ql_dbg_dpc
, vha
, 0x4014,
356 "Configure VP scheduled.\n");
357 qla24xx_configure_vp(vha
);
358 ql_dbg(ql_dbg_dpc
, vha
, 0x4015,
359 "Configure VP end.\n");
364 if (test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
)) {
365 ql_dbg(ql_dbg_dpc
, vha
, 0x4016,
366 "FCPort update scheduled.\n");
367 qla2x00_update_fcports(vha
);
368 clear_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
);
369 ql_dbg(ql_dbg_dpc
, vha
, 0x4017,
370 "FCPort update end.\n");
373 if (test_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
) &&
374 !test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) &&
375 atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
377 if (!vha
->relogin_jif
||
378 time_after_eq(jiffies
, vha
->relogin_jif
)) {
379 vha
->relogin_jif
= jiffies
+ HZ
;
380 clear_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
382 ql_dbg(ql_dbg_dpc
, vha
, 0x4018,
383 "Relogin needed scheduled.\n");
384 qla24xx_post_relogin_work(vha
);
388 if (test_and_clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
) &&
389 (!(test_and_set_bit(RESET_ACTIVE
, &vha
->dpc_flags
)))) {
390 clear_bit(RESET_ACTIVE
, &vha
->dpc_flags
);
393 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
394 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
))) {
395 ql_dbg(ql_dbg_dpc
, vha
, 0x401a,
396 "Loop resync scheduled.\n");
397 qla2x00_loop_resync(vha
);
398 clear_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
);
399 ql_dbg(ql_dbg_dpc
, vha
, 0x401b,
400 "Loop resync end.\n");
404 ql_dbg(ql_dbg_dpc
+ ql_dbg_verbose
, vha
, 0x401c,
405 "Exiting %s.\n", __func__
);
410 qla2x00_do_dpc_all_vps(scsi_qla_host_t
*vha
)
412 struct qla_hw_data
*ha
= vha
->hw
;
414 unsigned long flags
= 0;
418 if (list_empty(&ha
->vp_list
))
421 clear_bit(VP_DPC_NEEDED
, &vha
->dpc_flags
);
423 if (!(ha
->current_topology
& ISP_CFG_F
))
426 spin_lock_irqsave(&ha
->vport_slock
, flags
);
427 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
429 atomic_inc(&vp
->vref_count
);
430 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
432 qla2x00_do_dpc_vp(vp
);
434 spin_lock_irqsave(&ha
->vport_slock
, flags
);
435 atomic_dec(&vp
->vref_count
);
438 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
442 qla24xx_vport_create_req_sanity_check(struct fc_vport
*fc_vport
)
444 scsi_qla_host_t
*base_vha
= shost_priv(fc_vport
->shost
);
445 struct qla_hw_data
*ha
= base_vha
->hw
;
446 scsi_qla_host_t
*vha
;
447 uint8_t port_name
[WWN_SIZE
];
449 if (fc_vport
->roles
!= FC_PORT_ROLE_FCP_INITIATOR
)
450 return VPCERR_UNSUPPORTED
;
452 /* Check up the F/W and H/W support NPIV */
453 if (!ha
->flags
.npiv_supported
)
454 return VPCERR_UNSUPPORTED
;
456 /* Check up whether npiv supported switch presented */
457 if (!(ha
->switch_cap
& FLOGI_MID_SUPPORT
))
458 return VPCERR_NO_FABRIC_SUPP
;
460 /* Check up unique WWPN */
461 u64_to_wwn(fc_vport
->port_name
, port_name
);
462 if (!memcmp(port_name
, base_vha
->port_name
, WWN_SIZE
))
463 return VPCERR_BAD_WWN
;
464 vha
= qla24xx_find_vhost_by_name(ha
, port_name
);
466 return VPCERR_BAD_WWN
;
468 /* Check up max-npiv-supports */
469 if (ha
->num_vhosts
> ha
->max_npiv_vports
) {
470 ql_dbg(ql_dbg_vport
, vha
, 0xa004,
471 "num_vhosts %ud is bigger "
472 "than max_npiv_vports %ud.\n",
473 ha
->num_vhosts
, ha
->max_npiv_vports
);
474 return VPCERR_UNSUPPORTED
;
480 qla24xx_create_vhost(struct fc_vport
*fc_vport
)
482 scsi_qla_host_t
*base_vha
= shost_priv(fc_vport
->shost
);
483 struct qla_hw_data
*ha
= base_vha
->hw
;
484 scsi_qla_host_t
*vha
;
485 struct scsi_host_template
*sht
= &qla2xxx_driver_template
;
486 struct Scsi_Host
*host
;
488 vha
= qla2x00_create_host(sht
, ha
);
490 ql_log(ql_log_warn
, vha
, 0xa005,
491 "scsi_host_alloc() failed for vport.\n");
496 fc_vport
->dd_data
= vha
;
498 u64_to_wwn(fc_vport
->node_name
, vha
->node_name
);
499 u64_to_wwn(fc_vport
->port_name
, vha
->port_name
);
501 vha
->fc_vport
= fc_vport
;
502 vha
->device_flags
= 0;
503 vha
->vp_idx
= qla24xx_allocate_vp_id(vha
);
504 if (vha
->vp_idx
> ha
->max_npiv_vports
) {
505 ql_dbg(ql_dbg_vport
, vha
, 0xa006,
506 "Couldn't allocate vp_id.\n");
507 goto create_vhost_failed
;
509 vha
->mgmt_svr_loop_id
= qla2x00_reserve_mgmt_server_loop_id(vha
);
514 * To fix the issue of processing a parent's RSCN for the vport before
515 * its SCR is complete.
517 set_bit(VP_SCR_NEEDED
, &vha
->vp_flags
);
518 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
519 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
521 qla2x00_start_timer(vha
, WATCH_INTERVAL
);
523 vha
->req
= base_vha
->req
;
524 vha
->flags
.nvme_enabled
= base_vha
->flags
.nvme_enabled
;
525 host
->can_queue
= base_vha
->req
->length
+ 128;
526 host
->cmd_per_lun
= 3;
527 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
)
528 host
->max_cmd_len
= 32;
530 host
->max_cmd_len
= MAX_CMDSZ
;
531 host
->max_channel
= MAX_BUSES
- 1;
532 host
->max_lun
= ql2xmaxlun
;
533 host
->unique_id
= host
->host_no
;
534 host
->max_id
= ha
->max_fibre_devices
;
535 host
->transportt
= qla2xxx_transport_vport_template
;
537 ql_dbg(ql_dbg_vport
, vha
, 0xa007,
538 "Detect vport hba %ld at address = %p.\n",
541 vha
->flags
.init_done
= 1;
543 mutex_lock(&ha
->vport_lock
);
544 set_bit(vha
->vp_idx
, ha
->vp_idx_map
);
545 ha
->cur_vport_count
++;
546 mutex_unlock(&ha
->vport_lock
);
555 qla25xx_free_req_que(struct scsi_qla_host
*vha
, struct req_que
*req
)
557 struct qla_hw_data
*ha
= vha
->hw
;
558 uint16_t que_id
= req
->id
;
560 dma_free_coherent(&ha
->pdev
->dev
, (req
->length
+ 1) *
561 sizeof(request_t
), req
->ring
, req
->dma
);
565 ha
->req_q_map
[que_id
] = NULL
;
566 mutex_lock(&ha
->vport_lock
);
567 clear_bit(que_id
, ha
->req_qid_map
);
568 mutex_unlock(&ha
->vport_lock
);
570 kfree(req
->outstanding_cmds
);
576 qla25xx_free_rsp_que(struct scsi_qla_host
*vha
, struct rsp_que
*rsp
)
578 struct qla_hw_data
*ha
= vha
->hw
;
579 uint16_t que_id
= rsp
->id
;
581 if (rsp
->msix
&& rsp
->msix
->have_irq
) {
582 free_irq(rsp
->msix
->vector
, rsp
->msix
->handle
);
583 rsp
->msix
->have_irq
= 0;
584 rsp
->msix
->in_use
= 0;
585 rsp
->msix
->handle
= NULL
;
587 dma_free_coherent(&ha
->pdev
->dev
, (rsp
->length
+ 1) *
588 sizeof(response_t
), rsp
->ring
, rsp
->dma
);
592 ha
->rsp_q_map
[que_id
] = NULL
;
593 mutex_lock(&ha
->vport_lock
);
594 clear_bit(que_id
, ha
->rsp_qid_map
);
595 mutex_unlock(&ha
->vport_lock
);
602 qla25xx_delete_req_que(struct scsi_qla_host
*vha
, struct req_que
*req
)
604 int ret
= QLA_SUCCESS
;
606 if (req
&& vha
->flags
.qpairs_req_created
) {
607 req
->options
|= BIT_0
;
608 ret
= qla25xx_init_req_que(vha
, req
);
609 if (ret
!= QLA_SUCCESS
)
610 return QLA_FUNCTION_FAILED
;
612 qla25xx_free_req_que(vha
, req
);
619 qla25xx_delete_rsp_que(struct scsi_qla_host
*vha
, struct rsp_que
*rsp
)
621 int ret
= QLA_SUCCESS
;
623 if (rsp
&& vha
->flags
.qpairs_rsp_created
) {
624 rsp
->options
|= BIT_0
;
625 ret
= qla25xx_init_rsp_que(vha
, rsp
);
626 if (ret
!= QLA_SUCCESS
)
627 return QLA_FUNCTION_FAILED
;
629 qla25xx_free_rsp_que(vha
, rsp
);
635 /* Delete all queues for a given vhost */
637 qla25xx_delete_queues(struct scsi_qla_host
*vha
)
640 struct req_que
*req
= NULL
;
641 struct rsp_que
*rsp
= NULL
;
642 struct qla_hw_data
*ha
= vha
->hw
;
643 struct qla_qpair
*qpair
, *tqpair
;
645 if (ql2xmqsupport
|| ql2xnvmeenable
) {
646 list_for_each_entry_safe(qpair
, tqpair
, &vha
->qp_list
,
648 qla2xxx_delete_qpair(vha
, qpair
);
650 /* Delete request queues */
651 for (cnt
= 1; cnt
< ha
->max_req_queues
; cnt
++) {
652 req
= ha
->req_q_map
[cnt
];
653 if (req
&& test_bit(cnt
, ha
->req_qid_map
)) {
654 ret
= qla25xx_delete_req_que(vha
, req
);
655 if (ret
!= QLA_SUCCESS
) {
656 ql_log(ql_log_warn
, vha
, 0x00ea,
657 "Couldn't delete req que %d.\n",
664 /* Delete response queues */
665 for (cnt
= 1; cnt
< ha
->max_rsp_queues
; cnt
++) {
666 rsp
= ha
->rsp_q_map
[cnt
];
667 if (rsp
&& test_bit(cnt
, ha
->rsp_qid_map
)) {
668 ret
= qla25xx_delete_rsp_que(vha
, rsp
);
669 if (ret
!= QLA_SUCCESS
) {
670 ql_log(ql_log_warn
, vha
, 0x00eb,
671 "Couldn't delete rsp que %d.\n",
683 qla25xx_create_req_que(struct qla_hw_data
*ha
, uint16_t options
,
684 uint8_t vp_idx
, uint16_t rid
, int rsp_que
, uint8_t qos
, bool startqp
)
687 struct req_que
*req
= NULL
;
688 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
689 struct scsi_qla_host
*vha
= pci_get_drvdata(ha
->pdev
);
694 req
= kzalloc(sizeof(struct req_que
), GFP_KERNEL
);
696 ql_log(ql_log_fatal
, base_vha
, 0x00d9,
697 "Failed to allocate memory for request queue.\n");
701 req
->length
= REQUEST_ENTRY_CNT_24XX
;
702 req
->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
703 (req
->length
+ 1) * sizeof(request_t
),
704 &req
->dma
, GFP_KERNEL
);
705 if (req
->ring
== NULL
) {
706 ql_log(ql_log_fatal
, base_vha
, 0x00da,
707 "Failed to allocate memory for request_ring.\n");
711 ret
= qla2x00_alloc_outstanding_cmds(ha
, req
);
712 if (ret
!= QLA_SUCCESS
)
715 mutex_lock(&ha
->mq_lock
);
716 que_id
= find_first_zero_bit(ha
->req_qid_map
, ha
->max_req_queues
);
717 if (que_id
>= ha
->max_req_queues
) {
718 mutex_unlock(&ha
->mq_lock
);
719 ql_log(ql_log_warn
, base_vha
, 0x00db,
720 "No resources to create additional request queue.\n");
723 set_bit(que_id
, ha
->req_qid_map
);
724 ha
->req_q_map
[que_id
] = req
;
726 req
->vp_idx
= vp_idx
;
729 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc002,
730 "queue_id=%d rid=%d vp_idx=%d qos=%d.\n",
731 que_id
, req
->rid
, req
->vp_idx
, req
->qos
);
732 ql_dbg(ql_dbg_init
, base_vha
, 0x00dc,
733 "queue_id=%d rid=%d vp_idx=%d qos=%d.\n",
734 que_id
, req
->rid
, req
->vp_idx
, req
->qos
);
738 req
->rsp
= ha
->rsp_q_map
[rsp_que
];
739 /* Use alternate PCI bus number */
742 /* Use alternate PCI devfn */
745 req
->options
= options
;
747 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc003,
748 "options=0x%x.\n", req
->options
);
749 ql_dbg(ql_dbg_init
, base_vha
, 0x00dd,
750 "options=0x%x.\n", req
->options
);
751 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++)
752 req
->outstanding_cmds
[cnt
] = NULL
;
753 req
->current_outstanding_cmd
= 1;
755 req
->ring_ptr
= req
->ring
;
757 req
->cnt
= req
->length
;
759 reg
= ISP_QUE_REG(ha
, que_id
);
760 req
->req_q_in
= ®
->isp25mq
.req_q_in
;
761 req
->req_q_out
= ®
->isp25mq
.req_q_out
;
762 req
->max_q_depth
= ha
->req_q_map
[0]->max_q_depth
;
763 req
->out_ptr
= (void *)(req
->ring
+ req
->length
);
764 mutex_unlock(&ha
->mq_lock
);
765 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc004,
766 "ring_ptr=%p ring_index=%d, "
767 "cnt=%d id=%d max_q_depth=%d.\n",
768 req
->ring_ptr
, req
->ring_index
,
769 req
->cnt
, req
->id
, req
->max_q_depth
);
770 ql_dbg(ql_dbg_init
, base_vha
, 0x00de,
771 "ring_ptr=%p ring_index=%d, "
772 "cnt=%d id=%d max_q_depth=%d.\n",
773 req
->ring_ptr
, req
->ring_index
, req
->cnt
,
774 req
->id
, req
->max_q_depth
);
777 ret
= qla25xx_init_req_que(base_vha
, req
);
778 if (ret
!= QLA_SUCCESS
) {
779 ql_log(ql_log_fatal
, base_vha
, 0x00df,
780 "%s failed.\n", __func__
);
781 mutex_lock(&ha
->mq_lock
);
782 clear_bit(que_id
, ha
->req_qid_map
);
783 mutex_unlock(&ha
->mq_lock
);
786 vha
->flags
.qpairs_req_created
= 1;
792 qla25xx_free_req_que(base_vha
, req
);
797 static void qla_do_work(struct work_struct
*work
)
800 struct qla_qpair
*qpair
= container_of(work
, struct qla_qpair
, q_work
);
801 struct scsi_qla_host
*vha
;
802 struct qla_hw_data
*ha
= qpair
->hw
;
804 spin_lock_irqsave(&qpair
->qp_lock
, flags
);
805 vha
= pci_get_drvdata(ha
->pdev
);
806 qla24xx_process_response_queue(vha
, qpair
->rsp
);
807 spin_unlock_irqrestore(&qpair
->qp_lock
, flags
);
811 /* create response queue */
813 qla25xx_create_rsp_que(struct qla_hw_data
*ha
, uint16_t options
,
814 uint8_t vp_idx
, uint16_t rid
, struct qla_qpair
*qpair
, bool startqp
)
817 struct rsp_que
*rsp
= NULL
;
818 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
819 struct scsi_qla_host
*vha
= pci_get_drvdata(ha
->pdev
);
823 rsp
= kzalloc(sizeof(struct rsp_que
), GFP_KERNEL
);
825 ql_log(ql_log_warn
, base_vha
, 0x0066,
826 "Failed to allocate memory for response queue.\n");
830 rsp
->length
= RESPONSE_ENTRY_CNT_MQ
;
831 rsp
->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
832 (rsp
->length
+ 1) * sizeof(response_t
),
833 &rsp
->dma
, GFP_KERNEL
);
834 if (rsp
->ring
== NULL
) {
835 ql_log(ql_log_warn
, base_vha
, 0x00e1,
836 "Failed to allocate memory for response ring.\n");
840 mutex_lock(&ha
->mq_lock
);
841 que_id
= find_first_zero_bit(ha
->rsp_qid_map
, ha
->max_rsp_queues
);
842 if (que_id
>= ha
->max_rsp_queues
) {
843 mutex_unlock(&ha
->mq_lock
);
844 ql_log(ql_log_warn
, base_vha
, 0x00e2,
845 "No resources to create additional request queue.\n");
848 set_bit(que_id
, ha
->rsp_qid_map
);
850 rsp
->msix
= qpair
->msix
;
852 ha
->rsp_q_map
[que_id
] = rsp
;
854 rsp
->vp_idx
= vp_idx
;
856 ql_dbg(ql_dbg_init
, base_vha
, 0x00e4,
857 "rsp queue_id=%d rid=%d vp_idx=%d hw=%p.\n",
858 que_id
, rsp
->rid
, rsp
->vp_idx
, rsp
->hw
);
859 /* Use alternate PCI bus number */
862 /* Use alternate PCI devfn */
865 /* Enable MSIX handshake mode on for uncapable adapters */
866 if (!IS_MSIX_NACK_CAPABLE(ha
))
869 /* Set option to indicate response queue creation */
872 rsp
->options
= options
;
874 reg
= ISP_QUE_REG(ha
, que_id
);
875 rsp
->rsp_q_in
= ®
->isp25mq
.rsp_q_in
;
876 rsp
->rsp_q_out
= ®
->isp25mq
.rsp_q_out
;
877 rsp
->in_ptr
= (void *)(rsp
->ring
+ rsp
->length
);
878 mutex_unlock(&ha
->mq_lock
);
879 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc00b,
880 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p\n",
881 rsp
->options
, rsp
->id
, rsp
->rsp_q_in
,
883 ql_dbg(ql_dbg_init
, base_vha
, 0x00e5,
884 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p\n",
885 rsp
->options
, rsp
->id
, rsp
->rsp_q_in
,
888 ret
= qla25xx_request_irq(ha
, qpair
, qpair
->msix
,
889 QLA_MSIX_QPAIR_MULTIQ_RSP_Q
);
894 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
895 if (ret
!= QLA_SUCCESS
) {
896 ql_log(ql_log_fatal
, base_vha
, 0x00e7,
897 "%s failed.\n", __func__
);
898 mutex_lock(&ha
->mq_lock
);
899 clear_bit(que_id
, ha
->rsp_qid_map
);
900 mutex_unlock(&ha
->mq_lock
);
903 vha
->flags
.qpairs_rsp_created
= 1;
907 qla2x00_init_response_q_entries(rsp
);
909 INIT_WORK(&qpair
->q_work
, qla_do_work
);
913 qla25xx_free_rsp_que(base_vha
, rsp
);
918 static void qla_ctrlvp_sp_done(srb_t
*sp
, int res
)
922 /* don't free sp here. Let the caller do the free */
926 * qla24xx_control_vp() - Enable a virtual port for given host
927 * @vha: adapter block pointer
928 * @cmd: command type to be sent for enable virtual port
930 * Return: qla2xxx local function return status code.
932 int qla24xx_control_vp(scsi_qla_host_t
*vha
, int cmd
)
934 int rval
= QLA_MEMORY_ALLOC_FAILED
;
935 struct qla_hw_data
*ha
= vha
->hw
;
936 int vp_index
= vha
->vp_idx
;
937 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
938 DECLARE_COMPLETION_ONSTACK(comp
);
941 ql_dbg(ql_dbg_vport
, vha
, 0x10c1,
942 "Entered %s cmd %x index %d.\n", __func__
, cmd
, vp_index
);
944 if (vp_index
== 0 || vp_index
>= ha
->max_npiv_vports
)
945 return QLA_PARAMETER_ERROR
;
947 sp
= qla2x00_get_sp(base_vha
, NULL
, GFP_KERNEL
);
951 sp
->type
= SRB_CTRL_VP
;
952 sp
->name
= "ctrl_vp";
954 sp
->done
= qla_ctrlvp_sp_done
;
955 sp
->u
.iocb_cmd
.timeout
= qla2x00_async_iocb_timeout
;
956 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
957 sp
->u
.iocb_cmd
.u
.ctrlvp
.cmd
= cmd
;
958 sp
->u
.iocb_cmd
.u
.ctrlvp
.vp_index
= vp_index
;
960 rval
= qla2x00_start_sp(sp
);
961 if (rval
!= QLA_SUCCESS
) {
962 ql_dbg(ql_dbg_async
, vha
, 0xffff,
963 "%s: %s Failed submission. %x.\n",
964 __func__
, sp
->name
, rval
);
968 ql_dbg(ql_dbg_vport
, vha
, 0x113f, "%s hndl %x submitted\n",
969 sp
->name
, sp
->handle
);
971 wait_for_completion(&comp
);
976 case QLA_FUNCTION_TIMEOUT
:
977 ql_dbg(ql_dbg_vport
, vha
, 0xffff, "%s: %s Timeout. %x.\n",
978 __func__
, sp
->name
, rval
);
981 ql_dbg(ql_dbg_vport
, vha
, 0xffff, "%s: %s done.\n",
985 ql_dbg(ql_dbg_vport
, vha
, 0xffff, "%s: %s Failed. %x.\n",
986 __func__
, sp
->name
, rval
);