gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / net / ethernet / aquantia / atlantic / aq_hw_utils.c
blob7dbf49adcea6c0436d1fcba5f68a49de01ea3c27
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * aQuantia Corporation Network Driver
4 * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
5 */
7 /* File aq_hw_utils.c: Definitions of helper functions used across
8 * hardware layer.
9 */
11 #include "aq_hw_utils.h"
12 #include "aq_hw.h"
13 #include "aq_nic.h"
15 void aq_hw_write_reg_bit(struct aq_hw_s *aq_hw, u32 addr, u32 msk,
16 u32 shift, u32 val)
18 if (msk ^ ~0) {
19 u32 reg_old, reg_new;
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);
26 } else {
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);
40 if ((~0U) == value &&
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);
45 return value;
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;
63 return value;
66 int aq_hw_err_from_flags(struct aq_hw_s *hw)
68 int err = 0;
70 if (aq_utils_obj_test(&hw->flags, AQ_HW_FLAG_ERR_UNPLUG)) {
71 err = -ENXIO;
72 goto err_exit;
74 if (aq_utils_obj_test(&hw->flags, AQ_HW_FLAG_ERR_HW)) {
75 err = -EIO;
76 goto err_exit;
79 err_exit:
80 return err;