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#include <linux/export.h>
34#include <rdma/ib_marshall.h>
35
36void ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst,
37 struct rdma_ah_attr *src)
38{
39 memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
40 dst->dlid = rdma_ah_get_dlid(src);
41 dst->sl = rdma_ah_get_sl(src);
42 dst->src_path_bits = rdma_ah_get_path_bits(src);
43 dst->static_rate = rdma_ah_get_static_rate(src);
44 dst->is_global = rdma_ah_get_ah_flags(src) &
45 IB_AH_GRH ? 1 : 0;
46 if (dst->is_global) {
47 const struct ib_global_route *grh = rdma_ah_read_grh(src);
48
49 memcpy(dst->grh.dgid, grh->dgid.raw, sizeof(grh->dgid));
50 dst->grh.flow_label = grh->flow_label;
51 dst->grh.sgid_index = grh->sgid_index;
52 dst->grh.hop_limit = grh->hop_limit;
53 dst->grh.traffic_class = grh->traffic_class;
54 }
55 dst->port_num = rdma_ah_get_port_num(src);
56 dst->reserved = 0;
57}
58EXPORT_SYMBOL(ib_copy_ah_attr_to_user);
59
60void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
61 struct ib_qp_attr *src)
62{
63 dst->qp_state = src->qp_state;
64 dst->cur_qp_state = src->cur_qp_state;
65 dst->path_mtu = src->path_mtu;
66 dst->path_mig_state = src->path_mig_state;
67 dst->qkey = src->qkey;
68 dst->rq_psn = src->rq_psn;
69 dst->sq_psn = src->sq_psn;
70 dst->dest_qp_num = src->dest_qp_num;
71 dst->qp_access_flags = src->qp_access_flags;
72
73 dst->max_send_wr = src->cap.max_send_wr;
74 dst->max_recv_wr = src->cap.max_recv_wr;
75 dst->max_send_sge = src->cap.max_send_sge;
76 dst->max_recv_sge = src->cap.max_recv_sge;
77 dst->max_inline_data = src->cap.max_inline_data;
78
79 ib_copy_ah_attr_to_user(&dst->ah_attr, &src->ah_attr);
80 ib_copy_ah_attr_to_user(&dst->alt_ah_attr, &src->alt_ah_attr);
81
82 dst->pkey_index = src->pkey_index;
83 dst->alt_pkey_index = src->alt_pkey_index;
84 dst->en_sqd_async_notify = src->en_sqd_async_notify;
85 dst->sq_draining = src->sq_draining;
86 dst->max_rd_atomic = src->max_rd_atomic;
87 dst->max_dest_rd_atomic = src->max_dest_rd_atomic;
88 dst->min_rnr_timer = src->min_rnr_timer;
89 dst->port_num = src->port_num;
90 dst->timeout = src->timeout;
91 dst->retry_cnt = src->retry_cnt;
92 dst->rnr_retry = src->rnr_retry;
93 dst->alt_port_num = src->alt_port_num;
94 dst->alt_timeout = src->alt_timeout;
95 memset(dst->reserved, 0, sizeof(dst->reserved));
96}
97EXPORT_SYMBOL(ib_copy_qp_attr_to_user);
98
99static void __ib_copy_path_rec_to_user(struct ib_user_path_rec *dst,
100 struct sa_path_rec *src)
101{
102 memcpy(dst->dgid, src->dgid.raw, sizeof(src->dgid));
103 memcpy(dst->sgid, src->sgid.raw, sizeof(src->sgid));
104
105 dst->dlid = htons(ntohl(sa_path_get_dlid(src)));
106 dst->slid = htons(ntohl(sa_path_get_slid(src)));
107 dst->raw_traffic = sa_path_get_raw_traffic(src);
108 dst->flow_label = src->flow_label;
109 dst->hop_limit = src->hop_limit;
110 dst->traffic_class = src->traffic_class;
111 dst->reversible = src->reversible;
112 dst->numb_path = src->numb_path;
113 dst->pkey = src->pkey;
114 dst->sl = src->sl;
115 dst->mtu_selector = src->mtu_selector;
116 dst->mtu = src->mtu;
117 dst->rate_selector = src->rate_selector;
118 dst->rate = src->rate;
119 dst->packet_life_time = src->packet_life_time;
120 dst->preference = src->preference;
121 dst->packet_life_time_selector = src->packet_life_time_selector;
122}
123
124void ib_copy_path_rec_to_user(struct ib_user_path_rec *dst,
125 struct sa_path_rec *src)
126{
127 struct sa_path_rec rec;
128
129 if (src->rec_type == SA_PATH_REC_TYPE_OPA) {
130 sa_convert_path_opa_to_ib(&rec, src);
131 __ib_copy_path_rec_to_user(dst, &rec);
132 return;
133 }
134 __ib_copy_path_rec_to_user(dst, src);
135}
136EXPORT_SYMBOL(ib_copy_path_rec_to_user);
137
138void ib_copy_path_rec_from_user(struct sa_path_rec *dst,
139 struct ib_user_path_rec *src)
140{
141 __be32 slid, dlid;
142
143 memset(dst, 0, sizeof(*dst));
144 if ((ib_is_opa_gid((union ib_gid *)src->sgid)) ||
145 (ib_is_opa_gid((union ib_gid *)src->dgid))) {
146 dst->rec_type = SA_PATH_REC_TYPE_OPA;
147 slid = htonl(opa_get_lid_from_gid((union ib_gid *)src->sgid));
148 dlid = htonl(opa_get_lid_from_gid((union ib_gid *)src->dgid));
149 } else {
150 dst->rec_type = SA_PATH_REC_TYPE_IB;
151 slid = htonl(ntohs(src->slid));
152 dlid = htonl(ntohs(src->dlid));
153 }
154 memcpy(dst->dgid.raw, src->dgid, sizeof dst->dgid);
155 memcpy(dst->sgid.raw, src->sgid, sizeof dst->sgid);
156
157 sa_path_set_dlid(dst, dlid);
158 sa_path_set_slid(dst, slid);
159 sa_path_set_raw_traffic(dst, src->raw_traffic);
160 dst->flow_label = src->flow_label;
161 dst->hop_limit = src->hop_limit;
162 dst->traffic_class = src->traffic_class;
163 dst->reversible = src->reversible;
164 dst->numb_path = src->numb_path;
165 dst->pkey = src->pkey;
166 dst->sl = src->sl;
167 dst->mtu_selector = src->mtu_selector;
168 dst->mtu = src->mtu;
169 dst->rate_selector = src->rate_selector;
170 dst->rate = src->rate;
171 dst->packet_life_time = src->packet_life_time;
172 dst->preference = src->preference;
173 dst->packet_life_time_selector = src->packet_life_time_selector;
174
175
176 sa_path_set_dmac_zero(dst);
177 sa_path_set_ndev(dst, NULL);
178 sa_path_set_ifindex(dst, 0);
179}
180EXPORT_SYMBOL(ib_copy_path_rec_from_user);
181