You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ipoib.h 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. This software is available to you under a choice of one of two
  3. licenses. You may choose to be licensed under the terms of the GNU
  4. General Public License (GPL) Version 2, available at
  5. <http://www.fsf.org/copyleft/gpl.html>, or the OpenIB.org BSD
  6. license, available in the LICENSE.TXT file accompanying this
  7. software. These details are also available at
  8. <http://openib.org/license.html>.
  9. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  10. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  12. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  13. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  14. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. SOFTWARE.
  17. Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
  18. */
  19. #ifndef __ipoib_h__
  20. #define __ipoib_h__
  21. #define ARP_PROT_TYPE 0x806
  22. #define IPV4_PROT_TYPE 0x800
  23. #define IPOIB_HW_TYPE 0x20
  24. #define ETH_HW_TYPE 1
  25. #define ARP_OP_REQUESET 1
  26. #define ARP_OP_REPLY 2
  27. #define MLX_ETH_3BYTE_PREFIX 0x2c9 /* 00,02,c9 */
  28. #define MLX_ETH_BYTE0 0
  29. #define MLX_ETH_BYTE1 2
  30. #define MLX_ETH_BYTE2 0xC9
  31. #define IP_PROT_UDP 17
  32. #define DHCP_TYPE_REQUEST 1
  33. #define DHCP_TYPE_RESPONSE 2
  34. #define DHCP_TYPE_ACK 5
  35. struct ipoib_mac_st {
  36. __u32 qpn:24;
  37. __u32 r0:8;
  38. __u8 gid[16];
  39. } __attribute__ ((packed));
  40. struct arp_packet_st {
  41. __u16 arp_prot_type;
  42. __u16 hw_type;
  43. __u16 opcode;
  44. __u8 prot_size;
  45. __u8 hw_len;
  46. struct ipoib_mac_st sender_mac;
  47. __u32 sender_ip;
  48. struct ipoib_mac_st target_mac;
  49. __u32 target_ip;
  50. } __attribute__ ((packed));
  51. /* this struct is used to translate between ipoib and
  52. ethernet mac addresses */
  53. struct mac_xlation_st {
  54. __u8 valid; /* 1=entry valid 0=entry free */
  55. __u32 youth; /* youth of this entry the lowest the
  56. number the older in age */
  57. __u8 eth_mac_lsb[3]; /* three bytes Ethernet MAC
  58. LS bytes are constants */
  59. union ib_gid_u gid;
  60. __u32 qpn;
  61. ud_av_t av; /* address vector representing neighbour */
  62. };
  63. static inline __u16 get_prot_type(void *data)
  64. {
  65. __u8 *ptr = data;
  66. return be16_to_cpu(*((__u16 *) ptr));
  67. }
  68. static inline __u8 get_hw_len(void *data)
  69. {
  70. return ((__u8 *) data)[8];
  71. }
  72. static inline __u8 get_prot_size(void *data)
  73. {
  74. return ((__u8 *) data)[9];
  75. }
  76. static inline __u16 get_opcode(const void *data)
  77. {
  78. return be16_to_cpu(*((__u16 *) (&(((__u8 *) data)[10]))));
  79. }
  80. static inline __u32 get_sender_qpn(void *data)
  81. {
  82. __u8 *ptr = data;
  83. return (ptr[13] << 16) | (ptr[14] << 8) | ptr[15];
  84. }
  85. static inline const __u8 *get_sender_gid(void *data)
  86. {
  87. return &(((__u8 *) data)[16]);
  88. }
  89. static inline void *arp_mac6_get_sender_ip(const void *data)
  90. {
  91. return (__u8 *) data + 14;
  92. }
  93. static inline const void *arp_mac6_get_target_ip(const void *data)
  94. {
  95. return data + 24;
  96. }
  97. static inline void arp_mac20_set_sender_ip(const void *ip, void *data)
  98. {
  99. memcpy(((__u8 *) data) + 28, ip, 4);
  100. }
  101. static inline void arp_mac20_set_target_ip(const void *ip, void *data)
  102. {
  103. memcpy(((__u8 *) data) + 52, ip, 4);
  104. }
  105. static inline void arp_mac20_set_sender_mac(const void *qpn, const void *gid,
  106. void *data)
  107. {
  108. memcpy(((__u8 *) data) + 9, qpn, 3);
  109. memcpy(((__u8 *) data) + 12, gid, 16);
  110. }
  111. static inline void arp_mac20_set_target_mac(void *qpn, void *gid, void *data)
  112. {
  113. memcpy(((__u8 *) data) + 33, qpn, 3);
  114. memcpy(((__u8 *) data) + 36, gid, 16);
  115. }
  116. static inline const void *arp_mac6_get_opcode(const void *data)
  117. {
  118. return data + 6;
  119. }
  120. static inline void arp_mac20_set_opcode(const void *opcode, void *data)
  121. {
  122. memcpy(data + 6, opcode, 2);
  123. }
  124. static inline const void *arp_mac6_get_target_mac(const void *data)
  125. {
  126. return data + 18;
  127. }
  128. static inline const void *arp_mac20_get_sender_qpn(void *data)
  129. {
  130. return ((__u8 *) data) + 13;
  131. }
  132. static inline const void *arp_mac20_get_sender_gid(void *data)
  133. {
  134. return ((__u8 *) data) + 16;
  135. }
  136. static inline const void *arp_mac20_get_target_qpn(void *data)
  137. {
  138. return ((__u8 *) data) + 37;
  139. }
  140. static inline const void *arp_mac20_get_target_gid(void *data)
  141. {
  142. return ((__u8 *) data) + 40;
  143. }
  144. static inline const void *get_lptr_by_off(const void *packet, __u16 offset)
  145. {
  146. return packet + offset;
  147. }
  148. static inline __u8 get_ip_protocl_type(const void *packet)
  149. {
  150. const void *ptr;
  151. __u8 prot;
  152. ptr = get_lptr_by_off(packet, 9);
  153. memcpy(&prot, ptr, 1);
  154. return prot;
  155. }
  156. static inline __u16 get_udp_dest_port(const void *packet)
  157. {
  158. const void *ptr;
  159. __u16 port;
  160. ptr = get_lptr_by_off(packet, 22);
  161. memcpy(&port, ptr, 2);
  162. return port;
  163. }
  164. static inline __u8 get_dhcp_message_type(const void *packet)
  165. {
  166. const void *ptr;
  167. __u8 type;
  168. ptr = get_lptr_by_off(packet, 28);
  169. memcpy(&type, ptr, 1);
  170. return type;
  171. }
  172. static inline void set_hw_type(__u8 * packet)
  173. {
  174. packet[29] = IPOIB_HW_TYPE;
  175. }
  176. static inline void zero_hw_len(__u8 * packet)
  177. {
  178. packet[30] = 0;
  179. }
  180. static inline void set_udp_csum(__u8 * packet, __u16 val)
  181. {
  182. __u16 *csum_ptr;
  183. csum_ptr = (__u16 *) (packet + 26);
  184. *csum_ptr = htons(val);
  185. }
  186. static inline void zero_chaddr(__u8 * packet)
  187. {
  188. memset(packet + 56, 0, 16);
  189. }
  190. static inline void set_bcast_flag(__u8 * packet)
  191. {
  192. packet[38] = 0x80;
  193. }
  194. static inline __u8 get_ip_protocl(void *buf)
  195. {
  196. return ((__u8 *) buf)[9];
  197. }
  198. static inline __u16 get_udp_dst_port(void *buf)
  199. {
  200. return be16_to_cpu(*((__u16 *) (((__u8 *) buf) + 0x16)));
  201. }
  202. static inline __u8 get_dhcp_msg_type(void *buf)
  203. {
  204. return ((__u8 *) buf)[0x1c];
  205. }
  206. static inline void set_eth_hwtype(void *buf)
  207. {
  208. ((__u8 *) buf)[0x1d] = ETH_HW_TYPE;
  209. }
  210. static inline void set_eth_hwlen(void *buf)
  211. {
  212. ((__u8 *) buf)[0x1e] = 6;
  213. }
  214. static inline void add_udp_len(void *buf, __u16 size_add)
  215. {
  216. __u16 old_len, *len_ptr;
  217. len_ptr = (__u16 *) (((__u8 *) buf) + 24);
  218. old_len = ntohs(*len_ptr);
  219. *len_ptr = htons(old_len + size_add);
  220. }
  221. static inline void set_own_mac(void *buf)
  222. {
  223. ((__u8 *) buf)[0x38] = 0xff; //MLX_ETH_BYTE0;
  224. ((__u8 *) buf)[0x39] = 0xff; //MLX_ETH_BYTE1;
  225. ((__u8 *) buf)[0x3a] = 0xff; //MLX_ETH_BYTE2;
  226. ((__u8 *) buf)[0x3b] = 0xff; //0;
  227. ((__u8 *) buf)[0x3c] = 0xff; //0;
  228. ((__u8 *) buf)[0x3d] = 0xff; //0;
  229. }
  230. static int ipoib_handle_rcv(void *buf, void **out_buf_p,
  231. unsigned int *new_size_p, int *bcast_p);
  232. static int ipoib_send_packet(const __u8 * mac, __u16 protocol, const void *data,
  233. unsigned int size);
  234. static int ipoib_init(struct pci_device *pci);
  235. static u8 *get_port_gid(void);
  236. static int ipoib_read_packet(__u16 * prot_p, void *data, unsigned int *size_p,
  237. int *is_bcast_p);
  238. #endif /* __ipoib_h__ */