ONLP
Open Network Linux Platform APIs
onlp.h
1 /************************************************************
2  * <bsn.cl fy=2014 v=onl>
3  *
4  * Copyright 2014, 2015 Big Switch Networks, Inc.
5  *
6  * Licensed under the Eclipse Public License, Version 1.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.eclipse.org/legal/epl-v10.html
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific
16  * language governing permissions and limitations under the
17  * License.
18  *
19  * </bsn.cl>
20  ************************************************************
21  *
22  *
23  *
24  ***********************************************************/
25 #ifndef __ONLP_ONLP_H__
26 #define __ONLP_ONLP_H__
27 
28 #include <onlp/onlp_config.h>
29 
30 /* <auto.start.enum(tag:onlp).define> */
32 typedef enum onlp_status_e {
33  ONLP_STATUS_OK = 0,
34  ONLP_STATUS_E_GENERIC = -1,
35  ONLP_STATUS_E_UNSUPPORTED = -10,
36  ONLP_STATUS_E_MISSING = -11,
37  ONLP_STATUS_E_INVALID = -12,
38  ONLP_STATUS_E_INTERNAL = -13,
39  ONLP_STATUS_E_PARAM = -14,
40  ONLP_STATUS_E_I2C = -15,
41 } onlp_status_t;
42 /* <auto.end.enum(tag:onlp).define> */
43 
44 #define ONLP_IF_ERROR_RETURN(_expr) \
45  do { \
46  int _rv = (_expr); \
47  if(_rv < 0) { \
48  return _rv; \
49  } \
50  } while(0)
51 
52 #define ONLP_FAILURE(_rv) ((_rv) < 0)
53 #define ONLP_SUCCESS(_rv) (!(ONLP_FAILURE(_rv)))
54 #define ONLP_UNSUPPORTED(_rv) \
55  ((_rv) == ONLP_STATUS_E_UNSUPPORTED)
56 
57 #define ONLP_TRY(_expr) \
58  do { \
59  int _rv = (_expr); \
60  if(ONLP_FAILURE(_rv)) { \
61  AIM_LOG_ERROR("%s returned %{onlp_status}", #_expr, _rv); \
62  return _rv; \
63  } \
64  } while(0)
65 
66 #define ONLP_SUPPORTED(_rv) \
67  (ONLP_SUCCESS(_rv) || !ONLP_UNSUPPORTED(_rv))
68 
69 #define ONLP_RETURN_IF_SUPPORTED(_expr) \
70  do { \
71  int _rv = _expr; \
72  if(ONLP_SUPPORTED(_rv)) { \
73  return _rv; \
74  } \
75  } while(0)
76 
80 int onlp_sw_init(const char* platform);
81 
82 int onlp_hw_init(uint32_t flags);
83 
84 int onlp_sw_denit(void);
85 
91 void onlp_platform_dump(aim_pvs_t* pvs, uint32_t flags);
92 void onlp_platform_show(aim_pvs_t* pvs, uint32_t flags);
93 
95 #define ONLP_MILLI_NORMAL_INTEGER(_m) (_m / 1000)
96 #define ONLP_MILLI_NORMAL_TENTHS(_m) ( (_m % 1000) / 100)
97 #define ONLP_MILLI_NORMAL_INTEGER_TENTHS(_m) ONLP_MILLI_NORMAL_INTEGER(_m), ONLP_MILLI_NORMAL_TENTHS(_m)
98 
99 
100 
101 
102 
103 /******************************************************************************
104  *
105  * Enumeration Support Definitions.
106  *
107  * Please do not add additional code beyond this point.
108  *
109  *****************************************************************************/
110 /* <auto.start.enum(tag:onlp).supportheader> */
112 const char* onlp_status_name(onlp_status_t e);
113 
115 int onlp_status_value(const char* str, onlp_status_t* e, int substr);
116 
118 const char* onlp_status_desc(onlp_status_t e);
119 
121 int onlp_status_valid(onlp_status_t e);
122 
124 #define ONLP_STATUS_VALID(_e) \
125  (onlp_status_valid((_e)))
126 
128 extern aim_map_si_t onlp_status_map[];
130 extern aim_map_si_t onlp_status_desc_map[];
131 /* <auto.end.enum(tag:onlp).supportheader> */
132 
133 #endif /* __ONLP_ONLP_H__ */
onlp Configuration Header