]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/dpdk/drivers/net/atlantic/atl_hw_regs.c
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / dpdk / drivers / net / atlantic / atl_hw_regs.c
1 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2 /* Copyright (C) 2014-2017 aQuantia Corporation. */
3
4 /* File aq_hw_utils.c: Definitions of helper functions used across
5 * hardware layer.
6 */
7
8 #include "atl_hw_regs.h"
9
10 #include <rte_io.h>
11 #include <rte_byteorder.h>
12
13 void aq_hw_write_reg_bit(struct aq_hw_s *aq_hw, u32 addr, u32 msk,
14 u32 shift, u32 val)
15 {
16 if (msk ^ ~0) {
17 u32 reg_old, reg_new;
18
19 reg_old = aq_hw_read_reg(aq_hw, addr);
20 reg_new = (reg_old & (~msk)) | (val << shift);
21
22 if (reg_old != reg_new)
23 aq_hw_write_reg(aq_hw, addr, reg_new);
24 } else {
25 aq_hw_write_reg(aq_hw, addr, val);
26 }
27 }
28
29 u32 aq_hw_read_reg_bit(struct aq_hw_s *aq_hw, u32 addr, u32 msk, u32 shift)
30 {
31 return ((aq_hw_read_reg(aq_hw, addr) & msk) >> shift);
32 }
33
34 u32 aq_hw_read_reg(struct aq_hw_s *hw, u32 reg)
35 {
36 return rte_le_to_cpu_32(rte_read32((u8 *)hw->mmio + reg));
37 }
38
39 void aq_hw_write_reg(struct aq_hw_s *hw, u32 reg, u32 value)
40 {
41 rte_write32((rte_cpu_to_le_32(value)), (u8 *)hw->mmio + reg);
42 }
43
44 int aq_hw_err_from_flags(struct aq_hw_s *hw)
45 {
46 int err = 0;
47
48 if (aq_hw_read_reg(hw, 0x10U) == ~0U)
49 return -ENXIO;
50
51 return err;
52 }