-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpoemgr.h
145 lines (113 loc) · 2.92 KB
/
poemgr.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* SPDX-License-Identifier: GPL-2.0-only */
#pragma once
#include <time.h>
#include <stdint.h>
#define POEMGR_MAX_PORTS 4
#define POEMGR_MAX_PSE_CHIPS 2
#define POEMGR_MAX_METRICS 10
#define POEMGR_ACTION_STRING_ENABLE "enable"
#define POEMGR_ACTION_STRING_DISABLE "disable"
#define POEMGR_ACTION_STRING_SHOW "show"
#define POEMGR_ACTION_STRING_APPLY "apply"
enum poemgr_poe_type {
POEMGR_POE_TYPE_AF = 0x1,
POEMGR_POE_TYPE_AT = 0x2,
POEMGR_POE_TYPE_BT = 0x4,
};
enum poemgr_port_fault_type {
POEMGR_FAULT_TYPE_POWER_MANAGEMENT = 0x1,
POEMGR_FAULT_TYPE_OVER_TEMPERATURE = 0x2,
POEMGR_FAULT_TYPE_SHORT_CIRCUIT = 0x4,
POEMGR_FAULT_TYPE_RESISTANCE_TOO_LOW = 0x8,
POEMGR_FAULT_TYPE_RESISTANCE_TOO_HIGH = 0x10,
POEMGR_FAULT_TYPE_CAPACITY_TOO_HIGH = 0x20,
POEMGR_FAULT_TYPE_OPEN_CIRCUIT = 0x40,
POEMGR_FAULT_TYPE_OVER_CURRENT = 0x80,
POEMGR_FAULT_TYPE_UNKNOWN = 0x100,
};
enum poemgr_metric_type {
POEMGR_METRIC_INT32,
};
struct poemgr_port_settings {
char *name;
int disabled;
int pse_port;
};
struct poemgr_port_status {
int enabled;
int active;
int power_limit;
int power;
int poe_class;
int faults;
time_t last_update;
};
struct poemgr_port {
struct poemgr_port_settings settings;
struct poemgr_port_status status;
};
struct poemgr_input_status {
enum poemgr_poe_type type;
time_t last_update;
};
struct poemgr_output_status {
int power_budget;
time_t last_update;
};
struct poemgr_settings {
int disabled;
int power_budget;
char *profile;
};
struct poemgr_ctx {
struct poemgr_settings settings;
struct poemgr_port ports[POEMGR_MAX_PORTS];
struct poemgr_profile *profile;
struct poemgr_input_status input_status;
struct poemgr_output_status output_status;
};
struct poemgr_metric {
enum poemgr_metric_type type;
char *name;
union {
char *val_char;
int32_t val_int32;
};
};
struct poemgr_pse_chip {
const char *model;
uint32_t portmask;
void *priv;
/* Metrics */
int num_metrics;
int (*export_metric)(struct poemgr_pse_chip *pse_chip, struct poemgr_metric *output, int metric);
};
struct poemgr_profile {
char *name;
int num_ports;
struct poemgr_pse_chip pse_chips[POEMGR_MAX_PSE_CHIPS];
int num_pse_chips;
void *priv;
int (*init)(struct poemgr_ctx *);
int (*ready)(struct poemgr_ctx *);
int (*enable)(struct poemgr_ctx *);
int (*disable)(struct poemgr_ctx *);
int (*apply_config)(struct poemgr_ctx *);
int (*update_port_status)(struct poemgr_ctx *, int port);
int (*update_input_status)(struct poemgr_ctx *);
int (*update_output_status)(struct poemgr_ctx *);
};
static inline const char *poemgr_poe_type_to_string(enum poemgr_poe_type poe_type)
{
if (poe_type == POEMGR_POE_TYPE_AF)
return "802.3af";
if (poe_type == POEMGR_POE_TYPE_AT)
return "802.3at";
if (poe_type == POEMGR_POE_TYPE_BT)
return "802.3bt";
return "unknown";
}
static inline struct poemgr_pse_chip *poemgr_profile_pse_chip_get(struct poemgr_profile *profile, int pse_idx)
{
return &profile->pse_chips[pse_idx];
}