xref: /linux/drivers/net/ethernet/mellanox/mlx4/en_main.c (revision a1c613ae4c322ddd58d5a8539dbfba2a0380a8c0)
15a2cc190SJeff Kirsher /*
25a2cc190SJeff Kirsher  * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
35a2cc190SJeff Kirsher  *
45a2cc190SJeff Kirsher  * This software is available to you under a choice of one of two
55a2cc190SJeff Kirsher  * licenses.  You may choose to be licensed under the terms of the GNU
65a2cc190SJeff Kirsher  * General Public License (GPL) Version 2, available from the file
75a2cc190SJeff Kirsher  * COPYING in the main directory of this source tree, or the
85a2cc190SJeff Kirsher  * OpenIB.org BSD license below:
95a2cc190SJeff Kirsher  *
105a2cc190SJeff Kirsher  *     Redistribution and use in source and binary forms, with or
115a2cc190SJeff Kirsher  *     without modification, are permitted provided that the following
125a2cc190SJeff Kirsher  *     conditions are met:
135a2cc190SJeff Kirsher  *
145a2cc190SJeff Kirsher  *      - Redistributions of source code must retain the above
155a2cc190SJeff Kirsher  *        copyright notice, this list of conditions and the following
165a2cc190SJeff Kirsher  *        disclaimer.
175a2cc190SJeff Kirsher  *
185a2cc190SJeff Kirsher  *      - Redistributions in binary form must reproduce the above
195a2cc190SJeff Kirsher  *        copyright notice, this list of conditions and the following
205a2cc190SJeff Kirsher  *        disclaimer in the documentation and/or other materials
215a2cc190SJeff Kirsher  *        provided with the distribution.
225a2cc190SJeff Kirsher  *
235a2cc190SJeff Kirsher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
245a2cc190SJeff Kirsher  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
255a2cc190SJeff Kirsher  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
265a2cc190SJeff Kirsher  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
275a2cc190SJeff Kirsher  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
285a2cc190SJeff Kirsher  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
295a2cc190SJeff Kirsher  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
305a2cc190SJeff Kirsher  * SOFTWARE.
315a2cc190SJeff Kirsher  *
325a2cc190SJeff Kirsher  */
335a2cc190SJeff Kirsher 
345a2cc190SJeff Kirsher #include <linux/cpumask.h>
355a2cc190SJeff Kirsher #include <linux/module.h>
365a2cc190SJeff Kirsher #include <linux/delay.h>
375a2cc190SJeff Kirsher #include <linux/netdevice.h>
385a2cc190SJeff Kirsher #include <linux/slab.h>
395a2cc190SJeff Kirsher 
405a2cc190SJeff Kirsher #include <linux/mlx4/driver.h>
415a2cc190SJeff Kirsher #include <linux/mlx4/device.h>
425a2cc190SJeff Kirsher #include <linux/mlx4/cmd.h>
435a2cc190SJeff Kirsher 
445a2cc190SJeff Kirsher #include "mlx4_en.h"
455a2cc190SJeff Kirsher 
465a2cc190SJeff Kirsher MODULE_AUTHOR("Liran Liss, Yevgeny Petrilin");
475a2cc190SJeff Kirsher MODULE_DESCRIPTION("Mellanox ConnectX HCA Ethernet driver");
485a2cc190SJeff Kirsher MODULE_LICENSE("Dual BSD/GPL");
49808df6a2STariq Toukan MODULE_VERSION(DRV_VERSION);
505a2cc190SJeff Kirsher 
515a2cc190SJeff Kirsher static const char mlx4_en_version[] =
525a2cc190SJeff Kirsher 	DRV_NAME ": Mellanox ConnectX HCA Ethernet driver v"
53808df6a2STariq Toukan 	DRV_VERSION "\n";
545a2cc190SJeff Kirsher 
555a2cc190SJeff Kirsher #define MLX4_EN_PARM_INT(X, def_val, desc) \
565a2cc190SJeff Kirsher 	static unsigned int X = def_val;\
575a2cc190SJeff Kirsher 	module_param(X , uint, 0444); \
585a2cc190SJeff Kirsher 	MODULE_PARM_DESC(X, desc);
595a2cc190SJeff Kirsher 
605a2cc190SJeff Kirsher 
615a2cc190SJeff Kirsher /*
625a2cc190SJeff Kirsher  * Device scope module parameters
635a2cc190SJeff Kirsher  */
645a2cc190SJeff Kirsher 
655a2cc190SJeff Kirsher /* Enable RSS UDP traffic */
665a2cc190SJeff Kirsher MLX4_EN_PARM_INT(udp_rss, 1,
67d82603c6SJorrit Schippers 		 "Enable RSS for incoming UDP traffic or disabled (0)");
685a2cc190SJeff Kirsher 
695a2cc190SJeff Kirsher /* Priority pausing */
705a2cc190SJeff Kirsher MLX4_EN_PARM_INT(pfctx, 0, "Priority based Flow Control policy on TX[7:0]."
715a2cc190SJeff Kirsher 			   " Per priority bit mask");
725a2cc190SJeff Kirsher MLX4_EN_PARM_INT(pfcrx, 0, "Priority based Flow Control policy on RX[7:0]."
735a2cc190SJeff Kirsher 			   " Per priority bit mask");
745a2cc190SJeff Kirsher 
75b97b33a3SEugenia Emantayev MLX4_EN_PARM_INT(inline_thold, MAX_INLINE,
76b97b33a3SEugenia Emantayev 		 "Threshold for using inline data (range: 17-104, default: 104)");
77b97b33a3SEugenia Emantayev 
78b97b33a3SEugenia Emantayev #define MAX_PFC_TX     0xff
79b97b33a3SEugenia Emantayev #define MAX_PFC_RX     0xff
80b97b33a3SEugenia Emantayev 
en_print(const char * level,const struct mlx4_en_priv * priv,const char * format,...)810c87b29cSJoe Perches void en_print(const char *level, const struct mlx4_en_priv *priv,
825a2cc190SJeff Kirsher 	      const char *format, ...)
835a2cc190SJeff Kirsher {
845a2cc190SJeff Kirsher 	va_list args;
855a2cc190SJeff Kirsher 	struct va_format vaf;
865a2cc190SJeff Kirsher 
875a2cc190SJeff Kirsher 	va_start(args, format);
885a2cc190SJeff Kirsher 
895a2cc190SJeff Kirsher 	vaf.fmt = format;
905a2cc190SJeff Kirsher 	vaf.va = &args;
915a2cc190SJeff Kirsher 	if (priv->registered)
920c87b29cSJoe Perches 		printk("%s%s: %s: %pV",
935a2cc190SJeff Kirsher 		       level, DRV_NAME, priv->dev->name, &vaf);
945a2cc190SJeff Kirsher 	else
950c87b29cSJoe Perches 		printk("%s%s: %s: Port %d: %pV",
965a2cc190SJeff Kirsher 		       level, DRV_NAME, dev_name(&priv->mdev->pdev->dev),
975a2cc190SJeff Kirsher 		       priv->port, &vaf);
985a2cc190SJeff Kirsher 	va_end(args);
995a2cc190SJeff Kirsher }
1005a2cc190SJeff Kirsher 
mlx4_en_update_loopback_state(struct net_device * dev,netdev_features_t features)10179aeaccdSYan Burman void mlx4_en_update_loopback_state(struct net_device *dev,
10279aeaccdSYan Burman 				   netdev_features_t features)
10379aeaccdSYan Burman {
10479aeaccdSYan Burman 	struct mlx4_en_priv *priv = netdev_priv(dev);
10579aeaccdSYan Burman 
106241a08c3SIdo Shamay 	if (features & NETIF_F_LOOPBACK)
107241a08c3SIdo Shamay 		priv->ctrl_flags |= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK);
108241a08c3SIdo Shamay 	else
109241a08c3SIdo Shamay 		priv->ctrl_flags &= cpu_to_be32(~MLX4_WQE_CTRL_FORCE_LOOPBACK);
110241a08c3SIdo Shamay 
11179aeaccdSYan Burman 	priv->flags &= ~(MLX4_EN_FLAG_RX_FILTER_NEEDED|
11279aeaccdSYan Burman 			MLX4_EN_FLAG_ENABLE_HW_LOOPBACK);
11379aeaccdSYan Burman 
11479aeaccdSYan Burman 	/* Drop the packet if SRIOV is not enabled
11579aeaccdSYan Burman 	 * and not performing the selftest or flb disabled
11679aeaccdSYan Burman 	 */
11779aeaccdSYan Burman 	if (mlx4_is_mfunc(priv->mdev->dev) &&
11879aeaccdSYan Burman 	    !(features & NETIF_F_LOOPBACK) && !priv->validate_loopback)
11979aeaccdSYan Burman 		priv->flags |= MLX4_EN_FLAG_RX_FILTER_NEEDED;
12079aeaccdSYan Burman 
12179aeaccdSYan Burman 	/* Set dmac in Tx WQE if we are in SRIOV mode or if loopback selftest
12279aeaccdSYan Burman 	 * is requested
12379aeaccdSYan Burman 	 */
12479aeaccdSYan Burman 	if (mlx4_is_mfunc(priv->mdev->dev) || priv->validate_loopback)
12579aeaccdSYan Burman 		priv->flags |= MLX4_EN_FLAG_ENABLE_HW_LOOPBACK;
12674194fb9SMaor Gottlieb 
12774194fb9SMaor Gottlieb 	mutex_lock(&priv->mdev->state_lock);
1284931c6efSSaeed Mahameed 	if ((priv->mdev->dev->caps.flags2 &
1294931c6efSSaeed Mahameed 	     MLX4_DEV_CAP_FLAG2_UPDATE_QP_SRC_CHECK_LB) &&
1304931c6efSSaeed Mahameed 	    priv->rss_map.indir_qp && priv->rss_map.indir_qp->qpn) {
13174194fb9SMaor Gottlieb 		int i;
13274194fb9SMaor Gottlieb 		int err = 0;
13374194fb9SMaor Gottlieb 		int loopback = !!(features & NETIF_F_LOOPBACK);
13474194fb9SMaor Gottlieb 
13574194fb9SMaor Gottlieb 		for (i = 0; i < priv->rx_ring_num; i++) {
13674194fb9SMaor Gottlieb 			int ret;
13774194fb9SMaor Gottlieb 
13874194fb9SMaor Gottlieb 			ret = mlx4_en_change_mcast_lb(priv,
13974194fb9SMaor Gottlieb 						      &priv->rss_map.qps[i],
14074194fb9SMaor Gottlieb 						      loopback);
14174194fb9SMaor Gottlieb 			if (!err)
14274194fb9SMaor Gottlieb 				err = ret;
14374194fb9SMaor Gottlieb 		}
14474194fb9SMaor Gottlieb 		if (err)
14574194fb9SMaor Gottlieb 			mlx4_warn(priv->mdev, "failed to change mcast loopback\n");
14674194fb9SMaor Gottlieb 	}
14774194fb9SMaor Gottlieb 	mutex_unlock(&priv->mdev->state_lock);
14879aeaccdSYan Burman }
14979aeaccdSYan Burman 
mlx4_en_get_profile(struct mlx4_en_dev * mdev)150f575a02eSZhu Yanjun static void mlx4_en_get_profile(struct mlx4_en_dev *mdev)
1515a2cc190SJeff Kirsher {
1525a2cc190SJeff Kirsher 	struct mlx4_en_profile *params = &mdev->profile;
1535a2cc190SJeff Kirsher 	int i;
1545a2cc190SJeff Kirsher 
1555a2cc190SJeff Kirsher 	params->udp_rss = udp_rss;
1567e1dc5e9SInbar Karmy 	params->max_num_tx_rings_p_up = mlx4_low_memory_profile() ?
157ea1c1af1SAmir Vadai 		MLX4_EN_MIN_TX_RING_P_UP :
158ea1c1af1SAmir Vadai 		min_t(int, num_online_cpus(), MLX4_EN_MAX_TX_RING_P_UP);
159ea1c1af1SAmir Vadai 
1605a2cc190SJeff Kirsher 	if (params->udp_rss && !(mdev->dev->caps.flags
1615a2cc190SJeff Kirsher 					& MLX4_DEV_CAP_FLAG_UDP_RSS)) {
1621a91de28SJoe Perches 		mlx4_warn(mdev, "UDP RSS is not supported on this device\n");
1635a2cc190SJeff Kirsher 		params->udp_rss = 0;
1645a2cc190SJeff Kirsher 	}
1655a2cc190SJeff Kirsher 	for (i = 1; i <= MLX4_MAX_PORTS; i++) {
1666e8814ceSEran Ben Elisha 		params->prof[i].rx_pause = !(pfcrx || pfctx);
1675a2cc190SJeff Kirsher 		params->prof[i].rx_ppp = pfcrx;
1686e8814ceSEran Ben Elisha 		params->prof[i].tx_pause = !(pfcrx || pfctx);
1695a2cc190SJeff Kirsher 		params->prof[i].tx_ppp = pfctx;
17027055454SAlaa Hleihel 		if (mlx4_low_memory_profile()) {
17127055454SAlaa Hleihel 			params->prof[i].tx_ring_size = MLX4_EN_MIN_TX_SIZE;
17227055454SAlaa Hleihel 			params->prof[i].rx_ring_size = MLX4_EN_MIN_RX_SIZE;
17327055454SAlaa Hleihel 		} else {
1745a2cc190SJeff Kirsher 			params->prof[i].tx_ring_size = MLX4_EN_DEF_TX_RING_SIZE;
1755a2cc190SJeff Kirsher 			params->prof[i].rx_ring_size = MLX4_EN_DEF_RX_RING_SIZE;
17627055454SAlaa Hleihel 		}
177ec327f7aSInbar Karmy 		params->prof[i].num_up = MLX4_EN_NUM_UP_LOW;
1787e1dc5e9SInbar Karmy 		params->prof[i].num_tx_rings_p_up = params->max_num_tx_rings_p_up;
1797e1dc5e9SInbar Karmy 		params->prof[i].tx_ring_num[TX] = params->max_num_tx_rings_p_up *
180f21ad614SInbar Karmy 			params->prof[i].num_up;
18193d3e367SYevgeny Petrilin 		params->prof[i].rss_rings = 0;
182b97b33a3SEugenia Emantayev 		params->prof[i].inline_thold = inline_thold;
1835a2cc190SJeff Kirsher 	}
1845a2cc190SJeff Kirsher }
1855a2cc190SJeff Kirsher 
mlx4_en_event(struct notifier_block * this,unsigned long event,void * param)18673d68002SPetr Pavlu static int mlx4_en_event(struct notifier_block *this, unsigned long event,
18773d68002SPetr Pavlu 			 void *param)
1885a2cc190SJeff Kirsher {
18973d68002SPetr Pavlu 	struct mlx4_en_dev *mdev =
19073d68002SPetr Pavlu 		container_of(this, struct mlx4_en_dev, mlx_nb);
19173d68002SPetr Pavlu 	struct mlx4_dev *dev = mdev->dev;
1925a2cc190SJeff Kirsher 	struct mlx4_en_priv *priv;
1937ba189acSPetr Pavlu 	int port;
1947ba189acSPetr Pavlu 
1957ba189acSPetr Pavlu 	switch (event) {
1967ba189acSPetr Pavlu 	case MLX4_DEV_EVENT_CATASTROPHIC_ERROR:
1977ba189acSPetr Pavlu 	case MLX4_DEV_EVENT_PORT_MGMT_CHANGE:
1987ba189acSPetr Pavlu 	case MLX4_DEV_EVENT_SLAVE_INIT:
1997ba189acSPetr Pavlu 	case MLX4_DEV_EVENT_SLAVE_SHUTDOWN:
2007ba189acSPetr Pavlu 		break;
2017ba189acSPetr Pavlu 	default:
2027ba189acSPetr Pavlu 		port = *(int *)param;
2037ba189acSPetr Pavlu 		break;
2047ba189acSPetr Pavlu 	}
2055a2cc190SJeff Kirsher 
2065a2cc190SJeff Kirsher 	switch (event) {
2075a2cc190SJeff Kirsher 	case MLX4_DEV_EVENT_PORT_UP:
2085a2cc190SJeff Kirsher 	case MLX4_DEV_EVENT_PORT_DOWN:
20913bf58b7SJack Morgenstein 		if (!mdev->pndev[port])
21073d68002SPetr Pavlu 			return NOTIFY_DONE;
21113bf58b7SJack Morgenstein 		priv = netdev_priv(mdev->pndev[port]);
2125a2cc190SJeff Kirsher 		/* To prevent races, we poll the link state in a separate
2135a2cc190SJeff Kirsher 		  task rather than changing it here */
2145a2cc190SJeff Kirsher 		priv->link_state = event;
2155a2cc190SJeff Kirsher 		queue_work(mdev->workqueue, &priv->linkstate_task);
2165a2cc190SJeff Kirsher 		break;
2175a2cc190SJeff Kirsher 
2185a2cc190SJeff Kirsher 	case MLX4_DEV_EVENT_CATASTROPHIC_ERROR:
2195a2cc190SJeff Kirsher 		mlx4_err(mdev, "Internal error detected, restarting device\n");
2205a2cc190SJeff Kirsher 		break;
2215a2cc190SJeff Kirsher 
2227ba189acSPetr Pavlu 	case MLX4_DEV_EVENT_PORT_MGMT_CHANGE:
223e4b59a1cSEugenia Emantayev 	case MLX4_DEV_EVENT_SLAVE_INIT:
224e4b59a1cSEugenia Emantayev 	case MLX4_DEV_EVENT_SLAVE_SHUTDOWN:
225e4b59a1cSEugenia Emantayev 		break;
2265a2cc190SJeff Kirsher 	default:
22713bf58b7SJack Morgenstein 		if (port < 1 || port > dev->caps.num_ports ||
22813bf58b7SJack Morgenstein 		    !mdev->pndev[port])
22973d68002SPetr Pavlu 			return NOTIFY_DONE;
23073d68002SPetr Pavlu 		mlx4_warn(mdev, "Unhandled event %d for port %d\n", (int)event,
2317ba189acSPetr Pavlu 			  port);
2325a2cc190SJeff Kirsher 	}
23373d68002SPetr Pavlu 
23473d68002SPetr Pavlu 	return NOTIFY_DONE;
2355a2cc190SJeff Kirsher }
2365a2cc190SJeff Kirsher 
mlx4_en_remove(struct auxiliary_device * adev)237*eb93ae49SPetr Pavlu static void mlx4_en_remove(struct auxiliary_device *adev)
2385a2cc190SJeff Kirsher {
239*eb93ae49SPetr Pavlu 	struct mlx4_adev *madev = container_of(adev, struct mlx4_adev, adev);
240*eb93ae49SPetr Pavlu 	struct mlx4_dev *dev = madev->mdev;
241*eb93ae49SPetr Pavlu 	struct mlx4_en_dev *mdev = auxiliary_get_drvdata(adev);
2425a2cc190SJeff Kirsher 	int i;
2435a2cc190SJeff Kirsher 
24473d68002SPetr Pavlu 	mlx4_unregister_event_notifier(dev, &mdev->mlx_nb);
24573d68002SPetr Pavlu 
2465a2cc190SJeff Kirsher 	mutex_lock(&mdev->state_lock);
2475a2cc190SJeff Kirsher 	mdev->device_up = false;
2485a2cc190SJeff Kirsher 	mutex_unlock(&mdev->state_lock);
2495a2cc190SJeff Kirsher 
2505a2cc190SJeff Kirsher 	mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH)
2515a2cc190SJeff Kirsher 		if (mdev->pndev[i])
2525a2cc190SJeff Kirsher 			mlx4_en_destroy_netdev(mdev->pndev[i]);
2535a2cc190SJeff Kirsher 
2545a2cc190SJeff Kirsher 	destroy_workqueue(mdev->workqueue);
25561083720SShani Michaeli 	(void) mlx4_mr_free(dev, &mdev->mr);
2567398af40SAlexander Guller 	iounmap(mdev->uar_map);
2575a2cc190SJeff Kirsher 	mlx4_uar_free(dev, &mdev->priv_uar);
2585a2cc190SJeff Kirsher 	mlx4_pd_free(dev, mdev->priv_pdn);
259ef5617e3SPetr Pavlu 	if (mdev->netdev_nb.notifier_call)
260ef5617e3SPetr Pavlu 		unregister_netdevice_notifier(&mdev->netdev_nb);
2615a2cc190SJeff Kirsher 	kfree(mdev);
2625a2cc190SJeff Kirsher }
2635a2cc190SJeff Kirsher 
mlx4_en_probe(struct auxiliary_device * adev,const struct auxiliary_device_id * id)264*eb93ae49SPetr Pavlu static int mlx4_en_probe(struct auxiliary_device *adev,
265*eb93ae49SPetr Pavlu 			 const struct auxiliary_device_id *id)
2665a2cc190SJeff Kirsher {
267*eb93ae49SPetr Pavlu 	struct mlx4_adev *madev = container_of(adev, struct mlx4_adev, adev);
268*eb93ae49SPetr Pavlu 	struct mlx4_dev *dev = madev->mdev;
2695a2cc190SJeff Kirsher 	struct mlx4_en_dev *mdev;
27073d68002SPetr Pavlu 	int err, i;
2715a2cc190SJeff Kirsher 
2725a2cc190SJeff Kirsher 	printk_once(KERN_INFO "%s", mlx4_en_version);
2735a2cc190SJeff Kirsher 
274b2adaca9SJoe Perches 	mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
275*eb93ae49SPetr Pavlu 	if (!mdev) {
276*eb93ae49SPetr Pavlu 		err = -ENOMEM;
2775a2cc190SJeff Kirsher 		goto err_free_res;
278*eb93ae49SPetr Pavlu 	}
2795a2cc190SJeff Kirsher 
280*eb93ae49SPetr Pavlu 	err = mlx4_pd_alloc(dev, &mdev->priv_pdn);
281*eb93ae49SPetr Pavlu 	if (err)
2825a2cc190SJeff Kirsher 		goto err_free_dev;
2835a2cc190SJeff Kirsher 
284*eb93ae49SPetr Pavlu 	err = mlx4_uar_alloc(dev, &mdev->priv_uar);
285*eb93ae49SPetr Pavlu 	if (err)
2865a2cc190SJeff Kirsher 		goto err_pd;
2875a2cc190SJeff Kirsher 
2885a2cc190SJeff Kirsher 	mdev->uar_map = ioremap((phys_addr_t) mdev->priv_uar.pfn << PAGE_SHIFT,
2895a2cc190SJeff Kirsher 				PAGE_SIZE);
290*eb93ae49SPetr Pavlu 	if (!mdev->uar_map) {
291*eb93ae49SPetr Pavlu 		err = -ENOMEM;
2925a2cc190SJeff Kirsher 		goto err_uar;
293*eb93ae49SPetr Pavlu 	}
2945a2cc190SJeff Kirsher 	spin_lock_init(&mdev->uar_lock);
2955a2cc190SJeff Kirsher 
2965a2cc190SJeff Kirsher 	mdev->dev = dev;
297872bf2fbSYishai Hadas 	mdev->dma_device = &dev->persist->pdev->dev;
298872bf2fbSYishai Hadas 	mdev->pdev = dev->persist->pdev;
2995a2cc190SJeff Kirsher 	mdev->device_up = false;
3005a2cc190SJeff Kirsher 
3015a2cc190SJeff Kirsher 	mdev->LSO_support = !!(dev->caps.flags & (1 << 15));
3025a2cc190SJeff Kirsher 	if (!mdev->LSO_support)
3031a91de28SJoe Perches 		mlx4_warn(mdev, "LSO not supported, please upgrade to later FW version to enable LSO\n");
3045a2cc190SJeff Kirsher 
305*eb93ae49SPetr Pavlu 	err = mlx4_mr_alloc(mdev->dev, mdev->priv_pdn, 0, ~0ull,
306*eb93ae49SPetr Pavlu 			    MLX4_PERM_LOCAL_WRITE | MLX4_PERM_LOCAL_READ, 0, 0,
307*eb93ae49SPetr Pavlu 			    &mdev->mr);
308*eb93ae49SPetr Pavlu 	if (err) {
3095a2cc190SJeff Kirsher 		mlx4_err(mdev, "Failed allocating memory region\n");
3107398af40SAlexander Guller 		goto err_map;
3115a2cc190SJeff Kirsher 	}
312*eb93ae49SPetr Pavlu 	err = mlx4_mr_enable(mdev->dev, &mdev->mr);
313*eb93ae49SPetr Pavlu 	if (err) {
3145a2cc190SJeff Kirsher 		mlx4_err(mdev, "Failed enabling memory region\n");
3155a2cc190SJeff Kirsher 		goto err_mr;
3165a2cc190SJeff Kirsher 	}
3175a2cc190SJeff Kirsher 
3185a2cc190SJeff Kirsher 	/* Build device profile according to supplied module parameters */
319f575a02eSZhu Yanjun 	mlx4_en_get_profile(mdev);
3205a2cc190SJeff Kirsher 
3215a2cc190SJeff Kirsher 	/* Configure which ports to start according to module parameters */
3225a2cc190SJeff Kirsher 	mdev->port_cnt = 0;
3235a2cc190SJeff Kirsher 	mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH)
3245a2cc190SJeff Kirsher 		mdev->port_cnt++;
3255a2cc190SJeff Kirsher 
32602512482SIdo Shamay 	/* Set default number of RX rings*/
32702512482SIdo Shamay 	mlx4_en_set_num_rx_rings(mdev);
3285a2cc190SJeff Kirsher 
3295a2cc190SJeff Kirsher 	/* Create our own workqueue for reset/multicast tasks
3305a2cc190SJeff Kirsher 	 * Note: we cannot use the shared workqueue because of deadlocks caused
3315a2cc190SJeff Kirsher 	 *       by the rtnl lock */
3325a2cc190SJeff Kirsher 	mdev->workqueue = create_singlethread_workqueue("mlx4_en");
333*eb93ae49SPetr Pavlu 	if (!mdev->workqueue) {
334*eb93ae49SPetr Pavlu 		err = -ENOMEM;
3355a2cc190SJeff Kirsher 		goto err_mr;
336*eb93ae49SPetr Pavlu 	}
3375a2cc190SJeff Kirsher 
3385a2cc190SJeff Kirsher 	/* At this stage all non-port specific tasks are complete:
3395a2cc190SJeff Kirsher 	 * mark the card state as up */
3405a2cc190SJeff Kirsher 	mutex_init(&mdev->state_lock);
3415a2cc190SJeff Kirsher 	mdev->device_up = true;
3425a2cc190SJeff Kirsher 
34373d68002SPetr Pavlu 	/* register mlx4 core notifier */
34473d68002SPetr Pavlu 	mdev->mlx_nb.notifier_call = mlx4_en_event;
34573d68002SPetr Pavlu 	err = mlx4_register_event_notifier(dev, &mdev->mlx_nb);
34673d68002SPetr Pavlu 	WARN(err, "failed to register mlx4 event notifier (%d)", err);
34773d68002SPetr Pavlu 
34813f85711SPetr Pavlu 	/* Setup ports */
34913f85711SPetr Pavlu 
35013f85711SPetr Pavlu 	/* Create a netdev for each port */
35113f85711SPetr Pavlu 	mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) {
35213f85711SPetr Pavlu 		mlx4_info(mdev, "Activating port:%d\n", i);
35313f85711SPetr Pavlu 		if (mlx4_en_init_netdev(mdev, i, &mdev->profile.prof[i]))
35413f85711SPetr Pavlu 			mdev->pndev[i] = NULL;
35513f85711SPetr Pavlu 	}
35613f85711SPetr Pavlu 
35713f85711SPetr Pavlu 	/* register netdev notifier */
35813f85711SPetr Pavlu 	mdev->netdev_nb.notifier_call = mlx4_en_netdev_event;
35913f85711SPetr Pavlu 	if (register_netdevice_notifier(&mdev->netdev_nb)) {
36013f85711SPetr Pavlu 		mdev->netdev_nb.notifier_call = NULL;
36113f85711SPetr Pavlu 		mlx4_err(mdev, "Failed to create netdev notifier\n");
36213f85711SPetr Pavlu 	}
36313f85711SPetr Pavlu 
364*eb93ae49SPetr Pavlu 	auxiliary_set_drvdata(adev, mdev);
365*eb93ae49SPetr Pavlu 	return 0;
3665a2cc190SJeff Kirsher 
3675a2cc190SJeff Kirsher err_mr:
36861083720SShani Michaeli 	(void) mlx4_mr_free(dev, &mdev->mr);
3697398af40SAlexander Guller err_map:
3708850494aSDotan Barak 	if (mdev->uar_map)
3717398af40SAlexander Guller 		iounmap(mdev->uar_map);
3725a2cc190SJeff Kirsher err_uar:
3735a2cc190SJeff Kirsher 	mlx4_uar_free(dev, &mdev->priv_uar);
3745a2cc190SJeff Kirsher err_pd:
3755a2cc190SJeff Kirsher 	mlx4_pd_free(dev, mdev->priv_pdn);
3765a2cc190SJeff Kirsher err_free_dev:
3775a2cc190SJeff Kirsher 	kfree(mdev);
3785a2cc190SJeff Kirsher err_free_res:
379*eb93ae49SPetr Pavlu 	return err;
3805a2cc190SJeff Kirsher }
3815a2cc190SJeff Kirsher 
382*eb93ae49SPetr Pavlu static const struct auxiliary_device_id mlx4_en_id_table[] = {
383*eb93ae49SPetr Pavlu 	{ .name = MLX4_ADEV_NAME ".eth" },
384*eb93ae49SPetr Pavlu 	{},
385*eb93ae49SPetr Pavlu };
386*eb93ae49SPetr Pavlu 
387*eb93ae49SPetr Pavlu MODULE_DEVICE_TABLE(auxiliary, mlx4_en_id_table);
388*eb93ae49SPetr Pavlu 
389*eb93ae49SPetr Pavlu static struct mlx4_adrv mlx4_en_adrv = {
390*eb93ae49SPetr Pavlu 	.adrv = {
391*eb93ae49SPetr Pavlu 		.name	= "eth",
392*eb93ae49SPetr Pavlu 		.probe	= mlx4_en_probe,
3935a2cc190SJeff Kirsher 		.remove	= mlx4_en_remove,
394*eb93ae49SPetr Pavlu 		.id_table = mlx4_en_id_table,
395*eb93ae49SPetr Pavlu 	},
3965a2cc190SJeff Kirsher 	.protocol	= MLX4_PROT_ETH,
3975a2cc190SJeff Kirsher };
3985a2cc190SJeff Kirsher 
mlx4_en_verify_params(void)399d0ceebd7SFengguang Wu static void mlx4_en_verify_params(void)
400b97b33a3SEugenia Emantayev {
401b97b33a3SEugenia Emantayev 	if (pfctx > MAX_PFC_TX) {
402b97b33a3SEugenia Emantayev 		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",
403b97b33a3SEugenia Emantayev 			pfctx, MAX_PFC_TX);
404b97b33a3SEugenia Emantayev 		pfctx = 0;
405b97b33a3SEugenia Emantayev 	}
406b97b33a3SEugenia Emantayev 
407b97b33a3SEugenia Emantayev 	if (pfcrx > MAX_PFC_RX) {
408b97b33a3SEugenia Emantayev 		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",
409b97b33a3SEugenia Emantayev 			pfcrx, MAX_PFC_RX);
410b97b33a3SEugenia Emantayev 		pfcrx = 0;
411b97b33a3SEugenia Emantayev 	}
412b97b33a3SEugenia Emantayev 
413b97b33a3SEugenia Emantayev 	if (inline_thold < MIN_PKT_LEN || inline_thold > MAX_INLINE) {
414b97b33a3SEugenia Emantayev 		pr_warn("mlx4_en: WARNING: illegal module parameter inline_thold %d - should be in range %d-%d, will be changed to default (%d)\n",
415b97b33a3SEugenia Emantayev 			inline_thold, MIN_PKT_LEN, MAX_INLINE, MAX_INLINE);
416b97b33a3SEugenia Emantayev 		inline_thold = MAX_INLINE;
417b97b33a3SEugenia Emantayev 	}
418b97b33a3SEugenia Emantayev }
419b97b33a3SEugenia Emantayev 
mlx4_en_init(void)4205a2cc190SJeff Kirsher static int __init mlx4_en_init(void)
4215a2cc190SJeff Kirsher {
422b97b33a3SEugenia Emantayev 	mlx4_en_verify_params();
4233d8f7cc7SDavid Decotigny 	mlx4_en_init_ptys2ethtool_map();
424b97b33a3SEugenia Emantayev 
425*eb93ae49SPetr Pavlu 	return mlx4_register_auxiliary_driver(&mlx4_en_adrv);
4265a2cc190SJeff Kirsher }
4275a2cc190SJeff Kirsher 
mlx4_en_cleanup(void)4285a2cc190SJeff Kirsher static void __exit mlx4_en_cleanup(void)
4295a2cc190SJeff Kirsher {
430*eb93ae49SPetr Pavlu 	mlx4_unregister_auxiliary_driver(&mlx4_en_adrv);
4315a2cc190SJeff Kirsher }
4325a2cc190SJeff Kirsher 
4335a2cc190SJeff Kirsher module_init(mlx4_en_init);
4345a2cc190SJeff Kirsher module_exit(mlx4_en_cleanup);
4355a2cc190SJeff Kirsher 
436