26 #include <linux/module.h>
28 #include <linux/types.h>
31 #include <linux/pci.h>
33 #include <linux/list.h>
35 #include <asm/unaligned.h>
36 #include <scsi/scsi.h>
48 "Determines when initiator mode will be enabled. Possible values: "
49 "\"exclusive\" - initiator mode will be enabled on load, "
50 "disabled on enabling target mode and then on disabling target mode "
52 "\"disabled\" - initiator mode will never be enabled; "
53 "\"enabled\" (default) - initiator mode will always stay enabled.");
73 #define FCP_PTA_SIMPLE 0
74 #define FCP_PTA_HEADQ 1
75 #define FCP_PTA_ORDERED 2
77 #define FCP_PTA_MASK 7
78 #define FCP_PRI_SHIFT 3
79 #define FCP_PRI_RESVD_MASK 0x80
102 static void qlt_reject_free_srr_imm(
struct scsi_qla_host *ha,
108 static struct kmem_cache *qla_tgt_mgmt_cmd_cachep;
109 static mempool_t *qla_tgt_mgmt_cmd_mempool;
130 static inline int qlt_issue_marker(
struct scsi_qla_host *
vha,
int vha_locked)
137 "qla_target(%d): issue_marker() failed\n",
152 if ((vha->
d_id.
b.area != d_id[1]) || (vha->
d_id.
b.domain != d_id[0]))
155 if (vha->
d_id.
b.al_pa == d_id[2])
159 vp_idx = ha->
tgt.tgt_vp_map[d_id[2]].idx;
161 return ha->
tgt.tgt_vp_map[vp_idx].vha;
172 if (vha->
vp_idx == vp_idx)
177 return ha->
tgt.tgt_vp_map[vp_idx].vha;
185 switch (atio->
u.
raw.entry_type) {
189 atio->
u.
isp24.fcp_hdr.d_id);
192 "qla_target(%d): Received ATIO_TYPE7 "
193 "with unknown d_id %x:%x:%x\n", vha->
vp_idx,
194 atio->
u.
isp24.fcp_hdr.d_id[0],
195 atio->
u.
isp24.fcp_hdr.d_id[1],
196 atio->
u.
isp24.fcp_hdr.d_id[2]);
199 qlt_24xx_atio_pkt(host, atio);
209 if ((entry->
u.
isp24.vp_index != 0xFF) &&
210 (entry->
u.
isp24.nport_handle != 0xFFFF)) {
211 host = qlt_find_host_by_vp_idx(vha,
215 "qla_target(%d): Received "
216 "ATIO (IMMED_NOTIFY_TYPE) "
217 "with unknown vp_index %d\n",
222 qlt_24xx_atio_pkt(host, atio);
228 "qla_target(%d): Received unknown ATIO atio "
229 "type %x\n", vha->
vp_idx, atio->
u.
raw.entry_type);
246 "qla_target(%d): Response pkt (CTIO_TYPE7) "
247 "received, with unknown vp_index %d\n",
251 qlt_response_pkt(host, pkt);
261 host = qlt_find_host_by_vp_idx(vha, entry->
u.
isp24.vp_index);
264 "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) "
265 "received, with unknown vp_index %d\n",
269 qlt_response_pkt(host, pkt);
278 if (0xFF != entry->
u.
isp24.vp_index) {
279 host = qlt_find_host_by_vp_idx(vha,
283 "qla_target(%d): Response "
284 "pkt (NOTIFY_ACK_TYPE) "
285 "received, with unknown "
286 "vp_index %d\n", vha->
vp_idx,
291 qlt_response_pkt(host, pkt);
303 "qla_target(%d): Response pkt "
304 "(ABTS_RECV_24XX) received, with unknown "
308 qlt_response_pkt(host, pkt);
320 "qla_target(%d): Response pkt "
321 "(ABTS_RECV_24XX) received, with unknown "
325 qlt_response_pkt(host, pkt);
330 qlt_response_pkt(vha, pkt);
349 ha->
tgt.tgt_ops->free_session(sess);
352 "Unregistration of sess %p finished\n", sess);
369 vha->
hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess);
392 if (loop_id == 0xFFFF) {
396 qlt_clear_tgt_db(ha->
tgt.qla_tgt, 1);
397 if (!list_empty(&ha->
tgt.qla_tgt->sess_list)) {
399 typeof(*sess), sess_list_entry);
412 "qla_target(%d): Not allowed "
413 "command %x in %s", vha->
vp_idx,
422 sess = ha->
tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id);
426 "Using sess for qla_tgt_reset: %p\n", sess);
433 "scsi(%ld): resetting (session %p from port "
434 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, "
435 "mcmd %x, loop_id %d)\n", vha->
host_no, sess,
442 lun = a->
u.
isp24.fcp_cmnd.lun;
445 return qlt_issue_task_mgmt(sess, unpacked_lun, mcmd,
450 static void qlt_schedule_sess_for_deletion(
struct qla_tgt_sess *sess,
460 "Scheduling sess %p for deletion\n", sess);
470 "qla_target(%d): session for port %02x:%02x:%02x:"
471 "%02x:%02x:%02x:%02x:%02x (loop ID %d) scheduled for "
472 "deletion in %u secs (expires: %lu) immed: %d\n",
488 static void qlt_clear_tgt_db(
struct qla_tgt *tgt,
bool local_only)
493 qlt_schedule_sess_for_deletion(sess,
true);
512 "qla_target(%d): DMA Alloc failed of %u\n",
513 vha->vp_idx, qla2x00_gid_list_size(ha));
521 "qla_target(%d): get_id_list() failed: %x\n",
524 goto out_free_id_list;
527 id_iter = (
char *)gid_list;
529 for (i = 0; i <
entries; i++) {
531 if ((gid->
al_pa == s_id[2]) &&
532 (gid->
area == s_id[1]) &&
533 (gid->
domain == s_id[0])) {
543 gid_list, gid_list_dma);
547 static bool qlt_check_fcport_exist(
struct scsi_qla_host *vha,
552 bool res, found =
false;
563 global_resets =
atomic_read(&ha->
tgt.qla_tgt->tgt_global_resets_count);
572 entries = pmap_len/
sizeof(*pmap24);
590 "qlt_check_fcport_exist(): loop_id %d", loop_id);
592 fcport = kzalloc(
sizeof(*fcport),
GFP_KERNEL);
593 if (fcport ==
NULL) {
595 "qla_target(%d): Allocation of tmp FC port failed",
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);
610 goto out_free_fcport;
616 "qla_target(%d): global reset during session discovery"
617 " (counter was %d, new %d), retrying",
618 vha->
vp_idx, global_resets,
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,
632 spin_unlock_irqrestore(&ha->hardware_lock, flags);
644 static void qlt_undelete_sess(
struct qla_tgt_sess *sess)
652 static void qlt_del_sess_work_fn(
struct delayed_work *work)
668 qlt_undelete_sess(sess);
670 spin_unlock_irqrestore(&ha->hardware_lock, flags);
671 cancel = qlt_check_fcport_exist(vha, sess);
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",
696 "Timeout: sess %p about to be deleted\n",
698 ha->
tgt.tgt_ops->shutdown_sess(sess);
699 ha->
tgt.tgt_ops->put_sess(sess);
709 spin_unlock_irqrestore(&ha->hardware_lock, flags);
724 unsigned char be_sid[3];
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,
741 qlt_undelete_sess(sess);
743 kref_get(&sess->
se_sess->sess_kref);
747 if (sess->
local && !local)
749 spin_unlock_irqrestore(&ha->hardware_lock, flags);
754 spin_unlock_irqrestore(&ha->hardware_lock, flags);
759 "qla_target(%u): session allocation failed, "
760 "all commands from port %02x:%02x:%02x:%02x:"
761 "%02x:%02x:%02x:%02x will be refused", vha->
vp_idx,
769 sess->
tgt = ha->
tgt.qla_tgt;
776 "Adding sess %p to tgt %p via ->check_initiator_node_acl()\n",
777 sess, ha->
tgt.qla_tgt);
779 be_sid[0] = sess->
s_id.
b.domain;
780 be_sid[1] = sess->
s_id.
b.area;
781 be_sid[2] = sess->
s_id.
b.al_pa;
788 if (ha->
tgt.tgt_ops->check_initiator_node_acl(vha,
797 kref_get(&sess->
se_sess->sess_kref);
805 ha->
tgt.qla_tgt->sess_count++;
806 spin_unlock_irqrestore(&ha->hardware_lock, flags);
809 "qla_target(%d): %ssession for wwn %02x:%02x:%02x:%02x:"
810 "%02x:%02x:%02x:%02x (loop_id %d, s_id %x:%x:%x, confirmed"
811 " completion %ssupported) added\n",
832 if (!vha->
hw->tgt.tgt_ops)
840 spin_unlock_irqrestore(&ha->hardware_lock, flags);
843 sess = qlt_find_sess_by_port_name(tgt, fcport->
port_name);
845 spin_unlock_irqrestore(&ha->hardware_lock, flags);
848 sess = qlt_create_sess(vha, fcport,
false);
853 kref_get(&sess->
se_sess->sess_kref);
856 qlt_undelete_sess(sess);
859 "qla_target(%u): %ssession for port %02x:"
860 "%02x:%02x:%02x:%02x:%02x:%02x:%02x (loop ID %d) "
861 "reappeared\n", vha->
vp_idx, sess->
local ?
"local "
869 "Reappeared sess %p\n", sess);
875 if (sess && sess->
local) {
877 "qla_target(%u): local session for "
878 "port %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
879 "(loop ID %d) became global\n", vha->
vp_idx,
887 spin_unlock_irqrestore(&ha->hardware_lock, flags);
889 ha->
tgt.tgt_ops->put_sess(sess);
899 if (!vha->
hw->tgt.tgt_ops)
907 spin_unlock_irqrestore(&ha->hardware_lock, flags);
910 sess = qlt_find_sess_by_port_name(tgt, fcport->
port_name);
912 spin_unlock_irqrestore(&ha->hardware_lock, flags);
919 qlt_schedule_sess_for_deletion(sess,
false);
920 spin_unlock_irqrestore(&ha->hardware_lock, flags);
923 static inline int test_tgt_sess_count(
struct qla_tgt *tgt)
934 "tgt %p, empty(sess_list)=%d sess_count=%d\n",
937 spin_unlock_irqrestore(&ha->hardware_lock, flags);
951 "Already in tgt->tgt_stop or tgt_stopped state\n");
965 qlt_clear_tgt_db(tgt,
true);
966 spin_unlock_irqrestore(&ha->hardware_lock, flags);
972 "Waiting for sess works (tgt %p)", tgt);
982 "Waiting for tgt %p: list_empty(sess_list)=%d "
983 "sess_count=%d\n", tgt, list_empty(&tgt->
sess_list),
989 if (!ha->
flags.host_shutting_down && qla_tgt_mode_enabled(vha))
1001 unsigned long flags;
1005 "Already in tgt->tgt_stopped state\n");
1011 "Waiting for %d IRQ commands to complete (tgt %p)",
1017 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1023 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1042 "Release of tgt %p finished\n", tgt);
1048 static int qlt_sched_sess_work(
struct qla_tgt *tgt,
int type,
1052 unsigned long flags;
1057 "qla_target(%d): Unable to create session "
1058 "work, command will be refused", 0);
1063 "Scheduling work (type %d, prm %p)"
1064 " to find session for param %p (size %d, tgt %p)\n",
1065 type, prm, param, param_size, tgt);
1100 "qla_target(%d): %s failed: unable to allocate "
1101 "request packet\n", vha->
vp_idx, __func__);
1106 ha->
tgt.qla_tgt->notify_ack_expected++;
1114 nack->
u.
isp24.nport_handle = ntfy->
u.
isp24.nport_handle;
1121 nack->
u.
isp24.status_subcode = ntfy->
u.
isp24.status_subcode;
1122 nack->
u.
isp24.exchange_address = ntfy->
u.
isp24.exchange_address;
1123 nack->
u.
isp24.srr_rel_offs = ntfy->
u.
isp24.srr_rel_offs;
1127 nack->
u.
isp24.srr_reject_code_expl = srr_explan;
1131 "qla_target(%d): Sending 24xx Notify Ack %d\n",
1140 static void qlt_24xx_send_abts_resp(
struct scsi_qla_host *vha,
1150 "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n",
1160 "qla_target(%d): %s failed: unable to allocate "
1161 "request packet", vha->
vp_idx, __func__);
1209 ha->
tgt.qla_tgt->abts_resp_expected++;
1217 static void qlt_24xx_retry_term_exchange(
struct scsi_qla_host *vha,
1223 "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha->
hw);
1231 "qla_target(%d): %s failed: unable to allocate "
1232 "request packet\n", vha->
vp_idx, __func__);
1263 static int __qlt_24xx_handle_abts(
struct scsi_qla_host *vha,
1271 "qla_target(%d): task abort (tag=%d)\n",
1277 "qla_target(%d): %s: Allocation of ABORT cmd failed",
1281 memset(mcmd, 0,
sizeof(*mcmd));
1290 "qla_target(%d): tgt_ops->handle_tmr()"
1291 " failed: %d", vha->
vp_idx, rc);
1313 "qla_target(%d): ABTS: Abort Sequence not "
1314 "supported\n", vha->
vp_idx);
1321 "qla_target(%d): ABTS: Unknown Exchange "
1322 "Address received\n", vha->
vp_idx);
1328 "qla_target(%d): task abort (s_id=%x:%x:%x, "
1337 sess = ha->
tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
1340 "qla_target(%d): task abort for non-existant session\n",
1342 rc = qlt_sched_sess_work(ha->
tgt.qla_tgt,
1351 rc = __qlt_24xx_handle_abts(vha, abts, sess);
1354 "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n",
1364 static void qlt_24xx_send_task_mgmt_ctio(
struct scsi_qla_host *ha,
1371 "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n",
1372 ha, atio, resp_code);
1381 "qla_target(%d): %s failed: unable to allocate "
1382 "request packet\n", ha->
vp_idx, __func__);
1403 ctio->
u.
status1.sense_data[0] = resp_code;
1419 unsigned long flags;
1422 "TM response mcmd (%p) status %#x state %#x",
1434 qlt_24xx_send_task_mgmt_ctio(vha, mcmd,
1445 ha->
tgt.tgt_ops->free_mcmd(mcmd);
1446 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1451 static int qlt_pci_map_calc_cnt(
struct qla_tgt_prm *prm)
1463 prm->
cmd->sg_mapped = 1;
1469 if (prm->
seg_cnt > prm->
tgt->datasegs_per_cmd)
1471 prm->
tgt->datasegs_per_cmd, prm->
tgt->datasegs_per_cont);
1479 "qla_target(%d): PCI mapping failed: sg_cnt=%d",
1480 0, prm->
cmd->sg_cnt);
1494 static int qlt_check_reserve_free_req(
struct scsi_qla_host *vha,
1501 if (vha->
req->cnt < (req_cnt + 2)) {
1505 "Request ring circled: cnt=%d, vha->->ring_index=%d, "
1506 "vha->req->cnt=%d, req_cnt=%d\n", cnt,
1507 vha->
req->ring_index, vha->
req->cnt, req_cnt);
1508 if (vha->
req->ring_index < cnt)
1509 vha->
req->cnt = cnt - vha->
req->ring_index;
1511 vha->
req->cnt = vha->
req->length -
1512 (vha->
req->ring_index -
cnt);
1517 "qla_target(%d): There is no room in the "
1518 "request ring: vha->req->ring_index=%d, vha->req->cnt=%d, "
1519 "req_cnt=%d\n", vha->
vp_idx, vha->
req->ring_index,
1520 vha->
req->cnt, req_cnt);
1523 vha->
req->cnt -= req_cnt;
1531 static inline void *qlt_get_req_pkt(
struct scsi_qla_host *vha)
1534 vha->
req->ring_index++;
1535 if (vha->
req->ring_index == vha->
req->length) {
1536 vha->
req->ring_index = 0;
1537 vha->
req->ring_ptr = vha->
req->ring;
1539 vha->
req->ring_ptr++;
1550 h = ha->
tgt.current_handle;
1556 if (h == ha->
tgt.current_handle) {
1558 "qla_target(%d): Ran out of "
1559 "empty cmd slots in ha %p\n", vha->
vp_idx, ha);
1568 ha->
tgt.current_handle =
h;
1574 static int qlt_24xx_build_ctio_pkt(
struct qla_tgt_prm *prm,
1584 memset(pkt, 0,
sizeof(*pkt));
1590 h = qlt_make_handle(vha);
1599 ha->
tgt.cmds[h-1] = prm->
cmd;
1613 "qla_target(%d): handle(cmd) -> %08x, timeout %d, ox_id %#x\n",
1623 static void qlt_load_cont_data_segments(
struct qla_tgt_prm *prm,
1628 int enable_64bit_addressing = prm->
tgt->tgt_enable_64bit_addr;
1642 memset(cont_pkt64, 0,
sizeof(*cont_pkt64));
1647 if (enable_64bit_addressing) {
1660 cnt < prm->
tgt->datasegs_per_cont && prm->
seg_cnt;
1665 if (enable_64bit_addressing) {
1674 "S/G Segment Cont. phys_addr=%llx:%llx, len=%d\n",
1675 (
long long unsigned int)
1677 (
long long unsigned int)
1690 static void qlt_load_data_segments(
struct qla_tgt_prm *prm,
1695 int enable_64bit_addressing = prm->
tgt->tgt_enable_64bit_addr;
1699 "iocb->scsi_status=%x, iocb->flags=%x\n",
1706 dword_ptr = pkt24->
u.
status0.dseg_0_address;
1724 (cnt < prm->
tgt->datasegs_per_cmd) && prm->
seg_cnt;
1728 if (enable_64bit_addressing) {
1736 "S/G Segment phys_addr=%llx:%llx, len=%d\n",
1746 qlt_load_cont_data_segments(prm, vha);
1749 static inline int qlt_has_data(
struct qla_tgt_cmd *cmd)
1757 static int qlt_pre_xmit_response(
struct qla_tgt_cmd *cmd,
1768 "qla_target(%d): terminating exchange "
1769 "for aborted cmd=%p (se_cmd=%p, tag=%d)", vha->
vp_idx, cmd,
1774 qlt_send_term_exchange(vha, cmd, &cmd->
atio, 0);
1803 if (qlt_pci_map_calc_cnt(prm) != 0)
1812 "Residual underflow: %d (tag %d, "
1813 "op %x, bufflen %d, rq_result %x)\n", prm->
residual,
1820 "Residual overflow: %d (tag %d, "
1821 "op %x, bufflen %d, rq_result %x)\n", prm->
residual,
1832 if (qlt_has_data(cmd)) {
1843 "req_cnt=%d, full_req_cnt=%d, add_status_pkt=%d\n",
1849 static inline int qlt_need_explicit_conf(
struct qla_hw_data *ha,
1852 if (ha->
tgt.enable_class_2)
1858 return ha->
tgt.enable_explicit_conf &&
1862 #ifdef CONFIG_QLA_TGT_DEBUG_SRR
1866 static unsigned long qlt_srr_random(
void)
1869 static unsigned long RandomValue;
1875 unsigned long flags;
1885 rv = 16807 * lo - 2836 * hi;
1889 spin_unlock_irqrestore(&lock, flags);
1893 static void qlt_check_srr_debug(
struct qla_tgt_cmd *cmd,
int *xmit_type)
1896 if ((*xmit_type & QLA_TGT_XMIT_STATUS) && (qlt_srr_random() % 200)
1898 *xmit_type &= ~QLA_TGT_XMIT_STATUS;
1900 "Dropping cmd %p (tag %d) status", cmd, cmd->
tag);
1910 if (qlt_has_data(cmd) && (cmd->
sg_cnt > 1) &&
1911 ((qlt_srr_random() % 100) == 20)) {
1913 unsigned int tot_len = 0;
1916 leave = qlt_srr_random() % cmd->
sg_cnt;
1918 for (i = 0; i <
leave; i++)
1919 tot_len += cmd->
sg[i].length;
1922 "Cutting cmd %p (tag %d) buffer"
1923 " tail to len %d, sg_cnt %d (cmd->bufflen %d,"
1924 " cmd->sg_cnt %d)", cmd, cmd->
tag, tot_len, leave,
1931 if (qlt_has_data(cmd) && ((qlt_srr_random() % 100) == 70)) {
1935 "Cutting cmd %p (tag %d) buffer head "
1936 "to offset %d (cmd->bufflen %d)", cmd, cmd->
tag, offset,
1939 *xmit_type &= ~QLA_TGT_XMIT_DATA;
1940 else if (qlt_set_data_offset(cmd, offset)) {
1942 "qlt_set_data_offset() failed (tag %d)", cmd->
tag);
1947 static inline void qlt_check_srr_debug(
struct qla_tgt_cmd *cmd,
int *xmit_type)
1951 static void qlt_24xx_init_ctio_to_isp(
struct ctio7_to_24xx *ctio,
1958 if (qlt_need_explicit_conf(prm->
tgt->ha, prm->
cmd, 0)) {
1968 if (qlt_need_explicit_conf(prm->
tgt->ha, prm->
cmd, 1)) {
1969 if (prm->
cmd->se_cmd.scsi_status != 0) {
1971 "Skipping EXPLICIT_CONFORM and "
1972 "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ "
1973 "non GOOD status\n");
1974 goto skip_explict_conf;
1997 "qla_target(%d): %d bytes of sense "
1998 "lost", prm->
tgt->ha->vp_idx,
2011 sizeof(ctio->
u.
status1.sense_data));
2029 unsigned long flags = 0;
2032 memset(&prm, 0,
sizeof(prm));
2033 qlt_check_srr_debug(cmd, &xmit_type);
2036 "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, "
2037 "cmd->dma_data_direction=%d\n", (xmit_type & QLA_TGT_XMIT_STATUS) ?
2040 res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status,
2052 res = qlt_check_reserve_free_req(vha, full_req_cnt);
2054 goto out_unmap_unlock;
2056 res = qlt_24xx_build_ctio_pkt(&prm, vha);
2058 goto out_unmap_unlock;
2068 qlt_load_data_segments(&prm, vha);
2071 if (xmit_type & QLA_TGT_XMIT_STATUS) {
2078 if (qlt_need_explicit_conf(ha, cmd, 0)) {
2096 "Building additional status packet\n");
2098 memcpy(ctio, pkt,
sizeof(*ctio));
2110 pr_debug(
"Status CTIO7: %p\n", ctio);
2113 qlt_24xx_init_ctio_to_isp(pkt, &prm);
2119 "Xmitting CTIO7 response pkt for 24xx: %p scsi_status: 0x%02x\n",
2123 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2129 qlt_unmap_sg(vha, cmd);
2130 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2143 unsigned long flags;
2146 memset(&prm, 0,
sizeof(prm));
2160 if (qlt_pci_map_calc_cnt(&prm) != 0)
2166 res = qlt_check_reserve_free_req(vha, prm.
req_cnt);
2168 goto out_unlock_free_unmap;
2170 res = qlt_24xx_build_ctio_pkt(&prm, vha);
2172 goto out_unlock_free_unmap;
2176 qlt_load_data_segments(&prm, vha);
2181 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2185 out_unlock_free_unmap:
2187 qlt_unmap_sg(vha, cmd);
2188 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2196 static int __qlt_send_term_exchange(
struct scsi_qla_host *vha,
2210 "qla_target(%d): %s failed: unable to allocate "
2211 "request packet\n", vha->
vp_idx, __func__);
2218 "qla_target(%d): Terminating cmd %p with "
2219 "incorrect state %d\n", vha->
vp_idx, cmd,
2244 &atio->
u.
isp24.fcp_cmnd.add_cdb[
2245 atio->
u.
isp24.fcp_cmnd.add_cdb_len]);
2246 if (ctio24->
u.
status1.residual != 0)
2253 static void qlt_send_term_exchange(
struct scsi_qla_host *vha,
2256 unsigned long flags;
2259 if (qlt_issue_marker(vha, ha_locked) < 0)
2263 rc = __qlt_send_term_exchange(vha, cmd, atio);
2267 rc = __qlt_send_term_exchange(vha, cmd, atio);
2268 spin_unlock_irqrestore(&vha->
hw->hardware_lock, flags);
2274 vha->
hw->tgt.tgt_ops->free_cmd(cmd);
2300 "qla_target(%d): CTIO with SRR status received\n", vha->
vp_idx);
2304 "qla_target(%d): SRR CTIO, but ctio is NULL\n",
2318 "CTIO SRR %p added (id %d)\n", sc, sc->
srr_id);
2330 "Scheduling srr work\n");
2334 "qla_target(%d): imm_srr_id "
2335 "== ctio_srr_id (%d), but there is no "
2336 "corresponding SRR IMM, deleting CTIO "
2351 "qla_target(%d): Unable to allocate SRR CTIO entry\n",
2358 "IMM SRR %p deleted (id %d)\n",
2361 qlt_reject_free_srr_imm(vha, imm, 1);
2375 static int qlt_term_ctio_exchange(
struct scsi_qla_host *vha,
void *ctio,
2388 qlt_send_term_exchange(vha, cmd, &cmd->
atio, 1);
2400 if (ha->
tgt.cmds[handle] !=
NULL) {
2421 "SKIP_HANDLE CTIO\n");
2427 "qla_target(%d): Wrong handle %x received\n",
2431 cmd = qlt_get_cmd(vha, handle);
2434 "qla_target(%d): Suspicious: unable to "
2435 "find the command with handle %x\n", vha->
vp_idx,
2439 }
else if (ctio !=
NULL) {
2442 "qla_target(%d): Wrong CTIO received: QLA24xx doesn't "
2443 "support NULL handles\n", vha->
vp_idx);
2457 struct se_cmd *se_cmd;
2462 "qla_target(%d): handle(ctio %p status %#x) <- %08x\n",
2463 vha->
vp_idx, ctio, status, handle);
2469 "Intermediate CTIO received"
2470 " (status %x)\n", status);
2475 cmd = qlt_ctio_to_cmd(vha, handle, ctio);
2483 qlt_unmap_sg(vha, cmd);
2486 switch (status & 0xFFFF) {
2494 "qla_target(%d): CTIO with "
2495 "status %#x received, state %x, se_cmd %p, "
2496 "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, "
2497 "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->
vp_idx,
2498 status, cmd->
state, se_cmd);
2504 "qla_target(%d): CTIO with PORT LOGGED "
2505 "OUT (29) or PORT UNAVAILABLE (28) status %x "
2506 "received (state %x, se_cmd %p)\n", vha->
vp_idx,
2507 status, cmd->
state, se_cmd);
2512 "qla_target(%d): CTIO with SRR_RECEIVED"
2513 " status %x received (state %x, se_cmd %p)\n",
2515 if (qlt_prepare_srr_ctio(vha, cmd, ctio) != 0)
2522 "qla_target(%d): CTIO with error status "
2523 "0x%x received (state %x, se_cmd %p\n",
2529 if (qlt_term_ctio_exchange(vha, ctio, cmd, status))
2546 "Data received, context %x, rx_status %d\n",
2549 ha->
tgt.tgt_ops->handle_data(cmd);
2553 "Aborted command %p (tag %d) finished\n", cmd, cmd->
tag);
2556 "qla_target(%d): A command in state (%d) should "
2557 "not return a CTIO complete\n", vha->
vp_idx, cmd->
state);
2565 ha->
tgt.tgt_ops->free_cmd(cmd);
2577 "CTIO, but target mode not enabled"
2578 " (ha %d %p handle %#x)", vha->
vp_idx, ha, handle);
2587 static inline int qlt_get_fcp_task_attr(
struct scsi_qla_host *vha,
2592 switch (task_codes) {
2610 "qla_target: unknown task code %x, use ORDERED instead\n",
2616 return fcp_task_attr;
2633 unsigned long flags;
2641 sess = ha->
tgt.tgt_ops->find_sess_by_s_id(vha,
2642 atio->
u.
isp24.fcp_hdr.s_id);
2645 kref_get(&sess->
se_sess->sess_kref);
2646 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2652 "qla_target(%d): Unable to find wwn login"
2653 " (s_id %x:%x:%x), trying to create it manually\n",
2654 vha->
vp_idx, s_id[0], s_id[1], s_id[2]);
2656 if (atio->
u.
raw.entry_count > 1) {
2658 "Dropping multy entry cmd %p\n", cmd);
2663 sess = qlt_make_local_sess(vha, s_id);
2675 cdb = &atio->
u.
isp24.fcp_cmnd.cdb[0];
2680 if (atio->
u.
isp24.fcp_cmnd.rddata &&
2681 atio->
u.
isp24.fcp_cmnd.wrdata) {
2684 }
else if (atio->
u.
isp24.fcp_cmnd.rddata)
2686 else if (atio->
u.
isp24.fcp_cmnd.wrdata)
2691 fcp_task_attr = qlt_get_fcp_task_attr(vha,
2692 atio->
u.
isp24.fcp_cmnd.task_attr);
2694 &atio->
u.
isp24.fcp_cmnd.add_cdb[
2695 atio->
u.
isp24.fcp_cmnd.add_cdb_len]));
2698 "qla_target: START qla command: %p lun: 0x%04x (tag %d)\n",
2701 ret = vha->
hw->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length,
2702 fcp_task_attr, data_dir, bidi);
2708 ha->
tgt.tgt_ops->put_sess(sess);
2718 qlt_send_term_exchange(vha,
NULL, &cmd->
atio, 1);
2720 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2722 ha->
tgt.tgt_ops->put_sess(sess);
2726 static int qlt_handle_cmd_for_atio(
struct scsi_qla_host *vha,
2735 "New command while device %p is shutting down\n", tgt);
2739 cmd = kmem_cache_zalloc(qla_tgt_cmd_cachep,
GFP_ATOMIC);
2742 "qla_target(%d): Allocation of cmd failed\n", vha->
vp_idx);
2750 cmd->
tgt = ha->
tgt.qla_tgt;
2761 int fn,
void *iocb,
int flags)
2772 "qla_target(%d): Allocation of management "
2773 "command failed, some commands and their data could "
2777 memset(mcmd, 0,
sizeof(*mcmd));
2790 "qla_target(%d): CLEAR_ACA received\n", sess->
vha->vp_idx);
2796 "qla_target(%d): TARGET_RESET received\n",
2803 "qla_target(%d): LUN_RESET received\n", sess->
vha->vp_idx);
2809 "qla_target(%d): CLEAR_TS received\n", sess->
vha->vp_idx);
2815 "qla_target(%d): ABORT_TS received\n", sess->
vha->vp_idx);
2821 "qla_target(%d): Doing ABORT_ALL_TASKS\n",
2828 "qla_target(%d): Doing ABORT_ALL_TASKS_SESS\n",
2835 "qla_target(%d): Doing NEXUS_LOSS_SESS\n",
2842 "qla_target(%d): Doing NEXUS_LOSS\n", sess->
vha->vp_idx);
2848 "qla_target(%d): Unknown task mgmt fn 0x%x\n",
2849 sess->
vha->vp_idx, fn);
2854 res = ha->
tgt.tgt_ops->handle_tmr(mcmd, lun, tmr_func, 0);
2857 "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n",
2858 sess->
vha->vp_idx, res);
2867 static int qlt_handle_task_mgmt(
struct scsi_qla_host *vha,
void *iocb)
2876 tgt = ha->
tgt.qla_tgt;
2878 lun = a->
u.
isp24.fcp_cmnd.lun;
2879 lun_size =
sizeof(a->
u.
isp24.fcp_cmnd.lun);
2880 fn = a->
u.
isp24.fcp_cmnd.task_mgmt_flags;
2881 sess = ha->
tgt.tgt_ops->find_sess_by_s_id(vha,
2882 a->
u.
isp24.fcp_hdr.s_id);
2887 "qla_target(%d): task mgmt fn 0x%x for "
2888 "non-existant session\n", vha->
vp_idx, fn);
2893 return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0);
2909 "qla_target(%d): %s: Allocation of ABORT cmd failed\n",
2913 memset(mcmd, 0,
sizeof(*mcmd));
2919 lun = a->
u.
isp24.fcp_cmnd.lun;
2926 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
2945 sess = ha->
tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id);
2948 "qla_target(%d): task abort for unexisting "
2949 "session\n", vha->
vp_idx);
2950 return qlt_sched_sess_work(ha->
tgt.qla_tgt,
2954 return __qlt_abort_task(vha, iocb, sess);
2967 "qla_target(%d): Port ID: 0x%02x:%02x:%02x"
2968 " ELS opcode: 0x%02x\n", vha->
vp_idx, iocb->
u.
isp24.port_id[0],
2970 iocb->
u.
isp24.status_subcode);
2972 switch (iocb->
u.
isp24.status_subcode) {
2995 "qla_target(%d): Unsupported ELS command %x "
2996 "received\n", vha->
vp_idx, iocb->
u.
isp24.status_subcode);
3007 size_t first_offset = 0, rem_offset =
offset,
tmp = 0;
3011 "Entering qla_tgt_set_data_offset: cmd: %p, cmd->sg: %p, "
3012 "cmd->sg_cnt: %u, direction: %d\n",
3019 pr_debug(
"Rejecting non zero SRR rel_offs: %u\n", offset);
3024 "Missing cmd->sg or zero cmd->sg_cnt in"
3025 " qla_tgt_set_data_offset\n");
3033 "sg[%d]: %p page: %p, length: %d, offset: %d\n",
3036 if ((sg->
length + tmp) > offset) {
3037 first_offset = rem_offset;
3040 "Found matching sg[%d], using %p as sg_srr_start, "
3041 "and using first_offset: %zu\n", i, sg,
3046 rem_offset -= sg->
length;
3049 if (!sg_srr_start) {
3051 "Unable to locate sg_srr_start for offset: %u\n", offset);
3054 sg_srr_cnt = (cmd->
sg_cnt -
i);
3059 "Unable to allocate sgp\n");
3070 sg_set_page(sgp, sg_page(sg),
3071 (sg->
length - first_offset), first_offset);
3074 sg_set_page(sgp, sg_page(sg), sg->
length, 0);
3084 cmd->
sg_cnt = sg_srr_cnt;
3106 static inline int qlt_srr_adjust_data(
struct qla_tgt_cmd *cmd,
3107 uint32_t srr_rel_offs,
int *xmit_type)
3109 int res = 0, rel_offs;
3111 rel_offs = srr_rel_offs - cmd->
offset;
3113 srr_rel_offs, rel_offs);
3119 "qla_target(%d): SRR rel_offs (%d) < 0",
3120 cmd->
vha->vp_idx, rel_offs);
3122 }
else if (rel_offs == cmd->
bufflen)
3124 else if (rel_offs > 0)
3125 res = qlt_set_data_offset(cmd, rel_offs);
3138 struct se_cmd *se_cmd = &cmd->
se_cmd;
3139 unsigned long flags;
3140 int xmit_type = 0, resp = 0;
3153 qlt_send_notify_ack(vha, ntfy,
3155 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3162 "Unable to process SRR_IU_DATA_IN due to"
3163 " missing cmd->sg, state: %d\n", cmd->
state);
3169 "Rejecting SRR_IU_DATA_IN with non GOOD "
3175 if (qlt_has_data(cmd)) {
3176 if (qlt_srr_adjust_data(cmd, offset, &xmit_type) != 0)
3179 qlt_send_notify_ack(vha, ntfy,
3181 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3185 "qla_target(%d): SRR for in data for cmd "
3186 "without them (tag %d, SCSI status %d), "
3188 cmd->
se_cmd.scsi_status);
3195 "Unable to process SRR_IU_DATA_OUT due to"
3196 " missing cmd->sg\n");
3202 "Rejecting SRR_IU_DATA_OUT"
3203 " with non GOOD scsi_status\n");
3208 if (qlt_has_data(cmd)) {
3209 if (qlt_srr_adjust_data(cmd, offset, &xmit_type) != 0)
3212 qlt_send_notify_ack(vha, ntfy,
3214 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3215 if (xmit_type & QLA_TGT_XMIT_DATA)
3219 "qla_target(%d): SRR for out data for cmd "
3220 "without them (tag %d, SCSI status %d), "
3222 cmd->
se_cmd.scsi_status);
3228 "qla_target(%d): Unknown srr_ui value %x",
3241 qlt_send_notify_ack(vha, ntfy, 0, 0, 0,
3249 qlt_send_term_exchange(vha, cmd, &cmd->
atio, 1);
3250 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3253 static void qlt_reject_free_srr_imm(
struct scsi_qla_host *vha,
3257 unsigned long flags = 0;
3262 qlt_send_notify_ack(vha, (
void *)&imm->
imm_ntfy, 0, 0, 0,
3268 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3273 static void qlt_handle_srr_work(
struct work_struct *work)
3278 unsigned long flags;
3288 struct se_cmd *se_cmd;
3297 "qla_target(%d): There must be "
3298 "only one IMM SRR per CTIO SRR "
3299 "(IMM SRR %p, id %d, CTIO %p\n",
3301 qlt_reject_free_srr_imm(tgt->
vha, i, 0);
3308 "IMM SRR %p, CTIO SRR %p (id %d)\n", imm, sctio,
3313 "Not found matching IMM for SRR CTIO (id %d)\n",
3319 spin_unlock_irqrestore(&tgt->
srr_lock, flags);
3339 "SRR cmd %p (se_cmd %p, tag %d, op %x), "
3340 "sg_cnt=%d, offset=%d", cmd, &cmd->
se_cmd, cmd->
tag,
3343 qlt_handle_srr(vha, sctio, imm);
3349 spin_unlock_irqrestore(&tgt->
srr_lock, flags);
3376 "IMM NTFY SRR %p added (id %d, ui %x)\n",
3389 "Scheduling srr work\n");
3393 "qla_target(%d): imm_srr_id "
3394 "== ctio_srr_id (%d), but there is no "
3395 "corresponding SRR CTIO, deleting IMM "
3411 "qla_target(%d): Unable to allocate SRR IMM "
3412 "entry, SRR request will be rejected\n", vha->
vp_idx);
3420 "CTIO SRR %p deleted (id %d)\n",
3423 qlt_send_term_exchange(vha, sctio->
cmd,
3424 &sctio->
cmd->atio, 1);
3435 qlt_send_notify_ack(vha, iocb, 0, 0, 0,
3444 static void qlt_handle_imm_notify(
struct scsi_qla_host *vha,
3449 int send_notify_ack = 1;
3457 "qla_target(%d): LIP reset (loop %#x), subcode %x\n",
3459 iocb->
u.
isp24.status_subcode);
3462 send_notify_ack = 0;
3470 "qla_target(%d): LINK REINIT (loop %#x, "
3471 "subcode %x)\n", vha->
vp_idx,
3473 iocb->
u.
isp24.status_subcode);
3484 send_notify_ack = 0;
3490 "qla_target(%d): Port logout (loop "
3491 "%#x, subcode %x)\n", vha->
vp_idx,
3493 iocb->
u.
isp24.status_subcode);
3496 send_notify_ack = 0;
3502 "qla_target(%d): Global TPRLO (%x)\n", vha->
vp_idx, status);
3504 send_notify_ack = 0;
3510 "qla_target(%d): Port config changed (%x)\n", vha->
vp_idx,
3513 send_notify_ack = 0;
3519 "qla_target(%d): Link failure detected\n",
3523 send_notify_ack = 0;
3528 "qla_target(%d): Cannot provide requested "
3529 "capability (IOCB overflowed the immediate notify "
3530 "resource count)\n", vha->
vp_idx);
3535 "qla_target(%d): Abort Task (S %08x I %#x -> "
3540 if (qlt_abort_task(vha, iocb) == 0)
3541 send_notify_ack = 0;
3546 "qla_target(%d): Out of resources, host %ld\n",
3552 "qla_target(%d): Immediate notify task %x\n",
3554 if (qlt_handle_task_mgmt(vha, iocb) == 0)
3555 send_notify_ack = 0;
3559 if (qlt_24xx_handle_els(vha, iocb) == 0)
3560 send_notify_ack = 0;
3564 qlt_prepare_srr_imm(vha, iocb);
3565 send_notify_ack = 0;
3570 "qla_target(%d): Received unknown immediate "
3571 "notify status %x\n", vha->
vp_idx, status);
3575 if (send_notify_ack)
3576 qlt_send_notify_ack(vha, iocb, add_flags, 0, 0, 0, 0, 0);
3591 sess = ha->
tgt.tgt_ops->find_sess_by_s_id(vha,
3592 atio->
u.
isp24.fcp_hdr.s_id);
3594 qlt_send_term_exchange(vha,
NULL, atio, 1);
3602 "qla_target(%d): %s failed: unable to allocate "
3603 "request packet", vha->
vp_idx, __func__);
3630 &atio->
u.
isp24.fcp_cmnd.add_cdb[
3631 atio->
u.
isp24.fcp_cmnd.add_cdb_len]);
3632 if (ctio24->
u.
status1.residual != 0)
3649 "ATIO pkt, but no tgt (ha %p)", ha);
3653 "qla_target(%d): ATIO pkt %p: type %02x count %02x",
3655 atio->
u.
raw.entry_count);
3663 switch (atio->
u.
raw.entry_type) {
3666 "ATIO_TYPE7 instance %d, lun %Lx, read/write %d/%d, "
3667 "add_cdb_len %d, data_length %04x, s_id %x:%x:%x\n",
3669 atio->
u.
isp24.fcp_cmnd.rddata,
3670 atio->
u.
isp24.fcp_cmnd.wrdata,
3671 atio->
u.
isp24.fcp_cmnd.add_cdb_len,
3673 &atio->
u.
isp24.fcp_cmnd.add_cdb[
3674 atio->
u.
isp24.fcp_cmnd.add_cdb_len])),
3675 atio->
u.
isp24.fcp_hdr.s_id[0],
3676 atio->
u.
isp24.fcp_hdr.s_id[1],
3677 atio->
u.
isp24.fcp_hdr.s_id[2]);
3682 "qla_target(%d): ATIO_TYPE7 "
3683 "received with UNKNOWN exchange address, "
3684 "sending QUEUE_FULL\n", vha->
vp_idx);
3688 if (
likely(atio->
u.
isp24.fcp_cmnd.task_mgmt_flags == 0))
3689 rc = qlt_handle_cmd_for_atio(vha, atio);
3691 rc = qlt_handle_task_mgmt(vha, atio);
3697 qlt_send_term_exchange(vha,
NULL, atio, 1);
3702 "qla_target: Unable to send "
3703 "command to target for req, "
3707 "qla_target(%d): Unable to send "
3708 "command to target, sending BUSY "
3709 "status.\n", vha->
vp_idx);
3720 "qla_target(%d): Received ATIO packet %x "
3721 "with error status %x\n", vha->
vp_idx,
3722 atio->
u.
raw.entry_type,
3723 atio->
u.
isp2x.entry_status);
3733 "qla_target(%d): Received unknown ATIO atio "
3734 "type %x\n", vha->
vp_idx, atio->
u.
raw.entry_type);
3750 "qla_target(%d): Response pkt %x received, but no "
3756 "qla_target(%d): response pkt %p: T %02x C %02x S %02x "
3773 qlt_do_ctio_completion(vha, entry->
handle,
3784 "ACCEPT_TGT_IO instance %d status %04x "
3785 "lun %04x read/write %d data_length %04x "
3786 "target_id %02x rx_id %04x\n ", vha->
vp_idx,
3789 atio->
u.
isp2x.execution_codes,
3791 atio), atio->
u.
isp2x.rx_id);
3792 if (atio->
u.
isp2x.status !=
3795 "qla_target(%d): ATIO with error "
3796 "status %x received\n", vha->
vp_idx,
3801 "FCP CDB: 0x%02x, sizeof(cdb): %lu",
3802 atio->
u.
isp2x.cdb[0], (
unsigned long
3803 int)
sizeof(atio->
u.
isp2x.cdb));
3805 rc = qlt_handle_cmd_for_atio(vha, atio);
3809 qlt_send_busy(vha, atio, 0);
3811 qlt_send_term_exchange(vha,
NULL, atio, 1);
3816 "qla_target: Unable to send "
3817 "command to target, sending TERM "
3818 "EXCHANGE for rsp\n");
3819 qlt_send_term_exchange(vha,
NULL,
3823 "qla_target(%d): Unable to send "
3824 "command to target, sending BUSY "
3825 "status\n", vha->
vp_idx);
3826 qlt_send_busy(vha, atio, 0);
3837 "CONTINUE_TGT_IO: instance %d\n", vha->
vp_idx);
3838 qlt_do_ctio_completion(vha, entry->
handle,
3849 qlt_do_ctio_completion(vha, entry->
handle,
3864 "NOTIFY_ACK seq %08x status %x\n",
3868 if (entry->
u.
isp2x.status !=
3871 "qla_target(%d): NOTIFY_ACK "
3872 "failed %x\n", vha->
vp_idx,
3877 "qla_target(%d): Unexpected NOTIFY_ACK received\n",
3884 "ABTS_RECV_24XX: instance %d\n", vha->
vp_idx);
3893 "ABTS_RESP_24XX: compl_status %x\n",
3915 qlt_24xx_retry_term_exchange(vha,
3919 "qla_target(%d): ABTS_RESP_24XX "
3920 "failed %x (subcode %x:%x)",
3927 "qla_target(%d): Unexpected ABTS_RESP_24XX "
3928 "received\n", vha->
vp_idx);
3934 "qla_target(%d): Received unknown response pkt "
3953 "scsi(%ld): ha state %d init_done %d oper_mode %d topo %d\n",
3957 if (!ha->
tgt.tgt_ops)
3962 "ASYNC EVENT %#x, but no tgt (ha %p)\n", code, ha);
3982 "qla_target(%d): System error async event %#x "
3983 "occured", vha->
vp_idx, code);
3992 "qla_target(%d): Async LOOP_UP occured "
3993 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->
vp_idx,
4009 "qla_target(%d): Async event %#x occured "
4010 "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->
vp_idx, code,
4017 "qla_target(%d): Port update async event %#x "
4018 "occured: updating the ports database (m[0]=%x, m[1]=%x, "
4019 "m[2]=%x, m[3]=%x)", vha->
vp_idx, code,
4024 if (login_code == 0x4)
4026 "Async MB 2: Got PLOGI Complete\n");
4027 else if (login_code == 0x7)
4029 "Async MB 2: Port Logged Out\n");
4034 "qla_target(%d): Async event %#x occured: "
4035 "ignore (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->
vp_idx,
4050 fcport = kzalloc(
sizeof(*fcport),
GFP_KERNEL);
4053 "qla_target(%d): Allocation of tmp FC port failed",
4065 "qla_target(%d): Failed to retrieve fcport "
4066 "information -- get_port_database() returned %x "
4067 "(loop_id=0x%04x)", vha->
vp_idx, rc, loop_id);
4082 int rc, global_resets;
4086 global_resets =
atomic_read(&ha->
tgt.qla_tgt->tgt_global_resets_count);
4088 rc = qla24xx_get_loop_id(vha, s_id, &loop_id);
4090 if ((s_id[0] == 0xFF) &&
4091 (s_id[1] == 0xFC)) {
4097 "Unable to find initiator with S_ID %x:%x:%x",
4098 s_id[0], s_id[1], s_id[2]);
4101 "qla_target(%d): Unable to find "
4102 "initiator with S_ID %x:%x:%x",
4103 vha->
vp_idx, s_id[0], s_id[1],
4108 fcport = qlt_get_port_database(vha, loop_id);
4112 if (global_resets !=
4115 "qla_target(%d): global reset during session discovery "
4116 "(counter was %d, new %d), retrying", vha->
vp_idx,
4122 sess = qlt_create_sess(vha, fcport,
true);
4128 static void qlt_abort_work(
struct qla_tgt *tgt,
4134 unsigned long flags;
4144 s_id[0] = prm->
abts.fcp_hdr_le.s_id[2];
4145 s_id[1] = prm->
abts.fcp_hdr_le.s_id[1];
4146 s_id[2] = prm->
abts.fcp_hdr_le.s_id[0];
4148 sess = ha->
tgt.tgt_ops->find_sess_by_s_id(vha,
4149 (
unsigned char *)&be_s_id);
4151 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4154 sess = qlt_make_local_sess(vha, s_id);
4162 kref_get(&sess->
se_sess->sess_kref);
4168 rc = __qlt_24xx_handle_abts(vha, &prm->
abts, sess);
4171 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4173 ha->
tgt.tgt_ops->put_sess(sess);
4178 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4180 ha->
tgt.tgt_ops->put_sess(sess);
4183 static void qlt_tmr_work(
struct qla_tgt *tgt,
4190 unsigned long flags;
4202 s_id = prm->
tm_iocb2.u.isp24.fcp_hdr.s_id;
4203 sess = ha->
tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
4205 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4208 sess = qlt_make_local_sess(vha, s_id);
4216 kref_get(&sess->
se_sess->sess_kref);
4220 lun = a->
u.
isp24.fcp_cmnd.lun;
4221 lun_size =
sizeof(
lun);
4222 fn = a->
u.
isp24.fcp_cmnd.task_mgmt_flags;
4225 rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0);
4228 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4230 ha->
tgt.tgt_ops->put_sess(sess);
4235 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4237 ha->
tgt.tgt_ops->put_sess(sess);
4240 static void qlt_sess_work_fn(
struct work_struct *work)
4244 unsigned long flags;
4262 switch (prm->
type) {
4264 qlt_abort_work(tgt, prm);
4267 qlt_tmr_work(tgt, prm);
4290 "Registering target for host %ld(%p)", base_vha->
host_no, ha);
4297 "Unable to allocate struct qla_tgt\n");
4305 tgt->
vha = base_vha;
4320 ha->
tgt.qla_tgt = tgt;
4323 "qla_target(%d): using 64 Bit PCI addressing",
4341 if (!ha->
tgt.qla_tgt)
4360 pr_debug(
"qla2xxx HW vha->node_name: ");
4364 pr_debug(
"qla2xxx HW vha->port_name: ");
4369 pr_debug(
"qla2xxx passed configfs WWPN: ");
4391 unsigned long flags;
4412 pr_debug(
"MODE_TARGET already active on qla2xxx(%d)\n",
4414 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4417 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4421 "Unable to scsi_host_get() for"
4422 " qla2xxx scsi_host\n");
4425 qlt_lport_dump(vha, wwpn, b);
4434 ha->
tgt.tgt_ops = qla_tgt_ops;
4435 ha->
tgt.target_lport_ptr = target_lport_ptr;
4436 rc = (*callback)(
vha);
4439 ha->
tgt.target_lport_ptr =
NULL;
4462 ha->
tgt.target_lport_ptr =
NULL;
4476 switch (ql2x_ini_mode) {
4488 if (ha->
tgt.ini_mode_force_reverse)
4489 qla_reverse_ini_mode(vha);
4497 switch (ql2x_ini_mode) {
4511 if (ha->
tgt.ini_mode_force_reverse)
4512 qla_reverse_ini_mode(vha);
4525 unsigned long flags;
4529 "Unable to locate qla_tgt pointer from"
4530 " struct qla_hw_data\n");
4538 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4556 unsigned long flags;
4560 "Unable to locate qla_tgt pointer from"
4561 " struct qla_hw_data\n");
4568 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4583 if (!qla_tgt_mode_enabled(vha))
4606 if (qla_tgt_mode_enabled(vha)) {
4607 if (qla_ini_mode_enabled(vha))
4611 }
else if (qla_ini_mode_enabled(vha)) {
4632 if (!qla_tgt_mode_enabled(vha))
4635 for (cnt = 0; cnt < ha->
tgt.atio_q_length; cnt++) {
4654 if (!vha->
flags.online)
4659 cnt = pkt->
u.
raw.entry_count;
4663 for (i = 0; i <
cnt; i++) {
4664 ha->
tgt.atio_ring_index++;
4665 if (ha->
tgt.atio_ring_index == ha->
tgt.atio_q_length) {
4666 ha->
tgt.atio_ring_index = 0;
4667 ha->
tgt.atio_ring_ptr = ha->
tgt.atio_ring;
4669 ha->
tgt.atio_ring_ptr++;
4706 if (qla_tgt_mode_enabled(vha)) {
4707 if (!ha->
tgt.saved_set) {
4710 ha->
tgt.saved_firmware_options_1 =
4712 ha->
tgt.saved_firmware_options_2 =
4714 ha->
tgt.saved_firmware_options_3 =
4716 ha->
tgt.saved_set = 1;
4725 if (!qla_ini_mode_enabled(vha))
4739 if (ha->
tgt.saved_set) {
4742 ha->
tgt.saved_firmware_options_1;
4744 ha->
tgt.saved_firmware_options_2;
4746 ha->
tgt.saved_firmware_options_3;
4754 if (ha->
tgt.enable_class_2) {
4755 if (vha->
flags.init_done)
4761 if (vha->
flags.init_done)
4774 if (ha->
tgt.node_name_set) {
4799 if (qla_tgt_mode_enabled(vha))
4802 if (!qla_ini_mode_enabled(vha))
4825 if (!ha->
tgt.tgt_vp_map)
4831 if (!ha->
tgt.atio_ring) {
4844 if (ha->
tgt.atio_ring) {
4864 vha->
hw->tgt.tgt_vp_map[vha->
d_id.
b.al_pa].idx = vha->
vp_idx;
4870 vha->
hw->tgt.tgt_vp_map[vha->
d_id.
b.al_pa].idx = 0;
4875 static int __init qlt_parse_ini_mode(
void)
4893 if (!qlt_parse_ini_mode()) {
4895 "qlt_parse_ini_mode() failed\n");
4905 if (!qla_tgt_cmd_cachep) {
4907 "kmem_cache_create for qla_tgt_cmd_cachep failed\n");
4914 if (!qla_tgt_mgmt_cmd_cachep) {
4916 "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n");
4923 if (!qla_tgt_mgmt_cmd_mempool) {
4925 "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n");
4927 goto out_mgmt_cmd_cachep;
4933 "alloc_workqueue for qla_tgt_wq failed\n");
4935 goto out_cmd_mempool;
4944 out_mgmt_cmd_cachep: