You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ib_qset.c 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. #include <errno.h>
  20. #include <string.h>
  21. #include <gpxe/iobuf.h>
  22. #include <gpxe/infiniband.h>
  23. #include <gpxe/ib_qset.h>
  24. /**
  25. * @file
  26. *
  27. * Infiniband queue sets
  28. *
  29. */
  30. /**
  31. * Create queue set
  32. *
  33. * @v ibdev Infiniband device
  34. * @v qset Queue set
  35. * @v num_cqes Number of completion queue entries
  36. * @v cq_op Completion queue operations
  37. * @v num_send_wqes Number of send work queue entries
  38. * @v num_recv_wqes Number of receive work queue entries
  39. * @v qkey Queue key
  40. * @ret rc Return status code
  41. */
  42. int ib_create_qset ( struct ib_device *ibdev, struct ib_queue_set *qset,
  43. unsigned int num_cqes,
  44. struct ib_completion_queue_operations *cq_op,
  45. unsigned int num_send_wqes, unsigned int num_recv_wqes,
  46. unsigned long qkey ) {
  47. int rc;
  48. /* Sanity check */
  49. assert ( qset->cq == NULL );
  50. assert ( qset->qp == NULL );
  51. /* Allocate completion queue */
  52. qset->cq = ib_create_cq ( ibdev, num_cqes, cq_op );
  53. if ( ! qset->cq ) {
  54. DBGC ( ibdev, "IBDEV %p could not allocate completion queue\n",
  55. ibdev );
  56. rc = -ENOMEM;
  57. goto err;
  58. }
  59. /* Allocate queue pair */
  60. qset->qp = ib_create_qp ( ibdev, num_send_wqes, qset->cq,
  61. num_recv_wqes, qset->cq, qkey );
  62. if ( ! qset->qp ) {
  63. DBGC ( ibdev, "IBDEV %p could not allocate queue pair\n",
  64. ibdev );
  65. rc = -ENOMEM;
  66. goto err;
  67. }
  68. return 0;
  69. err:
  70. ib_destroy_qset ( ibdev, qset );
  71. return rc;
  72. }
  73. /**
  74. * Destroy queue set
  75. *
  76. * @v ibdev Infiniband device
  77. * @v qset Queue set
  78. */
  79. void ib_destroy_qset ( struct ib_device *ibdev,
  80. struct ib_queue_set *qset ) {
  81. if ( qset->qp )
  82. ib_destroy_qp ( ibdev, qset->qp );
  83. if ( qset->cq )
  84. ib_destroy_cq ( ibdev, qset->cq );
  85. memset ( qset, 0, sizeof ( *qset ) );
  86. }