ib_addr.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (c) 2005 Voltaire Inc. All rights reserved.
  3. * Copyright (c) 2005 Intel Corporation. All rights reserved.
  4. *
  5. * This Software is licensed under one of the following licenses:
  6. *
  7. * 1) under the terms of the "Common Public License 1.0" a copy of which is
  8. * available from the Open Source Initiative, see
  9. * http://www.opensource.org/licenses/cpl.php.
  10. *
  11. * 2) under the terms of the "The BSD License" a copy of which is
  12. * available from the Open Source Initiative, see
  13. * http://www.opensource.org/licenses/bsd-license.php.
  14. *
  15. * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
  16. * copy of which is available from the Open Source Initiative, see
  17. * http://www.opensource.org/licenses/gpl-license.php.
  18. *
  19. * Licensee has the right to choose one of the above licenses.
  20. *
  21. * Redistributions of source code must retain the above copyright
  22. * notice and one of the license notices.
  23. *
  24. * Redistributions in binary form must reproduce both the above copyright
  25. * notice, one of the license notices in the documentation
  26. * and/or other materials provided with the distribution.
  27. *
  28. */
  29. #if !defined(IB_ADDR_H)
  30. #define IB_ADDR_H
  31. #include <linux/in.h>
  32. #include <linux/in6.h>
  33. #include <linux/netdevice.h>
  34. #include <linux/socket.h>
  35. #include <rdma/ib_verbs.h>
  36. struct rdma_addr_client {
  37. atomic_t refcount;
  38. struct completion comp;
  39. };
  40. /**
  41. * rdma_addr_register_client - Register an address client.
  42. */
  43. void rdma_addr_register_client(struct rdma_addr_client *client);
  44. /**
  45. * rdma_addr_unregister_client - Deregister an address client.
  46. * @client: Client object to deregister.
  47. */
  48. void rdma_addr_unregister_client(struct rdma_addr_client *client);
  49. struct rdma_dev_addr {
  50. unsigned char src_dev_addr[MAX_ADDR_LEN];
  51. unsigned char dst_dev_addr[MAX_ADDR_LEN];
  52. unsigned char broadcast[MAX_ADDR_LEN];
  53. enum rdma_node_type dev_type;
  54. };
  55. /**
  56. * rdma_translate_ip - Translate a local IP address to an RDMA hardware
  57. * address.
  58. */
  59. int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr);
  60. /**
  61. * rdma_resolve_ip - Resolve source and destination IP addresses to
  62. * RDMA hardware addresses.
  63. * @client: Address client associated with request.
  64. * @src_addr: An optional source address to use in the resolution. If a
  65. * source address is not provided, a usable address will be returned via
  66. * the callback.
  67. * @dst_addr: The destination address to resolve.
  68. * @addr: A reference to a data location that will receive the resolved
  69. * addresses. The data location must remain valid until the callback has
  70. * been invoked.
  71. * @timeout_ms: Amount of time to wait for the address resolution to complete.
  72. * @callback: Call invoked once address resolution has completed, timed out,
  73. * or been canceled. A status of 0 indicates success.
  74. * @context: User-specified context associated with the call.
  75. */
  76. int rdma_resolve_ip(struct rdma_addr_client *client,
  77. struct sockaddr *src_addr, struct sockaddr *dst_addr,
  78. struct rdma_dev_addr *addr, int timeout_ms,
  79. void (*callback)(int status, struct sockaddr *src_addr,
  80. struct rdma_dev_addr *addr, void *context),
  81. void *context);
  82. void rdma_addr_cancel(struct rdma_dev_addr *addr);
  83. int rdma_copy_addr(struct rdma_dev_addr *dev_addr, struct net_device *dev,
  84. const unsigned char *dst_dev_addr);
  85. static inline int ip_addr_size(struct sockaddr *addr)
  86. {
  87. return addr->sa_family == AF_INET6 ?
  88. sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
  89. }
  90. static inline u16 ib_addr_get_pkey(struct rdma_dev_addr *dev_addr)
  91. {
  92. return ((u16)dev_addr->broadcast[8] << 8) | (u16)dev_addr->broadcast[9];
  93. }
  94. static inline void ib_addr_set_pkey(struct rdma_dev_addr *dev_addr, u16 pkey)
  95. {
  96. dev_addr->broadcast[8] = pkey >> 8;
  97. dev_addr->broadcast[9] = (unsigned char) pkey;
  98. }
  99. static inline void ib_addr_get_mgid(struct rdma_dev_addr *dev_addr,
  100. union ib_gid *gid)
  101. {
  102. memcpy(gid, dev_addr->broadcast + 4, sizeof *gid);
  103. }
  104. static inline void ib_addr_get_sgid(struct rdma_dev_addr *dev_addr,
  105. union ib_gid *gid)
  106. {
  107. memcpy(gid, dev_addr->src_dev_addr + 4, sizeof *gid);
  108. }
  109. static inline void ib_addr_set_sgid(struct rdma_dev_addr *dev_addr,
  110. union ib_gid *gid)
  111. {
  112. memcpy(dev_addr->src_dev_addr + 4, gid, sizeof *gid);
  113. }
  114. static inline void ib_addr_get_dgid(struct rdma_dev_addr *dev_addr,
  115. union ib_gid *gid)
  116. {
  117. memcpy(gid, dev_addr->dst_dev_addr + 4, sizeof *gid);
  118. }
  119. static inline void ib_addr_set_dgid(struct rdma_dev_addr *dev_addr,
  120. union ib_gid *gid)
  121. {
  122. memcpy(dev_addr->dst_dev_addr + 4, gid, sizeof *gid);
  123. }
  124. static inline void iw_addr_get_sgid(struct rdma_dev_addr *dev_addr,
  125. union ib_gid *gid)
  126. {
  127. memcpy(gid, dev_addr->src_dev_addr, sizeof *gid);
  128. }
  129. static inline void iw_addr_get_dgid(struct rdma_dev_addr *dev_addr,
  130. union ib_gid *gid)
  131. {
  132. memcpy(gid, dev_addr->dst_dev_addr, sizeof *gid);
  133. }
  134. #endif /* IB_ADDR_H */