// File: /workspace/github_c_makefile_star2_O3/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 0x1e27b(%rip), %rcx     # 0x327e0
movb 0x9(%rax,%rcx), %al
movb %al, 0xb(%rsp)
movl 0xc84208(%r14), %ebx
leaq 0x1e465(%rip), %r13     # 0x329e0
xorl %ebp, %ebp
leaq 0x7f26(%rip), %r15      # 0x1c4aa
xorl %r12d, %r12d
btl %r12d, %ebx
jae 0x145bc
orb 0x9(%r13), %bpl
callq 0x16674
leaq 0x1f933(%rip), %rcx     # 0x33ed0
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 0x199b4
incq %r12
addq $0x10, %r13
cmpq $0x20, %r12
jne 0x14587
movl 0xc84004(%r14), %ebx
leaq 0x1e609(%rip), %r13     # 0x32be0
leaq 0x7f03(%rip), %r15      # 0x1c4e1
xorl %r12d, %r12d
btl %r12d, %ebx
jae 0x14612
callq 0x16674
leaq 0x1f8dd(%rip), %rcx     # 0x33ed0
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 0x199b4
incq %r12
addq $0x10, %r13
cmpq $0x20, %r12
jne 0x145e1
movl $0x40000, 0xc84004(%r14) # imm = 0x40000
movl $0x1, %edi
callq 0xd450
testl $0x1, 0xb80028(%r14)
je 0x14668
callq 0x16674
leaq 0x1f883(%rip), %rcx     # 0x33ed0
movq (%rcx), %r8
leaq 0x7e71(%rip), %rdx      # 0x1c4c8
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
movb $0x1, %bpl
testl $0x1, 0xb80e08(%r14)
je 0x1469c
callq 0x16674
leaq 0x1f84f(%rip), %rcx     # 0x33ed0
movq (%rcx), %r8
leaq 0x8b5c(%rip), %rdx      # 0x1d1e7
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
movb $0x1, %bpl
movl $0x0, 0xc84204(%r14)
movl $0x1, %edi
callq 0xd450
movl $0x30, 0x810000(%r14)
movl $0x1, %edi
callq 0xd450
movl $0xffffffff, 0xb80800(%r14) # imm = 0xFFFFFFFF
movl $0x1, %edi
callq 0xd450
movl $0x2e03c0, %ebx         # imm = 0x2E03C0
movl $0x200000, (%r14,%rbx,4) # imm = 0x200000
movl $0x1, %edi
callq 0xd450
incq %rbx
cmpq $0x2e03c6, %rbx         # imm = 0x2E03C6
jne 0x146e0
orb 0xb(%rsp), %bpl
movl $0x800, %ebx            # imm = 0x800
movl %ebx, 0xa00040(%r14)
movl $0x1, %edi
callq 0xd450
movl %ebx, 0xa00048(%r14)
movl $0x1, %edi
callq 0xd450
movl $0x10000000, 0xa00050(%r14) # imm = 0x10000000
movl $0x1, %edi
callq 0xd450
movl $0x100000, 0xb80e04(%r14) # imm = 0x100000
movl $0x1, %edi
callq 0xd450
cmpb $0x1, 0x261d6(%rip)     # 0x3a931
jne 0x14772
movl $0x1, 0xb80e00(%r14)
movl $0x1, %edi
callq 0xd450
testb $0x1, %bpl
je 0x1483e
movq 0x10(%rsp), %r15
cmpq $0x5, 0xf0(%r15)
je 0x14871
callq 0x16674
leaq 0x1f735(%rip), %rcx     # 0x33ed0
movq (%rcx), %r8
leaq 0x7d5b(%rip), %rdx      # 0x1c500
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
movq %r15, %rdi
movl $0x5, %esi
callq 0x1a06b
cmpl $0x0, 0x4f0(%r15)
je 0x14871
movl $0xffffffff, 0xc84004(%r14) # imm = 0xFFFFFFFF
movl 0x4f4(%r15), %ebx
callq 0x16674
leaq 0x1f6e4(%rip), %rcx     # 0x33ed0
movq 0x10(%rcx), %r8
cmpl $0x1, %ebx
jne 0x14895
leaq 0x7d13(%rip), %rdx      # 0x1c513
movl $0x2, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
movq %r15, %rdi
callq 0x19cef
movb $0x1, %bl
testl %eax, %eax
je 0x148df
callq 0x16674
leaq 0x1f6a1(%rip), %rcx     # 0x33ed0
movq (%rcx), %r8
leaq 0x7cf2(%rip), %rdx      # 0x1c52b
jmp 0x148d1
callq 0x16674
leaq 0x1f686(%rip), %rcx     # 0x33ed0
movq 0x18(%rcx), %r8
leaq 0x8963(%rip), %rdx      # 0x1d1b8
leaq 0x8979(%rip), %r9       # 0x1d1d5
xorl %ebx, %ebx
movl $0x3, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
jmp 0x148df
movq %r14, %rdi
movl 0xc(%rsp), %ebx
movl %ebx, %esi
callq 0x166be
cmpl $0x1b, %ebx
jne 0x14891
movq %r14, %rdi
movl $0x1a, %esi
callq 0x166be
xorl %ebx, %ebx
jmp 0x148df
leaq 0x7cae(%rip), %rdx      # 0x1c54a
movl $0x2, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
movq %r15, %rdi
callq 0x19e6d
movb $0x1, %bl
testl %eax, %eax
je 0x148df
callq 0x16674
leaq 0x1f609(%rip), %rcx     # 0x33ed0
movq (%rcx), %r8
leaq 0x7c9b(%rip), %rdx      # 0x1c56c
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq