Merge branch 'bkl-removal' into next
[pandora-kernel.git] / drivers / infiniband / ulp / iser / iscsi_iser.c
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 #include <linux/types.h>
48 #include <linux/list.h>
49 #include <linux/hardirq.h>
50 #include <linux/kfifo.h>
51 #include <linux/blkdev.h>
52 #include <linux/init.h>
53 #include <linux/ioctl.h>
54 #include <linux/cdev.h>
55 #include <linux/in.h>
56 #include <linux/net.h>
57 #include <linux/scatterlist.h>
58 #include <linux/delay.h>
59
60 #include <net/sock.h>
61
62 #include <asm/uaccess.h>
63
64 #include <scsi/scsi_cmnd.h>
65 #include <scsi/scsi_device.h>
66 #include <scsi/scsi_eh.h>
67 #include <scsi/scsi_tcq.h>
68 #include <scsi/scsi_host.h>
69 #include <scsi/scsi.h>
70 #include <scsi/scsi_transport_iscsi.h>
71
72 #include "iscsi_iser.h"
73
74 static unsigned int iscsi_max_lun = 512;
75 module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
76
77 int iser_debug_level = 0;
78
79 MODULE_DESCRIPTION("iSER (iSCSI Extensions for RDMA) Datamover "
80                    "v" DRV_VER " (" DRV_DATE ")");
81 MODULE_LICENSE("Dual BSD/GPL");
82 MODULE_AUTHOR("Alex Nezhinsky, Dan Bar Dov, Or Gerlitz");
83
84 module_param_named(debug_level, iser_debug_level, int, 0644);
85 MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0 (default:disabled)");
86
87 struct iser_global ig;
88
89 void
90 iscsi_iser_recv(struct iscsi_conn *conn,
91                 struct iscsi_hdr *hdr, char *rx_data, int rx_data_len)
92 {
93         int rc = 0;
94         uint32_t ret_itt;
95         int datalen;
96         int ahslen;
97
98         /* verify PDU length */
99         datalen = ntoh24(hdr->dlength);
100         if (datalen != rx_data_len) {
101                 printk(KERN_ERR "iscsi_iser: datalen %d (hdr) != %d (IB) \n",
102                        datalen, rx_data_len);
103                 rc = ISCSI_ERR_DATALEN;
104                 goto error;
105         }
106
107         /* read AHS */
108         ahslen = hdr->hlength * 4;
109
110         /* verify itt (itt encoding: age+cid+itt) */
111         rc = iscsi_verify_itt(conn, hdr, &ret_itt);
112
113         if (!rc)
114                 rc = iscsi_complete_pdu(conn, hdr, rx_data, rx_data_len);
115
116         if (rc && rc != ISCSI_ERR_NO_SCSI_CMD)
117                 goto error;
118
119         return;
120 error:
121         iscsi_conn_failure(conn, rc);
122 }
123
124
125 /**
126  * iscsi_iser_cmd_init - Initialize iSCSI SCSI_READ or SCSI_WRITE commands
127  *
128  **/
129 static int
130 iscsi_iser_cmd_init(struct iscsi_cmd_task *ctask)
131 {
132         struct iscsi_iser_conn     *iser_conn  = ctask->conn->dd_data;
133         struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
134
135         iser_ctask->command_sent = 0;
136         iser_ctask->iser_conn    = iser_conn;
137         iser_ctask_rdma_init(iser_ctask);
138         return 0;
139 }
140
141 /**
142  * iscsi_mtask_xmit - xmit management(immediate) task
143  * @conn: iscsi connection
144  * @mtask: task management task
145  *
146  * Notes:
147  *      The function can return -EAGAIN in which case caller must
148  *      call it again later, or recover. '0' return code means successful
149  *      xmit.
150  *
151  **/
152 static int
153 iscsi_iser_mtask_xmit(struct iscsi_conn *conn,
154                       struct iscsi_mgmt_task *mtask)
155 {
156         int error = 0;
157
158         debug_scsi("mtask deq [cid %d itt 0x%x]\n", conn->id, mtask->itt);
159
160         error = iser_send_control(conn, mtask);
161
162         /* since iser xmits control with zero copy, mtasks can not be recycled
163          * right after sending them.
164          * The recycling scheme is based on whether a response is expected
165          * - if yes, the mtask is recycled at iscsi_complete_pdu
166          * - if no,  the mtask is recycled at iser_snd_completion
167          */
168         if (error && error != -ENOBUFS)
169                 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
170
171         return error;
172 }
173
174 static int
175 iscsi_iser_ctask_xmit_unsol_data(struct iscsi_conn *conn,
176                                  struct iscsi_cmd_task *ctask)
177 {
178         struct iscsi_data  hdr;
179         int error = 0;
180
181         /* Send data-out PDUs while there's still unsolicited data to send */
182         while (ctask->unsol_count > 0) {
183                 iscsi_prep_unsolicit_data_pdu(ctask, &hdr);
184                 debug_scsi("Sending data-out: itt 0x%x, data count %d\n",
185                            hdr.itt, ctask->data_count);
186
187                 /* the buffer description has been passed with the command */
188                 /* Send the command */
189                 error = iser_send_data_out(conn, ctask, &hdr);
190                 if (error) {
191                         ctask->unsol_datasn--;
192                         goto iscsi_iser_ctask_xmit_unsol_data_exit;
193                 }
194                 ctask->unsol_count -= ctask->data_count;
195                 debug_scsi("Need to send %d more as data-out PDUs\n",
196                            ctask->unsol_count);
197         }
198
199 iscsi_iser_ctask_xmit_unsol_data_exit:
200         return error;
201 }
202
203 static int
204 iscsi_iser_ctask_xmit(struct iscsi_conn *conn,
205                       struct iscsi_cmd_task *ctask)
206 {
207         struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
208         int error = 0;
209
210         if (ctask->sc->sc_data_direction == DMA_TO_DEVICE) {
211                 BUG_ON(scsi_bufflen(ctask->sc) == 0);
212
213                 debug_scsi("cmd [itt %x total %d imm %d unsol_data %d\n",
214                            ctask->itt, scsi_bufflen(ctask->sc),
215                            ctask->imm_count, ctask->unsol_count);
216         }
217
218         debug_scsi("ctask deq [cid %d itt 0x%x]\n",
219                    conn->id, ctask->itt);
220
221         /* Send the cmd PDU */
222         if (!iser_ctask->command_sent) {
223                 error = iser_send_command(conn, ctask);
224                 if (error)
225                         goto iscsi_iser_ctask_xmit_exit;
226                 iser_ctask->command_sent = 1;
227         }
228
229         /* Send unsolicited data-out PDU(s) if necessary */
230         if (ctask->unsol_count)
231                 error = iscsi_iser_ctask_xmit_unsol_data(conn, ctask);
232
233  iscsi_iser_ctask_xmit_exit:
234         if (error && error != -ENOBUFS)
235                 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
236         return error;
237 }
238
239 static void
240 iscsi_iser_cleanup_ctask(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
241 {
242         struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
243
244         if (iser_ctask->status == ISER_TASK_STATUS_STARTED) {
245                 iser_ctask->status = ISER_TASK_STATUS_COMPLETED;
246                 iser_ctask_rdma_finalize(iser_ctask);
247         }
248 }
249
250 static struct iser_conn *
251 iscsi_iser_ib_conn_lookup(__u64 ep_handle)
252 {
253         struct iser_conn *ib_conn;
254         struct iser_conn *uib_conn = (struct iser_conn *)(unsigned long)ep_handle;
255
256         mutex_lock(&ig.connlist_mutex);
257         list_for_each_entry(ib_conn, &ig.connlist, conn_list) {
258                 if (ib_conn == uib_conn) {
259                         mutex_unlock(&ig.connlist_mutex);
260                         return ib_conn;
261                 }
262         }
263         mutex_unlock(&ig.connlist_mutex);
264         iser_err("no conn exists for eph %llx\n",(unsigned long long)ep_handle);
265         return NULL;
266 }
267
268 static struct iscsi_cls_conn *
269 iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
270 {
271         struct iscsi_conn *conn;
272         struct iscsi_cls_conn *cls_conn;
273         struct iscsi_iser_conn *iser_conn;
274
275         cls_conn = iscsi_conn_setup(cls_session, conn_idx);
276         if (!cls_conn)
277                 return NULL;
278         conn = cls_conn->dd_data;
279
280         /*
281          * due to issues with the login code re iser sematics
282          * this not set in iscsi_conn_setup - FIXME
283          */
284         conn->max_recv_dlength = 128;
285
286         iser_conn = kzalloc(sizeof(*iser_conn), GFP_KERNEL);
287         if (!iser_conn)
288                 goto conn_alloc_fail;
289
290         /* currently this is the only field which need to be initiated */
291         rwlock_init(&iser_conn->lock);
292
293         conn->dd_data = iser_conn;
294         iser_conn->iscsi_conn = conn;
295
296         return cls_conn;
297
298 conn_alloc_fail:
299         iscsi_conn_teardown(cls_conn);
300         return NULL;
301 }
302
303 static void
304 iscsi_iser_conn_destroy(struct iscsi_cls_conn *cls_conn)
305 {
306         struct iscsi_conn *conn = cls_conn->dd_data;
307         struct iscsi_iser_conn *iser_conn = conn->dd_data;
308
309         iscsi_conn_teardown(cls_conn);
310         if (iser_conn->ib_conn)
311                 iser_conn->ib_conn->iser_conn = NULL;
312         kfree(iser_conn);
313 }
314
315 static int
316 iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session,
317                      struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
318                      int is_leading)
319 {
320         struct iscsi_conn *conn = cls_conn->dd_data;
321         struct iscsi_iser_conn *iser_conn;
322         struct iser_conn *ib_conn;
323         int error;
324
325         error = iscsi_conn_bind(cls_session, cls_conn, is_leading);
326         if (error)
327                 return error;
328
329         /* the transport ep handle comes from user space so it must be
330          * verified against the global ib connections list */
331         ib_conn = iscsi_iser_ib_conn_lookup(transport_eph);
332         if (!ib_conn) {
333                 iser_err("can't bind eph %llx\n",
334                          (unsigned long long)transport_eph);
335                 return -EINVAL;
336         }
337         /* binds the iSER connection retrieved from the previously
338          * connected ep_handle to the iSCSI layer connection. exchanges
339          * connection pointers */
340         iser_err("binding iscsi conn %p to iser_conn %p\n",conn,ib_conn);
341         iser_conn = conn->dd_data;
342         ib_conn->iser_conn = iser_conn;
343         iser_conn->ib_conn  = ib_conn;
344
345         conn->recv_lock = &iser_conn->lock;
346
347         return 0;
348 }
349
350 static int
351 iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn)
352 {
353         struct iscsi_conn *conn = cls_conn->dd_data;
354         int err;
355
356         err = iser_conn_set_full_featured_mode(conn);
357         if (err)
358                 return err;
359
360         return iscsi_conn_start(cls_conn);
361 }
362
363 static struct iscsi_transport iscsi_iser_transport;
364
365 static struct iscsi_cls_session *
366 iscsi_iser_session_create(struct iscsi_transport *iscsit,
367                          struct scsi_transport_template *scsit,
368                          uint16_t cmds_max, uint16_t qdepth,
369                          uint32_t initial_cmdsn, uint32_t *hostno)
370 {
371         struct iscsi_cls_session *cls_session;
372         struct iscsi_session *session;
373         int i;
374         uint32_t hn;
375         struct iscsi_cmd_task  *ctask;
376         struct iscsi_mgmt_task *mtask;
377         struct iscsi_iser_cmd_task *iser_ctask;
378         struct iser_desc *desc;
379
380         /*
381          * we do not support setting can_queue cmd_per_lun from userspace yet
382          * because we preallocate so many resources
383          */
384         cls_session = iscsi_session_setup(iscsit, scsit,
385                                           ISCSI_DEF_XMIT_CMDS_MAX,
386                                           ISCSI_MAX_CMD_PER_LUN,
387                                           sizeof(struct iscsi_iser_cmd_task),
388                                           sizeof(struct iser_desc),
389                                           initial_cmdsn, &hn);
390         if (!cls_session)
391         return NULL;
392
393         *hostno = hn;
394         session = class_to_transport_session(cls_session);
395
396         /* libiscsi setup itts, data and pool so just set desc fields */
397         for (i = 0; i < session->cmds_max; i++) {
398                 ctask      = session->cmds[i];
399                 iser_ctask = ctask->dd_data;
400                 ctask->hdr = (struct iscsi_cmd *)&iser_ctask->desc.iscsi_header;
401                 ctask->hdr_max = sizeof(iser_ctask->desc.iscsi_header);
402         }
403
404         for (i = 0; i < session->mgmtpool_max; i++) {
405                 mtask      = session->mgmt_cmds[i];
406                 desc       = mtask->dd_data;
407                 mtask->hdr = &desc->iscsi_header;
408                 desc->data = mtask->data;
409         }
410
411         return cls_session;
412 }
413
414 static int
415 iscsi_iser_set_param(struct iscsi_cls_conn *cls_conn,
416                      enum iscsi_param param, char *buf, int buflen)
417 {
418         int value;
419
420         switch (param) {
421         case ISCSI_PARAM_MAX_RECV_DLENGTH:
422                 /* TBD */
423                 break;
424         case ISCSI_PARAM_HDRDGST_EN:
425                 sscanf(buf, "%d", &value);
426                 if (value) {
427                         printk(KERN_ERR "DataDigest wasn't negotiated to None");
428                         return -EPROTO;
429                 }
430                 break;
431         case ISCSI_PARAM_DATADGST_EN:
432                 sscanf(buf, "%d", &value);
433                 if (value) {
434                         printk(KERN_ERR "DataDigest wasn't negotiated to None");
435                         return -EPROTO;
436                 }
437                 break;
438         case ISCSI_PARAM_IFMARKER_EN:
439                 sscanf(buf, "%d", &value);
440                 if (value) {
441                         printk(KERN_ERR "IFMarker wasn't negotiated to No");
442                         return -EPROTO;
443                 }
444                 break;
445         case ISCSI_PARAM_OFMARKER_EN:
446                 sscanf(buf, "%d", &value);
447                 if (value) {
448                         printk(KERN_ERR "OFMarker wasn't negotiated to No");
449                         return -EPROTO;
450                 }
451                 break;
452         default:
453                 return iscsi_set_param(cls_conn, param, buf, buflen);
454         }
455
456         return 0;
457 }
458
459 static void
460 iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
461 {
462         struct iscsi_conn *conn = cls_conn->dd_data;
463
464         stats->txdata_octets = conn->txdata_octets;
465         stats->rxdata_octets = conn->rxdata_octets;
466         stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
467         stats->dataout_pdus = conn->dataout_pdus_cnt;
468         stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
469         stats->datain_pdus = conn->datain_pdus_cnt; /* always 0 */
470         stats->r2t_pdus = conn->r2t_pdus_cnt; /* always 0 */
471         stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
472         stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
473         stats->custom_length = 4;
474         strcpy(stats->custom[0].desc, "qp_tx_queue_full");
475         stats->custom[0].value = 0; /* TB iser_conn->qp_tx_queue_full; */
476         strcpy(stats->custom[1].desc, "fmr_map_not_avail");
477         stats->custom[1].value = 0; /* TB iser_conn->fmr_map_not_avail */;
478         strcpy(stats->custom[2].desc, "eh_abort_cnt");
479         stats->custom[2].value = conn->eh_abort_cnt;
480         strcpy(stats->custom[3].desc, "fmr_unalign_cnt");
481         stats->custom[3].value = conn->fmr_unalign_cnt;
482 }
483
484 static int
485 iscsi_iser_ep_connect(struct sockaddr *dst_addr, int non_blocking,
486                       __u64 *ep_handle)
487 {
488         int err;
489         struct iser_conn *ib_conn;
490
491         err = iser_conn_init(&ib_conn);
492         if (err)
493                 goto out;
494
495         err = iser_connect(ib_conn, NULL, (struct sockaddr_in *)dst_addr, non_blocking);
496         if (!err)
497                 *ep_handle = (__u64)(unsigned long)ib_conn;
498
499 out:
500         return err;
501 }
502
503 static int
504 iscsi_iser_ep_poll(__u64 ep_handle, int timeout_ms)
505 {
506         struct iser_conn *ib_conn = iscsi_iser_ib_conn_lookup(ep_handle);
507         int rc;
508
509         if (!ib_conn)
510                 return -EINVAL;
511
512         rc = wait_event_interruptible_timeout(ib_conn->wait,
513                              ib_conn->state == ISER_CONN_UP,
514                              msecs_to_jiffies(timeout_ms));
515
516         /* if conn establishment failed, return error code to iscsi */
517         if (!rc &&
518             (ib_conn->state == ISER_CONN_TERMINATING ||
519              ib_conn->state == ISER_CONN_DOWN))
520                 rc = -1;
521
522         iser_err("ib conn %p rc = %d\n", ib_conn, rc);
523
524         if (rc > 0)
525                 return 1; /* success, this is the equivalent of POLLOUT */
526         else if (!rc)
527                 return 0; /* timeout */
528         else
529                 return rc; /* signal */
530 }
531
532 static void
533 iscsi_iser_ep_disconnect(__u64 ep_handle)
534 {
535         struct iser_conn *ib_conn;
536
537         ib_conn = iscsi_iser_ib_conn_lookup(ep_handle);
538         if (!ib_conn)
539                 return;
540
541         iser_err("ib conn %p state %d\n",ib_conn, ib_conn->state);
542         iser_conn_terminate(ib_conn);
543 }
544
545 static struct scsi_host_template iscsi_iser_sht = {
546         .module                 = THIS_MODULE,
547         .name                   = "iSCSI Initiator over iSER, v." DRV_VER,
548         .queuecommand           = iscsi_queuecommand,
549         .change_queue_depth     = iscsi_change_queue_depth,
550         .can_queue              = ISCSI_DEF_XMIT_CMDS_MAX - 1,
551         .sg_tablesize           = ISCSI_ISER_SG_TABLESIZE,
552         .max_sectors            = 1024,
553         .cmd_per_lun            = ISCSI_MAX_CMD_PER_LUN,
554         .eh_abort_handler       = iscsi_eh_abort,
555         .eh_device_reset_handler= iscsi_eh_device_reset,
556         .eh_host_reset_handler  = iscsi_eh_host_reset,
557         .use_clustering         = DISABLE_CLUSTERING,
558         .proc_name              = "iscsi_iser",
559         .this_id                = -1,
560 };
561
562 static 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 |
576                                   ISCSI_DATASEQ_INORDER_EN |
577                                   ISCSI_EXP_STATSN |
578                                   ISCSI_PERSISTENT_PORT |
579                                   ISCSI_PERSISTENT_ADDRESS |
580                                   ISCSI_TARGET_NAME | ISCSI_TPGT |
581                                   ISCSI_USERNAME | ISCSI_PASSWORD |
582                                   ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
583                                   ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
584                                   ISCSI_PING_TMO | ISCSI_RECV_TMO,
585         .host_param_mask        = ISCSI_HOST_HWADDRESS |
586                                   ISCSI_HOST_NETDEV_NAME |
587                                   ISCSI_HOST_INITIATOR_NAME,
588         .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,
599         .set_param              = iscsi_iser_set_param,
600         .get_conn_param         = iscsi_conn_get_param,
601         .get_session_param      = iscsi_session_get_param,
602         .start_conn             = iscsi_iser_conn_start,
603         .stop_conn              = iscsi_conn_stop,
604         /* iscsi host params */
605         .get_host_param         = iscsi_host_get_param,
606         .set_host_param         = iscsi_host_set_param,
607         /* 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
622 static 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,
640                                           NULL);
641         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
658 register_transport_failure:
659         kmem_cache_destroy(ig.desc_cache);
660
661         return err;
662 }
663
664 static 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
671 module_init(iser_init);
672 module_exit(iser_exit);