cregit-Linux how code gets into the kernel

Release 4.16 drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib_vlan.c

/*
 * 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; }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker64100.00%1100.00%
Total64100.00%1100.00%


void mlx5i_pkey_qpn_ht_cleanup(struct net_device *netdev) { struct mlx5i_priv *ipriv = netdev_priv(netdev); kfree(ipriv->qpn_htbl); }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker27100.00%1100.00%
Total27100.00%1100.00%


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; }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker61100.00%1100.00%
Total61100.00%1100.00%


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; }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker116100.00%1100.00%
Total116100.00%1100.00%


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; }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker109100.00%1100.00%
Total109100.00%1100.00%


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; }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker56100.00%1100.00%
Total56100.00%1100.00%

static int mlx5i_pkey_open(struct net_device *netdev); static int mlx5i_pkey_close(struct net_device *netdev); static int mlx5i_pkey_dev_init(struct net_device *dev); static void mlx5i_pkey_dev_cleanup(struct net_device *netdev); static int mlx5i_pkey_change_mtu(struct net_device *netdev, int new_mtu); static int mlx5i_pkey_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd); static const struct net_device_ops mlx5i_pkey_netdev_ops = { .ndo_open = mlx5i_pkey_open, .ndo_stop = mlx5i_pkey_close, .ndo_init = mlx5i_pkey_dev_init, .ndo_uninit = mlx5i_pkey_dev_cleanup, .ndo_change_mtu = mlx5i_pkey_change_mtu, .ndo_do_ioctl = mlx5i_pkey_ioctl, }; /* Child NDOs */
static int mlx5i_pkey_dev_init(struct net_device *dev) { struct mlx5e_priv *priv = mlx5i_epriv(dev); struct mlx5i_priv *ipriv, *parent_ipriv; struct net_device *parent_dev; int parent_ifindex; ipriv = priv->ppriv; /* Get QPN to netdevice hash table from parent */ parent_ifindex = dev->netdev_ops->ndo_get_iflink(dev); parent_dev = dev_get_by_index(dev_net(dev), parent_ifindex); if (!parent_dev) { mlx5_core_warn(priv->mdev, "failed to get parent device\n"); return -EINVAL; } parent_ipriv = netdev_priv(parent_dev); ipriv->qpn_htbl = parent_ipriv->qpn_htbl; dev_put(parent_dev); return mlx5i_dev_init(dev); }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker113100.00%1100.00%
Total113100.00%1100.00%


static int mlx5i_pkey_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { return mlx5i_ioctl(dev, ifr, cmd); }

Contributors

PersonTokensPropCommitsCommitProp
Feras Daoud29100.00%1100.00%
Total29100.00%1100.00%


static void mlx5i_pkey_dev_cleanup(struct net_device *netdev) { return mlx5i_dev_cleanup(netdev); }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker17100.00%1100.00%
Total17100.00%1100.00%


