summaryrefslogtreecommitdiffstats
path: root/src/occ_405/sensor/sensor.h
blob: 406021fedd680881d23bcaf1eecdbe951a1590e1 (plain)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_405/sensor/sensor.h $                                 */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,2017                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

#ifndef _sensor_h
#define _sensor_h

#include <common_types.h>        // defines for uint8_t,uint3_t..etc
#include <errl.h>                // For errlHndl_t
#include <occ_common.h>              // Common OCC defines
#include <sensor_enum.h>         // For Sensor Enum

// Macro to get mini sensor value. It gives the mini sensor value for
// the given occId at given the given field. If occId is out of range, it will
// return 0.
#define MINI_SENSOR_VALUE(occId,fieldNm) \
            ( (occId < MAX_OCCS) ? G_dcom_slv_outbox[occId].fieldNm : 0x0)

// Make a AMEC Number out of mantissa & exponent.
#define AMEFP(mantissa,exp) (((UINT32)mantissa << 8) | (UINT32)((UINT8) 256 + (UINT8)exp))

// Get pointer to sensor based on GSID
#define AMECSENSOR_PTR(sensor) G_amec_sensor_list[sensor]
#define AMECSENSOR_ARRAY_PTR(sensor_base,idx) G_amec_sensor_list[sensor_base+idx]
#define AMECSENSOR_2D_ARRAY_PTR(sensor_base,idx,idx2) G_amec_sensor_list[sensor_base+idx+idx2]

#define AMEC_SENSOR_NONUM           0xFF
#define SENSOR_TYPE_ALL             0xFFFF
#define SENSOR_LOC_ALL              0xFFFF
#define MAX_VECTOR_SENSORS          32
#define MAX_SENSOR_NAME_SZ          16 // including NULL
#define MAX_SENSOR_UNIT_SZ          4 // including NULL
#define MAX_AMEC_SENSORS            710
#define VECTOR_SENSOR_DEFAULT_VAL   0xFF

// AMEC_SENSOR_TYPE_INVALID can not be used to identify sensor type.
// A bit vector mask is used to specify sensor types that AMESTER is
// probed for, and hence when a new sensor type is defined, it has to
// have only one bit set in its value (e.g., 0x01<<num). When all types
// are requested, a 0xFFFF mask (SENSOR_TYPE_ALL) is used to specify all
// types, which is the case for initial AMESTER sensor scan routine to
// detect all OCC sensors.
typedef enum
{
    AMEC_SENSOR_TYPE_INVALID    = 0x0000,    // Not a valid sensor type
    AMEC_SENSOR_TYPE_GENERIC    = 0x0001,
    AMEC_SENSOR_TYPE_CURRENT    = 0x0002,
    AMEC_SENSOR_TYPE_VOLTAGE    = 0x0004,
    AMEC_SENSOR_TYPE_TEMP       = 0x0008,
    AMEC_SENSOR_TYPE_UTIL       = 0x0010,
    AMEC_SENSOR_TYPE_TIME       = 0x0020,
    AMEC_SENSOR_TYPE_FREQ       = 0x0040,
    AMEC_SENSOR_TYPE_POWER      = 0x0080,
    AMEC_SENSOR_TYPE_PERF       = 0x0200,
    AMEC_SENSOR_TYPE_WOF        = 0x0400,
    AMEC_SENSOR_TYPE_ALL        = 0xffff,
}AMEC_SENSOR_TYPE;
// Changes to sensor type bits would require changes to select sensor groups command
// Define the sensor types allowed to be selected via select sensor groups command
#define VALID_SET_SENSOR_GROUPS_MASK (AMEC_SENSOR_TYPE_GENERIC | AMEC_SENSOR_TYPE_CURRENT | \
         AMEC_SENSOR_TYPE_VOLTAGE | AMEC_SENSOR_TYPE_TEMP | AMEC_SENSOR_TYPE_UTIL | \
         AMEC_SENSOR_TYPE_TIME | AMEC_SENSOR_TYPE_FREQ | AMEC_SENSOR_TYPE_POWER | \
         AMEC_SENSOR_TYPE_PERF)

