1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41#include <linux/slab.h>
42
43#include "ehca_tools.h"
44#include "ehca_iverbs.h"
45
46static struct kmem_cache *pd_cache;
47
48struct ib_pd *ehca_alloc_pd(struct ib_device *device,
49 struct ib_ucontext *context, struct ib_udata *udata)
50{
51 struct ehca_pd *pd;
52 int i;
53
54 pd = kmem_cache_zalloc(pd_cache, GFP_KERNEL);
55 if (!pd) {
56 ehca_err(device, "device=%p context=%p out of memory",
57 device, context);
58 return ERR_PTR(-ENOMEM);
59 }
60
61 for (i = 0; i < 2; i++) {
62 INIT_LIST_HEAD(&pd->free[i]);
63 INIT_LIST_HEAD(&pd->full[i]);
64 }
65 mutex_init(&pd->lock);
66
67
68
69
70
71 if (!context) {
72
73
74
75
76 struct ehca_shca *shca = container_of(device, struct ehca_shca,
77 ib_device);
78 pd->fw_pd.value = shca->pd->fw_pd.value;
79 } else
80 pd->fw_pd.value = (u64)pd;
81
82 return &pd->ib_pd;
83}
84
85int ehca_dealloc_pd(struct ib_pd *pd)
86{
87 struct ehca_pd *my_pd = container_of(pd, struct ehca_pd, ib_pd);
88 int i, leftovers = 0;
89 struct ipz_small_queue_page *page, *tmp;
90
91 for (i = 0; i < 2; i++) {
92 list_splice(&my_pd->full[i], &my_pd->free[i]);
93 list_for_each_entry_safe(page, tmp, &my_pd->free[i], list) {
94 leftovers = 1;
95 free_page(page->page);
96 kmem_cache_free(small_qp_cache, page);
97 }
98 }
99
100 if (leftovers)
101 ehca_warn(pd->device,
102 "Some small queue pages were not freed");
103
104 kmem_cache_free(pd_cache, my_pd);
105
106 return 0;
107}
108
109int ehca_init_pd_cache(void)
110{
111 pd_cache = kmem_cache_create("ehca_cache_pd",
112 sizeof(struct ehca_pd), 0,
113 SLAB_HWCACHE_ALIGN,
114 NULL);
115 if (!pd_cache)
116 return -ENOMEM;
117 return 0;
118}
119
120void ehca_cleanup_pd_cache(void)
121{
122 if (pd_cache)
123 kmem_cache_destroy(pd_cache);
124}
125