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