hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/scsi/qla2xxx/qla_target.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx
34 *
....@@ -11,16 +12,6 @@
1112 * Forward port and refactoring to modern qla2xxx and target/configfs
1213 *
1314 * Copyright (C) 2010-2013 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.
2415 */
2516
2617 #include <linux/module.h>
....@@ -36,8 +27,6 @@
3627 #include <scsi/scsi.h>
3728 #include <scsi/scsi_host.h>
3829 #include <scsi/scsi_tcq.h>
39
-#include <target/target_core_base.h>
40
-#include <target/target_core_fabric.h>
4130
4231 #include "qla_def.h"
4332 #include "qla_target.h"
....@@ -141,6 +130,8 @@
141130 struct abts_recv_from_24xx *);
142131 static void qlt_send_busy(struct qla_qpair *, struct atio_from_isp *,
143132 uint16_t);
133
+static int qlt_check_reserve_free_req(struct qla_qpair *qpair, uint32_t);
134
+static inline uint32_t qlt_make_handle(struct qla_qpair *);
144135
145136 /*
146137 * Global Variables
....@@ -182,6 +173,7 @@
182173 /* Send marker if required */
183174 if (unlikely(vha->marker_needed != 0)) {
184175 int rc = qla2x00_issue_marker(vha, vha_locked);
176
+
185177 if (rc != QLA_SUCCESS) {
186178 ql_dbg(ql_dbg_tgt, vha, 0xe03d,
187179 "qla_target(%d): issue_marker() failed\n",
....@@ -194,18 +186,17 @@
194186
195187 static inline
196188 struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha,
197
- uint8_t *d_id)
189
+ be_id_t d_id)
198190 {
199191 struct scsi_qla_host *host;
200
- uint32_t key = 0;
192
+ uint32_t key;
201193
202
- if ((vha->d_id.b.area == d_id[1]) && (vha->d_id.b.domain == d_id[0]) &&
203
- (vha->d_id.b.al_pa == d_id[2]))
194
+ if (vha->d_id.b.area == d_id.area &&
195
+ vha->d_id.b.domain == d_id.domain &&
196
+ vha->d_id.b.al_pa == d_id.al_pa)
204197 return vha;
205198
206
- key = (uint32_t)d_id[0] << 16;
207
- key |= (uint32_t)d_id[1] << 8;
208
- key |= (uint32_t)d_id[2];
199
+ key = be_to_port_id(d_id).b24;
209200
210201 host = btree_lookup32(&vha->hw->tgt.host_map, key);
211202 if (!host)
....@@ -363,9 +354,9 @@
363354 ql_dbg(ql_dbg_tgt, vha, 0xe03e,
364355 "qla_target(%d): Received ATIO_TYPE7 "
365356 "with unknown d_id %x:%x:%x\n", vha->vp_idx,
366
- atio->u.isp24.fcp_hdr.d_id[0],
367
- atio->u.isp24.fcp_hdr.d_id[1],
368
- atio->u.isp24.fcp_hdr.d_id[2]);
357
+ atio->u.isp24.fcp_hdr.d_id.domain,
358
+ atio->u.isp24.fcp_hdr.d_id.area,
359
+ atio->u.isp24.fcp_hdr.d_id.al_pa);
369360
370361
371362 qlt_queue_unknown_atio(vha, atio, ha_locked);
....@@ -387,7 +378,7 @@
387378 qlt_issue_marker(vha, ha_locked);
388379
389380 if ((entry->u.isp24.vp_index != 0xFF) &&
390
- (entry->u.isp24.nport_handle != 0xFFFF)) {
381
+ (entry->u.isp24.nport_handle != cpu_to_le16(0xFFFF))) {
391382 host = qlt_find_host_by_vp_idx(vha,
392383 entry->u.isp24.vp_index);
393384 if (unlikely(!host)) {
....@@ -451,7 +442,7 @@
451442 ql_dbg(ql_dbg_tgt, vha, 0xe073,
452443 "qla_target(%d):%s: CRC2 Response pkt\n",
453444 vha->vp_idx, __func__);
454
- /* fall through */
445
+ fallthrough;
455446 case CTIO_TYPE7:
456447 {
457448 struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt;
....@@ -470,7 +461,7 @@
470461
471462 case IMMED_NOTIFY_TYPE:
472463 {
473
- struct scsi_qla_host *host = vha;
464
+ struct scsi_qla_host *host;
474465 struct imm_ntfy_from_isp *entry =
475466 (struct imm_ntfy_from_isp *)pkt;
476467
....@@ -541,7 +532,6 @@
541532 qlt_response_pkt(host, rsp, pkt);
542533 break;
543534 }
544
-
545535 default:
546536 qlt_response_pkt(vha, rsp, pkt);
547537 break;
....@@ -556,6 +546,7 @@
556546 struct imm_ntfy_from_isp *ntfy, int type)
557547 {
558548 struct qla_work_evt *e;
549
+
559550 e = qla2x00_alloc_work(vha, QLA_EVT_NACK);
560551 if (!e)
561552 return QLA_FUNCTION_FAILED;
....@@ -566,10 +557,8 @@
566557 return qla2x00_post_work(vha, e);
567558 }
568559
569
-static
570
-void qla2x00_async_nack_sp_done(void *s, int res)
560
+static void qla2x00_async_nack_sp_done(srb_t *sp, int res)
571561 {
572
- struct srb *sp = (struct srb *)s;
573562 struct scsi_qla_host *vha = sp->vha;
574563 unsigned long flags;
575564
....@@ -605,7 +594,8 @@
605594 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
606595 } else {
607596 sp->fcport->login_retry = 0;
608
- sp->fcport->disc_state = DSC_LOGIN_COMPLETE;
597
+ qla2x00_set_fcport_disc_state(sp->fcport,
598
+ DSC_LOGIN_COMPLETE);
609599 sp->fcport->deleted = 0;
610600 sp->fcport->logout_on_delete = 1;
611601 }
....@@ -659,13 +649,13 @@
659649 sp->u.iocb_cmd.u.nack.ntfy = ntfy;
660650 sp->done = qla2x00_async_nack_sp_done;
661651
662
- rval = qla2x00_start_sp(sp);
663
- if (rval != QLA_SUCCESS)
664
- goto done_free_sp;
665
-
666652 ql_dbg(ql_dbg_disc, vha, 0x20f4,
667653 "Async-%s %8phC hndl %x %s\n",
668654 sp->name, fcport->port_name, sp->handle, c);
655
+
656
+ rval = qla2x00_start_sp(sp);
657
+ if (rval != QLA_SUCCESS)
658
+ goto done_free_sp;
669659
670660 return rval;
671661
....@@ -682,6 +672,9 @@
682672
683673 switch (e->u.nack.type) {
684674 case SRB_NACK_PRLI:
675
+ t = e->u.nack.fcport;
676
+ flush_work(&t->del_work);
677
+ flush_work(&t->free_work);
685678 mutex_lock(&vha->vha_tgt.tgt_mutex);
686679 t = qlt_create_sess(vha, e->u.nack.fcport, 0);
687680 mutex_unlock(&vha->vha_tgt.tgt_mutex);
....@@ -694,7 +687,7 @@
694687 break;
695688 }
696689 qla24xx_async_notify_ack(vha, e->u.nack.fcport,
697
- (struct imm_ntfy_from_isp*)e->u.nack.iocb, e->u.nack.type);
690
+ (struct imm_ntfy_from_isp *)e->u.nack.iocb, e->u.nack.type);
698691 }
699692
700693 void qla24xx_delete_sess_fn(struct work_struct *work)
....@@ -791,6 +784,8 @@
791784 struct imm_ntfy_from_isp *iocb)
792785 {
793786 struct qlt_plogi_ack_t *pla;
787
+
788
+ lockdep_assert_held(&vha->hw->hardware_lock);
794789
795790 list_for_each_entry(pla, &vha->plogi_ack_list, list) {
796791 if (pla->id.b24 == id->b24) {
....@@ -957,11 +952,11 @@
957952 struct qla_hw_data *ha = vha->hw;
958953 unsigned long flags;
959954 bool logout_started = false;
960
- scsi_qla_host_t *base_vha;
955
+ scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
961956 struct qlt_plogi_ack_t *own =
962957 sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN];
963958
964
- ql_dbg(ql_dbg_tgt_mgt, vha, 0xf084,
959
+ ql_dbg(ql_dbg_disc, vha, 0xf084,
965960 "%s: se_sess %p / sess %p from port %8phC loop_id %#04x"
966961 " s_id %02x:%02x:%02x logout %d keep %d els_logo %d\n",
967962 __func__, sess->se_sess, sess, sess->port_name, sess->loop_id,
....@@ -970,7 +965,7 @@
970965 sess->send_els_logo);
971966
972967 if (!IS_SW_RESV_ADDR(sess->d_id)) {
973
- qla2x00_mark_device_lost(vha, sess, 0, 0);
968
+ qla2x00_mark_device_lost(vha, sess, 0);
974969
975970 if (sess->send_els_logo) {
976971 qlt_port_logo_t logo;
....@@ -1007,6 +1002,12 @@
10071002 else
10081003 logout_started = true;
10091004 }
1005
+ } /* if sess->logout_on_delete */
1006
+
1007
+ if (sess->nvme_flag & NVME_FLAG_REGISTERED &&
1008
+ !(sess->nvme_flag & NVME_FLAG_DELETING)) {
1009
+ sess->nvme_flag |= NVME_FLAG_DELETING;
1010
+ qla_nvme_unregister_remote_port(sess);
10101011 }
10111012 }
10121013
....@@ -1022,7 +1023,7 @@
10221023
10231024 while (!READ_ONCE(sess->logout_completed)) {
10241025 if (!traced) {
1025
- ql_dbg(ql_dbg_tgt_mgt, vha, 0xf086,
1026
+ ql_dbg(ql_dbg_disc, vha, 0xf086,
10261027 "%s: waiting for sess %p logout\n",
10271028 __func__, sess);
10281029 traced = true;
....@@ -1050,9 +1051,8 @@
10501051 tgt->sess_count--;
10511052 }
10521053
1053
- sess->disc_state = DSC_DELETED;
1054
+ qla2x00_set_fcport_disc_state(sess, DSC_DELETED);
10541055 sess->fw_login_state = DSC_LS_PORT_UNAVAIL;
1055
- sess->deleted = QLA_SESS_DELETED;
10561056
10571057 if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) {
10581058 vha->fcport_count--;
....@@ -1072,6 +1072,7 @@
10721072 struct qlt_plogi_ack_t *con =
10731073 sess->plogi_link[QLT_PLOGI_LINK_CONFLICT];
10741074 struct imm_ntfy_from_isp *iocb;
1075
+
10751076 own = sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN];
10761077
10771078 if (con) {
....@@ -1101,26 +1102,27 @@
11011102 }
11021103 }
11031104
1105
+ sess->explicit_logout = 0;
11041106 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
11051107
1106
- ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001,
1108
+ qla2x00_dfs_remove_rport(vha, sess);
1109
+
1110
+ spin_lock_irqsave(&vha->work_lock, flags);
1111
+ sess->flags &= ~FCF_ASYNC_SENT;
1112
+ sess->deleted = QLA_SESS_DELETED;
1113
+ sess->free_pending = 0;
1114
+ spin_unlock_irqrestore(&vha->work_lock, flags);
1115
+
1116
+ ql_dbg(ql_dbg_disc, vha, 0xf001,
11071117 "Unregistration of sess %p %8phC finished fcp_cnt %d\n",
11081118 sess, sess->port_name, vha->fcport_count);
11091119
11101120 if (tgt && (tgt->sess_count == 0))
11111121 wake_up_all(&tgt->waitQ);
11121122
1113
- if (vha->fcport_count == 0)
1114
- wake_up_all(&vha->fcport_waitQ);
1115
-
1116
- base_vha = pci_get_drvdata(ha->pdev);
1117
-
1118
- sess->free_pending = 0;
1119
-
1120
- if (test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags))
1121
- return;
1122
-
1123
- if ((!tgt || !tgt->tgt_stop) && !LOOP_TRANSITION(vha)) {
1123
+ if (!test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags) &&
1124
+ !(vha->vp_idx && test_bit(VPORT_DELETE, &vha->dpc_flags)) &&
1125
+ (!tgt || !tgt->tgt_stop) && !LOOP_TRANSITION(vha)) {
11241126 switch (vha->host->active_mode) {
11251127 case MODE_INITIATOR:
11261128 case MODE_DUAL:
....@@ -1133,6 +1135,9 @@
11331135 break;
11341136 }
11351137 }
1138
+
1139
+ if (vha->fcport_count == 0)
1140
+ wake_up_all(&vha->fcport_waitQ);
11361141 }
11371142
11381143 /* ha->tgt.sess_lock supposed to be held on entry */
....@@ -1151,24 +1156,22 @@
11511156 return;
11521157 }
11531158 sess->free_pending = 1;
1159
+ /*
1160
+ * Use FCF_ASYNC_SENT flag to block other cmds used in sess
1161
+ * management from being sent.
1162
+ */
1163
+ sess->flags |= FCF_ASYNC_SENT;
1164
+ sess->deleted = QLA_SESS_DELETION_IN_PROGRESS;
11541165 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
11551166
11561167 if (sess->se_sess)
11571168 vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess);
11581169
1159
- sess->deleted = QLA_SESS_DELETION_IN_PROGRESS;
1160
- sess->disc_state = DSC_DELETE_PEND;
1170
+ qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND);
11611171 sess->last_rscn_gen = sess->rscn_gen;
11621172 sess->last_login_gen = sess->login_gen;
11631173
1164
- if (sess->nvme_flag & NVME_FLAG_REGISTERED &&
1165
- !(sess->nvme_flag & NVME_FLAG_DELETING)) {
1166
- sess->nvme_flag |= NVME_FLAG_DELETING;
1167
- schedule_work(&sess->nvme_del_work);
1168
- } else {
1169
- INIT_WORK(&sess->free_work, qlt_free_session_done);
1170
- schedule_work(&sess->free_work);
1171
- }
1174
+ queue_work(sess->vha->hw->wq, &sess->free_work);
11721175 }
11731176 EXPORT_SYMBOL(qlt_unreg_sess);
11741177
....@@ -1257,9 +1260,6 @@
12571260 break;
12581261 }
12591262
1260
- if (sess->deleted == QLA_SESS_DELETED)
1261
- sess->logout_on_delete = 0;
1262
-
12631263 spin_lock_irqsave(&sess->vha->work_lock, flags);
12641264 if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) {
12651265 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
....@@ -1268,11 +1268,12 @@
12681268 sess->deleted = QLA_SESS_DELETION_IN_PROGRESS;
12691269 spin_unlock_irqrestore(&sess->vha->work_lock, flags);
12701270
1271
- sess->disc_state = DSC_DELETE_PEND;
1271
+ sess->prli_pend_timer = 0;
1272
+ qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND);
12721273
12731274 qla24xx_chk_fcp_state(sess);
12741275
1275
- ql_dbg(ql_dbg_tgt, sess->vha, 0xe001,
1276
+ ql_dbg(ql_dbg_disc, sess->vha, 0xe001,
12761277 "Scheduling sess %p for deletion %8phC\n",
12771278 sess, sess->port_name);
12781279
....@@ -1292,13 +1293,12 @@
12921293 /* At this point tgt could be already dead */
12931294 }
12941295
1295
-static int qla24xx_get_loop_id(struct scsi_qla_host *vha, const uint8_t *s_id,
1296
+static int qla24xx_get_loop_id(struct scsi_qla_host *vha, be_id_t s_id,
12961297 uint16_t *loop_id)
12971298 {
12981299 struct qla_hw_data *ha = vha->hw;
12991300 dma_addr_t gid_list_dma;
1300
- struct gid_list_info *gid_list;
1301
- char *id_iter;
1301
+ struct gid_list_info *gid_list, *gid;
13021302 int res, rc, i;
13031303 uint16_t entries;
13041304
....@@ -1321,18 +1321,17 @@
13211321 goto out_free_id_list;
13221322 }
13231323
1324
- id_iter = (char *)gid_list;
1324
+ gid = gid_list;
13251325 res = -ENOENT;
13261326 for (i = 0; i < entries; i++) {
1327
- struct gid_list_info *gid = (struct gid_list_info *)id_iter;
1328
- if ((gid->al_pa == s_id[2]) &&
1329
- (gid->area == s_id[1]) &&
1330
- (gid->domain == s_id[0])) {
1327
+ if (gid->al_pa == s_id.al_pa &&
1328
+ gid->area == s_id.area &&
1329
+ gid->domain == s_id.domain) {
13311330 *loop_id = le16_to_cpu(gid->loop_id);
13321331 res = 0;
13331332 break;
13341333 }
1335
- id_iter += ha->gid_list_info_size;
1334
+ gid = (void *)gid + ha->gid_list_info_size;
13361335 }
13371336
13381337 out_free_id_list:
....@@ -1491,27 +1490,14 @@
14911490 struct qla_hw_data *ha = tgt->ha;
14921491 unsigned long flags;
14931492
1493
+ mutex_lock(&ha->optrom_mutex);
14941494 mutex_lock(&qla_tgt_mutex);
1495
- if (!vha->fc_vport) {
1496
- struct Scsi_Host *sh = vha->host;
1497
- struct fc_host_attrs *fc_host = shost_to_fc_host(sh);
1498
- bool npiv_vports;
14991495
1500
- spin_lock_irqsave(sh->host_lock, flags);
1501
- npiv_vports = (fc_host->npiv_vports_inuse);
1502
- spin_unlock_irqrestore(sh->host_lock, flags);
1503
-
1504
- if (npiv_vports) {
1505
- mutex_unlock(&qla_tgt_mutex);
1506
- ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021,
1507
- "NPIV is in use. Can not stop target\n");
1508
- return -EPERM;
1509
- }
1510
- }
15111496 if (tgt->tgt_stop || tgt->tgt_stopped) {
15121497 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e,
15131498 "Already in tgt->tgt_stop or tgt_stopped state\n");
15141499 mutex_unlock(&qla_tgt_mutex);
1500
+ mutex_unlock(&ha->optrom_mutex);
15151501 return -EPERM;
15161502 }
15171503
....@@ -1549,6 +1535,8 @@
15491535
15501536 /* Wait for sessions to clear out (just in case) */
15511537 wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ);
1538
+ mutex_unlock(&ha->optrom_mutex);
1539
+
15521540 return 0;
15531541 }
15541542 EXPORT_SYMBOL(qlt_stop_phase1);
....@@ -1580,6 +1568,15 @@
15801568
15811569 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00c, "Stop of tgt %p finished\n",
15821570 tgt);
1571
+
1572
+ switch (vha->qlini_mode) {
1573
+ case QLA2XXX_INI_MODE_EXCLUSIVE:
1574
+ vha->flags.online = 1;
1575
+ set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1576
+ break;
1577
+ default:
1578
+ break;
1579
+ }
15831580 }
15841581 EXPORT_SYMBOL(qlt_stop_phase2);
15851582
....@@ -1593,11 +1590,10 @@
15931590 struct qla_qpair_hint *h;
15941591 struct qla_hw_data *ha = vha->hw;
15951592
1596
- if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stop &&
1597
- !tgt->tgt_stopped)
1593
+ if (!tgt->tgt_stop && !tgt->tgt_stopped)
15981594 qlt_stop_phase1(tgt);
15991595
1600
- if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stopped)
1596
+ if (!tgt->tgt_stopped)
16011597 qlt_stop_phase2(tgt);
16021598
16031599 for (i = 0; i < vha->hw->max_qpairs + 1; i++) {
....@@ -1706,7 +1702,7 @@
17061702 nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle;
17071703 if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) {
17081704 nack->u.isp24.flags = ntfy->u.isp24.flags &
1709
- cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB);
1705
+ cpu_to_le16(NOTIFY24XX_FLAGS_PUREX_IOCB);
17101706 }
17111707 nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id;
17121708 nack->u.isp24.status = ntfy->u.isp24.status;
....@@ -1729,6 +1725,91 @@
17291725 qla2x00_start_iocbs(vha, qpair->req);
17301726 }
17311727
1728
+static int qlt_build_abts_resp_iocb(struct qla_tgt_mgmt_cmd *mcmd)
1729
+{
1730
+ struct scsi_qla_host *vha = mcmd->vha;
1731
+ struct qla_hw_data *ha = vha->hw;
1732
+ struct abts_resp_to_24xx *resp;
1733
+ __le32 f_ctl;
1734
+ uint32_t h;
1735
+ uint8_t *p;
1736
+ int rc;
1737
+ struct abts_recv_from_24xx *abts = &mcmd->orig_iocb.abts;
1738
+ struct qla_qpair *qpair = mcmd->qpair;
1739
+
1740
+ ql_dbg(ql_dbg_tgt, vha, 0xe006,
1741
+ "Sending task mgmt ABTS response (ha=%p, status=%x)\n",
1742
+ ha, mcmd->fc_tm_rsp);
1743
+
1744
+ rc = qlt_check_reserve_free_req(qpair, 1);
1745
+ if (rc) {
1746
+ ql_dbg(ql_dbg_tgt, vha, 0xe04a,
1747
+ "qla_target(%d): %s failed: unable to allocate request packet\n",
1748
+ vha->vp_idx, __func__);
1749
+ return -EAGAIN;
1750
+ }
1751
+
1752
+ resp = (struct abts_resp_to_24xx *)qpair->req->ring_ptr;
1753
+ memset(resp, 0, sizeof(*resp));
1754
+
1755
+ h = qlt_make_handle(qpair);
1756
+ if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
1757
+ /*
1758
+ * CTIO type 7 from the firmware doesn't provide a way to
1759
+ * know the initiator's LOOP ID, hence we can't find
1760
+ * the session and, so, the command.
1761
+ */
1762
+ return -EAGAIN;
1763
+ } else {
1764
+ qpair->req->outstanding_cmds[h] = (srb_t *)mcmd;
1765
+ }
1766
+
1767
+ resp->handle = make_handle(qpair->req->id, h);
1768
+ resp->entry_type = ABTS_RESP_24XX;
1769
+ resp->entry_count = 1;
1770
+ resp->nport_handle = abts->nport_handle;
1771
+ resp->vp_index = vha->vp_idx;
1772
+ resp->sof_type = abts->sof_type;
1773
+ resp->exchange_address = abts->exchange_address;
1774
+ resp->fcp_hdr_le = abts->fcp_hdr_le;
1775
+ f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP |
1776
+ F_CTL_LAST_SEQ | F_CTL_END_SEQ |
1777
+ F_CTL_SEQ_INITIATIVE);
1778
+ p = (uint8_t *)&f_ctl;
1779
+ resp->fcp_hdr_le.f_ctl[0] = *p++;
1780
+ resp->fcp_hdr_le.f_ctl[1] = *p++;
1781
+ resp->fcp_hdr_le.f_ctl[2] = *p;
1782
+
1783
+ resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id;
1784
+ resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id;
1785
+
1786
+ resp->exchange_addr_to_abort = abts->exchange_addr_to_abort;
1787
+ if (mcmd->fc_tm_rsp == FCP_TMF_CMPL) {
1788
+ resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC;
1789
+ resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID;
1790
+ resp->payload.ba_acct.low_seq_cnt = 0x0000;
1791
+ resp->payload.ba_acct.high_seq_cnt = cpu_to_le16(0xFFFF);
1792
+ resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id;
1793
+ resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id;
1794
+ } else {
1795
+ resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT;
1796
+ resp->payload.ba_rjt.reason_code =
1797
+ BA_RJT_REASON_CODE_UNABLE_TO_PERFORM;
1798
+ /* Other bytes are zero */
1799
+ }
1800
+
1801
+ vha->vha_tgt.qla_tgt->abts_resp_expected++;
1802
+
1803
+ /* Memory Barrier */
1804
+ wmb();
1805
+ if (qpair->reqq_start_iocbs)
1806
+ qpair->reqq_start_iocbs(qpair);
1807
+ else
1808
+ qla2x00_start_iocbs(vha, qpair->req);
1809
+
1810
+ return rc;
1811
+}
1812
+
17321813 /*
17331814 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
17341815 */
....@@ -1739,7 +1820,7 @@
17391820 struct scsi_qla_host *vha = qpair->vha;
17401821 struct qla_hw_data *ha = vha->hw;
17411822 struct abts_resp_to_24xx *resp;
1742
- uint32_t f_ctl;
1823
+ __le32 f_ctl;
17431824 uint8_t *p;
17441825
17451826 ql_dbg(ql_dbg_tgt, vha, 0xe006,
....@@ -1756,6 +1837,7 @@
17561837 }
17571838
17581839 resp->entry_type = ABTS_RESP_24XX;
1840
+ resp->handle = QLA_TGT_SKIP_HANDLE;
17591841 resp->entry_count = 1;
17601842 resp->nport_handle = abts->nport_handle;
17611843 resp->vp_index = vha->vp_idx;
....@@ -1770,26 +1852,18 @@
17701852 resp->fcp_hdr_le.f_ctl[1] = *p++;
17711853 resp->fcp_hdr_le.f_ctl[2] = *p;
17721854 if (ids_reversed) {
1773
- resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.d_id[0];
1774
- resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.d_id[1];
1775
- resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.d_id[2];
1776
- resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.s_id[0];
1777
- resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.s_id[1];
1778
- resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.s_id[2];
1855
+ resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.d_id;
1856
+ resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.s_id;
17791857 } else {
1780
- resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.s_id[0];
1781
- resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.s_id[1];
1782
- resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.s_id[2];
1783
- resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.d_id[0];
1784
- resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.d_id[1];
1785
- resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.d_id[2];
1858
+ resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id;
1859
+ resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id;
17861860 }
17871861 resp->exchange_addr_to_abort = abts->exchange_addr_to_abort;
17881862 if (status == FCP_TMF_CMPL) {
17891863 resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC;
17901864 resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID;
17911865 resp->payload.ba_acct.low_seq_cnt = 0x0000;
1792
- resp->payload.ba_acct.high_seq_cnt = 0xFFFF;
1866
+ resp->payload.ba_acct.high_seq_cnt = cpu_to_le16(0xFFFF);
17931867 resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id;
17941868 resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id;
17951869 } else {
....@@ -1813,21 +1887,26 @@
18131887 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
18141888 */
18151889 static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha,
1816
- struct abts_resp_from_24xx_fw *entry)
1890
+ struct qla_qpair *qpair, response_t *pkt, struct qla_tgt_mgmt_cmd *mcmd)
18171891 {
18181892 struct ctio7_to_24xx *ctio;
1893
+ u16 tmp;
1894
+ struct abts_recv_from_24xx *entry;
18191895
1820
- ql_dbg(ql_dbg_tgt, vha, 0xe007,
1821
- "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha->hw);
1822
-
1823
- ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(
1824
- vha->hw->base_qpair, NULL);
1896
+ ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, NULL);
18251897 if (ctio == NULL) {
18261898 ql_dbg(ql_dbg_tgt, vha, 0xe04b,
18271899 "qla_target(%d): %s failed: unable to allocate "
18281900 "request packet\n", vha->vp_idx, __func__);
18291901 return;
18301902 }
1903
+
1904
+ if (mcmd)
1905
+ /* abts from remote port */
1906
+ entry = &mcmd->orig_iocb.abts;
1907
+ else
1908
+ /* abts from this driver. */
1909
+ entry = (struct abts_recv_from_24xx *)pkt;
18311910
18321911 /*
18331912 * We've got on entrance firmware's response on by us generated
....@@ -1840,56 +1919,44 @@
18401919 ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
18411920 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
18421921 ctio->vp_index = vha->vp_idx;
1843
- ctio->initiator_id[0] = entry->fcp_hdr_le.d_id[0];
1844
- ctio->initiator_id[1] = entry->fcp_hdr_le.d_id[1];
1845
- ctio->initiator_id[2] = entry->fcp_hdr_le.d_id[2];
18461922 ctio->exchange_addr = entry->exchange_addr_to_abort;
1847
- ctio->u.status1.flags = cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 |
1848
- CTIO7_FLAGS_TERMINATE);
1849
- ctio->u.status1.ox_id = cpu_to_le16(entry->fcp_hdr_le.ox_id);
1923
+ tmp = (CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_TERMINATE);
1924
+
1925
+ if (mcmd) {
1926
+ ctio->initiator_id = entry->fcp_hdr_le.s_id;
1927
+
1928
+ if (mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID)
1929
+ tmp |= (mcmd->abort_io_attr << 9);
1930
+ else if (qpair->retry_term_cnt & 1)
1931
+ tmp |= (0x4 << 9);
1932
+ } else {
1933
+ ctio->initiator_id = entry->fcp_hdr_le.d_id;
1934
+
1935
+ if (qpair->retry_term_cnt & 1)
1936
+ tmp |= (0x4 << 9);
1937
+ }
1938
+ ctio->u.status1.flags = cpu_to_le16(tmp);
1939
+ ctio->u.status1.ox_id = entry->fcp_hdr_le.ox_id;
1940
+
1941
+ ql_dbg(ql_dbg_tgt, vha, 0xe007,
1942
+ "Sending retry TERM EXCH CTIO7 flags %04xh oxid %04xh attr valid %x\n",
1943
+ le16_to_cpu(ctio->u.status1.flags),
1944
+ le16_to_cpu(ctio->u.status1.ox_id),
1945
+ (mcmd && mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID) ? 1 : 0);
18501946
18511947 /* Memory Barrier */
18521948 wmb();
1853
- qla2x00_start_iocbs(vha, vha->req);
1949
+ if (qpair->reqq_start_iocbs)
1950
+ qpair->reqq_start_iocbs(qpair);
1951
+ else
1952
+ qla2x00_start_iocbs(vha, qpair->req);
18541953
1855
- qlt_24xx_send_abts_resp(vha->hw->base_qpair,
1856
- (struct abts_recv_from_24xx *)entry,
1857
- FCP_TMF_CMPL, true);
1858
-}
1954
+ if (mcmd)
1955
+ qlt_build_abts_resp_iocb(mcmd);
1956
+ else
1957
+ qlt_24xx_send_abts_resp(qpair,
1958
+ (struct abts_recv_from_24xx *)entry, FCP_TMF_CMPL, true);
18591959
1860
-static int abort_cmd_for_tag(struct scsi_qla_host *vha, uint32_t tag)
1861
-{
1862
- struct qla_tgt_sess_op *op;
1863
- struct qla_tgt_cmd *cmd;
1864
- unsigned long flags;
1865
-
1866
- spin_lock_irqsave(&vha->cmd_list_lock, flags);
1867
- list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) {
1868
- if (tag == op->atio.u.isp24.exchange_addr) {
1869
- op->aborted = true;
1870
- spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
1871
- return 1;
1872
- }
1873
- }
1874
-
1875
- list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) {
1876
- if (tag == op->atio.u.isp24.exchange_addr) {
1877
- op->aborted = true;
1878
- spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
1879
- return 1;
1880
- }
1881
- }
1882
-
1883
- list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) {
1884
- if (tag == cmd->atio.u.isp24.exchange_addr) {
1885
- cmd->aborted = 1;
1886
- spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
1887
- return 1;
1888
- }
1889
- }
1890
- spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
1891
-
1892
- return 0;
18931960 }
18941961
18951962 /* drop cmds for the given lun
....@@ -1897,8 +1964,7 @@
18971964 * XXX does not go through the list of other port (which may have cmds
18981965 * for the same lun)
18991966 */
1900
-static void abort_cmds_for_lun(struct scsi_qla_host *vha,
1901
- u64 lun, uint8_t *s_id)
1967
+static void abort_cmds_for_lun(struct scsi_qla_host *vha, u64 lun, be_id_t s_id)
19021968 {
19031969 struct qla_tgt_sess_op *op;
19041970 struct qla_tgt_cmd *cmd;
....@@ -1964,13 +2030,13 @@
19642030 struct qla_tgt_mgmt_cmd *mcmd =
19652031 container_of(work, struct qla_tgt_mgmt_cmd, work);
19662032 struct qla_hw_data *ha = mcmd->vha->hw;
1967
- int rc = EIO;
2033
+ int rc;
19682034 uint32_t tag;
19692035 unsigned long flags;
19702036
19712037 switch (mcmd->tmr_func) {
19722038 case QLA_TGT_ABTS:
1973
- tag = mcmd->orig_iocb.abts.exchange_addr_to_abort;
2039
+ tag = le32_to_cpu(mcmd->orig_iocb.abts.exchange_addr_to_abort);
19742040 break;
19752041 default:
19762042 tag = 0;
....@@ -1984,9 +2050,8 @@
19842050 spin_lock_irqsave(mcmd->qpair->qp_lock_ptr, flags);
19852051 switch (mcmd->tmr_func) {
19862052 case QLA_TGT_ABTS:
1987
- qlt_24xx_send_abts_resp(mcmd->qpair,
1988
- &mcmd->orig_iocb.abts,
1989
- FCP_TMF_REJECTED, false);
2053
+ mcmd->fc_tm_rsp = FCP_TMF_REJECTED;
2054
+ qlt_build_abts_resp_iocb(mcmd);
19902055 break;
19912056 case QLA_TGT_LUN_RESET:
19922057 case QLA_TGT_CLEAR_TS:
....@@ -2021,12 +2086,6 @@
20212086 struct qla_tgt_mgmt_cmd *mcmd;
20222087 struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0];
20232088
2024
- if (abort_cmd_for_tag(vha, abts->exchange_addr_to_abort)) {
2025
- /* send TASK_ABORT response immediately */
2026
- qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_CMPL, false);
2027
- return 0;
2028
- }
2029
-
20302089 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f,
20312090 "qla_target(%d): task abort (tag=%d)\n",
20322091 vha->vp_idx, abts->exchange_addr_to_abort);
....@@ -2039,7 +2098,7 @@
20392098 return -ENOMEM;
20402099 }
20412100 memset(mcmd, 0, sizeof(*mcmd));
2042
-
2101
+ mcmd->cmd_type = TYPE_TGT_TMCMD;
20432102 mcmd->sess = sess;
20442103 memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts));
20452104 mcmd->reset_count = ha->base_qpair->chip_reset;
....@@ -2057,10 +2116,12 @@
20572116 struct qla_tgt_cmd *abort_cmd;
20582117
20592118 abort_cmd = ha->tgt.tgt_ops->find_cmd_by_tag(sess,
2060
- abts->exchange_addr_to_abort);
2119
+ le32_to_cpu(abts->exchange_addr_to_abort));
20612120 if (abort_cmd && abort_cmd->qpair) {
20622121 mcmd->qpair = abort_cmd->qpair;
20632122 mcmd->se_cmd.cpuid = abort_cmd->se_cmd.cpuid;
2123
+ mcmd->abort_io_attr = abort_cmd->atio.u.isp24.attr;
2124
+ mcmd->flags = QLA24XX_MGMT_ABORT_IO_ATTR_VALID;
20642125 }
20652126 }
20662127
....@@ -2078,8 +2139,8 @@
20782139 {
20792140 struct qla_hw_data *ha = vha->hw;
20802141 struct fc_port *sess;
2081
- uint32_t tag = abts->exchange_addr_to_abort;
2082
- uint8_t s_id[3];
2142
+ uint32_t tag = le32_to_cpu(abts->exchange_addr_to_abort);
2143
+ be_id_t s_id;
20832144 int rc;
20842145 unsigned long flags;
20852146
....@@ -2103,13 +2164,11 @@
21032164
21042165 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011,
21052166 "qla_target(%d): task abort (s_id=%x:%x:%x, "
2106
- "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id[2],
2107
- abts->fcp_hdr_le.s_id[1], abts->fcp_hdr_le.s_id[0], tag,
2167
+ "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id.domain,
2168
+ abts->fcp_hdr_le.s_id.area, abts->fcp_hdr_le.s_id.al_pa, tag,
21082169 le32_to_cpu(abts->fcp_hdr_le.parameter));
21092170
2110
- s_id[0] = abts->fcp_hdr_le.s_id[2];
2111
- s_id[1] = abts->fcp_hdr_le.s_id[1];
2112
- s_id[2] = abts->fcp_hdr_le.s_id[0];
2171
+ s_id = le_id_to_be(abts->fcp_hdr_le.s_id);
21132172
21142173 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
21152174 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
....@@ -2170,12 +2229,10 @@
21702229 ctio->entry_type = CTIO_TYPE7;
21712230 ctio->entry_count = 1;
21722231 ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
2173
- ctio->nport_handle = mcmd->sess->loop_id;
2232
+ ctio->nport_handle = cpu_to_le16(mcmd->sess->loop_id);
21742233 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
21752234 ctio->vp_index = ha->vp_idx;
2176
- ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2];
2177
- ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1];
2178
- ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0];
2235
+ ctio->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
21792236 ctio->exchange_addr = atio->u.isp24.exchange_addr;
21802237 temp = (atio->u.isp24.attr << 9)|
21812238 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS;
....@@ -2229,12 +2286,10 @@
22292286 ctio->entry_type = CTIO_TYPE7;
22302287 ctio->entry_count = 1;
22312288 ctio->handle = QLA_TGT_SKIP_HANDLE;
2232
- ctio->nport_handle = cmd->sess->loop_id;
2289
+ ctio->nport_handle = cpu_to_le16(cmd->sess->loop_id);
22332290 ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
22342291 ctio->vp_index = vha->vp_idx;
2235
- ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2];
2236
- ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1];
2237
- ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0];
2292
+ ctio->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
22382293 ctio->exchange_addr = atio->u.isp24.exchange_addr;
22392294 temp = (atio->u.isp24.attr << 9) |
22402295 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS;
....@@ -2278,6 +2333,7 @@
22782333 struct qla_hw_data *ha = vha->hw;
22792334 unsigned long flags;
22802335 struct qla_qpair *qpair = mcmd->qpair;
2336
+ bool free_mcmd = true;
22812337
22822338 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013,
22832339 "TM response mcmd (%p) status %#x state %#x",
....@@ -2300,26 +2356,26 @@
23002356 }
23012357
23022358 if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) {
2303
- if (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode ==
2304
- ELS_LOGO ||
2305
- mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode ==
2306
- ELS_PRLO ||
2307
- mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode ==
2308
- ELS_TPRLO) {
2359
+ switch (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode) {
2360
+ case ELS_LOGO:
2361
+ case ELS_PRLO:
2362
+ case ELS_TPRLO:
23092363 ql_dbg(ql_dbg_disc, vha, 0x2106,
23102364 "TM response logo %8phC status %#x state %#x",
23112365 mcmd->sess->port_name, mcmd->fc_tm_rsp,
23122366 mcmd->flags);
23132367 qlt_schedule_sess_for_deletion(mcmd->sess);
2314
- } else {
2368
+ break;
2369
+ default:
23152370 qlt_send_notify_ack(vha->hw->base_qpair,
23162371 &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0);
2372
+ break;
23172373 }
23182374 } else {
2319
- if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX)
2320
- qlt_24xx_send_abts_resp(qpair, &mcmd->orig_iocb.abts,
2321
- mcmd->fc_tm_rsp, false);
2322
- else
2375
+ if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) {
2376
+ qlt_build_abts_resp_iocb(mcmd);
2377
+ free_mcmd = false;
2378
+ } else
23232379 qlt_24xx_send_task_mgmt_ctio(qpair, mcmd,
23242380 mcmd->fc_tm_rsp);
23252381 }
....@@ -2331,7 +2387,9 @@
23312387 * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() ->
23322388 * qlt_xmit_tm_rsp() returns here..
23332389 */
2334
- ha->tgt.tgt_ops->free_mcmd(mcmd);
2390
+ if (free_mcmd)
2391
+ ha->tgt.tgt_ops->free_mcmd(mcmd);
2392
+
23352393 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
23362394 }
23372395 EXPORT_SYMBOL(qlt_xmit_tm_rsp);
....@@ -2344,7 +2402,7 @@
23442402 BUG_ON(cmd->sg_cnt == 0);
23452403
23462404 prm->sg = (struct scatterlist *)cmd->sg;
2347
- prm->seg_cnt = pci_map_sg(cmd->qpair->pdev, cmd->sg,
2405
+ prm->seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, cmd->sg,
23482406 cmd->sg_cnt, cmd->dma_data_direction);
23492407 if (unlikely(prm->seg_cnt == 0))
23502408 goto out_err;
....@@ -2371,7 +2429,7 @@
23712429
23722430 if (cmd->prot_sg_cnt) {
23732431 prm->prot_sg = cmd->prot_sg;
2374
- prm->prot_seg_cnt = pci_map_sg(cmd->qpair->pdev,
2432
+ prm->prot_seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev,
23752433 cmd->prot_sg, cmd->prot_sg_cnt,
23762434 cmd->dma_data_direction);
23772435 if (unlikely(prm->prot_seg_cnt == 0))
....@@ -2401,17 +2459,18 @@
24012459 {
24022460 struct qla_hw_data *ha;
24032461 struct qla_qpair *qpair;
2462
+
24042463 if (!cmd->sg_mapped)
24052464 return;
24062465
24072466 qpair = cmd->qpair;
24082467
2409
- pci_unmap_sg(qpair->pdev, cmd->sg, cmd->sg_cnt,
2468
+ dma_unmap_sg(&qpair->pdev->dev, cmd->sg, cmd->sg_cnt,
24102469 cmd->dma_data_direction);
24112470 cmd->sg_mapped = 0;
24122471
24132472 if (cmd->prot_sg_cnt)
2414
- pci_unmap_sg(qpair->pdev, cmd->prot_sg, cmd->prot_sg_cnt,
2473
+ dma_unmap_sg(&qpair->pdev->dev, cmd->prot_sg, cmd->prot_sg_cnt,
24152474 cmd->dma_data_direction);
24162475
24172476 if (!cmd->ctx)
....@@ -2431,7 +2490,7 @@
24312490
24322491 if (req->cnt < (req_cnt + 2)) {
24332492 cnt = (uint16_t)(qpair->use_shadow_reg ? *req->out_ptr :
2434
- RD_REG_DWORD_RELAXED(req->req_q_out));
2493
+ rd_reg_dword_relaxed(req->req_q_out));
24352494
24362495 if (req->ring_index < cnt)
24372496 req->cnt = cnt - req->ring_index;
....@@ -2527,13 +2586,11 @@
25272586 } else
25282587 qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd;
25292588
2530
- pkt->handle = MAKE_HANDLE(qpair->req->id, h);
2589
+ pkt->handle = make_handle(qpair->req->id, h);
25312590 pkt->handle |= CTIO_COMPLETION_HANDLE_MARK;
25322591 pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id);
25332592 pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
2534
- pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2];
2535
- pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1];
2536
- pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0];
2593
+ pkt->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
25372594 pkt->exchange_addr = atio->u.isp24.exchange_addr;
25382595 temp = atio->u.isp24.attr << 9;
25392596 pkt->u.status0.flags |= cpu_to_le16(temp);
....@@ -2551,7 +2608,7 @@
25512608 static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm)
25522609 {
25532610 int cnt;
2554
- uint32_t *dword_ptr;
2611
+ struct dsd64 *cur_dsd;
25552612
25562613 /* Build continuation packets */
25572614 while (prm->seg_cnt > 0) {
....@@ -2572,19 +2629,13 @@
25722629 cont_pkt64->sys_define = 0;
25732630
25742631 cont_pkt64->entry_type = CONTINUE_A64_TYPE;
2575
- dword_ptr = (uint32_t *)&cont_pkt64->dseg_0_address;
2632
+ cur_dsd = cont_pkt64->dsd;
25762633
25772634 /* Load continuation entry data segments */
25782635 for (cnt = 0;
25792636 cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt;
25802637 cnt++, prm->seg_cnt--) {
2581
- *dword_ptr++ =
2582
- cpu_to_le32(pci_dma_lo32
2583
- (sg_dma_address(prm->sg)));
2584
- *dword_ptr++ = cpu_to_le32(pci_dma_hi32
2585
- (sg_dma_address(prm->sg)));
2586
- *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg));
2587
-
2638
+ append_dsd64(&cur_dsd, prm->sg);
25882639 prm->sg = sg_next(prm->sg);
25892640 }
25902641 }
....@@ -2597,13 +2648,13 @@
25972648 static void qlt_load_data_segments(struct qla_tgt_prm *prm)
25982649 {
25992650 int cnt;
2600
- uint32_t *dword_ptr;
2651
+ struct dsd64 *cur_dsd;
26012652 struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt;
26022653
26032654 pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen);
26042655
26052656 /* Setup packet address segment pointer */
2606
- dword_ptr = pkt24->u.status0.dseg_0_address;
2657
+ cur_dsd = &pkt24->u.status0.dsd;
26072658
26082659 /* Set total data segment count */
26092660 if (prm->seg_cnt)
....@@ -2611,8 +2662,8 @@
26112662
26122663 if (prm->seg_cnt == 0) {
26132664 /* No data transfer */
2614
- *dword_ptr++ = 0;
2615
- *dword_ptr = 0;
2665
+ cur_dsd->address = 0;
2666
+ cur_dsd->length = 0;
26162667 return;
26172668 }
26182669
....@@ -2622,14 +2673,7 @@
26222673 for (cnt = 0;
26232674 (cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt;
26242675 cnt++, prm->seg_cnt--) {
2625
- *dword_ptr++ =
2626
- cpu_to_le32(pci_dma_lo32(sg_dma_address(prm->sg)));
2627
-
2628
- *dword_ptr++ = cpu_to_le32(pci_dma_hi32(
2629
- sg_dma_address(prm->sg)));
2630
-
2631
- *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg));
2632
-
2676
+ append_dsd64(&cur_dsd, prm->sg);
26332677 prm->sg = sg_next(prm->sg);
26342678 }
26352679
....@@ -2802,10 +2846,14 @@
28022846 cpu_to_le16(SS_SENSE_LEN_VALID);
28032847 ctio->u.status1.sense_length =
28042848 cpu_to_le16(prm->sense_buffer_len);
2805
- for (i = 0; i < prm->sense_buffer_len/4; i++)
2806
- ((uint32_t *)ctio->u.status1.sense_data)[i] =
2807
- cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]);
2849
+ for (i = 0; i < prm->sense_buffer_len/4; i++) {
2850
+ uint32_t v;
28082851
2852
+ v = get_unaligned_be32(
2853
+ &((uint32_t *)prm->sense_buffer)[i]);
2854
+ put_unaligned_le32(v,
2855
+ &((uint32_t *)ctio->u.status1.sense_data)[i]);
2856
+ }
28092857 qlt_print_dif_err(prm);
28102858
28112859 } else {
....@@ -2953,7 +3001,7 @@
29533001 static inline int
29543002 qlt_build_ctio_crc2_pkt(struct qla_qpair *qpair, struct qla_tgt_prm *prm)
29553003 {
2956
- uint32_t *cur_dsd;
3004
+ struct dsd64 *cur_dsd;
29573005 uint32_t transfer_length = 0;
29583006 uint32_t data_bytes;
29593007 uint32_t dif_bytes;
....@@ -3055,13 +3103,11 @@
30553103 } else
30563104 qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd;
30573105
3058
- pkt->handle = MAKE_HANDLE(qpair->req->id, h);
3106
+ pkt->handle = make_handle(qpair->req->id, h);
30593107 pkt->handle |= CTIO_COMPLETION_HANDLE_MARK;
30603108 pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id);
30613109 pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
3062
- pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2];
3063
- pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1];
3064
- pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0];
3110
+ pkt->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
30653111 pkt->exchange_addr = atio->u.isp24.exchange_addr;
30663112
30673113 /* silence compile warning */
....@@ -3078,7 +3124,7 @@
30783124 else if (cmd->dma_data_direction == DMA_FROM_DEVICE)
30793125 pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT);
30803126
3081
- pkt->dseg_count = prm->tot_dsds;
3127
+ pkt->dseg_count = cpu_to_le16(prm->tot_dsds);
30823128 /* Fibre channel byte count */
30833129 pkt->transfer_length = cpu_to_le32(transfer_length);
30843130
....@@ -3099,12 +3145,11 @@
30993145
31003146 qla_tgt_set_dif_tags(cmd, crc_ctx_pkt, &fw_prot_opts);
31013147
3102
- pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma));
3103
- pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma));
3104
- pkt->crc_context_len = CRC_CONTEXT_LEN_FW;
3148
+ put_unaligned_le64(crc_ctx_dma, &pkt->crc_context_address);
3149
+ pkt->crc_context_len = cpu_to_le16(CRC_CONTEXT_LEN_FW);
31053150
31063151 if (!bundling) {
3107
- cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address;
3152
+ cur_dsd = &crc_ctx_pkt->u.nobundling.data_dsd[0];
31083153 } else {
31093154 /*
31103155 * Configure Bundling if we need to fetch interlaving
....@@ -3114,7 +3159,7 @@
31143159 crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes);
31153160 crc_ctx_pkt->u.bundling.dseg_count =
31163161 cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt);
3117
- cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address;
3162
+ cur_dsd = &crc_ctx_pkt->u.bundling.data_dsd[0];
31183163 }
31193164
31203165 /* Finish the common fields of CRC pkt */
....@@ -3147,9 +3192,9 @@
31473192 /* Walks dif segments */
31483193 pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA;
31493194
3150
- cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address;
3195
+ cur_dsd = &crc_ctx_pkt->u.bundling.dif_dsd;
31513196 if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd,
3152
- prm->prot_seg_cnt, &tc))
3197
+ prm->prot_seg_cnt, cmd))
31533198 goto crc_queuing_error;
31543199 }
31553200 return QLA_SUCCESS;
....@@ -3176,13 +3221,9 @@
31763221 unsigned long flags = 0;
31773222 int res;
31783223
3179
- if (cmd->sess && cmd->sess->deleted) {
3224
+ if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) ||
3225
+ (cmd->sess && cmd->sess->deleted)) {
31803226 cmd->state = QLA_TGT_STATE_PROCESSED;
3181
- if (cmd->sess->logout_completed)
3182
- /* no need to terminate. FW already freed exchange. */
3183
- qlt_abort_cmd_on_host_reset(cmd->vha, cmd);
3184
- else
3185
- qlt_send_term_exchange(qpair, cmd, &cmd->atio, 0, 0);
31863227 return 0;
31873228 }
31883229
....@@ -3211,11 +3252,11 @@
32113252 * previous life, just abort the processing.
32123253 */
32133254 cmd->state = QLA_TGT_STATE_PROCESSED;
3214
- qlt_abort_cmd_on_host_reset(cmd->vha, cmd);
32153255 ql_dbg_qp(ql_dbg_async, qpair, 0xe101,
32163256 "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n",
32173257 vha->flags.online, qla2x00_reset_active(vha),
32183258 cmd->reset_count, qpair->chip_reset);
3259
+ res = 0;
32193260 goto out_unmap_unlock;
32203261 }
32213262
....@@ -3303,6 +3344,7 @@
33033344
33043345 cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */
33053346 cmd->cmd_sent_to_fw = 1;
3347
+ cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags);
33063348
33073349 /* Memory Barrier */
33083350 wmb();
....@@ -3344,8 +3386,10 @@
33443386 * Either the port is not online or this request was from
33453387 * previous life, just abort the processing.
33463388 */
3347
- cmd->state = QLA_TGT_STATE_NEED_DATA;
3348
- qlt_abort_cmd_on_host_reset(cmd->vha, cmd);
3389
+ cmd->aborted = 1;
3390
+ cmd->write_data_transferred = 0;
3391
+ cmd->state = QLA_TGT_STATE_DATA_IN;
3392
+ vha->hw->tgt.tgt_ops->handle_data(cmd);
33493393 ql_dbg_qp(ql_dbg_async, qpair, 0xe102,
33503394 "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n",
33513395 vha->flags.online, qla2x00_reset_active(vha),
....@@ -3381,6 +3425,7 @@
33813425
33823426 cmd->state = QLA_TGT_STATE_NEED_DATA;
33833427 cmd->cmd_sent_to_fw = 1;
3428
+ cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags);
33843429
33853430 /* Memory Barrier */
33863431 wmb();
....@@ -3417,13 +3462,13 @@
34173462
34183463 cmd->trc_flags |= TRC_DIF_ERR;
34193464
3420
- cmd->a_guard = be16_to_cpu(*(uint16_t *)(ap + 0));
3421
- cmd->a_app_tag = be16_to_cpu(*(uint16_t *)(ap + 2));
3422
- cmd->a_ref_tag = be32_to_cpu(*(uint32_t *)(ap + 4));
3465
+ cmd->a_guard = get_unaligned_be16(ap + 0);
3466
+ cmd->a_app_tag = get_unaligned_be16(ap + 2);
3467
+ cmd->a_ref_tag = get_unaligned_be32(ap + 4);
34233468
3424
- cmd->e_guard = be16_to_cpu(*(uint16_t *)(ep + 0));
3425
- cmd->e_app_tag = be16_to_cpu(*(uint16_t *)(ep + 2));
3426
- cmd->e_ref_tag = be32_to_cpu(*(uint32_t *)(ep + 4));
3469
+ cmd->e_guard = get_unaligned_be16(ep + 0);
3470
+ cmd->e_app_tag = get_unaligned_be16(ep + 2);
3471
+ cmd->e_ref_tag = get_unaligned_be32(ep + 4);
34273472
34283473 ql_dbg(ql_dbg_tgt_dif, vha, 0xf075,
34293474 "%s: aborted %d state %d\n", __func__, cmd->aborted, cmd->state);
....@@ -3535,7 +3580,7 @@
35353580 nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle;
35363581 if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) {
35373582 nack->u.isp24.flags = ntfy->u.isp24.flags &
3538
- __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB);
3583
+ cpu_to_le16(NOTIFY24XX_FLAGS_PUREX_IOCB);
35393584 }
35403585
35413586 /* terminate */
....@@ -3558,33 +3603,11 @@
35583603 static void qlt_send_term_imm_notif(struct scsi_qla_host *vha,
35593604 struct imm_ntfy_from_isp *imm, int ha_locked)
35603605 {
3561
- unsigned long flags = 0;
35623606 int rc;
35633607
3564
- if (ha_locked) {
3565
- rc = __qlt_send_term_imm_notif(vha, imm);
3566
-
3567
-#if 0 /* Todo */
3568
- if (rc == -ENOMEM)
3569
- qlt_alloc_qfull_cmd(vha, imm, 0, 0);
3570
-#else
3571
- if (rc) {
3572
- }
3573
-#endif
3574
- goto done;
3575
- }
3576
-
3577
- spin_lock_irqsave(&vha->hw->hardware_lock, flags);
3608
+ WARN_ON_ONCE(!ha_locked);
35783609 rc = __qlt_send_term_imm_notif(vha, imm);
3579
-
3580
-#if 0 /* Todo */
3581
- if (rc == -ENOMEM)
3582
- qlt_alloc_qfull_cmd(vha, imm, 0, 0);
3583
-#endif
3584
-
3585
-done:
3586
- if (!ha_locked)
3587
- spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
3610
+ pr_debug("rc = %d\n", rc);
35883611 }
35893612
35903613 /*
....@@ -3631,12 +3654,10 @@
36313654
36323655 ctio24 = (struct ctio7_to_24xx *)pkt;
36333656 ctio24->entry_type = CTIO_TYPE7;
3634
- ctio24->nport_handle = CTIO7_NHANDLE_UNRECOGNIZED;
3657
+ ctio24->nport_handle = cpu_to_le16(CTIO7_NHANDLE_UNRECOGNIZED);
36353658 ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
36363659 ctio24->vp_index = vha->vp_idx;
3637
- ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2];
3638
- ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1];
3639
- ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0];
3660
+ ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
36403661 ctio24->exchange_addr = atio->u.isp24.exchange_addr;
36413662 temp = (atio->u.isp24.attr << 9) | CTIO7_FLAGS_STATUS_MODE_1 |
36423663 CTIO7_FLAGS_TERMINATE;
....@@ -3752,6 +3773,9 @@
37523773
37533774 spin_lock_irqsave(&cmd->cmd_lock, flags);
37543775 if (cmd->aborted) {
3776
+ if (cmd->sg_mapped)
3777
+ qlt_unmap_sg(vha, cmd);
3778
+
37553779 spin_unlock_irqrestore(&cmd->cmd_lock, flags);
37563780 /*
37573781 * It's normal to see 2 calls in this path:
....@@ -3762,7 +3786,7 @@
37623786 "multiple abort. %p transport_state %x, t_state %x, "
37633787 "se_cmd_flags %x\n", cmd, cmd->se_cmd.transport_state,
37643788 cmd->se_cmd.t_state, cmd->se_cmd.se_cmd_flags);
3765
- return EIO;
3789
+ return -EIO;
37663790 }
37673791 cmd->aborted = 1;
37683792 cmd->trc_flags |= TRC_ABORT;
....@@ -3797,7 +3821,7 @@
37973821 return;
37983822 }
37993823 cmd->jiffies_at_free = get_jiffies_64();
3800
- target_free_tag(sess->se_sess, &cmd->se_cmd);
3824
+ cmd->vha->hw->tgt.tgt_ops->rel_cmd(cmd);
38013825 }
38023826 EXPORT_SYMBOL(qlt_free_cmd);
38033827
....@@ -3822,6 +3846,7 @@
38223846
38233847 if (ctio != NULL) {
38243848 struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio;
3849
+
38253850 term = !(c->flags &
38263851 cpu_to_le16(OF_TERM_EXCH));
38273852 } else
....@@ -3835,10 +3860,10 @@
38353860
38363861
38373862 /* ha->hardware_lock supposed to be held on entry */
3838
-static struct qla_tgt_cmd *qlt_ctio_to_cmd(struct scsi_qla_host *vha,
3863
+static void *qlt_ctio_to_cmd(struct scsi_qla_host *vha,
38393864 struct rsp_que *rsp, uint32_t handle, void *ctio)
38403865 {
3841
- struct qla_tgt_cmd *cmd = NULL;
3866
+ void *cmd = NULL;
38423867 struct req_que *req;
38433868 int qid = GET_QID(handle);
38443869 uint32_t h = handle & ~QLA_TGT_HANDLE_MASK;
....@@ -3867,7 +3892,7 @@
38673892 return NULL;
38683893 }
38693894
3870
- cmd = (struct qla_tgt_cmd *)req->outstanding_cmds[h];
3895
+ cmd = req->outstanding_cmds[h];
38713896 if (unlikely(cmd == NULL)) {
38723897 ql_dbg(ql_dbg_async, vha, 0xe053,
38733898 "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n",
....@@ -3884,39 +3909,6 @@
38843909 }
38853910
38863911 return cmd;
3887
-}
3888
-
3889
-/* hardware_lock should be held by caller. */
3890
-void
3891
-qlt_abort_cmd_on_host_reset(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd)
3892
-{
3893
- struct qla_hw_data *ha = vha->hw;
3894
-
3895
- if (cmd->sg_mapped)
3896
- qlt_unmap_sg(vha, cmd);
3897
-
3898
- /* TODO: fix debug message type and ids. */
3899
- if (cmd->state == QLA_TGT_STATE_PROCESSED) {
3900
- ql_dbg(ql_dbg_io, vha, 0xff00,
3901
- "HOST-ABORT: state=PROCESSED.\n");
3902
- } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) {
3903
- cmd->write_data_transferred = 0;
3904
- cmd->state = QLA_TGT_STATE_DATA_IN;
3905
-
3906
- ql_dbg(ql_dbg_io, vha, 0xff01,
3907
- "HOST-ABORT: state=DATA_IN.\n");
3908
-
3909
- ha->tgt.tgt_ops->handle_data(cmd);
3910
- return;
3911
- } else {
3912
- ql_dbg(ql_dbg_io, vha, 0xff03,
3913
- "HOST-ABORT: state=BAD(%d).\n",
3914
- cmd->state);
3915
- dump_stack();
3916
- }
3917
-
3918
- cmd->trc_flags |= TRC_FLUSH;
3919
- ha->tgt.tgt_ops->free_cmd(cmd);
39203912 }
39213913
39223914 /*
....@@ -3951,12 +3943,20 @@
39513943
39523944 if (unlikely(status != CTIO_SUCCESS)) {
39533945 switch (status & 0xFFFF) {
3946
+ case CTIO_INVALID_RX_ID:
3947
+ if (printk_ratelimit())
3948
+ dev_info(&vha->hw->pdev->dev,
3949
+ "qla_target(%d): CTIO with INVALID_RX_ID ATIO attr %x CTIO Flags %x|%x\n",
3950
+ vha->vp_idx, cmd->atio.u.isp24.attr,
3951
+ ((cmd->ctio_flags >> 9) & 0xf),
3952
+ cmd->ctio_flags);
3953
+
3954
+ break;
39543955 case CTIO_LIP_RESET:
39553956 case CTIO_TARGET_RESET:
39563957 case CTIO_ABORTED:
39573958 /* driver request abort via Terminate exchange */
39583959 case CTIO_TIMEOUT:
3959
- case CTIO_INVALID_RX_ID:
39603960 /* They are OK */
39613961 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058,
39623962 "qla_target(%d): CTIO with "
....@@ -3983,7 +3983,6 @@
39833983 * Session is already logged out, but we need
39843984 * to notify initiator, who's not aware of this
39853985 */
3986
- cmd->sess->logout_on_delete = 0;
39873986 cmd->sess->send_els_logo = 1;
39883987 ql_dbg(ql_dbg_disc, vha, 0x20f8,
39893988 "%s %d %8phC post del sess\n",
....@@ -4091,8 +4090,6 @@
40914090 return fcp_task_attr;
40924091 }
40934092
4094
-static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *,
4095
- uint8_t *);
40964093 /*
40974094 * Process context for I/O path into tcm_qla2xxx code
40984095 */
....@@ -4120,7 +4117,7 @@
41204117
41214118 spin_lock_init(&cmd->cmd_lock);
41224119 cdb = &atio->u.isp24.fcp_cmnd.cdb[0];
4123
- cmd->se_cmd.tag = atio->u.isp24.exchange_addr;
4120
+ cmd->se_cmd.tag = le32_to_cpu(atio->u.isp24.exchange_addr);
41244121
41254122 if (atio->u.isp24.fcp_cmnd.rddata &&
41264123 atio->u.isp24.fcp_cmnd.wrdata) {
....@@ -4142,7 +4139,7 @@
41424139 if (ret != 0)
41434140 goto out_term;
41444141 /*
4145
- * Drop extra session reference from qla_tgt_handle_cmd_for_atio*(
4142
+ * Drop extra session reference from qlt_handle_cmd_for_atio().
41464143 */
41474144 ha->tgt.tgt_ops->put_sess(sess);
41484145 return;
....@@ -4158,7 +4155,7 @@
41584155 qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0);
41594156
41604157 qlt_decr_num_pend_cmds(vha);
4161
- target_free_tag(sess->se_sess, &cmd->se_cmd);
4158
+ cmd->vha->hw->tgt.tgt_ops->rel_cmd(cmd);
41624159 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
41634160
41644161 ha->tgt.tgt_ops->put_sess(sess);
....@@ -4285,24 +4282,18 @@
42854282 struct fc_port *sess,
42864283 struct atio_from_isp *atio)
42874284 {
4288
- struct se_session *se_sess = sess->se_sess;
42894285 struct qla_tgt_cmd *cmd;
4290
- int tag, cpu;
42914286
4292
- tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu);
4293
- if (tag < 0)
4287
+ cmd = vha->hw->tgt.tgt_ops->get_cmd(sess);
4288
+ if (!cmd)
42944289 return NULL;
42954290
4296
- cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag];
4297
- memset(cmd, 0, sizeof(struct qla_tgt_cmd));
42984291 cmd->cmd_type = TYPE_TGT_CMD;
42994292 memcpy(&cmd->atio, atio, sizeof(*atio));
43004293 cmd->state = QLA_TGT_STATE_NEW;
43014294 cmd->tgt = vha->vha_tgt.qla_tgt;
43024295 qlt_incr_num_pend_cmds(vha);
43034296 cmd->vha = vha;
4304
- cmd->se_cmd.map_tag = tag;
4305
- cmd->se_cmd.map_cpu = cpu;
43064297 cmd->sess = sess;
43074298 cmd->loop_id = sess->loop_id;
43084299 cmd->conf_compl_supported = sess->conf_compl_supported;
....@@ -4336,9 +4327,7 @@
43364327 return -ENODEV;
43374328 }
43384329
4339
- id.b.al_pa = atio->u.isp24.fcp_hdr.s_id[2];
4340
- id.b.area = atio->u.isp24.fcp_hdr.s_id[1];
4341
- id.b.domain = atio->u.isp24.fcp_hdr.s_id[0];
4330
+ id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id);
43424331 if (IS_SW_RESV_ADDR(id))
43434332 return -EBUSY;
43444333
....@@ -4436,7 +4425,7 @@
44364425 case QLA_TGT_CLEAR_TS:
44374426 case QLA_TGT_ABORT_TS:
44384427 abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id);
4439
- /* drop through */
4428
+ fallthrough;
44404429 case QLA_TGT_CLEAR_ACA:
44414430 h = qlt_find_qphint(vha, mcmd->unpacked_lun);
44424431 mcmd->qpair = h->qpair;
....@@ -4600,7 +4589,7 @@
46004589 /* find other sess with nport_id collision */
46014590 if (port_id.b24 == other_sess->d_id.b24) {
46024591 if (loop_id != other_sess->loop_id) {
4603
- ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000c,
4592
+ ql_dbg(ql_dbg_disc, vha, 0x1000c,
46044593 "Invalidating sess %p loop_id %d wwn %llx.\n",
46054594 other_sess, other_sess->loop_id, other_wwn);
46064595
....@@ -4616,7 +4605,7 @@
46164605 * Another wwn used to have our s_id/loop_id
46174606 * kill the session, but don't free the loop_id
46184607 */
4619
- ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01b,
4608
+ ql_dbg(ql_dbg_disc, vha, 0xf01b,
46204609 "Invalidating sess %p loop_id %d wwn %llx.\n",
46214610 other_sess, other_sess->loop_id, other_wwn);
46224611
....@@ -4631,7 +4620,7 @@
46314620 /* find other sess with nport handle collision */
46324621 if ((loop_id == other_sess->loop_id) &&
46334622 (loop_id != FC_NO_LOOP_ID)) {
4634
- ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000d,
4623
+ ql_dbg(ql_dbg_disc, vha, 0x1000d,
46354624 "Invalidating sess %p loop_id %d wwn %llx.\n",
46364625 other_sess, other_sess->loop_id, other_wwn);
46374626
....@@ -4669,6 +4658,7 @@
46694658
46704659 list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) {
46714660 uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
4661
+
46724662 if (op_key == key) {
46734663 op->aborted = true;
46744664 count++;
....@@ -4677,6 +4667,7 @@
46774667
46784668 list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) {
46794669 uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id);
4670
+
46804671 if (cmd_key == key) {
46814672 cmd->aborted = 1;
46824673 count++;
....@@ -4697,6 +4688,8 @@
46974688 int res = 0;
46984689 struct qlt_plogi_ack_t *pla;
46994690 unsigned long flags;
4691
+
4692
+ lockdep_assert_held(&vha->hw->hardware_lock);
47004693
47014694 wwn = wwn_to_u64(iocb->u.isp24.port_name);
47024695
....@@ -4753,11 +4746,11 @@
47534746 qla24xx_post_newsess_work(vha, &port_id,
47544747 iocb->u.isp24.port_name,
47554748 iocb->u.isp24.u.plogi.node_name,
4756
- pla, FC4_TYPE_UNKNOWN);
4749
+ pla, 0);
47574750 else
47584751 qla24xx_post_newsess_work(vha, &port_id,
47594752 iocb->u.isp24.port_name, NULL,
4760
- pla, FC4_TYPE_UNKNOWN);
4753
+ pla, 0);
47614754
47624755 goto out;
47634756 }
....@@ -4781,8 +4774,10 @@
47814774 __func__, sess->port_name, sec);
47824775 }
47834776
4784
- if (!conflict_sess)
4777
+ if (!conflict_sess) {
4778
+ list_del(&pla->list);
47854779 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4780
+ }
47864781
47874782 qlt_send_term_imm_notif(vha, iocb, 1);
47884783 goto out;
....@@ -4872,6 +4867,8 @@
48724867 int res = 0;
48734868 unsigned long flags;
48744869
4870
+ lockdep_assert_held(&ha->hardware_lock);
4871
+
48754872 wwn = wwn_to_u64(iocb->u.isp24.port_name);
48764873
48774874 port_id.b.domain = iocb->u.isp24.port_id[2];
....@@ -4948,6 +4945,7 @@
49484945 if (sess != NULL) {
49494946 bool delete = false;
49504947 int sec;
4948
+
49514949 spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags);
49524950 switch (sess->fw_login_state) {
49534951 case DSC_LS_PLOGI_PEND:
....@@ -5061,7 +5059,7 @@
50615059 res = 1;
50625060 break;
50635061 }
5064
- /* fall through */
5062
+ fallthrough;
50655063 case ELS_LOGO:
50665064 case ELS_PRLO:
50675065 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
....@@ -5100,6 +5098,7 @@
51005098 case ELS_ADISC:
51015099 {
51025100 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5101
+
51035102 if (tgt->link_reinit_iocb_pending) {
51045103 qlt_send_notify_ack(ha->base_qpair,
51055104 &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0);
....@@ -5146,6 +5145,8 @@
51465145 int send_notify_ack = 1;
51475146 uint16_t status;
51485147
5148
+ lockdep_assert_held(&ha->hardware_lock);
5149
+
51495150 status = le16_to_cpu(iocb->u.isp2x.status);
51505151 switch (status) {
51515152 case IMM_NTFY_LIP_RESET:
....@@ -5163,6 +5164,7 @@
51635164 case IMM_NTFY_LIP_LINK_REINIT:
51645165 {
51655166 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
5167
+
51665168 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033,
51675169 "qla_target(%d): LINK REINIT (loop %#x, "
51685170 "subcode %x)\n", vha->vp_idx,
....@@ -5282,10 +5284,7 @@
52825284 u16 temp;
52835285 port_id_t id;
52845286
5285
- id.b.al_pa = atio->u.isp24.fcp_hdr.s_id[2];
5286
- id.b.area = atio->u.isp24.fcp_hdr.s_id[1];
5287
- id.b.domain = atio->u.isp24.fcp_hdr.s_id[0];
5288
- id.b.rsvd_1 = 0;
5287
+ id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id);
52895288
52905289 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
52915290 sess = qla2x00_find_fcport_by_nportid(vha, &id, 1);
....@@ -5310,12 +5309,10 @@
53105309
53115310 ctio24 = (struct ctio7_to_24xx *)pkt;
53125311 ctio24->entry_type = CTIO_TYPE7;
5313
- ctio24->nport_handle = sess->loop_id;
5312
+ ctio24->nport_handle = cpu_to_le16(sess->loop_id);
53145313 ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
53155314 ctio24->vp_index = vha->vp_idx;
5316
- ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2];
5317
- ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1];
5318
- ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0];
5315
+ ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
53195316 ctio24->exchange_addr = atio->u.isp24.exchange_addr;
53205317 temp = (atio->u.isp24.attr << 9) |
53215318 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS |
....@@ -5325,13 +5322,14 @@
53255322 * CTIO from fw w/o se_cmd doesn't provide enough info to retry it,
53265323 * if the explicit conformation is used.
53275324 */
5328
- ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id);
5325
+ ctio24->u.status1.ox_id =
5326
+ cpu_to_le16(be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
53295327 ctio24->u.status1.scsi_status = cpu_to_le16(status);
53305328
5331
- ctio24->u.status1.residual = get_datalen_for_atio(atio);
5329
+ ctio24->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio));
53325330
53335331 if (ctio24->u.status1.residual != 0)
5334
- ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER;
5332
+ ctio24->u.status1.scsi_status |= cpu_to_le16(SS_RESIDUAL_UNDER);
53355333
53365334 /* Memory Barrier */
53375335 wmb();
....@@ -5354,9 +5352,7 @@
53545352 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
53555353 struct qla_hw_data *ha = vha->hw;
53565354 struct fc_port *sess;
5357
- struct se_session *se_sess;
53585355 struct qla_tgt_cmd *cmd;
5359
- int tag, cpu;
53605356 unsigned long flags;
53615357
53625358 if (unlikely(tgt->tgt_stop)) {
....@@ -5386,10 +5382,8 @@
53865382 if (!sess)
53875383 return;
53885384
5389
- se_sess = sess->se_sess;
5390
-
5391
- tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu);
5392
- if (tag < 0) {
5385
+ cmd = ha->tgt.tgt_ops->get_cmd(sess);
5386
+ if (!cmd) {
53935387 ql_dbg(ql_dbg_io, vha, 0x3009,
53945388 "qla_target(%d): %s: Allocation of cmd failed\n",
53955389 vha->vp_idx, __func__);
....@@ -5404,9 +5398,6 @@
54045398 return;
54055399 }
54065400
5407
- cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag];
5408
- memset(cmd, 0, sizeof(struct qla_tgt_cmd));
5409
-
54105401 qlt_incr_num_pend_cmds(vha);
54115402 INIT_LIST_HEAD(&cmd->cmd_list);
54125403 memcpy(&cmd->atio, atio, sizeof(*atio));
....@@ -5416,7 +5407,6 @@
54165407 cmd->reset_count = ha->base_qpair->chip_reset;
54175408 cmd->q_full = 1;
54185409 cmd->qpair = ha->base_qpair;
5419
- cmd->se_cmd.map_cpu = cpu;
54205410
54215411 if (qfull) {
54225412 cmd->q_full = 1;
....@@ -5568,7 +5558,7 @@
55685558 switch (atio->u.raw.entry_type) {
55695559 case ATIO_TYPE7:
55705560 if (unlikely(atio->u.isp24.exchange_addr ==
5571
- ATIO_EXCHANGE_ADDRESS_UNKNOWN)) {
5561
+ cpu_to_le32(ATIO_EXCHANGE_ADDRESS_UNKNOWN))) {
55725562 ql_dbg(ql_dbg_io, vha, 0x3065,
55735563 "qla_target(%d): ATIO_TYPE7 "
55745564 "received with UNKNOWN exchange address, "
....@@ -5658,6 +5648,100 @@
56585648 tgt->atio_irq_cmd_count--;
56595649 }
56605650
5651
+/*
5652
+ * qpair lock is assume to be held
5653
+ * rc = 0 : send terminate & abts respond
5654
+ * rc != 0: do not send term & abts respond
5655
+ */
5656
+static int qlt_chk_unresolv_exchg(struct scsi_qla_host *vha,
5657
+ struct qla_qpair *qpair, struct abts_resp_from_24xx_fw *entry)
5658
+{
5659
+ struct qla_hw_data *ha = vha->hw;
5660
+ int rc = 0;
5661
+
5662
+ /*
5663
+ * Detect unresolved exchange. If the same ABTS is unable
5664
+ * to terminate an existing command and the same ABTS loops
5665
+ * between FW & Driver, then force FW dump. Under 1 jiff,
5666
+ * we should see multiple loops.
5667
+ */
5668
+ if (qpair->retry_term_exchg_addr == entry->exchange_addr_to_abort &&
5669
+ qpair->retry_term_jiff == jiffies) {
5670
+ /* found existing exchange */
5671
+ qpair->retry_term_cnt++;
5672
+ if (qpair->retry_term_cnt >= 5) {
5673
+ rc = -EIO;
5674
+ qpair->retry_term_cnt = 0;
5675
+ ql_log(ql_log_warn, vha, 0xffff,
5676
+ "Unable to send ABTS Respond. Dumping firmware.\n");
5677
+ ql_dump_buffer(ql_dbg_tgt_mgt + ql_dbg_buffer,
5678
+ vha, 0xffff, (uint8_t *)entry, sizeof(*entry));
5679
+
5680
+ if (qpair == ha->base_qpair)
5681
+ ha->isp_ops->fw_dump(vha);
5682
+ else
5683
+ qla2xxx_dump_fw(vha);
5684
+
5685
+ set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
5686
+ qla2xxx_wake_dpc(vha);
5687
+ }
5688
+ } else if (qpair->retry_term_jiff != jiffies) {
5689
+ qpair->retry_term_exchg_addr = entry->exchange_addr_to_abort;
5690
+ qpair->retry_term_cnt = 0;
5691
+ qpair->retry_term_jiff = jiffies;
5692
+ }
5693
+
5694
+ return rc;
5695
+}
5696
+
5697
+
5698
+static void qlt_handle_abts_completion(struct scsi_qla_host *vha,
5699
+ struct rsp_que *rsp, response_t *pkt)
5700
+{
5701
+ struct abts_resp_from_24xx_fw *entry =
5702
+ (struct abts_resp_from_24xx_fw *)pkt;
5703
+ u32 h = pkt->handle & ~QLA_TGT_HANDLE_MASK;
5704
+ struct qla_tgt_mgmt_cmd *mcmd;
5705
+ struct qla_hw_data *ha = vha->hw;
5706
+
5707
+ mcmd = qlt_ctio_to_cmd(vha, rsp, pkt->handle, pkt);
5708
+ if (mcmd == NULL && h != QLA_TGT_SKIP_HANDLE) {
5709
+ ql_dbg(ql_dbg_async, vha, 0xe064,
5710
+ "qla_target(%d): ABTS Comp without mcmd\n",
5711
+ vha->vp_idx);
5712
+ return;
5713
+ }
5714
+
5715
+ if (mcmd)
5716
+ vha = mcmd->vha;
5717
+ vha->vha_tgt.qla_tgt->abts_resp_expected--;
5718
+
5719
+ ql_dbg(ql_dbg_tgt, vha, 0xe038,
5720
+ "ABTS_RESP_24XX: compl_status %x\n",
5721
+ entry->compl_status);
5722
+
5723
+ if (le16_to_cpu(entry->compl_status) != ABTS_RESP_COMPL_SUCCESS) {
5724
+ if (le32_to_cpu(entry->error_subcode1) == 0x1E &&
5725
+ le32_to_cpu(entry->error_subcode2) == 0) {
5726
+ if (qlt_chk_unresolv_exchg(vha, rsp->qpair, entry)) {
5727
+ ha->tgt.tgt_ops->free_mcmd(mcmd);
5728
+ return;
5729
+ }
5730
+ qlt_24xx_retry_term_exchange(vha, rsp->qpair,
5731
+ pkt, mcmd);
5732
+ } else {
5733
+ ql_dbg(ql_dbg_tgt, vha, 0xe063,
5734
+ "qla_target(%d): ABTS_RESP_24XX failed %x (subcode %x:%x)",
5735
+ vha->vp_idx, entry->compl_status,
5736
+ entry->error_subcode1,
5737
+ entry->error_subcode2);
5738
+ ha->tgt.tgt_ops->free_mcmd(mcmd);
5739
+ }
5740
+ } else if (mcmd) {
5741
+ ha->tgt.tgt_ops->free_mcmd(mcmd);
5742
+ }
5743
+}
5744
+
56615745 /* ha->hardware_lock supposed to be held on entry */
56625746 /* called via callback from qla2xxx */
56635747 static void qlt_response_pkt(struct scsi_qla_host *vha,
....@@ -5682,6 +5766,7 @@
56825766 case CTIO_TYPE7:
56835767 {
56845768 struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt;
5769
+
56855770 qlt_do_ctio_completion(vha, rsp, entry->handle,
56865771 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
56875772 entry);
....@@ -5692,6 +5777,7 @@
56925777 {
56935778 struct atio_from_isp *atio = (struct atio_from_isp *)pkt;
56945779 int rc;
5780
+
56955781 if (atio->u.isp2x.status !=
56965782 cpu_to_le16(ATIO_CDB_VALID)) {
56975783 ql_dbg(ql_dbg_tgt, vha, 0xe05e,
....@@ -5740,6 +5826,7 @@
57405826 case CONTINUE_TGT_IO_TYPE:
57415827 {
57425828 struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt;
5829
+
57435830 qlt_do_ctio_completion(vha, rsp, entry->handle,
57445831 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
57455832 entry);
....@@ -5749,6 +5836,7 @@
57495836 case CTIO_A64_TYPE:
57505837 {
57515838 struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt;
5839
+
57525840 qlt_do_ctio_completion(vha, rsp, entry->handle,
57535841 le16_to_cpu(entry->status)|(pkt->entry_status << 16),
57545842 entry);
....@@ -5763,6 +5851,7 @@
57635851 case NOTIFY_ACK_TYPE:
57645852 if (tgt->notify_ack_expected > 0) {
57655853 struct nack_to_isp *entry = (struct nack_to_isp *)pkt;
5854
+
57665855 ql_dbg(ql_dbg_tgt, vha, 0xe036,
57675856 "NOTIFY_ACK seq %08x status %x\n",
57685857 le16_to_cpu(entry->u.isp2x.seq_id),
....@@ -5790,41 +5879,7 @@
57905879
57915880 case ABTS_RESP_24XX:
57925881 if (tgt->abts_resp_expected > 0) {
5793
- struct abts_resp_from_24xx_fw *entry =
5794
- (struct abts_resp_from_24xx_fw *)pkt;
5795
- ql_dbg(ql_dbg_tgt, vha, 0xe038,
5796
- "ABTS_RESP_24XX: compl_status %x\n",
5797
- entry->compl_status);
5798
- tgt->abts_resp_expected--;
5799
- if (le16_to_cpu(entry->compl_status) !=
5800
- ABTS_RESP_COMPL_SUCCESS) {
5801
- if ((entry->error_subcode1 == 0x1E) &&
5802
- (entry->error_subcode2 == 0)) {
5803
- /*
5804
- * We've got a race here: aborted
5805
- * exchange not terminated, i.e.
5806
- * response for the aborted command was
5807
- * sent between the abort request was
5808
- * received and processed.
5809
- * Unfortunately, the firmware has a
5810
- * silly requirement that all aborted
5811
- * exchanges must be explicitely
5812
- * terminated, otherwise it refuses to
5813
- * send responses for the abort
5814
- * requests. So, we have to
5815
- * (re)terminate the exchange and retry
5816
- * the abort response.
5817
- */
5818
- qlt_24xx_retry_term_exchange(vha,
5819
- entry);
5820
- } else
5821
- ql_dbg(ql_dbg_tgt, vha, 0xe063,
5822
- "qla_target(%d): ABTS_RESP_24XX "
5823
- "failed %x (subcode %x:%x)",
5824
- vha->vp_idx, entry->compl_status,
5825
- entry->error_subcode1,
5826
- entry->error_subcode2);
5827
- }
5882
+ qlt_handle_abts_completion(vha, rsp, pkt);
58285883 } else {
58295884 ql_dbg(ql_dbg_tgt, vha, 0xe064,
58305885 "qla_target(%d): Unexpected ABTS_RESP_24XX "
....@@ -5881,11 +5936,10 @@
58815936 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b,
58825937 "qla_target(%d): Async LOOP_UP occurred "
58835938 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx,
5884
- le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
5885
- le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
5939
+ mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
58865940 if (tgt->link_reinit_iocb_pending) {
58875941 qlt_send_notify_ack(ha->base_qpair,
5888
- (void *)&tgt->link_reinit_iocb,
5942
+ &tgt->link_reinit_iocb,
58895943 0, 0, 0, 0, 0, 0);
58905944 tgt->link_reinit_iocb_pending = 0;
58915945 }
....@@ -5899,18 +5953,16 @@
58995953 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c,
59005954 "qla_target(%d): Async event %#x occurred "
59015955 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code,
5902
- le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
5903
- le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
5956
+ mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
59045957 break;
59055958
59065959 case MBA_REJECTED_FCP_CMD:
59075960 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf017,
59085961 "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)",
59095962 vha->vp_idx,
5910
- le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
5911
- le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
5963
+ mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
59125964
5913
- if (le16_to_cpu(mailbox[3]) == 1) {
5965
+ if (mailbox[3] == 1) {
59145966 /* exchange starvation. */
59155967 vha->hw->exch_starvation++;
59165968 if (vha->hw->exch_starvation > 5) {
....@@ -5934,10 +5986,9 @@
59345986 "qla_target(%d): Port update async event %#x "
59355987 "occurred: updating the ports database (m[0]=%x, m[1]=%x, "
59365988 "m[2]=%x, m[3]=%x)", vha->vp_idx, code,
5937
- le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]),
5938
- le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3]));
5989
+ mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
59395990
5940
- login_code = le16_to_cpu(mailbox[2]);
5991
+ login_code = mailbox[2];
59415992 if (login_code == 0x4) {
59425993 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e,
59435994 "Async MB 2: Got PLOGI Complete\n");
....@@ -6001,7 +6052,7 @@
60016052 if (!IS_SW_RESV_ADDR(fcport->d_id))
60026053 vha->fcport_count++;
60036054 fcport->login_gen++;
6004
- fcport->disc_state = DSC_LOGIN_COMPLETE;
6055
+ qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
60056056 fcport->login_succ = 1;
60066057 newfcport = 1;
60076058 }
....@@ -6036,21 +6087,21 @@
60366087
60376088 /* Must be called under tgt_mutex */
60386089 static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *vha,
6039
- uint8_t *s_id)
6090
+ be_id_t s_id)
60406091 {
60416092 struct fc_port *sess = NULL;
60426093 fc_port_t *fcport = NULL;
60436094 int rc, global_resets;
60446095 uint16_t loop_id = 0;
60456096
6046
- if ((s_id[0] == 0xFF) && (s_id[1] == 0xFC)) {
6097
+ if (s_id.domain == 0xFF && s_id.area == 0xFC) {
60476098 /*
60486099 * This is Domain Controller, so it should be
60496100 * OK to drop SCSI commands from it.
60506101 */
60516102 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042,
60526103 "Unable to find initiator with S_ID %x:%x:%x",
6053
- s_id[0], s_id[1], s_id[2]);
6104
+ s_id.domain, s_id.area, s_id.al_pa);
60546105 return NULL;
60556106 }
60566107
....@@ -6067,12 +6118,12 @@
60676118 ql_log(ql_log_info, vha, 0xf071,
60686119 "qla_target(%d): Unable to find "
60696120 "initiator with S_ID %x:%x:%x",
6070
- vha->vp_idx, s_id[0], s_id[1],
6071
- s_id[2]);
6121
+ vha->vp_idx, s_id.domain, s_id.area, s_id.al_pa);
60726122
60736123 if (rc == -ENOENT) {
60746124 qlt_port_logo_t logo;
6075
- sid_to_portid(s_id, &logo.id);
6125
+
6126
+ logo.id = be_to_port_id(s_id);
60766127 logo.cmd_count = 1;
60776128 qlt_send_first_logo(vha, &logo);
60786129 }
....@@ -6111,7 +6162,7 @@
61116162 struct qla_hw_data *ha = vha->hw;
61126163 struct fc_port *sess = NULL;
61136164 unsigned long flags = 0, flags2 = 0;
6114
- uint8_t s_id[3];
6165
+ be_id_t s_id;
61156166 int rc;
61166167
61176168 spin_lock_irqsave(&ha->tgt.sess_lock, flags2);
....@@ -6119,9 +6170,7 @@
61196170 if (tgt->tgt_stop)
61206171 goto out_term2;
61216172
6122
- s_id[0] = prm->abts.fcp_hdr_le.s_id[2];
6123
- s_id[1] = prm->abts.fcp_hdr_le.s_id[1];
6124
- s_id[2] = prm->abts.fcp_hdr_le.s_id[0];
6173
+ s_id = le_id_to_be(prm->abts.fcp_hdr_le.s_id);
61256174
61266175 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
61276176 if (!sess) {
....@@ -6160,9 +6209,6 @@
61606209 out_term2:
61616210 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
61626211
6163
- if (sess)
6164
- ha->tgt.tgt_ops->put_sess(sess);
6165
-
61666212 out_term:
61676213 spin_lock_irqsave(&ha->hardware_lock, flags);
61686214 qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts,
....@@ -6176,9 +6222,9 @@
61766222 struct atio_from_isp *a = &prm->tm_iocb2;
61776223 struct scsi_qla_host *vha = tgt->vha;
61786224 struct qla_hw_data *ha = vha->hw;
6179
- struct fc_port *sess = NULL;
6225
+ struct fc_port *sess;
61806226 unsigned long flags;
6181
- uint8_t *s_id = NULL; /* to hide compiler warnings */
6227
+ be_id_t s_id;
61826228 int rc;
61836229 u64 unpacked_lun;
61846230 int fn;
....@@ -6202,7 +6248,6 @@
62026248 goto out_term2;
62036249 } else {
62046250 if (sess->deleted) {
6205
- sess = NULL;
62066251 goto out_term2;
62076252 }
62086253
....@@ -6210,7 +6255,6 @@
62106255 ql_dbg(ql_dbg_tgt_tmr, vha, 0xf020,
62116256 "%s: kref_get fail %8phC\n",
62126257 __func__, sess->port_name);
6213
- sess = NULL;
62146258 goto out_term2;
62156259 }
62166260 }
....@@ -6230,8 +6274,6 @@
62306274 return;
62316275
62326276 out_term2:
6233
- if (sess)
6234
- ha->tgt.tgt_ops->put_sess(sess);
62356277 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
62366278 out_term:
62376279 qlt_send_term_exchange(ha->base_qpair, NULL, &prm->tm_iocb2, 1, 0);
....@@ -6337,6 +6379,7 @@
63376379 unsigned long flags;
63386380
63396381 struct qla_qpair *qpair = ha->queue_pair_map[i];
6382
+
63406383 h = &tgt->qphints[i + 1];
63416384 INIT_LIST_HEAD(&h->hint_elem);
63426385 if (qpair) {
....@@ -6410,31 +6453,19 @@
64106453 static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn,
64116454 unsigned char *b)
64126455 {
6413
- int i;
6414
-
6415
- pr_debug("qla2xxx HW vha->node_name: ");
6416
- for (i = 0; i < WWN_SIZE; i++)
6417
- pr_debug("%02x ", vha->node_name[i]);
6418
- pr_debug("\n");
6419
- pr_debug("qla2xxx HW vha->port_name: ");
6420
- for (i = 0; i < WWN_SIZE; i++)
6421
- pr_debug("%02x ", vha->port_name[i]);
6422
- pr_debug("\n");
6423
-
6424
- pr_debug("qla2xxx passed configfs WWPN: ");
6456
+ pr_debug("qla2xxx HW vha->node_name: %8phC\n", vha->node_name);
6457
+ pr_debug("qla2xxx HW vha->port_name: %8phC\n", vha->port_name);
64256458 put_unaligned_be64(wwpn, b);
6426
- for (i = 0; i < WWN_SIZE; i++)
6427
- pr_debug("%02x ", b[i]);
6428
- pr_debug("\n");
6459
+ pr_debug("qla2xxx passed configfs WWPN: %8phC\n", b);
64296460 }
64306461
64316462 /**
64326463 * qla_tgt_lport_register - register lport with external module
64336464 *
64346465 * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data
6435
- * @phys_wwpn:
6436
- * @npiv_wwpn:
6437
- * @npiv_wwnn:
6466
+ * @phys_wwpn: physical port WWPN
6467
+ * @npiv_wwpn: NPIV WWPN
6468
+ * @npiv_wwnn: NPIV WWNN
64386469 * @callback: lport initialization callback for tcm_qla2xxx code
64396470 */
64406471 int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn,
....@@ -6459,6 +6490,9 @@
64596490 continue;
64606491
64616492 if (!(host->hostt->supported_mode & MODE_TARGET))
6493
+ continue;
6494
+
6495
+ if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED)
64626496 continue;
64636497
64646498 spin_lock_irqsave(&ha->hardware_lock, flags);
....@@ -6523,15 +6557,15 @@
65236557 EXPORT_SYMBOL(qlt_lport_deregister);
65246558
65256559 /* Must be called under HW lock */
6526
-static void qlt_set_mode(struct scsi_qla_host *vha)
6560
+void qlt_set_mode(struct scsi_qla_host *vha)
65276561 {
6528
- switch (ql2x_ini_mode) {
6562
+ switch (vha->qlini_mode) {
65296563 case QLA2XXX_INI_MODE_DISABLED:
65306564 case QLA2XXX_INI_MODE_EXCLUSIVE:
65316565 vha->host->active_mode = MODE_TARGET;
65326566 break;
65336567 case QLA2XXX_INI_MODE_ENABLED:
6534
- vha->host->active_mode = MODE_UNKNOWN;
6568
+ vha->host->active_mode = MODE_INITIATOR;
65356569 break;
65366570 case QLA2XXX_INI_MODE_DUAL:
65376571 vha->host->active_mode = MODE_DUAL;
....@@ -6544,7 +6578,7 @@
65446578 /* Must be called under HW lock */
65456579 static void qlt_clear_mode(struct scsi_qla_host *vha)
65466580 {
6547
- switch (ql2x_ini_mode) {
6581
+ switch (vha->qlini_mode) {
65486582 case QLA2XXX_INI_MODE_DISABLED:
65496583 vha->host->active_mode = MODE_UNKNOWN;
65506584 break;
....@@ -6580,12 +6614,19 @@
65806614 dump_stack();
65816615 return;
65826616 }
6617
+ if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED)
6618
+ return;
65836619
6620
+ if (ha->tgt.num_act_qpairs > ha->max_qpairs)
6621
+ ha->tgt.num_act_qpairs = ha->max_qpairs;
65846622 spin_lock_irqsave(&ha->hardware_lock, flags);
65856623 tgt->tgt_stopped = 0;
65866624 qlt_set_mode(vha);
65876625 spin_unlock_irqrestore(&ha->hardware_lock, flags);
65886626
6627
+ mutex_lock(&ha->optrom_mutex);
6628
+ ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021,
6629
+ "%s.\n", __func__);
65896630 if (vha->vp_idx) {
65906631 qla24xx_disable_vp(vha);
65916632 qla24xx_enable_vp(vha);
....@@ -6595,6 +6636,7 @@
65956636 WARN_ON_ONCE(qla2x00_wait_for_hba_online(base_vha) !=
65966637 QLA_SUCCESS);
65976638 }
6639
+ mutex_unlock(&ha->optrom_mutex);
65986640 }
65996641 EXPORT_SYMBOL(qlt_enable_vha);
66006642
....@@ -6623,9 +6665,14 @@
66236665
66246666 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
66256667 qla2xxx_wake_dpc(vha);
6668
+
6669
+ /*
6670
+ * We are expecting the offline state.
6671
+ * QLA_FUNCTION_FAILED means that adapter is offline.
6672
+ */
66266673 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
66276674 ql_dbg(ql_dbg_tgt, vha, 0xe081,
6628
- "qla2x00_wait_for_hba_online() failed\n");
6675
+ "adapter is offline\n");
66296676 }
66306677
66316678 /*
....@@ -6691,7 +6738,7 @@
66916738 return;
66926739
66936740 for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) {
6694
- pkt->u.raw.signature = ATIO_PROCESSED;
6741
+ pkt->u.raw.signature = cpu_to_le32(ATIO_PROCESSED);
66956742 pkt++;
66966743 }
66976744
....@@ -6724,9 +6771,9 @@
67246771 */
67256772 ql_log(ql_log_warn, vha, 0xd03c,
67266773 "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n",
6727
- pkt->u.isp24.fcp_hdr.s_id,
6774
+ &pkt->u.isp24.fcp_hdr.s_id,
67286775 be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id),
6729
- le32_to_cpu(pkt->u.isp24.exchange_addr), pkt);
6776
+ pkt->u.isp24.exchange_addr, pkt);
67306777
67316778 adjust_corrupted_atio(pkt);
67326779 qlt_send_term_exchange(ha->base_qpair, NULL, pkt,
....@@ -6744,14 +6791,14 @@
67446791 } else
67456792 ha->tgt.atio_ring_ptr++;
67466793
6747
- pkt->u.raw.signature = ATIO_PROCESSED;
6794
+ pkt->u.raw.signature = cpu_to_le32(ATIO_PROCESSED);
67486795 pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr;
67496796 }
67506797 wmb();
67516798 }
67526799
67536800 /* Adjust ring index */
6754
- WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), ha->tgt.atio_ring_index);
6801
+ wrt_reg_dword(ISP_ATIO_Q_OUT(vha), ha->tgt.atio_ring_index);
67556802 }
67566803
67576804 void
....@@ -6764,29 +6811,23 @@
67646811 if (!QLA_TGT_MODE_ENABLED())
67656812 return;
67666813
6767
- WRT_REG_DWORD(ISP_ATIO_Q_IN(vha), 0);
6768
- WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), 0);
6769
- RD_REG_DWORD(ISP_ATIO_Q_OUT(vha));
6814
+ wrt_reg_dword(ISP_ATIO_Q_IN(vha), 0);
6815
+ wrt_reg_dword(ISP_ATIO_Q_OUT(vha), 0);
6816
+ rd_reg_dword(ISP_ATIO_Q_OUT(vha));
67706817
67716818 if (ha->flags.msix_enabled) {
6772
- if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
6773
- if (IS_QLA2071(ha)) {
6774
- /* 4 ports Baker: Enable Interrupt Handshake */
6775
- icb->msix_atio = 0;
6776
- icb->firmware_options_2 |= BIT_26;
6777
- } else {
6778
- icb->msix_atio = cpu_to_le16(msix->entry);
6779
- icb->firmware_options_2 &= ~BIT_26;
6780
- }
6819
+ if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
6820
+ icb->msix_atio = cpu_to_le16(msix->entry);
6821
+ icb->firmware_options_2 &= cpu_to_le32(~BIT_26);
67816822 ql_dbg(ql_dbg_init, vha, 0xf072,
67826823 "Registering ICB vector 0x%x for atio que.\n",
67836824 msix->entry);
67846825 }
67856826 } else {
67866827 /* INTx|MSI */
6787
- if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
6828
+ if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
67886829 icb->msix_atio = 0;
6789
- icb->firmware_options_2 |= BIT_26;
6830
+ icb->firmware_options_2 |= cpu_to_le32(BIT_26);
67906831 ql_dbg(ql_dbg_init, vha, 0xf072,
67916832 "%s: Use INTx for ATIOQ.\n", __func__);
67926833 }
....@@ -6818,7 +6859,7 @@
68186859 if (qla_tgt_mode_enabled(vha))
68196860 nv->exchange_count = cpu_to_le16(0xFFFF);
68206861 else /* dual */
6821
- nv->exchange_count = cpu_to_le16(ql2xexchoffld);
6862
+ nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
68226863
68236864 /* Enable target mode */
68246865 nv->firmware_options_1 |= cpu_to_le32(BIT_4);
....@@ -6897,14 +6938,6 @@
68976938 memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE);
68986939 icb->firmware_options_1 |= cpu_to_le32(BIT_14);
68996940 }
6900
-
6901
- /* disable ZIO at start time. */
6902
- if (!vha->flags.init_done) {
6903
- uint32_t tmp;
6904
- tmp = le32_to_cpu(icb->firmware_options_2);
6905
- tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
6906
- icb->firmware_options_2 = cpu_to_le32(tmp);
6907
- }
69086941 }
69096942
69106943 void
....@@ -6932,7 +6965,7 @@
69326965 if (qla_tgt_mode_enabled(vha))
69336966 nv->exchange_count = cpu_to_le16(0xFFFF);
69346967 else /* dual */
6935
- nv->exchange_count = cpu_to_le16(ql2xexchoffld);
6968
+ nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
69366969
69376970 /* Enable target mode */
69386971 nv->firmware_options_1 |= cpu_to_le32(BIT_4);
....@@ -7008,15 +7041,6 @@
70087041 memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE);
70097042 icb->firmware_options_1 |= cpu_to_le32(BIT_14);
70107043 }
7011
-
7012
- /* disable ZIO at start time. */
7013
- if (!vha->flags.init_done) {
7014
- uint32_t tmp;
7015
- tmp = le32_to_cpu(icb->firmware_options_2);
7016
- tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
7017
- icb->firmware_options_2 = cpu_to_le32(tmp);
7018
- }
7019
-
70207044 }
70217045
70227046 void
....@@ -7050,7 +7074,7 @@
70507074 if (!QLA_TGT_MODE_ENABLED())
70517075 return;
70527076
7053
- if ((ql2xenablemsix == 0) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
7077
+ if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
70547078 ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in;
70557079 ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out;
70567080 } else {
....@@ -7178,7 +7202,10 @@
71787202 sizeof(struct atio_from_isp), ha->tgt.atio_ring,
71797203 ha->tgt.atio_dma);
71807204 }
7205
+ ha->tgt.atio_ring = NULL;
7206
+ ha->tgt.atio_dma = 0;
71817207 kfree(ha->tgt.tgt_vp_map);
7208
+ ha->tgt.tgt_vp_map = NULL;
71827209 }
71837210
71847211 /* vport_slock to be held by the caller */
....@@ -7262,6 +7289,9 @@
72627289 {
72637290 int ret;
72647291
7292
+ BUILD_BUG_ON(sizeof(struct ctio7_to_24xx) != 64);
7293
+ BUILD_BUG_ON(sizeof(struct ctio_to_2xxx) != 64);
7294
+
72657295 if (!qlt_parse_ini_mode()) {
72667296 ql_log(ql_log_fatal, NULL, 0xe06b,
72677297 "qlt_parse_ini_mode() failed\n");