1 // SPDX-License-Identifier: GPL-2.0-only
3 * qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx
5 * based on qla2x00t.c code:
7 * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net>
8 * Copyright (C) 2004 - 2005 Leonid Stoljar
9 * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us>
10 * Copyright (C) 2006 - 2010 ID7 Ltd.
12 * Forward port and refactoring to modern qla2xxx and target/configfs
14 * Copyright (C) 2010-2013 Nicholas A. Bellinger <nab@kernel.org>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/types.h>
20 #include <linux/blkdev.h>
21 #include <linux/interrupt.h>
22 #include <linux/pci.h>
23 #include <linux/delay.h>
24 #include <linux/list.h>
25 #include <linux/workqueue.h>
26 #include <linux/unaligned.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_tcq.h>
32 #include "qla_target.h"
34 static int ql2xtgt_tape_enable
;
35 module_param(ql2xtgt_tape_enable
, int, S_IRUGO
|S_IWUSR
);
36 MODULE_PARM_DESC(ql2xtgt_tape_enable
,
37 "Enables Sequence level error recovery (aka FC Tape). Default is 0 - no SLER. 1 - Enable SLER.");
39 static char *qlini_mode
= QLA2XXX_INI_MODE_STR_ENABLED
;
40 module_param(qlini_mode
, charp
, S_IRUGO
);
41 MODULE_PARM_DESC(qlini_mode
,
42 "Determines when initiator mode will be enabled. Possible values: "
43 "\"exclusive\" - initiator mode will be enabled on load, "
44 "disabled on enabling target mode and then on disabling target mode "
46 "\"disabled\" - initiator mode will never be enabled; "
47 "\"dual\" - Initiator Modes will be enabled. Target Mode can be activated "
49 "\"enabled\" (default) - initiator mode will always stay enabled.");
52 module_param(ql2xuctrlirq
, int, 0644);
53 MODULE_PARM_DESC(ql2xuctrlirq
,
54 "User to control IRQ placement via smp_affinity."
55 "Valid with qlini_mode=disabled."
56 "1(default): enable");
58 int ql2x_ini_mode
= QLA2XXX_INI_MODE_EXCLUSIVE
;
60 static int qla_sam_status
= SAM_STAT_BUSY
;
61 static int tc_sam_status
= SAM_STAT_TASK_SET_FULL
; /* target core */
64 * From scsi/fc/fc_fcp.h
66 enum fcp_resp_rsp_codes
{
68 FCP_DATA_LEN_INVALID
= 1,
69 FCP_CMND_FIELDS_INVALID
= 2,
70 FCP_DATA_PARAM_MISMATCH
= 3,
73 FCP_TMF_INVALID_LUN
= 9,
77 * fc_pri_ta from scsi/fc/fc_fcp.h
79 #define FCP_PTA_SIMPLE 0 /* simple task attribute */
80 #define FCP_PTA_HEADQ 1 /* head of queue task attribute */
81 #define FCP_PTA_ORDERED 2 /* ordered task attribute */
82 #define FCP_PTA_ACA 4 /* auto. contingent allegiance */
83 #define FCP_PTA_MASK 7 /* mask for task attribute field */
84 #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */
85 #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */
88 * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which
89 * must be called under HW lock and could unlock/lock it inside.
90 * It isn't an issue, since in the current implementation on the time when
91 * those functions are called:
93 * - Either context is IRQ and only IRQ handler can modify HW data,
94 * including rings related fields,
96 * - Or access to target mode variables from struct qla_tgt doesn't
97 * cross those functions boundaries, except tgt_stop, which
98 * additionally protected by irq_cmd_count.
100 /* Predefs for callbacks handed to qla2xxx LLD */
101 static void qlt_24xx_atio_pkt(struct scsi_qla_host
*ha
,
102 struct atio_from_isp
*pkt
, uint8_t);
103 static void qlt_response_pkt(struct scsi_qla_host
*ha
, struct rsp_que
*rsp
,
105 static int qlt_issue_task_mgmt(struct fc_port
*sess
, u64 lun
,
106 int fn
, void *iocb
, int flags
);
107 static void qlt_send_term_exchange(struct qla_qpair
*, struct qla_tgt_cmd
108 *cmd
, struct atio_from_isp
*atio
, int ha_locked
, int ul_abort
);
109 static void qlt_alloc_qfull_cmd(struct scsi_qla_host
*vha
,
110 struct atio_from_isp
*atio
, uint16_t status
, int qfull
);
111 static void qlt_disable_vha(struct scsi_qla_host
*vha
);
112 static void qlt_clear_tgt_db(struct qla_tgt
*tgt
);
113 static void qlt_send_notify_ack(struct qla_qpair
*qpair
,
114 struct imm_ntfy_from_isp
*ntfy
,
115 uint32_t add_flags
, uint16_t resp_code
, int resp_code_valid
,
116 uint16_t srr_flags
, uint16_t srr_reject_code
, uint8_t srr_explan
);
117 static void qlt_send_term_imm_notif(struct scsi_qla_host
*vha
,
118 struct imm_ntfy_from_isp
*imm
, int ha_locked
);
119 static struct fc_port
*qlt_create_sess(struct scsi_qla_host
*vha
,
120 fc_port_t
*fcport
, bool local
);
121 void qlt_unreg_sess(struct fc_port
*sess
);
122 static void qlt_24xx_handle_abts(struct scsi_qla_host
*,
123 struct abts_recv_from_24xx
*);
124 static void qlt_send_busy(struct qla_qpair
*, struct atio_from_isp
*,
126 static int qlt_check_reserve_free_req(struct qla_qpair
*qpair
, uint32_t);
127 static inline uint32_t qlt_make_handle(struct qla_qpair
*);
132 static struct kmem_cache
*qla_tgt_mgmt_cmd_cachep
;
133 struct kmem_cache
*qla_tgt_plogi_cachep
;
134 static mempool_t
*qla_tgt_mgmt_cmd_mempool
;
135 static struct workqueue_struct
*qla_tgt_wq
;
136 static DEFINE_MUTEX(qla_tgt_mutex
);
137 static LIST_HEAD(qla_tgt_glist
);
139 static const char *prot_op_str(u32 prot_op
)
142 case TARGET_PROT_NORMAL
: return "NORMAL";
143 case TARGET_PROT_DIN_INSERT
: return "DIN_INSERT";
144 case TARGET_PROT_DOUT_INSERT
: return "DOUT_INSERT";
145 case TARGET_PROT_DIN_STRIP
: return "DIN_STRIP";
146 case TARGET_PROT_DOUT_STRIP
: return "DOUT_STRIP";
147 case TARGET_PROT_DIN_PASS
: return "DIN_PASS";
148 case TARGET_PROT_DOUT_PASS
: return "DOUT_PASS";
149 default: return "UNKNOWN";
153 /* This API intentionally takes dest as a parameter, rather than returning
154 * int value to avoid caller forgetting to issue wmb() after the store */
155 void qlt_do_generation_tick(struct scsi_qla_host
*vha
, int *dest
)
157 scsi_qla_host_t
*base_vha
= pci_get_drvdata(vha
->hw
->pdev
);
158 *dest
= atomic_inc_return(&base_vha
->generation_tick
);
163 /* Might release hw lock, then reaquire!! */
164 static inline int qlt_issue_marker(struct scsi_qla_host
*vha
, int vha_locked
)
166 /* Send marker if required */
167 if (unlikely(vha
->marker_needed
!= 0)) {
168 int rc
= qla2x00_issue_marker(vha
, vha_locked
);
170 if (rc
!= QLA_SUCCESS
) {
171 ql_dbg(ql_dbg_tgt
, vha
, 0xe03d,
172 "qla_target(%d): issue_marker() failed\n",
180 struct scsi_qla_host
*qla_find_host_by_d_id(struct scsi_qla_host
*vha
,
183 struct scsi_qla_host
*host
;
186 if (vha
->d_id
.b
.area
== d_id
.area
&&
187 vha
->d_id
.b
.domain
== d_id
.domain
&&
188 vha
->d_id
.b
.al_pa
== d_id
.al_pa
)
191 key
= be_to_port_id(d_id
).b24
;
193 host
= btree_lookup32(&vha
->hw
->host_map
, key
);
195 ql_dbg(ql_dbg_tgt_mgt
+ ql_dbg_verbose
, vha
, 0xf005,
196 "Unable to find host %06x\n", key
);
201 static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host
*vha
)
205 spin_lock_irqsave(&vha
->hw
->tgt
.q_full_lock
, flags
);
207 vha
->hw
->tgt
.num_pend_cmds
++;
208 if (vha
->hw
->tgt
.num_pend_cmds
> vha
->qla_stats
.stat_max_pend_cmds
)
209 vha
->qla_stats
.stat_max_pend_cmds
=
210 vha
->hw
->tgt
.num_pend_cmds
;
211 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
213 static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host
*vha
)
217 spin_lock_irqsave(&vha
->hw
->tgt
.q_full_lock
, flags
);
218 vha
->hw
->tgt
.num_pend_cmds
--;
219 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
223 static void qlt_queue_unknown_atio(scsi_qla_host_t
*vha
,
224 struct atio_from_isp
*atio
, uint8_t ha_locked
)
226 struct qla_tgt_sess_op
*u
;
227 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
231 ql_dbg(ql_dbg_async
, vha
, 0x502c,
232 "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped",
237 u
= kzalloc(sizeof(*u
), GFP_ATOMIC
);
242 memcpy(&u
->atio
, atio
, sizeof(*atio
));
243 INIT_LIST_HEAD(&u
->cmd_list
);
245 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
246 list_add_tail(&u
->cmd_list
, &vha
->unknown_atio_list
);
247 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
249 schedule_delayed_work(&vha
->unknown_atio_work
, 1);
255 qlt_send_term_exchange(vha
->hw
->base_qpair
, NULL
, atio
, ha_locked
, 0);
259 static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host
*vha
,
262 struct qla_tgt_sess_op
*u
, *t
;
263 scsi_qla_host_t
*host
;
264 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
268 list_for_each_entry_safe(u
, t
, &vha
->unknown_atio_list
, cmd_list
) {
270 ql_dbg(ql_dbg_async
, vha
, 0x502e,
271 "Freeing unknown %s %p, because of Abort\n",
273 qlt_send_term_exchange(vha
->hw
->base_qpair
, NULL
,
274 &u
->atio
, ha_locked
, 0);
278 host
= qla_find_host_by_d_id(vha
, u
->atio
.u
.isp24
.fcp_hdr
.d_id
);
280 ql_dbg(ql_dbg_async
+ ql_dbg_verbose
, vha
, 0x502f,
281 "Requeuing unknown ATIO_TYPE7 %p\n", u
);
282 qlt_24xx_atio_pkt(host
, &u
->atio
, ha_locked
);
283 } else if (tgt
->tgt_stop
) {
284 ql_dbg(ql_dbg_async
+ ql_dbg_verbose
, vha
, 0x503a,
285 "Freeing unknown %s %p, because tgt is being stopped\n",
287 qlt_send_term_exchange(vha
->hw
->base_qpair
, NULL
,
288 &u
->atio
, ha_locked
, 0);
290 ql_dbg(ql_dbg_async
+ ql_dbg_verbose
, vha
, 0x503d,
291 "Reschedule u %p, vha %p, host %p\n", u
, vha
, host
);
294 schedule_delayed_work(&vha
->unknown_atio_work
,
301 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
302 list_del(&u
->cmd_list
);
303 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
308 void qlt_unknown_atio_work_fn(struct work_struct
*work
)
310 struct scsi_qla_host
*vha
= container_of(to_delayed_work(work
),
311 struct scsi_qla_host
, unknown_atio_work
);
313 qlt_try_to_dequeue_unknown_atios(vha
, 0);
316 static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host
*vha
,
317 struct atio_from_isp
*atio
, uint8_t ha_locked
)
319 ql_dbg(ql_dbg_tgt
, vha
, 0xe072,
320 "%s: qla_target(%d): type %x ox_id %04x\n",
321 __func__
, vha
->vp_idx
, atio
->u
.raw
.entry_type
,
322 be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
));
324 switch (atio
->u
.raw
.entry_type
) {
327 struct scsi_qla_host
*host
= qla_find_host_by_d_id(vha
,
328 atio
->u
.isp24
.fcp_hdr
.d_id
);
329 if (unlikely(NULL
== host
)) {
330 ql_dbg(ql_dbg_tgt
, vha
, 0xe03e,
331 "qla_target(%d): Received ATIO_TYPE7 "
332 "with unknown d_id %x:%x:%x\n", vha
->vp_idx
,
333 atio
->u
.isp24
.fcp_hdr
.d_id
.domain
,
334 atio
->u
.isp24
.fcp_hdr
.d_id
.area
,
335 atio
->u
.isp24
.fcp_hdr
.d_id
.al_pa
);
338 qlt_queue_unknown_atio(vha
, atio
, ha_locked
);
341 if (unlikely(!list_empty(&vha
->unknown_atio_list
)))
342 qlt_try_to_dequeue_unknown_atios(vha
, ha_locked
);
344 qlt_24xx_atio_pkt(host
, atio
, ha_locked
);
348 case IMMED_NOTIFY_TYPE
:
350 struct scsi_qla_host
*host
= vha
;
351 struct imm_ntfy_from_isp
*entry
=
352 (struct imm_ntfy_from_isp
*)atio
;
354 qlt_issue_marker(vha
, ha_locked
);
356 if ((entry
->u
.isp24
.vp_index
!= 0xFF) &&
357 (entry
->u
.isp24
.nport_handle
!= cpu_to_le16(0xFFFF))) {
358 host
= qla_find_host_by_vp_idx(vha
,
359 entry
->u
.isp24
.vp_index
);
360 if (unlikely(!host
)) {
361 ql_dbg(ql_dbg_tgt
, vha
, 0xe03f,
362 "qla_target(%d): Received "
363 "ATIO (IMMED_NOTIFY_TYPE) "
364 "with unknown vp_index %d\n",
365 vha
->vp_idx
, entry
->u
.isp24
.vp_index
);
369 qlt_24xx_atio_pkt(host
, atio
, ha_locked
);
373 case VP_RPT_ID_IOCB_TYPE
:
374 qla24xx_report_id_acquisition(vha
,
375 (struct vp_rpt_id_entry_24xx
*)atio
);
380 struct abts_recv_from_24xx
*entry
=
381 (struct abts_recv_from_24xx
*)atio
;
382 struct scsi_qla_host
*host
= qla_find_host_by_vp_idx(vha
,
386 if (unlikely(!host
)) {
387 ql_dbg(ql_dbg_tgt
, vha
, 0xe00a,
388 "qla_target(%d): Response pkt (ABTS_RECV_24XX) "
389 "received, with unknown vp_index %d\n",
390 vha
->vp_idx
, entry
->vp_index
);
394 spin_lock_irqsave(&host
->hw
->hardware_lock
, flags
);
395 qlt_24xx_handle_abts(host
, (struct abts_recv_from_24xx
*)atio
);
397 spin_unlock_irqrestore(&host
->hw
->hardware_lock
, flags
);
401 /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */
404 ql_dbg(ql_dbg_tgt
, vha
, 0xe040,
405 "qla_target(%d): Received unknown ATIO atio "
406 "type %x\n", vha
->vp_idx
, atio
->u
.raw
.entry_type
);
413 void qlt_response_pkt_all_vps(struct scsi_qla_host
*vha
,
414 struct rsp_que
*rsp
, response_t
*pkt
)
416 switch (pkt
->entry_type
) {
418 ql_dbg(ql_dbg_tgt
, vha
, 0xe073,
419 "qla_target(%d):%s: CRC2 Response pkt\n",
420 vha
->vp_idx
, __func__
);
424 struct ctio7_from_24xx
*entry
= (struct ctio7_from_24xx
*)pkt
;
425 struct scsi_qla_host
*host
= qla_find_host_by_vp_idx(vha
,
427 if (unlikely(!host
)) {
428 ql_dbg(ql_dbg_tgt
, vha
, 0xe041,
429 "qla_target(%d): Response pkt (CTIO_TYPE7) "
430 "received, with unknown vp_index %d\n",
431 vha
->vp_idx
, entry
->vp_index
);
434 qlt_response_pkt(host
, rsp
, pkt
);
438 case IMMED_NOTIFY_TYPE
:
440 struct scsi_qla_host
*host
;
441 struct imm_ntfy_from_isp
*entry
=
442 (struct imm_ntfy_from_isp
*)pkt
;
444 host
= qla_find_host_by_vp_idx(vha
, entry
->u
.isp24
.vp_index
);
445 if (unlikely(!host
)) {
446 ql_dbg(ql_dbg_tgt
, vha
, 0xe042,
447 "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) "
448 "received, with unknown vp_index %d\n",
449 vha
->vp_idx
, entry
->u
.isp24
.vp_index
);
452 qlt_response_pkt(host
, rsp
, pkt
);
456 case NOTIFY_ACK_TYPE
:
458 struct scsi_qla_host
*host
= vha
;
459 struct nack_to_isp
*entry
= (struct nack_to_isp
*)pkt
;
461 if (0xFF != entry
->u
.isp24
.vp_index
) {
462 host
= qla_find_host_by_vp_idx(vha
,
463 entry
->u
.isp24
.vp_index
);
464 if (unlikely(!host
)) {
465 ql_dbg(ql_dbg_tgt
, vha
, 0xe043,
466 "qla_target(%d): Response "
467 "pkt (NOTIFY_ACK_TYPE) "
468 "received, with unknown "
469 "vp_index %d\n", vha
->vp_idx
,
470 entry
->u
.isp24
.vp_index
);
474 qlt_response_pkt(host
, rsp
, pkt
);
480 struct abts_recv_from_24xx
*entry
=
481 (struct abts_recv_from_24xx
*)pkt
;
482 struct scsi_qla_host
*host
= qla_find_host_by_vp_idx(vha
,
484 if (unlikely(!host
)) {
485 ql_dbg(ql_dbg_tgt
, vha
, 0xe044,
486 "qla_target(%d): Response pkt "
487 "(ABTS_RECV_24XX) received, with unknown "
488 "vp_index %d\n", vha
->vp_idx
, entry
->vp_index
);
491 qlt_response_pkt(host
, rsp
, pkt
);
497 struct abts_resp_to_24xx
*entry
=
498 (struct abts_resp_to_24xx
*)pkt
;
499 struct scsi_qla_host
*host
= qla_find_host_by_vp_idx(vha
,
501 if (unlikely(!host
)) {
502 ql_dbg(ql_dbg_tgt
, vha
, 0xe045,
503 "qla_target(%d): Response pkt "
504 "(ABTS_RECV_24XX) received, with unknown "
505 "vp_index %d\n", vha
->vp_idx
, entry
->vp_index
);
508 qlt_response_pkt(host
, rsp
, pkt
);
512 qlt_response_pkt(vha
, rsp
, pkt
);
519 * All qlt_plogi_ack_t operations are protected by hardware_lock
521 static int qla24xx_post_nack_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
522 struct imm_ntfy_from_isp
*ntfy
, int type
)
524 struct qla_work_evt
*e
;
526 e
= qla2x00_alloc_work(vha
, QLA_EVT_NACK
);
528 return QLA_FUNCTION_FAILED
;
530 e
->u
.nack
.fcport
= fcport
;
531 e
->u
.nack
.type
= type
;
532 memcpy(e
->u
.nack
.iocb
, ntfy
, sizeof(struct imm_ntfy_from_isp
));
533 return qla2x00_post_work(vha
, e
);
536 static void qla2x00_async_nack_sp_done(srb_t
*sp
, int res
)
538 struct scsi_qla_host
*vha
= sp
->vha
;
541 ql_dbg(ql_dbg_disc
, vha
, 0x20f2,
542 "Async done-%s res %x %8phC type %d\n",
543 sp
->name
, res
, sp
->fcport
->port_name
, sp
->type
);
545 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
546 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
547 sp
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
551 sp
->fcport
->login_gen
++;
552 sp
->fcport
->fw_login_state
= DSC_LS_PLOGI_COMP
;
553 sp
->fcport
->logout_on_delete
= 1;
554 sp
->fcport
->plogi_nack_done_deadline
= jiffies
+ HZ
;
555 sp
->fcport
->send_els_logo
= 0;
557 if (sp
->fcport
->flags
& FCF_FCSP_DEVICE
) {
558 ql_dbg(ql_dbg_edif
, vha
, 0x20ef,
559 "%s %8phC edif: PLOGI- AUTH WAIT\n", __func__
,
560 sp
->fcport
->port_name
);
561 qla2x00_set_fcport_disc_state(sp
->fcport
,
562 DSC_LOGIN_AUTH_PEND
);
563 qla2x00_post_aen_work(vha
, FCH_EVT_PORT_ONLINE
,
564 sp
->fcport
->d_id
.b24
);
565 qla_edb_eventcreate(vha
, VND_CMD_AUTH_STATE_NEEDED
, sp
->fcport
->d_id
.b24
,
571 sp
->fcport
->fw_login_state
= DSC_LS_PRLI_COMP
;
572 sp
->fcport
->deleted
= 0;
573 sp
->fcport
->send_els_logo
= 0;
575 if (!sp
->fcport
->login_succ
&&
576 !IS_SW_RESV_ADDR(sp
->fcport
->d_id
)) {
577 sp
->fcport
->login_succ
= 1;
580 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
581 qla24xx_sched_upd_fcport(sp
->fcport
);
582 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
584 sp
->fcport
->login_retry
= 0;
585 qla2x00_set_fcport_disc_state(sp
->fcport
,
587 sp
->fcport
->deleted
= 0;
588 sp
->fcport
->logout_on_delete
= 1;
593 sp
->fcport
->login_gen
++;
594 sp
->fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
595 qlt_logo_completion_handler(sp
->fcport
, MBS_COMMAND_COMPLETE
);
598 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
600 kref_put(&sp
->cmd_kref
, qla2x00_sp_release
);
603 int qla24xx_async_notify_ack(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
604 struct imm_ntfy_from_isp
*ntfy
, int type
)
606 int rval
= QLA_FUNCTION_FAILED
;
610 fcport
->flags
|= FCF_ASYNC_SENT
;
613 fcport
->fw_login_state
= DSC_LS_PLOGI_PEND
;
615 if (vha
->hw
->flags
.edif_enabled
&&
616 (le16_to_cpu(ntfy
->u
.isp24
.flags
) & NOTIFY24XX_FLAGS_FCSP
))
617 fcport
->flags
|= FCF_FCSP_DEVICE
;
620 fcport
->fw_login_state
= DSC_LS_PRLI_PEND
;
625 fcport
->fw_login_state
= DSC_LS_LOGO_PEND
;
630 sp
= qla2x00_get_sp(vha
, fcport
, GFP_ATOMIC
);
636 qla2x00_init_async_sp(sp
, qla2x00_get_async_timeout(vha
) + 2,
637 qla2x00_async_nack_sp_done
);
639 sp
->u
.iocb_cmd
.u
.nack
.ntfy
= ntfy
;
641 ql_dbg(ql_dbg_disc
, vha
, 0x20f4,
642 "Async-%s %8phC hndl %x %s\n",
643 sp
->name
, fcport
->port_name
, sp
->handle
, c
);
645 rval
= qla2x00_start_sp(sp
);
646 if (rval
!= QLA_SUCCESS
)
652 kref_put(&sp
->cmd_kref
, qla2x00_sp_release
);
654 fcport
->flags
&= ~FCF_ASYNC_SENT
;
658 void qla24xx_do_nack_work(struct scsi_qla_host
*vha
, struct qla_work_evt
*e
)
662 switch (e
->u
.nack
.type
) {
664 t
= e
->u
.nack
.fcport
;
665 flush_work(&t
->del_work
);
666 flush_work(&t
->free_work
);
667 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
668 t
= qlt_create_sess(vha
, e
->u
.nack
.fcport
, 0);
669 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
671 ql_log(ql_log_info
, vha
, 0xd034,
672 "%s create sess success %p", __func__
, t
);
673 /* create sess has an extra kref */
674 vha
->hw
->tgt
.tgt_ops
->put_sess(e
->u
.nack
.fcport
);
678 qla24xx_async_notify_ack(vha
, e
->u
.nack
.fcport
,
679 (struct imm_ntfy_from_isp
*)e
->u
.nack
.iocb
, e
->u
.nack
.type
);
682 void qla24xx_delete_sess_fn(struct work_struct
*work
)
684 fc_port_t
*fcport
= container_of(work
, struct fc_port
, del_work
);
685 struct qla_hw_data
*ha
= NULL
;
687 if (!fcport
|| !fcport
->vha
|| !fcport
->vha
->hw
)
690 ha
= fcport
->vha
->hw
;
692 if (fcport
->se_sess
) {
693 ha
->tgt
.tgt_ops
->shutdown_sess(fcport
);
694 ha
->tgt
.tgt_ops
->put_sess(fcport
);
696 qlt_unreg_sess(fcport
);
701 * Called from qla2x00_reg_remote_port()
703 void qlt_fc_port_added(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
705 struct qla_hw_data
*ha
= vha
->hw
;
706 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
707 struct fc_port
*sess
= fcport
;
710 if (!vha
->hw
->tgt
.tgt_ops
)
713 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
715 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
719 if (fcport
->disc_state
== DSC_DELETE_PEND
) {
720 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
724 if (!sess
->se_sess
) {
725 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
727 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
728 sess
= qlt_create_sess(vha
, fcport
, false);
729 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
731 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
733 if (fcport
->fw_login_state
== DSC_LS_PRLI_COMP
) {
734 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
738 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
739 ql_dbg(ql_dbg_disc
, vha
, 0x2107,
740 "%s: kref_get fail sess %8phC \n",
741 __func__
, sess
->port_name
);
742 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
746 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04c,
747 "qla_target(%u): %ssession for port %8phC "
748 "(loop ID %d) reappeared\n", vha
->vp_idx
,
749 sess
->local
? "local " : "", sess
->port_name
, sess
->loop_id
);
751 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf007,
752 "Reappeared sess %p\n", sess
);
754 ha
->tgt
.tgt_ops
->update_sess(sess
, fcport
->d_id
,
756 (fcport
->flags
& FCF_CONF_COMP_SUPPORTED
));
759 if (sess
&& sess
->local
) {
760 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04d,
761 "qla_target(%u): local session for "
762 "port %8phC (loop ID %d) became global\n", vha
->vp_idx
,
763 fcport
->port_name
, sess
->loop_id
);
766 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
768 ha
->tgt
.tgt_ops
->put_sess(sess
);
772 * This is a zero-base ref-counting solution, since hardware_lock
773 * guarantees that ref_count is not modified concurrently.
774 * Upon successful return content of iocb is undefined
776 static struct qlt_plogi_ack_t
*
777 qlt_plogi_ack_find_add(struct scsi_qla_host
*vha
, port_id_t
*id
,
778 struct imm_ntfy_from_isp
*iocb
)
780 struct qlt_plogi_ack_t
*pla
;
782 lockdep_assert_held(&vha
->hw
->hardware_lock
);
784 list_for_each_entry(pla
, &vha
->plogi_ack_list
, list
) {
785 if (pla
->id
.b24
== id
->b24
) {
786 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
, vha
, 0x210d,
787 "%s %d %8phC Term INOT due to new INOT",
789 pla
->iocb
.u
.isp24
.port_name
);
790 qlt_send_term_imm_notif(vha
, &pla
->iocb
, 1);
791 memcpy(&pla
->iocb
, iocb
, sizeof(pla
->iocb
));
796 pla
= kmem_cache_zalloc(qla_tgt_plogi_cachep
, GFP_ATOMIC
);
798 ql_dbg(ql_dbg_async
, vha
, 0x5088,
799 "qla_target(%d): Allocation of plogi_ack failed\n",
804 memcpy(&pla
->iocb
, iocb
, sizeof(pla
->iocb
));
806 list_add_tail(&pla
->list
, &vha
->plogi_ack_list
);
811 void qlt_plogi_ack_unref(struct scsi_qla_host
*vha
,
812 struct qlt_plogi_ack_t
*pla
)
814 struct imm_ntfy_from_isp
*iocb
= &pla
->iocb
;
817 fc_port_t
*fcport
= pla
->fcport
;
819 BUG_ON(!pla
->ref_count
);
825 ql_dbg(ql_dbg_disc
, vha
, 0x5089,
826 "Sending PLOGI ACK to wwn %8phC s_id %02x:%02x:%02x loop_id %#04x"
827 " exch %#x ox_id %#x\n", iocb
->u
.isp24
.port_name
,
828 iocb
->u
.isp24
.port_id
[2], iocb
->u
.isp24
.port_id
[1],
829 iocb
->u
.isp24
.port_id
[0],
830 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
831 iocb
->u
.isp24
.exchange_address
, iocb
->ox_id
);
833 port_id
.b
.domain
= iocb
->u
.isp24
.port_id
[2];
834 port_id
.b
.area
= iocb
->u
.isp24
.port_id
[1];
835 port_id
.b
.al_pa
= iocb
->u
.isp24
.port_id
[0];
836 port_id
.b
.rsvd_1
= 0;
838 loop_id
= le16_to_cpu(iocb
->u
.isp24
.nport_handle
);
840 fcport
->loop_id
= loop_id
;
841 fcport
->d_id
= port_id
;
842 if (iocb
->u
.isp24
.status_subcode
== ELS_PLOGI
)
843 qla24xx_post_nack_work(vha
, fcport
, iocb
, SRB_NACK_PLOGI
);
845 qla24xx_post_nack_work(vha
, fcport
, iocb
, SRB_NACK_PRLI
);
847 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
848 if (fcport
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] == pla
)
849 fcport
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] = NULL
;
850 if (fcport
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
] == pla
)
851 fcport
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
] = NULL
;
854 list_del(&pla
->list
);
855 kmem_cache_free(qla_tgt_plogi_cachep
, pla
);
859 qlt_plogi_ack_link(struct scsi_qla_host
*vha
, struct qlt_plogi_ack_t
*pla
,
860 struct fc_port
*sess
, enum qlt_plogi_link_t link
)
862 struct imm_ntfy_from_isp
*iocb
= &pla
->iocb
;
863 /* Inc ref_count first because link might already be pointing at pla */
866 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf097,
867 "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC"
868 " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n",
869 sess
, link
, sess
->port_name
,
870 iocb
->u
.isp24
.port_name
, iocb
->u
.isp24
.port_id
[2],
871 iocb
->u
.isp24
.port_id
[1], iocb
->u
.isp24
.port_id
[0],
872 pla
->ref_count
, pla
, link
);
874 if (link
== QLT_PLOGI_LINK_CONFLICT
) {
875 switch (sess
->disc_state
) {
877 case DSC_DELETE_PEND
:
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 if (test_bit(PFLG_DRIVER_REMOVING
, &vha
->pci_flags
)) {
919 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
921 list_for_each_entry(tmp
, &vha
->logo_list
, list
) {
922 if (tmp
->id
.b24
== logo
->id
.b24
) {
923 tmp
->cmd_count
+= logo
->cmd_count
;
924 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
929 list_add_tail(&logo
->list
, &vha
->logo_list
);
931 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
933 res
= qla24xx_els_dcmd_iocb(vha
, ELS_DCMD_LOGO
, logo
->id
);
935 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
936 list_del(&logo
->list
);
937 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
940 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf098,
941 "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n",
942 logo
->id
.b
.domain
, logo
->id
.b
.area
, logo
->id
.b
.al_pa
,
943 logo
->cmd_count
, res
);
946 void qlt_free_session_done(struct work_struct
*work
)
948 struct fc_port
*sess
= container_of(work
, struct fc_port
,
950 struct qla_tgt
*tgt
= sess
->tgt
;
951 struct scsi_qla_host
*vha
= sess
->vha
;
952 struct qla_hw_data
*ha
= vha
->hw
;
954 bool logout_started
= false;
955 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
956 struct qlt_plogi_ack_t
*own
=
957 sess
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
];
959 ql_dbg(ql_dbg_disc
, vha
, 0xf084,
960 "%s: se_sess %p / sess %p from port %8phC loop_id %#04x"
961 " s_id %02x:%02x:%02x logout %d keep %d els_logo %d\n",
962 __func__
, sess
->se_sess
, sess
, sess
->port_name
, sess
->loop_id
,
963 sess
->d_id
.b
.domain
, sess
->d_id
.b
.area
, sess
->d_id
.b
.al_pa
,
964 sess
->logout_on_delete
, sess
->keep_nport_handle
,
965 sess
->send_els_logo
);
967 if (!IS_SW_RESV_ADDR(sess
->d_id
)) {
968 qla2x00_mark_device_lost(vha
, sess
, 0);
970 if (sess
->send_els_logo
) {
971 qlt_port_logo_t logo
;
973 logo
.id
= sess
->d_id
;
975 INIT_LIST_HEAD(&logo
.list
);
977 qlt_send_first_logo(vha
, &logo
);
978 sess
->send_els_logo
= 0;
981 if (sess
->logout_on_delete
&& sess
->loop_id
!= FC_NO_LOOP_ID
) {
985 (own
->iocb
.u
.isp24
.status_subcode
== ELS_PLOGI
)) {
986 sess
->logout_completed
= 0;
987 rc
= qla2x00_post_async_logout_work(vha
, sess
,
989 if (rc
!= QLA_SUCCESS
)
990 ql_log(ql_log_warn
, vha
, 0xf085,
991 "Schedule logo failed sess %p rc %d\n",
994 logout_started
= true;
995 } else if (own
&& (own
->iocb
.u
.isp24
.status_subcode
==
996 ELS_PRLI
) && ha
->flags
.rida_fmt2
) {
997 rc
= qla2x00_post_async_prlo_work(vha
, sess
,
999 if (rc
!= QLA_SUCCESS
)
1000 ql_log(ql_log_warn
, vha
, 0xf085,
1001 "Schedule PRLO failed sess %p rc %d\n",
1004 logout_started
= true;
1006 } /* if sess->logout_on_delete */
1008 if (sess
->nvme_flag
& NVME_FLAG_REGISTERED
&&
1009 !(sess
->nvme_flag
& NVME_FLAG_DELETING
)) {
1010 sess
->nvme_flag
|= NVME_FLAG_DELETING
;
1011 qla_nvme_unregister_remote_port(sess
);
1014 if (ha
->flags
.edif_enabled
&&
1015 (!own
|| own
->iocb
.u
.isp24
.status_subcode
== ELS_PLOGI
)) {
1016 sess
->edif
.authok
= 0;
1017 if (!ha
->flags
.host_shutting_down
) {
1018 ql_dbg(ql_dbg_edif
, vha
, 0x911e,
1019 "%s wwpn %8phC calling qla2x00_release_all_sadb\n",
1020 __func__
, sess
->port_name
);
1021 qla2x00_release_all_sadb(vha
, sess
);
1023 ql_dbg(ql_dbg_edif
, vha
, 0x911e,
1024 "%s bypassing release_all_sadb\n",
1028 qla_edif_clear_appdata(vha
, sess
);
1029 qla_edif_sess_down(vha
, sess
);
1034 * Release the target session for FC Nexus from fabric module code.
1036 if (sess
->se_sess
!= NULL
)
1037 ha
->tgt
.tgt_ops
->free_session(sess
);
1039 if (logout_started
) {
1040 bool traced
= false;
1043 while (!READ_ONCE(sess
->logout_completed
)) {
1045 ql_dbg(ql_dbg_disc
, vha
, 0xf086,
1046 "%s: waiting for sess %p logout\n",
1053 * Driver timeout is set to 22 Sec, update count value to loop
1054 * long enough for log-out to complete before advancing. Otherwise,
1055 * straddling logout can interfere with re-login attempt.
1061 ql_dbg(ql_dbg_disc
, vha
, 0xf087,
1062 "%s: sess %p logout completed\n", __func__
, sess
);
1065 /* check for any straggling io left behind */
1066 if (!(sess
->flags
& FCF_FCP2_DEVICE
) &&
1067 qla2x00_eh_wait_for_pending_commands(sess
->vha
, sess
->d_id
.b24
, 0, WAIT_TARGET
)) {
1068 ql_log(ql_log_warn
, vha
, 0x3027,
1069 "IO not return. Resetting.\n");
1070 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1071 qla2xxx_wake_dpc(vha
);
1072 qla2x00_wait_for_chip_reset(vha
);
1075 if (sess
->logo_ack_needed
) {
1076 sess
->logo_ack_needed
= 0;
1077 qla24xx_async_notify_ack(vha
, sess
,
1078 (struct imm_ntfy_from_isp
*)sess
->iocb
, SRB_NACK_LOGO
);
1081 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1082 if (sess
->se_sess
) {
1083 sess
->se_sess
= NULL
;
1084 if (tgt
&& !IS_SW_RESV_ADDR(sess
->d_id
))
1088 qla2x00_set_fcport_disc_state(sess
, DSC_DELETED
);
1089 sess
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1091 if (sess
->login_succ
&& !IS_SW_RESV_ADDR(sess
->d_id
)) {
1092 vha
->fcport_count
--;
1093 sess
->login_succ
= 0;
1096 qla2x00_clear_loop_id(sess
);
1098 if (sess
->conflict
) {
1099 sess
->conflict
->login_pause
= 0;
1100 sess
->conflict
= NULL
;
1101 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
1102 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1106 struct qlt_plogi_ack_t
*con
=
1107 sess
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
];
1108 struct imm_ntfy_from_isp
*iocb
;
1110 own
= sess
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
];
1114 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf099,
1115 "se_sess %p / sess %p port %8phC is gone,"
1116 " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n",
1117 sess
->se_sess
, sess
, sess
->port_name
,
1118 own
? "releasing own PLOGI" : "no own PLOGI pending",
1119 own
? own
->ref_count
: -1,
1120 iocb
->u
.isp24
.port_name
, con
->ref_count
);
1121 qlt_plogi_ack_unref(vha
, con
);
1122 sess
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
] = NULL
;
1124 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf09a,
1125 "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n",
1126 sess
->se_sess
, sess
, sess
->port_name
,
1127 own
? "releasing own PLOGI" :
1128 "no own PLOGI pending",
1129 own
? own
->ref_count
: -1);
1133 sess
->fw_login_state
= DSC_LS_PLOGI_PEND
;
1134 qlt_plogi_ack_unref(vha
, own
);
1135 sess
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] = NULL
;
1139 sess
->explicit_logout
= 0;
1140 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1142 qla2x00_dfs_remove_rport(vha
, sess
);
1144 spin_lock_irqsave(&vha
->work_lock
, flags
);
1145 sess
->flags
&= ~FCF_ASYNC_SENT
;
1146 sess
->deleted
= QLA_SESS_DELETED
;
1147 sess
->free_pending
= 0;
1148 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
1150 ql_dbg(ql_dbg_disc
, vha
, 0xf001,
1151 "Unregistration of sess %p %8phC finished fcp_cnt %d\n",
1152 sess
, sess
->port_name
, vha
->fcport_count
);
1154 if (tgt
&& (tgt
->sess_count
== 0))
1155 wake_up_all(&tgt
->waitQ
);
1157 if (!test_bit(PFLG_DRIVER_REMOVING
, &base_vha
->pci_flags
) &&
1158 !(vha
->vp_idx
&& test_bit(VPORT_DELETE
, &vha
->dpc_flags
)) &&
1159 (!tgt
|| !tgt
->tgt_stop
) && !LOOP_TRANSITION(vha
)) {
1160 switch (vha
->host
->active_mode
) {
1161 case MODE_INITIATOR
:
1163 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1164 qla2xxx_wake_dpc(vha
);
1173 if (vha
->fcport_count
== 0)
1174 wake_up_all(&vha
->fcport_waitQ
);
1177 /* ha->tgt.sess_lock supposed to be held on entry */
1178 void qlt_unreg_sess(struct fc_port
*sess
)
1180 struct scsi_qla_host
*vha
= sess
->vha
;
1181 unsigned long flags
;
1183 ql_dbg(ql_dbg_disc
, sess
->vha
, 0x210a,
1184 "%s sess %p for deletion %8phC\n",
1185 __func__
, sess
, sess
->port_name
);
1187 spin_lock_irqsave(&sess
->vha
->work_lock
, flags
);
1188 if (sess
->free_pending
) {
1189 spin_unlock_irqrestore(&sess
->vha
->work_lock
, flags
);
1192 sess
->free_pending
= 1;
1194 * Use FCF_ASYNC_SENT flag to block other cmds used in sess
1195 * management from being sent.
1197 sess
->flags
|= FCF_ASYNC_SENT
;
1198 sess
->deleted
= QLA_SESS_DELETION_IN_PROGRESS
;
1199 spin_unlock_irqrestore(&sess
->vha
->work_lock
, flags
);
1202 vha
->hw
->tgt
.tgt_ops
->clear_nacl_from_fcport_map(sess
);
1204 qla2x00_set_fcport_disc_state(sess
, DSC_DELETE_PEND
);
1205 sess
->last_rscn_gen
= sess
->rscn_gen
;
1206 sess
->last_login_gen
= sess
->login_gen
;
1208 queue_work(sess
->vha
->hw
->wq
, &sess
->free_work
);
1210 EXPORT_SYMBOL(qlt_unreg_sess
);
1212 static int qlt_reset(struct scsi_qla_host
*vha
, void *iocb
, int mcmd
)
1214 struct qla_hw_data
*ha
= vha
->hw
;
1215 struct fc_port
*sess
= NULL
;
1218 struct imm_ntfy_from_isp
*n
= (struct imm_ntfy_from_isp
*)iocb
;
1219 unsigned long flags
;
1221 loop_id
= le16_to_cpu(n
->u
.isp24
.nport_handle
);
1222 if (loop_id
== 0xFFFF) {
1224 atomic_inc(&vha
->vha_tgt
.qla_tgt
->tgt_global_resets_count
);
1225 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1226 qlt_clear_tgt_db(vha
->vha_tgt
.qla_tgt
);
1227 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1229 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1230 sess
= ha
->tgt
.tgt_ops
->find_sess_by_loop_id(vha
, loop_id
);
1231 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1234 ql_dbg(ql_dbg_tgt
, vha
, 0xe000,
1235 "Using sess for qla_tgt_reset: %p\n", sess
);
1241 ql_dbg(ql_dbg_tgt
, vha
, 0xe047,
1242 "scsi(%ld): resetting (session %p from port %8phC mcmd %x, "
1243 "loop_id %d)\n", vha
->host_no
, sess
, sess
->port_name
,
1246 return qlt_issue_task_mgmt(sess
, 0, mcmd
, iocb
, QLA24XX_MGMT_SEND_NACK
);
1249 static void qla24xx_chk_fcp_state(struct fc_port
*sess
)
1251 if (sess
->chip_reset
!= sess
->vha
->hw
->base_qpair
->chip_reset
) {
1252 sess
->logout_on_delete
= 0;
1253 sess
->logo_ack_needed
= 0;
1254 sess
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1258 void qlt_schedule_sess_for_deletion(struct fc_port
*sess
)
1260 struct qla_tgt
*tgt
= sess
->tgt
;
1261 unsigned long flags
;
1264 switch (sess
->disc_state
) {
1265 case DSC_DELETE_PEND
:
1268 if (!sess
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
] &&
1269 !sess
->plogi_link
[QLT_PLOGI_LINK_CONFLICT
]) {
1270 if (tgt
&& tgt
->tgt_stop
&& tgt
->sess_count
== 0)
1271 wake_up_all(&tgt
->waitQ
);
1273 if (sess
->vha
->fcport_count
== 0)
1274 wake_up_all(&sess
->vha
->fcport_waitQ
);
1278 case DSC_UPD_FCPORT
:
1280 * This port is not done reporting to upper layer.
1283 sess
->next_disc_state
= DSC_DELETE_PEND
;
1284 sec
= jiffies_to_msecs(jiffies
-
1285 sess
->jiffies_at_registration
)/1000;
1286 if (sess
->sec_since_registration
< sec
&& sec
&& !(sec
% 5)) {
1287 sess
->sec_since_registration
= sec
;
1288 ql_dbg(ql_dbg_disc
, sess
->vha
, 0xffff,
1289 "%s %8phC : Slow Rport registration(%d Sec)\n",
1290 __func__
, sess
->port_name
, sec
);
1297 spin_lock_irqsave(&sess
->vha
->work_lock
, flags
);
1298 if (sess
->deleted
== QLA_SESS_DELETION_IN_PROGRESS
) {
1299 spin_unlock_irqrestore(&sess
->vha
->work_lock
, flags
);
1302 sess
->deleted
= QLA_SESS_DELETION_IN_PROGRESS
;
1303 spin_unlock_irqrestore(&sess
->vha
->work_lock
, flags
);
1305 sess
->prli_pend_timer
= 0;
1306 qla2x00_set_fcport_disc_state(sess
, DSC_DELETE_PEND
);
1308 qla24xx_chk_fcp_state(sess
);
1310 ql_dbg(ql_log_warn
, sess
->vha
, 0xe001,
1311 "Scheduling sess %p for deletion %8phC fc4_type %x\n",
1312 sess
, sess
->port_name
, sess
->fc4_type
);
1314 WARN_ON(!queue_work(sess
->vha
->hw
->wq
, &sess
->del_work
));
1317 static void qlt_clear_tgt_db(struct qla_tgt
*tgt
)
1319 struct fc_port
*sess
;
1320 scsi_qla_host_t
*vha
= tgt
->vha
;
1322 list_for_each_entry(sess
, &vha
->vp_fcports
, list
) {
1324 qlt_schedule_sess_for_deletion(sess
);
1327 /* At this point tgt could be already dead */
1330 static int qla24xx_get_loop_id(struct scsi_qla_host
*vha
, be_id_t s_id
,
1333 struct qla_hw_data
*ha
= vha
->hw
;
1334 dma_addr_t gid_list_dma
;
1335 struct gid_list_info
*gid_list
, *gid
;
1339 gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, qla2x00_gid_list_size(ha
),
1340 &gid_list_dma
, GFP_KERNEL
);
1342 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf044,
1343 "qla_target(%d): DMA Alloc failed of %u\n",
1344 vha
->vp_idx
, qla2x00_gid_list_size(ha
));
1348 /* Get list of logged in devices */
1349 rc
= qla24xx_gidlist_wait(vha
, gid_list
, gid_list_dma
, &entries
);
1350 if (rc
!= QLA_SUCCESS
) {
1351 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf045,
1352 "qla_target(%d): get_id_list() failed: %x\n",
1355 goto out_free_id_list
;
1360 for (i
= 0; i
< entries
; i
++) {
1361 if (gid
->al_pa
== s_id
.al_pa
&&
1362 gid
->area
== s_id
.area
&&
1363 gid
->domain
== s_id
.domain
) {
1364 *loop_id
= le16_to_cpu(gid
->loop_id
);
1368 gid
= (void *)gid
+ ha
->gid_list_info_size
;
1372 dma_free_coherent(&ha
->pdev
->dev
, qla2x00_gid_list_size(ha
),
1373 gid_list
, gid_list_dma
);
1378 * Adds an extra ref to allow to drop hw lock after adding sess to the list.
1379 * Caller must put it.
1381 static struct fc_port
*qlt_create_sess(
1382 struct scsi_qla_host
*vha
,
1386 struct qla_hw_data
*ha
= vha
->hw
;
1387 struct fc_port
*sess
= fcport
;
1388 unsigned long flags
;
1390 if (vha
->vha_tgt
.qla_tgt
->tgt_stop
)
1393 if (fcport
->se_sess
) {
1394 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
1395 ql_dbg(ql_dbg_disc
, vha
, 0x20f6,
1396 "%s: kref_get_unless_zero failed for %8phC\n",
1397 __func__
, sess
->port_name
);
1402 sess
->tgt
= vha
->vha_tgt
.qla_tgt
;
1403 sess
->local
= local
;
1406 * Under normal circumstances we want to logout from firmware when
1407 * session eventually ends and release corresponding nport handle.
1408 * In the exception cases (e.g. when new PLOGI is waiting) corresponding
1409 * code will adjust these flags as necessary.
1411 sess
->logout_on_delete
= 1;
1412 sess
->keep_nport_handle
= 0;
1413 sess
->logout_completed
= 0;
1415 if (ha
->tgt
.tgt_ops
->check_initiator_node_acl(vha
,
1416 &fcport
->port_name
[0], sess
) < 0) {
1417 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf015,
1418 "(%d) %8phC check_initiator_node_acl failed\n",
1419 vha
->vp_idx
, fcport
->port_name
);
1422 kref_init(&fcport
->sess_kref
);
1424 * Take an extra reference to ->sess_kref here to handle
1425 * fc_port access across ->tgt.sess_lock reaquire.
1427 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
1428 ql_dbg(ql_dbg_disc
, vha
, 0x20f7,
1429 "%s: kref_get_unless_zero failed for %8phC\n",
1430 __func__
, sess
->port_name
);
1434 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1435 if (!IS_SW_RESV_ADDR(sess
->d_id
))
1436 vha
->vha_tgt
.qla_tgt
->sess_count
++;
1438 qlt_do_generation_tick(vha
, &sess
->generation
);
1439 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1442 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf006,
1443 "Adding sess %p se_sess %p to tgt %p sess_count %d\n",
1444 sess
, sess
->se_sess
, vha
->vha_tgt
.qla_tgt
,
1445 vha
->vha_tgt
.qla_tgt
->sess_count
);
1447 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04b,
1448 "qla_target(%d): %ssession for wwn %8phC (loop_id %d, "
1449 "s_id %x:%x:%x, confirmed completion %ssupported) added\n",
1450 vha
->vp_idx
, local
? "local " : "", fcport
->port_name
,
1451 fcport
->loop_id
, sess
->d_id
.b
.domain
, sess
->d_id
.b
.area
,
1452 sess
->d_id
.b
.al_pa
, sess
->conf_compl_supported
? "" : "not ");
1458 * max_gen - specifies maximum session generation
1459 * at which this deletion requestion is still valid
1462 qlt_fc_port_deleted(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, int max_gen
)
1464 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
1465 struct fc_port
*sess
= fcport
;
1466 unsigned long flags
;
1468 if (!vha
->hw
->tgt
.tgt_ops
)
1474 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1475 if (tgt
->tgt_stop
) {
1476 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1479 if (!sess
->se_sess
) {
1480 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1484 if (max_gen
- sess
->generation
< 0) {
1485 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1486 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf092,
1487 "Ignoring stale deletion request for se_sess %p / sess %p"
1488 " for port %8phC, req_gen %d, sess_gen %d\n",
1489 sess
->se_sess
, sess
, sess
->port_name
, max_gen
,
1494 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf008, "qla_tgt_fc_port_deleted %p", sess
);
1497 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1498 qlt_schedule_sess_for_deletion(sess
);
1501 static inline int test_tgt_sess_count(struct qla_tgt
*tgt
)
1503 struct qla_hw_data
*ha
= tgt
->ha
;
1504 unsigned long flags
;
1507 * We need to protect against race, when tgt is freed before or
1510 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1511 ql_dbg(ql_dbg_tgt
, tgt
->vha
, 0xe002,
1512 "tgt %p, sess_count=%d\n",
1513 tgt
, tgt
->sess_count
);
1514 res
= (tgt
->sess_count
== 0);
1515 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1520 /* Called by tcm_qla2xxx configfs code */
1521 int qlt_stop_phase1(struct qla_tgt
*tgt
)
1523 struct scsi_qla_host
*vha
= tgt
->vha
;
1524 struct qla_hw_data
*ha
= tgt
->ha
;
1525 unsigned long flags
;
1527 mutex_lock(&ha
->optrom_mutex
);
1528 mutex_lock(&qla_tgt_mutex
);
1530 if (tgt
->tgt_stop
|| tgt
->tgt_stopped
) {
1531 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04e,
1532 "Already in tgt->tgt_stop or tgt_stopped state\n");
1533 mutex_unlock(&qla_tgt_mutex
);
1534 mutex_unlock(&ha
->optrom_mutex
);
1538 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xe003, "Stopping target for host %ld(%p)\n",
1541 * Mutex needed to sync with qla_tgt_fc_port_[added,deleted].
1542 * Lock is needed, because we still can get an incoming packet.
1544 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
1546 qlt_clear_tgt_db(tgt
);
1547 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
1548 mutex_unlock(&qla_tgt_mutex
);
1550 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf009,
1551 "Waiting for sess works (tgt %p)", tgt
);
1552 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
1554 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
1555 flush_work(&tgt
->sess_work
);
1556 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
1557 } while (!list_empty(&tgt
->sess_works_list
));
1558 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
1560 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00a,
1561 "Waiting for tgt %p: sess_count=%d\n", tgt
, tgt
->sess_count
);
1563 wait_event_timeout(tgt
->waitQ
, test_tgt_sess_count(tgt
), 10*HZ
);
1566 if (!ha
->flags
.host_shutting_down
&&
1567 (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)))
1568 qlt_disable_vha(vha
);
1570 /* Wait for sessions to clear out (just in case) */
1571 wait_event_timeout(tgt
->waitQ
, test_tgt_sess_count(tgt
), 10*HZ
);
1572 mutex_unlock(&ha
->optrom_mutex
);
1576 EXPORT_SYMBOL(qlt_stop_phase1
);
1578 /* Called by tcm_qla2xxx configfs code */
1579 void qlt_stop_phase2(struct qla_tgt
*tgt
)
1581 scsi_qla_host_t
*vha
= tgt
->vha
;
1583 if (tgt
->tgt_stopped
) {
1584 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04f,
1585 "Already in tgt->tgt_stopped state\n");
1589 if (!tgt
->tgt_stop
) {
1590 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00b,
1591 "%s: phase1 stop is not completed\n", __func__
);
1596 mutex_lock(&tgt
->ha
->optrom_mutex
);
1597 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
1599 tgt
->tgt_stopped
= 1;
1600 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
1601 mutex_unlock(&tgt
->ha
->optrom_mutex
);
1603 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00c, "Stop of tgt %p finished\n",
1606 switch (vha
->qlini_mode
) {
1607 case QLA2XXX_INI_MODE_EXCLUSIVE
:
1608 vha
->flags
.online
= 1;
1609 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1615 EXPORT_SYMBOL(qlt_stop_phase2
);
1617 /* Called from qlt_remove_target() -> qla2x00_remove_one() */
1618 static void qlt_release(struct qla_tgt
*tgt
)
1620 scsi_qla_host_t
*vha
= tgt
->vha
;
1624 struct qla_qpair_hint
*h
;
1625 struct qla_hw_data
*ha
= vha
->hw
;
1627 if (!tgt
->tgt_stop
&& !tgt
->tgt_stopped
)
1628 qlt_stop_phase1(tgt
);
1630 if (!tgt
->tgt_stopped
)
1631 qlt_stop_phase2(tgt
);
1633 for (i
= 0; i
< vha
->hw
->max_qpairs
+ 1; i
++) {
1634 unsigned long flags
;
1636 h
= &tgt
->qphints
[i
];
1638 spin_lock_irqsave(h
->qpair
->qp_lock_ptr
, flags
);
1639 list_del(&h
->hint_elem
);
1640 spin_unlock_irqrestore(h
->qpair
->qp_lock_ptr
, flags
);
1644 kfree(tgt
->qphints
);
1645 mutex_lock(&qla_tgt_mutex
);
1646 list_del(&vha
->vha_tgt
.qla_tgt
->tgt_list_entry
);
1647 mutex_unlock(&qla_tgt_mutex
);
1649 btree_for_each_safe64(&tgt
->lun_qpair_map
, key
, node
)
1650 btree_remove64(&tgt
->lun_qpair_map
, key
);
1652 btree_destroy64(&tgt
->lun_qpair_map
);
1655 if (ha
->tgt
.tgt_ops
&&
1656 ha
->tgt
.tgt_ops
->remove_target
&&
1657 vha
->vha_tgt
.target_lport_ptr
)
1658 ha
->tgt
.tgt_ops
->remove_target(vha
);
1660 vha
->vha_tgt
.qla_tgt
= NULL
;
1662 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00d,
1663 "Release of tgt %p finished\n", tgt
);
1668 /* ha->hardware_lock supposed to be held on entry */
1669 static int qlt_sched_sess_work(struct qla_tgt
*tgt
, int type
,
1670 const void *param
, unsigned int param_size
)
1672 struct qla_tgt_sess_work_param
*prm
;
1673 unsigned long flags
;
1675 prm
= kzalloc(sizeof(*prm
), GFP_ATOMIC
);
1677 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf050,
1678 "qla_target(%d): Unable to create session "
1679 "work, command will be refused", 0);
1683 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf00e,
1684 "Scheduling work (type %d, prm %p)"
1685 " to find session for param %p (size %d, tgt %p)\n",
1686 type
, prm
, param
, param_size
, tgt
);
1689 memcpy(&prm
->tm_iocb
, param
, param_size
);
1691 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
1692 list_add_tail(&prm
->sess_works_list_entry
, &tgt
->sess_works_list
);
1693 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
1695 schedule_work(&tgt
->sess_work
);
1701 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1703 static void qlt_send_notify_ack(struct qla_qpair
*qpair
,
1704 struct imm_ntfy_from_isp
*ntfy
,
1705 uint32_t add_flags
, uint16_t resp_code
, int resp_code_valid
,
1706 uint16_t srr_flags
, uint16_t srr_reject_code
, uint8_t srr_explan
)
1708 struct scsi_qla_host
*vha
= qpair
->vha
;
1709 struct qla_hw_data
*ha
= vha
->hw
;
1711 struct nack_to_isp
*nack
;
1713 if (!ha
->flags
.fw_started
)
1716 ql_dbg(ql_dbg_tgt
, vha
, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha
);
1718 pkt
= (request_t
*)__qla2x00_alloc_iocbs(qpair
, NULL
);
1720 ql_dbg(ql_dbg_tgt
, vha
, 0xe049,
1721 "qla_target(%d): %s failed: unable to allocate "
1722 "request packet\n", vha
->vp_idx
, __func__
);
1726 if (vha
->vha_tgt
.qla_tgt
!= NULL
)
1727 vha
->vha_tgt
.qla_tgt
->notify_ack_expected
++;
1729 pkt
->entry_type
= NOTIFY_ACK_TYPE
;
1730 pkt
->entry_count
= 1;
1732 nack
= (struct nack_to_isp
*)pkt
;
1733 nack
->ox_id
= ntfy
->ox_id
;
1735 nack
->u
.isp24
.handle
= QLA_TGT_SKIP_HANDLE
;
1736 nack
->u
.isp24
.nport_handle
= ntfy
->u
.isp24
.nport_handle
;
1737 if (le16_to_cpu(ntfy
->u
.isp24
.status
) == IMM_NTFY_ELS
) {
1738 nack
->u
.isp24
.flags
= ntfy
->u
.isp24
.flags
&
1739 cpu_to_le16(NOTIFY24XX_FLAGS_PUREX_IOCB
);
1741 nack
->u
.isp24
.srr_rx_id
= ntfy
->u
.isp24
.srr_rx_id
;
1742 nack
->u
.isp24
.status
= ntfy
->u
.isp24
.status
;
1743 nack
->u
.isp24
.status_subcode
= ntfy
->u
.isp24
.status_subcode
;
1744 nack
->u
.isp24
.fw_handle
= ntfy
->u
.isp24
.fw_handle
;
1745 nack
->u
.isp24
.exchange_address
= ntfy
->u
.isp24
.exchange_address
;
1746 nack
->u
.isp24
.srr_rel_offs
= ntfy
->u
.isp24
.srr_rel_offs
;
1747 nack
->u
.isp24
.srr_ui
= ntfy
->u
.isp24
.srr_ui
;
1748 nack
->u
.isp24
.srr_flags
= cpu_to_le16(srr_flags
);
1749 nack
->u
.isp24
.srr_reject_code
= srr_reject_code
;
1750 nack
->u
.isp24
.srr_reject_code_expl
= srr_explan
;
1751 nack
->u
.isp24
.vp_index
= ntfy
->u
.isp24
.vp_index
;
1753 /* TODO qualify this with EDIF enable */
1754 if (ntfy
->u
.isp24
.status_subcode
== ELS_PLOGI
&&
1755 (le16_to_cpu(ntfy
->u
.isp24
.flags
) & NOTIFY24XX_FLAGS_FCSP
)) {
1756 nack
->u
.isp24
.flags
|= cpu_to_le16(NOTIFY_ACK_FLAGS_FCSP
);
1759 ql_dbg(ql_dbg_tgt
, vha
, 0xe005,
1760 "qla_target(%d): Sending 24xx Notify Ack %d\n",
1761 vha
->vp_idx
, nack
->u
.isp24
.status
);
1763 /* Memory Barrier */
1765 qla2x00_start_iocbs(vha
, qpair
->req
);
1768 static int qlt_build_abts_resp_iocb(struct qla_tgt_mgmt_cmd
*mcmd
)
1770 struct scsi_qla_host
*vha
= mcmd
->vha
;
1771 struct qla_hw_data
*ha
= vha
->hw
;
1772 struct abts_resp_to_24xx
*resp
;
1777 struct abts_recv_from_24xx
*abts
= &mcmd
->orig_iocb
.abts
;
1778 struct qla_qpair
*qpair
= mcmd
->qpair
;
1780 ql_dbg(ql_dbg_tgt
, vha
, 0xe006,
1781 "Sending task mgmt ABTS response (ha=%p, status=%x)\n",
1782 ha
, mcmd
->fc_tm_rsp
);
1784 rc
= qlt_check_reserve_free_req(qpair
, 1);
1786 ql_dbg(ql_dbg_tgt
, vha
, 0xe04a,
1787 "qla_target(%d): %s failed: unable to allocate request packet\n",
1788 vha
->vp_idx
, __func__
);
1792 resp
= (struct abts_resp_to_24xx
*)qpair
->req
->ring_ptr
;
1793 memset(resp
, 0, sizeof(*resp
));
1795 h
= qlt_make_handle(qpair
);
1796 if (unlikely(h
== QLA_TGT_NULL_HANDLE
)) {
1798 * CTIO type 7 from the firmware doesn't provide a way to
1799 * know the initiator's LOOP ID, hence we can't find
1800 * the session and, so, the command.
1804 qpair
->req
->outstanding_cmds
[h
] = (srb_t
*)mcmd
;
1807 resp
->handle
= make_handle(qpair
->req
->id
, h
);
1808 resp
->entry_type
= ABTS_RESP_24XX
;
1809 resp
->entry_count
= 1;
1810 resp
->nport_handle
= abts
->nport_handle
;
1811 resp
->vp_index
= vha
->vp_idx
;
1812 resp
->sof_type
= abts
->sof_type
;
1813 resp
->exchange_address
= abts
->exchange_address
;
1814 resp
->fcp_hdr_le
= abts
->fcp_hdr_le
;
1815 f_ctl
= cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP
|
1816 F_CTL_LAST_SEQ
| F_CTL_END_SEQ
|
1817 F_CTL_SEQ_INITIATIVE
);
1818 p
= (uint8_t *)&f_ctl
;
1819 resp
->fcp_hdr_le
.f_ctl
[0] = *p
++;
1820 resp
->fcp_hdr_le
.f_ctl
[1] = *p
++;
1821 resp
->fcp_hdr_le
.f_ctl
[2] = *p
;
1823 resp
->fcp_hdr_le
.d_id
= abts
->fcp_hdr_le
.s_id
;
1824 resp
->fcp_hdr_le
.s_id
= abts
->fcp_hdr_le
.d_id
;
1826 resp
->exchange_addr_to_abort
= abts
->exchange_addr_to_abort
;
1827 if (mcmd
->fc_tm_rsp
== FCP_TMF_CMPL
) {
1828 resp
->fcp_hdr_le
.r_ctl
= R_CTL_BASIC_LINK_SERV
| R_CTL_B_ACC
;
1829 resp
->payload
.ba_acct
.seq_id_valid
= SEQ_ID_INVALID
;
1830 resp
->payload
.ba_acct
.low_seq_cnt
= 0x0000;
1831 resp
->payload
.ba_acct
.high_seq_cnt
= cpu_to_le16(0xFFFF);
1832 resp
->payload
.ba_acct
.ox_id
= abts
->fcp_hdr_le
.ox_id
;
1833 resp
->payload
.ba_acct
.rx_id
= abts
->fcp_hdr_le
.rx_id
;
1835 resp
->fcp_hdr_le
.r_ctl
= R_CTL_BASIC_LINK_SERV
| R_CTL_B_RJT
;
1836 resp
->payload
.ba_rjt
.reason_code
=
1837 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM
;
1838 /* Other bytes are zero */
1841 vha
->vha_tgt
.qla_tgt
->abts_resp_expected
++;
1843 /* Memory Barrier */
1845 if (qpair
->reqq_start_iocbs
)
1846 qpair
->reqq_start_iocbs(qpair
);
1848 qla2x00_start_iocbs(vha
, qpair
->req
);
1854 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1856 static void qlt_24xx_send_abts_resp(struct qla_qpair
*qpair
,
1857 struct abts_recv_from_24xx
*abts
, uint32_t status
,
1860 struct scsi_qla_host
*vha
= qpair
->vha
;
1861 struct qla_hw_data
*ha
= vha
->hw
;
1862 struct abts_resp_to_24xx
*resp
;
1866 ql_dbg(ql_dbg_tgt
, vha
, 0xe006,
1867 "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n",
1870 resp
= (struct abts_resp_to_24xx
*)qla2x00_alloc_iocbs_ready(qpair
,
1873 ql_dbg(ql_dbg_tgt
, vha
, 0xe04a,
1874 "qla_target(%d): %s failed: unable to allocate "
1875 "request packet", vha
->vp_idx
, __func__
);
1879 resp
->entry_type
= ABTS_RESP_24XX
;
1880 resp
->handle
= QLA_TGT_SKIP_HANDLE
;
1881 resp
->entry_count
= 1;
1882 resp
->nport_handle
= abts
->nport_handle
;
1883 resp
->vp_index
= vha
->vp_idx
;
1884 resp
->sof_type
= abts
->sof_type
;
1885 resp
->exchange_address
= abts
->exchange_address
;
1886 resp
->fcp_hdr_le
= abts
->fcp_hdr_le
;
1887 f_ctl
= cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP
|
1888 F_CTL_LAST_SEQ
| F_CTL_END_SEQ
|
1889 F_CTL_SEQ_INITIATIVE
);
1890 p
= (uint8_t *)&f_ctl
;
1891 resp
->fcp_hdr_le
.f_ctl
[0] = *p
++;
1892 resp
->fcp_hdr_le
.f_ctl
[1] = *p
++;
1893 resp
->fcp_hdr_le
.f_ctl
[2] = *p
;
1895 resp
->fcp_hdr_le
.d_id
= abts
->fcp_hdr_le
.d_id
;
1896 resp
->fcp_hdr_le
.s_id
= abts
->fcp_hdr_le
.s_id
;
1898 resp
->fcp_hdr_le
.d_id
= abts
->fcp_hdr_le
.s_id
;
1899 resp
->fcp_hdr_le
.s_id
= abts
->fcp_hdr_le
.d_id
;
1901 resp
->exchange_addr_to_abort
= abts
->exchange_addr_to_abort
;
1902 if (status
== FCP_TMF_CMPL
) {
1903 resp
->fcp_hdr_le
.r_ctl
= R_CTL_BASIC_LINK_SERV
| R_CTL_B_ACC
;
1904 resp
->payload
.ba_acct
.seq_id_valid
= SEQ_ID_INVALID
;
1905 resp
->payload
.ba_acct
.low_seq_cnt
= 0x0000;
1906 resp
->payload
.ba_acct
.high_seq_cnt
= cpu_to_le16(0xFFFF);
1907 resp
->payload
.ba_acct
.ox_id
= abts
->fcp_hdr_le
.ox_id
;
1908 resp
->payload
.ba_acct
.rx_id
= abts
->fcp_hdr_le
.rx_id
;
1910 resp
->fcp_hdr_le
.r_ctl
= R_CTL_BASIC_LINK_SERV
| R_CTL_B_RJT
;
1911 resp
->payload
.ba_rjt
.reason_code
=
1912 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM
;
1913 /* Other bytes are zero */
1916 vha
->vha_tgt
.qla_tgt
->abts_resp_expected
++;
1918 /* Memory Barrier */
1920 if (qpair
->reqq_start_iocbs
)
1921 qpair
->reqq_start_iocbs(qpair
);
1923 qla2x00_start_iocbs(vha
, qpair
->req
);
1927 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1929 static void qlt_24xx_retry_term_exchange(struct scsi_qla_host
*vha
,
1930 struct qla_qpair
*qpair
, response_t
*pkt
, struct qla_tgt_mgmt_cmd
*mcmd
)
1932 struct ctio7_to_24xx
*ctio
;
1934 struct abts_recv_from_24xx
*entry
;
1936 ctio
= (struct ctio7_to_24xx
*)qla2x00_alloc_iocbs_ready(qpair
, NULL
);
1938 ql_dbg(ql_dbg_tgt
, vha
, 0xe04b,
1939 "qla_target(%d): %s failed: unable to allocate "
1940 "request packet\n", vha
->vp_idx
, __func__
);
1945 /* abts from remote port */
1946 entry
= &mcmd
->orig_iocb
.abts
;
1948 /* abts from this driver. */
1949 entry
= (struct abts_recv_from_24xx
*)pkt
;
1952 * We've got on entrance firmware's response on by us generated
1953 * ABTS response. So, in it ID fields are reversed.
1956 ctio
->entry_type
= CTIO_TYPE7
;
1957 ctio
->entry_count
= 1;
1958 ctio
->nport_handle
= entry
->nport_handle
;
1959 ctio
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
1960 ctio
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
1961 ctio
->vp_index
= vha
->vp_idx
;
1962 ctio
->exchange_addr
= entry
->exchange_addr_to_abort
;
1963 tmp
= (CTIO7_FLAGS_STATUS_MODE_1
| CTIO7_FLAGS_TERMINATE
);
1966 ctio
->initiator_id
= entry
->fcp_hdr_le
.s_id
;
1968 if (mcmd
->flags
& QLA24XX_MGMT_ABORT_IO_ATTR_VALID
)
1969 tmp
|= (mcmd
->abort_io_attr
<< 9);
1970 else if (qpair
->retry_term_cnt
& 1)
1973 ctio
->initiator_id
= entry
->fcp_hdr_le
.d_id
;
1975 if (qpair
->retry_term_cnt
& 1)
1978 ctio
->u
.status1
.flags
= cpu_to_le16(tmp
);
1979 ctio
->u
.status1
.ox_id
= entry
->fcp_hdr_le
.ox_id
;
1981 ql_dbg(ql_dbg_tgt
, vha
, 0xe007,
1982 "Sending retry TERM EXCH CTIO7 flags %04xh oxid %04xh attr valid %x\n",
1983 le16_to_cpu(ctio
->u
.status1
.flags
),
1984 le16_to_cpu(ctio
->u
.status1
.ox_id
),
1985 (mcmd
&& mcmd
->flags
& QLA24XX_MGMT_ABORT_IO_ATTR_VALID
) ? 1 : 0);
1987 /* Memory Barrier */
1989 if (qpair
->reqq_start_iocbs
)
1990 qpair
->reqq_start_iocbs(qpair
);
1992 qla2x00_start_iocbs(vha
, qpair
->req
);
1995 qlt_build_abts_resp_iocb(mcmd
);
1997 qlt_24xx_send_abts_resp(qpair
,
1998 (struct abts_recv_from_24xx
*)entry
, FCP_TMF_CMPL
, true);
2002 /* drop cmds for the given lun
2003 * XXX only looks for cmds on the port through which lun reset was recieved
2004 * XXX does not go through the list of other port (which may have cmds
2007 static void abort_cmds_for_lun(struct scsi_qla_host
*vha
, u64 lun
, be_id_t s_id
)
2009 struct qla_tgt_sess_op
*op
;
2010 struct qla_tgt_cmd
*cmd
;
2012 unsigned long flags
;
2014 key
= sid_to_key(s_id
);
2015 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
2016 list_for_each_entry(op
, &vha
->unknown_atio_list
, cmd_list
) {
2020 op_key
= sid_to_key(op
->atio
.u
.isp24
.fcp_hdr
.s_id
);
2021 op_lun
= scsilun_to_int(
2022 (struct scsi_lun
*)&op
->atio
.u
.isp24
.fcp_cmnd
.lun
);
2023 if (op_key
== key
&& op_lun
== lun
)
2027 list_for_each_entry(cmd
, &vha
->qla_cmd_list
, cmd_list
) {
2031 cmd_key
= sid_to_key(cmd
->atio
.u
.isp24
.fcp_hdr
.s_id
);
2032 cmd_lun
= scsilun_to_int(
2033 (struct scsi_lun
*)&cmd
->atio
.u
.isp24
.fcp_cmnd
.lun
);
2034 if (cmd_key
== key
&& cmd_lun
== lun
)
2037 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
2040 static struct qla_qpair_hint
*qlt_find_qphint(struct scsi_qla_host
*vha
,
2041 uint64_t unpacked_lun
)
2043 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
2044 struct qla_qpair_hint
*h
= NULL
;
2046 if (vha
->flags
.qpairs_available
) {
2047 h
= btree_lookup64(&tgt
->lun_qpair_map
, unpacked_lun
);
2049 h
= &tgt
->qphints
[0];
2051 h
= &tgt
->qphints
[0];
2057 static void qlt_do_tmr_work(struct work_struct
*work
)
2059 struct qla_tgt_mgmt_cmd
*mcmd
=
2060 container_of(work
, struct qla_tgt_mgmt_cmd
, work
);
2061 struct qla_hw_data
*ha
= mcmd
->vha
->hw
;
2064 unsigned long flags
;
2066 switch (mcmd
->tmr_func
) {
2068 tag
= le32_to_cpu(mcmd
->orig_iocb
.abts
.exchange_addr_to_abort
);
2075 rc
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, mcmd
->unpacked_lun
,
2076 mcmd
->tmr_func
, tag
);
2079 spin_lock_irqsave(mcmd
->qpair
->qp_lock_ptr
, flags
);
2080 switch (mcmd
->tmr_func
) {
2082 mcmd
->fc_tm_rsp
= FCP_TMF_REJECTED
;
2083 qlt_build_abts_resp_iocb(mcmd
);
2085 case QLA_TGT_LUN_RESET
:
2086 case QLA_TGT_CLEAR_TS
:
2087 case QLA_TGT_ABORT_TS
:
2088 case QLA_TGT_CLEAR_ACA
:
2089 case QLA_TGT_TARGET_RESET
:
2090 qlt_send_busy(mcmd
->qpair
, &mcmd
->orig_iocb
.atio
,
2094 case QLA_TGT_ABORT_ALL
:
2095 case QLA_TGT_NEXUS_LOSS_SESS
:
2096 case QLA_TGT_NEXUS_LOSS
:
2097 qlt_send_notify_ack(mcmd
->qpair
,
2098 &mcmd
->orig_iocb
.imm_ntfy
, 0, 0, 0, 0, 0, 0);
2101 spin_unlock_irqrestore(mcmd
->qpair
->qp_lock_ptr
, flags
);
2103 ql_dbg(ql_dbg_tgt_mgt
, mcmd
->vha
, 0xf052,
2104 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
2105 mcmd
->vha
->vp_idx
, rc
);
2106 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
2110 /* ha->hardware_lock supposed to be held on entry */
2111 static int __qlt_24xx_handle_abts(struct scsi_qla_host
*vha
,
2112 struct abts_recv_from_24xx
*abts
, struct fc_port
*sess
)
2114 struct qla_hw_data
*ha
= vha
->hw
;
2115 struct qla_tgt_mgmt_cmd
*mcmd
;
2116 struct qla_qpair_hint
*h
= &vha
->vha_tgt
.qla_tgt
->qphints
[0];
2117 struct qla_tgt_cmd
*abort_cmd
;
2119 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00f,
2120 "qla_target(%d): task abort (tag=%d)\n",
2121 vha
->vp_idx
, abts
->exchange_addr_to_abort
);
2123 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
2125 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf051,
2126 "qla_target(%d): %s: Allocation of ABORT cmd failed",
2127 vha
->vp_idx
, __func__
);
2130 memset(mcmd
, 0, sizeof(*mcmd
));
2131 mcmd
->cmd_type
= TYPE_TGT_TMCMD
;
2133 memcpy(&mcmd
->orig_iocb
.abts
, abts
, sizeof(mcmd
->orig_iocb
.abts
));
2134 mcmd
->reset_count
= ha
->base_qpair
->chip_reset
;
2135 mcmd
->tmr_func
= QLA_TGT_ABTS
;
2136 mcmd
->qpair
= h
->qpair
;
2140 * LUN is looked up by target-core internally based on the passed
2141 * abts->exchange_addr_to_abort tag.
2143 mcmd
->se_cmd
.cpuid
= h
->cpuid
;
2145 abort_cmd
= ha
->tgt
.tgt_ops
->find_cmd_by_tag(sess
,
2146 le32_to_cpu(abts
->exchange_addr_to_abort
));
2148 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
2151 mcmd
->unpacked_lun
= abort_cmd
->se_cmd
.orig_fe_lun
;
2153 if (abort_cmd
->qpair
) {
2154 mcmd
->qpair
= abort_cmd
->qpair
;
2155 mcmd
->se_cmd
.cpuid
= abort_cmd
->se_cmd
.cpuid
;
2156 mcmd
->abort_io_attr
= abort_cmd
->atio
.u
.isp24
.attr
;
2157 mcmd
->flags
= QLA24XX_MGMT_ABORT_IO_ATTR_VALID
;
2160 INIT_WORK(&mcmd
->work
, qlt_do_tmr_work
);
2161 queue_work_on(mcmd
->se_cmd
.cpuid
, qla_tgt_wq
, &mcmd
->work
);
2167 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2169 static void qlt_24xx_handle_abts(struct scsi_qla_host
*vha
,
2170 struct abts_recv_from_24xx
*abts
)
2172 struct qla_hw_data
*ha
= vha
->hw
;
2173 struct fc_port
*sess
;
2174 uint32_t tag
= le32_to_cpu(abts
->exchange_addr_to_abort
);
2177 unsigned long flags
;
2179 if (le32_to_cpu(abts
->fcp_hdr_le
.parameter
) & ABTS_PARAM_ABORT_SEQ
) {
2180 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf053,
2181 "qla_target(%d): ABTS: Abort Sequence not "
2182 "supported\n", vha
->vp_idx
);
2183 qlt_24xx_send_abts_resp(ha
->base_qpair
, abts
, FCP_TMF_REJECTED
,
2188 if (tag
== ATIO_EXCHANGE_ADDRESS_UNKNOWN
) {
2189 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf010,
2190 "qla_target(%d): ABTS: Unknown Exchange "
2191 "Address received\n", vha
->vp_idx
);
2192 qlt_24xx_send_abts_resp(ha
->base_qpair
, abts
, FCP_TMF_REJECTED
,
2197 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf011,
2198 "qla_target(%d): task abort (s_id=%x:%x:%x, "
2199 "tag=%d, param=%x)\n", vha
->vp_idx
, abts
->fcp_hdr_le
.s_id
.domain
,
2200 abts
->fcp_hdr_le
.s_id
.area
, abts
->fcp_hdr_le
.s_id
.al_pa
, tag
,
2201 le32_to_cpu(abts
->fcp_hdr_le
.parameter
));
2203 s_id
= le_id_to_be(abts
->fcp_hdr_le
.s_id
);
2205 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
2206 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, s_id
);
2208 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf012,
2209 "qla_target(%d): task abort for non-existent session\n",
2211 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
2213 qlt_24xx_send_abts_resp(ha
->base_qpair
, abts
, FCP_TMF_REJECTED
,
2217 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
2220 if (sess
->deleted
) {
2221 qlt_24xx_send_abts_resp(ha
->base_qpair
, abts
, FCP_TMF_REJECTED
,
2226 rc
= __qlt_24xx_handle_abts(vha
, abts
, sess
);
2228 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf054,
2229 "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n",
2231 qlt_24xx_send_abts_resp(ha
->base_qpair
, abts
, FCP_TMF_REJECTED
,
2238 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2240 static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair
*qpair
,
2241 struct qla_tgt_mgmt_cmd
*mcmd
, uint32_t resp_code
)
2243 struct scsi_qla_host
*ha
= mcmd
->vha
;
2244 struct atio_from_isp
*atio
= &mcmd
->orig_iocb
.atio
;
2245 struct ctio7_to_24xx
*ctio
;
2248 ql_dbg(ql_dbg_tgt
, ha
, 0xe008,
2249 "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n",
2250 ha
, atio
, resp_code
);
2253 ctio
= (struct ctio7_to_24xx
*)__qla2x00_alloc_iocbs(qpair
, NULL
);
2255 ql_dbg(ql_dbg_tgt
, ha
, 0xe04c,
2256 "qla_target(%d): %s failed: unable to allocate "
2257 "request packet\n", ha
->vp_idx
, __func__
);
2261 ctio
->entry_type
= CTIO_TYPE7
;
2262 ctio
->entry_count
= 1;
2263 ctio
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
2264 ctio
->nport_handle
= cpu_to_le16(mcmd
->sess
->loop_id
);
2265 ctio
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
2266 ctio
->vp_index
= ha
->vp_idx
;
2267 ctio
->initiator_id
= be_id_to_le(atio
->u
.isp24
.fcp_hdr
.s_id
);
2268 ctio
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2269 temp
= (atio
->u
.isp24
.attr
<< 9)|
2270 CTIO7_FLAGS_STATUS_MODE_1
| CTIO7_FLAGS_SEND_STATUS
;
2271 ctio
->u
.status1
.flags
= cpu_to_le16(temp
);
2272 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2273 ctio
->u
.status1
.ox_id
= cpu_to_le16(temp
);
2274 ctio
->u
.status1
.scsi_status
=
2275 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID
);
2276 ctio
->u
.status1
.response_len
= cpu_to_le16(8);
2277 ctio
->u
.status1
.sense_data
[0] = resp_code
;
2279 /* Memory Barrier */
2281 if (qpair
->reqq_start_iocbs
)
2282 qpair
->reqq_start_iocbs(qpair
);
2284 qla2x00_start_iocbs(ha
, qpair
->req
);
2287 void qlt_free_mcmd(struct qla_tgt_mgmt_cmd
*mcmd
)
2289 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
2291 EXPORT_SYMBOL(qlt_free_mcmd
);
2294 * ha->hardware_lock supposed to be held on entry. Might drop it, then
2297 void qlt_send_resp_ctio(struct qla_qpair
*qpair
, struct qla_tgt_cmd
*cmd
,
2298 uint8_t scsi_status
, uint8_t sense_key
, uint8_t asc
, uint8_t ascq
)
2300 struct atio_from_isp
*atio
= &cmd
->atio
;
2301 struct ctio7_to_24xx
*ctio
;
2303 struct scsi_qla_host
*vha
= cmd
->vha
;
2305 ql_dbg(ql_dbg_tgt_dif
, vha
, 0x3066,
2306 "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, "
2307 "sense_key=%02x, asc=%02x, ascq=%02x",
2308 vha
, atio
, scsi_status
, sense_key
, asc
, ascq
);
2310 ctio
= (struct ctio7_to_24xx
*)qla2x00_alloc_iocbs(vha
, NULL
);
2312 ql_dbg(ql_dbg_async
, vha
, 0x3067,
2313 "qla2x00t(%ld): %s failed: unable to allocate request packet",
2314 vha
->host_no
, __func__
);
2318 ctio
->entry_type
= CTIO_TYPE7
;
2319 ctio
->entry_count
= 1;
2320 ctio
->handle
= QLA_TGT_SKIP_HANDLE
;
2321 ctio
->nport_handle
= cpu_to_le16(cmd
->sess
->loop_id
);
2322 ctio
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
2323 ctio
->vp_index
= vha
->vp_idx
;
2324 ctio
->initiator_id
= be_id_to_le(atio
->u
.isp24
.fcp_hdr
.s_id
);
2325 ctio
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2326 temp
= (atio
->u
.isp24
.attr
<< 9) |
2327 CTIO7_FLAGS_STATUS_MODE_1
| CTIO7_FLAGS_SEND_STATUS
;
2328 ctio
->u
.status1
.flags
= cpu_to_le16(temp
);
2329 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2330 ctio
->u
.status1
.ox_id
= cpu_to_le16(temp
);
2331 ctio
->u
.status1
.scsi_status
=
2332 cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID
| scsi_status
);
2333 ctio
->u
.status1
.response_len
= cpu_to_le16(18);
2334 ctio
->u
.status1
.residual
= cpu_to_le32(get_datalen_for_atio(atio
));
2336 if (ctio
->u
.status1
.residual
!= 0)
2337 ctio
->u
.status1
.scsi_status
|=
2338 cpu_to_le16(SS_RESIDUAL_UNDER
);
2340 /* Fixed format sense data. */
2341 ctio
->u
.status1
.sense_data
[0] = 0x70;
2342 ctio
->u
.status1
.sense_data
[2] = sense_key
;
2343 /* Additional sense length */
2344 ctio
->u
.status1
.sense_data
[7] = 0xa;
2346 ctio
->u
.status1
.sense_data
[12] = asc
;
2347 ctio
->u
.status1
.sense_data
[13] = ascq
;
2349 /* Memory Barrier */
2352 if (qpair
->reqq_start_iocbs
)
2353 qpair
->reqq_start_iocbs(qpair
);
2355 qla2x00_start_iocbs(vha
, qpair
->req
);
2361 /* callback from target fabric module code */
2362 void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd
*mcmd
)
2364 struct scsi_qla_host
*vha
= mcmd
->sess
->vha
;
2365 struct qla_hw_data
*ha
= vha
->hw
;
2366 unsigned long flags
;
2367 struct qla_qpair
*qpair
= mcmd
->qpair
;
2368 bool free_mcmd
= true;
2370 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf013,
2371 "TM response mcmd (%p) status %#x state %#x",
2372 mcmd
, mcmd
->fc_tm_rsp
, mcmd
->flags
);
2374 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
2376 if (!vha
->flags
.online
|| mcmd
->reset_count
!= qpair
->chip_reset
) {
2378 * Either the port is not online or this request was from
2379 * previous life, just abort the processing.
2381 ql_dbg(ql_dbg_async
, vha
, 0xe100,
2382 "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n",
2383 vha
->flags
.online
, qla2x00_reset_active(vha
),
2384 mcmd
->reset_count
, qpair
->chip_reset
);
2385 ha
->tgt
.tgt_ops
->free_mcmd(mcmd
);
2386 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
2390 if (mcmd
->flags
== QLA24XX_MGMT_SEND_NACK
) {
2391 switch (mcmd
->orig_iocb
.imm_ntfy
.u
.isp24
.status_subcode
) {
2395 ql_dbg(ql_dbg_disc
, vha
, 0x2106,
2396 "TM response logo %8phC status %#x state %#x",
2397 mcmd
->sess
->port_name
, mcmd
->fc_tm_rsp
,
2399 qlt_schedule_sess_for_deletion(mcmd
->sess
);
2402 qlt_send_notify_ack(vha
->hw
->base_qpair
,
2403 &mcmd
->orig_iocb
.imm_ntfy
, 0, 0, 0, 0, 0, 0);
2407 if (mcmd
->orig_iocb
.atio
.u
.raw
.entry_type
== ABTS_RECV_24XX
) {
2408 qlt_build_abts_resp_iocb(mcmd
);
2411 qlt_24xx_send_task_mgmt_ctio(qpair
, mcmd
,
2415 * Make the callback for ->free_mcmd() to queue_work() and invoke
2416 * target_put_sess_cmd() to drop cmd_kref to 1. The final
2417 * target_put_sess_cmd() call will be made from TFO->check_stop_free()
2418 * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd
2419 * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() ->
2420 * qlt_xmit_tm_rsp() returns here..
2423 ha
->tgt
.tgt_ops
->free_mcmd(mcmd
);
2425 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
2427 EXPORT_SYMBOL(qlt_xmit_tm_rsp
);
2430 static int qlt_pci_map_calc_cnt(struct qla_tgt_prm
*prm
)
2432 struct qla_tgt_cmd
*cmd
= prm
->cmd
;
2434 BUG_ON(cmd
->sg_cnt
== 0);
2436 prm
->sg
= (struct scatterlist
*)cmd
->sg
;
2437 prm
->seg_cnt
= dma_map_sg(&cmd
->qpair
->pdev
->dev
, cmd
->sg
,
2438 cmd
->sg_cnt
, cmd
->dma_data_direction
);
2439 if (unlikely(prm
->seg_cnt
== 0))
2442 prm
->cmd
->sg_mapped
= 1;
2444 if (cmd
->se_cmd
.prot_op
== TARGET_PROT_NORMAL
) {
2446 * If greater than four sg entries then we need to allocate
2447 * the continuation entries
2449 if (prm
->seg_cnt
> QLA_TGT_DATASEGS_PER_CMD_24XX
)
2450 prm
->req_cnt
+= DIV_ROUND_UP(prm
->seg_cnt
-
2451 QLA_TGT_DATASEGS_PER_CMD_24XX
,
2452 QLA_TGT_DATASEGS_PER_CONT_24XX
);
2455 if ((cmd
->se_cmd
.prot_op
== TARGET_PROT_DIN_INSERT
) ||
2456 (cmd
->se_cmd
.prot_op
== TARGET_PROT_DOUT_STRIP
)) {
2457 prm
->seg_cnt
= DIV_ROUND_UP(cmd
->bufflen
, cmd
->blk_sz
);
2458 prm
->tot_dsds
= prm
->seg_cnt
;
2460 prm
->tot_dsds
= prm
->seg_cnt
;
2462 if (cmd
->prot_sg_cnt
) {
2463 prm
->prot_sg
= cmd
->prot_sg
;
2464 prm
->prot_seg_cnt
= dma_map_sg(&cmd
->qpair
->pdev
->dev
,
2465 cmd
->prot_sg
, cmd
->prot_sg_cnt
,
2466 cmd
->dma_data_direction
);
2467 if (unlikely(prm
->prot_seg_cnt
== 0))
2470 if ((cmd
->se_cmd
.prot_op
== TARGET_PROT_DIN_INSERT
) ||
2471 (cmd
->se_cmd
.prot_op
== TARGET_PROT_DOUT_STRIP
)) {
2472 /* Dif Bundling not support here */
2473 prm
->prot_seg_cnt
= DIV_ROUND_UP(cmd
->bufflen
,
2475 prm
->tot_dsds
+= prm
->prot_seg_cnt
;
2477 prm
->tot_dsds
+= prm
->prot_seg_cnt
;
2484 ql_dbg_qp(ql_dbg_tgt
, prm
->cmd
->qpair
, 0xe04d,
2485 "qla_target(%d): PCI mapping failed: sg_cnt=%d",
2486 0, prm
->cmd
->sg_cnt
);
2490 static void qlt_unmap_sg(struct scsi_qla_host
*vha
, struct qla_tgt_cmd
*cmd
)
2492 struct qla_hw_data
*ha
;
2493 struct qla_qpair
*qpair
;
2495 if (!cmd
->sg_mapped
)
2500 dma_unmap_sg(&qpair
->pdev
->dev
, cmd
->sg
, cmd
->sg_cnt
,
2501 cmd
->dma_data_direction
);
2504 if (cmd
->prot_sg_cnt
)
2505 dma_unmap_sg(&qpair
->pdev
->dev
, cmd
->prot_sg
, cmd
->prot_sg_cnt
,
2506 cmd
->dma_data_direction
);
2511 if (cmd
->ctx_dsd_alloced
)
2512 qla2x00_clean_dsd_pool(ha
, cmd
->ctx
);
2514 dma_pool_free(ha
->dl_dma_pool
, cmd
->ctx
, cmd
->ctx
->crc_ctx_dma
);
2517 static int qlt_check_reserve_free_req(struct qla_qpair
*qpair
,
2521 struct req_que
*req
= qpair
->req
;
2523 if (req
->cnt
< (req_cnt
+ 2)) {
2524 cnt
= (uint16_t)(qpair
->use_shadow_reg
? *req
->out_ptr
:
2525 rd_reg_dword_relaxed(req
->req_q_out
));
2527 if (req
->ring_index
< cnt
)
2528 req
->cnt
= cnt
- req
->ring_index
;
2530 req
->cnt
= req
->length
- (req
->ring_index
- cnt
);
2532 if (unlikely(req
->cnt
< (req_cnt
+ 2)))
2536 req
->cnt
-= req_cnt
;
2542 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2544 static inline void *qlt_get_req_pkt(struct req_que
*req
)
2546 /* Adjust ring index. */
2548 if (req
->ring_index
== req
->length
) {
2549 req
->ring_index
= 0;
2550 req
->ring_ptr
= req
->ring
;
2554 return (cont_entry_t
*)req
->ring_ptr
;
2557 /* ha->hardware_lock supposed to be held on entry */
2558 static inline uint32_t qlt_make_handle(struct qla_qpair
*qpair
)
2563 struct req_que
*req
= qpair
->req
;
2565 h
= req
->current_outstanding_cmd
;
2567 for (index
= 1; index
< req
->num_outstanding_cmds
; index
++) {
2569 if (h
== req
->num_outstanding_cmds
)
2572 if (h
== QLA_TGT_SKIP_HANDLE
)
2575 if (!req
->outstanding_cmds
[h
]) {
2582 req
->current_outstanding_cmd
= h
;
2584 ql_dbg(ql_dbg_io
, qpair
->vha
, 0x305b,
2585 "qla_target(%d): Ran out of empty cmd slots\n",
2586 qpair
->vha
->vp_idx
);
2587 h
= QLA_TGT_NULL_HANDLE
;
2593 /* ha->hardware_lock supposed to be held on entry */
2594 static int qlt_24xx_build_ctio_pkt(struct qla_qpair
*qpair
,
2595 struct qla_tgt_prm
*prm
)
2598 struct ctio7_to_24xx
*pkt
;
2599 struct atio_from_isp
*atio
= &prm
->cmd
->atio
;
2601 struct qla_tgt_cmd
*cmd
= prm
->cmd
;
2603 pkt
= (struct ctio7_to_24xx
*)qpair
->req
->ring_ptr
;
2605 memset(pkt
, 0, sizeof(*pkt
));
2607 pkt
->entry_type
= CTIO_TYPE7
;
2608 pkt
->entry_count
= (uint8_t)prm
->req_cnt
;
2609 pkt
->vp_index
= prm
->cmd
->vp_idx
;
2611 h
= qlt_make_handle(qpair
);
2612 if (unlikely(h
== QLA_TGT_NULL_HANDLE
)) {
2614 * CTIO type 7 from the firmware doesn't provide a way to
2615 * know the initiator's LOOP ID, hence we can't find
2616 * the session and, so, the command.
2620 qpair
->req
->outstanding_cmds
[h
] = (srb_t
*)prm
->cmd
;
2622 pkt
->handle
= make_handle(qpair
->req
->id
, h
);
2623 pkt
->handle
|= CTIO_COMPLETION_HANDLE_MARK
;
2624 pkt
->nport_handle
= cpu_to_le16(prm
->cmd
->loop_id
);
2625 pkt
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
2626 pkt
->initiator_id
= be_id_to_le(atio
->u
.isp24
.fcp_hdr
.s_id
);
2627 pkt
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2628 temp
= atio
->u
.isp24
.attr
<< 9;
2629 pkt
->u
.status0
.flags
|= cpu_to_le16(temp
);
2630 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2631 pkt
->u
.status0
.ox_id
= cpu_to_le16(temp
);
2632 pkt
->u
.status0
.relative_offset
= cpu_to_le32(prm
->cmd
->offset
);
2635 if (cmd
->dma_data_direction
== DMA_TO_DEVICE
)
2636 prm
->cmd
->sess
->edif
.rx_bytes
+= cmd
->bufflen
;
2637 if (cmd
->dma_data_direction
== DMA_FROM_DEVICE
)
2638 prm
->cmd
->sess
->edif
.tx_bytes
+= cmd
->bufflen
;
2640 pkt
->u
.status0
.edif_flags
|= EF_EN_EDIF
;
2647 * ha->hardware_lock supposed to be held on entry. We have already made sure
2648 * that there is sufficient amount of request entries to not drop it.
2650 static void qlt_load_cont_data_segments(struct qla_tgt_prm
*prm
)
2653 struct dsd64
*cur_dsd
;
2655 /* Build continuation packets */
2656 while (prm
->seg_cnt
> 0) {
2657 cont_a64_entry_t
*cont_pkt64
=
2658 (cont_a64_entry_t
*)qlt_get_req_pkt(
2659 prm
->cmd
->qpair
->req
);
2662 * Make sure that from cont_pkt64 none of
2663 * 64-bit specific fields used for 32-bit
2664 * addressing. Cast to (cont_entry_t *) for
2668 memset(cont_pkt64
, 0, sizeof(*cont_pkt64
));
2670 cont_pkt64
->entry_count
= 1;
2671 cont_pkt64
->sys_define
= 0;
2673 cont_pkt64
->entry_type
= CONTINUE_A64_TYPE
;
2674 cur_dsd
= cont_pkt64
->dsd
;
2676 /* Load continuation entry data segments */
2678 cnt
< QLA_TGT_DATASEGS_PER_CONT_24XX
&& prm
->seg_cnt
;
2679 cnt
++, prm
->seg_cnt
--) {
2680 append_dsd64(&cur_dsd
, prm
->sg
);
2681 prm
->sg
= sg_next(prm
->sg
);
2687 * ha->hardware_lock supposed to be held on entry. We have already made sure
2688 * that there is sufficient amount of request entries to not drop it.
2690 static void qlt_load_data_segments(struct qla_tgt_prm
*prm
)
2693 struct dsd64
*cur_dsd
;
2694 struct ctio7_to_24xx
*pkt24
= (struct ctio7_to_24xx
*)prm
->pkt
;
2696 pkt24
->u
.status0
.transfer_length
= cpu_to_le32(prm
->cmd
->bufflen
);
2698 /* Setup packet address segment pointer */
2699 cur_dsd
= &pkt24
->u
.status0
.dsd
;
2701 /* Set total data segment count */
2703 pkt24
->dseg_count
= cpu_to_le16(prm
->seg_cnt
);
2705 if (prm
->seg_cnt
== 0) {
2706 /* No data transfer */
2707 cur_dsd
->address
= 0;
2708 cur_dsd
->length
= 0;
2712 /* If scatter gather */
2714 /* Load command entry data segments */
2716 (cnt
< QLA_TGT_DATASEGS_PER_CMD_24XX
) && prm
->seg_cnt
;
2717 cnt
++, prm
->seg_cnt
--) {
2718 append_dsd64(&cur_dsd
, prm
->sg
);
2719 prm
->sg
= sg_next(prm
->sg
);
2722 qlt_load_cont_data_segments(prm
);
2725 static inline int qlt_has_data(struct qla_tgt_cmd
*cmd
)
2727 return cmd
->bufflen
> 0;
2730 static void qlt_print_dif_err(struct qla_tgt_prm
*prm
)
2732 struct qla_tgt_cmd
*cmd
;
2733 struct scsi_qla_host
*vha
;
2735 /* asc 0x10=dif error */
2736 if (prm
->sense_buffer
&& (prm
->sense_buffer
[12] == 0x10)) {
2740 switch (prm
->sense_buffer
[13]) {
2742 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe00b,
2743 "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2744 "se_cmd=%p tag[%x]",
2745 cmd
->lba
, cmd
->lba
, cmd
->num_blks
, &cmd
->se_cmd
,
2746 cmd
->atio
.u
.isp24
.exchange_addr
);
2749 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe00c,
2750 "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2751 "se_cmd=%p tag[%x]",
2752 cmd
->lba
, cmd
->lba
, cmd
->num_blks
, &cmd
->se_cmd
,
2753 cmd
->atio
.u
.isp24
.exchange_addr
);
2756 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe00f,
2757 "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] "
2758 "se_cmd=%p tag[%x]",
2759 cmd
->lba
, cmd
->lba
, cmd
->num_blks
, &cmd
->se_cmd
,
2760 cmd
->atio
.u
.isp24
.exchange_addr
);
2763 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe010,
2764 "BE detected Dif ERR: lba[%llx|%lld] len[%x] "
2765 "se_cmd=%p tag[%x]",
2766 cmd
->lba
, cmd
->lba
, cmd
->num_blks
, &cmd
->se_cmd
,
2767 cmd
->atio
.u
.isp24
.exchange_addr
);
2770 ql_dump_buffer(ql_dbg_tgt_dif
, vha
, 0xe011, cmd
->cdb
, 16);
2775 * Called without ha->hardware_lock held
2777 static int qlt_pre_xmit_response(struct qla_tgt_cmd
*cmd
,
2778 struct qla_tgt_prm
*prm
, int xmit_type
, uint8_t scsi_status
,
2779 uint32_t *full_req_cnt
)
2781 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
2782 struct qla_qpair
*qpair
= cmd
->qpair
;
2785 prm
->tgt
= cmd
->tgt
;
2787 prm
->rq_result
= scsi_status
;
2788 prm
->sense_buffer
= &cmd
->sense_buffer
[0];
2789 prm
->sense_buffer_len
= TRANSPORT_SENSE_BUFFER
;
2794 prm
->add_status_pkt
= 0;
2795 prm
->prot_sg
= NULL
;
2796 prm
->prot_seg_cnt
= 0;
2799 if ((xmit_type
& QLA_TGT_XMIT_DATA
) && qlt_has_data(cmd
)) {
2800 if (qlt_pci_map_calc_cnt(prm
) != 0)
2804 *full_req_cnt
= prm
->req_cnt
;
2806 if (se_cmd
->se_cmd_flags
& SCF_UNDERFLOW_BIT
) {
2807 prm
->residual
= se_cmd
->residual_count
;
2808 ql_dbg_qp(ql_dbg_io
+ ql_dbg_verbose
, qpair
, 0x305c,
2809 "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2810 prm
->residual
, se_cmd
->tag
,
2811 se_cmd
->t_task_cdb
? se_cmd
->t_task_cdb
[0] : 0,
2812 cmd
->bufflen
, prm
->rq_result
);
2813 prm
->rq_result
|= SS_RESIDUAL_UNDER
;
2814 } else if (se_cmd
->se_cmd_flags
& SCF_OVERFLOW_BIT
) {
2815 prm
->residual
= se_cmd
->residual_count
;
2816 ql_dbg_qp(ql_dbg_io
, qpair
, 0x305d,
2817 "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
2818 prm
->residual
, se_cmd
->tag
, se_cmd
->t_task_cdb
?
2819 se_cmd
->t_task_cdb
[0] : 0, cmd
->bufflen
, prm
->rq_result
);
2820 prm
->rq_result
|= SS_RESIDUAL_OVER
;
2823 if (xmit_type
& QLA_TGT_XMIT_STATUS
) {
2825 * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be
2826 * ignored in *xmit_response() below
2828 if (qlt_has_data(cmd
)) {
2829 if (QLA_TGT_SENSE_VALID(prm
->sense_buffer
) ||
2830 (IS_FWI2_CAPABLE(cmd
->vha
->hw
) &&
2831 (prm
->rq_result
!= 0))) {
2832 prm
->add_status_pkt
= 1;
2841 static inline int qlt_need_explicit_conf(struct qla_tgt_cmd
*cmd
,
2844 if (cmd
->qpair
->enable_class_2
)
2848 return cmd
->conf_compl_supported
;
2850 return cmd
->qpair
->enable_explicit_conf
&&
2851 cmd
->conf_compl_supported
;
2854 static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx
*ctio
,
2855 struct qla_tgt_prm
*prm
)
2857 prm
->sense_buffer_len
= min_t(uint32_t, prm
->sense_buffer_len
,
2858 (uint32_t)sizeof(ctio
->u
.status1
.sense_data
));
2859 ctio
->u
.status0
.flags
|= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS
);
2860 if (qlt_need_explicit_conf(prm
->cmd
, 0)) {
2861 ctio
->u
.status0
.flags
|= cpu_to_le16(
2862 CTIO7_FLAGS_EXPLICIT_CONFORM
|
2863 CTIO7_FLAGS_CONFORM_REQ
);
2865 ctio
->u
.status0
.residual
= cpu_to_le32(prm
->residual
);
2866 ctio
->u
.status0
.scsi_status
= cpu_to_le16(prm
->rq_result
);
2867 if (QLA_TGT_SENSE_VALID(prm
->sense_buffer
)) {
2870 if (qlt_need_explicit_conf(prm
->cmd
, 1)) {
2871 if ((prm
->rq_result
& SS_SCSI_STATUS_BYTE
) != 0) {
2872 ql_dbg_qp(ql_dbg_tgt
, prm
->cmd
->qpair
, 0xe017,
2873 "Skipping EXPLICIT_CONFORM and "
2874 "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ "
2875 "non GOOD status\n");
2876 goto skip_explict_conf
;
2878 ctio
->u
.status1
.flags
|= cpu_to_le16(
2879 CTIO7_FLAGS_EXPLICIT_CONFORM
|
2880 CTIO7_FLAGS_CONFORM_REQ
);
2883 ctio
->u
.status1
.flags
&=
2884 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0
);
2885 ctio
->u
.status1
.flags
|=
2886 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
);
2887 ctio
->u
.status1
.scsi_status
|=
2888 cpu_to_le16(SS_SENSE_LEN_VALID
);
2889 ctio
->u
.status1
.sense_length
=
2890 cpu_to_le16(prm
->sense_buffer_len
);
2891 for (i
= 0; i
< prm
->sense_buffer_len
/4; i
++) {
2894 v
= get_unaligned_be32(
2895 &((uint32_t *)prm
->sense_buffer
)[i
]);
2896 put_unaligned_le32(v
,
2897 &((uint32_t *)ctio
->u
.status1
.sense_data
)[i
]);
2899 qlt_print_dif_err(prm
);
2902 ctio
->u
.status1
.flags
&=
2903 ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0
);
2904 ctio
->u
.status1
.flags
|=
2905 cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
);
2906 ctio
->u
.status1
.sense_length
= 0;
2907 memset(ctio
->u
.status1
.sense_data
, 0,
2908 sizeof(ctio
->u
.status1
.sense_data
));
2911 /* Sense with len > 24, is it possible ??? */
2915 qlt_hba_err_chk_enabled(struct se_cmd
*se_cmd
)
2917 switch (se_cmd
->prot_op
) {
2918 case TARGET_PROT_DOUT_INSERT
:
2919 case TARGET_PROT_DIN_STRIP
:
2920 if (ql2xenablehba_err_chk
>= 1)
2923 case TARGET_PROT_DOUT_PASS
:
2924 case TARGET_PROT_DIN_PASS
:
2925 if (ql2xenablehba_err_chk
>= 2)
2928 case TARGET_PROT_DIN_INSERT
:
2929 case TARGET_PROT_DOUT_STRIP
:
2938 qla_tgt_ref_mask_check(struct se_cmd
*se_cmd
)
2940 switch (se_cmd
->prot_op
) {
2941 case TARGET_PROT_DIN_INSERT
:
2942 case TARGET_PROT_DOUT_INSERT
:
2943 case TARGET_PROT_DIN_STRIP
:
2944 case TARGET_PROT_DOUT_STRIP
:
2945 case TARGET_PROT_DIN_PASS
:
2946 case TARGET_PROT_DOUT_PASS
:
2955 * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command
2958 qla_tgt_set_dif_tags(struct qla_tgt_cmd
*cmd
, struct crc_context
*ctx
,
2959 uint16_t *pfw_prot_opts
)
2961 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
2962 uint32_t lba
= 0xffffffff & se_cmd
->t_task_lba
;
2963 scsi_qla_host_t
*vha
= cmd
->tgt
->vha
;
2964 struct qla_hw_data
*ha
= vha
->hw
;
2968 * wait till Mode Sense/Select cmd, modepage Ah, subpage 2
2969 * have been immplemented by TCM, before AppTag is avail.
2970 * Look for modesense_handlers[]
2973 ctx
->app_tag_mask
[0] = 0x0;
2974 ctx
->app_tag_mask
[1] = 0x0;
2976 if (IS_PI_UNINIT_CAPABLE(ha
)) {
2977 if ((se_cmd
->prot_type
== TARGET_DIF_TYPE1_PROT
) ||
2978 (se_cmd
->prot_type
== TARGET_DIF_TYPE2_PROT
))
2979 *pfw_prot_opts
|= PO_DIS_VALD_APP_ESC
;
2980 else if (se_cmd
->prot_type
== TARGET_DIF_TYPE3_PROT
)
2981 *pfw_prot_opts
|= PO_DIS_VALD_APP_REF_ESC
;
2984 t32
= ha
->tgt
.tgt_ops
->get_dif_tags(cmd
, pfw_prot_opts
);
2986 switch (se_cmd
->prot_type
) {
2987 case TARGET_DIF_TYPE0_PROT
:
2989 * No check for ql2xenablehba_err_chk, as it
2990 * would be an I/O error if hba tag generation
2993 ctx
->ref_tag
= cpu_to_le32(lba
);
2994 /* enable ALL bytes of the ref tag */
2995 ctx
->ref_tag_mask
[0] = 0xff;
2996 ctx
->ref_tag_mask
[1] = 0xff;
2997 ctx
->ref_tag_mask
[2] = 0xff;
2998 ctx
->ref_tag_mask
[3] = 0xff;
3000 case TARGET_DIF_TYPE1_PROT
:
3002 * For TYPE 1 protection: 16 bit GUARD tag, 32 bit
3003 * REF tag, and 16 bit app tag.
3005 ctx
->ref_tag
= cpu_to_le32(lba
);
3006 if (!qla_tgt_ref_mask_check(se_cmd
) ||
3007 !(ha
->tgt
.tgt_ops
->chk_dif_tags(t32
))) {
3008 *pfw_prot_opts
|= PO_DIS_REF_TAG_VALD
;
3011 /* enable ALL bytes of the ref tag */
3012 ctx
->ref_tag_mask
[0] = 0xff;
3013 ctx
->ref_tag_mask
[1] = 0xff;
3014 ctx
->ref_tag_mask
[2] = 0xff;
3015 ctx
->ref_tag_mask
[3] = 0xff;
3017 case TARGET_DIF_TYPE2_PROT
:
3019 * For TYPE 2 protection: 16 bit GUARD + 32 bit REF
3020 * tag has to match LBA in CDB + N
3022 ctx
->ref_tag
= cpu_to_le32(lba
);
3023 if (!qla_tgt_ref_mask_check(se_cmd
) ||
3024 !(ha
->tgt
.tgt_ops
->chk_dif_tags(t32
))) {
3025 *pfw_prot_opts
|= PO_DIS_REF_TAG_VALD
;
3028 /* enable ALL bytes of the ref tag */
3029 ctx
->ref_tag_mask
[0] = 0xff;
3030 ctx
->ref_tag_mask
[1] = 0xff;
3031 ctx
->ref_tag_mask
[2] = 0xff;
3032 ctx
->ref_tag_mask
[3] = 0xff;
3034 case TARGET_DIF_TYPE3_PROT
:
3035 /* For TYPE 3 protection: 16 bit GUARD only */
3036 *pfw_prot_opts
|= PO_DIS_REF_TAG_VALD
;
3037 ctx
->ref_tag_mask
[0] = ctx
->ref_tag_mask
[1] =
3038 ctx
->ref_tag_mask
[2] = ctx
->ref_tag_mask
[3] = 0x00;
3044 qlt_build_ctio_crc2_pkt(struct qla_qpair
*qpair
, struct qla_tgt_prm
*prm
)
3046 struct dsd64
*cur_dsd
;
3047 uint32_t transfer_length
= 0;
3048 uint32_t data_bytes
;
3050 uint8_t bundling
= 1;
3051 struct crc_context
*crc_ctx_pkt
= NULL
;
3052 struct qla_hw_data
*ha
;
3053 struct ctio_crc2_to_fw
*pkt
;
3054 dma_addr_t crc_ctx_dma
;
3055 uint16_t fw_prot_opts
= 0;
3056 struct qla_tgt_cmd
*cmd
= prm
->cmd
;
3057 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
3059 struct atio_from_isp
*atio
= &prm
->cmd
->atio
;
3060 struct qla_tc_param tc
;
3062 scsi_qla_host_t
*vha
= cmd
->vha
;
3066 pkt
= (struct ctio_crc2_to_fw
*)qpair
->req
->ring_ptr
;
3068 memset(pkt
, 0, sizeof(*pkt
));
3070 ql_dbg_qp(ql_dbg_tgt
, cmd
->qpair
, 0xe071,
3071 "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n",
3072 cmd
->vp_idx
, __func__
, se_cmd
, se_cmd
->prot_op
,
3073 prm
->prot_sg
, prm
->prot_seg_cnt
, se_cmd
->t_task_lba
);
3075 if ((se_cmd
->prot_op
== TARGET_PROT_DIN_INSERT
) ||
3076 (se_cmd
->prot_op
== TARGET_PROT_DOUT_STRIP
))
3079 /* Compute dif len and adjust data len to incude protection */
3080 data_bytes
= cmd
->bufflen
;
3081 dif_bytes
= (data_bytes
/ cmd
->blk_sz
) * 8;
3083 switch (se_cmd
->prot_op
) {
3084 case TARGET_PROT_DIN_INSERT
:
3085 case TARGET_PROT_DOUT_STRIP
:
3086 transfer_length
= data_bytes
;
3087 if (cmd
->prot_sg_cnt
)
3088 data_bytes
+= dif_bytes
;
3090 case TARGET_PROT_DIN_STRIP
:
3091 case TARGET_PROT_DOUT_INSERT
:
3092 case TARGET_PROT_DIN_PASS
:
3093 case TARGET_PROT_DOUT_PASS
:
3094 transfer_length
= data_bytes
+ dif_bytes
;
3101 if (!qlt_hba_err_chk_enabled(se_cmd
))
3102 fw_prot_opts
|= 0x10; /* Disable Guard tag checking */
3103 /* HBA error checking enabled */
3104 else if (IS_PI_UNINIT_CAPABLE(ha
)) {
3105 if ((se_cmd
->prot_type
== TARGET_DIF_TYPE1_PROT
) ||
3106 (se_cmd
->prot_type
== TARGET_DIF_TYPE2_PROT
))
3107 fw_prot_opts
|= PO_DIS_VALD_APP_ESC
;
3108 else if (se_cmd
->prot_type
== TARGET_DIF_TYPE3_PROT
)
3109 fw_prot_opts
|= PO_DIS_VALD_APP_REF_ESC
;
3112 switch (se_cmd
->prot_op
) {
3113 case TARGET_PROT_DIN_INSERT
:
3114 case TARGET_PROT_DOUT_INSERT
:
3115 fw_prot_opts
|= PO_MODE_DIF_INSERT
;
3117 case TARGET_PROT_DIN_STRIP
:
3118 case TARGET_PROT_DOUT_STRIP
:
3119 fw_prot_opts
|= PO_MODE_DIF_REMOVE
;
3121 case TARGET_PROT_DIN_PASS
:
3122 case TARGET_PROT_DOUT_PASS
:
3123 fw_prot_opts
|= PO_MODE_DIF_PASS
;
3124 /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */
3126 default:/* Normal Request */
3127 fw_prot_opts
|= PO_MODE_DIF_PASS
;
3132 /* Update entry type to indicate Command Type CRC_2 IOCB */
3133 pkt
->entry_type
= CTIO_CRC2
;
3134 pkt
->entry_count
= 1;
3135 pkt
->vp_index
= cmd
->vp_idx
;
3137 h
= qlt_make_handle(qpair
);
3138 if (unlikely(h
== QLA_TGT_NULL_HANDLE
)) {
3140 * CTIO type 7 from the firmware doesn't provide a way to
3141 * know the initiator's LOOP ID, hence we can't find
3142 * the session and, so, the command.
3146 qpair
->req
->outstanding_cmds
[h
] = (srb_t
*)prm
->cmd
;
3148 pkt
->handle
= make_handle(qpair
->req
->id
, h
);
3149 pkt
->handle
|= CTIO_COMPLETION_HANDLE_MARK
;
3150 pkt
->nport_handle
= cpu_to_le16(prm
->cmd
->loop_id
);
3151 pkt
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
3152 pkt
->initiator_id
= be_id_to_le(atio
->u
.isp24
.fcp_hdr
.s_id
);
3153 pkt
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
3155 /* silence compile warning */
3156 t16
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
3157 pkt
->ox_id
= cpu_to_le16(t16
);
3159 t16
= (atio
->u
.isp24
.attr
<< 9);
3160 pkt
->flags
|= cpu_to_le16(t16
);
3161 pkt
->relative_offset
= cpu_to_le32(prm
->cmd
->offset
);
3163 /* Set transfer direction */
3164 if (cmd
->dma_data_direction
== DMA_TO_DEVICE
)
3165 pkt
->flags
= cpu_to_le16(CTIO7_FLAGS_DATA_IN
);
3166 else if (cmd
->dma_data_direction
== DMA_FROM_DEVICE
)
3167 pkt
->flags
= cpu_to_le16(CTIO7_FLAGS_DATA_OUT
);
3169 pkt
->dseg_count
= cpu_to_le16(prm
->tot_dsds
);
3170 /* Fibre channel byte count */
3171 pkt
->transfer_length
= cpu_to_le32(transfer_length
);
3173 /* ----- CRC context -------- */
3175 /* Allocate CRC context from global pool */
3176 crc_ctx_pkt
= cmd
->ctx
=
3177 dma_pool_zalloc(ha
->dl_dma_pool
, GFP_ATOMIC
, &crc_ctx_dma
);
3180 goto crc_queuing_error
;
3182 crc_ctx_pkt
->crc_ctx_dma
= crc_ctx_dma
;
3183 INIT_LIST_HEAD(&crc_ctx_pkt
->dsd_list
);
3186 crc_ctx_pkt
->handle
= pkt
->handle
;
3188 qla_tgt_set_dif_tags(cmd
, crc_ctx_pkt
, &fw_prot_opts
);
3190 put_unaligned_le64(crc_ctx_dma
, &pkt
->crc_context_address
);
3191 pkt
->crc_context_len
= cpu_to_le16(CRC_CONTEXT_LEN_FW
);
3194 cur_dsd
= &crc_ctx_pkt
->u
.nobundling
.data_dsd
[0];
3197 * Configure Bundling if we need to fetch interlaving
3198 * protection PCI accesses
3200 fw_prot_opts
|= PO_ENABLE_DIF_BUNDLING
;
3201 crc_ctx_pkt
->u
.bundling
.dif_byte_count
= cpu_to_le32(dif_bytes
);
3202 crc_ctx_pkt
->u
.bundling
.dseg_count
=
3203 cpu_to_le16(prm
->tot_dsds
- prm
->prot_seg_cnt
);
3204 cur_dsd
= &crc_ctx_pkt
->u
.bundling
.data_dsd
[0];
3207 /* Finish the common fields of CRC pkt */
3208 crc_ctx_pkt
->blk_size
= cpu_to_le16(cmd
->blk_sz
);
3209 crc_ctx_pkt
->prot_opts
= cpu_to_le16(fw_prot_opts
);
3210 crc_ctx_pkt
->byte_count
= cpu_to_le32(data_bytes
);
3211 crc_ctx_pkt
->guard_seed
= cpu_to_le16(0);
3213 memset((uint8_t *)&tc
, 0 , sizeof(tc
));
3215 tc
.blk_sz
= cmd
->blk_sz
;
3216 tc
.bufflen
= cmd
->bufflen
;
3218 tc
.prot_sg
= cmd
->prot_sg
;
3219 tc
.ctx
= crc_ctx_pkt
;
3220 tc
.ctx_dsd_alloced
= &cmd
->ctx_dsd_alloced
;
3222 /* Walks data segments */
3223 pkt
->flags
|= cpu_to_le16(CTIO7_FLAGS_DSD_PTR
);
3225 if (!bundling
&& prm
->prot_seg_cnt
) {
3226 if (qla24xx_walk_and_build_sglist_no_difb(ha
, NULL
, cur_dsd
,
3227 prm
->tot_dsds
, &tc
))
3228 goto crc_queuing_error
;
3229 } else if (qla24xx_walk_and_build_sglist(ha
, NULL
, cur_dsd
,
3230 (prm
->tot_dsds
- prm
->prot_seg_cnt
), &tc
))
3231 goto crc_queuing_error
;
3233 if (bundling
&& prm
->prot_seg_cnt
) {
3234 /* Walks dif segments */
3235 pkt
->add_flags
|= CTIO_CRC2_AF_DIF_DSD_ENA
;
3237 cur_dsd
= &crc_ctx_pkt
->u
.bundling
.dif_dsd
;
3238 if (qla24xx_walk_and_build_prot_sglist(ha
, NULL
, cur_dsd
,
3239 prm
->prot_seg_cnt
, cmd
))
3240 goto crc_queuing_error
;
3245 /* Cleanup will be performed by the caller */
3246 qpair
->req
->outstanding_cmds
[h
] = NULL
;
3248 return QLA_FUNCTION_FAILED
;
3252 * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and *
3253 * QLA_TGT_XMIT_STATUS for >= 24xx silicon
3255 int qlt_xmit_response(struct qla_tgt_cmd
*cmd
, int xmit_type
,
3256 uint8_t scsi_status
)
3258 struct scsi_qla_host
*vha
= cmd
->vha
;
3259 struct qla_qpair
*qpair
= cmd
->qpair
;
3260 struct ctio7_to_24xx
*pkt
;
3261 struct qla_tgt_prm prm
;
3262 uint32_t full_req_cnt
= 0;
3263 unsigned long flags
= 0;
3266 if (!qpair
->fw_started
|| (cmd
->reset_count
!= qpair
->chip_reset
) ||
3267 (cmd
->sess
&& cmd
->sess
->deleted
)) {
3268 cmd
->state
= QLA_TGT_STATE_PROCESSED
;
3272 ql_dbg_qp(ql_dbg_tgt
, qpair
, 0xe018,
3273 "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p] qp %d\n",
3274 (xmit_type
& QLA_TGT_XMIT_STATUS
) ?
3275 1 : 0, cmd
->bufflen
, cmd
->sg_cnt
, cmd
->dma_data_direction
,
3276 &cmd
->se_cmd
, qpair
->id
);
3278 res
= qlt_pre_xmit_response(cmd
, &prm
, xmit_type
, scsi_status
,
3280 if (unlikely(res
!= 0)) {
3284 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
3286 if (xmit_type
== QLA_TGT_XMIT_STATUS
)
3287 qpair
->tgt_counters
.core_qla_snd_status
++;
3289 qpair
->tgt_counters
.core_qla_que_buf
++;
3291 if (!qpair
->fw_started
|| cmd
->reset_count
!= qpair
->chip_reset
) {
3293 * Either the port is not online or this request was from
3294 * previous life, just abort the processing.
3296 cmd
->state
= QLA_TGT_STATE_PROCESSED
;
3297 ql_dbg_qp(ql_dbg_async
, qpair
, 0xe101,
3298 "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n",
3299 vha
->flags
.online
, qla2x00_reset_active(vha
),
3300 cmd
->reset_count
, qpair
->chip_reset
);
3302 goto out_unmap_unlock
;
3305 /* Does F/W have an IOCBs for this request */
3306 res
= qlt_check_reserve_free_req(qpair
, full_req_cnt
);
3308 goto out_unmap_unlock
;
3310 if (cmd
->se_cmd
.prot_op
&& (xmit_type
& QLA_TGT_XMIT_DATA
))
3311 res
= qlt_build_ctio_crc2_pkt(qpair
, &prm
);
3313 res
= qlt_24xx_build_ctio_pkt(qpair
, &prm
);
3314 if (unlikely(res
!= 0)) {
3315 qpair
->req
->cnt
+= full_req_cnt
;
3316 goto out_unmap_unlock
;
3319 pkt
= (struct ctio7_to_24xx
*)prm
.pkt
;
3321 if (qlt_has_data(cmd
) && (xmit_type
& QLA_TGT_XMIT_DATA
)) {
3322 pkt
->u
.status0
.flags
|=
3323 cpu_to_le16(CTIO7_FLAGS_DATA_IN
|
3324 CTIO7_FLAGS_STATUS_MODE_0
);
3326 if (cmd
->se_cmd
.prot_op
== TARGET_PROT_NORMAL
)
3327 qlt_load_data_segments(&prm
);
3329 if (prm
.add_status_pkt
== 0) {
3330 if (xmit_type
& QLA_TGT_XMIT_STATUS
) {
3331 pkt
->u
.status0
.scsi_status
=
3332 cpu_to_le16(prm
.rq_result
);
3334 pkt
->u
.status0
.residual
=
3335 cpu_to_le32(prm
.residual
);
3337 pkt
->u
.status0
.flags
|= cpu_to_le16(
3338 CTIO7_FLAGS_SEND_STATUS
);
3339 if (qlt_need_explicit_conf(cmd
, 0)) {
3340 pkt
->u
.status0
.flags
|=
3342 CTIO7_FLAGS_EXPLICIT_CONFORM
|
3343 CTIO7_FLAGS_CONFORM_REQ
);
3349 * We have already made sure that there is sufficient
3350 * amount of request entries to not drop HW lock in
3353 struct ctio7_to_24xx
*ctio
=
3354 (struct ctio7_to_24xx
*)qlt_get_req_pkt(
3357 ql_dbg_qp(ql_dbg_tgt
, qpair
, 0x305e,
3358 "Building additional status packet 0x%p.\n",
3362 * T10Dif: ctio_crc2_to_fw overlay ontop of
3365 memcpy(ctio
, pkt
, sizeof(*ctio
));
3366 /* reset back to CTIO7 */
3367 ctio
->entry_count
= 1;
3368 ctio
->entry_type
= CTIO_TYPE7
;
3369 ctio
->dseg_count
= 0;
3370 ctio
->u
.status1
.flags
&= ~cpu_to_le16(
3371 CTIO7_FLAGS_DATA_IN
);
3373 /* Real finish is ctio_m1's finish */
3374 pkt
->handle
|= CTIO_INTERMEDIATE_HANDLE_MARK
;
3375 pkt
->u
.status0
.flags
|= cpu_to_le16(
3376 CTIO7_FLAGS_DONT_RET_CTIO
);
3378 /* qlt_24xx_init_ctio_to_isp will correct
3379 * all neccessary fields that's part of CTIO7.
3380 * There should be no residual of CTIO-CRC2 data.
3382 qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx
*)ctio
,
3386 qlt_24xx_init_ctio_to_isp(pkt
, &prm
);
3389 cmd
->state
= QLA_TGT_STATE_PROCESSED
; /* Mid-level is done processing */
3390 cmd
->cmd_sent_to_fw
= 1;
3391 cmd
->ctio_flags
= le16_to_cpu(pkt
->u
.status0
.flags
);
3393 /* Memory Barrier */
3395 if (qpair
->reqq_start_iocbs
)
3396 qpair
->reqq_start_iocbs(qpair
);
3398 qla2x00_start_iocbs(vha
, qpair
->req
);
3399 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
3404 qlt_unmap_sg(vha
, cmd
);
3405 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
3409 EXPORT_SYMBOL(qlt_xmit_response
);
3411 int qlt_rdy_to_xfer(struct qla_tgt_cmd
*cmd
)
3413 struct ctio7_to_24xx
*pkt
;
3414 struct scsi_qla_host
*vha
= cmd
->vha
;
3415 struct qla_tgt
*tgt
= cmd
->tgt
;
3416 struct qla_tgt_prm prm
;
3417 unsigned long flags
= 0;
3419 struct qla_qpair
*qpair
= cmd
->qpair
;
3421 memset(&prm
, 0, sizeof(prm
));
3427 if (!qpair
->fw_started
|| (cmd
->reset_count
!= qpair
->chip_reset
) ||
3428 (cmd
->sess
&& cmd
->sess
->deleted
)) {
3430 * Either the port is not online or this request was from
3431 * previous life, just abort the processing.
3434 cmd
->write_data_transferred
= 0;
3435 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
3436 vha
->hw
->tgt
.tgt_ops
->handle_data(cmd
);
3437 ql_dbg_qp(ql_dbg_async
, qpair
, 0xe102,
3438 "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n",
3439 vha
->flags
.online
, qla2x00_reset_active(vha
),
3440 cmd
->reset_count
, qpair
->chip_reset
);
3444 /* Calculate number of entries and segments required */
3445 if (qlt_pci_map_calc_cnt(&prm
) != 0)
3448 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
3449 /* Does F/W have an IOCBs for this request */
3450 res
= qlt_check_reserve_free_req(qpair
, prm
.req_cnt
);
3452 goto out_unlock_free_unmap
;
3453 if (cmd
->se_cmd
.prot_op
)
3454 res
= qlt_build_ctio_crc2_pkt(qpair
, &prm
);
3456 res
= qlt_24xx_build_ctio_pkt(qpair
, &prm
);
3458 if (unlikely(res
!= 0)) {
3459 qpair
->req
->cnt
+= prm
.req_cnt
;
3460 goto out_unlock_free_unmap
;
3463 pkt
= (struct ctio7_to_24xx
*)prm
.pkt
;
3464 pkt
->u
.status0
.flags
|= cpu_to_le16(CTIO7_FLAGS_DATA_OUT
|
3465 CTIO7_FLAGS_STATUS_MODE_0
);
3467 if (cmd
->se_cmd
.prot_op
== TARGET_PROT_NORMAL
)
3468 qlt_load_data_segments(&prm
);
3470 cmd
->state
= QLA_TGT_STATE_NEED_DATA
;
3471 cmd
->cmd_sent_to_fw
= 1;
3472 cmd
->ctio_flags
= le16_to_cpu(pkt
->u
.status0
.flags
);
3474 /* Memory Barrier */
3476 if (qpair
->reqq_start_iocbs
)
3477 qpair
->reqq_start_iocbs(qpair
);
3479 qla2x00_start_iocbs(vha
, qpair
->req
);
3480 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
3484 out_unlock_free_unmap
:
3485 qlt_unmap_sg(vha
, cmd
);
3486 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
3490 EXPORT_SYMBOL(qlt_rdy_to_xfer
);
3494 * it is assumed either hardware_lock or qpair lock is held.
3497 qlt_handle_dif_error(struct qla_qpair
*qpair
, struct qla_tgt_cmd
*cmd
,
3498 struct ctio_crc_from_fw
*sts
)
3500 uint8_t *ap
= &sts
->actual_dif
[0];
3501 uint8_t *ep
= &sts
->expected_dif
[0];
3502 uint64_t lba
= cmd
->se_cmd
.t_task_lba
;
3503 uint8_t scsi_status
, sense_key
, asc
, ascq
;
3504 unsigned long flags
;
3505 struct scsi_qla_host
*vha
= cmd
->vha
;
3507 cmd
->trc_flags
|= TRC_DIF_ERR
;
3509 cmd
->a_guard
= get_unaligned_be16(ap
+ 0);
3510 cmd
->a_app_tag
= get_unaligned_be16(ap
+ 2);
3511 cmd
->a_ref_tag
= get_unaligned_be32(ap
+ 4);
3513 cmd
->e_guard
= get_unaligned_be16(ep
+ 0);
3514 cmd
->e_app_tag
= get_unaligned_be16(ep
+ 2);
3515 cmd
->e_ref_tag
= get_unaligned_be32(ep
+ 4);
3517 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xf075,
3518 "%s: aborted %d state %d\n", __func__
, cmd
->aborted
, cmd
->state
);
3520 scsi_status
= sense_key
= asc
= ascq
= 0;
3522 /* check appl tag */
3523 if (cmd
->e_app_tag
!= cmd
->a_app_tag
) {
3524 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe00d,
3525 "App Tag ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] Ref[%x|%x], App[%x|%x], Guard [%x|%x] cmd=%p ox_id[%04x]",
3526 cmd
->cdb
[0], lba
, (lba
+cmd
->num_blks
), cmd
->num_blks
,
3527 cmd
->a_ref_tag
, cmd
->e_ref_tag
, cmd
->a_app_tag
,
3528 cmd
->e_app_tag
, cmd
->a_guard
, cmd
->e_guard
, cmd
,
3529 cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
);
3531 cmd
->dif_err_code
= DIF_ERR_APP
;
3532 scsi_status
= SAM_STAT_CHECK_CONDITION
;
3533 sense_key
= ABORTED_COMMAND
;
3539 if (cmd
->e_ref_tag
!= cmd
->a_ref_tag
) {
3540 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe00e,
3541 "Ref Tag ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] Ref[%x|%x], App[%x|%x], Guard[%x|%x] cmd=%p ox_id[%04x] ",
3542 cmd
->cdb
[0], lba
, (lba
+cmd
->num_blks
), cmd
->num_blks
,
3543 cmd
->a_ref_tag
, cmd
->e_ref_tag
, cmd
->a_app_tag
,
3544 cmd
->e_app_tag
, cmd
->a_guard
, cmd
->e_guard
, cmd
,
3545 cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
);
3547 cmd
->dif_err_code
= DIF_ERR_REF
;
3548 scsi_status
= SAM_STAT_CHECK_CONDITION
;
3549 sense_key
= ABORTED_COMMAND
;
3556 if (cmd
->e_guard
!= cmd
->a_guard
) {
3557 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe012,
3558 "Guard ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] Ref[%x|%x], App[%x|%x], Guard [%x|%x] cmd=%p ox_id[%04x]",
3559 cmd
->cdb
[0], lba
, (lba
+cmd
->num_blks
), cmd
->num_blks
,
3560 cmd
->a_ref_tag
, cmd
->e_ref_tag
, cmd
->a_app_tag
,
3561 cmd
->e_app_tag
, cmd
->a_guard
, cmd
->e_guard
, cmd
,
3562 cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
);
3564 cmd
->dif_err_code
= DIF_ERR_GRD
;
3565 scsi_status
= SAM_STAT_CHECK_CONDITION
;
3566 sense_key
= ABORTED_COMMAND
;
3571 switch (cmd
->state
) {
3572 case QLA_TGT_STATE_NEED_DATA
:
3573 /* handle_data will load DIF error code */
3574 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
3575 vha
->hw
->tgt
.tgt_ops
->handle_data(cmd
);
3578 spin_lock_irqsave(&cmd
->cmd_lock
, flags
);
3580 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
3581 vha
->hw
->tgt
.tgt_ops
->free_cmd(cmd
);
3584 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
3586 qlt_send_resp_ctio(qpair
, cmd
, scsi_status
, sense_key
, asc
,
3588 /* assume scsi status gets out on the wire.
3589 * Will not wait for completion.
3591 vha
->hw
->tgt
.tgt_ops
->free_cmd(cmd
);
3596 /* If hardware_lock held on entry, might drop it, then reaquire */
3597 /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */
3598 static int __qlt_send_term_imm_notif(struct scsi_qla_host
*vha
,
3599 struct imm_ntfy_from_isp
*ntfy
)
3601 struct nack_to_isp
*nack
;
3602 struct qla_hw_data
*ha
= vha
->hw
;
3606 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0xe01c,
3607 "Sending TERM ELS CTIO (ha=%p)\n", ha
);
3609 pkt
= (request_t
*)qla2x00_alloc_iocbs(vha
, NULL
);
3611 ql_dbg(ql_dbg_tgt
, vha
, 0xe080,
3612 "qla_target(%d): %s failed: unable to allocate "
3613 "request packet\n", vha
->vp_idx
, __func__
);
3617 pkt
->entry_type
= NOTIFY_ACK_TYPE
;
3618 pkt
->entry_count
= 1;
3619 pkt
->handle
= QLA_TGT_SKIP_HANDLE
;
3621 nack
= (struct nack_to_isp
*)pkt
;
3622 nack
->ox_id
= ntfy
->ox_id
;
3624 nack
->u
.isp24
.nport_handle
= ntfy
->u
.isp24
.nport_handle
;
3625 if (le16_to_cpu(ntfy
->u
.isp24
.status
) == IMM_NTFY_ELS
) {
3626 nack
->u
.isp24
.flags
= ntfy
->u
.isp24
.flags
&
3627 cpu_to_le16(NOTIFY24XX_FLAGS_PUREX_IOCB
);
3631 nack
->u
.isp24
.flags
|=
3632 __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE
);
3634 nack
->u
.isp24
.srr_rx_id
= ntfy
->u
.isp24
.srr_rx_id
;
3635 nack
->u
.isp24
.status
= ntfy
->u
.isp24
.status
;
3636 nack
->u
.isp24
.status_subcode
= ntfy
->u
.isp24
.status_subcode
;
3637 nack
->u
.isp24
.fw_handle
= ntfy
->u
.isp24
.fw_handle
;
3638 nack
->u
.isp24
.exchange_address
= ntfy
->u
.isp24
.exchange_address
;
3639 nack
->u
.isp24
.srr_rel_offs
= ntfy
->u
.isp24
.srr_rel_offs
;
3640 nack
->u
.isp24
.srr_ui
= ntfy
->u
.isp24
.srr_ui
;
3641 nack
->u
.isp24
.vp_index
= ntfy
->u
.isp24
.vp_index
;
3643 qla2x00_start_iocbs(vha
, vha
->req
);
3647 static void qlt_send_term_imm_notif(struct scsi_qla_host
*vha
,
3648 struct imm_ntfy_from_isp
*imm
, int ha_locked
)
3652 WARN_ON_ONCE(!ha_locked
);
3653 rc
= __qlt_send_term_imm_notif(vha
, imm
);
3654 pr_debug("rc = %d\n", rc
);
3658 * If hardware_lock held on entry, might drop it, then reaquire
3659 * This function sends the appropriate CTIO to ISP 2xxx or 24xx
3661 static int __qlt_send_term_exchange(struct qla_qpair
*qpair
,
3662 struct qla_tgt_cmd
*cmd
,
3663 struct atio_from_isp
*atio
)
3665 struct scsi_qla_host
*vha
= qpair
->vha
;
3666 struct ctio7_to_24xx
*ctio24
;
3667 struct qla_hw_data
*ha
= vha
->hw
;
3672 ql_dbg(ql_dbg_tgt
, vha
, 0xe009, "Sending TERM EXCH CTIO (ha=%p)\n", ha
);
3677 pkt
= (request_t
*)qla2x00_alloc_iocbs_ready(qpair
, NULL
);
3679 ql_dbg(ql_dbg_tgt
, vha
, 0xe050,
3680 "qla_target(%d): %s failed: unable to allocate "
3681 "request packet\n", vha
->vp_idx
, __func__
);
3686 if (cmd
->state
< QLA_TGT_STATE_PROCESSED
) {
3687 ql_dbg(ql_dbg_tgt
, vha
, 0xe051,
3688 "qla_target(%d): Terminating cmd %p with "
3689 "incorrect state %d\n", vha
->vp_idx
, cmd
,
3695 qpair
->tgt_counters
.num_term_xchg_sent
++;
3696 pkt
->entry_count
= 1;
3697 pkt
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
3699 ctio24
= (struct ctio7_to_24xx
*)pkt
;
3700 ctio24
->entry_type
= CTIO_TYPE7
;
3701 ctio24
->nport_handle
= cpu_to_le16(CTIO7_NHANDLE_UNRECOGNIZED
);
3702 ctio24
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
3703 ctio24
->vp_index
= vha
->vp_idx
;
3704 ctio24
->initiator_id
= be_id_to_le(atio
->u
.isp24
.fcp_hdr
.s_id
);
3705 ctio24
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
3706 temp
= (atio
->u
.isp24
.attr
<< 9) | CTIO7_FLAGS_STATUS_MODE_1
|
3707 CTIO7_FLAGS_TERMINATE
;
3708 ctio24
->u
.status1
.flags
= cpu_to_le16(temp
);
3709 temp
= be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
);
3710 ctio24
->u
.status1
.ox_id
= cpu_to_le16(temp
);
3712 /* Memory Barrier */
3714 if (qpair
->reqq_start_iocbs
)
3715 qpair
->reqq_start_iocbs(qpair
);
3717 qla2x00_start_iocbs(vha
, qpair
->req
);
3721 static void qlt_send_term_exchange(struct qla_qpair
*qpair
,
3722 struct qla_tgt_cmd
*cmd
, struct atio_from_isp
*atio
, int ha_locked
,
3725 struct scsi_qla_host
*vha
;
3726 unsigned long flags
= 0;
3729 /* why use different vha? NPIV */
3736 rc
= __qlt_send_term_exchange(qpair
, cmd
, atio
);
3738 qlt_alloc_qfull_cmd(vha
, atio
, 0, 0);
3741 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
3742 rc
= __qlt_send_term_exchange(qpair
, cmd
, atio
);
3744 qlt_alloc_qfull_cmd(vha
, atio
, 0, 0);
3747 if (cmd
&& !ul_abort
&& !cmd
->aborted
) {
3749 qlt_unmap_sg(vha
, cmd
);
3750 vha
->hw
->tgt
.tgt_ops
->free_cmd(cmd
);
3754 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
3759 static void qlt_init_term_exchange(struct scsi_qla_host
*vha
)
3761 struct list_head free_list
;
3762 struct qla_tgt_cmd
*cmd
, *tcmd
;
3764 vha
->hw
->tgt
.leak_exchg_thresh_hold
=
3765 (vha
->hw
->cur_fw_xcb_count
/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT
;
3768 if (!list_empty(&vha
->hw
->tgt
.q_full_list
)) {
3769 INIT_LIST_HEAD(&free_list
);
3770 list_splice_init(&vha
->hw
->tgt
.q_full_list
, &free_list
);
3772 list_for_each_entry_safe(cmd
, tcmd
, &free_list
, cmd_list
) {
3773 list_del(&cmd
->cmd_list
);
3774 /* This cmd was never sent to TCM. There is no need
3775 * to schedule free or call free_cmd
3778 vha
->hw
->tgt
.num_qfull_cmds_alloc
--;
3781 vha
->hw
->tgt
.num_qfull_cmds_dropped
= 0;
3784 static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host
*vha
)
3786 uint32_t total_leaked
;
3788 total_leaked
= vha
->hw
->tgt
.num_qfull_cmds_dropped
;
3790 if (vha
->hw
->tgt
.leak_exchg_thresh_hold
&&
3791 (total_leaked
> vha
->hw
->tgt
.leak_exchg_thresh_hold
)) {
3793 ql_dbg(ql_dbg_tgt
, vha
, 0xe079,
3794 "Chip reset due to exchange starvation: %d/%d.\n",
3795 total_leaked
, vha
->hw
->cur_fw_xcb_count
);
3797 if (IS_P3P_TYPE(vha
->hw
))
3798 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
3800 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3801 qla2xxx_wake_dpc(vha
);
3806 int qlt_abort_cmd(struct qla_tgt_cmd
*cmd
)
3808 struct qla_tgt
*tgt
= cmd
->tgt
;
3809 struct scsi_qla_host
*vha
= tgt
->vha
;
3810 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
3811 unsigned long flags
;
3813 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf014,
3814 "qla_target(%d): terminating exchange for aborted cmd=%p "
3815 "(se_cmd=%p, tag=%llu)", vha
->vp_idx
, cmd
, &cmd
->se_cmd
,
3818 spin_lock_irqsave(&cmd
->cmd_lock
, flags
);
3821 qlt_unmap_sg(vha
, cmd
);
3823 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
3825 * It's normal to see 2 calls in this path:
3826 * 1) XFER Rdy completion + CMD_T_ABORT
3827 * 2) TCM TMR - drain_state_list
3829 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf016,
3830 "multiple abort. %p transport_state %x, t_state %x, "
3831 "se_cmd_flags %x\n", cmd
, cmd
->se_cmd
.transport_state
,
3832 cmd
->se_cmd
.t_state
, cmd
->se_cmd
.se_cmd_flags
);
3836 cmd
->trc_flags
|= TRC_ABORT
;
3837 spin_unlock_irqrestore(&cmd
->cmd_lock
, flags
);
3839 qlt_send_term_exchange(cmd
->qpair
, cmd
, &cmd
->atio
, 0, 1);
3842 EXPORT_SYMBOL(qlt_abort_cmd
);
3844 void qlt_free_cmd(struct qla_tgt_cmd
*cmd
)
3846 struct fc_port
*sess
= cmd
->sess
;
3848 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe074,
3849 "%s: se_cmd[%p] ox_id %04x\n",
3850 __func__
, &cmd
->se_cmd
,
3851 be16_to_cpu(cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
));
3853 BUG_ON(cmd
->cmd_in_wq
);
3856 qlt_decr_num_pend_cmds(cmd
->vha
);
3858 BUG_ON(cmd
->sg_mapped
);
3859 cmd
->jiffies_at_free
= get_jiffies_64();
3861 if (!sess
|| !sess
->se_sess
) {
3865 cmd
->jiffies_at_free
= get_jiffies_64();
3866 cmd
->vha
->hw
->tgt
.tgt_ops
->rel_cmd(cmd
);
3868 EXPORT_SYMBOL(qlt_free_cmd
);
3871 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3873 static int qlt_term_ctio_exchange(struct qla_qpair
*qpair
, void *ctio
,
3874 struct qla_tgt_cmd
*cmd
, uint32_t status
)
3877 struct scsi_qla_host
*vha
= qpair
->vha
;
3879 if (cmd
->se_cmd
.prot_op
)
3880 ql_dbg(ql_dbg_tgt_dif
, vha
, 0xe013,
3881 "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] "
3882 "se_cmd=%p tag[%x] op %#x/%s",
3884 cmd
->num_blks
, &cmd
->se_cmd
,
3885 cmd
->atio
.u
.isp24
.exchange_addr
,
3886 cmd
->se_cmd
.prot_op
,
3887 prot_op_str(cmd
->se_cmd
.prot_op
));
3890 struct ctio7_from_24xx
*c
= (struct ctio7_from_24xx
*)ctio
;
3893 cpu_to_le16(OF_TERM_EXCH
));
3898 qlt_send_term_exchange(qpair
, cmd
, &cmd
->atio
, 1, 0);
3904 /* ha->hardware_lock supposed to be held on entry */
3905 static void *qlt_ctio_to_cmd(struct scsi_qla_host
*vha
,
3906 struct rsp_que
*rsp
, uint32_t handle
, void *ctio
)
3909 struct req_que
*req
;
3910 int qid
= GET_QID(handle
);
3911 uint32_t h
= handle
& ~QLA_TGT_HANDLE_MASK
;
3913 if (unlikely(h
== QLA_TGT_SKIP_HANDLE
))
3916 if (qid
== rsp
->req
->id
) {
3918 } else if (vha
->hw
->req_q_map
[qid
]) {
3919 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0x1000a,
3920 "qla_target(%d): CTIO completion with different QID %d handle %x\n",
3921 vha
->vp_idx
, rsp
->id
, handle
);
3922 req
= vha
->hw
->req_q_map
[qid
];
3927 h
&= QLA_CMD_HANDLE_MASK
;
3929 if (h
!= QLA_TGT_NULL_HANDLE
) {
3930 if (unlikely(h
>= req
->num_outstanding_cmds
)) {
3931 ql_dbg(ql_dbg_tgt
, vha
, 0xe052,
3932 "qla_target(%d): Wrong handle %x received\n",
3933 vha
->vp_idx
, handle
);
3937 cmd
= req
->outstanding_cmds
[h
];
3938 if (unlikely(cmd
== NULL
)) {
3939 ql_dbg(ql_dbg_async
, vha
, 0xe053,
3940 "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n",
3941 vha
->vp_idx
, handle
, req
->id
, rsp
->id
);
3944 req
->outstanding_cmds
[h
] = NULL
;
3945 } else if (ctio
!= NULL
) {
3946 /* We can't get loop ID from CTIO7 */
3947 ql_dbg(ql_dbg_tgt
, vha
, 0xe054,
3948 "qla_target(%d): Wrong CTIO received: QLA24xx doesn't "
3949 "support NULL handles\n", vha
->vp_idx
);
3957 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3959 static void qlt_do_ctio_completion(struct scsi_qla_host
*vha
,
3960 struct rsp_que
*rsp
, uint32_t handle
, uint32_t status
, void *ctio
)
3962 struct qla_hw_data
*ha
= vha
->hw
;
3963 struct se_cmd
*se_cmd
;
3964 struct qla_tgt_cmd
*cmd
;
3965 struct qla_qpair
*qpair
= rsp
->qpair
;
3967 if (handle
& CTIO_INTERMEDIATE_HANDLE_MARK
) {
3968 /* That could happen only in case of an error/reset/abort */
3969 if (status
!= CTIO_SUCCESS
) {
3970 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01d,
3971 "Intermediate CTIO received"
3972 " (status %x)\n", status
);
3977 cmd
= qlt_ctio_to_cmd(vha
, rsp
, handle
, ctio
);
3981 if ((le16_to_cpu(((struct ctio7_from_24xx
*)ctio
)->flags
) & CTIO7_FLAGS_DATA_OUT
) &&
3983 qlt_chk_edif_rx_sa_delete_pending(vha
, cmd
->sess
,
3984 (struct ctio7_from_24xx
*)ctio
);
3987 se_cmd
= &cmd
->se_cmd
;
3988 cmd
->cmd_sent_to_fw
= 0;
3990 qlt_unmap_sg(vha
, cmd
);
3992 if (unlikely(status
!= CTIO_SUCCESS
)) {
3993 switch (status
& 0xFFFF) {
3994 case CTIO_INVALID_RX_ID
:
3995 if (printk_ratelimit())
3996 dev_info(&vha
->hw
->pdev
->dev
,
3997 "qla_target(%d): CTIO with INVALID_RX_ID ATIO attr %x CTIO Flags %x|%x\n",
3998 vha
->vp_idx
, cmd
->atio
.u
.isp24
.attr
,
3999 ((cmd
->ctio_flags
>> 9) & 0xf),
4003 case CTIO_LIP_RESET
:
4004 case CTIO_TARGET_RESET
:
4006 /* driver request abort via Terminate exchange */
4009 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf058,
4010 "qla_target(%d): CTIO with "
4011 "status %#x received, state %x, se_cmd %p, "
4012 "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, "
4013 "TIMEOUT=b, INVALID_RX_ID=8)\n", vha
->vp_idx
,
4014 status
, cmd
->state
, se_cmd
);
4017 case CTIO_PORT_LOGGED_OUT
:
4018 case CTIO_PORT_UNAVAILABLE
:
4021 (status
& 0xFFFF) == CTIO_PORT_LOGGED_OUT
;
4023 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf059,
4024 "qla_target(%d): CTIO with %s status %x "
4025 "received (state %x, se_cmd %p)\n", vha
->vp_idx
,
4026 logged_out
? "PORT LOGGED OUT" : "PORT UNAVAILABLE",
4027 status
, cmd
->state
, se_cmd
);
4029 if (logged_out
&& cmd
->sess
) {
4031 * Session is already logged out, but we need
4032 * to notify initiator, who's not aware of this
4034 cmd
->sess
->send_els_logo
= 1;
4035 ql_dbg(ql_dbg_disc
, vha
, 0x20f8,
4036 "%s %d %8phC post del sess\n",
4037 __func__
, __LINE__
, cmd
->sess
->port_name
);
4039 qlt_schedule_sess_for_deletion(cmd
->sess
);
4043 case CTIO_DIF_ERROR
: {
4044 struct ctio_crc_from_fw
*crc
=
4045 (struct ctio_crc_from_fw
*)ctio
;
4046 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf073,
4047 "qla_target(%d): CTIO with DIF_ERROR status %x "
4048 "received (state %x, ulp_cmd %p) actual_dif[0x%llx] "
4049 "expect_dif[0x%llx]\n",
4050 vha
->vp_idx
, status
, cmd
->state
, se_cmd
,
4051 *((u64
*)&crc
->actual_dif
[0]),
4052 *((u64
*)&crc
->expected_dif
[0]));
4054 qlt_handle_dif_error(qpair
, cmd
, ctio
);
4058 case CTIO_FAST_AUTH_ERR
:
4059 case CTIO_FAST_INCOMP_PAD_LEN
:
4060 case CTIO_FAST_INVALID_REQ
:
4061 case CTIO_FAST_SPI_ERR
:
4062 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05b,
4063 "qla_target(%d): CTIO with EDIF error status 0x%x received (state %x, se_cmd %p\n",
4064 vha
->vp_idx
, status
, cmd
->state
, se_cmd
);
4068 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05b,
4069 "qla_target(%d): CTIO with error status 0x%x received (state %x, se_cmd %p\n",
4070 vha
->vp_idx
, status
, cmd
->state
, se_cmd
);
4075 /* "cmd->aborted" means
4076 * cmd is already aborted/terminated, we don't
4077 * need to terminate again. The exchange is already
4078 * cleaned up/freed at FW level. Just cleanup at driver
4081 if ((cmd
->state
!= QLA_TGT_STATE_NEED_DATA
) &&
4083 cmd
->trc_flags
|= TRC_CTIO_ERR
;
4084 if (qlt_term_ctio_exchange(qpair
, ctio
, cmd
, status
))
4089 if (cmd
->state
== QLA_TGT_STATE_PROCESSED
) {
4090 cmd
->trc_flags
|= TRC_CTIO_DONE
;
4091 } else if (cmd
->state
== QLA_TGT_STATE_NEED_DATA
) {
4092 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
4094 if (status
== CTIO_SUCCESS
)
4095 cmd
->write_data_transferred
= 1;
4097 ha
->tgt
.tgt_ops
->handle_data(cmd
);
4099 } else if (cmd
->aborted
) {
4100 cmd
->trc_flags
|= TRC_CTIO_ABORTED
;
4101 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01e,
4102 "Aborted command %p (tag %lld) finished\n", cmd
, se_cmd
->tag
);
4104 cmd
->trc_flags
|= TRC_CTIO_STRANGE
;
4105 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05c,
4106 "qla_target(%d): A command in state (%d) should "
4107 "not return a CTIO complete\n", vha
->vp_idx
, cmd
->state
);
4110 if (unlikely(status
!= CTIO_SUCCESS
) &&
4112 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01f, "Finishing failed CTIO\n");
4116 ha
->tgt
.tgt_ops
->free_cmd(cmd
);
4119 static inline int qlt_get_fcp_task_attr(struct scsi_qla_host
*vha
,
4124 switch (task_codes
) {
4125 case ATIO_SIMPLE_QUEUE
:
4126 fcp_task_attr
= TCM_SIMPLE_TAG
;
4128 case ATIO_HEAD_OF_QUEUE
:
4129 fcp_task_attr
= TCM_HEAD_TAG
;
4131 case ATIO_ORDERED_QUEUE
:
4132 fcp_task_attr
= TCM_ORDERED_TAG
;
4134 case ATIO_ACA_QUEUE
:
4135 fcp_task_attr
= TCM_ACA_TAG
;
4138 fcp_task_attr
= TCM_SIMPLE_TAG
;
4141 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05d,
4142 "qla_target: unknown task code %x, use ORDERED instead\n",
4144 fcp_task_attr
= TCM_ORDERED_TAG
;
4148 return fcp_task_attr
;
4152 * Process context for I/O path into tcm_qla2xxx code
4154 static void __qlt_do_work(struct qla_tgt_cmd
*cmd
)
4156 scsi_qla_host_t
*vha
= cmd
->vha
;
4157 struct qla_hw_data
*ha
= vha
->hw
;
4158 struct fc_port
*sess
= cmd
->sess
;
4159 struct atio_from_isp
*atio
= &cmd
->atio
;
4161 unsigned long flags
;
4162 uint32_t data_length
;
4163 int ret
, fcp_task_attr
, data_dir
, bidi
= 0;
4164 struct qla_qpair
*qpair
= cmd
->qpair
;
4167 cmd
->trc_flags
|= TRC_DO_WORK
;
4170 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf082,
4171 "cmd with tag %u is aborted\n",
4172 cmd
->atio
.u
.isp24
.exchange_addr
);
4176 spin_lock_init(&cmd
->cmd_lock
);
4177 cdb
= &atio
->u
.isp24
.fcp_cmnd
.cdb
[0];
4178 cmd
->se_cmd
.tag
= le32_to_cpu(atio
->u
.isp24
.exchange_addr
);
4180 if (atio
->u
.isp24
.fcp_cmnd
.rddata
&&
4181 atio
->u
.isp24
.fcp_cmnd
.wrdata
) {
4183 data_dir
= DMA_TO_DEVICE
;
4184 } else if (atio
->u
.isp24
.fcp_cmnd
.rddata
)
4185 data_dir
= DMA_FROM_DEVICE
;
4186 else if (atio
->u
.isp24
.fcp_cmnd
.wrdata
)
4187 data_dir
= DMA_TO_DEVICE
;
4189 data_dir
= DMA_NONE
;
4191 fcp_task_attr
= qlt_get_fcp_task_attr(vha
,
4192 atio
->u
.isp24
.fcp_cmnd
.task_attr
);
4193 data_length
= get_datalen_for_atio(atio
);
4195 ret
= ha
->tgt
.tgt_ops
->handle_cmd(vha
, cmd
, cdb
, data_length
,
4196 fcp_task_attr
, data_dir
, bidi
);
4200 * Drop extra session reference from qlt_handle_cmd_for_atio().
4202 ha
->tgt
.tgt_ops
->put_sess(sess
);
4206 ql_dbg(ql_dbg_io
, vha
, 0x3060, "Terminating work cmd %p", cmd
);
4208 * cmd has not sent to target yet, so pass NULL as the second
4209 * argument to qlt_send_term_exchange() and free the memory here.
4211 cmd
->trc_flags
|= TRC_DO_WORK_ERR
;
4212 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
4213 qlt_send_term_exchange(qpair
, NULL
, &cmd
->atio
, 1, 0);
4215 qlt_decr_num_pend_cmds(vha
);
4216 cmd
->vha
->hw
->tgt
.tgt_ops
->rel_cmd(cmd
);
4217 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
4219 ha
->tgt
.tgt_ops
->put_sess(sess
);
4222 static void qlt_do_work(struct work_struct
*work
)
4224 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
4225 scsi_qla_host_t
*vha
= cmd
->vha
;
4226 unsigned long flags
;
4228 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
4229 list_del(&cmd
->cmd_list
);
4230 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
4235 void qlt_clr_qp_table(struct scsi_qla_host
*vha
)
4237 unsigned long flags
;
4238 struct qla_hw_data
*ha
= vha
->hw
;
4239 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4243 ql_log(ql_log_info
, vha
, 0x706c,
4244 "User update Number of Active Qpairs %d\n",
4245 ha
->tgt
.num_act_qpairs
);
4247 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags
);
4249 btree_for_each_safe64(&tgt
->lun_qpair_map
, key
, node
)
4250 btree_remove64(&tgt
->lun_qpair_map
, key
);
4252 ha
->base_qpair
->lun_cnt
= 0;
4253 for (key
= 0; key
< ha
->max_qpairs
; key
++)
4254 if (ha
->queue_pair_map
[key
])
4255 ha
->queue_pair_map
[key
]->lun_cnt
= 0;
4257 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
, flags
);
4260 static void qlt_assign_qpair(struct scsi_qla_host
*vha
,
4261 struct qla_tgt_cmd
*cmd
)
4263 struct qla_qpair
*qpair
, *qp
;
4264 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4265 struct qla_qpair_hint
*h
;
4267 if (vha
->flags
.qpairs_available
) {
4268 h
= btree_lookup64(&tgt
->lun_qpair_map
, cmd
->unpacked_lun
);
4270 /* spread lun to qpair ratio evently */
4272 struct scsi_qla_host
*base_vha
=
4273 pci_get_drvdata(vha
->hw
->pdev
);
4275 qpair
= vha
->hw
->base_qpair
;
4276 if (qpair
->lun_cnt
== 0) {
4278 h
= qla_qpair_to_hint(tgt
, qpair
);
4280 rc
= btree_insert64(&tgt
->lun_qpair_map
,
4281 cmd
->unpacked_lun
, h
, GFP_ATOMIC
);
4284 ql_log(ql_log_info
, vha
, 0xd037,
4285 "Unable to insert lun %llx into lun_qpair_map\n",
4290 lcnt
= qpair
->lun_cnt
;
4294 list_for_each_entry(qp
, &base_vha
->qp_list
,
4296 if (qp
->lun_cnt
== 0) {
4298 h
= qla_qpair_to_hint(tgt
, qp
);
4300 rc
= btree_insert64(&tgt
->lun_qpair_map
,
4301 cmd
->unpacked_lun
, h
, GFP_ATOMIC
);
4304 ql_log(ql_log_info
, vha
, 0xd038,
4305 "Unable to insert lun %llx into lun_qpair_map\n",
4311 if (qp
->lun_cnt
< lcnt
) {
4320 h
= qla_qpair_to_hint(tgt
, qpair
);
4322 rc
= btree_insert64(&tgt
->lun_qpair_map
,
4323 cmd
->unpacked_lun
, h
, GFP_ATOMIC
);
4326 ql_log(ql_log_info
, vha
, 0xd039,
4327 "Unable to insert lun %llx into lun_qpair_map\n",
4332 h
= &tgt
->qphints
[0];
4335 cmd
->qpair
= h
->qpair
;
4336 cmd
->se_cmd
.cpuid
= h
->cpuid
;
4339 static struct qla_tgt_cmd
*qlt_get_tag(scsi_qla_host_t
*vha
,
4340 struct fc_port
*sess
,
4341 struct atio_from_isp
*atio
)
4343 struct qla_tgt_cmd
*cmd
;
4345 cmd
= vha
->hw
->tgt
.tgt_ops
->get_cmd(sess
);
4349 cmd
->cmd_type
= TYPE_TGT_CMD
;
4350 memcpy(&cmd
->atio
, atio
, sizeof(*atio
));
4351 INIT_LIST_HEAD(&cmd
->sess_cmd_list
);
4352 cmd
->state
= QLA_TGT_STATE_NEW
;
4353 cmd
->tgt
= vha
->vha_tgt
.qla_tgt
;
4354 qlt_incr_num_pend_cmds(vha
);
4357 cmd
->loop_id
= sess
->loop_id
;
4358 cmd
->conf_compl_supported
= sess
->conf_compl_supported
;
4361 cmd
->jiffies_at_alloc
= get_jiffies_64();
4363 cmd
->unpacked_lun
= scsilun_to_int(
4364 (struct scsi_lun
*)&atio
->u
.isp24
.fcp_cmnd
.lun
);
4365 qlt_assign_qpair(vha
, cmd
);
4366 cmd
->reset_count
= vha
->hw
->base_qpair
->chip_reset
;
4367 cmd
->vp_idx
= vha
->vp_idx
;
4368 cmd
->edif
= sess
->edif
.enable
;
4373 /* ha->hardware_lock supposed to be held on entry */
4374 static int qlt_handle_cmd_for_atio(struct scsi_qla_host
*vha
,
4375 struct atio_from_isp
*atio
)
4377 struct qla_hw_data
*ha
= vha
->hw
;
4378 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4379 struct fc_port
*sess
;
4380 struct qla_tgt_cmd
*cmd
;
4381 unsigned long flags
;
4384 if (unlikely(tgt
->tgt_stop
)) {
4385 ql_dbg(ql_dbg_io
, vha
, 0x3061,
4386 "New command while device %p is shutting down\n", tgt
);
4390 id
= be_to_port_id(atio
->u
.isp24
.fcp_hdr
.s_id
);
4391 if (IS_SW_RESV_ADDR(id
))
4394 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, atio
->u
.isp24
.fcp_hdr
.s_id
);
4395 if (unlikely(!sess
))
4398 /* Another WWN used to have our s_id. Our PLOGI scheduled its
4399 * session deletion, but it's still in sess_del_work wq */
4400 if (sess
->deleted
) {
4401 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf002,
4402 "New command while old session %p is being deleted\n",
4408 * Do kref_get() before returning + dropping qla_hw_data->hardware_lock.
4410 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
4411 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf004,
4412 "%s: kref_get fail, %8phC oxid %x \n",
4413 __func__
, sess
->port_name
,
4414 be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
));
4418 cmd
= qlt_get_tag(vha
, sess
, atio
);
4420 ql_dbg(ql_dbg_io
, vha
, 0x3062,
4421 "qla_target(%d): Allocation of cmd failed\n", vha
->vp_idx
);
4422 ha
->tgt
.tgt_ops
->put_sess(sess
);
4427 cmd
->trc_flags
|= TRC_NEW_CMD
;
4429 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
4430 list_add_tail(&cmd
->cmd_list
, &vha
->qla_cmd_list
);
4431 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
4433 INIT_WORK(&cmd
->work
, qlt_do_work
);
4434 if (vha
->flags
.qpairs_available
) {
4435 queue_work_on(cmd
->se_cmd
.cpuid
, qla_tgt_wq
, &cmd
->work
);
4436 } else if (ha
->msix_count
) {
4437 if (cmd
->atio
.u
.isp24
.fcp_cmnd
.rddata
)
4438 queue_work(qla_tgt_wq
, &cmd
->work
);
4440 queue_work_on(cmd
->se_cmd
.cpuid
, qla_tgt_wq
,
4443 queue_work(qla_tgt_wq
, &cmd
->work
);
4449 /* ha->hardware_lock supposed to be held on entry */
4450 static int qlt_issue_task_mgmt(struct fc_port
*sess
, u64 lun
,
4451 int fn
, void *iocb
, int flags
)
4453 struct scsi_qla_host
*vha
= sess
->vha
;
4454 struct qla_hw_data
*ha
= vha
->hw
;
4455 struct qla_tgt_mgmt_cmd
*mcmd
;
4456 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
4457 struct qla_qpair_hint
*h
= &vha
->vha_tgt
.qla_tgt
->qphints
[0];
4459 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
4461 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10009,
4462 "qla_target(%d): Allocation of management "
4463 "command failed, some commands and their data could "
4464 "leak\n", vha
->vp_idx
);
4467 memset(mcmd
, 0, sizeof(*mcmd
));
4471 memcpy(&mcmd
->orig_iocb
.imm_ntfy
, iocb
,
4472 sizeof(mcmd
->orig_iocb
.imm_ntfy
));
4474 mcmd
->tmr_func
= fn
;
4475 mcmd
->flags
= flags
;
4476 mcmd
->reset_count
= ha
->base_qpair
->chip_reset
;
4477 mcmd
->qpair
= h
->qpair
;
4479 mcmd
->se_cmd
.cpuid
= h
->cpuid
;
4480 mcmd
->unpacked_lun
= lun
;
4483 case QLA_TGT_LUN_RESET
:
4484 case QLA_TGT_CLEAR_TS
:
4485 case QLA_TGT_ABORT_TS
:
4486 abort_cmds_for_lun(vha
, lun
, a
->u
.isp24
.fcp_hdr
.s_id
);
4488 case QLA_TGT_CLEAR_ACA
:
4489 h
= qlt_find_qphint(vha
, mcmd
->unpacked_lun
);
4490 mcmd
->qpair
= h
->qpair
;
4491 mcmd
->se_cmd
.cpuid
= h
->cpuid
;
4494 case QLA_TGT_TARGET_RESET
:
4495 case QLA_TGT_NEXUS_LOSS_SESS
:
4496 case QLA_TGT_NEXUS_LOSS
:
4497 case QLA_TGT_ABORT_ALL
:
4503 INIT_WORK(&mcmd
->work
, qlt_do_tmr_work
);
4504 queue_work_on(mcmd
->se_cmd
.cpuid
, qla_tgt_wq
,
4510 /* ha->hardware_lock supposed to be held on entry */
4511 static int qlt_handle_task_mgmt(struct scsi_qla_host
*vha
, void *iocb
)
4513 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
4514 struct qla_hw_data
*ha
= vha
->hw
;
4515 struct fc_port
*sess
;
4518 unsigned long flags
;
4520 fn
= a
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
;
4522 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4523 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
4524 a
->u
.isp24
.fcp_hdr
.s_id
);
4525 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4528 scsilun_to_int((struct scsi_lun
*)&a
->u
.isp24
.fcp_cmnd
.lun
);
4530 if (sess
== NULL
|| sess
->deleted
)
4533 return qlt_issue_task_mgmt(sess
, unpacked_lun
, fn
, iocb
, 0);
4536 /* ha->hardware_lock supposed to be held on entry */
4537 static int __qlt_abort_task(struct scsi_qla_host
*vha
,
4538 struct imm_ntfy_from_isp
*iocb
, struct fc_port
*sess
)
4540 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
4541 struct qla_hw_data
*ha
= vha
->hw
;
4542 struct qla_tgt_mgmt_cmd
*mcmd
;
4546 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
4548 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05f,
4549 "qla_target(%d): %s: Allocation of ABORT cmd failed\n",
4550 vha
->vp_idx
, __func__
);
4553 memset(mcmd
, 0, sizeof(*mcmd
));
4556 memcpy(&mcmd
->orig_iocb
.imm_ntfy
, iocb
,
4557 sizeof(mcmd
->orig_iocb
.imm_ntfy
));
4560 scsilun_to_int((struct scsi_lun
*)&a
->u
.isp24
.fcp_cmnd
.lun
);
4561 mcmd
->reset_count
= ha
->base_qpair
->chip_reset
;
4562 mcmd
->tmr_func
= QLA_TGT_2G_ABORT_TASK
;
4563 mcmd
->qpair
= ha
->base_qpair
;
4565 rc
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, unpacked_lun
, mcmd
->tmr_func
,
4566 le16_to_cpu(iocb
->u
.isp2x
.seq_id
));
4568 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf060,
4569 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
4571 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
4578 /* ha->hardware_lock supposed to be held on entry */
4579 static int qlt_abort_task(struct scsi_qla_host
*vha
,
4580 struct imm_ntfy_from_isp
*iocb
)
4582 struct qla_hw_data
*ha
= vha
->hw
;
4583 struct fc_port
*sess
;
4585 unsigned long flags
;
4587 loop_id
= GET_TARGET_ID(ha
, (struct atio_from_isp
*)iocb
);
4589 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
4590 sess
= ha
->tgt
.tgt_ops
->find_sess_by_loop_id(vha
, loop_id
);
4591 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
4594 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf025,
4595 "qla_target(%d): task abort for unexisting "
4596 "session\n", vha
->vp_idx
);
4597 return qlt_sched_sess_work(vha
->vha_tgt
.qla_tgt
,
4598 QLA_TGT_SESS_WORK_ABORT
, iocb
, sizeof(*iocb
));
4601 return __qlt_abort_task(vha
, iocb
, sess
);
4604 void qlt_logo_completion_handler(fc_port_t
*fcport
, int rc
)
4606 if (rc
!= MBS_COMMAND_COMPLETE
) {
4607 ql_dbg(ql_dbg_tgt_mgt
, fcport
->vha
, 0xf093,
4608 "%s: se_sess %p / sess %p from"
4609 " port %8phC loop_id %#04x s_id %02x:%02x:%02x"
4610 " LOGO failed: %#x\n",
4614 fcport
->port_name
, fcport
->loop_id
,
4615 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
4616 fcport
->d_id
.b
.al_pa
, rc
);
4619 fcport
->logout_completed
= 1;
4623 * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list)
4625 * Schedules sessions with matching port_id/loop_id but different wwn for
4626 * deletion. Returns existing session with matching wwn if present.
4630 qlt_find_sess_invalidate_other(scsi_qla_host_t
*vha
, uint64_t wwn
,
4631 port_id_t port_id
, uint16_t loop_id
, struct fc_port
**conflict_sess
)
4633 struct fc_port
*sess
= NULL
, *other_sess
;
4636 *conflict_sess
= NULL
;
4638 list_for_each_entry(other_sess
, &vha
->vp_fcports
, list
) {
4640 other_wwn
= wwn_to_u64(other_sess
->port_name
);
4642 if (wwn
== other_wwn
) {
4648 /* find other sess with nport_id collision */
4649 if (port_id
.b24
== other_sess
->d_id
.b24
) {
4650 if (loop_id
!= other_sess
->loop_id
) {
4651 ql_dbg(ql_dbg_disc
, vha
, 0x1000c,
4652 "Invalidating sess %p loop_id %d wwn %llx.\n",
4653 other_sess
, other_sess
->loop_id
, other_wwn
);
4656 * logout_on_delete is set by default, but another
4657 * session that has the same s_id/loop_id combo
4658 * might have cleared it when requested this session
4659 * deletion, so don't touch it
4661 qlt_schedule_sess_for_deletion(other_sess
);
4664 * Another wwn used to have our s_id/loop_id
4665 * kill the session, but don't free the loop_id
4667 ql_dbg(ql_dbg_disc
, vha
, 0xf01b,
4668 "Invalidating sess %p loop_id %d wwn %llx.\n",
4669 other_sess
, other_sess
->loop_id
, other_wwn
);
4671 other_sess
->keep_nport_handle
= 1;
4672 if (other_sess
->disc_state
!= DSC_DELETED
)
4673 *conflict_sess
= other_sess
;
4674 qlt_schedule_sess_for_deletion(other_sess
);
4679 /* find other sess with nport handle collision */
4680 if ((loop_id
== other_sess
->loop_id
) &&
4681 (loop_id
!= FC_NO_LOOP_ID
)) {
4682 ql_dbg(ql_dbg_disc
, vha
, 0x1000d,
4683 "Invalidating sess %p loop_id %d wwn %llx.\n",
4684 other_sess
, other_sess
->loop_id
, other_wwn
);
4686 /* Same loop_id but different s_id
4687 * Ok to kill and logout */
4688 qlt_schedule_sess_for_deletion(other_sess
);
4695 /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */
4696 static int abort_cmds_for_s_id(struct scsi_qla_host
*vha
, port_id_t
*s_id
)
4698 struct qla_tgt_sess_op
*op
;
4699 struct qla_tgt_cmd
*cmd
;
4702 unsigned long flags
;
4704 key
= (((u32
)s_id
->b
.domain
<< 16) |
4705 ((u32
)s_id
->b
.area
<< 8) |
4706 ((u32
)s_id
->b
.al_pa
));
4708 spin_lock_irqsave(&vha
->cmd_list_lock
, flags
);
4709 list_for_each_entry(op
, &vha
->unknown_atio_list
, cmd_list
) {
4710 uint32_t op_key
= sid_to_key(op
->atio
.u
.isp24
.fcp_hdr
.s_id
);
4712 if (op_key
== key
) {
4718 list_for_each_entry(cmd
, &vha
->qla_cmd_list
, cmd_list
) {
4719 uint32_t cmd_key
= sid_to_key(cmd
->atio
.u
.isp24
.fcp_hdr
.s_id
);
4721 if (cmd_key
== key
) {
4726 spin_unlock_irqrestore(&vha
->cmd_list_lock
, flags
);
4731 static int qlt_handle_login(struct scsi_qla_host
*vha
,
4732 struct imm_ntfy_from_isp
*iocb
)
4734 struct fc_port
*sess
= NULL
, *conflict_sess
= NULL
;
4737 uint16_t loop_id
, wd3_lo
;
4739 struct qlt_plogi_ack_t
*pla
;
4740 unsigned long flags
;
4742 lockdep_assert_held(&vha
->hw
->hardware_lock
);
4744 wwn
= wwn_to_u64(iocb
->u
.isp24
.port_name
);
4746 port_id
.b
.domain
= iocb
->u
.isp24
.port_id
[2];
4747 port_id
.b
.area
= iocb
->u
.isp24
.port_id
[1];
4748 port_id
.b
.al_pa
= iocb
->u
.isp24
.port_id
[0];
4749 port_id
.b
.rsvd_1
= 0;
4751 loop_id
= le16_to_cpu(iocb
->u
.isp24
.nport_handle
);
4753 /* Mark all stale commands sitting in qla_tgt_wq for deletion */
4754 abort_cmds_for_s_id(vha
, &port_id
);
4757 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
4758 sess
= qlt_find_sess_invalidate_other(vha
, wwn
,
4759 port_id
, loop_id
, &conflict_sess
);
4760 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
4762 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4763 "%s %d Term INOT due to WWN=0 lid=%d, NportID %06X ",
4764 __func__
, __LINE__
, loop_id
, port_id
.b24
);
4765 qlt_send_term_imm_notif(vha
, iocb
, 1);
4769 if (IS_SW_RESV_ADDR(port_id
)) {
4774 if (vha
->hw
->flags
.edif_enabled
&&
4775 !(vha
->e_dbell
.db_flags
& EDB_ACTIVE
) &&
4776 iocb
->u
.isp24
.status_subcode
== ELS_PLOGI
&&
4777 !(le16_to_cpu(iocb
->u
.isp24
.flags
) & NOTIFY24XX_FLAGS_FCSP
)) {
4778 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4779 "%s %d Term INOT due to app not available lid=%d, NportID %06X ",
4780 __func__
, __LINE__
, loop_id
, port_id
.b24
);
4781 qlt_send_term_imm_notif(vha
, iocb
, 1);
4785 if (vha
->hw
->flags
.edif_enabled
) {
4786 if (DBELL_INACTIVE(vha
)) {
4787 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4788 "%s %d Term INOT due to app not started lid=%d, NportID %06X ",
4789 __func__
, __LINE__
, loop_id
, port_id
.b24
);
4790 qlt_send_term_imm_notif(vha
, iocb
, 1);
4792 } else if (iocb
->u
.isp24
.status_subcode
== ELS_PLOGI
&&
4793 !(le16_to_cpu(iocb
->u
.isp24
.flags
) & NOTIFY24XX_FLAGS_FCSP
)) {
4794 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4795 "%s %d Term INOT due to unsecure lid=%d, NportID %06X ",
4796 __func__
, __LINE__
, loop_id
, port_id
.b24
);
4797 qlt_send_term_imm_notif(vha
, iocb
, 1);
4802 pla
= qlt_plogi_ack_find_add(vha
, &port_id
, iocb
);
4804 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
, vha
, 0xffff,
4805 "%s %d %8phC Term INOT due to mem alloc fail",
4807 iocb
->u
.isp24
.port_name
);
4808 qlt_send_term_imm_notif(vha
, iocb
, 1);
4812 if (conflict_sess
) {
4813 conflict_sess
->login_gen
++;
4814 qlt_plogi_ack_link(vha
, pla
, conflict_sess
,
4815 QLT_PLOGI_LINK_CONFLICT
);
4820 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4821 "%s %d %8phC post new sess\n",
4822 __func__
, __LINE__
, iocb
->u
.isp24
.port_name
);
4823 if (iocb
->u
.isp24
.status_subcode
== ELS_PLOGI
)
4824 qla24xx_post_newsess_work(vha
, &port_id
,
4825 iocb
->u
.isp24
.port_name
,
4826 iocb
->u
.isp24
.u
.plogi
.node_name
,
4829 qla24xx_post_newsess_work(vha
, &port_id
,
4830 iocb
->u
.isp24
.port_name
, NULL
,
4836 if (sess
->disc_state
== DSC_UPD_FCPORT
) {
4840 * Remote port registration is still going on from
4841 * previous login. Allow it to finish before we
4842 * accept the new login.
4844 sess
->next_disc_state
= DSC_DELETE_PEND
;
4845 sec
= jiffies_to_msecs(jiffies
-
4846 sess
->jiffies_at_registration
) / 1000;
4847 if (sess
->sec_since_registration
< sec
&& sec
&&
4849 sess
->sec_since_registration
= sec
;
4850 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4851 "%s %8phC - Slow Rport registration (%d Sec)\n",
4852 __func__
, sess
->port_name
, sec
);
4855 if (!conflict_sess
) {
4856 list_del(&pla
->list
);
4857 kmem_cache_free(qla_tgt_plogi_cachep
, pla
);
4860 qlt_send_term_imm_notif(vha
, iocb
, 1);
4864 qlt_plogi_ack_link(vha
, pla
, sess
, QLT_PLOGI_LINK_SAME_WWN
);
4865 sess
->d_id
= port_id
;
4867 sess
->loop_id
= loop_id
;
4869 if (iocb
->u
.isp24
.status_subcode
== ELS_PLOGI
) {
4870 /* remote port has assigned Port ID */
4871 if (N2N_TOPO(vha
->hw
) && fcport_is_bigger(sess
))
4872 vha
->d_id
= sess
->d_id
;
4874 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4875 "%s %8phC - send port online\n",
4876 __func__
, sess
->port_name
);
4878 qla2x00_post_aen_work(vha
, FCH_EVT_PORT_ONLINE
,
4882 if (iocb
->u
.isp24
.status_subcode
== ELS_PRLI
) {
4883 sess
->fw_login_state
= DSC_LS_PRLI_PEND
;
4885 sess
->loop_id
= loop_id
;
4886 sess
->d_id
= port_id
;
4887 sess
->fw_login_state
= DSC_LS_PRLI_PEND
;
4888 wd3_lo
= le16_to_cpu(iocb
->u
.isp24
.u
.prli
.wd3_lo
);
4891 sess
->conf_compl_supported
= 1;
4893 if ((wd3_lo
& BIT_4
) == 0)
4894 sess
->port_type
= FCT_INITIATOR
;
4896 sess
->port_type
= FCT_TARGET
;
4899 sess
->fw_login_state
= DSC_LS_PLOGI_PEND
;
4902 ql_dbg(ql_dbg_disc
, vha
, 0x20f9,
4903 "%s %d %8phC DS %d\n",
4904 __func__
, __LINE__
, sess
->port_name
, sess
->disc_state
);
4906 switch (sess
->disc_state
) {
4908 case DSC_LOGIN_PEND
:
4909 qlt_plogi_ack_unref(vha
, pla
);
4914 * Under normal circumstances we want to release nport handle
4915 * during LOGO process to avoid nport handle leaks inside FW.
4916 * The exception is when LOGO is done while another PLOGI with
4917 * the same nport handle is waiting as might be the case here.
4918 * Note: there is always a possibily of a race where session
4919 * deletion has already started for other reasons (e.g. ACL
4920 * removal) and now PLOGI arrives:
4921 * 1. if PLOGI arrived in FW after nport handle has been freed,
4922 * FW must have assigned this PLOGI a new/same handle and we
4923 * can proceed ACK'ing it as usual when session deletion
4925 * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT
4926 * bit reached it, the handle has now been released. We'll
4927 * get an error when we ACK this PLOGI. Nothing will be sent
4928 * back to initiator. Initiator should eventually retry
4929 * PLOGI and situation will correct itself.
4931 sess
->keep_nport_handle
= ((sess
->loop_id
== loop_id
) &&
4932 (sess
->d_id
.b24
== port_id
.b24
));
4934 ql_dbg(ql_dbg_disc
, vha
, 0x20f9,
4935 "%s %d %8phC post del sess\n",
4936 __func__
, __LINE__
, sess
->port_name
);
4939 qlt_schedule_sess_for_deletion(sess
);
4947 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
4949 static int qlt_24xx_handle_els(struct scsi_qla_host
*vha
,
4950 struct imm_ntfy_from_isp
*iocb
)
4952 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4953 struct qla_hw_data
*ha
= vha
->hw
;
4954 struct fc_port
*sess
= NULL
, *conflict_sess
= NULL
;
4960 unsigned long flags
;
4962 lockdep_assert_held(&ha
->hardware_lock
);
4964 wwn
= wwn_to_u64(iocb
->u
.isp24
.port_name
);
4966 port_id
.b
.domain
= iocb
->u
.isp24
.port_id
[2];
4967 port_id
.b
.area
= iocb
->u
.isp24
.port_id
[1];
4968 port_id
.b
.al_pa
= iocb
->u
.isp24
.port_id
[0];
4969 port_id
.b
.rsvd_1
= 0;
4971 loop_id
= le16_to_cpu(iocb
->u
.isp24
.nport_handle
);
4973 ql_dbg(ql_dbg_disc
, vha
, 0xf026,
4974 "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n",
4975 vha
->vp_idx
, iocb
->u
.isp24
.port_id
[2],
4976 iocb
->u
.isp24
.port_id
[1], iocb
->u
.isp24
.port_id
[0],
4977 iocb
->u
.isp24
.status_subcode
, loop_id
,
4978 iocb
->u
.isp24
.port_name
);
4980 /* res = 1 means ack at the end of thread
4981 * res = 0 means ack async/later.
4983 switch (iocb
->u
.isp24
.status_subcode
) {
4985 res
= qlt_handle_login(vha
, iocb
);
4990 sess
= qla2x00_find_fcport_by_wwpn(vha
,
4991 iocb
->u
.isp24
.port_name
, 1);
4993 if (vha
->hw
->flags
.edif_enabled
&& sess
&&
4994 (!(sess
->flags
& FCF_FCSP_DEVICE
) ||
4995 !sess
->edif
.authok
)) {
4996 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
4997 "%s %d %8phC Term PRLI due to unauthorize PRLI\n",
4998 __func__
, __LINE__
, iocb
->u
.isp24
.port_name
);
4999 qlt_send_term_imm_notif(vha
, iocb
, 1);
5003 if (sess
&& sess
->plogi_link
[QLT_PLOGI_LINK_SAME_WWN
]) {
5004 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
5005 "%s %d %8phC Term PRLI due to PLOGI ACK not completed\n",
5007 iocb
->u
.isp24
.port_name
);
5008 qlt_send_term_imm_notif(vha
, iocb
, 1);
5012 res
= qlt_handle_login(vha
, iocb
);
5016 if (IS_SW_RESV_ADDR(port_id
)) {
5021 wd3_lo
= le16_to_cpu(iocb
->u
.isp24
.u
.prli
.wd3_lo
);
5024 spin_lock_irqsave(&tgt
->ha
->tgt
.sess_lock
, flags
);
5025 sess
= qlt_find_sess_invalidate_other(vha
, wwn
, port_id
,
5026 loop_id
, &conflict_sess
);
5027 spin_unlock_irqrestore(&tgt
->ha
->tgt
.sess_lock
, flags
);
5030 if (conflict_sess
) {
5031 switch (conflict_sess
->disc_state
) {
5033 case DSC_DELETE_PEND
:
5036 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf09b,
5037 "PRLI with conflicting sess %p port %8phC\n",
5038 conflict_sess
, conflict_sess
->port_name
);
5039 conflict_sess
->fw_login_state
=
5040 DSC_LS_PORT_UNAVAIL
;
5041 qlt_send_term_imm_notif(vha
, iocb
, 1);
5048 bool delete = false;
5051 if (vha
->hw
->flags
.edif_enabled
&& sess
&&
5052 (!(sess
->flags
& FCF_FCSP_DEVICE
) ||
5053 !sess
->edif
.authok
)) {
5054 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
5055 "%s %d %8phC Term PRLI due to unauthorize prli\n",
5056 __func__
, __LINE__
, iocb
->u
.isp24
.port_name
);
5057 qlt_send_term_imm_notif(vha
, iocb
, 1);
5061 spin_lock_irqsave(&tgt
->ha
->tgt
.sess_lock
, flags
);
5062 switch (sess
->fw_login_state
) {
5063 case DSC_LS_PLOGI_PEND
:
5064 case DSC_LS_PLOGI_COMP
:
5065 case DSC_LS_PRLI_COMP
:
5072 switch (sess
->disc_state
) {
5073 case DSC_UPD_FCPORT
:
5074 spin_unlock_irqrestore(&tgt
->ha
->tgt
.sess_lock
,
5077 sec
= jiffies_to_msecs(jiffies
-
5078 sess
->jiffies_at_registration
)/1000;
5079 if (sess
->sec_since_registration
< sec
&& sec
&&
5081 sess
->sec_since_registration
= sec
;
5082 ql_dbg(ql_dbg_disc
, sess
->vha
, 0xffff,
5083 "%s %8phC : Slow Rport registration(%d Sec)\n",
5084 __func__
, sess
->port_name
, sec
);
5086 qlt_send_term_imm_notif(vha
, iocb
, 1);
5089 case DSC_LOGIN_PEND
:
5091 case DSC_LOGIN_COMPLETE
:
5100 spin_unlock_irqrestore(&tgt
->ha
->tgt
.sess_lock
,
5103 * Impatient initiator sent PRLI before last
5104 * PLOGI could finish. Will force him to re-try,
5105 * while last one finishes.
5107 ql_log(ql_log_warn
, sess
->vha
, 0xf095,
5108 "sess %p PRLI received, before plogi ack.\n",
5110 qlt_send_term_imm_notif(vha
, iocb
, 1);
5116 * This shouldn't happen under normal circumstances,
5117 * since we have deleted the old session during PLOGI
5119 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf096,
5120 "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n",
5121 sess
->loop_id
, sess
, iocb
->u
.isp24
.nport_handle
);
5124 sess
->loop_id
= loop_id
;
5125 sess
->d_id
= port_id
;
5126 sess
->fw_login_state
= DSC_LS_PRLI_PEND
;
5129 sess
->conf_compl_supported
= 1;
5131 if ((wd3_lo
& BIT_4
) == 0)
5132 sess
->port_type
= FCT_INITIATOR
;
5134 sess
->port_type
= FCT_TARGET
;
5136 spin_unlock_irqrestore(&tgt
->ha
->tgt
.sess_lock
, flags
);
5138 res
= 1; /* send notify ack */
5140 /* Make session global (not used in fabric mode) */
5141 if (ha
->current_topology
!= ISP_CFG_F
) {
5143 ql_dbg(ql_dbg_disc
, vha
, 0x20fa,
5144 "%s %d %8phC post nack\n",
5145 __func__
, __LINE__
, sess
->port_name
);
5146 qla24xx_post_nack_work(vha
, sess
, iocb
,
5150 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5151 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5152 qla2xxx_wake_dpc(vha
);
5156 ql_dbg(ql_dbg_disc
, vha
, 0x20fb,
5157 "%s %d %8phC post nack\n",
5158 __func__
, __LINE__
, sess
->port_name
);
5159 qla24xx_post_nack_work(vha
, sess
, iocb
,
5167 if (le16_to_cpu(iocb
->u
.isp24
.flags
) &
5168 NOTIFY24XX_FLAGS_GLOBAL_TPRLO
) {
5170 qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
);
5177 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
5178 sess
= qla2x00_find_fcport_by_loopid(vha
, loop_id
);
5179 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
5183 sess
->fw_login_state
= DSC_LS_LOGO_PEND
;
5184 sess
->logo_ack_needed
= 1;
5185 memcpy(sess
->iocb
, iocb
, IOCB_SIZE
);
5188 res
= qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
);
5190 ql_dbg(ql_dbg_disc
, vha
, 0x20fc,
5191 "%s: logo %llx res %d sess %p ",
5192 __func__
, wwn
, res
, sess
);
5195 * cmd went upper layer, look for qlt_xmit_tm_rsp()
5196 * for LOGO_ACK & sess delete
5201 /* cmd did not go to upper layer. */
5203 qlt_schedule_sess_for_deletion(sess
);
5206 /* else logo will be ack */
5212 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5214 if (tgt
->link_reinit_iocb_pending
) {
5215 qlt_send_notify_ack(ha
->base_qpair
,
5216 &tgt
->link_reinit_iocb
, 0, 0, 0, 0, 0, 0);
5217 tgt
->link_reinit_iocb_pending
= 0;
5220 sess
= qla2x00_find_fcport_by_wwpn(vha
,
5221 iocb
->u
.isp24
.port_name
, 1);
5223 ql_dbg(ql_dbg_disc
, vha
, 0x20fd,
5224 "sess %p lid %d|%d DS %d LS %d\n",
5225 sess
, sess
->loop_id
, loop_id
,
5226 sess
->disc_state
, sess
->fw_login_state
);
5229 res
= 1; /* send notify ack */
5233 case ELS_FLOGI
: /* should never happen */
5235 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf061,
5236 "qla_target(%d): Unsupported ELS command %x "
5237 "received\n", vha
->vp_idx
, iocb
->u
.isp24
.status_subcode
);
5238 res
= qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
);
5242 ql_dbg(ql_dbg_disc
, vha
, 0xf026,
5243 "qla_target(%d): Exit ELS opcode: 0x%02x res %d\n",
5244 vha
->vp_idx
, iocb
->u
.isp24
.status_subcode
, res
);
5250 * ha->hardware_lock supposed to be held on entry.
5251 * Might drop it, then reacquire.
5253 static void qlt_handle_imm_notify(struct scsi_qla_host
*vha
,
5254 struct imm_ntfy_from_isp
*iocb
)
5256 struct qla_hw_data
*ha
= vha
->hw
;
5257 uint32_t add_flags
= 0;
5258 int send_notify_ack
= 1;
5261 lockdep_assert_held(&ha
->hardware_lock
);
5263 status
= le16_to_cpu(iocb
->u
.isp2x
.status
);
5265 case IMM_NTFY_LIP_RESET
:
5267 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf032,
5268 "qla_target(%d): LIP reset (loop %#x), subcode %x\n",
5269 vha
->vp_idx
, le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
5270 iocb
->u
.isp24
.status_subcode
);
5272 if (qlt_reset(vha
, iocb
, QLA_TGT_ABORT_ALL
) == 0)
5273 send_notify_ack
= 0;
5277 case IMM_NTFY_LIP_LINK_REINIT
:
5279 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5281 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf033,
5282 "qla_target(%d): LINK REINIT (loop %#x, "
5283 "subcode %x)\n", vha
->vp_idx
,
5284 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
5285 iocb
->u
.isp24
.status_subcode
);
5286 if (tgt
->link_reinit_iocb_pending
) {
5287 qlt_send_notify_ack(ha
->base_qpair
,
5288 &tgt
->link_reinit_iocb
, 0, 0, 0, 0, 0, 0);
5290 memcpy(&tgt
->link_reinit_iocb
, iocb
, sizeof(*iocb
));
5291 tgt
->link_reinit_iocb_pending
= 1;
5293 * QLogic requires to wait after LINK REINIT for possible
5294 * PDISC or ADISC ELS commands
5296 send_notify_ack
= 0;
5300 case IMM_NTFY_PORT_LOGOUT
:
5301 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf034,
5302 "qla_target(%d): Port logout (loop "
5303 "%#x, subcode %x)\n", vha
->vp_idx
,
5304 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
5305 iocb
->u
.isp24
.status_subcode
);
5307 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
) == 0)
5308 send_notify_ack
= 0;
5309 /* The sessions will be cleared in the callback, if needed */
5312 case IMM_NTFY_GLBL_TPRLO
:
5313 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf035,
5314 "qla_target(%d): Global TPRLO (%x)\n", vha
->vp_idx
, status
);
5315 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
) == 0)
5316 send_notify_ack
= 0;
5317 /* The sessions will be cleared in the callback, if needed */
5320 case IMM_NTFY_PORT_CONFIG
:
5321 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf036,
5322 "qla_target(%d): Port config changed (%x)\n", vha
->vp_idx
,
5324 if (qlt_reset(vha
, iocb
, QLA_TGT_ABORT_ALL
) == 0)
5325 send_notify_ack
= 0;
5326 /* The sessions will be cleared in the callback, if needed */
5329 case IMM_NTFY_GLBL_LOGO
:
5330 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06a,
5331 "qla_target(%d): Link failure detected\n",
5333 /* I_T nexus loss */
5334 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
) == 0)
5335 send_notify_ack
= 0;
5338 case IMM_NTFY_IOCB_OVERFLOW
:
5339 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06b,
5340 "qla_target(%d): Cannot provide requested "
5341 "capability (IOCB overflowed the immediate notify "
5342 "resource count)\n", vha
->vp_idx
);
5345 case IMM_NTFY_ABORT_TASK
:
5346 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf037,
5347 "qla_target(%d): Abort Task (S %08x I %#x -> "
5348 "L %#x)\n", vha
->vp_idx
,
5349 le16_to_cpu(iocb
->u
.isp2x
.seq_id
),
5350 GET_TARGET_ID(ha
, (struct atio_from_isp
*)iocb
),
5351 le16_to_cpu(iocb
->u
.isp2x
.lun
));
5352 if (qlt_abort_task(vha
, iocb
) == 0)
5353 send_notify_ack
= 0;
5356 case IMM_NTFY_RESOURCE
:
5357 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06c,
5358 "qla_target(%d): Out of resources, host %ld\n",
5359 vha
->vp_idx
, vha
->host_no
);
5362 case IMM_NTFY_MSG_RX
:
5363 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf038,
5364 "qla_target(%d): Immediate notify task %x\n",
5365 vha
->vp_idx
, iocb
->u
.isp2x
.task_flags
);
5369 if (qlt_24xx_handle_els(vha
, iocb
) == 0)
5370 send_notify_ack
= 0;
5373 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06d,
5374 "qla_target(%d): Received unknown immediate "
5375 "notify status %x\n", vha
->vp_idx
, status
);
5379 if (send_notify_ack
)
5380 qlt_send_notify_ack(ha
->base_qpair
, iocb
, add_flags
, 0, 0, 0,
5385 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
5386 * This function sends busy to ISP 2xxx or 24xx.
5388 static int __qlt_send_busy(struct qla_qpair
*qpair
,
5389 struct atio_from_isp
*atio
, uint16_t status
)
5391 struct scsi_qla_host
*vha
= qpair
->vha
;
5392 struct ctio7_to_24xx
*ctio24
;
5393 struct qla_hw_data
*ha
= vha
->hw
;
5395 struct fc_port
*sess
= NULL
;
5396 unsigned long flags
;
5400 id
= be_to_port_id(atio
->u
.isp24
.fcp_hdr
.s_id
);
5402 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
5403 sess
= qla2x00_find_fcport_by_nportid(vha
, &id
, 1);
5404 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
5406 qlt_send_term_exchange(qpair
, NULL
, atio
, 1, 0);
5409 /* Sending marker isn't necessary, since we called from ISR */
5411 pkt
= (request_t
*)__qla2x00_alloc_iocbs(qpair
, NULL
);
5413 ql_dbg(ql_dbg_io
, vha
, 0x3063,
5414 "qla_target(%d): %s failed: unable to allocate "
5415 "request packet", vha
->vp_idx
, __func__
);
5419 qpair
->tgt_counters
.num_q_full_sent
++;
5420 pkt
->entry_count
= 1;
5421 pkt
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
5423 ctio24
= (struct ctio7_to_24xx
*)pkt
;
5424 ctio24
->entry_type
= CTIO_TYPE7
;
5425 ctio24
->nport_handle
= cpu_to_le16(sess
->loop_id
);
5426 ctio24
->timeout
= cpu_to_le16(QLA_TGT_TIMEOUT
);
5427 ctio24
->vp_index
= vha
->vp_idx
;
5428 ctio24
->initiator_id
= be_id_to_le(atio
->u
.isp24
.fcp_hdr
.s_id
);
5429 ctio24
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
5430 temp
= (atio
->u
.isp24
.attr
<< 9) |
5431 CTIO7_FLAGS_STATUS_MODE_1
| CTIO7_FLAGS_SEND_STATUS
|
5432 CTIO7_FLAGS_DONT_RET_CTIO
;
5433 ctio24
->u
.status1
.flags
= cpu_to_le16(temp
);
5435 * CTIO from fw w/o se_cmd doesn't provide enough info to retry it,
5436 * if the explicit conformation is used.
5438 ctio24
->u
.status1
.ox_id
=
5439 cpu_to_le16(be16_to_cpu(atio
->u
.isp24
.fcp_hdr
.ox_id
));
5440 ctio24
->u
.status1
.scsi_status
= cpu_to_le16(status
);
5442 ctio24
->u
.status1
.residual
= cpu_to_le32(get_datalen_for_atio(atio
));
5444 if (ctio24
->u
.status1
.residual
!= 0)
5445 ctio24
->u
.status1
.scsi_status
|= cpu_to_le16(SS_RESIDUAL_UNDER
);
5447 /* Memory Barrier */
5449 if (qpair
->reqq_start_iocbs
)
5450 qpair
->reqq_start_iocbs(qpair
);
5452 qla2x00_start_iocbs(vha
, qpair
->req
);
5457 * This routine is used to allocate a command for either a QFull condition
5458 * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go
5462 qlt_alloc_qfull_cmd(struct scsi_qla_host
*vha
,
5463 struct atio_from_isp
*atio
, uint16_t status
, int qfull
)
5465 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5466 struct qla_hw_data
*ha
= vha
->hw
;
5467 struct fc_port
*sess
;
5468 struct qla_tgt_cmd
*cmd
;
5469 unsigned long flags
;
5471 if (unlikely(tgt
->tgt_stop
)) {
5472 ql_dbg(ql_dbg_io
, vha
, 0x300a,
5473 "New command while device %p is shutting down\n", tgt
);
5477 if ((vha
->hw
->tgt
.num_qfull_cmds_alloc
+ 1) > MAX_QFULL_CMDS_ALLOC
) {
5478 vha
->hw
->tgt
.num_qfull_cmds_dropped
++;
5479 if (vha
->hw
->tgt
.num_qfull_cmds_dropped
>
5480 vha
->qla_stats
.stat_max_qfull_cmds_dropped
)
5481 vha
->qla_stats
.stat_max_qfull_cmds_dropped
=
5482 vha
->hw
->tgt
.num_qfull_cmds_dropped
;
5484 ql_dbg(ql_dbg_io
, vha
, 0x3068,
5485 "qla_target(%d): %s: QFull CMD dropped[%d]\n",
5486 vha
->vp_idx
, __func__
,
5487 vha
->hw
->tgt
.num_qfull_cmds_dropped
);
5489 qlt_chk_exch_leak_thresh_hold(vha
);
5493 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id
5494 (vha
, atio
->u
.isp24
.fcp_hdr
.s_id
);
5498 cmd
= ha
->tgt
.tgt_ops
->get_cmd(sess
);
5500 ql_dbg(ql_dbg_io
, vha
, 0x3009,
5501 "qla_target(%d): %s: Allocation of cmd failed\n",
5502 vha
->vp_idx
, __func__
);
5504 vha
->hw
->tgt
.num_qfull_cmds_dropped
++;
5505 if (vha
->hw
->tgt
.num_qfull_cmds_dropped
>
5506 vha
->qla_stats
.stat_max_qfull_cmds_dropped
)
5507 vha
->qla_stats
.stat_max_qfull_cmds_dropped
=
5508 vha
->hw
->tgt
.num_qfull_cmds_dropped
;
5510 qlt_chk_exch_leak_thresh_hold(vha
);
5514 qlt_incr_num_pend_cmds(vha
);
5515 INIT_LIST_HEAD(&cmd
->cmd_list
);
5516 memcpy(&cmd
->atio
, atio
, sizeof(*atio
));
5518 cmd
->tgt
= vha
->vha_tgt
.qla_tgt
;
5520 cmd
->reset_count
= ha
->base_qpair
->chip_reset
;
5522 cmd
->qpair
= ha
->base_qpair
;
5526 /* NOTE: borrowing the state field to carry the status */
5527 cmd
->state
= status
;
5529 cmd
->term_exchg
= 1;
5531 spin_lock_irqsave(&vha
->hw
->tgt
.q_full_lock
, flags
);
5532 list_add_tail(&cmd
->cmd_list
, &vha
->hw
->tgt
.q_full_list
);
5534 vha
->hw
->tgt
.num_qfull_cmds_alloc
++;
5535 if (vha
->hw
->tgt
.num_qfull_cmds_alloc
>
5536 vha
->qla_stats
.stat_max_qfull_cmds_alloc
)
5537 vha
->qla_stats
.stat_max_qfull_cmds_alloc
=
5538 vha
->hw
->tgt
.num_qfull_cmds_alloc
;
5539 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
5543 qlt_free_qfull_cmds(struct qla_qpair
*qpair
)
5545 struct scsi_qla_host
*vha
= qpair
->vha
;
5546 struct qla_hw_data
*ha
= vha
->hw
;
5547 unsigned long flags
;
5548 struct qla_tgt_cmd
*cmd
, *tcmd
;
5549 struct list_head free_list
, q_full_list
;
5552 if (list_empty(&ha
->tgt
.q_full_list
))
5555 INIT_LIST_HEAD(&free_list
);
5556 INIT_LIST_HEAD(&q_full_list
);
5558 spin_lock_irqsave(&vha
->hw
->tgt
.q_full_lock
, flags
);
5559 if (list_empty(&ha
->tgt
.q_full_list
)) {
5560 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
5564 list_splice_init(&vha
->hw
->tgt
.q_full_list
, &q_full_list
);
5565 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
5567 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
5568 list_for_each_entry_safe(cmd
, tcmd
, &q_full_list
, cmd_list
) {
5570 /* cmd->state is a borrowed field to hold status */
5571 rc
= __qlt_send_busy(qpair
, &cmd
->atio
, cmd
->state
);
5572 else if (cmd
->term_exchg
)
5573 rc
= __qlt_send_term_exchange(qpair
, NULL
, &cmd
->atio
);
5579 ql_dbg(ql_dbg_io
, vha
, 0x3006,
5580 "%s: busy sent for ox_id[%04x]\n", __func__
,
5581 be16_to_cpu(cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
));
5582 else if (cmd
->term_exchg
)
5583 ql_dbg(ql_dbg_io
, vha
, 0x3007,
5584 "%s: Term exchg sent for ox_id[%04x]\n", __func__
,
5585 be16_to_cpu(cmd
->atio
.u
.isp24
.fcp_hdr
.ox_id
));
5587 ql_dbg(ql_dbg_io
, vha
, 0x3008,
5588 "%s: Unexpected cmd in QFull list %p\n", __func__
,
5591 list_move_tail(&cmd
->cmd_list
, &free_list
);
5593 /* piggy back on hardware_lock for protection */
5594 vha
->hw
->tgt
.num_qfull_cmds_alloc
--;
5596 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
5600 list_for_each_entry_safe(cmd
, tcmd
, &free_list
, cmd_list
) {
5601 list_del(&cmd
->cmd_list
);
5602 /* This cmd was never sent to TCM. There is no need
5603 * to schedule free or call free_cmd
5608 if (!list_empty(&q_full_list
)) {
5609 spin_lock_irqsave(&vha
->hw
->tgt
.q_full_lock
, flags
);
5610 list_splice(&q_full_list
, &vha
->hw
->tgt
.q_full_list
);
5611 spin_unlock_irqrestore(&vha
->hw
->tgt
.q_full_lock
, flags
);
5618 qlt_send_busy(struct qla_qpair
*qpair
, struct atio_from_isp
*atio
,
5622 struct scsi_qla_host
*vha
= qpair
->vha
;
5624 rc
= __qlt_send_busy(qpair
, atio
, status
);
5626 qlt_alloc_qfull_cmd(vha
, atio
, status
, 1);
5630 qlt_chk_qfull_thresh_hold(struct scsi_qla_host
*vha
, struct qla_qpair
*qpair
,
5631 struct atio_from_isp
*atio
, uint8_t ha_locked
)
5633 struct qla_hw_data
*ha
= vha
->hw
;
5634 unsigned long flags
;
5636 if (ha
->tgt
.num_pend_cmds
< Q_FULL_THRESH_HOLD(ha
))
5640 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5641 qlt_send_busy(qpair
, atio
, qla_sam_status
);
5643 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5648 /* ha->hardware_lock supposed to be held on entry */
5649 /* called via callback from qla2xxx */
5650 static void qlt_24xx_atio_pkt(struct scsi_qla_host
*vha
,
5651 struct atio_from_isp
*atio
, uint8_t ha_locked
)
5653 struct qla_hw_data
*ha
= vha
->hw
;
5654 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5656 unsigned long flags
= 0;
5658 if (unlikely(tgt
== NULL
)) {
5659 ql_dbg(ql_dbg_tgt
, vha
, 0x3064,
5660 "ATIO pkt, but no tgt (ha %p)", ha
);
5664 * In tgt_stop mode we also should allow all requests to pass.
5665 * Otherwise, some commands can stuck.
5668 tgt
->atio_irq_cmd_count
++;
5670 switch (atio
->u
.raw
.entry_type
) {
5672 if (unlikely(atio
->u
.isp24
.exchange_addr
==
5673 cpu_to_le32(ATIO_EXCHANGE_ADDRESS_UNKNOWN
))) {
5674 ql_dbg(ql_dbg_io
, vha
, 0x3065,
5675 "qla_target(%d): ATIO_TYPE7 "
5676 "received with UNKNOWN exchange address, "
5677 "sending QUEUE_FULL\n", vha
->vp_idx
);
5679 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5680 qlt_send_busy(ha
->base_qpair
, atio
, qla_sam_status
);
5682 spin_unlock_irqrestore(&ha
->hardware_lock
,
5687 if (likely(atio
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
== 0)) {
5688 rc
= qlt_chk_qfull_thresh_hold(vha
, ha
->base_qpair
,
5691 tgt
->atio_irq_cmd_count
--;
5694 rc
= qlt_handle_cmd_for_atio(vha
, atio
);
5696 rc
= qlt_handle_task_mgmt(vha
, atio
);
5698 if (unlikely(rc
!= 0)) {
5700 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5703 ql_dbg(ql_dbg_tgt
, vha
, 0xe05f,
5704 "qla_target: Unable to send command to target\n");
5707 ql_dbg(ql_dbg_tgt
, vha
, 0xe05f,
5708 "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n");
5709 qlt_send_term_exchange(ha
->base_qpair
, NULL
,
5713 ql_dbg(ql_dbg_tgt
, vha
, 0xe060,
5714 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5716 qlt_send_busy(ha
->base_qpair
, atio
,
5720 ql_dbg(ql_dbg_tgt
, vha
, 0xe060,
5721 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5723 qlt_send_busy(ha
->base_qpair
, atio
,
5728 spin_unlock_irqrestore(&ha
->hardware_lock
,
5733 case IMMED_NOTIFY_TYPE
:
5735 if (unlikely(atio
->u
.isp2x
.entry_status
!= 0)) {
5736 ql_dbg(ql_dbg_tgt
, vha
, 0xe05b,
5737 "qla_target(%d): Received ATIO packet %x "
5738 "with error status %x\n", vha
->vp_idx
,
5739 atio
->u
.raw
.entry_type
,
5740 atio
->u
.isp2x
.entry_status
);
5743 ql_dbg(ql_dbg_tgt
, vha
, 0xe02e, "%s", "IMMED_NOTIFY ATIO");
5746 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
5747 qlt_handle_imm_notify(vha
, (struct imm_ntfy_from_isp
*)atio
);
5749 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
5754 ql_dbg(ql_dbg_tgt
, vha
, 0xe05c,
5755 "qla_target(%d): Received unknown ATIO atio "
5756 "type %x\n", vha
->vp_idx
, atio
->u
.raw
.entry_type
);
5760 tgt
->atio_irq_cmd_count
--;
5764 * qpair lock is assume to be held
5765 * rc = 0 : send terminate & abts respond
5766 * rc != 0: do not send term & abts respond
5768 static int qlt_chk_unresolv_exchg(struct scsi_qla_host
*vha
,
5769 struct qla_qpair
*qpair
, struct abts_resp_from_24xx_fw
*entry
)
5771 struct qla_hw_data
*ha
= vha
->hw
;
5775 * Detect unresolved exchange. If the same ABTS is unable
5776 * to terminate an existing command and the same ABTS loops
5777 * between FW & Driver, then force FW dump. Under 1 jiff,
5778 * we should see multiple loops.
5780 if (qpair
->retry_term_exchg_addr
== entry
->exchange_addr_to_abort
&&
5781 qpair
->retry_term_jiff
== jiffies
) {
5782 /* found existing exchange */
5783 qpair
->retry_term_cnt
++;
5784 if (qpair
->retry_term_cnt
>= 5) {
5786 qpair
->retry_term_cnt
= 0;
5787 ql_log(ql_log_warn
, vha
, 0xffff,
5788 "Unable to send ABTS Respond. Dumping firmware.\n");
5789 ql_dump_buffer(ql_dbg_tgt_mgt
+ ql_dbg_buffer
,
5790 vha
, 0xffff, (uint8_t *)entry
, sizeof(*entry
));
5792 if (qpair
== ha
->base_qpair
)
5793 ha
->isp_ops
->fw_dump(vha
);
5795 qla2xxx_dump_fw(vha
);
5797 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
5798 qla2xxx_wake_dpc(vha
);
5800 } else if (qpair
->retry_term_jiff
!= jiffies
) {
5801 qpair
->retry_term_exchg_addr
= entry
->exchange_addr_to_abort
;
5802 qpair
->retry_term_cnt
= 0;
5803 qpair
->retry_term_jiff
= jiffies
;
5810 static void qlt_handle_abts_completion(struct scsi_qla_host
*vha
,
5811 struct rsp_que
*rsp
, response_t
*pkt
)
5813 struct abts_resp_from_24xx_fw
*entry
=
5814 (struct abts_resp_from_24xx_fw
*)pkt
;
5815 u32 h
= pkt
->handle
& ~QLA_TGT_HANDLE_MASK
;
5816 struct qla_tgt_mgmt_cmd
*mcmd
;
5817 struct qla_hw_data
*ha
= vha
->hw
;
5819 mcmd
= qlt_ctio_to_cmd(vha
, rsp
, pkt
->handle
, pkt
);
5820 if (mcmd
== NULL
&& h
!= QLA_TGT_SKIP_HANDLE
) {
5821 ql_dbg(ql_dbg_async
, vha
, 0xe064,
5822 "qla_target(%d): ABTS Comp without mcmd\n",
5829 vha
->vha_tgt
.qla_tgt
->abts_resp_expected
--;
5831 ql_dbg(ql_dbg_tgt
, vha
, 0xe038,
5832 "ABTS_RESP_24XX: compl_status %x\n",
5833 entry
->compl_status
);
5835 if (le16_to_cpu(entry
->compl_status
) != ABTS_RESP_COMPL_SUCCESS
) {
5836 if (le32_to_cpu(entry
->error_subcode1
) == 0x1E &&
5837 le32_to_cpu(entry
->error_subcode2
) == 0) {
5838 if (qlt_chk_unresolv_exchg(vha
, rsp
->qpair
, entry
)) {
5839 ha
->tgt
.tgt_ops
->free_mcmd(mcmd
);
5842 qlt_24xx_retry_term_exchange(vha
, rsp
->qpair
,
5845 ql_dbg(ql_dbg_tgt
, vha
, 0xe063,
5846 "qla_target(%d): ABTS_RESP_24XX failed %x (subcode %x:%x)",
5847 vha
->vp_idx
, entry
->compl_status
,
5848 entry
->error_subcode1
,
5849 entry
->error_subcode2
);
5850 ha
->tgt
.tgt_ops
->free_mcmd(mcmd
);
5853 ha
->tgt
.tgt_ops
->free_mcmd(mcmd
);
5857 /* ha->hardware_lock supposed to be held on entry */
5858 /* called via callback from qla2xxx */
5859 static void qlt_response_pkt(struct scsi_qla_host
*vha
,
5860 struct rsp_que
*rsp
, response_t
*pkt
)
5862 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
5864 if (unlikely(tgt
== NULL
)) {
5865 ql_dbg(ql_dbg_tgt
, vha
, 0xe05d,
5866 "qla_target(%d): Response pkt %x received, but no tgt (ha %p)\n",
5867 vha
->vp_idx
, pkt
->entry_type
, vha
->hw
);
5872 * In tgt_stop mode we also should allow all requests to pass.
5873 * Otherwise, some commands can stuck.
5876 switch (pkt
->entry_type
) {
5880 struct ctio7_from_24xx
*entry
= (struct ctio7_from_24xx
*)pkt
;
5882 qlt_do_ctio_completion(vha
, rsp
, entry
->handle
,
5883 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
5888 case ACCEPT_TGT_IO_TYPE
:
5890 struct atio_from_isp
*atio
= (struct atio_from_isp
*)pkt
;
5893 if (atio
->u
.isp2x
.status
!=
5894 cpu_to_le16(ATIO_CDB_VALID
)) {
5895 ql_dbg(ql_dbg_tgt
, vha
, 0xe05e,
5896 "qla_target(%d): ATIO with error "
5897 "status %x received\n", vha
->vp_idx
,
5898 le16_to_cpu(atio
->u
.isp2x
.status
));
5902 rc
= qlt_chk_qfull_thresh_hold(vha
, rsp
->qpair
, atio
, 1);
5906 rc
= qlt_handle_cmd_for_atio(vha
, atio
);
5907 if (unlikely(rc
!= 0)) {
5910 ql_dbg(ql_dbg_tgt
, vha
, 0xe05f,
5911 "qla_target: Unable to send command to target\n");
5914 ql_dbg(ql_dbg_tgt
, vha
, 0xe05f,
5915 "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n");
5916 qlt_send_term_exchange(rsp
->qpair
, NULL
,
5920 ql_dbg(ql_dbg_tgt
, vha
, 0xe060,
5921 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5923 qlt_send_busy(rsp
->qpair
, atio
,
5927 ql_dbg(ql_dbg_tgt
, vha
, 0xe060,
5928 "qla_target(%d): Unable to send command to target, sending BUSY status\n",
5930 qlt_send_busy(rsp
->qpair
, atio
,
5938 case CONTINUE_TGT_IO_TYPE
:
5940 struct ctio_to_2xxx
*entry
= (struct ctio_to_2xxx
*)pkt
;
5942 qlt_do_ctio_completion(vha
, rsp
, entry
->handle
,
5943 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
5950 struct ctio_to_2xxx
*entry
= (struct ctio_to_2xxx
*)pkt
;
5952 qlt_do_ctio_completion(vha
, rsp
, entry
->handle
,
5953 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
5958 case IMMED_NOTIFY_TYPE
:
5959 ql_dbg(ql_dbg_tgt
, vha
, 0xe035, "%s", "IMMED_NOTIFY\n");
5960 qlt_handle_imm_notify(vha
, (struct imm_ntfy_from_isp
*)pkt
);
5963 case NOTIFY_ACK_TYPE
:
5964 if (tgt
->notify_ack_expected
> 0) {
5965 struct nack_to_isp
*entry
= (struct nack_to_isp
*)pkt
;
5967 ql_dbg(ql_dbg_tgt
, vha
, 0xe036,
5968 "NOTIFY_ACK seq %08x status %x\n",
5969 le16_to_cpu(entry
->u
.isp2x
.seq_id
),
5970 le16_to_cpu(entry
->u
.isp2x
.status
));
5971 tgt
->notify_ack_expected
--;
5972 if (entry
->u
.isp2x
.status
!=
5973 cpu_to_le16(NOTIFY_ACK_SUCCESS
)) {
5974 ql_dbg(ql_dbg_tgt
, vha
, 0xe061,
5975 "qla_target(%d): NOTIFY_ACK "
5976 "failed %x\n", vha
->vp_idx
,
5977 le16_to_cpu(entry
->u
.isp2x
.status
));
5980 ql_dbg(ql_dbg_tgt
, vha
, 0xe062,
5981 "qla_target(%d): Unexpected NOTIFY_ACK received\n",
5986 case ABTS_RECV_24XX
:
5987 ql_dbg(ql_dbg_tgt
, vha
, 0xe037,
5988 "ABTS_RECV_24XX: instance %d\n", vha
->vp_idx
);
5989 qlt_24xx_handle_abts(vha
, (struct abts_recv_from_24xx
*)pkt
);
5992 case ABTS_RESP_24XX
:
5993 if (tgt
->abts_resp_expected
> 0) {
5994 qlt_handle_abts_completion(vha
, rsp
, pkt
);
5996 ql_dbg(ql_dbg_tgt
, vha
, 0xe064,
5997 "qla_target(%d): Unexpected ABTS_RESP_24XX "
5998 "received\n", vha
->vp_idx
);
6003 ql_dbg(ql_dbg_tgt
, vha
, 0xe065,
6004 "qla_target(%d): Received unknown response pkt "
6005 "type %x\n", vha
->vp_idx
, pkt
->entry_type
);
6012 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
6014 void qlt_async_event(uint16_t code
, struct scsi_qla_host
*vha
,
6017 struct qla_hw_data
*ha
= vha
->hw
;
6018 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
6021 if (!tgt
|| tgt
->tgt_stop
|| tgt
->tgt_stopped
)
6024 if (((code
== MBA_POINT_TO_POINT
) || (code
== MBA_CHG_IN_CONNECTION
)) &&
6028 * In tgt_stop mode we also should allow all requests to pass.
6029 * Otherwise, some commands can stuck.
6034 case MBA_RESET
: /* Reset */
6035 case MBA_SYSTEM_ERR
: /* System Error */
6036 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
6037 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
6038 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03a,
6039 "qla_target(%d): System error async event %#x "
6040 "occurred", vha
->vp_idx
, code
);
6042 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up. */
6043 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
6048 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03b,
6049 "qla_target(%d): Async LOOP_UP occurred "
6050 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
,
6051 mailbox
[0], mailbox
[1], mailbox
[2], mailbox
[3]);
6052 if (tgt
->link_reinit_iocb_pending
) {
6053 qlt_send_notify_ack(ha
->base_qpair
,
6054 &tgt
->link_reinit_iocb
,
6056 tgt
->link_reinit_iocb_pending
= 0;
6061 case MBA_LIP_OCCURRED
:
6064 case MBA_RSCN_UPDATE
:
6065 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03c,
6066 "qla_target(%d): Async event %#x occurred "
6067 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
, code
,
6068 mailbox
[0], mailbox
[1], mailbox
[2], mailbox
[3]);
6071 case MBA_REJECTED_FCP_CMD
:
6072 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf017,
6073 "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)",
6075 mailbox
[0], mailbox
[1], mailbox
[2], mailbox
[3]);
6077 if (mailbox
[3] == 1) {
6078 /* exchange starvation. */
6079 vha
->hw
->exch_starvation
++;
6080 if (vha
->hw
->exch_starvation
> 5) {
6081 ql_log(ql_log_warn
, vha
, 0xd03a,
6082 "Exchange starvation-. Resetting RISC\n");
6084 vha
->hw
->exch_starvation
= 0;
6085 if (IS_P3P_TYPE(vha
->hw
))
6086 set_bit(FCOE_CTX_RESET_NEEDED
,
6089 set_bit(ISP_ABORT_NEEDED
,
6091 qla2xxx_wake_dpc(vha
);
6096 case MBA_PORT_UPDATE
:
6097 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03d,
6098 "qla_target(%d): Port update async event %#x "
6099 "occurred: updating the ports database (m[0]=%x, m[1]=%x, "
6100 "m[2]=%x, m[3]=%x)", vha
->vp_idx
, code
,
6101 mailbox
[0], mailbox
[1], mailbox
[2], mailbox
[3]);
6103 login_code
= mailbox
[2];
6104 if (login_code
== 0x4) {
6105 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03e,
6106 "Async MB 2: Got PLOGI Complete\n");
6107 vha
->hw
->exch_starvation
= 0;
6108 } else if (login_code
== 0x7)
6109 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03f,
6110 "Async MB 2: Port Logged Out\n");
6118 static fc_port_t
*qlt_get_port_database(struct scsi_qla_host
*vha
,
6121 fc_port_t
*fcport
, *tfcp
, *del
;
6123 unsigned long flags
;
6126 fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
6128 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06f,
6129 "qla_target(%d): Allocation of tmp FC port failed",
6134 fcport
->loop_id
= loop_id
;
6136 rc
= qla24xx_gpdb_wait(vha
, fcport
, 0);
6137 if (rc
!= QLA_SUCCESS
) {
6138 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf070,
6139 "qla_target(%d): Failed to retrieve fcport "
6140 "information -- get_port_database() returned %x "
6141 "(loop_id=0x%04x)", vha
->vp_idx
, rc
, loop_id
);
6147 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
6148 tfcp
= qla2x00_find_fcport_by_wwpn(vha
, fcport
->port_name
, 1);
6151 tfcp
->d_id
= fcport
->d_id
;
6152 tfcp
->port_type
= fcport
->port_type
;
6153 tfcp
->supported_classes
= fcport
->supported_classes
;
6154 tfcp
->flags
|= fcport
->flags
;
6155 tfcp
->scan_state
= QLA_FCPORT_FOUND
;
6160 if (vha
->hw
->current_topology
== ISP_CFG_F
)
6161 fcport
->flags
|= FCF_FABRIC_DEVICE
;
6163 list_add_tail(&fcport
->list
, &vha
->vp_fcports
);
6164 if (!IS_SW_RESV_ADDR(fcport
->d_id
))
6165 vha
->fcport_count
++;
6166 fcport
->login_gen
++;
6167 qla2x00_set_fcport_disc_state(fcport
, DSC_LOGIN_COMPLETE
);
6168 fcport
->login_succ
= 1;
6172 fcport
->deleted
= 0;
6173 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
6175 switch (vha
->host
->active_mode
) {
6176 case MODE_INITIATOR
:
6179 if (!IS_IIDMA_CAPABLE(vha
->hw
) || !vha
->hw
->flags
.gpsc_supported
) {
6180 qla24xx_sched_upd_fcport(fcport
);
6182 ql_dbg(ql_dbg_disc
, vha
, 0x20ff,
6183 "%s %d %8phC post gpsc fcp_cnt %d\n",
6184 __func__
, __LINE__
, fcport
->port_name
, vha
->fcport_count
);
6185 qla24xx_post_gpsc_work(vha
, fcport
);
6195 qla2x00_free_fcport(del
);
6200 /* Must be called under tgt_mutex */
6201 static struct fc_port
*qlt_make_local_sess(struct scsi_qla_host
*vha
,
6204 struct fc_port
*sess
= NULL
;
6205 fc_port_t
*fcport
= NULL
;
6206 int rc
, global_resets
;
6207 uint16_t loop_id
= 0;
6209 if (s_id
.domain
== 0xFF && s_id
.area
== 0xFC) {
6211 * This is Domain Controller, so it should be
6212 * OK to drop SCSI commands from it.
6214 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf042,
6215 "Unable to find initiator with S_ID %x:%x:%x",
6216 s_id
.domain
, s_id
.area
, s_id
.al_pa
);
6220 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
6224 atomic_read(&vha
->vha_tgt
.qla_tgt
->tgt_global_resets_count
);
6226 rc
= qla24xx_get_loop_id(vha
, s_id
, &loop_id
);
6228 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
6230 ql_log(ql_log_info
, vha
, 0xf071,
6231 "qla_target(%d): Unable to find "
6232 "initiator with S_ID %x:%x:%x",
6233 vha
->vp_idx
, s_id
.domain
, s_id
.area
, s_id
.al_pa
);
6235 if (rc
== -ENOENT
) {
6236 qlt_port_logo_t logo
;
6238 logo
.id
= be_to_port_id(s_id
);
6240 qlt_send_first_logo(vha
, &logo
);
6246 fcport
= qlt_get_port_database(vha
, loop_id
);
6248 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
6252 if (global_resets
!=
6253 atomic_read(&vha
->vha_tgt
.qla_tgt
->tgt_global_resets_count
)) {
6254 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf043,
6255 "qla_target(%d): global reset during session discovery "
6256 "(counter was %d, new %d), retrying", vha
->vp_idx
,
6258 atomic_read(&vha
->vha_tgt
.
6259 qla_tgt
->tgt_global_resets_count
));
6263 sess
= qlt_create_sess(vha
, fcport
, true);
6265 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
6270 static void qlt_abort_work(struct qla_tgt
*tgt
,
6271 struct qla_tgt_sess_work_param
*prm
)
6273 struct scsi_qla_host
*vha
= tgt
->vha
;
6274 struct qla_hw_data
*ha
= vha
->hw
;
6275 struct fc_port
*sess
= NULL
;
6276 unsigned long flags
= 0, flags2
= 0;
6280 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags2
);
6285 s_id
= le_id_to_be(prm
->abts
.fcp_hdr_le
.s_id
);
6287 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, s_id
);
6289 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags2
);
6291 sess
= qlt_make_local_sess(vha
, s_id
);
6292 /* sess has got an extra creation ref */
6294 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags2
);
6298 if (sess
->deleted
) {
6303 if (!kref_get_unless_zero(&sess
->sess_kref
)) {
6304 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0xf01c,
6305 "%s: kref_get fail %8phC \n",
6306 __func__
, sess
->port_name
);
6312 rc
= __qlt_24xx_handle_abts(vha
, &prm
->abts
, sess
);
6313 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags2
);
6315 ha
->tgt
.tgt_ops
->put_sess(sess
);
6322 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags2
);
6325 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6326 qlt_24xx_send_abts_resp(ha
->base_qpair
, &prm
->abts
,
6327 FCP_TMF_REJECTED
, false);
6328 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6331 static void qlt_sess_work_fn(struct work_struct
*work
)
6333 struct qla_tgt
*tgt
= container_of(work
, struct qla_tgt
, sess_work
);
6334 struct scsi_qla_host
*vha
= tgt
->vha
;
6335 unsigned long flags
;
6337 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf000, "Sess work (tgt %p)", tgt
);
6339 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
6340 while (!list_empty(&tgt
->sess_works_list
)) {
6341 struct qla_tgt_sess_work_param
*prm
= list_entry(
6342 tgt
->sess_works_list
.next
, typeof(*prm
),
6343 sess_works_list_entry
);
6346 * This work can be scheduled on several CPUs at time, so we
6347 * must delete the entry to eliminate double processing
6349 list_del(&prm
->sess_works_list_entry
);
6351 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
6353 switch (prm
->type
) {
6354 case QLA_TGT_SESS_WORK_ABORT
:
6355 qlt_abort_work(tgt
, prm
);
6362 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
6366 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
6369 /* Must be called under tgt_host_action_mutex */
6370 int qlt_add_target(struct qla_hw_data
*ha
, struct scsi_qla_host
*base_vha
)
6372 struct qla_tgt
*tgt
;
6374 struct qla_qpair_hint
*h
;
6376 if (!QLA_TGT_MODE_ENABLED())
6379 if (!IS_TGT_MODE_CAPABLE(ha
)) {
6380 ql_log(ql_log_warn
, base_vha
, 0xe070,
6381 "This adapter does not support target mode.\n");
6385 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe03b,
6386 "Registering target for host %ld(%p).\n", base_vha
->host_no
, ha
);
6388 BUG_ON(base_vha
->vha_tgt
.qla_tgt
!= NULL
);
6390 tgt
= kzalloc(sizeof(struct qla_tgt
), GFP_KERNEL
);
6392 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe066,
6393 "Unable to allocate struct qla_tgt\n");
6397 tgt
->qphints
= kcalloc(ha
->max_qpairs
+ 1,
6398 sizeof(struct qla_qpair_hint
),
6400 if (!tgt
->qphints
) {
6402 ql_log(ql_log_warn
, base_vha
, 0x0197,
6403 "Unable to allocate qpair hints.\n");
6407 qla2xxx_driver_template
.supported_mode
|= MODE_TARGET
;
6409 rc
= btree_init64(&tgt
->lun_qpair_map
);
6411 kfree(tgt
->qphints
);
6413 ql_log(ql_log_info
, base_vha
, 0x0198,
6414 "Unable to initialize lun_qpair_map btree\n");
6417 h
= &tgt
->qphints
[0];
6418 h
->qpair
= ha
->base_qpair
;
6419 INIT_LIST_HEAD(&h
->hint_elem
);
6420 h
->cpuid
= ha
->base_qpair
->cpuid
;
6421 list_add_tail(&h
->hint_elem
, &ha
->base_qpair
->hints_list
);
6423 for (i
= 0; i
< ha
->max_qpairs
; i
++) {
6424 unsigned long flags
;
6426 struct qla_qpair
*qpair
= ha
->queue_pair_map
[i
];
6428 h
= &tgt
->qphints
[i
+ 1];
6429 INIT_LIST_HEAD(&h
->hint_elem
);
6432 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
6433 list_add_tail(&h
->hint_elem
, &qpair
->hints_list
);
6434 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
6435 h
->cpuid
= qpair
->cpuid
;
6440 tgt
->vha
= base_vha
;
6441 init_waitqueue_head(&tgt
->waitQ
);
6442 spin_lock_init(&tgt
->sess_work_lock
);
6443 INIT_WORK(&tgt
->sess_work
, qlt_sess_work_fn
);
6444 INIT_LIST_HEAD(&tgt
->sess_works_list
);
6445 atomic_set(&tgt
->tgt_global_resets_count
, 0);
6447 base_vha
->vha_tgt
.qla_tgt
= tgt
;
6449 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe067,
6450 "qla_target(%d): using 64 Bit PCI addressing",
6453 tgt
->sg_tablesize
= QLA_TGT_MAX_SG_24XX(base_vha
->req
->length
- 3);
6455 mutex_lock(&qla_tgt_mutex
);
6456 list_add_tail(&tgt
->tgt_list_entry
, &qla_tgt_glist
);
6457 mutex_unlock(&qla_tgt_mutex
);
6459 if (ha
->tgt
.tgt_ops
&& ha
->tgt
.tgt_ops
->add_target
)
6460 ha
->tgt
.tgt_ops
->add_target(base_vha
);
6465 /* Must be called under tgt_host_action_mutex */
6466 int qlt_remove_target(struct qla_hw_data
*ha
, struct scsi_qla_host
*vha
)
6468 if (!vha
->vha_tgt
.qla_tgt
)
6471 if (vha
->fc_vport
) {
6472 qlt_release(vha
->vha_tgt
.qla_tgt
);
6476 /* free left over qfull cmds */
6477 qlt_init_term_exchange(vha
);
6479 ql_dbg(ql_dbg_tgt
, vha
, 0xe03c, "Unregistering target for host %ld(%p)",
6481 qlt_release(vha
->vha_tgt
.qla_tgt
);
6486 void qla_remove_hostmap(struct qla_hw_data
*ha
)
6488 struct scsi_qla_host
*node
;
6491 btree_for_each_safe32(&ha
->host_map
, key
, node
)
6492 btree_remove32(&ha
->host_map
, key
);
6494 btree_destroy32(&ha
->host_map
);
6497 static void qlt_lport_dump(struct scsi_qla_host
*vha
, u64 wwpn
,
6500 pr_debug("qla2xxx HW vha->node_name: %8phC\n", vha
->node_name
);
6501 pr_debug("qla2xxx HW vha->port_name: %8phC\n", vha
->port_name
);
6502 put_unaligned_be64(wwpn
, b
);
6503 pr_debug("qla2xxx passed configfs WWPN: %8phC\n", b
);
6507 * qlt_lport_register - register lport with external module
6509 * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data
6510 * @phys_wwpn: physical port WWPN
6511 * @npiv_wwpn: NPIV WWPN
6512 * @npiv_wwnn: NPIV WWNN
6513 * @callback: lport initialization callback for tcm_qla2xxx code
6515 int qlt_lport_register(void *target_lport_ptr
, u64 phys_wwpn
,
6516 u64 npiv_wwpn
, u64 npiv_wwnn
,
6517 int (*callback
)(struct scsi_qla_host
*, void *, u64
, u64
))
6519 struct qla_tgt
*tgt
;
6520 struct scsi_qla_host
*vha
;
6521 struct qla_hw_data
*ha
;
6522 struct Scsi_Host
*host
;
6523 unsigned long flags
;
6527 mutex_lock(&qla_tgt_mutex
);
6528 list_for_each_entry(tgt
, &qla_tgt_glist
, tgt_list_entry
) {
6536 if (!(host
->hostt
->supported_mode
& MODE_TARGET
))
6539 if (vha
->qlini_mode
== QLA2XXX_INI_MODE_ENABLED
)
6542 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6543 if ((!npiv_wwpn
|| !npiv_wwnn
) && host
->active_mode
& MODE_TARGET
) {
6544 pr_debug("MODE_TARGET already active on qla2xxx(%d)\n",
6546 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6549 if (tgt
->tgt_stop
) {
6550 pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n",
6552 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6555 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6557 if (!scsi_host_get(host
)) {
6558 ql_dbg(ql_dbg_tgt
, vha
, 0xe068,
6559 "Unable to scsi_host_get() for"
6560 " qla2xxx scsi_host\n");
6563 qlt_lport_dump(vha
, phys_wwpn
, b
);
6565 if (memcmp(vha
->port_name
, b
, WWN_SIZE
)) {
6566 scsi_host_put(host
);
6569 rc
= (*callback
)(vha
, target_lport_ptr
, npiv_wwpn
, npiv_wwnn
);
6571 scsi_host_put(host
);
6573 mutex_unlock(&qla_tgt_mutex
);
6576 mutex_unlock(&qla_tgt_mutex
);
6580 EXPORT_SYMBOL(qlt_lport_register
);
6583 * qlt_lport_deregister - Degister lport
6585 * @vha: Registered scsi_qla_host pointer
6587 void qlt_lport_deregister(struct scsi_qla_host
*vha
)
6589 struct qla_hw_data
*ha
= vha
->hw
;
6590 struct Scsi_Host
*sh
= vha
->host
;
6592 * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data
6594 vha
->vha_tgt
.target_lport_ptr
= NULL
;
6595 ha
->tgt
.tgt_ops
= NULL
;
6597 * Release the Scsi_Host reference for the underlying qla2xxx host
6601 EXPORT_SYMBOL(qlt_lport_deregister
);
6603 /* Must be called under HW lock */
6604 void qlt_set_mode(struct scsi_qla_host
*vha
)
6606 switch (vha
->qlini_mode
) {
6607 case QLA2XXX_INI_MODE_DISABLED
:
6608 case QLA2XXX_INI_MODE_EXCLUSIVE
:
6609 vha
->host
->active_mode
= MODE_TARGET
;
6611 case QLA2XXX_INI_MODE_ENABLED
:
6612 vha
->host
->active_mode
= MODE_INITIATOR
;
6614 case QLA2XXX_INI_MODE_DUAL
:
6615 vha
->host
->active_mode
= MODE_DUAL
;
6622 /* Must be called under HW lock */
6623 static void qlt_clear_mode(struct scsi_qla_host
*vha
)
6625 switch (vha
->qlini_mode
) {
6626 case QLA2XXX_INI_MODE_DISABLED
:
6627 vha
->host
->active_mode
= MODE_UNKNOWN
;
6629 case QLA2XXX_INI_MODE_EXCLUSIVE
:
6630 vha
->host
->active_mode
= MODE_INITIATOR
;
6632 case QLA2XXX_INI_MODE_ENABLED
:
6633 case QLA2XXX_INI_MODE_DUAL
:
6634 vha
->host
->active_mode
= MODE_INITIATOR
;
6642 * qla_tgt_enable_vha - NO LOCK HELD
6644 * host_reset, bring up w/ Target Mode Enabled
6647 qlt_enable_vha(struct scsi_qla_host
*vha
)
6649 struct qla_hw_data
*ha
= vha
->hw
;
6650 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
6651 unsigned long flags
;
6652 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
6655 ql_dbg(ql_dbg_tgt
, vha
, 0xe069,
6656 "Unable to locate qla_tgt pointer from"
6657 " struct qla_hw_data\n");
6661 if (vha
->qlini_mode
== QLA2XXX_INI_MODE_ENABLED
)
6664 if (ha
->tgt
.num_act_qpairs
> ha
->max_qpairs
)
6665 ha
->tgt
.num_act_qpairs
= ha
->max_qpairs
;
6666 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6667 tgt
->tgt_stopped
= 0;
6669 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6671 mutex_lock(&ha
->optrom_mutex
);
6672 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf021,
6675 qla24xx_disable_vp(vha
);
6676 qla24xx_enable_vp(vha
);
6678 set_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
);
6679 qla2xxx_wake_dpc(base_vha
);
6680 WARN_ON_ONCE(qla2x00_wait_for_hba_online(base_vha
) !=
6683 mutex_unlock(&ha
->optrom_mutex
);
6685 EXPORT_SYMBOL(qlt_enable_vha
);
6688 * qla_tgt_disable_vha - NO LOCK HELD
6690 * Disable Target Mode and reset the adapter
6692 static void qlt_disable_vha(struct scsi_qla_host
*vha
)
6694 struct qla_hw_data
*ha
= vha
->hw
;
6695 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
6696 unsigned long flags
;
6699 ql_dbg(ql_dbg_tgt
, vha
, 0xe06a,
6700 "Unable to locate qla_tgt pointer from"
6701 " struct qla_hw_data\n");
6706 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6707 qlt_clear_mode(vha
);
6708 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6710 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
6711 qla2xxx_wake_dpc(vha
);
6714 * We are expecting the offline state.
6715 * QLA_FUNCTION_FAILED means that adapter is offline.
6717 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
)
6718 ql_dbg(ql_dbg_tgt
, vha
, 0xe081,
6719 "adapter is offline\n");
6723 * Called from qla_init.c:qla24xx_vport_create() contex to setup
6724 * the target mode specific struct scsi_qla_host and struct qla_hw_data
6728 qlt_vport_create(struct scsi_qla_host
*vha
, struct qla_hw_data
*ha
)
6730 vha
->vha_tgt
.qla_tgt
= NULL
;
6732 mutex_init(&vha
->vha_tgt
.tgt_mutex
);
6733 mutex_init(&vha
->vha_tgt
.tgt_host_action_mutex
);
6735 INIT_LIST_HEAD(&vha
->unknown_atio_list
);
6736 INIT_DELAYED_WORK(&vha
->unknown_atio_work
, qlt_unknown_atio_work_fn
);
6738 qlt_clear_mode(vha
);
6741 * NOTE: Currently the value is kept the same for <24xx and
6742 * >=24xx ISPs. If it is necessary to change it,
6743 * the check should be added for specific ISPs,
6744 * assigning the value appropriately.
6746 ha
->tgt
.atio_q_length
= ATIO_ENTRY_CNT_24XX
;
6748 qlt_add_target(ha
, vha
);
6752 qlt_rff_id(struct scsi_qla_host
*vha
)
6756 * FC-4 Feature bit 0 indicates target functionality to the name server.
6758 if (qla_tgt_mode_enabled(vha
)) {
6759 fc4_feature
= BIT_0
;
6760 } else if (qla_ini_mode_enabled(vha
)) {
6761 fc4_feature
= BIT_1
;
6762 } else if (qla_dual_mode_enabled(vha
))
6763 fc4_feature
= BIT_0
| BIT_1
;
6769 * qlt_init_atio_q_entries() - Initializes ATIO queue entries.
6772 * Beginning of ATIO ring has initialization control block already built
6773 * by nvram config routine.
6775 * Returns 0 on success.
6778 qlt_init_atio_q_entries(struct scsi_qla_host
*vha
)
6780 struct qla_hw_data
*ha
= vha
->hw
;
6782 struct atio_from_isp
*pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring
;
6784 if (qla_ini_mode_enabled(vha
))
6787 for (cnt
= 0; cnt
< ha
->tgt
.atio_q_length
; cnt
++) {
6788 pkt
->u
.raw
.signature
= cpu_to_le32(ATIO_PROCESSED
);
6795 * qlt_24xx_process_atio_queue() - Process ATIO queue entries.
6796 * @ha: SCSI driver HA context
6799 qlt_24xx_process_atio_queue(struct scsi_qla_host
*vha
, uint8_t ha_locked
)
6801 struct qla_hw_data
*ha
= vha
->hw
;
6802 struct atio_from_isp
*pkt
;
6805 if (!ha
->flags
.fw_started
)
6808 while ((ha
->tgt
.atio_ring_ptr
->signature
!= ATIO_PROCESSED
) ||
6809 fcpcmd_is_corrupted(ha
->tgt
.atio_ring_ptr
)) {
6810 pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring_ptr
;
6811 cnt
= pkt
->u
.raw
.entry_count
;
6813 if (unlikely(fcpcmd_is_corrupted(ha
->tgt
.atio_ring_ptr
))) {
6815 * This packet is corrupted. The header + payload
6816 * can not be trusted. There is no point in passing
6819 ql_log(ql_log_warn
, vha
, 0xd03c,
6820 "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n",
6821 &pkt
->u
.isp24
.fcp_hdr
.s_id
,
6822 be16_to_cpu(pkt
->u
.isp24
.fcp_hdr
.ox_id
),
6823 pkt
->u
.isp24
.exchange_addr
, pkt
);
6825 adjust_corrupted_atio(pkt
);
6826 qlt_send_term_exchange(ha
->base_qpair
, NULL
, pkt
,
6829 qlt_24xx_atio_pkt_all_vps(vha
,
6830 (struct atio_from_isp
*)pkt
, ha_locked
);
6833 for (i
= 0; i
< cnt
; i
++) {
6834 ha
->tgt
.atio_ring_index
++;
6835 if (ha
->tgt
.atio_ring_index
== ha
->tgt
.atio_q_length
) {
6836 ha
->tgt
.atio_ring_index
= 0;
6837 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
6839 ha
->tgt
.atio_ring_ptr
++;
6841 pkt
->u
.raw
.signature
= cpu_to_le32(ATIO_PROCESSED
);
6842 pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring_ptr
;
6847 /* Adjust ring index */
6848 wrt_reg_dword(ISP_ATIO_Q_OUT(vha
), ha
->tgt
.atio_ring_index
);
6852 qlt_24xx_config_rings(struct scsi_qla_host
*vha
)
6854 struct qla_hw_data
*ha
= vha
->hw
;
6855 struct qla_msix_entry
*msix
= &ha
->msix_entries
[2];
6856 struct init_cb_24xx
*icb
= (struct init_cb_24xx
*)ha
->init_cb
;
6858 if (!QLA_TGT_MODE_ENABLED())
6861 wrt_reg_dword(ISP_ATIO_Q_IN(vha
), 0);
6862 wrt_reg_dword(ISP_ATIO_Q_OUT(vha
), 0);
6863 rd_reg_dword(ISP_ATIO_Q_OUT(vha
));
6865 if (ha
->flags
.msix_enabled
) {
6866 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
) || IS_QLA28XX(ha
)) {
6867 icb
->msix_atio
= cpu_to_le16(msix
->entry
);
6868 icb
->firmware_options_2
&= cpu_to_le32(~BIT_26
);
6869 ql_dbg(ql_dbg_init
, vha
, 0xf072,
6870 "Registering ICB vector 0x%x for atio que.\n",
6875 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
) || IS_QLA28XX(ha
)) {
6877 icb
->firmware_options_2
|= cpu_to_le32(BIT_26
);
6878 ql_dbg(ql_dbg_init
, vha
, 0xf072,
6879 "%s: Use INTx for ATIOQ.\n", __func__
);
6885 qlt_24xx_config_nvram_stage1(struct scsi_qla_host
*vha
, struct nvram_24xx
*nv
)
6887 struct qla_hw_data
*ha
= vha
->hw
;
6890 if (!QLA_TGT_MODE_ENABLED())
6893 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
6894 if (!ha
->tgt
.saved_set
) {
6895 /* We save only once */
6896 ha
->tgt
.saved_exchange_count
= nv
->exchange_count
;
6897 ha
->tgt
.saved_firmware_options_1
=
6898 nv
->firmware_options_1
;
6899 ha
->tgt
.saved_firmware_options_2
=
6900 nv
->firmware_options_2
;
6901 ha
->tgt
.saved_firmware_options_3
=
6902 nv
->firmware_options_3
;
6903 ha
->tgt
.saved_set
= 1;
6906 if (qla_tgt_mode_enabled(vha
))
6907 nv
->exchange_count
= cpu_to_le16(0xFFFF);
6909 nv
->exchange_count
= cpu_to_le16(vha
->ql2xexchoffld
);
6911 /* Enable target mode */
6912 nv
->firmware_options_1
|= cpu_to_le32(BIT_4
);
6914 /* Disable ini mode, if requested */
6915 if (qla_tgt_mode_enabled(vha
))
6916 nv
->firmware_options_1
|= cpu_to_le32(BIT_5
);
6918 /* Disable Full Login after LIP */
6919 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
6920 /* Enable initial LIP */
6921 nv
->firmware_options_1
&= cpu_to_le32(~BIT_9
);
6922 if (ql2xtgt_tape_enable
)
6923 /* Enable FC Tape support */
6924 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
6926 /* Disable FC Tape support */
6927 nv
->firmware_options_2
&= cpu_to_le32(~BIT_12
);
6929 /* Disable Full Login after LIP */
6930 nv
->host_p
&= cpu_to_le32(~BIT_10
);
6933 * clear BIT 15 explicitly as we have seen at least
6934 * a couple of instances where this was set and this
6935 * was causing the firmware to not be initialized.
6937 nv
->firmware_options_1
&= cpu_to_le32(~BIT_15
);
6938 /* Enable target PRLI control */
6939 nv
->firmware_options_2
|= cpu_to_le32(BIT_14
);
6941 if (IS_QLA25XX(ha
)) {
6942 /* Change Loop-prefer to Pt-Pt */
6943 tmp
= ~(BIT_4
|BIT_5
|BIT_6
);
6944 nv
->firmware_options_2
&= cpu_to_le32(tmp
);
6946 nv
->firmware_options_2
|= cpu_to_le32(tmp
);
6949 if (ha
->tgt
.saved_set
) {
6950 nv
->exchange_count
= ha
->tgt
.saved_exchange_count
;
6951 nv
->firmware_options_1
=
6952 ha
->tgt
.saved_firmware_options_1
;
6953 nv
->firmware_options_2
=
6954 ha
->tgt
.saved_firmware_options_2
;
6955 nv
->firmware_options_3
=
6956 ha
->tgt
.saved_firmware_options_3
;
6961 if (ha
->base_qpair
->enable_class_2
) {
6962 if (vha
->flags
.init_done
)
6963 fc_host_supported_classes(vha
->host
) =
6964 FC_COS_CLASS2
| FC_COS_CLASS3
;
6966 nv
->firmware_options_2
|= cpu_to_le32(BIT_8
);
6968 if (vha
->flags
.init_done
)
6969 fc_host_supported_classes(vha
->host
) = FC_COS_CLASS3
;
6971 nv
->firmware_options_2
&= ~cpu_to_le32(BIT_8
);
6976 qlt_24xx_config_nvram_stage2(struct scsi_qla_host
*vha
,
6977 struct init_cb_24xx
*icb
)
6979 struct qla_hw_data
*ha
= vha
->hw
;
6981 if (!QLA_TGT_MODE_ENABLED())
6984 if (ha
->tgt
.node_name_set
) {
6985 memcpy(icb
->node_name
, ha
->tgt
.tgt_node_name
, WWN_SIZE
);
6986 icb
->firmware_options_1
|= cpu_to_le32(BIT_14
);
6991 qlt_81xx_config_nvram_stage1(struct scsi_qla_host
*vha
, struct nvram_81xx
*nv
)
6993 struct qla_hw_data
*ha
= vha
->hw
;
6996 if (!QLA_TGT_MODE_ENABLED())
6999 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
7000 if (!ha
->tgt
.saved_set
) {
7001 /* We save only once */
7002 ha
->tgt
.saved_exchange_count
= nv
->exchange_count
;
7003 ha
->tgt
.saved_firmware_options_1
=
7004 nv
->firmware_options_1
;
7005 ha
->tgt
.saved_firmware_options_2
=
7006 nv
->firmware_options_2
;
7007 ha
->tgt
.saved_firmware_options_3
=
7008 nv
->firmware_options_3
;
7009 ha
->tgt
.saved_set
= 1;
7012 if (qla_tgt_mode_enabled(vha
))
7013 nv
->exchange_count
= cpu_to_le16(0xFFFF);
7015 nv
->exchange_count
= cpu_to_le16(vha
->ql2xexchoffld
);
7017 /* Enable target mode */
7018 nv
->firmware_options_1
|= cpu_to_le32(BIT_4
);
7020 /* Disable ini mode, if requested */
7021 if (qla_tgt_mode_enabled(vha
))
7022 nv
->firmware_options_1
|= cpu_to_le32(BIT_5
);
7023 /* Disable Full Login after LIP */
7024 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
7025 /* Enable initial LIP */
7026 nv
->firmware_options_1
&= cpu_to_le32(~BIT_9
);
7028 * clear BIT 15 explicitly as we have seen at
7029 * least a couple of instances where this was set
7030 * and this was causing the firmware to not be
7033 nv
->firmware_options_1
&= cpu_to_le32(~BIT_15
);
7034 if (ql2xtgt_tape_enable
)
7035 /* Enable FC tape support */
7036 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
7038 /* Disable FC tape support */
7039 nv
->firmware_options_2
&= cpu_to_le32(~BIT_12
);
7041 /* Disable Full Login after LIP */
7042 nv
->host_p
&= cpu_to_le32(~BIT_10
);
7043 /* Enable target PRLI control */
7044 nv
->firmware_options_2
|= cpu_to_le32(BIT_14
);
7046 /* Change Loop-prefer to Pt-Pt */
7047 tmp
= ~(BIT_4
|BIT_5
|BIT_6
);
7048 nv
->firmware_options_2
&= cpu_to_le32(tmp
);
7050 nv
->firmware_options_2
|= cpu_to_le32(tmp
);
7052 if (ha
->tgt
.saved_set
) {
7053 nv
->exchange_count
= ha
->tgt
.saved_exchange_count
;
7054 nv
->firmware_options_1
=
7055 ha
->tgt
.saved_firmware_options_1
;
7056 nv
->firmware_options_2
=
7057 ha
->tgt
.saved_firmware_options_2
;
7058 nv
->firmware_options_3
=
7059 ha
->tgt
.saved_firmware_options_3
;
7064 if (ha
->base_qpair
->enable_class_2
) {
7065 if (vha
->flags
.init_done
)
7066 fc_host_supported_classes(vha
->host
) =
7067 FC_COS_CLASS2
| FC_COS_CLASS3
;
7069 nv
->firmware_options_2
|= cpu_to_le32(BIT_8
);
7071 if (vha
->flags
.init_done
)
7072 fc_host_supported_classes(vha
->host
) = FC_COS_CLASS3
;
7074 nv
->firmware_options_2
&= ~cpu_to_le32(BIT_8
);
7079 qlt_81xx_config_nvram_stage2(struct scsi_qla_host
*vha
,
7080 struct init_cb_81xx
*icb
)
7082 struct qla_hw_data
*ha
= vha
->hw
;
7084 if (!QLA_TGT_MODE_ENABLED())
7087 if (ha
->tgt
.node_name_set
) {
7088 memcpy(icb
->node_name
, ha
->tgt
.tgt_node_name
, WWN_SIZE
);
7089 icb
->firmware_options_1
|= cpu_to_le32(BIT_14
);
7094 qlt_83xx_iospace_config(struct qla_hw_data
*ha
)
7096 if (!QLA_TGT_MODE_ENABLED())
7099 ha
->msix_count
+= 1; /* For ATIO Q */
7104 qlt_modify_vp_config(struct scsi_qla_host
*vha
,
7105 struct vp_config_entry_24xx
*vpmod
)
7107 /* enable target mode. Bit5 = 1 => disable */
7108 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
7109 vpmod
->options_idx1
&= ~BIT_5
;
7111 /* Disable ini mode, if requested. bit4 = 1 => disable */
7112 if (qla_tgt_mode_enabled(vha
))
7113 vpmod
->options_idx1
&= ~BIT_4
;
7117 qlt_probe_one_stage1(struct scsi_qla_host
*base_vha
, struct qla_hw_data
*ha
)
7119 mutex_init(&base_vha
->vha_tgt
.tgt_mutex
);
7120 if (!QLA_TGT_MODE_ENABLED())
7123 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
) || IS_QLA28XX(ha
)) {
7124 ISP_ATIO_Q_IN(base_vha
) = &ha
->mqiobase
->isp25mq
.atio_q_in
;
7125 ISP_ATIO_Q_OUT(base_vha
) = &ha
->mqiobase
->isp25mq
.atio_q_out
;
7127 ISP_ATIO_Q_IN(base_vha
) = &ha
->iobase
->isp24
.atio_q_in
;
7128 ISP_ATIO_Q_OUT(base_vha
) = &ha
->iobase
->isp24
.atio_q_out
;
7131 mutex_init(&base_vha
->vha_tgt
.tgt_host_action_mutex
);
7133 INIT_LIST_HEAD(&base_vha
->unknown_atio_list
);
7134 INIT_DELAYED_WORK(&base_vha
->unknown_atio_work
,
7135 qlt_unknown_atio_work_fn
);
7137 qlt_clear_mode(base_vha
);
7139 qla_update_vp_map(base_vha
, SET_VP_IDX
);
7143 qla83xx_msix_atio_q(int irq
, void *dev_id
)
7145 struct rsp_que
*rsp
;
7146 scsi_qla_host_t
*vha
;
7147 struct qla_hw_data
*ha
;
7148 unsigned long flags
;
7150 rsp
= (struct rsp_que
*) dev_id
;
7152 vha
= pci_get_drvdata(ha
->pdev
);
7154 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags
);
7156 qlt_24xx_process_atio_queue(vha
, 0);
7158 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
, flags
);
7164 qlt_handle_abts_recv_work(struct work_struct
*work
)
7166 struct qla_tgt_sess_op
*op
= container_of(work
,
7167 struct qla_tgt_sess_op
, work
);
7168 scsi_qla_host_t
*vha
= op
->vha
;
7169 struct qla_hw_data
*ha
= vha
->hw
;
7170 unsigned long flags
;
7172 if (qla2x00_reset_active(vha
) ||
7173 (op
->chip_reset
!= ha
->base_qpair
->chip_reset
))
7176 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags
);
7177 qlt_24xx_process_atio_queue(vha
, 0);
7178 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
, flags
);
7180 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
7181 qlt_response_pkt_all_vps(vha
, op
->rsp
, (response_t
*)&op
->atio
);
7182 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
7188 qlt_handle_abts_recv(struct scsi_qla_host
*vha
, struct rsp_que
*rsp
,
7191 struct qla_tgt_sess_op
*op
;
7193 op
= kzalloc(sizeof(*op
), GFP_ATOMIC
);
7196 /* do not reach for ATIO queue here. This is best effort err
7197 * recovery at this point.
7199 qlt_response_pkt_all_vps(vha
, rsp
, pkt
);
7203 memcpy(&op
->atio
, pkt
, sizeof(*pkt
));
7205 op
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
7207 INIT_WORK(&op
->work
, qlt_handle_abts_recv_work
);
7208 queue_work(qla_tgt_wq
, &op
->work
);
7213 qlt_mem_alloc(struct qla_hw_data
*ha
)
7215 if (!QLA_TGT_MODE_ENABLED())
7218 ha
->tgt
.atio_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
7219 (ha
->tgt
.atio_q_length
+ 1) * sizeof(struct atio_from_isp
),
7220 &ha
->tgt
.atio_dma
, GFP_KERNEL
);
7221 if (!ha
->tgt
.atio_ring
) {
7228 qlt_mem_free(struct qla_hw_data
*ha
)
7230 if (!QLA_TGT_MODE_ENABLED())
7233 if (ha
->tgt
.atio_ring
) {
7234 dma_free_coherent(&ha
->pdev
->dev
, (ha
->tgt
.atio_q_length
+ 1) *
7235 sizeof(struct atio_from_isp
), ha
->tgt
.atio_ring
,
7238 ha
->tgt
.atio_ring
= NULL
;
7239 ha
->tgt
.atio_dma
= 0;
7242 static int __init
qlt_parse_ini_mode(void)
7244 if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_EXCLUSIVE
) == 0)
7245 ql2x_ini_mode
= QLA2XXX_INI_MODE_EXCLUSIVE
;
7246 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_DISABLED
) == 0)
7247 ql2x_ini_mode
= QLA2XXX_INI_MODE_DISABLED
;
7248 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_ENABLED
) == 0)
7249 ql2x_ini_mode
= QLA2XXX_INI_MODE_ENABLED
;
7250 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_DUAL
) == 0)
7251 ql2x_ini_mode
= QLA2XXX_INI_MODE_DUAL
;
7258 int __init
qlt_init(void)
7262 BUILD_BUG_ON(sizeof(struct ctio7_to_24xx
) != 64);
7263 BUILD_BUG_ON(sizeof(struct ctio_to_2xxx
) != 64);
7265 if (!qlt_parse_ini_mode()) {
7266 ql_log(ql_log_fatal
, NULL
, 0xe06b,
7267 "qlt_parse_ini_mode() failed\n");
7271 if (!QLA_TGT_MODE_ENABLED())
7274 qla_tgt_mgmt_cmd_cachep
= kmem_cache_create("qla_tgt_mgmt_cmd_cachep",
7275 sizeof(struct qla_tgt_mgmt_cmd
), __alignof__(struct
7276 qla_tgt_mgmt_cmd
), 0, NULL
);
7277 if (!qla_tgt_mgmt_cmd_cachep
) {
7278 ql_log(ql_log_fatal
, NULL
, 0xd04b,
7279 "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n");
7283 qla_tgt_plogi_cachep
= kmem_cache_create("qla_tgt_plogi_cachep",
7284 sizeof(struct qlt_plogi_ack_t
), __alignof__(struct qlt_plogi_ack_t
),
7287 if (!qla_tgt_plogi_cachep
) {
7288 ql_log(ql_log_fatal
, NULL
, 0xe06d,
7289 "kmem_cache_create for qla_tgt_plogi_cachep failed\n");
7291 goto out_mgmt_cmd_cachep
;
7294 qla_tgt_mgmt_cmd_mempool
= mempool_create(25, mempool_alloc_slab
,
7295 mempool_free_slab
, qla_tgt_mgmt_cmd_cachep
);
7296 if (!qla_tgt_mgmt_cmd_mempool
) {
7297 ql_log(ql_log_fatal
, NULL
, 0xe06e,
7298 "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n");
7300 goto out_plogi_cachep
;
7303 qla_tgt_wq
= alloc_workqueue("qla_tgt_wq", 0, 0);
7305 ql_log(ql_log_fatal
, NULL
, 0xe06f,
7306 "alloc_workqueue for qla_tgt_wq failed\n");
7308 goto out_cmd_mempool
;
7311 * Return 1 to signal that initiator-mode is being disabled
7313 return (ql2x_ini_mode
== QLA2XXX_INI_MODE_DISABLED
) ? 1 : 0;
7316 mempool_destroy(qla_tgt_mgmt_cmd_mempool
);
7318 kmem_cache_destroy(qla_tgt_plogi_cachep
);
7319 out_mgmt_cmd_cachep
:
7320 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep
);
7326 if (!QLA_TGT_MODE_ENABLED())
7329 destroy_workqueue(qla_tgt_wq
);
7330 mempool_destroy(qla_tgt_mgmt_cmd_mempool
);
7331 kmem_cache_destroy(qla_tgt_plogi_cachep
);
7332 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep
);