1 // SPDX-License-Identifier: GPL-2.0-only
3 * aQuantia Corporation Network Driver
4 * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
7 /* File aq_hw_utils.c: Definitions of helper functions used across
11 #include "aq_hw_utils.h"
15 void aq_hw_write_reg_bit(struct aq_hw_s
*aq_hw
, u32 addr
, u32 msk
,
21 reg_old
= aq_hw_read_reg(aq_hw
, addr
);
22 reg_new
= (reg_old
& (~msk
)) | (val
<< shift
);
24 if (reg_old
!= reg_new
)
25 aq_hw_write_reg(aq_hw
, addr
, reg_new
);
27 aq_hw_write_reg(aq_hw
, addr
, val
);
31 u32
aq_hw_read_reg_bit(struct aq_hw_s
*aq_hw
, u32 addr
, u32 msk
, u32 shift
)
33 return ((aq_hw_read_reg(aq_hw
, addr
) & msk
) >> shift
);
36 u32
aq_hw_read_reg(struct aq_hw_s
*hw
, u32 reg
)
38 u32 value
= readl(hw
->mmio
+ reg
);
41 (~0U) == readl(hw
->mmio
+
42 hw
->aq_nic_cfg
->aq_hw_caps
->hw_alive_check_addr
))
43 aq_utils_obj_set(&hw
->flags
, AQ_HW_FLAG_ERR_UNPLUG
);
48 void aq_hw_write_reg(struct aq_hw_s
*hw
, u32 reg
, u32 value
)
50 writel(value
, hw
->mmio
+ reg
);
53 /* Most of 64-bit registers are in LSW, MSW form.
54 Counters are normally implemented by HW as latched pairs:
55 reading LSW first locks MSW, to overcome LSW overflow
57 u64
aq_hw_read_reg64(struct aq_hw_s
*hw
, u32 reg
)
59 u64 value
= aq_hw_read_reg(hw
, reg
);
61 value
|= (u64
)aq_hw_read_reg(hw
, reg
+ 4) << 32;
66 int aq_hw_err_from_flags(struct aq_hw_s
*hw
)
70 if (aq_utils_obj_test(&hw
->flags
, AQ_HW_FLAG_ERR_UNPLUG
)) {
74 if (aq_utils_obj_test(&hw
->flags
, AQ_HW_FLAG_ERR_HW
)) {