Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/ib/clients/iser/iser.c
+++ new/usr/src/uts/common/io/ib/clients/iser/iser.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #include <sys/types.h>
27 27 #include <sys/stat.h>
28 28 #include <sys/conf.h>
29 29 #include <sys/ddi.h>
30 30 #include <sys/sunddi.h>
31 31 #include <sys/modctl.h>
32 32 #include <sys/socket.h>
33 33 #include <netinet/in.h>
34 34
35 35 #include <sys/ib/clients/iser/iser.h>
36 36
37 37 /*
38 38 * iser.c
39 39 * DDI and core routines for Solaris iSER implementation.
40 40 */
41 41
42 42 iser_state_t *iser_state = NULL; /* global state */
43 43 ddi_taskq_t *iser_taskq = NULL; /* global taskq */
44 44
45 45 /* set B_TRUE for console logging */
46 46 boolean_t iser_logging = B_FALSE;
47 47
48 48 /* Driver functions */
49 49 static int iser_attach(dev_info_t *, ddi_attach_cmd_t);
50 50 static int iser_detach(dev_info_t *, ddi_detach_cmd_t);
51 51 static int iser_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
52 52 static int iser_open(dev_t *, int, int, cred_t *);
53 53 static int iser_close(dev_t, int, int, cred_t *);
54 54 static int iser_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
55 55 /* static int iser_close(dev_t, int, int, cred_t *); */
56 56
57 57 /* Char/Block operations */
58 58 static struct cb_ops iser_cb_ops = {
59 59 iser_open, /* open */
60 60 iser_close, /* close */
61 61 nodev, /* strategy */
62 62 nodev, /* print */
63 63 nodev, /* dump */
64 64 nodev, /* read */
65 65 nodev, /* write */
66 66 iser_ioctl, /* ioctl */
67 67 nodev, /* devmap */
68 68 nodev, /* mmap */
69 69 nodev, /* segmap */
70 70 nochpoll, /* poll */
71 71 ddi_prop_op, /* prop_op */
72 72 NULL, /* stream */
73 73 D_MP, /* cb_flag */
74 74 CB_REV, /* rev */
75 75 nodev, /* int (*cb_aread)() */
76 76 nodev, /* int (*cb_awrite)() */
77 77 };
78 78
79 79 /* Device operations */
80 80 static struct dev_ops iser_ops = {
81 81 DEVO_REV, /* devo_rev, */
82 82 0, /* refcnt */
83 83 iser_getinfo, /* getinfo */
84 84 nulldev, /* identify */
85 85 nulldev, /* probe */
86 86 iser_attach, /* attach */
87 87 iser_detach, /* detach */
88 88 nodev, /* reset */
89 89 &iser_cb_ops, /* cb_ops */
90 90 NULL, /* bus ops */
91 91 NULL, /* power */
92 92 ddi_quiesce_not_needed /* quiesce */
93 93 };
94 94
95 95 /* Module Driver Info */
↓ open down ↓ |
95 lines elided |
↑ open up ↑ |
96 96 #define ISER_NAME_VERSION "iSCSI Extensions for RDMA"
97 97 static struct modldrv iser_modldrv = {
98 98 &mod_driverops,
99 99 ISER_NAME_VERSION,
100 100 &iser_ops,
101 101 };
102 102
103 103 /* Module Linkage */
104 104 static struct modlinkage iser_modlinkage = {
105 105 MODREV_1,
106 - &iser_modldrv,
107 - NULL
106 + { &iser_modldrv, NULL }
108 107 };
109 108
110 109 /*
111 110 * _init()
112 111 */
113 112 int
114 113 _init(void)
115 114 {
116 115 int status;
117 116
118 117 iser_state = kmem_zalloc(sizeof (iser_state_t), KM_SLEEP);
119 118 status = mod_install(&iser_modlinkage);
120 119 if (status != DDI_SUCCESS) {
121 120 kmem_free(iser_state, sizeof (iser_state_t));
122 121 }
123 122
124 123 return (status);
125 124 }
126 125
127 126 /*
128 127 * _info()
129 128 */
130 129 int
131 130 _info(struct modinfo *modinfop)
132 131 {
133 132 return (mod_info(&iser_modlinkage, modinfop));
134 133 }
135 134
136 135 /*
137 136 * _fini()
138 137 */
139 138 int
140 139 _fini(void)
141 140 {
142 141 int status;
143 142
144 143 status = mod_remove(&iser_modlinkage);
145 144 if (status != DDI_SUCCESS) {
146 145 return (status);
147 146 }
148 147 kmem_free(iser_state, sizeof (iser_state_t));
149 148
150 149 return (DDI_SUCCESS);
151 150 }
152 151
153 152 /*
154 153 * iser_attach()
155 154 */
156 155 static int
157 156 iser_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
158 157 {
159 158 int instance;
160 159 int status;
161 160
162 161 switch (cmd) {
163 162 case DDI_ATTACH:
164 163 ISER_LOG(CE_CONT, "iser_attach: DDI_ATTACH");
165 164 instance = ddi_get_instance(dip);
166 165
167 166 iser_state->is_dip = dip;
168 167 iser_state->is_instance = instance;
169 168
170 169 /* Initialize the open refcnt and it's lock */
171 170 iser_state->is_open_refcnt = 0;
172 171 mutex_init(&iser_state->is_refcnt_lock, NULL, MUTEX_DRIVER,
173 172 NULL);
174 173
175 174 iser_taskq = ddi_taskq_create(dip, "iser_taskq",
176 175 ISER_TASKQ_NTHREADS, TASKQ_DEFAULTPRI, 0);
177 176
178 177 if (iser_taskq == NULL) {
179 178 ISER_LOG(CE_CONT, "%s%d: failed to create taskq",
180 179 "iser", instance);
181 180 mutex_destroy(&iser_state->is_refcnt_lock);
182 181 return (DDI_FAILURE);
183 182 }
184 183
185 184 /* initialize iSER as IB service */
186 185 status = iser_ib_init();
187 186 if (status != DDI_SUCCESS) {
188 187 ddi_taskq_destroy(iser_taskq);
189 188 mutex_destroy(&iser_state->is_refcnt_lock);
190 189 ISER_LOG(CE_CONT, "%s%d: failed to initialize IB",
191 190 "iser", instance);
192 191 return (DDI_FAILURE);
193 192 }
194 193
195 194 status = ddi_create_minor_node(
196 195 dip, ddi_get_name(dip), S_IFCHR, instance,
197 196 DDI_PSEUDO, 0);
198 197 if (status != DDI_SUCCESS) {
199 198 (void) iser_ib_fini();
200 199 ddi_taskq_destroy(iser_taskq);
201 200 mutex_destroy(&iser_state->is_refcnt_lock);
202 201 ISER_LOG(CE_CONT, "%s%d: failed ddi_create_minor_node",
203 202 "iser", instance);
204 203 return (DDI_FAILURE);
205 204 }
206 205
207 206 ddi_report_dev(dip);
208 207
209 208 return (DDI_SUCCESS);
210 209
211 210 case DDI_RESUME:
212 211 ISER_LOG(CE_CONT, "iser_detach: DDI_RESUME unsupported");
213 212 return (DDI_FAILURE);
214 213
215 214 default:
216 215 ISER_LOG(CE_CONT, "%s%d: unknown cmd in attach (0x%x)", "iser",
217 216 instance, cmd);
218 217 return (DDI_FAILURE);
219 218 }
220 219 }
221 220
222 221 /*
223 222 * iser_detach()
224 223 */
225 224 static int
226 225 iser_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
227 226 {
228 227 mutex_enter(&iser_state->is_refcnt_lock);
229 228 if (iser_state->is_open_refcnt > 0) {
230 229 mutex_exit(&iser_state->is_refcnt_lock);
231 230 return (DDI_FAILURE);
232 231 }
233 232 mutex_exit(&iser_state->is_refcnt_lock);
234 233 mutex_destroy(&iser_state->is_refcnt_lock);
235 234
236 235 switch (cmd) {
237 236 case DDI_DETACH:
238 237 ISER_LOG(CE_CONT, "iser_detach: DDI_DETACH");
239 238
240 239 if (iser_ib_fini() != DDI_SUCCESS) {
241 240 ISER_LOG(CE_CONT, "iser_ib_fini failed");
242 241 return (DDI_FAILURE);
243 242 }
244 243
245 244 if (iser_taskq != NULL) {
246 245 ddi_taskq_destroy(iser_taskq);
247 246 iser_taskq = NULL;
248 247 }
249 248 ddi_remove_minor_node(dip, NULL);
250 249
251 250 return (DDI_SUCCESS);
252 251
253 252 case DDI_SUSPEND:
254 253 ISER_LOG(CE_CONT, "iser_detach: DDI_SUSPEND unsupported");
255 254 return (DDI_FAILURE);
256 255
257 256 default:
258 257 ISER_LOG(CE_CONT, "iser: unknown cmd in detach (0x%x)", cmd);
259 258 return (DDI_FAILURE);
260 259 }
261 260 }
262 261
263 262 /*
264 263 * iser_getinfo()
265 264 */
266 265 /* ARGSUSED */
267 266 static int
268 267 iser_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
269 268 {
270 269 switch (cmd) {
271 270 case DDI_INFO_DEVT2DEVINFO:
272 271 *result = (void *)iser_state->is_dip;
273 272 return (DDI_SUCCESS);
274 273
275 274 case DDI_INFO_DEVT2INSTANCE:
276 275 *result = NULL;
277 276 return (DDI_SUCCESS);
278 277
279 278 default:
280 279 return (DDI_FAILURE);
281 280 }
282 281
283 282 }
284 283
285 284 /*
286 285 * iser_open()
287 286 */
288 287 /* ARGSUSED */
289 288 static int
290 289 iser_open(dev_t *devp, int flag, int otyp, cred_t *credp)
291 290 {
292 291 minor_t instance;
293 292 int status;
294 293
295 294 instance = getminor(*devp);
296 295
297 296 /* Register the transport with IDM */
298 297 status = iser_idm_register();
299 298 if (status != DDI_SUCCESS) {
300 299 ISER_LOG(CE_CONT, "%s%d: failed to register with IDM",
301 300 "iser", instance);
302 301 return (ENXIO);
303 302 }
304 303
305 304 /* Increment our open refcnt */
306 305 mutex_enter(&iser_state->is_refcnt_lock);
307 306 iser_state->is_open_refcnt++;
308 307 mutex_exit(&iser_state->is_refcnt_lock);
309 308
310 309 return (DDI_SUCCESS);
311 310 }
312 311
313 312 /*
314 313 * iser_close()
315 314 */
316 315 /* ARGSUSED */
317 316 static int
318 317 iser_close(dev_t devp, int flag, int otyp, cred_t *credp)
319 318 {
320 319 ASSERT(iser_state->is_open_refcnt != 0);
321 320
322 321 mutex_enter(&iser_state->is_refcnt_lock);
323 322 iser_state->is_open_refcnt--;
324 323 mutex_exit(&iser_state->is_refcnt_lock);
325 324
326 325 return (DDI_SUCCESS);
327 326 }
328 327
329 328 iser_status_t
330 329 iser_register_service(idm_svc_t *idm_svc)
331 330 {
332 331
333 332 return (iser_ib_register_service(idm_svc));
334 333 }
335 334
336 335 iser_status_t
337 336 iser_bind_service(idm_svc_t *idm_svc)
338 337 {
339 338
340 339 return (iser_ib_bind_service(idm_svc));
341 340 }
342 341
343 342 void
344 343 iser_unbind_service(idm_svc_t *idm_svc)
345 344 {
346 345
347 346 iser_ib_unbind_service(idm_svc);
348 347 }
349 348
350 349 void
351 350 iser_deregister_service(idm_svc_t *idm_svc)
352 351 {
353 352
354 353 iser_ib_deregister_service(idm_svc);
355 354 }
356 355
357 356 /*
358 357 * iser_path_exists
359 358 * This function takes in a pair of endpoints and determines if an iSER path
360 359 * exists between the two. The actual path information (required for creating
361 360 * a RC channel) is not returned, instead a boolean value indicating if a path
362 361 * exists is returned.
363 362 *
364 363 * To use an implicit source, a value of NULL is allowed for laddr.
365 364 */
366 365 boolean_t
367 366 iser_path_exists(idm_sockaddr_t *laddr, idm_sockaddr_t *raddr)
368 367 {
369 368
370 369 ibt_ip_addr_t remote_ip, local_ip;
371 370 ibt_path_info_t path;
372 371 int status;
373 372
374 373 iser_ib_conv_sockaddr2ibtaddr(raddr, &remote_ip);
375 374 iser_ib_conv_sockaddr2ibtaddr(laddr, &local_ip);
376 375
377 376 status = iser_ib_get_paths(&local_ip, &remote_ip, &path, NULL);
378 377
379 378 return ((status == IBT_SUCCESS) ? B_TRUE : B_FALSE);
380 379 }
381 380
382 381 /*
383 382 * iser_channel_alloc
384 383 * This function allocates a reliable communication channel between the
385 384 * given endpoints.
386 385 */
387 386 iser_chan_t *
388 387 iser_channel_alloc(idm_sockaddr_t *laddr, idm_sockaddr_t *raddr)
389 388 {
390 389 ibt_ip_addr_t remote_ip, local_ip;
391 390
392 391 iser_ib_conv_sockaddr2ibtaddr(raddr, &remote_ip);
393 392 iser_ib_conv_sockaddr2ibtaddr(laddr, &local_ip);
394 393
395 394 return (iser_ib_alloc_channel_pathlookup(&local_ip, &remote_ip));
396 395 }
397 396
398 397 /*
399 398 * iser_channel_open
400 399 * This function opens the already allocated communication channel between the
401 400 * two endpoints.
402 401 */
403 402 iser_status_t
404 403 iser_channel_open(iser_chan_t *chan)
405 404 {
406 405 return (iser_ib_open_rc_channel(chan));
407 406 }
408 407
409 408 /*
410 409 * iser_channel_close
411 410 * This function closes the already opened communication channel between the
412 411 * two endpoints.
413 412 */
414 413 void
415 414 iser_channel_close(iser_chan_t *chan)
416 415 {
417 416 iser_ib_close_rc_channel(chan);
418 417 }
419 418
420 419 /*
421 420 * iser_channel_free
422 421 * This function frees the channel between the given endpoints
423 422 */
424 423 void
425 424 iser_channel_free(iser_chan_t *chan)
426 425 {
427 426 iser_ib_free_rc_channel(chan);
428 427 }
429 428
430 429 /* ARGSUSED */
431 430 static int
432 431 iser_ioctl(dev_t devp, int cmd, intptr_t arg, int mode, cred_t *credp,
433 432 int *rvalp)
434 433 {
435 434 return (DDI_SUCCESS);
436 435 }
↓ open down ↓ |
319 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX