| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved. |
|---|
| 3 | 4 | * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved. |
|---|
| 4 | | - * |
|---|
| 5 | | - * This software is available to you under a choice of one of two |
|---|
| 6 | | - * licenses. You may choose to be licensed under the terms of the GNU |
|---|
| 7 | | - * General Public License (GPL) Version 2, available from the file |
|---|
| 8 | | - * COPYING in the main directory of this source tree, or the |
|---|
| 9 | | - * OpenIB.org BSD license below: |
|---|
| 10 | | - * |
|---|
| 11 | | - * Redistribution and use in source and binary forms, with or |
|---|
| 12 | | - * without modification, are permitted provided that the following |
|---|
| 13 | | - * conditions are met: |
|---|
| 14 | | - * |
|---|
| 15 | | - * - Redistributions of source code must retain the above |
|---|
| 16 | | - * copyright notice, this list of conditions and the following |
|---|
| 17 | | - * disclaimer. |
|---|
| 18 | | - * |
|---|
| 19 | | - * - Redistributions in binary form must reproduce the above |
|---|
| 20 | | - * copyright notice, this list of conditions and the following |
|---|
| 21 | | - * disclaimer in the documentation and/or other materials |
|---|
| 22 | | - * provided with the distribution. |
|---|
| 23 | | - * |
|---|
| 24 | | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|---|
| 25 | | - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|---|
| 26 | | - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|---|
| 27 | | - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
|---|
| 28 | | - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
|---|
| 29 | | - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|---|
| 30 | | - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|---|
| 31 | | - * SOFTWARE. |
|---|
| 32 | 5 | */ |
|---|
| 33 | 6 | |
|---|
| 34 | 7 | #ifndef RXE_POOL_H |
|---|
| .. | .. |
|---|
| 41 | 14 | RXE_POOL_ATOMIC = BIT(0), |
|---|
| 42 | 15 | RXE_POOL_INDEX = BIT(1), |
|---|
| 43 | 16 | RXE_POOL_KEY = BIT(2), |
|---|
| 17 | + RXE_POOL_NO_ALLOC = BIT(4), |
|---|
| 44 | 18 | }; |
|---|
| 45 | 19 | |
|---|
| 46 | 20 | enum rxe_elem_type { |
|---|
| .. | .. |
|---|
| 68 | 42 | u32 min_index; |
|---|
| 69 | 43 | size_t key_offset; |
|---|
| 70 | 44 | size_t key_size; |
|---|
| 71 | | - struct kmem_cache *cache; |
|---|
| 72 | 45 | }; |
|---|
| 73 | 46 | |
|---|
| 74 | 47 | extern struct rxe_type_info rxe_type_info[]; |
|---|
| 75 | 48 | |
|---|
| 76 | 49 | enum rxe_pool_state { |
|---|
| 77 | | - rxe_pool_invalid, |
|---|
| 78 | | - rxe_pool_valid, |
|---|
| 50 | + RXE_POOL_STATE_INVALID, |
|---|
| 51 | + RXE_POOL_STATE_VALID, |
|---|
| 79 | 52 | }; |
|---|
| 80 | 53 | |
|---|
| 81 | 54 | struct rxe_pool_entry { |
|---|
| .. | .. |
|---|
| 90 | 63 | |
|---|
| 91 | 64 | struct rxe_pool { |
|---|
| 92 | 65 | struct rxe_dev *rxe; |
|---|
| 93 | | - spinlock_t pool_lock; /* pool spinlock */ |
|---|
| 66 | + rwlock_t pool_lock; /* protects pool add/del/search */ |
|---|
| 94 | 67 | size_t elem_size; |
|---|
| 95 | 68 | struct kref ref_cnt; |
|---|
| 96 | 69 | void (*cleanup)(struct rxe_pool_entry *obj); |
|---|
| .. | .. |
|---|
| 112 | 85 | size_t key_size; |
|---|
| 113 | 86 | }; |
|---|
| 114 | 87 | |
|---|
| 115 | | -/* initialize slab caches for managed objects */ |
|---|
| 116 | | -int rxe_cache_init(void); |
|---|
| 117 | | - |
|---|
| 118 | | -/* cleanup slab caches for managed objects */ |
|---|
| 119 | | -void rxe_cache_exit(void); |
|---|
| 120 | | - |
|---|
| 121 | 88 | /* initialize a pool of objects with given limit on |
|---|
| 122 | 89 | * number of elements. gets parameters from rxe_type_info |
|---|
| 123 | 90 | * pool elements will be allocated out of a slab cache |
|---|
| .. | .. |
|---|
| 126 | 93 | enum rxe_elem_type type, u32 max_elem); |
|---|
| 127 | 94 | |
|---|
| 128 | 95 | /* free resources from object pool */ |
|---|
| 129 | | -int rxe_pool_cleanup(struct rxe_pool *pool); |
|---|
| 96 | +void rxe_pool_cleanup(struct rxe_pool *pool); |
|---|
| 130 | 97 | |
|---|
| 131 | 98 | /* allocate an object from pool */ |
|---|
| 132 | 99 | void *rxe_alloc(struct rxe_pool *pool); |
|---|
| 133 | 100 | |
|---|
| 101 | +/* connect already allocated object to pool */ |
|---|
| 102 | +int rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_entry *elem); |
|---|
| 103 | + |
|---|
| 134 | 104 | /* assign an index to an indexed object and insert object into |
|---|
| 135 | 105 | * pool's rb tree |
|---|
| 136 | 106 | */ |
|---|