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, 98a350ecceSPaolo Abeni struct net_device *sb_dev) 997d6f728cSVishwanathapura, Niranjana { 1007d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev); 1017d6f728cSVishwanathapura, Niranjana struct opa_vnic_skb_mdata *mdata; 1027d6f728cSVishwanathapura, Niranjana int rc; 1037d6f728cSVishwanathapura, Niranjana 1047d6f728cSVishwanathapura, Niranjana /* pass entropy and vl as metadata in skb */ 105d58ff351SJohannes Berg mdata = skb_push(skb, sizeof(*mdata)); 106d80d8d55SAlexander Duyck mdata->entropy = opa_vnic_calc_entropy(skb); 1077d6f728cSVishwanathapura, Niranjana mdata->vl = opa_vnic_get_vl(adapter, skb); 108a350ecceSPaolo Abeni rc = adapter->rn_ops->ndo_select_queue(netdev, skb, sb_dev); 1097d6f728cSVishwanathapura, Niranjana skb_pull(skb, sizeof(*mdata)); 1107d6f728cSVishwanathapura, Niranjana return rc; 1117d6f728cSVishwanathapura, Niranjana } 1127d6f728cSVishwanathapura, Niranjana 113e82b7c38SNiranjana Vishwanathapura static void opa_vnic_update_state(struct opa_vnic_adapter *adapter, bool up) 114e82b7c38SNiranjana Vishwanathapura { 115e82b7c38SNiranjana Vishwanathapura struct __opa_veswport_info *info = &adapter->info; 116e82b7c38SNiranjana Vishwanathapura 117e82b7c38SNiranjana Vishwanathapura mutex_lock(&adapter->lock); 118e82b7c38SNiranjana Vishwanathapura /* Operational state can only be DROP_ALL or FORWARDING */ 119e82b7c38SNiranjana Vishwanathapura if ((info->vport.config_state == OPA_VNIC_STATE_FORWARDING) && up) { 120e82b7c38SNiranjana Vishwanathapura info->vport.oper_state = OPA_VNIC_STATE_FORWARDING; 121e82b7c38SNiranjana Vishwanathapura info->vport.eth_link_status = OPA_VNIC_ETH_LINK_UP; 122e82b7c38SNiranjana Vishwanathapura } else { 123e82b7c38SNiranjana Vishwanathapura info->vport.oper_state = OPA_VNIC_STATE_DROP_ALL; 124e82b7c38SNiranjana Vishwanathapura info->vport.eth_link_status = OPA_VNIC_ETH_LINK_DOWN; 125e82b7c38SNiranjana Vishwanathapura } 126e82b7c38SNiranjana Vishwanathapura 127e82b7c38SNiranjana Vishwanathapura if (info->vport.config_state == OPA_VNIC_STATE_FORWARDING) 128e82b7c38SNiranjana Vishwanathapura netif_dormant_off(adapter->netdev); 129e82b7c38SNiranjana Vishwanathapura else 130e82b7c38SNiranjana Vishwanathapura netif_dormant_on(adapter->netdev); 131e82b7c38SNiranjana Vishwanathapura mutex_unlock(&adapter->lock); 132e82b7c38SNiranjana Vishwanathapura } 133e82b7c38SNiranjana Vishwanathapura 134cfd34f8eSVishwanathapura, Niranjana /* opa_vnic_process_vema_config - process vema configuration updates */ 135cfd34f8eSVishwanathapura, Niranjana void opa_vnic_process_vema_config(struct opa_vnic_adapter *adapter) 136cfd34f8eSVishwanathapura, Niranjana { 137cfd34f8eSVishwanathapura, Niranjana struct __opa_veswport_info *info = &adapter->info; 138cfd34f8eSVishwanathapura, Niranjana struct rdma_netdev *rn = netdev_priv(adapter->netdev); 139cfd34f8eSVishwanathapura, Niranjana u8 port_num[OPA_VESW_MAX_NUM_DEF_PORT] = { 0 }; 140cfd34f8eSVishwanathapura, Niranjana struct net_device *netdev = adapter->netdev; 141cfd34f8eSVishwanathapura, Niranjana u8 i, port_count = 0; 142cfd34f8eSVishwanathapura, Niranjana u16 port_mask; 143cfd34f8eSVishwanathapura, Niranjana 144cfd34f8eSVishwanathapura, Niranjana /* If the base_mac_addr is changed, update the interface mac address */ 145cfd34f8eSVishwanathapura, Niranjana if (memcmp(info->vport.base_mac_addr, adapter->vema_mac_addr, 146cfd34f8eSVishwanathapura, Niranjana ARRAY_SIZE(info->vport.base_mac_addr))) { 147cfd34f8eSVishwanathapura, Niranjana struct sockaddr saddr; 148cfd34f8eSVishwanathapura, Niranjana 149cfd34f8eSVishwanathapura, Niranjana memcpy(saddr.sa_data, info->vport.base_mac_addr, 150cfd34f8eSVishwanathapura, Niranjana ARRAY_SIZE(info->vport.base_mac_addr)); 151cfd34f8eSVishwanathapura, Niranjana mutex_lock(&adapter->lock); 1525a5a85daSNiranjana Vishwanathapura eth_commit_mac_addr_change(netdev, &saddr); 153cfd34f8eSVishwanathapura, Niranjana memcpy(adapter->vema_mac_addr, 154cfd34f8eSVishwanathapura, Niranjana info->vport.base_mac_addr, ETH_ALEN); 155cfd34f8eSVishwanathapura, Niranjana mutex_unlock(&adapter->lock); 156cfd34f8eSVishwanathapura, Niranjana } 157cfd34f8eSVishwanathapura, Niranjana 158cfd34f8eSVishwanathapura, Niranjana rn->set_id(netdev, info->vesw.vesw_id); 159cfd34f8eSVishwanathapura, Niranjana 160cfd34f8eSVishwanathapura, Niranjana /* Handle MTU limit change */ 161cfd34f8eSVishwanathapura, Niranjana rtnl_lock(); 16262f1e84eSNiranjana Vishwanathapura netdev->max_mtu = max_t(unsigned int, info->vesw.eth_mtu, 163cfd34f8eSVishwanathapura, Niranjana netdev->min_mtu); 164cfd34f8eSVishwanathapura, Niranjana if (netdev->mtu > netdev->max_mtu) 165cfd34f8eSVishwanathapura, Niranjana dev_set_mtu(netdev, netdev->max_mtu); 166cfd34f8eSVishwanathapura, Niranjana rtnl_unlock(); 167cfd34f8eSVishwanathapura, Niranjana 168cfd34f8eSVishwanathapura, Niranjana /* Update flow to default port redirection table */ 169cfd34f8eSVishwanathapura, Niranjana port_mask = info->vesw.def_port_mask; 170cfd34f8eSVishwanathapura, Niranjana for (i = 0; i < OPA_VESW_MAX_NUM_DEF_PORT; i++) { 171cfd34f8eSVishwanathapura, Niranjana if (port_mask & 1) 172cfd34f8eSVishwanathapura, Niranjana port_num[port_count++] = i; 173cfd34f8eSVishwanathapura, Niranjana port_mask >>= 1; 174cfd34f8eSVishwanathapura, Niranjana } 175cfd34f8eSVishwanathapura, Niranjana 176cfd34f8eSVishwanathapura, Niranjana /* 177cfd34f8eSVishwanathapura, Niranjana * Build the flow table. Flow table is required when destination LID 178cfd34f8eSVishwanathapura, Niranjana * is not available. Up to OPA_VNIC_FLOW_TBL_SIZE flows supported. 179cfd34f8eSVishwanathapura, Niranjana * Each flow need a default port number to get its dlid from the 180cfd34f8eSVishwanathapura, Niranjana * u_ucast_dlid array. 181cfd34f8eSVishwanathapura, Niranjana */ 182cfd34f8eSVishwanathapura, Niranjana for (i = 0; i < OPA_VNIC_FLOW_TBL_SIZE; i++) 183cfd34f8eSVishwanathapura, Niranjana adapter->flow_tbl[i] = port_count ? port_num[i % port_count] : 184cfd34f8eSVishwanathapura, Niranjana OPA_VNIC_INVALID_PORT; 185cfd34f8eSVishwanathapura, Niranjana 186e82b7c38SNiranjana Vishwanathapura /* update state */ 187e82b7c38SNiranjana Vishwanathapura opa_vnic_update_state(adapter, !!(netdev->flags & IFF_UP)); 188cfd34f8eSVishwanathapura, Niranjana } 189cfd34f8eSVishwanathapura, Niranjana 190cfd34f8eSVishwanathapura, Niranjana /* 191cfd34f8eSVishwanathapura, Niranjana * Set the power on default values in adapter's vema interface structure. 192cfd34f8eSVishwanathapura, Niranjana */ 193cfd34f8eSVishwanathapura, Niranjana static inline void opa_vnic_set_pod_values(struct opa_vnic_adapter *adapter) 194cfd34f8eSVishwanathapura, Niranjana { 195cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.max_mac_tbl_ent = OPA_VNIC_MAC_TBL_MAX_ENTRIES; 196cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.max_smac_ent = OPA_VNIC_MAX_SMAC_LIMIT; 197cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.config_state = OPA_VNIC_STATE_DROP_ALL; 198cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.eth_link_status = OPA_VNIC_ETH_LINK_DOWN; 1997f291d28SNiranjana Vishwanathapura adapter->info.vesw.eth_mtu = ETH_DATA_LEN; 200cfd34f8eSVishwanathapura, Niranjana } 201cfd34f8eSVishwanathapura, Niranjana 2027d6f728cSVishwanathapura, Niranjana /* opa_vnic_set_mac_addr - change mac address */ 2037d6f728cSVishwanathapura, Niranjana static int opa_vnic_set_mac_addr(struct net_device *netdev, void *addr) 2047d6f728cSVishwanathapura, Niranjana { 2057d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev); 2067d6f728cSVishwanathapura, Niranjana struct sockaddr *sa = addr; 2077d6f728cSVishwanathapura, Niranjana int rc; 2087d6f728cSVishwanathapura, Niranjana 2097d6f728cSVishwanathapura, Niranjana if (!memcmp(netdev->dev_addr, sa->sa_data, ETH_ALEN)) 2107d6f728cSVishwanathapura, Niranjana return 0; 2117d6f728cSVishwanathapura, Niranjana 2127d6f728cSVishwanathapura, Niranjana mutex_lock(&adapter->lock); 2137d6f728cSVishwanathapura, Niranjana rc = eth_mac_addr(netdev, addr); 2147d6f728cSVishwanathapura, Niranjana mutex_unlock(&adapter->lock); 215cfd34f8eSVishwanathapura, Niranjana if (rc) 2167d6f728cSVishwanathapura, Niranjana return rc; 217cfd34f8eSVishwanathapura, Niranjana 218cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.uc_macs_gen_count++; 219cfd34f8eSVishwanathapura, Niranjana opa_vnic_vema_report_event(adapter, 220cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_IFACE_UCAST_MAC_CHANGE); 221cfd34f8eSVishwanathapura, Niranjana return 0; 222cfd34f8eSVishwanathapura, Niranjana } 223cfd34f8eSVishwanathapura, Niranjana 224cfd34f8eSVishwanathapura, Niranjana /* 225cfd34f8eSVishwanathapura, Niranjana * opa_vnic_mac_send_event - post event on possible mac list exchange 226cfd34f8eSVishwanathapura, Niranjana * Send trap when digest from uc/mc mac list differs from previous run. 227cfd34f8eSVishwanathapura, Niranjana * Digest is evaluated similar to how cksum does. 228cfd34f8eSVishwanathapura, Niranjana */ 229cfd34f8eSVishwanathapura, Niranjana static void opa_vnic_mac_send_event(struct net_device *netdev, u8 event) 230cfd34f8eSVishwanathapura, Niranjana { 231cfd34f8eSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev); 232cfd34f8eSVishwanathapura, Niranjana struct netdev_hw_addr *ha; 233cfd34f8eSVishwanathapura, Niranjana struct netdev_hw_addr_list *hw_list; 234cfd34f8eSVishwanathapura, Niranjana u32 *ref_crc; 235cfd34f8eSVishwanathapura, Niranjana u32 l, crc = 0; 236cfd34f8eSVishwanathapura, Niranjana 237cfd34f8eSVishwanathapura, Niranjana switch (event) { 238cfd34f8eSVishwanathapura, Niranjana case OPA_VESWPORT_TRAP_IFACE_UCAST_MAC_CHANGE: 239cfd34f8eSVishwanathapura, Niranjana hw_list = &netdev->uc; 240cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.uc_macs_gen_count++; 241cfd34f8eSVishwanathapura, Niranjana ref_crc = &adapter->umac_hash; 242cfd34f8eSVishwanathapura, Niranjana break; 243cfd34f8eSVishwanathapura, Niranjana case OPA_VESWPORT_TRAP_IFACE_MCAST_MAC_CHANGE: 244cfd34f8eSVishwanathapura, Niranjana hw_list = &netdev->mc; 245cfd34f8eSVishwanathapura, Niranjana adapter->info.vport.mc_macs_gen_count++; 246cfd34f8eSVishwanathapura, Niranjana ref_crc = &adapter->mmac_hash; 247cfd34f8eSVishwanathapura, Niranjana break; 248cfd34f8eSVishwanathapura, Niranjana default: 249cfd34f8eSVishwanathapura, Niranjana return; 250cfd34f8eSVishwanathapura, Niranjana } 251cfd34f8eSVishwanathapura, Niranjana netdev_hw_addr_list_for_each(ha, hw_list) { 252cfd34f8eSVishwanathapura, Niranjana crc = crc32_le(crc, ha->addr, ETH_ALEN); 253cfd34f8eSVishwanathapura, Niranjana } 254cfd34f8eSVishwanathapura, Niranjana l = netdev_hw_addr_list_count(hw_list) * ETH_ALEN; 255cfd34f8eSVishwanathapura, Niranjana crc = ~crc32_le(crc, (void *)&l, sizeof(l)); 256cfd34f8eSVishwanathapura, Niranjana 257cfd34f8eSVishwanathapura, Niranjana if (crc != *ref_crc) { 258cfd34f8eSVishwanathapura, Niranjana *ref_crc = crc; 259cfd34f8eSVishwanathapura, Niranjana opa_vnic_vema_report_event(adapter, event); 260cfd34f8eSVishwanathapura, Niranjana } 261cfd34f8eSVishwanathapura, Niranjana } 262cfd34f8eSVishwanathapura, Niranjana 263cfd34f8eSVishwanathapura, Niranjana /* opa_vnic_set_rx_mode - handle uc/mc mac list change */ 264cfd34f8eSVishwanathapura, Niranjana static void opa_vnic_set_rx_mode(struct net_device *netdev) 265cfd34f8eSVishwanathapura, Niranjana { 266cfd34f8eSVishwanathapura, Niranjana opa_vnic_mac_send_event(netdev, 267cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_IFACE_UCAST_MAC_CHANGE); 268cfd34f8eSVishwanathapura, Niranjana 269cfd34f8eSVishwanathapura, Niranjana opa_vnic_mac_send_event(netdev, 270cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_IFACE_MCAST_MAC_CHANGE); 2717d6f728cSVishwanathapura, Niranjana } 2727d6f728cSVishwanathapura, Niranjana 2737d6f728cSVishwanathapura, Niranjana /* opa_netdev_open - activate network interface */ 2747d6f728cSVishwanathapura, Niranjana static int opa_netdev_open(struct net_device *netdev) 2757d6f728cSVishwanathapura, Niranjana { 2767d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev); 2777d6f728cSVishwanathapura, Niranjana int rc; 2787d6f728cSVishwanathapura, Niranjana 2797d6f728cSVishwanathapura, Niranjana rc = adapter->rn_ops->ndo_open(adapter->netdev); 2807d6f728cSVishwanathapura, Niranjana if (rc) { 2817d6f728cSVishwanathapura, Niranjana v_dbg("open failed %d\n", rc); 2827d6f728cSVishwanathapura, Niranjana return rc; 2837d6f728cSVishwanathapura, Niranjana } 2847d6f728cSVishwanathapura, Niranjana 285e82b7c38SNiranjana Vishwanathapura /* Update status and send trap */ 286e82b7c38SNiranjana Vishwanathapura opa_vnic_update_state(adapter, true); 287cfd34f8eSVishwanathapura, Niranjana opa_vnic_vema_report_event(adapter, 288cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_ETH_LINK_STATUS_CHANGE); 2897d6f728cSVishwanathapura, Niranjana return 0; 2907d6f728cSVishwanathapura, Niranjana } 2917d6f728cSVishwanathapura, Niranjana 2927d6f728cSVishwanathapura, Niranjana /* opa_netdev_close - disable network interface */ 2937d6f728cSVishwanathapura, Niranjana static int opa_netdev_close(struct net_device *netdev) 2947d6f728cSVishwanathapura, Niranjana { 2957d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev); 2967d6f728cSVishwanathapura, Niranjana int rc; 2977d6f728cSVishwanathapura, Niranjana 2987d6f728cSVishwanathapura, Niranjana rc = adapter->rn_ops->ndo_stop(adapter->netdev); 2997d6f728cSVishwanathapura, Niranjana if (rc) { 3007d6f728cSVishwanathapura, Niranjana v_dbg("close failed %d\n", rc); 3017d6f728cSVishwanathapura, Niranjana return rc; 3027d6f728cSVishwanathapura, Niranjana } 3037d6f728cSVishwanathapura, Niranjana 304e82b7c38SNiranjana Vishwanathapura /* Update status and send trap */ 305e82b7c38SNiranjana Vishwanathapura opa_vnic_update_state(adapter, false); 306cfd34f8eSVishwanathapura, Niranjana opa_vnic_vema_report_event(adapter, 307cfd34f8eSVishwanathapura, Niranjana OPA_VESWPORT_TRAP_ETH_LINK_STATUS_CHANGE); 3087d6f728cSVishwanathapura, Niranjana return 0; 3097d6f728cSVishwanathapura, Niranjana } 3107d6f728cSVishwanathapura, Niranjana 3117d6f728cSVishwanathapura, Niranjana /* netdev ops */ 3127d6f728cSVishwanathapura, Niranjana static const struct net_device_ops opa_netdev_ops = { 3137d6f728cSVishwanathapura, Niranjana .ndo_open = opa_netdev_open, 3147d6f728cSVishwanathapura, Niranjana .ndo_stop = opa_netdev_close, 3157d6f728cSVishwanathapura, Niranjana .ndo_start_xmit = opa_netdev_start_xmit, 316009b7dd4SVishwanathapura, Niranjana .ndo_get_stats64 = opa_vnic_get_stats64, 317cfd34f8eSVishwanathapura, Niranjana .ndo_set_rx_mode = opa_vnic_set_rx_mode, 3187d6f728cSVishwanathapura, Niranjana .ndo_select_queue = opa_vnic_select_queue, 3197d6f728cSVishwanathapura, Niranjana .ndo_set_mac_address = opa_vnic_set_mac_addr, 3207d6f728cSVishwanathapura, Niranjana }; 3217d6f728cSVishwanathapura, Niranjana 3227d6f728cSVishwanathapura, Niranjana /* opa_vnic_add_netdev - create vnic netdev interface */ 3237d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *opa_vnic_add_netdev(struct ib_device *ibdev, 3247d6f728cSVishwanathapura, Niranjana u8 port_num, u8 vport_num) 3257d6f728cSVishwanathapura, Niranjana { 3267d6f728cSVishwanathapura, Niranjana struct opa_vnic_adapter *adapter; 3277d6f728cSVishwanathapura, Niranjana struct net_device *netdev; 3287d6f728cSVishwanathapura, Niranjana struct rdma_netdev *rn; 3297d6f728cSVishwanathapura, Niranjana int rc; 3307d6f728cSVishwanathapura, Niranjana 3313023a1e9SKamal Heib netdev = ibdev->ops.alloc_rdma_netdev(ibdev, port_num, 3327d6f728cSVishwanathapura, Niranjana RDMA_NETDEV_OPA_VNIC, 3337d6f728cSVishwanathapura, Niranjana "veth%d", NET_NAME_UNKNOWN, 3347d6f728cSVishwanathapura, Niranjana ether_setup); 3357d6f728cSVishwanathapura, Niranjana if (!netdev) 3367d6f728cSVishwanathapura, Niranjana return ERR_PTR(-ENOMEM); 3377d6f728cSVishwanathapura, Niranjana else if (IS_ERR(netdev)) 3387d6f728cSVishwanathapura, Niranjana return ERR_CAST(netdev); 3397d6f728cSVishwanathapura, Niranjana 3408e959601SNiranjana Vishwanathapura rn = netdev_priv(netdev); 3417d6f728cSVishwanathapura, Niranjana adapter = kzalloc(sizeof(*adapter), GFP_KERNEL); 3427d6f728cSVishwanathapura, Niranjana if (!adapter) { 3437d6f728cSVishwanathapura, Niranjana rc = -ENOMEM; 3447d6f728cSVishwanathapura, Niranjana goto adapter_err; 3457d6f728cSVishwanathapura, Niranjana } 3467d6f728cSVishwanathapura, Niranjana 3477d6f728cSVishwanathapura, Niranjana rn->clnt_priv = adapter; 3487d6f728cSVishwanathapura, Niranjana rn->hca = ibdev; 3497d6f728cSVishwanathapura, Niranjana rn->port_num = port_num; 3507d6f728cSVishwanathapura, Niranjana adapter->netdev = netdev; 3517d6f728cSVishwanathapura, Niranjana adapter->ibdev = ibdev; 3527d6f728cSVishwanathapura, Niranjana adapter->port_num = port_num; 3537d6f728cSVishwanathapura, Niranjana adapter->vport_num = vport_num; 3547d6f728cSVishwanathapura, Niranjana adapter->rn_ops = netdev->netdev_ops; 3557d6f728cSVishwanathapura, Niranjana 3567d6f728cSVishwanathapura, Niranjana netdev->netdev_ops = &opa_netdev_ops; 3577d6f728cSVishwanathapura, Niranjana netdev->priv_flags |= IFF_LIVE_ADDR_CHANGE; 3587d6f728cSVishwanathapura, Niranjana netdev->hard_header_len += OPA_VNIC_SKB_HEADROOM; 3597d6f728cSVishwanathapura, Niranjana mutex_init(&adapter->lock); 360174e03d7SVishwanathapura, Niranjana mutex_init(&adapter->mactbl_lock); 361a379d69fSVishwanathapura, Niranjana spin_lock_init(&adapter->stats_lock); 3627d6f728cSVishwanathapura, Niranjana 3637d6f728cSVishwanathapura, Niranjana SET_NETDEV_DEV(netdev, ibdev->dev.parent); 3647d6f728cSVishwanathapura, Niranjana 3657d6f728cSVishwanathapura, Niranjana opa_vnic_set_ethtool_ops(netdev); 366cfd34f8eSVishwanathapura, Niranjana 367cfd34f8eSVishwanathapura, Niranjana opa_vnic_set_pod_values(adapter); 368cfd34f8eSVishwanathapura, Niranjana 3697d6f728cSVishwanathapura, Niranjana rc = register_netdev(netdev); 3707d6f728cSVishwanathapura, Niranjana if (rc) 3717d6f728cSVishwanathapura, Niranjana goto netdev_err; 3727d6f728cSVishwanathapura, Niranjana 3737d6f728cSVishwanathapura, Niranjana netif_carrier_off(netdev); 3747d6f728cSVishwanathapura, Niranjana netif_dormant_on(netdev); 3757d6f728cSVishwanathapura, Niranjana v_info("initialized\n"); 3767d6f728cSVishwanathapura, Niranjana 3777d6f728cSVishwanathapura, Niranjana return adapter; 3787d6f728cSVishwanathapura, Niranjana netdev_err: 3797d6f728cSVishwanathapura, Niranjana mutex_destroy(&adapter->lock); 380174e03d7SVishwanathapura, Niranjana mutex_destroy(&adapter->mactbl_lock); 3817d6f728cSVishwanathapura, Niranjana kfree(adapter); 3827d6f728cSVishwanathapura, Niranjana adapter_err: 3838e959601SNiranjana Vishwanathapura rn->free_rdma_netdev(netdev); 3847d6f728cSVishwanathapura, Niranjana 3857d6f728cSVishwanathapura, Niranjana return ERR_PTR(rc); 3867d6f728cSVishwanathapura, Niranjana } 3877d6f728cSVishwanathapura, Niranjana 3887d6f728cSVishwanathapura, Niranjana /* opa_vnic_rem_netdev - remove vnic netdev interface */ 3897d6f728cSVishwanathapura, Niranjana void opa_vnic_rem_netdev(struct opa_vnic_adapter *adapter) 3907d6f728cSVishwanathapura, Niranjana { 3917d6f728cSVishwanathapura, Niranjana struct net_device *netdev = adapter->netdev; 3928e959601SNiranjana Vishwanathapura struct rdma_netdev *rn = netdev_priv(netdev); 3937d6f728cSVishwanathapura, Niranjana 3947d6f728cSVishwanathapura, Niranjana v_info("removing\n"); 3957d6f728cSVishwanathapura, Niranjana unregister_netdev(netdev); 396174e03d7SVishwanathapura, Niranjana opa_vnic_release_mac_tbl(adapter); 3977d6f728cSVishwanathapura, Niranjana mutex_destroy(&adapter->lock); 398174e03d7SVishwanathapura, Niranjana mutex_destroy(&adapter->mactbl_lock); 3997d6f728cSVishwanathapura, Niranjana kfree(adapter); 4008e959601SNiranjana Vishwanathapura rn->free_rdma_netdev(netdev); 4017d6f728cSVishwanathapura, Niranjana } 402