Print this page
hg changesets 607a5b46a793..b706c96317c3
Fix ncpus for early boot config
Purge the ack to the interrupt before exiting mptsas_intr()
Changes from code review
Changes to enable driver to compile.
Header paths, object lists, etc.
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/scsi/adapters/mpt_sas3/mptsas3_hash.c
+++ new/usr/src/uts/common/io/scsi/adapters/mpt_sas3/mptsas3_hash.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 13 * Copyright 2014 Joyent, Inc. All rights reserved.
14 + * Copyright (c) 2014, Tegile Systems Inc. All rights reserved.
14 15 */
15 16
16 -#include <sys/scsi/adapters/mpt_sas/mptsas_hash.h>
17 +#include <sys/scsi/adapters/mpt_sas3/mptsas3_hash.h>
17 18 #include <sys/sysmacros.h>
18 19 #include <sys/types.h>
19 20 #include <sys/kmem.h>
20 21 #include <sys/list.h>
21 22 #include <sys/ddi.h>
22 23
23 24 #ifdef lint
24 25 extern refhash_link_t *obj_to_link(refhash_t *, void *);
25 26 extern void *link_to_obj(refhash_t *, refhash_link_t *);
26 27 extern void *obj_to_tag(refhash_t *, void *);
27 28 #else
28 29 #define obj_to_link(_h, _o) \
29 30 ((refhash_link_t *)(((char *)(_o)) + (_h)->rh_link_off))
30 31 #define link_to_obj(_h, _l) \
31 32 ((void *)(((char *)(_l)) - (_h)->rh_link_off))
32 33 #define obj_to_tag(_h, _o) \
33 34 ((void *)(((char *)(_o)) + (_h)->rh_tag_off))
34 35 #endif
35 36
36 37 refhash_t *
37 38 refhash_create(uint_t bucket_count, refhash_hash_f hash,
38 39 refhash_cmp_f cmp, refhash_dtor_f dtor, size_t obj_size, size_t link_off,
39 40 size_t tag_off, int km_flags)
40 41 {
41 42 refhash_t *hp;
42 43 uint_t i;
43 44
44 45 hp = kmem_alloc(sizeof (refhash_t), km_flags);
45 46 if (hp == NULL)
46 47 return (NULL);
47 48 hp->rh_buckets = kmem_zalloc(bucket_count * sizeof (list_t), km_flags);
48 49 if (hp->rh_buckets == NULL) {
49 50 kmem_free(hp, sizeof (refhash_t));
50 51 return (NULL);
51 52 }
52 53 hp->rh_bucket_count = bucket_count;
53 54
54 55 for (i = 0; i < bucket_count; i++) {
55 56 list_create(&hp->rh_buckets[i], sizeof (refhash_link_t),
56 57 offsetof(refhash_link_t, rhl_chain_link));
57 58 }
58 59 list_create(&hp->rh_objs, sizeof (refhash_link_t),
59 60 offsetof(refhash_link_t, rhl_global_link));
60 61
61 62 hp->rh_obj_size = obj_size;
62 63 hp->rh_link_off = link_off;
63 64 hp->rh_tag_off = tag_off;
64 65 hp->rh_hash = hash;
65 66 hp->rh_cmp = cmp;
66 67 hp->rh_dtor = dtor;
67 68
68 69 return (hp);
69 70 }
70 71
71 72 void
72 73 refhash_destroy(refhash_t *hp)
73 74 {
74 75 ASSERT(list_is_empty(&hp->rh_objs));
75 76
76 77 kmem_free(hp->rh_buckets, hp->rh_bucket_count * sizeof (list_t));
77 78 kmem_free(hp, sizeof (refhash_t));
78 79 }
79 80
80 81 void
81 82 refhash_insert(refhash_t *hp, void *op)
82 83 {
83 84 uint_t bucket;
84 85 refhash_link_t *lp = obj_to_link(hp, op);
85 86
86 87 bucket = hp->rh_hash(obj_to_tag(hp, op)) % hp->rh_bucket_count;
87 88 list_link_init(&lp->rhl_chain_link);
88 89 list_link_init(&lp->rhl_global_link);
89 90 lp->rhl_flags = 0;
90 91 lp->rhl_refcnt = 0;
91 92 list_insert_tail(&hp->rh_buckets[bucket], lp);
92 93 list_insert_tail(&hp->rh_objs, lp);
93 94 }
94 95
95 96 static void
96 97 refhash_delete(refhash_t *hp, void *op)
97 98 {
98 99 refhash_link_t *lp = obj_to_link(hp, op);
99 100 uint_t bucket;
100 101
101 102 bucket = hp->rh_hash(obj_to_tag(hp, op)) % hp->rh_bucket_count;
102 103 list_remove(&hp->rh_buckets[bucket], lp);
103 104 list_remove(&hp->rh_objs, lp);
104 105 hp->rh_dtor(op);
105 106 }
106 107
107 108 void
108 109 refhash_remove(refhash_t *hp, void *op)
109 110 {
110 111 refhash_link_t *lp = obj_to_link(hp, op);
111 112
112 113 if (lp->rhl_refcnt > 0) {
113 114 lp->rhl_flags |= RHL_F_DEAD;
114 115 } else {
115 116 refhash_delete(hp, op);
116 117 }
117 118 }
118 119
119 120 void *
120 121 refhash_lookup(refhash_t *hp, const void *tp)
121 122 {
122 123 uint_t bucket;
123 124 refhash_link_t *lp;
124 125 void *op;
125 126
126 127 bucket = hp->rh_hash(tp) % hp->rh_bucket_count;
127 128 for (lp = list_head(&hp->rh_buckets[bucket]); lp != NULL;
128 129 lp = list_next(&hp->rh_buckets[bucket], lp)) {
129 130 op = link_to_obj(hp, lp);
130 131 if (hp->rh_cmp(obj_to_tag(hp, op), tp) == 0 &&
131 132 !(lp->rhl_flags & RHL_F_DEAD)) {
132 133 return (op);
133 134 }
134 135 }
135 136
136 137 return (NULL);
137 138 }
138 139
139 140 void *
140 141 refhash_linear_search(refhash_t *hp, refhash_eval_f eval, void *arg)
141 142 {
142 143 void *op;
143 144 refhash_link_t *lp;
144 145
145 146 for (lp = list_head(&hp->rh_objs); lp != NULL;
146 147 lp = list_next(&hp->rh_objs, lp)) {
147 148 op = link_to_obj(hp, lp);
148 149 if (eval(op, arg) == 0)
149 150 return (op);
150 151 }
151 152
152 153 return (NULL);
153 154 }
154 155
155 156 void
156 157 refhash_hold(refhash_t *hp, void *op)
157 158 {
158 159 refhash_link_t *lp = obj_to_link(hp, op);
159 160
160 161 ++lp->rhl_refcnt;
161 162 }
162 163
163 164 void
164 165 refhash_rele(refhash_t *hp, void *op)
165 166 {
166 167 refhash_link_t *lp = obj_to_link(hp, op);
167 168
168 169 ASSERT(lp->rhl_refcnt > 0);
169 170
170 171 if (--lp->rhl_refcnt == 0 && (lp->rhl_flags & RHL_F_DEAD))
171 172 refhash_remove(hp, op);
172 173 }
173 174
174 175 void *
175 176 refhash_first(refhash_t *hp)
176 177 {
177 178 refhash_link_t *lp;
178 179
179 180 lp = list_head(&hp->rh_objs);
180 181 if (lp == NULL)
181 182 return (NULL);
182 183
183 184 ++lp->rhl_refcnt;
184 185
185 186 return (link_to_obj(hp, lp));
186 187 }
187 188
188 189 void *
189 190 refhash_next(refhash_t *hp, void *op)
190 191 {
191 192 refhash_link_t *lp;
192 193
193 194 lp = obj_to_link(hp, op);
194 195 while ((lp = list_next(&hp->rh_objs, lp)) != NULL) {
195 196 if (!(lp->rhl_flags & RHL_F_DEAD))
196 197 break;
197 198 }
198 199
199 200 refhash_rele(hp, op);
200 201 if (lp == NULL)
201 202 return (NULL);
202 203
203 204 ++lp->rhl_refcnt;
204 205
205 206 return (link_to_obj(hp, lp));
206 207 }
207 208
208 209 boolean_t
209 210 refhash_obj_valid(refhash_t *hp, const void *op)
210 211 {
211 212 /* LINTED - E_ARG_INCOMPATIBLE_WITH_ARG_L */
212 213 const refhash_link_t *lp = obj_to_link(hp, op);
213 214
214 215 return ((lp->rhl_flags & RHL_F_DEAD) != 0);
215 216 }
↓ open down ↓ |
189 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX