2 * aQuantia Corporation Network Driver
3 * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
10 /* File aq_hw_utils.c: Definitions of helper functions used across
14 #include "aq_hw_utils.h"
17 void aq_hw_write_reg_bit(struct aq_hw_s *aq_hw, u32 addr, u32 msk,
23 reg_old = aq_hw_read_reg(aq_hw, addr);
24 reg_new = (reg_old & (~msk)) | (val << shift);
26 if (reg_old != reg_new)
27 aq_hw_write_reg(aq_hw, addr, reg_new);
29 aq_hw_write_reg(aq_hw, addr, val);
33 u32 aq_hw_read_reg_bit(struct aq_hw_s *aq_hw, u32 addr, u32 msk, u32 shift)
35 return ((aq_hw_read_reg(aq_hw, addr) & msk) >> shift);
38 u32 aq_hw_read_reg(struct aq_hw_s *hw, u32 reg)
40 u32 value = readl(hw->mmio + reg);
42 if ((~0U) == value && (~0U) == readl(hw->mmio + hw->not_ff_addr))
43 aq_utils_obj_set(&hw->header.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 int aq_hw_err_from_flags(struct aq_hw_s *hw)
57 if (aq_utils_obj_test(&hw->header.flags, AQ_HW_FLAG_ERR_UNPLUG)) {
61 if (aq_utils_obj_test(&hw->header.flags, AQ_HW_FLAG_ERR_HW)) {