dma-mapping: fix 32-bit overflow with CONFIG_ARM_LPAE=n
[platform/kernel/linux-rpi.git] / drivers / infiniband / sw / rxe / rxe_av.c
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  */
6
7 #include "rxe.h"
8 #include "rxe_loc.h"
9
10 void rxe_init_av(struct rdma_ah_attr *attr, struct rxe_av *av)
11 {
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);
15 }
16
17 int rxe_av_chk_attr(struct rxe_dev *rxe, struct rdma_ah_attr *attr)
18 {
19         struct rxe_port *port;
20
21         port = &rxe->port;
22
23         if (rdma_ah_get_ah_flags(attr) & IB_AH_GRH) {
24                 u8 sgid_index = rdma_ah_read_grh(attr)->sgid_index;
25
26                 if (sgid_index > port->attr.gid_tbl_len) {
27                         pr_warn("invalid sgid index = %d\n", sgid_index);
28                         return -EINVAL;
29                 }
30         }
31
32         return 0;
33 }
34
35 void rxe_av_from_attr(u8 port_num, struct rxe_av *av,
36                      struct rdma_ah_attr *attr)
37 {
38         const struct ib_global_route *grh = rdma_ah_read_grh(attr);
39
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;
47 }
48
49 void rxe_av_to_attr(struct rxe_av *av, struct rdma_ah_attr *attr)
50 {
51         struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
52
53         attr->type = RDMA_AH_ATTR_TYPE_ROCE;
54
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;
60
61         rdma_ah_set_ah_flags(attr, IB_AH_GRH);
62         rdma_ah_set_port_num(attr, av->port_num);
63 }
64
65 void rxe_av_fill_ip_info(struct rxe_av *av, struct rdma_ah_attr *attr)
66 {
67         const struct ib_gid_attr *sgid_attr = attr->grh.sgid_attr;
68
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);
73 }
74
75 struct rxe_av *rxe_get_av(struct rxe_pkt_info *pkt)
76 {
77         if (!pkt || !pkt->qp)
78                 return NULL;
79
80         if (qp_type(pkt->qp) == IB_QPT_RC || qp_type(pkt->qp) == IB_QPT_UC)
81                 return &pkt->qp->pri_av;
82
83         return (pkt->wqe) ? &pkt->wqe->av : NULL;
84 }