usnic_ib.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This program is free software; you may redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  9. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15. * SOFTWARE.
  16. *
  17. */
  18. #ifndef USNIC_IB_H_
  19. #define USNIC_IB_H_
  20. #include <linux/iommu.h>
  21. #include <linux/netdevice.h>
  22. #include <rdma/ib_verbs.h>
  23. #include "usnic.h"
  24. #include "usnic_abi.h"
  25. #include "usnic_vnic.h"
  26. #define USNIC_IB_PORT_CNT 1
  27. #define USNIC_IB_NUM_COMP_VECTORS 1
  28. extern unsigned int usnic_ib_share_vf;
  29. struct usnic_ib_ucontext {
  30. struct ib_ucontext ibucontext;
  31. /* Protected by usnic_ib_dev->usdev_lock */
  32. struct list_head qp_grp_list;
  33. struct list_head link;
  34. };
  35. struct usnic_ib_pd {
  36. struct ib_pd ibpd;
  37. struct usnic_uiom_pd *umem_pd;
  38. };
  39. struct usnic_ib_mr {
  40. struct ib_mr ibmr;
  41. struct usnic_uiom_reg *umem;
  42. };
  43. struct usnic_ib_dev {
  44. struct ib_device ib_dev;
  45. struct pci_dev *pdev;
  46. struct net_device *netdev;
  47. struct usnic_fwd_dev *ufdev;
  48. struct list_head ib_dev_link;
  49. struct list_head vf_dev_list;
  50. struct list_head ctx_list;
  51. struct mutex usdev_lock;
  52. /* provisioning information */
  53. struct kref vf_cnt;
  54. unsigned int vf_res_cnt[USNIC_VNIC_RES_TYPE_MAX];
  55. /* sysfs vars for QPN reporting */
  56. struct kobject *qpn_kobj;
  57. };
  58. struct usnic_ib_vf {
  59. struct usnic_ib_dev *pf;
  60. spinlock_t lock;
  61. struct usnic_vnic *vnic;
  62. unsigned int qp_grp_ref_cnt;
  63. struct usnic_ib_pd *pd;
  64. struct list_head link;
  65. };
  66. static inline
  67. struct usnic_ib_dev *to_usdev(struct ib_device *ibdev)
  68. {
  69. return container_of(ibdev, struct usnic_ib_dev, ib_dev);
  70. }
  71. static inline
  72. struct usnic_ib_ucontext *to_ucontext(struct ib_ucontext *ibucontext)
  73. {
  74. return container_of(ibucontext, struct usnic_ib_ucontext, ibucontext);
  75. }
  76. static inline
  77. struct usnic_ib_pd *to_upd(struct ib_pd *ibpd)
  78. {
  79. return container_of(ibpd, struct usnic_ib_pd, ibpd);
  80. }
  81. static inline
  82. struct usnic_ib_ucontext *to_uucontext(struct ib_ucontext *ibucontext)
  83. {
  84. return container_of(ibucontext, struct usnic_ib_ucontext, ibucontext);
  85. }
  86. static inline
  87. struct usnic_ib_mr *to_umr(struct ib_mr *ibmr)
  88. {
  89. return container_of(ibmr, struct usnic_ib_mr, ibmr);
  90. }
  91. void usnic_ib_log_vf(struct usnic_ib_vf *vf);
  92. #define UPDATE_PTR_LEFT(N, P, L) \
  93. do { \
  94. L -= (N); \
  95. P += (N); \
  96. } while (0)
  97. #endif /* USNIC_IB_H_ */