aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband/hw
diff options
context:
space:
mode:
authorEli Cohen <eli@mellanox.com>2016-03-11 15:58:42 -0500
committerDoug Ledford <dledford@redhat.com>2016-03-21 17:13:14 -0400
commiteff901d30e6cebd940072637f112ce4d0090ac12 (patch)
treea2105d1050701146ce1c7364721fb1bc35834b53 /drivers/infiniband/hw
parent1f324bff9ba3db276f074169d5b4af9e9c117ba1 (diff)
IB/mlx5: Implement callbacks for manipulating VFs
Implement the IB defined callbacks used to manipulate the policy for the link state, set GUIDs or get statistics information. This functionality is added into a new file that will be used to add any SRIOV related functionality to the mlx5 IB layer. The following callbacks have been added: mlx5_ib_get_vf_config mlx5_ib_set_vf_link_state mlx5_ib_get_vf_stats mlx5_ib_set_vf_guid In addition, publish whether this device is based on a virtual function. In mlx5 supported devices, virtual functions are implemented as vHCAs. vHCAs have their own QP number space so it is possible that two vHCAs will use a QP with the same number at the same time. Signed-off-by: Eli Cohen <eli@mellanox.com> Reviewed-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
Diffstat (limited to 'drivers/infiniband/hw')
-rw-r--r--drivers/infiniband/hw/mlx5/Makefile2
-rw-r--r--drivers/infiniband/hw/mlx5/ib_virt.c194
-rw-r--r--drivers/infiniband/hw/mlx5/main.c10
-rw-r--r--drivers/infiniband/hw/mlx5/mlx5_ib.h8
4 files changed, 213 insertions, 1 deletions
diff --git a/drivers/infiniband/hw/mlx5/Makefile b/drivers/infiniband/hw/mlx5/Makefile
index 4e851889355a..7493a83acd28 100644
--- a/drivers/infiniband/hw/mlx5/Makefile
+++ b/drivers/infiniband/hw/mlx5/Makefile
@@ -1,4 +1,4 @@
1obj-$(CONFIG_MLX5_INFINIBAND) += mlx5_ib.o 1obj-$(CONFIG_MLX5_INFINIBAND) += mlx5_ib.o
2 2
3mlx5_ib-y := main.o cq.o doorbell.o qp.o mem.o srq.o mr.o ah.o mad.o gsi.o 3mlx5_ib-y := main.o cq.o doorbell.o qp.o mem.o srq.o mr.o ah.o mad.o gsi.o ib_virt.o
4mlx5_ib-$(CONFIG_INFINIBAND_ON_DEMAND_PAGING) += odp.o 4mlx5_ib-$(CONFIG_INFINIBAND_ON_DEMAND_PAGING) += odp.o
diff --git a/drivers/infiniband/hw/mlx5/ib_virt.c b/drivers/infiniband/hw/mlx5/ib_virt.c
new file mode 100644
index 000000000000..c1b9de800fe5
--- /dev/null
+++ b/drivers/infiniband/hw/mlx5/ib_virt.c
@@ -0,0 +1,194 @@
1/*
2 * Copyright (c) 2016, Mellanox Technologies. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/module.h>
34#include <linux/mlx5/vport.h>
35#include "mlx5_ib.h"
36
37static inline u32 mlx_to_net_policy(enum port_state_policy mlx_policy)
38{
39 switch (mlx_policy) {
40 case MLX5_POLICY_DOWN:
41 return IFLA_VF_LINK_STATE_DISABLE;
42 case MLX5_POLICY_UP:
43 return IFLA_VF_LINK_STATE_ENABLE;
44 case MLX5_POLICY_FOLLOW:
45 return IFLA_VF_LINK_STATE_AUTO;
46 default:
47 return __IFLA_VF_LINK_STATE_MAX;
48 }
49}
50
51int mlx5_ib_get_vf_config(struct ib_device *device, int vf, u8 port,
52 struct ifla_vf_info *info)
53{
54 struct mlx5_ib_dev *dev = to_mdev(device);
55 struct mlx5_core_dev *mdev = dev->mdev;
56 struct mlx5_hca_vport_context *rep;
57 int err;
58
59 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
60 if (!rep)
61 return -ENOMEM;
62
63 err = mlx5_query_hca_vport_context(mdev, 1, 1, vf + 1, rep);
64 if (err) {
65 mlx5_ib_warn(dev, "failed to query port policy for vf %d (%d)\n",
66 vf, err);
67 goto free;
68 }
69 memset(info, 0, sizeof(*info));
70 info->linkstate = mlx_to_net_policy(rep->policy);
71 if (info->linkstate == __IFLA_VF_LINK_STATE_MAX)
72 err = -EINVAL;
73
74free:
75 kfree(rep);
76 return err;
77}
78
79static inline enum port_state_policy net_to_mlx_policy(int policy)
80{
81 switch (policy) {
82 case IFLA_VF_LINK_STATE_DISABLE:
83 return MLX5_POLICY_DOWN;
84 case IFLA_VF_LINK_STATE_ENABLE:
85 return MLX5_POLICY_UP;
86 case IFLA_VF_LINK_STATE_AUTO:
87 return MLX5_POLICY_FOLLOW;
88 default:
89 return MLX5_POLICY_INVALID;
90 }
91}
92
93int mlx5_ib_set_vf_link_state(struct ib_device *device, int vf,
94 u8 port, int state)
95{
96 struct mlx5_ib_dev *dev = to_mdev(device);
97 struct mlx5_core_dev *mdev = dev->mdev;
98 struct mlx5_hca_vport_context *in;
99 int err;
100
101 in = kzalloc(sizeof(*in), GFP_KERNEL);
102 if (!in)
103 return -ENOMEM;
104
105 in->policy = net_to_mlx_policy(state);
106 if (in->policy == MLX5_POLICY_INVALID) {
107 err = -EINVAL;
108 goto out;
109 }
110 in->field_select = MLX5_HCA_VPORT_SEL_STATE_POLICY;
111 err = mlx5_core_modify_hca_vport_context(mdev, 1, 1, vf + 1, in);
112
113out:
114 kfree(in);
115 return err;
116}
117
118int mlx5_ib_get_vf_stats(struct ib_device *device, int vf,
119 u8 port, struct ifla_vf_stats *stats)
120{
121 int out_sz = MLX5_ST_SZ_BYTES(query_vport_counter_out);
122 struct mlx5_core_dev *mdev;
123 struct mlx5_ib_dev *dev;
124 void *out;
125 int err;
126
127 dev = to_mdev(device);
128 mdev = dev->mdev;
129
130 out = kzalloc(out_sz, GFP_KERNEL);
131 if (!out)
132 return -ENOMEM;
133
134 err = mlx5_core_query_vport_counter(mdev, true, vf, port, out, out_sz);
135 if (err)
136 goto ex;
137
138 stats->rx_packets = MLX5_GET64_PR(query_vport_counter_out, out, received_ib_unicast.packets);
139 stats->tx_packets = MLX5_GET64_PR(query_vport_counter_out, out, transmitted_ib_unicast.packets);
140 stats->rx_bytes = MLX5_GET64_PR(query_vport_counter_out, out, received_ib_unicast.octets);
141 stats->tx_bytes = MLX5_GET64_PR(query_vport_counter_out, out, transmitted_ib_unicast.octets);
142 stats->multicast = MLX5_GET64_PR(query_vport_counter_out, out, received_ib_multicast.packets);
143
144ex:
145 kfree(out);
146 return err;
147}
148
149static int set_vf_node_guid(struct ib_device *device, int vf, u8 port, u64 guid)
150{
151 struct mlx5_ib_dev *dev = to_mdev(device);
152 struct mlx5_core_dev *mdev = dev->mdev;
153 struct mlx5_hca_vport_context *in;
154 int err;
155
156 in = kzalloc(sizeof(*in), GFP_KERNEL);
157 if (!in)
158 return -ENOMEM;
159
160 in->field_select = MLX5_HCA_VPORT_SEL_NODE_GUID;
161 in->node_guid = guid;
162 err = mlx5_core_modify_hca_vport_context(mdev, 1, 1, vf + 1, in);
163 kfree(in);
164 return err;
165}
166
167static int set_vf_port_guid(struct ib_device *device, int vf, u8 port, u64 guid)
168{
169 struct mlx5_ib_dev *dev = to_mdev(device);
170 struct mlx5_core_dev *mdev = dev->mdev;
171 struct mlx5_hca_vport_context *in;
172 int err;
173
174 in = kzalloc(sizeof(*in), GFP_KERNEL);
175 if (!in)
176 return -ENOMEM;
177
178 in->field_select = MLX5_HCA_VPORT_SEL_PORT_GUID;
179 in->port_guid = guid;
180 err = mlx5_core_modify_hca_vport_context(mdev, 1, 1, vf + 1, in);
181 kfree(in);
182 return err;
183}
184
185int mlx5_ib_set_vf_guid(struct ib_device *device, int vf, u8 port,
186 u64 guid, int type)
187{
188 if (type == IFLA_VF_IB_NODE_GUID)
189 return set_vf_node_guid(device, vf, port, guid);
190 else if (type == IFLA_VF_IB_PORT_GUID)
191 return set_vf_port_guid(device, vf, port, guid);
192
193 return -EINVAL;
194}
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 73cb6337d856..e305990b73f6 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -562,6 +562,9 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
562 if (MLX5_CAP_GEN(mdev, cd)) 562 if (MLX5_CAP_GEN(mdev, cd))
563 props->device_cap_flags |= IB_DEVICE_CROSS_CHANNEL; 563 props->device_cap_flags |= IB_DEVICE_CROSS_CHANNEL;
564 564
565 if (!mlx5_core_is_pf(mdev))
566 props->device_cap_flags |= IB_DEVICE_VIRTUAL_FUNCTION;
567
565 return 0; 568 return 0;
566} 569}
567 570
@@ -699,6 +702,7 @@ static int mlx5_query_hca_port(struct ib_device *ibdev, u8 port,
699 props->qkey_viol_cntr = rep->qkey_violation_counter; 702 props->qkey_viol_cntr = rep->qkey_violation_counter;
700 props->subnet_timeout = rep->subnet_timeout; 703 props->subnet_timeout = rep->subnet_timeout;
701 props->init_type_reply = rep->init_type_reply; 704 props->init_type_reply = rep->init_type_reply;
705 props->grh_required = rep->grh_required;
702 706
703 err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port); 707 err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port);
704 if (err) 708 if (err)
@@ -2349,6 +2353,12 @@ static void *mlx5_ib_add(struct mlx5_core_dev *mdev)
2349 dev->ib_dev.map_mr_sg = mlx5_ib_map_mr_sg; 2353 dev->ib_dev.map_mr_sg = mlx5_ib_map_mr_sg;
2350 dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status; 2354 dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status;
2351 dev->ib_dev.get_port_immutable = mlx5_port_immutable; 2355 dev->ib_dev.get_port_immutable = mlx5_port_immutable;
2356 if (mlx5_core_is_pf(mdev)) {
2357 dev->ib_dev.get_vf_config = mlx5_ib_get_vf_config;
2358 dev->ib_dev.set_vf_link_state = mlx5_ib_set_vf_link_state;
2359 dev->ib_dev.get_vf_stats = mlx5_ib_get_vf_stats;
2360 dev->ib_dev.set_vf_guid = mlx5_ib_set_vf_guid;
2361 }
2352 2362
2353 mlx5_ib_internal_fill_odp_caps(dev); 2363 mlx5_ib_internal_fill_odp_caps(dev);
2354 2364
diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h
index 76b2b42e0535..f16c818ad2e6 100644
--- a/drivers/infiniband/hw/mlx5/mlx5_ib.h
+++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h
@@ -776,6 +776,14 @@ void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp);
776void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp); 776void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp);
777void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start, 777void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start,
778 unsigned long end); 778 unsigned long end);
779int mlx5_ib_get_vf_config(struct ib_device *device, int vf,
780 u8 port, struct ifla_vf_info *info);
781int mlx5_ib_set_vf_link_state(struct ib_device *device, int vf,
782 u8 port, int state);
783int mlx5_ib_get_vf_stats(struct ib_device *device, int vf,
784 u8 port, struct ifla_vf_stats *stats);
785int mlx5_ib_set_vf_guid(struct ib_device *device, int vf, u8 port,
786 u64 guid, int type);
779 787
780#else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */ 788#else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
781static inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev) 789static inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev)