blob: 7b1468869066e6bb7ce068a0b1d940b31b28c9c4 [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;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300101 int datalen;
102 int ahslen;
103
104 /* verify PDU length */
105 datalen = ntoh24(hdr->dlength);
106 if (datalen != rx_data_len) {
107 printk(KERN_ERR "iscsi_iser: datalen %d (hdr) != %d (IB) \n",
108 datalen, rx_data_len);
109 rc = ISCSI_ERR_DATALEN;
110 goto error;
111 }
112
113 /* read AHS */
114 ahslen = hdr->hlength * 4;
115
Mike Christie0af967f2008-05-21 15:54:04 -0500116 rc = iscsi_complete_pdu(conn, hdr, rx_data, rx_data_len);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300117 if (rc && rc != ISCSI_ERR_NO_SCSI_CMD)
118 goto error;
119
120 return;
121error:
122 iscsi_conn_failure(conn, rc);
123}
124
125
126/**
127 * iscsi_iser_cmd_init - Initialize iSCSI SCSI_READ or SCSI_WRITE commands
128 *
129 **/
Olaf Kircha8ac6312007-12-13 12:43:35 -0600130static int
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300131iscsi_iser_cmd_init(struct iscsi_cmd_task *ctask)
132{
133 struct iscsi_iser_conn *iser_conn = ctask->conn->dd_data;
134 struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300135
136 iser_ctask->command_sent = 0;
137 iser_ctask->iser_conn = iser_conn;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300138 iser_ctask_rdma_init(iser_ctask);
Olaf Kircha8ac6312007-12-13 12:43:35 -0600139 return 0;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300140}
141
142/**
143 * iscsi_mtask_xmit - xmit management(immediate) task
144 * @conn: iscsi connection
145 * @mtask: task management task
146 *
147 * Notes:
148 * The function can return -EAGAIN in which case caller must
149 * call it again later, or recover. '0' return code means successful
150 * xmit.
151 *
152 **/
153static int
154iscsi_iser_mtask_xmit(struct iscsi_conn *conn,
155 struct iscsi_mgmt_task *mtask)
156{
157 int error = 0;
158
159 debug_scsi("mtask deq [cid %d itt 0x%x]\n", conn->id, mtask->itt);
160
161 error = iser_send_control(conn, mtask);
162
163 /* since iser xmits control with zero copy, mtasks can not be recycled
164 * right after sending them.
165 * The recycling scheme is based on whether a response is expected
166 * - if yes, the mtask is recycled at iscsi_complete_pdu
167 * - if no, the mtask is recycled at iser_snd_completion
168 */
Erez Zilberf0938402007-01-07 12:28:02 +0200169 if (error && error != -ENOBUFS)
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300170 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
171
172 return error;
173}
174
175static int
176iscsi_iser_ctask_xmit_unsol_data(struct iscsi_conn *conn,
177 struct iscsi_cmd_task *ctask)
178{
179 struct iscsi_data hdr;
180 int error = 0;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300181
182 /* Send data-out PDUs while there's still unsolicited data to send */
183 while (ctask->unsol_count > 0) {
Mike Christieffd04362006-08-31 18:09:24 -0400184 iscsi_prep_unsolicit_data_pdu(ctask, &hdr);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300185 debug_scsi("Sending data-out: itt 0x%x, data count %d\n",
186 hdr.itt, ctask->data_count);
187
188 /* the buffer description has been passed with the command */
189 /* Send the command */
190 error = iser_send_data_out(conn, ctask, &hdr);
191 if (error) {
192 ctask->unsol_datasn--;
193 goto iscsi_iser_ctask_xmit_unsol_data_exit;
194 }
195 ctask->unsol_count -= ctask->data_count;
196 debug_scsi("Need to send %d more as data-out PDUs\n",
197 ctask->unsol_count);
198 }
199
200iscsi_iser_ctask_xmit_unsol_data_exit:
201 return error;
202}
203
204static int
205iscsi_iser_ctask_xmit(struct iscsi_conn *conn,
206 struct iscsi_cmd_task *ctask)
207{
208 struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
209 int error = 0;
210
Mike Christie77a23c22007-05-30 12:57:18 -0500211 if (ctask->sc->sc_data_direction == DMA_TO_DEVICE) {
FUJITA Tomonorida9c0c72007-06-01 18:56:21 +0900212 BUG_ON(scsi_bufflen(ctask->sc) == 0);
Mike Christie77a23c22007-05-30 12:57:18 -0500213
214 debug_scsi("cmd [itt %x total %d imm %d unsol_data %d\n",
FUJITA Tomonorida9c0c72007-06-01 18:56:21 +0900215 ctask->itt, scsi_bufflen(ctask->sc),
Mike Christie77a23c22007-05-30 12:57:18 -0500216 ctask->imm_count, ctask->unsol_count);
217 }
218
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300219 debug_scsi("ctask deq [cid %d itt 0x%x]\n",
220 conn->id, ctask->itt);
221
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300222 /* Send the cmd PDU */
223 if (!iser_ctask->command_sent) {
224 error = iser_send_command(conn, ctask);
225 if (error)
226 goto iscsi_iser_ctask_xmit_exit;
227 iser_ctask->command_sent = 1;
228 }
229
230 /* Send unsolicited data-out PDU(s) if necessary */
231 if (ctask->unsol_count)
232 error = iscsi_iser_ctask_xmit_unsol_data(conn, ctask);
233
234 iscsi_iser_ctask_xmit_exit:
Erez Zilberf0938402007-01-07 12:28:02 +0200235 if (error && error != -ENOBUFS)
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300236 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
237 return error;
238}
239
240static void
241iscsi_iser_cleanup_ctask(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
242{
243 struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
244
245 if (iser_ctask->status == ISER_TASK_STATUS_STARTED) {
246 iser_ctask->status = ISER_TASK_STATUS_COMPLETED;
247 iser_ctask_rdma_finalize(iser_ctask);
248 }
249}
250
251static struct iser_conn *
252iscsi_iser_ib_conn_lookup(__u64 ep_handle)
253{
254 struct iser_conn *ib_conn;
255 struct iser_conn *uib_conn = (struct iser_conn *)(unsigned long)ep_handle;
256
257 mutex_lock(&ig.connlist_mutex);
258 list_for_each_entry(ib_conn, &ig.connlist, conn_list) {
259 if (ib_conn == uib_conn) {
260 mutex_unlock(&ig.connlist_mutex);
261 return ib_conn;
262 }
263 }
264 mutex_unlock(&ig.connlist_mutex);
265 iser_err("no conn exists for eph %llx\n",(unsigned long long)ep_handle);
266 return NULL;
267}
268
269static struct iscsi_cls_conn *
270iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
271{
272 struct iscsi_conn *conn;
273 struct iscsi_cls_conn *cls_conn;
274 struct iscsi_iser_conn *iser_conn;
275
Mike Christie5d91e202008-05-21 15:54:01 -0500276 cls_conn = iscsi_conn_setup(cls_session, sizeof(*iser_conn), conn_idx);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300277 if (!cls_conn)
278 return NULL;
279 conn = cls_conn->dd_data;
280
281 /*
282 * due to issues with the login code re iser sematics
283 * this not set in iscsi_conn_setup - FIXME
284 */
285 conn->max_recv_dlength = 128;
286
Mike Christie5d91e202008-05-21 15:54:01 -0500287 iser_conn = conn->dd_data;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300288 /* currently this is the only field which need to be initiated */
289 rwlock_init(&iser_conn->lock);
290
291 conn->dd_data = iser_conn;
292 iser_conn->iscsi_conn = conn;
293
294 return cls_conn;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300295}
296
297static void
298iscsi_iser_conn_destroy(struct iscsi_cls_conn *cls_conn)
299{
300 struct iscsi_conn *conn = cls_conn->dd_data;
301 struct iscsi_iser_conn *iser_conn = conn->dd_data;
Mike Christieb40977d2008-05-21 15:54:03 -0500302 struct iser_conn *ib_conn = iser_conn->ib_conn;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300303
Mike Christie5d91e202008-05-21 15:54:01 -0500304 iscsi_conn_teardown(cls_conn);
Mike Christieb40977d2008-05-21 15:54:03 -0500305 /*
306 * Userspace will normally call the stop callback and
307 * already have freed the ib_conn, but if it goofed up then
308 * we free it here.
309 */
310 if (ib_conn) {
311 ib_conn->iser_conn = NULL;
312 iser_conn_put(ib_conn);
313 }
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300314}
315
316static int
317iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session,
318 struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
319 int is_leading)
320{
321 struct iscsi_conn *conn = cls_conn->dd_data;
322 struct iscsi_iser_conn *iser_conn;
323 struct iser_conn *ib_conn;
324 int error;
325
326 error = iscsi_conn_bind(cls_session, cls_conn, is_leading);
327 if (error)
328 return error;
329
330 /* the transport ep handle comes from user space so it must be
331 * verified against the global ib connections list */
332 ib_conn = iscsi_iser_ib_conn_lookup(transport_eph);
333 if (!ib_conn) {
334 iser_err("can't bind eph %llx\n",
335 (unsigned long long)transport_eph);
336 return -EINVAL;
337 }
338 /* binds the iSER connection retrieved from the previously
339 * connected ep_handle to the iSCSI layer connection. exchanges
340 * connection pointers */
341 iser_err("binding iscsi conn %p to iser_conn %p\n",conn,ib_conn);
342 iser_conn = conn->dd_data;
343 ib_conn->iser_conn = iser_conn;
344 iser_conn->ib_conn = ib_conn;
Mike Christieb40977d2008-05-21 15:54:03 -0500345 iser_conn_get(ib_conn);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300346
347 conn->recv_lock = &iser_conn->lock;
348
349 return 0;
350}
351
Mike Christieb40977d2008-05-21 15:54:03 -0500352static void
353iscsi_iser_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
354{
355 struct iscsi_conn *conn = cls_conn->dd_data;
356 struct iscsi_iser_conn *iser_conn = conn->dd_data;
357 struct iser_conn *ib_conn = iser_conn->ib_conn;
358
359 iscsi_conn_stop(cls_conn, flag);
360 /*
361 * There is no unbind event so the stop callback
362 * must release the ref from the bind.
363 */
364 iser_conn_put(ib_conn);
365 iser_conn->ib_conn = NULL;
366}
367
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300368static int
369iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn)
370{
371 struct iscsi_conn *conn = cls_conn->dd_data;
372 int err;
373
Erez Zilber2e7a7422006-10-22 10:28:38 +0200374 err = iser_conn_set_full_featured_mode(conn);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300375 if (err)
376 return err;
377
Erez Zilber2e7a7422006-10-22 10:28:38 +0200378 return iscsi_conn_start(cls_conn);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300379}
380
Mike Christie75613522008-05-21 15:53:59 -0500381static void iscsi_iser_session_destroy(struct iscsi_cls_session *cls_session)
382{
383 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
384
Mike Christiea4804cd2008-05-21 15:54:00 -0500385 iscsi_host_remove(shost);
386 iscsi_host_free(shost);
Mike Christie75613522008-05-21 15:53:59 -0500387}
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300388
389static struct iscsi_cls_session *
Mike Christie75613522008-05-21 15:53:59 -0500390iscsi_iser_session_create(struct Scsi_Host *shost,
391 uint16_t cmds_max, uint16_t qdepth,
392 uint32_t initial_cmdsn, uint32_t *hostno)
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300393{
394 struct iscsi_cls_session *cls_session;
395 struct iscsi_session *session;
396 int i;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300397 struct iscsi_cmd_task *ctask;
398 struct iscsi_mgmt_task *mtask;
399 struct iscsi_iser_cmd_task *iser_ctask;
400 struct iser_desc *desc;
401
Mike Christie75613522008-05-21 15:53:59 -0500402 if (shost) {
403 printk(KERN_ERR "iscsi_tcp: invalid shost %d.\n",
404 shost->host_no);
405 return NULL;
406 }
407
Mike Christiea4804cd2008-05-21 15:54:00 -0500408 shost = iscsi_host_alloc(&iscsi_iser_sht, 0, ISCSI_MAX_CMD_PER_LUN);
Mike Christie75613522008-05-21 15:53:59 -0500409 if (!shost)
410 return NULL;
411 shost->transportt = iscsi_iser_scsi_transport;
412 shost->max_lun = iscsi_max_lun;
413 shost->max_id = 0;
414 shost->max_channel = 0;
415 shost->max_cmd_len = 16;
416
Mike Christiea4804cd2008-05-21 15:54:00 -0500417 if (iscsi_host_add(shost, NULL))
Mike Christie75613522008-05-21 15:53:59 -0500418 goto free_host;
419 *hostno = shost->host_no;
420
Mike Christie15482712007-05-30 12:57:19 -0500421 /*
422 * we do not support setting can_queue cmd_per_lun from userspace yet
423 * because we preallocate so many resources
424 */
Mike Christie75613522008-05-21 15:53:59 -0500425 cls_session = iscsi_session_setup(&iscsi_iser_transport, shost,
Mike Christie15482712007-05-30 12:57:19 -0500426 ISCSI_DEF_XMIT_CMDS_MAX,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300427 sizeof(struct iscsi_iser_cmd_task),
428 sizeof(struct iser_desc),
Mike Christie75613522008-05-21 15:53:59 -0500429 initial_cmdsn);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300430 if (!cls_session)
Mike Christie75613522008-05-21 15:53:59 -0500431 goto remove_host;
432 session = cls_session->dd_data;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300433
Mike Christie75613522008-05-21 15:53:59 -0500434 shost->can_queue = session->cmds_max;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300435 /* libiscsi setup itts, data and pool so just set desc fields */
436 for (i = 0; i < session->cmds_max; i++) {
437 ctask = session->cmds[i];
438 iser_ctask = ctask->dd_data;
439 ctask->hdr = (struct iscsi_cmd *)&iser_ctask->desc.iscsi_header;
Boaz Harrosh38ad03d2007-12-13 12:43:24 -0600440 ctask->hdr_max = sizeof(iser_ctask->desc.iscsi_header);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300441 }
442
443 for (i = 0; i < session->mgmtpool_max; i++) {
444 mtask = session->mgmt_cmds[i];
445 desc = mtask->dd_data;
446 mtask->hdr = &desc->iscsi_header;
447 desc->data = mtask->data;
448 }
449
450 return cls_session;
Mike Christie75613522008-05-21 15:53:59 -0500451
452remove_host:
Mike Christiea4804cd2008-05-21 15:54:00 -0500453 iscsi_host_remove(shost);
Mike Christie75613522008-05-21 15:53:59 -0500454free_host:
Mike Christiea4804cd2008-05-21 15:54:00 -0500455 iscsi_host_free(shost);
Mike Christie75613522008-05-21 15:53:59 -0500456 return NULL;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300457}
458
459static int
Mike Christie358ff012006-06-28 12:00:25 -0500460iscsi_iser_set_param(struct iscsi_cls_conn *cls_conn,
461 enum iscsi_param param, char *buf, int buflen)
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300462{
Mike Christie358ff012006-06-28 12:00:25 -0500463 int value;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300464
465 switch (param) {
466 case ISCSI_PARAM_MAX_RECV_DLENGTH:
467 /* TBD */
468 break;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300469 case ISCSI_PARAM_HDRDGST_EN:
Mike Christie358ff012006-06-28 12:00:25 -0500470 sscanf(buf, "%d", &value);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300471 if (value) {
472 printk(KERN_ERR "DataDigest wasn't negotiated to None");
473 return -EPROTO;
474 }
475 break;
476 case ISCSI_PARAM_DATADGST_EN:
Mike Christie358ff012006-06-28 12:00:25 -0500477 sscanf(buf, "%d", &value);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300478 if (value) {
479 printk(KERN_ERR "DataDigest wasn't negotiated to None");
480 return -EPROTO;
481 }
482 break;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300483 case ISCSI_PARAM_IFMARKER_EN:
Mike Christie358ff012006-06-28 12:00:25 -0500484 sscanf(buf, "%d", &value);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300485 if (value) {
486 printk(KERN_ERR "IFMarker wasn't negotiated to No");
487 return -EPROTO;
488 }
489 break;
490 case ISCSI_PARAM_OFMARKER_EN:
Mike Christie358ff012006-06-28 12:00:25 -0500491 sscanf(buf, "%d", &value);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300492 if (value) {
493 printk(KERN_ERR "OFMarker wasn't negotiated to No");
494 return -EPROTO;
495 }
496 break;
497 default:
Mike Christie358ff012006-06-28 12:00:25 -0500498 return iscsi_set_param(cls_conn, param, buf, buflen);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300499 }
500
501 return 0;
502}
503
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300504static void
505iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
506{
507 struct iscsi_conn *conn = cls_conn->dd_data;
508
509 stats->txdata_octets = conn->txdata_octets;
510 stats->rxdata_octets = conn->rxdata_octets;
511 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
512 stats->dataout_pdus = conn->dataout_pdus_cnt;
513 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
514 stats->datain_pdus = conn->datain_pdus_cnt; /* always 0 */
515 stats->r2t_pdus = conn->r2t_pdus_cnt; /* always 0 */
516 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
517 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
Eli Dorfman87528222008-04-29 13:46:52 -0700518 stats->custom_length = 4;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300519 strcpy(stats->custom[0].desc, "qp_tx_queue_full");
520 stats->custom[0].value = 0; /* TB iser_conn->qp_tx_queue_full; */
521 strcpy(stats->custom[1].desc, "fmr_map_not_avail");
522 stats->custom[1].value = 0; /* TB iser_conn->fmr_map_not_avail */;
523 strcpy(stats->custom[2].desc, "eh_abort_cnt");
524 stats->custom[2].value = conn->eh_abort_cnt;
Eli Dorfman87528222008-04-29 13:46:52 -0700525 strcpy(stats->custom[3].desc, "fmr_unalign_cnt");
526 stats->custom[3].value = conn->fmr_unalign_cnt;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300527}
528
529static int
530iscsi_iser_ep_connect(struct sockaddr *dst_addr, int non_blocking,
531 __u64 *ep_handle)
532{
533 int err;
534 struct iser_conn *ib_conn;
535
536 err = iser_conn_init(&ib_conn);
537 if (err)
538 goto out;
539
540 err = iser_connect(ib_conn, NULL, (struct sockaddr_in *)dst_addr, non_blocking);
541 if (!err)
542 *ep_handle = (__u64)(unsigned long)ib_conn;
543
544out:
545 return err;
546}
547
548static int
549iscsi_iser_ep_poll(__u64 ep_handle, int timeout_ms)
550{
551 struct iser_conn *ib_conn = iscsi_iser_ib_conn_lookup(ep_handle);
552 int rc;
553
554 if (!ib_conn)
555 return -EINVAL;
556
557 rc = wait_event_interruptible_timeout(ib_conn->wait,
558 ib_conn->state == ISER_CONN_UP,
559 msecs_to_jiffies(timeout_ms));
560
561 /* if conn establishment failed, return error code to iscsi */
562 if (!rc &&
563 (ib_conn->state == ISER_CONN_TERMINATING ||
564 ib_conn->state == ISER_CONN_DOWN))
565 rc = -1;
566
567 iser_err("ib conn %p rc = %d\n", ib_conn, rc);
568
569 if (rc > 0)
570 return 1; /* success, this is the equivalent of POLLOUT */
571 else if (!rc)
572 return 0; /* timeout */
573 else
574 return rc; /* signal */
575}
576
577static void
578iscsi_iser_ep_disconnect(__u64 ep_handle)
579{
Mike Christie1c834692006-07-24 15:47:26 -0500580 struct iser_conn *ib_conn;
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300581
Mike Christie1c834692006-07-24 15:47:26 -0500582 ib_conn = iscsi_iser_ib_conn_lookup(ep_handle);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300583 if (!ib_conn)
584 return;
585
Mike Christieb40977d2008-05-21 15:54:03 -0500586 if (ib_conn->iser_conn)
587 /*
588 * Must suspend xmit path if the ep is bound to the
589 * iscsi_conn, so we know we are not accessing the ib_conn
590 * when we free it.
591 *
592 * This may not be bound if the ep poll failed.
593 */
594 iscsi_suspend_tx(ib_conn->iser_conn->iscsi_conn);
595
596
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300597 iser_err("ib conn %p state %d\n",ib_conn, ib_conn->state);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300598 iser_conn_terminate(ib_conn);
599}
600
601static struct scsi_host_template iscsi_iser_sht = {
Mike Christie79743922007-07-26 12:46:46 -0500602 .module = THIS_MODULE,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300603 .name = "iSCSI Initiator over iSER, v." DRV_VER,
604 .queuecommand = iscsi_queuecommand,
Erez Zilber64106272008-01-17 11:53:17 +0200605 .change_queue_depth = iscsi_change_queue_depth,
Mike Christie15482712007-05-30 12:57:19 -0500606 .can_queue = ISCSI_DEF_XMIT_CMDS_MAX - 1,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300607 .sg_tablesize = ISCSI_ISER_SG_TABLESIZE,
Erez Zilber8072ec22006-09-11 12:20:54 +0300608 .max_sectors = 1024,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300609 .cmd_per_lun = ISCSI_MAX_CMD_PER_LUN,
610 .eh_abort_handler = iscsi_eh_abort,
Erez Zilber90c18f32008-01-22 12:06:25 +0200611 .eh_device_reset_handler= iscsi_eh_device_reset,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300612 .eh_host_reset_handler = iscsi_eh_host_reset,
613 .use_clustering = DISABLE_CLUSTERING,
614 .proc_name = "iscsi_iser",
615 .this_id = -1,
616};
617
618static struct iscsi_transport iscsi_iser_transport = {
619 .owner = THIS_MODULE,
620 .name = "iser",
621 .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T,
622 .param_mask = ISCSI_MAX_RECV_DLENGTH |
623 ISCSI_MAX_XMIT_DLENGTH |
624 ISCSI_HDRDGST_EN |
625 ISCSI_DATADGST_EN |
626 ISCSI_INITIAL_R2T_EN |
627 ISCSI_MAX_R2T |
628 ISCSI_IMM_DATA_EN |
629 ISCSI_FIRST_BURST |
630 ISCSI_MAX_BURST |
631 ISCSI_PDU_INORDER_EN |
Mike Christie358ff012006-06-28 12:00:25 -0500632 ISCSI_DATASEQ_INORDER_EN |
633 ISCSI_EXP_STATSN |
634 ISCSI_PERSISTENT_PORT |
635 ISCSI_PERSISTENT_ADDRESS |
Mike Christieb2c64162007-05-30 12:57:16 -0500636 ISCSI_TARGET_NAME | ISCSI_TPGT |
637 ISCSI_USERNAME | ISCSI_PASSWORD |
Mike Christief6d51802007-12-13 12:43:30 -0600638 ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
639 ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
640 ISCSI_PING_TMO | ISCSI_RECV_TMO,
Mike Christie8ad57812007-05-30 12:57:13 -0500641 .host_param_mask = ISCSI_HOST_HWADDRESS |
Mike Christied8196ed2007-05-30 12:57:25 -0500642 ISCSI_HOST_NETDEV_NAME |
Mike Christie8ad57812007-05-30 12:57:13 -0500643 ISCSI_HOST_INITIATOR_NAME,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300644 /* session management */
645 .create_session = iscsi_iser_session_create,
Mike Christie75613522008-05-21 15:53:59 -0500646 .destroy_session = iscsi_iser_session_destroy,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300647 /* connection management */
648 .create_conn = iscsi_iser_conn_create,
649 .bind_conn = iscsi_iser_conn_bind,
650 .destroy_conn = iscsi_iser_conn_destroy,
Mike Christie358ff012006-06-28 12:00:25 -0500651 .set_param = iscsi_iser_set_param,
652 .get_conn_param = iscsi_conn_get_param,
653 .get_session_param = iscsi_session_get_param,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300654 .start_conn = iscsi_iser_conn_start,
Mike Christieb40977d2008-05-21 15:54:03 -0500655 .stop_conn = iscsi_iser_conn_stop,
Mike Christie0801c242007-05-30 12:57:12 -0500656 /* iscsi host params */
657 .get_host_param = iscsi_host_get_param,
658 .set_host_param = iscsi_host_set_param,
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300659 /* IO */
660 .send_pdu = iscsi_conn_send_pdu,
661 .get_stats = iscsi_iser_conn_get_stats,
662 .init_cmd_task = iscsi_iser_cmd_init,
663 .xmit_cmd_task = iscsi_iser_ctask_xmit,
664 .xmit_mgmt_task = iscsi_iser_mtask_xmit,
665 .cleanup_cmd_task = iscsi_iser_cleanup_ctask,
666 /* recovery */
667 .session_recovery_timedout = iscsi_session_recovery_timedout,
668
669 .ep_connect = iscsi_iser_ep_connect,
670 .ep_poll = iscsi_iser_ep_poll,
671 .ep_disconnect = iscsi_iser_ep_disconnect
672};
673
674static int __init iser_init(void)
675{
676 int err;
677
678 iser_dbg("Starting iSER datamover...\n");
679
680 if (iscsi_max_lun < 1) {
681 printk(KERN_ERR "Invalid max_lun value of %u\n", iscsi_max_lun);
682 return -EINVAL;
683 }
684
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300685 memset(&ig, 0, sizeof(struct iser_global));
686
687 ig.desc_cache = kmem_cache_create("iser_descriptors",
688 sizeof (struct iser_desc),
689 0, SLAB_HWCACHE_ALIGN,
Paul Mundt20c2df82007-07-20 10:11:58 +0900690 NULL);
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300691 if (ig.desc_cache == NULL)
692 return -ENOMEM;
693
694 /* device init is called only after the first addr resolution */
695 mutex_init(&ig.device_list_mutex);
696 INIT_LIST_HEAD(&ig.device_list);
697 mutex_init(&ig.connlist_mutex);
698 INIT_LIST_HEAD(&ig.connlist);
699
Mike Christie75613522008-05-21 15:53:59 -0500700 iscsi_iser_scsi_transport = iscsi_register_transport(
701 &iscsi_iser_transport);
702 if (!iscsi_iser_scsi_transport) {
Or Gerlitz65e7ae72006-05-11 10:00:44 +0300703 iser_err("iscsi_register_transport failed\n");
704 err = -EINVAL;
705 goto register_transport_failure;
706 }
707
708 return 0;
709
710register_transport_failure:
711 kmem_cache_destroy(ig.desc_cache);
712
713 return err;
714}
715
716static void __exit iser_exit(void)
717{
718 iser_dbg("Removing iSER datamover...\n");
719 iscsi_unregister_transport(&iscsi_iser_transport);
720 kmem_cache_destroy(ig.desc_cache);
721}
722
723module_init(iser_init);
724module_exit(iser_exit);