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;
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
78 wait_event_timeout(vha
->vref_waitq
, !atomic_read(&vha
->vref_count
),
81 spin_lock_irqsave(&ha
->vport_slock
, flags
);
82 if (atomic_read(&vha
->vref_count
)) {
83 ql_dbg(ql_dbg_vport
, vha
, 0xfffa,
84 "vha->vref_count=%u timeout\n", vha
->vref_count
.counter
);
85 vha
->vref_count
= (atomic_t
)ATOMIC_INIT(0);
88 qlt_update_vp_map(vha
, RESET_VP_IDX
);
89 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
93 clear_bit(vp_id
, ha
->vp_idx_map
);
95 mutex_unlock(&ha
->vport_lock
);
98 static scsi_qla_host_t
*
99 qla24xx_find_vhost_by_name(struct qla_hw_data
*ha
, uint8_t *port_name
)
101 scsi_qla_host_t
*vha
;
102 struct scsi_qla_host
*tvha
;
105 spin_lock_irqsave(&ha
->vport_slock
, flags
);
106 /* Locate matching device in database. */
107 list_for_each_entry_safe(vha
, tvha
, &ha
->vp_list
, list
) {
108 if (!memcmp(port_name
, vha
->port_name
, WWN_SIZE
)) {
109 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
113 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
118 * qla2x00_mark_vp_devices_dead
119 * Updates fcport state when device goes offline.
122 * ha = adapter block pointer.
123 * fcport = port structure pointer.
131 qla2x00_mark_vp_devices_dead(scsi_qla_host_t
*vha
)
135 * This function, if called in contexts other than vp create, disable
136 * or delete, please make sure this is synchronized with the
141 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
142 ql_dbg(ql_dbg_vport
, vha
, 0xa001,
143 "Marking port dead, loop_id=0x%04x : %x.\n",
144 fcport
->loop_id
, fcport
->vha
->vp_idx
);
146 qla2x00_mark_device_lost(vha
, fcport
, 0, 0);
147 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
152 qla24xx_disable_vp(scsi_qla_host_t
*vha
)
157 ret
= qla24xx_control_vp(vha
, VCE_COMMAND_DISABLE_VPS_LOGO_ALL
);
158 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
159 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
161 /* Remove port id from vp target map */
162 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
163 qlt_update_vp_map(vha
, RESET_AL_PA
);
164 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
166 qla2x00_mark_vp_devices_dead(vha
);
167 atomic_set(&vha
->vp_state
, VP_FAILED
);
168 vha
->flags
.management_server_logged_in
= 0;
169 if (ret
== QLA_SUCCESS
) {
170 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_DISABLED
);
172 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
179 qla24xx_enable_vp(scsi_qla_host_t
*vha
)
182 struct qla_hw_data
*ha
= vha
->hw
;
183 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
185 /* Check if physical ha port is Up */
186 if (atomic_read(&base_vha
->loop_state
) == LOOP_DOWN
||
187 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
||
188 !(ha
->current_topology
& ISP_CFG_F
)) {
189 vha
->vp_err_state
= VP_ERR_PORTDWN
;
190 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_LINKDOWN
);
191 ql_dbg(ql_dbg_taskm
, vha
, 0x800b,
192 "%s skip enable. loop_state %x topo %x\n",
193 __func__
, base_vha
->loop_state
.counter
,
194 ha
->current_topology
);
199 /* Initialize the new vport unless it is a persistent port */
200 mutex_lock(&ha
->vport_lock
);
201 ret
= qla24xx_modify_vp_config(vha
);
202 mutex_unlock(&ha
->vport_lock
);
204 if (ret
!= QLA_SUCCESS
) {
205 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
209 ql_dbg(ql_dbg_taskm
, vha
, 0x801a,
210 "Virtual port with id: %d - Enabled.\n", vha
->vp_idx
);
214 ql_dbg(ql_dbg_taskm
, vha
, 0x801b,
215 "Virtual port with id: %d - Disabled.\n", vha
->vp_idx
);
220 qla24xx_configure_vp(scsi_qla_host_t
*vha
)
222 struct fc_vport
*fc_vport
;
225 fc_vport
= vha
->fc_vport
;
227 ql_dbg(ql_dbg_vport
, vha
, 0xa002,
228 "%s: change request #3.\n", __func__
);
229 ret
= qla2x00_send_change_request(vha
, 0x3, vha
->vp_idx
);
230 if (ret
!= QLA_SUCCESS
) {
231 ql_dbg(ql_dbg_vport
, vha
, 0xa003, "Failed to enable "
232 "receiving of RSCN requests: 0x%x.\n", ret
);
235 /* Corresponds to SCR enabled */
236 clear_bit(VP_SCR_NEEDED
, &vha
->vp_flags
);
239 vha
->flags
.online
= 1;
240 if (qla24xx_configure_vhba(vha
))
243 atomic_set(&vha
->vp_state
, VP_ACTIVE
);
244 fc_vport_set_state(fc_vport
, FC_VPORT_ACTIVE
);
248 qla2x00_alert_all_vps(struct rsp_que
*rsp
, uint16_t *mb
)
250 scsi_qla_host_t
*vha
;
251 struct qla_hw_data
*ha
= rsp
->hw
;
255 spin_lock_irqsave(&ha
->vport_slock
, flags
);
256 list_for_each_entry(vha
, &ha
->vp_list
, list
) {
258 atomic_inc(&vha
->vref_count
);
259 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
262 case MBA_LIP_OCCURRED
:
266 case MBA_POINT_TO_POINT
:
267 case MBA_CHG_IN_CONNECTION
:
268 ql_dbg(ql_dbg_async
, vha
, 0x5024,
269 "Async_event for VP[%d], mb=0x%x vha=%p.\n",
271 qla2x00_async_event(vha
, rsp
, mb
);
273 case MBA_PORT_UPDATE
:
274 case MBA_RSCN_UPDATE
:
275 if ((mb
[3] & 0xff) == vha
->vp_idx
) {
276 ql_dbg(ql_dbg_async
, vha
, 0x5024,
277 "Async_event for VP[%d], mb=0x%x vha=%p\n",
279 qla2x00_async_event(vha
, rsp
, mb
);
284 spin_lock_irqsave(&ha
->vport_slock
, flags
);
285 atomic_dec(&vha
->vref_count
);
286 wake_up(&vha
->vref_waitq
);
290 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
294 qla2x00_vp_abort_isp(scsi_qla_host_t
*vha
)
297 * Physical port will do most of the abort and recovery work. We can
298 * just treat it as a loop down
300 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
301 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
302 qla2x00_mark_all_devices_lost(vha
, 0);
304 if (!atomic_read(&vha
->loop_down_timer
))
305 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
309 * To exclusively reset vport, we need to log it out first. Note: this
310 * control_vp can fail if ISP reset is already issued, this is
311 * expected, as the vp would be already logged out due to ISP reset.
313 if (!test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))
314 qla24xx_control_vp(vha
, VCE_COMMAND_DISABLE_VPS_LOGO_ALL
);
316 ql_dbg(ql_dbg_taskm
, vha
, 0x801d,
317 "Scheduling enable of Vport %d.\n", vha
->vp_idx
);
318 return qla24xx_enable_vp(vha
);
322 qla2x00_do_dpc_vp(scsi_qla_host_t
*vha
)
324 struct qla_hw_data
*ha
= vha
->hw
;
325 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
327 ql_dbg(ql_dbg_dpc
+ ql_dbg_verbose
, vha
, 0x4012,
328 "Entering %s vp_flags: 0x%lx.\n", __func__
, vha
->vp_flags
);
330 /* Check if Fw is ready to configure VP first */
331 if (test_bit(VP_CONFIG_OK
, &base_vha
->vp_flags
)) {
332 if (test_and_clear_bit(VP_IDX_ACQUIRED
, &vha
->vp_flags
)) {
333 /* VP acquired. complete port configuration */
334 ql_dbg(ql_dbg_dpc
, vha
, 0x4014,
335 "Configure VP scheduled.\n");
336 qla24xx_configure_vp(vha
);
337 ql_dbg(ql_dbg_dpc
, vha
, 0x4015,
338 "Configure VP end.\n");
343 if (test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
)) {
344 ql_dbg(ql_dbg_dpc
, vha
, 0x4016,
345 "FCPort update scheduled.\n");
346 qla2x00_update_fcports(vha
);
347 clear_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
);
348 ql_dbg(ql_dbg_dpc
, vha
, 0x4017,
349 "FCPort update end.\n");
352 if (test_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
) &&
353 !test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) &&
354 atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
356 if (!vha
->relogin_jif
||
357 time_after_eq(jiffies
, vha
->relogin_jif
)) {
358 vha
->relogin_jif
= jiffies
+ HZ
;
359 clear_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
361 ql_dbg(ql_dbg_dpc
, vha
, 0x4018,
362 "Relogin needed scheduled.\n");
363 qla24xx_post_relogin_work(vha
);
367 if (test_and_clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
) &&
368 (!(test_and_set_bit(RESET_ACTIVE
, &vha
->dpc_flags
)))) {
369 clear_bit(RESET_ACTIVE
, &vha
->dpc_flags
);
372 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
373 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
))) {
374 ql_dbg(ql_dbg_dpc
, vha
, 0x401a,
375 "Loop resync scheduled.\n");
376 qla2x00_loop_resync(vha
);
377 clear_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
);
378 ql_dbg(ql_dbg_dpc
, vha
, 0x401b,
379 "Loop resync end.\n");
383 ql_dbg(ql_dbg_dpc
+ ql_dbg_verbose
, vha
, 0x401c,
384 "Exiting %s.\n", __func__
);
389 qla2x00_do_dpc_all_vps(scsi_qla_host_t
*vha
)
391 struct qla_hw_data
*ha
= vha
->hw
;
393 unsigned long flags
= 0;
397 if (list_empty(&ha
->vp_list
))
400 clear_bit(VP_DPC_NEEDED
, &vha
->dpc_flags
);
402 if (!(ha
->current_topology
& ISP_CFG_F
))
405 spin_lock_irqsave(&ha
->vport_slock
, flags
);
406 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
408 atomic_inc(&vp
->vref_count
);
409 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
411 qla2x00_do_dpc_vp(vp
);
413 spin_lock_irqsave(&ha
->vport_slock
, flags
);
414 atomic_dec(&vp
->vref_count
);
417 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
421 qla24xx_vport_create_req_sanity_check(struct fc_vport
*fc_vport
)
423 scsi_qla_host_t
*base_vha
= shost_priv(fc_vport
->shost
);
424 struct qla_hw_data
*ha
= base_vha
->hw
;
425 scsi_qla_host_t
*vha
;
426 uint8_t port_name
[WWN_SIZE
];
428 if (fc_vport
->roles
!= FC_PORT_ROLE_FCP_INITIATOR
)
429 return VPCERR_UNSUPPORTED
;
431 /* Check up the F/W and H/W support NPIV */
432 if (!ha
->flags
.npiv_supported
)
433 return VPCERR_UNSUPPORTED
;
435 /* Check up whether npiv supported switch presented */
436 if (!(ha
->switch_cap
& FLOGI_MID_SUPPORT
))
437 return VPCERR_NO_FABRIC_SUPP
;
439 /* Check up unique WWPN */
440 u64_to_wwn(fc_vport
->port_name
, port_name
);
441 if (!memcmp(port_name
, base_vha
->port_name
, WWN_SIZE
))
442 return VPCERR_BAD_WWN
;
443 vha
= qla24xx_find_vhost_by_name(ha
, port_name
);
445 return VPCERR_BAD_WWN
;
447 /* Check up max-npiv-supports */
448 if (ha
->num_vhosts
> ha
->max_npiv_vports
) {
449 ql_dbg(ql_dbg_vport
, vha
, 0xa004,
450 "num_vhosts %ud is bigger "
451 "than max_npiv_vports %ud.\n",
452 ha
->num_vhosts
, ha
->max_npiv_vports
);
453 return VPCERR_UNSUPPORTED
;
459 qla24xx_create_vhost(struct fc_vport
*fc_vport
)
461 scsi_qla_host_t
*base_vha
= shost_priv(fc_vport
->shost
);
462 struct qla_hw_data
*ha
= base_vha
->hw
;
463 scsi_qla_host_t
*vha
;
464 struct scsi_host_template
*sht
= &qla2xxx_driver_template
;
465 struct Scsi_Host
*host
;
467 vha
= qla2x00_create_host(sht
, ha
);
469 ql_log(ql_log_warn
, vha
, 0xa005,
470 "scsi_host_alloc() failed for vport.\n");
475 fc_vport
->dd_data
= vha
;
477 u64_to_wwn(fc_vport
->node_name
, vha
->node_name
);
478 u64_to_wwn(fc_vport
->port_name
, vha
->port_name
);
480 vha
->fc_vport
= fc_vport
;
481 vha
->device_flags
= 0;
482 vha
->vp_idx
= qla24xx_allocate_vp_id(vha
);
483 if (vha
->vp_idx
> ha
->max_npiv_vports
) {
484 ql_dbg(ql_dbg_vport
, vha
, 0xa006,
485 "Couldn't allocate vp_id.\n");
486 goto create_vhost_failed
;
488 vha
->mgmt_svr_loop_id
= NPH_MGMT_SERVER
;
493 * To fix the issue of processing a parent's RSCN for the vport before
494 * its SCR is complete.
496 set_bit(VP_SCR_NEEDED
, &vha
->vp_flags
);
497 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
498 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
500 qla2x00_start_timer(vha
, WATCH_INTERVAL
);
502 vha
->req
= base_vha
->req
;
503 host
->can_queue
= base_vha
->req
->length
+ 128;
504 host
->cmd_per_lun
= 3;
505 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
)
506 host
->max_cmd_len
= 32;
508 host
->max_cmd_len
= MAX_CMDSZ
;
509 host
->max_channel
= MAX_BUSES
- 1;
510 host
->max_lun
= ql2xmaxlun
;
511 host
->unique_id
= host
->host_no
;
512 host
->max_id
= ha
->max_fibre_devices
;
513 host
->transportt
= qla2xxx_transport_vport_template
;
515 ql_dbg(ql_dbg_vport
, vha
, 0xa007,
516 "Detect vport hba %ld at address = %p.\n",
519 vha
->flags
.init_done
= 1;
521 mutex_lock(&ha
->vport_lock
);
522 set_bit(vha
->vp_idx
, ha
->vp_idx_map
);
523 ha
->cur_vport_count
++;
524 mutex_unlock(&ha
->vport_lock
);
533 qla25xx_free_req_que(struct scsi_qla_host
*vha
, struct req_que
*req
)
535 struct qla_hw_data
*ha
= vha
->hw
;
536 uint16_t que_id
= req
->id
;
538 dma_free_coherent(&ha
->pdev
->dev
, (req
->length
+ 1) *
539 sizeof(request_t
), req
->ring
, req
->dma
);
543 ha
->req_q_map
[que_id
] = NULL
;
544 mutex_lock(&ha
->vport_lock
);
545 clear_bit(que_id
, ha
->req_qid_map
);
546 mutex_unlock(&ha
->vport_lock
);
548 kfree(req
->outstanding_cmds
);
554 qla25xx_free_rsp_que(struct scsi_qla_host
*vha
, struct rsp_que
*rsp
)
556 struct qla_hw_data
*ha
= vha
->hw
;
557 uint16_t que_id
= rsp
->id
;
559 if (rsp
->msix
&& rsp
->msix
->have_irq
) {
560 free_irq(rsp
->msix
->vector
, rsp
->msix
->handle
);
561 rsp
->msix
->have_irq
= 0;
562 rsp
->msix
->in_use
= 0;
563 rsp
->msix
->handle
= NULL
;
565 dma_free_coherent(&ha
->pdev
->dev
, (rsp
->length
+ 1) *
566 sizeof(response_t
), rsp
->ring
, rsp
->dma
);
570 ha
->rsp_q_map
[que_id
] = NULL
;
571 mutex_lock(&ha
->vport_lock
);
572 clear_bit(que_id
, ha
->rsp_qid_map
);
573 mutex_unlock(&ha
->vport_lock
);
580 qla25xx_delete_req_que(struct scsi_qla_host
*vha
, struct req_que
*req
)
582 int ret
= QLA_SUCCESS
;
584 if (req
&& vha
->flags
.qpairs_req_created
) {
585 req
->options
|= BIT_0
;
586 ret
= qla25xx_init_req_que(vha
, req
);
587 if (ret
!= QLA_SUCCESS
)
588 return QLA_FUNCTION_FAILED
;
590 qla25xx_free_req_que(vha
, req
);
597 qla25xx_delete_rsp_que(struct scsi_qla_host
*vha
, struct rsp_que
*rsp
)
599 int ret
= QLA_SUCCESS
;
601 if (rsp
&& vha
->flags
.qpairs_rsp_created
) {
602 rsp
->options
|= BIT_0
;
603 ret
= qla25xx_init_rsp_que(vha
, rsp
);
604 if (ret
!= QLA_SUCCESS
)
605 return QLA_FUNCTION_FAILED
;
607 qla25xx_free_rsp_que(vha
, rsp
);
613 /* Delete all queues for a given vhost */
615 qla25xx_delete_queues(struct scsi_qla_host
*vha
)
618 struct req_que
*req
= NULL
;
619 struct rsp_que
*rsp
= NULL
;
620 struct qla_hw_data
*ha
= vha
->hw
;
621 struct qla_qpair
*qpair
, *tqpair
;
623 if (ql2xmqsupport
|| ql2xnvmeenable
) {
624 list_for_each_entry_safe(qpair
, tqpair
, &vha
->qp_list
,
626 qla2xxx_delete_qpair(vha
, qpair
);
628 /* Delete request queues */
629 for (cnt
= 1; cnt
< ha
->max_req_queues
; cnt
++) {
630 req
= ha
->req_q_map
[cnt
];
631 if (req
&& test_bit(cnt
, ha
->req_qid_map
)) {
632 ret
= qla25xx_delete_req_que(vha
, req
);
633 if (ret
!= QLA_SUCCESS
) {
634 ql_log(ql_log_warn
, vha
, 0x00ea,
635 "Couldn't delete req que %d.\n",
642 /* Delete response queues */
643 for (cnt
= 1; cnt
< ha
->max_rsp_queues
; cnt
++) {
644 rsp
= ha
->rsp_q_map
[cnt
];
645 if (rsp
&& test_bit(cnt
, ha
->rsp_qid_map
)) {
646 ret
= qla25xx_delete_rsp_que(vha
, rsp
);
647 if (ret
!= QLA_SUCCESS
) {
648 ql_log(ql_log_warn
, vha
, 0x00eb,
649 "Couldn't delete rsp que %d.\n",
661 qla25xx_create_req_que(struct qla_hw_data
*ha
, uint16_t options
,
662 uint8_t vp_idx
, uint16_t rid
, int rsp_que
, uint8_t qos
, bool startqp
)
665 struct req_que
*req
= NULL
;
666 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
667 struct scsi_qla_host
*vha
= pci_get_drvdata(ha
->pdev
);
672 req
= kzalloc(sizeof(struct req_que
), GFP_KERNEL
);
674 ql_log(ql_log_fatal
, base_vha
, 0x00d9,
675 "Failed to allocate memory for request queue.\n");
679 req
->length
= REQUEST_ENTRY_CNT_24XX
;
680 req
->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
681 (req
->length
+ 1) * sizeof(request_t
),
682 &req
->dma
, GFP_KERNEL
);
683 if (req
->ring
== NULL
) {
684 ql_log(ql_log_fatal
, base_vha
, 0x00da,
685 "Failed to allocate memory for request_ring.\n");
689 ret
= qla2x00_alloc_outstanding_cmds(ha
, req
);
690 if (ret
!= QLA_SUCCESS
)
693 mutex_lock(&ha
->mq_lock
);
694 que_id
= find_first_zero_bit(ha
->req_qid_map
, ha
->max_req_queues
);
695 if (que_id
>= ha
->max_req_queues
) {
696 mutex_unlock(&ha
->mq_lock
);
697 ql_log(ql_log_warn
, base_vha
, 0x00db,
698 "No resources to create additional request queue.\n");
701 set_bit(que_id
, ha
->req_qid_map
);
702 ha
->req_q_map
[que_id
] = req
;
704 req
->vp_idx
= vp_idx
;
707 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc002,
708 "queue_id=%d rid=%d vp_idx=%d qos=%d.\n",
709 que_id
, req
->rid
, req
->vp_idx
, req
->qos
);
710 ql_dbg(ql_dbg_init
, base_vha
, 0x00dc,
711 "queue_id=%d rid=%d vp_idx=%d qos=%d.\n",
712 que_id
, req
->rid
, req
->vp_idx
, req
->qos
);
716 req
->rsp
= ha
->rsp_q_map
[rsp_que
];
717 /* Use alternate PCI bus number */
720 /* Use alternate PCI devfn */
723 req
->options
= options
;
725 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc003,
726 "options=0x%x.\n", req
->options
);
727 ql_dbg(ql_dbg_init
, base_vha
, 0x00dd,
728 "options=0x%x.\n", req
->options
);
729 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++)
730 req
->outstanding_cmds
[cnt
] = NULL
;
731 req
->current_outstanding_cmd
= 1;
733 req
->ring_ptr
= req
->ring
;
735 req
->cnt
= req
->length
;
737 reg
= ISP_QUE_REG(ha
, que_id
);
738 req
->req_q_in
= ®
->isp25mq
.req_q_in
;
739 req
->req_q_out
= ®
->isp25mq
.req_q_out
;
740 req
->max_q_depth
= ha
->req_q_map
[0]->max_q_depth
;
741 req
->out_ptr
= (void *)(req
->ring
+ req
->length
);
742 mutex_unlock(&ha
->mq_lock
);
743 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc004,
744 "ring_ptr=%p ring_index=%d, "
745 "cnt=%d id=%d max_q_depth=%d.\n",
746 req
->ring_ptr
, req
->ring_index
,
747 req
->cnt
, req
->id
, req
->max_q_depth
);
748 ql_dbg(ql_dbg_init
, base_vha
, 0x00de,
749 "ring_ptr=%p ring_index=%d, "
750 "cnt=%d id=%d max_q_depth=%d.\n",
751 req
->ring_ptr
, req
->ring_index
, req
->cnt
,
752 req
->id
, req
->max_q_depth
);
755 ret
= qla25xx_init_req_que(base_vha
, req
);
756 if (ret
!= QLA_SUCCESS
) {
757 ql_log(ql_log_fatal
, base_vha
, 0x00df,
758 "%s failed.\n", __func__
);
759 mutex_lock(&ha
->mq_lock
);
760 clear_bit(que_id
, ha
->req_qid_map
);
761 mutex_unlock(&ha
->mq_lock
);
764 vha
->flags
.qpairs_req_created
= 1;
770 qla25xx_free_req_que(base_vha
, req
);
775 static void qla_do_work(struct work_struct
*work
)
778 struct qla_qpair
*qpair
= container_of(work
, struct qla_qpair
, q_work
);
779 struct scsi_qla_host
*vha
;
780 struct qla_hw_data
*ha
= qpair
->hw
;
782 spin_lock_irqsave(&qpair
->qp_lock
, flags
);
783 vha
= pci_get_drvdata(ha
->pdev
);
784 qla24xx_process_response_queue(vha
, qpair
->rsp
);
785 spin_unlock_irqrestore(&qpair
->qp_lock
, flags
);
789 /* create response queue */
791 qla25xx_create_rsp_que(struct qla_hw_data
*ha
, uint16_t options
,
792 uint8_t vp_idx
, uint16_t rid
, struct qla_qpair
*qpair
, bool startqp
)
795 struct rsp_que
*rsp
= NULL
;
796 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
797 struct scsi_qla_host
*vha
= pci_get_drvdata(ha
->pdev
);
801 rsp
= kzalloc(sizeof(struct rsp_que
), GFP_KERNEL
);
803 ql_log(ql_log_warn
, base_vha
, 0x0066,
804 "Failed to allocate memory for response queue.\n");
808 rsp
->length
= RESPONSE_ENTRY_CNT_MQ
;
809 rsp
->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
810 (rsp
->length
+ 1) * sizeof(response_t
),
811 &rsp
->dma
, GFP_KERNEL
);
812 if (rsp
->ring
== NULL
) {
813 ql_log(ql_log_warn
, base_vha
, 0x00e1,
814 "Failed to allocate memory for response ring.\n");
818 mutex_lock(&ha
->mq_lock
);
819 que_id
= find_first_zero_bit(ha
->rsp_qid_map
, ha
->max_rsp_queues
);
820 if (que_id
>= ha
->max_rsp_queues
) {
821 mutex_unlock(&ha
->mq_lock
);
822 ql_log(ql_log_warn
, base_vha
, 0x00e2,
823 "No resources to create additional request queue.\n");
826 set_bit(que_id
, ha
->rsp_qid_map
);
828 rsp
->msix
= qpair
->msix
;
830 ha
->rsp_q_map
[que_id
] = rsp
;
832 rsp
->vp_idx
= vp_idx
;
834 ql_dbg(ql_dbg_init
, base_vha
, 0x00e4,
835 "rsp queue_id=%d rid=%d vp_idx=%d hw=%p.\n",
836 que_id
, rsp
->rid
, rsp
->vp_idx
, rsp
->hw
);
837 /* Use alternate PCI bus number */
840 /* Use alternate PCI devfn */
843 /* Enable MSIX handshake mode on for uncapable adapters */
844 if (!IS_MSIX_NACK_CAPABLE(ha
))
847 /* Set option to indicate response queue creation */
850 rsp
->options
= options
;
852 reg
= ISP_QUE_REG(ha
, que_id
);
853 rsp
->rsp_q_in
= ®
->isp25mq
.rsp_q_in
;
854 rsp
->rsp_q_out
= ®
->isp25mq
.rsp_q_out
;
855 rsp
->in_ptr
= (void *)(rsp
->ring
+ rsp
->length
);
856 mutex_unlock(&ha
->mq_lock
);
857 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc00b,
858 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p\n",
859 rsp
->options
, rsp
->id
, rsp
->rsp_q_in
,
861 ql_dbg(ql_dbg_init
, base_vha
, 0x00e5,
862 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p\n",
863 rsp
->options
, rsp
->id
, rsp
->rsp_q_in
,
866 ret
= qla25xx_request_irq(ha
, qpair
, qpair
->msix
,
867 QLA_MSIX_QPAIR_MULTIQ_RSP_Q
);
872 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
873 if (ret
!= QLA_SUCCESS
) {
874 ql_log(ql_log_fatal
, base_vha
, 0x00e7,
875 "%s failed.\n", __func__
);
876 mutex_lock(&ha
->mq_lock
);
877 clear_bit(que_id
, ha
->rsp_qid_map
);
878 mutex_unlock(&ha
->mq_lock
);
881 vha
->flags
.qpairs_rsp_created
= 1;
885 qla2x00_init_response_q_entries(rsp
);
887 INIT_WORK(&qpair
->q_work
, qla_do_work
);
891 qla25xx_free_rsp_que(base_vha
, rsp
);
896 static void qla_ctrlvp_sp_done(void *s
, int res
)
901 /* don't free sp here. Let the caller do the free */
905 * qla24xx_control_vp() - Enable a virtual port for given host
906 * @vha: adapter block pointer
907 * @cmd: command type to be sent for enable virtual port
909 * Return: qla2xxx local function return status code.
911 int qla24xx_control_vp(scsi_qla_host_t
*vha
, int cmd
)
913 int rval
= QLA_MEMORY_ALLOC_FAILED
;
914 struct qla_hw_data
*ha
= vha
->hw
;
915 int vp_index
= vha
->vp_idx
;
916 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
919 ql_dbg(ql_dbg_vport
, vha
, 0x10c1,
920 "Entered %s cmd %x index %d.\n", __func__
, cmd
, vp_index
);
922 if (vp_index
== 0 || vp_index
>= ha
->max_npiv_vports
)
923 return QLA_PARAMETER_ERROR
;
925 sp
= qla2x00_get_sp(base_vha
, NULL
, GFP_KERNEL
);
929 sp
->type
= SRB_CTRL_VP
;
930 sp
->name
= "ctrl_vp";
931 sp
->done
= qla_ctrlvp_sp_done
;
932 sp
->u
.iocb_cmd
.timeout
= qla2x00_async_iocb_timeout
;
933 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
934 sp
->u
.iocb_cmd
.u
.ctrlvp
.cmd
= cmd
;
935 sp
->u
.iocb_cmd
.u
.ctrlvp
.vp_index
= vp_index
;
937 rval
= qla2x00_start_sp(sp
);
938 if (rval
!= QLA_SUCCESS
) {
939 ql_dbg(ql_dbg_async
, vha
, 0xffff,
940 "%s: %s Failed submission. %x.\n",
941 __func__
, sp
->name
, rval
);
945 ql_dbg(ql_dbg_vport
, vha
, 0x113f, "%s hndl %x submitted\n",
946 sp
->name
, sp
->handle
);
948 wait_for_completion(&sp
->comp
);
951 case QLA_FUNCTION_TIMEOUT
:
952 ql_dbg(ql_dbg_vport
, vha
, 0xffff, "%s: %s Timeout. %x.\n",
953 __func__
, sp
->name
, rval
);
956 ql_dbg(ql_dbg_vport
, vha
, 0xffff, "%s: %s done.\n",
960 ql_dbg(ql_dbg_vport
, vha
, 0xffff, "%s: %s Failed. %x.\n",
961 __func__
, sp
->name
, rval
);