aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband
diff options
context:
space:
mode:
authorBart Van Assche <bvanassche@acm.org>2014-10-06 11:14:36 -0400
committerChristoph Hellwig <hch@lst.de>2014-11-12 06:05:24 -0500
commitd92c0da71a35dfddccca7bfa932829504311359e (patch)
tree84b87ede947430e8b53b33bf99c349c99243cb9d /drivers/infiniband
parent77f2c1a40e6fed202d08c8ec0bdca36a76dab368 (diff)
IB/srp: Add multichannel support
Improve performance by using multiple RDMA/RC channels per SCSI host for communication with an SRP target. About the implementation: - Introduce a loop over all channels in the code that uses target->ch. - Set the SRP_MULTICHAN_MULTI flag during login for the creation of the second and subsequent channels. - RDMA completion vectors are chosen such that RDMA completion interrupts are handled by the CPU socket that submitted the I/O request. As one can see in this patch it has been assumed if a system contains n CPU sockets and m RDMA completion vectors have been assigned to an RDMA HCA that IRQ affinity has been configured such that completion vectors [i*m/n..(i+1)*m/n) are bound to CPU socket i with 0 <= i < n. - Modify srp_free_ch_ib() and srp_free_req_data() such that it becomes safe to invoke these functions after the corresponding allocation function failed. - Add a ch_count sysfs attribute per target port. Signed-off-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Sagi Grimberg <sagig@mellanox.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'drivers/infiniband')
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c288
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.h3
2 files changed, 216 insertions, 75 deletions
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 42af59f3c8c6..aac844a6eef6 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -123,6 +123,11 @@ MODULE_PARM_DESC(dev_loss_tmo,
123 " if fast_io_fail_tmo has not been set. \"off\" means that" 123 " if fast_io_fail_tmo has not been set. \"off\" means that"
124 " this functionality is disabled."); 124 " this functionality is disabled.");
125 125
126static unsigned ch_count;
127module_param(ch_count, uint, 0444);
128MODULE_PARM_DESC(ch_count,
129 "Number of RDMA channels to use for communication with an SRP target. Using more than one channel improves performance if the HCA supports multiple completion vectors. The default value is the minimum of four times the number of online CPU sockets and the number of completion vectors supported by the HCA.");
130
126static void srp_add_one(struct ib_device *device); 131static void srp_add_one(struct ib_device *device);
127static void srp_remove_one(struct ib_device *device); 132static void srp_remove_one(struct ib_device *device);
128static void srp_recv_completion(struct ib_cq *cq, void *ch_ptr); 133static void srp_recv_completion(struct ib_cq *cq, void *ch_ptr);
@@ -562,11 +567,18 @@ static void srp_free_ch_ib(struct srp_target_port *target,
562 struct srp_device *dev = target->srp_host->srp_dev; 567 struct srp_device *dev = target->srp_host->srp_dev;
563 int i; 568 int i;
564 569
570 if (!ch->target)
571 return;
572
565 if (ch->cm_id) { 573 if (ch->cm_id) {
566 ib_destroy_cm_id(ch->cm_id); 574 ib_destroy_cm_id(ch->cm_id);
567 ch->cm_id = NULL; 575 ch->cm_id = NULL;
568 } 576 }
569 577
578 /* If srp_new_cm_id() succeeded but srp_create_ch_ib() not, return. */
579 if (!ch->qp)
580 return;
581
570 if (dev->use_fast_reg) { 582 if (dev->use_fast_reg) {
571 if (ch->fr_pool) 583 if (ch->fr_pool)
572 srp_destroy_fr_pool(ch->fr_pool); 584 srp_destroy_fr_pool(ch->fr_pool);
@@ -578,6 +590,14 @@ static void srp_free_ch_ib(struct srp_target_port *target,
578 ib_destroy_cq(ch->send_cq); 590 ib_destroy_cq(ch->send_cq);
579 ib_destroy_cq(ch->recv_cq); 591 ib_destroy_cq(ch->recv_cq);
580 592
593 /*
594 * Avoid that the SCSI error handler tries to use this channel after
595 * it has been freed. The SCSI error handler can namely continue
596 * trying to perform recovery actions after scsi_remove_host()
597 * returned.
598 */
599 ch->target = NULL;
600
581 ch->qp = NULL; 601 ch->qp = NULL;
582 ch->send_cq = ch->recv_cq = NULL; 602 ch->send_cq = ch->recv_cq = NULL;
583 603
@@ -647,7 +667,7 @@ static int srp_lookup_path(struct srp_rdma_ch *ch)
647 return ch->status; 667 return ch->status;
648} 668}
649 669
650static int srp_send_req(struct srp_rdma_ch *ch) 670static int srp_send_req(struct srp_rdma_ch *ch, bool multich)
651{ 671{
652 struct srp_target_port *target = ch->target; 672 struct srp_target_port *target = ch->target;
653 struct { 673 struct {
@@ -688,6 +708,8 @@ static int srp_send_req(struct srp_rdma_ch *ch)
688 req->priv.req_it_iu_len = cpu_to_be32(target->max_iu_len); 708 req->priv.req_it_iu_len = cpu_to_be32(target->max_iu_len);
689 req->priv.req_buf_fmt = cpu_to_be16(SRP_BUF_FORMAT_DIRECT | 709 req->priv.req_buf_fmt = cpu_to_be16(SRP_BUF_FORMAT_DIRECT |
690 SRP_BUF_FORMAT_INDIRECT); 710 SRP_BUF_FORMAT_INDIRECT);
711 req->priv.req_flags = (multich ? SRP_MULTICHAN_MULTI :
712 SRP_MULTICHAN_SINGLE);
691 /* 713 /*
692 * In the published SRP specification (draft rev. 16a), the 714 * In the published SRP specification (draft rev. 16a), the
693 * port identifier format is 8 bytes of ID extension followed 715 * port identifier format is 8 bytes of ID extension followed
@@ -769,14 +791,18 @@ static bool srp_change_conn_state(struct srp_target_port *target,
769 791
770static void srp_disconnect_target(struct srp_target_port *target) 792static void srp_disconnect_target(struct srp_target_port *target)
771{ 793{
772 struct srp_rdma_ch *ch = &target->ch; 794 struct srp_rdma_ch *ch;
795 int i;
773 796
774 if (srp_change_conn_state(target, false)) { 797 if (srp_change_conn_state(target, false)) {
775 /* XXX should send SRP_I_LOGOUT request */ 798 /* XXX should send SRP_I_LOGOUT request */
776 799
777 if (ib_send_cm_dreq(ch->cm_id, NULL, 0)) { 800 for (i = 0; i < target->ch_count; i++) {
778 shost_printk(KERN_DEBUG, target->scsi_host, 801 ch = &target->ch[i];
779 PFX "Sending CM DREQ failed\n"); 802 if (ch->cm_id && ib_send_cm_dreq(ch->cm_id, NULL, 0)) {
803 shost_printk(KERN_DEBUG, target->scsi_host,
804 PFX "Sending CM DREQ failed\n");
805 }
780 } 806 }
781 } 807 }
782} 808}
@@ -789,7 +815,7 @@ static void srp_free_req_data(struct srp_target_port *target,
789 struct srp_request *req; 815 struct srp_request *req;
790 int i; 816 int i;
791 817
792 if (!ch->req_ring) 818 if (!ch->target || !ch->req_ring)
793 return; 819 return;
794 820
795 for (i = 0; i < target->req_ring_size; ++i) { 821 for (i = 0; i < target->req_ring_size; ++i) {
@@ -875,7 +901,8 @@ static void srp_del_scsi_host_attr(struct Scsi_Host *shost)
875 901
876static void srp_remove_target(struct srp_target_port *target) 902static void srp_remove_target(struct srp_target_port *target)
877{ 903{
878 struct srp_rdma_ch *ch = &target->ch; 904 struct srp_rdma_ch *ch;
905 int i;
879 906
880 WARN_ON_ONCE(target->state != SRP_TARGET_REMOVED); 907 WARN_ON_ONCE(target->state != SRP_TARGET_REMOVED);
881 908
@@ -885,10 +912,18 @@ static void srp_remove_target(struct srp_target_port *target)
885 scsi_remove_host(target->scsi_host); 912 scsi_remove_host(target->scsi_host);
886 srp_stop_rport_timers(target->rport); 913 srp_stop_rport_timers(target->rport);
887 srp_disconnect_target(target); 914 srp_disconnect_target(target);
888 srp_free_ch_ib(target, ch); 915 for (i = 0; i < target->ch_count; i++) {
916 ch = &target->ch[i];
917 srp_free_ch_ib(target, ch);
918 }
889 cancel_work_sync(&target->tl_err_work); 919 cancel_work_sync(&target->tl_err_work);
890 srp_rport_put(target->rport); 920 srp_rport_put(target->rport);
891 srp_free_req_data(target, ch); 921 for (i = 0; i < target->ch_count; i++) {
922 ch = &target->ch[i];
923 srp_free_req_data(target, ch);
924 }
925 kfree(target->ch);
926 target->ch = NULL;
892 927
893 spin_lock(&target->srp_host->target_lock); 928 spin_lock(&target->srp_host->target_lock);
894 list_del(&target->list); 929 list_del(&target->list);
@@ -914,12 +949,12 @@ static void srp_rport_delete(struct srp_rport *rport)
914 srp_queue_remove_work(target); 949 srp_queue_remove_work(target);
915} 950}
916 951
917static int srp_connect_ch(struct srp_rdma_ch *ch) 952static int srp_connect_ch(struct srp_rdma_ch *ch, bool multich)
918{ 953{
919 struct srp_target_port *target = ch->target; 954 struct srp_target_port *target = ch->target;
920 int ret; 955 int ret;
921 956
922 WARN_ON_ONCE(target->connected); 957 WARN_ON_ONCE(!multich && target->connected);
923 958
924 target->qp_in_error = false; 959 target->qp_in_error = false;
925 960
@@ -929,7 +964,7 @@ static int srp_connect_ch(struct srp_rdma_ch *ch)
929 964
930 while (1) { 965 while (1) {
931 init_completion(&ch->done); 966 init_completion(&ch->done);
932 ret = srp_send_req(ch); 967 ret = srp_send_req(ch, multich);
933 if (ret) 968 if (ret)
934 return ret; 969 return ret;
935 ret = wait_for_completion_interruptible(&ch->done); 970 ret = wait_for_completion_interruptible(&ch->done);
@@ -1090,10 +1125,10 @@ static void srp_finish_req(struct srp_rdma_ch *ch, struct srp_request *req,
1090static void srp_terminate_io(struct srp_rport *rport) 1125static void srp_terminate_io(struct srp_rport *rport)
1091{ 1126{
1092 struct srp_target_port *target = rport->lld_data; 1127 struct srp_target_port *target = rport->lld_data;
1093 struct srp_rdma_ch *ch = &target->ch; 1128 struct srp_rdma_ch *ch;
1094 struct Scsi_Host *shost = target->scsi_host; 1129 struct Scsi_Host *shost = target->scsi_host;
1095 struct scsi_device *sdev; 1130 struct scsi_device *sdev;
1096 int i; 1131 int i, j;
1097 1132
1098 /* 1133 /*
1099 * Invoking srp_terminate_io() while srp_queuecommand() is running 1134 * Invoking srp_terminate_io() while srp_queuecommand() is running
@@ -1102,10 +1137,15 @@ static void srp_terminate_io(struct srp_rport *rport)
1102 shost_for_each_device(sdev, shost) 1137 shost_for_each_device(sdev, shost)
1103 WARN_ON_ONCE(sdev->request_queue->request_fn_active); 1138 WARN_ON_ONCE(sdev->request_queue->request_fn_active);
1104 1139
1105 for (i = 0; i < target->req_ring_size; ++i) { 1140 for (i = 0; i < target->ch_count; i++) {
1106 struct srp_request *req = &ch->req_ring[i]; 1141 ch = &target->ch[i];
1107 1142
1108 srp_finish_req(ch, req, NULL, DID_TRANSPORT_FAILFAST << 16); 1143 for (j = 0; j < target->req_ring_size; ++j) {
1144 struct srp_request *req = &ch->req_ring[j];
1145
1146 srp_finish_req(ch, req, NULL,
1147 DID_TRANSPORT_FAILFAST << 16);
1148 }
1109 } 1149 }
1110} 1150}
1111 1151
@@ -1121,8 +1161,9 @@ static void srp_terminate_io(struct srp_rport *rport)
1121static int srp_rport_reconnect(struct srp_rport *rport) 1161static int srp_rport_reconnect(struct srp_rport *rport)
1122{ 1162{
1123 struct srp_target_port *target = rport->lld_data; 1163 struct srp_target_port *target = rport->lld_data;
1124 struct srp_rdma_ch *ch = &target->ch; 1164 struct srp_rdma_ch *ch;
1125 int i, ret; 1165 int i, j, ret = 0;
1166 bool multich = false;
1126 1167
1127 srp_disconnect_target(target); 1168 srp_disconnect_target(target);
1128 1169
@@ -1134,27 +1175,47 @@ static int srp_rport_reconnect(struct srp_rport *rport)
1134 * case things are really fouled up. Doing so also ensures that all CM 1175 * case things are really fouled up. Doing so also ensures that all CM
1135 * callbacks will have finished before a new QP is allocated. 1176 * callbacks will have finished before a new QP is allocated.
1136 */ 1177 */
1137 ret = srp_new_cm_id(ch); 1178 for (i = 0; i < target->ch_count; i++) {
1138 1179 ch = &target->ch[i];
1139 for (i = 0; i < target->req_ring_size; ++i) { 1180 if (!ch->target)
1140 struct srp_request *req = &ch->req_ring[i]; 1181 break;
1141 1182 ret += srp_new_cm_id(ch);
1142 srp_finish_req(ch, req, NULL, DID_RESET << 16);
1143 } 1183 }
1184 for (i = 0; i < target->ch_count; i++) {
1185 ch = &target->ch[i];
1186 if (!ch->target)
1187 break;
1188 for (j = 0; j < target->req_ring_size; ++j) {
1189 struct srp_request *req = &ch->req_ring[j];
1144 1190
1145 /* 1191 srp_finish_req(ch, req, NULL, DID_RESET << 16);
1146 * Whether or not creating a new CM ID succeeded, create a new 1192 }
1147 * QP. This guarantees that all callback functions for the old QP have 1193 }
1148 * finished before any send requests are posted on the new QP. 1194 for (i = 0; i < target->ch_count; i++) {
1149 */ 1195 ch = &target->ch[i];
1150 ret += srp_create_ch_ib(ch); 1196 if (!ch->target)
1151 1197 break;
1152 INIT_LIST_HEAD(&ch->free_tx); 1198 /*
1153 for (i = 0; i < target->queue_size; ++i) 1199 * Whether or not creating a new CM ID succeeded, create a new
1154 list_add(&ch->tx_ring[i]->list, &ch->free_tx); 1200 * QP. This guarantees that all completion callback function
1201 * invocations have finished before request resetting starts.
1202 */
1203 ret += srp_create_ch_ib(ch);
1155 1204
1156 if (ret == 0) 1205 INIT_LIST_HEAD(&ch->free_tx);
1157 ret = srp_connect_ch(ch); 1206 for (j = 0; j < target->queue_size; ++j)
1207 list_add(&ch->tx_ring[j]->list, &ch->free_tx);
1208 }
1209 for (i = 0; i < target->ch_count; i++) {
1210 ch = &target->ch[i];
1211 if (ret || !ch->target) {
1212 if (i > 1)
1213 ret = 0;
1214 break;
1215 }
1216 ret = srp_connect_ch(ch, multich);
1217 multich = true;
1218 }
1158 1219
1159 if (ret == 0) 1220 if (ret == 0)
1160 shost_printk(KERN_INFO, target->scsi_host, 1221 shost_printk(KERN_INFO, target->scsi_host,
@@ -1650,8 +1711,8 @@ static void srp_process_rsp(struct srp_rdma_ch *ch, struct srp_rsp *rsp)
1650 } 1711 }
1651 if (!scmnd) { 1712 if (!scmnd) {
1652 shost_printk(KERN_ERR, target->scsi_host, 1713 shost_printk(KERN_ERR, target->scsi_host,
1653 "Null scmnd for RSP w/tag %016llx\n", 1714 "Null scmnd for RSP w/tag %#016llx received on ch %td / QP %#x\n",
1654 (unsigned long long) rsp->tag); 1715 rsp->tag, ch - target->ch, ch->qp->qp_num);
1655 1716
1656 spin_lock_irqsave(&ch->lock, flags); 1717 spin_lock_irqsave(&ch->lock, flags);
1657 ch->req_lim += be32_to_cpu(rsp->req_lim_delta); 1718 ch->req_lim += be32_to_cpu(rsp->req_lim_delta);
@@ -1907,7 +1968,7 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd)
1907 1968
1908 WARN_ON_ONCE(scmnd->request->tag < 0); 1969 WARN_ON_ONCE(scmnd->request->tag < 0);
1909 tag = blk_mq_unique_tag(scmnd->request); 1970 tag = blk_mq_unique_tag(scmnd->request);
1910 ch = &target->ch; 1971 ch = &target->ch[blk_mq_unique_tag_to_hwq(tag)];
1911 idx = blk_mq_unique_tag_to_tag(tag); 1972 idx = blk_mq_unique_tag_to_tag(tag);
1912 WARN_ONCE(idx >= target->req_ring_size, "%s: tag %#x: idx %d >= %d\n", 1973 WARN_ONCE(idx >= target->req_ring_size, "%s: tag %#x: idx %d >= %d\n",
1913 dev_name(&shost->shost_gendev), tag, idx, 1974 dev_name(&shost->shost_gendev), tag, idx,
@@ -2387,15 +2448,23 @@ static int srp_abort(struct scsi_cmnd *scmnd)
2387 struct srp_target_port *target = host_to_target(scmnd->device->host); 2448 struct srp_target_port *target = host_to_target(scmnd->device->host);
2388 struct srp_request *req = (struct srp_request *) scmnd->host_scribble; 2449 struct srp_request *req = (struct srp_request *) scmnd->host_scribble;
2389 u32 tag; 2450 u32 tag;
2451 u16 ch_idx;
2390 struct srp_rdma_ch *ch; 2452 struct srp_rdma_ch *ch;
2391 int ret; 2453 int ret;
2392 2454
2393 shost_printk(KERN_ERR, target->scsi_host, "SRP abort called\n"); 2455 shost_printk(KERN_ERR, target->scsi_host, "SRP abort called\n");
2394 2456
2395 ch = &target->ch; 2457 if (!req)
2396 if (!req || !srp_claim_req(ch, req, NULL, scmnd))
2397 return SUCCESS; 2458 return SUCCESS;
2398 tag = blk_mq_unique_tag(scmnd->request); 2459 tag = blk_mq_unique_tag(scmnd->request);
2460 ch_idx = blk_mq_unique_tag_to_hwq(tag);
2461 if (WARN_ON_ONCE(ch_idx >= target->ch_count))
2462 return SUCCESS;
2463 ch = &target->ch[ch_idx];
2464 if (!srp_claim_req(ch, req, NULL, scmnd))
2465 return SUCCESS;
2466 shost_printk(KERN_ERR, target->scsi_host,
2467 "Sending SRP abort for tag %#x\n", tag);
2399 if (srp_send_tsk_mgmt(ch, tag, scmnd->device->lun, 2468 if (srp_send_tsk_mgmt(ch, tag, scmnd->device->lun,
2400 SRP_TSK_ABORT_TASK) == 0) 2469 SRP_TSK_ABORT_TASK) == 0)
2401 ret = SUCCESS; 2470 ret = SUCCESS;
@@ -2413,21 +2482,25 @@ static int srp_abort(struct scsi_cmnd *scmnd)
2413static int srp_reset_device(struct scsi_cmnd *scmnd) 2482static int srp_reset_device(struct scsi_cmnd *scmnd)
2414{ 2483{
2415 struct srp_target_port *target = host_to_target(scmnd->device->host); 2484 struct srp_target_port *target = host_to_target(scmnd->device->host);
2416 struct srp_rdma_ch *ch = &target->ch; 2485 struct srp_rdma_ch *ch;
2417 int i; 2486 int i;
2418 2487
2419 shost_printk(KERN_ERR, target->scsi_host, "SRP reset_device called\n"); 2488 shost_printk(KERN_ERR, target->scsi_host, "SRP reset_device called\n");
2420 2489
2490 ch = &target->ch[0];
2421 if (srp_send_tsk_mgmt(ch, SRP_TAG_NO_REQ, scmnd->device->lun, 2491 if (srp_send_tsk_mgmt(ch, SRP_TAG_NO_REQ, scmnd->device->lun,
2422 SRP_TSK_LUN_RESET)) 2492 SRP_TSK_LUN_RESET))
2423 return FAILED; 2493 return FAILED;
2424 if (ch->tsk_mgmt_status) 2494 if (ch->tsk_mgmt_status)
2425 return FAILED; 2495 return FAILED;
2426 2496
2427 for (i = 0; i < target->req_ring_size; ++i) { 2497 for (i = 0; i < target->ch_count; i++) {
2428 struct srp_request *req = &ch->req_ring[i]; 2498 ch = &target->ch[i];
2499 for (i = 0; i < target->req_ring_size; ++i) {
2500 struct srp_request *req = &ch->req_ring[i];
2429 2501
2430 srp_finish_req(ch, req, scmnd->device, DID_RESET << 16); 2502 srp_finish_req(ch, req, scmnd->device, DID_RESET << 16);
2503 }
2431 } 2504 }
2432 2505
2433 return SUCCESS; 2506 return SUCCESS;
@@ -2504,7 +2577,7 @@ static ssize_t show_dgid(struct device *dev, struct device_attribute *attr,
2504 char *buf) 2577 char *buf)
2505{ 2578{
2506 struct srp_target_port *target = host_to_target(class_to_shost(dev)); 2579 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2507 struct srp_rdma_ch *ch = &target->ch; 2580 struct srp_rdma_ch *ch = &target->ch[0];
2508 2581
2509 return sprintf(buf, "%pI6\n", ch->path.dgid.raw); 2582 return sprintf(buf, "%pI6\n", ch->path.dgid.raw);
2510} 2583}
@@ -2521,8 +2594,14 @@ static ssize_t show_req_lim(struct device *dev,
2521 struct device_attribute *attr, char *buf) 2594 struct device_attribute *attr, char *buf)
2522{ 2595{
2523 struct srp_target_port *target = host_to_target(class_to_shost(dev)); 2596 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2597 struct srp_rdma_ch *ch;
2598 int i, req_lim = INT_MAX;
2524 2599
2525 return sprintf(buf, "%d\n", target->ch.req_lim); 2600 for (i = 0; i < target->ch_count; i++) {
2601 ch = &target->ch[i];
2602 req_lim = min(req_lim, ch->req_lim);
2603 }
2604 return sprintf(buf, "%d\n", req_lim);
2526} 2605}
2527 2606
2528static ssize_t show_zero_req_lim(struct device *dev, 2607static ssize_t show_zero_req_lim(struct device *dev,
@@ -2549,6 +2628,14 @@ static ssize_t show_local_ib_device(struct device *dev,
2549 return sprintf(buf, "%s\n", target->srp_host->srp_dev->dev->name); 2628 return sprintf(buf, "%s\n", target->srp_host->srp_dev->dev->name);
2550} 2629}
2551 2630
2631static ssize_t show_ch_count(struct device *dev, struct device_attribute *attr,
2632 char *buf)
2633{
2634 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2635
2636 return sprintf(buf, "%d\n", target->ch_count);
2637}
2638
2552static ssize_t show_comp_vector(struct device *dev, 2639static ssize_t show_comp_vector(struct device *dev,
2553 struct device_attribute *attr, char *buf) 2640 struct device_attribute *attr, char *buf)
2554{ 2641{
@@ -2592,6 +2679,7 @@ static DEVICE_ATTR(req_lim, S_IRUGO, show_req_lim, NULL);
2592static DEVICE_ATTR(zero_req_lim, S_IRUGO, show_zero_req_lim, NULL); 2679static DEVICE_ATTR(zero_req_lim, S_IRUGO, show_zero_req_lim, NULL);
2593static DEVICE_ATTR(local_ib_port, S_IRUGO, show_local_ib_port, NULL); 2680static DEVICE_ATTR(local_ib_port, S_IRUGO, show_local_ib_port, NULL);
2594static DEVICE_ATTR(local_ib_device, S_IRUGO, show_local_ib_device, NULL); 2681static DEVICE_ATTR(local_ib_device, S_IRUGO, show_local_ib_device, NULL);
2682static DEVICE_ATTR(ch_count, S_IRUGO, show_ch_count, NULL);
2595static DEVICE_ATTR(comp_vector, S_IRUGO, show_comp_vector, NULL); 2683static DEVICE_ATTR(comp_vector, S_IRUGO, show_comp_vector, NULL);
2596static DEVICE_ATTR(tl_retry_count, S_IRUGO, show_tl_retry_count, NULL); 2684static DEVICE_ATTR(tl_retry_count, S_IRUGO, show_tl_retry_count, NULL);
2597static DEVICE_ATTR(cmd_sg_entries, S_IRUGO, show_cmd_sg_entries, NULL); 2685static DEVICE_ATTR(cmd_sg_entries, S_IRUGO, show_cmd_sg_entries, NULL);
@@ -2609,6 +2697,7 @@ static struct device_attribute *srp_host_attrs[] = {
2609 &dev_attr_zero_req_lim, 2697 &dev_attr_zero_req_lim,
2610 &dev_attr_local_ib_port, 2698 &dev_attr_local_ib_port,
2611 &dev_attr_local_ib_device, 2699 &dev_attr_local_ib_device,
2700 &dev_attr_ch_count,
2612 &dev_attr_comp_vector, 2701 &dev_attr_comp_vector,
2613 &dev_attr_tl_retry_count, 2702 &dev_attr_tl_retry_count,
2614 &dev_attr_cmd_sg_entries, 2703 &dev_attr_cmd_sg_entries,
@@ -3018,7 +3107,8 @@ static ssize_t srp_create_target(struct device *dev,
3018 struct srp_rdma_ch *ch; 3107 struct srp_rdma_ch *ch;
3019 struct srp_device *srp_dev = host->srp_dev; 3108 struct srp_device *srp_dev = host->srp_dev;
3020 struct ib_device *ibdev = srp_dev->dev; 3109 struct ib_device *ibdev = srp_dev->dev;
3021 int ret; 3110 int ret, node_idx, node, cpu, i;
3111 bool multich = false;
3022 3112
3023 target_host = scsi_host_alloc(&srp_template, 3113 target_host = scsi_host_alloc(&srp_template,
3024 sizeof (struct srp_target_port)); 3114 sizeof (struct srp_target_port));
@@ -3088,34 +3178,82 @@ static ssize_t srp_create_target(struct device *dev,
3088 INIT_WORK(&target->tl_err_work, srp_tl_err_work); 3178 INIT_WORK(&target->tl_err_work, srp_tl_err_work);
3089 INIT_WORK(&target->remove_work, srp_remove_work); 3179 INIT_WORK(&target->remove_work, srp_remove_work);
3090 spin_lock_init(&target->lock); 3180 spin_lock_init(&target->lock);
3091 ch = &target->ch;
3092 ch->target = target;
3093 ch->comp_vector = target->comp_vector;
3094 spin_lock_init(&ch->lock);
3095 INIT_LIST_HEAD(&ch->free_tx);
3096 ret = srp_alloc_req_data(ch);
3097 if (ret)
3098 goto err_free_mem;
3099
3100 ret = ib_query_gid(ibdev, host->port, 0, &target->sgid); 3181 ret = ib_query_gid(ibdev, host->port, 0, &target->sgid);
3101 if (ret) 3182 if (ret)
3102 goto err_free_mem; 3183 goto err;
3103 3184
3104 ret = srp_create_ch_ib(ch); 3185 ret = -ENOMEM;
3105 if (ret) 3186 target->ch_count = max_t(unsigned, num_online_nodes(),
3106 goto err_free_mem; 3187 min(ch_count ? :
3188 min(4 * num_online_nodes(),
3189 ibdev->num_comp_vectors),
3190 num_online_cpus()));
3191 target->ch = kcalloc(target->ch_count, sizeof(*target->ch),
3192 GFP_KERNEL);
3193 if (!target->ch)
3194 goto err;
3107 3195
3108 ret = srp_new_cm_id(ch); 3196 node_idx = 0;
3109 if (ret) 3197 for_each_online_node(node) {
3110 goto err_free_ib; 3198 const int ch_start = (node_idx * target->ch_count /
3199 num_online_nodes());
3200 const int ch_end = ((node_idx + 1) * target->ch_count /
3201 num_online_nodes());
3202 const int cv_start = (node_idx * ibdev->num_comp_vectors /
3203 num_online_nodes() + target->comp_vector)
3204 % ibdev->num_comp_vectors;
3205 const int cv_end = ((node_idx + 1) * ibdev->num_comp_vectors /
3206 num_online_nodes() + target->comp_vector)
3207 % ibdev->num_comp_vectors;
3208 int cpu_idx = 0;
3209
3210 for_each_online_cpu(cpu) {
3211 if (cpu_to_node(cpu) != node)
3212 continue;
3213 if (ch_start + cpu_idx >= ch_end)
3214 continue;
3215 ch = &target->ch[ch_start + cpu_idx];
3216 ch->target = target;
3217 ch->comp_vector = cv_start == cv_end ? cv_start :
3218 cv_start + cpu_idx % (cv_end - cv_start);
3219 spin_lock_init(&ch->lock);
3220 INIT_LIST_HEAD(&ch->free_tx);
3221 ret = srp_new_cm_id(ch);
3222 if (ret)
3223 goto err_disconnect;
3111 3224
3112 ret = srp_connect_ch(ch); 3225 ret = srp_create_ch_ib(ch);
3113 if (ret) { 3226 if (ret)
3114 shost_printk(KERN_ERR, target->scsi_host, 3227 goto err_disconnect;
3115 PFX "Connection failed\n"); 3228
3116 goto err_free_ib; 3229 ret = srp_alloc_req_data(ch);
3230 if (ret)
3231 goto err_disconnect;
3232
3233 ret = srp_connect_ch(ch, multich);
3234 if (ret) {
3235 shost_printk(KERN_ERR, target->scsi_host,
3236 PFX "Connection %d/%d failed\n",
3237 ch_start + cpu_idx,
3238 target->ch_count);
3239 if (node_idx == 0 && cpu_idx == 0) {
3240 goto err_disconnect;
3241 } else {
3242 srp_free_ch_ib(target, ch);
3243 srp_free_req_data(target, ch);
3244 target->ch_count = ch - target->ch;
3245 break;
3246 }
3247 }
3248
3249 multich = true;
3250 cpu_idx++;
3251 }
3252 node_idx++;
3117 } 3253 }
3118 3254
3255 target->scsi_host->nr_hw_queues = target->ch_count;
3256
3119 ret = srp_add_target(host, target); 3257 ret = srp_add_target(host, target);
3120 if (ret) 3258 if (ret)
3121 goto err_disconnect; 3259 goto err_disconnect;
@@ -3142,11 +3280,13 @@ out:
3142err_disconnect: 3280err_disconnect:
3143 srp_disconnect_target(target); 3281 srp_disconnect_target(target);
3144 3282
3145err_free_ib: 3283 for (i = 0; i < target->ch_count; i++) {
3146 srp_free_ch_ib(target, ch); 3284 ch = &target->ch[i];
3285 srp_free_ch_ib(target, ch);
3286 srp_free_req_data(target, ch);
3287 }
3147 3288
3148err_free_mem: 3289 kfree(target->ch);
3149 srp_free_req_data(target, ch);
3150 3290
3151err: 3291err:
3152 scsi_host_put(target_host); 3292 scsi_host_put(target_host);
diff --git a/drivers/infiniband/ulp/srp/ib_srp.h b/drivers/infiniband/ulp/srp/ib_srp.h
index 37aa9f49947a..ca7c6f065434 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.h
+++ b/drivers/infiniband/ulp/srp/ib_srp.h
@@ -179,8 +179,9 @@ struct srp_target_port {
179 /* read and written in the hot path */ 179 /* read and written in the hot path */
180 spinlock_t lock; 180 spinlock_t lock;
181 181
182 struct srp_rdma_ch ch;
183 /* read only in the hot path */ 182 /* read only in the hot path */
183 struct srp_rdma_ch *ch;
184 u32 ch_count;
184 u32 lkey; 185 u32 lkey;
185 u32 rkey; 186 u32 rkey;
186 enum srp_target_state state; 187 enum srp_target_state state;