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/module.h> 547d6f728cSVishwanathapura, Niranjana #include <linux/if_vlan.h> 55cfd34f8eSVishwanathapura, Niranjana #include <linux/crc32.h> 567d6f728cSVishwanathapura, Niranjana 577d6f728cSVishwanathapura, Niranjana #include "opa_vnic_internal.h" 587d6f728cSVishwanathapura, Niranjana 597d6f728cSVishwanathapura, Niranjana #define OPA_TX_TIMEOUT_MS 1000 607d6f728cSVishwanathapura, Niranjana 617d6f728cSVishwanathapura, Niranjana #define OPA_VNIC_SKB_HEADROOM \ 627d6f728cSVishwanathapura, Niranjana ALIGN((OPA_VNIC_HDR_LEN + OPA_VNIC_SKB_MDATA_LEN), 8) 637d6f728cSVishwanathapura, Niranjana 64009b7dd4SVishwanathapura, Niranjana /* This function is overloaded for opa_vnic specific implementation */ 65009b7dd4SVishwanathapura, Niranjana static void opa_vnic_get_stats64(struct net_device *netdev, 66009b7dd4SVishwanathapura, Niranjana struct rtnl_link_stats64 *stats) 67009b7dd4SVishwanathapura, Niranjana { 68009b7dd4SVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev); 69009b7dd4SVishwanathapura, Niranjana struct opa_vnic_stats vstats; 70009b7dd4SVishwanathapura, Niranjana 71009b7dd4SVishwanathapura, Niranjana memset(&vstats, 0, sizeof(vstats)); 72a379d69fSVishwanathapura, Niranjana spin_lock(&adapter->stats_lock); 73009b7dd4SVishwanathapura, Niranjana adapter->rn_ops->ndo_get_stats64(netdev, &vstats.netstats); 74a379d69fSVishwanathapura, Niranjana spin_unlock(&adapter->stats_lock); 75009b7dd4SVishwanathapura, Niranjana memcpy(stats, &vstats.netstats, sizeof(*stats)); 76009b7dd4SVishwanathapura, Niranjana } 77009b7dd4SVishwanathapura, Niranjana 787d6f728cSVishwanathapura, Niranjana /* opa_netdev_start_xmit - transmit function */ 797d6f728cSVishwanathapura, Niranjana static netdev_tx_t opa_netdev_start_xmit(struct sk_buff *skb, 807d6f728cSVishwanathapura, Niranjana struct net_device *netdev) 817d6f728cSVishwanathapura, Niranjana { 827d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev); 837d6f728cSVishwanathapura, Niranjana 847d6f728cSVishwanathapura, Niranjana v_dbg("xmit: queue %d skb len %d\n", skb->queue_mapping, skb->len); 857d6f728cSVishwanathapura, Niranjana /* pad to ensure mininum ethernet packet length */ 867d6f728cSVishwanathapura, Niranjana if (unlikely(skb->len < ETH_ZLEN)) { 877d6f728cSVishwanathapura, Niranjana if (skb_padto(skb, ETH_ZLEN)) 887d6f728cSVishwanathapura, Niranjana return NETDEV_TX_OK; 897d6f728cSVishwanathapura, Niranjana 907d6f728cSVishwanathapura, Niranjana skb_put(skb, ETH_ZLEN - skb->len); 917d6f728cSVishwanathapura, Niranjana } 927d6f728cSVishwanathapura, Niranjana 937d6f728cSVishwanathapura, Niranjana opa_vnic_encap_skb(adapter, skb); 947d6f728cSVishwanathapura, Niranjana return adapter->rn_ops->ndo_start_xmit(skb, netdev); 957d6f728cSVishwanathapura, Niranjana } 967d6f728cSVishwanathapura, Niranjana 977d6f728cSVishwanathapura, Niranjana static u16 opa_vnic_select_queue(struct net_device *netdev, struct sk_buff *skb, 984f49dec9SAlexander Duyck struct net_device *sb_dev, 997d6f728cSVishwanathapura, Niranjana select_queue_fallback_t fallback) 1007d6f728cSVishwanathapura, Niranjana { 1017d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev); 1027d6f728cSVishwanathapura, Niranjana struct opa_vnic_skb_mdata *mdata; 1037d6f728cSVishwanathapura, Niranjana int rc; 1047d6f728cSVishwanathapura, Niranjana 1057d6f728cSVishwanathapura, Niranjana /* pass entropy and vl as metadata in skb */ 106d58ff351SJohannes Berg mdata = skb_push(skb, sizeof(*mdata)); 107d80d8d55SAlexander Duyck mdata->entropy = opa_vnic_calc_entropy(skb); 1087d6f728cSVishwanathapura, Niranjana mdata->vl = opa_vnic_get_vl(adapter, skb); 1097d6f728cSVishwanathapura, Niranjana rc = adapter->rn_ops->ndo_select_queue(netdev, skb, 1104f49dec9SAlexander Duyck sb_dev, fallback); 1117d6f728cSVishwanathapura, Niranjana skb_pull(skb, sizeof(*mdata)); 1127d6f728cSVishwanathapura, Niranjana return rc; 1137d6f728cSVishwanathapura, Niranjana } 1147d6f728cSVishwanathapura, Niranjana 115e82b7c38SNiranjana Vishwanathapura static void opa_vnic_update_state(struct opa_vnic_adapter *adapter, bool up) 116e82b7c38SNiranjana Vishwanathapura { 117e82b7c38SNiranjana Vishwanathapura struct __opa_veswport_info *info = &adapter->info; 118e82b7c38SNiranjana Vishwanathapura 119e82b7c38SNiranjana Vishwanathapura mutex_lock(&adapter->lock); 120e82b7c38SNiranjana Vishwanathapura /* Operational state can only be DROP_ALL or FORWARDING */ 121e82b7c38SNiranjana Vishwanathapura if ((info->vport.config_state == OPA_VNIC_STATE_FORWARDING) && up) { 122e82b7c38SNiranjana Vishwanathapura info->vport.oper_state = OPA_VNIC_STATE_FORWARDING; 123e82b7c38SNiranjana Vishwanathapura info->vport.eth_link_status = OPA_VNIC_ETH_LINK_UP; 124e82b7c38SNiranjana Vishwanathapura } else { 125e82b7c38SNiranjana Vishwanathapura info->vport.oper_state = OPA_VNIC_STATE_DROP_ALL; 126e82b7c38SNiranjana Vishwanathapura info->vport.eth_link_status = OPA_VNIC_ETH_LINK_DOWN; 127e82b7c38SNiranjana Vishwanathapura } 128e82b7c38SNiranjana Vishwanathapura 129e82b7c38SNiranjana Vishwanathapura if (info->vport.config_state == OPA_VNIC_STATE_FORWARDING) 130e82b7c38SNiranjana Vishwanathapura netif_dormant_off(adapter->netdev); 131e82b7c38SNiranjana Vishwanathapura else 132e82b7c38SNiranjana Vishwanathapura netif_dormant_on(adapter->netdev); 133e82b7c38SNiranjana Vishwanathapura mutex_unlock(&adapter->lock); 134e82b7c38SNiranjana Vishwanathapura } 135e82b7c38SNiranjana Vishwanathapura 136cfd34f8eSVishwanathapura, Niranjana /* opa_vnic_process_vema_config - process vema configuration updates */ 137cfd34f8eSVishwanathapura, Niranjana void opa_vnic_process_vema_config(struct opa_vnic_adapter *adapter) 138cfd34f8eSVishwanathapura, Niranjana { 139cfd34f8eSVishwanathapura, Niranjana struct __opa_veswport_info *info = &adapter->info; 140cfd34f8eSVishwanathapura, Niranjana struct rdma_netdev *rn = netdev_priv(adapter->netdev); 141cfd34f8eSVishwanathapura, Niranjana u8 port_num[OPA_VESW_MAX_NUM_DEF_PORT] = { 0 }; 142cfd34f8eSVishwanathapura, Niranjana struct net_device *netdev = adapter->netdev; 143cfd34f8eSVishwanathapura, Niranjana u8 i, port_count = 0; 144cfd34f8eSVishwanathapura, Niranjana u16 port_mask; 145cfd34f8eSVishwanathapura, Niranjana 146cfd34f8eSVishwanathapura, Niranjana /* If the base_mac_addr is changed, update the interface mac address */ 147cfd34f8eSVishwanathapura, Niranjana if (memcmp(info->vport.base_mac_addr, adapter->vema_mac_addr, 148cfd34f8eSVishwanathapura, Niranjana ARRAY_SIZE(info->vport.base_mac_addr))) { 149cfd34f8eSVishwanathapura, Niranjana struct sockaddr saddr; 150cfd34f8eSVishwanathapura, Niranjana 151cfd34f8eSVishwanathapura, Niranjana memcpy(saddr.sa_data, info->vport.base_mac_addr, 152cfd34f8eSVishwanathapura, Niranjana ARRAY_SIZE(info->vport.base_mac_addr)); 153cfd34f8eSVishwanathapura, Niranjana mutex_lock(&adapter->lock); 1545a5a85daSNiranjana Vishwanathapura eth_commit_mac_addr_change(netdev, &saddr); 155cfd34f8eSVishwanathapura, Niranjana memcpy(adapter->vema_mac_addr, 156cfd34f8eSVishwanathapura, Niranjana info->vport.base_mac_addr, ETH_ALEN); 157cfd34f8eSVishwanathapura, Niranjana mutex_unlock(&adapter->lock); 158cfd34f8eSVishwanathapura, Niranjana } 159cfd34f8eSVishwanathapura, Niranjana 160cfd34f8eSVishwanathapura, Niranjana rn->set_id(netdev, info->vesw.vesw_id); 161cfd34f8eSVishwanathapura, Niranjana 162cfd34f8eSVishwanathapura, Niranjana /* Handle MTU limit change */ 163cfd34f8eSVishwanathapura, Niranjana rtnl_lock(); 16462f1e84eSNiranjana Vishwanathapura netdev->max_mtu = max_t(unsigned int, info->vesw.eth_mtu, 165cfd34f8eSVishwanathapura, Niranjana netdev->min_mtu); 166cfd34f8eSVishwanathapura, Niranjana if (netdev->mtu > netdev->max_mtu) 167cfd34f8eSVishwanathapura, Niranjana dev_set_mtu(netdev, netdev->max_mtu); 168cfd34f8eSVishwanathapura, Niranjana rtnl_unlock(); 169cfd34f8eSVishwanathapura, Niranjana 170cfd34f8eSVishwanathapura, Niranjana /* Update flow to default port redirection table */ 171cfd34f8eSVishwanathapura, Niranjana port_mask = info->vesw.def_port_mask; 172cfd34f8eSVishwanathapura, Niranjana for (i = 0; i < OPA_VESW_MAX_NUM_DEF_PORT; i++) { 173cfd34f8eSVishwanathapura, Niranjana if (port_mask & 1) 174cfd34f8eSVishwanathapura, Niranjana port_num[port_count++] = i; 175cfd34f8eSVishwanathapura, Niranjana port_mask >>= 1; 176cfd34f8eSVishwanathapura, Niranjana } 177cfd34f8eSVishwanathapura, Niranjana 178cfd34f8eSVishwanathapura, Niranjana /* 179cfd34f8eSVishwanathapura, Niranjana * Build the flow table. Flow table is required when destination LID 180cfd34f8eSVishwanathapura, Niranjana * is not available. Up to OPA_VNIC_FLOW_TBL_SIZE flows supported. 181cfd34f8eSVishwanathapura, Niranjana * Each flow need a default port number to get its dlid from the 182cfd34f8eSVishwanathapura, Niranjana * u_ucast_dlid array. 183cfd34f8eSVishwanathapura, Niranjana */ 184cfd34f8eSVishwanathapura, Niranjana for (i = 0; i < OPA_VNIC_FLOW_TBL_SIZE; i++) 185cfd34f8eSVishwanathapura, Niranjana adapter->flow_tbl[i] = port_count ? port_num[i % port_count] : 186cfd34f8eSVishwanathapura, Niranjana OPA_VNIC_INVALID_PORT; 187cfd34f8eSVishwanathapura, Niranjana 188e82b7c38SNiranjana Vishwanathapura /* update state */ 189e82b7c38SNiranjana Vishwanathapura opa_vnic_update_state(adapter, !!(netdev->flags & IFF_UP)); 190cfd34f8eSVishwanathapura, Niranjana } 191cfd34f8eSVishwanathapura, Niranjana 192cfd34f8eSVishwanathapura, Niranjana /* 193cfd34f8eSVishwanathapura, Niranjana * Set the power on default values in adapter's vema interface structure. 194cfd34f8eSVishwanathapura, Niranjana */ 195cfd34f8eSVishwanathapura, Niranjana static inline void opa_vnic_set_pod_values(struct opa_vnic_adapter *adapter) 196cfd34f8eSVishwanathapura, Niranjana { 197cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.max_mac_tbl_ent = OPA_VNIC_MAC_TBL_MAX_ENTRIES; 198cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.max_smac_ent = OPA_VNIC_MAX_SMAC_LIMIT; 199cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.config_state = OPA_VNIC_STATE_DROP_ALL; 200cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.eth_link_status = OPA_VNIC_ETH_LINK_DOWN; 2017f291d28SNiranjana Vishwanathapura adapter->info.vesw.eth_mtu = ETH_DATA_LEN; 202cfd34f8eSVishwanathapura, Niranjana } 203cfd34f8eSVishwanathapura, Niranjana 2047d6f728cSVishwanathapura, Niranjana /* opa_vnic_set_mac_addr - change mac address */ 2057d6f728cSVishwanathapura, Niranjana static int opa_vnic_set_mac_addr(struct net_device *netdev, void *addr) 2067d6f728cSVishwanathapura, Niranjana { 2077d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev); 2087d6f728cSVishwanathapura, Niranjana struct sockaddr *sa = addr; 2097d6f728cSVishwanathapura, Niranjana int rc; 2107d6f728cSVishwanathapura, Niranjana 2117d6f728cSVishwanathapura, Niranjana if (!memcmp(netdev->dev_addr, sa->sa_data, ETH_ALEN)) 2127d6f728cSVishwanathapura, Niranjana return 0; 2137d6f728cSVishwanathapura, Niranjana 2147d6f728cSVishwanathapura, Niranjana mutex_lock(&adapter->lock); 2157d6f728cSVishwanathapura, Niranjana rc = eth_mac_addr(netdev, addr); 2167d6f728cSVishwanathapura, Niranjana mutex_unlock(&adapter->lock); 217cfd34f8eSVishwanathapura, Niranjana if (rc) 2187d6f728cSVishwanathapura, Niranjana return rc; 219cfd34f8eSVishwanathapura, Niranjana 220cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.uc_macs_gen_count++; 221cfd34f8eSVishwanathapura, Niranjana opa_vnic_vema_report_event(adapter, 222cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_IFACE_UCAST_MAC_CHANGE); 223cfd34f8eSVishwanathapura, Niranjana return 0; 224cfd34f8eSVishwanathapura, Niranjana } 225cfd34f8eSVishwanathapura, Niranjana 226cfd34f8eSVishwanathapura, Niranjana /* 227cfd34f8eSVishwanathapura, Niranjana * opa_vnic_mac_send_event - post event on possible mac list exchange 228cfd34f8eSVishwanathapura, Niranjana * Send trap when digest from uc/mc mac list differs from previous run. 229cfd34f8eSVishwanathapura, Niranjana * Digest is evaluated similar to how cksum does. 230cfd34f8eSVishwanathapura, Niranjana */ 231cfd34f8eSVishwanathapura, Niranjana static void opa_vnic_mac_send_event(struct net_device *netdev, u8 event) 232cfd34f8eSVishwanathapura, Niranjana { 233cfd34f8eSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev); 234cfd34f8eSVishwanathapura, Niranjana struct netdev_hw_addr *ha; 235cfd34f8eSVishwanathapura, Niranjana struct netdev_hw_addr_list *hw_list; 236cfd34f8eSVishwanathapura, Niranjana u32 *ref_crc; 237cfd34f8eSVishwanathapura, Niranjana u32 l, crc = 0; 238cfd34f8eSVishwanathapura, Niranjana 239cfd34f8eSVishwanathapura, Niranjana switch (event) { 240cfd34f8eSVishwanathapura, Niranjana case OPA_VESWPORT_TRAP_IFACE_UCAST_MAC_CHANGE: 241cfd34f8eSVishwanathapura, Niranjana hw_list = &netdev->uc; 242cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.uc_macs_gen_count++; 243cfd34f8eSVishwanathapura, Niranjana ref_crc = &adapter->umac_hash; 244cfd34f8eSVishwanathapura, Niranjana break; 245cfd34f8eSVishwanathapura, Niranjana case OPA_VESWPORT_TRAP_IFACE_MCAST_MAC_CHANGE: 246cfd34f8eSVishwanathapura, Niranjana hw_list = &netdev->mc; 247cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.mc_macs_gen_count++; 248cfd34f8eSVishwanathapura, Niranjana ref_crc = &adapter->mmac_hash; 249cfd34f8eSVishwanathapura, Niranjana break; 250cfd34f8eSVishwanathapura, Niranjana default: 251cfd34f8eSVishwanathapura, Niranjana return; 252cfd34f8eSVishwanathapura, Niranjana } 253cfd34f8eSVishwanathapura, Niranjana netdev_hw_addr_list_for_each(ha, hw_list) { 254cfd34f8eSVishwanathapura, Niranjana crc = crc32_le(crc, ha->addr, ETH_ALEN); 255cfd34f8eSVishwanathapura, Niranjana } 256cfd34f8eSVishwanathapura, Niranjana l = netdev_hw_addr_list_count(hw_list) * ETH_ALEN; 257cfd34f8eSVishwanathapura, Niranjana crc = ~crc32_le(crc, (void *)&l, sizeof(l)); 258cfd34f8eSVishwanathapura, Niranjana 259cfd34f8eSVishwanathapura, Niranjana if (crc != *ref_crc) { 260cfd34f8eSVishwanathapura, Niranjana *ref_crc = crc; 261cfd34f8eSVishwanathapura, Niranjana opa_vnic_vema_report_event(adapter, event); 262cfd34f8eSVishwanathapura, Niranjana } 263cfd34f8eSVishwanathapura, Niranjana } 264cfd34f8eSVishwanathapura, Niranjana 265cfd34f8eSVishwanathapura, Niranjana /* opa_vnic_set_rx_mode - handle uc/mc mac list change */ 266cfd34f8eSVishwanathapura, Niranjana static void opa_vnic_set_rx_mode(struct net_device *netdev) 267cfd34f8eSVishwanathapura, Niranjana { 268cfd34f8eSVishwanathapura, Niranjana opa_vnic_mac_send_event(netdev, 269cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_IFACE_UCAST_MAC_CHANGE); 270cfd34f8eSVishwanathapura, Niranjana 271cfd34f8eSVishwanathapura, Niranjana opa_vnic_mac_send_event(netdev, 272cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_IFACE_MCAST_MAC_CHANGE); 2737d6f728cSVishwanathapura, Niranjana } 2747d6f728cSVishwanathapura, Niranjana 2757d6f728cSVishwanathapura, Niranjana /* opa_netdev_open - activate network interface */ 2767d6f728cSVishwanathapura, Niranjana static int opa_netdev_open(struct net_device *netdev) 2777d6f728cSVishwanathapura, Niranjana { 2787d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev); 2797d6f728cSVishwanathapura, Niranjana int rc; 2807d6f728cSVishwanathapura, Niranjana 2817d6f728cSVishwanathapura, Niranjana rc = adapter->rn_ops->ndo_open(adapter->netdev); 2827d6f728cSVishwanathapura, Niranjana if (rc) { 2837d6f728cSVishwanathapura, Niranjana v_dbg("open failed %d\n", rc); 2847d6f728cSVishwanathapura, Niranjana return rc; 2857d6f728cSVishwanathapura, Niranjana } 2867d6f728cSVishwanathapura, Niranjana 287e82b7c38SNiranjana Vishwanathapura /* Update status and send trap */ 288e82b7c38SNiranjana Vishwanathapura opa_vnic_update_state(adapter, true); 289cfd34f8eSVishwanathapura, Niranjana opa_vnic_vema_report_event(adapter, 290cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_ETH_LINK_STATUS_CHANGE); 2917d6f728cSVishwanathapura, Niranjana return 0; 2927d6f728cSVishwanathapura, Niranjana } 2937d6f728cSVishwanathapura, Niranjana 2947d6f728cSVishwanathapura, Niranjana /* opa_netdev_close - disable network interface */ 2957d6f728cSVishwanathapura, Niranjana static int opa_netdev_close(struct net_device *netdev) 2967d6f728cSVishwanathapura, Niranjana { 2977d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev); 2987d6f728cSVishwanathapura, Niranjana int rc; 2997d6f728cSVishwanathapura, Niranjana 3007d6f728cSVishwanathapura, Niranjana rc = adapter->rn_ops->ndo_stop(adapter->netdev); 3017d6f728cSVishwanathapura, Niranjana if (rc) { 3027d6f728cSVishwanathapura, Niranjana v_dbg("close failed %d\n", rc); 3037d6f728cSVishwanathapura, Niranjana return rc; 3047d6f728cSVishwanathapura, Niranjana } 3057d6f728cSVishwanathapura, Niranjana 306e82b7c38SNiranjana Vishwanathapura /* Update status and send trap */ 307e82b7c38SNiranjana Vishwanathapura opa_vnic_update_state(adapter, false); 308cfd34f8eSVishwanathapura, Niranjana opa_vnic_vema_report_event(adapter, 309cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_ETH_LINK_STATUS_CHANGE); 3107d6f728cSVishwanathapura, Niranjana return 0; 3117d6f728cSVishwanathapura, Niranjana } 3127d6f728cSVishwanathapura, Niranjana 3137d6f728cSVishwanathapura, Niranjana /* netdev ops */ 3147d6f728cSVishwanathapura, Niranjana static const struct net_device_ops opa_netdev_ops = { 3157d6f728cSVishwanathapura, Niranjana .ndo_open = opa_netdev_open, 3167d6f728cSVishwanathapura, Niranjana .ndo_stop = opa_netdev_close, 3177d6f728cSVishwanathapura, Niranjana .ndo_start_xmit = opa_netdev_start_xmit, 318009b7dd4SVishwanathapura, Niranjana .ndo_get_stats64 = opa_vnic_get_stats64, 319cfd34f8eSVishwanathapura, Niranjana .ndo_set_rx_mode = opa_vnic_set_rx_mode, 3207d6f728cSVishwanathapura, Niranjana .ndo_select_queue = opa_vnic_select_queue, 3217d6f728cSVishwanathapura, Niranjana .ndo_set_mac_address = opa_vnic_set_mac_addr, 3227d6f728cSVishwanathapura, Niranjana }; 3237d6f728cSVishwanathapura, Niranjana 3247d6f728cSVishwanathapura, Niranjana /* opa_vnic_add_netdev - create vnic netdev interface */ 3257d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *opa_vnic_add_netdev(struct ib_device *ibdev, 3267d6f728cSVishwanathapura, Niranjana u8 port_num, u8 vport_num) 3277d6f728cSVishwanathapura, Niranjana { 3287d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter; 3297d6f728cSVishwanathapura, Niranjana struct net_device *netdev; 3307d6f728cSVishwanathapura, Niranjana struct rdma_netdev *rn; 3317d6f728cSVishwanathapura, Niranjana int rc; 3327d6f728cSVishwanathapura, Niranjana 3333023a1e9SKamal Heib netdev = ibdev->ops.alloc_rdma_netdev(ibdev, port_num, 3347d6f728cSVishwanathapura, Niranjana RDMA_NETDEV_OPA_VNIC, 3357d6f728cSVishwanathapura, Niranjana "veth%d", NET_NAME_UNKNOWN, 3367d6f728cSVishwanathapura, Niranjana ether_setup); 3377d6f728cSVishwanathapura, Niranjana if (!netdev) 3387d6f728cSVishwanathapura, Niranjana return ERR_PTR(-ENOMEM); 3397d6f728cSVishwanathapura, Niranjana else if (IS_ERR(netdev)) 3407d6f728cSVishwanathapura, Niranjana return ERR_CAST(netdev); 3417d6f728cSVishwanathapura, Niranjana 3428e959601SNiranjana Vishwanathapura rn = netdev_priv(netdev); 3437d6f728cSVishwanathapura, Niranjana adapter = kzalloc(sizeof(*adapter), GFP_KERNEL); 3447d6f728cSVishwanathapura, Niranjana if (!adapter) { 3457d6f728cSVishwanathapura, Niranjana rc = -ENOMEM; 3467d6f728cSVishwanathapura, Niranjana goto adapter_err; 3477d6f728cSVishwanathapura, Niranjana } 3487d6f728cSVishwanathapura, Niranjana 3497d6f728cSVishwanathapura, Niranjana rn->clnt_priv = adapter; 3507d6f728cSVishwanathapura, Niranjana rn->hca = ibdev; 3517d6f728cSVishwanathapura, Niranjana rn->port_num = port_num; 3527d6f728cSVishwanathapura, Niranjana adapter->netdev = netdev; 3537d6f728cSVishwanathapura, Niranjana adapter->ibdev = ibdev; 3547d6f728cSVishwanathapura, Niranjana adapter->port_num = port_num; 3557d6f728cSVishwanathapura, Niranjana adapter->vport_num = vport_num; 3567d6f728cSVishwanathapura, Niranjana adapter->rn_ops = netdev->netdev_ops; 3577d6f728cSVishwanathapura, Niranjana 3587d6f728cSVishwanathapura, Niranjana netdev->netdev_ops = &opa_netdev_ops; 3597d6f728cSVishwanathapura, Niranjana netdev->priv_flags |= IFF_LIVE_ADDR_CHANGE; 3607d6f728cSVishwanathapura, Niranjana netdev->hard_header_len += OPA_VNIC_SKB_HEADROOM; 3617d6f728cSVishwanathapura, Niranjana mutex_init(&adapter->lock); 362174e03d7SVishwanathapura, Niranjana mutex_init(&adapter->mactbl_lock); 363a379d69fSVishwanathapura, Niranjana spin_lock_init(&adapter->stats_lock); 3647d6f728cSVishwanathapura, Niranjana 3657d6f728cSVishwanathapura, Niranjana SET_NETDEV_DEV(netdev, ibdev->dev.parent); 3667d6f728cSVishwanathapura, Niranjana 3677d6f728cSVishwanathapura, Niranjana opa_vnic_set_ethtool_ops(netdev); 368cfd34f8eSVishwanathapura, Niranjana 369cfd34f8eSVishwanathapura, Niranjana opa_vnic_set_pod_values(adapter); 370cfd34f8eSVishwanathapura, Niranjana 3717d6f728cSVishwanathapura, Niranjana rc = register_netdev(netdev); 3727d6f728cSVishwanathapura, Niranjana if (rc) 3737d6f728cSVishwanathapura, Niranjana goto netdev_err; 3747d6f728cSVishwanathapura, Niranjana 3757d6f728cSVishwanathapura, Niranjana netif_carrier_off(netdev); 3767d6f728cSVishwanathapura, Niranjana netif_dormant_on(netdev); 3777d6f728cSVishwanathapura, Niranjana v_info("initialized\n"); 3787d6f728cSVishwanathapura, Niranjana 3797d6f728cSVishwanathapura, Niranjana return adapter; 3807d6f728cSVishwanathapura, Niranjana netdev_err: 3817d6f728cSVishwanathapura, Niranjana mutex_destroy(&adapter->lock); 382174e03d7SVishwanathapura, Niranjana mutex_destroy(&adapter->mactbl_lock); 3837d6f728cSVishwanathapura, Niranjana kfree(adapter); 3847d6f728cSVishwanathapura, Niranjana adapter_err: 3858e959601SNiranjana Vishwanathapura rn->free_rdma_netdev(netdev); 3867d6f728cSVishwanathapura, Niranjana 3877d6f728cSVishwanathapura, Niranjana return ERR_PTR(rc); 3887d6f728cSVishwanathapura, Niranjana } 3897d6f728cSVishwanathapura, Niranjana 3907d6f728cSVishwanathapura, Niranjana /* opa_vnic_rem_netdev - remove vnic netdev interface */ 3917d6f728cSVishwanathapura, Niranjana void opa_vnic_rem_netdev(struct opa_vnic_adapter *adapter) 3927d6f728cSVishwanathapura, Niranjana { 3937d6f728cSVishwanathapura, Niranjana struct net_device *netdev = adapter->netdev; 3948e959601SNiranjana Vishwanathapura struct rdma_netdev *rn = netdev_priv(netdev); 3957d6f728cSVishwanathapura, Niranjana 3967d6f728cSVishwanathapura, Niranjana v_info("removing\n"); 3977d6f728cSVishwanathapura, Niranjana unregister_netdev(netdev); 398174e03d7SVishwanathapura, Niranjana opa_vnic_release_mac_tbl(adapter); 3997d6f728cSVishwanathapura, Niranjana mutex_destroy(&adapter->lock); 400174e03d7SVishwanathapura, Niranjana mutex_destroy(&adapter->mactbl_lock); 4017d6f728cSVishwanathapura, Niranjana kfree(adapter); 4028e959601SNiranjana Vishwanathapura rn->free_rdma_netdev(netdev); 4037d6f728cSVishwanathapura, Niranjana } 404