diff options
author | Sagi Grimberg <sagig@mellanox.com> | 2014-03-05 12:43:48 -0500 |
---|---|---|
committer | Roland Dreier <roland@purestorage.com> | 2014-03-18 01:33:58 -0400 |
commit | 177e31bd5a40999028f6694623ceea1bec5abff6 (patch) | |
tree | 851325a413c642824ae6763fa16ab65dec62c6d2 | |
parent | 6b5a8fb0d22f95fff1eefe1545aa2c7771cacc3f (diff) |
IB/iser: Support T10-PI operations
Add logic to initialize protection information entities. Upon each
iSCSI task, we keep the scsi_cmnd in order to query the scsi
protection operations and reference to protection buffers.
Modify iser_fast_reg_mr to receive indication whether it is
registering the data or protection buffers.
In addition introduce iser_reg_sig_mr which performs fast registration
work-request for a signature enabled memory region
(IB_WR_REG_SIG_MR). In this routine we set all the protection
relevants for the device to offload protection data-transfer and
verification.
Signed-off-by: Sagi Grimberg <sagig@mellanox.com>
Signed-off-by: Alex Tabachnik <alext@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
-rw-r--r-- | drivers/infiniband/ulp/iser/iscsi_iser.c | 2 | ||||
-rw-r--r-- | drivers/infiniband/ulp/iser/iscsi_iser.h | 9 | ||||
-rw-r--r-- | drivers/infiniband/ulp/iser/iser_initiator.c | 63 | ||||
-rw-r--r-- | drivers/infiniband/ulp/iser/iser_memory.c | 257 |
4 files changed, 304 insertions, 27 deletions
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c index cfa952e9ac90..a64b87811915 100644 --- a/drivers/infiniband/ulp/iser/iscsi_iser.c +++ b/drivers/infiniband/ulp/iser/iscsi_iser.c | |||
@@ -184,6 +184,8 @@ iscsi_iser_task_init(struct iscsi_task *task) | |||
184 | 184 | ||
185 | iser_task->command_sent = 0; | 185 | iser_task->command_sent = 0; |
186 | iser_task_rdma_init(iser_task); | 186 | iser_task_rdma_init(iser_task); |
187 | iser_task->sc = task->sc; | ||
188 | |||
187 | return 0; | 189 | return 0; |
188 | } | 190 | } |
189 | 191 | ||
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.h b/drivers/infiniband/ulp/iser/iscsi_iser.h index 99fc8b899648..fce54092d300 100644 --- a/drivers/infiniband/ulp/iser/iscsi_iser.h +++ b/drivers/infiniband/ulp/iser/iscsi_iser.h | |||
@@ -46,6 +46,8 @@ | |||
46 | #include <linux/printk.h> | 46 | #include <linux/printk.h> |
47 | #include <scsi/libiscsi.h> | 47 | #include <scsi/libiscsi.h> |
48 | #include <scsi/scsi_transport_iscsi.h> | 48 | #include <scsi/scsi_transport_iscsi.h> |
49 | #include <scsi/scsi_cmnd.h> | ||
50 | #include <scsi/scsi_device.h> | ||
49 | 51 | ||
50 | #include <linux/interrupt.h> | 52 | #include <linux/interrupt.h> |
51 | #include <linux/wait.h> | 53 | #include <linux/wait.h> |
@@ -289,6 +291,10 @@ struct iser_device { | |||
289 | enum iser_data_dir cmd_dir); | 291 | enum iser_data_dir cmd_dir); |
290 | }; | 292 | }; |
291 | 293 | ||
294 | #define ISER_CHECK_GUARD 0xc0 | ||
295 | #define ISER_CHECK_REFTAG 0x0f | ||
296 | #define ISER_CHECK_APPTAG 0x30 | ||
297 | |||
292 | enum iser_reg_indicator { | 298 | enum iser_reg_indicator { |
293 | ISER_DATA_KEY_VALID = 1 << 0, | 299 | ISER_DATA_KEY_VALID = 1 << 0, |
294 | ISER_PROT_KEY_VALID = 1 << 1, | 300 | ISER_PROT_KEY_VALID = 1 << 1, |
@@ -361,11 +367,14 @@ struct iscsi_iser_task { | |||
361 | struct iser_tx_desc desc; | 367 | struct iser_tx_desc desc; |
362 | struct iscsi_iser_conn *iser_conn; | 368 | struct iscsi_iser_conn *iser_conn; |
363 | enum iser_task_status status; | 369 | enum iser_task_status status; |
370 | struct scsi_cmnd *sc; | ||
364 | int command_sent; /* set if command sent */ | 371 | int command_sent; /* set if command sent */ |
365 | int dir[ISER_DIRS_NUM]; /* set if dir use*/ | 372 | int dir[ISER_DIRS_NUM]; /* set if dir use*/ |
366 | struct iser_regd_buf rdma_regd[ISER_DIRS_NUM];/* regd rdma buf */ | 373 | struct iser_regd_buf rdma_regd[ISER_DIRS_NUM];/* regd rdma buf */ |
367 | struct iser_data_buf data[ISER_DIRS_NUM]; /* orig. data des*/ | 374 | struct iser_data_buf data[ISER_DIRS_NUM]; /* orig. data des*/ |
368 | struct iser_data_buf data_copy[ISER_DIRS_NUM];/* contig. copy */ | 375 | struct iser_data_buf data_copy[ISER_DIRS_NUM];/* contig. copy */ |
376 | struct iser_data_buf prot[ISER_DIRS_NUM]; /* prot desc */ | ||
377 | struct iser_data_buf prot_copy[ISER_DIRS_NUM];/* prot copy */ | ||
369 | }; | 378 | }; |
370 | 379 | ||
371 | struct iser_page_vec { | 380 | struct iser_page_vec { |
diff --git a/drivers/infiniband/ulp/iser/iser_initiator.c b/drivers/infiniband/ulp/iser/iser_initiator.c index 58e14c7705c6..7fd95fe6d989 100644 --- a/drivers/infiniband/ulp/iser/iser_initiator.c +++ b/drivers/infiniband/ulp/iser/iser_initiator.c | |||
@@ -62,6 +62,17 @@ static int iser_prepare_read_cmd(struct iscsi_task *task, | |||
62 | if (err) | 62 | if (err) |
63 | return err; | 63 | return err; |
64 | 64 | ||
65 | if (scsi_prot_sg_count(iser_task->sc)) { | ||
66 | struct iser_data_buf *pbuf_in = &iser_task->prot[ISER_DIR_IN]; | ||
67 | |||
68 | err = iser_dma_map_task_data(iser_task, | ||
69 | pbuf_in, | ||
70 | ISER_DIR_IN, | ||
71 | DMA_FROM_DEVICE); | ||
72 | if (err) | ||
73 | return err; | ||
74 | } | ||
75 | |||
65 | if (edtl > iser_task->data[ISER_DIR_IN].data_len) { | 76 | if (edtl > iser_task->data[ISER_DIR_IN].data_len) { |
66 | iser_err("Total data length: %ld, less than EDTL: " | 77 | iser_err("Total data length: %ld, less than EDTL: " |
67 | "%d, in READ cmd BHS itt: %d, conn: 0x%p\n", | 78 | "%d, in READ cmd BHS itt: %d, conn: 0x%p\n", |
@@ -113,6 +124,17 @@ iser_prepare_write_cmd(struct iscsi_task *task, | |||
113 | if (err) | 124 | if (err) |
114 | return err; | 125 | return err; |
115 | 126 | ||
127 | if (scsi_prot_sg_count(iser_task->sc)) { | ||
128 | struct iser_data_buf *pbuf_out = &iser_task->prot[ISER_DIR_OUT]; | ||
129 | |||
130 | err = iser_dma_map_task_data(iser_task, | ||
131 | pbuf_out, | ||
132 | ISER_DIR_OUT, | ||
133 | DMA_TO_DEVICE); | ||
134 | if (err) | ||
135 | return err; | ||
136 | } | ||
137 | |||
116 | if (edtl > iser_task->data[ISER_DIR_OUT].data_len) { | 138 | if (edtl > iser_task->data[ISER_DIR_OUT].data_len) { |
117 | iser_err("Total data length: %ld, less than EDTL: %d, " | 139 | iser_err("Total data length: %ld, less than EDTL: %d, " |
118 | "in WRITE cmd BHS itt: %d, conn: 0x%p\n", | 140 | "in WRITE cmd BHS itt: %d, conn: 0x%p\n", |
@@ -368,7 +390,7 @@ int iser_send_command(struct iscsi_conn *conn, | |||
368 | struct iscsi_iser_task *iser_task = task->dd_data; | 390 | struct iscsi_iser_task *iser_task = task->dd_data; |
369 | unsigned long edtl; | 391 | unsigned long edtl; |
370 | int err; | 392 | int err; |
371 | struct iser_data_buf *data_buf; | 393 | struct iser_data_buf *data_buf, *prot_buf; |
372 | struct iscsi_scsi_req *hdr = (struct iscsi_scsi_req *)task->hdr; | 394 | struct iscsi_scsi_req *hdr = (struct iscsi_scsi_req *)task->hdr; |
373 | struct scsi_cmnd *sc = task->sc; | 395 | struct scsi_cmnd *sc = task->sc; |
374 | struct iser_tx_desc *tx_desc = &iser_task->desc; | 396 | struct iser_tx_desc *tx_desc = &iser_task->desc; |
@@ -379,18 +401,26 @@ int iser_send_command(struct iscsi_conn *conn, | |||
379 | tx_desc->type = ISCSI_TX_SCSI_COMMAND; | 401 | tx_desc->type = ISCSI_TX_SCSI_COMMAND; |
380 | iser_create_send_desc(iser_conn->ib_conn, tx_desc); | 402 | iser_create_send_desc(iser_conn->ib_conn, tx_desc); |
381 | 403 | ||
382 | if (hdr->flags & ISCSI_FLAG_CMD_READ) | 404 | if (hdr->flags & ISCSI_FLAG_CMD_READ) { |
383 | data_buf = &iser_task->data[ISER_DIR_IN]; | 405 | data_buf = &iser_task->data[ISER_DIR_IN]; |
384 | else | 406 | prot_buf = &iser_task->prot[ISER_DIR_IN]; |
407 | } else { | ||
385 | data_buf = &iser_task->data[ISER_DIR_OUT]; | 408 | data_buf = &iser_task->data[ISER_DIR_OUT]; |
409 | prot_buf = &iser_task->prot[ISER_DIR_OUT]; | ||
410 | } | ||
386 | 411 | ||
387 | if (scsi_sg_count(sc)) { /* using a scatter list */ | 412 | if (scsi_sg_count(sc)) { /* using a scatter list */ |
388 | data_buf->buf = scsi_sglist(sc); | 413 | data_buf->buf = scsi_sglist(sc); |
389 | data_buf->size = scsi_sg_count(sc); | 414 | data_buf->size = scsi_sg_count(sc); |
390 | } | 415 | } |
391 | |||
392 | data_buf->data_len = scsi_bufflen(sc); | 416 | data_buf->data_len = scsi_bufflen(sc); |
393 | 417 | ||
418 | if (scsi_prot_sg_count(sc)) { | ||
419 | prot_buf->buf = scsi_prot_sglist(sc); | ||
420 | prot_buf->size = scsi_prot_sg_count(sc); | ||
421 | prot_buf->data_len = sc->prot_sdb->length; | ||
422 | } | ||
423 | |||
394 | if (hdr->flags & ISCSI_FLAG_CMD_READ) { | 424 | if (hdr->flags & ISCSI_FLAG_CMD_READ) { |
395 | err = iser_prepare_read_cmd(task, edtl); | 425 | err = iser_prepare_read_cmd(task, edtl); |
396 | if (err) | 426 | if (err) |
@@ -635,6 +665,9 @@ void iser_task_rdma_init(struct iscsi_iser_task *iser_task) | |||
635 | iser_task->data[ISER_DIR_IN].data_len = 0; | 665 | iser_task->data[ISER_DIR_IN].data_len = 0; |
636 | iser_task->data[ISER_DIR_OUT].data_len = 0; | 666 | iser_task->data[ISER_DIR_OUT].data_len = 0; |
637 | 667 | ||
668 | iser_task->prot[ISER_DIR_IN].data_len = 0; | ||
669 | iser_task->prot[ISER_DIR_OUT].data_len = 0; | ||
670 | |||
638 | memset(&iser_task->rdma_regd[ISER_DIR_IN], 0, | 671 | memset(&iser_task->rdma_regd[ISER_DIR_IN], 0, |
639 | sizeof(struct iser_regd_buf)); | 672 | sizeof(struct iser_regd_buf)); |
640 | memset(&iser_task->rdma_regd[ISER_DIR_OUT], 0, | 673 | memset(&iser_task->rdma_regd[ISER_DIR_OUT], 0, |
@@ -645,6 +678,8 @@ void iser_task_rdma_finalize(struct iscsi_iser_task *iser_task) | |||
645 | { | 678 | { |
646 | struct iser_device *device = iser_task->iser_conn->ib_conn->device; | 679 | struct iser_device *device = iser_task->iser_conn->ib_conn->device; |
647 | int is_rdma_data_aligned = 1; | 680 | int is_rdma_data_aligned = 1; |
681 | int is_rdma_prot_aligned = 1; | ||
682 | int prot_count = scsi_prot_sg_count(iser_task->sc); | ||
648 | 683 | ||
649 | /* if we were reading, copy back to unaligned sglist, | 684 | /* if we were reading, copy back to unaligned sglist, |
650 | * anyway dma_unmap and free the copy | 685 | * anyway dma_unmap and free the copy |
@@ -665,12 +700,30 @@ void iser_task_rdma_finalize(struct iscsi_iser_task *iser_task) | |||
665 | ISER_DIR_OUT); | 700 | ISER_DIR_OUT); |
666 | } | 701 | } |
667 | 702 | ||
703 | if (iser_task->prot_copy[ISER_DIR_IN].copy_buf != NULL) { | ||
704 | is_rdma_prot_aligned = 0; | ||
705 | iser_finalize_rdma_unaligned_sg(iser_task, | ||
706 | &iser_task->prot[ISER_DIR_IN], | ||
707 | &iser_task->prot_copy[ISER_DIR_IN], | ||
708 | ISER_DIR_IN); | ||
709 | } | ||
710 | |||
711 | if (iser_task->prot_copy[ISER_DIR_OUT].copy_buf != NULL) { | ||
712 | is_rdma_prot_aligned = 0; | ||
713 | iser_finalize_rdma_unaligned_sg(iser_task, | ||
714 | &iser_task->prot[ISER_DIR_OUT], | ||
715 | &iser_task->prot_copy[ISER_DIR_OUT], | ||
716 | ISER_DIR_OUT); | ||
717 | } | ||
718 | |||
668 | if (iser_task->dir[ISER_DIR_IN]) { | 719 | if (iser_task->dir[ISER_DIR_IN]) { |
669 | device->iser_unreg_rdma_mem(iser_task, ISER_DIR_IN); | 720 | device->iser_unreg_rdma_mem(iser_task, ISER_DIR_IN); |
670 | if (is_rdma_data_aligned) | 721 | if (is_rdma_data_aligned) |
671 | iser_dma_unmap_task_data(iser_task, | 722 | iser_dma_unmap_task_data(iser_task, |
672 | &iser_task->data[ISER_DIR_IN]); | 723 | &iser_task->data[ISER_DIR_IN]); |
673 | 724 | if (prot_count && is_rdma_prot_aligned) | |
725 | iser_dma_unmap_task_data(iser_task, | ||
726 | &iser_task->prot[ISER_DIR_IN]); | ||
674 | } | 727 | } |
675 | 728 | ||
676 | if (iser_task->dir[ISER_DIR_OUT]) { | 729 | if (iser_task->dir[ISER_DIR_OUT]) { |
diff --git a/drivers/infiniband/ulp/iser/iser_memory.c b/drivers/infiniband/ulp/iser/iser_memory.c index 2c3f4b144a1a..0995565f5dda 100644 --- a/drivers/infiniband/ulp/iser/iser_memory.c +++ b/drivers/infiniband/ulp/iser/iser_memory.c | |||
@@ -440,15 +440,180 @@ int iser_reg_rdma_mem_fmr(struct iscsi_iser_task *iser_task, | |||
440 | return 0; | 440 | return 0; |
441 | } | 441 | } |
442 | 442 | ||
443 | static inline enum ib_t10_dif_type | ||
444 | scsi2ib_prot_type(unsigned char prot_type) | ||
445 | { | ||
446 | switch (prot_type) { | ||
447 | case SCSI_PROT_DIF_TYPE0: | ||
448 | return IB_T10DIF_NONE; | ||
449 | case SCSI_PROT_DIF_TYPE1: | ||
450 | return IB_T10DIF_TYPE1; | ||
451 | case SCSI_PROT_DIF_TYPE2: | ||
452 | return IB_T10DIF_TYPE2; | ||
453 | case SCSI_PROT_DIF_TYPE3: | ||
454 | return IB_T10DIF_TYPE3; | ||
455 | default: | ||
456 | return IB_T10DIF_NONE; | ||
457 | } | ||
458 | } | ||
459 | |||
460 | |||
461 | static int | ||
462 | iser_set_sig_attrs(struct scsi_cmnd *sc, struct ib_sig_attrs *sig_attrs) | ||
463 | { | ||
464 | unsigned char scsi_ptype = scsi_get_prot_type(sc); | ||
465 | |||
466 | sig_attrs->mem.sig_type = IB_SIG_TYPE_T10_DIF; | ||
467 | sig_attrs->wire.sig_type = IB_SIG_TYPE_T10_DIF; | ||
468 | sig_attrs->mem.sig.dif.pi_interval = sc->device->sector_size; | ||
469 | sig_attrs->wire.sig.dif.pi_interval = sc->device->sector_size; | ||
470 | |||
471 | switch (scsi_get_prot_op(sc)) { | ||
472 | case SCSI_PROT_WRITE_INSERT: | ||
473 | case SCSI_PROT_READ_STRIP: | ||
474 | sig_attrs->mem.sig.dif.type = IB_T10DIF_NONE; | ||
475 | sig_attrs->wire.sig.dif.type = scsi2ib_prot_type(scsi_ptype); | ||
476 | sig_attrs->wire.sig.dif.bg_type = IB_T10DIF_CRC; | ||
477 | sig_attrs->wire.sig.dif.ref_tag = scsi_get_lba(sc) & | ||
478 | 0xffffffff; | ||
479 | break; | ||
480 | case SCSI_PROT_READ_INSERT: | ||
481 | case SCSI_PROT_WRITE_STRIP: | ||
482 | sig_attrs->mem.sig.dif.type = scsi2ib_prot_type(scsi_ptype); | ||
483 | sig_attrs->mem.sig.dif.bg_type = IB_T10DIF_CRC; | ||
484 | sig_attrs->mem.sig.dif.ref_tag = scsi_get_lba(sc) & | ||
485 | 0xffffffff; | ||
486 | sig_attrs->wire.sig.dif.type = IB_T10DIF_NONE; | ||
487 | break; | ||
488 | case SCSI_PROT_READ_PASS: | ||
489 | case SCSI_PROT_WRITE_PASS: | ||
490 | sig_attrs->mem.sig.dif.type = scsi2ib_prot_type(scsi_ptype); | ||
491 | sig_attrs->mem.sig.dif.bg_type = IB_T10DIF_CRC; | ||
492 | sig_attrs->mem.sig.dif.ref_tag = scsi_get_lba(sc) & | ||
493 | 0xffffffff; | ||
494 | sig_attrs->wire.sig.dif.type = scsi2ib_prot_type(scsi_ptype); | ||
495 | sig_attrs->wire.sig.dif.bg_type = IB_T10DIF_CRC; | ||
496 | sig_attrs->wire.sig.dif.ref_tag = scsi_get_lba(sc) & | ||
497 | 0xffffffff; | ||
498 | break; | ||
499 | default: | ||
500 | iser_err("Unsupported PI operation %d\n", | ||
501 | scsi_get_prot_op(sc)); | ||
502 | return -EINVAL; | ||
503 | } | ||
504 | return 0; | ||
505 | } | ||
506 | |||
507 | |||
508 | static int | ||
509 | iser_set_prot_checks(struct scsi_cmnd *sc, u8 *mask) | ||
510 | { | ||
511 | switch (scsi_get_prot_type(sc)) { | ||
512 | case SCSI_PROT_DIF_TYPE0: | ||
513 | *mask = 0x0; | ||
514 | break; | ||
515 | case SCSI_PROT_DIF_TYPE1: | ||
516 | case SCSI_PROT_DIF_TYPE2: | ||
517 | *mask = ISER_CHECK_GUARD | ISER_CHECK_REFTAG; | ||
518 | break; | ||
519 | case SCSI_PROT_DIF_TYPE3: | ||
520 | *mask = ISER_CHECK_GUARD; | ||
521 | break; | ||
522 | default: | ||
523 | iser_err("Unsupported protection type %d\n", | ||
524 | scsi_get_prot_type(sc)); | ||
525 | return -EINVAL; | ||
526 | } | ||
527 | |||
528 | return 0; | ||
529 | } | ||
530 | |||
531 | static int | ||
532 | iser_reg_sig_mr(struct iscsi_iser_task *iser_task, | ||
533 | struct fast_reg_descriptor *desc, struct ib_sge *data_sge, | ||
534 | struct ib_sge *prot_sge, struct ib_sge *sig_sge) | ||
535 | { | ||
536 | struct iser_conn *iser_conn = iser_task->iser_conn->ib_conn; | ||
537 | struct iser_pi_context *pi_ctx = desc->pi_ctx; | ||
538 | struct ib_send_wr sig_wr, inv_wr; | ||
539 | struct ib_send_wr *bad_wr, *wr = NULL; | ||
540 | struct ib_sig_attrs sig_attrs; | ||
541 | int ret; | ||
542 | u32 key; | ||
543 | |||
544 | memset(&sig_attrs, 0, sizeof(sig_attrs)); | ||
545 | ret = iser_set_sig_attrs(iser_task->sc, &sig_attrs); | ||
546 | if (ret) | ||
547 | goto err; | ||
548 | |||
549 | ret = iser_set_prot_checks(iser_task->sc, &sig_attrs.check_mask); | ||
550 | if (ret) | ||
551 | goto err; | ||
552 | |||
553 | if (!(desc->reg_indicators & ISER_SIG_KEY_VALID)) { | ||
554 | memset(&inv_wr, 0, sizeof(inv_wr)); | ||
555 | inv_wr.opcode = IB_WR_LOCAL_INV; | ||
556 | inv_wr.wr_id = ISER_FASTREG_LI_WRID; | ||
557 | inv_wr.ex.invalidate_rkey = pi_ctx->sig_mr->rkey; | ||
558 | wr = &inv_wr; | ||
559 | /* Bump the key */ | ||
560 | key = (u8)(pi_ctx->sig_mr->rkey & 0x000000FF); | ||
561 | ib_update_fast_reg_key(pi_ctx->sig_mr, ++key); | ||
562 | } | ||
563 | |||
564 | memset(&sig_wr, 0, sizeof(sig_wr)); | ||
565 | sig_wr.opcode = IB_WR_REG_SIG_MR; | ||
566 | sig_wr.wr_id = ISER_FASTREG_LI_WRID; | ||
567 | sig_wr.sg_list = data_sge; | ||
568 | sig_wr.num_sge = 1; | ||
569 | sig_wr.wr.sig_handover.sig_attrs = &sig_attrs; | ||
570 | sig_wr.wr.sig_handover.sig_mr = pi_ctx->sig_mr; | ||
571 | if (scsi_prot_sg_count(iser_task->sc)) | ||
572 | sig_wr.wr.sig_handover.prot = prot_sge; | ||
573 | sig_wr.wr.sig_handover.access_flags = IB_ACCESS_LOCAL_WRITE | | ||
574 | IB_ACCESS_REMOTE_READ | | ||
575 | IB_ACCESS_REMOTE_WRITE; | ||
576 | |||
577 | if (!wr) | ||
578 | wr = &sig_wr; | ||
579 | else | ||
580 | wr->next = &sig_wr; | ||
581 | |||
582 | ret = ib_post_send(iser_conn->qp, wr, &bad_wr); | ||
583 | if (ret) { | ||
584 | iser_err("reg_sig_mr failed, ret:%d\n", ret); | ||
585 | goto err; | ||
586 | } | ||
587 | desc->reg_indicators &= ~ISER_SIG_KEY_VALID; | ||
588 | |||
589 | sig_sge->lkey = pi_ctx->sig_mr->lkey; | ||
590 | sig_sge->addr = 0; | ||
591 | sig_sge->length = data_sge->length + prot_sge->length; | ||
592 | if (scsi_get_prot_op(iser_task->sc) == SCSI_PROT_WRITE_INSERT || | ||
593 | scsi_get_prot_op(iser_task->sc) == SCSI_PROT_READ_STRIP) { | ||
594 | sig_sge->length += (data_sge->length / | ||
595 | iser_task->sc->device->sector_size) * 8; | ||
596 | } | ||
597 | |||
598 | iser_dbg("sig_sge: addr: 0x%llx length: %u lkey: 0x%x\n", | ||
599 | sig_sge->addr, sig_sge->length, | ||
600 | sig_sge->lkey); | ||
601 | err: | ||
602 | return ret; | ||
603 | } | ||
604 | |||
443 | static int iser_fast_reg_mr(struct iscsi_iser_task *iser_task, | 605 | static int iser_fast_reg_mr(struct iscsi_iser_task *iser_task, |
444 | struct iser_regd_buf *regd_buf, | 606 | struct iser_regd_buf *regd_buf, |
445 | struct iser_data_buf *mem, | 607 | struct iser_data_buf *mem, |
608 | enum iser_reg_indicator ind, | ||
446 | struct ib_sge *sge) | 609 | struct ib_sge *sge) |
447 | { | 610 | { |
448 | struct fast_reg_descriptor *desc = regd_buf->reg.mem_h; | 611 | struct fast_reg_descriptor *desc = regd_buf->reg.mem_h; |
449 | struct iser_conn *ib_conn = iser_task->iser_conn->ib_conn; | 612 | struct iser_conn *ib_conn = iser_task->iser_conn->ib_conn; |
450 | struct iser_device *device = ib_conn->device; | 613 | struct iser_device *device = ib_conn->device; |
451 | struct ib_device *ibdev = device->ib_device; | 614 | struct ib_device *ibdev = device->ib_device; |
615 | struct ib_mr *mr; | ||
616 | struct ib_fast_reg_page_list *frpl; | ||
452 | struct ib_send_wr fastreg_wr, inv_wr; | 617 | struct ib_send_wr fastreg_wr, inv_wr; |
453 | struct ib_send_wr *bad_wr, *wr = NULL; | 618 | struct ib_send_wr *bad_wr, *wr = NULL; |
454 | u8 key; | 619 | u8 key; |
@@ -467,35 +632,42 @@ static int iser_fast_reg_mr(struct iscsi_iser_task *iser_task, | |||
467 | return 0; | 632 | return 0; |
468 | } | 633 | } |
469 | 634 | ||
470 | plen = iser_sg_to_page_vec(mem, device->ib_device, | 635 | if (ind == ISER_DATA_KEY_VALID) { |
471 | desc->data_frpl->page_list, | 636 | mr = desc->data_mr; |
637 | frpl = desc->data_frpl; | ||
638 | } else { | ||
639 | mr = desc->pi_ctx->prot_mr; | ||
640 | frpl = desc->pi_ctx->prot_frpl; | ||
641 | } | ||
642 | |||
643 | plen = iser_sg_to_page_vec(mem, device->ib_device, frpl->page_list, | ||
472 | &offset, &size); | 644 | &offset, &size); |
473 | if (plen * SIZE_4K < size) { | 645 | if (plen * SIZE_4K < size) { |
474 | iser_err("fast reg page_list too short to hold this SG\n"); | 646 | iser_err("fast reg page_list too short to hold this SG\n"); |
475 | return -EINVAL; | 647 | return -EINVAL; |
476 | } | 648 | } |
477 | 649 | ||
478 | if (!(desc->reg_indicators & ISER_DATA_KEY_VALID)) { | 650 | if (!(desc->reg_indicators & ind)) { |
479 | memset(&inv_wr, 0, sizeof(inv_wr)); | 651 | memset(&inv_wr, 0, sizeof(inv_wr)); |
480 | inv_wr.wr_id = ISER_FASTREG_LI_WRID; | 652 | inv_wr.wr_id = ISER_FASTREG_LI_WRID; |
481 | inv_wr.opcode = IB_WR_LOCAL_INV; | 653 | inv_wr.opcode = IB_WR_LOCAL_INV; |
482 | inv_wr.ex.invalidate_rkey = desc->data_mr->rkey; | 654 | inv_wr.ex.invalidate_rkey = mr->rkey; |
483 | wr = &inv_wr; | 655 | wr = &inv_wr; |
484 | /* Bump the key */ | 656 | /* Bump the key */ |
485 | key = (u8)(desc->data_mr->rkey & 0x000000FF); | 657 | key = (u8)(mr->rkey & 0x000000FF); |
486 | ib_update_fast_reg_key(desc->data_mr, ++key); | 658 | ib_update_fast_reg_key(mr, ++key); |
487 | } | 659 | } |
488 | 660 | ||
489 | /* Prepare FASTREG WR */ | 661 | /* Prepare FASTREG WR */ |
490 | memset(&fastreg_wr, 0, sizeof(fastreg_wr)); | 662 | memset(&fastreg_wr, 0, sizeof(fastreg_wr)); |
491 | fastreg_wr.wr_id = ISER_FASTREG_LI_WRID; | 663 | fastreg_wr.wr_id = ISER_FASTREG_LI_WRID; |
492 | fastreg_wr.opcode = IB_WR_FAST_REG_MR; | 664 | fastreg_wr.opcode = IB_WR_FAST_REG_MR; |
493 | fastreg_wr.wr.fast_reg.iova_start = desc->data_frpl->page_list[0] + offset; | 665 | fastreg_wr.wr.fast_reg.iova_start = frpl->page_list[0] + offset; |
494 | fastreg_wr.wr.fast_reg.page_list = desc->data_frpl; | 666 | fastreg_wr.wr.fast_reg.page_list = frpl; |
495 | fastreg_wr.wr.fast_reg.page_list_len = plen; | 667 | fastreg_wr.wr.fast_reg.page_list_len = plen; |
496 | fastreg_wr.wr.fast_reg.page_shift = SHIFT_4K; | 668 | fastreg_wr.wr.fast_reg.page_shift = SHIFT_4K; |
497 | fastreg_wr.wr.fast_reg.length = size; | 669 | fastreg_wr.wr.fast_reg.length = size; |
498 | fastreg_wr.wr.fast_reg.rkey = desc->data_mr->rkey; | 670 | fastreg_wr.wr.fast_reg.rkey = mr->rkey; |
499 | fastreg_wr.wr.fast_reg.access_flags = (IB_ACCESS_LOCAL_WRITE | | 671 | fastreg_wr.wr.fast_reg.access_flags = (IB_ACCESS_LOCAL_WRITE | |
500 | IB_ACCESS_REMOTE_WRITE | | 672 | IB_ACCESS_REMOTE_WRITE | |
501 | IB_ACCESS_REMOTE_READ); | 673 | IB_ACCESS_REMOTE_READ); |
@@ -510,10 +682,10 @@ static int iser_fast_reg_mr(struct iscsi_iser_task *iser_task, | |||
510 | iser_err("fast registration failed, ret:%d\n", ret); | 682 | iser_err("fast registration failed, ret:%d\n", ret); |
511 | return ret; | 683 | return ret; |
512 | } | 684 | } |
513 | desc->reg_indicators &= ~ISER_DATA_KEY_VALID; | 685 | desc->reg_indicators &= ~ind; |
514 | 686 | ||
515 | sge->lkey = desc->data_mr->lkey; | 687 | sge->lkey = mr->lkey; |
516 | sge->addr = desc->data_frpl->page_list[0] + offset; | 688 | sge->addr = frpl->page_list[0] + offset; |
517 | sge->length = size; | 689 | sge->length = size; |
518 | 690 | ||
519 | return ret; | 691 | return ret; |
@@ -550,7 +722,8 @@ int iser_reg_rdma_mem_fastreg(struct iscsi_iser_task *iser_task, | |||
550 | mem = &iser_task->data_copy[cmd_dir]; | 722 | mem = &iser_task->data_copy[cmd_dir]; |
551 | } | 723 | } |
552 | 724 | ||
553 | if (mem->dma_nents != 1) { | 725 | if (mem->dma_nents != 1 || |
726 | scsi_get_prot_op(iser_task->sc) != SCSI_PROT_NORMAL) { | ||
554 | spin_lock_irqsave(&ib_conn->lock, flags); | 727 | spin_lock_irqsave(&ib_conn->lock, flags); |
555 | desc = list_first_entry(&ib_conn->fastreg.pool, | 728 | desc = list_first_entry(&ib_conn->fastreg.pool, |
556 | struct fast_reg_descriptor, list); | 729 | struct fast_reg_descriptor, list); |
@@ -559,21 +732,61 @@ int iser_reg_rdma_mem_fastreg(struct iscsi_iser_task *iser_task, | |||
559 | regd_buf->reg.mem_h = desc; | 732 | regd_buf->reg.mem_h = desc; |
560 | } | 733 | } |
561 | 734 | ||
562 | err = iser_fast_reg_mr(iser_task, regd_buf, mem, &data_sge); | 735 | err = iser_fast_reg_mr(iser_task, regd_buf, mem, |
736 | ISER_DATA_KEY_VALID, &data_sge); | ||
563 | if (err) | 737 | if (err) |
564 | goto err_reg; | 738 | goto err_reg; |
565 | 739 | ||
566 | if (desc) { | 740 | if (scsi_get_prot_op(iser_task->sc) != SCSI_PROT_NORMAL) { |
567 | regd_buf->reg.rkey = desc->data_mr->rkey; | 741 | struct ib_sge prot_sge, sig_sge; |
742 | |||
743 | memset(&prot_sge, 0, sizeof(prot_sge)); | ||
744 | if (scsi_prot_sg_count(iser_task->sc)) { | ||
745 | mem = &iser_task->prot[cmd_dir]; | ||
746 | aligned_len = iser_data_buf_aligned_len(mem, ibdev); | ||
747 | if (aligned_len != mem->dma_nents) { | ||
748 | err = fall_to_bounce_buf(iser_task, ibdev, mem, | ||
749 | &iser_task->prot_copy[cmd_dir], | ||
750 | cmd_dir, aligned_len); | ||
751 | if (err) { | ||
752 | iser_err("failed to allocate bounce buffer\n"); | ||
753 | return err; | ||
754 | } | ||
755 | mem = &iser_task->prot_copy[cmd_dir]; | ||
756 | } | ||
757 | |||
758 | err = iser_fast_reg_mr(iser_task, regd_buf, mem, | ||
759 | ISER_PROT_KEY_VALID, &prot_sge); | ||
760 | if (err) | ||
761 | goto err_reg; | ||
762 | } | ||
763 | |||
764 | err = iser_reg_sig_mr(iser_task, desc, &data_sge, | ||
765 | &prot_sge, &sig_sge); | ||
766 | if (err) { | ||
767 | iser_err("Failed to register signature mr\n"); | ||
768 | return err; | ||
769 | } | ||
770 | desc->reg_indicators |= ISER_FASTREG_PROTECTED; | ||
771 | |||
772 | regd_buf->reg.lkey = sig_sge.lkey; | ||
773 | regd_buf->reg.rkey = desc->pi_ctx->sig_mr->rkey; | ||
774 | regd_buf->reg.va = sig_sge.addr; | ||
775 | regd_buf->reg.len = sig_sge.length; | ||
568 | regd_buf->reg.is_mr = 1; | 776 | regd_buf->reg.is_mr = 1; |
569 | } else { | 777 | } else { |
570 | regd_buf->reg.rkey = device->mr->rkey; | 778 | if (desc) { |
571 | regd_buf->reg.is_mr = 0; | 779 | regd_buf->reg.rkey = desc->data_mr->rkey; |
572 | } | 780 | regd_buf->reg.is_mr = 1; |
781 | } else { | ||
782 | regd_buf->reg.rkey = device->mr->rkey; | ||
783 | regd_buf->reg.is_mr = 0; | ||
784 | } | ||
573 | 785 | ||
574 | regd_buf->reg.lkey = data_sge.lkey; | 786 | regd_buf->reg.lkey = data_sge.lkey; |
575 | regd_buf->reg.va = data_sge.addr; | 787 | regd_buf->reg.va = data_sge.addr; |
576 | regd_buf->reg.len = data_sge.length; | 788 | regd_buf->reg.len = data_sge.length; |
789 | } | ||
577 | 790 | ||
578 | return 0; | 791 | return 0; |
579 | err_reg: | 792 | err_reg: |