1331772Shselasky/*-
2331772Shselasky * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3331772Shselasky *
4320592Shselasky * Copyright (c) 2005 Intel Corporation.  All rights reserved.
5320592Shselasky *
6320592Shselasky * This software is available to you under a choice of one of two
7320592Shselasky * licenses.  You may choose to be licensed under the terms of the GNU
8320592Shselasky * General Public License (GPL) Version 2, available from the file
9320592Shselasky * COPYING in the main directory of this source tree, or the
10320592Shselasky * OpenIB.org BSD license below:
11320592Shselasky *
12320592Shselasky *     Redistribution and use in source and binary forms, with or
13320592Shselasky *     without modification, are permitted provided that the following
14320592Shselasky *     conditions are met:
15320592Shselasky *
16320592Shselasky *      - Redistributions of source code must retain the above
17320592Shselasky *        copyright notice, this list of conditions and the following
18320592Shselasky *        disclaimer.
19320592Shselasky *
20320592Shselasky *      - Redistributions in binary form must reproduce the above
21320592Shselasky *        copyright notice, this list of conditions and the following
22320592Shselasky *        disclaimer in the documentation and/or other materials
23320592Shselasky *        provided with the distribution.
24320592Shselasky *
25320592Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26320592Shselasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27320592Shselasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28320592Shselasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29320592Shselasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30320592Shselasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31320592Shselasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32320592Shselasky * SOFTWARE.
33320592Shselasky */
34320592Shselasky
35337096Shselasky#include <sys/cdefs.h>
36337096Shselasky__FBSDID("$FreeBSD: stable/11/sys/ofed/drivers/infiniband/core/ib_uverbs_marshall.c 338557 2018-09-10 08:19:38Z hselasky $");
37337096Shselasky
38320592Shselasky#include <rdma/ib_marshall.h>
39320592Shselasky
40320592Shselaskyvoid ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst,
41320592Shselasky			     struct ib_ah_attr *src)
42320592Shselasky{
43320592Shselasky	memcpy(dst->grh.dgid, src->grh.dgid.raw, sizeof src->grh.dgid);
44320592Shselasky	dst->grh.flow_label        = src->grh.flow_label;
45320592Shselasky	dst->grh.sgid_index        = src->grh.sgid_index;
46320592Shselasky	dst->grh.hop_limit         = src->grh.hop_limit;
47320592Shselasky	dst->grh.traffic_class     = src->grh.traffic_class;
48320592Shselasky	memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
49320592Shselasky	dst->dlid 	    	   = src->dlid;
50320592Shselasky	dst->sl   	    	   = src->sl;
51320592Shselasky	dst->src_path_bits 	   = src->src_path_bits;
52320592Shselasky	dst->static_rate   	   = src->static_rate;
53320592Shselasky	dst->is_global             = src->ah_flags & IB_AH_GRH ? 1 : 0;
54320592Shselasky	dst->port_num 	    	   = src->port_num;
55320592Shselasky	dst->reserved 		   = 0;
56320592Shselasky}
57320592ShselaskyEXPORT_SYMBOL(ib_copy_ah_attr_to_user);
58320592Shselasky
59320592Shselaskyvoid ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
60320592Shselasky			     struct ib_qp_attr *src)
61320592Shselasky{
62320592Shselasky	dst->qp_state	        = src->qp_state;
63320592Shselasky	dst->cur_qp_state	= src->cur_qp_state;
64320592Shselasky	dst->path_mtu		= src->path_mtu;
65320592Shselasky	dst->path_mig_state	= src->path_mig_state;
66320592Shselasky	dst->qkey		= src->qkey;
67320592Shselasky	dst->rq_psn		= src->rq_psn;
68320592Shselasky	dst->sq_psn		= src->sq_psn;
69320592Shselasky	dst->dest_qp_num	= src->dest_qp_num;
70320592Shselasky	dst->qp_access_flags	= src->qp_access_flags;
71320592Shselasky
72320592Shselasky	dst->max_send_wr	= src->cap.max_send_wr;
73320592Shselasky	dst->max_recv_wr	= src->cap.max_recv_wr;
74320592Shselasky	dst->max_send_sge	= src->cap.max_send_sge;
75320592Shselasky	dst->max_recv_sge	= src->cap.max_recv_sge;
76320592Shselasky	dst->max_inline_data	= src->cap.max_inline_data;
77320592Shselasky
78320592Shselasky	ib_copy_ah_attr_to_user(&dst->ah_attr, &src->ah_attr);
79320592Shselasky	ib_copy_ah_attr_to_user(&dst->alt_ah_attr, &src->alt_ah_attr);
80320592Shselasky
81320592Shselasky	dst->pkey_index		= src->pkey_index;
82320592Shselasky	dst->alt_pkey_index	= src->alt_pkey_index;
83320592Shselasky	dst->en_sqd_async_notify = src->en_sqd_async_notify;
84320592Shselasky	dst->sq_draining	= src->sq_draining;
85320592Shselasky	dst->max_rd_atomic	= src->max_rd_atomic;
86320592Shselasky	dst->max_dest_rd_atomic	= src->max_dest_rd_atomic;
87320592Shselasky	dst->min_rnr_timer	= src->min_rnr_timer;
88320592Shselasky	dst->port_num		= src->port_num;
89320592Shselasky	dst->timeout		= src->timeout;
90320592Shselasky	dst->retry_cnt		= src->retry_cnt;
91320592Shselasky	dst->rnr_retry		= src->rnr_retry;
92320592Shselasky	dst->alt_port_num	= src->alt_port_num;
93320592Shselasky	dst->alt_timeout	= src->alt_timeout;
94320592Shselasky	memset(dst->reserved, 0, sizeof(dst->reserved));
95320592Shselasky}
96320592ShselaskyEXPORT_SYMBOL(ib_copy_qp_attr_to_user);
97320592Shselasky
98320592Shselaskyvoid ib_copy_path_rec_to_user(struct ib_user_path_rec *dst,
99320592Shselasky			      struct ib_sa_path_rec *src)
100320592Shselasky{
101320592Shselasky	memcpy(dst->dgid, src->dgid.raw, sizeof src->dgid);
102320592Shselasky	memcpy(dst->sgid, src->sgid.raw, sizeof src->sgid);
103320592Shselasky
104320592Shselasky	dst->dlid		= src->dlid;
105320592Shselasky	dst->slid		= src->slid;
106320592Shselasky	dst->raw_traffic	= src->raw_traffic;
107320592Shselasky	dst->flow_label		= src->flow_label;
108320592Shselasky	dst->hop_limit		= src->hop_limit;
109320592Shselasky	dst->traffic_class	= src->traffic_class;
110320592Shselasky	dst->reversible		= src->reversible;
111320592Shselasky	dst->numb_path		= src->numb_path;
112320592Shselasky	dst->pkey		= src->pkey;
113320592Shselasky	dst->sl			= src->sl;
114320592Shselasky	dst->mtu_selector	= src->mtu_selector;
115320592Shselasky	dst->mtu		= src->mtu;
116320592Shselasky	dst->rate_selector	= src->rate_selector;
117320592Shselasky	dst->rate		= src->rate;
118320592Shselasky	dst->packet_life_time	= src->packet_life_time;
119320592Shselasky	dst->preference		= src->preference;
120320592Shselasky	dst->packet_life_time_selector = src->packet_life_time_selector;
121320592Shselasky}
122320592ShselaskyEXPORT_SYMBOL(ib_copy_path_rec_to_user);
123320592Shselasky
124320592Shselaskyvoid ib_copy_path_rec_from_user(struct ib_sa_path_rec *dst,
125320592Shselasky				struct ib_user_path_rec *src)
126320592Shselasky{
127320592Shselasky	memcpy(dst->dgid.raw, src->dgid, sizeof dst->dgid);
128320592Shselasky	memcpy(dst->sgid.raw, src->sgid, sizeof dst->sgid);
129320592Shselasky
130320592Shselasky	dst->dlid		= src->dlid;
131320592Shselasky	dst->slid		= src->slid;
132320592Shselasky	dst->raw_traffic	= src->raw_traffic;
133320592Shselasky	dst->flow_label		= src->flow_label;
134320592Shselasky	dst->hop_limit		= src->hop_limit;
135320592Shselasky	dst->traffic_class	= src->traffic_class;
136320592Shselasky	dst->reversible		= src->reversible;
137320592Shselasky	dst->numb_path		= src->numb_path;
138320592Shselasky	dst->pkey		= src->pkey;
139320592Shselasky	dst->sl			= src->sl;
140320592Shselasky	dst->mtu_selector	= src->mtu_selector;
141320592Shselasky	dst->mtu		= src->mtu;
142320592Shselasky	dst->rate_selector	= src->rate_selector;
143320592Shselasky	dst->rate		= src->rate;
144320592Shselasky	dst->packet_life_time	= src->packet_life_time;
145320592Shselasky	dst->preference		= src->preference;
146320592Shselasky	dst->packet_life_time_selector = src->packet_life_time_selector;
147320592Shselasky
148320592Shselasky	memset(dst->dmac, 0, sizeof(dst->dmac));
149338557Shselasky	dst->net = TD_TO_VNET(curthread);
150320592Shselasky	dst->ifindex = 0;
151320592Shselasky	dst->gid_type = IB_GID_TYPE_IB;
152320592Shselasky}
153320592ShselaskyEXPORT_SYMBOL(ib_copy_path_rec_from_user);
154