xref: /illumos-gate/usr/src/lib/udapl/libdat/common/dat_strerror.c (revision 3ce5372277f4657ad0e52d36c979527c4ca22de2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
23  */
24 
25 /*
26  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 /*
31  *
32  * MODULE: dat_strerror.c
33  *
34  * PURPOSE: Convert DAT_RETURN values to humman readable string
35  *
36  * $Id: dat_strerror.c,v 1.2 2003/08/06 14:40:29 jlentini Exp $
37  */
38 
39 #include <dat/udat.h>
40 
41 
42 /*
43  *
44  * Internal Function Declarations
45  *
46  */
47 
48 DAT_RETURN
49 dat_strerror_major(
50     IN  DAT_RETURN 		value,
51     OUT const char 		**message);
52 
53 DAT_RETURN
54 dat_strerror_minor(
55     IN  DAT_RETURN 		value,
56     OUT const char 		**message);
57 
58 
59 /*
60  *
61  * Internal Function Definitions
62  *
63  */
64 
65 DAT_RETURN
66 dat_strerror_major(
67     IN  DAT_RETURN 		value,
68     OUT const char 		**message)
69 {
70 	switch (DAT_GET_TYPE(value)) {
71 	case DAT_SUCCESS:
72 	{
73 		*message = "DAT_SUCCESS";
74 		return (DAT_SUCCESS);
75 	}
76 	case DAT_ABORT:
77 	{
78 		*message = "DAT_ABORT";
79 		return (DAT_SUCCESS);
80 	}
81 	case DAT_CONN_QUAL_IN_USE:
82 	{
83 		*message = "DAT_CONN_QUAL_IN_USE";
84 		return (DAT_SUCCESS);
85 	}
86 	case DAT_INSUFFICIENT_RESOURCES:
87 	{
88 		*message = "DAT_INSUFFICIENT_RESOURCES";
89 		return (DAT_SUCCESS);
90 	}
91 	case DAT_INTERNAL_ERROR:
92 	{
93 		*message = "DAT_INTERNAL_ERROR";
94 		return (DAT_SUCCESS);
95 	}
96 	case DAT_INVALID_HANDLE:
97 	{
98 		*message = "DAT_INVALID_HANDLE";
99 		return (DAT_SUCCESS);
100 	}
101 	case DAT_INVALID_PARAMETER:
102 	{
103 		*message = "DAT_INVALID_PARAMETER";
104 		return (DAT_SUCCESS);
105 	}
106 	case DAT_INVALID_STATE:
107 	{
108 		*message = "DAT_INVALID_STATE";
109 		return (DAT_SUCCESS);
110 	}
111 	case DAT_LENGTH_ERROR:
112 	{
113 		*message = "DAT_LENGTH_ERROR";
114 		return (DAT_SUCCESS);
115 	}
116 	case DAT_MODEL_NOT_SUPPORTED:
117 	{
118 		*message = "DAT_MODEL_NOT_SUPPORTED";
119 		return (DAT_SUCCESS);
120 	}
121 	case DAT_NAME_NOT_FOUND:
122 	{
123 		*message = "DAT_NAME_NOT_FOUND";
124 		return (DAT_SUCCESS);
125 	}
126 	case DAT_PRIVILEGES_VIOLATION:
127 	{
128 		*message = "DAT_PRIVILEGES_VIOLATION";
129 		return (DAT_SUCCESS);
130 	}
131 	case DAT_PROTECTION_VIOLATION:
132 	{
133 		*message = "DAT_PROTECTION_VIOLATION";
134 		return (DAT_SUCCESS);
135 	}
136 	case DAT_QUEUE_EMPTY:
137 	{
138 		*message = "DAT_QUEUE_EMPTY";
139 		return (DAT_SUCCESS);
140 	}
141 	case DAT_QUEUE_FULL:
142 	{
143 		*message = "DAT_QUEUE_FULL";
144 		return (DAT_SUCCESS);
145 	}
146 	case DAT_TIMEOUT_EXPIRED:
147 	{
148 		*message = "DAT_TIMEOUT_EXPIRED";
149 		return (DAT_SUCCESS);
150 	}
151 	case DAT_PROVIDER_ALREADY_REGISTERED:
152 	{
153 		*message = "DAT_PROVIDER_ALREADY_REGISTERED";
154 		return (DAT_SUCCESS);
155 	}
156 	case DAT_PROVIDER_IN_USE:
157 	{
158 		*message = "DAT_PROVIDER_IN_USE";
159 		return (DAT_SUCCESS);
160 	}
161 	case DAT_INVALID_ADDRESS:
162 	{
163 		*message = "DAT_INVALID_ADDRESS";
164 		return (DAT_SUCCESS);
165 	}
166 	case DAT_INTERRUPTED_CALL:
167 	{
168 		*message = "DAT_INTERRUPTED_CALL";
169 		return (DAT_SUCCESS);
170 	}
171 	case DAT_NOT_IMPLEMENTED:
172 	{
173 		*message = "DAT_NOT_IMPLEMENTED";
174 		return (DAT_SUCCESS);
175 	}
176 	default:
177 	{
178 		return (DAT_INVALID_PARAMETER);
179 	}
180 	}
181 }
182 
183 
184 DAT_RETURN
185 dat_strerror_minor(
186     IN  DAT_RETURN 		value,
187     OUT const char 		**message)
188 {
189 	switch (DAT_GET_SUBTYPE(value)) {
190 	case DAT_NO_SUBTYPE:
191 	{
192 		*message = "";
193 		return (DAT_SUCCESS);
194 	}
195 	case DAT_SUB_INTERRUPTED:
196 	{
197 		*message = "DAT_SUB_INTERRUPTED";
198 		return (DAT_SUCCESS);
199 	}
200 	case DAT_RESOURCE_MEMORY:
201 	{
202 		*message = "DAT_RESOURCE_MEMORY";
203 		return (DAT_SUCCESS);
204 	}
205 	case DAT_RESOURCE_DEVICE:
206 	{
207 		*message = "DAT_RESOURCE_DEVICE";
208 		return (DAT_SUCCESS);
209 	}
210 	case DAT_RESOURCE_TEP:
211 	{
212 		*message = "DAT_RESOURCE_TEP";
213 		return (DAT_SUCCESS);
214 	}
215 	case DAT_RESOURCE_TEVD:
216 	{
217 		*message = "DAT_RESOURCE_TEVD";
218 		return (DAT_SUCCESS);
219 	}
220 	case DAT_RESOURCE_PROTECTION_DOMAIN:
221 	{
222 		*message = "DAT_RESOURCE_PROTECTION_DOMAIN";
223 		return (DAT_SUCCESS);
224 	}
225 	case DAT_RESOURCE_MEMORY_REGION:
226 	{
227 		*message = "DAT_RESOURCE_MEMORY_REGION";
228 		return (DAT_SUCCESS);
229 	}
230 	case DAT_RESOURCE_ERROR_HANDLER:
231 	{
232 		*message = "DAT_RESOURCE_ERROR_HANDLER";
233 		return (DAT_SUCCESS);
234 	}
235 	case DAT_RESOURCE_CREDITS:
236 	{
237 		*message = "DAT_RESOURCE_CREDITS";
238 		return (DAT_SUCCESS);
239 	}
240 	case DAT_INVALID_HANDLE_IA:
241 	{
242 		*message = "DAT_INVALID_HANDLE_IA";
243 		return (DAT_SUCCESS);
244 	}
245 	case DAT_INVALID_HANDLE_EP:
246 	{
247 		*message = "DAT_INVALID_HANDLE_EP";
248 		return (DAT_SUCCESS);
249 	}
250 	case DAT_INVALID_HANDLE_LMR:
251 	{
252 		*message = "DAT_INVALID_HANDLE_LMR";
253 		return (DAT_SUCCESS);
254 	}
255 	case  DAT_INVALID_HANDLE_RMR:
256 	{
257 		*message = "DAT_INVALID_HANDLE_RMR";
258 		return (DAT_SUCCESS);
259 	}
260 	case DAT_INVALID_HANDLE_PZ:
261 	{
262 		*message = "DAT_INVALID_HANDLE_PZ";
263 		return (DAT_SUCCESS);
264 	}
265 	case DAT_INVALID_HANDLE_PSP:
266 	{
267 		*message = "DAT_INVALID_HANDLE_PSP";
268 		return (DAT_SUCCESS);
269 	}
270 	case DAT_INVALID_HANDLE_RSP:
271 	{
272 		*message = "DAT_INVALID_HANDLE_RSP";
273 		return (DAT_SUCCESS);
274 	}
275 	case DAT_INVALID_HANDLE_CR:
276 	{
277 		*message = "DAT_INVALID_HANDLE_CR";
278 		return (DAT_SUCCESS);
279 	}
280 	case DAT_INVALID_HANDLE_CNO:
281 	{
282 		*message = "DAT_INVALID_HANDLE_CNO";
283 		return (DAT_SUCCESS);
284 	}
285 	case DAT_INVALID_HANDLE_EVD_CR:
286 	{
287 		*message = "DAT_INVALID_HANDLE_EVD_CR";
288 		return (DAT_SUCCESS);
289 	}
290 	case DAT_INVALID_HANDLE_EVD_REQUEST:
291 	{
292 		*message = "DAT_INVALID_HANDLE_EVD_REQUEST";
293 		return (DAT_SUCCESS);
294 	}
295 	case DAT_INVALID_HANDLE_EVD_RECV:
296 	{
297 		*message = "DAT_INVALID_HANDLE_EVD_RECV";
298 		return (DAT_SUCCESS);
299 	}
300 	case DAT_INVALID_HANDLE_EVD_CONN:
301 	{
302 		*message = "DAT_INVALID_HANDLE_EVD_CONN";
303 		return (DAT_SUCCESS);
304 	}
305 	case DAT_INVALID_HANDLE_EVD_ASYNC:
306 	{
307 		*message = "DAT_INVALID_HANDLE_EVD_ASYNC";
308 		return (DAT_SUCCESS);
309 	}
310 	case DAT_INVALID_ARG1:
311 	{
312 		*message = "DAT_INVALID_ARG1";
313 		return (DAT_SUCCESS);
314 	}
315 	case DAT_INVALID_ARG2:
316 	{
317 		*message = "DAT_INVALID_ARG2";
318 		return (DAT_SUCCESS);
319 	}
320 	case DAT_INVALID_ARG3:
321 	{
322 		*message = "DAT_INVALID_ARG3";
323 		return (DAT_SUCCESS);
324 	}
325 	case DAT_INVALID_ARG4:
326 	{
327 		*message = "DAT_INVALID_ARG4";
328 		return (DAT_SUCCESS);
329 	}
330 	case DAT_INVALID_ARG5:
331 	{
332 		*message = "DAT_INVALID_ARG5";
333 		return (DAT_SUCCESS);
334 	}
335 	case DAT_INVALID_ARG6:
336 	{
337 		*message = "DAT_INVALID_ARG6";
338 		return (DAT_SUCCESS);
339 	}
340 	case DAT_INVALID_ARG7:
341 	{
342 		*message = "DAT_INVALID_ARG7";
343 		return (DAT_SUCCESS);
344 	}
345 	case DAT_INVALID_ARG8:
346 	{
347 		*message = "DAT_INVALID_ARG8";
348 		return (DAT_SUCCESS);
349 	}
350 	case DAT_INVALID_ARG9:
351 	{
352 		*message = "DAT_INVALID_ARG9";
353 		return (DAT_SUCCESS);
354 	}
355 	case DAT_INVALID_ARG10:
356 	{
357 		*message = "DAT_INVALID_ARG10";
358 		return (DAT_SUCCESS);
359 	}
360 	case DAT_INVALID_STATE_EP_UNCONNECTED:
361 	{
362 		*message = "DAT_INVALID_STATE_EP_UNCONNECTED";
363 		return (DAT_SUCCESS);
364 	}
365 	case DAT_INVALID_STATE_EP_ACTCONNPENDING:
366 	{
367 		*message = "DAT_INVALID_STATE_EP_ACTCONNPENDING";
368 		return (DAT_SUCCESS);
369 	}
370 	case DAT_INVALID_STATE_EP_PASSCONNPENDING:
371 	{
372 		*message = "DAT_INVALID_STATE_EP_PASSCONNPENDING";
373 		return (DAT_SUCCESS);
374 	}
375 	case DAT_INVALID_STATE_EP_TENTCONNPENDING:
376 	{
377 		*message = "DAT_INVALID_STATE_EP_TENTCONNPENDING";
378 		return (DAT_SUCCESS);
379 	}
380 	case DAT_INVALID_STATE_EP_CONNECTED:
381 	{
382 		*message = "DAT_INVALID_STATE_EP_CONNECTED";
383 		return (DAT_SUCCESS);
384 	}
385 	case DAT_INVALID_STATE_EP_DISCONNECTED:
386 	{
387 		*message = "DAT_INVALID_STATE_EP_DISCONNECTED";
388 		return (DAT_SUCCESS);
389 	}
390 	case DAT_INVALID_STATE_EP_RESERVED:
391 	{
392 		*message = "DAT_INVALID_STATE_EP_RESERVED";
393 		return (DAT_SUCCESS);
394 	}
395 	case DAT_INVALID_STATE_EP_COMPLPENDING:
396 	{
397 		*message = "DAT_INVALID_STATE_EP_COMPLPENDING";
398 		return (DAT_SUCCESS);
399 	}
400 	case DAT_INVALID_STATE_EP_DISCPENDING:
401 	{
402 		*message = "DAT_INVALID_STATE_EP_DISCPENDING";
403 		return (DAT_SUCCESS);
404 	}
405 	case DAT_INVALID_STATE_EP_PROVIDERCONTROL:
406 	{
407 		*message = "DAT_INVALID_STATE_EP_PROVIDERCONTROL";
408 		return (DAT_SUCCESS);
409 	}
410 	case DAT_INVALID_STATE_EP_NOTREADY:
411 	{
412 		*message = "DAT_INVALID_STATE_EP_NOTREADY";
413 		return (DAT_SUCCESS);
414 	}
415 	case DAT_INVALID_STATE_CNO_IN_USE:
416 	{
417 		*message = "DAT_INVALID_STATE_CNO_IN_USE";
418 		return (DAT_SUCCESS);
419 	}
420 	case DAT_INVALID_STATE_CNO_DEAD:
421 	{
422 		*message = "DAT_INVALID_STATE_CNO_DEAD";
423 		return (DAT_SUCCESS);
424 	}
425 	case DAT_INVALID_STATE_EVD_OPEN:
426 	{
427 		*message = "DAT_INVALID_STATE_EVD_OPEN";
428 		return (DAT_SUCCESS);
429 	}
430 	case DAT_INVALID_STATE_EVD_ENABLED:
431 	{
432 		*message = "DAT_INVALID_STATE_EVD_ENABLED";
433 		return (DAT_SUCCESS);
434 	}
435 	case DAT_INVALID_STATE_EVD_DISABLED:
436 	{
437 		*message = "DAT_INVALID_STATE_EVD_DISABLED";
438 		return (DAT_SUCCESS);
439 	}
440 	case DAT_INVALID_STATE_EVD_WAITABLE:
441 	{
442 		*message = "DAT_INVALID_STATE_EVD_WAITABLE";
443 		return (DAT_SUCCESS);
444 	}
445 	case DAT_INVALID_STATE_EVD_UNWAITABLE:
446 	{
447 		*message = "DAT_INVALID_STATE_EVD_UNWAITABLE";
448 		return (DAT_SUCCESS);
449 	}
450 	case DAT_INVALID_STATE_EVD_IN_USE:
451 	{
452 		*message = "DAT_INVALID_STATE_EVD_IN_USE";
453 		return (DAT_SUCCESS);
454 	}
455 	case DAT_INVALID_STATE_EVD_CONFIG_NOTIFY:
456 	{
457 		*message = "DAT_INVALID_STATE_EVD_CONFIG_NOTIFY";
458 		return (DAT_SUCCESS);
459 	}
460 	case DAT_INVALID_STATE_EVD_CONFIG_SOLICITED:
461 	{
462 		*message = "DAT_INVALID_STATE_EVD_CONFIG_SOLICITED";
463 		return (DAT_SUCCESS);
464 	}
465 	case DAT_INVALID_STATE_EVD_CONFIG_THRESHOLD:
466 	{
467 		*message = "DAT_INVALID_STATE_EVD_CONFIG_THRESHOLD";
468 		return (DAT_SUCCESS);
469 	}
470 	case DAT_INVALID_STATE_EVD_WAITER:
471 	{
472 		*message = "DAT_INVALID_STATE_EVD_WAITER";
473 		return (DAT_SUCCESS);
474 	}
475 	case DAT_INVALID_STATE_EVD_ASYNC:
476 	{
477 		*message = "DAT_INVALID_STATE_EVD_ASYNC";
478 		return (DAT_SUCCESS);
479 	}
480 	case DAT_INVALID_STATE_IA_IN_USE:
481 	{
482 		*message = "DAT_INVALID_STATE_IA_IN_USE";
483 		return (DAT_SUCCESS);
484 	}
485 	case DAT_INVALID_STATE_LMR_IN_USE:
486 	{
487 		*message = "DAT_INVALID_STATE_LMR_IN_USE";
488 		return (DAT_SUCCESS);
489 	}
490 	case DAT_INVALID_STATE_LMR_FREE:
491 	{
492 		*message = "DAT_INVALID_STATE_LMR_FREE";
493 		return (DAT_SUCCESS);
494 	}
495 	case DAT_INVALID_STATE_PZ_IN_USE:
496 	{
497 		*message = "DAT_INVALID_STATE_PZ_IN_USE";
498 		return (DAT_SUCCESS);
499 	}
500 	case DAT_INVALID_STATE_PZ_FREE:
501 	{
502 		*message = "DAT_INVALID_STATE_PZ_FREE";
503 		return (DAT_SUCCESS);
504 	}
505 	case DAT_PRIVILEGES_READ:
506 	{
507 		*message = "DAT_PRIVILEGES_READ";
508 		return (DAT_SUCCESS);
509 	}
510 	case DAT_PRIVILEGES_WRITE:
511 	{
512 		*message = "DAT_PRIVILEGES_WRITE";
513 		return (DAT_SUCCESS);
514 	}
515 	case DAT_PRIVILEGES_RDMA_READ:
516 	{
517 		*message = "DAT_PRIVILEGES_RDMA_READ";
518 		return (DAT_SUCCESS);
519 	}
520 	case DAT_PRIVILEGES_RDMA_WRITE:
521 	{
522 		*message = "DAT_PRIVILEGES_RDMA_WRITE";
523 		return (DAT_SUCCESS);
524 	}
525 	case DAT_PROTECTION_READ:
526 	{
527 		*message = "DAT_PROTECTION_READ";
528 		return (DAT_SUCCESS);
529 	}
530 	case DAT_PROTECTION_WRITE:
531 	{
532 		*message = "DAT_PROTECTION_WRITE";
533 		return (DAT_SUCCESS);
534 	}
535 	case DAT_PROTECTION_RDMA_READ:
536 	{
537 		*message = "DAT_PROTECTION_RDMA_READ";
538 		return (DAT_SUCCESS);
539 	}
540 	case DAT_PROTECTION_RDMA_WRITE:
541 	{
542 		*message = "DAT_PROTECTION_RDMA_WRITE";
543 		return (DAT_SUCCESS);
544 	}
545 	case DAT_INVALID_ADDRESS_UNSUPPORTED:
546 	{
547 		*message = "DAT_INVALID_ADDRESS_UNSUPPORTED";
548 		return (DAT_SUCCESS);
549 	}
550 	case DAT_INVALID_ADDRESS_UNREACHABLE:
551 	{
552 		*message = "DAT_INVALID_ADDRESS_UNREACHABLE";
553 		return (DAT_SUCCESS);
554 	}
555 	case DAT_INVALID_ADDRESS_MALFORMED:
556 	{
557 		*message = "DAT_INVALID_ADDRESS_MALFORMED";
558 		return (DAT_SUCCESS);
559 	}
560 	case DAT_INVALID_RO_COOKIE:
561 		*message = "DAT_INVALID_RO_COOKIE";
562 		return (DAT_SUCCESS);
563 	default:
564 	{
565 		return (DAT_INVALID_PARAMETER);
566 	}
567 	}
568 }
569 
570 
571 /*
572  *
573  * External Function Definitions
574  *
575  */
576 
577 DAT_RETURN
578 dat_strerror(
579 	IN  DAT_RETURN 		value,
580 	OUT const char 		**major_message,
581 	OUT const char		**minor_message)
582 {
583 	/*
584 	 * The DAT specification contains a note to implementers
585 	 * suggesting that the consumer's DAT_RETURN value be used
586 	 * as an index into a table of text strings. However,
587 	 * the DAT_RETURN values are not consecutive. Therefore this
588 	 * implementation does not follow the suggested implementation.
589 	 */
590 
591 	if (DAT_SUCCESS != dat_strerror_major(value, major_message)) {
592 		return (DAT_INVALID_PARAMETER);
593 	} else if (DAT_SUCCESS != dat_strerror_minor(value, minor_message)) {
594 		return (DAT_INVALID_PARAMETER);
595 	} else {
596 		return (DAT_SUCCESS);
597 	}
598 }
599