171088Sjasone/*
271088Sjasone * Copyright (c) 2010 Intel Corporation.  All rights reserved.
371088Sjasone *
471088Sjasone * This software is available to you under a choice of one of two
571088Sjasone * licenses.  You may choose to be licensed under the terms of the GNU
671088Sjasone * General Public License (GPL) Version 2, available from the file
771088Sjasone * COPYING in the main directory of this source tree, or the
871088Sjasone * OpenIB.org BSD license below:
971088Sjasone *
1071088Sjasone *     Redistribution and use in source and binary forms, with or
1171088Sjasone *     without modification, are permitted provided that the following
1271088Sjasone *     conditions are met:
1371088Sjasone *
1471088Sjasone *      - Redistributions of source code must retain the above
1571088Sjasone *        copyright notice, this list of conditions and the following
1671088Sjasone *        disclaimer.
1771088Sjasone *
1871088Sjasone *      - Redistributions in binary form must reproduce the above
1971088Sjasone *        copyright notice, this list of conditions and the following
2071088Sjasone *        disclaimer in the documentation and/or other materials
2171088Sjasone *        provided with the distribution.
2271088Sjasone *
2371088Sjasone * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2471088Sjasone * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2571088Sjasone * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2671088Sjasone * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27116182Sobrien * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28116182Sobrien * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29116182Sobrien * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3071088Sjasone * SOFTWARE.
3171088Sjasone */
3271088Sjasone
3371088Sjasone#if !defined(_RDMA_IB_H)
3476166Smarkm#define _RDMA_IB_H
3576166Smarkm
3671088Sjasone#include <infiniband/types.h>
3771088Sjasone#include <infiniband/endian.h>
3871088Sjasone#include <string.h>
3971088Sjasone
40109862Sjeff#ifndef AF_IB
4171088Sjasone#define AF_IB 41
42126326Sjhb#endif
4371088Sjasone#ifndef PF_IB
4471088Sjasone#define PF_IB AF_IB
4571088Sjasone#endif
4671088Sjasone
4771088Sjasonestruct ib_addr {
4871088Sjasone	union {
4971088Sjasone		__u8		uib_addr8[16];
5071088Sjasone		__be16		uib_addr16[8];
5171088Sjasone		__be32		uib_addr32[4];
52167789Sjhb		__be64		uib_addr64[2];
53250581Shiren	} ib_u;
54103216Sjulian#define sib_addr8		ib_u.uib_addr8
5587594Sobrien#define sib_addr16		ib_u.uib_addr16
56167789Sjhb#define sib_addr32		ib_u.uib_addr32
5771088Sjasone#define sib_addr64		ib_u.uib_addr64
5871088Sjasone#define sib_raw			ib_u.uib_addr8
5971088Sjasone#define sib_subnet_prefix	ib_u.uib_addr64[0]
6071088Sjasone#define sib_interface_id	ib_u.uib_addr64[1]
6171088Sjasone};
6271088Sjasone
6371088Sjasonestatic inline int ib_addr_any(const struct ib_addr *a)
6471088Sjasone{
6571088Sjasone	return ((a->sib_addr64[0] | a->sib_addr64[1]) == 0);
6671088Sjasone}
67127954Sjhb
6871088Sjasonestatic inline int ib_addr_loopback(const struct ib_addr *a)
6971088Sjasone{
7071088Sjasone	return ((a->sib_addr32[0] | a->sib_addr32[1] |
7171088Sjasone		 a->sib_addr32[2] | (a->sib_addr32[3] ^ htobe32(1))) == 0);
7271088Sjasone}
7371088Sjasone
7471088Sjasonestatic inline void ib_addr_set(struct ib_addr *addr,
7571088Sjasone			       __be32 w1, __be32 w2, __be32 w3, __be32 w4)
7671088Sjasone{
77126326Sjhb	addr->sib_addr32[0] = w1;
78136445Sjhb	addr->sib_addr32[1] = w2;
7971088Sjasone	addr->sib_addr32[2] = w3;
80136445Sjhb	addr->sib_addr32[3] = w4;
81126326Sjhb}
82126326Sjhb
83126326Sjhbstatic inline int ib_addr_cmp(const struct ib_addr *a1, const struct ib_addr *a2)
84126326Sjhb{
8571088Sjasone	return memcmp(a1, a2, sizeof(struct ib_addr));
8671088Sjasone}
8771088Sjasone
8883366Sjulianstruct sockaddr_ib {
8971088Sjasone	unsigned short int	sib_family;	/* AF_IB */
9083366Sjulian	__be16			sib_pkey;
9171088Sjasone	__be32			sib_flowinfo;
9271088Sjasone	struct ib_addr		sib_addr;
9371088Sjasone	__be64			sib_sid;
9471088Sjasone	__be64			sib_sid_mask;
95167789Sjhb	__u64			sib_scope_id;
9671088Sjasone};
97167789Sjhb
98167789Sjhb#endif /* _RDMA_IB_H */
99167786Sjhb