en_main.c revision d0ceebd7508d5bf6e81367640959aef7e0de4947
1c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin/* 2c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * Copyright (c) 2007 Mellanox Technologies. All rights reserved. 3c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * 4c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * This software is available to you under a choice of one of two 5c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * licenses. You may choose to be licensed under the terms of the GNU 6c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * General Public License (GPL) Version 2, available from the file 7c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * COPYING in the main directory of this source tree, or the 8c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * OpenIB.org BSD license below: 9c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * 10c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * Redistribution and use in source and binary forms, with or 11c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * without modification, are permitted provided that the following 12c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * conditions are met: 13c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * 14c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * - Redistributions of source code must retain the above 15c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * copyright notice, this list of conditions and the following 16c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * disclaimer. 17c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * 18c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * - Redistributions in binary form must reproduce the above 19c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * copyright notice, this list of conditions and the following 20c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * disclaimer in the documentation and/or other materials 21c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * provided with the distribution. 22c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * 23c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * SOFTWARE. 31c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * 32c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin */ 33c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 34c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin#include <linux/cpumask.h> 35c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin#include <linux/module.h> 36c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin#include <linux/delay.h> 37c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin#include <linux/netdevice.h> 385a0e3ad6af8660be21ca98a971cd00f331318c05Tejun Heo#include <linux/slab.h> 39c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 40c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin#include <linux/mlx4/driver.h> 41c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin#include <linux/mlx4/device.h> 42c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin#include <linux/mlx4/cmd.h> 43c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 44c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin#include "mlx4_en.h" 45c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 46c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny PetrilinMODULE_AUTHOR("Liran Liss, Yevgeny Petrilin"); 47c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny PetrilinMODULE_DESCRIPTION("Mellanox ConnectX HCA Ethernet driver"); 48c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny PetrilinMODULE_LICENSE("Dual BSD/GPL"); 49c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny PetrilinMODULE_VERSION(DRV_VERSION " ("DRV_RELDATE")"); 50c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 51c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic const char mlx4_en_version[] = 52c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin DRV_NAME ": Mellanox ConnectX HCA Ethernet driver v" 53c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin DRV_VERSION " (" DRV_RELDATE ")\n"; 54c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 55a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin#define MLX4_EN_PARM_INT(X, def_val, desc) \ 56a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin static unsigned int X = def_val;\ 57a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin module_param(X , uint, 0444); \ 58a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin MODULE_PARM_DESC(X, desc); 59a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 60a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 61a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin/* 62a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin * Device scope module parameters 63a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin */ 64a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 650533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin/* Enable RSS UDP traffic */ 660533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny PetrilinMLX4_EN_PARM_INT(udp_rss, 1, 67d82603c6da7579c50ebe3fe7da6e3e267d9f6427Jorrit Schippers "Enable RSS for incoming UDP traffic or disabled (0)"); 68a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 69a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin/* Priority pausing */ 70a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny PetrilinMLX4_EN_PARM_INT(pfctx, 0, "Priority based Flow Control policy on TX[7:0]." 71a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin " Per priority bit mask"); 72a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny PetrilinMLX4_EN_PARM_INT(pfcrx, 0, "Priority based Flow Control policy on RX[7:0]." 73a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin " Per priority bit mask"); 74a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 75b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia EmantayevMLX4_EN_PARM_INT(inline_thold, MAX_INLINE, 76b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev "Threshold for using inline data (range: 17-104, default: 104)"); 77b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev 78b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev#define MAX_PFC_TX 0xff 79b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev#define MAX_PFC_RX 0xff 80b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev 810a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perchesint en_print(const char *level, const struct mlx4_en_priv *priv, 820a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches const char *format, ...) 830a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches{ 840a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches va_list args; 850a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches struct va_format vaf; 860a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches int i; 870a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches 880a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches va_start(args, format); 890a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches 900a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches vaf.fmt = format; 910a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches vaf.va = &args; 920a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches if (priv->registered) 930a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches i = printk("%s%s: %s: %pV", 940a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches level, DRV_NAME, priv->dev->name, &vaf); 950a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches else 960a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches i = printk("%s%s: %s: Port %d: %pV", 970a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches level, DRV_NAME, dev_name(&priv->mdev->pdev->dev), 980a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches priv->port, &vaf); 990a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches va_end(args); 1000a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches 1010a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches return i; 1020a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches} 1030a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches 10479aeaccd915c527a75f2cb01682eab160bed4f48Yan Burmanvoid mlx4_en_update_loopback_state(struct net_device *dev, 10579aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman netdev_features_t features) 10679aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman{ 10779aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman struct mlx4_en_priv *priv = netdev_priv(dev); 10879aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman 10979aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman priv->flags &= ~(MLX4_EN_FLAG_RX_FILTER_NEEDED| 11079aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman MLX4_EN_FLAG_ENABLE_HW_LOOPBACK); 11179aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman 11279aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman /* Drop the packet if SRIOV is not enabled 11379aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman * and not performing the selftest or flb disabled 11479aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman */ 11579aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman if (mlx4_is_mfunc(priv->mdev->dev) && 11679aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman !(features & NETIF_F_LOOPBACK) && !priv->validate_loopback) 11779aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman priv->flags |= MLX4_EN_FLAG_RX_FILTER_NEEDED; 11879aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman 11979aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman /* Set dmac in Tx WQE if we are in SRIOV mode or if loopback selftest 12079aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman * is requested 12179aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman */ 12279aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman if (mlx4_is_mfunc(priv->mdev->dev) || priv->validate_loopback) 12379aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman priv->flags |= MLX4_EN_FLAG_ENABLE_HW_LOOPBACK; 12479aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman} 12579aeaccd915c527a75f2cb01682eab160bed4f48Yan Burman 126a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilinstatic int mlx4_en_get_profile(struct mlx4_en_dev *mdev) 127a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin{ 128a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin struct mlx4_en_profile *params = &mdev->profile; 129a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin int i; 130a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 1310533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin params->udp_rss = udp_rss; 132bc6a4744b827c5a78ca591acca81809bddb8b2dbAmir Vadai params->num_tx_rings_p_up = min_t(int, num_online_cpus(), 133bc6a4744b827c5a78ca591acca81809bddb8b2dbAmir Vadai MLX4_EN_MAX_TX_RING_P_UP); 134ccf863219675aa86bebdd6a2806acb8176478e37Or Gerlitz if (params->udp_rss && !(mdev->dev->caps.flags 135ccf863219675aa86bebdd6a2806acb8176478e37Or Gerlitz & MLX4_DEV_CAP_FLAG_UDP_RSS)) { 1360533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin mlx4_warn(mdev, "UDP RSS is not supported on this device.\n"); 1370533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin params->udp_rss = 0; 1380533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin } 139a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin for (i = 1; i <= MLX4_MAX_PORTS; i++) { 140a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].rx_pause = 1; 141a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].rx_ppp = pfcrx; 142a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].tx_pause = 1; 143a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].tx_ppp = pfctx; 144a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].tx_ring_size = MLX4_EN_DEF_TX_RING_SIZE; 145a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].rx_ring_size = MLX4_EN_DEF_RX_RING_SIZE; 146bc6a4744b827c5a78ca591acca81809bddb8b2dbAmir Vadai params->prof[i].tx_ring_num = params->num_tx_rings_p_up * 147bc6a4744b827c5a78ca591acca81809bddb8b2dbAmir Vadai MLX4_EN_NUM_UP; 14893d3e3678f23109363cd6f99f2944d2cda616b23Yevgeny Petrilin params->prof[i].rss_rings = 0; 149b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev params->prof[i].inline_thold = inline_thold; 150a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin } 151a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 152a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin return 0; 153a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin} 154a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 15533c87f0af60146b375220809c1cb745ac1a86edfEli Cohenstatic void *mlx4_en_get_netdev(struct mlx4_dev *dev, void *ctx, u8 port) 15633c87f0af60146b375220809c1cb745ac1a86edfEli Cohen{ 15733c87f0af60146b375220809c1cb745ac1a86edfEli Cohen struct mlx4_en_dev *endev = ctx; 15833c87f0af60146b375220809c1cb745ac1a86edfEli Cohen 15933c87f0af60146b375220809c1cb745ac1a86edfEli Cohen return endev->pndev[port]; 16033c87f0af60146b375220809c1cb745ac1a86edfEli Cohen} 16133c87f0af60146b375220809c1cb745ac1a86edfEli Cohen 162c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic void mlx4_en_event(struct mlx4_dev *dev, void *endev_ptr, 16300f5ce99dc6ee46c3113393cc8fa12173f9bbcd7Jack Morgenstein enum mlx4_dev_event event, unsigned long port) 164c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 165c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin struct mlx4_en_dev *mdev = (struct mlx4_en_dev *) endev_ptr; 166c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin struct mlx4_en_priv *priv; 167c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 168c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin switch (event) { 169c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin case MLX4_DEV_EVENT_PORT_UP: 170c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin case MLX4_DEV_EVENT_PORT_DOWN: 17113bf58b7604d9adfebb8b7c95e6cfb31ec17c699Jack Morgenstein if (!mdev->pndev[port]) 17213bf58b7604d9adfebb8b7c95e6cfb31ec17c699Jack Morgenstein return; 17313bf58b7604d9adfebb8b7c95e6cfb31ec17c699Jack Morgenstein priv = netdev_priv(mdev->pndev[port]); 174c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* To prevent races, we poll the link state in a separate 175c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin task rather than changing it here */ 176c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin priv->link_state = event; 177c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin queue_work(mdev->workqueue, &priv->linkstate_task); 178c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin break; 179c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 180c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin case MLX4_DEV_EVENT_CATASTROPHIC_ERROR: 181c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_err(mdev, "Internal error detected, restarting device\n"); 182c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin break; 183c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 184e4b59a1cb6f8feb03f356b0abfd20451f05d7470Eugenia Emantayev case MLX4_DEV_EVENT_SLAVE_INIT: 185e4b59a1cb6f8feb03f356b0abfd20451f05d7470Eugenia Emantayev case MLX4_DEV_EVENT_SLAVE_SHUTDOWN: 186e4b59a1cb6f8feb03f356b0abfd20451f05d7470Eugenia Emantayev break; 187c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin default: 18813bf58b7604d9adfebb8b7c95e6cfb31ec17c699Jack Morgenstein if (port < 1 || port > dev->caps.num_ports || 18913bf58b7604d9adfebb8b7c95e6cfb31ec17c699Jack Morgenstein !mdev->pndev[port]) 19013bf58b7604d9adfebb8b7c95e6cfb31ec17c699Jack Morgenstein return; 19100f5ce99dc6ee46c3113393cc8fa12173f9bbcd7Jack Morgenstein mlx4_warn(mdev, "Unhandled event %d for port %d\n", event, 19200f5ce99dc6ee46c3113393cc8fa12173f9bbcd7Jack Morgenstein (int) port); 193c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 194c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 195c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 196c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic void mlx4_en_remove(struct mlx4_dev *dev, void *endev_ptr) 197c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 198c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin struct mlx4_en_dev *mdev = endev_ptr; 199c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin int i; 200c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 201c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mutex_lock(&mdev->state_lock); 202c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->device_up = false; 203c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mutex_unlock(&mdev->state_lock); 204c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 205c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) 206c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mdev->pndev[i]) 207c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_en_destroy_netdev(mdev->pndev[i]); 208c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 209ad7d4eaed995d76fb24a18e202fdf5072197ff0aShawn Bohrer if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) 210ad7d4eaed995d76fb24a18e202fdf5072197ff0aShawn Bohrer mlx4_en_remove_timestamp(mdev); 211ad7d4eaed995d76fb24a18e202fdf5072197ff0aShawn Bohrer 212c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin flush_workqueue(mdev->workqueue); 213c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin destroy_workqueue(mdev->workqueue); 21461083720702a329ed5952e32bda384e3bbc9093cShani Michaeli (void) mlx4_mr_free(dev, &mdev->mr); 2157398af403f621418fa05c6936cac34aa06b5a758Alexander Guller iounmap(mdev->uar_map); 216c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_uar_free(dev, &mdev->priv_uar); 217c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_pd_free(dev, mdev->priv_pdn); 218c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin kfree(mdev); 219c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 220c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 221c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic void *mlx4_en_add(struct mlx4_dev *dev) 222c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 223c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin struct mlx4_en_dev *mdev; 224c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin int i; 225c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin int err; 226c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 2270a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches printk_once(KERN_INFO "%s", mlx4_en_version); 228c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 229b2adaca92c63b9bb8beb021d554f656e387a7648Joe Perches mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); 230c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (!mdev) { 231c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin err = -ENOMEM; 232c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_free_res; 233c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 234c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 235c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mlx4_pd_alloc(dev, &mdev->priv_pdn)) 236c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_free_dev; 237c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 238c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mlx4_uar_alloc(dev, &mdev->priv_uar)) 239c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_pd; 240c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 2414979d18fe105297f8f065743f31f8f735da8df2dRoland Dreier mdev->uar_map = ioremap((phys_addr_t) mdev->priv_uar.pfn << PAGE_SHIFT, 2424979d18fe105297f8f065743f31f8f735da8df2dRoland Dreier PAGE_SIZE); 243c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (!mdev->uar_map) 244c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_uar; 245c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin spin_lock_init(&mdev->uar_lock); 246c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 247c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->dev = dev; 248c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->dma_device = &(dev->pdev->dev); 249c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->pdev = dev->pdev; 250c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->device_up = false; 251c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 252c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->LSO_support = !!(dev->caps.flags & (1 << 15)); 253c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (!mdev->LSO_support) 254c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_warn(mdev, "LSO not supported, please upgrade to later " 255c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin "FW version to enable LSO\n"); 256c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 257c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mlx4_mr_alloc(mdev->dev, mdev->priv_pdn, 0, ~0ull, 258c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin MLX4_PERM_LOCAL_WRITE | MLX4_PERM_LOCAL_READ, 259c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 0, 0, &mdev->mr)) { 260c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_err(mdev, "Failed allocating memory region\n"); 2617398af403f621418fa05c6936cac34aa06b5a758Alexander Guller goto err_map; 262c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 263c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mlx4_mr_enable(mdev->dev, &mdev->mr)) { 264c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_err(mdev, "Failed enabling memory region\n"); 265c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_mr; 266c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 267c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 268c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* Build device profile according to supplied module parameters */ 269c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin err = mlx4_en_get_profile(mdev); 270c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (err) { 271c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_err(mdev, "Bad module parameters, aborting.\n"); 272c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_mr; 273c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 274c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 27525985edcedea6396277003854657b5f3cb31a628Lucas De Marchi /* Configure which ports to start according to module parameters */ 276c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->port_cnt = 0; 277c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) 278c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->port_cnt++; 279c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 2801ec4864b10171b0691ee196d7006ae56d2c153f2Amir Vadai /* Initialize time stamp mechanism */ 2811ec4864b10171b0691ee196d7006ae56d2c153f2Amir Vadai if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) 2821ec4864b10171b0691ee196d7006ae56d2c153f2Amir Vadai mlx4_en_init_timestamp(mdev); 2831ec4864b10171b0691ee196d7006ae56d2c153f2Amir Vadai 28402512482321c531df4abf73943529f8b44d869e2Ido Shamay /* Set default number of RX rings*/ 28502512482321c531df4abf73943529f8b44d869e2Ido Shamay mlx4_en_set_num_rx_rings(mdev); 286c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 287c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* Create our own workqueue for reset/multicast tasks 288c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * Note: we cannot use the shared workqueue because of deadlocks caused 289c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * by the rtnl lock */ 290c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->workqueue = create_singlethread_workqueue("mlx4_en"); 291c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (!mdev->workqueue) { 292c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin err = -ENOMEM; 2931a44cc3778f63dca5795708da2a2a7696da7fd61Roland Dreier goto err_mr; 294c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 295c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 296c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* At this stage all non-port specific tasks are complete: 297c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * mark the card state as up */ 298c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mutex_init(&mdev->state_lock); 299c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->device_up = true; 300c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 301c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* Setup ports */ 302c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 303c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* Create a netdev for each port */ 304c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) { 305c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_info(mdev, "Activating port:%d\n", i); 3063c2fa83f9c2bbb3e91992a2fc443b7104a07e0bcYevgeny Petrilin if (mlx4_en_init_netdev(mdev, i, &mdev->profile.prof[i])) 307c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->pndev[i] = NULL; 308c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 309ec693d47010e8302e61e0bdf3f47496c5610641aAmir Vadai 310c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin return mdev; 311c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 312c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_mr: 31361083720702a329ed5952e32bda384e3bbc9093cShani Michaeli (void) mlx4_mr_free(dev, &mdev->mr); 3147398af403f621418fa05c6936cac34aa06b5a758Alexander Gullererr_map: 3158850494a33cc67bbf31d2e3ce630d0f4e14efa56Dotan Barak if (mdev->uar_map) 3167398af403f621418fa05c6936cac34aa06b5a758Alexander Guller iounmap(mdev->uar_map); 317c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_uar: 318c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_uar_free(dev, &mdev->priv_uar); 319c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_pd: 320c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_pd_free(dev, mdev->priv_pdn); 321c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_free_dev: 322c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin kfree(mdev); 323c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_free_res: 324c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin return NULL; 325c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 326c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 327c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic struct mlx4_interface mlx4_en_interface = { 32833c87f0af60146b375220809c1cb745ac1a86edfEli Cohen .add = mlx4_en_add, 32933c87f0af60146b375220809c1cb745ac1a86edfEli Cohen .remove = mlx4_en_remove, 33033c87f0af60146b375220809c1cb745ac1a86edfEli Cohen .event = mlx4_en_event, 33133c87f0af60146b375220809c1cb745ac1a86edfEli Cohen .get_dev = mlx4_en_get_netdev, 3320345584e0b8be3735a950d17c7e463db20c6ce27Yevgeny Petrilin .protocol = MLX4_PROT_ETH, 333c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin}; 334c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 335d0ceebd7508d5bf6e81367640959aef7e0de4947Fengguang Wustatic void mlx4_en_verify_params(void) 336b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev{ 337b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev if (pfctx > MAX_PFC_TX) { 338b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia 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", 339b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev pfctx, MAX_PFC_TX); 340b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev pfctx = 0; 341b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev } 342b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev 343b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev if (pfcrx > MAX_PFC_RX) { 344b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia 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", 345b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev pfcrx, MAX_PFC_RX); 346b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev pfcrx = 0; 347b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev } 348b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev 349b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev if (inline_thold < MIN_PKT_LEN || inline_thold > MAX_INLINE) { 350b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia 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", 351b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev inline_thold, MIN_PKT_LEN, MAX_INLINE, MAX_INLINE); 352b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev inline_thold = MAX_INLINE; 353b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev } 354b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev} 355b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev 356c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic int __init mlx4_en_init(void) 357c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 358b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev mlx4_en_verify_params(); 359b97b33a3df0439401f80f041eda507d4fffa0dbfEugenia Emantayev 360c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin return mlx4_register_interface(&mlx4_en_interface); 361c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 362c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 363c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic void __exit mlx4_en_cleanup(void) 364c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 365c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_unregister_interface(&mlx4_en_interface); 366c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 367c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 368c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinmodule_init(mlx4_en_init); 369c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinmodule_exit(mlx4_en_cleanup); 370c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 371