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
);
133 static void qlt_24xx_handle_abts(struct scsi_qla_host
*,
134 struct abts_recv_from_24xx
*);
139 static struct kmem_cache
*qla_tgt_mgmt_cmd_cachep
;
140 static struct kmem_cache
*qla_tgt_plogi_cachep
;
141 static mempool_t
*qla_tgt_mgmt_cmd_mempool
;
142 static struct workqueue_struct
*qla_tgt_wq
;
143 static DEFINE_MUTEX(qla_tgt_mutex
);
144 static LIST_HEAD(qla_tgt_glist
);
146 static const char *prot_op_str(u32 prot_op
)
149 case TARGET_PROT_NORMAL
: return "NORMAL";
150 case TARGET_PROT_DIN_INSERT
: return "DIN_INSERT";
151 case TARGET_PROT_DOUT_INSERT
: return "DOUT_INSERT";
152 case TARGET_PROT_DIN_STRIP
: return "DIN_STRIP";
153 case TARGET_PROT_DOUT_STRIP
: return "DOUT_STRIP";
154 case TARGET_PROT_DIN_PASS
: return "DIN_PASS";
155 case TARGET_PROT_DOUT_PASS
: return "DOUT_PASS";
156 default: return "UNKNOWN";
160 /* This API intentionally takes dest as a parameter, rather than returning
161 * int value to avoid caller forgetting to issue wmb() after the store */
162 void qlt_do_generation_tick(struct scsi_qla_host
*vha
, int *dest
)
164 scsi_qla_host_t
*base_vha
= pci_get_drvdata(vha
->hw
->pdev
);
165 *dest
= atomic_inc_return(&base_vha
->generation_tick
);
170 /* Might release hw lock, then reaquire!! */
171 static inline int qlt_issue_marker(struct scsi_qla_host
*vha
, int vha_locked
)
173 /* Send marker if required */
174 if (unlikely(vha
->marker_needed
!= 0)) {
175 int rc
= qla2x00_issue_marker(vha
, vha_locked
);
176 if (rc
!= QLA_SUCCESS
) {
177 ql_dbg(ql_dbg_tgt
, vha
, 0xe03d,
178 "qla_target(%d): issue_marker() failed\n",
187 struct scsi_qla_host
*qlt_find_host_by_d_id(struct scsi_qla_host
*vha
,
190 struct scsi_qla_host
*host
;
193 if ((vha
->d_id
.b
.area
== d_id
[1]) && (vha
->d_id
.b
.domain
== d_id
[0]) &&
194 (vha
->d_id
.b
.al_pa
== d_id
[2]))
197 key
= (uint32_t)d_id
[0] << 16;
198 key
|= (uint32_t)d_id
[1] << 8;
199 key
|= (uint32_t)d_id
[2];
201 host
= btree_lookup32(&vha
->hw
->tgt
.host_map
, key
);
203 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xffff,
204 "Unable to find host %06x\n", key
);
210 struct scsi_qla_host
*qlt_find_host_by_vp_idx(struct scsi_qla_host
*vha
,
213 struct qla_hw_data
*ha
= vha
->hw
;
215 if (vha
->vp_idx
== vp_idx
)
218 BUG_ON(ha
->tgt
.tgt_vp_map
== NULL
);
219 if (likely(test_bit(vp_idx
, ha
->vp_idx_map
)))
220 return ha
->tgt
.tgt_vp_map
[vp_idx
].vha
;
225 static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host
*vha
)
229 spin_lock_irqsave(&vha
->hw
->tgt
.q_full_lock
, flags
);
231 vha
->hw
->tgt
.num_pend_cmds
++;
232 if (vha
->hw
->tgt
.num_pend_cmds
> vha
->qla_stats
.stat_max_pend_cmds
)
233 vha
->qla_stats
.stat_max_pend_cmds
=
234 vha
->hw
->tgt
.num_pend_cmds
;
235 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
237 static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host
*vha
)
241 spin_lock_irqsave(&vha
->hw
->tgt
.q_full_lock
, flags
);
242 vha
->hw
->tgt
.num_pend_cmds
--;
243 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
247 static void qlt_queue_unknown_atio(scsi_qla_host_t
*vha
,
248 struct atio_from_isp
*atio
, uint8_t ha_locked
)
250 struct qla_tgt_sess_op
*u
;
251 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
255 ql_dbg(ql_dbg_async
, vha
, 0xffff,
256 "qla_target(%d): dropping unknown ATIO_TYPE7, "
257 "because tgt is being stopped", vha
->vp_idx
);
261 u
= kzalloc(sizeof(*u
), GFP_ATOMIC
);
263 ql_dbg(ql_dbg_async
, vha
, 0xffff,
264 "Alloc of struct unknown_atio (size %zd) failed", sizeof(*u
));
265 /* It should be harmless and on the next retry should work well */
270 memcpy(&u
->atio
, atio
, sizeof(*atio
));
271 INIT_LIST_HEAD(&u
->cmd_list
);
273 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
274 list_add_tail(&u
->cmd_list
, &vha
->unknown_atio_list
);
275 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
277 schedule_delayed_work(&vha
->unknown_atio_work
, 1);
283 qlt_send_term_exchange(vha
, NULL
, atio
, ha_locked
, 0);
287 static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host
*vha
,
290 struct qla_tgt_sess_op
*u
, *t
;
291 scsi_qla_host_t
*host
;
292 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
296 list_for_each_entry_safe(u
, t
, &vha
->unknown_atio_list
, cmd_list
) {
298 ql_dbg(ql_dbg_async
, vha
, 0xffff,
299 "Freeing unknown %s %p, because of Abort",
301 qlt_send_term_exchange(vha
, NULL
, &u
->atio
,
306 host
= qlt_find_host_by_d_id(vha
, u
->atio
.u
.isp24
.fcp_hdr
.d_id
);
308 ql_dbg(ql_dbg_async
, vha
, 0xffff,
309 "Requeuing unknown ATIO_TYPE7 %p", u
);
310 qlt_24xx_atio_pkt(host
, &u
->atio
, ha_locked
);
311 } else if (tgt
->tgt_stop
) {
312 ql_dbg(ql_dbg_async
, vha
, 0xffff,
313 "Freeing unknown %s %p, because tgt is being stopped",
315 qlt_send_term_exchange(vha
, NULL
, &u
->atio
,
318 ql_dbg(ql_dbg_async
, vha
, 0xffff,
319 "u %p, vha %p, host %p, sched again..", u
,
323 schedule_delayed_work(&vha
->unknown_atio_work
,
330 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
331 list_del(&u
->cmd_list
);
332 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
337 void qlt_unknown_atio_work_fn(struct work_struct
*work
)
339 struct scsi_qla_host
*vha
= container_of(to_delayed_work(work
),
340 struct scsi_qla_host
, unknown_atio_work
);
342 qlt_try_to_dequeue_unknown_atios(vha
, 0);
345 static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host
*vha
,
346 struct atio_from_isp
*atio
, uint8_t ha_locked
)
348 ql_dbg(ql_dbg_tgt
, vha
, 0xe072,
349 "%s: qla_target(%d): type %x ox_id %04x\n",
350 __func__
, vha
->vp_idx
, atio
->u
.raw
.entry_type
,
351 be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
));
353 switch (atio
->u
.raw
.entry_type
) {
356 struct scsi_qla_host
*host
= qlt_find_host_by_d_id(vha
,
357 atio
->u
.isp24
.fcp_hdr
.d_id
);
358 if (unlikely(NULL
== host
)) {
359 ql_dbg(ql_dbg_tgt
, vha
, 0xe03e,
360 "qla_target(%d): Received ATIO_TYPE7 "
361 "with unknown d_id %x:%x:%x\n", vha
->vp_idx
,
362 atio
->u
.isp24
.fcp_hdr
.d_id
[0],
363 atio
->u
.isp24
.fcp_hdr
.d_id
[1],
364 atio
->u
.isp24
.fcp_hdr
.d_id
[2]);
367 qlt_queue_unknown_atio(vha
, atio
, ha_locked
);
370 if (unlikely(!list_empty(&vha
->unknown_atio_list
)))
371 qlt_try_to_dequeue_unknown_atios(vha
, ha_locked
);
373 qlt_24xx_atio_pkt(host
, atio
, ha_locked
);
377 case IMMED_NOTIFY_TYPE
:
379 struct scsi_qla_host
*host
= vha
;
380 struct imm_ntfy_from_isp
*entry
=
381 (struct imm_ntfy_from_isp
*)atio
;
383 if ((entry
->u
.isp24
.vp_index
!= 0xFF) &&
384 (entry
->u
.isp24
.nport_handle
!= 0xFFFF)) {
385 host
= qlt_find_host_by_vp_idx(vha
,
386 entry
->u
.isp24
.vp_index
);
387 if (unlikely(!host
)) {
388 ql_dbg(ql_dbg_tgt
, vha
, 0xe03f,
389 "qla_target(%d): Received "
390 "ATIO (IMMED_NOTIFY_TYPE) "
391 "with unknown vp_index %d\n",
392 vha
->vp_idx
, entry
->u
.isp24
.vp_index
);
396 qlt_24xx_atio_pkt(host
, atio
, ha_locked
);
400 case VP_RPT_ID_IOCB_TYPE
:
401 qla24xx_report_id_acquisition(vha
,
402 (struct vp_rpt_id_entry_24xx
*)atio
);
407 struct abts_recv_from_24xx
*entry
=
408 (struct abts_recv_from_24xx
*)atio
;
409 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
413 if (unlikely(!host
)) {
414 ql_dbg(ql_dbg_tgt
, vha
, 0xffff,
415 "qla_target(%d): Response pkt (ABTS_RECV_24XX) "
416 "received, with unknown vp_index %d\n",
417 vha
->vp_idx
, entry
->vp_index
);
421 spin_lock_irqsave(&host
->hw
->hardware_lock
, flags
);
422 qlt_24xx_handle_abts(host
, (struct abts_recv_from_24xx
*)atio
);
424 spin_unlock_irqrestore(&host
->hw
->hardware_lock
, flags
);
428 /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */
431 ql_dbg(ql_dbg_tgt
, vha
, 0xe040,
432 "qla_target(%d): Received unknown ATIO atio "
433 "type %x\n", vha
->vp_idx
, atio
->u
.raw
.entry_type
);
440 void qlt_response_pkt_all_vps(struct scsi_qla_host
*vha
, response_t
*pkt
)
442 switch (pkt
->entry_type
) {
444 ql_dbg(ql_dbg_tgt
, vha
, 0xe073,
445 "qla_target(%d):%s: CRC2 Response pkt\n",
446 vha
->vp_idx
, __func__
);
449 struct ctio7_from_24xx
*entry
= (struct ctio7_from_24xx
*)pkt
;
450 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
452 if (unlikely(!host
)) {
453 ql_dbg(ql_dbg_tgt
, vha
, 0xe041,
454 "qla_target(%d): Response pkt (CTIO_TYPE7) "
455 "received, with unknown vp_index %d\n",
456 vha
->vp_idx
, entry
->vp_index
);
459 qlt_response_pkt(host
, pkt
);
463 case IMMED_NOTIFY_TYPE
:
465 struct scsi_qla_host
*host
= vha
;
466 struct imm_ntfy_from_isp
*entry
=
467 (struct imm_ntfy_from_isp
*)pkt
;
469 host
= qlt_find_host_by_vp_idx(vha
, entry
->u
.isp24
.vp_index
);
470 if (unlikely(!host
)) {
471 ql_dbg(ql_dbg_tgt
, vha
, 0xe042,
472 "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) "
473 "received, with unknown vp_index %d\n",
474 vha
->vp_idx
, entry
->u
.isp24
.vp_index
);
477 qlt_response_pkt(host
, pkt
);
481 case NOTIFY_ACK_TYPE
:
483 struct scsi_qla_host
*host
= vha
;
484 struct nack_to_isp
*entry
= (struct nack_to_isp
*)pkt
;
486 if (0xFF != entry
->u
.isp24
.vp_index
) {
487 host
= qlt_find_host_by_vp_idx(vha
,
488 entry
->u
.isp24
.vp_index
);
489 if (unlikely(!host
)) {
490 ql_dbg(ql_dbg_tgt
, vha
, 0xe043,
491 "qla_target(%d): Response "
492 "pkt (NOTIFY_ACK_TYPE) "
493 "received, with unknown "
494 "vp_index %d\n", vha
->vp_idx
,
495 entry
->u
.isp24
.vp_index
);
499 qlt_response_pkt(host
, pkt
);
505 struct abts_recv_from_24xx
*entry
=
506 (struct abts_recv_from_24xx
*)pkt
;
507 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
509 if (unlikely(!host
)) {
510 ql_dbg(ql_dbg_tgt
, vha
, 0xe044,
511 "qla_target(%d): Response pkt "
512 "(ABTS_RECV_24XX) received, with unknown "
513 "vp_index %d\n", vha
->vp_idx
, entry
->vp_index
);
516 qlt_response_pkt(host
, pkt
);
522 struct abts_resp_to_24xx
*entry
=
523 (struct abts_resp_to_24xx
*)pkt
;
524 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
526 if (unlikely(!host
)) {
527 ql_dbg(ql_dbg_tgt
, vha
, 0xe045,
528 "qla_target(%d): Response pkt "
529 "(ABTS_RECV_24XX) received, with unknown "
530 "vp_index %d\n", vha
->vp_idx
, entry
->vp_index
);
533 qlt_response_pkt(host
, pkt
);
538 qlt_response_pkt(vha
, pkt
);
545 * All qlt_plogi_ack_t operations are protected by hardware_lock
547 static int qla24xx_post_nack_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
548 struct imm_ntfy_from_isp
*ntfy
, int type
)
550 struct qla_work_evt
*e
;
551 e
= qla2x00_alloc_work(vha
, QLA_EVT_NACK
);
553 return QLA_FUNCTION_FAILED
;
555 e
->u
.nack
.fcport
= fcport
;
556 e
->u
.nack
.type
= type
;
557 memcpy(e
->u
.nack
.iocb
, ntfy
, sizeof(struct imm_ntfy_from_isp
));
558 return qla2x00_post_work(vha
, e
);
562 void qla2x00_async_nack_sp_done(void *s
, int res
)
564 struct srb
*sp
= (struct srb
*)s
;
565 struct scsi_qla_host
*vha
= sp
->vha
;
568 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
569 "Async done-%s res %x %8phC type %d\n",
570 sp
->name
, res
, sp
->fcport
->port_name
, sp
->type
);
572 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
573 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
574 sp
->fcport
->chip_reset
= vha
->hw
->chip_reset
;
578 sp
->fcport
->login_gen
++;
579 sp
->fcport
->fw_login_state
= DSC_LS_PLOGI_COMP
;
580 sp
->fcport
->logout_on_delete
= 1;
581 sp
->fcport
->plogi_nack_done_deadline
= jiffies
+ HZ
;
585 sp
->fcport
->fw_login_state
= DSC_LS_PRLI_COMP
;
586 sp
->fcport
->deleted
= 0;
588 if (!sp
->fcport
->login_succ
&&
589 !IS_SW_RESV_ADDR(sp
->fcport
->d_id
)) {
590 sp
->fcport
->login_succ
= 1;
594 if (!IS_IIDMA_CAPABLE(vha
->hw
) ||
595 !vha
->hw
->flags
.gpsc_supported
) {
596 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
597 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
599 sp
->fcport
->port_name
,
602 qla24xx_post_upd_fcport_work(vha
, sp
->fcport
);
604 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
605 "%s %d %8phC post gpsc fcp_cnt %d\n",
607 sp
->fcport
->port_name
,
610 qla24xx_post_gpsc_work(vha
, sp
->fcport
);
616 sp
->fcport
->login_gen
++;
617 sp
->fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
618 qlt_logo_completion_handler(sp
->fcport
, MBS_COMMAND_COMPLETE
);
621 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
626 int qla24xx_async_notify_ack(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
627 struct imm_ntfy_from_isp
*ntfy
, int type
)
629 int rval
= QLA_FUNCTION_FAILED
;
633 fcport
->flags
|= FCF_ASYNC_SENT
;
636 fcport
->fw_login_state
= DSC_LS_PLOGI_PEND
;
640 fcport
->fw_login_state
= DSC_LS_PRLI_PEND
;
645 fcport
->fw_login_state
= DSC_LS_LOGO_PEND
;
650 sp
= qla2x00_get_sp(vha
, fcport
, GFP_ATOMIC
);
657 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
)+2);
659 sp
->u
.iocb_cmd
.u
.nack
.ntfy
= ntfy
;
661 sp
->done
= qla2x00_async_nack_sp_done
;
663 rval
= qla2x00_start_sp(sp
);
664 if (rval
!= QLA_SUCCESS
)
667 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
668 "Async-%s %8phC hndl %x %s\n",
669 sp
->name
, fcport
->port_name
, sp
->handle
, c
);
676 fcport
->flags
&= ~FCF_ASYNC_SENT
;
680 void qla24xx_do_nack_work(struct scsi_qla_host
*vha
, struct qla_work_evt
*e
)
685 switch (e
->u
.nack
.type
) {
687 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
688 t
= qlt_create_sess(vha
, e
->u
.nack
.fcport
, 0);
689 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
691 ql_log(ql_log_info
, vha
, 0xffff,
692 "%s create sess success %p", __func__
, t
);
693 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
694 /* create sess has an extra kref */
695 vha
->hw
->tgt
.tgt_ops
->put_sess(e
->u
.nack
.fcport
);
696 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
700 qla24xx_async_notify_ack(vha
, e
->u
.nack
.fcport
,
701 (struct imm_ntfy_from_isp
*)e
->u
.nack
.iocb
, e
->u
.nack
.type
);
704 void qla24xx_delete_sess_fn(struct work_struct
*work
)
706 fc_port_t
*fcport
= container_of(work
, struct fc_port
, del_work
);
707 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
710 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
712 if (fcport
->se_sess
) {
713 ha
->tgt
.tgt_ops
->shutdown_sess(fcport
);
714 ha
->tgt
.tgt_ops
->put_sess(fcport
);
716 qlt_unreg_sess(fcport
);
718 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
722 * Called from qla2x00_reg_remote_port()
724 void qlt_fc_port_added(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
726 struct qla_hw_data
*ha
= vha
->hw
;
727 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
728 struct fc_port
*sess
= fcport
;
731 if (!vha
->hw
->tgt
.tgt_ops
)
734 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
736 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
740 if (fcport
->disc_state
== DSC_DELETE_PEND
) {
741 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
745 if (!sess
->se_sess
) {
746 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
748 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
749 sess
= qlt_create_sess(vha
, fcport
, false);
750 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
752 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
754 if (fcport
->fw_login_state
== DSC_LS_PRLI_COMP
) {
755 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
759 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
760 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
761 "%s: kref_get fail sess %8phC \n",
762 __func__
, sess
->port_name
);
763 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
767 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04c,
768 "qla_target(%u): %ssession for port %8phC "
769 "(loop ID %d) reappeared\n", vha
->vp_idx
,
770 sess
->local
? "local " : "", sess
->port_name
, sess
->loop_id
);
772 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf007,
773 "Reappeared sess %p\n", sess
);
775 ha
->tgt
.tgt_ops
->update_sess(sess
, fcport
->d_id
,
777 (fcport
->flags
& FCF_CONF_COMP_SUPPORTED
));
780 if (sess
&& sess
->local
) {
781 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04d,
782 "qla_target(%u): local session for "
783 "port %8phC (loop ID %d) became global\n", vha
->vp_idx
,
784 fcport
->port_name
, sess
->loop_id
);
787 ha
->tgt
.tgt_ops
->put_sess(sess
);
788 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
792 * This is a zero-base ref-counting solution, since hardware_lock
793 * guarantees that ref_count is not modified concurrently.
794 * Upon successful return content of iocb is undefined
796 static struct qlt_plogi_ack_t
*
797 qlt_plogi_ack_find_add(struct scsi_qla_host
*vha
, port_id_t
*id
,
798 struct imm_ntfy_from_isp
*iocb
)
800 struct qlt_plogi_ack_t
*pla
;
802 list_for_each_entry(pla
, &vha
->plogi_ack_list
, list
) {
803 if (pla
->id
.b24
== id
->b24
) {
804 qlt_send_term_imm_notif(vha
, &pla
->iocb
, 1);
805 memcpy(&pla
->iocb
, iocb
, sizeof(pla
->iocb
));
810 pla
= kmem_cache_zalloc(qla_tgt_plogi_cachep
, GFP_ATOMIC
);
812 ql_dbg(ql_dbg_async
, vha
, 0x5088,
813 "qla_target(%d): Allocation of plogi_ack failed\n",
818 memcpy(&pla
->iocb
, iocb
, sizeof(pla
->iocb
));
820 list_add_tail(&pla
->list
, &vha
->plogi_ack_list
);
825 void qlt_plogi_ack_unref(struct scsi_qla_host
*vha
,
826 struct qlt_plogi_ack_t
*pla
)
828 struct imm_ntfy_from_isp
*iocb
= &pla
->iocb
;
831 fc_port_t
*fcport
= pla
->fcport
;
833 BUG_ON(!pla
->ref_count
);
839 ql_dbg(ql_dbg_disc
, vha
, 0x5089,
840 "Sending PLOGI ACK to wwn %8phC s_id %02x:%02x:%02x loop_id %#04x"
841 " exch %#x ox_id %#x\n", iocb
->u
.isp24
.port_name
,
842 iocb
->u
.isp24
.port_id
[2], iocb
->u
.isp24
.port_id
[1],
843 iocb
->u
.isp24
.port_id
[0],
844 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
845 iocb
->u
.isp24
.exchange_address
, iocb
->ox_id
);
847 port_id
.b
.domain
= iocb
->u
.isp24
.port_id
[2];
848 port_id
.b
.area
= iocb
->u
.isp24
.port_id
[1];
849 port_id
.b
.al_pa
= iocb
->u
.isp24
.port_id
[0];
850 port_id
.b
.rsvd_1
= 0;
852 loop_id
= le16_to_cpu(iocb
->u
.isp24
.nport_handle
);
854 fcport
->loop_id
= loop_id
;
855 fcport
->d_id
= port_id
;
856 qla24xx_post_nack_work(vha
, fcport
, iocb
, SRB_NACK_PLOGI
);
858 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
859 if (fcport
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] == pla
)
860 fcport
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] = NULL
;
861 if (fcport
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
] == pla
)
862 fcport
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
] = NULL
;
865 list_del(&pla
->list
);
866 kmem_cache_free(qla_tgt_plogi_cachep
, pla
);
870 qlt_plogi_ack_link(struct scsi_qla_host
*vha
, struct qlt_plogi_ack_t
*pla
,
871 struct fc_port
*sess
, enum qlt_plogi_link_t link
)
873 struct imm_ntfy_from_isp
*iocb
= &pla
->iocb
;
874 /* Inc ref_count first because link might already be pointing at pla */
877 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf097,
878 "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC"
879 " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n",
880 sess
, link
, sess
->port_name
,
881 iocb
->u
.isp24
.port_name
, iocb
->u
.isp24
.port_id
[2],
882 iocb
->u
.isp24
.port_id
[1], iocb
->u
.isp24
.port_id
[0],
883 pla
->ref_count
, pla
, link
);
885 if (sess
->plogi_link
[link
])
886 qlt_plogi_ack_unref(vha
, sess
->plogi_link
[link
]);
888 if (link
== QLT_PLOGI_LINK_SAME_WWN
)
891 sess
->plogi_link
[link
] = pla
;
895 /* These fields must be initialized by the caller */
898 * number of cmds dropped while we were waiting for
899 * initiator to ack LOGO initialize to 1 if LOGO is
900 * triggered by a command, otherwise, to 0
904 /* These fields are used by callee */
905 struct list_head list
;
909 qlt_send_first_logo(struct scsi_qla_host
*vha
, qlt_port_logo_t
*logo
)
911 qlt_port_logo_t
*tmp
;
914 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
916 list_for_each_entry(tmp
, &vha
->logo_list
, list
) {
917 if (tmp
->id
.b24
== logo
->id
.b24
) {
918 tmp
->cmd_count
+= logo
->cmd_count
;
919 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
924 list_add_tail(&logo
->list
, &vha
->logo_list
);
926 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
928 res
= qla24xx_els_dcmd_iocb(vha
, ELS_DCMD_LOGO
, logo
->id
);
930 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
931 list_del(&logo
->list
);
932 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
934 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf098,
935 "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n",
936 logo
->id
.b
.domain
, logo
->id
.b
.area
, logo
->id
.b
.al_pa
,
937 logo
->cmd_count
, res
);
940 static void qlt_free_session_done(struct work_struct
*work
)
942 struct fc_port
*sess
= container_of(work
, struct fc_port
,
944 struct qla_tgt
*tgt
= sess
->tgt
;
945 struct scsi_qla_host
*vha
= sess
->vha
;
946 struct qla_hw_data
*ha
= vha
->hw
;
948 bool logout_started
= false;
950 scsi_qla_host_t
*base_vha
;
952 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf084,
953 "%s: se_sess %p / sess %p from port %8phC loop_id %#04x"
954 " s_id %02x:%02x:%02x logout %d keep %d els_logo %d\n",
955 __func__
, sess
->se_sess
, sess
, sess
->port_name
, sess
->loop_id
,
956 sess
->d_id
.b
.domain
, sess
->d_id
.b
.area
, sess
->d_id
.b
.al_pa
,
957 sess
->logout_on_delete
, sess
->keep_nport_handle
,
958 sess
->send_els_logo
);
961 if (!IS_SW_RESV_ADDR(sess
->d_id
)) {
962 if (sess
->send_els_logo
) {
963 qlt_port_logo_t logo
;
965 logo
.id
= sess
->d_id
;
967 qlt_send_first_logo(vha
, &logo
);
970 if (sess
->logout_on_delete
) {
973 rc
= qla2x00_post_async_logout_work(vha
, sess
, NULL
);
974 if (rc
!= QLA_SUCCESS
)
975 ql_log(ql_log_warn
, vha
, 0xf085,
976 "Schedule logo failed sess %p rc %d\n",
979 logout_started
= true;
984 * Release the target session for FC Nexus from fabric module code.
986 if (sess
->se_sess
!= NULL
)
987 ha
->tgt
.tgt_ops
->free_session(sess
);
989 if (logout_started
) {
992 while (!ACCESS_ONCE(sess
->logout_completed
)) {
994 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf086,
995 "%s: waiting for sess %p logout\n",
1002 ql_dbg(ql_dbg_disc
, vha
, 0xf087,
1003 "%s: sess %p logout completed\n",__func__
, sess
);
1006 if (sess
->logo_ack_needed
) {
1007 sess
->logo_ack_needed
= 0;
1008 qla24xx_async_notify_ack(vha
, sess
,
1009 (struct imm_ntfy_from_isp
*)sess
->iocb
, SRB_NACK_LOGO
);
1012 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1013 if (sess
->se_sess
) {
1014 sess
->se_sess
= NULL
;
1015 if (tgt
&& !IS_SW_RESV_ADDR(sess
->d_id
))
1019 sess
->disc_state
= DSC_DELETED
;
1020 sess
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1021 sess
->deleted
= QLA_SESS_DELETED
;
1022 sess
->login_retry
= vha
->hw
->login_retry_count
;
1024 if (sess
->login_succ
&& !IS_SW_RESV_ADDR(sess
->d_id
)) {
1025 vha
->fcport_count
--;
1026 sess
->login_succ
= 0;
1029 if (sess
->chip_reset
!= sess
->vha
->hw
->chip_reset
)
1030 qla2x00_clear_loop_id(sess
);
1032 if (sess
->conflict
) {
1033 sess
->conflict
->login_pause
= 0;
1034 sess
->conflict
= NULL
;
1035 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
1036 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1040 struct qlt_plogi_ack_t
*own
=
1041 sess
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
];
1042 struct qlt_plogi_ack_t
*con
=
1043 sess
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
];
1044 struct imm_ntfy_from_isp
*iocb
;
1048 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf099,
1049 "se_sess %p / sess %p port %8phC is gone,"
1050 " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n",
1051 sess
->se_sess
, sess
, sess
->port_name
,
1052 own
? "releasing own PLOGI" : "no own PLOGI pending",
1053 own
? own
->ref_count
: -1,
1054 iocb
->u
.isp24
.port_name
, con
->ref_count
);
1055 qlt_plogi_ack_unref(vha
, con
);
1056 sess
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
] = NULL
;
1058 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf09a,
1059 "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n",
1060 sess
->se_sess
, sess
, sess
->port_name
,
1061 own
? "releasing own PLOGI" :
1062 "no own PLOGI pending",
1063 own
? own
->ref_count
: -1);
1067 sess
->fw_login_state
= DSC_LS_PLOGI_PEND
;
1068 qlt_plogi_ack_unref(vha
, own
);
1069 sess
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] = NULL
;
1072 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1074 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf001,
1075 "Unregistration of sess %p %8phC finished fcp_cnt %d\n",
1076 sess
, sess
->port_name
, vha
->fcport_count
);
1078 if (tgt
&& (tgt
->sess_count
== 0))
1079 wake_up_all(&tgt
->waitQ
);
1081 if (vha
->fcport_count
== 0)
1082 wake_up_all(&vha
->fcport_waitQ
);
1084 base_vha
= pci_get_drvdata(ha
->pdev
);
1085 if (test_bit(PFLG_DRIVER_REMOVING
, &base_vha
->pci_flags
))
1088 if (!tgt
|| !tgt
->tgt_stop
) {
1089 memset(&ea
, 0, sizeof(ea
));
1090 ea
.event
= FCME_DELETE_DONE
;
1092 qla2x00_fcport_event_handler(vha
, &ea
);
1096 /* ha->tgt.sess_lock supposed to be held on entry */
1097 void qlt_unreg_sess(struct fc_port
*sess
)
1099 struct scsi_qla_host
*vha
= sess
->vha
;
1101 ql_dbg(ql_dbg_disc
, sess
->vha
, 0xffff,
1102 "%s sess %p for deletion %8phC\n",
1103 __func__
, sess
, sess
->port_name
);
1106 vha
->hw
->tgt
.tgt_ops
->clear_nacl_from_fcport_map(sess
);
1108 qla2x00_mark_device_lost(vha
, sess
, 1, 1);
1110 sess
->deleted
= QLA_SESS_DELETION_IN_PROGRESS
;
1111 sess
->disc_state
= DSC_DELETE_PEND
;
1112 sess
->last_rscn_gen
= sess
->rscn_gen
;
1113 sess
->last_login_gen
= sess
->login_gen
;
1115 INIT_WORK(&sess
->free_work
, qlt_free_session_done
);
1116 schedule_work(&sess
->free_work
);
1118 EXPORT_SYMBOL(qlt_unreg_sess
);
1120 static int qlt_reset(struct scsi_qla_host
*vha
, void *iocb
, int mcmd
)
1122 struct qla_hw_data
*ha
= vha
->hw
;
1123 struct fc_port
*sess
= NULL
;
1126 struct imm_ntfy_from_isp
*n
= (struct imm_ntfy_from_isp
*)iocb
;
1127 unsigned long flags
;
1129 loop_id
= le16_to_cpu(n
->u
.isp24
.nport_handle
);
1130 if (loop_id
== 0xFFFF) {
1132 atomic_inc(&vha
->vha_tgt
.qla_tgt
->tgt_global_resets_count
);
1133 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1134 qlt_clear_tgt_db(vha
->vha_tgt
.qla_tgt
);
1135 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1137 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1138 sess
= ha
->tgt
.tgt_ops
->find_sess_by_loop_id(vha
, loop_id
);
1139 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1142 ql_dbg(ql_dbg_tgt
, vha
, 0xe000,
1143 "Using sess for qla_tgt_reset: %p\n", sess
);
1149 ql_dbg(ql_dbg_tgt
, vha
, 0xe047,
1150 "scsi(%ld): resetting (session %p from port %8phC mcmd %x, "
1151 "loop_id %d)\n", vha
->host_no
, sess
, sess
->port_name
,
1154 return qlt_issue_task_mgmt(sess
, 0, mcmd
, iocb
, QLA24XX_MGMT_SEND_NACK
);
1157 static void qla24xx_chk_fcp_state(struct fc_port
*sess
)
1159 if (sess
->chip_reset
!= sess
->vha
->hw
->chip_reset
) {
1160 sess
->logout_on_delete
= 0;
1161 sess
->logo_ack_needed
= 0;
1162 sess
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1163 sess
->scan_state
= 0;
1167 /* ha->tgt.sess_lock supposed to be held on entry */
1168 void qlt_schedule_sess_for_deletion(struct fc_port
*sess
,
1171 struct qla_tgt
*tgt
= sess
->tgt
;
1173 if (sess
->disc_state
== DSC_DELETE_PEND
)
1176 if (sess
->disc_state
== DSC_DELETED
) {
1177 if (tgt
&& tgt
->tgt_stop
&& (tgt
->sess_count
== 0))
1178 wake_up_all(&tgt
->waitQ
);
1179 if (sess
->vha
->fcport_count
== 0)
1180 wake_up_all(&sess
->vha
->fcport_waitQ
);
1182 if (!sess
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] &&
1183 !sess
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
])
1187 sess
->disc_state
= DSC_DELETE_PEND
;
1189 if (sess
->deleted
== QLA_SESS_DELETED
)
1190 sess
->logout_on_delete
= 0;
1192 sess
->deleted
= QLA_SESS_DELETION_IN_PROGRESS
;
1193 qla24xx_chk_fcp_state(sess
);
1195 ql_dbg(ql_dbg_tgt
, sess
->vha
, 0xe001,
1196 "Scheduling sess %p for deletion\n", sess
);
1198 schedule_work(&sess
->del_work
);
1201 void qlt_schedule_sess_for_deletion_lock(struct fc_port
*sess
)
1203 unsigned long flags
;
1204 struct qla_hw_data
*ha
= sess
->vha
->hw
;
1205 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1206 qlt_schedule_sess_for_deletion(sess
, 1);
1207 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1210 /* ha->tgt.sess_lock supposed to be held on entry */
1211 static void qlt_clear_tgt_db(struct qla_tgt
*tgt
)
1213 struct fc_port
*sess
;
1214 scsi_qla_host_t
*vha
= tgt
->vha
;
1216 list_for_each_entry(sess
, &vha
->vp_fcports
, list
) {
1218 qlt_schedule_sess_for_deletion(sess
, 1);
1221 /* At this point tgt could be already dead */
1224 static int qla24xx_get_loop_id(struct scsi_qla_host
*vha
, const uint8_t *s_id
,
1227 struct qla_hw_data
*ha
= vha
->hw
;
1228 dma_addr_t gid_list_dma
;
1229 struct gid_list_info
*gid_list
;
1234 gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, qla2x00_gid_list_size(ha
),
1235 &gid_list_dma
, GFP_KERNEL
);
1237 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf044,
1238 "qla_target(%d): DMA Alloc failed of %u\n",
1239 vha
->vp_idx
, qla2x00_gid_list_size(ha
));
1243 /* Get list of logged in devices */
1244 rc
= qla24xx_gidlist_wait(vha
, gid_list
, gid_list_dma
, &entries
);
1245 if (rc
!= QLA_SUCCESS
) {
1246 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf045,
1247 "qla_target(%d): get_id_list() failed: %x\n",
1250 goto out_free_id_list
;
1253 id_iter
= (char *)gid_list
;
1255 for (i
= 0; i
< entries
; i
++) {
1256 struct gid_list_info
*gid
= (struct gid_list_info
*)id_iter
;
1257 if ((gid
->al_pa
== s_id
[2]) &&
1258 (gid
->area
== s_id
[1]) &&
1259 (gid
->domain
== s_id
[0])) {
1260 *loop_id
= le16_to_cpu(gid
->loop_id
);
1264 id_iter
+= ha
->gid_list_info_size
;
1268 dma_free_coherent(&ha
->pdev
->dev
, qla2x00_gid_list_size(ha
),
1269 gid_list
, gid_list_dma
);
1274 * Adds an extra ref to allow to drop hw lock after adding sess to the list.
1275 * Caller must put it.
1277 static struct fc_port
*qlt_create_sess(
1278 struct scsi_qla_host
*vha
,
1282 struct qla_hw_data
*ha
= vha
->hw
;
1283 struct fc_port
*sess
= fcport
;
1284 unsigned long flags
;
1286 if (vha
->vha_tgt
.qla_tgt
->tgt_stop
)
1289 if (fcport
->se_sess
) {
1290 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
1291 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1292 "%s: kref_get_unless_zero failed for %8phC\n",
1293 __func__
, sess
->port_name
);
1298 sess
->tgt
= vha
->vha_tgt
.qla_tgt
;
1299 sess
->local
= local
;
1302 * Under normal circumstances we want to logout from firmware when
1303 * session eventually ends and release corresponding nport handle.
1304 * In the exception cases (e.g. when new PLOGI is waiting) corresponding
1305 * code will adjust these flags as necessary.
1307 sess
->logout_on_delete
= 1;
1308 sess
->keep_nport_handle
= 0;
1309 sess
->logout_completed
= 0;
1311 if (ha
->tgt
.tgt_ops
->check_initiator_node_acl(vha
,
1312 &fcport
->port_name
[0], sess
) < 0) {
1313 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xffff,
1314 "(%d) %8phC check_initiator_node_acl failed\n",
1315 vha
->vp_idx
, fcport
->port_name
);
1318 kref_init(&fcport
->sess_kref
);
1320 * Take an extra reference to ->sess_kref here to handle
1321 * fc_port access across ->tgt.sess_lock reaquire.
1323 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
1324 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1325 "%s: kref_get_unless_zero failed for %8phC\n",
1326 __func__
, sess
->port_name
);
1330 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1331 if (!IS_SW_RESV_ADDR(sess
->d_id
))
1332 vha
->vha_tgt
.qla_tgt
->sess_count
++;
1334 qlt_do_generation_tick(vha
, &sess
->generation
);
1335 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1338 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf006,
1339 "Adding sess %p se_sess %p to tgt %p sess_count %d\n",
1340 sess
, sess
->se_sess
, vha
->vha_tgt
.qla_tgt
,
1341 vha
->vha_tgt
.qla_tgt
->sess_count
);
1343 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04b,
1344 "qla_target(%d): %ssession for wwn %8phC (loop_id %d, "
1345 "s_id %x:%x:%x, confirmed completion %ssupported) added\n",
1346 vha
->vp_idx
, local
? "local " : "", fcport
->port_name
,
1347 fcport
->loop_id
, sess
->d_id
.b
.domain
, sess
->d_id
.b
.area
,
1348 sess
->d_id
.b
.al_pa
, sess
->conf_compl_supported
? "" : "not ");
1354 * max_gen - specifies maximum session generation
1355 * at which this deletion requestion is still valid
1358 qlt_fc_port_deleted(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, int max_gen
)
1360 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
1361 struct fc_port
*sess
= fcport
;
1362 unsigned long flags
;
1364 if (!vha
->hw
->tgt
.tgt_ops
)
1370 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1371 if (tgt
->tgt_stop
) {
1372 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1375 if (!sess
->se_sess
) {
1376 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1380 if (max_gen
- sess
->generation
< 0) {
1381 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1382 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf092,
1383 "Ignoring stale deletion request for se_sess %p / sess %p"
1384 " for port %8phC, req_gen %d, sess_gen %d\n",
1385 sess
->se_sess
, sess
, sess
->port_name
, max_gen
,
1390 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf008, "qla_tgt_fc_port_deleted %p", sess
);
1393 qlt_schedule_sess_for_deletion(sess
, false);
1394 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1397 static inline int test_tgt_sess_count(struct qla_tgt
*tgt
)
1399 struct qla_hw_data
*ha
= tgt
->ha
;
1400 unsigned long flags
;
1403 * We need to protect against race, when tgt is freed before or
1406 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1407 ql_dbg(ql_dbg_tgt
, tgt
->vha
, 0xe002,
1408 "tgt %p, sess_count=%d\n",
1409 tgt
, tgt
->sess_count
);
1410 res
= (tgt
->sess_count
== 0);
1411 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1416 /* Called by tcm_qla2xxx configfs code */
1417 int qlt_stop_phase1(struct qla_tgt
*tgt
)
1419 struct scsi_qla_host
*vha
= tgt
->vha
;
1420 struct qla_hw_data
*ha
= tgt
->ha
;
1421 unsigned long flags
;
1423 mutex_lock(&qla_tgt_mutex
);
1424 if (!vha
->fc_vport
) {
1425 struct Scsi_Host
*sh
= vha
->host
;
1426 struct fc_host_attrs
*fc_host
= shost_to_fc_host(sh
);
1429 spin_lock_irqsave(sh
->host_lock
, flags
);
1430 npiv_vports
= (fc_host
->npiv_vports_inuse
);
1431 spin_unlock_irqrestore(sh
->host_lock
, flags
);
1434 mutex_unlock(&qla_tgt_mutex
);
1438 if (tgt
->tgt_stop
|| tgt
->tgt_stopped
) {
1439 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04e,
1440 "Already in tgt->tgt_stop or tgt_stopped state\n");
1441 mutex_unlock(&qla_tgt_mutex
);
1445 ql_dbg(ql_dbg_tgt
, vha
, 0xe003, "Stopping target for host %ld(%p)\n",
1448 * Mutex needed to sync with qla_tgt_fc_port_[added,deleted].
1449 * Lock is needed, because we still can get an incoming packet.
1451 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
1452 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1454 qlt_clear_tgt_db(tgt
);
1455 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1456 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
1457 mutex_unlock(&qla_tgt_mutex
);
1459 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf009,
1460 "Waiting for sess works (tgt %p)", tgt
);
1461 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
1462 while (!list_empty(&tgt
->sess_works_list
)) {
1463 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
1464 flush_scheduled_work();
1465 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
1467 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
1469 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00a,
1470 "Waiting for tgt %p: sess_count=%d\n", tgt
, tgt
->sess_count
);
1472 wait_event(tgt
->waitQ
, test_tgt_sess_count(tgt
));
1475 if (!ha
->flags
.host_shutting_down
&&
1476 (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)))
1477 qlt_disable_vha(vha
);
1479 /* Wait for sessions to clear out (just in case) */
1480 wait_event(tgt
->waitQ
, test_tgt_sess_count(tgt
));
1483 EXPORT_SYMBOL(qlt_stop_phase1
);
1485 /* Called by tcm_qla2xxx configfs code */
1486 void qlt_stop_phase2(struct qla_tgt
*tgt
)
1488 struct qla_hw_data
*ha
= tgt
->ha
;
1489 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
1490 unsigned long flags
;
1492 if (tgt
->tgt_stopped
) {
1493 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04f,
1494 "Already in tgt->tgt_stopped state\n");
1499 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00b,
1500 "Waiting for %d IRQ commands to complete (tgt %p)",
1501 tgt
->irq_cmd_count
, tgt
);
1503 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
1504 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1505 while ((tgt
->irq_cmd_count
!= 0) || (tgt
->atio_irq_cmd_count
!= 0)) {
1506 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1508 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1511 tgt
->tgt_stopped
= 1;
1512 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1513 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
1515 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00c, "Stop of tgt %p finished",
1518 EXPORT_SYMBOL(qlt_stop_phase2
);
1520 /* Called from qlt_remove_target() -> qla2x00_remove_one() */
1521 static void qlt_release(struct qla_tgt
*tgt
)
1523 scsi_qla_host_t
*vha
= tgt
->vha
;
1525 if ((vha
->vha_tgt
.qla_tgt
!= NULL
) && !tgt
->tgt_stopped
)
1526 qlt_stop_phase2(tgt
);
1528 vha
->vha_tgt
.qla_tgt
= NULL
;
1530 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00d,
1531 "Release of tgt %p finished\n", tgt
);
1536 /* ha->hardware_lock supposed to be held on entry */
1537 static int qlt_sched_sess_work(struct qla_tgt
*tgt
, int type
,
1538 const void *param
, unsigned int param_size
)
1540 struct qla_tgt_sess_work_param
*prm
;
1541 unsigned long flags
;
1543 prm
= kzalloc(sizeof(*prm
), GFP_ATOMIC
);
1545 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf050,
1546 "qla_target(%d): Unable to create session "
1547 "work, command will be refused", 0);
1551 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf00e,
1552 "Scheduling work (type %d, prm %p)"
1553 " to find session for param %p (size %d, tgt %p)\n",
1554 type
, prm
, param
, param_size
, tgt
);
1557 memcpy(&prm
->tm_iocb
, param
, param_size
);
1559 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
1560 list_add_tail(&prm
->sess_works_list_entry
, &tgt
->sess_works_list
);
1561 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
1563 schedule_work(&tgt
->sess_work
);
1569 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1571 static void qlt_send_notify_ack(struct scsi_qla_host
*vha
,
1572 struct imm_ntfy_from_isp
*ntfy
,
1573 uint32_t add_flags
, uint16_t resp_code
, int resp_code_valid
,
1574 uint16_t srr_flags
, uint16_t srr_reject_code
, uint8_t srr_explan
)
1576 struct qla_hw_data
*ha
= vha
->hw
;
1578 struct nack_to_isp
*nack
;
1580 if (!ha
->flags
.fw_started
)
1583 ql_dbg(ql_dbg_tgt
, vha
, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha
);
1585 /* Send marker if required */
1586 if (qlt_issue_marker(vha
, 1) != QLA_SUCCESS
)
1589 pkt
= (request_t
*)qla2x00_alloc_iocbs(vha
, NULL
);
1591 ql_dbg(ql_dbg_tgt
, vha
, 0xe049,
1592 "qla_target(%d): %s failed: unable to allocate "
1593 "request packet\n", vha
->vp_idx
, __func__
);
1597 if (vha
->vha_tgt
.qla_tgt
!= NULL
)
1598 vha
->vha_tgt
.qla_tgt
->notify_ack_expected
++;
1600 pkt
->entry_type
= NOTIFY_ACK_TYPE
;
1601 pkt
->entry_count
= 1;
1603 nack
= (struct nack_to_isp
*)pkt
;
1604 nack
->ox_id
= ntfy
->ox_id
;
1606 nack
->u
.isp24
.handle
= QLA_TGT_SKIP_HANDLE
;
1607 nack
->u
.isp24
.nport_handle
= ntfy
->u
.isp24
.nport_handle
;
1608 if (le16_to_cpu(ntfy
->u
.isp24
.status
) == IMM_NTFY_ELS
) {
1609 nack
->u
.isp24
.flags
= ntfy
->u
.isp24
.flags
&
1610 cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB
);
1612 nack
->u
.isp24
.srr_rx_id
= ntfy
->u
.isp24
.srr_rx_id
;
1613 nack
->u
.isp24
.status
= ntfy
->u
.isp24
.status
;
1614 nack
->u
.isp24
.status_subcode
= ntfy
->u
.isp24
.status_subcode
;
1615 nack
->u
.isp24
.fw_handle
= ntfy
->u
.isp24
.fw_handle
;
1616 nack
->u
.isp24
.exchange_address
= ntfy
->u
.isp24
.exchange_address
;
1617 nack
->u
.isp24
.srr_rel_offs
= ntfy
->u
.isp24
.srr_rel_offs
;
1618 nack
->u
.isp24
.srr_ui
= ntfy
->u
.isp24
.srr_ui
;
1619 nack
->u
.isp24
.srr_flags
= cpu_to_le16(srr_flags
);
1620 nack
->u
.isp24
.srr_reject_code
= srr_reject_code
;
1621 nack
->u
.isp24
.srr_reject_code_expl
= srr_explan
;
1622 nack
->u
.isp24
.vp_index
= ntfy
->u
.isp24
.vp_index
;
1624 ql_dbg(ql_dbg_tgt
, vha
, 0xe005,
1625 "qla_target(%d): Sending 24xx Notify Ack %d\n",
1626 vha
->vp_idx
, nack
->u
.isp24
.status
);
1628 /* Memory Barrier */
1630 qla2x00_start_iocbs(vha
, vha
->req
);
1634 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1636 static void qlt_24xx_send_abts_resp(struct scsi_qla_host
*vha
,
1637 struct abts_recv_from_24xx
*abts
, uint32_t status
,
1640 struct qla_hw_data
*ha
= vha
->hw
;
1641 struct abts_resp_to_24xx
*resp
;
1645 ql_dbg(ql_dbg_tgt
, vha
, 0xe006,
1646 "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n",
1649 /* Send marker if required */
1650 if (qlt_issue_marker(vha
, 1) != QLA_SUCCESS
)
1653 resp
= (struct abts_resp_to_24xx
*)qla2x00_alloc_iocbs_ready(vha
, NULL
);
1655 ql_dbg(ql_dbg_tgt
, vha
, 0xe04a,
1656 "qla_target(%d): %s failed: unable to allocate "
1657 "request packet", vha
->vp_idx
, __func__
);
1661 resp
->entry_type
= ABTS_RESP_24XX
;
1662 resp
->entry_count
= 1;
1663 resp
->nport_handle
= abts
->nport_handle
;
1664 resp
->vp_index
= vha
->vp_idx
;
1665 resp
->sof_type
= abts
->sof_type
;
1666 resp
->exchange_address
= abts
->exchange_address
;
1667 resp
->fcp_hdr_le
= abts
->fcp_hdr_le
;
1668 f_ctl
= cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP
|
1669 F_CTL_LAST_SEQ
| F_CTL_END_SEQ
|
1670 F_CTL_SEQ_INITIATIVE
);
1671 p
= (uint8_t *)&f_ctl
;
1672 resp
->fcp_hdr_le
.f_ctl
[0] = *p
++;
1673 resp
->fcp_hdr_le
.f_ctl
[1] = *p
++;
1674 resp
->fcp_hdr_le
.f_ctl
[2] = *p
;
1676 resp
->fcp_hdr_le
.d_id
[0] = abts
->fcp_hdr_le
.d_id
[0];
1677 resp
->fcp_hdr_le
.d_id
[1] = abts
->fcp_hdr_le
.d_id
[1];
1678 resp
->fcp_hdr_le
.d_id
[2] = abts
->fcp_hdr_le
.d_id
[2];
1679 resp
->fcp_hdr_le
.s_id
[0] = abts
->fcp_hdr_le
.s_id
[0];
1680 resp
->fcp_hdr_le
.s_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1681 resp
->fcp_hdr_le
.s_id
[2] = abts
->fcp_hdr_le
.s_id
[2];
1683 resp
->fcp_hdr_le
.d_id
[0] = abts
->fcp_hdr_le
.s_id
[0];
1684 resp
->fcp_hdr_le
.d_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1685 resp
->fcp_hdr_le
.d_id
[2] = abts
->fcp_hdr_le
.s_id
[2];
1686 resp
->fcp_hdr_le
.s_id
[0] = abts
->fcp_hdr_le
.d_id
[0];
1687 resp
->fcp_hdr_le
.s_id
[1] = abts
->fcp_hdr_le
.d_id
[1];
1688 resp
->fcp_hdr_le
.s_id
[2] = abts
->fcp_hdr_le
.d_id
[2];
1690 resp
->exchange_addr_to_abort
= abts
->exchange_addr_to_abort
;
1691 if (status
== FCP_TMF_CMPL
) {
1692 resp
->fcp_hdr_le
.r_ctl
= R_CTL_BASIC_LINK_SERV
| R_CTL_B_ACC
;
1693 resp
->payload
.ba_acct
.seq_id_valid
= SEQ_ID_INVALID
;
1694 resp
->payload
.ba_acct
.low_seq_cnt
= 0x0000;
1695 resp
->payload
.ba_acct
.high_seq_cnt
= 0xFFFF;
1696 resp
->payload
.ba_acct
.ox_id
= abts
->fcp_hdr_le
.ox_id
;
1697 resp
->payload
.ba_acct
.rx_id
= abts
->fcp_hdr_le
.rx_id
;
1699 resp
->fcp_hdr_le
.r_ctl
= R_CTL_BASIC_LINK_SERV
| R_CTL_B_RJT
;
1700 resp
->payload
.ba_rjt
.reason_code
=
1701 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM
;
1702 /* Other bytes are zero */
1705 vha
->vha_tgt
.qla_tgt
->abts_resp_expected
++;
1707 /* Memory Barrier */
1709 qla2x00_start_iocbs(vha
, vha
->req
);
1713 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1715 static void qlt_24xx_retry_term_exchange(struct scsi_qla_host
*vha
,
1716 struct abts_resp_from_24xx_fw
*entry
)
1718 struct ctio7_to_24xx
*ctio
;
1720 ql_dbg(ql_dbg_tgt
, vha
, 0xe007,
1721 "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha
->hw
);
1722 /* Send marker if required */
1723 if (qlt_issue_marker(vha
, 1) != QLA_SUCCESS
)
1726 ctio
= (struct ctio7_to_24xx
*)qla2x00_alloc_iocbs_ready(vha
, NULL
);
1728 ql_dbg(ql_dbg_tgt
, vha
, 0xe04b,
1729 "qla_target(%d): %s failed: unable to allocate "
1730 "request packet\n", vha
->vp_idx
, __func__
);
1735 * We've got on entrance firmware's response on by us generated
1736 * ABTS response. So, in it ID fields are reversed.
1739 ctio
->entry_type
= CTIO_TYPE7
;
1740 ctio
->entry_count
= 1;
1741 ctio
->nport_handle
= entry
->nport_handle
;
1742 ctio
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
1743 ctio
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
1744 ctio
->vp_index
= vha
->vp_idx
;
1745 ctio
->initiator_id
[0] = entry
->fcp_hdr_le
.d_id
[0];
1746 ctio
->initiator_id
[1] = entry
->fcp_hdr_le
.d_id
[1];
1747 ctio
->initiator_id
[2] = entry
->fcp_hdr_le
.d_id
[2];
1748 ctio
->exchange_addr
= entry
->exchange_addr_to_abort
;
1749 ctio
->u
.status1
.flags
= cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
|
1750 CTIO7_FLAGS_TERMINATE
);
1751 ctio
->u
.status1
.ox_id
= cpu_to_le16(entry
->fcp_hdr_le
.ox_id
);
1753 /* Memory Barrier */
1755 qla2x00_start_iocbs(vha
, vha
->req
);
1757 qlt_24xx_send_abts_resp(vha
, (struct abts_recv_from_24xx
*)entry
,
1758 FCP_TMF_CMPL
, true);
1761 static int abort_cmd_for_tag(struct scsi_qla_host
*vha
, uint32_t tag
)
1763 struct qla_tgt_sess_op
*op
;
1764 struct qla_tgt_cmd
*cmd
;
1766 spin_lock(&vha
->cmd_list_lock
);
1768 list_for_each_entry(op
, &vha
->qla_sess_op_cmd_list
, cmd_list
) {
1769 if (tag
== op
->atio
.u
.isp24
.exchange_addr
) {
1771 spin_unlock(&vha
->cmd_list_lock
);
1776 list_for_each_entry(op
, &vha
->unknown_atio_list
, cmd_list
) {
1777 if (tag
== op
->atio
.u
.isp24
.exchange_addr
) {
1779 spin_unlock(&vha
->cmd_list_lock
);
1784 list_for_each_entry(cmd
, &vha
->qla_cmd_list
, cmd_list
) {
1785 if (tag
== cmd
->atio
.u
.isp24
.exchange_addr
) {
1787 spin_unlock(&vha
->cmd_list_lock
);
1792 spin_unlock(&vha
->cmd_list_lock
);
1796 /* drop cmds for the given lun
1797 * XXX only looks for cmds on the port through which lun reset was recieved
1798 * XXX does not go through the list of other port (which may have cmds
1801 static void abort_cmds_for_lun(struct scsi_qla_host
*vha
,
1802 uint32_t lun
, uint8_t *s_id
)
1804 struct qla_tgt_sess_op
*op
;
1805 struct qla_tgt_cmd
*cmd
;
1808 key
= sid_to_key(s_id
);
1809 spin_lock(&vha
->cmd_list_lock
);
1810 list_for_each_entry(op
, &vha
->qla_sess_op_cmd_list
, cmd_list
) {
1814 op_key
= sid_to_key(op
->atio
.u
.isp24
.fcp_hdr
.s_id
);
1815 op_lun
= scsilun_to_int(
1816 (struct scsi_lun
*)&op
->atio
.u
.isp24
.fcp_cmnd
.lun
);
1817 if (op_key
== key
&& op_lun
== lun
)
1821 list_for_each_entry(op
, &vha
->unknown_atio_list
, cmd_list
) {
1825 op_key
= sid_to_key(op
->atio
.u
.isp24
.fcp_hdr
.s_id
);
1826 op_lun
= scsilun_to_int(
1827 (struct scsi_lun
*)&op
->atio
.u
.isp24
.fcp_cmnd
.lun
);
1828 if (op_key
== key
&& op_lun
== lun
)
1832 list_for_each_entry(cmd
, &vha
->qla_cmd_list
, cmd_list
) {
1836 cmd_key
= sid_to_key(cmd
->atio
.u
.isp24
.fcp_hdr
.s_id
);
1837 cmd_lun
= scsilun_to_int(
1838 (struct scsi_lun
*)&cmd
->atio
.u
.isp24
.fcp_cmnd
.lun
);
1839 if (cmd_key
== key
&& cmd_lun
== lun
)
1842 spin_unlock(&vha
->cmd_list_lock
);
1845 /* ha->hardware_lock supposed to be held on entry */
1846 static int __qlt_24xx_handle_abts(struct scsi_qla_host
*vha
,
1847 struct abts_recv_from_24xx
*abts
, struct fc_port
*sess
)
1849 struct qla_hw_data
*ha
= vha
->hw
;
1850 struct se_session
*se_sess
= sess
->se_sess
;
1851 struct qla_tgt_mgmt_cmd
*mcmd
;
1852 struct se_cmd
*se_cmd
;
1855 bool found_lun
= false;
1856 unsigned long flags
;
1858 spin_lock_irqsave(&se_sess
->sess_cmd_lock
, flags
);
1859 list_for_each_entry(se_cmd
, &se_sess
->sess_cmd_list
, se_cmd_list
) {
1860 struct qla_tgt_cmd
*cmd
=
1861 container_of(se_cmd
, struct qla_tgt_cmd
, se_cmd
);
1862 if (se_cmd
->tag
== abts
->exchange_addr_to_abort
) {
1863 lun
= cmd
->unpacked_lun
;
1868 spin_unlock_irqrestore(&se_sess
->sess_cmd_lock
, flags
);
1870 /* cmd not in LIO lists, look in qla list */
1872 if (abort_cmd_for_tag(vha
, abts
->exchange_addr_to_abort
)) {
1873 /* send TASK_ABORT response immediately */
1874 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_CMPL
, false);
1877 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf081,
1878 "unable to find cmd in driver or LIO for tag 0x%x\n",
1879 abts
->exchange_addr_to_abort
);
1884 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00f,
1885 "qla_target(%d): task abort (tag=%d)\n",
1886 vha
->vp_idx
, abts
->exchange_addr_to_abort
);
1888 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
1890 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf051,
1891 "qla_target(%d): %s: Allocation of ABORT cmd failed",
1892 vha
->vp_idx
, __func__
);
1895 memset(mcmd
, 0, sizeof(*mcmd
));
1898 memcpy(&mcmd
->orig_iocb
.abts
, abts
, sizeof(mcmd
->orig_iocb
.abts
));
1899 mcmd
->reset_count
= vha
->hw
->chip_reset
;
1900 mcmd
->tmr_func
= QLA_TGT_ABTS
;
1902 rc
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, lun
, mcmd
->tmr_func
,
1903 abts
->exchange_addr_to_abort
);
1905 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf052,
1906 "qla_target(%d): tgt_ops->handle_tmr()"
1907 " failed: %d", vha
->vp_idx
, rc
);
1908 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
1916 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1918 static void qlt_24xx_handle_abts(struct scsi_qla_host
*vha
,
1919 struct abts_recv_from_24xx
*abts
)
1921 struct qla_hw_data
*ha
= vha
->hw
;
1922 struct fc_port
*sess
;
1923 uint32_t tag
= abts
->exchange_addr_to_abort
;
1926 unsigned long flags
;
1928 if (le32_to_cpu(abts
->fcp_hdr_le
.parameter
) & ABTS_PARAM_ABORT_SEQ
) {
1929 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf053,
1930 "qla_target(%d): ABTS: Abort Sequence not "
1931 "supported\n", vha
->vp_idx
);
1932 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
, false);
1936 if (tag
== ATIO_EXCHANGE_ADDRESS_UNKNOWN
) {
1937 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf010,
1938 "qla_target(%d): ABTS: Unknown Exchange "
1939 "Address received\n", vha
->vp_idx
);
1940 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
, false);
1944 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf011,
1945 "qla_target(%d): task abort (s_id=%x:%x:%x, "
1946 "tag=%d, param=%x)\n", vha
->vp_idx
, abts
->fcp_hdr_le
.s_id
[2],
1947 abts
->fcp_hdr_le
.s_id
[1], abts
->fcp_hdr_le
.s_id
[0], tag
,
1948 le32_to_cpu(abts
->fcp_hdr_le
.parameter
));
1950 s_id
[0] = abts
->fcp_hdr_le
.s_id
[2];
1951 s_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1952 s_id
[2] = abts
->fcp_hdr_le
.s_id
[0];
1954 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1955 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, s_id
);
1957 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf012,
1958 "qla_target(%d): task abort for non-existant session\n",
1960 rc
= qlt_sched_sess_work(vha
->vha_tgt
.qla_tgt
,
1961 QLA_TGT_SESS_WORK_ABORT
, abts
, sizeof(*abts
));
1963 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1966 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
,
1971 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1974 if (sess
->deleted
) {
1975 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
, false);
1979 rc
= __qlt_24xx_handle_abts(vha
, abts
, sess
);
1981 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf054,
1982 "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n",
1984 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
, false);
1990 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1992 static void qlt_24xx_send_task_mgmt_ctio(struct scsi_qla_host
*ha
,
1993 struct qla_tgt_mgmt_cmd
*mcmd
, uint32_t resp_code
)
1995 struct atio_from_isp
*atio
= &mcmd
->orig_iocb
.atio
;
1996 struct ctio7_to_24xx
*ctio
;
1999 ql_dbg(ql_dbg_tgt
, ha
, 0xe008,
2000 "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n",
2001 ha
, atio
, resp_code
);
2003 /* Send marker if required */
2004 if (qlt_issue_marker(ha
, 1) != QLA_SUCCESS
)
2007 ctio
= (struct ctio7_to_24xx
*)qla2x00_alloc_iocbs(ha
, NULL
);
2009 ql_dbg(ql_dbg_tgt
, ha
, 0xe04c,
2010 "qla_target(%d): %s failed: unable to allocate "
2011 "request packet\n", ha
->vp_idx
, __func__
);
2015 ctio
->entry_type
= CTIO_TYPE7
;
2016 ctio
->entry_count
= 1;
2017 ctio
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
2018 ctio
->nport_handle
= mcmd
->sess
->loop_id
;
2019 ctio
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
2020 ctio
->vp_index
= ha
->vp_idx
;
2021 ctio
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
2022 ctio
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
2023 ctio
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
2024 ctio
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2025 ctio
->u
.status1
.flags
= (atio
->u
.isp24
.attr
<< 9) |
2026 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
| CTIO7_FLAGS_SEND_STATUS
);
2027 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2028 ctio
->u
.status1
.ox_id
= cpu_to_le16(temp
);
2029 ctio
->u
.status1
.scsi_status
=
2030 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID
);
2031 ctio
->u
.status1
.response_len
= cpu_to_le16(8);
2032 ctio
->u
.status1
.sense_data
[0] = resp_code
;
2034 /* Memory Barrier */
2036 qla2x00_start_iocbs(ha
, ha
->req
);
2039 void qlt_free_mcmd(struct qla_tgt_mgmt_cmd
*mcmd
)
2041 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
2043 EXPORT_SYMBOL(qlt_free_mcmd
);
2046 * ha->hardware_lock supposed to be held on entry. Might drop it, then
2049 void qlt_send_resp_ctio(scsi_qla_host_t
*vha
, struct qla_tgt_cmd
*cmd
,
2050 uint8_t scsi_status
, uint8_t sense_key
, uint8_t asc
, uint8_t ascq
)
2052 struct atio_from_isp
*atio
= &cmd
->atio
;
2053 struct ctio7_to_24xx
*ctio
;
2056 ql_dbg(ql_dbg_tgt_dif
, vha
, 0x3066,
2057 "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, "
2058 "sense_key=%02x, asc=%02x, ascq=%02x",
2059 vha
, atio
, scsi_status
, sense_key
, asc
, ascq
);
2061 ctio
= (struct ctio7_to_24xx
*)qla2x00_alloc_iocbs(vha
, NULL
);
2063 ql_dbg(ql_dbg_async
, vha
, 0x3067,
2064 "qla2x00t(%ld): %s failed: unable to allocate request packet",
2065 vha
->host_no
, __func__
);
2069 ctio
->entry_type
= CTIO_TYPE7
;
2070 ctio
->entry_count
= 1;
2071 ctio
->handle
= QLA_TGT_SKIP_HANDLE
;
2072 ctio
->nport_handle
= cmd
->sess
->loop_id
;
2073 ctio
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
2074 ctio
->vp_index
= vha
->vp_idx
;
2075 ctio
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
2076 ctio
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
2077 ctio
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
2078 ctio
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2079 ctio
->u
.status1
.flags
= (atio
->u
.isp24
.attr
<< 9) |
2080 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
| CTIO7_FLAGS_SEND_STATUS
);
2081 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2082 ctio
->u
.status1
.ox_id
= cpu_to_le16(temp
);
2083 ctio
->u
.status1
.scsi_status
=
2084 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID
| scsi_status
);
2085 ctio
->u
.status1
.response_len
= cpu_to_le16(18);
2086 ctio
->u
.status1
.residual
= cpu_to_le32(get_datalen_for_atio(atio
));
2088 if (ctio
->u
.status1
.residual
!= 0)
2089 ctio
->u
.status1
.scsi_status
|=
2090 cpu_to_le16(SS_RESIDUAL_UNDER
);
2092 /* Response code and sense key */
2093 put_unaligned_le32(((0x70 << 24) | (sense_key
<< 8)),
2094 (&ctio
->u
.status1
.sense_data
)[0]);
2095 /* Additional sense length */
2096 put_unaligned_le32(0x0a, (&ctio
->u
.status1
.sense_data
)[1]);
2098 put_unaligned_le32(((asc
<< 24) | (ascq
<< 16)),
2099 (&ctio
->u
.status1
.sense_data
)[3]);
2101 /* Memory Barrier */
2104 qla2x00_start_iocbs(vha
, vha
->req
);
2109 /* callback from target fabric module code */
2110 void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd
*mcmd
)
2112 struct scsi_qla_host
*vha
= mcmd
->sess
->vha
;
2113 struct qla_hw_data
*ha
= vha
->hw
;
2114 unsigned long flags
;
2116 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf013,
2117 "TM response mcmd (%p) status %#x state %#x",
2118 mcmd
, mcmd
->fc_tm_rsp
, mcmd
->flags
);
2120 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2122 if (!vha
->flags
.online
|| mcmd
->reset_count
!= ha
->chip_reset
) {
2124 * Either the port is not online or this request was from
2125 * previous life, just abort the processing.
2127 ql_dbg(ql_dbg_async
, vha
, 0xe100,
2128 "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n",
2129 vha
->flags
.online
, qla2x00_reset_active(vha
),
2130 mcmd
->reset_count
, ha
->chip_reset
);
2131 ha
->tgt
.tgt_ops
->free_mcmd(mcmd
);
2132 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2136 if (mcmd
->flags
== QLA24XX_MGMT_SEND_NACK
) {
2137 if (mcmd
->orig_iocb
.imm_ntfy
.u
.isp24
.status_subcode
==
2139 mcmd
->orig_iocb
.imm_ntfy
.u
.isp24
.status_subcode
==
2141 mcmd
->orig_iocb
.imm_ntfy
.u
.isp24
.status_subcode
==
2143 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
2144 "TM response logo %phC status %#x state %#x",
2145 mcmd
->sess
->port_name
, mcmd
->fc_tm_rsp
,
2147 qlt_schedule_sess_for_deletion_lock(mcmd
->sess
);
2149 qlt_send_notify_ack(vha
, &mcmd
->orig_iocb
.imm_ntfy
,
2153 if (mcmd
->orig_iocb
.atio
.u
.raw
.entry_type
== ABTS_RECV_24XX
)
2154 qlt_24xx_send_abts_resp(vha
, &mcmd
->orig_iocb
.abts
,
2155 mcmd
->fc_tm_rsp
, false);
2157 qlt_24xx_send_task_mgmt_ctio(vha
, mcmd
,
2161 * Make the callback for ->free_mcmd() to queue_work() and invoke
2162 * target_put_sess_cmd() to drop cmd_kref to 1. The final
2163 * target_put_sess_cmd() call will be made from TFO->check_stop_free()
2164 * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd
2165 * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() ->
2166 * qlt_xmit_tm_rsp() returns here..
2168 ha
->tgt
.tgt_ops
->free_mcmd(mcmd
);
2169 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2171 EXPORT_SYMBOL(qlt_xmit_tm_rsp
);
2174 static int qlt_pci_map_calc_cnt(struct qla_tgt_prm
*prm
)
2176 struct qla_tgt_cmd
*cmd
= prm
->cmd
;
2178 BUG_ON(cmd
->sg_cnt
== 0);
2180 prm
->sg
= (struct scatterlist
*)cmd
->sg
;
2181 prm
->seg_cnt
= pci_map_sg(prm
->tgt
->ha
->pdev
, cmd
->sg
,
2182 cmd
->sg_cnt
, cmd
->dma_data_direction
);
2183 if (unlikely(prm
->seg_cnt
== 0))
2186 prm
->cmd
->sg_mapped
= 1;
2188 if (cmd
->se_cmd
.prot_op
== TARGET_PROT_NORMAL
) {
2190 * If greater than four sg entries then we need to allocate
2191 * the continuation entries
2193 if (prm
->seg_cnt
> prm
->tgt
->datasegs_per_cmd
)
2194 prm
->req_cnt
+= DIV_ROUND_UP(prm
->seg_cnt
-
2195 prm
->tgt
->datasegs_per_cmd
,
2196 prm
->tgt
->datasegs_per_cont
);
2199 if ((cmd
->se_cmd
.prot_op
== TARGET_PROT_DIN_INSERT
) ||
2200 (cmd
->se_cmd
.prot_op
== TARGET_PROT_DOUT_STRIP
)) {
2201 prm
->seg_cnt
= DIV_ROUND_UP(cmd
->bufflen
, cmd
->blk_sz
);
2202 prm
->tot_dsds
= prm
->seg_cnt
;
2204 prm
->tot_dsds
= prm
->seg_cnt
;
2206 if (cmd
->prot_sg_cnt
) {
2207 prm
->prot_sg
= cmd
->prot_sg
;
2208 prm
->prot_seg_cnt
= pci_map_sg(prm
->tgt
->ha
->pdev
,
2209 cmd
->prot_sg
, cmd
->prot_sg_cnt
,
2210 cmd
->dma_data_direction
);
2211 if (unlikely(prm
->prot_seg_cnt
== 0))
2214 if ((cmd
->se_cmd
.prot_op
== TARGET_PROT_DIN_INSERT
) ||
2215 (cmd
->se_cmd
.prot_op
== TARGET_PROT_DOUT_STRIP
)) {
2216 /* Dif Bundling not support here */
2217 prm
->prot_seg_cnt
= DIV_ROUND_UP(cmd
->bufflen
,
2219 prm
->tot_dsds
+= prm
->prot_seg_cnt
;
2221 prm
->tot_dsds
+= prm
->prot_seg_cnt
;
2228 ql_dbg(ql_dbg_tgt
, prm
->cmd
->vha
, 0xe04d,
2229 "qla_target(%d): PCI mapping failed: sg_cnt=%d",
2230 0, prm
->cmd
->sg_cnt
);
2234 static void qlt_unmap_sg(struct scsi_qla_host
*vha
, struct qla_tgt_cmd
*cmd
)
2236 struct qla_hw_data
*ha
= vha
->hw
;
2238 if (!cmd
->sg_mapped
)
2241 pci_unmap_sg(ha
->pdev
, cmd
->sg
, cmd
->sg_cnt
, cmd
->dma_data_direction
);
2244 if (cmd
->prot_sg_cnt
)
2245 pci_unmap_sg(ha
->pdev
, cmd
->prot_sg
, cmd
->prot_sg_cnt
,
2246 cmd
->dma_data_direction
);
2251 if (cmd
->ctx_dsd_alloced
)
2252 qla2x00_clean_dsd_pool(ha
, cmd
->ctx
);
2254 dma_pool_free(ha
->dl_dma_pool
, cmd
->ctx
, cmd
->ctx
->crc_ctx_dma
);
2257 static int qlt_check_reserve_free_req(struct scsi_qla_host
*vha
,
2260 uint32_t cnt
, cnt_in
;
2262 if (vha
->req
->cnt
< (req_cnt
+ 2)) {
2263 cnt
= (uint16_t)RD_REG_DWORD(vha
->req
->req_q_out
);
2264 cnt_in
= (uint16_t)RD_REG_DWORD(vha
->req
->req_q_in
);
2266 if (vha
->req
->ring_index
< cnt
)
2267 vha
->req
->cnt
= cnt
- vha
->req
->ring_index
;
2269 vha
->req
->cnt
= vha
->req
->length
-
2270 (vha
->req
->ring_index
- cnt
);
2272 if (unlikely(vha
->req
->cnt
< (req_cnt
+ 2))) {
2273 ql_dbg(ql_dbg_io
, vha
, 0x305a,
2274 "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",
2275 vha
->vp_idx
, vha
->req
->ring_index
,
2276 vha
->req
->cnt
, req_cnt
, cnt
, cnt_in
,
2282 vha
->req
->cnt
-= req_cnt
;
2288 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2290 static inline void *qlt_get_req_pkt(struct scsi_qla_host
*vha
)
2292 /* Adjust ring index. */
2293 vha
->req
->ring_index
++;
2294 if (vha
->req
->ring_index
== vha
->req
->length
) {
2295 vha
->req
->ring_index
= 0;
2296 vha
->req
->ring_ptr
= vha
->req
->ring
;
2298 vha
->req
->ring_ptr
++;
2300 return (cont_entry_t
*)vha
->req
->ring_ptr
;
2303 /* ha->hardware_lock supposed to be held on entry */
2304 static inline uint32_t qlt_make_handle(struct scsi_qla_host
*vha
)
2306 struct qla_hw_data
*ha
= vha
->hw
;
2309 h
= ha
->tgt
.current_handle
;
2310 /* always increment cmd handle */
2313 if (h
> DEFAULT_OUTSTANDING_COMMANDS
)
2314 h
= 1; /* 0 is QLA_TGT_NULL_HANDLE */
2315 if (h
== ha
->tgt
.current_handle
) {
2316 ql_dbg(ql_dbg_io
, vha
, 0x305b,
2317 "qla_target(%d): Ran out of "
2318 "empty cmd slots in ha %p\n", vha
->vp_idx
, ha
);
2319 h
= QLA_TGT_NULL_HANDLE
;
2322 } while ((h
== QLA_TGT_NULL_HANDLE
) ||
2323 (h
== QLA_TGT_SKIP_HANDLE
) ||
2324 (ha
->tgt
.cmds
[h
-1] != NULL
));
2326 if (h
!= QLA_TGT_NULL_HANDLE
)
2327 ha
->tgt
.current_handle
= h
;
2332 /* ha->hardware_lock supposed to be held on entry */
2333 static int qlt_24xx_build_ctio_pkt(struct qla_tgt_prm
*prm
,
2334 struct scsi_qla_host
*vha
)
2337 struct ctio7_to_24xx
*pkt
;
2338 struct qla_hw_data
*ha
= vha
->hw
;
2339 struct atio_from_isp
*atio
= &prm
->cmd
->atio
;
2342 pkt
= (struct ctio7_to_24xx
*)vha
->req
->ring_ptr
;
2344 memset(pkt
, 0, sizeof(*pkt
));
2346 pkt
->entry_type
= CTIO_TYPE7
;
2347 pkt
->entry_count
= (uint8_t)prm
->req_cnt
;
2348 pkt
->vp_index
= vha
->vp_idx
;
2350 h
= qlt_make_handle(vha
);
2351 if (unlikely(h
== QLA_TGT_NULL_HANDLE
)) {
2353 * CTIO type 7 from the firmware doesn't provide a way to
2354 * know the initiator's LOOP ID, hence we can't find
2355 * the session and, so, the command.
2359 ha
->tgt
.cmds
[h
- 1] = prm
->cmd
;
2361 pkt
->handle
= h
| CTIO_COMPLETION_HANDLE_MARK
;
2362 pkt
->nport_handle
= prm
->cmd
->loop_id
;
2363 pkt
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
2364 pkt
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
2365 pkt
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
2366 pkt
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
2367 pkt
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2368 pkt
->u
.status0
.flags
|= (atio
->u
.isp24
.attr
<< 9);
2369 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2370 pkt
->u
.status0
.ox_id
= cpu_to_le16(temp
);
2371 pkt
->u
.status0
.relative_offset
= cpu_to_le32(prm
->cmd
->offset
);
2377 * ha->hardware_lock supposed to be held on entry. We have already made sure
2378 * that there is sufficient amount of request entries to not drop it.
2380 static void qlt_load_cont_data_segments(struct qla_tgt_prm
*prm
,
2381 struct scsi_qla_host
*vha
)
2384 uint32_t *dword_ptr
;
2385 int enable_64bit_addressing
= prm
->tgt
->tgt_enable_64bit_addr
;
2387 /* Build continuation packets */
2388 while (prm
->seg_cnt
> 0) {
2389 cont_a64_entry_t
*cont_pkt64
=
2390 (cont_a64_entry_t
*)qlt_get_req_pkt(vha
);
2393 * Make sure that from cont_pkt64 none of
2394 * 64-bit specific fields used for 32-bit
2395 * addressing. Cast to (cont_entry_t *) for
2399 memset(cont_pkt64
, 0, sizeof(*cont_pkt64
));
2401 cont_pkt64
->entry_count
= 1;
2402 cont_pkt64
->sys_define
= 0;
2404 if (enable_64bit_addressing
) {
2405 cont_pkt64
->entry_type
= CONTINUE_A64_TYPE
;
2407 (uint32_t *)&cont_pkt64
->dseg_0_address
;
2409 cont_pkt64
->entry_type
= CONTINUE_TYPE
;
2411 (uint32_t *)&((cont_entry_t
*)
2412 cont_pkt64
)->dseg_0_address
;
2415 /* Load continuation entry data segments */
2417 cnt
< prm
->tgt
->datasegs_per_cont
&& prm
->seg_cnt
;
2418 cnt
++, prm
->seg_cnt
--) {
2420 cpu_to_le32(pci_dma_lo32
2421 (sg_dma_address(prm
->sg
)));
2422 if (enable_64bit_addressing
) {
2424 cpu_to_le32(pci_dma_hi32
2428 *dword_ptr
++ = cpu_to_le32(sg_dma_len(prm
->sg
));
2430 prm
->sg
= sg_next(prm
->sg
);
2436 * ha->hardware_lock supposed to be held on entry. We have already made sure
2437 * that there is sufficient amount of request entries to not drop it.
2439 static void qlt_load_data_segments(struct qla_tgt_prm
*prm
,
2440 struct scsi_qla_host
*vha
)
2443 uint32_t *dword_ptr
;
2444 int enable_64bit_addressing
= prm
->tgt
->tgt_enable_64bit_addr
;
2445 struct ctio7_to_24xx
*pkt24
= (struct ctio7_to_24xx
*)prm
->pkt
;
2447 pkt24
->u
.status0
.transfer_length
= cpu_to_le32(prm
->cmd
->bufflen
);
2449 /* Setup packet address segment pointer */
2450 dword_ptr
= pkt24
->u
.status0
.dseg_0_address
;
2452 /* Set total data segment count */
2454 pkt24
->dseg_count
= cpu_to_le16(prm
->seg_cnt
);
2456 if (prm
->seg_cnt
== 0) {
2457 /* No data transfer */
2463 /* If scatter gather */
2465 /* Load command entry data segments */
2467 (cnt
< prm
->tgt
->datasegs_per_cmd
) && prm
->seg_cnt
;
2468 cnt
++, prm
->seg_cnt
--) {
2470 cpu_to_le32(pci_dma_lo32(sg_dma_address(prm
->sg
)));
2471 if (enable_64bit_addressing
) {
2473 cpu_to_le32(pci_dma_hi32(
2474 sg_dma_address(prm
->sg
)));
2476 *dword_ptr
++ = cpu_to_le32(sg_dma_len(prm
->sg
));
2478 prm
->sg
= sg_next(prm
->sg
);
2481 qlt_load_cont_data_segments(prm
, vha
);
2484 static inline int qlt_has_data(struct qla_tgt_cmd
*cmd
)
2486 return cmd
->bufflen
> 0;
2489 static void qlt_print_dif_err(struct qla_tgt_prm
*prm
)
2491 struct qla_tgt_cmd
*cmd
;
2492 struct scsi_qla_host
*vha
;
2494 /* asc 0x10=dif error */
2495 if (prm
->sense_buffer
&& (prm
->sense_buffer
[12] == 0x10)) {
2499 switch (prm
->sense_buffer
[13]) {
2501 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xffff,
2502 "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2503 "se_cmd=%p tag[%x]",
2504 cmd
->lba
, cmd
->lba
, cmd
->num_blks
, &cmd
->se_cmd
,
2505 cmd
->atio
.u
.isp24
.exchange_addr
);
2508 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xffff,
2509 "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2510 "se_cmd=%p tag[%x]",
2511 cmd
->lba
, cmd
->lba
, cmd
->num_blks
, &cmd
->se_cmd
,
2512 cmd
->atio
.u
.isp24
.exchange_addr
);
2515 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xffff,
2516 "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2517 "se_cmd=%p tag[%x]",
2518 cmd
->lba
, cmd
->lba
, cmd
->num_blks
, &cmd
->se_cmd
,
2519 cmd
->atio
.u
.isp24
.exchange_addr
);
2522 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xffff,
2523 "BE detected Dif ERR: lba[%llx|%lld] len[%x] "
2524 "se_cmd=%p tag[%x]",
2525 cmd
->lba
, cmd
->lba
, cmd
->num_blks
, &cmd
->se_cmd
,
2526 cmd
->atio
.u
.isp24
.exchange_addr
);
2529 ql_dump_buffer(ql_dbg_tgt_dif
, vha
, 0xffff, cmd
->cdb
, 16);
2534 * Called without ha->hardware_lock held
2536 static int qlt_pre_xmit_response(struct qla_tgt_cmd
*cmd
,
2537 struct qla_tgt_prm
*prm
, int xmit_type
, uint8_t scsi_status
,
2538 uint32_t *full_req_cnt
)
2540 struct qla_tgt
*tgt
= cmd
->tgt
;
2541 struct scsi_qla_host
*vha
= tgt
->vha
;
2542 struct qla_hw_data
*ha
= vha
->hw
;
2543 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
2547 prm
->rq_result
= scsi_status
;
2548 prm
->sense_buffer
= &cmd
->sense_buffer
[0];
2549 prm
->sense_buffer_len
= TRANSPORT_SENSE_BUFFER
;
2553 prm
->add_status_pkt
= 0;
2555 /* Send marker if required */
2556 if (qlt_issue_marker(vha
, 0) != QLA_SUCCESS
)
2559 if ((xmit_type
& QLA_TGT_XMIT_DATA
) && qlt_has_data(cmd
)) {
2560 if (qlt_pci_map_calc_cnt(prm
) != 0)
2564 *full_req_cnt
= prm
->req_cnt
;
2566 if (se_cmd
->se_cmd_flags
& SCF_UNDERFLOW_BIT
) {
2567 prm
->residual
= se_cmd
->residual_count
;
2568 ql_dbg(ql_dbg_io
+ ql_dbg_verbose
, vha
, 0x305c,
2569 "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2570 prm
->residual
, se_cmd
->tag
,
2571 se_cmd
->t_task_cdb
? se_cmd
->t_task_cdb
[0] : 0,
2572 cmd
->bufflen
, prm
->rq_result
);
2573 prm
->rq_result
|= SS_RESIDUAL_UNDER
;
2574 } else if (se_cmd
->se_cmd_flags
& SCF_OVERFLOW_BIT
) {
2575 prm
->residual
= se_cmd
->residual_count
;
2576 ql_dbg(ql_dbg_io
, vha
, 0x305d,
2577 "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2578 prm
->residual
, se_cmd
->tag
, se_cmd
->t_task_cdb
?
2579 se_cmd
->t_task_cdb
[0] : 0, cmd
->bufflen
, prm
->rq_result
);
2580 prm
->rq_result
|= SS_RESIDUAL_OVER
;
2583 if (xmit_type
& QLA_TGT_XMIT_STATUS
) {
2585 * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be
2586 * ignored in *xmit_response() below
2588 if (qlt_has_data(cmd
)) {
2589 if (QLA_TGT_SENSE_VALID(prm
->sense_buffer
) ||
2590 (IS_FWI2_CAPABLE(ha
) &&
2591 (prm
->rq_result
!= 0))) {
2592 prm
->add_status_pkt
= 1;
2601 static inline int qlt_need_explicit_conf(struct qla_hw_data
*ha
,
2602 struct qla_tgt_cmd
*cmd
, int sending_sense
)
2604 if (ha
->tgt
.enable_class_2
)
2608 return cmd
->conf_compl_supported
;
2610 return ha
->tgt
.enable_explicit_conf
&&
2611 cmd
->conf_compl_supported
;
2614 static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx
*ctio
,
2615 struct qla_tgt_prm
*prm
)
2617 prm
->sense_buffer_len
= min_t(uint32_t, prm
->sense_buffer_len
,
2618 (uint32_t)sizeof(ctio
->u
.status1
.sense_data
));
2619 ctio
->u
.status0
.flags
|= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS
);
2620 if (qlt_need_explicit_conf(prm
->tgt
->ha
, prm
->cmd
, 0)) {
2621 ctio
->u
.status0
.flags
|= cpu_to_le16(
2622 CTIO7_FLAGS_EXPLICIT_CONFORM
|
2623 CTIO7_FLAGS_CONFORM_REQ
);
2625 ctio
->u
.status0
.residual
= cpu_to_le32(prm
->residual
);
2626 ctio
->u
.status0
.scsi_status
= cpu_to_le16(prm
->rq_result
);
2627 if (QLA_TGT_SENSE_VALID(prm
->sense_buffer
)) {
2630 if (qlt_need_explicit_conf(prm
->tgt
->ha
, prm
->cmd
, 1)) {
2631 if ((prm
->rq_result
& SS_SCSI_STATUS_BYTE
) != 0) {
2632 ql_dbg(ql_dbg_tgt
, prm
->cmd
->vha
, 0xe017,
2633 "Skipping EXPLICIT_CONFORM and "
2634 "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ "
2635 "non GOOD status\n");
2636 goto skip_explict_conf
;
2638 ctio
->u
.status1
.flags
|= cpu_to_le16(
2639 CTIO7_FLAGS_EXPLICIT_CONFORM
|
2640 CTIO7_FLAGS_CONFORM_REQ
);
2643 ctio
->u
.status1
.flags
&=
2644 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0
);
2645 ctio
->u
.status1
.flags
|=
2646 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
);
2647 ctio
->u
.status1
.scsi_status
|=
2648 cpu_to_le16(SS_SENSE_LEN_VALID
);
2649 ctio
->u
.status1
.sense_length
=
2650 cpu_to_le16(prm
->sense_buffer_len
);
2651 for (i
= 0; i
< prm
->sense_buffer_len
/4; i
++)
2652 ((uint32_t *)ctio
->u
.status1
.sense_data
)[i
] =
2653 cpu_to_be32(((uint32_t *)prm
->sense_buffer
)[i
]);
2655 qlt_print_dif_err(prm
);
2658 ctio
->u
.status1
.flags
&=
2659 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0
);
2660 ctio
->u
.status1
.flags
|=
2661 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
);
2662 ctio
->u
.status1
.sense_length
= 0;
2663 memset(ctio
->u
.status1
.sense_data
, 0,
2664 sizeof(ctio
->u
.status1
.sense_data
));
2667 /* Sense with len > 24, is it possible ??? */
2671 qlt_hba_err_chk_enabled(struct se_cmd
*se_cmd
)
2673 switch (se_cmd
->prot_op
) {
2674 case TARGET_PROT_DOUT_INSERT
:
2675 case TARGET_PROT_DIN_STRIP
:
2676 if (ql2xenablehba_err_chk
>= 1)
2679 case TARGET_PROT_DOUT_PASS
:
2680 case TARGET_PROT_DIN_PASS
:
2681 if (ql2xenablehba_err_chk
>= 2)
2684 case TARGET_PROT_DIN_INSERT
:
2685 case TARGET_PROT_DOUT_STRIP
:
2694 qla_tgt_ref_mask_check(struct se_cmd
*se_cmd
)
2696 switch (se_cmd
->prot_op
) {
2697 case TARGET_PROT_DIN_INSERT
:
2698 case TARGET_PROT_DOUT_INSERT
:
2699 case TARGET_PROT_DIN_STRIP
:
2700 case TARGET_PROT_DOUT_STRIP
:
2701 case TARGET_PROT_DIN_PASS
:
2702 case TARGET_PROT_DOUT_PASS
:
2711 * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command
2714 qla_tgt_set_dif_tags(struct qla_tgt_cmd
*cmd
, struct crc_context
*ctx
,
2715 uint16_t *pfw_prot_opts
)
2717 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
2718 uint32_t lba
= 0xffffffff & se_cmd
->t_task_lba
;
2719 scsi_qla_host_t
*vha
= cmd
->tgt
->vha
;
2720 struct qla_hw_data
*ha
= vha
->hw
;
2724 * wait till Mode Sense/Select cmd, modepage Ah, subpage 2
2725 * have been immplemented by TCM, before AppTag is avail.
2726 * Look for modesense_handlers[]
2729 ctx
->app_tag_mask
[0] = 0x0;
2730 ctx
->app_tag_mask
[1] = 0x0;
2732 if (IS_PI_UNINIT_CAPABLE(ha
)) {
2733 if ((se_cmd
->prot_type
== TARGET_DIF_TYPE1_PROT
) ||
2734 (se_cmd
->prot_type
== TARGET_DIF_TYPE2_PROT
))
2735 *pfw_prot_opts
|= PO_DIS_VALD_APP_ESC
;
2736 else if (se_cmd
->prot_type
== TARGET_DIF_TYPE3_PROT
)
2737 *pfw_prot_opts
|= PO_DIS_VALD_APP_REF_ESC
;
2740 t32
= ha
->tgt
.tgt_ops
->get_dif_tags(cmd
, pfw_prot_opts
);
2742 switch (se_cmd
->prot_type
) {
2743 case TARGET_DIF_TYPE0_PROT
:
2745 * No check for ql2xenablehba_err_chk, as it
2746 * would be an I/O error if hba tag generation
2749 ctx
->ref_tag
= cpu_to_le32(lba
);
2750 /* enable ALL bytes of the ref tag */
2751 ctx
->ref_tag_mask
[0] = 0xff;
2752 ctx
->ref_tag_mask
[1] = 0xff;
2753 ctx
->ref_tag_mask
[2] = 0xff;
2754 ctx
->ref_tag_mask
[3] = 0xff;
2756 case TARGET_DIF_TYPE1_PROT
:
2758 * For TYPE 1 protection: 16 bit GUARD tag, 32 bit
2759 * REF tag, and 16 bit app tag.
2761 ctx
->ref_tag
= cpu_to_le32(lba
);
2762 if (!qla_tgt_ref_mask_check(se_cmd
) ||
2763 !(ha
->tgt
.tgt_ops
->chk_dif_tags(t32
))) {
2764 *pfw_prot_opts
|= PO_DIS_REF_TAG_VALD
;
2767 /* enable ALL bytes of the ref tag */
2768 ctx
->ref_tag_mask
[0] = 0xff;
2769 ctx
->ref_tag_mask
[1] = 0xff;
2770 ctx
->ref_tag_mask
[2] = 0xff;
2771 ctx
->ref_tag_mask
[3] = 0xff;
2773 case TARGET_DIF_TYPE2_PROT
:
2775 * For TYPE 2 protection: 16 bit GUARD + 32 bit REF
2776 * tag has to match LBA in CDB + N
2778 ctx
->ref_tag
= cpu_to_le32(lba
);
2779 if (!qla_tgt_ref_mask_check(se_cmd
) ||
2780 !(ha
->tgt
.tgt_ops
->chk_dif_tags(t32
))) {
2781 *pfw_prot_opts
|= PO_DIS_REF_TAG_VALD
;
2784 /* enable ALL bytes of the ref tag */
2785 ctx
->ref_tag_mask
[0] = 0xff;
2786 ctx
->ref_tag_mask
[1] = 0xff;
2787 ctx
->ref_tag_mask
[2] = 0xff;
2788 ctx
->ref_tag_mask
[3] = 0xff;
2790 case TARGET_DIF_TYPE3_PROT
:
2791 /* For TYPE 3 protection: 16 bit GUARD only */
2792 *pfw_prot_opts
|= PO_DIS_REF_TAG_VALD
;
2793 ctx
->ref_tag_mask
[0] = ctx
->ref_tag_mask
[1] =
2794 ctx
->ref_tag_mask
[2] = ctx
->ref_tag_mask
[3] = 0x00;
2800 qlt_build_ctio_crc2_pkt(struct qla_tgt_prm
*prm
, scsi_qla_host_t
*vha
)
2803 uint32_t transfer_length
= 0;
2804 uint32_t data_bytes
;
2806 uint8_t bundling
= 1;
2808 struct crc_context
*crc_ctx_pkt
= NULL
;
2809 struct qla_hw_data
*ha
;
2810 struct ctio_crc2_to_fw
*pkt
;
2811 dma_addr_t crc_ctx_dma
;
2812 uint16_t fw_prot_opts
= 0;
2813 struct qla_tgt_cmd
*cmd
= prm
->cmd
;
2814 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
2816 struct atio_from_isp
*atio
= &prm
->cmd
->atio
;
2817 struct qla_tc_param tc
;
2822 pkt
= (struct ctio_crc2_to_fw
*)vha
->req
->ring_ptr
;
2824 memset(pkt
, 0, sizeof(*pkt
));
2826 ql_dbg(ql_dbg_tgt
, vha
, 0xe071,
2827 "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n",
2828 vha
->vp_idx
, __func__
, se_cmd
, se_cmd
->prot_op
,
2829 prm
->prot_sg
, prm
->prot_seg_cnt
, se_cmd
->t_task_lba
);
2831 if ((se_cmd
->prot_op
== TARGET_PROT_DIN_INSERT
) ||
2832 (se_cmd
->prot_op
== TARGET_PROT_DOUT_STRIP
))
2835 /* Compute dif len and adjust data len to incude protection */
2836 data_bytes
= cmd
->bufflen
;
2837 dif_bytes
= (data_bytes
/ cmd
->blk_sz
) * 8;
2839 switch (se_cmd
->prot_op
) {
2840 case TARGET_PROT_DIN_INSERT
:
2841 case TARGET_PROT_DOUT_STRIP
:
2842 transfer_length
= data_bytes
;
2843 if (cmd
->prot_sg_cnt
)
2844 data_bytes
+= dif_bytes
;
2846 case TARGET_PROT_DIN_STRIP
:
2847 case TARGET_PROT_DOUT_INSERT
:
2848 case TARGET_PROT_DIN_PASS
:
2849 case TARGET_PROT_DOUT_PASS
:
2850 transfer_length
= data_bytes
+ dif_bytes
;
2857 if (!qlt_hba_err_chk_enabled(se_cmd
))
2858 fw_prot_opts
|= 0x10; /* Disable Guard tag checking */
2859 /* HBA error checking enabled */
2860 else if (IS_PI_UNINIT_CAPABLE(ha
)) {
2861 if ((se_cmd
->prot_type
== TARGET_DIF_TYPE1_PROT
) ||
2862 (se_cmd
->prot_type
== TARGET_DIF_TYPE2_PROT
))
2863 fw_prot_opts
|= PO_DIS_VALD_APP_ESC
;
2864 else if (se_cmd
->prot_type
== TARGET_DIF_TYPE3_PROT
)
2865 fw_prot_opts
|= PO_DIS_VALD_APP_REF_ESC
;
2868 switch (se_cmd
->prot_op
) {
2869 case TARGET_PROT_DIN_INSERT
:
2870 case TARGET_PROT_DOUT_INSERT
:
2871 fw_prot_opts
|= PO_MODE_DIF_INSERT
;
2873 case TARGET_PROT_DIN_STRIP
:
2874 case TARGET_PROT_DOUT_STRIP
:
2875 fw_prot_opts
|= PO_MODE_DIF_REMOVE
;
2877 case TARGET_PROT_DIN_PASS
:
2878 case TARGET_PROT_DOUT_PASS
:
2879 fw_prot_opts
|= PO_MODE_DIF_PASS
;
2880 /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */
2882 default:/* Normal Request */
2883 fw_prot_opts
|= PO_MODE_DIF_PASS
;
2888 /* Update entry type to indicate Command Type CRC_2 IOCB */
2889 pkt
->entry_type
= CTIO_CRC2
;
2890 pkt
->entry_count
= 1;
2891 pkt
->vp_index
= vha
->vp_idx
;
2893 h
= qlt_make_handle(vha
);
2894 if (unlikely(h
== QLA_TGT_NULL_HANDLE
)) {
2896 * CTIO type 7 from the firmware doesn't provide a way to
2897 * know the initiator's LOOP ID, hence we can't find
2898 * the session and, so, the command.
2902 ha
->tgt
.cmds
[h
-1] = prm
->cmd
;
2904 pkt
->handle
= h
| CTIO_COMPLETION_HANDLE_MARK
;
2905 pkt
->nport_handle
= cpu_to_le16(prm
->cmd
->loop_id
);
2906 pkt
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
2907 pkt
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
2908 pkt
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
2909 pkt
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
2910 pkt
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2912 /* silence compile warning */
2913 t16
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2914 pkt
->ox_id
= cpu_to_le16(t16
);
2916 t16
= (atio
->u
.isp24
.attr
<< 9);
2917 pkt
->flags
|= cpu_to_le16(t16
);
2918 pkt
->relative_offset
= cpu_to_le32(prm
->cmd
->offset
);
2920 /* Set transfer direction */
2921 if (cmd
->dma_data_direction
== DMA_TO_DEVICE
)
2922 pkt
->flags
= cpu_to_le16(CTIO7_FLAGS_DATA_IN
);
2923 else if (cmd
->dma_data_direction
== DMA_FROM_DEVICE
)
2924 pkt
->flags
= cpu_to_le16(CTIO7_FLAGS_DATA_OUT
);
2926 pkt
->dseg_count
= prm
->tot_dsds
;
2927 /* Fibre channel byte count */
2928 pkt
->transfer_length
= cpu_to_le32(transfer_length
);
2930 /* ----- CRC context -------- */
2932 /* Allocate CRC context from global pool */
2933 crc_ctx_pkt
= cmd
->ctx
=
2934 dma_pool_alloc(ha
->dl_dma_pool
, GFP_ATOMIC
, &crc_ctx_dma
);
2937 goto crc_queuing_error
;
2939 /* Zero out CTX area. */
2940 clr_ptr
= (uint8_t *)crc_ctx_pkt
;
2941 memset(clr_ptr
, 0, sizeof(*crc_ctx_pkt
));
2943 crc_ctx_pkt
->crc_ctx_dma
= crc_ctx_dma
;
2944 INIT_LIST_HEAD(&crc_ctx_pkt
->dsd_list
);
2947 crc_ctx_pkt
->handle
= pkt
->handle
;
2949 qla_tgt_set_dif_tags(cmd
, crc_ctx_pkt
, &fw_prot_opts
);
2951 pkt
->crc_context_address
[0] = cpu_to_le32(LSD(crc_ctx_dma
));
2952 pkt
->crc_context_address
[1] = cpu_to_le32(MSD(crc_ctx_dma
));
2953 pkt
->crc_context_len
= CRC_CONTEXT_LEN_FW
;
2956 cur_dsd
= (uint32_t *) &crc_ctx_pkt
->u
.nobundling
.data_address
;
2959 * Configure Bundling if we need to fetch interlaving
2960 * protection PCI accesses
2962 fw_prot_opts
|= PO_ENABLE_DIF_BUNDLING
;
2963 crc_ctx_pkt
->u
.bundling
.dif_byte_count
= cpu_to_le32(dif_bytes
);
2964 crc_ctx_pkt
->u
.bundling
.dseg_count
=
2965 cpu_to_le16(prm
->tot_dsds
- prm
->prot_seg_cnt
);
2966 cur_dsd
= (uint32_t *) &crc_ctx_pkt
->u
.bundling
.data_address
;
2969 /* Finish the common fields of CRC pkt */
2970 crc_ctx_pkt
->blk_size
= cpu_to_le16(cmd
->blk_sz
);
2971 crc_ctx_pkt
->prot_opts
= cpu_to_le16(fw_prot_opts
);
2972 crc_ctx_pkt
->byte_count
= cpu_to_le32(data_bytes
);
2973 crc_ctx_pkt
->guard_seed
= cpu_to_le16(0);
2975 memset((uint8_t *)&tc
, 0 , sizeof(tc
));
2977 tc
.blk_sz
= cmd
->blk_sz
;
2978 tc
.bufflen
= cmd
->bufflen
;
2980 tc
.prot_sg
= cmd
->prot_sg
;
2981 tc
.ctx
= crc_ctx_pkt
;
2982 tc
.ctx_dsd_alloced
= &cmd
->ctx_dsd_alloced
;
2984 /* Walks data segments */
2985 pkt
->flags
|= cpu_to_le16(CTIO7_FLAGS_DSD_PTR
);
2987 if (!bundling
&& prm
->prot_seg_cnt
) {
2988 if (qla24xx_walk_and_build_sglist_no_difb(ha
, NULL
, cur_dsd
,
2989 prm
->tot_dsds
, &tc
))
2990 goto crc_queuing_error
;
2991 } else if (qla24xx_walk_and_build_sglist(ha
, NULL
, cur_dsd
,
2992 (prm
->tot_dsds
- prm
->prot_seg_cnt
), &tc
))
2993 goto crc_queuing_error
;
2995 if (bundling
&& prm
->prot_seg_cnt
) {
2996 /* Walks dif segments */
2997 pkt
->add_flags
|= CTIO_CRC2_AF_DIF_DSD_ENA
;
2999 cur_dsd
= (uint32_t *) &crc_ctx_pkt
->u
.bundling
.dif_address
;
3000 if (qla24xx_walk_and_build_prot_sglist(ha
, NULL
, cur_dsd
,
3001 prm
->prot_seg_cnt
, &tc
))
3002 goto crc_queuing_error
;
3007 /* Cleanup will be performed by the caller */
3008 vha
->hw
->tgt
.cmds
[h
- 1] = NULL
;
3010 return QLA_FUNCTION_FAILED
;
3014 * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and *
3015 * QLA_TGT_XMIT_STATUS for >= 24xx silicon
3017 int qlt_xmit_response(struct qla_tgt_cmd
*cmd
, int xmit_type
,
3018 uint8_t scsi_status
)
3020 struct scsi_qla_host
*vha
= cmd
->vha
;
3021 struct qla_hw_data
*ha
= vha
->hw
;
3022 struct ctio7_to_24xx
*pkt
;
3023 struct qla_tgt_prm prm
;
3024 uint32_t full_req_cnt
= 0;
3025 unsigned long flags
= 0;
3028 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3029 if (cmd
->sess
&& cmd
->sess
->deleted
) {
3030 cmd
->state
= QLA_TGT_STATE_PROCESSED
;
3031 if (cmd
->sess
->logout_completed
)
3032 /* no need to terminate. FW already freed exchange. */
3033 qlt_abort_cmd_on_host_reset(cmd
->vha
, cmd
);
3035 qlt_send_term_exchange(vha
, cmd
, &cmd
->atio
, 1, 0);
3036 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3039 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3041 memset(&prm
, 0, sizeof(prm
));
3043 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe018,
3044 "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p]\n",
3045 (xmit_type
& QLA_TGT_XMIT_STATUS
) ?
3046 1 : 0, cmd
->bufflen
, cmd
->sg_cnt
, cmd
->dma_data_direction
,
3049 res
= qlt_pre_xmit_response(cmd
, &prm
, xmit_type
, scsi_status
,
3051 if (unlikely(res
!= 0)) {
3055 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3057 if (xmit_type
== QLA_TGT_XMIT_STATUS
)
3058 vha
->tgt_counters
.core_qla_snd_status
++;
3060 vha
->tgt_counters
.core_qla_que_buf
++;
3062 if (!ha
->flags
.fw_started
|| cmd
->reset_count
!= ha
->chip_reset
) {
3064 * Either the port is not online or this request was from
3065 * previous life, just abort the processing.
3067 cmd
->state
= QLA_TGT_STATE_PROCESSED
;
3068 qlt_abort_cmd_on_host_reset(cmd
->vha
, cmd
);
3069 ql_dbg(ql_dbg_async
, vha
, 0xe101,
3070 "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n",
3071 vha
->flags
.online
, qla2x00_reset_active(vha
),
3072 cmd
->reset_count
, ha
->chip_reset
);
3073 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3077 /* Does F/W have an IOCBs for this request */
3078 res
= qlt_check_reserve_free_req(vha
, full_req_cnt
);
3080 goto out_unmap_unlock
;
3082 if (cmd
->se_cmd
.prot_op
&& (xmit_type
& QLA_TGT_XMIT_DATA
))
3083 res
= qlt_build_ctio_crc2_pkt(&prm
, vha
);
3085 res
= qlt_24xx_build_ctio_pkt(&prm
, vha
);
3086 if (unlikely(res
!= 0)) {
3087 vha
->req
->cnt
+= full_req_cnt
;
3088 goto out_unmap_unlock
;
3091 pkt
= (struct ctio7_to_24xx
*)prm
.pkt
;
3093 if (qlt_has_data(cmd
) && (xmit_type
& QLA_TGT_XMIT_DATA
)) {
3094 pkt
->u
.status0
.flags
|=
3095 cpu_to_le16(CTIO7_FLAGS_DATA_IN
|
3096 CTIO7_FLAGS_STATUS_MODE_0
);
3098 if (cmd
->se_cmd
.prot_op
== TARGET_PROT_NORMAL
)
3099 qlt_load_data_segments(&prm
, vha
);
3101 if (prm
.add_status_pkt
== 0) {
3102 if (xmit_type
& QLA_TGT_XMIT_STATUS
) {
3103 pkt
->u
.status0
.scsi_status
=
3104 cpu_to_le16(prm
.rq_result
);
3105 pkt
->u
.status0
.residual
=
3106 cpu_to_le32(prm
.residual
);
3107 pkt
->u
.status0
.flags
|= cpu_to_le16(
3108 CTIO7_FLAGS_SEND_STATUS
);
3109 if (qlt_need_explicit_conf(ha
, cmd
, 0)) {
3110 pkt
->u
.status0
.flags
|=
3112 CTIO7_FLAGS_EXPLICIT_CONFORM
|
3113 CTIO7_FLAGS_CONFORM_REQ
);
3119 * We have already made sure that there is sufficient
3120 * amount of request entries to not drop HW lock in
3123 struct ctio7_to_24xx
*ctio
=
3124 (struct ctio7_to_24xx
*)qlt_get_req_pkt(vha
);
3126 ql_dbg(ql_dbg_io
, vha
, 0x305e,
3127 "Building additional status packet 0x%p.\n",
3131 * T10Dif: ctio_crc2_to_fw overlay ontop of
3134 memcpy(ctio
, pkt
, sizeof(*ctio
));
3135 /* reset back to CTIO7 */
3136 ctio
->entry_count
= 1;
3137 ctio
->entry_type
= CTIO_TYPE7
;
3138 ctio
->dseg_count
= 0;
3139 ctio
->u
.status1
.flags
&= ~cpu_to_le16(
3140 CTIO7_FLAGS_DATA_IN
);
3142 /* Real finish is ctio_m1's finish */
3143 pkt
->handle
|= CTIO_INTERMEDIATE_HANDLE_MARK
;
3144 pkt
->u
.status0
.flags
|= cpu_to_le16(
3145 CTIO7_FLAGS_DONT_RET_CTIO
);
3147 /* qlt_24xx_init_ctio_to_isp will correct
3148 * all neccessary fields that's part of CTIO7.
3149 * There should be no residual of CTIO-CRC2 data.
3151 qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx
*)ctio
,
3153 pr_debug("Status CTIO7: %p\n", ctio
);
3156 qlt_24xx_init_ctio_to_isp(pkt
, &prm
);
3159 cmd
->state
= QLA_TGT_STATE_PROCESSED
; /* Mid-level is done processing */
3160 cmd
->cmd_sent_to_fw
= 1;
3162 /* Memory Barrier */
3164 qla2x00_start_iocbs(vha
, vha
->req
);
3165 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3170 qlt_unmap_sg(vha
, cmd
);
3171 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3175 EXPORT_SYMBOL(qlt_xmit_response
);
3177 int qlt_rdy_to_xfer(struct qla_tgt_cmd
*cmd
)
3179 struct ctio7_to_24xx
*pkt
;
3180 struct scsi_qla_host
*vha
= cmd
->vha
;
3181 struct qla_hw_data
*ha
= vha
->hw
;
3182 struct qla_tgt
*tgt
= cmd
->tgt
;
3183 struct qla_tgt_prm prm
;
3184 unsigned long flags
;
3187 memset(&prm
, 0, sizeof(prm
));
3193 /* Send marker if required */
3194 if (qlt_issue_marker(vha
, 0) != QLA_SUCCESS
)
3197 /* Calculate number of entries and segments required */
3198 if (qlt_pci_map_calc_cnt(&prm
) != 0)
3201 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3203 if (!ha
->flags
.fw_started
|| (cmd
->reset_count
!= ha
->chip_reset
) ||
3204 (cmd
->sess
&& cmd
->sess
->deleted
)) {
3206 * Either the port is not online or this request was from
3207 * previous life, just abort the processing.
3209 cmd
->state
= QLA_TGT_STATE_NEED_DATA
;
3210 qlt_abort_cmd_on_host_reset(cmd
->vha
, cmd
);
3211 ql_dbg(ql_dbg_async
, vha
, 0xe102,
3212 "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n",
3213 vha
->flags
.online
, qla2x00_reset_active(vha
),
3214 cmd
->reset_count
, ha
->chip_reset
);
3215 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3219 /* Does F/W have an IOCBs for this request */
3220 res
= qlt_check_reserve_free_req(vha
, prm
.req_cnt
);
3222 goto out_unlock_free_unmap
;
3223 if (cmd
->se_cmd
.prot_op
)
3224 res
= qlt_build_ctio_crc2_pkt(&prm
, vha
);
3226 res
= qlt_24xx_build_ctio_pkt(&prm
, vha
);
3228 if (unlikely(res
!= 0)) {
3229 vha
->req
->cnt
+= prm
.req_cnt
;
3230 goto out_unlock_free_unmap
;
3233 pkt
= (struct ctio7_to_24xx
*)prm
.pkt
;
3234 pkt
->u
.status0
.flags
|= cpu_to_le16(CTIO7_FLAGS_DATA_OUT
|
3235 CTIO7_FLAGS_STATUS_MODE_0
);
3237 if (cmd
->se_cmd
.prot_op
== TARGET_PROT_NORMAL
)
3238 qlt_load_data_segments(&prm
, vha
);
3240 cmd
->state
= QLA_TGT_STATE_NEED_DATA
;
3241 cmd
->cmd_sent_to_fw
= 1;
3243 /* Memory Barrier */
3245 qla2x00_start_iocbs(vha
, vha
->req
);
3246 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3250 out_unlock_free_unmap
:
3251 qlt_unmap_sg(vha
, cmd
);
3252 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3256 EXPORT_SYMBOL(qlt_rdy_to_xfer
);
3260 * it is assumed either hardware_lock or qpair lock is held.
3263 qlt_handle_dif_error(struct scsi_qla_host
*vha
, struct qla_tgt_cmd
*cmd
,
3264 struct ctio_crc_from_fw
*sts
)
3266 uint8_t *ap
= &sts
->actual_dif
[0];
3267 uint8_t *ep
= &sts
->expected_dif
[0];
3268 uint64_t lba
= cmd
->se_cmd
.t_task_lba
;
3269 uint8_t scsi_status
, sense_key
, asc
, ascq
;
3270 unsigned long flags
;
3272 cmd
->trc_flags
|= TRC_DIF_ERR
;
3274 cmd
->a_guard
= be16_to_cpu(*(uint16_t *)(ap
+ 0));
3275 cmd
->a_app_tag
= be16_to_cpu(*(uint16_t *)(ap
+ 2));
3276 cmd
->a_ref_tag
= be32_to_cpu(*(uint32_t *)(ap
+ 4));
3278 cmd
->e_guard
= be16_to_cpu(*(uint16_t *)(ep
+ 0));
3279 cmd
->e_app_tag
= be16_to_cpu(*(uint16_t *)(ep
+ 2));
3280 cmd
->e_ref_tag
= be32_to_cpu(*(uint32_t *)(ep
+ 4));
3282 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xf075,
3283 "%s: aborted %d state %d\n", __func__
, cmd
->aborted
, cmd
->state
);
3285 scsi_status
= sense_key
= asc
= ascq
= 0;
3287 /* check appl tag */
3288 if (cmd
->e_app_tag
!= cmd
->a_app_tag
) {
3289 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xffff,
3290 "App Tag ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] "
3291 "Ref[%x|%x], App[%x|%x], "
3292 "Guard [%x|%x] cmd=%p ox_id[%04x]",
3293 cmd
->cdb
[0], lba
, (lba
+cmd
->num_blks
), cmd
->num_blks
,
3294 cmd
->a_ref_tag
, cmd
->e_ref_tag
,
3295 cmd
->a_app_tag
, cmd
->e_app_tag
,
3296 cmd
->a_guard
, cmd
->e_guard
,
3297 cmd
, cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
);
3299 cmd
->dif_err_code
= DIF_ERR_APP
;
3300 scsi_status
= SAM_STAT_CHECK_CONDITION
;
3301 sense_key
= ABORTED_COMMAND
;
3307 if (cmd
->e_ref_tag
!= cmd
->a_ref_tag
) {
3308 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xffff,
3309 "Ref Tag ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] "
3310 "Ref[%x|%x], App[%x|%x], "
3311 "Guard[%x|%x] cmd=%p ox_id[%04x] ",
3312 cmd
->cdb
[0], lba
, (lba
+cmd
->num_blks
), cmd
->num_blks
,
3313 cmd
->a_ref_tag
, cmd
->e_ref_tag
,
3314 cmd
->a_app_tag
, cmd
->e_app_tag
,
3315 cmd
->a_guard
, cmd
->e_guard
,
3316 cmd
, cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
);
3318 cmd
->dif_err_code
= DIF_ERR_REF
;
3319 scsi_status
= SAM_STAT_CHECK_CONDITION
;
3320 sense_key
= ABORTED_COMMAND
;
3327 if (cmd
->e_guard
!= cmd
->a_guard
) {
3328 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xffff,
3329 "Guard ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] "
3330 "Ref[%x|%x], App[%x|%x], "
3331 "Guard [%x|%x] cmd=%p ox_id[%04x]",
3332 cmd
->cdb
[0], lba
, (lba
+cmd
->num_blks
), cmd
->num_blks
,
3333 cmd
->a_ref_tag
, cmd
->e_ref_tag
,
3334 cmd
->a_app_tag
, cmd
->e_app_tag
,
3335 cmd
->a_guard
, cmd
->e_guard
,
3336 cmd
, cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
);
3337 cmd
->dif_err_code
= DIF_ERR_GRD
;
3338 scsi_status
= SAM_STAT_CHECK_CONDITION
;
3339 sense_key
= ABORTED_COMMAND
;
3344 switch (cmd
->state
) {
3345 case QLA_TGT_STATE_NEED_DATA
:
3346 /* handle_data will load DIF error code */
3347 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
3348 vha
->hw
->tgt
.tgt_ops
->handle_data(cmd
);
3351 spin_lock_irqsave(&cmd
->cmd_lock
, flags
);
3353 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
3354 vha
->hw
->tgt
.tgt_ops
->free_cmd(cmd
);
3357 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
3359 qlt_send_resp_ctio(vha
, cmd
, scsi_status
, sense_key
, asc
, ascq
);
3360 /* assume scsi status gets out on the wire.
3361 * Will not wait for completion.
3363 vha
->hw
->tgt
.tgt_ops
->free_cmd(cmd
);
3368 /* If hardware_lock held on entry, might drop it, then reaquire */
3369 /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */
3370 static int __qlt_send_term_imm_notif(struct scsi_qla_host
*vha
,
3371 struct imm_ntfy_from_isp
*ntfy
)
3373 struct nack_to_isp
*nack
;
3374 struct qla_hw_data
*ha
= vha
->hw
;
3378 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0xe01c,
3379 "Sending TERM ELS CTIO (ha=%p)\n", ha
);
3381 pkt
= (request_t
*)qla2x00_alloc_iocbs(vha
, NULL
);
3383 ql_dbg(ql_dbg_tgt
, vha
, 0xe080,
3384 "qla_target(%d): %s failed: unable to allocate "
3385 "request packet\n", vha
->vp_idx
, __func__
);
3389 pkt
->entry_type
= NOTIFY_ACK_TYPE
;
3390 pkt
->entry_count
= 1;
3391 pkt
->handle
= QLA_TGT_SKIP_HANDLE
;
3393 nack
= (struct nack_to_isp
*)pkt
;
3394 nack
->ox_id
= ntfy
->ox_id
;
3396 nack
->u
.isp24
.nport_handle
= ntfy
->u
.isp24
.nport_handle
;
3397 if (le16_to_cpu(ntfy
->u
.isp24
.status
) == IMM_NTFY_ELS
) {
3398 nack
->u
.isp24
.flags
= ntfy
->u
.isp24
.flags
&
3399 __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB
);
3403 nack
->u
.isp24
.flags
|=
3404 __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE
);
3406 nack
->u
.isp24
.srr_rx_id
= ntfy
->u
.isp24
.srr_rx_id
;
3407 nack
->u
.isp24
.status
= ntfy
->u
.isp24
.status
;
3408 nack
->u
.isp24
.status_subcode
= ntfy
->u
.isp24
.status_subcode
;
3409 nack
->u
.isp24
.fw_handle
= ntfy
->u
.isp24
.fw_handle
;
3410 nack
->u
.isp24
.exchange_address
= ntfy
->u
.isp24
.exchange_address
;
3411 nack
->u
.isp24
.srr_rel_offs
= ntfy
->u
.isp24
.srr_rel_offs
;
3412 nack
->u
.isp24
.srr_ui
= ntfy
->u
.isp24
.srr_ui
;
3413 nack
->u
.isp24
.vp_index
= ntfy
->u
.isp24
.vp_index
;
3415 qla2x00_start_iocbs(vha
, vha
->req
);
3419 static void qlt_send_term_imm_notif(struct scsi_qla_host
*vha
,
3420 struct imm_ntfy_from_isp
*imm
, int ha_locked
)
3422 unsigned long flags
= 0;
3425 if (qlt_issue_marker(vha
, ha_locked
) < 0)
3429 rc
= __qlt_send_term_imm_notif(vha
, imm
);
3433 qlt_alloc_qfull_cmd(vha
, imm
, 0, 0);
3441 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
3442 rc
= __qlt_send_term_imm_notif(vha
, imm
);
3446 qlt_alloc_qfull_cmd(vha
, imm
, 0, 0);
3451 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
3454 /* If hardware_lock held on entry, might drop it, then reaquire */
3455 /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */
3456 static int __qlt_send_term_exchange(struct scsi_qla_host
*vha
,
3457 struct qla_tgt_cmd
*cmd
,
3458 struct atio_from_isp
*atio
)
3460 struct ctio7_to_24xx
*ctio24
;
3461 struct qla_hw_data
*ha
= vha
->hw
;
3466 ql_dbg(ql_dbg_tgt
, vha
, 0xe01c, "Sending TERM EXCH CTIO (ha=%p)\n", ha
);
3468 pkt
= (request_t
*)qla2x00_alloc_iocbs_ready(vha
, NULL
);
3470 ql_dbg(ql_dbg_tgt
, vha
, 0xe050,
3471 "qla_target(%d): %s failed: unable to allocate "
3472 "request packet\n", vha
->vp_idx
, __func__
);
3477 if (cmd
->state
< QLA_TGT_STATE_PROCESSED
) {
3478 ql_dbg(ql_dbg_tgt
, vha
, 0xe051,
3479 "qla_target(%d): Terminating cmd %p with "
3480 "incorrect state %d\n", vha
->vp_idx
, cmd
,
3486 vha
->tgt_counters
.num_term_xchg_sent
++;
3487 pkt
->entry_count
= 1;
3488 pkt
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
3490 ctio24
= (struct ctio7_to_24xx
*)pkt
;
3491 ctio24
->entry_type
= CTIO_TYPE7
;
3492 ctio24
->nport_handle
= CTIO7_NHANDLE_UNRECOGNIZED
;
3493 ctio24
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
3494 ctio24
->vp_index
= vha
->vp_idx
;
3495 ctio24
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
3496 ctio24
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
3497 ctio24
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
3498 ctio24
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
3499 ctio24
->u
.status1
.flags
= (atio
->u
.isp24
.attr
<< 9) |
3500 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
|
3501 CTIO7_FLAGS_TERMINATE
);
3502 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
3503 ctio24
->u
.status1
.ox_id
= cpu_to_le16(temp
);
3505 /* Most likely, it isn't needed */
3506 ctio24
->u
.status1
.residual
= get_unaligned((uint32_t *)
3507 &atio
->u
.isp24
.fcp_cmnd
.add_cdb
[
3508 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
]);
3509 if (ctio24
->u
.status1
.residual
!= 0)
3510 ctio24
->u
.status1
.scsi_status
|= SS_RESIDUAL_UNDER
;
3512 /* Memory Barrier */
3514 qla2x00_start_iocbs(vha
, vha
->req
);
3518 static void qlt_send_term_exchange(struct scsi_qla_host
*vha
,
3519 struct qla_tgt_cmd
*cmd
, struct atio_from_isp
*atio
, int ha_locked
,
3522 unsigned long flags
= 0;
3525 if (qlt_issue_marker(vha
, ha_locked
) < 0)
3529 rc
= __qlt_send_term_exchange(vha
, cmd
, atio
);
3531 qlt_alloc_qfull_cmd(vha
, atio
, 0, 0);
3534 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
3535 rc
= __qlt_send_term_exchange(vha
, cmd
, atio
);
3537 qlt_alloc_qfull_cmd(vha
, atio
, 0, 0);
3540 if (cmd
&& !ul_abort
&& !cmd
->aborted
) {
3542 qlt_unmap_sg(vha
, cmd
);
3543 vha
->hw
->tgt
.tgt_ops
->free_cmd(cmd
);
3547 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
3552 static void qlt_init_term_exchange(struct scsi_qla_host
*vha
)
3554 struct list_head free_list
;
3555 struct qla_tgt_cmd
*cmd
, *tcmd
;
3557 vha
->hw
->tgt
.leak_exchg_thresh_hold
=
3558 (vha
->hw
->cur_fw_xcb_count
/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT
;
3561 if (!list_empty(&vha
->hw
->tgt
.q_full_list
)) {
3562 INIT_LIST_HEAD(&free_list
);
3563 list_splice_init(&vha
->hw
->tgt
.q_full_list
, &free_list
);
3565 list_for_each_entry_safe(cmd
, tcmd
, &free_list
, cmd_list
) {
3566 list_del(&cmd
->cmd_list
);
3567 /* This cmd was never sent to TCM. There is no need
3568 * to schedule free or call free_cmd
3571 vha
->hw
->tgt
.num_qfull_cmds_alloc
--;
3574 vha
->hw
->tgt
.num_qfull_cmds_dropped
= 0;
3577 static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host
*vha
)
3579 uint32_t total_leaked
;
3581 total_leaked
= vha
->hw
->tgt
.num_qfull_cmds_dropped
;
3583 if (vha
->hw
->tgt
.leak_exchg_thresh_hold
&&
3584 (total_leaked
> vha
->hw
->tgt
.leak_exchg_thresh_hold
)) {
3586 ql_dbg(ql_dbg_tgt
, vha
, 0xe079,
3587 "Chip reset due to exchange starvation: %d/%d.\n",
3588 total_leaked
, vha
->hw
->cur_fw_xcb_count
);
3590 if (IS_P3P_TYPE(vha
->hw
))
3591 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
3593 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3594 qla2xxx_wake_dpc(vha
);
3599 int qlt_abort_cmd(struct qla_tgt_cmd
*cmd
)
3601 struct qla_tgt
*tgt
= cmd
->tgt
;
3602 struct scsi_qla_host
*vha
= tgt
->vha
;
3603 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
3604 unsigned long flags
;
3606 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf014,
3607 "qla_target(%d): terminating exchange for aborted cmd=%p "
3608 "(se_cmd=%p, tag=%llu)", vha
->vp_idx
, cmd
, &cmd
->se_cmd
,
3611 spin_lock_irqsave(&cmd
->cmd_lock
, flags
);
3613 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
3615 * It's normal to see 2 calls in this path:
3616 * 1) XFER Rdy completion + CMD_T_ABORT
3617 * 2) TCM TMR - drain_state_list
3619 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xffff,
3620 "multiple abort. %p transport_state %x, t_state %x,"
3621 " se_cmd_flags %x \n", cmd
, cmd
->se_cmd
.transport_state
,
3622 cmd
->se_cmd
.t_state
,cmd
->se_cmd
.se_cmd_flags
);
3626 cmd
->trc_flags
|= TRC_ABORT
;
3627 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
3629 qlt_send_term_exchange(vha
, cmd
, &cmd
->atio
, 0, 1);
3632 EXPORT_SYMBOL(qlt_abort_cmd
);
3634 void qlt_free_cmd(struct qla_tgt_cmd
*cmd
)
3636 struct fc_port
*sess
= cmd
->sess
;
3638 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe074,
3639 "%s: se_cmd[%p] ox_id %04x\n",
3640 __func__
, &cmd
->se_cmd
,
3641 be16_to_cpu(cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
));
3643 BUG_ON(cmd
->cmd_in_wq
);
3646 qlt_unmap_sg(cmd
->vha
, cmd
);
3649 qlt_decr_num_pend_cmds(cmd
->vha
);
3651 BUG_ON(cmd
->sg_mapped
);
3652 cmd
->jiffies_at_free
= get_jiffies_64();
3653 if (unlikely(cmd
->free_sg
))
3656 if (!sess
|| !sess
->se_sess
) {
3660 cmd
->jiffies_at_free
= get_jiffies_64();
3661 percpu_ida_free(&sess
->se_sess
->sess_tag_pool
, cmd
->se_cmd
.map_tag
);
3663 EXPORT_SYMBOL(qlt_free_cmd
);
3666 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3668 static int qlt_term_ctio_exchange(struct scsi_qla_host
*vha
, void *ctio
,
3669 struct qla_tgt_cmd
*cmd
, uint32_t status
)
3673 if (cmd
->se_cmd
.prot_op
)
3674 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xffff,
3675 "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] "
3676 "se_cmd=%p tag[%x] op %#x/%s",
3678 cmd
->num_blks
, &cmd
->se_cmd
,
3679 cmd
->atio
.u
.isp24
.exchange_addr
,
3680 cmd
->se_cmd
.prot_op
,
3681 prot_op_str(cmd
->se_cmd
.prot_op
));
3684 struct ctio7_from_24xx
*c
= (struct ctio7_from_24xx
*)ctio
;
3686 cpu_to_le16(OF_TERM_EXCH
));
3691 qlt_send_term_exchange(vha
, cmd
, &cmd
->atio
, 1, 0);
3696 /* ha->hardware_lock supposed to be held on entry */
3697 static inline struct qla_tgt_cmd
*qlt_get_cmd(struct scsi_qla_host
*vha
,
3700 struct qla_hw_data
*ha
= vha
->hw
;
3703 if (ha
->tgt
.cmds
[handle
] != NULL
) {
3704 struct qla_tgt_cmd
*cmd
= ha
->tgt
.cmds
[handle
];
3705 ha
->tgt
.cmds
[handle
] = NULL
;
3711 /* ha->hardware_lock supposed to be held on entry */
3712 static struct qla_tgt_cmd
*qlt_ctio_to_cmd(struct scsi_qla_host
*vha
,
3713 uint32_t handle
, void *ctio
)
3715 struct qla_tgt_cmd
*cmd
= NULL
;
3717 /* Clear out internal marks */
3718 handle
&= ~(CTIO_COMPLETION_HANDLE_MARK
|
3719 CTIO_INTERMEDIATE_HANDLE_MARK
);
3721 if (handle
!= QLA_TGT_NULL_HANDLE
) {
3722 if (unlikely(handle
== QLA_TGT_SKIP_HANDLE
))
3725 /* handle-1 is actually used */
3726 if (unlikely(handle
> DEFAULT_OUTSTANDING_COMMANDS
)) {
3727 ql_dbg(ql_dbg_tgt
, vha
, 0xe052,
3728 "qla_target(%d): Wrong handle %x received\n",
3729 vha
->vp_idx
, handle
);
3732 cmd
= qlt_get_cmd(vha
, handle
);
3733 if (unlikely(cmd
== NULL
)) {
3734 ql_dbg(ql_dbg_tgt
, vha
, 0xe053,
3735 "qla_target(%d): Suspicious: unable to "
3736 "find the command with handle %x\n", vha
->vp_idx
,
3740 } else if (ctio
!= NULL
) {
3741 /* We can't get loop ID from CTIO7 */
3742 ql_dbg(ql_dbg_tgt
, vha
, 0xe054,
3743 "qla_target(%d): Wrong CTIO received: QLA24xx doesn't "
3744 "support NULL handles\n", vha
->vp_idx
);
3751 /* hardware_lock should be held by caller. */
3753 qlt_abort_cmd_on_host_reset(struct scsi_qla_host
*vha
, struct qla_tgt_cmd
*cmd
)
3755 struct qla_hw_data
*ha
= vha
->hw
;
3759 qlt_unmap_sg(vha
, cmd
);
3761 handle
= qlt_make_handle(vha
);
3763 /* TODO: fix debug message type and ids. */
3764 if (cmd
->state
== QLA_TGT_STATE_PROCESSED
) {
3765 ql_dbg(ql_dbg_io
, vha
, 0xff00,
3766 "HOST-ABORT: handle=%d, state=PROCESSED.\n", handle
);
3767 } else if (cmd
->state
== QLA_TGT_STATE_NEED_DATA
) {
3768 cmd
->write_data_transferred
= 0;
3769 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
3771 ql_dbg(ql_dbg_io
, vha
, 0xff01,
3772 "HOST-ABORT: handle=%d, state=DATA_IN.\n", handle
);
3774 ha
->tgt
.tgt_ops
->handle_data(cmd
);
3777 ql_dbg(ql_dbg_io
, vha
, 0xff03,
3778 "HOST-ABORT: handle=%d, state=BAD(%d).\n", handle
,
3783 cmd
->trc_flags
|= TRC_FLUSH
;
3784 ha
->tgt
.tgt_ops
->free_cmd(cmd
);
3788 qlt_host_reset_handler(struct qla_hw_data
*ha
)
3790 struct qla_tgt_cmd
*cmd
;
3791 unsigned long flags
;
3792 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
3793 scsi_qla_host_t
*vha
= NULL
;
3794 struct qla_tgt
*tgt
= base_vha
->vha_tgt
.qla_tgt
;
3797 if (!base_vha
->hw
->tgt
.tgt_ops
)
3800 if (!tgt
|| qla_ini_mode_enabled(base_vha
)) {
3801 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf003,
3802 "Target mode disabled\n");
3806 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xff10,
3807 "HOST-ABORT-HNDLR: base_vha->dpc_flags=%lx.\n",
3808 base_vha
->dpc_flags
);
3810 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3811 for (i
= 1; i
< DEFAULT_OUTSTANDING_COMMANDS
+ 1; i
++) {
3812 cmd
= qlt_get_cmd(base_vha
, i
);
3815 /* ha->tgt.cmds entry is cleared by qlt_get_cmd. */
3817 qlt_abort_cmd_on_host_reset(vha
, cmd
);
3819 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3824 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3826 static void qlt_do_ctio_completion(struct scsi_qla_host
*vha
, uint32_t handle
,
3827 uint32_t status
, void *ctio
)
3829 struct qla_hw_data
*ha
= vha
->hw
;
3830 struct se_cmd
*se_cmd
;
3831 struct qla_tgt_cmd
*cmd
;
3833 if (handle
& CTIO_INTERMEDIATE_HANDLE_MARK
) {
3834 /* That could happen only in case of an error/reset/abort */
3835 if (status
!= CTIO_SUCCESS
) {
3836 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01d,
3837 "Intermediate CTIO received"
3838 " (status %x)\n", status
);
3843 cmd
= qlt_ctio_to_cmd(vha
, handle
, ctio
);
3847 se_cmd
= &cmd
->se_cmd
;
3848 cmd
->cmd_sent_to_fw
= 0;
3850 qlt_unmap_sg(vha
, cmd
);
3852 if (unlikely(status
!= CTIO_SUCCESS
)) {
3853 switch (status
& 0xFFFF) {
3854 case CTIO_LIP_RESET
:
3855 case CTIO_TARGET_RESET
:
3857 /* driver request abort via Terminate exchange */
3859 case CTIO_INVALID_RX_ID
:
3861 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf058,
3862 "qla_target(%d): CTIO with "
3863 "status %#x received, state %x, se_cmd %p, "
3864 "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, "
3865 "TIMEOUT=b, INVALID_RX_ID=8)\n", vha
->vp_idx
,
3866 status
, cmd
->state
, se_cmd
);
3869 case CTIO_PORT_LOGGED_OUT
:
3870 case CTIO_PORT_UNAVAILABLE
:
3873 (status
& 0xFFFF) == CTIO_PORT_LOGGED_OUT
;
3875 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf059,
3876 "qla_target(%d): CTIO with %s status %x "
3877 "received (state %x, se_cmd %p)\n", vha
->vp_idx
,
3878 logged_out
? "PORT LOGGED OUT" : "PORT UNAVAILABLE",
3879 status
, cmd
->state
, se_cmd
);
3881 if (logged_out
&& cmd
->sess
) {
3883 * Session is already logged out, but we need
3884 * to notify initiator, who's not aware of this
3886 cmd
->sess
->logout_on_delete
= 0;
3887 cmd
->sess
->send_els_logo
= 1;
3888 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
3889 "%s %d %8phC post del sess\n",
3890 __func__
, __LINE__
, cmd
->sess
->port_name
);
3892 qlt_schedule_sess_for_deletion_lock(cmd
->sess
);
3896 case CTIO_DIF_ERROR
: {
3897 struct ctio_crc_from_fw
*crc
=
3898 (struct ctio_crc_from_fw
*)ctio
;
3899 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf073,
3900 "qla_target(%d): CTIO with DIF_ERROR status %x "
3901 "received (state %x, ulp_cmd %p) actual_dif[0x%llx] "
3902 "expect_dif[0x%llx]\n",
3903 vha
->vp_idx
, status
, cmd
->state
, se_cmd
,
3904 *((u64
*)&crc
->actual_dif
[0]),
3905 *((u64
*)&crc
->expected_dif
[0]));
3907 qlt_handle_dif_error(vha
, cmd
, ctio
);
3911 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05b,
3912 "qla_target(%d): CTIO with error status 0x%x received (state %x, se_cmd %p\n",
3913 vha
->vp_idx
, status
, cmd
->state
, se_cmd
);
3918 /* "cmd->aborted" means
3919 * cmd is already aborted/terminated, we don't
3920 * need to terminate again. The exchange is already
3921 * cleaned up/freed at FW level. Just cleanup at driver
3924 if ((cmd
->state
!= QLA_TGT_STATE_NEED_DATA
) &&
3926 cmd
->trc_flags
|= TRC_CTIO_ERR
;
3927 if (qlt_term_ctio_exchange(vha
, ctio
, cmd
, status
))
3932 if (cmd
->state
== QLA_TGT_STATE_PROCESSED
) {
3933 cmd
->trc_flags
|= TRC_CTIO_DONE
;
3934 } else if (cmd
->state
== QLA_TGT_STATE_NEED_DATA
) {
3935 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
3937 if (status
== CTIO_SUCCESS
)
3938 cmd
->write_data_transferred
= 1;
3940 ha
->tgt
.tgt_ops
->handle_data(cmd
);
3942 } else if (cmd
->aborted
) {
3943 cmd
->trc_flags
|= TRC_CTIO_ABORTED
;
3944 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01e,
3945 "Aborted command %p (tag %lld) finished\n", cmd
, se_cmd
->tag
);
3947 cmd
->trc_flags
|= TRC_CTIO_STRANGE
;
3948 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05c,
3949 "qla_target(%d): A command in state (%d) should "
3950 "not return a CTIO complete\n", vha
->vp_idx
, cmd
->state
);
3953 if (unlikely(status
!= CTIO_SUCCESS
) &&
3955 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01f, "Finishing failed CTIO\n");
3959 ha
->tgt
.tgt_ops
->free_cmd(cmd
);
3962 static inline int qlt_get_fcp_task_attr(struct scsi_qla_host
*vha
,
3967 switch (task_codes
) {
3968 case ATIO_SIMPLE_QUEUE
:
3969 fcp_task_attr
= TCM_SIMPLE_TAG
;
3971 case ATIO_HEAD_OF_QUEUE
:
3972 fcp_task_attr
= TCM_HEAD_TAG
;
3974 case ATIO_ORDERED_QUEUE
:
3975 fcp_task_attr
= TCM_ORDERED_TAG
;
3977 case ATIO_ACA_QUEUE
:
3978 fcp_task_attr
= TCM_ACA_TAG
;
3981 fcp_task_attr
= TCM_SIMPLE_TAG
;
3984 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05d,
3985 "qla_target: unknown task code %x, use ORDERED instead\n",
3987 fcp_task_attr
= TCM_ORDERED_TAG
;
3991 return fcp_task_attr
;
3994 static struct fc_port
*qlt_make_local_sess(struct scsi_qla_host
*,
3997 * Process context for I/O path into tcm_qla2xxx code
3999 static void __qlt_do_work(struct qla_tgt_cmd
*cmd
)
4001 scsi_qla_host_t
*vha
= cmd
->vha
;
4002 struct qla_hw_data
*ha
= vha
->hw
;
4003 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4004 struct fc_port
*sess
= cmd
->sess
;
4005 struct atio_from_isp
*atio
= &cmd
->atio
;
4007 unsigned long flags
;
4008 uint32_t data_length
;
4009 int ret
, fcp_task_attr
, data_dir
, bidi
= 0;
4012 cmd
->trc_flags
|= TRC_DO_WORK
;
4017 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf082,
4018 "cmd with tag %u is aborted\n",
4019 cmd
->atio
.u
.isp24
.exchange_addr
);
4023 spin_lock_init(&cmd
->cmd_lock
);
4024 cdb
= &atio
->u
.isp24
.fcp_cmnd
.cdb
[0];
4025 cmd
->se_cmd
.tag
= atio
->u
.isp24
.exchange_addr
;
4026 cmd
->unpacked_lun
= scsilun_to_int(
4027 (struct scsi_lun
*)&atio
->u
.isp24
.fcp_cmnd
.lun
);
4029 if (atio
->u
.isp24
.fcp_cmnd
.rddata
&&
4030 atio
->u
.isp24
.fcp_cmnd
.wrdata
) {
4032 data_dir
= DMA_TO_DEVICE
;
4033 } else if (atio
->u
.isp24
.fcp_cmnd
.rddata
)
4034 data_dir
= DMA_FROM_DEVICE
;
4035 else if (atio
->u
.isp24
.fcp_cmnd
.wrdata
)
4036 data_dir
= DMA_TO_DEVICE
;
4038 data_dir
= DMA_NONE
;
4040 fcp_task_attr
= qlt_get_fcp_task_attr(vha
,
4041 atio
->u
.isp24
.fcp_cmnd
.task_attr
);
4042 data_length
= be32_to_cpu(get_unaligned((uint32_t *)
4043 &atio
->u
.isp24
.fcp_cmnd
.add_cdb
[
4044 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
]));
4046 ret
= ha
->tgt
.tgt_ops
->handle_cmd(vha
, cmd
, cdb
, data_length
,
4047 fcp_task_attr
, data_dir
, bidi
);
4051 * Drop extra session reference from qla_tgt_handle_cmd_for_atio*(
4053 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4054 ha
->tgt
.tgt_ops
->put_sess(sess
);
4055 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4059 ql_dbg(ql_dbg_io
, vha
, 0x3060, "Terminating work cmd %p", cmd
);
4061 * cmd has not sent to target yet, so pass NULL as the second
4062 * argument to qlt_send_term_exchange() and free the memory here.
4064 cmd
->trc_flags
|= TRC_DO_WORK_ERR
;
4065 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4066 qlt_send_term_exchange(vha
, NULL
, &cmd
->atio
, 1, 0);
4068 qlt_decr_num_pend_cmds(vha
);
4069 percpu_ida_free(&sess
->se_sess
->sess_tag_pool
, cmd
->se_cmd
.map_tag
);
4070 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4072 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4073 ha
->tgt
.tgt_ops
->put_sess(sess
);
4074 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4077 static void qlt_do_work(struct work_struct
*work
)
4079 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
4080 scsi_qla_host_t
*vha
= cmd
->vha
;
4081 unsigned long flags
;
4083 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
4084 list_del(&cmd
->cmd_list
);
4085 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
4090 static struct qla_tgt_cmd
*qlt_get_tag(scsi_qla_host_t
*vha
,
4091 struct fc_port
*sess
,
4092 struct atio_from_isp
*atio
)
4094 struct se_session
*se_sess
= sess
->se_sess
;
4095 struct qla_tgt_cmd
*cmd
;
4098 tag
= percpu_ida_alloc(&se_sess
->sess_tag_pool
, TASK_RUNNING
);
4102 cmd
= &((struct qla_tgt_cmd
*)se_sess
->sess_cmd_map
)[tag
];
4103 memset(cmd
, 0, sizeof(struct qla_tgt_cmd
));
4105 memcpy(&cmd
->atio
, atio
, sizeof(*atio
));
4106 cmd
->state
= QLA_TGT_STATE_NEW
;
4107 cmd
->tgt
= vha
->vha_tgt
.qla_tgt
;
4108 qlt_incr_num_pend_cmds(vha
);
4110 cmd
->se_cmd
.map_tag
= tag
;
4112 cmd
->loop_id
= sess
->loop_id
;
4113 cmd
->conf_compl_supported
= sess
->conf_compl_supported
;
4116 cmd
->jiffies_at_alloc
= get_jiffies_64();
4118 cmd
->reset_count
= vha
->hw
->chip_reset
;
4123 static void qlt_send_busy(struct scsi_qla_host
*, struct atio_from_isp
*,
4126 static void qlt_create_sess_from_atio(struct work_struct
*work
)
4128 struct qla_tgt_sess_op
*op
= container_of(work
,
4129 struct qla_tgt_sess_op
, work
);
4130 scsi_qla_host_t
*vha
= op
->vha
;
4131 struct qla_hw_data
*ha
= vha
->hw
;
4132 struct fc_port
*sess
;
4133 struct qla_tgt_cmd
*cmd
;
4134 unsigned long flags
;
4135 uint8_t *s_id
= op
->atio
.u
.isp24
.fcp_hdr
.s_id
;
4137 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
4138 list_del(&op
->cmd_list
);
4139 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
4142 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf083,
4143 "sess_op with tag %u is aborted\n",
4144 op
->atio
.u
.isp24
.exchange_addr
);
4148 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf022,
4149 "qla_target(%d): Unable to find wwn login"
4150 " (s_id %x:%x:%x), trying to create it manually\n",
4151 vha
->vp_idx
, s_id
[0], s_id
[1], s_id
[2]);
4153 if (op
->atio
.u
.raw
.entry_count
> 1) {
4154 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf023,
4155 "Dropping multy entry atio %p\n", &op
->atio
);
4159 sess
= qlt_make_local_sess(vha
, s_id
);
4160 /* sess has an extra creation ref. */
4165 * Now obtain a pre-allocated session tag using the original op->atio
4166 * packet header, and dispatch into __qlt_do_work() using the existing
4169 cmd
= qlt_get_tag(vha
, sess
, &op
->atio
);
4171 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4172 qlt_send_busy(vha
, &op
->atio
, SAM_STAT_BUSY
);
4173 ha
->tgt
.tgt_ops
->put_sess(sess
);
4174 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4180 * __qlt_do_work() will call qlt_put_sess() to release
4181 * the extra reference taken above by qlt_make_local_sess()
4187 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4188 qlt_send_term_exchange(vha
, NULL
, &op
->atio
, 1, 0);
4189 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4193 /* ha->hardware_lock supposed to be held on entry */
4194 static int qlt_handle_cmd_for_atio(struct scsi_qla_host
*vha
,
4195 struct atio_from_isp
*atio
)
4197 struct qla_hw_data
*ha
= vha
->hw
;
4198 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4199 struct fc_port
*sess
;
4200 struct qla_tgt_cmd
*cmd
;
4201 unsigned long flags
;
4203 if (unlikely(tgt
->tgt_stop
)) {
4204 ql_dbg(ql_dbg_io
, vha
, 0x3061,
4205 "New command while device %p is shutting down\n", tgt
);
4209 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, atio
->u
.isp24
.fcp_hdr
.s_id
);
4210 if (unlikely(!sess
)) {
4211 struct qla_tgt_sess_op
*op
= kzalloc(sizeof(struct qla_tgt_sess_op
),
4216 memcpy(&op
->atio
, atio
, sizeof(*atio
));
4219 spin_lock(&vha
->cmd_list_lock
);
4220 list_add_tail(&op
->cmd_list
, &vha
->qla_sess_op_cmd_list
);
4221 spin_unlock(&vha
->cmd_list_lock
);
4223 INIT_WORK(&op
->work
, qlt_create_sess_from_atio
);
4224 queue_work(qla_tgt_wq
, &op
->work
);
4228 /* Another WWN used to have our s_id. Our PLOGI scheduled its
4229 * session deletion, but it's still in sess_del_work wq */
4230 if (sess
->deleted
) {
4231 ql_dbg(ql_dbg_io
, vha
, 0x3061,
4232 "New command while old session %p is being deleted\n",
4238 * Do kref_get() before returning + dropping qla_hw_data->hardware_lock.
4240 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
4241 ql_dbg(ql_dbg_tgt
, vha
, 0xffff,
4242 "%s: kref_get fail, %8phC oxid %x \n",
4243 __func__
, sess
->port_name
,
4244 be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
));
4248 cmd
= qlt_get_tag(vha
, sess
, atio
);
4250 ql_dbg(ql_dbg_io
, vha
, 0x3062,
4251 "qla_target(%d): Allocation of cmd failed\n", vha
->vp_idx
);
4252 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4253 ha
->tgt
.tgt_ops
->put_sess(sess
);
4254 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4259 cmd
->trc_flags
|= TRC_NEW_CMD
;
4260 cmd
->se_cmd
.cpuid
= ha
->msix_count
?
4261 ha
->tgt
.rspq_vector_cpuid
: WORK_CPU_UNBOUND
;
4263 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
4264 list_add_tail(&cmd
->cmd_list
, &vha
->qla_cmd_list
);
4265 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
4267 INIT_WORK(&cmd
->work
, qlt_do_work
);
4268 if (ha
->msix_count
) {
4269 if (cmd
->atio
.u
.isp24
.fcp_cmnd
.rddata
)
4270 queue_work_on(smp_processor_id(), qla_tgt_wq
,
4273 queue_work_on(cmd
->se_cmd
.cpuid
, qla_tgt_wq
,
4276 queue_work(qla_tgt_wq
, &cmd
->work
);
4282 /* ha->hardware_lock supposed to be held on entry */
4283 static int qlt_issue_task_mgmt(struct fc_port
*sess
, u64 lun
,
4284 int fn
, void *iocb
, int flags
)
4286 struct scsi_qla_host
*vha
= sess
->vha
;
4287 struct qla_hw_data
*ha
= vha
->hw
;
4288 struct qla_tgt_mgmt_cmd
*mcmd
;
4289 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
4292 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
4294 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10009,
4295 "qla_target(%d): Allocation of management "
4296 "command failed, some commands and their data could "
4297 "leak\n", vha
->vp_idx
);
4300 memset(mcmd
, 0, sizeof(*mcmd
));
4304 memcpy(&mcmd
->orig_iocb
.imm_ntfy
, iocb
,
4305 sizeof(mcmd
->orig_iocb
.imm_ntfy
));
4307 mcmd
->tmr_func
= fn
;
4308 mcmd
->flags
= flags
;
4309 mcmd
->reset_count
= vha
->hw
->chip_reset
;
4312 case QLA_TGT_LUN_RESET
:
4313 abort_cmds_for_lun(vha
, lun
, a
->u
.isp24
.fcp_hdr
.s_id
);
4317 res
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, lun
, mcmd
->tmr_func
, 0);
4319 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x1000b,
4320 "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n",
4321 sess
->vha
->vp_idx
, res
);
4322 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
4329 /* ha->hardware_lock supposed to be held on entry */
4330 static int qlt_handle_task_mgmt(struct scsi_qla_host
*vha
, void *iocb
)
4332 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
4333 struct qla_hw_data
*ha
= vha
->hw
;
4334 struct qla_tgt
*tgt
;
4335 struct fc_port
*sess
;
4336 uint32_t lun
, unpacked_lun
;
4338 unsigned long flags
;
4340 tgt
= vha
->vha_tgt
.qla_tgt
;
4342 lun
= a
->u
.isp24
.fcp_cmnd
.lun
;
4343 fn
= a
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
;
4345 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4346 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
4347 a
->u
.isp24
.fcp_hdr
.s_id
);
4348 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4350 unpacked_lun
= scsilun_to_int((struct scsi_lun
*)&lun
);
4353 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf024,
4354 "qla_target(%d): task mgmt fn 0x%x for "
4355 "non-existant session\n", vha
->vp_idx
, fn
);
4356 return qlt_sched_sess_work(tgt
, QLA_TGT_SESS_WORK_TM
, iocb
,
4357 sizeof(struct atio_from_isp
));
4363 return qlt_issue_task_mgmt(sess
, unpacked_lun
, fn
, iocb
, 0);
4366 /* ha->hardware_lock supposed to be held on entry */
4367 static int __qlt_abort_task(struct scsi_qla_host
*vha
,
4368 struct imm_ntfy_from_isp
*iocb
, struct fc_port
*sess
)
4370 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
4371 struct qla_hw_data
*ha
= vha
->hw
;
4372 struct qla_tgt_mgmt_cmd
*mcmd
;
4373 uint32_t lun
, unpacked_lun
;
4376 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
4378 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05f,
4379 "qla_target(%d): %s: Allocation of ABORT cmd failed\n",
4380 vha
->vp_idx
, __func__
);
4383 memset(mcmd
, 0, sizeof(*mcmd
));
4386 memcpy(&mcmd
->orig_iocb
.imm_ntfy
, iocb
,
4387 sizeof(mcmd
->orig_iocb
.imm_ntfy
));
4389 lun
= a
->u
.isp24
.fcp_cmnd
.lun
;
4390 unpacked_lun
= scsilun_to_int((struct scsi_lun
*)&lun
);
4391 mcmd
->reset_count
= vha
->hw
->chip_reset
;
4392 mcmd
->tmr_func
= QLA_TGT_2G_ABORT_TASK
;
4394 rc
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, unpacked_lun
, mcmd
->tmr_func
,
4395 le16_to_cpu(iocb
->u
.isp2x
.seq_id
));
4397 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf060,
4398 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
4400 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
4407 /* ha->hardware_lock supposed to be held on entry */
4408 static int qlt_abort_task(struct scsi_qla_host
*vha
,
4409 struct imm_ntfy_from_isp
*iocb
)
4411 struct qla_hw_data
*ha
= vha
->hw
;
4412 struct fc_port
*sess
;
4414 unsigned long flags
;
4416 loop_id
= GET_TARGET_ID(ha
, (struct atio_from_isp
*)iocb
);
4418 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4419 sess
= ha
->tgt
.tgt_ops
->find_sess_by_loop_id(vha
, loop_id
);
4420 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4423 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf025,
4424 "qla_target(%d): task abort for unexisting "
4425 "session\n", vha
->vp_idx
);
4426 return qlt_sched_sess_work(vha
->vha_tgt
.qla_tgt
,
4427 QLA_TGT_SESS_WORK_ABORT
, iocb
, sizeof(*iocb
));
4430 return __qlt_abort_task(vha
, iocb
, sess
);
4433 void qlt_logo_completion_handler(fc_port_t
*fcport
, int rc
)
4435 if (rc
!= MBS_COMMAND_COMPLETE
) {
4436 ql_dbg(ql_dbg_tgt_mgt
, fcport
->vha
, 0xf093,
4437 "%s: se_sess %p / sess %p from"
4438 " port %8phC loop_id %#04x s_id %02x:%02x:%02x"
4439 " LOGO failed: %#x\n",
4443 fcport
->port_name
, fcport
->loop_id
,
4444 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
4445 fcport
->d_id
.b
.al_pa
, rc
);
4448 fcport
->logout_completed
= 1;
4452 * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list)
4454 * Schedules sessions with matching port_id/loop_id but different wwn for
4455 * deletion. Returns existing session with matching wwn if present.
4459 qlt_find_sess_invalidate_other(scsi_qla_host_t
*vha
, uint64_t wwn
,
4460 port_id_t port_id
, uint16_t loop_id
, struct fc_port
**conflict_sess
)
4462 struct fc_port
*sess
= NULL
, *other_sess
;
4465 *conflict_sess
= NULL
;
4467 list_for_each_entry(other_sess
, &vha
->vp_fcports
, list
) {
4469 other_wwn
= wwn_to_u64(other_sess
->port_name
);
4471 if (wwn
== other_wwn
) {
4477 /* find other sess with nport_id collision */
4478 if (port_id
.b24
== other_sess
->d_id
.b24
) {
4479 if (loop_id
!= other_sess
->loop_id
) {
4480 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x1000c,
4481 "Invalidating sess %p loop_id %d wwn %llx.\n",
4482 other_sess
, other_sess
->loop_id
, other_wwn
);
4485 * logout_on_delete is set by default, but another
4486 * session that has the same s_id/loop_id combo
4487 * might have cleared it when requested this session
4488 * deletion, so don't touch it
4490 qlt_schedule_sess_for_deletion(other_sess
, true);
4493 * Another wwn used to have our s_id/loop_id
4494 * kill the session, but don't free the loop_id
4496 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0xffff,
4497 "Invalidating sess %p loop_id %d wwn %llx.\n",
4498 other_sess
, other_sess
->loop_id
, other_wwn
);
4501 other_sess
->keep_nport_handle
= 1;
4502 *conflict_sess
= other_sess
;
4503 qlt_schedule_sess_for_deletion(other_sess
,
4509 /* find other sess with nport handle collision */
4510 if ((loop_id
== other_sess
->loop_id
) &&
4511 (loop_id
!= FC_NO_LOOP_ID
)) {
4512 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x1000d,
4513 "Invalidating sess %p loop_id %d wwn %llx.\n",
4514 other_sess
, other_sess
->loop_id
, other_wwn
);
4516 /* Same loop_id but different s_id
4517 * Ok to kill and logout */
4518 qlt_schedule_sess_for_deletion(other_sess
, true);
4525 /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */
4526 static int abort_cmds_for_s_id(struct scsi_qla_host
*vha
, port_id_t
*s_id
)
4528 struct qla_tgt_sess_op
*op
;
4529 struct qla_tgt_cmd
*cmd
;
4533 key
= (((u32
)s_id
->b
.domain
<< 16) |
4534 ((u32
)s_id
->b
.area
<< 8) |
4535 ((u32
)s_id
->b
.al_pa
));
4537 spin_lock(&vha
->cmd_list_lock
);
4538 list_for_each_entry(op
, &vha
->qla_sess_op_cmd_list
, cmd_list
) {
4539 uint32_t op_key
= sid_to_key(op
->atio
.u
.isp24
.fcp_hdr
.s_id
);
4541 if (op_key
== key
) {
4547 list_for_each_entry(op
, &vha
->unknown_atio_list
, cmd_list
) {
4548 uint32_t op_key
= sid_to_key(op
->atio
.u
.isp24
.fcp_hdr
.s_id
);
4549 if (op_key
== key
) {
4555 list_for_each_entry(cmd
, &vha
->qla_cmd_list
, cmd_list
) {
4556 uint32_t cmd_key
= sid_to_key(cmd
->atio
.u
.isp24
.fcp_hdr
.s_id
);
4557 if (cmd_key
== key
) {
4562 spin_unlock(&vha
->cmd_list_lock
);
4568 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
4570 static int qlt_24xx_handle_els(struct scsi_qla_host
*vha
,
4571 struct imm_ntfy_from_isp
*iocb
)
4573 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4574 struct qla_hw_data
*ha
= vha
->hw
;
4575 struct fc_port
*sess
= NULL
, *conflict_sess
= NULL
;
4581 struct qlt_plogi_ack_t
*pla
;
4582 unsigned long flags
;
4584 wwn
= wwn_to_u64(iocb
->u
.isp24
.port_name
);
4586 port_id
.b
.domain
= iocb
->u
.isp24
.port_id
[2];
4587 port_id
.b
.area
= iocb
->u
.isp24
.port_id
[1];
4588 port_id
.b
.al_pa
= iocb
->u
.isp24
.port_id
[0];
4589 port_id
.b
.rsvd_1
= 0;
4591 loop_id
= le16_to_cpu(iocb
->u
.isp24
.nport_handle
);
4593 ql_dbg(ql_dbg_disc
, vha
, 0xf026,
4594 "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n",
4595 vha
->vp_idx
, iocb
->u
.isp24
.port_id
[2],
4596 iocb
->u
.isp24
.port_id
[1], iocb
->u
.isp24
.port_id
[0],
4597 iocb
->u
.isp24
.status_subcode
, loop_id
,
4598 iocb
->u
.isp24
.port_name
);
4600 /* res = 1 means ack at the end of thread
4601 * res = 0 means ack async/later.
4603 switch (iocb
->u
.isp24
.status_subcode
) {
4606 /* Mark all stale commands in qla_tgt_wq for deletion */
4607 abort_cmds_for_s_id(vha
, &port_id
);
4610 spin_lock_irqsave(&tgt
->ha
->tgt
.sess_lock
, flags
);
4611 sess
= qlt_find_sess_invalidate_other(vha
, wwn
,
4612 port_id
, loop_id
, &conflict_sess
);
4613 spin_unlock_irqrestore(&tgt
->ha
->tgt
.sess_lock
, flags
);
4616 if (IS_SW_RESV_ADDR(port_id
)) {
4621 pla
= qlt_plogi_ack_find_add(vha
, &port_id
, iocb
);
4623 qlt_send_term_imm_notif(vha
, iocb
, 1);
4629 if (conflict_sess
) {
4630 conflict_sess
->login_gen
++;
4631 qlt_plogi_ack_link(vha
, pla
, conflict_sess
,
4632 QLT_PLOGI_LINK_CONFLICT
);
4637 qla24xx_post_newsess_work(vha
, &port_id
,
4638 iocb
->u
.isp24
.port_name
, pla
);
4643 qlt_plogi_ack_link(vha
, pla
, sess
, QLT_PLOGI_LINK_SAME_WWN
);
4644 sess
->fw_login_state
= DSC_LS_PLOGI_PEND
;
4645 sess
->d_id
= port_id
;
4648 switch (sess
->disc_state
) {
4650 qlt_plogi_ack_unref(vha
, pla
);
4655 * Under normal circumstances we want to release nport handle
4656 * during LOGO process to avoid nport handle leaks inside FW.
4657 * The exception is when LOGO is done while another PLOGI with
4658 * the same nport handle is waiting as might be the case here.
4659 * Note: there is always a possibily of a race where session
4660 * deletion has already started for other reasons (e.g. ACL
4661 * removal) and now PLOGI arrives:
4662 * 1. if PLOGI arrived in FW after nport handle has been freed,
4663 * FW must have assigned this PLOGI a new/same handle and we
4664 * can proceed ACK'ing it as usual when session deletion
4666 * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT
4667 * bit reached it, the handle has now been released. We'll
4668 * get an error when we ACK this PLOGI. Nothing will be sent
4669 * back to initiator. Initiator should eventually retry
4670 * PLOGI and situation will correct itself.
4672 sess
->keep_nport_handle
= ((sess
->loop_id
== loop_id
) &&
4673 (sess
->d_id
.b24
== port_id
.b24
));
4675 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4676 "%s %d %8phC post del sess\n",
4677 __func__
, __LINE__
, sess
->port_name
);
4680 qlt_schedule_sess_for_deletion_lock(sess
);
4687 wd3_lo
= le16_to_cpu(iocb
->u
.isp24
.u
.prli
.wd3_lo
);
4690 spin_lock_irqsave(&tgt
->ha
->tgt
.sess_lock
, flags
);
4691 sess
= qlt_find_sess_invalidate_other(vha
, wwn
, port_id
,
4692 loop_id
, &conflict_sess
);
4693 spin_unlock_irqrestore(&tgt
->ha
->tgt
.sess_lock
, flags
);
4696 if (conflict_sess
) {
4697 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf09b,
4698 "PRLI with conflicting sess %p port %8phC\n",
4699 conflict_sess
, conflict_sess
->port_name
);
4700 qlt_send_term_imm_notif(vha
, iocb
, 1);
4706 if (sess
->fw_login_state
!= DSC_LS_PLOGI_PEND
&&
4707 sess
->fw_login_state
!= DSC_LS_PLOGI_COMP
) {
4709 * Impatient initiator sent PRLI before last
4710 * PLOGI could finish. Will force him to re-try,
4711 * while last one finishes.
4713 ql_log(ql_log_warn
, sess
->vha
, 0xf095,
4714 "sess %p PRLI received, before plogi ack.\n",
4716 qlt_send_term_imm_notif(vha
, iocb
, 1);
4722 * This shouldn't happen under normal circumstances,
4723 * since we have deleted the old session during PLOGI
4725 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf096,
4726 "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n",
4727 sess
->loop_id
, sess
, iocb
->u
.isp24
.nport_handle
);
4730 sess
->loop_id
= loop_id
;
4731 sess
->d_id
= port_id
;
4732 sess
->fw_login_state
= DSC_LS_PRLI_PEND
;
4735 sess
->conf_compl_supported
= 1;
4737 if ((wd3_lo
& BIT_4
) == 0)
4738 sess
->port_type
= FCT_INITIATOR
;
4740 sess
->port_type
= FCT_TARGET
;
4742 res
= 1; /* send notify ack */
4744 /* Make session global (not used in fabric mode) */
4745 if (ha
->current_topology
!= ISP_CFG_F
) {
4747 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4748 "%s %d %8phC post nack\n",
4749 __func__
, __LINE__
, sess
->port_name
);
4750 qla24xx_post_nack_work(vha
, sess
, iocb
,
4754 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4755 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4756 qla2xxx_wake_dpc(vha
);
4760 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4761 "%s %d %8phC post nack\n",
4762 __func__
, __LINE__
, sess
->port_name
);
4763 qla24xx_post_nack_work(vha
, sess
, iocb
,
4771 if (le16_to_cpu(iocb
->u
.isp24
.flags
) &
4772 NOTIFY24XX_FLAGS_GLOBAL_TPRLO
) {
4774 qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
);
4781 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4782 sess
= qla2x00_find_fcport_by_loopid(vha
, loop_id
);
4783 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4787 sess
->fw_login_state
= DSC_LS_LOGO_PEND
;
4788 sess
->logo_ack_needed
= 1;
4789 memcpy(sess
->iocb
, iocb
, IOCB_SIZE
);
4792 res
= qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
);
4794 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4795 "%s: logo %llx res %d sess %p ",
4796 __func__
, wwn
, res
, sess
);
4799 * cmd went upper layer, look for qlt_xmit_tm_rsp()
4800 * for LOGO_ACK & sess delete
4805 /* cmd did not go to upper layer. */
4807 qlt_schedule_sess_for_deletion_lock(sess
);
4810 /* else logo will be ack */
4816 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4817 if (tgt
->link_reinit_iocb_pending
) {
4818 qlt_send_notify_ack(vha
, &tgt
->link_reinit_iocb
,
4820 tgt
->link_reinit_iocb_pending
= 0;
4823 sess
= qla2x00_find_fcport_by_wwpn(vha
,
4824 iocb
->u
.isp24
.port_name
, 1);
4826 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4827 "sess %p lid %d|%d DS %d LS %d\n",
4828 sess
, sess
->loop_id
, loop_id
,
4829 sess
->disc_state
, sess
->fw_login_state
);
4832 res
= 1; /* send notify ack */
4836 case ELS_FLOGI
: /* should never happen */
4838 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf061,
4839 "qla_target(%d): Unsupported ELS command %x "
4840 "received\n", vha
->vp_idx
, iocb
->u
.isp24
.status_subcode
);
4841 res
= qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
);
4849 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
4851 static void qlt_handle_imm_notify(struct scsi_qla_host
*vha
,
4852 struct imm_ntfy_from_isp
*iocb
)
4854 struct qla_hw_data
*ha
= vha
->hw
;
4855 uint32_t add_flags
= 0;
4856 int send_notify_ack
= 1;
4859 status
= le16_to_cpu(iocb
->u
.isp2x
.status
);
4861 case IMM_NTFY_LIP_RESET
:
4863 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf032,
4864 "qla_target(%d): LIP reset (loop %#x), subcode %x\n",
4865 vha
->vp_idx
, le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
4866 iocb
->u
.isp24
.status_subcode
);
4868 if (qlt_reset(vha
, iocb
, QLA_TGT_ABORT_ALL
) == 0)
4869 send_notify_ack
= 0;
4873 case IMM_NTFY_LIP_LINK_REINIT
:
4875 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4876 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf033,
4877 "qla_target(%d): LINK REINIT (loop %#x, "
4878 "subcode %x)\n", vha
->vp_idx
,
4879 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
4880 iocb
->u
.isp24
.status_subcode
);
4881 if (tgt
->link_reinit_iocb_pending
) {
4882 qlt_send_notify_ack(vha
, &tgt
->link_reinit_iocb
,
4885 memcpy(&tgt
->link_reinit_iocb
, iocb
, sizeof(*iocb
));
4886 tgt
->link_reinit_iocb_pending
= 1;
4888 * QLogic requires to wait after LINK REINIT for possible
4889 * PDISC or ADISC ELS commands
4891 send_notify_ack
= 0;
4895 case IMM_NTFY_PORT_LOGOUT
:
4896 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf034,
4897 "qla_target(%d): Port logout (loop "
4898 "%#x, subcode %x)\n", vha
->vp_idx
,
4899 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
4900 iocb
->u
.isp24
.status_subcode
);
4902 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
) == 0)
4903 send_notify_ack
= 0;
4904 /* The sessions will be cleared in the callback, if needed */
4907 case IMM_NTFY_GLBL_TPRLO
:
4908 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf035,
4909 "qla_target(%d): Global TPRLO (%x)\n", vha
->vp_idx
, status
);
4910 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
) == 0)
4911 send_notify_ack
= 0;
4912 /* The sessions will be cleared in the callback, if needed */
4915 case IMM_NTFY_PORT_CONFIG
:
4916 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf036,
4917 "qla_target(%d): Port config changed (%x)\n", vha
->vp_idx
,
4919 if (qlt_reset(vha
, iocb
, QLA_TGT_ABORT_ALL
) == 0)
4920 send_notify_ack
= 0;
4921 /* The sessions will be cleared in the callback, if needed */
4924 case IMM_NTFY_GLBL_LOGO
:
4925 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06a,
4926 "qla_target(%d): Link failure detected\n",
4928 /* I_T nexus loss */
4929 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
) == 0)
4930 send_notify_ack
= 0;
4933 case IMM_NTFY_IOCB_OVERFLOW
:
4934 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06b,
4935 "qla_target(%d): Cannot provide requested "
4936 "capability (IOCB overflowed the immediate notify "
4937 "resource count)\n", vha
->vp_idx
);
4940 case IMM_NTFY_ABORT_TASK
:
4941 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf037,
4942 "qla_target(%d): Abort Task (S %08x I %#x -> "
4943 "L %#x)\n", vha
->vp_idx
,
4944 le16_to_cpu(iocb
->u
.isp2x
.seq_id
),
4945 GET_TARGET_ID(ha
, (struct atio_from_isp
*)iocb
),
4946 le16_to_cpu(iocb
->u
.isp2x
.lun
));
4947 if (qlt_abort_task(vha
, iocb
) == 0)
4948 send_notify_ack
= 0;
4951 case IMM_NTFY_RESOURCE
:
4952 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06c,
4953 "qla_target(%d): Out of resources, host %ld\n",
4954 vha
->vp_idx
, vha
->host_no
);
4957 case IMM_NTFY_MSG_RX
:
4958 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf038,
4959 "qla_target(%d): Immediate notify task %x\n",
4960 vha
->vp_idx
, iocb
->u
.isp2x
.task_flags
);
4961 if (qlt_handle_task_mgmt(vha
, iocb
) == 0)
4962 send_notify_ack
= 0;
4966 if (qlt_24xx_handle_els(vha
, iocb
) == 0)
4967 send_notify_ack
= 0;
4970 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06d,
4971 "qla_target(%d): Received unknown immediate "
4972 "notify status %x\n", vha
->vp_idx
, status
);
4976 if (send_notify_ack
)
4977 qlt_send_notify_ack(vha
, iocb
, add_flags
, 0, 0, 0, 0, 0);
4981 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
4982 * This function sends busy to ISP 2xxx or 24xx.
4984 static int __qlt_send_busy(struct scsi_qla_host
*vha
,
4985 struct atio_from_isp
*atio
, uint16_t status
)
4987 struct ctio7_to_24xx
*ctio24
;
4988 struct qla_hw_data
*ha
= vha
->hw
;
4990 struct fc_port
*sess
= NULL
;
4991 unsigned long flags
;
4993 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4994 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
4995 atio
->u
.isp24
.fcp_hdr
.s_id
);
4996 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4998 qlt_send_term_exchange(vha
, NULL
, atio
, 1, 0);
5001 /* Sending marker isn't necessary, since we called from ISR */
5003 pkt
= (request_t
*)qla2x00_alloc_iocbs(vha
, NULL
);
5005 ql_dbg(ql_dbg_io
, vha
, 0x3063,
5006 "qla_target(%d): %s failed: unable to allocate "
5007 "request packet", vha
->vp_idx
, __func__
);
5011 vha
->tgt_counters
.num_q_full_sent
++;
5012 pkt
->entry_count
= 1;
5013 pkt
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
5015 ctio24
= (struct ctio7_to_24xx
*)pkt
;
5016 ctio24
->entry_type
= CTIO_TYPE7
;
5017 ctio24
->nport_handle
= sess
->loop_id
;
5018 ctio24
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
5019 ctio24
->vp_index
= vha
->vp_idx
;
5020 ctio24
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
5021 ctio24
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
5022 ctio24
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
5023 ctio24
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
5024 ctio24
->u
.status1
.flags
= (atio
->u
.isp24
.attr
<< 9) |
5026 CTIO7_FLAGS_STATUS_MODE_1
| CTIO7_FLAGS_SEND_STATUS
|
5027 CTIO7_FLAGS_DONT_RET_CTIO
);
5029 * CTIO from fw w/o se_cmd doesn't provide enough info to retry it,
5030 * if the explicit conformation is used.
5032 ctio24
->u
.status1
.ox_id
= swab16(atio
->u
.isp24
.fcp_hdr
.ox_id
);
5033 ctio24
->u
.status1
.scsi_status
= cpu_to_le16(status
);
5034 /* Memory Barrier */
5036 qla2x00_start_iocbs(vha
, vha
->req
);
5041 * This routine is used to allocate a command for either a QFull condition
5042 * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go
5046 qlt_alloc_qfull_cmd(struct scsi_qla_host
*vha
,
5047 struct atio_from_isp
*atio
, uint16_t status
, int qfull
)
5049 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5050 struct qla_hw_data
*ha
= vha
->hw
;
5051 struct fc_port
*sess
;
5052 struct se_session
*se_sess
;
5053 struct qla_tgt_cmd
*cmd
;
5056 if (unlikely(tgt
->tgt_stop
)) {
5057 ql_dbg(ql_dbg_io
, vha
, 0x300a,
5058 "New command while device %p is shutting down\n", tgt
);
5062 if ((vha
->hw
->tgt
.num_qfull_cmds_alloc
+ 1) > MAX_QFULL_CMDS_ALLOC
) {
5063 vha
->hw
->tgt
.num_qfull_cmds_dropped
++;
5064 if (vha
->hw
->tgt
.num_qfull_cmds_dropped
>
5065 vha
->qla_stats
.stat_max_qfull_cmds_dropped
)
5066 vha
->qla_stats
.stat_max_qfull_cmds_dropped
=
5067 vha
->hw
->tgt
.num_qfull_cmds_dropped
;
5069 ql_dbg(ql_dbg_io
, vha
, 0x3068,
5070 "qla_target(%d): %s: QFull CMD dropped[%d]\n",
5071 vha
->vp_idx
, __func__
,
5072 vha
->hw
->tgt
.num_qfull_cmds_dropped
);
5074 qlt_chk_exch_leak_thresh_hold(vha
);
5078 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id
5079 (vha
, atio
->u
.isp24
.fcp_hdr
.s_id
);
5083 se_sess
= sess
->se_sess
;
5085 tag
= percpu_ida_alloc(&se_sess
->sess_tag_pool
, TASK_RUNNING
);
5089 cmd
= &((struct qla_tgt_cmd
*)se_sess
->sess_cmd_map
)[tag
];
5091 ql_dbg(ql_dbg_io
, vha
, 0x3009,
5092 "qla_target(%d): %s: Allocation of cmd failed\n",
5093 vha
->vp_idx
, __func__
);
5095 vha
->hw
->tgt
.num_qfull_cmds_dropped
++;
5096 if (vha
->hw
->tgt
.num_qfull_cmds_dropped
>
5097 vha
->qla_stats
.stat_max_qfull_cmds_dropped
)
5098 vha
->qla_stats
.stat_max_qfull_cmds_dropped
=
5099 vha
->hw
->tgt
.num_qfull_cmds_dropped
;
5101 qlt_chk_exch_leak_thresh_hold(vha
);
5105 memset(cmd
, 0, sizeof(struct qla_tgt_cmd
));
5107 qlt_incr_num_pend_cmds(vha
);
5108 INIT_LIST_HEAD(&cmd
->cmd_list
);
5109 memcpy(&cmd
->atio
, atio
, sizeof(*atio
));
5111 cmd
->tgt
= vha
->vha_tgt
.qla_tgt
;
5113 cmd
->reset_count
= vha
->hw
->chip_reset
;
5118 /* NOTE: borrowing the state field to carry the status */
5119 cmd
->state
= status
;
5121 cmd
->term_exchg
= 1;
5123 list_add_tail(&cmd
->cmd_list
, &vha
->hw
->tgt
.q_full_list
);
5125 vha
->hw
->tgt
.num_qfull_cmds_alloc
++;
5126 if (vha
->hw
->tgt
.num_qfull_cmds_alloc
>
5127 vha
->qla_stats
.stat_max_qfull_cmds_alloc
)
5128 vha
->qla_stats
.stat_max_qfull_cmds_alloc
=
5129 vha
->hw
->tgt
.num_qfull_cmds_alloc
;
5133 qlt_free_qfull_cmds(struct scsi_qla_host
*vha
)
5135 struct qla_hw_data
*ha
= vha
->hw
;
5136 unsigned long flags
;
5137 struct qla_tgt_cmd
*cmd
, *tcmd
;
5138 struct list_head free_list
;
5141 if (list_empty(&ha
->tgt
.q_full_list
))
5144 INIT_LIST_HEAD(&free_list
);
5146 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
5148 if (list_empty(&ha
->tgt
.q_full_list
)) {
5149 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
5153 list_for_each_entry_safe(cmd
, tcmd
, &ha
->tgt
.q_full_list
, cmd_list
) {
5155 /* cmd->state is a borrowed field to hold status */
5156 rc
= __qlt_send_busy(vha
, &cmd
->atio
, cmd
->state
);
5157 else if (cmd
->term_exchg
)
5158 rc
= __qlt_send_term_exchange(vha
, NULL
, &cmd
->atio
);
5164 ql_dbg(ql_dbg_io
, vha
, 0x3006,
5165 "%s: busy sent for ox_id[%04x]\n", __func__
,
5166 be16_to_cpu(cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
));
5167 else if (cmd
->term_exchg
)
5168 ql_dbg(ql_dbg_io
, vha
, 0x3007,
5169 "%s: Term exchg sent for ox_id[%04x]\n", __func__
,
5170 be16_to_cpu(cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
));
5172 ql_dbg(ql_dbg_io
, vha
, 0x3008,
5173 "%s: Unexpected cmd in QFull list %p\n", __func__
,
5176 list_del(&cmd
->cmd_list
);
5177 list_add_tail(&cmd
->cmd_list
, &free_list
);
5179 /* piggy back on hardware_lock for protection */
5180 vha
->hw
->tgt
.num_qfull_cmds_alloc
--;
5182 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
5186 list_for_each_entry_safe(cmd
, tcmd
, &free_list
, cmd_list
) {
5187 list_del(&cmd
->cmd_list
);
5188 /* This cmd was never sent to TCM. There is no need
5189 * to schedule free or call free_cmd
5197 qlt_send_busy(struct scsi_qla_host
*vha
,
5198 struct atio_from_isp
*atio
, uint16_t status
)
5202 rc
= __qlt_send_busy(vha
, atio
, status
);
5204 qlt_alloc_qfull_cmd(vha
, atio
, status
, 1);
5208 qlt_chk_qfull_thresh_hold(struct scsi_qla_host
*vha
,
5209 struct atio_from_isp
*atio
, bool ha_locked
)
5211 struct qla_hw_data
*ha
= vha
->hw
;
5213 unsigned long flags
;
5215 if (ha
->tgt
.num_pend_cmds
< Q_FULL_THRESH_HOLD(ha
))
5219 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5220 status
= temp_sam_status
;
5221 qlt_send_busy(vha
, atio
, status
);
5223 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5228 /* ha->hardware_lock supposed to be held on entry */
5229 /* called via callback from qla2xxx */
5230 static void qlt_24xx_atio_pkt(struct scsi_qla_host
*vha
,
5231 struct atio_from_isp
*atio
, uint8_t ha_locked
)
5233 struct qla_hw_data
*ha
= vha
->hw
;
5234 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5236 unsigned long flags
;
5238 if (unlikely(tgt
== NULL
)) {
5239 ql_dbg(ql_dbg_tgt
, vha
, 0x3064,
5240 "ATIO pkt, but no tgt (ha %p)", ha
);
5244 * In tgt_stop mode we also should allow all requests to pass.
5245 * Otherwise, some commands can stuck.
5248 tgt
->atio_irq_cmd_count
++;
5250 switch (atio
->u
.raw
.entry_type
) {
5252 if (unlikely(atio
->u
.isp24
.exchange_addr
==
5253 ATIO_EXCHANGE_ADDRESS_UNKNOWN
)) {
5254 ql_dbg(ql_dbg_io
, vha
, 0x3065,
5255 "qla_target(%d): ATIO_TYPE7 "
5256 "received with UNKNOWN exchange address, "
5257 "sending QUEUE_FULL\n", vha
->vp_idx
);
5259 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5260 qlt_send_busy(vha
, atio
, SAM_STAT_TASK_SET_FULL
);
5262 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5268 if (likely(atio
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
== 0)) {
5269 rc
= qlt_chk_qfull_thresh_hold(vha
, atio
, ha_locked
);
5271 tgt
->atio_irq_cmd_count
--;
5274 rc
= qlt_handle_cmd_for_atio(vha
, atio
);
5276 rc
= qlt_handle_task_mgmt(vha
, atio
);
5278 if (unlikely(rc
!= 0)) {
5282 (&ha
->hardware_lock
, flags
);
5284 #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */
5285 qlt_send_busy(vha
, atio
, SAM_STAT_BUSY
);
5287 qlt_send_term_exchange(vha
, NULL
, atio
, 1, 0);
5291 spin_unlock_irqrestore
5292 (&ha
->hardware_lock
, flags
);
5295 if (tgt
->tgt_stop
) {
5296 ql_dbg(ql_dbg_tgt
, vha
, 0xe059,
5297 "qla_target: Unable to send "
5298 "command to target for req, "
5301 ql_dbg(ql_dbg_tgt
, vha
, 0xe05a,
5302 "qla_target(%d): Unable to send "
5303 "command to target, sending BUSY "
5304 "status.\n", vha
->vp_idx
);
5307 &ha
->hardware_lock
, flags
);
5308 qlt_send_busy(vha
, atio
, SAM_STAT_BUSY
);
5310 spin_unlock_irqrestore(
5311 &ha
->hardware_lock
, flags
);
5317 case IMMED_NOTIFY_TYPE
:
5319 if (unlikely(atio
->u
.isp2x
.entry_status
!= 0)) {
5320 ql_dbg(ql_dbg_tgt
, vha
, 0xe05b,
5321 "qla_target(%d): Received ATIO packet %x "
5322 "with error status %x\n", vha
->vp_idx
,
5323 atio
->u
.raw
.entry_type
,
5324 atio
->u
.isp2x
.entry_status
);
5327 ql_dbg(ql_dbg_tgt
, vha
, 0xe02e, "%s", "IMMED_NOTIFY ATIO");
5330 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5331 qlt_handle_imm_notify(vha
, (struct imm_ntfy_from_isp
*)atio
);
5333 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5338 ql_dbg(ql_dbg_tgt
, vha
, 0xe05c,
5339 "qla_target(%d): Received unknown ATIO atio "
5340 "type %x\n", vha
->vp_idx
, atio
->u
.raw
.entry_type
);
5344 tgt
->atio_irq_cmd_count
--;
5347 /* ha->hardware_lock supposed to be held on entry */
5348 /* called via callback from qla2xxx */
5349 static void qlt_response_pkt(struct scsi_qla_host
*vha
, response_t
*pkt
)
5351 struct qla_hw_data
*ha
= vha
->hw
;
5352 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5354 if (unlikely(tgt
== NULL
)) {
5355 ql_dbg(ql_dbg_tgt
, vha
, 0xe05d,
5356 "qla_target(%d): Response pkt %x received, but no "
5357 "tgt (ha %p)\n", vha
->vp_idx
, pkt
->entry_type
, ha
);
5362 * In tgt_stop mode we also should allow all requests to pass.
5363 * Otherwise, some commands can stuck.
5366 tgt
->irq_cmd_count
++;
5368 switch (pkt
->entry_type
) {
5372 struct ctio7_from_24xx
*entry
= (struct ctio7_from_24xx
*)pkt
;
5373 qlt_do_ctio_completion(vha
, entry
->handle
,
5374 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
5379 case ACCEPT_TGT_IO_TYPE
:
5381 struct atio_from_isp
*atio
= (struct atio_from_isp
*)pkt
;
5383 if (atio
->u
.isp2x
.status
!=
5384 cpu_to_le16(ATIO_CDB_VALID
)) {
5385 ql_dbg(ql_dbg_tgt
, vha
, 0xe05e,
5386 "qla_target(%d): ATIO with error "
5387 "status %x received\n", vha
->vp_idx
,
5388 le16_to_cpu(atio
->u
.isp2x
.status
));
5392 rc
= qlt_chk_qfull_thresh_hold(vha
, atio
, true);
5394 tgt
->irq_cmd_count
--;
5398 rc
= qlt_handle_cmd_for_atio(vha
, atio
);
5399 if (unlikely(rc
!= 0)) {
5401 #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */
5402 qlt_send_busy(vha
, atio
, 0);
5404 qlt_send_term_exchange(vha
, NULL
, atio
, 1, 0);
5407 if (tgt
->tgt_stop
) {
5408 ql_dbg(ql_dbg_tgt
, vha
, 0xe05f,
5409 "qla_target: Unable to send "
5410 "command to target, sending TERM "
5411 "EXCHANGE for rsp\n");
5412 qlt_send_term_exchange(vha
, NULL
,
5415 ql_dbg(ql_dbg_tgt
, vha
, 0xe060,
5416 "qla_target(%d): Unable to send "
5417 "command to target, sending BUSY "
5418 "status\n", vha
->vp_idx
);
5419 qlt_send_busy(vha
, atio
, 0);
5426 case CONTINUE_TGT_IO_TYPE
:
5428 struct ctio_to_2xxx
*entry
= (struct ctio_to_2xxx
*)pkt
;
5429 qlt_do_ctio_completion(vha
, entry
->handle
,
5430 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
5437 struct ctio_to_2xxx
*entry
= (struct ctio_to_2xxx
*)pkt
;
5438 qlt_do_ctio_completion(vha
, entry
->handle
,
5439 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
5444 case IMMED_NOTIFY_TYPE
:
5445 ql_dbg(ql_dbg_tgt
, vha
, 0xe035, "%s", "IMMED_NOTIFY\n");
5446 qlt_handle_imm_notify(vha
, (struct imm_ntfy_from_isp
*)pkt
);
5449 case NOTIFY_ACK_TYPE
:
5450 if (tgt
->notify_ack_expected
> 0) {
5451 struct nack_to_isp
*entry
= (struct nack_to_isp
*)pkt
;
5452 ql_dbg(ql_dbg_tgt
, vha
, 0xe036,
5453 "NOTIFY_ACK seq %08x status %x\n",
5454 le16_to_cpu(entry
->u
.isp2x
.seq_id
),
5455 le16_to_cpu(entry
->u
.isp2x
.status
));
5456 tgt
->notify_ack_expected
--;
5457 if (entry
->u
.isp2x
.status
!=
5458 cpu_to_le16(NOTIFY_ACK_SUCCESS
)) {
5459 ql_dbg(ql_dbg_tgt
, vha
, 0xe061,
5460 "qla_target(%d): NOTIFY_ACK "
5461 "failed %x\n", vha
->vp_idx
,
5462 le16_to_cpu(entry
->u
.isp2x
.status
));
5465 ql_dbg(ql_dbg_tgt
, vha
, 0xe062,
5466 "qla_target(%d): Unexpected NOTIFY_ACK received\n",
5471 case ABTS_RECV_24XX
:
5472 ql_dbg(ql_dbg_tgt
, vha
, 0xe037,
5473 "ABTS_RECV_24XX: instance %d\n", vha
->vp_idx
);
5474 qlt_24xx_handle_abts(vha
, (struct abts_recv_from_24xx
*)pkt
);
5477 case ABTS_RESP_24XX
:
5478 if (tgt
->abts_resp_expected
> 0) {
5479 struct abts_resp_from_24xx_fw
*entry
=
5480 (struct abts_resp_from_24xx_fw
*)pkt
;
5481 ql_dbg(ql_dbg_tgt
, vha
, 0xe038,
5482 "ABTS_RESP_24XX: compl_status %x\n",
5483 entry
->compl_status
);
5484 tgt
->abts_resp_expected
--;
5485 if (le16_to_cpu(entry
->compl_status
) !=
5486 ABTS_RESP_COMPL_SUCCESS
) {
5487 if ((entry
->error_subcode1
== 0x1E) &&
5488 (entry
->error_subcode2
== 0)) {
5490 * We've got a race here: aborted
5491 * exchange not terminated, i.e.
5492 * response for the aborted command was
5493 * sent between the abort request was
5494 * received and processed.
5495 * Unfortunately, the firmware has a
5496 * silly requirement that all aborted
5497 * exchanges must be explicitely
5498 * terminated, otherwise it refuses to
5499 * send responses for the abort
5500 * requests. So, we have to
5501 * (re)terminate the exchange and retry
5502 * the abort response.
5504 qlt_24xx_retry_term_exchange(vha
,
5507 ql_dbg(ql_dbg_tgt
, vha
, 0xe063,
5508 "qla_target(%d): ABTS_RESP_24XX "
5509 "failed %x (subcode %x:%x)",
5510 vha
->vp_idx
, entry
->compl_status
,
5511 entry
->error_subcode1
,
5512 entry
->error_subcode2
);
5515 ql_dbg(ql_dbg_tgt
, vha
, 0xe064,
5516 "qla_target(%d): Unexpected ABTS_RESP_24XX "
5517 "received\n", vha
->vp_idx
);
5522 ql_dbg(ql_dbg_tgt
, vha
, 0xe065,
5523 "qla_target(%d): Received unknown response pkt "
5524 "type %x\n", vha
->vp_idx
, pkt
->entry_type
);
5528 tgt
->irq_cmd_count
--;
5532 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5534 void qlt_async_event(uint16_t code
, struct scsi_qla_host
*vha
,
5537 struct qla_hw_data
*ha
= vha
->hw
;
5538 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5541 if (!ha
->tgt
.tgt_ops
)
5544 if (unlikely(tgt
== NULL
)) {
5545 ql_dbg(ql_dbg_tgt
, vha
, 0xe03a,
5546 "ASYNC EVENT %#x, but no tgt (ha %p)\n", code
, ha
);
5550 if (((code
== MBA_POINT_TO_POINT
) || (code
== MBA_CHG_IN_CONNECTION
)) &&
5554 * In tgt_stop mode we also should allow all requests to pass.
5555 * Otherwise, some commands can stuck.
5558 tgt
->irq_cmd_count
++;
5561 case MBA_RESET
: /* Reset */
5562 case MBA_SYSTEM_ERR
: /* System Error */
5563 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
5564 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
5565 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03a,
5566 "qla_target(%d): System error async event %#x "
5567 "occurred", vha
->vp_idx
, code
);
5569 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up. */
5570 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
5575 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03b,
5576 "qla_target(%d): Async LOOP_UP occurred "
5577 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
,
5578 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
5579 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
5580 if (tgt
->link_reinit_iocb_pending
) {
5581 qlt_send_notify_ack(vha
, (void *)&tgt
->link_reinit_iocb
,
5583 tgt
->link_reinit_iocb_pending
= 0;
5588 case MBA_LIP_OCCURRED
:
5591 case MBA_RSCN_UPDATE
:
5592 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03c,
5593 "qla_target(%d): Async event %#x occurred "
5594 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
, code
,
5595 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
5596 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
5599 case MBA_REJECTED_FCP_CMD
:
5600 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xffff,
5601 "qla_target(%d): Async event LS_REJECT occurred "
5602 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
,
5603 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
5604 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
5606 if (le16_to_cpu(mailbox
[3]) == 1) {
5607 /* exchange starvation. */
5608 vha
->hw
->exch_starvation
++;
5609 if (vha
->hw
->exch_starvation
> 5) {
5610 ql_log(ql_log_warn
, vha
, 0xffff,
5611 "Exchange starvation-. Resetting RISC\n");
5613 vha
->hw
->exch_starvation
= 0;
5614 if (IS_P3P_TYPE(vha
->hw
))
5615 set_bit(FCOE_CTX_RESET_NEEDED
,
5618 set_bit(ISP_ABORT_NEEDED
,
5620 qla2xxx_wake_dpc(vha
);
5625 case MBA_PORT_UPDATE
:
5626 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03d,
5627 "qla_target(%d): Port update async event %#x "
5628 "occurred: updating the ports database (m[0]=%x, m[1]=%x, "
5629 "m[2]=%x, m[3]=%x)", vha
->vp_idx
, code
,
5630 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
5631 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
5633 login_code
= le16_to_cpu(mailbox
[2]);
5634 if (login_code
== 0x4) {
5635 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03e,
5636 "Async MB 2: Got PLOGI Complete\n");
5637 vha
->hw
->exch_starvation
= 0;
5638 } else if (login_code
== 0x7)
5639 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03f,
5640 "Async MB 2: Port Logged Out\n");
5646 tgt
->irq_cmd_count
--;
5649 static fc_port_t
*qlt_get_port_database(struct scsi_qla_host
*vha
,
5652 fc_port_t
*fcport
, *tfcp
, *del
;
5654 unsigned long flags
;
5657 fcport
= kzalloc(sizeof(*fcport
), GFP_KERNEL
);
5659 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06f,
5660 "qla_target(%d): Allocation of tmp FC port failed",
5665 fcport
->loop_id
= loop_id
;
5667 rc
= qla24xx_gpdb_wait(vha
, fcport
, 0);
5668 if (rc
!= QLA_SUCCESS
) {
5669 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf070,
5670 "qla_target(%d): Failed to retrieve fcport "
5671 "information -- get_port_database() returned %x "
5672 "(loop_id=0x%04x)", vha
->vp_idx
, rc
, loop_id
);
5678 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5679 tfcp
= qla2x00_find_fcport_by_wwpn(vha
, fcport
->port_name
, 1);
5682 tfcp
->d_id
= fcport
->d_id
;
5683 tfcp
->port_type
= fcport
->port_type
;
5684 tfcp
->supported_classes
= fcport
->supported_classes
;
5685 tfcp
->flags
|= fcport
->flags
;
5690 if (vha
->hw
->current_topology
== ISP_CFG_F
)
5691 fcport
->flags
|= FCF_FABRIC_DEVICE
;
5693 list_add_tail(&fcport
->list
, &vha
->vp_fcports
);
5694 if (!IS_SW_RESV_ADDR(fcport
->d_id
))
5695 vha
->fcport_count
++;
5696 fcport
->login_gen
++;
5697 fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
5698 fcport
->login_succ
= 1;
5702 fcport
->deleted
= 0;
5703 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5705 switch (vha
->host
->active_mode
) {
5706 case MODE_INITIATOR
:
5709 if (!IS_IIDMA_CAPABLE(vha
->hw
) || !vha
->hw
->flags
.gpsc_supported
) {
5710 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
5711 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
5712 __func__
, __LINE__
, fcport
->port_name
, vha
->fcport_count
);
5713 qla24xx_post_upd_fcport_work(vha
, fcport
);
5715 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
5716 "%s %d %8phC post gpsc fcp_cnt %d\n",
5717 __func__
, __LINE__
, fcport
->port_name
, vha
->fcport_count
);
5718 qla24xx_post_gpsc_work(vha
, fcport
);
5728 qla2x00_free_fcport(del
);
5733 /* Must be called under tgt_mutex */
5734 static struct fc_port
*qlt_make_local_sess(struct scsi_qla_host
*vha
,
5737 struct fc_port
*sess
= NULL
;
5738 fc_port_t
*fcport
= NULL
;
5739 int rc
, global_resets
;
5740 uint16_t loop_id
= 0;
5742 if ((s_id
[0] == 0xFF) && (s_id
[1] == 0xFC)) {
5744 * This is Domain Controller, so it should be
5745 * OK to drop SCSI commands from it.
5747 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf042,
5748 "Unable to find initiator with S_ID %x:%x:%x",
5749 s_id
[0], s_id
[1], s_id
[2]);
5753 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
5757 atomic_read(&vha
->vha_tgt
.qla_tgt
->tgt_global_resets_count
);
5759 rc
= qla24xx_get_loop_id(vha
, s_id
, &loop_id
);
5761 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
5763 ql_log(ql_log_info
, vha
, 0xf071,
5764 "qla_target(%d): Unable to find "
5765 "initiator with S_ID %x:%x:%x",
5766 vha
->vp_idx
, s_id
[0], s_id
[1],
5769 if (rc
== -ENOENT
) {
5770 qlt_port_logo_t logo
;
5771 sid_to_portid(s_id
, &logo
.id
);
5773 qlt_send_first_logo(vha
, &logo
);
5779 fcport
= qlt_get_port_database(vha
, loop_id
);
5781 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
5785 if (global_resets
!=
5786 atomic_read(&vha
->vha_tgt
.qla_tgt
->tgt_global_resets_count
)) {
5787 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf043,
5788 "qla_target(%d): global reset during session discovery "
5789 "(counter was %d, new %d), retrying", vha
->vp_idx
,
5791 atomic_read(&vha
->vha_tgt
.
5792 qla_tgt
->tgt_global_resets_count
));
5796 sess
= qlt_create_sess(vha
, fcport
, true);
5798 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
5803 static void qlt_abort_work(struct qla_tgt
*tgt
,
5804 struct qla_tgt_sess_work_param
*prm
)
5806 struct scsi_qla_host
*vha
= tgt
->vha
;
5807 struct qla_hw_data
*ha
= vha
->hw
;
5808 struct fc_port
*sess
= NULL
;
5809 unsigned long flags
= 0, flags2
= 0;
5814 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags2
);
5819 s_id
[0] = prm
->abts
.fcp_hdr_le
.s_id
[2];
5820 s_id
[1] = prm
->abts
.fcp_hdr_le
.s_id
[1];
5821 s_id
[2] = prm
->abts
.fcp_hdr_le
.s_id
[0];
5823 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
5824 (unsigned char *)&be_s_id
);
5826 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags2
);
5828 sess
= qlt_make_local_sess(vha
, s_id
);
5829 /* sess has got an extra creation ref */
5831 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags2
);
5835 if (sess
->deleted
) {
5840 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
5841 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0xffff,
5842 "%s: kref_get fail %8phC \n",
5843 __func__
, sess
->port_name
);
5849 rc
= __qlt_24xx_handle_abts(vha
, &prm
->abts
, sess
);
5850 ha
->tgt
.tgt_ops
->put_sess(sess
);
5851 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags2
);
5859 ha
->tgt
.tgt_ops
->put_sess(sess
);
5860 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags2
);
5863 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5864 qlt_24xx_send_abts_resp(vha
, &prm
->abts
, FCP_TMF_REJECTED
, false);
5865 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5868 static void qlt_tmr_work(struct qla_tgt
*tgt
,
5869 struct qla_tgt_sess_work_param
*prm
)
5871 struct atio_from_isp
*a
= &prm
->tm_iocb2
;
5872 struct scsi_qla_host
*vha
= tgt
->vha
;
5873 struct qla_hw_data
*ha
= vha
->hw
;
5874 struct fc_port
*sess
= NULL
;
5875 unsigned long flags
;
5876 uint8_t *s_id
= NULL
; /* to hide compiler warnings */
5878 uint32_t lun
, unpacked_lun
;
5882 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
5887 s_id
= prm
->tm_iocb2
.u
.isp24
.fcp_hdr
.s_id
;
5888 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, s_id
);
5890 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
5892 sess
= qlt_make_local_sess(vha
, s_id
);
5893 /* sess has got an extra creation ref */
5895 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
5899 if (sess
->deleted
) {
5904 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
5905 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0xffff,
5906 "%s: kref_get fail %8phC\n",
5907 __func__
, sess
->port_name
);
5914 lun
= a
->u
.isp24
.fcp_cmnd
.lun
;
5915 fn
= a
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
;
5916 unpacked_lun
= scsilun_to_int((struct scsi_lun
*)&lun
);
5918 rc
= qlt_issue_task_mgmt(sess
, unpacked_lun
, fn
, iocb
, 0);
5919 ha
->tgt
.tgt_ops
->put_sess(sess
);
5920 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
5928 ha
->tgt
.tgt_ops
->put_sess(sess
);
5929 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
5931 qlt_send_term_exchange(vha
, NULL
, &prm
->tm_iocb2
, 1, 0);
5934 static void qlt_sess_work_fn(struct work_struct
*work
)
5936 struct qla_tgt
*tgt
= container_of(work
, struct qla_tgt
, sess_work
);
5937 struct scsi_qla_host
*vha
= tgt
->vha
;
5938 unsigned long flags
;
5940 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf000, "Sess work (tgt %p)", tgt
);
5942 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
5943 while (!list_empty(&tgt
->sess_works_list
)) {
5944 struct qla_tgt_sess_work_param
*prm
= list_entry(
5945 tgt
->sess_works_list
.next
, typeof(*prm
),
5946 sess_works_list_entry
);
5949 * This work can be scheduled on several CPUs at time, so we
5950 * must delete the entry to eliminate double processing
5952 list_del(&prm
->sess_works_list_entry
);
5954 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
5956 switch (prm
->type
) {
5957 case QLA_TGT_SESS_WORK_ABORT
:
5958 qlt_abort_work(tgt
, prm
);
5960 case QLA_TGT_SESS_WORK_TM
:
5961 qlt_tmr_work(tgt
, prm
);
5968 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
5972 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
5975 /* Must be called under tgt_host_action_mutex */
5976 int qlt_add_target(struct qla_hw_data
*ha
, struct scsi_qla_host
*base_vha
)
5978 struct qla_tgt
*tgt
;
5980 if (!QLA_TGT_MODE_ENABLED())
5983 if (!IS_TGT_MODE_CAPABLE(ha
)) {
5984 ql_log(ql_log_warn
, base_vha
, 0xe070,
5985 "This adapter does not support target mode.\n");
5989 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe03b,
5990 "Registering target for host %ld(%p).\n", base_vha
->host_no
, ha
);
5992 BUG_ON(base_vha
->vha_tgt
.qla_tgt
!= NULL
);
5994 tgt
= kzalloc(sizeof(struct qla_tgt
), GFP_KERNEL
);
5996 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe066,
5997 "Unable to allocate struct qla_tgt\n");
6001 if (!(base_vha
->host
->hostt
->supported_mode
& MODE_TARGET
))
6002 base_vha
->host
->hostt
->supported_mode
|= MODE_TARGET
;
6005 tgt
->vha
= base_vha
;
6006 init_waitqueue_head(&tgt
->waitQ
);
6007 INIT_LIST_HEAD(&tgt
->del_sess_list
);
6008 spin_lock_init(&tgt
->sess_work_lock
);
6009 INIT_WORK(&tgt
->sess_work
, qlt_sess_work_fn
);
6010 INIT_LIST_HEAD(&tgt
->sess_works_list
);
6011 atomic_set(&tgt
->tgt_global_resets_count
, 0);
6013 base_vha
->vha_tgt
.qla_tgt
= tgt
;
6015 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe067,
6016 "qla_target(%d): using 64 Bit PCI addressing",
6018 tgt
->tgt_enable_64bit_addr
= 1;
6020 tgt
->sg_tablesize
= QLA_TGT_MAX_SG_24XX(base_vha
->req
->length
- 3);
6021 tgt
->datasegs_per_cmd
= QLA_TGT_DATASEGS_PER_CMD_24XX
;
6022 tgt
->datasegs_per_cont
= QLA_TGT_DATASEGS_PER_CONT_24XX
;
6024 mutex_lock(&qla_tgt_mutex
);
6025 list_add_tail(&tgt
->tgt_list_entry
, &qla_tgt_glist
);
6026 mutex_unlock(&qla_tgt_mutex
);
6028 if (ha
->tgt
.tgt_ops
&& ha
->tgt
.tgt_ops
->add_target
)
6029 ha
->tgt
.tgt_ops
->add_target(base_vha
);
6034 /* Must be called under tgt_host_action_mutex */
6035 int qlt_remove_target(struct qla_hw_data
*ha
, struct scsi_qla_host
*vha
)
6037 if (!vha
->vha_tgt
.qla_tgt
)
6040 if (vha
->fc_vport
) {
6041 qlt_release(vha
->vha_tgt
.qla_tgt
);
6045 /* free left over qfull cmds */
6046 qlt_init_term_exchange(vha
);
6048 mutex_lock(&qla_tgt_mutex
);
6049 list_del(&vha
->vha_tgt
.qla_tgt
->tgt_list_entry
);
6050 mutex_unlock(&qla_tgt_mutex
);
6052 ql_dbg(ql_dbg_tgt
, vha
, 0xe03c, "Unregistering target for host %ld(%p)",
6054 qlt_release(vha
->vha_tgt
.qla_tgt
);
6059 void qlt_remove_target_resources(struct qla_hw_data
*ha
)
6061 struct scsi_qla_host
*node
;
6064 btree_for_each_safe32(&ha
->tgt
.host_map
, key
, node
)
6065 btree_remove32(&ha
->tgt
.host_map
, key
);
6067 btree_destroy32(&ha
->tgt
.host_map
);
6070 static void qlt_lport_dump(struct scsi_qla_host
*vha
, u64 wwpn
,
6075 pr_debug("qla2xxx HW vha->node_name: ");
6076 for (i
= 0; i
< WWN_SIZE
; i
++)
6077 pr_debug("%02x ", vha
->node_name
[i
]);
6079 pr_debug("qla2xxx HW vha->port_name: ");
6080 for (i
= 0; i
< WWN_SIZE
; i
++)
6081 pr_debug("%02x ", vha
->port_name
[i
]);
6084 pr_debug("qla2xxx passed configfs WWPN: ");
6085 put_unaligned_be64(wwpn
, b
);
6086 for (i
= 0; i
< WWN_SIZE
; i
++)
6087 pr_debug("%02x ", b
[i
]);
6092 * qla_tgt_lport_register - register lport with external module
6094 * @qla_tgt_ops: Pointer for tcm_qla2xxx qla_tgt_ops
6095 * @wwpn: Passwd FC target WWPN
6096 * @callback: lport initialization callback for tcm_qla2xxx code
6097 * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data
6099 int qlt_lport_register(void *target_lport_ptr
, u64 phys_wwpn
,
6100 u64 npiv_wwpn
, u64 npiv_wwnn
,
6101 int (*callback
)(struct scsi_qla_host
*, void *, u64
, u64
))
6103 struct qla_tgt
*tgt
;
6104 struct scsi_qla_host
*vha
;
6105 struct qla_hw_data
*ha
;
6106 struct Scsi_Host
*host
;
6107 unsigned long flags
;
6111 mutex_lock(&qla_tgt_mutex
);
6112 list_for_each_entry(tgt
, &qla_tgt_glist
, tgt_list_entry
) {
6120 if (!(host
->hostt
->supported_mode
& MODE_TARGET
))
6123 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6124 if ((!npiv_wwpn
|| !npiv_wwnn
) && host
->active_mode
& MODE_TARGET
) {
6125 pr_debug("MODE_TARGET already active on qla2xxx(%d)\n",
6127 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6130 if (tgt
->tgt_stop
) {
6131 pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n",
6133 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6136 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6138 if (!scsi_host_get(host
)) {
6139 ql_dbg(ql_dbg_tgt
, vha
, 0xe068,
6140 "Unable to scsi_host_get() for"
6141 " qla2xxx scsi_host\n");
6144 qlt_lport_dump(vha
, phys_wwpn
, b
);
6146 if (memcmp(vha
->port_name
, b
, WWN_SIZE
)) {
6147 scsi_host_put(host
);
6150 rc
= (*callback
)(vha
, target_lport_ptr
, npiv_wwpn
, npiv_wwnn
);
6152 scsi_host_put(host
);
6154 mutex_unlock(&qla_tgt_mutex
);
6157 mutex_unlock(&qla_tgt_mutex
);
6161 EXPORT_SYMBOL(qlt_lport_register
);
6164 * qla_tgt_lport_deregister - Degister lport
6166 * @vha: Registered scsi_qla_host pointer
6168 void qlt_lport_deregister(struct scsi_qla_host
*vha
)
6170 struct qla_hw_data
*ha
= vha
->hw
;
6171 struct Scsi_Host
*sh
= vha
->host
;
6173 * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data
6175 vha
->vha_tgt
.target_lport_ptr
= NULL
;
6176 ha
->tgt
.tgt_ops
= NULL
;
6178 * Release the Scsi_Host reference for the underlying qla2xxx host
6182 EXPORT_SYMBOL(qlt_lport_deregister
);
6184 /* Must be called under HW lock */
6185 static void qlt_set_mode(struct scsi_qla_host
*vha
)
6187 switch (ql2x_ini_mode
) {
6188 case QLA2XXX_INI_MODE_DISABLED
:
6189 case QLA2XXX_INI_MODE_EXCLUSIVE
:
6190 vha
->host
->active_mode
= MODE_TARGET
;
6192 case QLA2XXX_INI_MODE_ENABLED
:
6193 vha
->host
->active_mode
= MODE_UNKNOWN
;
6195 case QLA2XXX_INI_MODE_DUAL
:
6196 vha
->host
->active_mode
= MODE_DUAL
;
6203 /* Must be called under HW lock */
6204 static void qlt_clear_mode(struct scsi_qla_host
*vha
)
6206 switch (ql2x_ini_mode
) {
6207 case QLA2XXX_INI_MODE_DISABLED
:
6208 vha
->host
->active_mode
= MODE_UNKNOWN
;
6210 case QLA2XXX_INI_MODE_EXCLUSIVE
:
6211 vha
->host
->active_mode
= MODE_INITIATOR
;
6213 case QLA2XXX_INI_MODE_ENABLED
:
6214 case QLA2XXX_INI_MODE_DUAL
:
6215 vha
->host
->active_mode
= MODE_INITIATOR
;
6223 * qla_tgt_enable_vha - NO LOCK HELD
6225 * host_reset, bring up w/ Target Mode Enabled
6228 qlt_enable_vha(struct scsi_qla_host
*vha
)
6230 struct qla_hw_data
*ha
= vha
->hw
;
6231 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
6232 unsigned long flags
;
6233 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
6234 int rspq_ent
= QLA83XX_RSPQ_MSIX_ENTRY_NUMBER
;
6237 ql_dbg(ql_dbg_tgt
, vha
, 0xe069,
6238 "Unable to locate qla_tgt pointer from"
6239 " struct qla_hw_data\n");
6244 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6245 tgt
->tgt_stopped
= 0;
6247 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6250 qla24xx_disable_vp(vha
);
6251 qla24xx_enable_vp(vha
);
6253 if (ha
->msix_entries
) {
6254 ql_dbg(ql_dbg_tgt
, vha
, 0xffff,
6255 "%s: host%ld : vector %d cpu %d\n",
6256 __func__
, vha
->host_no
,
6257 ha
->msix_entries
[rspq_ent
].vector
,
6258 ha
->msix_entries
[rspq_ent
].cpuid
);
6260 ha
->tgt
.rspq_vector_cpuid
=
6261 ha
->msix_entries
[rspq_ent
].cpuid
;
6264 set_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
);
6265 qla2xxx_wake_dpc(base_vha
);
6266 qla2x00_wait_for_hba_online(base_vha
);
6269 EXPORT_SYMBOL(qlt_enable_vha
);
6272 * qla_tgt_disable_vha - NO LOCK HELD
6274 * Disable Target Mode and reset the adapter
6276 static void qlt_disable_vha(struct scsi_qla_host
*vha
)
6278 struct qla_hw_data
*ha
= vha
->hw
;
6279 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
6280 unsigned long flags
;
6283 ql_dbg(ql_dbg_tgt
, vha
, 0xe06a,
6284 "Unable to locate qla_tgt pointer from"
6285 " struct qla_hw_data\n");
6290 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6291 qlt_clear_mode(vha
);
6292 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6294 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
6295 qla2xxx_wake_dpc(vha
);
6296 qla2x00_wait_for_hba_online(vha
);
6300 * Called from qla_init.c:qla24xx_vport_create() contex to setup
6301 * the target mode specific struct scsi_qla_host and struct qla_hw_data
6305 qlt_vport_create(struct scsi_qla_host
*vha
, struct qla_hw_data
*ha
)
6307 vha
->vha_tgt
.qla_tgt
= NULL
;
6309 mutex_init(&vha
->vha_tgt
.tgt_mutex
);
6310 mutex_init(&vha
->vha_tgt
.tgt_host_action_mutex
);
6312 qlt_clear_mode(vha
);
6315 * NOTE: Currently the value is kept the same for <24xx and
6316 * >=24xx ISPs. If it is necessary to change it,
6317 * the check should be added for specific ISPs,
6318 * assigning the value appropriately.
6320 ha
->tgt
.atio_q_length
= ATIO_ENTRY_CNT_24XX
;
6322 qlt_add_target(ha
, vha
);
6326 qlt_rff_id(struct scsi_qla_host
*vha
, struct ct_sns_req
*ct_req
)
6329 * FC-4 Feature bit 0 indicates target functionality to the name server.
6331 if (qla_tgt_mode_enabled(vha
)) {
6332 ct_req
->req
.rff_id
.fc4_feature
= BIT_0
;
6333 } else if (qla_ini_mode_enabled(vha
)) {
6334 ct_req
->req
.rff_id
.fc4_feature
= BIT_1
;
6335 } else if (qla_dual_mode_enabled(vha
))
6336 ct_req
->req
.rff_id
.fc4_feature
= BIT_0
| BIT_1
;
6340 * qlt_init_atio_q_entries() - Initializes ATIO queue entries.
6343 * Beginning of ATIO ring has initialization control block already built
6344 * by nvram config routine.
6346 * Returns 0 on success.
6349 qlt_init_atio_q_entries(struct scsi_qla_host
*vha
)
6351 struct qla_hw_data
*ha
= vha
->hw
;
6353 struct atio_from_isp
*pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring
;
6355 if (qla_ini_mode_enabled(vha
))
6358 for (cnt
= 0; cnt
< ha
->tgt
.atio_q_length
; cnt
++) {
6359 pkt
->u
.raw
.signature
= ATIO_PROCESSED
;
6366 * qlt_24xx_process_atio_queue() - Process ATIO queue entries.
6367 * @ha: SCSI driver HA context
6370 qlt_24xx_process_atio_queue(struct scsi_qla_host
*vha
, uint8_t ha_locked
)
6372 struct qla_hw_data
*ha
= vha
->hw
;
6373 struct atio_from_isp
*pkt
;
6376 if (!ha
->flags
.fw_started
)
6379 while ((ha
->tgt
.atio_ring_ptr
->signature
!= ATIO_PROCESSED
) ||
6380 fcpcmd_is_corrupted(ha
->tgt
.atio_ring_ptr
)) {
6381 pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring_ptr
;
6382 cnt
= pkt
->u
.raw
.entry_count
;
6384 if (unlikely(fcpcmd_is_corrupted(ha
->tgt
.atio_ring_ptr
))) {
6386 * This packet is corrupted. The header + payload
6387 * can not be trusted. There is no point in passing
6390 ql_log(ql_log_warn
, vha
, 0xffff,
6391 "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n",
6392 pkt
->u
.isp24
.fcp_hdr
.s_id
,
6393 be16_to_cpu(pkt
->u
.isp24
.fcp_hdr
.ox_id
),
6394 le32_to_cpu(pkt
->u
.isp24
.exchange_addr
), pkt
);
6396 adjust_corrupted_atio(pkt
);
6397 qlt_send_term_exchange(vha
, NULL
, pkt
, ha_locked
, 0);
6399 qlt_24xx_atio_pkt_all_vps(vha
,
6400 (struct atio_from_isp
*)pkt
, ha_locked
);
6403 for (i
= 0; i
< cnt
; i
++) {
6404 ha
->tgt
.atio_ring_index
++;
6405 if (ha
->tgt
.atio_ring_index
== ha
->tgt
.atio_q_length
) {
6406 ha
->tgt
.atio_ring_index
= 0;
6407 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
6409 ha
->tgt
.atio_ring_ptr
++;
6411 pkt
->u
.raw
.signature
= ATIO_PROCESSED
;
6412 pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring_ptr
;
6417 /* Adjust ring index */
6418 WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha
), ha
->tgt
.atio_ring_index
);
6419 RD_REG_DWORD_RELAXED(ISP_ATIO_Q_OUT(vha
));
6423 qlt_24xx_config_rings(struct scsi_qla_host
*vha
)
6425 struct qla_hw_data
*ha
= vha
->hw
;
6426 if (!QLA_TGT_MODE_ENABLED())
6429 WRT_REG_DWORD(ISP_ATIO_Q_IN(vha
), 0);
6430 WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha
), 0);
6431 RD_REG_DWORD(ISP_ATIO_Q_OUT(vha
));
6433 if (IS_ATIO_MSIX_CAPABLE(ha
)) {
6434 struct qla_msix_entry
*msix
= &ha
->msix_entries
[2];
6435 struct init_cb_24xx
*icb
= (struct init_cb_24xx
*)ha
->init_cb
;
6437 icb
->msix_atio
= cpu_to_le16(msix
->entry
);
6438 ql_dbg(ql_dbg_init
, vha
, 0xf072,
6439 "Registering ICB vector 0x%x for atio que.\n",
6445 qlt_24xx_config_nvram_stage1(struct scsi_qla_host
*vha
, struct nvram_24xx
*nv
)
6447 struct qla_hw_data
*ha
= vha
->hw
;
6451 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
6452 if (!ha
->tgt
.saved_set
) {
6453 /* We save only once */
6454 ha
->tgt
.saved_exchange_count
= nv
->exchange_count
;
6455 ha
->tgt
.saved_firmware_options_1
=
6456 nv
->firmware_options_1
;
6457 ha
->tgt
.saved_firmware_options_2
=
6458 nv
->firmware_options_2
;
6459 ha
->tgt
.saved_firmware_options_3
=
6460 nv
->firmware_options_3
;
6461 ha
->tgt
.saved_set
= 1;
6464 if (qla_tgt_mode_enabled(vha
)) {
6465 nv
->exchange_count
= cpu_to_le16(0xFFFF);
6467 if (ql_dm_tgt_ex_pct
> 100) {
6468 ql_dm_tgt_ex_pct
= 50;
6469 } else if (ql_dm_tgt_ex_pct
== 100) {
6470 /* leave some for FW */
6471 ql_dm_tgt_ex_pct
= 95;
6474 tmp
= ha
->orig_fw_xcb_count
* ql_dm_tgt_ex_pct
;
6480 nv
->exchange_count
= cpu_to_le16(t
);
6483 /* Enable target mode */
6484 nv
->firmware_options_1
|= cpu_to_le32(BIT_4
);
6486 /* Disable ini mode, if requested */
6487 if (qla_tgt_mode_enabled(vha
))
6488 nv
->firmware_options_1
|= cpu_to_le32(BIT_5
);
6490 /* Disable Full Login after LIP */
6491 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
6492 /* Enable initial LIP */
6493 nv
->firmware_options_1
&= cpu_to_le32(~BIT_9
);
6494 if (ql2xtgt_tape_enable
)
6495 /* Enable FC Tape support */
6496 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
6498 /* Disable FC Tape support */
6499 nv
->firmware_options_2
&= cpu_to_le32(~BIT_12
);
6501 /* Disable Full Login after LIP */
6502 nv
->host_p
&= cpu_to_le32(~BIT_10
);
6505 * clear BIT 15 explicitly as we have seen at least
6506 * a couple of instances where this was set and this
6507 * was causing the firmware to not be initialized.
6509 nv
->firmware_options_1
&= cpu_to_le32(~BIT_15
);
6510 /* Enable target PRLI control */
6511 nv
->firmware_options_2
|= cpu_to_le32(BIT_14
);
6513 if (ha
->tgt
.saved_set
) {
6514 nv
->exchange_count
= ha
->tgt
.saved_exchange_count
;
6515 nv
->firmware_options_1
=
6516 ha
->tgt
.saved_firmware_options_1
;
6517 nv
->firmware_options_2
=
6518 ha
->tgt
.saved_firmware_options_2
;
6519 nv
->firmware_options_3
=
6520 ha
->tgt
.saved_firmware_options_3
;
6525 if (ha
->tgt
.enable_class_2
) {
6526 if (vha
->flags
.init_done
)
6527 fc_host_supported_classes(vha
->host
) =
6528 FC_COS_CLASS2
| FC_COS_CLASS3
;
6530 nv
->firmware_options_2
|= cpu_to_le32(BIT_8
);
6532 if (vha
->flags
.init_done
)
6533 fc_host_supported_classes(vha
->host
) = FC_COS_CLASS3
;
6535 nv
->firmware_options_2
&= ~cpu_to_le32(BIT_8
);
6540 qlt_24xx_config_nvram_stage2(struct scsi_qla_host
*vha
,
6541 struct init_cb_24xx
*icb
)
6543 struct qla_hw_data
*ha
= vha
->hw
;
6545 if (!QLA_TGT_MODE_ENABLED())
6548 if (ha
->tgt
.node_name_set
) {
6549 memcpy(icb
->node_name
, ha
->tgt
.tgt_node_name
, WWN_SIZE
);
6550 icb
->firmware_options_1
|= cpu_to_le32(BIT_14
);
6553 /* disable ZIO at start time. */
6554 if (!vha
->flags
.init_done
) {
6556 tmp
= le32_to_cpu(icb
->firmware_options_2
);
6557 tmp
&= ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
6558 icb
->firmware_options_2
= cpu_to_le32(tmp
);
6563 qlt_81xx_config_nvram_stage1(struct scsi_qla_host
*vha
, struct nvram_81xx
*nv
)
6565 struct qla_hw_data
*ha
= vha
->hw
;
6569 if (!QLA_TGT_MODE_ENABLED())
6572 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
6573 if (!ha
->tgt
.saved_set
) {
6574 /* We save only once */
6575 ha
->tgt
.saved_exchange_count
= nv
->exchange_count
;
6576 ha
->tgt
.saved_firmware_options_1
=
6577 nv
->firmware_options_1
;
6578 ha
->tgt
.saved_firmware_options_2
=
6579 nv
->firmware_options_2
;
6580 ha
->tgt
.saved_firmware_options_3
=
6581 nv
->firmware_options_3
;
6582 ha
->tgt
.saved_set
= 1;
6585 if (qla_tgt_mode_enabled(vha
)) {
6586 nv
->exchange_count
= cpu_to_le16(0xFFFF);
6588 if (ql_dm_tgt_ex_pct
> 100) {
6589 ql_dm_tgt_ex_pct
= 50;
6590 } else if (ql_dm_tgt_ex_pct
== 100) {
6591 /* leave some for FW */
6592 ql_dm_tgt_ex_pct
= 95;
6595 tmp
= ha
->orig_fw_xcb_count
* ql_dm_tgt_ex_pct
;
6600 nv
->exchange_count
= cpu_to_le16(t
);
6603 /* Enable target mode */
6604 nv
->firmware_options_1
|= cpu_to_le32(BIT_4
);
6606 /* Disable ini mode, if requested */
6607 if (qla_tgt_mode_enabled(vha
))
6608 nv
->firmware_options_1
|= cpu_to_le32(BIT_5
);
6609 /* Disable Full Login after LIP */
6610 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
6611 /* Enable initial LIP */
6612 nv
->firmware_options_1
&= cpu_to_le32(~BIT_9
);
6614 * clear BIT 15 explicitly as we have seen at
6615 * least a couple of instances where this was set
6616 * and this was causing the firmware to not be
6619 nv
->firmware_options_1
&= cpu_to_le32(~BIT_15
);
6620 if (ql2xtgt_tape_enable
)
6621 /* Enable FC tape support */
6622 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
6624 /* Disable FC tape support */
6625 nv
->firmware_options_2
&= cpu_to_le32(~BIT_12
);
6627 /* Disable Full Login after LIP */
6628 nv
->host_p
&= cpu_to_le32(~BIT_10
);
6629 /* Enable target PRLI control */
6630 nv
->firmware_options_2
|= cpu_to_le32(BIT_14
);
6632 if (ha
->tgt
.saved_set
) {
6633 nv
->exchange_count
= ha
->tgt
.saved_exchange_count
;
6634 nv
->firmware_options_1
=
6635 ha
->tgt
.saved_firmware_options_1
;
6636 nv
->firmware_options_2
=
6637 ha
->tgt
.saved_firmware_options_2
;
6638 nv
->firmware_options_3
=
6639 ha
->tgt
.saved_firmware_options_3
;
6644 if (ha
->tgt
.enable_class_2
) {
6645 if (vha
->flags
.init_done
)
6646 fc_host_supported_classes(vha
->host
) =
6647 FC_COS_CLASS2
| FC_COS_CLASS3
;
6649 nv
->firmware_options_2
|= cpu_to_le32(BIT_8
);
6651 if (vha
->flags
.init_done
)
6652 fc_host_supported_classes(vha
->host
) = FC_COS_CLASS3
;
6654 nv
->firmware_options_2
&= ~cpu_to_le32(BIT_8
);
6659 qlt_81xx_config_nvram_stage2(struct scsi_qla_host
*vha
,
6660 struct init_cb_81xx
*icb
)
6662 struct qla_hw_data
*ha
= vha
->hw
;
6664 if (!QLA_TGT_MODE_ENABLED())
6667 if (ha
->tgt
.node_name_set
) {
6668 memcpy(icb
->node_name
, ha
->tgt
.tgt_node_name
, WWN_SIZE
);
6669 icb
->firmware_options_1
|= cpu_to_le32(BIT_14
);
6672 /* disable ZIO at start time. */
6673 if (!vha
->flags
.init_done
) {
6675 tmp
= le32_to_cpu(icb
->firmware_options_2
);
6676 tmp
&= ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
6677 icb
->firmware_options_2
= cpu_to_le32(tmp
);
6683 qlt_83xx_iospace_config(struct qla_hw_data
*ha
)
6685 if (!QLA_TGT_MODE_ENABLED())
6688 ha
->msix_count
+= 1; /* For ATIO Q */
6692 qlt_24xx_process_response_error(struct scsi_qla_host
*vha
,
6693 struct sts_entry_24xx
*pkt
)
6695 switch (pkt
->entry_type
) {
6696 case ABTS_RECV_24XX
:
6697 case ABTS_RESP_24XX
:
6699 case NOTIFY_ACK_TYPE
:
6708 qlt_modify_vp_config(struct scsi_qla_host
*vha
,
6709 struct vp_config_entry_24xx
*vpmod
)
6711 /* enable target mode. Bit5 = 1 => disable */
6712 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
6713 vpmod
->options_idx1
&= ~BIT_5
;
6715 /* Disable ini mode, if requested. bit4 = 1 => disable */
6716 if (qla_tgt_mode_enabled(vha
))
6717 vpmod
->options_idx1
&= ~BIT_4
;
6721 qlt_probe_one_stage1(struct scsi_qla_host
*base_vha
, struct qla_hw_data
*ha
)
6725 if (!QLA_TGT_MODE_ENABLED())
6728 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
6729 ISP_ATIO_Q_IN(base_vha
) = &ha
->mqiobase
->isp25mq
.atio_q_in
;
6730 ISP_ATIO_Q_OUT(base_vha
) = &ha
->mqiobase
->isp25mq
.atio_q_out
;
6732 ISP_ATIO_Q_IN(base_vha
) = &ha
->iobase
->isp24
.atio_q_in
;
6733 ISP_ATIO_Q_OUT(base_vha
) = &ha
->iobase
->isp24
.atio_q_out
;
6736 mutex_init(&base_vha
->vha_tgt
.tgt_mutex
);
6737 mutex_init(&base_vha
->vha_tgt
.tgt_host_action_mutex
);
6739 INIT_LIST_HEAD(&base_vha
->unknown_atio_list
);
6740 INIT_DELAYED_WORK(&base_vha
->unknown_atio_work
,
6741 qlt_unknown_atio_work_fn
);
6743 qlt_clear_mode(base_vha
);
6745 rc
= btree_init32(&ha
->tgt
.host_map
);
6747 ql_log(ql_log_info
, base_vha
, 0xffff,
6748 "Unable to initialize ha->host_map btree\n");
6750 qlt_update_vp_map(base_vha
, SET_VP_IDX
);
6754 qla83xx_msix_atio_q(int irq
, void *dev_id
)
6756 struct rsp_que
*rsp
;
6757 scsi_qla_host_t
*vha
;
6758 struct qla_hw_data
*ha
;
6759 unsigned long flags
;
6761 rsp
= (struct rsp_que
*) dev_id
;
6763 vha
= pci_get_drvdata(ha
->pdev
);
6765 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags
);
6767 qlt_24xx_process_atio_queue(vha
, 0);
6769 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
, flags
);
6775 qlt_handle_abts_recv_work(struct work_struct
*work
)
6777 struct qla_tgt_sess_op
*op
= container_of(work
,
6778 struct qla_tgt_sess_op
, work
);
6779 scsi_qla_host_t
*vha
= op
->vha
;
6780 struct qla_hw_data
*ha
= vha
->hw
;
6781 unsigned long flags
;
6783 if (qla2x00_reset_active(vha
) || (op
->chip_reset
!= ha
->chip_reset
))
6786 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags
);
6787 qlt_24xx_process_atio_queue(vha
, 0);
6788 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
, flags
);
6790 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6791 qlt_response_pkt_all_vps(vha
, (response_t
*)&op
->atio
);
6792 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6798 qlt_handle_abts_recv(struct scsi_qla_host
*vha
, response_t
*pkt
)
6800 struct qla_tgt_sess_op
*op
;
6802 op
= kzalloc(sizeof(*op
), GFP_ATOMIC
);
6805 /* do not reach for ATIO queue here. This is best effort err
6806 * recovery at this point.
6808 qlt_response_pkt_all_vps(vha
, pkt
);
6812 memcpy(&op
->atio
, pkt
, sizeof(*pkt
));
6814 op
->chip_reset
= vha
->hw
->chip_reset
;
6815 INIT_WORK(&op
->work
, qlt_handle_abts_recv_work
);
6816 queue_work(qla_tgt_wq
, &op
->work
);
6821 qlt_mem_alloc(struct qla_hw_data
*ha
)
6823 if (!QLA_TGT_MODE_ENABLED())
6826 ha
->tgt
.tgt_vp_map
= kzalloc(sizeof(struct qla_tgt_vp_map
) *
6827 MAX_MULTI_ID_FABRIC
, GFP_KERNEL
);
6828 if (!ha
->tgt
.tgt_vp_map
)
6831 ha
->tgt
.atio_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
6832 (ha
->tgt
.atio_q_length
+ 1) * sizeof(struct atio_from_isp
),
6833 &ha
->tgt
.atio_dma
, GFP_KERNEL
);
6834 if (!ha
->tgt
.atio_ring
) {
6835 kfree(ha
->tgt
.tgt_vp_map
);
6842 qlt_mem_free(struct qla_hw_data
*ha
)
6844 if (!QLA_TGT_MODE_ENABLED())
6847 if (ha
->tgt
.atio_ring
) {
6848 dma_free_coherent(&ha
->pdev
->dev
, (ha
->tgt
.atio_q_length
+ 1) *
6849 sizeof(struct atio_from_isp
), ha
->tgt
.atio_ring
,
6852 kfree(ha
->tgt
.tgt_vp_map
);
6855 /* vport_slock to be held by the caller */
6857 qlt_update_vp_map(struct scsi_qla_host
*vha
, int cmd
)
6863 if (!QLA_TGT_MODE_ENABLED())
6866 key
= vha
->d_id
.b24
;
6870 vha
->hw
->tgt
.tgt_vp_map
[vha
->vp_idx
].vha
= vha
;
6873 slot
= btree_lookup32(&vha
->hw
->tgt
.host_map
, key
);
6875 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xffff,
6876 "Save vha in host_map %p %06x\n", vha
, key
);
6877 rc
= btree_insert32(&vha
->hw
->tgt
.host_map
,
6878 key
, vha
, GFP_ATOMIC
);
6880 ql_log(ql_log_info
, vha
, 0xffff,
6881 "Unable to insert s_id into host_map: %06x\n",
6885 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xffff,
6886 "replace existing vha in host_map %p %06x\n", vha
, key
);
6887 btree_update32(&vha
->hw
->tgt
.host_map
, key
, vha
);
6890 vha
->hw
->tgt
.tgt_vp_map
[vha
->vp_idx
].vha
= NULL
;
6893 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xffff,
6894 "clear vha in host_map %p %06x\n", vha
, key
);
6895 slot
= btree_lookup32(&vha
->hw
->tgt
.host_map
, key
);
6897 btree_remove32(&vha
->hw
->tgt
.host_map
, key
);
6903 void qlt_update_host_map(struct scsi_qla_host
*vha
, port_id_t id
)
6905 unsigned long flags
;
6906 struct qla_hw_data
*ha
= vha
->hw
;
6908 if (!vha
->d_id
.b24
) {
6909 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6911 qlt_update_vp_map(vha
, SET_AL_PA
);
6912 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6913 } else if (vha
->d_id
.b24
!= id
.b24
) {
6914 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6915 qlt_update_vp_map(vha
, RESET_AL_PA
);
6917 qlt_update_vp_map(vha
, SET_AL_PA
);
6918 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6922 static int __init
qlt_parse_ini_mode(void)
6924 if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_EXCLUSIVE
) == 0)
6925 ql2x_ini_mode
= QLA2XXX_INI_MODE_EXCLUSIVE
;
6926 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_DISABLED
) == 0)
6927 ql2x_ini_mode
= QLA2XXX_INI_MODE_DISABLED
;
6928 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_ENABLED
) == 0)
6929 ql2x_ini_mode
= QLA2XXX_INI_MODE_ENABLED
;
6930 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_DUAL
) == 0)
6931 ql2x_ini_mode
= QLA2XXX_INI_MODE_DUAL
;
6938 int __init
qlt_init(void)
6942 if (!qlt_parse_ini_mode()) {
6943 ql_log(ql_log_fatal
, NULL
, 0xe06b,
6944 "qlt_parse_ini_mode() failed\n");
6948 if (!QLA_TGT_MODE_ENABLED())
6951 qla_tgt_mgmt_cmd_cachep
= kmem_cache_create("qla_tgt_mgmt_cmd_cachep",
6952 sizeof(struct qla_tgt_mgmt_cmd
), __alignof__(struct
6953 qla_tgt_mgmt_cmd
), 0, NULL
);
6954 if (!qla_tgt_mgmt_cmd_cachep
) {
6955 ql_log(ql_log_fatal
, NULL
, 0xe06d,
6956 "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n");
6960 qla_tgt_plogi_cachep
= kmem_cache_create("qla_tgt_plogi_cachep",
6961 sizeof(struct qlt_plogi_ack_t
), __alignof__(struct qlt_plogi_ack_t
),
6964 if (!qla_tgt_plogi_cachep
) {
6965 ql_log(ql_log_fatal
, NULL
, 0xe06d,
6966 "kmem_cache_create for qla_tgt_plogi_cachep failed\n");
6968 goto out_mgmt_cmd_cachep
;
6971 qla_tgt_mgmt_cmd_mempool
= mempool_create(25, mempool_alloc_slab
,
6972 mempool_free_slab
, qla_tgt_mgmt_cmd_cachep
);
6973 if (!qla_tgt_mgmt_cmd_mempool
) {
6974 ql_log(ql_log_fatal
, NULL
, 0xe06e,
6975 "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n");
6977 goto out_plogi_cachep
;
6980 qla_tgt_wq
= alloc_workqueue("qla_tgt_wq", 0, 0);
6982 ql_log(ql_log_fatal
, NULL
, 0xe06f,
6983 "alloc_workqueue for qla_tgt_wq failed\n");
6985 goto out_cmd_mempool
;
6988 * Return 1 to signal that initiator-mode is being disabled
6990 return (ql2x_ini_mode
== QLA2XXX_INI_MODE_DISABLED
) ? 1 : 0;
6993 mempool_destroy(qla_tgt_mgmt_cmd_mempool
);
6995 kmem_cache_destroy(qla_tgt_plogi_cachep
);
6996 out_mgmt_cmd_cachep
:
6997 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep
);
7003 if (!QLA_TGT_MODE_ENABLED())
7006 destroy_workqueue(qla_tgt_wq
);
7007 mempool_destroy(qla_tgt_mgmt_cmd_mempool
);
7008 kmem_cache_destroy(qla_tgt_plogi_cachep
);
7009 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep
);