xref: /dpdk/drivers/net/atlantic/atl_hw_regs.h (revision 72b452c5f2599f970f47fd17d3e8e5d60bfebe7a)
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 <errno.h>
12 #include <rte_common.h>
13 #include <rte_io.h>
14 #include <rte_byteorder.h>
15 #include <rte_random.h>
16 #include <rte_cycles.h>
17 #include "atl_common.h"
18 #include "atl_types.h"
19 
20 
21 #ifndef HIDWORD
22 #define LODWORD(_qw)    ((u32)(_qw))
23 #define HIDWORD(_qw)    ((u32)(((_qw) >> 32) & 0xffffffff))
24 #endif
25 
26 #define AQ_HW_SLEEP(_US_) rte_delay_ms(_US_)
27 
28 #define mdelay rte_delay_ms
29 #define udelay rte_delay_us
30 #define ARRAY_SIZE(arr) RTE_DIM(arr)
31 #define BIT(x)	(1UL << (x))
32 
33 #define AQ_HW_WAIT_FOR(_B_, _US_, _N_) \
34 do { \
35 	unsigned int AQ_HW_WAIT_FOR_i; \
36 	for (AQ_HW_WAIT_FOR_i = _N_; (!(_B_)) && (AQ_HW_WAIT_FOR_i);\
37 	--AQ_HW_WAIT_FOR_i) {\
38 		udelay(_US_); \
39 	} \
40 	if (!AQ_HW_WAIT_FOR_i) {\
41 		err = -ETIMEDOUT; \
42 	} \
43 } while (0)
44 
45 #define ATL_WRITE_FLUSH(aq_hw) { (void)aq_hw_read_reg(aq_hw, 0x10); }
46 
47 void aq_hw_write_reg_bit(struct aq_hw_s *aq_hw, u32 addr, u32 msk,
48 			 u32 shift, u32 val);
49 u32 aq_hw_read_reg_bit(struct aq_hw_s *aq_hw, u32 addr, u32 msk, u32 shift);
50 u32 aq_hw_read_reg(struct aq_hw_s *hw, u32 reg);
51 void aq_hw_write_reg(struct aq_hw_s *hw, u32 reg, u32 value);
52 int aq_hw_err_from_flags(struct aq_hw_s *hw);
53 
54 #endif /* AQ_HW_UTILS_H */
55