// AMEC_SENSOR_LOC_INVALID can not be used to identify sensor location.
// A bit vector mask is used to specify sensor locations that AMESTER is
// probed for, and hence when a new sensor type is defined, it has to
// have exactly one bit set in its value (e.g., 0x01<<num). When sensors
// from all locations are requested, a 0xFFFF mask (SENSOR_LOC_ALL) is
// used to specify all locations, and that's the case in the initial
// AMESTER sensor scan routine.
typedef enum
{
    AMEC_SENSOR_LOC_INVALID     = 0x0000,   // Not a valid sensor location.
    AMEC_SENSOR_LOC_SYS         = 0x0001,
    AMEC_SENSOR_LOC_PROC        = 0x0002,
    AMEC_SENSOR_LOC_LPAR        = 0x0004,
    AMEC_SENSOR_LOC_MEM         = 0x0008,
    AMEC_SENSOR_LOC_VRM         = 0x0010,
    AMEC_SENSOR_LOC_OCC         = 0x0020,
    AMEC_SENSOR_LOC_CORE        = 0x0040,
    AMEC_SENSOR_LOC_GPU         = 0x0080,
    AMEC_SENSOR_LOC_QUAD        = 0x0100,
    AMEC_SENSOR_LOC_ALL         = 0xffff,
}AMEC_SENSOR_LOC;

// Vector Sensor operation enumeration
typedef enum
{
    VECTOR_OP_NONE = 0x00,
    VECTOR_OP_MAX = 0x01,
    VECTOR_OP_MIN = 0x02,
    VECTOR_OP_AVG = 0x03,

} VECTOR_SENSOR_OP;

// This enumeration specifies which sample minimum/maximum values to clear when
// calling sensor_clear_minmax().  The enumeration values can be OR'd together,
// so each value must be a different power of 2.  Specifying
// AMEC_SENSOR_CLEAR_ALL_MINMAX clears all min/max values in the sensor.
typedef enum
{
    AMEC_SENSOR_CLEAR_SAMPLE_MINMAX           = 0x01,
    AMEC_SENSOR_CLEAR_CSM_SAMPLE_MINMAX       = 0x10,
    AMEC_SENSOR_CLEAR_PROFILER_SAMPLE_MINMAX  = 0x20,
    AMEC_SENSOR_CLEAR_JOB_S_SAMPLE_MINMAX     = 0x40,
    AMEC_SENSOR_CLEAR_ALL_MINMAX              = 0xff,
} AMEC_SENSOR_CLEAR_TYPE;
// The bits for types must match the defined owners in the clear sensor data command
// Define the owners allowed to be cleared via clear sensor data command
#define VALID_CLEAR_SENSOR_OWNER_MASK (AMEC_SENSOR_CLEAR_CSM_SAMPLE_MINMAX | \
         AMEC_SENSOR_CLEAR_PROFILER_SAMPLE_MINMAX | AMEC_SENSOR_CLEAR_JOB_S_SAMPLE_MINMAX)
/*****************************************************************************/
// Forward declaration as used in vectorSensor
struct sensor;
typedef struct sensor sensor_t;

// Vector Sensor structure
struct vectorSensor
{
    VECTOR_SENSOR_OP operation; //Operation that this vector should execute
    uint8_t size; // Number of elements in this vector
    uint8_t  elem_enabled[MAX_VECTOR_SENSORS]; // indicates if a given element
                                            // is enabled or disabled
    sensor_t* source_ptr[MAX_VECTOR_SENSORS]; // Pointer to an array of source
                                //pointers (source elements of this vector)
    uint8_t min_pos; // Minimum val vector position for the latest snapshot
    uint8_t max_pos; // Maximum val vector position for the latest snapshot

} __attribute__ ((__packed__));

typedef struct vectorSensor vectorSensor_t;

typedef struct
{
  char name[MAX_SENSOR_NAME_SZ];
  struct
  {
    char units[MAX_SENSOR_UNIT_SZ];
    uint16_t type;
    uint16_t location;
    uint8_t number;
    uint32_t freq;
    uint32_t scalefactor;
  } __attribute__ ((__packed__)) sensor;
} __attribute__ ((__packed__)) sensor_info_t;

/*****************************************************************************/
//Sensor status structure
struct sensorStatus
{
    uint8_t buffer_area_type:1,
            update_histogram:1,
            reset:1,
            reserved:5;
};
typedef struct sensorStatus sensorStatus_t;

