2 * qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx
4 * based on qla2x00t.c code:
6 * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net>
7 * Copyright (C) 2004 - 2005 Leonid Stoljar
8 * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us>
9 * Copyright (C) 2006 - 2010 ID7 Ltd.
11 * Forward port and refactoring to modern qla2xxx and target/configfs
13 * Copyright (C) 2010-2013 Nicholas A. Bellinger <nab@kernel.org>
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation, version 2
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/types.h>
29 #include <linux/blkdev.h>
30 #include <linux/interrupt.h>
31 #include <linux/pci.h>
32 #include <linux/delay.h>
33 #include <linux/list.h>
34 #include <linux/workqueue.h>
35 #include <asm/unaligned.h>
36 #include <scsi/scsi.h>
37 #include <scsi/scsi_host.h>
38 #include <scsi/scsi_tcq.h>
39 #include <target/target_core_base.h>
40 #include <target/target_core_fabric.h>
43 #include "qla_target.h"
45 static char *qlini_mode
= QLA2XXX_INI_MODE_STR_ENABLED
;
46 module_param(qlini_mode
, charp
, S_IRUGO
);
47 MODULE_PARM_DESC(qlini_mode
,
48 "Determines when initiator mode will be enabled. Possible values: "
49 "\"exclusive\" - initiator mode will be enabled on load, "
50 "disabled on enabling target mode and then on disabling target mode "
52 "\"disabled\" - initiator mode will never be enabled; "
53 "\"enabled\" (default) - initiator mode will always stay enabled.");
55 int ql2x_ini_mode
= QLA2XXX_INI_MODE_EXCLUSIVE
;
58 * From scsi/fc/fc_fcp.h
60 enum fcp_resp_rsp_codes
{
62 FCP_DATA_LEN_INVALID
= 1,
63 FCP_CMND_FIELDS_INVALID
= 2,
64 FCP_DATA_PARAM_MISMATCH
= 3,
67 FCP_TMF_INVALID_LUN
= 9,
71 * fc_pri_ta from scsi/fc/fc_fcp.h
73 #define FCP_PTA_SIMPLE 0 /* simple task attribute */
74 #define FCP_PTA_HEADQ 1 /* head of queue task attribute */
75 #define FCP_PTA_ORDERED 2 /* ordered task attribute */
76 #define FCP_PTA_ACA 4 /* auto. contingent allegiance */
77 #define FCP_PTA_MASK 7 /* mask for task attribute field */
78 #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */
79 #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */
82 * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which
83 * must be called under HW lock and could unlock/lock it inside.
84 * It isn't an issue, since in the current implementation on the time when
85 * those functions are called:
87 * - Either context is IRQ and only IRQ handler can modify HW data,
88 * including rings related fields,
90 * - Or access to target mode variables from struct qla_tgt doesn't
91 * cross those functions boundaries, except tgt_stop, which
92 * additionally protected by irq_cmd_count.
94 /* Predefs for callbacks handed to qla2xxx LLD */
95 static void qlt_24xx_atio_pkt(struct scsi_qla_host
*ha
,
96 struct atio_from_isp
*pkt
);
97 static void qlt_response_pkt(struct scsi_qla_host
*ha
, response_t
*pkt
);
98 static int qlt_issue_task_mgmt(struct qla_tgt_sess
*sess
, uint32_t lun
,
99 int fn
, void *iocb
, int flags
);
100 static void qlt_send_term_exchange(struct scsi_qla_host
*ha
, struct qla_tgt_cmd
101 *cmd
, struct atio_from_isp
*atio
, int ha_locked
);
102 static void qlt_reject_free_srr_imm(struct scsi_qla_host
*ha
,
103 struct qla_tgt_srr_imm
*imm
, int ha_lock
);
107 static struct kmem_cache
*qla_tgt_cmd_cachep
;
108 static struct kmem_cache
*qla_tgt_mgmt_cmd_cachep
;
109 static mempool_t
*qla_tgt_mgmt_cmd_mempool
;
110 static struct workqueue_struct
*qla_tgt_wq
;
111 static DEFINE_MUTEX(qla_tgt_mutex
);
112 static LIST_HEAD(qla_tgt_glist
);
114 /* ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) */
115 static struct qla_tgt_sess
*qlt_find_sess_by_port_name(
117 const uint8_t *port_name
)
119 struct qla_tgt_sess
*sess
;
121 list_for_each_entry(sess
, &tgt
->sess_list
, sess_list_entry
) {
122 if (!memcmp(sess
->port_name
, port_name
, WWN_SIZE
))
129 /* Might release hw lock, then reaquire!! */
130 static inline int qlt_issue_marker(struct scsi_qla_host
*vha
, int vha_locked
)
132 /* Send marker if required */
133 if (unlikely(vha
->marker_needed
!= 0)) {
134 int rc
= qla2x00_issue_marker(vha
, vha_locked
);
135 if (rc
!= QLA_SUCCESS
) {
136 ql_dbg(ql_dbg_tgt
, vha
, 0xe03d,
137 "qla_target(%d): issue_marker() failed\n",
146 struct scsi_qla_host
*qlt_find_host_by_d_id(struct scsi_qla_host
*vha
,
149 struct qla_hw_data
*ha
= vha
->hw
;
152 if ((vha
->d_id
.b
.area
!= d_id
[1]) || (vha
->d_id
.b
.domain
!= d_id
[0]))
155 if (vha
->d_id
.b
.al_pa
== d_id
[2])
158 BUG_ON(ha
->tgt
.tgt_vp_map
== NULL
);
159 vp_idx
= ha
->tgt
.tgt_vp_map
[d_id
[2]].idx
;
160 if (likely(test_bit(vp_idx
, ha
->vp_idx_map
)))
161 return ha
->tgt
.tgt_vp_map
[vp_idx
].vha
;
167 struct scsi_qla_host
*qlt_find_host_by_vp_idx(struct scsi_qla_host
*vha
,
170 struct qla_hw_data
*ha
= vha
->hw
;
172 if (vha
->vp_idx
== vp_idx
)
175 BUG_ON(ha
->tgt
.tgt_vp_map
== NULL
);
176 if (likely(test_bit(vp_idx
, ha
->vp_idx_map
)))
177 return ha
->tgt
.tgt_vp_map
[vp_idx
].vha
;
182 void qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host
*vha
,
183 struct atio_from_isp
*atio
)
185 switch (atio
->u
.raw
.entry_type
) {
188 struct scsi_qla_host
*host
= qlt_find_host_by_d_id(vha
,
189 atio
->u
.isp24
.fcp_hdr
.d_id
);
190 if (unlikely(NULL
== host
)) {
191 ql_dbg(ql_dbg_tgt
, vha
, 0xe03e,
192 "qla_target(%d): Received ATIO_TYPE7 "
193 "with unknown d_id %x:%x:%x\n", vha
->vp_idx
,
194 atio
->u
.isp24
.fcp_hdr
.d_id
[0],
195 atio
->u
.isp24
.fcp_hdr
.d_id
[1],
196 atio
->u
.isp24
.fcp_hdr
.d_id
[2]);
199 qlt_24xx_atio_pkt(host
, atio
);
203 case IMMED_NOTIFY_TYPE
:
205 struct scsi_qla_host
*host
= vha
;
206 struct imm_ntfy_from_isp
*entry
=
207 (struct imm_ntfy_from_isp
*)atio
;
209 if ((entry
->u
.isp24
.vp_index
!= 0xFF) &&
210 (entry
->u
.isp24
.nport_handle
!= 0xFFFF)) {
211 host
= qlt_find_host_by_vp_idx(vha
,
212 entry
->u
.isp24
.vp_index
);
213 if (unlikely(!host
)) {
214 ql_dbg(ql_dbg_tgt
, vha
, 0xe03f,
215 "qla_target(%d): Received "
216 "ATIO (IMMED_NOTIFY_TYPE) "
217 "with unknown vp_index %d\n",
218 vha
->vp_idx
, entry
->u
.isp24
.vp_index
);
222 qlt_24xx_atio_pkt(host
, atio
);
227 ql_dbg(ql_dbg_tgt
, vha
, 0xe040,
228 "qla_target(%d): Received unknown ATIO atio "
229 "type %x\n", vha
->vp_idx
, atio
->u
.raw
.entry_type
);
236 void qlt_response_pkt_all_vps(struct scsi_qla_host
*vha
, response_t
*pkt
)
238 switch (pkt
->entry_type
) {
241 struct ctio7_from_24xx
*entry
= (struct ctio7_from_24xx
*)pkt
;
242 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
244 if (unlikely(!host
)) {
245 ql_dbg(ql_dbg_tgt
, vha
, 0xe041,
246 "qla_target(%d): Response pkt (CTIO_TYPE7) "
247 "received, with unknown vp_index %d\n",
248 vha
->vp_idx
, entry
->vp_index
);
251 qlt_response_pkt(host
, pkt
);
255 case IMMED_NOTIFY_TYPE
:
257 struct scsi_qla_host
*host
= vha
;
258 struct imm_ntfy_from_isp
*entry
=
259 (struct imm_ntfy_from_isp
*)pkt
;
261 host
= qlt_find_host_by_vp_idx(vha
, entry
->u
.isp24
.vp_index
);
262 if (unlikely(!host
)) {
263 ql_dbg(ql_dbg_tgt
, vha
, 0xe042,
264 "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) "
265 "received, with unknown vp_index %d\n",
266 vha
->vp_idx
, entry
->u
.isp24
.vp_index
);
269 qlt_response_pkt(host
, pkt
);
273 case NOTIFY_ACK_TYPE
:
275 struct scsi_qla_host
*host
= vha
;
276 struct nack_to_isp
*entry
= (struct nack_to_isp
*)pkt
;
278 if (0xFF != entry
->u
.isp24
.vp_index
) {
279 host
= qlt_find_host_by_vp_idx(vha
,
280 entry
->u
.isp24
.vp_index
);
281 if (unlikely(!host
)) {
282 ql_dbg(ql_dbg_tgt
, vha
, 0xe043,
283 "qla_target(%d): Response "
284 "pkt (NOTIFY_ACK_TYPE) "
285 "received, with unknown "
286 "vp_index %d\n", vha
->vp_idx
,
287 entry
->u
.isp24
.vp_index
);
291 qlt_response_pkt(host
, pkt
);
297 struct abts_recv_from_24xx
*entry
=
298 (struct abts_recv_from_24xx
*)pkt
;
299 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
301 if (unlikely(!host
)) {
302 ql_dbg(ql_dbg_tgt
, vha
, 0xe044,
303 "qla_target(%d): Response pkt "
304 "(ABTS_RECV_24XX) received, with unknown "
305 "vp_index %d\n", vha
->vp_idx
, entry
->vp_index
);
308 qlt_response_pkt(host
, pkt
);
314 struct abts_resp_to_24xx
*entry
=
315 (struct abts_resp_to_24xx
*)pkt
;
316 struct scsi_qla_host
*host
= qlt_find_host_by_vp_idx(vha
,
318 if (unlikely(!host
)) {
319 ql_dbg(ql_dbg_tgt
, vha
, 0xe045,
320 "qla_target(%d): Response pkt "
321 "(ABTS_RECV_24XX) received, with unknown "
322 "vp_index %d\n", vha
->vp_idx
, entry
->vp_index
);
325 qlt_response_pkt(host
, pkt
);
330 qlt_response_pkt(vha
, pkt
);
336 static void qlt_free_session_done(struct work_struct
*work
)
338 struct qla_tgt_sess
*sess
= container_of(work
, struct qla_tgt_sess
,
340 struct qla_tgt
*tgt
= sess
->tgt
;
341 struct scsi_qla_host
*vha
= sess
->vha
;
342 struct qla_hw_data
*ha
= vha
->hw
;
346 * Release the target session for FC Nexus from fabric module code.
348 if (sess
->se_sess
!= NULL
)
349 ha
->tgt
.tgt_ops
->free_session(sess
);
351 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf001,
352 "Unregistration of sess %p finished\n", sess
);
356 * We need to protect against race, when tgt is freed before or
360 if (tgt
->sess_count
== 0)
361 wake_up_all(&tgt
->waitQ
);
364 /* ha->hardware_lock supposed to be held on entry */
365 void qlt_unreg_sess(struct qla_tgt_sess
*sess
)
367 struct scsi_qla_host
*vha
= sess
->vha
;
369 vha
->hw
->tgt
.tgt_ops
->clear_nacl_from_fcport_map(sess
);
371 list_del(&sess
->sess_list_entry
);
373 list_del(&sess
->del_list_entry
);
375 INIT_WORK(&sess
->free_work
, qlt_free_session_done
);
376 schedule_work(&sess
->free_work
);
378 EXPORT_SYMBOL(qlt_unreg_sess
);
380 /* ha->hardware_lock supposed to be held on entry */
381 static int qlt_reset(struct scsi_qla_host
*vha
, void *iocb
, int mcmd
)
383 struct qla_hw_data
*ha
= vha
->hw
;
384 struct qla_tgt_sess
*sess
= NULL
;
385 uint32_t unpacked_lun
, lun
= 0;
388 struct imm_ntfy_from_isp
*n
= (struct imm_ntfy_from_isp
*)iocb
;
389 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
391 loop_id
= le16_to_cpu(n
->u
.isp24
.nport_handle
);
392 if (loop_id
== 0xFFFF) {
393 #if 0 /* FIXME: Re-enable Global event handling.. */
395 atomic_inc(&ha
->tgt
.qla_tgt
->tgt_global_resets_count
);
396 qlt_clear_tgt_db(ha
->tgt
.qla_tgt
, 1);
397 if (!list_empty(&ha
->tgt
.qla_tgt
->sess_list
)) {
398 sess
= list_entry(ha
->tgt
.qla_tgt
->sess_list
.next
,
399 typeof(*sess
), sess_list_entry
);
401 case QLA_TGT_NEXUS_LOSS_SESS
:
402 mcmd
= QLA_TGT_NEXUS_LOSS
;
404 case QLA_TGT_ABORT_ALL_SESS
:
405 mcmd
= QLA_TGT_ABORT_ALL
;
407 case QLA_TGT_NEXUS_LOSS
:
408 case QLA_TGT_ABORT_ALL
:
411 ql_dbg(ql_dbg_tgt
, vha
, 0xe046,
412 "qla_target(%d): Not allowed "
413 "command %x in %s", vha
->vp_idx
,
422 sess
= ha
->tgt
.tgt_ops
->find_sess_by_loop_id(vha
, loop_id
);
425 ql_dbg(ql_dbg_tgt
, vha
, 0xe000,
426 "Using sess for qla_tgt_reset: %p\n", sess
);
432 ql_dbg(ql_dbg_tgt
, vha
, 0xe047,
433 "scsi(%ld): resetting (session %p from port %8phC mcmd %x, "
434 "loop_id %d)\n", vha
->host_no
, sess
, sess
->port_name
,
437 lun
= a
->u
.isp24
.fcp_cmnd
.lun
;
438 unpacked_lun
= scsilun_to_int((struct scsi_lun
*)&lun
);
440 return qlt_issue_task_mgmt(sess
, unpacked_lun
, mcmd
,
441 iocb
, QLA24XX_MGMT_SEND_NACK
);
444 /* ha->hardware_lock supposed to be held on entry */
445 static void qlt_schedule_sess_for_deletion(struct qla_tgt_sess
*sess
,
448 struct qla_tgt
*tgt
= sess
->tgt
;
449 uint32_t dev_loss_tmo
= tgt
->ha
->port_down_retry_count
+ 5;
454 ql_dbg(ql_dbg_tgt
, sess
->vha
, 0xe001,
455 "Scheduling sess %p for deletion\n", sess
);
456 list_add_tail(&sess
->del_list_entry
, &tgt
->del_sess_list
);
462 sess
->expires
= jiffies
+ dev_loss_tmo
* HZ
;
464 ql_dbg(ql_dbg_tgt
, sess
->vha
, 0xe048,
465 "qla_target(%d): session for port %8phC (loop ID %d) scheduled for "
466 "deletion in %u secs (expires: %lu) immed: %d\n",
467 sess
->vha
->vp_idx
, sess
->port_name
, sess
->loop_id
, dev_loss_tmo
,
468 sess
->expires
, immediate
);
471 schedule_delayed_work(&tgt
->sess_del_work
, 0);
473 schedule_delayed_work(&tgt
->sess_del_work
,
474 sess
->expires
- jiffies
);
477 /* ha->hardware_lock supposed to be held on entry */
478 static void qlt_clear_tgt_db(struct qla_tgt
*tgt
, bool local_only
)
480 struct qla_tgt_sess
*sess
;
482 list_for_each_entry(sess
, &tgt
->sess_list
, sess_list_entry
)
483 qlt_schedule_sess_for_deletion(sess
, true);
485 /* At this point tgt could be already dead */
488 static int qla24xx_get_loop_id(struct scsi_qla_host
*vha
, const uint8_t *s_id
,
491 struct qla_hw_data
*ha
= vha
->hw
;
492 dma_addr_t gid_list_dma
;
493 struct gid_list_info
*gid_list
;
498 gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, qla2x00_gid_list_size(ha
),
499 &gid_list_dma
, GFP_KERNEL
);
501 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf044,
502 "qla_target(%d): DMA Alloc failed of %u\n",
503 vha
->vp_idx
, qla2x00_gid_list_size(ha
));
507 /* Get list of logged in devices */
508 rc
= qla2x00_get_id_list(vha
, gid_list
, gid_list_dma
, &entries
);
509 if (rc
!= QLA_SUCCESS
) {
510 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf045,
511 "qla_target(%d): get_id_list() failed: %x\n",
514 goto out_free_id_list
;
517 id_iter
= (char *)gid_list
;
519 for (i
= 0; i
< entries
; i
++) {
520 struct gid_list_info
*gid
= (struct gid_list_info
*)id_iter
;
521 if ((gid
->al_pa
== s_id
[2]) &&
522 (gid
->area
== s_id
[1]) &&
523 (gid
->domain
== s_id
[0])) {
524 *loop_id
= le16_to_cpu(gid
->loop_id
);
528 id_iter
+= ha
->gid_list_info_size
;
532 dma_free_coherent(&ha
->pdev
->dev
, qla2x00_gid_list_size(ha
),
533 gid_list
, gid_list_dma
);
537 /* ha->hardware_lock supposed to be held on entry */
538 static void qlt_undelete_sess(struct qla_tgt_sess
*sess
)
540 BUG_ON(!sess
->deleted
);
542 list_del(&sess
->del_list_entry
);
546 static void qlt_del_sess_work_fn(struct delayed_work
*work
)
548 struct qla_tgt
*tgt
= container_of(work
, struct qla_tgt
,
550 struct scsi_qla_host
*vha
= tgt
->vha
;
551 struct qla_hw_data
*ha
= vha
->hw
;
552 struct qla_tgt_sess
*sess
;
553 unsigned long flags
, elapsed
;
555 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
556 while (!list_empty(&tgt
->del_sess_list
)) {
557 sess
= list_entry(tgt
->del_sess_list
.next
, typeof(*sess
),
560 if (time_after_eq(elapsed
, sess
->expires
)) {
561 qlt_undelete_sess(sess
);
563 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf004,
564 "Timeout: sess %p about to be deleted\n",
566 ha
->tgt
.tgt_ops
->shutdown_sess(sess
);
567 ha
->tgt
.tgt_ops
->put_sess(sess
);
569 schedule_delayed_work(&tgt
->sess_del_work
,
570 sess
->expires
- elapsed
);
574 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
578 * Adds an extra ref to allow to drop hw lock after adding sess to the list.
579 * Caller must put it.
581 static struct qla_tgt_sess
*qlt_create_sess(
582 struct scsi_qla_host
*vha
,
586 struct qla_hw_data
*ha
= vha
->hw
;
587 struct qla_tgt_sess
*sess
;
589 unsigned char be_sid
[3];
591 /* Check to avoid double sessions */
592 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
593 list_for_each_entry(sess
, &vha
->vha_tgt
.qla_tgt
->sess_list
,
595 if (!memcmp(sess
->port_name
, fcport
->port_name
, WWN_SIZE
)) {
596 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf005,
597 "Double sess %p found (s_id %x:%x:%x, "
598 "loop_id %d), updating to d_id %x:%x:%x, "
599 "loop_id %d", sess
, sess
->s_id
.b
.domain
,
600 sess
->s_id
.b
.al_pa
, sess
->s_id
.b
.area
,
601 sess
->loop_id
, fcport
->d_id
.b
.domain
,
602 fcport
->d_id
.b
.al_pa
, fcport
->d_id
.b
.area
,
606 qlt_undelete_sess(sess
);
608 kref_get(&sess
->se_sess
->sess_kref
);
609 ha
->tgt
.tgt_ops
->update_sess(sess
, fcport
->d_id
, fcport
->loop_id
,
610 (fcport
->flags
& FCF_CONF_COMP_SUPPORTED
));
612 if (sess
->local
&& !local
)
614 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
619 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
621 sess
= kzalloc(sizeof(*sess
), GFP_KERNEL
);
623 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04a,
624 "qla_target(%u): session allocation failed, all commands "
625 "from port %8phC will be refused", vha
->vp_idx
,
630 sess
->tgt
= vha
->vha_tgt
.qla_tgt
;
632 sess
->s_id
= fcport
->d_id
;
633 sess
->loop_id
= fcport
->loop_id
;
636 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf006,
637 "Adding sess %p to tgt %p via ->check_initiator_node_acl()\n",
638 sess
, vha
->vha_tgt
.qla_tgt
);
640 be_sid
[0] = sess
->s_id
.b
.domain
;
641 be_sid
[1] = sess
->s_id
.b
.area
;
642 be_sid
[2] = sess
->s_id
.b
.al_pa
;
644 * Determine if this fc_port->port_name is allowed to access
645 * target mode using explict NodeACLs+MappedLUNs, or using
646 * TPG demo mode. If this is successful a target mode FC nexus
649 if (ha
->tgt
.tgt_ops
->check_initiator_node_acl(vha
,
650 &fcport
->port_name
[0], sess
, &be_sid
[0], fcport
->loop_id
) < 0) {
655 * Take an extra reference to ->sess_kref here to handle qla_tgt_sess
656 * access across ->hardware_lock reaquire.
658 kref_get(&sess
->se_sess
->sess_kref
);
660 sess
->conf_compl_supported
= (fcport
->flags
& FCF_CONF_COMP_SUPPORTED
);
661 BUILD_BUG_ON(sizeof(sess
->port_name
) != sizeof(fcport
->port_name
));
662 memcpy(sess
->port_name
, fcport
->port_name
, sizeof(sess
->port_name
));
664 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
665 list_add_tail(&sess
->sess_list_entry
, &vha
->vha_tgt
.qla_tgt
->sess_list
);
666 vha
->vha_tgt
.qla_tgt
->sess_count
++;
667 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
669 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04b,
670 "qla_target(%d): %ssession for wwn %8phC (loop_id %d, "
671 "s_id %x:%x:%x, confirmed completion %ssupported) added\n",
672 vha
->vp_idx
, local
? "local " : "", fcport
->port_name
,
673 fcport
->loop_id
, sess
->s_id
.b
.domain
, sess
->s_id
.b
.area
,
674 sess
->s_id
.b
.al_pa
, sess
->conf_compl_supported
? "" : "not ");
680 * Called from drivers/scsi/qla2xxx/qla_init.c:qla2x00_reg_remote_port()
682 void qlt_fc_port_added(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
684 struct qla_hw_data
*ha
= vha
->hw
;
685 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
686 struct qla_tgt_sess
*sess
;
689 if (!vha
->hw
->tgt
.tgt_ops
)
692 if (!tgt
|| (fcport
->port_type
!= FCT_INITIATOR
))
695 if (qla_ini_mode_enabled(vha
))
698 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
700 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
703 sess
= qlt_find_sess_by_port_name(tgt
, fcport
->port_name
);
705 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
707 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
708 sess
= qlt_create_sess(vha
, fcport
, false);
709 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
711 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
713 kref_get(&sess
->se_sess
->sess_kref
);
716 qlt_undelete_sess(sess
);
718 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04c,
719 "qla_target(%u): %ssession for port %8phC "
720 "(loop ID %d) reappeared\n", vha
->vp_idx
,
721 sess
->local
? "local " : "", sess
->port_name
,
724 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf007,
725 "Reappeared sess %p\n", sess
);
727 ha
->tgt
.tgt_ops
->update_sess(sess
, fcport
->d_id
, fcport
->loop_id
,
728 (fcport
->flags
& FCF_CONF_COMP_SUPPORTED
));
731 if (sess
&& sess
->local
) {
732 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04d,
733 "qla_target(%u): local session for "
734 "port %8phC (loop ID %d) became global\n", vha
->vp_idx
,
735 fcport
->port_name
, sess
->loop_id
);
738 ha
->tgt
.tgt_ops
->put_sess(sess
);
739 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
742 void qlt_fc_port_deleted(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
744 struct qla_hw_data
*ha
= vha
->hw
;
745 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
746 struct qla_tgt_sess
*sess
;
749 if (!vha
->hw
->tgt
.tgt_ops
)
752 if (!tgt
|| (fcport
->port_type
!= FCT_INITIATOR
))
755 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
757 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
760 sess
= qlt_find_sess_by_port_name(tgt
, fcport
->port_name
);
762 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
766 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf008, "qla_tgt_fc_port_deleted %p", sess
);
769 qlt_schedule_sess_for_deletion(sess
, false);
770 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
773 static inline int test_tgt_sess_count(struct qla_tgt
*tgt
)
775 struct qla_hw_data
*ha
= tgt
->ha
;
779 * We need to protect against race, when tgt is freed before or
782 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
783 ql_dbg(ql_dbg_tgt
, tgt
->vha
, 0xe002,
784 "tgt %p, empty(sess_list)=%d sess_count=%d\n",
785 tgt
, list_empty(&tgt
->sess_list
), tgt
->sess_count
);
786 res
= (tgt
->sess_count
== 0);
787 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
792 /* Called by tcm_qla2xxx configfs code */
793 void qlt_stop_phase1(struct qla_tgt
*tgt
)
795 struct scsi_qla_host
*vha
= tgt
->vha
;
796 struct qla_hw_data
*ha
= tgt
->ha
;
799 if (tgt
->tgt_stop
|| tgt
->tgt_stopped
) {
800 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04e,
801 "Already in tgt->tgt_stop or tgt_stopped state\n");
806 ql_dbg(ql_dbg_tgt
, vha
, 0xe003, "Stopping target for host %ld(%p)\n",
809 * Mutex needed to sync with qla_tgt_fc_port_[added,deleted].
810 * Lock is needed, because we still can get an incoming packet.
812 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
813 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
815 qlt_clear_tgt_db(tgt
, true);
816 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
817 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
819 flush_delayed_work(&tgt
->sess_del_work
);
821 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf009,
822 "Waiting for sess works (tgt %p)", tgt
);
823 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
824 while (!list_empty(&tgt
->sess_works_list
)) {
825 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
826 flush_scheduled_work();
827 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
829 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
831 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00a,
832 "Waiting for tgt %p: list_empty(sess_list)=%d "
833 "sess_count=%d\n", tgt
, list_empty(&tgt
->sess_list
),
836 wait_event(tgt
->waitQ
, test_tgt_sess_count(tgt
));
839 if (!ha
->flags
.host_shutting_down
&& qla_tgt_mode_enabled(vha
))
840 qlt_disable_vha(vha
);
842 /* Wait for sessions to clear out (just in case) */
843 wait_event(tgt
->waitQ
, test_tgt_sess_count(tgt
));
845 EXPORT_SYMBOL(qlt_stop_phase1
);
847 /* Called by tcm_qla2xxx configfs code */
848 void qlt_stop_phase2(struct qla_tgt
*tgt
)
850 struct qla_hw_data
*ha
= tgt
->ha
;
851 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
854 if (tgt
->tgt_stopped
) {
855 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf04f,
856 "Already in tgt->tgt_stopped state\n");
861 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00b,
862 "Waiting for %d IRQ commands to complete (tgt %p)",
863 tgt
->irq_cmd_count
, tgt
);
865 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
866 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
867 while (tgt
->irq_cmd_count
!= 0) {
868 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
870 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
873 tgt
->tgt_stopped
= 1;
874 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
875 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
877 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00c, "Stop of tgt %p finished",
880 EXPORT_SYMBOL(qlt_stop_phase2
);
882 /* Called from qlt_remove_target() -> qla2x00_remove_one() */
883 static void qlt_release(struct qla_tgt
*tgt
)
885 scsi_qla_host_t
*vha
= tgt
->vha
;
887 if ((vha
->vha_tgt
.qla_tgt
!= NULL
) && !tgt
->tgt_stopped
)
888 qlt_stop_phase2(tgt
);
890 vha
->vha_tgt
.qla_tgt
= NULL
;
892 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00d,
893 "Release of tgt %p finished\n", tgt
);
898 /* ha->hardware_lock supposed to be held on entry */
899 static int qlt_sched_sess_work(struct qla_tgt
*tgt
, int type
,
900 const void *param
, unsigned int param_size
)
902 struct qla_tgt_sess_work_param
*prm
;
905 prm
= kzalloc(sizeof(*prm
), GFP_ATOMIC
);
907 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf050,
908 "qla_target(%d): Unable to create session "
909 "work, command will be refused", 0);
913 ql_dbg(ql_dbg_tgt_mgt
, tgt
->vha
, 0xf00e,
914 "Scheduling work (type %d, prm %p)"
915 " to find session for param %p (size %d, tgt %p)\n",
916 type
, prm
, param
, param_size
, tgt
);
919 memcpy(&prm
->tm_iocb
, param
, param_size
);
921 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
922 list_add_tail(&prm
->sess_works_list_entry
, &tgt
->sess_works_list
);
923 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
925 schedule_work(&tgt
->sess_work
);
931 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
933 static void qlt_send_notify_ack(struct scsi_qla_host
*vha
,
934 struct imm_ntfy_from_isp
*ntfy
,
935 uint32_t add_flags
, uint16_t resp_code
, int resp_code_valid
,
936 uint16_t srr_flags
, uint16_t srr_reject_code
, uint8_t srr_explan
)
938 struct qla_hw_data
*ha
= vha
->hw
;
940 struct nack_to_isp
*nack
;
942 ql_dbg(ql_dbg_tgt
, vha
, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha
);
944 /* Send marker if required */
945 if (qlt_issue_marker(vha
, 1) != QLA_SUCCESS
)
948 pkt
= (request_t
*)qla2x00_alloc_iocbs(vha
, NULL
);
950 ql_dbg(ql_dbg_tgt
, vha
, 0xe049,
951 "qla_target(%d): %s failed: unable to allocate "
952 "request packet\n", vha
->vp_idx
, __func__
);
956 if (vha
->vha_tgt
.qla_tgt
!= NULL
)
957 vha
->vha_tgt
.qla_tgt
->notify_ack_expected
++;
959 pkt
->entry_type
= NOTIFY_ACK_TYPE
;
960 pkt
->entry_count
= 1;
962 nack
= (struct nack_to_isp
*)pkt
;
963 nack
->ox_id
= ntfy
->ox_id
;
965 nack
->u
.isp24
.nport_handle
= ntfy
->u
.isp24
.nport_handle
;
966 if (le16_to_cpu(ntfy
->u
.isp24
.status
) == IMM_NTFY_ELS
) {
967 nack
->u
.isp24
.flags
= ntfy
->u
.isp24
.flags
&
968 __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB
);
970 nack
->u
.isp24
.srr_rx_id
= ntfy
->u
.isp24
.srr_rx_id
;
971 nack
->u
.isp24
.status
= ntfy
->u
.isp24
.status
;
972 nack
->u
.isp24
.status_subcode
= ntfy
->u
.isp24
.status_subcode
;
973 nack
->u
.isp24
.fw_handle
= ntfy
->u
.isp24
.fw_handle
;
974 nack
->u
.isp24
.exchange_address
= ntfy
->u
.isp24
.exchange_address
;
975 nack
->u
.isp24
.srr_rel_offs
= ntfy
->u
.isp24
.srr_rel_offs
;
976 nack
->u
.isp24
.srr_ui
= ntfy
->u
.isp24
.srr_ui
;
977 nack
->u
.isp24
.srr_flags
= cpu_to_le16(srr_flags
);
978 nack
->u
.isp24
.srr_reject_code
= srr_reject_code
;
979 nack
->u
.isp24
.srr_reject_code_expl
= srr_explan
;
980 nack
->u
.isp24
.vp_index
= ntfy
->u
.isp24
.vp_index
;
982 ql_dbg(ql_dbg_tgt
, vha
, 0xe005,
983 "qla_target(%d): Sending 24xx Notify Ack %d\n",
984 vha
->vp_idx
, nack
->u
.isp24
.status
);
986 qla2x00_start_iocbs(vha
, vha
->req
);
990 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
992 static void qlt_24xx_send_abts_resp(struct scsi_qla_host
*vha
,
993 struct abts_recv_from_24xx
*abts
, uint32_t status
,
996 struct qla_hw_data
*ha
= vha
->hw
;
997 struct abts_resp_to_24xx
*resp
;
1001 ql_dbg(ql_dbg_tgt
, vha
, 0xe006,
1002 "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n",
1005 /* Send marker if required */
1006 if (qlt_issue_marker(vha
, 1) != QLA_SUCCESS
)
1009 resp
= (struct abts_resp_to_24xx
*)qla2x00_alloc_iocbs(vha
, NULL
);
1011 ql_dbg(ql_dbg_tgt
, vha
, 0xe04a,
1012 "qla_target(%d): %s failed: unable to allocate "
1013 "request packet", vha
->vp_idx
, __func__
);
1017 resp
->entry_type
= ABTS_RESP_24XX
;
1018 resp
->entry_count
= 1;
1019 resp
->nport_handle
= abts
->nport_handle
;
1020 resp
->vp_index
= vha
->vp_idx
;
1021 resp
->sof_type
= abts
->sof_type
;
1022 resp
->exchange_address
= abts
->exchange_address
;
1023 resp
->fcp_hdr_le
= abts
->fcp_hdr_le
;
1024 f_ctl
= __constant_cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP
|
1025 F_CTL_LAST_SEQ
| F_CTL_END_SEQ
|
1026 F_CTL_SEQ_INITIATIVE
);
1027 p
= (uint8_t *)&f_ctl
;
1028 resp
->fcp_hdr_le
.f_ctl
[0] = *p
++;
1029 resp
->fcp_hdr_le
.f_ctl
[1] = *p
++;
1030 resp
->fcp_hdr_le
.f_ctl
[2] = *p
;
1032 resp
->fcp_hdr_le
.d_id
[0] = abts
->fcp_hdr_le
.d_id
[0];
1033 resp
->fcp_hdr_le
.d_id
[1] = abts
->fcp_hdr_le
.d_id
[1];
1034 resp
->fcp_hdr_le
.d_id
[2] = abts
->fcp_hdr_le
.d_id
[2];
1035 resp
->fcp_hdr_le
.s_id
[0] = abts
->fcp_hdr_le
.s_id
[0];
1036 resp
->fcp_hdr_le
.s_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1037 resp
->fcp_hdr_le
.s_id
[2] = abts
->fcp_hdr_le
.s_id
[2];
1039 resp
->fcp_hdr_le
.d_id
[0] = abts
->fcp_hdr_le
.s_id
[0];
1040 resp
->fcp_hdr_le
.d_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1041 resp
->fcp_hdr_le
.d_id
[2] = abts
->fcp_hdr_le
.s_id
[2];
1042 resp
->fcp_hdr_le
.s_id
[0] = abts
->fcp_hdr_le
.d_id
[0];
1043 resp
->fcp_hdr_le
.s_id
[1] = abts
->fcp_hdr_le
.d_id
[1];
1044 resp
->fcp_hdr_le
.s_id
[2] = abts
->fcp_hdr_le
.d_id
[2];
1046 resp
->exchange_addr_to_abort
= abts
->exchange_addr_to_abort
;
1047 if (status
== FCP_TMF_CMPL
) {
1048 resp
->fcp_hdr_le
.r_ctl
= R_CTL_BASIC_LINK_SERV
| R_CTL_B_ACC
;
1049 resp
->payload
.ba_acct
.seq_id_valid
= SEQ_ID_INVALID
;
1050 resp
->payload
.ba_acct
.low_seq_cnt
= 0x0000;
1051 resp
->payload
.ba_acct
.high_seq_cnt
= 0xFFFF;
1052 resp
->payload
.ba_acct
.ox_id
= abts
->fcp_hdr_le
.ox_id
;
1053 resp
->payload
.ba_acct
.rx_id
= abts
->fcp_hdr_le
.rx_id
;
1055 resp
->fcp_hdr_le
.r_ctl
= R_CTL_BASIC_LINK_SERV
| R_CTL_B_RJT
;
1056 resp
->payload
.ba_rjt
.reason_code
=
1057 BA_RJT_REASON_CODE_UNABLE_TO_PERFORM
;
1058 /* Other bytes are zero */
1061 vha
->vha_tgt
.qla_tgt
->abts_resp_expected
++;
1063 qla2x00_start_iocbs(vha
, vha
->req
);
1067 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1069 static void qlt_24xx_retry_term_exchange(struct scsi_qla_host
*vha
,
1070 struct abts_resp_from_24xx_fw
*entry
)
1072 struct ctio7_to_24xx
*ctio
;
1074 ql_dbg(ql_dbg_tgt
, vha
, 0xe007,
1075 "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha
->hw
);
1076 /* Send marker if required */
1077 if (qlt_issue_marker(vha
, 1) != QLA_SUCCESS
)
1080 ctio
= (struct ctio7_to_24xx
*)qla2x00_alloc_iocbs(vha
, NULL
);
1082 ql_dbg(ql_dbg_tgt
, vha
, 0xe04b,
1083 "qla_target(%d): %s failed: unable to allocate "
1084 "request packet\n", vha
->vp_idx
, __func__
);
1089 * We've got on entrance firmware's response on by us generated
1090 * ABTS response. So, in it ID fields are reversed.
1093 ctio
->entry_type
= CTIO_TYPE7
;
1094 ctio
->entry_count
= 1;
1095 ctio
->nport_handle
= entry
->nport_handle
;
1096 ctio
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
1097 ctio
->timeout
= __constant_cpu_to_le16(QLA_TGT_TIMEOUT
);
1098 ctio
->vp_index
= vha
->vp_idx
;
1099 ctio
->initiator_id
[0] = entry
->fcp_hdr_le
.d_id
[0];
1100 ctio
->initiator_id
[1] = entry
->fcp_hdr_le
.d_id
[1];
1101 ctio
->initiator_id
[2] = entry
->fcp_hdr_le
.d_id
[2];
1102 ctio
->exchange_addr
= entry
->exchange_addr_to_abort
;
1103 ctio
->u
.status1
.flags
=
1104 __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
|
1105 CTIO7_FLAGS_TERMINATE
);
1106 ctio
->u
.status1
.ox_id
= entry
->fcp_hdr_le
.ox_id
;
1108 qla2x00_start_iocbs(vha
, vha
->req
);
1110 qlt_24xx_send_abts_resp(vha
, (struct abts_recv_from_24xx
*)entry
,
1111 FCP_TMF_CMPL
, true);
1114 /* ha->hardware_lock supposed to be held on entry */
1115 static int __qlt_24xx_handle_abts(struct scsi_qla_host
*vha
,
1116 struct abts_recv_from_24xx
*abts
, struct qla_tgt_sess
*sess
)
1118 struct qla_hw_data
*ha
= vha
->hw
;
1119 struct se_session
*se_sess
= sess
->se_sess
;
1120 struct qla_tgt_mgmt_cmd
*mcmd
;
1121 struct se_cmd
*se_cmd
;
1124 bool found_lun
= false;
1126 spin_lock(&se_sess
->sess_cmd_lock
);
1127 list_for_each_entry(se_cmd
, &se_sess
->sess_cmd_list
, se_cmd_list
) {
1128 struct qla_tgt_cmd
*cmd
=
1129 container_of(se_cmd
, struct qla_tgt_cmd
, se_cmd
);
1130 if (cmd
->tag
== abts
->exchange_addr_to_abort
) {
1131 lun
= cmd
->unpacked_lun
;
1136 spin_unlock(&se_sess
->sess_cmd_lock
);
1141 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf00f,
1142 "qla_target(%d): task abort (tag=%d)\n",
1143 vha
->vp_idx
, abts
->exchange_addr_to_abort
);
1145 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
1147 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf051,
1148 "qla_target(%d): %s: Allocation of ABORT cmd failed",
1149 vha
->vp_idx
, __func__
);
1152 memset(mcmd
, 0, sizeof(*mcmd
));
1155 memcpy(&mcmd
->orig_iocb
.abts
, abts
, sizeof(mcmd
->orig_iocb
.abts
));
1157 rc
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, lun
, TMR_ABORT_TASK
,
1158 abts
->exchange_addr_to_abort
);
1160 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf052,
1161 "qla_target(%d): tgt_ops->handle_tmr()"
1162 " failed: %d", vha
->vp_idx
, rc
);
1163 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
1171 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1173 static void qlt_24xx_handle_abts(struct scsi_qla_host
*vha
,
1174 struct abts_recv_from_24xx
*abts
)
1176 struct qla_hw_data
*ha
= vha
->hw
;
1177 struct qla_tgt_sess
*sess
;
1178 uint32_t tag
= abts
->exchange_addr_to_abort
;
1182 if (le32_to_cpu(abts
->fcp_hdr_le
.parameter
) & ABTS_PARAM_ABORT_SEQ
) {
1183 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf053,
1184 "qla_target(%d): ABTS: Abort Sequence not "
1185 "supported\n", vha
->vp_idx
);
1186 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
, false);
1190 if (tag
== ATIO_EXCHANGE_ADDRESS_UNKNOWN
) {
1191 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf010,
1192 "qla_target(%d): ABTS: Unknown Exchange "
1193 "Address received\n", vha
->vp_idx
);
1194 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
, false);
1198 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf011,
1199 "qla_target(%d): task abort (s_id=%x:%x:%x, "
1200 "tag=%d, param=%x)\n", vha
->vp_idx
, abts
->fcp_hdr_le
.s_id
[2],
1201 abts
->fcp_hdr_le
.s_id
[1], abts
->fcp_hdr_le
.s_id
[0], tag
,
1202 le32_to_cpu(abts
->fcp_hdr_le
.parameter
));
1204 s_id
[0] = abts
->fcp_hdr_le
.s_id
[2];
1205 s_id
[1] = abts
->fcp_hdr_le
.s_id
[1];
1206 s_id
[2] = abts
->fcp_hdr_le
.s_id
[0];
1208 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, s_id
);
1210 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf012,
1211 "qla_target(%d): task abort for non-existant session\n",
1213 rc
= qlt_sched_sess_work(vha
->vha_tgt
.qla_tgt
,
1214 QLA_TGT_SESS_WORK_ABORT
, abts
, sizeof(*abts
));
1216 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
,
1222 rc
= __qlt_24xx_handle_abts(vha
, abts
, sess
);
1224 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf054,
1225 "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n",
1227 qlt_24xx_send_abts_resp(vha
, abts
, FCP_TMF_REJECTED
, false);
1233 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1235 static void qlt_24xx_send_task_mgmt_ctio(struct scsi_qla_host
*ha
,
1236 struct qla_tgt_mgmt_cmd
*mcmd
, uint32_t resp_code
)
1238 struct atio_from_isp
*atio
= &mcmd
->orig_iocb
.atio
;
1239 struct ctio7_to_24xx
*ctio
;
1241 ql_dbg(ql_dbg_tgt
, ha
, 0xe008,
1242 "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n",
1243 ha
, atio
, resp_code
);
1245 /* Send marker if required */
1246 if (qlt_issue_marker(ha
, 1) != QLA_SUCCESS
)
1249 ctio
= (struct ctio7_to_24xx
*)qla2x00_alloc_iocbs(ha
, NULL
);
1251 ql_dbg(ql_dbg_tgt
, ha
, 0xe04c,
1252 "qla_target(%d): %s failed: unable to allocate "
1253 "request packet\n", ha
->vp_idx
, __func__
);
1257 ctio
->entry_type
= CTIO_TYPE7
;
1258 ctio
->entry_count
= 1;
1259 ctio
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
1260 ctio
->nport_handle
= mcmd
->sess
->loop_id
;
1261 ctio
->timeout
= __constant_cpu_to_le16(QLA_TGT_TIMEOUT
);
1262 ctio
->vp_index
= ha
->vp_idx
;
1263 ctio
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
1264 ctio
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
1265 ctio
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
1266 ctio
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
1267 ctio
->u
.status1
.flags
= (atio
->u
.isp24
.attr
<< 9) |
1268 __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
|
1269 CTIO7_FLAGS_SEND_STATUS
);
1270 ctio
->u
.status1
.ox_id
= swab16(atio
->u
.isp24
.fcp_hdr
.ox_id
);
1271 ctio
->u
.status1
.scsi_status
=
1272 __constant_cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID
);
1273 ctio
->u
.status1
.response_len
= __constant_cpu_to_le16(8);
1274 ctio
->u
.status1
.sense_data
[0] = resp_code
;
1276 qla2x00_start_iocbs(ha
, ha
->req
);
1279 void qlt_free_mcmd(struct qla_tgt_mgmt_cmd
*mcmd
)
1281 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
1283 EXPORT_SYMBOL(qlt_free_mcmd
);
1285 /* callback from target fabric module code */
1286 void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd
*mcmd
)
1288 struct scsi_qla_host
*vha
= mcmd
->sess
->vha
;
1289 struct qla_hw_data
*ha
= vha
->hw
;
1290 unsigned long flags
;
1292 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf013,
1293 "TM response mcmd (%p) status %#x state %#x",
1294 mcmd
, mcmd
->fc_tm_rsp
, mcmd
->flags
);
1296 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1297 if (mcmd
->flags
== QLA24XX_MGMT_SEND_NACK
)
1298 qlt_send_notify_ack(vha
, &mcmd
->orig_iocb
.imm_ntfy
,
1301 if (mcmd
->se_cmd
.se_tmr_req
->function
== TMR_ABORT_TASK
)
1302 qlt_24xx_send_abts_resp(vha
, &mcmd
->orig_iocb
.abts
,
1303 mcmd
->fc_tm_rsp
, false);
1305 qlt_24xx_send_task_mgmt_ctio(vha
, mcmd
,
1309 * Make the callback for ->free_mcmd() to queue_work() and invoke
1310 * target_put_sess_cmd() to drop cmd_kref to 1. The final
1311 * target_put_sess_cmd() call will be made from TFO->check_stop_free()
1312 * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd
1313 * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() ->
1314 * qlt_xmit_tm_rsp() returns here..
1316 ha
->tgt
.tgt_ops
->free_mcmd(mcmd
);
1317 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1319 EXPORT_SYMBOL(qlt_xmit_tm_rsp
);
1322 static int qlt_pci_map_calc_cnt(struct qla_tgt_prm
*prm
)
1324 struct qla_tgt_cmd
*cmd
= prm
->cmd
;
1326 BUG_ON(cmd
->sg_cnt
== 0);
1328 prm
->sg
= (struct scatterlist
*)cmd
->sg
;
1329 prm
->seg_cnt
= pci_map_sg(prm
->tgt
->ha
->pdev
, cmd
->sg
,
1330 cmd
->sg_cnt
, cmd
->dma_data_direction
);
1331 if (unlikely(prm
->seg_cnt
== 0))
1334 prm
->cmd
->sg_mapped
= 1;
1337 * If greater than four sg entries then we need to allocate
1338 * the continuation entries
1340 if (prm
->seg_cnt
> prm
->tgt
->datasegs_per_cmd
)
1341 prm
->req_cnt
+= DIV_ROUND_UP(prm
->seg_cnt
-
1342 prm
->tgt
->datasegs_per_cmd
, prm
->tgt
->datasegs_per_cont
);
1344 ql_dbg(ql_dbg_tgt
, prm
->cmd
->vha
, 0xe009, "seg_cnt=%d, req_cnt=%d\n",
1345 prm
->seg_cnt
, prm
->req_cnt
);
1349 ql_dbg(ql_dbg_tgt
, prm
->cmd
->vha
, 0xe04d,
1350 "qla_target(%d): PCI mapping failed: sg_cnt=%d",
1351 0, prm
->cmd
->sg_cnt
);
1355 static inline void qlt_unmap_sg(struct scsi_qla_host
*vha
,
1356 struct qla_tgt_cmd
*cmd
)
1358 struct qla_hw_data
*ha
= vha
->hw
;
1360 BUG_ON(!cmd
->sg_mapped
);
1361 pci_unmap_sg(ha
->pdev
, cmd
->sg
, cmd
->sg_cnt
, cmd
->dma_data_direction
);
1365 static int qlt_check_reserve_free_req(struct scsi_qla_host
*vha
,
1368 struct qla_hw_data
*ha
= vha
->hw
;
1369 device_reg_t __iomem
*reg
= ha
->iobase
;
1372 if (vha
->req
->cnt
< (req_cnt
+ 2)) {
1373 cnt
= (uint16_t)RD_REG_DWORD(®
->isp24
.req_q_out
);
1375 ql_dbg(ql_dbg_tgt
, vha
, 0xe00a,
1376 "Request ring circled: cnt=%d, vha->->ring_index=%d, "
1377 "vha->req->cnt=%d, req_cnt=%d\n", cnt
,
1378 vha
->req
->ring_index
, vha
->req
->cnt
, req_cnt
);
1379 if (vha
->req
->ring_index
< cnt
)
1380 vha
->req
->cnt
= cnt
- vha
->req
->ring_index
;
1382 vha
->req
->cnt
= vha
->req
->length
-
1383 (vha
->req
->ring_index
- cnt
);
1386 if (unlikely(vha
->req
->cnt
< (req_cnt
+ 2))) {
1387 ql_dbg(ql_dbg_tgt
, vha
, 0xe00b,
1388 "qla_target(%d): There is no room in the "
1389 "request ring: vha->req->ring_index=%d, vha->req->cnt=%d, "
1390 "req_cnt=%d\n", vha
->vp_idx
, vha
->req
->ring_index
,
1391 vha
->req
->cnt
, req_cnt
);
1394 vha
->req
->cnt
-= req_cnt
;
1400 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
1402 static inline void *qlt_get_req_pkt(struct scsi_qla_host
*vha
)
1404 /* Adjust ring index. */
1405 vha
->req
->ring_index
++;
1406 if (vha
->req
->ring_index
== vha
->req
->length
) {
1407 vha
->req
->ring_index
= 0;
1408 vha
->req
->ring_ptr
= vha
->req
->ring
;
1410 vha
->req
->ring_ptr
++;
1412 return (cont_entry_t
*)vha
->req
->ring_ptr
;
1415 /* ha->hardware_lock supposed to be held on entry */
1416 static inline uint32_t qlt_make_handle(struct scsi_qla_host
*vha
)
1418 struct qla_hw_data
*ha
= vha
->hw
;
1421 h
= ha
->tgt
.current_handle
;
1422 /* always increment cmd handle */
1425 if (h
> DEFAULT_OUTSTANDING_COMMANDS
)
1426 h
= 1; /* 0 is QLA_TGT_NULL_HANDLE */
1427 if (h
== ha
->tgt
.current_handle
) {
1428 ql_dbg(ql_dbg_tgt
, vha
, 0xe04e,
1429 "qla_target(%d): Ran out of "
1430 "empty cmd slots in ha %p\n", vha
->vp_idx
, ha
);
1431 h
= QLA_TGT_NULL_HANDLE
;
1434 } while ((h
== QLA_TGT_NULL_HANDLE
) ||
1435 (h
== QLA_TGT_SKIP_HANDLE
) ||
1436 (ha
->tgt
.cmds
[h
-1] != NULL
));
1438 if (h
!= QLA_TGT_NULL_HANDLE
)
1439 ha
->tgt
.current_handle
= h
;
1444 /* ha->hardware_lock supposed to be held on entry */
1445 static int qlt_24xx_build_ctio_pkt(struct qla_tgt_prm
*prm
,
1446 struct scsi_qla_host
*vha
)
1449 struct ctio7_to_24xx
*pkt
;
1450 struct qla_hw_data
*ha
= vha
->hw
;
1451 struct atio_from_isp
*atio
= &prm
->cmd
->atio
;
1453 pkt
= (struct ctio7_to_24xx
*)vha
->req
->ring_ptr
;
1455 memset(pkt
, 0, sizeof(*pkt
));
1457 pkt
->entry_type
= CTIO_TYPE7
;
1458 pkt
->entry_count
= (uint8_t)prm
->req_cnt
;
1459 pkt
->vp_index
= vha
->vp_idx
;
1461 h
= qlt_make_handle(vha
);
1462 if (unlikely(h
== QLA_TGT_NULL_HANDLE
)) {
1464 * CTIO type 7 from the firmware doesn't provide a way to
1465 * know the initiator's LOOP ID, hence we can't find
1466 * the session and, so, the command.
1470 ha
->tgt
.cmds
[h
-1] = prm
->cmd
;
1472 pkt
->handle
= h
| CTIO_COMPLETION_HANDLE_MARK
;
1473 pkt
->nport_handle
= prm
->cmd
->loop_id
;
1474 pkt
->timeout
= __constant_cpu_to_le16(QLA_TGT_TIMEOUT
);
1475 pkt
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
1476 pkt
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
1477 pkt
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
1478 pkt
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
1479 pkt
->u
.status0
.flags
|= (atio
->u
.isp24
.attr
<< 9);
1480 pkt
->u
.status0
.ox_id
= swab16(atio
->u
.isp24
.fcp_hdr
.ox_id
);
1481 pkt
->u
.status0
.relative_offset
= cpu_to_le32(prm
->cmd
->offset
);
1483 ql_dbg(ql_dbg_tgt
, vha
, 0xe00c,
1484 "qla_target(%d): handle(cmd) -> %08x, timeout %d, ox_id %#x\n",
1485 vha
->vp_idx
, pkt
->handle
, QLA_TGT_TIMEOUT
,
1486 le16_to_cpu(pkt
->u
.status0
.ox_id
));
1491 * ha->hardware_lock supposed to be held on entry. We have already made sure
1492 * that there is sufficient amount of request entries to not drop it.
1494 static void qlt_load_cont_data_segments(struct qla_tgt_prm
*prm
,
1495 struct scsi_qla_host
*vha
)
1498 uint32_t *dword_ptr
;
1499 int enable_64bit_addressing
= prm
->tgt
->tgt_enable_64bit_addr
;
1501 /* Build continuation packets */
1502 while (prm
->seg_cnt
> 0) {
1503 cont_a64_entry_t
*cont_pkt64
=
1504 (cont_a64_entry_t
*)qlt_get_req_pkt(vha
);
1507 * Make sure that from cont_pkt64 none of
1508 * 64-bit specific fields used for 32-bit
1509 * addressing. Cast to (cont_entry_t *) for
1513 memset(cont_pkt64
, 0, sizeof(*cont_pkt64
));
1515 cont_pkt64
->entry_count
= 1;
1516 cont_pkt64
->sys_define
= 0;
1518 if (enable_64bit_addressing
) {
1519 cont_pkt64
->entry_type
= CONTINUE_A64_TYPE
;
1521 (uint32_t *)&cont_pkt64
->dseg_0_address
;
1523 cont_pkt64
->entry_type
= CONTINUE_TYPE
;
1525 (uint32_t *)&((cont_entry_t
*)
1526 cont_pkt64
)->dseg_0_address
;
1529 /* Load continuation entry data segments */
1531 cnt
< prm
->tgt
->datasegs_per_cont
&& prm
->seg_cnt
;
1532 cnt
++, prm
->seg_cnt
--) {
1534 cpu_to_le32(pci_dma_lo32
1535 (sg_dma_address(prm
->sg
)));
1536 if (enable_64bit_addressing
) {
1538 cpu_to_le32(pci_dma_hi32
1542 *dword_ptr
++ = cpu_to_le32(sg_dma_len(prm
->sg
));
1544 ql_dbg(ql_dbg_tgt
, vha
, 0xe00d,
1545 "S/G Segment Cont. phys_addr=%llx:%llx, len=%d\n",
1546 (long long unsigned int)
1547 pci_dma_hi32(sg_dma_address(prm
->sg
)),
1548 (long long unsigned int)
1549 pci_dma_lo32(sg_dma_address(prm
->sg
)),
1550 (int)sg_dma_len(prm
->sg
));
1552 prm
->sg
= sg_next(prm
->sg
);
1558 * ha->hardware_lock supposed to be held on entry. We have already made sure
1559 * that there is sufficient amount of request entries to not drop it.
1561 static void qlt_load_data_segments(struct qla_tgt_prm
*prm
,
1562 struct scsi_qla_host
*vha
)
1565 uint32_t *dword_ptr
;
1566 int enable_64bit_addressing
= prm
->tgt
->tgt_enable_64bit_addr
;
1567 struct ctio7_to_24xx
*pkt24
= (struct ctio7_to_24xx
*)prm
->pkt
;
1569 ql_dbg(ql_dbg_tgt
, vha
, 0xe00e,
1570 "iocb->scsi_status=%x, iocb->flags=%x\n",
1571 le16_to_cpu(pkt24
->u
.status0
.scsi_status
),
1572 le16_to_cpu(pkt24
->u
.status0
.flags
));
1574 pkt24
->u
.status0
.transfer_length
= cpu_to_le32(prm
->cmd
->bufflen
);
1576 /* Setup packet address segment pointer */
1577 dword_ptr
= pkt24
->u
.status0
.dseg_0_address
;
1579 /* Set total data segment count */
1581 pkt24
->dseg_count
= cpu_to_le16(prm
->seg_cnt
);
1583 if (prm
->seg_cnt
== 0) {
1584 /* No data transfer */
1590 /* If scatter gather */
1591 ql_dbg(ql_dbg_tgt
, vha
, 0xe00f, "%s", "Building S/G data segments...");
1593 /* Load command entry data segments */
1595 (cnt
< prm
->tgt
->datasegs_per_cmd
) && prm
->seg_cnt
;
1596 cnt
++, prm
->seg_cnt
--) {
1598 cpu_to_le32(pci_dma_lo32(sg_dma_address(prm
->sg
)));
1599 if (enable_64bit_addressing
) {
1601 cpu_to_le32(pci_dma_hi32(
1602 sg_dma_address(prm
->sg
)));
1604 *dword_ptr
++ = cpu_to_le32(sg_dma_len(prm
->sg
));
1606 ql_dbg(ql_dbg_tgt
, vha
, 0xe010,
1607 "S/G Segment phys_addr=%llx:%llx, len=%d\n",
1608 (long long unsigned int)pci_dma_hi32(sg_dma_address(
1610 (long long unsigned int)pci_dma_lo32(sg_dma_address(
1612 (int)sg_dma_len(prm
->sg
));
1614 prm
->sg
= sg_next(prm
->sg
);
1617 qlt_load_cont_data_segments(prm
, vha
);
1620 static inline int qlt_has_data(struct qla_tgt_cmd
*cmd
)
1622 return cmd
->bufflen
> 0;
1626 * Called without ha->hardware_lock held
1628 static int qlt_pre_xmit_response(struct qla_tgt_cmd
*cmd
,
1629 struct qla_tgt_prm
*prm
, int xmit_type
, uint8_t scsi_status
,
1630 uint32_t *full_req_cnt
)
1632 struct qla_tgt
*tgt
= cmd
->tgt
;
1633 struct scsi_qla_host
*vha
= tgt
->vha
;
1634 struct qla_hw_data
*ha
= vha
->hw
;
1635 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
1637 if (unlikely(cmd
->aborted
)) {
1638 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf014,
1639 "qla_target(%d): terminating exchange "
1640 "for aborted cmd=%p (se_cmd=%p, tag=%d)", vha
->vp_idx
, cmd
,
1643 cmd
->state
= QLA_TGT_STATE_ABORTED
;
1645 qlt_send_term_exchange(vha
, cmd
, &cmd
->atio
, 0);
1647 /* !! At this point cmd could be already freed !! */
1648 return QLA_TGT_PRE_XMIT_RESP_CMD_ABORTED
;
1651 ql_dbg(ql_dbg_tgt
, vha
, 0xe011, "qla_target(%d): tag=%u\n",
1652 vha
->vp_idx
, cmd
->tag
);
1656 prm
->rq_result
= scsi_status
;
1657 prm
->sense_buffer
= &cmd
->sense_buffer
[0];
1658 prm
->sense_buffer_len
= TRANSPORT_SENSE_BUFFER
;
1662 prm
->add_status_pkt
= 0;
1664 ql_dbg(ql_dbg_tgt
, vha
, 0xe012, "rq_result=%x, xmit_type=%x\n",
1665 prm
->rq_result
, xmit_type
);
1667 /* Send marker if required */
1668 if (qlt_issue_marker(vha
, 0) != QLA_SUCCESS
)
1671 ql_dbg(ql_dbg_tgt
, vha
, 0xe013, "CTIO start: vha(%d)\n", vha
->vp_idx
);
1673 if ((xmit_type
& QLA_TGT_XMIT_DATA
) && qlt_has_data(cmd
)) {
1674 if (qlt_pci_map_calc_cnt(prm
) != 0)
1678 *full_req_cnt
= prm
->req_cnt
;
1680 if (se_cmd
->se_cmd_flags
& SCF_UNDERFLOW_BIT
) {
1681 prm
->residual
= se_cmd
->residual_count
;
1682 ql_dbg(ql_dbg_tgt
, vha
, 0xe014,
1683 "Residual underflow: %d (tag %d, "
1684 "op %x, bufflen %d, rq_result %x)\n", prm
->residual
,
1685 cmd
->tag
, se_cmd
->t_task_cdb
? se_cmd
->t_task_cdb
[0] : 0,
1686 cmd
->bufflen
, prm
->rq_result
);
1687 prm
->rq_result
|= SS_RESIDUAL_UNDER
;
1688 } else if (se_cmd
->se_cmd_flags
& SCF_OVERFLOW_BIT
) {
1689 prm
->residual
= se_cmd
->residual_count
;
1690 ql_dbg(ql_dbg_tgt
, vha
, 0xe015,
1691 "Residual overflow: %d (tag %d, "
1692 "op %x, bufflen %d, rq_result %x)\n", prm
->residual
,
1693 cmd
->tag
, se_cmd
->t_task_cdb
? se_cmd
->t_task_cdb
[0] : 0,
1694 cmd
->bufflen
, prm
->rq_result
);
1695 prm
->rq_result
|= SS_RESIDUAL_OVER
;
1698 if (xmit_type
& QLA_TGT_XMIT_STATUS
) {
1700 * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be
1701 * ignored in *xmit_response() below
1703 if (qlt_has_data(cmd
)) {
1704 if (QLA_TGT_SENSE_VALID(prm
->sense_buffer
) ||
1705 (IS_FWI2_CAPABLE(ha
) &&
1706 (prm
->rq_result
!= 0))) {
1707 prm
->add_status_pkt
= 1;
1713 ql_dbg(ql_dbg_tgt
, vha
, 0xe016,
1714 "req_cnt=%d, full_req_cnt=%d, add_status_pkt=%d\n",
1715 prm
->req_cnt
, *full_req_cnt
, prm
->add_status_pkt
);
1720 static inline int qlt_need_explicit_conf(struct qla_hw_data
*ha
,
1721 struct qla_tgt_cmd
*cmd
, int sending_sense
)
1723 if (ha
->tgt
.enable_class_2
)
1727 return cmd
->conf_compl_supported
;
1729 return ha
->tgt
.enable_explicit_conf
&&
1730 cmd
->conf_compl_supported
;
1733 #ifdef CONFIG_QLA_TGT_DEBUG_SRR
1735 * Original taken from the XFS code
1737 static unsigned long qlt_srr_random(void)
1740 static unsigned long RandomValue
;
1741 static DEFINE_SPINLOCK(lock
);
1742 /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
1746 unsigned long flags
;
1748 spin_lock_irqsave(&lock
, flags
);
1750 RandomValue
= jiffies
;
1756 rv
= 16807 * lo
- 2836 * hi
;
1760 spin_unlock_irqrestore(&lock
, flags
);
1764 static void qlt_check_srr_debug(struct qla_tgt_cmd
*cmd
, int *xmit_type
)
1766 #if 0 /* This is not a real status packets lost, so it won't lead to SRR */
1767 if ((*xmit_type
& QLA_TGT_XMIT_STATUS
) && (qlt_srr_random() % 200)
1769 *xmit_type
&= ~QLA_TGT_XMIT_STATUS
;
1770 ql_dbg(ql_dbg_tgt_mgt
, cmd
->vha
, 0xf015,
1771 "Dropping cmd %p (tag %d) status", cmd
, cmd
->tag
);
1775 * It's currently not possible to simulate SRRs for FCP_WRITE without
1776 * a physical link layer failure, so don't even try here..
1778 if (cmd
->dma_data_direction
!= DMA_FROM_DEVICE
)
1781 if (qlt_has_data(cmd
) && (cmd
->sg_cnt
> 1) &&
1782 ((qlt_srr_random() % 100) == 20)) {
1784 unsigned int tot_len
= 0;
1787 leave
= qlt_srr_random() % cmd
->sg_cnt
;
1789 for (i
= 0; i
< leave
; i
++)
1790 tot_len
+= cmd
->sg
[i
].length
;
1792 ql_dbg(ql_dbg_tgt_mgt
, cmd
->vha
, 0xf016,
1793 "Cutting cmd %p (tag %d) buffer"
1794 " tail to len %d, sg_cnt %d (cmd->bufflen %d,"
1795 " cmd->sg_cnt %d)", cmd
, cmd
->tag
, tot_len
, leave
,
1796 cmd
->bufflen
, cmd
->sg_cnt
);
1798 cmd
->bufflen
= tot_len
;
1799 cmd
->sg_cnt
= leave
;
1802 if (qlt_has_data(cmd
) && ((qlt_srr_random() % 100) == 70)) {
1803 unsigned int offset
= qlt_srr_random() % cmd
->bufflen
;
1805 ql_dbg(ql_dbg_tgt_mgt
, cmd
->vha
, 0xf017,
1806 "Cutting cmd %p (tag %d) buffer head "
1807 "to offset %d (cmd->bufflen %d)", cmd
, cmd
->tag
, offset
,
1810 *xmit_type
&= ~QLA_TGT_XMIT_DATA
;
1811 else if (qlt_set_data_offset(cmd
, offset
)) {
1812 ql_dbg(ql_dbg_tgt_mgt
, cmd
->vha
, 0xf018,
1813 "qlt_set_data_offset() failed (tag %d)", cmd
->tag
);
1818 static inline void qlt_check_srr_debug(struct qla_tgt_cmd
*cmd
, int *xmit_type
)
1822 static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx
*ctio
,
1823 struct qla_tgt_prm
*prm
)
1825 prm
->sense_buffer_len
= min_t(uint32_t, prm
->sense_buffer_len
,
1826 (uint32_t)sizeof(ctio
->u
.status1
.sense_data
));
1827 ctio
->u
.status0
.flags
|=
1828 __constant_cpu_to_le16(CTIO7_FLAGS_SEND_STATUS
);
1829 if (qlt_need_explicit_conf(prm
->tgt
->ha
, prm
->cmd
, 0)) {
1830 ctio
->u
.status0
.flags
|= __constant_cpu_to_le16(
1831 CTIO7_FLAGS_EXPLICIT_CONFORM
|
1832 CTIO7_FLAGS_CONFORM_REQ
);
1834 ctio
->u
.status0
.residual
= cpu_to_le32(prm
->residual
);
1835 ctio
->u
.status0
.scsi_status
= cpu_to_le16(prm
->rq_result
);
1836 if (QLA_TGT_SENSE_VALID(prm
->sense_buffer
)) {
1839 if (qlt_need_explicit_conf(prm
->tgt
->ha
, prm
->cmd
, 1)) {
1840 if (prm
->cmd
->se_cmd
.scsi_status
!= 0) {
1841 ql_dbg(ql_dbg_tgt
, prm
->cmd
->vha
, 0xe017,
1842 "Skipping EXPLICIT_CONFORM and "
1843 "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ "
1844 "non GOOD status\n");
1845 goto skip_explict_conf
;
1847 ctio
->u
.status1
.flags
|= __constant_cpu_to_le16(
1848 CTIO7_FLAGS_EXPLICIT_CONFORM
|
1849 CTIO7_FLAGS_CONFORM_REQ
);
1852 ctio
->u
.status1
.flags
&=
1853 ~__constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0
);
1854 ctio
->u
.status1
.flags
|=
1855 __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
);
1856 ctio
->u
.status1
.scsi_status
|=
1857 __constant_cpu_to_le16(SS_SENSE_LEN_VALID
);
1858 ctio
->u
.status1
.sense_length
=
1859 cpu_to_le16(prm
->sense_buffer_len
);
1860 for (i
= 0; i
< prm
->sense_buffer_len
/4; i
++)
1861 ((uint32_t *)ctio
->u
.status1
.sense_data
)[i
] =
1862 cpu_to_be32(((uint32_t *)prm
->sense_buffer
)[i
]);
1864 if (unlikely((prm
->sense_buffer_len
% 4) != 0)) {
1867 ql_dbg(ql_dbg_tgt
, vha
, 0xe04f,
1868 "qla_target(%d): %d bytes of sense "
1869 "lost", prm
->tgt
->ha
->vp_idx
,
1870 prm
->sense_buffer_len
% 4);
1876 ctio
->u
.status1
.flags
&=
1877 ~__constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0
);
1878 ctio
->u
.status1
.flags
|=
1879 __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
);
1880 ctio
->u
.status1
.sense_length
= 0;
1881 memset(ctio
->u
.status1
.sense_data
, 0,
1882 sizeof(ctio
->u
.status1
.sense_data
));
1885 /* Sense with len > 24, is it possible ??? */
1889 * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and *
1890 * QLA_TGT_XMIT_STATUS for >= 24xx silicon
1892 int qlt_xmit_response(struct qla_tgt_cmd
*cmd
, int xmit_type
,
1893 uint8_t scsi_status
)
1895 struct scsi_qla_host
*vha
= cmd
->vha
;
1896 struct qla_hw_data
*ha
= vha
->hw
;
1897 struct ctio7_to_24xx
*pkt
;
1898 struct qla_tgt_prm prm
;
1899 uint32_t full_req_cnt
= 0;
1900 unsigned long flags
= 0;
1903 memset(&prm
, 0, sizeof(prm
));
1904 qlt_check_srr_debug(cmd
, &xmit_type
);
1906 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe018,
1907 "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, "
1908 "cmd->dma_data_direction=%d\n", (xmit_type
& QLA_TGT_XMIT_STATUS
) ?
1909 1 : 0, cmd
->bufflen
, cmd
->sg_cnt
, cmd
->dma_data_direction
);
1911 res
= qlt_pre_xmit_response(cmd
, &prm
, xmit_type
, scsi_status
,
1913 if (unlikely(res
!= 0)) {
1914 if (res
== QLA_TGT_PRE_XMIT_RESP_CMD_ABORTED
)
1920 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1922 /* Does F/W have an IOCBs for this request */
1923 res
= qlt_check_reserve_free_req(vha
, full_req_cnt
);
1925 goto out_unmap_unlock
;
1927 res
= qlt_24xx_build_ctio_pkt(&prm
, vha
);
1928 if (unlikely(res
!= 0))
1929 goto out_unmap_unlock
;
1932 pkt
= (struct ctio7_to_24xx
*)prm
.pkt
;
1934 if (qlt_has_data(cmd
) && (xmit_type
& QLA_TGT_XMIT_DATA
)) {
1935 pkt
->u
.status0
.flags
|=
1936 __constant_cpu_to_le16(CTIO7_FLAGS_DATA_IN
|
1937 CTIO7_FLAGS_STATUS_MODE_0
);
1939 qlt_load_data_segments(&prm
, vha
);
1941 if (prm
.add_status_pkt
== 0) {
1942 if (xmit_type
& QLA_TGT_XMIT_STATUS
) {
1943 pkt
->u
.status0
.scsi_status
=
1944 cpu_to_le16(prm
.rq_result
);
1945 pkt
->u
.status0
.residual
=
1946 cpu_to_le32(prm
.residual
);
1947 pkt
->u
.status0
.flags
|= __constant_cpu_to_le16(
1948 CTIO7_FLAGS_SEND_STATUS
);
1949 if (qlt_need_explicit_conf(ha
, cmd
, 0)) {
1950 pkt
->u
.status0
.flags
|=
1951 __constant_cpu_to_le16(
1952 CTIO7_FLAGS_EXPLICIT_CONFORM
|
1953 CTIO7_FLAGS_CONFORM_REQ
);
1959 * We have already made sure that there is sufficient
1960 * amount of request entries to not drop HW lock in
1963 struct ctio7_to_24xx
*ctio
=
1964 (struct ctio7_to_24xx
*)qlt_get_req_pkt(vha
);
1966 ql_dbg(ql_dbg_tgt
, vha
, 0xe019,
1967 "Building additional status packet\n");
1969 memcpy(ctio
, pkt
, sizeof(*ctio
));
1970 ctio
->entry_count
= 1;
1971 ctio
->dseg_count
= 0;
1972 ctio
->u
.status1
.flags
&= ~__constant_cpu_to_le16(
1973 CTIO7_FLAGS_DATA_IN
);
1975 /* Real finish is ctio_m1's finish */
1976 pkt
->handle
|= CTIO_INTERMEDIATE_HANDLE_MARK
;
1977 pkt
->u
.status0
.flags
|= __constant_cpu_to_le16(
1978 CTIO7_FLAGS_DONT_RET_CTIO
);
1979 qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx
*)ctio
,
1981 pr_debug("Status CTIO7: %p\n", ctio
);
1984 qlt_24xx_init_ctio_to_isp(pkt
, &prm
);
1987 cmd
->state
= QLA_TGT_STATE_PROCESSED
; /* Mid-level is done processing */
1989 ql_dbg(ql_dbg_tgt
, vha
, 0xe01a,
1990 "Xmitting CTIO7 response pkt for 24xx: %p scsi_status: 0x%02x\n",
1993 qla2x00_start_iocbs(vha
, vha
->req
);
1994 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2000 qlt_unmap_sg(vha
, cmd
);
2001 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2005 EXPORT_SYMBOL(qlt_xmit_response
);
2007 int qlt_rdy_to_xfer(struct qla_tgt_cmd
*cmd
)
2009 struct ctio7_to_24xx
*pkt
;
2010 struct scsi_qla_host
*vha
= cmd
->vha
;
2011 struct qla_hw_data
*ha
= vha
->hw
;
2012 struct qla_tgt
*tgt
= cmd
->tgt
;
2013 struct qla_tgt_prm prm
;
2014 unsigned long flags
;
2017 memset(&prm
, 0, sizeof(prm
));
2023 /* Send marker if required */
2024 if (qlt_issue_marker(vha
, 0) != QLA_SUCCESS
)
2027 ql_dbg(ql_dbg_tgt
, vha
, 0xe01b, "CTIO_start: vha(%d)",
2030 /* Calculate number of entries and segments required */
2031 if (qlt_pci_map_calc_cnt(&prm
) != 0)
2034 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2036 /* Does F/W have an IOCBs for this request */
2037 res
= qlt_check_reserve_free_req(vha
, prm
.req_cnt
);
2039 goto out_unlock_free_unmap
;
2041 res
= qlt_24xx_build_ctio_pkt(&prm
, vha
);
2042 if (unlikely(res
!= 0))
2043 goto out_unlock_free_unmap
;
2044 pkt
= (struct ctio7_to_24xx
*)prm
.pkt
;
2045 pkt
->u
.status0
.flags
|= __constant_cpu_to_le16(CTIO7_FLAGS_DATA_OUT
|
2046 CTIO7_FLAGS_STATUS_MODE_0
);
2047 qlt_load_data_segments(&prm
, vha
);
2049 cmd
->state
= QLA_TGT_STATE_NEED_DATA
;
2051 qla2x00_start_iocbs(vha
, vha
->req
);
2052 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2056 out_unlock_free_unmap
:
2058 qlt_unmap_sg(vha
, cmd
);
2059 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2063 EXPORT_SYMBOL(qlt_rdy_to_xfer
);
2065 /* If hardware_lock held on entry, might drop it, then reaquire */
2066 /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */
2067 static int __qlt_send_term_exchange(struct scsi_qla_host
*vha
,
2068 struct qla_tgt_cmd
*cmd
,
2069 struct atio_from_isp
*atio
)
2071 struct ctio7_to_24xx
*ctio24
;
2072 struct qla_hw_data
*ha
= vha
->hw
;
2076 ql_dbg(ql_dbg_tgt
, vha
, 0xe01c, "Sending TERM EXCH CTIO (ha=%p)\n", ha
);
2078 pkt
= (request_t
*)qla2x00_alloc_iocbs(vha
, NULL
);
2080 ql_dbg(ql_dbg_tgt
, vha
, 0xe050,
2081 "qla_target(%d): %s failed: unable to allocate "
2082 "request packet\n", vha
->vp_idx
, __func__
);
2087 if (cmd
->state
< QLA_TGT_STATE_PROCESSED
) {
2088 ql_dbg(ql_dbg_tgt
, vha
, 0xe051,
2089 "qla_target(%d): Terminating cmd %p with "
2090 "incorrect state %d\n", vha
->vp_idx
, cmd
,
2096 pkt
->entry_count
= 1;
2097 pkt
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
2099 ctio24
= (struct ctio7_to_24xx
*)pkt
;
2100 ctio24
->entry_type
= CTIO_TYPE7
;
2101 ctio24
->nport_handle
= cmd
? cmd
->loop_id
: CTIO7_NHANDLE_UNRECOGNIZED
;
2102 ctio24
->timeout
= __constant_cpu_to_le16(QLA_TGT_TIMEOUT
);
2103 ctio24
->vp_index
= vha
->vp_idx
;
2104 ctio24
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
2105 ctio24
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
2106 ctio24
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
2107 ctio24
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
2108 ctio24
->u
.status1
.flags
= (atio
->u
.isp24
.attr
<< 9) |
2109 __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1
|
2110 CTIO7_FLAGS_TERMINATE
);
2111 ctio24
->u
.status1
.ox_id
= swab16(atio
->u
.isp24
.fcp_hdr
.ox_id
);
2113 /* Most likely, it isn't needed */
2114 ctio24
->u
.status1
.residual
= get_unaligned((uint32_t *)
2115 &atio
->u
.isp24
.fcp_cmnd
.add_cdb
[
2116 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
]);
2117 if (ctio24
->u
.status1
.residual
!= 0)
2118 ctio24
->u
.status1
.scsi_status
|= SS_RESIDUAL_UNDER
;
2120 qla2x00_start_iocbs(vha
, vha
->req
);
2124 static void qlt_send_term_exchange(struct scsi_qla_host
*vha
,
2125 struct qla_tgt_cmd
*cmd
, struct atio_from_isp
*atio
, int ha_locked
)
2127 unsigned long flags
;
2130 if (qlt_issue_marker(vha
, ha_locked
) < 0)
2134 rc
= __qlt_send_term_exchange(vha
, cmd
, atio
);
2137 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
2138 rc
= __qlt_send_term_exchange(vha
, cmd
, atio
);
2139 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
2142 if (!ha_locked
&& !in_interrupt())
2143 msleep(250); /* just in case */
2145 vha
->hw
->tgt
.tgt_ops
->free_cmd(cmd
);
2149 void qlt_free_cmd(struct qla_tgt_cmd
*cmd
)
2151 BUG_ON(cmd
->sg_mapped
);
2153 if (unlikely(cmd
->free_sg
))
2155 kmem_cache_free(qla_tgt_cmd_cachep
, cmd
);
2157 EXPORT_SYMBOL(qlt_free_cmd
);
2159 /* ha->hardware_lock supposed to be held on entry */
2160 static int qlt_prepare_srr_ctio(struct scsi_qla_host
*vha
,
2161 struct qla_tgt_cmd
*cmd
, void *ctio
)
2163 struct qla_tgt_srr_ctio
*sc
;
2164 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
2165 struct qla_tgt_srr_imm
*imm
;
2169 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf019,
2170 "qla_target(%d): CTIO with SRR status received\n", vha
->vp_idx
);
2173 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf055,
2174 "qla_target(%d): SRR CTIO, but ctio is NULL\n",
2179 sc
= kzalloc(sizeof(*sc
), GFP_ATOMIC
);
2182 /* IRQ is already OFF */
2183 spin_lock(&tgt
->srr_lock
);
2184 sc
->srr_id
= tgt
->ctio_srr_id
;
2185 list_add_tail(&sc
->srr_list_entry
,
2186 &tgt
->srr_ctio_list
);
2187 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01a,
2188 "CTIO SRR %p added (id %d)\n", sc
, sc
->srr_id
);
2189 if (tgt
->imm_srr_id
== tgt
->ctio_srr_id
) {
2191 list_for_each_entry(imm
, &tgt
->srr_imm_list
,
2193 if (imm
->srr_id
== sc
->srr_id
) {
2199 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01b,
2200 "Scheduling srr work\n");
2201 schedule_work(&tgt
->srr_work
);
2203 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf056,
2204 "qla_target(%d): imm_srr_id "
2205 "== ctio_srr_id (%d), but there is no "
2206 "corresponding SRR IMM, deleting CTIO "
2207 "SRR %p\n", vha
->vp_idx
,
2208 tgt
->ctio_srr_id
, sc
);
2209 list_del(&sc
->srr_list_entry
);
2210 spin_unlock(&tgt
->srr_lock
);
2216 spin_unlock(&tgt
->srr_lock
);
2218 struct qla_tgt_srr_imm
*ti
;
2220 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf057,
2221 "qla_target(%d): Unable to allocate SRR CTIO entry\n",
2223 spin_lock(&tgt
->srr_lock
);
2224 list_for_each_entry_safe(imm
, ti
, &tgt
->srr_imm_list
,
2226 if (imm
->srr_id
== tgt
->ctio_srr_id
) {
2227 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01c,
2228 "IMM SRR %p deleted (id %d)\n",
2230 list_del(&imm
->srr_list_entry
);
2231 qlt_reject_free_srr_imm(vha
, imm
, 1);
2234 spin_unlock(&tgt
->srr_lock
);
2243 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2245 static int qlt_term_ctio_exchange(struct scsi_qla_host
*vha
, void *ctio
,
2246 struct qla_tgt_cmd
*cmd
, uint32_t status
)
2251 struct ctio7_from_24xx
*c
= (struct ctio7_from_24xx
*)ctio
;
2253 __constant_cpu_to_le16(OF_TERM_EXCH
));
2258 qlt_send_term_exchange(vha
, cmd
, &cmd
->atio
, 1);
2263 /* ha->hardware_lock supposed to be held on entry */
2264 static inline struct qla_tgt_cmd
*qlt_get_cmd(struct scsi_qla_host
*vha
,
2267 struct qla_hw_data
*ha
= vha
->hw
;
2270 if (ha
->tgt
.cmds
[handle
] != NULL
) {
2271 struct qla_tgt_cmd
*cmd
= ha
->tgt
.cmds
[handle
];
2272 ha
->tgt
.cmds
[handle
] = NULL
;
2278 /* ha->hardware_lock supposed to be held on entry */
2279 static struct qla_tgt_cmd
*qlt_ctio_to_cmd(struct scsi_qla_host
*vha
,
2280 uint32_t handle
, void *ctio
)
2282 struct qla_tgt_cmd
*cmd
= NULL
;
2284 /* Clear out internal marks */
2285 handle
&= ~(CTIO_COMPLETION_HANDLE_MARK
|
2286 CTIO_INTERMEDIATE_HANDLE_MARK
);
2288 if (handle
!= QLA_TGT_NULL_HANDLE
) {
2289 if (unlikely(handle
== QLA_TGT_SKIP_HANDLE
)) {
2290 ql_dbg(ql_dbg_tgt
, vha
, 0xe01d, "%s",
2291 "SKIP_HANDLE CTIO\n");
2294 /* handle-1 is actually used */
2295 if (unlikely(handle
> DEFAULT_OUTSTANDING_COMMANDS
)) {
2296 ql_dbg(ql_dbg_tgt
, vha
, 0xe052,
2297 "qla_target(%d): Wrong handle %x received\n",
2298 vha
->vp_idx
, handle
);
2301 cmd
= qlt_get_cmd(vha
, handle
);
2302 if (unlikely(cmd
== NULL
)) {
2303 ql_dbg(ql_dbg_tgt
, vha
, 0xe053,
2304 "qla_target(%d): Suspicious: unable to "
2305 "find the command with handle %x\n", vha
->vp_idx
,
2309 } else if (ctio
!= NULL
) {
2310 /* We can't get loop ID from CTIO7 */
2311 ql_dbg(ql_dbg_tgt
, vha
, 0xe054,
2312 "qla_target(%d): Wrong CTIO received: QLA24xx doesn't "
2313 "support NULL handles\n", vha
->vp_idx
);
2321 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2323 static void qlt_do_ctio_completion(struct scsi_qla_host
*vha
, uint32_t handle
,
2324 uint32_t status
, void *ctio
)
2326 struct qla_hw_data
*ha
= vha
->hw
;
2327 struct se_cmd
*se_cmd
;
2328 struct target_core_fabric_ops
*tfo
;
2329 struct qla_tgt_cmd
*cmd
;
2331 ql_dbg(ql_dbg_tgt
, vha
, 0xe01e,
2332 "qla_target(%d): handle(ctio %p status %#x) <- %08x\n",
2333 vha
->vp_idx
, ctio
, status
, handle
);
2335 if (handle
& CTIO_INTERMEDIATE_HANDLE_MARK
) {
2336 /* That could happen only in case of an error/reset/abort */
2337 if (status
!= CTIO_SUCCESS
) {
2338 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01d,
2339 "Intermediate CTIO received"
2340 " (status %x)\n", status
);
2345 cmd
= qlt_ctio_to_cmd(vha
, handle
, ctio
);
2349 se_cmd
= &cmd
->se_cmd
;
2350 tfo
= se_cmd
->se_tfo
;
2353 qlt_unmap_sg(vha
, cmd
);
2355 if (unlikely(status
!= CTIO_SUCCESS
)) {
2356 switch (status
& 0xFFFF) {
2357 case CTIO_LIP_RESET
:
2358 case CTIO_TARGET_RESET
:
2361 case CTIO_INVALID_RX_ID
:
2363 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf058,
2364 "qla_target(%d): CTIO with "
2365 "status %#x received, state %x, se_cmd %p, "
2366 "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, "
2367 "TIMEOUT=b, INVALID_RX_ID=8)\n", vha
->vp_idx
,
2368 status
, cmd
->state
, se_cmd
);
2371 case CTIO_PORT_LOGGED_OUT
:
2372 case CTIO_PORT_UNAVAILABLE
:
2373 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf059,
2374 "qla_target(%d): CTIO with PORT LOGGED "
2375 "OUT (29) or PORT UNAVAILABLE (28) status %x "
2376 "received (state %x, se_cmd %p)\n", vha
->vp_idx
,
2377 status
, cmd
->state
, se_cmd
);
2380 case CTIO_SRR_RECEIVED
:
2381 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05a,
2382 "qla_target(%d): CTIO with SRR_RECEIVED"
2383 " status %x received (state %x, se_cmd %p)\n",
2384 vha
->vp_idx
, status
, cmd
->state
, se_cmd
);
2385 if (qlt_prepare_srr_ctio(vha
, cmd
, ctio
) != 0)
2391 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05b,
2392 "qla_target(%d): CTIO with error status "
2393 "0x%x received (state %x, se_cmd %p\n",
2394 vha
->vp_idx
, status
, cmd
->state
, se_cmd
);
2398 if (cmd
->state
!= QLA_TGT_STATE_NEED_DATA
)
2399 if (qlt_term_ctio_exchange(vha
, ctio
, cmd
, status
))
2403 if (cmd
->state
== QLA_TGT_STATE_PROCESSED
) {
2404 ql_dbg(ql_dbg_tgt
, vha
, 0xe01f, "Command %p finished\n", cmd
);
2405 } else if (cmd
->state
== QLA_TGT_STATE_NEED_DATA
) {
2408 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
2410 if (unlikely(status
!= CTIO_SUCCESS
))
2413 cmd
->write_data_transferred
= 1;
2415 ql_dbg(ql_dbg_tgt
, vha
, 0xe020,
2416 "Data received, context %x, rx_status %d\n",
2419 ha
->tgt
.tgt_ops
->handle_data(cmd
);
2421 } else if (cmd
->state
== QLA_TGT_STATE_ABORTED
) {
2422 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01e,
2423 "Aborted command %p (tag %d) finished\n", cmd
, cmd
->tag
);
2425 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05c,
2426 "qla_target(%d): A command in state (%d) should "
2427 "not return a CTIO complete\n", vha
->vp_idx
, cmd
->state
);
2430 if (unlikely(status
!= CTIO_SUCCESS
)) {
2431 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf01f, "Finishing failed CTIO\n");
2435 ha
->tgt
.tgt_ops
->free_cmd(cmd
);
2438 static inline int qlt_get_fcp_task_attr(struct scsi_qla_host
*vha
,
2443 switch (task_codes
) {
2444 case ATIO_SIMPLE_QUEUE
:
2445 fcp_task_attr
= MSG_SIMPLE_TAG
;
2447 case ATIO_HEAD_OF_QUEUE
:
2448 fcp_task_attr
= MSG_HEAD_TAG
;
2450 case ATIO_ORDERED_QUEUE
:
2451 fcp_task_attr
= MSG_ORDERED_TAG
;
2453 case ATIO_ACA_QUEUE
:
2454 fcp_task_attr
= MSG_ACA_TAG
;
2457 fcp_task_attr
= MSG_SIMPLE_TAG
;
2460 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05d,
2461 "qla_target: unknown task code %x, use ORDERED instead\n",
2463 fcp_task_attr
= MSG_ORDERED_TAG
;
2467 return fcp_task_attr
;
2470 static struct qla_tgt_sess
*qlt_make_local_sess(struct scsi_qla_host
*,
2473 * Process context for I/O path into tcm_qla2xxx code
2475 static void qlt_do_work(struct work_struct
*work
)
2477 struct qla_tgt_cmd
*cmd
= container_of(work
, struct qla_tgt_cmd
, work
);
2478 scsi_qla_host_t
*vha
= cmd
->vha
;
2479 struct qla_hw_data
*ha
= vha
->hw
;
2480 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
2481 struct qla_tgt_sess
*sess
= NULL
;
2482 struct atio_from_isp
*atio
= &cmd
->atio
;
2484 unsigned long flags
;
2485 uint32_t data_length
;
2486 int ret
, fcp_task_attr
, data_dir
, bidi
= 0;
2491 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2492 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
2493 atio
->u
.isp24
.fcp_hdr
.s_id
);
2494 /* Do kref_get() before dropping qla_hw_data->hardware_lock. */
2496 kref_get(&sess
->se_sess
->sess_kref
);
2497 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2499 if (unlikely(!sess
)) {
2500 uint8_t *s_id
= atio
->u
.isp24
.fcp_hdr
.s_id
;
2502 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf022,
2503 "qla_target(%d): Unable to find wwn login"
2504 " (s_id %x:%x:%x), trying to create it manually\n",
2505 vha
->vp_idx
, s_id
[0], s_id
[1], s_id
[2]);
2507 if (atio
->u
.raw
.entry_count
> 1) {
2508 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf023,
2509 "Dropping multy entry cmd %p\n", cmd
);
2513 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
2514 sess
= qlt_make_local_sess(vha
, s_id
);
2515 /* sess has an extra creation ref. */
2516 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
2523 cmd
->loop_id
= sess
->loop_id
;
2524 cmd
->conf_compl_supported
= sess
->conf_compl_supported
;
2526 cdb
= &atio
->u
.isp24
.fcp_cmnd
.cdb
[0];
2527 cmd
->tag
= atio
->u
.isp24
.exchange_addr
;
2528 cmd
->unpacked_lun
= scsilun_to_int(
2529 (struct scsi_lun
*)&atio
->u
.isp24
.fcp_cmnd
.lun
);
2531 if (atio
->u
.isp24
.fcp_cmnd
.rddata
&&
2532 atio
->u
.isp24
.fcp_cmnd
.wrdata
) {
2534 data_dir
= DMA_TO_DEVICE
;
2535 } else if (atio
->u
.isp24
.fcp_cmnd
.rddata
)
2536 data_dir
= DMA_FROM_DEVICE
;
2537 else if (atio
->u
.isp24
.fcp_cmnd
.wrdata
)
2538 data_dir
= DMA_TO_DEVICE
;
2540 data_dir
= DMA_NONE
;
2542 fcp_task_attr
= qlt_get_fcp_task_attr(vha
,
2543 atio
->u
.isp24
.fcp_cmnd
.task_attr
);
2544 data_length
= be32_to_cpu(get_unaligned((uint32_t *)
2545 &atio
->u
.isp24
.fcp_cmnd
.add_cdb
[
2546 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
]));
2548 ql_dbg(ql_dbg_tgt
, vha
, 0xe022,
2549 "qla_target: START qla command: %p lun: 0x%04x (tag %d)\n",
2550 cmd
, cmd
->unpacked_lun
, cmd
->tag
);
2552 ret
= vha
->hw
->tgt
.tgt_ops
->handle_cmd(vha
, cmd
, cdb
, data_length
,
2553 fcp_task_attr
, data_dir
, bidi
);
2557 * Drop extra session reference from qla_tgt_handle_cmd_for_atio*(
2559 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2560 ha
->tgt
.tgt_ops
->put_sess(sess
);
2561 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2565 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf020, "Terminating work cmd %p", cmd
);
2567 * cmd has not sent to target yet, so pass NULL as the second
2568 * argument to qlt_send_term_exchange() and free the memory here.
2570 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2571 qlt_send_term_exchange(vha
, NULL
, &cmd
->atio
, 1);
2572 kmem_cache_free(qla_tgt_cmd_cachep
, cmd
);
2574 ha
->tgt
.tgt_ops
->put_sess(sess
);
2575 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2578 /* ha->hardware_lock supposed to be held on entry */
2579 static int qlt_handle_cmd_for_atio(struct scsi_qla_host
*vha
,
2580 struct atio_from_isp
*atio
)
2582 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
2583 struct qla_tgt_cmd
*cmd
;
2585 if (unlikely(tgt
->tgt_stop
)) {
2586 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf021,
2587 "New command while device %p is shutting down\n", tgt
);
2591 cmd
= kmem_cache_zalloc(qla_tgt_cmd_cachep
, GFP_ATOMIC
);
2593 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05e,
2594 "qla_target(%d): Allocation of cmd failed\n", vha
->vp_idx
);
2598 memcpy(&cmd
->atio
, atio
, sizeof(*atio
));
2599 cmd
->state
= QLA_TGT_STATE_NEW
;
2600 cmd
->tgt
= vha
->vha_tgt
.qla_tgt
;
2603 INIT_WORK(&cmd
->work
, qlt_do_work
);
2604 queue_work(qla_tgt_wq
, &cmd
->work
);
2609 /* ha->hardware_lock supposed to be held on entry */
2610 static int qlt_issue_task_mgmt(struct qla_tgt_sess
*sess
, uint32_t lun
,
2611 int fn
, void *iocb
, int flags
)
2613 struct scsi_qla_host
*vha
= sess
->vha
;
2614 struct qla_hw_data
*ha
= vha
->hw
;
2615 struct qla_tgt_mgmt_cmd
*mcmd
;
2619 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
2621 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10009,
2622 "qla_target(%d): Allocation of management "
2623 "command failed, some commands and their data could "
2624 "leak\n", vha
->vp_idx
);
2627 memset(mcmd
, 0, sizeof(*mcmd
));
2631 memcpy(&mcmd
->orig_iocb
.imm_ntfy
, iocb
,
2632 sizeof(mcmd
->orig_iocb
.imm_ntfy
));
2634 mcmd
->tmr_func
= fn
;
2635 mcmd
->flags
= flags
;
2638 case QLA_TGT_CLEAR_ACA
:
2639 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10000,
2640 "qla_target(%d): CLEAR_ACA received\n", sess
->vha
->vp_idx
);
2641 tmr_func
= TMR_CLEAR_ACA
;
2644 case QLA_TGT_TARGET_RESET
:
2645 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10001,
2646 "qla_target(%d): TARGET_RESET received\n",
2648 tmr_func
= TMR_TARGET_WARM_RESET
;
2651 case QLA_TGT_LUN_RESET
:
2652 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10002,
2653 "qla_target(%d): LUN_RESET received\n", sess
->vha
->vp_idx
);
2654 tmr_func
= TMR_LUN_RESET
;
2657 case QLA_TGT_CLEAR_TS
:
2658 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10003,
2659 "qla_target(%d): CLEAR_TS received\n", sess
->vha
->vp_idx
);
2660 tmr_func
= TMR_CLEAR_TASK_SET
;
2663 case QLA_TGT_ABORT_TS
:
2664 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10004,
2665 "qla_target(%d): ABORT_TS received\n", sess
->vha
->vp_idx
);
2666 tmr_func
= TMR_ABORT_TASK_SET
;
2669 case QLA_TGT_ABORT_ALL
:
2670 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10005,
2671 "qla_target(%d): Doing ABORT_ALL_TASKS\n",
2676 case QLA_TGT_ABORT_ALL_SESS
:
2677 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10006,
2678 "qla_target(%d): Doing ABORT_ALL_TASKS_SESS\n",
2683 case QLA_TGT_NEXUS_LOSS_SESS
:
2684 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10007,
2685 "qla_target(%d): Doing NEXUS_LOSS_SESS\n",
2690 case QLA_TGT_NEXUS_LOSS
:
2691 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x10008,
2692 "qla_target(%d): Doing NEXUS_LOSS\n", sess
->vha
->vp_idx
);
2697 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x1000a,
2698 "qla_target(%d): Unknown task mgmt fn 0x%x\n",
2699 sess
->vha
->vp_idx
, fn
);
2700 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
2704 res
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, lun
, tmr_func
, 0);
2706 ql_dbg(ql_dbg_tgt_tmr
, vha
, 0x1000b,
2707 "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n",
2708 sess
->vha
->vp_idx
, res
);
2709 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
2716 /* ha->hardware_lock supposed to be held on entry */
2717 static int qlt_handle_task_mgmt(struct scsi_qla_host
*vha
, void *iocb
)
2719 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
2720 struct qla_hw_data
*ha
= vha
->hw
;
2721 struct qla_tgt
*tgt
;
2722 struct qla_tgt_sess
*sess
;
2723 uint32_t lun
, unpacked_lun
;
2726 tgt
= vha
->vha_tgt
.qla_tgt
;
2728 lun
= a
->u
.isp24
.fcp_cmnd
.lun
;
2729 lun_size
= sizeof(a
->u
.isp24
.fcp_cmnd
.lun
);
2730 fn
= a
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
;
2731 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
2732 a
->u
.isp24
.fcp_hdr
.s_id
);
2733 unpacked_lun
= scsilun_to_int((struct scsi_lun
*)&lun
);
2736 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf024,
2737 "qla_target(%d): task mgmt fn 0x%x for "
2738 "non-existant session\n", vha
->vp_idx
, fn
);
2739 return qlt_sched_sess_work(tgt
, QLA_TGT_SESS_WORK_TM
, iocb
,
2740 sizeof(struct atio_from_isp
));
2743 return qlt_issue_task_mgmt(sess
, unpacked_lun
, fn
, iocb
, 0);
2746 /* ha->hardware_lock supposed to be held on entry */
2747 static int __qlt_abort_task(struct scsi_qla_host
*vha
,
2748 struct imm_ntfy_from_isp
*iocb
, struct qla_tgt_sess
*sess
)
2750 struct atio_from_isp
*a
= (struct atio_from_isp
*)iocb
;
2751 struct qla_hw_data
*ha
= vha
->hw
;
2752 struct qla_tgt_mgmt_cmd
*mcmd
;
2753 uint32_t lun
, unpacked_lun
;
2756 mcmd
= mempool_alloc(qla_tgt_mgmt_cmd_mempool
, GFP_ATOMIC
);
2758 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf05f,
2759 "qla_target(%d): %s: Allocation of ABORT cmd failed\n",
2760 vha
->vp_idx
, __func__
);
2763 memset(mcmd
, 0, sizeof(*mcmd
));
2766 memcpy(&mcmd
->orig_iocb
.imm_ntfy
, iocb
,
2767 sizeof(mcmd
->orig_iocb
.imm_ntfy
));
2769 lun
= a
->u
.isp24
.fcp_cmnd
.lun
;
2770 unpacked_lun
= scsilun_to_int((struct scsi_lun
*)&lun
);
2772 rc
= ha
->tgt
.tgt_ops
->handle_tmr(mcmd
, unpacked_lun
, TMR_ABORT_TASK
,
2773 le16_to_cpu(iocb
->u
.isp2x
.seq_id
));
2775 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf060,
2776 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
2778 mempool_free(mcmd
, qla_tgt_mgmt_cmd_mempool
);
2785 /* ha->hardware_lock supposed to be held on entry */
2786 static int qlt_abort_task(struct scsi_qla_host
*vha
,
2787 struct imm_ntfy_from_isp
*iocb
)
2789 struct qla_hw_data
*ha
= vha
->hw
;
2790 struct qla_tgt_sess
*sess
;
2793 loop_id
= GET_TARGET_ID(ha
, (struct atio_from_isp
*)iocb
);
2795 sess
= ha
->tgt
.tgt_ops
->find_sess_by_loop_id(vha
, loop_id
);
2797 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf025,
2798 "qla_target(%d): task abort for unexisting "
2799 "session\n", vha
->vp_idx
);
2800 return qlt_sched_sess_work(vha
->vha_tgt
.qla_tgt
,
2801 QLA_TGT_SESS_WORK_ABORT
, iocb
, sizeof(*iocb
));
2804 return __qlt_abort_task(vha
, iocb
, sess
);
2808 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
2810 static int qlt_24xx_handle_els(struct scsi_qla_host
*vha
,
2811 struct imm_ntfy_from_isp
*iocb
)
2815 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf026,
2816 "qla_target(%d): Port ID: 0x%3phC ELS opcode: 0x%02x\n",
2817 vha
->vp_idx
, iocb
->u
.isp24
.port_id
, iocb
->u
.isp24
.status_subcode
);
2819 switch (iocb
->u
.isp24
.status_subcode
) {
2825 res
= qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
);
2830 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
2831 if (tgt
->link_reinit_iocb_pending
) {
2832 qlt_send_notify_ack(vha
, &tgt
->link_reinit_iocb
,
2834 tgt
->link_reinit_iocb_pending
= 0;
2836 res
= 1; /* send notify ack */
2841 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf061,
2842 "qla_target(%d): Unsupported ELS command %x "
2843 "received\n", vha
->vp_idx
, iocb
->u
.isp24
.status_subcode
);
2844 res
= qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
);
2851 static int qlt_set_data_offset(struct qla_tgt_cmd
*cmd
, uint32_t offset
)
2853 struct scatterlist
*sg
, *sgp
, *sg_srr
, *sg_srr_start
= NULL
;
2854 size_t first_offset
= 0, rem_offset
= offset
, tmp
= 0;
2855 int i
, sg_srr_cnt
, bufflen
= 0;
2857 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe023,
2858 "Entering qla_tgt_set_data_offset: cmd: %p, cmd->sg: %p, "
2859 "cmd->sg_cnt: %u, direction: %d\n",
2860 cmd
, cmd
->sg
, cmd
->sg_cnt
, cmd
->dma_data_direction
);
2863 * FIXME: Reject non zero SRR relative offset until we can test
2864 * this code properly.
2866 pr_debug("Rejecting non zero SRR rel_offs: %u\n", offset
);
2869 if (!cmd
->sg
|| !cmd
->sg_cnt
) {
2870 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe055,
2871 "Missing cmd->sg or zero cmd->sg_cnt in"
2872 " qla_tgt_set_data_offset\n");
2876 * Walk the current cmd->sg list until we locate the new sg_srr_start
2878 for_each_sg(cmd
->sg
, sg
, cmd
->sg_cnt
, i
) {
2879 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe024,
2880 "sg[%d]: %p page: %p, length: %d, offset: %d\n",
2881 i
, sg
, sg_page(sg
), sg
->length
, sg
->offset
);
2883 if ((sg
->length
+ tmp
) > offset
) {
2884 first_offset
= rem_offset
;
2886 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe025,
2887 "Found matching sg[%d], using %p as sg_srr_start, "
2888 "and using first_offset: %zu\n", i
, sg
,
2893 rem_offset
-= sg
->length
;
2896 if (!sg_srr_start
) {
2897 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe056,
2898 "Unable to locate sg_srr_start for offset: %u\n", offset
);
2901 sg_srr_cnt
= (cmd
->sg_cnt
- i
);
2903 sg_srr
= kzalloc(sizeof(struct scatterlist
) * sg_srr_cnt
, GFP_KERNEL
);
2905 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe057,
2906 "Unable to allocate sgp\n");
2909 sg_init_table(sg_srr
, sg_srr_cnt
);
2912 * Walk the remaining list for sg_srr_start, mapping to the newly
2913 * allocated sg_srr taking first_offset into account.
2915 for_each_sg(sg_srr_start
, sg
, sg_srr_cnt
, i
) {
2917 sg_set_page(sgp
, sg_page(sg
),
2918 (sg
->length
- first_offset
), first_offset
);
2921 sg_set_page(sgp
, sg_page(sg
), sg
->length
, 0);
2923 bufflen
+= sgp
->length
;
2931 cmd
->sg_cnt
= sg_srr_cnt
;
2932 cmd
->bufflen
= bufflen
;
2933 cmd
->offset
+= offset
;
2936 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe026, "New cmd->sg: %p\n", cmd
->sg
);
2937 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe027, "New cmd->sg_cnt: %u\n",
2939 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe028, "New cmd->bufflen: %u\n",
2941 ql_dbg(ql_dbg_tgt
, cmd
->vha
, 0xe029, "New cmd->offset: %u\n",
2944 if (cmd
->sg_cnt
< 0)
2947 if (cmd
->bufflen
< 0)
2953 static inline int qlt_srr_adjust_data(struct qla_tgt_cmd
*cmd
,
2954 uint32_t srr_rel_offs
, int *xmit_type
)
2956 int res
= 0, rel_offs
;
2958 rel_offs
= srr_rel_offs
- cmd
->offset
;
2959 ql_dbg(ql_dbg_tgt_mgt
, cmd
->vha
, 0xf027, "srr_rel_offs=%d, rel_offs=%d",
2960 srr_rel_offs
, rel_offs
);
2962 *xmit_type
= QLA_TGT_XMIT_ALL
;
2965 ql_dbg(ql_dbg_tgt_mgt
, cmd
->vha
, 0xf062,
2966 "qla_target(%d): SRR rel_offs (%d) < 0",
2967 cmd
->vha
->vp_idx
, rel_offs
);
2969 } else if (rel_offs
== cmd
->bufflen
)
2970 *xmit_type
= QLA_TGT_XMIT_STATUS
;
2971 else if (rel_offs
> 0)
2972 res
= qlt_set_data_offset(cmd
, rel_offs
);
2977 /* No locks, thread context */
2978 static void qlt_handle_srr(struct scsi_qla_host
*vha
,
2979 struct qla_tgt_srr_ctio
*sctio
, struct qla_tgt_srr_imm
*imm
)
2981 struct imm_ntfy_from_isp
*ntfy
=
2982 (struct imm_ntfy_from_isp
*)&imm
->imm_ntfy
;
2983 struct qla_hw_data
*ha
= vha
->hw
;
2984 struct qla_tgt_cmd
*cmd
= sctio
->cmd
;
2985 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
2986 unsigned long flags
;
2987 int xmit_type
= 0, resp
= 0;
2991 offset
= le32_to_cpu(ntfy
->u
.isp24
.srr_rel_offs
);
2992 srr_ui
= ntfy
->u
.isp24
.srr_ui
;
2994 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf028, "SRR cmd %p, srr_ui %x\n",
2999 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3000 qlt_send_notify_ack(vha
, ntfy
,
3001 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT
, 0, 0);
3002 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3003 xmit_type
= QLA_TGT_XMIT_STATUS
;
3006 case SRR_IU_DATA_IN
:
3007 if (!cmd
->sg
|| !cmd
->sg_cnt
) {
3008 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf063,
3009 "Unable to process SRR_IU_DATA_IN due to"
3010 " missing cmd->sg, state: %d\n", cmd
->state
);
3014 if (se_cmd
->scsi_status
!= 0) {
3015 ql_dbg(ql_dbg_tgt
, vha
, 0xe02a,
3016 "Rejecting SRR_IU_DATA_IN with non GOOD "
3020 cmd
->bufflen
= se_cmd
->data_length
;
3022 if (qlt_has_data(cmd
)) {
3023 if (qlt_srr_adjust_data(cmd
, offset
, &xmit_type
) != 0)
3025 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3026 qlt_send_notify_ack(vha
, ntfy
,
3027 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT
, 0, 0);
3028 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3031 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf064,
3032 "qla_target(%d): SRR for in data for cmd "
3033 "without them (tag %d, SCSI status %d), "
3034 "reject", vha
->vp_idx
, cmd
->tag
,
3035 cmd
->se_cmd
.scsi_status
);
3039 case SRR_IU_DATA_OUT
:
3040 if (!cmd
->sg
|| !cmd
->sg_cnt
) {
3041 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf065,
3042 "Unable to process SRR_IU_DATA_OUT due to"
3043 " missing cmd->sg\n");
3047 if (se_cmd
->scsi_status
!= 0) {
3048 ql_dbg(ql_dbg_tgt
, vha
, 0xe02b,
3049 "Rejecting SRR_IU_DATA_OUT"
3050 " with non GOOD scsi_status\n");
3053 cmd
->bufflen
= se_cmd
->data_length
;
3055 if (qlt_has_data(cmd
)) {
3056 if (qlt_srr_adjust_data(cmd
, offset
, &xmit_type
) != 0)
3058 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3059 qlt_send_notify_ack(vha
, ntfy
,
3060 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT
, 0, 0);
3061 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3062 if (xmit_type
& QLA_TGT_XMIT_DATA
)
3063 qlt_rdy_to_xfer(cmd
);
3065 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf066,
3066 "qla_target(%d): SRR for out data for cmd "
3067 "without them (tag %d, SCSI status %d), "
3068 "reject", vha
->vp_idx
, cmd
->tag
,
3069 cmd
->se_cmd
.scsi_status
);
3074 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf067,
3075 "qla_target(%d): Unknown srr_ui value %x",
3076 vha
->vp_idx
, srr_ui
);
3080 /* Transmit response in case of status and data-in cases */
3082 qlt_xmit_response(cmd
, xmit_type
, se_cmd
->scsi_status
);
3087 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3088 qlt_send_notify_ack(vha
, ntfy
, 0, 0, 0,
3089 NOTIFY_ACK_SRR_FLAGS_REJECT
,
3090 NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM
,
3091 NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL
);
3092 if (cmd
->state
== QLA_TGT_STATE_NEED_DATA
) {
3093 cmd
->state
= QLA_TGT_STATE_DATA_IN
;
3096 qlt_send_term_exchange(vha
, cmd
, &cmd
->atio
, 1);
3097 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3100 static void qlt_reject_free_srr_imm(struct scsi_qla_host
*vha
,
3101 struct qla_tgt_srr_imm
*imm
, int ha_locked
)
3103 struct qla_hw_data
*ha
= vha
->hw
;
3104 unsigned long flags
= 0;
3107 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3109 qlt_send_notify_ack(vha
, (void *)&imm
->imm_ntfy
, 0, 0, 0,
3110 NOTIFY_ACK_SRR_FLAGS_REJECT
,
3111 NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM
,
3112 NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL
);
3115 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3120 static void qlt_handle_srr_work(struct work_struct
*work
)
3122 struct qla_tgt
*tgt
= container_of(work
, struct qla_tgt
, srr_work
);
3123 struct scsi_qla_host
*vha
= tgt
->vha
;
3124 struct qla_tgt_srr_ctio
*sctio
;
3125 unsigned long flags
;
3127 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf029, "Entering SRR work (tgt %p)\n",
3131 spin_lock_irqsave(&tgt
->srr_lock
, flags
);
3132 list_for_each_entry(sctio
, &tgt
->srr_ctio_list
, srr_list_entry
) {
3133 struct qla_tgt_srr_imm
*imm
, *i
, *ti
;
3134 struct qla_tgt_cmd
*cmd
;
3135 struct se_cmd
*se_cmd
;
3138 list_for_each_entry_safe(i
, ti
, &tgt
->srr_imm_list
,
3140 if (i
->srr_id
== sctio
->srr_id
) {
3141 list_del(&i
->srr_list_entry
);
3143 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf068,
3144 "qla_target(%d): There must be "
3145 "only one IMM SRR per CTIO SRR "
3146 "(IMM SRR %p, id %d, CTIO %p\n",
3147 vha
->vp_idx
, i
, i
->srr_id
, sctio
);
3148 qlt_reject_free_srr_imm(tgt
->vha
, i
, 0);
3154 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf02a,
3155 "IMM SRR %p, CTIO SRR %p (id %d)\n", imm
, sctio
,
3159 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf02b,
3160 "Not found matching IMM for SRR CTIO (id %d)\n",
3164 list_del(&sctio
->srr_list_entry
);
3166 spin_unlock_irqrestore(&tgt
->srr_lock
, flags
);
3170 * Reset qla_tgt_cmd SRR values and SGL pointer+count to follow
3171 * tcm_qla2xxx_write_pending() and tcm_qla2xxx_queue_data_in()
3180 se_cmd
= &cmd
->se_cmd
;
3182 cmd
->sg_cnt
= se_cmd
->t_data_nents
;
3183 cmd
->sg
= se_cmd
->t_data_sg
;
3185 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf02c,
3186 "SRR cmd %p (se_cmd %p, tag %d, op %x), "
3187 "sg_cnt=%d, offset=%d", cmd
, &cmd
->se_cmd
, cmd
->tag
,
3188 se_cmd
->t_task_cdb
[0], cmd
->sg_cnt
, cmd
->offset
);
3190 qlt_handle_srr(vha
, sctio
, imm
);
3196 spin_unlock_irqrestore(&tgt
->srr_lock
, flags
);
3199 /* ha->hardware_lock supposed to be held on entry */
3200 static void qlt_prepare_srr_imm(struct scsi_qla_host
*vha
,
3201 struct imm_ntfy_from_isp
*iocb
)
3203 struct qla_tgt_srr_imm
*imm
;
3204 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
3205 struct qla_tgt_srr_ctio
*sctio
;
3209 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf02d, "qla_target(%d): SRR received\n",
3212 imm
= kzalloc(sizeof(*imm
), GFP_ATOMIC
);
3214 memcpy(&imm
->imm_ntfy
, iocb
, sizeof(imm
->imm_ntfy
));
3216 /* IRQ is already OFF */
3217 spin_lock(&tgt
->srr_lock
);
3218 imm
->srr_id
= tgt
->imm_srr_id
;
3219 list_add_tail(&imm
->srr_list_entry
,
3220 &tgt
->srr_imm_list
);
3221 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf02e,
3222 "IMM NTFY SRR %p added (id %d, ui %x)\n",
3223 imm
, imm
->srr_id
, iocb
->u
.isp24
.srr_ui
);
3224 if (tgt
->imm_srr_id
== tgt
->ctio_srr_id
) {
3226 list_for_each_entry(sctio
, &tgt
->srr_ctio_list
,
3228 if (sctio
->srr_id
== imm
->srr_id
) {
3234 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf02f, "%s",
3235 "Scheduling srr work\n");
3236 schedule_work(&tgt
->srr_work
);
3238 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf030,
3239 "qla_target(%d): imm_srr_id "
3240 "== ctio_srr_id (%d), but there is no "
3241 "corresponding SRR CTIO, deleting IMM "
3242 "SRR %p\n", vha
->vp_idx
, tgt
->ctio_srr_id
,
3244 list_del(&imm
->srr_list_entry
);
3248 spin_unlock(&tgt
->srr_lock
);
3252 spin_unlock(&tgt
->srr_lock
);
3254 struct qla_tgt_srr_ctio
*ts
;
3256 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf069,
3257 "qla_target(%d): Unable to allocate SRR IMM "
3258 "entry, SRR request will be rejected\n", vha
->vp_idx
);
3260 /* IRQ is already OFF */
3261 spin_lock(&tgt
->srr_lock
);
3262 list_for_each_entry_safe(sctio
, ts
, &tgt
->srr_ctio_list
,
3264 if (sctio
->srr_id
== tgt
->imm_srr_id
) {
3265 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf031,
3266 "CTIO SRR %p deleted (id %d)\n",
3267 sctio
, sctio
->srr_id
);
3268 list_del(&sctio
->srr_list_entry
);
3269 qlt_send_term_exchange(vha
, sctio
->cmd
,
3270 &sctio
->cmd
->atio
, 1);
3274 spin_unlock(&tgt
->srr_lock
);
3281 qlt_send_notify_ack(vha
, iocb
, 0, 0, 0,
3282 NOTIFY_ACK_SRR_FLAGS_REJECT
,
3283 NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM
,
3284 NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL
);
3288 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3290 static void qlt_handle_imm_notify(struct scsi_qla_host
*vha
,
3291 struct imm_ntfy_from_isp
*iocb
)
3293 struct qla_hw_data
*ha
= vha
->hw
;
3294 uint32_t add_flags
= 0;
3295 int send_notify_ack
= 1;
3298 status
= le16_to_cpu(iocb
->u
.isp2x
.status
);
3300 case IMM_NTFY_LIP_RESET
:
3302 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf032,
3303 "qla_target(%d): LIP reset (loop %#x), subcode %x\n",
3304 vha
->vp_idx
, le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
3305 iocb
->u
.isp24
.status_subcode
);
3307 if (qlt_reset(vha
, iocb
, QLA_TGT_ABORT_ALL
) == 0)
3308 send_notify_ack
= 0;
3312 case IMM_NTFY_LIP_LINK_REINIT
:
3314 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
3315 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf033,
3316 "qla_target(%d): LINK REINIT (loop %#x, "
3317 "subcode %x)\n", vha
->vp_idx
,
3318 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
3319 iocb
->u
.isp24
.status_subcode
);
3320 if (tgt
->link_reinit_iocb_pending
) {
3321 qlt_send_notify_ack(vha
, &tgt
->link_reinit_iocb
,
3324 memcpy(&tgt
->link_reinit_iocb
, iocb
, sizeof(*iocb
));
3325 tgt
->link_reinit_iocb_pending
= 1;
3327 * QLogic requires to wait after LINK REINIT for possible
3328 * PDISC or ADISC ELS commands
3330 send_notify_ack
= 0;
3334 case IMM_NTFY_PORT_LOGOUT
:
3335 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf034,
3336 "qla_target(%d): Port logout (loop "
3337 "%#x, subcode %x)\n", vha
->vp_idx
,
3338 le16_to_cpu(iocb
->u
.isp24
.nport_handle
),
3339 iocb
->u
.isp24
.status_subcode
);
3341 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS_SESS
) == 0)
3342 send_notify_ack
= 0;
3343 /* The sessions will be cleared in the callback, if needed */
3346 case IMM_NTFY_GLBL_TPRLO
:
3347 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf035,
3348 "qla_target(%d): Global TPRLO (%x)\n", vha
->vp_idx
, status
);
3349 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
) == 0)
3350 send_notify_ack
= 0;
3351 /* The sessions will be cleared in the callback, if needed */
3354 case IMM_NTFY_PORT_CONFIG
:
3355 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf036,
3356 "qla_target(%d): Port config changed (%x)\n", vha
->vp_idx
,
3358 if (qlt_reset(vha
, iocb
, QLA_TGT_ABORT_ALL
) == 0)
3359 send_notify_ack
= 0;
3360 /* The sessions will be cleared in the callback, if needed */
3363 case IMM_NTFY_GLBL_LOGO
:
3364 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06a,
3365 "qla_target(%d): Link failure detected\n",
3367 /* I_T nexus loss */
3368 if (qlt_reset(vha
, iocb
, QLA_TGT_NEXUS_LOSS
) == 0)
3369 send_notify_ack
= 0;
3372 case IMM_NTFY_IOCB_OVERFLOW
:
3373 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06b,
3374 "qla_target(%d): Cannot provide requested "
3375 "capability (IOCB overflowed the immediate notify "
3376 "resource count)\n", vha
->vp_idx
);
3379 case IMM_NTFY_ABORT_TASK
:
3380 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf037,
3381 "qla_target(%d): Abort Task (S %08x I %#x -> "
3382 "L %#x)\n", vha
->vp_idx
,
3383 le16_to_cpu(iocb
->u
.isp2x
.seq_id
),
3384 GET_TARGET_ID(ha
, (struct atio_from_isp
*)iocb
),
3385 le16_to_cpu(iocb
->u
.isp2x
.lun
));
3386 if (qlt_abort_task(vha
, iocb
) == 0)
3387 send_notify_ack
= 0;
3390 case IMM_NTFY_RESOURCE
:
3391 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06c,
3392 "qla_target(%d): Out of resources, host %ld\n",
3393 vha
->vp_idx
, vha
->host_no
);
3396 case IMM_NTFY_MSG_RX
:
3397 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf038,
3398 "qla_target(%d): Immediate notify task %x\n",
3399 vha
->vp_idx
, iocb
->u
.isp2x
.task_flags
);
3400 if (qlt_handle_task_mgmt(vha
, iocb
) == 0)
3401 send_notify_ack
= 0;
3405 if (qlt_24xx_handle_els(vha
, iocb
) == 0)
3406 send_notify_ack
= 0;
3410 qlt_prepare_srr_imm(vha
, iocb
);
3411 send_notify_ack
= 0;
3415 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06d,
3416 "qla_target(%d): Received unknown immediate "
3417 "notify status %x\n", vha
->vp_idx
, status
);
3421 if (send_notify_ack
)
3422 qlt_send_notify_ack(vha
, iocb
, add_flags
, 0, 0, 0, 0, 0);
3426 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3427 * This function sends busy to ISP 2xxx or 24xx.
3429 static void qlt_send_busy(struct scsi_qla_host
*vha
,
3430 struct atio_from_isp
*atio
, uint16_t status
)
3432 struct ctio7_to_24xx
*ctio24
;
3433 struct qla_hw_data
*ha
= vha
->hw
;
3435 struct qla_tgt_sess
*sess
= NULL
;
3437 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
3438 atio
->u
.isp24
.fcp_hdr
.s_id
);
3440 qlt_send_term_exchange(vha
, NULL
, atio
, 1);
3443 /* Sending marker isn't necessary, since we called from ISR */
3445 pkt
= (request_t
*)qla2x00_alloc_iocbs(vha
, NULL
);
3447 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06e,
3448 "qla_target(%d): %s failed: unable to allocate "
3449 "request packet", vha
->vp_idx
, __func__
);
3453 pkt
->entry_count
= 1;
3454 pkt
->handle
= QLA_TGT_SKIP_HANDLE
| CTIO_COMPLETION_HANDLE_MARK
;
3456 ctio24
= (struct ctio7_to_24xx
*)pkt
;
3457 ctio24
->entry_type
= CTIO_TYPE7
;
3458 ctio24
->nport_handle
= sess
->loop_id
;
3459 ctio24
->timeout
= __constant_cpu_to_le16(QLA_TGT_TIMEOUT
);
3460 ctio24
->vp_index
= vha
->vp_idx
;
3461 ctio24
->initiator_id
[0] = atio
->u
.isp24
.fcp_hdr
.s_id
[2];
3462 ctio24
->initiator_id
[1] = atio
->u
.isp24
.fcp_hdr
.s_id
[1];
3463 ctio24
->initiator_id
[2] = atio
->u
.isp24
.fcp_hdr
.s_id
[0];
3464 ctio24
->exchange_addr
= atio
->u
.isp24
.exchange_addr
;
3465 ctio24
->u
.status1
.flags
= (atio
->u
.isp24
.attr
<< 9) |
3466 __constant_cpu_to_le16(
3467 CTIO7_FLAGS_STATUS_MODE_1
| CTIO7_FLAGS_SEND_STATUS
|
3468 CTIO7_FLAGS_DONT_RET_CTIO
);
3470 * CTIO from fw w/o se_cmd doesn't provide enough info to retry it,
3471 * if the explicit conformation is used.
3473 ctio24
->u
.status1
.ox_id
= swab16(atio
->u
.isp24
.fcp_hdr
.ox_id
);
3474 ctio24
->u
.status1
.scsi_status
= cpu_to_le16(status
);
3475 ctio24
->u
.status1
.residual
= get_unaligned((uint32_t *)
3476 &atio
->u
.isp24
.fcp_cmnd
.add_cdb
[
3477 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
]);
3478 if (ctio24
->u
.status1
.residual
!= 0)
3479 ctio24
->u
.status1
.scsi_status
|= SS_RESIDUAL_UNDER
;
3481 qla2x00_start_iocbs(vha
, vha
->req
);
3484 /* ha->hardware_lock supposed to be held on entry */
3485 /* called via callback from qla2xxx */
3486 static void qlt_24xx_atio_pkt(struct scsi_qla_host
*vha
,
3487 struct atio_from_isp
*atio
)
3489 struct qla_hw_data
*ha
= vha
->hw
;
3490 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
3493 if (unlikely(tgt
== NULL
)) {
3494 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf039,
3495 "ATIO pkt, but no tgt (ha %p)", ha
);
3498 ql_dbg(ql_dbg_tgt
, vha
, 0xe02c,
3499 "qla_target(%d): ATIO pkt %p: type %02x count %02x",
3500 vha
->vp_idx
, atio
, atio
->u
.raw
.entry_type
,
3501 atio
->u
.raw
.entry_count
);
3503 * In tgt_stop mode we also should allow all requests to pass.
3504 * Otherwise, some commands can stuck.
3507 tgt
->irq_cmd_count
++;
3509 switch (atio
->u
.raw
.entry_type
) {
3511 ql_dbg(ql_dbg_tgt
, vha
, 0xe02d,
3512 "ATIO_TYPE7 instance %d, lun %Lx, read/write %d/%d, "
3513 "add_cdb_len %d, data_length %04x, s_id %x:%x:%x\n",
3514 vha
->vp_idx
, atio
->u
.isp24
.fcp_cmnd
.lun
,
3515 atio
->u
.isp24
.fcp_cmnd
.rddata
,
3516 atio
->u
.isp24
.fcp_cmnd
.wrdata
,
3517 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
,
3518 be32_to_cpu(get_unaligned((uint32_t *)
3519 &atio
->u
.isp24
.fcp_cmnd
.add_cdb
[
3520 atio
->u
.isp24
.fcp_cmnd
.add_cdb_len
])),
3521 atio
->u
.isp24
.fcp_hdr
.s_id
[0],
3522 atio
->u
.isp24
.fcp_hdr
.s_id
[1],
3523 atio
->u
.isp24
.fcp_hdr
.s_id
[2]);
3525 if (unlikely(atio
->u
.isp24
.exchange_addr
==
3526 ATIO_EXCHANGE_ADDRESS_UNKNOWN
)) {
3527 ql_dbg(ql_dbg_tgt
, vha
, 0xe058,
3528 "qla_target(%d): ATIO_TYPE7 "
3529 "received with UNKNOWN exchange address, "
3530 "sending QUEUE_FULL\n", vha
->vp_idx
);
3531 qlt_send_busy(vha
, atio
, SAM_STAT_TASK_SET_FULL
);
3534 if (likely(atio
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
== 0))
3535 rc
= qlt_handle_cmd_for_atio(vha
, atio
);
3537 rc
= qlt_handle_task_mgmt(vha
, atio
);
3538 if (unlikely(rc
!= 0)) {
3540 #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */
3541 qlt_send_busy(vha
, atio
, SAM_STAT_BUSY
);
3543 qlt_send_term_exchange(vha
, NULL
, atio
, 1);
3546 if (tgt
->tgt_stop
) {
3547 ql_dbg(ql_dbg_tgt
, vha
, 0xe059,
3548 "qla_target: Unable to send "
3549 "command to target for req, "
3552 ql_dbg(ql_dbg_tgt
, vha
, 0xe05a,
3553 "qla_target(%d): Unable to send "
3554 "command to target, sending BUSY "
3555 "status.\n", vha
->vp_idx
);
3556 qlt_send_busy(vha
, atio
, SAM_STAT_BUSY
);
3562 case IMMED_NOTIFY_TYPE
:
3564 if (unlikely(atio
->u
.isp2x
.entry_status
!= 0)) {
3565 ql_dbg(ql_dbg_tgt
, vha
, 0xe05b,
3566 "qla_target(%d): Received ATIO packet %x "
3567 "with error status %x\n", vha
->vp_idx
,
3568 atio
->u
.raw
.entry_type
,
3569 atio
->u
.isp2x
.entry_status
);
3572 ql_dbg(ql_dbg_tgt
, vha
, 0xe02e, "%s", "IMMED_NOTIFY ATIO");
3573 qlt_handle_imm_notify(vha
, (struct imm_ntfy_from_isp
*)atio
);
3578 ql_dbg(ql_dbg_tgt
, vha
, 0xe05c,
3579 "qla_target(%d): Received unknown ATIO atio "
3580 "type %x\n", vha
->vp_idx
, atio
->u
.raw
.entry_type
);
3584 tgt
->irq_cmd_count
--;
3587 /* ha->hardware_lock supposed to be held on entry */
3588 /* called via callback from qla2xxx */
3589 static void qlt_response_pkt(struct scsi_qla_host
*vha
, response_t
*pkt
)
3591 struct qla_hw_data
*ha
= vha
->hw
;
3592 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
3594 if (unlikely(tgt
== NULL
)) {
3595 ql_dbg(ql_dbg_tgt
, vha
, 0xe05d,
3596 "qla_target(%d): Response pkt %x received, but no "
3597 "tgt (ha %p)\n", vha
->vp_idx
, pkt
->entry_type
, ha
);
3601 ql_dbg(ql_dbg_tgt
, vha
, 0xe02f,
3602 "qla_target(%d): response pkt %p: T %02x C %02x S %02x "
3603 "handle %#x\n", vha
->vp_idx
, pkt
, pkt
->entry_type
,
3604 pkt
->entry_count
, pkt
->entry_status
, pkt
->handle
);
3607 * In tgt_stop mode we also should allow all requests to pass.
3608 * Otherwise, some commands can stuck.
3611 tgt
->irq_cmd_count
++;
3613 switch (pkt
->entry_type
) {
3616 struct ctio7_from_24xx
*entry
= (struct ctio7_from_24xx
*)pkt
;
3617 ql_dbg(ql_dbg_tgt
, vha
, 0xe030, "CTIO_TYPE7: instance %d\n",
3619 qlt_do_ctio_completion(vha
, entry
->handle
,
3620 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
3625 case ACCEPT_TGT_IO_TYPE
:
3627 struct atio_from_isp
*atio
= (struct atio_from_isp
*)pkt
;
3629 ql_dbg(ql_dbg_tgt
, vha
, 0xe031,
3630 "ACCEPT_TGT_IO instance %d status %04x "
3631 "lun %04x read/write %d data_length %04x "
3632 "target_id %02x rx_id %04x\n ", vha
->vp_idx
,
3633 le16_to_cpu(atio
->u
.isp2x
.status
),
3634 le16_to_cpu(atio
->u
.isp2x
.lun
),
3635 atio
->u
.isp2x
.execution_codes
,
3636 le32_to_cpu(atio
->u
.isp2x
.data_length
), GET_TARGET_ID(ha
,
3637 atio
), atio
->u
.isp2x
.rx_id
);
3638 if (atio
->u
.isp2x
.status
!=
3639 __constant_cpu_to_le16(ATIO_CDB_VALID
)) {
3640 ql_dbg(ql_dbg_tgt
, vha
, 0xe05e,
3641 "qla_target(%d): ATIO with error "
3642 "status %x received\n", vha
->vp_idx
,
3643 le16_to_cpu(atio
->u
.isp2x
.status
));
3646 ql_dbg(ql_dbg_tgt
, vha
, 0xe032,
3647 "FCP CDB: 0x%02x, sizeof(cdb): %lu",
3648 atio
->u
.isp2x
.cdb
[0], (unsigned long
3649 int)sizeof(atio
->u
.isp2x
.cdb
));
3651 rc
= qlt_handle_cmd_for_atio(vha
, atio
);
3652 if (unlikely(rc
!= 0)) {
3654 #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */
3655 qlt_send_busy(vha
, atio
, 0);
3657 qlt_send_term_exchange(vha
, NULL
, atio
, 1);
3660 if (tgt
->tgt_stop
) {
3661 ql_dbg(ql_dbg_tgt
, vha
, 0xe05f,
3662 "qla_target: Unable to send "
3663 "command to target, sending TERM "
3664 "EXCHANGE for rsp\n");
3665 qlt_send_term_exchange(vha
, NULL
,
3668 ql_dbg(ql_dbg_tgt
, vha
, 0xe060,
3669 "qla_target(%d): Unable to send "
3670 "command to target, sending BUSY "
3671 "status\n", vha
->vp_idx
);
3672 qlt_send_busy(vha
, atio
, 0);
3679 case CONTINUE_TGT_IO_TYPE
:
3681 struct ctio_to_2xxx
*entry
= (struct ctio_to_2xxx
*)pkt
;
3682 ql_dbg(ql_dbg_tgt
, vha
, 0xe033,
3683 "CONTINUE_TGT_IO: instance %d\n", vha
->vp_idx
);
3684 qlt_do_ctio_completion(vha
, entry
->handle
,
3685 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
3692 struct ctio_to_2xxx
*entry
= (struct ctio_to_2xxx
*)pkt
;
3693 ql_dbg(ql_dbg_tgt
, vha
, 0xe034, "CTIO_A64: instance %d\n",
3695 qlt_do_ctio_completion(vha
, entry
->handle
,
3696 le16_to_cpu(entry
->status
)|(pkt
->entry_status
<< 16),
3701 case IMMED_NOTIFY_TYPE
:
3702 ql_dbg(ql_dbg_tgt
, vha
, 0xe035, "%s", "IMMED_NOTIFY\n");
3703 qlt_handle_imm_notify(vha
, (struct imm_ntfy_from_isp
*)pkt
);
3706 case NOTIFY_ACK_TYPE
:
3707 if (tgt
->notify_ack_expected
> 0) {
3708 struct nack_to_isp
*entry
= (struct nack_to_isp
*)pkt
;
3709 ql_dbg(ql_dbg_tgt
, vha
, 0xe036,
3710 "NOTIFY_ACK seq %08x status %x\n",
3711 le16_to_cpu(entry
->u
.isp2x
.seq_id
),
3712 le16_to_cpu(entry
->u
.isp2x
.status
));
3713 tgt
->notify_ack_expected
--;
3714 if (entry
->u
.isp2x
.status
!=
3715 __constant_cpu_to_le16(NOTIFY_ACK_SUCCESS
)) {
3716 ql_dbg(ql_dbg_tgt
, vha
, 0xe061,
3717 "qla_target(%d): NOTIFY_ACK "
3718 "failed %x\n", vha
->vp_idx
,
3719 le16_to_cpu(entry
->u
.isp2x
.status
));
3722 ql_dbg(ql_dbg_tgt
, vha
, 0xe062,
3723 "qla_target(%d): Unexpected NOTIFY_ACK received\n",
3728 case ABTS_RECV_24XX
:
3729 ql_dbg(ql_dbg_tgt
, vha
, 0xe037,
3730 "ABTS_RECV_24XX: instance %d\n", vha
->vp_idx
);
3731 qlt_24xx_handle_abts(vha
, (struct abts_recv_from_24xx
*)pkt
);
3734 case ABTS_RESP_24XX
:
3735 if (tgt
->abts_resp_expected
> 0) {
3736 struct abts_resp_from_24xx_fw
*entry
=
3737 (struct abts_resp_from_24xx_fw
*)pkt
;
3738 ql_dbg(ql_dbg_tgt
, vha
, 0xe038,
3739 "ABTS_RESP_24XX: compl_status %x\n",
3740 entry
->compl_status
);
3741 tgt
->abts_resp_expected
--;
3742 if (le16_to_cpu(entry
->compl_status
) !=
3743 ABTS_RESP_COMPL_SUCCESS
) {
3744 if ((entry
->error_subcode1
== 0x1E) &&
3745 (entry
->error_subcode2
== 0)) {
3747 * We've got a race here: aborted
3748 * exchange not terminated, i.e.
3749 * response for the aborted command was
3750 * sent between the abort request was
3751 * received and processed.
3752 * Unfortunately, the firmware has a
3753 * silly requirement that all aborted
3754 * exchanges must be explicitely
3755 * terminated, otherwise it refuses to
3756 * send responses for the abort
3757 * requests. So, we have to
3758 * (re)terminate the exchange and retry
3759 * the abort response.
3761 qlt_24xx_retry_term_exchange(vha
,
3764 ql_dbg(ql_dbg_tgt
, vha
, 0xe063,
3765 "qla_target(%d): ABTS_RESP_24XX "
3766 "failed %x (subcode %x:%x)",
3767 vha
->vp_idx
, entry
->compl_status
,
3768 entry
->error_subcode1
,
3769 entry
->error_subcode2
);
3772 ql_dbg(ql_dbg_tgt
, vha
, 0xe064,
3773 "qla_target(%d): Unexpected ABTS_RESP_24XX "
3774 "received\n", vha
->vp_idx
);
3779 ql_dbg(ql_dbg_tgt
, vha
, 0xe065,
3780 "qla_target(%d): Received unknown response pkt "
3781 "type %x\n", vha
->vp_idx
, pkt
->entry_type
);
3785 tgt
->irq_cmd_count
--;
3789 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
3791 void qlt_async_event(uint16_t code
, struct scsi_qla_host
*vha
,
3794 struct qla_hw_data
*ha
= vha
->hw
;
3795 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
3798 ql_dbg(ql_dbg_tgt
, vha
, 0xe039,
3799 "scsi(%ld): ha state %d init_done %d oper_mode %d topo %d\n",
3800 vha
->host_no
, atomic_read(&vha
->loop_state
), vha
->flags
.init_done
,
3801 ha
->operating_mode
, ha
->current_topology
);
3803 if (!ha
->tgt
.tgt_ops
)
3806 if (unlikely(tgt
== NULL
)) {
3807 ql_dbg(ql_dbg_tgt
, vha
, 0xe03a,
3808 "ASYNC EVENT %#x, but no tgt (ha %p)\n", code
, ha
);
3812 if (((code
== MBA_POINT_TO_POINT
) || (code
== MBA_CHG_IN_CONNECTION
)) &&
3816 * In tgt_stop mode we also should allow all requests to pass.
3817 * Otherwise, some commands can stuck.
3820 tgt
->irq_cmd_count
++;
3823 case MBA_RESET
: /* Reset */
3824 case MBA_SYSTEM_ERR
: /* System Error */
3825 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
3826 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
3827 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03a,
3828 "qla_target(%d): System error async event %#x "
3829 "occurred", vha
->vp_idx
, code
);
3831 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up. */
3832 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3837 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03b,
3838 "qla_target(%d): Async LOOP_UP occurred "
3839 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
,
3840 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
3841 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
3842 if (tgt
->link_reinit_iocb_pending
) {
3843 qlt_send_notify_ack(vha
, (void *)&tgt
->link_reinit_iocb
,
3845 tgt
->link_reinit_iocb_pending
= 0;
3850 case MBA_LIP_OCCURRED
:
3853 case MBA_RSCN_UPDATE
:
3854 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03c,
3855 "qla_target(%d): Async event %#x occurred "
3856 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
, code
,
3857 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
3858 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
3861 case MBA_PORT_UPDATE
:
3862 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03d,
3863 "qla_target(%d): Port update async event %#x "
3864 "occurred: updating the ports database (m[0]=%x, m[1]=%x, "
3865 "m[2]=%x, m[3]=%x)", vha
->vp_idx
, code
,
3866 le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
3867 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
3869 login_code
= le16_to_cpu(mailbox
[2]);
3870 if (login_code
== 0x4)
3871 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03e,
3872 "Async MB 2: Got PLOGI Complete\n");
3873 else if (login_code
== 0x7)
3874 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf03f,
3875 "Async MB 2: Port Logged Out\n");
3879 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf040,
3880 "qla_target(%d): Async event %#x occurred: "
3881 "ignore (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha
->vp_idx
,
3882 code
, le16_to_cpu(mailbox
[0]), le16_to_cpu(mailbox
[1]),
3883 le16_to_cpu(mailbox
[2]), le16_to_cpu(mailbox
[3]));
3887 tgt
->irq_cmd_count
--;
3890 static fc_port_t
*qlt_get_port_database(struct scsi_qla_host
*vha
,
3896 fcport
= kzalloc(sizeof(*fcport
), GFP_KERNEL
);
3898 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf06f,
3899 "qla_target(%d): Allocation of tmp FC port failed",
3904 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf041, "loop_id %d", loop_id
);
3906 fcport
->loop_id
= loop_id
;
3908 rc
= qla2x00_get_port_database(vha
, fcport
, 0);
3909 if (rc
!= QLA_SUCCESS
) {
3910 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf070,
3911 "qla_target(%d): Failed to retrieve fcport "
3912 "information -- get_port_database() returned %x "
3913 "(loop_id=0x%04x)", vha
->vp_idx
, rc
, loop_id
);
3921 /* Must be called under tgt_mutex */
3922 static struct qla_tgt_sess
*qlt_make_local_sess(struct scsi_qla_host
*vha
,
3925 struct qla_tgt_sess
*sess
= NULL
;
3926 fc_port_t
*fcport
= NULL
;
3927 int rc
, global_resets
;
3928 uint16_t loop_id
= 0;
3932 atomic_read(&vha
->vha_tgt
.qla_tgt
->tgt_global_resets_count
);
3934 rc
= qla24xx_get_loop_id(vha
, s_id
, &loop_id
);
3936 if ((s_id
[0] == 0xFF) &&
3937 (s_id
[1] == 0xFC)) {
3939 * This is Domain Controller, so it should be
3940 * OK to drop SCSI commands from it.
3942 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf042,
3943 "Unable to find initiator with S_ID %x:%x:%x",
3944 s_id
[0], s_id
[1], s_id
[2]);
3946 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf071,
3947 "qla_target(%d): Unable to find "
3948 "initiator with S_ID %x:%x:%x",
3949 vha
->vp_idx
, s_id
[0], s_id
[1],
3954 fcport
= qlt_get_port_database(vha
, loop_id
);
3958 if (global_resets
!=
3959 atomic_read(&vha
->vha_tgt
.qla_tgt
->tgt_global_resets_count
)) {
3960 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf043,
3961 "qla_target(%d): global reset during session discovery "
3962 "(counter was %d, new %d), retrying", vha
->vp_idx
,
3964 atomic_read(&vha
->vha_tgt
.
3965 qla_tgt
->tgt_global_resets_count
));
3969 sess
= qlt_create_sess(vha
, fcport
, true);
3975 static void qlt_abort_work(struct qla_tgt
*tgt
,
3976 struct qla_tgt_sess_work_param
*prm
)
3978 struct scsi_qla_host
*vha
= tgt
->vha
;
3979 struct qla_hw_data
*ha
= vha
->hw
;
3980 struct qla_tgt_sess
*sess
= NULL
;
3981 unsigned long flags
;
3986 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3991 s_id
[0] = prm
->abts
.fcp_hdr_le
.s_id
[2];
3992 s_id
[1] = prm
->abts
.fcp_hdr_le
.s_id
[1];
3993 s_id
[2] = prm
->abts
.fcp_hdr_le
.s_id
[0];
3995 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
,
3996 (unsigned char *)&be_s_id
);
3998 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4000 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
4001 sess
= qlt_make_local_sess(vha
, s_id
);
4002 /* sess has got an extra creation ref */
4003 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
4005 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4009 kref_get(&sess
->se_sess
->sess_kref
);
4015 rc
= __qlt_24xx_handle_abts(vha
, &prm
->abts
, sess
);
4019 ha
->tgt
.tgt_ops
->put_sess(sess
);
4020 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4024 qlt_24xx_send_abts_resp(vha
, &prm
->abts
, FCP_TMF_REJECTED
, false);
4026 ha
->tgt
.tgt_ops
->put_sess(sess
);
4027 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4030 static void qlt_tmr_work(struct qla_tgt
*tgt
,
4031 struct qla_tgt_sess_work_param
*prm
)
4033 struct atio_from_isp
*a
= &prm
->tm_iocb2
;
4034 struct scsi_qla_host
*vha
= tgt
->vha
;
4035 struct qla_hw_data
*ha
= vha
->hw
;
4036 struct qla_tgt_sess
*sess
= NULL
;
4037 unsigned long flags
;
4038 uint8_t *s_id
= NULL
; /* to hide compiler warnings */
4040 uint32_t lun
, unpacked_lun
;
4044 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4049 s_id
= prm
->tm_iocb2
.u
.isp24
.fcp_hdr
.s_id
;
4050 sess
= ha
->tgt
.tgt_ops
->find_sess_by_s_id(vha
, s_id
);
4052 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4054 mutex_lock(&vha
->vha_tgt
.tgt_mutex
);
4055 sess
= qlt_make_local_sess(vha
, s_id
);
4056 /* sess has got an extra creation ref */
4057 mutex_unlock(&vha
->vha_tgt
.tgt_mutex
);
4059 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4063 kref_get(&sess
->se_sess
->sess_kref
);
4067 lun
= a
->u
.isp24
.fcp_cmnd
.lun
;
4068 lun_size
= sizeof(lun
);
4069 fn
= a
->u
.isp24
.fcp_cmnd
.task_mgmt_flags
;
4070 unpacked_lun
= scsilun_to_int((struct scsi_lun
*)&lun
);
4072 rc
= qlt_issue_task_mgmt(sess
, unpacked_lun
, fn
, iocb
, 0);
4076 ha
->tgt
.tgt_ops
->put_sess(sess
);
4077 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4081 qlt_send_term_exchange(vha
, NULL
, &prm
->tm_iocb2
, 1);
4083 ha
->tgt
.tgt_ops
->put_sess(sess
);
4084 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4087 static void qlt_sess_work_fn(struct work_struct
*work
)
4089 struct qla_tgt
*tgt
= container_of(work
, struct qla_tgt
, sess_work
);
4090 struct scsi_qla_host
*vha
= tgt
->vha
;
4091 unsigned long flags
;
4093 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf000, "Sess work (tgt %p)", tgt
);
4095 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
4096 while (!list_empty(&tgt
->sess_works_list
)) {
4097 struct qla_tgt_sess_work_param
*prm
= list_entry(
4098 tgt
->sess_works_list
.next
, typeof(*prm
),
4099 sess_works_list_entry
);
4102 * This work can be scheduled on several CPUs at time, so we
4103 * must delete the entry to eliminate double processing
4105 list_del(&prm
->sess_works_list_entry
);
4107 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
4109 switch (prm
->type
) {
4110 case QLA_TGT_SESS_WORK_ABORT
:
4111 qlt_abort_work(tgt
, prm
);
4113 case QLA_TGT_SESS_WORK_TM
:
4114 qlt_tmr_work(tgt
, prm
);
4121 spin_lock_irqsave(&tgt
->sess_work_lock
, flags
);
4125 spin_unlock_irqrestore(&tgt
->sess_work_lock
, flags
);
4128 /* Must be called under tgt_host_action_mutex */
4129 int qlt_add_target(struct qla_hw_data
*ha
, struct scsi_qla_host
*base_vha
)
4131 struct qla_tgt
*tgt
;
4133 if (!QLA_TGT_MODE_ENABLED())
4136 if (!IS_TGT_MODE_CAPABLE(ha
)) {
4137 ql_log(ql_log_warn
, base_vha
, 0xe070,
4138 "This adapter does not support target mode.\n");
4142 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe03b,
4143 "Registering target for host %ld(%p).\n", base_vha
->host_no
, ha
);
4145 BUG_ON(base_vha
->vha_tgt
.qla_tgt
!= NULL
);
4147 tgt
= kzalloc(sizeof(struct qla_tgt
), GFP_KERNEL
);
4149 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe066,
4150 "Unable to allocate struct qla_tgt\n");
4154 if (!(base_vha
->host
->hostt
->supported_mode
& MODE_TARGET
))
4155 base_vha
->host
->hostt
->supported_mode
|= MODE_TARGET
;
4158 tgt
->vha
= base_vha
;
4159 init_waitqueue_head(&tgt
->waitQ
);
4160 INIT_LIST_HEAD(&tgt
->sess_list
);
4161 INIT_LIST_HEAD(&tgt
->del_sess_list
);
4162 INIT_DELAYED_WORK(&tgt
->sess_del_work
,
4163 (void (*)(struct work_struct
*))qlt_del_sess_work_fn
);
4164 spin_lock_init(&tgt
->sess_work_lock
);
4165 INIT_WORK(&tgt
->sess_work
, qlt_sess_work_fn
);
4166 INIT_LIST_HEAD(&tgt
->sess_works_list
);
4167 spin_lock_init(&tgt
->srr_lock
);
4168 INIT_LIST_HEAD(&tgt
->srr_ctio_list
);
4169 INIT_LIST_HEAD(&tgt
->srr_imm_list
);
4170 INIT_WORK(&tgt
->srr_work
, qlt_handle_srr_work
);
4171 atomic_set(&tgt
->tgt_global_resets_count
, 0);
4173 base_vha
->vha_tgt
.qla_tgt
= tgt
;
4175 ql_dbg(ql_dbg_tgt
, base_vha
, 0xe067,
4176 "qla_target(%d): using 64 Bit PCI addressing",
4178 tgt
->tgt_enable_64bit_addr
= 1;
4180 tgt
->sg_tablesize
= QLA_TGT_MAX_SG_24XX(base_vha
->req
->length
- 3);
4181 tgt
->datasegs_per_cmd
= QLA_TGT_DATASEGS_PER_CMD_24XX
;
4182 tgt
->datasegs_per_cont
= QLA_TGT_DATASEGS_PER_CONT_24XX
;
4184 mutex_lock(&qla_tgt_mutex
);
4185 list_add_tail(&tgt
->tgt_list_entry
, &qla_tgt_glist
);
4186 mutex_unlock(&qla_tgt_mutex
);
4191 /* Must be called under tgt_host_action_mutex */
4192 int qlt_remove_target(struct qla_hw_data
*ha
, struct scsi_qla_host
*vha
)
4194 if (!vha
->vha_tgt
.qla_tgt
)
4197 mutex_lock(&qla_tgt_mutex
);
4198 list_del(&vha
->vha_tgt
.qla_tgt
->tgt_list_entry
);
4199 mutex_unlock(&qla_tgt_mutex
);
4201 ql_dbg(ql_dbg_tgt
, vha
, 0xe03c, "Unregistering target for host %ld(%p)",
4203 qlt_release(vha
->vha_tgt
.qla_tgt
);
4208 static void qlt_lport_dump(struct scsi_qla_host
*vha
, u64 wwpn
,
4213 pr_debug("qla2xxx HW vha->node_name: ");
4214 for (i
= 0; i
< WWN_SIZE
; i
++)
4215 pr_debug("%02x ", vha
->node_name
[i
]);
4217 pr_debug("qla2xxx HW vha->port_name: ");
4218 for (i
= 0; i
< WWN_SIZE
; i
++)
4219 pr_debug("%02x ", vha
->port_name
[i
]);
4222 pr_debug("qla2xxx passed configfs WWPN: ");
4223 put_unaligned_be64(wwpn
, b
);
4224 for (i
= 0; i
< WWN_SIZE
; i
++)
4225 pr_debug("%02x ", b
[i
]);
4230 * qla_tgt_lport_register - register lport with external module
4232 * @qla_tgt_ops: Pointer for tcm_qla2xxx qla_tgt_ops
4233 * @wwpn: Passwd FC target WWPN
4234 * @callback: lport initialization callback for tcm_qla2xxx code
4235 * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data
4237 int qlt_lport_register(void *target_lport_ptr
, u64 phys_wwpn
,
4238 u64 npiv_wwpn
, u64 npiv_wwnn
,
4239 int (*callback
)(struct scsi_qla_host
*, void *, u64
, u64
))
4241 struct qla_tgt
*tgt
;
4242 struct scsi_qla_host
*vha
;
4243 struct qla_hw_data
*ha
;
4244 struct Scsi_Host
*host
;
4245 unsigned long flags
;
4249 mutex_lock(&qla_tgt_mutex
);
4250 list_for_each_entry(tgt
, &qla_tgt_glist
, tgt_list_entry
) {
4258 if (!(host
->hostt
->supported_mode
& MODE_TARGET
))
4261 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4262 if ((!npiv_wwpn
|| !npiv_wwnn
) && host
->active_mode
& MODE_TARGET
) {
4263 pr_debug("MODE_TARGET already active on qla2xxx(%d)\n",
4265 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4268 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4270 if (!scsi_host_get(host
)) {
4271 ql_dbg(ql_dbg_tgt
, vha
, 0xe068,
4272 "Unable to scsi_host_get() for"
4273 " qla2xxx scsi_host\n");
4276 qlt_lport_dump(vha
, phys_wwpn
, b
);
4278 if (memcmp(vha
->port_name
, b
, WWN_SIZE
)) {
4279 scsi_host_put(host
);
4282 mutex_unlock(&qla_tgt_mutex
);
4284 rc
= (*callback
)(vha
, target_lport_ptr
, npiv_wwpn
, npiv_wwnn
);
4286 scsi_host_put(host
);
4290 mutex_unlock(&qla_tgt_mutex
);
4294 EXPORT_SYMBOL(qlt_lport_register
);
4297 * qla_tgt_lport_deregister - Degister lport
4299 * @vha: Registered scsi_qla_host pointer
4301 void qlt_lport_deregister(struct scsi_qla_host
*vha
)
4303 struct qla_hw_data
*ha
= vha
->hw
;
4304 struct Scsi_Host
*sh
= vha
->host
;
4306 * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data
4308 vha
->vha_tgt
.target_lport_ptr
= NULL
;
4309 ha
->tgt
.tgt_ops
= NULL
;
4311 * Release the Scsi_Host reference for the underlying qla2xxx host
4315 EXPORT_SYMBOL(qlt_lport_deregister
);
4317 /* Must be called under HW lock */
4318 void qlt_set_mode(struct scsi_qla_host
*vha
)
4320 struct qla_hw_data
*ha
= vha
->hw
;
4322 switch (ql2x_ini_mode
) {
4323 case QLA2XXX_INI_MODE_DISABLED
:
4324 case QLA2XXX_INI_MODE_EXCLUSIVE
:
4325 vha
->host
->active_mode
= MODE_TARGET
;
4327 case QLA2XXX_INI_MODE_ENABLED
:
4328 vha
->host
->active_mode
|= MODE_TARGET
;
4334 if (ha
->tgt
.ini_mode_force_reverse
)
4335 qla_reverse_ini_mode(vha
);
4338 /* Must be called under HW lock */
4339 void qlt_clear_mode(struct scsi_qla_host
*vha
)
4341 struct qla_hw_data
*ha
= vha
->hw
;
4343 switch (ql2x_ini_mode
) {
4344 case QLA2XXX_INI_MODE_DISABLED
:
4345 vha
->host
->active_mode
= MODE_UNKNOWN
;
4347 case QLA2XXX_INI_MODE_EXCLUSIVE
:
4348 vha
->host
->active_mode
= MODE_INITIATOR
;
4350 case QLA2XXX_INI_MODE_ENABLED
:
4351 vha
->host
->active_mode
&= ~MODE_TARGET
;
4357 if (ha
->tgt
.ini_mode_force_reverse
)
4358 qla_reverse_ini_mode(vha
);
4362 * qla_tgt_enable_vha - NO LOCK HELD
4364 * host_reset, bring up w/ Target Mode Enabled
4367 qlt_enable_vha(struct scsi_qla_host
*vha
)
4369 struct qla_hw_data
*ha
= vha
->hw
;
4370 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4371 unsigned long flags
;
4372 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
4375 ql_dbg(ql_dbg_tgt
, vha
, 0xe069,
4376 "Unable to locate qla_tgt pointer from"
4377 " struct qla_hw_data\n");
4382 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4383 tgt
->tgt_stopped
= 0;
4385 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4388 qla24xx_disable_vp(vha
);
4389 qla24xx_enable_vp(vha
);
4391 set_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
);
4392 qla2xxx_wake_dpc(base_vha
);
4393 qla2x00_wait_for_hba_online(base_vha
);
4396 EXPORT_SYMBOL(qlt_enable_vha
);
4399 * qla_tgt_disable_vha - NO LOCK HELD
4401 * Disable Target Mode and reset the adapter
4404 qlt_disable_vha(struct scsi_qla_host
*vha
)
4406 struct qla_hw_data
*ha
= vha
->hw
;
4407 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
4408 unsigned long flags
;
4411 ql_dbg(ql_dbg_tgt
, vha
, 0xe06a,
4412 "Unable to locate qla_tgt pointer from"
4413 " struct qla_hw_data\n");
4418 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4419 qlt_clear_mode(vha
);
4420 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4422 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
4423 qla2xxx_wake_dpc(vha
);
4424 qla2x00_wait_for_hba_online(vha
);
4428 * Called from qla_init.c:qla24xx_vport_create() contex to setup
4429 * the target mode specific struct scsi_qla_host and struct qla_hw_data
4433 qlt_vport_create(struct scsi_qla_host
*vha
, struct qla_hw_data
*ha
)
4435 if (!qla_tgt_mode_enabled(vha
))
4438 vha
->vha_tgt
.qla_tgt
= NULL
;
4440 mutex_init(&vha
->vha_tgt
.tgt_mutex
);
4441 mutex_init(&vha
->vha_tgt
.tgt_host_action_mutex
);
4443 qlt_clear_mode(vha
);
4446 * NOTE: Currently the value is kept the same for <24xx and
4447 * >=24xx ISPs. If it is necessary to change it,
4448 * the check should be added for specific ISPs,
4449 * assigning the value appropriately.
4451 ha
->tgt
.atio_q_length
= ATIO_ENTRY_CNT_24XX
;
4453 qlt_add_target(ha
, vha
);
4457 qlt_rff_id(struct scsi_qla_host
*vha
, struct ct_sns_req
*ct_req
)
4460 * FC-4 Feature bit 0 indicates target functionality to the name server.
4462 if (qla_tgt_mode_enabled(vha
)) {
4463 if (qla_ini_mode_enabled(vha
))
4464 ct_req
->req
.rff_id
.fc4_feature
= BIT_0
| BIT_1
;
4466 ct_req
->req
.rff_id
.fc4_feature
= BIT_0
;
4467 } else if (qla_ini_mode_enabled(vha
)) {
4468 ct_req
->req
.rff_id
.fc4_feature
= BIT_1
;
4473 * qlt_init_atio_q_entries() - Initializes ATIO queue entries.
4476 * Beginning of ATIO ring has initialization control block already built
4477 * by nvram config routine.
4479 * Returns 0 on success.
4482 qlt_init_atio_q_entries(struct scsi_qla_host
*vha
)
4484 struct qla_hw_data
*ha
= vha
->hw
;
4486 struct atio_from_isp
*pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring
;
4488 if (!qla_tgt_mode_enabled(vha
))
4491 for (cnt
= 0; cnt
< ha
->tgt
.atio_q_length
; cnt
++) {
4492 pkt
->u
.raw
.signature
= ATIO_PROCESSED
;
4499 * qlt_24xx_process_atio_queue() - Process ATIO queue entries.
4500 * @ha: SCSI driver HA context
4503 qlt_24xx_process_atio_queue(struct scsi_qla_host
*vha
)
4505 struct qla_hw_data
*ha
= vha
->hw
;
4506 struct atio_from_isp
*pkt
;
4509 if (!vha
->flags
.online
)
4512 while (ha
->tgt
.atio_ring_ptr
->signature
!= ATIO_PROCESSED
) {
4513 pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring_ptr
;
4514 cnt
= pkt
->u
.raw
.entry_count
;
4516 qlt_24xx_atio_pkt_all_vps(vha
, (struct atio_from_isp
*)pkt
);
4518 for (i
= 0; i
< cnt
; i
++) {
4519 ha
->tgt
.atio_ring_index
++;
4520 if (ha
->tgt
.atio_ring_index
== ha
->tgt
.atio_q_length
) {
4521 ha
->tgt
.atio_ring_index
= 0;
4522 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
4524 ha
->tgt
.atio_ring_ptr
++;
4526 pkt
->u
.raw
.signature
= ATIO_PROCESSED
;
4527 pkt
= (struct atio_from_isp
*)ha
->tgt
.atio_ring_ptr
;
4532 /* Adjust ring index */
4533 WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha
), ha
->tgt
.atio_ring_index
);
4537 qlt_24xx_config_rings(struct scsi_qla_host
*vha
)
4539 struct qla_hw_data
*ha
= vha
->hw
;
4540 if (!QLA_TGT_MODE_ENABLED())
4543 WRT_REG_DWORD(ISP_ATIO_Q_IN(vha
), 0);
4544 WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha
), 0);
4545 RD_REG_DWORD(ISP_ATIO_Q_OUT(vha
));
4547 if (IS_ATIO_MSIX_CAPABLE(ha
)) {
4548 struct qla_msix_entry
*msix
= &ha
->msix_entries
[2];
4549 struct init_cb_24xx
*icb
= (struct init_cb_24xx
*)ha
->init_cb
;
4551 icb
->msix_atio
= cpu_to_le16(msix
->entry
);
4552 ql_dbg(ql_dbg_init
, vha
, 0xf072,
4553 "Registering ICB vector 0x%x for atio que.\n",
4559 qlt_24xx_config_nvram_stage1(struct scsi_qla_host
*vha
, struct nvram_24xx
*nv
)
4561 struct qla_hw_data
*ha
= vha
->hw
;
4563 if (qla_tgt_mode_enabled(vha
)) {
4564 if (!ha
->tgt
.saved_set
) {
4565 /* We save only once */
4566 ha
->tgt
.saved_exchange_count
= nv
->exchange_count
;
4567 ha
->tgt
.saved_firmware_options_1
=
4568 nv
->firmware_options_1
;
4569 ha
->tgt
.saved_firmware_options_2
=
4570 nv
->firmware_options_2
;
4571 ha
->tgt
.saved_firmware_options_3
=
4572 nv
->firmware_options_3
;
4573 ha
->tgt
.saved_set
= 1;
4576 nv
->exchange_count
= __constant_cpu_to_le16(0xFFFF);
4578 /* Enable target mode */
4579 nv
->firmware_options_1
|= __constant_cpu_to_le32(BIT_4
);
4581 /* Disable ini mode, if requested */
4582 if (!qla_ini_mode_enabled(vha
))
4583 nv
->firmware_options_1
|= __constant_cpu_to_le32(BIT_5
);
4585 /* Disable Full Login after LIP */
4586 nv
->firmware_options_1
&= __constant_cpu_to_le32(~BIT_13
);
4587 /* Enable initial LIP */
4588 nv
->firmware_options_1
&= __constant_cpu_to_le32(~BIT_9
);
4589 /* Enable FC tapes support */
4590 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
4591 /* Disable Full Login after LIP */
4592 nv
->host_p
&= __constant_cpu_to_le32(~BIT_10
);
4593 /* Enable target PRLI control */
4594 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_14
);
4596 if (ha
->tgt
.saved_set
) {
4597 nv
->exchange_count
= ha
->tgt
.saved_exchange_count
;
4598 nv
->firmware_options_1
=
4599 ha
->tgt
.saved_firmware_options_1
;
4600 nv
->firmware_options_2
=
4601 ha
->tgt
.saved_firmware_options_2
;
4602 nv
->firmware_options_3
=
4603 ha
->tgt
.saved_firmware_options_3
;
4608 /* out-of-order frames reassembly */
4609 nv
->firmware_options_3
|= BIT_6
|BIT_9
;
4611 if (ha
->tgt
.enable_class_2
) {
4612 if (vha
->flags
.init_done
)
4613 fc_host_supported_classes(vha
->host
) =
4614 FC_COS_CLASS2
| FC_COS_CLASS3
;
4616 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_8
);
4618 if (vha
->flags
.init_done
)
4619 fc_host_supported_classes(vha
->host
) = FC_COS_CLASS3
;
4621 nv
->firmware_options_2
&= ~__constant_cpu_to_le32(BIT_8
);
4626 qlt_24xx_config_nvram_stage2(struct scsi_qla_host
*vha
,
4627 struct init_cb_24xx
*icb
)
4629 struct qla_hw_data
*ha
= vha
->hw
;
4631 if (ha
->tgt
.node_name_set
) {
4632 memcpy(icb
->node_name
, ha
->tgt
.tgt_node_name
, WWN_SIZE
);
4633 icb
->firmware_options_1
|= __constant_cpu_to_le32(BIT_14
);
4638 qlt_81xx_config_nvram_stage1(struct scsi_qla_host
*vha
, struct nvram_81xx
*nv
)
4640 struct qla_hw_data
*ha
= vha
->hw
;
4642 if (!QLA_TGT_MODE_ENABLED())
4645 if (qla_tgt_mode_enabled(vha
)) {
4646 if (!ha
->tgt
.saved_set
) {
4647 /* We save only once */
4648 ha
->tgt
.saved_exchange_count
= nv
->exchange_count
;
4649 ha
->tgt
.saved_firmware_options_1
=
4650 nv
->firmware_options_1
;
4651 ha
->tgt
.saved_firmware_options_2
=
4652 nv
->firmware_options_2
;
4653 ha
->tgt
.saved_firmware_options_3
=
4654 nv
->firmware_options_3
;
4655 ha
->tgt
.saved_set
= 1;
4658 nv
->exchange_count
= __constant_cpu_to_le16(0xFFFF);
4660 /* Enable target mode */
4661 nv
->firmware_options_1
|= __constant_cpu_to_le32(BIT_4
);
4663 /* Disable ini mode, if requested */
4664 if (!qla_ini_mode_enabled(vha
))
4665 nv
->firmware_options_1
|=
4666 __constant_cpu_to_le32(BIT_5
);
4668 /* Disable Full Login after LIP */
4669 nv
->firmware_options_1
&= __constant_cpu_to_le32(~BIT_13
);
4670 /* Enable initial LIP */
4671 nv
->firmware_options_1
&= __constant_cpu_to_le32(~BIT_9
);
4672 /* Enable FC tapes support */
4673 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
4674 /* Disable Full Login after LIP */
4675 nv
->host_p
&= __constant_cpu_to_le32(~BIT_10
);
4676 /* Enable target PRLI control */
4677 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_14
);
4679 if (ha
->tgt
.saved_set
) {
4680 nv
->exchange_count
= ha
->tgt
.saved_exchange_count
;
4681 nv
->firmware_options_1
=
4682 ha
->tgt
.saved_firmware_options_1
;
4683 nv
->firmware_options_2
=
4684 ha
->tgt
.saved_firmware_options_2
;
4685 nv
->firmware_options_3
=
4686 ha
->tgt
.saved_firmware_options_3
;
4691 /* out-of-order frames reassembly */
4692 nv
->firmware_options_3
|= BIT_6
|BIT_9
;
4694 if (ha
->tgt
.enable_class_2
) {
4695 if (vha
->flags
.init_done
)
4696 fc_host_supported_classes(vha
->host
) =
4697 FC_COS_CLASS2
| FC_COS_CLASS3
;
4699 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_8
);
4701 if (vha
->flags
.init_done
)
4702 fc_host_supported_classes(vha
->host
) = FC_COS_CLASS3
;
4704 nv
->firmware_options_2
&= ~__constant_cpu_to_le32(BIT_8
);
4709 qlt_81xx_config_nvram_stage2(struct scsi_qla_host
*vha
,
4710 struct init_cb_81xx
*icb
)
4712 struct qla_hw_data
*ha
= vha
->hw
;
4714 if (!QLA_TGT_MODE_ENABLED())
4717 if (ha
->tgt
.node_name_set
) {
4718 memcpy(icb
->node_name
, ha
->tgt
.tgt_node_name
, WWN_SIZE
);
4719 icb
->firmware_options_1
|= __constant_cpu_to_le32(BIT_14
);
4724 qlt_83xx_iospace_config(struct qla_hw_data
*ha
)
4726 if (!QLA_TGT_MODE_ENABLED())
4729 ha
->msix_count
+= 1; /* For ATIO Q */
4733 qlt_24xx_process_response_error(struct scsi_qla_host
*vha
,
4734 struct sts_entry_24xx
*pkt
)
4736 switch (pkt
->entry_type
) {
4737 case ABTS_RECV_24XX
:
4738 case ABTS_RESP_24XX
:
4740 case NOTIFY_ACK_TYPE
:
4748 qlt_modify_vp_config(struct scsi_qla_host
*vha
,
4749 struct vp_config_entry_24xx
*vpmod
)
4751 if (qla_tgt_mode_enabled(vha
))
4752 vpmod
->options_idx1
&= ~BIT_5
;
4753 /* Disable ini mode, if requested */
4754 if (!qla_ini_mode_enabled(vha
))
4755 vpmod
->options_idx1
&= ~BIT_4
;
4759 qlt_probe_one_stage1(struct scsi_qla_host
*base_vha
, struct qla_hw_data
*ha
)
4761 if (!QLA_TGT_MODE_ENABLED())
4764 if (ha
->mqenable
|| IS_QLA83XX(ha
)) {
4765 ISP_ATIO_Q_IN(base_vha
) = &ha
->mqiobase
->isp25mq
.atio_q_in
;
4766 ISP_ATIO_Q_OUT(base_vha
) = &ha
->mqiobase
->isp25mq
.atio_q_out
;
4768 ISP_ATIO_Q_IN(base_vha
) = &ha
->iobase
->isp24
.atio_q_in
;
4769 ISP_ATIO_Q_OUT(base_vha
) = &ha
->iobase
->isp24
.atio_q_out
;
4772 mutex_init(&base_vha
->vha_tgt
.tgt_mutex
);
4773 mutex_init(&base_vha
->vha_tgt
.tgt_host_action_mutex
);
4774 qlt_clear_mode(base_vha
);
4778 qla83xx_msix_atio_q(int irq
, void *dev_id
)
4780 struct rsp_que
*rsp
;
4781 scsi_qla_host_t
*vha
;
4782 struct qla_hw_data
*ha
;
4783 unsigned long flags
;
4785 rsp
= (struct rsp_que
*) dev_id
;
4787 vha
= pci_get_drvdata(ha
->pdev
);
4789 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4791 qlt_24xx_process_atio_queue(vha
);
4792 qla24xx_process_response_queue(vha
, rsp
);
4794 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4800 qlt_mem_alloc(struct qla_hw_data
*ha
)
4802 if (!QLA_TGT_MODE_ENABLED())
4805 ha
->tgt
.tgt_vp_map
= kzalloc(sizeof(struct qla_tgt_vp_map
) *
4806 MAX_MULTI_ID_FABRIC
, GFP_KERNEL
);
4807 if (!ha
->tgt
.tgt_vp_map
)
4810 ha
->tgt
.atio_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
4811 (ha
->tgt
.atio_q_length
+ 1) * sizeof(struct atio_from_isp
),
4812 &ha
->tgt
.atio_dma
, GFP_KERNEL
);
4813 if (!ha
->tgt
.atio_ring
) {
4814 kfree(ha
->tgt
.tgt_vp_map
);
4821 qlt_mem_free(struct qla_hw_data
*ha
)
4823 if (!QLA_TGT_MODE_ENABLED())
4826 if (ha
->tgt
.atio_ring
) {
4827 dma_free_coherent(&ha
->pdev
->dev
, (ha
->tgt
.atio_q_length
+ 1) *
4828 sizeof(struct atio_from_isp
), ha
->tgt
.atio_ring
,
4831 kfree(ha
->tgt
.tgt_vp_map
);
4834 /* vport_slock to be held by the caller */
4836 qlt_update_vp_map(struct scsi_qla_host
*vha
, int cmd
)
4838 if (!QLA_TGT_MODE_ENABLED())
4843 vha
->hw
->tgt
.tgt_vp_map
[vha
->vp_idx
].vha
= vha
;
4846 vha
->hw
->tgt
.tgt_vp_map
[vha
->d_id
.b
.al_pa
].idx
= vha
->vp_idx
;
4849 vha
->hw
->tgt
.tgt_vp_map
[vha
->vp_idx
].vha
= NULL
;
4852 vha
->hw
->tgt
.tgt_vp_map
[vha
->d_id
.b
.al_pa
].idx
= 0;
4857 static int __init
qlt_parse_ini_mode(void)
4859 if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_EXCLUSIVE
) == 0)
4860 ql2x_ini_mode
= QLA2XXX_INI_MODE_EXCLUSIVE
;
4861 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_DISABLED
) == 0)
4862 ql2x_ini_mode
= QLA2XXX_INI_MODE_DISABLED
;
4863 else if (strcasecmp(qlini_mode
, QLA2XXX_INI_MODE_STR_ENABLED
) == 0)
4864 ql2x_ini_mode
= QLA2XXX_INI_MODE_ENABLED
;
4871 int __init
qlt_init(void)
4875 if (!qlt_parse_ini_mode()) {
4876 ql_log(ql_log_fatal
, NULL
, 0xe06b,
4877 "qlt_parse_ini_mode() failed\n");
4881 if (!QLA_TGT_MODE_ENABLED())
4884 qla_tgt_cmd_cachep
= kmem_cache_create("qla_tgt_cmd_cachep",
4885 sizeof(struct qla_tgt_cmd
), __alignof__(struct qla_tgt_cmd
), 0,
4887 if (!qla_tgt_cmd_cachep
) {
4888 ql_log(ql_log_fatal
, NULL
, 0xe06c,
4889 "kmem_cache_create for qla_tgt_cmd_cachep failed\n");
4893 qla_tgt_mgmt_cmd_cachep
= kmem_cache_create("qla_tgt_mgmt_cmd_cachep",
4894 sizeof(struct qla_tgt_mgmt_cmd
), __alignof__(struct
4895 qla_tgt_mgmt_cmd
), 0, NULL
);
4896 if (!qla_tgt_mgmt_cmd_cachep
) {
4897 ql_log(ql_log_fatal
, NULL
, 0xe06d,
4898 "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n");
4903 qla_tgt_mgmt_cmd_mempool
= mempool_create(25, mempool_alloc_slab
,
4904 mempool_free_slab
, qla_tgt_mgmt_cmd_cachep
);
4905 if (!qla_tgt_mgmt_cmd_mempool
) {
4906 ql_log(ql_log_fatal
, NULL
, 0xe06e,
4907 "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n");
4909 goto out_mgmt_cmd_cachep
;
4912 qla_tgt_wq
= alloc_workqueue("qla_tgt_wq", 0, 0);
4914 ql_log(ql_log_fatal
, NULL
, 0xe06f,
4915 "alloc_workqueue for qla_tgt_wq failed\n");
4917 goto out_cmd_mempool
;
4920 * Return 1 to signal that initiator-mode is being disabled
4922 return (ql2x_ini_mode
== QLA2XXX_INI_MODE_DISABLED
) ? 1 : 0;
4925 mempool_destroy(qla_tgt_mgmt_cmd_mempool
);
4926 out_mgmt_cmd_cachep
:
4927 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep
);
4929 kmem_cache_destroy(qla_tgt_cmd_cachep
);
4935 if (!QLA_TGT_MODE_ENABLED())
4938 destroy_workqueue(qla_tgt_wq
);
4939 mempool_destroy(qla_tgt_mgmt_cmd_mempool
);
4940 kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep
);
4941 kmem_cache_destroy(qla_tgt_cmd_cachep
);