Changes in 4.9.187 MIPS: ath79: fix ar933x uart parity mode MIPS: fix build on non-linux hosts arm64/efi: Mark __efistub_stext_offset as an absolute symbol explicitly dmaengine: imx-sdma: fix use-after-free on probe error path ath10k: Do not send probe response template for mesh ath9k: Check for errors when reading SREV register ath6kl: add some bounds checking ath: DFS JP domain W56 fixed pulse type 3 RADAR detection batman-adv: fix for leaked TVLV handler. media: dvb: usb: fix use after free in dvb_usb_device_exit crypto: talitos - fix skcipher failure due to wrong output IV media: marvell-ccic: fix DMA s/g desc number calculation media: vpss: fix a potential NULL pointer dereference media: media_device_enum_links32: clean a reserved field net: stmmac: dwmac1000: Clear unused address entries net: stmmac: dwmac4/5: Clear unused address entries signal/pid_namespace: Fix reboot_pid_ns to use send_sig not force_sig af_key: fix leaks in key_pol_get_resp and dump_sp. xfrm: Fix xfrm sel prefix length validation media: mc-device.c: don't memset __user pointer contents media: staging: media: davinci_vpfe: - Fix for memory leak if decoder initialization fails. net: phy: Check against net_device being NULL crypto: talitos - properly handle split ICV. crypto: talitos - Align SEC1 accesses to 32 bits boundaries. tua6100: Avoid build warnings. locking/lockdep: Fix merging of hlocks with non-zero references media: wl128x: Fix some error handling in fm_v4l2_init_video_device() cpupower : frequency-set -r option misses the last cpu in related cpu list net: fec: Do not use netdev messages too early net: axienet: Fix race condition causing TX hang s390/qdio: handle PENDING state for QEBSM devices perf cs-etm: Properly set the value of 'old' and 'head' in snapshot mode perf test 6: Fix missing kvm module load for s390 gpio: omap: fix lack of irqstatus_raw0 for OMAP4 gpio: omap: ensure irq is enabled before wakeup regmap: fix bulk writes on paged registers bpf: silence warning messages in core rcu: Force inlining of rcu_read_lock() blkcg, writeback: dead memcgs shouldn't contribute to writeback ownership arbitration xfrm: fix sa selector validation perf evsel: Make perf_evsel__name() accept a NULL argument vhost_net: disable zerocopy by default ipoib: correcly show a VF hardware address EDAC/sysfs: Fix memory leak when creating a csrow object ipsec: select crypto ciphers for xfrm_algo media: i2c: fix warning same module names ntp: Limit TAI-UTC offset timer_list: Guard procfs specific code acpi/arm64: ignore 5.1 FADTs that are reported as 5.0 media: coda: fix mpeg2 sequence number handling media: coda: increment sequence offset for the last returned frame mt7601u: do not schedule rx_tasklet when the device has been disconnected x86/build: Add 'set -e' to mkcapflags.sh to delete broken capflags.c mt7601u: fix possible memory leak when the device is disconnected ath10k: fix PCIE device wake up failed perf tools: Increase MAX_NR_CPUS and MAX_CACHES libata: don't request sense data on !ZAC ATA devices clocksource/drivers/exynos_mct: Increase priority over ARM arch timer rslib: Fix decoding of shortened codes rslib: Fix handling of of caller provided syndrome ixgbe: Check DDM existence in transceiver before access crypto: asymmetric_keys - select CRYPTO_HASH where needed EDAC: Fix global-out-of-bounds write when setting edac_mc_poll_msec bcache: check c->gc_thread by IS_ERR_OR_NULL in cache_set_flush() iwlwifi: mvm: Drop large non sta frames net: usb: asix: init MAC address buffers gpiolib: Fix references to gpiod_[gs]et_*value_cansleep() variants Bluetooth: hci_bcsp: Fix memory leak in rx_skb Bluetooth: 6lowpan: search for destination address in all peers Bluetooth: Check state in l2cap_disconnect_rsp Bluetooth: validate BLE connection interval updates gtp: fix Illegal context switch in RCU read-side critical section. gtp: fix use-after-free in gtp_newlink() xen: let alloc_xenballooned_pages() fail if not enough memory free scsi: NCR5380: Reduce goto statements in NCR5380_select() scsi: NCR5380: Always re-enable reselection interrupt scsi: mac_scsi: Increase PIO/PDMA transfer length threshold crypto: ghash - fix unaligned memory access in ghash_setkey() crypto: arm64/sha1-ce - correct digest for empty data in finup crypto: arm64/sha2-ce - correct digest for empty data in finup crypto: chacha20poly1305 - fix atomic sleep when using async algorithm crypto: crypto4xx - fix a potential double free in ppc4xx_trng_probe Input: gtco - bounds check collection indent level regulator: s2mps11: Fix buck7 and buck8 wrong voltages arm64: tegra: Update Jetson TX1 GPU regulator timings iwlwifi: pcie: don't service an interrupt that was masked tracing/snapshot: Resize spare buffer if size changed NFSv4: Handle the special Linux file open access mode lib/scatterlist: Fix mapping iterator when sg->offset is greater than PAGE_SIZE ALSA: seq: Break too long mutex context in the write loop ALSA: hda/realtek: apply ALC891 headset fixup to one Dell machine media: v4l2: Test type instead of cfg->type in v4l2_ctrl_new_custom() media: coda: Remove unbalanced and unneeded mutex unlock KVM: x86/vPMU: refine kvm_pmu err msg when event creation failed arm64: tegra: Fix AGIC register range fs/proc/proc_sysctl.c: fix the default values of i_uid/i_gid on /proc/sys inodes. drm/nouveau/i2c: Enable i2c pads & busses during preinit padata: use smp_mb in padata_reorder to avoid orphaned padata jobs 9p/virtio: Add cleanup path in p9_virtio_init PCI: Do not poll for PME if the device is in D3cold Btrfs: add missing inode version, ctime and mtime updates when punching hole libnvdimm/pfn: fix fsdax-mode namespace info-block zero-fields take floppy compat ioctls to sodding floppy.c floppy: fix div-by-zero in setup_format_params floppy: fix out-of-bounds read in next_valid_format floppy: fix invalid pointer dereference in drive_name floppy: fix out-of-bounds read in copy_buffer coda: pass the host file in vma->vm_file on mmap gpu: ipu-v3: ipu-ic: Fix saturation bit offset in TPMEM crypto: ccp - Validate the the error value used to index error messages PCI: hv: Delete the device earlier from hbus->children for hot-remove PCI: hv: Fix a use-after-free bug in hv_eject_device_work() crypto: caam - limit output IV to CBC to work around CTR mode DMA issue um: Allow building and running on older hosts um: Fix FP register size for XSTATE/XSAVE parisc: Ensure userspace privilege for ptraced processes in regset functions parisc: Fix kernel panic due invalid values in IAOQ0 or IAOQ1 powerpc/32s: fix suspend/resume when IBATs 4-7 are used powerpc/watchpoint: Restore NV GPRs while returning from exception eCryptfs: fix a couple type promotion bugs intel_th: msu: Fix single mode with disabled IOMMU Bluetooth: Add SMP workaround Microsoft Surface Precision Mouse bug usb: Handle USB3 remote wakeup for LPM enabled devices correctly dm bufio: fix deadlock with loop device compiler.h, kasan: Avoid duplicating __read_once_size_nocheck() compiler.h: Add read_word_at_a_time() function. lib/strscpy: Shut up KASAN false-positives in strscpy() ext4: allow directory holes bnx2x: Prevent load reordering in tx completion processing bnx2x: Prevent ptp_task to be rescheduled indefinitely caif-hsi: fix possible deadlock in cfhsi_exit_module() igmp: fix memory leak in igmpv3_del_delrec() ipv4: don't set IPv6 only flags to IPv4 addresses net: bcmgenet: use promisc for unsupported filters net: dsa: mv88e6xxx: wait after reset deactivation net: neigh: fix multiple neigh timer scheduling net: openvswitch: fix csum updates for MPLS actions nfc: fix potential illegal memory access rxrpc: Fix send on a connected, but unbound socket sky2: Disable MSI on ASUS P6T vrf: make sure skb->data contains ip header to make routing macsec: fix use-after-free of skb during RX macsec: fix checksumming after decryption netrom: fix a memory leak in nr_rx_frame() netrom: hold sock when setting skb->destructor bonding: validate ip header before check IPPROTO_IGMP tcp: Reset bytes_acked and bytes_received when disconnecting net: bridge: mcast: fix stale nsrcs pointer in igmp3/mld2 report handling net: bridge: mcast: fix stale ipv6 hdr pointer when handling v6 query net: bridge: stp: don't cache eth dest pointer before skb pull perf/x86/amd/uncore: Rename 'L2' to 'LLC' perf/x86/amd/uncore: Get correct number of cores sharing last level cache perf/events/amd/uncore: Fix amd_uncore_llc ID to use pre-defined cpu_llc_id NFSv4: Fix open create exclusive when the server reboots nfsd: increase DRC cache limit nfsd: give out fewer session slots as limit approaches nfsd: fix performance-limiting session calculation nfsd: Fix overflow causing non-working mounts on 1 TB machines drm/panel: simple: Fix panel_simple_dsi_probe usb: core: hub: Disable hub-initiated U1/U2 tty: max310x: Fix invalid baudrate divisors calculator pinctrl: rockchip: fix leaked of_node references tty: serial: cpm_uart - fix init when SMC is relocated drm/bridge: tc358767: read display_props in get_modes() drm/bridge: sii902x: pixel clock unit is 10kHz instead of 1kHz memstick: Fix error cleanup path of memstick_init tty/serial: digicolor: Fix digicolor-usart already registered warning tty: serial: msm_serial: avoid system lockup condition serial: 8250: Fix TX interrupt handling condition drm/virtio: Add memory barriers for capset cache. phy: renesas: rcar-gen2: Fix memory leak at error paths drm/rockchip: Properly adjust to a true clock in adjusted_mode tty: serial_core: Set port active bit in uart_port_activate usb: gadget: Zero ffs_io_data powerpc/pci/of: Fix OF flags parsing for 64bit BARs PCI: sysfs: Ignore lockdep for remove attribute kbuild: Add -Werror=unknown-warning-option to CLANG_FLAGS PCI: xilinx-nwl: Fix Multi MSI data programming iio: iio-utils: Fix possible incorrect mask calculation recordmcount: Fix spurious mcount entries on powerpc mfd: core: Set fwnode for created devices mfd: arizona: Fix undefined behavior mfd: hi655x-pmic: Fix missing return value check for devm_regmap_init_mmio_clk um: Silence lockdep complaint about mmap_sem powerpc/4xx/uic: clear pending interrupt after irq type/pol change RDMA/i40iw: Set queue pair state when being queried serial: sh-sci: Terminate TX DMA during buffer flushing serial: sh-sci: Fix TX DMA buffer flushing and workqueue races kallsyms: exclude kasan local symbols on s390 perf test mmap-thread-lookup: Initialize variable to suppress memory sanitizer warning RDMA/rxe: Fill in wc byte_len with IB_WC_RECV_RDMA_WITH_IMM powerpc/boot: add {get, put}_unaligned_be32 to xz_config.h f2fs: avoid out-of-range memory access mailbox: handle failed named mailbox channel request powerpc/eeh: Handle hugepages in ioremap space sh: prevent warnings when using iounmap mm/kmemleak.c: fix check for softirq context 9p: pass the correct prototype to read_cache_page mm/mmu_notifier: use hlist_add_head_rcu() locking/lockdep: Fix lock used or unused stats error locking/lockdep: Hide unused 'class' variable usb: wusbcore: fix unbalanced get/put cluster_id usb: pci-quirks: Correct AMD PLL quirk detection x86/sysfb_efi: Add quirks for some devices with swapped width and height x86/speculation/mds: Apply more accurate check on hypervisor platform hpet: Fix division by zero in hpet_time_div() ALSA: line6: Fix wrong altsetting for LINE6_PODHD500_1 ALSA: hda - Add a conexant codec entry to let mute led work powerpc/tm: Fix oops on sigreturn on systems without TM access: avoid the RCU grace period for the temporary subjective credentials ipv6: check sk sk_type and protocol early in ip_mroute_set/getsockopt tcp: reset sk_send_head in tcp_write_queue_purge arm64: dts: marvell: Fix A37xx UART0 register size i2c: qup: fixed releasing dma without flush operation completion arm64: compat: Provide definition for COMPAT_SIGMINSTKSZ ISDN: hfcsusb: checking idx of ep configuration media: au0828: fix null dereference in error path media: cpia2_usb: first wake up, then free in disconnect media: radio-raremono: change devm_k*alloc to k*alloc Bluetooth: hci_uart: check for missing tty operations sched/fair: Don't free p->numa_faults with concurrent readers drivers/pps/pps.c: clear offset flags in PPS_SETPARAMS ioctl ceph: hold i_ceph_lock when removing caps for freeing inode Linux 4.9.187 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
879 lines
23 KiB
C
879 lines
23 KiB
C
/*
|
|
* PCIe host controller driver for NWL PCIe Bridge
|
|
* Based on pcie-xilinx.c, pci-tegra.c
|
|
*
|
|
* (C) Copyright 2014 - 2015, Xilinx, Inc.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*/
|
|
|
|
#include <linux/delay.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/irq.h>
|
|
#include <linux/irqdomain.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/msi.h>
|
|
#include <linux/of_address.h>
|
|
#include <linux/of_pci.h>
|
|
#include <linux/of_platform.h>
|
|
#include <linux/of_irq.h>
|
|
#include <linux/pci.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/irqchip/chained_irq.h>
|
|
|
|
/* Bridge core config registers */
|
|
#define BRCFG_PCIE_RX0 0x00000000
|
|
#define BRCFG_INTERRUPT 0x00000010
|
|
#define BRCFG_PCIE_RX_MSG_FILTER 0x00000020
|
|
|
|
/* Egress - Bridge translation registers */
|
|
#define E_BREG_CAPABILITIES 0x00000200
|
|
#define E_BREG_CONTROL 0x00000208
|
|
#define E_BREG_BASE_LO 0x00000210
|
|
#define E_BREG_BASE_HI 0x00000214
|
|
#define E_ECAM_CAPABILITIES 0x00000220
|
|
#define E_ECAM_CONTROL 0x00000228
|
|
#define E_ECAM_BASE_LO 0x00000230
|
|
#define E_ECAM_BASE_HI 0x00000234
|
|
|
|
/* Ingress - address translations */
|
|
#define I_MSII_CAPABILITIES 0x00000300
|
|
#define I_MSII_CONTROL 0x00000308
|
|
#define I_MSII_BASE_LO 0x00000310
|
|
#define I_MSII_BASE_HI 0x00000314
|
|
|
|
#define I_ISUB_CONTROL 0x000003E8
|
|
#define SET_ISUB_CONTROL BIT(0)
|
|
/* Rxed msg fifo - Interrupt status registers */
|
|
#define MSGF_MISC_STATUS 0x00000400
|
|
#define MSGF_MISC_MASK 0x00000404
|
|
#define MSGF_LEG_STATUS 0x00000420
|
|
#define MSGF_LEG_MASK 0x00000424
|
|
#define MSGF_MSI_STATUS_LO 0x00000440
|
|
#define MSGF_MSI_STATUS_HI 0x00000444
|
|
#define MSGF_MSI_MASK_LO 0x00000448
|
|
#define MSGF_MSI_MASK_HI 0x0000044C
|
|
|
|
/* Msg filter mask bits */
|
|
#define CFG_ENABLE_PM_MSG_FWD BIT(1)
|
|
#define CFG_ENABLE_INT_MSG_FWD BIT(2)
|
|
#define CFG_ENABLE_ERR_MSG_FWD BIT(3)
|
|
#define CFG_ENABLE_SLT_MSG_FWD BIT(5)
|
|
#define CFG_ENABLE_VEN_MSG_FWD BIT(7)
|
|
#define CFG_ENABLE_OTH_MSG_FWD BIT(13)
|
|
#define CFG_ENABLE_VEN_MSG_EN BIT(14)
|
|
#define CFG_ENABLE_VEN_MSG_VEN_INV BIT(15)
|
|
#define CFG_ENABLE_VEN_MSG_VEN_ID GENMASK(31, 16)
|
|
#define CFG_ENABLE_MSG_FILTER_MASK (CFG_ENABLE_PM_MSG_FWD | \
|
|
CFG_ENABLE_INT_MSG_FWD | \
|
|
CFG_ENABLE_ERR_MSG_FWD | \
|
|
CFG_ENABLE_SLT_MSG_FWD | \
|
|
CFG_ENABLE_VEN_MSG_FWD | \
|
|
CFG_ENABLE_OTH_MSG_FWD | \
|
|
CFG_ENABLE_VEN_MSG_EN | \
|
|
CFG_ENABLE_VEN_MSG_VEN_INV | \
|
|
CFG_ENABLE_VEN_MSG_VEN_ID)
|
|
|
|
/* Misc interrupt status mask bits */
|
|
#define MSGF_MISC_SR_RXMSG_AVAIL BIT(0)
|
|
#define MSGF_MISC_SR_RXMSG_OVER BIT(1)
|
|
#define MSGF_MISC_SR_SLAVE_ERR BIT(4)
|
|
#define MSGF_MISC_SR_MASTER_ERR BIT(5)
|
|
#define MSGF_MISC_SR_I_ADDR_ERR BIT(6)
|
|
#define MSGF_MISC_SR_E_ADDR_ERR BIT(7)
|
|
#define MSGF_MISC_SR_FATAL_AER BIT(16)
|
|
#define MSGF_MISC_SR_NON_FATAL_AER BIT(17)
|
|
#define MSGF_MISC_SR_CORR_AER BIT(18)
|
|
#define MSGF_MISC_SR_UR_DETECT BIT(20)
|
|
#define MSGF_MISC_SR_NON_FATAL_DEV BIT(22)
|
|
#define MSGF_MISC_SR_FATAL_DEV BIT(23)
|
|
#define MSGF_MISC_SR_LINK_DOWN BIT(24)
|
|
#define MSGF_MSIC_SR_LINK_AUTO_BWIDTH BIT(25)
|
|
#define MSGF_MSIC_SR_LINK_BWIDTH BIT(26)
|
|
|
|
#define MSGF_MISC_SR_MASKALL (MSGF_MISC_SR_RXMSG_AVAIL | \
|
|
MSGF_MISC_SR_RXMSG_OVER | \
|
|
MSGF_MISC_SR_SLAVE_ERR | \
|
|
MSGF_MISC_SR_MASTER_ERR | \
|
|
MSGF_MISC_SR_I_ADDR_ERR | \
|
|
MSGF_MISC_SR_E_ADDR_ERR | \
|
|
MSGF_MISC_SR_FATAL_AER | \
|
|
MSGF_MISC_SR_NON_FATAL_AER | \
|
|
MSGF_MISC_SR_CORR_AER | \
|
|
MSGF_MISC_SR_UR_DETECT | \
|
|
MSGF_MISC_SR_NON_FATAL_DEV | \
|
|
MSGF_MISC_SR_FATAL_DEV | \
|
|
MSGF_MISC_SR_LINK_DOWN | \
|
|
MSGF_MSIC_SR_LINK_AUTO_BWIDTH | \
|
|
MSGF_MSIC_SR_LINK_BWIDTH)
|
|
|
|
/* Legacy interrupt status mask bits */
|
|
#define MSGF_LEG_SR_INTA BIT(0)
|
|
#define MSGF_LEG_SR_INTB BIT(1)
|
|
#define MSGF_LEG_SR_INTC BIT(2)
|
|
#define MSGF_LEG_SR_INTD BIT(3)
|
|
#define MSGF_LEG_SR_MASKALL (MSGF_LEG_SR_INTA | MSGF_LEG_SR_INTB | \
|
|
MSGF_LEG_SR_INTC | MSGF_LEG_SR_INTD)
|
|
|
|
/* MSI interrupt status mask bits */
|
|
#define MSGF_MSI_SR_LO_MASK GENMASK(31, 0)
|
|
#define MSGF_MSI_SR_HI_MASK GENMASK(31, 0)
|
|
|
|
#define MSII_PRESENT BIT(0)
|
|
#define MSII_ENABLE BIT(0)
|
|
#define MSII_STATUS_ENABLE BIT(15)
|
|
|
|
/* Bridge config interrupt mask */
|
|
#define BRCFG_INTERRUPT_MASK BIT(0)
|
|
#define BREG_PRESENT BIT(0)
|
|
#define BREG_ENABLE BIT(0)
|
|
#define BREG_ENABLE_FORCE BIT(1)
|
|
|
|
/* E_ECAM status mask bits */
|
|
#define E_ECAM_PRESENT BIT(0)
|
|
#define E_ECAM_CR_ENABLE BIT(0)
|
|
#define E_ECAM_SIZE_LOC GENMASK(20, 16)
|
|
#define E_ECAM_SIZE_SHIFT 16
|
|
#define ECAM_BUS_LOC_SHIFT 20
|
|
#define ECAM_DEV_LOC_SHIFT 12
|
|
#define NWL_ECAM_VALUE_DEFAULT 12
|
|
|
|
#define CFG_DMA_REG_BAR GENMASK(2, 0)
|
|
|
|
#define INT_PCI_MSI_NR (2 * 32)
|
|
#define INTX_NUM 4
|
|
|
|
/* Readin the PS_LINKUP */
|
|
#define PS_LINKUP_OFFSET 0x00000238
|
|
#define PCIE_PHY_LINKUP_BIT BIT(0)
|
|
#define PHY_RDY_LINKUP_BIT BIT(1)
|
|
|
|
/* Parameters for the waiting for link up routine */
|
|
#define LINK_WAIT_MAX_RETRIES 10
|
|
#define LINK_WAIT_USLEEP_MIN 90000
|
|
#define LINK_WAIT_USLEEP_MAX 100000
|
|
|
|
struct nwl_msi { /* MSI information */
|
|
struct irq_domain *msi_domain;
|
|
unsigned long *bitmap;
|
|
struct irq_domain *dev_domain;
|
|
struct mutex lock; /* protect bitmap variable */
|
|
int irq_msi0;
|
|
int irq_msi1;
|
|
};
|
|
|
|
struct nwl_pcie {
|
|
struct device *dev;
|
|
void __iomem *breg_base;
|
|
void __iomem *pcireg_base;
|
|
void __iomem *ecam_base;
|
|
phys_addr_t phys_breg_base; /* Physical Bridge Register Base */
|
|
phys_addr_t phys_pcie_reg_base; /* Physical PCIe Controller Base */
|
|
phys_addr_t phys_ecam_base; /* Physical Configuration Base */
|
|
u32 breg_size;
|
|
u32 pcie_reg_size;
|
|
u32 ecam_size;
|
|
int irq_intx;
|
|
int irq_misc;
|
|
u32 ecam_value;
|
|
u8 last_busno;
|
|
u8 root_busno;
|
|
struct nwl_msi msi;
|
|
struct irq_domain *legacy_irq_domain;
|
|
};
|
|
|
|
static inline u32 nwl_bridge_readl(struct nwl_pcie *pcie, u32 off)
|
|
{
|
|
return readl(pcie->breg_base + off);
|
|
}
|
|
|
|
static inline void nwl_bridge_writel(struct nwl_pcie *pcie, u32 val, u32 off)
|
|
{
|
|
writel(val, pcie->breg_base + off);
|
|
}
|
|
|
|
static bool nwl_pcie_link_up(struct nwl_pcie *pcie)
|
|
{
|
|
if (readl(pcie->pcireg_base + PS_LINKUP_OFFSET) & PCIE_PHY_LINKUP_BIT)
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
static bool nwl_phy_link_up(struct nwl_pcie *pcie)
|
|
{
|
|
if (readl(pcie->pcireg_base + PS_LINKUP_OFFSET) & PHY_RDY_LINKUP_BIT)
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
static int nwl_wait_for_link(struct nwl_pcie *pcie)
|
|
{
|
|
struct device *dev = pcie->dev;
|
|
int retries;
|
|
|
|
/* check if the link is up or not */
|
|
for (retries = 0; retries < LINK_WAIT_MAX_RETRIES; retries++) {
|
|
if (nwl_phy_link_up(pcie))
|
|
return 0;
|
|
usleep_range(LINK_WAIT_USLEEP_MIN, LINK_WAIT_USLEEP_MAX);
|
|
}
|
|
|
|
dev_err(dev, "PHY link never came up\n");
|
|
return -ETIMEDOUT;
|
|
}
|
|
|
|
static bool nwl_pcie_valid_device(struct pci_bus *bus, unsigned int devfn)
|
|
{
|
|
struct nwl_pcie *pcie = bus->sysdata;
|
|
|
|
/* Check link before accessing downstream ports */
|
|
if (bus->number != pcie->root_busno) {
|
|
if (!nwl_pcie_link_up(pcie))
|
|
return false;
|
|
}
|
|
|
|
/* Only one device down on each root port */
|
|
if (bus->number == pcie->root_busno && devfn > 0)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* nwl_pcie_map_bus - Get configuration base
|
|
*
|
|
* @bus: Bus structure of current bus
|
|
* @devfn: Device/function
|
|
* @where: Offset from base
|
|
*
|
|
* Return: Base address of the configuration space needed to be
|
|
* accessed.
|
|
*/
|
|
static void __iomem *nwl_pcie_map_bus(struct pci_bus *bus, unsigned int devfn,
|
|
int where)
|
|
{
|
|
struct nwl_pcie *pcie = bus->sysdata;
|
|
int relbus;
|
|
|
|
if (!nwl_pcie_valid_device(bus, devfn))
|
|
return NULL;
|
|
|
|
relbus = (bus->number << ECAM_BUS_LOC_SHIFT) |
|
|
(devfn << ECAM_DEV_LOC_SHIFT);
|
|
|
|
return pcie->ecam_base + relbus + where;
|
|
}
|
|
|
|
/* PCIe operations */
|
|
static struct pci_ops nwl_pcie_ops = {
|
|
.map_bus = nwl_pcie_map_bus,
|
|
.read = pci_generic_config_read,
|
|
.write = pci_generic_config_write,
|
|
};
|
|
|
|
static irqreturn_t nwl_pcie_misc_handler(int irq, void *data)
|
|
{
|
|
struct nwl_pcie *pcie = data;
|
|
struct device *dev = pcie->dev;
|
|
u32 misc_stat;
|
|
|
|
/* Checking for misc interrupts */
|
|
misc_stat = nwl_bridge_readl(pcie, MSGF_MISC_STATUS) &
|
|
MSGF_MISC_SR_MASKALL;
|
|
if (!misc_stat)
|
|
return IRQ_NONE;
|
|
|
|
if (misc_stat & MSGF_MISC_SR_RXMSG_OVER)
|
|
dev_err(dev, "Received Message FIFO Overflow\n");
|
|
|
|
if (misc_stat & MSGF_MISC_SR_SLAVE_ERR)
|
|
dev_err(dev, "Slave error\n");
|
|
|
|
if (misc_stat & MSGF_MISC_SR_MASTER_ERR)
|
|
dev_err(dev, "Master error\n");
|
|
|
|
if (misc_stat & MSGF_MISC_SR_I_ADDR_ERR)
|
|
dev_err(dev, "In Misc Ingress address translation error\n");
|
|
|
|
if (misc_stat & MSGF_MISC_SR_E_ADDR_ERR)
|
|
dev_err(dev, "In Misc Egress address translation error\n");
|
|
|
|
if (misc_stat & MSGF_MISC_SR_FATAL_AER)
|
|
dev_err(dev, "Fatal Error in AER Capability\n");
|
|
|
|
if (misc_stat & MSGF_MISC_SR_NON_FATAL_AER)
|
|
dev_err(dev, "Non-Fatal Error in AER Capability\n");
|
|
|
|
if (misc_stat & MSGF_MISC_SR_CORR_AER)
|
|
dev_err(dev, "Correctable Error in AER Capability\n");
|
|
|
|
if (misc_stat & MSGF_MISC_SR_UR_DETECT)
|
|
dev_err(dev, "Unsupported request Detected\n");
|
|
|
|
if (misc_stat & MSGF_MISC_SR_NON_FATAL_DEV)
|
|
dev_err(dev, "Non-Fatal Error Detected\n");
|
|
|
|
if (misc_stat & MSGF_MISC_SR_FATAL_DEV)
|
|
dev_err(dev, "Fatal Error Detected\n");
|
|
|
|
if (misc_stat & MSGF_MSIC_SR_LINK_AUTO_BWIDTH)
|
|
dev_info(dev, "Link Autonomous Bandwidth Management Status bit set\n");
|
|
|
|
if (misc_stat & MSGF_MSIC_SR_LINK_BWIDTH)
|
|
dev_info(dev, "Link Bandwidth Management Status bit set\n");
|
|
|
|
/* Clear misc interrupt status */
|
|
nwl_bridge_writel(pcie, misc_stat, MSGF_MISC_STATUS);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static void nwl_pcie_leg_handler(struct irq_desc *desc)
|
|
{
|
|
struct irq_chip *chip = irq_desc_get_chip(desc);
|
|
struct nwl_pcie *pcie;
|
|
unsigned long status;
|
|
u32 bit;
|
|
u32 virq;
|
|
|
|
chained_irq_enter(chip, desc);
|
|
pcie = irq_desc_get_handler_data(desc);
|
|
|
|
while ((status = nwl_bridge_readl(pcie, MSGF_LEG_STATUS) &
|
|
MSGF_LEG_SR_MASKALL) != 0) {
|
|
for_each_set_bit(bit, &status, INTX_NUM) {
|
|
virq = irq_find_mapping(pcie->legacy_irq_domain,
|
|
bit + 1);
|
|
if (virq)
|
|
generic_handle_irq(virq);
|
|
}
|
|
}
|
|
|
|
chained_irq_exit(chip, desc);
|
|
}
|
|
|
|
static void nwl_pcie_handle_msi_irq(struct nwl_pcie *pcie, u32 status_reg)
|
|
{
|
|
struct nwl_msi *msi;
|
|
unsigned long status;
|
|
u32 bit;
|
|
u32 virq;
|
|
|
|
msi = &pcie->msi;
|
|
|
|
while ((status = nwl_bridge_readl(pcie, status_reg)) != 0) {
|
|
for_each_set_bit(bit, &status, 32) {
|
|
nwl_bridge_writel(pcie, 1 << bit, status_reg);
|
|
virq = irq_find_mapping(msi->dev_domain, bit);
|
|
if (virq)
|
|
generic_handle_irq(virq);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void nwl_pcie_msi_handler_high(struct irq_desc *desc)
|
|
{
|
|
struct irq_chip *chip = irq_desc_get_chip(desc);
|
|
struct nwl_pcie *pcie = irq_desc_get_handler_data(desc);
|
|
|
|
chained_irq_enter(chip, desc);
|
|
nwl_pcie_handle_msi_irq(pcie, MSGF_MSI_STATUS_HI);
|
|
chained_irq_exit(chip, desc);
|
|
}
|
|
|
|
static void nwl_pcie_msi_handler_low(struct irq_desc *desc)
|
|
{
|
|
struct irq_chip *chip = irq_desc_get_chip(desc);
|
|
struct nwl_pcie *pcie = irq_desc_get_handler_data(desc);
|
|
|
|
chained_irq_enter(chip, desc);
|
|
nwl_pcie_handle_msi_irq(pcie, MSGF_MSI_STATUS_LO);
|
|
chained_irq_exit(chip, desc);
|
|
}
|
|
|
|
static int nwl_legacy_map(struct irq_domain *domain, unsigned int irq,
|
|
irq_hw_number_t hwirq)
|
|
{
|
|
irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
|
|
irq_set_chip_data(irq, domain->host_data);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct irq_domain_ops legacy_domain_ops = {
|
|
.map = nwl_legacy_map,
|
|
};
|
|
|
|
#ifdef CONFIG_PCI_MSI
|
|
static struct irq_chip nwl_msi_irq_chip = {
|
|
.name = "nwl_pcie:msi",
|
|
.irq_enable = unmask_msi_irq,
|
|
.irq_disable = mask_msi_irq,
|
|
.irq_mask = mask_msi_irq,
|
|
.irq_unmask = unmask_msi_irq,
|
|
|
|
};
|
|
|
|
static struct msi_domain_info nwl_msi_domain_info = {
|
|
.flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
|
|
MSI_FLAG_MULTI_PCI_MSI),
|
|
.chip = &nwl_msi_irq_chip,
|
|
};
|
|
#endif
|
|
|
|
static void nwl_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
|
|
{
|
|
struct nwl_pcie *pcie = irq_data_get_irq_chip_data(data);
|
|
phys_addr_t msi_addr = pcie->phys_pcie_reg_base;
|
|
|
|
msg->address_lo = lower_32_bits(msi_addr);
|
|
msg->address_hi = upper_32_bits(msi_addr);
|
|
msg->data = data->hwirq;
|
|
}
|
|
|
|
static int nwl_msi_set_affinity(struct irq_data *irq_data,
|
|
const struct cpumask *mask, bool force)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static struct irq_chip nwl_irq_chip = {
|
|
.name = "Xilinx MSI",
|
|
.irq_compose_msi_msg = nwl_compose_msi_msg,
|
|
.irq_set_affinity = nwl_msi_set_affinity,
|
|
};
|
|
|
|
static int nwl_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
|
|
unsigned int nr_irqs, void *args)
|
|
{
|
|
struct nwl_pcie *pcie = domain->host_data;
|
|
struct nwl_msi *msi = &pcie->msi;
|
|
int bit;
|
|
int i;
|
|
|
|
mutex_lock(&msi->lock);
|
|
bit = bitmap_find_free_region(msi->bitmap, INT_PCI_MSI_NR,
|
|
get_count_order(nr_irqs));
|
|
if (bit < 0) {
|
|
mutex_unlock(&msi->lock);
|
|
return -ENOSPC;
|
|
}
|
|
|
|
for (i = 0; i < nr_irqs; i++) {
|
|
irq_domain_set_info(domain, virq + i, bit + i, &nwl_irq_chip,
|
|
domain->host_data, handle_simple_irq,
|
|
NULL, NULL);
|
|
}
|
|
mutex_unlock(&msi->lock);
|
|
return 0;
|
|
}
|
|
|
|
static void nwl_irq_domain_free(struct irq_domain *domain, unsigned int virq,
|
|
unsigned int nr_irqs)
|
|
{
|
|
struct irq_data *data = irq_domain_get_irq_data(domain, virq);
|
|
struct nwl_pcie *pcie = irq_data_get_irq_chip_data(data);
|
|
struct nwl_msi *msi = &pcie->msi;
|
|
|
|
mutex_lock(&msi->lock);
|
|
bitmap_release_region(msi->bitmap, data->hwirq,
|
|
get_count_order(nr_irqs));
|
|
mutex_unlock(&msi->lock);
|
|
}
|
|
|
|
static const struct irq_domain_ops dev_msi_domain_ops = {
|
|
.alloc = nwl_irq_domain_alloc,
|
|
.free = nwl_irq_domain_free,
|
|
};
|
|
|
|
static int nwl_pcie_init_msi_irq_domain(struct nwl_pcie *pcie)
|
|
{
|
|
#ifdef CONFIG_PCI_MSI
|
|
struct device *dev = pcie->dev;
|
|
struct fwnode_handle *fwnode = of_node_to_fwnode(dev->of_node);
|
|
struct nwl_msi *msi = &pcie->msi;
|
|
|
|
msi->dev_domain = irq_domain_add_linear(NULL, INT_PCI_MSI_NR,
|
|
&dev_msi_domain_ops, pcie);
|
|
if (!msi->dev_domain) {
|
|
dev_err(dev, "failed to create dev IRQ domain\n");
|
|
return -ENOMEM;
|
|
}
|
|
msi->msi_domain = pci_msi_create_irq_domain(fwnode,
|
|
&nwl_msi_domain_info,
|
|
msi->dev_domain);
|
|
if (!msi->msi_domain) {
|
|
dev_err(dev, "failed to create msi IRQ domain\n");
|
|
irq_domain_remove(msi->dev_domain);
|
|
return -ENOMEM;
|
|
}
|
|
#endif
|
|
return 0;
|
|
}
|
|
|
|
static int nwl_pcie_init_irq_domain(struct nwl_pcie *pcie)
|
|
{
|
|
struct device *dev = pcie->dev;
|
|
struct device_node *node = dev->of_node;
|
|
struct device_node *legacy_intc_node;
|
|
|
|
legacy_intc_node = of_get_next_child(node, NULL);
|
|
if (!legacy_intc_node) {
|
|
dev_err(dev, "No legacy intc node found\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
pcie->legacy_irq_domain = irq_domain_add_linear(legacy_intc_node,
|
|
INTX_NUM,
|
|
&legacy_domain_ops,
|
|
pcie);
|
|
of_node_put(legacy_intc_node);
|
|
if (!pcie->legacy_irq_domain) {
|
|
dev_err(dev, "failed to create IRQ domain\n");
|
|
return -ENOMEM;
|
|
}
|
|
|
|
nwl_pcie_init_msi_irq_domain(pcie);
|
|
return 0;
|
|
}
|
|
|
|
static int nwl_pcie_enable_msi(struct nwl_pcie *pcie, struct pci_bus *bus)
|
|
{
|
|
struct device *dev = pcie->dev;
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
struct nwl_msi *msi = &pcie->msi;
|
|
unsigned long base;
|
|
int ret;
|
|
int size = BITS_TO_LONGS(INT_PCI_MSI_NR) * sizeof(long);
|
|
|
|
mutex_init(&msi->lock);
|
|
|
|
msi->bitmap = kzalloc(size, GFP_KERNEL);
|
|
if (!msi->bitmap)
|
|
return -ENOMEM;
|
|
|
|
/* Get msi_1 IRQ number */
|
|
msi->irq_msi1 = platform_get_irq_byname(pdev, "msi1");
|
|
if (msi->irq_msi1 < 0) {
|
|
dev_err(dev, "failed to get IRQ#%d\n", msi->irq_msi1);
|
|
ret = -EINVAL;
|
|
goto err;
|
|
}
|
|
|
|
irq_set_chained_handler_and_data(msi->irq_msi1,
|
|
nwl_pcie_msi_handler_high, pcie);
|
|
|
|
/* Get msi_0 IRQ number */
|
|
msi->irq_msi0 = platform_get_irq_byname(pdev, "msi0");
|
|
if (msi->irq_msi0 < 0) {
|
|
dev_err(dev, "failed to get IRQ#%d\n", msi->irq_msi0);
|
|
ret = -EINVAL;
|
|
goto err;
|
|
}
|
|
|
|
irq_set_chained_handler_and_data(msi->irq_msi0,
|
|
nwl_pcie_msi_handler_low, pcie);
|
|
|
|
/* Check for msii_present bit */
|
|
ret = nwl_bridge_readl(pcie, I_MSII_CAPABILITIES) & MSII_PRESENT;
|
|
if (!ret) {
|
|
dev_err(dev, "MSI not present\n");
|
|
ret = -EIO;
|
|
goto err;
|
|
}
|
|
|
|
/* Enable MSII */
|
|
nwl_bridge_writel(pcie, nwl_bridge_readl(pcie, I_MSII_CONTROL) |
|
|
MSII_ENABLE, I_MSII_CONTROL);
|
|
|
|
/* Enable MSII status */
|
|
nwl_bridge_writel(pcie, nwl_bridge_readl(pcie, I_MSII_CONTROL) |
|
|
MSII_STATUS_ENABLE, I_MSII_CONTROL);
|
|
|
|
/* setup AFI/FPCI range */
|
|
base = pcie->phys_pcie_reg_base;
|
|
nwl_bridge_writel(pcie, lower_32_bits(base), I_MSII_BASE_LO);
|
|
nwl_bridge_writel(pcie, upper_32_bits(base), I_MSII_BASE_HI);
|
|
|
|
/*
|
|
* For high range MSI interrupts: disable, clear any pending,
|
|
* and enable
|
|
*/
|
|
nwl_bridge_writel(pcie, (u32)~MSGF_MSI_SR_HI_MASK, MSGF_MSI_MASK_HI);
|
|
|
|
nwl_bridge_writel(pcie, nwl_bridge_readl(pcie, MSGF_MSI_STATUS_HI) &
|
|
MSGF_MSI_SR_HI_MASK, MSGF_MSI_STATUS_HI);
|
|
|
|
nwl_bridge_writel(pcie, MSGF_MSI_SR_HI_MASK, MSGF_MSI_MASK_HI);
|
|
|
|
/*
|
|
* For low range MSI interrupts: disable, clear any pending,
|
|
* and enable
|
|
*/
|
|
nwl_bridge_writel(pcie, (u32)~MSGF_MSI_SR_LO_MASK, MSGF_MSI_MASK_LO);
|
|
|
|
nwl_bridge_writel(pcie, nwl_bridge_readl(pcie, MSGF_MSI_STATUS_LO) &
|
|
MSGF_MSI_SR_LO_MASK, MSGF_MSI_STATUS_LO);
|
|
|
|
nwl_bridge_writel(pcie, MSGF_MSI_SR_LO_MASK, MSGF_MSI_MASK_LO);
|
|
|
|
return 0;
|
|
err:
|
|
kfree(msi->bitmap);
|
|
msi->bitmap = NULL;
|
|
return ret;
|
|
}
|
|
|
|
static int nwl_pcie_bridge_init(struct nwl_pcie *pcie)
|
|
{
|
|
struct device *dev = pcie->dev;
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
u32 breg_val, ecam_val, first_busno = 0;
|
|
int err;
|
|
|
|
breg_val = nwl_bridge_readl(pcie, E_BREG_CAPABILITIES) & BREG_PRESENT;
|
|
if (!breg_val) {
|
|
dev_err(dev, "BREG is not present\n");
|
|
return breg_val;
|
|
}
|
|
|
|
/* Write bridge_off to breg base */
|
|
nwl_bridge_writel(pcie, lower_32_bits(pcie->phys_breg_base),
|
|
E_BREG_BASE_LO);
|
|
nwl_bridge_writel(pcie, upper_32_bits(pcie->phys_breg_base),
|
|
E_BREG_BASE_HI);
|
|
|
|
/* Enable BREG */
|
|
nwl_bridge_writel(pcie, ~BREG_ENABLE_FORCE & BREG_ENABLE,
|
|
E_BREG_CONTROL);
|
|
|
|
/* Disable DMA channel registers */
|
|
nwl_bridge_writel(pcie, nwl_bridge_readl(pcie, BRCFG_PCIE_RX0) |
|
|
CFG_DMA_REG_BAR, BRCFG_PCIE_RX0);
|
|
|
|
/* Enable Ingress subtractive decode translation */
|
|
nwl_bridge_writel(pcie, SET_ISUB_CONTROL, I_ISUB_CONTROL);
|
|
|
|
/* Enable msg filtering details */
|
|
nwl_bridge_writel(pcie, CFG_ENABLE_MSG_FILTER_MASK,
|
|
BRCFG_PCIE_RX_MSG_FILTER);
|
|
|
|
err = nwl_wait_for_link(pcie);
|
|
if (err)
|
|
return err;
|
|
|
|
ecam_val = nwl_bridge_readl(pcie, E_ECAM_CAPABILITIES) & E_ECAM_PRESENT;
|
|
if (!ecam_val) {
|
|
dev_err(dev, "ECAM is not present\n");
|
|
return ecam_val;
|
|
}
|
|
|
|
/* Enable ECAM */
|
|
nwl_bridge_writel(pcie, nwl_bridge_readl(pcie, E_ECAM_CONTROL) |
|
|
E_ECAM_CR_ENABLE, E_ECAM_CONTROL);
|
|
|
|
nwl_bridge_writel(pcie, nwl_bridge_readl(pcie, E_ECAM_CONTROL) |
|
|
(pcie->ecam_value << E_ECAM_SIZE_SHIFT),
|
|
E_ECAM_CONTROL);
|
|
|
|
nwl_bridge_writel(pcie, lower_32_bits(pcie->phys_ecam_base),
|
|
E_ECAM_BASE_LO);
|
|
nwl_bridge_writel(pcie, upper_32_bits(pcie->phys_ecam_base),
|
|
E_ECAM_BASE_HI);
|
|
|
|
/* Get bus range */
|
|
ecam_val = nwl_bridge_readl(pcie, E_ECAM_CONTROL);
|
|
pcie->last_busno = (ecam_val & E_ECAM_SIZE_LOC) >> E_ECAM_SIZE_SHIFT;
|
|
/* Write primary, secondary and subordinate bus numbers */
|
|
ecam_val = first_busno;
|
|
ecam_val |= (first_busno + 1) << 8;
|
|
ecam_val |= (pcie->last_busno << E_ECAM_SIZE_SHIFT);
|
|
writel(ecam_val, (pcie->ecam_base + PCI_PRIMARY_BUS));
|
|
|
|
if (nwl_pcie_link_up(pcie))
|
|
dev_info(dev, "Link is UP\n");
|
|
else
|
|
dev_info(dev, "Link is DOWN\n");
|
|
|
|
/* Get misc IRQ number */
|
|
pcie->irq_misc = platform_get_irq_byname(pdev, "misc");
|
|
if (pcie->irq_misc < 0) {
|
|
dev_err(dev, "failed to get misc IRQ %d\n",
|
|
pcie->irq_misc);
|
|
return -EINVAL;
|
|
}
|
|
|
|
err = devm_request_irq(dev, pcie->irq_misc,
|
|
nwl_pcie_misc_handler, IRQF_SHARED,
|
|
"nwl_pcie:misc", pcie);
|
|
if (err) {
|
|
dev_err(dev, "fail to register misc IRQ#%d\n",
|
|
pcie->irq_misc);
|
|
return err;
|
|
}
|
|
|
|
/* Disable all misc interrupts */
|
|
nwl_bridge_writel(pcie, (u32)~MSGF_MISC_SR_MASKALL, MSGF_MISC_MASK);
|
|
|
|
/* Clear pending misc interrupts */
|
|
nwl_bridge_writel(pcie, nwl_bridge_readl(pcie, MSGF_MISC_STATUS) &
|
|
MSGF_MISC_SR_MASKALL, MSGF_MISC_STATUS);
|
|
|
|
/* Enable all misc interrupts */
|
|
nwl_bridge_writel(pcie, MSGF_MISC_SR_MASKALL, MSGF_MISC_MASK);
|
|
|
|
|
|
/* Disable all legacy interrupts */
|
|
nwl_bridge_writel(pcie, (u32)~MSGF_LEG_SR_MASKALL, MSGF_LEG_MASK);
|
|
|
|
/* Clear pending legacy interrupts */
|
|
nwl_bridge_writel(pcie, nwl_bridge_readl(pcie, MSGF_LEG_STATUS) &
|
|
MSGF_LEG_SR_MASKALL, MSGF_LEG_STATUS);
|
|
|
|
/* Enable all legacy interrupts */
|
|
nwl_bridge_writel(pcie, MSGF_LEG_SR_MASKALL, MSGF_LEG_MASK);
|
|
|
|
/* Enable the bridge config interrupt */
|
|
nwl_bridge_writel(pcie, nwl_bridge_readl(pcie, BRCFG_INTERRUPT) |
|
|
BRCFG_INTERRUPT_MASK, BRCFG_INTERRUPT);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int nwl_pcie_parse_dt(struct nwl_pcie *pcie,
|
|
struct platform_device *pdev)
|
|
{
|
|
struct device *dev = pcie->dev;
|
|
struct device_node *node = dev->of_node;
|
|
struct resource *res;
|
|
const char *type;
|
|
|
|
/* Check for device type */
|
|
type = of_get_property(node, "device_type", NULL);
|
|
if (!type || strcmp(type, "pci")) {
|
|
dev_err(dev, "invalid \"device_type\" %s\n", type);
|
|
return -EINVAL;
|
|
}
|
|
|
|
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "breg");
|
|
pcie->breg_base = devm_ioremap_resource(dev, res);
|
|
if (IS_ERR(pcie->breg_base))
|
|
return PTR_ERR(pcie->breg_base);
|
|
pcie->phys_breg_base = res->start;
|
|
|
|
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcireg");
|
|
pcie->pcireg_base = devm_ioremap_resource(dev, res);
|
|
if (IS_ERR(pcie->pcireg_base))
|
|
return PTR_ERR(pcie->pcireg_base);
|
|
pcie->phys_pcie_reg_base = res->start;
|
|
|
|
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg");
|
|
pcie->ecam_base = devm_ioremap_resource(dev, res);
|
|
if (IS_ERR(pcie->ecam_base))
|
|
return PTR_ERR(pcie->ecam_base);
|
|
pcie->phys_ecam_base = res->start;
|
|
|
|
/* Get intx IRQ number */
|
|
pcie->irq_intx = platform_get_irq_byname(pdev, "intx");
|
|
if (pcie->irq_intx < 0) {
|
|
dev_err(dev, "failed to get intx IRQ %d\n", pcie->irq_intx);
|
|
return -EINVAL;
|
|
}
|
|
|
|
irq_set_chained_handler_and_data(pcie->irq_intx,
|
|
nwl_pcie_leg_handler, pcie);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct of_device_id nwl_pcie_of_match[] = {
|
|
{ .compatible = "xlnx,nwl-pcie-2.11", },
|
|
{}
|
|
};
|
|
|
|
static int nwl_pcie_probe(struct platform_device *pdev)
|
|
{
|
|
struct device *dev = &pdev->dev;
|
|
struct device_node *node = dev->of_node;
|
|
struct nwl_pcie *pcie;
|
|
struct pci_bus *bus;
|
|
struct pci_bus *child;
|
|
int err;
|
|
resource_size_t iobase = 0;
|
|
LIST_HEAD(res);
|
|
|
|
pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
|
|
if (!pcie)
|
|
return -ENOMEM;
|
|
|
|
pcie->dev = dev;
|
|
pcie->ecam_value = NWL_ECAM_VALUE_DEFAULT;
|
|
|
|
err = nwl_pcie_parse_dt(pcie, pdev);
|
|
if (err) {
|
|
dev_err(dev, "Parsing DT failed\n");
|
|
return err;
|
|
}
|
|
|
|
err = nwl_pcie_bridge_init(pcie);
|
|
if (err) {
|
|
dev_err(dev, "HW Initialization failed\n");
|
|
return err;
|
|
}
|
|
|
|
err = of_pci_get_host_bridge_resources(node, 0, 0xff, &res, &iobase);
|
|
if (err) {
|
|
dev_err(dev, "Getting bridge resources failed\n");
|
|
return err;
|
|
}
|
|
|
|
err = devm_request_pci_bus_resources(dev, &res);
|
|
if (err)
|
|
goto error;
|
|
|
|
err = nwl_pcie_init_irq_domain(pcie);
|
|
if (err) {
|
|
dev_err(dev, "Failed creating IRQ Domain\n");
|
|
goto error;
|
|
}
|
|
|
|
bus = pci_create_root_bus(dev, pcie->root_busno,
|
|
&nwl_pcie_ops, pcie, &res);
|
|
if (!bus) {
|
|
err = -ENOMEM;
|
|
goto error;
|
|
}
|
|
|
|
if (IS_ENABLED(CONFIG_PCI_MSI)) {
|
|
err = nwl_pcie_enable_msi(pcie, bus);
|
|
if (err < 0) {
|
|
dev_err(dev, "failed to enable MSI support: %d\n", err);
|
|
goto error;
|
|
}
|
|
}
|
|
pci_scan_child_bus(bus);
|
|
pci_assign_unassigned_bus_resources(bus);
|
|
list_for_each_entry(child, &bus->children, node)
|
|
pcie_bus_configure_settings(child);
|
|
pci_bus_add_devices(bus);
|
|
return 0;
|
|
|
|
error:
|
|
pci_free_resource_list(&res);
|
|
return err;
|
|
}
|
|
|
|
static struct platform_driver nwl_pcie_driver = {
|
|
.driver = {
|
|
.name = "nwl-pcie",
|
|
.suppress_bind_attrs = true,
|
|
.of_match_table = nwl_pcie_of_match,
|
|
},
|
|
.probe = nwl_pcie_probe,
|
|
};
|
|
builtin_platform_driver(nwl_pcie_driver);
|