/* * 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.
*/
/* * Using a simple hash table for mac table implementation with the last octet * of mac address as a key.
*/ staticvoid opa_vnic_free_mac_tbl(struct hlist_head *mactbl)
{ struct opa_vnic_mac_tbl_node *node; struct hlist_node *tmp; int bkt;
/* * 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)
{ struct opa_vnic_mac_tbl_node *node; struct hlist_head *mactbl; int bkt;
u16 loffset, lnum_entries;
rcu_read_lock();
mactbl = rcu_dereference(adapter->mactbl); if (!mactbl) goto get_mac_done;
/* populate entry in the tbl corresponding to the index */
entry = &tbl->tbl_entries[node->index - loffset];
memcpy(entry->mac_addr, nentry->mac_addr,
ARRAY_SIZE(entry->mac_addr));
memcpy(entry->mac_addr_mask, nentry->mac_addr_mask,
ARRAY_SIZE(entry->mac_addr_mask));
entry->dlid_sd = cpu_to_be32(nentry->dlid_sd);
}
tbl->mac_tbl_digest = cpu_to_be32(adapter->info.vport.mac_tbl_digest);
get_mac_done:
rcu_read_unlock();
}
/* * 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)
{ struct opa_vnic_mac_tbl_node *node, *new_node; struct hlist_head *new_mactbl, *old_mactbl; int i, bkt, rc = 0;
u8 key;
u16 loffset, lnum_entries;
mutex_lock(&adapter->mactbl_lock); /* allocate new mac table */
new_mactbl = opa_vnic_alloc_mac_tbl(); if (IS_ERR(new_mactbl)) {
mutex_unlock(&adapter->mactbl_lock); return PTR_ERR(new_mactbl);
}
switch_tbl: /* switch to new table */
rcu_assign_pointer(adapter->mactbl, new_mactbl);
synchronize_rcu();
adapter->info.vport.mac_tbl_digest = be32_to_cpu(tbl->mac_tbl_digest);
updt_done: /* upon failure, free the new table; otherwise, free the old table */ if (rc)
opa_vnic_free_mac_tbl(new_mactbl); else
opa_vnic_free_mac_tbl(old_mactbl);
/* opa_vnic_get_def_port - get default port based on entropy */ staticinline u8 opa_vnic_get_def_port(struct opa_vnic_adapter *adapter,
u8 entropy)
{
u8 flow_id;
/* Add the upper and lower 4-bits of entropy to get the flow id */
flow_id = ((entropy & 0xf) + (entropy >> 4)); return adapter->flow_tbl[flow_id & (OPA_VNIC_FLOW_TBL_SIZE - 1)];
}
/* Calculate packet length including OPA header, crc and padding */ staticinlineint opa_vnic_wire_length(struct sk_buff *skb)
{
u32 pad_len;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.