diff options
author | Nicholas Bellinger <nab@linux-iscsi.org> | 2012-05-15 14:34:28 -0400 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2012-05-22 06:47:51 -0400 |
commit | 2d70c103fd2a066f904712b14239a5ce141f8236 (patch) | |
tree | ab803dc02ea9be7c45bf1b506880031ad87ac1f9 | |
parent | 2c1391d395ef7ba9261b7dd590c5a195315631d6 (diff) |
[SCSI] qla2xxx: Add LLD target-mode infrastructure for >= 24xx series
Add LLD target mode for >= 24xx series HW. This code was originally based on
external qla2x00t module based on 8.02.01-k4, and has been refactored to
push the bulk of code into mainline qla2xxx.ko LLD -> qla_target.c.
The implementation uses internal workqueues for I/O context submission
into tcm_qla2xxx code, and includes the struct qla_tgt_func_tmpl API for
external interaction to allow qla2xxx LDD to function without direct
target-core dependencies:
It also enables qla_target.c usage within existing qla2xxx LLD code.
This includes:
*) Addition of target mode specific members to existing data
structures in qla_def.h and struct qla_hw_data->tgt_ops using
qla_target.h:struct qla_tgt_func_tmpl
*) Addition of struct qla_tgt_func_tmpl and direct calls into
qla_target.c logic w/ qlt_* prefixed functions.
*) Addition of qla_iocb.c:qla2x00_req_pkt() for ring processing, and
qla2x00_issue_marker() for handling request/response queue processing
for target mode operation
*) Addition of various qla_tgt_mode_enabled() logic checks in
qla24xx_nvram_config(), qla2x00_initialize_adapter(), qla2x00_rff_id(),
qla2x00_abort_isp(), qla24xx_modify_vp_config(), and
qla2x00_vp_abort_isp().
By default the new qlini_mode module parameter is setting initiator-mode
to 'enabled' in order for 'modprobe qla2xxx' to continue to function as
expected in initiator only mode. Enabling target-mode operation will
currently require a:
modprobe qla2xxx qlini_mode="disabled"
in order to explictly disabled initiator mode and allow target-mode
to be enabled via tcm_qla2xxx configfs fabric callers.
(nab: Convert to qlini_mode='enabled' by default in qla_target.c)
(joern: Remove loop_id from qla_tgt_make_local_sess() arguments +
Remove unused s_id + fix s_id endianness bug +
simplify qla_tgt_abort_work)
(gerard: fix section __exit mismatch in qla_tgt_exit)
(arun: Capture ATIO queue during firmware dump + Send SCR in target mode +
Target mode review comments)
(roland: Don't create duplicate target sessions to address tearing down
ACLs with IO in flight + Add missing call to qlt_fc_port_deleted
call during qla2x00_schedule_rport_del timeout)
Signed-off-by: Nicholas A. Bellinger <nab@linux-iscsi.org>
Signed-off-by: Chad Dupuis <chad.dupuis@qlogic.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
-rw-r--r-- | drivers/scsi/qla2xxx/Makefile | 2 | ||||
-rw-r--r-- | drivers/scsi/qla2xxx/qla_attr.c | 5 | ||||
-rw-r--r-- | drivers/scsi/qla2xxx/qla_dbg.c | 70 | ||||
-rw-r--r-- | drivers/scsi/qla2xxx/qla_dbg.h | 4 | ||||
-rw-r--r-- | drivers/scsi/qla2xxx/qla_def.h | 69 | ||||
-rw-r--r-- | drivers/scsi/qla2xxx/qla_gbl.h | 7 | ||||
-rw-r--r-- | drivers/scsi/qla2xxx/qla_gs.c | 4 | ||||
-rw-r--r-- | drivers/scsi/qla2xxx/qla_init.c | 74 | ||||
-rw-r--r-- | drivers/scsi/qla2xxx/qla_iocb.c | 26 | ||||
-rw-r--r-- | drivers/scsi/qla2xxx/qla_isr.c | 40 | ||||
-rw-r--r-- | drivers/scsi/qla2xxx/qla_mbx.c | 112 | ||||
-rw-r--r-- | drivers/scsi/qla2xxx/qla_mid.c | 8 | ||||
-rw-r--r-- | drivers/scsi/qla2xxx/qla_os.c | 108 | ||||
-rw-r--r-- | drivers/scsi/qla2xxx/qla_target.c | 4973 | ||||
-rw-r--r-- | drivers/scsi/qla2xxx/qla_target.h | 1005 |
15 files changed, 6472 insertions, 35 deletions
diff --git a/drivers/scsi/qla2xxx/Makefile b/drivers/scsi/qla2xxx/Makefile index 5df782f4a097..702931ff67db 100644 --- a/drivers/scsi/qla2xxx/Makefile +++ b/drivers/scsi/qla2xxx/Makefile | |||
@@ -1,5 +1,5 @@ | |||
1 | qla2xxx-y := qla_os.o qla_init.o qla_mbx.o qla_iocb.o qla_isr.o qla_gs.o \ | 1 | qla2xxx-y := qla_os.o qla_init.o qla_mbx.o qla_iocb.o qla_isr.o qla_gs.o \ |
2 | qla_dbg.o qla_sup.o qla_attr.o qla_mid.o qla_dfs.o qla_bsg.o \ | 2 | qla_dbg.o qla_sup.o qla_attr.o qla_mid.o qla_dfs.o qla_bsg.o \ |
3 | qla_nx.o | 3 | qla_nx.o qla_target.o |
4 | 4 | ||
5 | obj-$(CONFIG_SCSI_QLA_FC) += qla2xxx.o | 5 | obj-$(CONFIG_SCSI_QLA_FC) += qla2xxx.o |
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c index 00df96b96a1b..5ab953029f8d 100644 --- a/drivers/scsi/qla2xxx/qla_attr.c +++ b/drivers/scsi/qla2xxx/qla_attr.c | |||
@@ -5,6 +5,7 @@ | |||
5 | * See LICENSE.qla2xxx for copyright and licensing details. | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
6 | */ | 6 | */ |
7 | #include "qla_def.h" | 7 | #include "qla_def.h" |
8 | #include "qla_target.h" | ||
8 | 9 | ||
9 | #include <linux/kthread.h> | 10 | #include <linux/kthread.h> |
10 | #include <linux/vmalloc.h> | 11 | #include <linux/vmalloc.h> |
@@ -1737,6 +1738,7 @@ qla24xx_vport_create(struct fc_vport *fc_vport, bool disable) | |||
1737 | fc_host_supported_speeds(vha->host) = | 1738 | fc_host_supported_speeds(vha->host) = |
1738 | fc_host_supported_speeds(base_vha->host); | 1739 | fc_host_supported_speeds(base_vha->host); |
1739 | 1740 | ||
1741 | qlt_vport_create(vha, ha); | ||
1740 | qla24xx_vport_disable(fc_vport, disable); | 1742 | qla24xx_vport_disable(fc_vport, disable); |
1741 | 1743 | ||
1742 | if (ha->flags.cpu_affinity_enabled) { | 1744 | if (ha->flags.cpu_affinity_enabled) { |
@@ -1951,7 +1953,8 @@ qla2x00_init_host_attr(scsi_qla_host_t *vha) | |||
1951 | fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count; | 1953 | fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count; |
1952 | fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name); | 1954 | fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name); |
1953 | fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name); | 1955 | fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name); |
1954 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; | 1956 | fc_host_supported_classes(vha->host) = ha->tgt.enable_class_2 ? |
1957 | (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3; | ||
1955 | fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports; | 1958 | fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports; |
1956 | fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count; | 1959 | fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count; |
1957 | 1960 | ||
diff --git a/drivers/scsi/qla2xxx/qla_dbg.c b/drivers/scsi/qla2xxx/qla_dbg.c index 1457186a0f2c..fdee5611f3e2 100644 --- a/drivers/scsi/qla2xxx/qla_dbg.c +++ b/drivers/scsi/qla2xxx/qla_dbg.c | |||
@@ -11,8 +11,8 @@ | |||
11 | * ---------------------------------------------------------------------- | 11 | * ---------------------------------------------------------------------- |
12 | * | Level | Last Value Used | Holes | | 12 | * | Level | Last Value Used | Holes | |
13 | * ---------------------------------------------------------------------- | 13 | * ---------------------------------------------------------------------- |
14 | * | Module Init and Probe | 0x0120 | 0x4b,0xba,0xfa | | 14 | * | Module Init and Probe | 0x0122 | 0x4b,0xba,0xfa | |
15 | * | Mailbox commands | 0x113e | 0x111a-0x111b | | 15 | * | Mailbox commands | 0x1140 | 0x111a-0x111b | |
16 | * | | | 0x112c-0x112e | | 16 | * | | | 0x112c-0x112e | |
17 | * | | | 0x113a | | 17 | * | | | 0x113a | |
18 | * | Device Discovery | 0x2086 | 0x2020-0x2022 | | 18 | * | Device Discovery | 0x2086 | 0x2020-0x2022 | |
@@ -33,6 +33,9 @@ | |||
33 | * | ISP82XX Specific | 0xb054 | 0xb024 | | 33 | * | ISP82XX Specific | 0xb054 | 0xb024 | |
34 | * | MultiQ | 0xc00c | | | 34 | * | MultiQ | 0xc00c | | |
35 | * | Misc | 0xd010 | | | 35 | * | Misc | 0xd010 | | |
36 | * | Target Mode | 0xe06f | | | ||
37 | * | Target Mode Management | 0xf071 | | | ||
38 | * | Target Mode Task Management | 0x1000b | | | ||
36 | * ---------------------------------------------------------------------- | 39 | * ---------------------------------------------------------------------- |
37 | */ | 40 | */ |
38 | 41 | ||
@@ -380,6 +383,54 @@ qla25xx_copy_fce(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain) | |||
380 | } | 383 | } |
381 | 384 | ||
382 | static inline void * | 385 | static inline void * |
386 | qla2xxx_copy_atioqueues(struct qla_hw_data *ha, void *ptr, | ||
387 | uint32_t **last_chain) | ||
388 | { | ||
389 | struct qla2xxx_mqueue_chain *q; | ||
390 | struct qla2xxx_mqueue_header *qh; | ||
391 | uint32_t num_queues; | ||
392 | int que; | ||
393 | struct { | ||
394 | int length; | ||
395 | void *ring; | ||
396 | } aq, *aqp; | ||
397 | |||
398 | if (!ha->tgt.atio_q_length) | ||
399 | return ptr; | ||
400 | |||
401 | num_queues = 1; | ||
402 | aqp = &aq; | ||
403 | aqp->length = ha->tgt.atio_q_length; | ||
404 | aqp->ring = ha->tgt.atio_ring; | ||
405 | |||
406 | for (que = 0; que < num_queues; que++) { | ||
407 | /* aqp = ha->atio_q_map[que]; */ | ||
408 | q = ptr; | ||
409 | *last_chain = &q->type; | ||
410 | q->type = __constant_htonl(DUMP_CHAIN_QUEUE); | ||
411 | q->chain_size = htonl( | ||
412 | sizeof(struct qla2xxx_mqueue_chain) + | ||
413 | sizeof(struct qla2xxx_mqueue_header) + | ||
414 | (aqp->length * sizeof(request_t))); | ||
415 | ptr += sizeof(struct qla2xxx_mqueue_chain); | ||
416 | |||
417 | /* Add header. */ | ||
418 | qh = ptr; | ||
419 | qh->queue = __constant_htonl(TYPE_ATIO_QUEUE); | ||
420 | qh->number = htonl(que); | ||
421 | qh->size = htonl(aqp->length * sizeof(request_t)); | ||
422 | ptr += sizeof(struct qla2xxx_mqueue_header); | ||
423 | |||
424 | /* Add data. */ | ||
425 | memcpy(ptr, aqp->ring, aqp->length * sizeof(request_t)); | ||
426 | |||
427 | ptr += aqp->length * sizeof(request_t); | ||
428 | } | ||
429 | |||
430 | return ptr; | ||
431 | } | ||
432 | |||
433 | static inline void * | ||
383 | qla25xx_copy_mqueues(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain) | 434 | qla25xx_copy_mqueues(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain) |
384 | { | 435 | { |
385 | struct qla2xxx_mqueue_chain *q; | 436 | struct qla2xxx_mqueue_chain *q; |
@@ -874,6 +925,8 @@ qla24xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) | |||
874 | struct qla24xx_fw_dump *fw; | 925 | struct qla24xx_fw_dump *fw; |
875 | uint32_t ext_mem_cnt; | 926 | uint32_t ext_mem_cnt; |
876 | void *nxt; | 927 | void *nxt; |
928 | void *nxt_chain; | ||
929 | uint32_t *last_chain = NULL; | ||
877 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | 930 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
878 | 931 | ||
879 | if (IS_QLA82XX(ha)) | 932 | if (IS_QLA82XX(ha)) |
@@ -1092,6 +1145,16 @@ qla24xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) | |||
1092 | 1145 | ||
1093 | qla24xx_copy_eft(ha, nxt); | 1146 | qla24xx_copy_eft(ha, nxt); |
1094 | 1147 | ||
1148 | nxt_chain = (void *)ha->fw_dump + ha->chain_offset; | ||
1149 | nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain); | ||
1150 | if (last_chain) { | ||
1151 | ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT); | ||
1152 | *last_chain |= __constant_htonl(DUMP_CHAIN_LAST); | ||
1153 | } | ||
1154 | |||
1155 | /* Adjust valid length. */ | ||
1156 | ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump); | ||
1157 | |||
1095 | qla24xx_fw_dump_failed_0: | 1158 | qla24xx_fw_dump_failed_0: |
1096 | qla2xxx_dump_post_process(base_vha, rval); | 1159 | qla2xxx_dump_post_process(base_vha, rval); |
1097 | 1160 | ||
@@ -1400,6 +1463,7 @@ qla25xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) | |||
1400 | /* Chain entries -- started with MQ. */ | 1463 | /* Chain entries -- started with MQ. */ |
1401 | nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain); | 1464 | nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain); |
1402 | nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain); | 1465 | nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain); |
1466 | nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain); | ||
1403 | if (last_chain) { | 1467 | if (last_chain) { |
1404 | ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT); | 1468 | ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT); |
1405 | *last_chain |= __constant_htonl(DUMP_CHAIN_LAST); | 1469 | *last_chain |= __constant_htonl(DUMP_CHAIN_LAST); |
@@ -1718,6 +1782,7 @@ qla81xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) | |||
1718 | /* Chain entries -- started with MQ. */ | 1782 | /* Chain entries -- started with MQ. */ |
1719 | nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain); | 1783 | nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain); |
1720 | nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain); | 1784 | nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain); |
1785 | nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain); | ||
1721 | if (last_chain) { | 1786 | if (last_chain) { |
1722 | ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT); | 1787 | ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT); |
1723 | *last_chain |= __constant_htonl(DUMP_CHAIN_LAST); | 1788 | *last_chain |= __constant_htonl(DUMP_CHAIN_LAST); |
@@ -2219,6 +2284,7 @@ copy_queue: | |||
2219 | /* Chain entries -- started with MQ. */ | 2284 | /* Chain entries -- started with MQ. */ |
2220 | nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain); | 2285 | nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain); |
2221 | nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain); | 2286 | nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain); |
2287 | nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain); | ||
2222 | if (last_chain) { | 2288 | if (last_chain) { |
2223 | ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT); | 2289 | ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT); |
2224 | *last_chain |= __constant_htonl(DUMP_CHAIN_LAST); | 2290 | *last_chain |= __constant_htonl(DUMP_CHAIN_LAST); |
diff --git a/drivers/scsi/qla2xxx/qla_dbg.h b/drivers/scsi/qla2xxx/qla_dbg.h index 3ba45a73c81f..f278df8cce0f 100644 --- a/drivers/scsi/qla2xxx/qla_dbg.h +++ b/drivers/scsi/qla2xxx/qla_dbg.h | |||
@@ -244,6 +244,7 @@ struct qla2xxx_mqueue_header { | |||
244 | uint32_t queue; | 244 | uint32_t queue; |
245 | #define TYPE_REQUEST_QUEUE 0x1 | 245 | #define TYPE_REQUEST_QUEUE 0x1 |
246 | #define TYPE_RESPONSE_QUEUE 0x2 | 246 | #define TYPE_RESPONSE_QUEUE 0x2 |
247 | #define TYPE_ATIO_QUEUE 0x3 | ||
247 | uint32_t number; | 248 | uint32_t number; |
248 | uint32_t size; | 249 | uint32_t size; |
249 | }; | 250 | }; |
@@ -344,3 +345,6 @@ ql_log_pci(uint32_t, struct pci_dev *pdev, int32_t, const char *fmt, ...); | |||
344 | * more verbosity is required. It might not | 345 | * more verbosity is required. It might not |
345 | * be applicable to all the levels. | 346 | * be applicable to all the levels. |
346 | */ | 347 | */ |
348 | #define ql_dbg_tgt 0x00004000 /* Target mode */ | ||
349 | #define ql_dbg_tgt_mgt 0x00002000 /* Target mode management */ | ||
350 | #define ql_dbg_tgt_tmr 0x00001000 /* Target mode task management */ | ||
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h index 13c3fe1316fa..39007f53aec0 100644 --- a/drivers/scsi/qla2xxx/qla_def.h +++ b/drivers/scsi/qla2xxx/qla_def.h | |||
@@ -186,6 +186,7 @@ | |||
186 | #define RESPONSE_ENTRY_CNT_2100 64 /* Number of response entries.*/ | 186 | #define RESPONSE_ENTRY_CNT_2100 64 /* Number of response entries.*/ |
187 | #define RESPONSE_ENTRY_CNT_2300 512 /* Number of response entries.*/ | 187 | #define RESPONSE_ENTRY_CNT_2300 512 /* Number of response entries.*/ |
188 | #define RESPONSE_ENTRY_CNT_MQ 128 /* Number of response entries.*/ | 188 | #define RESPONSE_ENTRY_CNT_MQ 128 /* Number of response entries.*/ |
189 | #define ATIO_ENTRY_CNT_24XX 4096 /* Number of ATIO entries. */ | ||
189 | 190 | ||
190 | struct req_que; | 191 | struct req_que; |
191 | 192 | ||
@@ -1234,11 +1235,27 @@ typedef struct { | |||
1234 | * ISP queue - response queue entry definition. | 1235 | * ISP queue - response queue entry definition. |
1235 | */ | 1236 | */ |
1236 | typedef struct { | 1237 | typedef struct { |
1237 | uint8_t data[60]; | 1238 | uint8_t entry_type; /* Entry type. */ |
1239 | uint8_t entry_count; /* Entry count. */ | ||
1240 | uint8_t sys_define; /* System defined. */ | ||
1241 | uint8_t entry_status; /* Entry Status. */ | ||
1242 | uint32_t handle; /* System defined handle */ | ||
1243 | uint8_t data[52]; | ||
1238 | uint32_t signature; | 1244 | uint32_t signature; |
1239 | #define RESPONSE_PROCESSED 0xDEADDEAD /* Signature */ | 1245 | #define RESPONSE_PROCESSED 0xDEADDEAD /* Signature */ |
1240 | } response_t; | 1246 | } response_t; |
1241 | 1247 | ||
1248 | /* | ||
1249 | * ISP queue - ATIO queue entry definition. | ||
1250 | */ | ||
1251 | struct atio { | ||
1252 | uint8_t entry_type; /* Entry type. */ | ||
1253 | uint8_t entry_count; /* Entry count. */ | ||
1254 | uint8_t data[58]; | ||
1255 | uint32_t signature; | ||
1256 | #define ATIO_PROCESSED 0xDEADDEAD /* Signature */ | ||
1257 | }; | ||
1258 | |||
1242 | typedef union { | 1259 | typedef union { |
1243 | uint16_t extended; | 1260 | uint16_t extended; |
1244 | struct { | 1261 | struct { |
@@ -1749,6 +1766,7 @@ static const char * const port_state_str[] = { | |||
1749 | #define FCF_LOGIN_NEEDED BIT_1 | 1766 | #define FCF_LOGIN_NEEDED BIT_1 |
1750 | #define FCF_FCP2_DEVICE BIT_2 | 1767 | #define FCF_FCP2_DEVICE BIT_2 |
1751 | #define FCF_ASYNC_SENT BIT_3 | 1768 | #define FCF_ASYNC_SENT BIT_3 |
1769 | #define FCF_CONF_COMP_SUPPORTED BIT_4 | ||
1752 | 1770 | ||
1753 | /* No loop ID flag. */ | 1771 | /* No loop ID flag. */ |
1754 | #define FC_NO_LOOP_ID 0x1000 | 1772 | #define FC_NO_LOOP_ID 0x1000 |
@@ -2421,6 +2439,40 @@ struct qlfc_fw { | |||
2421 | uint32_t len; | 2439 | uint32_t len; |
2422 | }; | 2440 | }; |
2423 | 2441 | ||
2442 | struct qlt_hw_data { | ||
2443 | /* Protected by hw lock */ | ||
2444 | uint32_t enable_class_2:1; | ||
2445 | uint32_t enable_explicit_conf:1; | ||
2446 | uint32_t ini_mode_force_reverse:1; | ||
2447 | uint32_t node_name_set:1; | ||
2448 | |||
2449 | dma_addr_t atio_dma; /* Physical address. */ | ||
2450 | struct atio *atio_ring; /* Base virtual address */ | ||
2451 | struct atio *atio_ring_ptr; /* Current address. */ | ||
2452 | uint16_t atio_ring_index; /* Current index. */ | ||
2453 | uint16_t atio_q_length; | ||
2454 | |||
2455 | void *target_lport_ptr; | ||
2456 | struct qla_tgt_func_tmpl *tgt_ops; | ||
2457 | struct qla_tgt *qla_tgt; | ||
2458 | struct qla_tgt_cmd *cmds[MAX_OUTSTANDING_COMMANDS]; | ||
2459 | uint16_t current_handle; | ||
2460 | |||
2461 | struct qla_tgt_vp_map *tgt_vp_map; | ||
2462 | struct mutex tgt_mutex; | ||
2463 | struct mutex tgt_host_action_mutex; | ||
2464 | |||
2465 | int saved_set; | ||
2466 | uint16_t saved_exchange_count; | ||
2467 | uint32_t saved_firmware_options_1; | ||
2468 | uint32_t saved_firmware_options_2; | ||
2469 | uint32_t saved_firmware_options_3; | ||
2470 | uint8_t saved_firmware_options[2]; | ||
2471 | uint8_t saved_add_firmware_options[2]; | ||
2472 | |||
2473 | uint8_t tgt_node_name[WWN_SIZE]; | ||
2474 | }; | ||
2475 | |||
2424 | /* | 2476 | /* |
2425 | * Qlogic host adapter specific data structure. | 2477 | * Qlogic host adapter specific data structure. |
2426 | */ | 2478 | */ |
@@ -2463,7 +2515,8 @@ struct qla_hw_data { | |||
2463 | uint32_t isp82xx_reset_hdlr_active:1; | 2515 | uint32_t isp82xx_reset_hdlr_active:1; |
2464 | uint32_t isp82xx_reset_owner:1; | 2516 | uint32_t isp82xx_reset_owner:1; |
2465 | uint32_t isp82xx_no_md_cap:1; | 2517 | uint32_t isp82xx_no_md_cap:1; |
2466 | /* 28 bits */ | 2518 | uint32_t host_shutting_down:1; |
2519 | /* 30 bits */ | ||
2467 | } flags; | 2520 | } flags; |
2468 | 2521 | ||
2469 | /* This spinlock is used to protect "io transactions", you must | 2522 | /* This spinlock is used to protect "io transactions", you must |
@@ -2864,6 +2917,8 @@ struct qla_hw_data { | |||
2864 | dma_addr_t md_tmplt_hdr_dma; | 2917 | dma_addr_t md_tmplt_hdr_dma; |
2865 | void *md_dump; | 2918 | void *md_dump; |
2866 | uint32_t md_dump_size; | 2919 | uint32_t md_dump_size; |
2920 | |||
2921 | struct qlt_hw_data tgt; | ||
2867 | }; | 2922 | }; |
2868 | 2923 | ||
2869 | /* | 2924 | /* |
@@ -2921,6 +2976,7 @@ typedef struct scsi_qla_host { | |||
2921 | #define FCOE_CTX_RESET_NEEDED 18 /* Initiate FCoE context reset */ | 2976 | #define FCOE_CTX_RESET_NEEDED 18 /* Initiate FCoE context reset */ |
2922 | #define MPI_RESET_NEEDED 19 /* Initiate MPI FW reset */ | 2977 | #define MPI_RESET_NEEDED 19 /* Initiate MPI FW reset */ |
2923 | #define ISP_QUIESCE_NEEDED 20 /* Driver need some quiescence */ | 2978 | #define ISP_QUIESCE_NEEDED 20 /* Driver need some quiescence */ |
2979 | #define SCR_PENDING 21 /* SCR in target mode */ | ||
2924 | 2980 | ||
2925 | uint32_t device_flags; | 2981 | uint32_t device_flags; |
2926 | #define SWITCH_FOUND BIT_0 | 2982 | #define SWITCH_FOUND BIT_0 |
@@ -2986,6 +3042,15 @@ typedef struct scsi_qla_host { | |||
2986 | atomic_t vref_count; | 3042 | atomic_t vref_count; |
2987 | } scsi_qla_host_t; | 3043 | } scsi_qla_host_t; |
2988 | 3044 | ||
3045 | #define SET_VP_IDX 1 | ||
3046 | #define SET_AL_PA 2 | ||
3047 | #define RESET_VP_IDX 3 | ||
3048 | #define RESET_AL_PA 4 | ||
3049 | struct qla_tgt_vp_map { | ||
3050 | uint8_t idx; | ||
3051 | scsi_qla_host_t *vha; | ||
3052 | }; | ||
3053 | |||
2989 | /* | 3054 | /* |
2990 | * Macros to help code, maintain, etc. | 3055 | * Macros to help code, maintain, etc. |
2991 | */ | 3056 | */ |
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h index c0896996b56b..9eacd2df111b 100644 --- a/drivers/scsi/qla2xxx/qla_gbl.h +++ b/drivers/scsi/qla2xxx/qla_gbl.h | |||
@@ -175,6 +175,7 @@ extern int qla2x00_vp_abort_isp(scsi_qla_host_t *); | |||
175 | /* | 175 | /* |
176 | * Global Function Prototypes in qla_iocb.c source file. | 176 | * Global Function Prototypes in qla_iocb.c source file. |
177 | */ | 177 | */ |
178 | |||
178 | extern uint16_t qla2x00_calc_iocbs_32(uint16_t); | 179 | extern uint16_t qla2x00_calc_iocbs_32(uint16_t); |
179 | extern uint16_t qla2x00_calc_iocbs_64(uint16_t); | 180 | extern uint16_t qla2x00_calc_iocbs_64(uint16_t); |
180 | extern void qla2x00_build_scsi_iocbs_32(srb_t *, cmd_entry_t *, uint16_t); | 181 | extern void qla2x00_build_scsi_iocbs_32(srb_t *, cmd_entry_t *, uint16_t); |
@@ -188,6 +189,8 @@ extern uint16_t qla24xx_calc_iocbs(scsi_qla_host_t *, uint16_t); | |||
188 | extern void qla24xx_build_scsi_iocbs(srb_t *, struct cmd_type_7 *, uint16_t); | 189 | extern void qla24xx_build_scsi_iocbs(srb_t *, struct cmd_type_7 *, uint16_t); |
189 | extern int qla24xx_dif_start_scsi(srb_t *); | 190 | extern int qla24xx_dif_start_scsi(srb_t *); |
190 | 191 | ||
192 | extern void *qla2x00_alloc_iocbs(scsi_qla_host_t *, srb_t *); | ||
193 | extern int qla2x00_issue_marker(scsi_qla_host_t *, int); | ||
191 | 194 | ||
192 | /* | 195 | /* |
193 | * Global Function Prototypes in qla_mbx.c source file. | 196 | * Global Function Prototypes in qla_mbx.c source file. |
@@ -239,6 +242,9 @@ extern int | |||
239 | qla2x00_init_firmware(scsi_qla_host_t *, uint16_t); | 242 | qla2x00_init_firmware(scsi_qla_host_t *, uint16_t); |
240 | 243 | ||
241 | extern int | 244 | extern int |
245 | qla2x00_get_node_name_list(scsi_qla_host_t *, void **, int *); | ||
246 | |||
247 | extern int | ||
242 | qla2x00_get_port_database(scsi_qla_host_t *, fc_port_t *, uint8_t); | 248 | qla2x00_get_port_database(scsi_qla_host_t *, fc_port_t *, uint8_t); |
243 | 249 | ||
244 | extern int | 250 | extern int |
@@ -548,6 +554,7 @@ extern void qla2x00_sp_free(void *, void *); | |||
548 | extern void qla2x00_sp_timeout(unsigned long); | 554 | extern void qla2x00_sp_timeout(unsigned long); |
549 | extern void qla2x00_bsg_job_done(void *, void *, int); | 555 | extern void qla2x00_bsg_job_done(void *, void *, int); |
550 | extern void qla2x00_bsg_sp_free(void *, void *); | 556 | extern void qla2x00_bsg_sp_free(void *, void *); |
557 | extern void qla2x00_start_iocbs(struct scsi_qla_host *, struct req_que *); | ||
551 | 558 | ||
552 | /* Interrupt related */ | 559 | /* Interrupt related */ |
553 | extern irqreturn_t qla82xx_intr_handler(int, void *); | 560 | extern irqreturn_t qla82xx_intr_handler(int, void *); |
diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c index 3128f80441f5..05260d25fe46 100644 --- a/drivers/scsi/qla2xxx/qla_gs.c +++ b/drivers/scsi/qla2xxx/qla_gs.c | |||
@@ -5,6 +5,7 @@ | |||
5 | * See LICENSE.qla2xxx for copyright and licensing details. | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
6 | */ | 6 | */ |
7 | #include "qla_def.h" | 7 | #include "qla_def.h" |
8 | #include "qla_target.h" | ||
8 | 9 | ||
9 | static int qla2x00_sns_ga_nxt(scsi_qla_host_t *, fc_port_t *); | 10 | static int qla2x00_sns_ga_nxt(scsi_qla_host_t *, fc_port_t *); |
10 | static int qla2x00_sns_gid_pt(scsi_qla_host_t *, sw_info_t *); | 11 | static int qla2x00_sns_gid_pt(scsi_qla_host_t *, sw_info_t *); |
@@ -556,7 +557,8 @@ qla2x00_rff_id(scsi_qla_host_t *vha) | |||
556 | ct_req->req.rff_id.port_id[1] = vha->d_id.b.area; | 557 | ct_req->req.rff_id.port_id[1] = vha->d_id.b.area; |
557 | ct_req->req.rff_id.port_id[2] = vha->d_id.b.al_pa; | 558 | ct_req->req.rff_id.port_id[2] = vha->d_id.b.al_pa; |
558 | 559 | ||
559 | ct_req->req.rff_id.fc4_feature = BIT_1; | 560 | qlt_rff_id(vha, ct_req); |
561 | |||
560 | ct_req->req.rff_id.fc4_type = 0x08; /* SCSI - FCP */ | 562 | ct_req->req.rff_id.fc4_type = 0x08; /* SCSI - FCP */ |
561 | 563 | ||
562 | /* Execute MS IOCB */ | 564 | /* Execute MS IOCB */ |
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c index 886b2b653965..ca5084743135 100644 --- a/drivers/scsi/qla2xxx/qla_init.c +++ b/drivers/scsi/qla2xxx/qla_init.c | |||
@@ -17,6 +17,9 @@ | |||
17 | #include <asm/prom.h> | 17 | #include <asm/prom.h> |
18 | #endif | 18 | #endif |
19 | 19 | ||
20 | #include <target/target_core_base.h> | ||
21 | #include "qla_target.h" | ||
22 | |||
20 | /* | 23 | /* |
21 | * QLogic ISP2x00 Hardware Support Function Prototypes. | 24 | * QLogic ISP2x00 Hardware Support Function Prototypes. |
22 | */ | 25 | */ |
@@ -518,7 +521,10 @@ qla2x00_initialize_adapter(scsi_qla_host_t *vha) | |||
518 | return QLA_FUNCTION_FAILED; | 521 | return QLA_FUNCTION_FAILED; |
519 | } | 522 | } |
520 | } | 523 | } |
521 | rval = qla2x00_init_rings(vha); | 524 | |
525 | if (qla_ini_mode_enabled(vha)) | ||
526 | rval = qla2x00_init_rings(vha); | ||
527 | |||
522 | ha->flags.chip_reset_done = 1; | 528 | ha->flags.chip_reset_done = 1; |
523 | 529 | ||
524 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { | 530 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
@@ -1233,6 +1239,8 @@ qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) | |||
1233 | mq_size += ha->max_rsp_queues * | 1239 | mq_size += ha->max_rsp_queues * |
1234 | (rsp->length * sizeof(response_t)); | 1240 | (rsp->length * sizeof(response_t)); |
1235 | } | 1241 | } |
1242 | if (ha->tgt.atio_q_length) | ||
1243 | mq_size += ha->tgt.atio_q_length * sizeof(request_t); | ||
1236 | /* Allocate memory for Fibre Channel Event Buffer. */ | 1244 | /* Allocate memory for Fibre Channel Event Buffer. */ |
1237 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha)) | 1245 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha)) |
1238 | goto try_eft; | 1246 | goto try_eft; |
@@ -1696,6 +1704,12 @@ qla24xx_config_rings(struct scsi_qla_host *vha) | |||
1696 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); | 1704 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
1697 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); | 1705 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
1698 | 1706 | ||
1707 | /* Setup ATIO queue dma pointers for target mode */ | ||
1708 | icb->atio_q_inpointer = __constant_cpu_to_le16(0); | ||
1709 | icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); | ||
1710 | icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma)); | ||
1711 | icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma)); | ||
1712 | |||
1699 | if (ha->mqenable || IS_QLA83XX(ha)) { | 1713 | if (ha->mqenable || IS_QLA83XX(ha)) { |
1700 | icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS); | 1714 | icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
1701 | icb->rid = __constant_cpu_to_le16(rid); | 1715 | icb->rid = __constant_cpu_to_le16(rid); |
@@ -1739,6 +1753,8 @@ qla24xx_config_rings(struct scsi_qla_host *vha) | |||
1739 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); | 1753 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
1740 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); | 1754 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
1741 | } | 1755 | } |
1756 | qlt_24xx_config_rings(vha, reg); | ||
1757 | |||
1742 | /* PCI posting */ | 1758 | /* PCI posting */ |
1743 | RD_REG_DWORD(&ioreg->hccr); | 1759 | RD_REG_DWORD(&ioreg->hccr); |
1744 | } | 1760 | } |
@@ -1794,6 +1810,11 @@ qla2x00_init_rings(scsi_qla_host_t *vha) | |||
1794 | 1810 | ||
1795 | spin_unlock(&ha->vport_slock); | 1811 | spin_unlock(&ha->vport_slock); |
1796 | 1812 | ||
1813 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; | ||
1814 | ha->tgt.atio_ring_index = 0; | ||
1815 | /* Initialize ATIO queue entries */ | ||
1816 | qlt_init_atio_q_entries(vha); | ||
1817 | |||
1797 | ha->isp_ops->config_rings(vha); | 1818 | ha->isp_ops->config_rings(vha); |
1798 | 1819 | ||
1799 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 1820 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
@@ -2051,6 +2072,10 @@ qla2x00_configure_hba(scsi_qla_host_t *vha) | |||
2051 | vha->d_id.b.area = area; | 2072 | vha->d_id.b.area = area; |
2052 | vha->d_id.b.al_pa = al_pa; | 2073 | vha->d_id.b.al_pa = al_pa; |
2053 | 2074 | ||
2075 | spin_lock(&ha->vport_slock); | ||
2076 | qlt_update_vp_map(vha, SET_AL_PA); | ||
2077 | spin_unlock(&ha->vport_slock); | ||
2078 | |||
2054 | if (!vha->flags.init_done) | 2079 | if (!vha->flags.init_done) |
2055 | ql_log(ql_log_info, vha, 0x2010, | 2080 | ql_log(ql_log_info, vha, 0x2010, |
2056 | "Topology - %s, Host Loop address 0x%x.\n", | 2081 | "Topology - %s, Host Loop address 0x%x.\n", |
@@ -2270,7 +2295,7 @@ qla2x00_nvram_config(scsi_qla_host_t *vha) | |||
2270 | if (IS_QLA23XX(ha)) { | 2295 | if (IS_QLA23XX(ha)) { |
2271 | nv->firmware_options[0] |= BIT_2; | 2296 | nv->firmware_options[0] |= BIT_2; |
2272 | nv->firmware_options[0] &= ~BIT_3; | 2297 | nv->firmware_options[0] &= ~BIT_3; |
2273 | nv->firmware_options[0] &= ~BIT_6; | 2298 | nv->special_options[0] &= ~BIT_6; |
2274 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; | 2299 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
2275 | 2300 | ||
2276 | if (IS_QLA2300(ha)) { | 2301 | if (IS_QLA2300(ha)) { |
@@ -2467,14 +2492,21 @@ qla2x00_rport_del(void *data) | |||
2467 | { | 2492 | { |
2468 | fc_port_t *fcport = data; | 2493 | fc_port_t *fcport = data; |
2469 | struct fc_rport *rport; | 2494 | struct fc_rport *rport; |
2495 | scsi_qla_host_t *vha = fcport->vha; | ||
2470 | unsigned long flags; | 2496 | unsigned long flags; |
2471 | 2497 | ||
2472 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); | 2498 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
2473 | rport = fcport->drport ? fcport->drport: fcport->rport; | 2499 | rport = fcport->drport ? fcport->drport: fcport->rport; |
2474 | fcport->drport = NULL; | 2500 | fcport->drport = NULL; |
2475 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); | 2501 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
2476 | if (rport) | 2502 | if (rport) { |
2477 | fc_remote_port_delete(rport); | 2503 | fc_remote_port_delete(rport); |
2504 | /* | ||
2505 | * Release the target mode FC NEXUS in qla_target.c code | ||
2506 | * if target mod is enabled. | ||
2507 | */ | ||
2508 | qlt_fc_port_deleted(vha, fcport); | ||
2509 | } | ||
2478 | } | 2510 | } |
2479 | 2511 | ||
2480 | /** | 2512 | /** |
@@ -2853,6 +2885,12 @@ qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) | |||
2853 | "Unable to allocate fc remote port.\n"); | 2885 | "Unable to allocate fc remote port.\n"); |
2854 | return; | 2886 | return; |
2855 | } | 2887 | } |
2888 | /* | ||
2889 | * Create target mode FC NEXUS in qla_target.c if target mode is | ||
2890 | * enabled.. | ||
2891 | */ | ||
2892 | qlt_fc_port_added(vha, fcport); | ||
2893 | |||
2856 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); | 2894 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
2857 | *((fc_port_t **)rport->dd_data) = fcport; | 2895 | *((fc_port_t **)rport->dd_data) = fcport; |
2858 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); | 2896 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
@@ -3532,6 +3570,12 @@ qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, | |||
3532 | if (mb[10] & BIT_1) | 3570 | if (mb[10] & BIT_1) |
3533 | fcport->supported_classes |= FC_COS_CLASS3; | 3571 | fcport->supported_classes |= FC_COS_CLASS3; |
3534 | 3572 | ||
3573 | if (IS_FWI2_CAPABLE(ha)) { | ||
3574 | if (mb[10] & BIT_7) | ||
3575 | fcport->flags |= | ||
3576 | FCF_CONF_COMP_SUPPORTED; | ||
3577 | } | ||
3578 | |||
3535 | rval = QLA_SUCCESS; | 3579 | rval = QLA_SUCCESS; |
3536 | break; | 3580 | break; |
3537 | } else if (mb[0] == MBS_LOOP_ID_USED) { | 3581 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
@@ -4003,6 +4047,7 @@ qla2x00_restart_isp(scsi_qla_host_t *vha) | |||
4003 | struct qla_hw_data *ha = vha->hw; | 4047 | struct qla_hw_data *ha = vha->hw; |
4004 | struct req_que *req = ha->req_q_map[0]; | 4048 | struct req_que *req = ha->req_q_map[0]; |
4005 | struct rsp_que *rsp = ha->rsp_q_map[0]; | 4049 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
4050 | unsigned long flags; | ||
4006 | 4051 | ||
4007 | /* If firmware needs to be loaded */ | 4052 | /* If firmware needs to be loaded */ |
4008 | if (qla2x00_isp_firmware(vha)) { | 4053 | if (qla2x00_isp_firmware(vha)) { |
@@ -4027,6 +4072,16 @@ qla2x00_restart_isp(scsi_qla_host_t *vha) | |||
4027 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); | 4072 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
4028 | 4073 | ||
4029 | vha->flags.online = 1; | 4074 | vha->flags.online = 1; |
4075 | |||
4076 | /* | ||
4077 | * Process any ATIO queue entries that came in | ||
4078 | * while we weren't online. | ||
4079 | */ | ||
4080 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
4081 | if (qla_tgt_mode_enabled(vha)) | ||
4082 | qlt_24xx_process_atio_queue(vha); | ||
4083 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
4084 | |||
4030 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ | 4085 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
4031 | wait_time = 256; | 4086 | wait_time = 256; |
4032 | do { | 4087 | do { |
@@ -4267,6 +4322,15 @@ qla24xx_nvram_config(scsi_qla_host_t *vha) | |||
4267 | rval = 1; | 4322 | rval = 1; |
4268 | } | 4323 | } |
4269 | 4324 | ||
4325 | if (!qla_ini_mode_enabled(vha)) { | ||
4326 | /* Don't enable full login after initial LIP */ | ||
4327 | nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13); | ||
4328 | /* Don't enable LIP full login for initiator */ | ||
4329 | nv->host_p &= __constant_cpu_to_le32(~BIT_10); | ||
4330 | } | ||
4331 | |||
4332 | qlt_24xx_config_nvram_stage1(vha, nv); | ||
4333 | |||
4270 | /* Reset Initialization control block */ | 4334 | /* Reset Initialization control block */ |
4271 | memset(icb, 0, ha->init_cb_size); | 4335 | memset(icb, 0, ha->init_cb_size); |
4272 | 4336 | ||
@@ -4294,8 +4358,10 @@ qla24xx_nvram_config(scsi_qla_host_t *vha) | |||
4294 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), | 4358 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
4295 | "QLA2462"); | 4359 | "QLA2462"); |
4296 | 4360 | ||
4297 | /* Use alternate WWN? */ | 4361 | qlt_24xx_config_nvram_stage2(vha, icb); |
4362 | |||
4298 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { | 4363 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
4364 | /* Use alternate WWN? */ | ||
4299 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); | 4365 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
4300 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); | 4366 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
4301 | } | 4367 | } |
diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c index 6bf6c08650e8..73cc96da9421 100644 --- a/drivers/scsi/qla2xxx/qla_iocb.c +++ b/drivers/scsi/qla2xxx/qla_iocb.c | |||
@@ -5,6 +5,7 @@ | |||
5 | * See LICENSE.qla2xxx for copyright and licensing details. | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
6 | */ | 6 | */ |
7 | #include "qla_def.h" | 7 | #include "qla_def.h" |
8 | #include "qla_target.h" | ||
8 | 9 | ||
9 | #include <linux/blkdev.h> | 10 | #include <linux/blkdev.h> |
10 | #include <linux/delay.h> | 11 | #include <linux/delay.h> |
@@ -470,7 +471,7 @@ queuing_error: | |||
470 | /** | 471 | /** |
471 | * qla2x00_start_iocbs() - Execute the IOCB command | 472 | * qla2x00_start_iocbs() - Execute the IOCB command |
472 | */ | 473 | */ |
473 | static void | 474 | void |
474 | qla2x00_start_iocbs(struct scsi_qla_host *vha, struct req_que *req) | 475 | qla2x00_start_iocbs(struct scsi_qla_host *vha, struct req_que *req) |
475 | { | 476 | { |
476 | struct qla_hw_data *ha = vha->hw; | 477 | struct qla_hw_data *ha = vha->hw; |
@@ -571,6 +572,29 @@ qla2x00_marker(struct scsi_qla_host *vha, struct req_que *req, | |||
571 | return (ret); | 572 | return (ret); |
572 | } | 573 | } |
573 | 574 | ||
575 | /* | ||
576 | * qla2x00_issue_marker | ||
577 | * | ||
578 | * Issue marker | ||
579 | * Caller CAN have hardware lock held as specified by ha_locked parameter. | ||
580 | * Might release it, then reaquire. | ||
581 | */ | ||
582 | int qla2x00_issue_marker(scsi_qla_host_t *vha, int ha_locked) | ||
583 | { | ||
584 | if (ha_locked) { | ||
585 | if (__qla2x00_marker(vha, vha->req, vha->req->rsp, 0, 0, | ||
586 | MK_SYNC_ALL) != QLA_SUCCESS) | ||
587 | return QLA_FUNCTION_FAILED; | ||
588 | } else { | ||
589 | if (qla2x00_marker(vha, vha->req, vha->req->rsp, 0, 0, | ||
590 | MK_SYNC_ALL) != QLA_SUCCESS) | ||
591 | return QLA_FUNCTION_FAILED; | ||
592 | } | ||
593 | vha->marker_needed = 0; | ||
594 | |||
595 | return QLA_SUCCESS; | ||
596 | } | ||
597 | |||
574 | /** | 598 | /** |
575 | * qla24xx_calc_iocbs() - Determine number of Command Type 3 and | 599 | * qla24xx_calc_iocbs() - Determine number of Command Type 3 and |
576 | * Continuation Type 1 IOCBs to allocate. | 600 | * Continuation Type 1 IOCBs to allocate. |
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c index 0e716dcea944..6f67a9d4998b 100644 --- a/drivers/scsi/qla2xxx/qla_isr.c +++ b/drivers/scsi/qla2xxx/qla_isr.c | |||
@@ -5,6 +5,7 @@ | |||
5 | * See LICENSE.qla2xxx for copyright and licensing details. | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
6 | */ | 6 | */ |
7 | #include "qla_def.h" | 7 | #include "qla_def.h" |
8 | #include "qla_target.h" | ||
8 | 9 | ||
9 | #include <linux/delay.h> | 10 | #include <linux/delay.h> |
10 | #include <linux/slab.h> | 11 | #include <linux/slab.h> |
@@ -473,8 +474,8 @@ skip_rio: | |||
473 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up */ | 474 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up */ |
474 | ql_dbg(ql_dbg_async, vha, 0x5008, | 475 | ql_dbg(ql_dbg_async, vha, 0x5008, |
475 | "Asynchronous WAKEUP_THRES.\n"); | 476 | "Asynchronous WAKEUP_THRES.\n"); |
476 | break; | ||
477 | 477 | ||
478 | break; | ||
478 | case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */ | 479 | case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */ |
479 | ql_dbg(ql_dbg_async, vha, 0x5009, | 480 | ql_dbg(ql_dbg_async, vha, 0x5009, |
480 | "LIP occurred (%x).\n", mb[1]); | 481 | "LIP occurred (%x).\n", mb[1]); |
@@ -685,6 +686,8 @@ skip_rio: | |||
685 | ql_dbg(ql_dbg_async, vha, 0x5011, | 686 | ql_dbg(ql_dbg_async, vha, 0x5011, |
686 | "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n", | 687 | "Asynchronous PORT UPDATE ignored %04x/%04x/%04x.\n", |
687 | mb[1], mb[2], mb[3]); | 688 | mb[1], mb[2], mb[3]); |
689 | |||
690 | qlt_async_event(mb[0], vha, mb); | ||
688 | break; | 691 | break; |
689 | } | 692 | } |
690 | 693 | ||
@@ -702,8 +705,13 @@ skip_rio: | |||
702 | 705 | ||
703 | qla2x00_mark_all_devices_lost(vha, 1); | 706 | qla2x00_mark_all_devices_lost(vha, 1); |
704 | 707 | ||
708 | if (vha->vp_idx == 0 && !qla_ini_mode_enabled(vha)) | ||
709 | set_bit(SCR_PENDING, &vha->dpc_flags); | ||
710 | |||
705 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | 711 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
706 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | 712 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
713 | |||
714 | qlt_async_event(mb[0], vha, mb); | ||
707 | break; | 715 | break; |
708 | 716 | ||
709 | case MBA_RSCN_UPDATE: /* State Change Registration */ | 717 | case MBA_RSCN_UPDATE: /* State Change Registration */ |
@@ -825,6 +833,8 @@ skip_rio: | |||
825 | mb[0], mb[1], mb[2], mb[3]); | 833 | mb[0], mb[1], mb[2], mb[3]); |
826 | } | 834 | } |
827 | 835 | ||
836 | qlt_async_event(mb[0], vha, mb); | ||
837 | |||
828 | if (!vha->vp_idx && ha->num_vhosts) | 838 | if (!vha->vp_idx && ha->num_vhosts) |
829 | qla2x00_alert_all_vps(rsp, mb); | 839 | qla2x00_alert_all_vps(rsp, mb); |
830 | } | 840 | } |
@@ -1190,6 +1200,9 @@ qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req, | |||
1190 | } else if (iop[0] & BIT_5) | 1200 | } else if (iop[0] & BIT_5) |
1191 | fcport->port_type = FCT_INITIATOR; | 1201 | fcport->port_type = FCT_INITIATOR; |
1192 | 1202 | ||
1203 | if (iop[0] & BIT_7) | ||
1204 | fcport->flags |= FCF_CONF_COMP_SUPPORTED; | ||
1205 | |||
1193 | if (logio->io_parameter[7] || logio->io_parameter[8]) | 1206 | if (logio->io_parameter[7] || logio->io_parameter[8]) |
1194 | fcport->supported_classes |= FC_COS_CLASS2; | 1207 | fcport->supported_classes |= FC_COS_CLASS2; |
1195 | if (logio->io_parameter[9] || logio->io_parameter[10]) | 1208 | if (logio->io_parameter[9] || logio->io_parameter[10]) |
@@ -2004,6 +2017,9 @@ void qla24xx_process_response_queue(struct scsi_qla_host *vha, | |||
2004 | 2017 | ||
2005 | if (pkt->entry_status != 0) { | 2018 | if (pkt->entry_status != 0) { |
2006 | qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt); | 2019 | qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt); |
2020 | |||
2021 | (void)qlt_24xx_process_response_error(vha, pkt); | ||
2022 | |||
2007 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; | 2023 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; |
2008 | wmb(); | 2024 | wmb(); |
2009 | continue; | 2025 | continue; |
@@ -2034,6 +2050,14 @@ void qla24xx_process_response_queue(struct scsi_qla_host *vha, | |||
2034 | case ELS_IOCB_TYPE: | 2050 | case ELS_IOCB_TYPE: |
2035 | qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE); | 2051 | qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE); |
2036 | break; | 2052 | break; |
2053 | case ABTS_RECV_24XX: | ||
2054 | /* ensure that the ATIO queue is empty */ | ||
2055 | qlt_24xx_process_atio_queue(vha); | ||
2056 | case ABTS_RESP_24XX: | ||
2057 | case CTIO_TYPE7: | ||
2058 | case NOTIFY_ACK_TYPE: | ||
2059 | qlt_response_pkt_all_vps(vha, (response_t *)pkt); | ||
2060 | break; | ||
2037 | case MARKER_TYPE: | 2061 | case MARKER_TYPE: |
2038 | /* Do nothing in this case, this check is to prevent it | 2062 | /* Do nothing in this case, this check is to prevent it |
2039 | * from falling into default case | 2063 | * from falling into default case |
@@ -2186,6 +2210,13 @@ qla24xx_intr_handler(int irq, void *dev_id) | |||
2186 | case 0x14: | 2210 | case 0x14: |
2187 | qla24xx_process_response_queue(vha, rsp); | 2211 | qla24xx_process_response_queue(vha, rsp); |
2188 | break; | 2212 | break; |
2213 | case 0x1C: /* ATIO queue updated */ | ||
2214 | qlt_24xx_process_atio_queue(vha); | ||
2215 | break; | ||
2216 | case 0x1D: /* ATIO and response queues updated */ | ||
2217 | qlt_24xx_process_atio_queue(vha); | ||
2218 | qla24xx_process_response_queue(vha, rsp); | ||
2219 | break; | ||
2189 | default: | 2220 | default: |
2190 | ql_dbg(ql_dbg_async, vha, 0x504f, | 2221 | ql_dbg(ql_dbg_async, vha, 0x504f, |
2191 | "Unrecognized interrupt type (%d).\n", stat * 0xff); | 2222 | "Unrecognized interrupt type (%d).\n", stat * 0xff); |
@@ -2330,6 +2361,13 @@ qla24xx_msix_default(int irq, void *dev_id) | |||
2330 | case 0x14: | 2361 | case 0x14: |
2331 | qla24xx_process_response_queue(vha, rsp); | 2362 | qla24xx_process_response_queue(vha, rsp); |
2332 | break; | 2363 | break; |
2364 | case 0x1C: /* ATIO queue updated */ | ||
2365 | qlt_24xx_process_atio_queue(vha); | ||
2366 | break; | ||
2367 | case 0x1D: /* ATIO and response queues updated */ | ||
2368 | qlt_24xx_process_atio_queue(vha); | ||
2369 | qla24xx_process_response_queue(vha, rsp); | ||
2370 | break; | ||
2333 | default: | 2371 | default: |
2334 | ql_dbg(ql_dbg_async, vha, 0x5051, | 2372 | ql_dbg(ql_dbg_async, vha, 0x5051, |
2335 | "Unrecognized interrupt type (%d).\n", stat & 0xff); | 2373 | "Unrecognized interrupt type (%d).\n", stat & 0xff); |
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c index 07f4d3cbcc07..d5ce92c0a8fc 100644 --- a/drivers/scsi/qla2xxx/qla_mbx.c +++ b/drivers/scsi/qla2xxx/qla_mbx.c | |||
@@ -5,6 +5,7 @@ | |||
5 | * See LICENSE.qla2xxx for copyright and licensing details. | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
6 | */ | 6 | */ |
7 | #include "qla_def.h" | 7 | #include "qla_def.h" |
8 | #include "qla_target.h" | ||
8 | 9 | ||
9 | #include <linux/delay.h> | 10 | #include <linux/delay.h> |
10 | #include <linux/gfp.h> | 11 | #include <linux/gfp.h> |
@@ -1245,6 +1246,96 @@ qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size) | |||
1245 | } | 1246 | } |
1246 | 1247 | ||
1247 | /* | 1248 | /* |
1249 | * qla2x00_get_node_name_list | ||
1250 | * Issue get node name list mailbox command, kmalloc() | ||
1251 | * and return the resulting list. Caller must kfree() it! | ||
1252 | * | ||
1253 | * Input: | ||
1254 | * ha = adapter state pointer. | ||
1255 | * out_data = resulting list | ||
1256 | * out_len = length of the resulting list | ||
1257 | * | ||
1258 | * Returns: | ||
1259 | * qla2x00 local function return status code. | ||
1260 | * | ||
1261 | * Context: | ||
1262 | * Kernel context. | ||
1263 | */ | ||
1264 | int | ||
1265 | qla2x00_get_node_name_list(scsi_qla_host_t *vha, void **out_data, int *out_len) | ||
1266 | { | ||
1267 | struct qla_hw_data *ha = vha->hw; | ||
1268 | struct qla_port_24xx_data *list = NULL; | ||
1269 | void *pmap; | ||
1270 | mbx_cmd_t mc; | ||
1271 | dma_addr_t pmap_dma; | ||
1272 | ulong dma_size; | ||
1273 | int rval, left; | ||
1274 | |||
1275 | left = 1; | ||
1276 | while (left > 0) { | ||
1277 | dma_size = left * sizeof(*list); | ||
1278 | pmap = dma_alloc_coherent(&ha->pdev->dev, dma_size, | ||
1279 | &pmap_dma, GFP_KERNEL); | ||
1280 | if (!pmap) { | ||
1281 | ql_log(ql_log_warn, vha, 0x113f, | ||
1282 | "%s(%ld): DMA Alloc failed of %ld\n", | ||
1283 | __func__, vha->host_no, dma_size); | ||
1284 | rval = QLA_MEMORY_ALLOC_FAILED; | ||
1285 | goto out; | ||
1286 | } | ||
1287 | |||
1288 | mc.mb[0] = MBC_PORT_NODE_NAME_LIST; | ||
1289 | mc.mb[1] = BIT_1 | BIT_3; | ||
1290 | mc.mb[2] = MSW(pmap_dma); | ||
1291 | mc.mb[3] = LSW(pmap_dma); | ||
1292 | mc.mb[6] = MSW(MSD(pmap_dma)); | ||
1293 | mc.mb[7] = LSW(MSD(pmap_dma)); | ||
1294 | mc.mb[8] = dma_size; | ||
1295 | mc.out_mb = MBX_0|MBX_1|MBX_2|MBX_3|MBX_6|MBX_7|MBX_8; | ||
1296 | mc.in_mb = MBX_0|MBX_1; | ||
1297 | mc.tov = 30; | ||
1298 | mc.flags = MBX_DMA_IN; | ||
1299 | |||
1300 | rval = qla2x00_mailbox_command(vha, &mc); | ||
1301 | if (rval != QLA_SUCCESS) { | ||
1302 | if ((mc.mb[0] == MBS_COMMAND_ERROR) && | ||
1303 | (mc.mb[1] == 0xA)) { | ||
1304 | left += le16_to_cpu(mc.mb[2]) / | ||
1305 | sizeof(struct qla_port_24xx_data); | ||
1306 | goto restart; | ||
1307 | } | ||
1308 | goto out_free; | ||
1309 | } | ||
1310 | |||
1311 | left = 0; | ||
1312 | |||
1313 | list = kzalloc(dma_size, GFP_KERNEL); | ||
1314 | if (!list) { | ||
1315 | ql_log(ql_log_warn, vha, 0x1140, | ||
1316 | "%s(%ld): failed to allocate node names list " | ||
1317 | "structure.\n", __func__, vha->host_no); | ||
1318 | rval = QLA_MEMORY_ALLOC_FAILED; | ||
1319 | goto out_free; | ||
1320 | } | ||
1321 | |||
1322 | memcpy(list, pmap, dma_size); | ||
1323 | restart: | ||
1324 | dma_free_coherent(&ha->pdev->dev, dma_size, pmap, pmap_dma); | ||
1325 | } | ||
1326 | |||
1327 | *out_data = list; | ||
1328 | *out_len = dma_size; | ||
1329 | |||
1330 | out: | ||
1331 | return rval; | ||
1332 | |||
1333 | out_free: | ||
1334 | dma_free_coherent(&ha->pdev->dev, dma_size, pmap, pmap_dma); | ||
1335 | return rval; | ||
1336 | } | ||
1337 | |||
1338 | /* | ||
1248 | * qla2x00_get_port_database | 1339 | * qla2x00_get_port_database |
1249 | * Issue normal/enhanced get port database mailbox command | 1340 | * Issue normal/enhanced get port database mailbox command |
1250 | * and copy device name as necessary. | 1341 | * and copy device name as necessary. |
@@ -1352,6 +1443,13 @@ qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt) | |||
1352 | fcport->port_type = FCT_INITIATOR; | 1443 | fcport->port_type = FCT_INITIATOR; |
1353 | else | 1444 | else |
1354 | fcport->port_type = FCT_TARGET; | 1445 | fcport->port_type = FCT_TARGET; |
1446 | |||
1447 | /* Passback COS information. */ | ||
1448 | fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ? | ||
1449 | FC_COS_CLASS2 : FC_COS_CLASS3; | ||
1450 | |||
1451 | if (pd24->prli_svc_param_word_3[0] & BIT_7) | ||
1452 | fcport->flags |= FCF_CONF_COMP_SUPPORTED; | ||
1355 | } else { | 1453 | } else { |
1356 | uint64_t zero = 0; | 1454 | uint64_t zero = 0; |
1357 | 1455 | ||
@@ -1770,6 +1868,10 @@ qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain, | |||
1770 | mb[10] |= BIT_0; /* Class 2. */ | 1868 | mb[10] |= BIT_0; /* Class 2. */ |
1771 | if (lg->io_parameter[9] || lg->io_parameter[10]) | 1869 | if (lg->io_parameter[9] || lg->io_parameter[10]) |
1772 | mb[10] |= BIT_1; /* Class 3. */ | 1870 | mb[10] |= BIT_1; /* Class 3. */ |
1871 | if (lg->io_parameter[0] & __constant_cpu_to_le32(BIT_7)) | ||
1872 | mb[10] |= BIT_7; /* Confirmed Completion | ||
1873 | * Allowed | ||
1874 | */ | ||
1773 | } | 1875 | } |
1774 | 1876 | ||
1775 | dma_pool_free(ha->s_dma_pool, lg, lg_dma); | 1877 | dma_pool_free(ha->s_dma_pool, lg, lg_dma); |
@@ -3096,6 +3198,9 @@ qla24xx_modify_vp_config(scsi_qla_host_t *vha) | |||
3096 | vpmod->vp_count = 1; | 3198 | vpmod->vp_count = 1; |
3097 | vpmod->vp_index1 = vha->vp_idx; | 3199 | vpmod->vp_index1 = vha->vp_idx; |
3098 | vpmod->options_idx1 = BIT_3|BIT_4|BIT_5; | 3200 | vpmod->options_idx1 = BIT_3|BIT_4|BIT_5; |
3201 | |||
3202 | qlt_modify_vp_config(vha, vpmod); | ||
3203 | |||
3099 | memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE); | 3204 | memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE); |
3100 | memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE); | 3205 | memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE); |
3101 | vpmod->entry_count = 1; | 3206 | vpmod->entry_count = 1; |
@@ -3235,13 +3340,6 @@ qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format, | |||
3235 | ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7, | 3340 | ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7, |
3236 | "Entered %s.\n", __func__); | 3341 | "Entered %s.\n", __func__); |
3237 | 3342 | ||
3238 | /* | ||
3239 | * This command is implicitly executed by firmware during login for the | ||
3240 | * physical hosts | ||
3241 | */ | ||
3242 | if (vp_idx == 0) | ||
3243 | return QLA_FUNCTION_FAILED; | ||
3244 | |||
3245 | mcp->mb[0] = MBC_SEND_CHANGE_REQUEST; | 3343 | mcp->mb[0] = MBC_SEND_CHANGE_REQUEST; |
3246 | mcp->mb[1] = format; | 3344 | mcp->mb[1] = format; |
3247 | mcp->mb[9] = vp_idx; | 3345 | mcp->mb[9] = vp_idx; |
diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c index efb3cc3d6793..3e8b32419e68 100644 --- a/drivers/scsi/qla2xxx/qla_mid.c +++ b/drivers/scsi/qla2xxx/qla_mid.c | |||
@@ -6,6 +6,7 @@ | |||
6 | */ | 6 | */ |
7 | #include "qla_def.h" | 7 | #include "qla_def.h" |
8 | #include "qla_gbl.h" | 8 | #include "qla_gbl.h" |
9 | #include "qla_target.h" | ||
9 | 10 | ||
10 | #include <linux/moduleparam.h> | 11 | #include <linux/moduleparam.h> |
11 | #include <linux/vmalloc.h> | 12 | #include <linux/vmalloc.h> |
@@ -49,6 +50,9 @@ qla24xx_allocate_vp_id(scsi_qla_host_t *vha) | |||
49 | 50 | ||
50 | spin_lock_irqsave(&ha->vport_slock, flags); | 51 | spin_lock_irqsave(&ha->vport_slock, flags); |
51 | list_add_tail(&vha->list, &ha->vp_list); | 52 | list_add_tail(&vha->list, &ha->vp_list); |
53 | |||
54 | qlt_update_vp_map(vha, SET_VP_IDX); | ||
55 | |||
52 | spin_unlock_irqrestore(&ha->vport_slock, flags); | 56 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
53 | 57 | ||
54 | mutex_unlock(&ha->vport_lock); | 58 | mutex_unlock(&ha->vport_lock); |
@@ -79,6 +83,7 @@ qla24xx_deallocate_vp_id(scsi_qla_host_t *vha) | |||
79 | spin_lock_irqsave(&ha->vport_slock, flags); | 83 | spin_lock_irqsave(&ha->vport_slock, flags); |
80 | } | 84 | } |
81 | list_del(&vha->list); | 85 | list_del(&vha->list); |
86 | qlt_update_vp_map(vha, RESET_VP_IDX); | ||
82 | spin_unlock_irqrestore(&ha->vport_slock, flags); | 87 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
83 | 88 | ||
84 | vp_id = vha->vp_idx; | 89 | vp_id = vha->vp_idx; |
@@ -150,6 +155,9 @@ qla24xx_disable_vp(scsi_qla_host_t *vha) | |||
150 | atomic_set(&vha->loop_state, LOOP_DOWN); | 155 | atomic_set(&vha->loop_state, LOOP_DOWN); |
151 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | 156 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
152 | 157 | ||
158 | /* Remove port id from vp target map */ | ||
159 | qlt_update_vp_map(vha, RESET_AL_PA); | ||
160 | |||
153 | qla2x00_mark_vp_devices_dead(vha); | 161 | qla2x00_mark_vp_devices_dead(vha); |
154 | atomic_set(&vha->vp_state, VP_FAILED); | 162 | atomic_set(&vha->vp_state, VP_FAILED); |
155 | vha->flags.management_server_logged_in = 0; | 163 | vha->flags.management_server_logged_in = 0; |
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c index 9387f7914e66..9c50a8505f07 100644 --- a/drivers/scsi/qla2xxx/qla_os.c +++ b/drivers/scsi/qla2xxx/qla_os.c | |||
@@ -13,12 +13,13 @@ | |||
13 | #include <linux/mutex.h> | 13 | #include <linux/mutex.h> |
14 | #include <linux/kobject.h> | 14 | #include <linux/kobject.h> |
15 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
16 | |||
17 | #include <scsi/scsi_tcq.h> | 16 | #include <scsi/scsi_tcq.h> |
18 | #include <scsi/scsicam.h> | 17 | #include <scsi/scsicam.h> |
19 | #include <scsi/scsi_transport.h> | 18 | #include <scsi/scsi_transport.h> |
20 | #include <scsi/scsi_transport_fc.h> | 19 | #include <scsi/scsi_transport_fc.h> |
21 | 20 | ||
21 | #include "qla_target.h" | ||
22 | |||
22 | /* | 23 | /* |
23 | * Driver version | 24 | * Driver version |
24 | */ | 25 | */ |
@@ -40,6 +41,12 @@ static struct kmem_cache *ctx_cachep; | |||
40 | */ | 41 | */ |
41 | int ql_errlev = ql_log_all; | 42 | int ql_errlev = ql_log_all; |
42 | 43 | ||
44 | int ql2xenableclass2; | ||
45 | module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR); | ||
46 | MODULE_PARM_DESC(ql2xenableclass2, | ||
47 | "Specify if Class 2 operations are supported from the very " | ||
48 | "beginning. Default is 0 - class 2 not supported."); | ||
49 | |||
43 | int ql2xlogintimeout = 20; | 50 | int ql2xlogintimeout = 20; |
44 | module_param(ql2xlogintimeout, int, S_IRUGO); | 51 | module_param(ql2xlogintimeout, int, S_IRUGO); |
45 | MODULE_PARM_DESC(ql2xlogintimeout, | 52 | MODULE_PARM_DESC(ql2xlogintimeout, |
@@ -255,6 +262,8 @@ struct scsi_host_template qla2xxx_driver_template = { | |||
255 | 262 | ||
256 | .max_sectors = 0xFFFF, | 263 | .max_sectors = 0xFFFF, |
257 | .shost_attrs = qla2x00_host_attrs, | 264 | .shost_attrs = qla2x00_host_attrs, |
265 | |||
266 | .supported_mode = MODE_INITIATOR, | ||
258 | }; | 267 | }; |
259 | 268 | ||
260 | static struct scsi_transport_template *qla2xxx_transport_template = NULL; | 269 | static struct scsi_transport_template *qla2xxx_transport_template = NULL; |
@@ -2187,6 +2196,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) | |||
2187 | ql_dbg_pci(ql_dbg_init, pdev, 0x000a, | 2196 | ql_dbg_pci(ql_dbg_init, pdev, 0x000a, |
2188 | "Memory allocated for ha=%p.\n", ha); | 2197 | "Memory allocated for ha=%p.\n", ha); |
2189 | ha->pdev = pdev; | 2198 | ha->pdev = pdev; |
2199 | ha->tgt.enable_class_2 = ql2xenableclass2; | ||
2190 | 2200 | ||
2191 | /* Clear our data area */ | 2201 | /* Clear our data area */ |
2192 | ha->bars = bars; | 2202 | ha->bars = bars; |
@@ -2250,6 +2260,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) | |||
2250 | ha->mbx_count = MAILBOX_REGISTER_COUNT; | 2260 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
2251 | req_length = REQUEST_ENTRY_CNT_24XX; | 2261 | req_length = REQUEST_ENTRY_CNT_24XX; |
2252 | rsp_length = RESPONSE_ENTRY_CNT_2300; | 2262 | rsp_length = RESPONSE_ENTRY_CNT_2300; |
2263 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; | ||
2253 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; | 2264 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; |
2254 | ha->init_cb_size = sizeof(struct mid_init_cb_24xx); | 2265 | ha->init_cb_size = sizeof(struct mid_init_cb_24xx); |
2255 | ha->gid_list_info_size = 8; | 2266 | ha->gid_list_info_size = 8; |
@@ -2265,6 +2276,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) | |||
2265 | ha->mbx_count = MAILBOX_REGISTER_COUNT; | 2276 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
2266 | req_length = REQUEST_ENTRY_CNT_24XX; | 2277 | req_length = REQUEST_ENTRY_CNT_24XX; |
2267 | rsp_length = RESPONSE_ENTRY_CNT_2300; | 2278 | rsp_length = RESPONSE_ENTRY_CNT_2300; |
2279 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; | ||
2268 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; | 2280 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; |
2269 | ha->init_cb_size = sizeof(struct mid_init_cb_24xx); | 2281 | ha->init_cb_size = sizeof(struct mid_init_cb_24xx); |
2270 | ha->gid_list_info_size = 8; | 2282 | ha->gid_list_info_size = 8; |
@@ -2433,6 +2445,7 @@ que_init: | |||
2433 | goto probe_init_failed; | 2445 | goto probe_init_failed; |
2434 | } | 2446 | } |
2435 | 2447 | ||
2448 | qlt_probe_one_stage1(base_vha, ha); | ||
2436 | 2449 | ||
2437 | /* Set up the irqs */ | 2450 | /* Set up the irqs */ |
2438 | ret = qla2x00_request_irqs(ha, rsp); | 2451 | ret = qla2x00_request_irqs(ha, rsp); |
@@ -2521,6 +2534,14 @@ que_init: | |||
2521 | ql_dbg(ql_dbg_init, base_vha, 0x00ee, | 2534 | ql_dbg(ql_dbg_init, base_vha, 0x00ee, |
2522 | "DPC thread started successfully.\n"); | 2535 | "DPC thread started successfully.\n"); |
2523 | 2536 | ||
2537 | /* | ||
2538 | * If we're not coming up in initiator mode, we might sit for | ||
2539 | * a while without waking up the dpc thread, which leads to a | ||
2540 | * stuck process warning. So just kick the dpc once here and | ||
2541 | * let the kthread start (and go back to sleep in qla2x00_do_dpc). | ||
2542 | */ | ||
2543 | qla2xxx_wake_dpc(base_vha); | ||
2544 | |||
2524 | skip_dpc: | 2545 | skip_dpc: |
2525 | list_add_tail(&base_vha->list, &ha->vp_list); | 2546 | list_add_tail(&base_vha->list, &ha->vp_list); |
2526 | base_vha->host->irq = ha->pdev->irq; | 2547 | base_vha->host->irq = ha->pdev->irq; |
@@ -2566,7 +2587,11 @@ skip_dpc: | |||
2566 | ql_dbg(ql_dbg_init, base_vha, 0x00f2, | 2587 | ql_dbg(ql_dbg_init, base_vha, 0x00f2, |
2567 | "Init done and hba is online.\n"); | 2588 | "Init done and hba is online.\n"); |
2568 | 2589 | ||
2569 | scsi_scan_host(host); | 2590 | if (qla_ini_mode_enabled(base_vha)) |
2591 | scsi_scan_host(host); | ||
2592 | else | ||
2593 | ql_dbg(ql_dbg_init, base_vha, 0x0122, | ||
2594 | "skipping scsi_scan_host() for non-initiator port\n"); | ||
2570 | 2595 | ||
2571 | qla2x00_alloc_sysfs_attr(base_vha); | 2596 | qla2x00_alloc_sysfs_attr(base_vha); |
2572 | 2597 | ||
@@ -2584,6 +2609,8 @@ skip_dpc: | |||
2584 | base_vha->host_no, | 2609 | base_vha->host_no, |
2585 | ha->isp_ops->fw_version_str(base_vha, fw_str)); | 2610 | ha->isp_ops->fw_version_str(base_vha, fw_str)); |
2586 | 2611 | ||
2612 | qlt_add_target(ha, base_vha); | ||
2613 | |||
2587 | return 0; | 2614 | return 0; |
2588 | 2615 | ||
2589 | probe_init_failed: | 2616 | probe_init_failed: |
@@ -2632,6 +2659,22 @@ probe_out: | |||
2632 | } | 2659 | } |
2633 | 2660 | ||
2634 | static void | 2661 | static void |
2662 | qla2x00_stop_dpc_thread(scsi_qla_host_t *vha) | ||
2663 | { | ||
2664 | struct qla_hw_data *ha = vha->hw; | ||
2665 | struct task_struct *t = ha->dpc_thread; | ||
2666 | |||
2667 | if (ha->dpc_thread == NULL) | ||
2668 | return; | ||
2669 | /* | ||
2670 | * qla2xxx_wake_dpc checks for ->dpc_thread | ||
2671 | * so we need to zero it out. | ||
2672 | */ | ||
2673 | ha->dpc_thread = NULL; | ||
2674 | kthread_stop(t); | ||
2675 | } | ||
2676 | |||
2677 | static void | ||
2635 | qla2x00_shutdown(struct pci_dev *pdev) | 2678 | qla2x00_shutdown(struct pci_dev *pdev) |
2636 | { | 2679 | { |
2637 | scsi_qla_host_t *vha; | 2680 | scsi_qla_host_t *vha; |
@@ -2684,6 +2727,8 @@ qla2x00_remove_one(struct pci_dev *pdev) | |||
2684 | base_vha = pci_get_drvdata(pdev); | 2727 | base_vha = pci_get_drvdata(pdev); |
2685 | ha = base_vha->hw; | 2728 | ha = base_vha->hw; |
2686 | 2729 | ||
2730 | ha->flags.host_shutting_down = 1; | ||
2731 | |||
2687 | mutex_lock(&ha->vport_lock); | 2732 | mutex_lock(&ha->vport_lock); |
2688 | while (ha->cur_vport_count) { | 2733 | while (ha->cur_vport_count) { |
2689 | struct Scsi_Host *scsi_host; | 2734 | struct Scsi_Host *scsi_host; |
@@ -2737,6 +2782,7 @@ qla2x00_remove_one(struct pci_dev *pdev) | |||
2737 | ha->dpc_thread = NULL; | 2782 | ha->dpc_thread = NULL; |
2738 | kthread_stop(t); | 2783 | kthread_stop(t); |
2739 | } | 2784 | } |
2785 | qlt_remove_target(ha, base_vha); | ||
2740 | 2786 | ||
2741 | qla2x00_free_sysfs_attr(base_vha); | 2787 | qla2x00_free_sysfs_attr(base_vha); |
2742 | 2788 | ||
@@ -2788,17 +2834,7 @@ qla2x00_free_device(scsi_qla_host_t *vha) | |||
2788 | if (vha->timer_active) | 2834 | if (vha->timer_active) |
2789 | qla2x00_stop_timer(vha); | 2835 | qla2x00_stop_timer(vha); |
2790 | 2836 | ||
2791 | /* Kill the kernel thread for this host */ | 2837 | qla2x00_stop_dpc_thread(vha); |
2792 | if (ha->dpc_thread) { | ||
2793 | struct task_struct *t = ha->dpc_thread; | ||
2794 | |||
2795 | /* | ||
2796 | * qla2xxx_wake_dpc checks for ->dpc_thread | ||
2797 | * so we need to zero it out. | ||
2798 | */ | ||
2799 | ha->dpc_thread = NULL; | ||
2800 | kthread_stop(t); | ||
2801 | } | ||
2802 | 2838 | ||
2803 | qla25xx_delete_queues(vha); | 2839 | qla25xx_delete_queues(vha); |
2804 | 2840 | ||
@@ -2860,8 +2896,10 @@ qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport, | |||
2860 | spin_unlock_irqrestore(vha->host->host_lock, flags); | 2896 | spin_unlock_irqrestore(vha->host->host_lock, flags); |
2861 | set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags); | 2897 | set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags); |
2862 | qla2xxx_wake_dpc(base_vha); | 2898 | qla2xxx_wake_dpc(base_vha); |
2863 | } else | 2899 | } else { |
2864 | fc_remote_port_delete(rport); | 2900 | fc_remote_port_delete(rport); |
2901 | qlt_fc_port_deleted(vha, fcport); | ||
2902 | } | ||
2865 | } | 2903 | } |
2866 | 2904 | ||
2867 | /* | 2905 | /* |
@@ -2964,10 +3002,13 @@ qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len, | |||
2964 | if (!ha->init_cb) | 3002 | if (!ha->init_cb) |
2965 | goto fail; | 3003 | goto fail; |
2966 | 3004 | ||
3005 | if (qlt_mem_alloc(ha) < 0) | ||
3006 | goto fail_free_init_cb; | ||
3007 | |||
2967 | ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, | 3008 | ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, |
2968 | qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL); | 3009 | qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL); |
2969 | if (!ha->gid_list) | 3010 | if (!ha->gid_list) |
2970 | goto fail_free_init_cb; | 3011 | goto fail_free_tgt_mem; |
2971 | 3012 | ||
2972 | ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); | 3013 | ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); |
2973 | if (!ha->srb_mempool) | 3014 | if (!ha->srb_mempool) |
@@ -3185,6 +3226,8 @@ fail_free_gid_list: | |||
3185 | ha->gid_list_dma); | 3226 | ha->gid_list_dma); |
3186 | ha->gid_list = NULL; | 3227 | ha->gid_list = NULL; |
3187 | ha->gid_list_dma = 0; | 3228 | ha->gid_list_dma = 0; |
3229 | fail_free_tgt_mem: | ||
3230 | qlt_mem_free(ha); | ||
3188 | fail_free_init_cb: | 3231 | fail_free_init_cb: |
3189 | dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb, | 3232 | dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb, |
3190 | ha->init_cb_dma); | 3233 | ha->init_cb_dma); |
@@ -3300,6 +3343,8 @@ qla2x00_mem_free(struct qla_hw_data *ha) | |||
3300 | if (ha->ctx_mempool) | 3343 | if (ha->ctx_mempool) |
3301 | mempool_destroy(ha->ctx_mempool); | 3344 | mempool_destroy(ha->ctx_mempool); |
3302 | 3345 | ||
3346 | qlt_mem_free(ha); | ||
3347 | |||
3303 | if (ha->init_cb) | 3348 | if (ha->init_cb) |
3304 | dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, | 3349 | dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, |
3305 | ha->init_cb, ha->init_cb_dma); | 3350 | ha->init_cb, ha->init_cb_dma); |
@@ -3329,6 +3374,10 @@ qla2x00_mem_free(struct qla_hw_data *ha) | |||
3329 | 3374 | ||
3330 | ha->gid_list = NULL; | 3375 | ha->gid_list = NULL; |
3331 | ha->gid_list_dma = 0; | 3376 | ha->gid_list_dma = 0; |
3377 | |||
3378 | ha->tgt.atio_ring = NULL; | ||
3379 | ha->tgt.atio_dma = 0; | ||
3380 | ha->tgt.tgt_vp_map = NULL; | ||
3332 | } | 3381 | } |
3333 | 3382 | ||
3334 | struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht, | 3383 | struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht, |
@@ -3757,6 +3806,16 @@ qla2x00_do_dpc(void *data) | |||
3757 | clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags); | 3806 | clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags); |
3758 | } | 3807 | } |
3759 | 3808 | ||
3809 | if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) { | ||
3810 | int ret; | ||
3811 | ret = qla2x00_send_change_request(base_vha, 0x3, 0); | ||
3812 | if (ret != QLA_SUCCESS) | ||
3813 | ql_log(ql_log_warn, base_vha, 0x121, | ||
3814 | "Failed to enable receiving of RSCN " | ||
3815 | "requests: 0x%x.\n", ret); | ||
3816 | clear_bit(SCR_PENDING, &base_vha->dpc_flags); | ||
3817 | } | ||
3818 | |||
3760 | if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) { | 3819 | if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) { |
3761 | ql_dbg(ql_dbg_dpc, base_vha, 0x4009, | 3820 | ql_dbg(ql_dbg_dpc, base_vha, 0x4009, |
3762 | "Quiescence mode scheduled.\n"); | 3821 | "Quiescence mode scheduled.\n"); |
@@ -4475,6 +4534,21 @@ qla2x00_module_init(void) | |||
4475 | return -ENOMEM; | 4534 | return -ENOMEM; |
4476 | } | 4535 | } |
4477 | 4536 | ||
4537 | /* Initialize target kmem_cache and mem_pools */ | ||
4538 | ret = qlt_init(); | ||
4539 | if (ret < 0) { | ||
4540 | kmem_cache_destroy(srb_cachep); | ||
4541 | return ret; | ||
4542 | } else if (ret > 0) { | ||
4543 | /* | ||
4544 | * If initiator mode is explictly disabled by qlt_init(), | ||
4545 | * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from | ||
4546 | * performing scsi_scan_target() during LOOP UP event. | ||
4547 | */ | ||
4548 | qla2xxx_transport_functions.disable_target_scan = 1; | ||
4549 | qla2xxx_transport_vport_functions.disable_target_scan = 1; | ||
4550 | } | ||
4551 | |||
4478 | /* Derive version string. */ | 4552 | /* Derive version string. */ |
4479 | strcpy(qla2x00_version_str, QLA2XXX_VERSION); | 4553 | strcpy(qla2x00_version_str, QLA2XXX_VERSION); |
4480 | if (ql2xextended_error_logging) | 4554 | if (ql2xextended_error_logging) |
@@ -4486,6 +4560,7 @@ qla2x00_module_init(void) | |||
4486 | kmem_cache_destroy(srb_cachep); | 4560 | kmem_cache_destroy(srb_cachep); |
4487 | ql_log(ql_log_fatal, NULL, 0x0002, | 4561 | ql_log(ql_log_fatal, NULL, 0x0002, |
4488 | "fc_attach_transport failed...Failing load!.\n"); | 4562 | "fc_attach_transport failed...Failing load!.\n"); |
4563 | qlt_exit(); | ||
4489 | return -ENODEV; | 4564 | return -ENODEV; |
4490 | } | 4565 | } |
4491 | 4566 | ||
@@ -4499,6 +4574,7 @@ qla2x00_module_init(void) | |||
4499 | fc_attach_transport(&qla2xxx_transport_vport_functions); | 4574 | fc_attach_transport(&qla2xxx_transport_vport_functions); |
4500 | if (!qla2xxx_transport_vport_template) { | 4575 | if (!qla2xxx_transport_vport_template) { |
4501 | kmem_cache_destroy(srb_cachep); | 4576 | kmem_cache_destroy(srb_cachep); |
4577 | qlt_exit(); | ||
4502 | fc_release_transport(qla2xxx_transport_template); | 4578 | fc_release_transport(qla2xxx_transport_template); |
4503 | ql_log(ql_log_fatal, NULL, 0x0004, | 4579 | ql_log(ql_log_fatal, NULL, 0x0004, |
4504 | "fc_attach_transport vport failed...Failing load!.\n"); | 4580 | "fc_attach_transport vport failed...Failing load!.\n"); |
@@ -4510,6 +4586,7 @@ qla2x00_module_init(void) | |||
4510 | ret = pci_register_driver(&qla2xxx_pci_driver); | 4586 | ret = pci_register_driver(&qla2xxx_pci_driver); |
4511 | if (ret) { | 4587 | if (ret) { |
4512 | kmem_cache_destroy(srb_cachep); | 4588 | kmem_cache_destroy(srb_cachep); |
4589 | qlt_exit(); | ||
4513 | fc_release_transport(qla2xxx_transport_template); | 4590 | fc_release_transport(qla2xxx_transport_template); |
4514 | fc_release_transport(qla2xxx_transport_vport_template); | 4591 | fc_release_transport(qla2xxx_transport_vport_template); |
4515 | ql_log(ql_log_fatal, NULL, 0x0006, | 4592 | ql_log(ql_log_fatal, NULL, 0x0006, |
@@ -4529,6 +4606,7 @@ qla2x00_module_exit(void) | |||
4529 | pci_unregister_driver(&qla2xxx_pci_driver); | 4606 | pci_unregister_driver(&qla2xxx_pci_driver); |
4530 | qla2x00_release_firmware(); | 4607 | qla2x00_release_firmware(); |
4531 | kmem_cache_destroy(srb_cachep); | 4608 | kmem_cache_destroy(srb_cachep); |
4609 | qlt_exit(); | ||
4532 | if (ctx_cachep) | 4610 | if (ctx_cachep) |
4533 | kmem_cache_destroy(ctx_cachep); | 4611 | kmem_cache_destroy(ctx_cachep); |
4534 | fc_release_transport(qla2xxx_transport_template); | 4612 | fc_release_transport(qla2xxx_transport_template); |
diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c new file mode 100644 index 000000000000..04f80ebf09eb --- /dev/null +++ b/drivers/scsi/qla2xxx/qla_target.c | |||
@@ -0,0 +1,4973 @@ | |||
1 | /* | ||
2 | * qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx | ||
3 | * | ||
4 | * based on qla2x00t.c code: | ||
5 | * | ||
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. | ||
10 | * | ||
11 | * Forward port and refactoring to modern qla2xxx and target/configfs | ||
12 | * | ||
13 | * Copyright (C) 2010-2011 Nicholas A. Bellinger <nab@kernel.org> | ||
14 | * | ||
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 | ||
18 | * of the License. | ||
19 | * | ||
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. | ||
24 | */ | ||
25 | |||
26 | #include <linux/module.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/types.h> | ||
29 | #include <linux/version.h> | ||
30 | #include <linux/blkdev.h> | ||
31 | #include <linux/interrupt.h> | ||
32 | #include <linux/pci.h> | ||
33 | #include <linux/delay.h> | ||
34 | #include <linux/list.h> | ||
35 | #include <linux/workqueue.h> | ||
36 | #include <asm/unaligned.h> | ||
37 | #include <scsi/scsi.h> | ||
38 | #include <scsi/scsi_host.h> | ||
39 | #include <scsi/scsi_tcq.h> | ||
40 | #include <target/target_core_base.h> | ||
41 | #include <target/target_core_fabric.h> | ||
42 | |||
43 | #include "qla_def.h" | ||
44 | #include "qla_target.h" | ||
45 | |||
46 | static char *qlini_mode = QLA2XXX_INI_MODE_STR_ENABLED; | ||
47 | module_param(qlini_mode, charp, S_IRUGO); | ||
48 | MODULE_PARM_DESC(qlini_mode, | ||
49 | "Determines when initiator mode will be enabled. Possible values: " | ||
50 | "\"exclusive\" - initiator mode will be enabled on load, " | ||
51 | "disabled on enabling target mode and then on disabling target mode " | ||
52 | "enabled back; " | ||
53 | "\"disabled\" - initiator mode will never be enabled; " | ||
54 | "\"enabled\" (default) - initiator mode will always stay enabled."); | ||
55 | |||
56 | static int ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; | ||
57 | |||
58 | /* | ||
59 | * From scsi/fc/fc_fcp.h | ||
60 | */ | ||
61 | enum fcp_resp_rsp_codes { | ||
62 | FCP_TMF_CMPL = 0, | ||
63 | FCP_DATA_LEN_INVALID = 1, | ||
64 | FCP_CMND_FIELDS_INVALID = 2, | ||
65 | FCP_DATA_PARAM_MISMATCH = 3, | ||
66 | FCP_TMF_REJECTED = 4, | ||
67 | FCP_TMF_FAILED = 5, | ||
68 | FCP_TMF_INVALID_LUN = 9, | ||
69 | }; | ||
70 | |||
71 | /* | ||
72 | * fc_pri_ta from scsi/fc/fc_fcp.h | ||
73 | */ | ||
74 | #define FCP_PTA_SIMPLE 0 /* simple task attribute */ | ||
75 | #define FCP_PTA_HEADQ 1 /* head of queue task attribute */ | ||
76 | #define FCP_PTA_ORDERED 2 /* ordered task attribute */ | ||
77 | #define FCP_PTA_ACA 4 /* auto. contigent allegiance */ | ||
78 | #define FCP_PTA_MASK 7 /* mask for task attribute field */ | ||
79 | #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */ | ||
80 | #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */ | ||
81 | |||
82 | /* | ||
83 | * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which | ||
84 | * must be called under HW lock and could unlock/lock it inside. | ||
85 | * It isn't an issue, since in the current implementation on the time when | ||
86 | * those functions are called: | ||
87 | * | ||
88 | * - Either context is IRQ and only IRQ handler can modify HW data, | ||
89 | * including rings related fields, | ||
90 | * | ||
91 | * - Or access to target mode variables from struct qla_tgt doesn't | ||
92 | * cross those functions boundaries, except tgt_stop, which | ||
93 | * additionally protected by irq_cmd_count. | ||
94 | */ | ||
95 | /* Predefs for callbacks handed to qla2xxx LLD */ | ||
96 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha, | ||
97 | struct atio_from_isp *pkt); | ||
98 | static void qlt_response_pkt(struct scsi_qla_host *ha, response_t *pkt); | ||
99 | static int qlt_issue_task_mgmt(struct qla_tgt_sess *sess, uint32_t lun, | ||
100 | int fn, void *iocb, int flags); | ||
101 | static void qlt_send_term_exchange(struct scsi_qla_host *ha, struct qla_tgt_cmd | ||
102 | *cmd, struct atio_from_isp *atio, int ha_locked); | ||
103 | static void qlt_reject_free_srr_imm(struct scsi_qla_host *ha, | ||
104 | struct qla_tgt_srr_imm *imm, int ha_lock); | ||
105 | /* | ||
106 | * Global Variables | ||
107 | */ | ||
108 | static struct kmem_cache *qla_tgt_cmd_cachep; | ||
109 | static struct kmem_cache *qla_tgt_mgmt_cmd_cachep; | ||
110 | static mempool_t *qla_tgt_mgmt_cmd_mempool; | ||
111 | static struct workqueue_struct *qla_tgt_wq; | ||
112 | static DEFINE_MUTEX(qla_tgt_mutex); | ||
113 | static LIST_HEAD(qla_tgt_glist); | ||
114 | |||
115 | /* ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) */ | ||
116 | static struct qla_tgt_sess *qlt_find_sess_by_port_name( | ||
117 | struct qla_tgt *tgt, | ||
118 | const uint8_t *port_name) | ||
119 | { | ||
120 | struct qla_tgt_sess *sess; | ||
121 | |||
122 | list_for_each_entry(sess, &tgt->sess_list, sess_list_entry) { | ||
123 | if (!memcmp(sess->port_name, port_name, WWN_SIZE)) | ||
124 | return sess; | ||
125 | } | ||
126 | |||
127 | return NULL; | ||
128 | } | ||
129 | |||
130 | /* Might release hw lock, then reaquire!! */ | ||
131 | static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked) | ||
132 | { | ||
133 | /* Send marker if required */ | ||
134 | if (unlikely(vha->marker_needed != 0)) { | ||
135 | int rc = qla2x00_issue_marker(vha, vha_locked); | ||
136 | if (rc != QLA_SUCCESS) { | ||
137 | ql_dbg(ql_dbg_tgt, vha, 0xe03d, | ||
138 | "qla_target(%d): issue_marker() failed\n", | ||
139 | vha->vp_idx); | ||
140 | } | ||
141 | return rc; | ||
142 | } | ||
143 | return QLA_SUCCESS; | ||
144 | } | ||
145 | |||
146 | static inline | ||
147 | struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha, | ||
148 | uint8_t *d_id) | ||
149 | { | ||
150 | struct qla_hw_data *ha = vha->hw; | ||
151 | uint8_t vp_idx; | ||
152 | |||
153 | if ((vha->d_id.b.area != d_id[1]) || (vha->d_id.b.domain != d_id[0])) | ||
154 | return NULL; | ||
155 | |||
156 | if (vha->d_id.b.al_pa == d_id[2]) | ||
157 | return vha; | ||
158 | |||
159 | BUG_ON(ha->tgt.tgt_vp_map == NULL); | ||
160 | vp_idx = ha->tgt.tgt_vp_map[d_id[2]].idx; | ||
161 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) | ||
162 | return ha->tgt.tgt_vp_map[vp_idx].vha; | ||
163 | |||
164 | return NULL; | ||
165 | } | ||
166 | |||
167 | static inline | ||
168 | struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha, | ||
169 | uint16_t vp_idx) | ||
170 | { | ||
171 | struct qla_hw_data *ha = vha->hw; | ||
172 | |||
173 | if (vha->vp_idx == vp_idx) | ||
174 | return vha; | ||
175 | |||
176 | BUG_ON(ha->tgt.tgt_vp_map == NULL); | ||
177 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) | ||
178 | return ha->tgt.tgt_vp_map[vp_idx].vha; | ||
179 | |||
180 | return NULL; | ||
181 | } | ||
182 | |||
183 | void qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host *vha, | ||
184 | struct atio_from_isp *atio) | ||
185 | { | ||
186 | switch (atio->u.raw.entry_type) { | ||
187 | case ATIO_TYPE7: | ||
188 | { | ||
189 | struct scsi_qla_host *host = qlt_find_host_by_d_id(vha, | ||
190 | atio->u.isp24.fcp_hdr.d_id); | ||
191 | if (unlikely(NULL == host)) { | ||
192 | ql_dbg(ql_dbg_tgt, vha, 0xe03e, | ||
193 | "qla_target(%d): Received ATIO_TYPE7 " | ||
194 | "with unknown d_id %x:%x:%x\n", vha->vp_idx, | ||
195 | atio->u.isp24.fcp_hdr.d_id[0], | ||
196 | atio->u.isp24.fcp_hdr.d_id[1], | ||
197 | atio->u.isp24.fcp_hdr.d_id[2]); | ||
198 | break; | ||
199 | } | ||
200 | qlt_24xx_atio_pkt(host, atio); | ||
201 | break; | ||
202 | } | ||
203 | |||
204 | case IMMED_NOTIFY_TYPE: | ||
205 | { | ||
206 | struct scsi_qla_host *host = vha; | ||
207 | struct imm_ntfy_from_isp *entry = | ||
208 | (struct imm_ntfy_from_isp *)atio; | ||
209 | |||
210 | if ((entry->u.isp24.vp_index != 0xFF) && | ||
211 | (entry->u.isp24.nport_handle != 0xFFFF)) { | ||
212 | host = qlt_find_host_by_vp_idx(vha, | ||
213 | entry->u.isp24.vp_index); | ||
214 | if (unlikely(!host)) { | ||
215 | ql_dbg(ql_dbg_tgt, vha, 0xe03f, | ||
216 | "qla_target(%d): Received " | ||
217 | "ATIO (IMMED_NOTIFY_TYPE) " | ||
218 | "with unknown vp_index %d\n", | ||
219 | vha->vp_idx, entry->u.isp24.vp_index); | ||
220 | break; | ||
221 | } | ||
222 | } | ||
223 | qlt_24xx_atio_pkt(host, atio); | ||
224 | break; | ||
225 | } | ||
226 | |||
227 | default: | ||
228 | ql_dbg(ql_dbg_tgt, vha, 0xe040, | ||
229 | "qla_target(%d): Received unknown ATIO atio " | ||
230 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); | ||
231 | break; | ||
232 | } | ||
233 | |||
234 | return; | ||
235 | } | ||
236 | |||
237 | void qlt_response_pkt_all_vps(struct scsi_qla_host *vha, response_t *pkt) | ||
238 | { | ||
239 | switch (pkt->entry_type) { | ||
240 | case CTIO_TYPE7: | ||
241 | { | ||
242 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; | ||
243 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, | ||
244 | entry->vp_index); | ||
245 | if (unlikely(!host)) { | ||
246 | ql_dbg(ql_dbg_tgt, vha, 0xe041, | ||
247 | "qla_target(%d): Response pkt (CTIO_TYPE7) " | ||
248 | "received, with unknown vp_index %d\n", | ||
249 | vha->vp_idx, entry->vp_index); | ||
250 | break; | ||
251 | } | ||
252 | qlt_response_pkt(host, pkt); | ||
253 | break; | ||
254 | } | ||
255 | |||
256 | case IMMED_NOTIFY_TYPE: | ||
257 | { | ||
258 | struct scsi_qla_host *host = vha; | ||
259 | struct imm_ntfy_from_isp *entry = | ||
260 | (struct imm_ntfy_from_isp *)pkt; | ||
261 | |||
262 | host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index); | ||
263 | if (unlikely(!host)) { | ||
264 | ql_dbg(ql_dbg_tgt, vha, 0xe042, | ||
265 | "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) " | ||
266 | "received, with unknown vp_index %d\n", | ||
267 | vha->vp_idx, entry->u.isp24.vp_index); | ||
268 | break; | ||
269 | } | ||
270 | qlt_response_pkt(host, pkt); | ||
271 | break; | ||
272 | } | ||
273 | |||
274 | case NOTIFY_ACK_TYPE: | ||
275 | { | ||
276 | struct scsi_qla_host *host = vha; | ||
277 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; | ||
278 | |||
279 | if (0xFF != entry->u.isp24.vp_index) { | ||
280 | host = qlt_find_host_by_vp_idx(vha, | ||
281 | entry->u.isp24.vp_index); | ||
282 | if (unlikely(!host)) { | ||
283 | ql_dbg(ql_dbg_tgt, vha, 0xe043, | ||
284 | "qla_target(%d): Response " | ||
285 | "pkt (NOTIFY_ACK_TYPE) " | ||
286 | "received, with unknown " | ||
287 | "vp_index %d\n", vha->vp_idx, | ||
288 | entry->u.isp24.vp_index); | ||
289 | break; | ||
290 | } | ||
291 | } | ||
292 | qlt_response_pkt(host, pkt); | ||
293 | break; | ||
294 | } | ||
295 | |||
296 | case ABTS_RECV_24XX: | ||
297 | { | ||
298 | struct abts_recv_from_24xx *entry = | ||
299 | (struct abts_recv_from_24xx *)pkt; | ||
300 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, | ||
301 | entry->vp_index); | ||
302 | if (unlikely(!host)) { | ||
303 | ql_dbg(ql_dbg_tgt, vha, 0xe044, | ||
304 | "qla_target(%d): Response pkt " | ||
305 | "(ABTS_RECV_24XX) received, with unknown " | ||
306 | "vp_index %d\n", vha->vp_idx, entry->vp_index); | ||
307 | break; | ||
308 | } | ||
309 | qlt_response_pkt(host, pkt); | ||
310 | break; | ||
311 | } | ||
312 | |||
313 | case ABTS_RESP_24XX: | ||
314 | { | ||
315 | struct abts_resp_to_24xx *entry = | ||
316 | (struct abts_resp_to_24xx *)pkt; | ||
317 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, | ||
318 | entry->vp_index); | ||
319 | if (unlikely(!host)) { | ||
320 | ql_dbg(ql_dbg_tgt, vha, 0xe045, | ||
321 | "qla_target(%d): Response pkt " | ||
322 | "(ABTS_RECV_24XX) received, with unknown " | ||
323 | "vp_index %d\n", vha->vp_idx, entry->vp_index); | ||
324 | break; | ||
325 | } | ||
326 | qlt_response_pkt(host, pkt); | ||
327 | break; | ||
328 | } | ||
329 | |||
330 | default: | ||
331 | qlt_response_pkt(vha, pkt); | ||
332 | break; | ||
333 | } | ||
334 | |||
335 | } | ||
336 | |||
337 | static void qlt_free_session_done(struct work_struct *work) | ||
338 | { | ||
339 | struct qla_tgt_sess *sess = container_of(work, struct qla_tgt_sess, | ||
340 | free_work); | ||
341 | struct qla_tgt *tgt = sess->tgt; | ||
342 | struct scsi_qla_host *vha = sess->vha; | ||
343 | struct qla_hw_data *ha = vha->hw; | ||
344 | |||
345 | BUG_ON(!tgt); | ||
346 | /* | ||
347 | * Release the target session for FC Nexus from fabric module code. | ||
348 | */ | ||
349 | if (sess->se_sess != NULL) | ||
350 | ha->tgt.tgt_ops->free_session(sess); | ||
351 | |||
352 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001, | ||
353 | "Unregistration of sess %p finished\n", sess); | ||
354 | |||
355 | kfree(sess); | ||
356 | /* | ||
357 | * We need to protect against race, when tgt is freed before or | ||
358 | * inside wake_up() | ||
359 | */ | ||
360 | tgt->sess_count--; | ||
361 | if (tgt->sess_count == 0) | ||
362 | wake_up_all(&tgt->waitQ); | ||
363 | } | ||
364 | |||
365 | /* ha->hardware_lock supposed to be held on entry */ | ||
366 | void qlt_unreg_sess(struct qla_tgt_sess *sess) | ||
367 | { | ||
368 | struct scsi_qla_host *vha = sess->vha; | ||
369 | |||
370 | vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess); | ||
371 | |||
372 | list_del(&sess->sess_list_entry); | ||
373 | if (sess->deleted) | ||
374 | list_del(&sess->del_list_entry); | ||
375 | |||
376 | INIT_WORK(&sess->free_work, qlt_free_session_done); | ||
377 | schedule_work(&sess->free_work); | ||
378 | } | ||
379 | EXPORT_SYMBOL(qlt_unreg_sess); | ||
380 | |||
381 | /* ha->hardware_lock supposed to be held on entry */ | ||
382 | static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd) | ||
383 | { | ||
384 | struct qla_hw_data *ha = vha->hw; | ||
385 | struct qla_tgt_sess *sess = NULL; | ||
386 | uint32_t unpacked_lun, lun = 0; | ||
387 | uint16_t loop_id; | ||
388 | int res = 0; | ||
389 | struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb; | ||
390 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; | ||
391 | |||
392 | loop_id = le16_to_cpu(n->u.isp24.nport_handle); | ||
393 | if (loop_id == 0xFFFF) { | ||
394 | #if 0 /* FIXME: Re-enable Global event handling.. */ | ||
395 | /* Global event */ | ||
396 | atomic_inc(&ha->tgt.qla_tgt->tgt_global_resets_count); | ||
397 | qlt_clear_tgt_db(ha->tgt.qla_tgt, 1); | ||
398 | if (!list_empty(&ha->tgt.qla_tgt->sess_list)) { | ||
399 | sess = list_entry(ha->tgt.qla_tgt->sess_list.next, | ||
400 | typeof(*sess), sess_list_entry); | ||
401 | switch (mcmd) { | ||
402 | case QLA_TGT_NEXUS_LOSS_SESS: | ||
403 | mcmd = QLA_TGT_NEXUS_LOSS; | ||
404 | break; | ||
405 | case QLA_TGT_ABORT_ALL_SESS: | ||
406 | mcmd = QLA_TGT_ABORT_ALL; | ||
407 | break; | ||
408 | case QLA_TGT_NEXUS_LOSS: | ||
409 | case QLA_TGT_ABORT_ALL: | ||
410 | break; | ||
411 | default: | ||
412 | ql_dbg(ql_dbg_tgt, vha, 0xe046, | ||
413 | "qla_target(%d): Not allowed " | ||
414 | "command %x in %s", vha->vp_idx, | ||
415 | mcmd, __func__); | ||
416 | sess = NULL; | ||
417 | break; | ||
418 | } | ||
419 | } else | ||
420 | sess = NULL; | ||
421 | #endif | ||
422 | } else { | ||
423 | sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id); | ||
424 | } | ||
425 | |||
426 | ql_dbg(ql_dbg_tgt, vha, 0xe000, | ||
427 | "Using sess for qla_tgt_reset: %p\n", sess); | ||
428 | if (!sess) { | ||
429 | res = -ESRCH; | ||
430 | return res; | ||
431 | } | ||
432 | |||
433 | ql_dbg(ql_dbg_tgt, vha, 0xe047, | ||
434 | "scsi(%ld): resetting (session %p from port " | ||
435 | "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, " | ||
436 | "mcmd %x, loop_id %d)\n", vha->host_no, sess, | ||
437 | sess->port_name[0], sess->port_name[1], | ||
438 | sess->port_name[2], sess->port_name[3], | ||
439 | sess->port_name[4], sess->port_name[5], | ||
440 | sess->port_name[6], sess->port_name[7], | ||
441 | mcmd, loop_id); | ||
442 | |||
443 | lun = a->u.isp24.fcp_cmnd.lun; | ||
444 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); | ||
445 | |||
446 | return qlt_issue_task_mgmt(sess, unpacked_lun, mcmd, | ||
447 | iocb, QLA24XX_MGMT_SEND_NACK); | ||
448 | } | ||
449 | |||
450 | /* ha->hardware_lock supposed to be held on entry */ | ||
451 | static void qlt_schedule_sess_for_deletion(struct qla_tgt_sess *sess, | ||
452 | bool immediate) | ||
453 | { | ||
454 | struct qla_tgt *tgt = sess->tgt; | ||
455 | uint32_t dev_loss_tmo = tgt->ha->port_down_retry_count + 5; | ||
456 | |||
457 | if (sess->deleted) | ||
458 | return; | ||
459 | |||
460 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe001, | ||
461 | "Scheduling sess %p for deletion\n", sess); | ||
462 | list_add_tail(&sess->del_list_entry, &tgt->del_sess_list); | ||
463 | sess->deleted = 1; | ||
464 | |||
465 | if (immediate) | ||
466 | dev_loss_tmo = 0; | ||
467 | |||
468 | sess->expires = jiffies + dev_loss_tmo * HZ; | ||
469 | |||
470 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe048, | ||
471 | "qla_target(%d): session for port %02x:%02x:%02x:" | ||
472 | "%02x:%02x:%02x:%02x:%02x (loop ID %d) scheduled for " | ||
473 | "deletion in %u secs (expires: %lu) immed: %d\n", | ||
474 | sess->vha->vp_idx, | ||
475 | sess->port_name[0], sess->port_name[1], | ||
476 | sess->port_name[2], sess->port_name[3], | ||
477 | sess->port_name[4], sess->port_name[5], | ||
478 | sess->port_name[6], sess->port_name[7], | ||
479 | sess->loop_id, dev_loss_tmo, sess->expires, immediate); | ||
480 | |||
481 | if (immediate) | ||
482 | schedule_delayed_work(&tgt->sess_del_work, 0); | ||
483 | else | ||
484 | schedule_delayed_work(&tgt->sess_del_work, | ||
485 | jiffies - sess->expires); | ||
486 | } | ||
487 | |||
488 | /* ha->hardware_lock supposed to be held on entry */ | ||
489 | static void qlt_clear_tgt_db(struct qla_tgt *tgt, bool local_only) | ||
490 | { | ||
491 | struct qla_tgt_sess *sess; | ||
492 | |||
493 | list_for_each_entry(sess, &tgt->sess_list, sess_list_entry) | ||
494 | qlt_schedule_sess_for_deletion(sess, true); | ||
495 | |||
496 | /* At this point tgt could be already dead */ | ||
497 | } | ||
498 | |||
499 | static int qla24xx_get_loop_id(struct scsi_qla_host *vha, const uint8_t *s_id, | ||
500 | uint16_t *loop_id) | ||
501 | { | ||
502 | struct qla_hw_data *ha = vha->hw; | ||
503 | dma_addr_t gid_list_dma; | ||
504 | struct gid_list_info *gid_list; | ||
505 | char *id_iter; | ||
506 | int res, rc, i; | ||
507 | uint16_t entries; | ||
508 | |||
509 | gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), | ||
510 | &gid_list_dma, GFP_KERNEL); | ||
511 | if (!gid_list) { | ||
512 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044, | ||
513 | "qla_target(%d): DMA Alloc failed of %u\n", | ||
514 | vha->vp_idx, qla2x00_gid_list_size(ha)); | ||
515 | return -ENOMEM; | ||
516 | } | ||
517 | |||
518 | /* Get list of logged in devices */ | ||
519 | rc = qla2x00_get_id_list(vha, gid_list, gid_list_dma, &entries); | ||
520 | if (rc != QLA_SUCCESS) { | ||
521 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045, | ||
522 | "qla_target(%d): get_id_list() failed: %x\n", | ||
523 | vha->vp_idx, rc); | ||
524 | res = -1; | ||
525 | goto out_free_id_list; | ||
526 | } | ||
527 | |||
528 | id_iter = (char *)gid_list; | ||
529 | res = -1; | ||
530 | for (i = 0; i < entries; i++) { | ||
531 | struct gid_list_info *gid = (struct gid_list_info *)id_iter; | ||
532 | if ((gid->al_pa == s_id[2]) && | ||
533 | (gid->area == s_id[1]) && | ||
534 | (gid->domain == s_id[0])) { | ||
535 | *loop_id = le16_to_cpu(gid->loop_id); | ||
536 | res = 0; | ||
537 | break; | ||
538 | } | ||
539 | id_iter += ha->gid_list_info_size; | ||
540 | } | ||
541 | |||
542 | out_free_id_list: | ||
543 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), | ||
544 | gid_list, gid_list_dma); | ||
545 | return res; | ||
546 | } | ||
547 | |||
548 | static bool qlt_check_fcport_exist(struct scsi_qla_host *vha, | ||
549 | struct qla_tgt_sess *sess) | ||
550 | { | ||
551 | struct qla_hw_data *ha = vha->hw; | ||
552 | struct qla_port_24xx_data *pmap24; | ||
553 | bool res, found = false; | ||
554 | int rc, i; | ||
555 | uint16_t loop_id = 0xFFFF; /* to eliminate compiler's warning */ | ||
556 | uint16_t entries; | ||
557 | void *pmap; | ||
558 | int pmap_len; | ||
559 | fc_port_t *fcport; | ||
560 | int global_resets; | ||
561 | |||
562 | retry: | ||
563 | global_resets = atomic_read(&ha->tgt.qla_tgt->tgt_global_resets_count); | ||
564 | |||
565 | rc = qla2x00_get_node_name_list(vha, &pmap, &pmap_len); | ||
566 | if (rc != QLA_SUCCESS) { | ||
567 | res = false; | ||
568 | goto out; | ||
569 | } | ||
570 | |||
571 | pmap24 = pmap; | ||
572 | entries = pmap_len/sizeof(*pmap24); | ||
573 | |||
574 | for (i = 0; i < entries; ++i) { | ||
575 | if (!memcmp(sess->port_name, pmap24[i].port_name, WWN_SIZE)) { | ||
576 | loop_id = le16_to_cpu(pmap24[i].loop_id); | ||
577 | found = true; | ||
578 | break; | ||
579 | } | ||
580 | } | ||
581 | |||
582 | kfree(pmap); | ||
583 | |||
584 | if (!found) { | ||
585 | res = false; | ||
586 | goto out; | ||
587 | } | ||
588 | |||
589 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf046, | ||
590 | "qlt_check_fcport_exist(): loop_id %d", loop_id); | ||
591 | |||
592 | fcport = kzalloc(sizeof(*fcport), GFP_KERNEL); | ||
593 | if (fcport == NULL) { | ||
594 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf047, | ||
595 | "qla_target(%d): Allocation of tmp FC port failed", | ||
596 | vha->vp_idx); | ||
597 | res = false; | ||
598 | goto out; | ||
599 | } | ||
600 | |||
601 | fcport->loop_id = loop_id; | ||
602 | |||
603 | rc = qla2x00_get_port_database(vha, fcport, 0); | ||
604 | if (rc != QLA_SUCCESS) { | ||
605 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf048, | ||
606 | "qla_target(%d): Failed to retrieve fcport " | ||
607 | "information -- get_port_database() returned %x " | ||
608 | "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id); | ||
609 | res = false; | ||
610 | goto out_free_fcport; | ||
611 | } | ||
612 | |||
613 | if (global_resets != | ||
614 | atomic_read(&ha->tgt.qla_tgt->tgt_global_resets_count)) { | ||
615 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf002, | ||
616 | "qla_target(%d): global reset during session discovery" | ||
617 | " (counter was %d, new %d), retrying", | ||
618 | vha->vp_idx, global_resets, | ||
619 | atomic_read(&ha->tgt.qla_tgt->tgt_global_resets_count)); | ||
620 | goto retry; | ||
621 | } | ||
622 | |||
623 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003, | ||
624 | "Updating sess %p s_id %x:%x:%x, loop_id %d) to d_id %x:%x:%x, " | ||
625 | "loop_id %d", sess, sess->s_id.b.domain, sess->s_id.b.al_pa, | ||
626 | sess->s_id.b.area, sess->loop_id, fcport->d_id.b.domain, | ||
627 | fcport->d_id.b.al_pa, fcport->d_id.b.area, fcport->loop_id); | ||
628 | |||
629 | sess->s_id = fcport->d_id; | ||
630 | sess->loop_id = fcport->loop_id; | ||
631 | sess->conf_compl_supported = !!(fcport->flags & | ||
632 | FCF_CONF_COMP_SUPPORTED); | ||
633 | |||
634 | res = true; | ||
635 | |||
636 | out_free_fcport: | ||
637 | kfree(fcport); | ||
638 | |||
639 | out: | ||
640 | return res; | ||
641 | } | ||
642 | |||
643 | /* ha->hardware_lock supposed to be held on entry */ | ||
644 | static void qlt_undelete_sess(struct qla_tgt_sess *sess) | ||
645 | { | ||
646 | BUG_ON(!sess->deleted); | ||
647 | |||
648 | list_del(&sess->del_list_entry); | ||
649 | sess->deleted = 0; | ||
650 | } | ||
651 | |||
652 | static void qlt_del_sess_work_fn(struct delayed_work *work) | ||
653 | { | ||
654 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, | ||
655 | sess_del_work); | ||
656 | struct scsi_qla_host *vha = tgt->vha; | ||
657 | struct qla_hw_data *ha = vha->hw; | ||
658 | struct qla_tgt_sess *sess; | ||
659 | unsigned long flags; | ||
660 | |||
661 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
662 | while (!list_empty(&tgt->del_sess_list)) { | ||
663 | sess = list_entry(tgt->del_sess_list.next, typeof(*sess), | ||
664 | del_list_entry); | ||
665 | if (time_after_eq(jiffies, sess->expires)) { | ||
666 | bool cancel; | ||
667 | |||
668 | qlt_undelete_sess(sess); | ||
669 | |||
670 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
671 | cancel = qlt_check_fcport_exist(vha, sess); | ||
672 | |||
673 | if (cancel) { | ||
674 | if (sess->deleted) { | ||
675 | /* | ||
676 | * sess was again deleted while we were | ||
677 | * discovering it | ||
678 | */ | ||
679 | spin_lock_irqsave(&ha->hardware_lock, | ||
680 | flags); | ||
681 | continue; | ||
682 | } | ||
683 | |||
684 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf049, | ||
685 | "qla_target(%d): cancel deletion of " | ||
686 | "session for port %02x:%02x:%02x:%02x:%02x:" | ||
687 | "%02x:%02x:%02x (loop ID %d), because " | ||
688 | " it isn't deleted by firmware", | ||
689 | vha->vp_idx, sess->port_name[0], | ||
690 | sess->port_name[1], sess->port_name[2], | ||
691 | sess->port_name[3], sess->port_name[4], | ||
692 | sess->port_name[5], sess->port_name[6], | ||
693 | sess->port_name[7], sess->loop_id); | ||
694 | } else { | ||
695 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004, | ||
696 | "Timeout: sess %p about to be deleted\n", | ||
697 | sess); | ||
698 | ha->tgt.tgt_ops->shutdown_sess(sess); | ||
699 | ha->tgt.tgt_ops->put_sess(sess); | ||
700 | } | ||
701 | |||
702 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
703 | } else { | ||
704 | schedule_delayed_work(&tgt->sess_del_work, | ||
705 | jiffies - sess->expires); | ||
706 | break; | ||
707 | } | ||
708 | } | ||
709 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
710 | } | ||
711 | |||
712 | /* | ||
713 | * Adds an extra ref to allow to drop hw lock after adding sess to the list. | ||
714 | * Caller must put it. | ||
715 | */ | ||
716 | static struct qla_tgt_sess *qlt_create_sess( | ||
717 | struct scsi_qla_host *vha, | ||
718 | fc_port_t *fcport, | ||
719 | bool local) | ||
720 | { | ||
721 | struct qla_hw_data *ha = vha->hw; | ||
722 | struct qla_tgt_sess *sess; | ||
723 | unsigned long flags; | ||
724 | unsigned char be_sid[3]; | ||
725 | |||
726 | /* Check to avoid double sessions */ | ||
727 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
728 | list_for_each_entry(sess, &ha->tgt.qla_tgt->sess_list, | ||
729 | sess_list_entry) { | ||
730 | if (!memcmp(sess->port_name, fcport->port_name, WWN_SIZE)) { | ||
731 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf005, | ||
732 | "Double sess %p found (s_id %x:%x:%x, " | ||
733 | "loop_id %d), updating to d_id %x:%x:%x, " | ||
734 | "loop_id %d", sess, sess->s_id.b.domain, | ||
735 | sess->s_id.b.al_pa, sess->s_id.b.area, | ||
736 | sess->loop_id, fcport->d_id.b.domain, | ||
737 | fcport->d_id.b.al_pa, fcport->d_id.b.area, | ||
738 | fcport->loop_id); | ||
739 | |||
740 | if (sess->deleted) | ||
741 | qlt_undelete_sess(sess); | ||
742 | |||
743 | kref_get(&sess->se_sess->sess_kref); | ||
744 | sess->s_id = fcport->d_id; | ||
745 | sess->loop_id = fcport->loop_id; | ||
746 | sess->conf_compl_supported = !!(fcport->flags & | ||
747 | FCF_CONF_COMP_SUPPORTED); | ||
748 | if (sess->local && !local) | ||
749 | sess->local = 0; | ||
750 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
751 | |||
752 | return sess; | ||
753 | } | ||
754 | } | ||
755 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
756 | |||
757 | sess = kzalloc(sizeof(*sess), GFP_KERNEL); | ||
758 | if (!sess) { | ||
759 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04a, | ||
760 | "qla_target(%u): session allocation failed, " | ||
761 | "all commands from port %02x:%02x:%02x:%02x:" | ||
762 | "%02x:%02x:%02x:%02x will be refused", vha->vp_idx, | ||
763 | fcport->port_name[0], fcport->port_name[1], | ||
764 | fcport->port_name[2], fcport->port_name[3], | ||
765 | fcport->port_name[4], fcport->port_name[5], | ||
766 | fcport->port_name[6], fcport->port_name[7]); | ||
767 | |||
768 | return NULL; | ||
769 | } | ||
770 | sess->tgt = ha->tgt.qla_tgt; | ||
771 | sess->vha = vha; | ||
772 | sess->s_id = fcport->d_id; | ||
773 | sess->loop_id = fcport->loop_id; | ||
774 | sess->local = local; | ||
775 | |||
776 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006, | ||
777 | "Adding sess %p to tgt %p via ->check_initiator_node_acl()\n", | ||
778 | sess, ha->tgt.qla_tgt); | ||
779 | |||
780 | be_sid[0] = sess->s_id.b.domain; | ||
781 | be_sid[1] = sess->s_id.b.area; | ||
782 | be_sid[2] = sess->s_id.b.al_pa; | ||
783 | /* | ||
784 | * Determine if this fc_port->port_name is allowed to access | ||
785 | * target mode using explict NodeACLs+MappedLUNs, or using | ||
786 | * TPG demo mode. If this is successful a target mode FC nexus | ||
787 | * is created. | ||
788 | */ | ||
789 | if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, | ||
790 | &fcport->port_name[0], sess, &be_sid[0], fcport->loop_id) < 0) { | ||
791 | kfree(sess); | ||
792 | return NULL; | ||
793 | } | ||
794 | /* | ||
795 | * Take an extra reference to ->sess_kref here to handle qla_tgt_sess | ||
796 | * access across ->hardware_lock reaquire. | ||
797 | */ | ||
798 | kref_get(&sess->se_sess->sess_kref); | ||
799 | |||
800 | sess->conf_compl_supported = !!(fcport->flags & | ||
801 | FCF_CONF_COMP_SUPPORTED); | ||
802 | BUILD_BUG_ON(sizeof(sess->port_name) != sizeof(fcport->port_name)); | ||
803 | memcpy(sess->port_name, fcport->port_name, sizeof(sess->port_name)); | ||
804 | |||
805 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
806 | list_add_tail(&sess->sess_list_entry, &ha->tgt.qla_tgt->sess_list); | ||
807 | ha->tgt.qla_tgt->sess_count++; | ||
808 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
809 | |||
810 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b, | ||
811 | "qla_target(%d): %ssession for wwn %02x:%02x:%02x:%02x:" | ||
812 | "%02x:%02x:%02x:%02x (loop_id %d, s_id %x:%x:%x, confirmed" | ||
813 | " completion %ssupported) added\n", | ||
814 | vha->vp_idx, local ? "local " : "", fcport->port_name[0], | ||
815 | fcport->port_name[1], fcport->port_name[2], fcport->port_name[3], | ||
816 | fcport->port_name[4], fcport->port_name[5], fcport->port_name[6], | ||
817 | fcport->port_name[7], fcport->loop_id, sess->s_id.b.domain, | ||
818 | sess->s_id.b.area, sess->s_id.b.al_pa, sess->conf_compl_supported ? | ||
819 | "" : "not "); | ||
820 | |||
821 | return sess; | ||
822 | } | ||
823 | |||
824 | /* | ||
825 | * Called from drivers/scsi/qla2xxx/qla_init.c:qla2x00_reg_remote_port() | ||
826 | */ | ||
827 | void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport) | ||
828 | { | ||
829 | struct qla_hw_data *ha = vha->hw; | ||
830 | struct qla_tgt *tgt = ha->tgt.qla_tgt; | ||
831 | struct qla_tgt_sess *sess; | ||
832 | unsigned long flags; | ||
833 | |||
834 | if (!vha->hw->tgt.tgt_ops) | ||
835 | return; | ||
836 | |||
837 | if (!tgt || (fcport->port_type != FCT_INITIATOR)) | ||
838 | return; | ||
839 | |||
840 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
841 | if (tgt->tgt_stop) { | ||
842 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
843 | return; | ||
844 | } | ||
845 | sess = qlt_find_sess_by_port_name(tgt, fcport->port_name); | ||
846 | if (!sess) { | ||
847 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
848 | |||
849 | mutex_lock(&ha->tgt.tgt_mutex); | ||
850 | sess = qlt_create_sess(vha, fcport, false); | ||
851 | mutex_unlock(&ha->tgt.tgt_mutex); | ||
852 | |||
853 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
854 | } else { | ||
855 | kref_get(&sess->se_sess->sess_kref); | ||
856 | |||
857 | if (sess->deleted) { | ||
858 | qlt_undelete_sess(sess); | ||
859 | |||
860 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c, | ||
861 | "qla_target(%u): %ssession for port %02x:" | ||
862 | "%02x:%02x:%02x:%02x:%02x:%02x:%02x (loop ID %d) " | ||
863 | "reappeared\n", vha->vp_idx, sess->local ? "local " | ||
864 | : "", sess->port_name[0], sess->port_name[1], | ||
865 | sess->port_name[2], sess->port_name[3], | ||
866 | sess->port_name[4], sess->port_name[5], | ||
867 | sess->port_name[6], sess->port_name[7], | ||
868 | sess->loop_id); | ||
869 | |||
870 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007, | ||
871 | "Reappeared sess %p\n", sess); | ||
872 | } | ||
873 | sess->s_id = fcport->d_id; | ||
874 | sess->loop_id = fcport->loop_id; | ||
875 | sess->conf_compl_supported = !!(fcport->flags & | ||
876 | FCF_CONF_COMP_SUPPORTED); | ||
877 | } | ||
878 | |||
879 | if (sess && sess->local) { | ||
880 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d, | ||
881 | "qla_target(%u): local session for " | ||
882 | "port %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " | ||
883 | "(loop ID %d) became global\n", vha->vp_idx, | ||
884 | fcport->port_name[0], fcport->port_name[1], | ||
885 | fcport->port_name[2], fcport->port_name[3], | ||
886 | fcport->port_name[4], fcport->port_name[5], | ||
887 | fcport->port_name[6], fcport->port_name[7], | ||
888 | sess->loop_id); | ||
889 | sess->local = 0; | ||
890 | } | ||
891 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
892 | |||
893 | ha->tgt.tgt_ops->put_sess(sess); | ||
894 | } | ||
895 | |||
896 | void qlt_fc_port_deleted(struct scsi_qla_host *vha, fc_port_t *fcport) | ||
897 | { | ||
898 | struct qla_hw_data *ha = vha->hw; | ||
899 | struct qla_tgt *tgt = ha->tgt.qla_tgt; | ||
900 | struct qla_tgt_sess *sess; | ||
901 | unsigned long flags; | ||
902 | |||
903 | if (!vha->hw->tgt.tgt_ops) | ||
904 | return; | ||
905 | |||
906 | if (!tgt || (fcport->port_type != FCT_INITIATOR)) | ||
907 | return; | ||
908 | |||
909 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
910 | if (tgt->tgt_stop) { | ||
911 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
912 | return; | ||
913 | } | ||
914 | sess = qlt_find_sess_by_port_name(tgt, fcport->port_name); | ||
915 | if (!sess) { | ||
916 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
917 | return; | ||
918 | } | ||
919 | |||
920 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess); | ||
921 | |||
922 | sess->local = 1; | ||
923 | qlt_schedule_sess_for_deletion(sess, false); | ||
924 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
925 | } | ||
926 | |||
927 | static inline int test_tgt_sess_count(struct qla_tgt *tgt) | ||
928 | { | ||
929 | struct qla_hw_data *ha = tgt->ha; | ||
930 | unsigned long flags; | ||
931 | int res; | ||
932 | /* | ||
933 | * We need to protect against race, when tgt is freed before or | ||
934 | * inside wake_up() | ||
935 | */ | ||
936 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
937 | ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002, | ||
938 | "tgt %p, empty(sess_list)=%d sess_count=%d\n", | ||
939 | tgt, list_empty(&tgt->sess_list), tgt->sess_count); | ||
940 | res = (tgt->sess_count == 0); | ||
941 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
942 | |||
943 | return res; | ||
944 | } | ||
945 | |||
946 | /* Called by tcm_qla2xxx configfs code */ | ||
947 | void qlt_stop_phase1(struct qla_tgt *tgt) | ||
948 | { | ||
949 | struct scsi_qla_host *vha = tgt->vha; | ||
950 | struct qla_hw_data *ha = tgt->ha; | ||
951 | unsigned long flags; | ||
952 | |||
953 | if (tgt->tgt_stop || tgt->tgt_stopped) { | ||
954 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, | ||
955 | "Already in tgt->tgt_stop or tgt_stopped state\n"); | ||
956 | dump_stack(); | ||
957 | return; | ||
958 | } | ||
959 | |||
960 | ql_dbg(ql_dbg_tgt, vha, 0xe003, "Stopping target for host %ld(%p)\n", | ||
961 | vha->host_no, vha); | ||
962 | /* | ||
963 | * Mutex needed to sync with qla_tgt_fc_port_[added,deleted]. | ||
964 | * Lock is needed, because we still can get an incoming packet. | ||
965 | */ | ||
966 | mutex_lock(&ha->tgt.tgt_mutex); | ||
967 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
968 | tgt->tgt_stop = 1; | ||
969 | qlt_clear_tgt_db(tgt, true); | ||
970 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
971 | mutex_unlock(&ha->tgt.tgt_mutex); | ||
972 | |||
973 | flush_delayed_work_sync(&tgt->sess_del_work); | ||
974 | |||
975 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009, | ||
976 | "Waiting for sess works (tgt %p)", tgt); | ||
977 | spin_lock_irqsave(&tgt->sess_work_lock, flags); | ||
978 | while (!list_empty(&tgt->sess_works_list)) { | ||
979 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); | ||
980 | flush_scheduled_work(); | ||
981 | spin_lock_irqsave(&tgt->sess_work_lock, flags); | ||
982 | } | ||
983 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); | ||
984 | |||
985 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a, | ||
986 | "Waiting for tgt %p: list_empty(sess_list)=%d " | ||
987 | "sess_count=%d\n", tgt, list_empty(&tgt->sess_list), | ||
988 | tgt->sess_count); | ||
989 | |||
990 | wait_event(tgt->waitQ, test_tgt_sess_count(tgt)); | ||
991 | |||
992 | /* Big hammer */ | ||
993 | if (!ha->flags.host_shutting_down && qla_tgt_mode_enabled(vha)) | ||
994 | qlt_disable_vha(vha); | ||
995 | |||
996 | /* Wait for sessions to clear out (just in case) */ | ||
997 | wait_event(tgt->waitQ, test_tgt_sess_count(tgt)); | ||
998 | } | ||
999 | EXPORT_SYMBOL(qlt_stop_phase1); | ||
1000 | |||
1001 | /* Called by tcm_qla2xxx configfs code */ | ||
1002 | void qlt_stop_phase2(struct qla_tgt *tgt) | ||
1003 | { | ||
1004 | struct qla_hw_data *ha = tgt->ha; | ||
1005 | unsigned long flags; | ||
1006 | |||
1007 | if (tgt->tgt_stopped) { | ||
1008 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf04f, | ||
1009 | "Already in tgt->tgt_stopped state\n"); | ||
1010 | dump_stack(); | ||
1011 | return; | ||
1012 | } | ||
1013 | |||
1014 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00b, | ||
1015 | "Waiting for %d IRQ commands to complete (tgt %p)", | ||
1016 | tgt->irq_cmd_count, tgt); | ||
1017 | |||
1018 | mutex_lock(&ha->tgt.tgt_mutex); | ||
1019 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
1020 | while (tgt->irq_cmd_count != 0) { | ||
1021 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
1022 | udelay(2); | ||
1023 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
1024 | } | ||
1025 | tgt->tgt_stop = 0; | ||
1026 | tgt->tgt_stopped = 1; | ||
1027 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
1028 | mutex_unlock(&ha->tgt.tgt_mutex); | ||
1029 | |||
1030 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00c, "Stop of tgt %p finished", | ||
1031 | tgt); | ||
1032 | } | ||
1033 | EXPORT_SYMBOL(qlt_stop_phase2); | ||
1034 | |||
1035 | /* Called from qlt_remove_target() -> qla2x00_remove_one() */ | ||
1036 | void qlt_release(struct qla_tgt *tgt) | ||
1037 | { | ||
1038 | struct qla_hw_data *ha = tgt->ha; | ||
1039 | |||
1040 | if ((ha->tgt.qla_tgt != NULL) && !tgt->tgt_stopped) | ||
1041 | qlt_stop_phase2(tgt); | ||
1042 | |||
1043 | ha->tgt.qla_tgt = NULL; | ||
1044 | |||
1045 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00d, | ||
1046 | "Release of tgt %p finished\n", tgt); | ||
1047 | |||
1048 | kfree(tgt); | ||
1049 | } | ||
1050 | |||
1051 | /* ha->hardware_lock supposed to be held on entry */ | ||
1052 | static int qlt_sched_sess_work(struct qla_tgt *tgt, int type, | ||
1053 | const void *param, unsigned int param_size) | ||
1054 | { | ||
1055 | struct qla_tgt_sess_work_param *prm; | ||
1056 | unsigned long flags; | ||
1057 | |||
1058 | prm = kzalloc(sizeof(*prm), GFP_ATOMIC); | ||
1059 | if (!prm) { | ||
1060 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050, | ||
1061 | "qla_target(%d): Unable to create session " | ||
1062 | "work, command will be refused", 0); | ||
1063 | return -ENOMEM; | ||
1064 | } | ||
1065 | |||
1066 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e, | ||
1067 | "Scheduling work (type %d, prm %p)" | ||
1068 | " to find session for param %p (size %d, tgt %p)\n", | ||
1069 | type, prm, param, param_size, tgt); | ||
1070 | |||
1071 | prm->type = type; | ||
1072 | memcpy(&prm->tm_iocb, param, param_size); | ||
1073 | |||
1074 | spin_lock_irqsave(&tgt->sess_work_lock, flags); | ||
1075 | list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list); | ||
1076 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); | ||
1077 | |||
1078 | schedule_work(&tgt->sess_work); | ||
1079 | |||
1080 | return 0; | ||
1081 | } | ||
1082 | |||
1083 | /* | ||
1084 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | ||
1085 | */ | ||
1086 | static void qlt_send_notify_ack(struct scsi_qla_host *vha, | ||
1087 | struct imm_ntfy_from_isp *ntfy, | ||
1088 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, | ||
1089 | uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan) | ||
1090 | { | ||
1091 | struct qla_hw_data *ha = vha->hw; | ||
1092 | request_t *pkt; | ||
1093 | struct nack_to_isp *nack; | ||
1094 | |||
1095 | ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha); | ||
1096 | |||
1097 | /* Send marker if required */ | ||
1098 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) | ||
1099 | return; | ||
1100 | |||
1101 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); | ||
1102 | if (!pkt) { | ||
1103 | ql_dbg(ql_dbg_tgt, vha, 0xe049, | ||
1104 | "qla_target(%d): %s failed: unable to allocate " | ||
1105 | "request packet\n", vha->vp_idx, __func__); | ||
1106 | return; | ||
1107 | } | ||
1108 | |||
1109 | if (ha->tgt.qla_tgt != NULL) | ||
1110 | ha->tgt.qla_tgt->notify_ack_expected++; | ||
1111 | |||
1112 | pkt->entry_type = NOTIFY_ACK_TYPE; | ||
1113 | pkt->entry_count = 1; | ||
1114 | |||
1115 | nack = (struct nack_to_isp *)pkt; | ||
1116 | nack->ox_id = ntfy->ox_id; | ||
1117 | |||
1118 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; | ||
1119 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { | ||
1120 | nack->u.isp24.flags = ntfy->u.isp24.flags & | ||
1121 | __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); | ||
1122 | } | ||
1123 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; | ||
1124 | nack->u.isp24.status = ntfy->u.isp24.status; | ||
1125 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; | ||
1126 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; | ||
1127 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; | ||
1128 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; | ||
1129 | nack->u.isp24.srr_flags = cpu_to_le16(srr_flags); | ||
1130 | nack->u.isp24.srr_reject_code = srr_reject_code; | ||
1131 | nack->u.isp24.srr_reject_code_expl = srr_explan; | ||
1132 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; | ||
1133 | |||
1134 | ql_dbg(ql_dbg_tgt, vha, 0xe005, | ||
1135 | "qla_target(%d): Sending 24xx Notify Ack %d\n", | ||
1136 | vha->vp_idx, nack->u.isp24.status); | ||
1137 | |||
1138 | qla2x00_start_iocbs(vha, vha->req); | ||
1139 | } | ||
1140 | |||
1141 | /* | ||
1142 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | ||
1143 | */ | ||
1144 | static void qlt_24xx_send_abts_resp(struct scsi_qla_host *vha, | ||
1145 | struct abts_recv_from_24xx *abts, uint32_t status, | ||
1146 | bool ids_reversed) | ||
1147 | { | ||
1148 | struct qla_hw_data *ha = vha->hw; | ||
1149 | struct abts_resp_to_24xx *resp; | ||
1150 | uint32_t f_ctl; | ||
1151 | uint8_t *p; | ||
1152 | |||
1153 | ql_dbg(ql_dbg_tgt, vha, 0xe006, | ||
1154 | "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n", | ||
1155 | ha, abts, status); | ||
1156 | |||
1157 | /* Send marker if required */ | ||
1158 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) | ||
1159 | return; | ||
1160 | |||
1161 | resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs(vha, NULL); | ||
1162 | if (!resp) { | ||
1163 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, | ||
1164 | "qla_target(%d): %s failed: unable to allocate " | ||
1165 | "request packet", vha->vp_idx, __func__); | ||
1166 | return; | ||
1167 | } | ||
1168 | |||
1169 | resp->entry_type = ABTS_RESP_24XX; | ||
1170 | resp->entry_count = 1; | ||
1171 | resp->nport_handle = abts->nport_handle; | ||
1172 | resp->vp_index = vha->vp_idx; | ||
1173 | resp->sof_type = abts->sof_type; | ||
1174 | resp->exchange_address = abts->exchange_address; | ||
1175 | resp->fcp_hdr_le = abts->fcp_hdr_le; | ||
1176 | f_ctl = __constant_cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | | ||
1177 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | | ||
1178 | F_CTL_SEQ_INITIATIVE); | ||
1179 | p = (uint8_t *)&f_ctl; | ||
1180 | resp->fcp_hdr_le.f_ctl[0] = *p++; | ||
1181 | resp->fcp_hdr_le.f_ctl[1] = *p++; | ||
1182 | resp->fcp_hdr_le.f_ctl[2] = *p; | ||
1183 | if (ids_reversed) { | ||
1184 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.d_id[0]; | ||
1185 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.d_id[1]; | ||
1186 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.d_id[2]; | ||
1187 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.s_id[0]; | ||
1188 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.s_id[1]; | ||
1189 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.s_id[2]; | ||
1190 | } else { | ||
1191 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.s_id[0]; | ||
1192 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.s_id[1]; | ||
1193 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.s_id[2]; | ||
1194 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.d_id[0]; | ||
1195 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.d_id[1]; | ||
1196 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.d_id[2]; | ||
1197 | } | ||
1198 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; | ||
1199 | if (status == FCP_TMF_CMPL) { | ||
1200 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; | ||
1201 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; | ||
1202 | resp->payload.ba_acct.low_seq_cnt = 0x0000; | ||
1203 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; | ||
1204 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; | ||
1205 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; | ||
1206 | } else { | ||
1207 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; | ||
1208 | resp->payload.ba_rjt.reason_code = | ||
1209 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; | ||
1210 | /* Other bytes are zero */ | ||
1211 | } | ||
1212 | |||
1213 | ha->tgt.qla_tgt->abts_resp_expected++; | ||
1214 | |||
1215 | qla2x00_start_iocbs(vha, vha->req); | ||
1216 | } | ||
1217 | |||
1218 | /* | ||
1219 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | ||
1220 | */ | ||
1221 | static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha, | ||
1222 | struct abts_resp_from_24xx_fw *entry) | ||
1223 | { | ||
1224 | struct ctio7_to_24xx *ctio; | ||
1225 | |||
1226 | ql_dbg(ql_dbg_tgt, vha, 0xe007, | ||
1227 | "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha->hw); | ||
1228 | /* Send marker if required */ | ||
1229 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) | ||
1230 | return; | ||
1231 | |||
1232 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL); | ||
1233 | if (ctio == NULL) { | ||
1234 | ql_dbg(ql_dbg_tgt, vha, 0xe04b, | ||
1235 | "qla_target(%d): %s failed: unable to allocate " | ||
1236 | "request packet\n", vha->vp_idx, __func__); | ||
1237 | return; | ||
1238 | } | ||
1239 | |||
1240 | /* | ||
1241 | * We've got on entrance firmware's response on by us generated | ||
1242 | * ABTS response. So, in it ID fields are reversed. | ||
1243 | */ | ||
1244 | |||
1245 | ctio->entry_type = CTIO_TYPE7; | ||
1246 | ctio->entry_count = 1; | ||
1247 | ctio->nport_handle = entry->nport_handle; | ||
1248 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; | ||
1249 | ctio->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT); | ||
1250 | ctio->vp_index = vha->vp_idx; | ||
1251 | ctio->initiator_id[0] = entry->fcp_hdr_le.d_id[0]; | ||
1252 | ctio->initiator_id[1] = entry->fcp_hdr_le.d_id[1]; | ||
1253 | ctio->initiator_id[2] = entry->fcp_hdr_le.d_id[2]; | ||
1254 | ctio->exchange_addr = entry->exchange_addr_to_abort; | ||
1255 | ctio->u.status1.flags = | ||
1256 | __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | | ||
1257 | CTIO7_FLAGS_TERMINATE); | ||
1258 | ctio->u.status1.ox_id = entry->fcp_hdr_le.ox_id; | ||
1259 | |||
1260 | qla2x00_start_iocbs(vha, vha->req); | ||
1261 | |||
1262 | qlt_24xx_send_abts_resp(vha, (struct abts_recv_from_24xx *)entry, | ||
1263 | FCP_TMF_CMPL, true); | ||
1264 | } | ||
1265 | |||
1266 | /* ha->hardware_lock supposed to be held on entry */ | ||
1267 | static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha, | ||
1268 | struct abts_recv_from_24xx *abts, struct qla_tgt_sess *sess) | ||
1269 | { | ||
1270 | struct qla_hw_data *ha = vha->hw; | ||
1271 | struct qla_tgt_mgmt_cmd *mcmd; | ||
1272 | int rc; | ||
1273 | |||
1274 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f, | ||
1275 | "qla_target(%d): task abort (tag=%d)\n", | ||
1276 | vha->vp_idx, abts->exchange_addr_to_abort); | ||
1277 | |||
1278 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); | ||
1279 | if (mcmd == NULL) { | ||
1280 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051, | ||
1281 | "qla_target(%d): %s: Allocation of ABORT cmd failed", | ||
1282 | vha->vp_idx, __func__); | ||
1283 | return -ENOMEM; | ||
1284 | } | ||
1285 | memset(mcmd, 0, sizeof(*mcmd)); | ||
1286 | |||
1287 | mcmd->sess = sess; | ||
1288 | memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts)); | ||
1289 | |||
1290 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, 0, TMR_ABORT_TASK, | ||
1291 | abts->exchange_addr_to_abort); | ||
1292 | if (rc != 0) { | ||
1293 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf052, | ||
1294 | "qla_target(%d): tgt_ops->handle_tmr()" | ||
1295 | " failed: %d", vha->vp_idx, rc); | ||
1296 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); | ||
1297 | return -EFAULT; | ||
1298 | } | ||
1299 | |||
1300 | return 0; | ||
1301 | } | ||
1302 | |||
1303 | /* | ||
1304 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | ||
1305 | */ | ||
1306 | static void qlt_24xx_handle_abts(struct scsi_qla_host *vha, | ||
1307 | struct abts_recv_from_24xx *abts) | ||
1308 | { | ||
1309 | struct qla_hw_data *ha = vha->hw; | ||
1310 | struct qla_tgt_sess *sess; | ||
1311 | uint32_t tag = abts->exchange_addr_to_abort; | ||
1312 | uint8_t s_id[3]; | ||
1313 | int rc; | ||
1314 | |||
1315 | if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) { | ||
1316 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053, | ||
1317 | "qla_target(%d): ABTS: Abort Sequence not " | ||
1318 | "supported\n", vha->vp_idx); | ||
1319 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); | ||
1320 | return; | ||
1321 | } | ||
1322 | |||
1323 | if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) { | ||
1324 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010, | ||
1325 | "qla_target(%d): ABTS: Unknown Exchange " | ||
1326 | "Address received\n", vha->vp_idx); | ||
1327 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); | ||
1328 | return; | ||
1329 | } | ||
1330 | |||
1331 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011, | ||
1332 | "qla_target(%d): task abort (s_id=%x:%x:%x, " | ||
1333 | "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id[2], | ||
1334 | abts->fcp_hdr_le.s_id[1], abts->fcp_hdr_le.s_id[0], tag, | ||
1335 | le32_to_cpu(abts->fcp_hdr_le.parameter)); | ||
1336 | |||
1337 | s_id[0] = abts->fcp_hdr_le.s_id[2]; | ||
1338 | s_id[1] = abts->fcp_hdr_le.s_id[1]; | ||
1339 | s_id[2] = abts->fcp_hdr_le.s_id[0]; | ||
1340 | |||
1341 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); | ||
1342 | if (!sess) { | ||
1343 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012, | ||
1344 | "qla_target(%d): task abort for non-existant session\n", | ||
1345 | vha->vp_idx); | ||
1346 | rc = qlt_sched_sess_work(ha->tgt.qla_tgt, | ||
1347 | QLA_TGT_SESS_WORK_ABORT, abts, sizeof(*abts)); | ||
1348 | if (rc != 0) { | ||
1349 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, | ||
1350 | false); | ||
1351 | } | ||
1352 | return; | ||
1353 | } | ||
1354 | |||
1355 | rc = __qlt_24xx_handle_abts(vha, abts, sess); | ||
1356 | if (rc != 0) { | ||
1357 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054, | ||
1358 | "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n", | ||
1359 | vha->vp_idx, rc); | ||
1360 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); | ||
1361 | return; | ||
1362 | } | ||
1363 | } | ||
1364 | |||
1365 | /* | ||
1366 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | ||
1367 | */ | ||
1368 | static void qlt_24xx_send_task_mgmt_ctio(struct scsi_qla_host *ha, | ||
1369 | struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code) | ||
1370 | { | ||
1371 | struct atio_from_isp *atio = &mcmd->orig_iocb.atio; | ||
1372 | struct ctio7_to_24xx *ctio; | ||
1373 | |||
1374 | ql_dbg(ql_dbg_tgt, ha, 0xe008, | ||
1375 | "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n", | ||
1376 | ha, atio, resp_code); | ||
1377 | |||
1378 | /* Send marker if required */ | ||
1379 | if (qlt_issue_marker(ha, 1) != QLA_SUCCESS) | ||
1380 | return; | ||
1381 | |||
1382 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(ha, NULL); | ||
1383 | if (ctio == NULL) { | ||
1384 | ql_dbg(ql_dbg_tgt, ha, 0xe04c, | ||
1385 | "qla_target(%d): %s failed: unable to allocate " | ||
1386 | "request packet\n", ha->vp_idx, __func__); | ||
1387 | return; | ||
1388 | } | ||
1389 | |||
1390 | ctio->entry_type = CTIO_TYPE7; | ||
1391 | ctio->entry_count = 1; | ||
1392 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; | ||
1393 | ctio->nport_handle = mcmd->sess->loop_id; | ||
1394 | ctio->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT); | ||
1395 | ctio->vp_index = ha->vp_idx; | ||
1396 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; | ||
1397 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; | ||
1398 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; | ||
1399 | ctio->exchange_addr = atio->u.isp24.exchange_addr; | ||
1400 | ctio->u.status1.flags = (atio->u.isp24.attr << 9) | | ||
1401 | __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | | ||
1402 | CTIO7_FLAGS_SEND_STATUS); | ||
1403 | ctio->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); | ||
1404 | ctio->u.status1.scsi_status = | ||
1405 | __constant_cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID); | ||
1406 | ctio->u.status1.response_len = __constant_cpu_to_le16(8); | ||
1407 | ((uint32_t *)ctio->u.status1.sense_data)[0] = cpu_to_be32(resp_code); | ||
1408 | |||
1409 | qla2x00_start_iocbs(ha, ha->req); | ||
1410 | } | ||
1411 | |||
1412 | void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd) | ||
1413 | { | ||
1414 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); | ||
1415 | } | ||
1416 | EXPORT_SYMBOL(qlt_free_mcmd); | ||
1417 | |||
1418 | /* callback from target fabric module code */ | ||
1419 | void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd) | ||
1420 | { | ||
1421 | struct scsi_qla_host *vha = mcmd->sess->vha; | ||
1422 | struct qla_hw_data *ha = vha->hw; | ||
1423 | unsigned long flags; | ||
1424 | |||
1425 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013, | ||
1426 | "TM response mcmd (%p) status %#x state %#x", | ||
1427 | mcmd, mcmd->fc_tm_rsp, mcmd->flags); | ||
1428 | |||
1429 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
1430 | if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) | ||
1431 | qlt_send_notify_ack(vha, &mcmd->orig_iocb.imm_ntfy, | ||
1432 | 0, 0, 0, 0, 0, 0); | ||
1433 | else { | ||
1434 | if (mcmd->se_cmd.se_tmr_req->function == TMR_ABORT_TASK) | ||
1435 | qlt_24xx_send_abts_resp(vha, &mcmd->orig_iocb.abts, | ||
1436 | mcmd->fc_tm_rsp, false); | ||
1437 | else | ||
1438 | qlt_24xx_send_task_mgmt_ctio(vha, mcmd, | ||
1439 | mcmd->fc_tm_rsp); | ||
1440 | } | ||
1441 | /* | ||
1442 | * Make the callback for ->free_mcmd() to queue_work() and invoke | ||
1443 | * target_put_sess_cmd() to drop cmd_kref to 1. The final | ||
1444 | * target_put_sess_cmd() call will be made from TFO->check_stop_free() | ||
1445 | * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd | ||
1446 | * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() -> | ||
1447 | * qlt_xmit_tm_rsp() returns here.. | ||
1448 | */ | ||
1449 | ha->tgt.tgt_ops->free_mcmd(mcmd); | ||
1450 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
1451 | } | ||
1452 | EXPORT_SYMBOL(qlt_xmit_tm_rsp); | ||
1453 | |||
1454 | /* No locks */ | ||
1455 | static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm) | ||
1456 | { | ||
1457 | struct qla_tgt_cmd *cmd = prm->cmd; | ||
1458 | |||
1459 | BUG_ON(cmd->sg_cnt == 0); | ||
1460 | |||
1461 | prm->sg = (struct scatterlist *)cmd->sg; | ||
1462 | prm->seg_cnt = pci_map_sg(prm->tgt->ha->pdev, cmd->sg, | ||
1463 | cmd->sg_cnt, cmd->dma_data_direction); | ||
1464 | if (unlikely(prm->seg_cnt == 0)) | ||
1465 | goto out_err; | ||
1466 | |||
1467 | prm->cmd->sg_mapped = 1; | ||
1468 | |||
1469 | /* | ||
1470 | * If greater than four sg entries then we need to allocate | ||
1471 | * the continuation entries | ||
1472 | */ | ||
1473 | if (prm->seg_cnt > prm->tgt->datasegs_per_cmd) | ||
1474 | prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt - | ||
1475 | prm->tgt->datasegs_per_cmd, prm->tgt->datasegs_per_cont); | ||
1476 | |||
1477 | ql_dbg(ql_dbg_tgt, prm->cmd->vha, 0xe009, "seg_cnt=%d, req_cnt=%d\n", | ||
1478 | prm->seg_cnt, prm->req_cnt); | ||
1479 | return 0; | ||
1480 | |||
1481 | out_err: | ||
1482 | ql_dbg(ql_dbg_tgt, prm->cmd->vha, 0xe04d, | ||
1483 | "qla_target(%d): PCI mapping failed: sg_cnt=%d", | ||
1484 | 0, prm->cmd->sg_cnt); | ||
1485 | return -1; | ||
1486 | } | ||
1487 | |||
1488 | static inline void qlt_unmap_sg(struct scsi_qla_host *vha, | ||
1489 | struct qla_tgt_cmd *cmd) | ||
1490 | { | ||
1491 | struct qla_hw_data *ha = vha->hw; | ||
1492 | |||
1493 | BUG_ON(!cmd->sg_mapped); | ||
1494 | pci_unmap_sg(ha->pdev, cmd->sg, cmd->sg_cnt, cmd->dma_data_direction); | ||
1495 | cmd->sg_mapped = 0; | ||
1496 | } | ||
1497 | |||
1498 | static int qlt_check_reserve_free_req(struct scsi_qla_host *vha, | ||
1499 | uint32_t req_cnt) | ||
1500 | { | ||
1501 | struct qla_hw_data *ha = vha->hw; | ||
1502 | device_reg_t __iomem *reg = ha->iobase; | ||
1503 | uint32_t cnt; | ||
1504 | |||
1505 | if (vha->req->cnt < (req_cnt + 2)) { | ||
1506 | cnt = (uint16_t)RD_REG_DWORD(®->isp24.req_q_out); | ||
1507 | |||
1508 | ql_dbg(ql_dbg_tgt, vha, 0xe00a, | ||
1509 | "Request ring circled: cnt=%d, vha->->ring_index=%d, " | ||
1510 | "vha->req->cnt=%d, req_cnt=%d\n", cnt, | ||
1511 | vha->req->ring_index, vha->req->cnt, req_cnt); | ||
1512 | if (vha->req->ring_index < cnt) | ||
1513 | vha->req->cnt = cnt - vha->req->ring_index; | ||
1514 | else | ||
1515 | vha->req->cnt = vha->req->length - | ||
1516 | (vha->req->ring_index - cnt); | ||
1517 | } | ||
1518 | |||
1519 | if (unlikely(vha->req->cnt < (req_cnt + 2))) { | ||
1520 | ql_dbg(ql_dbg_tgt, vha, 0xe00b, | ||
1521 | "qla_target(%d): There is no room in the " | ||
1522 | "request ring: vha->req->ring_index=%d, vha->req->cnt=%d, " | ||
1523 | "req_cnt=%d\n", vha->vp_idx, vha->req->ring_index, | ||
1524 | vha->req->cnt, req_cnt); | ||
1525 | return -EAGAIN; | ||
1526 | } | ||
1527 | vha->req->cnt -= req_cnt; | ||
1528 | |||
1529 | return 0; | ||
1530 | } | ||
1531 | |||
1532 | /* | ||
1533 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | ||
1534 | */ | ||
1535 | static inline void *qlt_get_req_pkt(struct scsi_qla_host *vha) | ||
1536 | { | ||
1537 | /* Adjust ring index. */ | ||
1538 | vha->req->ring_index++; | ||
1539 | if (vha->req->ring_index == vha->req->length) { | ||
1540 | vha->req->ring_index = 0; | ||
1541 | vha->req->ring_ptr = vha->req->ring; | ||
1542 | } else { | ||
1543 | vha->req->ring_ptr++; | ||
1544 | } | ||
1545 | return (cont_entry_t *)vha->req->ring_ptr; | ||
1546 | } | ||
1547 | |||
1548 | /* ha->hardware_lock supposed to be held on entry */ | ||
1549 | static inline uint32_t qlt_make_handle(struct scsi_qla_host *vha) | ||
1550 | { | ||
1551 | struct qla_hw_data *ha = vha->hw; | ||
1552 | uint32_t h; | ||
1553 | |||
1554 | h = ha->tgt.current_handle; | ||
1555 | /* always increment cmd handle */ | ||
1556 | do { | ||
1557 | ++h; | ||
1558 | if (h > MAX_OUTSTANDING_COMMANDS) | ||
1559 | h = 1; /* 0 is QLA_TGT_NULL_HANDLE */ | ||
1560 | if (h == ha->tgt.current_handle) { | ||
1561 | ql_dbg(ql_dbg_tgt, vha, 0xe04e, | ||
1562 | "qla_target(%d): Ran out of " | ||
1563 | "empty cmd slots in ha %p\n", vha->vp_idx, ha); | ||
1564 | h = QLA_TGT_NULL_HANDLE; | ||
1565 | break; | ||
1566 | } | ||
1567 | } while ((h == QLA_TGT_NULL_HANDLE) || | ||
1568 | (h == QLA_TGT_SKIP_HANDLE) || | ||
1569 | (ha->tgt.cmds[h-1] != NULL)); | ||
1570 | |||
1571 | if (h != QLA_TGT_NULL_HANDLE) | ||
1572 | ha->tgt.current_handle = h; | ||
1573 | |||
1574 | return h; | ||
1575 | } | ||
1576 | |||
1577 | /* ha->hardware_lock supposed to be held on entry */ | ||
1578 | static int qlt_24xx_build_ctio_pkt(struct qla_tgt_prm *prm, | ||
1579 | struct scsi_qla_host *vha) | ||
1580 | { | ||
1581 | uint32_t h; | ||
1582 | struct ctio7_to_24xx *pkt; | ||
1583 | struct qla_hw_data *ha = vha->hw; | ||
1584 | struct atio_from_isp *atio = &prm->cmd->atio; | ||
1585 | |||
1586 | pkt = (struct ctio7_to_24xx *)vha->req->ring_ptr; | ||
1587 | prm->pkt = pkt; | ||
1588 | memset(pkt, 0, sizeof(*pkt)); | ||
1589 | |||
1590 | pkt->entry_type = CTIO_TYPE7; | ||
1591 | pkt->entry_count = (uint8_t)prm->req_cnt; | ||
1592 | pkt->vp_index = vha->vp_idx; | ||
1593 | |||
1594 | h = qlt_make_handle(vha); | ||
1595 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { | ||
1596 | /* | ||
1597 | * CTIO type 7 from the firmware doesn't provide a way to | ||
1598 | * know the initiator's LOOP ID, hence we can't find | ||
1599 | * the session and, so, the command. | ||
1600 | */ | ||
1601 | return -EAGAIN; | ||
1602 | } else | ||
1603 | ha->tgt.cmds[h-1] = prm->cmd; | ||
1604 | |||
1605 | pkt->handle = h | CTIO_COMPLETION_HANDLE_MARK; | ||
1606 | pkt->nport_handle = prm->cmd->loop_id; | ||
1607 | pkt->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT); | ||
1608 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; | ||
1609 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; | ||
1610 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; | ||
1611 | pkt->exchange_addr = atio->u.isp24.exchange_addr; | ||
1612 | pkt->u.status0.flags |= (atio->u.isp24.attr << 9); | ||
1613 | pkt->u.status0.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); | ||
1614 | pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset); | ||
1615 | |||
1616 | ql_dbg(ql_dbg_tgt, vha, 0xe00c, | ||
1617 | "qla_target(%d): handle(cmd) -> %08x, timeout %d, ox_id %#x\n", | ||
1618 | vha->vp_idx, pkt->handle, QLA_TGT_TIMEOUT, | ||
1619 | le16_to_cpu(pkt->u.status0.ox_id)); | ||
1620 | return 0; | ||
1621 | } | ||
1622 | |||
1623 | /* | ||
1624 | * ha->hardware_lock supposed to be held on entry. We have already made sure | ||
1625 | * that there is sufficient amount of request entries to not drop it. | ||
1626 | */ | ||
1627 | static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm, | ||
1628 | struct scsi_qla_host *vha) | ||
1629 | { | ||
1630 | int cnt; | ||
1631 | uint32_t *dword_ptr; | ||
1632 | int enable_64bit_addressing = prm->tgt->tgt_enable_64bit_addr; | ||
1633 | |||
1634 | /* Build continuation packets */ | ||
1635 | while (prm->seg_cnt > 0) { | ||
1636 | cont_a64_entry_t *cont_pkt64 = | ||
1637 | (cont_a64_entry_t *)qlt_get_req_pkt(vha); | ||
1638 | |||
1639 | /* | ||
1640 | * Make sure that from cont_pkt64 none of | ||
1641 | * 64-bit specific fields used for 32-bit | ||
1642 | * addressing. Cast to (cont_entry_t *) for | ||
1643 | * that. | ||
1644 | */ | ||
1645 | |||
1646 | memset(cont_pkt64, 0, sizeof(*cont_pkt64)); | ||
1647 | |||
1648 | cont_pkt64->entry_count = 1; | ||
1649 | cont_pkt64->sys_define = 0; | ||
1650 | |||
1651 | if (enable_64bit_addressing) { | ||
1652 | cont_pkt64->entry_type = CONTINUE_A64_TYPE; | ||
1653 | dword_ptr = | ||
1654 | (uint32_t *)&cont_pkt64->dseg_0_address; | ||
1655 | } else { | ||
1656 | cont_pkt64->entry_type = CONTINUE_TYPE; | ||
1657 | dword_ptr = | ||
1658 | (uint32_t *)&((cont_entry_t *) | ||
1659 | cont_pkt64)->dseg_0_address; | ||
1660 | } | ||
1661 | |||
1662 | /* Load continuation entry data segments */ | ||
1663 | for (cnt = 0; | ||
1664 | cnt < prm->tgt->datasegs_per_cont && prm->seg_cnt; | ||
1665 | cnt++, prm->seg_cnt--) { | ||
1666 | *dword_ptr++ = | ||
1667 | cpu_to_le32(pci_dma_lo32 | ||
1668 | (sg_dma_address(prm->sg))); | ||
1669 | if (enable_64bit_addressing) { | ||
1670 | *dword_ptr++ = | ||
1671 | cpu_to_le32(pci_dma_hi32 | ||
1672 | (sg_dma_address | ||
1673 | (prm->sg))); | ||
1674 | } | ||
1675 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); | ||
1676 | |||
1677 | ql_dbg(ql_dbg_tgt, vha, 0xe00d, | ||
1678 | "S/G Segment Cont. phys_addr=%llx:%llx, len=%d\n", | ||
1679 | (long long unsigned int) | ||
1680 | pci_dma_hi32(sg_dma_address(prm->sg)), | ||
1681 | (long long unsigned int) | ||
1682 | pci_dma_lo32(sg_dma_address(prm->sg)), | ||
1683 | (int)sg_dma_len(prm->sg)); | ||
1684 | |||
1685 | prm->sg = sg_next(prm->sg); | ||
1686 | } | ||
1687 | } | ||
1688 | } | ||
1689 | |||
1690 | /* | ||
1691 | * ha->hardware_lock supposed to be held on entry. We have already made sure | ||
1692 | * that there is sufficient amount of request entries to not drop it. | ||
1693 | */ | ||
1694 | static void qlt_load_data_segments(struct qla_tgt_prm *prm, | ||
1695 | struct scsi_qla_host *vha) | ||
1696 | { | ||
1697 | int cnt; | ||
1698 | uint32_t *dword_ptr; | ||
1699 | int enable_64bit_addressing = prm->tgt->tgt_enable_64bit_addr; | ||
1700 | struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt; | ||
1701 | |||
1702 | ql_dbg(ql_dbg_tgt, vha, 0xe00e, | ||
1703 | "iocb->scsi_status=%x, iocb->flags=%x\n", | ||
1704 | le16_to_cpu(pkt24->u.status0.scsi_status), | ||
1705 | le16_to_cpu(pkt24->u.status0.flags)); | ||
1706 | |||
1707 | pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen); | ||
1708 | |||
1709 | /* Setup packet address segment pointer */ | ||
1710 | dword_ptr = pkt24->u.status0.dseg_0_address; | ||
1711 | |||
1712 | /* Set total data segment count */ | ||
1713 | if (prm->seg_cnt) | ||
1714 | pkt24->dseg_count = cpu_to_le16(prm->seg_cnt); | ||
1715 | |||
1716 | if (prm->seg_cnt == 0) { | ||
1717 | /* No data transfer */ | ||
1718 | *dword_ptr++ = 0; | ||
1719 | *dword_ptr = 0; | ||
1720 | return; | ||
1721 | } | ||
1722 | |||
1723 | /* If scatter gather */ | ||
1724 | ql_dbg(ql_dbg_tgt, vha, 0xe00f, "%s", "Building S/G data segments..."); | ||
1725 | |||
1726 | /* Load command entry data segments */ | ||
1727 | for (cnt = 0; | ||
1728 | (cnt < prm->tgt->datasegs_per_cmd) && prm->seg_cnt; | ||
1729 | cnt++, prm->seg_cnt--) { | ||
1730 | *dword_ptr++ = | ||
1731 | cpu_to_le32(pci_dma_lo32(sg_dma_address(prm->sg))); | ||
1732 | if (enable_64bit_addressing) { | ||
1733 | *dword_ptr++ = | ||
1734 | cpu_to_le32(pci_dma_hi32( | ||
1735 | sg_dma_address(prm->sg))); | ||
1736 | } | ||
1737 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); | ||
1738 | |||
1739 | ql_dbg(ql_dbg_tgt, vha, 0xe010, | ||
1740 | "S/G Segment phys_addr=%llx:%llx, len=%d\n", | ||
1741 | (long long unsigned int)pci_dma_hi32(sg_dma_address( | ||
1742 | prm->sg)), | ||
1743 | (long long unsigned int)pci_dma_lo32(sg_dma_address( | ||
1744 | prm->sg)), | ||
1745 | (int)sg_dma_len(prm->sg)); | ||
1746 | |||
1747 | prm->sg = sg_next(prm->sg); | ||
1748 | } | ||
1749 | |||
1750 | qlt_load_cont_data_segments(prm, vha); | ||
1751 | } | ||
1752 | |||
1753 | static inline int qlt_has_data(struct qla_tgt_cmd *cmd) | ||
1754 | { | ||
1755 | return cmd->bufflen > 0; | ||
1756 | } | ||
1757 | |||
1758 | /* | ||
1759 | * Called without ha->hardware_lock held | ||
1760 | */ | ||
1761 | static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd, | ||
1762 | struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status, | ||
1763 | uint32_t *full_req_cnt) | ||
1764 | { | ||
1765 | struct qla_tgt *tgt = cmd->tgt; | ||
1766 | struct scsi_qla_host *vha = tgt->vha; | ||
1767 | struct qla_hw_data *ha = vha->hw; | ||
1768 | struct se_cmd *se_cmd = &cmd->se_cmd; | ||
1769 | |||
1770 | if (unlikely(cmd->aborted)) { | ||
1771 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, | ||
1772 | "qla_target(%d): terminating exchange " | ||
1773 | "for aborted cmd=%p (se_cmd=%p, tag=%d)", vha->vp_idx, cmd, | ||
1774 | se_cmd, cmd->tag); | ||
1775 | |||
1776 | cmd->state = QLA_TGT_STATE_ABORTED; | ||
1777 | |||
1778 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 0); | ||
1779 | |||
1780 | /* !! At this point cmd could be already freed !! */ | ||
1781 | return QLA_TGT_PRE_XMIT_RESP_CMD_ABORTED; | ||
1782 | } | ||
1783 | |||
1784 | ql_dbg(ql_dbg_tgt, vha, 0xe011, "qla_target(%d): tag=%u\n", | ||
1785 | vha->vp_idx, cmd->tag); | ||
1786 | |||
1787 | prm->cmd = cmd; | ||
1788 | prm->tgt = tgt; | ||
1789 | prm->rq_result = scsi_status; | ||
1790 | prm->sense_buffer = &cmd->sense_buffer[0]; | ||
1791 | prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER; | ||
1792 | prm->sg = NULL; | ||
1793 | prm->seg_cnt = -1; | ||
1794 | prm->req_cnt = 1; | ||
1795 | prm->add_status_pkt = 0; | ||
1796 | |||
1797 | ql_dbg(ql_dbg_tgt, vha, 0xe012, "rq_result=%x, xmit_type=%x\n", | ||
1798 | prm->rq_result, xmit_type); | ||
1799 | |||
1800 | /* Send marker if required */ | ||
1801 | if (qlt_issue_marker(vha, 0) != QLA_SUCCESS) | ||
1802 | return -EFAULT; | ||
1803 | |||
1804 | ql_dbg(ql_dbg_tgt, vha, 0xe013, "CTIO start: vha(%d)\n", vha->vp_idx); | ||
1805 | |||
1806 | if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) { | ||
1807 | if (qlt_pci_map_calc_cnt(prm) != 0) | ||
1808 | return -EAGAIN; | ||
1809 | } | ||
1810 | |||
1811 | *full_req_cnt = prm->req_cnt; | ||
1812 | |||
1813 | if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { | ||
1814 | prm->residual = se_cmd->residual_count; | ||
1815 | ql_dbg(ql_dbg_tgt, vha, 0xe014, | ||
1816 | "Residual underflow: %d (tag %d, " | ||
1817 | "op %x, bufflen %d, rq_result %x)\n", prm->residual, | ||
1818 | cmd->tag, se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, | ||
1819 | cmd->bufflen, prm->rq_result); | ||
1820 | prm->rq_result |= SS_RESIDUAL_UNDER; | ||
1821 | } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { | ||
1822 | prm->residual = se_cmd->residual_count; | ||
1823 | ql_dbg(ql_dbg_tgt, vha, 0xe015, | ||
1824 | "Residual overflow: %d (tag %d, " | ||
1825 | "op %x, bufflen %d, rq_result %x)\n", prm->residual, | ||
1826 | cmd->tag, se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, | ||
1827 | cmd->bufflen, prm->rq_result); | ||
1828 | prm->rq_result |= SS_RESIDUAL_OVER; | ||
1829 | } | ||
1830 | |||
1831 | if (xmit_type & QLA_TGT_XMIT_STATUS) { | ||
1832 | /* | ||
1833 | * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be | ||
1834 | * ignored in *xmit_response() below | ||
1835 | */ | ||
1836 | if (qlt_has_data(cmd)) { | ||
1837 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer) || | ||
1838 | (IS_FWI2_CAPABLE(ha) && | ||
1839 | (prm->rq_result != 0))) { | ||
1840 | prm->add_status_pkt = 1; | ||
1841 | (*full_req_cnt)++; | ||
1842 | } | ||
1843 | } | ||
1844 | } | ||
1845 | |||
1846 | ql_dbg(ql_dbg_tgt, vha, 0xe016, | ||
1847 | "req_cnt=%d, full_req_cnt=%d, add_status_pkt=%d\n", | ||
1848 | prm->req_cnt, *full_req_cnt, prm->add_status_pkt); | ||
1849 | |||
1850 | return 0; | ||
1851 | } | ||
1852 | |||
1853 | static inline int qlt_need_explicit_conf(struct qla_hw_data *ha, | ||
1854 | struct qla_tgt_cmd *cmd, int sending_sense) | ||
1855 | { | ||
1856 | if (ha->tgt.enable_class_2) | ||
1857 | return 0; | ||
1858 | |||
1859 | if (sending_sense) | ||
1860 | return cmd->conf_compl_supported; | ||
1861 | else | ||
1862 | return ha->tgt.enable_explicit_conf && | ||
1863 | cmd->conf_compl_supported; | ||
1864 | } | ||
1865 | |||
1866 | #ifdef CONFIG_QLA_TGT_DEBUG_SRR | ||
1867 | /* | ||
1868 | * Original taken from the XFS code | ||
1869 | */ | ||
1870 | static unsigned long qlt_srr_random(void) | ||
1871 | { | ||
1872 | static int Inited; | ||
1873 | static unsigned long RandomValue; | ||
1874 | static DEFINE_SPINLOCK(lock); | ||
1875 | /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */ | ||
1876 | register long rv; | ||
1877 | register long lo; | ||
1878 | register long hi; | ||
1879 | unsigned long flags; | ||
1880 | |||
1881 | spin_lock_irqsave(&lock, flags); | ||
1882 | if (!Inited) { | ||
1883 | RandomValue = jiffies; | ||
1884 | Inited = 1; | ||
1885 | } | ||
1886 | rv = RandomValue; | ||
1887 | hi = rv / 127773; | ||
1888 | lo = rv % 127773; | ||
1889 | rv = 16807 * lo - 2836 * hi; | ||
1890 | if (rv <= 0) | ||
1891 | rv += 2147483647; | ||
1892 | RandomValue = rv; | ||
1893 | spin_unlock_irqrestore(&lock, flags); | ||
1894 | return rv; | ||
1895 | } | ||
1896 | |||
1897 | static void qlt_check_srr_debug(struct qla_tgt_cmd *cmd, int *xmit_type) | ||
1898 | { | ||
1899 | #if 0 /* This is not a real status packets lost, so it won't lead to SRR */ | ||
1900 | if ((*xmit_type & QLA_TGT_XMIT_STATUS) && (qlt_srr_random() % 200) | ||
1901 | == 50) { | ||
1902 | *xmit_type &= ~QLA_TGT_XMIT_STATUS; | ||
1903 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf015, | ||
1904 | "Dropping cmd %p (tag %d) status", cmd, cmd->tag); | ||
1905 | } | ||
1906 | #endif | ||
1907 | /* | ||
1908 | * It's currently not possible to simulate SRRs for FCP_WRITE without | ||
1909 | * a physical link layer failure, so don't even try here.. | ||
1910 | */ | ||
1911 | if (cmd->dma_data_direction != DMA_FROM_DEVICE) | ||
1912 | return; | ||
1913 | |||
1914 | if (qlt_has_data(cmd) && (cmd->sg_cnt > 1) && | ||
1915 | ((qlt_srr_random() % 100) == 20)) { | ||
1916 | int i, leave = 0; | ||
1917 | unsigned int tot_len = 0; | ||
1918 | |||
1919 | while (leave == 0) | ||
1920 | leave = qlt_srr_random() % cmd->sg_cnt; | ||
1921 | |||
1922 | for (i = 0; i < leave; i++) | ||
1923 | tot_len += cmd->sg[i].length; | ||
1924 | |||
1925 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf016, | ||
1926 | "Cutting cmd %p (tag %d) buffer" | ||
1927 | " tail to len %d, sg_cnt %d (cmd->bufflen %d," | ||
1928 | " cmd->sg_cnt %d)", cmd, cmd->tag, tot_len, leave, | ||
1929 | cmd->bufflen, cmd->sg_cnt); | ||
1930 | |||
1931 | cmd->bufflen = tot_len; | ||
1932 | cmd->sg_cnt = leave; | ||
1933 | } | ||
1934 | |||
1935 | if (qlt_has_data(cmd) && ((qlt_srr_random() % 100) == 70)) { | ||
1936 | unsigned int offset = qlt_srr_random() % cmd->bufflen; | ||
1937 | |||
1938 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf017, | ||
1939 | "Cutting cmd %p (tag %d) buffer head " | ||
1940 | "to offset %d (cmd->bufflen %d)", cmd, cmd->tag, offset, | ||
1941 | cmd->bufflen); | ||
1942 | if (offset == 0) | ||
1943 | *xmit_type &= ~QLA_TGT_XMIT_DATA; | ||
1944 | else if (qlt_set_data_offset(cmd, offset)) { | ||
1945 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf018, | ||
1946 | "qlt_set_data_offset() failed (tag %d)", cmd->tag); | ||
1947 | } | ||
1948 | } | ||
1949 | } | ||
1950 | #else | ||
1951 | static inline void qlt_check_srr_debug(struct qla_tgt_cmd *cmd, int *xmit_type) | ||
1952 | {} | ||
1953 | #endif | ||
1954 | |||
1955 | static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, | ||
1956 | struct qla_tgt_prm *prm) | ||
1957 | { | ||
1958 | prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len, | ||
1959 | (uint32_t)sizeof(ctio->u.status1.sense_data)); | ||
1960 | ctio->u.status0.flags |= | ||
1961 | __constant_cpu_to_le16(CTIO7_FLAGS_SEND_STATUS); | ||
1962 | if (qlt_need_explicit_conf(prm->tgt->ha, prm->cmd, 0)) { | ||
1963 | ctio->u.status0.flags |= __constant_cpu_to_le16( | ||
1964 | CTIO7_FLAGS_EXPLICIT_CONFORM | | ||
1965 | CTIO7_FLAGS_CONFORM_REQ); | ||
1966 | } | ||
1967 | ctio->u.status0.residual = cpu_to_le32(prm->residual); | ||
1968 | ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result); | ||
1969 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) { | ||
1970 | int i; | ||
1971 | |||
1972 | if (qlt_need_explicit_conf(prm->tgt->ha, prm->cmd, 1)) { | ||
1973 | if (prm->cmd->se_cmd.scsi_status != 0) { | ||
1974 | ql_dbg(ql_dbg_tgt, prm->cmd->vha, 0xe017, | ||
1975 | "Skipping EXPLICIT_CONFORM and " | ||
1976 | "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ " | ||
1977 | "non GOOD status\n"); | ||
1978 | goto skip_explict_conf; | ||
1979 | } | ||
1980 | ctio->u.status1.flags |= __constant_cpu_to_le16( | ||
1981 | CTIO7_FLAGS_EXPLICIT_CONFORM | | ||
1982 | CTIO7_FLAGS_CONFORM_REQ); | ||
1983 | } | ||
1984 | skip_explict_conf: | ||
1985 | ctio->u.status1.flags &= | ||
1986 | ~__constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); | ||
1987 | ctio->u.status1.flags |= | ||
1988 | __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); | ||
1989 | ctio->u.status1.scsi_status |= | ||
1990 | __constant_cpu_to_le16(SS_SENSE_LEN_VALID); | ||
1991 | ctio->u.status1.sense_length = | ||
1992 | cpu_to_le16(prm->sense_buffer_len); | ||
1993 | for (i = 0; i < prm->sense_buffer_len/4; i++) | ||
1994 | ((uint32_t *)ctio->u.status1.sense_data)[i] = | ||
1995 | cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]); | ||
1996 | #if 0 | ||
1997 | if (unlikely((prm->sense_buffer_len % 4) != 0)) { | ||
1998 | static int q; | ||
1999 | if (q < 10) { | ||
2000 | ql_dbg(ql_dbg_tgt, vha, 0xe04f, | ||
2001 | "qla_target(%d): %d bytes of sense " | ||
2002 | "lost", prm->tgt->ha->vp_idx, | ||
2003 | prm->sense_buffer_len % 4); | ||
2004 | q++; | ||
2005 | } | ||
2006 | } | ||
2007 | #endif | ||
2008 | } else { | ||
2009 | ctio->u.status1.flags &= | ||
2010 | ~__constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); | ||
2011 | ctio->u.status1.flags |= | ||
2012 | __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); | ||
2013 | ctio->u.status1.sense_length = 0; | ||
2014 | memset(ctio->u.status1.sense_data, 0, | ||
2015 | sizeof(ctio->u.status1.sense_data)); | ||
2016 | } | ||
2017 | |||
2018 | /* Sense with len > 24, is it possible ??? */ | ||
2019 | } | ||
2020 | |||
2021 | /* | ||
2022 | * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and * | ||
2023 | * QLA_TGT_XMIT_STATUS for >= 24xx silicon | ||
2024 | */ | ||
2025 | int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, | ||
2026 | uint8_t scsi_status) | ||
2027 | { | ||
2028 | struct scsi_qla_host *vha = cmd->vha; | ||
2029 | struct qla_hw_data *ha = vha->hw; | ||
2030 | struct ctio7_to_24xx *pkt; | ||
2031 | struct qla_tgt_prm prm; | ||
2032 | uint32_t full_req_cnt = 0; | ||
2033 | unsigned long flags = 0; | ||
2034 | int res; | ||
2035 | |||
2036 | memset(&prm, 0, sizeof(prm)); | ||
2037 | qlt_check_srr_debug(cmd, &xmit_type); | ||
2038 | |||
2039 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe018, | ||
2040 | "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, " | ||
2041 | "cmd->dma_data_direction=%d\n", (xmit_type & QLA_TGT_XMIT_STATUS) ? | ||
2042 | 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction); | ||
2043 | |||
2044 | res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, | ||
2045 | &full_req_cnt); | ||
2046 | if (unlikely(res != 0)) { | ||
2047 | if (res == QLA_TGT_PRE_XMIT_RESP_CMD_ABORTED) | ||
2048 | return 0; | ||
2049 | |||
2050 | return res; | ||
2051 | } | ||
2052 | |||
2053 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
2054 | |||
2055 | /* Does F/W have an IOCBs for this request */ | ||
2056 | res = qlt_check_reserve_free_req(vha, full_req_cnt); | ||
2057 | if (unlikely(res)) | ||
2058 | goto out_unmap_unlock; | ||
2059 | |||
2060 | res = qlt_24xx_build_ctio_pkt(&prm, vha); | ||
2061 | if (unlikely(res != 0)) | ||
2062 | goto out_unmap_unlock; | ||
2063 | |||
2064 | |||
2065 | pkt = (struct ctio7_to_24xx *)prm.pkt; | ||
2066 | |||
2067 | if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) { | ||
2068 | pkt->u.status0.flags |= | ||
2069 | __constant_cpu_to_le16(CTIO7_FLAGS_DATA_IN | | ||
2070 | CTIO7_FLAGS_STATUS_MODE_0); | ||
2071 | |||
2072 | qlt_load_data_segments(&prm, vha); | ||
2073 | |||
2074 | if (prm.add_status_pkt == 0) { | ||
2075 | if (xmit_type & QLA_TGT_XMIT_STATUS) { | ||
2076 | pkt->u.status0.scsi_status = | ||
2077 | cpu_to_le16(prm.rq_result); | ||
2078 | pkt->u.status0.residual = | ||
2079 | cpu_to_le32(prm.residual); | ||
2080 | pkt->u.status0.flags |= __constant_cpu_to_le16( | ||
2081 | CTIO7_FLAGS_SEND_STATUS); | ||
2082 | if (qlt_need_explicit_conf(ha, cmd, 0)) { | ||
2083 | pkt->u.status0.flags |= | ||
2084 | __constant_cpu_to_le16( | ||
2085 | CTIO7_FLAGS_EXPLICIT_CONFORM | | ||
2086 | CTIO7_FLAGS_CONFORM_REQ); | ||
2087 | } | ||
2088 | } | ||
2089 | |||
2090 | } else { | ||
2091 | /* | ||
2092 | * We have already made sure that there is sufficient | ||
2093 | * amount of request entries to not drop HW lock in | ||
2094 | * req_pkt(). | ||
2095 | */ | ||
2096 | struct ctio7_to_24xx *ctio = | ||
2097 | (struct ctio7_to_24xx *)qlt_get_req_pkt(vha); | ||
2098 | |||
2099 | ql_dbg(ql_dbg_tgt, vha, 0xe019, | ||
2100 | "Building additional status packet\n"); | ||
2101 | |||
2102 | memcpy(ctio, pkt, sizeof(*ctio)); | ||
2103 | ctio->entry_count = 1; | ||
2104 | ctio->dseg_count = 0; | ||
2105 | ctio->u.status1.flags &= ~__constant_cpu_to_le16( | ||
2106 | CTIO7_FLAGS_DATA_IN); | ||
2107 | |||
2108 | /* Real finish is ctio_m1's finish */ | ||
2109 | pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK; | ||
2110 | pkt->u.status0.flags |= __constant_cpu_to_le16( | ||
2111 | CTIO7_FLAGS_DONT_RET_CTIO); | ||
2112 | qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio, | ||
2113 | &prm); | ||
2114 | pr_debug("Status CTIO7: %p\n", ctio); | ||
2115 | } | ||
2116 | } else | ||
2117 | qlt_24xx_init_ctio_to_isp(pkt, &prm); | ||
2118 | |||
2119 | |||
2120 | cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */ | ||
2121 | |||
2122 | ql_dbg(ql_dbg_tgt, vha, 0xe01a, | ||
2123 | "Xmitting CTIO7 response pkt for 24xx: %p scsi_status: 0x%02x\n", | ||
2124 | pkt, scsi_status); | ||
2125 | |||
2126 | qla2x00_start_iocbs(vha, vha->req); | ||
2127 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
2128 | |||
2129 | return 0; | ||
2130 | |||
2131 | out_unmap_unlock: | ||
2132 | if (cmd->sg_mapped) | ||
2133 | qlt_unmap_sg(vha, cmd); | ||
2134 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
2135 | |||
2136 | return res; | ||
2137 | } | ||
2138 | EXPORT_SYMBOL(qlt_xmit_response); | ||
2139 | |||
2140 | int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) | ||
2141 | { | ||
2142 | struct ctio7_to_24xx *pkt; | ||
2143 | struct scsi_qla_host *vha = cmd->vha; | ||
2144 | struct qla_hw_data *ha = vha->hw; | ||
2145 | struct qla_tgt *tgt = cmd->tgt; | ||
2146 | struct qla_tgt_prm prm; | ||
2147 | unsigned long flags; | ||
2148 | int res = 0; | ||
2149 | |||
2150 | memset(&prm, 0, sizeof(prm)); | ||
2151 | prm.cmd = cmd; | ||
2152 | prm.tgt = tgt; | ||
2153 | prm.sg = NULL; | ||
2154 | prm.req_cnt = 1; | ||
2155 | |||
2156 | /* Send marker if required */ | ||
2157 | if (qlt_issue_marker(vha, 0) != QLA_SUCCESS) | ||
2158 | return -EIO; | ||
2159 | |||
2160 | ql_dbg(ql_dbg_tgt, vha, 0xe01b, "CTIO_start: vha(%d)", | ||
2161 | (int)vha->vp_idx); | ||
2162 | |||
2163 | /* Calculate number of entries and segments required */ | ||
2164 | if (qlt_pci_map_calc_cnt(&prm) != 0) | ||
2165 | return -EAGAIN; | ||
2166 | |||
2167 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
2168 | |||
2169 | /* Does F/W have an IOCBs for this request */ | ||
2170 | res = qlt_check_reserve_free_req(vha, prm.req_cnt); | ||
2171 | if (res != 0) | ||
2172 | goto out_unlock_free_unmap; | ||
2173 | |||
2174 | res = qlt_24xx_build_ctio_pkt(&prm, vha); | ||
2175 | if (unlikely(res != 0)) | ||
2176 | goto out_unlock_free_unmap; | ||
2177 | pkt = (struct ctio7_to_24xx *)prm.pkt; | ||
2178 | pkt->u.status0.flags |= __constant_cpu_to_le16(CTIO7_FLAGS_DATA_OUT | | ||
2179 | CTIO7_FLAGS_STATUS_MODE_0); | ||
2180 | qlt_load_data_segments(&prm, vha); | ||
2181 | |||
2182 | cmd->state = QLA_TGT_STATE_NEED_DATA; | ||
2183 | |||
2184 | qla2x00_start_iocbs(vha, vha->req); | ||
2185 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
2186 | |||
2187 | return res; | ||
2188 | |||
2189 | out_unlock_free_unmap: | ||
2190 | if (cmd->sg_mapped) | ||
2191 | qlt_unmap_sg(vha, cmd); | ||
2192 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
2193 | |||
2194 | return res; | ||
2195 | } | ||
2196 | EXPORT_SYMBOL(qlt_rdy_to_xfer); | ||
2197 | |||
2198 | /* If hardware_lock held on entry, might drop it, then reaquire */ | ||
2199 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ | ||
2200 | static int __qlt_send_term_exchange(struct scsi_qla_host *vha, | ||
2201 | struct qla_tgt_cmd *cmd, | ||
2202 | struct atio_from_isp *atio) | ||
2203 | { | ||
2204 | struct ctio7_to_24xx *ctio24; | ||
2205 | struct qla_hw_data *ha = vha->hw; | ||
2206 | request_t *pkt; | ||
2207 | int ret = 0; | ||
2208 | |||
2209 | ql_dbg(ql_dbg_tgt, vha, 0xe01c, "Sending TERM EXCH CTIO (ha=%p)\n", ha); | ||
2210 | |||
2211 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); | ||
2212 | if (pkt == NULL) { | ||
2213 | ql_dbg(ql_dbg_tgt, vha, 0xe050, | ||
2214 | "qla_target(%d): %s failed: unable to allocate " | ||
2215 | "request packet\n", vha->vp_idx, __func__); | ||
2216 | return -ENOMEM; | ||
2217 | } | ||
2218 | |||
2219 | if (cmd != NULL) { | ||
2220 | if (cmd->state < QLA_TGT_STATE_PROCESSED) { | ||
2221 | ql_dbg(ql_dbg_tgt, vha, 0xe051, | ||
2222 | "qla_target(%d): Terminating cmd %p with " | ||
2223 | "incorrect state %d\n", vha->vp_idx, cmd, | ||
2224 | cmd->state); | ||
2225 | } else | ||
2226 | ret = 1; | ||
2227 | } | ||
2228 | |||
2229 | pkt->entry_count = 1; | ||
2230 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; | ||
2231 | |||
2232 | ctio24 = (struct ctio7_to_24xx *)pkt; | ||
2233 | ctio24->entry_type = CTIO_TYPE7; | ||
2234 | ctio24->nport_handle = cmd ? cmd->loop_id : CTIO7_NHANDLE_UNRECOGNIZED; | ||
2235 | ctio24->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT); | ||
2236 | ctio24->vp_index = vha->vp_idx; | ||
2237 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; | ||
2238 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; | ||
2239 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; | ||
2240 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; | ||
2241 | ctio24->u.status1.flags = (atio->u.isp24.attr << 9) | | ||
2242 | __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | | ||
2243 | CTIO7_FLAGS_TERMINATE); | ||
2244 | ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); | ||
2245 | |||
2246 | /* Most likely, it isn't needed */ | ||
2247 | ctio24->u.status1.residual = get_unaligned((uint32_t *) | ||
2248 | &atio->u.isp24.fcp_cmnd.add_cdb[ | ||
2249 | atio->u.isp24.fcp_cmnd.add_cdb_len]); | ||
2250 | if (ctio24->u.status1.residual != 0) | ||
2251 | ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER; | ||
2252 | |||
2253 | qla2x00_start_iocbs(vha, vha->req); | ||
2254 | return ret; | ||
2255 | } | ||
2256 | |||
2257 | static void qlt_send_term_exchange(struct scsi_qla_host *vha, | ||
2258 | struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked) | ||
2259 | { | ||
2260 | unsigned long flags; | ||
2261 | int rc; | ||
2262 | |||
2263 | if (qlt_issue_marker(vha, ha_locked) < 0) | ||
2264 | return; | ||
2265 | |||
2266 | if (ha_locked) { | ||
2267 | rc = __qlt_send_term_exchange(vha, cmd, atio); | ||
2268 | goto done; | ||
2269 | } | ||
2270 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); | ||
2271 | rc = __qlt_send_term_exchange(vha, cmd, atio); | ||
2272 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); | ||
2273 | done: | ||
2274 | if (rc == 1) { | ||
2275 | if (!ha_locked && !in_interrupt()) | ||
2276 | msleep(250); /* just in case */ | ||
2277 | |||
2278 | vha->hw->tgt.tgt_ops->free_cmd(cmd); | ||
2279 | } | ||
2280 | } | ||
2281 | |||
2282 | void qlt_free_cmd(struct qla_tgt_cmd *cmd) | ||
2283 | { | ||
2284 | BUG_ON(cmd->sg_mapped); | ||
2285 | |||
2286 | if (unlikely(cmd->free_sg)) | ||
2287 | kfree(cmd->sg); | ||
2288 | kmem_cache_free(qla_tgt_cmd_cachep, cmd); | ||
2289 | } | ||
2290 | EXPORT_SYMBOL(qlt_free_cmd); | ||
2291 | |||
2292 | /* ha->hardware_lock supposed to be held on entry */ | ||
2293 | static int qlt_prepare_srr_ctio(struct scsi_qla_host *vha, | ||
2294 | struct qla_tgt_cmd *cmd, void *ctio) | ||
2295 | { | ||
2296 | struct qla_tgt_srr_ctio *sc; | ||
2297 | struct qla_hw_data *ha = vha->hw; | ||
2298 | struct qla_tgt *tgt = ha->tgt.qla_tgt; | ||
2299 | struct qla_tgt_srr_imm *imm; | ||
2300 | |||
2301 | tgt->ctio_srr_id++; | ||
2302 | |||
2303 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019, | ||
2304 | "qla_target(%d): CTIO with SRR status received\n", vha->vp_idx); | ||
2305 | |||
2306 | if (!ctio) { | ||
2307 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf055, | ||
2308 | "qla_target(%d): SRR CTIO, but ctio is NULL\n", | ||
2309 | vha->vp_idx); | ||
2310 | return -EINVAL; | ||
2311 | } | ||
2312 | |||
2313 | sc = kzalloc(sizeof(*sc), GFP_ATOMIC); | ||
2314 | if (sc != NULL) { | ||
2315 | sc->cmd = cmd; | ||
2316 | /* IRQ is already OFF */ | ||
2317 | spin_lock(&tgt->srr_lock); | ||
2318 | sc->srr_id = tgt->ctio_srr_id; | ||
2319 | list_add_tail(&sc->srr_list_entry, | ||
2320 | &tgt->srr_ctio_list); | ||
2321 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a, | ||
2322 | "CTIO SRR %p added (id %d)\n", sc, sc->srr_id); | ||
2323 | if (tgt->imm_srr_id == tgt->ctio_srr_id) { | ||
2324 | int found = 0; | ||
2325 | list_for_each_entry(imm, &tgt->srr_imm_list, | ||
2326 | srr_list_entry) { | ||
2327 | if (imm->srr_id == sc->srr_id) { | ||
2328 | found = 1; | ||
2329 | break; | ||
2330 | } | ||
2331 | } | ||
2332 | if (found) { | ||
2333 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01b, | ||
2334 | "Scheduling srr work\n"); | ||
2335 | schedule_work(&tgt->srr_work); | ||
2336 | } else { | ||
2337 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf056, | ||
2338 | "qla_target(%d): imm_srr_id " | ||
2339 | "== ctio_srr_id (%d), but there is no " | ||
2340 | "corresponding SRR IMM, deleting CTIO " | ||
2341 | "SRR %p\n", vha->vp_idx, | ||
2342 | tgt->ctio_srr_id, sc); | ||
2343 | list_del(&sc->srr_list_entry); | ||
2344 | spin_unlock(&tgt->srr_lock); | ||
2345 | |||
2346 | kfree(sc); | ||
2347 | return -EINVAL; | ||
2348 | } | ||
2349 | } | ||
2350 | spin_unlock(&tgt->srr_lock); | ||
2351 | } else { | ||
2352 | struct qla_tgt_srr_imm *ti; | ||
2353 | |||
2354 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf057, | ||
2355 | "qla_target(%d): Unable to allocate SRR CTIO entry\n", | ||
2356 | vha->vp_idx); | ||
2357 | spin_lock(&tgt->srr_lock); | ||
2358 | list_for_each_entry_safe(imm, ti, &tgt->srr_imm_list, | ||
2359 | srr_list_entry) { | ||
2360 | if (imm->srr_id == tgt->ctio_srr_id) { | ||
2361 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01c, | ||
2362 | "IMM SRR %p deleted (id %d)\n", | ||
2363 | imm, imm->srr_id); | ||
2364 | list_del(&imm->srr_list_entry); | ||
2365 | qlt_reject_free_srr_imm(vha, imm, 1); | ||
2366 | } | ||
2367 | } | ||
2368 | spin_unlock(&tgt->srr_lock); | ||
2369 | |||
2370 | return -ENOMEM; | ||
2371 | } | ||
2372 | |||
2373 | return 0; | ||
2374 | } | ||
2375 | |||
2376 | /* | ||
2377 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | ||
2378 | */ | ||
2379 | static int qlt_term_ctio_exchange(struct scsi_qla_host *vha, void *ctio, | ||
2380 | struct qla_tgt_cmd *cmd, uint32_t status) | ||
2381 | { | ||
2382 | int term = 0; | ||
2383 | |||
2384 | if (ctio != NULL) { | ||
2385 | struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio; | ||
2386 | term = !(c->flags & | ||
2387 | __constant_cpu_to_le16(OF_TERM_EXCH)); | ||
2388 | } else | ||
2389 | term = 1; | ||
2390 | |||
2391 | if (term) | ||
2392 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 1); | ||
2393 | |||
2394 | return term; | ||
2395 | } | ||
2396 | |||
2397 | /* ha->hardware_lock supposed to be held on entry */ | ||
2398 | static inline struct qla_tgt_cmd *qlt_get_cmd(struct scsi_qla_host *vha, | ||
2399 | uint32_t handle) | ||
2400 | { | ||
2401 | struct qla_hw_data *ha = vha->hw; | ||
2402 | |||
2403 | handle--; | ||
2404 | if (ha->tgt.cmds[handle] != NULL) { | ||
2405 | struct qla_tgt_cmd *cmd = ha->tgt.cmds[handle]; | ||
2406 | ha->tgt.cmds[handle] = NULL; | ||
2407 | return cmd; | ||
2408 | } else | ||
2409 | return NULL; | ||
2410 | } | ||
2411 | |||
2412 | /* ha->hardware_lock supposed to be held on entry */ | ||
2413 | static struct qla_tgt_cmd *qlt_ctio_to_cmd(struct scsi_qla_host *vha, | ||
2414 | uint32_t handle, void *ctio) | ||
2415 | { | ||
2416 | struct qla_tgt_cmd *cmd = NULL; | ||
2417 | |||
2418 | /* Clear out internal marks */ | ||
2419 | handle &= ~(CTIO_COMPLETION_HANDLE_MARK | | ||
2420 | CTIO_INTERMEDIATE_HANDLE_MARK); | ||
2421 | |||
2422 | if (handle != QLA_TGT_NULL_HANDLE) { | ||
2423 | if (unlikely(handle == QLA_TGT_SKIP_HANDLE)) { | ||
2424 | ql_dbg(ql_dbg_tgt, vha, 0xe01d, "%s", | ||
2425 | "SKIP_HANDLE CTIO\n"); | ||
2426 | return NULL; | ||
2427 | } | ||
2428 | /* handle-1 is actually used */ | ||
2429 | if (unlikely(handle > MAX_OUTSTANDING_COMMANDS)) { | ||
2430 | ql_dbg(ql_dbg_tgt, vha, 0xe052, | ||
2431 | "qla_target(%d): Wrong handle %x received\n", | ||
2432 | vha->vp_idx, handle); | ||
2433 | return NULL; | ||
2434 | } | ||
2435 | cmd = qlt_get_cmd(vha, handle); | ||
2436 | if (unlikely(cmd == NULL)) { | ||
2437 | ql_dbg(ql_dbg_tgt, vha, 0xe053, | ||
2438 | "qla_target(%d): Suspicious: unable to " | ||
2439 | "find the command with handle %x\n", vha->vp_idx, | ||
2440 | handle); | ||
2441 | return NULL; | ||
2442 | } | ||
2443 | } else if (ctio != NULL) { | ||
2444 | /* We can't get loop ID from CTIO7 */ | ||
2445 | ql_dbg(ql_dbg_tgt, vha, 0xe054, | ||
2446 | "qla_target(%d): Wrong CTIO received: QLA24xx doesn't " | ||
2447 | "support NULL handles\n", vha->vp_idx); | ||
2448 | return NULL; | ||
2449 | } | ||
2450 | |||
2451 | return cmd; | ||
2452 | } | ||
2453 | |||
2454 | /* | ||
2455 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | ||
2456 | */ | ||
2457 | static void qlt_do_ctio_completion(struct scsi_qla_host *vha, uint32_t handle, | ||
2458 | uint32_t status, void *ctio) | ||
2459 | { | ||
2460 | struct qla_hw_data *ha = vha->hw; | ||
2461 | struct se_cmd *se_cmd; | ||
2462 | struct target_core_fabric_ops *tfo; | ||
2463 | struct qla_tgt_cmd *cmd; | ||
2464 | |||
2465 | ql_dbg(ql_dbg_tgt, vha, 0xe01e, | ||
2466 | "qla_target(%d): handle(ctio %p status %#x) <- %08x\n", | ||
2467 | vha->vp_idx, ctio, status, handle); | ||
2468 | |||
2469 | if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { | ||
2470 | /* That could happen only in case of an error/reset/abort */ | ||
2471 | if (status != CTIO_SUCCESS) { | ||
2472 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d, | ||
2473 | "Intermediate CTIO received" | ||
2474 | " (status %x)\n", status); | ||
2475 | } | ||
2476 | return; | ||
2477 | } | ||
2478 | |||
2479 | cmd = qlt_ctio_to_cmd(vha, handle, ctio); | ||
2480 | if (cmd == NULL) { | ||
2481 | if (status != CTIO_SUCCESS) | ||
2482 | qlt_term_ctio_exchange(vha, ctio, NULL, status); | ||
2483 | return; | ||
2484 | } | ||
2485 | se_cmd = &cmd->se_cmd; | ||
2486 | tfo = se_cmd->se_tfo; | ||
2487 | |||
2488 | if (cmd->sg_mapped) | ||
2489 | qlt_unmap_sg(vha, cmd); | ||
2490 | |||
2491 | if (unlikely(status != CTIO_SUCCESS)) { | ||
2492 | switch (status & 0xFFFF) { | ||
2493 | case CTIO_LIP_RESET: | ||
2494 | case CTIO_TARGET_RESET: | ||
2495 | case CTIO_ABORTED: | ||
2496 | case CTIO_TIMEOUT: | ||
2497 | case CTIO_INVALID_RX_ID: | ||
2498 | /* They are OK */ | ||
2499 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058, | ||
2500 | "qla_target(%d): CTIO with " | ||
2501 | "status %#x received, state %x, se_cmd %p, " | ||
2502 | "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, " | ||
2503 | "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx, | ||
2504 | status, cmd->state, se_cmd); | ||
2505 | break; | ||
2506 | |||
2507 | case CTIO_PORT_LOGGED_OUT: | ||
2508 | case CTIO_PORT_UNAVAILABLE: | ||
2509 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059, | ||
2510 | "qla_target(%d): CTIO with PORT LOGGED " | ||
2511 | "OUT (29) or PORT UNAVAILABLE (28) status %x " | ||
2512 | "received (state %x, se_cmd %p)\n", vha->vp_idx, | ||
2513 | status, cmd->state, se_cmd); | ||
2514 | break; | ||
2515 | |||
2516 | case CTIO_SRR_RECEIVED: | ||
2517 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05a, | ||
2518 | "qla_target(%d): CTIO with SRR_RECEIVED" | ||
2519 | " status %x received (state %x, se_cmd %p)\n", | ||
2520 | vha->vp_idx, status, cmd->state, se_cmd); | ||
2521 | if (qlt_prepare_srr_ctio(vha, cmd, ctio) != 0) | ||
2522 | break; | ||
2523 | else | ||
2524 | return; | ||
2525 | |||
2526 | default: | ||
2527 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, | ||
2528 | "qla_target(%d): CTIO with error status " | ||
2529 | "0x%x received (state %x, se_cmd %p\n", | ||
2530 | vha->vp_idx, status, cmd->state, se_cmd); | ||
2531 | break; | ||
2532 | } | ||
2533 | |||
2534 | if (cmd->state != QLA_TGT_STATE_NEED_DATA) | ||
2535 | if (qlt_term_ctio_exchange(vha, ctio, cmd, status)) | ||
2536 | return; | ||
2537 | } | ||
2538 | |||
2539 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { | ||
2540 | ql_dbg(ql_dbg_tgt, vha, 0xe01f, "Command %p finished\n", cmd); | ||
2541 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { | ||
2542 | int rx_status = 0; | ||
2543 | |||
2544 | cmd->state = QLA_TGT_STATE_DATA_IN; | ||
2545 | |||
2546 | if (unlikely(status != CTIO_SUCCESS)) | ||
2547 | rx_status = -EIO; | ||
2548 | else | ||
2549 | cmd->write_data_transferred = 1; | ||
2550 | |||
2551 | ql_dbg(ql_dbg_tgt, vha, 0xe020, | ||
2552 | "Data received, context %x, rx_status %d\n", | ||
2553 | 0x0, rx_status); | ||
2554 | |||
2555 | ha->tgt.tgt_ops->handle_data(cmd); | ||
2556 | return; | ||
2557 | } else if (cmd->state == QLA_TGT_STATE_ABORTED) { | ||
2558 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, | ||
2559 | "Aborted command %p (tag %d) finished\n", cmd, cmd->tag); | ||
2560 | } else { | ||
2561 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, | ||
2562 | "qla_target(%d): A command in state (%d) should " | ||
2563 | "not return a CTIO complete\n", vha->vp_idx, cmd->state); | ||
2564 | } | ||
2565 | |||
2566 | if (unlikely(status != CTIO_SUCCESS)) { | ||
2567 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n"); | ||
2568 | dump_stack(); | ||
2569 | } | ||
2570 | |||
2571 | ha->tgt.tgt_ops->free_cmd(cmd); | ||
2572 | } | ||
2573 | |||
2574 | /* ha->hardware_lock supposed to be held on entry */ | ||
2575 | /* called via callback from qla2xxx */ | ||
2576 | void qlt_ctio_completion(struct scsi_qla_host *vha, uint32_t handle) | ||
2577 | { | ||
2578 | struct qla_hw_data *ha = vha->hw; | ||
2579 | struct qla_tgt *tgt = ha->tgt.qla_tgt; | ||
2580 | |||
2581 | if (likely(tgt == NULL)) { | ||
2582 | ql_dbg(ql_dbg_tgt, vha, 0xe021, | ||
2583 | "CTIO, but target mode not enabled" | ||
2584 | " (ha %d %p handle %#x)", vha->vp_idx, ha, handle); | ||
2585 | return; | ||
2586 | } | ||
2587 | |||
2588 | tgt->irq_cmd_count++; | ||
2589 | qlt_do_ctio_completion(vha, handle, CTIO_SUCCESS, NULL); | ||
2590 | tgt->irq_cmd_count--; | ||
2591 | } | ||
2592 | |||
2593 | static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha, | ||
2594 | uint8_t task_codes) | ||
2595 | { | ||
2596 | int fcp_task_attr; | ||
2597 | |||
2598 | switch (task_codes) { | ||
2599 | case ATIO_SIMPLE_QUEUE: | ||
2600 | fcp_task_attr = MSG_SIMPLE_TAG; | ||
2601 | break; | ||
2602 | case ATIO_HEAD_OF_QUEUE: | ||
2603 | fcp_task_attr = MSG_HEAD_TAG; | ||
2604 | break; | ||
2605 | case ATIO_ORDERED_QUEUE: | ||
2606 | fcp_task_attr = MSG_ORDERED_TAG; | ||
2607 | break; | ||
2608 | case ATIO_ACA_QUEUE: | ||
2609 | fcp_task_attr = MSG_ACA_TAG; | ||
2610 | break; | ||
2611 | case ATIO_UNTAGGED: | ||
2612 | fcp_task_attr = MSG_SIMPLE_TAG; | ||
2613 | break; | ||
2614 | default: | ||
2615 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d, | ||
2616 | "qla_target: unknown task code %x, use ORDERED instead\n", | ||
2617 | task_codes); | ||
2618 | fcp_task_attr = MSG_ORDERED_TAG; | ||
2619 | break; | ||
2620 | } | ||
2621 | |||
2622 | return fcp_task_attr; | ||
2623 | } | ||
2624 | |||
2625 | static struct qla_tgt_sess *qlt_make_local_sess(struct scsi_qla_host *, | ||
2626 | uint8_t *); | ||
2627 | /* | ||
2628 | * Process context for I/O path into tcm_qla2xxx code | ||
2629 | */ | ||
2630 | static void qlt_do_work(struct work_struct *work) | ||
2631 | { | ||
2632 | struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work); | ||
2633 | scsi_qla_host_t *vha = cmd->vha; | ||
2634 | struct qla_hw_data *ha = vha->hw; | ||
2635 | struct qla_tgt *tgt = ha->tgt.qla_tgt; | ||
2636 | struct qla_tgt_sess *sess = NULL; | ||
2637 | struct atio_from_isp *atio = &cmd->atio; | ||
2638 | unsigned char *cdb; | ||
2639 | unsigned long flags; | ||
2640 | uint32_t data_length; | ||
2641 | int ret, fcp_task_attr, data_dir, bidi = 0; | ||
2642 | |||
2643 | if (tgt->tgt_stop) | ||
2644 | goto out_term; | ||
2645 | |||
2646 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
2647 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, | ||
2648 | atio->u.isp24.fcp_hdr.s_id); | ||
2649 | if (sess) { | ||
2650 | if (unlikely(sess->tearing_down)) { | ||
2651 | sess = NULL; | ||
2652 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
2653 | goto out_term; | ||
2654 | } else { | ||
2655 | /* | ||
2656 | * Do the extra kref_get() before dropping | ||
2657 | * qla_hw_data->hardware_lock. | ||
2658 | */ | ||
2659 | kref_get(&sess->se_sess->sess_kref); | ||
2660 | } | ||
2661 | } | ||
2662 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
2663 | |||
2664 | if (unlikely(!sess)) { | ||
2665 | uint8_t *s_id = atio->u.isp24.fcp_hdr.s_id; | ||
2666 | |||
2667 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf022, | ||
2668 | "qla_target(%d): Unable to find wwn login" | ||
2669 | " (s_id %x:%x:%x), trying to create it manually\n", | ||
2670 | vha->vp_idx, s_id[0], s_id[1], s_id[2]); | ||
2671 | |||
2672 | if (atio->u.raw.entry_count > 1) { | ||
2673 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf023, | ||
2674 | "Dropping multy entry cmd %p\n", cmd); | ||
2675 | goto out_term; | ||
2676 | } | ||
2677 | |||
2678 | mutex_lock(&ha->tgt.tgt_mutex); | ||
2679 | sess = qlt_make_local_sess(vha, s_id); | ||
2680 | /* sess has an extra creation ref. */ | ||
2681 | mutex_unlock(&ha->tgt.tgt_mutex); | ||
2682 | |||
2683 | if (!sess) | ||
2684 | goto out_term; | ||
2685 | } | ||
2686 | |||
2687 | cmd->sess = sess; | ||
2688 | cmd->loop_id = sess->loop_id; | ||
2689 | cmd->conf_compl_supported = sess->conf_compl_supported; | ||
2690 | |||
2691 | cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; | ||
2692 | cmd->tag = atio->u.isp24.exchange_addr; | ||
2693 | cmd->unpacked_lun = scsilun_to_int( | ||
2694 | (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun); | ||
2695 | |||
2696 | if (atio->u.isp24.fcp_cmnd.rddata && | ||
2697 | atio->u.isp24.fcp_cmnd.wrdata) { | ||
2698 | bidi = 1; | ||
2699 | data_dir = DMA_TO_DEVICE; | ||
2700 | } else if (atio->u.isp24.fcp_cmnd.rddata) | ||
2701 | data_dir = DMA_FROM_DEVICE; | ||
2702 | else if (atio->u.isp24.fcp_cmnd.wrdata) | ||
2703 | data_dir = DMA_TO_DEVICE; | ||
2704 | else | ||
2705 | data_dir = DMA_NONE; | ||
2706 | |||
2707 | fcp_task_attr = qlt_get_fcp_task_attr(vha, | ||
2708 | atio->u.isp24.fcp_cmnd.task_attr); | ||
2709 | data_length = be32_to_cpu(get_unaligned((uint32_t *) | ||
2710 | &atio->u.isp24.fcp_cmnd.add_cdb[ | ||
2711 | atio->u.isp24.fcp_cmnd.add_cdb_len])); | ||
2712 | |||
2713 | ql_dbg(ql_dbg_tgt, vha, 0xe022, | ||
2714 | "qla_target: START qla command: %p lun: 0x%04x (tag %d)\n", | ||
2715 | cmd, cmd->unpacked_lun, cmd->tag); | ||
2716 | |||
2717 | ret = vha->hw->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length, | ||
2718 | fcp_task_attr, data_dir, bidi); | ||
2719 | if (ret != 0) | ||
2720 | goto out_term; | ||
2721 | /* | ||
2722 | * Drop extra session reference from qla_tgt_handle_cmd_for_atio*( | ||
2723 | */ | ||
2724 | ha->tgt.tgt_ops->put_sess(sess); | ||
2725 | return; | ||
2726 | |||
2727 | out_term: | ||
2728 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf020, "Terminating work cmd %p", cmd); | ||
2729 | /* | ||
2730 | * cmd has not sent to target yet, so pass NULL as the second argument | ||
2731 | */ | ||
2732 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
2733 | qlt_send_term_exchange(vha, NULL, &cmd->atio, 1); | ||
2734 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
2735 | if (sess) | ||
2736 | ha->tgt.tgt_ops->put_sess(sess); | ||
2737 | } | ||
2738 | |||
2739 | /* ha->hardware_lock supposed to be held on entry */ | ||
2740 | static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, | ||
2741 | struct atio_from_isp *atio) | ||
2742 | { | ||
2743 | struct qla_hw_data *ha = vha->hw; | ||
2744 | struct qla_tgt *tgt = ha->tgt.qla_tgt; | ||
2745 | struct qla_tgt_cmd *cmd; | ||
2746 | |||
2747 | if (unlikely(tgt->tgt_stop)) { | ||
2748 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021, | ||
2749 | "New command while device %p is shutting down\n", tgt); | ||
2750 | return -EFAULT; | ||
2751 | } | ||
2752 | |||
2753 | cmd = kmem_cache_zalloc(qla_tgt_cmd_cachep, GFP_ATOMIC); | ||
2754 | if (!cmd) { | ||
2755 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05e, | ||
2756 | "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx); | ||
2757 | return -ENOMEM; | ||
2758 | } | ||
2759 | |||
2760 | INIT_LIST_HEAD(&cmd->cmd_list); | ||
2761 | |||
2762 | memcpy(&cmd->atio, atio, sizeof(*atio)); | ||
2763 | cmd->state = QLA_TGT_STATE_NEW; | ||
2764 | cmd->tgt = ha->tgt.qla_tgt; | ||
2765 | cmd->vha = vha; | ||
2766 | |||
2767 | INIT_WORK(&cmd->work, qlt_do_work); | ||
2768 | queue_work(qla_tgt_wq, &cmd->work); | ||
2769 | return 0; | ||
2770 | |||
2771 | } | ||
2772 | |||
2773 | /* ha->hardware_lock supposed to be held on entry */ | ||
2774 | static int qlt_issue_task_mgmt(struct qla_tgt_sess *sess, uint32_t lun, | ||
2775 | int fn, void *iocb, int flags) | ||
2776 | { | ||
2777 | struct scsi_qla_host *vha = sess->vha; | ||
2778 | struct qla_hw_data *ha = vha->hw; | ||
2779 | struct qla_tgt_mgmt_cmd *mcmd; | ||
2780 | int res; | ||
2781 | uint8_t tmr_func; | ||
2782 | |||
2783 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); | ||
2784 | if (!mcmd) { | ||
2785 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009, | ||
2786 | "qla_target(%d): Allocation of management " | ||
2787 | "command failed, some commands and their data could " | ||
2788 | "leak\n", vha->vp_idx); | ||
2789 | return -ENOMEM; | ||
2790 | } | ||
2791 | memset(mcmd, 0, sizeof(*mcmd)); | ||
2792 | mcmd->sess = sess; | ||
2793 | |||
2794 | if (iocb) { | ||
2795 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, | ||
2796 | sizeof(mcmd->orig_iocb.imm_ntfy)); | ||
2797 | } | ||
2798 | mcmd->tmr_func = fn; | ||
2799 | mcmd->flags = flags; | ||
2800 | |||
2801 | switch (fn) { | ||
2802 | case QLA_TGT_CLEAR_ACA: | ||
2803 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10000, | ||
2804 | "qla_target(%d): CLEAR_ACA received\n", sess->vha->vp_idx); | ||
2805 | tmr_func = TMR_CLEAR_ACA; | ||
2806 | break; | ||
2807 | |||
2808 | case QLA_TGT_TARGET_RESET: | ||
2809 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10001, | ||
2810 | "qla_target(%d): TARGET_RESET received\n", | ||
2811 | sess->vha->vp_idx); | ||
2812 | tmr_func = TMR_TARGET_WARM_RESET; | ||
2813 | break; | ||
2814 | |||
2815 | case QLA_TGT_LUN_RESET: | ||
2816 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10002, | ||
2817 | "qla_target(%d): LUN_RESET received\n", sess->vha->vp_idx); | ||
2818 | tmr_func = TMR_LUN_RESET; | ||
2819 | break; | ||
2820 | |||
2821 | case QLA_TGT_CLEAR_TS: | ||
2822 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10003, | ||
2823 | "qla_target(%d): CLEAR_TS received\n", sess->vha->vp_idx); | ||
2824 | tmr_func = TMR_CLEAR_TASK_SET; | ||
2825 | break; | ||
2826 | |||
2827 | case QLA_TGT_ABORT_TS: | ||
2828 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10004, | ||
2829 | "qla_target(%d): ABORT_TS received\n", sess->vha->vp_idx); | ||
2830 | tmr_func = TMR_ABORT_TASK_SET; | ||
2831 | break; | ||
2832 | #if 0 | ||
2833 | case QLA_TGT_ABORT_ALL: | ||
2834 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10005, | ||
2835 | "qla_target(%d): Doing ABORT_ALL_TASKS\n", | ||
2836 | sess->vha->vp_idx); | ||
2837 | tmr_func = 0; | ||
2838 | break; | ||
2839 | |||
2840 | case QLA_TGT_ABORT_ALL_SESS: | ||
2841 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10006, | ||
2842 | "qla_target(%d): Doing ABORT_ALL_TASKS_SESS\n", | ||
2843 | sess->vha->vp_idx); | ||
2844 | tmr_func = 0; | ||
2845 | break; | ||
2846 | |||
2847 | case QLA_TGT_NEXUS_LOSS_SESS: | ||
2848 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10007, | ||
2849 | "qla_target(%d): Doing NEXUS_LOSS_SESS\n", | ||
2850 | sess->vha->vp_idx); | ||
2851 | tmr_func = 0; | ||
2852 | break; | ||
2853 | |||
2854 | case QLA_TGT_NEXUS_LOSS: | ||
2855 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10008, | ||
2856 | "qla_target(%d): Doing NEXUS_LOSS\n", sess->vha->vp_idx); | ||
2857 | tmr_func = 0; | ||
2858 | break; | ||
2859 | #endif | ||
2860 | default: | ||
2861 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000a, | ||
2862 | "qla_target(%d): Unknown task mgmt fn 0x%x\n", | ||
2863 | sess->vha->vp_idx, fn); | ||
2864 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); | ||
2865 | return -ENOSYS; | ||
2866 | } | ||
2867 | |||
2868 | res = ha->tgt.tgt_ops->handle_tmr(mcmd, lun, tmr_func, 0); | ||
2869 | if (res != 0) { | ||
2870 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000b, | ||
2871 | "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n", | ||
2872 | sess->vha->vp_idx, res); | ||
2873 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); | ||
2874 | return -EFAULT; | ||
2875 | } | ||
2876 | |||
2877 | return 0; | ||
2878 | } | ||
2879 | |||
2880 | /* ha->hardware_lock supposed to be held on entry */ | ||
2881 | static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb) | ||
2882 | { | ||
2883 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; | ||
2884 | struct qla_hw_data *ha = vha->hw; | ||
2885 | struct qla_tgt *tgt; | ||
2886 | struct qla_tgt_sess *sess; | ||
2887 | uint32_t lun, unpacked_lun; | ||
2888 | int lun_size, fn; | ||
2889 | |||
2890 | tgt = ha->tgt.qla_tgt; | ||
2891 | |||
2892 | lun = a->u.isp24.fcp_cmnd.lun; | ||
2893 | lun_size = sizeof(a->u.isp24.fcp_cmnd.lun); | ||
2894 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; | ||
2895 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, | ||
2896 | a->u.isp24.fcp_hdr.s_id); | ||
2897 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); | ||
2898 | |||
2899 | if (!sess) { | ||
2900 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf024, | ||
2901 | "qla_target(%d): task mgmt fn 0x%x for " | ||
2902 | "non-existant session\n", vha->vp_idx, fn); | ||
2903 | return qlt_sched_sess_work(tgt, QLA_TGT_SESS_WORK_TM, iocb, | ||
2904 | sizeof(struct atio_from_isp)); | ||
2905 | } | ||
2906 | |||
2907 | return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); | ||
2908 | } | ||
2909 | |||
2910 | /* ha->hardware_lock supposed to be held on entry */ | ||
2911 | static int __qlt_abort_task(struct scsi_qla_host *vha, | ||
2912 | struct imm_ntfy_from_isp *iocb, struct qla_tgt_sess *sess) | ||
2913 | { | ||
2914 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; | ||
2915 | struct qla_hw_data *ha = vha->hw; | ||
2916 | struct qla_tgt_mgmt_cmd *mcmd; | ||
2917 | uint32_t lun, unpacked_lun; | ||
2918 | int rc; | ||
2919 | |||
2920 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); | ||
2921 | if (mcmd == NULL) { | ||
2922 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f, | ||
2923 | "qla_target(%d): %s: Allocation of ABORT cmd failed\n", | ||
2924 | vha->vp_idx, __func__); | ||
2925 | return -ENOMEM; | ||
2926 | } | ||
2927 | memset(mcmd, 0, sizeof(*mcmd)); | ||
2928 | |||
2929 | mcmd->sess = sess; | ||
2930 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, | ||
2931 | sizeof(mcmd->orig_iocb.imm_ntfy)); | ||
2932 | |||
2933 | lun = a->u.isp24.fcp_cmnd.lun; | ||
2934 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); | ||
2935 | |||
2936 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, unpacked_lun, TMR_ABORT_TASK, | ||
2937 | le16_to_cpu(iocb->u.isp2x.seq_id)); | ||
2938 | if (rc != 0) { | ||
2939 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060, | ||
2940 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", | ||
2941 | vha->vp_idx, rc); | ||
2942 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); | ||
2943 | return -EFAULT; | ||
2944 | } | ||
2945 | |||
2946 | return 0; | ||
2947 | } | ||
2948 | |||
2949 | /* ha->hardware_lock supposed to be held on entry */ | ||
2950 | static int qlt_abort_task(struct scsi_qla_host *vha, | ||
2951 | struct imm_ntfy_from_isp *iocb) | ||
2952 | { | ||
2953 | struct qla_hw_data *ha = vha->hw; | ||
2954 | struct qla_tgt_sess *sess; | ||
2955 | int loop_id; | ||
2956 | |||
2957 | loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb); | ||
2958 | |||
2959 | sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id); | ||
2960 | if (sess == NULL) { | ||
2961 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025, | ||
2962 | "qla_target(%d): task abort for unexisting " | ||
2963 | "session\n", vha->vp_idx); | ||
2964 | return qlt_sched_sess_work(ha->tgt.qla_tgt, | ||
2965 | QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb)); | ||
2966 | } | ||
2967 | |||
2968 | return __qlt_abort_task(vha, iocb, sess); | ||
2969 | } | ||
2970 | |||
2971 | /* | ||
2972 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | ||
2973 | */ | ||
2974 | static int qlt_24xx_handle_els(struct scsi_qla_host *vha, | ||
2975 | struct imm_ntfy_from_isp *iocb) | ||
2976 | { | ||
2977 | struct qla_hw_data *ha = vha->hw; | ||
2978 | int res = 0; | ||
2979 | |||
2980 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf026, | ||
2981 | "qla_target(%d): Port ID: 0x%02x:%02x:%02x" | ||
2982 | " ELS opcode: 0x%02x\n", vha->vp_idx, iocb->u.isp24.port_id[0], | ||
2983 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[2], | ||
2984 | iocb->u.isp24.status_subcode); | ||
2985 | |||
2986 | switch (iocb->u.isp24.status_subcode) { | ||
2987 | case ELS_PLOGI: | ||
2988 | case ELS_FLOGI: | ||
2989 | case ELS_PRLI: | ||
2990 | case ELS_LOGO: | ||
2991 | case ELS_PRLO: | ||
2992 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); | ||
2993 | break; | ||
2994 | case ELS_PDISC: | ||
2995 | case ELS_ADISC: | ||
2996 | { | ||
2997 | struct qla_tgt *tgt = ha->tgt.qla_tgt; | ||
2998 | if (tgt->link_reinit_iocb_pending) { | ||
2999 | qlt_send_notify_ack(vha, &tgt->link_reinit_iocb, | ||
3000 | 0, 0, 0, 0, 0, 0); | ||
3001 | tgt->link_reinit_iocb_pending = 0; | ||
3002 | } | ||
3003 | res = 1; /* send notify ack */ | ||
3004 | break; | ||
3005 | } | ||
3006 | |||
3007 | default: | ||
3008 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061, | ||
3009 | "qla_target(%d): Unsupported ELS command %x " | ||
3010 | "received\n", vha->vp_idx, iocb->u.isp24.status_subcode); | ||
3011 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); | ||
3012 | break; | ||
3013 | } | ||
3014 | |||
3015 | return res; | ||
3016 | } | ||
3017 | |||
3018 | static int qlt_set_data_offset(struct qla_tgt_cmd *cmd, uint32_t offset) | ||
3019 | { | ||
3020 | struct scatterlist *sg, *sgp, *sg_srr, *sg_srr_start = NULL; | ||
3021 | size_t first_offset = 0, rem_offset = offset, tmp = 0; | ||
3022 | int i, sg_srr_cnt, bufflen = 0; | ||
3023 | |||
3024 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe023, | ||
3025 | "Entering qla_tgt_set_data_offset: cmd: %p, cmd->sg: %p, " | ||
3026 | "cmd->sg_cnt: %u, direction: %d\n", | ||
3027 | cmd, cmd->sg, cmd->sg_cnt, cmd->dma_data_direction); | ||
3028 | |||
3029 | /* | ||
3030 | * FIXME: Reject non zero SRR relative offset until we can test | ||
3031 | * this code properly. | ||
3032 | */ | ||
3033 | pr_debug("Rejecting non zero SRR rel_offs: %u\n", offset); | ||
3034 | return -1; | ||
3035 | |||
3036 | if (!cmd->sg || !cmd->sg_cnt) { | ||
3037 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe055, | ||
3038 | "Missing cmd->sg or zero cmd->sg_cnt in" | ||
3039 | " qla_tgt_set_data_offset\n"); | ||
3040 | return -EINVAL; | ||
3041 | } | ||
3042 | /* | ||
3043 | * Walk the current cmd->sg list until we locate the new sg_srr_start | ||
3044 | */ | ||
3045 | for_each_sg(cmd->sg, sg, cmd->sg_cnt, i) { | ||
3046 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe024, | ||
3047 | "sg[%d]: %p page: %p, length: %d, offset: %d\n", | ||
3048 | i, sg, sg_page(sg), sg->length, sg->offset); | ||
3049 | |||
3050 | if ((sg->length + tmp) > offset) { | ||
3051 | first_offset = rem_offset; | ||
3052 | sg_srr_start = sg; | ||
3053 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe025, | ||
3054 | "Found matching sg[%d], using %p as sg_srr_start, " | ||
3055 | "and using first_offset: %zu\n", i, sg, | ||
3056 | first_offset); | ||
3057 | break; | ||
3058 | } | ||
3059 | tmp += sg->length; | ||
3060 | rem_offset -= sg->length; | ||
3061 | } | ||
3062 | |||
3063 | if (!sg_srr_start) { | ||
3064 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe056, | ||
3065 | "Unable to locate sg_srr_start for offset: %u\n", offset); | ||
3066 | return -EINVAL; | ||
3067 | } | ||
3068 | sg_srr_cnt = (cmd->sg_cnt - i); | ||
3069 | |||
3070 | sg_srr = kzalloc(sizeof(struct scatterlist) * sg_srr_cnt, GFP_KERNEL); | ||
3071 | if (!sg_srr) { | ||
3072 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe057, | ||
3073 | "Unable to allocate sgp\n"); | ||
3074 | return -ENOMEM; | ||
3075 | } | ||
3076 | sg_init_table(sg_srr, sg_srr_cnt); | ||
3077 | sgp = &sg_srr[0]; | ||
3078 | /* | ||
3079 | * Walk the remaining list for sg_srr_start, mapping to the newly | ||
3080 | * allocated sg_srr taking first_offset into account. | ||
3081 | */ | ||
3082 | for_each_sg(sg_srr_start, sg, sg_srr_cnt, i) { | ||
3083 | if (first_offset) { | ||
3084 | sg_set_page(sgp, sg_page(sg), | ||
3085 | (sg->length - first_offset), first_offset); | ||
3086 | first_offset = 0; | ||
3087 | } else { | ||
3088 | sg_set_page(sgp, sg_page(sg), sg->length, 0); | ||
3089 | } | ||
3090 | bufflen += sgp->length; | ||
3091 | |||
3092 | sgp = sg_next(sgp); | ||
3093 | if (!sgp) | ||
3094 | break; | ||
3095 | } | ||
3096 | |||
3097 | cmd->sg = sg_srr; | ||
3098 | cmd->sg_cnt = sg_srr_cnt; | ||
3099 | cmd->bufflen = bufflen; | ||
3100 | cmd->offset += offset; | ||
3101 | cmd->free_sg = 1; | ||
3102 | |||
3103 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe026, "New cmd->sg: %p\n", cmd->sg); | ||
3104 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe027, "New cmd->sg_cnt: %u\n", | ||
3105 | cmd->sg_cnt); | ||
3106 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe028, "New cmd->bufflen: %u\n", | ||
3107 | cmd->bufflen); | ||
3108 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe029, "New cmd->offset: %u\n", | ||
3109 | cmd->offset); | ||
3110 | |||
3111 | if (cmd->sg_cnt < 0) | ||
3112 | BUG(); | ||
3113 | |||
3114 | if (cmd->bufflen < 0) | ||
3115 | BUG(); | ||
3116 | |||
3117 | return 0; | ||
3118 | } | ||
3119 | |||
3120 | static inline int qlt_srr_adjust_data(struct qla_tgt_cmd *cmd, | ||
3121 | uint32_t srr_rel_offs, int *xmit_type) | ||
3122 | { | ||
3123 | int res = 0, rel_offs; | ||
3124 | |||
3125 | rel_offs = srr_rel_offs - cmd->offset; | ||
3126 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf027, "srr_rel_offs=%d, rel_offs=%d", | ||
3127 | srr_rel_offs, rel_offs); | ||
3128 | |||
3129 | *xmit_type = QLA_TGT_XMIT_ALL; | ||
3130 | |||
3131 | if (rel_offs < 0) { | ||
3132 | ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf062, | ||
3133 | "qla_target(%d): SRR rel_offs (%d) < 0", | ||
3134 | cmd->vha->vp_idx, rel_offs); | ||
3135 | res = -1; | ||
3136 | } else if (rel_offs == cmd->bufflen) | ||
3137 | *xmit_type = QLA_TGT_XMIT_STATUS; | ||
3138 | else if (rel_offs > 0) | ||
3139 | res = qlt_set_data_offset(cmd, rel_offs); | ||
3140 | |||
3141 | return res; | ||
3142 | } | ||
3143 | |||
3144 | /* No locks, thread context */ | ||
3145 | static void qlt_handle_srr(struct scsi_qla_host *vha, | ||
3146 | struct qla_tgt_srr_ctio *sctio, struct qla_tgt_srr_imm *imm) | ||
3147 | { | ||
3148 | struct imm_ntfy_from_isp *ntfy = | ||
3149 | (struct imm_ntfy_from_isp *)&imm->imm_ntfy; | ||
3150 | struct qla_hw_data *ha = vha->hw; | ||
3151 | struct qla_tgt_cmd *cmd = sctio->cmd; | ||
3152 | struct se_cmd *se_cmd = &cmd->se_cmd; | ||
3153 | unsigned long flags; | ||
3154 | int xmit_type = 0, resp = 0; | ||
3155 | uint32_t offset; | ||
3156 | uint16_t srr_ui; | ||
3157 | |||
3158 | offset = le32_to_cpu(ntfy->u.isp24.srr_rel_offs); | ||
3159 | srr_ui = ntfy->u.isp24.srr_ui; | ||
3160 | |||
3161 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf028, "SRR cmd %p, srr_ui %x\n", | ||
3162 | cmd, srr_ui); | ||
3163 | |||
3164 | switch (srr_ui) { | ||
3165 | case SRR_IU_STATUS: | ||
3166 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
3167 | qlt_send_notify_ack(vha, ntfy, | ||
3168 | 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT, 0, 0); | ||
3169 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
3170 | xmit_type = QLA_TGT_XMIT_STATUS; | ||
3171 | resp = 1; | ||
3172 | break; | ||
3173 | case SRR_IU_DATA_IN: | ||
3174 | if (!cmd->sg || !cmd->sg_cnt) { | ||
3175 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf063, | ||
3176 | "Unable to process SRR_IU_DATA_IN due to" | ||
3177 | " missing cmd->sg, state: %d\n", cmd->state); | ||
3178 | dump_stack(); | ||
3179 | goto out_reject; | ||
3180 | } | ||
3181 | if (se_cmd->scsi_status != 0) { | ||
3182 | ql_dbg(ql_dbg_tgt, vha, 0xe02a, | ||
3183 | "Rejecting SRR_IU_DATA_IN with non GOOD " | ||
3184 | "scsi_status\n"); | ||
3185 | goto out_reject; | ||
3186 | } | ||
3187 | cmd->bufflen = se_cmd->data_length; | ||
3188 | |||
3189 | if (qlt_has_data(cmd)) { | ||
3190 | if (qlt_srr_adjust_data(cmd, offset, &xmit_type) != 0) | ||
3191 | goto out_reject; | ||
3192 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
3193 | qlt_send_notify_ack(vha, ntfy, | ||
3194 | 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT, 0, 0); | ||
3195 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
3196 | resp = 1; | ||
3197 | } else { | ||
3198 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf064, | ||
3199 | "qla_target(%d): SRR for in data for cmd " | ||
3200 | "without them (tag %d, SCSI status %d), " | ||
3201 | "reject", vha->vp_idx, cmd->tag, | ||
3202 | cmd->se_cmd.scsi_status); | ||
3203 | goto out_reject; | ||
3204 | } | ||
3205 | break; | ||
3206 | case SRR_IU_DATA_OUT: | ||
3207 | if (!cmd->sg || !cmd->sg_cnt) { | ||
3208 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf065, | ||
3209 | "Unable to process SRR_IU_DATA_OUT due to" | ||
3210 | " missing cmd->sg\n"); | ||
3211 | dump_stack(); | ||
3212 | goto out_reject; | ||
3213 | } | ||
3214 | if (se_cmd->scsi_status != 0) { | ||
3215 | ql_dbg(ql_dbg_tgt, vha, 0xe02b, | ||
3216 | "Rejecting SRR_IU_DATA_OUT" | ||
3217 | " with non GOOD scsi_status\n"); | ||
3218 | goto out_reject; | ||
3219 | } | ||
3220 | cmd->bufflen = se_cmd->data_length; | ||
3221 | |||
3222 | if (qlt_has_data(cmd)) { | ||
3223 | if (qlt_srr_adjust_data(cmd, offset, &xmit_type) != 0) | ||
3224 | goto out_reject; | ||
3225 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
3226 | qlt_send_notify_ack(vha, ntfy, | ||
3227 | 0, 0, 0, NOTIFY_ACK_SRR_FLAGS_ACCEPT, 0, 0); | ||
3228 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
3229 | if (xmit_type & QLA_TGT_XMIT_DATA) | ||
3230 | qlt_rdy_to_xfer(cmd); | ||
3231 | } else { | ||
3232 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf066, | ||
3233 | "qla_target(%d): SRR for out data for cmd " | ||
3234 | "without them (tag %d, SCSI status %d), " | ||
3235 | "reject", vha->vp_idx, cmd->tag, | ||
3236 | cmd->se_cmd.scsi_status); | ||
3237 | goto out_reject; | ||
3238 | } | ||
3239 | break; | ||
3240 | default: | ||
3241 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf067, | ||
3242 | "qla_target(%d): Unknown srr_ui value %x", | ||
3243 | vha->vp_idx, srr_ui); | ||
3244 | goto out_reject; | ||
3245 | } | ||
3246 | |||
3247 | /* Transmit response in case of status and data-in cases */ | ||
3248 | if (resp) | ||
3249 | qlt_xmit_response(cmd, xmit_type, se_cmd->scsi_status); | ||
3250 | |||
3251 | return; | ||
3252 | |||
3253 | out_reject: | ||
3254 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
3255 | qlt_send_notify_ack(vha, ntfy, 0, 0, 0, | ||
3256 | NOTIFY_ACK_SRR_FLAGS_REJECT, | ||
3257 | NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM, | ||
3258 | NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL); | ||
3259 | if (cmd->state == QLA_TGT_STATE_NEED_DATA) { | ||
3260 | cmd->state = QLA_TGT_STATE_DATA_IN; | ||
3261 | dump_stack(); | ||
3262 | } else | ||
3263 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 1); | ||
3264 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
3265 | } | ||
3266 | |||
3267 | static void qlt_reject_free_srr_imm(struct scsi_qla_host *vha, | ||
3268 | struct qla_tgt_srr_imm *imm, int ha_locked) | ||
3269 | { | ||
3270 | struct qla_hw_data *ha = vha->hw; | ||
3271 | unsigned long flags = 0; | ||
3272 | |||
3273 | if (!ha_locked) | ||
3274 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
3275 | |||
3276 | qlt_send_notify_ack(vha, (void *)&imm->imm_ntfy, 0, 0, 0, | ||
3277 | NOTIFY_ACK_SRR_FLAGS_REJECT, | ||
3278 | NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM, | ||
3279 | NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL); | ||
3280 | |||
3281 | if (!ha_locked) | ||
3282 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
3283 | |||
3284 | kfree(imm); | ||
3285 | } | ||
3286 | |||
3287 | static void qlt_handle_srr_work(struct work_struct *work) | ||
3288 | { | ||
3289 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, srr_work); | ||
3290 | struct scsi_qla_host *vha = tgt->vha; | ||
3291 | struct qla_tgt_srr_ctio *sctio; | ||
3292 | unsigned long flags; | ||
3293 | |||
3294 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf029, "Entering SRR work (tgt %p)\n", | ||
3295 | tgt); | ||
3296 | |||
3297 | restart: | ||
3298 | spin_lock_irqsave(&tgt->srr_lock, flags); | ||
3299 | list_for_each_entry(sctio, &tgt->srr_ctio_list, srr_list_entry) { | ||
3300 | struct qla_tgt_srr_imm *imm, *i, *ti; | ||
3301 | struct qla_tgt_cmd *cmd; | ||
3302 | struct se_cmd *se_cmd; | ||
3303 | |||
3304 | imm = NULL; | ||
3305 | list_for_each_entry_safe(i, ti, &tgt->srr_imm_list, | ||
3306 | srr_list_entry) { | ||
3307 | if (i->srr_id == sctio->srr_id) { | ||
3308 | list_del(&i->srr_list_entry); | ||
3309 | if (imm) { | ||
3310 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf068, | ||
3311 | "qla_target(%d): There must be " | ||
3312 | "only one IMM SRR per CTIO SRR " | ||
3313 | "(IMM SRR %p, id %d, CTIO %p\n", | ||
3314 | vha->vp_idx, i, i->srr_id, sctio); | ||
3315 | qlt_reject_free_srr_imm(tgt->vha, i, 0); | ||
3316 | } else | ||
3317 | imm = i; | ||
3318 | } | ||
3319 | } | ||
3320 | |||
3321 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02a, | ||
3322 | "IMM SRR %p, CTIO SRR %p (id %d)\n", imm, sctio, | ||
3323 | sctio->srr_id); | ||
3324 | |||
3325 | if (imm == NULL) { | ||
3326 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02b, | ||
3327 | "Not found matching IMM for SRR CTIO (id %d)\n", | ||
3328 | sctio->srr_id); | ||
3329 | continue; | ||
3330 | } else | ||
3331 | list_del(&sctio->srr_list_entry); | ||
3332 | |||
3333 | spin_unlock_irqrestore(&tgt->srr_lock, flags); | ||
3334 | |||
3335 | cmd = sctio->cmd; | ||
3336 | /* | ||
3337 | * Reset qla_tgt_cmd SRR values and SGL pointer+count to follow | ||
3338 | * tcm_qla2xxx_write_pending() and tcm_qla2xxx_queue_data_in() | ||
3339 | * logic.. | ||
3340 | */ | ||
3341 | cmd->offset = 0; | ||
3342 | if (cmd->free_sg) { | ||
3343 | kfree(cmd->sg); | ||
3344 | cmd->sg = NULL; | ||
3345 | cmd->free_sg = 0; | ||
3346 | } | ||
3347 | se_cmd = &cmd->se_cmd; | ||
3348 | |||
3349 | cmd->sg_cnt = se_cmd->t_data_nents; | ||
3350 | cmd->sg = se_cmd->t_data_sg; | ||
3351 | |||
3352 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02c, | ||
3353 | "SRR cmd %p (se_cmd %p, tag %d, op %x), " | ||
3354 | "sg_cnt=%d, offset=%d", cmd, &cmd->se_cmd, cmd->tag, | ||
3355 | se_cmd->t_task_cdb[0], cmd->sg_cnt, cmd->offset); | ||
3356 | |||
3357 | qlt_handle_srr(vha, sctio, imm); | ||
3358 | |||
3359 | kfree(imm); | ||
3360 | kfree(sctio); | ||
3361 | goto restart; | ||
3362 | } | ||
3363 | spin_unlock_irqrestore(&tgt->srr_lock, flags); | ||
3364 | } | ||
3365 | |||
3366 | /* ha->hardware_lock supposed to be held on entry */ | ||
3367 | static void qlt_prepare_srr_imm(struct scsi_qla_host *vha, | ||
3368 | struct imm_ntfy_from_isp *iocb) | ||
3369 | { | ||
3370 | struct qla_tgt_srr_imm *imm; | ||
3371 | struct qla_hw_data *ha = vha->hw; | ||
3372 | struct qla_tgt *tgt = ha->tgt.qla_tgt; | ||
3373 | struct qla_tgt_srr_ctio *sctio; | ||
3374 | |||
3375 | tgt->imm_srr_id++; | ||
3376 | |||
3377 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02d, "qla_target(%d): SRR received\n", | ||
3378 | vha->vp_idx); | ||
3379 | |||
3380 | imm = kzalloc(sizeof(*imm), GFP_ATOMIC); | ||
3381 | if (imm != NULL) { | ||
3382 | memcpy(&imm->imm_ntfy, iocb, sizeof(imm->imm_ntfy)); | ||
3383 | |||
3384 | /* IRQ is already OFF */ | ||
3385 | spin_lock(&tgt->srr_lock); | ||
3386 | imm->srr_id = tgt->imm_srr_id; | ||
3387 | list_add_tail(&imm->srr_list_entry, | ||
3388 | &tgt->srr_imm_list); | ||
3389 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02e, | ||
3390 | "IMM NTFY SRR %p added (id %d, ui %x)\n", | ||
3391 | imm, imm->srr_id, iocb->u.isp24.srr_ui); | ||
3392 | if (tgt->imm_srr_id == tgt->ctio_srr_id) { | ||
3393 | int found = 0; | ||
3394 | list_for_each_entry(sctio, &tgt->srr_ctio_list, | ||
3395 | srr_list_entry) { | ||
3396 | if (sctio->srr_id == imm->srr_id) { | ||
3397 | found = 1; | ||
3398 | break; | ||
3399 | } | ||
3400 | } | ||
3401 | if (found) { | ||
3402 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02f, "%s", | ||
3403 | "Scheduling srr work\n"); | ||
3404 | schedule_work(&tgt->srr_work); | ||
3405 | } else { | ||
3406 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf030, | ||
3407 | "qla_target(%d): imm_srr_id " | ||
3408 | "== ctio_srr_id (%d), but there is no " | ||
3409 | "corresponding SRR CTIO, deleting IMM " | ||
3410 | "SRR %p\n", vha->vp_idx, tgt->ctio_srr_id, | ||
3411 | imm); | ||
3412 | list_del(&imm->srr_list_entry); | ||
3413 | |||
3414 | kfree(imm); | ||
3415 | |||
3416 | spin_unlock(&tgt->srr_lock); | ||
3417 | goto out_reject; | ||
3418 | } | ||
3419 | } | ||
3420 | spin_unlock(&tgt->srr_lock); | ||
3421 | } else { | ||
3422 | struct qla_tgt_srr_ctio *ts; | ||
3423 | |||
3424 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf069, | ||
3425 | "qla_target(%d): Unable to allocate SRR IMM " | ||
3426 | "entry, SRR request will be rejected\n", vha->vp_idx); | ||
3427 | |||
3428 | /* IRQ is already OFF */ | ||
3429 | spin_lock(&tgt->srr_lock); | ||
3430 | list_for_each_entry_safe(sctio, ts, &tgt->srr_ctio_list, | ||
3431 | srr_list_entry) { | ||
3432 | if (sctio->srr_id == tgt->imm_srr_id) { | ||
3433 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf031, | ||
3434 | "CTIO SRR %p deleted (id %d)\n", | ||
3435 | sctio, sctio->srr_id); | ||
3436 | list_del(&sctio->srr_list_entry); | ||
3437 | qlt_send_term_exchange(vha, sctio->cmd, | ||
3438 | &sctio->cmd->atio, 1); | ||
3439 | kfree(sctio); | ||
3440 | } | ||
3441 | } | ||
3442 | spin_unlock(&tgt->srr_lock); | ||
3443 | goto out_reject; | ||
3444 | } | ||
3445 | |||
3446 | return; | ||
3447 | |||
3448 | out_reject: | ||
3449 | qlt_send_notify_ack(vha, iocb, 0, 0, 0, | ||
3450 | NOTIFY_ACK_SRR_FLAGS_REJECT, | ||
3451 | NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM, | ||
3452 | NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL); | ||
3453 | } | ||
3454 | |||
3455 | /* | ||
3456 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | ||
3457 | */ | ||
3458 | static void qlt_handle_imm_notify(struct scsi_qla_host *vha, | ||
3459 | struct imm_ntfy_from_isp *iocb) | ||
3460 | { | ||
3461 | struct qla_hw_data *ha = vha->hw; | ||
3462 | uint32_t add_flags = 0; | ||
3463 | int send_notify_ack = 1; | ||
3464 | uint16_t status; | ||
3465 | |||
3466 | status = le16_to_cpu(iocb->u.isp2x.status); | ||
3467 | switch (status) { | ||
3468 | case IMM_NTFY_LIP_RESET: | ||
3469 | { | ||
3470 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032, | ||
3471 | "qla_target(%d): LIP reset (loop %#x), subcode %x\n", | ||
3472 | vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle), | ||
3473 | iocb->u.isp24.status_subcode); | ||
3474 | |||
3475 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) | ||
3476 | send_notify_ack = 0; | ||
3477 | break; | ||
3478 | } | ||
3479 | |||
3480 | case IMM_NTFY_LIP_LINK_REINIT: | ||
3481 | { | ||
3482 | struct qla_tgt *tgt = ha->tgt.qla_tgt; | ||
3483 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033, | ||
3484 | "qla_target(%d): LINK REINIT (loop %#x, " | ||
3485 | "subcode %x)\n", vha->vp_idx, | ||
3486 | le16_to_cpu(iocb->u.isp24.nport_handle), | ||
3487 | iocb->u.isp24.status_subcode); | ||
3488 | if (tgt->link_reinit_iocb_pending) { | ||
3489 | qlt_send_notify_ack(vha, &tgt->link_reinit_iocb, | ||
3490 | 0, 0, 0, 0, 0, 0); | ||
3491 | } | ||
3492 | memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb)); | ||
3493 | tgt->link_reinit_iocb_pending = 1; | ||
3494 | /* | ||
3495 | * QLogic requires to wait after LINK REINIT for possible | ||
3496 | * PDISC or ADISC ELS commands | ||
3497 | */ | ||
3498 | send_notify_ack = 0; | ||
3499 | break; | ||
3500 | } | ||
3501 | |||
3502 | case IMM_NTFY_PORT_LOGOUT: | ||
3503 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034, | ||
3504 | "qla_target(%d): Port logout (loop " | ||
3505 | "%#x, subcode %x)\n", vha->vp_idx, | ||
3506 | le16_to_cpu(iocb->u.isp24.nport_handle), | ||
3507 | iocb->u.isp24.status_subcode); | ||
3508 | |||
3509 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0) | ||
3510 | send_notify_ack = 0; | ||
3511 | /* The sessions will be cleared in the callback, if needed */ | ||
3512 | break; | ||
3513 | |||
3514 | case IMM_NTFY_GLBL_TPRLO: | ||
3515 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035, | ||
3516 | "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status); | ||
3517 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) | ||
3518 | send_notify_ack = 0; | ||
3519 | /* The sessions will be cleared in the callback, if needed */ | ||
3520 | break; | ||
3521 | |||
3522 | case IMM_NTFY_PORT_CONFIG: | ||
3523 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036, | ||
3524 | "qla_target(%d): Port config changed (%x)\n", vha->vp_idx, | ||
3525 | status); | ||
3526 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) | ||
3527 | send_notify_ack = 0; | ||
3528 | /* The sessions will be cleared in the callback, if needed */ | ||
3529 | break; | ||
3530 | |||
3531 | case IMM_NTFY_GLBL_LOGO: | ||
3532 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a, | ||
3533 | "qla_target(%d): Link failure detected\n", | ||
3534 | vha->vp_idx); | ||
3535 | /* I_T nexus loss */ | ||
3536 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) | ||
3537 | send_notify_ack = 0; | ||
3538 | break; | ||
3539 | |||
3540 | case IMM_NTFY_IOCB_OVERFLOW: | ||
3541 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b, | ||
3542 | "qla_target(%d): Cannot provide requested " | ||
3543 | "capability (IOCB overflowed the immediate notify " | ||
3544 | "resource count)\n", vha->vp_idx); | ||
3545 | break; | ||
3546 | |||
3547 | case IMM_NTFY_ABORT_TASK: | ||
3548 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037, | ||
3549 | "qla_target(%d): Abort Task (S %08x I %#x -> " | ||
3550 | "L %#x)\n", vha->vp_idx, | ||
3551 | le16_to_cpu(iocb->u.isp2x.seq_id), | ||
3552 | GET_TARGET_ID(ha, (struct atio_from_isp *)iocb), | ||
3553 | le16_to_cpu(iocb->u.isp2x.lun)); | ||
3554 | if (qlt_abort_task(vha, iocb) == 0) | ||
3555 | send_notify_ack = 0; | ||
3556 | break; | ||
3557 | |||
3558 | case IMM_NTFY_RESOURCE: | ||
3559 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c, | ||
3560 | "qla_target(%d): Out of resources, host %ld\n", | ||
3561 | vha->vp_idx, vha->host_no); | ||
3562 | break; | ||
3563 | |||
3564 | case IMM_NTFY_MSG_RX: | ||
3565 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038, | ||
3566 | "qla_target(%d): Immediate notify task %x\n", | ||
3567 | vha->vp_idx, iocb->u.isp2x.task_flags); | ||
3568 | if (qlt_handle_task_mgmt(vha, iocb) == 0) | ||
3569 | send_notify_ack = 0; | ||
3570 | break; | ||
3571 | |||
3572 | case IMM_NTFY_ELS: | ||
3573 | if (qlt_24xx_handle_els(vha, iocb) == 0) | ||
3574 | send_notify_ack = 0; | ||
3575 | break; | ||
3576 | |||
3577 | case IMM_NTFY_SRR: | ||
3578 | qlt_prepare_srr_imm(vha, iocb); | ||
3579 | send_notify_ack = 0; | ||
3580 | break; | ||
3581 | |||
3582 | default: | ||
3583 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d, | ||
3584 | "qla_target(%d): Received unknown immediate " | ||
3585 | "notify status %x\n", vha->vp_idx, status); | ||
3586 | break; | ||
3587 | } | ||
3588 | |||
3589 | if (send_notify_ack) | ||
3590 | qlt_send_notify_ack(vha, iocb, add_flags, 0, 0, 0, 0, 0); | ||
3591 | } | ||
3592 | |||
3593 | /* | ||
3594 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | ||
3595 | * This function sends busy to ISP 2xxx or 24xx. | ||
3596 | */ | ||
3597 | static void qlt_send_busy(struct scsi_qla_host *vha, | ||
3598 | struct atio_from_isp *atio, uint16_t status) | ||
3599 | { | ||
3600 | struct ctio7_to_24xx *ctio24; | ||
3601 | struct qla_hw_data *ha = vha->hw; | ||
3602 | request_t *pkt; | ||
3603 | struct qla_tgt_sess *sess = NULL; | ||
3604 | |||
3605 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, | ||
3606 | atio->u.isp24.fcp_hdr.s_id); | ||
3607 | if (!sess) { | ||
3608 | qlt_send_term_exchange(vha, NULL, atio, 1); | ||
3609 | return; | ||
3610 | } | ||
3611 | /* Sending marker isn't necessary, since we called from ISR */ | ||
3612 | |||
3613 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); | ||
3614 | if (!pkt) { | ||
3615 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06e, | ||
3616 | "qla_target(%d): %s failed: unable to allocate " | ||
3617 | "request packet", vha->vp_idx, __func__); | ||
3618 | return; | ||
3619 | } | ||
3620 | |||
3621 | pkt->entry_count = 1; | ||
3622 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; | ||
3623 | |||
3624 | ctio24 = (struct ctio7_to_24xx *)pkt; | ||
3625 | ctio24->entry_type = CTIO_TYPE7; | ||
3626 | ctio24->nport_handle = sess->loop_id; | ||
3627 | ctio24->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT); | ||
3628 | ctio24->vp_index = vha->vp_idx; | ||
3629 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; | ||
3630 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; | ||
3631 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; | ||
3632 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; | ||
3633 | ctio24->u.status1.flags = (atio->u.isp24.attr << 9) | | ||
3634 | __constant_cpu_to_le16( | ||
3635 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS | | ||
3636 | CTIO7_FLAGS_DONT_RET_CTIO); | ||
3637 | /* | ||
3638 | * CTIO from fw w/o se_cmd doesn't provide enough info to retry it, | ||
3639 | * if the explicit conformation is used. | ||
3640 | */ | ||
3641 | ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); | ||
3642 | ctio24->u.status1.scsi_status = cpu_to_le16(status); | ||
3643 | ctio24->u.status1.residual = get_unaligned((uint32_t *) | ||
3644 | &atio->u.isp24.fcp_cmnd.add_cdb[ | ||
3645 | atio->u.isp24.fcp_cmnd.add_cdb_len]); | ||
3646 | if (ctio24->u.status1.residual != 0) | ||
3647 | ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER; | ||
3648 | |||
3649 | qla2x00_start_iocbs(vha, vha->req); | ||
3650 | } | ||
3651 | |||
3652 | /* ha->hardware_lock supposed to be held on entry */ | ||
3653 | /* called via callback from qla2xxx */ | ||
3654 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha, | ||
3655 | struct atio_from_isp *atio) | ||
3656 | { | ||
3657 | struct qla_hw_data *ha = vha->hw; | ||
3658 | struct qla_tgt *tgt = ha->tgt.qla_tgt; | ||
3659 | int rc; | ||
3660 | |||
3661 | if (unlikely(tgt == NULL)) { | ||
3662 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf039, | ||
3663 | "ATIO pkt, but no tgt (ha %p)", ha); | ||
3664 | return; | ||
3665 | } | ||
3666 | ql_dbg(ql_dbg_tgt, vha, 0xe02c, | ||
3667 | "qla_target(%d): ATIO pkt %p: type %02x count %02x", | ||
3668 | vha->vp_idx, atio, atio->u.raw.entry_type, | ||
3669 | atio->u.raw.entry_count); | ||
3670 | /* | ||
3671 | * In tgt_stop mode we also should allow all requests to pass. | ||
3672 | * Otherwise, some commands can stuck. | ||
3673 | */ | ||
3674 | |||
3675 | tgt->irq_cmd_count++; | ||
3676 | |||
3677 | switch (atio->u.raw.entry_type) { | ||
3678 | case ATIO_TYPE7: | ||
3679 | ql_dbg(ql_dbg_tgt, vha, 0xe02d, | ||
3680 | "ATIO_TYPE7 instance %d, lun %Lx, read/write %d/%d, " | ||
3681 | "add_cdb_len %d, data_length %04x, s_id %x:%x:%x\n", | ||
3682 | vha->vp_idx, atio->u.isp24.fcp_cmnd.lun, | ||
3683 | atio->u.isp24.fcp_cmnd.rddata, | ||
3684 | atio->u.isp24.fcp_cmnd.wrdata, | ||
3685 | atio->u.isp24.fcp_cmnd.add_cdb_len, | ||
3686 | be32_to_cpu(get_unaligned((uint32_t *) | ||
3687 | &atio->u.isp24.fcp_cmnd.add_cdb[ | ||
3688 | atio->u.isp24.fcp_cmnd.add_cdb_len])), | ||
3689 | atio->u.isp24.fcp_hdr.s_id[0], | ||
3690 | atio->u.isp24.fcp_hdr.s_id[1], | ||
3691 | atio->u.isp24.fcp_hdr.s_id[2]); | ||
3692 | |||
3693 | if (unlikely(atio->u.isp24.exchange_addr == | ||
3694 | ATIO_EXCHANGE_ADDRESS_UNKNOWN)) { | ||
3695 | ql_dbg(ql_dbg_tgt, vha, 0xe058, | ||
3696 | "qla_target(%d): ATIO_TYPE7 " | ||
3697 | "received with UNKNOWN exchange address, " | ||
3698 | "sending QUEUE_FULL\n", vha->vp_idx); | ||
3699 | qlt_send_busy(vha, atio, SAM_STAT_TASK_SET_FULL); | ||
3700 | break; | ||
3701 | } | ||
3702 | if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) | ||
3703 | rc = qlt_handle_cmd_for_atio(vha, atio); | ||
3704 | else | ||
3705 | rc = qlt_handle_task_mgmt(vha, atio); | ||
3706 | if (unlikely(rc != 0)) { | ||
3707 | if (rc == -ESRCH) { | ||
3708 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ | ||
3709 | qlt_send_busy(vha, atio, SAM_STAT_BUSY); | ||
3710 | #else | ||
3711 | qlt_send_term_exchange(vha, NULL, atio, 1); | ||
3712 | #endif | ||
3713 | } else { | ||
3714 | if (tgt->tgt_stop) { | ||
3715 | ql_dbg(ql_dbg_tgt, vha, 0xe059, | ||
3716 | "qla_target: Unable to send " | ||
3717 | "command to target for req, " | ||
3718 | "ignoring.\n"); | ||
3719 | } else { | ||
3720 | ql_dbg(ql_dbg_tgt, vha, 0xe05a, | ||
3721 | "qla_target(%d): Unable to send " | ||
3722 | "command to target, sending BUSY " | ||
3723 | "status.\n", vha->vp_idx); | ||
3724 | qlt_send_busy(vha, atio, SAM_STAT_BUSY); | ||
3725 | } | ||
3726 | } | ||
3727 | } | ||
3728 | break; | ||
3729 | |||
3730 | case IMMED_NOTIFY_TYPE: | ||
3731 | { | ||
3732 | if (unlikely(atio->u.isp2x.entry_status != 0)) { | ||
3733 | ql_dbg(ql_dbg_tgt, vha, 0xe05b, | ||
3734 | "qla_target(%d): Received ATIO packet %x " | ||
3735 | "with error status %x\n", vha->vp_idx, | ||
3736 | atio->u.raw.entry_type, | ||
3737 | atio->u.isp2x.entry_status); | ||
3738 | break; | ||
3739 | } | ||
3740 | ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO"); | ||
3741 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio); | ||
3742 | break; | ||
3743 | } | ||
3744 | |||
3745 | default: | ||
3746 | ql_dbg(ql_dbg_tgt, vha, 0xe05c, | ||
3747 | "qla_target(%d): Received unknown ATIO atio " | ||
3748 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); | ||
3749 | break; | ||
3750 | } | ||
3751 | |||
3752 | tgt->irq_cmd_count--; | ||
3753 | } | ||
3754 | |||
3755 | /* ha->hardware_lock supposed to be held on entry */ | ||
3756 | /* called via callback from qla2xxx */ | ||
3757 | static void qlt_response_pkt(struct scsi_qla_host *vha, response_t *pkt) | ||
3758 | { | ||
3759 | struct qla_hw_data *ha = vha->hw; | ||
3760 | struct qla_tgt *tgt = ha->tgt.qla_tgt; | ||
3761 | |||
3762 | if (unlikely(tgt == NULL)) { | ||
3763 | ql_dbg(ql_dbg_tgt, vha, 0xe05d, | ||
3764 | "qla_target(%d): Response pkt %x received, but no " | ||
3765 | "tgt (ha %p)\n", vha->vp_idx, pkt->entry_type, ha); | ||
3766 | return; | ||
3767 | } | ||
3768 | |||
3769 | ql_dbg(ql_dbg_tgt, vha, 0xe02f, | ||
3770 | "qla_target(%d): response pkt %p: T %02x C %02x S %02x " | ||
3771 | "handle %#x\n", vha->vp_idx, pkt, pkt->entry_type, | ||
3772 | pkt->entry_count, pkt->entry_status, pkt->handle); | ||
3773 | |||
3774 | /* | ||
3775 | * In tgt_stop mode we also should allow all requests to pass. | ||
3776 | * Otherwise, some commands can stuck. | ||
3777 | */ | ||
3778 | |||
3779 | tgt->irq_cmd_count++; | ||
3780 | |||
3781 | switch (pkt->entry_type) { | ||
3782 | case CTIO_TYPE7: | ||
3783 | { | ||
3784 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; | ||
3785 | ql_dbg(ql_dbg_tgt, vha, 0xe030, "CTIO_TYPE7: instance %d\n", | ||
3786 | vha->vp_idx); | ||
3787 | qlt_do_ctio_completion(vha, entry->handle, | ||
3788 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), | ||
3789 | entry); | ||
3790 | break; | ||
3791 | } | ||
3792 | |||
3793 | case ACCEPT_TGT_IO_TYPE: | ||
3794 | { | ||
3795 | struct atio_from_isp *atio = (struct atio_from_isp *)pkt; | ||
3796 | int rc; | ||
3797 | ql_dbg(ql_dbg_tgt, vha, 0xe031, | ||
3798 | "ACCEPT_TGT_IO instance %d status %04x " | ||
3799 | "lun %04x read/write %d data_length %04x " | ||
3800 | "target_id %02x rx_id %04x\n ", vha->vp_idx, | ||
3801 | le16_to_cpu(atio->u.isp2x.status), | ||
3802 | le16_to_cpu(atio->u.isp2x.lun), | ||
3803 | atio->u.isp2x.execution_codes, | ||
3804 | le32_to_cpu(atio->u.isp2x.data_length), GET_TARGET_ID(ha, | ||
3805 | atio), atio->u.isp2x.rx_id); | ||
3806 | if (atio->u.isp2x.status != | ||
3807 | __constant_cpu_to_le16(ATIO_CDB_VALID)) { | ||
3808 | ql_dbg(ql_dbg_tgt, vha, 0xe05e, | ||
3809 | "qla_target(%d): ATIO with error " | ||
3810 | "status %x received\n", vha->vp_idx, | ||
3811 | le16_to_cpu(atio->u.isp2x.status)); | ||
3812 | break; | ||
3813 | } | ||
3814 | ql_dbg(ql_dbg_tgt, vha, 0xe032, | ||
3815 | "FCP CDB: 0x%02x, sizeof(cdb): %lu", | ||
3816 | atio->u.isp2x.cdb[0], (unsigned long | ||
3817 | int)sizeof(atio->u.isp2x.cdb)); | ||
3818 | |||
3819 | rc = qlt_handle_cmd_for_atio(vha, atio); | ||
3820 | if (unlikely(rc != 0)) { | ||
3821 | if (rc == -ESRCH) { | ||
3822 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ | ||
3823 | qlt_send_busy(vha, atio, 0); | ||
3824 | #else | ||
3825 | qlt_send_term_exchange(vha, NULL, atio, 1); | ||
3826 | #endif | ||
3827 | } else { | ||
3828 | if (tgt->tgt_stop) { | ||
3829 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, | ||
3830 | "qla_target: Unable to send " | ||
3831 | "command to target, sending TERM " | ||
3832 | "EXCHANGE for rsp\n"); | ||
3833 | qlt_send_term_exchange(vha, NULL, | ||
3834 | atio, 1); | ||
3835 | } else { | ||
3836 | ql_dbg(ql_dbg_tgt, vha, 0xe060, | ||
3837 | "qla_target(%d): Unable to send " | ||
3838 | "command to target, sending BUSY " | ||
3839 | "status\n", vha->vp_idx); | ||
3840 | qlt_send_busy(vha, atio, 0); | ||
3841 | } | ||
3842 | } | ||
3843 | } | ||
3844 | } | ||
3845 | break; | ||
3846 | |||
3847 | case CONTINUE_TGT_IO_TYPE: | ||
3848 | { | ||
3849 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; | ||
3850 | ql_dbg(ql_dbg_tgt, vha, 0xe033, | ||
3851 | "CONTINUE_TGT_IO: instance %d\n", vha->vp_idx); | ||
3852 | qlt_do_ctio_completion(vha, entry->handle, | ||
3853 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), | ||
3854 | entry); | ||
3855 | break; | ||
3856 | } | ||
3857 | |||
3858 | case CTIO_A64_TYPE: | ||
3859 | { | ||
3860 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; | ||
3861 | ql_dbg(ql_dbg_tgt, vha, 0xe034, "CTIO_A64: instance %d\n", | ||
3862 | vha->vp_idx); | ||
3863 | qlt_do_ctio_completion(vha, entry->handle, | ||
3864 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), | ||
3865 | entry); | ||
3866 | break; | ||
3867 | } | ||
3868 | |||
3869 | case IMMED_NOTIFY_TYPE: | ||
3870 | ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n"); | ||
3871 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt); | ||
3872 | break; | ||
3873 | |||
3874 | case NOTIFY_ACK_TYPE: | ||
3875 | if (tgt->notify_ack_expected > 0) { | ||
3876 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; | ||
3877 | ql_dbg(ql_dbg_tgt, vha, 0xe036, | ||
3878 | "NOTIFY_ACK seq %08x status %x\n", | ||
3879 | le16_to_cpu(entry->u.isp2x.seq_id), | ||
3880 | le16_to_cpu(entry->u.isp2x.status)); | ||
3881 | tgt->notify_ack_expected--; | ||
3882 | if (entry->u.isp2x.status != | ||
3883 | __constant_cpu_to_le16(NOTIFY_ACK_SUCCESS)) { | ||
3884 | ql_dbg(ql_dbg_tgt, vha, 0xe061, | ||
3885 | "qla_target(%d): NOTIFY_ACK " | ||
3886 | "failed %x\n", vha->vp_idx, | ||
3887 | le16_to_cpu(entry->u.isp2x.status)); | ||
3888 | } | ||
3889 | } else { | ||
3890 | ql_dbg(ql_dbg_tgt, vha, 0xe062, | ||
3891 | "qla_target(%d): Unexpected NOTIFY_ACK received\n", | ||
3892 | vha->vp_idx); | ||
3893 | } | ||
3894 | break; | ||
3895 | |||
3896 | case ABTS_RECV_24XX: | ||
3897 | ql_dbg(ql_dbg_tgt, vha, 0xe037, | ||
3898 | "ABTS_RECV_24XX: instance %d\n", vha->vp_idx); | ||
3899 | qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt); | ||
3900 | break; | ||
3901 | |||
3902 | case ABTS_RESP_24XX: | ||
3903 | if (tgt->abts_resp_expected > 0) { | ||
3904 | struct abts_resp_from_24xx_fw *entry = | ||
3905 | (struct abts_resp_from_24xx_fw *)pkt; | ||
3906 | ql_dbg(ql_dbg_tgt, vha, 0xe038, | ||
3907 | "ABTS_RESP_24XX: compl_status %x\n", | ||
3908 | entry->compl_status); | ||
3909 | tgt->abts_resp_expected--; | ||
3910 | if (le16_to_cpu(entry->compl_status) != | ||
3911 | ABTS_RESP_COMPL_SUCCESS) { | ||
3912 | if ((entry->error_subcode1 == 0x1E) && | ||
3913 | (entry->error_subcode2 == 0)) { | ||
3914 | /* | ||
3915 | * We've got a race here: aborted | ||
3916 | * exchange not terminated, i.e. | ||
3917 | * response for the aborted command was | ||
3918 | * sent between the abort request was | ||
3919 | * received and processed. | ||
3920 | * Unfortunately, the firmware has a | ||
3921 | * silly requirement that all aborted | ||
3922 | * exchanges must be explicitely | ||
3923 | * terminated, otherwise it refuses to | ||
3924 | * send responses for the abort | ||
3925 | * requests. So, we have to | ||
3926 | * (re)terminate the exchange and retry | ||
3927 | * the abort response. | ||
3928 | */ | ||
3929 | qlt_24xx_retry_term_exchange(vha, | ||
3930 | entry); | ||
3931 | } else | ||
3932 | ql_dbg(ql_dbg_tgt, vha, 0xe063, | ||
3933 | "qla_target(%d): ABTS_RESP_24XX " | ||
3934 | "failed %x (subcode %x:%x)", | ||
3935 | vha->vp_idx, entry->compl_status, | ||
3936 | entry->error_subcode1, | ||
3937 | entry->error_subcode2); | ||
3938 | } | ||
3939 | } else { | ||
3940 | ql_dbg(ql_dbg_tgt, vha, 0xe064, | ||
3941 | "qla_target(%d): Unexpected ABTS_RESP_24XX " | ||
3942 | "received\n", vha->vp_idx); | ||
3943 | } | ||
3944 | break; | ||
3945 | |||
3946 | default: | ||
3947 | ql_dbg(ql_dbg_tgt, vha, 0xe065, | ||
3948 | "qla_target(%d): Received unknown response pkt " | ||
3949 | "type %x\n", vha->vp_idx, pkt->entry_type); | ||
3950 | break; | ||
3951 | } | ||
3952 | |||
3953 | tgt->irq_cmd_count--; | ||
3954 | } | ||
3955 | |||
3956 | /* | ||
3957 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire | ||
3958 | */ | ||
3959 | void qlt_async_event(uint16_t code, struct scsi_qla_host *vha, | ||
3960 | uint16_t *mailbox) | ||
3961 | { | ||
3962 | struct qla_hw_data *ha = vha->hw; | ||
3963 | struct qla_tgt *tgt = ha->tgt.qla_tgt; | ||
3964 | int reason_code; | ||
3965 | |||
3966 | ql_dbg(ql_dbg_tgt, vha, 0xe039, | ||
3967 | "scsi(%ld): ha state %d init_done %d oper_mode %d topo %d\n", | ||
3968 | vha->host_no, atomic_read(&vha->loop_state), vha->flags.init_done, | ||
3969 | ha->operating_mode, ha->current_topology); | ||
3970 | |||
3971 | if (!ha->tgt.tgt_ops) | ||
3972 | return; | ||
3973 | |||
3974 | if (unlikely(tgt == NULL)) { | ||
3975 | ql_dbg(ql_dbg_tgt, vha, 0xe03a, | ||
3976 | "ASYNC EVENT %#x, but no tgt (ha %p)\n", code, ha); | ||
3977 | return; | ||
3978 | } | ||
3979 | |||
3980 | if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) && | ||
3981 | IS_QLA2100(ha)) | ||
3982 | return; | ||
3983 | /* | ||
3984 | * In tgt_stop mode we also should allow all requests to pass. | ||
3985 | * Otherwise, some commands can stuck. | ||
3986 | */ | ||
3987 | |||
3988 | tgt->irq_cmd_count++; | ||
3989 | |||
3990 | switch (code) { | ||
3991 | case MBA_RESET: /* Reset */ | ||
3992 | case MBA_SYSTEM_ERR: /* System Error */ | ||
3993 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ | ||
3994 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ | ||
3995 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a, | ||
3996 | "qla_target(%d): System error async event %#x " | ||
3997 | "occured", vha->vp_idx, code); | ||
3998 | break; | ||
3999 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */ | ||
4000 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | ||
4001 | break; | ||
4002 | |||
4003 | case MBA_LOOP_UP: | ||
4004 | { | ||
4005 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b, | ||
4006 | "qla_target(%d): Async LOOP_UP occured " | ||
4007 | "(m[1]=%x, m[2]=%x, m[3]=%x, m[4]=%x)", vha->vp_idx, | ||
4008 | le16_to_cpu(mailbox[1]), le16_to_cpu(mailbox[2]), | ||
4009 | le16_to_cpu(mailbox[3]), le16_to_cpu(mailbox[4])); | ||
4010 | if (tgt->link_reinit_iocb_pending) { | ||
4011 | qlt_send_notify_ack(vha, (void *)&tgt->link_reinit_iocb, | ||
4012 | 0, 0, 0, 0, 0, 0); | ||
4013 | tgt->link_reinit_iocb_pending = 0; | ||
4014 | } | ||
4015 | break; | ||
4016 | } | ||
4017 | |||
4018 | case MBA_LIP_OCCURRED: | ||
4019 | case MBA_LOOP_DOWN: | ||
4020 | case MBA_LIP_RESET: | ||
4021 | case MBA_RSCN_UPDATE: | ||
4022 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c, | ||
4023 | "qla_target(%d): Async event %#x occured " | ||
4024 | "(m[1]=%x, m[2]=%x, m[3]=%x, m[4]=%x)", vha->vp_idx, code, | ||
4025 | le16_to_cpu(mailbox[1]), le16_to_cpu(mailbox[2]), | ||
4026 | le16_to_cpu(mailbox[3]), le16_to_cpu(mailbox[4])); | ||
4027 | break; | ||
4028 | |||
4029 | case MBA_PORT_UPDATE: | ||
4030 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d, | ||
4031 | "qla_target(%d): Port update async event %#x " | ||
4032 | "occured: updating the ports database (m[1]=%x, m[2]=%x, " | ||
4033 | "m[3]=%x, m[4]=%x)", vha->vp_idx, code, | ||
4034 | le16_to_cpu(mailbox[1]), le16_to_cpu(mailbox[2]), | ||
4035 | le16_to_cpu(mailbox[3]), le16_to_cpu(mailbox[4])); | ||
4036 | reason_code = le16_to_cpu(mailbox[2]); | ||
4037 | if (reason_code == 0x4) | ||
4038 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e, | ||
4039 | "Async MB 2: Got PLOGI Complete\n"); | ||
4040 | else if (reason_code == 0x7) | ||
4041 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f, | ||
4042 | "Async MB 2: Port Logged Out\n"); | ||
4043 | break; | ||
4044 | |||
4045 | default: | ||
4046 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf040, | ||
4047 | "qla_target(%d): Async event %#x occured: " | ||
4048 | "ignore (m[1]=%x, m[2]=%x, m[3]=%x, m[4]=%x)", vha->vp_idx, | ||
4049 | code, le16_to_cpu(mailbox[1]), le16_to_cpu(mailbox[2]), | ||
4050 | le16_to_cpu(mailbox[3]), le16_to_cpu(mailbox[4])); | ||
4051 | break; | ||
4052 | } | ||
4053 | |||
4054 | tgt->irq_cmd_count--; | ||
4055 | } | ||
4056 | |||
4057 | static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha, | ||
4058 | uint16_t loop_id) | ||
4059 | { | ||
4060 | fc_port_t *fcport; | ||
4061 | int rc; | ||
4062 | |||
4063 | fcport = kzalloc(sizeof(*fcport), GFP_KERNEL); | ||
4064 | if (!fcport) { | ||
4065 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f, | ||
4066 | "qla_target(%d): Allocation of tmp FC port failed", | ||
4067 | vha->vp_idx); | ||
4068 | return NULL; | ||
4069 | } | ||
4070 | |||
4071 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf041, "loop_id %d", loop_id); | ||
4072 | |||
4073 | fcport->loop_id = loop_id; | ||
4074 | |||
4075 | rc = qla2x00_get_port_database(vha, fcport, 0); | ||
4076 | if (rc != QLA_SUCCESS) { | ||
4077 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070, | ||
4078 | "qla_target(%d): Failed to retrieve fcport " | ||
4079 | "information -- get_port_database() returned %x " | ||
4080 | "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id); | ||
4081 | kfree(fcport); | ||
4082 | return NULL; | ||
4083 | } | ||
4084 | |||
4085 | return fcport; | ||
4086 | } | ||
4087 | |||
4088 | /* Must be called under tgt_mutex */ | ||
4089 | static struct qla_tgt_sess *qlt_make_local_sess(struct scsi_qla_host *vha, | ||
4090 | uint8_t *s_id) | ||
4091 | { | ||
4092 | struct qla_hw_data *ha = vha->hw; | ||
4093 | struct qla_tgt_sess *sess = NULL; | ||
4094 | fc_port_t *fcport = NULL; | ||
4095 | int rc, global_resets; | ||
4096 | uint16_t loop_id = 0; | ||
4097 | |||
4098 | retry: | ||
4099 | global_resets = atomic_read(&ha->tgt.qla_tgt->tgt_global_resets_count); | ||
4100 | |||
4101 | rc = qla24xx_get_loop_id(vha, s_id, &loop_id); | ||
4102 | if (rc != 0) { | ||
4103 | if ((s_id[0] == 0xFF) && | ||
4104 | (s_id[1] == 0xFC)) { | ||
4105 | /* | ||
4106 | * This is Domain Controller, so it should be | ||
4107 | * OK to drop SCSI commands from it. | ||
4108 | */ | ||
4109 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042, | ||
4110 | "Unable to find initiator with S_ID %x:%x:%x", | ||
4111 | s_id[0], s_id[1], s_id[2]); | ||
4112 | } else | ||
4113 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf071, | ||
4114 | "qla_target(%d): Unable to find " | ||
4115 | "initiator with S_ID %x:%x:%x", | ||
4116 | vha->vp_idx, s_id[0], s_id[1], | ||
4117 | s_id[2]); | ||
4118 | return NULL; | ||
4119 | } | ||
4120 | |||
4121 | fcport = qlt_get_port_database(vha, loop_id); | ||
4122 | if (!fcport) | ||
4123 | return NULL; | ||
4124 | |||
4125 | if (global_resets != | ||
4126 | atomic_read(&ha->tgt.qla_tgt->tgt_global_resets_count)) { | ||
4127 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043, | ||
4128 | "qla_target(%d): global reset during session discovery " | ||
4129 | "(counter was %d, new %d), retrying", vha->vp_idx, | ||
4130 | global_resets, | ||
4131 | atomic_read(&ha->tgt.qla_tgt->tgt_global_resets_count)); | ||
4132 | goto retry; | ||
4133 | } | ||
4134 | |||
4135 | sess = qlt_create_sess(vha, fcport, true); | ||
4136 | |||
4137 | kfree(fcport); | ||
4138 | return sess; | ||
4139 | } | ||
4140 | |||
4141 | static void qlt_abort_work(struct qla_tgt *tgt, | ||
4142 | struct qla_tgt_sess_work_param *prm) | ||
4143 | { | ||
4144 | struct scsi_qla_host *vha = tgt->vha; | ||
4145 | struct qla_hw_data *ha = vha->hw; | ||
4146 | struct qla_tgt_sess *sess = NULL; | ||
4147 | unsigned long flags; | ||
4148 | uint32_t be_s_id; | ||
4149 | uint8_t s_id[3]; | ||
4150 | int rc; | ||
4151 | |||
4152 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
4153 | |||
4154 | if (tgt->tgt_stop) | ||
4155 | goto out_term; | ||
4156 | |||
4157 | s_id[0] = prm->abts.fcp_hdr_le.s_id[2]; | ||
4158 | s_id[1] = prm->abts.fcp_hdr_le.s_id[1]; | ||
4159 | s_id[2] = prm->abts.fcp_hdr_le.s_id[0]; | ||
4160 | |||
4161 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, | ||
4162 | (unsigned char *)&be_s_id); | ||
4163 | if (!sess) { | ||
4164 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
4165 | |||
4166 | mutex_lock(&ha->tgt.tgt_mutex); | ||
4167 | sess = qlt_make_local_sess(vha, s_id); | ||
4168 | /* sess has got an extra creation ref */ | ||
4169 | mutex_unlock(&ha->tgt.tgt_mutex); | ||
4170 | |||
4171 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
4172 | if (!sess) | ||
4173 | goto out_term; | ||
4174 | } else { | ||
4175 | kref_get(&sess->se_sess->sess_kref); | ||
4176 | } | ||
4177 | |||
4178 | if (tgt->tgt_stop) | ||
4179 | goto out_term; | ||
4180 | |||
4181 | rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess); | ||
4182 | if (rc != 0) | ||
4183 | goto out_term; | ||
4184 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
4185 | |||
4186 | ha->tgt.tgt_ops->put_sess(sess); | ||
4187 | return; | ||
4188 | |||
4189 | out_term: | ||
4190 | qlt_24xx_send_abts_resp(vha, &prm->abts, FCP_TMF_REJECTED, false); | ||
4191 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
4192 | if (sess) | ||
4193 | ha->tgt.tgt_ops->put_sess(sess); | ||
4194 | } | ||
4195 | |||
4196 | static void qlt_tmr_work(struct qla_tgt *tgt, | ||
4197 | struct qla_tgt_sess_work_param *prm) | ||
4198 | { | ||
4199 | struct atio_from_isp *a = &prm->tm_iocb2; | ||
4200 | struct scsi_qla_host *vha = tgt->vha; | ||
4201 | struct qla_hw_data *ha = vha->hw; | ||
4202 | struct qla_tgt_sess *sess = NULL; | ||
4203 | unsigned long flags; | ||
4204 | uint8_t *s_id = NULL; /* to hide compiler warnings */ | ||
4205 | int rc; | ||
4206 | uint32_t lun, unpacked_lun; | ||
4207 | int lun_size, fn; | ||
4208 | void *iocb; | ||
4209 | |||
4210 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
4211 | |||
4212 | if (tgt->tgt_stop) | ||
4213 | goto out_term; | ||
4214 | |||
4215 | s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id; | ||
4216 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); | ||
4217 | if (!sess) { | ||
4218 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
4219 | |||
4220 | mutex_lock(&ha->tgt.tgt_mutex); | ||
4221 | sess = qlt_make_local_sess(vha, s_id); | ||
4222 | /* sess has got an extra creation ref */ | ||
4223 | mutex_unlock(&ha->tgt.tgt_mutex); | ||
4224 | |||
4225 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
4226 | if (!sess) | ||
4227 | goto out_term; | ||
4228 | } else { | ||
4229 | kref_get(&sess->se_sess->sess_kref); | ||
4230 | } | ||
4231 | |||
4232 | iocb = a; | ||
4233 | lun = a->u.isp24.fcp_cmnd.lun; | ||
4234 | lun_size = sizeof(lun); | ||
4235 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; | ||
4236 | unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); | ||
4237 | |||
4238 | rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); | ||
4239 | if (rc != 0) | ||
4240 | goto out_term; | ||
4241 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
4242 | |||
4243 | ha->tgt.tgt_ops->put_sess(sess); | ||
4244 | return; | ||
4245 | |||
4246 | out_term: | ||
4247 | qlt_send_term_exchange(vha, NULL, &prm->tm_iocb2, 1); | ||
4248 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
4249 | if (sess) | ||
4250 | ha->tgt.tgt_ops->put_sess(sess); | ||
4251 | } | ||
4252 | |||
4253 | static void qlt_sess_work_fn(struct work_struct *work) | ||
4254 | { | ||
4255 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work); | ||
4256 | struct scsi_qla_host *vha = tgt->vha; | ||
4257 | unsigned long flags; | ||
4258 | |||
4259 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt); | ||
4260 | |||
4261 | spin_lock_irqsave(&tgt->sess_work_lock, flags); | ||
4262 | while (!list_empty(&tgt->sess_works_list)) { | ||
4263 | struct qla_tgt_sess_work_param *prm = list_entry( | ||
4264 | tgt->sess_works_list.next, typeof(*prm), | ||
4265 | sess_works_list_entry); | ||
4266 | |||
4267 | /* | ||
4268 | * This work can be scheduled on several CPUs at time, so we | ||
4269 | * must delete the entry to eliminate double processing | ||
4270 | */ | ||
4271 | list_del(&prm->sess_works_list_entry); | ||
4272 | |||
4273 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); | ||
4274 | |||
4275 | switch (prm->type) { | ||
4276 | case QLA_TGT_SESS_WORK_ABORT: | ||
4277 | qlt_abort_work(tgt, prm); | ||
4278 | break; | ||
4279 | case QLA_TGT_SESS_WORK_TM: | ||
4280 | qlt_tmr_work(tgt, prm); | ||
4281 | break; | ||
4282 | default: | ||
4283 | BUG_ON(1); | ||
4284 | break; | ||
4285 | } | ||
4286 | |||
4287 | spin_lock_irqsave(&tgt->sess_work_lock, flags); | ||
4288 | |||
4289 | kfree(prm); | ||
4290 | } | ||
4291 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); | ||
4292 | } | ||
4293 | |||
4294 | /* Must be called under tgt_host_action_mutex */ | ||
4295 | int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha) | ||
4296 | { | ||
4297 | struct qla_tgt *tgt; | ||
4298 | |||
4299 | if (!QLA_TGT_MODE_ENABLED()) | ||
4300 | return 0; | ||
4301 | |||
4302 | ql_dbg(ql_dbg_tgt, base_vha, 0xe03b, | ||
4303 | "Registering target for host %ld(%p)", base_vha->host_no, ha); | ||
4304 | |||
4305 | BUG_ON((ha->tgt.qla_tgt != NULL) || (ha->tgt.tgt_ops != NULL)); | ||
4306 | |||
4307 | tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL); | ||
4308 | if (!tgt) { | ||
4309 | ql_dbg(ql_dbg_tgt, base_vha, 0xe066, | ||
4310 | "Unable to allocate struct qla_tgt\n"); | ||
4311 | return -ENOMEM; | ||
4312 | } | ||
4313 | |||
4314 | if (!(base_vha->host->hostt->supported_mode & MODE_TARGET)) | ||
4315 | base_vha->host->hostt->supported_mode |= MODE_TARGET; | ||
4316 | |||
4317 | tgt->ha = ha; | ||
4318 | tgt->vha = base_vha; | ||
4319 | init_waitqueue_head(&tgt->waitQ); | ||
4320 | INIT_LIST_HEAD(&tgt->sess_list); | ||
4321 | INIT_LIST_HEAD(&tgt->del_sess_list); | ||
4322 | INIT_DELAYED_WORK(&tgt->sess_del_work, | ||
4323 | (void (*)(struct work_struct *))qlt_del_sess_work_fn); | ||
4324 | spin_lock_init(&tgt->sess_work_lock); | ||
4325 | INIT_WORK(&tgt->sess_work, qlt_sess_work_fn); | ||
4326 | INIT_LIST_HEAD(&tgt->sess_works_list); | ||
4327 | spin_lock_init(&tgt->srr_lock); | ||
4328 | INIT_LIST_HEAD(&tgt->srr_ctio_list); | ||
4329 | INIT_LIST_HEAD(&tgt->srr_imm_list); | ||
4330 | INIT_WORK(&tgt->srr_work, qlt_handle_srr_work); | ||
4331 | atomic_set(&tgt->tgt_global_resets_count, 0); | ||
4332 | |||
4333 | ha->tgt.qla_tgt = tgt; | ||
4334 | |||
4335 | ql_dbg(ql_dbg_tgt, base_vha, 0xe067, | ||
4336 | "qla_target(%d): using 64 Bit PCI addressing", | ||
4337 | base_vha->vp_idx); | ||
4338 | tgt->tgt_enable_64bit_addr = 1; | ||
4339 | /* 3 is reserved */ | ||
4340 | tgt->sg_tablesize = QLA_TGT_MAX_SG_24XX(base_vha->req->length - 3); | ||
4341 | tgt->datasegs_per_cmd = QLA_TGT_DATASEGS_PER_CMD_24XX; | ||
4342 | tgt->datasegs_per_cont = QLA_TGT_DATASEGS_PER_CONT_24XX; | ||
4343 | |||
4344 | mutex_lock(&qla_tgt_mutex); | ||
4345 | list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); | ||
4346 | mutex_unlock(&qla_tgt_mutex); | ||
4347 | |||
4348 | return 0; | ||
4349 | } | ||
4350 | |||
4351 | /* Must be called under tgt_host_action_mutex */ | ||
4352 | int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha) | ||
4353 | { | ||
4354 | if (!ha->tgt.qla_tgt) | ||
4355 | return 0; | ||
4356 | |||
4357 | mutex_lock(&qla_tgt_mutex); | ||
4358 | list_del(&ha->tgt.qla_tgt->tgt_list_entry); | ||
4359 | mutex_unlock(&qla_tgt_mutex); | ||
4360 | |||
4361 | ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)", | ||
4362 | vha->host_no, ha); | ||
4363 | qlt_release(ha->tgt.qla_tgt); | ||
4364 | |||
4365 | return 0; | ||
4366 | } | ||
4367 | |||
4368 | static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn, | ||
4369 | unsigned char *b) | ||
4370 | { | ||
4371 | int i; | ||
4372 | |||
4373 | pr_debug("qla2xxx HW vha->node_name: "); | ||
4374 | for (i = 0; i < WWN_SIZE; i++) | ||
4375 | pr_debug("%02x ", vha->node_name[i]); | ||
4376 | pr_debug("\n"); | ||
4377 | pr_debug("qla2xxx HW vha->port_name: "); | ||
4378 | for (i = 0; i < WWN_SIZE; i++) | ||
4379 | pr_debug("%02x ", vha->port_name[i]); | ||
4380 | pr_debug("\n"); | ||
4381 | |||
4382 | pr_debug("qla2xxx passed configfs WWPN: "); | ||
4383 | put_unaligned_be64(wwpn, b); | ||
4384 | for (i = 0; i < WWN_SIZE; i++) | ||
4385 | pr_debug("%02x ", b[i]); | ||
4386 | pr_debug("\n"); | ||
4387 | } | ||
4388 | |||
4389 | /** | ||
4390 | * qla_tgt_lport_register - register lport with external module | ||
4391 | * | ||
4392 | * @qla_tgt_ops: Pointer for tcm_qla2xxx qla_tgt_ops | ||
4393 | * @wwpn: Passwd FC target WWPN | ||
4394 | * @callback: lport initialization callback for tcm_qla2xxx code | ||
4395 | * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data | ||
4396 | */ | ||
4397 | int qlt_lport_register(struct qla_tgt_func_tmpl *qla_tgt_ops, u64 wwpn, | ||
4398 | int (*callback)(struct scsi_qla_host *), void *target_lport_ptr) | ||
4399 | { | ||
4400 | struct qla_tgt *tgt; | ||
4401 | struct scsi_qla_host *vha; | ||
4402 | struct qla_hw_data *ha; | ||
4403 | struct Scsi_Host *host; | ||
4404 | unsigned long flags; | ||
4405 | int rc; | ||
4406 | u8 b[WWN_SIZE]; | ||
4407 | |||
4408 | mutex_lock(&qla_tgt_mutex); | ||
4409 | list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) { | ||
4410 | vha = tgt->vha; | ||
4411 | ha = vha->hw; | ||
4412 | |||
4413 | host = vha->host; | ||
4414 | if (!host) | ||
4415 | continue; | ||
4416 | |||
4417 | if (ha->tgt.tgt_ops != NULL) | ||
4418 | continue; | ||
4419 | |||
4420 | if (!(host->hostt->supported_mode & MODE_TARGET)) | ||
4421 | continue; | ||
4422 | |||
4423 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
4424 | if (host->active_mode & MODE_TARGET) { | ||
4425 | pr_debug("MODE_TARGET already active on qla2xxx(%d)\n", | ||
4426 | host->host_no); | ||
4427 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
4428 | continue; | ||
4429 | } | ||
4430 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
4431 | |||
4432 | if (!scsi_host_get(host)) { | ||
4433 | ql_dbg(ql_dbg_tgt, vha, 0xe068, | ||
4434 | "Unable to scsi_host_get() for" | ||
4435 | " qla2xxx scsi_host\n"); | ||
4436 | continue; | ||
4437 | } | ||
4438 | qlt_lport_dump(vha, wwpn, b); | ||
4439 | |||
4440 | if (memcmp(vha->port_name, b, WWN_SIZE)) { | ||
4441 | scsi_host_put(host); | ||
4442 | continue; | ||
4443 | } | ||
4444 | /* | ||
4445 | * Setup passed parameters ahead of invoking callback | ||
4446 | */ | ||
4447 | ha->tgt.tgt_ops = qla_tgt_ops; | ||
4448 | ha->tgt.target_lport_ptr = target_lport_ptr; | ||
4449 | rc = (*callback)(vha); | ||
4450 | if (rc != 0) { | ||
4451 | ha->tgt.tgt_ops = NULL; | ||
4452 | ha->tgt.target_lport_ptr = NULL; | ||
4453 | } | ||
4454 | mutex_unlock(&qla_tgt_mutex); | ||
4455 | return rc; | ||
4456 | } | ||
4457 | mutex_unlock(&qla_tgt_mutex); | ||
4458 | |||
4459 | return -ENODEV; | ||
4460 | } | ||
4461 | EXPORT_SYMBOL(qlt_lport_register); | ||
4462 | |||
4463 | /** | ||
4464 | * qla_tgt_lport_deregister - Degister lport | ||
4465 | * | ||
4466 | * @vha: Registered scsi_qla_host pointer | ||
4467 | */ | ||
4468 | void qlt_lport_deregister(struct scsi_qla_host *vha) | ||
4469 | { | ||
4470 | struct qla_hw_data *ha = vha->hw; | ||
4471 | struct Scsi_Host *sh = vha->host; | ||
4472 | /* | ||
4473 | * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data | ||
4474 | */ | ||
4475 | ha->tgt.target_lport_ptr = NULL; | ||
4476 | ha->tgt.tgt_ops = NULL; | ||
4477 | /* | ||
4478 | * Release the Scsi_Host reference for the underlying qla2xxx host | ||
4479 | */ | ||
4480 | scsi_host_put(sh); | ||
4481 | } | ||
4482 | EXPORT_SYMBOL(qlt_lport_deregister); | ||
4483 | |||
4484 | /* Must be called under HW lock */ | ||
4485 | void qlt_set_mode(struct scsi_qla_host *vha) | ||
4486 | { | ||
4487 | struct qla_hw_data *ha = vha->hw; | ||
4488 | |||
4489 | switch (ql2x_ini_mode) { | ||
4490 | case QLA2XXX_INI_MODE_DISABLED: | ||
4491 | case QLA2XXX_INI_MODE_EXCLUSIVE: | ||
4492 | vha->host->active_mode = MODE_TARGET; | ||
4493 | break; | ||
4494 | case QLA2XXX_INI_MODE_ENABLED: | ||
4495 | vha->host->active_mode |= MODE_TARGET; | ||
4496 | break; | ||
4497 | default: | ||
4498 | break; | ||
4499 | } | ||
4500 | |||
4501 | if (ha->tgt.ini_mode_force_reverse) | ||
4502 | qla_reverse_ini_mode(vha); | ||
4503 | } | ||
4504 | |||
4505 | /* Must be called under HW lock */ | ||
4506 | void qlt_clear_mode(struct scsi_qla_host *vha) | ||
4507 | { | ||
4508 | struct qla_hw_data *ha = vha->hw; | ||
4509 | |||
4510 | switch (ql2x_ini_mode) { | ||
4511 | case QLA2XXX_INI_MODE_DISABLED: | ||
4512 | vha->host->active_mode = MODE_UNKNOWN; | ||
4513 | break; | ||
4514 | case QLA2XXX_INI_MODE_EXCLUSIVE: | ||
4515 | vha->host->active_mode = MODE_INITIATOR; | ||
4516 | break; | ||
4517 | case QLA2XXX_INI_MODE_ENABLED: | ||
4518 | vha->host->active_mode &= ~MODE_TARGET; | ||
4519 | break; | ||
4520 | default: | ||
4521 | break; | ||
4522 | } | ||
4523 | |||
4524 | if (ha->tgt.ini_mode_force_reverse) | ||
4525 | qla_reverse_ini_mode(vha); | ||
4526 | } | ||
4527 | |||
4528 | /* | ||
4529 | * qla_tgt_enable_vha - NO LOCK HELD | ||
4530 | * | ||
4531 | * host_reset, bring up w/ Target Mode Enabled | ||
4532 | */ | ||
4533 | void | ||
4534 | qlt_enable_vha(struct scsi_qla_host *vha) | ||
4535 | { | ||
4536 | struct qla_hw_data *ha = vha->hw; | ||
4537 | struct qla_tgt *tgt = ha->tgt.qla_tgt; | ||
4538 | unsigned long flags; | ||
4539 | |||
4540 | if (!tgt) { | ||
4541 | ql_dbg(ql_dbg_tgt, vha, 0xe069, | ||
4542 | "Unable to locate qla_tgt pointer from" | ||
4543 | " struct qla_hw_data\n"); | ||
4544 | dump_stack(); | ||
4545 | return; | ||
4546 | } | ||
4547 | |||
4548 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
4549 | tgt->tgt_stopped = 0; | ||
4550 | qlt_set_mode(vha); | ||
4551 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
4552 | |||
4553 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | ||
4554 | qla2xxx_wake_dpc(vha); | ||
4555 | qla2x00_wait_for_hba_online(vha); | ||
4556 | } | ||
4557 | EXPORT_SYMBOL(qlt_enable_vha); | ||
4558 | |||
4559 | /* | ||
4560 | * qla_tgt_disable_vha - NO LOCK HELD | ||
4561 | * | ||
4562 | * Disable Target Mode and reset the adapter | ||
4563 | */ | ||
4564 | void | ||
4565 | qlt_disable_vha(struct scsi_qla_host *vha) | ||
4566 | { | ||
4567 | struct qla_hw_data *ha = vha->hw; | ||
4568 | struct qla_tgt *tgt = ha->tgt.qla_tgt; | ||
4569 | unsigned long flags; | ||
4570 | |||
4571 | if (!tgt) { | ||
4572 | ql_dbg(ql_dbg_tgt, vha, 0xe06a, | ||
4573 | "Unable to locate qla_tgt pointer from" | ||
4574 | " struct qla_hw_data\n"); | ||
4575 | dump_stack(); | ||
4576 | return; | ||
4577 | } | ||
4578 | |||
4579 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
4580 | qlt_clear_mode(vha); | ||
4581 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
4582 | |||
4583 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | ||
4584 | qla2xxx_wake_dpc(vha); | ||
4585 | qla2x00_wait_for_hba_online(vha); | ||
4586 | } | ||
4587 | |||
4588 | /* | ||
4589 | * Called from qla_init.c:qla24xx_vport_create() contex to setup | ||
4590 | * the target mode specific struct scsi_qla_host and struct qla_hw_data | ||
4591 | * members. | ||
4592 | */ | ||
4593 | void | ||
4594 | qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha) | ||
4595 | { | ||
4596 | if (!qla_tgt_mode_enabled(vha)) | ||
4597 | return; | ||
4598 | |||
4599 | mutex_init(&ha->tgt.tgt_mutex); | ||
4600 | mutex_init(&ha->tgt.tgt_host_action_mutex); | ||
4601 | |||
4602 | qlt_clear_mode(vha); | ||
4603 | |||
4604 | /* | ||
4605 | * NOTE: Currently the value is kept the same for <24xx and | ||
4606 | * >=24xx ISPs. If it is necessary to change it, | ||
4607 | * the check should be added for specific ISPs, | ||
4608 | * assigning the value appropriately. | ||
4609 | */ | ||
4610 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; | ||
4611 | } | ||
4612 | |||
4613 | void | ||
4614 | qlt_rff_id(struct scsi_qla_host *vha, struct ct_sns_req *ct_req) | ||
4615 | { | ||
4616 | /* | ||
4617 | * FC-4 Feature bit 0 indicates target functionality to the name server. | ||
4618 | */ | ||
4619 | if (qla_tgt_mode_enabled(vha)) { | ||
4620 | if (qla_ini_mode_enabled(vha)) | ||
4621 | ct_req->req.rff_id.fc4_feature = BIT_0 | BIT_1; | ||
4622 | else | ||
4623 | ct_req->req.rff_id.fc4_feature = BIT_0; | ||
4624 | } else if (qla_ini_mode_enabled(vha)) { | ||
4625 | ct_req->req.rff_id.fc4_feature = BIT_1; | ||
4626 | } | ||
4627 | } | ||
4628 | |||
4629 | /* | ||
4630 | * qlt_init_atio_q_entries() - Initializes ATIO queue entries. | ||
4631 | * @ha: HA context | ||
4632 | * | ||
4633 | * Beginning of ATIO ring has initialization control block already built | ||
4634 | * by nvram config routine. | ||
4635 | * | ||
4636 | * Returns 0 on success. | ||
4637 | */ | ||
4638 | void | ||
4639 | qlt_init_atio_q_entries(struct scsi_qla_host *vha) | ||
4640 | { | ||
4641 | struct qla_hw_data *ha = vha->hw; | ||
4642 | uint16_t cnt; | ||
4643 | struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring; | ||
4644 | |||
4645 | if (!qla_tgt_mode_enabled(vha)) | ||
4646 | return; | ||
4647 | |||
4648 | for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) { | ||
4649 | pkt->u.raw.signature = ATIO_PROCESSED; | ||
4650 | pkt++; | ||
4651 | } | ||
4652 | |||
4653 | } | ||
4654 | |||
4655 | /* | ||
4656 | * qlt_24xx_process_atio_queue() - Process ATIO queue entries. | ||
4657 | * @ha: SCSI driver HA context | ||
4658 | */ | ||
4659 | void | ||
4660 | qlt_24xx_process_atio_queue(struct scsi_qla_host *vha) | ||
4661 | { | ||
4662 | struct qla_hw_data *ha = vha->hw; | ||
4663 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; | ||
4664 | struct atio_from_isp *pkt; | ||
4665 | int cnt, i; | ||
4666 | |||
4667 | if (!vha->flags.online) | ||
4668 | return; | ||
4669 | |||
4670 | while (ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) { | ||
4671 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; | ||
4672 | cnt = pkt->u.raw.entry_count; | ||
4673 | |||
4674 | qlt_24xx_atio_pkt_all_vps(vha, (struct atio_from_isp *)pkt); | ||
4675 | |||
4676 | for (i = 0; i < cnt; i++) { | ||
4677 | ha->tgt.atio_ring_index++; | ||
4678 | if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) { | ||
4679 | ha->tgt.atio_ring_index = 0; | ||
4680 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; | ||
4681 | } else | ||
4682 | ha->tgt.atio_ring_ptr++; | ||
4683 | |||
4684 | pkt->u.raw.signature = ATIO_PROCESSED; | ||
4685 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; | ||
4686 | } | ||
4687 | wmb(); | ||
4688 | } | ||
4689 | |||
4690 | /* Adjust ring index */ | ||
4691 | WRT_REG_DWORD(®->atio_q_out, ha->tgt.atio_ring_index); | ||
4692 | } | ||
4693 | |||
4694 | void | ||
4695 | qlt_24xx_config_rings(struct scsi_qla_host *vha, device_reg_t __iomem *reg) | ||
4696 | { | ||
4697 | struct qla_hw_data *ha = vha->hw; | ||
4698 | |||
4699 | /* FIXME: atio_q in/out for ha->mqenable=1..? */ | ||
4700 | if (ha->mqenable) { | ||
4701 | #if 0 | ||
4702 | WRT_REG_DWORD(®->isp25mq.atio_q_in, 0); | ||
4703 | WRT_REG_DWORD(®->isp25mq.atio_q_out, 0); | ||
4704 | RD_REG_DWORD(®->isp25mq.atio_q_out); | ||
4705 | #endif | ||
4706 | } else { | ||
4707 | /* Setup APTIO registers for target mode */ | ||
4708 | WRT_REG_DWORD(®->isp24.atio_q_in, 0); | ||
4709 | WRT_REG_DWORD(®->isp24.atio_q_out, 0); | ||
4710 | RD_REG_DWORD(®->isp24.atio_q_out); | ||
4711 | } | ||
4712 | } | ||
4713 | |||
4714 | void | ||
4715 | qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) | ||
4716 | { | ||
4717 | struct qla_hw_data *ha = vha->hw; | ||
4718 | |||
4719 | if (qla_tgt_mode_enabled(vha)) { | ||
4720 | if (!ha->tgt.saved_set) { | ||
4721 | /* We save only once */ | ||
4722 | ha->tgt.saved_exchange_count = nv->exchange_count; | ||
4723 | ha->tgt.saved_firmware_options_1 = | ||
4724 | nv->firmware_options_1; | ||
4725 | ha->tgt.saved_firmware_options_2 = | ||
4726 | nv->firmware_options_2; | ||
4727 | ha->tgt.saved_firmware_options_3 = | ||
4728 | nv->firmware_options_3; | ||
4729 | ha->tgt.saved_set = 1; | ||
4730 | } | ||
4731 | |||
4732 | nv->exchange_count = __constant_cpu_to_le16(0xFFFF); | ||
4733 | |||
4734 | /* Enable target mode */ | ||
4735 | nv->firmware_options_1 |= __constant_cpu_to_le32(BIT_4); | ||
4736 | |||
4737 | /* Disable ini mode, if requested */ | ||
4738 | if (!qla_ini_mode_enabled(vha)) | ||
4739 | nv->firmware_options_1 |= __constant_cpu_to_le32(BIT_5); | ||
4740 | |||
4741 | /* Disable Full Login after LIP */ | ||
4742 | nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13); | ||
4743 | /* Enable initial LIP */ | ||
4744 | nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_9); | ||
4745 | /* Enable FC tapes support */ | ||
4746 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); | ||
4747 | /* Disable Full Login after LIP */ | ||
4748 | nv->host_p &= __constant_cpu_to_le32(~BIT_10); | ||
4749 | /* Enable target PRLI control */ | ||
4750 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_14); | ||
4751 | } else { | ||
4752 | if (ha->tgt.saved_set) { | ||
4753 | nv->exchange_count = ha->tgt.saved_exchange_count; | ||
4754 | nv->firmware_options_1 = | ||
4755 | ha->tgt.saved_firmware_options_1; | ||
4756 | nv->firmware_options_2 = | ||
4757 | ha->tgt.saved_firmware_options_2; | ||
4758 | nv->firmware_options_3 = | ||
4759 | ha->tgt.saved_firmware_options_3; | ||
4760 | } | ||
4761 | return; | ||
4762 | } | ||
4763 | |||
4764 | /* out-of-order frames reassembly */ | ||
4765 | nv->firmware_options_3 |= BIT_6|BIT_9; | ||
4766 | |||
4767 | if (ha->tgt.enable_class_2) { | ||
4768 | if (vha->flags.init_done) | ||
4769 | fc_host_supported_classes(vha->host) = | ||
4770 | FC_COS_CLASS2 | FC_COS_CLASS3; | ||
4771 | |||
4772 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_8); | ||
4773 | } else { | ||
4774 | if (vha->flags.init_done) | ||
4775 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; | ||
4776 | |||
4777 | nv->firmware_options_2 &= ~__constant_cpu_to_le32(BIT_8); | ||
4778 | } | ||
4779 | } | ||
4780 | |||
4781 | void | ||
4782 | qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha, | ||
4783 | struct init_cb_24xx *icb) | ||
4784 | { | ||
4785 | struct qla_hw_data *ha = vha->hw; | ||
4786 | |||
4787 | if (ha->tgt.node_name_set) { | ||
4788 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); | ||
4789 | icb->firmware_options_1 |= __constant_cpu_to_le32(BIT_14); | ||
4790 | } | ||
4791 | } | ||
4792 | |||
4793 | int | ||
4794 | qlt_24xx_process_response_error(struct scsi_qla_host *vha, | ||
4795 | struct sts_entry_24xx *pkt) | ||
4796 | { | ||
4797 | switch (pkt->entry_type) { | ||
4798 | case ABTS_RECV_24XX: | ||
4799 | case ABTS_RESP_24XX: | ||
4800 | case CTIO_TYPE7: | ||
4801 | case NOTIFY_ACK_TYPE: | ||
4802 | return 1; | ||
4803 | default: | ||
4804 | return 0; | ||
4805 | } | ||
4806 | } | ||
4807 | |||
4808 | void | ||
4809 | qlt_modify_vp_config(struct scsi_qla_host *vha, | ||
4810 | struct vp_config_entry_24xx *vpmod) | ||
4811 | { | ||
4812 | if (qla_tgt_mode_enabled(vha)) | ||
4813 | vpmod->options_idx1 &= ~BIT_5; | ||
4814 | /* Disable ini mode, if requested */ | ||
4815 | if (!qla_ini_mode_enabled(vha)) | ||
4816 | vpmod->options_idx1 &= ~BIT_4; | ||
4817 | } | ||
4818 | |||
4819 | void | ||
4820 | qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha) | ||
4821 | { | ||
4822 | if (!QLA_TGT_MODE_ENABLED()) | ||
4823 | return; | ||
4824 | |||
4825 | mutex_init(&ha->tgt.tgt_mutex); | ||
4826 | mutex_init(&ha->tgt.tgt_host_action_mutex); | ||
4827 | qlt_clear_mode(base_vha); | ||
4828 | } | ||
4829 | |||
4830 | int | ||
4831 | qlt_mem_alloc(struct qla_hw_data *ha) | ||
4832 | { | ||
4833 | if (!QLA_TGT_MODE_ENABLED()) | ||
4834 | return 0; | ||
4835 | |||
4836 | ha->tgt.tgt_vp_map = kzalloc(sizeof(struct qla_tgt_vp_map) * | ||
4837 | MAX_MULTI_ID_FABRIC, GFP_KERNEL); | ||
4838 | if (!ha->tgt.tgt_vp_map) | ||
4839 | return -ENOMEM; | ||
4840 | |||
4841 | ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev, | ||
4842 | (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp), | ||
4843 | &ha->tgt.atio_dma, GFP_KERNEL); | ||
4844 | if (!ha->tgt.atio_ring) { | ||
4845 | kfree(ha->tgt.tgt_vp_map); | ||
4846 | return -ENOMEM; | ||
4847 | } | ||
4848 | return 0; | ||
4849 | } | ||
4850 | |||
4851 | void | ||
4852 | qlt_mem_free(struct qla_hw_data *ha) | ||
4853 | { | ||
4854 | if (!QLA_TGT_MODE_ENABLED()) | ||
4855 | return; | ||
4856 | |||
4857 | if (ha->tgt.atio_ring) { | ||
4858 | dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) * | ||
4859 | sizeof(struct atio_from_isp), ha->tgt.atio_ring, | ||
4860 | ha->tgt.atio_dma); | ||
4861 | } | ||
4862 | kfree(ha->tgt.tgt_vp_map); | ||
4863 | } | ||
4864 | |||
4865 | /* vport_slock to be held by the caller */ | ||
4866 | void | ||
4867 | qlt_update_vp_map(struct scsi_qla_host *vha, int cmd) | ||
4868 | { | ||
4869 | if (!QLA_TGT_MODE_ENABLED()) | ||
4870 | return; | ||
4871 | |||
4872 | switch (cmd) { | ||
4873 | case SET_VP_IDX: | ||
4874 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha; | ||
4875 | break; | ||
4876 | case SET_AL_PA: | ||
4877 | vha->hw->tgt.tgt_vp_map[vha->d_id.b.al_pa].idx = vha->vp_idx; | ||
4878 | break; | ||
4879 | case RESET_VP_IDX: | ||
4880 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL; | ||
4881 | break; | ||
4882 | case RESET_AL_PA: | ||
4883 | vha->hw->tgt.tgt_vp_map[vha->d_id.b.al_pa].idx = 0; | ||
4884 | break; | ||
4885 | } | ||
4886 | } | ||
4887 | |||
4888 | static int __init qlt_parse_ini_mode(void) | ||
4889 | { | ||
4890 | if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0) | ||
4891 | ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; | ||
4892 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0) | ||
4893 | ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED; | ||
4894 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0) | ||
4895 | ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED; | ||
4896 | else | ||
4897 | return false; | ||
4898 | |||
4899 | return true; | ||
4900 | } | ||
4901 | |||
4902 | int __init qlt_init(void) | ||
4903 | { | ||
4904 | int ret; | ||
4905 | |||
4906 | if (!qlt_parse_ini_mode()) { | ||
4907 | ql_log(ql_log_fatal, NULL, 0xe06b, | ||
4908 | "qlt_parse_ini_mode() failed\n"); | ||
4909 | return -EINVAL; | ||
4910 | } | ||
4911 | |||
4912 | if (!QLA_TGT_MODE_ENABLED()) | ||
4913 | return 0; | ||
4914 | |||
4915 | qla_tgt_cmd_cachep = kmem_cache_create("qla_tgt_cmd_cachep", | ||
4916 | sizeof(struct qla_tgt_cmd), __alignof__(struct qla_tgt_cmd), 0, | ||
4917 | NULL); | ||
4918 | if (!qla_tgt_cmd_cachep) { | ||
4919 | ql_log(ql_log_fatal, NULL, 0xe06c, | ||
4920 | "kmem_cache_create for qla_tgt_cmd_cachep failed\n"); | ||
4921 | return -ENOMEM; | ||
4922 | } | ||
4923 | |||
4924 | qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep", | ||
4925 | sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct | ||
4926 | qla_tgt_mgmt_cmd), 0, NULL); | ||
4927 | if (!qla_tgt_mgmt_cmd_cachep) { | ||
4928 | ql_log(ql_log_fatal, NULL, 0xe06d, | ||
4929 | "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n"); | ||
4930 | ret = -ENOMEM; | ||
4931 | goto out; | ||
4932 | } | ||
4933 | |||
4934 | qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab, | ||
4935 | mempool_free_slab, qla_tgt_mgmt_cmd_cachep); | ||
4936 | if (!qla_tgt_mgmt_cmd_mempool) { | ||
4937 | ql_log(ql_log_fatal, NULL, 0xe06e, | ||
4938 | "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n"); | ||
4939 | ret = -ENOMEM; | ||
4940 | goto out_mgmt_cmd_cachep; | ||
4941 | } | ||
4942 | |||
4943 | qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0); | ||
4944 | if (!qla_tgt_wq) { | ||
4945 | ql_log(ql_log_fatal, NULL, 0xe06f, | ||
4946 | "alloc_workqueue for qla_tgt_wq failed\n"); | ||
4947 | ret = -ENOMEM; | ||
4948 | goto out_cmd_mempool; | ||
4949 | } | ||
4950 | /* | ||
4951 | * Return 1 to signal that initiator-mode is being disabled | ||
4952 | */ | ||
4953 | return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0; | ||
4954 | |||
4955 | out_cmd_mempool: | ||
4956 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); | ||
4957 | out_mgmt_cmd_cachep: | ||
4958 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); | ||
4959 | out: | ||
4960 | kmem_cache_destroy(qla_tgt_cmd_cachep); | ||
4961 | return ret; | ||
4962 | } | ||
4963 | |||
4964 | void qlt_exit(void) | ||
4965 | { | ||
4966 | if (!QLA_TGT_MODE_ENABLED()) | ||
4967 | return; | ||
4968 | |||
4969 | destroy_workqueue(qla_tgt_wq); | ||
4970 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); | ||
4971 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); | ||
4972 | kmem_cache_destroy(qla_tgt_cmd_cachep); | ||
4973 | } | ||
diff --git a/drivers/scsi/qla2xxx/qla_target.h b/drivers/scsi/qla2xxx/qla_target.h new file mode 100644 index 000000000000..9ec19bc2f0fe --- /dev/null +++ b/drivers/scsi/qla2xxx/qla_target.h | |||
@@ -0,0 +1,1005 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net> | ||
3 | * Copyright (C) 2004 - 2005 Leonid Stoljar | ||
4 | * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us> | ||
5 | * Copyright (C) 2007 - 2010 ID7 Ltd. | ||
6 | * | ||
7 | * Forward port and refactoring to modern qla2xxx and target/configfs | ||
8 | * | ||
9 | * Copyright (C) 2010-2011 Nicholas A. Bellinger <nab@kernel.org> | ||
10 | * | ||
11 | * Additional file for the target driver support. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | * GNU General Public License for more details. | ||
22 | */ | ||
23 | /* | ||
24 | * This is the global def file that is useful for including from the | ||
25 | * target portion. | ||
26 | */ | ||
27 | |||
28 | #ifndef __QLA_TARGET_H | ||
29 | #define __QLA_TARGET_H | ||
30 | |||
31 | #include "qla_def.h" | ||
32 | |||
33 | /* | ||
34 | * Must be changed on any change in any initiator visible interfaces or | ||
35 | * data in the target add-on | ||
36 | */ | ||
37 | #define QLA2XXX_TARGET_MAGIC 269 | ||
38 | |||
39 | /* | ||
40 | * Must be changed on any change in any target visible interfaces or | ||
41 | * data in the initiator | ||
42 | */ | ||
43 | #define QLA2XXX_INITIATOR_MAGIC 57222 | ||
44 | |||
45 | #define QLA2XXX_INI_MODE_STR_EXCLUSIVE "exclusive" | ||
46 | #define QLA2XXX_INI_MODE_STR_DISABLED "disabled" | ||
47 | #define QLA2XXX_INI_MODE_STR_ENABLED "enabled" | ||
48 | |||
49 | #define QLA2XXX_INI_MODE_EXCLUSIVE 0 | ||
50 | #define QLA2XXX_INI_MODE_DISABLED 1 | ||
51 | #define QLA2XXX_INI_MODE_ENABLED 2 | ||
52 | |||
53 | #define QLA2XXX_COMMAND_COUNT_INIT 250 | ||
54 | #define QLA2XXX_IMMED_NOTIFY_COUNT_INIT 250 | ||
55 | |||
56 | /* | ||
57 | * Used to mark which completion handles (for RIO Status's) are for CTIO's | ||
58 | * vs. regular (non-target) info. This is checked for in | ||
59 | * qla2x00_process_response_queue() to see if a handle coming back in a | ||
60 | * multi-complete should come to the tgt driver or be handled there by qla2xxx | ||
61 | */ | ||
62 | #define CTIO_COMPLETION_HANDLE_MARK BIT_29 | ||
63 | #if (CTIO_COMPLETION_HANDLE_MARK <= MAX_OUTSTANDING_COMMANDS) | ||
64 | #error "CTIO_COMPLETION_HANDLE_MARK not larger than MAX_OUTSTANDING_COMMANDS" | ||
65 | #endif | ||
66 | #define HANDLE_IS_CTIO_COMP(h) (h & CTIO_COMPLETION_HANDLE_MARK) | ||
67 | |||
68 | /* Used to mark CTIO as intermediate */ | ||
69 | #define CTIO_INTERMEDIATE_HANDLE_MARK BIT_30 | ||
70 | |||
71 | #ifndef OF_SS_MODE_0 | ||
72 | /* | ||
73 | * ISP target entries - Flags bit definitions. | ||
74 | */ | ||
75 | #define OF_SS_MODE_0 0 | ||
76 | #define OF_SS_MODE_1 1 | ||
77 | #define OF_SS_MODE_2 2 | ||
78 | #define OF_SS_MODE_3 3 | ||
79 | |||
80 | #define OF_EXPL_CONF BIT_5 /* Explicit Confirmation Requested */ | ||
81 | #define OF_DATA_IN BIT_6 /* Data in to initiator */ | ||
82 | /* (data from target to initiator) */ | ||
83 | #define OF_DATA_OUT BIT_7 /* Data out from initiator */ | ||
84 | /* (data from initiator to target) */ | ||
85 | #define OF_NO_DATA (BIT_7 | BIT_6) | ||
86 | #define OF_INC_RC BIT_8 /* Increment command resource count */ | ||
87 | #define OF_FAST_POST BIT_9 /* Enable mailbox fast posting. */ | ||
88 | #define OF_CONF_REQ BIT_13 /* Confirmation Requested */ | ||
89 | #define OF_TERM_EXCH BIT_14 /* Terminate exchange */ | ||
90 | #define OF_SSTS BIT_15 /* Send SCSI status */ | ||
91 | #endif | ||
92 | |||
93 | #ifndef QLA_TGT_DATASEGS_PER_CMD32 | ||
94 | #define QLA_TGT_DATASEGS_PER_CMD32 3 | ||
95 | #define QLA_TGT_DATASEGS_PER_CONT32 7 | ||
96 | #define QLA_TGT_MAX_SG32(ql) \ | ||
97 | (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD32 + \ | ||
98 | QLA_TGT_DATASEGS_PER_CONT32*((ql) - 1)) : 0) | ||
99 | |||
100 | #define QLA_TGT_DATASEGS_PER_CMD64 2 | ||
101 | #define QLA_TGT_DATASEGS_PER_CONT64 5 | ||
102 | #define QLA_TGT_MAX_SG64(ql) \ | ||
103 | (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD64 + \ | ||
104 | QLA_TGT_DATASEGS_PER_CONT64*((ql) - 1)) : 0) | ||
105 | #endif | ||
106 | |||
107 | #ifndef QLA_TGT_DATASEGS_PER_CMD_24XX | ||
108 | #define QLA_TGT_DATASEGS_PER_CMD_24XX 1 | ||
109 | #define QLA_TGT_DATASEGS_PER_CONT_24XX 5 | ||
110 | #define QLA_TGT_MAX_SG_24XX(ql) \ | ||
111 | (min(1270, ((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD_24XX + \ | ||
112 | QLA_TGT_DATASEGS_PER_CONT_24XX*((ql) - 1)) : 0)) | ||
113 | #endif | ||
114 | #endif | ||
115 | |||
116 | #define GET_TARGET_ID(ha, iocb) ((HAS_EXTENDED_IDS(ha)) \ | ||
117 | ? le16_to_cpu((iocb)->u.isp2x.target.extended) \ | ||
118 | : (uint16_t)(iocb)->u.isp2x.target.id.standard) | ||
119 | |||
120 | #ifndef IMMED_NOTIFY_TYPE | ||
121 | #define IMMED_NOTIFY_TYPE 0x0D /* Immediate notify entry. */ | ||
122 | /* | ||
123 | * ISP queue - immediate notify entry structure definition. | ||
124 | * This is sent by the ISP to the Target driver. | ||
125 | * This IOCB would have report of events sent by the | ||
126 | * initiator, that needs to be handled by the target | ||
127 | * driver immediately. | ||
128 | */ | ||
129 | struct imm_ntfy_from_isp { | ||
130 | uint8_t entry_type; /* Entry type. */ | ||
131 | uint8_t entry_count; /* Entry count. */ | ||
132 | uint8_t sys_define; /* System defined. */ | ||
133 | uint8_t entry_status; /* Entry Status. */ | ||
134 | union { | ||
135 | struct { | ||
136 | uint32_t sys_define_2; /* System defined. */ | ||
137 | target_id_t target; | ||
138 | uint16_t lun; | ||
139 | uint8_t target_id; | ||
140 | uint8_t reserved_1; | ||
141 | uint16_t status_modifier; | ||
142 | uint16_t status; | ||
143 | uint16_t task_flags; | ||
144 | uint16_t seq_id; | ||
145 | uint16_t srr_rx_id; | ||
146 | uint32_t srr_rel_offs; | ||
147 | uint16_t srr_ui; | ||
148 | #define SRR_IU_DATA_IN 0x1 | ||
149 | #define SRR_IU_DATA_OUT 0x5 | ||
150 | #define SRR_IU_STATUS 0x7 | ||
151 | uint16_t srr_ox_id; | ||
152 | uint8_t reserved_2[28]; | ||
153 | } isp2x; | ||
154 | struct { | ||
155 | uint32_t reserved; | ||
156 | uint16_t nport_handle; | ||
157 | uint16_t reserved_2; | ||
158 | uint16_t flags; | ||
159 | #define NOTIFY24XX_FLAGS_GLOBAL_TPRLO BIT_1 | ||
160 | #define NOTIFY24XX_FLAGS_PUREX_IOCB BIT_0 | ||
161 | uint16_t srr_rx_id; | ||
162 | uint16_t status; | ||
163 | uint8_t status_subcode; | ||
164 | uint8_t reserved_3; | ||
165 | uint32_t exchange_address; | ||
166 | uint32_t srr_rel_offs; | ||
167 | uint16_t srr_ui; | ||
168 | uint16_t srr_ox_id; | ||
169 | uint8_t reserved_4[19]; | ||
170 | uint8_t vp_index; | ||
171 | uint32_t reserved_5; | ||
172 | uint8_t port_id[3]; | ||
173 | uint8_t reserved_6; | ||
174 | } isp24; | ||
175 | } u; | ||
176 | uint16_t reserved_7; | ||
177 | uint16_t ox_id; | ||
178 | } __packed; | ||
179 | #endif | ||
180 | |||
181 | #ifndef NOTIFY_ACK_TYPE | ||
182 | #define NOTIFY_ACK_TYPE 0x0E /* Notify acknowledge entry. */ | ||
183 | /* | ||
184 | * ISP queue - notify acknowledge entry structure definition. | ||
185 | * This is sent to the ISP from the target driver. | ||
186 | */ | ||
187 | struct nack_to_isp { | ||
188 | uint8_t entry_type; /* Entry type. */ | ||
189 | uint8_t entry_count; /* Entry count. */ | ||
190 | uint8_t sys_define; /* System defined. */ | ||
191 | uint8_t entry_status; /* Entry Status. */ | ||
192 | union { | ||
193 | struct { | ||
194 | uint32_t sys_define_2; /* System defined. */ | ||
195 | target_id_t target; | ||
196 | uint8_t target_id; | ||
197 | uint8_t reserved_1; | ||
198 | uint16_t flags; | ||
199 | uint16_t resp_code; | ||
200 | uint16_t status; | ||
201 | uint16_t task_flags; | ||
202 | uint16_t seq_id; | ||
203 | uint16_t srr_rx_id; | ||
204 | uint32_t srr_rel_offs; | ||
205 | uint16_t srr_ui; | ||
206 | uint16_t srr_flags; | ||
207 | uint16_t srr_reject_code; | ||
208 | uint8_t srr_reject_vendor_uniq; | ||
209 | uint8_t srr_reject_code_expl; | ||
210 | uint8_t reserved_2[24]; | ||
211 | } isp2x; | ||
212 | struct { | ||
213 | uint32_t handle; | ||
214 | uint16_t nport_handle; | ||
215 | uint16_t reserved_1; | ||
216 | uint16_t flags; | ||
217 | uint16_t srr_rx_id; | ||
218 | uint16_t status; | ||
219 | uint8_t status_subcode; | ||
220 | uint8_t reserved_3; | ||
221 | uint32_t exchange_address; | ||
222 | uint32_t srr_rel_offs; | ||
223 | uint16_t srr_ui; | ||
224 | uint16_t srr_flags; | ||
225 | uint8_t reserved_4[19]; | ||
226 | uint8_t vp_index; | ||
227 | uint8_t srr_reject_vendor_uniq; | ||
228 | uint8_t srr_reject_code_expl; | ||
229 | uint8_t srr_reject_code; | ||
230 | uint8_t reserved_5[5]; | ||
231 | } isp24; | ||
232 | } u; | ||
233 | uint8_t reserved[2]; | ||
234 | uint16_t ox_id; | ||
235 | } __packed; | ||
236 | #define NOTIFY_ACK_SRR_FLAGS_ACCEPT 0 | ||
237 | #define NOTIFY_ACK_SRR_FLAGS_REJECT 1 | ||
238 | |||
239 | #define NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM 0x9 | ||
240 | |||
241 | #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL 0 | ||
242 | #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_UNABLE_TO_SUPPLY_DATA 0x2a | ||
243 | |||
244 | #define NOTIFY_ACK_SUCCESS 0x01 | ||
245 | #endif | ||
246 | |||
247 | #ifndef ACCEPT_TGT_IO_TYPE | ||
248 | #define ACCEPT_TGT_IO_TYPE 0x16 /* Accept target I/O entry. */ | ||
249 | #endif | ||
250 | |||
251 | #ifndef CONTINUE_TGT_IO_TYPE | ||
252 | #define CONTINUE_TGT_IO_TYPE 0x17 | ||
253 | /* | ||
254 | * ISP queue - Continue Target I/O (CTIO) entry for status mode 0 structure. | ||
255 | * This structure is sent to the ISP 2xxx from target driver. | ||
256 | */ | ||
257 | struct ctio_to_2xxx { | ||
258 | uint8_t entry_type; /* Entry type. */ | ||
259 | uint8_t entry_count; /* Entry count. */ | ||
260 | uint8_t sys_define; /* System defined. */ | ||
261 | uint8_t entry_status; /* Entry Status. */ | ||
262 | uint32_t handle; /* System defined handle */ | ||
263 | target_id_t target; | ||
264 | uint16_t rx_id; | ||
265 | uint16_t flags; | ||
266 | uint16_t status; | ||
267 | uint16_t timeout; /* 0 = 30 seconds, 0xFFFF = disable */ | ||
268 | uint16_t dseg_count; /* Data segment count. */ | ||
269 | uint32_t relative_offset; | ||
270 | uint32_t residual; | ||
271 | uint16_t reserved_1[3]; | ||
272 | uint16_t scsi_status; | ||
273 | uint32_t transfer_length; | ||
274 | uint32_t dseg_0_address; /* Data segment 0 address. */ | ||
275 | uint32_t dseg_0_length; /* Data segment 0 length. */ | ||
276 | uint32_t dseg_1_address; /* Data segment 1 address. */ | ||
277 | uint32_t dseg_1_length; /* Data segment 1 length. */ | ||
278 | uint32_t dseg_2_address; /* Data segment 2 address. */ | ||
279 | uint32_t dseg_2_length; /* Data segment 2 length. */ | ||
280 | } __packed; | ||
281 | #define ATIO_PATH_INVALID 0x07 | ||
282 | #define ATIO_CANT_PROV_CAP 0x16 | ||
283 | #define ATIO_CDB_VALID 0x3D | ||
284 | |||
285 | #define ATIO_EXEC_READ BIT_1 | ||
286 | #define ATIO_EXEC_WRITE BIT_0 | ||
287 | #endif | ||
288 | |||
289 | #ifndef CTIO_A64_TYPE | ||
290 | #define CTIO_A64_TYPE 0x1F | ||
291 | #define CTIO_SUCCESS 0x01 | ||
292 | #define CTIO_ABORTED 0x02 | ||
293 | #define CTIO_INVALID_RX_ID 0x08 | ||
294 | #define CTIO_TIMEOUT 0x0B | ||
295 | #define CTIO_LIP_RESET 0x0E | ||
296 | #define CTIO_TARGET_RESET 0x17 | ||
297 | #define CTIO_PORT_UNAVAILABLE 0x28 | ||
298 | #define CTIO_PORT_LOGGED_OUT 0x29 | ||
299 | #define CTIO_PORT_CONF_CHANGED 0x2A | ||
300 | #define CTIO_SRR_RECEIVED 0x45 | ||
301 | #endif | ||
302 | |||
303 | #ifndef CTIO_RET_TYPE | ||
304 | #define CTIO_RET_TYPE 0x17 /* CTIO return entry */ | ||
305 | #define ATIO_TYPE7 0x06 /* Accept target I/O entry for 24xx */ | ||
306 | |||
307 | struct fcp_hdr { | ||
308 | uint8_t r_ctl; | ||
309 | uint8_t d_id[3]; | ||
310 | uint8_t cs_ctl; | ||
311 | uint8_t s_id[3]; | ||
312 | uint8_t type; | ||
313 | uint8_t f_ctl[3]; | ||
314 | uint8_t seq_id; | ||
315 | uint8_t df_ctl; | ||
316 | uint16_t seq_cnt; | ||
317 | uint16_t ox_id; | ||
318 | uint16_t rx_id; | ||
319 | uint32_t parameter; | ||
320 | } __packed; | ||
321 | |||
322 | struct fcp_hdr_le { | ||
323 | uint8_t d_id[3]; | ||
324 | uint8_t r_ctl; | ||
325 | uint8_t s_id[3]; | ||
326 | uint8_t cs_ctl; | ||
327 | uint8_t f_ctl[3]; | ||
328 | uint8_t type; | ||
329 | uint16_t seq_cnt; | ||
330 | uint8_t df_ctl; | ||
331 | uint8_t seq_id; | ||
332 | uint16_t rx_id; | ||
333 | uint16_t ox_id; | ||
334 | uint32_t parameter; | ||
335 | } __packed; | ||
336 | |||
337 | #define F_CTL_EXCH_CONTEXT_RESP BIT_23 | ||
338 | #define F_CTL_SEQ_CONTEXT_RESIP BIT_22 | ||
339 | #define F_CTL_LAST_SEQ BIT_20 | ||
340 | #define F_CTL_END_SEQ BIT_19 | ||
341 | #define F_CTL_SEQ_INITIATIVE BIT_16 | ||
342 | |||
343 | #define R_CTL_BASIC_LINK_SERV 0x80 | ||
344 | #define R_CTL_B_ACC 0x4 | ||
345 | #define R_CTL_B_RJT 0x5 | ||
346 | |||
347 | struct atio7_fcp_cmnd { | ||
348 | uint64_t lun; | ||
349 | uint8_t cmnd_ref; | ||
350 | uint8_t task_attr:3; | ||
351 | uint8_t reserved:5; | ||
352 | uint8_t task_mgmt_flags; | ||
353 | #define FCP_CMND_TASK_MGMT_CLEAR_ACA 6 | ||
354 | #define FCP_CMND_TASK_MGMT_TARGET_RESET 5 | ||
355 | #define FCP_CMND_TASK_MGMT_LU_RESET 4 | ||
356 | #define FCP_CMND_TASK_MGMT_CLEAR_TASK_SET 2 | ||
357 | #define FCP_CMND_TASK_MGMT_ABORT_TASK_SET 1 | ||
358 | uint8_t wrdata:1; | ||
359 | uint8_t rddata:1; | ||
360 | uint8_t add_cdb_len:6; | ||
361 | uint8_t cdb[16]; | ||
362 | /* | ||
363 | * add_cdb is optional and can absent from struct atio7_fcp_cmnd. Size 4 | ||
364 | * only to make sizeof(struct atio7_fcp_cmnd) be as expected by | ||
365 | * BUILD_BUG_ON in qlt_init(). | ||
366 | */ | ||
367 | uint8_t add_cdb[4]; | ||
368 | /* uint32_t data_length; */ | ||
369 | } __packed; | ||
370 | |||
371 | /* | ||
372 | * ISP queue - Accept Target I/O (ATIO) type entry IOCB structure. | ||
373 | * This is sent from the ISP to the target driver. | ||
374 | */ | ||
375 | struct atio_from_isp { | ||
376 | union { | ||
377 | struct { | ||
378 | uint16_t entry_hdr; | ||
379 | uint8_t sys_define; /* System defined. */ | ||
380 | uint8_t entry_status; /* Entry Status. */ | ||
381 | uint32_t sys_define_2; /* System defined. */ | ||
382 | target_id_t target; | ||
383 | uint16_t rx_id; | ||
384 | uint16_t flags; | ||
385 | uint16_t status; | ||
386 | uint8_t command_ref; | ||
387 | uint8_t task_codes; | ||
388 | uint8_t task_flags; | ||
389 | uint8_t execution_codes; | ||
390 | uint8_t cdb[MAX_CMDSZ]; | ||
391 | uint32_t data_length; | ||
392 | uint16_t lun; | ||
393 | uint8_t initiator_port_name[WWN_SIZE]; /* on qla23xx */ | ||
394 | uint16_t reserved_32[6]; | ||
395 | uint16_t ox_id; | ||
396 | } isp2x; | ||
397 | struct { | ||
398 | uint16_t entry_hdr; | ||
399 | uint8_t fcp_cmnd_len_low; | ||
400 | uint8_t fcp_cmnd_len_high:4; | ||
401 | uint8_t attr:4; | ||
402 | uint32_t exchange_addr; | ||
403 | #define ATIO_EXCHANGE_ADDRESS_UNKNOWN 0xFFFFFFFF | ||
404 | struct fcp_hdr fcp_hdr; | ||
405 | struct atio7_fcp_cmnd fcp_cmnd; | ||
406 | } isp24; | ||
407 | struct { | ||
408 | uint8_t entry_type; /* Entry type. */ | ||
409 | uint8_t entry_count; /* Entry count. */ | ||
410 | uint8_t data[58]; | ||
411 | uint32_t signature; | ||
412 | #define ATIO_PROCESSED 0xDEADDEAD /* Signature */ | ||
413 | } raw; | ||
414 | } u; | ||
415 | } __packed; | ||
416 | |||
417 | #define CTIO_TYPE7 0x12 /* Continue target I/O entry (for 24xx) */ | ||
418 | |||
419 | /* | ||
420 | * ISP queue - Continue Target I/O (ATIO) type 7 entry (for 24xx) structure. | ||
421 | * This structure is sent to the ISP 24xx from the target driver. | ||
422 | */ | ||
423 | |||
424 | struct ctio7_to_24xx { | ||
425 | uint8_t entry_type; /* Entry type. */ | ||
426 | uint8_t entry_count; /* Entry count. */ | ||
427 | uint8_t sys_define; /* System defined. */ | ||
428 | uint8_t entry_status; /* Entry Status. */ | ||
429 | uint32_t handle; /* System defined handle */ | ||
430 | uint16_t nport_handle; | ||
431 | #define CTIO7_NHANDLE_UNRECOGNIZED 0xFFFF | ||
432 | uint16_t timeout; | ||
433 | uint16_t dseg_count; /* Data segment count. */ | ||
434 | uint8_t vp_index; | ||
435 | uint8_t add_flags; | ||
436 | uint8_t initiator_id[3]; | ||
437 | uint8_t reserved; | ||
438 | uint32_t exchange_addr; | ||
439 | union { | ||
440 | struct { | ||
441 | uint16_t reserved1; | ||
442 | uint16_t flags; | ||
443 | uint32_t residual; | ||
444 | uint16_t ox_id; | ||
445 | uint16_t scsi_status; | ||
446 | uint32_t relative_offset; | ||
447 | uint32_t reserved2; | ||
448 | uint32_t transfer_length; | ||
449 | uint32_t reserved3; | ||
450 | /* Data segment 0 address. */ | ||
451 | uint32_t dseg_0_address[2]; | ||
452 | /* Data segment 0 length. */ | ||
453 | uint32_t dseg_0_length; | ||
454 | } status0; | ||
455 | struct { | ||
456 | uint16_t sense_length; | ||
457 | uint16_t flags; | ||
458 | uint32_t residual; | ||
459 | uint16_t ox_id; | ||
460 | uint16_t scsi_status; | ||
461 | uint16_t response_len; | ||
462 | uint16_t reserved; | ||
463 | uint8_t sense_data[24]; | ||
464 | } status1; | ||
465 | } u; | ||
466 | } __packed; | ||
467 | |||
468 | /* | ||
469 | * ISP queue - CTIO type 7 from ISP 24xx to target driver | ||
470 | * returned entry structure. | ||
471 | */ | ||
472 | struct ctio7_from_24xx { | ||
473 | uint8_t entry_type; /* Entry type. */ | ||
474 | uint8_t entry_count; /* Entry count. */ | ||
475 | uint8_t sys_define; /* System defined. */ | ||
476 | uint8_t entry_status; /* Entry Status. */ | ||
477 | uint32_t handle; /* System defined handle */ | ||
478 | uint16_t status; | ||
479 | uint16_t timeout; | ||
480 | uint16_t dseg_count; /* Data segment count. */ | ||
481 | uint8_t vp_index; | ||
482 | uint8_t reserved1[5]; | ||
483 | uint32_t exchange_address; | ||
484 | uint16_t reserved2; | ||
485 | uint16_t flags; | ||
486 | uint32_t residual; | ||
487 | uint16_t ox_id; | ||
488 | uint16_t reserved3; | ||
489 | uint32_t relative_offset; | ||
490 | uint8_t reserved4[24]; | ||
491 | } __packed; | ||
492 | |||
493 | /* CTIO7 flags values */ | ||
494 | #define CTIO7_FLAGS_SEND_STATUS BIT_15 | ||
495 | #define CTIO7_FLAGS_TERMINATE BIT_14 | ||
496 | #define CTIO7_FLAGS_CONFORM_REQ BIT_13 | ||
497 | #define CTIO7_FLAGS_DONT_RET_CTIO BIT_8 | ||
498 | #define CTIO7_FLAGS_STATUS_MODE_0 0 | ||
499 | #define CTIO7_FLAGS_STATUS_MODE_1 BIT_6 | ||
500 | #define CTIO7_FLAGS_EXPLICIT_CONFORM BIT_5 | ||
501 | #define CTIO7_FLAGS_CONFIRM_SATISF BIT_4 | ||
502 | #define CTIO7_FLAGS_DSD_PTR BIT_2 | ||
503 | #define CTIO7_FLAGS_DATA_IN BIT_1 | ||
504 | #define CTIO7_FLAGS_DATA_OUT BIT_0 | ||
505 | |||
506 | #define ELS_PLOGI 0x3 | ||
507 | #define ELS_FLOGI 0x4 | ||
508 | #define ELS_LOGO 0x5 | ||
509 | #define ELS_PRLI 0x20 | ||
510 | #define ELS_PRLO 0x21 | ||
511 | #define ELS_TPRLO 0x24 | ||
512 | #define ELS_PDISC 0x50 | ||
513 | #define ELS_ADISC 0x52 | ||
514 | |||
515 | /* | ||
516 | * ISP queue - ABTS received/response entries structure definition for 24xx. | ||
517 | */ | ||
518 | #define ABTS_RECV_24XX 0x54 /* ABTS received (for 24xx) */ | ||
519 | #define ABTS_RESP_24XX 0x55 /* ABTS responce (for 24xx) */ | ||
520 | |||
521 | /* | ||
522 | * ISP queue - ABTS received IOCB entry structure definition for 24xx. | ||
523 | * The ABTS BLS received from the wire is sent to the | ||
524 | * target driver by the ISP 24xx. | ||
525 | * The IOCB is placed on the response queue. | ||
526 | */ | ||
527 | struct abts_recv_from_24xx { | ||
528 | uint8_t entry_type; /* Entry type. */ | ||
529 | uint8_t entry_count; /* Entry count. */ | ||
530 | uint8_t sys_define; /* System defined. */ | ||
531 | uint8_t entry_status; /* Entry Status. */ | ||
532 | uint8_t reserved_1[6]; | ||
533 | uint16_t nport_handle; | ||
534 | uint8_t reserved_2[2]; | ||
535 | uint8_t vp_index; | ||
536 | uint8_t reserved_3:4; | ||
537 | uint8_t sof_type:4; | ||
538 | uint32_t exchange_address; | ||
539 | struct fcp_hdr_le fcp_hdr_le; | ||
540 | uint8_t reserved_4[16]; | ||
541 | uint32_t exchange_addr_to_abort; | ||
542 | } __packed; | ||
543 | |||
544 | #define ABTS_PARAM_ABORT_SEQ BIT_0 | ||
545 | |||
546 | struct ba_acc_le { | ||
547 | uint16_t reserved; | ||
548 | uint8_t seq_id_last; | ||
549 | uint8_t seq_id_valid; | ||
550 | #define SEQ_ID_VALID 0x80 | ||
551 | #define SEQ_ID_INVALID 0x00 | ||
552 | uint16_t rx_id; | ||
553 | uint16_t ox_id; | ||
554 | uint16_t high_seq_cnt; | ||
555 | uint16_t low_seq_cnt; | ||
556 | } __packed; | ||
557 | |||
558 | struct ba_rjt_le { | ||
559 | uint8_t vendor_uniq; | ||
560 | uint8_t reason_expl; | ||
561 | uint8_t reason_code; | ||
562 | #define BA_RJT_REASON_CODE_INVALID_COMMAND 0x1 | ||
563 | #define BA_RJT_REASON_CODE_UNABLE_TO_PERFORM 0x9 | ||
564 | uint8_t reserved; | ||
565 | } __packed; | ||
566 | |||
567 | /* | ||
568 | * ISP queue - ABTS Response IOCB entry structure definition for 24xx. | ||
569 | * The ABTS response to the ABTS received is sent by the | ||
570 | * target driver to the ISP 24xx. | ||
571 | * The IOCB is placed on the request queue. | ||
572 | */ | ||
573 | struct abts_resp_to_24xx { | ||
574 | uint8_t entry_type; /* Entry type. */ | ||
575 | uint8_t entry_count; /* Entry count. */ | ||
576 | uint8_t sys_define; /* System defined. */ | ||
577 | uint8_t entry_status; /* Entry Status. */ | ||
578 | uint32_t handle; | ||
579 | uint16_t reserved_1; | ||
580 | uint16_t nport_handle; | ||
581 | uint16_t control_flags; | ||
582 | #define ABTS_CONTR_FLG_TERM_EXCHG BIT_0 | ||
583 | uint8_t vp_index; | ||
584 | uint8_t reserved_3:4; | ||
585 | uint8_t sof_type:4; | ||
586 | uint32_t exchange_address; | ||
587 | struct fcp_hdr_le fcp_hdr_le; | ||
588 | union { | ||
589 | struct ba_acc_le ba_acct; | ||
590 | struct ba_rjt_le ba_rjt; | ||
591 | } __packed payload; | ||
592 | uint32_t reserved_4; | ||
593 | uint32_t exchange_addr_to_abort; | ||
594 | } __packed; | ||
595 | |||
596 | /* | ||
597 | * ISP queue - ABTS Response IOCB from ISP24xx Firmware entry structure. | ||
598 | * The ABTS response with completion status to the ABTS response | ||
599 | * (sent by the target driver to the ISP 24xx) is sent by the | ||
600 | * ISP24xx firmware to the target driver. | ||
601 | * The IOCB is placed on the response queue. | ||
602 | */ | ||
603 | struct abts_resp_from_24xx_fw { | ||
604 | uint8_t entry_type; /* Entry type. */ | ||
605 | uint8_t entry_count; /* Entry count. */ | ||
606 | uint8_t sys_define; /* System defined. */ | ||
607 | uint8_t entry_status; /* Entry Status. */ | ||
608 | uint32_t handle; | ||
609 | uint16_t compl_status; | ||
610 | #define ABTS_RESP_COMPL_SUCCESS 0 | ||
611 | #define ABTS_RESP_COMPL_SUBCODE_ERROR 0x31 | ||
612 | uint16_t nport_handle; | ||
613 | uint16_t reserved_1; | ||
614 | uint8_t reserved_2; | ||
615 | uint8_t reserved_3:4; | ||
616 | uint8_t sof_type:4; | ||
617 | uint32_t exchange_address; | ||
618 | struct fcp_hdr_le fcp_hdr_le; | ||
619 | uint8_t reserved_4[8]; | ||
620 | uint32_t error_subcode1; | ||
621 | #define ABTS_RESP_SUBCODE_ERR_ABORTED_EXCH_NOT_TERM 0x1E | ||
622 | uint32_t error_subcode2; | ||
623 | uint32_t exchange_addr_to_abort; | ||
624 | } __packed; | ||
625 | |||
626 | /********************************************************************\ | ||
627 | * Type Definitions used by initiator & target halves | ||
628 | \********************************************************************/ | ||
629 | |||
630 | struct qla_tgt_mgmt_cmd; | ||
631 | struct qla_tgt_sess; | ||
632 | |||
633 | /* | ||
634 | * This structure provides a template of function calls that the | ||
635 | * target driver (from within qla_target.c) can issue to the | ||
636 | * target module (tcm_qla2xxx). | ||
637 | */ | ||
638 | struct qla_tgt_func_tmpl { | ||
639 | |||
640 | int (*handle_cmd)(struct scsi_qla_host *, struct qla_tgt_cmd *, | ||
641 | unsigned char *, uint32_t, int, int, int); | ||
642 | int (*handle_data)(struct qla_tgt_cmd *); | ||
643 | int (*handle_tmr)(struct qla_tgt_mgmt_cmd *, uint32_t, uint8_t, | ||
644 | uint32_t); | ||
645 | void (*free_cmd)(struct qla_tgt_cmd *); | ||
646 | void (*free_mcmd)(struct qla_tgt_mgmt_cmd *); | ||
647 | void (*free_session)(struct qla_tgt_sess *); | ||
648 | |||
649 | int (*check_initiator_node_acl)(struct scsi_qla_host *, unsigned char *, | ||
650 | void *, uint8_t *, uint16_t); | ||
651 | struct qla_tgt_sess *(*find_sess_by_loop_id)(struct scsi_qla_host *, | ||
652 | const uint16_t); | ||
653 | struct qla_tgt_sess *(*find_sess_by_s_id)(struct scsi_qla_host *, | ||
654 | const uint8_t *); | ||
655 | void (*clear_nacl_from_fcport_map)(struct qla_tgt_sess *); | ||
656 | void (*put_sess)(struct qla_tgt_sess *); | ||
657 | void (*shutdown_sess)(struct qla_tgt_sess *); | ||
658 | }; | ||
659 | |||
660 | int qla2x00_wait_for_hba_online(struct scsi_qla_host *); | ||
661 | |||
662 | #include <target/target_core_base.h> | ||
663 | |||
664 | #define QLA_TGT_TIMEOUT 10 /* in seconds */ | ||
665 | |||
666 | #define QLA_TGT_MAX_HW_PENDING_TIME 60 /* in seconds */ | ||
667 | |||
668 | /* Immediate notify status constants */ | ||
669 | #define IMM_NTFY_LIP_RESET 0x000E | ||
670 | #define IMM_NTFY_LIP_LINK_REINIT 0x000F | ||
671 | #define IMM_NTFY_IOCB_OVERFLOW 0x0016 | ||
672 | #define IMM_NTFY_ABORT_TASK 0x0020 | ||
673 | #define IMM_NTFY_PORT_LOGOUT 0x0029 | ||
674 | #define IMM_NTFY_PORT_CONFIG 0x002A | ||
675 | #define IMM_NTFY_GLBL_TPRLO 0x002D | ||
676 | #define IMM_NTFY_GLBL_LOGO 0x002E | ||
677 | #define IMM_NTFY_RESOURCE 0x0034 | ||
678 | #define IMM_NTFY_MSG_RX 0x0036 | ||
679 | #define IMM_NTFY_SRR 0x0045 | ||
680 | #define IMM_NTFY_ELS 0x0046 | ||
681 | |||
682 | /* Immediate notify task flags */ | ||
683 | #define IMM_NTFY_TASK_MGMT_SHIFT 8 | ||
684 | |||
685 | #define QLA_TGT_CLEAR_ACA 0x40 | ||
686 | #define QLA_TGT_TARGET_RESET 0x20 | ||
687 | #define QLA_TGT_LUN_RESET 0x10 | ||
688 | #define QLA_TGT_CLEAR_TS 0x04 | ||
689 | #define QLA_TGT_ABORT_TS 0x02 | ||
690 | #define QLA_TGT_ABORT_ALL_SESS 0xFFFF | ||
691 | #define QLA_TGT_ABORT_ALL 0xFFFE | ||
692 | #define QLA_TGT_NEXUS_LOSS_SESS 0xFFFD | ||
693 | #define QLA_TGT_NEXUS_LOSS 0xFFFC | ||
694 | |||
695 | /* Notify Acknowledge flags */ | ||
696 | #define NOTIFY_ACK_RES_COUNT BIT_8 | ||
697 | #define NOTIFY_ACK_CLEAR_LIP_RESET BIT_5 | ||
698 | #define NOTIFY_ACK_TM_RESP_CODE_VALID BIT_4 | ||
699 | |||
700 | /* Command's states */ | ||
701 | #define QLA_TGT_STATE_NEW 0 /* New command + target processing */ | ||
702 | #define QLA_TGT_STATE_NEED_DATA 1 /* target needs data to continue */ | ||
703 | #define QLA_TGT_STATE_DATA_IN 2 /* Data arrived + target processing */ | ||
704 | #define QLA_TGT_STATE_PROCESSED 3 /* target done processing */ | ||
705 | #define QLA_TGT_STATE_ABORTED 4 /* Command aborted */ | ||
706 | |||
707 | /* Special handles */ | ||
708 | #define QLA_TGT_NULL_HANDLE 0 | ||
709 | #define QLA_TGT_SKIP_HANDLE (0xFFFFFFFF & ~CTIO_COMPLETION_HANDLE_MARK) | ||
710 | |||
711 | /* ATIO task_codes field */ | ||
712 | #define ATIO_SIMPLE_QUEUE 0 | ||
713 | #define ATIO_HEAD_OF_QUEUE 1 | ||
714 | #define ATIO_ORDERED_QUEUE 2 | ||
715 | #define ATIO_ACA_QUEUE 4 | ||
716 | #define ATIO_UNTAGGED 5 | ||
717 | |||
718 | /* TM failed response codes, see FCP (9.4.11 FCP_RSP_INFO) */ | ||
719 | #define FC_TM_SUCCESS 0 | ||
720 | #define FC_TM_BAD_FCP_DATA 1 | ||
721 | #define FC_TM_BAD_CMD 2 | ||
722 | #define FC_TM_FCP_DATA_MISMATCH 3 | ||
723 | #define FC_TM_REJECT 4 | ||
724 | #define FC_TM_FAILED 5 | ||
725 | |||
726 | /* | ||
727 | * Error code of qlt_pre_xmit_response() meaning that cmd's exchange was | ||
728 | * terminated, so no more actions is needed and success should be returned | ||
729 | * to target. | ||
730 | */ | ||
731 | #define QLA_TGT_PRE_XMIT_RESP_CMD_ABORTED 0x1717 | ||
732 | |||
733 | #if (BITS_PER_LONG > 32) || defined(CONFIG_HIGHMEM64G) | ||
734 | #define pci_dma_lo32(a) (a & 0xffffffff) | ||
735 | #define pci_dma_hi32(a) ((((a) >> 16)>>16) & 0xffffffff) | ||
736 | #else | ||
737 | #define pci_dma_lo32(a) (a & 0xffffffff) | ||
738 | #define pci_dma_hi32(a) 0 | ||
739 | #endif | ||
740 | |||
741 | #define QLA_TGT_SENSE_VALID(sense) ((sense != NULL) && \ | ||
742 | (((const uint8_t *)(sense))[0] & 0x70) == 0x70) | ||
743 | |||
744 | struct qla_port_24xx_data { | ||
745 | uint8_t port_name[WWN_SIZE]; | ||
746 | uint16_t loop_id; | ||
747 | uint16_t reserved; | ||
748 | }; | ||
749 | |||
750 | struct qla_tgt { | ||
751 | struct scsi_qla_host *vha; | ||
752 | struct qla_hw_data *ha; | ||
753 | |||
754 | /* | ||
755 | * To sync between IRQ handlers and qlt_target_release(). Needed, | ||
756 | * because req_pkt() can drop/reaquire HW lock inside. Protected by | ||
757 | * HW lock. | ||
758 | */ | ||
759 | int irq_cmd_count; | ||
760 | |||
761 | int datasegs_per_cmd, datasegs_per_cont, sg_tablesize; | ||
762 | |||
763 | /* Target's flags, serialized by pha->hardware_lock */ | ||
764 | unsigned int tgt_enable_64bit_addr:1; /* 64-bits PCI addr enabled */ | ||
765 | unsigned int link_reinit_iocb_pending:1; | ||
766 | |||
767 | /* | ||
768 | * Protected by tgt_mutex AND hardware_lock for writing and tgt_mutex | ||
769 | * OR hardware_lock for reading. | ||
770 | */ | ||
771 | int tgt_stop; /* the target mode driver is being stopped */ | ||
772 | int tgt_stopped; /* the target mode driver has been stopped */ | ||
773 | |||
774 | /* Count of sessions refering qla_tgt. Protected by hardware_lock. */ | ||
775 | int sess_count; | ||
776 | |||
777 | /* Protected by hardware_lock. Addition also protected by tgt_mutex. */ | ||
778 | struct list_head sess_list; | ||
779 | |||
780 | /* Protected by hardware_lock */ | ||
781 | struct list_head del_sess_list; | ||
782 | struct delayed_work sess_del_work; | ||
783 | |||
784 | spinlock_t sess_work_lock; | ||
785 | struct list_head sess_works_list; | ||
786 | struct work_struct sess_work; | ||
787 | |||
788 | struct imm_ntfy_from_isp link_reinit_iocb; | ||
789 | wait_queue_head_t waitQ; | ||
790 | int notify_ack_expected; | ||
791 | int abts_resp_expected; | ||
792 | int modify_lun_expected; | ||
793 | |||
794 | int ctio_srr_id; | ||
795 | int imm_srr_id; | ||
796 | spinlock_t srr_lock; | ||
797 | struct list_head srr_ctio_list; | ||
798 | struct list_head srr_imm_list; | ||
799 | struct work_struct srr_work; | ||
800 | |||
801 | atomic_t tgt_global_resets_count; | ||
802 | |||
803 | struct list_head tgt_list_entry; | ||
804 | }; | ||
805 | |||
806 | /* | ||
807 | * Equivilant to IT Nexus (Initiator-Target) | ||
808 | */ | ||
809 | struct qla_tgt_sess { | ||
810 | uint16_t loop_id; | ||
811 | port_id_t s_id; | ||
812 | |||
813 | unsigned int conf_compl_supported:1; | ||
814 | unsigned int deleted:1; | ||
815 | unsigned int local:1; | ||
816 | unsigned int tearing_down:1; | ||
817 | |||
818 | struct se_session *se_sess; | ||
819 | struct scsi_qla_host *vha; | ||
820 | struct qla_tgt *tgt; | ||
821 | |||
822 | struct list_head sess_list_entry; | ||
823 | unsigned long expires; | ||
824 | struct list_head del_list_entry; | ||
825 | |||
826 | uint8_t port_name[WWN_SIZE]; | ||
827 | struct work_struct free_work; | ||
828 | }; | ||
829 | |||
830 | struct qla_tgt_cmd { | ||
831 | struct qla_tgt_sess *sess; | ||
832 | int state; | ||
833 | struct se_cmd se_cmd; | ||
834 | struct work_struct free_work; | ||
835 | struct work_struct work; | ||
836 | /* Sense buffer that will be mapped into outgoing status */ | ||
837 | unsigned char sense_buffer[TRANSPORT_SENSE_BUFFER]; | ||
838 | |||
839 | /* to save extra sess dereferences */ | ||
840 | unsigned int conf_compl_supported:1; | ||
841 | unsigned int sg_mapped:1; | ||
842 | unsigned int free_sg:1; | ||
843 | unsigned int aborted:1; /* Needed in case of SRR */ | ||
844 | unsigned int write_data_transferred:1; | ||
845 | |||
846 | struct scatterlist *sg; /* cmd data buffer SG vector */ | ||
847 | int sg_cnt; /* SG segments count */ | ||
848 | int bufflen; /* cmd buffer length */ | ||
849 | int offset; | ||
850 | uint32_t tag; | ||
851 | uint32_t unpacked_lun; | ||
852 | enum dma_data_direction dma_data_direction; | ||
853 | |||
854 | uint16_t loop_id; /* to save extra sess dereferences */ | ||
855 | struct qla_tgt *tgt; /* to save extra sess dereferences */ | ||
856 | struct scsi_qla_host *vha; | ||
857 | struct list_head cmd_list; | ||
858 | |||
859 | struct atio_from_isp atio; | ||
860 | }; | ||
861 | |||
862 | struct qla_tgt_sess_work_param { | ||
863 | struct list_head sess_works_list_entry; | ||
864 | |||
865 | #define QLA_TGT_SESS_WORK_ABORT 1 | ||
866 | #define QLA_TGT_SESS_WORK_TM 2 | ||
867 | int type; | ||
868 | |||
869 | union { | ||
870 | struct abts_recv_from_24xx abts; | ||
871 | struct imm_ntfy_from_isp tm_iocb; | ||
872 | struct atio_from_isp tm_iocb2; | ||
873 | }; | ||
874 | }; | ||
875 | |||
876 | struct qla_tgt_mgmt_cmd { | ||
877 | uint8_t tmr_func; | ||
878 | uint8_t fc_tm_rsp; | ||
879 | struct qla_tgt_sess *sess; | ||
880 | struct se_cmd se_cmd; | ||
881 | struct work_struct free_work; | ||
882 | unsigned int flags; | ||
883 | #define QLA24XX_MGMT_SEND_NACK 1 | ||
884 | union { | ||
885 | struct atio_from_isp atio; | ||
886 | struct imm_ntfy_from_isp imm_ntfy; | ||
887 | struct abts_recv_from_24xx abts; | ||
888 | } __packed orig_iocb; | ||
889 | }; | ||
890 | |||
891 | struct qla_tgt_prm { | ||
892 | struct qla_tgt_cmd *cmd; | ||
893 | struct qla_tgt *tgt; | ||
894 | void *pkt; | ||
895 | struct scatterlist *sg; /* cmd data buffer SG vector */ | ||
896 | int seg_cnt; | ||
897 | int req_cnt; | ||
898 | uint16_t rq_result; | ||
899 | uint16_t scsi_status; | ||
900 | unsigned char *sense_buffer; | ||
901 | int sense_buffer_len; | ||
902 | int residual; | ||
903 | int add_status_pkt; | ||
904 | }; | ||
905 | |||
906 | struct qla_tgt_srr_imm { | ||
907 | struct list_head srr_list_entry; | ||
908 | int srr_id; | ||
909 | struct imm_ntfy_from_isp imm_ntfy; | ||
910 | }; | ||
911 | |||
912 | struct qla_tgt_srr_ctio { | ||
913 | struct list_head srr_list_entry; | ||
914 | int srr_id; | ||
915 | struct qla_tgt_cmd *cmd; | ||
916 | }; | ||
917 | |||
918 | #define QLA_TGT_XMIT_DATA 1 | ||
919 | #define QLA_TGT_XMIT_STATUS 2 | ||
920 | #define QLA_TGT_XMIT_ALL (QLA_TGT_XMIT_STATUS|QLA_TGT_XMIT_DATA) | ||
921 | |||
922 | #include <linux/version.h> | ||
923 | |||
924 | extern struct qla_tgt_data qla_target; | ||
925 | /* | ||
926 | * Internal function prototypes | ||
927 | */ | ||
928 | void qlt_disable_vha(struct scsi_qla_host *); | ||
929 | |||
930 | /* | ||
931 | * Function prototypes for qla_target.c logic used by qla2xxx LLD code. | ||
932 | */ | ||
933 | extern int qlt_add_target(struct qla_hw_data *, struct scsi_qla_host *); | ||
934 | extern int qlt_remove_target(struct qla_hw_data *, struct scsi_qla_host *); | ||
935 | extern int qlt_lport_register(struct qla_tgt_func_tmpl *, u64, | ||
936 | int (*callback)(struct scsi_qla_host *), void *); | ||
937 | extern void qlt_lport_deregister(struct scsi_qla_host *); | ||
938 | extern void qlt_unreg_sess(struct qla_tgt_sess *); | ||
939 | extern void qlt_fc_port_added(struct scsi_qla_host *, fc_port_t *); | ||
940 | extern void qlt_fc_port_deleted(struct scsi_qla_host *, fc_port_t *); | ||
941 | extern void qlt_set_mode(struct scsi_qla_host *ha); | ||
942 | extern void qlt_clear_mode(struct scsi_qla_host *ha); | ||
943 | extern int __init qlt_init(void); | ||
944 | extern void qlt_exit(void); | ||
945 | extern void qlt_update_vp_map(struct scsi_qla_host *, int); | ||
946 | |||
947 | /* | ||
948 | * This macro is used during early initializations when host->active_mode | ||
949 | * is not set. Right now, ha value is ignored. | ||
950 | */ | ||
951 | #define QLA_TGT_MODE_ENABLED() (ql2x_ini_mode != QLA2XXX_INI_MODE_ENABLED) | ||
952 | |||
953 | static inline bool qla_tgt_mode_enabled(struct scsi_qla_host *ha) | ||
954 | { | ||
955 | return ha->host->active_mode & MODE_TARGET; | ||
956 | } | ||
957 | |||
958 | static inline bool qla_ini_mode_enabled(struct scsi_qla_host *ha) | ||
959 | { | ||
960 | return ha->host->active_mode & MODE_INITIATOR; | ||
961 | } | ||
962 | |||
963 | static inline void qla_reverse_ini_mode(struct scsi_qla_host *ha) | ||
964 | { | ||
965 | if (ha->host->active_mode & MODE_INITIATOR) | ||
966 | ha->host->active_mode &= ~MODE_INITIATOR; | ||
967 | else | ||
968 | ha->host->active_mode |= MODE_INITIATOR; | ||
969 | } | ||
970 | |||
971 | /* | ||
972 | * Exported symbols from qla_target.c LLD logic used by qla2xxx code.. | ||
973 | */ | ||
974 | extern void qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host *, | ||
975 | struct atio_from_isp *); | ||
976 | extern void qlt_response_pkt_all_vps(struct scsi_qla_host *, response_t *); | ||
977 | extern int qlt_rdy_to_xfer(struct qla_tgt_cmd *); | ||
978 | extern int qlt_xmit_response(struct qla_tgt_cmd *, int, uint8_t); | ||
979 | extern void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *); | ||
980 | extern void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *); | ||
981 | extern void qlt_free_cmd(struct qla_tgt_cmd *cmd); | ||
982 | extern void qlt_ctio_completion(struct scsi_qla_host *, uint32_t); | ||
983 | extern void qlt_async_event(uint16_t, struct scsi_qla_host *, uint16_t *); | ||
984 | extern void qlt_enable_vha(struct scsi_qla_host *); | ||
985 | extern void qlt_vport_create(struct scsi_qla_host *, struct qla_hw_data *); | ||
986 | extern void qlt_rff_id(struct scsi_qla_host *, struct ct_sns_req *); | ||
987 | extern void qlt_init_atio_q_entries(struct scsi_qla_host *); | ||
988 | extern void qlt_24xx_process_atio_queue(struct scsi_qla_host *); | ||
989 | extern void qlt_24xx_config_rings(struct scsi_qla_host *, | ||
990 | device_reg_t __iomem *); | ||
991 | extern void qlt_24xx_config_nvram_stage1(struct scsi_qla_host *, | ||
992 | struct nvram_24xx *); | ||
993 | extern void qlt_24xx_config_nvram_stage2(struct scsi_qla_host *, | ||
994 | struct init_cb_24xx *); | ||
995 | extern int qlt_24xx_process_response_error(struct scsi_qla_host *, | ||
996 | struct sts_entry_24xx *); | ||
997 | extern void qlt_modify_vp_config(struct scsi_qla_host *, | ||
998 | struct vp_config_entry_24xx *); | ||
999 | extern void qlt_probe_one_stage1(struct scsi_qla_host *, struct qla_hw_data *); | ||
1000 | extern int qlt_mem_alloc(struct qla_hw_data *); | ||
1001 | extern void qlt_mem_free(struct qla_hw_data *); | ||
1002 | extern void qlt_stop_phase1(struct qla_tgt *); | ||
1003 | extern void qlt_stop_phase2(struct qla_tgt *); | ||
1004 | |||
1005 | #endif /* __QLA_TARGET_H */ | ||