Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
[linux-2.6-block.git] / drivers / net / ethernet / mellanox / mlx5 / core / main.c
index ef196cb764e2a3edaf640c29e928954f1c1d1475..fbd4dd76a19f3c908dcb88c69f1c5a47a35659a1 100644 (file)
@@ -62,9 +62,7 @@
 #include "lib/mlx5.h"
 #include "lib/tout.h"
 #include "fpga/core.h"
-#include "fpga/ipsec.h"
-#include "accel/ipsec.h"
-#include "accel/tls.h"
+#include "en_accel/ipsec.h"
 #include "lib/clock.h"
 #include "lib/vxlan.h"
 #include "lib/geneve.h"
@@ -179,30 +177,30 @@ static struct mlx5_profile profile[] = {
        },
 };
 
-static int fw_initializing(struct mlx5_core_dev *dev)
-{
-       return ioread32be(&dev->iseg->initializing) >> 31;
-}
-
 static int wait_fw_init(struct mlx5_core_dev *dev, u32 max_wait_mili,
                        u32 warn_time_mili)
 {
        unsigned long warn = jiffies + msecs_to_jiffies(warn_time_mili);
        unsigned long end = jiffies + msecs_to_jiffies(max_wait_mili);
+       u32 fw_initializing;
        int err = 0;
 
-       while (fw_initializing(dev)) {
-               if (time_after(jiffies, end)) {
+       do {
+               fw_initializing = ioread32be(&dev->iseg->initializing);
+               if (!(fw_initializing >> 31))
+                       break;
+               if (time_after(jiffies, end) ||
+                   test_and_clear_bit(MLX5_BREAK_FW_WAIT, &dev->intf_state)) {
                        err = -EBUSY;
                        break;
                }
                if (warn_time_mili && time_after(jiffies, warn)) {
-                       mlx5_core_warn(dev, "Waiting for FW initialization, timeout abort in %ds\n",
-                                      jiffies_to_msecs(end - warn) / 1000);
+                       mlx5_core_warn(dev, "Waiting for FW initialization, timeout abort in %ds (0x%x)\n",
+                                      jiffies_to_msecs(end - warn) / 1000, fw_initializing);
                        warn = jiffies + msecs_to_jiffies(warn_time_mili);
                }
                msleep(mlx5_tout_ms(dev, FW_PRE_INIT_WAIT));
-       }
+       } while (true);
 
        return err;
 }
@@ -1014,7 +1012,7 @@ static void mlx5_cleanup_once(struct mlx5_core_dev *dev)
        mlx5_devcom_unregister_device(dev->priv.devcom);
 }
 
-static int mlx5_function_setup(struct mlx5_core_dev *dev, bool boot)
+static int mlx5_function_setup(struct mlx5_core_dev *dev, u64 timeout)
 {
        int err;
 
@@ -1029,11 +1027,11 @@ static int mlx5_function_setup(struct mlx5_core_dev *dev, bool boot)
 
        /* wait for firmware to accept initialization segments configurations
         */
-       err = wait_fw_init(dev, mlx5_tout_ms(dev, FW_PRE_INIT_TIMEOUT),
+       err = wait_fw_init(dev, timeout,
                           mlx5_tout_ms(dev, FW_PRE_INIT_WARN_MESSAGE_INTERVAL));
        if (err) {
                mlx5_core_err(dev, "Firmware over %llu MS in pre-initializing state, aborting\n",
-                             mlx5_tout_ms(dev, FW_PRE_INIT_TIMEOUT));
+                             timeout);
                return err;
        }
 
@@ -1192,14 +1190,6 @@ static int mlx5_load(struct mlx5_core_dev *dev)
                goto err_fpga_start;
        }
 
-       mlx5_accel_ipsec_init(dev);
-
-       err = mlx5_accel_tls_init(dev);
-       if (err) {
-               mlx5_core_err(dev, "TLS device start failed %d\n", err);
-               goto err_tls_start;
-       }
-
        err = mlx5_fs_core_init(dev);
        if (err) {
                mlx5_core_err(dev, "Failed to init flow steering\n");
@@ -1247,9 +1237,6 @@ err_vhca:
 err_set_hca:
        mlx5_fs_core_cleanup(dev);
 err_fs:
-       mlx5_accel_tls_cleanup(dev);
-err_tls_start:
-       mlx5_accel_ipsec_cleanup(dev);
        mlx5_fpga_device_stop(dev);
 err_fpga_start:
        mlx5_rsc_dump_cleanup(dev);
@@ -1275,8 +1262,6 @@ static void mlx5_unload(struct mlx5_core_dev *dev)
        mlx5_sf_hw_table_destroy(dev);
        mlx5_vhca_event_stop(dev);
        mlx5_fs_core_cleanup(dev);
-       mlx5_accel_ipsec_cleanup(dev);
-       mlx5_accel_tls_cleanup(dev);
        mlx5_fpga_device_stop(dev);
        mlx5_rsc_dump_cleanup(dev);
        mlx5_hv_vhca_cleanup(dev->hv_vhca);
@@ -1296,7 +1281,7 @@ int mlx5_init_one(struct mlx5_core_dev *dev)
        mutex_lock(&dev->intf_state_mutex);
        dev->state = MLX5_DEVICE_STATE_UP;
 
-       err = mlx5_function_setup(dev, true);
+       err = mlx5_function_setup(dev, mlx5_tout_ms(dev, FW_PRE_INIT_TIMEOUT));
        if (err)
                goto err_function;
 
@@ -1360,9 +1345,10 @@ out:
        mutex_unlock(&dev->intf_state_mutex);
 }
 
