iwch.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright (c) 2006 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:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/module.h>
  33. #include <linux/moduleparam.h>
  34. #include <rdma/ib_verbs.h>
  35. #include "cxgb3_offload.h"
  36. #include "iwch_provider.h"
  37. #include "iwch_user.h"
  38. #include "iwch.h"
  39. #include "iwch_cm.h"
  40. #define DRV_VERSION "1.1"
  41. MODULE_AUTHOR("Boyd Faulkner, Steve Wise");
  42. MODULE_DESCRIPTION("Chelsio T3 RDMA Driver");
  43. MODULE_LICENSE("Dual BSD/GPL");
  44. MODULE_VERSION(DRV_VERSION);
  45. cxgb3_cpl_handler_func t3c_handlers[NUM_CPL_CMDS];
  46. static void open_rnic_dev(struct t3cdev *);
  47. static void close_rnic_dev(struct t3cdev *);
  48. struct cxgb3_client t3c_client = {
  49. .name = "iw_cxgb3",
  50. .add = open_rnic_dev,
  51. .remove = close_rnic_dev,
  52. .handlers = t3c_handlers,
  53. .redirect = iwch_ep_redirect
  54. };
  55. static LIST_HEAD(dev_list);
  56. static DEFINE_MUTEX(dev_mutex);
  57. static void rnic_init(struct iwch_dev *rnicp)
  58. {
  59. PDBG("%s iwch_dev %p\n", __func__, rnicp);
  60. idr_init(&rnicp->cqidr);
  61. idr_init(&rnicp->qpidr);
  62. idr_init(&rnicp->mmidr);
  63. spin_lock_init(&rnicp->lock);
  64. rnicp->attr.max_qps = T3_MAX_NUM_QP - 32;
  65. rnicp->attr.max_wrs = T3_MAX_QP_DEPTH;
  66. rnicp->attr.max_sge_per_wr = T3_MAX_SGE;
  67. rnicp->attr.max_sge_per_rdma_write_wr = T3_MAX_SGE;
  68. rnicp->attr.max_cqs = T3_MAX_NUM_CQ - 1;
  69. rnicp->attr.max_cqes_per_cq = T3_MAX_CQ_DEPTH;
  70. rnicp->attr.max_mem_regs = cxio_num_stags(&rnicp->rdev);
  71. rnicp->attr.max_phys_buf_entries = T3_MAX_PBL_SIZE;
  72. rnicp->attr.max_pds = T3_MAX_NUM_PD - 1;
  73. rnicp->attr.mem_pgsizes_bitmask = T3_PAGESIZE_MASK;
  74. rnicp->attr.max_mr_size = T3_MAX_MR_SIZE;
  75. rnicp->attr.can_resize_wq = 0;
  76. rnicp->attr.max_rdma_reads_per_qp = 8;
  77. rnicp->attr.max_rdma_read_resources =
  78. rnicp->attr.max_rdma_reads_per_qp * rnicp->attr.max_qps;
  79. rnicp->attr.max_rdma_read_qp_depth = 8; /* IRD */
  80. rnicp->attr.max_rdma_read_depth =
  81. rnicp->attr.max_rdma_read_qp_depth * rnicp->attr.max_qps;
  82. rnicp->attr.rq_overflow_handled = 0;
  83. rnicp->attr.can_modify_ird = 0;
  84. rnicp->attr.can_modify_ord = 0;
  85. rnicp->attr.max_mem_windows = rnicp->attr.max_mem_regs - 1;
  86. rnicp->attr.stag0_value = 1;
  87. rnicp->attr.zbva_support = 1;
  88. rnicp->attr.local_invalidate_fence = 1;
  89. rnicp->attr.cq_overflow_detection = 1;
  90. return;
  91. }
  92. static void open_rnic_dev(struct t3cdev *tdev)
  93. {
  94. struct iwch_dev *rnicp;
  95. static int vers_printed;
  96. PDBG("%s t3cdev %p\n", __func__, tdev);
  97. if (!vers_printed++)
  98. printk(KERN_INFO MOD "Chelsio T3 RDMA Driver - version %s\n",
  99. DRV_VERSION);
  100. rnicp = (struct iwch_dev *)ib_alloc_device(sizeof(*rnicp));
  101. if (!rnicp) {
  102. printk(KERN_ERR MOD "Cannot allocate ib device\n");
  103. return;
  104. }
  105. rnicp->rdev.ulp = rnicp;
  106. rnicp->rdev.t3cdev_p = tdev;
  107. mutex_lock(&dev_mutex);
  108. if (cxio_rdev_open(&rnicp->rdev)) {
  109. mutex_unlock(&dev_mutex);
  110. printk(KERN_ERR MOD "Unable to open CXIO rdev\n");
  111. ib_dealloc_device(&rnicp->ibdev);
  112. return;
  113. }
  114. rnic_init(rnicp);
  115. list_add_tail(&rnicp->entry, &dev_list);
  116. mutex_unlock(&dev_mutex);
  117. if (iwch_register_device(rnicp)) {
  118. printk(KERN_ERR MOD "Unable to register device\n");
  119. close_rnic_dev(tdev);
  120. }
  121. printk(KERN_INFO MOD "Initialized device %s\n",
  122. pci_name(rnicp->rdev.rnic_info.pdev));
  123. return;
  124. }
  125. static void close_rnic_dev(struct t3cdev *tdev)
  126. {
  127. struct iwch_dev *dev, *tmp;
  128. PDBG("%s t3cdev %p\n", __func__, tdev);
  129. mutex_lock(&dev_mutex);
  130. list_for_each_entry_safe(dev, tmp, &dev_list, entry) {
  131. if (dev->rdev.t3cdev_p == tdev) {
  132. list_del(&dev->entry);
  133. iwch_unregister_device(dev);
  134. cxio_rdev_close(&dev->rdev);
  135. idr_destroy(&dev->cqidr);
  136. idr_destroy(&dev->qpidr);
  137. idr_destroy(&dev->mmidr);
  138. ib_dealloc_device(&dev->ibdev);
  139. break;
  140. }
  141. }
  142. mutex_unlock(&dev_mutex);
  143. }
  144. static int __init iwch_init_module(void)
  145. {
  146. int err;
  147. err = cxio_hal_init();
  148. if (err)
  149. return err;
  150. err = iwch_cm_init();
  151. if (err)
  152. return err;
  153. cxio_register_ev_cb(iwch_ev_dispatch);
  154. cxgb3_register_client(&t3c_client);
  155. return 0;
  156. }
  157. static void __exit iwch_exit_module(void)
  158. {
  159. cxgb3_unregister_client(&t3c_client);
  160. cxio_unregister_ev_cb(iwch_ev_dispatch);
  161. iwch_cm_term();
  162. cxio_hal_exit();
  163. }
  164. module_init(iwch_init_module);
  165. module_exit(iwch_exit_module);