1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0 3 * 4 * Copyright (c) 2005 Intel Corporation. All rights reserved. 5 * 6 * This software is available to you under a choice of one of two 7 * licenses. You may choose to be licensed under the terms of the GNU 8 * General Public License (GPL) Version 2, available from the file 9 * COPYING in the main directory of this source tree, or the 10 * OpenIB.org BSD license below: 11 * 12 * Redistribution and use in source and binary forms, with or 13 * without modification, are permitted provided that the following 14 * conditions are met: 15 * 16 * - Redistributions of source code must retain the above 17 * copyright notice, this list of conditions and the following 18 * disclaimer. 19 * 20 * - Redistributions in binary form must reproduce the above 21 * copyright notice, this list of conditions and the following 22 * disclaimer in the documentation and/or other materials 23 * provided with the distribution. 24 * 25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 * SOFTWARE. 33 */ 34 35 #include <sys/cdefs.h> 36 #include <rdma/ib_marshall.h> 37 38 void ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst, 39 struct ib_ah_attr *src) 40 { 41 memcpy(dst->grh.dgid, src->grh.dgid.raw, sizeof src->grh.dgid); 42 dst->grh.flow_label = src->grh.flow_label; 43 dst->grh.sgid_index = src->grh.sgid_index; 44 dst->grh.hop_limit = src->grh.hop_limit; 45 dst->grh.traffic_class = src->grh.traffic_class; 46 memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved)); 47 dst->dlid = src->dlid; 48 dst->sl = src->sl; 49 dst->src_path_bits = src->src_path_bits; 50 dst->static_rate = src->static_rate; 51 dst->is_global = src->ah_flags & IB_AH_GRH ? 1 : 0; 52 dst->port_num = src->port_num; 53 dst->reserved = 0; 54 } 55 EXPORT_SYMBOL(ib_copy_ah_attr_to_user); 56 57 void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst, 58 struct ib_qp_attr *src) 59 { 60 dst->qp_state = src->qp_state; 61 dst->cur_qp_state = src->cur_qp_state; 62 dst->path_mtu = src->path_mtu; 63 dst->path_mig_state = src->path_mig_state; 64 dst->qkey = src->qkey; 65 dst->rq_psn = src->rq_psn; 66 dst->sq_psn = src->sq_psn; 67 dst->dest_qp_num = src->dest_qp_num; 68 dst->qp_access_flags = src->qp_access_flags; 69 70 dst->max_send_wr = src->cap.max_send_wr; 71 dst->max_recv_wr = src->cap.max_recv_wr; 72 dst->max_send_sge = src->cap.max_send_sge; 73 dst->max_recv_sge = src->cap.max_recv_sge; 74 dst->max_inline_data = src->cap.max_inline_data; 75 76 ib_copy_ah_attr_to_user(&dst->ah_attr, &src->ah_attr); 77 ib_copy_ah_attr_to_user(&dst->alt_ah_attr, &src->alt_ah_attr); 78 79 dst->pkey_index = src->pkey_index; 80 dst->alt_pkey_index = src->alt_pkey_index; 81 dst->en_sqd_async_notify = src->en_sqd_async_notify; 82 dst->sq_draining = src->sq_draining; 83 dst->max_rd_atomic = src->max_rd_atomic; 84 dst->max_dest_rd_atomic = src->max_dest_rd_atomic; 85 dst->min_rnr_timer = src->min_rnr_timer; 86 dst->port_num = src->port_num; 87 dst->timeout = src->timeout; 88 dst->retry_cnt = src->retry_cnt; 89 dst->rnr_retry = src->rnr_retry; 90 dst->alt_port_num = src->alt_port_num; 91 dst->alt_timeout = src->alt_timeout; 92 memset(dst->reserved, 0, sizeof(dst->reserved)); 93 } 94 EXPORT_SYMBOL(ib_copy_qp_attr_to_user); 95 96 void ib_copy_path_rec_to_user(struct ib_user_path_rec *dst, 97 struct ib_sa_path_rec *src) 98 { 99 memcpy(dst->dgid, src->dgid.raw, sizeof src->dgid); 100 memcpy(dst->sgid, src->sgid.raw, sizeof src->sgid); 101 102 dst->dlid = src->dlid; 103 dst->slid = src->slid; 104 dst->raw_traffic = src->raw_traffic; 105 dst->flow_label = src->flow_label; 106 dst->hop_limit = src->hop_limit; 107 dst->traffic_class = src->traffic_class; 108 dst->reversible = src->reversible; 109 dst->numb_path = src->numb_path; 110 dst->pkey = src->pkey; 111 dst->sl = src->sl; 112 dst->mtu_selector = src->mtu_selector; 113 dst->mtu = src->mtu; 114 dst->rate_selector = src->rate_selector; 115 dst->rate = src->rate; 116 dst->packet_life_time = src->packet_life_time; 117 dst->preference = src->preference; 118 dst->packet_life_time_selector = src->packet_life_time_selector; 119 } 120 EXPORT_SYMBOL(ib_copy_path_rec_to_user); 121 122 void ib_copy_path_rec_from_user(struct ib_sa_path_rec *dst, 123 struct ib_user_path_rec *src) 124 { 125 memcpy(dst->dgid.raw, src->dgid, sizeof dst->dgid); 126 memcpy(dst->sgid.raw, src->sgid, sizeof dst->sgid); 127 128 dst->dlid = src->dlid; 129 dst->slid = src->slid; 130 dst->raw_traffic = src->raw_traffic; 131 dst->flow_label = src->flow_label; 132 dst->hop_limit = src->hop_limit; 133 dst->traffic_class = src->traffic_class; 134 dst->reversible = src->reversible; 135 dst->numb_path = src->numb_path; 136 dst->pkey = src->pkey; 137 dst->sl = src->sl; 138 dst->mtu_selector = src->mtu_selector; 139 dst->mtu = src->mtu; 140 dst->rate_selector = src->rate_selector; 141 dst->rate = src->rate; 142 dst->packet_life_time = src->packet_life_time; 143 dst->preference = src->preference; 144 dst->packet_life_time_selector = src->packet_life_time_selector; 145 146 memset(dst->dmac, 0, sizeof(dst->dmac)); 147 dst->net = TD_TO_VNET(curthread); 148 dst->ifindex = 0; 149 dst->gid_type = IB_GID_TYPE_IB; 150 } 151 EXPORT_SYMBOL(ib_copy_path_rec_from_user); 152