[ofa-general][PATCH 10/11 v3] mlx4_core: Auto negotiation support
Yevgeny Petrilin
yevgenyp at mellanox.co.il
Wed Aug 20 06:22:45 PDT 2008
From: Yevgeny Petrilin <yevgenyp at mellanox.co.il>
Date: Wed, 20 Aug 2008 10:25:17 +0300
Subject: [PATCH] mlx4_core: Auto negotiation support
At any time when port link is down (except to driver restart), and port
is configured to auto sensing, we try to sense port's configuration in
order to determine how to initialize the port.
If port type need to be changed, all ulp's are unregistered and then
registered again with the new port types. Sense is done with intervals
that move between 1-3 seconds.
Signed-off-by: Yevgeny Petrilin <yevgenyp at mellanox.co.il>
---
drivers/net/mlx4/Makefile | 2 +-
drivers/net/mlx4/eq.c | 16 +++--
drivers/net/mlx4/intf.c | 4 +
drivers/net/mlx4/main.c | 97 +++++++++++++++++++++++-----
drivers/net/mlx4/mlx4.h | 24 +++++++
drivers/net/mlx4/sense.c | 148 +++++++++++++++++++++++++++++++++++++++++++
include/linux/mlx4/cmd.h | 1 +
include/linux/mlx4/device.h | 6 +-
8 files changed, 272 insertions(+), 26 deletions(-)
create mode 100644 drivers/net/mlx4/sense.c
diff --git a/drivers/net/mlx4/Makefile b/drivers/net/mlx4/Makefile
index f4932d8..3f71687 100644
--- a/drivers/net/mlx4/Makefile
+++ b/drivers/net/mlx4/Makefile
@@ -1,4 +1,4 @@
obj-$(CONFIG_MLX4_CORE) += mlx4_core.o
mlx4_core-y := alloc.o catas.o cmd.o cq.o eq.o fw.o icm.o intf.o main.o mcg.o \
- mr.o pd.o profile.o qp.o reset.o srq.o port.o
+ mr.o pd.o profile.o qp.o reset.o srq.o port.o sense.o
diff --git a/drivers/net/mlx4/eq.c b/drivers/net/mlx4/eq.c
index b436234..bd3ce60 100644
--- a/drivers/net/mlx4/eq.c
+++ b/drivers/net/mlx4/eq.c
@@ -163,6 +163,7 @@ static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
int cqn;
int eqes_found = 0;
int set_ci = 0;
+ int port;
while ((eqe = next_eqe_sw(eq))) {
/*
@@ -203,11 +204,16 @@ static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
break;
case MLX4_EVENT_TYPE_PORT_CHANGE:
- mlx4_dispatch_event(dev,
- eqe->subtype == MLX4_PORT_CHANGE_SUBTYPE_ACTIVE ?
- MLX4_DEV_EVENT_PORT_UP :
- MLX4_DEV_EVENT_PORT_DOWN,
- be32_to_cpu(eqe->event.port_change.port) >> 28);
+ port = be32_to_cpu(eqe->event.port_change.port) >> 28;
+ if (eqe->subtype == MLX4_PORT_CHANGE_SUBTYPE_DOWN) {
+ mlx4_dispatch_event(dev, MLX4_DEV_EVENT_PORT_DOWN,
+ port);
+ mlx4_priv(dev)->sense.do_sense_port[port] = 1;
+ } else {
+ mlx4_dispatch_event(dev, MLX4_DEV_EVENT_PORT_UP,
+ port);
+ mlx4_priv(dev)->sense.do_sense_port[port] = 0;
+ }
break;
case MLX4_EVENT_TYPE_CQ_ERROR:
diff --git a/drivers/net/mlx4/intf.c b/drivers/net/mlx4/intf.c
index 0e7eb10..30ef000 100644
--- a/drivers/net/mlx4/intf.c
+++ b/drivers/net/mlx4/intf.c
@@ -141,6 +141,8 @@ int mlx4_register_device(struct mlx4_dev *dev)
mutex_unlock(&intf_mutex);
mlx4_start_catas_poll(dev);
+ mlx4_start_sense(dev);
+
return 0;
}
@@ -149,6 +151,8 @@ void mlx4_unregister_device(struct mlx4_dev *dev)
struct mlx4_priv *priv = mlx4_priv(dev);
struct mlx4_interface *intf;
+ mlx4_stop_sense(dev);
+
mlx4_stop_catas_poll(dev);
mutex_lock(&intf_mutex);
diff --git a/drivers/net/mlx4/main.c b/drivers/net/mlx4/main.c
index 4f6ec90..92784ad 100644
--- a/drivers/net/mlx4/main.c
+++ b/drivers/net/mlx4/main.c
@@ -103,18 +103,21 @@ module_param_array_named(port_type, port_type_arr, charp, NULL, 0444);
MODULE_PARM_DESC(port_type, "Ports L2 type (ib/eth/auto, entry per port, "
"comma seperated, default ib for all)");
-static int mlx4_check_port_params(struct mlx4_dev *dev,
- enum mlx4_port_type *port_type)
+int mlx4_check_port_params(struct mlx4_dev *dev,
+ enum mlx4_port_type *port_type)
{
- if (port_type[0] != port_type[1] &&
+ if ((port_type[0] != port_type[1] ||
+ port_type[0] == MLX4_PORT_TYPE_AUTO) &&
!(dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP)) {
mlx4_err(dev, "Only same port types supported "
"on this HCA, aborting.\n");
return -EINVAL;
}
- if ((port_type[0] == MLX4_PORT_TYPE_ETH) &&
- (port_type[1] == MLX4_PORT_TYPE_IB)) {
- mlx4_err(dev, "eth-ib configuration is not supported.\n");
+ if ((port_type[0] == MLX4_PORT_TYPE_ETH &&
+ port_type[1] != MLX4_PORT_TYPE_ETH) ||
+ (port_type[1] == MLX4_PORT_TYPE_IB &&
+ port_type[0] != MLX4_PORT_TYPE_IB)) {
+ mlx4_err(dev, "Given port configuration is not supported.\n");
return -EINVAL;
}
return 0;
@@ -128,8 +131,10 @@ static void mlx4_str2port_type(char **port_str,
for (i = 0; i < MLX4_MAX_PORTS; i++) {
if (!strcmp(port_str[i], "eth"))
port_type[i] = MLX4_PORT_TYPE_ETH;
- else
+ else if (!strcmp(port_str[i], "ib"))
port_type[i] = MLX4_PORT_TYPE_IB;
+ else
+ port_type[i] = MLX4_PORT_TYPE_AUTO;
}
}
@@ -228,11 +233,17 @@ static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
mlx4_warn(dev, "FW doesn't support Multi Protocol, "
"loading IB only\n");
dev->caps.port_type[i] = MLX4_PORT_TYPE_IB;
+ dev->caps.possible_type[i] = MLX4_PORT_TYPE_IB;
continue;
}
- if (port_type[i-1] & dev_cap->supported_port_types[i])
- dev->caps.port_type[i] = port_type[i-1];
- else {
+ mlx4_priv(dev)->sense.sense_allowed[i] =
+ (dev_cap->supported_port_types[i] >> 1) & 1;
+ if (port_type[i-1] & dev_cap->supported_port_types[i]) {
+ dev->caps.possible_type[i] = port_type[i-1];
+ dev->caps.port_type[i] =
+ (port_type[i-1] == MLX4_PORT_TYPE_ETH) ?
+ port_type[i-1] : MLX4_PORT_TYPE_IB;
+ } else {
mlx4_err(dev, "Requested port type for port %d "
"not supported by HW\n", i);
return -ENODEV;
@@ -270,7 +281,7 @@ static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
/* Changes the port configuration of the device.
* Every user of this function must hold the port lock */
-static int mlx4_change_port_types(struct mlx4_dev *dev,
+int mlx4_change_port_types(struct mlx4_dev *dev,
enum mlx4_port_type *port_types)
{
int err = 0;
@@ -281,10 +292,13 @@ static int mlx4_change_port_types(struct mlx4_dev *dev,
if (port_types[port] != dev->caps.port_type[port + 1]) {
change = 1;
dev->caps.port_type[port + 1] = port_types[port];
+ if (dev->caps.possible_type[port + 1] != MLX4_PORT_TYPE_AUTO)
+ dev->caps.possible_type[port + 1] = port_types[port];
}
}
if (change) {
mlx4_unregister_device(dev);
+ flush_workqueue(mlx4_priv(dev)->sense.sense_wq);
for (port = 1; port <= dev->caps.num_ports; port++) {
mlx4_CLOSE_PORT(dev, port);
err = mlx4_SET_PORT(dev, port);
@@ -308,9 +322,15 @@ static ssize_t show_port_type(struct device *dev,
struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
port_attr);
struct mlx4_dev *mdev = info->dev;
+ char type[8];
- sprintf(buf, "%s\n", (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_IB) ?
+ sprintf(type, "%s", (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_IB) ?
"ib" : "eth");
+ if (mdev->caps.possible_type[info->port] == MLX4_PORT_TYPE_AUTO)
+ sprintf(buf, "auto (%s)\n", type);
+ else
+ sprintf(buf, "%s\n", type);
+
return strlen(buf);
}
@@ -330,6 +350,8 @@ static ssize_t set_port_type(struct device *dev,
info->tmp_type = MLX4_PORT_TYPE_IB;
else if (!strcmp(buf, "eth\n"))
info->tmp_type = MLX4_PORT_TYPE_ETH;
+ else if (!strcmp(buf, "auto\n"))
+ info->tmp_type = MLX4_PORT_TYPE_AUTO;
else {
mlx4_err(mdev, "%s is not supported port type\n", buf);
return -EINVAL;
@@ -344,8 +366,13 @@ static ssize_t set_port_type(struct device *dev,
if (err)
goto out;
- for (i = 1; i <= mdev->caps.num_ports; i++)
- priv->port[i].tmp_type = 0;
+ for (i = 0; i < mdev->caps.num_ports; i++) {
+ mdev->caps.possible_type[i + 1] = types[i];
+ if (types[i] == MLX4_PORT_TYPE_AUTO)
+ types[i] = mdev->caps.port_type[i + 1];
+
+ priv->port[i + 1].tmp_type = 0;
+ }
err = mlx4_change_port_types(mdev, types);
@@ -970,6 +997,31 @@ static void mlx4_cleanup_port_info(struct mlx4_port_info *info)
device_remove_file(&info->dev->pdev->dev, &info->port_attr);
}
+static void mlx4_set_actual_type(struct mlx4_dev *dev)
+{
+ enum mlx4_port_type stype[dev->caps.num_ports];
+ int i;
+
+ if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP))
+ return;
+
+ for (i = 1; i <= dev->caps.num_ports; i++) {
+ stype[i-1] = 0;
+ if (mlx4_priv(dev)->sense.sense_allowed[i] &&
+ dev->caps.possible_type[i] == MLX4_PORT_TYPE_AUTO) {
+ if (mlx4_SENSE_PORT(dev, i, &stype[i-1]))
+ return;
+ }
+ if (!stype[i-1])
+ stype[i-1] = dev->caps.port_type[i];
+ }
+
+ if (!mlx4_check_port_params(dev, stype)) {
+ for (i = 1; i <= dev->caps.num_ports; i++)
+ dev->caps.port_type[i] = stype[i-1];
+ }
+}
+
static int __mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
{
struct mlx4_priv *priv;
@@ -1093,14 +1145,23 @@ static int __mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
goto err_port;
}
- err = mlx4_register_device(dev);
+ mlx4_set_actual_type(dev);
+
+ err = mlx4_sense_init(dev);
if (err)
goto err_port;
+ err = mlx4_register_device(dev);
+ if (err)
+ goto err_sense;
+
pci_set_drvdata(pdev, dev);
return 0;
+err_sense:
+ mlx4_sense_cleanup(dev);
+
err_port:
for (port = 1; port <= dev->caps.num_ports; port++)
mlx4_cleanup_port_info(&priv->port[port]);
@@ -1160,12 +1221,11 @@ static void mlx4_remove_one(struct pci_dev *pdev)
if (dev) {
mlx4_unregister_device(dev);
-
+ mlx4_sense_cleanup(dev);
for (p = 1; p <= dev->caps.num_ports; p++) {
mlx4_cleanup_port_info(&priv->port[p]);
mlx4_CLOSE_PORT(dev, p);
}
-
mlx4_cleanup_mcg_table(dev);
mlx4_cleanup_qp_table(dev);
mlx4_cleanup_srq_table(dev);
@@ -1222,7 +1282,8 @@ static int __init mlx4_verify_params(void)
for (i = 0; i < MLX4_MAX_PORTS; ++i) {
if (strcmp(port_type_arr[i], "eth") &&
- strcmp(port_type_arr[i], "ib")) {
+ strcmp(port_type_arr[i], "ib") &&
+ strcmp(port_type_arr[i], "auto")) {
printk(KERN_WARNING "mlx4_core: bad port_type for "
"port %d: %s\n", i, port_type_arr[i]);
return -1;
diff --git a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h
index 4c18e36..be3496b 100644
--- a/drivers/net/mlx4/mlx4.h
+++ b/drivers/net/mlx4/mlx4.h
@@ -40,6 +40,8 @@
#include <linux/mutex.h>
#include <linux/radix-tree.h>
#include <linux/timer.h>
+#include <linux/random.h>
+#include <linux/workqueue.h>
#include <linux/mlx4/device.h>
#include <linux/mlx4/driver.h>
@@ -287,6 +289,14 @@ struct mlx4_port_info {
struct mlx4_vlan_table vlan_table;
};
+struct mlx4_sense {
+ struct mlx4_dev *dev;
+ u8 do_sense_port[MLX4_MAX_PORTS + 1];
+ u8 sense_allowed[MLX4_MAX_PORTS + 1];
+ struct delayed_work sense_poll;
+ struct workqueue_struct *sense_wq;
+};
+
struct mlx4_priv {
struct mlx4_dev dev;
@@ -316,6 +326,7 @@ struct mlx4_priv {
struct mlx4_uar driver_uar;
void __iomem *kar;
struct mlx4_port_info port[MLX4_MAX_PORTS + 1];
+ struct mlx4_sense sense;
spinlock_t port_lock;
};
@@ -324,6 +335,9 @@ static inline struct mlx4_priv *mlx4_priv(struct mlx4_dev *dev)
return container_of(dev, struct mlx4_priv, dev);
}
+#define MIN_SENCE_RANGE HZ
+#define MAX_SENCE_RANGE (HZ * 3)
+
u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap);
void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj);
u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align);
@@ -387,6 +401,16 @@ void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type);
void mlx4_handle_catas_err(struct mlx4_dev *dev);
+void mlx4_start_sense(struct mlx4_dev *dev);
+void mlx4_stop_sense(struct mlx4_dev *dev);
+int mlx4_sense_init(struct mlx4_dev *dev);
+void mlx4_sense_cleanup(struct mlx4_dev *dev);
+int mlx4_SENSE_PORT(struct mlx4_dev *dev, int port, enum mlx4_port_type *type);
+int mlx4_check_port_params(struct mlx4_dev *dev,
+ enum mlx4_port_type *port_type);
+int mlx4_change_port_types(struct mlx4_dev *dev,
+ enum mlx4_port_type *port_types);
+
void mlx4_init_mac_table(struct mlx4_dev *dev, struct mlx4_mac_table *table);
void mlx4_init_vlan_table(struct mlx4_dev *dev, struct mlx4_vlan_table *table);
diff --git a/drivers/net/mlx4/sense.c b/drivers/net/mlx4/sense.c
new file mode 100644
index 0000000..999dcce
--- /dev/null
+++ b/drivers/net/mlx4/sense.c
@@ -0,0 +1,148 @@
+/*
+ * 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/errno.h>
+#include <linux/if_ether.h>
+
+#include <linux/mlx4/cmd.h>
+
+#include "mlx4.h"
+
+static inline unsigned long mlx4_gen_sense_tout(void)
+{
+ return MIN_SENCE_RANGE + random32() %
+ (MAX_SENCE_RANGE - MIN_SENCE_RANGE);
+}
+
+int mlx4_SENSE_PORT(struct mlx4_dev *dev, int port, enum mlx4_port_type *type)
+{
+ u64 out_param;
+ int err = 0;
+
+ err = mlx4_cmd_imm(dev, 0, &out_param, port, 0,
+ MLX4_CMD_SENSE_PORT, MLX4_CMD_TIME_CLASS_B);
+ if (err) {
+ mlx4_err(dev, "Sense command failed for port: %d\n", port);
+ return err;
+ }
+
+ if (out_param > 2) {
+ mlx4_err(dev, "Sense returned illegal value: 0x%llx\n", out_param);
+ return EINVAL;
+ }
+
+ *type = out_param;
+ return 0;
+}
+
+static void mlx4_sense_port(struct work_struct *work)
+{
+ struct delayed_work *delay = container_of(work, struct delayed_work, work);
+ struct mlx4_sense *sense = container_of(delay, struct mlx4_sense,
+ sense_poll);
+ struct mlx4_dev *dev = sense->dev;
+ struct mlx4_priv *priv = mlx4_priv(dev);
+ enum mlx4_port_type stype[dev->caps.num_ports];
+ int err = 0;
+ int i;
+
+ spin_lock(&priv->port_lock);
+ for (i = 1; i <= dev->caps.num_ports; i++) {
+ stype[i-1] = 0;
+ if (sense->do_sense_port[i] && sense->sense_allowed[i] &&
+ dev->caps.possible_type[i] == MLX4_PORT_TYPE_AUTO) {
+ err = mlx4_SENSE_PORT(dev, i, &stype[i-1]);
+ if (err)
+ goto sense_again;
+ }
+ if (!stype[i-1])
+ stype[i-1] = dev->caps.port_type[i];
+ }
+
+ if (mlx4_check_port_params(dev, stype))
+ goto sense_again;
+
+ if (mlx4_change_port_types(dev, stype))
+ mlx4_err(dev, "Failed to change port_types\n");
+
+sense_again:
+ spin_unlock(&priv->port_lock);
+ queue_delayed_work(sense->sense_wq , &sense->sense_poll,
+ mlx4_gen_sense_tout());
+}
+
+
+void mlx4_start_sense(struct mlx4_dev *dev)
+{
+ struct mlx4_priv *priv = mlx4_priv(dev);
+ struct mlx4_sense *sense = &priv->sense;
+
+ if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP))
+ return;
+
+ queue_delayed_work(sense->sense_wq , &sense->sense_poll,
+ mlx4_gen_sense_tout());
+}
+
+
+void mlx4_stop_sense(struct mlx4_dev *dev)
+{
+ cancel_delayed_work(&mlx4_priv(dev)->sense.sense_poll);
+}
+
+int mlx4_sense_init(struct mlx4_dev *dev)
+{
+ struct mlx4_priv *priv = mlx4_priv(dev);
+ struct mlx4_sense *sense = &priv->sense;
+ int port;
+
+ sense->dev = dev;
+ sense->sense_wq = create_singlethread_workqueue("mlx4_sense");
+ if (!sense->sense_wq)
+ return -ENOMEM;
+
+ for (port = 1; port <= dev->caps.num_ports; port++)
+ sense->do_sense_port[port] = 1;
+
+ INIT_DELAYED_WORK(&sense->sense_poll, mlx4_sense_port);
+
+ return 0;
+}
+
+void mlx4_sense_cleanup(struct mlx4_dev *dev)
+{
+ mlx4_stop_sense(dev);
+ flush_workqueue(mlx4_priv(dev)->sense.sense_wq);
+ destroy_workqueue(mlx4_priv(dev)->sense.sense_wq);
+}
+
diff --git a/include/linux/mlx4/cmd.h b/include/linux/mlx4/cmd.h
index cf9c679..0f82293 100644
--- a/include/linux/mlx4/cmd.h
+++ b/include/linux/mlx4/cmd.h
@@ -55,6 +55,7 @@ enum {
MLX4_CMD_CLOSE_PORT = 0xa,
MLX4_CMD_QUERY_HCA = 0xb,
MLX4_CMD_QUERY_PORT = 0x43,
+ MLX4_CMD_SENSE_PORT = 0x4d,
MLX4_CMD_SET_PORT = 0xc,
MLX4_CMD_ACCESS_DDR = 0x2e,
MLX4_CMD_MAP_ICM = 0xffa,
diff --git a/include/linux/mlx4/device.h b/include/linux/mlx4/device.h
index 3496a27..9e2fd41 100644
--- a/include/linux/mlx4/device.h
+++ b/include/linux/mlx4/device.h
@@ -151,8 +151,9 @@ enum qp_region {
};
enum mlx4_port_type {
- MLX4_PORT_TYPE_IB = 1 << 0,
- MLX4_PORT_TYPE_ETH = 1 << 1,
+ MLX4_PORT_TYPE_IB = 1,
+ MLX4_PORT_TYPE_ETH = 2,
+ MLX4_PORT_TYPE_AUTO = 3
};
enum {
@@ -226,6 +227,7 @@ struct mlx4_caps {
int log_num_vlans;
int log_num_prios;
enum mlx4_port_type port_type[MLX4_MAX_PORTS + 1];
+ enum mlx4_port_type possible_type[MLX4_MAX_PORTS + 1];
int reserved_fexch_mpts_base;
int num_fexch_mpts;
};
--
1.5.4
More information about the general
mailing list