2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2011 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
);
54 qlt_update_vp_map(vha
, SET_VP_IDX
);
56 spin_unlock_irqrestore(&ha
->vport_slock
, 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;
69 mutex_lock(&ha
->vport_lock
);
71 * Wait for all pending activities to finish before removing vport from
73 * Lock needs to be held for safe removal from the list (it
74 * ensures no active vp_list traversal while the vport is removed
77 spin_lock_irqsave(&ha
->vport_slock
, flags
);
78 while (atomic_read(&vha
->vref_count
)) {
79 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
83 spin_lock_irqsave(&ha
->vport_slock
, flags
);
86 qlt_update_vp_map(vha
, RESET_VP_IDX
);
87 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
91 clear_bit(vp_id
, ha
->vp_idx_map
);
93 mutex_unlock(&ha
->vport_lock
);
96 static scsi_qla_host_t
*
97 qla24xx_find_vhost_by_name(struct qla_hw_data
*ha
, uint8_t *port_name
)
100 struct scsi_qla_host
*tvha
;
103 spin_lock_irqsave(&ha
->vport_slock
, flags
);
104 /* Locate matching device in database. */
105 list_for_each_entry_safe(vha
, tvha
, &ha
->vp_list
, list
) {
106 if (!memcmp(port_name
, vha
->port_name
, WWN_SIZE
)) {
107 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
111 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
116 * qla2x00_mark_vp_devices_dead
117 * Updates fcport state when device goes offline.
120 * ha = adapter block pointer.
121 * fcport = port structure pointer.
129 qla2x00_mark_vp_devices_dead(scsi_qla_host_t
*vha
)
133 * This function, if called in contexts other than vp create, disable
134 * or delete, please make sure this is synchronized with the
139 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
140 ql_dbg(ql_dbg_vport
, vha
, 0xa001,
141 "Marking port dead, loop_id=0x%04x : %x.\n",
142 fcport
->loop_id
, fcport
->vha
->vp_idx
);
144 qla2x00_mark_device_lost(vha
, fcport
, 0, 0);
145 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
150 qla24xx_disable_vp(scsi_qla_host_t
*vha
)
154 ret
= qla24xx_control_vp(vha
, VCE_COMMAND_DISABLE_VPS_LOGO_ALL
);
155 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
156 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
158 /* Remove port id from vp target map */
159 qlt_update_vp_map(vha
, RESET_AL_PA
);
161 qla2x00_mark_vp_devices_dead(vha
);
162 atomic_set(&vha
->vp_state
, VP_FAILED
);
163 vha
->flags
.management_server_logged_in
= 0;
164 if (ret
== QLA_SUCCESS
) {
165 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_DISABLED
);
167 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
174 qla24xx_enable_vp(scsi_qla_host_t
*vha
)
177 struct qla_hw_data
*ha
= vha
->hw
;
178 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
180 /* Check if physical ha port is Up */
181 if (atomic_read(&base_vha
->loop_state
) == LOOP_DOWN
||
182 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
||
183 !(ha
->current_topology
& ISP_CFG_F
)) {
184 vha
->vp_err_state
= VP_ERR_PORTDWN
;
185 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_LINKDOWN
);
189 /* Initialize the new vport unless it is a persistent port */
190 mutex_lock(&ha
->vport_lock
);
191 ret
= qla24xx_modify_vp_config(vha
);
192 mutex_unlock(&ha
->vport_lock
);
194 if (ret
!= QLA_SUCCESS
) {
195 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
199 ql_dbg(ql_dbg_taskm
, vha
, 0x801a,
200 "Virtual port with id: %d - Enabled.\n", vha
->vp_idx
);
204 ql_dbg(ql_dbg_taskm
, vha
, 0x801b,
205 "Virtual port with id: %d - Disabled.\n", vha
->vp_idx
);
210 qla24xx_configure_vp(scsi_qla_host_t
*vha
)
212 struct fc_vport
*fc_vport
;
215 fc_vport
= vha
->fc_vport
;
217 ql_dbg(ql_dbg_vport
, vha
, 0xa002,
218 "%s: change request #3.\n", __func__
);
219 ret
= qla2x00_send_change_request(vha
, 0x3, vha
->vp_idx
);
220 if (ret
!= QLA_SUCCESS
) {
221 ql_dbg(ql_dbg_vport
, vha
, 0xa003, "Failed to enable "
222 "receiving of RSCN requests: 0x%x.\n", ret
);
225 /* Corresponds to SCR enabled */
226 clear_bit(VP_SCR_NEEDED
, &vha
->vp_flags
);
229 vha
->flags
.online
= 1;
230 if (qla24xx_configure_vhba(vha
))
233 atomic_set(&vha
->vp_state
, VP_ACTIVE
);
234 fc_vport_set_state(fc_vport
, FC_VPORT_ACTIVE
);
238 qla2x00_alert_all_vps(struct rsp_que
*rsp
, uint16_t *mb
)
240 scsi_qla_host_t
*vha
;
241 struct qla_hw_data
*ha
= rsp
->hw
;
245 spin_lock_irqsave(&ha
->vport_slock
, flags
);
246 list_for_each_entry(vha
, &ha
->vp_list
, list
) {
248 atomic_inc(&vha
->vref_count
);
249 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
252 case MBA_LIP_OCCURRED
:
256 case MBA_POINT_TO_POINT
:
257 case MBA_CHG_IN_CONNECTION
:
258 case MBA_PORT_UPDATE
:
259 case MBA_RSCN_UPDATE
:
260 ql_dbg(ql_dbg_async
, vha
, 0x5024,
261 "Async_event for VP[%d], mb=0x%x vha=%p.\n",
263 qla2x00_async_event(vha
, rsp
, mb
);
267 spin_lock_irqsave(&ha
->vport_slock
, flags
);
268 atomic_dec(&vha
->vref_count
);
272 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
276 qla2x00_vp_abort_isp(scsi_qla_host_t
*vha
)
279 * Physical port will do most of the abort and recovery work. We can
280 * just treat it as a loop down
282 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
283 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
284 qla2x00_mark_all_devices_lost(vha
, 0);
286 if (!atomic_read(&vha
->loop_down_timer
))
287 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
291 * To exclusively reset vport, we need to log it out first. Note: this
292 * control_vp can fail if ISP reset is already issued, this is
293 * expected, as the vp would be already logged out due to ISP reset.
295 if (!test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))
296 qla24xx_control_vp(vha
, VCE_COMMAND_DISABLE_VPS_LOGO_ALL
);
298 ql_dbg(ql_dbg_taskm
, vha
, 0x801d,
299 "Scheduling enable of Vport %d.\n", vha
->vp_idx
);
300 return qla24xx_enable_vp(vha
);
304 qla2x00_do_dpc_vp(scsi_qla_host_t
*vha
)
306 ql_dbg(ql_dbg_dpc
+ ql_dbg_verbose
, vha
, 0x4012,
307 "Entering %s vp_flags: 0x%lx.\n", __func__
, vha
->vp_flags
);
309 qla2x00_do_work(vha
);
311 if (test_and_clear_bit(VP_IDX_ACQUIRED
, &vha
->vp_flags
)) {
312 /* VP acquired. complete port configuration */
313 ql_dbg(ql_dbg_dpc
, vha
, 0x4014,
314 "Configure VP scheduled.\n");
315 qla24xx_configure_vp(vha
);
316 ql_dbg(ql_dbg_dpc
, vha
, 0x4015,
317 "Configure VP end.\n");
321 if (test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
)) {
322 ql_dbg(ql_dbg_dpc
, vha
, 0x4016,
323 "FCPort update scheduled.\n");
324 qla2x00_update_fcports(vha
);
325 clear_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
);
326 ql_dbg(ql_dbg_dpc
, vha
, 0x4017,
327 "FCPort update end.\n");
330 if ((test_and_clear_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
)) &&
331 !test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) &&
332 atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
334 ql_dbg(ql_dbg_dpc
, vha
, 0x4018,
335 "Relogin needed scheduled.\n");
336 qla2x00_relogin(vha
);
337 ql_dbg(ql_dbg_dpc
, vha
, 0x4019,
338 "Relogin needed end.\n");
341 if (test_and_clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
) &&
342 (!(test_and_set_bit(RESET_ACTIVE
, &vha
->dpc_flags
)))) {
343 clear_bit(RESET_ACTIVE
, &vha
->dpc_flags
);
346 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
347 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
))) {
348 ql_dbg(ql_dbg_dpc
, vha
, 0x401a,
349 "Loop resync scheduled.\n");
350 qla2x00_loop_resync(vha
);
351 clear_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
);
352 ql_dbg(ql_dbg_dpc
, vha
, 0x401b,
353 "Loop resync end.\n");
357 ql_dbg(ql_dbg_dpc
+ ql_dbg_verbose
, vha
, 0x401c,
358 "Exiting %s.\n", __func__
);
363 qla2x00_do_dpc_all_vps(scsi_qla_host_t
*vha
)
366 struct qla_hw_data
*ha
= vha
->hw
;
368 unsigned long flags
= 0;
372 if (list_empty(&ha
->vp_list
))
375 clear_bit(VP_DPC_NEEDED
, &vha
->dpc_flags
);
377 if (!(ha
->current_topology
& ISP_CFG_F
))
380 spin_lock_irqsave(&ha
->vport_slock
, flags
);
381 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
383 atomic_inc(&vp
->vref_count
);
384 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
386 ret
= qla2x00_do_dpc_vp(vp
);
388 spin_lock_irqsave(&ha
->vport_slock
, flags
);
389 atomic_dec(&vp
->vref_count
);
392 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
396 qla24xx_vport_create_req_sanity_check(struct fc_vport
*fc_vport
)
398 scsi_qla_host_t
*base_vha
= shost_priv(fc_vport
->shost
);
399 struct qla_hw_data
*ha
= base_vha
->hw
;
400 scsi_qla_host_t
*vha
;
401 uint8_t port_name
[WWN_SIZE
];
403 if (fc_vport
->roles
!= FC_PORT_ROLE_FCP_INITIATOR
)
404 return VPCERR_UNSUPPORTED
;
406 /* Check up the F/W and H/W support NPIV */
407 if (!ha
->flags
.npiv_supported
)
408 return VPCERR_UNSUPPORTED
;
410 /* Check up whether npiv supported switch presented */
411 if (!(ha
->switch_cap
& FLOGI_MID_SUPPORT
))
412 return VPCERR_NO_FABRIC_SUPP
;
414 /* Check up unique WWPN */
415 u64_to_wwn(fc_vport
->port_name
, port_name
);
416 if (!memcmp(port_name
, base_vha
->port_name
, WWN_SIZE
))
417 return VPCERR_BAD_WWN
;
418 vha
= qla24xx_find_vhost_by_name(ha
, port_name
);
420 return VPCERR_BAD_WWN
;
422 /* Check up max-npiv-supports */
423 if (ha
->num_vhosts
> ha
->max_npiv_vports
) {
424 ql_dbg(ql_dbg_vport
, vha
, 0xa004,
425 "num_vhosts %ud is bigger "
426 "than max_npiv_vports %ud.\n",
427 ha
->num_vhosts
, ha
->max_npiv_vports
);
428 return VPCERR_UNSUPPORTED
;
434 qla24xx_create_vhost(struct fc_vport
*fc_vport
)
436 scsi_qla_host_t
*base_vha
= shost_priv(fc_vport
->shost
);
437 struct qla_hw_data
*ha
= base_vha
->hw
;
438 scsi_qla_host_t
*vha
;
439 struct scsi_host_template
*sht
= &qla2xxx_driver_template
;
440 struct Scsi_Host
*host
;
442 vha
= qla2x00_create_host(sht
, ha
);
444 ql_log(ql_log_warn
, vha
, 0xa005,
445 "scsi_host_alloc() failed for vport.\n");
450 fc_vport
->dd_data
= vha
;
452 u64_to_wwn(fc_vport
->node_name
, vha
->node_name
);
453 u64_to_wwn(fc_vport
->port_name
, vha
->port_name
);
455 vha
->fc_vport
= fc_vport
;
456 vha
->device_flags
= 0;
457 vha
->vp_idx
= qla24xx_allocate_vp_id(vha
);
458 if (vha
->vp_idx
> ha
->max_npiv_vports
) {
459 ql_dbg(ql_dbg_vport
, vha
, 0xa006,
460 "Couldn't allocate vp_id.\n");
461 goto create_vhost_failed
;
463 vha
->mgmt_svr_loop_id
= 10 + vha
->vp_idx
;
468 * To fix the issue of processing a parent's RSCN for the vport before
469 * its SCR is complete.
471 set_bit(VP_SCR_NEEDED
, &vha
->vp_flags
);
472 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
473 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
475 qla2x00_start_timer(vha
, qla2x00_timer
, WATCH_INTERVAL
);
477 vha
->req
= base_vha
->req
;
478 host
->can_queue
= base_vha
->req
->length
+ 128;
480 host
->cmd_per_lun
= 3;
481 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
)
482 host
->max_cmd_len
= 32;
484 host
->max_cmd_len
= MAX_CMDSZ
;
485 host
->max_channel
= MAX_BUSES
- 1;
486 host
->max_lun
= ql2xmaxlun
;
487 host
->unique_id
= host
->host_no
;
488 host
->max_id
= ha
->max_fibre_devices
;
489 host
->transportt
= qla2xxx_transport_vport_template
;
491 ql_dbg(ql_dbg_vport
, vha
, 0xa007,
492 "Detect vport hba %ld at address = %p.\n",
495 vha
->flags
.init_done
= 1;
497 mutex_lock(&ha
->vport_lock
);
498 set_bit(vha
->vp_idx
, ha
->vp_idx_map
);
499 ha
->cur_vport_count
++;
500 mutex_unlock(&ha
->vport_lock
);
509 qla25xx_free_req_que(struct scsi_qla_host
*vha
, struct req_que
*req
)
511 struct qla_hw_data
*ha
= vha
->hw
;
512 uint16_t que_id
= req
->id
;
514 dma_free_coherent(&ha
->pdev
->dev
, (req
->length
+ 1) *
515 sizeof(request_t
), req
->ring
, req
->dma
);
519 ha
->req_q_map
[que_id
] = NULL
;
520 mutex_lock(&ha
->vport_lock
);
521 clear_bit(que_id
, ha
->req_qid_map
);
522 mutex_unlock(&ha
->vport_lock
);
529 qla25xx_free_rsp_que(struct scsi_qla_host
*vha
, struct rsp_que
*rsp
)
531 struct qla_hw_data
*ha
= vha
->hw
;
532 uint16_t que_id
= rsp
->id
;
534 if (rsp
->msix
&& rsp
->msix
->have_irq
) {
535 free_irq(rsp
->msix
->vector
, rsp
);
536 rsp
->msix
->have_irq
= 0;
537 rsp
->msix
->rsp
= NULL
;
539 dma_free_coherent(&ha
->pdev
->dev
, (rsp
->length
+ 1) *
540 sizeof(response_t
), rsp
->ring
, rsp
->dma
);
544 ha
->rsp_q_map
[que_id
] = NULL
;
545 mutex_lock(&ha
->vport_lock
);
546 clear_bit(que_id
, ha
->rsp_qid_map
);
547 mutex_unlock(&ha
->vport_lock
);
554 qla25xx_delete_req_que(struct scsi_qla_host
*vha
, struct req_que
*req
)
559 req
->options
|= BIT_0
;
560 ret
= qla25xx_init_req_que(vha
, req
);
562 if (ret
== QLA_SUCCESS
)
563 qla25xx_free_req_que(vha
, req
);
569 qla25xx_delete_rsp_que(struct scsi_qla_host
*vha
, struct rsp_que
*rsp
)
574 rsp
->options
|= BIT_0
;
575 ret
= qla25xx_init_rsp_que(vha
, rsp
);
577 if (ret
== QLA_SUCCESS
)
578 qla25xx_free_rsp_que(vha
, rsp
);
583 /* Delete all queues for a given vhost */
585 qla25xx_delete_queues(struct scsi_qla_host
*vha
)
588 struct req_que
*req
= NULL
;
589 struct rsp_que
*rsp
= NULL
;
590 struct qla_hw_data
*ha
= vha
->hw
;
592 /* Delete request queues */
593 for (cnt
= 1; cnt
< ha
->max_req_queues
; cnt
++) {
594 req
= ha
->req_q_map
[cnt
];
596 ret
= qla25xx_delete_req_que(vha
, req
);
597 if (ret
!= QLA_SUCCESS
) {
598 ql_log(ql_log_warn
, vha
, 0x00ea,
599 "Couldn't delete req que %d.\n",
606 /* Delete response queues */
607 for (cnt
= 1; cnt
< ha
->max_rsp_queues
; cnt
++) {
608 rsp
= ha
->rsp_q_map
[cnt
];
610 ret
= qla25xx_delete_rsp_que(vha
, rsp
);
611 if (ret
!= QLA_SUCCESS
) {
612 ql_log(ql_log_warn
, vha
, 0x00eb,
613 "Couldn't delete rsp que %d.\n",
623 qla25xx_create_req_que(struct qla_hw_data
*ha
, uint16_t options
,
624 uint8_t vp_idx
, uint16_t rid
, int rsp_que
, uint8_t qos
)
627 struct req_que
*req
= NULL
;
628 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
630 device_reg_t __iomem
*reg
;
633 req
= kzalloc(sizeof(struct req_que
), GFP_KERNEL
);
635 ql_log(ql_log_fatal
, base_vha
, 0x00d9,
636 "Failed to allocate memory for request queue.\n");
640 req
->length
= REQUEST_ENTRY_CNT_24XX
;
641 req
->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
642 (req
->length
+ 1) * sizeof(request_t
),
643 &req
->dma
, GFP_KERNEL
);
644 if (req
->ring
== NULL
) {
645 ql_log(ql_log_fatal
, base_vha
, 0x00da,
646 "Failed to allocte memory for request_ring.\n");
650 mutex_lock(&ha
->vport_lock
);
651 que_id
= find_first_zero_bit(ha
->req_qid_map
, ha
->max_req_queues
);
652 if (que_id
>= ha
->max_req_queues
) {
653 mutex_unlock(&ha
->vport_lock
);
654 ql_log(ql_log_warn
, base_vha
, 0x00db,
655 "No resources to create additional request queue.\n");
658 set_bit(que_id
, ha
->req_qid_map
);
659 ha
->req_q_map
[que_id
] = req
;
661 req
->vp_idx
= vp_idx
;
664 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc002,
665 "queue_id=%d rid=%d vp_idx=%d qos=%d.\n",
666 que_id
, req
->rid
, req
->vp_idx
, req
->qos
);
667 ql_dbg(ql_dbg_init
, base_vha
, 0x00dc,
668 "queue_id=%d rid=%d vp_idx=%d qos=%d.\n",
669 que_id
, req
->rid
, req
->vp_idx
, req
->qos
);
673 req
->rsp
= ha
->rsp_q_map
[rsp_que
];
674 /* Use alternate PCI bus number */
677 /* Use alternate PCI devfn */
680 req
->options
= options
;
682 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc003,
683 "options=0x%x.\n", req
->options
);
684 ql_dbg(ql_dbg_init
, base_vha
, 0x00dd,
685 "options=0x%x.\n", req
->options
);
686 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
687 req
->outstanding_cmds
[cnt
] = NULL
;
688 req
->current_outstanding_cmd
= 1;
690 req
->ring_ptr
= req
->ring
;
692 req
->cnt
= req
->length
;
694 reg
= ISP_QUE_REG(ha
, que_id
);
695 req
->max_q_depth
= ha
->req_q_map
[0]->max_q_depth
;
696 mutex_unlock(&ha
->vport_lock
);
697 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc004,
698 "ring_ptr=%p ring_index=%d, "
699 "cnt=%d id=%d max_q_depth=%d.\n",
700 req
->ring_ptr
, req
->ring_index
,
701 req
->cnt
, req
->id
, req
->max_q_depth
);
702 ql_dbg(ql_dbg_init
, base_vha
, 0x00de,
703 "ring_ptr=%p ring_index=%d, "
704 "cnt=%d id=%d max_q_depth=%d.\n",
705 req
->ring_ptr
, req
->ring_index
, req
->cnt
,
706 req
->id
, req
->max_q_depth
);
708 ret
= qla25xx_init_req_que(base_vha
, req
);
709 if (ret
!= QLA_SUCCESS
) {
710 ql_log(ql_log_fatal
, base_vha
, 0x00df,
711 "%s failed.\n", __func__
);
712 mutex_lock(&ha
->vport_lock
);
713 clear_bit(que_id
, ha
->req_qid_map
);
714 mutex_unlock(&ha
->vport_lock
);
721 qla25xx_free_req_que(base_vha
, req
);
726 static void qla_do_work(struct work_struct
*work
)
729 struct rsp_que
*rsp
= container_of(work
, struct rsp_que
, q_work
);
730 struct scsi_qla_host
*vha
;
731 struct qla_hw_data
*ha
= rsp
->hw
;
733 spin_lock_irqsave(&rsp
->hw
->hardware_lock
, flags
);
734 vha
= pci_get_drvdata(ha
->pdev
);
735 qla24xx_process_response_queue(vha
, rsp
);
736 spin_unlock_irqrestore(&rsp
->hw
->hardware_lock
, flags
);
739 /* create response queue */
741 qla25xx_create_rsp_que(struct qla_hw_data
*ha
, uint16_t options
,
742 uint8_t vp_idx
, uint16_t rid
, int req
)
745 struct rsp_que
*rsp
= NULL
;
746 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
748 device_reg_t __iomem
*reg
;
750 rsp
= kzalloc(sizeof(struct rsp_que
), GFP_KERNEL
);
752 ql_log(ql_log_warn
, base_vha
, 0x0066,
753 "Failed to allocate memory for response queue.\n");
757 rsp
->length
= RESPONSE_ENTRY_CNT_MQ
;
758 rsp
->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
759 (rsp
->length
+ 1) * sizeof(response_t
),
760 &rsp
->dma
, GFP_KERNEL
);
761 if (rsp
->ring
== NULL
) {
762 ql_log(ql_log_warn
, base_vha
, 0x00e1,
763 "Failed to allocate memory for response ring.\n");
767 mutex_lock(&ha
->vport_lock
);
768 que_id
= find_first_zero_bit(ha
->rsp_qid_map
, ha
->max_rsp_queues
);
769 if (que_id
>= ha
->max_rsp_queues
) {
770 mutex_unlock(&ha
->vport_lock
);
771 ql_log(ql_log_warn
, base_vha
, 0x00e2,
772 "No resources to create additional request queue.\n");
775 set_bit(que_id
, ha
->rsp_qid_map
);
777 if (ha
->flags
.msix_enabled
)
778 rsp
->msix
= &ha
->msix_entries
[que_id
+ 1];
780 ql_log(ql_log_warn
, base_vha
, 0x00e3,
781 "MSIX not enalbled.\n");
783 ha
->rsp_q_map
[que_id
] = rsp
;
785 rsp
->vp_idx
= vp_idx
;
787 ql_dbg(ql_dbg_init
, base_vha
, 0x00e4,
788 "queue_id=%d rid=%d vp_idx=%d hw=%p.\n",
789 que_id
, rsp
->rid
, rsp
->vp_idx
, rsp
->hw
);
790 /* Use alternate PCI bus number */
793 /* Use alternate PCI devfn */
796 /* Enable MSIX handshake mode on for uncapable adapters */
797 if (!IS_MSIX_NACK_CAPABLE(ha
))
800 rsp
->options
= options
;
802 reg
= ISP_QUE_REG(ha
, que_id
);
803 rsp
->rsp_q_in
= ®
->isp25mq
.rsp_q_in
;
804 rsp
->rsp_q_out
= ®
->isp25mq
.rsp_q_out
;
805 mutex_unlock(&ha
->vport_lock
);
806 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc00b,
807 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p",
808 rsp
->options
, rsp
->id
, rsp
->rsp_q_in
,
810 ql_dbg(ql_dbg_init
, base_vha
, 0x00e5,
811 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p",
812 rsp
->options
, rsp
->id
, rsp
->rsp_q_in
,
815 ret
= qla25xx_request_irq(rsp
);
819 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
820 if (ret
!= QLA_SUCCESS
) {
821 ql_log(ql_log_fatal
, base_vha
, 0x00e7,
822 "%s failed.\n", __func__
);
823 mutex_lock(&ha
->vport_lock
);
824 clear_bit(que_id
, ha
->rsp_qid_map
);
825 mutex_unlock(&ha
->vport_lock
);
829 rsp
->req
= ha
->req_q_map
[req
];
833 qla2x00_init_response_q_entries(rsp
);
835 INIT_WORK(&rsp
->q_work
, qla_do_work
);
839 qla25xx_free_rsp_que(base_vha
, rsp
);