Merge branches 'imx/pata' and 'imx/sata' into next/driver
[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 #include <linux/slab.h>
60
61 #include <net/sock.h>
62
63 #include <asm/uaccess.h>
64
65 #include <scsi/scsi_cmnd.h>
66 #include <scsi/scsi_device.h>
67 #include <scsi/scsi_eh.h>
68 #include <scsi/scsi_tcq.h>
69 #include <scsi/scsi_host.h>
70 #include <scsi/scsi.h>
71 #include <scsi/scsi_transport_iscsi.h>
72
73 #include "iscsi_iser.h"
74
75 static struct scsi_host_template iscsi_iser_sht;
76 static struct iscsi_transport iscsi_iser_transport;
77 static struct scsi_transport_template *iscsi_iser_scsi_transport;
78
79 static unsigned int iscsi_max_lun = 512;
80 module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
81
82 int iser_debug_level = 0;
83
84 MODULE_DESCRIPTION("iSER (iSCSI Extensions for RDMA) Datamover "
85                    "v" DRV_VER " (" DRV_DATE ")");
86 MODULE_LICENSE("Dual BSD/GPL");
87 MODULE_AUTHOR("Alex Nezhinsky, Dan Bar Dov, Or Gerlitz");
88
89 module_param_named(debug_level, iser_debug_level, int, 0644);
90 MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0 (default:disabled)");
91
92 struct iser_global ig;
93
94 void
95 iscsi_iser_recv(struct iscsi_conn *conn,
96                 struct iscsi_hdr *hdr, char *rx_data, int rx_data_len)
97 {
98         int rc = 0;
99         int datalen;
100         int ahslen;
101
102         /* verify PDU length */
103         datalen = ntoh24(hdr->dlength);
104         if (datalen > rx_data_len || (datalen + 4) < rx_data_len) {
105                 iser_err("wrong datalen %d (hdr), %d (IB)\n",
106                         datalen, rx_data_len);
107                 rc = ISCSI_ERR_DATALEN;
108                 goto error;
109         }
110
111         if (datalen != rx_data_len)
112                 iser_dbg("aligned datalen (%d) hdr, %d (IB)\n",
113                         datalen, rx_data_len);
114
115         /* read AHS */
116         ahslen = hdr->hlength * 4;
117
118         rc = iscsi_complete_pdu(conn, hdr, rx_data, rx_data_len);
119         if (rc && rc != ISCSI_ERR_NO_SCSI_CMD)
120                 goto error;
121
122         return;
123 error:
124         iscsi_conn_failure(conn, rc);
125 }
126
127 static int iscsi_iser_pdu_alloc(struct iscsi_task *task, uint8_t opcode)
128 {
129         struct iscsi_iser_task *iser_task = task->dd_data;
130
131         task->hdr = (struct iscsi_hdr *)&iser_task->desc.iscsi_header;
132         task->hdr_max = sizeof(iser_task->desc.iscsi_header);
133         return 0;
134 }
135
136 int iser_initialize_task_headers(struct iscsi_task *task,
137                                                 struct iser_tx_desc *tx_desc)
138 {
139         struct iscsi_iser_conn *iser_conn = task->conn->dd_data;
140         struct iser_device     *device    = iser_conn->ib_conn->device;
141         struct iscsi_iser_task *iser_task = task->dd_data;
142         u64 dma_addr;
143
144         dma_addr = ib_dma_map_single(device->ib_device, (void *)tx_desc,
145                                 ISER_HEADERS_LEN, DMA_TO_DEVICE);
146         if (ib_dma_mapping_error(device->ib_device, dma_addr))
147                 return -ENOMEM;
148
149         tx_desc->dma_addr = dma_addr;
150         tx_desc->tx_sg[0].addr   = tx_desc->dma_addr;
151         tx_desc->tx_sg[0].length = ISER_HEADERS_LEN;
152         tx_desc->tx_sg[0].lkey   = device->mr->lkey;
153
154         iser_task->headers_initialized  = 1;
155         iser_task->iser_conn            = iser_conn;
156         return 0;
157 }
158 /**
159  * iscsi_iser_task_init - Initialize task
160  * @task: iscsi task
161  *
162  * Initialize the task for the scsi command or mgmt command.
163  */
164 static int
165 iscsi_iser_task_init(struct iscsi_task *task)
166 {
167         struct iscsi_iser_task *iser_task = task->dd_data;
168
169         if (!iser_task->headers_initialized)
170                 if (iser_initialize_task_headers(task, &iser_task->desc))
171                         return -ENOMEM;
172
173         /* mgmt task */
174         if (!task->sc)
175                 return 0;
176
177         iser_task->command_sent = 0;
178         iser_task_rdma_init(iser_task);
179         return 0;
180 }
181
182 /**
183  * iscsi_iser_mtask_xmit - xmit management(immediate) task
184  * @conn: iscsi connection
185  * @task: task management task
186  *
187  * Notes:
188  *      The function can return -EAGAIN in which case caller must
189  *      call it again later, or recover. '0' return code means successful
190  *      xmit.
191  *
192  **/
193 static int
194 iscsi_iser_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
195 {
196         int error = 0;
197
198         iser_dbg("mtask xmit [cid %d itt 0x%x]\n", conn->id, task->itt);
199
200         error = iser_send_control(conn, task);
201
202         /* since iser xmits control with zero copy, tasks can not be recycled
203          * right after sending them.
204          * The recycling scheme is based on whether a response is expected
205          * - if yes, the task is recycled at iscsi_complete_pdu
206          * - if no,  the task is recycled at iser_snd_completion
207          */
208         return error;
209 }
210
211 static int
212 iscsi_iser_task_xmit_unsol_data(struct iscsi_conn *conn,
213                                  struct iscsi_task *task)
214 {
215         struct iscsi_r2t_info *r2t = &task->unsol_r2t;
216         struct iscsi_data hdr;
217         int error = 0;
218
219         /* Send data-out PDUs while there's still unsolicited data to send */
220         while (iscsi_task_has_unsol_data(task)) {
221                 iscsi_prep_data_out_pdu(task, r2t, &hdr);
222                 iser_dbg("Sending data-out: itt 0x%x, data count %d\n",
223                            hdr.itt, r2t->data_count);
224
225                 /* the buffer description has been passed with the command */
226                 /* Send the command */
227                 error = iser_send_data_out(conn, task, &hdr);
228                 if (error) {
229                         r2t->datasn--;
230                         goto iscsi_iser_task_xmit_unsol_data_exit;
231                 }
232                 r2t->sent += r2t->data_count;
233                 iser_dbg("Need to send %d more as data-out PDUs\n",
234                            r2t->data_length - r2t->sent);
235         }
236
237 iscsi_iser_task_xmit_unsol_data_exit:
238         return error;
239 }
240
241 static int
242 iscsi_iser_task_xmit(struct iscsi_task *task)
243 {
244         struct iscsi_conn *conn = task->conn;
245         struct iscsi_iser_task *iser_task = task->dd_data;
246         int error = 0;
247
248         if (!task->sc)
249                 return iscsi_iser_mtask_xmit(conn, task);
250
251         if (task->sc->sc_data_direction == DMA_TO_DEVICE) {
252                 BUG_ON(scsi_bufflen(task->sc) == 0);
253
254                 iser_dbg("cmd [itt %x total %d imm %d unsol_data %d\n",
255                            task->itt, scsi_bufflen(task->sc),
256                            task->imm_count, task->unsol_r2t.data_length);
257         }
258
259         iser_dbg("ctask xmit [cid %d itt 0x%x]\n",
260                    conn->id, task->itt);
261
262         /* Send the cmd PDU */
263         if (!iser_task->command_sent) {
264                 error = iser_send_command(conn, task);
265                 if (error)
266                         goto iscsi_iser_task_xmit_exit;
267                 iser_task->command_sent = 1;
268         }
269
270         /* Send unsolicited data-out PDU(s) if necessary */
271         if (iscsi_task_has_unsol_data(task))
272                 error = iscsi_iser_task_xmit_unsol_data(conn, task);
273
274  iscsi_iser_task_xmit_exit:
275         return error;
276 }
277
278 static void iscsi_iser_cleanup_task(struct iscsi_task *task)
279 {
280         struct iscsi_iser_task *iser_task = task->dd_data;
281
282         /* mgmt tasks do not need special cleanup */
283         if (!task->sc)
284                 return;
285
286         if (iser_task->status == ISER_TASK_STATUS_STARTED) {
287                 iser_task->status = ISER_TASK_STATUS_COMPLETED;
288                 iser_task_rdma_finalize(iser_task);
289         }
290 }
291
292 static struct iscsi_cls_conn *
293 iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
294 {
295         struct iscsi_conn *conn;
296         struct iscsi_cls_conn *cls_conn;
297         struct iscsi_iser_conn *iser_conn;
298
299         cls_conn = iscsi_conn_setup(cls_session, sizeof(*iser_conn), conn_idx);
300         if (!cls_conn)
301                 return NULL;
302         conn = cls_conn->dd_data;
303
304         /*
305          * due to issues with the login code re iser sematics
306          * this not set in iscsi_conn_setup - FIXME
307          */
308         conn->max_recv_dlength = ISER_RECV_DATA_SEG_LEN;
309
310         iser_conn = conn->dd_data;
311         conn->dd_data = iser_conn;
312         iser_conn->iscsi_conn = conn;
313
314         return cls_conn;
315 }
316
317 static void
318 iscsi_iser_conn_destroy(struct iscsi_cls_conn *cls_conn)
319 {
320         struct iscsi_conn *conn = cls_conn->dd_data;
321         struct iscsi_iser_conn *iser_conn = conn->dd_data;
322         struct iser_conn *ib_conn = iser_conn->ib_conn;
323
324         iscsi_conn_teardown(cls_conn);
325         /*
326          * Userspace will normally call the stop callback and
327          * already have freed the ib_conn, but if it goofed up then
328          * we free it here.
329          */
330         if (ib_conn) {
331                 ib_conn->iser_conn = NULL;
332                 iser_conn_put(ib_conn, 1); /* deref iscsi/ib conn unbinding */
333         }
334 }
335
336 static int
337 iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session,
338                      struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
339                      int is_leading)
340 {
341         struct iscsi_conn *conn = cls_conn->dd_data;
342         struct iscsi_iser_conn *iser_conn;
343         struct iser_conn *ib_conn;
344         struct iscsi_endpoint *ep;
345         int error;
346
347         error = iscsi_conn_bind(cls_session, cls_conn, is_leading);
348         if (error)
349                 return error;
350
351         /* the transport ep handle comes from user space so it must be
352          * verified against the global ib connections list */
353         ep = iscsi_lookup_endpoint(transport_eph);
354         if (!ep) {
355                 iser_err("can't bind eph %llx\n",
356                          (unsigned long long)transport_eph);
357                 return -EINVAL;
358         }
359         ib_conn = ep->dd_data;
360
361         /* binds the iSER connection retrieved from the previously
362          * connected ep_handle to the iSCSI layer connection. exchanges
363          * connection pointers */
364         iser_err("binding iscsi/iser conn %p %p to ib_conn %p\n",
365                                         conn, conn->dd_data, ib_conn);
366         iser_conn = conn->dd_data;
367         ib_conn->iser_conn = iser_conn;
368         iser_conn->ib_conn  = ib_conn;
369         iser_conn_get(ib_conn); /* ref iscsi/ib conn binding */
370         return 0;
371 }
372
373 static void
374 iscsi_iser_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
375 {
376         struct iscsi_conn *conn = cls_conn->dd_data;
377         struct iscsi_iser_conn *iser_conn = conn->dd_data;
378         struct iser_conn *ib_conn = iser_conn->ib_conn;
379
380         /*
381          * Userspace may have goofed up and not bound the connection or
382          * might have only partially setup the connection.
383          */
384         if (ib_conn) {
385                 iscsi_conn_stop(cls_conn, flag);
386                 /*
387                  * There is no unbind event so the stop callback
388                  * must release the ref from the bind.
389                  */
390                 iser_conn_put(ib_conn, 1); /* deref iscsi/ib conn unbinding */
391         }
392         iser_conn->ib_conn = NULL;
393 }
394
395 static int
396 iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn)
397 {
398         struct iscsi_conn *conn = cls_conn->dd_data;
399         int err;
400
401         err = iser_conn_set_full_featured_mode(conn);
402         if (err)
403                 return err;
404
405         return iscsi_conn_start(cls_conn);
406 }
407
408 static void iscsi_iser_session_destroy(struct iscsi_cls_session *cls_session)
409 {
410         struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
411
412         iscsi_session_teardown(cls_session);
413         iscsi_host_remove(shost);
414         iscsi_host_free(shost);
415 }
416
417 static struct iscsi_cls_session *
418 iscsi_iser_session_create(struct iscsi_endpoint *ep,
419                           uint16_t cmds_max, uint16_t qdepth,
420                           uint32_t initial_cmdsn)
421 {
422         struct iscsi_cls_session *cls_session;
423         struct iscsi_session *session;
424         struct Scsi_Host *shost;
425         struct iser_conn *ib_conn;
426
427         shost = iscsi_host_alloc(&iscsi_iser_sht, 0, 0);
428         if (!shost)
429                 return NULL;
430         shost->transportt = iscsi_iser_scsi_transport;
431         shost->max_lun = iscsi_max_lun;
432         shost->max_id = 0;
433         shost->max_channel = 0;
434         shost->max_cmd_len = 16;
435
436         /*
437          * older userspace tools (before 2.0-870) did not pass us
438          * the leading conn's ep so this will be NULL;
439          */
440         if (ep)
441                 ib_conn = ep->dd_data;
442
443         if (iscsi_host_add(shost,
444                            ep ? ib_conn->device->ib_device->dma_device : NULL))
445                 goto free_host;
446
447         /*
448          * we do not support setting can_queue cmd_per_lun from userspace yet
449          * because we preallocate so many resources
450          */
451         cls_session = iscsi_session_setup(&iscsi_iser_transport, shost,
452                                           ISCSI_DEF_XMIT_CMDS_MAX, 0,
453                                           sizeof(struct iscsi_iser_task),
454                                           initial_cmdsn, 0);
455         if (!cls_session)
456                 goto remove_host;
457         session = cls_session->dd_data;
458
459         shost->can_queue = session->scsi_cmds_max;
460         return cls_session;
461
462 remove_host:
463         iscsi_host_remove(shost);
464 free_host:
465         iscsi_host_free(shost);
466         return NULL;
467 }
468
469 static int
470 iscsi_iser_set_param(struct iscsi_cls_conn *cls_conn,
471                      enum iscsi_param param, char *buf, int buflen)
472 {
473         int value;
474
475         switch (param) {
476         case ISCSI_PARAM_MAX_RECV_DLENGTH:
477                 /* TBD */
478                 break;
479         case ISCSI_PARAM_HDRDGST_EN:
480                 sscanf(buf, "%d", &value);
481                 if (value) {
482                         printk(KERN_ERR "DataDigest wasn't negotiated to None");
483                         return -EPROTO;
484                 }
485                 break;
486         case ISCSI_PARAM_DATADGST_EN:
487                 sscanf(buf, "%d", &value);
488                 if (value) {
489                         printk(KERN_ERR "DataDigest wasn't negotiated to None");
490                         return -EPROTO;
491                 }
492                 break;
493         case ISCSI_PARAM_IFMARKER_EN:
494                 sscanf(buf, "%d", &value);
495                 if (value) {
496                         printk(KERN_ERR "IFMarker wasn't negotiated to No");
497                         return -EPROTO;
498                 }
499                 break;
500         case ISCSI_PARAM_OFMARKER_EN:
501                 sscanf(buf, "%d", &value);
502                 if (value) {
503                         printk(KERN_ERR "OFMarker wasn't negotiated to No");
504                         return -EPROTO;
505                 }
506                 break;
507         default:
508                 return iscsi_set_param(cls_conn, param, buf, buflen);
509         }
510
511         return 0;
512 }
513
514 static void
515 iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
516 {
517         struct iscsi_conn *conn = cls_conn->dd_data;
518
519         stats->txdata_octets = conn->txdata_octets;
520         stats->rxdata_octets = conn->rxdata_octets;
521         stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
522         stats->dataout_pdus = conn->dataout_pdus_cnt;
523         stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
524         stats->datain_pdus = conn->datain_pdus_cnt; /* always 0 */
525         stats->r2t_pdus = conn->r2t_pdus_cnt; /* always 0 */
526         stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
527         stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
528         stats->custom_length = 4;
529         strcpy(stats->custom[0].desc, "qp_tx_queue_full");
530         stats->custom[0].value = 0; /* TB iser_conn->qp_tx_queue_full; */
531         strcpy(stats->custom[1].desc, "fmr_map_not_avail");
532         stats->custom[1].value = 0; /* TB iser_conn->fmr_map_not_avail */;
533         strcpy(stats->custom[2].desc, "eh_abort_cnt");
534         stats->custom[2].value = conn->eh_abort_cnt;
535         strcpy(stats->custom[3].desc, "fmr_unalign_cnt");
536         stats->custom[3].value = conn->fmr_unalign_cnt;
537 }
538
539 static int iscsi_iser_get_ep_param(struct iscsi_endpoint *ep,
540                                    enum iscsi_param param, char *buf)
541 {
542         struct iser_conn *ib_conn = ep->dd_data;
543         int len;
544
545         switch (param) {
546         case ISCSI_PARAM_CONN_PORT:
547         case ISCSI_PARAM_CONN_ADDRESS:
548                 if (!ib_conn || !ib_conn->cma_id)
549                         return -ENOTCONN;
550
551                 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
552                                         &ib_conn->cma_id->route.addr.dst_addr,
553                                         param, buf);
554                 break;
555         default:
556                 return -ENOSYS;
557         }
558
559         return len;
560 }
561
562 static struct iscsi_endpoint *
563 iscsi_iser_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
564                       int non_blocking)
565 {
566         int err;
567         struct iser_conn *ib_conn;
568         struct iscsi_endpoint *ep;
569
570         ep = iscsi_create_endpoint(sizeof(*ib_conn));
571         if (!ep)
572                 return ERR_PTR(-ENOMEM);
573
574         ib_conn = ep->dd_data;
575         ib_conn->ep = ep;
576         iser_conn_init(ib_conn);
577
578         err = iser_connect(ib_conn, NULL, (struct sockaddr_in *)dst_addr,
579                            non_blocking);
580         if (err) {
581                 iscsi_destroy_endpoint(ep);
582                 return ERR_PTR(err);
583         }
584         return ep;
585 }
586
587 static int
588 iscsi_iser_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
589 {
590         struct iser_conn *ib_conn;
591         int rc;
592
593         ib_conn = ep->dd_data;
594         rc = wait_event_interruptible_timeout(ib_conn->wait,
595                              ib_conn->state == ISER_CONN_UP,
596                              msecs_to_jiffies(timeout_ms));
597
598         /* if conn establishment failed, return error code to iscsi */
599         if (!rc &&
600             (ib_conn->state == ISER_CONN_TERMINATING ||
601              ib_conn->state == ISER_CONN_DOWN))
602                 rc = -1;
603
604         iser_err("ib conn %p rc = %d\n", ib_conn, rc);
605
606         if (rc > 0)
607                 return 1; /* success, this is the equivalent of POLLOUT */
608         else if (!rc)
609                 return 0; /* timeout */
610         else
611                 return rc; /* signal */
612 }
613
614 static void
615 iscsi_iser_ep_disconnect(struct iscsi_endpoint *ep)
616 {
617         struct iser_conn *ib_conn;
618
619         ib_conn = ep->dd_data;
620         if (ib_conn->iser_conn)
621                 /*
622                  * Must suspend xmit path if the ep is bound to the
623                  * iscsi_conn, so we know we are not accessing the ib_conn
624                  * when we free it.
625                  *
626                  * This may not be bound if the ep poll failed.
627                  */
628                 iscsi_suspend_tx(ib_conn->iser_conn->iscsi_conn);
629
630
631         iser_err("ib conn %p state %d\n",ib_conn, ib_conn->state);
632         iser_conn_terminate(ib_conn);
633 }
634
635 static struct scsi_host_template iscsi_iser_sht = {
636         .module                 = THIS_MODULE,
637         .name                   = "iSCSI Initiator over iSER, v." DRV_VER,
638         .queuecommand           = iscsi_queuecommand,
639         .change_queue_depth     = iscsi_change_queue_depth,
640         .sg_tablesize           = ISCSI_ISER_SG_TABLESIZE,
641         .max_sectors            = 1024,
642         .cmd_per_lun            = ISER_DEF_CMD_PER_LUN,
643         .eh_abort_handler       = iscsi_eh_abort,
644         .eh_device_reset_handler= iscsi_eh_device_reset,
645         .eh_target_reset_handler = iscsi_eh_recover_target,
646         .target_alloc           = iscsi_target_alloc,
647         .use_clustering         = DISABLE_CLUSTERING,
648         .proc_name              = "iscsi_iser",
649         .this_id                = -1,
650 };
651
652 static struct iscsi_transport iscsi_iser_transport = {
653         .owner                  = THIS_MODULE,
654         .name                   = "iser",
655         .caps                   = CAP_RECOVERY_L0 | CAP_MULTI_R2T,
656         .param_mask             = ISCSI_MAX_RECV_DLENGTH |
657                                   ISCSI_MAX_XMIT_DLENGTH |
658                                   ISCSI_HDRDGST_EN |
659                                   ISCSI_DATADGST_EN |
660                                   ISCSI_INITIAL_R2T_EN |
661                                   ISCSI_MAX_R2T |
662                                   ISCSI_IMM_DATA_EN |
663                                   ISCSI_FIRST_BURST |
664                                   ISCSI_MAX_BURST |
665                                   ISCSI_PDU_INORDER_EN |
666                                   ISCSI_DATASEQ_INORDER_EN |
667                                   ISCSI_CONN_PORT |
668                                   ISCSI_CONN_ADDRESS |
669                                   ISCSI_EXP_STATSN |
670                                   ISCSI_PERSISTENT_PORT |
671                                   ISCSI_PERSISTENT_ADDRESS |
672                                   ISCSI_TARGET_NAME | ISCSI_TPGT |
673                                   ISCSI_USERNAME | ISCSI_PASSWORD |
674                                   ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
675                                   ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
676                                   ISCSI_LU_RESET_TMO | ISCSI_TGT_RESET_TMO |
677                                   ISCSI_PING_TMO | ISCSI_RECV_TMO |
678                                   ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
679         .host_param_mask        = ISCSI_HOST_HWADDRESS |
680                                   ISCSI_HOST_NETDEV_NAME |
681                                   ISCSI_HOST_INITIATOR_NAME,
682         /* session management */
683         .create_session         = iscsi_iser_session_create,
684         .destroy_session        = iscsi_iser_session_destroy,
685         /* connection management */
686         .create_conn            = iscsi_iser_conn_create,
687         .bind_conn              = iscsi_iser_conn_bind,
688         .destroy_conn           = iscsi_iser_conn_destroy,
689         .set_param              = iscsi_iser_set_param,
690         .get_conn_param         = iscsi_conn_get_param,
691         .get_ep_param           = iscsi_iser_get_ep_param,
692         .get_session_param      = iscsi_session_get_param,
693         .start_conn             = iscsi_iser_conn_start,
694         .stop_conn              = iscsi_iser_conn_stop,
695         /* iscsi host params */
696         .get_host_param         = iscsi_host_get_param,
697         .set_host_param         = iscsi_host_set_param,
698         /* IO */
699         .send_pdu               = iscsi_conn_send_pdu,
700         .get_stats              = iscsi_iser_conn_get_stats,
701         .init_task              = iscsi_iser_task_init,
702         .xmit_task              = iscsi_iser_task_xmit,
703         .cleanup_task           = iscsi_iser_cleanup_task,
704         .alloc_pdu              = iscsi_iser_pdu_alloc,
705         /* recovery */
706         .session_recovery_timedout = iscsi_session_recovery_timedout,
707
708         .ep_connect             = iscsi_iser_ep_connect,
709         .ep_poll                = iscsi_iser_ep_poll,
710         .ep_disconnect          = iscsi_iser_ep_disconnect
711 };
712
713 static int __init iser_init(void)
714 {
715         int err;
716
717         iser_dbg("Starting iSER datamover...\n");
718
719         if (iscsi_max_lun < 1) {
720                 printk(KERN_ERR "Invalid max_lun value of %u\n", iscsi_max_lun);
721                 return -EINVAL;
722         }
723
724         memset(&ig, 0, sizeof(struct iser_global));
725
726         ig.desc_cache = kmem_cache_create("iser_descriptors",
727                                           sizeof(struct iser_tx_desc),
728                                           0, SLAB_HWCACHE_ALIGN,
729                                           NULL);
730         if (ig.desc_cache == NULL)
731                 return -ENOMEM;
732
733         /* device init is called only after the first addr resolution */
734         mutex_init(&ig.device_list_mutex);
735         INIT_LIST_HEAD(&ig.device_list);
736         mutex_init(&ig.connlist_mutex);
737         INIT_LIST_HEAD(&ig.connlist);
738
739         iscsi_iser_scsi_transport = iscsi_register_transport(
740                                                         &iscsi_iser_transport);
741         if (!iscsi_iser_scsi_transport) {
742                 iser_err("iscsi_register_transport failed\n");
743                 err = -EINVAL;
744                 goto register_transport_failure;
745         }
746
747         return 0;
748
749 register_transport_failure:
750         kmem_cache_destroy(ig.desc_cache);
751
752         return err;
753 }
754
755 static void __exit iser_exit(void)
756 {
757         iser_dbg("Removing iSER datamover...\n");
758         iscsi_unregister_transport(&iscsi_iser_transport);
759         kmem_cache_destroy(ig.desc_cache);
760 }
761
762 module_init(iser_init);
763 module_exit(iser_exit);