// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
movq 0xb0(%rdi), %r14
movl %esi, 0xc(%rsp)
movl %esi, %eax
shlq $0x4, %rax
leaq 0x1f58f(%rip), %rcx     # 0x337e0
movb 0x9(%rax,%rcx), %al
movb %al, 0xb(%rsp)
movl 0xc84208(%r14), %ebx
leaq 0x1f779(%rip), %r13     # 0x339e0
xorl %ebp, %ebp
leaq 0x81f6(%rip), %r15      # 0x1c466
xorl %r12d, %r12d
cmpq $0x20, %r12
je 0x142b7
btl %r12d, %ebx
jae 0x142ae
orb 0x9(%r13), %bpl
callq 0x16020
leaq 0x20c41(%rip), %rcx     # 0x34ed0
movq (%rcx), %r8
movq (%r13), %rcx
movq %rcx, (%rsp)
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %rax, %rcx
movl %r12d, %r9d
xorl %eax, %eax
callq 0x19400
incq %r12
addq $0x10, %r13
jmp 0x14273
movl 0xc84004(%r14), %ebx
leaq 0x1f91b(%rip), %r13     # 0x33be0
leaq 0x81d1(%rip), %r15      # 0x1c49d
xorl %r12d, %r12d
cmpq $0x20, %r12
je 0x1430f
btl %r12d, %ebx
jae 0x14306
callq 0x16020
leaq 0x20be9(%rip), %rcx     # 0x34ed0
movq (%rcx), %r8
movq (%r13), %rcx
movq %rcx, (%rsp)
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %rax, %rcx
movl %r12d, %r9d
xorl %eax, %eax
callq 0x19400
incq %r12
addq $0x10, %r13
jmp 0x142cf
movl $0x40000, 0xc84004(%r14) # imm = 0x40000
pushq $0x1
popq %rdi
callq 0xd460
testl $0x1, 0xb80028(%r14)
je 0x14356
callq 0x16020
leaq 0x20b95(%rip), %rcx     # 0x34ed0
movq (%rcx), %r8
leaq 0x813f(%rip), %rdx      # 0x1c484
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
movb $0x1, %bpl
testl $0x1, 0xb80e08(%r14)
je 0x1438a
callq 0x16020
leaq 0x20b61(%rip), %rcx     # 0x34ed0
movq (%rcx), %r8
leaq 0x8e1e(%rip), %rdx      # 0x1d197
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
movb $0x1, %bpl
movl $0x0, 0xc84204(%r14)
pushq $0x1
popq %r15
movl %r15d, %edi
callq 0xd460
movl $0x30, 0x810000(%r14)
movl %r15d, %edi
callq 0xd460
movl $0xffffffff, 0xb80800(%r14) # imm = 0xFFFFFFFF
movl %r15d, %edi
callq 0xd460
movl $0x2e03c0, %ebx         # imm = 0x2E03C0
cmpq $0x2e03c6, %rbx         # imm = 0x2E03C6
je 0x143ea
movl $0x200000, (%r14,%rbx,4) # imm = 0x200000
movl %r15d, %edi
callq 0xd460
incq %rbx
jmp 0x143cc
orb 0xb(%rsp), %bpl
movl $0x800, %ebx            # imm = 0x800
movl %ebx, 0xa00040(%r14)
pushq $0x1
popq %r15
movl %r15d, %edi
callq 0xd460
movl %ebx, 0xa00048(%r14)
movl %r15d, %edi
callq 0xd460
movl $0x10000000, 0xa00050(%r14) # imm = 0x10000000
movl %r15d, %edi
callq 0xd460
movl $0x100000, 0xb80e04(%r14) # imm = 0x100000
movl %r15d, %edi
callq 0xd460
cmpb $0x1, 0x274ee(%rip)     # 0x3b931
jne 0x14458
movl $0x1, 0xb80e00(%r14)
pushq $0x1
popq %rdi
callq 0xd460
testb $0x1, %bpl
je 0x14520
movq 0x10(%rsp), %r15
cmpq $0x5, 0xf0(%r15)
je 0x14551
callq 0x16020
leaq 0x20a4f(%rip), %rcx     # 0x34ed0
movq (%rcx), %r8
leaq 0x8031(%rip), %rdx      # 0x1c4bc
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
pushq $0x5
popq %rsi
movq %r15, %rdi
callq 0x19a78
cmpl $0x0, 0x4f0(%r15)
je 0x14551
movl $0xffffffff, 0xc84004(%r14) # imm = 0xFFFFFFFF
movl 0x4f4(%r15), %ebx
callq 0x16020
leaq 0x20a00(%rip), %rcx     # 0x34ed0
movq 0x10(%rcx), %r8
cmpl $0x1, %ebx
jne 0x14573
leaq 0x7feb(%rip), %rdx      # 0x1c4cf
pushq $0x2
popq %rdi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
movq %r15, %rdi
callq 0x19737
movb $0x1, %bl
testl %eax, %eax
je 0x145bb
callq 0x16020
leaq 0x209bf(%rip), %rcx     # 0x34ed0
movq (%rcx), %r8
leaq 0x7fcc(%rip), %rdx      # 0x1c4e7
jmp 0x145ad
callq 0x16020
leaq 0x209a4(%rip), %rcx     # 0x34ed0
movq 0x18(%rcx), %r8
leaq 0x8c31(%rip), %rdx      # 0x1d168
leaq 0x8c47(%rip), %r9       # 0x1d185
xorl %ebx, %ebx
pushq $0x3
popq %rdi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
jmp 0x145bb
movq %r14, %rdi
movl 0xc(%rsp), %ebx
movl %ebx, %esi
callq 0x1606a
cmpl $0x1b, %ebx
jne 0x1456f
pushq $0x1a
popq %rsi
movq %r14, %rdi
callq 0x1606a
xorl %ebx, %ebx
jmp 0x145bb
leaq 0x7f8c(%rip), %rdx      # 0x1c506
pushq $0x2
popq %rdi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
movq %r15, %rdi
callq 0x1988f
movb $0x1, %bl
testl %eax, %eax
je 0x145bb
callq 0x16020
leaq 0x2092d(%rip), %rcx     # 0x34ed0
movq (%rcx), %r8
leaq 0x7f7b(%rip), %rdx      # 0x1c528
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq