qp.c (d8a382d2662822248a97ce9d670b90e68aefbd3a) qp.c (732bee7af3102cad811fb047dee8d15966efe569)
1/*
2 * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:

--- 558 unchanged lines hidden (view full) ---

567 err = build_rdma_send(wqe, wr, &len16);
568 break;
569 case IB_WR_RDMA_WRITE:
570 fw_opcode = FW_RI_RDMA_WRITE_WR;
571 swsqe->opcode = FW_RI_RDMA_WRITE;
572 err = build_rdma_write(wqe, wr, &len16);
573 break;
574 case IB_WR_RDMA_READ:
1/*
2 * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:

--- 558 unchanged lines hidden (view full) ---

567 err = build_rdma_send(wqe, wr, &len16);
568 break;
569 case IB_WR_RDMA_WRITE:
570 fw_opcode = FW_RI_RDMA_WRITE_WR;
571 swsqe->opcode = FW_RI_RDMA_WRITE;
572 err = build_rdma_write(wqe, wr, &len16);
573 break;
574 case IB_WR_RDMA_READ:
575 case IB_WR_RDMA_READ_WITH_INV:
576 fw_opcode = FW_RI_RDMA_READ_WR;
577 swsqe->opcode = FW_RI_READ_REQ;
575 fw_opcode = FW_RI_RDMA_READ_WR;
576 swsqe->opcode = FW_RI_READ_REQ;
578 if (wr->opcode == IB_WR_RDMA_READ_WITH_INV)
579 fw_flags |= FW_RI_RDMA_READ_INVALIDATE;
580 else
581 fw_flags = 0;
577 fw_flags = 0;
582 err = build_rdma_read(wqe, wr, &len16);
583 if (err)
584 break;
585 swsqe->read_len = wr->sg_list[0].length;
586 if (!qhp->wq.sq.oldest_read)
587 qhp->wq.sq.oldest_read = swsqe;
588 break;
589 case IB_WR_FAST_REG_MR:
590 fw_opcode = FW_RI_FR_NSMR_WR;
591 swsqe->opcode = FW_RI_FAST_REGISTER;
592 err = build_fastreg(wqe, wr, &len16);
593 break;
594 case IB_WR_LOCAL_INV:
578 err = build_rdma_read(wqe, wr, &len16);
579 if (err)
580 break;
581 swsqe->read_len = wr->sg_list[0].length;
582 if (!qhp->wq.sq.oldest_read)
583 qhp->wq.sq.oldest_read = swsqe;
584 break;
585 case IB_WR_FAST_REG_MR:
586 fw_opcode = FW_RI_FR_NSMR_WR;
587 swsqe->opcode = FW_RI_FAST_REGISTER;
588 err = build_fastreg(wqe, wr, &len16);
589 break;
590 case IB_WR_LOCAL_INV:
595 if (wr->send_flags & IB_SEND_FENCE)
596 fw_flags |= FW_RI_LOCAL_FENCE_FLAG;
597 fw_opcode = FW_RI_INV_LSTAG_WR;
598 swsqe->opcode = FW_RI_LOCAL_INV;
599 err = build_inv_stag(wqe, wr, &len16);
600 break;
601 default:
602 PDBG("%s post of type=%d TBD!\n", __func__,
603 wr->opcode);
604 err = -EINVAL;

--- 295 unchanged lines hidden (view full) ---

900 int count;
901 int flushed;
902
903 PDBG("%s qhp %p rchp %p schp %p\n", __func__, qhp, rchp, schp);
904 /* take a ref on the qhp since we must release the lock */
905 atomic_inc(&qhp->refcnt);
906 spin_unlock_irqrestore(&qhp->lock, *flag);
907
591 fw_opcode = FW_RI_INV_LSTAG_WR;
592 swsqe->opcode = FW_RI_LOCAL_INV;
593 err = build_inv_stag(wqe, wr, &len16);
594 break;
595 default:
596 PDBG("%s post of type=%d TBD!\n", __func__,
597 wr->opcode);
598 err = -EINVAL;

--- 295 unchanged lines hidden (view full) ---

