blob: 8a1bfb7277c8a8d5f4141d57c812c1bfa8621edf [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
Mike Christie75613522008-05-21 15:53:59 -050077static struct scsi_host_template iscsi_iser_sht;
78static struct iscsi_transport iscsi_iser_transport;
79static struct scsi_transport_template *iscsi_iser_scsi_transport;
80
Or Gerlitz65e7ae72006-05-11 10:00:44 +030081static unsigned int iscsi_max_lun = 512;
82module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
83
84int iser_debug_level = 0;
85
86MODULE_DESCRIPTION("iSER (iSCSI Extensions for RDMA) Datamover "
87 "v" DRV_VER " (" DRV_DATE ")");
88MODULE_LICENSE("Dual BSD/GPL");
89MODULE_AUTHOR("Alex Nezhinsky, Dan Bar Dov, Or Gerlitz");
90
91module_param_named(debug_level, iser_debug_level, int, 0644);
92MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0 (default:disabled)");
93
94struct iser_global ig;
95
96void
97iscsi_iser_recv(struct iscsi_conn *conn,
98 struct iscsi_hdr *hdr, char *rx_data, int rx_data_len)
99{
100 int rc = 0;
101 uint32_t ret_itt;
102 int datalen;
103 int ahslen;
104
105 /* verify PDU length */
106 datalen = ntoh24(hdr->dlength);
107 if (datalen != rx_data_len) {
108 printk(KERN_ERR "iscsi_iser: datalen %d (hdr) != %d (IB) \n",
109 datalen, rx_data_len);
110 rc = ISCSI_ERR_DATALEN;
111 goto error;
112 }
113
114 /* read AHS */
115 ahslen = hdr->hlength * 4;
116
117 /* verify itt (itt encoding: age+cid+itt) */
118 rc = iscsi_verify_itt(conn, hdr, &ret_itt);
119
120 if (!rc)
121 rc = iscsi_complete_pdu(conn, hdr, rx_data, rx_data_len);
122
123 if (rc && rc != ISCSI_ERR_NO_SCSI_CMD)
124 goto error;
125
126 return;
127error:
128 iscsi_conn_failure(conn, rc);
129}
130
131
132/**
133 * iscsi_iser_cmd_init - Initialize iSCSI SCSI_READ or SCSI_WRITE commands
134 *
135 **/
Olaf Kircha8ac6312007-12-13 12:43:35 -0600136static int
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300137iscsi_iser_cmd_init(struct iscsi_cmd_task *ctask)
138{
139 struct iscsi_iser_conn *iser_conn = ctask->conn->dd_data;
140 struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300141
142 iser_ctask->command_sent = 0;
143 iser_ctask->iser_conn = iser_conn;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300144 iser_ctask_rdma_init(iser_ctask);
Olaf Kircha8ac6312007-12-13 12:43:35 -0600145 return 0;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300146}
147
148/**
149 * iscsi_mtask_xmit - xmit management(immediate) task
150 * @conn: iscsi connection
151 * @mtask: task management task
152 *
153 * Notes:
154 * The function can return -EAGAIN in which case caller must
155 * call it again later, or recover. '0' return code means successful
156 * xmit.
157 *
158 **/
159static int
160iscsi_iser_mtask_xmit(struct iscsi_conn *conn,
161 struct iscsi_mgmt_task *mtask)
162{
163 int error = 0;
164
165 debug_scsi("mtask deq [cid %d itt 0x%x]\n", conn->id, mtask->itt);
166
167 error = iser_send_control(conn, mtask);
168
169 /* since iser xmits control with zero copy, mtasks can not be recycled
170 * right after sending them.
171 * The recycling scheme is based on whether a response is expected
172 * - if yes, the mtask is recycled at iscsi_complete_pdu
173 * - if no, the mtask is recycled at iser_snd_completion
174 */
Erez Zilberf0938402007-01-07 12:28:02 +0200175 if (error && error != -ENOBUFS)
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300176 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
177
178 return error;
179}
180
181static int
182iscsi_iser_ctask_xmit_unsol_data(struct iscsi_conn *conn,
183 struct iscsi_cmd_task *ctask)
184{
185 struct iscsi_data hdr;
186 int error = 0;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300187
188 /* Send data-out PDUs while there's still unsolicited data to send */
189 while (ctask->unsol_count > 0) {
Mike Christieffd04362006-08-31 18:09:24 -0400190 iscsi_prep_unsolicit_data_pdu(ctask, &hdr);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300191 debug_scsi("Sending data-out: itt 0x%x, data count %d\n",
192 hdr.itt, ctask->data_count);
193
194 /* the buffer description has been passed with the command */
195 /* Send the command */
196 error = iser_send_data_out(conn, ctask, &hdr);
197 if (error) {
198 ctask->unsol_datasn--;
199 goto iscsi_iser_ctask_xmit_unsol_data_exit;
200 }
201 ctask->unsol_count -= ctask->data_count;
202 debug_scsi("Need to send %d more as data-out PDUs\n",
203 ctask->unsol_count);
204 }
205
206iscsi_iser_ctask_xmit_unsol_data_exit:
207 return error;
208}
209
210static int
211iscsi_iser_ctask_xmit(struct iscsi_conn *conn,
212 struct iscsi_cmd_task *ctask)
213{
214 struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
215 int error = 0;
216
Mike Christie77a23c22007-05-30 12:57:18 -0500217 if (ctask->sc->sc_data_direction == DMA_TO_DEVICE) {
FUJITA Tomonorida9c0c72007-06-01 18:56:21 +0900218 BUG_ON(scsi_bufflen(ctask->sc) == 0);
Mike Christie77a23c22007-05-30 12:57:18 -0500219
220 debug_scsi("cmd [itt %x total %d imm %d unsol_data %d\n",
FUJITA Tomonorida9c0c72007-06-01 18:56:21 +0900221 ctask->itt, scsi_bufflen(ctask->sc),
Mike Christie77a23c22007-05-30 12:57:18 -0500222 ctask->imm_count, ctask->unsol_count);
223 }
224
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300225 debug_scsi("ctask deq [cid %d itt 0x%x]\n",
226 conn->id, ctask->itt);
227
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300228 /* Send the cmd PDU */
229 if (!iser_ctask->command_sent) {
230 error = iser_send_command(conn, ctask);
231 if (error)
232 goto iscsi_iser_ctask_xmit_exit;
233 iser_ctask->command_sent = 1;
234 }
235
236 /* Send unsolicited data-out PDU(s) if necessary */
237 if (ctask->unsol_count)
238 error = iscsi_iser_ctask_xmit_unsol_data(conn, ctask);
239
240 iscsi_iser_ctask_xmit_exit:
Erez Zilberf0938402007-01-07 12:28:02 +0200241 if (error && error != -ENOBUFS)
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300242 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
243 return error;
244}
245
246static void
247iscsi_iser_cleanup_ctask(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
248{
249 struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
250
251 if (iser_ctask->status == ISER_TASK_STATUS_STARTED) {
252 iser_ctask->status = ISER_TASK_STATUS_COMPLETED;
253 iser_ctask_rdma_finalize(iser_ctask);
254 }
255}
256
257static struct iser_conn *
258iscsi_iser_ib_conn_lookup(__u64 ep_handle)
259{
260 struct iser_conn *ib_conn;
261 struct iser_conn *uib_conn = (struct iser_conn *)(unsigned long)ep_handle;
262
263 mutex_lock(&ig.connlist_mutex);
264 list_for_each_entry(ib_conn, &ig.connlist, conn_list) {
265 if (ib_conn == uib_conn) {
266 mutex_unlock(&ig.connlist_mutex);
267 return ib_conn;
268 }
269 }
270 mutex_unlock(&ig.connlist_mutex);
271 iser_err("no conn exists for eph %llx\n",(unsigned long long)ep_handle);
272 return NULL;
273}
274
275static struct iscsi_cls_conn *
276iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
277{
278 struct iscsi_conn *conn;
279 struct iscsi_cls_conn *cls_conn;
280 struct iscsi_iser_conn *iser_conn;
281
Mike Christie5d91e202008-05-21 15:54:01 -0500282 cls_conn = iscsi_conn_setup(cls_session, sizeof(*iser_conn), conn_idx);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300283 if (!cls_conn)
284 return NULL;
285 conn = cls_conn->dd_data;
286
287 /*
288 * due to issues with the login code re iser sematics
289 * this not set in iscsi_conn_setup - FIXME
290 */
291 conn->max_recv_dlength = 128;
292
Mike Christie5d91e202008-05-21 15:54:01 -0500293 iser_conn = conn->dd_data;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300294 /* currently this is the only field which need to be initiated */
295 rwlock_init(&iser_conn->lock);
296
297 conn->dd_data = iser_conn;
298 iser_conn->iscsi_conn = conn;
299
300 return cls_conn;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300301}
302
303static void
304iscsi_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;
Mike Christieb40977d2008-05-21 15:54:03 -0500308 struct iser_conn *ib_conn = iser_conn->ib_conn;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300309
Mike Christie5d91e202008-05-21 15:54:01 -0500310 iscsi_conn_teardown(cls_conn);
Mike Christieb40977d2008-05-21 15:54:03 -0500311 /*
312 * Userspace will normally call the stop callback and
313 * already have freed the ib_conn, but if it goofed up then
314 * we free it here.
315 */
316 if (ib_conn) {
317 ib_conn->iser_conn = NULL;
318 iser_conn_put(ib_conn);
319 }
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300320}
321
322static int
323iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session,
324 struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
325 int is_leading)
326{
327 struct iscsi_conn *conn = cls_conn->dd_data;
328 struct iscsi_iser_conn *iser_conn;
329 struct iser_conn *ib_conn;
330 int error;
331
332 error = iscsi_conn_bind(cls_session, cls_conn, is_leading);
333 if (error)
334 return error;
335
336 /* the transport ep handle comes from user space so it must be
337 * verified against the global ib connections list */
338 ib_conn = iscsi_iser_ib_conn_lookup(transport_eph);
339 if (!ib_conn) {
340 iser_err("can't bind eph %llx\n",
341 (unsigned long long)transport_eph);
342 return -EINVAL;
343 }
344 /* binds the iSER connection retrieved from the previously
345 * connected ep_handle to the iSCSI layer connection. exchanges
346 * connection pointers */
347 iser_err("binding iscsi conn %p to iser_conn %p\n",conn,ib_conn);
348 iser_conn = conn->dd_data;
349 ib_conn->iser_conn = iser_conn;
350 iser_conn->ib_conn = ib_conn;
Mike Christieb40977d2008-05-21 15:54:03 -0500351 iser_conn_get(ib_conn);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300352
353 conn->recv_lock = &iser_conn->lock;
354
355 return 0;
356}
357
Mike Christieb40977d2008-05-21 15:54:03 -0500358static void
359iscsi_iser_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
360{
361 struct iscsi_conn *conn = cls_conn->dd_data;
362 struct iscsi_iser_conn *iser_conn = conn->dd_data;
363 struct iser_conn *ib_conn = iser_conn->ib_conn;
364
365 iscsi_conn_stop(cls_conn, flag);
366 /*
367 * There is no unbind event so the stop callback
368 * must release the ref from the bind.
369 */
370 iser_conn_put(ib_conn);
371 iser_conn->ib_conn = NULL;
372}
373
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300374static int
375iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn)
376{
377 struct iscsi_conn *conn = cls_conn->dd_data;
378 int err;
379
Erez Zilber2e7a7422006-10-22 10:28:38 +0200380 err = iser_conn_set_full_featured_mode(conn);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300381 if (err)
382 return err;
383
Erez Zilber2e7a7422006-10-22 10:28:38 +0200384 return iscsi_conn_start(cls_conn);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300385}
386
Mike Christie75613522008-05-21 15:53:59 -0500387static void iscsi_iser_session_destroy(struct iscsi_cls_session *cls_session)
388{
389 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
390
Mike Christiea4804cd2008-05-21 15:54:00 -0500391 iscsi_host_remove(shost);
392 iscsi_host_free(shost);
Mike Christie75613522008-05-21 15:53:59 -0500393}
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300394
395static struct iscsi_cls_session *
Mike Christie75613522008-05-21 15:53:59 -0500396iscsi_iser_session_create(struct Scsi_Host *shost,
397 uint16_t cmds_max, uint16_t qdepth,
398 uint32_t initial_cmdsn, uint32_t *hostno)
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300399{
400 struct iscsi_cls_session *cls_session;
401 struct iscsi_session *session;
402 int i;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300403 struct iscsi_cmd_task *ctask;
404 struct iscsi_mgmt_task *mtask;
405 struct iscsi_iser_cmd_task *iser_ctask;
406 struct iser_desc *desc;
407
Mike Christie75613522008-05-21 15:53:59 -0500408 if (shost) {
409 printk(KERN_ERR "iscsi_tcp: invalid shost %d.\n",
410 shost->host_no);
411 return NULL;
412 }
413
Mike Christiea4804cd2008-05-21 15:54:00 -0500414 shost = iscsi_host_alloc(&iscsi_iser_sht, 0, ISCSI_MAX_CMD_PER_LUN);
Mike Christie75613522008-05-21 15:53:59 -0500415 if (!shost)
416 return NULL;
417 shost->transportt = iscsi_iser_scsi_transport;
418 shost->max_lun = iscsi_max_lun;
419 shost->max_id = 0;
420 shost->max_channel = 0;
421 shost->max_cmd_len = 16;
422
Mike Christiea4804cd2008-05-21 15:54:00 -0500423 if (iscsi_host_add(shost, NULL))
Mike Christie75613522008-05-21 15:53:59 -0500424 goto free_host;
425 *hostno = shost->host_no;
426
Mike Christie15482712007-05-30 12:57:19 -0500427 /*
428 * we do not support setting can_queue cmd_per_lun from userspace yet
429 * because we preallocate so many resources
430 */
Mike Christie75613522008-05-21 15:53:59 -0500431 cls_session = iscsi_session_setup(&iscsi_iser_transport, shost,
Mike Christie15482712007-05-30 12:57:19 -0500432 ISCSI_DEF_XMIT_CMDS_MAX,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300433 sizeof(struct iscsi_iser_cmd_task),
434 sizeof(struct iser_desc),
Mike Christie75613522008-05-21 15:53:59 -0500435 initial_cmdsn);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300436 if (!cls_session)
Mike Christie75613522008-05-21 15:53:59 -0500437 goto remove_host;
438 session = cls_session->dd_data;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300439
Mike Christie75613522008-05-21 15:53:59 -0500440 shost->can_queue = session->cmds_max;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300441 /* libiscsi setup itts, data and pool so just set desc fields */
442 for (i = 0; i < session->cmds_max; i++) {
443 ctask = session->cmds[i];
444 iser_ctask = ctask->dd_data;
445 ctask->hdr = (struct iscsi_cmd *)&iser_ctask->desc.iscsi_header;
Boaz Harrosh38ad03d2007-12-13 12:43:24 -0600446 ctask->hdr_max = sizeof(iser_ctask->desc.iscsi_header);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300447 }
448
449 for (i = 0; i < session->mgmtpool_max; i++) {
450 mtask = session->mgmt_cmds[i];
451 desc = mtask->dd_data;
452 mtask->hdr = &desc->iscsi_header;
453 desc->data = mtask->data;
454 }
455
456 return cls_session;
Mike Christie75613522008-05-21 15:53:59 -0500457
458remove_host:
Mike Christiea4804cd2008-05-21 15:54:00 -0500459 iscsi_host_remove(shost);
Mike Christie75613522008-05-21 15:53:59 -0500460free_host:
Mike Christiea4804cd2008-05-21 15:54:00 -0500461 iscsi_host_free(shost);
Mike Christie75613522008-05-21 15:53:59 -0500462 return NULL;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300463}
464
465static int
Mike Christie358ff012006-06-28 12:00:25 -0500466iscsi_iser_set_param(struct iscsi_cls_conn *cls_conn,
467 enum iscsi_param param, char *buf, int buflen)
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300468{
Mike Christie358ff012006-06-28 12:00:25 -0500469 int value;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300470
471 switch (param) {
472 case ISCSI_PARAM_MAX_RECV_DLENGTH:
473 /* TBD */
474 break;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300475 case ISCSI_PARAM_HDRDGST_EN:
Mike Christie358ff012006-06-28 12:00:25 -0500476 sscanf(buf, "%d", &value);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300477 if (value) {
478 printk(KERN_ERR "DataDigest wasn't negotiated to None");
479 return -EPROTO;
480 }
481 break;
482 case ISCSI_PARAM_DATADGST_EN:
Mike Christie358ff012006-06-28 12:00:25 -0500483 sscanf(buf, "%d", &value);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300484 if (value) {
485 printk(KERN_ERR "DataDigest wasn't negotiated to None");
486 return -EPROTO;
487 }
488 break;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300489 case ISCSI_PARAM_IFMARKER_EN:
Mike Christie358ff012006-06-28 12:00:25 -0500490 sscanf(buf, "%d", &value);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300491 if (value) {
492 printk(KERN_ERR "IFMarker wasn't negotiated to No");
493 return -EPROTO;
494 }
495 break;
496 case ISCSI_PARAM_OFMARKER_EN:
Mike Christie358ff012006-06-28 12:00:25 -0500497 sscanf(buf, "%d", &value);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300498 if (value) {
499 printk(KERN_ERR "OFMarker wasn't negotiated to No");
500 return -EPROTO;
501 }
502 break;
503 default:
Mike Christie358ff012006-06-28 12:00:25 -0500504 return iscsi_set_param(cls_conn, param, buf, buflen);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300505 }
506
507 return 0;
508}
509
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300510static void
511iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
512{
513 struct iscsi_conn *conn = cls_conn->dd_data;
514
515 stats->txdata_octets = conn->txdata_octets;
516 stats->rxdata_octets = conn->rxdata_octets;
517 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
518 stats->dataout_pdus = conn->dataout_pdus_cnt;
519 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
520 stats->datain_pdus = conn->datain_pdus_cnt; /* always 0 */
521 stats->r2t_pdus = conn->r2t_pdus_cnt; /* always 0 */
522 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
523 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
Eli Dorfman87528222008-04-29 13:46:52 -0700524 stats->custom_length = 4;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300525 strcpy(stats->custom[0].desc, "qp_tx_queue_full");
526 stats->custom[0].value = 0; /* TB iser_conn->qp_tx_queue_full; */
527 strcpy(stats->custom[1].desc, "fmr_map_not_avail");
528 stats->custom[1].value = 0; /* TB iser_conn->fmr_map_not_avail */;
529 strcpy(stats->custom[2].desc, "eh_abort_cnt");
530 stats->custom[2].value = conn->eh_abort_cnt;
Eli Dorfman87528222008-04-29 13:46:52 -0700531 strcpy(stats->custom[3].desc, "fmr_unalign_cnt");
532 stats->custom[3].value = conn->fmr_unalign_cnt;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300533}
534
535static int
536iscsi_iser_ep_connect(struct sockaddr *dst_addr, int non_blocking,
537 __u64 *ep_handle)
538{
539 int err;
540 struct iser_conn *ib_conn;
541
542 err = iser_conn_init(&ib_conn);
543 if (err)
544 goto out;
545
546 err = iser_connect(ib_conn, NULL, (struct sockaddr_in *)dst_addr, non_blocking);
547 if (!err)
548 *ep_handle = (__u64)(unsigned long)ib_conn;
549
550out:
551 return err;
552}
553
554static int
555iscsi_iser_ep_poll(__u64 ep_handle, int timeout_ms)
556{
557 struct iser_conn *ib_conn = iscsi_iser_ib_conn_lookup(ep_handle);
558 int rc;
559
560 if (!ib_conn)
561 return -EINVAL;
562
563 rc = wait_event_interruptible_timeout(ib_conn->wait,
564 ib_conn->state == ISER_CONN_UP,
565 msecs_to_jiffies(timeout_ms));
566
567 /* if conn establishment failed, return error code to iscsi */
568 if (!rc &&
569 (ib_conn->state == ISER_CONN_TERMINATING ||
570 ib_conn->state == ISER_CONN_DOWN))
571 rc = -1;
572
573 iser_err("ib conn %p rc = %d\n", ib_conn, rc);
574
575 if (rc > 0)
576 return 1; /* success, this is the equivalent of POLLOUT */
577 else if (!rc)
578 return 0; /* timeout */
579 else
580 return rc; /* signal */
581}
582
583static void
584iscsi_iser_ep_disconnect(__u64 ep_handle)
585{
Mike Christie1c834692006-07-24 15:47:26 -0500586 struct iser_conn *ib_conn;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300587
Mike Christie1c834692006-07-24 15:47:26 -0500588 ib_conn = iscsi_iser_ib_conn_lookup(ep_handle);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300589 if (!ib_conn)
590 return;
591
Mike Christieb40977d2008-05-21 15:54:03 -0500592 if (ib_conn->iser_conn)
593 /*
594 * Must suspend xmit path if the ep is bound to the
595 * iscsi_conn, so we know we are not accessing the ib_conn
596 * when we free it.
597 *
598 * This may not be bound if the ep poll failed.
599 */
600 iscsi_suspend_tx(ib_conn->iser_conn->iscsi_conn);
601
602
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300603 iser_err("ib conn %p state %d\n",ib_conn, ib_conn->state);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300604 iser_conn_terminate(ib_conn);
605}
606
607static struct scsi_host_template iscsi_iser_sht = {
Mike Christie79743922007-07-26 12:46:46 -0500608 .module = THIS_MODULE,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300609 .name = "iSCSI Initiator over iSER, v." DRV_VER,
610 .queuecommand = iscsi_queuecommand,
Erez Zilber64106272008-01-17 11:53:17 +0200611 .change_queue_depth = iscsi_change_queue_depth,
Mike Christie15482712007-05-30 12:57:19 -0500612 .can_queue = ISCSI_DEF_XMIT_CMDS_MAX - 1,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300613 .sg_tablesize = ISCSI_ISER_SG_TABLESIZE,
Erez Zilber8072ec22006-09-11 12:20:54 +0300614 .max_sectors = 1024,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300615 .cmd_per_lun = ISCSI_MAX_CMD_PER_LUN,
616 .eh_abort_handler = iscsi_eh_abort,
Erez Zilber90c18f32008-01-22 12:06:25 +0200617 .eh_device_reset_handler= iscsi_eh_device_reset,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300618 .eh_host_reset_handler = iscsi_eh_host_reset,
619 .use_clustering = DISABLE_CLUSTERING,
620 .proc_name = "iscsi_iser",
621 .this_id = -1,
622};
623
624static struct iscsi_transport iscsi_iser_transport = {
625 .owner = THIS_MODULE,
626 .name = "iser",
627 .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T,
628 .param_mask = ISCSI_MAX_RECV_DLENGTH |
629 ISCSI_MAX_XMIT_DLENGTH |
630 ISCSI_HDRDGST_EN |
631 ISCSI_DATADGST_EN |
632 ISCSI_INITIAL_R2T_EN |
633 ISCSI_MAX_R2T |
634 ISCSI_IMM_DATA_EN |
635 ISCSI_FIRST_BURST |
636 ISCSI_MAX_BURST |
637 ISCSI_PDU_INORDER_EN |
Mike Christie358ff012006-06-28 12:00:25 -0500638 ISCSI_DATASEQ_INORDER_EN |
639 ISCSI_EXP_STATSN |
640 ISCSI_PERSISTENT_PORT |
641 ISCSI_PERSISTENT_ADDRESS |
Mike Christieb2c64162007-05-30 12:57:16 -0500642 ISCSI_TARGET_NAME | ISCSI_TPGT |
643 ISCSI_USERNAME | ISCSI_PASSWORD |
Mike Christief6d51802007-12-13 12:43:30 -0600644 ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
645 ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
646 ISCSI_PING_TMO | ISCSI_RECV_TMO,
Mike Christie8ad57812007-05-30 12:57:13 -0500647 .host_param_mask = ISCSI_HOST_HWADDRESS |
Mike Christied8196ed2007-05-30 12:57:25 -0500648 ISCSI_HOST_NETDEV_NAME |
Mike Christie8ad57812007-05-30 12:57:13 -0500649 ISCSI_HOST_INITIATOR_NAME,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300650 /* session management */
651 .create_session = iscsi_iser_session_create,
Mike Christie75613522008-05-21 15:53:59 -0500652 .destroy_session = iscsi_iser_session_destroy,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300653 /* connection management */
654 .create_conn = iscsi_iser_conn_create,
655 .bind_conn = iscsi_iser_conn_bind,
656 .destroy_conn = iscsi_iser_conn_destroy,
Mike Christie358ff012006-06-28 12:00:25 -0500657 .set_param = iscsi_iser_set_param,
658 .get_conn_param = iscsi_conn_get_param,
659 .get_session_param = iscsi_session_get_param,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300660 .start_conn = iscsi_iser_conn_start,
Mike Christieb40977d2008-05-21 15:54:03 -0500661 .stop_conn = iscsi_iser_conn_stop,
Mike Christie0801c242007-05-30 12:57:12 -0500662 /* iscsi host params */
663 .get_host_param = iscsi_host_get_param,
664 .set_host_param = iscsi_host_set_param,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300665 /* IO */
666 .send_pdu = iscsi_conn_send_pdu,
667 .get_stats = iscsi_iser_conn_get_stats,
668 .init_cmd_task = iscsi_iser_cmd_init,
669 .xmit_cmd_task = iscsi_iser_ctask_xmit,
670 .xmit_mgmt_task = iscsi_iser_mtask_xmit,
671 .cleanup_cmd_task = iscsi_iser_cleanup_ctask,
672 /* recovery */
673 .session_recovery_timedout = iscsi_session_recovery_timedout,
674
675 .ep_connect = iscsi_iser_ep_connect,
676 .ep_poll = iscsi_iser_ep_poll,
677 .ep_disconnect = iscsi_iser_ep_disconnect
678};
679
680static int __init iser_init(void)
681{
682 int err;
683
684 iser_dbg("Starting iSER datamover...\n");
685
686 if (iscsi_max_lun < 1) {
687 printk(KERN_ERR "Invalid max_lun value of %u\n", iscsi_max_lun);
688 return -EINVAL;
689 }
690
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300691 memset(&ig, 0, sizeof(struct iser_global));
692
693 ig.desc_cache = kmem_cache_create("iser_descriptors",
694 sizeof (struct iser_desc),
695 0, SLAB_HWCACHE_ALIGN,
Paul Mundt20c2df82007-07-20 10:11:58 +0900696 NULL);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300697 if (ig.desc_cache == NULL)
698 return -ENOMEM;
699
700 /* device init is called only after the first addr resolution */
701 mutex_init(&ig.device_list_mutex);
702 INIT_LIST_HEAD(&ig.device_list);
703 mutex_init(&ig.connlist_mutex);
704 INIT_LIST_HEAD(&ig.connlist);
705
Mike Christie75613522008-05-21 15:53:59 -0500706 iscsi_iser_scsi_transport = iscsi_register_transport(
707 &iscsi_iser_transport);
708 if (!iscsi_iser_scsi_transport) {
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300709 iser_err("iscsi_register_transport failed\n");
710 err = -EINVAL;
711 goto register_transport_failure;
712 }
713
714 return 0;
715
716register_transport_failure:
717 kmem_cache_destroy(ig.desc_cache);
718
719 return err;
720}
721
722static void __exit iser_exit(void)
723{
724 iser_dbg("Removing iSER datamover...\n");
725 iscsi_unregister_transport(&iscsi_iser_transport);
726 kmem_cache_destroy(ig.desc_cache);
727}
728
729module_init(iser_init);
730module_exit(iser_exit);