blob: 4cd07056e45689ce9a9cb1dc75814c6e9260f319 [file] [log] [blame]
Or Gerlitz65e7ae72006-05-11 10:00:44 +03001/*
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 Gerlitz65e7ae72006-05-11 10:00:44 +030057#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
77static unsigned int iscsi_max_lun = 512;
78module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
79
80int iser_debug_level = 0;
81
82MODULE_DESCRIPTION("iSER (iSCSI Extensions for RDMA) Datamover "
83 "v" DRV_VER " (" DRV_DATE ")");
84MODULE_LICENSE("Dual BSD/GPL");
85MODULE_AUTHOR("Alex Nezhinsky, Dan Bar Dov, Or Gerlitz");
86
87module_param_named(debug_level, iser_debug_level, int, 0644);
88MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0 (default:disabled)");
89
90struct iser_global ig;
91
92void
93iscsi_iser_recv(struct iscsi_conn *conn,
94 struct iscsi_hdr *hdr, char *rx_data, int rx_data_len)
95{
96 int rc = 0;
97 uint32_t ret_itt;
98 int datalen;
99 int ahslen;
100
101 /* verify PDU length */
102 datalen = ntoh24(hdr->dlength);
103 if (datalen != rx_data_len) {
104 printk(KERN_ERR "iscsi_iser: datalen %d (hdr) != %d (IB) \n",
105 datalen, rx_data_len);
106 rc = ISCSI_ERR_DATALEN;
107 goto error;
108 }
109
110 /* read AHS */
111 ahslen = hdr->hlength * 4;
112
113 /* verify itt (itt encoding: age+cid+itt) */
114 rc = iscsi_verify_itt(conn, hdr, &ret_itt);
115
116 if (!rc)
117 rc = iscsi_complete_pdu(conn, hdr, rx_data, rx_data_len);
118
119 if (rc && rc != ISCSI_ERR_NO_SCSI_CMD)
120 goto error;
121
122 return;
123error:
124 iscsi_conn_failure(conn, rc);
125}
126
127
128/**
129 * iscsi_iser_cmd_init - Initialize iSCSI SCSI_READ or SCSI_WRITE commands
130 *
131 **/
Olaf Kircha8ac6312007-12-13 12:43:35 -0600132static int
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300133iscsi_iser_cmd_init(struct iscsi_cmd_task *ctask)
134{
135 struct iscsi_iser_conn *iser_conn = ctask->conn->dd_data;
136 struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300137
138 iser_ctask->command_sent = 0;
139 iser_ctask->iser_conn = iser_conn;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300140 iser_ctask_rdma_init(iser_ctask);
Olaf Kircha8ac6312007-12-13 12:43:35 -0600141 return 0;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300142}
143
144/**
145 * iscsi_mtask_xmit - xmit management(immediate) task
146 * @conn: iscsi connection
147 * @mtask: task management task
148 *
149 * Notes:
150 * The function can return -EAGAIN in which case caller must
151 * call it again later, or recover. '0' return code means successful
152 * xmit.
153 *
154 **/
155static int
156iscsi_iser_mtask_xmit(struct iscsi_conn *conn,
157 struct iscsi_mgmt_task *mtask)
158{
159 int error = 0;
160
161 debug_scsi("mtask deq [cid %d itt 0x%x]\n", conn->id, mtask->itt);
162
163 error = iser_send_control(conn, mtask);
164
165 /* since iser xmits control with zero copy, mtasks can not be recycled
166 * right after sending them.
167 * The recycling scheme is based on whether a response is expected
168 * - if yes, the mtask is recycled at iscsi_complete_pdu
169 * - if no, the mtask is recycled at iser_snd_completion
170 */
Erez Zilberf0938402007-01-07 12:28:02 +0200171 if (error && error != -ENOBUFS)
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300172 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
173
174 return error;
175}
176
177static int
178iscsi_iser_ctask_xmit_unsol_data(struct iscsi_conn *conn,
179 struct iscsi_cmd_task *ctask)
180{
181 struct iscsi_data hdr;
182 int error = 0;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300183
184 /* Send data-out PDUs while there's still unsolicited data to send */
185 while (ctask->unsol_count > 0) {
Mike Christieffd04362006-08-31 18:09:24 -0400186 iscsi_prep_unsolicit_data_pdu(ctask, &hdr);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300187 debug_scsi("Sending data-out: itt 0x%x, data count %d\n",
188 hdr.itt, ctask->data_count);
189
190 /* the buffer description has been passed with the command */
191 /* Send the command */
192 error = iser_send_data_out(conn, ctask, &hdr);
193 if (error) {
194 ctask->unsol_datasn--;
195 goto iscsi_iser_ctask_xmit_unsol_data_exit;
196 }
197 ctask->unsol_count -= ctask->data_count;
198 debug_scsi("Need to send %d more as data-out PDUs\n",
199 ctask->unsol_count);
200 }
201
202iscsi_iser_ctask_xmit_unsol_data_exit:
203 return error;
204}
205
206static int
207iscsi_iser_ctask_xmit(struct iscsi_conn *conn,
208 struct iscsi_cmd_task *ctask)
209{
210 struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
211 int error = 0;
212
Mike Christie77a23c22007-05-30 12:57:18 -0500213 if (ctask->sc->sc_data_direction == DMA_TO_DEVICE) {
FUJITA Tomonorida9c0c72007-06-01 18:56:21 +0900214 BUG_ON(scsi_bufflen(ctask->sc) == 0);
Mike Christie77a23c22007-05-30 12:57:18 -0500215
216 debug_scsi("cmd [itt %x total %d imm %d unsol_data %d\n",
FUJITA Tomonorida9c0c72007-06-01 18:56:21 +0900217 ctask->itt, scsi_bufflen(ctask->sc),
Mike Christie77a23c22007-05-30 12:57:18 -0500218 ctask->imm_count, ctask->unsol_count);
219 }
220
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300221 debug_scsi("ctask deq [cid %d itt 0x%x]\n",
222 conn->id, ctask->itt);
223
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300224 /* Send the cmd PDU */
225 if (!iser_ctask->command_sent) {
226 error = iser_send_command(conn, ctask);
227 if (error)
228 goto iscsi_iser_ctask_xmit_exit;
229 iser_ctask->command_sent = 1;
230 }
231
232 /* Send unsolicited data-out PDU(s) if necessary */
233 if (ctask->unsol_count)
234 error = iscsi_iser_ctask_xmit_unsol_data(conn, ctask);
235
236 iscsi_iser_ctask_xmit_exit:
Erez Zilberf0938402007-01-07 12:28:02 +0200237 if (error && error != -ENOBUFS)
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300238 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
239 return error;
240}
241
242static void
243iscsi_iser_cleanup_ctask(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
244{
245 struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
246
247 if (iser_ctask->status == ISER_TASK_STATUS_STARTED) {
248 iser_ctask->status = ISER_TASK_STATUS_COMPLETED;
249 iser_ctask_rdma_finalize(iser_ctask);
250 }
251}
252
253static struct iser_conn *
254iscsi_iser_ib_conn_lookup(__u64 ep_handle)
255{
256 struct iser_conn *ib_conn;
257 struct iser_conn *uib_conn = (struct iser_conn *)(unsigned long)ep_handle;
258
259 mutex_lock(&ig.connlist_mutex);
260 list_for_each_entry(ib_conn, &ig.connlist, conn_list) {
261 if (ib_conn == uib_conn) {
262 mutex_unlock(&ig.connlist_mutex);
263 return ib_conn;
264 }
265 }
266 mutex_unlock(&ig.connlist_mutex);
267 iser_err("no conn exists for eph %llx\n",(unsigned long long)ep_handle);
268 return NULL;
269}
270
271static struct iscsi_cls_conn *
272iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
273{
274 struct iscsi_conn *conn;
275 struct iscsi_cls_conn *cls_conn;
276 struct iscsi_iser_conn *iser_conn;
277
278 cls_conn = iscsi_conn_setup(cls_session, conn_idx);
279 if (!cls_conn)
280 return NULL;
281 conn = cls_conn->dd_data;
282
283 /*
284 * due to issues with the login code re iser sematics
285 * this not set in iscsi_conn_setup - FIXME
286 */
287 conn->max_recv_dlength = 128;
288
289 iser_conn = kzalloc(sizeof(*iser_conn), GFP_KERNEL);
290 if (!iser_conn)
291 goto conn_alloc_fail;
292
293 /* currently this is the only field which need to be initiated */
294 rwlock_init(&iser_conn->lock);
295
296 conn->dd_data = iser_conn;
297 iser_conn->iscsi_conn = conn;
298
299 return cls_conn;
300
301conn_alloc_fail:
302 iscsi_conn_teardown(cls_conn);
303 return NULL;
304}
305
306static void
307iscsi_iser_conn_destroy(struct iscsi_cls_conn *cls_conn)
308{
309 struct iscsi_conn *conn = cls_conn->dd_data;
310 struct iscsi_iser_conn *iser_conn = conn->dd_data;
311
312 iscsi_conn_teardown(cls_conn);
Erez Zilber87e8df72006-09-27 15:27:10 +0300313 if (iser_conn->ib_conn)
314 iser_conn->ib_conn->iser_conn = NULL;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300315 kfree(iser_conn);
316}
317
318static int
319iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session,
320 struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
321 int is_leading)
322{
323 struct iscsi_conn *conn = cls_conn->dd_data;
324 struct iscsi_iser_conn *iser_conn;
325 struct iser_conn *ib_conn;
326 int error;
327
328 error = iscsi_conn_bind(cls_session, cls_conn, is_leading);
329 if (error)
330 return error;
331
332 /* the transport ep handle comes from user space so it must be
333 * verified against the global ib connections list */
334 ib_conn = iscsi_iser_ib_conn_lookup(transport_eph);
335 if (!ib_conn) {
336 iser_err("can't bind eph %llx\n",
337 (unsigned long long)transport_eph);
338 return -EINVAL;
339 }
340 /* binds the iSER connection retrieved from the previously
341 * connected ep_handle to the iSCSI layer connection. exchanges
342 * connection pointers */
343 iser_err("binding iscsi conn %p to iser_conn %p\n",conn,ib_conn);
344 iser_conn = conn->dd_data;
345 ib_conn->iser_conn = iser_conn;
346 iser_conn->ib_conn = ib_conn;
347
348 conn->recv_lock = &iser_conn->lock;
349
350 return 0;
351}
352
353static int
354iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn)
355{
356 struct iscsi_conn *conn = cls_conn->dd_data;
357 int err;
358
Erez Zilber2e7a7422006-10-22 10:28:38 +0200359 err = iser_conn_set_full_featured_mode(conn);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300360 if (err)
361 return err;
362
Erez Zilber2e7a7422006-10-22 10:28:38 +0200363 return iscsi_conn_start(cls_conn);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300364}
365
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300366static struct iscsi_transport iscsi_iser_transport;
367
368static struct iscsi_cls_session *
369iscsi_iser_session_create(struct iscsi_transport *iscsit,
370 struct scsi_transport_template *scsit,
Mike Christie15482712007-05-30 12:57:19 -0500371 uint16_t cmds_max, uint16_t qdepth,
372 uint32_t initial_cmdsn, uint32_t *hostno)
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300373{
374 struct iscsi_cls_session *cls_session;
375 struct iscsi_session *session;
376 int i;
377 uint32_t hn;
378 struct iscsi_cmd_task *ctask;
379 struct iscsi_mgmt_task *mtask;
380 struct iscsi_iser_cmd_task *iser_ctask;
381 struct iser_desc *desc;
382
Mike Christie15482712007-05-30 12:57:19 -0500383 /*
384 * we do not support setting can_queue cmd_per_lun from userspace yet
385 * because we preallocate so many resources
386 */
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300387 cls_session = iscsi_session_setup(iscsit, scsit,
Mike Christie15482712007-05-30 12:57:19 -0500388 ISCSI_DEF_XMIT_CMDS_MAX,
389 ISCSI_MAX_CMD_PER_LUN,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300390 sizeof(struct iscsi_iser_cmd_task),
391 sizeof(struct iser_desc),
392 initial_cmdsn, &hn);
393 if (!cls_session)
394 return NULL;
395
396 *hostno = hn;
397 session = class_to_transport_session(cls_session);
398
399 /* libiscsi setup itts, data and pool so just set desc fields */
400 for (i = 0; i < session->cmds_max; i++) {
401 ctask = session->cmds[i];
402 iser_ctask = ctask->dd_data;
403 ctask->hdr = (struct iscsi_cmd *)&iser_ctask->desc.iscsi_header;
Boaz Harrosh38ad03d2007-12-13 12:43:24 -0600404 ctask->hdr_max = sizeof(iser_ctask->desc.iscsi_header);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300405 }
406
407 for (i = 0; i < session->mgmtpool_max; i++) {
408 mtask = session->mgmt_cmds[i];
409 desc = mtask->dd_data;
410 mtask->hdr = &desc->iscsi_header;
411 desc->data = mtask->data;
412 }
413
414 return cls_session;
415}
416
417static int
Mike Christie358ff012006-06-28 12:00:25 -0500418iscsi_iser_set_param(struct iscsi_cls_conn *cls_conn,
419 enum iscsi_param param, char *buf, int buflen)
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300420{
Mike Christie358ff012006-06-28 12:00:25 -0500421 int value;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300422
423 switch (param) {
424 case ISCSI_PARAM_MAX_RECV_DLENGTH:
425 /* TBD */
426 break;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300427 case ISCSI_PARAM_HDRDGST_EN:
Mike Christie358ff012006-06-28 12:00:25 -0500428 sscanf(buf, "%d", &value);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300429 if (value) {
430 printk(KERN_ERR "DataDigest wasn't negotiated to None");
431 return -EPROTO;
432 }
433 break;
434 case ISCSI_PARAM_DATADGST_EN:
Mike Christie358ff012006-06-28 12:00:25 -0500435 sscanf(buf, "%d", &value);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300436 if (value) {
437 printk(KERN_ERR "DataDigest wasn't negotiated to None");
438 return -EPROTO;
439 }
440 break;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300441 case ISCSI_PARAM_IFMARKER_EN:
Mike Christie358ff012006-06-28 12:00:25 -0500442 sscanf(buf, "%d", &value);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300443 if (value) {
444 printk(KERN_ERR "IFMarker wasn't negotiated to No");
445 return -EPROTO;
446 }
447 break;
448 case ISCSI_PARAM_OFMARKER_EN:
Mike Christie358ff012006-06-28 12:00:25 -0500449 sscanf(buf, "%d", &value);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300450 if (value) {
451 printk(KERN_ERR "OFMarker wasn't negotiated to No");
452 return -EPROTO;
453 }
454 break;
455 default:
Mike Christie358ff012006-06-28 12:00:25 -0500456 return iscsi_set_param(cls_conn, param, buf, buflen);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300457 }
458
459 return 0;
460}
461
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300462static void
463iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
464{
465 struct iscsi_conn *conn = cls_conn->dd_data;
466
467 stats->txdata_octets = conn->txdata_octets;
468 stats->rxdata_octets = conn->rxdata_octets;
469 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
470 stats->dataout_pdus = conn->dataout_pdus_cnt;
471 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
472 stats->datain_pdus = conn->datain_pdus_cnt; /* always 0 */
473 stats->r2t_pdus = conn->r2t_pdus_cnt; /* always 0 */
474 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
475 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
476 stats->custom_length = 3;
477 strcpy(stats->custom[0].desc, "qp_tx_queue_full");
478 stats->custom[0].value = 0; /* TB iser_conn->qp_tx_queue_full; */
479 strcpy(stats->custom[1].desc, "fmr_map_not_avail");
480 stats->custom[1].value = 0; /* TB iser_conn->fmr_map_not_avail */;
481 strcpy(stats->custom[2].desc, "eh_abort_cnt");
482 stats->custom[2].value = conn->eh_abort_cnt;
483}
484
485static int
486iscsi_iser_ep_connect(struct sockaddr *dst_addr, int non_blocking,
487 __u64 *ep_handle)
488{
489 int err;
490 struct iser_conn *ib_conn;
491
492 err = iser_conn_init(&ib_conn);
493 if (err)
494 goto out;
495
496 err = iser_connect(ib_conn, NULL, (struct sockaddr_in *)dst_addr, non_blocking);
497 if (!err)
498 *ep_handle = (__u64)(unsigned long)ib_conn;
499
500out:
501 return err;
502}
503
504static int
505iscsi_iser_ep_poll(__u64 ep_handle, int timeout_ms)
506{
507 struct iser_conn *ib_conn = iscsi_iser_ib_conn_lookup(ep_handle);
508 int rc;
509
510 if (!ib_conn)
511 return -EINVAL;
512
513 rc = wait_event_interruptible_timeout(ib_conn->wait,
514 ib_conn->state == ISER_CONN_UP,
515 msecs_to_jiffies(timeout_ms));
516
517 /* if conn establishment failed, return error code to iscsi */
518 if (!rc &&
519 (ib_conn->state == ISER_CONN_TERMINATING ||
520 ib_conn->state == ISER_CONN_DOWN))
521 rc = -1;
522
523 iser_err("ib conn %p rc = %d\n", ib_conn, rc);
524
525 if (rc > 0)
526 return 1; /* success, this is the equivalent of POLLOUT */
527 else if (!rc)
528 return 0; /* timeout */
529 else
530 return rc; /* signal */
531}
532
533static void
534iscsi_iser_ep_disconnect(__u64 ep_handle)
535{
Mike Christie1c834692006-07-24 15:47:26 -0500536 struct iser_conn *ib_conn;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300537
Mike Christie1c834692006-07-24 15:47:26 -0500538 ib_conn = iscsi_iser_ib_conn_lookup(ep_handle);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300539 if (!ib_conn)
540 return;
541
542 iser_err("ib conn %p state %d\n",ib_conn, ib_conn->state);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300543 iser_conn_terminate(ib_conn);
544}
545
546static struct scsi_host_template iscsi_iser_sht = {
Mike Christie79743922007-07-26 12:46:46 -0500547 .module = THIS_MODULE,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300548 .name = "iSCSI Initiator over iSER, v." DRV_VER,
549 .queuecommand = iscsi_queuecommand,
Mike Christie15482712007-05-30 12:57:19 -0500550 .can_queue = ISCSI_DEF_XMIT_CMDS_MAX - 1,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300551 .sg_tablesize = ISCSI_ISER_SG_TABLESIZE,
Erez Zilber8072ec22006-09-11 12:20:54 +0300552 .max_sectors = 1024,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300553 .cmd_per_lun = ISCSI_MAX_CMD_PER_LUN,
554 .eh_abort_handler = iscsi_eh_abort,
Erez Zilber90c18f32008-01-22 12:06:25 +0200555 .eh_device_reset_handler= iscsi_eh_device_reset,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300556 .eh_host_reset_handler = iscsi_eh_host_reset,
557 .use_clustering = DISABLE_CLUSTERING,
558 .proc_name = "iscsi_iser",
559 .this_id = -1,
560};
561
562static struct iscsi_transport iscsi_iser_transport = {
563 .owner = THIS_MODULE,
564 .name = "iser",
565 .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T,
566 .param_mask = ISCSI_MAX_RECV_DLENGTH |
567 ISCSI_MAX_XMIT_DLENGTH |
568 ISCSI_HDRDGST_EN |
569 ISCSI_DATADGST_EN |
570 ISCSI_INITIAL_R2T_EN |
571 ISCSI_MAX_R2T |
572 ISCSI_IMM_DATA_EN |
573 ISCSI_FIRST_BURST |
574 ISCSI_MAX_BURST |
575 ISCSI_PDU_INORDER_EN |
Mike Christie358ff012006-06-28 12:00:25 -0500576 ISCSI_DATASEQ_INORDER_EN |
577 ISCSI_EXP_STATSN |
578 ISCSI_PERSISTENT_PORT |
579 ISCSI_PERSISTENT_ADDRESS |
Mike Christieb2c64162007-05-30 12:57:16 -0500580 ISCSI_TARGET_NAME | ISCSI_TPGT |
581 ISCSI_USERNAME | ISCSI_PASSWORD |
Mike Christief6d51802007-12-13 12:43:30 -0600582 ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
583 ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
584 ISCSI_PING_TMO | ISCSI_RECV_TMO,
Mike Christie8ad57812007-05-30 12:57:13 -0500585 .host_param_mask = ISCSI_HOST_HWADDRESS |
Mike Christied8196ed2007-05-30 12:57:25 -0500586 ISCSI_HOST_NETDEV_NAME |
Mike Christie8ad57812007-05-30 12:57:13 -0500587 ISCSI_HOST_INITIATOR_NAME,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300588 .host_template = &iscsi_iser_sht,
589 .conndata_size = sizeof(struct iscsi_conn),
590 .max_lun = ISCSI_ISER_MAX_LUN,
591 .max_cmd_len = ISCSI_ISER_MAX_CMD_LEN,
592 /* session management */
593 .create_session = iscsi_iser_session_create,
594 .destroy_session = iscsi_session_teardown,
595 /* connection management */
596 .create_conn = iscsi_iser_conn_create,
597 .bind_conn = iscsi_iser_conn_bind,
598 .destroy_conn = iscsi_iser_conn_destroy,
Mike Christie358ff012006-06-28 12:00:25 -0500599 .set_param = iscsi_iser_set_param,
600 .get_conn_param = iscsi_conn_get_param,
601 .get_session_param = iscsi_session_get_param,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300602 .start_conn = iscsi_iser_conn_start,
603 .stop_conn = iscsi_conn_stop,
Mike Christie0801c242007-05-30 12:57:12 -0500604 /* iscsi host params */
605 .get_host_param = iscsi_host_get_param,
606 .set_host_param = iscsi_host_set_param,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300607 /* IO */
608 .send_pdu = iscsi_conn_send_pdu,
609 .get_stats = iscsi_iser_conn_get_stats,
610 .init_cmd_task = iscsi_iser_cmd_init,
611 .xmit_cmd_task = iscsi_iser_ctask_xmit,
612 .xmit_mgmt_task = iscsi_iser_mtask_xmit,
613 .cleanup_cmd_task = iscsi_iser_cleanup_ctask,
614 /* recovery */
615 .session_recovery_timedout = iscsi_session_recovery_timedout,
616
617 .ep_connect = iscsi_iser_ep_connect,
618 .ep_poll = iscsi_iser_ep_poll,
619 .ep_disconnect = iscsi_iser_ep_disconnect
620};
621
622static int __init iser_init(void)
623{
624 int err;
625
626 iser_dbg("Starting iSER datamover...\n");
627
628 if (iscsi_max_lun < 1) {
629 printk(KERN_ERR "Invalid max_lun value of %u\n", iscsi_max_lun);
630 return -EINVAL;
631 }
632
633 iscsi_iser_transport.max_lun = iscsi_max_lun;
634
635 memset(&ig, 0, sizeof(struct iser_global));
636
637 ig.desc_cache = kmem_cache_create("iser_descriptors",
638 sizeof (struct iser_desc),
639 0, SLAB_HWCACHE_ALIGN,
Paul Mundt20c2df82007-07-20 10:11:58 +0900640 NULL);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300641 if (ig.desc_cache == NULL)
642 return -ENOMEM;
643
644 /* device init is called only after the first addr resolution */
645 mutex_init(&ig.device_list_mutex);
646 INIT_LIST_HEAD(&ig.device_list);
647 mutex_init(&ig.connlist_mutex);
648 INIT_LIST_HEAD(&ig.connlist);
649
650 if (!iscsi_register_transport(&iscsi_iser_transport)) {
651 iser_err("iscsi_register_transport failed\n");
652 err = -EINVAL;
653 goto register_transport_failure;
654 }
655
656 return 0;
657
658register_transport_failure:
659 kmem_cache_destroy(ig.desc_cache);
660
661 return err;
662}
663
664static void __exit iser_exit(void)
665{
666 iser_dbg("Removing iSER datamover...\n");
667 iscsi_unregister_transport(&iscsi_iser_transport);
668 kmem_cache_destroy(ig.desc_cache);
669}
670
671module_init(iser_init);
672module_exit(iser_exit);