]>
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; | |
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; | |
127 | error: | |
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 | **/ | |
a8ac6311 | 136 | static int |
65e7ae7b OG |
137 | iscsi_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; | |
65e7ae7b OG |
141 | |
142 | iser_ctask->command_sent = 0; | |
143 | iser_ctask->iser_conn = iser_conn; | |
65e7ae7b | 144 | iser_ctask_rdma_init(iser_ctask); |
a8ac6311 | 145 | return 0; |
65e7ae7b OG |
146 | } |
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 | **/ | |
159 | static int | |
160 | iscsi_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 | */ | |
f0938401 | 175 | if (error && error != -ENOBUFS) |
65e7ae7b OG |
176 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
177 | ||
178 | return error; | |
179 | } | |
180 | ||
181 | static int | |
182 | iscsi_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; | |
65e7ae7b OG |
187 | |
188 | /* Send data-out PDUs while there's still unsolicited data to send */ | |
189 | while (ctask->unsol_count > 0) { | |
ffd0436e | 190 | iscsi_prep_unsolicit_data_pdu(ctask, &hdr); |
65e7ae7b OG |
191 | 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 | ||
206 | iscsi_iser_ctask_xmit_unsol_data_exit: | |
207 | return error; | |
208 | } | |
209 | ||
210 | static int | |
211 | iscsi_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 | ||
77a23c21 | 217 | if (ctask->sc->sc_data_direction == DMA_TO_DEVICE) { |
da9c0c77 | 218 | BUG_ON(scsi_bufflen(ctask->sc) == 0); |
77a23c21 MC |
219 | |
220 | debug_scsi("cmd [itt %x total %d imm %d unsol_data %d\n", | |
da9c0c77 | 221 | ctask->itt, scsi_bufflen(ctask->sc), |
77a23c21 MC |
222 | ctask->imm_count, ctask->unsol_count); |
223 | } | |
224 | ||
65e7ae7b OG |
225 | debug_scsi("ctask deq [cid %d itt 0x%x]\n", |
226 | conn->id, ctask->itt); | |
227 | ||
65e7ae7b OG |
228 | /* 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: | |
f0938401 | 241 | if (error && error != -ENOBUFS) |
65e7ae7b OG |
242 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
243 | return error; | |
244 | } | |
245 | ||
246 | static void | |
247 | iscsi_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 | ||
257 | static struct iser_conn * | |
258 | iscsi_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 | ||
275 | static struct iscsi_cls_conn * | |
276 | iscsi_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 | ||
5d91e209 | 282 | cls_conn = iscsi_conn_setup(cls_session, sizeof(*iser_conn), conn_idx); |
65e7ae7b OG |
283 | 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 | ||
5d91e209 | 293 | iser_conn = conn->dd_data; |
65e7ae7b OG |
294 | /* 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; | |
65e7ae7b OG |
301 | } |
302 | ||
303 | static void | |
304 | iscsi_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; | |
308 | ||
87e8df7a EZ |
309 | if (iser_conn->ib_conn) |
310 | iser_conn->ib_conn->iser_conn = NULL; | |
5d91e209 | 311 | iscsi_conn_teardown(cls_conn); |
65e7ae7b OG |
312 | } |
313 | ||
314 | static int | |
315 | iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session, | |
316 | struct iscsi_cls_conn *cls_conn, uint64_t transport_eph, | |
317 | int is_leading) | |
318 | { | |
319 | struct iscsi_conn *conn = cls_conn->dd_data; | |
320 | struct iscsi_iser_conn *iser_conn; | |
321 | struct iser_conn *ib_conn; | |
322 | int error; | |
323 | ||
324 | error = iscsi_conn_bind(cls_session, cls_conn, is_leading); | |
325 | if (error) | |
326 | return error; | |
327 | ||
328 | /* the transport ep handle comes from user space so it must be | |
329 | * verified against the global ib connections list */ | |
330 | ib_conn = iscsi_iser_ib_conn_lookup(transport_eph); | |
331 | if (!ib_conn) { | |
332 | iser_err("can't bind eph %llx\n", | |
333 | (unsigned long long)transport_eph); | |
334 | return -EINVAL; | |
335 | } | |
336 | /* binds the iSER connection retrieved from the previously | |
337 | * connected ep_handle to the iSCSI layer connection. exchanges | |
338 | * connection pointers */ | |
339 | iser_err("binding iscsi conn %p to iser_conn %p\n",conn,ib_conn); | |
340 | iser_conn = conn->dd_data; | |
341 | ib_conn->iser_conn = iser_conn; | |
342 | iser_conn->ib_conn = ib_conn; | |
343 | ||
344 | conn->recv_lock = &iser_conn->lock; | |
345 | ||
346 | return 0; | |
347 | } | |
348 | ||
349 | static int | |
350 | iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn) | |
351 | { | |
352 | struct iscsi_conn *conn = cls_conn->dd_data; | |
353 | int err; | |
354 | ||
2e7a7426 | 355 | err = iser_conn_set_full_featured_mode(conn); |
65e7ae7b OG |
356 | if (err) |
357 | return err; | |
358 | ||
2e7a7426 | 359 | return iscsi_conn_start(cls_conn); |
65e7ae7b OG |
360 | } |
361 | ||
75613521 MC |
362 | static void iscsi_iser_session_destroy(struct iscsi_cls_session *cls_session) |
363 | { | |
364 | struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); | |
365 | ||
a4804cd6 MC |
366 | iscsi_host_remove(shost); |
367 | iscsi_host_free(shost); | |
75613521 | 368 | } |
65e7ae7b OG |
369 | |
370 | static struct iscsi_cls_session * | |
75613521 MC |
371 | iscsi_iser_session_create(struct Scsi_Host *shost, |
372 | uint16_t cmds_max, uint16_t qdepth, | |
373 | uint32_t initial_cmdsn, uint32_t *hostno) | |
65e7ae7b OG |
374 | { |
375 | struct iscsi_cls_session *cls_session; | |
376 | struct iscsi_session *session; | |
377 | int i; | |
65e7ae7b OG |
378 | struct iscsi_cmd_task *ctask; |
379 | struct iscsi_mgmt_task *mtask; | |
380 | struct iscsi_iser_cmd_task *iser_ctask; | |
381 | struct iser_desc *desc; | |
382 | ||
75613521 MC |
383 | if (shost) { |
384 | printk(KERN_ERR "iscsi_tcp: invalid shost %d.\n", | |
385 | shost->host_no); | |
386 | return NULL; | |
387 | } | |
388 | ||
a4804cd6 | 389 | shost = iscsi_host_alloc(&iscsi_iser_sht, 0, ISCSI_MAX_CMD_PER_LUN); |
75613521 MC |
390 | if (!shost) |
391 | return NULL; | |
392 | shost->transportt = iscsi_iser_scsi_transport; | |
393 | shost->max_lun = iscsi_max_lun; | |
394 | shost->max_id = 0; | |
395 | shost->max_channel = 0; | |
396 | shost->max_cmd_len = 16; | |
397 | ||
a4804cd6 | 398 | if (iscsi_host_add(shost, NULL)) |
75613521 MC |
399 | goto free_host; |
400 | *hostno = shost->host_no; | |
401 | ||
1548271e MC |
402 | /* |
403 | * we do not support setting can_queue cmd_per_lun from userspace yet | |
404 | * because we preallocate so many resources | |
405 | */ | |
75613521 | 406 | cls_session = iscsi_session_setup(&iscsi_iser_transport, shost, |
1548271e | 407 | ISCSI_DEF_XMIT_CMDS_MAX, |
65e7ae7b OG |
408 | sizeof(struct iscsi_iser_cmd_task), |
409 | sizeof(struct iser_desc), | |
75613521 | 410 | initial_cmdsn); |
65e7ae7b | 411 | if (!cls_session) |
75613521 MC |
412 | goto remove_host; |
413 | session = cls_session->dd_data; | |
65e7ae7b | 414 | |
75613521 | 415 | shost->can_queue = session->cmds_max; |
65e7ae7b OG |
416 | /* libiscsi setup itts, data and pool so just set desc fields */ |
417 | for (i = 0; i < session->cmds_max; i++) { | |
418 | ctask = session->cmds[i]; | |
419 | iser_ctask = ctask->dd_data; | |
420 | ctask->hdr = (struct iscsi_cmd *)&iser_ctask->desc.iscsi_header; | |
38ad03de | 421 | ctask->hdr_max = sizeof(iser_ctask->desc.iscsi_header); |
65e7ae7b OG |
422 | } |
423 | ||
424 | for (i = 0; i < session->mgmtpool_max; i++) { | |
425 | mtask = session->mgmt_cmds[i]; | |
426 | desc = mtask->dd_data; | |
427 | mtask->hdr = &desc->iscsi_header; | |
428 | desc->data = mtask->data; | |
429 | } | |
430 | ||
431 | return cls_session; | |
75613521 MC |
432 | |
433 | remove_host: | |
a4804cd6 | 434 | iscsi_host_remove(shost); |
75613521 | 435 | free_host: |
a4804cd6 | 436 | iscsi_host_free(shost); |
75613521 | 437 | return NULL; |
65e7ae7b OG |
438 | } |
439 | ||
440 | static int | |
358ff019 MC |
441 | iscsi_iser_set_param(struct iscsi_cls_conn *cls_conn, |
442 | enum iscsi_param param, char *buf, int buflen) | |
65e7ae7b | 443 | { |
358ff019 | 444 | int value; |
65e7ae7b OG |
445 | |
446 | switch (param) { | |
447 | case ISCSI_PARAM_MAX_RECV_DLENGTH: | |
448 | /* TBD */ | |
449 | break; | |
65e7ae7b | 450 | case ISCSI_PARAM_HDRDGST_EN: |
358ff019 | 451 | sscanf(buf, "%d", &value); |
65e7ae7b OG |
452 | if (value) { |
453 | printk(KERN_ERR "DataDigest wasn't negotiated to None"); | |
454 | return -EPROTO; | |
455 | } | |
456 | break; | |
457 | case ISCSI_PARAM_DATADGST_EN: | |
358ff019 | 458 | sscanf(buf, "%d", &value); |
65e7ae7b OG |
459 | if (value) { |
460 | printk(KERN_ERR "DataDigest wasn't negotiated to None"); | |
461 | return -EPROTO; | |
462 | } | |
463 | break; | |
65e7ae7b | 464 | case ISCSI_PARAM_IFMARKER_EN: |
358ff019 | 465 | sscanf(buf, "%d", &value); |
65e7ae7b OG |
466 | if (value) { |
467 | printk(KERN_ERR "IFMarker wasn't negotiated to No"); | |
468 | return -EPROTO; | |
469 | } | |
470 | break; | |
471 | case ISCSI_PARAM_OFMARKER_EN: | |
358ff019 | 472 | sscanf(buf, "%d", &value); |
65e7ae7b OG |
473 | if (value) { |
474 | printk(KERN_ERR "OFMarker wasn't negotiated to No"); | |
475 | return -EPROTO; | |
476 | } | |
477 | break; | |
478 | default: | |
358ff019 | 479 | return iscsi_set_param(cls_conn, param, buf, buflen); |
65e7ae7b OG |
480 | } |
481 | ||
482 | return 0; | |
483 | } | |
484 | ||
65e7ae7b OG |
485 | static void |
486 | iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats) | |
487 | { | |
488 | struct iscsi_conn *conn = cls_conn->dd_data; | |
489 | ||
490 | stats->txdata_octets = conn->txdata_octets; | |
491 | stats->rxdata_octets = conn->rxdata_octets; | |
492 | stats->scsicmd_pdus = conn->scsicmd_pdus_cnt; | |
493 | stats->dataout_pdus = conn->dataout_pdus_cnt; | |
494 | stats->scsirsp_pdus = conn->scsirsp_pdus_cnt; | |
495 | stats->datain_pdus = conn->datain_pdus_cnt; /* always 0 */ | |
496 | stats->r2t_pdus = conn->r2t_pdus_cnt; /* always 0 */ | |
497 | stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt; | |
498 | stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt; | |
87528227 | 499 | stats->custom_length = 4; |
65e7ae7b OG |
500 | strcpy(stats->custom[0].desc, "qp_tx_queue_full"); |
501 | stats->custom[0].value = 0; /* TB iser_conn->qp_tx_queue_full; */ | |
502 | strcpy(stats->custom[1].desc, "fmr_map_not_avail"); | |
503 | stats->custom[1].value = 0; /* TB iser_conn->fmr_map_not_avail */; | |
504 | strcpy(stats->custom[2].desc, "eh_abort_cnt"); | |
505 | stats->custom[2].value = conn->eh_abort_cnt; | |
87528227 ED |
506 | strcpy(stats->custom[3].desc, "fmr_unalign_cnt"); |
507 | stats->custom[3].value = conn->fmr_unalign_cnt; | |
65e7ae7b OG |
508 | } |
509 | ||
510 | static int | |
511 | iscsi_iser_ep_connect(struct sockaddr *dst_addr, int non_blocking, | |
512 | __u64 *ep_handle) | |
513 | { | |
514 | int err; | |
515 | struct iser_conn *ib_conn; | |
516 | ||
517 | err = iser_conn_init(&ib_conn); | |
518 | if (err) | |
519 | goto out; | |
520 | ||
521 | err = iser_connect(ib_conn, NULL, (struct sockaddr_in *)dst_addr, non_blocking); | |
522 | if (!err) | |
523 | *ep_handle = (__u64)(unsigned long)ib_conn; | |
524 | ||
525 | out: | |
526 | return err; | |
527 | } | |
528 | ||
529 | static int | |
530 | iscsi_iser_ep_poll(__u64 ep_handle, int timeout_ms) | |
531 | { | |
532 | struct iser_conn *ib_conn = iscsi_iser_ib_conn_lookup(ep_handle); | |
533 | int rc; | |
534 | ||
535 | if (!ib_conn) | |
536 | return -EINVAL; | |
537 | ||
538 | rc = wait_event_interruptible_timeout(ib_conn->wait, | |
539 | ib_conn->state == ISER_CONN_UP, | |
540 | msecs_to_jiffies(timeout_ms)); | |
541 | ||
542 | /* if conn establishment failed, return error code to iscsi */ | |
543 | if (!rc && | |
544 | (ib_conn->state == ISER_CONN_TERMINATING || | |
545 | ib_conn->state == ISER_CONN_DOWN)) | |
546 | rc = -1; | |
547 | ||
548 | iser_err("ib conn %p rc = %d\n", ib_conn, rc); | |
549 | ||
550 | if (rc > 0) | |
551 | return 1; /* success, this is the equivalent of POLLOUT */ | |
552 | else if (!rc) | |
553 | return 0; /* timeout */ | |
554 | else | |
555 | return rc; /* signal */ | |
556 | } | |
557 | ||
558 | static void | |
559 | iscsi_iser_ep_disconnect(__u64 ep_handle) | |
560 | { | |
1c83469d | 561 | struct iser_conn *ib_conn; |
65e7ae7b | 562 | |
1c83469d | 563 | ib_conn = iscsi_iser_ib_conn_lookup(ep_handle); |
65e7ae7b OG |
564 | if (!ib_conn) |
565 | return; | |
566 | ||
567 | iser_err("ib conn %p state %d\n",ib_conn, ib_conn->state); | |
65e7ae7b OG |
568 | iser_conn_terminate(ib_conn); |
569 | } | |
570 | ||
571 | static struct scsi_host_template iscsi_iser_sht = { | |
7974392c | 572 | .module = THIS_MODULE, |
65e7ae7b OG |
573 | .name = "iSCSI Initiator over iSER, v." DRV_VER, |
574 | .queuecommand = iscsi_queuecommand, | |
6410627e | 575 | .change_queue_depth = iscsi_change_queue_depth, |
1548271e | 576 | .can_queue = ISCSI_DEF_XMIT_CMDS_MAX - 1, |
65e7ae7b | 577 | .sg_tablesize = ISCSI_ISER_SG_TABLESIZE, |
8072ec2f | 578 | .max_sectors = 1024, |
65e7ae7b OG |
579 | .cmd_per_lun = ISCSI_MAX_CMD_PER_LUN, |
580 | .eh_abort_handler = iscsi_eh_abort, | |
90c18f3c | 581 | .eh_device_reset_handler= iscsi_eh_device_reset, |
65e7ae7b OG |
582 | .eh_host_reset_handler = iscsi_eh_host_reset, |
583 | .use_clustering = DISABLE_CLUSTERING, | |
584 | .proc_name = "iscsi_iser", | |
585 | .this_id = -1, | |
586 | }; | |
587 | ||
588 | static struct iscsi_transport iscsi_iser_transport = { | |
589 | .owner = THIS_MODULE, | |
590 | .name = "iser", | |
591 | .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T, | |
592 | .param_mask = ISCSI_MAX_RECV_DLENGTH | | |
593 | ISCSI_MAX_XMIT_DLENGTH | | |
594 | ISCSI_HDRDGST_EN | | |
595 | ISCSI_DATADGST_EN | | |
596 | ISCSI_INITIAL_R2T_EN | | |
597 | ISCSI_MAX_R2T | | |
598 | ISCSI_IMM_DATA_EN | | |
599 | ISCSI_FIRST_BURST | | |
600 | ISCSI_MAX_BURST | | |
601 | ISCSI_PDU_INORDER_EN | | |
358ff019 MC |
602 | ISCSI_DATASEQ_INORDER_EN | |
603 | ISCSI_EXP_STATSN | | |
604 | ISCSI_PERSISTENT_PORT | | |
605 | ISCSI_PERSISTENT_ADDRESS | | |
b2c64167 MC |
606 | ISCSI_TARGET_NAME | ISCSI_TPGT | |
607 | ISCSI_USERNAME | ISCSI_PASSWORD | | |
f6d5180c MC |
608 | ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN | |
609 | ISCSI_FAST_ABORT | ISCSI_ABORT_TMO | | |
610 | ISCSI_PING_TMO | ISCSI_RECV_TMO, | |
8ad5781a | 611 | .host_param_mask = ISCSI_HOST_HWADDRESS | |
d8196ed2 | 612 | ISCSI_HOST_NETDEV_NAME | |
8ad5781a | 613 | ISCSI_HOST_INITIATOR_NAME, |
65e7ae7b OG |
614 | /* session management */ |
615 | .create_session = iscsi_iser_session_create, | |
75613521 | 616 | .destroy_session = iscsi_iser_session_destroy, |
65e7ae7b OG |
617 | /* connection management */ |
618 | .create_conn = iscsi_iser_conn_create, | |
619 | .bind_conn = iscsi_iser_conn_bind, | |
620 | .destroy_conn = iscsi_iser_conn_destroy, | |
358ff019 MC |
621 | .set_param = iscsi_iser_set_param, |
622 | .get_conn_param = iscsi_conn_get_param, | |
623 | .get_session_param = iscsi_session_get_param, | |
65e7ae7b OG |
624 | .start_conn = iscsi_iser_conn_start, |
625 | .stop_conn = iscsi_conn_stop, | |
0801c242 MC |
626 | /* iscsi host params */ |
627 | .get_host_param = iscsi_host_get_param, | |
628 | .set_host_param = iscsi_host_set_param, | |
65e7ae7b OG |
629 | /* IO */ |
630 | .send_pdu = iscsi_conn_send_pdu, | |
631 | .get_stats = iscsi_iser_conn_get_stats, | |
632 | .init_cmd_task = iscsi_iser_cmd_init, | |
633 | .xmit_cmd_task = iscsi_iser_ctask_xmit, | |
634 | .xmit_mgmt_task = iscsi_iser_mtask_xmit, | |
635 | .cleanup_cmd_task = iscsi_iser_cleanup_ctask, | |
636 | /* recovery */ | |
637 | .session_recovery_timedout = iscsi_session_recovery_timedout, | |
638 | ||
639 | .ep_connect = iscsi_iser_ep_connect, | |
640 | .ep_poll = iscsi_iser_ep_poll, | |
641 | .ep_disconnect = iscsi_iser_ep_disconnect | |
642 | }; | |
643 | ||
644 | static int __init iser_init(void) | |
645 | { | |
646 | int err; | |
647 | ||
648 | iser_dbg("Starting iSER datamover...\n"); | |
649 | ||
650 | if (iscsi_max_lun < 1) { | |
651 | printk(KERN_ERR "Invalid max_lun value of %u\n", iscsi_max_lun); | |
652 | return -EINVAL; | |
653 | } | |
654 | ||
65e7ae7b OG |
655 | memset(&ig, 0, sizeof(struct iser_global)); |
656 | ||
657 | ig.desc_cache = kmem_cache_create("iser_descriptors", | |
658 | sizeof (struct iser_desc), | |
659 | 0, SLAB_HWCACHE_ALIGN, | |
20c2df83 | 660 | NULL); |
65e7ae7b OG |
661 | if (ig.desc_cache == NULL) |
662 | return -ENOMEM; | |
663 | ||
664 | /* device init is called only after the first addr resolution */ | |
665 | mutex_init(&ig.device_list_mutex); | |
666 | INIT_LIST_HEAD(&ig.device_list); | |
667 | mutex_init(&ig.connlist_mutex); | |
668 | INIT_LIST_HEAD(&ig.connlist); | |
669 | ||
75613521 MC |
670 | iscsi_iser_scsi_transport = iscsi_register_transport( |
671 | &iscsi_iser_transport); | |
672 | if (!iscsi_iser_scsi_transport) { | |
65e7ae7b OG |
673 | iser_err("iscsi_register_transport failed\n"); |
674 | err = -EINVAL; | |
675 | goto register_transport_failure; | |
676 | } | |
677 | ||
678 | return 0; | |
679 | ||
680 | register_transport_failure: | |
681 | kmem_cache_destroy(ig.desc_cache); | |
682 | ||
683 | return err; | |
684 | } | |
685 | ||
686 | static void __exit iser_exit(void) | |
687 | { | |
688 | iser_dbg("Removing iSER datamover...\n"); | |
689 | iscsi_unregister_transport(&iscsi_iser_transport); | |
690 | kmem_cache_destroy(ig.desc_cache); | |
691 | } | |
692 | ||
693 | module_init(iser_init); | |
694 | module_exit(iser_exit); |