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