cma.c (cc055dd3a71352759a6c7ecaee612eeaef93ef22) cma.c (5ff8c8fa44c2cb74f3066ec4a531265db69b86c5)
1// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2/*
3 * Copyright (c) 2005 Voltaire Inc. All rights reserved.
4 * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
5 * Copyright (c) 1999-2019, Mellanox Technologies, Inc. All rights reserved.
6 * Copyright (c) 2005-2006 Intel Corporation. All rights reserved.
7 */
8

--- 233 unchanged lines hidden (view full) ---

242
243 xa_erase(xa, snum);
244}
245
246enum {
247 CMA_OPTION_AFONLY,
248};
249
1// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2/*
3 * Copyright (c) 2005 Voltaire Inc. All rights reserved.
4 * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
5 * Copyright (c) 1999-2019, Mellanox Technologies, Inc. All rights reserved.
6 * Copyright (c) 2005-2006 Intel Corporation. All rights reserved.
7 */
8

--- 233 unchanged lines hidden (view full) ---

242
243 xa_erase(xa, snum);
244}
245
246enum {
247 CMA_OPTION_AFONLY,
248};
249
250void cma_ref_dev(struct cma_device *cma_dev)
250void cma_dev_get(struct cma_device *cma_dev)
251{
252 atomic_inc(&cma_dev->refcount);
253}
254
251{
252 atomic_inc(&cma_dev->refcount);
253}
254
255void cma_dev_put(struct cma_device *cma_dev)
256{
257 if (atomic_dec_and_test(&cma_dev->refcount))
258 complete(&cma_dev->comp);
259}
260
255struct cma_device *cma_enum_devices_by_ibdev(cma_device_filter filter,
256 void *cookie)
257{
258 struct cma_device *cma_dev;
259 struct cma_device *found_cma_dev = NULL;
260
261 mutex_lock(&lock);
262
263 list_for_each_entry(cma_dev, &dev_list, list)
264 if (filter(cma_dev->device, cookie)) {
265 found_cma_dev = cma_dev;
266 break;
267 }
268
269 if (found_cma_dev)
261struct cma_device *cma_enum_devices_by_ibdev(cma_device_filter filter,
262 void *cookie)
263{
264 struct cma_device *cma_dev;
265 struct cma_device *found_cma_dev = NULL;
266
267 mutex_lock(&lock);
268
269 list_for_each_entry(cma_dev, &dev_list, list)
270 if (filter(cma_dev->device, cookie)) {
271 found_cma_dev = cma_dev;
272 break;
273 }
274
275 if (found_cma_dev)
270 cma_ref_dev(found_cma_dev);
276 cma_dev_get(found_cma_dev);
271 mutex_unlock(&lock);
272 return found_cma_dev;
273}
274
275int cma_get_default_gid_type(struct cma_device *cma_dev,
276 unsigned int port)
277{
278 if (!rdma_is_port_valid(cma_dev->device, port))

--- 179 unchanged lines hidden (view full) ---

458 rtnl_unlock();
459 }
460 return (in_dev) ? 0 : -ENODEV;
461}
462
463static void _cma_attach_to_dev(struct rdma_id_private *id_priv,
464 struct cma_device *cma_dev)
465{
277 mutex_unlock(&lock);
278 return found_cma_dev;
279}
280
281int cma_get_default_gid_type(struct cma_device *cma_dev,
282 unsigned int port)
283{
284 if (!rdma_is_port_valid(cma_dev->device, port))

--- 179 unchanged lines hidden (view full) ---

464 rtnl_unlock();
465 }
466 return (in_dev) ? 0 : -ENODEV;
467}
468
469static void _cma_attach_to_dev(struct rdma_id_private *id_priv,
470 struct cma_device *cma_dev)
471{
466 cma_ref_dev(cma_dev);
472 cma_dev_get(cma_dev);
467 id_priv->cma_dev = cma_dev;
468 id_priv->id.device = cma_dev->device;
469 id_priv->id.route.addr.dev_addr.transport =
470 rdma_node_get_transport(cma_dev->device->node_type);
471 list_add_tail(&id_priv->list, &cma_dev->id_list);
472 if (id_priv->res.kern_name)
473 rdma_restrack_kadd(&id_priv->res);
474 else

--- 4 unchanged lines hidden (view full) ---

479 struct cma_device *cma_dev)
480{
481 _cma_attach_to_dev(id_priv, cma_dev);
482 id_priv->gid_type =
483 cma_dev->default_gid_type[id_priv->id.port_num -
484 rdma_start_port(cma_dev->device)];
485}
486
473 id_priv->cma_dev = cma_dev;
474 id_priv->id.device = cma_dev->device;
475 id_priv->id.route.addr.dev_addr.transport =
476 rdma_node_get_transport(cma_dev->device->node_type);
477 list_add_tail(&id_priv->list, &cma_dev->id_list);
478 if (id_priv->res.kern_name)
479 rdma_restrack_kadd(&id_priv->res);
480 else

