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
);
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
)
155 ret
= qla24xx_control_vp(vha
, VCE_COMMAND_DISABLE_VPS_LOGO_ALL
);
156 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
157 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
159 /* Remove port id from vp target map */
160 spin_lock_irqsave(&vha
->hw
->vport_slock
, flags
);
161 qlt_update_vp_map(vha
, RESET_AL_PA
);
162 spin_unlock_irqrestore(&vha
->hw
->vport_slock
, flags
);
164 qla2x00_mark_vp_devices_dead(vha
);
165 atomic_set(&vha
->vp_state
, VP_FAILED
);
166 vha
->flags
.management_server_logged_in
= 0;
167 if (ret
== QLA_SUCCESS
) {
168 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_DISABLED
);
170 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
177 qla24xx_enable_vp(scsi_qla_host_t
*vha
)
180 struct qla_hw_data
*ha
= vha
->hw
;
181 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
183 /* Check if physical ha port is Up */
184 if (atomic_read(&base_vha
->loop_state
) == LOOP_DOWN
||
185 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
||
186 !(ha
->current_topology
& ISP_CFG_F
)) {
187 vha
->vp_err_state
= VP_ERR_PORTDWN
;
188 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_LINKDOWN
);
192 /* Initialize the new vport unless it is a persistent port */
193 mutex_lock(&ha
->vport_lock
);
194 ret
= qla24xx_modify_vp_config(vha
);
195 mutex_unlock(&ha
->vport_lock
);
197 if (ret
!= QLA_SUCCESS
) {
198 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
202 ql_dbg(ql_dbg_taskm
, vha
, 0x801a,
203 "Virtual port with id: %d - Enabled.\n", vha
->vp_idx
);
207 ql_dbg(ql_dbg_taskm
, vha
, 0x801b,
208 "Virtual port with id: %d - Disabled.\n", vha
->vp_idx
);
213 qla24xx_configure_vp(scsi_qla_host_t
*vha
)
215 struct fc_vport
*fc_vport
;
218 fc_vport
= vha
->fc_vport
;
220 ql_dbg(ql_dbg_vport
, vha
, 0xa002,
221 "%s: change request #3.\n", __func__
);
222 ret
= qla2x00_send_change_request(vha
, 0x3, vha
->vp_idx
);
223 if (ret
!= QLA_SUCCESS
) {
224 ql_dbg(ql_dbg_vport
, vha
, 0xa003, "Failed to enable "
225 "receiving of RSCN requests: 0x%x.\n", ret
);
228 /* Corresponds to SCR enabled */
229 clear_bit(VP_SCR_NEEDED
, &vha
->vp_flags
);
232 vha
->flags
.online
= 1;
233 if (qla24xx_configure_vhba(vha
))
236 atomic_set(&vha
->vp_state
, VP_ACTIVE
);
237 fc_vport_set_state(fc_vport
, FC_VPORT_ACTIVE
);
241 qla2x00_alert_all_vps(struct rsp_que
*rsp
, uint16_t *mb
)
243 scsi_qla_host_t
*vha
;
244 struct qla_hw_data
*ha
= rsp
->hw
;
248 spin_lock_irqsave(&ha
->vport_slock
, flags
);
249 list_for_each_entry(vha
, &ha
->vp_list
, list
) {
251 atomic_inc(&vha
->vref_count
);
252 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
255 case MBA_LIP_OCCURRED
:
259 case MBA_POINT_TO_POINT
:
260 case MBA_CHG_IN_CONNECTION
:
261 case MBA_PORT_UPDATE
:
262 case MBA_RSCN_UPDATE
:
263 ql_dbg(ql_dbg_async
, vha
, 0x5024,
264 "Async_event for VP[%d], mb=0x%x vha=%p.\n",
266 qla2x00_async_event(vha
, rsp
, mb
);
270 spin_lock_irqsave(&ha
->vport_slock
, flags
);
271 atomic_dec(&vha
->vref_count
);
275 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
279 qla2x00_vp_abort_isp(scsi_qla_host_t
*vha
)
282 * Physical port will do most of the abort and recovery work. We can
283 * just treat it as a loop down
285 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
286 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
287 qla2x00_mark_all_devices_lost(vha
, 0);
289 if (!atomic_read(&vha
->loop_down_timer
))
290 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
294 * To exclusively reset vport, we need to log it out first. Note: this
295 * control_vp can fail if ISP reset is already issued, this is
296 * expected, as the vp would be already logged out due to ISP reset.
298 if (!test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))
299 qla24xx_control_vp(vha
, VCE_COMMAND_DISABLE_VPS_LOGO_ALL
);
301 ql_dbg(ql_dbg_taskm
, vha
, 0x801d,
302 "Scheduling enable of Vport %d.\n", vha
->vp_idx
);
303 return qla24xx_enable_vp(vha
);
307 qla2x00_do_dpc_vp(scsi_qla_host_t
*vha
)
309 struct qla_hw_data
*ha
= vha
->hw
;
310 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
312 ql_dbg(ql_dbg_dpc
+ ql_dbg_verbose
, vha
, 0x4012,
313 "Entering %s vp_flags: 0x%lx.\n", __func__
, vha
->vp_flags
);
315 qla2x00_do_work(vha
);
317 /* Check if Fw is ready to configure VP first */
318 if (test_bit(VP_CONFIG_OK
, &base_vha
->vp_flags
)) {
319 if (test_and_clear_bit(VP_IDX_ACQUIRED
, &vha
->vp_flags
)) {
320 /* VP acquired. complete port configuration */
321 ql_dbg(ql_dbg_dpc
, vha
, 0x4014,
322 "Configure VP scheduled.\n");
323 qla24xx_configure_vp(vha
);
324 ql_dbg(ql_dbg_dpc
, vha
, 0x4015,
325 "Configure VP end.\n");
330 if (test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
)) {
331 ql_dbg(ql_dbg_dpc
, vha
, 0x4016,
332 "FCPort update scheduled.\n");
333 qla2x00_update_fcports(vha
);
334 clear_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
);
335 ql_dbg(ql_dbg_dpc
, vha
, 0x4017,
336 "FCPort update end.\n");
339 if ((test_and_clear_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
)) &&
340 !test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) &&
341 atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
343 ql_dbg(ql_dbg_dpc
, vha
, 0x4018,
344 "Relogin needed scheduled.\n");
345 qla2x00_relogin(vha
);
346 ql_dbg(ql_dbg_dpc
, vha
, 0x4019,
347 "Relogin needed end.\n");
350 if (test_and_clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
) &&
351 (!(test_and_set_bit(RESET_ACTIVE
, &vha
->dpc_flags
)))) {
352 clear_bit(RESET_ACTIVE
, &vha
->dpc_flags
);
355 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
356 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
))) {
357 ql_dbg(ql_dbg_dpc
, vha
, 0x401a,
358 "Loop resync scheduled.\n");
359 qla2x00_loop_resync(vha
);
360 clear_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
);
361 ql_dbg(ql_dbg_dpc
, vha
, 0x401b,
362 "Loop resync end.\n");
366 ql_dbg(ql_dbg_dpc
+ ql_dbg_verbose
, vha
, 0x401c,
367 "Exiting %s.\n", __func__
);
372 qla2x00_do_dpc_all_vps(scsi_qla_host_t
*vha
)
374 struct qla_hw_data
*ha
= vha
->hw
;
376 unsigned long flags
= 0;
380 if (list_empty(&ha
->vp_list
))
383 clear_bit(VP_DPC_NEEDED
, &vha
->dpc_flags
);
385 if (!(ha
->current_topology
& ISP_CFG_F
))
388 spin_lock_irqsave(&ha
->vport_slock
, flags
);
389 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
391 atomic_inc(&vp
->vref_count
);
392 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
394 qla2x00_do_dpc_vp(vp
);
396 spin_lock_irqsave(&ha
->vport_slock
, flags
);
397 atomic_dec(&vp
->vref_count
);
400 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
404 qla24xx_vport_create_req_sanity_check(struct fc_vport
*fc_vport
)
406 scsi_qla_host_t
*base_vha
= shost_priv(fc_vport
->shost
);
407 struct qla_hw_data
*ha
= base_vha
->hw
;
408 scsi_qla_host_t
*vha
;
409 uint8_t port_name
[WWN_SIZE
];
411 if (fc_vport
->roles
!= FC_PORT_ROLE_FCP_INITIATOR
)
412 return VPCERR_UNSUPPORTED
;
414 /* Check up the F/W and H/W support NPIV */
415 if (!ha
->flags
.npiv_supported
)
416 return VPCERR_UNSUPPORTED
;
418 /* Check up whether npiv supported switch presented */
419 if (!(ha
->switch_cap
& FLOGI_MID_SUPPORT
))
420 return VPCERR_NO_FABRIC_SUPP
;
422 /* Check up unique WWPN */
423 u64_to_wwn(fc_vport
->port_name
, port_name
);
424 if (!memcmp(port_name
, base_vha
->port_name
, WWN_SIZE
))
425 return VPCERR_BAD_WWN
;
426 vha
= qla24xx_find_vhost_by_name(ha
, port_name
);
428 return VPCERR_BAD_WWN
;
430 /* Check up max-npiv-supports */
431 if (ha
->num_vhosts
> ha
->max_npiv_vports
) {
432 ql_dbg(ql_dbg_vport
, vha
, 0xa004,
433 "num_vhosts %ud is bigger "
434 "than max_npiv_vports %ud.\n",
435 ha
->num_vhosts
, ha
->max_npiv_vports
);
436 return VPCERR_UNSUPPORTED
;
442 qla24xx_create_vhost(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 struct scsi_host_template
*sht
= &qla2xxx_driver_template
;
448 struct Scsi_Host
*host
;
450 vha
= qla2x00_create_host(sht
, ha
);
452 ql_log(ql_log_warn
, vha
, 0xa005,
453 "scsi_host_alloc() failed for vport.\n");
458 fc_vport
->dd_data
= vha
;
460 u64_to_wwn(fc_vport
->node_name
, vha
->node_name
);
461 u64_to_wwn(fc_vport
->port_name
, vha
->port_name
);
463 vha
->fc_vport
= fc_vport
;
464 vha
->device_flags
= 0;
465 vha
->vp_idx
= qla24xx_allocate_vp_id(vha
);
466 if (vha
->vp_idx
> ha
->max_npiv_vports
) {
467 ql_dbg(ql_dbg_vport
, vha
, 0xa006,
468 "Couldn't allocate vp_id.\n");
469 goto create_vhost_failed
;
471 vha
->mgmt_svr_loop_id
= 10 + vha
->vp_idx
;
476 * To fix the issue of processing a parent's RSCN for the vport before
477 * its SCR is complete.
479 set_bit(VP_SCR_NEEDED
, &vha
->vp_flags
);
480 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
481 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
483 qla2x00_start_timer(vha
, qla2x00_timer
, WATCH_INTERVAL
);
485 vha
->req
= base_vha
->req
;
486 host
->can_queue
= base_vha
->req
->length
+ 128;
487 host
->cmd_per_lun
= 3;
488 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
)
489 host
->max_cmd_len
= 32;
491 host
->max_cmd_len
= MAX_CMDSZ
;
492 host
->max_channel
= MAX_BUSES
- 1;
493 host
->max_lun
= ql2xmaxlun
;
494 host
->unique_id
= host
->host_no
;
495 host
->max_id
= ha
->max_fibre_devices
;
496 host
->transportt
= qla2xxx_transport_vport_template
;
498 ql_dbg(ql_dbg_vport
, vha
, 0xa007,
499 "Detect vport hba %ld at address = %p.\n",
502 vha
->flags
.init_done
= 1;
504 mutex_lock(&ha
->vport_lock
);
505 set_bit(vha
->vp_idx
, ha
->vp_idx_map
);
506 ha
->cur_vport_count
++;
507 mutex_unlock(&ha
->vport_lock
);
516 qla25xx_free_req_que(struct scsi_qla_host
*vha
, struct req_que
*req
)
518 struct qla_hw_data
*ha
= vha
->hw
;
519 uint16_t que_id
= req
->id
;
521 dma_free_coherent(&ha
->pdev
->dev
, (req
->length
+ 1) *
522 sizeof(request_t
), req
->ring
, req
->dma
);
526 ha
->req_q_map
[que_id
] = NULL
;
527 mutex_lock(&ha
->vport_lock
);
528 clear_bit(que_id
, ha
->req_qid_map
);
529 mutex_unlock(&ha
->vport_lock
);
531 kfree(req
->outstanding_cmds
);
537 qla25xx_free_rsp_que(struct scsi_qla_host
*vha
, struct rsp_que
*rsp
)
539 struct qla_hw_data
*ha
= vha
->hw
;
540 uint16_t que_id
= rsp
->id
;
542 if (rsp
->msix
&& rsp
->msix
->have_irq
) {
543 free_irq(rsp
->msix
->vector
, rsp
);
544 rsp
->msix
->have_irq
= 0;
545 rsp
->msix
->rsp
= NULL
;
547 dma_free_coherent(&ha
->pdev
->dev
, (rsp
->length
+ 1) *
548 sizeof(response_t
), rsp
->ring
, rsp
->dma
);
552 ha
->rsp_q_map
[que_id
] = NULL
;
553 mutex_lock(&ha
->vport_lock
);
554 clear_bit(que_id
, ha
->rsp_qid_map
);
555 mutex_unlock(&ha
->vport_lock
);
562 qla25xx_delete_req_que(struct scsi_qla_host
*vha
, struct req_que
*req
)
567 req
->options
|= BIT_0
;
568 ret
= qla25xx_init_req_que(vha
, req
);
570 if (ret
== QLA_SUCCESS
)
571 qla25xx_free_req_que(vha
, req
);
577 qla25xx_delete_rsp_que(struct scsi_qla_host
*vha
, struct rsp_que
*rsp
)
582 rsp
->options
|= BIT_0
;
583 ret
= qla25xx_init_rsp_que(vha
, rsp
);
585 if (ret
== QLA_SUCCESS
)
586 qla25xx_free_rsp_que(vha
, rsp
);
591 /* Delete all queues for a given vhost */
593 qla25xx_delete_queues(struct scsi_qla_host
*vha
)
596 struct req_que
*req
= NULL
;
597 struct rsp_que
*rsp
= NULL
;
598 struct qla_hw_data
*ha
= vha
->hw
;
600 /* Delete request queues */
601 for (cnt
= 1; cnt
< ha
->max_req_queues
; cnt
++) {
602 req
= ha
->req_q_map
[cnt
];
603 if (req
&& test_bit(cnt
, ha
->req_qid_map
)) {
604 ret
= qla25xx_delete_req_que(vha
, req
);
605 if (ret
!= QLA_SUCCESS
) {
606 ql_log(ql_log_warn
, vha
, 0x00ea,
607 "Couldn't delete req que %d.\n",
614 /* Delete response queues */
615 for (cnt
= 1; cnt
< ha
->max_rsp_queues
; cnt
++) {
616 rsp
= ha
->rsp_q_map
[cnt
];
617 if (rsp
&& test_bit(cnt
, ha
->rsp_qid_map
)) {
618 ret
= qla25xx_delete_rsp_que(vha
, rsp
);
619 if (ret
!= QLA_SUCCESS
) {
620 ql_log(ql_log_warn
, vha
, 0x00eb,
621 "Couldn't delete rsp que %d.\n",
631 qla25xx_create_req_que(struct qla_hw_data
*ha
, uint16_t options
,
632 uint8_t vp_idx
, uint16_t rid
, int rsp_que
, uint8_t qos
)
635 struct req_que
*req
= NULL
;
636 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
641 req
= kzalloc(sizeof(struct req_que
), GFP_KERNEL
);
643 ql_log(ql_log_fatal
, base_vha
, 0x00d9,
644 "Failed to allocate memory for request queue.\n");
648 req
->length
= REQUEST_ENTRY_CNT_24XX
;
649 req
->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
650 (req
->length
+ 1) * sizeof(request_t
),
651 &req
->dma
, GFP_KERNEL
);
652 if (req
->ring
== NULL
) {
653 ql_log(ql_log_fatal
, base_vha
, 0x00da,
654 "Failed to allocate memory for request_ring.\n");
658 ret
= qla2x00_alloc_outstanding_cmds(ha
, req
);
659 if (ret
!= QLA_SUCCESS
)
662 mutex_lock(&ha
->vport_lock
);
663 que_id
= find_first_zero_bit(ha
->req_qid_map
, ha
->max_req_queues
);
664 if (que_id
>= ha
->max_req_queues
) {
665 mutex_unlock(&ha
->vport_lock
);
666 ql_log(ql_log_warn
, base_vha
, 0x00db,
667 "No resources to create additional request queue.\n");
670 set_bit(que_id
, ha
->req_qid_map
);
671 ha
->req_q_map
[que_id
] = req
;
673 req
->vp_idx
= vp_idx
;
676 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc002,
677 "queue_id=%d rid=%d vp_idx=%d qos=%d.\n",
678 que_id
, req
->rid
, req
->vp_idx
, req
->qos
);
679 ql_dbg(ql_dbg_init
, base_vha
, 0x00dc,
680 "queue_id=%d rid=%d vp_idx=%d qos=%d.\n",
681 que_id
, req
->rid
, req
->vp_idx
, req
->qos
);
685 req
->rsp
= ha
->rsp_q_map
[rsp_que
];
686 /* Use alternate PCI bus number */
689 /* Use alternate PCI devfn */
692 req
->options
= options
;
694 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc003,
695 "options=0x%x.\n", req
->options
);
696 ql_dbg(ql_dbg_init
, base_vha
, 0x00dd,
697 "options=0x%x.\n", req
->options
);
698 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++)
699 req
->outstanding_cmds
[cnt
] = NULL
;
700 req
->current_outstanding_cmd
= 1;
702 req
->ring_ptr
= req
->ring
;
704 req
->cnt
= req
->length
;
706 reg
= ISP_QUE_REG(ha
, que_id
);
707 req
->req_q_in
= ®
->isp25mq
.req_q_in
;
708 req
->req_q_out
= ®
->isp25mq
.req_q_out
;
709 req
->max_q_depth
= ha
->req_q_map
[0]->max_q_depth
;
710 req
->out_ptr
= (void *)(req
->ring
+ req
->length
);
711 mutex_unlock(&ha
->vport_lock
);
712 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc004,
713 "ring_ptr=%p ring_index=%d, "
714 "cnt=%d id=%d max_q_depth=%d.\n",
715 req
->ring_ptr
, req
->ring_index
,
716 req
->cnt
, req
->id
, req
->max_q_depth
);
717 ql_dbg(ql_dbg_init
, base_vha
, 0x00de,
718 "ring_ptr=%p ring_index=%d, "
719 "cnt=%d id=%d max_q_depth=%d.\n",
720 req
->ring_ptr
, req
->ring_index
, req
->cnt
,
721 req
->id
, req
->max_q_depth
);
723 ret
= qla25xx_init_req_que(base_vha
, req
);
724 if (ret
!= QLA_SUCCESS
) {
725 ql_log(ql_log_fatal
, base_vha
, 0x00df,
726 "%s failed.\n", __func__
);
727 mutex_lock(&ha
->vport_lock
);
728 clear_bit(que_id
, ha
->req_qid_map
);
729 mutex_unlock(&ha
->vport_lock
);
736 qla25xx_free_req_que(base_vha
, req
);
741 static void qla_do_work(struct work_struct
*work
)
744 struct rsp_que
*rsp
= container_of(work
, struct rsp_que
, q_work
);
745 struct scsi_qla_host
*vha
;
746 struct qla_hw_data
*ha
= rsp
->hw
;
748 spin_lock_irqsave(&rsp
->hw
->hardware_lock
, flags
);
749 vha
= pci_get_drvdata(ha
->pdev
);
750 qla24xx_process_response_queue(vha
, rsp
);
751 spin_unlock_irqrestore(&rsp
->hw
->hardware_lock
, flags
);
754 /* create response queue */
756 qla25xx_create_rsp_que(struct qla_hw_data
*ha
, uint16_t options
,
757 uint8_t vp_idx
, uint16_t rid
, int req
)
760 struct rsp_que
*rsp
= NULL
;
761 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
765 rsp
= kzalloc(sizeof(struct rsp_que
), GFP_KERNEL
);
767 ql_log(ql_log_warn
, base_vha
, 0x0066,
768 "Failed to allocate memory for response queue.\n");
772 rsp
->length
= RESPONSE_ENTRY_CNT_MQ
;
773 rsp
->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
774 (rsp
->length
+ 1) * sizeof(response_t
),
775 &rsp
->dma
, GFP_KERNEL
);
776 if (rsp
->ring
== NULL
) {
777 ql_log(ql_log_warn
, base_vha
, 0x00e1,
778 "Failed to allocate memory for response ring.\n");
782 mutex_lock(&ha
->vport_lock
);
783 que_id
= find_first_zero_bit(ha
->rsp_qid_map
, ha
->max_rsp_queues
);
784 if (que_id
>= ha
->max_rsp_queues
) {
785 mutex_unlock(&ha
->vport_lock
);
786 ql_log(ql_log_warn
, base_vha
, 0x00e2,
787 "No resources to create additional request queue.\n");
790 set_bit(que_id
, ha
->rsp_qid_map
);
792 if (ha
->flags
.msix_enabled
)
793 rsp
->msix
= &ha
->msix_entries
[que_id
+ 1];
795 ql_log(ql_log_warn
, base_vha
, 0x00e3,
796 "MSIX not enabled.\n");
798 ha
->rsp_q_map
[que_id
] = rsp
;
800 rsp
->vp_idx
= vp_idx
;
802 ql_dbg(ql_dbg_init
, base_vha
, 0x00e4,
803 "queue_id=%d rid=%d vp_idx=%d hw=%p.\n",
804 que_id
, rsp
->rid
, rsp
->vp_idx
, rsp
->hw
);
805 /* Use alternate PCI bus number */
808 /* Use alternate PCI devfn */
811 /* Enable MSIX handshake mode on for uncapable adapters */
812 if (!IS_MSIX_NACK_CAPABLE(ha
))
815 rsp
->options
= options
;
817 reg
= ISP_QUE_REG(ha
, que_id
);
818 rsp
->rsp_q_in
= ®
->isp25mq
.rsp_q_in
;
819 rsp
->rsp_q_out
= ®
->isp25mq
.rsp_q_out
;
820 rsp
->in_ptr
= (void *)(rsp
->ring
+ rsp
->length
);
821 mutex_unlock(&ha
->vport_lock
);
822 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc00b,
823 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p",
824 rsp
->options
, rsp
->id
, rsp
->rsp_q_in
,
826 ql_dbg(ql_dbg_init
, base_vha
, 0x00e5,
827 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p",
828 rsp
->options
, rsp
->id
, rsp
->rsp_q_in
,
831 ret
= qla25xx_request_irq(rsp
);
835 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
836 if (ret
!= QLA_SUCCESS
) {
837 ql_log(ql_log_fatal
, base_vha
, 0x00e7,
838 "%s failed.\n", __func__
);
839 mutex_lock(&ha
->vport_lock
);
840 clear_bit(que_id
, ha
->rsp_qid_map
);
841 mutex_unlock(&ha
->vport_lock
);
845 rsp
->req
= ha
->req_q_map
[req
];
849 qla2x00_init_response_q_entries(rsp
);
851 INIT_WORK(&rsp
->q_work
, qla_do_work
);
855 qla25xx_free_rsp_que(base_vha
, rsp
);