]>
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 | ||
77 | static unsigned int iscsi_max_lun = 512; | |
78 | module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO); | |
79 | ||
80 | int iser_debug_level = 0; | |
81 | ||
82 | MODULE_DESCRIPTION("iSER (iSCSI Extensions for RDMA) Datamover " | |
83 | "v" DRV_VER " (" DRV_DATE ")"); | |
84 | MODULE_LICENSE("Dual BSD/GPL"); | |
85 | MODULE_AUTHOR("Alex Nezhinsky, Dan Bar Dov, Or Gerlitz"); | |
86 | ||
87 | module_param_named(debug_level, iser_debug_level, int, 0644); | |
88 | MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0 (default:disabled)"); | |
89 | ||
90 | struct iser_global ig; | |
91 | ||
92 | void | |
93 | iscsi_iser_recv(struct iscsi_conn *conn, | |
94 | struct iscsi_hdr *hdr, char *rx_data, int rx_data_len) | |
95 | { | |
96 | int rc = 0; | |
97 | uint32_t ret_itt; | |
98 | int datalen; | |
99 | int ahslen; | |
100 | ||
101 | /* verify PDU length */ | |
102 | datalen = ntoh24(hdr->dlength); | |
103 | if (datalen != rx_data_len) { | |
104 | printk(KERN_ERR "iscsi_iser: datalen %d (hdr) != %d (IB) \n", | |
105 | datalen, rx_data_len); | |
106 | rc = ISCSI_ERR_DATALEN; | |
107 | goto error; | |
108 | } | |
109 | ||
110 | /* read AHS */ | |
111 | ahslen = hdr->hlength * 4; | |
112 | ||
113 | /* verify itt (itt encoding: age+cid+itt) */ | |
114 | rc = iscsi_verify_itt(conn, hdr, &ret_itt); | |
115 | ||
116 | if (!rc) | |
117 | rc = iscsi_complete_pdu(conn, hdr, rx_data, rx_data_len); | |
118 | ||
119 | if (rc && rc != ISCSI_ERR_NO_SCSI_CMD) | |
120 | goto error; | |
121 | ||
122 | return; | |
123 | error: | |
124 | iscsi_conn_failure(conn, rc); | |
125 | } | |
126 | ||
127 | ||
128 | /** | |
129 | * iscsi_iser_cmd_init - Initialize iSCSI SCSI_READ or SCSI_WRITE commands | |
130 | * | |
131 | **/ | |
132 | static void | |
133 | iscsi_iser_cmd_init(struct iscsi_cmd_task *ctask) | |
134 | { | |
135 | struct iscsi_iser_conn *iser_conn = ctask->conn->dd_data; | |
136 | struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data; | |
65e7ae7b OG |
137 | |
138 | iser_ctask->command_sent = 0; | |
139 | iser_ctask->iser_conn = iser_conn; | |
65e7ae7b OG |
140 | iser_ctask_rdma_init(iser_ctask); |
141 | } | |
142 | ||
143 | /** | |
144 | * iscsi_mtask_xmit - xmit management(immediate) task | |
145 | * @conn: iscsi connection | |
146 | * @mtask: task management task | |
147 | * | |
148 | * Notes: | |
149 | * The function can return -EAGAIN in which case caller must | |
150 | * call it again later, or recover. '0' return code means successful | |
151 | * xmit. | |
152 | * | |
153 | **/ | |
154 | static int | |
155 | iscsi_iser_mtask_xmit(struct iscsi_conn *conn, | |
156 | struct iscsi_mgmt_task *mtask) | |
157 | { | |
158 | int error = 0; | |
159 | ||
160 | debug_scsi("mtask deq [cid %d itt 0x%x]\n", conn->id, mtask->itt); | |
161 | ||
162 | error = iser_send_control(conn, mtask); | |
163 | ||
164 | /* since iser xmits control with zero copy, mtasks can not be recycled | |
165 | * right after sending them. | |
166 | * The recycling scheme is based on whether a response is expected | |
167 | * - if yes, the mtask is recycled at iscsi_complete_pdu | |
168 | * - if no, the mtask is recycled at iser_snd_completion | |
169 | */ | |
f0938401 | 170 | if (error && error != -ENOBUFS) |
65e7ae7b OG |
171 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
172 | ||
173 | return error; | |
174 | } | |
175 | ||
176 | static int | |
177 | iscsi_iser_ctask_xmit_unsol_data(struct iscsi_conn *conn, | |
178 | struct iscsi_cmd_task *ctask) | |
179 | { | |
180 | struct iscsi_data hdr; | |
181 | int error = 0; | |
65e7ae7b OG |
182 | |
183 | /* Send data-out PDUs while there's still unsolicited data to send */ | |
184 | while (ctask->unsol_count > 0) { | |
ffd0436e | 185 | iscsi_prep_unsolicit_data_pdu(ctask, &hdr); |
65e7ae7b OG |
186 | debug_scsi("Sending data-out: itt 0x%x, data count %d\n", |
187 | hdr.itt, ctask->data_count); | |
188 | ||
189 | /* the buffer description has been passed with the command */ | |
190 | /* Send the command */ | |
191 | error = iser_send_data_out(conn, ctask, &hdr); | |
192 | if (error) { | |
193 | ctask->unsol_datasn--; | |
194 | goto iscsi_iser_ctask_xmit_unsol_data_exit; | |
195 | } | |
196 | ctask->unsol_count -= ctask->data_count; | |
197 | debug_scsi("Need to send %d more as data-out PDUs\n", | |
198 | ctask->unsol_count); | |
199 | } | |
200 | ||
201 | iscsi_iser_ctask_xmit_unsol_data_exit: | |
202 | return error; | |
203 | } | |
204 | ||
205 | static int | |
206 | iscsi_iser_ctask_xmit(struct iscsi_conn *conn, | |
207 | struct iscsi_cmd_task *ctask) | |
208 | { | |
209 | struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data; | |
210 | int error = 0; | |
211 | ||
77a23c21 | 212 | if (ctask->sc->sc_data_direction == DMA_TO_DEVICE) { |
da9c0c77 | 213 | BUG_ON(scsi_bufflen(ctask->sc) == 0); |
77a23c21 MC |
214 | |
215 | debug_scsi("cmd [itt %x total %d imm %d unsol_data %d\n", | |
da9c0c77 | 216 | ctask->itt, scsi_bufflen(ctask->sc), |
77a23c21 MC |
217 | ctask->imm_count, ctask->unsol_count); |
218 | } | |
219 | ||
65e7ae7b OG |
220 | debug_scsi("ctask deq [cid %d itt 0x%x]\n", |
221 | conn->id, ctask->itt); | |
222 | ||
223 | /* | |
224 | * serialize with TMF AbortTask | |
225 | */ | |
226 | if (ctask->mtask) | |
227 | return error; | |
228 | ||
229 | /* Send the cmd PDU */ | |
230 | if (!iser_ctask->command_sent) { | |
231 | error = iser_send_command(conn, ctask); | |
232 | if (error) | |
233 | goto iscsi_iser_ctask_xmit_exit; | |
234 | iser_ctask->command_sent = 1; | |
235 | } | |
236 | ||
237 | /* Send unsolicited data-out PDU(s) if necessary */ | |
238 | if (ctask->unsol_count) | |
239 | error = iscsi_iser_ctask_xmit_unsol_data(conn, ctask); | |
240 | ||
241 | iscsi_iser_ctask_xmit_exit: | |
f0938401 | 242 | if (error && error != -ENOBUFS) |
65e7ae7b OG |
243 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
244 | return error; | |
245 | } | |
246 | ||
247 | static void | |
248 | iscsi_iser_cleanup_ctask(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) | |
249 | { | |
250 | struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data; | |
251 | ||
252 | if (iser_ctask->status == ISER_TASK_STATUS_STARTED) { | |
253 | iser_ctask->status = ISER_TASK_STATUS_COMPLETED; | |
254 | iser_ctask_rdma_finalize(iser_ctask); | |
255 | } | |
256 | } | |
257 | ||
258 | static struct iser_conn * | |
259 | iscsi_iser_ib_conn_lookup(__u64 ep_handle) | |
260 | { | |
261 | struct iser_conn *ib_conn; | |
262 | struct iser_conn *uib_conn = (struct iser_conn *)(unsigned long)ep_handle; | |
263 | ||
264 | mutex_lock(&ig.connlist_mutex); | |
265 | list_for_each_entry(ib_conn, &ig.connlist, conn_list) { | |
266 | if (ib_conn == uib_conn) { | |
267 | mutex_unlock(&ig.connlist_mutex); | |
268 | return ib_conn; | |
269 | } | |
270 | } | |
271 | mutex_unlock(&ig.connlist_mutex); | |
272 | iser_err("no conn exists for eph %llx\n",(unsigned long long)ep_handle); | |
273 | return NULL; | |
274 | } | |
275 | ||
276 | static struct iscsi_cls_conn * | |
277 | iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx) | |
278 | { | |
279 | struct iscsi_conn *conn; | |
280 | struct iscsi_cls_conn *cls_conn; | |
281 | struct iscsi_iser_conn *iser_conn; | |
282 | ||
283 | cls_conn = iscsi_conn_setup(cls_session, conn_idx); | |
284 | if (!cls_conn) | |
285 | return NULL; | |
286 | conn = cls_conn->dd_data; | |
287 | ||
288 | /* | |
289 | * due to issues with the login code re iser sematics | |
290 | * this not set in iscsi_conn_setup - FIXME | |
291 | */ | |
292 | conn->max_recv_dlength = 128; | |
293 | ||
294 | iser_conn = kzalloc(sizeof(*iser_conn), GFP_KERNEL); | |
295 | if (!iser_conn) | |
296 | goto conn_alloc_fail; | |
297 | ||
298 | /* currently this is the only field which need to be initiated */ | |
299 | rwlock_init(&iser_conn->lock); | |
300 | ||
301 | conn->dd_data = iser_conn; | |
302 | iser_conn->iscsi_conn = conn; | |
303 | ||
304 | return cls_conn; | |
305 | ||
306 | conn_alloc_fail: | |
307 | iscsi_conn_teardown(cls_conn); | |
308 | return NULL; | |
309 | } | |
310 | ||
311 | static void | |
312 | iscsi_iser_conn_destroy(struct iscsi_cls_conn *cls_conn) | |
313 | { | |
314 | struct iscsi_conn *conn = cls_conn->dd_data; | |
315 | struct iscsi_iser_conn *iser_conn = conn->dd_data; | |
316 | ||
317 | iscsi_conn_teardown(cls_conn); | |
87e8df7a EZ |
318 | if (iser_conn->ib_conn) |
319 | iser_conn->ib_conn->iser_conn = NULL; | |
65e7ae7b OG |
320 | kfree(iser_conn); |
321 | } | |
322 | ||
323 | static int | |
324 | iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session, | |
325 | struct iscsi_cls_conn *cls_conn, uint64_t transport_eph, | |
326 | int is_leading) | |
327 | { | |
328 | struct iscsi_conn *conn = cls_conn->dd_data; | |
329 | struct iscsi_iser_conn *iser_conn; | |
330 | struct iser_conn *ib_conn; | |
331 | int error; | |
332 | ||
333 | error = iscsi_conn_bind(cls_session, cls_conn, is_leading); | |
334 | if (error) | |
335 | return error; | |
336 | ||
337 | /* the transport ep handle comes from user space so it must be | |
338 | * verified against the global ib connections list */ | |
339 | ib_conn = iscsi_iser_ib_conn_lookup(transport_eph); | |
340 | if (!ib_conn) { | |
341 | iser_err("can't bind eph %llx\n", | |
342 | (unsigned long long)transport_eph); | |
343 | return -EINVAL; | |
344 | } | |
345 | /* binds the iSER connection retrieved from the previously | |
346 | * connected ep_handle to the iSCSI layer connection. exchanges | |
347 | * connection pointers */ | |
348 | iser_err("binding iscsi conn %p to iser_conn %p\n",conn,ib_conn); | |
349 | iser_conn = conn->dd_data; | |
350 | ib_conn->iser_conn = iser_conn; | |
351 | iser_conn->ib_conn = ib_conn; | |
352 | ||
353 | conn->recv_lock = &iser_conn->lock; | |
354 | ||
355 | return 0; | |
356 | } | |
357 | ||
358 | static int | |
359 | iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn) | |
360 | { | |
361 | struct iscsi_conn *conn = cls_conn->dd_data; | |
362 | int err; | |
363 | ||
2e7a7426 | 364 | err = iser_conn_set_full_featured_mode(conn); |
65e7ae7b OG |
365 | if (err) |
366 | return err; | |
367 | ||
2e7a7426 | 368 | return iscsi_conn_start(cls_conn); |
65e7ae7b OG |
369 | } |
370 | ||
65e7ae7b OG |
371 | static struct iscsi_transport iscsi_iser_transport; |
372 | ||
373 | static struct iscsi_cls_session * | |
374 | iscsi_iser_session_create(struct iscsi_transport *iscsit, | |
375 | struct scsi_transport_template *scsit, | |
1548271e MC |
376 | uint16_t cmds_max, uint16_t qdepth, |
377 | uint32_t initial_cmdsn, uint32_t *hostno) | |
65e7ae7b OG |
378 | { |
379 | struct iscsi_cls_session *cls_session; | |
380 | struct iscsi_session *session; | |
381 | int i; | |
382 | uint32_t hn; | |
383 | struct iscsi_cmd_task *ctask; | |
384 | struct iscsi_mgmt_task *mtask; | |
385 | struct iscsi_iser_cmd_task *iser_ctask; | |
386 | struct iser_desc *desc; | |
387 | ||
1548271e MC |
388 | /* |
389 | * we do not support setting can_queue cmd_per_lun from userspace yet | |
390 | * because we preallocate so many resources | |
391 | */ | |
65e7ae7b | 392 | cls_session = iscsi_session_setup(iscsit, scsit, |
1548271e MC |
393 | ISCSI_DEF_XMIT_CMDS_MAX, |
394 | ISCSI_MAX_CMD_PER_LUN, | |
65e7ae7b OG |
395 | sizeof(struct iscsi_iser_cmd_task), |
396 | sizeof(struct iser_desc), | |
397 | initial_cmdsn, &hn); | |
398 | if (!cls_session) | |
399 | return NULL; | |
400 | ||
401 | *hostno = hn; | |
402 | session = class_to_transport_session(cls_session); | |
403 | ||
404 | /* libiscsi setup itts, data and pool so just set desc fields */ | |
405 | for (i = 0; i < session->cmds_max; i++) { | |
406 | ctask = session->cmds[i]; | |
407 | iser_ctask = ctask->dd_data; | |
408 | ctask->hdr = (struct iscsi_cmd *)&iser_ctask->desc.iscsi_header; | |
409 | } | |
410 | ||
411 | for (i = 0; i < session->mgmtpool_max; i++) { | |
412 | mtask = session->mgmt_cmds[i]; | |
413 | desc = mtask->dd_data; | |
414 | mtask->hdr = &desc->iscsi_header; | |
415 | desc->data = mtask->data; | |
416 | } | |
417 | ||
418 | return cls_session; | |
419 | } | |
420 | ||
421 | static int | |
358ff019 MC |
422 | iscsi_iser_set_param(struct iscsi_cls_conn *cls_conn, |
423 | enum iscsi_param param, char *buf, int buflen) | |
65e7ae7b | 424 | { |
358ff019 | 425 | int value; |
65e7ae7b OG |
426 | |
427 | switch (param) { | |
428 | case ISCSI_PARAM_MAX_RECV_DLENGTH: | |
429 | /* TBD */ | |
430 | break; | |
65e7ae7b | 431 | case ISCSI_PARAM_HDRDGST_EN: |
358ff019 | 432 | sscanf(buf, "%d", &value); |
65e7ae7b OG |
433 | if (value) { |
434 | printk(KERN_ERR "DataDigest wasn't negotiated to None"); | |
435 | return -EPROTO; | |
436 | } | |
437 | break; | |
438 | case ISCSI_PARAM_DATADGST_EN: | |
358ff019 | 439 | sscanf(buf, "%d", &value); |
65e7ae7b OG |
440 | if (value) { |
441 | printk(KERN_ERR "DataDigest wasn't negotiated to None"); | |
442 | return -EPROTO; | |
443 | } | |
444 | break; | |
65e7ae7b | 445 | case ISCSI_PARAM_IFMARKER_EN: |
358ff019 | 446 | sscanf(buf, "%d", &value); |
65e7ae7b OG |
447 | if (value) { |
448 | printk(KERN_ERR "IFMarker wasn't negotiated to No"); | |
449 | return -EPROTO; | |
450 | } | |
451 | break; | |
452 | case ISCSI_PARAM_OFMARKER_EN: | |
358ff019 | 453 | sscanf(buf, "%d", &value); |
65e7ae7b OG |
454 | if (value) { |
455 | printk(KERN_ERR "OFMarker wasn't negotiated to No"); | |
456 | return -EPROTO; | |
457 | } | |
458 | break; | |
459 | default: | |
358ff019 | 460 | return iscsi_set_param(cls_conn, param, buf, buflen); |
65e7ae7b OG |
461 | } |
462 | ||
463 | return 0; | |
464 | } | |
465 | ||
65e7ae7b OG |
466 | static void |
467 | iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats) | |
468 | { | |
469 | struct iscsi_conn *conn = cls_conn->dd_data; | |
470 | ||
471 | stats->txdata_octets = conn->txdata_octets; | |
472 | stats->rxdata_octets = conn->rxdata_octets; | |
473 | stats->scsicmd_pdus = conn->scsicmd_pdus_cnt; | |
474 | stats->dataout_pdus = conn->dataout_pdus_cnt; | |
475 | stats->scsirsp_pdus = conn->scsirsp_pdus_cnt; | |
476 | stats->datain_pdus = conn->datain_pdus_cnt; /* always 0 */ | |
477 | stats->r2t_pdus = conn->r2t_pdus_cnt; /* always 0 */ | |
478 | stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt; | |
479 | stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt; | |
480 | stats->custom_length = 3; | |
481 | strcpy(stats->custom[0].desc, "qp_tx_queue_full"); | |
482 | stats->custom[0].value = 0; /* TB iser_conn->qp_tx_queue_full; */ | |
483 | strcpy(stats->custom[1].desc, "fmr_map_not_avail"); | |
484 | stats->custom[1].value = 0; /* TB iser_conn->fmr_map_not_avail */; | |
485 | strcpy(stats->custom[2].desc, "eh_abort_cnt"); | |
486 | stats->custom[2].value = conn->eh_abort_cnt; | |
487 | } | |
488 | ||
489 | static int | |
490 | iscsi_iser_ep_connect(struct sockaddr *dst_addr, int non_blocking, | |
491 | __u64 *ep_handle) | |
492 | { | |
493 | int err; | |
494 | struct iser_conn *ib_conn; | |
495 | ||
496 | err = iser_conn_init(&ib_conn); | |
497 | if (err) | |
498 | goto out; | |
499 | ||
500 | err = iser_connect(ib_conn, NULL, (struct sockaddr_in *)dst_addr, non_blocking); | |
501 | if (!err) | |
502 | *ep_handle = (__u64)(unsigned long)ib_conn; | |
503 | ||
504 | out: | |
505 | return err; | |
506 | } | |
507 | ||
508 | static int | |
509 | iscsi_iser_ep_poll(__u64 ep_handle, int timeout_ms) | |
510 | { | |
511 | struct iser_conn *ib_conn = iscsi_iser_ib_conn_lookup(ep_handle); | |
512 | int rc; | |
513 | ||
514 | if (!ib_conn) | |
515 | return -EINVAL; | |
516 | ||
517 | rc = wait_event_interruptible_timeout(ib_conn->wait, | |
518 | ib_conn->state == ISER_CONN_UP, | |
519 | msecs_to_jiffies(timeout_ms)); | |
520 | ||
521 | /* if conn establishment failed, return error code to iscsi */ | |
522 | if (!rc && | |
523 | (ib_conn->state == ISER_CONN_TERMINATING || | |
524 | ib_conn->state == ISER_CONN_DOWN)) | |
525 | rc = -1; | |
526 | ||
527 | iser_err("ib conn %p rc = %d\n", ib_conn, rc); | |
528 | ||
529 | if (rc > 0) | |
530 | return 1; /* success, this is the equivalent of POLLOUT */ | |
531 | else if (!rc) | |
532 | return 0; /* timeout */ | |
533 | else | |
534 | return rc; /* signal */ | |
535 | } | |
536 | ||
537 | static void | |
538 | iscsi_iser_ep_disconnect(__u64 ep_handle) | |
539 | { | |
1c83469d | 540 | struct iser_conn *ib_conn; |
65e7ae7b | 541 | |
1c83469d | 542 | ib_conn = iscsi_iser_ib_conn_lookup(ep_handle); |
65e7ae7b OG |
543 | if (!ib_conn) |
544 | return; | |
545 | ||
546 | iser_err("ib conn %p state %d\n",ib_conn, ib_conn->state); | |
65e7ae7b OG |
547 | iser_conn_terminate(ib_conn); |
548 | } | |
549 | ||
550 | static struct scsi_host_template iscsi_iser_sht = { | |
7974392c | 551 | .module = THIS_MODULE, |
65e7ae7b OG |
552 | .name = "iSCSI Initiator over iSER, v." DRV_VER, |
553 | .queuecommand = iscsi_queuecommand, | |
1548271e | 554 | .can_queue = ISCSI_DEF_XMIT_CMDS_MAX - 1, |
65e7ae7b | 555 | .sg_tablesize = ISCSI_ISER_SG_TABLESIZE, |
8072ec2f | 556 | .max_sectors = 1024, |
65e7ae7b OG |
557 | .cmd_per_lun = ISCSI_MAX_CMD_PER_LUN, |
558 | .eh_abort_handler = iscsi_eh_abort, | |
559 | .eh_host_reset_handler = iscsi_eh_host_reset, | |
560 | .use_clustering = DISABLE_CLUSTERING, | |
561 | .proc_name = "iscsi_iser", | |
562 | .this_id = -1, | |
563 | }; | |
564 | ||
565 | static struct iscsi_transport iscsi_iser_transport = { | |
566 | .owner = THIS_MODULE, | |
567 | .name = "iser", | |
568 | .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T, | |
569 | .param_mask = ISCSI_MAX_RECV_DLENGTH | | |
570 | ISCSI_MAX_XMIT_DLENGTH | | |
571 | ISCSI_HDRDGST_EN | | |
572 | ISCSI_DATADGST_EN | | |
573 | ISCSI_INITIAL_R2T_EN | | |
574 | ISCSI_MAX_R2T | | |
575 | ISCSI_IMM_DATA_EN | | |
576 | ISCSI_FIRST_BURST | | |
577 | ISCSI_MAX_BURST | | |
578 | ISCSI_PDU_INORDER_EN | | |
358ff019 MC |
579 | ISCSI_DATASEQ_INORDER_EN | |
580 | ISCSI_EXP_STATSN | | |
581 | ISCSI_PERSISTENT_PORT | | |
582 | ISCSI_PERSISTENT_ADDRESS | | |
b2c64167 MC |
583 | ISCSI_TARGET_NAME | ISCSI_TPGT | |
584 | ISCSI_USERNAME | ISCSI_PASSWORD | | |
585 | ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN, | |
8ad5781a | 586 | .host_param_mask = ISCSI_HOST_HWADDRESS | |
d8196ed2 | 587 | ISCSI_HOST_NETDEV_NAME | |
8ad5781a | 588 | ISCSI_HOST_INITIATOR_NAME, |
65e7ae7b OG |
589 | .host_template = &iscsi_iser_sht, |
590 | .conndata_size = sizeof(struct iscsi_conn), | |
591 | .max_lun = ISCSI_ISER_MAX_LUN, | |
592 | .max_cmd_len = ISCSI_ISER_MAX_CMD_LEN, | |
593 | /* session management */ | |
594 | .create_session = iscsi_iser_session_create, | |
595 | .destroy_session = iscsi_session_teardown, | |
596 | /* connection management */ | |
597 | .create_conn = iscsi_iser_conn_create, | |
598 | .bind_conn = iscsi_iser_conn_bind, | |
599 | .destroy_conn = iscsi_iser_conn_destroy, | |
358ff019 MC |
600 | .set_param = iscsi_iser_set_param, |
601 | .get_conn_param = iscsi_conn_get_param, | |
602 | .get_session_param = iscsi_session_get_param, | |
65e7ae7b OG |
603 | .start_conn = iscsi_iser_conn_start, |
604 | .stop_conn = iscsi_conn_stop, | |
0801c242 MC |
605 | /* iscsi host params */ |
606 | .get_host_param = iscsi_host_get_param, | |
607 | .set_host_param = iscsi_host_set_param, | |
65e7ae7b OG |
608 | /* IO */ |
609 | .send_pdu = iscsi_conn_send_pdu, | |
610 | .get_stats = iscsi_iser_conn_get_stats, | |
611 | .init_cmd_task = iscsi_iser_cmd_init, | |
612 | .xmit_cmd_task = iscsi_iser_ctask_xmit, | |
613 | .xmit_mgmt_task = iscsi_iser_mtask_xmit, | |
614 | .cleanup_cmd_task = iscsi_iser_cleanup_ctask, | |
615 | /* recovery */ | |
616 | .session_recovery_timedout = iscsi_session_recovery_timedout, | |
617 | ||
618 | .ep_connect = iscsi_iser_ep_connect, | |
619 | .ep_poll = iscsi_iser_ep_poll, | |
620 | .ep_disconnect = iscsi_iser_ep_disconnect | |
621 | }; | |
622 | ||
623 | static int __init iser_init(void) | |
624 | { | |
625 | int err; | |
626 | ||
627 | iser_dbg("Starting iSER datamover...\n"); | |
628 | ||
629 | if (iscsi_max_lun < 1) { | |
630 | printk(KERN_ERR "Invalid max_lun value of %u\n", iscsi_max_lun); | |
631 | return -EINVAL; | |
632 | } | |
633 | ||
634 | iscsi_iser_transport.max_lun = iscsi_max_lun; | |
635 | ||
636 | memset(&ig, 0, sizeof(struct iser_global)); | |
637 | ||
638 | ig.desc_cache = kmem_cache_create("iser_descriptors", | |
639 | sizeof (struct iser_desc), | |
640 | 0, SLAB_HWCACHE_ALIGN, | |
20c2df83 | 641 | NULL); |
65e7ae7b OG |
642 | if (ig.desc_cache == NULL) |
643 | return -ENOMEM; | |
644 | ||
645 | /* device init is called only after the first addr resolution */ | |
646 | mutex_init(&ig.device_list_mutex); | |
647 | INIT_LIST_HEAD(&ig.device_list); | |
648 | mutex_init(&ig.connlist_mutex); | |
649 | INIT_LIST_HEAD(&ig.connlist); | |
650 | ||
651 | if (!iscsi_register_transport(&iscsi_iser_transport)) { | |
652 | iser_err("iscsi_register_transport failed\n"); | |
653 | err = -EINVAL; | |
654 | goto register_transport_failure; | |
655 | } | |
656 | ||
657 | return 0; | |
658 | ||
659 | register_transport_failure: | |
660 | kmem_cache_destroy(ig.desc_cache); | |
661 | ||
662 | return err; | |
663 | } | |
664 | ||
665 | static void __exit iser_exit(void) | |
666 | { | |
667 | iser_dbg("Removing iSER datamover...\n"); | |
668 | iscsi_unregister_transport(&iscsi_iser_transport); | |
669 | kmem_cache_destroy(ig.desc_cache); | |
670 | } | |
671 | ||
672 | module_init(iser_init); | |
673 | module_exit(iser_exit); |