/*****************************************************************************/
// Sensor structure
struct sensor
{
    uint16_t gsid;                // Global Sensor ID
    uint64_t timestamp;           // Timestamp for latest sample
    uint16_t sample;              // Latest sample of this sensor
    uint16_t sample_min;          // Minimum value since last OCC reset
    uint16_t sample_max;          // Maximum value since last OCC reset
    uint16_t csm_sample_min;      // Minimum value since last reset request by CSM
    uint16_t csm_sample_max;      // Maximum value since last reset request by CSM
    uint16_t profiler_sample_min; // Minimum value since last reset request by profiler
    uint16_t profiler_sample_max; // Maximum value since last reset request by profiler
    uint16_t job_s_sample_min;    // Minimum value since last reset by job scheduler
    uint16_t job_s_sample_max;    // Maximum value since last reset by job scheduler
    uint64_t accumulator;         // Accumulator register for this sensor
    uint32_t src_accum_snapshot;  // Copy of the source sensor's accumulator
                                  // used for time-derived sensors
    uint32_t update_tag;          // Count of the number of 'ticks' that have passed
                                  // between updates to this sensor (used for time-
                                  // derived sensor)
    uint32_t ipmi_sid;            // Ipmi sensor id obtained from mrw
    vectorSensor_t * vector;      // Pointer to vector control structure. NULL if
                                  // this is not a vector sensor.
    uint16_t * mini_sensor;       // Pointer to entry in mini-sensor table. NULL if
                                  // this sensor does not have a mini-sensor
    sensorStatus_t status;        // Status and control register

} __attribute__ ((__packed__));

// Typedef for this structure is part of the forward declaration for the
// vector sensor structure section in this file

/*****************************************************************************/
// Sensor Query list structure used for querying sensor data
struct sensorQueryList
{
    uint16_t gsid; // Global Sensor ID
    uint16_t sample; // Latest sample of the sensor
    char name[MAX_SENSOR_NAME_SZ]; // Sensor Name
};

typedef struct sensorQueryList sensorQueryList_t;

/*****************************************************************************/
// Sensor List Structures used to build tables of sensor pointers.
// Global sensor list type
typedef sensor_t * sensor_ptr_t;
// Global mini-sensor list type
typedef uint16_t * minisensor_ptr_t;

/*****************************************************************************/
// These are used by the sensor init
// Global sensor counter
extern uint32_t G_amec_sensor_count;

// Contains array of pointers to sensors, indexed by GSID
extern const sensor_ptr_t     G_amec_sensor_list[];

extern const sensor_info_t    G_sensor_info[];

// Contains array of pointers to mini-sensors, indexed by GSID
extern const minisensor_ptr_t G_amec_mini_sensor_list[];

// Current Time Of Day (TOD).  Constantly updated by TASK_ID_GET_TOD.  Used by
// sensor_update().  Declared volatile since it is used in multiple threads.
extern volatile uint64_t G_tod;

// sensor_init
void sensor_init(sensor_t * io_sensor_ptr,
                 const uint16_t i_gsid,
                 const uint16_t * i_miniSnsrPtr
                 );

// Clear mininum/maximum sample values in sensor
void sensor_clear_minmax(sensor_t * io_sensor_ptr,
                         AMEC_SENSOR_CLEAR_TYPE i_clear_type);

// Sensor reset
void sensor_reset( sensor_t * io_sensor_ptr);

//Vectorize sensor
void sensor_vectorize( sensor_t * io_sensor_ptr,
                       vectorSensor_t * io_vec_sensor_ptr,
                       const VECTOR_SENSOR_OP i_op);

//Update sensor
void sensor_update( sensor_t * io_sensor_ptr, const uint16_t i_sensor_value);

//Perform operation on vector sensor and update sensor
void sensor_vector_update( sensor_t * io_sensor_ptr,const uint32_t i_threshold);

// Get sensor by GSID
sensor_t * getSensorByGsid( const uint16_t i_gsid);

// enable/disable vector sensor element
void sensor_vector_elem_enable( vectorSensor_t* io_sensor_vector_ptr,
                                const uint8_t i_loc,
                                const uint8_t i_enable);

// Add element to the vector sensor
void sensor_vector_elem_add( vectorSensor_t* io_sensor_vector_ptr,
                             const uint8_t i_loc,
                             const sensor_t * i_elemPtr);

// Initialize all sensors
void sensor_init_all(void);

#endif // _sensor_h


OpenPOWER on IntegriCloud