Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 1 | /* |
| 2 | * iSCSI Initiator over iSER Data-Path |
| 3 | * |
| 4 | * Copyright (C) 2004 Dmitry Yusupov |
| 5 | * Copyright (C) 2004 Alex Aizman |
| 6 | * Copyright (C) 2005 Mike Christie |
| 7 | * Copyright (c) 2005, 2006 Voltaire, Inc. All rights reserved. |
| 8 | * maintained by openib-general@openib.org |
| 9 | * |
| 10 | * This software is available to you under a choice of one of two |
| 11 | * licenses. You may choose to be licensed under the terms of the GNU |
| 12 | * General Public License (GPL) Version 2, available from the file |
| 13 | * COPYING in the main directory of this source tree, or the |
| 14 | * OpenIB.org BSD license below: |
| 15 | * |
| 16 | * Redistribution and use in source and binary forms, with or |
| 17 | * without modification, are permitted provided that the following |
| 18 | * conditions are met: |
| 19 | * |
| 20 | * - Redistributions of source code must retain the above |
| 21 | * copyright notice, this list of conditions and the following |
| 22 | * disclaimer. |
| 23 | * |
| 24 | * - Redistributions in binary form must reproduce the above |
| 25 | * copyright notice, this list of conditions and the following |
| 26 | * disclaimer in the documentation and/or other materials |
| 27 | * provided with the distribution. |
| 28 | * |
| 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 30 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 31 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 32 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 33 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 34 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 35 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 36 | * SOFTWARE. |
| 37 | * |
| 38 | * Credits: |
| 39 | * Christoph Hellwig |
| 40 | * FUJITA Tomonori |
| 41 | * Arne Redlich |
| 42 | * Zhenyu Wang |
| 43 | * Modified by: |
| 44 | * Erez Zilber |
| 45 | * |
| 46 | * |
| 47 | * $Id: iscsi_iser.c 6965 2006-05-07 11:36:20Z ogerlitz $ |
| 48 | */ |
| 49 | |
| 50 | #include <linux/types.h> |
| 51 | #include <linux/list.h> |
| 52 | #include <linux/hardirq.h> |
| 53 | #include <linux/kfifo.h> |
| 54 | #include <linux/blkdev.h> |
| 55 | #include <linux/init.h> |
| 56 | #include <linux/ioctl.h> |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 57 | #include <linux/cdev.h> |
| 58 | #include <linux/in.h> |
| 59 | #include <linux/net.h> |
| 60 | #include <linux/scatterlist.h> |
| 61 | #include <linux/delay.h> |
| 62 | |
| 63 | #include <net/sock.h> |
| 64 | |
| 65 | #include <asm/uaccess.h> |
| 66 | |
| 67 | #include <scsi/scsi_cmnd.h> |
| 68 | #include <scsi/scsi_device.h> |
| 69 | #include <scsi/scsi_eh.h> |
| 70 | #include <scsi/scsi_tcq.h> |
| 71 | #include <scsi/scsi_host.h> |
| 72 | #include <scsi/scsi.h> |
| 73 | #include <scsi/scsi_transport_iscsi.h> |
| 74 | |
| 75 | #include "iscsi_iser.h" |
| 76 | |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 77 | static struct scsi_host_template iscsi_iser_sht; |
| 78 | static struct iscsi_transport iscsi_iser_transport; |
| 79 | static struct scsi_transport_template *iscsi_iser_scsi_transport; |
| 80 | |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 81 | static unsigned int iscsi_max_lun = 512; |
| 82 | module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO); |
| 83 | |
| 84 | int iser_debug_level = 0; |
| 85 | |
| 86 | MODULE_DESCRIPTION("iSER (iSCSI Extensions for RDMA) Datamover " |
| 87 | "v" DRV_VER " (" DRV_DATE ")"); |
| 88 | MODULE_LICENSE("Dual BSD/GPL"); |
| 89 | MODULE_AUTHOR("Alex Nezhinsky, Dan Bar Dov, Or Gerlitz"); |
| 90 | |
| 91 | module_param_named(debug_level, iser_debug_level, int, 0644); |
| 92 | MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0 (default:disabled)"); |
| 93 | |
| 94 | struct iser_global ig; |
| 95 | |
| 96 | void |
| 97 | iscsi_iser_recv(struct iscsi_conn *conn, |
| 98 | struct iscsi_hdr *hdr, char *rx_data, int rx_data_len) |
| 99 | { |
| 100 | int rc = 0; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 101 | int datalen; |
| 102 | int ahslen; |
| 103 | |
| 104 | /* verify PDU length */ |
| 105 | datalen = ntoh24(hdr->dlength); |
| 106 | if (datalen != rx_data_len) { |
| 107 | printk(KERN_ERR "iscsi_iser: datalen %d (hdr) != %d (IB) \n", |
| 108 | datalen, rx_data_len); |
| 109 | rc = ISCSI_ERR_DATALEN; |
| 110 | goto error; |
| 111 | } |
| 112 | |
| 113 | /* read AHS */ |
| 114 | ahslen = hdr->hlength * 4; |
| 115 | |
Mike Christie | 0af967f | 2008-05-21 15:54:04 -0500 | [diff] [blame] | 116 | rc = iscsi_complete_pdu(conn, hdr, rx_data, rx_data_len); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 117 | if (rc && rc != ISCSI_ERR_NO_SCSI_CMD) |
| 118 | goto error; |
| 119 | |
| 120 | return; |
| 121 | error: |
| 122 | iscsi_conn_failure(conn, rc); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | /** |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 127 | * iscsi_iser_task_init - Initialize task |
| 128 | * @task: iscsi task |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 129 | * |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 130 | * Initialize the task for the scsi command or mgmt command. |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 131 | */ |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 132 | static int |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 133 | iscsi_iser_task_init(struct iscsi_task *task) |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 134 | { |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 135 | struct iscsi_iser_conn *iser_conn = task->conn->dd_data; |
| 136 | struct iscsi_iser_task *iser_task = task->dd_data; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 137 | |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 138 | /* mgmt task */ |
| 139 | if (!task->sc) { |
| 140 | iser_task->desc.data = task->data; |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 141 | return 0; |
| 142 | } |
| 143 | |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 144 | iser_task->command_sent = 0; |
| 145 | iser_task->iser_conn = iser_conn; |
| 146 | iser_task_rdma_init(iser_task); |
Olaf Kirch | a8ac631 | 2007-12-13 12:43:35 -0600 | [diff] [blame] | 147 | return 0; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /** |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 151 | * iscsi_iser_mtask_xmit - xmit management(immediate) task |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 152 | * @conn: iscsi connection |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 153 | * @task: task management task |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 154 | * |
| 155 | * Notes: |
| 156 | * The function can return -EAGAIN in which case caller must |
| 157 | * call it again later, or recover. '0' return code means successful |
| 158 | * xmit. |
| 159 | * |
| 160 | **/ |
| 161 | static int |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 162 | iscsi_iser_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task) |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 163 | { |
| 164 | int error = 0; |
| 165 | |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 166 | debug_scsi("task deq [cid %d itt 0x%x]\n", conn->id, task->itt); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 167 | |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 168 | error = iser_send_control(conn, task); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 169 | |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 170 | /* since iser xmits control with zero copy, tasks can not be recycled |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 171 | * right after sending them. |
| 172 | * The recycling scheme is based on whether a response is expected |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 173 | * - if yes, the task is recycled at iscsi_complete_pdu |
| 174 | * - if no, the task is recycled at iser_snd_completion |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 175 | */ |
Erez Zilber | f093840 | 2007-01-07 12:28:02 +0200 | [diff] [blame] | 176 | if (error && error != -ENOBUFS) |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 177 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
| 178 | |
| 179 | return error; |
| 180 | } |
| 181 | |
| 182 | static int |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 183 | iscsi_iser_task_xmit_unsol_data(struct iscsi_conn *conn, |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 184 | struct iscsi_task *task) |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 185 | { |
| 186 | struct iscsi_data hdr; |
| 187 | int error = 0; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 188 | |
| 189 | /* Send data-out PDUs while there's still unsolicited data to send */ |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 190 | while (task->unsol_count > 0) { |
| 191 | iscsi_prep_unsolicit_data_pdu(task, &hdr); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 192 | debug_scsi("Sending data-out: itt 0x%x, data count %d\n", |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 193 | hdr.itt, task->data_count); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 194 | |
| 195 | /* the buffer description has been passed with the command */ |
| 196 | /* Send the command */ |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 197 | error = iser_send_data_out(conn, task, &hdr); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 198 | if (error) { |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 199 | task->unsol_datasn--; |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 200 | goto iscsi_iser_task_xmit_unsol_data_exit; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 201 | } |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 202 | task->unsol_count -= task->data_count; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 203 | debug_scsi("Need to send %d more as data-out PDUs\n", |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 204 | task->unsol_count); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 205 | } |
| 206 | |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 207 | iscsi_iser_task_xmit_unsol_data_exit: |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 208 | return error; |
| 209 | } |
| 210 | |
| 211 | static int |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 212 | iscsi_iser_task_xmit(struct iscsi_task *task) |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 213 | { |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 214 | struct iscsi_conn *conn = task->conn; |
| 215 | struct iscsi_iser_task *iser_task = task->dd_data; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 216 | int error = 0; |
| 217 | |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 218 | if (!task->sc) |
| 219 | return iscsi_iser_mtask_xmit(conn, task); |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 220 | |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 221 | if (task->sc->sc_data_direction == DMA_TO_DEVICE) { |
| 222 | BUG_ON(scsi_bufflen(task->sc) == 0); |
Mike Christie | 77a23c2 | 2007-05-30 12:57:18 -0500 | [diff] [blame] | 223 | |
| 224 | debug_scsi("cmd [itt %x total %d imm %d unsol_data %d\n", |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 225 | task->itt, scsi_bufflen(task->sc), |
| 226 | task->imm_count, task->unsol_count); |
Mike Christie | 77a23c2 | 2007-05-30 12:57:18 -0500 | [diff] [blame] | 227 | } |
| 228 | |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 229 | debug_scsi("task deq [cid %d itt 0x%x]\n", |
| 230 | conn->id, task->itt); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 231 | |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 232 | /* Send the cmd PDU */ |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 233 | if (!iser_task->command_sent) { |
| 234 | error = iser_send_command(conn, task); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 235 | if (error) |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 236 | goto iscsi_iser_task_xmit_exit; |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 237 | iser_task->command_sent = 1; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /* Send unsolicited data-out PDU(s) if necessary */ |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 241 | if (task->unsol_count) |
| 242 | error = iscsi_iser_task_xmit_unsol_data(conn, task); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 243 | |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 244 | iscsi_iser_task_xmit_exit: |
Erez Zilber | f093840 | 2007-01-07 12:28:02 +0200 | [diff] [blame] | 245 | if (error && error != -ENOBUFS) |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 246 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
| 247 | return error; |
| 248 | } |
| 249 | |
| 250 | static void |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 251 | iscsi_iser_cleanup_task(struct iscsi_conn *conn, struct iscsi_task *task) |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 252 | { |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 253 | struct iscsi_iser_task *iser_task = task->dd_data; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 254 | |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 255 | /* mgmt tasks do not need special cleanup */ |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 256 | if (!task->sc) |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 257 | return; |
| 258 | |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 259 | if (iser_task->status == ISER_TASK_STATUS_STARTED) { |
| 260 | iser_task->status = ISER_TASK_STATUS_COMPLETED; |
| 261 | iser_task_rdma_finalize(iser_task); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
| 265 | static struct iser_conn * |
| 266 | iscsi_iser_ib_conn_lookup(__u64 ep_handle) |
| 267 | { |
| 268 | struct iser_conn *ib_conn; |
| 269 | struct iser_conn *uib_conn = (struct iser_conn *)(unsigned long)ep_handle; |
| 270 | |
| 271 | mutex_lock(&ig.connlist_mutex); |
| 272 | list_for_each_entry(ib_conn, &ig.connlist, conn_list) { |
| 273 | if (ib_conn == uib_conn) { |
| 274 | mutex_unlock(&ig.connlist_mutex); |
| 275 | return ib_conn; |
| 276 | } |
| 277 | } |
| 278 | mutex_unlock(&ig.connlist_mutex); |
| 279 | iser_err("no conn exists for eph %llx\n",(unsigned long long)ep_handle); |
| 280 | return NULL; |
| 281 | } |
| 282 | |
| 283 | static struct iscsi_cls_conn * |
| 284 | iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx) |
| 285 | { |
| 286 | struct iscsi_conn *conn; |
| 287 | struct iscsi_cls_conn *cls_conn; |
| 288 | struct iscsi_iser_conn *iser_conn; |
| 289 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 290 | cls_conn = iscsi_conn_setup(cls_session, sizeof(*iser_conn), conn_idx); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 291 | if (!cls_conn) |
| 292 | return NULL; |
| 293 | conn = cls_conn->dd_data; |
| 294 | |
| 295 | /* |
| 296 | * due to issues with the login code re iser sematics |
| 297 | * this not set in iscsi_conn_setup - FIXME |
| 298 | */ |
| 299 | conn->max_recv_dlength = 128; |
| 300 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 301 | iser_conn = conn->dd_data; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 302 | /* currently this is the only field which need to be initiated */ |
| 303 | rwlock_init(&iser_conn->lock); |
| 304 | |
| 305 | conn->dd_data = iser_conn; |
| 306 | iser_conn->iscsi_conn = conn; |
| 307 | |
| 308 | return cls_conn; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | static void |
| 312 | iscsi_iser_conn_destroy(struct iscsi_cls_conn *cls_conn) |
| 313 | { |
| 314 | struct iscsi_conn *conn = cls_conn->dd_data; |
| 315 | struct iscsi_iser_conn *iser_conn = conn->dd_data; |
Mike Christie | b40977d | 2008-05-21 15:54:03 -0500 | [diff] [blame] | 316 | struct iser_conn *ib_conn = iser_conn->ib_conn; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 317 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 318 | iscsi_conn_teardown(cls_conn); |
Mike Christie | b40977d | 2008-05-21 15:54:03 -0500 | [diff] [blame] | 319 | /* |
| 320 | * Userspace will normally call the stop callback and |
| 321 | * already have freed the ib_conn, but if it goofed up then |
| 322 | * we free it here. |
| 323 | */ |
| 324 | if (ib_conn) { |
| 325 | ib_conn->iser_conn = NULL; |
| 326 | iser_conn_put(ib_conn); |
| 327 | } |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | static int |
| 331 | iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session, |
| 332 | struct iscsi_cls_conn *cls_conn, uint64_t transport_eph, |
| 333 | int is_leading) |
| 334 | { |
| 335 | struct iscsi_conn *conn = cls_conn->dd_data; |
| 336 | struct iscsi_iser_conn *iser_conn; |
| 337 | struct iser_conn *ib_conn; |
| 338 | int error; |
| 339 | |
| 340 | error = iscsi_conn_bind(cls_session, cls_conn, is_leading); |
| 341 | if (error) |
| 342 | return error; |
| 343 | |
| 344 | /* the transport ep handle comes from user space so it must be |
| 345 | * verified against the global ib connections list */ |
| 346 | ib_conn = iscsi_iser_ib_conn_lookup(transport_eph); |
| 347 | if (!ib_conn) { |
| 348 | iser_err("can't bind eph %llx\n", |
| 349 | (unsigned long long)transport_eph); |
| 350 | return -EINVAL; |
| 351 | } |
| 352 | /* binds the iSER connection retrieved from the previously |
| 353 | * connected ep_handle to the iSCSI layer connection. exchanges |
| 354 | * connection pointers */ |
| 355 | iser_err("binding iscsi conn %p to iser_conn %p\n",conn,ib_conn); |
| 356 | iser_conn = conn->dd_data; |
| 357 | ib_conn->iser_conn = iser_conn; |
| 358 | iser_conn->ib_conn = ib_conn; |
Mike Christie | b40977d | 2008-05-21 15:54:03 -0500 | [diff] [blame] | 359 | iser_conn_get(ib_conn); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 360 | |
| 361 | conn->recv_lock = &iser_conn->lock; |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
Mike Christie | b40977d | 2008-05-21 15:54:03 -0500 | [diff] [blame] | 366 | static void |
| 367 | iscsi_iser_conn_stop(struct iscsi_cls_conn *cls_conn, int flag) |
| 368 | { |
| 369 | struct iscsi_conn *conn = cls_conn->dd_data; |
| 370 | struct iscsi_iser_conn *iser_conn = conn->dd_data; |
| 371 | struct iser_conn *ib_conn = iser_conn->ib_conn; |
| 372 | |
| 373 | iscsi_conn_stop(cls_conn, flag); |
| 374 | /* |
| 375 | * There is no unbind event so the stop callback |
| 376 | * must release the ref from the bind. |
| 377 | */ |
| 378 | iser_conn_put(ib_conn); |
| 379 | iser_conn->ib_conn = NULL; |
| 380 | } |
| 381 | |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 382 | static int |
| 383 | iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn) |
| 384 | { |
| 385 | struct iscsi_conn *conn = cls_conn->dd_data; |
| 386 | int err; |
| 387 | |
Erez Zilber | 2e7a742 | 2006-10-22 10:28:38 +0200 | [diff] [blame] | 388 | err = iser_conn_set_full_featured_mode(conn); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 389 | if (err) |
| 390 | return err; |
| 391 | |
Erez Zilber | 2e7a742 | 2006-10-22 10:28:38 +0200 | [diff] [blame] | 392 | return iscsi_conn_start(cls_conn); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 393 | } |
| 394 | |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 395 | static void iscsi_iser_session_destroy(struct iscsi_cls_session *cls_session) |
| 396 | { |
| 397 | struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); |
| 398 | |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 399 | iscsi_host_remove(shost); |
| 400 | iscsi_host_free(shost); |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 401 | } |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 402 | |
| 403 | static struct iscsi_cls_session * |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 404 | iscsi_iser_session_create(struct Scsi_Host *shost, |
| 405 | uint16_t cmds_max, uint16_t qdepth, |
| 406 | uint32_t initial_cmdsn, uint32_t *hostno) |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 407 | { |
| 408 | struct iscsi_cls_session *cls_session; |
| 409 | struct iscsi_session *session; |
| 410 | int i; |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 411 | struct iscsi_task *task; |
| 412 | struct iscsi_iser_task *iser_task; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 413 | |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 414 | if (shost) { |
| 415 | printk(KERN_ERR "iscsi_tcp: invalid shost %d.\n", |
| 416 | shost->host_no); |
| 417 | return NULL; |
| 418 | } |
| 419 | |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 420 | shost = iscsi_host_alloc(&iscsi_iser_sht, 0, ISCSI_MAX_CMD_PER_LUN); |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 421 | if (!shost) |
| 422 | return NULL; |
| 423 | shost->transportt = iscsi_iser_scsi_transport; |
| 424 | shost->max_lun = iscsi_max_lun; |
| 425 | shost->max_id = 0; |
| 426 | shost->max_channel = 0; |
| 427 | shost->max_cmd_len = 16; |
| 428 | |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 429 | if (iscsi_host_add(shost, NULL)) |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 430 | goto free_host; |
| 431 | *hostno = shost->host_no; |
| 432 | |
Mike Christie | 1548271 | 2007-05-30 12:57:19 -0500 | [diff] [blame] | 433 | /* |
| 434 | * we do not support setting can_queue cmd_per_lun from userspace yet |
| 435 | * because we preallocate so many resources |
| 436 | */ |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 437 | cls_session = iscsi_session_setup(&iscsi_iser_transport, shost, |
Mike Christie | 1548271 | 2007-05-30 12:57:19 -0500 | [diff] [blame] | 438 | ISCSI_DEF_XMIT_CMDS_MAX, |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 439 | sizeof(struct iscsi_iser_task), |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 440 | initial_cmdsn, 0); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 441 | if (!cls_session) |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 442 | goto remove_host; |
| 443 | session = cls_session->dd_data; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 444 | |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 445 | shost->can_queue = session->scsi_cmds_max; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 446 | /* libiscsi setup itts, data and pool so just set desc fields */ |
| 447 | for (i = 0; i < session->cmds_max; i++) { |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 448 | task = session->cmds[i]; |
| 449 | iser_task = task->dd_data; |
| 450 | task->hdr = (struct iscsi_cmd *)&iser_task->desc.iscsi_header; |
| 451 | task->hdr_max = sizeof(iser_task->desc.iscsi_header); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 452 | } |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 453 | return cls_session; |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 454 | |
| 455 | remove_host: |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 456 | iscsi_host_remove(shost); |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 457 | free_host: |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 458 | iscsi_host_free(shost); |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 459 | return NULL; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | static int |
Mike Christie | 358ff01 | 2006-06-28 12:00:25 -0500 | [diff] [blame] | 463 | iscsi_iser_set_param(struct iscsi_cls_conn *cls_conn, |
| 464 | enum iscsi_param param, char *buf, int buflen) |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 465 | { |
Mike Christie | 358ff01 | 2006-06-28 12:00:25 -0500 | [diff] [blame] | 466 | int value; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 467 | |
| 468 | switch (param) { |
| 469 | case ISCSI_PARAM_MAX_RECV_DLENGTH: |
| 470 | /* TBD */ |
| 471 | break; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 472 | case ISCSI_PARAM_HDRDGST_EN: |
Mike Christie | 358ff01 | 2006-06-28 12:00:25 -0500 | [diff] [blame] | 473 | sscanf(buf, "%d", &value); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 474 | if (value) { |
| 475 | printk(KERN_ERR "DataDigest wasn't negotiated to None"); |
| 476 | return -EPROTO; |
| 477 | } |
| 478 | break; |
| 479 | case ISCSI_PARAM_DATADGST_EN: |
Mike Christie | 358ff01 | 2006-06-28 12:00:25 -0500 | [diff] [blame] | 480 | sscanf(buf, "%d", &value); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 481 | if (value) { |
| 482 | printk(KERN_ERR "DataDigest wasn't negotiated to None"); |
| 483 | return -EPROTO; |
| 484 | } |
| 485 | break; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 486 | case ISCSI_PARAM_IFMARKER_EN: |
Mike Christie | 358ff01 | 2006-06-28 12:00:25 -0500 | [diff] [blame] | 487 | sscanf(buf, "%d", &value); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 488 | if (value) { |
| 489 | printk(KERN_ERR "IFMarker wasn't negotiated to No"); |
| 490 | return -EPROTO; |
| 491 | } |
| 492 | break; |
| 493 | case ISCSI_PARAM_OFMARKER_EN: |
Mike Christie | 358ff01 | 2006-06-28 12:00:25 -0500 | [diff] [blame] | 494 | sscanf(buf, "%d", &value); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 495 | if (value) { |
| 496 | printk(KERN_ERR "OFMarker wasn't negotiated to No"); |
| 497 | return -EPROTO; |
| 498 | } |
| 499 | break; |
| 500 | default: |
Mike Christie | 358ff01 | 2006-06-28 12:00:25 -0500 | [diff] [blame] | 501 | return iscsi_set_param(cls_conn, param, buf, buflen); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 507 | static void |
| 508 | iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats) |
| 509 | { |
| 510 | struct iscsi_conn *conn = cls_conn->dd_data; |
| 511 | |
| 512 | stats->txdata_octets = conn->txdata_octets; |
| 513 | stats->rxdata_octets = conn->rxdata_octets; |
| 514 | stats->scsicmd_pdus = conn->scsicmd_pdus_cnt; |
| 515 | stats->dataout_pdus = conn->dataout_pdus_cnt; |
| 516 | stats->scsirsp_pdus = conn->scsirsp_pdus_cnt; |
| 517 | stats->datain_pdus = conn->datain_pdus_cnt; /* always 0 */ |
| 518 | stats->r2t_pdus = conn->r2t_pdus_cnt; /* always 0 */ |
| 519 | stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt; |
| 520 | stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt; |
Eli Dorfman | 8752822 | 2008-04-29 13:46:52 -0700 | [diff] [blame] | 521 | stats->custom_length = 4; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 522 | strcpy(stats->custom[0].desc, "qp_tx_queue_full"); |
| 523 | stats->custom[0].value = 0; /* TB iser_conn->qp_tx_queue_full; */ |
| 524 | strcpy(stats->custom[1].desc, "fmr_map_not_avail"); |
| 525 | stats->custom[1].value = 0; /* TB iser_conn->fmr_map_not_avail */; |
| 526 | strcpy(stats->custom[2].desc, "eh_abort_cnt"); |
| 527 | stats->custom[2].value = conn->eh_abort_cnt; |
Eli Dorfman | 8752822 | 2008-04-29 13:46:52 -0700 | [diff] [blame] | 528 | strcpy(stats->custom[3].desc, "fmr_unalign_cnt"); |
| 529 | stats->custom[3].value = conn->fmr_unalign_cnt; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | static int |
| 533 | iscsi_iser_ep_connect(struct sockaddr *dst_addr, int non_blocking, |
| 534 | __u64 *ep_handle) |
| 535 | { |
| 536 | int err; |
| 537 | struct iser_conn *ib_conn; |
| 538 | |
| 539 | err = iser_conn_init(&ib_conn); |
| 540 | if (err) |
| 541 | goto out; |
| 542 | |
| 543 | err = iser_connect(ib_conn, NULL, (struct sockaddr_in *)dst_addr, non_blocking); |
| 544 | if (!err) |
| 545 | *ep_handle = (__u64)(unsigned long)ib_conn; |
| 546 | |
| 547 | out: |
| 548 | return err; |
| 549 | } |
| 550 | |
| 551 | static int |
| 552 | iscsi_iser_ep_poll(__u64 ep_handle, int timeout_ms) |
| 553 | { |
| 554 | struct iser_conn *ib_conn = iscsi_iser_ib_conn_lookup(ep_handle); |
| 555 | int rc; |
| 556 | |
| 557 | if (!ib_conn) |
| 558 | return -EINVAL; |
| 559 | |
| 560 | rc = wait_event_interruptible_timeout(ib_conn->wait, |
| 561 | ib_conn->state == ISER_CONN_UP, |
| 562 | msecs_to_jiffies(timeout_ms)); |
| 563 | |
| 564 | /* if conn establishment failed, return error code to iscsi */ |
| 565 | if (!rc && |
| 566 | (ib_conn->state == ISER_CONN_TERMINATING || |
| 567 | ib_conn->state == ISER_CONN_DOWN)) |
| 568 | rc = -1; |
| 569 | |
| 570 | iser_err("ib conn %p rc = %d\n", ib_conn, rc); |
| 571 | |
| 572 | if (rc > 0) |
| 573 | return 1; /* success, this is the equivalent of POLLOUT */ |
| 574 | else if (!rc) |
| 575 | return 0; /* timeout */ |
| 576 | else |
| 577 | return rc; /* signal */ |
| 578 | } |
| 579 | |
| 580 | static void |
| 581 | iscsi_iser_ep_disconnect(__u64 ep_handle) |
| 582 | { |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 583 | struct iser_conn *ib_conn; |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 584 | |
Mike Christie | 1c83469 | 2006-07-24 15:47:26 -0500 | [diff] [blame] | 585 | ib_conn = iscsi_iser_ib_conn_lookup(ep_handle); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 586 | if (!ib_conn) |
| 587 | return; |
| 588 | |
Mike Christie | b40977d | 2008-05-21 15:54:03 -0500 | [diff] [blame] | 589 | if (ib_conn->iser_conn) |
| 590 | /* |
| 591 | * Must suspend xmit path if the ep is bound to the |
| 592 | * iscsi_conn, so we know we are not accessing the ib_conn |
| 593 | * when we free it. |
| 594 | * |
| 595 | * This may not be bound if the ep poll failed. |
| 596 | */ |
| 597 | iscsi_suspend_tx(ib_conn->iser_conn->iscsi_conn); |
| 598 | |
| 599 | |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 600 | iser_err("ib conn %p state %d\n",ib_conn, ib_conn->state); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 601 | iser_conn_terminate(ib_conn); |
| 602 | } |
| 603 | |
| 604 | static struct scsi_host_template iscsi_iser_sht = { |
Mike Christie | 7974392 | 2007-07-26 12:46:46 -0500 | [diff] [blame] | 605 | .module = THIS_MODULE, |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 606 | .name = "iSCSI Initiator over iSER, v." DRV_VER, |
| 607 | .queuecommand = iscsi_queuecommand, |
Erez Zilber | 6410627 | 2008-01-17 11:53:17 +0200 | [diff] [blame] | 608 | .change_queue_depth = iscsi_change_queue_depth, |
Mike Christie | 1548271 | 2007-05-30 12:57:19 -0500 | [diff] [blame] | 609 | .can_queue = ISCSI_DEF_XMIT_CMDS_MAX - 1, |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 610 | .sg_tablesize = ISCSI_ISER_SG_TABLESIZE, |
Erez Zilber | 8072ec2 | 2006-09-11 12:20:54 +0300 | [diff] [blame] | 611 | .max_sectors = 1024, |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 612 | .cmd_per_lun = ISCSI_MAX_CMD_PER_LUN, |
| 613 | .eh_abort_handler = iscsi_eh_abort, |
Erez Zilber | 90c18f3 | 2008-01-22 12:06:25 +0200 | [diff] [blame] | 614 | .eh_device_reset_handler= iscsi_eh_device_reset, |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 615 | .eh_host_reset_handler = iscsi_eh_host_reset, |
| 616 | .use_clustering = DISABLE_CLUSTERING, |
| 617 | .proc_name = "iscsi_iser", |
| 618 | .this_id = -1, |
| 619 | }; |
| 620 | |
| 621 | static struct iscsi_transport iscsi_iser_transport = { |
| 622 | .owner = THIS_MODULE, |
| 623 | .name = "iser", |
| 624 | .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T, |
| 625 | .param_mask = ISCSI_MAX_RECV_DLENGTH | |
| 626 | ISCSI_MAX_XMIT_DLENGTH | |
| 627 | ISCSI_HDRDGST_EN | |
| 628 | ISCSI_DATADGST_EN | |
| 629 | ISCSI_INITIAL_R2T_EN | |
| 630 | ISCSI_MAX_R2T | |
| 631 | ISCSI_IMM_DATA_EN | |
| 632 | ISCSI_FIRST_BURST | |
| 633 | ISCSI_MAX_BURST | |
| 634 | ISCSI_PDU_INORDER_EN | |
Mike Christie | 358ff01 | 2006-06-28 12:00:25 -0500 | [diff] [blame] | 635 | ISCSI_DATASEQ_INORDER_EN | |
| 636 | ISCSI_EXP_STATSN | |
| 637 | ISCSI_PERSISTENT_PORT | |
| 638 | ISCSI_PERSISTENT_ADDRESS | |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 639 | ISCSI_TARGET_NAME | ISCSI_TPGT | |
| 640 | ISCSI_USERNAME | ISCSI_PASSWORD | |
Mike Christie | f6d5180 | 2007-12-13 12:43:30 -0600 | [diff] [blame] | 641 | ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN | |
| 642 | ISCSI_FAST_ABORT | ISCSI_ABORT_TMO | |
| 643 | ISCSI_PING_TMO | ISCSI_RECV_TMO, |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 644 | .host_param_mask = ISCSI_HOST_HWADDRESS | |
Mike Christie | d8196ed | 2007-05-30 12:57:25 -0500 | [diff] [blame] | 645 | ISCSI_HOST_NETDEV_NAME | |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 646 | ISCSI_HOST_INITIATOR_NAME, |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 647 | /* session management */ |
| 648 | .create_session = iscsi_iser_session_create, |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 649 | .destroy_session = iscsi_iser_session_destroy, |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 650 | /* connection management */ |
| 651 | .create_conn = iscsi_iser_conn_create, |
| 652 | .bind_conn = iscsi_iser_conn_bind, |
| 653 | .destroy_conn = iscsi_iser_conn_destroy, |
Mike Christie | 358ff01 | 2006-06-28 12:00:25 -0500 | [diff] [blame] | 654 | .set_param = iscsi_iser_set_param, |
| 655 | .get_conn_param = iscsi_conn_get_param, |
| 656 | .get_session_param = iscsi_session_get_param, |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 657 | .start_conn = iscsi_iser_conn_start, |
Mike Christie | b40977d | 2008-05-21 15:54:03 -0500 | [diff] [blame] | 658 | .stop_conn = iscsi_iser_conn_stop, |
Mike Christie | 0801c24 | 2007-05-30 12:57:12 -0500 | [diff] [blame] | 659 | /* iscsi host params */ |
| 660 | .get_host_param = iscsi_host_get_param, |
| 661 | .set_host_param = iscsi_host_set_param, |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 662 | /* IO */ |
| 663 | .send_pdu = iscsi_conn_send_pdu, |
| 664 | .get_stats = iscsi_iser_conn_get_stats, |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 665 | .init_task = iscsi_iser_task_init, |
| 666 | .xmit_task = iscsi_iser_task_xmit, |
| 667 | .cleanup_task = iscsi_iser_cleanup_task, |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 668 | /* recovery */ |
| 669 | .session_recovery_timedout = iscsi_session_recovery_timedout, |
| 670 | |
| 671 | .ep_connect = iscsi_iser_ep_connect, |
| 672 | .ep_poll = iscsi_iser_ep_poll, |
| 673 | .ep_disconnect = iscsi_iser_ep_disconnect |
| 674 | }; |
| 675 | |
| 676 | static int __init iser_init(void) |
| 677 | { |
| 678 | int err; |
| 679 | |
| 680 | iser_dbg("Starting iSER datamover...\n"); |
| 681 | |
| 682 | if (iscsi_max_lun < 1) { |
| 683 | printk(KERN_ERR "Invalid max_lun value of %u\n", iscsi_max_lun); |
| 684 | return -EINVAL; |
| 685 | } |
| 686 | |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 687 | memset(&ig, 0, sizeof(struct iser_global)); |
| 688 | |
| 689 | ig.desc_cache = kmem_cache_create("iser_descriptors", |
| 690 | sizeof (struct iser_desc), |
| 691 | 0, SLAB_HWCACHE_ALIGN, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 692 | NULL); |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 693 | if (ig.desc_cache == NULL) |
| 694 | return -ENOMEM; |
| 695 | |
| 696 | /* device init is called only after the first addr resolution */ |
| 697 | mutex_init(&ig.device_list_mutex); |
| 698 | INIT_LIST_HEAD(&ig.device_list); |
| 699 | mutex_init(&ig.connlist_mutex); |
| 700 | INIT_LIST_HEAD(&ig.connlist); |
| 701 | |
Mike Christie | 7561352 | 2008-05-21 15:53:59 -0500 | [diff] [blame] | 702 | iscsi_iser_scsi_transport = iscsi_register_transport( |
| 703 | &iscsi_iser_transport); |
| 704 | if (!iscsi_iser_scsi_transport) { |
Or Gerlitz | 65e7ae7 | 2006-05-11 10:00:44 +0300 | [diff] [blame] | 705 | iser_err("iscsi_register_transport failed\n"); |
| 706 | err = -EINVAL; |
| 707 | goto register_transport_failure; |
| 708 | } |
| 709 | |
| 710 | return 0; |
| 711 | |
| 712 | register_transport_failure: |
| 713 | kmem_cache_destroy(ig.desc_cache); |
| 714 | |
| 715 | return err; |
| 716 | } |
| 717 | |
| 718 | static void __exit iser_exit(void) |
| 719 | { |
| 720 | iser_dbg("Removing iSER datamover...\n"); |
| 721 | iscsi_unregister_transport(&iscsi_iser_transport); |
| 722 | kmem_cache_destroy(ig.desc_cache); |
| 723 | } |
| 724 | |
| 725 | module_init(iser_init); |
| 726 | module_exit(iser_exit); |