New upstream version 18.11-rc1
[deb_dpdk.git] / drivers / net / atlantic / atl_hw_regs.h
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) */
2 /* Copyright (C) 2014-2017 aQuantia Corporation. */
3
4 /* File aq_hw_utils.h: Declaration of helper functions used across hardware
5  * layer.
6  */
7
8 #ifndef AQ_HW_UTILS_H
9 #define AQ_HW_UTILS_H
10
11 #include <rte_common.h>
12 #include <rte_io.h>
13 #include <rte_byteorder.h>
14 #include <rte_random.h>
15 #include <rte_cycles.h>
16 #include "atl_common.h"
17 #include "atl_types.h"
18
19
20 #ifndef HIDWORD
21 #define LODWORD(_qw)    ((u32)(_qw))
22 #define HIDWORD(_qw)    ((u32)(((_qw) >> 32) & 0xffffffff))
23 #endif
24
25 #define AQ_HW_SLEEP(_US_) rte_delay_ms(_US_)
26
27 #define mdelay rte_delay_ms
28 #define udelay rte_delay_us
29 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
30 #define BIT(x)  (1UL << (x))
31
32 #define AQ_HW_WAIT_FOR(_B_, _US_, _N_) \
33 do { \
34         unsigned int AQ_HW_WAIT_FOR_i; \
35         for (AQ_HW_WAIT_FOR_i = _N_; (!(_B_)) && (AQ_HW_WAIT_FOR_i);\
36         --AQ_HW_WAIT_FOR_i) {\
37                 udelay(_US_); \
38         } \
39         if (!AQ_HW_WAIT_FOR_i) {\
40                 err = -ETIMEDOUT; \
41         } \
42 } while (0)
43
44 #define ATL_WRITE_FLUSH(aq_hw) { (void)aq_hw_read_reg(aq_hw, 0x10); }
45
46 void aq_hw_write_reg_bit(struct aq_hw_s *aq_hw, u32 addr, u32 msk,
47                          u32 shift, u32 val);
48 u32 aq_hw_read_reg_bit(struct aq_hw_s *aq_hw, u32 addr, u32 msk, u32 shift);
49 u32 aq_hw_read_reg(struct aq_hw_s *hw, u32 reg);
50 void aq_hw_write_reg(struct aq_hw_s *hw, u32 reg, u32 value);
51 int aq_hw_err_from_flags(struct aq_hw_s *hw);
52
53 #endif /* AQ_HW_UTILS_H */