rxe_loc.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /*
  2. * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
  3. * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #ifndef RXE_LOC_H
  34. #define RXE_LOC_H
  35. /* rxe_av.c */
  36. int rxe_av_chk_attr(struct rxe_dev *rxe, struct rdma_ah_attr *attr);
  37. void rxe_av_from_attr(u8 port_num, struct rxe_av *av,
  38. struct rdma_ah_attr *attr);
  39. void rxe_av_to_attr(struct rxe_av *av, struct rdma_ah_attr *attr);
  40. void rxe_av_fill_ip_info(struct rxe_av *av,
  41. struct rdma_ah_attr *attr,
  42. struct ib_gid_attr *sgid_attr,
  43. union ib_gid *sgid);
  44. struct rxe_av *rxe_get_av(struct rxe_pkt_info *pkt);
  45. /* rxe_cq.c */
  46. int rxe_cq_chk_attr(struct rxe_dev *rxe, struct rxe_cq *cq,
  47. int cqe, int comp_vector, struct ib_udata *udata);
  48. int rxe_cq_from_init(struct rxe_dev *rxe, struct rxe_cq *cq, int cqe,
  49. int comp_vector, struct ib_ucontext *context,
  50. struct ib_udata *udata);
  51. int rxe_cq_resize_queue(struct rxe_cq *cq, int new_cqe, struct ib_udata *udata);
  52. int rxe_cq_post(struct rxe_cq *cq, struct rxe_cqe *cqe, int solicited);
  53. void rxe_cq_disable(struct rxe_cq *cq);
  54. void rxe_cq_cleanup(struct rxe_pool_entry *arg);
  55. /* rxe_mcast.c */
  56. int rxe_mcast_get_grp(struct rxe_dev *rxe, union ib_gid *mgid,
  57. struct rxe_mc_grp **grp_p);
  58. int rxe_mcast_add_grp_elem(struct rxe_dev *rxe, struct rxe_qp *qp,
  59. struct rxe_mc_grp *grp);
  60. int rxe_mcast_drop_grp_elem(struct rxe_dev *rxe, struct rxe_qp *qp,
  61. union ib_gid *mgid);
  62. void rxe_drop_all_mcast_groups(struct rxe_qp *qp);
  63. void rxe_mc_cleanup(struct rxe_pool_entry *arg);
  64. /* rxe_mmap.c */
  65. struct rxe_mmap_info {
  66. struct list_head pending_mmaps;
  67. struct ib_ucontext *context;
  68. struct kref ref;
  69. void *obj;
  70. struct mminfo info;
  71. };
  72. void rxe_mmap_release(struct kref *ref);
  73. struct rxe_mmap_info *rxe_create_mmap_info(struct rxe_dev *dev,
  74. u32 size,
  75. struct ib_ucontext *context,
  76. void *obj);
  77. int rxe_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
  78. /* rxe_mr.c */
  79. enum copy_direction {
  80. to_mem_obj,
  81. from_mem_obj,
  82. };
  83. int rxe_mem_init_dma(struct rxe_dev *rxe, struct rxe_pd *pd,
  84. int access, struct rxe_mem *mem);
  85. int rxe_mem_init_user(struct rxe_dev *rxe, struct rxe_pd *pd, u64 start,
  86. u64 length, u64 iova, int access, struct ib_udata *udata,
  87. struct rxe_mem *mr);
  88. int rxe_mem_init_fast(struct rxe_dev *rxe, struct rxe_pd *pd,
  89. int max_pages, struct rxe_mem *mem);
  90. int rxe_mem_copy(struct rxe_mem *mem, u64 iova, void *addr,
  91. int length, enum copy_direction dir, u32 *crcp);
  92. int copy_data(struct rxe_dev *rxe, struct rxe_pd *pd, int access,
  93. struct rxe_dma_info *dma, void *addr, int length,
  94. enum copy_direction dir, u32 *crcp);
  95. void *iova_to_vaddr(struct rxe_mem *mem, u64 iova, int length);
  96. enum lookup_type {
  97. lookup_local,
  98. lookup_remote,
  99. };
  100. struct rxe_mem *lookup_mem(struct rxe_pd *pd, int access, u32 key,
  101. enum lookup_type type);
  102. int mem_check_range(struct rxe_mem *mem, u64 iova, size_t length);
  103. int rxe_mem_map_pages(struct rxe_dev *rxe, struct rxe_mem *mem,
  104. u64 *page, int num_pages, u64 iova);
  105. void rxe_mem_cleanup(struct rxe_pool_entry *arg);
  106. int advance_dma_data(struct rxe_dma_info *dma, unsigned int length);
  107. /* rxe_net.c */
  108. int rxe_loopback(struct sk_buff *skb);
  109. int rxe_send(struct rxe_dev *rxe, struct rxe_pkt_info *pkt,
  110. struct sk_buff *skb);
  111. struct sk_buff *rxe_init_packet(struct rxe_dev *rxe, struct rxe_av *av,
  112. int paylen, struct rxe_pkt_info *pkt);
  113. int rxe_prepare(struct rxe_dev *rxe, struct rxe_pkt_info *pkt,
  114. struct sk_buff *skb, u32 *crc);
  115. enum rdma_link_layer rxe_link_layer(struct rxe_dev *rxe, unsigned int port_num);
  116. const char *rxe_parent_name(struct rxe_dev *rxe, unsigned int port_num);
  117. struct device *rxe_dma_device(struct rxe_dev *rxe);
  118. int rxe_mcast_add(struct rxe_dev *rxe, union ib_gid *mgid);
  119. int rxe_mcast_delete(struct rxe_dev *rxe, union ib_gid *mgid);
  120. /* rxe_qp.c */
  121. int rxe_qp_chk_init(struct rxe_dev *rxe, struct ib_qp_init_attr *init);
  122. int rxe_qp_from_init(struct rxe_dev *rxe, struct rxe_qp *qp, struct rxe_pd *pd,
  123. struct ib_qp_init_attr *init, struct ib_udata *udata,
  124. struct ib_pd *ibpd);
  125. int rxe_qp_to_init(struct rxe_qp *qp, struct ib_qp_init_attr *init);
  126. int rxe_qp_chk_attr(struct rxe_dev *rxe, struct rxe_qp *qp,
  127. struct ib_qp_attr *attr, int mask);
  128. int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr,
  129. int mask, struct ib_udata *udata);
  130. int rxe_qp_to_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask);
  131. void rxe_qp_error(struct rxe_qp *qp);
  132. void rxe_qp_destroy(struct rxe_qp *qp);
  133. void rxe_qp_cleanup(struct rxe_pool_entry *arg);
  134. static inline int qp_num(struct rxe_qp *qp)
  135. {
  136. return qp->ibqp.qp_num;
  137. }
  138. static inline enum ib_qp_type qp_type(struct rxe_qp *qp)
  139. {
  140. return qp->ibqp.qp_type;
  141. }
  142. static inline enum ib_qp_state qp_state(struct rxe_qp *qp)
  143. {
  144. return qp->attr.qp_state;
  145. }
  146. static inline int qp_mtu(struct rxe_qp *qp)
  147. {
  148. if (qp->ibqp.qp_type == IB_QPT_RC || qp->ibqp.qp_type == IB_QPT_UC)
  149. return qp->attr.path_mtu;
  150. else
  151. return RXE_PORT_MAX_MTU;
  152. }
  153. static inline int rcv_wqe_size(int max_sge)
  154. {
  155. return sizeof(struct rxe_recv_wqe) +
  156. max_sge * sizeof(struct ib_sge);
  157. }
  158. void free_rd_atomic_resource(struct rxe_qp *qp, struct resp_res *res);
  159. static inline void rxe_advance_resp_resource(struct rxe_qp *qp)
  160. {
  161. qp->resp.res_head++;
  162. if (unlikely(qp->resp.res_head == qp->attr.max_dest_rd_atomic))
  163. qp->resp.res_head = 0;
  164. }
  165. void retransmit_timer(struct timer_list *t);
  166. void rnr_nak_timer(struct timer_list *t);
  167. /* rxe_srq.c */
  168. #define IB_SRQ_INIT_MASK (~IB_SRQ_LIMIT)
  169. int rxe_srq_chk_attr(struct rxe_dev *rxe, struct rxe_srq *srq,
  170. struct ib_srq_attr *attr, enum ib_srq_attr_mask mask);
  171. int rxe_srq_from_init(struct rxe_dev *rxe, struct rxe_srq *srq,
  172. struct ib_srq_init_attr *init,
  173. struct ib_ucontext *context, struct ib_udata *udata);
  174. int rxe_srq_from_attr(struct rxe_dev *rxe, struct rxe_srq *srq,
  175. struct ib_srq_attr *attr, enum ib_srq_attr_mask mask,
  176. struct ib_udata *udata);
  177. void rxe_release(struct kref *kref);
  178. int rxe_completer(void *arg);
  179. int rxe_requester(void *arg);
  180. int rxe_responder(void *arg);
  181. u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb);
  182. void rxe_resp_queue_pkt(struct rxe_dev *rxe,
  183. struct rxe_qp *qp, struct sk_buff *skb);
  184. void rxe_comp_queue_pkt(struct rxe_dev *rxe,
  185. struct rxe_qp *qp, struct sk_buff *skb);
  186. static inline unsigned int wr_opcode_mask(int opcode, struct rxe_qp *qp)
  187. {
  188. return rxe_wr_opcode_info[opcode].mask[qp->ibqp.qp_type];
  189. }
  190. static inline int rxe_xmit_packet(struct rxe_dev *rxe, struct rxe_qp *qp,
  191. struct rxe_pkt_info *pkt, struct sk_buff *skb)
  192. {
  193. int err;
  194. int is_request = pkt->mask & RXE_REQ_MASK;
  195. if ((is_request && (qp->req.state != QP_STATE_READY)) ||
  196. (!is_request && (qp->resp.state != QP_STATE_READY))) {
  197. pr_info("Packet dropped. QP is not in ready state\n");
  198. goto drop;
  199. }
  200. if (pkt->mask & RXE_LOOPBACK_MASK) {
  201. memcpy(SKB_TO_PKT(skb), pkt, sizeof(*pkt));
  202. err = rxe_loopback(skb);
  203. } else {
  204. err = rxe_send(rxe, pkt, skb);
  205. }
  206. if (err) {
  207. rxe->xmit_errors++;
  208. rxe_counter_inc(rxe, RXE_CNT_SEND_ERR);
  209. return err;
  210. }
  211. if ((qp_type(qp) != IB_QPT_RC) &&
  212. (pkt->mask & RXE_END_MASK)) {
  213. pkt->wqe->state = wqe_state_done;
  214. rxe_run_task(&qp->comp.task, 1);
  215. }
  216. rxe_counter_inc(rxe, RXE_CNT_SENT_PKTS);
  217. goto done;
  218. drop:
  219. kfree_skb(skb);
  220. err = 0;
  221. done:
  222. return err;
  223. }
  224. #endif /* RXE_LOC_H */