xref: /dpdk/drivers/net/ngbe/ngbe_regs_group.h (revision 71aec12796ccd9ed793cb834d925ff1ab6afad01)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
3  * Copyright(c) 2010-2017 Intel Corporation
4  */
5 
6 #ifndef _NGBE_REGS_GROUP_H_
7 #define _NGBE_REGS_GROUP_H_
8 
9 #include "ngbe_ethdev.h"
10 
11 struct ngbe_hw;
12 struct reg_info {
13 	uint32_t base_addr;
14 	uint32_t count;
15 	uint32_t stride;
16 	const char *name;
17 };
18 
19 static inline int
ngbe_read_regs(struct ngbe_hw * hw,const struct reg_info * reg,uint32_t * reg_buf)20 ngbe_read_regs(struct ngbe_hw *hw, const struct reg_info *reg,
21 	uint32_t *reg_buf)
22 {
23 	unsigned int i;
24 
25 	for (i = 0; i < reg->count; i++)
26 		reg_buf[i] = rd32(hw, reg->base_addr + i * reg->stride);
27 	return reg->count;
28 };
29 
30 static inline int
ngbe_regs_group_count(const struct reg_info * regs)31 ngbe_regs_group_count(const struct reg_info *regs)
32 {
33 	int count = 0;
34 	int i = 0;
35 
36 	while (regs[i].count)
37 		count += regs[i++].count;
38 	return count;
39 };
40 
41 static inline int
ngbe_read_regs_group(struct rte_eth_dev * dev,uint32_t * reg_buf,const struct reg_info * regs)42 ngbe_read_regs_group(struct rte_eth_dev *dev, uint32_t *reg_buf,
43 					  const struct reg_info *regs)
44 {
45 	int count = 0;
46 	int i = 0;
47 	struct ngbe_hw *hw = ngbe_dev_hw(dev);
48 
49 	while (regs[i].count)
50 		count += ngbe_read_regs(hw, &regs[i++], &reg_buf[count]);
51 	return count;
52 };
53 
54 #endif /* _NGBE_REGS_GROUP_H_ */
55