894 int count;
895 int flushed;
896
897 PDBG("%s qhp %p rchp %p schp %p\n", __func__, qhp, rchp, schp);
898 /* take a ref on the qhp since we must release the lock */
899 atomic_inc(&qhp->refcnt);
900 spin_unlock_irqrestore(&qhp->lock, *flag);
901
908 /* locking heirarchy: cq lock first, then qp lock. */
902 /* locking hierarchy: cq lock first, then qp lock. */
909 spin_lock_irqsave(&rchp->lock, *flag);
910 spin_lock(&qhp->lock);
911 c4iw_flush_hw_cq(&rchp->cq);
912 c4iw_count_rcqes(&rchp->cq, &qhp->wq, &count);
913 flushed = c4iw_flush_rq(&qhp->wq, &rchp->cq, count);
914 spin_unlock(&qhp->lock);
915 spin_unlock_irqrestore(&rchp->lock, *flag);
916 if (flushed)
917 (*rchp->ibcq.comp_handler)(&rchp->ibcq, rchp->ibcq.cq_context);
918
903 spin_lock_irqsave(&rchp->lock, *flag);
904 spin_lock(&qhp->lock);
905 c4iw_flush_hw_cq(&rchp->cq);
906 c4iw_count_rcqes(&rchp->cq, &qhp->wq, &count);
907 flushed = c4iw_flush_rq(&qhp->wq, &rchp->cq, count);
908 spin_unlock(&qhp->lock);
909 spin_unlock_irqrestore(&rchp->lock, *flag);
910 if (flushed)
911 (*rchp->ibcq.comp_handler)(&rchp->ibcq, rchp->ibcq.cq_context);
912
919 /* locking heirarchy: cq lock first, then qp lock. */
913 /* locking hierarchy: cq lock first, then qp lock. */
920 spin_lock_irqsave(&schp->lock, *flag);
921 spin_lock(&qhp->lock);
922 c4iw_flush_hw_cq(&schp->cq);
923 c4iw_count_scqes(&schp->cq, &qhp->wq, &count);
924 flushed = c4iw_flush_sq(&qhp->wq, &schp->cq, count);
925 spin_unlock(&qhp->lock);
926 spin_unlock_irqrestore(&schp->lock, *flag);
927 if (flushed)

--- 412 unchanged lines hidden (view full) ---

