xref: /linux/drivers/infiniband/ulp/opa_vnic/opa_vnic_vema_iface.c (revision cdd38c5f1ce4398ec58fec95904b75824daab7b5)
1cfd34f8eSVishwanathapura, Niranjana /*
2cfd34f8eSVishwanathapura, Niranjana  * Copyright(c) 2017 Intel Corporation.
3cfd34f8eSVishwanathapura, Niranjana  *
4cfd34f8eSVishwanathapura, Niranjana  * This file is provided under a dual BSD/GPLv2 license.  When using or
5cfd34f8eSVishwanathapura, Niranjana  * redistributing this file, you may do so under either license.
6cfd34f8eSVishwanathapura, Niranjana  *
7cfd34f8eSVishwanathapura, Niranjana  * GPL LICENSE SUMMARY
8cfd34f8eSVishwanathapura, Niranjana  *
9cfd34f8eSVishwanathapura, Niranjana  * This program is free software; you can redistribute it and/or modify
10cfd34f8eSVishwanathapura, Niranjana  * it under the terms of version 2 of the GNU General Public License as
11cfd34f8eSVishwanathapura, Niranjana  * published by the Free Software Foundation.
12cfd34f8eSVishwanathapura, Niranjana  *
13cfd34f8eSVishwanathapura, Niranjana  * This program is distributed in the hope that it will be useful, but
14cfd34f8eSVishwanathapura, Niranjana  * WITHOUT ANY WARRANTY; without even the implied warranty of
15cfd34f8eSVishwanathapura, Niranjana  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16cfd34f8eSVishwanathapura, Niranjana  * General Public License for more details.
17cfd34f8eSVishwanathapura, Niranjana  *
18cfd34f8eSVishwanathapura, Niranjana  * BSD LICENSE
19cfd34f8eSVishwanathapura, Niranjana  *
20cfd34f8eSVishwanathapura, Niranjana  * Redistribution and use in source and binary forms, with or without
21cfd34f8eSVishwanathapura, Niranjana  * modification, are permitted provided that the following conditions
22cfd34f8eSVishwanathapura, Niranjana  * are met:
23cfd34f8eSVishwanathapura, Niranjana  *
24cfd34f8eSVishwanathapura, Niranjana  *  - Redistributions of source code must retain the above copyright
25cfd34f8eSVishwanathapura, Niranjana  *    notice, this list of conditions and the following disclaimer.
26cfd34f8eSVishwanathapura, Niranjana  *  - Redistributions in binary form must reproduce the above copyright
27cfd34f8eSVishwanathapura, Niranjana  *    notice, this list of conditions and the following disclaimer in
28cfd34f8eSVishwanathapura, Niranjana  *    the documentation and/or other materials provided with the
29cfd34f8eSVishwanathapura, Niranjana  *    distribution.
30cfd34f8eSVishwanathapura, Niranjana  *  - Neither the name of Intel Corporation nor the names of its
31cfd34f8eSVishwanathapura, Niranjana  *    contributors may be used to endorse or promote products derived
32cfd34f8eSVishwanathapura, Niranjana  *    from this software without specific prior written permission.
33cfd34f8eSVishwanathapura, Niranjana  *
34cfd34f8eSVishwanathapura, Niranjana  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35cfd34f8eSVishwanathapura, Niranjana  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36cfd34f8eSVishwanathapura, Niranjana  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37cfd34f8eSVishwanathapura, Niranjana  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38cfd34f8eSVishwanathapura, Niranjana  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39cfd34f8eSVishwanathapura, Niranjana  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40cfd34f8eSVishwanathapura, Niranjana  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41cfd34f8eSVishwanathapura, Niranjana  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42cfd34f8eSVishwanathapura, Niranjana  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43cfd34f8eSVishwanathapura, Niranjana  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44cfd34f8eSVishwanathapura, Niranjana  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45cfd34f8eSVishwanathapura, Niranjana  *
46cfd34f8eSVishwanathapura, Niranjana  */
47cfd34f8eSVishwanathapura, Niranjana 
48cfd34f8eSVishwanathapura, Niranjana /*
49cfd34f8eSVishwanathapura, Niranjana  * This file contains OPA VNIC EMA Interface functions.
50cfd34f8eSVishwanathapura, Niranjana  */
51cfd34f8eSVishwanathapura, Niranjana 
52cfd34f8eSVishwanathapura, Niranjana #include "opa_vnic_internal.h"
53cfd34f8eSVishwanathapura, Niranjana 
54cfd34f8eSVishwanathapura, Niranjana /**
55cfd34f8eSVishwanathapura, Niranjana  * opa_vnic_vema_report_event - sent trap to report the specified event
56cfd34f8eSVishwanathapura, Niranjana  * @adapter: vnic port adapter
57cfd34f8eSVishwanathapura, Niranjana  * @event: event to be reported
58cfd34f8eSVishwanathapura, Niranjana  *
59cfd34f8eSVishwanathapura, Niranjana  * This function calls vema api to sent a trap for the given event.
60cfd34f8eSVishwanathapura, Niranjana  */
opa_vnic_vema_report_event(struct opa_vnic_adapter * adapter,u8 event)61cfd34f8eSVishwanathapura, Niranjana void opa_vnic_vema_report_event(struct opa_vnic_adapter *adapter, u8 event)
62cfd34f8eSVishwanathapura, Niranjana {
63cfd34f8eSVishwanathapura, Niranjana 	struct __opa_veswport_info *info = &adapter->info;
64cfd34f8eSVishwanathapura, Niranjana 	struct __opa_veswport_trap trap_data;
65cfd34f8eSVishwanathapura, Niranjana 
66cfd34f8eSVishwanathapura, Niranjana 	trap_data.fabric_id = info->vesw.fabric_id;
67cfd34f8eSVishwanathapura, Niranjana 	trap_data.veswid = info->vesw.vesw_id;
68cfd34f8eSVishwanathapura, Niranjana 	trap_data.veswportnum = info->vport.port_num;
69cfd34f8eSVishwanathapura, Niranjana 	trap_data.opaportnum = adapter->port_num;
70cfd34f8eSVishwanathapura, Niranjana 	trap_data.veswportindex = adapter->vport_num;
71cfd34f8eSVishwanathapura, Niranjana 	trap_data.opcode = event;
72cfd34f8eSVishwanathapura, Niranjana 
731bd671abSVishwanathapura, Niranjana 	opa_vnic_vema_send_trap(adapter, &trap_data, info->vport.encap_slid);
74cfd34f8eSVishwanathapura, Niranjana }
75cfd34f8eSVishwanathapura, Niranjana 
76cfd34f8eSVishwanathapura, Niranjana /**
77*2988ca08SMauro Carvalho Chehab  * opa_vnic_get_summary_counters - get summary counters
78cfd34f8eSVishwanathapura, Niranjana  * @adapter: vnic port adapter
79cfd34f8eSVishwanathapura, Niranjana  * @cntrs: pointer to destination summary counters structure
80cfd34f8eSVishwanathapura, Niranjana  *
81cfd34f8eSVishwanathapura, Niranjana  * This function populates the summary counters that is maintained by the
82cfd34f8eSVishwanathapura, Niranjana  * given adapter to destination address provided.
83cfd34f8eSVishwanathapura, Niranjana  */
opa_vnic_get_summary_counters(struct opa_vnic_adapter * adapter,struct opa_veswport_summary_counters * cntrs)84cfd34f8eSVishwanathapura, Niranjana void opa_vnic_get_summary_counters(struct opa_vnic_adapter *adapter,
85cfd34f8eSVishwanathapura, Niranjana 				   struct opa_veswport_summary_counters *cntrs)
86cfd34f8eSVishwanathapura, Niranjana {
87cfd34f8eSVishwanathapura, Niranjana 	struct opa_vnic_stats vstats;
88cfd34f8eSVishwanathapura, Niranjana 	__be64 *dst;
89cfd34f8eSVishwanathapura, Niranjana 	u64 *src;
90cfd34f8eSVishwanathapura, Niranjana 
91cfd34f8eSVishwanathapura, Niranjana 	memset(&vstats, 0, sizeof(vstats));
92a379d69fSVishwanathapura, Niranjana 	spin_lock(&adapter->stats_lock);
93cfd34f8eSVishwanathapura, Niranjana 	adapter->rn_ops->ndo_get_stats64(adapter->netdev, &vstats.netstats);
94a379d69fSVishwanathapura, Niranjana 	spin_unlock(&adapter->stats_lock);
95cfd34f8eSVishwanathapura, Niranjana 
96cfd34f8eSVishwanathapura, Niranjana 	cntrs->vp_instance = cpu_to_be16(adapter->vport_num);
97cfd34f8eSVishwanathapura, Niranjana 	cntrs->vesw_id = cpu_to_be16(adapter->info.vesw.vesw_id);
98cfd34f8eSVishwanathapura, Niranjana 	cntrs->veswport_num = cpu_to_be32(adapter->port_num);
99cfd34f8eSVishwanathapura, Niranjana 
100cfd34f8eSVishwanathapura, Niranjana 	cntrs->tx_errors = cpu_to_be64(vstats.netstats.tx_errors);
101cfd34f8eSVishwanathapura, Niranjana 	cntrs->rx_errors = cpu_to_be64(vstats.netstats.rx_errors);
102cfd34f8eSVishwanathapura, Niranjana 	cntrs->tx_packets = cpu_to_be64(vstats.netstats.tx_packets);
103cfd34f8eSVishwanathapura, Niranjana 	cntrs->rx_packets = cpu_to_be64(vstats.netstats.rx_packets);
104cfd34f8eSVishwanathapura, Niranjana 	cntrs->tx_bytes = cpu_to_be64(vstats.netstats.tx_bytes);
105cfd34f8eSVishwanathapura, Niranjana 	cntrs->rx_bytes = cpu_to_be64(vstats.netstats.rx_bytes);
106cfd34f8eSVishwanathapura, Niranjana 
107cfd34f8eSVishwanathapura, Niranjana 	/*
108cfd34f8eSVishwanathapura, Niranjana 	 * This loop depends on layout of
109cfd34f8eSVishwanathapura, Niranjana 	 * opa_veswport_summary_counters opa_vnic_stats structures.
110cfd34f8eSVishwanathapura, Niranjana 	 */
111cfd34f8eSVishwanathapura, Niranjana 	for (dst = &cntrs->tx_unicast, src = &vstats.tx_grp.unicast;
112cfd34f8eSVishwanathapura, Niranjana 	     dst < &cntrs->reserved[0]; dst++, src++) {
113cfd34f8eSVishwanathapura, Niranjana 		*dst = cpu_to_be64(*src);
114cfd34f8eSVishwanathapura, Niranjana 	}
115cfd34f8eSVishwanathapura, Niranjana }
116cfd34f8eSVishwanathapura, Niranjana 
117cfd34f8eSVishwanathapura, Niranjana /**
118cfd34f8eSVishwanathapura, Niranjana  * opa_vnic_get_error_counters - get error counters
119cfd34f8eSVishwanathapura, Niranjana  * @adapter: vnic port adapter
120cfd34f8eSVishwanathapura, Niranjana  * @cntrs: pointer to destination error counters structure
121cfd34f8eSVishwanathapura, Niranjana  *
122cfd34f8eSVishwanathapura, Niranjana  * This function populates the error counters that is maintained by the
123cfd34f8eSVishwanathapura, Niranjana  * given adapter to destination address provided.
124cfd34f8eSVishwanathapura, Niranjana  */
opa_vnic_get_error_counters(struct opa_vnic_adapter * adapter,struct opa_veswport_error_counters * cntrs)125cfd34f8eSVishwanathapura, Niranjana void opa_vnic_get_error_counters(struct opa_vnic_adapter *adapter,
126cfd34f8eSVishwanathapura, Niranjana 				 struct opa_veswport_error_counters *cntrs)
127cfd34f8eSVishwanathapura, Niranjana {
128cfd34f8eSVishwanathapura, Niranjana 	struct opa_vnic_stats vstats;
129cfd34f8eSVishwanathapura, Niranjana 
130cfd34f8eSVishwanathapura, Niranjana 	memset(&vstats, 0, sizeof(vstats));
131a379d69fSVishwanathapura, Niranjana 	spin_lock(&adapter->stats_lock);
132cfd34f8eSVishwanathapura, Niranjana 	adapter->rn_ops->ndo_get_stats64(adapter->netdev, &vstats.netstats);
133a379d69fSVishwanathapura, Niranjana 	spin_unlock(&adapter->stats_lock);
134cfd34f8eSVishwanathapura, Niranjana 
135cfd34f8eSVishwanathapura, Niranjana 	cntrs->vp_instance = cpu_to_be16(adapter->vport_num);
136cfd34f8eSVishwanathapura, Niranjana 	cntrs->vesw_id = cpu_to_be16(adapter->info.vesw.vesw_id);
137cfd34f8eSVishwanathapura, Niranjana 	cntrs->veswport_num = cpu_to_be32(adapter->port_num);
138cfd34f8eSVishwanathapura, Niranjana 
139cfd34f8eSVishwanathapura, Niranjana 	cntrs->tx_errors = cpu_to_be64(vstats.netstats.tx_errors);
140cfd34f8eSVishwanathapura, Niranjana 	cntrs->rx_errors = cpu_to_be64(vstats.netstats.rx_errors);
141cfd34f8eSVishwanathapura, Niranjana 	cntrs->tx_dlid_zero = cpu_to_be64(vstats.tx_dlid_zero);
142cfd34f8eSVishwanathapura, Niranjana 	cntrs->tx_drop_state = cpu_to_be64(vstats.tx_drop_state);
143cfd34f8eSVishwanathapura, Niranjana 	cntrs->tx_logic = cpu_to_be64(vstats.netstats.tx_fifo_errors +
144cfd34f8eSVishwanathapura, Niranjana 				      vstats.netstats.tx_carrier_errors);
145cfd34f8eSVishwanathapura, Niranjana 
146cfd34f8eSVishwanathapura, Niranjana 	cntrs->rx_bad_veswid = cpu_to_be64(vstats.netstats.rx_nohandler);
147cfd34f8eSVishwanathapura, Niranjana 	cntrs->rx_runt = cpu_to_be64(vstats.rx_runt);
148cfd34f8eSVishwanathapura, Niranjana 	cntrs->rx_oversize = cpu_to_be64(vstats.rx_oversize);
149cfd34f8eSVishwanathapura, Niranjana 	cntrs->rx_drop_state = cpu_to_be64(vstats.rx_drop_state);
150cfd34f8eSVishwanathapura, Niranjana 	cntrs->rx_logic = cpu_to_be64(vstats.netstats.rx_fifo_errors);
151cfd34f8eSVishwanathapura, Niranjana }
152cfd34f8eSVishwanathapura, Niranjana 
153cfd34f8eSVishwanathapura, Niranjana /**
154cfd34f8eSVishwanathapura, Niranjana  * opa_vnic_get_vesw_info -- Get the vesw information
155cfd34f8eSVishwanathapura, Niranjana  * @adapter: vnic port adapter
156cfd34f8eSVishwanathapura, Niranjana  * @info: pointer to destination vesw info structure
157cfd34f8eSVishwanathapura, Niranjana  *
158cfd34f8eSVishwanathapura, Niranjana  * This function copies the vesw info that is maintained by the
159cfd34f8eSVishwanathapura, Niranjana  * given adapter to destination address provided.
160cfd34f8eSVishwanathapura, Niranjana  */
opa_vnic_get_vesw_info(struct opa_vnic_adapter * adapter,struct opa_vesw_info * info)161cfd34f8eSVishwanathapura, Niranjana void opa_vnic_get_vesw_info(struct opa_vnic_adapter *adapter,
162cfd34f8eSVishwanathapura, Niranjana 			    struct opa_vesw_info *info)
163cfd34f8eSVishwanathapura, Niranjana {
164cfd34f8eSVishwanathapura, Niranjana 	struct __opa_vesw_info *src = &adapter->info.vesw;
165cfd34f8eSVishwanathapura, Niranjana 	int i;
166cfd34f8eSVishwanathapura, Niranjana 
167cfd34f8eSVishwanathapura, Niranjana 	info->fabric_id = cpu_to_be16(src->fabric_id);
168cfd34f8eSVishwanathapura, Niranjana 	info->vesw_id = cpu_to_be16(src->vesw_id);
169cfd34f8eSVishwanathapura, Niranjana 	memcpy(info->rsvd0, src->rsvd0, ARRAY_SIZE(src->rsvd0));
170cfd34f8eSVishwanathapura, Niranjana 	info->def_port_mask = cpu_to_be16(src->def_port_mask);
171cfd34f8eSVishwanathapura, Niranjana 	memcpy(info->rsvd1, src->rsvd1, ARRAY_SIZE(src->rsvd1));
172cfd34f8eSVishwanathapura, Niranjana 	info->pkey = cpu_to_be16(src->pkey);
173cfd34f8eSVishwanathapura, Niranjana 
174cfd34f8eSVishwanathapura, Niranjana 	memcpy(info->rsvd2, src->rsvd2, ARRAY_SIZE(src->rsvd2));
175cfd34f8eSVishwanathapura, Niranjana 	info->u_mcast_dlid = cpu_to_be32(src->u_mcast_dlid);
176cfd34f8eSVishwanathapura, Niranjana 	for (i = 0; i < OPA_VESW_MAX_NUM_DEF_PORT; i++)
177cfd34f8eSVishwanathapura, Niranjana 		info->u_ucast_dlid[i] = cpu_to_be32(src->u_ucast_dlid[i]);
178cfd34f8eSVishwanathapura, Niranjana 
179b209a368SNiranjana Vishwanathapura 	info->rc = cpu_to_be32(src->rc);
180b209a368SNiranjana Vishwanathapura 
181cfd34f8eSVishwanathapura, Niranjana 	memcpy(info->rsvd3, src->rsvd3, ARRAY_SIZE(src->rsvd3));
18262f1e84eSNiranjana Vishwanathapura 	info->eth_mtu = cpu_to_be16(src->eth_mtu);
183cfd34f8eSVishwanathapura, Niranjana 	memcpy(info->rsvd4, src->rsvd4, ARRAY_SIZE(src->rsvd4));
184cfd34f8eSVishwanathapura, Niranjana }
185cfd34f8eSVishwanathapura, Niranjana 
186cfd34f8eSVishwanathapura, Niranjana /**
187cfd34f8eSVishwanathapura, Niranjana  * opa_vnic_set_vesw_info -- Set the vesw information
188cfd34f8eSVishwanathapura, Niranjana  * @adapter: vnic port adapter
189cfd34f8eSVishwanathapura, Niranjana  * @info: pointer to vesw info structure
190cfd34f8eSVishwanathapura, Niranjana  *
191cfd34f8eSVishwanathapura, Niranjana  * This function updates the vesw info that is maintained by the
192cfd34f8eSVishwanathapura, Niranjana  * given adapter with vesw info provided. Reserved fields are stored
193cfd34f8eSVishwanathapura, Niranjana  * and returned back to EM as is.
194cfd34f8eSVishwanathapura, Niranjana  */
opa_vnic_set_vesw_info(struct opa_vnic_adapter * adapter,struct opa_vesw_info * info)195cfd34f8eSVishwanathapura, Niranjana void opa_vnic_set_vesw_info(struct opa_vnic_adapter *adapter,
196cfd34f8eSVishwanathapura, Niranjana 			    struct opa_vesw_info *info)
197cfd34f8eSVishwanathapura, Niranjana {
198cfd34f8eSVishwanathapura, Niranjana 	struct __opa_vesw_info *dst = &adapter->info.vesw;
199cfd34f8eSVishwanathapura, Niranjana 	int i;
200cfd34f8eSVishwanathapura, Niranjana 
201cfd34f8eSVishwanathapura, Niranjana 	dst->fabric_id = be16_to_cpu(info->fabric_id);
202cfd34f8eSVishwanathapura, Niranjana 	dst->vesw_id = be16_to_cpu(info->vesw_id);
203cfd34f8eSVishwanathapura, Niranjana 	memcpy(dst->rsvd0, info->rsvd0, ARRAY_SIZE(info->rsvd0));
204cfd34f8eSVishwanathapura, Niranjana 	dst->def_port_mask = be16_to_cpu(info->def_port_mask);
205cfd34f8eSVishwanathapura, Niranjana 	memcpy(dst->rsvd1, info->rsvd1, ARRAY_SIZE(info->rsvd1));
206cfd34f8eSVishwanathapura, Niranjana 	dst->pkey = be16_to_cpu(info->pkey);
207cfd34f8eSVishwanathapura, Niranjana 
208cfd34f8eSVishwanathapura, Niranjana 	memcpy(dst->rsvd2, info->rsvd2, ARRAY_SIZE(info->rsvd2));
209cfd34f8eSVishwanathapura, Niranjana 	dst->u_mcast_dlid = be32_to_cpu(info->u_mcast_dlid);
210cfd34f8eSVishwanathapura, Niranjana 	for (i = 0; i < OPA_VESW_MAX_NUM_DEF_PORT; i++)
211cfd34f8eSVishwanathapura, Niranjana 		dst->u_ucast_dlid[i] = be32_to_cpu(info->u_ucast_dlid[i]);
212cfd34f8eSVishwanathapura, Niranjana 
213b209a368SNiranjana Vishwanathapura 	dst->rc = be32_to_cpu(info->rc);
214b209a368SNiranjana Vishwanathapura 
215cfd34f8eSVishwanathapura, Niranjana 	memcpy(dst->rsvd3, info->rsvd3, ARRAY_SIZE(info->rsvd3));
21662f1e84eSNiranjana Vishwanathapura 	dst->eth_mtu = be16_to_cpu(info->eth_mtu);
217cfd34f8eSVishwanathapura, Niranjana 	memcpy(dst->rsvd4, info->rsvd4, ARRAY_SIZE(info->rsvd4));
218cfd34f8eSVishwanathapura, Niranjana }
219cfd34f8eSVishwanathapura, Niranjana 
220cfd34f8eSVishwanathapura, Niranjana /**
221cfd34f8eSVishwanathapura, Niranjana  * opa_vnic_get_per_veswport_info -- Get the vesw per port information
222cfd34f8eSVishwanathapura, Niranjana  * @adapter: vnic port adapter
223cfd34f8eSVishwanathapura, Niranjana  * @info: pointer to destination vport info structure
224cfd34f8eSVishwanathapura, Niranjana  *
225cfd34f8eSVishwanathapura, Niranjana  * This function copies the vesw per port info that is maintained by the
226cfd34f8eSVishwanathapura, Niranjana  * given adapter to destination address provided.
227cfd34f8eSVishwanathapura, Niranjana  * Note that the read only fields are not copied.
228cfd34f8eSVishwanathapura, Niranjana  */
opa_vnic_get_per_veswport_info(struct opa_vnic_adapter * adapter,struct opa_per_veswport_info * info)229cfd34f8eSVishwanathapura, Niranjana void opa_vnic_get_per_veswport_info(struct opa_vnic_adapter *adapter,
230cfd34f8eSVishwanathapura, Niranjana 				    struct opa_per_veswport_info *info)
231cfd34f8eSVishwanathapura, Niranjana {
232cfd34f8eSVishwanathapura, Niranjana 	struct __opa_per_veswport_info *src = &adapter->info.vport;
233cfd34f8eSVishwanathapura, Niranjana 
234cfd34f8eSVishwanathapura, Niranjana 	info->port_num = cpu_to_be32(src->port_num);
235cfd34f8eSVishwanathapura, Niranjana 	info->eth_link_status = src->eth_link_status;
236cfd34f8eSVishwanathapura, Niranjana 	memcpy(info->rsvd0, src->rsvd0, ARRAY_SIZE(src->rsvd0));
237cfd34f8eSVishwanathapura, Niranjana 
238cfd34f8eSVishwanathapura, Niranjana 	memcpy(info->base_mac_addr, src->base_mac_addr,
239cfd34f8eSVishwanathapura, Niranjana 	       ARRAY_SIZE(info->base_mac_addr));
240cfd34f8eSVishwanathapura, Niranjana 	info->config_state = src->config_state;
241cfd34f8eSVishwanathapura, Niranjana 	info->oper_state = src->oper_state;
242cfd34f8eSVishwanathapura, Niranjana 	info->max_mac_tbl_ent = cpu_to_be16(src->max_mac_tbl_ent);
243cfd34f8eSVishwanathapura, Niranjana 	info->max_smac_ent = cpu_to_be16(src->max_smac_ent);
244cfd34f8eSVishwanathapura, Niranjana 	info->mac_tbl_digest = cpu_to_be32(src->mac_tbl_digest);
245cfd34f8eSVishwanathapura, Niranjana 	memcpy(info->rsvd1, src->rsvd1, ARRAY_SIZE(src->rsvd1));
246cfd34f8eSVishwanathapura, Niranjana 
247cfd34f8eSVishwanathapura, Niranjana 	info->encap_slid = cpu_to_be32(src->encap_slid);
248cfd34f8eSVishwanathapura, Niranjana 	memcpy(info->pcp_to_sc_uc, src->pcp_to_sc_uc,
249cfd34f8eSVishwanathapura, Niranjana 	       ARRAY_SIZE(info->pcp_to_sc_uc));
250cfd34f8eSVishwanathapura, Niranjana 	memcpy(info->pcp_to_vl_uc, src->pcp_to_vl_uc,
251cfd34f8eSVishwanathapura, Niranjana 	       ARRAY_SIZE(info->pcp_to_vl_uc));
252cfd34f8eSVishwanathapura, Niranjana 	memcpy(info->pcp_to_sc_mc, src->pcp_to_sc_mc,
253cfd34f8eSVishwanathapura, Niranjana 	       ARRAY_SIZE(info->pcp_to_sc_mc));
254cfd34f8eSVishwanathapura, Niranjana 	memcpy(info->pcp_to_vl_mc, src->pcp_to_vl_mc,
255cfd34f8eSVishwanathapura, Niranjana 	       ARRAY_SIZE(info->pcp_to_vl_mc));
256cfd34f8eSVishwanathapura, Niranjana 	info->non_vlan_sc_uc = src->non_vlan_sc_uc;
257cfd34f8eSVishwanathapura, Niranjana 	info->non_vlan_vl_uc = src->non_vlan_vl_uc;
258cfd34f8eSVishwanathapura, Niranjana 	info->non_vlan_sc_mc = src->non_vlan_sc_mc;
259cfd34f8eSVishwanathapura, Niranjana 	info->non_vlan_vl_mc = src->non_vlan_vl_mc;
260cfd34f8eSVishwanathapura, Niranjana 	memcpy(info->rsvd2, src->rsvd2, ARRAY_SIZE(src->rsvd2));
261cfd34f8eSVishwanathapura, Niranjana 
262cfd34f8eSVishwanathapura, Niranjana 	info->uc_macs_gen_count = cpu_to_be16(src->uc_macs_gen_count);
263cfd34f8eSVishwanathapura, Niranjana 	info->mc_macs_gen_count = cpu_to_be16(src->mc_macs_gen_count);
264cfd34f8eSVishwanathapura, Niranjana 	memcpy(info->rsvd3, src->rsvd3, ARRAY_SIZE(src->rsvd3));
265cfd34f8eSVishwanathapura, Niranjana }
266cfd34f8eSVishwanathapura, Niranjana 
267cfd34f8eSVishwanathapura, Niranjana /**
268cfd34f8eSVishwanathapura, Niranjana  * opa_vnic_set_per_veswport_info -- Set vesw per port information
269cfd34f8eSVishwanathapura, Niranjana  * @adapter: vnic port adapter
270cfd34f8eSVishwanathapura, Niranjana  * @info: pointer to vport info structure
271cfd34f8eSVishwanathapura, Niranjana  *
272cfd34f8eSVishwanathapura, Niranjana  * This function updates the vesw per port info that is maintained by the
273cfd34f8eSVishwanathapura, Niranjana  * given adapter with vesw per port info provided. Reserved fields are
274cfd34f8eSVishwanathapura, Niranjana  * stored and returned back to EM as is.
275cfd34f8eSVishwanathapura, Niranjana  */
opa_vnic_set_per_veswport_info(struct opa_vnic_adapter * adapter,struct opa_per_veswport_info * info)276cfd34f8eSVishwanathapura, Niranjana void opa_vnic_set_per_veswport_info(struct opa_vnic_adapter *adapter,
277cfd34f8eSVishwanathapura, Niranjana 				    struct opa_per_veswport_info *info)
278cfd34f8eSVishwanathapura, Niranjana {
279cfd34f8eSVishwanathapura, Niranjana 	struct __opa_per_veswport_info *dst = &adapter->info.vport;
280cfd34f8eSVishwanathapura, Niranjana 
281cfd34f8eSVishwanathapura, Niranjana 	dst->port_num = be32_to_cpu(info->port_num);
282cfd34f8eSVishwanathapura, Niranjana 	memcpy(dst->rsvd0, info->rsvd0, ARRAY_SIZE(info->rsvd0));
283cfd34f8eSVishwanathapura, Niranjana 
284cfd34f8eSVishwanathapura, Niranjana 	memcpy(dst->base_mac_addr, info->base_mac_addr,
285cfd34f8eSVishwanathapura, Niranjana 	       ARRAY_SIZE(dst->base_mac_addr));
286cfd34f8eSVishwanathapura, Niranjana 	dst->config_state = info->config_state;
287cfd34f8eSVishwanathapura, Niranjana 	memcpy(dst->rsvd1, info->rsvd1, ARRAY_SIZE(info->rsvd1));
288cfd34f8eSVishwanathapura, Niranjana 
289cfd34f8eSVishwanathapura, Niranjana 	dst->encap_slid = be32_to_cpu(info->encap_slid);
290cfd34f8eSVishwanathapura, Niranjana 	memcpy(dst->pcp_to_sc_uc, info->pcp_to_sc_uc,
291cfd34f8eSVishwanathapura, Niranjana 	       ARRAY_SIZE(dst->pcp_to_sc_uc));
292cfd34f8eSVishwanathapura, Niranjana 	memcpy(dst->pcp_to_vl_uc, info->pcp_to_vl_uc,
293cfd34f8eSVishwanathapura, Niranjana 	       ARRAY_SIZE(dst->pcp_to_vl_uc));
294cfd34f8eSVishwanathapura, Niranjana 	memcpy(dst->pcp_to_sc_mc, info->pcp_to_sc_mc,
295cfd34f8eSVishwanathapura, Niranjana 	       ARRAY_SIZE(dst->pcp_to_sc_mc));
296cfd34f8eSVishwanathapura, Niranjana 	memcpy(dst->pcp_to_vl_mc, info->pcp_to_vl_mc,
297cfd34f8eSVishwanathapura, Niranjana 	       ARRAY_SIZE(dst->pcp_to_vl_mc));
298cfd34f8eSVishwanathapura, Niranjana 	dst->non_vlan_sc_uc = info->non_vlan_sc_uc;
299cfd34f8eSVishwanathapura, Niranjana 	dst->non_vlan_vl_uc = info->non_vlan_vl_uc;
300cfd34f8eSVishwanathapura, Niranjana 	dst->non_vlan_sc_mc = info->non_vlan_sc_mc;
301cfd34f8eSVishwanathapura, Niranjana 	dst->non_vlan_vl_mc = info->non_vlan_vl_mc;
302cfd34f8eSVishwanathapura, Niranjana 	memcpy(dst->rsvd2, info->rsvd2, ARRAY_SIZE(info->rsvd2));
303cfd34f8eSVishwanathapura, Niranjana 	memcpy(dst->rsvd3, info->rsvd3, ARRAY_SIZE(info->rsvd3));
304cfd34f8eSVishwanathapura, Niranjana }
305cfd34f8eSVishwanathapura, Niranjana 
306cfd34f8eSVishwanathapura, Niranjana /**
307cfd34f8eSVishwanathapura, Niranjana  * opa_vnic_query_mcast_macs - query multicast mac list
308cfd34f8eSVishwanathapura, Niranjana  * @adapter: vnic port adapter
309cfd34f8eSVishwanathapura, Niranjana  * @macs: pointer mac list
310cfd34f8eSVishwanathapura, Niranjana  *
311cfd34f8eSVishwanathapura, Niranjana  * This function populates the provided mac list with the configured
312cfd34f8eSVishwanathapura, Niranjana  * multicast addresses in the adapter.
313cfd34f8eSVishwanathapura, Niranjana  */
opa_vnic_query_mcast_macs(struct opa_vnic_adapter * adapter,struct opa_veswport_iface_macs * macs)314cfd34f8eSVishwanathapura, Niranjana void opa_vnic_query_mcast_macs(struct opa_vnic_adapter *adapter,
315cfd34f8eSVishwanathapura, Niranjana 			       struct opa_veswport_iface_macs *macs)
316cfd34f8eSVishwanathapura, Niranjana {
317cfd34f8eSVishwanathapura, Niranjana 	u16 start_idx, num_macs, idx = 0, count = 0;
318cfd34f8eSVishwanathapura, Niranjana 	struct netdev_hw_addr *ha;
319cfd34f8eSVishwanathapura, Niranjana 
320cfd34f8eSVishwanathapura, Niranjana 	start_idx = be16_to_cpu(macs->start_idx);
321cfd34f8eSVishwanathapura, Niranjana 	num_macs = be16_to_cpu(macs->num_macs_in_msg);
322cfd34f8eSVishwanathapura, Niranjana 	netdev_for_each_mc_addr(ha, adapter->netdev) {
323cfd34f8eSVishwanathapura, Niranjana 		struct opa_vnic_iface_mac_entry *entry = &macs->entry[count];
324cfd34f8eSVishwanathapura, Niranjana 
325cfd34f8eSVishwanathapura, Niranjana 		if (start_idx > idx++)
326cfd34f8eSVishwanathapura, Niranjana 			continue;
327cfd34f8eSVishwanathapura, Niranjana 		else if (num_macs == count)
328cfd34f8eSVishwanathapura, Niranjana 			break;
329cfd34f8eSVishwanathapura, Niranjana 		memcpy(entry, ha->addr, sizeof(*entry));
330cfd34f8eSVishwanathapura, Niranjana 		count++;
331cfd34f8eSVishwanathapura, Niranjana 	}
332cfd34f8eSVishwanathapura, Niranjana 
333cfd34f8eSVishwanathapura, Niranjana 	macs->tot_macs_in_lst = cpu_to_be16(netdev_mc_count(adapter->netdev));
334cfd34f8eSVishwanathapura, Niranjana 	macs->num_macs_in_msg = cpu_to_be16(count);
335cfd34f8eSVishwanathapura, Niranjana 	macs->gen_count = cpu_to_be16(adapter->info.vport.mc_macs_gen_count);
336cfd34f8eSVishwanathapura, Niranjana }
337cfd34f8eSVishwanathapura, Niranjana 
338cfd34f8eSVishwanathapura, Niranjana /**
339cfd34f8eSVishwanathapura, Niranjana  * opa_vnic_query_ucast_macs - query unicast mac list
340cfd34f8eSVishwanathapura, Niranjana  * @adapter: vnic port adapter
341cfd34f8eSVishwanathapura, Niranjana  * @macs: pointer mac list
342cfd34f8eSVishwanathapura, Niranjana  *
343cfd34f8eSVishwanathapura, Niranjana  * This function populates the provided mac list with the configured
344cfd34f8eSVishwanathapura, Niranjana  * unicast addresses in the adapter.
345cfd34f8eSVishwanathapura, Niranjana  */
opa_vnic_query_ucast_macs(struct opa_vnic_adapter * adapter,struct opa_veswport_iface_macs * macs)346cfd34f8eSVishwanathapura, Niranjana void opa_vnic_query_ucast_macs(struct opa_vnic_adapter *adapter,
347cfd34f8eSVishwanathapura, Niranjana 			       struct opa_veswport_iface_macs *macs)
348cfd34f8eSVishwanathapura, Niranjana {
349b77eb45eSNiranjana Vishwanathapura 	u16 start_idx, tot_macs, num_macs, idx = 0, count = 0, em_macs = 0;
350cfd34f8eSVishwanathapura, Niranjana 	struct netdev_hw_addr *ha;
351cfd34f8eSVishwanathapura, Niranjana 
352cfd34f8eSVishwanathapura, Niranjana 	start_idx = be16_to_cpu(macs->start_idx);
353cfd34f8eSVishwanathapura, Niranjana 	num_macs = be16_to_cpu(macs->num_macs_in_msg);
354cfd34f8eSVishwanathapura, Niranjana 	/* loop through dev_addrs list first */
355cfd34f8eSVishwanathapura, Niranjana 	for_each_dev_addr(adapter->netdev, ha) {
356cfd34f8eSVishwanathapura, Niranjana 		struct opa_vnic_iface_mac_entry *entry = &macs->entry[count];
357cfd34f8eSVishwanathapura, Niranjana 
358cfd34f8eSVishwanathapura, Niranjana 		/* Do not include EM specified MAC address */
359cfd34f8eSVishwanathapura, Niranjana 		if (!memcmp(adapter->info.vport.base_mac_addr, ha->addr,
360b77eb45eSNiranjana Vishwanathapura 			    ARRAY_SIZE(adapter->info.vport.base_mac_addr))) {
361b77eb45eSNiranjana Vishwanathapura 			em_macs++;
362cfd34f8eSVishwanathapura, Niranjana 			continue;
363b77eb45eSNiranjana Vishwanathapura 		}
364cfd34f8eSVishwanathapura, Niranjana 
365cfd34f8eSVishwanathapura, Niranjana 		if (start_idx > idx++)
366cfd34f8eSVishwanathapura, Niranjana 			continue;
367cfd34f8eSVishwanathapura, Niranjana 		else if (num_macs == count)
368cfd34f8eSVishwanathapura, Niranjana 			break;
369cfd34f8eSVishwanathapura, Niranjana 		memcpy(entry, ha->addr, sizeof(*entry));
370cfd34f8eSVishwanathapura, Niranjana 		count++;
371cfd34f8eSVishwanathapura, Niranjana 	}
372cfd34f8eSVishwanathapura, Niranjana 
373cfd34f8eSVishwanathapura, Niranjana 	/* loop through uc list */
374cfd34f8eSVishwanathapura, Niranjana 	netdev_for_each_uc_addr(ha, adapter->netdev) {
375cfd34f8eSVishwanathapura, Niranjana 		struct opa_vnic_iface_mac_entry *entry = &macs->entry[count];
376cfd34f8eSVishwanathapura, Niranjana 
377cfd34f8eSVishwanathapura, Niranjana 		if (start_idx > idx++)
378cfd34f8eSVishwanathapura, Niranjana 			continue;
379cfd34f8eSVishwanathapura, Niranjana 		else if (num_macs == count)
380cfd34f8eSVishwanathapura, Niranjana 			break;
381cfd34f8eSVishwanathapura, Niranjana 		memcpy(entry, ha->addr, sizeof(*entry));
382cfd34f8eSVishwanathapura, Niranjana 		count++;
383cfd34f8eSVishwanathapura, Niranjana 	}
384cfd34f8eSVishwanathapura, Niranjana 
385cfd34f8eSVishwanathapura, Niranjana 	tot_macs = netdev_hw_addr_list_count(&adapter->netdev->dev_addrs) +
386b77eb45eSNiranjana Vishwanathapura 		   netdev_uc_count(adapter->netdev) - em_macs;
387cfd34f8eSVishwanathapura, Niranjana 	macs->tot_macs_in_lst = cpu_to_be16(tot_macs);
388cfd34f8eSVishwanathapura, Niranjana 	macs->num_macs_in_msg = cpu_to_be16(count);
389cfd34f8eSVishwanathapura, Niranjana 	macs->gen_count = cpu_to_be16(adapter->info.vport.uc_macs_gen_count);
390cfd34f8eSVishwanathapura, Niranjana }
391