Path: blob/main/sys/contrib/dev/athk/ath10k/pci.h
107436 views
/* SPDX-License-Identifier: ISC */1/*2* Copyright (c) 2005-2011 Atheros Communications Inc.3* Copyright (c) 2011-2017 Qualcomm Atheros, Inc.4* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.5*/67#ifndef _PCI_H_8#define _PCI_H_910#include <linux/interrupt.h>11#include <linux/mutex.h>1213#include "hw.h"14#include "ce.h"15#include "ahb.h"1617/*18* maximum number of bytes that can be19* handled atomically by DiagRead/DiagWrite20*/21#define DIAG_TRANSFER_LIMIT 20482223struct bmi_xfer {24bool tx_done;25bool rx_done;26bool wait_for_resp;27u32 resp_len;28};2930/*31* PCI-specific Target state32*33* NOTE: Structure is shared between Host software and Target firmware!34*35* Much of this may be of interest to the Host so36* HOST_INTEREST->hi_interconnect_state points here37* (and all members are 32-bit quantities in order to38* facilitate Host access). In particular, Host software is39* required to initialize pipe_cfg_addr and svc_to_pipe_map.40*/41struct pcie_state {42/* Pipe configuration Target address */43/* NB: ce_pipe_config[CE_COUNT] */44u32 pipe_cfg_addr;4546/* Service to pipe map Target address */47/* NB: service_to_pipe[PIPE_TO_CE_MAP_CN] */48u32 svc_to_pipe_map;4950/* number of MSI interrupts requested */51u32 msi_requested;5253/* number of MSI interrupts granted */54u32 msi_granted;5556/* Message Signalled Interrupt address */57u32 msi_addr;5859/* Base data */60u32 msi_data;6162/*63* Data for firmware interrupt;64* MSI data for other interrupts are65* in various SoC registers66*/67u32 msi_fw_intr_data;6869/* PCIE_PWR_METHOD_* */70u32 power_mgmt_method;7172/* PCIE_CONFIG_FLAG_* */73u32 config_flags;74};7576/* PCIE_CONFIG_FLAG definitions */77#define PCIE_CONFIG_FLAG_ENABLE_L1 0x00000017879/* Per-pipe state. */80struct ath10k_pci_pipe {81/* Handle of underlying Copy Engine */82struct ath10k_ce_pipe *ce_hdl;8384/* Our pipe number; facilitates use of pipe_info ptrs. */85u8 pipe_num;8687/* Convenience back pointer to hif_ce_state. */88struct ath10k *hif_ce_state;8990size_t buf_sz;9192/* protects compl_free and num_send_allowed */93spinlock_t pipe_lock;94};9596struct ath10k_pci_supp_chip {97u32 dev_id;98u32 rev_id;99};100101enum ath10k_pci_irq_mode {102ATH10K_PCI_IRQ_AUTO = 0,103ATH10K_PCI_IRQ_INTX = 1,104ATH10K_PCI_IRQ_MSI = 2,105};106107struct ath10k_pci {108struct pci_dev *pdev;109struct device *dev;110struct ath10k *ar;111void __iomem *mem;112size_t mem_len;113114/* Operating interrupt mode */115enum ath10k_pci_irq_mode oper_irq_mode;116117struct ath10k_pci_pipe pipe_info[CE_COUNT_MAX];118119/* Copy Engine used for Diagnostic Accesses */120struct ath10k_ce_pipe *ce_diag;121/* For protecting ce_diag */122struct mutex ce_diag_mutex;123124struct work_struct dump_work;125126struct ath10k_ce ce;127struct timer_list rx_post_retry;128129/* Due to HW quirks it is recommended to disable ASPM during device130* bootup. To do that the original PCI-E Link Control is stored before131* device bootup is executed and re-programmed later.132*/133u16 link_ctl;134135/* Protects ps_awake and ps_wake_refcount */136spinlock_t ps_lock;137138/* The device has a special powersave-oriented register. When device is139* considered asleep it drains less power and driver is forbidden from140* accessing most MMIO registers. If host were to access them without141* waking up the device might scribble over host memory or return142* 0xdeadbeef readouts.143*/144unsigned long ps_wake_refcount;145146/* Waking up takes some time (up to 2ms in some cases) so it can be bad147* for latency. To mitigate this the device isn't immediately allowed148* to sleep after all references are undone - instead there's a grace149* period after which the powersave register is updated unless some150* activity to/from device happened in the meantime.151*152* Also see comments on ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC.153*/154struct timer_list ps_timer;155156/* MMIO registers are used to communicate with the device. With157* intensive traffic accessing powersave register would be a bit158* wasteful overhead and would needlessly stall CPU. It is far more159* efficient to rely on a variable in RAM and update it only upon160* powersave register state changes.161*/162bool ps_awake;163164/* pci power save, disable for QCA988X and QCA99X0.165* Writing 'false' to this variable avoids frequent locking166* on MMIO read/write.167*/168bool pci_ps;169170/* Chip specific pci reset routine used to do a safe reset */171int (*pci_soft_reset)(struct ath10k *ar);172173/* Chip specific pci full reset function */174int (*pci_hard_reset)(struct ath10k *ar);175176/* chip specific methods for converting target CPU virtual address177* space to CE address space178*/179u32 (*targ_cpu_to_ce_addr)(struct ath10k *ar, u32 addr);180181struct ce_attr *attr;182struct ce_pipe_config *pipe_config;183struct ce_service_to_pipe *serv_to_pipe;184185/* Keep this entry in the last, memory for struct ath10k_ahb is186* allocated (ahb support enabled case) in the continuation of187* this struct.188*/189struct ath10k_ahb ahb[];190191};192193static inline struct ath10k_pci *ath10k_pci_priv(struct ath10k *ar)194{195return (struct ath10k_pci *)ar->drv_priv;196}197198#define ATH10K_PCI_RX_POST_RETRY_MS 50199#define ATH_PCI_RESET_WAIT_MAX 10 /* ms */200#define PCIE_WAKE_TIMEOUT 30000 /* 30ms */201#define PCIE_WAKE_LATE_US 10000 /* 10ms */202203#define BAR_NUM 0204205#define CDC_WAR_MAGIC_STR 0xceef0000206#define CDC_WAR_DATA_CE 4207208/* Wait up to this many Ms for a Diagnostic Access CE operation to complete */209#define DIAG_ACCESS_CE_TIMEOUT_US 10000 /* 10 ms */210#define DIAG_ACCESS_CE_WAIT_US 50211212void ath10k_pci_write32(struct ath10k *ar, u32 offset, u32 value);213void ath10k_pci_soc_write32(struct ath10k *ar, u32 addr, u32 val);214void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val);215216u32 ath10k_pci_read32(struct ath10k *ar, u32 offset);217u32 ath10k_pci_soc_read32(struct ath10k *ar, u32 addr);218u32 ath10k_pci_reg_read32(struct ath10k *ar, u32 addr);219220int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,221struct ath10k_hif_sg_item *items, int n_items);222int ath10k_pci_hif_diag_read(struct ath10k *ar, u32 address, void *buf,223size_t buf_len);224int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,225const void *data, int nbytes);226int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar, void *req, u32 req_len,227void *resp, u32 *resp_len);228int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, u16 service_id,229u8 *ul_pipe, u8 *dl_pipe);230void ath10k_pci_hif_get_default_pipe(struct ath10k *ar, u8 *ul_pipe,231u8 *dl_pipe);232void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe,233int force);234u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe);235void ath10k_pci_hif_power_down(struct ath10k *ar);236int ath10k_pci_alloc_pipes(struct ath10k *ar);237void ath10k_pci_free_pipes(struct ath10k *ar);238void ath10k_pci_rx_replenish_retry(struct timer_list *t);239void ath10k_pci_ce_deinit(struct ath10k *ar);240void ath10k_pci_init_napi(struct ath10k *ar);241int ath10k_pci_init_pipes(struct ath10k *ar);242int ath10k_pci_init_config(struct ath10k *ar);243void ath10k_pci_rx_post(struct ath10k *ar);244void ath10k_pci_flush(struct ath10k *ar);245void ath10k_pci_enable_intx_irq(struct ath10k *ar);246bool ath10k_pci_irq_pending(struct ath10k *ar);247void ath10k_pci_disable_and_clear_intx_irq(struct ath10k *ar);248void ath10k_pci_irq_msi_fw_mask(struct ath10k *ar);249int ath10k_pci_wait_for_target_init(struct ath10k *ar);250int ath10k_pci_setup_resource(struct ath10k *ar);251void ath10k_pci_release_resource(struct ath10k *ar);252253/* QCA6174 is known to have Tx/Rx issues when SOC_WAKE register is poked too254* frequently. To avoid this put SoC to sleep after a very conservative grace255* period. Adjust with great care.256*/257#define ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC 60258259#endif /* _PCI_H_ */260261262