WIP FPC-III support
[linux/fpc-iii.git] / drivers / infiniband / sw / rxe / rxe_av.c
blobdf0d173d6acba6c8c8d461f4cb1d6b54918c15f0
1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /*
3 * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
4 * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
5 */
7 #include "rxe.h"
8 #include "rxe_loc.h"
10 void rxe_init_av(struct rdma_ah_attr *attr, struct rxe_av *av)
12 rxe_av_from_attr(rdma_ah_get_port_num(attr), av, attr);
13 rxe_av_fill_ip_info(av, attr);
14 memcpy(av->dmac, attr->roce.dmac, ETH_ALEN);
17 int rxe_av_chk_attr(struct rxe_dev *rxe, struct rdma_ah_attr *attr)
19 const struct ib_global_route *grh = rdma_ah_read_grh(attr);
20 struct rxe_port *port;
21 int type;
23 port = &rxe->port;
25 if (rdma_ah_get_ah_flags(attr) & IB_AH_GRH) {
26 if (grh->sgid_index > port->attr.gid_tbl_len) {
27 pr_warn("invalid sgid index = %d\n",
28 grh->sgid_index);
29 return -EINVAL;
32 type = rdma_gid_attr_network_type(grh->sgid_attr);
33 if (type < RDMA_NETWORK_IPV4 ||
34 type > RDMA_NETWORK_IPV6) {
35 pr_warn("invalid network type for rdma_rxe = %d\n",
36 type);
37 return -EINVAL;
41 return 0;
44 void rxe_av_from_attr(u8 port_num, struct rxe_av *av,
45 struct rdma_ah_attr *attr)
47 const struct ib_global_route *grh = rdma_ah_read_grh(attr);
49 memset(av, 0, sizeof(*av));
50 memcpy(av->grh.dgid.raw, grh->dgid.raw, sizeof(grh->dgid.raw));
51 av->grh.flow_label = grh->flow_label;
52 av->grh.sgid_index = grh->sgid_index;
53 av->grh.hop_limit = grh->hop_limit;
54 av->grh.traffic_class = grh->traffic_class;
55 av->port_num = port_num;
58 void rxe_av_to_attr(struct rxe_av *av, struct rdma_ah_attr *attr)
60 struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
62 attr->type = RDMA_AH_ATTR_TYPE_ROCE;
64 memcpy(grh->dgid.raw, av->grh.dgid.raw, sizeof(av->grh.dgid.raw));
65 grh->flow_label = av->grh.flow_label;
66 grh->sgid_index = av->grh.sgid_index;
67 grh->hop_limit = av->grh.hop_limit;
68 grh->traffic_class = av->grh.traffic_class;
70 rdma_ah_set_ah_flags(attr, IB_AH_GRH);
71 rdma_ah_set_port_num(attr, av->port_num);
74 void rxe_av_fill_ip_info(struct rxe_av *av, struct rdma_ah_attr *attr)
76 const struct ib_gid_attr *sgid_attr = attr->grh.sgid_attr;
77 int ibtype;
78 int type;
80 rdma_gid2ip((struct sockaddr *)&av->sgid_addr, &sgid_attr->gid);
81 rdma_gid2ip((struct sockaddr *)&av->dgid_addr,
82 &rdma_ah_read_grh(attr)->dgid);
84 ibtype = rdma_gid_attr_network_type(sgid_attr);
86 switch (ibtype) {
87 case RDMA_NETWORK_IPV4:
88 type = RXE_NETWORK_TYPE_IPV4;
89 break;
90 case RDMA_NETWORK_IPV6:
91 type = RXE_NETWORK_TYPE_IPV4;
92 break;
93 default:
94 /* not reached - checked in rxe_av_chk_attr */
95 type = 0;
96 break;
99 av->network_type = type;
102 struct rxe_av *rxe_get_av(struct rxe_pkt_info *pkt)
104 if (!pkt || !pkt->qp)
105 return NULL;
107 if (qp_type(pkt->qp) == IB_QPT_RC || qp_type(pkt->qp) == IB_QPT_UC)
108 return &pkt->qp->pri_av;
110 return (pkt->wqe) ? &pkt->wqe->av : NULL;