18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Copyright(c) 2013 - 2018 Intel Corporation. */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef _FM10K_COMMON_H_
58c2ecf20Sopenharmony_ci#define _FM10K_COMMON_H_
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include "fm10k_type.h"
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define FM10K_REMOVED(hw_addr) unlikely(!(hw_addr))
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/* PCI configuration read */
128c2ecf20Sopenharmony_ciu16 fm10k_read_pci_cfg_word(struct fm10k_hw *hw, u32 reg);
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/* read operations, indexed using DWORDS */
158c2ecf20Sopenharmony_ciu32 fm10k_read_reg(struct fm10k_hw *hw, int reg);
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* write operations, indexed using DWORDS */
188c2ecf20Sopenharmony_ci#define fm10k_write_reg(hw, reg, val) \
198c2ecf20Sopenharmony_cido { \
208c2ecf20Sopenharmony_ci	u32 __iomem *hw_addr = READ_ONCE((hw)->hw_addr); \
218c2ecf20Sopenharmony_ci	if (!FM10K_REMOVED(hw_addr)) \
228c2ecf20Sopenharmony_ci		writel((val), &hw_addr[(reg)]); \
238c2ecf20Sopenharmony_ci} while (0)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* Switch register write operations, index using DWORDS */
268c2ecf20Sopenharmony_ci#define fm10k_write_sw_reg(hw, reg, val) \
278c2ecf20Sopenharmony_cido { \
288c2ecf20Sopenharmony_ci	u32 __iomem *sw_addr = READ_ONCE((hw)->sw_addr); \
298c2ecf20Sopenharmony_ci	if (!FM10K_REMOVED(sw_addr)) \
308c2ecf20Sopenharmony_ci		writel((val), &sw_addr[(reg)]); \
318c2ecf20Sopenharmony_ci} while (0)
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/* read ctrl register which has no clear on read fields as PCIe flush */
348c2ecf20Sopenharmony_ci#define fm10k_write_flush(hw) fm10k_read_reg((hw), FM10K_CTRL)
358c2ecf20Sopenharmony_cis32 fm10k_get_bus_info_generic(struct fm10k_hw *hw);
368c2ecf20Sopenharmony_cis32 fm10k_get_invariants_generic(struct fm10k_hw *hw);
378c2ecf20Sopenharmony_cis32 fm10k_disable_queues_generic(struct fm10k_hw *hw, u16 q_cnt);
388c2ecf20Sopenharmony_cis32 fm10k_start_hw_generic(struct fm10k_hw *hw);
398c2ecf20Sopenharmony_cis32 fm10k_stop_hw_generic(struct fm10k_hw *hw);
408c2ecf20Sopenharmony_ciu32 fm10k_read_hw_stats_32b(struct fm10k_hw *hw, u32 addr,
418c2ecf20Sopenharmony_ci			    struct fm10k_hw_stat *stat);
428c2ecf20Sopenharmony_ci#define fm10k_update_hw_base_32b(stat, delta) ((stat)->base_l += (delta))
438c2ecf20Sopenharmony_civoid fm10k_update_hw_stats_q(struct fm10k_hw *hw, struct fm10k_hw_stats_q *q,
448c2ecf20Sopenharmony_ci			     u32 idx, u32 count);
458c2ecf20Sopenharmony_ci#define fm10k_unbind_hw_stats_32b(s) ((s)->base_h = 0)
468c2ecf20Sopenharmony_civoid fm10k_unbind_hw_stats_q(struct fm10k_hw_stats_q *q, u32 idx, u32 count);
478c2ecf20Sopenharmony_cis32 fm10k_get_host_state_generic(struct fm10k_hw *hw, bool *host_ready);
488c2ecf20Sopenharmony_ci#endif /* _FM10K_COMMON_H_ */
49