diff options
author | Majd Dibbiny <majd@mellanox.com> | 2017-02-14 00:21:52 -0500 |
---|---|---|
committer | Doug Ledford <dledford@redhat.com> | 2017-02-15 09:51:28 -0500 |
commit | 89052d784bc977c2a0b92393f6bd57140952c206 (patch) | |
tree | e5d873be24145516ba481a639da5f7381f7f1e21 | |
parent | 590396084039b6504097b371cda6474dfcb83648 (diff) |
IB/cma: Add default RoCE TOS to CMA configfs
Add new entry to the RDMA-CM configfs that allows users
to select default TOS for RDMA-CM QPs.
This is useful for users that want to control the TOS for legacy
applications without changing their code.
Application that sets the TOS explicitly using the rdma_set_option
API will continue to work as expected, meaning overriding the configfs
value.
CC: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Majd Dibbiny <majd@mellanox.com>
Reviewed-by: Moni Shoua <monis@mellanox.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r-- | Documentation/ABI/testing/configfs-rdma_cm | 8 | ||||
-rw-r--r-- | drivers/infiniband/core/cma.c | 54 | ||||
-rw-r--r-- | drivers/infiniband/core/cma_configfs.c | 42 | ||||
-rw-r--r-- | drivers/infiniband/core/core_priv.h | 3 |
4 files changed, 102 insertions, 5 deletions
diff --git a/Documentation/ABI/testing/configfs-rdma_cm b/Documentation/ABI/testing/configfs-rdma_cm index 5c389aaf5291..74f9506f42e7 100644 --- a/Documentation/ABI/testing/configfs-rdma_cm +++ b/Documentation/ABI/testing/configfs-rdma_cm | |||
@@ -20,3 +20,11 @@ Description: RDMA-CM based connections from HCA <hca> at port <port-num> | |||
20 | will be initiated with this RoCE type as default. | 20 | will be initiated with this RoCE type as default. |
21 | The possible RoCE types are either "IB/RoCE v1" or "RoCE v2". | 21 | The possible RoCE types are either "IB/RoCE v1" or "RoCE v2". |
22 | This parameter has RW access. | 22 | This parameter has RW access. |
23 | |||
24 | What: /config/rdma_cm/<hca>/ports/<port-num>/default_roce_tos | ||
25 | Date: February 7, 2017 | ||
26 | KernelVersion: 4.11.0 | ||
27 | Description: RDMA-CM QPs from HCA <hca> at port <port-num> | ||
28 | will be created with this TOS as default. | ||
29 | This can be overridden by using the rdma_set_option API. | ||
30 | The possible RoCE TOS values are 0-255. | ||
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index 9c93e2fa969b..f98ec19a851a 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c | |||
@@ -198,6 +198,7 @@ struct cma_device { | |||
198 | atomic_t refcount; | 198 | atomic_t refcount; |
199 | struct list_head id_list; | 199 | struct list_head id_list; |
200 | enum ib_gid_type *default_gid_type; | 200 | enum ib_gid_type *default_gid_type; |
201 | u8 *default_roce_tos; | ||
201 | }; | 202 | }; |
202 | 203 | ||
203 | struct rdma_bind_list { | 204 | struct rdma_bind_list { |
@@ -295,6 +296,25 @@ int cma_set_default_gid_type(struct cma_device *cma_dev, | |||
295 | return 0; | 296 | return 0; |
296 | } | 297 | } |
297 | 298 | ||
299 | int cma_get_default_roce_tos(struct cma_device *cma_dev, unsigned int port) | ||
300 | { | ||
301 | if (!rdma_is_port_valid(cma_dev->device, port)) | ||
302 | return -EINVAL; | ||
303 | |||
304 | return cma_dev->default_roce_tos[port - rdma_start_port(cma_dev->device)]; | ||
305 | } | ||
306 | |||
307 | int cma_set_default_roce_tos(struct cma_device *cma_dev, unsigned int port, | ||
308 | u8 default_roce_tos) | ||
309 | { | ||
310 | if (!rdma_is_port_valid(cma_dev->device, port)) | ||
311 | return -EINVAL; | ||
312 | |||
313 | cma_dev->default_roce_tos[port - rdma_start_port(cma_dev->device)] = | ||
314 | default_roce_tos; | ||
315 | |||
316 | return 0; | ||
317 | } | ||
298 | struct ib_device *cma_get_ib_dev(struct cma_device *cma_dev) | 318 | struct ib_device *cma_get_ib_dev(struct cma_device *cma_dev) |
299 | { | 319 | { |
300 | return cma_dev->device; | 320 | return cma_dev->device; |
@@ -341,6 +361,7 @@ struct rdma_id_private { | |||
341 | u32 options; | 361 | u32 options; |
342 | u8 srq; | 362 | u8 srq; |
343 | u8 tos; | 363 | u8 tos; |
364 | bool tos_set; | ||
344 | u8 reuseaddr; | 365 | u8 reuseaddr; |
345 | u8 afonly; | 366 | u8 afonly; |
346 | enum ib_gid_type gid_type; | 367 | enum ib_gid_type gid_type; |
@@ -780,6 +801,7 @@ struct rdma_cm_id *rdma_create_id(struct net *net, | |||
780 | id_priv->id.event_handler = event_handler; | 801 | id_priv->id.event_handler = event_handler; |
781 | id_priv->id.ps = ps; | 802 | id_priv->id.ps = ps; |
782 | id_priv->id.qp_type = qp_type; | 803 | id_priv->id.qp_type = qp_type; |
804 | id_priv->tos_set = false; | ||
783 | spin_lock_init(&id_priv->lock); | 805 | spin_lock_init(&id_priv->lock); |
784 | mutex_init(&id_priv->qp_mutex); | 806 | mutex_init(&id_priv->qp_mutex); |
785 | init_completion(&id_priv->comp); | 807 | init_completion(&id_priv->comp); |
@@ -2271,6 +2293,7 @@ void rdma_set_service_type(struct rdma_cm_id *id, int tos) | |||
2271 | 2293 | ||
2272 | id_priv = container_of(id, struct rdma_id_private, id); | 2294 | id_priv = container_of(id, struct rdma_id_private, id); |
2273 | id_priv->tos = (u8) tos; | 2295 | id_priv->tos = (u8) tos; |
2296 | id_priv->tos_set = true; | ||
2274 | } | 2297 | } |
2275 | EXPORT_SYMBOL(rdma_set_service_type); | 2298 | EXPORT_SYMBOL(rdma_set_service_type); |
2276 | 2299 | ||
@@ -2507,6 +2530,9 @@ static int cma_resolve_iboe_route(struct rdma_id_private *id_priv) | |||
2507 | struct cma_work *work; | 2530 | struct cma_work *work; |
2508 | int ret; | 2531 | int ret; |
2509 | struct net_device *ndev = NULL; | 2532 | struct net_device *ndev = NULL; |
2533 | u8 default_roce_tos = id_priv->cma_dev->default_roce_tos[id_priv->id.port_num - | ||
2534 | rdma_start_port(id_priv->cma_dev->device)]; | ||
2535 | u8 tos = id_priv->tos_set ? id_priv->tos : default_roce_tos; | ||
2510 | 2536 | ||
2511 | 2537 | ||
2512 | work = kzalloc(sizeof *work, GFP_KERNEL); | 2538 | work = kzalloc(sizeof *work, GFP_KERNEL); |
@@ -2580,7 +2606,8 @@ static int cma_resolve_iboe_route(struct rdma_id_private *id_priv) | |||
2580 | route->path_rec->reversible = 1; | 2606 | route->path_rec->reversible = 1; |
2581 | route->path_rec->pkey = cpu_to_be16(0xffff); | 2607 | route->path_rec->pkey = cpu_to_be16(0xffff); |
2582 | route->path_rec->mtu_selector = IB_SA_EQ; | 2608 | route->path_rec->mtu_selector = IB_SA_EQ; |
2583 | route->path_rec->sl = iboe_tos_to_sl(ndev, id_priv->tos); | 2609 | route->path_rec->sl = iboe_tos_to_sl(ndev, tos); |
2610 | route->path_rec->traffic_class = tos; | ||
2584 | route->path_rec->mtu = iboe_get_mtu(ndev->mtu); | 2611 | route->path_rec->mtu = iboe_get_mtu(ndev->mtu); |
2585 | route->path_rec->rate_selector = IB_SA_EQ; | 2612 | route->path_rec->rate_selector = IB_SA_EQ; |
2586 | route->path_rec->rate = iboe_get_rate(ndev); | 2613 | route->path_rec->rate = iboe_get_rate(ndev); |
@@ -4304,15 +4331,21 @@ static void cma_add_one(struct ib_device *device) | |||
4304 | cma_dev->default_gid_type = kcalloc(device->phys_port_cnt, | 4331 | cma_dev->default_gid_type = kcalloc(device->phys_port_cnt, |
4305 | sizeof(*cma_dev->default_gid_type), | 4332 | sizeof(*cma_dev->default_gid_type), |
4306 | GFP_KERNEL); | 4333 | GFP_KERNEL); |
4307 | if (!cma_dev->default_gid_type) { | 4334 | if (!cma_dev->default_gid_type) |
4308 | kfree(cma_dev); | 4335 | goto free_cma_dev; |
4309 | return; | 4336 | |
4310 | } | 4337 | cma_dev->default_roce_tos = kcalloc(device->phys_port_cnt, |
4338 | sizeof(*cma_dev->default_roce_tos), | ||
4339 | GFP_KERNEL); | ||
4340 | if (!cma_dev->default_roce_tos) | ||
4341 | goto free_gid_type; | ||
4342 | |||
4311 | for (i = rdma_start_port(device); i <= rdma_end_port(device); i++) { | 4343 | for (i = rdma_start_port(device); i <= rdma_end_port(device); i++) { |
4312 | supported_gids = roce_gid_type_mask_support(device, i); | 4344 | supported_gids = roce_gid_type_mask_support(device, i); |
4313 | WARN_ON(!supported_gids); | 4345 | WARN_ON(!supported_gids); |
4314 | cma_dev->default_gid_type[i - rdma_start_port(device)] = | 4346 | cma_dev->default_gid_type[i - rdma_start_port(device)] = |
4315 | find_first_bit(&supported_gids, BITS_PER_LONG); | 4347 | find_first_bit(&supported_gids, BITS_PER_LONG); |
4348 | cma_dev->default_roce_tos[i - rdma_start_port(device)] = 0; | ||
4316 | } | 4349 | } |
4317 | 4350 | ||
4318 | init_completion(&cma_dev->comp); | 4351 | init_completion(&cma_dev->comp); |
@@ -4325,6 +4358,16 @@ static void cma_add_one(struct ib_device *device) | |||
4325 | list_for_each_entry(id_priv, &listen_any_list, list) | 4358 | list_for_each_entry(id_priv, &listen_any_list, list) |
4326 | cma_listen_on_dev(id_priv, cma_dev); | 4359 | cma_listen_on_dev(id_priv, cma_dev); |
4327 | mutex_unlock(&lock); | 4360 | mutex_unlock(&lock); |
4361 | |||
4362 | return; | ||
4363 | |||
4364 | free_gid_type: | ||
4365 | kfree(cma_dev->default_gid_type); | ||
4366 | |||
4367 | free_cma_dev: | ||
4368 | kfree(cma_dev); | ||
4369 | |||
4370 | return; | ||
4328 | } | 4371 | } |
4329 | 4372 | ||
4330 | static int cma_remove_id_dev(struct rdma_id_private *id_priv) | 4373 | static int cma_remove_id_dev(struct rdma_id_private *id_priv) |
@@ -4393,6 +4436,7 @@ static void cma_remove_one(struct ib_device *device, void *client_data) | |||
4393 | mutex_unlock(&lock); | 4436 | mutex_unlock(&lock); |
4394 | 4437 | ||
4395 | cma_process_remove(cma_dev); | 4438 | cma_process_remove(cma_dev); |
4439 | kfree(cma_dev->default_roce_tos); | ||
4396 | kfree(cma_dev->default_gid_type); | 4440 | kfree(cma_dev->default_gid_type); |
4397 | kfree(cma_dev); | 4441 | kfree(cma_dev); |
4398 | } | 4442 | } |
diff --git a/drivers/infiniband/core/cma_configfs.c b/drivers/infiniband/core/cma_configfs.c index 41573df1d9fc..54076a3e8007 100644 --- a/drivers/infiniband/core/cma_configfs.c +++ b/drivers/infiniband/core/cma_configfs.c | |||
@@ -139,8 +139,50 @@ static ssize_t default_roce_mode_store(struct config_item *item, | |||
139 | 139 | ||
140 | CONFIGFS_ATTR(, default_roce_mode); | 140 | CONFIGFS_ATTR(, default_roce_mode); |
141 | 141 | ||
142 | static ssize_t default_roce_tos_show(struct config_item *item, char *buf) | ||
143 | { | ||
144 | struct cma_device *cma_dev; | ||
145 | struct cma_dev_port_group *group; | ||
146 | ssize_t ret; | ||
147 | u8 tos; | ||
148 | |||
149 | ret = cma_configfs_params_get(item, &cma_dev, &group); | ||
150 | if (ret) | ||
151 | return ret; | ||
152 | |||
153 | tos = cma_get_default_roce_tos(cma_dev, group->port_num); | ||
154 | cma_configfs_params_put(cma_dev); | ||
155 | |||
156 | return sprintf(buf, "%u\n", tos); | ||
157 | } | ||
158 | |||
159 | static ssize_t default_roce_tos_store(struct config_item *item, | ||
160 | const char *buf, size_t count) | ||
161 | { | ||
162 | struct cma_device *cma_dev; | ||
163 | struct cma_dev_port_group *group; | ||
164 | ssize_t ret; | ||
165 | u8 tos; | ||
166 | |||
167 | ret = kstrtou8(buf, 0, &tos); | ||
168 | if (ret) | ||
169 | return ret; | ||
170 | |||
171 | ret = cma_configfs_params_get(item, &cma_dev, &group); | ||
172 | if (ret) | ||
173 | return ret; | ||
174 | |||
175 | ret = cma_set_default_roce_tos(cma_dev, group->port_num, tos); | ||
176 | cma_configfs_params_put(cma_dev); | ||
177 | |||
178 | return ret ? ret : strnlen(buf, count); | ||
179 | } | ||
180 | |||
181 | CONFIGFS_ATTR(, default_roce_tos); | ||
182 | |||
142 | static struct configfs_attribute *cma_configfs_attributes[] = { | 183 | static struct configfs_attribute *cma_configfs_attributes[] = { |
143 | &attr_default_roce_mode, | 184 | &attr_default_roce_mode, |
185 | &attr_default_roce_tos, | ||
144 | NULL, | 186 | NULL, |
145 | }; | 187 | }; |
146 | 188 | ||
diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h index d29372624f3a..912ab4cd6eae 100644 --- a/drivers/infiniband/core/core_priv.h +++ b/drivers/infiniband/core/core_priv.h | |||
@@ -62,6 +62,9 @@ int cma_get_default_gid_type(struct cma_device *cma_dev, | |||
62 | int cma_set_default_gid_type(struct cma_device *cma_dev, | 62 | int cma_set_default_gid_type(struct cma_device *cma_dev, |
63 | unsigned int port, | 63 | unsigned int port, |
64 | enum ib_gid_type default_gid_type); | 64 | enum ib_gid_type default_gid_type); |
65 | int cma_get_default_roce_tos(struct cma_device *cma_dev, unsigned int port); | ||
66 | int cma_set_default_roce_tos(struct cma_device *a_dev, unsigned int port, | ||
67 | u8 default_roce_tos); | ||
65 | struct ib_device *cma_get_ib_dev(struct cma_device *cma_dev); | 68 | struct ib_device *cma_get_ib_dev(struct cma_device *cma_dev); |
66 | 69 | ||
67 | int ib_device_register_sysfs(struct ib_device *device, | 70 | int ib_device_register_sysfs(struct ib_device *device, |