]>
Commit | Line | Data |
---|---|---|
65e7ae7b OG |
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 | * $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> | |
65e7ae7b OG |
57 | #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 | ||
75613521 MC |
77 | static struct scsi_host_template iscsi_iser_sht; |
78 | static struct iscsi_transport iscsi_iser_transport; | |
79 | static struct scsi_transport_template *iscsi_iser_scsi_transport; | |
80 | ||
65e7ae7b OG |
81 | static unsigned int iscsi_max_lun = 512; |
82 | module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO); | |
83 | ||
84 | int iser_debug_level = 0; | |
85 | ||
86 | MODULE_DESCRIPTION("iSER (iSCSI Extensions for RDMA) Datamover " | |
87 | "v" DRV_VER " (" DRV_DATE ")"); | |
88 | MODULE_LICENSE("Dual BSD/GPL"); | |
89 | MODULE_AUTHOR("Alex Nezhinsky, Dan Bar Dov, Or Gerlitz"); | |
90 | ||
91 | module_param_named(debug_level, iser_debug_level, int, 0644); | |
92 | MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0 (default:disabled)"); | |
93 | ||
94 | struct iser_global ig; | |
95 | ||
96 | void | |
97 | iscsi_iser_recv(struct iscsi_conn *conn, | |
98 | struct iscsi_hdr *hdr, char *rx_data, int rx_data_len) | |
99 | { | |
100 | int rc = 0; | |
65e7ae7b OG |
101 | 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 | ||
0af967f5 | 116 | rc = iscsi_complete_pdu(conn, hdr, rx_data, rx_data_len); |
65e7ae7b OG |
117 | if (rc && rc != ISCSI_ERR_NO_SCSI_CMD) |
118 | goto error; | |
119 | ||
120 | return; | |
121 | error: | |
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 | **/ | |
a8ac6311 | 130 | static int |
65e7ae7b OG |
131 | iscsi_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; | |
65e7ae7b OG |
135 | |
136 | iser_ctask->command_sent = 0; | |
137 | iser_ctask->iser_conn = iser_conn; | |
65e7ae7b | 138 | iser_ctask_rdma_init(iser_ctask); |
a8ac6311 | 139 | return 0; |
65e7ae7b OG |
140 | } |
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 | **/ | |
153 | static int | |
154 | iscsi_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 | */ | |
f0938401 | 169 | if (error && error != -ENOBUFS) |
65e7ae7b OG |
170 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
171 | ||
172 | return error; | |
173 | } | |
174 | ||
175 | static int | |
176 | iscsi_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; | |
65e7ae7b OG |
181 | |
182 | /* Send data-out PDUs while there's still unsolicited data to send */ | |
183 | while (ctask->unsol_count > 0) { | |
ffd0436e | 184 | iscsi_prep_unsolicit_data_pdu(ctask, &hdr); |
65e7ae7b OG |
185 | 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 | ||
200 | iscsi_iser_ctask_xmit_unsol_data_exit: | |
201 | return error; | |
202 | } | |
203 | ||
204 | static int | |
205 | iscsi_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 | ||
77a23c21 | 211 | if (ctask->sc->sc_data_direction == DMA_TO_DEVICE) { |
da9c0c77 | 212 | BUG_ON(scsi_bufflen(ctask->sc) == 0); |
77a23c21 MC |
213 | |
214 | debug_scsi("cmd [itt %x total %d imm %d unsol_data %d\n", | |
da9c0c77 | 215 | ctask->itt, scsi_bufflen(ctask->sc), |
77a23c21 MC |
216 | ctask->imm_count, ctask->unsol_count); |
217 | } | |
218 | ||
65e7ae7b OG |
219 | debug_scsi("ctask deq [cid %d itt 0x%x]\n", |
220 | conn->id, ctask->itt); | |
221 | ||
65e7ae7b OG |
222 | /* 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: | |
f0938401 | 235 | if (error && error != -ENOBUFS) |
65e7ae7b OG |
236 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
237 | return error; | |
238 | } | |
239 | ||
240 | static void | |
241 | iscsi_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 | ||
251 | static struct iser_conn * | |
252 | iscsi_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 | ||
269 | static struct iscsi_cls_conn * | |
270 | iscsi_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 | ||
5d91e209 | 276 | cls_conn = iscsi_conn_setup(cls_session, sizeof(*iser_conn), conn_idx); |
65e7ae7b OG |
277 | 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 | ||
5d91e209 | 287 | iser_conn = conn->dd_data; |
65e7ae7b OG |
288 | /* 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; | |
65e7ae7b OG |
295 | } |
296 | ||
297 | static void | |
298 | iscsi_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; | |
b40977d9 | 302 | struct iser_conn *ib_conn = iser_conn->ib_conn; |
65e7ae7b | 303 | |
5d91e209 | 304 | iscsi_conn_teardown(cls_conn); |
b40977d9 MC |
305 | /* |
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 | } | |
65e7ae7b OG |
314 | } |
315 | ||
316 | static int | |
317 | iscsi_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; | |
b40977d9 | 345 | iser_conn_get(ib_conn); |
65e7ae7b OG |
346 | |
347 | conn->recv_lock = &iser_conn->lock; | |
348 | ||
349 | return 0; | |
350 | } | |
351 | ||
b40977d9 MC |
352 | static void |
353 | iscsi_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 | ||
65e7ae7b OG |
368 | static int |
369 | iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn) | |
370 | { | |
371 | struct iscsi_conn *conn = cls_conn->dd_data; | |
372 | int err; | |
373 | ||
2e7a7426 | 374 | err = iser_conn_set_full_featured_mode(conn); |
65e7ae7b OG |
375 | if (err) |
376 | return err; | |
377 | ||
2e7a7426 | 378 | return iscsi_conn_start(cls_conn); |
65e7ae7b OG |
379 | } |
380 | ||
75613521 MC |
381 | static void iscsi_iser_session_destroy(struct iscsi_cls_session *cls_session) |
382 | { | |
383 | struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); | |
384 | ||
a4804cd6 MC |
385 | iscsi_host_remove(shost); |
386 | iscsi_host_free(shost); | |
75613521 | 387 | } |
65e7ae7b OG |
388 | |
389 | static struct iscsi_cls_session * | |
75613521 MC |
390 | iscsi_iser_session_create(struct Scsi_Host *shost, |
391 | uint16_t cmds_max, uint16_t qdepth, | |
392 | uint32_t initial_cmdsn, uint32_t *hostno) | |
65e7ae7b OG |
393 | { |
394 | struct iscsi_cls_session *cls_session; | |
395 | struct iscsi_session *session; | |
396 | int i; | |
65e7ae7b OG |
397 | 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 | ||
75613521 MC |
402 | if (shost) { |
403 | printk(KERN_ERR "iscsi_tcp: invalid shost %d.\n", | |
404 | shost->host_no); | |
405 | return NULL; | |
406 | } | |
407 | ||
a4804cd6 | 408 | shost = iscsi_host_alloc(&iscsi_iser_sht, 0, ISCSI_MAX_CMD_PER_LUN); |
75613521 MC |
409 | 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 | ||
a4804cd6 | 417 | if (iscsi_host_add(shost, NULL)) |
75613521 MC |
418 | goto free_host; |
419 | *hostno = shost->host_no; | |
420 | ||
1548271e MC |
421 | /* |
422 | * we do not support setting can_queue cmd_per_lun from userspace yet | |
423 | * because we preallocate so many resources | |
424 | */ | |
75613521 | 425 | cls_session = iscsi_session_setup(&iscsi_iser_transport, shost, |
1548271e | 426 | ISCSI_DEF_XMIT_CMDS_MAX, |
65e7ae7b OG |
427 | sizeof(struct iscsi_iser_cmd_task), |
428 | sizeof(struct iser_desc), | |
75613521 | 429 | initial_cmdsn); |
65e7ae7b | 430 | if (!cls_session) |
75613521 MC |
431 | goto remove_host; |
432 | session = cls_session->dd_data; | |
65e7ae7b | 433 | |
75613521 | 434 | shost->can_queue = session->cmds_max; |
65e7ae7b OG |
435 | /* 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; | |
38ad03de | 440 | ctask->hdr_max = sizeof(iser_ctask->desc.iscsi_header); |
65e7ae7b OG |
441 | } |
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; | |
75613521 MC |
451 | |
452 | remove_host: | |
a4804cd6 | 453 | iscsi_host_remove(shost); |
75613521 | 454 | free_host: |
a4804cd6 | 455 | iscsi_host_free(shost); |
75613521 | 456 | return NULL; |
65e7ae7b OG |
457 | } |
458 | ||
459 | static int | |
358ff019 MC |
460 | iscsi_iser_set_param(struct iscsi_cls_conn *cls_conn, |
461 | enum iscsi_param param, char *buf, int buflen) | |
65e7ae7b | 462 | { |
358ff019 | 463 | int value; |
65e7ae7b OG |
464 | |
465 | switch (param) { | |
466 | case ISCSI_PARAM_MAX_RECV_DLENGTH: | |
467 | /* TBD */ | |
468 | break; | |
65e7ae7b | 469 | case ISCSI_PARAM_HDRDGST_EN: |
358ff019 | 470 | sscanf(buf, "%d", &value); |
65e7ae7b OG |
471 | if (value) { |
472 | printk(KERN_ERR "DataDigest wasn't negotiated to None"); | |
473 | return -EPROTO; | |
474 | } | |
475 | break; | |
476 | case ISCSI_PARAM_DATADGST_EN: | |
358ff019 | 477 | sscanf(buf, "%d", &value); |
65e7ae7b OG |
478 | if (value) { |
479 | printk(KERN_ERR "DataDigest wasn't negotiated to None"); | |
480 | return -EPROTO; | |
481 | } | |
482 | break; | |
65e7ae7b | 483 | case ISCSI_PARAM_IFMARKER_EN: |
358ff019 | 484 | sscanf(buf, "%d", &value); |
65e7ae7b OG |
485 | if (value) { |
486 | printk(KERN_ERR "IFMarker wasn't negotiated to No"); | |
487 | return -EPROTO; | |
488 | } | |
489 | break; | |
490 | case ISCSI_PARAM_OFMARKER_EN: | |
358ff019 | 491 | sscanf(buf, "%d", &value); |
65e7ae7b OG |
492 | if (value) { |
493 | printk(KERN_ERR "OFMarker wasn't negotiated to No"); | |
494 | return -EPROTO; | |
495 | } | |
496 | break; | |
497 | default: | |
358ff019 | 498 | return iscsi_set_param(cls_conn, param, buf, buflen); |
65e7ae7b OG |
499 | } |
500 | ||
501 | return 0; | |
502 | } | |
503 | ||
65e7ae7b OG |
504 | static void |
505 | iscsi_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; | |
87528227 | 518 | stats->custom_length = 4; |
65e7ae7b OG |
519 | 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; | |
87528227 ED |
525 | strcpy(stats->custom[3].desc, "fmr_unalign_cnt"); |
526 | stats->custom[3].value = conn->fmr_unalign_cnt; | |
65e7ae7b OG |
527 | } |
528 | ||
529 | static int | |
530 | iscsi_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 | ||
544 | out: | |
545 | return err; | |
546 | } | |
547 | ||
548 | static int | |
549 | iscsi_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 | ||
577 | static void | |
578 | iscsi_iser_ep_disconnect(__u64 ep_handle) | |
579 | { | |
1c83469d | 580 | struct iser_conn *ib_conn; |
65e7ae7b | 581 | |
1c83469d | 582 | ib_conn = iscsi_iser_ib_conn_lookup(ep_handle); |
65e7ae7b OG |
583 | if (!ib_conn) |
584 | return; | |
585 | ||
b40977d9 MC |
586 | 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 | ||
65e7ae7b | 597 | iser_err("ib conn %p state %d\n",ib_conn, ib_conn->state); |
65e7ae7b OG |
598 | iser_conn_terminate(ib_conn); |
599 | } | |
600 | ||
601 | static struct scsi_host_template iscsi_iser_sht = { | |
7974392c | 602 | .module = THIS_MODULE, |
65e7ae7b OG |
603 | .name = "iSCSI Initiator over iSER, v." DRV_VER, |
604 | .queuecommand = iscsi_queuecommand, | |
6410627e | 605 | .change_queue_depth = iscsi_change_queue_depth, |
1548271e | 606 | .can_queue = ISCSI_DEF_XMIT_CMDS_MAX - 1, |
65e7ae7b | 607 | .sg_tablesize = ISCSI_ISER_SG_TABLESIZE, |
8072ec2f | 608 | .max_sectors = 1024, |
65e7ae7b OG |
609 | .cmd_per_lun = ISCSI_MAX_CMD_PER_LUN, |
610 | .eh_abort_handler = iscsi_eh_abort, | |
90c18f3c | 611 | .eh_device_reset_handler= iscsi_eh_device_reset, |
65e7ae7b OG |
612 | .eh_host_reset_handler = iscsi_eh_host_reset, |
613 | .use_clustering = DISABLE_CLUSTERING, | |
614 | .proc_name = "iscsi_iser", | |
615 | .this_id = -1, | |
616 | }; | |
617 | ||
618 | static 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 | | |
358ff019 MC |
632 | ISCSI_DATASEQ_INORDER_EN | |
633 | ISCSI_EXP_STATSN | | |
634 | ISCSI_PERSISTENT_PORT | | |
635 | ISCSI_PERSISTENT_ADDRESS | | |
b2c64167 MC |
636 | ISCSI_TARGET_NAME | ISCSI_TPGT | |
637 | ISCSI_USERNAME | ISCSI_PASSWORD | | |
f6d5180c MC |
638 | ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN | |
639 | ISCSI_FAST_ABORT | ISCSI_ABORT_TMO | | |
640 | ISCSI_PING_TMO | ISCSI_RECV_TMO, | |
8ad5781a | 641 | .host_param_mask = ISCSI_HOST_HWADDRESS | |
d8196ed2 | 642 | ISCSI_HOST_NETDEV_NAME | |
8ad5781a | 643 | ISCSI_HOST_INITIATOR_NAME, |
65e7ae7b OG |
644 | /* session management */ |
645 | .create_session = iscsi_iser_session_create, | |
75613521 | 646 | .destroy_session = iscsi_iser_session_destroy, |
65e7ae7b OG |
647 | /* connection management */ |
648 | .create_conn = iscsi_iser_conn_create, | |
649 | .bind_conn = iscsi_iser_conn_bind, | |
650 | .destroy_conn = iscsi_iser_conn_destroy, | |
358ff019 MC |
651 | .set_param = iscsi_iser_set_param, |
652 | .get_conn_param = iscsi_conn_get_param, | |
653 | .get_session_param = iscsi_session_get_param, | |
65e7ae7b | 654 | .start_conn = iscsi_iser_conn_start, |
b40977d9 | 655 | .stop_conn = iscsi_iser_conn_stop, |
0801c242 MC |
656 | /* iscsi host params */ |
657 | .get_host_param = iscsi_host_get_param, | |
658 | .set_host_param = iscsi_host_set_param, | |
65e7ae7b OG |
659 | /* 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 | ||
674 | static 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 | ||
65e7ae7b OG |
685 | 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, | |
20c2df83 | 690 | NULL); |
65e7ae7b OG |
691 | 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 | ||
75613521 MC |
700 | iscsi_iser_scsi_transport = iscsi_register_transport( |
701 | &iscsi_iser_transport); | |
702 | if (!iscsi_iser_scsi_transport) { | |
65e7ae7b OG |
703 | iser_err("iscsi_register_transport failed\n"); |
704 | err = -EINVAL; | |
705 | goto register_transport_failure; | |
706 | } | |
707 | ||
708 | return 0; | |
709 | ||
710 | register_transport_failure: | |
711 | kmem_cache_destroy(ig.desc_cache); | |
712 | ||
713 | return err; | |
714 | } | |
715 | ||
716 | static 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 | ||
723 | module_init(iser_init); | |
724 | module_exit(iser_exit); |