2008-10-22 16:47:49 -06:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Mellanox Technologies. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software is available to you under a choice of one of two
|
|
|
|
* licenses. You may choose to be licensed under the terms of the GNU
|
|
|
|
* General Public License (GPL) Version 2, available from the file
|
|
|
|
* COPYING in the main directory of this source tree, or the
|
|
|
|
* OpenIB.org BSD license below:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or
|
|
|
|
* without modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials
|
|
|
|
* provided with the distribution.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/cpumask.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/netdevice.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2008-10-22 16:47:49 -06:00
|
|
|
|
|
|
|
#include <linux/mlx4/driver.h>
|
|
|
|
#include <linux/mlx4/device.h>
|
|
|
|
#include <linux/mlx4/cmd.h>
|
|
|
|
|
|
|
|
#include "mlx4_en.h"
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Liran Liss, Yevgeny Petrilin");
|
|
|
|
MODULE_DESCRIPTION("Mellanox ConnectX HCA Ethernet driver");
|
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
2017-06-07 07:26:14 -06:00
|
|
|
MODULE_VERSION(DRV_VERSION);
|
2008-10-22 16:47:49 -06:00
|
|
|
|
|
|
|
static const char mlx4_en_version[] =
|
|
|
|
DRV_NAME ": Mellanox ConnectX HCA Ethernet driver v"
|
2017-06-07 07:26:14 -06:00
|
|
|
DRV_VERSION "\n";
|
2008-10-22 16:47:49 -06:00
|
|
|
|
2009-06-01 17:20:18 -06:00
|
|
|
#define MLX4_EN_PARM_INT(X, def_val, desc) \
|
|
|
|
static unsigned int X = def_val;\
|
|
|
|
module_param(X , uint, 0444); \
|
|
|
|
MODULE_PARM_DESC(X, desc);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device scope module parameters
|
|
|
|
*/
|
|
|
|
|
2010-08-23 21:46:42 -06:00
|
|
|
/* Enable RSS UDP traffic */
|
|
|
|
MLX4_EN_PARM_INT(udp_rss, 1,
|
2012-12-27 09:33:02 -07:00
|
|
|
"Enable RSS for incoming UDP traffic or disabled (0)");
|
2009-06-01 17:20:18 -06:00
|
|
|
|
|
|
|
/* Priority pausing */
|
|
|
|
MLX4_EN_PARM_INT(pfctx, 0, "Priority based Flow Control policy on TX[7:0]."
|
|
|
|
" Per priority bit mask");
|
|
|
|
MLX4_EN_PARM_INT(pfcrx, 0, "Priority based Flow Control policy on RX[7:0]."
|
|
|
|
" Per priority bit mask");
|
|
|
|
|
2014-03-02 01:24:58 -07:00
|
|
|
MLX4_EN_PARM_INT(inline_thold, MAX_INLINE,
|
|
|
|
"Threshold for using inline data (range: 17-104, default: 104)");
|
|
|
|
|
|
|
|
#define MAX_PFC_TX 0xff
|
|
|
|
#define MAX_PFC_RX 0xff
|
|
|
|
|
2014-09-22 11:40:22 -06:00
|
|
|
void en_print(const char *level, const struct mlx4_en_priv *priv,
|
|
|
|
const char *format, ...)
|
2010-07-10 01:22:46 -06:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
struct va_format vaf;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
|
|
|
vaf.fmt = format;
|
|
|
|
vaf.va = &args;
|
|
|
|
if (priv->registered)
|
2014-09-22 11:40:22 -06:00
|
|
|
printk("%s%s: %s: %pV",
|
|
|
|
level, DRV_NAME, priv->dev->name, &vaf);
|
2010-07-10 01:22:46 -06:00
|
|
|
else
|
2014-09-22 11:40:22 -06:00
|
|
|
printk("%s%s: %s: Port %d: %pV",
|
|
|
|
level, DRV_NAME, dev_name(&priv->mdev->pdev->dev),
|
|
|
|
priv->port, &vaf);
|
2010-07-10 01:22:46 -06:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2013-02-06 19:25:19 -07:00
|
|
|
void mlx4_en_update_loopback_state(struct net_device *dev,
|
|
|
|
netdev_features_t features)
|
|
|
|
{
|
|
|
|
struct mlx4_en_priv *priv = netdev_priv(dev);
|
|
|
|
|
2015-04-02 07:31:07 -06:00
|
|
|
if (features & NETIF_F_LOOPBACK)
|
|
|
|
priv->ctrl_flags |= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK);
|
|
|
|
else
|
|
|
|
priv->ctrl_flags &= cpu_to_be32(~MLX4_WQE_CTRL_FORCE_LOOPBACK);
|
|
|
|
|
2013-02-06 19:25:19 -07:00
|
|
|
priv->flags &= ~(MLX4_EN_FLAG_RX_FILTER_NEEDED|
|
|
|
|
MLX4_EN_FLAG_ENABLE_HW_LOOPBACK);
|
|
|
|
|
|
|
|
/* Drop the packet if SRIOV is not enabled
|
|
|
|
* and not performing the selftest or flb disabled
|
|
|
|
*/
|
|
|
|
if (mlx4_is_mfunc(priv->mdev->dev) &&
|
|
|
|
!(features & NETIF_F_LOOPBACK) && !priv->validate_loopback)
|
|
|
|
priv->flags |= MLX4_EN_FLAG_RX_FILTER_NEEDED;
|
|
|
|
|
|
|
|
/* Set dmac in Tx WQE if we are in SRIOV mode or if loopback selftest
|
|
|
|
* is requested
|
|
|
|
*/
|
|
|
|
if (mlx4_is_mfunc(priv->mdev->dev) || priv->validate_loopback)
|
|
|
|
priv->flags |= MLX4_EN_FLAG_ENABLE_HW_LOOPBACK;
|
2015-10-15 05:44:39 -06:00
|
|
|
|
|
|
|
mutex_lock(&priv->mdev->state_lock);
|
2017-06-15 05:35:32 -06:00
|
|
|
if ((priv->mdev->dev->caps.flags2 &
|
|
|
|
MLX4_DEV_CAP_FLAG2_UPDATE_QP_SRC_CHECK_LB) &&
|
|
|
|
priv->rss_map.indir_qp && priv->rss_map.indir_qp->qpn) {
|
2015-10-15 05:44:39 -06:00
|
|
|
int i;
|
|
|
|
int err = 0;
|
|
|
|
int loopback = !!(features & NETIF_F_LOOPBACK);
|
|
|
|
|
|
|
|
for (i = 0; i < priv->rx_ring_num; i++) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = mlx4_en_change_mcast_lb(priv,
|
|
|
|
&priv->rss_map.qps[i],
|
|
|
|
loopback);
|
|
|
|
if (!err)
|
|
|
|
err = ret;
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
mlx4_warn(priv->mdev, "failed to change mcast loopback\n");
|
|
|
|
}
|
|
|
|
mutex_unlock(&priv->mdev->state_lock);
|
2013-02-06 19:25:19 -07:00
|
|
|
}
|
|
|
|
|
2017-07-24 02:22:44 -06:00
|
|
|
static void mlx4_en_get_profile(struct mlx4_en_dev *mdev)
|
2009-06-01 17:20:18 -06:00
|
|
|
{
|
|
|
|
struct mlx4_en_profile *params = &mdev->profile;
|
|
|
|
int i;
|
|
|
|
|
2010-08-23 21:46:42 -06:00
|
|
|
params->udp_rss = udp_rss;
|
2017-10-10 03:28:33 -06:00
|
|
|
params->max_num_tx_rings_p_up = mlx4_low_memory_profile() ?
|
2014-07-22 06:44:12 -06:00
|
|
|
MLX4_EN_MIN_TX_RING_P_UP :
|
|
|
|
min_t(int, num_online_cpus(), MLX4_EN_MAX_TX_RING_P_UP);
|
|
|
|
|
2011-07-07 13:19:29 -06:00
|
|
|
if (params->udp_rss && !(mdev->dev->caps.flags
|
|
|
|
& MLX4_DEV_CAP_FLAG_UDP_RSS)) {
|
2014-05-07 13:52:57 -06:00
|
|
|
mlx4_warn(mdev, "UDP RSS is not supported on this device\n");
|
2010-08-23 21:46:42 -06:00
|
|
|
params->udp_rss = 0;
|
|
|
|
}
|
2009-06-01 17:20:18 -06:00
|
|
|
for (i = 1; i <= MLX4_MAX_PORTS; i++) {
|
2018-03-27 05:41:18 -06:00
|
|
|
params->prof[i].rx_pause = !(pfcrx || pfctx);
|
2009-06-01 17:20:18 -06:00
|
|
|
params->prof[i].rx_ppp = pfcrx;
|
2018-03-27 05:41:18 -06:00
|
|
|
params->prof[i].tx_pause = !(pfcrx || pfctx);
|
2009-06-01 17:20:18 -06:00
|
|
|
params->prof[i].tx_ppp = pfctx;
|
2018-10-09 03:06:52 -06:00
|
|
|
if (mlx4_low_memory_profile()) {
|
|
|
|
params->prof[i].tx_ring_size = MLX4_EN_MIN_TX_SIZE;
|
|
|
|
params->prof[i].rx_ring_size = MLX4_EN_MIN_RX_SIZE;
|
|
|
|
} else {
|
|
|
|
params->prof[i].tx_ring_size = MLX4_EN_DEF_TX_RING_SIZE;
|
|
|
|
params->prof[i].rx_ring_size = MLX4_EN_DEF_RX_RING_SIZE;
|
|
|
|
}
|
2017-06-29 05:07:57 -06:00
|
|
|
params->prof[i].num_up = MLX4_EN_NUM_UP_LOW;
|
2017-10-10 03:28:33 -06:00
|
|
|
params->prof[i].num_tx_rings_p_up = params->max_num_tx_rings_p_up;
|
|
|
|
params->prof[i].tx_ring_num[TX] = params->max_num_tx_rings_p_up *
|
2017-06-29 05:07:56 -06:00
|
|
|
params->prof[i].num_up;
|
2012-01-17 15:54:55 -07:00
|
|
|
params->prof[i].rss_rings = 0;
|
2014-03-02 01:24:58 -07:00
|
|
|
params->prof[i].inline_thold = inline_thold;
|
2009-06-01 17:20:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-26 08:18:43 -06:00
|
|
|
static void *mlx4_en_get_netdev(struct mlx4_dev *dev, void *ctx, u8 port)
|
|
|
|
{
|
|
|
|
struct mlx4_en_dev *endev = ctx;
|
|
|
|
|
|
|
|
return endev->pndev[port];
|
|
|
|
}
|
|
|
|
|
2008-10-22 16:47:49 -06:00
|
|
|
static void mlx4_en_event(struct mlx4_dev *dev, void *endev_ptr,
|
mlx4: Use port management change event instead of smp_snoop
The port management change event can replace smp_snoop. If the
capability bit for this event is set in dev-caps, the event is used
(by the driver setting the PORT_MNG_CHG_EVENT bit in the async event
mask in the MAP_EQ fw command). In this case, when the driver passes
incoming SMP PORT_INFO SET mads to the FW, the FW generates port
management change events to signal any changes to the driver.
If the FW generates these events, smp_snoop shouldn't be invoked in
ib_process_mad(), or duplicate events will occur (once from the
FW-generated event, and once from smp_snoop).
In the case where the FW does not generate port management change
events smp_snoop needs to be invoked to create these events. The flow
in smp_snoop has been modified to make use of the same procedures as
in the fw-generated-event event case to generate the port management
events (LID change, Client-rereg, Pkey change, and/or GID change).
Port management change event handling required changing the
mlx4_ib_event and mlx4_dispatch_event prototypes; the "param" argument
(last argument) had to be changed to unsigned long in order to
accomodate passing the EQE pointer.
We also needed to move the definition of struct mlx4_eqe from
net/mlx4.h to file device.h -- to make it available to the IB driver,
to handle port management change events.
Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2012-06-19 02:21:40 -06:00
|
|
|
enum mlx4_dev_event event, unsigned long port)
|
2008-10-22 16:47:49 -06:00
|
|
|
{
|
|
|
|
struct mlx4_en_dev *mdev = (struct mlx4_en_dev *) endev_ptr;
|
|
|
|
struct mlx4_en_priv *priv;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case MLX4_DEV_EVENT_PORT_UP:
|
|
|
|
case MLX4_DEV_EVENT_PORT_DOWN:
|
2012-05-30 03:14:52 -06:00
|
|
|
if (!mdev->pndev[port])
|
|
|
|
return;
|
|
|
|
priv = netdev_priv(mdev->pndev[port]);
|
2008-10-22 16:47:49 -06:00
|
|
|
/* To prevent races, we poll the link state in a separate
|
|
|
|
task rather than changing it here */
|
|
|
|
priv->link_state = event;
|
|
|
|
queue_work(mdev->workqueue, &priv->linkstate_task);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MLX4_DEV_EVENT_CATASTROPHIC_ERROR:
|
|
|
|
mlx4_err(mdev, "Internal error detected, restarting device\n");
|
|
|
|
break;
|
|
|
|
|
2013-12-19 12:20:16 -07:00
|
|
|
case MLX4_DEV_EVENT_SLAVE_INIT:
|
|
|
|
case MLX4_DEV_EVENT_SLAVE_SHUTDOWN:
|
|
|
|
break;
|
2008-10-22 16:47:49 -06:00
|
|
|
default:
|
2012-05-30 03:14:52 -06:00
|
|
|
if (port < 1 || port > dev->caps.num_ports ||
|
|
|
|
!mdev->pndev[port])
|
|
|
|
return;
|
mlx4: Use port management change event instead of smp_snoop
The port management change event can replace smp_snoop. If the
capability bit for this event is set in dev-caps, the event is used
(by the driver setting the PORT_MNG_CHG_EVENT bit in the async event
mask in the MAP_EQ fw command). In this case, when the driver passes
incoming SMP PORT_INFO SET mads to the FW, the FW generates port
management change events to signal any changes to the driver.
If the FW generates these events, smp_snoop shouldn't be invoked in
ib_process_mad(), or duplicate events will occur (once from the
FW-generated event, and once from smp_snoop).
In the case where the FW does not generate port management change
events smp_snoop needs to be invoked to create these events. The flow
in smp_snoop has been modified to make use of the same procedures as
in the fw-generated-event event case to generate the port management
events (LID change, Client-rereg, Pkey change, and/or GID change).
Port management change event handling required changing the
mlx4_ib_event and mlx4_dispatch_event prototypes; the "param" argument
(last argument) had to be changed to unsigned long in order to
accomodate passing the EQE pointer.
We also needed to move the definition of struct mlx4_eqe from
net/mlx4.h to file device.h -- to make it available to the IB driver,
to handle port management change events.
Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2012-06-19 02:21:40 -06:00
|
|
|
mlx4_warn(mdev, "Unhandled event %d for port %d\n", event,
|
|
|
|
(int) port);
|
2008-10-22 16:47:49 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mlx4_en_remove(struct mlx4_dev *dev, void *endev_ptr)
|
|
|
|
{
|
|
|
|
struct mlx4_en_dev *mdev = endev_ptr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mutex_lock(&mdev->state_lock);
|
|
|
|
mdev->device_up = false;
|
|
|
|
mutex_unlock(&mdev->state_lock);
|
|
|
|
|
|
|
|
mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH)
|
|
|
|
if (mdev->pndev[i])
|
|
|
|
mlx4_en_destroy_netdev(mdev->pndev[i]);
|
|
|
|
|
|
|
|
flush_workqueue(mdev->workqueue);
|
|
|
|
destroy_workqueue(mdev->workqueue);
|
2013-02-06 09:19:09 -07:00
|
|
|
(void) mlx4_mr_free(dev, &mdev->mr);
|
2011-10-08 23:27:11 -06:00
|
|
|
iounmap(mdev->uar_map);
|
2008-10-22 16:47:49 -06:00
|
|
|
mlx4_uar_free(dev, &mdev->priv_uar);
|
|
|
|
mlx4_pd_free(dev, mdev->priv_pdn);
|
2015-02-03 07:48:34 -07:00
|
|
|
if (mdev->nb.notifier_call)
|
|
|
|
unregister_netdevice_notifier(&mdev->nb);
|
2008-10-22 16:47:49 -06:00
|
|
|
kfree(mdev);
|
|
|
|
}
|
|
|
|
|
2015-07-30 09:33:28 -06:00
|
|
|
static void mlx4_en_activate(struct mlx4_dev *dev, void *ctx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct mlx4_en_dev *mdev = ctx;
|
|
|
|
|
|
|
|
/* Create a netdev for each port */
|
|
|
|
mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) {
|
|
|
|
mlx4_info(mdev, "Activating port:%d\n", i);
|
|
|
|
if (mlx4_en_init_netdev(mdev, i, &mdev->profile.prof[i]))
|
|
|
|
mdev->pndev[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* register notifier */
|
|
|
|
mdev->nb.notifier_call = mlx4_en_netdev_event;
|
|
|
|
if (register_netdevice_notifier(&mdev->nb)) {
|
|
|
|
mdev->nb.notifier_call = NULL;
|
|
|
|
mlx4_err(mdev, "Failed to create notifier\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-22 16:47:49 -06:00
|
|
|
static void *mlx4_en_add(struct mlx4_dev *dev)
|
|
|
|
{
|
|
|
|
struct mlx4_en_dev *mdev;
|
|
|
|
int i;
|
|
|
|
|
2010-07-10 01:22:46 -06:00
|
|
|
printk_once(KERN_INFO "%s", mlx4_en_version);
|
2008-10-22 16:47:49 -06:00
|
|
|
|
2013-02-03 10:43:58 -07:00
|
|
|
mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
|
2014-10-27 03:37:44 -06:00
|
|
|
if (!mdev)
|
2008-10-22 16:47:49 -06:00
|
|
|
goto err_free_res;
|
|
|
|
|
|
|
|
if (mlx4_pd_alloc(dev, &mdev->priv_pdn))
|
|
|
|
goto err_free_dev;
|
|
|
|
|
|
|
|
if (mlx4_uar_alloc(dev, &mdev->priv_uar))
|
|
|
|
goto err_pd;
|
|
|
|
|
2011-01-12 10:50:36 -07:00
|
|
|
mdev->uar_map = ioremap((phys_addr_t) mdev->priv_uar.pfn << PAGE_SHIFT,
|
|
|
|
PAGE_SIZE);
|
2008-10-22 16:47:49 -06:00
|
|
|
if (!mdev->uar_map)
|
|
|
|
goto err_uar;
|
|
|
|
spin_lock_init(&mdev->uar_lock);
|
|
|
|
|
|
|
|
mdev->dev = dev;
|
2015-01-25 07:59:35 -07:00
|
|
|
mdev->dma_device = &dev->persist->pdev->dev;
|
|
|
|
mdev->pdev = dev->persist->pdev;
|
2008-10-22 16:47:49 -06:00
|
|
|
mdev->device_up = false;
|
|
|
|
|
|
|
|
mdev->LSO_support = !!(dev->caps.flags & (1 << 15));
|
|
|
|
if (!mdev->LSO_support)
|
2014-05-07 13:52:57 -06:00
|
|
|
mlx4_warn(mdev, "LSO not supported, please upgrade to later FW version to enable LSO\n");
|
2008-10-22 16:47:49 -06:00
|
|
|
|
|
|
|
if (mlx4_mr_alloc(mdev->dev, mdev->priv_pdn, 0, ~0ull,
|
|
|
|
MLX4_PERM_LOCAL_WRITE | MLX4_PERM_LOCAL_READ,
|
|
|
|
0, 0, &mdev->mr)) {
|
|
|
|
mlx4_err(mdev, "Failed allocating memory region\n");
|
2011-10-08 23:27:11 -06:00
|
|
|
goto err_map;
|
2008-10-22 16:47:49 -06:00
|
|
|
}
|
|
|
|
if (mlx4_mr_enable(mdev->dev, &mdev->mr)) {
|
|
|
|
mlx4_err(mdev, "Failed enabling memory region\n");
|
|
|
|
goto err_mr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build device profile according to supplied module parameters */
|
2017-07-24 02:22:44 -06:00
|
|
|
mlx4_en_get_profile(mdev);
|
2008-10-22 16:47:49 -06:00
|
|
|
|
2011-03-30 19:57:33 -06:00
|
|
|
/* Configure which ports to start according to module parameters */
|
2008-10-22 16:47:49 -06:00
|
|
|
mdev->port_cnt = 0;
|
|
|
|
mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH)
|
|
|
|
mdev->port_cnt++;
|
|
|
|
|
2014-02-21 03:39:17 -07:00
|
|
|
/* Set default number of RX rings*/
|
|
|
|
mlx4_en_set_num_rx_rings(mdev);
|
2008-10-22 16:47:49 -06:00
|
|
|
|
|
|
|
/* Create our own workqueue for reset/multicast tasks
|
|
|
|
* Note: we cannot use the shared workqueue because of deadlocks caused
|
|
|
|
* by the rtnl lock */
|
|
|
|
mdev->workqueue = create_singlethread_workqueue("mlx4_en");
|
2014-10-27 03:37:44 -06:00
|
|
|
if (!mdev->workqueue)
|
2009-04-20 12:32:08 -06:00
|
|
|
goto err_mr;
|
2008-10-22 16:47:49 -06:00
|
|
|
|
|
|
|
/* At this stage all non-port specific tasks are complete:
|
|
|
|
* mark the card state as up */
|
|
|
|
mutex_init(&mdev->state_lock);
|
|
|
|
mdev->device_up = true;
|
|
|
|
|
|
|
|
return mdev;
|
|
|
|
|
|
|
|
err_mr:
|
2013-02-06 09:19:09 -07:00
|
|
|
(void) mlx4_mr_free(dev, &mdev->mr);
|
2011-10-08 23:27:11 -06:00
|
|
|
err_map:
|
2013-06-25 03:09:29 -06:00
|
|
|
if (mdev->uar_map)
|
2011-10-08 23:27:11 -06:00
|
|
|
iounmap(mdev->uar_map);
|
2008-10-22 16:47:49 -06:00
|
|
|
err_uar:
|
|
|
|
mlx4_uar_free(dev, &mdev->priv_uar);
|
|
|
|
err_pd:
|
|
|
|
mlx4_pd_free(dev, mdev->priv_pdn);
|
|
|
|
err_free_dev:
|
|
|
|
kfree(mdev);
|
|
|
|
err_free_res:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct mlx4_interface mlx4_en_interface = {
|
2010-08-26 08:18:43 -06:00
|
|
|
.add = mlx4_en_add,
|
|
|
|
.remove = mlx4_en_remove,
|
|
|
|
.event = mlx4_en_event,
|
|
|
|
.get_dev = mlx4_en_get_netdev,
|
2011-03-22 16:38:17 -06:00
|
|
|
.protocol = MLX4_PROT_ETH,
|
2015-07-30 09:33:28 -06:00
|
|
|
.activate = mlx4_en_activate,
|
2008-10-22 16:47:49 -06:00
|
|
|
};
|
|
|
|
|
2014-03-05 02:57:23 -07:00
|
|
|
static void mlx4_en_verify_params(void)
|
2014-03-02 01:24:58 -07:00
|
|
|
{
|
|
|
|
if (pfctx > MAX_PFC_TX) {
|
|
|
|
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",
|
|
|
|
pfctx, MAX_PFC_TX);
|
|
|
|
pfctx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pfcrx > MAX_PFC_RX) {
|
|
|
|
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",
|
|
|
|
pfcrx, MAX_PFC_RX);
|
|
|
|
pfcrx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inline_thold < MIN_PKT_LEN || inline_thold > MAX_INLINE) {
|
|
|
|
pr_warn("mlx4_en: WARNING: illegal module parameter inline_thold %d - should be in range %d-%d, will be changed to default (%d)\n",
|
|
|
|
inline_thold, MIN_PKT_LEN, MAX_INLINE, MAX_INLINE);
|
|
|
|
inline_thold = MAX_INLINE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-22 16:47:49 -06:00
|
|
|
static int __init mlx4_en_init(void)
|
|
|
|
{
|
2014-03-02 01:24:58 -07:00
|
|
|
mlx4_en_verify_params();
|
2016-02-24 11:58:12 -07:00
|
|
|
mlx4_en_init_ptys2ethtool_map();
|
2014-03-02 01:24:58 -07:00
|
|
|
|
2008-10-22 16:47:49 -06:00
|
|
|
return mlx4_register_interface(&mlx4_en_interface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit mlx4_en_cleanup(void)
|
|
|
|
{
|
|
|
|
mlx4_unregister_interface(&mlx4_en_interface);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(mlx4_en_init);
|
|
|
|
module_exit(mlx4_en_cleanup);
|
|
|
|
|