30#define SWITCHTEC_LIB_CORE
32#include "switchtec_priv.h"
35#include "switchtec/utils.h"
57#define EV(t, n, s, d)[SWITCHTEC_ ## t ## _EVT_ ## n] = {\
59 .summary_bit = (1 << (s)), \
64#define GLOBAL SWITCHTEC_EVT_GLOBAL
65#define PART SWITCHTEC_EVT_PART
66#define PFF SWITCHTEC_EVT_PFF
72 const char *short_name;
75 EV(GLOBAL, STACK_ERROR, 0,
"Stack Error"),
76 EV(GLOBAL, PPU_ERROR, 1,
"PPU Error"),
77 EV(GLOBAL, ISP_ERROR, 2,
"ISP Error"),
78 EV(GLOBAL, SYS_RESET, 3,
"System Reset"),
79 EV(GLOBAL, FW_EXC, 4,
"Firmware Exception"),
80 EV(GLOBAL, FW_NMI, 5,
"Firmware Non-Maskable Interrupt"),
81 EV(GLOBAL, FW_NON_FATAL, 6,
"Firmware Non-Fatal Error"),
82 EV(GLOBAL, FW_FATAL, 7,
"Firmware Fatal Error"),
83 EV(GLOBAL, TWI_MRPC_COMP, 8,
"TWI MRPC Completion"),
84 EV(GLOBAL, TWI_MRPC_COMP_ASYNC, 9,
"TWI MRPC Async Completion"),
85 EV(GLOBAL, CLI_MRPC_COMP, 10,
"CLI MRPC Completion"),
86 EV(GLOBAL, CLI_MRPC_COMP_ASYNC, 11,
"CLI MRPC Async Completion"),
87 EV(GLOBAL, GPIO_INT, 12,
"GPIO Interrupt"),
88 EV(GLOBAL, GFMS, 13,
"Global Fabric Management Server Event"),
89 EV(PART, PART_RESET, 0,
"Partition Reset"),
90 EV(PART, MRPC_COMP, 1,
"MRPC Completion"),
91 EV(PART, MRPC_COMP_ASYNC, 2,
"MRPC Async Completion"),
92 EV(PART, DYN_PART_BIND_COMP, 3,
93 "Dynamic Partition Binding Completion"),
94 EV(PFF, AER_IN_P2P, 0,
"Advanced Error Reporting in P2P Port"),
95 EV(PFF, AER_IN_VEP, 1,
"Advanced Error Reporting in vEP"),
96 EV(PFF, DPC, 2,
"Downstream Port Containment Event"),
97 EV(PFF, CTS, 3,
"Completion Timeout Synthesis Event"),
98 EV(PFF, UEC, 4,
"Upstream Error Containment Event"),
99 EV(PFF, HOTPLUG, 5,
"Hotplug Event"),
100 EV(PFF, IER, 6,
"Internal Error Reporting Event"),
101 EV(PFF, THRESH, 7,
"Event Counter Threshold Reached"),
102 EV(PFF, POWER_MGMT, 8,
"Power Management Event"),
103 EV(PFF, TLP_THROTTLING, 9,
"TLP Throttling Event"),
104 EV(PFF, FORCE_SPEED, 10,
"Force Speed Error"),
105 EV(PFF, CREDIT_TIMEOUT, 11,
"Credit Timeout"),
106 EV(PFF, LINK_STATE, 12,
"Link State Change Event"),
107 EV(GLOBAL, ASSERT_ERR, 3,
"Global Assert Error"),
110#define EVBIT(t, n, b)[b] = SWITCHTEC_ ## t ## _EVT_ ## n
113 EVBIT(GLOBAL, STACK_ERROR, 0),
114 EVBIT(GLOBAL, PPU_ERROR, 1),
115 EVBIT(GLOBAL, ISP_ERROR, 2),
116 EVBIT(GLOBAL, SYS_RESET, 3),
117 EVBIT(GLOBAL, FW_EXC, 4),
118 EVBIT(GLOBAL, FW_NMI, 5),
119 EVBIT(GLOBAL, FW_NON_FATAL, 6),
120 EVBIT(GLOBAL, FW_FATAL, 7),
121 EVBIT(GLOBAL, TWI_MRPC_COMP, 8),
122 EVBIT(GLOBAL, TWI_MRPC_COMP_ASYNC, 9),
123 EVBIT(GLOBAL, CLI_MRPC_COMP, 10),
124 EVBIT(GLOBAL, CLI_MRPC_COMP_ASYNC, 11),
125 EVBIT(GLOBAL, GPIO_INT, 12),
130 EVBIT(PART, PART_RESET, 0),
131 EVBIT(PART, MRPC_COMP, 1),
132 EVBIT(PART, MRPC_COMP_ASYNC, 2),
133 EVBIT(PART, DYN_PART_BIND_COMP, 3),
138 EVBIT(PFF, AER_IN_P2P, 0),
139 EVBIT(PFF, AER_IN_VEP, 1),
143 EVBIT(PFF, HOTPLUG, 5),
145 EVBIT(PFF, THRESH, 7),
146 EVBIT(PFF, POWER_MGMT, 8),
147 EVBIT(PFF, TLP_THROTTLING, 9),
148 EVBIT(PFF, FORCE_SPEED, 10),
149 EVBIT(PFF, CREDIT_TIMEOUT, 11),
150 EVBIT(PFF, LINK_STATE, 12),
157 for (i = 0; i < ARRAY_SIZE(sum->
part); i++)
165 for (i = 0; i < ARRAY_SIZE(sum->
pff); i++)
180 uint64_t bit = events[e].summary_bit;
182 switch (events[e].type) {
187 if (index == SWITCHTEC_EVT_IDX_LOCAL) {
189 }
else if (index == SWITCHTEC_EVT_IDX_ALL) {
190 set_all_parts(sum, bit);
191 }
else if (index < 0 || index >= ARRAY_SIZE(sum->
part)) {
195 sum->
part[index] |= bit;
199 if (index == SWITCHTEC_EVT_IDX_ALL) {
200 set_all_pffs(sum, bit);
201 }
else if (index < 0 || index >= ARRAY_SIZE(sum->
pff)) {
205 sum->
pff[index] |= bit;
224 uint64_t bit = events[e].summary_bit;
226 switch (events[e].type) {
230 return sum->
part[index] & bit;
232 return sum->
pff[index] & bit;
261 bit = ffs(sum->
global) - 1;
264 *e = SWITCHTEC_GLOBAL_EVT_ASSERT_ERR;
266 *e = global_event_bits[bit];
267 sum->
global &= ~(1 << bit);
271 for (*idx = 0; *idx < ARRAY_SIZE(sum->
part); (*idx)++) {
272 bit = ffs(sum->
part[*idx]) - 1;
276 *e = part_event_bits[bit];
277 sum->
part[*idx] &= ~(1 << bit);
281 for (*idx = 0; *idx < ARRAY_SIZE(sum->
pff); (*idx)++) {
282 bit = ffs(sum->
pff[*idx]) - 1;
286 *e = pff_event_bits[bit];
287 sum->
pff[*idx] &= ~(1 << bit);
329 for (i = 0; i < SWITCHTEC_MAX_PARTS; i++)
333 for (i = 0; i < SWITCHTEC_MAX_PFF_CSR; i++)
334 if (chk->
pff[i] & res->
pff[i])
352 if (e <= SWITCHTEC_EVT_INVALID || e >= SWITCHTEC_MAX_EVENTS)
356 *name = events[e].short_name;
359 *desc = events[e].desc;
361 return events[e].type;
380 long long start, now;
384 if (dev->ops->event_wait_for)
385 return dev->ops->event_wait_for(dev, e, index, res, timeout_ms);
392 SWITCHTEC_EVT_FLAG_CLEAR |
393 SWITCHTEC_EVT_FLAG_EN_POLL,
398 ret = gettimeofday(&tv, NULL);
402 now = start = ((tv.tv_sec) * 1000 + tv.tv_usec / 1000);
406 now - start + timeout_ms : -1);
421 ret = gettimeofday(&tv, NULL);
425 now = ((tv.tv_sec) * 1000 + tv.tv_usec / 1000);
427 if (timeout_ms > 0 && now - start >= timeout_ms) {
int switchtec_event_ctl(struct switchtec_dev *dev, enum switchtec_event_id e, int index, int flags, uint32_t data[5])
Enable, disable and clear events or retrieve event data.
enum switchtec_event_type switchtec_event_info(enum switchtec_event_id e, const char **name, const char **desc)
Get the name and description strings as well as the type (global, partition or pff) for a specific ev...
int switchtec_event_wait_for(struct switchtec_dev *dev, enum switchtec_event_id e, int index, struct switchtec_event_summary *res, int timeout_ms)
Block until a specific event occurs.
int switchtec_event_summary_iter(struct switchtec_dev *dev, struct switchtec_event_summary *sum, enum switchtec_event_id *e, int *idx)
Iterate through all set bits in an event summary structure.
int switchtec_event_summary_set(struct switchtec_event_summary *sum, enum switchtec_event_id e, int index)
Set a bit corresponding to an event in a summary structure.
int switchtec_event_summary(struct switchtec_dev *dev, struct switchtec_event_summary *sum)
Retrieve a summary of all the events that have occurred in the switch.
int switchtec_event_wait(struct switchtec_dev *dev, int timeout_ms)
Wait for any event to occur (typically just an interrupt).
int switchtec_event_summary_test(struct switchtec_event_summary *sum, enum switchtec_event_id e, int index)
Test if a bit corresponding to an event is set in a summary structure.
int switchtec_event_check(struct switchtec_dev *dev, struct switchtec_event_summary *chk, struct switchtec_event_summary *res)
Check if one or more events have occurred.
uint64_t part_bitmap
Bitmap of partitions with active events.
uint64_t global
Bitmap of global events.
unsigned part[SWITCHTEC_MAX_PARTS]
Bitmap of events in each partition.
unsigned local_part
Bitmap of events in the local partition.
unsigned pff[SWITCHTEC_MAX_PFF_CSR]
Bitmap of events in each port function.
switchtec_event_id
Enumeration of all possible events.
static int switchtec_is_gen6(struct switchtec_dev *dev)
Return whether a Switchtec device is a Gen 6 device.
switchtec_event_type
There are three event types indicated by this enumeration: global, partition and port function.