// File: /workspace/github_c_makefile_star2_O0/intel[P]pf-bb-config/vrb2/vrb2_cfg_app.c
// Function: vrb2_device_error
static bool
vrb2_device_error(void *dev, int int_src)
{
	uint16_t eng_type;
	hw_device *accel_dev = (hw_device *)dev;
	uint8_t *bar0addr = accel_dev->bar0Addr;
	bool fatal_error = false, exit_ir = false;

	/* Flag fatal error based on interrupt source */
	if (irdata[int_src].fatal)
		fatal_error = true;
	/* Flag fatal error based on error register */
	if (vrb2_check_error_reg(bar0addr))
		fatal_error = true;

	/* Clear error injection */
	vrb2_reg_write(bar0addr, HWPfHiErrInjectReg, 0);
	vrb2_reg_write(bar0addr, HWPfAramControlStatus, VRB2_ARAM_CONTROL);
	vrb2_reg_write(bar0addr, HWPfDmaCmplTmOutCnt, 0xFFFFFFFF);
	for (eng_type = 0; eng_type < VRB2_ENG_TYPE_NUM; eng_type++)
		vrb2_reg_write(bar0addr, HWPfDmaProcTmOutCnt + eng_type * 4, VRB2_PROC_TIMEOUT);
	vrb2_reg_write(bar0addr, HWPfQmgrAramWatchdogCount, VRB2_QMGR_ARAM_TIMEOUT);
	vrb2_reg_write(bar0addr, HWPfQmgrAxiWatchdogCount, VRB2_QMGR_AXI_TIMEOUT);
	vrb2_reg_write(bar0addr, HWPfQmgrProcessWatchdogCount, VRB2_QMGR_TIMEOUT);
	vrb2_reg_write(bar0addr, HWPfDmaClusterHangThld, VRB2_CLUST_TIMEOUT);
	if (b0_variant)
		vrb2_reg_write(bar0addr, HWPfDmaClusterCtrl, 0x1);

	if (fatal_error && (accel_dev->dev_status[0] != RTE_BBDEV_DEV_FATAL_ERR)) {
		LOG(ERR, "Fatal error");
		/* For these conditions a device fatal error was hit */
		bb_acc_set_all_device_status(accel_dev, RTE_BBDEV_DEV_FATAL_ERR);
		/*
		 * When fatal error is detected, the device may be reset or not according to
		 * the related device attributes.
		 */
		if (accel_dev->auto_reconfig_on_fatal_error) {
			/* Clear back the status register */
			vrb2_reg_fast_write(bar0addr, HWPfHiIosf2axiErrLogReg, 0xFFFFFFFF);
			/* reset and reconfigure the device */
			if (accel_dev->device_reset_using_flr == DEVICE_RESET_USING_FLR) {
				LOG(INFO, "FLR and reconfig");
				if (bb_acc_dev_reset_and_reconfig(accel_dev))
					LOG(ERR, "FLR and reconfig failed");
			} else {
				LOG(INFO, "Cluster reset and reconfig");
				if (bb_acc_cluster_reset_and_reconfig(accel_dev))
					LOG(ERR, "Cluster reset and reconfig failed");
			}
			/* Exit IR since the device was reconfigured. */
			exit_ir = true;
		}
	}

	if (fatal_error && !exit_ir) {
		/* In case of fatal error but not recovered, need to hide this very error
		source so that to prevent flooding the IR with the same cause. */
		vrb2_disable_int_src(bar0addr, int_src);
		if (int_src == VRB2_DMA_CLUSTER_HANG_DETECTED)
			vrb2_disable_int_src(bar0addr, VRB2_CORE_HANG_DETECTED);
	}

	if (!fatal_error)
		LOG(DEBUG, "Non fatal error");

	return exit_ir;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0xb0(%rax), %rax
movq %rax, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
movb $0x0, -0x22(%rbp)
movslq -0xc(%rbp), %rcx
leaq 0x22277(%rip), %rax     # 0x3ae50
shlq $0x4, %rcx
addq %rcx, %rax
testb $0x1, 0x9(%rax)
je 0x18bea
movb $0x1, -0x21(%rbp)
movq -0x20(%rbp), %rdi
callq 0x1be00
testb $0x1, %al
jne 0x18bf9
jmp 0x18bfd
movb $0x1, -0x21(%rbp)
movq -0x20(%rbp), %rdi
movl $0xc84204, %esi         # imm = 0xC84204
xorl %edx, %edx
callq 0x197e0
movq -0x20(%rbp), %rdi
movl $0x810000, %esi         # imm = 0x810000
movl $0x30, %edx
callq 0x197e0
movq -0x20(%rbp), %rdi
movl $0xb80800, %esi         # imm = 0xB80800
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x197e0
movw $0x0, -0xe(%rbp)
movzwl -0xe(%rbp), %eax
cmpl $0x6, %eax
jge 0x18c6b
movq -0x20(%rbp), %rdi
movzwl -0xe(%rbp), %esi
shll $0x2, %esi
addl $0xb80f00, %esi         # imm = 0xB80F00
movl $0x200000, %edx         # imm = 0x200000
callq 0x197e0
movw -0xe(%rbp), %ax
addw $0x1, %ax
movw %ax, -0xe(%rbp)
jmp 0x18c39
movq -0x20(%rbp), %rdi
movl $0xa00040, %esi         # imm = 0xA00040
movl $0x800, %edx            # imm = 0x800
callq 0x197e0
movq -0x20(%rbp), %rdi
movl $0xa00048, %esi         # imm = 0xA00048
movl $0x800, %edx            # imm = 0x800
callq 0x197e0
movq -0x20(%rbp), %rdi
movl $0xa00050, %esi         # imm = 0xA00050
movl $0x10000000, %edx       # imm = 0x10000000
callq 0x197e0
movq -0x20(%rbp), %rdi
movl $0xb80e04, %esi         # imm = 0xB80E04
movl $0x100000, %edx         # imm = 0x100000
callq 0x197e0
testb $0x1, 0x29673(%rip)     # 0x42331
je 0x18cd3
movq -0x20(%rbp), %rdi
movl $0xb80e00, %esi         # imm = 0xB80E00
movl $0x1, %edx
callq 0x197e0
testb $0x1, -0x21(%rbp)
je 0x18e10
movq -0x18(%rbp), %rax
cmpq $0x5, 0xf0(%rax)
je 0x18e10
callq 0x1bd70
movq %rax, %rcx
leaq 0x22bd2(%rip), %rax     # 0x3b8d0
movq (%rax), %r8
xorl %esi, %esi
leaq 0xb815(%rip), %rdx      # 0x2451f
movl %esi, %edi
movb $0x0, %al
callq 0x216e0
movq -0x18(%rbp), %rdi
movl $0x5, %esi
callq 0x21ff0
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4f0(%rax)
je 0x18e0e
movq -0x20(%rbp), %rdi
movl $0xc84004, %esi         # imm = 0xC84004
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1bfd0
movq -0x18(%rbp), %rax
cmpl $0x1, 0x4f4(%rax)
jne 0x18dae
callq 0x1bd70
movq %rax, %rcx
leaq 0x22b6f(%rip), %rax     # 0x3b8d0
movq 0x10(%rax), %r8
movl $0x2, %edi
xorl %esi, %esi
leaq 0xb7bf(%rip), %rdx      # 0x24532
movb $0x0, %al
callq 0x216e0
movq -0x18(%rbp), %rdi
callq 0x21b20
cmpl $0x0, %eax
je 0x18dac
callq 0x1bd70
movq %rax, %rcx
leaq 0x22b39(%rip), %rax     # 0x3b8d0
movq (%rax), %r8
xorl %esi, %esi
leaq 0xb7a7(%rip), %rdx      # 0x2454a
movl %esi, %edi
movb $0x0, %al
callq 0x216e0
jmp 0x18e0a
callq 0x1bd70
movq %rax, %rcx
leaq 0x22b13(%rip), %rax     # 0x3b8d0
movq 0x10(%rax), %r8
movl $0x2, %edi
xorl %esi, %esi
leaq 0xb79a(%rip), %rdx      # 0x24569
movb $0x0, %al
callq 0x216e0
movq -0x18(%rbp), %rdi
callq 0x21d30
cmpl $0x0, %eax
je 0x18e08
callq 0x1bd70
movq %rax, %rcx
leaq 0x22add(%rip), %rax     # 0x3b8d0
movq (%rax), %r8
xorl %esi, %esi
leaq 0xb78c(%rip), %rdx      # 0x2458b
movl %esi, %edi
movb $0x0, %al
callq 0x216e0
jmp 0x18e0a
movb $0x1, -0x22(%rbp)
jmp 0x18e10
testb $0x1, -0x21(%rbp)
je 0x18e3e
testb $0x1, -0x22(%rbp)
jne 0x18e3e
movq -0x20(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x1c000
cmpl $0x1b, -0xc(%rbp)
jne 0x18e3c
movq -0x20(%rbp), %rdi
movl $0x1a, %esi
callq 0x1c000
jmp 0x18e3e
testb $0x1, -0x21(%rbp)
jne 0x18e73
callq 0x1bd70
movq %rax, %rcx
leaq 0x22a7d(%rip), %rax     # 0x3b8d0
movq 0x18(%rax), %r8
movl $0x3, %edi
xorl %esi, %esi
leaq 0xc333(%rip), %rdx      # 0x25198
leaq 0xc349(%rip), %r9       # 0x251b5
movb $0x0, %al
callq 0x216e0
movb -0x22(%rbp), %al
andb $0x1, %al
addq $0x30, %rsp
popq %rbp
retq
nop