en_main.c revision 13bf58b7604d9adfebb8b7c95e6cfb31ec17c699
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, 670533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin "Enable RSS for incomming 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 750a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perchesint en_print(const char *level, const struct mlx4_en_priv *priv, 760a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches const char *format, ...) 770a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches{ 780a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches va_list args; 790a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches struct va_format vaf; 800a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches int i; 810a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches 820a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches va_start(args, format); 830a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches 840a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches vaf.fmt = format; 850a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches vaf.va = &args; 860a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches if (priv->registered) 870a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches i = printk("%s%s: %s: %pV", 880a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches level, DRV_NAME, priv->dev->name, &vaf); 890a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches else 900a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches i = printk("%s%s: %s: Port %d: %pV", 910a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches level, DRV_NAME, dev_name(&priv->mdev->pdev->dev), 920a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches priv->port, &vaf); 930a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches va_end(args); 940a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches 950a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches return i; 960a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches} 970a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches 98a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilinstatic int mlx4_en_get_profile(struct mlx4_en_dev *mdev) 99a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin{ 100a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin struct mlx4_en_profile *params = &mdev->profile; 101a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin int i; 102a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 1030533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin params->udp_rss = udp_rss; 104bc6a4744b827c5a78ca591acca81809bddb8b2dbAmir Vadai params->num_tx_rings_p_up = min_t(int, num_online_cpus(), 105bc6a4744b827c5a78ca591acca81809bddb8b2dbAmir Vadai MLX4_EN_MAX_TX_RING_P_UP); 106ccf863219675aa86bebdd6a2806acb8176478e37Or Gerlitz if (params->udp_rss && !(mdev->dev->caps.flags 107ccf863219675aa86bebdd6a2806acb8176478e37Or Gerlitz & MLX4_DEV_CAP_FLAG_UDP_RSS)) { 1080533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin mlx4_warn(mdev, "UDP RSS is not supported on this device.\n"); 1090533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin params->udp_rss = 0; 1100533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin } 111a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin for (i = 1; i <= MLX4_MAX_PORTS; i++) { 112a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].rx_pause = 1; 113a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].rx_ppp = pfcrx; 114a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].tx_pause = 1; 115a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].tx_ppp = pfctx; 116a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].tx_ring_size = MLX4_EN_DEF_TX_RING_SIZE; 117a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].rx_ring_size = MLX4_EN_DEF_RX_RING_SIZE; 118bc6a4744b827c5a78ca591acca81809bddb8b2dbAmir Vadai params->prof[i].tx_ring_num = params->num_tx_rings_p_up * 119bc6a4744b827c5a78ca591acca81809bddb8b2dbAmir Vadai MLX4_EN_NUM_UP; 12093d3e3678f23109363cd6f99f2944d2cda616b23Yevgeny Petrilin params->prof[i].rss_rings = 0; 121a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin } 122a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 123a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin return 0; 124a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin} 125a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 12633c87f0af60146b375220809c1cb745ac1a86edfEli Cohenstatic void *mlx4_en_get_netdev(struct mlx4_dev *dev, void *ctx, u8 port) 12733c87f0af60146b375220809c1cb745ac1a86edfEli Cohen{ 12833c87f0af60146b375220809c1cb745ac1a86edfEli Cohen struct mlx4_en_dev *endev = ctx; 12933c87f0af60146b375220809c1cb745ac1a86edfEli Cohen 13033c87f0af60146b375220809c1cb745ac1a86edfEli Cohen return endev->pndev[port]; 13133c87f0af60146b375220809c1cb745ac1a86edfEli Cohen} 13233c87f0af60146b375220809c1cb745ac1a86edfEli Cohen 133c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic void mlx4_en_event(struct mlx4_dev *dev, void *endev_ptr, 134c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin enum mlx4_dev_event event, int port) 135c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 136c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin struct mlx4_en_dev *mdev = (struct mlx4_en_dev *) endev_ptr; 137c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin struct mlx4_en_priv *priv; 138c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 139c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin switch (event) { 140c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin case MLX4_DEV_EVENT_PORT_UP: 141c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin case MLX4_DEV_EVENT_PORT_DOWN: 14213bf58b7604d9adfebb8b7c95e6cfb31ec17c699Jack Morgenstein if (!mdev->pndev[port]) 14313bf58b7604d9adfebb8b7c95e6cfb31ec17c699Jack Morgenstein return; 14413bf58b7604d9adfebb8b7c95e6cfb31ec17c699Jack Morgenstein priv = netdev_priv(mdev->pndev[port]); 145c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* To prevent races, we poll the link state in a separate 146c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin task rather than changing it here */ 147c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin priv->link_state = event; 148c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin queue_work(mdev->workqueue, &priv->linkstate_task); 149c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin break; 150c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 151c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin case MLX4_DEV_EVENT_CATASTROPHIC_ERROR: 152c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_err(mdev, "Internal error detected, restarting device\n"); 153c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin break; 154c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 155c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin default: 15613bf58b7604d9adfebb8b7c95e6cfb31ec17c699Jack Morgenstein if (port < 1 || port > dev->caps.num_ports || 15713bf58b7604d9adfebb8b7c95e6cfb31ec17c699Jack Morgenstein !mdev->pndev[port]) 15813bf58b7604d9adfebb8b7c95e6cfb31ec17c699Jack Morgenstein return; 15913bf58b7604d9adfebb8b7c95e6cfb31ec17c699Jack Morgenstein mlx4_warn(mdev, "Unhandled event %d for port %d\n", event, port); 160c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 161c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 162c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 163c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic void mlx4_en_remove(struct mlx4_dev *dev, void *endev_ptr) 164c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 165c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin struct mlx4_en_dev *mdev = endev_ptr; 166c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin int i; 167c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 168c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mutex_lock(&mdev->state_lock); 169c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->device_up = false; 170c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mutex_unlock(&mdev->state_lock); 171c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 172c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) 173c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mdev->pndev[i]) 174c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_en_destroy_netdev(mdev->pndev[i]); 175c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 176c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin flush_workqueue(mdev->workqueue); 177c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin destroy_workqueue(mdev->workqueue); 178c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_mr_free(dev, &mdev->mr); 1797398af403f621418fa05c6936cac34aa06b5a758Alexander Guller iounmap(mdev->uar_map); 180c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_uar_free(dev, &mdev->priv_uar); 181c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_pd_free(dev, mdev->priv_pdn); 182c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin kfree(mdev); 183c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 184c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 185c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic void *mlx4_en_add(struct mlx4_dev *dev) 186c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 187c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin struct mlx4_en_dev *mdev; 188c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin int i; 189c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin int err; 190c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 1910a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches printk_once(KERN_INFO "%s", mlx4_en_version); 192c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 193c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev = kzalloc(sizeof *mdev, GFP_KERNEL); 194c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (!mdev) { 195c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin dev_err(&dev->pdev->dev, "Device struct alloc failed, " 196c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin "aborting.\n"); 197c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin err = -ENOMEM; 198c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_free_res; 199c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 200c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 201c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mlx4_pd_alloc(dev, &mdev->priv_pdn)) 202c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_free_dev; 203c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 204c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mlx4_uar_alloc(dev, &mdev->priv_uar)) 205c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_pd; 206c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 2074979d18fe105297f8f065743f31f8f735da8df2dRoland Dreier mdev->uar_map = ioremap((phys_addr_t) mdev->priv_uar.pfn << PAGE_SHIFT, 2084979d18fe105297f8f065743f31f8f735da8df2dRoland Dreier PAGE_SIZE); 209c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (!mdev->uar_map) 210c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_uar; 211c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin spin_lock_init(&mdev->uar_lock); 212c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 213c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->dev = dev; 214c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->dma_device = &(dev->pdev->dev); 215c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->pdev = dev->pdev; 216c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->device_up = false; 217c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 218c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->LSO_support = !!(dev->caps.flags & (1 << 15)); 219c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (!mdev->LSO_support) 220c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_warn(mdev, "LSO not supported, please upgrade to later " 221c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin "FW version to enable LSO\n"); 222c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 223c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mlx4_mr_alloc(mdev->dev, mdev->priv_pdn, 0, ~0ull, 224c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin MLX4_PERM_LOCAL_WRITE | MLX4_PERM_LOCAL_READ, 225c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 0, 0, &mdev->mr)) { 226c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_err(mdev, "Failed allocating memory region\n"); 2277398af403f621418fa05c6936cac34aa06b5a758Alexander Guller goto err_map; 228c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 229c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mlx4_mr_enable(mdev->dev, &mdev->mr)) { 230c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_err(mdev, "Failed enabling memory region\n"); 231c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_mr; 232c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 233c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 234c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* Build device profile according to supplied module parameters */ 235c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin err = mlx4_en_get_profile(mdev); 236c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (err) { 237c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_err(mdev, "Bad module parameters, aborting.\n"); 238c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_mr; 239c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 240c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 24125985edcedea6396277003854657b5f3cb31a628Lucas De Marchi /* Configure which ports to start according to module parameters */ 242c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->port_cnt = 0; 243c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) 244c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->port_cnt++; 245c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 246c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) { 2471fb9876e9bf895ea4127ff17180f1b2ab37771b6Yevgeny Petrilin if (!dev->caps.comp_pool) { 2481fb9876e9bf895ea4127ff17180f1b2ab37771b6Yevgeny Petrilin mdev->profile.prof[i].rx_ring_num = 2491fb9876e9bf895ea4127ff17180f1b2ab37771b6Yevgeny Petrilin rounddown_pow_of_two(max_t(int, MIN_RX_RINGS, 2501fb9876e9bf895ea4127ff17180f1b2ab37771b6Yevgeny Petrilin min_t(int, 2511fb9876e9bf895ea4127ff17180f1b2ab37771b6Yevgeny Petrilin dev->caps.num_comp_vectors, 2521fb9876e9bf895ea4127ff17180f1b2ab37771b6Yevgeny Petrilin MAX_RX_RINGS))); 2531fb9876e9bf895ea4127ff17180f1b2ab37771b6Yevgeny Petrilin } else { 2541fb9876e9bf895ea4127ff17180f1b2ab37771b6Yevgeny Petrilin mdev->profile.prof[i].rx_ring_num = rounddown_pow_of_two( 2551fb9876e9bf895ea4127ff17180f1b2ab37771b6Yevgeny Petrilin min_t(int, dev->caps.comp_pool/ 2561fb9876e9bf895ea4127ff17180f1b2ab37771b6Yevgeny Petrilin dev->caps.num_ports - 1 , MAX_MSIX_P_PORT - 1)); 2571fb9876e9bf895ea4127ff17180f1b2ab37771b6Yevgeny Petrilin } 258c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 259c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 260c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* Create our own workqueue for reset/multicast tasks 261c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * Note: we cannot use the shared workqueue because of deadlocks caused 262c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * by the rtnl lock */ 263c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->workqueue = create_singlethread_workqueue("mlx4_en"); 264c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (!mdev->workqueue) { 265c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin err = -ENOMEM; 2661a44cc3778f63dca5795708da2a2a7696da7fd61Roland Dreier goto err_mr; 267c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 268c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 269c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* At this stage all non-port specific tasks are complete: 270c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * mark the card state as up */ 271c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mutex_init(&mdev->state_lock); 272c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->device_up = true; 273c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 274c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* Setup ports */ 275c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 276c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* Create a netdev for each port */ 277c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) { 278c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_info(mdev, "Activating port:%d\n", i); 2793c2fa83f9c2bbb3e91992a2fc443b7104a07e0bcYevgeny Petrilin if (mlx4_en_init_netdev(mdev, i, &mdev->profile.prof[i])) 280c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->pndev[i] = NULL; 281c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 282c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin return mdev; 283c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 284c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_mr: 285c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_mr_free(dev, &mdev->mr); 2867398af403f621418fa05c6936cac34aa06b5a758Alexander Gullererr_map: 2877398af403f621418fa05c6936cac34aa06b5a758Alexander Guller if (!mdev->uar_map) 2887398af403f621418fa05c6936cac34aa06b5a758Alexander Guller iounmap(mdev->uar_map); 289c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_uar: 290c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_uar_free(dev, &mdev->priv_uar); 291c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_pd: 292c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_pd_free(dev, mdev->priv_pdn); 293c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_free_dev: 294c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin kfree(mdev); 295c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_free_res: 296c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin return NULL; 297c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 298c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 299c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic struct mlx4_interface mlx4_en_interface = { 30033c87f0af60146b375220809c1cb745ac1a86edfEli Cohen .add = mlx4_en_add, 30133c87f0af60146b375220809c1cb745ac1a86edfEli Cohen .remove = mlx4_en_remove, 30233c87f0af60146b375220809c1cb745ac1a86edfEli Cohen .event = mlx4_en_event, 30333c87f0af60146b375220809c1cb745ac1a86edfEli Cohen .get_dev = mlx4_en_get_netdev, 3040345584e0b8be3735a950d17c7e463db20c6ce27Yevgeny Petrilin .protocol = MLX4_PROT_ETH, 305c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin}; 306c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 307c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic int __init mlx4_en_init(void) 308c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 309c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin return mlx4_register_interface(&mlx4_en_interface); 310c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 311c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 312c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic void __exit mlx4_en_cleanup(void) 313c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 314c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_unregister_interface(&mlx4_en_interface); 315c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 316c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 317c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinmodule_init(mlx4_en_init); 318c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinmodule_exit(mlx4_en_cleanup); 319c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 320