static int mlx5i_pkey_open(struct net_device *netdev) { struct mlx5e_priv *epriv = mlx5i_epriv(netdev); struct mlx5i_priv *ipriv = epriv->ppriv; struct mlx5_core_dev *mdev = epriv->mdev; int err; mutex_lock(&epriv->state_lock); set_bit(MLX5E_STATE_OPENED, &epriv->state); err = mlx5i_init_underlay_qp(epriv); if (err) { mlx5_core_warn(mdev, "prepare child underlay qp state failed, %d\n", err); goto err_release_lock; } err = mlx5_fs_add_rx_underlay_qpn(mdev, ipriv->qp.qpn); if (err) { mlx5_core_warn(mdev, "attach child underlay qp to ft failed, %d\n", err); goto err_unint_underlay_qp; } err = mlx5e_create_tis(mdev, 0 /* tc */, ipriv->qp.qpn, &epriv->tisn[0]); if (err) { mlx5_core_warn(mdev, "create child tis failed, %d\n", err); goto err_remove_rx_uderlay_qp; } err = mlx5e_open_channels(epriv, &epriv->channels); if (err) { mlx5_core_warn(mdev, "opening child channels failed, %d\n", err); goto err_clear_state_opened_flag; } mlx5e_refresh_tirs(epriv, false); mlx5e_activate_priv_channels(epriv); mutex_unlock(&epriv->state_lock); return 0; err_clear_state_opened_flag: mlx5e_destroy_tis(mdev, epriv->tisn[0]); err_remove_rx_uderlay_qp: mlx5_fs_remove_rx_underlay_qpn(mdev, ipriv->qp.qpn); err_unint_underlay_qp: mlx5i_uninit_underlay_qp(epriv); err_release_lock: clear_bit(MLX5E_STATE_OPENED, &epriv->state); mutex_unlock(&epriv->state_lock); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker268100.00%1100.00%
Total268100.00%1100.00%


static int mlx5i_pkey_close(struct net_device *netdev) { struct mlx5e_priv *priv = mlx5i_epriv(netdev); struct mlx5i_priv *ipriv = priv->ppriv; struct mlx5_core_dev *mdev = priv->mdev; mutex_lock(&priv->state_lock); if (!test_bit(MLX5E_STATE_OPENED, &priv->state)) goto unlock; clear_bit(MLX5E_STATE_OPENED, &priv->state); netif_carrier_off(priv->netdev); mlx5_fs_remove_rx_underlay_qpn(mdev, ipriv->qp.qpn); mlx5i_uninit_underlay_qp(priv); mlx5e_deactivate_priv_channels(priv); mlx5e_close_channels(&priv->channels); mlx5e_destroy_tis(mdev, priv->tisn[0]); unlock: mutex_unlock(&priv->state_lock); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker134100.00%1100.00%
Total134100.00%1100.00%


static int mlx5i_pkey_change_mtu(struct net_device *netdev, int new_mtu) { struct mlx5e_priv *priv = mlx5i_epriv(netdev); mutex_lock(&priv->state_lock); netdev->mtu = new_mtu; mutex_unlock(&priv->state_lock); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker49100.00%1100.00%
Total49100.00%1100.00%

/* Called directly after IPoIB netdevice was created to initialize SW structs */
static void mlx5i_pkey_init(struct mlx5_core_dev *mdev, struct net_device *netdev, const struct mlx5e_profile *profile, void *ppriv) { struct mlx5e_priv *priv = mlx5i_epriv(netdev); mlx5i_init(mdev, netdev, profile, ppriv); /* Override parent ndo */ netdev->netdev_ops = &mlx5i_pkey_netdev_ops; /* Set child limited ethtool support */ netdev->ethtool_ops = &mlx5i_pkey_ethtool_ops; /* Use dummy rqs */ priv->channels.params.log_rq_size = MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE; }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker74100.00%3100.00%
Total74100.00%3100.00%

/* Called directly before IPoIB netdevice is destroyed to cleanup SW structs */
static void mlx5i_pkey_cleanup(struct mlx5e_priv *priv) { /* Do nothing .. */ }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker12100.00%1100.00%
Total12100.00%1100.00%


static int mlx5i_pkey_init_tx(struct mlx5e_priv *priv) { struct mlx5i_priv *ipriv = priv->ppriv; int err; err = mlx5i_create_underlay_qp(priv->mdev, &ipriv->qp); if (err) { mlx5_core_warn(priv->mdev, "create child underlay QP failed, %d\n", err); return err; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker60100.00%1100.00%
Total60100.00%1100.00%


static void mlx5i_pkey_cleanup_tx(struct mlx5e_priv *priv) { struct mlx5i_priv *ipriv = priv->ppriv; mlx5i_destroy_underlay_qp(priv->mdev, &ipriv->qp); }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker32100.00%1100.00%
Total32100.00%1100.00%


static int mlx5i_pkey_init_rx(struct mlx5e_priv *priv) { /* Since the rx resources are shared between child and parent, the * parent interface is taking care of rx resource allocation and init */ return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker15100.00%1100.00%
Total15100.00%1100.00%


static void mlx5i_pkey_cleanup_rx(struct mlx5e_priv *priv) { /* Since the rx resources are shared between child and parent, the * parent interface is taking care of rx resource free and de-init */ }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker12100.00%1100.00%
Total12100.00%1100.00%

static const struct mlx5e_profile mlx5i_pkey_nic_profile = { .init = mlx5i_pkey_init, .cleanup = mlx5i_pkey_cleanup, .init_tx = mlx5i_pkey_init_tx, .cleanup_tx = mlx5i_pkey_cleanup_tx, .init_rx = mlx5i_pkey_init_rx, .cleanup_rx = mlx5i_pkey_cleanup_rx, .enable = NULL, .disable = NULL, .update_stats = NULL, .max_nch = mlx5e_get_max_num_channels, .rx_handlers.handle_rx_cqe = mlx5i_handle_rx_cqe, .rx_handlers.handle_rx_cqe_mpwqe = NULL, /* Not supported */ .max_tc = MLX5I_MAX_NUM_TC, };
const struct mlx5e_profile *mlx5i_pkey_get_profile(void) { return &mlx5i_pkey_nic_profile; }

Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker14100.00%1100.00%
Total14100.00%1100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Alex Vesker144696.53%480.00%
Feras Daoud523.47%120.00%
Total1498100.00%5100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.