109938b21SHans Petter Selasky /*-
209938b21SHans Petter Selasky  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
309938b21SHans Petter Selasky  *
49f715dc1SHans Petter Selasky  * Copyright (c) 2005 Intel Corporation.  All rights reserved.
59f715dc1SHans Petter Selasky  *
69f715dc1SHans Petter Selasky  * This software is available to you under a choice of one of two
79f715dc1SHans Petter Selasky  * licenses.  You may choose to be licensed under the terms of the GNU
89f715dc1SHans Petter Selasky  * General Public License (GPL) Version 2, available from the file
99f715dc1SHans Petter Selasky  * COPYING in the main directory of this source tree, or the
109f715dc1SHans Petter Selasky  * OpenIB.org BSD license below:
119f715dc1SHans Petter Selasky  *
129f715dc1SHans Petter Selasky  *     Redistribution and use in source and binary forms, with or
139f715dc1SHans Petter Selasky  *     without modification, are permitted provided that the following
149f715dc1SHans Petter Selasky  *     conditions are met:
159f715dc1SHans Petter Selasky  *
169f715dc1SHans Petter Selasky  *      - Redistributions of source code must retain the above
179f715dc1SHans Petter Selasky  *        copyright notice, this list of conditions and the following
189f715dc1SHans Petter Selasky  *        disclaimer.
199f715dc1SHans Petter Selasky  *
209f715dc1SHans Petter Selasky  *      - Redistributions in binary form must reproduce the above
219f715dc1SHans Petter Selasky  *        copyright notice, this list of conditions and the following
229f715dc1SHans Petter Selasky  *        disclaimer in the documentation and/or other materials
239f715dc1SHans Petter Selasky  *        provided with the distribution.
249f715dc1SHans Petter Selasky  *
259f715dc1SHans Petter Selasky  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
269f715dc1SHans Petter Selasky  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
279f715dc1SHans Petter Selasky  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
289f715dc1SHans Petter Selasky  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
299f715dc1SHans Petter Selasky  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
309f715dc1SHans Petter Selasky  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
319f715dc1SHans Petter Selasky  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
329f715dc1SHans Petter Selasky  * SOFTWARE.
339f715dc1SHans Petter Selasky  */
349f715dc1SHans Petter Selasky 
35cda1e10cSHans Petter Selasky #include <sys/cdefs.h>
369f715dc1SHans Petter Selasky #include <rdma/ib_marshall.h>
379f715dc1SHans Petter Selasky 
ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr * dst,struct ib_ah_attr * src)389f715dc1SHans Petter Selasky void ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst,
399f715dc1SHans Petter Selasky 			     struct ib_ah_attr *src)
409f715dc1SHans Petter Selasky {
419f715dc1SHans Petter Selasky 	memcpy(dst->grh.dgid, src->grh.dgid.raw, sizeof src->grh.dgid);
429f715dc1SHans Petter Selasky 	dst->grh.flow_label        = src->grh.flow_label;
439f715dc1SHans Petter Selasky 	dst->grh.sgid_index        = src->grh.sgid_index;
449f715dc1SHans Petter Selasky 	dst->grh.hop_limit         = src->grh.hop_limit;
459f715dc1SHans Petter Selasky 	dst->grh.traffic_class     = src->grh.traffic_class;
469f715dc1SHans Petter Selasky 	memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
479f715dc1SHans Petter Selasky 	dst->dlid 	    	   = src->dlid;
489f715dc1SHans Petter Selasky 	dst->sl   	    	   = src->sl;
499f715dc1SHans Petter Selasky 	dst->src_path_bits 	   = src->src_path_bits;
509f715dc1SHans Petter Selasky 	dst->static_rate   	   = src->static_rate;
519f715dc1SHans Petter Selasky 	dst->is_global             = src->ah_flags & IB_AH_GRH ? 1 : 0;
529f715dc1SHans Petter Selasky 	dst->port_num 	    	   = src->port_num;
539f715dc1SHans Petter Selasky 	dst->reserved 		   = 0;
549f715dc1SHans Petter Selasky }
559f715dc1SHans Petter Selasky EXPORT_SYMBOL(ib_copy_ah_attr_to_user);
569f715dc1SHans Petter Selasky 
ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr * dst,struct ib_qp_attr * src)579f715dc1SHans Petter Selasky void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
589f715dc1SHans Petter Selasky 			     struct ib_qp_attr *src)
599f715dc1SHans Petter Selasky {
609f715dc1SHans Petter Selasky 	dst->qp_state	        = src->qp_state;
619f715dc1SHans Petter Selasky 	dst->cur_qp_state	= src->cur_qp_state;
629f715dc1SHans Petter Selasky 	dst->path_mtu		= src->path_mtu;
639f715dc1SHans Petter Selasky 	dst->path_mig_state	= src->path_mig_state;
649f715dc1SHans Petter Selasky 	dst->qkey		= src->qkey;
659f715dc1SHans Petter Selasky 	dst->rq_psn		= src->rq_psn;
669f715dc1SHans Petter Selasky 	dst->sq_psn		= src->sq_psn;
679f715dc1SHans Petter Selasky 	dst->dest_qp_num	= src->dest_qp_num;
689f715dc1SHans Petter Selasky 	dst->qp_access_flags	= src->qp_access_flags;
699f715dc1SHans Petter Selasky 
709f715dc1SHans Petter Selasky 	dst->max_send_wr	= src->cap.max_send_wr;
719f715dc1SHans Petter Selasky 	dst->max_recv_wr	= src->cap.max_recv_wr;
729f715dc1SHans Petter Selasky 	dst->max_send_sge	= src->cap.max_send_sge;
739f715dc1SHans Petter Selasky 	dst->max_recv_sge	= src->cap.max_recv_sge;
749f715dc1SHans Petter Selasky 	dst->max_inline_data	= src->cap.max_inline_data;
759f715dc1SHans Petter Selasky 
769f715dc1SHans Petter Selasky 	ib_copy_ah_attr_to_user(&dst->ah_attr, &src->ah_attr);
779f715dc1SHans Petter Selasky 	ib_copy_ah_attr_to_user(&dst->alt_ah_attr, &src->alt_ah_attr);
789f715dc1SHans Petter Selasky 
799f715dc1SHans Petter Selasky 	dst->pkey_index		= src->pkey_index;
809f715dc1SHans Petter Selasky 	dst->alt_pkey_index	= src->alt_pkey_index;
819f715dc1SHans Petter Selasky 	dst->en_sqd_async_notify = src->en_sqd_async_notify;
829f715dc1SHans Petter Selasky 	dst->sq_draining	= src->sq_draining;
839f715dc1SHans Petter Selasky 	dst->max_rd_atomic	= src->max_rd_atomic;
849f715dc1SHans Petter Selasky 	dst->max_dest_rd_atomic	= src->max_dest_rd_atomic;
859f715dc1SHans Petter Selasky 	dst->min_rnr_timer	= src->min_rnr_timer;
869f715dc1SHans Petter Selasky 	dst->port_num		= src->port_num;
879f715dc1SHans Petter Selasky 	dst->timeout		= src->timeout;
889f715dc1SHans Petter Selasky 	dst->retry_cnt		= src->retry_cnt;
899f715dc1SHans Petter Selasky 	dst->rnr_retry		= src->rnr_retry;
909f715dc1SHans Petter Selasky 	dst->alt_port_num	= src->alt_port_num;
919f715dc1SHans Petter Selasky 	dst->alt_timeout	= src->alt_timeout;
929f715dc1SHans Petter Selasky 	memset(dst->reserved, 0, sizeof(dst->reserved));
939f715dc1SHans Petter Selasky }
949f715dc1SHans Petter Selasky EXPORT_SYMBOL(ib_copy_qp_attr_to_user);
959f715dc1SHans Petter Selasky 
ib_copy_path_rec_to_user(struct ib_user_path_rec * dst,struct ib_sa_path_rec * src)969f715dc1SHans Petter Selasky void ib_copy_path_rec_to_user(struct ib_user_path_rec *dst,
979f715dc1SHans Petter Selasky 			      struct ib_sa_path_rec *src)
989f715dc1SHans Petter Selasky {
999f715dc1SHans Petter Selasky 	memcpy(dst->dgid, src->dgid.raw, sizeof src->dgid);
1009f715dc1SHans Petter Selasky 	memcpy(dst->sgid, src->sgid.raw, sizeof src->sgid);
1019f715dc1SHans Petter Selasky 
1029f715dc1SHans Petter Selasky 	dst->dlid		= src->dlid;
1039f715dc1SHans Petter Selasky 	dst->slid		= src->slid;
1049f715dc1SHans Petter Selasky 	dst->raw_traffic	= src->raw_traffic;
1059f715dc1SHans Petter Selasky 	dst->flow_label		= src->flow_label;
1069f715dc1SHans Petter Selasky 	dst->hop_limit		= src->hop_limit;
1079f715dc1SHans Petter Selasky 	dst->traffic_class	= src->traffic_class;
1089f715dc1SHans Petter Selasky 	dst->reversible		= src->reversible;
1099f715dc1SHans Petter Selasky 	dst->numb_path		= src->numb_path;
1109f715dc1SHans Petter Selasky 	dst->pkey		= src->pkey;
1119f715dc1SHans Petter Selasky 	dst->sl			= src->sl;
1129f715dc1SHans Petter Selasky 	dst->mtu_selector	= src->mtu_selector;
1139f715dc1SHans Petter Selasky 	dst->mtu		= src->mtu;
1149f715dc1SHans Petter Selasky 	dst->rate_selector	= src->rate_selector;
1159f715dc1SHans Petter Selasky 	dst->rate		= src->rate;
1169f715dc1SHans Petter Selasky 	dst->packet_life_time	= src->packet_life_time;
1179f715dc1SHans Petter Selasky 	dst->preference		= src->preference;
1189f715dc1SHans Petter Selasky 	dst->packet_life_time_selector = src->packet_life_time_selector;
1199f715dc1SHans Petter Selasky }
1209f715dc1SHans Petter Selasky EXPORT_SYMBOL(ib_copy_path_rec_to_user);
1219f715dc1SHans Petter Selasky 
ib_copy_path_rec_from_user(struct ib_sa_path_rec * dst,struct ib_user_path_rec * src)1229f715dc1SHans Petter Selasky void ib_copy_path_rec_from_user(struct ib_sa_path_rec *dst,
1239f715dc1SHans Petter Selasky 				struct ib_user_path_rec *src)
1249f715dc1SHans Petter Selasky {
1259f715dc1SHans Petter Selasky 	memcpy(dst->dgid.raw, src->dgid, sizeof dst->dgid);
1269f715dc1SHans Petter Selasky 	memcpy(dst->sgid.raw, src->sgid, sizeof dst->sgid);
1279f715dc1SHans Petter Selasky 
1289f715dc1SHans Petter Selasky 	dst->dlid		= src->dlid;
1299f715dc1SHans Petter Selasky 	dst->slid		= src->slid;
1309f715dc1SHans Petter Selasky 	dst->raw_traffic	= src->raw_traffic;
1319f715dc1SHans Petter Selasky 	dst->flow_label		= src->flow_label;
1329f715dc1SHans Petter Selasky 	dst->hop_limit		= src->hop_limit;
1339f715dc1SHans Petter Selasky 	dst->traffic_class	= src->traffic_class;
1349f715dc1SHans Petter Selasky 	dst->reversible		= src->reversible;
1359f715dc1SHans Petter Selasky 	dst->numb_path		= src->numb_path;
1369f715dc1SHans Petter Selasky 	dst->pkey		= src->pkey;
1379f715dc1SHans Petter Selasky 	dst->sl			= src->sl;
1389f715dc1SHans Petter Selasky 	dst->mtu_selector	= src->mtu_selector;
1399f715dc1SHans Petter Selasky 	dst->mtu		= src->mtu;
1409f715dc1SHans Petter Selasky 	dst->rate_selector	= src->rate_selector;
1419f715dc1SHans Petter Selasky 	dst->rate		= src->rate;
1429f715dc1SHans Petter Selasky 	dst->packet_life_time	= src->packet_life_time;
1439f715dc1SHans Petter Selasky 	dst->preference		= src->preference;
1449f715dc1SHans Petter Selasky 	dst->packet_life_time_selector = src->packet_life_time_selector;
1459f715dc1SHans Petter Selasky 
1469f715dc1SHans Petter Selasky 	memset(dst->dmac, 0, sizeof(dst->dmac));
1477877f593SHans Petter Selasky 	dst->net = TD_TO_VNET(curthread);
1489f715dc1SHans Petter Selasky 	dst->ifindex = 0;
1499f715dc1SHans Petter Selasky 	dst->gid_type = IB_GID_TYPE_IB;
1509f715dc1SHans Petter Selasky }
1519f715dc1SHans Petter Selasky EXPORT_SYMBOL(ib_copy_path_rec_from_user);
152