SCSI/libiscsi: Add check_protection callback for transports
[deliverable/linux.git] / drivers / infiniband / ulp / iser / iscsi_iser.c
CommitLineData
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.
28f292e8 8 * Copyright (c) 2013 Mellanox Technologies. All rights reserved.
65e7ae7b
OG
9 * maintained by openib-general@openib.org
10 *
11 * This software is available to you under a choice of one of two
12 * licenses. You may choose to be licensed under the terms of the GNU
13 * General Public License (GPL) Version 2, available from the file
14 * COPYING in the main directory of this source tree, or the
15 * OpenIB.org BSD license below:
16 *
17 * Redistribution and use in source and binary forms, with or
18 * without modification, are permitted provided that the following
19 * conditions are met:
20 *
21 * - Redistributions of source code must retain the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer.
24 *
25 * - Redistributions in binary form must reproduce the above
26 * copyright notice, this list of conditions and the following
27 * disclaimer in the documentation and/or other materials
28 * provided with the distribution.
29 *
30 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
34 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
35 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
36 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 * SOFTWARE.
38 *
39 * Credits:
40 * Christoph Hellwig
41 * FUJITA Tomonori
42 * Arne Redlich
43 * Zhenyu Wang
44 * Modified by:
45 * Erez Zilber
65e7ae7b
OG
46 */
47
48#include <linux/types.h>
49#include <linux/list.h>
50#include <linux/hardirq.h>
51#include <linux/kfifo.h>
52#include <linux/blkdev.h>
53#include <linux/init.h>
54#include <linux/ioctl.h>
65e7ae7b
OG
55#include <linux/cdev.h>
56#include <linux/in.h>
57#include <linux/net.h>
58#include <linux/scatterlist.h>
59#include <linux/delay.h>
5a0e3ad6 60#include <linux/slab.h>
e4dd23d7 61#include <linux/module.h>
65e7ae7b
OG
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
77static struct scsi_host_template iscsi_iser_sht;
78static struct iscsi_transport iscsi_iser_transport;
79static struct scsi_transport_template *iscsi_iser_scsi_transport;
80
65e7ae7b
OG
81static unsigned int iscsi_max_lun = 512;
82module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
83
84int iser_debug_level = 0;
7f733847
AT
85bool iser_pi_enable = false;
86int iser_pi_guard = 0;
65e7ae7b 87
c1d786e6 88MODULE_DESCRIPTION("iSER (iSCSI Extensions for RDMA) Datamover");
65e7ae7b
OG
89MODULE_LICENSE("Dual BSD/GPL");
90MODULE_AUTHOR("Alex Nezhinsky, Dan Bar Dov, Or Gerlitz");
c1d786e6 91MODULE_VERSION(DRV_VER);
65e7ae7b
OG
92
93module_param_named(debug_level, iser_debug_level, int, 0644);
94MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0 (default:disabled)");
95
7f733847
AT
96module_param_named(pi_enable, iser_pi_enable, bool, 0644);
97MODULE_PARM_DESC(pi_enable, "Enable T10-PI offload support (default:disabled)");
98
99module_param_named(pi_guard, iser_pi_guard, int, 0644);
100MODULE_PARM_DESC(pi_guard, "T10-PI guard_type, 0:CRC|1:IP_CSUM (default:CRC)");
101
65e7ae7b
OG
102struct iser_global ig;
103
104void
105iscsi_iser_recv(struct iscsi_conn *conn,
106 struct iscsi_hdr *hdr, char *rx_data, int rx_data_len)
107{
108 int rc = 0;
65e7ae7b
OG
109 int datalen;
110 int ahslen;
111
112 /* verify PDU length */
113 datalen = ntoh24(hdr->dlength);
200ae1a0
OG
114 if (datalen > rx_data_len || (datalen + 4) < rx_data_len) {
115 iser_err("wrong datalen %d (hdr), %d (IB)\n",
116 datalen, rx_data_len);
65e7ae7b
OG
117 rc = ISCSI_ERR_DATALEN;
118 goto error;
119 }
120
200ae1a0
OG
121 if (datalen != rx_data_len)
122 iser_dbg("aligned datalen (%d) hdr, %d (IB)\n",
123 datalen, rx_data_len);
124
65e7ae7b
OG
125 /* read AHS */
126 ahslen = hdr->hlength * 4;
127
0af967f5 128 rc = iscsi_complete_pdu(conn, hdr, rx_data, rx_data_len);
65e7ae7b
OG
129 if (rc && rc != ISCSI_ERR_NO_SCSI_CMD)
130 goto error;
131
132 return;
133error:
134 iscsi_conn_failure(conn, rc);
135}
136
2ff79d52 137static int iscsi_iser_pdu_alloc(struct iscsi_task *task, uint8_t opcode)
0f9c7449
MC
138{
139 struct iscsi_iser_task *iser_task = task->dd_data;
140
141 task->hdr = (struct iscsi_hdr *)&iser_task->desc.iscsi_header;
142 task->hdr_max = sizeof(iser_task->desc.iscsi_header);
143 return 0;
144}
65e7ae7b 145
f19624aa
OG
146int iser_initialize_task_headers(struct iscsi_task *task,
147 struct iser_tx_desc *tx_desc)
148{
149 struct iscsi_iser_conn *iser_conn = task->conn->dd_data;
150 struct iser_device *device = iser_conn->ib_conn->device;
151 struct iscsi_iser_task *iser_task = task->dd_data;
152 u64 dma_addr;
153
154 dma_addr = ib_dma_map_single(device->ib_device, (void *)tx_desc,
155 ISER_HEADERS_LEN, DMA_TO_DEVICE);
156 if (ib_dma_mapping_error(device->ib_device, dma_addr))
157 return -ENOMEM;
158
159 tx_desc->dma_addr = dma_addr;
160 tx_desc->tx_sg[0].addr = tx_desc->dma_addr;
161 tx_desc->tx_sg[0].length = ISER_HEADERS_LEN;
162 tx_desc->tx_sg[0].lkey = device->mr->lkey;
163
f19624aa
OG
164 iser_task->iser_conn = iser_conn;
165 return 0;
166}
65e7ae7b 167/**
2261ec3d
MC
168 * iscsi_iser_task_init - Initialize task
169 * @task: iscsi task
65e7ae7b 170 *
2261ec3d 171 * Initialize the task for the scsi command or mgmt command.
2747fdb2 172 */
a8ac6311 173static int
2261ec3d 174iscsi_iser_task_init(struct iscsi_task *task)
65e7ae7b 175{
2261ec3d 176 struct iscsi_iser_task *iser_task = task->dd_data;
65e7ae7b 177
52439540 178 if (iser_initialize_task_headers(task, &iser_task->desc))
f19624aa
OG
179 return -ENOMEM;
180
2261ec3d 181 /* mgmt task */
f19624aa 182 if (!task->sc)
2747fdb2 183 return 0;
65e7ae7b 184
2261ec3d 185 iser_task->command_sent = 0;
2261ec3d 186 iser_task_rdma_init(iser_task);
177e31bd
SG
187 iser_task->sc = task->sc;
188
a8ac6311 189 return 0;
65e7ae7b
OG
190}
191
192/**
2261ec3d 193 * iscsi_iser_mtask_xmit - xmit management(immediate) task
65e7ae7b 194 * @conn: iscsi connection
2261ec3d 195 * @task: task management task
65e7ae7b
OG
196 *
197 * Notes:
198 * The function can return -EAGAIN in which case caller must
199 * call it again later, or recover. '0' return code means successful
200 * xmit.
201 *
202 **/
203static int
2261ec3d 204iscsi_iser_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
65e7ae7b
OG
205{
206 int error = 0;
207
962b4b52 208 iser_dbg("mtask xmit [cid %d itt 0x%x]\n", conn->id, task->itt);
65e7ae7b 209
2261ec3d 210 error = iser_send_control(conn, task);
65e7ae7b 211
2261ec3d 212 /* since iser xmits control with zero copy, tasks can not be recycled
65e7ae7b
OG
213 * right after sending them.
214 * The recycling scheme is based on whether a response is expected
2261ec3d
MC
215 * - if yes, the task is recycled at iscsi_complete_pdu
216 * - if no, the task is recycled at iser_snd_completion
65e7ae7b 217 */
65e7ae7b
OG
218 return error;
219}
220
221static int
2747fdb2 222iscsi_iser_task_xmit_unsol_data(struct iscsi_conn *conn,
2261ec3d 223 struct iscsi_task *task)
65e7ae7b 224{
0f9c7449
MC
225 struct iscsi_r2t_info *r2t = &task->unsol_r2t;
226 struct iscsi_data hdr;
65e7ae7b 227 int error = 0;
65e7ae7b
OG
228
229 /* Send data-out PDUs while there's still unsolicited data to send */
0f9c7449
MC
230 while (iscsi_task_has_unsol_data(task)) {
231 iscsi_prep_data_out_pdu(task, r2t, &hdr);
48a237a2 232 iser_dbg("Sending data-out: itt 0x%x, data count %d\n",
0f9c7449 233 hdr.itt, r2t->data_count);
65e7ae7b
OG
234
235 /* the buffer description has been passed with the command */
236 /* Send the command */
2261ec3d 237 error = iser_send_data_out(conn, task, &hdr);
65e7ae7b 238 if (error) {
0f9c7449 239 r2t->datasn--;
2747fdb2 240 goto iscsi_iser_task_xmit_unsol_data_exit;
65e7ae7b 241 }
0f9c7449 242 r2t->sent += r2t->data_count;
48a237a2 243 iser_dbg("Need to send %d more as data-out PDUs\n",
0f9c7449 244 r2t->data_length - r2t->sent);
65e7ae7b
OG
245 }
246
2747fdb2 247iscsi_iser_task_xmit_unsol_data_exit:
65e7ae7b
OG
248 return error;
249}
250
251static int
2261ec3d 252iscsi_iser_task_xmit(struct iscsi_task *task)
65e7ae7b 253{
2261ec3d
MC
254 struct iscsi_conn *conn = task->conn;
255 struct iscsi_iser_task *iser_task = task->dd_data;
65e7ae7b
OG
256 int error = 0;
257
2261ec3d
MC
258 if (!task->sc)
259 return iscsi_iser_mtask_xmit(conn, task);
2747fdb2 260
2261ec3d
MC
261 if (task->sc->sc_data_direction == DMA_TO_DEVICE) {
262 BUG_ON(scsi_bufflen(task->sc) == 0);
77a23c21 263
48a237a2 264 iser_dbg("cmd [itt %x total %d imm %d unsol_data %d\n",
2261ec3d 265 task->itt, scsi_bufflen(task->sc),
0f9c7449 266 task->imm_count, task->unsol_r2t.data_length);
77a23c21
MC
267 }
268
962b4b52 269 iser_dbg("ctask xmit [cid %d itt 0x%x]\n",
2261ec3d 270 conn->id, task->itt);
65e7ae7b 271
65e7ae7b 272 /* Send the cmd PDU */
2261ec3d
MC
273 if (!iser_task->command_sent) {
274 error = iser_send_command(conn, task);
65e7ae7b 275 if (error)
2747fdb2 276 goto iscsi_iser_task_xmit_exit;
2261ec3d 277 iser_task->command_sent = 1;
65e7ae7b
OG
278 }
279
280 /* Send unsolicited data-out PDU(s) if necessary */
0f9c7449 281 if (iscsi_task_has_unsol_data(task))
2261ec3d 282 error = iscsi_iser_task_xmit_unsol_data(conn, task);
65e7ae7b 283
2747fdb2 284 iscsi_iser_task_xmit_exit:
65e7ae7b
OG
285 return error;
286}
287
0f9c7449 288static void iscsi_iser_cleanup_task(struct iscsi_task *task)
65e7ae7b 289{
2261ec3d 290 struct iscsi_iser_task *iser_task = task->dd_data;
52439540
OG
291 struct iser_tx_desc *tx_desc = &iser_task->desc;
292
293 struct iscsi_iser_conn *iser_conn = task->conn->dd_data;
294 struct iser_device *device = iser_conn->ib_conn->device;
295
296 ib_dma_unmap_single(device->ib_device,
297 tx_desc->dma_addr, ISER_HEADERS_LEN, DMA_TO_DEVICE);
65e7ae7b 298
b3cd5050
MC
299 /* mgmt tasks do not need special cleanup */
300 if (!task->sc)
2747fdb2 301 return;
65e7ae7b 302
2261ec3d
MC
303 if (iser_task->status == ISER_TASK_STATUS_STARTED) {
304 iser_task->status = ISER_TASK_STATUS_COMPLETED;
305 iser_task_rdma_finalize(iser_task);
65e7ae7b 306 }
65e7ae7b
OG
307}
308
309static struct iscsi_cls_conn *
310iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
311{
312 struct iscsi_conn *conn;
313 struct iscsi_cls_conn *cls_conn;
314 struct iscsi_iser_conn *iser_conn;
315
5d91e209 316 cls_conn = iscsi_conn_setup(cls_session, sizeof(*iser_conn), conn_idx);
65e7ae7b
OG
317 if (!cls_conn)
318 return NULL;
319 conn = cls_conn->dd_data;
320
321 /*
322 * due to issues with the login code re iser sematics
323 * this not set in iscsi_conn_setup - FIXME
324 */
bcc60c38 325 conn->max_recv_dlength = ISER_RECV_DATA_SEG_LEN;
65e7ae7b 326
5d91e209 327 iser_conn = conn->dd_data;
65e7ae7b
OG
328 conn->dd_data = iser_conn;
329 iser_conn->iscsi_conn = conn;
330
331 return cls_conn;
65e7ae7b
OG
332}
333
334static void
335iscsi_iser_conn_destroy(struct iscsi_cls_conn *cls_conn)
336{
337 struct iscsi_conn *conn = cls_conn->dd_data;
338 struct iscsi_iser_conn *iser_conn = conn->dd_data;
b40977d9 339 struct iser_conn *ib_conn = iser_conn->ib_conn;
65e7ae7b
OG
340
341 iscsi_conn_teardown(cls_conn);
b40977d9
MC
342 /*
343 * Userspace will normally call the stop callback and
344 * already have freed the ib_conn, but if it goofed up then
345 * we free it here.
346 */
347 if (ib_conn) {
348 ib_conn->iser_conn = NULL;
39ff05db 349 iser_conn_put(ib_conn, 1); /* deref iscsi/ib conn unbinding */
b40977d9 350 }
65e7ae7b
OG
351}
352
353static int
354iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session,
355 struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
356 int is_leading)
357{
358 struct iscsi_conn *conn = cls_conn->dd_data;
359 struct iscsi_iser_conn *iser_conn;
b7f04513 360 struct iscsi_session *session;
65e7ae7b 361 struct iser_conn *ib_conn;
412eeafa 362 struct iscsi_endpoint *ep;
65e7ae7b
OG
363 int error;
364
365 error = iscsi_conn_bind(cls_session, cls_conn, is_leading);
366 if (error)
367 return error;
368
369 /* the transport ep handle comes from user space so it must be
370 * verified against the global ib connections list */
412eeafa
MC
371 ep = iscsi_lookup_endpoint(transport_eph);
372 if (!ep) {
65e7ae7b
OG
373 iser_err("can't bind eph %llx\n",
374 (unsigned long long)transport_eph);
375 return -EINVAL;
376 }
412eeafa
MC
377 ib_conn = ep->dd_data;
378
b7f04513
SP
379 session = conn->session;
380 if (iser_alloc_rx_descriptors(ib_conn, session))
89e984e2
OG
381 return -ENOMEM;
382
65e7ae7b
OG
383 /* binds the iSER connection retrieved from the previously
384 * connected ep_handle to the iSCSI layer connection. exchanges
385 * connection pointers */
4f363882
RD
386 iser_info("binding iscsi/iser conn %p %p to ib_conn %p\n",
387 conn, conn->dd_data, ib_conn);
65e7ae7b
OG
388 iser_conn = conn->dd_data;
389 ib_conn->iser_conn = iser_conn;
390 iser_conn->ib_conn = ib_conn;
39ff05db 391 iser_conn_get(ib_conn); /* ref iscsi/ib conn binding */
65e7ae7b
OG
392 return 0;
393}
65e7ae7b 394
b40977d9
MC
395static void
396iscsi_iser_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
397{
398 struct iscsi_conn *conn = cls_conn->dd_data;
399 struct iscsi_iser_conn *iser_conn = conn->dd_data;
400 struct iser_conn *ib_conn = iser_conn->ib_conn;
65e7ae7b 401
b40977d9 402 /*
913e5bf4
MC
403 * Userspace may have goofed up and not bound the connection or
404 * might have only partially setup the connection.
b40977d9 405 */
913e5bf4
MC
406 if (ib_conn) {
407 iscsi_conn_stop(cls_conn, flag);
408 /*
409 * There is no unbind event so the stop callback
410 * must release the ref from the bind.
411 */
39ff05db 412 iser_conn_put(ib_conn, 1); /* deref iscsi/ib conn unbinding */
913e5bf4 413 }
b40977d9 414 iser_conn->ib_conn = NULL;
65e7ae7b
OG
415}
416
75613521
MC
417static void iscsi_iser_session_destroy(struct iscsi_cls_session *cls_session)
418{
419 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
420
e5bd7b54 421 iscsi_session_teardown(cls_session);
a4804cd6
MC
422 iscsi_host_remove(shost);
423 iscsi_host_free(shost);
75613521 424}
65e7ae7b
OG
425
426static struct iscsi_cls_session *
412eeafa 427iscsi_iser_session_create(struct iscsi_endpoint *ep,
75613521 428 uint16_t cmds_max, uint16_t qdepth,
5e7facb7 429 uint32_t initial_cmdsn)
65e7ae7b
OG
430{
431 struct iscsi_cls_session *cls_session;
432 struct iscsi_session *session;
412eeafa 433 struct Scsi_Host *shost;
b7f04513 434 struct iser_conn *ib_conn = NULL;
75613521 435
962b4b52 436 shost = iscsi_host_alloc(&iscsi_iser_sht, 0, 0);
75613521
MC
437 if (!shost)
438 return NULL;
439 shost->transportt = iscsi_iser_scsi_transport;
b7f04513 440 shost->cmd_per_lun = qdepth;
75613521
MC
441 shost->max_lun = iscsi_max_lun;
442 shost->max_id = 0;
443 shost->max_channel = 0;
444 shost->max_cmd_len = 16;
445
412eeafa
MC
446 /*
447 * older userspace tools (before 2.0-870) did not pass us
448 * the leading conn's ep so this will be NULL;
449 */
450 if (ep)
451 ib_conn = ep->dd_data;
452
453 if (iscsi_host_add(shost,
454 ep ? ib_conn->device->ib_device->dma_device : NULL))
75613521 455 goto free_host;
65e7ae7b 456
b7f04513
SP
457 if (cmds_max > ISER_DEF_XMIT_CMDS_MAX) {
458 iser_info("cmds_max changed from %u to %u\n",
459 cmds_max, ISER_DEF_XMIT_CMDS_MAX);
460 cmds_max = ISER_DEF_XMIT_CMDS_MAX;
461 }
462
75613521 463 cls_session = iscsi_session_setup(&iscsi_iser_transport, shost,
b7f04513 464 cmds_max, 0,
2261ec3d 465 sizeof(struct iscsi_iser_task),
7970634b 466 initial_cmdsn, 0);
65e7ae7b 467 if (!cls_session)
75613521
MC
468 goto remove_host;
469 session = cls_session->dd_data;
65e7ae7b 470
2747fdb2 471 shost->can_queue = session->scsi_cmds_max;
65e7ae7b 472 return cls_session;
75613521
MC
473
474remove_host:
a4804cd6 475 iscsi_host_remove(shost);
75613521 476free_host:
a4804cd6 477 iscsi_host_free(shost);
75613521 478 return NULL;
65e7ae7b
OG
479}
480
481static int
358ff019
MC
482iscsi_iser_set_param(struct iscsi_cls_conn *cls_conn,
483 enum iscsi_param param, char *buf, int buflen)
65e7ae7b 484{
358ff019 485 int value;
65e7ae7b
OG
486
487 switch (param) {
488 case ISCSI_PARAM_MAX_RECV_DLENGTH:
489 /* TBD */
490 break;
65e7ae7b 491 case ISCSI_PARAM_HDRDGST_EN:
358ff019 492 sscanf(buf, "%d", &value);
65e7ae7b 493 if (value) {
4f363882 494 iser_err("DataDigest wasn't negotiated to None");
65e7ae7b
OG
495 return -EPROTO;
496 }
497 break;
498 case ISCSI_PARAM_DATADGST_EN:
358ff019 499 sscanf(buf, "%d", &value);
65e7ae7b 500 if (value) {
4f363882 501 iser_err("DataDigest wasn't negotiated to None");
65e7ae7b
OG
502 return -EPROTO;
503 }
504 break;
65e7ae7b 505 case ISCSI_PARAM_IFMARKER_EN:
358ff019 506 sscanf(buf, "%d", &value);
65e7ae7b 507 if (value) {
4f363882 508 iser_err("IFMarker wasn't negotiated to No");
65e7ae7b
OG
509 return -EPROTO;
510 }
511 break;
512 case ISCSI_PARAM_OFMARKER_EN:
358ff019 513 sscanf(buf, "%d", &value);
65e7ae7b 514 if (value) {
4f363882 515 iser_err("OFMarker wasn't negotiated to No");
65e7ae7b
OG
516 return -EPROTO;
517 }
518 break;
519 default:
358ff019 520 return iscsi_set_param(cls_conn, param, buf, buflen);
65e7ae7b
OG
521 }
522
523 return 0;
524}
525
65e7ae7b
OG
526static void
527iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
528{
529 struct iscsi_conn *conn = cls_conn->dd_data;
530
531 stats->txdata_octets = conn->txdata_octets;
532 stats->rxdata_octets = conn->rxdata_octets;
533 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
534 stats->dataout_pdus = conn->dataout_pdus_cnt;
535 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
536 stats->datain_pdus = conn->datain_pdus_cnt; /* always 0 */
537 stats->r2t_pdus = conn->r2t_pdus_cnt; /* always 0 */
538 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
539 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
87528227 540 stats->custom_length = 4;
65e7ae7b
OG
541 strcpy(stats->custom[0].desc, "qp_tx_queue_full");
542 stats->custom[0].value = 0; /* TB iser_conn->qp_tx_queue_full; */
543 strcpy(stats->custom[1].desc, "fmr_map_not_avail");
544 stats->custom[1].value = 0; /* TB iser_conn->fmr_map_not_avail */;
545 strcpy(stats->custom[2].desc, "eh_abort_cnt");
546 stats->custom[2].value = conn->eh_abort_cnt;
87528227
ED
547 strcpy(stats->custom[3].desc, "fmr_unalign_cnt");
548 stats->custom[3].value = conn->fmr_unalign_cnt;
65e7ae7b
OG
549}
550
7c53c6f8
MC
551static int iscsi_iser_get_ep_param(struct iscsi_endpoint *ep,
552 enum iscsi_param param, char *buf)
553{
554 struct iser_conn *ib_conn = ep->dd_data;
555 int len;
556
557 switch (param) {
558 case ISCSI_PARAM_CONN_PORT:
559 case ISCSI_PARAM_CONN_ADDRESS:
560 if (!ib_conn || !ib_conn->cma_id)
561 return -ENOTCONN;
562
563 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
564 &ib_conn->cma_id->route.addr.dst_addr,
565 param, buf);
566 break;
567 default:
568 return -ENOSYS;
569 }
570
571 return len;
572}
573
412eeafa 574static struct iscsi_endpoint *
10eb0f01
MC
575iscsi_iser_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
576 int non_blocking)
65e7ae7b
OG
577{
578 int err;
579 struct iser_conn *ib_conn;
412eeafa 580 struct iscsi_endpoint *ep;
65e7ae7b 581
412eeafa
MC
582 ep = iscsi_create_endpoint(sizeof(*ib_conn));
583 if (!ep)
584 return ERR_PTR(-ENOMEM);
65e7ae7b 585
412eeafa
MC
586 ib_conn = ep->dd_data;
587 ib_conn->ep = ep;
588 iser_conn_init(ib_conn);
65e7ae7b 589
412eeafa
MC
590 err = iser_connect(ib_conn, NULL, (struct sockaddr_in *)dst_addr,
591 non_blocking);
7d9c0de4 592 if (err)
412eeafa 593 return ERR_PTR(err);
7d9c0de4 594
412eeafa 595 return ep;
65e7ae7b
OG
596}
597
598static int
412eeafa 599iscsi_iser_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
65e7ae7b 600{
412eeafa 601 struct iser_conn *ib_conn;
65e7ae7b
OG
602 int rc;
603
412eeafa 604 ib_conn = ep->dd_data;
65e7ae7b
OG
605 rc = wait_event_interruptible_timeout(ib_conn->wait,
606 ib_conn->state == ISER_CONN_UP,
607 msecs_to_jiffies(timeout_ms));
608
609 /* if conn establishment failed, return error code to iscsi */
610 if (!rc &&
611 (ib_conn->state == ISER_CONN_TERMINATING ||
612 ib_conn->state == ISER_CONN_DOWN))
613 rc = -1;
614
4f363882 615 iser_info("ib conn %p rc = %d\n", ib_conn, rc);
65e7ae7b
OG
616
617 if (rc > 0)
618 return 1; /* success, this is the equivalent of POLLOUT */
619 else if (!rc)
620 return 0; /* timeout */
621 else
622 return rc; /* signal */
623}
624
625static void
412eeafa 626iscsi_iser_ep_disconnect(struct iscsi_endpoint *ep)
65e7ae7b 627{
1c83469d 628 struct iser_conn *ib_conn;
65e7ae7b 629
412eeafa 630 ib_conn = ep->dd_data;
b40977d9
MC
631 if (ib_conn->iser_conn)
632 /*
633 * Must suspend xmit path if the ep is bound to the
634 * iscsi_conn, so we know we are not accessing the ib_conn
635 * when we free it.
636 *
637 * This may not be bound if the ep poll failed.
638 */
639 iscsi_suspend_tx(ib_conn->iser_conn->iscsi_conn);
640
65e7ae7b 641
4f363882 642 iser_info("ib conn %p state %d\n", ib_conn, ib_conn->state);
65e7ae7b
OG
643 iser_conn_terminate(ib_conn);
644}
645
587a1f16 646static umode_t iser_attr_is_visible(int param_type, int param)
3128c6c7
MC
647{
648 switch (param_type) {
f27fb2ef
MC
649 case ISCSI_HOST_PARAM:
650 switch (param) {
651 case ISCSI_HOST_PARAM_NETDEV_NAME:
652 case ISCSI_HOST_PARAM_HWADDRESS:
653 case ISCSI_HOST_PARAM_INITIATOR_NAME:
654 return S_IRUGO;
655 default:
656 return 0;
657 }
3128c6c7
MC
658 case ISCSI_PARAM:
659 switch (param) {
660 case ISCSI_PARAM_MAX_RECV_DLENGTH:
661 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
662 case ISCSI_PARAM_HDRDGST_EN:
663 case ISCSI_PARAM_DATADGST_EN:
664 case ISCSI_PARAM_CONN_ADDRESS:
665 case ISCSI_PARAM_CONN_PORT:
666 case ISCSI_PARAM_EXP_STATSN:
667 case ISCSI_PARAM_PERSISTENT_ADDRESS:
668 case ISCSI_PARAM_PERSISTENT_PORT:
669 case ISCSI_PARAM_PING_TMO:
670 case ISCSI_PARAM_RECV_TMO:
1d063c17
MC
671 case ISCSI_PARAM_INITIAL_R2T_EN:
672 case ISCSI_PARAM_MAX_R2T:
673 case ISCSI_PARAM_IMM_DATA_EN:
674 case ISCSI_PARAM_FIRST_BURST:
675 case ISCSI_PARAM_MAX_BURST:
676 case ISCSI_PARAM_PDU_INORDER_EN:
677 case ISCSI_PARAM_DATASEQ_INORDER_EN:
678 case ISCSI_PARAM_TARGET_NAME:
679 case ISCSI_PARAM_TPGT:
680 case ISCSI_PARAM_USERNAME:
681 case ISCSI_PARAM_PASSWORD:
682 case ISCSI_PARAM_USERNAME_IN:
683 case ISCSI_PARAM_PASSWORD_IN:
684 case ISCSI_PARAM_FAST_ABORT:
685 case ISCSI_PARAM_ABORT_TMO:
686 case ISCSI_PARAM_LU_RESET_TMO:
687 case ISCSI_PARAM_TGT_RESET_TMO:
688 case ISCSI_PARAM_IFACE_NAME:
689 case ISCSI_PARAM_INITIATOR_NAME:
6a06a4b8 690 case ISCSI_PARAM_DISCOVERY_SESS:
3128c6c7
MC
691 return S_IRUGO;
692 default:
693 return 0;
694 }
695 }
696
697 return 0;
698}
699
65e7ae7b 700static struct scsi_host_template iscsi_iser_sht = {
7974392c 701 .module = THIS_MODULE,
c1d786e6 702 .name = "iSCSI Initiator over iSER",
65e7ae7b 703 .queuecommand = iscsi_queuecommand,
6410627e 704 .change_queue_depth = iscsi_change_queue_depth,
65e7ae7b 705 .sg_tablesize = ISCSI_ISER_SG_TABLESIZE,
8072ec2f 706 .max_sectors = 1024,
e28f3d5b 707 .cmd_per_lun = ISER_DEF_CMD_PER_LUN,
65e7ae7b 708 .eh_abort_handler = iscsi_eh_abort,
90c18f3c 709 .eh_device_reset_handler= iscsi_eh_device_reset,
309ce156 710 .eh_target_reset_handler = iscsi_eh_recover_target,
6b5d6c44 711 .target_alloc = iscsi_target_alloc,
65e7ae7b
OG
712 .use_clustering = DISABLE_CLUSTERING,
713 .proc_name = "iscsi_iser",
714 .this_id = -1,
715};
716
717static struct iscsi_transport iscsi_iser_transport = {
718 .owner = THIS_MODULE,
719 .name = "iser",
6a06a4b8 720 .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_TEXT_NEGO,
65e7ae7b
OG
721 /* session management */
722 .create_session = iscsi_iser_session_create,
75613521 723 .destroy_session = iscsi_iser_session_destroy,
65e7ae7b
OG
724 /* connection management */
725 .create_conn = iscsi_iser_conn_create,
726 .bind_conn = iscsi_iser_conn_bind,
727 .destroy_conn = iscsi_iser_conn_destroy,
3128c6c7 728 .attr_is_visible = iser_attr_is_visible,
358ff019
MC
729 .set_param = iscsi_iser_set_param,
730 .get_conn_param = iscsi_conn_get_param,
7c53c6f8 731 .get_ep_param = iscsi_iser_get_ep_param,
358ff019 732 .get_session_param = iscsi_session_get_param,
89e984e2 733 .start_conn = iscsi_conn_start,
b40977d9 734 .stop_conn = iscsi_iser_conn_stop,
0801c242
MC
735 /* iscsi host params */
736 .get_host_param = iscsi_host_get_param,
737 .set_host_param = iscsi_host_set_param,
65e7ae7b
OG
738 /* IO */
739 .send_pdu = iscsi_conn_send_pdu,
740 .get_stats = iscsi_iser_conn_get_stats,
2747fdb2
MC
741 .init_task = iscsi_iser_task_init,
742 .xmit_task = iscsi_iser_task_xmit,
743 .cleanup_task = iscsi_iser_cleanup_task,
0f9c7449 744 .alloc_pdu = iscsi_iser_pdu_alloc,
65e7ae7b
OG
745 /* recovery */
746 .session_recovery_timedout = iscsi_session_recovery_timedout,
747
748 .ep_connect = iscsi_iser_ep_connect,
749 .ep_poll = iscsi_iser_ep_poll,
750 .ep_disconnect = iscsi_iser_ep_disconnect
751};
752
753static int __init iser_init(void)
754{
755 int err;
756
757 iser_dbg("Starting iSER datamover...\n");
758
759 if (iscsi_max_lun < 1) {
4f363882 760 iser_err("Invalid max_lun value of %u\n", iscsi_max_lun);
65e7ae7b
OG
761 return -EINVAL;
762 }
763
65e7ae7b
OG
764 memset(&ig, 0, sizeof(struct iser_global));
765
766 ig.desc_cache = kmem_cache_create("iser_descriptors",
f19624aa 767 sizeof(struct iser_tx_desc),
65e7ae7b 768 0, SLAB_HWCACHE_ALIGN,
20c2df83 769 NULL);
65e7ae7b
OG
770 if (ig.desc_cache == NULL)
771 return -ENOMEM;
772
773 /* device init is called only after the first addr resolution */
774 mutex_init(&ig.device_list_mutex);
775 INIT_LIST_HEAD(&ig.device_list);
776 mutex_init(&ig.connlist_mutex);
777 INIT_LIST_HEAD(&ig.connlist);
778
75613521
MC
779 iscsi_iser_scsi_transport = iscsi_register_transport(
780 &iscsi_iser_transport);
781 if (!iscsi_iser_scsi_transport) {
65e7ae7b
OG
782 iser_err("iscsi_register_transport failed\n");
783 err = -EINVAL;
784 goto register_transport_failure;
785 }
786
787 return 0;
788
789register_transport_failure:
790 kmem_cache_destroy(ig.desc_cache);
791
792 return err;
793}
794
795static void __exit iser_exit(void)
796{
797 iser_dbg("Removing iSER datamover...\n");
798 iscsi_unregister_transport(&iscsi_iser_transport);
799 kmem_cache_destroy(ig.desc_cache);
800}
801
802module_init(iser_init);
803module_exit(iser_exit);
This page took 0.612947 seconds and 5 git commands to generate.