/* * Copyright(c) 2017 Intel Corporation. * * This file is provided under a dual BSD/GPLv2 license. When using or * redistributing this file, you may do so under either license. * * GPL LICENSE SUMMARY * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * BSD LICENSE * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * - Neither the name of Intel Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ /* * This file contains OPA VNIC encapsulation/decapsulation function. */ #include <linux/if_ether.h> #include <linux/if_vlan.h> #include "opa_vnic_internal.h" /* OPA 16B Header fields */ #define OPA_16B_LID_MASK … #define OPA_16B_SLID_HIGH_SHFT … #define OPA_16B_SLID_MASK … #define OPA_16B_DLID_MASK … #define OPA_16B_DLID_HIGH_SHFT … #define OPA_16B_LEN_SHFT … #define OPA_16B_SC_SHFT … #define OPA_16B_RC_SHFT … #define OPA_16B_PKEY_SHFT … #define OPA_VNIC_L4_HDR_SHFT … /* L2+L4 hdr len is 20 bytes (5 quad words) */ #define OPA_VNIC_HDR_QW_LEN … static inline void opa_vnic_make_header(u8 *hdr, u32 slid, u32 dlid, u16 len, u16 pkey, u16 entropy, u8 sc, u8 rc, u8 l4_type, u16 l4_hdr) { … } /* * Using a simple hash table for mac table implementation with the last octet * of mac address as a key. */ static void opa_vnic_free_mac_tbl(struct hlist_head *mactbl) { … } static struct hlist_head *opa_vnic_alloc_mac_tbl(void) { … } /* opa_vnic_release_mac_tbl - empty and free the mac table */ void opa_vnic_release_mac_tbl(struct opa_vnic_adapter *adapter) { … } /* * opa_vnic_query_mac_tbl - query the mac table for a section * * This function implements query of specific function of the mac table. * The function also expects the requested range to be valid. */ void opa_vnic_query_mac_tbl(struct opa_vnic_adapter *adapter, struct opa_veswport_mactable *tbl) { … } /* * opa_vnic_update_mac_tbl - update mac table section * * This function updates the specified section of the mac table. * The procedure includes following steps. * - Allocate a new mac (hash) table. * - Add the specified entries to the new table. * (except the ones that are requested to be deleted). * - Add all the other entries from the old mac table. * - If there is a failure, free the new table and return. * - Switch to the new table. * - Free the old table and return. * * The function also expects the requested range to be valid. */ int opa_vnic_update_mac_tbl(struct opa_vnic_adapter *adapter, struct opa_veswport_mactable *tbl) { … } /* opa_vnic_chk_mac_tbl - check mac table for dlid */ static uint32_t opa_vnic_chk_mac_tbl(struct opa_vnic_adapter *adapter, struct ethhdr *mac_hdr) { … } /* opa_vnic_get_dlid - find and return the DLID */ static uint32_t opa_vnic_get_dlid(struct opa_vnic_adapter *adapter, struct sk_buff *skb, u8 def_port) { … } /* opa_vnic_get_sc - return the service class */ static u8 opa_vnic_get_sc(struct __opa_veswport_info *info, struct sk_buff *skb) { … } u8 opa_vnic_get_vl(struct opa_vnic_adapter *adapter, struct sk_buff *skb) { … } /* opa_vnic_get_rc - return the routing control */ static u8 opa_vnic_get_rc(struct __opa_veswport_info *info, struct sk_buff *skb) { … } /* opa_vnic_calc_entropy - calculate the packet entropy */ u8 opa_vnic_calc_entropy(struct sk_buff *skb) { … } /* opa_vnic_get_def_port - get default port based on entropy */ static inline u8 opa_vnic_get_def_port(struct opa_vnic_adapter *adapter, u8 entropy) { … } /* Calculate packet length including OPA header, crc and padding */ static inline int opa_vnic_wire_length(struct sk_buff *skb) { … } /* opa_vnic_encap_skb - encapsulate skb packet with OPA header and meta data */ void opa_vnic_encap_skb(struct opa_vnic_adapter *adapter, struct sk_buff *skb) { … }