From patchwork Mon Mar 13 18:31:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erez Shitrit X-Patchwork-Id: 9621757 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DCBDC60522 for ; Mon, 13 Mar 2017 18:32:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D323328494 for ; Mon, 13 Mar 2017 18:32:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C70F428502; Mon, 13 Mar 2017 18:32:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6386028501 for ; Mon, 13 Mar 2017 18:32:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752846AbdCMScZ (ORCPT ); Mon, 13 Mar 2017 14:32:25 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:49759 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752900AbdCMScB (ORCPT ); Mon, 13 Mar 2017 14:32:01 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from erezsh@mellanox.com) with ESMTPS (AES256-SHA encrypted); 13 Mar 2017 20:31:54 +0200 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id v2DIVrvT021688; Mon, 13 Mar 2017 20:31:54 +0200 From: Erez Shitrit To: dledford@redhat.com Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, valex@mellanox.com, leonro@mellanox.com, saedm@mellanox.com, erezsh@dev.mellanox.co.il, Erez Shitrit Subject: [RFC v1 for accelerated IPoIB 13/25] net/mlx5e: Export resource creation function to be used in IB link Date: Mon, 13 Mar 2017 20:31:24 +0200 Message-Id: <1489429896-10781-14-git-send-email-erezsh@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1489429896-10781-1-git-send-email-erezsh@mellanox.com> References: <1489429896-10781-1-git-send-email-erezsh@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP mlx5i_attach that creates the resources of IB network device. mlx5i_detach cleans resources for IB device. Signed-off-by: Erez Shitrit --- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 122 +++++++++++++++------- 1 file changed, 87 insertions(+), 35 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 87881f9ddf35..5b3c2e67607f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -3844,6 +3844,54 @@ static void mlx5e_nic_disable(struct mlx5e_priv *priv) mlx5_lag_remove(mdev); } +static int mlx5n_attach_netdev_common(struct mlx5_core_dev *mdev, + struct mlx5e_priv *priv) +{ + const struct mlx5e_profile *profile; + struct net_device *netdev; + int err; + + netdev = priv->netdev; + profile = priv->profile; + clear_bit(MLX5E_STATE_DESTROYING, &priv->state); + + err = profile->init_tx(priv); + if (err) + goto out; + + err = mlx5e_open_drop_rq(priv); + if (err) { + mlx5_core_err(mdev, "open drop rq failed, %d\n", err); + goto err_cleanup_tx; + } + + err = profile->init_rx(priv); + if (err) + goto err_close_drop_rq; + + mlx5e_create_q_counter(priv); + + if (profile->enable) + profile->enable(priv); + + rtnl_lock(); + if (netif_running(netdev)) + mlx5e_open(netdev); + netif_device_attach(netdev); + rtnl_unlock(); + + return 0; + +err_close_drop_rq: + mlx5e_close_drop_rq(priv); + +err_cleanup_tx: + profile->cleanup_tx(priv); + +out: + return err; +} + static void mlx5i_nic_init(struct mlx5_core_dev *mdev, struct net_device *netdev, const struct mlx5e_profile *profile, @@ -3942,6 +3990,42 @@ struct net_device *mlx5i_create_netdev(struct mlx5_core_dev *mdev, } EXPORT_SYMBOL(mlx5i_create_netdev); +int mlx5i_attach(struct mlx5_core_dev *mdev, void *vpriv) +{ + struct mlx5e_priv *priv = vpriv; + struct net_device *netdev = priv->netdev; + int err; + + if (netif_device_present(netdev)) + return 0; + + err = mlx5e_create_mdev_resources(mdev); + if (err) + return err; + + err = mlx5n_attach_netdev_common(mdev, priv); + if (err) { + mlx5e_destroy_mdev_resources(mdev); + return err; + } + + return 0; +} +EXPORT_SYMBOL(mlx5i_attach); + +void mlx5i_detach(struct mlx5_core_dev *mdev, void *vpriv) +{ + struct mlx5e_priv *priv = vpriv; + struct net_device *netdev = priv->netdev; + + if (!netif_device_present(netdev)) + return; + + mlx5e_detach_netdev(mdev, netdev); + mlx5e_destroy_mdev_resources(mdev); +} +EXPORT_SYMBOL(mlx5i_detach); + static const struct mlx5e_profile mlx5e_nic_profile = { .init = mlx5e_nic_init, .cleanup = mlx5e_nic_cleanup, @@ -3996,31 +4080,17 @@ struct net_device *mlx5e_create_netdev(struct mlx5_core_dev *mdev, int mlx5e_attach_netdev(struct mlx5_core_dev *mdev, struct mlx5e_priv *priv) { - const struct mlx5e_profile *profile; struct net_device *netdev; u16 max_mtu; int err; netdev = priv->netdev; - profile = priv->profile; - clear_bit(MLX5E_STATE_DESTROYING, &priv->state); - - err = profile->init_tx(priv); - if (err) - goto out; - err = mlx5e_open_drop_rq(priv); + err = mlx5n_attach_netdev_common(mdev, priv); if (err) { - mlx5_core_err(mdev, "open drop rq failed, %d\n", err); - goto err_cleanup_tx; + mlx5_core_err(mdev, "failed attach netdev %d\n", err); + return err; } - - err = profile->init_rx(priv); - if (err) - goto err_close_drop_rq; - - mlx5e_create_q_counter(priv); - //TBD do i need to change that? mlx5e_init_l2_addr(priv); /* MTU range: 68 - hw-specific max */ @@ -4030,25 +4100,7 @@ int mlx5e_attach_netdev(struct mlx5_core_dev *mdev, struct mlx5e_priv *priv) mlx5e_set_dev_port_mtu(netdev); - if (profile->enable) - profile->enable(priv); - - rtnl_lock(); - if (netif_running(netdev)) - mlx5e_open(netdev); - netif_device_attach(netdev); - rtnl_unlock(); - return 0; - -err_close_drop_rq: - mlx5e_close_drop_rq(priv); - -err_cleanup_tx: - profile->cleanup_tx(priv); - -out: - return err; } static void mlx5e_register_vport_rep(struct mlx5_core_dev *mdev)