ib_hdrs.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright(c) 2016 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. #ifndef IB_HDRS_H
  48. #define IB_HDRS_H
  49. #include <linux/types.h>
  50. #include <asm/unaligned.h>
  51. #include <rdma/ib_verbs.h>
  52. #define IB_SEQ_NAK (3 << 29)
  53. /* AETH NAK opcode values */
  54. #define IB_RNR_NAK 0x20
  55. #define IB_NAK_PSN_ERROR 0x60
  56. #define IB_NAK_INVALID_REQUEST 0x61
  57. #define IB_NAK_REMOTE_ACCESS_ERROR 0x62
  58. #define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
  59. #define IB_NAK_INVALID_RD_REQUEST 0x64
  60. #define IB_BTH_REQ_ACK BIT(31)
  61. #define IB_BTH_SOLICITED BIT(23)
  62. #define IB_BTH_MIG_REQ BIT(22)
  63. #define IB_GRH_VERSION 6
  64. #define IB_GRH_VERSION_MASK 0xF
  65. #define IB_GRH_VERSION_SHIFT 28
  66. #define IB_GRH_TCLASS_MASK 0xFF
  67. #define IB_GRH_TCLASS_SHIFT 20
  68. #define IB_GRH_FLOW_MASK 0xFFFFF
  69. #define IB_GRH_FLOW_SHIFT 0
  70. #define IB_GRH_NEXT_HDR 0x1B
  71. struct ib_reth {
  72. __be64 vaddr; /* potentially unaligned */
  73. __be32 rkey;
  74. __be32 length;
  75. } __packed;
  76. struct ib_atomic_eth {
  77. __be64 vaddr; /* potentially unaligned */
  78. __be32 rkey;
  79. __be64 swap_data; /* potentially unaligned */
  80. __be64 compare_data; /* potentially unaligned */
  81. } __packed;
  82. union ib_ehdrs {
  83. struct {
  84. __be32 deth[2];
  85. __be32 imm_data;
  86. } ud;
  87. struct {
  88. struct ib_reth reth;
  89. __be32 imm_data;
  90. } rc;
  91. struct {
  92. __be32 aeth;
  93. __be64 atomic_ack_eth; /* potentially unaligned */
  94. } __packed at;
  95. __be32 imm_data;
  96. __be32 aeth;
  97. __be32 ieth;
  98. struct ib_atomic_eth atomic_eth;
  99. } __packed;
  100. struct ib_other_headers {
  101. __be32 bth[3];
  102. union ib_ehdrs u;
  103. } __packed;
  104. struct ib_header {
  105. __be16 lrh[4];
  106. union {
  107. struct {
  108. struct ib_grh grh;
  109. struct ib_other_headers oth;
  110. } l;
  111. struct ib_other_headers oth;
  112. } u;
  113. } __packed;
  114. /* accessors for unaligned __be64 items */
  115. static inline u64 ib_u64_get(__be64 *p)
  116. {
  117. return get_unaligned_be64(p);
  118. }
  119. static inline void ib_u64_put(u64 val, __be64 *p)
  120. {
  121. put_unaligned_be64(val, p);
  122. }
  123. static inline u64 get_ib_reth_vaddr(struct ib_reth *reth)
  124. {
  125. return ib_u64_get(&reth->vaddr);
  126. }
  127. static inline void put_ib_reth_vaddr(u64 val, struct ib_reth *reth)
  128. {
  129. ib_u64_put(val, &reth->vaddr);
  130. }
  131. static inline u64 get_ib_ateth_vaddr(struct ib_atomic_eth *ateth)
  132. {
  133. return ib_u64_get(&ateth->vaddr);
  134. }
  135. static inline void put_ib_ateth_vaddr(u64 val, struct ib_atomic_eth *ateth)
  136. {
  137. ib_u64_put(val, &ateth->vaddr);
  138. }
  139. static inline u64 get_ib_ateth_swap(struct ib_atomic_eth *ateth)
  140. {
  141. return ib_u64_get(&ateth->swap_data);
  142. }
  143. static inline void put_ib_ateth_swap(u64 val, struct ib_atomic_eth *ateth)
  144. {
  145. ib_u64_put(val, &ateth->swap_data);
  146. }
  147. static inline u64 get_ib_ateth_compare(struct ib_atomic_eth *ateth)
  148. {
  149. return ib_u64_get(&ateth->compare_data);
  150. }
  151. static inline void put_ib_ateth_compare(u64 val, struct ib_atomic_eth *ateth)
  152. {
  153. ib_u64_put(val, &ateth->compare_data);
  154. }
  155. #endif /* IB_HDRS_H */