Blame view

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