Lines Matching defs:cb
251 struct krping_cb *cb = cma_id->context;
254 (cma_id == cb->cm_id) ? "parent" : "child");
258 cb->state = ADDR_RESOLVED;
263 wake_up_interruptible(&cb->sem);
268 cb->state = ROUTE_RESOLVED;
269 wake_up_interruptible(&cb->sem);
273 cb->state = CONNECT_REQUEST;
274 cb->child_cm_id = cma_id;
275 DEBUG_LOG("child cma %p\n", cb->child_cm_id);
276 wake_up_interruptible(&cb->sem);
281 if (!cb->server) {
282 cb->state = CONNECTED;
284 wake_up_interruptible(&cb->sem);
294 cb->state = ERROR;
295 wake_up_interruptible(&cb->sem);
300 cb->state = ERROR;
301 wake_up_interruptible(&cb->sem);
306 cb->state = ERROR;
307 wake_up_interruptible(&cb->sem);
312 wake_up_interruptible(&cb->sem);
318 static int server_recv(struct krping_cb *cb, struct ib_wc *wc)
320 if (wc->byte_len != sizeof(cb->recv_buf)) {
326 cb->remote_rkey = ntohl(cb->recv_buf.rkey);
327 cb->remote_addr = ntohll(cb->recv_buf.buf);
328 cb->remote_len = ntohl(cb->recv_buf.size);
330 cb->remote_rkey, (unsigned long long)cb->remote_addr,
331 cb->remote_len);
333 if (cb->state <= CONNECTED || cb->state == RDMA_WRITE_COMPLETE)
334 cb->state = RDMA_READ_ADV;
336 cb->state = RDMA_WRITE_ADV;
341 static int client_recv(struct krping_cb *cb, struct ib_wc *wc)
343 if (wc->byte_len != sizeof(cb->recv_buf)) {
349 if (cb->state == RDMA_READ_ADV)
350 cb->state = RDMA_WRITE_ADV;
352 cb->state = RDMA_WRITE_COMPLETE;
359 struct krping_cb *cb = ctx;
364 BUG_ON(cb->cq != cq);
365 if (cb->frtest) {
369 if (!cb->wlat && !cb->rlat && !cb->bw)
370 ib_req_notify_cq(cb->cq, IB_CQ_NEXT_COMP);
371 while ((ret = ib_poll_cq(cb->cq, 1, &wc)) == 1) {
383 if (cb->state == ERROR) {
390 cb->stats.send_bytes += cb->send_sgl.length;
391 cb->stats.send_msgs++;
396 cb->stats.write_bytes += cb->rdma_sq_wr.wr.sg_list->length;
397 cb->stats.write_msgs++;
398 cb->state = RDMA_WRITE_COMPLETE;
399 wake_up_interruptible(&cb->sem);
404 cb->stats.read_bytes += cb->rdma_sq_wr.wr.sg_list->length;
405 cb->stats.read_msgs++;
406 cb->state = RDMA_READ_COMPLETE;
407 wake_up_interruptible(&cb->sem);
412 cb->stats.recv_bytes += sizeof(cb->recv_buf);
413 cb->stats.recv_msgs++;
414 if (cb->wlat || cb->rlat || cb->bw)
415 ret = server_recv(cb, &wc);
417 ret = cb->server ? server_recv(cb, &wc) :
418 client_recv(cb, &wc);
424 ret = ib_post_recv(cb->qp, &cb->rq_wr, &bad_wr);
430 wake_up_interruptible(&cb->sem);
446 cb->state = ERROR;
447 wake_up_interruptible(&cb->sem);
450 static int krping_accept(struct krping_cb *cb)
461 ret = rdma_accept(cb->child_cm_id, &conn_param);
467 if (!cb->wlat && !cb->rlat && !cb->bw) {
468 wait_event_interruptible(cb->sem, cb->state >= CONNECTED);
469 if (cb->state == ERROR) {
471 cb->state);
478 static void krping_setup_wr(struct krping_cb *cb)
480 cb->recv_sgl.addr = cb->recv_dma_addr;
481 cb->recv_sgl.length = sizeof cb->recv_buf;
482 cb->recv_sgl.lkey = cb->pd->local_dma_lkey;
483 cb->rq_wr.sg_list = &cb->recv_sgl;
484 cb->rq_wr.num_sge = 1;
486 cb->send_sgl.addr = cb->send_dma_addr;
487 cb->send_sgl.length = sizeof cb->send_buf;
488 cb->send_sgl.lkey = cb->pd->local_dma_lkey;
490 cb->sq_wr.opcode = IB_WR_SEND;
491 cb->sq_wr.send_flags = IB_SEND_SIGNALED;
492 cb->sq_wr.sg_list = &cb->send_sgl;
493 cb->sq_wr.num_sge = 1;
495 if (cb->server || cb->wlat || cb->rlat || cb->bw) {
496 cb->rdma_sgl.addr = cb->rdma_dma_addr;
497 cb->rdma_sq_wr.wr.send_flags = IB_SEND_SIGNALED;
498 cb->rdma_sq_wr.wr.sg_list = &cb->rdma_sgl;
499 cb->rdma_sq_wr.wr.num_sge = 1;
507 cb->reg_mr_wr.wr.opcode = IB_WR_REG_MR;
508 cb->reg_mr_wr.mr = cb->reg_mr;
510 cb->invalidate_wr.next = &cb->reg_mr_wr.wr;
511 cb->invalidate_wr.opcode = IB_WR_LOCAL_INV;
514 static int krping_setup_buffers(struct krping_cb *cb)
518 DEBUG_LOG(PFX "krping_setup_buffers called on cb %p\n", cb);
520 cb->recv_dma_addr = ib_dma_map_single(cb->pd->device,
521 &cb->recv_buf,
522 sizeof(cb->recv_buf), DMA_BIDIRECTIONAL);
523 pci_unmap_addr_set(cb, recv_mapping, cb->recv_dma_addr);
524 cb->send_dma_addr = ib_dma_map_single(cb->pd->device,
525 &cb->send_buf, sizeof(cb->send_buf),
527 pci_unmap_addr_set(cb, send_mapping, cb->send_dma_addr);
529 cb->rdma_buf = ib_dma_alloc_coherent(cb->pd->device, cb->size,
530 &cb->rdma_dma_addr,
532 if (!cb->rdma_buf) {
537 pci_unmap_addr_set(cb, rdma_mapping, cb->rdma_dma_addr);
538 cb->page_list_len = (((cb->size - 1) & PAGE_MASK) + PAGE_SIZE)
540 cb->reg_mr = ib_alloc_mr(cb->pd, IB_MR_TYPE_MEM_REG,
541 cb->page_list_len);
542 if (IS_ERR(cb->reg_mr)) {
543 ret = PTR_ERR(cb->reg_mr);
548 cb->reg_mr->rkey, cb->page_list_len);
550 if (!cb->server || cb->wlat || cb->rlat || cb->bw) {
552 cb->start_buf = ib_dma_alloc_coherent(cb->pd->device, cb->size,
553 &cb->start_dma_addr,
555 if (!cb->start_buf) {
560 pci_unmap_addr_set(cb, start_mapping, cb->start_dma_addr);
563 krping_setup_wr(cb);
567 if (cb->reg_mr && !IS_ERR(cb->reg_mr))
568 ib_dereg_mr(cb->reg_mr);
569 if (cb->rdma_mr && !IS_ERR(cb->rdma_mr))
570 ib_dereg_mr(cb->rdma_mr);
571 if (cb->dma_mr && !IS_ERR(cb->dma_mr))
572 ib_dereg_mr(cb->dma_mr);
573 if (cb->rdma_buf) {
574 ib_dma_free_coherent(cb->pd->device, cb->size, cb->rdma_buf,
575 cb->rdma_dma_addr);
577 if (cb->start_buf) {
578 ib_dma_free_coherent(cb->pd->device, cb->size, cb->start_buf,
579 cb->start_dma_addr);
584 static void krping_free_buffers(struct krping_cb *cb)
586 DEBUG_LOG("krping_free_buffers called on cb %p\n", cb);
588 if (cb->dma_mr)
589 ib_dereg_mr(cb->dma_mr);
590 if (cb->rdma_mr)
591 ib_dereg_mr(cb->rdma_mr);
592 if (cb->start_mr)
593 ib_dereg_mr(cb->start_mr);
594 if (cb->reg_mr)
595 ib_dereg_mr(cb->reg_mr);
597 dma_unmap_single(cb->pd->device->dma_device,
598 pci_unmap_addr(cb, recv_mapping),
599 sizeof(cb->recv_buf), DMA_BIDIRECTIONAL);
600 dma_unmap_single(cb->pd->device->dma_device,
601 pci_unmap_addr(cb, send_mapping),
602 sizeof(cb->send_buf), DMA_BIDIRECTIONAL);
604 ib_dma_free_coherent(cb->pd->device, cb->size, cb->rdma_buf,
605 cb->rdma_dma_addr);
607 if (cb->start_buf) {
608 ib_dma_free_coherent(cb->pd->device, cb->size, cb->start_buf,
609 cb->start_dma_addr);
613 static int krping_create_qp(struct krping_cb *cb)
619 init_attr.cap.max_send_wr = cb->txdepth;
629 init_attr.send_cq = cb->cq;
630 init_attr.recv_cq = cb->cq;
633 if (cb->server) {
634 ret = rdma_create_qp(cb->child_cm_id, cb->pd, &init_attr);
636 cb->qp = cb->child_cm_id->qp;
638 ret = rdma_create_qp(cb->cm_id, cb->pd, &init_attr);
640 cb->qp = cb->cm_id->qp;
646 static void krping_free_qp(struct krping_cb *cb)
648 ib_destroy_qp(cb->qp);
649 ib_destroy_cq(cb->cq);
650 ib_dealloc_pd(cb->pd);
653 static int krping_setup_qp(struct krping_cb *cb, struct rdma_cm_id *cm_id)
658 cb->pd = ib_alloc_pd(cm_id->device, 0);
659 if (IS_ERR(cb->pd)) {
661 return PTR_ERR(cb->pd);
663 DEBUG_LOG("created pd %p\n", cb->pd);
665 strlcpy(cb->stats.name, cb->pd->device->name, sizeof(cb->stats.name));
667 attr.cqe = cb->txdepth * 2;
669 cb->cq = ib_create_cq(cm_id->device, krping_cq_event_handler, NULL,
670 cb, &attr);
671 if (IS_ERR(cb->cq)) {
673 ret = PTR_ERR(cb->cq);
676 DEBUG_LOG("created cq %p\n", cb->cq);
678 if (!cb->wlat && !cb->rlat && !cb->bw && !cb->frtest) {
679 ret = ib_req_notify_cq(cb->cq, IB_CQ_NEXT_COMP);
686 ret = krping_create_qp(cb);
691 DEBUG_LOG("created qp %p\n", cb->qp);
694 ib_destroy_cq(cb->cq);
696 ib_dealloc_pd(cb->pd);
705 static u32 krping_rdma_rkey(struct krping_cb *cb, u64 buf, int post_inv)
712 cb->invalidate_wr.ex.invalidate_rkey = cb->reg_mr->rkey;
717 ib_update_fast_reg_key(cb->reg_mr, ++cb->key);
718 cb->reg_mr_wr.key = cb->reg_mr->rkey;
723 if (buf == (u64)cb->start_dma_addr)
724 cb->reg_mr_wr.access = IB_ACCESS_REMOTE_READ;
726 cb->reg_mr_wr.access = IB_ACCESS_REMOTE_WRITE | IB_ACCESS_LOCAL_WRITE;
728 sg_dma_len(&sg) = cb->size;
730 ret = ib_map_mr_sg(cb->reg_mr, &sg, 1, NULL, PAGE_SIZE);
731 BUG_ON(ret <= 0 || ret > cb->page_list_len);
736 cb->reg_mr_wr.key,
737 cb->reg_mr->page_size,
738 (unsigned)cb->reg_mr->length,
739 (unsigned long long)cb->reg_mr->iova);
742 ret = ib_post_send(cb->qp, &cb->invalidate_wr, &bad_wr);
744 ret = ib_post_send(cb->qp, &cb->reg_mr_wr.wr, &bad_wr);
747 cb->state = ERROR;
749 rkey = cb->reg_mr->rkey;
753 static void krping_format_send(struct krping_cb *cb, u64 buf)
755 struct krping_rdma_info *info = &cb->send_buf;
763 if (!cb->server || cb->wlat || cb->rlat || cb->bw) {
764 rkey = krping_rdma_rkey(cb, buf, !cb->server_invalidate);
767 info->size = htonl(cb->size);
769 (unsigned long long)buf, rkey, cb->size);
773 static void krping_test_server(struct krping_cb *cb)
780 wait_event_interruptible(cb->sem, cb->state >= RDMA_READ_ADV);
781 if (cb->state != RDMA_READ_ADV) {
783 cb->state);
789 cb->rdma_sq_wr.rkey = cb->remote_rkey;
790 cb->rdma_sq_wr.remote_addr = cb->remote_addr;
791 cb->rdma_sq_wr.wr.sg_list->length = cb->remote_len;
792 cb->rdma_sgl.lkey = krping_rdma_rkey(cb, cb->rdma_dma_addr, !cb->read_inv);
793 cb->rdma_sq_wr.wr.next = NULL;
796 if (cb->read_inv)
797 cb->rdma_sq_wr.wr.opcode = IB_WR_RDMA_READ_WITH_INV;
800 cb->rdma_sq_wr.wr.opcode = IB_WR_RDMA_READ;
805 cb->rdma_sq_wr.wr.next = &inv;
808 inv.ex.invalidate_rkey = cb->reg_mr->rkey;
812 ret = ib_post_send(cb->qp, &cb->rdma_sq_wr.wr, &bad_wr);
817 cb->rdma_sq_wr.wr.next = NULL;
822 wait_event_interruptible(cb->sem,
823 cb->state >= RDMA_READ_COMPLETE);
824 if (cb->state != RDMA_READ_COMPLETE) {
827 cb->state);
833 if (cb->verbose)
835 cb->rdma_buf);
838 if (cb->server && cb->server_invalidate) {
839 cb->sq_wr.ex.invalidate_rkey = cb->remote_rkey;
840 cb->sq_wr.opcode = IB_WR_SEND_WITH_INV;
841 DEBUG_LOG("send-w-inv rkey 0x%x\n", cb->remote_rkey);
843 ret = ib_post_send(cb->qp, &cb->sq_wr, &bad_wr);
851 wait_event_interruptible(cb->sem, cb->state >= RDMA_WRITE_ADV);
852 if (cb->state != RDMA_WRITE_ADV) {
855 cb->state);
861 cb->rdma_sq_wr.wr.opcode = IB_WR_RDMA_WRITE;
862 cb->rdma_sq_wr.rkey = cb->remote_rkey;
863 cb->rdma_sq_wr.remote_addr = cb->remote_addr;
864 cb->rdma_sq_wr.wr.sg_list->length = strlen(cb->rdma_buf) + 1;
865 if (cb->local_dma_lkey)
866 cb->rdma_sgl.lkey = cb->pd->local_dma_lkey;
868 cb->rdma_sgl.lkey = krping_rdma_rkey(cb, cb->rdma_dma_addr, 0);
871 cb->rdma_sq_wr.wr.sg_list->lkey,
872 (unsigned long long)cb->rdma_sq_wr.wr.sg_list->addr,
873 cb->rdma_sq_wr.wr.sg_list->length);
875 ret = ib_post_send(cb->qp, &cb->rdma_sq_wr.wr, &bad_wr);
882 ret = wait_event_interruptible(cb->sem, cb->state >=
884 if (cb->state != RDMA_WRITE_COMPLETE) {
887 cb->state);
892 cb->state = CONNECTED;
895 if (cb->server && cb->server_invalidate) {
896 cb->sq_wr.ex.invalidate_rkey = cb->remote_rkey;
897 cb->sq_wr.opcode = IB_WR_SEND_WITH_INV;
898 DEBUG_LOG("send-w-inv rkey 0x%x\n", cb->remote_rkey);
900 ret = ib_post_send(cb->qp, &cb->sq_wr, &bad_wr);
909 static void rlat_test(struct krping_cb *cb)
912 int iters = cb->count;
920 cb->rdma_sq_wr.wr.opcode = IB_WR_RDMA_READ;
921 cb->rdma_sq_wr.rkey = cb->remote_rkey;
922 cb->rdma_sq_wr.remote_addr = cb->remote_addr;
923 cb->rdma_sq_wr.wr.sg_list->length = cb->size;
926 if (!cb->poll) {
927 cb->state = RDMA_READ_ADV;
928 ib_req_notify_cq(cb->cq, IB_CQ_NEXT_COMP);
932 cb->state = RDMA_READ_ADV;
933 ret = ib_post_send(cb->qp, &cb->rdma_sq_wr.wr, &bad_wr);
942 if (!cb->poll) {
943 wait_event_interruptible(cb->sem,
944 cb->state != RDMA_READ_ADV);
945 if (cb->state == RDMA_READ_COMPLETE) {
947 ib_req_notify_cq(cb->cq,
953 ne = ib_poll_cq(cb->cq, 1, &wc);
954 if (cb->state == ERROR) {
966 if (cb->poll && wc.status != IB_WC_SUCCESS) {
968 cb->server ? "server" : "client");
985 scnt, cb->size);
988 static void wlat_test(struct krping_cb *cb)
991 int iters=cb->count;
992 volatile char *poll_buf = (char *) cb->start_buf;
993 char *buf = (char *)cb->rdma_buf;
1034 cb->rdma_sq_wr.wr.opcode = IB_WR_RDMA_WRITE;
1035 cb->rdma_sq_wr.rkey = cb->remote_rkey;
1036 cb->rdma_sq_wr.remote_addr = cb->remote_addr;
1037 cb->rdma_sq_wr.wr.sg_list->length = cb->size;
1045 if (rcnt < iters && !(scnt < 1 && !cb->server)) {
1048 if (cb->state == ERROR) {
1062 if (ib_post_send(cb->qp, &cb->rdma_sq_wr.wr, &bad_wr)) {
1083 ne = ib_poll_cq(cb->cq, 1, &wc);
1096 cb->server ? "server" : "client");
1124 scnt, cb->size, cycle_iters,
1135 static void bw_test(struct krping_cb *cb)
1138 int iters=cb->count;
1179 cb->rdma_sq_wr.wr.opcode = IB_WR_RDMA_WRITE;
1180 cb->rdma_sq_wr.rkey = cb->remote_rkey;
1181 cb->rdma_sq_wr.remote_addr = cb->remote_addr;
1182 cb->rdma_sq_wr.wr.sg_list->length = cb->size;
1189 while (scnt < iters && scnt - ccnt < cb->txdepth) {
1194 if (ib_post_send(cb->qp, &cb->rdma_sq_wr.wr, &bad_wr)) {
1215 ne = ib_poll_cq(cb->cq, 1, &wc);
1228 cb->server ? "server" : "client");
1253 scnt, cb->size, cycle_iters,
1264 static void krping_rlat_test_server(struct krping_cb *cb)
1271 while (cb->state < RDMA_READ_ADV) {
1272 krping_cq_event_handler(cb->cq, cb);
1276 krping_format_send(cb, cb->start_dma_addr);
1277 ret = ib_post_send(cb->qp, &cb->sq_wr, &bad_wr);
1284 while ((ret = ib_poll_cq(cb->cq, 1, &wc) == 0));
1294 wait_event_interruptible(cb->sem, cb->state == ERROR);
1297 static void krping_wlat_test_server(struct krping_cb *cb)
1304 while (cb->state < RDMA_READ_ADV) {
1305 krping_cq_event_handler(cb->cq, cb);
1309 krping_format_send(cb, cb->start_dma_addr);
1310 ret = ib_post_send(cb->qp, &cb->sq_wr, &bad_wr);
1317 while ((ret = ib_poll_cq(cb->cq, 1, &wc) == 0));
1327 wlat_test(cb);
1328 wait_event_interruptible(cb->sem, cb->state == ERROR);
1331 static void krping_bw_test_server(struct krping_cb *cb)
1338 while (cb->state < RDMA_READ_ADV) {
1339 krping_cq_event_handler(cb->cq, cb);
1343 krping_format_send(cb, cb->start_dma_addr);
1344 ret = ib_post_send(cb->qp, &cb->sq_wr, &bad_wr);
1351 while ((ret = ib_poll_cq(cb->cq, 1, &wc) == 0));
1361 if (cb->duplex)
1362 bw_test(cb);
1363 wait_event_interruptible(cb->sem, cb->state == ERROR);
1381 static void fill_sockaddr(struct sockaddr_storage *sin, struct krping_cb *cb)
1385 if (cb->addr_type == AF_INET) {
1389 memcpy((void *)&sin4->sin_addr.s_addr, cb->addr, 4);
1390 sin4->sin_port = cb->port;
1391 } else if (cb->addr_type == AF_INET6) {
1395 memcpy((void *)&sin6->sin6_addr, cb->addr, 16);
1396 sin6->sin6_port = cb->port;
1400 static int krping_bind_server(struct krping_cb *cb)
1406 fill_sockaddr(&sin, cb);
1408 ret = rdma_bind_addr(cb->cm_id, (struct sockaddr *)&sin);
1416 ret = rdma_listen(cb->cm_id, 3);
1422 wait_event_interruptible(cb->sem, cb->state >= CONNECT_REQUEST);
1423 if (cb->state != CONNECT_REQUEST) {
1425 cb->state);
1429 if (!reg_supported(cb->child_cm_id->device))
1435 static void krping_run_server(struct krping_cb *cb)
1440 ret = krping_bind_server(cb);
1444 ret = krping_setup_qp(cb, cb->child_cm_id);
1450 ret = krping_setup_buffers(cb);
1456 ret = ib_post_recv(cb->qp, &cb->rq_wr, &bad_wr);
1462 ret = krping_accept(cb);
1468 if (cb->wlat)
1469 krping_wlat_test_server(cb);
1470 else if (cb->rlat)
1471 krping_rlat_test_server(cb);
1472 else if (cb->bw)
1473 krping_bw_test_server(cb);
1475 krping_test_server(cb);
1476 rdma_disconnect(cb->child_cm_id);
1478 krping_free_buffers(cb);
1480 krping_free_qp(cb);
1482 rdma_destroy_id(cb->child_cm_id);
1485 static void krping_test_client(struct krping_cb *cb)
1492 for (ping = 0; !cb->count || ping < cb->count; ping++) {
1493 cb->state = RDMA_READ_ADV;
1496 cc = sprintf(cb->start_buf, "rdma-ping-%d: ", ping);
1497 for (i = cc, c = start; i < cb->size; i++) {
1498 cb->start_buf[i] = c;
1506 cb->start_buf[cb->size - 1] = 0;
1508 krping_format_send(cb, cb->start_dma_addr);
1509 if (cb->state == ERROR) {
1513 ret = ib_post_send(cb->qp, &cb->sq_wr, &bad_wr);
1520 wait_event_interruptible(cb->sem, cb->state >= RDMA_WRITE_ADV);
1521 if (cb->state != RDMA_WRITE_ADV) {
1524 cb->state);
1528 krping_format_send(cb, cb->rdma_dma_addr);
1529 ret = ib_post_send(cb->qp, &cb->sq_wr, &bad_wr);
1536 wait_event_interruptible(cb->sem,
1537 cb->state >= RDMA_WRITE_COMPLETE);
1538 if (cb->state != RDMA_WRITE_COMPLETE) {
1541 cb->state);
1545 if (cb->validate)
1546 if (memcmp(cb->start_buf, cb->rdma_buf, cb->size)) {
1551 if (cb->verbose)
1552 printk(KERN_INFO PFX "ping data: %s\n", cb->rdma_buf);
1554 wait_event_interruptible_timeout(cb->sem, cb->state == ERROR, HZ);
1559 static void krping_rlat_test_client(struct krping_cb *cb)
1565 cb->state = RDMA_READ_ADV;
1568 krping_format_send(cb, cb->start_dma_addr);
1569 if (cb->state == ERROR) {
1573 ret = ib_post_send(cb->qp, &cb->sq_wr, &bad_wr);
1580 while ((ret = ib_poll_cq(cb->cq, 1, &wc) == 0));
1591 while (cb->state < RDMA_WRITE_ADV) {
1592 krping_cq_event_handler(cb->cq, cb);
1606 cb->rdma_sq_wr.wr.opcode = IB_WR_RDMA_WRITE;
1607 cb->rdma_sq_wr.rkey = cb->remote_rkey;
1608 cb->rdma_sq_wr.remote_addr = cb->remote_addr;
1609 cb->rdma_sq_wr.wr.sg_list->length = 0;
1610 cb->rdma_sq_wr.wr.num_sge = 0;
1614 if (ib_post_send(cb->qp, &cb->rdma_sq_wr.wr, &bad_wr)) {
1619 ne = ib_poll_cq(cb->cq, 1, &wc);
1627 cb->server ? "server" : "client");
1646 rlat_test(cb);
1649 static void krping_wlat_test_client(struct krping_cb *cb)
1655 cb->state = RDMA_READ_ADV;
1658 krping_format_send(cb, cb->start_dma_addr);
1659 if (cb->state == ERROR) {
1663 ret = ib_post_send(cb->qp, &cb->sq_wr, &bad_wr);
1670 while ((ret = ib_poll_cq(cb->cq, 1, &wc) == 0));
1681 while (cb->state < RDMA_WRITE_ADV) {
1682 krping_cq_event_handler(cb->cq, cb);
1685 wlat_test(cb);
1688 static void krping_bw_test_client(struct krping_cb *cb)
1694 cb->state = RDMA_READ_ADV;
1697 krping_format_send(cb, cb->start_dma_addr);
1698 if (cb->state == ERROR) {
1702 ret = ib_post_send(cb->qp, &cb->sq_wr, &bad_wr);
1709 while ((ret = ib_poll_cq(cb->cq, 1, &wc) == 0));
1720 while (cb->state < RDMA_WRITE_ADV) {
1721 krping_cq_event_handler(cb->cq, cb);
1724 bw_test(cb);
1730 static void flush_qp(struct krping_cb *cb)
1739 rdma_disconnect(cb->cm_id);
1744 ret = ib_post_send(cb->qp, &wr, &bad);
1751 ret = ib_post_recv(cb->qp, &recv_wr, &recv_bad);
1759 ret = ib_poll_cq(cb->cq, 1, &wc);
1774 static void krping_fr_test(struct krping_cb *cb)
1782 int size = cb->size;
1789 mr = ib_alloc_mr(cb->pd, IB_MR_TYPE_MEM_REG, plen);
1813 DEBUG_LOG("fr_test: stag index 0x%x plen %u size %u depth %u\n", mr->rkey >> 8, plen, cb->size, cb->txdepth);
1815 while (!cb->count || count <= cb->count) {
1822 wait_event_interruptible_timeout(cb->sem, cb->state == ERROR, HZ);
1823 if (cb->state == ERROR)
1827 while (scnt < (cb->txdepth>>1)) {
1832 size = arc4random() % cb->size;
1834 size = cb->size;
1841 ret = ib_post_send(cb->qp, &fr.wr, &bad);
1849 ret = ib_poll_cq(cb->cq, 1, &wc);
1864 flush_qp(cb);
1869 static int krping_connect_client(struct krping_cb *cb)
1879 ret = rdma_connect(cb->cm_id, &conn_param);
1885 wait_event_interruptible(cb->sem, cb->state >= CONNECTED);
1886 if (cb->state == ERROR) {
1887 printk(KERN_ERR PFX "wait for CONNECTED state %d\n", cb->state);
1895 static int krping_bind_client(struct krping_cb *cb)
1900 fill_sockaddr(&sin, cb);
1902 ret = rdma_resolve_addr(cb->cm_id, NULL, (struct sockaddr *)&sin, 2000);
1908 wait_event_interruptible(cb->sem, cb->state >= ROUTE_RESOLVED);
1909 if (cb->state != ROUTE_RESOLVED) {
1912 cb->state);
1916 if (!reg_supported(cb->cm_id->device))
1923 static void krping_run_client(struct krping_cb *cb)
1929 if (cb->tos != 0)
1930 rdma_set_service_type(cb->cm_id, cb->tos);
1932 ret = krping_bind_client(cb);
1936 ret = krping_setup_qp(cb, cb->cm_id);
1942 ret = krping_setup_buffers(cb);
1948 ret = ib_post_recv(cb->qp, &cb->rq_wr, &bad_wr);
1954 ret = krping_connect_client(cb);
1960 if (cb->wlat)
1961 krping_wlat_test_client(cb);
1962 else if (cb->rlat)
1963 krping_rlat_test_client(cb);
1964 else if (cb->bw)
1965 krping_bw_test_client(cb);
1966 else if (cb->frtest)
1967 krping_fr_test(cb);
1969 krping_test_client(cb);
1970 rdma_disconnect(cb->cm_id);
1972 krping_free_buffers(cb);
1974 krping_free_qp(cb);
1997 struct krping_cb *cb;
2004 cb = kzalloc(sizeof(*cb), GFP_KERNEL);
2005 if (!cb)
2009 list_add_tail(&cb->list, &krping_cbs);
2012 cb->server = -1;
2013 cb->state = IDLE;
2014 cb->size = 64;
2015 cb->txdepth = RPING_SQ_DEPTH;
2016 init_waitqueue_head(&cb->sem);
2022 cb->addr_str = optarg;
2023 cb->addr_type = AF_INET;
2025 if (inet_pton(AF_INET, optarg, cb->addr) != 1) {
2032 cb->addr_str = optarg;
2033 cb->addr_type = AF_INET6;
2040 if (inet_pton(AF_INET6, optarg, cb->addr) != 1) {
2044 } else if (IN6_IS_SCOPE_LINKLOCAL((struct in6_addr *)cb->addr) ||
2045 IN6_IS_ADDR_MC_INTFACELOCAL((struct in6_addr *)cb->addr)) {
2048 cb->addr[2] = scope_id >> 8;
2049 cb->addr[3] = scope_id & 0xFF;
2053 cb->port = htons(optint);
2057 cb->poll = 1;
2061 cb->server = 1;
2065 cb->server = 0;
2069 cb->size = optint;
2070 if ((cb->size < 1) ||
2071 (cb->size > RPING_BUFSIZE)) {
2074 cb->size, RPING_BUFSIZE);
2080 cb->count = optint;
2081 if (cb->count < 0) {
2083 cb->count);
2086 DEBUG_LOG("count %d\n", (int) cb->count);
2089 cb->verbose++;
2093 cb->validate++;
2097 cb->wlat++;
2100 cb->rlat++;
2103 cb->bw++;
2106 cb->duplex++;
2109 cb->server_invalidate = 1;
2112 cb->tos = optint;
2113 DEBUG_LOG("type of service, tos=%d\n", (int) cb->tos);
2116 cb->txdepth = optint;
2117 DEBUG_LOG("txdepth %d\n", (int) cb->txdepth);
2120 cb->local_dma_lkey = 1;
2124 cb->read_inv = 1;
2128 cb->frtest = 1;
2140 if (cb->server == -1) {
2146 if (cb->server && cb->frtest) {
2152 if ((cb->frtest + cb->bw + cb->rlat + cb->wlat) > 1) {
2158 if (cb->wlat || cb->rlat || cb->bw) {
2164 cb->cm_id = rdma_create_id(TD_TO_VNET(curthread), krping_cma_event_handler, cb, RDMA_PS_TCP, IB_QPT_RC);
2165 if (IS_ERR(cb->cm_id)) {
2166 ret = PTR_ERR(cb->cm_id);
2170 DEBUG_LOG("created cm_id %p\n", cb->cm_id);
2172 if (cb->server)
2173 krping_run_server(cb);
2175 krping_run_client(cb);
2177 DEBUG_LOG("destroy cm_id %p\n", cb->cm_id);
2178 rdma_destroy_id(cb->cm_id);
2181 list_del(&cb->list);
2183 kfree(cb);
2190 struct krping_cb *cb;
2193 list_for_each_entry(cb, &krping_cbs, list)
2194 (*f)(cb->pd ? &cb->stats : NULL, arg);
2201 struct krping_cb *cb;
2204 list_for_each_entry(cb, &krping_cbs, list) {
2205 cb->state = ERROR;
2206 wake_up_interruptible(&cb->sem);