Skip to content

Commit 3f89a64

Browse files
Achiad Shochatdledford
authored andcommitted
IB/mlx5: Extend query_device/port to support RoCE
Using the vport access functions to retrieve the Ethernet specific information and return this information in ib_query_device and ib_query_port. Signed-off-by: Achiad Shochat <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 9efa752 commit 3f89a64

File tree

2 files changed

+69
-13
lines changed

2 files changed

+69
-13
lines changed

drivers/infiniband/hw/mlx5/main.c

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <linux/io-mapping.h>
4141
#include <linux/sched.h>
4242
#include <rdma/ib_user_verbs.h>
43+
#include <rdma/ib_addr.h>
4344
#include <linux/mlx5/vport.h>
4445
#include <rdma/ib_smi.h>
4546
#include <rdma/ib_umem.h>
@@ -120,6 +121,50 @@ static struct net_device *mlx5_ib_get_netdev(struct ib_device *device,
120121
return ndev;
121122
}
122123

124+
static int mlx5_query_port_roce(struct ib_device *device, u8 port_num,
125+
struct ib_port_attr *props)
126+
{
127+
struct mlx5_ib_dev *dev = to_mdev(device);
128+
struct net_device *ndev;
129+
enum ib_mtu ndev_ib_mtu;
130+
131+
memset(props, 0, sizeof(*props));
132+
133+
props->port_cap_flags |= IB_PORT_CM_SUP;
134+
props->port_cap_flags |= IB_PORT_IP_BASED_GIDS;
135+
136+
props->gid_tbl_len = MLX5_CAP_ROCE(dev->mdev,
137+
roce_address_table_size);
138+
props->max_mtu = IB_MTU_4096;
139+
props->max_msg_sz = 1 << MLX5_CAP_GEN(dev->mdev, log_max_msg);
140+
props->pkey_tbl_len = 1;
141+
props->state = IB_PORT_DOWN;
142+
props->phys_state = 3;
143+
144+
mlx5_query_nic_vport_qkey_viol_cntr(dev->mdev,
145+
(u16 *)&props->qkey_viol_cntr);
146+
147+
ndev = mlx5_ib_get_netdev(device, port_num);
148+
if (!ndev)
149+
return 0;
150+
151+
if (netif_running(ndev) && netif_carrier_ok(ndev)) {
152+
props->state = IB_PORT_ACTIVE;
153+
props->phys_state = 5;
154+
}
155+
156+
ndev_ib_mtu = iboe_get_mtu(ndev->mtu);
157+
158+
dev_put(ndev);
159+
160+
props->active_mtu = min(props->max_mtu, ndev_ib_mtu);
161+
162+
props->active_width = IB_WIDTH_4X; /* TODO */
163+
props->active_speed = IB_SPEED_QDR; /* TODO */
164+
165+
return 0;
166+
}
167+
123168
static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev)
124169
{
125170
return !dev->mdev->issi;
@@ -158,13 +203,21 @@ static int mlx5_query_system_image_guid(struct ib_device *ibdev,
158203

159204
case MLX5_VPORT_ACCESS_METHOD_HCA:
160205
err = mlx5_query_hca_vport_system_image_guid(mdev, &tmp);
161-
if (!err)
162-
*sys_image_guid = cpu_to_be64(tmp);
163-
return err;
206+
break;
207+
208+
case MLX5_VPORT_ACCESS_METHOD_NIC:
209+
err = mlx5_query_nic_vport_system_image_guid(mdev, &tmp);
210+
break;
164211

165212
default:
166213
return -EINVAL;
167214
}
215+
216+
if (!err)
217+
*sys_image_guid = cpu_to_be64(tmp);
218+
219+
return err;
220+
168221
}
169222

170223
static int mlx5_query_max_pkeys(struct ib_device *ibdev,
@@ -218,13 +271,20 @@ static int mlx5_query_node_guid(struct mlx5_ib_dev *dev,
218271

219272
case MLX5_VPORT_ACCESS_METHOD_HCA:
220273
err = mlx5_query_hca_vport_node_guid(dev->mdev, &tmp);
221-
if (!err)
222-
*node_guid = cpu_to_be64(tmp);
223-
return err;
274+
break;
275+
276+
case MLX5_VPORT_ACCESS_METHOD_NIC:
277+
err = mlx5_query_nic_vport_node_guid(dev->mdev, &tmp);
278+
break;
224279

225280
default:
226281
return -EINVAL;
227282
}
283+
284+
if (!err)
285+
*node_guid = cpu_to_be64(tmp);
286+
287+
return err;
228288
}
229289

230290
struct mlx5_reg_node_desc {
@@ -522,6 +582,9 @@ int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
522582
case MLX5_VPORT_ACCESS_METHOD_HCA:
523583
return mlx5_query_hca_port(ibdev, port, props);
524584

585+
case MLX5_VPORT_ACCESS_METHOD_NIC:
586+
return mlx5_query_port_roce(ibdev, port, props);
587+
525588
default:
526589
return -EINVAL;
527590
}

include/linux/mlx5/driver.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -632,13 +632,6 @@ extern struct workqueue_struct *mlx5_core_wq;
632632
.struct_offset_bytes = offsetof(struct ib_unpacked_ ## header, field), \
633633
.struct_size_bytes = sizeof((struct ib_unpacked_ ## header *)0)->field
634634

635-
struct ib_field {
636-
size_t struct_offset_bytes;
637-
size_t struct_size_bytes;
638-
int offset_bits;
639-
int size_bits;
640-
};
641-
642635
static inline struct mlx5_core_dev *pci2mlx5_core_dev(struct pci_dev *pdev)
643636
{
644637
return pci_get_drvdata(pdev);

0 commit comments

Comments
 (0)