-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net/mlx5e: IPoIB, Use hash-table to map between QPN to child netdev
This change is needed for PKEY support, since the RQs are shared between the child interface and the parent. The parent is responsible for NAPI and the precessing of RX completions. Using the dqpn in the completion descriptor we set the corresponding child IPoIB netdevice on the SKB. The mapping between the dqpn and the netdevice is done using a HT, each mlx5 IPoIB interface registers its mapping on creation. Signed-off-by: Alex Vesker <valex@mellanox.com> Reviewed-by: Erez Shitrit <erezsh@mellanox.com>
- Loading branch information
Alex Vesker
authored and
Saeed Mahameed
committed
Oct 14, 2017
1 parent
da34f1a
commit 7e7f478
Showing
5 changed files
with
184 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib_vlan.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* Copyright (c) 2017, Mellanox Technologies. All rights reserved. | ||
* | ||
* This software is available to you under a choice of one of two | ||
* licenses. You may choose to be licensed under the terms of the GNU | ||
* General Public License (GPL) Version 2, available from the file | ||
* COPYING in the main directory of this source tree, or the | ||
* OpenIB.org BSD license below: | ||
* | ||
* 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. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
#include <linux/hash.h> | ||
#include "ipoib.h" | ||
|
||
#define MLX5I_MAX_LOG_PKEY_SUP 7 | ||
|
||
struct qpn_to_netdev { | ||
struct net_device *netdev; | ||
struct hlist_node hlist; | ||
u32 underlay_qpn; | ||
}; | ||
|
||
struct mlx5i_pkey_qpn_ht { | ||
struct hlist_head buckets[1 << MLX5I_MAX_LOG_PKEY_SUP]; | ||
spinlock_t ht_lock; /* Synchronise with NAPI */ | ||
}; | ||
|
||
int mlx5i_pkey_qpn_ht_init(struct net_device *netdev) | ||
{ | ||
struct mlx5i_priv *ipriv = netdev_priv(netdev); | ||
struct mlx5i_pkey_qpn_ht *qpn_htbl; | ||
|
||
qpn_htbl = kzalloc(sizeof(*qpn_htbl), GFP_KERNEL); | ||
if (!qpn_htbl) | ||
return -ENOMEM; | ||
|
||
ipriv->qpn_htbl = qpn_htbl; | ||
spin_lock_init(&qpn_htbl->ht_lock); | ||
|
||
return 0; | ||
} | ||
|
||
void mlx5i_pkey_qpn_ht_cleanup(struct net_device *netdev) | ||
{ | ||
struct mlx5i_priv *ipriv = netdev_priv(netdev); | ||
|
||
kfree(ipriv->qpn_htbl); | ||
} | ||
|
||
static struct qpn_to_netdev *mlx5i_find_qpn_to_netdev_node(struct hlist_head *buckets, | ||
u32 qpn) | ||
{ | ||
struct hlist_head *h = &buckets[hash_32(qpn, MLX5I_MAX_LOG_PKEY_SUP)]; | ||
struct qpn_to_netdev *node; | ||
|
||
hlist_for_each_entry(node, h, hlist) { | ||
if (node->underlay_qpn == qpn) | ||
return node; | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
int mlx5i_pkey_add_qpn(struct net_device *netdev, u32 qpn) | ||
{ | ||
struct mlx5i_priv *ipriv = netdev_priv(netdev); | ||
struct mlx5i_pkey_qpn_ht *ht = ipriv->qpn_htbl; | ||
u8 key = hash_32(qpn, MLX5I_MAX_LOG_PKEY_SUP); | ||
struct qpn_to_netdev *new_node; | ||
|
||
new_node = kzalloc(sizeof(*new_node), GFP_KERNEL); | ||
if (!new_node) | ||
return -ENOMEM; | ||
|
||
new_node->netdev = netdev; | ||
new_node->underlay_qpn = qpn; | ||
spin_lock_bh(&ht->ht_lock); | ||
hlist_add_head(&new_node->hlist, &ht->buckets[key]); | ||
spin_unlock_bh(&ht->ht_lock); | ||
|
||
return 0; | ||
} | ||
|
||
int mlx5i_pkey_del_qpn(struct net_device *netdev, u32 qpn) | ||
{ | ||
struct mlx5e_priv *epriv = mlx5i_epriv(netdev); | ||
struct mlx5i_priv *ipriv = epriv->ppriv; | ||
struct mlx5i_pkey_qpn_ht *ht = ipriv->qpn_htbl; | ||
struct qpn_to_netdev *node; | ||
|
||
node = mlx5i_find_qpn_to_netdev_node(ht->buckets, qpn); | ||
if (!node) { | ||
mlx5_core_warn(epriv->mdev, "QPN to netdev delete from HT failed\n"); | ||
return -EINVAL; | ||
} | ||
|
||
spin_lock_bh(&ht->ht_lock); | ||
hlist_del_init(&node->hlist); | ||
spin_unlock_bh(&ht->ht_lock); | ||
kfree(node); | ||
|
||
return 0; | ||
} | ||
|
||
struct net_device *mlx5i_pkey_get_netdev(struct net_device *netdev, u32 qpn) | ||
{ | ||
struct mlx5i_priv *ipriv = netdev_priv(netdev); | ||
struct qpn_to_netdev *node; | ||
|
||
node = mlx5i_find_qpn_to_netdev_node(ipriv->qpn_htbl->buckets, qpn); | ||
if (!node) | ||
return NULL; | ||
|
||
return node->netdev; | ||
} |