aboutsummaryrefslogtreecommitdiffstats
path: root/include/rdma
diff options
context:
space:
mode:
Diffstat (limited to 'include/rdma')
-rw-r--r--include/rdma/ib_addr.h43
-rw-r--r--include/rdma/ib_pack.h9
2 files changed, 48 insertions, 4 deletions
diff --git a/include/rdma/ib_addr.h b/include/rdma/ib_addr.h
index 904ffa92fc93..b5fc9f39122b 100644
--- a/include/rdma/ib_addr.h
+++ b/include/rdma/ib_addr.h
@@ -39,6 +39,7 @@
39#include <linux/if_arp.h> 39#include <linux/if_arp.h>
40#include <linux/netdevice.h> 40#include <linux/netdevice.h>
41#include <linux/socket.h> 41#include <linux/socket.h>
42#include <linux/if_vlan.h>
42#include <rdma/ib_verbs.h> 43#include <rdma/ib_verbs.h>
43#include <rdma/ib_pack.h> 44#include <rdma/ib_pack.h>
44 45
@@ -129,21 +130,41 @@ static inline int rdma_addr_gid_offset(struct rdma_dev_addr *dev_addr)
129 return dev_addr->dev_type == ARPHRD_INFINIBAND ? 4 : 0; 130 return dev_addr->dev_type == ARPHRD_INFINIBAND ? 4 : 0;
130} 131}
131 132
132static inline void iboe_mac_to_ll(union ib_gid *gid, u8 *mac) 133static inline void iboe_mac_vlan_to_ll(union ib_gid *gid, u8 *mac, u16 vid)
133{ 134{
134 memset(gid->raw, 0, 16); 135 memset(gid->raw, 0, 16);
135 *((__be32 *) gid->raw) = cpu_to_be32(0xfe800000); 136 *((__be32 *) gid->raw) = cpu_to_be32(0xfe800000);
136 gid->raw[12] = 0xfe; 137 if (vid < 0x1000) {
137 gid->raw[11] = 0xff; 138 gid->raw[12] = vid & 0xff;
139 gid->raw[11] = vid >> 8;
140 } else {
141 gid->raw[12] = 0xfe;
142 gid->raw[11] = 0xff;
143 }
138 memcpy(gid->raw + 13, mac + 3, 3); 144 memcpy(gid->raw + 13, mac + 3, 3);
139 memcpy(gid->raw + 8, mac, 3); 145 memcpy(gid->raw + 8, mac, 3);
140 gid->raw[8] ^= 2; 146 gid->raw[8] ^= 2;
141} 147}
142 148
149static inline u16 rdma_vlan_dev_vlan_id(const struct net_device *dev)
150{
151 return dev->priv_flags & IFF_802_1Q_VLAN ?
152 vlan_dev_vlan_id(dev) : 0xffff;
153}
154
143static inline void iboe_addr_get_sgid(struct rdma_dev_addr *dev_addr, 155static inline void iboe_addr_get_sgid(struct rdma_dev_addr *dev_addr,
144 union ib_gid *gid) 156 union ib_gid *gid)
145{ 157{
146 iboe_mac_to_ll(gid, dev_addr->src_dev_addr); 158 struct net_device *dev;
159 u16 vid = 0xffff;
160
161 dev = dev_get_by_index(&init_net, dev_addr->bound_dev_if);
162 if (dev) {
163 vid = rdma_vlan_dev_vlan_id(dev);
164 dev_put(dev);
165 }
166
167 iboe_mac_vlan_to_ll(gid, dev_addr->src_dev_addr, vid);
147} 168}
148 169
149static inline void rdma_addr_get_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid) 170static inline void rdma_addr_get_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid)
@@ -244,4 +265,18 @@ static inline void rdma_get_mcast_mac(struct in6_addr *addr, u8 *mac)
244 mac[i] = addr->s6_addr[i + 10]; 265 mac[i] = addr->s6_addr[i + 10];
245} 266}
246 267
268static inline u16 rdma_get_vlan_id(union ib_gid *dgid)
269{
270 u16 vid;
271
272 vid = dgid->raw[11] << 8 | dgid->raw[12];
273 return vid < 0x1000 ? vid : 0xffff;
274}
275
276static inline struct net_device *rdma_vlan_dev_real_dev(const struct net_device *dev)
277{
278 return dev->priv_flags & IFF_802_1Q_VLAN ?
279 vlan_dev_real_dev(dev) : 0;
280}
281
247#endif /* IB_ADDR_H */ 282#endif /* IB_ADDR_H */
diff --git a/include/rdma/ib_pack.h b/include/rdma/ib_pack.h
index 6b91d8e7a1fa..b37fe3b10a9d 100644
--- a/include/rdma/ib_pack.h
+++ b/include/rdma/ib_pack.h
@@ -38,6 +38,7 @@
38enum { 38enum {
39 IB_LRH_BYTES = 8, 39 IB_LRH_BYTES = 8,
40 IB_ETH_BYTES = 14, 40 IB_ETH_BYTES = 14,
41 IB_VLAN_BYTES = 4,
41 IB_GRH_BYTES = 40, 42 IB_GRH_BYTES = 40,
42 IB_BTH_BYTES = 12, 43 IB_BTH_BYTES = 12,
43 IB_DETH_BYTES = 8 44 IB_DETH_BYTES = 8
@@ -219,11 +220,18 @@ struct ib_unpacked_eth {
219 __be16 type; 220 __be16 type;
220}; 221};
221 222
223struct ib_unpacked_vlan {
224 __be16 tag;
225 __be16 type;
226};
227
222struct ib_ud_header { 228struct ib_ud_header {
223 int lrh_present; 229 int lrh_present;
224 struct ib_unpacked_lrh lrh; 230 struct ib_unpacked_lrh lrh;
225 int eth_present; 231 int eth_present;
226 struct ib_unpacked_eth eth; 232 struct ib_unpacked_eth eth;
233 int vlan_present;
234 struct ib_unpacked_vlan vlan;
227 int grh_present; 235 int grh_present;
228 struct ib_unpacked_grh grh; 236 struct ib_unpacked_grh grh;
229 struct ib_unpacked_bth bth; 237 struct ib_unpacked_bth bth;
@@ -245,6 +253,7 @@ void ib_unpack(const struct ib_field *desc,
245void ib_ud_header_init(int payload_bytes, 253void ib_ud_header_init(int payload_bytes,
246 int lrh_present, 254 int lrh_present,
247 int eth_present, 255 int eth_present,
256 int vlan_present,
248 int grh_present, 257 int grh_present,
249 int immediate_present, 258 int immediate_present,
250 struct ib_ud_header *header); 259 struct ib_ud_header *header);