opa_addr.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2. /*
  3. * Copyright(c) 2017 Intel Corporation.
  4. */
  5. #ifndef OPA_ADDR_H
  6. #define OPA_ADDR_H
  7. #include <rdma/opa_smi.h>
  8. #define OPA_SPECIAL_OUI (0x00066AULL)
  9. #define OPA_MAKE_ID(x) (cpu_to_be64(OPA_SPECIAL_OUI << 40 | (x)))
  10. #define OPA_TO_IB_UCAST_LID(x) (((x) >= be16_to_cpu(IB_MULTICAST_LID_BASE)) \
  11. ? 0 : x)
  12. #define OPA_GID_INDEX 0x1
  13. /**
  14. * 0xF8 - 4 bits of multicast range and 1 bit for collective range
  15. * Example: For 24 bit LID space,
  16. * Multicast range: 0xF00000 to 0xF7FFFF
  17. * Collective range: 0xF80000 to 0xFFFFFE
  18. */
  19. #define OPA_MCAST_NR 0x4 /* Number of top bits set */
  20. #define OPA_COLLECTIVE_NR 0x1 /* Number of bits after MCAST_NR */
  21. /**
  22. * ib_is_opa_gid: Returns true if the top 24 bits of the gid
  23. * contains the OPA_STL_OUI identifier. This identifies that
  24. * the provided gid is a special purpose GID meant to carry
  25. * extended LID information.
  26. *
  27. * @gid: The Global identifier
  28. */
  29. static inline bool ib_is_opa_gid(const union ib_gid *gid)
  30. {
  31. return ((be64_to_cpu(gid->global.interface_id) >> 40) ==
  32. OPA_SPECIAL_OUI);
  33. }
  34. /**
  35. * opa_get_lid_from_gid: Returns the last 32 bits of the gid.
  36. * OPA devices use one of the gids in the gid table to also
  37. * store the lid.
  38. *
  39. * @gid: The Global identifier
  40. */
  41. static inline u32 opa_get_lid_from_gid(const union ib_gid *gid)
  42. {
  43. return be64_to_cpu(gid->global.interface_id) & 0xFFFFFFFF;
  44. }
  45. /**
  46. * opa_is_extended_lid: Returns true if dlid or slid are
  47. * extended.
  48. *
  49. * @dlid: The DLID
  50. * @slid: The SLID
  51. */
  52. static inline bool opa_is_extended_lid(__be32 dlid, __be32 slid)
  53. {
  54. if ((be32_to_cpu(dlid) >=
  55. be16_to_cpu(IB_MULTICAST_LID_BASE)) ||
  56. (be32_to_cpu(slid) >=
  57. be16_to_cpu(IB_MULTICAST_LID_BASE)))
  58. return true;
  59. return false;
  60. }
  61. /* Get multicast lid base */
  62. static inline u32 opa_get_mcast_base(u32 nr_top_bits)
  63. {
  64. return (be32_to_cpu(OPA_LID_PERMISSIVE) << (32 - nr_top_bits));
  65. }
  66. /* Check for a valid unicast LID for non-SM traffic types */
  67. static inline bool rdma_is_valid_unicast_lid(struct rdma_ah_attr *attr)
  68. {
  69. if (attr->type == RDMA_AH_ATTR_TYPE_IB) {
  70. if (!rdma_ah_get_dlid(attr) ||
  71. rdma_ah_get_dlid(attr) >=
  72. be16_to_cpu(IB_MULTICAST_LID_BASE))
  73. return false;
  74. } else if (attr->type == RDMA_AH_ATTR_TYPE_OPA) {
  75. if (!rdma_ah_get_dlid(attr) ||
  76. rdma_ah_get_dlid(attr) >=
  77. opa_get_mcast_base(OPA_MCAST_NR))
  78. return false;
  79. }
  80. return true;
  81. }
  82. #endif /* OPA_ADDR_H */