27#include "../switchtec_priv.h"
28#include "switchtec/utils.h"
36#define gas_reg_read8(dev, reg) __gas_read8(dev, &dev->gas_map->reg)
37#define gas_reg_read16(dev, reg) __gas_read16(dev, &dev->gas_map->reg)
38#define gas_reg_read32(dev, reg) __gas_read32(dev, &dev->gas_map->reg)
39#define gas_reg_read64(dev, reg) __gas_read64(dev, &dev->gas_map->reg)
41#define gas_reg_write8(dev, val, reg) __gas_write8(dev, val, \
43#define gas_reg_write16(dev, val, reg) __gas_write16(dev, val, \
45#define gas_reg_write32(dev, val, reg) __gas_write32(dev, val, \
47#define gas_reg_write64(dev, val, reg) __gas_write64(dev, val, \
50static const char gasop_noretry_cmds[] = {
51 [MRPC_SECURITY_CONFIG_SET] = 1,
52 [MRPC_KMSK_ENTRY_SET] = 1,
53 [MRPC_SECURE_STATE_SET] = 1,
54 [MRPC_BOOTUP_RESUME] = 1,
55 [MRPC_DBG_UNLOCK] = 1,
56 [MRPC_SECURITY_CONFIG_SET_GEN5] = 1,
58static const int gasop_noretry_cmds_count =
sizeof(gasop_noretry_cmds) /
61static inline bool gasop_is_no_retry_cmd(uint32_t cmd)
63 cmd &= SWITCHTEC_CMD_MASK;
65 if (cmd >= gasop_noretry_cmds_count)
67 return gasop_noretry_cmds[cmd];
70int gasop_access_check(
struct switchtec_dev *dev)
74 device_id = gas_reg_read32(dev, sys_info.device_id);
80void gasop_set_partition_info(
struct switchtec_dev *dev)
82 dev->partition = gas_reg_read8(dev, top.partition_id);
83 dev->partition_count = gas_reg_read8(dev, top.partition_count);
86int gasop_cmd(
struct switchtec_dev *dev, uint32_t cmd,
87 const void *payload,
size_t payload_len,
void *resp,
90 struct mrpc_regs __gas *mrpc = &dev->gas_map->mrpc;
94 __memcpy_to_gas(dev, &mrpc->input_data, payload, payload_len);
109 if (gasop_is_no_retry_cmd(cmd))
110 __gas_write32_no_retry(dev, cmd, &mrpc->cmd);
112 __gas_write32(dev, cmd, &mrpc->cmd);
117 status = __gas_read32(dev, &mrpc->status);
118 if (status != SWITCHTEC_MRPC_STATUS_INPROGRESS)
122 if (status == SWITCHTEC_MRPC_STATUS_INTERRUPTED) {
127 if(status == SWITCHTEC_MRPC_STATUS_ERROR) {
128 errno = __gas_read32(dev, &mrpc->ret_value);
132 if (status != SWITCHTEC_MRPC_STATUS_DONE) {
137 ret = __gas_read32(dev, &mrpc->ret_value);
142 __memcpy_from_gas(dev, resp, &mrpc->output_data, resp_len);
147int gasop_get_device_id(
struct switchtec_dev *dev)
149 return gas_reg_read32(dev, sys_info.device_id);
152int gasop_get_fw_version(
struct switchtec_dev *dev,
char *buf,
157 ver = gas_reg_read32(dev, sys_info.firmware_version);
158 version_to_string(ver, buf, buflen);
163int gasop_pff_to_port(
struct switchtec_dev *dev,
int pff,
164 int *partition,
int *port)
172 for (part = 0; part < dev->partition_count; part++) {
173 pcfg = &dev->gas_map->part_cfg[part];
176 reg = __gas_read32(dev, &pcfg->usp_pff_inst_id);
182 reg = __gas_read32(dev, &pcfg->vep_pff_inst_id);
184 *port = SWITCHTEC_PFF_PORT_VEP;
188 for (i = 0; i < ARRAY_SIZE(pcfg->dsp_pff_inst_id); i++) {
189 reg = __gas_read32(dev, &pcfg->dsp_pff_inst_id[i]);
205int gasop_port_to_pff(
struct switchtec_dev *dev,
int partition,
211 partition = dev->partition;
212 }
else if (partition >= dev->partition_count) {
217 pcfg = &dev->gas_map->part_cfg[partition];
221 *pff = __gas_read32(dev, &pcfg->usp_pff_inst_id);
223 case SWITCHTEC_PFF_PORT_VEP:
224 *pff = __gas_read32(dev, &pcfg->vep_pff_inst_id);
227 if (port > ARRAY_SIZE(pcfg->dsp_pff_inst_id)) {
232 *pff = __gas_read32(dev, &pcfg->dsp_pff_inst_id[port - 1]);
239static void set_fw_info_part(
struct switchtec_dev *dev,
241 struct partition_info __gas *pi)
243 info->
part_addr = __gas_read32(dev, &pi->address);
244 info->
part_len = __gas_read32(dev, &pi->length);
247int gasop_flash_part(
struct switchtec_dev *dev,
249 enum switchtec_fw_image_part_id_gen3 part)
253 uint32_t active_addr = -1;
256 info->running =
false;
257 info->active =
false;
260 case SWITCHTEC_FW_PART_ID_G3_IMG0:
261 active_addr = __gas_read32(dev, &fi->active_img.address);
262 set_fw_info_part(dev, info, &fi->img0);
264 val = __gas_read16(dev, &si->img_running);
265 if (val == SWITCHTEC_IMG0_RUNNING)
266 info->running =
true;
269 case SWITCHTEC_FW_PART_ID_G3_IMG1:
270 active_addr = __gas_read32(dev, &fi->active_img.address);
271 set_fw_info_part(dev, info, &fi->img1);
273 val = __gas_read16(dev, &si->img_running);
274 if (val == SWITCHTEC_IMG1_RUNNING)
275 info->running =
true;
278 case SWITCHTEC_FW_PART_ID_G3_DAT0:
279 active_addr = __gas_read32(dev, &fi->active_cfg.address);
280 set_fw_info_part(dev, info, &fi->cfg0);
282 val = __gas_read16(dev, &si->cfg_running);
283 if (val == SWITCHTEC_CFG0_RUNNING)
284 info->running =
true;
287 case SWITCHTEC_FW_PART_ID_G3_DAT1:
288 active_addr = __gas_read32(dev, &fi->active_cfg.address);
289 set_fw_info_part(dev, info, &fi->cfg1);
291 val = __gas_read16(dev, &si->cfg_running);
292 if (val == SWITCHTEC_CFG1_RUNNING)
293 info->running =
true;
296 case SWITCHTEC_FW_PART_ID_G3_NVLOG:
297 set_fw_info_part(dev, info, &fi->nvlog);
310int gasop_event_summary(
struct switchtec_dev *dev,
319 memset(sum, 0,
sizeof(*sum));
321 sum->
global = gas_reg_read32(dev, sw_event.global_summary);
322 sum->
part_bitmap = gas_reg_read64(dev, sw_event.part_event_bitmap);
324 for (i = 0; i < dev->partition_count; i++) {
325 reg = gas_reg_read32(dev, part_cfg[i].part_event_summary);
327 if (i == dev->partition)
331 for (i = 0; i < SWITCHTEC_MAX_PFF_CSR; i++) {
332 reg = gas_reg_read16(dev, pff_csr[i].vendor_id);
333 if (reg != MICROSEMI_VENDOR_ID)
336 sum->
pff[i] = gas_reg_read32(dev, pff_csr[i].pff_event_summary);
342static uint32_t __gas *global_ev_reg(
struct switchtec_dev *dev,
343 size_t offset,
int index)
345 return (
void __gas *)&dev->gas_map->sw_event + offset;
348static uint32_t __gas *part_ev_reg(
struct switchtec_dev *dev,
349 size_t offset,
int index)
351 return (
void __gas *)&dev->gas_map->part_cfg[index] + offset;
354static uint32_t __gas *pff_ev_reg(
struct switchtec_dev *dev,
355 size_t offset,
int index)
357 return (
void __gas *)&dev->gas_map->pff_csr[index] + offset;
360#define EV_GLB(i, r)[SWITCHTEC_GLOBAL_EVT_ ## i] = \
361 {offsetof(struct sw_event_regs, r), global_ev_reg}
362#define EV_PAR(i, r)[SWITCHTEC_PART_EVT_ ## i] = \
363 {offsetof(struct part_cfg_regs, r), part_ev_reg}
364#define EV_PFF(i, r)[SWITCHTEC_PFF_EVT_ ## i] = \
365 {offsetof(struct pff_csr_regs, r), pff_ev_reg}
369 uint32_t __gas *(*map_reg)(
struct switchtec_dev *stdev,
370 size_t offset,
int index);
372 EV_GLB(STACK_ERROR, stack_error_event_hdr),
373 EV_GLB(PPU_ERROR, ppu_error_event_hdr),
374 EV_GLB(ISP_ERROR, isp_error_event_hdr),
375 EV_GLB(SYS_RESET, sys_reset_event_hdr),
376 EV_GLB(FW_EXC, fw_exception_hdr),
377 EV_GLB(FW_NMI, fw_nmi_hdr),
378 EV_GLB(FW_NON_FATAL, fw_non_fatal_hdr),
379 EV_GLB(FW_FATAL, fw_fatal_hdr),
380 EV_GLB(TWI_MRPC_COMP, twi_mrpc_comp_hdr),
381 EV_GLB(TWI_MRPC_COMP_ASYNC, twi_mrpc_comp_async_hdr),
382 EV_GLB(CLI_MRPC_COMP, cli_mrpc_comp_hdr),
383 EV_GLB(CLI_MRPC_COMP_ASYNC, cli_mrpc_comp_async_hdr),
384 EV_GLB(GPIO_INT, gpio_interrupt_hdr),
385 EV_GLB(GFMS, gfms_event_hdr),
386 EV_PAR(PART_RESET, part_reset_hdr),
387 EV_PAR(MRPC_COMP, mrpc_comp_hdr),
388 EV_PAR(MRPC_COMP_ASYNC, mrpc_comp_async_hdr),
389 EV_PAR(DYN_PART_BIND_COMP, dyn_binding_hdr),
390 EV_PFF(AER_IN_P2P, aer_in_p2p_hdr),
391 EV_PFF(AER_IN_VEP, aer_in_vep_hdr),
392 EV_PFF(DPC, dpc_hdr),
393 EV_PFF(CTS, cts_hdr),
394 EV_PFF(UEC, uec_hdr),
395 EV_PFF(HOTPLUG, hotplug_hdr),
396 EV_PFF(IER, ier_hdr),
397 EV_PFF(THRESH, threshold_hdr),
398 EV_PFF(POWER_MGMT, power_mgmt_hdr),
399 EV_PFF(TLP_THROTTLING, tlp_throttling_hdr),
400 EV_PFF(FORCE_SPEED, force_speed_hdr),
401 EV_PFF(CREDIT_TIMEOUT, credit_timeout_hdr),
402 EV_PFF(LINK_STATE, link_state_hdr),
405static uint32_t __gas *event_hdr_addr(
struct switchtec_dev *dev,
411 if (e < 0 || e >= SWITCHTEC_MAX_EVENTS)
414 off = event_regs[e].offset;
416 if (event_regs[e].map_reg == part_ev_reg) {
418 index = dev->partition;
419 else if (index >= dev->partition_count)
421 }
else if (event_regs[e].map_reg == pff_ev_reg) {
422 if (index < 0 || index >= SWITCHTEC_MAX_PFF_CSR)
426 return event_regs[e].map_reg(dev, off, index);
430 int index,
int flags, uint32_t data[5])
436 reg = event_hdr_addr(dev, e, index);
442 hdr = __gas_read32(dev, reg);
444 for (i = 0; i < 5; i++)
445 data[i] = __gas_read32(dev, ®[i + 1]);
447 if (!(flags & SWITCHTEC_EVT_FLAG_CLEAR))
448 hdr &= ~SWITCHTEC_EVENT_CLEAR;
449 if (flags & SWITCHTEC_EVT_FLAG_EN_POLL)
450 hdr |= SWITCHTEC_EVENT_EN_IRQ;
451 if (flags & SWITCHTEC_EVT_FLAG_EN_LOG)
452 hdr |= SWITCHTEC_EVENT_EN_LOG;
453 if (flags & SWITCHTEC_EVT_FLAG_EN_CLI)
454 hdr |= SWITCHTEC_EVENT_EN_CLI;
455 if (flags & SWITCHTEC_EVT_FLAG_EN_FATAL)
456 hdr |= SWITCHTEC_EVENT_FATAL;
457 if (flags & SWITCHTEC_EVT_FLAG_DIS_POLL)
458 hdr &= ~SWITCHTEC_EVENT_EN_IRQ;
459 if (flags & SWITCHTEC_EVT_FLAG_DIS_LOG)
460 hdr &= ~SWITCHTEC_EVENT_EN_LOG;
461 if (flags & SWITCHTEC_EVT_FLAG_DIS_CLI)
462 hdr &= ~SWITCHTEC_EVENT_EN_CLI;
463 if (flags & SWITCHTEC_EVT_FLAG_DIS_FATAL)
464 hdr &= ~SWITCHTEC_EVENT_FATAL;
467 __gas_write32(dev, hdr, reg);
469 return (hdr >> 5) & 0xFF;
473 int index,
int flags, uint32_t data[5])
478 if (e >= SWITCHTEC_MAX_EVENTS)
481 if (index == SWITCHTEC_EVT_IDX_ALL) {
482 if (event_regs[e].map_reg == global_ev_reg)
484 else if (event_regs[e].map_reg == part_ev_reg)
485 nr_idxs = dev->partition_count;
486 else if (event_regs[e].map_reg == pff_ev_reg)
487 nr_idxs = gas_reg_read8(dev, top.pff_count);
491 for (index = 0; index < nr_idxs; index++) {
492 ret = event_ctl(dev, e, index, flags, data);
497 ret = event_ctl(dev, e, index, flags, data);
507int gasop_event_wait_for(
struct switchtec_dev *dev,
513 long long start, now;
522 SWITCHTEC_EVT_FLAG_CLEAR |
523 SWITCHTEC_EVT_FLAG_EN_POLL,
528 ret = gettimeofday(&tv, NULL);
532 now = start = ((tv.tv_sec) * 1000 + tv.tv_usec / 1000);
542 ret = gettimeofday(&tv, NULL);
546 now = ((tv.tv_sec) * 1000 + tv.tv_usec / 1000);
548 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.
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_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.
Information about a firmware image or partition.
size_t part_addr
Address of the partition.
size_t part_len
Length of the partition.
switchtec_event_id
Enumeration of all possible events.