/* SPDX-License-Identifier: ISC */1/*2* Copyright (c) 2005-2011 Atheros Communications Inc.3* Copyright (c) 2011-2017 Qualcomm Atheros, Inc.4*/56#ifndef _PCI_H_7#define _PCI_H_89#include <linux/interrupt.h>10#include <linux/mutex.h>1112#include "hw.h"13#include "ce.h"14#include "ahb.h"1516/*17* maximum number of bytes that can be18* handled atomically by DiagRead/DiagWrite19*/20#define DIAG_TRANSFER_LIMIT 20482122struct bmi_xfer {23bool tx_done;24bool rx_done;25bool wait_for_resp;26u32 resp_len;27};2829/*30* PCI-specific Target state31*32* NOTE: Structure is shared between Host software and Target firmware!33*34* Much of this may be of interest to the Host so35* HOST_INTEREST->hi_interconnect_state points here36* (and all members are 32-bit quantities in order to37* facilitate Host access). In particular, Host software is38* required to initialize pipe_cfg_addr and svc_to_pipe_map.39*/40struct pcie_state {41/* Pipe configuration Target address */42/* NB: ce_pipe_config[CE_COUNT] */43u32 pipe_cfg_addr;4445/* Service to pipe map Target address */46/* NB: service_to_pipe[PIPE_TO_CE_MAP_CN] */47u32 svc_to_pipe_map;4849/* number of MSI interrupts requested */50u32 msi_requested;5152/* number of MSI interrupts granted */53u32 msi_granted;5455/* Message Signalled Interrupt address */56u32 msi_addr;5758/* Base data */59u32 msi_data;6061/*62* Data for firmware interrupt;63* MSI data for other interrupts are64* in various SoC registers65*/66u32 msi_fw_intr_data;6768/* PCIE_PWR_METHOD_* */69u32 power_mgmt_method;7071/* PCIE_CONFIG_FLAG_* */72u32 config_flags;73};7475/* PCIE_CONFIG_FLAG definitions */76#define PCIE_CONFIG_FLAG_ENABLE_L1 0x00000017778/* Per-pipe state. */79struct ath10k_pci_pipe {80/* Handle of underlying Copy Engine */81struct ath10k_ce_pipe *ce_hdl;8283/* Our pipe number; facilitates use of pipe_info ptrs. */84u8 pipe_num;8586/* Convenience back pointer to hif_ce_state. */87struct ath10k *hif_ce_state;8889size_t buf_sz;9091/* protects compl_free and num_send_allowed */92spinlock_t pipe_lock;93};9495struct ath10k_pci_supp_chip {96u32 dev_id;97u32 rev_id;98};99100enum ath10k_pci_irq_mode {101ATH10K_PCI_IRQ_AUTO = 0,102ATH10K_PCI_IRQ_LEGACY = 1,103ATH10K_PCI_IRQ_MSI = 2,104};105106struct ath10k_pci {107struct pci_dev *pdev;108struct device *dev;109struct ath10k *ar;110void __iomem *mem;111size_t mem_len;112113/* Operating interrupt mode */114enum ath10k_pci_irq_mode oper_irq_mode;115116struct ath10k_pci_pipe pipe_info[CE_COUNT_MAX];117118/* Copy Engine used for Diagnostic Accesses */119struct ath10k_ce_pipe *ce_diag;120/* For protecting ce_diag */121struct mutex ce_diag_mutex;122123struct work_struct dump_work;124125struct ath10k_ce ce;126struct timer_list rx_post_retry;127128/* Due to HW quirks it is recommended to disable ASPM during device129* bootup. To do that the original PCI-E Link Control is stored before130* device bootup is executed and re-programmed later.131*/132u16 link_ctl;133134/* Protects ps_awake and ps_wake_refcount */135spinlock_t ps_lock;136137/* The device has a special powersave-oriented register. When device is138* considered asleep it drains less power and driver is forbidden from139* accessing most MMIO registers. If host were to access them without140* waking up the device might scribble over host memory or return141* 0xdeadbeef readouts.142*/143unsigned long ps_wake_refcount;144145/* Waking up takes some time (up to 2ms in some cases) so it can be bad146* for latency. To mitigate this the device isn't immediately allowed147* to sleep after all references are undone - instead there's a grace148* period after which the powersave register is updated unless some149* activity to/from device happened in the meantime.150*151* Also see comments on ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC.152*/153struct timer_list ps_timer;154155/* MMIO registers are used to communicate with the device. With156* intensive traffic accessing powersave register would be a bit157* wasteful overhead and would needlessly stall CPU. It is far more158* efficient to rely on a variable in RAM and update it only upon159* powersave register state changes.160*/161bool ps_awake;162163/* pci power save, disable for QCA988X and QCA99X0.164* Writing 'false' to this variable avoids frequent locking165* on MMIO read/write.166*/167bool pci_ps;168169/* Chip specific pci reset routine used to do a safe reset */170int (*pci_soft_reset)(struct ath10k *ar);171172/* Chip specific pci full reset function */173int (*pci_hard_reset)(struct ath10k *ar);174175/* chip specific methods for converting target CPU virtual address176* space to CE address space177*/178u32 (*targ_cpu_to_ce_addr)(struct ath10k *ar, u32 addr);179180struct ce_attr *attr;181struct ce_pipe_config *pipe_config;182struct ce_service_to_pipe *serv_to_pipe;183184/* Keep this entry in the last, memory for struct ath10k_ahb is185* allocated (ahb support enabled case) in the continuation of186* this struct.187*/188struct ath10k_ahb ahb[];189190};191192static inline struct ath10k_pci *ath10k_pci_priv(struct ath10k *ar)193{194return (struct ath10k_pci *)ar->drv_priv;195}196197#define ATH10K_PCI_RX_POST_RETRY_MS 50198#define ATH_PCI_RESET_WAIT_MAX 10 /* ms */199#define PCIE_WAKE_TIMEOUT 30000 /* 30ms */200#define PCIE_WAKE_LATE_US 10000 /* 10ms */201202#define BAR_NUM 0203204#define CDC_WAR_MAGIC_STR 0xceef0000205#define CDC_WAR_DATA_CE 4206207/* Wait up to this many Ms for a Diagnostic Access CE operation to complete */208#define DIAG_ACCESS_CE_TIMEOUT_US 10000 /* 10 ms */209#define DIAG_ACCESS_CE_WAIT_US 50210211void ath10k_pci_write32(struct ath10k *ar, u32 offset, u32 value);212void ath10k_pci_soc_write32(struct ath10k *ar, u32 addr, u32 val);213void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val);214215u32 ath10k_pci_read32(struct ath10k *ar, u32 offset);216u32 ath10k_pci_soc_read32(struct ath10k *ar, u32 addr);217u32 ath10k_pci_reg_read32(struct ath10k *ar, u32 addr);218219int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,220struct ath10k_hif_sg_item *items, int n_items);221int ath10k_pci_hif_diag_read(struct ath10k *ar, u32 address, void *buf,222size_t buf_len);223int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,224const void *data, int nbytes);225int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar, void *req, u32 req_len,226void *resp, u32 *resp_len);227int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, u16 service_id,228u8 *ul_pipe, u8 *dl_pipe);229void ath10k_pci_hif_get_default_pipe(struct ath10k *ar, u8 *ul_pipe,230u8 *dl_pipe);231void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe,232int force);233u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe);234void ath10k_pci_hif_power_down(struct ath10k *ar);235int ath10k_pci_alloc_pipes(struct ath10k *ar);236void ath10k_pci_free_pipes(struct ath10k *ar);237void ath10k_pci_rx_replenish_retry(struct timer_list *t);238void ath10k_pci_ce_deinit(struct ath10k *ar);239void ath10k_pci_init_napi(struct ath10k *ar);240int ath10k_pci_init_pipes(struct ath10k *ar);241int ath10k_pci_init_config(struct ath10k *ar);242void ath10k_pci_rx_post(struct ath10k *ar);243void ath10k_pci_flush(struct ath10k *ar);244void ath10k_pci_enable_legacy_irq(struct ath10k *ar);245bool ath10k_pci_irq_pending(struct ath10k *ar);246void ath10k_pci_disable_and_clear_legacy_irq(struct ath10k *ar);247void ath10k_pci_irq_msi_fw_mask(struct ath10k *ar);248int ath10k_pci_wait_for_target_init(struct ath10k *ar);249int ath10k_pci_setup_resource(struct ath10k *ar);250void ath10k_pci_release_resource(struct ath10k *ar);251252/* QCA6174 is known to have Tx/Rx issues when SOC_WAKE register is poked too253* frequently. To avoid this put SoC to sleep after a very conservative grace254* period. Adjust with great care.255*/256#define ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC 60257258#endif /* _PCI_H_ */259260261