-int mlx5_load_one(struct mlx5_core_dev *dev)
+int mlx5_load_one(struct mlx5_core_dev *dev, bool recovery)
 {
        int err = 0;
+       u64 timeout;
 
        mutex_lock(&dev->intf_state_mutex);
        if (test_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state)) {
@@ -1372,7 +1358,11 @@ int mlx5_load_one(struct mlx5_core_dev *dev)
        /* remove any previous indication of internal error */
        dev->state = MLX5_DEVICE_STATE_UP;
 
-       err = mlx5_function_setup(dev, false);
+       if (recovery)
+               timeout = mlx5_tout_ms(dev, FW_PRE_INIT_ON_RECOVERY_TIMEOUT);
+       else
+               timeout = mlx5_tout_ms(dev, FW_PRE_INIT_TIMEOUT);
+       err = mlx5_function_setup(dev, timeout);
        if (err)
                goto err_function;
 
@@ -1631,6 +1621,7 @@ static void remove_one(struct pci_dev *pdev)
         * fw_reset before unregistering the devlink.
         */
        mlx5_drain_fw_reset(dev);
+       set_bit(MLX5_BREAK_FW_WAIT, &dev->intf_state);
        devlink_unregister(devlink);
        mlx5_sriov_disable(pdev);
        mlx5_crdump_disable(dev);
@@ -1746,7 +1737,7 @@ static void mlx5_pci_resume(struct pci_dev *pdev)
 
        mlx5_pci_trace(dev, "Enter, loading driver..\n");
 
-       err = mlx5_load_one(dev);
+       err = mlx5_load_one(dev, false);
 
        mlx5_pci_trace(dev, "Done, err = %d, device %s\n", err,
                       !err ? "recovered" : "Failed");
@@ -1814,6 +1805,7 @@ static void shutdown(struct pci_dev *pdev)
        int err;
 
        mlx5_core_info(dev, "Shutdown was called\n");
+       set_bit(MLX5_BREAK_FW_WAIT, &dev->intf_state);
        err = mlx5_try_fast_unload(dev);
        if (err)
                mlx5_unload_one(dev);
@@ -1833,7 +1825,7 @@ static int mlx5_resume(struct pci_dev *pdev)
 {
        struct mlx5_core_dev *dev = pci_get_drvdata(pdev);
 
-       return mlx5_load_one(dev);
+       return mlx5_load_one(dev, false);
 }
 
 static const struct pci_device_id mlx5_core_pci_table[] = {
@@ -1878,7 +1870,7 @@ int mlx5_recover_device(struct mlx5_core_dev *dev)
                        return -EIO;
        }
 
-       return mlx5_load_one(dev);
+       return mlx5_load_one(dev, true);
 }
 
 static struct pci_driver mlx5_core_driver = {
@@ -1907,7 +1899,6 @@ static struct pci_driver mlx5_core_driver = {
  * Return: Pointer to the associated mlx5_core_dev or NULL.
  */
 struct mlx5_core_dev *mlx5_vf_get_core_dev(struct pci_dev *pdev)
-                       __acquires(&mdev->intf_state_mutex)
 {
        struct mlx5_core_dev *mdev;
 
@@ -1933,7 +1924,6 @@ EXPORT_SYMBOL(mlx5_vf_get_core_dev);
  * access the mdev any more.
  */
 void mlx5_vf_put_core_dev(struct mlx5_core_dev *mdev)
-                       __releases(&mdev->intf_state_mutex)
 {
        mutex_unlock(&mdev->intf_state_mutex);
 }
@@ -1960,7 +1950,6 @@ static int __init init(void)
        get_random_bytes(&sw_owner_id, sizeof(sw_owner_id));
 
        mlx5_core_verify_params();
-       mlx5_fpga_ipsec_build_fs_cmds();
        mlx5_register_debugfs();
 
        err = pci_register_driver(&mlx5_core_driver);