-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathnvm_error.h
72 lines (37 loc) · 1.75 KB
/
nvm_error.h
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef __NVM_ERROR_H__
#define __NVM_ERROR_H__
// #ifndef __CUDACC__
// #define __device__
// #define __host__
// #endif
#include <stdint.h>
#include <nvm_types.h>
#include <nvm_util.h>
/* Get the status code type of an NVM completion. */
#define NVM_ERR_SCT(cpl) ((uint8_t) _RB(*NVM_CPL_STATUS(cpl), 11, 9))
/* Get the status code of an NVM completion */
#define NVM_ERR_SC(cpl) ((uint8_t) _RB(*NVM_CPL_STATUS(cpl), 8, 1))
/* Is do not retry flag set? */
#define NVM_ERR_DNR(cpl) (!!_RB(*NVM_CPL_STATUS(cpl), 15, 15))
/* Is there more? (Get log page) */
#define NVM_ERR_MORE(cpl) (!!_RB(*NVM_CPL_STATUS(cpl), 14, 14))
/* Extract value from status field from NVM completion */
#define NVM_ERR_STATUS(cpl) \
((int) ( (cpl) != NULL ? -((NVM_ERR_SCT(cpl) << 8) | NVM_ERR_SC(cpl)) : 0 ))
/* Convenience macro for checking if an NVM completion indicates success. */
#define NVM_ERR_OK(cpl) ( !NVM_ERR_SCT(cpl) && !NVM_ERR_SC(cpl) )
/* Pack errno and NVM completion status into a single status variable */
#define NVM_ERR_PACK(cpl, err) \
((int) ( (err) != 0 ? (err) : NVM_ERR_STATUS(cpl) ) )
/* Extract values from packed status */
#define NVM_ERR_UNPACK_ERRNO(status) ((status > 0) ? (status) : 0)
#define NVM_ERR_UNPACK_SCT(status) ((status < 0) ? (((-status) >> 8) & 0xff) : 0)
#define NVM_ERR_UNPACK_SC(status) ((status < 0) ? ((-status) & 0xff) : 0)
/* Check if everything is okay */
#define nvm_ok(status) ( !(status) )
/*
* Get an error string associated with the status code type and status code.
* This function calls strerror() if the packed status is a regular errno.
*/
const char* nvm_strerror(int status);
#endif /* __NVM_ERROR_H__ */