en_main.c revision 4979d18fe105297f8f065743f31f8f735da8df2d
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 65a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 660533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin/* Enable RSS TCP traffic */ 670533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny PetrilinMLX4_EN_PARM_INT(tcp_rss, 1, 680533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin "Enable RSS for incomming TCP traffic or disabled (0)"); 690533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin/* Enable RSS UDP traffic */ 700533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny PetrilinMLX4_EN_PARM_INT(udp_rss, 1, 710533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin "Enable RSS for incomming UDP traffic or disabled (0)"); 72a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 73a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin/* Priority pausing */ 74a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny PetrilinMLX4_EN_PARM_INT(pfctx, 0, "Priority based Flow Control policy on TX[7:0]." 75a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin " Per priority bit mask"); 76a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny PetrilinMLX4_EN_PARM_INT(pfcrx, 0, "Priority based Flow Control policy on RX[7:0]." 77a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin " Per priority bit mask"); 78a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 790a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perchesint en_print(const char *level, const struct mlx4_en_priv *priv, 800a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches const char *format, ...) 810a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches{ 820a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches va_list args; 830a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches struct va_format vaf; 840a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches int i; 850a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches 860a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches va_start(args, format); 870a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches 880a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches vaf.fmt = format; 890a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches vaf.va = &args; 900a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches if (priv->registered) 910a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches i = printk("%s%s: %s: %pV", 920a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches level, DRV_NAME, priv->dev->name, &vaf); 930a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches else 940a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches i = printk("%s%s: %s: Port %d: %pV", 950a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches level, DRV_NAME, dev_name(&priv->mdev->pdev->dev), 960a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches priv->port, &vaf); 970a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches va_end(args); 980a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches 990a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches return i; 1000a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches} 1010a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches 102a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilinstatic int mlx4_en_get_profile(struct mlx4_en_dev *mdev) 103a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin{ 104a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin struct mlx4_en_profile *params = &mdev->profile; 105a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin int i; 106a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 1070533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin params->tcp_rss = tcp_rss; 1080533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin params->udp_rss = udp_rss; 1090533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin if (params->udp_rss && !mdev->dev->caps.udp_rss) { 1100533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin mlx4_warn(mdev, "UDP RSS is not supported on this device.\n"); 1110533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin params->udp_rss = 0; 1120533943c5c45cce2e26432bf0a6b8e114757c897Yevgeny Petrilin } 113a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin for (i = 1; i <= MLX4_MAX_PORTS; i++) { 114a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].rx_pause = 1; 115a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].rx_ppp = pfcrx; 116a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].tx_pause = 1; 117a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].tx_ppp = pfctx; 118a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].tx_ring_size = MLX4_EN_DEF_TX_RING_SIZE; 119a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin params->prof[i].rx_ring_size = MLX4_EN_DEF_RX_RING_SIZE; 120f813cad836ab14b764cfe76f42a3b50bb9677b30Yevgeny Petrilin params->prof[i].tx_ring_num = MLX4_EN_NUM_TX_RINGS + 121f813cad836ab14b764cfe76f42a3b50bb9677b30Yevgeny Petrilin (!!pfcrx) * MLX4_EN_NUM_PPP_RINGS; 122a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin } 123a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 124a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin return 0; 125a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin} 126a2b28737a2c504ad4306eec30fc893e7f4513359Yevgeny Petrilin 12733c87f0af60146b375220809c1cb745ac1a86edfEli Cohenstatic void *mlx4_en_get_netdev(struct mlx4_dev *dev, void *ctx, u8 port) 12833c87f0af60146b375220809c1cb745ac1a86edfEli Cohen{ 12933c87f0af60146b375220809c1cb745ac1a86edfEli Cohen struct mlx4_en_dev *endev = ctx; 13033c87f0af60146b375220809c1cb745ac1a86edfEli Cohen 13133c87f0af60146b375220809c1cb745ac1a86edfEli Cohen return endev->pndev[port]; 13233c87f0af60146b375220809c1cb745ac1a86edfEli Cohen} 13333c87f0af60146b375220809c1cb745ac1a86edfEli Cohen 134c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic void mlx4_en_event(struct mlx4_dev *dev, void *endev_ptr, 135c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin enum mlx4_dev_event event, int port) 136c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 137c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin struct mlx4_en_dev *mdev = (struct mlx4_en_dev *) endev_ptr; 138c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin struct mlx4_en_priv *priv; 139c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 140c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (!mdev->pndev[port]) 141c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin return; 142c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 143c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin priv = netdev_priv(mdev->pndev[port]); 144c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin switch (event) { 145c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin case MLX4_DEV_EVENT_PORT_UP: 146c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin case MLX4_DEV_EVENT_PORT_DOWN: 147c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* To prevent races, we poll the link state in a separate 148c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin task rather than changing it here */ 149c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin priv->link_state = event; 150c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin queue_work(mdev->workqueue, &priv->linkstate_task); 151c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin break; 152c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 153c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin case MLX4_DEV_EVENT_CATASTROPHIC_ERROR: 154c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_err(mdev, "Internal error detected, restarting device\n"); 155c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin break; 156c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 157c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin default: 158c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_warn(mdev, "Unhandled event: %d\n", event); 159c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 160c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 161c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 162c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic void mlx4_en_remove(struct mlx4_dev *dev, void *endev_ptr) 163c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 164c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin struct mlx4_en_dev *mdev = endev_ptr; 165c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin int i; 166c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 167c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mutex_lock(&mdev->state_lock); 168c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->device_up = false; 169c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mutex_unlock(&mdev->state_lock); 170c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 171c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) 172c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mdev->pndev[i]) 173c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_en_destroy_netdev(mdev->pndev[i]); 174c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 175c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin flush_workqueue(mdev->workqueue); 176c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin destroy_workqueue(mdev->workqueue); 177c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_mr_free(dev, &mdev->mr); 178c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_uar_free(dev, &mdev->priv_uar); 179c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_pd_free(dev, mdev->priv_pdn); 180c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin kfree(mdev); 181c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 182c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 183c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic void *mlx4_en_add(struct mlx4_dev *dev) 184c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 185c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin struct mlx4_en_dev *mdev; 186c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin int i; 187c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin int err; 188c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 1890a645e809759a4b9c876d3e9ca6c139784a97a38Joe Perches printk_once(KERN_INFO "%s", mlx4_en_version); 190c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 191c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev = kzalloc(sizeof *mdev, GFP_KERNEL); 192c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (!mdev) { 193c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin dev_err(&dev->pdev->dev, "Device struct alloc failed, " 194c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin "aborting.\n"); 195c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin err = -ENOMEM; 196c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_free_res; 197c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 198c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 199c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mlx4_pd_alloc(dev, &mdev->priv_pdn)) 200c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_free_dev; 201c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 202c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mlx4_uar_alloc(dev, &mdev->priv_uar)) 203c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_pd; 204c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 2054979d18fe105297f8f065743f31f8f735da8df2dRoland Dreier mdev->uar_map = ioremap((phys_addr_t) mdev->priv_uar.pfn << PAGE_SHIFT, 2064979d18fe105297f8f065743f31f8f735da8df2dRoland Dreier PAGE_SIZE); 207c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (!mdev->uar_map) 208c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_uar; 209c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin spin_lock_init(&mdev->uar_lock); 210c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 211c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->dev = dev; 212c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->dma_device = &(dev->pdev->dev); 213c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->pdev = dev->pdev; 214c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->device_up = false; 215c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 216c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->LSO_support = !!(dev->caps.flags & (1 << 15)); 217c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (!mdev->LSO_support) 218c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_warn(mdev, "LSO not supported, please upgrade to later " 219c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin "FW version to enable LSO\n"); 220c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 221c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mlx4_mr_alloc(mdev->dev, mdev->priv_pdn, 0, ~0ull, 222c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin MLX4_PERM_LOCAL_WRITE | MLX4_PERM_LOCAL_READ, 223c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 0, 0, &mdev->mr)) { 224c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_err(mdev, "Failed allocating memory region\n"); 225c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_uar; 226c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 227c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (mlx4_mr_enable(mdev->dev, &mdev->mr)) { 228c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_err(mdev, "Failed enabling memory region\n"); 229c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_mr; 230c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 231c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 232c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* Build device profile according to supplied module parameters */ 233c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin err = mlx4_en_get_profile(mdev); 234c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (err) { 235c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_err(mdev, "Bad module parameters, aborting.\n"); 236c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin goto err_mr; 237c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 238c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 239c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* Configure wich ports to start according to module parameters */ 240c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->port_cnt = 0; 241c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) 242c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->port_cnt++; 243c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 244c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* If we did not receive an explicit number of Rx rings, default to 245c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * the number of completion vectors populated by the mlx4_core */ 246c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) { 247c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_info(mdev, "Using %d tx rings for port:%d\n", 248c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->profile.prof[i].tx_ring_num, i); 249b6b912e0804dc1b3e856da3cc82fbe78b50e968cYevgeny Petrilin mdev->profile.prof[i].rx_ring_num = min_t(int, 250b6b912e0804dc1b3e856da3cc82fbe78b50e968cYevgeny Petrilin roundup_pow_of_two(dev->caps.num_comp_vectors), 251b6b912e0804dc1b3e856da3cc82fbe78b50e968cYevgeny Petrilin MAX_RX_RINGS); 2522d6a7b7559b47f81c50a1df91910edefff79b9b4Yevgeny Petrilin mlx4_info(mdev, "Defaulting to %d rx rings for port:%d\n", 2532d6a7b7559b47f81c50a1df91910edefff79b9b4Yevgeny Petrilin mdev->profile.prof[i].rx_ring_num, i); 254c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 255c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 256c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* Create our own workqueue for reset/multicast tasks 257c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * Note: we cannot use the shared workqueue because of deadlocks caused 258c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * by the rtnl lock */ 259c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->workqueue = create_singlethread_workqueue("mlx4_en"); 260c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin if (!mdev->workqueue) { 261c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin err = -ENOMEM; 2621a44cc3778f63dca5795708da2a2a7696da7fd61Roland Dreier goto err_mr; 263c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 264c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 265c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* At this stage all non-port specific tasks are complete: 266c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin * mark the card state as up */ 267c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mutex_init(&mdev->state_lock); 268c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->device_up = true; 269c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 270c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* Setup ports */ 271c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 272c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin /* Create a netdev for each port */ 273c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) { 274c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_info(mdev, "Activating port:%d\n", i); 2753c2fa83f9c2bbb3e91992a2fc443b7104a07e0bcYevgeny Petrilin if (mlx4_en_init_netdev(mdev, i, &mdev->profile.prof[i])) 276c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mdev->pndev[i] = NULL; 277c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin } 278c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin return mdev; 279c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 280c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_mr: 281c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_mr_free(dev, &mdev->mr); 282c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_uar: 283c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_uar_free(dev, &mdev->priv_uar); 284c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_pd: 285c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_pd_free(dev, mdev->priv_pdn); 286c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_free_dev: 287c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin kfree(mdev); 288c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinerr_free_res: 289c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin return NULL; 290c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 291c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 292c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic struct mlx4_interface mlx4_en_interface = { 29333c87f0af60146b375220809c1cb745ac1a86edfEli Cohen .add = mlx4_en_add, 29433c87f0af60146b375220809c1cb745ac1a86edfEli Cohen .remove = mlx4_en_remove, 29533c87f0af60146b375220809c1cb745ac1a86edfEli Cohen .event = mlx4_en_event, 29633c87f0af60146b375220809c1cb745ac1a86edfEli Cohen .get_dev = mlx4_en_get_netdev, 29733c87f0af60146b375220809c1cb745ac1a86edfEli Cohen .protocol = MLX4_PROTOCOL_EN, 298c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin}; 299c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 300c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic int __init mlx4_en_init(void) 301c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 302c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin return mlx4_register_interface(&mlx4_en_interface); 303c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 304c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 305c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinstatic void __exit mlx4_en_cleanup(void) 306c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin{ 307c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin mlx4_unregister_interface(&mlx4_en_interface); 308c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin} 309c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 310c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinmodule_init(mlx4_en_init); 311c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilinmodule_exit(mlx4_en_cleanup); 312c27a02cd94d6695fbe5858ca364b1e415af02212Yevgeny Petrilin 313