1340 qhp = to_c4iw_qp(ib_qp);
1341 rhp = qhp->rhp;
1342
1343 attrs.next_state = C4IW_QP_STATE_ERROR;
1344 c4iw_modify_qp(rhp, qhp, C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1345 wait_event(qhp->wait, !qhp->ep);
1346
1347 remove_handle(rhp, &rhp->qpidr, qhp->wq.sq.qid);
914 spin_lock_irqsave(&schp->lock, *flag);
915 spin_lock(&qhp->lock);
916 c4iw_flush_hw_cq(&schp->cq);
917 c4iw_count_scqes(&schp->cq, &qhp->wq, &count);
918 flushed = c4iw_flush_sq(&qhp->wq, &schp->cq, count);
919 spin_unlock(&qhp->lock);
920 spin_unlock_irqrestore(&schp->lock, *flag);
921 if (flushed)

--- 412 unchanged lines hidden (view full) ---

1334 qhp = to_c4iw_qp(ib_qp);
1335 rhp = qhp->rhp;
1336
1337 attrs.next_state = C4IW_QP_STATE_ERROR;
1338 c4iw_modify_qp(rhp, qhp, C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1339 wait_event(qhp->wait, !qhp->ep);
1340
1341 remove_handle(rhp, &rhp->qpidr, qhp->wq.sq.qid);
1342 remove_handle(rhp, &rhp->qpidr, qhp->wq.rq.qid);
1348 atomic_dec(&qhp->refcnt);
1349 wait_event(qhp->wait, !atomic_read(&qhp->refcnt));
1350
1351 ucontext = ib_qp->uobject ?
1352 to_c4iw_ucontext(ib_qp->uobject->context) : NULL;
1353 destroy_qp(&rhp->rdev, &qhp->wq,
1354 ucontext ? &ucontext->uctx : &rhp->rdev.uctx);
1355

--- 86 unchanged lines hidden (view full) ---

1442 spin_lock_init(&qhp->lock);
1443 init_waitqueue_head(&qhp->wait);
1444 atomic_set(&qhp->refcnt, 1);
1445
1446 ret = insert_handle(rhp, &rhp->qpidr, qhp, qhp->wq.sq.qid);
1447 if (ret)
1448 goto err2;
1449
1343 atomic_dec(&qhp->refcnt);
1344 wait_event(qhp->wait, !atomic_read(&qhp->refcnt));
1345
1346 ucontext = ib_qp->uobject ?
1347 to_c4iw_ucontext(ib_qp->uobject->context) : NULL;
1348 destroy_qp(&rhp->rdev, &qhp->wq,
1349 ucontext ? &ucontext->uctx : &rhp->rdev.uctx);
1350

--- 86 unchanged lines hidden (view full) ---

1437 spin_lock_init(&qhp->lock);
1438 init_waitqueue_head(&qhp->wait);
1439 atomic_set(&qhp->refcnt, 1);
1440
1441 ret = insert_handle(rhp, &rhp->qpidr, qhp, qhp->wq.sq.qid);
1442 if (ret)
1443 goto err2;
1444
1445 ret = insert_handle(rhp, &rhp->qpidr, qhp, qhp->wq.rq.qid);
1446 if (ret)
1447 goto err3;
1448
1450 if (udata) {
1451 mm1 = kmalloc(sizeof *mm1, GFP_KERNEL);
1452 if (!mm1) {
1453 ret = -ENOMEM;
1449 if (udata) {
1450 mm1 = kmalloc(sizeof *mm1, GFP_KERNEL);
1451 if (!mm1) {
1452 ret = -ENOMEM;
1454 goto err3;
1453 goto err4;
1455 }
1456 mm2 = kmalloc(sizeof *mm2, GFP_KERNEL);
1457 if (!mm2) {
1458 ret = -ENOMEM;
1454 }
1455 mm2 = kmalloc(sizeof *mm2, GFP_KERNEL);
1456 if (!mm2) {
1457 ret = -ENOMEM;
1459 goto err4;
1458 goto err5;
1460 }
1461 mm3 = kmalloc(sizeof *mm3, GFP_KERNEL);
1462 if (!mm3) {
1463 ret = -ENOMEM;
1459 }
1460 mm3 = kmalloc(sizeof *mm3, GFP_KERNEL);
1461 if (!mm3) {
1462 ret = -ENOMEM;
1464 goto err5;
1463 goto err6;
1465 }
1466 mm4 = kmalloc(sizeof *mm4, GFP_KERNEL);
1467 if (!mm4) {
1468 ret = -ENOMEM;
1464 }
1465 mm4 = kmalloc(sizeof *mm4, GFP_KERNEL);
1466 if (!mm4) {
1467 ret = -ENOMEM;
1469 goto err6;
1468 goto err7;
1470 }
1471
1472 uresp.qid_mask = rhp->rdev.qpmask;
1473 uresp.sqid = qhp->wq.sq.qid;
1474 uresp.sq_size = qhp->wq.sq.size;
1475 uresp.sq_memsize = qhp->wq.sq.memsize;
1476 uresp.rqid = qhp->wq.rq.qid;
1477 uresp.rq_size = qhp->wq.rq.size;

--- 5 unchanged lines hidden (view full) ---

1483 ucontext->key += PAGE_SIZE;
1484 uresp.sq_db_gts_key = ucontext->key;
1485 ucontext->key += PAGE_SIZE;
1486 uresp.rq_db_gts_key = ucontext->key;
1487 ucontext->key += PAGE_SIZE;
1488 spin_unlock(&ucontext->mmap_lock);
1489 ret = ib_copy_to_udata(udata, &uresp, sizeof uresp);
1490 if (ret)
1469 }
1470
1471 uresp.qid_mask = rhp->rdev.qpmask;
1472 uresp.sqid = qhp->wq.sq.qid;
1473 uresp.sq_size = qhp->wq.sq.size;
1474 uresp.sq_memsize = qhp->wq.sq.memsize;
1475 uresp.rqid = qhp->wq.rq.qid;
1476 uresp.rq_size = qhp->wq.rq.size;

--- 5 unchanged lines hidden (view full) ---

1482 ucontext->key += PAGE_SIZE;
1483 uresp.sq_db_gts_key = ucontext->key;
1484 ucontext->key += PAGE_SIZE;
1485 uresp.rq_db_gts_key = ucontext->key;
1486 ucontext->key += PAGE_SIZE;
1487 spin_unlock(&ucontext->mmap_lock);
1488 ret = ib_copy_to_udata(udata, &uresp, sizeof uresp);
1489 if (ret)
1491 goto err7;
1490 goto err8;
1492 mm1->key = uresp.sq_key;
1493 mm1->addr = virt_to_phys(qhp->wq.sq.queue);
1494 mm1->len = PAGE_ALIGN(qhp->wq.sq.memsize);
1495 insert_mmap(ucontext, mm1);
1496 mm2->key = uresp.rq_key;
1497 mm2->addr = virt_to_phys(qhp->wq.rq.queue);
1498 mm2->len = PAGE_ALIGN(qhp->wq.rq.memsize);
1499 insert_mmap(ucontext, mm2);

--- 7 unchanged lines hidden (view full) ---

1507 insert_mmap(ucontext, mm4);
1508 }
1509 qhp->ibqp.qp_num = qhp->wq.sq.qid;
1510 init_timer(&(qhp->timer));
1511 PDBG("%s qhp %p sq_num_entries %d, rq_num_entries %d qpid 0x%0x\n",
1512 __func__, qhp, qhp->attr.sq_num_entries, qhp->attr.rq_num_entries,
1513 qhp->wq.sq.qid);
1514 return &qhp->ibqp;
1491 mm1->key = uresp.sq_key;
1492 mm1->addr = virt_to_phys(qhp->wq.sq.queue);
1493 mm1->len = PAGE_ALIGN(qhp->wq.sq.memsize);
1494 insert_mmap(ucontext, mm1);
1495 mm2->key = uresp.rq_key;
1496 mm2->addr = virt_to_phys(qhp->wq.rq.queue);
1497 mm2->len = PAGE_ALIGN(qhp->wq.rq.memsize);
1498 insert_mmap(ucontext, mm2);

--- 7 unchanged lines hidden (view full) ---

1506 insert_mmap(ucontext, mm4);
1507 }
1508 qhp->ibqp.qp_num = qhp->wq.sq.qid;
1509 init_timer(&(qhp->timer));
1510 PDBG("%s qhp %p sq_num_entries %d, rq_num_entries %d qpid 0x%0x\n",
1511 __func__, qhp, qhp->attr.sq_num_entries, qhp->attr.rq_num_entries,
1512 qhp->wq.sq.qid);
1513 return &qhp->ibqp;
1515err7:
1514err8:
1516 kfree(mm4);
1515 kfree(mm4);
1517err6:
1516err7:
1518 kfree(mm3);
1517 kfree(mm3);
1519err5:
1518err6:
1520 kfree(mm2);
1519 kfree(mm2);
1521err4:
1520err5:
1522 kfree(mm1);
1521 kfree(mm1);
1522err4:
1523 remove_handle(rhp, &rhp->qpidr, qhp->wq.rq.qid);
1523err3:
1524 remove_handle(rhp, &rhp->qpidr, qhp->wq.sq.qid);
1525err2:
1526 destroy_qp(&rhp->rdev, &qhp->wq,
1527 ucontext ? &ucontext->uctx : &rhp->rdev.uctx);
1528err1:
1529 kfree(qhp);
1530 return ERR_PTR(ret);

--- 46 unchanged lines hidden ---
1524err3:
1525 remove_handle(rhp, &rhp->qpidr, qhp->wq.sq.qid);
1526err2:
1527 destroy_qp(&rhp->rdev, &qhp->wq,
1528 ucontext ? &ucontext->uctx : &rhp->rdev.uctx);
1529err1:
1530 kfree(qhp);
1531 return ERR_PTR(ret);

--- 46 unchanged lines hidden ---