127Sjchu /* 227Sjchu * CDDL HEADER START 327Sjchu * 427Sjchu * The contents of this file are subject to the terms of the 52549Sgovinda * Common Development and Distribution License (the "License"). 62549Sgovinda * You may not use this file except in compliance with the License. 727Sjchu * 827Sjchu * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 927Sjchu * or http://www.opensolaris.org/os/licensing. 1027Sjchu * See the License for the specific language governing permissions 1127Sjchu * and limitations under the License. 1227Sjchu * 1327Sjchu * When distributing Covered Code, include this CDDL HEADER in each 1427Sjchu * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1527Sjchu * If applicable, add the following below this CDDL HEADER, with the 1627Sjchu * fields enclosed by brackets "[]" replaced with your own identifying 1727Sjchu * information: Portions Copyright [yyyy] [name of copyright owner] 1827Sjchu * 1927Sjchu * CDDL HEADER END 2027Sjchu */ 2127Sjchu /* 228495SAlan.Adamson@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 2327Sjchu * Use is subject to license terms. 2427Sjchu */ 2527Sjchu 2627Sjchu #ifndef _SYS_PCIE_IMPL_H 2727Sjchu #define _SYS_PCIE_IMPL_H 2827Sjchu 2927Sjchu #ifdef __cplusplus 3027Sjchu extern "C" { 3127Sjchu #endif 3227Sjchu 333274Set142600 #include <sys/pcie.h> 343274Set142600 356313Skrishnae #define PCI_GET_BDF(dip) \ 366313Skrishnae PCIE_DIP2BUS(dip)->bus_bdf 376313Skrishnae #define PCI_GET_SEC_BUS(dip) \ 386313Skrishnae PCIE_DIP2BUS(dip)->bus_bdg_secbus 396313Skrishnae #define PCI_GET_PCIE2PCI_SECBUS(dip) \ 4010187SKrishna.Elango@Sun.COM PCIE_DIP2BUS(dip)->bus_bdg_secbus 413274Set142600 426313Skrishnae #define DEVI_PORT_TYPE_PCI \ 436313Skrishnae ((PCI_CLASS_BRIDGE << 16) | (PCI_BRIDGE_PCI << 8) | \ 446313Skrishnae PCI_BRIDGE_PCI_IF_PCI2PCI) 453274Set142600 466313Skrishnae #define PCIE_DIP2BUS(dip) \ 476313Skrishnae (ndi_port_type(dip, B_TRUE, DEVI_PORT_TYPE_PCI) ? \ 486313Skrishnae PCIE_DIP2UPBUS(dip) : \ 496313Skrishnae ndi_port_type(dip, B_FALSE, DEVI_PORT_TYPE_PCI) ? \ 506313Skrishnae PCIE_DIP2DOWNBUS(dip) : NULL) 513274Set142600 526313Skrishnae #define PCIE_DIP2UPBUS(dip) \ 536313Skrishnae ((pcie_bus_t *)ndi_get_bus_private(dip, B_TRUE)) 546313Skrishnae #define PCIE_DIP2DOWNBUS(dip) \ 556313Skrishnae ((pcie_bus_t *)ndi_get_bus_private(dip, B_FALSE)) 566313Skrishnae #define PCIE_DIP2PFD(dip) (PCIE_DIP2BUS(dip))->bus_pfd 576313Skrishnae #define PCIE_PFD2BUS(pfd_p) pfd_p->pe_bus_p 586313Skrishnae #define PCIE_PFD2DIP(pfd_p) PCIE_PFD2BUS(pfd_p)->bus_dip 596313Skrishnae #define PCIE_BUS2DIP(bus_p) bus_p->bus_dip 606313Skrishnae #define PCIE_BUS2PFD(bus_p) PCIE_DIP2PFD(PCIE_BUS2DIP(bus_p)) 613274Set142600 62*11245SZhijun.Fu@Sun.COM /* 63*11245SZhijun.Fu@Sun.COM * These macros depend on initialization of type related data in bus_p. 64*11245SZhijun.Fu@Sun.COM */ 656313Skrishnae #define PCIE_IS_PCIE(bus_p) (bus_p->bus_pcie_off) 666313Skrishnae #define PCIE_IS_PCIX(bus_p) (bus_p->bus_pcix_off) 679921SKrishna.Elango@Sun.COM #define PCIE_IS_PCI(bus_p) (!PCIE_IS_PCIE(bus_p)) 686313Skrishnae #define PCIE_HAS_AER(bus_p) (bus_p->bus_aer_off) 696313Skrishnae /* IS_ROOT = is RC or RP */ 706313Skrishnae #define PCIE_IS_ROOT(bus_p) (PCIE_IS_RC(bus_p) || PCIE_IS_RP(bus_p)) 7110923SEvan.Yan@Sun.COM 7210923SEvan.Yan@Sun.COM #define PCIE_IS_HOTPLUG_CAPABLE(dip) \ 7310923SEvan.Yan@Sun.COM (PCIE_DIP2BUS(dip)->bus_hp_sup_modes) 7410923SEvan.Yan@Sun.COM 7510923SEvan.Yan@Sun.COM #define PCIE_IS_HOTPLUG_ENABLED(dip) \ 7610923SEvan.Yan@Sun.COM ((PCIE_DIP2BUS(dip)->bus_hp_curr_mode == PCIE_PCI_HP_MODE) || \ 7710923SEvan.Yan@Sun.COM (PCIE_DIP2BUS(dip)->bus_hp_curr_mode == PCIE_NATIVE_HP_MODE)) 7810923SEvan.Yan@Sun.COM 796313Skrishnae /* 806313Skrishnae * This is a pseudo pcie "device type", but it's needed to explain describe 816313Skrishnae * nodes such as PX and NPE, which aren't really PCI devices but do control or 826313Skrishnae * interaction with PCI error handling. 836313Skrishnae */ 846313Skrishnae #define PCIE_IS_RC(bus_p) \ 856313Skrishnae (bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_RC_PSEUDO) 866313Skrishnae #define PCIE_IS_RP(bus_p) \ 876313Skrishnae ((bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_ROOT) && \ 886313Skrishnae PCIE_IS_PCIE(bus_p)) 899921SKrishna.Elango@Sun.COM #define PCIE_IS_SWU(bus_p) \ 909921SKrishna.Elango@Sun.COM (bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_UP) 919921SKrishna.Elango@Sun.COM #define PCIE_IS_SWD(bus_p) \ 929921SKrishna.Elango@Sun.COM (bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_DOWN) 936313Skrishnae #define PCIE_IS_SW(bus_p) \ 949921SKrishna.Elango@Sun.COM (PCIE_IS_SWU(bus_p) || PCIE_IS_SWD(bus_p)) 956313Skrishnae #define PCIE_IS_BDG(bus_p) (bus_p->bus_hdr_type == PCI_HEADER_ONE) 969921SKrishna.Elango@Sun.COM #define PCIE_IS_PCI_BDG(bus_p) (PCIE_IS_PCI(bus_p) && PCIE_IS_BDG(bus_p)) 976313Skrishnae #define PCIE_IS_PCIE_BDG(bus_p) \ 986313Skrishnae (bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_PCIE2PCI) 997987SErwin.Tsaur@Sun.COM #define PCIE_IS_PCI2PCIE(bus_p) \ 1007987SErwin.Tsaur@Sun.COM (bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_PCI2PCIE) 1016313Skrishnae #define PCIE_IS_PCIE_SEC(bus_p) \ 1026313Skrishnae (PCIE_IS_PCIE(bus_p) && PCIE_IS_BDG(bus_p) && !PCIE_IS_PCIE_BDG(bus_p)) 1036313Skrishnae #define PCIX_ECC_VERSION_CHECK(bus_p) \ 1046313Skrishnae ((bus_p->bus_ecc_ver == PCI_PCIX_VER_1) || \ 1056313Skrishnae (bus_p->bus_ecc_ver == PCI_PCIX_VER_2)) 1063274Set142600 1076313Skrishnae #define PCIE_VENID(bus_p) (bus_p->bus_dev_ven_id & 0xffff) 1086313Skrishnae #define PCIE_DEVID(bus_p) ((bus_p->bus_dev_ven_id >> 16) & 0xffff) 1093274Set142600 1106313Skrishnae /* PCIE Cap/AER shortcuts */ 1116313Skrishnae #define PCIE_GET(sz, bus_p, off) \ 1126313Skrishnae pci_config_get ## sz(bus_p->bus_cfg_hdl, off) 1136313Skrishnae #define PCIE_PUT(sz, bus_p, off, val) \ 1146313Skrishnae pci_config_put ## sz(bus_p->bus_cfg_hdl, off, val) 1156313Skrishnae #define PCIE_CAP_GET(sz, bus_p, off) \ 1166313Skrishnae PCI_CAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcie_off, off) 1176313Skrishnae #define PCIE_CAP_PUT(sz, bus_p, off, val) \ 1186313Skrishnae PCI_CAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcie_off, off, \ 1196313Skrishnae val) 1206313Skrishnae #define PCIE_AER_GET(sz, bus_p, off) \ 1216313Skrishnae PCI_XCAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_aer_off, off) 1226313Skrishnae #define PCIE_AER_PUT(sz, bus_p, off, val) \ 1236313Skrishnae PCI_XCAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_aer_off, off, \ 1246313Skrishnae val) 1256313Skrishnae #define PCIX_CAP_GET(sz, bus_p, off) \ 1266313Skrishnae PCI_CAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcix_off, off) 1276313Skrishnae #define PCIX_CAP_PUT(sz, bus_p, off, val) \ 1286313Skrishnae PCI_CAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcix_off, off, \ 1296313Skrishnae val) 1303274Set142600 1316313Skrishnae /* Translate PF error return values to DDI_FM values */ 1326313Skrishnae #define PF_ERR2DDIFM_ERR(sts) \ 1336313Skrishnae (sts & PF_ERR_FATAL_FLAGS ? DDI_FM_FATAL : \ 1346313Skrishnae (sts == PF_ERR_NO_ERROR ? DDI_FM_OK : DDI_FM_NONFATAL)) 1353274Set142600 13627Sjchu /* 1372549Sgovinda * The following flag is used for Broadcom 5714/5715 bridge prefetch issue. 13810187SKrishna.Elango@Sun.COM * This flag will be used both by px and pcieb nexus drivers. 1392549Sgovinda */ 1402549Sgovinda #define PX_DMAI_FLAGS_MAP_BUFZONE 0x40000 1412549Sgovinda 1426313Skrishnae /* 1436313Skrishnae * PCI(e/-X) structures used to to gather and report errors detected by 1446313Skrishnae * PCI(e/-X) compliant devices. These registers only contain "dynamic" data. 1456313Skrishnae * Static data such as Capability Offsets and Version #s is saved in the parent 1466313Skrishnae * private data. 1476313Skrishnae */ 1486313Skrishnae #define PCI_ERR_REG(pfd_p) pfd_p->pe_pci_regs 1496313Skrishnae #define PCI_BDG_ERR_REG(pfd_p) PCI_ERR_REG(pfd_p)->pci_bdg_regs 1506313Skrishnae #define PCIX_ERR_REG(pfd_p) pfd_p->pe_ext.pe_pcix_regs 1516313Skrishnae #define PCIX_ECC_REG(pfd_p) PCIX_ERR_REG(pfd_p)->pcix_ecc_regs 1526313Skrishnae #define PCIX_BDG_ERR_REG(pfd_p) pfd_p->pe_pcix_bdg_regs 1536313Skrishnae #define PCIX_BDG_ECC_REG(pfd_p, n) PCIX_BDG_ERR_REG(pfd_p)->pcix_bdg_ecc_regs[n] 1546313Skrishnae #define PCIE_ERR_REG(pfd_p) pfd_p->pe_ext.pe_pcie_regs 1556313Skrishnae #define PCIE_RP_REG(pfd_p) PCIE_ERR_REG(pfd_p)->pcie_rp_regs 1566313Skrishnae #define PCIE_ROOT_FAULT(pfd_p) pfd_p->pe_root_fault 1576313Skrishnae #define PCIE_ADV_REG(pfd_p) PCIE_ERR_REG(pfd_p)->pcie_adv_regs 1586313Skrishnae #define PCIE_ADV_HDR(pfd_p, n) PCIE_ADV_REG(pfd_p)->pcie_ue_hdr[n] 1596313Skrishnae #define PCIE_ADV_BDG_REG(pfd_p) \ 1606313Skrishnae PCIE_ADV_REG(pfd_p)->pcie_ext.pcie_adv_bdg_regs 1616313Skrishnae #define PCIE_ADV_BDG_HDR(pfd_p, n) PCIE_ADV_BDG_REG(pfd_p)->pcie_sue_hdr[n] 1626313Skrishnae #define PCIE_ADV_RP_REG(pfd_p) \ 1636313Skrishnae PCIE_ADV_REG(pfd_p)->pcie_ext.pcie_adv_rp_regs 1646313Skrishnae #define PFD_IS_ROOT(pfd_p) PCIE_IS_ROOT(PCIE_PFD2BUS(pfd_p)) 1656313Skrishnae #define PFD_IS_RC(pfd_p) PCIE_IS_RC(PCIE_PFD2BUS(pfd_p)) 1666313Skrishnae #define PFD_IS_RP(pfd_p) PCIE_IS_RP(PCIE_PFD2BUS(pfd_p)) 1676313Skrishnae 16810923SEvan.Yan@Sun.COM /* bus_hp_mode field */ 16910923SEvan.Yan@Sun.COM typedef enum { 17010923SEvan.Yan@Sun.COM PCIE_NONE_HP_MODE = 0x0, 17110923SEvan.Yan@Sun.COM PCIE_ACPI_HP_MODE = 0x1, 17210923SEvan.Yan@Sun.COM PCIE_PCI_HP_MODE = 0x2, 17310923SEvan.Yan@Sun.COM PCIE_NATIVE_HP_MODE = 0x4 17410923SEvan.Yan@Sun.COM } pcie_hp_mode_t; 17510923SEvan.Yan@Sun.COM 1766313Skrishnae typedef struct pf_pci_bdg_err_regs { 1776313Skrishnae uint16_t pci_bdg_sec_stat; /* PCI secondary status reg */ 1786313Skrishnae uint16_t pci_bdg_ctrl; /* PCI bridge control reg */ 1796313Skrishnae } pf_pci_bdg_err_regs_t; 1806313Skrishnae 1816313Skrishnae typedef struct pf_pci_err_regs { 1826313Skrishnae uint16_t pci_err_status; /* pci status register */ 1836313Skrishnae uint16_t pci_cfg_comm; /* pci command register */ 1846313Skrishnae pf_pci_bdg_err_regs_t *pci_bdg_regs; 1856313Skrishnae } pf_pci_err_regs_t; 1866313Skrishnae 1876313Skrishnae typedef struct pf_pcix_ecc_regs { 1886313Skrishnae uint32_t pcix_ecc_ctlstat; /* pcix ecc control status reg */ 1896313Skrishnae uint32_t pcix_ecc_fstaddr; /* pcix ecc first address reg */ 1906313Skrishnae uint32_t pcix_ecc_secaddr; /* pcix ecc second address reg */ 1916313Skrishnae uint32_t pcix_ecc_attr; /* pcix ecc attributes reg */ 1926313Skrishnae } pf_pcix_ecc_regs_t; 1933274Set142600 1946313Skrishnae typedef struct pf_pcix_err_regs { 1956313Skrishnae uint16_t pcix_command; /* pcix command register */ 1966313Skrishnae uint32_t pcix_status; /* pcix status register */ 1976313Skrishnae pf_pcix_ecc_regs_t *pcix_ecc_regs; /* pcix ecc registers */ 1986313Skrishnae } pf_pcix_err_regs_t; 1996313Skrishnae 2006313Skrishnae typedef struct pf_pcix_bdg_err_regs { 2016313Skrishnae uint16_t pcix_bdg_sec_stat; /* pcix bridge secondary status reg */ 2026313Skrishnae uint32_t pcix_bdg_stat; /* pcix bridge status reg */ 2036313Skrishnae pf_pcix_ecc_regs_t *pcix_bdg_ecc_regs[2]; /* pcix ecc registers */ 2046313Skrishnae } pf_pcix_bdg_err_regs_t; 2056313Skrishnae 2066313Skrishnae typedef struct pf_pcie_adv_bdg_err_regs { 2076313Skrishnae uint32_t pcie_sue_ctl; /* pcie bridge secondary ue control */ 2086313Skrishnae uint32_t pcie_sue_status; /* pcie bridge secondary ue status */ 2096313Skrishnae uint32_t pcie_sue_mask; /* pcie bridge secondary ue mask */ 2106313Skrishnae uint32_t pcie_sue_sev; /* pcie bridge secondary ue severity */ 2116313Skrishnae uint32_t pcie_sue_hdr[4]; /* pcie bridge secondary ue hdr log */ 2126313Skrishnae uint32_t pcie_sue_tgt_trans; /* Fault trans type from SAER Logs */ 2136313Skrishnae uint64_t pcie_sue_tgt_addr; /* Fault addr from SAER Logs */ 2146313Skrishnae pcie_req_id_t pcie_sue_tgt_bdf; /* Fault bdf from SAER Logs */ 2156313Skrishnae } pf_pcie_adv_bdg_err_regs_t; 2163274Set142600 2176313Skrishnae typedef struct pf_pcie_adv_rp_err_regs { 2186313Skrishnae uint32_t pcie_rp_err_status; /* pcie root complex error status reg */ 2196313Skrishnae uint32_t pcie_rp_err_cmd; /* pcie root complex error cmd reg */ 2206313Skrishnae uint16_t pcie_rp_ce_src_id; /* pcie root complex ce sourpe id */ 2216313Skrishnae uint16_t pcie_rp_ue_src_id; /* pcie root complex ue sourpe id */ 2226313Skrishnae } pf_pcie_adv_rp_err_regs_t; 2236313Skrishnae 2246313Skrishnae typedef struct pf_pcie_adv_err_regs { 2256313Skrishnae uint32_t pcie_adv_ctl; /* pcie advanced control reg */ 2266313Skrishnae uint32_t pcie_ue_status; /* pcie ue error status reg */ 2276313Skrishnae uint32_t pcie_ue_mask; /* pcie ue error mask reg */ 2286313Skrishnae uint32_t pcie_ue_sev; /* pcie ue error severity reg */ 2296313Skrishnae uint32_t pcie_ue_hdr[4]; /* pcie ue header log */ 2306313Skrishnae uint32_t pcie_ce_status; /* pcie ce error status reg */ 2316313Skrishnae uint32_t pcie_ce_mask; /* pcie ce error mask reg */ 2326313Skrishnae union { 2336313Skrishnae pf_pcie_adv_bdg_err_regs_t *pcie_adv_bdg_regs; /* bdg regs */ 2346313Skrishnae pf_pcie_adv_rp_err_regs_t *pcie_adv_rp_regs; /* rp regs */ 2356313Skrishnae } pcie_ext; 2366313Skrishnae uint32_t pcie_ue_tgt_trans; /* Fault trans type from AER Logs */ 2376313Skrishnae uint64_t pcie_ue_tgt_addr; /* Fault addr from AER Logs */ 2389921SKrishna.Elango@Sun.COM pcie_req_id_t pcie_ue_tgt_bdf; /* Fault bdf from AER Logs */ 2396313Skrishnae } pf_pcie_adv_err_regs_t; 2406313Skrishnae 2416313Skrishnae typedef struct pf_pcie_rp_err_regs { 2426313Skrishnae uint32_t pcie_rp_status; /* root complex status register */ 2436313Skrishnae uint16_t pcie_rp_ctl; /* root complex control register */ 2446313Skrishnae } pf_pcie_rp_err_regs_t; 2453274Set142600 2466313Skrishnae typedef struct pf_pcie_err_regs { 2476313Skrishnae uint16_t pcie_err_status; /* pcie device status register */ 2486313Skrishnae uint16_t pcie_err_ctl; /* pcie error control register */ 2496313Skrishnae uint32_t pcie_dev_cap; /* pcie device capabilities register */ 2506313Skrishnae pf_pcie_rp_err_regs_t *pcie_rp_regs; /* pcie root complex regs */ 2516313Skrishnae pf_pcie_adv_err_regs_t *pcie_adv_regs; /* pcie aer regs */ 2526313Skrishnae } pf_pcie_err_regs_t; 2536313Skrishnae 2546313Skrishnae typedef struct pf_root_fault { 2559921SKrishna.Elango@Sun.COM pcie_req_id_t scan_bdf; /* BDF from error logs */ 2569921SKrishna.Elango@Sun.COM uint64_t scan_addr; /* Addr from error logs */ 2576313Skrishnae boolean_t full_scan; /* Option to do a full scan */ 2586313Skrishnae } pf_root_fault_t; 2596313Skrishnae 2606313Skrishnae typedef struct pf_data pf_data_t; 2616313Skrishnae 262*11245SZhijun.Fu@Sun.COM /* 263*11245SZhijun.Fu@Sun.COM * For hot plugged device, these data are init'ed during during probe 264*11245SZhijun.Fu@Sun.COM * For non-hotplugged device, these data are init'ed in pci_autoconfig (on x86), 265*11245SZhijun.Fu@Sun.COM * or in px_attach()(on sparc). 266*11245SZhijun.Fu@Sun.COM * 267*11245SZhijun.Fu@Sun.COM * For root complex the fields are initialized in pcie_rc_init_bus(); 268*11245SZhijun.Fu@Sun.COM * for others part of the fields are initialized in pcie_init_bus(), 269*11245SZhijun.Fu@Sun.COM * and part of fields initialized in pcie_post_init_bus(). See comments 270*11245SZhijun.Fu@Sun.COM * on top of respective functions for details. 271*11245SZhijun.Fu@Sun.COM */ 2726313Skrishnae typedef struct pcie_bus { 2736313Skrishnae /* Needed for PCI/PCIe fabric error handling */ 2746313Skrishnae dev_info_t *bus_dip; 2756313Skrishnae dev_info_t *bus_rp_dip; 27610923SEvan.Yan@Sun.COM ddi_acc_handle_t bus_cfg_hdl; /* error handling acc hdle */ 2776313Skrishnae uint_t bus_fm_flags; 27810923SEvan.Yan@Sun.COM uint_t bus_soft_state; 2796313Skrishnae 2806313Skrishnae /* Static PCI/PCIe information */ 2816313Skrishnae pcie_req_id_t bus_bdf; 2826313Skrishnae pcie_req_id_t bus_rp_bdf; /* BDF of device's Root Port */ 2836313Skrishnae uint32_t bus_dev_ven_id; /* device/vendor ID */ 2846313Skrishnae uint8_t bus_rev_id; /* revision ID */ 2856313Skrishnae uint8_t bus_hdr_type; /* pci header type, see pci.h */ 2866313Skrishnae uint16_t bus_dev_type; /* PCI-E dev type, see pcie.h */ 2876313Skrishnae uint8_t bus_bdg_secbus; /* Bridge secondary bus num */ 2886313Skrishnae uint16_t bus_pcie_off; /* PCIe Capability Offset */ 2896313Skrishnae uint16_t bus_aer_off; /* PCIe Advanced Error Offset */ 2906313Skrishnae uint16_t bus_pcix_off; /* PCIx Capability Offset */ 29110923SEvan.Yan@Sun.COM uint16_t bus_pci_hp_off; /* PCI HP (SHPC) Cap Offset */ 2926313Skrishnae uint16_t bus_ecc_ver; /* PCIX ecc version */ 2936313Skrishnae pci_bus_range_t bus_bus_range; /* pci bus-range property */ 2946313Skrishnae ppb_ranges_t *bus_addr_ranges; /* pci range property */ 2956313Skrishnae int bus_addr_entries; /* number of range prop */ 2966313Skrishnae pci_regspec_t *bus_assigned_addr; /* "assigned-address" prop */ 2976313Skrishnae int bus_assigned_entries; /* number of prop entries */ 2986313Skrishnae 2996313Skrishnae /* Cache of last fault data */ 3006313Skrishnae pf_data_t *bus_pfd; 3017596SAlan.Adamson@Sun.COM 3027596SAlan.Adamson@Sun.COM int bus_mps; /* Maximum Payload Size */ 3039455SKrishna.Elango@Sun.COM 3049455SKrishna.Elango@Sun.COM void *bus_plat_private; /* Platform specific */ 30510923SEvan.Yan@Sun.COM /* Hotplug specific fields */ 30610923SEvan.Yan@Sun.COM pcie_hp_mode_t bus_hp_sup_modes; /* HP modes supported */ 30710923SEvan.Yan@Sun.COM pcie_hp_mode_t bus_hp_curr_mode; /* HP mode used */ 30810923SEvan.Yan@Sun.COM void *bus_hp_ctrl; /* HP bus ctrl data */ 30910923SEvan.Yan@Sun.COM int bus_ari; /* ARI device */ 310*11245SZhijun.Fu@Sun.COM 311*11245SZhijun.Fu@Sun.COM uint64_t bus_cfgacc_base; /* config space base address */ 3126313Skrishnae } pcie_bus_t; 3133274Set142600 3146313Skrishnae struct pf_data { 3156313Skrishnae boolean_t pe_lock; 3166313Skrishnae boolean_t pe_valid; 3176313Skrishnae uint32_t pe_severity_flags; /* Severity of error */ 3186313Skrishnae pcie_bus_t *pe_bus_p; 3196313Skrishnae pf_root_fault_t *pe_root_fault; /* Only valid for RC and RP */ 3206313Skrishnae pf_pci_err_regs_t *pe_pci_regs; /* PCI error reg */ 3216313Skrishnae union { 3226313Skrishnae pf_pcix_err_regs_t *pe_pcix_regs; /* PCI-X error reg */ 3236313Skrishnae pf_pcie_err_regs_t *pe_pcie_regs; /* PCIe error reg */ 3246313Skrishnae } pe_ext; 3256313Skrishnae pf_pcix_bdg_err_regs_t *pe_pcix_bdg_regs; /* PCI-X bridge regs */ 3266313Skrishnae pf_data_t *pe_prev; /* Next error in queue */ 3276313Skrishnae pf_data_t *pe_next; /* Next error in queue */ 3287848SKrishna.Elango@Sun.COM boolean_t pe_rber_fatal; 3296313Skrishnae }; 3306313Skrishnae 3316313Skrishnae /* Information used while handling errors in the fabric. */ 3326313Skrishnae typedef struct pf_impl { 3336313Skrishnae ddi_fm_error_t *pf_derr; 3346313Skrishnae pf_root_fault_t *pf_fault; /* captured fault bdf/addr to scan */ 3356313Skrishnae pf_data_t *pf_dq_head_p; /* ptr to fault data queue */ 3366313Skrishnae pf_data_t *pf_dq_tail_p; /* ptr pt last fault data q */ 3376313Skrishnae uint32_t pf_total; /* total non RC pf_datas */ 3386313Skrishnae } pf_impl_t; 3396313Skrishnae 3406313Skrishnae /* bus_fm_flags field */ 3416313Skrishnae #define PF_FM_READY (1 << 0) /* bus_fm_lock initialized */ 3426313Skrishnae #define PF_FM_IS_NH (1 << 1) /* known as non-hardened */ 3433274Set142600 3446313Skrishnae /* 3456313Skrishnae * PCIe fabric handle lookup address flags. Used to define what type of 3466313Skrishnae * transaction the address is for. These same value are defined again in 3476313Skrishnae * fabric-xlate FM module. Do not modify these variables, without modifying 3486313Skrishnae * those. 3496313Skrishnae */ 3506313Skrishnae #define PF_ADDR_DMA (1 << 0) 3516313Skrishnae #define PF_ADDR_PIO (1 << 1) 3526313Skrishnae #define PF_ADDR_CFG (1 << 2) 3533274Set142600 3546313Skrishnae /* PCIe fabric error scanning status flags */ 3556313Skrishnae #define PF_SCAN_SUCCESS (1 << 0) 3566313Skrishnae #define PF_SCAN_CB_FAILURE (1 << 1) /* hardened device callback failure */ 3576313Skrishnae #define PF_SCAN_NO_ERR_IN_CHILD (1 << 2) /* no errors in bridge sec stat reg */ 3586313Skrishnae #define PF_SCAN_IN_DQ (1 << 3) /* already present in the faultq */ 3596313Skrishnae #define PF_SCAN_DEADLOCK (1 << 4) /* deadlock detected */ 3606313Skrishnae #define PF_SCAN_BAD_RESPONSE (1 << 5) /* Incorrect device response */ 3616313Skrishnae 3626313Skrishnae /* PCIe fabric error handling severity return flags */ 3636313Skrishnae #define PF_ERR_NO_ERROR (1 << 0) /* No error seen */ 3646313Skrishnae #define PF_ERR_CE (1 << 1) /* Correctable Error */ 3656313Skrishnae #define PF_ERR_NO_PANIC (1 << 2) /* Error should not panic sys */ 3666313Skrishnae #define PF_ERR_MATCHED_DEVICE (1 << 3) /* Error Handled By Device */ 3676313Skrishnae #define PF_ERR_MATCHED_RC (1 << 4) /* Error Handled By RC */ 3686313Skrishnae #define PF_ERR_MATCHED_PARENT (1 << 5) /* Error Handled By Parent */ 3696313Skrishnae #define PF_ERR_PANIC (1 << 6) /* Error should panic system */ 3706313Skrishnae #define PF_ERR_PANIC_DEADLOCK (1 << 7) /* deadlock detected */ 3716313Skrishnae 3726313Skrishnae #define PF_ERR_FATAL_FLAGS (PF_ERR_PANIC | PF_ERR_PANIC_DEADLOCK) 3736313Skrishnae 3746313Skrishnae #define PF_HDL_FOUND 1 3756313Skrishnae #define PF_HDL_NOTFOUND 2 3766313Skrishnae 3779921SKrishna.Elango@Sun.COM /* 3789921SKrishna.Elango@Sun.COM * PCIe Capability Device Type Pseudo Definitions. 3799921SKrishna.Elango@Sun.COM * 3809921SKrishna.Elango@Sun.COM * PCI_PSEUDO is used on real PCI devices. The Legacy PCI definition in the 3819921SKrishna.Elango@Sun.COM * PCIe spec really refers to PCIe devices that *require* IO Space access. IO 3829921SKrishna.Elango@Sun.COM * Space access is usually frowned upon now in PCIe, but there for legacy 3839921SKrishna.Elango@Sun.COM * purposes. 3849921SKrishna.Elango@Sun.COM */ 3859921SKrishna.Elango@Sun.COM #define PCIE_PCIECAP_DEV_TYPE_RC_PSEUDO 0x100 3869921SKrishna.Elango@Sun.COM #define PCIE_PCIECAP_DEV_TYPE_PCI_PSEUDO 0x101 3879921SKrishna.Elango@Sun.COM 3889921SKrishna.Elango@Sun.COM #define PCIE_INVALID_BDF 0xFFFF 3899921SKrishna.Elango@Sun.COM #define PCIE_CHECK_VALID_BDF(x) (x != PCIE_INVALID_BDF) 3903274Set142600 3917596SAlan.Adamson@Sun.COM typedef struct { 3927596SAlan.Adamson@Sun.COM dev_info_t *dip; 3937596SAlan.Adamson@Sun.COM int highest_common_mps; 3947596SAlan.Adamson@Sun.COM } pcie_max_supported_t; 3957596SAlan.Adamson@Sun.COM 39610923SEvan.Yan@Sun.COM /* 39710923SEvan.Yan@Sun.COM * Default interrupt priority for all PCI and PCIe nexus drivers including 39810923SEvan.Yan@Sun.COM * hotplug interrupts. 39910923SEvan.Yan@Sun.COM */ 40010923SEvan.Yan@Sun.COM #define PCIE_INTR_PRI (LOCK_LEVEL - 1) 40110923SEvan.Yan@Sun.COM 40210923SEvan.Yan@Sun.COM /* 40310923SEvan.Yan@Sun.COM * XXX - PCIE_IS_PCIE check is required in order not to invoke these macros 40410923SEvan.Yan@Sun.COM * for non-standard PCI or PCI Express Hotplug Controllers. 40510923SEvan.Yan@Sun.COM */ 40610923SEvan.Yan@Sun.COM #define PCIE_ENABLE_ERRORS(dip) \ 40710923SEvan.Yan@Sun.COM if (PCIE_IS_PCIE(PCIE_DIP2BUS(dip))) { \ 40810923SEvan.Yan@Sun.COM pcie_enable_errors(dip); \ 40910923SEvan.Yan@Sun.COM (void) pcie_enable_ce(dip); \ 41010923SEvan.Yan@Sun.COM } 41110923SEvan.Yan@Sun.COM 41210923SEvan.Yan@Sun.COM #define PCIE_DISABLE_ERRORS(dip) \ 41310923SEvan.Yan@Sun.COM if (PCIE_IS_PCIE(PCIE_DIP2BUS(dip))) { \ 41410923SEvan.Yan@Sun.COM pcie_disable_errors(dip); \ 41510923SEvan.Yan@Sun.COM } 41610923SEvan.Yan@Sun.COM 417*11245SZhijun.Fu@Sun.COM /* 418*11245SZhijun.Fu@Sun.COM * pcie_init_buspcie_fini_bus specific flags 419*11245SZhijun.Fu@Sun.COM */ 420*11245SZhijun.Fu@Sun.COM #define PCIE_BUS_INITIAL 0x0001 421*11245SZhijun.Fu@Sun.COM #define PCIE_BUS_FINAL 0x0002 422*11245SZhijun.Fu@Sun.COM #define PCIE_BUS_ALL (PCIE_BUS_INITIAL | PCIE_BUS_FINAL) 423*11245SZhijun.Fu@Sun.COM 4249455SKrishna.Elango@Sun.COM #ifdef DEBUG 4259455SKrishna.Elango@Sun.COM #define PCIE_DBG pcie_dbg 4269455SKrishna.Elango@Sun.COM /* Common Debugging shortcuts */ 4279455SKrishna.Elango@Sun.COM #define PCIE_DBG_CFG(dip, bus_p, name, sz, off, org) \ 4289455SKrishna.Elango@Sun.COM PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \ 4299455SKrishna.Elango@Sun.COM ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \ 4309455SKrishna.Elango@Sun.COM PCIE_GET(sz, bus_p, off)) 4319455SKrishna.Elango@Sun.COM #define PCIE_DBG_CAP(dip, bus_p, name, sz, off, org) \ 4329455SKrishna.Elango@Sun.COM PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \ 4339455SKrishna.Elango@Sun.COM ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \ 4349455SKrishna.Elango@Sun.COM PCIE_CAP_GET(sz, bus_p, off)) 4359455SKrishna.Elango@Sun.COM #define PCIE_DBG_AER(dip, bus_p, name, sz, off, org) \ 4369455SKrishna.Elango@Sun.COM PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \ 4379455SKrishna.Elango@Sun.COM ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \ 4389455SKrishna.Elango@Sun.COM PCIE_AER_GET(sz, bus_p, off)) 4399455SKrishna.Elango@Sun.COM 4409455SKrishna.Elango@Sun.COM #else /* DEBUG */ 4419455SKrishna.Elango@Sun.COM 4429455SKrishna.Elango@Sun.COM #define PCIE_DBG_CFG 0 && 4439455SKrishna.Elango@Sun.COM #define PCIE_DBG 0 && 44410923SEvan.Yan@Sun.COM #define PCIE_ARI_DBG 0 && 4459455SKrishna.Elango@Sun.COM #define PCIE_DBG_CAP 0 && 4469455SKrishna.Elango@Sun.COM #define PCIE_DBG_AER 0 && 4479455SKrishna.Elango@Sun.COM 4489455SKrishna.Elango@Sun.COM #endif /* DEBUG */ 4499455SKrishna.Elango@Sun.COM 4503274Set142600 /* PCIe Friendly Functions */ 45110923SEvan.Yan@Sun.COM extern int pcie_init(dev_info_t *dip, caddr_t arg); 45210923SEvan.Yan@Sun.COM extern int pcie_uninit(dev_info_t *dip); 45310923SEvan.Yan@Sun.COM extern int pcie_intr(dev_info_t *dip); 45410923SEvan.Yan@Sun.COM extern int pcie_open(dev_info_t *dip, dev_t *devp, int flags, int otyp, 45510923SEvan.Yan@Sun.COM cred_t *credp); 45610923SEvan.Yan@Sun.COM extern int pcie_close(dev_info_t *dip, dev_t dev, int flags, int otyp, 45710923SEvan.Yan@Sun.COM cred_t *credp); 45810923SEvan.Yan@Sun.COM extern int pcie_ioctl(dev_info_t *dip, dev_t dev, int cmd, intptr_t arg, 45910923SEvan.Yan@Sun.COM int mode, cred_t *credp, int *rvalp); 46010923SEvan.Yan@Sun.COM extern int pcie_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, 46110923SEvan.Yan@Sun.COM int flags, char *name, caddr_t valuep, int *lengthp); 46210923SEvan.Yan@Sun.COM 4638495SAlan.Adamson@Sun.COM extern void pcie_init_root_port_mps(dev_info_t *dip); 46427Sjchu extern int pcie_initchild(dev_info_t *dip); 46527Sjchu extern void pcie_uninitchild(dev_info_t *dip); 466*11245SZhijun.Fu@Sun.COM extern int pcie_init_cfghdl(dev_info_t *dip); 467*11245SZhijun.Fu@Sun.COM extern void pcie_fini_cfghdl(dev_info_t *dip); 4686313Skrishnae extern void pcie_clear_errors(dev_info_t *dip); 4692738Skrishnae extern int pcie_postattach_child(dev_info_t *dip); 4706313Skrishnae extern void pcie_enable_errors(dev_info_t *dip); 4716313Skrishnae extern void pcie_disable_errors(dev_info_t *dip); 4726313Skrishnae extern int pcie_enable_ce(dev_info_t *dip); 4736313Skrishnae extern boolean_t pcie_bridge_is_link_disabled(dev_info_t *); 4746313Skrishnae 475*11245SZhijun.Fu@Sun.COM extern pcie_bus_t *pcie_init_bus(dev_info_t *dip, pcie_req_id_t bdf, 476*11245SZhijun.Fu@Sun.COM uint8_t flags); 477*11245SZhijun.Fu@Sun.COM extern void pcie_fini_bus(dev_info_t *dip, uint8_t flags); 478*11245SZhijun.Fu@Sun.COM extern void pcie_fab_init_bus(dev_info_t *dip, uint8_t flags); 479*11245SZhijun.Fu@Sun.COM extern void pcie_fab_fini_bus(dev_info_t *dip, uint8_t flags); 4806313Skrishnae extern void pcie_rc_init_bus(dev_info_t *dip); 4816313Skrishnae extern void pcie_rc_fini_bus(dev_info_t *dip); 4826313Skrishnae extern void pcie_rc_init_pfd(dev_info_t *dip, pf_data_t *pfd); 4836313Skrishnae extern void pcie_rc_fini_pfd(pf_data_t *pfd); 4846313Skrishnae extern boolean_t pcie_is_child(dev_info_t *dip, dev_info_t *rdip); 4856313Skrishnae extern int pcie_get_bdf_from_dip(dev_info_t *dip, pcie_req_id_t *bdf); 4863156Sgirish extern dev_info_t *pcie_get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip); 4873249Sgovinda extern uint32_t pcie_get_bdf_for_dma_xfer(dev_info_t *dip, dev_info_t *rdip); 4887596SAlan.Adamson@Sun.COM extern int pcie_dev(dev_info_t *dip); 4897596SAlan.Adamson@Sun.COM extern void pcie_get_fabric_mps(dev_info_t *rc_dip, dev_info_t *dip, 4907596SAlan.Adamson@Sun.COM int *max_supported); 4917596SAlan.Adamson@Sun.COM extern int pcie_root_port(dev_info_t *dip); 4927596SAlan.Adamson@Sun.COM extern int pcie_initchild_mps(dev_info_t *dip); 4937848SKrishna.Elango@Sun.COM extern void pcie_set_rber_fatal(dev_info_t *dip, boolean_t val); 4947848SKrishna.Elango@Sun.COM extern boolean_t pcie_get_rber_fatal(dev_info_t *dip); 4953274Set142600 4966313Skrishnae extern uint32_t pcie_get_aer_uce_mask(); 4976313Skrishnae extern uint32_t pcie_get_aer_ce_mask(); 4986313Skrishnae extern uint32_t pcie_get_aer_suce_mask(); 4996313Skrishnae extern uint32_t pcie_get_serr_mask(); 5006313Skrishnae extern void pcie_set_aer_uce_mask(uint32_t mask); 5016313Skrishnae extern void pcie_set_aer_ce_mask(uint32_t mask); 5026313Skrishnae extern void pcie_set_aer_suce_mask(uint32_t mask); 5036313Skrishnae extern void pcie_set_serr_mask(uint32_t mask); 5049455SKrishna.Elango@Sun.COM extern void pcie_init_plat(dev_info_t *dip); 5059455SKrishna.Elango@Sun.COM extern void pcie_fini_plat(dev_info_t *dip); 50610923SEvan.Yan@Sun.COM extern int pcie_read_only_probe(dev_info_t *, char *, dev_info_t **); 50710923SEvan.Yan@Sun.COM extern dev_info_t *pcie_func_to_dip(dev_info_t *dip, pcie_req_id_t function); 50810923SEvan.Yan@Sun.COM extern int pcie_ari_disable(dev_info_t *dip); 50910923SEvan.Yan@Sun.COM extern int pcie_ari_enable(dev_info_t *dip); 51010923SEvan.Yan@Sun.COM 51110923SEvan.Yan@Sun.COM #define PCIE_ARI_FORW_NOT_SUPPORTED 0 51210923SEvan.Yan@Sun.COM #define PCIE_ARI_FORW_SUPPORTED 1 51310923SEvan.Yan@Sun.COM 51410923SEvan.Yan@Sun.COM extern int pcie_ari_supported(dev_info_t *dip); 51510923SEvan.Yan@Sun.COM 51610923SEvan.Yan@Sun.COM #define PCIE_ARI_FORW_DISABLED 0 51710923SEvan.Yan@Sun.COM #define PCIE_ARI_FORW_ENABLED 1 51810923SEvan.Yan@Sun.COM 51910923SEvan.Yan@Sun.COM extern int pcie_ari_is_enabled(dev_info_t *dip); 52010923SEvan.Yan@Sun.COM 52110923SEvan.Yan@Sun.COM #define PCIE_NOT_ARI_DEVICE 0 52210923SEvan.Yan@Sun.COM #define PCIE_ARI_DEVICE 1 52310923SEvan.Yan@Sun.COM 52410923SEvan.Yan@Sun.COM extern int pcie_ari_device(dev_info_t *dip); 52510923SEvan.Yan@Sun.COM extern int pcie_ari_get_next_function(dev_info_t *dip, int *func); 5263274Set142600 5273274Set142600 /* PCIe error handling functions */ 5283274Set142600 extern int pf_scan_fabric(dev_info_t *rpdip, ddi_fm_error_t *derr, 5296313Skrishnae pf_data_t *root_pfd_p); 5306313Skrishnae extern void pf_init(dev_info_t *, ddi_iblock_cookie_t, ddi_attach_cmd_t); 5316313Skrishnae extern void pf_fini(dev_info_t *, ddi_detach_cmd_t); 5326313Skrishnae extern int pf_hdl_lookup(dev_info_t *, uint64_t, uint32_t, uint64_t, 5336313Skrishnae pcie_req_id_t); 5346313Skrishnae extern int pf_tlp_decode(pcie_bus_t *, pf_pcie_adv_err_regs_t *); 53511040SPavel.Potoplyak@Sun.COM extern void pcie_force_fullscan(); 53627Sjchu 53710923SEvan.Yan@Sun.COM #ifdef DEBUG 53810923SEvan.Yan@Sun.COM extern uint_t pcie_debug_flags; 53910923SEvan.Yan@Sun.COM extern void pcie_dbg(char *fmt, ...); 54010923SEvan.Yan@Sun.COM #endif /* DEBUG */ 54110923SEvan.Yan@Sun.COM 54227Sjchu #ifdef __cplusplus 54327Sjchu } 54427Sjchu #endif 54527Sjchu 54627Sjchu #endif /* _SYS_PCIE_IMPL_H */ 547