2 * qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx
4 * based on qla2x00t.c code:
6 * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net>
7 * Copyright (C) 2004 - 2005 Leonid Stoljar
8 * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us>
9 * Copyright (C) 2006 - 2010 ID7 Ltd.
11 * Forward port and refactoring to modern qla2xxx and target/configfs
13 * Copyright (C) 2010-2013 Nicholas A. Bellinger <nab@kernel.org>
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation, version 2
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/types.h>
29 #include <linux/blkdev.h>
30 #include <linux/interrupt.h>
31 #include <linux/pci.h>
32 #include <linux/delay.h>
33 #include <linux/list.h>
34 #include <linux/workqueue.h>
35 #include <asm/unaligned.h>
36 #include <scsi/scsi.h>
37 #include <scsi/scsi_host.h>
38 #include <scsi/scsi_tcq.h>
39 #include <target/target_core_base.h>
40 #include <target/target_core_fabric.h>
43 #include "qla_target.h"
45 static int ql2xtgt_tape_enable
;
46 module_param(ql2xtgt_tape_enable
, int, S_IRUGO
|S_IWUSR
);
47 MODULE_PARM_DESC(ql2xtgt_tape_enable
,
48 "Enables Sequence level error recovery (aka FC Tape). Default is 0 - no SLER. 1 - Enable SLER.");
50 static char *qlini_mode
= QLA2XXX_INI_MODE_STR_ENABLED
;
51 module_param(qlini_mode
, charp
, S_IRUGO
);
52 MODULE_PARM_DESC(qlini_mode
,
53 "Determines when initiator mode will be enabled. Possible values: "
54 "\"exclusive\" - initiator mode will be enabled on load, "
55 "disabled on enabling target mode and then on disabling target mode "
57 "\"disabled\" - initiator mode will never be enabled; "
58 "\"dual\" - Initiator Modes will be enabled. Target Mode can be activated "
60 "\"enabled\" (default) - initiator mode will always stay enabled.");
62 static int ql_dm_tgt_ex_pct
= 50;
63 module_param(ql_dm_tgt_ex_pct
, int, S_IRUGO
|S_IWUSR
);
64 MODULE_PARM_DESC(ql_dm_tgt_ex_pct
,
65 "For Dual Mode (qlini_mode=dual), this parameter determines "
66 "the percentage of exchanges/cmds FW will allocate resources "
69 int ql2x_ini_mode
= QLA2XXX_INI_MODE_EXCLUSIVE
;
71 static int temp_sam_status
= SAM_STAT_BUSY
;
74 * From scsi/fc/fc_fcp.h
76 enum fcp_resp_rsp_codes
{
78 FCP_DATA_LEN_INVALID
= 1,
79 FCP_CMND_FIELDS_INVALID
= 2,
80 FCP_DATA_PARAM_MISMATCH
= 3,
83 FCP_TMF_INVALID_LUN
= 9,
87 * fc_pri_ta from scsi/fc/fc_fcp.h
89 #define FCP_PTA_SIMPLE 0 /* simple task attribute */
90 #define FCP_PTA_HEADQ 1 /* head of queue task attribute */
91 #define FCP_PTA_ORDERED 2 /* ordered task attribute */
92 #define FCP_PTA_ACA 4 /* auto. contingent allegiance */
93 #define FCP_PTA_MASK 7 /* mask for task attribute field */
94 #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */
95 #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */
98 * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which
99 * must be called under HW lock and could unlock/lock it inside.
100 * It isn't an issue, since in the current implementation on the time when
101 * those functions are called:
103 * - Either context is IRQ and only IRQ handler can modify HW data,
104 * including rings related fields,
106 * - Or access to target mode variables from struct qla_tgt doesn't
107 * cross those functions boundaries, except tgt_stop, which
108 * additionally protected by irq_cmd_count.
110 /* Predefs for callbacks handed to qla2xxx LLD */
111 static void qlt_24xx_atio_pkt(struct scsi_qla_host
*ha
,
112 struct atio_from_isp
*pkt
, uint8_t);
113 static void qlt_response_pkt(struct scsi_qla_host
*ha
, response_t
*pkt
);
114 static int qlt_issue_task_mgmt(struct fc_port
*sess
, u64 lun
,
115 int fn
, void *iocb
, int flags
);
116 static void qlt_send_term_exchange(struct scsi_qla_host
*ha
, struct qla_tgt_cmd
117 *cmd
, struct atio_from_isp
*atio
, int ha_locked
, int ul_abort
);
118 static void qlt_abort_cmd_on_host_reset(struct scsi_qla_host
*vha
,
119 struct qla_tgt_cmd
*cmd
);
120 static void qlt_alloc_qfull_cmd(struct scsi_qla_host
*vha
,
121 struct atio_from_isp
*atio
, uint16_t status
, int qfull
);
122 static void qlt_disable_vha(struct scsi_qla_host
*vha
);
123 static void qlt_clear_tgt_db(struct qla_tgt
*tgt
);
124 static void qlt_send_notify_ack(struct scsi_qla_host
*vha
,
125 struct imm_ntfy_from_isp
*ntfy
,
126 uint32_t add_flags
, uint16_t resp_code
, int resp_code_valid
,
127 uint16_t srr_flags
, uint16_t srr_reject_code
, uint8_t srr_explan
);
128 static void qlt_send_term_imm_notif(struct scsi_qla_host
*vha
,
129 struct imm_ntfy_from_isp
*imm
, int ha_locked
);
130 static struct fc_port
*qlt_create_sess(struct scsi_qla_host
*vha
,
131 fc_port_t
*fcport
, bool local
);
132 void qlt_unreg_sess(struct fc_port
*sess
);
136 static struct kmem_cache
*qla_tgt_mgmt_cmd_cachep
;
137 static struct kmem_cache
*qla_tgt_plogi_cachep
;
138 static mempool_t
*qla_tgt_mgmt_cmd_mempool
;
139 static struct workqueue_struct
*qla_tgt_wq
;
140 static DEFINE_MUTEX(qla_tgt_mutex
);
141 static LIST_HEAD(qla_tgt_glist
);
143 /* This API intentionally takes dest as a parameter, rather than returning
144 * int value to avoid caller forgetting to issue wmb() after the store */
145 void qlt_do_generation_tick(struct scsi_qla_host
*vha
, int *dest
)
147 scsi_qla_host_t
*base_vha
= pci_get_drvdata(vha
->hw
->pdev
);
148 *dest
= atomic_inc_return(&base_vha
->generation_tick
);
153 /* Might release hw lock, then reaquire!! */
154 static inline int qlt_issue_marker(struct scsi_qla_host
*vha
, int vha_locked
)
156 /* Send marker if required */
157 if (unlikely(vha
->marker_needed
!= 0)) {
158 int rc
= qla2x00_issue_marker(vha
, vha_locked
);
159 if (rc
!= QLA_SUCCESS
) {
160 ql_dbg(ql_dbg_tgt
, vha
, 0xe03d,
161 "qla_target(%d): issue_marker() failed\n",
170 struct scsi_qla_host
*qlt_find_host_by_d_id(struct scsi_qla_host
*vha
,
173 struct qla_hw_data
*ha
= vha
->hw
;
176 if ((vha
->d_id
.b
.area
!= d_id
[1]) || (vha
->d_id
.b
.domain
!= d_id
[0]))
179 if (vha
->d_id
.b
.al_pa
== d_id
[2])
182 BUG_ON(ha
->tgt
.tgt_vp_map
== NULL
);
183 vp_idx
= ha
->tgt
.tgt_vp_map
[d_id
[2]].idx
;
184 if (likely(test_bit(vp_idx
, ha
->vp_idx_map
)))
185 return ha
->tgt
.tgt_vp_map
[vp_idx
].vha
;
191 struct scsi_qla_host
*qlt_find_host_by_vp_idx(struct scsi_qla_host
*vha
,
194 struct qla_hw_data
*ha
= vha
->hw
;
196 if (vha
->vp_idx
== vp_idx
)
199 BUG_ON(ha
->tgt
.tgt_vp_map
== NULL
);
200 if (likely(test_bit(vp_idx
, ha
->vp_idx_map
)))
201 return ha
->tgt
.tgt_vp_map
[vp_idx
].vha
;
206 static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host
*vha
)
210 spin_lock_irqsave(&vha
->hw
->tgt
.q_full_lock
, flags
);
212 vha
->hw
->tgt
.num_pend_cmds
++;
213 if (vha
->hw
->tgt
.num_pend_cmds
> vha
->qla_stats
.stat_max_pend_cmds
)
214 vha
->qla_stats
.stat_max_pend_cmds
=
215 vha
->hw
->tgt
.num_pend_cmds
;
216 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
218 static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host
*vha
)
222 spin_lock_irqsave(&vha
->hw
->tgt
.q_full_lock
, flags
);
223 vha
->hw
->tgt
.num_pend_cmds
--;
224 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
228 static void qlt_queue_unknown_atio(scsi_qla_host_t
*vha
,
229 struct atio_from_isp
*atio
, uint8_t ha_locked
)
231 struct qla_tgt_sess_op
*u
;
232 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
236 ql_dbg(ql_dbg_async
, vha
, 0xffff,
237 "qla_target(%d): dropping unknown ATIO_TYPE7, "
238 "because tgt is being stopped", vha
->vp_idx
);
242 u
= kzalloc(sizeof(*u
), GFP_ATOMIC
);
244 ql_dbg(ql_dbg_async
, vha
, 0xffff,
245 "Alloc of struct unknown_atio (size %zd) failed", sizeof(*u
));
246 /* It should be harmless and on the next retry should work well */
251 memcpy(&u
->atio
, atio
, sizeof(*atio
));
252 INIT_LIST_HEAD(&u
->cmd_list
);
254 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
255 list_add_tail(&u
->cmd_list
, &vha
->unknown_atio_list
);
256 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
258 schedule_delayed_work(&vha
->unknown_atio_work
, 1);
264 qlt_send_term_exchange(vha
, NULL
, atio
, ha_locked
, 0);
268 static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host
*vha
,
271 struct qla_tgt_sess_op
*u
, *t
;
272 scsi_qla_host_t
*host
;
273 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
277 list_for_each_entry_safe(u
, t
, &vha
->unknown_atio_list
, cmd_list
) {
279 ql_dbg(ql_dbg_async
, vha
, 0xffff,
280 "Freeing unknown %s %p, because of Abort",
282 qlt_send_term_exchange(vha
, NULL
, &u
->atio
,
287 host
= qlt_find_host_by_d_id(vha
, u
->atio
.u
.isp24
.fcp_hdr
.d_id
);
289 ql_dbg(ql_dbg_async
, vha
, 0xffff,
290 "Requeuing unknown ATIO_TYPE7 %p", u
);
291 qlt_24xx_atio_pkt(host
, &u
->atio
, ha_locked
);
292 } else if (tgt
->tgt_stop
) {
293 ql_dbg(ql_dbg_async
, vha
, 0xffff,
294 "Freeing unknown %s %p, because tgt is being stopped",
296 qlt_send_term_exchange(vha
, NULL
, &u
->atio
,
299 ql_dbg(ql_dbg_async
, vha
, 0xffff,
300 "u %p, vha %p, host %p, sched again..", u
,
304 schedule_delayed_work(&vha
->unknown_atio_work
,
311 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
312 list_del(&u
->cmd_list
);
313 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
318 void qlt_unknown_atio_work_fn(struct work_struct
*work
)
320 struct scsi_qla_host
*vha
= container_of(to_delayed_work(work
),
321 struct scsi_qla_host
, unknown_atio_work
);
323 qlt_try_to_dequeue_unknown_atios(vha
, 0);
326 static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host
*vha
,
327 struct atio_from_isp
*atio
, uint8_t ha_locked
)
329 ql_dbg(ql_dbg_tgt
, vha
, 0xe072,
330 "%s: qla_target(%d): type %x ox_id %04x\n",
331 __func__
, vha
->vp_idx
, atio
->u
.raw
.entry_type
,
332 be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
));
334 switch (atio
->u
.raw
.entry_type
) {
337 struct scsi_qla_host
*host
= qlt_find_host_by_d_id(vha
,
338 atio
->u
.isp24
.fcp_hdr
.d_id
);
339 if (unlikely(NULL
== host
)) {
340 ql_dbg(ql_dbg_tgt
, vha
, 0xe03e,
341 "qla_target(%d): Received ATIO_TYPE7 "
342 "with unknown d_id %x:%x:%x\n", vha
->vp_idx
,
343 atio
->u
.isp24
.fcp_hdr
.d_id
[0],
344 atio
->u
.isp24
.fcp_hdr
.d_id
[1],
345 atio
->u
.isp24
.fcp_hdr
.d_id
[2]);
348 qlt_queue_unknown_atio(vha
, atio
, ha_locked
);
351 if (unlikely(!list_empty(&vha
->unknown_atio_list
)))
352 qlt_try_to_dequeue_unknown_atios(vha
, ha_locked
);
354 qlt_24xx_atio_pkt(host
, atio
, ha_locked
);
358 case IMMED_NOTIFY_TYPE
:
360 struct scsi_qla_host
*host
= vha
;
361 struct imm_ntfy_from_isp
*entry
=
362 (struct imm_ntfy_from_isp
*)atio
;
364 if ((entry
->u
.isp24
.vp_index
!= 0xFF) &&
365 (entry
->u
.isp24
.nport_handle
!= 0xFFFF)) {
366 host
= qlt_find_host_by_vp_idx(vha
,
367 entry
->u
.isp24
.vp_index
);
368 if (unlikely(!host
)) {
369 ql_dbg(ql_dbg_tgt
, vha
, 0xe03f,
370 "qla_target(%d): Received "
371 "ATIO (IMMED_NOTIFY_TYPE) "
372 "with unknown vp_index %d\n",
373 vha
->vp_idx
, entry
->u
.isp24
.vp_index
);
377 qlt_24xx_atio_pkt(host
, atio
, ha_locked
);
381 case VP_RPT_ID_IOCB_TYPE
:
382 qla24xx_report_id_acquisition(vha
,
383 (struct vp_rpt_id_entry_24xx
*)atio
);
388 struct abts_recv_from_24xx
*entry
=
389 (struct abts_recv_from_24xx
*)atio
;
390 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
392 if (unlikely(!host
)) {
393 ql_dbg(ql_dbg_tgt
, vha
, 0xffff,
394 "qla_target(%d): Response pkt (ABTS_RECV_24XX) "
395 "received, with unknown vp_index %d\n",
396 vha
->vp_idx
, entry
->vp_index
);
399 qlt_response_pkt(host
, (response_t
*)atio
);
404 /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */
407 ql_dbg(ql_dbg_tgt
, vha
, 0xe040,
408 "qla_target(%d): Received unknown ATIO atio "
409 "type %x\n", vha
->vp_idx
, atio
->u
.raw
.entry_type
);
416 void qlt_response_pkt_all_vps(struct scsi_qla_host
*vha
, response_t
*pkt
)
418 switch (pkt
->entry_type
) {
420 ql_dbg(ql_dbg_tgt
, vha
, 0xe073,
421 "qla_target(%d):%s: CRC2 Response pkt\n",
422 vha
->vp_idx
, __func__
);
425 struct ctio7_from_24xx
*entry
= (struct ctio7_from_24xx
*)pkt
;
426 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
428 if (unlikely(!host
)) {
429 ql_dbg(ql_dbg_tgt
, vha
, 0xe041,
430 "qla_target(%d): Response pkt (CTIO_TYPE7) "
431 "received, with unknown vp_index %d\n",
432 vha
->vp_idx
, entry
->vp_index
);
435 qlt_response_pkt(host
, pkt
);
439 case IMMED_NOTIFY_TYPE
:
441 struct scsi_qla_host
*host
= vha
;
442 struct imm_ntfy_from_isp
*entry
=
443 (struct imm_ntfy_from_isp
*)pkt
;
445 host
= qlt_find_host_by_vp_idx(vha
, entry
->u
.isp24
.vp_index
);
446 if (unlikely(!host
)) {
447 ql_dbg(ql_dbg_tgt
, vha
, 0xe042,
448 "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) "
449 "received, with unknown vp_index %d\n",
450 vha
->vp_idx
, entry
->u
.isp24
.vp_index
);
453 qlt_response_pkt(host
, pkt
);
457 case NOTIFY_ACK_TYPE
:
459 struct scsi_qla_host
*host
= vha
;
460 struct nack_to_isp
*entry
= (struct nack_to_isp
*)pkt
;
462 if (0xFF != entry
->u
.isp24
.vp_index
) {
463 host
= qlt_find_host_by_vp_idx(vha
,
464 entry
->u
.isp24
.vp_index
);
465 if (unlikely(!host
)) {
466 ql_dbg(ql_dbg_tgt
, vha
, 0xe043,
467 "qla_target(%d): Response "
468 "pkt (NOTIFY_ACK_TYPE) "
469 "received, with unknown "
470 "vp_index %d\n", vha
->vp_idx
,
471 entry
->u
.isp24
.vp_index
);
475 qlt_response_pkt(host
, pkt
);
481 struct abts_recv_from_24xx
*entry
=
482 (struct abts_recv_from_24xx
*)pkt
;
483 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
485 if (unlikely(!host
)) {
486 ql_dbg(ql_dbg_tgt
, vha
, 0xe044,
487 "qla_target(%d): Response pkt "
488 "(ABTS_RECV_24XX) received, with unknown "
489 "vp_index %d\n", vha
->vp_idx
, entry
->vp_index
);
492 qlt_response_pkt(host
, pkt
);
498 struct abts_resp_to_24xx
*entry
=
499 (struct abts_resp_to_24xx
*)pkt
;
500 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
502 if (unlikely(!host
)) {
503 ql_dbg(ql_dbg_tgt
, vha
, 0xe045,
504 "qla_target(%d): Response pkt "
505 "(ABTS_RECV_24XX) received, with unknown "
506 "vp_index %d\n", vha
->vp_idx
, entry
->vp_index
);
509 qlt_response_pkt(host
, pkt
);
514 qlt_response_pkt(vha
, pkt
);
521 * All qlt_plogi_ack_t operations are protected by hardware_lock
523 static int qla24xx_post_nack_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
524 struct imm_ntfy_from_isp
*ntfy
, int type
)
526 struct qla_work_evt
*e
;
527 e
= qla2x00_alloc_work(vha
, QLA_EVT_NACK
);
529 return QLA_FUNCTION_FAILED
;
531 e
->u
.nack
.fcport
= fcport
;
532 e
->u
.nack
.type
= type
;
533 memcpy(e
->u
.nack
.iocb
, ntfy
, sizeof(struct imm_ntfy_from_isp
));
534 return qla2x00_post_work(vha
, e
);
538 void qla2x00_async_nack_sp_done(void *s
, int res
)
540 struct srb
*sp
= (struct srb
*)s
;
541 struct scsi_qla_host
*vha
= sp
->vha
;
544 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
545 "Async done-%s res %x %8phC type %d\n",
546 sp
->name
, res
, sp
->fcport
->port_name
, sp
->type
);
548 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
549 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
550 sp
->fcport
->chip_reset
= vha
->hw
->chip_reset
;
554 sp
->fcport
->login_gen
++;
555 sp
->fcport
->fw_login_state
= DSC_LS_PLOGI_COMP
;
556 sp
->fcport
->logout_on_delete
= 1;
560 sp
->fcport
->fw_login_state
= DSC_LS_PRLI_COMP
;
561 sp
->fcport
->deleted
= 0;
563 if (!sp
->fcport
->login_succ
&&
564 !IS_SW_RESV_ADDR(sp
->fcport
->d_id
)) {
565 sp
->fcport
->login_succ
= 1;
569 if (!IS_IIDMA_CAPABLE(vha
->hw
) ||
570 !vha
->hw
->flags
.gpsc_supported
) {
571 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
572 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
574 sp
->fcport
->port_name
,
577 qla24xx_post_upd_fcport_work(vha
, sp
->fcport
);
579 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
580 "%s %d %8phC post gpsc fcp_cnt %d\n",
582 sp
->fcport
->port_name
,
585 qla24xx_post_gpsc_work(vha
, sp
->fcport
);
591 sp
->fcport
->login_gen
++;
592 sp
->fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
593 qlt_logo_completion_handler(sp
->fcport
, MBS_COMMAND_COMPLETE
);
596 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
601 int qla24xx_async_notify_ack(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
602 struct imm_ntfy_from_isp
*ntfy
, int type
)
604 int rval
= QLA_FUNCTION_FAILED
;
608 fcport
->flags
|= FCF_ASYNC_SENT
;
611 fcport
->fw_login_state
= DSC_LS_PLOGI_PEND
;
615 fcport
->fw_login_state
= DSC_LS_PRLI_PEND
;
619 fcport
->fw_login_state
= DSC_LS_LOGO_PEND
;
624 sp
= qla2x00_get_sp(vha
, fcport
, GFP_ATOMIC
);
631 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
)+2);
633 sp
->u
.iocb_cmd
.u
.nack
.ntfy
= ntfy
;
635 sp
->done
= qla2x00_async_nack_sp_done
;
637 rval
= qla2x00_start_sp(sp
);
638 if (rval
!= QLA_SUCCESS
)
641 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
642 "Async-%s %8phC hndl %x %s\n",
643 sp
->name
, fcport
->port_name
, sp
->handle
, c
);
650 fcport
->flags
&= ~FCF_ASYNC_SENT
;
654 void qla24xx_do_nack_work(struct scsi_qla_host
*vha
, struct qla_work_evt
*e
)
659 switch (e
->u
.nack
.type
) {
661 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
662 t
= qlt_create_sess(vha
, e
->u
.nack
.fcport
, 0);
663 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
665 ql_log(ql_log_info
, vha
, 0xffff,
666 "%s create sess success %p", __func__
, t
);
667 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
668 /* create sess has an extra kref */
669 vha
->hw
->tgt
.tgt_ops
->put_sess(e
->u
.nack
.fcport
);
670 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
674 qla24xx_async_notify_ack(vha
, e
->u
.nack
.fcport
,
675 (struct imm_ntfy_from_isp
*)e
->u
.nack
.iocb
, e
->u
.nack
.type
);
678 void qla24xx_delete_sess_fn(struct work_struct
*work
)
680 fc_port_t
*fcport
= container_of(work
, struct fc_port
, del_work
);
681 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
684 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
686 if (fcport
->se_sess
) {
687 ha
->tgt
.tgt_ops
->shutdown_sess(fcport
);
688 ha
->tgt
.tgt_ops
->put_sess(fcport
);
690 qlt_unreg_sess(fcport
);
692 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
696 * Called from qla2x00_reg_remote_port()
698 void qlt_fc_port_added(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
700 struct qla_hw_data
*ha
= vha
->hw
;
701 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
702 struct fc_port
*sess
= fcport
;
705 if (!vha
->hw
->tgt
.tgt_ops
)
708 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
710 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
714 if (fcport
->disc_state
== DSC_DELETE_PEND
) {
715 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
719 if (!sess
->se_sess
) {
720 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
722 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
723 sess
= qlt_create_sess(vha
, fcport
, false);
724 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
726 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
728 if (fcport
->fw_login_state
== DSC_LS_PRLI_COMP
) {
729 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
733 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
734 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
735 "%s: kref_get fail sess %8phC \n",
736 __func__
, sess
->port_name
);
737 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
741 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04c,
742 "qla_target(%u): %ssession for port %8phC "
743 "(loop ID %d) reappeared\n", vha
->vp_idx
,
744 sess
->local
? "local " : "", sess
->port_name
, sess
->loop_id
);
746 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf007,
747 "Reappeared sess %p\n", sess
);
749 ha
->tgt
.tgt_ops
->update_sess(sess
, fcport
->d_id
,
751 (fcport
->flags
& FCF_CONF_COMP_SUPPORTED
));
754 if (sess
&& sess
->local
) {
755 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04d,
756 "qla_target(%u): local session for "
757 "port %8phC (loop ID %d) became global\n", vha
->vp_idx
,
758 fcport
->port_name
, sess
->loop_id
);
761 ha
->tgt
.tgt_ops
->put_sess(sess
);
762 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
766 * This is a zero-base ref-counting solution, since hardware_lock
767 * guarantees that ref_count is not modified concurrently.
768 * Upon successful return content of iocb is undefined
770 static struct qlt_plogi_ack_t
*
771 qlt_plogi_ack_find_add(struct scsi_qla_host
*vha
, port_id_t
*id
,
772 struct imm_ntfy_from_isp
*iocb
)
774 struct qlt_plogi_ack_t
*pla
;
776 list_for_each_entry(pla
, &vha
->plogi_ack_list
, list
) {
777 if (pla
->id
.b24
== id
->b24
) {
778 qlt_send_term_imm_notif(vha
, &pla
->iocb
, 1);
779 memcpy(&pla
->iocb
, iocb
, sizeof(pla
->iocb
));
784 pla
= kmem_cache_zalloc(qla_tgt_plogi_cachep
, GFP_ATOMIC
);
786 ql_dbg(ql_dbg_async
, vha
, 0x5088,
787 "qla_target(%d): Allocation of plogi_ack failed\n",
792 memcpy(&pla
->iocb
, iocb
, sizeof(pla
->iocb
));
794 list_add_tail(&pla
->list
, &vha
->plogi_ack_list
);
799 void qlt_plogi_ack_unref(struct scsi_qla_host
*vha
,
800 struct qlt_plogi_ack_t
*pla
)
802 struct imm_ntfy_from_isp
*iocb
= &pla
->iocb
;
805 fc_port_t
*fcport
= pla
->fcport
;
807 BUG_ON(!pla
->ref_count
);
813 ql_dbg(ql_dbg_disc
, vha
, 0x5089,
814 "Sending PLOGI ACK to wwn %8phC s_id %02x:%02x:%02x loop_id %#04x"
815 " exch %#x ox_id %#x\n", iocb
->u
.isp24
.port_name
,
816 iocb
->u
.isp24
.port_id
[2], iocb
->u
.isp24
.port_id
[1],
817 iocb
->u
.isp24
.port_id
[0],
818 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
819 iocb
->u
.isp24
.exchange_address
, iocb
->ox_id
);
821 port_id
.b
.domain
= iocb
->u
.isp24
.port_id
[2];
822 port_id
.b
.area
= iocb
->u
.isp24
.port_id
[1];
823 port_id
.b
.al_pa
= iocb
->u
.isp24
.port_id
[0];
824 port_id
.b
.rsvd_1
= 0;
826 loop_id
= le16_to_cpu(iocb
->u
.isp24
.nport_handle
);
828 fcport
->loop_id
= loop_id
;
829 fcport
->d_id
= port_id
;
830 qla24xx_post_nack_work(vha
, fcport
, iocb
, SRB_NACK_PLOGI
);
832 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
833 if (fcport
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] == pla
)
834 fcport
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] = NULL
;
835 if (fcport
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
] == pla
)
836 fcport
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
] = NULL
;
839 list_del(&pla
->list
);
840 kmem_cache_free(qla_tgt_plogi_cachep
, pla
);
844 qlt_plogi_ack_link(struct scsi_qla_host
*vha
, struct qlt_plogi_ack_t
*pla
,
845 struct fc_port
*sess
, enum qlt_plogi_link_t link
)
847 struct imm_ntfy_from_isp
*iocb
= &pla
->iocb
;
848 /* Inc ref_count first because link might already be pointing at pla */
851 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf097,
852 "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC"
853 " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n",
854 sess
, link
, sess
->port_name
,
855 iocb
->u
.isp24
.port_name
, iocb
->u
.isp24
.port_id
[2],
856 iocb
->u
.isp24
.port_id
[1], iocb
->u
.isp24
.port_id
[0],
857 pla
->ref_count
, pla
, link
);
859 if (sess
->plogi_link
[link
])
860 qlt_plogi_ack_unref(vha
, sess
->plogi_link
[link
]);
862 if (link
== QLT_PLOGI_LINK_SAME_WWN
)
865 sess
->plogi_link
[link
] = pla
;
869 /* These fields must be initialized by the caller */
872 * number of cmds dropped while we were waiting for
873 * initiator to ack LOGO initialize to 1 if LOGO is
874 * triggered by a command, otherwise, to 0
878 /* These fields are used by callee */
879 struct list_head list
;
883 qlt_send_first_logo(struct scsi_qla_host
*vha
, qlt_port_logo_t
*logo
)
885 qlt_port_logo_t
*tmp
;
888 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
890 list_for_each_entry(tmp
, &vha
->logo_list
, list
) {
891 if (tmp
->id
.b24
== logo
->id
.b24
) {
892 tmp
->cmd_count
+= logo
->cmd_count
;
893 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
898 list_add_tail(&logo
->list
, &vha
->logo_list
);
900 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
902 res
= qla24xx_els_dcmd_iocb(vha
, ELS_DCMD_LOGO
, logo
->id
);
904 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
905 list_del(&logo
->list
);
906 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
908 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf098,
909 "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n",
910 logo
->id
.b
.domain
, logo
->id
.b
.area
, logo
->id
.b
.al_pa
,
911 logo
->cmd_count
, res
);
914 static void qlt_free_session_done(struct work_struct
*work
)
916 struct fc_port
*sess
= container_of(work
, struct fc_port
,
918 struct qla_tgt
*tgt
= sess
->tgt
;
919 struct scsi_qla_host
*vha
= sess
->vha
;
920 struct qla_hw_data
*ha
= vha
->hw
;
922 bool logout_started
= false;
924 scsi_qla_host_t
*base_vha
;
926 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf084,
927 "%s: se_sess %p / sess %p from port %8phC loop_id %#04x"
928 " s_id %02x:%02x:%02x logout %d keep %d els_logo %d\n",
929 __func__
, sess
->se_sess
, sess
, sess
->port_name
, sess
->loop_id
,
930 sess
->d_id
.b
.domain
, sess
->d_id
.b
.area
, sess
->d_id
.b
.al_pa
,
931 sess
->logout_on_delete
, sess
->keep_nport_handle
,
932 sess
->send_els_logo
);
935 if (!IS_SW_RESV_ADDR(sess
->d_id
)) {
936 if (sess
->send_els_logo
) {
937 qlt_port_logo_t logo
;
939 logo
.id
= sess
->d_id
;
941 qlt_send_first_logo(vha
, &logo
);
944 if (sess
->logout_on_delete
) {
947 rc
= qla2x00_post_async_logout_work(vha
, sess
, NULL
);
948 if (rc
!= QLA_SUCCESS
)
949 ql_log(ql_log_warn
, vha
, 0xf085,
950 "Schedule logo failed sess %p rc %d\n",
953 logout_started
= true;
958 * Release the target session for FC Nexus from fabric module code.
960 if (sess
->se_sess
!= NULL
)
961 ha
->tgt
.tgt_ops
->free_session(sess
);
963 if (logout_started
) {
966 while (!ACCESS_ONCE(sess
->logout_completed
)) {
968 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf086,
969 "%s: waiting for sess %p logout\n",
976 ql_dbg(ql_dbg_disc
, vha
, 0xf087,
977 "%s: sess %p logout completed\n",__func__
, sess
);
980 if (sess
->logo_ack_needed
) {
981 sess
->logo_ack_needed
= 0;
982 qla24xx_async_notify_ack(vha
, sess
,
983 (struct imm_ntfy_from_isp
*)sess
->iocb
, SRB_NACK_LOGO
);
986 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
988 sess
->se_sess
= NULL
;
989 if (tgt
&& !IS_SW_RESV_ADDR(sess
->d_id
))
993 sess
->disc_state
= DSC_DELETED
;
994 sess
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
995 sess
->deleted
= QLA_SESS_DELETED
;
996 sess
->login_retry
= vha
->hw
->login_retry_count
;
998 if (sess
->login_succ
&& !IS_SW_RESV_ADDR(sess
->d_id
)) {
1000 sess
->login_succ
= 0;
1003 if (sess
->chip_reset
!= sess
->vha
->hw
->chip_reset
)
1004 qla2x00_clear_loop_id(sess
);
1006 if (sess
->conflict
) {
1007 sess
->conflict
->login_pause
= 0;
1008 sess
->conflict
= NULL
;
1009 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
1010 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1014 struct qlt_plogi_ack_t
*own
=
1015 sess
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
];
1016 struct qlt_plogi_ack_t
*con
=
1017 sess
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
];
1018 struct imm_ntfy_from_isp
*iocb
;
1022 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf099,
1023 "se_sess %p / sess %p port %8phC is gone,"
1024 " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n",
1025 sess
->se_sess
, sess
, sess
->port_name
,
1026 own
? "releasing own PLOGI" : "no own PLOGI pending",
1027 own
? own
->ref_count
: -1,
1028 iocb
->u
.isp24
.port_name
, con
->ref_count
);
1029 qlt_plogi_ack_unref(vha
, con
);
1030 sess
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
] = NULL
;
1032 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf09a,
1033 "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n",
1034 sess
->se_sess
, sess
, sess
->port_name
,
1035 own
? "releasing own PLOGI" :
1036 "no own PLOGI pending",
1037 own
? own
->ref_count
: -1);
1041 sess
->fw_login_state
= DSC_LS_PLOGI_PEND
;
1042 qlt_plogi_ack_unref(vha
, own
);
1043 sess
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] = NULL
;
1046 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1048 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf001,
1049 "Unregistration of sess %p %8phC finished fcp_cnt %d\n",
1050 sess
, sess
->port_name
, vha
->fcport_count
);
1052 if (tgt
&& (tgt
->sess_count
== 0))
1053 wake_up_all(&tgt
->waitQ
);
1055 if (vha
->fcport_count
== 0)
1056 wake_up_all(&vha
->fcport_waitQ
);
1058 base_vha
= pci_get_drvdata(ha
->pdev
);
1059 if (test_bit(PFLG_DRIVER_REMOVING
, &base_vha
->pci_flags
))
1062 if (!tgt
|| !tgt
->tgt_stop
) {
1063 memset(&ea
, 0, sizeof(ea
));
1064 ea
.event
= FCME_DELETE_DONE
;
1066 qla2x00_fcport_event_handler(vha
, &ea
);
1070 /* ha->tgt.sess_lock supposed to be held on entry */
1071 void qlt_unreg_sess(struct fc_port
*sess
)
1073 struct scsi_qla_host
*vha
= sess
->vha
;
1075 ql_dbg(ql_dbg_disc
, sess
->vha
, 0xffff,
1076 "%s sess %p for deletion %8phC\n",
1077 __func__
, sess
, sess
->port_name
);
1080 vha
->hw
->tgt
.tgt_ops
->clear_nacl_from_fcport_map(sess
);
1082 qla2x00_mark_device_lost(vha
, sess
, 1, 1);
1084 sess
->deleted
= QLA_SESS_DELETION_IN_PROGRESS
;
1085 sess
->disc_state
= DSC_DELETE_PEND
;
1086 sess
->last_rscn_gen
= sess
->rscn_gen
;
1087 sess
->last_login_gen
= sess
->login_gen
;
1089 INIT_WORK(&sess
->free_work
, qlt_free_session_done
);
1090 schedule_work(&sess
->free_work
);
1092 EXPORT_SYMBOL(qlt_unreg_sess
);
1094 static int qlt_reset(struct scsi_qla_host
*vha
, void *iocb
, int mcmd
)
1096 struct qla_hw_data
*ha
= vha
->hw
;
1097 struct fc_port
*sess
= NULL
;
1100 struct imm_ntfy_from_isp
*n
= (struct imm_ntfy_from_isp
*)iocb
;
1101 unsigned long flags
;
1103 loop_id
= le16_to_cpu(n
->u
.isp24
.nport_handle
);
1104 if (loop_id
== 0xFFFF) {
1106 atomic_inc(&vha
->vha_tgt
.qla_tgt
->tgt_global_resets_count
);
1107 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1108 qlt_clear_tgt_db(vha
->vha_tgt
.qla_tgt
);
1109 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1111 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1112 sess
= ha
->tgt
.tgt_ops
->find_sess_by_loop_id(vha
, loop_id
);
1113 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1116 ql_dbg(ql_dbg_tgt
, vha
, 0xe000,
1117 "Using sess for qla_tgt_reset: %p\n", sess
);
1123 ql_dbg(ql_dbg_tgt
, vha
, 0xe047,
1124 "scsi(%ld): resetting (session %p from port %8phC mcmd %x, "
1125 "loop_id %d)\n", vha
->host_no
, sess
, sess
->port_name
,
1128 return qlt_issue_task_mgmt(sess
, 0, mcmd
, iocb
, QLA24XX_MGMT_SEND_NACK
);
1131 static void qla24xx_chk_fcp_state(struct fc_port
*sess
)
1133 if (sess
->chip_reset
!= sess
->vha
->hw
->chip_reset
) {
1134 sess
->logout_on_delete
= 0;
1135 sess
->logo_ack_needed
= 0;
1136 sess
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1137 sess
->scan_state
= 0;
1141 /* ha->tgt.sess_lock supposed to be held on entry */
1142 void qlt_schedule_sess_for_deletion(struct fc_port
*sess
,
1145 struct qla_tgt
*tgt
= sess
->tgt
;
1147 if (sess
->disc_state
== DSC_DELETE_PEND
)
1150 if (sess
->disc_state
== DSC_DELETED
) {
1151 if (tgt
&& tgt
->tgt_stop
&& (tgt
->sess_count
== 0))
1152 wake_up_all(&tgt
->waitQ
);
1153 if (sess
->vha
->fcport_count
== 0)
1154 wake_up_all(&sess
->vha
->fcport_waitQ
);
1156 if (!sess
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] &&
1157 !sess
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
])
1161 sess
->disc_state
= DSC_DELETE_PEND
;
1163 if (sess
->deleted
== QLA_SESS_DELETED
)
1164 sess
->logout_on_delete
= 0;
1166 sess
->deleted
= QLA_SESS_DELETION_IN_PROGRESS
;
1167 qla24xx_chk_fcp_state(sess
);
1169 ql_dbg(ql_dbg_tgt
, sess
->vha
, 0xe001,
1170 "Scheduling sess %p for deletion\n", sess
);
1172 schedule_work(&sess
->del_work
);
1175 void qlt_schedule_sess_for_deletion_lock(struct fc_port
*sess
)
1177 unsigned long flags
;
1178 struct qla_hw_data
*ha
= sess
->vha
->hw
;
1179 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1180 qlt_schedule_sess_for_deletion(sess
, 1);
1181 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1184 /* ha->tgt.sess_lock supposed to be held on entry */
1185 static void qlt_clear_tgt_db(struct qla_tgt
*tgt
)
1187 struct fc_port
*sess
;
1188 scsi_qla_host_t
*vha
= tgt
->vha
;
1190 list_for_each_entry(sess
, &vha
->vp_fcports
, list
) {
1192 qlt_schedule_sess_for_deletion(sess
, 1);
1195 /* At this point tgt could be already dead */
1198 static int qla24xx_get_loop_id(struct scsi_qla_host
*vha
, const uint8_t *s_id
,
1201 struct qla_hw_data
*ha
= vha
->hw
;
1202 dma_addr_t gid_list_dma
;
1203 struct gid_list_info
*gid_list
;
1208 gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, qla2x00_gid_list_size(ha
),
1209 &gid_list_dma
, GFP_KERNEL
);
1211 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf044,
1212 "qla_target(%d): DMA Alloc failed of %u\n",
1213 vha
->vp_idx
, qla2x00_gid_list_size(ha
));
1217 /* Get list of logged in devices */
1218 rc
= qla2x00_get_id_list(vha
, gid_list
, gid_list_dma
, &entries
);
1219 if (rc
!= QLA_SUCCESS
) {
1220 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf045,
1221 "qla_target(%d): get_id_list() failed: %x\n",
1224 goto out_free_id_list
;
1227 id_iter
= (char *)gid_list
;
1229 for (i
= 0; i
< entries
; i
++) {
1230 struct gid_list_info
*gid
= (struct gid_list_info
*)id_iter
;
1231 if ((gid
->al_pa
== s_id
[2]) &&
1232 (gid
->area
== s_id
[1]) &&
1233 (gid
->domain
== s_id
[0])) {
1234 *loop_id
= le16_to_cpu(gid
->loop_id
);
1238 id_iter
+= ha
->gid_list_info_size
;
1242 dma_free_coherent(&ha
->pdev
->dev
, qla2x00_gid_list_size(ha
),
1243 gid_list
, gid_list_dma
);
1248 * Adds an extra ref to allow to drop hw lock after adding sess to the list.
1249 * Caller must put it.
1251 static struct fc_port
*qlt_create_sess(
1252 struct scsi_qla_host
*vha
,
1256 struct qla_hw_data
*ha
= vha
->hw
;
1257 struct fc_port
*sess
= fcport
;
1258 unsigned long flags
;
1260 if (vha
->vha_tgt
.qla_tgt
->tgt_stop
)
1263 if (fcport
->se_sess
) {
1264 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
1265 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1266 "%s: kref_get_unless_zero failed for %8phC\n",
1267 __func__
, sess
->port_name
);
1272 sess
->tgt
= vha
->vha_tgt
.qla_tgt
;
1273 sess
->local
= local
;
1276 * Under normal circumstances we want to logout from firmware when
1277 * session eventually ends and release corresponding nport handle.
1278 * In the exception cases (e.g. when new PLOGI is waiting) corresponding
1279 * code will adjust these flags as necessary.
1281 sess
->logout_on_delete
= 1;
1282 sess
->keep_nport_handle
= 0;
1283 sess
->logout_completed
= 0;
1285 if (ha
->tgt
.tgt_ops
->check_initiator_node_acl(vha
,
1286 &fcport
->port_name
[0], sess
) < 0) {
1287 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xffff,
1288 "(%d) %8phC check_initiator_node_acl failed\n",
1289 vha
->vp_idx
, fcport
->port_name
);
1292 kref_init(&fcport
->sess_kref
);
1294 * Take an extra reference to ->sess_kref here to handle
1295 * fc_port access across ->tgt.sess_lock reaquire.
1297 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
1298 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1299 "%s: kref_get_unless_zero failed for %8phC\n",
1300 __func__
, sess
->port_name
);
1304 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1305 if (!IS_SW_RESV_ADDR(sess
->d_id
))
1306 vha
->vha_tgt
.qla_tgt
->sess_count
++;
1308 qlt_do_generation_tick(vha
, &sess
->generation
);
1309 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1312 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf006,
1313 "Adding sess %p se_sess %p to tgt %p sess_count %d\n",
1314 sess
, sess
->se_sess
, vha
->vha_tgt
.qla_tgt
,
1315 vha
->vha_tgt
.qla_tgt
->sess_count
);
1317 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04b,
1318 "qla_target(%d): %ssession for wwn %8phC (loop_id %d, "
1319 "s_id %x:%x:%x, confirmed completion %ssupported) added\n",
1320 vha
->vp_idx
, local
? "local " : "", fcport
->port_name
,
1321 fcport
->loop_id
, sess
->d_id
.b
.domain
, sess
->d_id
.b
.area
,
1322 sess
->d_id
.b
.al_pa
, sess
->conf_compl_supported
? "" : "not ");
1328 * max_gen - specifies maximum session generation
1329 * at which this deletion requestion is still valid
1332 qlt_fc_port_deleted(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, int max_gen
)
1334 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
1335 struct fc_port
*sess
= fcport
;
1336 unsigned long flags
;
1338 if (!vha
->hw
->tgt
.tgt_ops
)
1344 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1345 if (tgt
->tgt_stop
) {
1346 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1349 if (!sess
->se_sess
) {
1350 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1354 if (max_gen
- sess
->generation
< 0) {
1355 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1356 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf092,
1357 "Ignoring stale deletion request for se_sess %p / sess %p"
1358 " for port %8phC, req_gen %d, sess_gen %d\n",
1359 sess
->se_sess
, sess
, sess
->port_name
, max_gen
,
1364 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf008, "qla_tgt_fc_port_deleted %p", sess
);
1367 qlt_schedule_sess_for_deletion(sess
, false);
1368 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1371 static inline int test_tgt_sess_count(struct qla_tgt
*tgt
)
1373 struct qla_hw_data
*ha
= tgt
->ha
;
1374 unsigned long flags
;
1377 * We need to protect against race, when tgt is freed before or
1380 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1381 ql_dbg(ql_dbg_tgt
, tgt
->vha
, 0xe002,
1382 "tgt %p, sess_count=%d\n",
1383 tgt
, tgt
->sess_count
);
1384 res
= (tgt
->sess_count
== 0);
1385 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1390 /* Called by tcm_qla2xxx configfs code */
1391 int qlt_stop_phase1(struct qla_tgt
*tgt
)
1393 struct scsi_qla_host
*vha
= tgt
->vha
;
1394 struct qla_hw_data
*ha
= tgt
->ha
;
1395 unsigned long flags
;
1397 mutex_lock(&qla_tgt_mutex
);
1398 if (!vha
->fc_vport
) {
1399 struct Scsi_Host
*sh
= vha
->host
;
1400 struct fc_host_attrs
*fc_host
= shost_to_fc_host(sh
);
1403 spin_lock_irqsave(sh
->host_lock
, flags
);
1404 npiv_vports
= (fc_host
->npiv_vports_inuse
);
1405 spin_unlock_irqrestore(sh
->host_lock
, flags
);
1408 mutex_unlock(&qla_tgt_mutex
);
1412 if (tgt
->tgt_stop
|| tgt
->tgt_stopped
) {
1413 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04e,
1414 "Already in tgt->tgt_stop or tgt_stopped state\n");
1415 mutex_unlock(&qla_tgt_mutex
);
1419 ql_dbg(ql_dbg_tgt
, vha
, 0xe003, "Stopping target for host %ld(%p)\n",
1422 * Mutex needed to sync with qla_tgt_fc_port_[added,deleted].
1423 * Lock is needed, because we still can get an incoming packet.
1425 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
1426 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1428 qlt_clear_tgt_db(tgt
);
1429 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1430 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
1431 mutex_unlock(&qla_tgt_mutex
);
1433 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf009,
1434 "Waiting for sess works (tgt %p)", tgt
);
1435 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
1436 while (!list_empty(&tgt
->sess_works_list
)) {
1437 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
1438 flush_scheduled_work();
1439 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
1441 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
1443 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00a,
1444 "Waiting for tgt %p: sess_count=%d\n", tgt
, tgt
->sess_count
);
1446 wait_event(tgt
->waitQ
, test_tgt_sess_count(tgt
));
1449 if (!ha
->flags
.host_shutting_down
&&
1450 (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)))
1451 qlt_disable_vha(vha
);
1453 /* Wait for sessions to clear out (just in case) */
1454 wait_event(tgt
->waitQ
, test_tgt_sess_count(tgt
));
1457 EXPORT_SYMBOL(qlt_stop_phase1
);
1459 /* Called by tcm_qla2xxx configfs code */
1460 void qlt_stop_phase2(struct qla_tgt
*tgt
)
1462 struct qla_hw_data
*ha
= tgt
->ha
;
1463 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
1464 unsigned long flags
;
1466 if (tgt
->tgt_stopped
) {
1467 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04f,
1468 "Already in tgt->tgt_stopped state\n");
1473 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00b,
1474 "Waiting for %d IRQ commands to complete (tgt %p)",
1475 tgt
->irq_cmd_count
, tgt
);
1477 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
1478 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1479 while ((tgt
->irq_cmd_count
!= 0) || (tgt
->atio_irq_cmd_count
!= 0)) {
1480 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1482 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1485 tgt
->tgt_stopped
= 1;
1486 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1487 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
1489 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00c, "Stop of tgt %p finished",
1492 EXPORT_SYMBOL(qlt_stop_phase2
);
1494 /* Called from qlt_remove_target() -> qla2x00_remove_one() */
1495 static void qlt_release(struct qla_tgt
*tgt
)
1497 scsi_qla_host_t
*vha
= tgt
->vha
;
1499 if ((vha
->vha_tgt
.qla_tgt
!= NULL
) && !tgt
->tgt_stopped
)
1500 qlt_stop_phase2(tgt
);
1502 vha
->vha_tgt
.qla_tgt
= NULL
;
1504 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00d,
1505 "Release of tgt %p finished\n", tgt
);
1510 /* ha->hardware_lock supposed to be held on entry */
1511 static int qlt_sched_sess_work(struct qla_tgt
*tgt
, int type
,
1512 const void *param
, unsigned int param_size
)
1514 struct qla_tgt_sess_work_param
*prm
;
1515 unsigned long flags
;
1517 prm
= kzalloc(sizeof(*prm
), GFP_ATOMIC
);
1519 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf050,
1520 "qla_target(%d): Unable to create session "
1521 "work, command will be refused", 0);
1525 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf00e,
1526 "Scheduling work (type %d, prm %p)"
1527 " to find session for param %p (size %d, tgt %p)\n",
1528 type
, prm
, param
, param_size
, tgt
);
1531 memcpy(&prm
->tm_iocb
, param
, param_size
);
1533 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
1534 list_add_tail(&prm
->sess_works_list_entry
, &tgt
->sess_works_list
);
1535 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
1537 schedule_work(&tgt
->sess_work
);
1543 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1545 static void qlt_send_notify_ack(struct scsi_qla_host
*vha
,
1546 struct imm_ntfy_from_isp
*ntfy
,
1547 uint32_t add_flags
, uint16_t resp_code
, int resp_code_valid
,
1548 uint16_t srr_flags
, uint16_t srr_reject_code
, uint8_t srr_explan
)
1550 struct qla_hw_data
*ha
= vha
->hw
;
1552 struct nack_to_isp
*nack
;
1554 ql_dbg(ql_dbg_tgt
, vha
, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha
);
1556 /* Send marker if required */
1557 if (qlt_issue_marker(vha
, 1) != QLA_SUCCESS
)
1560 pkt
= (request_t
*)qla2x00_alloc_iocbs(vha
, NULL
);
1562 ql_dbg(ql_dbg_tgt
, vha
, 0xe049,
1563 "qla_target(%d): %s failed: unable to allocate "
1564 "request packet\n", vha
->vp_idx
, __func__
);
1568 if (vha
->vha_tgt
.qla_tgt
!= NULL
)
1569 vha
->vha_tgt
.qla_tgt
->notify_ack_expected
++;
1571 pkt
->entry_type
= NOTIFY_ACK_TYPE
;
1572 pkt
->entry_count
= 1;
1574 nack
= (struct nack_to_isp
*)pkt
;
1575 nack
->ox_id
= ntfy
->ox_id
;
1577 nack
->u
.isp24
.handle
= QLA_TGT_SKIP_HANDLE
;
1578 nack
->u
.isp24
.nport_handle
= ntfy
->u
.isp24
.nport_handle
;
1579 if (le16_to_cpu(ntfy
->u
.isp24
.status
) == IMM_NTFY_ELS
) {
1580 nack
->u
.isp24
.flags
= ntfy
->u
.isp24
.flags
&
1581 cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB
);
1583 nack
->u
.isp24
.srr_rx_id
= ntfy
->u
.isp24
.srr_rx_id
;
1584 nack
->u
.isp24
.status
= ntfy
->u
.isp24
.status
;
1585 nack
->u
.isp24
.status_subcode
= ntfy
->u
.isp24
.status_subcode
;
1586 nack
->u
.isp24
.fw_handle
= ntfy
->u
.isp24
.fw_handle
;
1587 nack
->u
.isp24
.exchange_address
= ntfy
->u
.isp24
.exchange_address
;
1588 nack
->u
.isp24
.srr_rel_offs
= ntfy
->u
.isp24
.srr_rel_offs
;
1589 nack
->u
.isp24
.srr_ui
= ntfy
->u
.isp24
.srr_ui
;
1590 nack
->u
.isp24
.srr_flags
= cpu_to_le16(srr_flags
);
1591 nack
->u
.isp24
.srr_reject_code
= srr_reject_code
;
1592 nack
->u
.isp24
.srr_reject_code_expl
= srr_explan
;
1593 nack
->u
.isp24
.vp_index
= ntfy
->u
.isp24
.vp_index
;
1595 ql_dbg(ql_dbg_tgt
, vha
, 0xe005,
1596 "qla_target(%d): Sending 24xx Notify Ack %d\n",
1597 vha
->vp_idx
, nack
->u
.isp24
.status
);
1599 /* Memory Barrier */
1601 qla2x00_start_iocbs(vha
, vha
->req
);
1605 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1607 static void qlt_24xx_send_abts_resp(struct scsi_qla_host
*vha
,
1608 struct abts_recv_from_24xx
*abts
, uint32_t status
,
1611 struct qla_hw_data
*ha
= vha
->hw
;
1612 struct abts_resp_to_24xx
*resp
;
1616 ql_dbg(ql_dbg_tgt
, vha
, 0xe006,
1617 "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n",
1620 /* Send marker if required */
1621 if (qlt_issue_marker(vha
, 1) != QLA_SUCCESS
)
1624 resp
= (struct abts_resp_to_24xx
*)qla2x00_alloc_iocbs_ready(vha
, NULL
);
1626 ql_dbg(ql_dbg_tgt
, vha
, 0xe04a,
1627 "qla_target(%d): %s failed: unable to allocate "
1628 "request packet", vha
->vp_idx
, __func__
);
1632 resp
->entry_type
= ABTS_RESP_24XX
;
1633 resp
->entry_count
= 1;
1634 resp
->nport_handle
= abts
->nport_handle
;
1635 resp
->vp_index
= vha
->vp_idx
;
1636 resp
->sof_type
= abts
->sof_type
;
1637 resp
->exchange_address
= abts
->exchange_address
;
1638 resp
->fcp_hdr_le
= abts
->fcp_hdr_le
;
1639 f_ctl
= cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP
|
1640 F_CTL_LAST_SEQ
| F_CTL_END_SEQ
|
1641 F_CTL_SEQ_INITIATIVE
);
1642 p
= (uint8_t *)&f_ctl
;
1643 resp
->fcp_hdr_le
.f_ctl
[0] = *p
++;
1644 resp
->fcp_hdr_le
.f_ctl
[1] = *p
++;
1645 resp
->fcp_hdr_le
.f_ctl
[2] = *p
;
1647 resp
->fcp_hdr_le
.d_id
[0] = abts
->fcp_hdr_le
.d_id
[0];
1648 resp
->fcp_hdr_le
.d_id
[1] = abts
->fcp_hdr_le
.d_id
[1];
1649 resp
->fcp_hdr_le
.d_id
[2] = abts
->fcp_hdr_le
.d_id
[2];
1650 resp
->fcp_hdr_le
.s_id
[0] = abts
->fcp_hdr_le
.s_id
[0];
1651 resp
->fcp_hdr_le
.s_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1652 resp
->fcp_hdr_le
.s_id
[2] = abts
->fcp_hdr_le
.s_id
[2];
1654 resp
->fcp_hdr_le
.d_id
[0] = abts
->fcp_hdr_le
.s_id
[0];
1655 resp
->fcp_hdr_le
.d_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1656 resp
->fcp_hdr_le
.d_id
[2] = abts
->fcp_hdr_le
.s_id
[2];
1657 resp
->fcp_hdr_le
.s_id
[0] = abts
->fcp_hdr_le
.d_id
[0];
1658 resp
->fcp_hdr_le
.s_id
[1] = abts
->fcp_hdr_le
.d_id
[1];
1659 resp
->fcp_hdr_le
.s_id
[2] = abts
->fcp_hdr_le
.d_id
[2];
1661 resp
->exchange_addr_to_abort
= abts
->exchange_addr_to_abort
;
1662 if (status
== FCP_TMF_CMPL
) {
1663 resp
->fcp_hdr_le
.r_ctl
= R_CTL_BASIC_LINK_SERV
| R_CTL_B_ACC
;
1664 resp
->payload
.ba_acct
.seq_id_valid
= SEQ_ID_INVALID
;
1665 resp
->payload
.ba_acct
.low_seq_cnt
= 0x0000;
1666 resp
->payload
.ba_acct
.high_seq_cnt
= 0xFFFF;
1667 resp
->payload
.ba_acct
.ox_id
= abts
->fcp_hdr_le
.ox_id
;
1668 resp
->payload
.ba_acct
.rx_id
= abts
->fcp_hdr_le
.rx_id
;
1670 resp
->fcp_hdr_le
.r_ctl
= R_CTL_BASIC_LINK_SERV
| R_CTL_B_RJT
;
1671 resp
->payload
.ba_rjt
.reason_code
=
1672 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM
;
1673 /* Other bytes are zero */
1676 vha
->vha_tgt
.qla_tgt
->abts_resp_expected
++;
1678 /* Memory Barrier */
1680 qla2x00_start_iocbs(vha
, vha
->req
);
1684 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1686 static void qlt_24xx_retry_term_exchange(struct scsi_qla_host
*vha
,
1687 struct abts_resp_from_24xx_fw
*entry
)
1689 struct ctio7_to_24xx
*ctio
;
1691 ql_dbg(ql_dbg_tgt
, vha
, 0xe007,
1692 "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha
->hw
);
1693 /* Send marker if required */
1694 if (qlt_issue_marker(vha
, 1) != QLA_SUCCESS
)
1697 ctio
= (struct ctio7_to_24xx
*)qla2x00_alloc_iocbs_ready(vha
, NULL
);
1699 ql_dbg(ql_dbg_tgt
, vha
, 0xe04b,
1700 "qla_target(%d): %s failed: unable to allocate "
1701 "request packet\n", vha
->vp_idx
, __func__
);
1706 * We've got on entrance firmware's response on by us generated
1707 * ABTS response. So, in it ID fields are reversed.
1710 ctio
->entry_type
= CTIO_TYPE7
;
1711 ctio
->entry_count
= 1;
1712 ctio
->nport_handle
= entry
->nport_handle
;
1713 ctio
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
1714 ctio
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
1715 ctio
->vp_index
= vha
->vp_idx
;
1716 ctio
->initiator_id
[0] = entry
->fcp_hdr_le
.d_id
[0];
1717 ctio
->initiator_id
[1] = entry
->fcp_hdr_le
.d_id
[1];
1718 ctio
->initiator_id
[2] = entry
->fcp_hdr_le
.d_id
[2];
1719 ctio
->exchange_addr
= entry
->exchange_addr_to_abort
;
1720 ctio
->u
.status1
.flags
= cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
|
1721 CTIO7_FLAGS_TERMINATE
);
1722 ctio
->u
.status1
.ox_id
= cpu_to_le16(entry
->fcp_hdr_le
.ox_id
);
1724 /* Memory Barrier */
1726 qla2x00_start_iocbs(vha
, vha
->req
);
1728 qlt_24xx_send_abts_resp(vha
, (struct abts_recv_from_24xx
*)entry
,
1729 FCP_TMF_CMPL
, true);
1732 static int abort_cmd_for_tag(struct scsi_qla_host
*vha
, uint32_t tag
)
1734 struct qla_tgt_sess_op
*op
;
1735 struct qla_tgt_cmd
*cmd
;
1737 spin_lock(&vha
->cmd_list_lock
);
1739 list_for_each_entry(op
, &vha
->qla_sess_op_cmd_list
, cmd_list
) {
1740 if (tag
== op
->atio
.u
.isp24
.exchange_addr
) {
1742 spin_unlock(&vha
->cmd_list_lock
);
1747 list_for_each_entry(op
, &vha
->unknown_atio_list
, cmd_list
) {
1748 if (tag
== op
->atio
.u
.isp24
.exchange_addr
) {
1750 spin_unlock(&vha
->cmd_list_lock
);
1755 list_for_each_entry(cmd
, &vha
->qla_cmd_list
, cmd_list
) {
1756 if (tag
== cmd
->atio
.u
.isp24
.exchange_addr
) {
1758 spin_unlock(&vha
->cmd_list_lock
);
1763 spin_unlock(&vha
->cmd_list_lock
);
1767 /* drop cmds for the given lun
1768 * XXX only looks for cmds on the port through which lun reset was recieved
1769 * XXX does not go through the list of other port (which may have cmds
1772 static void abort_cmds_for_lun(struct scsi_qla_host
*vha
,
1773 uint32_t lun
, uint8_t *s_id
)
1775 struct qla_tgt_sess_op
*op
;
1776 struct qla_tgt_cmd
*cmd
;
1779 key
= sid_to_key(s_id
);
1780 spin_lock(&vha
->cmd_list_lock
);
1781 list_for_each_entry(op
, &vha
->qla_sess_op_cmd_list
, cmd_list
) {
1785 op_key
= sid_to_key(op
->atio
.u
.isp24
.fcp_hdr
.s_id
);
1786 op_lun
= scsilun_to_int(
1787 (struct scsi_lun
*)&op
->atio
.u
.isp24
.fcp_cmnd
.lun
);
1788 if (op_key
== key
&& op_lun
== lun
)
1792 list_for_each_entry(op
, &vha
->unknown_atio_list
, cmd_list
) {
1796 op_key
= sid_to_key(op
->atio
.u
.isp24
.fcp_hdr
.s_id
);
1797 op_lun
= scsilun_to_int(
1798 (struct scsi_lun
*)&op
->atio
.u
.isp24
.fcp_cmnd
.lun
);
1799 if (op_key
== key
&& op_lun
== lun
)
1803 list_for_each_entry(cmd
, &vha
->qla_cmd_list
, cmd_list
) {
1807 cmd_key
= sid_to_key(cmd
->atio
.u
.isp24
.fcp_hdr
.s_id
);
1808 cmd_lun
= scsilun_to_int(
1809 (struct scsi_lun
*)&cmd
->atio
.u
.isp24
.fcp_cmnd
.lun
);
1810 if (cmd_key
== key
&& cmd_lun
== lun
)
1813 spin_unlock(&vha
->cmd_list_lock
);
1816 /* ha->hardware_lock supposed to be held on entry */
1817 static int __qlt_24xx_handle_abts(struct scsi_qla_host
*vha
,
1818 struct abts_recv_from_24xx
*abts
, struct fc_port
*sess
)
1820 struct qla_hw_data
*ha
= vha
->hw
;
1821 struct se_session
*se_sess
= sess
->se_sess
;
1822 struct qla_tgt_mgmt_cmd
*mcmd
;
1823 struct se_cmd
*se_cmd
;
1826 bool found_lun
= false;
1827 unsigned long flags
;
1829 spin_lock_irqsave(&se_sess
->sess_cmd_lock
, flags
);
1830 list_for_each_entry(se_cmd
, &se_sess
->sess_cmd_list
, se_cmd_list
) {
1831 struct qla_tgt_cmd
*cmd
=
1832 container_of(se_cmd
, struct qla_tgt_cmd
, se_cmd
);
1833 if (se_cmd
->tag
== abts
->exchange_addr_to_abort
) {
1834 lun
= cmd
->unpacked_lun
;
1839 spin_unlock_irqrestore(&se_sess
->sess_cmd_lock
, flags
);
1841 /* cmd not in LIO lists, look in qla list */
1843 if (abort_cmd_for_tag(vha
, abts
->exchange_addr_to_abort
)) {
1844 /* send TASK_ABORT response immediately */
1845 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_CMPL
, false);
1848 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf081,
1849 "unable to find cmd in driver or LIO for tag 0x%x\n",
1850 abts
->exchange_addr_to_abort
);
1855 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00f,
1856 "qla_target(%d): task abort (tag=%d)\n",
1857 vha
->vp_idx
, abts
->exchange_addr_to_abort
);
1859 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
1861 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf051,
1862 "qla_target(%d): %s: Allocation of ABORT cmd failed",
1863 vha
->vp_idx
, __func__
);
1866 memset(mcmd
, 0, sizeof(*mcmd
));
1869 memcpy(&mcmd
->orig_iocb
.abts
, abts
, sizeof(mcmd
->orig_iocb
.abts
));
1870 mcmd
->reset_count
= vha
->hw
->chip_reset
;
1871 mcmd
->tmr_func
= QLA_TGT_ABTS
;
1873 rc
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, lun
, mcmd
->tmr_func
,
1874 abts
->exchange_addr_to_abort
);
1876 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf052,
1877 "qla_target(%d): tgt_ops->handle_tmr()"
1878 " failed: %d", vha
->vp_idx
, rc
);
1879 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
1887 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1889 static void qlt_24xx_handle_abts(struct scsi_qla_host
*vha
,
1890 struct abts_recv_from_24xx
*abts
)
1892 struct qla_hw_data
*ha
= vha
->hw
;
1893 struct fc_port
*sess
;
1894 uint32_t tag
= abts
->exchange_addr_to_abort
;
1897 unsigned long flags
;
1899 if (le32_to_cpu(abts
->fcp_hdr_le
.parameter
) & ABTS_PARAM_ABORT_SEQ
) {
1900 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf053,
1901 "qla_target(%d): ABTS: Abort Sequence not "
1902 "supported\n", vha
->vp_idx
);
1903 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
, false);
1907 if (tag
== ATIO_EXCHANGE_ADDRESS_UNKNOWN
) {
1908 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf010,
1909 "qla_target(%d): ABTS: Unknown Exchange "
1910 "Address received\n", vha
->vp_idx
);
1911 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
, false);
1915 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf011,
1916 "qla_target(%d): task abort (s_id=%x:%x:%x, "
1917 "tag=%d, param=%x)\n", vha
->vp_idx
, abts
->fcp_hdr_le
.s_id
[2],
1918 abts
->fcp_hdr_le
.s_id
[1], abts
->fcp_hdr_le
.s_id
[0], tag
,
1919 le32_to_cpu(abts
->fcp_hdr_le
.parameter
));
1921 s_id
[0] = abts
->fcp_hdr_le
.s_id
[2];
1922 s_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1923 s_id
[2] = abts
->fcp_hdr_le
.s_id
[0];
1925 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1926 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, s_id
);
1928 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf012,
1929 "qla_target(%d): task abort for non-existant session\n",
1931 rc
= qlt_sched_sess_work(vha
->vha_tgt
.qla_tgt
,
1932 QLA_TGT_SESS_WORK_ABORT
, abts
, sizeof(*abts
));
1934 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1937 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
,
1942 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1945 if (sess
->deleted
) {
1946 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
, false);
1950 rc
= __qlt_24xx_handle_abts(vha
, abts
, sess
);
1952 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf054,
1953 "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n",
1955 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
, false);
1961 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1963 static void qlt_24xx_send_task_mgmt_ctio(struct scsi_qla_host
*ha
,
1964 struct qla_tgt_mgmt_cmd
*mcmd
, uint32_t resp_code
)
1966 struct atio_from_isp
*atio
= &mcmd
->orig_iocb
.atio
;
1967 struct ctio7_to_24xx
*ctio
;
1970 ql_dbg(ql_dbg_tgt
, ha
, 0xe008,
1971 "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n",
1972 ha
, atio
, resp_code
);
1974 /* Send marker if required */
1975 if (qlt_issue_marker(ha
, 1) != QLA_SUCCESS
)
1978 ctio
= (struct ctio7_to_24xx
*)qla2x00_alloc_iocbs(ha
, NULL
);
1980 ql_dbg(ql_dbg_tgt
, ha
, 0xe04c,
1981 "qla_target(%d): %s failed: unable to allocate "
1982 "request packet\n", ha
->vp_idx
, __func__
);
1986 ctio
->entry_type
= CTIO_TYPE7
;
1987 ctio
->entry_count
= 1;
1988 ctio
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
1989 ctio
->nport_handle
= mcmd
->sess
->loop_id
;
1990 ctio
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
1991 ctio
->vp_index
= ha
->vp_idx
;
1992 ctio
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
1993 ctio
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
1994 ctio
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
1995 ctio
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
1996 ctio
->u
.status1
.flags
= (atio
->u
.isp24
.attr
<< 9) |
1997 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
| CTIO7_FLAGS_SEND_STATUS
);
1998 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
1999 ctio
->u
.status1
.ox_id
= cpu_to_le16(temp
);
2000 ctio
->u
.status1
.scsi_status
=
2001 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID
);
2002 ctio
->u
.status1
.response_len
= cpu_to_le16(8);
2003 ctio
->u
.status1
.sense_data
[0] = resp_code
;
2005 /* Memory Barrier */
2007 qla2x00_start_iocbs(ha
, ha
->req
);
2010 void qlt_free_mcmd(struct qla_tgt_mgmt_cmd
*mcmd
)
2012 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
2014 EXPORT_SYMBOL(qlt_free_mcmd
);
2016 /* callback from target fabric module code */
2017 void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd
*mcmd
)
2019 struct scsi_qla_host
*vha
= mcmd
->sess
->vha
;
2020 struct qla_hw_data
*ha
= vha
->hw
;
2021 unsigned long flags
;
2023 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf013,
2024 "TM response mcmd (%p) status %#x state %#x",
2025 mcmd
, mcmd
->fc_tm_rsp
, mcmd
->flags
);
2027 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2029 if (!vha
->flags
.online
|| mcmd
->reset_count
!= ha
->chip_reset
) {
2031 * Either the port is not online or this request was from
2032 * previous life, just abort the processing.
2034 ql_dbg(ql_dbg_async
, vha
, 0xe100,
2035 "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n",
2036 vha
->flags
.online
, qla2x00_reset_active(vha
),
2037 mcmd
->reset_count
, ha
->chip_reset
);
2038 ha
->tgt
.tgt_ops
->free_mcmd(mcmd
);
2039 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2043 if (mcmd
->flags
== QLA24XX_MGMT_SEND_NACK
) {
2044 if (mcmd
->orig_iocb
.imm_ntfy
.u
.isp24
.status_subcode
==
2046 mcmd
->orig_iocb
.imm_ntfy
.u
.isp24
.status_subcode
==
2048 mcmd
->orig_iocb
.imm_ntfy
.u
.isp24
.status_subcode
==
2050 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
2051 "TM response logo %phC status %#x state %#x",
2052 mcmd
->sess
->port_name
, mcmd
->fc_tm_rsp
,
2054 qlt_schedule_sess_for_deletion_lock(mcmd
->sess
);
2056 qlt_send_notify_ack(vha
, &mcmd
->orig_iocb
.imm_ntfy
,
2060 if (mcmd
->orig_iocb
.atio
.u
.raw
.entry_type
== ABTS_RECV_24XX
)
2061 qlt_24xx_send_abts_resp(vha
, &mcmd
->orig_iocb
.abts
,
2062 mcmd
->fc_tm_rsp
, false);
2064 qlt_24xx_send_task_mgmt_ctio(vha
, mcmd
,
2068 * Make the callback for ->free_mcmd() to queue_work() and invoke
2069 * target_put_sess_cmd() to drop cmd_kref to 1. The final
2070 * target_put_sess_cmd() call will be made from TFO->check_stop_free()
2071 * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd
2072 * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() ->
2073 * qlt_xmit_tm_rsp() returns here..
2075 ha
->tgt
.tgt_ops
->free_mcmd(mcmd
);
2076 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2078 EXPORT_SYMBOL(qlt_xmit_tm_rsp
);
2081 static int qlt_pci_map_calc_cnt(struct qla_tgt_prm
*prm
)
2083 struct qla_tgt_cmd
*cmd
= prm
->cmd
;
2085 BUG_ON(cmd
->sg_cnt
== 0);
2087 prm
->sg
= (struct scatterlist
*)cmd
->sg
;
2088 prm
->seg_cnt
= pci_map_sg(prm
->tgt
->ha
->pdev
, cmd
->sg
,
2089 cmd
->sg_cnt
, cmd
->dma_data_direction
);
2090 if (unlikely(prm
->seg_cnt
== 0))
2093 prm
->cmd
->sg_mapped
= 1;
2095 if (cmd
->se_cmd
.prot_op
== TARGET_PROT_NORMAL
) {
2097 * If greater than four sg entries then we need to allocate
2098 * the continuation entries
2100 if (prm
->seg_cnt
> prm
->tgt
->datasegs_per_cmd
)
2101 prm
->req_cnt
+= DIV_ROUND_UP(prm
->seg_cnt
-
2102 prm
->tgt
->datasegs_per_cmd
,
2103 prm
->tgt
->datasegs_per_cont
);
2106 if ((cmd
->se_cmd
.prot_op
== TARGET_PROT_DIN_INSERT
) ||
2107 (cmd
->se_cmd
.prot_op
== TARGET_PROT_DOUT_STRIP
)) {
2108 prm
->seg_cnt
= DIV_ROUND_UP(cmd
->bufflen
, cmd
->blk_sz
);
2109 prm
->tot_dsds
= prm
->seg_cnt
;
2111 prm
->tot_dsds
= prm
->seg_cnt
;
2113 if (cmd
->prot_sg_cnt
) {
2114 prm
->prot_sg
= cmd
->prot_sg
;
2115 prm
->prot_seg_cnt
= pci_map_sg(prm
->tgt
->ha
->pdev
,
2116 cmd
->prot_sg
, cmd
->prot_sg_cnt
,
2117 cmd
->dma_data_direction
);
2118 if (unlikely(prm
->prot_seg_cnt
== 0))
2121 if ((cmd
->se_cmd
.prot_op
== TARGET_PROT_DIN_INSERT
) ||
2122 (cmd
->se_cmd
.prot_op
== TARGET_PROT_DOUT_STRIP
)) {
2123 /* Dif Bundling not support here */
2124 prm
->prot_seg_cnt
= DIV_ROUND_UP(cmd
->bufflen
,
2126 prm
->tot_dsds
+= prm
->prot_seg_cnt
;
2128 prm
->tot_dsds
+= prm
->prot_seg_cnt
;
2135 ql_dbg(ql_dbg_tgt
, prm
->cmd
->vha
, 0xe04d,
2136 "qla_target(%d): PCI mapping failed: sg_cnt=%d",
2137 0, prm
->cmd
->sg_cnt
);
2141 static void qlt_unmap_sg(struct scsi_qla_host
*vha
, struct qla_tgt_cmd
*cmd
)
2143 struct qla_hw_data
*ha
= vha
->hw
;
2145 if (!cmd
->sg_mapped
)
2148 pci_unmap_sg(ha
->pdev
, cmd
->sg
, cmd
->sg_cnt
, cmd
->dma_data_direction
);
2151 if (cmd
->prot_sg_cnt
)
2152 pci_unmap_sg(ha
->pdev
, cmd
->prot_sg
, cmd
->prot_sg_cnt
,
2153 cmd
->dma_data_direction
);
2155 if (cmd
->ctx_dsd_alloced
)
2156 qla2x00_clean_dsd_pool(ha
, NULL
, cmd
);
2159 dma_pool_free(ha
->dl_dma_pool
, cmd
->ctx
, cmd
->ctx
->crc_ctx_dma
);
2162 static int qlt_check_reserve_free_req(struct scsi_qla_host
*vha
,
2165 uint32_t cnt
, cnt_in
;
2167 if (vha
->req
->cnt
< (req_cnt
+ 2)) {
2168 cnt
= (uint16_t)RD_REG_DWORD(vha
->req
->req_q_out
);
2169 cnt_in
= (uint16_t)RD_REG_DWORD(vha
->req
->req_q_in
);
2171 if (vha
->req
->ring_index
< cnt
)
2172 vha
->req
->cnt
= cnt
- vha
->req
->ring_index
;
2174 vha
->req
->cnt
= vha
->req
->length
-
2175 (vha
->req
->ring_index
- cnt
);
2177 if (unlikely(vha
->req
->cnt
< (req_cnt
+ 2))) {
2178 ql_dbg(ql_dbg_io
, vha
, 0x305a,
2179 "qla_target(%d): There is no room in the request ring: vha->req->ring_index=%d, vha->req->cnt=%d, req_cnt=%d Req-out=%d Req-in=%d Req-Length=%d\n",
2180 vha
->vp_idx
, vha
->req
->ring_index
,
2181 vha
->req
->cnt
, req_cnt
, cnt
, cnt_in
,
2187 vha
->req
->cnt
-= req_cnt
;
2193 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2195 static inline void *qlt_get_req_pkt(struct scsi_qla_host
*vha
)
2197 /* Adjust ring index. */
2198 vha
->req
->ring_index
++;
2199 if (vha
->req
->ring_index
== vha
->req
->length
) {
2200 vha
->req
->ring_index
= 0;
2201 vha
->req
->ring_ptr
= vha
->req
->ring
;
2203 vha
->req
->ring_ptr
++;
2205 return (cont_entry_t
*)vha
->req
->ring_ptr
;
2208 /* ha->hardware_lock supposed to be held on entry */
2209 static inline uint32_t qlt_make_handle(struct scsi_qla_host
*vha
)
2211 struct qla_hw_data
*ha
= vha
->hw
;
2214 h
= ha
->tgt
.current_handle
;
2215 /* always increment cmd handle */
2218 if (h
> DEFAULT_OUTSTANDING_COMMANDS
)
2219 h
= 1; /* 0 is QLA_TGT_NULL_HANDLE */
2220 if (h
== ha
->tgt
.current_handle
) {
2221 ql_dbg(ql_dbg_io
, vha
, 0x305b,
2222 "qla_target(%d): Ran out of "
2223 "empty cmd slots in ha %p\n", vha
->vp_idx
, ha
);
2224 h
= QLA_TGT_NULL_HANDLE
;
2227 } while ((h
== QLA_TGT_NULL_HANDLE
) ||
2228 (h
== QLA_TGT_SKIP_HANDLE
) ||
2229 (ha
->tgt
.cmds
[h
-1] != NULL
));
2231 if (h
!= QLA_TGT_NULL_HANDLE
)
2232 ha
->tgt
.current_handle
= h
;
2237 /* ha->hardware_lock supposed to be held on entry */
2238 static int qlt_24xx_build_ctio_pkt(struct qla_tgt_prm
*prm
,
2239 struct scsi_qla_host
*vha
)
2242 struct ctio7_to_24xx
*pkt
;
2243 struct qla_hw_data
*ha
= vha
->hw
;
2244 struct atio_from_isp
*atio
= &prm
->cmd
->atio
;
2247 pkt
= (struct ctio7_to_24xx
*)vha
->req
->ring_ptr
;
2249 memset(pkt
, 0, sizeof(*pkt
));
2251 pkt
->entry_type
= CTIO_TYPE7
;
2252 pkt
->entry_count
= (uint8_t)prm
->req_cnt
;
2253 pkt
->vp_index
= vha
->vp_idx
;
2255 h
= qlt_make_handle(vha
);
2256 if (unlikely(h
== QLA_TGT_NULL_HANDLE
)) {
2258 * CTIO type 7 from the firmware doesn't provide a way to
2259 * know the initiator's LOOP ID, hence we can't find
2260 * the session and, so, the command.
2264 ha
->tgt
.cmds
[h
-1] = prm
->cmd
;
2266 pkt
->handle
= h
| CTIO_COMPLETION_HANDLE_MARK
;
2267 pkt
->nport_handle
= prm
->cmd
->loop_id
;
2268 pkt
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
2269 pkt
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
2270 pkt
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
2271 pkt
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
2272 pkt
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2273 pkt
->u
.status0
.flags
|= (atio
->u
.isp24
.attr
<< 9);
2274 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2275 pkt
->u
.status0
.ox_id
= cpu_to_le16(temp
);
2276 pkt
->u
.status0
.relative_offset
= cpu_to_le32(prm
->cmd
->offset
);
2282 * ha->hardware_lock supposed to be held on entry. We have already made sure
2283 * that there is sufficient amount of request entries to not drop it.
2285 static void qlt_load_cont_data_segments(struct qla_tgt_prm
*prm
,
2286 struct scsi_qla_host
*vha
)
2289 uint32_t *dword_ptr
;
2290 int enable_64bit_addressing
= prm
->tgt
->tgt_enable_64bit_addr
;
2292 /* Build continuation packets */
2293 while (prm
->seg_cnt
> 0) {
2294 cont_a64_entry_t
*cont_pkt64
=
2295 (cont_a64_entry_t
*)qlt_get_req_pkt(vha
);
2298 * Make sure that from cont_pkt64 none of
2299 * 64-bit specific fields used for 32-bit
2300 * addressing. Cast to (cont_entry_t *) for
2304 memset(cont_pkt64
, 0, sizeof(*cont_pkt64
));
2306 cont_pkt64
->entry_count
= 1;
2307 cont_pkt64
->sys_define
= 0;
2309 if (enable_64bit_addressing
) {
2310 cont_pkt64
->entry_type
= CONTINUE_A64_TYPE
;
2312 (uint32_t *)&cont_pkt64
->dseg_0_address
;
2314 cont_pkt64
->entry_type
= CONTINUE_TYPE
;
2316 (uint32_t *)&((cont_entry_t
*)
2317 cont_pkt64
)->dseg_0_address
;
2320 /* Load continuation entry data segments */
2322 cnt
< prm
->tgt
->datasegs_per_cont
&& prm
->seg_cnt
;
2323 cnt
++, prm
->seg_cnt
--) {
2325 cpu_to_le32(pci_dma_lo32
2326 (sg_dma_address(prm
->sg
)));
2327 if (enable_64bit_addressing
) {
2329 cpu_to_le32(pci_dma_hi32
2333 *dword_ptr
++ = cpu_to_le32(sg_dma_len(prm
->sg
));
2335 prm
->sg
= sg_next(prm
->sg
);
2341 * ha->hardware_lock supposed to be held on entry. We have already made sure
2342 * that there is sufficient amount of request entries to not drop it.
2344 static void qlt_load_data_segments(struct qla_tgt_prm
*prm
,
2345 struct scsi_qla_host
*vha
)
2348 uint32_t *dword_ptr
;
2349 int enable_64bit_addressing
= prm
->tgt
->tgt_enable_64bit_addr
;
2350 struct ctio7_to_24xx
*pkt24
= (struct ctio7_to_24xx
*)prm
->pkt
;
2352 pkt24
->u
.status0
.transfer_length
= cpu_to_le32(prm
->cmd
->bufflen
);
2354 /* Setup packet address segment pointer */
2355 dword_ptr
= pkt24
->u
.status0
.dseg_0_address
;
2357 /* Set total data segment count */
2359 pkt24
->dseg_count
= cpu_to_le16(prm
->seg_cnt
);
2361 if (prm
->seg_cnt
== 0) {
2362 /* No data transfer */
2368 /* If scatter gather */
2370 /* Load command entry data segments */
2372 (cnt
< prm
->tgt
->datasegs_per_cmd
) && prm
->seg_cnt
;
2373 cnt
++, prm
->seg_cnt
--) {
2375 cpu_to_le32(pci_dma_lo32(sg_dma_address(prm
->sg
)));
2376 if (enable_64bit_addressing
) {
2378 cpu_to_le32(pci_dma_hi32(
2379 sg_dma_address(prm
->sg
)));
2381 *dword_ptr
++ = cpu_to_le32(sg_dma_len(prm
->sg
));
2383 prm
->sg
= sg_next(prm
->sg
);
2386 qlt_load_cont_data_segments(prm
, vha
);
2389 static inline int qlt_has_data(struct qla_tgt_cmd
*cmd
)
2391 return cmd
->bufflen
> 0;
2395 * Called without ha->hardware_lock held
2397 static int qlt_pre_xmit_response(struct qla_tgt_cmd
*cmd
,
2398 struct qla_tgt_prm
*prm
, int xmit_type
, uint8_t scsi_status
,
2399 uint32_t *full_req_cnt
)
2401 struct qla_tgt
*tgt
= cmd
->tgt
;
2402 struct scsi_qla_host
*vha
= tgt
->vha
;
2403 struct qla_hw_data
*ha
= vha
->hw
;
2404 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
2408 prm
->rq_result
= scsi_status
;
2409 prm
->sense_buffer
= &cmd
->sense_buffer
[0];
2410 prm
->sense_buffer_len
= TRANSPORT_SENSE_BUFFER
;
2414 prm
->add_status_pkt
= 0;
2416 /* Send marker if required */
2417 if (qlt_issue_marker(vha
, 0) != QLA_SUCCESS
)
2420 if ((xmit_type
& QLA_TGT_XMIT_DATA
) && qlt_has_data(cmd
)) {
2421 if (qlt_pci_map_calc_cnt(prm
) != 0)
2425 *full_req_cnt
= prm
->req_cnt
;
2427 if (se_cmd
->se_cmd_flags
& SCF_UNDERFLOW_BIT
) {
2428 prm
->residual
= se_cmd
->residual_count
;
2429 ql_dbg(ql_dbg_io
+ ql_dbg_verbose
, vha
, 0x305c,
2430 "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2431 prm
->residual
, se_cmd
->tag
,
2432 se_cmd
->t_task_cdb
? se_cmd
->t_task_cdb
[0] : 0,
2433 cmd
->bufflen
, prm
->rq_result
);
2434 prm
->rq_result
|= SS_RESIDUAL_UNDER
;
2435 } else if (se_cmd
->se_cmd_flags
& SCF_OVERFLOW_BIT
) {
2436 prm
->residual
= se_cmd
->residual_count
;
2437 ql_dbg(ql_dbg_io
, vha
, 0x305d,
2438 "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2439 prm
->residual
, se_cmd
->tag
, se_cmd
->t_task_cdb
?
2440 se_cmd
->t_task_cdb
[0] : 0, cmd
->bufflen
, prm
->rq_result
);
2441 prm
->rq_result
|= SS_RESIDUAL_OVER
;
2444 if (xmit_type
& QLA_TGT_XMIT_STATUS
) {
2446 * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be
2447 * ignored in *xmit_response() below
2449 if (qlt_has_data(cmd
)) {
2450 if (QLA_TGT_SENSE_VALID(prm
->sense_buffer
) ||
2451 (IS_FWI2_CAPABLE(ha
) &&
2452 (prm
->rq_result
!= 0))) {
2453 prm
->add_status_pkt
= 1;
2462 static inline int qlt_need_explicit_conf(struct qla_hw_data
*ha
,
2463 struct qla_tgt_cmd
*cmd
, int sending_sense
)
2465 if (ha
->tgt
.enable_class_2
)
2469 return cmd
->conf_compl_supported
;
2471 return ha
->tgt
.enable_explicit_conf
&&
2472 cmd
->conf_compl_supported
;
2475 static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx
*ctio
,
2476 struct qla_tgt_prm
*prm
)
2478 prm
->sense_buffer_len
= min_t(uint32_t, prm
->sense_buffer_len
,
2479 (uint32_t)sizeof(ctio
->u
.status1
.sense_data
));
2480 ctio
->u
.status0
.flags
|= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS
);
2481 if (qlt_need_explicit_conf(prm
->tgt
->ha
, prm
->cmd
, 0)) {
2482 ctio
->u
.status0
.flags
|= cpu_to_le16(
2483 CTIO7_FLAGS_EXPLICIT_CONFORM
|
2484 CTIO7_FLAGS_CONFORM_REQ
);
2486 ctio
->u
.status0
.residual
= cpu_to_le32(prm
->residual
);
2487 ctio
->u
.status0
.scsi_status
= cpu_to_le16(prm
->rq_result
);
2488 if (QLA_TGT_SENSE_VALID(prm
->sense_buffer
)) {
2491 if (qlt_need_explicit_conf(prm
->tgt
->ha
, prm
->cmd
, 1)) {
2492 if ((prm
->rq_result
& SS_SCSI_STATUS_BYTE
) != 0) {
2493 ql_dbg(ql_dbg_tgt
, prm
->cmd
->vha
, 0xe017,
2494 "Skipping EXPLICIT_CONFORM and "
2495 "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ "
2496 "non GOOD status\n");
2497 goto skip_explict_conf
;
2499 ctio
->u
.status1
.flags
|= cpu_to_le16(
2500 CTIO7_FLAGS_EXPLICIT_CONFORM
|
2501 CTIO7_FLAGS_CONFORM_REQ
);
2504 ctio
->u
.status1
.flags
&=
2505 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0
);
2506 ctio
->u
.status1
.flags
|=
2507 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
);
2508 ctio
->u
.status1
.scsi_status
|=
2509 cpu_to_le16(SS_SENSE_LEN_VALID
);
2510 ctio
->u
.status1
.sense_length
=
2511 cpu_to_le16(prm
->sense_buffer_len
);
2512 for (i
= 0; i
< prm
->sense_buffer_len
/4; i
++)
2513 ((uint32_t *)ctio
->u
.status1
.sense_data
)[i
] =
2514 cpu_to_be32(((uint32_t *)prm
->sense_buffer
)[i
]);
2516 if (unlikely((prm
->sense_buffer_len
% 4) != 0)) {
2519 ql_dbg(ql_dbg_tgt
, vha
, 0xe04f,
2520 "qla_target(%d): %d bytes of sense "
2521 "lost", prm
->tgt
->ha
->vp_idx
,
2522 prm
->sense_buffer_len
% 4);
2528 ctio
->u
.status1
.flags
&=
2529 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0
);
2530 ctio
->u
.status1
.flags
|=
2531 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
);
2532 ctio
->u
.status1
.sense_length
= 0;
2533 memset(ctio
->u
.status1
.sense_data
, 0,
2534 sizeof(ctio
->u
.status1
.sense_data
));
2537 /* Sense with len > 24, is it possible ??? */
2544 qlt_hba_err_chk_enabled(struct se_cmd
*se_cmd
)
2547 * Uncomment when corresponding SCSI changes are done.
2549 if (!sp->cmd->prot_chk)
2553 switch (se_cmd
->prot_op
) {
2554 case TARGET_PROT_DOUT_INSERT
:
2555 case TARGET_PROT_DIN_STRIP
:
2556 if (ql2xenablehba_err_chk
>= 1)
2559 case TARGET_PROT_DOUT_PASS
:
2560 case TARGET_PROT_DIN_PASS
:
2561 if (ql2xenablehba_err_chk
>= 2)
2564 case TARGET_PROT_DIN_INSERT
:
2565 case TARGET_PROT_DOUT_STRIP
:
2574 * qla24xx_set_t10dif_tags_from_cmd - Extract Ref and App tags from SCSI command
2578 qlt_set_t10dif_tags(struct se_cmd
*se_cmd
, struct crc_context
*ctx
)
2580 uint32_t lba
= 0xffffffff & se_cmd
->t_task_lba
;
2582 /* wait til Mode Sense/Select cmd, modepage Ah, subpage 2
2583 * have been immplemented by TCM, before AppTag is avail.
2584 * Look for modesense_handlers[]
2587 ctx
->app_tag_mask
[0] = 0x0;
2588 ctx
->app_tag_mask
[1] = 0x0;
2590 switch (se_cmd
->prot_type
) {
2591 case TARGET_DIF_TYPE0_PROT
:
2593 * No check for ql2xenablehba_err_chk, as it would be an
2594 * I/O error if hba tag generation is not done.
2596 ctx
->ref_tag
= cpu_to_le32(lba
);
2598 if (!qlt_hba_err_chk_enabled(se_cmd
))
2601 /* enable ALL bytes of the ref tag */
2602 ctx
->ref_tag_mask
[0] = 0xff;
2603 ctx
->ref_tag_mask
[1] = 0xff;
2604 ctx
->ref_tag_mask
[2] = 0xff;
2605 ctx
->ref_tag_mask
[3] = 0xff;
2608 * For TYpe 1 protection: 16 bit GUARD tag, 32 bit REF tag, and
2611 case TARGET_DIF_TYPE1_PROT
:
2612 ctx
->ref_tag
= cpu_to_le32(lba
);
2614 if (!qlt_hba_err_chk_enabled(se_cmd
))
2617 /* enable ALL bytes of the ref tag */
2618 ctx
->ref_tag_mask
[0] = 0xff;
2619 ctx
->ref_tag_mask
[1] = 0xff;
2620 ctx
->ref_tag_mask
[2] = 0xff;
2621 ctx
->ref_tag_mask
[3] = 0xff;
2624 * For TYPE 2 protection: 16 bit GUARD + 32 bit REF tag has to
2625 * match LBA in CDB + N
2627 case TARGET_DIF_TYPE2_PROT
:
2628 ctx
->ref_tag
= cpu_to_le32(lba
);
2630 if (!qlt_hba_err_chk_enabled(se_cmd
))
2633 /* enable ALL bytes of the ref tag */
2634 ctx
->ref_tag_mask
[0] = 0xff;
2635 ctx
->ref_tag_mask
[1] = 0xff;
2636 ctx
->ref_tag_mask
[2] = 0xff;
2637 ctx
->ref_tag_mask
[3] = 0xff;
2640 /* For Type 3 protection: 16 bit GUARD only */
2641 case TARGET_DIF_TYPE3_PROT
:
2642 ctx
->ref_tag_mask
[0] = ctx
->ref_tag_mask
[1] =
2643 ctx
->ref_tag_mask
[2] = ctx
->ref_tag_mask
[3] = 0x00;
2650 qlt_build_ctio_crc2_pkt(struct qla_tgt_prm
*prm
, scsi_qla_host_t
*vha
)
2653 uint32_t transfer_length
= 0;
2654 uint32_t data_bytes
;
2656 uint8_t bundling
= 1;
2658 struct crc_context
*crc_ctx_pkt
= NULL
;
2659 struct qla_hw_data
*ha
;
2660 struct ctio_crc2_to_fw
*pkt
;
2661 dma_addr_t crc_ctx_dma
;
2662 uint16_t fw_prot_opts
= 0;
2663 struct qla_tgt_cmd
*cmd
= prm
->cmd
;
2664 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
2666 struct atio_from_isp
*atio
= &prm
->cmd
->atio
;
2671 pkt
= (struct ctio_crc2_to_fw
*)vha
->req
->ring_ptr
;
2673 memset(pkt
, 0, sizeof(*pkt
));
2675 ql_dbg(ql_dbg_tgt
, vha
, 0xe071,
2676 "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n",
2677 vha
->vp_idx
, __func__
, se_cmd
, se_cmd
->prot_op
,
2678 prm
->prot_sg
, prm
->prot_seg_cnt
, se_cmd
->t_task_lba
);
2680 if ((se_cmd
->prot_op
== TARGET_PROT_DIN_INSERT
) ||
2681 (se_cmd
->prot_op
== TARGET_PROT_DOUT_STRIP
))
2684 /* Compute dif len and adjust data len to incude protection */
2685 data_bytes
= cmd
->bufflen
;
2686 dif_bytes
= (data_bytes
/ cmd
->blk_sz
) * 8;
2688 switch (se_cmd
->prot_op
) {
2689 case TARGET_PROT_DIN_INSERT
:
2690 case TARGET_PROT_DOUT_STRIP
:
2691 transfer_length
= data_bytes
;
2692 data_bytes
+= dif_bytes
;
2695 case TARGET_PROT_DIN_STRIP
:
2696 case TARGET_PROT_DOUT_INSERT
:
2697 case TARGET_PROT_DIN_PASS
:
2698 case TARGET_PROT_DOUT_PASS
:
2699 transfer_length
= data_bytes
+ dif_bytes
;
2707 if (!qlt_hba_err_chk_enabled(se_cmd
))
2708 fw_prot_opts
|= 0x10; /* Disable Guard tag checking */
2709 /* HBA error checking enabled */
2710 else if (IS_PI_UNINIT_CAPABLE(ha
)) {
2711 if ((se_cmd
->prot_type
== TARGET_DIF_TYPE1_PROT
) ||
2712 (se_cmd
->prot_type
== TARGET_DIF_TYPE2_PROT
))
2713 fw_prot_opts
|= PO_DIS_VALD_APP_ESC
;
2714 else if (se_cmd
->prot_type
== TARGET_DIF_TYPE3_PROT
)
2715 fw_prot_opts
|= PO_DIS_VALD_APP_REF_ESC
;
2718 switch (se_cmd
->prot_op
) {
2719 case TARGET_PROT_DIN_INSERT
:
2720 case TARGET_PROT_DOUT_INSERT
:
2721 fw_prot_opts
|= PO_MODE_DIF_INSERT
;
2723 case TARGET_PROT_DIN_STRIP
:
2724 case TARGET_PROT_DOUT_STRIP
:
2725 fw_prot_opts
|= PO_MODE_DIF_REMOVE
;
2727 case TARGET_PROT_DIN_PASS
:
2728 case TARGET_PROT_DOUT_PASS
:
2729 fw_prot_opts
|= PO_MODE_DIF_PASS
;
2730 /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */
2732 default:/* Normal Request */
2733 fw_prot_opts
|= PO_MODE_DIF_PASS
;
2739 /* Update entry type to indicate Command Type CRC_2 IOCB */
2740 pkt
->entry_type
= CTIO_CRC2
;
2741 pkt
->entry_count
= 1;
2742 pkt
->vp_index
= vha
->vp_idx
;
2744 h
= qlt_make_handle(vha
);
2745 if (unlikely(h
== QLA_TGT_NULL_HANDLE
)) {
2747 * CTIO type 7 from the firmware doesn't provide a way to
2748 * know the initiator's LOOP ID, hence we can't find
2749 * the session and, so, the command.
2753 ha
->tgt
.cmds
[h
-1] = prm
->cmd
;
2756 pkt
->handle
= h
| CTIO_COMPLETION_HANDLE_MARK
;
2757 pkt
->nport_handle
= prm
->cmd
->loop_id
;
2758 pkt
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
2759 pkt
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
2760 pkt
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
2761 pkt
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
2762 pkt
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2764 /* silence compile warning */
2765 t16
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2766 pkt
->ox_id
= cpu_to_le16(t16
);
2768 t16
= (atio
->u
.isp24
.attr
<< 9);
2769 pkt
->flags
|= cpu_to_le16(t16
);
2770 pkt
->relative_offset
= cpu_to_le32(prm
->cmd
->offset
);
2772 /* Set transfer direction */
2773 if (cmd
->dma_data_direction
== DMA_TO_DEVICE
)
2774 pkt
->flags
= cpu_to_le16(CTIO7_FLAGS_DATA_IN
);
2775 else if (cmd
->dma_data_direction
== DMA_FROM_DEVICE
)
2776 pkt
->flags
= cpu_to_le16(CTIO7_FLAGS_DATA_OUT
);
2779 pkt
->dseg_count
= prm
->tot_dsds
;
2780 /* Fibre channel byte count */
2781 pkt
->transfer_length
= cpu_to_le32(transfer_length
);
2784 /* ----- CRC context -------- */
2786 /* Allocate CRC context from global pool */
2787 crc_ctx_pkt
= cmd
->ctx
=
2788 dma_pool_alloc(ha
->dl_dma_pool
, GFP_ATOMIC
, &crc_ctx_dma
);
2791 goto crc_queuing_error
;
2793 /* Zero out CTX area. */
2794 clr_ptr
= (uint8_t *)crc_ctx_pkt
;
2795 memset(clr_ptr
, 0, sizeof(*crc_ctx_pkt
));
2797 crc_ctx_pkt
->crc_ctx_dma
= crc_ctx_dma
;
2798 INIT_LIST_HEAD(&crc_ctx_pkt
->dsd_list
);
2801 crc_ctx_pkt
->handle
= pkt
->handle
;
2803 qlt_set_t10dif_tags(se_cmd
, crc_ctx_pkt
);
2805 pkt
->crc_context_address
[0] = cpu_to_le32(LSD(crc_ctx_dma
));
2806 pkt
->crc_context_address
[1] = cpu_to_le32(MSD(crc_ctx_dma
));
2807 pkt
->crc_context_len
= CRC_CONTEXT_LEN_FW
;
2811 cur_dsd
= (uint32_t *) &crc_ctx_pkt
->u
.nobundling
.data_address
;
2814 * Configure Bundling if we need to fetch interlaving
2815 * protection PCI accesses
2817 fw_prot_opts
|= PO_ENABLE_DIF_BUNDLING
;
2818 crc_ctx_pkt
->u
.bundling
.dif_byte_count
= cpu_to_le32(dif_bytes
);
2819 crc_ctx_pkt
->u
.bundling
.dseg_count
=
2820 cpu_to_le16(prm
->tot_dsds
- prm
->prot_seg_cnt
);
2821 cur_dsd
= (uint32_t *) &crc_ctx_pkt
->u
.bundling
.data_address
;
2824 /* Finish the common fields of CRC pkt */
2825 crc_ctx_pkt
->blk_size
= cpu_to_le16(cmd
->blk_sz
);
2826 crc_ctx_pkt
->prot_opts
= cpu_to_le16(fw_prot_opts
);
2827 crc_ctx_pkt
->byte_count
= cpu_to_le32(data_bytes
);
2828 crc_ctx_pkt
->guard_seed
= cpu_to_le16(0);
2831 /* Walks data segments */
2832 pkt
->flags
|= cpu_to_le16(CTIO7_FLAGS_DSD_PTR
);
2834 if (!bundling
&& prm
->prot_seg_cnt
) {
2835 if (qla24xx_walk_and_build_sglist_no_difb(ha
, NULL
, cur_dsd
,
2836 prm
->tot_dsds
, cmd
))
2837 goto crc_queuing_error
;
2838 } else if (qla24xx_walk_and_build_sglist(ha
, NULL
, cur_dsd
,
2839 (prm
->tot_dsds
- prm
->prot_seg_cnt
), cmd
))
2840 goto crc_queuing_error
;
2842 if (bundling
&& prm
->prot_seg_cnt
) {
2843 /* Walks dif segments */
2844 pkt
->add_flags
|= CTIO_CRC2_AF_DIF_DSD_ENA
;
2846 cur_dsd
= (uint32_t *) &crc_ctx_pkt
->u
.bundling
.dif_address
;
2847 if (qla24xx_walk_and_build_prot_sglist(ha
, NULL
, cur_dsd
,
2848 prm
->prot_seg_cnt
, cmd
))
2849 goto crc_queuing_error
;
2854 /* Cleanup will be performed by the caller */
2856 return QLA_FUNCTION_FAILED
;
2861 * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and *
2862 * QLA_TGT_XMIT_STATUS for >= 24xx silicon
2864 int qlt_xmit_response(struct qla_tgt_cmd
*cmd
, int xmit_type
,
2865 uint8_t scsi_status
)
2867 struct scsi_qla_host
*vha
= cmd
->vha
;
2868 struct qla_hw_data
*ha
= vha
->hw
;
2869 struct ctio7_to_24xx
*pkt
;
2870 struct qla_tgt_prm prm
;
2871 uint32_t full_req_cnt
= 0;
2872 unsigned long flags
= 0;
2875 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2876 if (cmd
->sess
&& cmd
->sess
->deleted
) {
2877 cmd
->state
= QLA_TGT_STATE_PROCESSED
;
2878 if (cmd
->sess
->logout_completed
)
2879 /* no need to terminate. FW already freed exchange. */
2880 qlt_abort_cmd_on_host_reset(cmd
->vha
, cmd
);
2882 qlt_send_term_exchange(vha
, cmd
, &cmd
->atio
, 1, 0);
2883 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2886 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2888 memset(&prm
, 0, sizeof(prm
));
2890 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe018,
2891 "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p]\n",
2892 (xmit_type
& QLA_TGT_XMIT_STATUS
) ?
2893 1 : 0, cmd
->bufflen
, cmd
->sg_cnt
, cmd
->dma_data_direction
,
2896 res
= qlt_pre_xmit_response(cmd
, &prm
, xmit_type
, scsi_status
,
2898 if (unlikely(res
!= 0)) {
2902 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2904 if (xmit_type
== QLA_TGT_XMIT_STATUS
)
2905 vha
->tgt_counters
.core_qla_snd_status
++;
2907 vha
->tgt_counters
.core_qla_que_buf
++;
2909 if (!vha
->flags
.online
|| cmd
->reset_count
!= ha
->chip_reset
) {
2911 * Either the port is not online or this request was from
2912 * previous life, just abort the processing.
2914 cmd
->state
= QLA_TGT_STATE_PROCESSED
;
2915 qlt_abort_cmd_on_host_reset(cmd
->vha
, cmd
);
2916 ql_dbg(ql_dbg_async
, vha
, 0xe101,
2917 "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n",
2918 vha
->flags
.online
, qla2x00_reset_active(vha
),
2919 cmd
->reset_count
, ha
->chip_reset
);
2920 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2924 /* Does F/W have an IOCBs for this request */
2925 res
= qlt_check_reserve_free_req(vha
, full_req_cnt
);
2927 goto out_unmap_unlock
;
2929 if (cmd
->se_cmd
.prot_op
&& (xmit_type
& QLA_TGT_XMIT_DATA
))
2930 res
= qlt_build_ctio_crc2_pkt(&prm
, vha
);
2932 res
= qlt_24xx_build_ctio_pkt(&prm
, vha
);
2933 if (unlikely(res
!= 0)) {
2934 vha
->req
->cnt
+= full_req_cnt
;
2935 goto out_unmap_unlock
;
2938 pkt
= (struct ctio7_to_24xx
*)prm
.pkt
;
2940 if (qlt_has_data(cmd
) && (xmit_type
& QLA_TGT_XMIT_DATA
)) {
2941 pkt
->u
.status0
.flags
|=
2942 cpu_to_le16(CTIO7_FLAGS_DATA_IN
|
2943 CTIO7_FLAGS_STATUS_MODE_0
);
2945 if (cmd
->se_cmd
.prot_op
== TARGET_PROT_NORMAL
)
2946 qlt_load_data_segments(&prm
, vha
);
2948 if (prm
.add_status_pkt
== 0) {
2949 if (xmit_type
& QLA_TGT_XMIT_STATUS
) {
2950 pkt
->u
.status0
.scsi_status
=
2951 cpu_to_le16(prm
.rq_result
);
2952 pkt
->u
.status0
.residual
=
2953 cpu_to_le32(prm
.residual
);
2954 pkt
->u
.status0
.flags
|= cpu_to_le16(
2955 CTIO7_FLAGS_SEND_STATUS
);
2956 if (qlt_need_explicit_conf(ha
, cmd
, 0)) {
2957 pkt
->u
.status0
.flags
|=
2959 CTIO7_FLAGS_EXPLICIT_CONFORM
|
2960 CTIO7_FLAGS_CONFORM_REQ
);
2966 * We have already made sure that there is sufficient
2967 * amount of request entries to not drop HW lock in
2970 struct ctio7_to_24xx
*ctio
=
2971 (struct ctio7_to_24xx
*)qlt_get_req_pkt(vha
);
2973 ql_dbg(ql_dbg_io
, vha
, 0x305e,
2974 "Building additional status packet 0x%p.\n",
2978 * T10Dif: ctio_crc2_to_fw overlay ontop of
2981 memcpy(ctio
, pkt
, sizeof(*ctio
));
2982 /* reset back to CTIO7 */
2983 ctio
->entry_count
= 1;
2984 ctio
->entry_type
= CTIO_TYPE7
;
2985 ctio
->dseg_count
= 0;
2986 ctio
->u
.status1
.flags
&= ~cpu_to_le16(
2987 CTIO7_FLAGS_DATA_IN
);
2989 /* Real finish is ctio_m1's finish */
2990 pkt
->handle
|= CTIO_INTERMEDIATE_HANDLE_MARK
;
2991 pkt
->u
.status0
.flags
|= cpu_to_le16(
2992 CTIO7_FLAGS_DONT_RET_CTIO
);
2994 /* qlt_24xx_init_ctio_to_isp will correct
2995 * all neccessary fields that's part of CTIO7.
2996 * There should be no residual of CTIO-CRC2 data.
2998 qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx
*)ctio
,
3000 pr_debug("Status CTIO7: %p\n", ctio
);
3003 qlt_24xx_init_ctio_to_isp(pkt
, &prm
);
3006 cmd
->state
= QLA_TGT_STATE_PROCESSED
; /* Mid-level is done processing */
3007 cmd
->cmd_sent_to_fw
= 1;
3009 /* Memory Barrier */
3011 qla2x00_start_iocbs(vha
, vha
->req
);
3012 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3017 qlt_unmap_sg(vha
, cmd
);
3018 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3022 EXPORT_SYMBOL(qlt_xmit_response
);
3024 int qlt_rdy_to_xfer(struct qla_tgt_cmd
*cmd
)
3026 struct ctio7_to_24xx
*pkt
;
3027 struct scsi_qla_host
*vha
= cmd
->vha
;
3028 struct qla_hw_data
*ha
= vha
->hw
;
3029 struct qla_tgt
*tgt
= cmd
->tgt
;
3030 struct qla_tgt_prm prm
;
3031 unsigned long flags
;
3034 memset(&prm
, 0, sizeof(prm
));
3040 /* Send marker if required */
3041 if (qlt_issue_marker(vha
, 0) != QLA_SUCCESS
)
3044 /* Calculate number of entries and segments required */
3045 if (qlt_pci_map_calc_cnt(&prm
) != 0)
3048 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3050 if (!vha
->flags
.online
|| (cmd
->reset_count
!= ha
->chip_reset
) ||
3051 (cmd
->sess
&& cmd
->sess
->deleted
)) {
3053 * Either the port is not online or this request was from
3054 * previous life, just abort the processing.
3056 cmd
->state
= QLA_TGT_STATE_NEED_DATA
;
3057 qlt_abort_cmd_on_host_reset(cmd
->vha
, cmd
);
3058 ql_dbg(ql_dbg_async
, vha
, 0xe102,
3059 "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n",
3060 vha
->flags
.online
, qla2x00_reset_active(vha
),
3061 cmd
->reset_count
, ha
->chip_reset
);
3062 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3066 /* Does F/W have an IOCBs for this request */
3067 res
= qlt_check_reserve_free_req(vha
, prm
.req_cnt
);
3069 goto out_unlock_free_unmap
;
3070 if (cmd
->se_cmd
.prot_op
)
3071 res
= qlt_build_ctio_crc2_pkt(&prm
, vha
);
3073 res
= qlt_24xx_build_ctio_pkt(&prm
, vha
);
3075 if (unlikely(res
!= 0)) {
3076 vha
->req
->cnt
+= prm
.req_cnt
;
3077 goto out_unlock_free_unmap
;
3080 pkt
= (struct ctio7_to_24xx
*)prm
.pkt
;
3081 pkt
->u
.status0
.flags
|= cpu_to_le16(CTIO7_FLAGS_DATA_OUT
|
3082 CTIO7_FLAGS_STATUS_MODE_0
);
3084 if (cmd
->se_cmd
.prot_op
== TARGET_PROT_NORMAL
)
3085 qlt_load_data_segments(&prm
, vha
);
3087 cmd
->state
= QLA_TGT_STATE_NEED_DATA
;
3088 cmd
->cmd_sent_to_fw
= 1;
3090 /* Memory Barrier */
3092 qla2x00_start_iocbs(vha
, vha
->req
);
3093 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3097 out_unlock_free_unmap
:
3098 qlt_unmap_sg(vha
, cmd
);
3099 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3103 EXPORT_SYMBOL(qlt_rdy_to_xfer
);
3107 * Checks the guard or meta-data for the type of error
3108 * detected by the HBA.
3111 qlt_handle_dif_error(struct scsi_qla_host
*vha
, struct qla_tgt_cmd
*cmd
,
3112 struct ctio_crc_from_fw
*sts
)
3114 uint8_t *ap
= &sts
->actual_dif
[0];
3115 uint8_t *ep
= &sts
->expected_dif
[0];
3116 uint32_t e_ref_tag
, a_ref_tag
;
3117 uint16_t e_app_tag
, a_app_tag
;
3118 uint16_t e_guard
, a_guard
;
3119 uint64_t lba
= cmd
->se_cmd
.t_task_lba
;
3121 a_guard
= be16_to_cpu(*(uint16_t *)(ap
+ 0));
3122 a_app_tag
= be16_to_cpu(*(uint16_t *)(ap
+ 2));
3123 a_ref_tag
= be32_to_cpu(*(uint32_t *)(ap
+ 4));
3125 e_guard
= be16_to_cpu(*(uint16_t *)(ep
+ 0));
3126 e_app_tag
= be16_to_cpu(*(uint16_t *)(ep
+ 2));
3127 e_ref_tag
= be32_to_cpu(*(uint32_t *)(ep
+ 4));
3129 ql_dbg(ql_dbg_tgt
, vha
, 0xe075,
3130 "iocb(s) %p Returned STATUS.\n", sts
);
3132 ql_dbg(ql_dbg_tgt
, vha
, 0xf075,
3133 "dif check TGT cdb 0x%x lba 0x%llx: [Actual|Expected] Ref Tag[0x%x|0x%x], App Tag [0x%x|0x%x], Guard [0x%x|0x%x]\n",
3134 cmd
->atio
.u
.isp24
.fcp_cmnd
.cdb
[0], lba
,
3135 a_ref_tag
, e_ref_tag
, a_app_tag
, e_app_tag
, a_guard
, e_guard
);
3139 * For type 3: ref & app tag is all 'f's
3140 * For type 0,1,2: app tag is all 'f's
3142 if ((a_app_tag
== 0xffff) &&
3143 ((cmd
->se_cmd
.prot_type
!= TARGET_DIF_TYPE3_PROT
) ||
3144 (a_ref_tag
== 0xffffffff))) {
3145 uint32_t blocks_done
;
3147 /* 2TB boundary case covered automatically with this */
3148 blocks_done
= e_ref_tag
- (uint32_t)lba
+ 1;
3149 cmd
->se_cmd
.bad_sector
= e_ref_tag
;
3150 cmd
->se_cmd
.pi_err
= 0;
3151 ql_dbg(ql_dbg_tgt
, vha
, 0xf074,
3152 "need to return scsi good\n");
3154 /* Update protection tag */
3155 if (cmd
->prot_sg_cnt
) {
3156 uint32_t i
, k
= 0, num_ent
;
3157 struct scatterlist
*sg
, *sgl
;
3162 /* Patch the corresponding protection tags */
3163 for_each_sg(sgl
, sg
, cmd
->prot_sg_cnt
, i
) {
3164 num_ent
= sg_dma_len(sg
) / 8;
3165 if (k
+ num_ent
< blocks_done
) {
3173 if (k
!= blocks_done
) {
3174 ql_log(ql_log_warn
, vha
, 0xf076,
3175 "unexpected tag values tag:lba=%u:%llu)\n",
3176 e_ref_tag
, (unsigned long long)lba
);
3181 struct sd_dif_tuple
*spt
;
3183 * This section came from initiator. Is it valid here?
3184 * should ulp be override with actual val???
3186 spt
= page_address(sg_page(sg
)) + sg
->offset
;
3189 spt
->app_tag
= 0xffff;
3190 if (cmd
->se_cmd
.prot_type
== SCSI_PROT_DIF_TYPE3
)
3191 spt
->ref_tag
= 0xffffffff;
3199 if (e_guard
!= a_guard
) {
3200 cmd
->se_cmd
.pi_err
= TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED
;
3201 cmd
->se_cmd
.bad_sector
= cmd
->se_cmd
.t_task_lba
;
3203 ql_log(ql_log_warn
, vha
, 0xe076,
3204 "Guard ERR: cdb 0x%x lba 0x%llx: [Actual|Expected] Ref Tag[0x%x|0x%x], App Tag [0x%x|0x%x], Guard [0x%x|0x%x] cmd=%p\n",
3205 cmd
->atio
.u
.isp24
.fcp_cmnd
.cdb
[0], lba
,
3206 a_ref_tag
, e_ref_tag
, a_app_tag
, e_app_tag
,
3207 a_guard
, e_guard
, cmd
);
3212 if (e_ref_tag
!= a_ref_tag
) {
3213 cmd
->se_cmd
.pi_err
= TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED
;
3214 cmd
->se_cmd
.bad_sector
= e_ref_tag
;
3216 ql_log(ql_log_warn
, vha
, 0xe077,
3217 "Ref Tag ERR: cdb 0x%x lba 0x%llx: [Actual|Expected] Ref Tag[0x%x|0x%x], App Tag [0x%x|0x%x], Guard [0x%x|0x%x] cmd=%p\n",
3218 cmd
->atio
.u
.isp24
.fcp_cmnd
.cdb
[0], lba
,
3219 a_ref_tag
, e_ref_tag
, a_app_tag
, e_app_tag
,
3220 a_guard
, e_guard
, cmd
);
3224 /* check appl tag */
3225 if (e_app_tag
!= a_app_tag
) {
3226 cmd
->se_cmd
.pi_err
= TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED
;
3227 cmd
->se_cmd
.bad_sector
= cmd
->se_cmd
.t_task_lba
;
3229 ql_log(ql_log_warn
, vha
, 0xe078,
3230 "App Tag ERR: cdb 0x%x lba 0x%llx: [Actual|Expected] Ref Tag[0x%x|0x%x], App Tag [0x%x|0x%x], Guard [0x%x|0x%x] cmd=%p\n",
3231 cmd
->atio
.u
.isp24
.fcp_cmnd
.cdb
[0], lba
,
3232 a_ref_tag
, e_ref_tag
, a_app_tag
, e_app_tag
,
3233 a_guard
, e_guard
, cmd
);
3241 /* If hardware_lock held on entry, might drop it, then reaquire */
3242 /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */
3243 static int __qlt_send_term_imm_notif(struct scsi_qla_host
*vha
,
3244 struct imm_ntfy_from_isp
*ntfy
)
3246 struct nack_to_isp
*nack
;
3247 struct qla_hw_data
*ha
= vha
->hw
;
3251 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0xe01c,
3252 "Sending TERM ELS CTIO (ha=%p)\n", ha
);
3254 pkt
= (request_t
*)qla2x00_alloc_iocbs_ready(vha
, NULL
);
3256 ql_dbg(ql_dbg_tgt
, vha
, 0xe080,
3257 "qla_target(%d): %s failed: unable to allocate "
3258 "request packet\n", vha
->vp_idx
, __func__
);
3262 pkt
->entry_type
= NOTIFY_ACK_TYPE
;
3263 pkt
->entry_count
= 1;
3264 pkt
->handle
= QLA_TGT_SKIP_HANDLE
;
3266 nack
= (struct nack_to_isp
*)pkt
;
3267 nack
->ox_id
= ntfy
->ox_id
;
3269 nack
->u
.isp24
.nport_handle
= ntfy
->u
.isp24
.nport_handle
;
3270 if (le16_to_cpu(ntfy
->u
.isp24
.status
) == IMM_NTFY_ELS
) {
3271 nack
->u
.isp24
.flags
= ntfy
->u
.isp24
.flags
&
3272 __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB
);
3276 nack
->u
.isp24
.flags
|=
3277 __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE
);
3279 nack
->u
.isp24
.srr_rx_id
= ntfy
->u
.isp24
.srr_rx_id
;
3280 nack
->u
.isp24
.status
= ntfy
->u
.isp24
.status
;
3281 nack
->u
.isp24
.status_subcode
= ntfy
->u
.isp24
.status_subcode
;
3282 nack
->u
.isp24
.fw_handle
= ntfy
->u
.isp24
.fw_handle
;
3283 nack
->u
.isp24
.exchange_address
= ntfy
->u
.isp24
.exchange_address
;
3284 nack
->u
.isp24
.srr_rel_offs
= ntfy
->u
.isp24
.srr_rel_offs
;
3285 nack
->u
.isp24
.srr_ui
= ntfy
->u
.isp24
.srr_ui
;
3286 nack
->u
.isp24
.vp_index
= ntfy
->u
.isp24
.vp_index
;
3288 qla2x00_start_iocbs(vha
, vha
->req
);
3292 static void qlt_send_term_imm_notif(struct scsi_qla_host
*vha
,
3293 struct imm_ntfy_from_isp
*imm
, int ha_locked
)
3295 unsigned long flags
= 0;
3298 if (qlt_issue_marker(vha
, ha_locked
) < 0)
3302 rc
= __qlt_send_term_imm_notif(vha
, imm
);
3306 qlt_alloc_qfull_cmd(vha
, imm
, 0, 0);
3314 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
3315 rc
= __qlt_send_term_imm_notif(vha
, imm
);
3319 qlt_alloc_qfull_cmd(vha
, imm
, 0, 0);
3324 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
3327 /* If hardware_lock held on entry, might drop it, then reaquire */
3328 /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */
3329 static int __qlt_send_term_exchange(struct scsi_qla_host
*vha
,
3330 struct qla_tgt_cmd
*cmd
,
3331 struct atio_from_isp
*atio
)
3333 struct ctio7_to_24xx
*ctio24
;
3334 struct qla_hw_data
*ha
= vha
->hw
;
3339 ql_dbg(ql_dbg_tgt
, vha
, 0xe01c, "Sending TERM EXCH CTIO (ha=%p)\n", ha
);
3341 pkt
= (request_t
*)qla2x00_alloc_iocbs_ready(vha
, NULL
);
3343 ql_dbg(ql_dbg_tgt
, vha
, 0xe050,
3344 "qla_target(%d): %s failed: unable to allocate "
3345 "request packet\n", vha
->vp_idx
, __func__
);
3350 if (cmd
->state
< QLA_TGT_STATE_PROCESSED
) {
3351 ql_dbg(ql_dbg_tgt
, vha
, 0xe051,
3352 "qla_target(%d): Terminating cmd %p with "
3353 "incorrect state %d\n", vha
->vp_idx
, cmd
,
3359 vha
->tgt_counters
.num_term_xchg_sent
++;
3360 pkt
->entry_count
= 1;
3361 pkt
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
3363 ctio24
= (struct ctio7_to_24xx
*)pkt
;
3364 ctio24
->entry_type
= CTIO_TYPE7
;
3365 ctio24
->nport_handle
= CTIO7_NHANDLE_UNRECOGNIZED
;
3366 ctio24
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
3367 ctio24
->vp_index
= vha
->vp_idx
;
3368 ctio24
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
3369 ctio24
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
3370 ctio24
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
3371 ctio24
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
3372 ctio24
->u
.status1
.flags
= (atio
->u
.isp24
.attr
<< 9) |
3373 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
|
3374 CTIO7_FLAGS_TERMINATE
);
3375 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
3376 ctio24
->u
.status1
.ox_id
= cpu_to_le16(temp
);
3378 /* Most likely, it isn't needed */
3379 ctio24
->u
.status1
.residual
= get_unaligned((uint32_t *)
3380 &atio
->u
.isp24
.fcp_cmnd
.add_cdb
[
3381 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
]);
3382 if (ctio24
->u
.status1
.residual
!= 0)
3383 ctio24
->u
.status1
.scsi_status
|= SS_RESIDUAL_UNDER
;
3385 /* Memory Barrier */
3387 qla2x00_start_iocbs(vha
, vha
->req
);
3391 static void qlt_send_term_exchange(struct scsi_qla_host
*vha
,
3392 struct qla_tgt_cmd
*cmd
, struct atio_from_isp
*atio
, int ha_locked
,
3395 unsigned long flags
= 0;
3398 if (qlt_issue_marker(vha
, ha_locked
) < 0)
3402 rc
= __qlt_send_term_exchange(vha
, cmd
, atio
);
3404 qlt_alloc_qfull_cmd(vha
, atio
, 0, 0);
3407 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
3408 rc
= __qlt_send_term_exchange(vha
, cmd
, atio
);
3410 qlt_alloc_qfull_cmd(vha
, atio
, 0, 0);
3413 if (cmd
&& !ul_abort
&& !cmd
->aborted
) {
3415 qlt_unmap_sg(vha
, cmd
);
3416 vha
->hw
->tgt
.tgt_ops
->free_cmd(cmd
);
3420 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
3425 static void qlt_init_term_exchange(struct scsi_qla_host
*vha
)
3427 struct list_head free_list
;
3428 struct qla_tgt_cmd
*cmd
, *tcmd
;
3430 vha
->hw
->tgt
.leak_exchg_thresh_hold
=
3431 (vha
->hw
->cur_fw_xcb_count
/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT
;
3434 if (!list_empty(&vha
->hw
->tgt
.q_full_list
)) {
3435 INIT_LIST_HEAD(&free_list
);
3436 list_splice_init(&vha
->hw
->tgt
.q_full_list
, &free_list
);
3438 list_for_each_entry_safe(cmd
, tcmd
, &free_list
, cmd_list
) {
3439 list_del(&cmd
->cmd_list
);
3440 /* This cmd was never sent to TCM. There is no need
3441 * to schedule free or call free_cmd
3444 vha
->hw
->tgt
.num_qfull_cmds_alloc
--;
3447 vha
->hw
->tgt
.num_qfull_cmds_dropped
= 0;
3450 static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host
*vha
)
3452 uint32_t total_leaked
;
3454 total_leaked
= vha
->hw
->tgt
.num_qfull_cmds_dropped
;
3456 if (vha
->hw
->tgt
.leak_exchg_thresh_hold
&&
3457 (total_leaked
> vha
->hw
->tgt
.leak_exchg_thresh_hold
)) {
3459 ql_dbg(ql_dbg_tgt
, vha
, 0xe079,
3460 "Chip reset due to exchange starvation: %d/%d.\n",
3461 total_leaked
, vha
->hw
->cur_fw_xcb_count
);
3463 if (IS_P3P_TYPE(vha
->hw
))
3464 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
3466 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3467 qla2xxx_wake_dpc(vha
);
3472 int qlt_abort_cmd(struct qla_tgt_cmd
*cmd
)
3474 struct qla_tgt
*tgt
= cmd
->tgt
;
3475 struct scsi_qla_host
*vha
= tgt
->vha
;
3476 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
3477 unsigned long flags
;
3479 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf014,
3480 "qla_target(%d): terminating exchange for aborted cmd=%p "
3481 "(se_cmd=%p, tag=%llu)", vha
->vp_idx
, cmd
, &cmd
->se_cmd
,
3484 spin_lock_irqsave(&cmd
->cmd_lock
, flags
);
3486 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
3488 * It's normal to see 2 calls in this path:
3489 * 1) XFER Rdy completion + CMD_T_ABORT
3490 * 2) TCM TMR - drain_state_list
3492 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xffff,
3493 "multiple abort. %p transport_state %x, t_state %x,"
3494 " se_cmd_flags %x \n", cmd
, cmd
->se_cmd
.transport_state
,
3495 cmd
->se_cmd
.t_state
,cmd
->se_cmd
.se_cmd_flags
);
3499 cmd
->trc_flags
|= TRC_ABORT
;
3500 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
3502 qlt_send_term_exchange(vha
, cmd
, &cmd
->atio
, 0, 1);
3505 EXPORT_SYMBOL(qlt_abort_cmd
);
3507 void qlt_free_cmd(struct qla_tgt_cmd
*cmd
)
3509 struct fc_port
*sess
= cmd
->sess
;
3511 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe074,
3512 "%s: se_cmd[%p] ox_id %04x\n",
3513 __func__
, &cmd
->se_cmd
,
3514 be16_to_cpu(cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
));
3516 BUG_ON(cmd
->cmd_in_wq
);
3519 qlt_unmap_sg(cmd
->vha
, cmd
);
3522 qlt_decr_num_pend_cmds(cmd
->vha
);
3524 BUG_ON(cmd
->sg_mapped
);
3525 cmd
->jiffies_at_free
= get_jiffies_64();
3526 if (unlikely(cmd
->free_sg
))
3529 if (!sess
|| !sess
->se_sess
) {
3533 cmd
->jiffies_at_free
= get_jiffies_64();
3534 percpu_ida_free(&sess
->se_sess
->sess_tag_pool
, cmd
->se_cmd
.map_tag
);
3536 EXPORT_SYMBOL(qlt_free_cmd
);
3539 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3541 static int qlt_term_ctio_exchange(struct scsi_qla_host
*vha
, void *ctio
,
3542 struct qla_tgt_cmd
*cmd
, uint32_t status
)
3547 struct ctio7_from_24xx
*c
= (struct ctio7_from_24xx
*)ctio
;
3549 cpu_to_le16(OF_TERM_EXCH
));
3554 qlt_send_term_exchange(vha
, cmd
, &cmd
->atio
, 1, 0);
3559 /* ha->hardware_lock supposed to be held on entry */
3560 static inline struct qla_tgt_cmd
*qlt_get_cmd(struct scsi_qla_host
*vha
,
3563 struct qla_hw_data
*ha
= vha
->hw
;
3566 if (ha
->tgt
.cmds
[handle
] != NULL
) {
3567 struct qla_tgt_cmd
*cmd
= ha
->tgt
.cmds
[handle
];
3568 ha
->tgt
.cmds
[handle
] = NULL
;
3574 /* ha->hardware_lock supposed to be held on entry */
3575 static struct qla_tgt_cmd
*qlt_ctio_to_cmd(struct scsi_qla_host
*vha
,
3576 uint32_t handle
, void *ctio
)
3578 struct qla_tgt_cmd
*cmd
= NULL
;
3580 /* Clear out internal marks */
3581 handle
&= ~(CTIO_COMPLETION_HANDLE_MARK
|
3582 CTIO_INTERMEDIATE_HANDLE_MARK
);
3584 if (handle
!= QLA_TGT_NULL_HANDLE
) {
3585 if (unlikely(handle
== QLA_TGT_SKIP_HANDLE
))
3588 /* handle-1 is actually used */
3589 if (unlikely(handle
> DEFAULT_OUTSTANDING_COMMANDS
)) {
3590 ql_dbg(ql_dbg_tgt
, vha
, 0xe052,
3591 "qla_target(%d): Wrong handle %x received\n",
3592 vha
->vp_idx
, handle
);
3595 cmd
= qlt_get_cmd(vha
, handle
);
3596 if (unlikely(cmd
== NULL
)) {
3597 ql_dbg(ql_dbg_tgt
, vha
, 0xe053,
3598 "qla_target(%d): Suspicious: unable to "
3599 "find the command with handle %x\n", vha
->vp_idx
,
3603 } else if (ctio
!= NULL
) {
3604 /* We can't get loop ID from CTIO7 */
3605 ql_dbg(ql_dbg_tgt
, vha
, 0xe054,
3606 "qla_target(%d): Wrong CTIO received: QLA24xx doesn't "
3607 "support NULL handles\n", vha
->vp_idx
);
3614 /* hardware_lock should be held by caller. */
3616 qlt_abort_cmd_on_host_reset(struct scsi_qla_host
*vha
, struct qla_tgt_cmd
*cmd
)
3618 struct qla_hw_data
*ha
= vha
->hw
;
3622 qlt_unmap_sg(vha
, cmd
);
3624 handle
= qlt_make_handle(vha
);
3626 /* TODO: fix debug message type and ids. */
3627 if (cmd
->state
== QLA_TGT_STATE_PROCESSED
) {
3628 ql_dbg(ql_dbg_io
, vha
, 0xff00,
3629 "HOST-ABORT: handle=%d, state=PROCESSED.\n", handle
);
3630 } else if (cmd
->state
== QLA_TGT_STATE_NEED_DATA
) {
3631 cmd
->write_data_transferred
= 0;
3632 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
3634 ql_dbg(ql_dbg_io
, vha
, 0xff01,
3635 "HOST-ABORT: handle=%d, state=DATA_IN.\n", handle
);
3637 ha
->tgt
.tgt_ops
->handle_data(cmd
);
3640 ql_dbg(ql_dbg_io
, vha
, 0xff03,
3641 "HOST-ABORT: handle=%d, state=BAD(%d).\n", handle
,
3646 cmd
->trc_flags
|= TRC_FLUSH
;
3647 ha
->tgt
.tgt_ops
->free_cmd(cmd
);
3651 qlt_host_reset_handler(struct qla_hw_data
*ha
)
3653 struct qla_tgt_cmd
*cmd
;
3654 unsigned long flags
;
3655 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
3656 scsi_qla_host_t
*vha
= NULL
;
3657 struct qla_tgt
*tgt
= base_vha
->vha_tgt
.qla_tgt
;
3660 if (!base_vha
->hw
->tgt
.tgt_ops
)
3663 if (!tgt
|| qla_ini_mode_enabled(base_vha
)) {
3664 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf003,
3665 "Target mode disabled\n");
3669 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xff10,
3670 "HOST-ABORT-HNDLR: base_vha->dpc_flags=%lx.\n",
3671 base_vha
->dpc_flags
);
3673 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3674 for (i
= 1; i
< DEFAULT_OUTSTANDING_COMMANDS
+ 1; i
++) {
3675 cmd
= qlt_get_cmd(base_vha
, i
);
3678 /* ha->tgt.cmds entry is cleared by qlt_get_cmd. */
3680 qlt_abort_cmd_on_host_reset(vha
, cmd
);
3682 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3687 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3689 static void qlt_do_ctio_completion(struct scsi_qla_host
*vha
, uint32_t handle
,
3690 uint32_t status
, void *ctio
)
3692 struct qla_hw_data
*ha
= vha
->hw
;
3693 struct se_cmd
*se_cmd
;
3694 struct qla_tgt_cmd
*cmd
;
3696 if (handle
& CTIO_INTERMEDIATE_HANDLE_MARK
) {
3697 /* That could happen only in case of an error/reset/abort */
3698 if (status
!= CTIO_SUCCESS
) {
3699 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01d,
3700 "Intermediate CTIO received"
3701 " (status %x)\n", status
);
3706 cmd
= qlt_ctio_to_cmd(vha
, handle
, ctio
);
3710 se_cmd
= &cmd
->se_cmd
;
3711 cmd
->cmd_sent_to_fw
= 0;
3713 qlt_unmap_sg(vha
, cmd
);
3715 if (unlikely(status
!= CTIO_SUCCESS
)) {
3716 switch (status
& 0xFFFF) {
3717 case CTIO_LIP_RESET
:
3718 case CTIO_TARGET_RESET
:
3720 /* driver request abort via Terminate exchange */
3722 case CTIO_INVALID_RX_ID
:
3724 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf058,
3725 "qla_target(%d): CTIO with "
3726 "status %#x received, state %x, se_cmd %p, "
3727 "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, "
3728 "TIMEOUT=b, INVALID_RX_ID=8)\n", vha
->vp_idx
,
3729 status
, cmd
->state
, se_cmd
);
3732 case CTIO_PORT_LOGGED_OUT
:
3733 case CTIO_PORT_UNAVAILABLE
:
3736 (status
& 0xFFFF) == CTIO_PORT_LOGGED_OUT
;
3738 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf059,
3739 "qla_target(%d): CTIO with %s status %x "
3740 "received (state %x, se_cmd %p)\n", vha
->vp_idx
,
3741 logged_out
? "PORT LOGGED OUT" : "PORT UNAVAILABLE",
3742 status
, cmd
->state
, se_cmd
);
3744 if (logged_out
&& cmd
->sess
) {
3746 * Session is already logged out, but we need
3747 * to notify initiator, who's not aware of this
3749 cmd
->sess
->logout_on_delete
= 0;
3750 cmd
->sess
->send_els_logo
= 1;
3751 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
3752 "%s %d %8phC post del sess\n",
3753 __func__
, __LINE__
, cmd
->sess
->port_name
);
3755 qlt_schedule_sess_for_deletion_lock(cmd
->sess
);
3759 case CTIO_DIF_ERROR
: {
3760 struct ctio_crc_from_fw
*crc
=
3761 (struct ctio_crc_from_fw
*)ctio
;
3762 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf073,
3763 "qla_target(%d): CTIO with DIF_ERROR status %x received (state %x, se_cmd %p) actual_dif[0x%llx] expect_dif[0x%llx]\n",
3764 vha
->vp_idx
, status
, cmd
->state
, se_cmd
,
3765 *((u64
*)&crc
->actual_dif
[0]),
3766 *((u64
*)&crc
->expected_dif
[0]));
3768 if (qlt_handle_dif_error(vha
, cmd
, ctio
)) {
3769 if (cmd
->state
== QLA_TGT_STATE_NEED_DATA
) {
3770 /* scsi Write/xfer rdy complete */
3773 /* scsi read/xmit respond complete
3774 * call handle dif to send scsi status
3775 * rather than terminate exchange.
3777 cmd
->state
= QLA_TGT_STATE_PROCESSED
;
3778 ha
->tgt
.tgt_ops
->handle_dif_err(cmd
);
3782 /* Need to generate a SCSI good completion.
3783 * because FW did not send scsi status.
3791 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05b,
3792 "qla_target(%d): CTIO with error status 0x%x received (state %x, se_cmd %p\n",
3793 vha
->vp_idx
, status
, cmd
->state
, se_cmd
);
3798 /* "cmd->aborted" means
3799 * cmd is already aborted/terminated, we don't
3800 * need to terminate again. The exchange is already
3801 * cleaned up/freed at FW level. Just cleanup at driver
3804 if ((cmd
->state
!= QLA_TGT_STATE_NEED_DATA
) &&
3806 cmd
->trc_flags
|= TRC_CTIO_ERR
;
3807 if (qlt_term_ctio_exchange(vha
, ctio
, cmd
, status
))
3813 if (cmd
->state
== QLA_TGT_STATE_PROCESSED
) {
3814 cmd
->trc_flags
|= TRC_CTIO_DONE
;
3815 } else if (cmd
->state
== QLA_TGT_STATE_NEED_DATA
) {
3816 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
3818 if (status
== CTIO_SUCCESS
)
3819 cmd
->write_data_transferred
= 1;
3821 ha
->tgt
.tgt_ops
->handle_data(cmd
);
3823 } else if (cmd
->aborted
) {
3824 cmd
->trc_flags
|= TRC_CTIO_ABORTED
;
3825 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01e,
3826 "Aborted command %p (tag %lld) finished\n", cmd
, se_cmd
->tag
);
3828 cmd
->trc_flags
|= TRC_CTIO_STRANGE
;
3829 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05c,
3830 "qla_target(%d): A command in state (%d) should "
3831 "not return a CTIO complete\n", vha
->vp_idx
, cmd
->state
);
3834 if (unlikely(status
!= CTIO_SUCCESS
) &&
3836 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01f, "Finishing failed CTIO\n");
3840 ha
->tgt
.tgt_ops
->free_cmd(cmd
);
3843 static inline int qlt_get_fcp_task_attr(struct scsi_qla_host
*vha
,
3848 switch (task_codes
) {
3849 case ATIO_SIMPLE_QUEUE
:
3850 fcp_task_attr
= TCM_SIMPLE_TAG
;
3852 case ATIO_HEAD_OF_QUEUE
:
3853 fcp_task_attr
= TCM_HEAD_TAG
;
3855 case ATIO_ORDERED_QUEUE
:
3856 fcp_task_attr
= TCM_ORDERED_TAG
;
3858 case ATIO_ACA_QUEUE
:
3859 fcp_task_attr
= TCM_ACA_TAG
;
3862 fcp_task_attr
= TCM_SIMPLE_TAG
;
3865 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05d,
3866 "qla_target: unknown task code %x, use ORDERED instead\n",
3868 fcp_task_attr
= TCM_ORDERED_TAG
;
3872 return fcp_task_attr
;
3875 static struct fc_port
*qlt_make_local_sess(struct scsi_qla_host
*,
3878 * Process context for I/O path into tcm_qla2xxx code
3880 static void __qlt_do_work(struct qla_tgt_cmd
*cmd
)
3882 scsi_qla_host_t
*vha
= cmd
->vha
;
3883 struct qla_hw_data
*ha
= vha
->hw
;
3884 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
3885 struct fc_port
*sess
= cmd
->sess
;
3886 struct atio_from_isp
*atio
= &cmd
->atio
;
3888 unsigned long flags
;
3889 uint32_t data_length
;
3890 int ret
, fcp_task_attr
, data_dir
, bidi
= 0;
3893 cmd
->trc_flags
|= TRC_DO_WORK
;
3898 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf082,
3899 "cmd with tag %u is aborted\n",
3900 cmd
->atio
.u
.isp24
.exchange_addr
);
3904 spin_lock_init(&cmd
->cmd_lock
);
3905 cdb
= &atio
->u
.isp24
.fcp_cmnd
.cdb
[0];
3906 cmd
->se_cmd
.tag
= atio
->u
.isp24
.exchange_addr
;
3907 cmd
->unpacked_lun
= scsilun_to_int(
3908 (struct scsi_lun
*)&atio
->u
.isp24
.fcp_cmnd
.lun
);
3910 if (atio
->u
.isp24
.fcp_cmnd
.rddata
&&
3911 atio
->u
.isp24
.fcp_cmnd
.wrdata
) {
3913 data_dir
= DMA_TO_DEVICE
;
3914 } else if (atio
->u
.isp24
.fcp_cmnd
.rddata
)
3915 data_dir
= DMA_FROM_DEVICE
;
3916 else if (atio
->u
.isp24
.fcp_cmnd
.wrdata
)
3917 data_dir
= DMA_TO_DEVICE
;
3919 data_dir
= DMA_NONE
;
3921 fcp_task_attr
= qlt_get_fcp_task_attr(vha
,
3922 atio
->u
.isp24
.fcp_cmnd
.task_attr
);
3923 data_length
= be32_to_cpu(get_unaligned((uint32_t *)
3924 &atio
->u
.isp24
.fcp_cmnd
.add_cdb
[
3925 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
]));
3927 ret
= ha
->tgt
.tgt_ops
->handle_cmd(vha
, cmd
, cdb
, data_length
,
3928 fcp_task_attr
, data_dir
, bidi
);
3932 * Drop extra session reference from qla_tgt_handle_cmd_for_atio*(
3934 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
3935 ha
->tgt
.tgt_ops
->put_sess(sess
);
3936 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
3940 ql_dbg(ql_dbg_io
, vha
, 0x3060, "Terminating work cmd %p", cmd
);
3942 * cmd has not sent to target yet, so pass NULL as the second
3943 * argument to qlt_send_term_exchange() and free the memory here.
3945 cmd
->trc_flags
|= TRC_DO_WORK_ERR
;
3946 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3947 qlt_send_term_exchange(vha
, NULL
, &cmd
->atio
, 1, 0);
3949 qlt_decr_num_pend_cmds(vha
);
3950 percpu_ida_free(&sess
->se_sess
->sess_tag_pool
, cmd
->se_cmd
.map_tag
);
3951 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3953 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
3954 ha
->tgt
.tgt_ops
->put_sess(sess
);
3955 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
3958 static void qlt_do_work(struct work_struct
*work
)
3960 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
3961 scsi_qla_host_t
*vha
= cmd
->vha
;
3962 unsigned long flags
;
3964 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
3965 list_del(&cmd
->cmd_list
);
3966 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
3971 static struct qla_tgt_cmd
*qlt_get_tag(scsi_qla_host_t
*vha
,
3972 struct fc_port
*sess
,
3973 struct atio_from_isp
*atio
)
3975 struct se_session
*se_sess
= sess
->se_sess
;
3976 struct qla_tgt_cmd
*cmd
;
3979 tag
= percpu_ida_alloc(&se_sess
->sess_tag_pool
, TASK_RUNNING
);
3983 cmd
= &((struct qla_tgt_cmd
*)se_sess
->sess_cmd_map
)[tag
];
3984 memset(cmd
, 0, sizeof(struct qla_tgt_cmd
));
3986 memcpy(&cmd
->atio
, atio
, sizeof(*atio
));
3987 cmd
->state
= QLA_TGT_STATE_NEW
;
3988 cmd
->tgt
= vha
->vha_tgt
.qla_tgt
;
3989 qlt_incr_num_pend_cmds(vha
);
3991 cmd
->se_cmd
.map_tag
= tag
;
3993 cmd
->loop_id
= sess
->loop_id
;
3994 cmd
->conf_compl_supported
= sess
->conf_compl_supported
;
3997 cmd
->jiffies_at_alloc
= get_jiffies_64();
3999 cmd
->reset_count
= vha
->hw
->chip_reset
;
4004 static void qlt_send_busy(struct scsi_qla_host
*, struct atio_from_isp
*,
4007 static void qlt_create_sess_from_atio(struct work_struct
*work
)
4009 struct qla_tgt_sess_op
*op
= container_of(work
,
4010 struct qla_tgt_sess_op
, work
);
4011 scsi_qla_host_t
*vha
= op
->vha
;
4012 struct qla_hw_data
*ha
= vha
->hw
;
4013 struct fc_port
*sess
;
4014 struct qla_tgt_cmd
*cmd
;
4015 unsigned long flags
;
4016 uint8_t *s_id
= op
->atio
.u
.isp24
.fcp_hdr
.s_id
;
4018 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
4019 list_del(&op
->cmd_list
);
4020 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
4023 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf083,
4024 "sess_op with tag %u is aborted\n",
4025 op
->atio
.u
.isp24
.exchange_addr
);
4029 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf022,
4030 "qla_target(%d): Unable to find wwn login"
4031 " (s_id %x:%x:%x), trying to create it manually\n",
4032 vha
->vp_idx
, s_id
[0], s_id
[1], s_id
[2]);
4034 if (op
->atio
.u
.raw
.entry_count
> 1) {
4035 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf023,
4036 "Dropping multy entry atio %p\n", &op
->atio
);
4040 sess
= qlt_make_local_sess(vha
, s_id
);
4041 /* sess has an extra creation ref. */
4046 * Now obtain a pre-allocated session tag using the original op->atio
4047 * packet header, and dispatch into __qlt_do_work() using the existing
4050 cmd
= qlt_get_tag(vha
, sess
, &op
->atio
);
4052 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4053 qlt_send_busy(vha
, &op
->atio
, SAM_STAT_BUSY
);
4054 ha
->tgt
.tgt_ops
->put_sess(sess
);
4055 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4061 * __qlt_do_work() will call qlt_put_sess() to release
4062 * the extra reference taken above by qlt_make_local_sess()
4068 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4069 qlt_send_term_exchange(vha
, NULL
, &op
->atio
, 1, 0);
4070 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4074 /* ha->hardware_lock supposed to be held on entry */
4075 static int qlt_handle_cmd_for_atio(struct scsi_qla_host
*vha
,
4076 struct atio_from_isp
*atio
)
4078 struct qla_hw_data
*ha
= vha
->hw
;
4079 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4080 struct fc_port
*sess
;
4081 struct qla_tgt_cmd
*cmd
;
4082 unsigned long flags
;
4084 if (unlikely(tgt
->tgt_stop
)) {
4085 ql_dbg(ql_dbg_io
, vha
, 0x3061,
4086 "New command while device %p is shutting down\n", tgt
);
4090 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, atio
->u
.isp24
.fcp_hdr
.s_id
);
4091 if (unlikely(!sess
)) {
4092 struct qla_tgt_sess_op
*op
= kzalloc(sizeof(struct qla_tgt_sess_op
),
4097 memcpy(&op
->atio
, atio
, sizeof(*atio
));
4100 spin_lock(&vha
->cmd_list_lock
);
4101 list_add_tail(&op
->cmd_list
, &vha
->qla_sess_op_cmd_list
);
4102 spin_unlock(&vha
->cmd_list_lock
);
4104 INIT_WORK(&op
->work
, qlt_create_sess_from_atio
);
4105 queue_work(qla_tgt_wq
, &op
->work
);
4109 /* Another WWN used to have our s_id. Our PLOGI scheduled its
4110 * session deletion, but it's still in sess_del_work wq */
4111 if (sess
->deleted
) {
4112 ql_dbg(ql_dbg_io
, vha
, 0x3061,
4113 "New command while old session %p is being deleted\n",
4119 * Do kref_get() before returning + dropping qla_hw_data->hardware_lock.
4121 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
4122 ql_dbg(ql_dbg_tgt
, vha
, 0xffff,
4123 "%s: kref_get fail, %8phC oxid %x \n",
4124 __func__
, sess
->port_name
,
4125 be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
));
4129 cmd
= qlt_get_tag(vha
, sess
, atio
);
4131 ql_dbg(ql_dbg_io
, vha
, 0x3062,
4132 "qla_target(%d): Allocation of cmd failed\n", vha
->vp_idx
);
4133 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4134 ha
->tgt
.tgt_ops
->put_sess(sess
);
4135 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4140 cmd
->trc_flags
|= TRC_NEW_CMD
;
4141 cmd
->se_cmd
.cpuid
= ha
->msix_count
?
4142 ha
->tgt
.rspq_vector_cpuid
: WORK_CPU_UNBOUND
;
4144 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
4145 list_add_tail(&cmd
->cmd_list
, &vha
->qla_cmd_list
);
4146 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
4148 INIT_WORK(&cmd
->work
, qlt_do_work
);
4149 if (ha
->msix_count
) {
4150 if (cmd
->atio
.u
.isp24
.fcp_cmnd
.rddata
)
4151 queue_work_on(smp_processor_id(), qla_tgt_wq
,
4154 queue_work_on(cmd
->se_cmd
.cpuid
, qla_tgt_wq
,
4157 queue_work(qla_tgt_wq
, &cmd
->work
);
4163 /* ha->hardware_lock supposed to be held on entry */
4164 static int qlt_issue_task_mgmt(struct fc_port
*sess
, u64 lun
,
4165 int fn
, void *iocb
, int flags
)
4167 struct scsi_qla_host
*vha
= sess
->vha
;
4168 struct qla_hw_data
*ha
= vha
->hw
;
4169 struct qla_tgt_mgmt_cmd
*mcmd
;
4170 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
4173 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
4175 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10009,
4176 "qla_target(%d): Allocation of management "
4177 "command failed, some commands and their data could "
4178 "leak\n", vha
->vp_idx
);
4181 memset(mcmd
, 0, sizeof(*mcmd
));
4185 memcpy(&mcmd
->orig_iocb
.imm_ntfy
, iocb
,
4186 sizeof(mcmd
->orig_iocb
.imm_ntfy
));
4188 mcmd
->tmr_func
= fn
;
4189 mcmd
->flags
= flags
;
4190 mcmd
->reset_count
= vha
->hw
->chip_reset
;
4193 case QLA_TGT_LUN_RESET
:
4194 abort_cmds_for_lun(vha
, lun
, a
->u
.isp24
.fcp_hdr
.s_id
);
4198 res
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, lun
, mcmd
->tmr_func
, 0);
4200 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x1000b,
4201 "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n",
4202 sess
->vha
->vp_idx
, res
);
4203 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
4210 /* ha->hardware_lock supposed to be held on entry */
4211 static int qlt_handle_task_mgmt(struct scsi_qla_host
*vha
, void *iocb
)
4213 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
4214 struct qla_hw_data
*ha
= vha
->hw
;
4215 struct qla_tgt
*tgt
;
4216 struct fc_port
*sess
;
4217 uint32_t lun
, unpacked_lun
;
4219 unsigned long flags
;
4221 tgt
= vha
->vha_tgt
.qla_tgt
;
4223 lun
= a
->u
.isp24
.fcp_cmnd
.lun
;
4224 fn
= a
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
;
4226 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4227 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
4228 a
->u
.isp24
.fcp_hdr
.s_id
);
4229 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4231 unpacked_lun
= scsilun_to_int((struct scsi_lun
*)&lun
);
4234 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf024,
4235 "qla_target(%d): task mgmt fn 0x%x for "
4236 "non-existant session\n", vha
->vp_idx
, fn
);
4237 return qlt_sched_sess_work(tgt
, QLA_TGT_SESS_WORK_TM
, iocb
,
4238 sizeof(struct atio_from_isp
));
4244 return qlt_issue_task_mgmt(sess
, unpacked_lun
, fn
, iocb
, 0);
4247 /* ha->hardware_lock supposed to be held on entry */
4248 static int __qlt_abort_task(struct scsi_qla_host
*vha
,
4249 struct imm_ntfy_from_isp
*iocb
, struct fc_port
*sess
)
4251 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
4252 struct qla_hw_data
*ha
= vha
->hw
;
4253 struct qla_tgt_mgmt_cmd
*mcmd
;
4254 uint32_t lun
, unpacked_lun
;
4257 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
4259 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05f,
4260 "qla_target(%d): %s: Allocation of ABORT cmd failed\n",
4261 vha
->vp_idx
, __func__
);
4264 memset(mcmd
, 0, sizeof(*mcmd
));
4267 memcpy(&mcmd
->orig_iocb
.imm_ntfy
, iocb
,
4268 sizeof(mcmd
->orig_iocb
.imm_ntfy
));
4270 lun
= a
->u
.isp24
.fcp_cmnd
.lun
;
4271 unpacked_lun
= scsilun_to_int((struct scsi_lun
*)&lun
);
4272 mcmd
->reset_count
= vha
->hw
->chip_reset
;
4273 mcmd
->tmr_func
= QLA_TGT_2G_ABORT_TASK
;
4275 rc
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, unpacked_lun
, mcmd
->tmr_func
,
4276 le16_to_cpu(iocb
->u
.isp2x
.seq_id
));
4278 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf060,
4279 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
4281 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
4288 /* ha->hardware_lock supposed to be held on entry */
4289 static int qlt_abort_task(struct scsi_qla_host
*vha
,
4290 struct imm_ntfy_from_isp
*iocb
)
4292 struct qla_hw_data
*ha
= vha
->hw
;
4293 struct fc_port
*sess
;
4295 unsigned long flags
;
4297 loop_id
= GET_TARGET_ID(ha
, (struct atio_from_isp
*)iocb
);
4299 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4300 sess
= ha
->tgt
.tgt_ops
->find_sess_by_loop_id(vha
, loop_id
);
4301 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4304 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf025,
4305 "qla_target(%d): task abort for unexisting "
4306 "session\n", vha
->vp_idx
);
4307 return qlt_sched_sess_work(vha
->vha_tgt
.qla_tgt
,
4308 QLA_TGT_SESS_WORK_ABORT
, iocb
, sizeof(*iocb
));
4311 return __qlt_abort_task(vha
, iocb
, sess
);
4314 void qlt_logo_completion_handler(fc_port_t
*fcport
, int rc
)
4316 if (rc
!= MBS_COMMAND_COMPLETE
) {
4317 ql_dbg(ql_dbg_tgt_mgt
, fcport
->vha
, 0xf093,
4318 "%s: se_sess %p / sess %p from"
4319 " port %8phC loop_id %#04x s_id %02x:%02x:%02x"
4320 " LOGO failed: %#x\n",
4324 fcport
->port_name
, fcport
->loop_id
,
4325 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
4326 fcport
->d_id
.b
.al_pa
, rc
);
4329 fcport
->logout_completed
= 1;
4333 * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list)
4335 * Schedules sessions with matching port_id/loop_id but different wwn for
4336 * deletion. Returns existing session with matching wwn if present.
4340 qlt_find_sess_invalidate_other(scsi_qla_host_t
*vha
, uint64_t wwn
,
4341 port_id_t port_id
, uint16_t loop_id
, struct fc_port
**conflict_sess
)
4343 struct fc_port
*sess
= NULL
, *other_sess
;
4346 *conflict_sess
= NULL
;
4348 list_for_each_entry(other_sess
, &vha
->vp_fcports
, list
) {
4350 other_wwn
= wwn_to_u64(other_sess
->port_name
);
4352 if (wwn
== other_wwn
) {
4358 /* find other sess with nport_id collision */
4359 if (port_id
.b24
== other_sess
->d_id
.b24
) {
4360 if (loop_id
!= other_sess
->loop_id
) {
4361 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x1000c,
4362 "Invalidating sess %p loop_id %d wwn %llx.\n",
4363 other_sess
, other_sess
->loop_id
, other_wwn
);
4366 * logout_on_delete is set by default, but another
4367 * session that has the same s_id/loop_id combo
4368 * might have cleared it when requested this session
4369 * deletion, so don't touch it
4371 qlt_schedule_sess_for_deletion(other_sess
, true);
4374 * Another wwn used to have our s_id/loop_id
4375 * kill the session, but don't free the loop_id
4377 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0xffff,
4378 "Invalidating sess %p loop_id %d wwn %llx.\n",
4379 other_sess
, other_sess
->loop_id
, other_wwn
);
4382 other_sess
->keep_nport_handle
= 1;
4383 *conflict_sess
= other_sess
;
4384 qlt_schedule_sess_for_deletion(other_sess
,
4390 /* find other sess with nport handle collision */
4391 if ((loop_id
== other_sess
->loop_id
) &&
4392 (loop_id
!= FC_NO_LOOP_ID
)) {
4393 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x1000d,
4394 "Invalidating sess %p loop_id %d wwn %llx.\n",
4395 other_sess
, other_sess
->loop_id
, other_wwn
);
4397 /* Same loop_id but different s_id
4398 * Ok to kill and logout */
4399 qlt_schedule_sess_for_deletion(other_sess
, true);
4406 /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */
4407 static int abort_cmds_for_s_id(struct scsi_qla_host
*vha
, port_id_t
*s_id
)
4409 struct qla_tgt_sess_op
*op
;
4410 struct qla_tgt_cmd
*cmd
;
4414 key
= (((u32
)s_id
->b
.domain
<< 16) |
4415 ((u32
)s_id
->b
.area
<< 8) |
4416 ((u32
)s_id
->b
.al_pa
));
4418 spin_lock(&vha
->cmd_list_lock
);
4419 list_for_each_entry(op
, &vha
->qla_sess_op_cmd_list
, cmd_list
) {
4420 uint32_t op_key
= sid_to_key(op
->atio
.u
.isp24
.fcp_hdr
.s_id
);
4422 if (op_key
== key
) {
4428 list_for_each_entry(op
, &vha
->unknown_atio_list
, cmd_list
) {
4429 uint32_t op_key
= sid_to_key(op
->atio
.u
.isp24
.fcp_hdr
.s_id
);
4430 if (op_key
== key
) {
4436 list_for_each_entry(cmd
, &vha
->qla_cmd_list
, cmd_list
) {
4437 uint32_t cmd_key
= sid_to_key(cmd
->atio
.u
.isp24
.fcp_hdr
.s_id
);
4438 if (cmd_key
== key
) {
4443 spin_unlock(&vha
->cmd_list_lock
);
4449 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
4451 static int qlt_24xx_handle_els(struct scsi_qla_host
*vha
,
4452 struct imm_ntfy_from_isp
*iocb
)
4454 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4455 struct qla_hw_data
*ha
= vha
->hw
;
4456 struct fc_port
*sess
= NULL
, *conflict_sess
= NULL
;
4462 struct qlt_plogi_ack_t
*pla
;
4463 unsigned long flags
;
4465 wwn
= wwn_to_u64(iocb
->u
.isp24
.port_name
);
4467 port_id
.b
.domain
= iocb
->u
.isp24
.port_id
[2];
4468 port_id
.b
.area
= iocb
->u
.isp24
.port_id
[1];
4469 port_id
.b
.al_pa
= iocb
->u
.isp24
.port_id
[0];
4470 port_id
.b
.rsvd_1
= 0;
4472 loop_id
= le16_to_cpu(iocb
->u
.isp24
.nport_handle
);
4474 ql_dbg(ql_dbg_disc
, vha
, 0xf026,
4475 "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n",
4476 vha
->vp_idx
, iocb
->u
.isp24
.port_id
[2],
4477 iocb
->u
.isp24
.port_id
[1], iocb
->u
.isp24
.port_id
[0],
4478 iocb
->u
.isp24
.status_subcode
, loop_id
,
4479 iocb
->u
.isp24
.port_name
);
4481 /* res = 1 means ack at the end of thread
4482 * res = 0 means ack async/later.
4484 switch (iocb
->u
.isp24
.status_subcode
) {
4487 /* Mark all stale commands in qla_tgt_wq for deletion */
4488 abort_cmds_for_s_id(vha
, &port_id
);
4491 spin_lock_irqsave(&tgt
->ha
->tgt
.sess_lock
, flags
);
4492 sess
= qlt_find_sess_invalidate_other(vha
, wwn
,
4493 port_id
, loop_id
, &conflict_sess
);
4494 spin_unlock_irqrestore(&tgt
->ha
->tgt
.sess_lock
, flags
);
4497 if (IS_SW_RESV_ADDR(port_id
)) {
4502 pla
= qlt_plogi_ack_find_add(vha
, &port_id
, iocb
);
4504 qlt_send_term_imm_notif(vha
, iocb
, 1);
4510 if (conflict_sess
) {
4511 conflict_sess
->login_gen
++;
4512 qlt_plogi_ack_link(vha
, pla
, conflict_sess
,
4513 QLT_PLOGI_LINK_CONFLICT
);
4518 qla24xx_post_newsess_work(vha
, &port_id
,
4519 iocb
->u
.isp24
.port_name
, pla
);
4524 qlt_plogi_ack_link(vha
, pla
, sess
, QLT_PLOGI_LINK_SAME_WWN
);
4525 sess
->fw_login_state
= DSC_LS_PLOGI_PEND
;
4526 sess
->d_id
= port_id
;
4529 switch (sess
->disc_state
) {
4531 qlt_plogi_ack_unref(vha
, pla
);
4536 * Under normal circumstances we want to release nport handle
4537 * during LOGO process to avoid nport handle leaks inside FW.
4538 * The exception is when LOGO is done while another PLOGI with
4539 * the same nport handle is waiting as might be the case here.
4540 * Note: there is always a possibily of a race where session
4541 * deletion has already started for other reasons (e.g. ACL
4542 * removal) and now PLOGI arrives:
4543 * 1. if PLOGI arrived in FW after nport handle has been freed,
4544 * FW must have assigned this PLOGI a new/same handle and we
4545 * can proceed ACK'ing it as usual when session deletion
4547 * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT
4548 * bit reached it, the handle has now been released. We'll
4549 * get an error when we ACK this PLOGI. Nothing will be sent
4550 * back to initiator. Initiator should eventually retry
4551 * PLOGI and situation will correct itself.
4553 sess
->keep_nport_handle
= ((sess
->loop_id
== loop_id
) &&
4554 (sess
->d_id
.b24
== port_id
.b24
));
4556 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4557 "%s %d %8phC post del sess\n",
4558 __func__
, __LINE__
, sess
->port_name
);
4561 qlt_schedule_sess_for_deletion_lock(sess
);
4568 wd3_lo
= le16_to_cpu(iocb
->u
.isp24
.u
.prli
.wd3_lo
);
4571 spin_lock_irqsave(&tgt
->ha
->tgt
.sess_lock
, flags
);
4572 sess
= qlt_find_sess_invalidate_other(vha
, wwn
, port_id
,
4573 loop_id
, &conflict_sess
);
4574 spin_unlock_irqrestore(&tgt
->ha
->tgt
.sess_lock
, flags
);
4577 if (conflict_sess
) {
4578 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf09b,
4579 "PRLI with conflicting sess %p port %8phC\n",
4580 conflict_sess
, conflict_sess
->port_name
);
4581 qlt_send_term_imm_notif(vha
, iocb
, 1);
4587 if (sess
->fw_login_state
== DSC_LS_PLOGI_PEND
) {
4589 * Impatient initiator sent PRLI before last
4590 * PLOGI could finish. Will force him to re-try,
4591 * while last one finishes.
4593 ql_log(ql_log_warn
, sess
->vha
, 0xf095,
4594 "sess %p PRLI received, before plogi ack.\n",
4596 qlt_send_term_imm_notif(vha
, iocb
, 1);
4602 * This shouldn't happen under normal circumstances,
4603 * since we have deleted the old session during PLOGI
4605 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf096,
4606 "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n",
4607 sess
->loop_id
, sess
, iocb
->u
.isp24
.nport_handle
);
4610 sess
->loop_id
= loop_id
;
4611 sess
->d_id
= port_id
;
4612 sess
->fw_login_state
= DSC_LS_PRLI_PEND
;
4615 sess
->conf_compl_supported
= 1;
4617 if ((wd3_lo
& BIT_4
) == 0)
4618 sess
->port_type
= FCT_INITIATOR
;
4620 sess
->port_type
= FCT_TARGET
;
4622 res
= 1; /* send notify ack */
4624 /* Make session global (not used in fabric mode) */
4625 if (ha
->current_topology
!= ISP_CFG_F
) {
4626 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4627 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4628 qla2xxx_wake_dpc(vha
);
4631 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4632 "%s %d %8phC post nack\n",
4633 __func__
, __LINE__
, sess
->port_name
);
4635 qla24xx_post_nack_work(vha
, sess
, iocb
,
4644 if (le16_to_cpu(iocb
->u
.isp24
.flags
) &
4645 NOTIFY24XX_FLAGS_GLOBAL_TPRLO
) {
4647 qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
);
4654 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4655 sess
= qla2x00_find_fcport_by_loopid(vha
, loop_id
);
4656 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4660 sess
->fw_login_state
= DSC_LS_LOGO_PEND
;
4661 sess
->logo_ack_needed
= 1;
4662 memcpy(sess
->iocb
, iocb
, IOCB_SIZE
);
4665 res
= qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
);
4667 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4668 "%s: logo %llx res %d sess %p ",
4669 __func__
, wwn
, res
, sess
);
4672 * cmd went upper layer, look for qlt_xmit_tm_rsp()
4673 * for LOGO_ACK & sess delete
4678 /* cmd did not go to upper layer. */
4680 qlt_schedule_sess_for_deletion_lock(sess
);
4683 /* else logo will be ack */
4689 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4690 if (tgt
->link_reinit_iocb_pending
) {
4691 qlt_send_notify_ack(vha
, &tgt
->link_reinit_iocb
,
4693 tgt
->link_reinit_iocb_pending
= 0;
4696 sess
= qla2x00_find_fcport_by_wwpn(vha
,
4697 iocb
->u
.isp24
.port_name
, 1);
4699 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4700 "sess %p lid %d|%d DS %d LS %d\n",
4701 sess
, sess
->loop_id
, loop_id
,
4702 sess
->disc_state
, sess
->fw_login_state
);
4705 res
= 1; /* send notify ack */
4709 case ELS_FLOGI
: /* should never happen */
4711 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf061,
4712 "qla_target(%d): Unsupported ELS command %x "
4713 "received\n", vha
->vp_idx
, iocb
->u
.isp24
.status_subcode
);
4714 res
= qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
);
4722 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
4724 static void qlt_handle_imm_notify(struct scsi_qla_host
*vha
,
4725 struct imm_ntfy_from_isp
*iocb
)
4727 struct qla_hw_data
*ha
= vha
->hw
;
4728 uint32_t add_flags
= 0;
4729 int send_notify_ack
= 1;
4732 status
= le16_to_cpu(iocb
->u
.isp2x
.status
);
4734 case IMM_NTFY_LIP_RESET
:
4736 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf032,
4737 "qla_target(%d): LIP reset (loop %#x), subcode %x\n",
4738 vha
->vp_idx
, le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
4739 iocb
->u
.isp24
.status_subcode
);
4741 if (qlt_reset(vha
, iocb
, QLA_TGT_ABORT_ALL
) == 0)
4742 send_notify_ack
= 0;
4746 case IMM_NTFY_LIP_LINK_REINIT
:
4748 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4749 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf033,
4750 "qla_target(%d): LINK REINIT (loop %#x, "
4751 "subcode %x)\n", vha
->vp_idx
,
4752 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
4753 iocb
->u
.isp24
.status_subcode
);
4754 if (tgt
->link_reinit_iocb_pending
) {
4755 qlt_send_notify_ack(vha
, &tgt
->link_reinit_iocb
,
4758 memcpy(&tgt
->link_reinit_iocb
, iocb
, sizeof(*iocb
));
4759 tgt
->link_reinit_iocb_pending
= 1;
4761 * QLogic requires to wait after LINK REINIT for possible
4762 * PDISC or ADISC ELS commands
4764 send_notify_ack
= 0;
4768 case IMM_NTFY_PORT_LOGOUT
:
4769 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf034,
4770 "qla_target(%d): Port logout (loop "
4771 "%#x, subcode %x)\n", vha
->vp_idx
,
4772 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
4773 iocb
->u
.isp24
.status_subcode
);
4775 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
) == 0)
4776 send_notify_ack
= 0;
4777 /* The sessions will be cleared in the callback, if needed */
4780 case IMM_NTFY_GLBL_TPRLO
:
4781 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf035,
4782 "qla_target(%d): Global TPRLO (%x)\n", vha
->vp_idx
, status
);
4783 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
) == 0)
4784 send_notify_ack
= 0;
4785 /* The sessions will be cleared in the callback, if needed */
4788 case IMM_NTFY_PORT_CONFIG
:
4789 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf036,
4790 "qla_target(%d): Port config changed (%x)\n", vha
->vp_idx
,
4792 if (qlt_reset(vha
, iocb
, QLA_TGT_ABORT_ALL
) == 0)
4793 send_notify_ack
= 0;
4794 /* The sessions will be cleared in the callback, if needed */
4797 case IMM_NTFY_GLBL_LOGO
:
4798 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06a,
4799 "qla_target(%d): Link failure detected\n",
4801 /* I_T nexus loss */
4802 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
) == 0)
4803 send_notify_ack
= 0;
4806 case IMM_NTFY_IOCB_OVERFLOW
:
4807 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06b,
4808 "qla_target(%d): Cannot provide requested "
4809 "capability (IOCB overflowed the immediate notify "
4810 "resource count)\n", vha
->vp_idx
);
4813 case IMM_NTFY_ABORT_TASK
:
4814 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf037,
4815 "qla_target(%d): Abort Task (S %08x I %#x -> "
4816 "L %#x)\n", vha
->vp_idx
,
4817 le16_to_cpu(iocb
->u
.isp2x
.seq_id
),
4818 GET_TARGET_ID(ha
, (struct atio_from_isp
*)iocb
),
4819 le16_to_cpu(iocb
->u
.isp2x
.lun
));
4820 if (qlt_abort_task(vha
, iocb
) == 0)
4821 send_notify_ack
= 0;
4824 case IMM_NTFY_RESOURCE
:
4825 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06c,
4826 "qla_target(%d): Out of resources, host %ld\n",
4827 vha
->vp_idx
, vha
->host_no
);
4830 case IMM_NTFY_MSG_RX
:
4831 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf038,
4832 "qla_target(%d): Immediate notify task %x\n",
4833 vha
->vp_idx
, iocb
->u
.isp2x
.task_flags
);
4834 if (qlt_handle_task_mgmt(vha
, iocb
) == 0)
4835 send_notify_ack
= 0;
4839 if (qlt_24xx_handle_els(vha
, iocb
) == 0)
4840 send_notify_ack
= 0;
4843 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06d,
4844 "qla_target(%d): Received unknown immediate "
4845 "notify status %x\n", vha
->vp_idx
, status
);
4849 if (send_notify_ack
)
4850 qlt_send_notify_ack(vha
, iocb
, add_flags
, 0, 0, 0, 0, 0);
4854 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
4855 * This function sends busy to ISP 2xxx or 24xx.
4857 static int __qlt_send_busy(struct scsi_qla_host
*vha
,
4858 struct atio_from_isp
*atio
, uint16_t status
)
4860 struct ctio7_to_24xx
*ctio24
;
4861 struct qla_hw_data
*ha
= vha
->hw
;
4863 struct fc_port
*sess
= NULL
;
4864 unsigned long flags
;
4866 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4867 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
4868 atio
->u
.isp24
.fcp_hdr
.s_id
);
4869 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4871 qlt_send_term_exchange(vha
, NULL
, atio
, 1, 0);
4874 /* Sending marker isn't necessary, since we called from ISR */
4876 pkt
= (request_t
*)qla2x00_alloc_iocbs(vha
, NULL
);
4878 ql_dbg(ql_dbg_io
, vha
, 0x3063,
4879 "qla_target(%d): %s failed: unable to allocate "
4880 "request packet", vha
->vp_idx
, __func__
);
4884 vha
->tgt_counters
.num_q_full_sent
++;
4885 pkt
->entry_count
= 1;
4886 pkt
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
4888 ctio24
= (struct ctio7_to_24xx
*)pkt
;
4889 ctio24
->entry_type
= CTIO_TYPE7
;
4890 ctio24
->nport_handle
= sess
->loop_id
;
4891 ctio24
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
4892 ctio24
->vp_index
= vha
->vp_idx
;
4893 ctio24
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
4894 ctio24
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
4895 ctio24
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
4896 ctio24
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
4897 ctio24
->u
.status1
.flags
= (atio
->u
.isp24
.attr
<< 9) |
4899 CTIO7_FLAGS_STATUS_MODE_1
| CTIO7_FLAGS_SEND_STATUS
|
4900 CTIO7_FLAGS_DONT_RET_CTIO
);
4902 * CTIO from fw w/o se_cmd doesn't provide enough info to retry it,
4903 * if the explicit conformation is used.
4905 ctio24
->u
.status1
.ox_id
= swab16(atio
->u
.isp24
.fcp_hdr
.ox_id
);
4906 ctio24
->u
.status1
.scsi_status
= cpu_to_le16(status
);
4907 /* Memory Barrier */
4909 qla2x00_start_iocbs(vha
, vha
->req
);
4914 * This routine is used to allocate a command for either a QFull condition
4915 * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go
4919 qlt_alloc_qfull_cmd(struct scsi_qla_host
*vha
,
4920 struct atio_from_isp
*atio
, uint16_t status
, int qfull
)
4922 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4923 struct qla_hw_data
*ha
= vha
->hw
;
4924 struct fc_port
*sess
;
4925 struct se_session
*se_sess
;
4926 struct qla_tgt_cmd
*cmd
;
4929 if (unlikely(tgt
->tgt_stop
)) {
4930 ql_dbg(ql_dbg_io
, vha
, 0x300a,
4931 "New command while device %p is shutting down\n", tgt
);
4935 if ((vha
->hw
->tgt
.num_qfull_cmds_alloc
+ 1) > MAX_QFULL_CMDS_ALLOC
) {
4936 vha
->hw
->tgt
.num_qfull_cmds_dropped
++;
4937 if (vha
->hw
->tgt
.num_qfull_cmds_dropped
>
4938 vha
->qla_stats
.stat_max_qfull_cmds_dropped
)
4939 vha
->qla_stats
.stat_max_qfull_cmds_dropped
=
4940 vha
->hw
->tgt
.num_qfull_cmds_dropped
;
4942 ql_dbg(ql_dbg_io
, vha
, 0x3068,
4943 "qla_target(%d): %s: QFull CMD dropped[%d]\n",
4944 vha
->vp_idx
, __func__
,
4945 vha
->hw
->tgt
.num_qfull_cmds_dropped
);
4947 qlt_chk_exch_leak_thresh_hold(vha
);
4951 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id
4952 (vha
, atio
->u
.isp24
.fcp_hdr
.s_id
);
4956 se_sess
= sess
->se_sess
;
4958 tag
= percpu_ida_alloc(&se_sess
->sess_tag_pool
, TASK_RUNNING
);
4962 cmd
= &((struct qla_tgt_cmd
*)se_sess
->sess_cmd_map
)[tag
];
4964 ql_dbg(ql_dbg_io
, vha
, 0x3009,
4965 "qla_target(%d): %s: Allocation of cmd failed\n",
4966 vha
->vp_idx
, __func__
);
4968 vha
->hw
->tgt
.num_qfull_cmds_dropped
++;
4969 if (vha
->hw
->tgt
.num_qfull_cmds_dropped
>
4970 vha
->qla_stats
.stat_max_qfull_cmds_dropped
)
4971 vha
->qla_stats
.stat_max_qfull_cmds_dropped
=
4972 vha
->hw
->tgt
.num_qfull_cmds_dropped
;
4974 qlt_chk_exch_leak_thresh_hold(vha
);
4978 memset(cmd
, 0, sizeof(struct qla_tgt_cmd
));
4980 qlt_incr_num_pend_cmds(vha
);
4981 INIT_LIST_HEAD(&cmd
->cmd_list
);
4982 memcpy(&cmd
->atio
, atio
, sizeof(*atio
));
4984 cmd
->tgt
= vha
->vha_tgt
.qla_tgt
;
4986 cmd
->reset_count
= vha
->hw
->chip_reset
;
4991 /* NOTE: borrowing the state field to carry the status */
4992 cmd
->state
= status
;
4994 cmd
->term_exchg
= 1;
4996 list_add_tail(&cmd
->cmd_list
, &vha
->hw
->tgt
.q_full_list
);
4998 vha
->hw
->tgt
.num_qfull_cmds_alloc
++;
4999 if (vha
->hw
->tgt
.num_qfull_cmds_alloc
>
5000 vha
->qla_stats
.stat_max_qfull_cmds_alloc
)
5001 vha
->qla_stats
.stat_max_qfull_cmds_alloc
=
5002 vha
->hw
->tgt
.num_qfull_cmds_alloc
;
5006 qlt_free_qfull_cmds(struct scsi_qla_host
*vha
)
5008 struct qla_hw_data
*ha
= vha
->hw
;
5009 unsigned long flags
;
5010 struct qla_tgt_cmd
*cmd
, *tcmd
;
5011 struct list_head free_list
;
5014 if (list_empty(&ha
->tgt
.q_full_list
))
5017 INIT_LIST_HEAD(&free_list
);
5019 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
5021 if (list_empty(&ha
->tgt
.q_full_list
)) {
5022 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
5026 list_for_each_entry_safe(cmd
, tcmd
, &ha
->tgt
.q_full_list
, cmd_list
) {
5028 /* cmd->state is a borrowed field to hold status */
5029 rc
= __qlt_send_busy(vha
, &cmd
->atio
, cmd
->state
);
5030 else if (cmd
->term_exchg
)
5031 rc
= __qlt_send_term_exchange(vha
, NULL
, &cmd
->atio
);
5037 ql_dbg(ql_dbg_io
, vha
, 0x3006,
5038 "%s: busy sent for ox_id[%04x]\n", __func__
,
5039 be16_to_cpu(cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
));
5040 else if (cmd
->term_exchg
)
5041 ql_dbg(ql_dbg_io
, vha
, 0x3007,
5042 "%s: Term exchg sent for ox_id[%04x]\n", __func__
,
5043 be16_to_cpu(cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
));
5045 ql_dbg(ql_dbg_io
, vha
, 0x3008,
5046 "%s: Unexpected cmd in QFull list %p\n", __func__
,
5049 list_del(&cmd
->cmd_list
);
5050 list_add_tail(&cmd
->cmd_list
, &free_list
);
5052 /* piggy back on hardware_lock for protection */
5053 vha
->hw
->tgt
.num_qfull_cmds_alloc
--;
5055 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
5059 list_for_each_entry_safe(cmd
, tcmd
, &free_list
, cmd_list
) {
5060 list_del(&cmd
->cmd_list
);
5061 /* This cmd was never sent to TCM. There is no need
5062 * to schedule free or call free_cmd
5070 qlt_send_busy(struct scsi_qla_host
*vha
,
5071 struct atio_from_isp
*atio
, uint16_t status
)
5075 rc
= __qlt_send_busy(vha
, atio
, status
);
5077 qlt_alloc_qfull_cmd(vha
, atio
, status
, 1);
5081 qlt_chk_qfull_thresh_hold(struct scsi_qla_host
*vha
,
5082 struct atio_from_isp
*atio
)
5084 struct qla_hw_data
*ha
= vha
->hw
;
5087 if (ha
->tgt
.num_pend_cmds
< Q_FULL_THRESH_HOLD(ha
))
5090 status
= temp_sam_status
;
5091 qlt_send_busy(vha
, atio
, status
);
5095 /* ha->hardware_lock supposed to be held on entry */
5096 /* called via callback from qla2xxx */
5097 static void qlt_24xx_atio_pkt(struct scsi_qla_host
*vha
,
5098 struct atio_from_isp
*atio
, uint8_t ha_locked
)
5100 struct qla_hw_data
*ha
= vha
->hw
;
5101 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5103 unsigned long flags
;
5105 if (unlikely(tgt
== NULL
)) {
5106 ql_dbg(ql_dbg_io
, vha
, 0x3064,
5107 "ATIO pkt, but no tgt (ha %p)", ha
);
5111 * In tgt_stop mode we also should allow all requests to pass.
5112 * Otherwise, some commands can stuck.
5115 tgt
->atio_irq_cmd_count
++;
5117 switch (atio
->u
.raw
.entry_type
) {
5119 if (unlikely(atio
->u
.isp24
.exchange_addr
==
5120 ATIO_EXCHANGE_ADDRESS_UNKNOWN
)) {
5121 ql_dbg(ql_dbg_io
, vha
, 0x3065,
5122 "qla_target(%d): ATIO_TYPE7 "
5123 "received with UNKNOWN exchange address, "
5124 "sending QUEUE_FULL\n", vha
->vp_idx
);
5126 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5127 qlt_send_busy(vha
, atio
, SAM_STAT_TASK_SET_FULL
);
5129 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5135 if (likely(atio
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
== 0)) {
5136 rc
= qlt_chk_qfull_thresh_hold(vha
, atio
);
5138 tgt
->atio_irq_cmd_count
--;
5141 rc
= qlt_handle_cmd_for_atio(vha
, atio
);
5143 rc
= qlt_handle_task_mgmt(vha
, atio
);
5145 if (unlikely(rc
!= 0)) {
5149 (&ha
->hardware_lock
, flags
);
5151 #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */
5152 qlt_send_busy(vha
, atio
, SAM_STAT_BUSY
);
5154 qlt_send_term_exchange(vha
, NULL
, atio
, 1, 0);
5158 spin_unlock_irqrestore
5159 (&ha
->hardware_lock
, flags
);
5162 if (tgt
->tgt_stop
) {
5163 ql_dbg(ql_dbg_tgt
, vha
, 0xe059,
5164 "qla_target: Unable to send "
5165 "command to target for req, "
5168 ql_dbg(ql_dbg_tgt
, vha
, 0xe05a,
5169 "qla_target(%d): Unable to send "
5170 "command to target, sending BUSY "
5171 "status.\n", vha
->vp_idx
);
5174 &ha
->hardware_lock
, flags
);
5175 qlt_send_busy(vha
, atio
, SAM_STAT_BUSY
);
5177 spin_unlock_irqrestore(
5178 &ha
->hardware_lock
, flags
);
5184 case IMMED_NOTIFY_TYPE
:
5186 if (unlikely(atio
->u
.isp2x
.entry_status
!= 0)) {
5187 ql_dbg(ql_dbg_tgt
, vha
, 0xe05b,
5188 "qla_target(%d): Received ATIO packet %x "
5189 "with error status %x\n", vha
->vp_idx
,
5190 atio
->u
.raw
.entry_type
,
5191 atio
->u
.isp2x
.entry_status
);
5194 ql_dbg(ql_dbg_tgt
, vha
, 0xe02e, "%s", "IMMED_NOTIFY ATIO");
5197 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5198 qlt_handle_imm_notify(vha
, (struct imm_ntfy_from_isp
*)atio
);
5200 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5205 ql_dbg(ql_dbg_tgt
, vha
, 0xe05c,
5206 "qla_target(%d): Received unknown ATIO atio "
5207 "type %x\n", vha
->vp_idx
, atio
->u
.raw
.entry_type
);
5211 tgt
->atio_irq_cmd_count
--;
5214 /* ha->hardware_lock supposed to be held on entry */
5215 /* called via callback from qla2xxx */
5216 static void qlt_response_pkt(struct scsi_qla_host
*vha
, response_t
*pkt
)
5218 struct qla_hw_data
*ha
= vha
->hw
;
5219 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5221 if (unlikely(tgt
== NULL
)) {
5222 ql_dbg(ql_dbg_tgt
, vha
, 0xe05d,
5223 "qla_target(%d): Response pkt %x received, but no "
5224 "tgt (ha %p)\n", vha
->vp_idx
, pkt
->entry_type
, ha
);
5229 * In tgt_stop mode we also should allow all requests to pass.
5230 * Otherwise, some commands can stuck.
5233 tgt
->irq_cmd_count
++;
5235 switch (pkt
->entry_type
) {
5239 struct ctio7_from_24xx
*entry
= (struct ctio7_from_24xx
*)pkt
;
5240 qlt_do_ctio_completion(vha
, entry
->handle
,
5241 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
5246 case ACCEPT_TGT_IO_TYPE
:
5248 struct atio_from_isp
*atio
= (struct atio_from_isp
*)pkt
;
5250 if (atio
->u
.isp2x
.status
!=
5251 cpu_to_le16(ATIO_CDB_VALID
)) {
5252 ql_dbg(ql_dbg_tgt
, vha
, 0xe05e,
5253 "qla_target(%d): ATIO with error "
5254 "status %x received\n", vha
->vp_idx
,
5255 le16_to_cpu(atio
->u
.isp2x
.status
));
5259 rc
= qlt_chk_qfull_thresh_hold(vha
, atio
);
5261 tgt
->irq_cmd_count
--;
5265 rc
= qlt_handle_cmd_for_atio(vha
, atio
);
5266 if (unlikely(rc
!= 0)) {
5268 #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */
5269 qlt_send_busy(vha
, atio
, 0);
5271 qlt_send_term_exchange(vha
, NULL
, atio
, 1, 0);
5274 if (tgt
->tgt_stop
) {
5275 ql_dbg(ql_dbg_tgt
, vha
, 0xe05f,
5276 "qla_target: Unable to send "
5277 "command to target, sending TERM "
5278 "EXCHANGE for rsp\n");
5279 qlt_send_term_exchange(vha
, NULL
,
5282 ql_dbg(ql_dbg_tgt
, vha
, 0xe060,
5283 "qla_target(%d): Unable to send "
5284 "command to target, sending BUSY "
5285 "status\n", vha
->vp_idx
);
5286 qlt_send_busy(vha
, atio
, 0);
5293 case CONTINUE_TGT_IO_TYPE
:
5295 struct ctio_to_2xxx
*entry
= (struct ctio_to_2xxx
*)pkt
;
5296 qlt_do_ctio_completion(vha
, entry
->handle
,
5297 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
5304 struct ctio_to_2xxx
*entry
= (struct ctio_to_2xxx
*)pkt
;
5305 qlt_do_ctio_completion(vha
, entry
->handle
,
5306 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
5311 case IMMED_NOTIFY_TYPE
:
5312 ql_dbg(ql_dbg_tgt
, vha
, 0xe035, "%s", "IMMED_NOTIFY\n");
5313 qlt_handle_imm_notify(vha
, (struct imm_ntfy_from_isp
*)pkt
);
5316 case NOTIFY_ACK_TYPE
:
5317 if (tgt
->notify_ack_expected
> 0) {
5318 struct nack_to_isp
*entry
= (struct nack_to_isp
*)pkt
;
5319 ql_dbg(ql_dbg_tgt
, vha
, 0xe036,
5320 "NOTIFY_ACK seq %08x status %x\n",
5321 le16_to_cpu(entry
->u
.isp2x
.seq_id
),
5322 le16_to_cpu(entry
->u
.isp2x
.status
));
5323 tgt
->notify_ack_expected
--;
5324 if (entry
->u
.isp2x
.status
!=
5325 cpu_to_le16(NOTIFY_ACK_SUCCESS
)) {
5326 ql_dbg(ql_dbg_tgt
, vha
, 0xe061,
5327 "qla_target(%d): NOTIFY_ACK "
5328 "failed %x\n", vha
->vp_idx
,
5329 le16_to_cpu(entry
->u
.isp2x
.status
));
5332 ql_dbg(ql_dbg_tgt
, vha
, 0xe062,
5333 "qla_target(%d): Unexpected NOTIFY_ACK received\n",
5338 case ABTS_RECV_24XX
:
5339 ql_dbg(ql_dbg_tgt
, vha
, 0xe037,
5340 "ABTS_RECV_24XX: instance %d\n", vha
->vp_idx
);
5341 qlt_24xx_handle_abts(vha
, (struct abts_recv_from_24xx
*)pkt
);
5344 case ABTS_RESP_24XX
:
5345 if (tgt
->abts_resp_expected
> 0) {
5346 struct abts_resp_from_24xx_fw
*entry
=
5347 (struct abts_resp_from_24xx_fw
*)pkt
;
5348 ql_dbg(ql_dbg_tgt
, vha
, 0xe038,
5349 "ABTS_RESP_24XX: compl_status %x\n",
5350 entry
->compl_status
);
5351 tgt
->abts_resp_expected
--;
5352 if (le16_to_cpu(entry
->compl_status
) !=
5353 ABTS_RESP_COMPL_SUCCESS
) {
5354 if ((entry
->error_subcode1
== 0x1E) &&
5355 (entry
->error_subcode2
== 0)) {
5357 * We've got a race here: aborted
5358 * exchange not terminated, i.e.
5359 * response for the aborted command was
5360 * sent between the abort request was
5361 * received and processed.
5362 * Unfortunately, the firmware has a
5363 * silly requirement that all aborted
5364 * exchanges must be explicitely
5365 * terminated, otherwise it refuses to
5366 * send responses for the abort
5367 * requests. So, we have to
5368 * (re)terminate the exchange and retry
5369 * the abort response.
5371 qlt_24xx_retry_term_exchange(vha
,
5374 ql_dbg(ql_dbg_tgt
, vha
, 0xe063,
5375 "qla_target(%d): ABTS_RESP_24XX "
5376 "failed %x (subcode %x:%x)",
5377 vha
->vp_idx
, entry
->compl_status
,
5378 entry
->error_subcode1
,
5379 entry
->error_subcode2
);
5382 ql_dbg(ql_dbg_tgt
, vha
, 0xe064,
5383 "qla_target(%d): Unexpected ABTS_RESP_24XX "
5384 "received\n", vha
->vp_idx
);
5389 ql_dbg(ql_dbg_tgt
, vha
, 0xe065,
5390 "qla_target(%d): Received unknown response pkt "
5391 "type %x\n", vha
->vp_idx
, pkt
->entry_type
);
5395 tgt
->irq_cmd_count
--;
5399 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5401 void qlt_async_event(uint16_t code
, struct scsi_qla_host
*vha
,
5404 struct qla_hw_data
*ha
= vha
->hw
;
5405 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5408 if (!ha
->tgt
.tgt_ops
)
5411 if (unlikely(tgt
== NULL
)) {
5412 ql_dbg(ql_dbg_tgt
, vha
, 0xe03a,
5413 "ASYNC EVENT %#x, but no tgt (ha %p)\n", code
, ha
);
5417 if (((code
== MBA_POINT_TO_POINT
) || (code
== MBA_CHG_IN_CONNECTION
)) &&
5421 * In tgt_stop mode we also should allow all requests to pass.
5422 * Otherwise, some commands can stuck.
5425 tgt
->irq_cmd_count
++;
5428 case MBA_RESET
: /* Reset */
5429 case MBA_SYSTEM_ERR
: /* System Error */
5430 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
5431 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
5432 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03a,
5433 "qla_target(%d): System error async event %#x "
5434 "occurred", vha
->vp_idx
, code
);
5436 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up. */
5437 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
5442 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03b,
5443 "qla_target(%d): Async LOOP_UP occurred "
5444 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
,
5445 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
5446 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
5447 if (tgt
->link_reinit_iocb_pending
) {
5448 qlt_send_notify_ack(vha
, (void *)&tgt
->link_reinit_iocb
,
5450 tgt
->link_reinit_iocb_pending
= 0;
5455 case MBA_LIP_OCCURRED
:
5458 case MBA_RSCN_UPDATE
:
5459 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03c,
5460 "qla_target(%d): Async event %#x occurred "
5461 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
, code
,
5462 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
5463 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
5466 case MBA_REJECTED_FCP_CMD
:
5467 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xffff,
5468 "qla_target(%d): Async event LS_REJECT occurred "
5469 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
,
5470 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
5471 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
5473 if (le16_to_cpu(mailbox
[3]) == 1) {
5474 /* exchange starvation. */
5475 vha
->hw
->exch_starvation
++;
5476 if (vha
->hw
->exch_starvation
> 5) {
5477 ql_log(ql_log_warn
, vha
, 0xffff,
5478 "Exchange starvation-. Resetting RISC\n");
5480 vha
->hw
->exch_starvation
= 0;
5481 if (IS_P3P_TYPE(vha
->hw
))
5482 set_bit(FCOE_CTX_RESET_NEEDED
,
5485 set_bit(ISP_ABORT_NEEDED
,
5487 qla2xxx_wake_dpc(vha
);
5492 case MBA_PORT_UPDATE
:
5493 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03d,
5494 "qla_target(%d): Port update async event %#x "
5495 "occurred: updating the ports database (m[0]=%x, m[1]=%x, "
5496 "m[2]=%x, m[3]=%x)", vha
->vp_idx
, code
,
5497 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
5498 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
5500 login_code
= le16_to_cpu(mailbox
[2]);
5501 if (login_code
== 0x4) {
5502 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03e,
5503 "Async MB 2: Got PLOGI Complete\n");
5504 vha
->hw
->exch_starvation
= 0;
5505 } else if (login_code
== 0x7)
5506 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03f,
5507 "Async MB 2: Port Logged Out\n");
5513 tgt
->irq_cmd_count
--;
5516 static fc_port_t
*qlt_get_port_database(struct scsi_qla_host
*vha
,
5519 fc_port_t
*fcport
, *tfcp
, *del
;
5521 unsigned long flags
;
5524 fcport
= kzalloc(sizeof(*fcport
), GFP_KERNEL
);
5526 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06f,
5527 "qla_target(%d): Allocation of tmp FC port failed",
5532 fcport
->loop_id
= loop_id
;
5534 rc
= qla2x00_get_port_database(vha
, fcport
, 0);
5535 if (rc
!= QLA_SUCCESS
) {
5536 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf070,
5537 "qla_target(%d): Failed to retrieve fcport "
5538 "information -- get_port_database() returned %x "
5539 "(loop_id=0x%04x)", vha
->vp_idx
, rc
, loop_id
);
5545 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5546 tfcp
= qla2x00_find_fcport_by_wwpn(vha
, fcport
->port_name
, 1);
5549 tfcp
->d_id
= fcport
->d_id
;
5550 tfcp
->port_type
= fcport
->port_type
;
5551 tfcp
->supported_classes
= fcport
->supported_classes
;
5552 tfcp
->flags
|= fcport
->flags
;
5557 if (vha
->hw
->current_topology
== ISP_CFG_F
)
5558 fcport
->flags
|= FCF_FABRIC_DEVICE
;
5560 list_add_tail(&fcport
->list
, &vha
->vp_fcports
);
5561 if (!IS_SW_RESV_ADDR(fcport
->d_id
))
5562 vha
->fcport_count
++;
5563 fcport
->login_gen
++;
5564 fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
5565 fcport
->login_succ
= 1;
5569 fcport
->deleted
= 0;
5570 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5572 switch (vha
->host
->active_mode
) {
5573 case MODE_INITIATOR
:
5576 if (!IS_IIDMA_CAPABLE(vha
->hw
) || !vha
->hw
->flags
.gpsc_supported
) {
5577 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
5578 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
5579 __func__
, __LINE__
, fcport
->port_name
, vha
->fcport_count
);
5580 qla24xx_post_upd_fcport_work(vha
, fcport
);
5582 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
5583 "%s %d %8phC post gpsc fcp_cnt %d\n",
5584 __func__
, __LINE__
, fcport
->port_name
, vha
->fcport_count
);
5585 qla24xx_post_gpsc_work(vha
, fcport
);
5595 qla2x00_free_fcport(del
);
5600 /* Must be called under tgt_mutex */
5601 static struct fc_port
*qlt_make_local_sess(struct scsi_qla_host
*vha
,
5604 struct fc_port
*sess
= NULL
;
5605 fc_port_t
*fcport
= NULL
;
5606 int rc
, global_resets
;
5607 uint16_t loop_id
= 0;
5609 if ((s_id
[0] == 0xFF) && (s_id
[1] == 0xFC)) {
5611 * This is Domain Controller, so it should be
5612 * OK to drop SCSI commands from it.
5614 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf042,
5615 "Unable to find initiator with S_ID %x:%x:%x",
5616 s_id
[0], s_id
[1], s_id
[2]);
5620 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
5624 atomic_read(&vha
->vha_tgt
.qla_tgt
->tgt_global_resets_count
);
5626 rc
= qla24xx_get_loop_id(vha
, s_id
, &loop_id
);
5628 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
5630 ql_log(ql_log_info
, vha
, 0xf071,
5631 "qla_target(%d): Unable to find "
5632 "initiator with S_ID %x:%x:%x",
5633 vha
->vp_idx
, s_id
[0], s_id
[1],
5636 if (rc
== -ENOENT
) {
5637 qlt_port_logo_t logo
;
5638 sid_to_portid(s_id
, &logo
.id
);
5640 qlt_send_first_logo(vha
, &logo
);
5646 fcport
= qlt_get_port_database(vha
, loop_id
);
5648 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
5652 if (global_resets
!=
5653 atomic_read(&vha
->vha_tgt
.qla_tgt
->tgt_global_resets_count
)) {
5654 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf043,
5655 "qla_target(%d): global reset during session discovery "
5656 "(counter was %d, new %d), retrying", vha
->vp_idx
,
5658 atomic_read(&vha
->vha_tgt
.
5659 qla_tgt
->tgt_global_resets_count
));
5663 sess
= qlt_create_sess(vha
, fcport
, true);
5665 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
5670 static void qlt_abort_work(struct qla_tgt
*tgt
,
5671 struct qla_tgt_sess_work_param
*prm
)
5673 struct scsi_qla_host
*vha
= tgt
->vha
;
5674 struct qla_hw_data
*ha
= vha
->hw
;
5675 struct fc_port
*sess
= NULL
;
5676 unsigned long flags
= 0, flags2
= 0;
5681 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags2
);
5686 s_id
[0] = prm
->abts
.fcp_hdr_le
.s_id
[2];
5687 s_id
[1] = prm
->abts
.fcp_hdr_le
.s_id
[1];
5688 s_id
[2] = prm
->abts
.fcp_hdr_le
.s_id
[0];
5690 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
5691 (unsigned char *)&be_s_id
);
5693 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags2
);
5695 sess
= qlt_make_local_sess(vha
, s_id
);
5696 /* sess has got an extra creation ref */
5698 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags2
);
5702 if (sess
->deleted
) {
5707 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
5708 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0xffff,
5709 "%s: kref_get fail %8phC \n",
5710 __func__
, sess
->port_name
);
5716 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5721 rc
= __qlt_24xx_handle_abts(vha
, &prm
->abts
, sess
);
5724 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5726 ha
->tgt
.tgt_ops
->put_sess(sess
);
5727 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags2
);
5731 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5734 qlt_24xx_send_abts_resp(vha
, &prm
->abts
, FCP_TMF_REJECTED
, false);
5735 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5738 ha
->tgt
.tgt_ops
->put_sess(sess
);
5739 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags2
);
5742 static void qlt_tmr_work(struct qla_tgt
*tgt
,
5743 struct qla_tgt_sess_work_param
*prm
)
5745 struct atio_from_isp
*a
= &prm
->tm_iocb2
;
5746 struct scsi_qla_host
*vha
= tgt
->vha
;
5747 struct qla_hw_data
*ha
= vha
->hw
;
5748 struct fc_port
*sess
= NULL
;
5749 unsigned long flags
;
5750 uint8_t *s_id
= NULL
; /* to hide compiler warnings */
5752 uint32_t lun
, unpacked_lun
;
5756 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
5761 s_id
= prm
->tm_iocb2
.u
.isp24
.fcp_hdr
.s_id
;
5762 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, s_id
);
5764 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
5766 sess
= qlt_make_local_sess(vha
, s_id
);
5767 /* sess has got an extra creation ref */
5769 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
5773 if (sess
->deleted
) {
5778 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
5779 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0xffff,
5780 "%s: kref_get fail %8phC\n",
5781 __func__
, sess
->port_name
);
5788 lun
= a
->u
.isp24
.fcp_cmnd
.lun
;
5789 fn
= a
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
;
5790 unpacked_lun
= scsilun_to_int((struct scsi_lun
*)&lun
);
5792 rc
= qlt_issue_task_mgmt(sess
, unpacked_lun
, fn
, iocb
, 0);
5796 ha
->tgt
.tgt_ops
->put_sess(sess
);
5797 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
5801 qlt_send_term_exchange(vha
, NULL
, &prm
->tm_iocb2
, 1, 0);
5802 ha
->tgt
.tgt_ops
->put_sess(sess
);
5803 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
5806 static void qlt_sess_work_fn(struct work_struct
*work
)
5808 struct qla_tgt
*tgt
= container_of(work
, struct qla_tgt
, sess_work
);
5809 struct scsi_qla_host
*vha
= tgt
->vha
;
5810 unsigned long flags
;
5812 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf000, "Sess work (tgt %p)", tgt
);
5814 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
5815 while (!list_empty(&tgt
->sess_works_list
)) {
5816 struct qla_tgt_sess_work_param
*prm
= list_entry(
5817 tgt
->sess_works_list
.next
, typeof(*prm
),
5818 sess_works_list_entry
);
5821 * This work can be scheduled on several CPUs at time, so we
5822 * must delete the entry to eliminate double processing
5824 list_del(&prm
->sess_works_list_entry
);
5826 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
5828 switch (prm
->type
) {
5829 case QLA_TGT_SESS_WORK_ABORT
:
5830 qlt_abort_work(tgt
, prm
);
5832 case QLA_TGT_SESS_WORK_TM
:
5833 qlt_tmr_work(tgt
, prm
);
5840 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
5844 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
5847 /* Must be called under tgt_host_action_mutex */
5848 int qlt_add_target(struct qla_hw_data
*ha
, struct scsi_qla_host
*base_vha
)
5850 struct qla_tgt
*tgt
;
5852 if (!QLA_TGT_MODE_ENABLED())
5855 if (!IS_TGT_MODE_CAPABLE(ha
)) {
5856 ql_log(ql_log_warn
, base_vha
, 0xe070,
5857 "This adapter does not support target mode.\n");
5861 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe03b,
5862 "Registering target for host %ld(%p).\n", base_vha
->host_no
, ha
);
5864 BUG_ON(base_vha
->vha_tgt
.qla_tgt
!= NULL
);
5866 tgt
= kzalloc(sizeof(struct qla_tgt
), GFP_KERNEL
);
5868 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe066,
5869 "Unable to allocate struct qla_tgt\n");
5873 if (!(base_vha
->host
->hostt
->supported_mode
& MODE_TARGET
))
5874 base_vha
->host
->hostt
->supported_mode
|= MODE_TARGET
;
5877 tgt
->vha
= base_vha
;
5878 init_waitqueue_head(&tgt
->waitQ
);
5879 INIT_LIST_HEAD(&tgt
->del_sess_list
);
5880 spin_lock_init(&tgt
->sess_work_lock
);
5881 INIT_WORK(&tgt
->sess_work
, qlt_sess_work_fn
);
5882 INIT_LIST_HEAD(&tgt
->sess_works_list
);
5883 atomic_set(&tgt
->tgt_global_resets_count
, 0);
5885 base_vha
->vha_tgt
.qla_tgt
= tgt
;
5887 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe067,
5888 "qla_target(%d): using 64 Bit PCI addressing",
5890 tgt
->tgt_enable_64bit_addr
= 1;
5892 tgt
->sg_tablesize
= QLA_TGT_MAX_SG_24XX(base_vha
->req
->length
- 3);
5893 tgt
->datasegs_per_cmd
= QLA_TGT_DATASEGS_PER_CMD_24XX
;
5894 tgt
->datasegs_per_cont
= QLA_TGT_DATASEGS_PER_CONT_24XX
;
5896 if (base_vha
->fc_vport
)
5899 mutex_lock(&qla_tgt_mutex
);
5900 list_add_tail(&tgt
->tgt_list_entry
, &qla_tgt_glist
);
5901 mutex_unlock(&qla_tgt_mutex
);
5906 /* Must be called under tgt_host_action_mutex */
5907 int qlt_remove_target(struct qla_hw_data
*ha
, struct scsi_qla_host
*vha
)
5909 if (!vha
->vha_tgt
.qla_tgt
)
5912 if (vha
->fc_vport
) {
5913 qlt_release(vha
->vha_tgt
.qla_tgt
);
5917 /* free left over qfull cmds */
5918 qlt_init_term_exchange(vha
);
5920 mutex_lock(&qla_tgt_mutex
);
5921 list_del(&vha
->vha_tgt
.qla_tgt
->tgt_list_entry
);
5922 mutex_unlock(&qla_tgt_mutex
);
5924 ql_dbg(ql_dbg_tgt
, vha
, 0xe03c, "Unregistering target for host %ld(%p)",
5926 qlt_release(vha
->vha_tgt
.qla_tgt
);
5931 static void qlt_lport_dump(struct scsi_qla_host
*vha
, u64 wwpn
,
5936 pr_debug("qla2xxx HW vha->node_name: ");
5937 for (i
= 0; i
< WWN_SIZE
; i
++)
5938 pr_debug("%02x ", vha
->node_name
[i
]);
5940 pr_debug("qla2xxx HW vha->port_name: ");
5941 for (i
= 0; i
< WWN_SIZE
; i
++)
5942 pr_debug("%02x ", vha
->port_name
[i
]);
5945 pr_debug("qla2xxx passed configfs WWPN: ");
5946 put_unaligned_be64(wwpn
, b
);
5947 for (i
= 0; i
< WWN_SIZE
; i
++)
5948 pr_debug("%02x ", b
[i
]);
5953 * qla_tgt_lport_register - register lport with external module
5955 * @qla_tgt_ops: Pointer for tcm_qla2xxx qla_tgt_ops
5956 * @wwpn: Passwd FC target WWPN
5957 * @callback: lport initialization callback for tcm_qla2xxx code
5958 * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data
5960 int qlt_lport_register(void *target_lport_ptr
, u64 phys_wwpn
,
5961 u64 npiv_wwpn
, u64 npiv_wwnn
,
5962 int (*callback
)(struct scsi_qla_host
*, void *, u64
, u64
))
5964 struct qla_tgt
*tgt
;
5965 struct scsi_qla_host
*vha
;
5966 struct qla_hw_data
*ha
;
5967 struct Scsi_Host
*host
;
5968 unsigned long flags
;
5972 mutex_lock(&qla_tgt_mutex
);
5973 list_for_each_entry(tgt
, &qla_tgt_glist
, tgt_list_entry
) {
5981 if (!(host
->hostt
->supported_mode
& MODE_TARGET
))
5984 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5985 if ((!npiv_wwpn
|| !npiv_wwnn
) && host
->active_mode
& MODE_TARGET
) {
5986 pr_debug("MODE_TARGET already active on qla2xxx(%d)\n",
5988 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5991 if (tgt
->tgt_stop
) {
5992 pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n",
5994 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5997 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5999 if (!scsi_host_get(host
)) {
6000 ql_dbg(ql_dbg_tgt
, vha
, 0xe068,
6001 "Unable to scsi_host_get() for"
6002 " qla2xxx scsi_host\n");
6005 qlt_lport_dump(vha
, phys_wwpn
, b
);
6007 if (memcmp(vha
->port_name
, b
, WWN_SIZE
)) {
6008 scsi_host_put(host
);
6011 rc
= (*callback
)(vha
, target_lport_ptr
, npiv_wwpn
, npiv_wwnn
);
6013 scsi_host_put(host
);
6015 mutex_unlock(&qla_tgt_mutex
);
6018 mutex_unlock(&qla_tgt_mutex
);
6022 EXPORT_SYMBOL(qlt_lport_register
);
6025 * qla_tgt_lport_deregister - Degister lport
6027 * @vha: Registered scsi_qla_host pointer
6029 void qlt_lport_deregister(struct scsi_qla_host
*vha
)
6031 struct qla_hw_data
*ha
= vha
->hw
;
6032 struct Scsi_Host
*sh
= vha
->host
;
6034 * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data
6036 vha
->vha_tgt
.target_lport_ptr
= NULL
;
6037 ha
->tgt
.tgt_ops
= NULL
;
6039 * Release the Scsi_Host reference for the underlying qla2xxx host
6043 EXPORT_SYMBOL(qlt_lport_deregister
);
6045 /* Must be called under HW lock */
6046 static void qlt_set_mode(struct scsi_qla_host
*vha
)
6048 switch (ql2x_ini_mode
) {
6049 case QLA2XXX_INI_MODE_DISABLED
:
6050 case QLA2XXX_INI_MODE_EXCLUSIVE
:
6051 vha
->host
->active_mode
= MODE_TARGET
;
6053 case QLA2XXX_INI_MODE_ENABLED
:
6054 vha
->host
->active_mode
= MODE_UNKNOWN
;
6056 case QLA2XXX_INI_MODE_DUAL
:
6057 vha
->host
->active_mode
= MODE_DUAL
;
6064 /* Must be called under HW lock */
6065 static void qlt_clear_mode(struct scsi_qla_host
*vha
)
6067 switch (ql2x_ini_mode
) {
6068 case QLA2XXX_INI_MODE_DISABLED
:
6069 vha
->host
->active_mode
= MODE_UNKNOWN
;
6071 case QLA2XXX_INI_MODE_EXCLUSIVE
:
6072 vha
->host
->active_mode
= MODE_INITIATOR
;
6074 case QLA2XXX_INI_MODE_ENABLED
:
6075 case QLA2XXX_INI_MODE_DUAL
:
6076 vha
->host
->active_mode
= MODE_INITIATOR
;
6084 * qla_tgt_enable_vha - NO LOCK HELD
6086 * host_reset, bring up w/ Target Mode Enabled
6089 qlt_enable_vha(struct scsi_qla_host
*vha
)
6091 struct qla_hw_data
*ha
= vha
->hw
;
6092 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
6093 unsigned long flags
;
6094 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
6095 int rspq_ent
= QLA83XX_RSPQ_MSIX_ENTRY_NUMBER
;
6098 ql_dbg(ql_dbg_tgt
, vha
, 0xe069,
6099 "Unable to locate qla_tgt pointer from"
6100 " struct qla_hw_data\n");
6105 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6106 tgt
->tgt_stopped
= 0;
6108 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6111 qla24xx_disable_vp(vha
);
6112 qla24xx_enable_vp(vha
);
6114 if (ha
->msix_entries
) {
6115 ql_dbg(ql_dbg_tgt
, vha
, 0xffff,
6116 "%s: host%ld : vector %d cpu %d\n",
6117 __func__
, vha
->host_no
,
6118 ha
->msix_entries
[rspq_ent
].vector
,
6119 ha
->msix_entries
[rspq_ent
].cpuid
);
6121 ha
->tgt
.rspq_vector_cpuid
=
6122 ha
->msix_entries
[rspq_ent
].cpuid
;
6125 set_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
);
6126 qla2xxx_wake_dpc(base_vha
);
6127 qla2x00_wait_for_hba_online(base_vha
);
6130 EXPORT_SYMBOL(qlt_enable_vha
);
6133 * qla_tgt_disable_vha - NO LOCK HELD
6135 * Disable Target Mode and reset the adapter
6137 static void qlt_disable_vha(struct scsi_qla_host
*vha
)
6139 struct qla_hw_data
*ha
= vha
->hw
;
6140 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
6141 unsigned long flags
;
6144 ql_dbg(ql_dbg_tgt
, vha
, 0xe06a,
6145 "Unable to locate qla_tgt pointer from"
6146 " struct qla_hw_data\n");
6151 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6152 qlt_clear_mode(vha
);
6153 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6155 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
6156 qla2xxx_wake_dpc(vha
);
6157 qla2x00_wait_for_hba_online(vha
);
6161 * Called from qla_init.c:qla24xx_vport_create() contex to setup
6162 * the target mode specific struct scsi_qla_host and struct qla_hw_data
6166 qlt_vport_create(struct scsi_qla_host
*vha
, struct qla_hw_data
*ha
)
6168 vha
->vha_tgt
.qla_tgt
= NULL
;
6170 mutex_init(&vha
->vha_tgt
.tgt_mutex
);
6171 mutex_init(&vha
->vha_tgt
.tgt_host_action_mutex
);
6173 qlt_clear_mode(vha
);
6176 * NOTE: Currently the value is kept the same for <24xx and
6177 * >=24xx ISPs. If it is necessary to change it,
6178 * the check should be added for specific ISPs,
6179 * assigning the value appropriately.
6181 ha
->tgt
.atio_q_length
= ATIO_ENTRY_CNT_24XX
;
6183 qlt_add_target(ha
, vha
);
6187 qlt_rff_id(struct scsi_qla_host
*vha
, struct ct_sns_req
*ct_req
)
6190 * FC-4 Feature bit 0 indicates target functionality to the name server.
6192 if (qla_tgt_mode_enabled(vha
)) {
6193 ct_req
->req
.rff_id
.fc4_feature
= BIT_0
;
6194 } else if (qla_ini_mode_enabled(vha
)) {
6195 ct_req
->req
.rff_id
.fc4_feature
= BIT_1
;
6196 } else if (qla_dual_mode_enabled(vha
))
6197 ct_req
->req
.rff_id
.fc4_feature
= BIT_0
| BIT_1
;
6201 * qlt_init_atio_q_entries() - Initializes ATIO queue entries.
6204 * Beginning of ATIO ring has initialization control block already built
6205 * by nvram config routine.
6207 * Returns 0 on success.
6210 qlt_init_atio_q_entries(struct scsi_qla_host
*vha
)
6212 struct qla_hw_data
*ha
= vha
->hw
;
6214 struct atio_from_isp
*pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring
;
6216 if (qla_ini_mode_enabled(vha
))
6219 for (cnt
= 0; cnt
< ha
->tgt
.atio_q_length
; cnt
++) {
6220 pkt
->u
.raw
.signature
= ATIO_PROCESSED
;
6227 * qlt_24xx_process_atio_queue() - Process ATIO queue entries.
6228 * @ha: SCSI driver HA context
6231 qlt_24xx_process_atio_queue(struct scsi_qla_host
*vha
, uint8_t ha_locked
)
6233 struct qla_hw_data
*ha
= vha
->hw
;
6234 struct atio_from_isp
*pkt
;
6237 if (!vha
->flags
.online
)
6240 while ((ha
->tgt
.atio_ring_ptr
->signature
!= ATIO_PROCESSED
) ||
6241 fcpcmd_is_corrupted(ha
->tgt
.atio_ring_ptr
)) {
6242 pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring_ptr
;
6243 cnt
= pkt
->u
.raw
.entry_count
;
6245 if (unlikely(fcpcmd_is_corrupted(ha
->tgt
.atio_ring_ptr
))) {
6247 * This packet is corrupted. The header + payload
6248 * can not be trusted. There is no point in passing
6251 ql_log(ql_log_warn
, vha
, 0xffff,
6252 "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n",
6253 pkt
->u
.isp24
.fcp_hdr
.s_id
,
6254 be16_to_cpu(pkt
->u
.isp24
.fcp_hdr
.ox_id
),
6255 le32_to_cpu(pkt
->u
.isp24
.exchange_addr
), pkt
);
6257 adjust_corrupted_atio(pkt
);
6258 qlt_send_term_exchange(vha
, NULL
, pkt
, ha_locked
, 0);
6260 qlt_24xx_atio_pkt_all_vps(vha
,
6261 (struct atio_from_isp
*)pkt
, ha_locked
);
6264 for (i
= 0; i
< cnt
; i
++) {
6265 ha
->tgt
.atio_ring_index
++;
6266 if (ha
->tgt
.atio_ring_index
== ha
->tgt
.atio_q_length
) {
6267 ha
->tgt
.atio_ring_index
= 0;
6268 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
6270 ha
->tgt
.atio_ring_ptr
++;
6272 pkt
->u
.raw
.signature
= ATIO_PROCESSED
;
6273 pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring_ptr
;
6278 /* Adjust ring index */
6279 WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha
), ha
->tgt
.atio_ring_index
);
6280 RD_REG_DWORD_RELAXED(ISP_ATIO_Q_OUT(vha
));
6284 qlt_24xx_config_rings(struct scsi_qla_host
*vha
)
6286 struct qla_hw_data
*ha
= vha
->hw
;
6287 if (!QLA_TGT_MODE_ENABLED())
6290 WRT_REG_DWORD(ISP_ATIO_Q_IN(vha
), 0);
6291 WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha
), 0);
6292 RD_REG_DWORD(ISP_ATIO_Q_OUT(vha
));
6294 if (IS_ATIO_MSIX_CAPABLE(ha
)) {
6295 struct qla_msix_entry
*msix
= &ha
->msix_entries
[2];
6296 struct init_cb_24xx
*icb
= (struct init_cb_24xx
*)ha
->init_cb
;
6298 icb
->msix_atio
= cpu_to_le16(msix
->entry
);
6299 ql_dbg(ql_dbg_init
, vha
, 0xf072,
6300 "Registering ICB vector 0x%x for atio que.\n",
6306 qlt_24xx_config_nvram_stage1(struct scsi_qla_host
*vha
, struct nvram_24xx
*nv
)
6308 struct qla_hw_data
*ha
= vha
->hw
;
6312 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
6313 if (!ha
->tgt
.saved_set
) {
6314 /* We save only once */
6315 ha
->tgt
.saved_exchange_count
= nv
->exchange_count
;
6316 ha
->tgt
.saved_firmware_options_1
=
6317 nv
->firmware_options_1
;
6318 ha
->tgt
.saved_firmware_options_2
=
6319 nv
->firmware_options_2
;
6320 ha
->tgt
.saved_firmware_options_3
=
6321 nv
->firmware_options_3
;
6322 ha
->tgt
.saved_set
= 1;
6325 if (qla_tgt_mode_enabled(vha
)) {
6326 nv
->exchange_count
= cpu_to_le16(0xFFFF);
6328 if (ql_dm_tgt_ex_pct
> 100) {
6329 ql_dm_tgt_ex_pct
= 50;
6330 } else if (ql_dm_tgt_ex_pct
== 100) {
6331 /* leave some for FW */
6332 ql_dm_tgt_ex_pct
= 95;
6335 tmp
= ha
->orig_fw_xcb_count
* ql_dm_tgt_ex_pct
;
6341 nv
->exchange_count
= cpu_to_le16(t
);
6344 /* Enable target mode */
6345 nv
->firmware_options_1
|= cpu_to_le32(BIT_4
);
6347 /* Disable ini mode, if requested */
6348 if (qla_tgt_mode_enabled(vha
))
6349 nv
->firmware_options_1
|= cpu_to_le32(BIT_5
);
6351 /* Disable Full Login after LIP */
6352 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
6353 /* Enable initial LIP */
6354 nv
->firmware_options_1
&= cpu_to_le32(~BIT_9
);
6355 if (ql2xtgt_tape_enable
)
6356 /* Enable FC Tape support */
6357 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
6359 /* Disable FC Tape support */
6360 nv
->firmware_options_2
&= cpu_to_le32(~BIT_12
);
6362 /* Disable Full Login after LIP */
6363 nv
->host_p
&= cpu_to_le32(~BIT_10
);
6366 * clear BIT 15 explicitly as we have seen at least
6367 * a couple of instances where this was set and this
6368 * was causing the firmware to not be initialized.
6370 nv
->firmware_options_1
&= cpu_to_le32(~BIT_15
);
6371 /* Enable target PRLI control */
6372 nv
->firmware_options_2
|= cpu_to_le32(BIT_14
);
6374 if (ha
->tgt
.saved_set
) {
6375 nv
->exchange_count
= ha
->tgt
.saved_exchange_count
;
6376 nv
->firmware_options_1
=
6377 ha
->tgt
.saved_firmware_options_1
;
6378 nv
->firmware_options_2
=
6379 ha
->tgt
.saved_firmware_options_2
;
6380 nv
->firmware_options_3
=
6381 ha
->tgt
.saved_firmware_options_3
;
6386 if (ha
->tgt
.enable_class_2
) {
6387 if (vha
->flags
.init_done
)
6388 fc_host_supported_classes(vha
->host
) =
6389 FC_COS_CLASS2
| FC_COS_CLASS3
;
6391 nv
->firmware_options_2
|= cpu_to_le32(BIT_8
);
6393 if (vha
->flags
.init_done
)
6394 fc_host_supported_classes(vha
->host
) = FC_COS_CLASS3
;
6396 nv
->firmware_options_2
&= ~cpu_to_le32(BIT_8
);
6401 qlt_24xx_config_nvram_stage2(struct scsi_qla_host
*vha
,
6402 struct init_cb_24xx
*icb
)
6404 struct qla_hw_data
*ha
= vha
->hw
;
6406 if (!QLA_TGT_MODE_ENABLED())
6409 if (ha
->tgt
.node_name_set
) {
6410 memcpy(icb
->node_name
, ha
->tgt
.tgt_node_name
, WWN_SIZE
);
6411 icb
->firmware_options_1
|= cpu_to_le32(BIT_14
);
6414 /* disable ZIO at start time. */
6415 if (!vha
->flags
.init_done
) {
6417 tmp
= le32_to_cpu(icb
->firmware_options_2
);
6418 tmp
&= ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
6419 icb
->firmware_options_2
= cpu_to_le32(tmp
);
6424 qlt_81xx_config_nvram_stage1(struct scsi_qla_host
*vha
, struct nvram_81xx
*nv
)
6426 struct qla_hw_data
*ha
= vha
->hw
;
6430 if (!QLA_TGT_MODE_ENABLED())
6433 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
6434 if (!ha
->tgt
.saved_set
) {
6435 /* We save only once */
6436 ha
->tgt
.saved_exchange_count
= nv
->exchange_count
;
6437 ha
->tgt
.saved_firmware_options_1
=
6438 nv
->firmware_options_1
;
6439 ha
->tgt
.saved_firmware_options_2
=
6440 nv
->firmware_options_2
;
6441 ha
->tgt
.saved_firmware_options_3
=
6442 nv
->firmware_options_3
;
6443 ha
->tgt
.saved_set
= 1;
6446 if (qla_tgt_mode_enabled(vha
)) {
6447 nv
->exchange_count
= cpu_to_le16(0xFFFF);
6449 if (ql_dm_tgt_ex_pct
> 100) {
6450 ql_dm_tgt_ex_pct
= 50;
6451 } else if (ql_dm_tgt_ex_pct
== 100) {
6452 /* leave some for FW */
6453 ql_dm_tgt_ex_pct
= 95;
6456 tmp
= ha
->orig_fw_xcb_count
* ql_dm_tgt_ex_pct
;
6461 nv
->exchange_count
= cpu_to_le16(t
);
6464 /* Enable target mode */
6465 nv
->firmware_options_1
|= cpu_to_le32(BIT_4
);
6467 /* Disable ini mode, if requested */
6468 if (qla_tgt_mode_enabled(vha
))
6469 nv
->firmware_options_1
|= cpu_to_le32(BIT_5
);
6470 /* Disable Full Login after LIP */
6471 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
6472 /* Enable initial LIP */
6473 nv
->firmware_options_1
&= cpu_to_le32(~BIT_9
);
6475 * clear BIT 15 explicitly as we have seen at
6476 * least a couple of instances where this was set
6477 * and this was causing the firmware to not be
6480 nv
->firmware_options_1
&= cpu_to_le32(~BIT_15
);
6481 if (ql2xtgt_tape_enable
)
6482 /* Enable FC tape support */
6483 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
6485 /* Disable FC tape support */
6486 nv
->firmware_options_2
&= cpu_to_le32(~BIT_12
);
6488 /* Disable Full Login after LIP */
6489 nv
->host_p
&= cpu_to_le32(~BIT_10
);
6490 /* Enable target PRLI control */
6491 nv
->firmware_options_2
|= cpu_to_le32(BIT_14
);
6493 if (ha
->tgt
.saved_set
) {
6494 nv
->exchange_count
= ha
->tgt
.saved_exchange_count
;
6495 nv
->firmware_options_1
=
6496 ha
->tgt
.saved_firmware_options_1
;
6497 nv
->firmware_options_2
=
6498 ha
->tgt
.saved_firmware_options_2
;
6499 nv
->firmware_options_3
=
6500 ha
->tgt
.saved_firmware_options_3
;
6505 if (ha
->tgt
.enable_class_2
) {
6506 if (vha
->flags
.init_done
)
6507 fc_host_supported_classes(vha
->host
) =
6508 FC_COS_CLASS2
| FC_COS_CLASS3
;
6510 nv
->firmware_options_2
|= cpu_to_le32(BIT_8
);
6512 if (vha
->flags
.init_done
)
6513 fc_host_supported_classes(vha
->host
) = FC_COS_CLASS3
;
6515 nv
->firmware_options_2
&= ~cpu_to_le32(BIT_8
);
6520 qlt_81xx_config_nvram_stage2(struct scsi_qla_host
*vha
,
6521 struct init_cb_81xx
*icb
)
6523 struct qla_hw_data
*ha
= vha
->hw
;
6525 if (!QLA_TGT_MODE_ENABLED())
6528 if (ha
->tgt
.node_name_set
) {
6529 memcpy(icb
->node_name
, ha
->tgt
.tgt_node_name
, WWN_SIZE
);
6530 icb
->firmware_options_1
|= cpu_to_le32(BIT_14
);
6533 /* disable ZIO at start time. */
6534 if (!vha
->flags
.init_done
) {
6536 tmp
= le32_to_cpu(icb
->firmware_options_2
);
6537 tmp
&= ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
6538 icb
->firmware_options_2
= cpu_to_le32(tmp
);
6544 qlt_83xx_iospace_config(struct qla_hw_data
*ha
)
6546 if (!QLA_TGT_MODE_ENABLED())
6549 ha
->msix_count
+= 1; /* For ATIO Q */
6553 qlt_24xx_process_response_error(struct scsi_qla_host
*vha
,
6554 struct sts_entry_24xx
*pkt
)
6556 switch (pkt
->entry_type
) {
6557 case ABTS_RECV_24XX
:
6558 case ABTS_RESP_24XX
:
6560 case NOTIFY_ACK_TYPE
:
6569 qlt_modify_vp_config(struct scsi_qla_host
*vha
,
6570 struct vp_config_entry_24xx
*vpmod
)
6572 /* enable target mode. Bit5 = 1 => disable */
6573 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
6574 vpmod
->options_idx1
&= ~BIT_5
;
6576 /* Disable ini mode, if requested. bit4 = 1 => disable */
6577 if (qla_tgt_mode_enabled(vha
))
6578 vpmod
->options_idx1
&= ~BIT_4
;
6582 qlt_probe_one_stage1(struct scsi_qla_host
*base_vha
, struct qla_hw_data
*ha
)
6584 if (!QLA_TGT_MODE_ENABLED())
6587 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
6588 ISP_ATIO_Q_IN(base_vha
) = &ha
->mqiobase
->isp25mq
.atio_q_in
;
6589 ISP_ATIO_Q_OUT(base_vha
) = &ha
->mqiobase
->isp25mq
.atio_q_out
;
6591 ISP_ATIO_Q_IN(base_vha
) = &ha
->iobase
->isp24
.atio_q_in
;
6592 ISP_ATIO_Q_OUT(base_vha
) = &ha
->iobase
->isp24
.atio_q_out
;
6595 mutex_init(&base_vha
->vha_tgt
.tgt_mutex
);
6596 mutex_init(&base_vha
->vha_tgt
.tgt_host_action_mutex
);
6598 INIT_LIST_HEAD(&base_vha
->unknown_atio_list
);
6599 INIT_DELAYED_WORK(&base_vha
->unknown_atio_work
,
6600 qlt_unknown_atio_work_fn
);
6602 qlt_clear_mode(base_vha
);
6606 qla83xx_msix_atio_q(int irq
, void *dev_id
)
6608 struct rsp_que
*rsp
;
6609 scsi_qla_host_t
*vha
;
6610 struct qla_hw_data
*ha
;
6611 unsigned long flags
;
6613 rsp
= (struct rsp_que
*) dev_id
;
6615 vha
= pci_get_drvdata(ha
->pdev
);
6617 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags
);
6619 qlt_24xx_process_atio_queue(vha
, 0);
6621 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
, flags
);
6627 qlt_handle_abts_recv_work(struct work_struct
*work
)
6629 struct qla_tgt_sess_op
*op
= container_of(work
,
6630 struct qla_tgt_sess_op
, work
);
6631 scsi_qla_host_t
*vha
= op
->vha
;
6632 struct qla_hw_data
*ha
= vha
->hw
;
6633 unsigned long flags
;
6635 if (qla2x00_reset_active(vha
) || (op
->chip_reset
!= ha
->chip_reset
))
6638 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags
);
6639 qlt_24xx_process_atio_queue(vha
, 0);
6640 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
, flags
);
6642 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6643 qlt_response_pkt_all_vps(vha
, (response_t
*)&op
->atio
);
6644 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6648 qlt_handle_abts_recv(struct scsi_qla_host
*vha
, response_t
*pkt
)
6650 struct qla_tgt_sess_op
*op
;
6652 op
= kzalloc(sizeof(*op
), GFP_ATOMIC
);
6655 /* do not reach for ATIO queue here. This is best effort err
6656 * recovery at this point.
6658 qlt_response_pkt_all_vps(vha
, pkt
);
6662 memcpy(&op
->atio
, pkt
, sizeof(*pkt
));
6664 op
->chip_reset
= vha
->hw
->chip_reset
;
6665 INIT_WORK(&op
->work
, qlt_handle_abts_recv_work
);
6666 queue_work(qla_tgt_wq
, &op
->work
);
6671 qlt_mem_alloc(struct qla_hw_data
*ha
)
6673 if (!QLA_TGT_MODE_ENABLED())
6676 ha
->tgt
.tgt_vp_map
= kzalloc(sizeof(struct qla_tgt_vp_map
) *
6677 MAX_MULTI_ID_FABRIC
, GFP_KERNEL
);
6678 if (!ha
->tgt
.tgt_vp_map
)
6681 ha
->tgt
.atio_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
6682 (ha
->tgt
.atio_q_length
+ 1) * sizeof(struct atio_from_isp
),
6683 &ha
->tgt
.atio_dma
, GFP_KERNEL
);
6684 if (!ha
->tgt
.atio_ring
) {
6685 kfree(ha
->tgt
.tgt_vp_map
);
6692 qlt_mem_free(struct qla_hw_data
*ha
)
6694 if (!QLA_TGT_MODE_ENABLED())
6697 if (ha
->tgt
.atio_ring
) {
6698 dma_free_coherent(&ha
->pdev
->dev
, (ha
->tgt
.atio_q_length
+ 1) *
6699 sizeof(struct atio_from_isp
), ha
->tgt
.atio_ring
,
6702 kfree(ha
->tgt
.tgt_vp_map
);
6705 /* vport_slock to be held by the caller */
6707 qlt_update_vp_map(struct scsi_qla_host
*vha
, int cmd
)
6709 if (!QLA_TGT_MODE_ENABLED())
6714 vha
->hw
->tgt
.tgt_vp_map
[vha
->vp_idx
].vha
= vha
;
6717 vha
->hw
->tgt
.tgt_vp_map
[vha
->d_id
.b
.al_pa
].idx
= vha
->vp_idx
;
6720 vha
->hw
->tgt
.tgt_vp_map
[vha
->vp_idx
].vha
= NULL
;
6723 vha
->hw
->tgt
.tgt_vp_map
[vha
->d_id
.b
.al_pa
].idx
= 0;
6728 static int __init
qlt_parse_ini_mode(void)
6730 if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_EXCLUSIVE
) == 0)
6731 ql2x_ini_mode
= QLA2XXX_INI_MODE_EXCLUSIVE
;
6732 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_DISABLED
) == 0)
6733 ql2x_ini_mode
= QLA2XXX_INI_MODE_DISABLED
;
6734 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_ENABLED
) == 0)
6735 ql2x_ini_mode
= QLA2XXX_INI_MODE_ENABLED
;
6736 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_DUAL
) == 0)
6737 ql2x_ini_mode
= QLA2XXX_INI_MODE_DUAL
;
6744 int __init
qlt_init(void)
6748 if (!qlt_parse_ini_mode()) {
6749 ql_log(ql_log_fatal
, NULL
, 0xe06b,
6750 "qlt_parse_ini_mode() failed\n");
6754 if (!QLA_TGT_MODE_ENABLED())
6757 qla_tgt_mgmt_cmd_cachep
= kmem_cache_create("qla_tgt_mgmt_cmd_cachep",
6758 sizeof(struct qla_tgt_mgmt_cmd
), __alignof__(struct
6759 qla_tgt_mgmt_cmd
), 0, NULL
);
6760 if (!qla_tgt_mgmt_cmd_cachep
) {
6761 ql_log(ql_log_fatal
, NULL
, 0xe06d,
6762 "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n");
6766 qla_tgt_plogi_cachep
= kmem_cache_create("qla_tgt_plogi_cachep",
6767 sizeof(struct qlt_plogi_ack_t
), __alignof__(struct qlt_plogi_ack_t
),
6770 if (!qla_tgt_plogi_cachep
) {
6771 ql_log(ql_log_fatal
, NULL
, 0xe06d,
6772 "kmem_cache_create for qla_tgt_plogi_cachep failed\n");
6774 goto out_mgmt_cmd_cachep
;
6777 qla_tgt_mgmt_cmd_mempool
= mempool_create(25, mempool_alloc_slab
,
6778 mempool_free_slab
, qla_tgt_mgmt_cmd_cachep
);
6779 if (!qla_tgt_mgmt_cmd_mempool
) {
6780 ql_log(ql_log_fatal
, NULL
, 0xe06e,
6781 "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n");
6783 goto out_plogi_cachep
;
6786 qla_tgt_wq
= alloc_workqueue("qla_tgt_wq", 0, 0);
6788 ql_log(ql_log_fatal
, NULL
, 0xe06f,
6789 "alloc_workqueue for qla_tgt_wq failed\n");
6791 goto out_cmd_mempool
;
6794 * Return 1 to signal that initiator-mode is being disabled
6796 return (ql2x_ini_mode
== QLA2XXX_INI_MODE_DISABLED
) ? 1 : 0;
6799 mempool_destroy(qla_tgt_mgmt_cmd_mempool
);
6801 kmem_cache_destroy(qla_tgt_plogi_cachep
);
6802 out_mgmt_cmd_cachep
:
6803 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep
);
6809 if (!QLA_TGT_MODE_ENABLED())
6812 destroy_workqueue(qla_tgt_wq
);
6813 mempool_destroy(qla_tgt_mgmt_cmd_mempool
);
6814 kmem_cache_destroy(qla_tgt_plogi_cachep
);
6815 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep
);