17d6f728cSVishwanathapura, Niranjana /*
27d6f728cSVishwanathapura, Niranjana * Copyright(c) 2017 Intel Corporation.
37d6f728cSVishwanathapura, Niranjana *
47d6f728cSVishwanathapura, Niranjana * This file is provided under a dual BSD/GPLv2 license. When using or
57d6f728cSVishwanathapura, Niranjana * redistributing this file, you may do so under either license.
67d6f728cSVishwanathapura, Niranjana *
77d6f728cSVishwanathapura, Niranjana * GPL LICENSE SUMMARY
87d6f728cSVishwanathapura, Niranjana *
97d6f728cSVishwanathapura, Niranjana * This program is free software; you can redistribute it and/or modify
107d6f728cSVishwanathapura, Niranjana * it under the terms of version 2 of the GNU General Public License as
117d6f728cSVishwanathapura, Niranjana * published by the Free Software Foundation.
127d6f728cSVishwanathapura, Niranjana *
137d6f728cSVishwanathapura, Niranjana * This program is distributed in the hope that it will be useful, but
147d6f728cSVishwanathapura, Niranjana * WITHOUT ANY WARRANTY; without even the implied warranty of
157d6f728cSVishwanathapura, Niranjana * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
167d6f728cSVishwanathapura, Niranjana * General Public License for more details.
177d6f728cSVishwanathapura, Niranjana *
187d6f728cSVishwanathapura, Niranjana * BSD LICENSE
197d6f728cSVishwanathapura, Niranjana *
207d6f728cSVishwanathapura, Niranjana * Redistribution and use in source and binary forms, with or without
217d6f728cSVishwanathapura, Niranjana * modification, are permitted provided that the following conditions
227d6f728cSVishwanathapura, Niranjana * are met:
237d6f728cSVishwanathapura, Niranjana *
247d6f728cSVishwanathapura, Niranjana * - Redistributions of source code must retain the above copyright
257d6f728cSVishwanathapura, Niranjana * notice, this list of conditions and the following disclaimer.
267d6f728cSVishwanathapura, Niranjana * - Redistributions in binary form must reproduce the above copyright
277d6f728cSVishwanathapura, Niranjana * notice, this list of conditions and the following disclaimer in
287d6f728cSVishwanathapura, Niranjana * the documentation and/or other materials provided with the
297d6f728cSVishwanathapura, Niranjana * distribution.
307d6f728cSVishwanathapura, Niranjana * - Neither the name of Intel Corporation nor the names of its
317d6f728cSVishwanathapura, Niranjana * contributors may be used to endorse or promote products derived
327d6f728cSVishwanathapura, Niranjana * from this software without specific prior written permission.
337d6f728cSVishwanathapura, Niranjana *
347d6f728cSVishwanathapura, Niranjana * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
357d6f728cSVishwanathapura, Niranjana * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
367d6f728cSVishwanathapura, Niranjana * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
377d6f728cSVishwanathapura, Niranjana * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
387d6f728cSVishwanathapura, Niranjana * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
397d6f728cSVishwanathapura, Niranjana * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
407d6f728cSVishwanathapura, Niranjana * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
417d6f728cSVishwanathapura, Niranjana * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
427d6f728cSVishwanathapura, Niranjana * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
437d6f728cSVishwanathapura, Niranjana * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
447d6f728cSVishwanathapura, Niranjana * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
457d6f728cSVishwanathapura, Niranjana *
467d6f728cSVishwanathapura, Niranjana */
477d6f728cSVishwanathapura, Niranjana
487d6f728cSVishwanathapura, Niranjana /*
497d6f728cSVishwanathapura, Niranjana * This file contains OPA Virtual Network Interface Controller (VNIC) driver
507d6f728cSVishwanathapura, Niranjana * netdev functionality.
517d6f728cSVishwanathapura, Niranjana */
527d6f728cSVishwanathapura, Niranjana
537d6f728cSVishwanathapura, Niranjana #include <linux/if_vlan.h>
54cfd34f8eSVishwanathapura, Niranjana #include <linux/crc32.h>
557d6f728cSVishwanathapura, Niranjana
567d6f728cSVishwanathapura, Niranjana #include "opa_vnic_internal.h"
577d6f728cSVishwanathapura, Niranjana
587d6f728cSVishwanathapura, Niranjana #define OPA_TX_TIMEOUT_MS 1000
597d6f728cSVishwanathapura, Niranjana
607d6f728cSVishwanathapura, Niranjana #define OPA_VNIC_SKB_HEADROOM \
617d6f728cSVishwanathapura, Niranjana ALIGN((OPA_VNIC_HDR_LEN + OPA_VNIC_SKB_MDATA_LEN), 8)
627d6f728cSVishwanathapura, Niranjana
63009b7dd4SVishwanathapura, Niranjana /* This function is overloaded for opa_vnic specific implementation */
opa_vnic_get_stats64(struct net_device * netdev,struct rtnl_link_stats64 * stats)64009b7dd4SVishwanathapura, Niranjana static void opa_vnic_get_stats64(struct net_device *netdev,
65009b7dd4SVishwanathapura, Niranjana struct rtnl_link_stats64 *stats)
66009b7dd4SVishwanathapura, Niranjana {
67009b7dd4SVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev);
68009b7dd4SVishwanathapura, Niranjana struct opa_vnic_stats vstats;
69009b7dd4SVishwanathapura, Niranjana
70009b7dd4SVishwanathapura, Niranjana memset(&vstats, 0, sizeof(vstats));
71a379d69fSVishwanathapura, Niranjana spin_lock(&adapter->stats_lock);
72009b7dd4SVishwanathapura, Niranjana adapter->rn_ops->ndo_get_stats64(netdev, &vstats.netstats);
73a379d69fSVishwanathapura, Niranjana spin_unlock(&adapter->stats_lock);
74009b7dd4SVishwanathapura, Niranjana memcpy(stats, &vstats.netstats, sizeof(*stats));
75009b7dd4SVishwanathapura, Niranjana }
76009b7dd4SVishwanathapura, Niranjana
777d6f728cSVishwanathapura, Niranjana /* opa_netdev_start_xmit - transmit function */
opa_netdev_start_xmit(struct sk_buff * skb,struct net_device * netdev)787d6f728cSVishwanathapura, Niranjana static netdev_tx_t opa_netdev_start_xmit(struct sk_buff *skb,
797d6f728cSVishwanathapura, Niranjana struct net_device *netdev)
807d6f728cSVishwanathapura, Niranjana {
817d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev);
827d6f728cSVishwanathapura, Niranjana
837d6f728cSVishwanathapura, Niranjana v_dbg("xmit: queue %d skb len %d\n", skb->queue_mapping, skb->len);
847d6f728cSVishwanathapura, Niranjana /* pad to ensure mininum ethernet packet length */
857d6f728cSVishwanathapura, Niranjana if (unlikely(skb->len < ETH_ZLEN)) {
867d6f728cSVishwanathapura, Niranjana if (skb_padto(skb, ETH_ZLEN))
877d6f728cSVishwanathapura, Niranjana return NETDEV_TX_OK;
887d6f728cSVishwanathapura, Niranjana
897d6f728cSVishwanathapura, Niranjana skb_put(skb, ETH_ZLEN - skb->len);
907d6f728cSVishwanathapura, Niranjana }
917d6f728cSVishwanathapura, Niranjana
927d6f728cSVishwanathapura, Niranjana opa_vnic_encap_skb(adapter, skb);
937d6f728cSVishwanathapura, Niranjana return adapter->rn_ops->ndo_start_xmit(skb, netdev);
947d6f728cSVishwanathapura, Niranjana }
957d6f728cSVishwanathapura, Niranjana
opa_vnic_select_queue(struct net_device * netdev,struct sk_buff * skb,struct net_device * sb_dev)967d6f728cSVishwanathapura, Niranjana static u16 opa_vnic_select_queue(struct net_device *netdev, struct sk_buff *skb,
97*a350ecceSPaolo Abeni struct net_device *sb_dev)
987d6f728cSVishwanathapura, Niranjana {
997d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev);
1007d6f728cSVishwanathapura, Niranjana struct opa_vnic_skb_mdata *mdata;
1017d6f728cSVishwanathapura, Niranjana int rc;
1027d6f728cSVishwanathapura, Niranjana
1037d6f728cSVishwanathapura, Niranjana /* pass entropy and vl as metadata in skb */
104d58ff351SJohannes Berg mdata = skb_push(skb, sizeof(*mdata));
105d80d8d55SAlexander Duyck mdata->entropy = opa_vnic_calc_entropy(skb);
1067d6f728cSVishwanathapura, Niranjana mdata->vl = opa_vnic_get_vl(adapter, skb);
107*a350ecceSPaolo Abeni rc = adapter->rn_ops->ndo_select_queue(netdev, skb, sb_dev);
1087d6f728cSVishwanathapura, Niranjana skb_pull(skb, sizeof(*mdata));
1097d6f728cSVishwanathapura, Niranjana return rc;
1107d6f728cSVishwanathapura, Niranjana }
1117d6f728cSVishwanathapura, Niranjana
opa_vnic_update_state(struct opa_vnic_adapter * adapter,bool up)112e82b7c38SNiranjana Vishwanathapura static void opa_vnic_update_state(struct opa_vnic_adapter *adapter, bool up)
113e82b7c38SNiranjana Vishwanathapura {
114e82b7c38SNiranjana Vishwanathapura struct __opa_veswport_info *info = &adapter->info;
115e82b7c38SNiranjana Vishwanathapura
116e82b7c38SNiranjana Vishwanathapura mutex_lock(&adapter->lock);
117e82b7c38SNiranjana Vishwanathapura /* Operational state can only be DROP_ALL or FORWARDING */
118e82b7c38SNiranjana Vishwanathapura if ((info->vport.config_state == OPA_VNIC_STATE_FORWARDING) && up) {
119e82b7c38SNiranjana Vishwanathapura info->vport.oper_state = OPA_VNIC_STATE_FORWARDING;
120e82b7c38SNiranjana Vishwanathapura info->vport.eth_link_status = OPA_VNIC_ETH_LINK_UP;
121e82b7c38SNiranjana Vishwanathapura } else {
122e82b7c38SNiranjana Vishwanathapura info->vport.oper_state = OPA_VNIC_STATE_DROP_ALL;
123e82b7c38SNiranjana Vishwanathapura info->vport.eth_link_status = OPA_VNIC_ETH_LINK_DOWN;
124e82b7c38SNiranjana Vishwanathapura }
125e82b7c38SNiranjana Vishwanathapura
126e82b7c38SNiranjana Vishwanathapura if (info->vport.config_state == OPA_VNIC_STATE_FORWARDING)
127e82b7c38SNiranjana Vishwanathapura netif_dormant_off(adapter->netdev);
128e82b7c38SNiranjana Vishwanathapura else
129e82b7c38SNiranjana Vishwanathapura netif_dormant_on(adapter->netdev);
130e82b7c38SNiranjana Vishwanathapura mutex_unlock(&adapter->lock);
131e82b7c38SNiranjana Vishwanathapura }
132e82b7c38SNiranjana Vishwanathapura
133cfd34f8eSVishwanathapura, Niranjana /* opa_vnic_process_vema_config - process vema configuration updates */
opa_vnic_process_vema_config(struct opa_vnic_adapter * adapter)134cfd34f8eSVishwanathapura, Niranjana void opa_vnic_process_vema_config(struct opa_vnic_adapter *adapter)
135cfd34f8eSVishwanathapura, Niranjana {
136cfd34f8eSVishwanathapura, Niranjana struct __opa_veswport_info *info = &adapter->info;
137cfd34f8eSVishwanathapura, Niranjana struct rdma_netdev *rn = netdev_priv(adapter->netdev);
138cfd34f8eSVishwanathapura, Niranjana u8 port_num[OPA_VESW_MAX_NUM_DEF_PORT] = { 0 };
139cfd34f8eSVishwanathapura, Niranjana struct net_device *netdev = adapter->netdev;
140cfd34f8eSVishwanathapura, Niranjana u8 i, port_count = 0;
141cfd34f8eSVishwanathapura, Niranjana u16 port_mask;
142cfd34f8eSVishwanathapura, Niranjana
143cfd34f8eSVishwanathapura, Niranjana /* If the base_mac_addr is changed, update the interface mac address */
144cfd34f8eSVishwanathapura, Niranjana if (memcmp(info->vport.base_mac_addr, adapter->vema_mac_addr,
145cfd34f8eSVishwanathapura, Niranjana ARRAY_SIZE(info->vport.base_mac_addr))) {
146cfd34f8eSVishwanathapura, Niranjana struct sockaddr saddr;
147cfd34f8eSVishwanathapura, Niranjana
148cfd34f8eSVishwanathapura, Niranjana memcpy(saddr.sa_data, info->vport.base_mac_addr,
149cfd34f8eSVishwanathapura, Niranjana ARRAY_SIZE(info->vport.base_mac_addr));
150cfd34f8eSVishwanathapura, Niranjana mutex_lock(&adapter->lock);
1515a5a85daSNiranjana Vishwanathapura eth_commit_mac_addr_change(netdev, &saddr);
152cfd34f8eSVishwanathapura, Niranjana memcpy(adapter->vema_mac_addr,
153cfd34f8eSVishwanathapura, Niranjana info->vport.base_mac_addr, ETH_ALEN);
154cfd34f8eSVishwanathapura, Niranjana mutex_unlock(&adapter->lock);
155cfd34f8eSVishwanathapura, Niranjana }
156cfd34f8eSVishwanathapura, Niranjana
157cfd34f8eSVishwanathapura, Niranjana rn->set_id(netdev, info->vesw.vesw_id);
158cfd34f8eSVishwanathapura, Niranjana
159cfd34f8eSVishwanathapura, Niranjana /* Handle MTU limit change */
160cfd34f8eSVishwanathapura, Niranjana rtnl_lock();
16162f1e84eSNiranjana Vishwanathapura netdev->max_mtu = max_t(unsigned int, info->vesw.eth_mtu,
162cfd34f8eSVishwanathapura, Niranjana netdev->min_mtu);
163cfd34f8eSVishwanathapura, Niranjana if (netdev->mtu > netdev->max_mtu)
164cfd34f8eSVishwanathapura, Niranjana dev_set_mtu(netdev, netdev->max_mtu);
165cfd34f8eSVishwanathapura, Niranjana rtnl_unlock();
166cfd34f8eSVishwanathapura, Niranjana
167cfd34f8eSVishwanathapura, Niranjana /* Update flow to default port redirection table */
168cfd34f8eSVishwanathapura, Niranjana port_mask = info->vesw.def_port_mask;
169cfd34f8eSVishwanathapura, Niranjana for (i = 0; i < OPA_VESW_MAX_NUM_DEF_PORT; i++) {
170cfd34f8eSVishwanathapura, Niranjana if (port_mask & 1)
171cfd34f8eSVishwanathapura, Niranjana port_num[port_count++] = i;
172cfd34f8eSVishwanathapura, Niranjana port_mask >>= 1;
173cfd34f8eSVishwanathapura, Niranjana }
174cfd34f8eSVishwanathapura, Niranjana
175cfd34f8eSVishwanathapura, Niranjana /*
176cfd34f8eSVishwanathapura, Niranjana * Build the flow table. Flow table is required when destination LID
177cfd34f8eSVishwanathapura, Niranjana * is not available. Up to OPA_VNIC_FLOW_TBL_SIZE flows supported.
178cfd34f8eSVishwanathapura, Niranjana * Each flow need a default port number to get its dlid from the
179cfd34f8eSVishwanathapura, Niranjana * u_ucast_dlid array.
180cfd34f8eSVishwanathapura, Niranjana */
181cfd34f8eSVishwanathapura, Niranjana for (i = 0; i < OPA_VNIC_FLOW_TBL_SIZE; i++)
182cfd34f8eSVishwanathapura, Niranjana adapter->flow_tbl[i] = port_count ? port_num[i % port_count] :
183cfd34f8eSVishwanathapura, Niranjana OPA_VNIC_INVALID_PORT;
184cfd34f8eSVishwanathapura, Niranjana
185e82b7c38SNiranjana Vishwanathapura /* update state */
186e82b7c38SNiranjana Vishwanathapura opa_vnic_update_state(adapter, !!(netdev->flags & IFF_UP));
187cfd34f8eSVishwanathapura, Niranjana }
188cfd34f8eSVishwanathapura, Niranjana
189cfd34f8eSVishwanathapura, Niranjana /*
190cfd34f8eSVishwanathapura, Niranjana * Set the power on default values in adapter's vema interface structure.
191cfd34f8eSVishwanathapura, Niranjana */
opa_vnic_set_pod_values(struct opa_vnic_adapter * adapter)192cfd34f8eSVishwanathapura, Niranjana static inline void opa_vnic_set_pod_values(struct opa_vnic_adapter *adapter)
193cfd34f8eSVishwanathapura, Niranjana {
194cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.max_mac_tbl_ent = OPA_VNIC_MAC_TBL_MAX_ENTRIES;
195cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.max_smac_ent = OPA_VNIC_MAX_SMAC_LIMIT;
196cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.config_state = OPA_VNIC_STATE_DROP_ALL;
197cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.eth_link_status = OPA_VNIC_ETH_LINK_DOWN;
1987f291d28SNiranjana Vishwanathapura adapter->info.vesw.eth_mtu = ETH_DATA_LEN;
199cfd34f8eSVishwanathapura, Niranjana }
200cfd34f8eSVishwanathapura, Niranjana
2017d6f728cSVishwanathapura, Niranjana /* opa_vnic_set_mac_addr - change mac address */
opa_vnic_set_mac_addr(struct net_device * netdev,void * addr)2027d6f728cSVishwanathapura, Niranjana static int opa_vnic_set_mac_addr(struct net_device *netdev, void *addr)
2037d6f728cSVishwanathapura, Niranjana {
2047d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev);
2057d6f728cSVishwanathapura, Niranjana struct sockaddr *sa = addr;
2067d6f728cSVishwanathapura, Niranjana int rc;
2077d6f728cSVishwanathapura, Niranjana
2087d6f728cSVishwanathapura, Niranjana if (!memcmp(netdev->dev_addr, sa->sa_data, ETH_ALEN))
2097d6f728cSVishwanathapura, Niranjana return 0;
2107d6f728cSVishwanathapura, Niranjana
2117d6f728cSVishwanathapura, Niranjana mutex_lock(&adapter->lock);
2127d6f728cSVishwanathapura, Niranjana rc = eth_mac_addr(netdev, addr);
2137d6f728cSVishwanathapura, Niranjana mutex_unlock(&adapter->lock);
214cfd34f8eSVishwanathapura, Niranjana if (rc)
2157d6f728cSVishwanathapura, Niranjana return rc;
216cfd34f8eSVishwanathapura, Niranjana
217cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.uc_macs_gen_count++;
218cfd34f8eSVishwanathapura, Niranjana opa_vnic_vema_report_event(adapter,
219cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_IFACE_UCAST_MAC_CHANGE);
220cfd34f8eSVishwanathapura, Niranjana return 0;
221cfd34f8eSVishwanathapura, Niranjana }
222cfd34f8eSVishwanathapura, Niranjana
223cfd34f8eSVishwanathapura, Niranjana /*
224cfd34f8eSVishwanathapura, Niranjana * opa_vnic_mac_send_event - post event on possible mac list exchange
225cfd34f8eSVishwanathapura, Niranjana * Send trap when digest from uc/mc mac list differs from previous run.
226cfd34f8eSVishwanathapura, Niranjana * Digest is evaluated similar to how cksum does.
227cfd34f8eSVishwanathapura, Niranjana */
opa_vnic_mac_send_event(struct net_device * netdev,u8 event)228cfd34f8eSVishwanathapura, Niranjana static void opa_vnic_mac_send_event(struct net_device *netdev, u8 event)
229cfd34f8eSVishwanathapura, Niranjana {
230cfd34f8eSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev);
231cfd34f8eSVishwanathapura, Niranjana struct netdev_hw_addr *ha;
232cfd34f8eSVishwanathapura, Niranjana struct netdev_hw_addr_list *hw_list;
233cfd34f8eSVishwanathapura, Niranjana u32 *ref_crc;
234cfd34f8eSVishwanathapura, Niranjana u32 l, crc = 0;
235cfd34f8eSVishwanathapura, Niranjana
236cfd34f8eSVishwanathapura, Niranjana switch (event) {
237cfd34f8eSVishwanathapura, Niranjana case OPA_VESWPORT_TRAP_IFACE_UCAST_MAC_CHANGE:
238cfd34f8eSVishwanathapura, Niranjana hw_list = &netdev->uc;
239cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.uc_macs_gen_count++;
240cfd34f8eSVishwanathapura, Niranjana ref_crc = &adapter->umac_hash;
241cfd34f8eSVishwanathapura, Niranjana break;
242cfd34f8eSVishwanathapura, Niranjana case OPA_VESWPORT_TRAP_IFACE_MCAST_MAC_CHANGE:
243cfd34f8eSVishwanathapura, Niranjana hw_list = &netdev->mc;
244cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.mc_macs_gen_count++;
245cfd34f8eSVishwanathapura, Niranjana ref_crc = &adapter->mmac_hash;
246cfd34f8eSVishwanathapura, Niranjana break;
247cfd34f8eSVishwanathapura, Niranjana default:
248cfd34f8eSVishwanathapura, Niranjana return;
249cfd34f8eSVishwanathapura, Niranjana }
250cfd34f8eSVishwanathapura, Niranjana netdev_hw_addr_list_for_each(ha, hw_list) {
251cfd34f8eSVishwanathapura, Niranjana crc = crc32_le(crc, ha->addr, ETH_ALEN);
252cfd34f8eSVishwanathapura, Niranjana }
253cfd34f8eSVishwanathapura, Niranjana l = netdev_hw_addr_list_count(hw_list) * ETH_ALEN;
254cfd34f8eSVishwanathapura, Niranjana crc = ~crc32_le(crc, (void *)&l, sizeof(l));
255cfd34f8eSVishwanathapura, Niranjana
256cfd34f8eSVishwanathapura, Niranjana if (crc != *ref_crc) {
257cfd34f8eSVishwanathapura, Niranjana *ref_crc = crc;
258cfd34f8eSVishwanathapura, Niranjana opa_vnic_vema_report_event(adapter, event);
259cfd34f8eSVishwanathapura, Niranjana }
260cfd34f8eSVishwanathapura, Niranjana }
261cfd34f8eSVishwanathapura, Niranjana
262cfd34f8eSVishwanathapura, Niranjana /* opa_vnic_set_rx_mode - handle uc/mc mac list change */
opa_vnic_set_rx_mode(struct net_device * netdev)263cfd34f8eSVishwanathapura, Niranjana static void opa_vnic_set_rx_mode(struct net_device *netdev)
264cfd34f8eSVishwanathapura, Niranjana {
265cfd34f8eSVishwanathapura, Niranjana opa_vnic_mac_send_event(netdev,
266cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_IFACE_UCAST_MAC_CHANGE);
267cfd34f8eSVishwanathapura, Niranjana
268cfd34f8eSVishwanathapura, Niranjana opa_vnic_mac_send_event(netdev,
269cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_IFACE_MCAST_MAC_CHANGE);
2707d6f728cSVishwanathapura, Niranjana }
2717d6f728cSVishwanathapura, Niranjana
2727d6f728cSVishwanathapura, Niranjana /* opa_netdev_open - activate network interface */
opa_netdev_open(struct net_device * netdev)2737d6f728cSVishwanathapura, Niranjana static int opa_netdev_open(struct net_device *netdev)
2747d6f728cSVishwanathapura, Niranjana {
2757d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev);
2767d6f728cSVishwanathapura, Niranjana int rc;
2777d6f728cSVishwanathapura, Niranjana
2787d6f728cSVishwanathapura, Niranjana rc = adapter->rn_ops->ndo_open(adapter->netdev);
2797d6f728cSVishwanathapura, Niranjana if (rc) {
2807d6f728cSVishwanathapura, Niranjana v_dbg("open failed %d\n", rc);
2817d6f728cSVishwanathapura, Niranjana return rc;
2827d6f728cSVishwanathapura, Niranjana }
2837d6f728cSVishwanathapura, Niranjana
284e82b7c38SNiranjana Vishwanathapura /* Update status and send trap */
285e82b7c38SNiranjana Vishwanathapura opa_vnic_update_state(adapter, true);
286cfd34f8eSVishwanathapura, Niranjana opa_vnic_vema_report_event(adapter,
287cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_ETH_LINK_STATUS_CHANGE);
2887d6f728cSVishwanathapura, Niranjana return 0;
2897d6f728cSVishwanathapura, Niranjana }
2907d6f728cSVishwanathapura, Niranjana
2917d6f728cSVishwanathapura, Niranjana /* opa_netdev_close - disable network interface */
opa_netdev_close(struct net_device * netdev)2927d6f728cSVishwanathapura, Niranjana static int opa_netdev_close(struct net_device *netdev)
2937d6f728cSVishwanathapura, Niranjana {
2947d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev);
2957d6f728cSVishwanathapura, Niranjana int rc;
2967d6f728cSVishwanathapura, Niranjana
2977d6f728cSVishwanathapura, Niranjana rc = adapter->rn_ops->ndo_stop(adapter->netdev);
2987d6f728cSVishwanathapura, Niranjana if (rc) {
2997d6f728cSVishwanathapura, Niranjana v_dbg("close failed %d\n", rc);
3007d6f728cSVishwanathapura, Niranjana return rc;
3017d6f728cSVishwanathapura, Niranjana }
3027d6f728cSVishwanathapura, Niranjana
303e82b7c38SNiranjana Vishwanathapura /* Update status and send trap */
304e82b7c38SNiranjana Vishwanathapura opa_vnic_update_state(adapter, false);
305cfd34f8eSVishwanathapura, Niranjana opa_vnic_vema_report_event(adapter,
306cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_ETH_LINK_STATUS_CHANGE);
3077d6f728cSVishwanathapura, Niranjana return 0;
3087d6f728cSVishwanathapura, Niranjana }
3097d6f728cSVishwanathapura, Niranjana
3107d6f728cSVishwanathapura, Niranjana /* netdev ops */
3117d6f728cSVishwanathapura, Niranjana static const struct net_device_ops opa_netdev_ops = {
3127d6f728cSVishwanathapura, Niranjana .ndo_open = opa_netdev_open,
3137d6f728cSVishwanathapura, Niranjana .ndo_stop = opa_netdev_close,
3147d6f728cSVishwanathapura, Niranjana .ndo_start_xmit = opa_netdev_start_xmit,
315009b7dd4SVishwanathapura, Niranjana .ndo_get_stats64 = opa_vnic_get_stats64,
316cfd34f8eSVishwanathapura, Niranjana .ndo_set_rx_mode = opa_vnic_set_rx_mode,
3177d6f728cSVishwanathapura, Niranjana .ndo_select_queue = opa_vnic_select_queue,
3187d6f728cSVishwanathapura, Niranjana .ndo_set_mac_address = opa_vnic_set_mac_addr,
3197d6f728cSVishwanathapura, Niranjana };
3207d6f728cSVishwanathapura, Niranjana
3217d6f728cSVishwanathapura, Niranjana /* opa_vnic_add_netdev - create vnic netdev interface */
opa_vnic_add_netdev(struct ib_device * ibdev,u8 port_num,u8 vport_num)3227d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *opa_vnic_add_netdev(struct ib_device *ibdev,
3237d6f728cSVishwanathapura, Niranjana u8 port_num, u8 vport_num)
3247d6f728cSVishwanathapura, Niranjana {
3257d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter;
3267d6f728cSVishwanathapura, Niranjana struct net_device *netdev;
3277d6f728cSVishwanathapura, Niranjana struct rdma_netdev *rn;
3287d6f728cSVishwanathapura, Niranjana int rc;
3297d6f728cSVishwanathapura, Niranjana
3303023a1e9SKamal Heib netdev = ibdev->ops.alloc_rdma_netdev(ibdev, port_num,
3317d6f728cSVishwanathapura, Niranjana RDMA_NETDEV_OPA_VNIC,
3327d6f728cSVishwanathapura, Niranjana "veth%d", NET_NAME_UNKNOWN,
3337d6f728cSVishwanathapura, Niranjana ether_setup);
3347d6f728cSVishwanathapura, Niranjana if (!netdev)
3357d6f728cSVishwanathapura, Niranjana return ERR_PTR(-ENOMEM);
3367d6f728cSVishwanathapura, Niranjana else if (IS_ERR(netdev))
3377d6f728cSVishwanathapura, Niranjana return ERR_CAST(netdev);
3387d6f728cSVishwanathapura, Niranjana
3398e959601SNiranjana Vishwanathapura rn = netdev_priv(netdev);
3407d6f728cSVishwanathapura, Niranjana adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3417d6f728cSVishwanathapura, Niranjana if (!adapter) {
3427d6f728cSVishwanathapura, Niranjana rc = -ENOMEM;
3437d6f728cSVishwanathapura, Niranjana goto adapter_err;
3447d6f728cSVishwanathapura, Niranjana }
3457d6f728cSVishwanathapura, Niranjana
3467d6f728cSVishwanathapura, Niranjana rn->clnt_priv = adapter;
3477d6f728cSVishwanathapura, Niranjana rn->hca = ibdev;
3487d6f728cSVishwanathapura, Niranjana rn->port_num = port_num;
3497d6f728cSVishwanathapura, Niranjana adapter->netdev = netdev;
3507d6f728cSVishwanathapura, Niranjana adapter->ibdev = ibdev;
3517d6f728cSVishwanathapura, Niranjana adapter->port_num = port_num;
3527d6f728cSVishwanathapura, Niranjana adapter->vport_num = vport_num;
3537d6f728cSVishwanathapura, Niranjana adapter->rn_ops = netdev->netdev_ops;
3547d6f728cSVishwanathapura, Niranjana
3557d6f728cSVishwanathapura, Niranjana netdev->netdev_ops = &opa_netdev_ops;
3567d6f728cSVishwanathapura, Niranjana netdev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
3577d6f728cSVishwanathapura, Niranjana netdev->hard_header_len += OPA_VNIC_SKB_HEADROOM;
3587d6f728cSVishwanathapura, Niranjana mutex_init(&adapter->lock);
359174e03d7SVishwanathapura, Niranjana mutex_init(&adapter->mactbl_lock);
360a379d69fSVishwanathapura, Niranjana spin_lock_init(&adapter->stats_lock);
3617d6f728cSVishwanathapura, Niranjana
3627d6f728cSVishwanathapura, Niranjana SET_NETDEV_DEV(netdev, ibdev->dev.parent);
3637d6f728cSVishwanathapura, Niranjana
3647d6f728cSVishwanathapura, Niranjana opa_vnic_set_ethtool_ops(netdev);
365cfd34f8eSVishwanathapura, Niranjana
366cfd34f8eSVishwanathapura, Niranjana opa_vnic_set_pod_values(adapter);
367cfd34f8eSVishwanathapura, Niranjana
3687d6f728cSVishwanathapura, Niranjana rc = register_netdev(netdev);
3697d6f728cSVishwanathapura, Niranjana if (rc)
3707d6f728cSVishwanathapura, Niranjana goto netdev_err;
3717d6f728cSVishwanathapura, Niranjana
3727d6f728cSVishwanathapura, Niranjana netif_carrier_off(netdev);
3737d6f728cSVishwanathapura, Niranjana netif_dormant_on(netdev);
3747d6f728cSVishwanathapura, Niranjana v_info("initialized\n");
3757d6f728cSVishwanathapura, Niranjana
3767d6f728cSVishwanathapura, Niranjana return adapter;
3777d6f728cSVishwanathapura, Niranjana netdev_err:
3787d6f728cSVishwanathapura, Niranjana mutex_destroy(&adapter->lock);
379174e03d7SVishwanathapura, Niranjana mutex_destroy(&adapter->mactbl_lock);
3807d6f728cSVishwanathapura, Niranjana kfree(adapter);
3817d6f728cSVishwanathapura, Niranjana adapter_err:
3828e959601SNiranjana Vishwanathapura rn->free_rdma_netdev(netdev);
3837d6f728cSVishwanathapura, Niranjana
3847d6f728cSVishwanathapura, Niranjana return ERR_PTR(rc);
3857d6f728cSVishwanathapura, Niranjana }
3867d6f728cSVishwanathapura, Niranjana
3877d6f728cSVishwanathapura, Niranjana /* opa_vnic_rem_netdev - remove vnic netdev interface */
opa_vnic_rem_netdev(struct opa_vnic_adapter * adapter)3887d6f728cSVishwanathapura, Niranjana void opa_vnic_rem_netdev(struct opa_vnic_adapter *adapter)
3897d6f728cSVishwanathapura, Niranjana {
3907d6f728cSVishwanathapura, Niranjana struct net_device *netdev = adapter->netdev;
3918e959601SNiranjana Vishwanathapura struct rdma_netdev *rn = netdev_priv(netdev);
3927d6f728cSVishwanathapura, Niranjana
3937d6f728cSVishwanathapura, Niranjana v_info("removing\n");
3947d6f728cSVishwanathapura, Niranjana unregister_netdev(netdev);
395174e03d7SVishwanathapura, Niranjana opa_vnic_release_mac_tbl(adapter);
3967d6f728cSVishwanathapura, Niranjana mutex_destroy(&adapter->lock);
397174e03d7SVishwanathapura, Niranjana mutex_destroy(&adapter->mactbl_lock);
3987d6f728cSVishwanathapura, Niranjana kfree(adapter);
3998e959601SNiranjana Vishwanathapura rn->free_rdma_netdev(netdev);
4007d6f728cSVishwanathapura, Niranjana }
401