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