From patchwork Wed Mar 1 14:02:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erez Shitrit X-Patchwork-Id: 9598445 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 0454F60453 for ; Wed, 1 Mar 2017 14:05:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7A8B2855D for ; Wed, 1 Mar 2017 14:05:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC79E28563; Wed, 1 Mar 2017 14:05:03 +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 7F8222855D for ; Wed, 1 Mar 2017 14:05:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751754AbdCAOFC (ORCPT ); Wed, 1 Mar 2017 09:05:02 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:33472 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751332AbdCAOEf (ORCPT ); Wed, 1 Mar 2017 09:04:35 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from erezsh@mellanox.com) with ESMTPS (AES256-SHA encrypted); 1 Mar 2017 16:02:51 +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 v21E2kkK028329; Wed, 1 Mar 2017 16:02:51 +0200 From: Erez Shitrit To: dledford@redhat.com Cc: linux-rdma@vger.kernel.org, valex@mellanox.com, leonro@mellanox.com, Erez Shitrit Subject: [RFC for accelerated IPoIB 14/26] net/mlx5e: Export resource creation function to be used in IB link Date: Wed, 1 Mar 2017 16:02:22 +0200 Message-Id: <1488376954-8346-15-git-send-email-erezsh@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1488376954-8346-1-git-send-email-erezsh@mellanox.com> References: <1488376954-8346-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 eedbe3947423..726d516b7ea8 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, @@ -3943,6 +3991,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, @@ -3997,31 +4081,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 */ @@ -4031,25 +4101,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)