^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * iSCSI lib functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2004 - 2006 Mike Christie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2004 - 2005 Dmitry Yusupov
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 2004 - 2005 Alex Aizman
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * maintained by open-iscsi@googlegroups.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kfifo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/log2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <net/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <scsi/scsi_eh.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <scsi/scsi_tcq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <scsi/iscsi_proto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <scsi/scsi_transport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <scsi/scsi_transport_iscsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <scsi/libiscsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <trace/events/iscsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static int iscsi_dbg_lib_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) module_param_named(debug_libiscsi_conn, iscsi_dbg_lib_conn, int,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) MODULE_PARM_DESC(debug_libiscsi_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) "Turn on debugging for connections in libiscsi module. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) "Set to 1 to turn on, and zero to turn off. Default is off.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int iscsi_dbg_lib_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) module_param_named(debug_libiscsi_session, iscsi_dbg_lib_session, int,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) MODULE_PARM_DESC(debug_libiscsi_session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) "Turn on debugging for sessions in libiscsi module. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) "Set to 1 to turn on, and zero to turn off. Default is off.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static int iscsi_dbg_lib_eh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) module_param_named(debug_libiscsi_eh, iscsi_dbg_lib_eh, int,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) MODULE_PARM_DESC(debug_libiscsi_eh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) "Turn on debugging for error handling in libiscsi module. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) "Set to 1 to turn on, and zero to turn off. Default is off.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define ISCSI_DBG_CONN(_conn, dbg_fmt, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (iscsi_dbg_lib_conn) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) iscsi_conn_printk(KERN_INFO, _conn, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) "%s " dbg_fmt, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) __func__, ##arg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) iscsi_dbg_trace(trace_iscsi_dbg_conn, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) &(_conn)->cls_conn->dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) "%s " dbg_fmt, __func__, ##arg);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) } while (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define ISCSI_DBG_SESSION(_session, dbg_fmt, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (iscsi_dbg_lib_session) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) iscsi_session_printk(KERN_INFO, _session, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) "%s " dbg_fmt, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) __func__, ##arg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) iscsi_dbg_trace(trace_iscsi_dbg_session, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) &(_session)->cls_session->dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) "%s " dbg_fmt, __func__, ##arg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) } while (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define ISCSI_DBG_EH(_session, dbg_fmt, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (iscsi_dbg_lib_eh) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) iscsi_session_printk(KERN_INFO, _session, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) "%s " dbg_fmt, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) __func__, ##arg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) iscsi_dbg_trace(trace_iscsi_dbg_eh, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) &(_session)->cls_session->dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) "%s " dbg_fmt, __func__, ##arg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) } while (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) inline void iscsi_conn_queue_work(struct iscsi_conn *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct Scsi_Host *shost = conn->session->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct iscsi_host *ihost = shost_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (ihost->workq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) queue_work(ihost->workq, &conn->xmitwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) EXPORT_SYMBOL_GPL(iscsi_conn_queue_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static void __iscsi_update_cmdsn(struct iscsi_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) uint32_t exp_cmdsn, uint32_t max_cmdsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * standard specifies this check for when to update expected and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * max sequence numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (iscsi_sna_lt(max_cmdsn, exp_cmdsn - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (exp_cmdsn != session->exp_cmdsn &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) !iscsi_sna_lt(exp_cmdsn, session->exp_cmdsn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) session->exp_cmdsn = exp_cmdsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (max_cmdsn != session->max_cmdsn &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) !iscsi_sna_lt(max_cmdsn, session->max_cmdsn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) session->max_cmdsn = max_cmdsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) void iscsi_update_cmdsn(struct iscsi_session *session, struct iscsi_nopin *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) __iscsi_update_cmdsn(session, be32_to_cpu(hdr->exp_cmdsn),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) be32_to_cpu(hdr->max_cmdsn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) EXPORT_SYMBOL_GPL(iscsi_update_cmdsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * iscsi_prep_data_out_pdu - initialize Data-Out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * @task: scsi command task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * @r2t: R2T info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * @hdr: iscsi data in pdu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * Notes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * Initialize Data-Out within this R2T sequence and finds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * proper data_offset within this SCSI command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * This function is called with connection lock taken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) void iscsi_prep_data_out_pdu(struct iscsi_task *task, struct iscsi_r2t_info *r2t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct iscsi_data *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct iscsi_conn *conn = task->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) unsigned int left = r2t->data_length - r2t->sent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) task->hdr_len = sizeof(struct iscsi_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) memset(hdr, 0, sizeof(struct iscsi_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) hdr->ttt = r2t->ttt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) hdr->datasn = cpu_to_be32(r2t->datasn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) r2t->datasn++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) hdr->opcode = ISCSI_OP_SCSI_DATA_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) hdr->lun = task->lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) hdr->itt = task->hdr_itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) hdr->exp_statsn = r2t->exp_statsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) hdr->offset = cpu_to_be32(r2t->data_offset + r2t->sent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (left > conn->max_xmit_dlength) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) hton24(hdr->dlength, conn->max_xmit_dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) r2t->data_count = conn->max_xmit_dlength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) hdr->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) hton24(hdr->dlength, left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) r2t->data_count = left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) hdr->flags = ISCSI_FLAG_CMD_FINAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) conn->dataout_pdus_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) EXPORT_SYMBOL_GPL(iscsi_prep_data_out_pdu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int iscsi_add_hdr(struct iscsi_task *task, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) unsigned exp_len = task->hdr_len + len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (exp_len > task->hdr_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) WARN_ON(len & (ISCSI_PAD_LEN - 1)); /* caller must pad the AHS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) task->hdr_len = exp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * make an extended cdb AHS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int iscsi_prep_ecdb_ahs(struct iscsi_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct scsi_cmnd *cmd = task->sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) unsigned rlen, pad_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) unsigned short ahslength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct iscsi_ecdb_ahdr *ecdb_ahdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) ecdb_ahdr = iscsi_next_hdr(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) rlen = cmd->cmd_len - ISCSI_CDB_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) BUG_ON(rlen > sizeof(ecdb_ahdr->ecdb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) ahslength = rlen + sizeof(ecdb_ahdr->reserved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) pad_len = iscsi_padding(rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) rc = iscsi_add_hdr(task, sizeof(ecdb_ahdr->ahslength) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) sizeof(ecdb_ahdr->ahstype) + ahslength + pad_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (pad_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) memset(&ecdb_ahdr->ecdb[rlen], 0, pad_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) ecdb_ahdr->ahslength = cpu_to_be16(ahslength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) ecdb_ahdr->ahstype = ISCSI_AHSTYPE_CDB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ecdb_ahdr->reserved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) memcpy(ecdb_ahdr->ecdb, cmd->cmnd + ISCSI_CDB_SIZE, rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) ISCSI_DBG_SESSION(task->conn->session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) "iscsi_prep_ecdb_ahs: varlen_cdb_len %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) "rlen %d pad_len %d ahs_length %d iscsi_headers_size "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) "%u\n", cmd->cmd_len, rlen, pad_len, ahslength,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) task->hdr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * iscsi_check_tmf_restrictions - check if a task is affected by TMF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * @task: iscsi task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * @opcode: opcode to check for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * During TMF a task has to be checked if it's affected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * All unrelated I/O can be passed through, but I/O to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * affected LUN should be restricted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * If 'fast_abort' is set we won't be sending any I/O to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * affected LUN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * Otherwise the target is waiting for all TTTs to be completed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * so we have to send all outstanding Data-Out PDUs to the target.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static int iscsi_check_tmf_restrictions(struct iscsi_task *task, int opcode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct iscsi_session *session = task->conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct iscsi_tm *tmf = &session->tmhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) u64 hdr_lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (session->tmf_state == TMF_INITIAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if ((tmf->opcode & ISCSI_OPCODE_MASK) != ISCSI_OP_SCSI_TMFUNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) switch (ISCSI_TM_FUNC_VALUE(tmf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) case ISCSI_TM_FUNC_LOGICAL_UNIT_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * Allow PDUs for unrelated LUNs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) hdr_lun = scsilun_to_int(&tmf->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (hdr_lun != task->sc->device->lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) case ISCSI_TM_FUNC_TARGET_WARM_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * Fail all SCSI cmd PDUs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (opcode != ISCSI_OP_SCSI_DATA_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) iscsi_session_printk(KERN_INFO, session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) "task [op %x itt 0x%x/0x%x] rejected.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) opcode, task->itt, task->hdr_itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * And also all data-out PDUs in response to R2T
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * if fast_abort is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (session->fast_abort) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) iscsi_session_printk(KERN_INFO, session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) "task [op %x itt 0x%x/0x%x] fast abort.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) opcode, task->itt, task->hdr_itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) case ISCSI_TM_FUNC_ABORT_TASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * the caller has already checked if the task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * they want to abort was in the pending queue so if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * we are here the cmd pdu has gone out already, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * we will only hit this for data-outs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (opcode == ISCSI_OP_SCSI_DATA_OUT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) task->hdr_itt == tmf->rtt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) ISCSI_DBG_SESSION(session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) "Preventing task %x/%x from sending "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) "data-out due to abort task in "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) "progress\n", task->itt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) task->hdr_itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * iscsi_prep_scsi_cmd_pdu - prep iscsi scsi cmd pdu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * @task: iscsi task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * Prep basic iSCSI PDU fields for a scsi cmd pdu. The LLD should set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * fields like dlength or final based on how much data it sends
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct iscsi_conn *conn = task->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct scsi_cmnd *sc = task->sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct iscsi_scsi_req *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) unsigned hdrlength, cmd_len, transfer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) itt_t itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) rc = iscsi_check_tmf_restrictions(task, ISCSI_OP_SCSI_CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (conn->session->tt->alloc_pdu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) rc = conn->session->tt->alloc_pdu(task, ISCSI_OP_SCSI_CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) hdr = (struct iscsi_scsi_req *)task->hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) itt = hdr->itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) memset(hdr, 0, sizeof(*hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (session->tt->parse_pdu_itt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) hdr->itt = task->hdr_itt = itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) hdr->itt = task->hdr_itt = build_itt(task->itt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) task->conn->session->age);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) task->hdr_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) rc = iscsi_add_hdr(task, sizeof(*hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) hdr->opcode = ISCSI_OP_SCSI_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) hdr->flags = ISCSI_ATTR_SIMPLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) int_to_scsilun(sc->device->lun, &hdr->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) task->lun = hdr->lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) hdr->exp_statsn = cpu_to_be32(conn->exp_statsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) cmd_len = sc->cmd_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (cmd_len < ISCSI_CDB_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) memset(&hdr->cdb[cmd_len], 0, ISCSI_CDB_SIZE - cmd_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) else if (cmd_len > ISCSI_CDB_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) rc = iscsi_prep_ecdb_ahs(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) cmd_len = ISCSI_CDB_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) memcpy(hdr->cdb, sc->cmnd, cmd_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) task->imm_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (scsi_get_prot_op(sc) != SCSI_PROT_NORMAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) task->protected = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) transfer_length = scsi_transfer_length(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) hdr->data_length = cpu_to_be32(transfer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (sc->sc_data_direction == DMA_TO_DEVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) struct iscsi_r2t_info *r2t = &task->unsol_r2t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) hdr->flags |= ISCSI_FLAG_CMD_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * Write counters:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * imm_count bytes to be sent right after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * SCSI PDU Header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * unsol_count bytes(as Data-Out) to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * without R2T ack right after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * immediate data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) * r2t data_length bytes to be sent via R2T ack's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * pad_count bytes to be sent as zero-padding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) memset(r2t, 0, sizeof(*r2t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (session->imm_data_en) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (transfer_length >= session->first_burst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) task->imm_count = min(session->first_burst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) conn->max_xmit_dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) task->imm_count = min(transfer_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) conn->max_xmit_dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) hton24(hdr->dlength, task->imm_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) zero_data(hdr->dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (!session->initial_r2t_en) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) r2t->data_length = min(session->first_burst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) transfer_length) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) task->imm_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) r2t->data_offset = task->imm_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) r2t->ttt = cpu_to_be32(ISCSI_RESERVED_TAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) r2t->exp_statsn = cpu_to_be32(conn->exp_statsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (!task->unsol_r2t.data_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) /* No unsolicit Data-Out's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) hdr->flags |= ISCSI_FLAG_CMD_FINAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) hdr->flags |= ISCSI_FLAG_CMD_FINAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) zero_data(hdr->dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (sc->sc_data_direction == DMA_FROM_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) hdr->flags |= ISCSI_FLAG_CMD_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) /* calculate size of additional header segments (AHSs) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) hdrlength = task->hdr_len - sizeof(*hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) WARN_ON(hdrlength & (ISCSI_PAD_LEN-1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) hdrlength /= ISCSI_PAD_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) WARN_ON(hdrlength >= 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) hdr->hlength = hdrlength & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) hdr->cmdsn = task->cmdsn = cpu_to_be32(session->cmdsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (session->tt->init_task && session->tt->init_task(task))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) task->state = ISCSI_TASK_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) session->cmdsn++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) conn->scsicmd_pdus_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) ISCSI_DBG_SESSION(session, "iscsi prep [%s cid %d sc %p cdb 0x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) "itt 0x%x len %d cmdsn %d win %d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) sc->sc_data_direction == DMA_TO_DEVICE ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) "write" : "read", conn->id, sc, sc->cmnd[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) task->itt, transfer_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) session->cmdsn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) session->max_cmdsn - session->exp_cmdsn + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * iscsi_free_task - free a task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * @task: iscsi cmd task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * Must be called with session back_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * This function returns the scsi command to scsi-ml or cleans
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * up mgmt tasks then returns the task to the pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) static void iscsi_free_task(struct iscsi_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) struct iscsi_conn *conn = task->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct scsi_cmnd *sc = task->sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) int oldstate = task->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) ISCSI_DBG_SESSION(session, "freeing task itt 0x%x state %d sc %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) task->itt, task->state, task->sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) session->tt->cleanup_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) task->state = ISCSI_TASK_FREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) task->sc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * login task is preallocated so do not free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (conn->login_task == task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) kfifo_in(&session->cmdpool.queue, (void*)&task, sizeof(void*));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (sc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) /* SCSI eh reuses commands to verify us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) sc->SCp.ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * queue command may call this to free the task, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * it will decide how to return sc to scsi-ml.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (oldstate != ISCSI_TASK_REQUEUE_SCSIQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) sc->scsi_done(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) void __iscsi_get_task(struct iscsi_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) refcount_inc(&task->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) EXPORT_SYMBOL_GPL(__iscsi_get_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) void __iscsi_put_task(struct iscsi_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (refcount_dec_and_test(&task->refcount))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) iscsi_free_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) EXPORT_SYMBOL_GPL(__iscsi_put_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) void iscsi_put_task(struct iscsi_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) struct iscsi_session *session = task->conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) /* regular RX path uses back_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) spin_lock_bh(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) __iscsi_put_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) spin_unlock_bh(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) EXPORT_SYMBOL_GPL(iscsi_put_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) * iscsi_complete_task - finish a task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * @task: iscsi cmd task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) * @state: state to complete task with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) * Must be called with session back_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) static void iscsi_complete_task(struct iscsi_task *task, int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct iscsi_conn *conn = task->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) ISCSI_DBG_SESSION(conn->session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) "complete task itt 0x%x state %d sc %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) task->itt, task->state, task->sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (task->state == ISCSI_TASK_COMPLETED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) task->state == ISCSI_TASK_ABRT_TMF ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) task->state == ISCSI_TASK_ABRT_SESS_RECOV ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) task->state == ISCSI_TASK_REQUEUE_SCSIQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) WARN_ON_ONCE(task->state == ISCSI_TASK_FREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) task->state = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) spin_lock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) if (!list_empty(&task->running)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) pr_debug_once("%s while task on list", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) list_del_init(&task->running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) spin_unlock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) if (conn->task == task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) conn->task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (READ_ONCE(conn->ping_task) == task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) WRITE_ONCE(conn->ping_task, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) /* release get from queueing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) __iscsi_put_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) * iscsi_complete_scsi_task - finish scsi task normally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) * @task: iscsi task for scsi cmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) * @exp_cmdsn: expected cmd sn in cpu format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) * @max_cmdsn: max cmd sn in cpu format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) * This is used when drivers do not need or cannot perform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * lower level pdu processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * Called with session back_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) void iscsi_complete_scsi_task(struct iscsi_task *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) uint32_t exp_cmdsn, uint32_t max_cmdsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) struct iscsi_conn *conn = task->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) ISCSI_DBG_SESSION(conn->session, "[itt 0x%x]\n", task->itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) conn->last_recv = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) __iscsi_update_cmdsn(conn->session, exp_cmdsn, max_cmdsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) EXPORT_SYMBOL_GPL(iscsi_complete_scsi_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) * session back_lock must be held and if not called for a task that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) * still pending or from the xmit thread, then xmit thread must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * be suspended.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) static void fail_scsi_task(struct iscsi_task *task, int err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) struct iscsi_conn *conn = task->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) struct scsi_cmnd *sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * if a command completes and we get a successful tmf response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) * we will hit this because the scsi eh abort code does not take
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * a ref to the task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) sc = task->sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (!sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) if (task->state == ISCSI_TASK_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) * cmd never made it to the xmit thread, so we should not count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) * the cmd in the sequencing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) conn->session->queued_cmdsn--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) /* it was never sent so just complete like normal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) state = ISCSI_TASK_COMPLETED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) } else if (err == DID_TRANSPORT_DISRUPTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) state = ISCSI_TASK_ABRT_SESS_RECOV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) state = ISCSI_TASK_ABRT_TMF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) sc->result = err << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) scsi_set_resid(sc, scsi_bufflen(sc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) /* regular RX path uses back_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) spin_lock_bh(&conn->session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) iscsi_complete_task(task, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) spin_unlock_bh(&conn->session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) static int iscsi_prep_mgmt_task(struct iscsi_conn *conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct iscsi_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) struct iscsi_hdr *hdr = task->hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) struct iscsi_nopout *nop = (struct iscsi_nopout *)hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) uint8_t opcode = hdr->opcode & ISCSI_OPCODE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if (conn->session->state == ISCSI_STATE_LOGGING_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (opcode != ISCSI_OP_LOGIN && opcode != ISCSI_OP_TEXT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) nop->exp_statsn = cpu_to_be32(conn->exp_statsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) * pre-format CmdSN for outgoing PDU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) nop->cmdsn = cpu_to_be32(session->cmdsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (hdr->itt != RESERVED_ITT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) * TODO: We always use immediate for normal session pdus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) * If we start to send tmfs or nops as non-immediate then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) * we should start checking the cmdsn numbers for mgmt tasks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) * During discovery sessions iscsid sends TEXT as non immediate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) * but we always only send one PDU at a time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) if (conn->c_stage == ISCSI_CONN_STARTED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) !(hdr->opcode & ISCSI_OP_IMMEDIATE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) session->queued_cmdsn++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) session->cmdsn++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (session->tt->init_task && session->tt->init_task(task))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if ((hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) session->state = ISCSI_STATE_LOGGING_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) task->state = ISCSI_TASK_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) ISCSI_DBG_SESSION(session, "mgmtpdu [op 0x%x hdr->itt 0x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) "datalen %d]\n", hdr->opcode & ISCSI_OPCODE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) hdr->itt, task->data_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) static struct iscsi_task *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) char *data, uint32_t data_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) struct iscsi_host *ihost = shost_priv(session->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) uint8_t opcode = hdr->opcode & ISCSI_OPCODE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) itt_t itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) if (session->state == ISCSI_STATE_TERMINATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) if (opcode == ISCSI_OP_LOGIN || opcode == ISCSI_OP_TEXT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * Login and Text are sent serially, in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) * request-followed-by-response sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) * Same task can be used. Same ITT must be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) * Note that login_task is preallocated at conn_create().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) if (conn->login_task->state != ISCSI_TASK_FREE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) iscsi_conn_printk(KERN_ERR, conn, "Login/Text in "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) "progress. Cannot start new task.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) if (data_size > ISCSI_DEF_MAX_RECV_SEG_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) iscsi_conn_printk(KERN_ERR, conn, "Invalid buffer len of %u for login task. Max len is %u\n", data_size, ISCSI_DEF_MAX_RECV_SEG_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) task = conn->login_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (session->state != ISCSI_STATE_LOGGED_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) if (data_size != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) iscsi_conn_printk(KERN_ERR, conn, "Can not send data buffer of len %u for op 0x%x\n", data_size, opcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if (!kfifo_out(&session->cmdpool.queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) (void*)&task, sizeof(void*)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) * released in complete pdu for task we expect a response for, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) * released by the lld when it has transmitted the task for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) * pdus we do not expect a response for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) refcount_set(&task->refcount, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) task->conn = conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) task->sc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) INIT_LIST_HEAD(&task->running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) task->state = ISCSI_TASK_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) if (data_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) memcpy(task->data, data, data_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) task->data_count = data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) task->data_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) if (conn->session->tt->alloc_pdu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) if (conn->session->tt->alloc_pdu(task, hdr->opcode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) iscsi_conn_printk(KERN_ERR, conn, "Could not allocate "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) "pdu for mgmt task.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) goto free_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) itt = task->hdr->itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) task->hdr_len = sizeof(struct iscsi_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) memcpy(task->hdr, hdr, sizeof(struct iscsi_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) if (hdr->itt != RESERVED_ITT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (session->tt->parse_pdu_itt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) task->hdr->itt = itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) task->hdr->itt = build_itt(task->itt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) task->conn->session->age);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (unlikely(READ_ONCE(conn->ping_task) == INVALID_SCSI_TASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) WRITE_ONCE(conn->ping_task, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) if (!ihost->workq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) if (iscsi_prep_mgmt_task(conn, task))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) goto free_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) if (session->tt->xmit_task(task))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) goto free_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) spin_lock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) list_add_tail(&task->running, &conn->mgmtqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) spin_unlock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) iscsi_conn_queue_work(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) return task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) free_task:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) /* regular RX path uses back_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) spin_lock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) __iscsi_put_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) spin_unlock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) int iscsi_conn_send_pdu(struct iscsi_cls_conn *cls_conn, struct iscsi_hdr *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) char *data, uint32_t data_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) struct iscsi_conn *conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) if (!__iscsi_conn_send_pdu(conn, hdr, data, data_size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) err = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) EXPORT_SYMBOL_GPL(iscsi_conn_send_pdu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) * iscsi_cmd_rsp - SCSI Command Response processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) * @conn: iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) * @hdr: iscsi header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) * @task: scsi command task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) * @data: cmd data buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) * @datalen: len of buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) * iscsi_cmd_rsp sets up the scsi_cmnd fields based on the PDU and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) * then completes the command and task. called under back_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) struct iscsi_task *task, char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) int datalen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) struct iscsi_scsi_rsp *rhdr = (struct iscsi_scsi_rsp *)hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) struct scsi_cmnd *sc = task->sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) sc->result = (DID_OK << 16) | rhdr->cmd_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) if (task->protected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) sector_t sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) u8 ascq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) * Transports that didn't implement check_protection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) * callback but still published T10-PI support to scsi-mid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) * deserve this BUG_ON.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) BUG_ON(!session->tt->check_protection);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) ascq = session->tt->check_protection(task, §or);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) if (ascq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) sc->result = DRIVER_SENSE << 24 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) SAM_STAT_CHECK_CONDITION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) scsi_build_sense_buffer(1, sc->sense_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) ILLEGAL_REQUEST, 0x10, ascq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) scsi_set_sense_information(sc->sense_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) SCSI_SENSE_BUFFERSIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) if (rhdr->response != ISCSI_STATUS_CMD_COMPLETED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) sc->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (rhdr->cmd_status == SAM_STAT_CHECK_CONDITION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) uint16_t senselen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) if (datalen < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) invalid_datalen:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) iscsi_conn_printk(KERN_ERR, conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) "Got CHECK_CONDITION but invalid data "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) "buffer size of %d\n", datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) sc->result = DID_BAD_TARGET << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) senselen = get_unaligned_be16(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) if (datalen < senselen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) goto invalid_datalen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) memcpy(sc->sense_buffer, data + 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) ISCSI_DBG_SESSION(session, "copied %d bytes of sense\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) min_t(uint16_t, senselen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) SCSI_SENSE_BUFFERSIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) if (rhdr->flags & (ISCSI_FLAG_CMD_BIDI_UNDERFLOW |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) ISCSI_FLAG_CMD_BIDI_OVERFLOW)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (rhdr->flags & (ISCSI_FLAG_CMD_UNDERFLOW |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) ISCSI_FLAG_CMD_OVERFLOW)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) int res_count = be32_to_cpu(rhdr->residual_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) if (res_count > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) res_count <= scsi_bufflen(sc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) /* write side for bidi or uni-io set_resid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) scsi_set_resid(sc, res_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) ISCSI_DBG_SESSION(session, "cmd rsp done [sc %p res %d itt 0x%x]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) sc, sc->result, task->itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) conn->scsirsp_pdus_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) * iscsi_data_in_rsp - SCSI Data-In Response processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) * @conn: iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) * @hdr: iscsi pdu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) * @task: scsi command task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) * iscsi_data_in_rsp sets up the scsi_cmnd fields based on the data received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) * then completes the command and task. called under back_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) iscsi_data_in_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) struct iscsi_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) struct iscsi_data_rsp *rhdr = (struct iscsi_data_rsp *)hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) struct scsi_cmnd *sc = task->sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) if (!(rhdr->flags & ISCSI_FLAG_DATA_STATUS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) iscsi_update_cmdsn(conn->session, (struct iscsi_nopin *)hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) sc->result = (DID_OK << 16) | rhdr->cmd_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) if (rhdr->flags & (ISCSI_FLAG_DATA_UNDERFLOW |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) ISCSI_FLAG_DATA_OVERFLOW)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) int res_count = be32_to_cpu(rhdr->residual_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) if (res_count > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) res_count <= sc->sdb.length))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) scsi_set_resid(sc, res_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) ISCSI_DBG_SESSION(conn->session, "data in with status done "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) "[sc %p res %d itt 0x%x]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) sc, sc->result, task->itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) conn->scsirsp_pdus_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) static void iscsi_tmf_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) struct iscsi_tm_rsp *tmf = (struct iscsi_tm_rsp *)hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) conn->tmfrsp_pdus_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) if (session->tmf_state != TMF_QUEUED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) if (tmf->response == ISCSI_TMF_RSP_COMPLETE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) session->tmf_state = TMF_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) else if (tmf->response == ISCSI_TMF_RSP_NO_TASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) session->tmf_state = TMF_NOT_FOUND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) session->tmf_state = TMF_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) wake_up(&session->ehwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) static int iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) struct iscsi_nopout hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) if (!rhdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) if (READ_ONCE(conn->ping_task))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) WRITE_ONCE(conn->ping_task, INVALID_SCSI_TASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) memset(&hdr, 0, sizeof(struct iscsi_nopout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) hdr.opcode = ISCSI_OP_NOOP_OUT | ISCSI_OP_IMMEDIATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) hdr.flags = ISCSI_FLAG_CMD_FINAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) if (rhdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) hdr.lun = rhdr->lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) hdr.ttt = rhdr->ttt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) hdr.itt = RESERVED_ITT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) hdr.ttt = RESERVED_ITT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) task = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)&hdr, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) if (!task) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) if (!rhdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) WRITE_ONCE(conn->ping_task, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) iscsi_conn_printk(KERN_ERR, conn, "Could not send nopout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) } else if (!rhdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) /* only track our nops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) conn->last_ping = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) * iscsi_nop_out_rsp - SCSI NOP Response processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) * @task: scsi command task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) * @nop: the nop structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) * @data: where to put the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) * @datalen: length of data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) * iscsi_nop_out_rsp handles nop response from use or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) * from user space. called under back_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) static int iscsi_nop_out_rsp(struct iscsi_task *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) struct iscsi_nopin *nop, char *data, int datalen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) struct iscsi_conn *conn = task->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) if (READ_ONCE(conn->ping_task) != task) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) * If this is not in response to one of our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) * nops then it must be from userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) if (iscsi_recv_pdu(conn->cls_conn, (struct iscsi_hdr *)nop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) data, datalen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) rc = ISCSI_ERR_CONN_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) mod_timer(&conn->transport_timer, jiffies + conn->recv_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) static int iscsi_handle_reject(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) char *data, int datalen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) struct iscsi_reject *reject = (struct iscsi_reject *)hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) struct iscsi_hdr rejected_pdu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) int opcode, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) conn->exp_statsn = be32_to_cpu(reject->statsn) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) if (ntoh24(reject->dlength) > datalen ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) ntoh24(reject->dlength) < sizeof(struct iscsi_hdr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) iscsi_conn_printk(KERN_ERR, conn, "Cannot handle rejected "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) "pdu. Invalid data length (pdu dlength "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) "%u, datalen %d\n", ntoh24(reject->dlength),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) return ISCSI_ERR_PROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) memcpy(&rejected_pdu, data, sizeof(struct iscsi_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) opcode = rejected_pdu.opcode & ISCSI_OPCODE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) switch (reject->reason) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) case ISCSI_REASON_DATA_DIGEST_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) iscsi_conn_printk(KERN_ERR, conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) "pdu (op 0x%x itt 0x%x) rejected "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) "due to DataDigest error.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) opcode, rejected_pdu.itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) case ISCSI_REASON_IMM_CMD_REJECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) iscsi_conn_printk(KERN_ERR, conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) "pdu (op 0x%x itt 0x%x) rejected. Too many "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) "immediate commands.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) opcode, rejected_pdu.itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) * We only send one TMF at a time so if the target could not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) * handle it, then it should get fixed (RFC mandates that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) * a target can handle one immediate TMF per conn).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) * For nops-outs, we could have sent more than one if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) * the target is sending us lots of nop-ins
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) if (opcode != ISCSI_OP_NOOP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) if (rejected_pdu.itt == cpu_to_be32(ISCSI_RESERVED_TAG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) * nop-out in response to target's nop-out rejected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) * Just resend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) /* In RX path we are under back lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) spin_unlock(&conn->session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) spin_lock(&conn->session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) iscsi_send_nopout(conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) (struct iscsi_nopin*)&rejected_pdu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) spin_unlock(&conn->session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) spin_lock(&conn->session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) * Our nop as ping got dropped. We know the target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) * and transport are ok so just clean up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) task = iscsi_itt_to_task(conn, rejected_pdu.itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) if (!task) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) iscsi_conn_printk(KERN_ERR, conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) "Invalid pdu reject. Could "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) "not lookup rejected task.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) rc = ISCSI_ERR_BAD_ITT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) rc = iscsi_nop_out_rsp(task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) (struct iscsi_nopin*)&rejected_pdu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) iscsi_conn_printk(KERN_ERR, conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) "pdu (op 0x%x itt 0x%x) rejected. Reason "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) "code 0x%x\n", rejected_pdu.opcode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) rejected_pdu.itt, reject->reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) * iscsi_itt_to_task - look up task by itt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) * @conn: iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) * @itt: itt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) * This should be used for mgmt tasks like login and nops, or if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) * the LDD's itt space does not include the session age.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) * The session back_lock must be held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) struct iscsi_task *iscsi_itt_to_task(struct iscsi_conn *conn, itt_t itt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) if (itt == RESERVED_ITT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) if (session->tt->parse_pdu_itt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) session->tt->parse_pdu_itt(conn, itt, &i, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) i = get_itt(itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) if (i >= session->cmds_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) return session->cmds[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) EXPORT_SYMBOL_GPL(iscsi_itt_to_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) * __iscsi_complete_pdu - complete pdu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) * @conn: iscsi conn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) * @hdr: iscsi header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) * @data: data buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) * @datalen: len of data buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) * Completes pdu processing by freeing any resources allocated at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) * queuecommand or send generic. session back_lock must be held and verify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) * itt must have been called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) char *data, int datalen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) int opcode = hdr->opcode & ISCSI_OPCODE_MASK, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) uint32_t itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) conn->last_recv = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) rc = iscsi_verify_itt(conn, hdr->itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) if (hdr->itt != RESERVED_ITT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) itt = get_itt(hdr->itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) itt = ~0U;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) ISCSI_DBG_SESSION(session, "[op 0x%x cid %d itt 0x%x len %d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) opcode, conn->id, itt, datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) if (itt == ~0U) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) switch(opcode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) case ISCSI_OP_NOOP_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) if (datalen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) rc = ISCSI_ERR_PROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) if (hdr->ttt == cpu_to_be32(ISCSI_RESERVED_TAG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) /* In RX path we are under back lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) spin_unlock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) spin_lock(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) iscsi_send_nopout(conn, (struct iscsi_nopin*)hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) spin_unlock(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) spin_lock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) case ISCSI_OP_REJECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) rc = iscsi_handle_reject(conn, hdr, data, datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) case ISCSI_OP_ASYNC_EVENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) if (iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) rc = ISCSI_ERR_CONN_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) rc = ISCSI_ERR_BAD_OPCODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) switch(opcode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) case ISCSI_OP_SCSI_CMD_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) case ISCSI_OP_SCSI_DATA_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) task = iscsi_itt_to_ctask(conn, hdr->itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) if (!task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) return ISCSI_ERR_BAD_ITT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) task->last_xfer = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) case ISCSI_OP_R2T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) * LLD handles R2Ts if they need to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) case ISCSI_OP_LOGOUT_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) case ISCSI_OP_LOGIN_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) case ISCSI_OP_TEXT_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) case ISCSI_OP_SCSI_TMFUNC_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) case ISCSI_OP_NOOP_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) task = iscsi_itt_to_task(conn, hdr->itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) if (!task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) return ISCSI_ERR_BAD_ITT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) return ISCSI_ERR_BAD_OPCODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) switch(opcode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) case ISCSI_OP_SCSI_CMD_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) iscsi_scsi_cmd_rsp(conn, hdr, task, data, datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) case ISCSI_OP_SCSI_DATA_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) iscsi_data_in_rsp(conn, hdr, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) case ISCSI_OP_LOGOUT_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) if (datalen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) rc = ISCSI_ERR_PROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) goto recv_pdu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) case ISCSI_OP_LOGIN_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) case ISCSI_OP_TEXT_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) * login related PDU's exp_statsn is handled in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) * userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) goto recv_pdu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) case ISCSI_OP_SCSI_TMFUNC_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) if (datalen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) rc = ISCSI_ERR_PROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) iscsi_tmf_rsp(conn, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) case ISCSI_OP_NOOP_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) if (hdr->ttt != cpu_to_be32(ISCSI_RESERVED_TAG) || datalen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) rc = ISCSI_ERR_PROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) rc = iscsi_nop_out_rsp(task, (struct iscsi_nopin*)hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) data, datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) rc = ISCSI_ERR_BAD_OPCODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) recv_pdu:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) if (iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) rc = ISCSI_ERR_CONN_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) EXPORT_SYMBOL_GPL(__iscsi_complete_pdu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) int iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) char *data, int datalen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) spin_lock(&conn->session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) rc = __iscsi_complete_pdu(conn, hdr, data, datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) spin_unlock(&conn->session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) EXPORT_SYMBOL_GPL(iscsi_complete_pdu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) int iscsi_verify_itt(struct iscsi_conn *conn, itt_t itt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) int age = 0, i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) if (itt == RESERVED_ITT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) if (session->tt->parse_pdu_itt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) session->tt->parse_pdu_itt(conn, itt, &i, &age);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) i = get_itt(itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) age = ((__force u32)itt >> ISCSI_AGE_SHIFT) & ISCSI_AGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) if (age != session->age) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) iscsi_conn_printk(KERN_ERR, conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) "received itt %x expected session age (%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) (__force u32)itt, session->age);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) return ISCSI_ERR_BAD_ITT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) if (i >= session->cmds_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) iscsi_conn_printk(KERN_ERR, conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) "received invalid itt index %u (max cmds "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) "%u.\n", i, session->cmds_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) return ISCSI_ERR_BAD_ITT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) EXPORT_SYMBOL_GPL(iscsi_verify_itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) * iscsi_itt_to_ctask - look up ctask by itt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) * @conn: iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) * @itt: itt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) * This should be used for cmd tasks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) * The session back_lock must be held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) struct iscsi_task *iscsi_itt_to_ctask(struct iscsi_conn *conn, itt_t itt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) if (iscsi_verify_itt(conn, itt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) task = iscsi_itt_to_task(conn, itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) if (!task || !task->sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) if (task->sc->SCp.phase != conn->session->age) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) iscsi_session_printk(KERN_ERR, conn->session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) "task's session age %d, expected %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) task->sc->SCp.phase, conn->session->age);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) return task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) EXPORT_SYMBOL_GPL(iscsi_itt_to_ctask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) void iscsi_session_failure(struct iscsi_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) enum iscsi_err err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) conn = session->leadconn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) if (session->state == ISCSI_STATE_TERMINATE || !conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) iscsi_get_conn(conn->cls_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) * if the host is being removed bypass the connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) * recovery initialization because we are going to kill
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) * the session.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) if (err == ISCSI_ERR_INVALID_HOST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) iscsi_conn_error_event(conn->cls_conn, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) iscsi_conn_failure(conn, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) iscsi_put_conn(conn->cls_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) EXPORT_SYMBOL_GPL(iscsi_session_failure);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) void iscsi_conn_failure(struct iscsi_conn *conn, enum iscsi_err err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) if (session->state == ISCSI_STATE_FAILED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) if (conn->stop_stage == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) session->state = ISCSI_STATE_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) iscsi_conn_error_event(conn->cls_conn, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) EXPORT_SYMBOL_GPL(iscsi_conn_failure);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) static int iscsi_check_cmdsn_window_closed(struct iscsi_conn *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) * Check for iSCSI window and take care of CmdSN wrap-around
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) if (!iscsi_sna_lte(session->queued_cmdsn, session->max_cmdsn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) ISCSI_DBG_SESSION(session, "iSCSI CmdSN closed. ExpCmdSn "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) "%u MaxCmdSN %u CmdSN %u/%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) session->exp_cmdsn, session->max_cmdsn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) session->cmdsn, session->queued_cmdsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) static int iscsi_xmit_task(struct iscsi_conn *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) struct iscsi_task *task = conn->task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) if (test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) spin_lock_bh(&conn->session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) if (conn->task == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) spin_unlock_bh(&conn->session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) __iscsi_get_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) spin_unlock_bh(&conn->session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) spin_unlock_bh(&conn->session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) rc = conn->session->tt->xmit_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) spin_lock_bh(&conn->session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) /* done with this task */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) task->last_xfer = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) conn->task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) /* regular RX path uses back_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) spin_lock(&conn->session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) __iscsi_put_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) spin_unlock(&conn->session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) * iscsi_requeue_task - requeue task to run from session workqueue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) * @task: task to requeue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) * LLDs that need to run a task from the session workqueue should call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) * this. The session frwd_lock must be held. This should only be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) * by software drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) void iscsi_requeue_task(struct iscsi_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) struct iscsi_conn *conn = task->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) * this may be on the requeue list already if the xmit_task callout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) * is handling the r2ts while we are adding new ones
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) spin_lock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) if (list_empty(&task->running))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) list_add_tail(&task->running, &conn->requeue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) spin_unlock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) iscsi_conn_queue_work(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) EXPORT_SYMBOL_GPL(iscsi_requeue_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) * iscsi_data_xmit - xmit any command into the scheduled connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) * @conn: iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) * Notes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) * The function can return -EAGAIN in which case the caller must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) * re-schedule it again later or recover. '0' return code means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) * successful xmit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) static int iscsi_data_xmit(struct iscsi_conn *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) spin_lock_bh(&conn->session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) if (test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) ISCSI_DBG_SESSION(conn->session, "Tx suspended!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) spin_unlock_bh(&conn->session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) if (conn->task) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) rc = iscsi_xmit_task(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) * process mgmt pdus like nops before commands since we should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) * only have one nop-out as a ping from us and targets should not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) * overflow us with nop-ins
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) spin_lock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) check_mgmt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) while (!list_empty(&conn->mgmtqueue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) conn->task = list_entry(conn->mgmtqueue.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) struct iscsi_task, running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) list_del_init(&conn->task->running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) spin_unlock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) if (iscsi_prep_mgmt_task(conn, conn->task)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) /* regular RX path uses back_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) spin_lock_bh(&conn->session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) __iscsi_put_task(conn->task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) spin_unlock_bh(&conn->session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) conn->task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) spin_lock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) rc = iscsi_xmit_task(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) spin_lock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) /* process pending command queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) while (!list_empty(&conn->cmdqueue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) conn->task = list_entry(conn->cmdqueue.next, struct iscsi_task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) list_del_init(&conn->task->running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) spin_unlock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) if (conn->session->state == ISCSI_STATE_LOGGING_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) fail_scsi_task(conn->task, DID_IMM_RETRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) spin_lock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) rc = iscsi_prep_scsi_cmd_pdu(conn->task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) if (rc == -ENOMEM || rc == -EACCES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) fail_scsi_task(conn->task, DID_IMM_RETRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) fail_scsi_task(conn->task, DID_ABORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) spin_lock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) rc = iscsi_xmit_task(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) * we could continuously get new task requests so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) * we need to check the mgmt queue for nops that need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) * be sent to aviod starvation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) spin_lock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) if (!list_empty(&conn->mgmtqueue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) goto check_mgmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) while (!list_empty(&conn->requeue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) * we always do fastlogout - conn stop code will clean up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) if (conn->session->state == ISCSI_STATE_LOGGING_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) task = list_entry(conn->requeue.next, struct iscsi_task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) if (iscsi_check_tmf_restrictions(task, ISCSI_OP_SCSI_DATA_OUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) conn->task = task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) list_del_init(&conn->task->running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) conn->task->state = ISCSI_TASK_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) spin_unlock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) rc = iscsi_xmit_task(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) spin_lock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) if (!list_empty(&conn->mgmtqueue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) goto check_mgmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) spin_unlock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) spin_unlock_bh(&conn->session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) spin_unlock_bh(&conn->session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) static void iscsi_xmitworker(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) struct iscsi_conn *conn =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) container_of(work, struct iscsi_conn, xmitwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) * serialize Xmit worker on a per-connection basis.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) rc = iscsi_data_xmit(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) } while (rc >= 0 || rc == -EAGAIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) static inline struct iscsi_task *iscsi_alloc_task(struct iscsi_conn *conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) struct scsi_cmnd *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) if (!kfifo_out(&conn->session->cmdpool.queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) (void *) &task, sizeof(void *)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) sc->SCp.phase = conn->session->age;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) sc->SCp.ptr = (char *) task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) refcount_set(&task->refcount, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) task->state = ISCSI_TASK_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) task->conn = conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) task->sc = sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) task->have_checked_conn = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) task->last_timeout = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) task->last_xfer = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) task->protected = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) INIT_LIST_HEAD(&task->running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) return task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) FAILURE_BAD_HOST = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) FAILURE_SESSION_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) FAILURE_SESSION_FREED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) FAILURE_WINDOW_CLOSED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) FAILURE_OOM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) FAILURE_SESSION_TERMINATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) FAILURE_SESSION_IN_RECOVERY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) FAILURE_SESSION_RECOVERY_TIMEOUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) FAILURE_SESSION_LOGGING_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) FAILURE_SESSION_NOT_READY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) struct iscsi_cls_session *cls_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) struct iscsi_host *ihost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) int reason = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) struct iscsi_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) struct iscsi_task *task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) sc->result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) sc->SCp.ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) ihost = shost_priv(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) cls_session = starget_to_session(scsi_target(sc->device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) session = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) reason = iscsi_session_chkready(cls_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) if (reason) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) sc->result = reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) if (session->state != ISCSI_STATE_LOGGED_IN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) * to handle the race between when we set the recovery state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) * and block the session we requeue here (commands could
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) * be entering our queuecommand while a block is starting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) * up because the block code is not locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) switch (session->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) case ISCSI_STATE_FAILED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) * cmds should fail during shutdown, if the session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) * state is bad, allowing completion to happen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) if (unlikely(system_state != SYSTEM_RUNNING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) reason = FAILURE_SESSION_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) sc->result = DID_NO_CONNECT << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) case ISCSI_STATE_IN_RECOVERY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) reason = FAILURE_SESSION_IN_RECOVERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) sc->result = DID_IMM_RETRY << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) case ISCSI_STATE_LOGGING_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) reason = FAILURE_SESSION_LOGGING_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) sc->result = DID_IMM_RETRY << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) case ISCSI_STATE_RECOVERY_FAILED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) reason = FAILURE_SESSION_RECOVERY_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) sc->result = DID_TRANSPORT_FAILFAST << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) case ISCSI_STATE_TERMINATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) reason = FAILURE_SESSION_TERMINATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) sc->result = DID_NO_CONNECT << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) reason = FAILURE_SESSION_FREED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) sc->result = DID_NO_CONNECT << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) conn = session->leadconn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) if (!conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) reason = FAILURE_SESSION_FREED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) sc->result = DID_NO_CONNECT << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) if (test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) reason = FAILURE_SESSION_IN_RECOVERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) sc->result = DID_REQUEUE << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) if (iscsi_check_cmdsn_window_closed(conn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) reason = FAILURE_WINDOW_CLOSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) goto reject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) task = iscsi_alloc_task(conn, sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) if (!task) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) reason = FAILURE_OOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) goto reject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) if (!ihost->workq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) reason = iscsi_prep_scsi_cmd_pdu(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) if (reason) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) if (reason == -ENOMEM || reason == -EACCES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) reason = FAILURE_OOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) goto prepd_reject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) sc->result = DID_ABORT << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) goto prepd_fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) if (session->tt->xmit_task(task)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) session->cmdsn--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) reason = FAILURE_SESSION_NOT_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) goto prepd_reject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) spin_lock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) list_add_tail(&task->running, &conn->cmdqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) spin_unlock_bh(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) iscsi_conn_queue_work(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) session->queued_cmdsn++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) prepd_reject:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) spin_lock_bh(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) spin_unlock_bh(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) reject:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) ISCSI_DBG_SESSION(session, "cmd 0x%x rejected (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) sc->cmnd[0], reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) return SCSI_MLQUEUE_TARGET_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) prepd_fault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) spin_lock_bh(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) spin_unlock_bh(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) fault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) ISCSI_DBG_SESSION(session, "iscsi: cmd 0x%x is not queued (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) sc->cmnd[0], reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) scsi_set_resid(sc, scsi_bufflen(sc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) sc->scsi_done(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) EXPORT_SYMBOL_GPL(iscsi_queuecommand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) int iscsi_target_alloc(struct scsi_target *starget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) struct iscsi_cls_session *cls_session = starget_to_session(starget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) struct iscsi_session *session = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) starget->can_queue = session->scsi_cmds_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) EXPORT_SYMBOL_GPL(iscsi_target_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) static void iscsi_tmf_timedout(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) struct iscsi_session *session = from_timer(session, t, tmf_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) spin_lock(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) if (session->tmf_state == TMF_QUEUED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) session->tmf_state = TMF_TIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) ISCSI_DBG_EH(session, "tmf timedout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) /* unblock eh_abort() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) wake_up(&session->ehwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) spin_unlock(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) struct iscsi_tm *hdr, int age,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) int timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) __must_hold(&session->frwd_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) task = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) if (!task) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) iscsi_conn_printk(KERN_ERR, conn, "Could not send TMF.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) conn->tmfcmd_pdus_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) session->tmf_timer.expires = timeout * HZ + jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) add_timer(&session->tmf_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) ISCSI_DBG_EH(session, "tmf set timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) mutex_unlock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) * block eh thread until:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) * 1) tmf response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) * 2) tmf timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) * 3) session is terminated or restarted or userspace has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) * given up on recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) wait_event_interruptible(session->ehwait, age != session->age ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) session->state != ISCSI_STATE_LOGGED_IN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) session->tmf_state != TMF_QUEUED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) if (signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) flush_signals(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) del_timer_sync(&session->tmf_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) mutex_lock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) /* if the session drops it will clean up the task */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) if (age != session->age ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) session->state != ISCSI_STATE_LOGGED_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) * Fail commands. session lock held and recv side suspended and xmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) * thread flushed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) static void fail_scsi_tasks(struct iscsi_conn *conn, u64 lun, int error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) for (i = 0; i < conn->session->cmds_max; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) task = conn->session->cmds[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) if (!task->sc || task->state == ISCSI_TASK_FREE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) if (lun != -1 && lun != task->sc->device->lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) ISCSI_DBG_SESSION(conn->session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) "failing sc %p itt 0x%x state %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) task->sc, task->itt, task->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) fail_scsi_task(task, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) * iscsi_suspend_queue - suspend iscsi_queuecommand
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) * @conn: iscsi conn to stop queueing IO on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) * This grabs the session frwd_lock to make sure no one is in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) * xmit_task/queuecommand, and then sets suspend to prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) * new commands from being queued. This only needs to be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) * by offload drivers that need to sync a path like ep disconnect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) * with the iscsi_queuecommand/xmit_task. To start IO again libiscsi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) * will call iscsi_start_tx and iscsi_unblock_session when in FFP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) void iscsi_suspend_queue(struct iscsi_conn *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) spin_lock_bh(&conn->session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) spin_unlock_bh(&conn->session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) EXPORT_SYMBOL_GPL(iscsi_suspend_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) * iscsi_suspend_tx - suspend iscsi_data_xmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) * @conn: iscsi conn tp stop processing IO on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) * This function sets the suspend bit to prevent iscsi_data_xmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) * from sending new IO, and if work is queued on the xmit thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) * it will wait for it to be completed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) void iscsi_suspend_tx(struct iscsi_conn *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) struct Scsi_Host *shost = conn->session->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) struct iscsi_host *ihost = shost_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) if (ihost->workq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) flush_workqueue(ihost->workq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) EXPORT_SYMBOL_GPL(iscsi_suspend_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) static void iscsi_start_tx(struct iscsi_conn *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) iscsi_conn_queue_work(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) * We want to make sure a ping is in flight. It has timed out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) * And we are not busy processing a pdu that is making
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) * progress but got started before the ping and is taking a while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) * to complete so the ping is just stuck behind it in a queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) static int iscsi_has_ping_timed_out(struct iscsi_conn *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) if (READ_ONCE(conn->ping_task) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) time_before_eq(conn->last_recv + (conn->recv_timeout * HZ) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) (conn->ping_timeout * HZ), jiffies))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) enum blk_eh_timer_return rc = BLK_EH_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) struct iscsi_task *task = NULL, *running_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) struct iscsi_cls_session *cls_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) struct iscsi_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) cls_session = starget_to_session(scsi_target(sc->device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) session = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) ISCSI_DBG_EH(session, "scsi cmd %p timedout\n", sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) task = (struct iscsi_task *)sc->SCp.ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) if (!task) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) * Raced with completion. Blk layer has taken ownership
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) * so let timeout code complete it now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) rc = BLK_EH_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) if (session->state != ISCSI_STATE_LOGGED_IN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) * During shutdown, if session is prematurely disconnected,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) * recovery won't happen and there will be hung cmds. Not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) * handling cmds would trigger EH, also bad in this case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) * Instead, handle cmd, allow completion to happen and let
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) * upper layer to deal with the result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) if (unlikely(system_state != SYSTEM_RUNNING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) sc->result = DID_NO_CONNECT << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) ISCSI_DBG_EH(session, "sc on shutdown, handled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) rc = BLK_EH_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) * We are probably in the middle of iscsi recovery so let
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) * that complete and handle the error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) rc = BLK_EH_RESET_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) conn = session->leadconn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) if (!conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) /* In the middle of shuting down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) rc = BLK_EH_RESET_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) * If we have sent (at least queued to the network layer) a pdu or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) * recvd one for the task since the last timeout ask for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) * more time. If on the next timeout we have not made progress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) * we can check if it is the task or connection when we send the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) * nop as a ping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) if (time_after(task->last_xfer, task->last_timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) ISCSI_DBG_EH(session, "Command making progress. Asking "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) "scsi-ml for more time to complete. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) "Last data xfer at %lu. Last timeout was at "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) "%lu\n.", task->last_xfer, task->last_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) task->have_checked_conn = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) rc = BLK_EH_RESET_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) if (!conn->recv_timeout && !conn->ping_timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) * if the ping timedout then we are in the middle of cleaning up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) * and can let the iscsi eh handle it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) if (iscsi_has_ping_timed_out(conn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) rc = BLK_EH_RESET_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) for (i = 0; i < conn->session->cmds_max; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) running_task = conn->session->cmds[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) if (!running_task->sc || running_task == task ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) running_task->state != ISCSI_TASK_RUNNING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) * Only check if cmds started before this one have made
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) * progress, or this could never fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) if (time_after(running_task->sc->jiffies_at_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) task->sc->jiffies_at_alloc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) if (time_after(running_task->last_xfer, task->last_timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) * This task has not made progress, but a task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) * started before us has transferred data since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) * we started/last-checked. We could be queueing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) * too many tasks or the LU is bad.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) * If the device is bad the cmds ahead of us on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) * other devs will complete, and this loop will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) * eventually fail starting the scsi eh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) ISCSI_DBG_EH(session, "Command has not made progress "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) "but commands ahead of it have. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) "Asking scsi-ml for more time to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) "complete. Our last xfer vs running task "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) "last xfer %lu/%lu. Last check %lu.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) task->last_xfer, running_task->last_xfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) task->last_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) rc = BLK_EH_RESET_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) /* Assumes nop timeout is shorter than scsi cmd timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) if (task->have_checked_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) * Checking the transport already or nop from a cmd timeout still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) * running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) if (READ_ONCE(conn->ping_task)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) task->have_checked_conn = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) rc = BLK_EH_RESET_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) /* Make sure there is a transport check done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) iscsi_send_nopout(conn, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) task->have_checked_conn = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) rc = BLK_EH_RESET_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) if (task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) task->last_timeout = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) ISCSI_DBG_EH(session, "return %s\n", rc == BLK_EH_RESET_TIMER ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) "timer reset" : "shutdown or nh");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) EXPORT_SYMBOL_GPL(iscsi_eh_cmd_timed_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) static void iscsi_check_transport_timeouts(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) struct iscsi_conn *conn = from_timer(conn, t, transport_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) unsigned long recv_timeout, next_timeout = 0, last_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) spin_lock(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) if (session->state != ISCSI_STATE_LOGGED_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) recv_timeout = conn->recv_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) if (!recv_timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) recv_timeout *= HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) last_recv = conn->last_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) if (iscsi_has_ping_timed_out(conn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) iscsi_conn_printk(KERN_ERR, conn, "ping timeout of %d secs "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) "expired, recv timeout %d, last rx %lu, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) "last ping %lu, now %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) conn->ping_timeout, conn->recv_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) last_recv, conn->last_ping, jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) spin_unlock(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) iscsi_conn_failure(conn, ISCSI_ERR_NOP_TIMEDOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) if (time_before_eq(last_recv + recv_timeout, jiffies)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) /* send a ping to try to provoke some traffic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) ISCSI_DBG_CONN(conn, "Sending nopout as ping\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) if (iscsi_send_nopout(conn, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) next_timeout = jiffies + (1 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) next_timeout = conn->last_ping + (conn->ping_timeout * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) next_timeout = last_recv + recv_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) ISCSI_DBG_CONN(conn, "Setting next tmo %lu\n", next_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) mod_timer(&conn->transport_timer, next_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) spin_unlock(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) static void iscsi_prep_abort_task_pdu(struct iscsi_task *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) struct iscsi_tm *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) memset(hdr, 0, sizeof(*hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) hdr->flags = ISCSI_TM_FUNC_ABORT_TASK & ISCSI_FLAG_TM_FUNC_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) hdr->flags |= ISCSI_FLAG_CMD_FINAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) hdr->lun = task->lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) hdr->rtt = task->hdr_itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) hdr->refcmdsn = task->cmdsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) int iscsi_eh_abort(struct scsi_cmnd *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) struct iscsi_cls_session *cls_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) struct iscsi_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) struct iscsi_tm *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) int age;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) cls_session = starget_to_session(scsi_target(sc->device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) session = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) ISCSI_DBG_EH(session, "aborting sc %p\n", sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) mutex_lock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) * if session was ISCSI_STATE_IN_RECOVERY then we may not have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) * got the command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) if (!sc->SCp.ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) ISCSI_DBG_EH(session, "sc never reached iscsi layer or "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) "it completed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) mutex_unlock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) * If we are not logged in or we have started a new session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) * then let the host reset code handle this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) sc->SCp.phase != session->age) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) mutex_unlock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) ISCSI_DBG_EH(session, "failing abort due to dropped "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) "session.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) conn = session->leadconn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) conn->eh_abort_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) age = session->age;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) task = (struct iscsi_task *)sc->SCp.ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) ISCSI_DBG_EH(session, "aborting [sc %p itt 0x%x]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) sc, task->itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) /* task completed before time out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) if (!task->sc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) ISCSI_DBG_EH(session, "sc completed while abort in progress\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) goto success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) if (task->state == ISCSI_TASK_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) fail_scsi_task(task, DID_ABORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) goto success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) /* only have one tmf outstanding at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) if (session->tmf_state != TMF_INITIAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) session->tmf_state = TMF_QUEUED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) hdr = &session->tmhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) iscsi_prep_abort_task_pdu(task, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) if (iscsi_exec_task_mgmt_fn(conn, hdr, age, session->abort_timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) switch (session->tmf_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) case TMF_SUCCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) * stop tx side incase the target had sent a abort rsp but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) * the initiator was still writing out data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) iscsi_suspend_tx(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) * we do not stop the recv side because targets have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) * good and have never sent us a successful tmf response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) * then sent more data for the cmd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) fail_scsi_task(task, DID_ABORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) session->tmf_state = TMF_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) memset(hdr, 0, sizeof(*hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) iscsi_start_tx(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) goto success_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) case TMF_TIMEDOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) goto failed_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) case TMF_NOT_FOUND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) if (!sc->SCp.ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) session->tmf_state = TMF_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) memset(hdr, 0, sizeof(*hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) /* task completed before tmf abort response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) ISCSI_DBG_EH(session, "sc completed while abort in "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) "progress\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) goto success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) session->tmf_state = TMF_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) success:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) success_unlocked:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) ISCSI_DBG_EH(session, "abort success [sc %p itt 0x%x]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) sc, task->itt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) mutex_unlock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) failed_unlocked:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) ISCSI_DBG_EH(session, "abort failed [sc %p itt 0x%x]\n", sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) task ? task->itt : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) mutex_unlock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) EXPORT_SYMBOL_GPL(iscsi_eh_abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) static void iscsi_prep_lun_reset_pdu(struct scsi_cmnd *sc, struct iscsi_tm *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) memset(hdr, 0, sizeof(*hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) hdr->flags = ISCSI_TM_FUNC_LOGICAL_UNIT_RESET & ISCSI_FLAG_TM_FUNC_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) hdr->flags |= ISCSI_FLAG_CMD_FINAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) int_to_scsilun(sc->device->lun, &hdr->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) hdr->rtt = RESERVED_ITT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) int iscsi_eh_device_reset(struct scsi_cmnd *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) struct iscsi_cls_session *cls_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) struct iscsi_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) struct iscsi_tm *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) int rc = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) cls_session = starget_to_session(scsi_target(sc->device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) session = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) ISCSI_DBG_EH(session, "LU Reset [sc %p lun %llu]\n", sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) sc->device->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) mutex_lock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) * Just check if we are not logged in. We cannot check for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) * the phase because the reset could come from a ioctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) conn = session->leadconn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) /* only have one tmf outstanding at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) if (session->tmf_state != TMF_INITIAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) session->tmf_state = TMF_QUEUED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) hdr = &session->tmhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) iscsi_prep_lun_reset_pdu(sc, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) if (iscsi_exec_task_mgmt_fn(conn, hdr, session->age,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) session->lu_reset_timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) rc = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) switch (session->tmf_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) case TMF_SUCCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) case TMF_TIMEDOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) session->tmf_state = TMF_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) rc = SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) iscsi_suspend_tx(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) memset(hdr, 0, sizeof(*hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) fail_scsi_tasks(conn, sc->device->lun, DID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) session->tmf_state = TMF_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) iscsi_start_tx(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) ISCSI_DBG_EH(session, "dev reset result = %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) rc == SUCCESS ? "SUCCESS" : "FAILED");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) mutex_unlock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) EXPORT_SYMBOL_GPL(iscsi_eh_device_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) void iscsi_session_recovery_timedout(struct iscsi_cls_session *cls_session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) struct iscsi_session *session = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) if (session->state != ISCSI_STATE_LOGGED_IN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) session->state = ISCSI_STATE_RECOVERY_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) wake_up(&session->ehwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) EXPORT_SYMBOL_GPL(iscsi_session_recovery_timedout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) * iscsi_eh_session_reset - drop session and attempt relogin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) * @sc: scsi command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) * This function will wait for a relogin, session termination from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) * userspace, or a recovery/replacement timeout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) int iscsi_eh_session_reset(struct scsi_cmnd *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) struct iscsi_cls_session *cls_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) struct iscsi_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) cls_session = starget_to_session(scsi_target(sc->device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) session = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) conn = session->leadconn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) mutex_lock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) if (session->state == ISCSI_STATE_TERMINATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) ISCSI_DBG_EH(session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) "failing session reset: Could not log back into "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) "%s [age %d]\n", session->targetname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) session->age);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) mutex_unlock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) mutex_unlock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) * we drop the lock here but the leadconn cannot be destoyed while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) * we are in the scsi eh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) ISCSI_DBG_EH(session, "wait for relogin\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) wait_event_interruptible(session->ehwait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) session->state == ISCSI_STATE_TERMINATE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) session->state == ISCSI_STATE_LOGGED_IN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) session->state == ISCSI_STATE_RECOVERY_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) if (signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) flush_signals(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) mutex_lock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) if (session->state == ISCSI_STATE_LOGGED_IN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) ISCSI_DBG_EH(session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) "session reset succeeded for %s,%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) session->targetname, conn->persistent_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) mutex_unlock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) EXPORT_SYMBOL_GPL(iscsi_eh_session_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) static void iscsi_prep_tgt_reset_pdu(struct scsi_cmnd *sc, struct iscsi_tm *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) memset(hdr, 0, sizeof(*hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) hdr->flags = ISCSI_TM_FUNC_TARGET_WARM_RESET & ISCSI_FLAG_TM_FUNC_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) hdr->flags |= ISCSI_FLAG_CMD_FINAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) hdr->rtt = RESERVED_ITT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) * iscsi_eh_target_reset - reset target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) * @sc: scsi command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) * This will attempt to send a warm target reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) static int iscsi_eh_target_reset(struct scsi_cmnd *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) struct iscsi_cls_session *cls_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) struct iscsi_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) struct iscsi_tm *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) int rc = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) cls_session = starget_to_session(scsi_target(sc->device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) session = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) ISCSI_DBG_EH(session, "tgt Reset [sc %p tgt %s]\n", sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) session->targetname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) mutex_lock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) * Just check if we are not logged in. We cannot check for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) * the phase because the reset could come from a ioctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) conn = session->leadconn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) /* only have one tmf outstanding at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) if (session->tmf_state != TMF_INITIAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) session->tmf_state = TMF_QUEUED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) hdr = &session->tmhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) iscsi_prep_tgt_reset_pdu(sc, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) if (iscsi_exec_task_mgmt_fn(conn, hdr, session->age,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) session->tgt_reset_timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) rc = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) switch (session->tmf_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) case TMF_SUCCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) case TMF_TIMEDOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) session->tmf_state = TMF_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) rc = SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) iscsi_suspend_tx(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) memset(hdr, 0, sizeof(*hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) fail_scsi_tasks(conn, -1, DID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) session->tmf_state = TMF_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) iscsi_start_tx(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) ISCSI_DBG_EH(session, "tgt %s reset result = %s\n", session->targetname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) rc == SUCCESS ? "SUCCESS" : "FAILED");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) mutex_unlock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) * iscsi_eh_recover_target - reset target and possibly the session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) * @sc: scsi command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) * This will attempt to send a warm target reset. If that fails,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) * we will escalate to ERL0 session recovery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) int iscsi_eh_recover_target(struct scsi_cmnd *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) rc = iscsi_eh_target_reset(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) if (rc == FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) rc = iscsi_eh_session_reset(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) EXPORT_SYMBOL_GPL(iscsi_eh_recover_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) * Pre-allocate a pool of @max items of @item_size. By default, the pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) * should be accessed via kfifo_{get,put} on q->queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) * Optionally, the caller can obtain the array of object pointers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) * by passing in a non-NULL @items pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) iscsi_pool_init(struct iscsi_pool *q, int max, void ***items, int item_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) int i, num_arrays = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) memset(q, 0, sizeof(*q));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) q->max = max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) /* If the user passed an items pointer, he wants a copy of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) * the array. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) if (items)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) num_arrays++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) q->pool = kvcalloc(num_arrays * max, sizeof(void *), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) if (q->pool == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) kfifo_init(&q->queue, (void*)q->pool, max * sizeof(void*));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) for (i = 0; i < max; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) q->pool[i] = kzalloc(item_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) if (q->pool[i] == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) q->max = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) goto enomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) kfifo_in(&q->queue, (void*)&q->pool[i], sizeof(void*));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) if (items) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) *items = q->pool + max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) memcpy(*items, q->pool, max * sizeof(void *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) enomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) iscsi_pool_free(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) EXPORT_SYMBOL_GPL(iscsi_pool_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) void iscsi_pool_free(struct iscsi_pool *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) for (i = 0; i < q->max; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) kfree(q->pool[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) kvfree(q->pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) EXPORT_SYMBOL_GPL(iscsi_pool_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) * iscsi_host_add - add host to system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) * @shost: scsi host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) * @pdev: parent device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) * This should be called by partial offload and software iscsi drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) * to add a host to the system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) int iscsi_host_add(struct Scsi_Host *shost, struct device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) if (!shost->can_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) shost->can_queue = ISCSI_DEF_XMIT_CMDS_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) if (!shost->cmd_per_lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) shost->cmd_per_lun = ISCSI_DEF_CMD_PER_LUN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) return scsi_add_host(shost, pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) EXPORT_SYMBOL_GPL(iscsi_host_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) * iscsi_host_alloc - allocate a host and driver data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) * @sht: scsi host template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) * @dd_data_size: driver host data size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) * @xmit_can_sleep: bool indicating if LLD will queue IO from a work queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) * This should be called by partial offload and software iscsi drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) * To access the driver specific memory use the iscsi_host_priv() macro.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) struct Scsi_Host *iscsi_host_alloc(struct scsi_host_template *sht,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) int dd_data_size, bool xmit_can_sleep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) struct Scsi_Host *shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) struct iscsi_host *ihost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) shost = scsi_host_alloc(sht, sizeof(struct iscsi_host) + dd_data_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) if (!shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) ihost = shost_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) if (xmit_can_sleep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) snprintf(ihost->workq_name, sizeof(ihost->workq_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) "iscsi_q_%d", shost->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) ihost->workq = alloc_workqueue("%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) WQ_SYSFS | __WQ_LEGACY | WQ_MEM_RECLAIM | WQ_UNBOUND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 1, ihost->workq_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) if (!ihost->workq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) goto free_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) spin_lock_init(&ihost->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) ihost->state = ISCSI_HOST_SETUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) ihost->num_sessions = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) init_waitqueue_head(&ihost->session_removal_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) return shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) free_host:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) scsi_host_put(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) EXPORT_SYMBOL_GPL(iscsi_host_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) static void iscsi_notify_host_removed(struct iscsi_cls_session *cls_session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_INVALID_HOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) * iscsi_host_remove - remove host and sessions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) * @shost: scsi host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) * If there are any sessions left, this will initiate the removal and wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) * for the completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) void iscsi_host_remove(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) struct iscsi_host *ihost = shost_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) spin_lock_irqsave(&ihost->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) ihost->state = ISCSI_HOST_REMOVED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) spin_unlock_irqrestore(&ihost->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) iscsi_host_for_each_session(shost, iscsi_notify_host_removed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) wait_event_interruptible(ihost->session_removal_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) ihost->num_sessions == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) if (signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) flush_signals(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) scsi_remove_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) if (ihost->workq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) destroy_workqueue(ihost->workq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) EXPORT_SYMBOL_GPL(iscsi_host_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) void iscsi_host_free(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) struct iscsi_host *ihost = shost_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) kfree(ihost->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) kfree(ihost->hwaddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) kfree(ihost->initiatorname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) scsi_host_put(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) EXPORT_SYMBOL_GPL(iscsi_host_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) static void iscsi_host_dec_session_cnt(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) struct iscsi_host *ihost = shost_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) shost = scsi_host_get(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) if (!shost) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) printk(KERN_ERR "Invalid state. Cannot notify host removal "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) "of session teardown event because host already "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) "removed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) spin_lock_irqsave(&ihost->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) ihost->num_sessions--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) if (ihost->num_sessions == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) wake_up(&ihost->session_removal_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) spin_unlock_irqrestore(&ihost->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) scsi_host_put(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) * iscsi_session_setup - create iscsi cls session and host and session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) * @iscsit: iscsi transport template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) * @shost: scsi host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) * @cmds_max: session can queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) * @dd_size: private driver data size, added to session allocation size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) * @cmd_task_size: LLD task private data size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) * @initial_cmdsn: initial CmdSN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) * @id: target ID to add to this session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) * This can be used by software iscsi_transports that allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) * a session per scsi host.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) * Callers should set cmds_max to the largest total numer (mgmt + scsi) of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) * tasks they support. The iscsi layer reserves ISCSI_MGMT_CMDS_MAX tasks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) * for nop handling and login/logout requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) struct iscsi_cls_session *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) iscsi_session_setup(struct iscsi_transport *iscsit, struct Scsi_Host *shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) uint16_t cmds_max, int dd_size, int cmd_task_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) uint32_t initial_cmdsn, unsigned int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) struct iscsi_host *ihost = shost_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) struct iscsi_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) struct iscsi_cls_session *cls_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) int cmd_i, scsi_cmds, total_cmds = cmds_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) spin_lock_irqsave(&ihost->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) if (ihost->state == ISCSI_HOST_REMOVED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) spin_unlock_irqrestore(&ihost->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) ihost->num_sessions++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) spin_unlock_irqrestore(&ihost->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) if (!total_cmds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) total_cmds = ISCSI_DEF_XMIT_CMDS_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) * The iscsi layer needs some tasks for nop handling and tmfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) * so the cmds_max must at least be greater than ISCSI_MGMT_CMDS_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) * + 1 command for scsi IO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) if (total_cmds < ISCSI_TOTAL_CMDS_MIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) printk(KERN_ERR "iscsi: invalid can_queue of %d. can_queue "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) "must be a power of two that is at least %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) total_cmds, ISCSI_TOTAL_CMDS_MIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) goto dec_session_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) if (total_cmds > ISCSI_TOTAL_CMDS_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) printk(KERN_ERR "iscsi: invalid can_queue of %d. can_queue "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) "must be a power of 2 less than or equal to %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) cmds_max, ISCSI_TOTAL_CMDS_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) total_cmds = ISCSI_TOTAL_CMDS_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) if (!is_power_of_2(total_cmds)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) printk(KERN_ERR "iscsi: invalid can_queue of %d. can_queue "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) "must be a power of 2.\n", total_cmds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) total_cmds = rounddown_pow_of_two(total_cmds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) if (total_cmds < ISCSI_TOTAL_CMDS_MIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) goto dec_session_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) printk(KERN_INFO "iscsi: Rounding can_queue to %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) total_cmds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) scsi_cmds = total_cmds - ISCSI_MGMT_CMDS_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) cls_session = iscsi_alloc_session(shost, iscsit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) sizeof(struct iscsi_session) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) dd_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) if (!cls_session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) goto dec_session_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) session = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) session->cls_session = cls_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) session->host = shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) session->state = ISCSI_STATE_FREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) session->fast_abort = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) session->tgt_reset_timeout = 30;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) session->lu_reset_timeout = 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) session->abort_timeout = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) session->scsi_cmds_max = scsi_cmds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) session->cmds_max = total_cmds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) session->queued_cmdsn = session->cmdsn = initial_cmdsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) session->exp_cmdsn = initial_cmdsn + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) session->max_cmdsn = initial_cmdsn + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) session->max_r2t = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) session->tt = iscsit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) session->dd_data = cls_session->dd_data + sizeof(*session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) session->tmf_state = TMF_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) timer_setup(&session->tmf_timer, iscsi_tmf_timedout, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) mutex_init(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) spin_lock_init(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) spin_lock_init(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) /* initialize SCSI PDU commands pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) if (iscsi_pool_init(&session->cmdpool, session->cmds_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) (void***)&session->cmds,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) cmd_task_size + sizeof(struct iscsi_task)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) goto cmdpool_alloc_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) /* pre-format cmds pool with ITT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) struct iscsi_task *task = session->cmds[cmd_i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) if (cmd_task_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) task->dd_data = &task[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) task->itt = cmd_i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) task->state = ISCSI_TASK_FREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) INIT_LIST_HEAD(&task->running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) if (!try_module_get(iscsit->owner))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) goto module_get_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) if (iscsi_add_session(cls_session, id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) goto cls_session_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) return cls_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) cls_session_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) module_put(iscsit->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) module_get_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) iscsi_pool_free(&session->cmdpool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) cmdpool_alloc_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) iscsi_free_session(cls_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) dec_session_count:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) iscsi_host_dec_session_cnt(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) EXPORT_SYMBOL_GPL(iscsi_session_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) * iscsi_session_teardown - destroy session, host, and cls_session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) * @cls_session: iscsi session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) void iscsi_session_teardown(struct iscsi_cls_session *cls_session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) struct iscsi_session *session = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) struct module *owner = cls_session->transport->owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) struct Scsi_Host *shost = session->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) iscsi_pool_free(&session->cmdpool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) iscsi_remove_session(cls_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) kfree(session->password);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) kfree(session->password_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) kfree(session->username);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) kfree(session->username_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) kfree(session->targetname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) kfree(session->targetalias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) kfree(session->initiatorname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) kfree(session->boot_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) kfree(session->boot_nic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) kfree(session->boot_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) kfree(session->ifacename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) kfree(session->portal_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) kfree(session->discovery_parent_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) iscsi_free_session(cls_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) iscsi_host_dec_session_cnt(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) module_put(owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) EXPORT_SYMBOL_GPL(iscsi_session_teardown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) * iscsi_conn_setup - create iscsi_cls_conn and iscsi_conn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) * @cls_session: iscsi_cls_session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) * @dd_size: private driver data size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) * @conn_idx: cid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) struct iscsi_cls_conn *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) iscsi_conn_setup(struct iscsi_cls_session *cls_session, int dd_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) uint32_t conn_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) struct iscsi_session *session = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) struct iscsi_cls_conn *cls_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) cls_conn = iscsi_create_conn(cls_session, sizeof(*conn) + dd_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) conn_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) if (!cls_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) memset(conn, 0, sizeof(*conn) + dd_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) conn->dd_data = cls_conn->dd_data + sizeof(*conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) conn->session = session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) conn->cls_conn = cls_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) conn->c_stage = ISCSI_CONN_INITIAL_STAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) conn->id = conn_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) conn->exp_statsn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) timer_setup(&conn->transport_timer, iscsi_check_transport_timeouts, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) INIT_LIST_HEAD(&conn->mgmtqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) INIT_LIST_HEAD(&conn->cmdqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) INIT_LIST_HEAD(&conn->requeue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) spin_lock_init(&conn->taskqueuelock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) INIT_WORK(&conn->xmitwork, iscsi_xmitworker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) /* allocate login_task used for the login/text sequences */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) if (!kfifo_out(&session->cmdpool.queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) (void*)&conn->login_task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) sizeof(void*))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) goto login_task_alloc_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) data = (char *) __get_free_pages(GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) get_order(ISCSI_DEF_MAX_RECV_SEG_LEN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) goto login_task_data_alloc_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) conn->login_task->data = conn->data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) init_waitqueue_head(&session->ehwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) return cls_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) login_task_data_alloc_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) kfifo_in(&session->cmdpool.queue, (void*)&conn->login_task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) sizeof(void*));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) login_task_alloc_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) iscsi_destroy_conn(cls_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) EXPORT_SYMBOL_GPL(iscsi_conn_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) * iscsi_conn_teardown - teardown iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) * @cls_conn: iscsi class connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) * TODO: we may need to make this into a two step process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) * like scsi-mls remove + put host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) struct iscsi_conn *conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) char *tmp_persistent_address = conn->persistent_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) char *tmp_local_ipaddr = conn->local_ipaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) del_timer_sync(&conn->transport_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) mutex_lock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) conn->c_stage = ISCSI_CONN_CLEANUP_WAIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) if (session->leadconn == conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) * leading connection? then give up on recovery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) session->state = ISCSI_STATE_TERMINATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) wake_up(&session->ehwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) /* flush queued up work because we free the connection below */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) iscsi_suspend_tx(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) free_pages((unsigned long) conn->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) get_order(ISCSI_DEF_MAX_RECV_SEG_LEN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) /* regular RX path uses back_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) spin_lock_bh(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) kfifo_in(&session->cmdpool.queue, (void*)&conn->login_task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) sizeof(void*));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) spin_unlock_bh(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) if (session->leadconn == conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) session->leadconn = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) mutex_unlock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) iscsi_destroy_conn(cls_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) kfree(tmp_persistent_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) kfree(tmp_local_ipaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) EXPORT_SYMBOL_GPL(iscsi_conn_teardown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) struct iscsi_conn *conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) if (!session) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) iscsi_conn_printk(KERN_ERR, conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) "can't start unbound connection\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) if ((session->imm_data_en || !session->initial_r2t_en) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) session->first_burst > session->max_burst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) iscsi_conn_printk(KERN_INFO, conn, "invalid burst lengths: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) "first_burst %d max_burst %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) session->first_burst, session->max_burst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) if (conn->ping_timeout && !conn->recv_timeout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) iscsi_conn_printk(KERN_ERR, conn, "invalid recv timeout of "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) "zero. Using 5 seconds\n.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) conn->recv_timeout = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) if (conn->recv_timeout && !conn->ping_timeout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) iscsi_conn_printk(KERN_ERR, conn, "invalid ping timeout of "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) "zero. Using 5 seconds.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) conn->ping_timeout = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) conn->c_stage = ISCSI_CONN_STARTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) session->state = ISCSI_STATE_LOGGED_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) session->queued_cmdsn = session->cmdsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) conn->last_recv = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) conn->last_ping = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) if (conn->recv_timeout && conn->ping_timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) mod_timer(&conn->transport_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) jiffies + (conn->recv_timeout * HZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) switch(conn->stop_stage) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) case STOP_CONN_RECOVER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) * unblock eh_abort() if it is blocked. re-try all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) * commands after successful recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) conn->stop_stage = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) session->tmf_state = TMF_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) session->age++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) if (session->age == 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) session->age = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) case STOP_CONN_TERM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) conn->stop_stage = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) iscsi_unblock_session(session->cls_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) wake_up(&session->ehwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) EXPORT_SYMBOL_GPL(iscsi_conn_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) fail_mgmt_tasks(struct iscsi_session *session, struct iscsi_conn *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) int i, state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) for (i = 0; i < conn->session->cmds_max; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) task = conn->session->cmds[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) if (task->sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) if (task->state == ISCSI_TASK_FREE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) ISCSI_DBG_SESSION(conn->session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) "failing mgmt itt 0x%x state %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) task->itt, task->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) state = ISCSI_TASK_ABRT_SESS_RECOV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) if (task->state == ISCSI_TASK_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) state = ISCSI_TASK_COMPLETED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) spin_lock_bh(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) iscsi_complete_task(task, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) spin_unlock_bh(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) void iscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) struct iscsi_conn *conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) int old_stop_stage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) mutex_lock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) if (conn->stop_stage == STOP_CONN_TERM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) mutex_unlock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) * When this is called for the in_login state, we only want to clean
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) * up the login task and connection. We do not need to block and set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) * the recovery state again
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) if (flag == STOP_CONN_TERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) session->state = ISCSI_STATE_TERMINATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) else if (conn->stop_stage != STOP_CONN_RECOVER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) session->state = ISCSI_STATE_IN_RECOVERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) old_stop_stage = conn->stop_stage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) conn->stop_stage = flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) del_timer_sync(&conn->transport_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) iscsi_suspend_tx(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) conn->c_stage = ISCSI_CONN_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) * for connection level recovery we should not calculate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) * header digest. conn->hdr_size used for optimization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) * in hdr_extract() and will be re-negotiated at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) * set_param() time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) if (flag == STOP_CONN_RECOVER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) conn->hdrdgst_en = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) conn->datadgst_en = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) if (session->state == ISCSI_STATE_IN_RECOVERY &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) old_stop_stage != STOP_CONN_RECOVER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) ISCSI_DBG_SESSION(session, "blocking session\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) iscsi_block_session(session->cls_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) * flush queues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) fail_scsi_tasks(conn, -1, DID_TRANSPORT_DISRUPTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) fail_mgmt_tasks(session, conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) memset(&session->tmhdr, 0, sizeof(session->tmhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) mutex_unlock(&session->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) EXPORT_SYMBOL_GPL(iscsi_conn_stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) int iscsi_conn_bind(struct iscsi_cls_session *cls_session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) struct iscsi_cls_conn *cls_conn, int is_leading)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) struct iscsi_session *session = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) struct iscsi_conn *conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) spin_lock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) if (is_leading)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) session->leadconn = conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) spin_unlock_bh(&session->frwd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) * Unblock xmitworker(), Login Phase will pass through.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) EXPORT_SYMBOL_GPL(iscsi_conn_bind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) int iscsi_switch_str_param(char **param, char *new_val_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) char *new_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) if (*param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) if (!strcmp(*param, new_val_buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) new_val = kstrdup(new_val_buf, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) if (!new_val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) kfree(*param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) *param = new_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) EXPORT_SYMBOL_GPL(iscsi_switch_str_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) int iscsi_set_param(struct iscsi_cls_conn *cls_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) enum iscsi_param param, char *buf, int buflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) struct iscsi_conn *conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) switch(param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) case ISCSI_PARAM_FAST_ABORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) sscanf(buf, "%d", &session->fast_abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) case ISCSI_PARAM_ABORT_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) sscanf(buf, "%d", &session->abort_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) case ISCSI_PARAM_LU_RESET_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) sscanf(buf, "%d", &session->lu_reset_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) case ISCSI_PARAM_TGT_RESET_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) sscanf(buf, "%d", &session->tgt_reset_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) case ISCSI_PARAM_PING_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) sscanf(buf, "%d", &conn->ping_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) case ISCSI_PARAM_RECV_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) sscanf(buf, "%d", &conn->recv_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) case ISCSI_PARAM_MAX_RECV_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) sscanf(buf, "%d", &conn->max_recv_dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) case ISCSI_PARAM_MAX_XMIT_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) sscanf(buf, "%d", &conn->max_xmit_dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) case ISCSI_PARAM_HDRDGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) sscanf(buf, "%d", &conn->hdrdgst_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) case ISCSI_PARAM_DATADGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) sscanf(buf, "%d", &conn->datadgst_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) case ISCSI_PARAM_INITIAL_R2T_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) sscanf(buf, "%d", &session->initial_r2t_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) case ISCSI_PARAM_MAX_R2T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) sscanf(buf, "%hu", &session->max_r2t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) case ISCSI_PARAM_IMM_DATA_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) sscanf(buf, "%d", &session->imm_data_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) case ISCSI_PARAM_FIRST_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) sscanf(buf, "%d", &session->first_burst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) case ISCSI_PARAM_MAX_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) sscanf(buf, "%d", &session->max_burst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) case ISCSI_PARAM_PDU_INORDER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) sscanf(buf, "%d", &session->pdu_inorder_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) case ISCSI_PARAM_DATASEQ_INORDER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) sscanf(buf, "%d", &session->dataseq_inorder_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) case ISCSI_PARAM_ERL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) sscanf(buf, "%d", &session->erl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) case ISCSI_PARAM_EXP_STATSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) sscanf(buf, "%u", &conn->exp_statsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) case ISCSI_PARAM_USERNAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) return iscsi_switch_str_param(&session->username, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) case ISCSI_PARAM_USERNAME_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) return iscsi_switch_str_param(&session->username_in, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) case ISCSI_PARAM_PASSWORD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) return iscsi_switch_str_param(&session->password, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) case ISCSI_PARAM_PASSWORD_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) return iscsi_switch_str_param(&session->password_in, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) case ISCSI_PARAM_TARGET_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) return iscsi_switch_str_param(&session->targetname, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) case ISCSI_PARAM_TARGET_ALIAS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) return iscsi_switch_str_param(&session->targetalias, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) case ISCSI_PARAM_TPGT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) sscanf(buf, "%d", &session->tpgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) case ISCSI_PARAM_PERSISTENT_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) sscanf(buf, "%d", &conn->persistent_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) case ISCSI_PARAM_PERSISTENT_ADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) return iscsi_switch_str_param(&conn->persistent_address, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) case ISCSI_PARAM_IFACE_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) return iscsi_switch_str_param(&session->ifacename, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) case ISCSI_PARAM_INITIATOR_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) return iscsi_switch_str_param(&session->initiatorname, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) case ISCSI_PARAM_BOOT_ROOT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) return iscsi_switch_str_param(&session->boot_root, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) case ISCSI_PARAM_BOOT_NIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) return iscsi_switch_str_param(&session->boot_nic, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) case ISCSI_PARAM_BOOT_TARGET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) return iscsi_switch_str_param(&session->boot_target, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) case ISCSI_PARAM_PORTAL_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) return iscsi_switch_str_param(&session->portal_type, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) return iscsi_switch_str_param(&session->discovery_parent_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) case ISCSI_PARAM_DISCOVERY_SESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) sscanf(buf, "%d", &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) session->discovery_sess = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) case ISCSI_PARAM_LOCAL_IPADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) return iscsi_switch_str_param(&conn->local_ipaddr, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) EXPORT_SYMBOL_GPL(iscsi_set_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) int iscsi_session_get_param(struct iscsi_cls_session *cls_session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) enum iscsi_param param, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) struct iscsi_session *session = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) switch(param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) case ISCSI_PARAM_FAST_ABORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) len = sysfs_emit(buf, "%d\n", session->fast_abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) case ISCSI_PARAM_ABORT_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) len = sysfs_emit(buf, "%d\n", session->abort_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) case ISCSI_PARAM_LU_RESET_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) len = sysfs_emit(buf, "%d\n", session->lu_reset_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) case ISCSI_PARAM_TGT_RESET_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) len = sysfs_emit(buf, "%d\n", session->tgt_reset_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) case ISCSI_PARAM_INITIAL_R2T_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) len = sysfs_emit(buf, "%d\n", session->initial_r2t_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) case ISCSI_PARAM_MAX_R2T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) len = sysfs_emit(buf, "%hu\n", session->max_r2t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) case ISCSI_PARAM_IMM_DATA_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) len = sysfs_emit(buf, "%d\n", session->imm_data_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) case ISCSI_PARAM_FIRST_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) len = sysfs_emit(buf, "%u\n", session->first_burst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) case ISCSI_PARAM_MAX_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) len = sysfs_emit(buf, "%u\n", session->max_burst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) case ISCSI_PARAM_PDU_INORDER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) len = sysfs_emit(buf, "%d\n", session->pdu_inorder_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) case ISCSI_PARAM_DATASEQ_INORDER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) len = sysfs_emit(buf, "%d\n", session->dataseq_inorder_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) case ISCSI_PARAM_DEF_TASKMGMT_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) len = sysfs_emit(buf, "%d\n", session->def_taskmgmt_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) case ISCSI_PARAM_ERL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) len = sysfs_emit(buf, "%d\n", session->erl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) case ISCSI_PARAM_TARGET_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) len = sysfs_emit(buf, "%s\n", session->targetname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) case ISCSI_PARAM_TARGET_ALIAS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) len = sysfs_emit(buf, "%s\n", session->targetalias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) case ISCSI_PARAM_TPGT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) len = sysfs_emit(buf, "%d\n", session->tpgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) case ISCSI_PARAM_USERNAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) len = sysfs_emit(buf, "%s\n", session->username);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) case ISCSI_PARAM_USERNAME_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) len = sysfs_emit(buf, "%s\n", session->username_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) case ISCSI_PARAM_PASSWORD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) len = sysfs_emit(buf, "%s\n", session->password);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) case ISCSI_PARAM_PASSWORD_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) len = sysfs_emit(buf, "%s\n", session->password_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) case ISCSI_PARAM_IFACE_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) len = sysfs_emit(buf, "%s\n", session->ifacename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) case ISCSI_PARAM_INITIATOR_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) len = sysfs_emit(buf, "%s\n", session->initiatorname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) case ISCSI_PARAM_BOOT_ROOT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) len = sysfs_emit(buf, "%s\n", session->boot_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) case ISCSI_PARAM_BOOT_NIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) len = sysfs_emit(buf, "%s\n", session->boot_nic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) case ISCSI_PARAM_BOOT_TARGET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) len = sysfs_emit(buf, "%s\n", session->boot_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) len = sysfs_emit(buf, "%u\n", session->auto_snd_tgt_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) case ISCSI_PARAM_DISCOVERY_SESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) len = sysfs_emit(buf, "%u\n", session->discovery_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) case ISCSI_PARAM_PORTAL_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) len = sysfs_emit(buf, "%s\n", session->portal_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) case ISCSI_PARAM_CHAP_AUTH_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) len = sysfs_emit(buf, "%u\n", session->chap_auth_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) len = sysfs_emit(buf, "%u\n", session->discovery_logout_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) case ISCSI_PARAM_BIDI_CHAP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) len = sysfs_emit(buf, "%u\n", session->bidi_chap_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) len = sysfs_emit(buf, "%u\n", session->discovery_auth_optional);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) case ISCSI_PARAM_DEF_TIME2WAIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) len = sysfs_emit(buf, "%d\n", session->time2wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) case ISCSI_PARAM_DEF_TIME2RETAIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) len = sysfs_emit(buf, "%d\n", session->time2retain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) case ISCSI_PARAM_TSID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) len = sysfs_emit(buf, "%u\n", session->tsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) case ISCSI_PARAM_ISID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) len = sysfs_emit(buf, "%02x%02x%02x%02x%02x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) session->isid[0], session->isid[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) session->isid[2], session->isid[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) session->isid[4], session->isid[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) len = sysfs_emit(buf, "%u\n", session->discovery_parent_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) if (session->discovery_parent_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) len = sysfs_emit(buf, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) session->discovery_parent_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) len = sysfs_emit(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) EXPORT_SYMBOL_GPL(iscsi_session_get_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) int iscsi_conn_get_addr_param(struct sockaddr_storage *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) enum iscsi_param param, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) struct sockaddr_in6 *sin6 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) struct sockaddr_in *sin = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) switch (addr->ss_family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) case AF_INET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) sin = (struct sockaddr_in *)addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) case AF_INET6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) sin6 = (struct sockaddr_in6 *)addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) case ISCSI_PARAM_CONN_ADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) case ISCSI_HOST_PARAM_IPADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) if (sin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) len = sysfs_emit(buf, "%pI4\n", &sin->sin_addr.s_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) len = sysfs_emit(buf, "%pI6\n", &sin6->sin6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) case ISCSI_PARAM_CONN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) case ISCSI_PARAM_LOCAL_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) if (sin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) len = sysfs_emit(buf, "%hu\n", be16_to_cpu(sin->sin_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) len = sysfs_emit(buf, "%hu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) be16_to_cpu(sin6->sin6_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) EXPORT_SYMBOL_GPL(iscsi_conn_get_addr_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) enum iscsi_param param, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) struct iscsi_conn *conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) switch(param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) case ISCSI_PARAM_PING_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) len = sysfs_emit(buf, "%u\n", conn->ping_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) case ISCSI_PARAM_RECV_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) len = sysfs_emit(buf, "%u\n", conn->recv_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) case ISCSI_PARAM_MAX_RECV_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) len = sysfs_emit(buf, "%u\n", conn->max_recv_dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) case ISCSI_PARAM_MAX_XMIT_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) len = sysfs_emit(buf, "%u\n", conn->max_xmit_dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) case ISCSI_PARAM_HDRDGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) len = sysfs_emit(buf, "%d\n", conn->hdrdgst_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) case ISCSI_PARAM_DATADGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) len = sysfs_emit(buf, "%d\n", conn->datadgst_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) case ISCSI_PARAM_IFMARKER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) len = sysfs_emit(buf, "%d\n", conn->ifmarker_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) case ISCSI_PARAM_OFMARKER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) len = sysfs_emit(buf, "%d\n", conn->ofmarker_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) case ISCSI_PARAM_EXP_STATSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) len = sysfs_emit(buf, "%u\n", conn->exp_statsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) case ISCSI_PARAM_PERSISTENT_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) len = sysfs_emit(buf, "%d\n", conn->persistent_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) case ISCSI_PARAM_PERSISTENT_ADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) len = sysfs_emit(buf, "%s\n", conn->persistent_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) case ISCSI_PARAM_STATSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) len = sysfs_emit(buf, "%u\n", conn->statsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) case ISCSI_PARAM_MAX_SEGMENT_SIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) len = sysfs_emit(buf, "%u\n", conn->max_segment_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) case ISCSI_PARAM_KEEPALIVE_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) len = sysfs_emit(buf, "%u\n", conn->keepalive_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) case ISCSI_PARAM_LOCAL_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) len = sysfs_emit(buf, "%u\n", conn->local_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) len = sysfs_emit(buf, "%u\n", conn->tcp_timestamp_stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) case ISCSI_PARAM_TCP_NAGLE_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) len = sysfs_emit(buf, "%u\n", conn->tcp_nagle_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) case ISCSI_PARAM_TCP_WSF_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) len = sysfs_emit(buf, "%u\n", conn->tcp_wsf_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) case ISCSI_PARAM_TCP_TIMER_SCALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) len = sysfs_emit(buf, "%u\n", conn->tcp_timer_scale);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) case ISCSI_PARAM_TCP_TIMESTAMP_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) len = sysfs_emit(buf, "%u\n", conn->tcp_timestamp_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) len = sysfs_emit(buf, "%u\n", conn->fragment_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) case ISCSI_PARAM_IPV4_TOS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) len = sysfs_emit(buf, "%u\n", conn->ipv4_tos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) case ISCSI_PARAM_IPV6_TC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) len = sysfs_emit(buf, "%u\n", conn->ipv6_traffic_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) case ISCSI_PARAM_IPV6_FLOW_LABEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) len = sysfs_emit(buf, "%u\n", conn->ipv6_flow_label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) len = sysfs_emit(buf, "%u\n", conn->is_fw_assigned_ipv6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) case ISCSI_PARAM_TCP_XMIT_WSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) len = sysfs_emit(buf, "%u\n", conn->tcp_xmit_wsf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) case ISCSI_PARAM_TCP_RECV_WSF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) len = sysfs_emit(buf, "%u\n", conn->tcp_recv_wsf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) case ISCSI_PARAM_LOCAL_IPADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) len = sysfs_emit(buf, "%s\n", conn->local_ipaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) EXPORT_SYMBOL_GPL(iscsi_conn_get_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) int iscsi_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) struct iscsi_host *ihost = shost_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) case ISCSI_HOST_PARAM_NETDEV_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) len = sysfs_emit(buf, "%s\n", ihost->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) case ISCSI_HOST_PARAM_HWADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) len = sysfs_emit(buf, "%s\n", ihost->hwaddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) case ISCSI_HOST_PARAM_INITIATOR_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) len = sysfs_emit(buf, "%s\n", ihost->initiatorname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) EXPORT_SYMBOL_GPL(iscsi_host_get_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) int iscsi_host_set_param(struct Scsi_Host *shost, enum iscsi_host_param param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) char *buf, int buflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) struct iscsi_host *ihost = shost_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) case ISCSI_HOST_PARAM_NETDEV_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) return iscsi_switch_str_param(&ihost->netdev, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) case ISCSI_HOST_PARAM_HWADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) return iscsi_switch_str_param(&ihost->hwaddress, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) case ISCSI_HOST_PARAM_INITIATOR_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) return iscsi_switch_str_param(&ihost->initiatorname, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) EXPORT_SYMBOL_GPL(iscsi_host_set_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) MODULE_AUTHOR("Mike Christie");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) MODULE_DESCRIPTION("iSCSI library functions");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) MODULE_LICENSE("GPL");