18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
58c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
68c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
78c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
88c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
118c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
128c2ecf20Sopenharmony_ci *     conditions are met:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
158c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
168c2ecf20Sopenharmony_ci *        disclaimer.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
198c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
208c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
218c2ecf20Sopenharmony_ci *        provided with the distribution.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
248c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
258c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
268c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
278c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
288c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
298c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
308c2ecf20Sopenharmony_ci * SOFTWARE.
318c2ecf20Sopenharmony_ci *
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include <linux/cpumask.h>
358c2ecf20Sopenharmony_ci#include <linux/module.h>
368c2ecf20Sopenharmony_ci#include <linux/delay.h>
378c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
388c2ecf20Sopenharmony_ci#include <linux/slab.h>
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#include <linux/mlx4/driver.h>
418c2ecf20Sopenharmony_ci#include <linux/mlx4/device.h>
428c2ecf20Sopenharmony_ci#include <linux/mlx4/cmd.h>
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#include "mlx4_en.h"
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ciMODULE_AUTHOR("Liran Liss, Yevgeny Petrilin");
478c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Mellanox ConnectX HCA Ethernet driver");
488c2ecf20Sopenharmony_ciMODULE_LICENSE("Dual BSD/GPL");
498c2ecf20Sopenharmony_ciMODULE_VERSION(DRV_VERSION);
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistatic const char mlx4_en_version[] =
528c2ecf20Sopenharmony_ci	DRV_NAME ": Mellanox ConnectX HCA Ethernet driver v"
538c2ecf20Sopenharmony_ci	DRV_VERSION "\n";
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#define MLX4_EN_PARM_INT(X, def_val, desc) \
568c2ecf20Sopenharmony_ci	static unsigned int X = def_val;\
578c2ecf20Sopenharmony_ci	module_param(X , uint, 0444); \
588c2ecf20Sopenharmony_ci	MODULE_PARM_DESC(X, desc);
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci/*
628c2ecf20Sopenharmony_ci * Device scope module parameters
638c2ecf20Sopenharmony_ci */
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/* Enable RSS UDP traffic */
668c2ecf20Sopenharmony_ciMLX4_EN_PARM_INT(udp_rss, 1,
678c2ecf20Sopenharmony_ci		 "Enable RSS for incoming UDP traffic or disabled (0)");
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* Priority pausing */
708c2ecf20Sopenharmony_ciMLX4_EN_PARM_INT(pfctx, 0, "Priority based Flow Control policy on TX[7:0]."
718c2ecf20Sopenharmony_ci			   " Per priority bit mask");
728c2ecf20Sopenharmony_ciMLX4_EN_PARM_INT(pfcrx, 0, "Priority based Flow Control policy on RX[7:0]."
738c2ecf20Sopenharmony_ci			   " Per priority bit mask");
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciMLX4_EN_PARM_INT(inline_thold, MAX_INLINE,
768c2ecf20Sopenharmony_ci		 "Threshold for using inline data (range: 17-104, default: 104)");
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#define MAX_PFC_TX     0xff
798c2ecf20Sopenharmony_ci#define MAX_PFC_RX     0xff
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_civoid en_print(const char *level, const struct mlx4_en_priv *priv,
828c2ecf20Sopenharmony_ci	      const char *format, ...)
838c2ecf20Sopenharmony_ci{
848c2ecf20Sopenharmony_ci	va_list args;
858c2ecf20Sopenharmony_ci	struct va_format vaf;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	va_start(args, format);
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	vaf.fmt = format;
908c2ecf20Sopenharmony_ci	vaf.va = &args;
918c2ecf20Sopenharmony_ci	if (priv->registered)
928c2ecf20Sopenharmony_ci		printk("%s%s: %s: %pV",
938c2ecf20Sopenharmony_ci		       level, DRV_NAME, priv->dev->name, &vaf);
948c2ecf20Sopenharmony_ci	else
958c2ecf20Sopenharmony_ci		printk("%s%s: %s: Port %d: %pV",
968c2ecf20Sopenharmony_ci		       level, DRV_NAME, dev_name(&priv->mdev->pdev->dev),
978c2ecf20Sopenharmony_ci		       priv->port, &vaf);
988c2ecf20Sopenharmony_ci	va_end(args);
998c2ecf20Sopenharmony_ci}
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_civoid mlx4_en_update_loopback_state(struct net_device *dev,
1028c2ecf20Sopenharmony_ci				   netdev_features_t features)
1038c2ecf20Sopenharmony_ci{
1048c2ecf20Sopenharmony_ci	struct mlx4_en_priv *priv = netdev_priv(dev);
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	if (features & NETIF_F_LOOPBACK)
1078c2ecf20Sopenharmony_ci		priv->ctrl_flags |= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK);
1088c2ecf20Sopenharmony_ci	else
1098c2ecf20Sopenharmony_ci		priv->ctrl_flags &= cpu_to_be32(~MLX4_WQE_CTRL_FORCE_LOOPBACK);
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	priv->flags &= ~(MLX4_EN_FLAG_RX_FILTER_NEEDED|
1128c2ecf20Sopenharmony_ci			MLX4_EN_FLAG_ENABLE_HW_LOOPBACK);
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	/* Drop the packet if SRIOV is not enabled
1158c2ecf20Sopenharmony_ci	 * and not performing the selftest or flb disabled
1168c2ecf20Sopenharmony_ci	 */
1178c2ecf20Sopenharmony_ci	if (mlx4_is_mfunc(priv->mdev->dev) &&
1188c2ecf20Sopenharmony_ci	    !(features & NETIF_F_LOOPBACK) && !priv->validate_loopback)
1198c2ecf20Sopenharmony_ci		priv->flags |= MLX4_EN_FLAG_RX_FILTER_NEEDED;
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	/* Set dmac in Tx WQE if we are in SRIOV mode or if loopback selftest
1228c2ecf20Sopenharmony_ci	 * is requested
1238c2ecf20Sopenharmony_ci	 */
1248c2ecf20Sopenharmony_ci	if (mlx4_is_mfunc(priv->mdev->dev) || priv->validate_loopback)
1258c2ecf20Sopenharmony_ci		priv->flags |= MLX4_EN_FLAG_ENABLE_HW_LOOPBACK;
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci	mutex_lock(&priv->mdev->state_lock);
1288c2ecf20Sopenharmony_ci	if ((priv->mdev->dev->caps.flags2 &
1298c2ecf20Sopenharmony_ci	     MLX4_DEV_CAP_FLAG2_UPDATE_QP_SRC_CHECK_LB) &&
1308c2ecf20Sopenharmony_ci	    priv->rss_map.indir_qp && priv->rss_map.indir_qp->qpn) {
1318c2ecf20Sopenharmony_ci		int i;
1328c2ecf20Sopenharmony_ci		int err = 0;
1338c2ecf20Sopenharmony_ci		int loopback = !!(features & NETIF_F_LOOPBACK);
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci		for (i = 0; i < priv->rx_ring_num; i++) {
1368c2ecf20Sopenharmony_ci			int ret;
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci			ret = mlx4_en_change_mcast_lb(priv,
1398c2ecf20Sopenharmony_ci						      &priv->rss_map.qps[i],
1408c2ecf20Sopenharmony_ci						      loopback);
1418c2ecf20Sopenharmony_ci			if (!err)
1428c2ecf20Sopenharmony_ci				err = ret;
1438c2ecf20Sopenharmony_ci		}
1448c2ecf20Sopenharmony_ci		if (err)
1458c2ecf20Sopenharmony_ci			mlx4_warn(priv->mdev, "failed to change mcast loopback\n");
1468c2ecf20Sopenharmony_ci	}
1478c2ecf20Sopenharmony_ci	mutex_unlock(&priv->mdev->state_lock);
1488c2ecf20Sopenharmony_ci}
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cistatic void mlx4_en_get_profile(struct mlx4_en_dev *mdev)
1518c2ecf20Sopenharmony_ci{
1528c2ecf20Sopenharmony_ci	struct mlx4_en_profile *params = &mdev->profile;
1538c2ecf20Sopenharmony_ci	int i;
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	params->udp_rss = udp_rss;
1568c2ecf20Sopenharmony_ci	params->max_num_tx_rings_p_up = mlx4_low_memory_profile() ?
1578c2ecf20Sopenharmony_ci		MLX4_EN_MIN_TX_RING_P_UP :
1588c2ecf20Sopenharmony_ci		min_t(int, num_online_cpus(), MLX4_EN_MAX_TX_RING_P_UP);
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	if (params->udp_rss && !(mdev->dev->caps.flags
1618c2ecf20Sopenharmony_ci					& MLX4_DEV_CAP_FLAG_UDP_RSS)) {
1628c2ecf20Sopenharmony_ci		mlx4_warn(mdev, "UDP RSS is not supported on this device\n");
1638c2ecf20Sopenharmony_ci		params->udp_rss = 0;
1648c2ecf20Sopenharmony_ci	}
1658c2ecf20Sopenharmony_ci	for (i = 1; i <= MLX4_MAX_PORTS; i++) {
1668c2ecf20Sopenharmony_ci		params->prof[i].rx_pause = !(pfcrx || pfctx);
1678c2ecf20Sopenharmony_ci		params->prof[i].rx_ppp = pfcrx;
1688c2ecf20Sopenharmony_ci		params->prof[i].tx_pause = !(pfcrx || pfctx);
1698c2ecf20Sopenharmony_ci		params->prof[i].tx_ppp = pfctx;
1708c2ecf20Sopenharmony_ci		if (mlx4_low_memory_profile()) {
1718c2ecf20Sopenharmony_ci			params->prof[i].tx_ring_size = MLX4_EN_MIN_TX_SIZE;
1728c2ecf20Sopenharmony_ci			params->prof[i].rx_ring_size = MLX4_EN_MIN_RX_SIZE;
1738c2ecf20Sopenharmony_ci		} else {
1748c2ecf20Sopenharmony_ci			params->prof[i].tx_ring_size = MLX4_EN_DEF_TX_RING_SIZE;
1758c2ecf20Sopenharmony_ci			params->prof[i].rx_ring_size = MLX4_EN_DEF_RX_RING_SIZE;
1768c2ecf20Sopenharmony_ci		}
1778c2ecf20Sopenharmony_ci		params->prof[i].num_up = MLX4_EN_NUM_UP_LOW;
1788c2ecf20Sopenharmony_ci		params->prof[i].num_tx_rings_p_up = params->max_num_tx_rings_p_up;
1798c2ecf20Sopenharmony_ci		params->prof[i].tx_ring_num[TX] = params->max_num_tx_rings_p_up *
1808c2ecf20Sopenharmony_ci			params->prof[i].num_up;
1818c2ecf20Sopenharmony_ci		params->prof[i].rss_rings = 0;
1828c2ecf20Sopenharmony_ci		params->prof[i].inline_thold = inline_thold;
1838c2ecf20Sopenharmony_ci	}
1848c2ecf20Sopenharmony_ci}
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_cistatic void *mlx4_en_get_netdev(struct mlx4_dev *dev, void *ctx, u8 port)
1878c2ecf20Sopenharmony_ci{
1888c2ecf20Sopenharmony_ci	struct mlx4_en_dev *endev = ctx;
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci	return endev->pndev[port];
1918c2ecf20Sopenharmony_ci}
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_cistatic void mlx4_en_event(struct mlx4_dev *dev, void *endev_ptr,
1948c2ecf20Sopenharmony_ci			  enum mlx4_dev_event event, unsigned long port)
1958c2ecf20Sopenharmony_ci{
1968c2ecf20Sopenharmony_ci	struct mlx4_en_dev *mdev = (struct mlx4_en_dev *) endev_ptr;
1978c2ecf20Sopenharmony_ci	struct mlx4_en_priv *priv;
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	switch (event) {
2008c2ecf20Sopenharmony_ci	case MLX4_DEV_EVENT_PORT_UP:
2018c2ecf20Sopenharmony_ci	case MLX4_DEV_EVENT_PORT_DOWN:
2028c2ecf20Sopenharmony_ci		if (!mdev->pndev[port])
2038c2ecf20Sopenharmony_ci			return;
2048c2ecf20Sopenharmony_ci		priv = netdev_priv(mdev->pndev[port]);
2058c2ecf20Sopenharmony_ci		/* To prevent races, we poll the link state in a separate
2068c2ecf20Sopenharmony_ci		  task rather than changing it here */
2078c2ecf20Sopenharmony_ci		priv->link_state = event;
2088c2ecf20Sopenharmony_ci		queue_work(mdev->workqueue, &priv->linkstate_task);
2098c2ecf20Sopenharmony_ci		break;
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci	case MLX4_DEV_EVENT_CATASTROPHIC_ERROR:
2128c2ecf20Sopenharmony_ci		mlx4_err(mdev, "Internal error detected, restarting device\n");
2138c2ecf20Sopenharmony_ci		break;
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	case MLX4_DEV_EVENT_SLAVE_INIT:
2168c2ecf20Sopenharmony_ci	case MLX4_DEV_EVENT_SLAVE_SHUTDOWN:
2178c2ecf20Sopenharmony_ci		break;
2188c2ecf20Sopenharmony_ci	default:
2198c2ecf20Sopenharmony_ci		if (port < 1 || port > dev->caps.num_ports ||
2208c2ecf20Sopenharmony_ci		    !mdev->pndev[port])
2218c2ecf20Sopenharmony_ci			return;
2228c2ecf20Sopenharmony_ci		mlx4_warn(mdev, "Unhandled event %d for port %d\n", event,
2238c2ecf20Sopenharmony_ci			  (int) port);
2248c2ecf20Sopenharmony_ci	}
2258c2ecf20Sopenharmony_ci}
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_cistatic void mlx4_en_remove(struct mlx4_dev *dev, void *endev_ptr)
2288c2ecf20Sopenharmony_ci{
2298c2ecf20Sopenharmony_ci	struct mlx4_en_dev *mdev = endev_ptr;
2308c2ecf20Sopenharmony_ci	int i;
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	mutex_lock(&mdev->state_lock);
2338c2ecf20Sopenharmony_ci	mdev->device_up = false;
2348c2ecf20Sopenharmony_ci	mutex_unlock(&mdev->state_lock);
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH)
2378c2ecf20Sopenharmony_ci		if (mdev->pndev[i])
2388c2ecf20Sopenharmony_ci			mlx4_en_destroy_netdev(mdev->pndev[i]);
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci	flush_workqueue(mdev->workqueue);
2418c2ecf20Sopenharmony_ci	destroy_workqueue(mdev->workqueue);
2428c2ecf20Sopenharmony_ci	(void) mlx4_mr_free(dev, &mdev->mr);
2438c2ecf20Sopenharmony_ci	iounmap(mdev->uar_map);
2448c2ecf20Sopenharmony_ci	mlx4_uar_free(dev, &mdev->priv_uar);
2458c2ecf20Sopenharmony_ci	mlx4_pd_free(dev, mdev->priv_pdn);
2468c2ecf20Sopenharmony_ci	if (mdev->nb.notifier_call)
2478c2ecf20Sopenharmony_ci		unregister_netdevice_notifier(&mdev->nb);
2488c2ecf20Sopenharmony_ci	kfree(mdev);
2498c2ecf20Sopenharmony_ci}
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_cistatic void mlx4_en_activate(struct mlx4_dev *dev, void *ctx)
2528c2ecf20Sopenharmony_ci{
2538c2ecf20Sopenharmony_ci	int i;
2548c2ecf20Sopenharmony_ci	struct mlx4_en_dev *mdev = ctx;
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci	/* Create a netdev for each port */
2578c2ecf20Sopenharmony_ci	mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) {
2588c2ecf20Sopenharmony_ci		mlx4_info(mdev, "Activating port:%d\n", i);
2598c2ecf20Sopenharmony_ci		if (mlx4_en_init_netdev(mdev, i, &mdev->profile.prof[i]))
2608c2ecf20Sopenharmony_ci			mdev->pndev[i] = NULL;
2618c2ecf20Sopenharmony_ci	}
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci	/* register notifier */
2648c2ecf20Sopenharmony_ci	mdev->nb.notifier_call = mlx4_en_netdev_event;
2658c2ecf20Sopenharmony_ci	if (register_netdevice_notifier(&mdev->nb)) {
2668c2ecf20Sopenharmony_ci		mdev->nb.notifier_call = NULL;
2678c2ecf20Sopenharmony_ci		mlx4_err(mdev, "Failed to create notifier\n");
2688c2ecf20Sopenharmony_ci	}
2698c2ecf20Sopenharmony_ci}
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_cistatic void *mlx4_en_add(struct mlx4_dev *dev)
2728c2ecf20Sopenharmony_ci{
2738c2ecf20Sopenharmony_ci	struct mlx4_en_dev *mdev;
2748c2ecf20Sopenharmony_ci	int i;
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	printk_once(KERN_INFO "%s", mlx4_en_version);
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci	mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
2798c2ecf20Sopenharmony_ci	if (!mdev)
2808c2ecf20Sopenharmony_ci		goto err_free_res;
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	if (mlx4_pd_alloc(dev, &mdev->priv_pdn))
2838c2ecf20Sopenharmony_ci		goto err_free_dev;
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	if (mlx4_uar_alloc(dev, &mdev->priv_uar))
2868c2ecf20Sopenharmony_ci		goto err_pd;
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci	mdev->uar_map = ioremap((phys_addr_t) mdev->priv_uar.pfn << PAGE_SHIFT,
2898c2ecf20Sopenharmony_ci				PAGE_SIZE);
2908c2ecf20Sopenharmony_ci	if (!mdev->uar_map)
2918c2ecf20Sopenharmony_ci		goto err_uar;
2928c2ecf20Sopenharmony_ci	spin_lock_init(&mdev->uar_lock);
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	mdev->dev = dev;
2958c2ecf20Sopenharmony_ci	mdev->dma_device = &dev->persist->pdev->dev;
2968c2ecf20Sopenharmony_ci	mdev->pdev = dev->persist->pdev;
2978c2ecf20Sopenharmony_ci	mdev->device_up = false;
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci	mdev->LSO_support = !!(dev->caps.flags & (1 << 15));
3008c2ecf20Sopenharmony_ci	if (!mdev->LSO_support)
3018c2ecf20Sopenharmony_ci		mlx4_warn(mdev, "LSO not supported, please upgrade to later FW version to enable LSO\n");
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci	if (mlx4_mr_alloc(mdev->dev, mdev->priv_pdn, 0, ~0ull,
3048c2ecf20Sopenharmony_ci			 MLX4_PERM_LOCAL_WRITE |  MLX4_PERM_LOCAL_READ,
3058c2ecf20Sopenharmony_ci			 0, 0, &mdev->mr)) {
3068c2ecf20Sopenharmony_ci		mlx4_err(mdev, "Failed allocating memory region\n");
3078c2ecf20Sopenharmony_ci		goto err_map;
3088c2ecf20Sopenharmony_ci	}
3098c2ecf20Sopenharmony_ci	if (mlx4_mr_enable(mdev->dev, &mdev->mr)) {
3108c2ecf20Sopenharmony_ci		mlx4_err(mdev, "Failed enabling memory region\n");
3118c2ecf20Sopenharmony_ci		goto err_mr;
3128c2ecf20Sopenharmony_ci	}
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_ci	/* Build device profile according to supplied module parameters */
3158c2ecf20Sopenharmony_ci	mlx4_en_get_profile(mdev);
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci	/* Configure which ports to start according to module parameters */
3188c2ecf20Sopenharmony_ci	mdev->port_cnt = 0;
3198c2ecf20Sopenharmony_ci	mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH)
3208c2ecf20Sopenharmony_ci		mdev->port_cnt++;
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci	/* Set default number of RX rings*/
3238c2ecf20Sopenharmony_ci	mlx4_en_set_num_rx_rings(mdev);
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	/* Create our own workqueue for reset/multicast tasks
3268c2ecf20Sopenharmony_ci	 * Note: we cannot use the shared workqueue because of deadlocks caused
3278c2ecf20Sopenharmony_ci	 *       by the rtnl lock */
3288c2ecf20Sopenharmony_ci	mdev->workqueue = create_singlethread_workqueue("mlx4_en");
3298c2ecf20Sopenharmony_ci	if (!mdev->workqueue)
3308c2ecf20Sopenharmony_ci		goto err_mr;
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	/* At this stage all non-port specific tasks are complete:
3338c2ecf20Sopenharmony_ci	 * mark the card state as up */
3348c2ecf20Sopenharmony_ci	mutex_init(&mdev->state_lock);
3358c2ecf20Sopenharmony_ci	mdev->device_up = true;
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	return mdev;
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_cierr_mr:
3408c2ecf20Sopenharmony_ci	(void) mlx4_mr_free(dev, &mdev->mr);
3418c2ecf20Sopenharmony_cierr_map:
3428c2ecf20Sopenharmony_ci	if (mdev->uar_map)
3438c2ecf20Sopenharmony_ci		iounmap(mdev->uar_map);
3448c2ecf20Sopenharmony_cierr_uar:
3458c2ecf20Sopenharmony_ci	mlx4_uar_free(dev, &mdev->priv_uar);
3468c2ecf20Sopenharmony_cierr_pd:
3478c2ecf20Sopenharmony_ci	mlx4_pd_free(dev, mdev->priv_pdn);
3488c2ecf20Sopenharmony_cierr_free_dev:
3498c2ecf20Sopenharmony_ci	kfree(mdev);
3508c2ecf20Sopenharmony_cierr_free_res:
3518c2ecf20Sopenharmony_ci	return NULL;
3528c2ecf20Sopenharmony_ci}
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_cistatic struct mlx4_interface mlx4_en_interface = {
3558c2ecf20Sopenharmony_ci	.add		= mlx4_en_add,
3568c2ecf20Sopenharmony_ci	.remove		= mlx4_en_remove,
3578c2ecf20Sopenharmony_ci	.event		= mlx4_en_event,
3588c2ecf20Sopenharmony_ci	.get_dev	= mlx4_en_get_netdev,
3598c2ecf20Sopenharmony_ci	.protocol	= MLX4_PROT_ETH,
3608c2ecf20Sopenharmony_ci	.activate	= mlx4_en_activate,
3618c2ecf20Sopenharmony_ci};
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_cistatic void mlx4_en_verify_params(void)
3648c2ecf20Sopenharmony_ci{
3658c2ecf20Sopenharmony_ci	if (pfctx > MAX_PFC_TX) {
3668c2ecf20Sopenharmony_ci		pr_warn("mlx4_en: WARNING: illegal module parameter pfctx 0x%x - should be in range 0-0x%x, will be changed to default (0)\n",
3678c2ecf20Sopenharmony_ci			pfctx, MAX_PFC_TX);
3688c2ecf20Sopenharmony_ci		pfctx = 0;
3698c2ecf20Sopenharmony_ci	}
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	if (pfcrx > MAX_PFC_RX) {
3728c2ecf20Sopenharmony_ci		pr_warn("mlx4_en: WARNING: illegal module parameter pfcrx 0x%x - should be in range 0-0x%x, will be changed to default (0)\n",
3738c2ecf20Sopenharmony_ci			pfcrx, MAX_PFC_RX);
3748c2ecf20Sopenharmony_ci		pfcrx = 0;
3758c2ecf20Sopenharmony_ci	}
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	if (inline_thold < MIN_PKT_LEN || inline_thold > MAX_INLINE) {
3788c2ecf20Sopenharmony_ci		pr_warn("mlx4_en: WARNING: illegal module parameter inline_thold %d - should be in range %d-%d, will be changed to default (%d)\n",
3798c2ecf20Sopenharmony_ci			inline_thold, MIN_PKT_LEN, MAX_INLINE, MAX_INLINE);
3808c2ecf20Sopenharmony_ci		inline_thold = MAX_INLINE;
3818c2ecf20Sopenharmony_ci	}
3828c2ecf20Sopenharmony_ci}
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_cistatic int __init mlx4_en_init(void)
3858c2ecf20Sopenharmony_ci{
3868c2ecf20Sopenharmony_ci	mlx4_en_verify_params();
3878c2ecf20Sopenharmony_ci	mlx4_en_init_ptys2ethtool_map();
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	return mlx4_register_interface(&mlx4_en_interface);
3908c2ecf20Sopenharmony_ci}
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_cistatic void __exit mlx4_en_cleanup(void)
3938c2ecf20Sopenharmony_ci{
3948c2ecf20Sopenharmony_ci	mlx4_unregister_interface(&mlx4_en_interface);
3958c2ecf20Sopenharmony_ci}
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_cimodule_init(mlx4_en_init);
3988c2ecf20Sopenharmony_cimodule_exit(mlx4_en_cleanup);
3998c2ecf20Sopenharmony_ci
400