162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#ifndef _IONIC_STATS_H_
562306a36Sopenharmony_ci#define _IONIC_STATS_H_
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#define IONIC_STAT_TO_OFFSET(type, stat_name) (offsetof(type, stat_name))
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#define IONIC_STAT_DESC(type, stat_name) { \
1062306a36Sopenharmony_ci	.name = #stat_name, \
1162306a36Sopenharmony_ci	.offset = IONIC_STAT_TO_OFFSET(type, stat_name) \
1262306a36Sopenharmony_ci}
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#define IONIC_PORT_STAT_DESC(stat_name) \
1562306a36Sopenharmony_ci	IONIC_STAT_DESC(struct ionic_port_stats, stat_name)
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#define IONIC_LIF_STAT_DESC(stat_name) \
1862306a36Sopenharmony_ci	IONIC_STAT_DESC(struct ionic_lif_sw_stats, stat_name)
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#define IONIC_TX_STAT_DESC(stat_name) \
2162306a36Sopenharmony_ci	IONIC_STAT_DESC(struct ionic_tx_stats, stat_name)
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci#define IONIC_RX_STAT_DESC(stat_name) \
2462306a36Sopenharmony_ci	IONIC_STAT_DESC(struct ionic_rx_stats, stat_name)
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define IONIC_TX_Q_STAT_DESC(stat_name) \
2762306a36Sopenharmony_ci	IONIC_STAT_DESC(struct ionic_queue, stat_name)
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci#define IONIC_CQ_STAT_DESC(stat_name) \
3062306a36Sopenharmony_ci	IONIC_STAT_DESC(struct ionic_cq, stat_name)
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define IONIC_INTR_STAT_DESC(stat_name) \
3362306a36Sopenharmony_ci	IONIC_STAT_DESC(struct ionic_intr_info, stat_name)
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define IONIC_NAPI_STAT_DESC(stat_name) \
3662306a36Sopenharmony_ci	IONIC_STAT_DESC(struct ionic_napi_stats, stat_name)
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci/* Interface structure for a particalar stats group */
3962306a36Sopenharmony_cistruct ionic_stats_group_intf {
4062306a36Sopenharmony_ci	void (*get_strings)(struct ionic_lif *lif, u8 **buf);
4162306a36Sopenharmony_ci	void (*get_values)(struct ionic_lif *lif, u64 **buf);
4262306a36Sopenharmony_ci	u64 (*get_count)(struct ionic_lif *lif);
4362306a36Sopenharmony_ci};
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ciextern const struct ionic_stats_group_intf ionic_stats_groups[];
4662306a36Sopenharmony_ciextern const int ionic_num_stats_grps;
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#define IONIC_READ_STAT64(base_ptr, desc_ptr) \
4962306a36Sopenharmony_ci	(*((u64 *)(((u8 *)(base_ptr)) + (desc_ptr)->offset)))
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#define IONIC_READ_STAT_LE64(base_ptr, desc_ptr) \
5262306a36Sopenharmony_ci	__le64_to_cpu(*((__le64 *)(((u8 *)(base_ptr)) + (desc_ptr)->offset)))
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistruct ionic_stat_desc {
5562306a36Sopenharmony_ci	char name[ETH_GSTRING_LEN];
5662306a36Sopenharmony_ci	u64 offset;
5762306a36Sopenharmony_ci};
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#endif /* _IONIC_STATS_H_ */
60