1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
3 * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
4 * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
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 struct rxe_port *port;
23 if (rdma_ah_get_ah_flags(attr) & IB_AH_GRH) {
24 u8 sgid_index = rdma_ah_read_grh(attr)->sgid_index;
26 if (sgid_index > port->attr.gid_tbl_len) {
27 pr_warn("invalid sgid index = %d\n", sgid_index);
35 void rxe_av_from_attr(u8 port_num, struct rxe_av *av,
36 struct rdma_ah_attr *attr)
38 const struct ib_global_route *grh = rdma_ah_read_grh(attr);
40 memset(av, 0, sizeof(*av));
41 memcpy(av->grh.dgid.raw, grh->dgid.raw, sizeof(grh->dgid.raw));
42 av->grh.flow_label = grh->flow_label;
43 av->grh.sgid_index = grh->sgid_index;
44 av->grh.hop_limit = grh->hop_limit;
45 av->grh.traffic_class = grh->traffic_class;
46 av->port_num = port_num;
49 void rxe_av_to_attr(struct rxe_av *av, struct rdma_ah_attr *attr)
51 struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
53 attr->type = RDMA_AH_ATTR_TYPE_ROCE;
55 memcpy(grh->dgid.raw, av->grh.dgid.raw, sizeof(av->grh.dgid.raw));
56 grh->flow_label = av->grh.flow_label;
57 grh->sgid_index = av->grh.sgid_index;
58 grh->hop_limit = av->grh.hop_limit;
59 grh->traffic_class = av->grh.traffic_class;
61 rdma_ah_set_ah_flags(attr, IB_AH_GRH);
62 rdma_ah_set_port_num(attr, av->port_num);
65 void rxe_av_fill_ip_info(struct rxe_av *av, struct rdma_ah_attr *attr)
67 const struct ib_gid_attr *sgid_attr = attr->grh.sgid_attr;
69 rdma_gid2ip((struct sockaddr *)&av->sgid_addr, &sgid_attr->gid);
70 rdma_gid2ip((struct sockaddr *)&av->dgid_addr,
71 &rdma_ah_read_grh(attr)->dgid);
72 av->network_type = rdma_gid_attr_network_type(sgid_attr);
75 struct rxe_av *rxe_get_av(struct rxe_pkt_info *pkt)
80 if (qp_type(pkt->qp) == IB_QPT_RC || qp_type(pkt->qp) == IB_QPT_UC)
81 return &pkt->qp->pri_av;
83 return (pkt->wqe) ? &pkt->wqe->av : NULL;