1 /*
2  * Copyright (c) 2014-2019 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include "linux/errno.h"
21 #include "qdf_module.h"
22 #include "qdf_status.h"
23 
24 /*
25  * Customer to make use of this API to map
26  * QDF errors to customer specific error codes
27  * or standard errors as need be.
28  */
29 #ifdef WLAN_CUSTOMIZE_ERROR_CODES
qdf_status_to_os_return(QDF_STATUS status)30 int qdf_status_to_os_return(QDF_STATUS status)
31 {
32 	switch (status) {
33 	case QDF_STATUS_SUCCESS:
34 		return 0;
35 	default:
36 		return -EPERM;
37 	}
38 }
39 
40 qdf_export_symbol(qdf_status_to_os_return);
41 #else
qdf_status_to_os_return(QDF_STATUS status)42 int qdf_status_to_os_return(QDF_STATUS status)
43 {
44 	switch (status) {
45 	case QDF_STATUS_SUCCESS:
46 		return 0;
47 	case QDF_STATUS_E_RESOURCES:
48 		return -EBUSY;
49 	case QDF_STATUS_E_NOMEM:
50 		return -ENOMEM;
51 	case QDF_STATUS_E_AGAIN:
52 		return -EAGAIN;
53 	case QDF_STATUS_E_INVAL:
54 		return -EINVAL;
55 	case QDF_STATUS_E_FAULT:
56 		return -EFAULT;
57 	case QDF_STATUS_E_ALREADY:
58 		return -EALREADY;
59 	case QDF_STATUS_E_BADMSG:
60 		return -EBADMSG;
61 	case QDF_STATUS_E_BUSY:
62 		return -EBUSY;
63 	case QDF_STATUS_E_CANCELED:
64 		return -ECANCELED;
65 	case QDF_STATUS_E_ABORTED:
66 		return -ECONNABORTED;
67 	case QDF_STATUS_E_PERM:
68 		return -EPERM;
69 	case QDF_STATUS_E_EXISTS:
70 		return -EEXIST;
71 	case QDF_STATUS_E_NOENT:
72 		return -ENOENT;
73 	case QDF_STATUS_E_E2BIG:
74 		return -E2BIG;
75 	case QDF_STATUS_E_NOSPC:
76 		return -ENOSPC;
77 	case QDF_STATUS_E_ADDRNOTAVAIL:
78 		return -EADDRNOTAVAIL;
79 	case QDF_STATUS_E_ENXIO:
80 		return -ENXIO;
81 	case QDF_STATUS_E_NETDOWN:
82 		return -ENETDOWN;
83 	case QDF_STATUS_E_IO:
84 		return -EIO;
85 	case QDF_STATUS_E_NETRESET:
86 		return -ENETRESET;
87 	case QDF_STATUS_E_PENDING:
88 		return -EINPROGRESS;
89 	case QDF_STATUS_E_TIMEOUT:
90 		return -ETIMEDOUT;
91 	default:
92 		return -EPERM;
93 	}
94 }
95 qdf_export_symbol(qdf_status_to_os_return);
96 #endif
97 
qdf_status_from_os_return(int rc)98 QDF_STATUS qdf_status_from_os_return(int rc)
99 {
100 	switch (rc) {
101 	case 0:
102 		return QDF_STATUS_SUCCESS;
103 	case -ENOMEM:
104 		return QDF_STATUS_E_NOMEM;
105 	case -EAGAIN:
106 		return QDF_STATUS_E_AGAIN;
107 	case -EINVAL:
108 		return QDF_STATUS_E_INVAL;
109 	case -EFAULT:
110 		return QDF_STATUS_E_FAULT;
111 	case -EALREADY:
112 		return QDF_STATUS_E_ALREADY;
113 	case -EBADMSG:
114 		return QDF_STATUS_E_BADMSG;
115 	case -EBUSY:
116 		return QDF_STATUS_E_BUSY;
117 	case -ECANCELED:
118 		return QDF_STATUS_E_CANCELED;
119 	case -ECONNABORTED:
120 		return QDF_STATUS_E_ABORTED;
121 	case -EPERM:
122 		return QDF_STATUS_E_PERM;
123 	case -EEXIST:
124 		return QDF_STATUS_E_EXISTS;
125 	case -ENOENT:
126 		return QDF_STATUS_E_NOENT;
127 	case -E2BIG:
128 		return QDF_STATUS_E_E2BIG;
129 	case -ENOSPC:
130 		return QDF_STATUS_E_NOSPC;
131 	case -EADDRNOTAVAIL:
132 		return QDF_STATUS_E_ADDRNOTAVAIL;
133 	case -ENXIO:
134 		return QDF_STATUS_E_ENXIO;
135 	case -ENETDOWN:
136 		return QDF_STATUS_E_NETDOWN;
137 	case -EIO:
138 		return QDF_STATUS_E_IO;
139 	case -ENETRESET:
140 		return QDF_STATUS_E_NETRESET;
141 	case -EINPROGRESS:
142 		return QDF_STATUS_E_PENDING;
143 	case -ETIMEDOUT:
144 		return QDF_STATUS_E_TIMEOUT;
145 	case -ERESTARTSYS:
146 		return QDF_STATUS_E_RESTART;
147 	default:
148 		return QDF_STATUS_E_PERM;
149 	}
150 }
151 qdf_export_symbol(qdf_status_from_os_return);
152 
153