--- 4 unchanged lines hidden (view full) ---

485 struct cma_device *cma_dev)
486{
487 _cma_attach_to_dev(id_priv, cma_dev);
488 id_priv->gid_type =
489 cma_dev->default_gid_type[id_priv->id.port_num -
490 rdma_start_port(cma_dev->device)];
491}
492
487void cma_deref_dev(struct cma_device *cma_dev)
488{
489 if (atomic_dec_and_test(&cma_dev->refcount))
490 complete(&cma_dev->comp);
491}
492
493static inline void release_mc(struct kref *kref)
494{
495 struct cma_multicast *mc = container_of(kref, struct cma_multicast, mcref);
496
497 kfree(mc->multicast.ib);
498 kfree(mc);
499}
500
501static void cma_release_dev(struct rdma_id_private *id_priv)
502{
503 mutex_lock(&lock);
504 list_del(&id_priv->list);
493static inline void release_mc(struct kref *kref)
494{
495 struct cma_multicast *mc = container_of(kref, struct cma_multicast, mcref);
496
497 kfree(mc->multicast.ib);
498 kfree(mc);
499}
500
501static void cma_release_dev(struct rdma_id_private *id_priv)
502{
503 mutex_lock(&lock);
504 list_del(&id_priv->list);
505 cma_deref_dev(id_priv->cma_dev);
505 cma_dev_put(id_priv->cma_dev);
506 id_priv->cma_dev = NULL;
507 mutex_unlock(&lock);
508}
509
510static inline struct sockaddr *cma_src_addr(struct rdma_id_private *id_priv)
511{
512 return (struct sockaddr *) &id_priv->id.route.addr.src_addr;
513}

--- 4209 unchanged lines hidden (view full) ---

4723 cma_deref_id(id_priv);
4724 if (ret)
4725 rdma_destroy_id(&id_priv->id);
4726
4727 mutex_lock(&lock);
4728 }
4729 mutex_unlock(&lock);
4730
506 id_priv->cma_dev = NULL;
507 mutex_unlock(&lock);
508}
509
510static inline struct sockaddr *cma_src_addr(struct rdma_id_private *id_priv)
511{
512 return (struct sockaddr *) &id_priv->id.route.addr.src_addr;
513}

--- 4209 unchanged lines hidden (view full) ---

4723 cma_deref_id(id_priv);
4724 if (ret)
4725 rdma_destroy_id(&id_priv->id);
4726
4727 mutex_lock(&lock);
4728 }
4729 mutex_unlock(&lock);
4730
4731 cma_deref_dev(cma_dev);
4731 cma_dev_put(cma_dev);
4732 wait_for_completion(&cma_dev->comp);
4733}
4734
4735static void cma_remove_one(struct ib_device *device, void *client_data)
4736{
4737 struct cma_device *cma_dev = client_data;
4738
4739 trace_cm_remove_one(device);

--- 91 unchanged lines hidden ---
4732 wait_for_completion(&cma_dev->comp);
4733}
4734
4735static void cma_remove_one(struct ib_device *device, void *client_data)
4736{
4737 struct cma_device *cma_dev = client_data;
4738
4739 trace_cm_remove_one(device);

--- 91 unchanged lines hidden ---