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
78 for (i
= 0; i
< 10; i
++) {
79 if (wait_event_timeout(vha
->vref_waitq
,
80 !atomic_read(&vha
->vref_count
), HZ
) > 0)
84 spin_lock_irqsave(&ha
->vport_slock
, flags
);
85 if (atomic_read(&vha
->vref_count
)) {
86 ql_dbg(ql_dbg_vport
, vha
, 0xfffa,
87 "vha->vref_count=%u timeout\n", vha
->vref_count
.counter
);
88 vha
->vref_count
= (atomic_t
)ATOMIC_INIT(0);
91 qlt_update_vp_map(vha
, RESET_VP_IDX
);
92 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
96 clear_bit(vp_id
, ha
->vp_idx_map
);
98 mutex_unlock(&ha
->vport_lock
);
101 static scsi_qla_host_t
*
102 qla24xx_find_vhost_by_name(struct qla_hw_data
*ha
, uint8_t *port_name
)
104 scsi_qla_host_t
*vha
;
105 struct scsi_qla_host
*tvha
;
108 spin_lock_irqsave(&ha
->vport_slock
, flags
);
109 /* Locate matching device in database. */
110 list_for_each_entry_safe(vha
, tvha
, &ha
->vp_list
, list
) {
111 if (!memcmp(port_name
, vha
->port_name
, WWN_SIZE
)) {
112 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
116 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
121 * qla2x00_mark_vp_devices_dead
122 * Updates fcport state when device goes offline.
125 * ha = adapter block pointer.
126 * fcport = port structure pointer.
134 qla2x00_mark_vp_devices_dead(scsi_qla_host_t
*vha
)
138 * This function, if called in contexts other than vp create, disable
139 * or delete, please make sure this is synchronized with the
144 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
145 ql_dbg(ql_dbg_vport
, vha
, 0xa001,
146 "Marking port dead, loop_id=0x%04x : %x.\n",
147 fcport
->loop_id
, fcport
->vha
->vp_idx
);
149 qla2x00_mark_device_lost(vha
, fcport
, 0);
150 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
155 qla24xx_disable_vp(scsi_qla_host_t
*vha
)
158 int ret
= QLA_SUCCESS
;
161 if (vha
->hw
->flags
.fw_started
)
162 ret
= qla24xx_control_vp(vha
, VCE_COMMAND_DISABLE_VPS_LOGO_ALL
);
164 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
165 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
166 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
167 fcport
->logout_on_delete
= 0;
169 qla2x00_mark_all_devices_lost(vha
);
171 /* Remove port id from vp target map */
172 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
173 qlt_update_vp_map(vha
, RESET_AL_PA
);
174 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
176 qla2x00_mark_vp_devices_dead(vha
);
177 atomic_set(&vha
->vp_state
, VP_FAILED
);
178 vha
->flags
.management_server_logged_in
= 0;
179 if (ret
== QLA_SUCCESS
) {
180 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_DISABLED
);
182 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
189 qla24xx_enable_vp(scsi_qla_host_t
*vha
)
192 struct qla_hw_data
*ha
= vha
->hw
;
193 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
195 /* Check if physical ha port is Up */
196 if (atomic_read(&base_vha
->loop_state
) == LOOP_DOWN
||
197 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
||
198 !(ha
->current_topology
& ISP_CFG_F
)) {
199 vha
->vp_err_state
= VP_ERR_PORTDWN
;
200 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_LINKDOWN
);
201 ql_dbg(ql_dbg_taskm
, vha
, 0x800b,
202 "%s skip enable. loop_state %x topo %x\n",
203 __func__
, base_vha
->loop_state
.counter
,
204 ha
->current_topology
);
209 /* Initialize the new vport unless it is a persistent port */
210 mutex_lock(&ha
->vport_lock
);
211 ret
= qla24xx_modify_vp_config(vha
);
212 mutex_unlock(&ha
->vport_lock
);
214 if (ret
!= QLA_SUCCESS
) {
215 fc_vport_set_state(vha
->fc_vport
, FC_VPORT_FAILED
);
219 ql_dbg(ql_dbg_taskm
, vha
, 0x801a,
220 "Virtual port with id: %d - Enabled.\n", vha
->vp_idx
);
224 ql_dbg(ql_dbg_taskm
, vha
, 0x801b,
225 "Virtual port with id: %d - Disabled.\n", vha
->vp_idx
);
230 qla24xx_configure_vp(scsi_qla_host_t
*vha
)
232 struct fc_vport
*fc_vport
;
235 fc_vport
= vha
->fc_vport
;
237 ql_dbg(ql_dbg_vport
, vha
, 0xa002,
238 "%s: change request #3.\n", __func__
);
239 ret
= qla2x00_send_change_request(vha
, 0x3, vha
->vp_idx
);
240 if (ret
!= QLA_SUCCESS
) {
241 ql_dbg(ql_dbg_vport
, vha
, 0xa003, "Failed to enable "
242 "receiving of RSCN requests: 0x%x.\n", ret
);
245 /* Corresponds to SCR enabled */
246 clear_bit(VP_SCR_NEEDED
, &vha
->vp_flags
);
249 vha
->flags
.online
= 1;
250 if (qla24xx_configure_vhba(vha
))
253 atomic_set(&vha
->vp_state
, VP_ACTIVE
);
254 fc_vport_set_state(fc_vport
, FC_VPORT_ACTIVE
);
258 qla2x00_alert_all_vps(struct rsp_que
*rsp
, uint16_t *mb
)
260 scsi_qla_host_t
*vha
;
261 struct qla_hw_data
*ha
= rsp
->hw
;
265 spin_lock_irqsave(&ha
->vport_slock
, flags
);
266 list_for_each_entry(vha
, &ha
->vp_list
, list
) {
268 if (test_bit(VPORT_DELETE
, &vha
->dpc_flags
))
271 atomic_inc(&vha
->vref_count
);
272 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
275 case MBA_LIP_OCCURRED
:
279 case MBA_POINT_TO_POINT
:
280 case MBA_CHG_IN_CONNECTION
:
281 ql_dbg(ql_dbg_async
, vha
, 0x5024,
282 "Async_event for VP[%d], mb=0x%x vha=%p.\n",
284 qla2x00_async_event(vha
, rsp
, mb
);
286 case MBA_PORT_UPDATE
:
287 case MBA_RSCN_UPDATE
:
288 if ((mb
[3] & 0xff) == vha
->vp_idx
) {
289 ql_dbg(ql_dbg_async
, vha
, 0x5024,
290 "Async_event for VP[%d], mb=0x%x vha=%p\n",
292 qla2x00_async_event(vha
, rsp
, mb
);
297 spin_lock_irqsave(&ha
->vport_slock
, flags
);
298 atomic_dec(&vha
->vref_count
);
299 wake_up(&vha
->vref_waitq
);
303 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
307 qla2x00_vp_abort_isp(scsi_qla_host_t
*vha
)
312 * To exclusively reset vport, we need to log it out first.
313 * Note: This control_vp can fail if ISP reset is already
314 * issued, this is expected, as the vp would be already
315 * logged out due to ISP reset.
317 if (!test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
)) {
318 qla24xx_control_vp(vha
, VCE_COMMAND_DISABLE_VPS_LOGO_ALL
);
319 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
320 fcport
->logout_on_delete
= 0;
324 * Physical port will do most of the abort and recovery work. We can
325 * just treat it as a loop down
327 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
328 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
329 qla2x00_mark_all_devices_lost(vha
);
331 if (!atomic_read(&vha
->loop_down_timer
))
332 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
335 ql_dbg(ql_dbg_taskm
, vha
, 0x801d,
336 "Scheduling enable of Vport %d.\n", vha
->vp_idx
);
338 return qla24xx_enable_vp(vha
);
342 qla2x00_do_dpc_vp(scsi_qla_host_t
*vha
)
344 struct qla_hw_data
*ha
= vha
->hw
;
345 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
347 ql_dbg(ql_dbg_dpc
+ ql_dbg_verbose
, vha
, 0x4012,
348 "Entering %s vp_flags: 0x%lx.\n", __func__
, vha
->vp_flags
);
350 /* Check if Fw is ready to configure VP first */
351 if (test_bit(VP_CONFIG_OK
, &base_vha
->vp_flags
)) {
352 if (test_and_clear_bit(VP_IDX_ACQUIRED
, &vha
->vp_flags
)) {
353 /* VP acquired. complete port configuration */
354 ql_dbg(ql_dbg_dpc
, vha
, 0x4014,
355 "Configure VP scheduled.\n");
356 qla24xx_configure_vp(vha
);
357 ql_dbg(ql_dbg_dpc
, vha
, 0x4015,
358 "Configure VP end.\n");
363 if (test_bit(PROCESS_PUREX_IOCB
, &vha
->dpc_flags
)) {
364 if (atomic_read(&vha
->loop_state
) == LOOP_READY
) {
365 qla24xx_process_purex_list(&vha
->purex_list
);
366 clear_bit(PROCESS_PUREX_IOCB
, &vha
->dpc_flags
);
370 if (test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
)) {
371 ql_dbg(ql_dbg_dpc
, vha
, 0x4016,
372 "FCPort update scheduled.\n");
373 qla2x00_update_fcports(vha
);
374 clear_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
);
375 ql_dbg(ql_dbg_dpc
, vha
, 0x4017,
376 "FCPort update end.\n");
379 if (test_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
) &&
380 !test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) &&
381 atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
383 if (!vha
->relogin_jif
||
384 time_after_eq(jiffies
, vha
->relogin_jif
)) {
385 vha
->relogin_jif
= jiffies
+ HZ
;
386 clear_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
388 ql_dbg(ql_dbg_dpc
, vha
, 0x4018,
389 "Relogin needed scheduled.\n");
390 qla24xx_post_relogin_work(vha
);
394 if (test_and_clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
) &&
395 (!(test_and_set_bit(RESET_ACTIVE
, &vha
->dpc_flags
)))) {
396 clear_bit(RESET_ACTIVE
, &vha
->dpc_flags
);
399 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
400 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
))) {
401 ql_dbg(ql_dbg_dpc
, vha
, 0x401a,
402 "Loop resync scheduled.\n");
403 qla2x00_loop_resync(vha
);
404 clear_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
);
405 ql_dbg(ql_dbg_dpc
, vha
, 0x401b,
406 "Loop resync end.\n");
410 ql_dbg(ql_dbg_dpc
+ ql_dbg_verbose
, vha
, 0x401c,
411 "Exiting %s.\n", __func__
);
416 qla2x00_do_dpc_all_vps(scsi_qla_host_t
*vha
)
418 struct qla_hw_data
*ha
= vha
->hw
;
420 unsigned long flags
= 0;
424 if (list_empty(&ha
->vp_list
))
427 clear_bit(VP_DPC_NEEDED
, &vha
->dpc_flags
);
429 if (!(ha
->current_topology
& ISP_CFG_F
))
432 spin_lock_irqsave(&ha
->vport_slock
, flags
);
433 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
435 atomic_inc(&vp
->vref_count
);
436 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
438 qla2x00_do_dpc_vp(vp
);
440 spin_lock_irqsave(&ha
->vport_slock
, flags
);
441 atomic_dec(&vp
->vref_count
);
444 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
448 qla24xx_vport_create_req_sanity_check(struct fc_vport
*fc_vport
)
450 scsi_qla_host_t
*base_vha
= shost_priv(fc_vport
->shost
);
451 struct qla_hw_data
*ha
= base_vha
->hw
;
452 scsi_qla_host_t
*vha
;
453 uint8_t port_name
[WWN_SIZE
];
455 if (fc_vport
->roles
!= FC_PORT_ROLE_FCP_INITIATOR
)
456 return VPCERR_UNSUPPORTED
;
458 /* Check up the F/W and H/W support NPIV */
459 if (!ha
->flags
.npiv_supported
)
460 return VPCERR_UNSUPPORTED
;
462 /* Check up whether npiv supported switch presented */
463 if (!(ha
->switch_cap
& FLOGI_MID_SUPPORT
))
464 return VPCERR_NO_FABRIC_SUPP
;
466 /* Check up unique WWPN */
467 u64_to_wwn(fc_vport
->port_name
, port_name
);
468 if (!memcmp(port_name
, base_vha
->port_name
, WWN_SIZE
))
469 return VPCERR_BAD_WWN
;
470 vha
= qla24xx_find_vhost_by_name(ha
, port_name
);
472 return VPCERR_BAD_WWN
;
474 /* Check up max-npiv-supports */
475 if (ha
->num_vhosts
> ha
->max_npiv_vports
) {
476 ql_dbg(ql_dbg_vport
, vha
, 0xa004,
477 "num_vhosts %ud is bigger "
478 "than max_npiv_vports %ud.\n",
479 ha
->num_vhosts
, ha
->max_npiv_vports
);
480 return VPCERR_UNSUPPORTED
;
486 qla24xx_create_vhost(struct fc_vport
*fc_vport
)
488 scsi_qla_host_t
*base_vha
= shost_priv(fc_vport
->shost
);
489 struct qla_hw_data
*ha
= base_vha
->hw
;
490 scsi_qla_host_t
*vha
;
491 struct scsi_host_template
*sht
= &qla2xxx_driver_template
;
492 struct Scsi_Host
*host
;
494 vha
= qla2x00_create_host(sht
, ha
);
496 ql_log(ql_log_warn
, vha
, 0xa005,
497 "scsi_host_alloc() failed for vport.\n");
502 fc_vport
->dd_data
= vha
;
504 u64_to_wwn(fc_vport
->node_name
, vha
->node_name
);
505 u64_to_wwn(fc_vport
->port_name
, vha
->port_name
);
507 vha
->fc_vport
= fc_vport
;
508 vha
->device_flags
= 0;
509 vha
->vp_idx
= qla24xx_allocate_vp_id(vha
);
510 if (vha
->vp_idx
> ha
->max_npiv_vports
) {
511 ql_dbg(ql_dbg_vport
, vha
, 0xa006,
512 "Couldn't allocate vp_id.\n");
513 goto create_vhost_failed
;
515 vha
->mgmt_svr_loop_id
= qla2x00_reserve_mgmt_server_loop_id(vha
);
519 set_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
);
520 set_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
);
523 * To fix the issue of processing a parent's RSCN for the vport before
524 * its SCR is complete.
526 set_bit(VP_SCR_NEEDED
, &vha
->vp_flags
);
527 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
528 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
530 qla2x00_start_timer(vha
, WATCH_INTERVAL
);
532 vha
->req
= base_vha
->req
;
533 vha
->flags
.nvme_enabled
= base_vha
->flags
.nvme_enabled
;
534 host
->can_queue
= base_vha
->req
->length
+ 128;
535 host
->cmd_per_lun
= 3;
536 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
)
537 host
->max_cmd_len
= 32;
539 host
->max_cmd_len
= MAX_CMDSZ
;
540 host
->max_channel
= MAX_BUSES
- 1;
541 host
->max_lun
= ql2xmaxlun
;
542 host
->unique_id
= host
->host_no
;
543 host
->max_id
= ha
->max_fibre_devices
;
544 host
->transportt
= qla2xxx_transport_vport_template
;
546 ql_dbg(ql_dbg_vport
, vha
, 0xa007,
547 "Detect vport hba %ld at address = %p.\n",
550 vha
->flags
.init_done
= 1;
552 mutex_lock(&ha
->vport_lock
);
553 set_bit(vha
->vp_idx
, ha
->vp_idx_map
);
554 ha
->cur_vport_count
++;
555 mutex_unlock(&ha
->vport_lock
);
564 qla25xx_free_req_que(struct scsi_qla_host
*vha
, struct req_que
*req
)
566 struct qla_hw_data
*ha
= vha
->hw
;
567 uint16_t que_id
= req
->id
;
569 dma_free_coherent(&ha
->pdev
->dev
, (req
->length
+ 1) *
570 sizeof(request_t
), req
->ring
, req
->dma
);
574 ha
->req_q_map
[que_id
] = NULL
;
575 mutex_lock(&ha
->vport_lock
);
576 clear_bit(que_id
, ha
->req_qid_map
);
577 mutex_unlock(&ha
->vport_lock
);
579 kfree(req
->outstanding_cmds
);
585 qla25xx_free_rsp_que(struct scsi_qla_host
*vha
, struct rsp_que
*rsp
)
587 struct qla_hw_data
*ha
= vha
->hw
;
588 uint16_t que_id
= rsp
->id
;
590 if (rsp
->msix
&& rsp
->msix
->have_irq
) {
591 free_irq(rsp
->msix
->vector
, rsp
->msix
->handle
);
592 rsp
->msix
->have_irq
= 0;
593 rsp
->msix
->in_use
= 0;
594 rsp
->msix
->handle
= NULL
;
596 dma_free_coherent(&ha
->pdev
->dev
, (rsp
->length
+ 1) *
597 sizeof(response_t
), rsp
->ring
, rsp
->dma
);
601 ha
->rsp_q_map
[que_id
] = NULL
;
602 mutex_lock(&ha
->vport_lock
);
603 clear_bit(que_id
, ha
->rsp_qid_map
);
604 mutex_unlock(&ha
->vport_lock
);
611 qla25xx_delete_req_que(struct scsi_qla_host
*vha
, struct req_que
*req
)
613 int ret
= QLA_SUCCESS
;
615 if (req
&& vha
->flags
.qpairs_req_created
) {
616 req
->options
|= BIT_0
;
617 ret
= qla25xx_init_req_que(vha
, req
);
618 if (ret
!= QLA_SUCCESS
)
619 return QLA_FUNCTION_FAILED
;
621 qla25xx_free_req_que(vha
, req
);
628 qla25xx_delete_rsp_que(struct scsi_qla_host
*vha
, struct rsp_que
*rsp
)
630 int ret
= QLA_SUCCESS
;
632 if (rsp
&& vha
->flags
.qpairs_rsp_created
) {
633 rsp
->options
|= BIT_0
;
634 ret
= qla25xx_init_rsp_que(vha
, rsp
);
635 if (ret
!= QLA_SUCCESS
)
636 return QLA_FUNCTION_FAILED
;
638 qla25xx_free_rsp_que(vha
, rsp
);
644 /* Delete all queues for a given vhost */
646 qla25xx_delete_queues(struct scsi_qla_host
*vha
)
649 struct req_que
*req
= NULL
;
650 struct rsp_que
*rsp
= NULL
;
651 struct qla_hw_data
*ha
= vha
->hw
;
652 struct qla_qpair
*qpair
, *tqpair
;
654 if (ql2xmqsupport
|| ql2xnvmeenable
) {
655 list_for_each_entry_safe(qpair
, tqpair
, &vha
->qp_list
,
657 qla2xxx_delete_qpair(vha
, qpair
);
659 /* Delete request queues */
660 for (cnt
= 1; cnt
< ha
->max_req_queues
; cnt
++) {
661 req
= ha
->req_q_map
[cnt
];
662 if (req
&& test_bit(cnt
, ha
->req_qid_map
)) {
663 ret
= qla25xx_delete_req_que(vha
, req
);
664 if (ret
!= QLA_SUCCESS
) {
665 ql_log(ql_log_warn
, vha
, 0x00ea,
666 "Couldn't delete req que %d.\n",
673 /* Delete response queues */
674 for (cnt
= 1; cnt
< ha
->max_rsp_queues
; cnt
++) {
675 rsp
= ha
->rsp_q_map
[cnt
];
676 if (rsp
&& test_bit(cnt
, ha
->rsp_qid_map
)) {
677 ret
= qla25xx_delete_rsp_que(vha
, rsp
);
678 if (ret
!= QLA_SUCCESS
) {
679 ql_log(ql_log_warn
, vha
, 0x00eb,
680 "Couldn't delete rsp que %d.\n",
692 qla25xx_create_req_que(struct qla_hw_data
*ha
, uint16_t options
,
693 uint8_t vp_idx
, uint16_t rid
, int rsp_que
, uint8_t qos
, bool startqp
)
696 struct req_que
*req
= NULL
;
697 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
698 struct scsi_qla_host
*vha
= pci_get_drvdata(ha
->pdev
);
703 req
= kzalloc(sizeof(struct req_que
), GFP_KERNEL
);
705 ql_log(ql_log_fatal
, base_vha
, 0x00d9,
706 "Failed to allocate memory for request queue.\n");
710 req
->length
= REQUEST_ENTRY_CNT_24XX
;
711 req
->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
712 (req
->length
+ 1) * sizeof(request_t
),
713 &req
->dma
, GFP_KERNEL
);
714 if (req
->ring
== NULL
) {
715 ql_log(ql_log_fatal
, base_vha
, 0x00da,
716 "Failed to allocate memory for request_ring.\n");
720 ret
= qla2x00_alloc_outstanding_cmds(ha
, req
);
721 if (ret
!= QLA_SUCCESS
)
724 mutex_lock(&ha
->mq_lock
);
725 que_id
= find_first_zero_bit(ha
->req_qid_map
, ha
->max_req_queues
);
726 if (que_id
>= ha
->max_req_queues
) {
727 mutex_unlock(&ha
->mq_lock
);
728 ql_log(ql_log_warn
, base_vha
, 0x00db,
729 "No resources to create additional request queue.\n");
732 set_bit(que_id
, ha
->req_qid_map
);
733 ha
->req_q_map
[que_id
] = req
;
735 req
->vp_idx
= vp_idx
;
738 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc002,
739 "queue_id=%d rid=%d vp_idx=%d qos=%d.\n",
740 que_id
, req
->rid
, req
->vp_idx
, req
->qos
);
741 ql_dbg(ql_dbg_init
, base_vha
, 0x00dc,
742 "queue_id=%d rid=%d vp_idx=%d qos=%d.\n",
743 que_id
, req
->rid
, req
->vp_idx
, req
->qos
);
747 req
->rsp
= ha
->rsp_q_map
[rsp_que
];
748 /* Use alternate PCI bus number */
751 /* Use alternate PCI devfn */
754 req
->options
= options
;
756 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc003,
757 "options=0x%x.\n", req
->options
);
758 ql_dbg(ql_dbg_init
, base_vha
, 0x00dd,
759 "options=0x%x.\n", req
->options
);
760 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++)
761 req
->outstanding_cmds
[cnt
] = NULL
;
762 req
->current_outstanding_cmd
= 1;
764 req
->ring_ptr
= req
->ring
;
766 req
->cnt
= req
->length
;
768 reg
= ISP_QUE_REG(ha
, que_id
);
769 req
->req_q_in
= ®
->isp25mq
.req_q_in
;
770 req
->req_q_out
= ®
->isp25mq
.req_q_out
;
771 req
->max_q_depth
= ha
->req_q_map
[0]->max_q_depth
;
772 req
->out_ptr
= (uint16_t *)(req
->ring
+ req
->length
);
773 mutex_unlock(&ha
->mq_lock
);
774 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc004,
775 "ring_ptr=%p ring_index=%d, "
776 "cnt=%d id=%d max_q_depth=%d.\n",
777 req
->ring_ptr
, req
->ring_index
,
778 req
->cnt
, req
->id
, req
->max_q_depth
);
779 ql_dbg(ql_dbg_init
, base_vha
, 0x00de,
780 "ring_ptr=%p ring_index=%d, "
781 "cnt=%d id=%d max_q_depth=%d.\n",
782 req
->ring_ptr
, req
->ring_index
, req
->cnt
,
783 req
->id
, req
->max_q_depth
);
786 ret
= qla25xx_init_req_que(base_vha
, req
);
787 if (ret
!= QLA_SUCCESS
) {
788 ql_log(ql_log_fatal
, base_vha
, 0x00df,
789 "%s failed.\n", __func__
);
790 mutex_lock(&ha
->mq_lock
);
791 clear_bit(que_id
, ha
->req_qid_map
);
792 mutex_unlock(&ha
->mq_lock
);
795 vha
->flags
.qpairs_req_created
= 1;
801 qla25xx_free_req_que(base_vha
, req
);
806 static void qla_do_work(struct work_struct
*work
)
809 struct qla_qpair
*qpair
= container_of(work
, struct qla_qpair
, q_work
);
810 struct scsi_qla_host
*vha
= qpair
->vha
;
812 spin_lock_irqsave(&qpair
->qp_lock
, flags
);
813 qla24xx_process_response_queue(vha
, qpair
->rsp
);
814 spin_unlock_irqrestore(&qpair
->qp_lock
, flags
);
818 /* create response queue */
820 qla25xx_create_rsp_que(struct qla_hw_data
*ha
, uint16_t options
,
821 uint8_t vp_idx
, uint16_t rid
, struct qla_qpair
*qpair
, bool startqp
)
824 struct rsp_que
*rsp
= NULL
;
825 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
826 struct scsi_qla_host
*vha
= pci_get_drvdata(ha
->pdev
);
830 rsp
= kzalloc(sizeof(struct rsp_que
), GFP_KERNEL
);
832 ql_log(ql_log_warn
, base_vha
, 0x0066,
833 "Failed to allocate memory for response queue.\n");
837 rsp
->length
= RESPONSE_ENTRY_CNT_MQ
;
838 rsp
->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
839 (rsp
->length
+ 1) * sizeof(response_t
),
840 &rsp
->dma
, GFP_KERNEL
);
841 if (rsp
->ring
== NULL
) {
842 ql_log(ql_log_warn
, base_vha
, 0x00e1,
843 "Failed to allocate memory for response ring.\n");
847 mutex_lock(&ha
->mq_lock
);
848 que_id
= find_first_zero_bit(ha
->rsp_qid_map
, ha
->max_rsp_queues
);
849 if (que_id
>= ha
->max_rsp_queues
) {
850 mutex_unlock(&ha
->mq_lock
);
851 ql_log(ql_log_warn
, base_vha
, 0x00e2,
852 "No resources to create additional request queue.\n");
855 set_bit(que_id
, ha
->rsp_qid_map
);
857 rsp
->msix
= qpair
->msix
;
859 ha
->rsp_q_map
[que_id
] = rsp
;
861 rsp
->vp_idx
= vp_idx
;
863 ql_dbg(ql_dbg_init
, base_vha
, 0x00e4,
864 "rsp queue_id=%d rid=%d vp_idx=%d hw=%p.\n",
865 que_id
, rsp
->rid
, rsp
->vp_idx
, rsp
->hw
);
866 /* Use alternate PCI bus number */
869 /* Use alternate PCI devfn */
872 /* Enable MSIX handshake mode on for uncapable adapters */
873 if (!IS_MSIX_NACK_CAPABLE(ha
))
876 /* Set option to indicate response queue creation */
879 rsp
->options
= options
;
881 reg
= ISP_QUE_REG(ha
, que_id
);
882 rsp
->rsp_q_in
= ®
->isp25mq
.rsp_q_in
;
883 rsp
->rsp_q_out
= ®
->isp25mq
.rsp_q_out
;
884 rsp
->in_ptr
= (uint16_t *)(rsp
->ring
+ rsp
->length
);
885 mutex_unlock(&ha
->mq_lock
);
886 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc00b,
887 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p\n",
888 rsp
->options
, rsp
->id
, rsp
->rsp_q_in
,
890 ql_dbg(ql_dbg_init
, base_vha
, 0x00e5,
891 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p\n",
892 rsp
->options
, rsp
->id
, rsp
->rsp_q_in
,
895 ret
= qla25xx_request_irq(ha
, qpair
, qpair
->msix
,
896 ha
->flags
.disable_msix_handshake
?
897 QLA_MSIX_QPAIR_MULTIQ_RSP_Q
: QLA_MSIX_QPAIR_MULTIQ_RSP_Q_HS
);
902 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
903 if (ret
!= QLA_SUCCESS
) {
904 ql_log(ql_log_fatal
, base_vha
, 0x00e7,
905 "%s failed.\n", __func__
);
906 mutex_lock(&ha
->mq_lock
);
907 clear_bit(que_id
, ha
->rsp_qid_map
);
908 mutex_unlock(&ha
->mq_lock
);
911 vha
->flags
.qpairs_rsp_created
= 1;
915 qla2x00_init_response_q_entries(rsp
);
917 INIT_WORK(&qpair
->q_work
, qla_do_work
);
921 qla25xx_free_rsp_que(base_vha
, rsp
);
926 static void qla_ctrlvp_sp_done(srb_t
*sp
, int res
)
930 /* don't free sp here. Let the caller do the free */
934 * qla24xx_control_vp() - Enable a virtual port for given host
935 * @vha: adapter block pointer
936 * @cmd: command type to be sent for enable virtual port
938 * Return: qla2xxx local function return status code.
940 int qla24xx_control_vp(scsi_qla_host_t
*vha
, int cmd
)
942 int rval
= QLA_MEMORY_ALLOC_FAILED
;
943 struct qla_hw_data
*ha
= vha
->hw
;
944 int vp_index
= vha
->vp_idx
;
945 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
946 DECLARE_COMPLETION_ONSTACK(comp
);
949 ql_dbg(ql_dbg_vport
, vha
, 0x10c1,
950 "Entered %s cmd %x index %d.\n", __func__
, cmd
, vp_index
);
952 if (vp_index
== 0 || vp_index
>= ha
->max_npiv_vports
)
953 return QLA_PARAMETER_ERROR
;
955 sp
= qla2x00_get_sp(base_vha
, NULL
, GFP_KERNEL
);
959 sp
->type
= SRB_CTRL_VP
;
960 sp
->name
= "ctrl_vp";
962 sp
->done
= qla_ctrlvp_sp_done
;
963 sp
->u
.iocb_cmd
.timeout
= qla2x00_async_iocb_timeout
;
964 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
965 sp
->u
.iocb_cmd
.u
.ctrlvp
.cmd
= cmd
;
966 sp
->u
.iocb_cmd
.u
.ctrlvp
.vp_index
= vp_index
;
968 rval
= qla2x00_start_sp(sp
);
969 if (rval
!= QLA_SUCCESS
) {
970 ql_dbg(ql_dbg_async
, vha
, 0xffff,
971 "%s: %s Failed submission. %x.\n",
972 __func__
, sp
->name
, rval
);
976 ql_dbg(ql_dbg_vport
, vha
, 0x113f, "%s hndl %x submitted\n",
977 sp
->name
, sp
->handle
);
979 wait_for_completion(&comp
);
984 case QLA_FUNCTION_TIMEOUT
:
985 ql_dbg(ql_dbg_vport
, vha
, 0xffff, "%s: %s Timeout. %x.\n",
986 __func__
, sp
->name
, rval
);
989 ql_dbg(ql_dbg_vport
, vha
, 0xffff, "%s: %s done.\n",
993 ql_dbg(ql_dbg_vport
, vha
, 0xffff, "%s: %s Failed. %x.\n",
994 __func__
, sp
->name
, rval
);